mm-share-lib 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +17 -17
  3. package/dist/src/{common/constant → constant}/entity-state.constant.d.ts +4 -4
  4. package/dist/src/{common/constant → constant}/entity-state.constant.js +8 -8
  5. package/dist/src/constant/entity-state.constant.js.map +1 -0
  6. package/dist/src/{common/constant → constant}/index.d.ts +1 -1
  7. package/dist/src/{common/constant → constant}/index.js +17 -17
  8. package/dist/src/constant/index.js.map +1 -0
  9. package/dist/src/dto/base-filter.dto.d.ts +4 -4
  10. package/dist/src/dto/base-filter.dto.js +10 -10
  11. package/dist/src/dto/index.d.ts +2 -2
  12. package/dist/src/dto/index.js +18 -18
  13. package/dist/src/dto/pagination.dto.d.ts +4 -4
  14. package/dist/src/dto/pagination.dto.js +10 -10
  15. package/dist/src/exception/index.d.ts +0 -0
  16. package/dist/src/exception/index.js +1 -0
  17. package/dist/src/exception/index.js.map +1 -0
  18. package/dist/src/{common/generic → generic}/entity/entity.generic.d.ts +10 -10
  19. package/dist/src/{common/generic → generic}/entity/entity.generic.js +47 -47
  20. package/dist/src/generic/entity/entity.generic.js.map +1 -0
  21. package/dist/src/{common/generic → generic}/entity/index.d.ts +1 -1
  22. package/dist/src/{common/generic → generic}/entity/index.js +17 -17
  23. package/dist/src/generic/entity/index.js.map +1 -0
  24. package/dist/src/{common/generic → generic}/index.d.ts +2 -2
  25. package/dist/src/{common/generic → generic}/index.js +18 -18
  26. package/dist/src/generic/index.js.map +1 -0
  27. package/dist/src/{common/generic → generic}/service/index.d.ts +1 -1
  28. package/dist/src/{common/generic → generic}/service/index.js +17 -17
  29. package/dist/src/generic/service/index.js.map +1 -0
  30. package/dist/src/{common/generic → generic}/service/service.generic.d.ts +18 -18
  31. package/dist/src/{common/generic → generic}/service/service.generic.js +84 -84
  32. package/dist/src/generic/service/service.generic.js.map +1 -0
  33. package/dist/src/index.d.ts +6 -5
  34. package/dist/src/index.js +22 -21
  35. package/dist/src/index.js.map +1 -1
  36. package/dist/src/lib/index.d.ts +1 -1
  37. package/dist/src/lib/index.js +17 -17
  38. package/dist/src/lib/search-engine/document/base.document.d.ts +3 -3
  39. package/dist/src/lib/search-engine/document/base.document.js +6 -6
  40. package/dist/src/lib/search-engine/document/index.d.ts +1 -1
  41. package/dist/src/lib/search-engine/document/index.js +17 -17
  42. package/dist/src/lib/search-engine/index.d.ts +1 -1
  43. package/dist/src/lib/search-engine/index.js +17 -17
  44. package/dist/src/lib/search-engine/interface/index.d.ts +2 -2
  45. package/dist/src/lib/search-engine/interface/index.js +18 -18
  46. package/dist/src/lib/search-engine/interface/search-document.interface.d.ts +4 -4
  47. package/dist/src/lib/search-engine/interface/search-document.interface.js +2 -2
  48. package/dist/src/lib/search-engine/interface/transform-service.interface.d.ts +6 -6
  49. package/dist/src/lib/search-engine/interface/transform-service.interface.js +2 -2
  50. package/dist/src/lib/search-engine/schema/generic.schema.d.ts +2 -2
  51. package/dist/src/lib/search-engine/schema/generic.schema.js +6 -6
  52. package/dist/src/lib/search-engine/schema/index.d.ts +1 -1
  53. package/dist/src/lib/search-engine/schema/index.js +17 -17
  54. package/dist/src/lib/search-engine/typesense/index.d.ts +3 -3
  55. package/dist/src/lib/search-engine/typesense/index.js +19 -19
  56. package/dist/src/lib/search-engine/typesense/metadata/index.d.ts +2 -2
  57. package/dist/src/lib/search-engine/typesense/metadata/index.js +18 -18
  58. package/dist/src/lib/search-engine/typesense/metadata/schema.metadata.d.ts +12 -12
  59. package/dist/src/lib/search-engine/typesense/metadata/schema.metadata.js +2 -2
  60. package/dist/src/lib/search-engine/typesense/metadata/typesense.metadata-registry.d.ts +10 -10
  61. package/dist/src/lib/search-engine/typesense/metadata/typesense.metadata-registry.js +32 -33
  62. package/dist/src/lib/search-engine/typesense/metadata/typesense.metadata-registry.js.map +1 -1
  63. package/dist/src/lib/search-engine/typesense/service/client.service.d.ts +33 -33
  64. package/dist/src/lib/search-engine/typesense/service/client.service.js +196 -196
  65. package/dist/src/lib/search-engine/typesense/service/index.d.ts +1 -1
  66. package/dist/src/lib/search-engine/typesense/service/index.js +17 -17
  67. package/dist/src/lib/search-engine/typesense/typesense-module.interface.d.ts +27 -27
  68. package/dist/src/lib/search-engine/typesense/typesense-module.interface.js +2 -2
  69. package/dist/src/lib/search-engine/typesense/typesense.constants.d.ts +1 -1
  70. package/dist/src/lib/search-engine/typesense/typesense.constants.js +4 -4
  71. package/dist/src/lib/search-engine/typesense/typesense.module.d.ts +8 -8
  72. package/dist/src/lib/search-engine/typesense/typesense.module.js +67 -68
  73. package/dist/src/lib/search-engine/typesense/typesense.module.js.map +1 -1
  74. package/dist/src/lib/search-engine/typesense/typesense.module.test.d.ts +1 -1
  75. package/dist/src/lib/search-engine/typesense/typesense.module.test.js +88 -88
  76. package/dist/src/lib/search-engine/typesense/typesense.providers.d.ts +4 -4
  77. package/dist/src/lib/search-engine/typesense/typesense.providers.js +39 -39
  78. package/dist/src/response/index.d.ts +1 -1
  79. package/dist/src/response/index.js +17 -17
  80. package/dist/src/response/pagination.response.d.ts +17 -17
  81. package/dist/src/response/pagination.response.js +28 -28
  82. package/dist/src/util/date.util.d.ts +2 -2
  83. package/dist/src/util/date.util.js +13 -6
  84. package/dist/src/util/date.util.js.map +1 -1
  85. package/dist/src/util/generator.util.d.ts +4 -2
  86. package/dist/src/util/generator.util.js +28 -19
  87. package/dist/src/util/generator.util.js.map +1 -1
  88. package/dist/src/util/index.d.ts +2 -2
  89. package/dist/src/util/index.js +18 -18
  90. package/dist/tsconfig.build.tsbuildinfo +1 -1
  91. package/package.json +81 -81
  92. package/src/constant/entity-state.constant.ts +4 -4
  93. package/src/constant/index.ts +1 -1
  94. package/src/generic/entity/entity.generic.ts +34 -34
  95. package/src/generic/entity/index.ts +1 -1
  96. package/src/generic/index.ts +2 -2
  97. package/src/generic/service/index.ts +1 -1
  98. package/src/generic/service/service.generic.ts +112 -112
  99. package/src/index.ts +6 -6
  100. package/src/lib/search-engine/index.ts +1 -1
  101. package/src/lib/search-engine/interface/transform-service.interface.ts +1 -1
  102. package/src/lib/search-engine/typesense/service/client.service.ts +1 -1
  103. package/src/util/date.util.spec.ts +49 -49
  104. package/src/util/date.util.ts +10 -10
  105. package/src/util/generator.util.spec.ts +79 -79
  106. package/src/util/generator.util.ts +34 -27
  107. package/src/util/index.ts +2 -2
  108. package/dist/src/common/constant/entity-state.constant.js.map +0 -1
  109. package/dist/src/common/constant/index.js.map +0 -1
  110. package/dist/src/common/generic/entity/entity.generic.js.map +0 -1
  111. package/dist/src/common/generic/entity/index.js.map +0 -1
  112. package/dist/src/common/generic/index.js.map +0 -1
  113. package/dist/src/common/generic/service/index.js.map +0 -1
  114. package/dist/src/common/generic/service/service.generic.js.map +0 -1
  115. package/dist/src/common/index.d.ts +0 -2
  116. package/dist/src/common/index.js +0 -19
  117. package/dist/src/common/index.js.map +0 -1
