lemon-core 3.1.0 → 3.1.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 (101) hide show
  1. package/README.md +1 -0
  2. package/dist/controllers/dummy-controller.d.ts +1 -1
  3. package/dist/controllers/dummy-controller.js +2 -2
  4. package/dist/controllers/dummy-controller.js.map +1 -1
  5. package/dist/controllers/general-api-controller.d.ts +1 -1
  6. package/dist/cores/api/api-service.d.ts +239 -0
  7. package/dist/cores/api/api-service.js +674 -0
  8. package/dist/cores/api/api-service.js.map +1 -0
  9. package/dist/cores/api/index.d.ts +10 -0
  10. package/dist/cores/api/index.js +27 -0
  11. package/dist/cores/api/index.js.map +1 -0
  12. package/dist/cores/aws/aws-kms-service.d.ts +53 -2
  13. package/dist/cores/aws/aws-kms-service.js +104 -17
  14. package/dist/cores/aws/aws-kms-service.js.map +1 -1
  15. package/dist/cores/cache/cache-service.d.ts +440 -0
  16. package/dist/cores/cache/cache-service.js +967 -0
  17. package/dist/cores/cache/cache-service.js.map +1 -0
  18. package/dist/cores/cache/index.d.ts +10 -0
  19. package/dist/cores/cache/index.js +27 -0
  20. package/dist/cores/cache/index.js.map +1 -0
  21. package/dist/cores/cache-service.d.ts +54 -18
  22. package/dist/cores/cache-service.js +37 -26
  23. package/dist/cores/cache-service.js.map +1 -1
  24. package/dist/cores/core-types.d.ts +42 -12
  25. package/dist/cores/dynamo/dynamo-query-service.d.ts +52 -0
  26. package/dist/cores/dynamo/dynamo-query-service.js +127 -0
  27. package/dist/cores/dynamo/dynamo-query-service.js.map +1 -0
  28. package/dist/cores/dynamo/dynamo-scan-service.d.ts +70 -0
  29. package/dist/cores/dynamo/dynamo-scan-service.js +164 -0
  30. package/dist/cores/dynamo/dynamo-scan-service.js.map +1 -0
  31. package/dist/cores/dynamo/dynamo-service.d.ts +192 -0
  32. package/dist/cores/dynamo/dynamo-service.js +525 -0
  33. package/dist/cores/dynamo/dynamo-service.js.map +1 -0
  34. package/dist/cores/dynamo/index.d.ts +12 -0
  35. package/dist/cores/dynamo/index.js +29 -0
  36. package/dist/cores/dynamo/index.js.map +1 -0
  37. package/dist/cores/elastic/elastic6-query-service.d.ts +104 -0
  38. package/dist/cores/elastic/elastic6-query-service.js +510 -0
  39. package/dist/cores/elastic/elastic6-query-service.js.map +1 -0
  40. package/dist/cores/elastic/elastic6-service.d.ts +273 -0
  41. package/dist/cores/elastic/elastic6-service.js +903 -0
  42. package/dist/cores/elastic/elastic6-service.js.map +1 -0
  43. package/dist/cores/elastic/hangul-service.d.ts +102 -0
  44. package/dist/cores/elastic/hangul-service.js +205 -0
  45. package/dist/cores/elastic/hangul-service.js.map +1 -0
  46. package/dist/cores/elastic/index.d.ts +12 -0
  47. package/dist/cores/elastic/index.js +29 -0
  48. package/dist/cores/elastic/index.js.map +1 -0
  49. package/dist/cores/hangul-service.d.ts +17 -3
  50. package/dist/cores/hangul-service.js +17 -8
  51. package/dist/cores/hangul-service.js.map +1 -1
  52. package/dist/cores/index.d.ts +5 -11
  53. package/dist/cores/index.js +8 -13
  54. package/dist/cores/index.js.map +1 -1
  55. package/dist/cores/lambda/lambda-dynamo-stream-handler.d.ts +2 -2
  56. package/dist/cores/lambda/lambda-web-handler.d.ts +158 -8
  57. package/dist/cores/lambda/lambda-web-handler.js +283 -77
  58. package/dist/cores/lambda/lambda-web-handler.js.map +1 -1
  59. package/dist/cores/protocol/protocol-service.d.ts +4 -0
  60. package/dist/cores/protocol/protocol-service.js +12 -7
  61. package/dist/cores/protocol/protocol-service.js.map +1 -1
  62. package/dist/cores/storage/http-storage-service.d.ts +22 -0
  63. package/dist/cores/storage/http-storage-service.js +129 -0
  64. package/dist/cores/storage/http-storage-service.js.map +1 -0
  65. package/dist/cores/storage/index.d.ts +14 -0
  66. package/dist/cores/storage/index.js +31 -0
  67. package/dist/cores/storage/index.js.map +1 -0
  68. package/dist/cores/storage/model-manager.d.ts +93 -0
  69. package/dist/cores/storage/model-manager.js +192 -0
  70. package/dist/cores/storage/model-manager.js.map +1 -0
  71. package/dist/cores/storage/proxy-storage-service.d.ts +573 -0
  72. package/dist/cores/storage/proxy-storage-service.js +913 -0
  73. package/dist/cores/storage/proxy-storage-service.js.map +1 -0
  74. package/dist/cores/storage/redis-storage-service.d.ts +183 -0
  75. package/dist/cores/storage/redis-storage-service.js +391 -0
  76. package/dist/cores/storage/redis-storage-service.js.map +1 -0
  77. package/dist/cores/storage/storage-service.d.ts +169 -0
  78. package/dist/cores/storage/storage-service.js +374 -0
  79. package/dist/cores/storage/storage-service.js.map +1 -0
  80. package/dist/cores/storage-service.d.ts +1 -1
  81. package/dist/cores/storage-service.js +2 -2
  82. package/dist/cores/storage-service.js.map +1 -1
  83. package/dist/engine/utilities.d.ts +4 -3
  84. package/dist/engine/utilities.js +6 -6
  85. package/dist/engine/utilities.js.map +1 -1
  86. package/dist/environ.d.ts +2 -2
  87. package/dist/environ.js +7 -4
  88. package/dist/environ.js.map +1 -1
  89. package/dist/extended/abstract-service.d.ts +533 -0
  90. package/dist/extended/abstract-service.js +915 -0
  91. package/dist/extended/abstract-service.js.map +1 -0
  92. package/dist/extended/index.d.ts +10 -0
  93. package/dist/extended/index.js +27 -0
  94. package/dist/extended/index.js.map +1 -0
  95. package/dist/helpers/helpers.d.ts +7 -0
  96. package/dist/helpers/helpers.js +7 -0
  97. package/dist/helpers/helpers.js.map +1 -1
  98. package/dist/index.d.ts +1 -0
  99. package/dist/index.js +3 -1
  100. package/dist/index.js.map +1 -1
  101. package/package.json +6 -4
