lemon-core 4.3.0 → 5.0.1

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 (167) hide show
  1. package/README.md +127 -2
  2. package/dist/common/lemon-error.d.ts +34 -0
  3. package/dist/common/lemon-error.js +52 -0
  4. package/dist/common/lemon-error.js.map +1 -0
  5. package/dist/controllers/general-api-controller.d.ts +7 -0
  6. package/dist/controllers/general-api-controller.js +7 -0
  7. package/dist/controllers/general-api-controller.js.map +1 -1
  8. package/dist/cores/api/api-service.js +10 -43
  9. package/dist/cores/api/api-service.js.map +1 -1
  10. package/dist/cores/aws/aws-kms-service.d.ts +13 -5
  11. package/dist/cores/aws/aws-kms-service.js +23 -9
  12. package/dist/cores/aws/aws-kms-service.js.map +1 -1
  13. package/dist/cores/aws/aws-s3-service.d.ts +30 -4
  14. package/dist/cores/aws/aws-s3-service.js +35 -15
  15. package/dist/cores/aws/aws-s3-service.js.map +1 -1
  16. package/dist/cores/aws/aws-sns-service.js +59 -9
  17. package/dist/cores/aws/aws-sns-service.js.map +1 -1
  18. package/dist/cores/aws/aws-sqs-service.d.ts +1 -1
  19. package/dist/cores/aws/aws-sqs-service.js +54 -12
  20. package/dist/cores/aws/aws-sqs-service.js.map +1 -1
  21. package/dist/cores/cache/cache-service.d.ts +10 -9
  22. package/dist/cores/cache/cache-service.js +9 -346
  23. package/dist/cores/cache/cache-service.js.map +1 -1
  24. package/dist/cores/config/config-service.d.ts +3 -15
  25. package/dist/cores/config/config-service.js +5 -34
  26. package/dist/cores/config/config-service.js.map +1 -1
  27. package/dist/cores/dynamo/dynamo-query-service.js +42 -2
  28. package/dist/cores/dynamo/dynamo-query-service.js.map +1 -1
  29. package/dist/cores/dynamo/dynamo-scan-service.js +42 -2
  30. package/dist/cores/dynamo/dynamo-scan-service.js.map +1 -1
  31. package/dist/cores/dynamo/dynamo-service.d.ts +45 -14
  32. package/dist/cores/dynamo/dynamo-service.js +48 -21
  33. package/dist/cores/dynamo/dynamo-service.js.map +1 -1
  34. package/dist/cores/dynamo/tools/expressions.js +32 -22
  35. package/dist/cores/dynamo/tools/expressions.js.map +1 -1
  36. package/dist/cores/dynamo/tools/lang.d.ts +30 -0
  37. package/dist/cores/dynamo/tools/lang.js +75 -0
  38. package/dist/cores/dynamo/tools/lang.js.map +1 -0
  39. package/dist/cores/dynamo/tools/query.js +20 -21
  40. package/dist/cores/dynamo/tools/query.js.map +1 -1
  41. package/dist/cores/dynamo/tools/scan.js +15 -16
  42. package/dist/cores/dynamo/tools/scan.js.map +1 -1
  43. package/dist/cores/dynamo/tools/serializer.js +40 -38
  44. package/dist/cores/dynamo/tools/serializer.js.map +1 -1
  45. package/dist/cores/dynamo/tools/utils.d.ts +6 -2
  46. package/dist/cores/dynamo/tools/utils.js +11 -8
  47. package/dist/cores/dynamo/tools/utils.js.map +1 -1
  48. package/dist/cores/elastic/elastic6-query-service.d.ts +1 -104
  49. package/dist/cores/elastic/elastic6-query-service.js +15 -489
  50. package/dist/cores/elastic/elastic6-query-service.js.map +1 -1
  51. package/dist/cores/elastic/elastic6-service.d.ts +1 -482
  52. package/dist/cores/elastic/elastic6-service.js +15 -1153
  53. package/dist/cores/elastic/elastic6-service.js.map +1 -1
  54. package/dist/cores/elastic/index.d.ts +2 -2
  55. package/dist/cores/elastic/index.js +3 -2
  56. package/dist/cores/elastic/index.js.map +1 -1
  57. package/dist/cores/elastic/os2-query-service.d.ts +104 -0
  58. package/dist/cores/elastic/os2-query-service.js +495 -0
  59. package/dist/cores/elastic/os2-query-service.js.map +1 -0
  60. package/dist/cores/elastic/os2-service.d.ts +372 -0
  61. package/dist/cores/elastic/os2-service.js +943 -0
  62. package/dist/cores/elastic/os2-service.js.map +1 -0
  63. package/dist/cores/index.d.ts +6 -1
  64. package/dist/cores/index.js +9 -2
  65. package/dist/cores/index.js.map +1 -1
  66. package/dist/cores/lambda/index.js +2 -1
  67. package/dist/cores/lambda/index.js.map +1 -1
  68. package/dist/cores/lambda/lambda-cron-handler.d.ts +1 -0
  69. package/dist/cores/lambda/lambda-cron-handler.js +5 -1
  70. package/dist/cores/lambda/lambda-cron-handler.js.map +1 -1
  71. package/dist/cores/lambda/lambda-dynamo-stream-handler.d.ts +5 -4
  72. package/dist/cores/lambda/lambda-dynamo-stream-handler.js +18 -5
  73. package/dist/cores/lambda/lambda-dynamo-stream-handler.js.map +1 -1
  74. package/dist/cores/lambda/lambda-handler.d.ts +22 -2
  75. package/dist/cores/lambda/lambda-handler.js +85 -23
  76. package/dist/cores/lambda/lambda-handler.js.map +1 -1
  77. package/dist/cores/lambda/lambda-sns-handler.d.ts +1 -0
  78. package/dist/cores/lambda/lambda-sns-handler.js +5 -0
  79. package/dist/cores/lambda/lambda-sns-handler.js.map +1 -1
  80. package/dist/cores/lambda/lambda-sqs-handler.d.ts +1 -0
  81. package/dist/cores/lambda/lambda-sqs-handler.js +20 -5
  82. package/dist/cores/lambda/lambda-sqs-handler.js.map +1 -1
  83. package/dist/cores/lambda/lambda-web-handler.d.ts +10 -0
  84. package/dist/cores/lambda/lambda-web-handler.js +107 -41
  85. package/dist/cores/lambda/lambda-web-handler.js.map +1 -1
  86. package/dist/cores/protocol/aws-lambda-helper.js +58 -11
  87. package/dist/cores/protocol/aws-lambda-helper.js.map +1 -1
  88. package/dist/cores/protocol/index.js +3 -0
  89. package/dist/cores/protocol/index.js.map +1 -1
  90. package/dist/cores/protocol/protocol-service.d.ts +26 -5
  91. package/dist/cores/protocol/protocol-service.js +42 -12
  92. package/dist/cores/protocol/protocol-service.js.map +1 -1
  93. package/dist/cores/protocol/protocol-sign.d.ts +72 -0
  94. package/dist/cores/protocol/protocol-sign.js +194 -0
  95. package/dist/cores/protocol/protocol-sign.js.map +1 -0
  96. package/dist/cores/storage/index.d.ts +0 -1
  97. package/dist/cores/storage/index.js +0 -1
  98. package/dist/cores/storage/index.js.map +1 -1
  99. package/dist/cores/storage/model-fields.d.ts +7 -0
  100. package/dist/cores/storage/model-fields.js +21 -0
  101. package/dist/cores/storage/model-fields.js.map +1 -0
  102. package/dist/cores/storage/model-manager.d.ts +5 -2
  103. package/dist/cores/storage/model-manager.js +11 -3
  104. package/dist/cores/storage/model-manager.js.map +1 -1
  105. package/dist/engine/builder.js +20 -2
  106. package/dist/engine/builder.js.map +1 -1
  107. package/dist/engine/engine.d.ts +2 -2
  108. package/dist/engine/engine.js +5 -5
  109. package/dist/engine/engine.js.map +1 -1
  110. package/dist/engine/utilities.d.ts +20 -12
  111. package/dist/engine/utilities.js +57 -86
  112. package/dist/engine/utilities.js.map +1 -1
  113. package/dist/environ.d.ts +0 -6
  114. package/dist/environ.js +1 -12
  115. package/dist/environ.js.map +1 -1
  116. package/dist/esm/index.mjs +141 -0
  117. package/dist/esm/testing.mjs +12 -0
  118. package/dist/extended/abstract-service.d.ts +48 -139
  119. package/dist/extended/abstract-service.js +46 -382
  120. package/dist/extended/abstract-service.js.map +1 -1
  121. package/dist/extended/cores/abstract-controllers.d.ts +25 -0
  122. package/dist/extended/cores/abstract-controllers.js +77 -7
  123. package/dist/extended/cores/abstract-controllers.js.map +1 -1
  124. package/dist/extended/cores/abstract-rest-apis.d.ts +2 -1
  125. package/dist/extended/cores/abstract-rest-apis.js +2 -1
  126. package/dist/extended/cores/abstract-rest-apis.js.map +1 -1
  127. package/dist/extended/cores/abstract-services.d.ts +48 -87
  128. package/dist/extended/cores/abstract-services.js +121 -248
  129. package/dist/extended/cores/abstract-services.js.map +1 -1
  130. package/dist/extended/cores/commons.d.ts +4 -113
  131. package/dist/extended/cores/commons.js +26 -180
  132. package/dist/extended/cores/commons.js.map +1 -1
  133. package/dist/extended/cores/fields-admin.d.ts +91 -0
  134. package/dist/extended/cores/fields-admin.js +142 -0
  135. package/dist/extended/cores/fields-admin.js.map +1 -0
  136. package/dist/extended/cores/index.d.ts +2 -0
  137. package/dist/extended/cores/index.js +2 -0
  138. package/dist/extended/cores/index.js.map +1 -1
  139. package/dist/extended/cores/types.d.ts +3 -225
  140. package/dist/extended/cores/types.js +28 -0
  141. package/dist/extended/cores/types.js.map +1 -1
  142. package/dist/helpers/helpers.d.ts +10 -5
  143. package/dist/helpers/helpers.js +46 -58
  144. package/dist/helpers/helpers.js.map +1 -1
  145. package/dist/helpers/types.d.ts +22 -10
  146. package/dist/index.d.ts +1 -5
  147. package/dist/index.js +8 -14
  148. package/dist/index.js.map +1 -1
  149. package/dist/lib/http-fetch.d.ts +54 -0
  150. package/dist/lib/http-fetch.js +133 -0
  151. package/dist/lib/http-fetch.js.map +1 -0
  152. package/dist/lib/lazy.d.ts +22 -0
  153. package/dist/lib/lazy.js +54 -0
  154. package/dist/lib/lazy.js.map +1 -0
  155. package/dist/lib/perf.d.ts +35 -0
  156. package/dist/lib/perf.js +52 -0
  157. package/dist/lib/perf.js.map +1 -0
  158. package/dist/tools/tools.d.ts +15 -3
  159. package/dist/tools/tools.js +21 -4
  160. package/dist/tools/tools.js.map +1 -1
  161. package/package.json +96 -39
  162. package/dist/cores/storage/redis-storage-service.d.ts +0 -183
  163. package/dist/cores/storage/redis-storage-service.js +0 -377
  164. package/dist/cores/storage/redis-storage-service.js.map +0 -1
  165. package/dist/generated/field-registry.d.ts +0 -12
  166. package/dist/generated/field-registry.js +0 -21
  167. package/dist/generated/field-registry.js.map +0 -1