@@ -1,12 +1,12 @@
1
- export interface SchemaField {
2
- name: string;
3
- type: string;
4
- facet?: boolean;
5
- index?: boolean;
6
- optional?: boolean;
7
- }
8
- export interface Schema {
9
- name: string;
10
- defaultSortingField: string;
11
- fields: Array<SchemaField>;
12
- }
1
+ export interface SchemaField {
2
+ name: string;
3
+ type: string;
4
+ facet?: boolean;
5
+ index?: boolean;
6
+ optional?: boolean;
7
+ }
8
+ export interface Schema {
9
+ name: string;
10
+ defaultSortingField: string;
11
+ fields: Array<SchemaField>;
12
+ }
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=schema.metadata.js.map
@@ -1,10 +1,10 @@
1
- import { Schema } from './schema.metadata';
2
- type Constructor = new (...args: any[]) => Record<string, unknown>;
3
- export declare class TypesenseMetadataRegistry {
4
- private logger;
5
- private schemas;
6
- addSchema(target: Constructor, schema: Schema): void;
7
- getSchemaByTarget(target: Constructor): Schema;
8
- getTargets(): IterableIterator<Constructor>;
9
- }
10
- export {};
1
+ import { Schema } from './schema.metadata';
2
+ type Constructor = new (...args: any[]) => Record<string, unknown>;
3
+ export declare class TypesenseMetadataRegistry {
4
+ private logger;
5
+ private schemas;
6
+ addSchema(target: Constructor, schema: Schema): void;
7
+ getSchemaByTarget(target: Constructor): Schema;
8
+ getTargets(): IterableIterator<Constructor>;
9
+ }
10
+ export {};
@@ -1,34 +1,33 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var TypesenseMetadataRegistry_1;
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.TypesenseMetadataRegistry = void 0;
11
- const common_1 = require("@nestjs/common");
12
- let TypesenseMetadataRegistry = TypesenseMetadataRegistry_1 = class TypesenseMetadataRegistry {
13
- constructor() {
14
- this.logger = new common_1.Logger(TypesenseMetadataRegistry_1.name);
15
- this.schemas = new Map();
16
- }
17
- addSchema(target, schema) {
18
- if (this.schemas.has(target)) {
19
- this.logger.warn(`Schema ${target} already exists`);
20
- }
21
- this.schemas.set(target, schema);
22
- }
23
- getSchemaByTarget(target) {
24
- return this.schemas.get(target);
25
- }
26
- getTargets() {
27
- return this.schemas.keys();
28
- }
29
- };
30
- TypesenseMetadataRegistry = TypesenseMetadataRegistry_1 = __decorate([
31
- (0, common_1.Injectable)()
32
- ], TypesenseMetadataRegistry);
33
- exports.TypesenseMetadataRegistry = TypesenseMetadataRegistry;
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var TypesenseMetadataRegistry_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.TypesenseMetadataRegistry = void 0;
11
+ const common_1 = require("@nestjs/common");
12
+ let TypesenseMetadataRegistry = exports.TypesenseMetadataRegistry = TypesenseMetadataRegistry_1 = class TypesenseMetadataRegistry {
13
+ constructor() {
14
+ this.logger = new common_1.Logger(TypesenseMetadataRegistry_1.name);
15
+ this.schemas = new Map();
16
+ }
17
+ addSchema(target, schema) {
18
+ if (this.schemas.has(target)) {
19
+ this.logger.warn(`Schema ${target} already exists`);
20
+ }
21
+ this.schemas.set(target, schema);
22
+ }
23
+ getSchemaByTarget(target) {
24
+ return this.schemas.get(target);
25
+ }
26
+ getTargets() {
27
+ return this.schemas.keys();
28
+ }
29
+ };
30
+ exports.TypesenseMetadataRegistry = TypesenseMetadataRegistry = TypesenseMetadataRegistry_1 = __decorate([
31
+ (0, common_1.Injectable)()
32
+ ], TypesenseMetadataRegistry);
34
33
  //# sourceMappingURL=typesense.metadata-registry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"typesense.metadata-registry.js","sourceRoot":"","sources":["../../../../../../src/lib/search-engine/typesense/metadata/typesense.metadata-registry.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAmD;AAO5C,IAAM,yBAAyB,iCAA/B,MAAM,yBAAyB;IAA/B;QACG,WAAM,GAAG,IAAI,eAAM,CAAC,2BAAyB,CAAC,IAAI,CAAC,CAAA;QAEnD,YAAO,GAA6B,IAAI,GAAG,EAAE,CAAA;IAiBvD,CAAC;IAfC,SAAS,CAAC,MAAmB,EAAE,MAAc;QAC3C,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;YAC5B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,MAAM,iBAAiB,CAAC,CAAA;SACpD;QAED,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAClC,CAAC;IAED,iBAAiB,CAAC,MAAmB;QACnC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IACjC,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAA;IAC5B,CAAC;CACF,CAAA;AApBY,yBAAyB;IADrC,IAAA,mBAAU,GAAE;GACA,yBAAyB,CAoBrC;AApBY,8DAAyB"}
