mm-share-lib 0.0.5 → 0.0.6
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.
- package/.eslintrc.js +25 -25
- package/.prettierrc +3 -3
- package/README.md +73 -73
- package/dist/src/exception/index.d.ts +0 -7
- package/dist/src/exception/index.js +0 -23
- package/dist/src/exception/index.js.map +1 -1
- package/index.ts +1 -1
- package/nest-cli.json +8 -8
- package/package.json +91 -82
- package/src/auth/apple/apple.module.ts +10 -0
- package/src/auth/apple/apple.service.ts +28 -0
- package/src/auth/apple/dto/apple-login.dto.ts +16 -0
- package/src/auth/apple/dto/index.ts +1 -0
- package/src/auth/apple/index.ts +3 -0
- package/src/auth/config/apple.config.ts +18 -0
- package/src/auth/config/auth.config.ts +29 -0
- package/src/auth/config/facebook.config.ts +23 -0
- package/src/auth/config/file.config.ts +50 -0
- package/src/auth/config/google.config.ts +23 -0
- package/src/auth/config/index.ts +6 -0
- package/src/auth/config/twitter.config.ts +22 -0
- package/src/auth/facebook/dto/facebook-login.dto.ts +8 -0
- package/src/auth/facebook/dto/index.ts +1 -0
- package/src/auth/facebook/facebook.module.ts +11 -0
- package/src/auth/facebook/facebook.service.ts +51 -0
- package/src/auth/facebook/index.ts +4 -0
- package/src/auth/facebook/interface/facebook.interface.ts +6 -0
- package/src/auth/facebook/interface/index.ts +1 -0
- package/src/auth/google/dto/google-login.dto.ts +8 -0
- package/src/auth/google/dto/index.ts +1 -0
- package/src/auth/google/google.module.ts +10 -0
- package/src/auth/google/google.service.ts +51 -0
- package/src/auth/google/index.ts +3 -0
- package/src/auth/index.ts +5 -0
- package/src/auth/twitter/dto/index.ts +1 -0
- package/src/auth/twitter/dto/twitter-login.dto.ts +12 -0
- package/src/auth/twitter/index.ts +3 -0
- package/src/auth/twitter/twitter.module.ts +11 -0
- package/src/auth/twitter/twitter.service.ts +43 -0
- package/src/config/index.ts +1 -0
- package/src/config/type.config.ts +88 -0
- package/src/constant/entity-state.constant.ts +4 -4
- package/src/constant/index.ts +1 -1
- package/src/dto/base-filter.dto.ts +4 -4
- package/src/dto/index.ts +2 -2
- package/src/dto/pagination.dto.ts +16 -4
- package/src/filter/index.ts +1 -1
- package/src/filter/rpc-exception.filter.ts +15 -0
- package/src/generic/entity/entity.generic.ts +34 -34
- package/src/generic/entity/index.ts +1 -1
- package/src/generic/index.ts +2 -2
- package/src/generic/service/index.ts +1 -1
- package/src/generic/service/service.generic.ts +112 -112
- package/src/index.ts +1 -0
- package/src/interface/index.ts +1 -0
- package/src/interface/social.interface.ts +6 -0
- package/src/lib/index.ts +3 -1
- package/src/lib/mailer/config/index.ts +1 -0
- package/src/lib/mailer/config/mailer.config.ts +62 -0
- package/src/lib/mailer/index.ts +2 -0
- package/src/lib/mailer/mailer.module.ts +8 -0
- package/src/lib/mailer/mailer.service.ts +53 -0
- package/src/lib/search-engine/document/base.document.ts +3 -3
- package/src/lib/search-engine/index.ts +1 -1
- package/src/lib/search-engine/interface/index.ts +1 -1
- package/src/lib/search-engine/interface/search-document.interface.ts +13 -5
- package/src/lib/search-engine/interface/transform-service.interface.ts +10 -10
- package/src/lib/search-engine/schema/generic.schema.ts +1 -1
- package/src/lib/search-engine/schema/index.ts +1 -1
- package/src/lib/search-engine/typesense/collection/index.ts +1 -0
- package/src/lib/search-engine/typesense/document/index.ts +1 -0
- package/src/lib/search-engine/typesense/index.ts +4 -3
- package/src/lib/search-engine/typesense/metadata/index.ts +1 -1
- package/src/lib/search-engine/typesense/metadata/schema.metadata.ts +13 -13
- package/src/lib/search-engine/typesense/metadata/typesense.metadata-registry.ts +28 -28
- package/src/lib/search-engine/typesense/service/client.service.ts +260 -258
- package/src/lib/search-engine/typesense/typesense-module.interface.ts +36 -36
- package/src/lib/search-engine/typesense/typesense.constants.ts +1 -1
- package/src/lib/search-engine/typesense/typesense.module.test.ts +94 -94
- package/src/lib/search-engine/typesense/typesense.module.ts +76 -76
- package/src/lib/search-engine/typesense/typesense.providers.ts +42 -42
- package/src/lib/storage/index.ts +0 -0
- package/src/lib/typesense/client/index.ts +1 -0
- package/src/lib/typesense/collection/index.ts +1 -0
- package/src/lib/typesense/decorator/field.decorator.spec.ts +89 -0
- package/src/lib/typesense/decorator/field.decorator.ts +44 -0
- package/src/lib/typesense/decorator/index.ts +2 -0
- package/src/lib/typesense/decorator/schema.decorator.ts +23 -0
- package/src/lib/typesense/document/base.document.ts +3 -0
- package/src/lib/typesense/index.ts +6 -0
- package/src/lib/typesense/metadata/index.ts +4 -0
- package/src/lib/typesense/metadata/schema.metadata.ts +21 -0
- package/src/lib/typesense/metadata/typesense.metadata-accessor.ts +37 -0
- package/src/lib/typesense/metadata/typesense.metadata-explorer.spec.ts +56 -0
- package/src/lib/typesense/metadata/typesense.metadata-explorer.ts +41 -0
- package/src/lib/typesense/metadata/typesense.metadata-registry.ts +28 -0
- package/src/lib/typesense/module/index.ts +4 -0
- package/src/lib/typesense/module/interface.module.ts +34 -0
- package/src/lib/typesense/module/typesense.constant.ts +1 -0
- package/src/lib/typesense/module/typesense.module.spec.ts +94 -0
- package/src/lib/typesense/module/typesense.module.ts +87 -0
- package/src/lib/typesense/module/typesense.provider.ts +54 -0
- package/src/response/base-entity.response.ts +8 -0
- package/src/response/index.ts +2 -1
- package/src/response/login.response.ts +0 -0
- package/src/response/pagination.response.ts +52 -37
- package/src/setup/index.ts +1 -1
- package/src/util/date.util.spec.ts +49 -49
- package/src/util/date.util.ts +10 -10
- package/src/util/generator.util.spec.ts +79 -79
- package/src/util/generator.util.ts +34 -34
- package/src/util/index.ts +4 -3
- package/src/util/validate-config.ts +20 -0
- package/test/app.e2e-spec.ts +24 -24
- package/test/jest-e2e.json +9 -9
- package/tsconfig.build.json +4 -4
- package/tsconfig.json +21 -21
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -18
- package/dist/index.js.map +0 -1
- package/dist/src/dto/base-filter.dto.d.ts +0 -4
- package/dist/src/dto/base-filter.dto.js +0 -11
- package/dist/src/dto/base-filter.dto.js.map +0 -1
- package/dist/src/dto/index.d.ts +0 -2
- package/dist/src/dto/index.js +0 -19
- package/dist/src/dto/index.js.map +0 -1
- package/dist/src/dto/pagination.dto.d.ts +0 -4
- package/dist/src/dto/pagination.dto.js +0 -11
- package/dist/src/dto/pagination.dto.js.map +0 -1
- package/dist/src/exception/bad-request-error.exception.d.ts +0 -4
- package/dist/src/exception/bad-request-error.exception.js +0 -12
- package/dist/src/exception/bad-request-error.exception.js.map +0 -1
- package/dist/src/exception/base.exception.d.ts +0 -21
- package/dist/src/exception/base.exception.js +0 -16
- package/dist/src/exception/base.exception.js.map +0 -1
- package/dist/src/exception/conflict-error.exception.d.ts +0 -4
- package/dist/src/exception/conflict-error.exception.js +0 -12
- package/dist/src/exception/conflict-error.exception.js.map +0 -1
- package/dist/src/exception/forbidden-error.exception.d.ts +0 -4
- package/dist/src/exception/forbidden-error.exception.js +0 -12
- package/dist/src/exception/forbidden-error.exception.js.map +0 -1
- package/dist/src/exception/internal-server-error.exception.d.ts +0 -4
- package/dist/src/exception/internal-server-error.exception.js +0 -12
- package/dist/src/exception/internal-server-error.exception.js.map +0 -1
- package/dist/src/exception/not-found-error.exception.d.ts +0 -4
- package/dist/src/exception/not-found-error.exception.js +0 -12
- package/dist/src/exception/not-found-error.exception.js.map +0 -1
- package/dist/src/exception/unauthorized-error.exception.d.ts +0 -4
- package/dist/src/exception/unauthorized-error.exception.js +0 -12
- package/dist/src/exception/unauthorized-error.exception.js.map +0 -1
- package/dist/src/filter/http-exception.filter.d.ts +0 -4
- package/dist/src/filter/http-exception.filter.js +0 -27
- package/dist/src/filter/http-exception.filter.js.map +0 -1
- package/dist/src/filter/index.d.ts +0 -1
- package/dist/src/filter/index.js +0 -18
- package/dist/src/filter/index.js.map +0 -1
- package/dist/src/index.d.ts +0 -8
- package/dist/src/index.js +0 -25
- package/dist/src/index.js.map +0 -1
- package/dist/src/lib/index.d.ts +0 -1
- package/dist/src/lib/index.js +0 -18
- package/dist/src/lib/index.js.map +0 -1
- package/dist/src/lib/search-engine/document/base.document.d.ts +0 -3
- package/dist/src/lib/search-engine/document/base.document.js +0 -7
- package/dist/src/lib/search-engine/document/base.document.js.map +0 -1
- package/dist/src/lib/search-engine/document/index.js +0 -18
- package/dist/src/lib/search-engine/document/index.js.map +0 -1
- package/dist/src/lib/search-engine/index.d.ts +0 -1
- package/dist/src/lib/search-engine/index.js +0 -18
- package/dist/src/lib/search-engine/index.js.map +0 -1
- package/dist/src/lib/search-engine/interface/index.d.ts +0 -2
- package/dist/src/lib/search-engine/interface/index.js +0 -19
- package/dist/src/lib/search-engine/interface/index.js.map +0 -1
- package/dist/src/lib/search-engine/interface/search-document.interface.d.ts +0 -4
- package/dist/src/lib/search-engine/interface/search-document.interface.js +0 -3
- package/dist/src/lib/search-engine/interface/search-document.interface.js.map +0 -1
- package/dist/src/lib/search-engine/interface/transform-service.interface.d.ts +0 -6
- package/dist/src/lib/search-engine/interface/transform-service.interface.js +0 -3
- package/dist/src/lib/search-engine/interface/transform-service.interface.js.map +0 -1
- package/dist/src/lib/search-engine/schema/generic.schema.d.ts +0 -2
- package/dist/src/lib/search-engine/schema/generic.schema.js +0 -7
- package/dist/src/lib/search-engine/schema/generic.schema.js.map +0 -1
- package/dist/src/lib/search-engine/schema/index.d.ts +0 -1
- package/dist/src/lib/search-engine/schema/index.js +0 -18
- package/dist/src/lib/search-engine/schema/index.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/index.d.ts +0 -3
- package/dist/src/lib/search-engine/typesense/index.js +0 -20
- package/dist/src/lib/search-engine/typesense/index.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/metadata/index.d.ts +0 -2
- package/dist/src/lib/search-engine/typesense/metadata/index.js +0 -19
- package/dist/src/lib/search-engine/typesense/metadata/index.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/metadata/schema.metadata.d.ts +0 -12
- package/dist/src/lib/search-engine/typesense/metadata/schema.metadata.js +0 -3
- package/dist/src/lib/search-engine/typesense/metadata/schema.metadata.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/metadata/typesense.metadata-registry.d.ts +0 -10
- package/dist/src/lib/search-engine/typesense/metadata/typesense.metadata-registry.js +0 -33
- package/dist/src/lib/search-engine/typesense/metadata/typesense.metadata-registry.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/service/client.service.d.ts +0 -33
- package/dist/src/lib/search-engine/typesense/service/client.service.js +0 -197
- package/dist/src/lib/search-engine/typesense/service/client.service.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/service/index.d.ts +0 -1
- package/dist/src/lib/search-engine/typesense/service/index.js +0 -18
- package/dist/src/lib/search-engine/typesense/service/index.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/typesense-module.interface.d.ts +0 -27
- package/dist/src/lib/search-engine/typesense/typesense-module.interface.js +0 -3
- package/dist/src/lib/search-engine/typesense/typesense-module.interface.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/typesense.constants.d.ts +0 -1
- package/dist/src/lib/search-engine/typesense/typesense.constants.js +0 -5
- package/dist/src/lib/search-engine/typesense/typesense.constants.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/typesense.module.d.ts +0 -8
- package/dist/src/lib/search-engine/typesense/typesense.module.js +0 -68
- package/dist/src/lib/search-engine/typesense/typesense.module.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/typesense.module.test.d.ts +0 -1
- package/dist/src/lib/search-engine/typesense/typesense.module.test.js +0 -89
- package/dist/src/lib/search-engine/typesense/typesense.module.test.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/typesense.providers.d.ts +0 -4
- package/dist/src/lib/search-engine/typesense/typesense.providers.js +0 -40
- package/dist/src/lib/search-engine/typesense/typesense.providers.js.map +0 -1
- package/dist/src/response/index.d.ts +0 -1
- package/dist/src/response/index.js +0 -18
- package/dist/src/response/index.js.map +0 -1
- package/dist/src/response/pagination.response.d.ts +0 -17
- package/dist/src/response/pagination.response.js +0 -29
- package/dist/src/response/pagination.response.js.map +0 -1
- package/dist/src/setup/index.d.ts +0 -1
- package/dist/src/setup/index.js +0 -18
- package/dist/src/setup/index.js.map +0 -1
- package/dist/src/setup/microservice.setup.d.ts +0 -2
- package/dist/src/setup/microservice.setup.js +0 -25
- package/dist/src/setup/microservice.setup.js.map +0 -1
- package/dist/src/setup/swagger.setup.js +0 -1
- package/dist/src/setup/swagger.setup.js.map +0 -1
- package/dist/src/util/app.utils.d.ts +0 -4
- package/dist/src/util/app.utils.js +0 -21
- package/dist/src/util/app.utils.js.map +0 -1
- package/dist/src/util/date.util.d.ts +0 -2
- package/dist/src/util/date.util.js +0 -14
- package/dist/src/util/date.util.js.map +0 -1
- package/dist/src/util/generator.util.d.ts +0 -4
- package/dist/src/util/generator.util.js +0 -29
- package/dist/src/util/generator.util.js.map +0 -1
- package/dist/src/util/index.d.ts +0 -3
- package/dist/src/util/index.js +0 -20
- package/dist/src/util/index.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- /package/{dist/src/setup/swagger.setup.d.ts → src/lib/redis/index.ts} +0 -0
- /package/{dist/src/lib/search-engine/document/index.d.ts → src/lib/typesense/document/index.ts} +0 -0
@@ -1,258 +1,260 @@
|
|
1
|
-
import { Client } from 'typesense';
|
2
|
-
import { Logger, Type } from '@nestjs/common';
|
3
|
-
import { plainToClass } from 'class-transformer';
|
4
|
-
import { CollectionCreateSchema } from '
|
5
|
-
import {
|
6
|
-
SearchParams,
|
7
|
-
SearchOptions,
|
8
|
-
SearchResponse,
|
9
|
-
DeleteResponse,
|
10
|
-
ImportResponse,
|
11
|
-
} from '
|
12
|
-
import { BaseDocument } from '../../document';
|
13
|
-
import { SearchDocumentService } from '../../interface';
|
14
|
-
import { EntityGeneric } from '../../../../generic';
|
15
|
-
import { PaginationResponse } from '../../../../response';
|
16
|
-
|
17
|
-
export abstract class ClientService<
|
18
|
-
Document extends BaseDocument,
|
19
|
-
Entity extends EntityGeneric,
|
20
|
-
> implements SearchDocumentService<Document>
|
21
|
-
{
|
22
|
-
|
23
|
-
protected
|
24
|
-
protected
|
25
|
-
|
26
|
-
|
27
|
-
protected readonly
|
28
|
-
protected readonly
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
//
|
37
|
-
//
|
38
|
-
//
|
39
|
-
//
|
40
|
-
//
|
41
|
-
//
|
42
|
-
//
|
43
|
-
//
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
.
|
61
|
-
.
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
.
|
77
|
-
.
|
78
|
-
|
79
|
-
|
80
|
-
documents.
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
const
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
.
|
112
|
-
|
113
|
-
|
114
|
-
}
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
.
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
.
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
.
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
.
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
.
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
.
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
.
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
.
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
}
|
1
|
+
import { Client } from 'typesense';
|
2
|
+
import { Logger, Type } from '@nestjs/common';
|
3
|
+
import { plainToClass } from 'class-transformer';
|
4
|
+
import { CollectionCreateSchema } from '../collection';
|
5
|
+
import {
|
6
|
+
SearchParams,
|
7
|
+
SearchOptions,
|
8
|
+
SearchResponse,
|
9
|
+
DeleteResponse,
|
10
|
+
ImportResponse,
|
11
|
+
} from '../document';
|
12
|
+
import { BaseDocument } from '../../document';
|
13
|
+
import { SearchDocumentService } from '../../interface';
|
14
|
+
import { EntityGeneric } from '../../../../generic';
|
15
|
+
import { PaginationResponse } from '../../../../response';
|
16
|
+
|
17
|
+
export abstract class ClientService<
|
18
|
+
Document extends BaseDocument,
|
19
|
+
Entity extends EntityGeneric,
|
20
|
+
> implements SearchDocumentService<Document>
|
21
|
+
{
|
22
|
+
private readonly logger = new Logger(ClientService.name);
|
23
|
+
protected readonly entity: Type<Entity>;
|
24
|
+
protected abstract cache_s: number;
|
25
|
+
protected readonly skipCheckSchema: boolean = false;
|
26
|
+
constructor(
|
27
|
+
protected readonly client: Client,
|
28
|
+
protected readonly schema: CollectionCreateSchema,
|
29
|
+
protected readonly prefix: string,
|
30
|
+
) {
|
31
|
+
if (!this.skipCheckSchema && schema != null) {
|
32
|
+
this.ensureCollection();
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
// searchDocument(searchParameters: SearchParams, options: SearchOptions) {
|
37
|
+
// const {
|
38
|
+
// per_page = 25,
|
39
|
+
// filter_by,
|
40
|
+
// archived = false,
|
41
|
+
// } = { ...searchParameters };
|
42
|
+
// searchParameters.per_page = per_page;
|
43
|
+
// return this.client.collections(this?.schema?.name || this.prefix).documents().search(searchParameters, options);
|
44
|
+
// }
|
45
|
+
|
46
|
+
async searchDocument(
|
47
|
+
searchParameters: SearchParams,
|
48
|
+
options: SearchOptions,
|
49
|
+
): Promise<SearchResponse<any>> {
|
50
|
+
try {
|
51
|
+
const { includeIds = [], per_page = 25 } = { ...searchParameters };
|
52
|
+
// TODO: should be support with include/exclude ids.
|
53
|
+
const includeDocuments = [];
|
54
|
+
if (includeIds.length > 0) {
|
55
|
+
const includeOpts = {
|
56
|
+
...searchParameters,
|
57
|
+
filter_by: `id:=[${includeIds.join(', ')}]`,
|
58
|
+
};
|
59
|
+
const includeDocs = await this.client
|
60
|
+
.collections(this?.schema?.name || this.prefix)
|
61
|
+
.documents()
|
62
|
+
.search(includeOpts, options);
|
63
|
+
if (includeDocs?.hits?.length > 0) {
|
64
|
+
const names = includeDocs.hits.map(
|
65
|
+
(data: Record<string, any>) => data.document.name,
|
66
|
+
);
|
67
|
+
searchParameters.filter_by =
|
68
|
+
searchParameters.filter_by == null
|
69
|
+
? `name:!=[${names.join(', ')}]`
|
70
|
+
: `${searchParameters.filter_by} && name:!=[${names.join(', ')}]`;
|
71
|
+
searchParameters.per_page = per_page - names.length;
|
72
|
+
}
|
73
|
+
includeDocuments.push(...includeDocs?.hits);
|
74
|
+
}
|
75
|
+
const documents = await this.client
|
76
|
+
.collections(this?.schema?.name || this.prefix)
|
77
|
+
.documents()
|
78
|
+
.search(searchParameters, options);
|
79
|
+
if (includeDocuments.length > 0) {
|
80
|
+
documents.hits.push(...includeDocuments);
|
81
|
+
documents.request_params.per_page = per_page;
|
82
|
+
}
|
83
|
+
return documents;
|
84
|
+
} catch (error) {
|
85
|
+
this.logger.error(error);
|
86
|
+
return null;
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
getAllRawDocs = async (
|
91
|
+
searchParameters: SearchParams,
|
92
|
+
options: SearchOptions,
|
93
|
+
) => {
|
94
|
+
searchParameters.per_page = searchParameters.per_page ?? 250;
|
95
|
+
options.cacheSearchResultsForSeconds = 1;
|
96
|
+
const response = await this.searchDocument(searchParameters, options);
|
97
|
+
const { hits = [], found = 0, page = 1 } = response;
|
98
|
+
let documents = hits;
|
99
|
+
const hasNext = hits.length * page < found;
|
100
|
+
if (hasNext) {
|
101
|
+
searchParameters.page = page + 1;
|
102
|
+
documents = await this.getAllRawDocs(searchParameters, options);
|
103
|
+
}
|
104
|
+
return documents;
|
105
|
+
};
|
106
|
+
|
107
|
+
async importIndex(data: Document[]): Promise<ImportResponse[]> {
|
108
|
+
if (data.length > 0) {
|
109
|
+
try {
|
110
|
+
return this.client
|
111
|
+
.collections(this?.schema?.name || this.prefix)
|
112
|
+
.documents()
|
113
|
+
.import(data, { action: 'upsert' });
|
114
|
+
} catch (error) {
|
115
|
+
this.logger.error(error);
|
116
|
+
}
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
async deleteOutOfDate(data: string[] | number[], key: string): Promise<any> {
|
121
|
+
if (data?.length > 0) {
|
122
|
+
const deleteParameters = {
|
123
|
+
filter_by: `${key}:!=[${data.join(', ')}]`,
|
124
|
+
};
|
125
|
+
return await this.client
|
126
|
+
.collections(this?.schema?.name || this.prefix)
|
127
|
+
.documents()
|
128
|
+
.delete(deleteParameters);
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
async insertIndex(data: Document): Promise<any> {
|
133
|
+
return this.client
|
134
|
+
.collections(this?.schema?.name || this.prefix)
|
135
|
+
.documents()
|
136
|
+
.create(data, { action: 'upsert' });
|
137
|
+
}
|
138
|
+
|
139
|
+
async updateIndex(data: Document): Promise<any> {
|
140
|
+
return this.client
|
141
|
+
.collections(this?.schema?.name || this.prefix)
|
142
|
+
.documents()
|
143
|
+
.upsert(data, { action: 'upsert' });
|
144
|
+
}
|
145
|
+
|
146
|
+
updateDocumentById = async (data: Document) => {
|
147
|
+
if (data?.id) {
|
148
|
+
const exist = await this.client
|
149
|
+
.collections(this?.schema?.name || this.prefix)
|
150
|
+
.documents(data.id)
|
151
|
+
.retrieve();
|
152
|
+
if (exist) {
|
153
|
+
return this.client
|
154
|
+
.collections(this?.schema?.name || this.prefix)
|
155
|
+
.documents(data.id)
|
156
|
+
.update(data);
|
157
|
+
}
|
158
|
+
}
|
159
|
+
};
|
160
|
+
|
161
|
+
async upsertOrDeleteIndex(datas: Document) {
|
162
|
+
throw new Error('Method is not implement.');
|
163
|
+
}
|
164
|
+
|
165
|
+
async deleteIndex(data: Document): Promise<DeleteResponse> {
|
166
|
+
return this.client
|
167
|
+
.collections(this?.schema?.name || this.prefix)
|
168
|
+
.documents()
|
169
|
+
.delete({ filter_by: `id: ${data.id}` });
|
170
|
+
}
|
171
|
+
|
172
|
+
async deleteBatchIndex(ids: string[]): Promise<DeleteResponse> {
|
173
|
+
return this.client
|
174
|
+
.collections(this?.schema?.name || this.prefix)
|
175
|
+
.documents()
|
176
|
+
.delete({ filter_by: `id: [${ids.join(',')}]` });
|
177
|
+
}
|
178
|
+
|
179
|
+
async deleteIndexByKeyValue(
|
180
|
+
key = 'id',
|
181
|
+
value: number,
|
182
|
+
): Promise<DeleteResponse> {
|
183
|
+
return this.client
|
184
|
+
.collections(this?.schema?.name || this.prefix)
|
185
|
+
.documents()
|
186
|
+
.delete({ filter_by: `${key}:=${value}` });
|
187
|
+
}
|
188
|
+
|
189
|
+
transforms = (
|
190
|
+
searchResponse: SearchResponse<Record<string, unknown>>,
|
191
|
+
): Entity[] => {
|
192
|
+
const entities: Entity[] = [];
|
193
|
+
const { hits = [] } = { ...searchResponse };
|
194
|
+
for (const hit of hits) {
|
195
|
+
const document = hit?.document;
|
196
|
+
if (document) {
|
197
|
+
const entity = plainToClass(this.entity, document);
|
198
|
+
entity.id = Number(document.id);
|
199
|
+
entities.push(entity);
|
200
|
+
}
|
201
|
+
}
|
202
|
+
return entities;
|
203
|
+
};
|
204
|
+
|
205
|
+
transform = (
|
206
|
+
searchResponse: SearchResponse<Record<string, unknown>>,
|
207
|
+
): Entity => {
|
208
|
+
let entity: Entity = null;
|
209
|
+
const { hits = [] } = { ...searchResponse };
|
210
|
+
for (const hit of hits) {
|
211
|
+
const document = hit?.document;
|
212
|
+
if (document) {
|
213
|
+
entity = plainToClass(this.entity, document);
|
214
|
+
entity.id = Number(document.id);
|
215
|
+
}
|
216
|
+
break;
|
217
|
+
}
|
218
|
+
return entity;
|
219
|
+
};
|
220
|
+
|
221
|
+
responseList = (
|
222
|
+
searchResponse: SearchResponse<Record<string, unknown>>,
|
223
|
+
offset = 0,
|
224
|
+
): PaginationResponse<Entity> => {
|
225
|
+
const entities: Entity[] = [];
|
226
|
+
const {
|
227
|
+
hits = [],
|
228
|
+
found = 0,
|
229
|
+
page = 1,
|
230
|
+
request_params,
|
231
|
+
} = { ...searchResponse };
|
232
|
+
for (const hit of hits) {
|
233
|
+
const document = hit?.document;
|
234
|
+
if (document) {
|
235
|
+
const entity = plainToClass(this.entity, document);
|
236
|
+
entity.id = Number(document.id);
|
237
|
+
entities.push(entity);
|
238
|
+
}
|
239
|
+
}
|
240
|
+
|
241
|
+
const limit = request_params?.per_page;
|
242
|
+
|
243
|
+
// offset = offset ?? (page - 1) * limit;
|
244
|
+
|
245
|
+
return new PaginationResponse(entities, found, limit, offset);
|
246
|
+
};
|
247
|
+
|
248
|
+
private ensureCollection = async (): Promise<void> => {
|
249
|
+
this.checkSchemaName();
|
250
|
+
const exists = await this.client.collections(this.schema.name).exists();
|
251
|
+
if (!exists) {
|
252
|
+
await this.client.collections().create(this.schema);
|
253
|
+
}
|
254
|
+
};
|
255
|
+
|
256
|
+
private checkSchemaName = (): void => {
|
257
|
+
const schemaName = this.schema.name.replace(/.*?\_/gi, '');
|
258
|
+
this.schema.name = `${this.prefix}_${schemaName}`;
|
259
|
+
};
|
260
|
+
}
|
@@ -1,36 +1,36 @@
|
|
1
|
-
import { ModuleMetadata, Type } from '@nestjs/common/interfaces';
|
2
|
-
import { LogLevelDesc } from 'loglevel';
|
3
|
-
|
4
|
-
export interface TypesenseNodeOptions {
|
5
|
-
host: string;
|
6
|
-
port: number;
|
7
|
-
protocol: string;
|
8
|
-
path?: string;
|
9
|
-
url?: string;
|
10
|
-
}
|
11
|
-
|
12
|
-
export interface TypesenseModuleOptions {
|
13
|
-
nodes?: Array<TypesenseNodeOptions>;
|
14
|
-
numRetries?: number;
|
15
|
-
apiKey?: string;
|
16
|
-
connectionTimeoutSeconds?: number;
|
17
|
-
retryIntervalSeconds?: number;
|
18
|
-
healthcheckIntervalSeconds?: number;
|
19
|
-
logLevel?: LogLevelDesc;
|
20
|
-
}
|
21
|
-
|
22
|
-
export interface TypesenseOptionsFactory {
|
23
|
-
createTypesenseOptions():
|
24
|
-
| Promise<TypesenseModuleOptions>
|
25
|
-
| TypesenseModuleOptions;
|
26
|
-
}
|
27
|
-
|
28
|
-
export interface TypesenseModuleAsyncOptions
|
29
|
-
extends Pick<ModuleMetadata, 'imports'> {
|
30
|
-
useExisting?: Type<TypesenseOptionsFactory>;
|
31
|
-
useClass?: Type<TypesenseOptionsFactory>;
|
32
|
-
useFactory?: (
|
33
|
-
...args: any[]
|
34
|
-
) => Promise<TypesenseModuleOptions> | TypesenseModuleOptions;
|
35
|
-
inject?: any[];
|
36
|
-
}
|
1
|
+
import { ModuleMetadata, Type } from '@nestjs/common/interfaces';
|
2
|
+
import { LogLevelDesc } from 'loglevel';
|
3
|
+
|
4
|
+
export interface TypesenseNodeOptions {
|
5
|
+
host: string;
|
6
|
+
port: number;
|
7
|
+
protocol: string;
|
8
|
+
path?: string;
|
9
|
+
url?: string;
|
10
|
+
}
|
11
|
+
|
12
|
+
export interface TypesenseModuleOptions {
|
13
|
+
nodes?: Array<TypesenseNodeOptions>;
|
14
|
+
numRetries?: number;
|
15
|
+
apiKey?: string;
|
16
|
+
connectionTimeoutSeconds?: number;
|
17
|
+
retryIntervalSeconds?: number;
|
18
|
+
healthcheckIntervalSeconds?: number;
|
19
|
+
logLevel?: LogLevelDesc;
|
20
|
+
}
|
21
|
+
|
22
|
+
export interface TypesenseOptionsFactory {
|
23
|
+
createTypesenseOptions():
|
24
|
+
| Promise<TypesenseModuleOptions>
|
25
|
+
| TypesenseModuleOptions;
|
26
|
+
}
|
27
|
+
|
28
|
+
export interface TypesenseModuleAsyncOptions
|
29
|
+
extends Pick<ModuleMetadata, 'imports'> {
|
30
|
+
useExisting?: Type<TypesenseOptionsFactory>;
|
31
|
+
useClass?: Type<TypesenseOptionsFactory>;
|
32
|
+
useFactory?: (
|
33
|
+
...args: any[]
|
34
|
+
) => Promise<TypesenseModuleOptions> | TypesenseModuleOptions;
|
35
|
+
inject?: any[];
|
36
|
+
}
|
@@ -1 +1 @@
|
|
1
|
-
export const TYPESENSE_MODULE_OPTIONS = 'TYPESENSE_MODULE_OPTIONS';
|
1
|
+
export const TYPESENSE_MODULE_OPTIONS = 'TYPESENSE_MODULE_OPTIONS';
|