@@ -0,0 +1,372 @@
1
+ import { Incrementable, SearchBody } from 'lemon-model';
2
+ import type { Client, ClientOptions } from '@opensearch-project/opensearch';
3
+ import $hangul from './hangul-service';
4
+ export { $hangul };
5
+ export type SearchType = 'query_then_fetch' | 'dfs_query_then_fetch';
6
+ export interface SearchResponse<T = any> {
7
+ total: number;
8
+ list: Array<T>;
9
+ last: Array<T>;
10
+ aggregations: T;
11
+ }
12
+ /**
13
+ * options for construction.
14
+ * - v5: the doc-type and version options are removed (typeless OpenSearch only).
15
+ */
16
+ export interface OS2BaseOption {
17
+ /**
18
+ * endpoint url of OpenSearch
19
+ */
20
+ endpoint: string;
21
+ /**
22
+ * index-name
23
+ */
24
+ indexName: string;
25
+ /**
26
+ * id-name (optional if time-seriese)
27
+ */
28
+ idName?: string;
29
+ /**
30
+ * is TIMESERIES data?
31
+ */
32
+ timeSeries?: boolean;
33
+ /**
34
+ * fields to provide autocomplete(Search-as-You-Type) feature
35
+ */
36
+ autocompleteFields?: string[] | null;
37
+ }
38
+ /**
39
+ * common type of item
40
+ */
41
+ export interface OS2Item {
42
+ _id?: string;
43
+ _version?: number;
44
+ _score?: number;
45
+ /**
46
+ * only has simple string or number (and in arrays)
47
+ */
48
+ [key: string]: string | string[] | number | number[] | undefined;
49
+ }
50
+ /**
51
+ * options for retrying searchAll
52
+ */
53
+ export interface RetryOptions {
54
+ /** do retry? (default true) */
55
+ do?: boolean;
56
+ /** retry after t msec (default 5000ms) */
57
+ t?: number;
58
+ /** maximum Retries (default 3 times) */
59
+ maxRetries?: number;
60
+ }
61
+ /**
62
+ * parameters for searchAll
63
+ */
64
+ interface ElasticSearchAllParams {
65
+ /** search-type */
66
+ searchType?: SearchType;
67
+ /** limit (default -1) */
68
+ limit?: number;
69
+ /** options for retrying (default true)*/
70
+ retryOptions?: RetryOptions;
71
+ }
72
+ /** ****************************************************************************************************************
73
+ * OS2 Client Service
74
+ ** ****************************************************************************************************************/
75
+ /**
76
+ * abstarct class: `OS2ClientService`
77
+ * - holds the options and the OpenSearch client.
78
+ * - the client is created on the first `client` access (not in the constructor).
79
+ */
80
+ export declare abstract class OS2ClientService<T extends OS2Item = any> {
81
+ protected _options: OS2BaseOption;
82
+ /** the client, created on first access of `client` */
83
+ protected _client?: Client;
84
+ /**
85
+ * default constuctor w/ options (no client is created here).
86
+ * @param options { endpoint, indexName } is required.
87
+ */
88
+ constructor(options: OS2BaseOption);
89
+ /**
90
+ * build the client for `options.endpoint` (override to add `auth`).
91
+ * @see https://opensearch.org/docs/latest/clients/javascript/index/
92
+ */
93
+ protected createClient(): Client;
94
+ /**
95
+ * build a client for `options.endpoint` with extra client options (e.g. `auth`); loads the package on first use.
96
+ */
97
+ protected newClient(extra?: Partial<ClientOptions>): Client;
98
+ /**
99
+ * get the client instance (created once, on first access).
100
+ */
101
+ get client(): Client;
102
+ /**
103
+ * get the current options.
104
+ */
105
+ get options(): OS2BaseOption;
106
+ /**
107
+ * say hello
108
+ */
109
+ abstract hello(): string;
110
+ /**
111
+ * save an item
112
+ * @param id - item id
113
+ * @param item - item to save
114
+ */
115
+ abstract saveItem(id: string, item: T): Promise<T>;
116
+ /**
117
+ * push item for time-series data
118
+ * @param item - item to push
119
+ */
120
+ abstract pushItem(item: T): Promise<T>;
121
+ /**
122
+ * read item with projections
123
+ * @param id - item id
124
+ * @param views - projections
125
+ */
126
+ abstract readItem(id: string, views?: string[] | object): Promise<T>;
127
+ /**
128
+ * delete an item by id
129
+ * @param id - item id
130
+ */
131
+ abstract deleteItem(id: string): Promise<T>;
132
+ /**
133
+ * update an item
134
+ * @param id - item id
135
+ * @param item - item to update
136
+ * @param increments - fields to increment
137
+ */
138
+ abstract updateItem(id: string, item: T | null, increments?: any, options?: {
139
+ maxRetries?: number;
140
+ }): Promise<T>;
141
+ /**
142
+ * search raw results using a query body
143
+ * @param body - search query
144
+ * @param searchType - type of search
145
+ */
146
+ abstract searchRaw<T extends object = any>(body: any, searchType?: string): Promise<T>;
147
+ /**
148
+ * search and return formatted response
149
+ * @param body - search query
150
+ * @param searchType - type of search
151
+ */
152
+ abstract search(body: any, searchType?: string): Promise<any>;
153
+ }
154
+ /** ****************************************************************************************************************
155
+ * OS2CoreService
156
+ ** ****************************************************************************************************************/
157
+ /**
158
+ * class: `OS2CoreService`
159
+ * - extends `OS2ClientService`: document CRUD, search and index management via the client.
160
+ * - the parent of `OS2Service`.
161
+ */
162
+ export declare class OS2CoreService<T extends OS2Item = any> extends OS2ClientService {
163
+ static readonly DECOMPOSED_FIELD = "_decomposed";
164
+ static readonly QWERTY_FIELD = "_qwerty";
165
+ /**
166
+ * default constuctor w/ options.
167
+ * @param options { endpoint, indexName } is required.
168
+ */
169
+ constructor(options: OS2BaseOption);
170
+ /**
171
+ * say hello of identity.
172
+ */
173
+ hello: () => string;
174
+ /**
175
+ * list of index
176
+ */
177
+ listIndices(): Promise<{
178
+ list: {
179
+ pri: number;
180
+ rep: number;
181
+ docsCount: number;
182
+ docsDeleted: number;
183
+ health: string;
184
+ index: string;
185
+ status: string;
186
+ uuid: string;
187
+ priStoreSize: string;
188
+ storeSize: string;
189
+ }[];
190
+ }>;
191
+ /**
192
+ * get mapping of an index
193
+ * @param indexName - name of the index
194
+ */
195
+ getIndexMapping(): Promise<any>;
196
+ /**
197
+ * find the index by name
198
+ * @param indexName - name of the index
199
+ */
200
+ findIndex(indexName?: string): Promise<{
201
+ pri: number;
202
+ rep: number;
203
+ docsCount: number;
204
+ docsDeleted: number;
205
+ health: string;
206
+ index: string;
207
+ status: string;
208
+ uuid: string;
209
+ priStoreSize: string;
210
+ storeSize: string;
211
+ }>;
212
+ /**
213
+ * create index by name
214
+ * @param settings - creating settings
215
+ */
216
+ createIndex(settings?: any): Promise<{
217
+ status: any;
218
+ index: string;
219
+ acknowledged: any;
220
+ }>;
221
+ /**
222
+ * destroy search index
223
+ */
224
+ destroyIndex(): Promise<{
225
+ status: any;
226
+ index: string;
227
+ acknowledged: any;
228
+ }>;
229
+ /**
230
+ * refresh search index - refresh index to make all items searchable
231
+ */
232
+ refreshIndex(): Promise<any>;
233
+ /**
234
+ * flush search index - force store changes into search index immediately
235
+ */
236
+ flushIndex(): Promise<any>;
237
+ /**
238
+ * describe `settings` and `mappings` of index.
239
+ */
240
+ describe(): Promise<{
241
+ settings: any;
242
+ mappings: any;
243
+ }>;
244
+ /**
245
+ * save single item
246
+ *
247
+ * - typeless: no `type` param (v5).
248
+ *
249
+ * @param id - id
250
+ * @param item - item to save
251
+ */
252
+ saveItem(id: string, item: T): Promise<T>;
253
+ /**
254
+ * push item for time-series data.
255
+ *
256
+ * - typeless: no `type` param (v5).
257
+ *
258
+ * @param item - item to push
259
+ */
260
+ pushItem(item: T): Promise<T>;
261
+ /**
262
+ * read item with projections (typeless `GET /{index}/_doc/{id}`)
263
+ *
264
+ * @param id - item-id
265
+ * @param views - projections
266
+ */
267
+ readItem(id: string, views?: string[] | object): Promise<T>;
268
+ /**
269
+ * delete item with projections (typeless `DELETE /{index}/_doc/{id}`)
270
+ *
271
+ * @param id - item-id
272
+ */
273
+ deleteItem(id: string): Promise<T>;
274
+ /**
275
+ * update item (throw if not exist)
276
+ * `update table set a=1, b=b+2 where id='a1'`
277
+ * 0. no of `a1` -> 1,2 (created)
278
+ * 1. a,b := 10,20 -> 11,22
279
+ * 2. a,b := 10,null -> 11,2 (upsert)
280
+ * 3. a,b := null,20 -> 1,22
281
+ *
282
+ * @param id - item-id
283
+ * @param item - item to update
284
+ * @param increments - item to increase
285
+ * @param options - (optional) request option of client.
286
+ */
287
+ updateItem(id: string, item: T | null, increments?: Incrementable, options?: {
288
+ maxRetries?: number;
289
+ }): Promise<T>;
290
+ /**
291
+ * run search and get the raw response (`search_type` in the query string).
292
+ * @param body - Elasticsearch Query DSL that defines the search request (e.g., size, query, filters).
293
+ * @param searchType - type of search (e.g., 'query_then_fetch', 'dfs_query_then_fetch').
294
+ */
295
+ searchRaw<T extends object = any>(body: SearchBody, searchType?: SearchType): Promise<T>;
296
+ /**
297
+ * run search, and get the formatmted response.
298
+ * @param body - Elasticsearch Query DSL that defines the search request (e.g., size, query, filters).
299
+ * @param searchType - type of search (e.g., 'query_then_fetch', 'dfs_query_then_fetch').
300
+ *
301
+ */
302
+ search(body: SearchBody, searchType?: SearchType): Promise<SearchResponse>;
303
+ /**
304
+ * search all until limit (-1 means no-limit)
305
+ * @param body - Elasticsearch Query DSL that defines the search request (e.g., size, query, filters).
306
+ * @param params - parameters including search type, limit, and retry options.
307
+ */
308
+ searchAll<T>(body: SearchBody, params?: ElasticSearchAllParams): Promise<T[]>;
309
+ /**
310
+ * create async generator that yields items queried until last
311
+ *
312
+ * @param body - Elasticsearch Query DSL that defines the search request (e.g., size, query, filters).
313
+ * @param params - parameters including search type, limit, and retry options.
314
+ */
315
+ generateSearchResult(body: SearchBody, params?: ElasticSearchAllParams): AsyncGenerator<any[], void, unknown>;
316
+ /**
317
+ * prepare default setting
318
+ * - migrated from engine-v2.
319
+ * - v5: always the typeless mapping (`mappings.properties`); no doc-type or version, no `standard` filter.
320
+ *
321
+ * @param idName id-name
322
+ * @param shards number of shards (default 4)
323
+ * @param replicas number of replicas (default 1)
324
+ * @param timeSeries flag of TIMESERIES (default false)
325
+ */
326
+ static prepareSettings(params: {
327
+ idName: string;
328
+ timeSeries?: boolean;
329
+ shards?: number;
330
+ replicas?: number;
331
+ }): any;
332
+ /**
333
+ * generate autocomplete fields into the item body to be indexed
334
+ * @param body item body to be saved into ES6 index
335
+ * @private
336
+ */
337
+ protected popullateAutocompleteFields<T = any>(body: T): T;
338
+ }
339
+ interface ErrorReasonDetail<T = any> {
340
+ status: number;
341
+ type: string;
342
+ reason?: string;
343
+ cause?: T;
344
+ }
345
+ interface ErrorReason {
346
+ status: number;
347
+ message: string;
348
+ reason: ErrorReasonDetail;
349
+ }
350
+ /**
351
+ * error samples
352
+ */
353
+ export declare const $ERROR: {
354
+ asJson: (e: any) => any;
355
+ throwAsJson: (e: any) => never;
356
+ parseMeta: <T extends {
357
+ type?: string;
358
+ value?: any;
359
+ error?: string;
360
+ list?: any[];
361
+ [key: string]: any;
362
+ }>(meta: any) => T;
363
+ /**
364
+ * parse a client error into `{ status, message, reason }`.
365
+ * - `type` comes from `meta.body.error.type` (same in both clients); it falls back to `message` only
366
+ * when the body has no error type (e.g. a meta-only sample of elastic 7.x).
367
+ * - output form is unchanged: `<TYPE upper, last token dropped, _ as space>` like `VERSION CONFLICT ENGINE`.
368
+ * - errors without `meta` (FGAC `http-fetch`, network) give `reason = null` and are rethrown by `handler`.
369
+ */
370
+ asError: (e: any) => ErrorReason;
371
+ handler: (name: string, cb?: (e: Error, E?: ErrorReason) => any) => (e: any) => any;
372
+ };