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,440 @@
1
+ /**
2
+ * type `CacheOptions`
3
+ */
4
+ export interface CacheOptions {
5
+ /**
6
+ * (optional) cache backend type (default: 'redis')
7
+ */
8
+ type?: 'memcached' | 'redis';
9
+ /**
10
+ * (optional) cache server endpoint (not required for dummy-cache)
11
+ */
12
+ endpoint?: string;
13
+ /**
14
+ * (optional) namespace. used as cache key prefix to avoid key collision between different services
15
+ */
16
+ ns?: string;
17
+ /**
18
+ * (optional) default timeout of cache entries. 0 for unlimited (default: 1-day)
19
+ */
20
+ defTimeout?: number;
21
+ }
22
+ /**
23
+ * type `CacheKey`
24
+ */
25
+ export declare type CacheKey = string | number;
26
+ /**
27
+ * type: `Timeout`
28
+ */
29
+ export interface Timeout {
30
+ /**
31
+ * key will be expired after given number of seconds
32
+ */
33
+ expireIn?: number;
34
+ /**
35
+ * key will be expired in given Unix timestamp (seconds since epoch)
36
+ * - ignored if 'expireIn' is provided
37
+ * - not accurate because this value is replaced to time to live in seconds using Math.ceil()
38
+ */
39
+ expireAt?: number;
40
+ }
41
+ /**
42
+ * type `CacheEntry`: parameter type of 'setMulti' operation
43
+ */
44
+ export interface CacheEntry<CacheValue> {
45
+ /**
46
+ * key
47
+ */
48
+ key: CacheKey;
49
+ /**
50
+ * value
51
+ */
52
+ val: CacheValue;
53
+ /**
54
+ * timeout - same effect as 'expireIn' if given value is number
55
+ */
56
+ timeout?: number | Timeout;
57
+ }
58
+ /**
59
+ * type `KeyValueMap`: result type of 'getMulti' operation
60
+ */
61
+ export declare type KeyValueMap<CacheValue> = Record<CacheKey, CacheValue>;
62
+ /**
63
+ * class: `CacheKeyMakable`
64
+ * - to provide the custom key-string of cache.
65
+ * - the global pkey would be like `<project>:<model.ns>:<model.type>::<cache-key>` (ex: `lemon:SS:item::100001`)
66
+ */
67
+ export interface CacheKeyMakable {
68
+ /**
69
+ * make the global pkey
70
+ * - default must be like `${ns}${delim}${key}`
71
+ */
72
+ (ns: string, delim: string, key: CacheKey): string;
73
+ }
74
+ /**
75
+ * class: `CacheSupportable`
76
+ * - support basic cache operation(read/write/timeout).
77
+ */
78
+ export interface CacheSupportable<CacheValue = any> {
79
+ /**
80
+ * save into cache w/ timeout(sec)
81
+ */
82
+ set(key: CacheKey, val: CacheValue, timeout?: number | Timeout): Promise<boolean>;
83
+ /**
84
+ * read from cache
85
+ */
86
+ get(key: CacheKey): Promise<CacheValue>;
87
+ /**
88
+ * increment number by `inc`
89
+ * - should be atomic operation w/ thread safe.
90
+ */
91
+ inc(key: CacheKey, inc: number): Promise<number>;
92
+ }
93
+ /**
94
+ * class `CacheService`
95
+ * - common service to provide cache
96
+ */
97
+ export declare class CacheService<CacheValue = any> implements CacheSupportable<CacheValue> {
98
+ /**
99
+ * Environment variable name for cache server endpoint
100
+ * @static
101
+ */
102
+ static readonly ENV_CACHE_ENDPOINT = "CACHE_ENDPOINT";
103
+ /**
104
+ * Environment variable name for default cache timeout
105
+ * @static
106
+ */
107
+ static readonly ENV_CACHE_DEFAULT_TIMEOUT = "CACHE_DEFAULT_TIMEOUT";
108
+ /**
109
+ * Default cache timeout
110
+ * @static
111
+ */
112
+ static readonly DEF_CACHE_DEFAULT_TIMEOUT: number;
113
+ /**
114
+ * Namespace delimiter
115
+ * @private
116
+ * @static
117
+ */
118
+ private static readonly NAMESPACE_DELIMITER;
119
+ /**
120
+ * Namespace of cache key
121
+ */
122
+ readonly ns: string;
123
+ /**
124
+ * the final options to create this service.
125
+ */
126
+ readonly options: CacheOptions;
127
+ /**
128
+ * maker of cache-key
129
+ */
130
+ readonly maker: CacheKeyMakable;
131
+ /**
132
+ * Cache backend instance
133
+ * @private
134
+ */
135
+ private readonly backend;
136
+ /**
137
+ * Factory method
138
+ *
139
+ * @param options (optional) cache options
140
+ * @param maker (optional) custome cache-pkey generator.
141
+ * @static
142
+ */
143
+ static create(options?: CacheOptions, maker?: CacheKeyMakable): CacheService;
144
+ /**
145
+ * Protected constructor -> use CacheService.create()
146
+ * WARN! - do not create directly.˜
147
+ *
148
+ * @param backend cache backend object
149
+ * @param params params to create service.
150
+ * @protected
151
+ */
152
+ protected constructor(backend: CacheBackend, params?: {
153
+ /** (optional) namespace of cache key (default: '') */
154
+ ns?: string;
155
+ /** (optional) the final options to create() */
156
+ options?: CacheOptions;
157
+ /** custom key-maker */
158
+ maker?: CacheKeyMakable;
159
+ });
160
+ /**
161
+ * Say hello
162
+ */
163
+ hello(): string;
164
+ /**
165
+ * for convient, make another typed service.
166
+ * - it add `type` into key automatically.
167
+ *
168
+ * @param type model-type like 'test'
169
+ * @param delimiter (optional) delim bewteen type and key (default ':')
170
+ * @returns the typed CacheService
171
+ */
172
+ cloneByType(type: string, delimiter?: string): CacheService<any>;
173
+ /**
174
+ * Close backend and connection
175
+ */
176
+ close(): Promise<void>;
177
+ /**
178
+ * Check whether the key is cached
179
+ *
180
+ * @return true if the key is cached
181
+ */
182
+ exists(key: CacheKey): Promise<boolean>;
183
+ /**
184
+ * List all keys
185
+ *
186
+ * @return list of keys
187
+ */
188
+ keys(): Promise<string[]>;
189
+ /**
190
+ * Store a key
191
+ *
192
+ * @param key
193
+ * @param val
194
+ * @param timeout (optional) TTL in seconds or Timeout object
195
+ * @return true on success
196
+ */
197
+ set(key: CacheKey, val: CacheValue, timeout?: number | Timeout): Promise<boolean>;
198
+ /**
199
+ * Store multiple keys
200
+ *
201
+ * @param entries
202
+ * @return true on success
203
+ */
204
+ setMulti(entries: CacheEntry<CacheValue>[]): Promise<boolean>;
205
+ /**
206
+ * Retrieve a key
207
+ *
208
+ * @param key
209
+ */
210
+ get(key: CacheKey): Promise<CacheValue | undefined>;
211
+ /**
212
+ * Get multiple keys
213
+ *
214
+ * @param keys
215
+ */
216
+ getMulti(keys: CacheKey[]): Promise<KeyValueMap<CacheValue>>;
217
+ /**
218
+ * Increment the integer value of a key
219
+ *
220
+ * @param key
221
+ * @param inc number to increment
222
+ */
223
+ increment(key: CacheKey, inc: number): Promise<number>;
224
+ /**
225
+ * same as increment()
226
+ */
227
+ inc(key: CacheKey, inc: number): Promise<number>;
228
+ /**
229
+ * Set the value of a key and return its old value
230
+ */
231
+ getAndSet(key: CacheKey, val: CacheValue): Promise<CacheValue | undefined>;
232
+ /**
233
+ * Get and delete the key
234
+ *
235
+ * @param key
236
+ */
237
+ getAndDelete(key: CacheKey): Promise<CacheValue | undefined>;
238
+ /**
239
+ * Delete a key
240
+ *
241
+ * @param key
242
+ * @return true on success
243
+ */
244
+ delete(key: CacheKey): Promise<boolean>;
245
+ /**
246
+ * Delete multiple keys
247
+ *
248
+ * @param keys
249
+ * @return number of deleted entries
250
+ */
251
+ deleteMulti(keys: CacheKey[]): Promise<boolean[]>;
252
+ /**
253
+ * Set or update the timeout of a key
254
+ *
255
+ * @param key
256
+ * @param timeout TTL in seconds or Timeout object
257
+ * @return true on success
258
+ */
259
+ setTimeout(key: CacheKey, timeout: number | Timeout): Promise<boolean>;
260
+ /**
261
+ * Get remaining time to live in milliseconds
262
+ *
263
+ * @return
264
+ * - number of milliseconds to expire
265
+ * - undefined if the key does not exist
266
+ * - 0 if the key has no timeout
267
+ */
268
+ getTimeout(key: CacheKey): Promise<number | undefined>;
269
+ /**
270
+ * Remove the timeout from a key
271
+ *
272
+ * @param key
273
+ */
274
+ removeTimeout(key: CacheKey): Promise<boolean>;
275
+ /**
276
+ * Get namespace prefixed cache key
277
+ *
278
+ * @param key
279
+ * @protected
280
+ */
281
+ asNamespacedKey(key: CacheKey): string;
282
+ }
283
+ /**
284
+ * class `DummyCacheService`: use 'node-cache' library
285
+ */
286
+ export declare class DummyCacheService extends CacheService {
287
+ /**
288
+ * Singleton node-cache backend
289
+ *
290
+ * @private
291
+ * @static
292
+ */
293
+ private static backend;
294
+ /**
295
+ * Factory method
296
+ *
297
+ * @param options (optional) cache options
298
+ * @static
299
+ */
300
+ static create(options?: CacheOptions): DummyCacheService;
301
+ /**
302
+ * Say hello
303
+ */
304
+ hello(): string;
305
+ }
306
+ /**
307
+ * function `sleep`
308
+ * @param ms duration in milliseconds
309
+ */
310
+ export declare function sleep(ms: number): Promise<void>;
311
+ /**
312
+ * Get TTL from timeout
313
+ * @param timeout timeout in seconds or Timeout object
314
+ * @return remaining time to live in seconds
315
+ */
316
+ export declare function toTTL(timeout: number | Timeout): number;
317
+ /**
318
+ * Get timestamp of expiration from TTL
319
+ * @param ttl remaining time to live in seconds
320
+ * @return timestamp in milliseconds since epoch
321
+ */
322
+ export declare function fromTTL(ttl: number): number;
323
+ /** ********************************************************************************************************************
324
+ * Internal Types
325
+ ** ********************************************************************************************************************/
326
+ /**
327
+ * type `ItemEntry`: parameter for mset operation
328
+ */
329
+ interface ItemEntry<T = any> {
330
+ key: string;
331
+ val: T;
332
+ ttl?: number;
333
+ }
334
+ /**
335
+ * interface `CacheBackend`
336
+ * @internal
337
+ */
338
+ interface CacheBackend {
339
+ /**
340
+ * backend type
341
+ */
342
+ readonly name: string;
343
+ /**
344
+ * Set the value of a key
345
+ *
346
+ * @param key
347
+ * @param val
348
+ * @param ttl (optional) time to live in seconds
349
+ * @return true on success
350
+ */
351
+ set<T>(key: string, val: T, ttl?: number): Promise<boolean>;
352
+ /**
353
+ * Get the value of a key
354
+ *
355
+ * @param key
356
+ * @return the value of key, or undefined when key does not exist
357
+ */
358
+ get<T>(key: string): Promise<T | undefined>;
359
+ /**
360
+ * Set multiple keys to multiple values
361
+ *
362
+ * @param entries see ItemEntry
363
+ * @return true on success
364
+ */
365
+ mset<T>(entries: ItemEntry<T>[]): Promise<boolean>;
366
+ /**
367
+ * Get the values of all the given keys
368
+ *
369
+ * @param keys
370
+ * @return key-value map
371
+ */
372
+ mget<T>(keys: string[]): Promise<{
373
+ [key: string]: T;
374
+ }>;
375
+ /**
376
+ * (optional) Set the value of a key and return its old value
377
+ *
378
+ * @param key
379
+ * @param val
380
+ * @return the old value stored at key, or undefined when key did not exist
381
+ */
382
+ getset?<T, U>(key: string, val: T): Promise<U | undefined>;
383
+ /**
384
+ * (optional) Get the value of a key and remove the key
385
+ *
386
+ * @param key
387
+ * @return the old value stored at key, or undefined when key did not exist
388
+ */
389
+ pop?<T>(key: string): Promise<T | undefined>;
390
+ /**
391
+ * Increment the integer value of a key
392
+ *
393
+ * @param key
394
+ * @param increment amount to increment
395
+ * @return the value of key after the increment
396
+ */
397
+ incr(key: string, increment: number): Promise<number>;
398
+ /**
399
+ * List all keys
400
+ *
401
+ * @return list of keys
402
+ */
403
+ keys(): Promise<string[]>;
404
+ /**
405
+ * Determine if a key exists
406
+ *
407
+ * @param key
408
+ * @return true on success
409
+ */
410
+ has(key: string): Promise<boolean>;
411
+ /**
412
+ * Delete a key
413
+ *
414
+ * @param key
415
+ * @return true on success
416
+ */
417
+ del(key: string): Promise<boolean>;
418
+ /**
419
+ * Set the time to live in seconds
420
+ *
421
+ * @param key
422
+ * @param ttl time to live in seconds
423
+ * @return true on success
424
+ */
425
+ expire(key: string, ttl: number): Promise<boolean>;
426
+ /**
427
+ * Get the time to live for a key in milliseconds
428
+ *
429
+ * @param key
430
+ * @return the remaining time to live in milliseconds
431
+ * - 0 if the key exists but has no associated timeout
432
+ * - undefined if the key does not exist
433
+ */
434
+ ttl(key: string): Promise<number | undefined>;
435
+ /**
436
+ * Close connection(s) to the cache server
437
+ */
438
+ close(): Promise<void>;
439
+ }
440
+ export {};