@samet-it/be-db-common 1.0.11
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/LICENSE +24 -0
- package/README.md +74 -0
- package/dist/assets/.gitkeep +0 -0
- package/dist/connection/db.connection.d.ts +74 -0
- package/dist/connection/db.connection.js +173 -0
- package/dist/connection/index.d.ts +2 -0
- package/dist/connection/index.js +18 -0
- package/dist/connection/index.types.d.ts +294 -0
- package/dist/connection/index.types.js +2 -0
- package/dist/error/db-execute.error.d.ts +5 -0
- package/dist/error/db-execute.error.js +10 -0
- package/dist/error/db-invalid-value.error.d.ts +5 -0
- package/dist/error/db-invalid-value.error.js +10 -0
- package/dist/error/db-not-supported.error.d.ts +4 -0
- package/dist/error/db-not-supported.error.js +10 -0
- package/dist/error/db.error.d.ts +7 -0
- package/dist/error/db.error.js +10 -0
- package/dist/error/index.d.ts +5 -0
- package/dist/error/index.js +21 -0
- package/dist/error/index.types.d.ts +1 -0
- package/dist/error/index.types.js +2 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +20 -0
- package/dist/line/db-lines.impl.d.ts +7 -0
- package/dist/line/db-lines.impl.js +141 -0
- package/dist/line/index.d.ts +2 -0
- package/dist/line/index.js +18 -0
- package/dist/line/index.types.d.ts +103 -0
- package/dist/line/index.types.js +2 -0
- package/dist/repo/db.repo.d.ts +147 -0
- package/dist/repo/db.repo.js +924 -0
- package/dist/repo/index.d.ts +2 -0
- package/dist/repo/index.js +18 -0
- package/dist/repo/index.types.d.ts +701 -0
- package/dist/repo/index.types.js +2 -0
- package/package.json +72 -0
|
@@ -0,0 +1,701 @@
|
|
|
1
|
+
import type { Entity, IdDocLike, Pair, UrnDocLike, UrnTuple } from "@samet-it/be-base-common";
|
|
2
|
+
import type { DbConnectionBase, DbExecOpt } from "../connection";
|
|
3
|
+
import type { DefDims, Portion, View } from "@samet-it/be-base-common";
|
|
4
|
+
import type { QueryAny, QueryRegular } from "@leyyo/query";
|
|
5
|
+
import type { CacheConnectionLike, CacheChannelLike } from "@samet-it/be-cache-common";
|
|
6
|
+
import type { Fnc, KeyValue, StrKey } from "@leyyo/common";
|
|
7
|
+
/**
|
|
8
|
+
* Urn delimiter literals (options)
|
|
9
|
+
* */
|
|
10
|
+
export type UrnDelimiter = ',' | '|' | ';' | '/';
|
|
11
|
+
/**
|
|
12
|
+
* DB repository interface
|
|
13
|
+
* */
|
|
14
|
+
export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt, ID extends KeyValue, ENTITY extends Entity<ID>, URN extends UrnDocLike, KEYS extends string, DIMS extends DefDims, PAIR extends Pair<ID>, VIEW extends View<ID>, PORTION extends Portion<ID>> {
|
|
15
|
+
/**
|
|
16
|
+
* Props on repository
|
|
17
|
+
* */
|
|
18
|
+
get props(): Readonly<DbRepoProps<CONN, ID, ENTITY>>;
|
|
19
|
+
/**
|
|
20
|
+
* Converts current instance to flatten instance with ignoring generics
|
|
21
|
+
* */
|
|
22
|
+
get $def(): DbRepoDef;
|
|
23
|
+
/**
|
|
24
|
+
* Casts current instance to given type
|
|
25
|
+
* */
|
|
26
|
+
$cast<T>(): T;
|
|
27
|
+
/**
|
|
28
|
+
* Build urn with prefix from urn object
|
|
29
|
+
*
|
|
30
|
+
* @param {UrnDocLike} urnRec - urn object
|
|
31
|
+
* @return {string} - urn
|
|
32
|
+
* */
|
|
33
|
+
toUrn(urnRec: URN): string;
|
|
34
|
+
/**
|
|
35
|
+
* Generates urn tuple
|
|
36
|
+
*
|
|
37
|
+
* @param {UrnDocLike} urnRec - urn object
|
|
38
|
+
* @return {UrnTuple} - urn tuple
|
|
39
|
+
* */
|
|
40
|
+
$toUrnTuple(urnRec: URN): UrnTuple;
|
|
41
|
+
/**
|
|
42
|
+
* Get document by key (primary or secondary)
|
|
43
|
+
*
|
|
44
|
+
* @param {KeyValue} key - primary or secondary key
|
|
45
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
46
|
+
* @return {Promise<Entity?>} - document
|
|
47
|
+
* @async
|
|
48
|
+
* */
|
|
49
|
+
get(key: KeyValue, opt?: OPT | string): Promise<ENTITY | undefined>;
|
|
50
|
+
/**
|
|
51
|
+
* Get document by primary key
|
|
52
|
+
*
|
|
53
|
+
* @param {string} key - primary key
|
|
54
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
55
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
56
|
+
* @return {Promise<Entity?>} - document
|
|
57
|
+
* @async
|
|
58
|
+
* */
|
|
59
|
+
getByPrimary(key: string, opt?: OPT | string, ignoreCheck?: boolean): Promise<ENTITY | undefined>;
|
|
60
|
+
/**
|
|
61
|
+
* Get document by primary key without cache
|
|
62
|
+
*
|
|
63
|
+
* @param {string} key - primary key
|
|
64
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
65
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
66
|
+
* @return {Promise<Entity?>} - document
|
|
67
|
+
* @async
|
|
68
|
+
* */
|
|
69
|
+
$getByPrimary(key: string, opt?: OPT | string, ignoreCheck?: boolean): Promise<ENTITY | undefined>;
|
|
70
|
+
/**
|
|
71
|
+
* Get document by secondary key
|
|
72
|
+
*
|
|
73
|
+
* @param {KeyValue} key - secondary key
|
|
74
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
75
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
76
|
+
* @return {Promise<Entity?>} - document
|
|
77
|
+
* @async
|
|
78
|
+
* */
|
|
79
|
+
getBySecondary(key: KeyValue, opt?: OPT | string, ignoreCheck?: boolean): Promise<ENTITY | undefined>;
|
|
80
|
+
/**
|
|
81
|
+
* Get document by secondary key without cache
|
|
82
|
+
*
|
|
83
|
+
* @param {KeyValue} key - secondary key
|
|
84
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
85
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
86
|
+
* @return {Promise<Entity?>} - document
|
|
87
|
+
* @async
|
|
88
|
+
* */
|
|
89
|
+
$getBySecondary(key: KeyValue, opt?: OPT | string, ignoreCheck?: boolean): Promise<ENTITY | undefined>;
|
|
90
|
+
/**
|
|
91
|
+
* Document exists by key (primary or secondary)
|
|
92
|
+
*
|
|
93
|
+
* @param {KeyValue} key - primary or secondary key
|
|
94
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
95
|
+
* @return {Promise<boolean>} - exists or not
|
|
96
|
+
* @async
|
|
97
|
+
* */
|
|
98
|
+
exists(key: KeyValue, opt?: OPT | string): Promise<boolean>;
|
|
99
|
+
/**
|
|
100
|
+
* Document exists by primary key
|
|
101
|
+
*
|
|
102
|
+
* @param {string} key - primary key
|
|
103
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
104
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
105
|
+
* @return {Promise<boolean>} - exists or not
|
|
106
|
+
* @async
|
|
107
|
+
* */
|
|
108
|
+
existsByPrimary(key: string, opt?: OPT | string, ignoreCheck?: boolean): Promise<boolean>;
|
|
109
|
+
/**
|
|
110
|
+
* Document exists by primary key without cache
|
|
111
|
+
*
|
|
112
|
+
* @param {string} key - primary key
|
|
113
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
114
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
115
|
+
* @return {Promise<boolean>} - exists or not
|
|
116
|
+
* @async
|
|
117
|
+
* */
|
|
118
|
+
$existsByPrimary(key: string, opt?: OPT | string, ignoreCheck?: boolean): Promise<boolean>;
|
|
119
|
+
/**
|
|
120
|
+
* Document exists by secondary key
|
|
121
|
+
*
|
|
122
|
+
* @param {KeyValue} key - secondary key
|
|
123
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
124
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
125
|
+
* @return {Promise<boolean>} - exists or not
|
|
126
|
+
* @async
|
|
127
|
+
* */
|
|
128
|
+
existsBySecondary(key: KeyValue, opt?: OPT | string, ignoreCheck?: boolean): Promise<boolean>;
|
|
129
|
+
/**
|
|
130
|
+
* Document exists by secondary key without cache
|
|
131
|
+
*
|
|
132
|
+
* @param {KeyValue} key - secondary key
|
|
133
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
134
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
135
|
+
* @return {Promise<boolean>} - exists or not
|
|
136
|
+
* @async
|
|
137
|
+
* */
|
|
138
|
+
$existsBySecondary(key: KeyValue, opt?: OPT | string, ignoreCheck?: boolean): Promise<boolean>;
|
|
139
|
+
/**
|
|
140
|
+
* List documents by keys (primary or secondary)
|
|
141
|
+
*
|
|
142
|
+
* @param {Array<KeyValue>} keys - primary or secondary keys
|
|
143
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
144
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
145
|
+
* @return {Promise<Array<Entity>>} - documents
|
|
146
|
+
* @async
|
|
147
|
+
* */
|
|
148
|
+
list(keys: Array<KeyValue>, opt?: OPT | string, ignoreCheck?: boolean): Promise<Array<ENTITY>>;
|
|
149
|
+
/**
|
|
150
|
+
* List documents by primary keys
|
|
151
|
+
*
|
|
152
|
+
* @param {Array<string>} keys - primary keys
|
|
153
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
154
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
155
|
+
* @return {Promise<Array<Entity>>} - documents
|
|
156
|
+
* @async
|
|
157
|
+
* */
|
|
158
|
+
$listByPrimary(keys: string[], opt?: OPT | string, ignoreCheck?: boolean): Promise<Array<ENTITY>>;
|
|
159
|
+
/**
|
|
160
|
+
* List documents by secondary keys
|
|
161
|
+
*
|
|
162
|
+
* @param {Array<KeyValue>} keys - secondary keys
|
|
163
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
164
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
165
|
+
* @return {Promise<Array<Entity>>} - documents
|
|
166
|
+
* @async
|
|
167
|
+
* */
|
|
168
|
+
$listBySecondary(keys: Array<KeyValue>, opt?: OPT | string, ignoreCheck?: boolean): Promise<Array<ENTITY>>;
|
|
169
|
+
/**
|
|
170
|
+
* Filter documents
|
|
171
|
+
*
|
|
172
|
+
* @param {QueryAny} query - query object
|
|
173
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
174
|
+
* @return {Promise<Array<Entity>>} - documents
|
|
175
|
+
* @async
|
|
176
|
+
* */
|
|
177
|
+
filter<R = ENTITY, K2 extends string = StrKey<R>>(query: QueryAny<K2 | KEYS | StrKey<ENTITY>>, opt?: OPT | string): Promise<Array<R>>;
|
|
178
|
+
$filter<R = ENTITY, K2 extends string = StrKey<R>>(query: QueryRegular<K2 | KEYS | StrKey<ENTITY>>, opt?: OPT | string): Promise<Array<R>>;
|
|
179
|
+
/**
|
|
180
|
+
* Insert document
|
|
181
|
+
*
|
|
182
|
+
* @param {Entity} doc - document
|
|
183
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
184
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
185
|
+
* @async
|
|
186
|
+
* */
|
|
187
|
+
insert(doc: ENTITY, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
|
|
188
|
+
/**
|
|
189
|
+
* Inserts document
|
|
190
|
+
*
|
|
191
|
+
* @param {Entity[]} docs - documents
|
|
192
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
193
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
194
|
+
* @async
|
|
195
|
+
* */
|
|
196
|
+
inserts(docs: Array<ENTITY>, opt?: OPT | string, ignoreCheck?: boolean): Promise<Array<string>>;
|
|
197
|
+
/**
|
|
198
|
+
* Insert document
|
|
199
|
+
*
|
|
200
|
+
* @param {Entity} doc - document
|
|
201
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
202
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
203
|
+
* @async
|
|
204
|
+
* */
|
|
205
|
+
$insert(doc: ENTITY, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
|
|
206
|
+
/**
|
|
207
|
+
* Replace document
|
|
208
|
+
*
|
|
209
|
+
* @param {Entity} doc - document
|
|
210
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
211
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
212
|
+
* @async
|
|
213
|
+
* */
|
|
214
|
+
replace(doc: ENTITY, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
|
|
215
|
+
/**
|
|
216
|
+
* Replace document
|
|
217
|
+
*
|
|
218
|
+
* @param {Entity} doc - document
|
|
219
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
220
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
221
|
+
* @async
|
|
222
|
+
* */
|
|
223
|
+
$replace(doc: ENTITY, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
|
|
224
|
+
/**
|
|
225
|
+
* Update document by key (primary or secondary)
|
|
226
|
+
*
|
|
227
|
+
* @param {KeyValue} key - primary or secondary key
|
|
228
|
+
* @param {Entity} doc - document
|
|
229
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
230
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
231
|
+
* @return {Promise<string>}
|
|
232
|
+
* @async
|
|
233
|
+
* */
|
|
234
|
+
update(key: KeyValue, doc: Partial<ENTITY>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
|
|
235
|
+
/**
|
|
236
|
+
* Update document by primary key
|
|
237
|
+
*
|
|
238
|
+
* @param {string} key - primary key
|
|
239
|
+
* @param {Partial<Entity>} doc - document
|
|
240
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
241
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
242
|
+
* @return {Promise<string>}
|
|
243
|
+
* @async
|
|
244
|
+
* */
|
|
245
|
+
updateByPrimary(key: string, doc: Partial<ENTITY>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
|
|
246
|
+
/**
|
|
247
|
+
* Update document by primary key
|
|
248
|
+
*
|
|
249
|
+
* @param {string} key - primary key
|
|
250
|
+
* @param {Partial<Entity>} doc - document
|
|
251
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
252
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
253
|
+
* @return {Promise<string>}
|
|
254
|
+
* @async
|
|
255
|
+
* */
|
|
256
|
+
$updateByPrimary(key: string, doc: Partial<ENTITY>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
|
|
257
|
+
/**
|
|
258
|
+
* Update document by secondary key
|
|
259
|
+
*
|
|
260
|
+
* @param {KeyValue} key - secondary key
|
|
261
|
+
* @param {Partial<Entity>} doc - document
|
|
262
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
263
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
264
|
+
* @return {Promise<string>}
|
|
265
|
+
* @async
|
|
266
|
+
* */
|
|
267
|
+
updateBySecondary(key: KeyValue, doc: Partial<ENTITY>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
|
|
268
|
+
/**
|
|
269
|
+
* Update document by secondary key
|
|
270
|
+
*
|
|
271
|
+
* @param {KeyValue} key - secondary key
|
|
272
|
+
* @param {Partial<Entity>} doc - document
|
|
273
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
274
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
275
|
+
* @return {Promise<string>}
|
|
276
|
+
* @async
|
|
277
|
+
* */
|
|
278
|
+
$updateBySecondary(key: KeyValue, doc: Partial<ENTITY>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
|
|
279
|
+
/**
|
|
280
|
+
* Set document with partial data by key (primary or secondary)
|
|
281
|
+
*
|
|
282
|
+
* @param {KeyValue} key - primary or secondary key
|
|
283
|
+
* @param {Partial<Entity>} doc - partial entity will be set
|
|
284
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
285
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
286
|
+
* @return {Promise<string>}
|
|
287
|
+
* @async
|
|
288
|
+
* */
|
|
289
|
+
set(key: KeyValue, doc: Partial<ENTITY>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
|
|
290
|
+
/**
|
|
291
|
+
* Unset document for given fields
|
|
292
|
+
*
|
|
293
|
+
* @param {KeyValue} key - primary or secondary key
|
|
294
|
+
* @param {Array<string>} fields - fields will be unset
|
|
295
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
296
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
297
|
+
* @return {Promise<string>}
|
|
298
|
+
* @async
|
|
299
|
+
* */
|
|
300
|
+
unset(key: KeyValue, fields: Array<keyof ENTITY | string>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
|
|
301
|
+
/**
|
|
302
|
+
* Remove document (hard delete) by key (primary or secondary)
|
|
303
|
+
*
|
|
304
|
+
* @param {KeyValue} key - primary or secondary key
|
|
305
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
306
|
+
* @async
|
|
307
|
+
* */
|
|
308
|
+
remove(key: KeyValue, opt?: OPT | string): Promise<string>;
|
|
309
|
+
/**
|
|
310
|
+
* Remove document by primary key (hard delete)
|
|
311
|
+
*
|
|
312
|
+
* @param {string} key - primary key
|
|
313
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
314
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
315
|
+
* @async
|
|
316
|
+
* */
|
|
317
|
+
removeByPrimary(key: string, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
|
|
318
|
+
/**
|
|
319
|
+
* Remove document by primary key (hard delete)
|
|
320
|
+
*
|
|
321
|
+
* @param {string} key - primary key
|
|
322
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
323
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
324
|
+
* @async
|
|
325
|
+
* */
|
|
326
|
+
$removeByPrimary(key: string, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
|
|
327
|
+
/**
|
|
328
|
+
* Remove document by secondary key (hard delete)
|
|
329
|
+
*
|
|
330
|
+
* @param {KeyValue} key - secondary key
|
|
331
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
332
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
333
|
+
* @async
|
|
334
|
+
* */
|
|
335
|
+
removeBySecondary(key: KeyValue, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
|
|
336
|
+
/**
|
|
337
|
+
* Remove document by secondary key (hard delete)
|
|
338
|
+
*
|
|
339
|
+
* @param {KeyValue} key - secondary key
|
|
340
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
341
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
342
|
+
* @async
|
|
343
|
+
* */
|
|
344
|
+
$removeBySecondary(key: KeyValue, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
|
|
345
|
+
/**
|
|
346
|
+
* Trash document (soft delete) by key (primary or secondary)
|
|
347
|
+
*
|
|
348
|
+
* @param {KeyValue} key - primary or secondary key
|
|
349
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
350
|
+
* @async
|
|
351
|
+
* */
|
|
352
|
+
trash(key: KeyValue, opt?: OPT | string): Promise<string>;
|
|
353
|
+
/**
|
|
354
|
+
* Trash document by primary key (soft delete)
|
|
355
|
+
*
|
|
356
|
+
* @param {string} key - primary key
|
|
357
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
358
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
359
|
+
* @async
|
|
360
|
+
* */
|
|
361
|
+
trashByPrimary(key: string, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
|
|
362
|
+
/**
|
|
363
|
+
* Trash document by primary key (soft delete)
|
|
364
|
+
*
|
|
365
|
+
* @param {string} key - primary key
|
|
366
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
367
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
368
|
+
* @async
|
|
369
|
+
* */
|
|
370
|
+
$trashByPrimary(key: string, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
|
|
371
|
+
/**
|
|
372
|
+
* Trash document by secondary key (soft delete)
|
|
373
|
+
*
|
|
374
|
+
* @param {KeyValue} key - secondary key
|
|
375
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
376
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
377
|
+
* @async
|
|
378
|
+
* */
|
|
379
|
+
trashBySecondary(key: KeyValue, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
|
|
380
|
+
/**
|
|
381
|
+
* Trash document by secondary key (soft delete)
|
|
382
|
+
*
|
|
383
|
+
* @param {KeyValue} key - secondary key
|
|
384
|
+
* @param {(opt?: OPT|string)?} opt - option or query name
|
|
385
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
386
|
+
* @async
|
|
387
|
+
* */
|
|
388
|
+
$trashBySecondary(key: KeyValue, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
|
|
389
|
+
/**
|
|
390
|
+
* Convert a document to a dim
|
|
391
|
+
*
|
|
392
|
+
* @param {Entity} doc - document object
|
|
393
|
+
* @param {string?} dim - dimension, default: `def`
|
|
394
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
395
|
+
* @return {Promise<IdDocLike>} - dim object
|
|
396
|
+
* @async
|
|
397
|
+
* */
|
|
398
|
+
$toDim<R extends IdDocLike<ID>>(doc: ENTITY, dim?: DIMS): Promise<R>;
|
|
399
|
+
/**
|
|
400
|
+
* Get dim by key (primary or secondary)
|
|
401
|
+
*
|
|
402
|
+
* @param {KeyValue} key - primary or secondary key
|
|
403
|
+
* @param {string?} dim - dimension, default: `def`
|
|
404
|
+
* @return {Promise<IdDocLike>} - dim object
|
|
405
|
+
* @async
|
|
406
|
+
* */
|
|
407
|
+
getDim<R extends IdDocLike<ID>>(key: KeyValue, dim?: DIMS): Promise<R>;
|
|
408
|
+
/**
|
|
409
|
+
* List dims by keys (primary or secondary)
|
|
410
|
+
*
|
|
411
|
+
* @param {Array<string>} keys - primary or secondary keys
|
|
412
|
+
* @param {string?} dim - dimension, default: `def`
|
|
413
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
414
|
+
* @return {Promise<Array<IdDocLike>>} - dim objects
|
|
415
|
+
* */
|
|
416
|
+
listDims<R extends IdDocLike<ID>>(keys: Array<KeyValue>, dim?: DIMS, ignoreCheck?: boolean): Promise<Array<R>>;
|
|
417
|
+
/**
|
|
418
|
+
* Set pair by document
|
|
419
|
+
*
|
|
420
|
+
* @param {Entity} doc - document
|
|
421
|
+
* @return {Promise<Pair>} - pair object
|
|
422
|
+
* @async
|
|
423
|
+
* */
|
|
424
|
+
$toPair(doc: ENTITY): Promise<PAIR>;
|
|
425
|
+
/**
|
|
426
|
+
* Get pair by key (primary or secondary)
|
|
427
|
+
*
|
|
428
|
+
* @param {KeyValue} key - primary or secondary key
|
|
429
|
+
* @return {Promise<Pair>} - pair object
|
|
430
|
+
* @async
|
|
431
|
+
* */
|
|
432
|
+
getPair(key: KeyValue): Promise<PAIR>;
|
|
433
|
+
/**
|
|
434
|
+
* List pairs by keys (primary or secondary)
|
|
435
|
+
*
|
|
436
|
+
* @param {Array<KeyValue>} keys - primary or secondary keys
|
|
437
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
438
|
+
* @return {Promise<Array<Pair>>} - pair objects
|
|
439
|
+
* */
|
|
440
|
+
listPairs(keys: Array<KeyValue>, ignoreCheck?: boolean): Promise<Array<PAIR>>;
|
|
441
|
+
/**
|
|
442
|
+
* Set view by document
|
|
443
|
+
*
|
|
444
|
+
* @param {Entity} doc - document
|
|
445
|
+
* @return {Promise<View>} - view object
|
|
446
|
+
* @async
|
|
447
|
+
* */
|
|
448
|
+
$toView(doc: ENTITY): Promise<VIEW>;
|
|
449
|
+
/**
|
|
450
|
+
* Get view by key (primary or secondary)
|
|
451
|
+
*
|
|
452
|
+
* @param {KeyValue} key - primary or secondary key
|
|
453
|
+
* @return {Promise<View>} - view object
|
|
454
|
+
* @async
|
|
455
|
+
* */
|
|
456
|
+
getView(key: KeyValue): Promise<VIEW>;
|
|
457
|
+
/**
|
|
458
|
+
* List views by keys (primary or secondary)
|
|
459
|
+
*
|
|
460
|
+
* @param {Array<KeyValue>} keys - primary or secondary keys
|
|
461
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
462
|
+
* @return {Promise<Array<View>>} - view objects
|
|
463
|
+
* */
|
|
464
|
+
listViews(keys: Array<KeyValue>, ignoreCheck?: boolean): Promise<Array<VIEW>>;
|
|
465
|
+
/**
|
|
466
|
+
* Set portion by document
|
|
467
|
+
*
|
|
468
|
+
* @param {Entity} doc - document
|
|
469
|
+
* @return {Promise<Portion>} - portion object
|
|
470
|
+
* @async
|
|
471
|
+
* */
|
|
472
|
+
$toPortion(doc: ENTITY): Promise<PORTION>;
|
|
473
|
+
/**
|
|
474
|
+
* Get portion by key (primary or secondary)
|
|
475
|
+
*
|
|
476
|
+
* @param {KeyValue} key - primary or secondary key
|
|
477
|
+
* @return {Promise<Portion>} - portion object
|
|
478
|
+
* @async
|
|
479
|
+
* */
|
|
480
|
+
getPortion(key: KeyValue): Promise<PORTION>;
|
|
481
|
+
/**
|
|
482
|
+
* List portions by key (primary or secondary)
|
|
483
|
+
*
|
|
484
|
+
* @param {Array<KeyValue>} keys - primary or secondary keys
|
|
485
|
+
* @param {boolean?} ignoreCheck - ignores to check input
|
|
486
|
+
* @return {Promise<Array<Portion>>} - portion objects
|
|
487
|
+
* */
|
|
488
|
+
listPortions(keys: Array<KeyValue>, ignoreCheck?: boolean): Promise<Array<PORTION>>;
|
|
489
|
+
}
|
|
490
|
+
export type DbRepoDef = DbRepoLike<DbConnectionBase, DbExecOpt, KeyValue, Entity, UrnDocLike, keyof Entity, DefDims, Pair, View, Portion>;
|
|
491
|
+
/**
|
|
492
|
+
* DB repository option
|
|
493
|
+
* */
|
|
494
|
+
export interface DbRepoOpt<ID extends KeyValue, ENTITY extends Entity<ID>> {
|
|
495
|
+
/**
|
|
496
|
+
* Cache repository
|
|
497
|
+
*
|
|
498
|
+
* @type {CacheChannelLike}
|
|
499
|
+
* */
|
|
500
|
+
cache?: CacheChannelLike<CacheConnectionLike, ID, ENTITY>;
|
|
501
|
+
/**
|
|
502
|
+
* Model version
|
|
503
|
+
*
|
|
504
|
+
* @default `1.0.0`
|
|
505
|
+
* @type {string}
|
|
506
|
+
* */
|
|
507
|
+
version?: number;
|
|
508
|
+
/**
|
|
509
|
+
* Urn delimiter
|
|
510
|
+
*
|
|
511
|
+
* @default `,` -- use comma
|
|
512
|
+
* @type {UrnDelimiter}
|
|
513
|
+
* */
|
|
514
|
+
urnDelimiter?: UrnDelimiter;
|
|
515
|
+
/**
|
|
516
|
+
* Urn prefix, like domain:subdomain
|
|
517
|
+
*
|
|
518
|
+
* @type {string}
|
|
519
|
+
* */
|
|
520
|
+
urnPrefix?: string;
|
|
521
|
+
/**
|
|
522
|
+
* Id format, number or string
|
|
523
|
+
* - if yes, it evaluates as integer
|
|
524
|
+
* - if no, it evaluates as string, uuid etc
|
|
525
|
+
* @default `false`
|
|
526
|
+
* */
|
|
527
|
+
useNumericId?: boolean;
|
|
528
|
+
/**
|
|
529
|
+
* Date format, number or iso date
|
|
530
|
+
* - if yes, it generates string - date as `yyyy-mm-dd:hh:ii:ss.lll+z`
|
|
531
|
+
* - if no, it generates number - timestamp
|
|
532
|
+
*
|
|
533
|
+
* @fields `createdAt`, `updatedAt`
|
|
534
|
+
* @default `false`
|
|
535
|
+
* */
|
|
536
|
+
useIsoDate?: boolean;
|
|
537
|
+
/**
|
|
538
|
+
* Id is same with urn or not
|
|
539
|
+
* - if yes, id is same with urn
|
|
540
|
+
* - if no, id is not same with urn
|
|
541
|
+
*
|
|
542
|
+
* @fields `_urn`
|
|
543
|
+
* @default `false`
|
|
544
|
+
* */
|
|
545
|
+
idSame?: boolean;
|
|
546
|
+
/**
|
|
547
|
+
* Ignores soft delete
|
|
548
|
+
* - if yes, it ignores trash case
|
|
549
|
+
* - if no, it validates trash case
|
|
550
|
+
*
|
|
551
|
+
* @fields `_trashId`
|
|
552
|
+
* @default `false`
|
|
553
|
+
* */
|
|
554
|
+
useSoftDelete?: boolean;
|
|
555
|
+
/**
|
|
556
|
+
* Manages `created at` case, as time by `useIsoDate`
|
|
557
|
+
* - if yes, it builds `createdAt`
|
|
558
|
+
* - if no, it ignores `createdAt`
|
|
559
|
+
*
|
|
560
|
+
* @fields `createdAt`
|
|
561
|
+
* @default `false`
|
|
562
|
+
* */
|
|
563
|
+
useCreatedAt?: boolean;
|
|
564
|
+
/**
|
|
565
|
+
* Manages `created by` case, as user
|
|
566
|
+
* - if yes, it builds `createdBy`
|
|
567
|
+
* - if no, it ignores `createdBy`
|
|
568
|
+
*
|
|
569
|
+
* @fields `createdBy`
|
|
570
|
+
* @default `false`
|
|
571
|
+
* */
|
|
572
|
+
useCreatedBy?: boolean;
|
|
573
|
+
/**
|
|
574
|
+
* Ignores updated at time
|
|
575
|
+
* - if yes, it ignores updatedAt
|
|
576
|
+
* - if no, it builds updatedAt
|
|
577
|
+
*
|
|
578
|
+
* @fields `updatedAt`
|
|
579
|
+
* @default `false`
|
|
580
|
+
* */
|
|
581
|
+
useUpdatedAt?: boolean;
|
|
582
|
+
/**
|
|
583
|
+
* Manages `updated by` case, as user
|
|
584
|
+
* - if yes, it builds `updatedBy`
|
|
585
|
+
* - if no, it ignores `updatedBy`
|
|
586
|
+
*
|
|
587
|
+
* @fields `updatedBy`
|
|
588
|
+
* @default `false`
|
|
589
|
+
* */
|
|
590
|
+
useUpdatedBy?: boolean;
|
|
591
|
+
/**
|
|
592
|
+
* Manages `version` case, data model structure
|
|
593
|
+
* - if yes, it builds `_ver`
|
|
594
|
+
* - if no, it ignores `_ver`
|
|
595
|
+
*
|
|
596
|
+
* @fields `_ver`
|
|
597
|
+
* @default `false`
|
|
598
|
+
* */
|
|
599
|
+
useVersion?: boolean;
|
|
600
|
+
/**
|
|
601
|
+
* Manages `revision` case, incrementing count
|
|
602
|
+
* - if yes, it builds `_rev`
|
|
603
|
+
* - if no, it ignores `_rev`
|
|
604
|
+
*
|
|
605
|
+
* @fields `_rev`
|
|
606
|
+
* @default `false`
|
|
607
|
+
* */
|
|
608
|
+
useRevision?: boolean;
|
|
609
|
+
/**
|
|
610
|
+
* Manages `alpha` or `slug` case, to power auto suggest
|
|
611
|
+
* - if yes, it builds `_alpha`
|
|
612
|
+
* - if no, it ignores `_alpha`
|
|
613
|
+
*
|
|
614
|
+
* @fields `_alpha`
|
|
615
|
+
* @default `false`
|
|
616
|
+
* */
|
|
617
|
+
alphaFn?: Fnc;
|
|
618
|
+
/**
|
|
619
|
+
* Manages `search` case, to power search
|
|
620
|
+
* - if yes, it builds `_search`
|
|
621
|
+
* - if no, it ignores `_search`
|
|
622
|
+
*
|
|
623
|
+
* @fields `_alpha`
|
|
624
|
+
* @default `false`
|
|
625
|
+
* */
|
|
626
|
+
searchFn?: Fnc;
|
|
627
|
+
/**
|
|
628
|
+
* Manages `irregular` case, to store irregular field which is not in model
|
|
629
|
+
* - if yes, it builds `_irregular`
|
|
630
|
+
* - if no, it ignores `_irregular`
|
|
631
|
+
*
|
|
632
|
+
* @fields `_irregular`
|
|
633
|
+
* @default `false`
|
|
634
|
+
* */
|
|
635
|
+
irregularFn?: Fnc;
|
|
636
|
+
/**
|
|
637
|
+
* Field list which can not be set (update/replace)
|
|
638
|
+
*
|
|
639
|
+
* @type {Array<string>}
|
|
640
|
+
* */
|
|
641
|
+
forbiddenSet?: Array<keyof ENTITY>;
|
|
642
|
+
/**
|
|
643
|
+
* Field list which can not be unset (clear,delete)
|
|
644
|
+
*
|
|
645
|
+
* @type {Array<string>}
|
|
646
|
+
* */
|
|
647
|
+
forbiddenUnset?: Array<keyof ENTITY>;
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* DB repository props
|
|
651
|
+
* */
|
|
652
|
+
export interface DbRepoProps<CONN extends DbConnectionBase, ID extends KeyValue, ENTITY extends Entity<ID>> extends DbRepoOpt<ID, ENTITY> {
|
|
653
|
+
/**
|
|
654
|
+
* DB connection
|
|
655
|
+
*
|
|
656
|
+
* @type {DbConnectionBase}
|
|
657
|
+
* */
|
|
658
|
+
conn: CONN;
|
|
659
|
+
/**
|
|
660
|
+
* Info path, generally it will be {db}.{schema}.{table}
|
|
661
|
+
*
|
|
662
|
+
* @type {string}
|
|
663
|
+
* */
|
|
664
|
+
path: string;
|
|
665
|
+
/**
|
|
666
|
+
* Length of urn prefix
|
|
667
|
+
*
|
|
668
|
+
* @type {number}
|
|
669
|
+
* */
|
|
670
|
+
urnLength?: number;
|
|
671
|
+
/**
|
|
672
|
+
* Is connected
|
|
673
|
+
*
|
|
674
|
+
* @type {boolean}
|
|
675
|
+
* */
|
|
676
|
+
isConnected?: boolean;
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* DB keys result
|
|
680
|
+
* */
|
|
681
|
+
export interface DbCheckKeysResult<ID extends KeyValue> {
|
|
682
|
+
ids: Array<ID>;
|
|
683
|
+
urns: Array<string>;
|
|
684
|
+
ordered: Array<DbCheckKeysTuple<ID>>;
|
|
685
|
+
}
|
|
686
|
+
export type DbCheckKeysTuple<ID extends KeyValue> = [string, '_urn'] | [ID, 'id'];
|
|
687
|
+
/**
|
|
688
|
+
* DB `$toUrnTuple` lambda
|
|
689
|
+
* @function
|
|
690
|
+
* */
|
|
691
|
+
export type DbRepoToUrnTuple<URN extends UrnDocLike = UrnDocLike> = (urnRec: URN) => UrnTuple;
|
|
692
|
+
/**
|
|
693
|
+
* DB `toDim` lambda
|
|
694
|
+
* @function
|
|
695
|
+
* */
|
|
696
|
+
export type DbRepoToDim<R, ID extends KeyValue, ENTITY extends Entity<ID>, DIMS extends DefDims = DefDims> = (doc: ENTITY, dim: DIMS | undefined) => Promise<R>;
|
|
697
|
+
export interface DbIdLike {
|
|
698
|
+
id?: KeyValue;
|
|
699
|
+
urn?: string;
|
|
700
|
+
_urn?: string;
|
|
701
|
+
}
|