lemon-core 3.0.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.
- package/README.md +13 -21
- package/dist/common/test-helper.js +19 -11
- package/dist/common/test-helper.js.map +1 -1
- package/dist/controllers/dummy-controller.d.ts +1 -1
- package/dist/controllers/dummy-controller.js +2 -2
- package/dist/controllers/dummy-controller.js.map +1 -1
- package/dist/controllers/general-api-controller.d.ts +1 -1
- package/dist/controllers/general-api-controller.js +5 -5
- package/dist/controllers/general-api-controller.js.map +1 -1
- package/dist/controllers/general-controller.js +2 -1
- package/dist/controllers/general-controller.js.map +1 -1
- package/dist/controllers/index.js +6 -2
- package/dist/controllers/index.js.map +1 -1
- package/dist/cores/api/api-service.d.ts +239 -0
- package/dist/cores/api/api-service.js +674 -0
- package/dist/cores/api/api-service.js.map +1 -0
- package/dist/cores/api/index.d.ts +10 -0
- package/dist/cores/api/index.js +27 -0
- package/dist/cores/api/index.js.map +1 -0
- package/dist/cores/api-service.js +19 -18
- package/dist/cores/api-service.js.map +1 -1
- package/dist/cores/aws/aws-kms-service.d.ts +53 -2
- package/dist/cores/aws/aws-kms-service.js +112 -29
- package/dist/cores/aws/aws-kms-service.js.map +1 -1
- package/dist/cores/aws/aws-s3-service.js +19 -18
- package/dist/cores/aws/aws-s3-service.js.map +1 -1
- package/dist/cores/aws/aws-sns-service.js +10 -10
- package/dist/cores/aws/aws-sns-service.js.map +1 -1
- package/dist/cores/aws/aws-sqs-service.js +12 -12
- package/dist/cores/aws/aws-sqs-service.js.map +1 -1
- package/dist/cores/aws/index.js +1 -1
- package/dist/cores/cache/cache-service.d.ts +440 -0
- package/dist/cores/cache/cache-service.js +967 -0
- package/dist/cores/cache/cache-service.js.map +1 -0
- package/dist/cores/cache/index.d.ts +10 -0
- package/dist/cores/cache/index.js +27 -0
- package/dist/cores/cache/index.js.map +1 -0
- package/dist/cores/cache-service.d.ts +54 -18
- package/dist/cores/cache-service.js +56 -45
- package/dist/cores/cache-service.js.map +1 -1
- package/dist/cores/config/config-service.js +11 -10
- package/dist/cores/config/config-service.js.map +1 -1
- package/dist/cores/core-services.js +6 -2
- package/dist/cores/core-services.js.map +1 -1
- package/dist/cores/core-types.d.ts +42 -12
- package/dist/cores/dynamo/dynamo-query-service.d.ts +52 -0
- package/dist/cores/dynamo/dynamo-query-service.js +127 -0
- package/dist/cores/dynamo/dynamo-query-service.js.map +1 -0
- package/dist/cores/dynamo/dynamo-scan-service.d.ts +70 -0
- package/dist/cores/dynamo/dynamo-scan-service.js +164 -0
- package/dist/cores/dynamo/dynamo-scan-service.js.map +1 -0
- package/dist/cores/dynamo/dynamo-service.d.ts +192 -0
- package/dist/cores/dynamo/dynamo-service.js +525 -0
- package/dist/cores/dynamo/dynamo-service.js.map +1 -0
- package/dist/cores/dynamo/index.d.ts +12 -0
- package/dist/cores/dynamo/index.js +29 -0
- package/dist/cores/dynamo/index.js.map +1 -0
- package/dist/cores/dynamo-query-service.js +7 -7
- package/dist/cores/dynamo-query-service.js.map +1 -1
- package/dist/cores/dynamo-scan-service.js +8 -8
- package/dist/cores/dynamo-scan-service.js.map +1 -1
- package/dist/cores/dynamo-service.js +19 -19
- package/dist/cores/dynamo-service.js.map +1 -1
- package/dist/cores/elastic/elastic6-query-service.d.ts +104 -0
- package/dist/cores/elastic/elastic6-query-service.js +510 -0
- package/dist/cores/elastic/elastic6-query-service.js.map +1 -0
- package/dist/cores/elastic/elastic6-service.d.ts +273 -0
- package/dist/cores/elastic/elastic6-service.js +903 -0
- package/dist/cores/elastic/elastic6-service.js.map +1 -0
- package/dist/cores/elastic/hangul-service.d.ts +102 -0
- package/dist/cores/elastic/hangul-service.js +205 -0
- package/dist/cores/elastic/hangul-service.js.map +1 -0
- package/dist/cores/elastic/index.d.ts +12 -0
- package/dist/cores/elastic/index.js +29 -0
- package/dist/cores/elastic/index.js.map +1 -0
- package/dist/cores/elastic6-query-service.js +7 -7
- package/dist/cores/elastic6-query-service.js.map +1 -1
- package/dist/cores/elastic6-service.js +57 -65
- package/dist/cores/elastic6-service.js.map +1 -1
- package/dist/cores/hangul-service.d.ts +17 -3
- package/dist/cores/hangul-service.js +17 -8
- package/dist/cores/hangul-service.js.map +1 -1
- package/dist/cores/http-storage-service.js +1 -1
- package/dist/cores/http-storage-service.js.map +1 -1
- package/dist/cores/index.d.ts +9 -15
- package/dist/cores/index.js +14 -15
- package/dist/cores/index.js.map +1 -1
- package/dist/cores/lambda/index.js +8 -4
- package/dist/cores/lambda/index.js.map +1 -1
- package/dist/cores/lambda/lambda-cognito-handler.js +2 -2
- package/dist/cores/lambda/lambda-cognito-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-cron-handler.js +2 -2
- package/dist/cores/lambda/lambda-cron-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-dynamo-stream-handler.d.ts +2 -2
- package/dist/cores/lambda/lambda-dynamo-stream-handler.js +20 -20
- package/dist/cores/lambda/lambda-dynamo-stream-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-handler.js +12 -11
- package/dist/cores/lambda/lambda-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-notification-handler.js +10 -10
- package/dist/cores/lambda/lambda-notification-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-sns-handler.js +13 -13
- package/dist/cores/lambda/lambda-sns-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-sqs-handler.js +13 -13
- package/dist/cores/lambda/lambda-sqs-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-web-handler.d.ts +158 -8
- package/dist/cores/lambda/lambda-web-handler.js +330 -119
- package/dist/cores/lambda/lambda-web-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-wss-handler.js +16 -12
- package/dist/cores/lambda/lambda-wss-handler.js.map +1 -1
- package/dist/cores/model-manager.js +11 -11
- package/dist/cores/model-manager.js.map +1 -1
- package/dist/cores/protocol/protocol-service.d.ts +4 -0
- package/dist/cores/protocol/protocol-service.js +46 -40
- package/dist/cores/protocol/protocol-service.js.map +1 -1
- package/dist/cores/proxy-storage-service.js +7 -10
- package/dist/cores/proxy-storage-service.js.map +1 -1
- package/dist/cores/redis-storage-service.js +13 -13
- package/dist/cores/redis-storage-service.js.map +1 -1
- package/dist/cores/storage/http-storage-service.d.ts +22 -0
- package/dist/cores/storage/http-storage-service.js +129 -0
- package/dist/cores/storage/http-storage-service.js.map +1 -0
- package/dist/cores/storage/index.d.ts +14 -0
- package/dist/cores/storage/index.js +31 -0
- package/dist/cores/storage/index.js.map +1 -0
- package/dist/cores/storage/model-manager.d.ts +93 -0
- package/dist/cores/storage/model-manager.js +192 -0
- package/dist/cores/storage/model-manager.js.map +1 -0
- package/dist/cores/storage/proxy-storage-service.d.ts +573 -0
- package/dist/cores/storage/proxy-storage-service.js +913 -0
- package/dist/cores/storage/proxy-storage-service.js.map +1 -0
- package/dist/cores/storage/redis-storage-service.d.ts +183 -0
- package/dist/cores/storage/redis-storage-service.js +391 -0
- package/dist/cores/storage/redis-storage-service.js.map +1 -0
- package/dist/cores/storage/storage-service.d.ts +169 -0
- package/dist/cores/storage/storage-service.js +374 -0
- package/dist/cores/storage/storage-service.js.map +1 -0
- package/dist/cores/storage-service.d.ts +1 -1
- package/dist/cores/storage-service.js +10 -8
- package/dist/cores/storage-service.js.map +1 -1
- package/dist/engine/builder.js +27 -20
- package/dist/engine/builder.js.map +1 -1
- package/dist/engine/engine.js +53 -44
- package/dist/engine/engine.js.map +1 -1
- package/dist/engine/index.js +8 -4
- package/dist/engine/index.js.map +1 -1
- package/dist/engine/utilities.d.ts +4 -3
- package/dist/engine/utilities.js +32 -37
- package/dist/engine/utilities.js.map +1 -1
- package/dist/environ.d.ts +2 -2
- package/dist/environ.js +20 -10
- package/dist/environ.js.map +1 -1
- package/dist/exec-cli.js +26 -26
- package/dist/exec-cli.js.map +1 -1
- package/dist/extended/abstract-service.d.ts +533 -0
- package/dist/extended/abstract-service.js +915 -0
- package/dist/extended/abstract-service.js.map +1 -0
- package/dist/extended/index.d.ts +10 -0
- package/dist/extended/index.js +27 -0
- package/dist/extended/index.js.map +1 -0
- package/dist/helpers/helpers.d.ts +273 -0
- package/dist/helpers/helpers.js +613 -0
- package/dist/helpers/helpers.js.map +1 -0
- package/dist/helpers/index.d.ts +10 -0
- package/dist/helpers/index.js +27 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/index.d.ts +7 -5
- package/dist/index.js +11 -4
- package/dist/index.js.map +1 -1
- package/dist/lib/dynamo/expressions.js +35 -27
- package/dist/lib/dynamo/expressions.js.map +1 -1
- package/dist/lib/dynamo/query.js +24 -20
- package/dist/lib/dynamo/query.js.map +1 -1
- package/dist/lib/dynamo/scan.js +17 -13
- package/dist/lib/dynamo/scan.js.map +1 -1
- package/dist/lib/dynamo/serializer.js +11 -7
- package/dist/lib/dynamo/serializer.js.map +1 -1
- package/dist/lib/dynamo/utils.js +19 -14
- package/dist/lib/dynamo/utils.js.map +1 -1
- package/dist/lib/dynamodb-value.js +3 -3
- package/dist/lib/dynamodb-value.js.map +1 -1
- package/dist/lib/index.js +6 -2
- package/dist/lib/index.js.map +1 -1
- package/dist/tools/express.js +21 -15
- package/dist/tools/express.js.map +1 -1
- package/dist/tools/index.js +6 -2
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/shared.js +12 -6
- package/dist/tools/shared.js.map +1 -1
- package/package.json +16 -15
|
@@ -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
|
+
}
|