@@ -0,0 +1,573 @@
1
+ import { StorageService, StorageModel } from './storage-service';
2
+ import { Elastic6SimpleQueriable } from '../core-types';
3
+ import { GeneralAPIController } from '../../controllers/general-api-controller';
4
+ /**
5
+ * class: `CoreKey`
6
+ * - to represent internal partition-key and model-id.
7
+ */
8
+ export interface CoreKey<ModelType extends string> {
9
+ /**
10
+ * defualt internal partition-key
11
+ */
12
+ _id?: string;
13
+ /**
14
+ * namespace
15
+ */
16
+ ns?: string;
17
+ /**
18
+ * model-id
19
+ */
20
+ id: string;
21
+ /**
22
+ * model-type
23
+ */
24
+ type: ModelType;
25
+ }
26
+ /**
27
+ * class: `CoreKeyMakeable`
28
+ * - make internal key by type + id.
29
+ */
30
+ export interface CoreKeyMakeable<ModelType extends string> {
31
+ /**
32
+ * get key object w/ internal partition-key (default as _id).
33
+ *
34
+ * @param type type of model
35
+ * @param id id of model in type
36
+ */
37
+ asKey$(type: ModelType, id: string): CoreKey<ModelType>;
38
+ /**
39
+ * get key-string to use for query. (USED FOR CUSTOM ID NAME);
40
+ *
41
+ * @param type type of model
42
+ * @param id id of model in type
43
+ */
44
+ asKey?(type: ModelType, id: string): string;
45
+ }
46
+ /**
47
+ * class: `InternalModel`
48
+ * - common internal properties. (ONLY FOR INTERNAL PROCESSING)
49
+ */
50
+ export interface InternalModel<T> {
51
+ /**
52
+ * internal unique partition-key (valid if using default idName )
53
+ */
54
+ _id?: string;
55
+ }
56
+ /**
57
+ * class: `CoreModel`
58
+ * - general model out of base Model to support the common usage
59
+ */
60
+ export interface CoreModel<ModelType extends string> extends StorageModel, InternalModel<CoreModel<ModelType>> {
61
+ /**
62
+ * namespace
63
+ */
64
+ ns?: string;
65
+ /**
66
+ * type of model
67
+ */
68
+ type?: ModelType;
69
+ /**
70
+ * stereo: stereo-type in common type.
71
+ */
72
+ stereo?: string;
73
+ /**
74
+ * site-id
75
+ */
76
+ sid?: string;
77
+ /**
78
+ * user-id
79
+ */
80
+ uid?: string;
81
+ /**
82
+ * group-id
83
+ */
84
+ gid?: string;
85
+ /**
86
+ * lock count to secure sync
87
+ */
88
+ lock?: number;
89
+ /**
90
+ * next sequence number (use `nextSeq()`)
91
+ */
92
+ next?: number;
93
+ /**
94
+ * meta the json stringified string.
95
+ */
96
+ meta?: string | any;
97
+ /**
98
+ * created timestamp
99
+ */
100
+ createdAt?: number;
101
+ /**
102
+ * updated timestamp
103
+ */
104
+ updatedAt?: number;
105
+ /**
106
+ * deleted timestamp
107
+ */
108
+ deletedAt?: number;
109
+ /**
110
+ * error message will be set if error occurred
111
+ */
112
+ error?: string;
113
+ }
114
+ export declare const CORE_FIELDS: string[];
115
+ /**
116
+ * type: ModelFilter
117
+ *
118
+ * @param model the new model to update
119
+ * @param origin the old model (or 2nd model)
120
+ * @return the updated model.
121
+ */
122
+ export declare type CoreModelFilter<T> = (model: T, origin?: T) => T;
123
+ /**
124
+ * class: `CoreModelFilterable`
125
+ * - support filters.
126
+ */
127
+ export interface CoreModelFilterable<T> {
128
+ afterRead: CoreModelFilter<T>;
129
+ beforeSave: CoreModelFilter<T>;
130
+ afterSave: CoreModelFilter<T>;
131
+ beforeUpdate: CoreModelFilter<T>;
132
+ afterUpdate: CoreModelFilter<T>;
133
+ }
134
+ /**
135
+ * class: `StorageMakeable`
136
+ * - makeable of `TypedStorageService`
137
+ */
138
+ export interface StorageMakeable<T extends CoreModel<ModelType>, ModelType extends string> {
139
+ /**
140
+ * create storage-service w/ fields list.
141
+ * @param type type of model
142
+ * @param fields list of field (properties)
143
+ * @param filter filter of model.
144
+ */
145
+ makeStorageService(type: ModelType, fields: string[], filter: CoreModelFilterable<T>): TypedStorageService<T, ModelType>;
146
+ }
147
+ /**
148
+ * class: `GeneralKeyMaker`
149
+ * - use ':' as delimiter to join [ns, type, id]
150
+ */
151
+ export declare class GeneralKeyMaker<ModelType extends string> implements CoreKeyMakeable<ModelType> {
152
+ readonly NS: string;
153
+ readonly DELIMITER: string;
154
+ constructor(ns?: string, delimiter?: string);
155
+ asKey$(type: ModelType, id: string): {
156
+ ns: string;
157
+ id: string;
158
+ type: ModelType;
159
+ _id: string;
160
+ };
161
+ }
162
+ /**
163
+ * class: `GeneralModelFilter`
164
+ * - general model-filter with differential update.
165
+ * - to customize, override this class.
166
+ */
167
+ export declare class GeneralModelFilter<T extends CoreModel<ModelType>, ModelType extends string> implements CoreModelFilterable<T> {
168
+ readonly FIELDS: string[];
169
+ /**
170
+ * default constructor
171
+ */
172
+ constructor(fields: string[]);
173
+ /**
174
+ * parse `.meta` to json
175
+ * @param model the current model
176
+ * @param origin the origin model
177
+ */
178
+ afterRead(model: T, origin?: T): T;
179
+ /**
180
+ * filter for before saving.
181
+ * - make sure data conversion
182
+ * - move the unknown fields to `.meta`.
183
+ *
184
+ * @param model the current model
185
+ * @param origin the origin model
186
+ */
187
+ beforeSave(model: T, origin?: T): T;
188
+ /**
189
+ * called after saving the model.
190
+ * - parse `.meta` back to json object.
191
+ *
192
+ * @param model the saved model
193
+ * @param origin the origin model.
194
+ */
195
+ afterSave(model: T, origin?: T): T;
196
+ /**
197
+ * called before updating the model.
198
+ * @param model the updated model
199
+ * @param incrementals (optional) incremental fields.
200
+ */
201
+ beforeUpdate(model: T, incrementals?: T): T;
202
+ /**
203
+ * called after updating the model.
204
+ * @param model the updated model
205
+ */
206
+ afterUpdate(model: T): T;
207
+ /**
208
+ * override this `onBeforeSave()` in sub-class.
209
+ * @param model the current model
210
+ * @param origin (optional) the origin model
211
+ */
212
+ onBeforeSave(model: T, origin?: T): T;
213
+ }
214
+ /**
215
+ * class: `ProxyStorageService`
216
+ * - support `nextSeq()`, `doLock()`, `doRelease()`
217
+ * - proxed storage-service to wrap the parent storage-service w/ more features.
218
+ * - table is supposed to have internal-key as `_id` string.
219
+ *
220
+ * **Usage**
221
+ * ```js
222
+ * type MyType = '' | 'test';
223
+ * interface MyModel extends CoreModel<MyType>{
224
+ * name?: string;
225
+ * }
226
+ * const storage = new ProxyStorageService<MyModel, MyType>(this, 'TestTable', ['id','name']);
227
+ * const $test = storage.makeTypedStorageService('test');
228
+ * ```
229
+ */
230
+ export declare class ProxyStorageService<T extends CoreModel<ModelType>, ModelType extends string> implements StorageService<T> {
231
+ static readonly AUTO_SEQUENCE = 1000000;
232
+ static readonly TYPE_SEQUENCE = "sequence";
233
+ readonly idName: string;
234
+ readonly service: CoreKeyMakeable<ModelType>;
235
+ readonly storage: StorageService<T>;
236
+ readonly filters: CoreModelFilterable<T>;
237
+ /**
238
+ * create proxed storage-service.
239
+ *
240
+ * @param service service to support `CoreKeyMakeable`
241
+ * @param storage table-name or the parent storage-service
242
+ * @param fields list of fields.
243
+ * @param filters filters of `CoreModelFilterable`
244
+ * @param idName (optional) internal partition-key (default as '_id')
245
+ */
246
+ constructor(service: CoreKeyMakeable<ModelType>, storage: StorageService<T> | string, fields: string[], filters?: CoreModelFilterable<T>, idName?: string);
247
+ /**
248
+ * factory function to create this `proxy-storage-service`
249
+ * @param service key-makeable
250
+ * @param table table-name
251
+ * @param fields list of fields.
252
+ * @param filters model filter.
253
+ * @param idName (optional) internal partition-key (default as '_id')
254
+ */
255
+ static create<T extends CoreModel<ModelType>, ModelType extends string>(service: CoreKeyMakeable<ModelType>, table: string, fields?: string[], filters?: CoreModelFilterable<T>, idName?: string): ProxyStorageService<T, ModelType>;
256
+ /**
257
+ * say hello()
258
+ */
259
+ hello: () => string;
260
+ /**
261
+ * read by _id
262
+ */
263
+ read: (_id: string) => Promise<T>;
264
+ /**
265
+ * read or create by _id
266
+ */
267
+ readOrCreate: (_id: string, model: T) => Promise<T>;
268
+ /**
269
+ * save by _id
270
+ */
271
+ save: (_id: string, model: T) => Promise<T>;
272
+ /**
273
+ * update by _id
274
+ */
275
+ update: (_id: string, model: T, incrementals?: T) => Promise<T>;
276
+ /**
277
+ * increment by _id
278
+ */
279
+ increment: (_id: string, model: T, $update?: T) => Promise<T>;
280
+ /**
281
+ * delete by _id
282
+ */
283
+ delete: (_id: string) => Promise<T>;
284
+ /**
285
+ * get key-id by type+id
286
+ */
287
+ asKey: (type: ModelType, id: string | number) => string;
288
+ /**
289
+ * get next auto-sequence number.
290
+ *
291
+ * @param type type of seqeunce.
292
+ * @param initNext initial next value if not exist.
293
+ */
294
+ nextSeq(type: ModelType, initNext?: number): Promise<number>;
295
+ /**
296
+ * get uuid by type.
297
+ * @param type
298
+ */
299
+ nextUuid(type?: ModelType): Promise<string>;
300
+ /**
301
+ * timer to generate the current-time (msec)
302
+ */
303
+ private $timer;
304
+ setTimer: (timer: () => number) => () => number;
305
+ getTime: () => number;
306
+ /**
307
+ * get time-stamp as now.
308
+ */
309
+ asTime(currentTime?: number): {
310
+ createdAt: number;
311
+ updatedAt: number;
312
+ deletedAt: number;
313
+ };
314
+ /**
315
+ * delete sequence-key.
316
+ * @param type type of seqeunce.
317
+ */
318
+ clearSeq(type: ModelType): Promise<void>;
319
+ /**
320
+ * read model by key + id with optional auto creation.
321
+ *
322
+ * @param type model-type
323
+ * @param id node-id
324
+ * @param $create (optional) initial model if not exist. (or throw 404 error)
325
+ */
326
+ doRead(type: ModelType, id: string, $create?: T): Promise<T>;
327
+ /**
328
+ * delete model by id.
329
+ *
330
+ * @param type model-type
331
+ * @param id node-id
332
+ * @param destroy flag to destroy (real delete)
333
+ */
334
+ doDelete(type: ModelType, id: string, destroy?: boolean): Promise<T>;
335
+ /**
336
+ * update model (or it will create automatically)
337
+ *
338
+ * @param type model-type
339
+ * @param id node-id
340
+ * @param node model
341
+ * @param incrementals (optional) fields to increment
342
+ */
343
+ doUpdate(type: ModelType, id: string, node: T, incrementals?: T): Promise<T>;
344
+ /**
345
+ * update model (or it will create automatically)
346
+ *
347
+ * @param type model-type
348
+ * @param id node-id
349
+ */
350
+ doIncrement(type: ModelType, id: string, $inc: T, $up: T): Promise<T>;
351
+ /**
352
+ * save model by checking origin node.
353
+ * - use `doSave()` rather than `doUpdate()` for both create & update.
354
+ * - if `$create` is null, throw 404 error it if not found.
355
+ *
356
+ * @param type model-type
357
+ * @param id node-id
358
+ * @param node node to save (or update)
359
+ * @param $create (optional) initial creation model if not found.
360
+ */
361
+ doSave(type: ModelType, id: string, node: T, $create?: T): Promise<T>;
362
+ /**
363
+ * lock data-entry by type+id w/ limited time tick
364
+ * - WARN! must release lock by `doRelease()`
365
+ *
366
+ * `total-waited-time = tick * interval (msec)`
367
+ *
368
+ * @param type model-type
369
+ * @param id model-id
370
+ * @param tick tick count to wait.
371
+ * @param interval timeout interval per each tick (in msec, default 1000 = 1sec)
372
+ */
373
+ doLock(type: ModelType, id: string, tick?: number, interval?: number): Promise<boolean>;
374
+ /**
375
+ * release lock by resetting lock = 0.
376
+ *
377
+ * @param type model-type
378
+ * @param id model-id
379
+ */
380
+ doRelease(type: ModelType, id: string): Promise<boolean>;
381
+ /**
382
+ * create storage-service w/ fields list.
383
+ * - idName should be `_id`
384
+ *
385
+ * @param table table-name or dummy file name (ex: `dummy-data.yml`).
386
+ * @param fields required for dynamo table.
387
+ * @param idName internal partition-key name (default '_id')
388
+ */
389
+ static makeStorageService<T>(table: string, fields?: string[], idName?: string): StorageService<T>;
390
+ /**
391
+ * create proxy-storage-service by type
392
+ * @param type model-type
393
+ */
394
+ makeTypedStorageService<U extends T>(type: ModelType): TypedStorageService<U, ModelType>;
395
+ }
396
+ /**
397
+ * class: `TypedStorageService`
398
+ * - wrap id with type + id.
399
+ */
400
+ export declare class TypedStorageService<T extends CoreModel<ModelType>, ModelType extends string> implements StorageService<T> {
401
+ readonly type: ModelType;
402
+ readonly storage: ProxyStorageService<T, ModelType>;
403
+ constructor(service: ProxyStorageService<T, ModelType>, type: ModelType);
404
+ /**
405
+ * show self service name
406
+ */
407
+ hello: () => string;
408
+ /**
409
+ * get next auto-sequence id in number like `1000003`.
410
+ */
411
+ nextId: () => Promise<number>;
412
+ /**
413
+ * get uuid like `d01764cd-9ef2-41e2-9e88-68e79555c979`
414
+ */
415
+ nextUuid: () => Promise<string>;
416
+ /**
417
+ * read model by key + id with optional auto creation.
418
+ * - throws '404 NOT FOUND' if not found.
419
+ *
420
+ * @param id node-id
421
+ */
422
+ read: (id: string | number) => Promise<T>;
423
+ /**
424
+ * read model by key + id with optional auto creation.
425
+ *
426
+ * @param id node-id
427
+ * @param model initial model if not exist. (or throw 404 error)
428
+ */
429
+ readOrCreate: (id: string | number, model: T) => Promise<T>;
430
+ /**
431
+ * update model (or it will create automatically)
432
+ *
433
+ * @param id node-id
434
+ * @param model model to update
435
+ * @param incrementals (optional) fields to increment.
436
+ */
437
+ update: (id: string | number, model: T, incrementals?: T) => Promise<T>;
438
+ /**
439
+ * insert model w/ auto generated id
440
+ *
441
+ * @param model model to insert
442
+ */
443
+ insert: (node: T) => Promise<T>;
444
+ /**
445
+ * update model (or it will create automatically)
446
+ *
447
+ * ```ts
448
+ * //before: { count: 1 };
449
+ * const res = await storage.increment(1, { count: 2 }, { total: 2 });
450
+ * //after : { count: 3, total: 2 }
451
+ * ```
452
+ *
453
+ * @param id node-id
454
+ * @param $increments model only with numbers
455
+ */
456
+ increment: (id: string | number, $increments: T, $update?: T) => Promise<T>;
457
+ /**
458
+ * delete model by id.
459
+ *
460
+ * @param id node-id
461
+ * @param destroy flag to destroy (real delete)
462
+ */
463
+ delete: (id: string | number, destroy?: boolean) => Promise<T>;
464
+ /**
465
+ * save model by checking origin node.
466
+ * - use `doSave()` rather than `doUpdate()` for both create & update.
467
+ * - if `$create` is null, throw 404 error it if not found.
468
+ *
469
+ * @param id node-id
470
+ * @param node node to save (or update)
471
+ * @param $create (optional) initial creation model.
472
+ */
473
+ save: (id: string | number, model: T, $create?: T) => Promise<T>;
474
+ /**
475
+ * lock data-entry by type+id w/ limited time tick
476
+ * - WARN! must release lock by `release(id)`
477
+ *
478
+ * `total-waited-time = tick * interval (msec)`
479
+ *
480
+ * **[UPDATES]**
481
+ * 1. read original node (or, throw 404 error)
482
+ * 2. use internal lock.
483
+ *
484
+ * @param id model-id to lock
485
+ * @param tick tick count to wait.
486
+ * @param interval timeout interval per each tick (in msec, default 1000 = 1sec)
487
+ */
488
+ lock: (id: string | number, tick?: number, interval?: number) => Promise<boolean>;
489
+ /**
490
+ * release lock by resetting lock = 0.
491
+ * @param id model-id
492
+ */
493
+ release: (id: string | number) => Promise<boolean>;
494
+ /**
495
+ * using `lock()`, guard func with auto lock & release.
496
+ *
497
+ * ```ts
498
+ * const res = await storage.guard(async ()=>{
499
+ * return 'abc';
500
+ * });
501
+ * // res === 'abc'
502
+ * ```
503
+ */
504
+ guard: <T_1>(id: string | number, handler: () => T_1 | Promise<T_1>, tick?: number, interval?: number) => Promise<any>;
505
+ /**
506
+ * make `UniqueFieldManager` for field.
507
+ */
508
+ makeUniqueFieldManager: (field: string) => UniqueFieldManager<T, ModelType>;
509
+ /**
510
+ * make `GeneralAPIController` for REST API w/ supporting basic CRUD
511
+ */
512
+ makeGeneralAPIController: (search?: Elastic6SimpleQueriable<any>, uniqueField?: string) => GeneralAPIController<this, string>;
513
+ }
514
+ /**
515
+ * class: `ModelUtil`
516
+ * - Helper functions for model.
517
+ */
518
+ export declare class ModelUtil {
519
+ static selfRead: <T>(self: any, key: string, defValue?: T) => T;
520
+ static selfPop: <T>(self: any, key: string, defValue?: T) => T;
521
+ /**
522
+ * attach `.pop()` method to object.
523
+ *
524
+ * ```js
525
+ * const data = CoreModelUtil.buildPop({'a':1});
526
+ * assert( 1 === data.pop('a) );
527
+ * const final = data.pop();
528
+ * assert( final == data );
529
+ */
530
+ static buildPop: (thiz: any, popName?: string) => any;
531
+ }
532
+ /**
533
+ * class: `UniqueFieldManager`
534
+ * - support `.{field}` is unique in typed-storage-service.
535
+ * - make lookup data entry to save the reverse mapping to origin id.
536
+ * - set `.stereo` as '#' to mark as lookup. (to filter out from Elastic.search())
537
+ * - set `.id` as `#{field}/{name}` or `#{name}`.
538
+ * - set `.meta` as origin id.
539
+ */
540
+ export declare class UniqueFieldManager<T extends CoreModel<ModelType>, ModelType extends string> {
541
+ readonly type: ModelType;
542
+ readonly field: string;
543
+ readonly storage: TypedStorageService<T, ModelType>;
544
+ constructor(storage: TypedStorageService<T, ModelType>, field?: string);
545
+ hello: () => string;
546
+ /**
547
+ * validate value format
548
+ * - just check empty string.
549
+ * @param value unique value in same type+field.
550
+ */
551
+ validate(value: string): boolean;
552
+ /**
553
+ * convert to internal id by value
554
+ * @param value unique value in same type group.
555
+ */
556
+ asLookupId(value: string): string;
557
+ /**
558
+ * lookup model by value
559
+ * - use `.meta` property to link with the origin.
560
+ * - mark `.stereo` as to '#' to distinguish normal.
561
+ *
562
+ * @param value unique value in same type group.
563
+ * @param $creates (optional) create-set if not found.
564
+ */
565
+ findOrCreate(value: string, $creates?: T): Promise<T>;
566
+ /**
567
+ * update lookup table (or create)
568
+ *
569
+ * @param model target model
570
+ * @param value (optional) new value of model.
571
+ */
572
+ updateLookup(model: T, value?: string): Promise<T>;
573
+ }