lemon-core 3.2.7 → 3.2.9
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/README.md
CHANGED
|
@@ -74,6 +74,8 @@ See [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md)
|
|
|
74
74
|
|
|
75
75
|
| Version | Description
|
|
76
76
|
|-- |--
|
|
77
|
+
| 3.2.9 | improve `elastic6-service` w/ latest open-search.
|
|
78
|
+
| 3.2.8 | updated `ttypescript^1.5.15`, and optimized.
|
|
77
79
|
| 3.2.7 | cleanup log message in `AWSS3Service`, and optimized.
|
|
78
80
|
| 3.2.6 | improve `listObjects()` in `AWSS3Service` w/ prefix.
|
|
79
81
|
| 3.2.5 | improve `doReportError` in `lambda-web-handler`.
|
|
@@ -14,7 +14,7 @@ export declare class Elastic6QueryService<T extends GeneralItem> implements Elas
|
|
|
14
14
|
/**
|
|
15
15
|
* get options
|
|
16
16
|
*/
|
|
17
|
-
protected get options(): import("./elastic6-service").
|
|
17
|
+
protected get options(): import("./elastic6-service").ElasticOption;
|
|
18
18
|
/**
|
|
19
19
|
* say hello of identity.
|
|
20
20
|
*/
|
|
@@ -3,11 +3,16 @@ import elasticsearch from '@elastic/elasticsearch';
|
|
|
3
3
|
import $hangul from './hangul-service';
|
|
4
4
|
export { elasticsearch, $hangul };
|
|
5
5
|
export declare type SearchType = 'query_then_fetch' | 'dfs_query_then_fetch';
|
|
6
|
-
export
|
|
6
|
+
export interface SearchResponse<T = any> {
|
|
7
|
+
total: number;
|
|
8
|
+
list: Array<T>;
|
|
9
|
+
last: Array<T>;
|
|
10
|
+
aggregations: T;
|
|
11
|
+
}
|
|
7
12
|
/**
|
|
8
13
|
* options for construction.
|
|
9
14
|
*/
|
|
10
|
-
export interface
|
|
15
|
+
export interface ElasticOption {
|
|
11
16
|
/**
|
|
12
17
|
* endpoint url of ES6
|
|
13
18
|
*/
|
|
@@ -37,30 +42,80 @@ export interface Elastic6Option {
|
|
|
37
42
|
/**
|
|
38
43
|
* fields to provide autocomplete(Search-as-You-Type) feature
|
|
39
44
|
*/
|
|
40
|
-
autocompleteFields?: string[];
|
|
45
|
+
autocompleteFields?: string[] | null;
|
|
41
46
|
}
|
|
42
47
|
/**
|
|
43
48
|
* common type of item
|
|
44
49
|
*/
|
|
45
|
-
export interface
|
|
50
|
+
export interface ElasticItem {
|
|
46
51
|
_id?: string;
|
|
47
52
|
_version?: number;
|
|
48
53
|
_score?: number;
|
|
54
|
+
/**
|
|
55
|
+
* only has simple string or number (and in arrays)
|
|
56
|
+
*/
|
|
57
|
+
[key: string]: string | string[] | number | number[] | undefined;
|
|
49
58
|
}
|
|
50
59
|
/**
|
|
51
|
-
*
|
|
52
|
-
* - basic CRUD service for Elastic Search 6
|
|
60
|
+
* options for retrying searchAll
|
|
53
61
|
*/
|
|
54
|
-
export
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
62
|
+
export interface RetryOptions {
|
|
63
|
+
/** do retry? (default true) */
|
|
64
|
+
do?: boolean;
|
|
65
|
+
/** retry after t msec (default 5000ms) */
|
|
66
|
+
t?: number;
|
|
67
|
+
/** maximum Retries (default 3 times) */
|
|
68
|
+
maxRetries?: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* parameters for searchAll
|
|
72
|
+
*/
|
|
73
|
+
interface ElasticSearchAllParams {
|
|
74
|
+
/** search-type */
|
|
75
|
+
searchType?: SearchType;
|
|
76
|
+
/** limit (default -1) */
|
|
77
|
+
limit?: number;
|
|
78
|
+
/** options for retrying (default true)*/
|
|
79
|
+
retryOptions?: RetryOptions;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* type of search-engine type
|
|
83
|
+
*/
|
|
84
|
+
export declare type EngineType = 'os' | 'es';
|
|
85
|
+
/**
|
|
86
|
+
* parsed version with major and minor version numbers.
|
|
87
|
+
*/
|
|
88
|
+
export interface ParsedVersion {
|
|
89
|
+
/** search-engine type */
|
|
90
|
+
engine?: EngineType;
|
|
91
|
+
/** major version */
|
|
92
|
+
major: number;
|
|
93
|
+
/** minor version */
|
|
94
|
+
minor: number;
|
|
95
|
+
/** patch version */
|
|
96
|
+
patch: number;
|
|
97
|
+
/** pre-release label (e.g., 'alpha', 'beta') */
|
|
98
|
+
prerelease?: string;
|
|
99
|
+
/** build metadata */
|
|
100
|
+
build?: string;
|
|
101
|
+
}
|
|
102
|
+
/** ****************************************************************************************************************
|
|
103
|
+
* Elastic Index Service
|
|
104
|
+
** ****************************************************************************************************************/
|
|
105
|
+
/**
|
|
106
|
+
* abstarct class: `ElasticIndexService`
|
|
107
|
+
* - abstract class for basic Elasticsearch CRUD operations
|
|
108
|
+
* - common operations that are shared across different versions.
|
|
109
|
+
* TODO - support `Elastic` and `OpenSearch`
|
|
110
|
+
*/
|
|
111
|
+
export declare abstract class ElasticIndexService<T extends ElasticItem = any> {
|
|
112
|
+
protected _options: ElasticOption;
|
|
58
113
|
readonly _client: elasticsearch.Client;
|
|
59
114
|
/**
|
|
60
115
|
* simple instance maker.
|
|
61
116
|
*
|
|
62
117
|
* ```js
|
|
63
|
-
* const { client } =
|
|
118
|
+
* const { client } = ElasticIndexService.instance(endpoint);
|
|
64
119
|
* ```
|
|
65
120
|
*
|
|
66
121
|
* @param endpoint service-url
|
|
@@ -69,6 +124,87 @@ export declare class Elastic6Service<T extends Elastic6Item = any> {
|
|
|
69
124
|
static instance(endpoint: string): {
|
|
70
125
|
client: elasticsearch.Client;
|
|
71
126
|
};
|
|
127
|
+
/**
|
|
128
|
+
* default constuctor w/ options.
|
|
129
|
+
* @param options { endpoint, indexName } is required.
|
|
130
|
+
*/
|
|
131
|
+
constructor(options: ElasticOption);
|
|
132
|
+
/**
|
|
133
|
+
* get the client instance.
|
|
134
|
+
*/
|
|
135
|
+
get client(): elasticsearch.Client;
|
|
136
|
+
/**
|
|
137
|
+
* get the current options.
|
|
138
|
+
*/
|
|
139
|
+
get options(): ElasticOption;
|
|
140
|
+
/**
|
|
141
|
+
* get the version from options
|
|
142
|
+
*/
|
|
143
|
+
get version(): number;
|
|
144
|
+
/**
|
|
145
|
+
* say hello
|
|
146
|
+
*/
|
|
147
|
+
abstract hello(): string;
|
|
148
|
+
/**
|
|
149
|
+
* save an item
|
|
150
|
+
* @param id - item id
|
|
151
|
+
* @param item - item to save
|
|
152
|
+
* @param type - document type
|
|
153
|
+
*/
|
|
154
|
+
abstract saveItem(id: string, item: T, type?: string): Promise<T>;
|
|
155
|
+
/**
|
|
156
|
+
* push item for time-series data
|
|
157
|
+
* @param item - item to push
|
|
158
|
+
* @param type - document type
|
|
159
|
+
*/
|
|
160
|
+
abstract pushItem(item: T, type?: string): Promise<T>;
|
|
161
|
+
/**
|
|
162
|
+
* read item with projections
|
|
163
|
+
* @param id - item id
|
|
164
|
+
* @param views - projections
|
|
165
|
+
*/
|
|
166
|
+
abstract readItem(id: string, views?: string[] | object): Promise<T>;
|
|
167
|
+
/**
|
|
168
|
+
* delete an item by id
|
|
169
|
+
* @param id - item id
|
|
170
|
+
*/
|
|
171
|
+
abstract deleteItem(id: string): Promise<T>;
|
|
172
|
+
/**
|
|
173
|
+
* update an item
|
|
174
|
+
* @param id - item id
|
|
175
|
+
* @param item - item to update
|
|
176
|
+
* @param increments - fields to increment
|
|
177
|
+
*/
|
|
178
|
+
abstract updateItem(id: string, item: T | null, increments?: any, options?: {
|
|
179
|
+
maxRetries?: number;
|
|
180
|
+
}): Promise<T>;
|
|
181
|
+
/**
|
|
182
|
+
* search raw results using a query body
|
|
183
|
+
* @param body - search query
|
|
184
|
+
* @param searchType - type of search
|
|
185
|
+
*/
|
|
186
|
+
abstract searchRaw<T extends object = any>(body: any, searchType?: string): Promise<T>;
|
|
187
|
+
/**
|
|
188
|
+
* search and return formatted response
|
|
189
|
+
* @param body - search query
|
|
190
|
+
* @param searchType - type of search
|
|
191
|
+
*/
|
|
192
|
+
abstract search(body: any, searchType?: string): Promise<any>;
|
|
193
|
+
}
|
|
194
|
+
/** ****************************************************************************************************************
|
|
195
|
+
* Elastic6Service
|
|
196
|
+
** ****************************************************************************************************************/
|
|
197
|
+
export interface Elastic6Option extends ElasticOption {
|
|
198
|
+
}
|
|
199
|
+
export interface Elastic6Item extends ElasticItem {
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* class: `Elastic6Service`
|
|
203
|
+
* - extends `ElasticIndexService` and adds version-specific implementation
|
|
204
|
+
*/
|
|
205
|
+
export declare class Elastic6Service<T extends ElasticItem = any> extends ElasticIndexService {
|
|
206
|
+
static readonly DECOMPOSED_FIELD = "_decomposed";
|
|
207
|
+
static readonly QWERTY_FIELD = "_qwerty";
|
|
72
208
|
/**
|
|
73
209
|
* default constuctor w/ options.
|
|
74
210
|
* @param options { endpoint, indexName } is required.
|
|
@@ -79,14 +215,59 @@ export declare class Elastic6Service<T extends Elastic6Item = any> {
|
|
|
79
215
|
*/
|
|
80
216
|
hello: () => string;
|
|
81
217
|
/**
|
|
82
|
-
* get
|
|
218
|
+
* get isOldES6
|
|
219
|
+
* - used when setting doctype
|
|
220
|
+
* - used when verifying mismatched error and results of search
|
|
83
221
|
*/
|
|
84
|
-
get
|
|
222
|
+
get isOldES6(): boolean;
|
|
85
223
|
/**
|
|
86
|
-
* get
|
|
224
|
+
* get isOldES71
|
|
225
|
+
* - used when verifying mismatched error
|
|
87
226
|
*/
|
|
88
|
-
get
|
|
89
|
-
|
|
227
|
+
get isOldES71(): boolean;
|
|
228
|
+
/**
|
|
229
|
+
* get isLatestOS2
|
|
230
|
+
* - used when verifying results of search
|
|
231
|
+
*/
|
|
232
|
+
get isLatestOS2(): boolean;
|
|
233
|
+
/**
|
|
234
|
+
* get the parsedVersion
|
|
235
|
+
*/
|
|
236
|
+
get parsedVersion(): ParsedVersion;
|
|
237
|
+
/**
|
|
238
|
+
* get the root version from client
|
|
239
|
+
*
|
|
240
|
+
* @protected only for internal test.
|
|
241
|
+
*/
|
|
242
|
+
protected getVersion(options?: {
|
|
243
|
+
dump?: boolean;
|
|
244
|
+
}): Promise<ParsedVersion>;
|
|
245
|
+
/**
|
|
246
|
+
* check whether the service version matches the version provided in the options.
|
|
247
|
+
*
|
|
248
|
+
* @protected only for internal test.
|
|
249
|
+
*/
|
|
250
|
+
protected executeSelfTest(): Promise<{
|
|
251
|
+
isEqual: boolean;
|
|
252
|
+
optionVersion: ParsedVersion;
|
|
253
|
+
rootVersion: ParsedVersion;
|
|
254
|
+
}>;
|
|
255
|
+
/**
|
|
256
|
+
* parse version according to Semantic Versioning (SemVer) rules.
|
|
257
|
+
*
|
|
258
|
+
* @param version The version string to parse (e.g., "1.2.3", "1.2.3-alpha.1", "1.2.3+build.001").
|
|
259
|
+
* @param options Optional configuration for throwable behavior.
|
|
260
|
+
* @returns A ParsedVersion object or null if parsing fails and throwable is false.
|
|
261
|
+
*/
|
|
262
|
+
parseVersion(version: string, options?: {
|
|
263
|
+
throwable?: boolean;
|
|
264
|
+
}): ParsedVersion;
|
|
265
|
+
/**
|
|
266
|
+
* save info to a JSON file.
|
|
267
|
+
* @param info - The information to be saved
|
|
268
|
+
* @param filePath - The file path where should be saved.
|
|
269
|
+
*/
|
|
270
|
+
private saveInfoToFile;
|
|
90
271
|
/**
|
|
91
272
|
* list of index
|
|
92
273
|
*/
|
|
@@ -104,8 +285,14 @@ export declare class Elastic6Service<T extends Elastic6Item = any> {
|
|
|
104
285
|
storeSize: string;
|
|
105
286
|
}[];
|
|
106
287
|
}>;
|
|
288
|
+
/**
|
|
289
|
+
* get mapping of an index
|
|
290
|
+
* @param indexName - name of the index
|
|
291
|
+
*/
|
|
292
|
+
getIndexMapping(): Promise<any>;
|
|
107
293
|
/**
|
|
108
294
|
* find the index by name
|
|
295
|
+
* @param indexName - name of the index
|
|
109
296
|
*/
|
|
110
297
|
findIndex(indexName?: string): Promise<{
|
|
111
298
|
pri: number;
|
|
@@ -121,8 +308,7 @@ export declare class Elastic6Service<T extends Elastic6Item = any> {
|
|
|
121
308
|
}>;
|
|
122
309
|
/**
|
|
123
310
|
* create index by name
|
|
124
|
-
*
|
|
125
|
-
* @param settings creating settings
|
|
311
|
+
* @param settings - creating settings
|
|
126
312
|
*/
|
|
127
313
|
createIndex(settings?: any): Promise<{
|
|
128
314
|
status: any;
|
|
@@ -155,53 +341,73 @@ export declare class Elastic6Service<T extends Elastic6Item = any> {
|
|
|
155
341
|
/**
|
|
156
342
|
* save single item
|
|
157
343
|
*
|
|
158
|
-
* @param id
|
|
159
|
-
* @param item
|
|
160
|
-
* @param type
|
|
344
|
+
* @param id - id
|
|
345
|
+
* @param item - item to save
|
|
346
|
+
* @param type - document type (default: doc-type given at construction time)
|
|
161
347
|
*/
|
|
162
348
|
saveItem(id: string, item: T, type?: string): Promise<T>;
|
|
163
349
|
/**
|
|
164
350
|
* push item for time-series data.
|
|
165
351
|
*
|
|
166
|
-
* @param item
|
|
352
|
+
* @param item - item to push
|
|
353
|
+
* @param type - document type (default: doc-type given at construction time)
|
|
167
354
|
*/
|
|
168
355
|
pushItem(item: T, type?: string): Promise<T>;
|
|
169
356
|
/**
|
|
170
357
|
* read item with projections
|
|
171
358
|
*
|
|
172
|
-
* @param id
|
|
173
|
-
* @param views
|
|
359
|
+
* @param id - item-id
|
|
360
|
+
* @param views - projections
|
|
174
361
|
*/
|
|
175
362
|
readItem(id: string, views?: string[] | object): Promise<T>;
|
|
176
363
|
/**
|
|
177
364
|
* delete item with projections
|
|
178
365
|
*
|
|
179
|
-
* @param id
|
|
366
|
+
* @param id - item-id
|
|
180
367
|
*/
|
|
181
368
|
deleteItem(id: string): Promise<T>;
|
|
182
369
|
/**
|
|
183
|
-
* update item
|
|
370
|
+
* update item (throw if not exist)
|
|
371
|
+
* `update table set a=1, b=b+2 where id='a1'`
|
|
372
|
+
* 0. no of `a1` -> 1,2 (created)
|
|
373
|
+
* 1. a,b := 10,20 -> 11,22
|
|
374
|
+
* 2. a,b := 10,null -> 11,2 (upsert)
|
|
375
|
+
* 3. a,b := null,20 -> 1,22
|
|
184
376
|
*
|
|
185
|
-
* @param id
|
|
186
|
-
* @param item
|
|
187
|
-
* @param
|
|
377
|
+
* @param id - item-id
|
|
378
|
+
* @param item - item to update
|
|
379
|
+
* @param increments - item to increase
|
|
380
|
+
* @param options - (optional) request option of client.
|
|
188
381
|
*/
|
|
189
|
-
updateItem(id: string, item: T, increments?: Incrementable, options?: {
|
|
382
|
+
updateItem(id: string, item: T | null, increments?: Incrementable, options?: {
|
|
190
383
|
maxRetries?: number;
|
|
191
384
|
}): Promise<T>;
|
|
192
385
|
/**
|
|
193
386
|
* run search and get the raw response.
|
|
387
|
+
* @param body - Elasticsearch Query DSL that defines the search request (e.g., size, query, filters).
|
|
388
|
+
* @param searchType - type of search (e.g., 'query_then_fetch', 'dfs_query_then_fetch').
|
|
194
389
|
*/
|
|
195
|
-
searchRaw(body: SearchBody, searchType?: SearchType): Promise<
|
|
390
|
+
searchRaw<T extends object = any>(body: SearchBody, searchType?: SearchType): Promise<T>;
|
|
196
391
|
/**
|
|
197
392
|
* run search, and get the formatmted response.
|
|
393
|
+
* @param body - Elasticsearch Query DSL that defines the search request (e.g., size, query, filters).
|
|
394
|
+
* @param searchType - type of search (e.g., 'query_then_fetch', 'dfs_query_then_fetch').
|
|
395
|
+
*
|
|
198
396
|
*/
|
|
199
|
-
search(body: SearchBody, searchType?: SearchType): Promise<
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
397
|
+
search(body: SearchBody, searchType?: SearchType): Promise<SearchResponse>;
|
|
398
|
+
/**
|
|
399
|
+
* search all until limit (-1 means no-limit)
|
|
400
|
+
* @param body - Elasticsearch Query DSL that defines the search request (e.g., size, query, filters).
|
|
401
|
+
* @param params - parameters including search type, limit, and retry options.
|
|
402
|
+
*/
|
|
403
|
+
searchAll<T>(body: SearchBody, params?: ElasticSearchAllParams): Promise<T[]>;
|
|
404
|
+
/**
|
|
405
|
+
* create async generator that yields items queried until last
|
|
406
|
+
*
|
|
407
|
+
* @param body - Elasticsearch Query DSL that defines the search request (e.g., size, query, filters).
|
|
408
|
+
* @param params - parameters including search type, limit, and retry options.
|
|
409
|
+
*/
|
|
410
|
+
generateSearchResult(body: SearchBody, params?: ElasticSearchAllParams): AsyncGenerator<any[], void, unknown>;
|
|
205
411
|
/**
|
|
206
412
|
* prepare default setting
|
|
207
413
|
* - migrated from engine-v2.
|
|
@@ -225,13 +431,13 @@ export declare class Elastic6Service<T extends Elastic6Item = any> {
|
|
|
225
431
|
* @param body item body to be saved into ES6 index
|
|
226
432
|
* @private
|
|
227
433
|
*/
|
|
228
|
-
|
|
434
|
+
protected popullateAutocompleteFields<T = any>(body: T): T;
|
|
229
435
|
}
|
|
230
|
-
interface ErrorReasonDetail {
|
|
436
|
+
interface ErrorReasonDetail<T = any> {
|
|
231
437
|
status: number;
|
|
232
438
|
type: string;
|
|
233
439
|
reason?: string;
|
|
234
|
-
cause?:
|
|
440
|
+
cause?: T;
|
|
235
441
|
}
|
|
236
442
|
interface ErrorReason {
|
|
237
443
|
status: number;
|
|
@@ -262,7 +468,7 @@ export declare const $ERROR: {
|
|
|
262
468
|
* - service in-memory dummy data
|
|
263
469
|
*/
|
|
264
470
|
export declare class DummyElastic6Service<T extends GeneralItem> extends Elastic6Service<T> {
|
|
265
|
-
constructor(dataFile: string, options:
|
|
471
|
+
constructor(dataFile: string, options: ElasticOption);
|
|
266
472
|
private buffer;
|
|
267
473
|
load(data: T[]): void;
|
|
268
474
|
/**
|