1
+ {"version":3,"file":"typesense.metadata-registry.js","sourceRoot":"","sources":["../../../../../../src/lib/search-engine/typesense/metadata/typesense.metadata-registry.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAmD;AAO5C,IAAM,yBAAyB,qEAA/B,MAAM,yBAAyB;IAA/B;QACG,WAAM,GAAG,IAAI,eAAM,CAAC,2BAAyB,CAAC,IAAI,CAAC,CAAA;QAEnD,YAAO,GAA6B,IAAI,GAAG,EAAE,CAAA;IAiBvD,CAAC;IAfC,SAAS,CAAC,MAAmB,EAAE,MAAc;QAC3C,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;YAC5B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,MAAM,iBAAiB,CAAC,CAAA;SACpD;QAED,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAClC,CAAC;IAED,iBAAiB,CAAC,MAAmB;QACnC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IACjC,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAA;IAC5B,CAAC;CACF,CAAA;oCApBY,yBAAyB;IADrC,IAAA,mBAAU,GAAE;GACA,yBAAyB,CAoBrC"}
@@ -1,33 +1,33 @@
1
- import { Client } from 'typesense';
2
- import { Type } from '@nestjs/common';
3
- import { CollectionCreateSchema } from 'typesense/lib/Typesense/Collections';
4
- import { SearchParams, SearchOptions, SearchResponse, DeleteResponse, ImportResponse } from 'typesense/lib/Typesense/Documents';
5
- import { BaseDocument } from '../../document';
6
- import { SearchDocumentService } from '../../interface';
7
- import { EntityGeneric } from '../../../../common';
8
- import { PaginationResponse } from '../../../../response';
9
- export declare abstract class ClientService<Document extends BaseDocument, Entity extends EntityGeneric> implements SearchDocumentService<Document> {
10
- protected readonly client: Client;
11
- protected readonly schema: CollectionCreateSchema;
12
- protected readonly prefix: string;
13
- protected readonly entity: Type<Entity>;
14
- protected abstract cache_s: number;
15
- protected readonly skipCheckSchema: boolean;
16
- constructor(client: Client, schema: CollectionCreateSchema, prefix: string);
17
- searchDocument(searchParameters: SearchParams, options: SearchOptions): Promise<SearchResponse<any>>;
18
- getAllRawDocs: (searchParameters: SearchParams, options: SearchOptions) => Promise<import("typesense/lib/Typesense/Documents").SearchResponseHit<any>[]>;
19
- importIndex(data: Document[]): Promise<ImportResponse[]>;
20
- deleteOutOfDate(data: string[] | number[], key: string): Promise<any>;
21
- insertIndex(data: Document): Promise<any>;
22
- updateIndex(data: Document): Promise<any>;
23
- updateDocumentById: (data: Document) => Promise<{}>;
24
- upsertOrDeleteIndex(datas: Document): Promise<void>;
25
- deleteIndex(data: Document): Promise<DeleteResponse>;
26
- deleteBatchIndex(ids: string[]): Promise<DeleteResponse>;
27
- deleteIndexByKeyValue(key: string, value: number): Promise<DeleteResponse>;
28
- transforms: (searchResponse: SearchResponse<Record<string, unknown>>) => Entity[];
29
- transform: (searchResponse: SearchResponse<Record<string, unknown>>) => Entity;
30
- responseList: (searchResponse: SearchResponse<Record<string, unknown>>, offset?: number) => PaginationResponse<Entity>;
31
- private ensureCollection;
32
- private checkSchemaName;
33
- }
1
+ import { Client } from 'typesense';
2
+ import { Type } from '@nestjs/common';
3
+ import { CollectionCreateSchema } from 'typesense/lib/Typesense/Collections';
4
+ import { SearchParams, SearchOptions, SearchResponse, DeleteResponse, ImportResponse } from 'typesense/lib/Typesense/Documents';
5
+ import { BaseDocument } from '../../document';
6
+ import { SearchDocumentService } from '../../interface';
7
+ import { EntityGeneric } from '../../../../generic';
8
+ import { PaginationResponse } from '../../../../response';
9
+ export declare abstract class ClientService<Document extends BaseDocument, Entity extends EntityGeneric> implements SearchDocumentService<Document> {
10
+ protected readonly client: Client;
11
+ protected readonly schema: CollectionCreateSchema;
12
+ protected readonly prefix: string;
13
+ protected readonly entity: Type<Entity>;
14
+ protected abstract cache_s: number;
15
+ protected readonly skipCheckSchema: boolean;
16
+ constructor(client: Client, schema: CollectionCreateSchema, prefix: string);
17
+ searchDocument(searchParameters: SearchParams, options: SearchOptions): Promise<SearchResponse<any>>;
18
+ getAllRawDocs: (searchParameters: SearchParams, options: SearchOptions) => Promise<import("typesense/lib/Typesense/Documents").SearchResponseHit<any>[]>;
19
+ importIndex(data: Document[]): Promise<ImportResponse[]>;
20
+ deleteOutOfDate(data: string[] | number[], key: string): Promise<any>;
21
+ insertIndex(data: Document): Promise<any>;
22
+ updateIndex(data: Document): Promise<any>;
23
+ updateDocumentById: (data: Document) => Promise<{}>;
24
+ upsertOrDeleteIndex(datas: Document): Promise<void>;
25
+ deleteIndex(data: Document): Promise<DeleteResponse>;
26
+ deleteBatchIndex(ids: string[]): Promise<DeleteResponse>;
27
+ deleteIndexByKeyValue(key: string, value: number): Promise<DeleteResponse>;
28
+ transforms: (searchResponse: SearchResponse<Record<string, unknown>>) => Entity[];
29
+ transform: (searchResponse: SearchResponse<Record<string, unknown>>) => Entity;
30
+ responseList: (searchResponse: SearchResponse<Record<string, unknown>>, offset?: number) => PaginationResponse<Entity>;
31
+ private ensureCollection;
32
+ private checkSchemaName;
33
+ }
@@ -1,197 +1,197 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ClientService = void 0;
4
- const class_transformer_1 = require("class-transformer");
5
- const response_1 = require("../../../../response");
6
- class ClientService {
7
- constructor(client, schema, prefix) {
8
- this.client = client;
9
- this.schema = schema;
10
- this.prefix = prefix;
11
- this.skipCheckSchema = false;
12
- this.getAllRawDocs = async (searchParameters, options) => {
13
- var _a;
14
- searchParameters.per_page = (_a = searchParameters.per_page) !== null && _a !== void 0 ? _a : 250;
15
- options.cacheSearchResultsForSeconds = 1;
16
- const response = await this.searchDocument(searchParameters, options);
17
- const { hits = [], found = 0, page = 1 } = response;
18
- let documents = hits;
19
- const hasNext = hits.length * page < found;
20
- if (hasNext) {
21
- searchParameters.page = page + 1;
22
- documents = await this.getAllRawDocs(searchParameters, options);
23
- }
24
- return documents;
25
- };
26
- this.updateDocumentById = async (data) => {
27
- var _a, _b;
28
- if (data === null || data === void 0 ? void 0 : data.id) {
29
- const exist = await this.client
30
- .collections(((_a = this === null || this === void 0 ? void 0 : this.schema) === null || _a === void 0 ? void 0 : _a.name) || this.prefix)
31
- .documents(data.id)
32
- .retrieve();
33
- if (exist) {
34
- return this.client
35
- .collections(((_b = this === null || this === void 0 ? void 0 : this.schema) === null || _b === void 0 ? void 0 : _b.name) || this.prefix)
36
- .documents(data.id)
37
- .update(data);
38
- }
39
- }
40
- };
41
- this.transforms = (searchResponse) => {
42
- const entities = [];
43
- const { hits = [] } = Object.assign({}, searchResponse);
44
- for (const hit of hits) {
45
- const document = hit === null || hit === void 0 ? void 0 : hit.document;
46
- if (document) {
47
- const entity = (0, class_transformer_1.plainToClass)(this.entity, document);
48
- entity.id = Number(document.id);
49
- entities.push(entity);
50
- }
51
- }
52
- return entities;
53
- };
54
- this.transform = (searchResponse) => {
55
- let entity = null;
56
- const { hits = [] } = Object.assign({}, searchResponse);
57
- for (const hit of hits) {
58
- const document = hit === null || hit === void 0 ? void 0 : hit.document;
59
- if (document) {
60
- entity = (0, class_transformer_1.plainToClass)(this.entity, document);
61
- entity.id = Number(document.id);
62
- }
63
- break;
64
- }
65
- return entity;
66
- };
67
- this.responseList = (searchResponse, offset = 0) => {
68
- const entities = [];
69
- const { hits = [], found = 0, page = 1, request_params, } = Object.assign({}, searchResponse);
70
- for (const hit of hits) {
71
- const document = hit === null || hit === void 0 ? void 0 : hit.document;
72
- if (document) {
73
- const entity = (0, class_transformer_1.plainToClass)(this.entity, document);
74
- entity.id = Number(document.id);
75
- entities.push(entity);
76
- }
77
- }
78
- const limit = request_params === null || request_params === void 0 ? void 0 : request_params.per_page;
79
- return new response_1.PaginationResponse(entities, found, limit, offset);
80
- };
81
- this.ensureCollection = async () => {
82
- this.checkSchemaName();
83
- const exists = await this.client.collections(this.schema.name).exists();
84
- if (!exists) {
85
- await this.client.collections().create(this.schema);
86
- }
87
- };
88
- this.checkSchemaName = () => {
89
- const schemaName = this.schema.name.replace(/.*?\_/gi, '');
90
- this.schema.name = `${this.prefix}_${schemaName}`;
91
- };
92
- if (!this.skipCheckSchema && schema != null) {
93
- this.ensureCollection();
94
- }
95
- }
96
- async searchDocument(searchParameters, options) {
97
- var _a, _b, _c;
98
- try {
99
- const { includeIds = [], per_page = 25 } = Object.assign({}, searchParameters);
100
- const includeDocuments = [];
101
- if (includeIds.length > 0) {
102
- const includeOpts = Object.assign(Object.assign({}, searchParameters), { filter_by: `id:=[${includeIds.join(', ')}]` });
103
- const includeDocs = await this.client
104
- .collections(((_a = this === null || this === void 0 ? void 0 : this.schema) === null || _a === void 0 ? void 0 : _a.name) || this.prefix)
105
- .documents()
106
- .search(includeOpts, options);
107
- if (((_b = includeDocs === null || includeDocs === void 0 ? void 0 : includeDocs.hits) === null || _b === void 0 ? void 0 : _b.length) > 0) {
108
- const names = includeDocs.hits.map((data) => data.document.name);
109
- searchParameters.filter_by =
110
- searchParameters.filter_by == null
111
- ? `name:!=[${names.join(', ')}]`
112
- : `${searchParameters.filter_by} && name:!=[${names.join(', ')}]`;
113
- searchParameters.per_page = per_page - names.length;
114
- }
115
- includeDocuments.push(...includeDocs === null || includeDocs === void 0 ? void 0 : includeDocs.hits);
116
- }
117
- const documents = await this.client
118
- .collections(((_c = this === null || this === void 0 ? void 0 : this.schema) === null || _c === void 0 ? void 0 : _c.name) || this.prefix)
119
- .documents()
120
- .search(searchParameters, options);
121
- if (includeDocuments.length > 0) {
122
- documents.hits.push(...includeDocuments);
123
- documents.request_params.per_page = per_page;
124
- }
125
- return documents;
126
- }
127
- catch (error) {
128
- return null;
129
- }
130
- }
131
- async importIndex(data) {
132
- var _a;
133
- if (data.length > 0) {
134
- try {
135
- return this.client
136
- .collections(((_a = this === null || this === void 0 ? void 0 : this.schema) === null || _a === void 0 ? void 0 : _a.name) || this.prefix)
137
- .documents()
138
- .import(data, { action: 'upsert' });
139
- }
140
- catch (error) {
141
- console.log(error);
142
- }
143
- }
144
- }
145
- async deleteOutOfDate(data, key) {
146
- var _a;
147
- if ((data === null || data === void 0 ? void 0 : data.length) > 0) {
148
- const deleteParameters = {
149
- filter_by: `${key}:!=[${data.join(', ')}]`,
150
- };
151
- return await this.client
152
- .collections(((_a = this === null || this === void 0 ? void 0 : this.schema) === null || _a === void 0 ? void 0 : _a.name) || this.prefix)
153
- .documents()
154
- .delete(deleteParameters);
155
- }
156
- }
157
- async insertIndex(data) {
158
- var _a;
159
- return this.client
160
- .collections(((_a = this === null || this === void 0 ? void 0 : this.schema) === null || _a === void 0 ? void 0 : _a.name) || this.prefix)
161
- .documents()
162
- .create(data, { action: 'upsert' });
163
- }
164
- async updateIndex(data) {
165
- var _a;
166
- return this.client
167
- .collections(((_a = this === null || this === void 0 ? void 0 : this.schema) === null || _a === void 0 ? void 0 : _a.name) || this.prefix)
168
- .documents()
169
- .upsert(data, { action: 'upsert' });
170
- }
171
- async upsertOrDeleteIndex(datas) {
172
- throw new Error('Method is not implement.');
173
- }
174
- async deleteIndex(data) {
175
- var _a;
176
- return this.client
177
- .collections(((_a = this === null || this === void 0 ? void 0 : this.schema) === null || _a === void 0 ? void 0 : _a.name) || this.prefix)
178
- .documents()
179
- .delete({ filter_by: `id: ${data.id}` });
180
- }
181
- async deleteBatchIndex(ids) {
182
- var _a;
183
- return this.client
184
- .collections(((_a = this === null || this === void 0 ? void 0 : this.schema) === null || _a === void 0 ? void 0 : _a.name) || this.prefix)
185
- .documents()
186
- .delete({ filter_by: `id: [${ids.join(',')}]` });
187
- }
188
- async deleteIndexByKeyValue(key = 'id', value) {
189
- var _a;
190
- return this.client
191
- .collections(((_a = this === null || this === void 0 ? void 0 : this.schema) === null || _a === void 0 ? void 0 : _a.name) || this.prefix)
192
- .documents()
193
- .delete({ filter_by: `${key}:=${value}` });
194
- }
195
- }
196
- exports.ClientService = ClientService;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClientService = void 0;
4
+ const class_transformer_1 = require("class-transformer");
5
+ const response_1 = require("../../../../response");
6
+ class ClientService {
7
+ constructor(client, schema, prefix) {
8
+ this.client = client;
9
+ this.schema = schema;
10
+ this.prefix = prefix;
11
+ this.skipCheckSchema = false;
12
+ this.getAllRawDocs = async (searchParameters, options) => {
13
+ var _a;
14
+ searchParameters.per_page = (_a = searchParameters.per_page) !== null && _a !== void 0 ? _a : 250;
15
+ options.cacheSearchResultsForSeconds = 1;
16
+ const response = await this.searchDocument(searchParameters, options);
17
+ const { hits = [], found = 0, page = 1 } = response;
18
+ let documents = hits;
19
+ const hasNext = hits.length * page < found;
20
+ if (hasNext) {
21
+ searchParameters.page = page + 1;
22
+ documents = await this.getAllRawDocs(searchParameters, options);
23
+ }
24
+ return documents;
25
+ };
26
+ this.updateDocumentById = async (data) => {
27
+ var _a, _b;
28
+ if (data === null || data === void 0 ? void 0 : data.id) {
29
+ const exist = await this.client
30
+ .collections(((_a = this === null || this === void 0 ? void 0 : this.schema) === null || _a === void 0 ? void 0 : _a.name) || this.prefix)
31
+ .documents(data.id)
32
+ .retrieve();
33
+ if (exist) {
34
+ return this.client
35
+ .collections(((_b = this === null || this === void 0 ? void 0 : this.schema) === null || _b === void 0 ? void 0 : _b.name) || this.prefix)
36
+ .documents(data.id)
37
+ .update(data);
38
+ }
39
+ }
40
+ };
41
+ this.transforms = (searchResponse) => {
42
+ const entities = [];
43
+ const { hits = [] } = Object.assign({}, searchResponse);
44
+ for (const hit of hits) {
45
+ const document = hit === null || hit === void 0 ? void 0 : hit.document;
46
+ if (document) {
47
+ const entity = (0, class_transformer_1.plainToClass)(this.entity, document);
48
+ entity.id = Number(document.id);
49
+ entities.push(entity);
50
+ }
51
+ }
52
+ return entities;
53
+ };
54
+ this.transform = (searchResponse) => {
55
+ let entity = null;
56
+ const { hits = [] } = Object.assign({}, searchResponse);
57
+ for (const hit of hits) {
58
+ const document = hit === null || hit === void 0 ? void 0 : hit.document;
59
+ if (document) {
60
+ entity = (0, class_transformer_1.plainToClass)(this.entity, document);
61
+ entity.id = Number(document.id);
62
+ }
63
+ break;
64
+ }
65
+ return entity;
66
+ };
67
+ this.responseList = (searchResponse, offset = 0) => {
68
+ const entities = [];
69
+ const { hits = [], found = 0, page = 1, request_params, } = Object.assign({}, searchResponse);
70
+ for (const hit of hits) {
71
+ const document = hit === null || hit === void 0 ? void 0 : hit.document;
72
+ if (document) {
73
+ const entity = (0, class_transformer_1.plainToClass)(this.entity, document);
74
+ entity.id = Number(document.id);
75
+ entities.push(entity);
76
+ }
77
+ }
78
+ const limit = request_params === null || request_params === void 0 ? void 0 : request_params.per_page;
79
+ return new response_1.PaginationResponse(entities, found, limit, offset);
80
+ };
81
+ this.ensureCollection = async () => {
82
+ this.checkSchemaName();
83
+ const exists = await this.client.collections(this.schema.name).exists();
84
+ if (!exists) {
85
+ await this.client.collections().create(this.schema);
86
+ }
87
+ };
88
+ this.checkSchemaName = () => {
89
+ const schemaName = this.schema.name.replace(/.*?\_/gi, '');
90
+ this.schema.name = `${this.prefix}_${schemaName}`;
91
+ };
92
+ if (!this.skipCheckSchema && schema != null) {
93
+ this.ensureCollection();
94
+ }
95
+ }
96
+ async searchDocument(searchParameters, options) {
97
+ var _a, _b, _c;
98
+ try {
99
+ const { includeIds = [], per_page = 25 } = Object.assign({}, searchParameters);
100
+ const includeDocuments = [];
101
+ if (includeIds.length > 0) {
102
+ const includeOpts = Object.assign(Object.assign({}, searchParameters), { filter_by: `id:=[${includeIds.join(', ')}]` });
103
+ const includeDocs = await this.client
104
+ .collections(((_a = this === null || this === void 0 ? void 0 : this.schema) === null || _a === void 0 ? void 0 : _a.name) || this.prefix)
105
+ .documents()
106
+ .search(includeOpts, options);
107
+ if (((_b = includeDocs === null || includeDocs === void 0 ? void 0 : includeDocs.hits) === null || _b === void 0 ? void 0 : _b.length) > 0) {
108
+ const names = includeDocs.hits.map((data) => data.document.name);
109
+ searchParameters.filter_by =
110
+ searchParameters.filter_by == null
111
+ ? `name:!=[${names.join(', ')}]`
112
+ : `${searchParameters.filter_by} && name:!=[${names.join(', ')}]`;
113
+ searchParameters.per_page = per_page - names.length;
114
+ }
115
+ includeDocuments.push(...includeDocs === null || includeDocs === void 0 ? void 0 : includeDocs.hits);
116
+ }
117
+ const documents = await this.client
118
+ .collections(((_c = this === null || this === void 0 ? void 0 : this.schema) === null || _c === void 0 ? void 0 : _c.name) || this.prefix)
119
+ .documents()
120
+ .search(searchParameters, options);
121
+ if (includeDocuments.length > 0) {
122
+ documents.hits.push(...includeDocuments);
123
+ documents.request_params.per_page = per_page;
124
+ }
125
+ return documents;
126
+ }
127
+ catch (error) {
128
+ return null;
129
+ }
130
+ }
131
+ async importIndex(data) {
132
+ var _a;
133
+ if (data.length > 0) {
134
+ try {
135
+ return this.client
136
+ .collections(((_a = this === null || this === void 0 ? void 0 : this.schema) === null || _a === void 0 ? void 0 : _a.name) || this.prefix)
137
+ .documents()
138
+ .import(data, { action: 'upsert' });
139
+ }
140
+ catch (error) {
141
+ console.log(error);
142
+ }
143
+ }
144
+ }
145
+ async deleteOutOfDate(data, key) {
146
+ var _a;
147
+ if ((data === null || data === void 0 ? void 0 : data.length) > 0) {
148
+ const deleteParameters = {
149
+ filter_by: `${key}:!=[${data.join(', ')}]`,
150
+ };
151
+ return await this.client
152
+ .collections(((_a = this === null || this === void 0 ? void 0 : this.schema) === null || _a === void 0 ? void 0 : _a.name) || this.prefix)
153
+ .documents()
154
+ .delete(deleteParameters);
155
+ }
156
+ }
157
+ async insertIndex(data) {
158
+ var _a;
159
+ return this.client
160
+ .collections(((_a = this === null || this === void 0 ? void 0 : this.schema) === null || _a === void 0 ? void 0 : _a.name) || this.prefix)
161
+ .documents()
162
+ .create(data, { action: 'upsert' });
163
+ }
164
+ async updateIndex(data) {
165
+ var _a;
166
+ return this.client
167
+ .collections(((_a = this === null || this === void 0 ? void 0 : this.schema) === null || _a === void 0 ? void 0 : _a.name) || this.prefix)
168
+ .documents()
169
+ .upsert(data, { action: 'upsert' });
170
+ }
171
+ async upsertOrDeleteIndex(datas) {
172
+ throw new Error('Method is not implement.');
173
+ }
174
+ async deleteIndex(data) {
175
+ var _a;
176
+ return this.client
177
+ .collections(((_a = this === null || this === void 0 ? void 0 : this.schema) === null || _a === void 0 ? void 0 : _a.name) || this.prefix)
178
+ .documents()
179
+ .delete({ filter_by: `id: ${data.id}` });
180
+ }
181
+ async deleteBatchIndex(ids) {
182
+ var _a;
183
+ return this.client
184
+ .collections(((_a = this === null || this === void 0 ? void 0 : this.schema) === null || _a === void 0 ? void 0 : _a.name) || this.prefix)
185
+ .documents()
186
+ .delete({ filter_by: `id: [${ids.join(',')}]` });
187
+ }
188
+ async deleteIndexByKeyValue(key = 'id', value) {
189
+ var _a;
190
+ return this.client
191
+ .collections(((_a = this === null || this === void 0 ? void 0 : this.schema) === null || _a === void 0 ? void 0 : _a.name) || this.prefix)
192
+ .documents()
193
+ .delete({ filter_by: `${key}:=${value}` });
194
+ }
195
+ }
196
+ exports.ClientService = ClientService;
197
197
  //# sourceMappingURL=client.service.js.map
@@ -1 +1 @@
1
- export * from './client.service';
1
+ export * from './client.service';
@@ -1,18 +1,18 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./client.service"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./client.service"), exports);
18
18
  //# sourceMappingURL=index.js.map