@samet-it/be-db-common 1.1.1 → 1.1.3

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.
@@ -4,22 +4,26 @@ import type { DefDims, Portion, View } from "@samet-it/be-base-common";
4
4
  import type { QueryAny, QueryRegular } from "@leyyo/query";
5
5
  import type { CacheConnectionLike, CacheChannelLike } from "@samet-it/be-cache-common";
6
6
  import type { KeyValue, StrKey } from "@leyyo/common";
7
- /**
8
- * Urn delimiter literals (options)
9
- * */
10
- export type UrnDelimiter = ',' | '|' | ';' | '/';
11
7
  /**
12
8
  * DB repository interface
9
+ *
10
+ * Generics:
11
+ * - 0-`CONN`: db connection {@link DbConnectionBase}
12
+ * - 1-`OPT`: db execution options {@link DbExecOpt}
13
+ * - 2-`ENT`: entity {@link Entity}
14
+ * - 3-`ID`: id type {@link KeyValue}
15
+ * - 4-`URN`: urn interface {@link UrnDocLike}
16
+ * - 5-`VIEW`: view interface for presentation layer {@link View}
17
+ * - 6-`PAIR`: pair interface for presentation layer {@link Pair}
18
+ * - 7-`PORTION`: portion interface for presentation layer {@link Portion}
19
+ * - 8-`KEYS`: keys to autocomplete, def: keys of {@link Entity}
20
+ * - 9-`DIMS`: dimensions for presentation layer {@link DefDims}
13
21
  * */
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>> {
22
+ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt, ENT extends Entity<ID>, ID extends KeyValue, URN extends UrnDocLike, VIEW extends View<ID>, PAIR extends Pair<ID>, PORTION extends Portion<ID>, KEYS extends string, DIMS extends DefDims> {
15
23
  /**
16
24
  * Props on repository
17
25
  * */
18
- get props(): Readonly<DbRepoProps<CONN, ID, ENTITY>>;
19
- /**
20
- * Converts current instance to flatten instance with ignoring generics
21
- * */
22
- get $def(): DbRepoDef;
26
+ get props(): Readonly<DbRepoProps<CONN, ENT, ID>>;
23
27
  /**
24
28
  * Casts current instance to given type
25
29
  * */
@@ -46,7 +50,7 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
46
50
  * @return {Promise<Entity?>} - document
47
51
  * @async
48
52
  * */
49
- get(key: KeyValue, opt?: OPT | string): Promise<ENTITY | undefined>;
53
+ get(key: KeyValue, opt?: OPT | string): Promise<ENT | undefined>;
50
54
  /**
51
55
  * Get document by primary key
52
56
  *
@@ -56,7 +60,7 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
56
60
  * @return {Promise<Entity?>} - document
57
61
  * @async
58
62
  * */
59
- getByPrimary(key: string, opt?: OPT | string, ignoreCheck?: boolean): Promise<ENTITY | undefined>;
63
+ getByPrimary(key: string, opt?: OPT | string, ignoreCheck?: boolean): Promise<ENT | undefined>;
60
64
  /**
61
65
  * Get document by primary key without cache
62
66
  *
@@ -66,7 +70,7 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
66
70
  * @return {Promise<Entity?>} - document
67
71
  * @async
68
72
  * */
69
- $getByPrimary(key: string, opt?: OPT | string, ignoreCheck?: boolean): Promise<ENTITY | undefined>;
73
+ $getByPrimary(key: string, opt?: OPT | string, ignoreCheck?: boolean): Promise<ENT | undefined>;
70
74
  /**
71
75
  * Get document by secondary key
72
76
  *
@@ -76,7 +80,7 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
76
80
  * @return {Promise<Entity?>} - document
77
81
  * @async
78
82
  * */
79
- getBySecondary(key: KeyValue, opt?: OPT | string, ignoreCheck?: boolean): Promise<ENTITY | undefined>;
83
+ getBySecondary(key: KeyValue, opt?: OPT | string, ignoreCheck?: boolean): Promise<ENT | undefined>;
80
84
  /**
81
85
  * Get document by secondary key without cache
82
86
  *
@@ -86,7 +90,7 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
86
90
  * @return {Promise<Entity?>} - document
87
91
  * @async
88
92
  * */
89
- $getBySecondary(key: KeyValue, opt?: OPT | string, ignoreCheck?: boolean): Promise<ENTITY | undefined>;
93
+ $getBySecondary(key: KeyValue, opt?: OPT | string, ignoreCheck?: boolean): Promise<ENT | undefined>;
90
94
  /**
91
95
  * Document exists by key (primary or secondary)
92
96
  *
@@ -145,7 +149,7 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
145
149
  * @return {Promise<Array<Entity>>} - documents
146
150
  * @async
147
151
  * */
148
- list(keys: Array<KeyValue>, opt?: OPT | string, ignoreCheck?: boolean): Promise<Array<ENTITY>>;
152
+ list(keys: Array<KeyValue>, opt?: OPT | string, ignoreCheck?: boolean): Promise<Array<ENT>>;
149
153
  /**
150
154
  * List documents by primary keys
151
155
  *
@@ -155,7 +159,7 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
155
159
  * @return {Promise<Array<Entity>>} - documents
156
160
  * @async
157
161
  * */
158
- $listByPrimary(keys: string[], opt?: OPT | string, ignoreCheck?: boolean): Promise<Array<ENTITY>>;
162
+ $listByPrimary(keys: string[], opt?: OPT | string, ignoreCheck?: boolean): Promise<Array<ENT>>;
159
163
  /**
160
164
  * List documents by secondary keys
161
165
  *
@@ -165,7 +169,16 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
165
169
  * @return {Promise<Array<Entity>>} - documents
166
170
  * @async
167
171
  * */
168
- $listBySecondary(keys: Array<KeyValue>, opt?: OPT | string, ignoreCheck?: boolean): Promise<Array<ENTITY>>;
172
+ $listBySecondary(keys: Array<KeyValue>, opt?: OPT | string, ignoreCheck?: boolean): Promise<Array<ENT>>;
173
+ /**
174
+ * Filter documents
175
+ *
176
+ * @param {QueryAny} query - query object
177
+ * @param {(opt?: OPT|string)?} opt - option or query name
178
+ * @return {Promise<Array<Entity>>} - documents
179
+ * @async
180
+ * */
181
+ filter<R = ENT, K2 extends string = StrKey<R>>(query: QueryAny<K2 | KEYS | StrKey<ENT>>, opt?: OPT | string): Promise<Array<R>>;
169
182
  /**
170
183
  * Filter documents
171
184
  *
@@ -174,8 +187,7 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
174
187
  * @return {Promise<Array<Entity>>} - documents
175
188
  * @async
176
189
  * */
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>>;
190
+ $filter<R = ENT, K2 extends string = StrKey<R>>(query: QueryRegular<K2 | KEYS | StrKey<ENT>>, opt?: OPT | string): Promise<Array<R>>;
179
191
  /**
180
192
  * Insert document
181
193
  *
@@ -184,7 +196,7 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
184
196
  * @param {boolean?} ignoreCheck - ignores to check input
185
197
  * @async
186
198
  * */
187
- insert(doc: ENTITY, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
199
+ insert(doc: ENT, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
188
200
  /**
189
201
  * Inserts document
190
202
  *
@@ -193,7 +205,7 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
193
205
  * @param {boolean?} ignoreCheck - ignores to check input
194
206
  * @async
195
207
  * */
196
- inserts(docs: Array<ENTITY>, opt?: OPT | string, ignoreCheck?: boolean): Promise<Array<string>>;
208
+ inserts(docs: Array<ENT>, opt?: OPT | string, ignoreCheck?: boolean): Promise<Array<string>>;
197
209
  /**
198
210
  * Insert document
199
211
  *
@@ -202,7 +214,7 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
202
214
  * @param {boolean?} ignoreCheck - ignores to check input
203
215
  * @async
204
216
  * */
205
- $insert(doc: ENTITY, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
217
+ $insert(doc: ENT, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
206
218
  /**
207
219
  * Replace document
208
220
  *
@@ -211,7 +223,7 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
211
223
  * @param {boolean?} ignoreCheck - ignores to check input
212
224
  * @async
213
225
  * */
214
- replace(doc: ENTITY, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
226
+ replace(doc: ENT, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
215
227
  /**
216
228
  * Replace document
217
229
  *
@@ -220,7 +232,25 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
220
232
  * @param {boolean?} ignoreCheck - ignores to check input
221
233
  * @async
222
234
  * */
223
- $replace(doc: ENTITY, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
235
+ $replace(doc: ENT, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
236
+ /**
237
+ * Upsert document
238
+ *
239
+ * @param {Entity} doc - document
240
+ * @param {(opt?: OPT|string)?} opt - option or query name
241
+ * @param {boolean?} ignoreCheck - ignores to check input
242
+ * @async
243
+ * */
244
+ upsert(doc: ENT, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
245
+ /**
246
+ * Upsert document
247
+ *
248
+ * @param {Entity} doc - document
249
+ * @param {(opt?: OPT|string)?} opt - option or query name
250
+ * @param {boolean?} ignoreCheck - ignores to check input
251
+ * @async
252
+ * */
253
+ $upsert(doc: ENT, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
224
254
  /**
225
255
  * Update document by key (primary or secondary)
226
256
  *
@@ -231,7 +261,7 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
231
261
  * @return {Promise<string>}
232
262
  * @async
233
263
  * */
234
- update(key: KeyValue, doc: Partial<ENTITY>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
264
+ update(key: KeyValue, doc: Partial<ENT>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
235
265
  /**
236
266
  * Update document by primary key
237
267
  *
@@ -242,7 +272,7 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
242
272
  * @return {Promise<string>}
243
273
  * @async
244
274
  * */
245
- updateByPrimary(key: string, doc: Partial<ENTITY>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
275
+ updateByPrimary(key: string, doc: Partial<ENT>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
246
276
  /**
247
277
  * Update document by primary key
248
278
  *
@@ -253,7 +283,7 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
253
283
  * @return {Promise<string>}
254
284
  * @async
255
285
  * */
256
- $updateByPrimary(key: string, doc: Partial<ENTITY>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
286
+ $updateByPrimary(key: string, doc: Partial<ENT>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
257
287
  /**
258
288
  * Update document by secondary key
259
289
  *
@@ -264,7 +294,7 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
264
294
  * @return {Promise<string>}
265
295
  * @async
266
296
  * */
267
- updateBySecondary(key: KeyValue, doc: Partial<ENTITY>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
297
+ updateBySecondary(key: KeyValue, doc: Partial<ENT>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
268
298
  /**
269
299
  * Update document by secondary key
270
300
  *
@@ -275,7 +305,7 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
275
305
  * @return {Promise<string>}
276
306
  * @async
277
307
  * */
278
- $updateBySecondary(key: KeyValue, doc: Partial<ENTITY>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
308
+ $updateBySecondary(key: KeyValue, doc: Partial<ENT>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
279
309
  /**
280
310
  * Set document with partial data by key (primary or secondary)
281
311
  *
@@ -286,7 +316,7 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
286
316
  * @return {Promise<string>}
287
317
  * @async
288
318
  * */
289
- set(key: KeyValue, doc: Partial<ENTITY>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
319
+ set(key: KeyValue, doc: Partial<ENT>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
290
320
  /**
291
321
  * Unset document for given fields
292
322
  *
@@ -297,7 +327,7 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
297
327
  * @return {Promise<string>}
298
328
  * @async
299
329
  * */
300
- unset(key: KeyValue, fields: Array<keyof ENTITY | string>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
330
+ unset(key: KeyValue, fields: Array<keyof ENT | KEYS | string>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
301
331
  /**
302
332
  * Remove document (hard delete) by key (primary or secondary)
303
333
  *
@@ -389,15 +419,21 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
389
419
  /**
390
420
  * Convert a document to a dim
391
421
  *
422
+ * Generics
423
+ * - 0-`R`: dim interface {@link IdDocLike}
424
+ *
392
425
  * @param {Entity} doc - document object
393
426
  * @param {string?} dim - dimension, default: `def`
394
427
  * @return {Promise<IdDocLike>} - dim object
395
428
  * @async
396
429
  * */
397
- $toDim<R extends IdDocLike<ID>>(doc: ENTITY, dim?: DIMS): Promise<R>;
430
+ $toDim<R extends IdDocLike<ID>>(doc: ENT, dim?: DIMS): Promise<R>;
398
431
  /**
399
432
  * Get dim by key (primary or secondary)
400
433
  *
434
+ * Generics
435
+ * - 0-`R`: dim interface {@link IdDocLike}
436
+ *
401
437
  * @param {KeyValue} key - primary or secondary key
402
438
  * @param {string?} dim - dimension, default: `def`
403
439
  * @return {Promise<IdDocLike>} - dim object
@@ -407,6 +443,9 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
407
443
  /**
408
444
  * List dims by keys (primary or secondary)
409
445
  *
446
+ * Generics
447
+ * - 0-`R`: dim interface {@link IdDocLike}
448
+ *
410
449
  * @param {Array<string>} keys - primary or secondary keys
411
450
  * @param {string?} dim - dimension, default: `def`
412
451
  * @param {boolean?} ignoreCheck - ignores to check input
@@ -420,7 +459,7 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
420
459
  * @return {Promise<Pair>} - pair object
421
460
  * @async
422
461
  * */
423
- $toPair(doc: ENTITY): Promise<PAIR>;
462
+ $toPair(doc: ENT): Promise<PAIR>;
424
463
  /**
425
464
  * Get pair by key (primary or secondary)
426
465
  *
@@ -444,7 +483,7 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
444
483
  * @return {Promise<View>} - view object
445
484
  * @async
446
485
  * */
447
- $toView(doc: ENTITY): Promise<VIEW>;
486
+ $toView(doc: ENT): Promise<VIEW>;
448
487
  /**
449
488
  * Get view by key (primary or secondary)
450
489
  *
@@ -468,7 +507,7 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
468
507
  * @return {Promise<Portion>} - portion object
469
508
  * @async
470
509
  * */
471
- $toPortion(doc: ENTITY): Promise<PORTION>;
510
+ $toPortion(doc: ENT): Promise<PORTION>;
472
511
  /**
473
512
  * Get portion by key (primary or secondary)
474
513
  *
@@ -486,17 +525,20 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
486
525
  * */
487
526
  listPortions(keys: Array<KeyValue>, ignoreCheck?: boolean): Promise<Array<PORTION>>;
488
527
  }
489
- export type DbRepoDef = DbRepoLike<DbConnectionBase, DbExecOpt, KeyValue, Entity, UrnDocLike, keyof Entity, DefDims, Pair, View, Portion>;
490
528
  /**
491
529
  * DB repository option
530
+ *
531
+ * Generics:
532
+ * - 0-`ENT`: entity {@link Entity}
533
+ * - 1-`ID`: id type {@link KeyValue}
492
534
  * */
493
- export interface DbRepoOpt<ID extends KeyValue, ENTITY extends Entity<ID>> {
535
+ export interface DbRepoOpt<ENT extends Entity<ID>, ID extends KeyValue> {
494
536
  /**
495
537
  * Cache repository
496
538
  *
497
539
  * @type {CacheChannelLike}
498
540
  * */
499
- cache?: CacheChannelLike<CacheConnectionLike, ID, ENTITY>;
541
+ cache?: CacheChannelLike<CacheConnectionLike, ENT, ID>;
500
542
  /**
501
543
  * Model version
502
544
  *
@@ -545,15 +587,6 @@ export interface DbRepoOpt<ID extends KeyValue, ENTITY extends Entity<ID>> {
545
587
  * @default false
546
588
  * */
547
589
  idSame?: boolean;
548
- /**
549
- * Ignores soft delete
550
- * - if yes, it ignores trash case
551
- * - if no, it validates trash case
552
- *
553
- * @fields `_trashId`
554
- * @default false
555
- * */
556
- useSoftDelete?: boolean;
557
590
  /**
558
591
  * Manages `created at` case, as time by `useIsoDate`
559
592
  * - if yes, it builds `createdAt`
@@ -608,6 +641,50 @@ export interface DbRepoOpt<ID extends KeyValue, ENTITY extends Entity<ID>> {
608
641
  * @default false
609
642
  * */
610
643
  useRevision?: boolean;
644
+ /**
645
+ * Check insert commands
646
+ * - if yes, it insert works
647
+ * - if no, it insert raises
648
+ *
649
+ * Commands: `insert`, `upsert`
650
+ *
651
+ * @fields `_rev`
652
+ * @default false
653
+ * */
654
+ noInsert?: boolean;
655
+ /**
656
+ * Check update commands
657
+ * - if yes, it update works
658
+ * - if no, it update raises
659
+ *
660
+ * Commands: `update`, `set`, `unset`, `upsert`
661
+ *
662
+ * @fields `_rev`
663
+ * @default false
664
+ * */
665
+ noUpdate?: boolean;
666
+ /**
667
+ * Check trash commands
668
+ * - if yes, it trash works
669
+ * - if no, it trash raises
670
+ *
671
+ * Commands: `trash`
672
+ *
673
+ * @fields `_rev`
674
+ * @default false
675
+ * */
676
+ noTrash?: boolean;
677
+ /**
678
+ * Check remove commands (delete)
679
+ * - if yes, it remove works
680
+ * - if no, it remove raises
681
+ *
682
+ * Commands: `remove`
683
+ *
684
+ * @fields `_rev`
685
+ * @default false
686
+ * */
687
+ noRemove?: boolean;
611
688
  /**
612
689
  * Manages `alpha` or `slug` case, to power auto suggest
613
690
  * - if yes, it builds `_alpha`
@@ -618,7 +695,7 @@ export interface DbRepoOpt<ID extends KeyValue, ENTITY extends Entity<ID>> {
618
695
  * @param {Entity} doc
619
696
  * @async
620
697
  * */
621
- alphaFn?: DbRepoExtensionLambda<ID, ENTITY>;
698
+ alphaFn?: DbRepoExtensionLambda<ENT, ID>;
622
699
  /**
623
700
  * Manages `search` case, to power search
624
701
  * - if yes, it builds `_search`
@@ -629,7 +706,7 @@ export interface DbRepoOpt<ID extends KeyValue, ENTITY extends Entity<ID>> {
629
706
  * @param {Entity} doc
630
707
  * @async
631
708
  * */
632
- searchFn?: DbRepoExtensionLambda<ID, ENTITY>;
709
+ searchFn?: DbRepoExtensionLambda<ENT, ID>;
633
710
  /**
634
711
  * Manages `irregular` case, to store irregular field which is not in model
635
712
  * - if yes, it builds `_irregular`
@@ -640,24 +717,29 @@ export interface DbRepoOpt<ID extends KeyValue, ENTITY extends Entity<ID>> {
640
717
  * @param {Entity} doc
641
718
  * @async
642
719
  * */
643
- irregularFn?: DbRepoExtensionLambda<ID, ENTITY>;
720
+ irregularFn?: DbRepoExtensionLambda<ENT, ID>;
644
721
  /**
645
722
  * Field list which can not be set (update/replace)
646
723
  *
647
724
  * @type {Array<string>}
648
725
  * */
649
- forbiddenSet?: Array<keyof ENTITY>;
726
+ forbiddenSet?: Array<keyof ENT>;
650
727
  /**
651
728
  * Field list which can not be unset (clear,delete)
652
729
  *
653
730
  * @type {Array<string>}
654
731
  * */
655
- forbiddenUnset?: Array<keyof ENTITY>;
732
+ forbiddenUnset?: Array<keyof ENT>;
656
733
  }
657
734
  /**
658
735
  * DB repository props
736
+ *
737
+ * Generics:
738
+ * - 0-`CONN`: db connection {@link DbConnectionBase}
739
+ * - 1-`ENT`: entity {@link Entity}
740
+ * - 2-`ID`: id type {@link KeyValue}
659
741
  * */
660
- export interface DbRepoProps<CONN extends DbConnectionBase, ID extends KeyValue, ENTITY extends Entity<ID>> extends DbRepoOpt<ID, ENTITY> {
742
+ export interface DbRepoProps<CONN extends DbConnectionBase, ENT extends Entity<ID>, ID extends KeyValue> extends DbRepoOpt<ENT, ID> {
661
743
  /**
662
744
  * DB connection
663
745
  *
@@ -685,6 +767,9 @@ export interface DbRepoProps<CONN extends DbConnectionBase, ID extends KeyValue,
685
767
  }
686
768
  /**
687
769
  * DB keys result
770
+ *
771
+ * Generics:
772
+ * - 0-`ID`: id type {@link KeyValue}
688
773
  * */
689
774
  export interface DbCheckKeysResult<ID extends KeyValue> {
690
775
  ids: Array<ID>;
@@ -693,7 +778,13 @@ export interface DbCheckKeysResult<ID extends KeyValue> {
693
778
  }
694
779
  /**
695
780
  * Response model during key is being checked
696
- * @tuple
781
+ *
782
+ * Tuple
783
+ * - 0: urn or id value
784
+ * - 1: field name as _urn or id
785
+ *
786
+ * Generics:
787
+ * - 0-`ID`: id type {@link KeyValue}
697
788
  *
698
789
  * Options
699
790
  * - if primary(urn) => `[value (string), '_urn'];
@@ -703,6 +794,9 @@ export type DbCheckKeysTuple<ID extends KeyValue> = [string, '_urn'] | [ID, 'id'
703
794
  /**
704
795
  * DB `$toUrnTuple` lambda
705
796
  *
797
+ * Generics:
798
+ * - 0-`URN`: urn interface {@link UrnDocLike}
799
+ *
706
800
  * @see {@link DbRepoLike#$toUrnTuple}
707
801
  * @method
708
802
  *
@@ -713,13 +807,19 @@ export type DbRepoToUrnTuple<URN extends UrnDocLike = UrnDocLike> = (urnRec: URN
713
807
  /**
714
808
  * DB `toDim` lambda
715
809
  *
810
+ * Generics:
811
+ * - 0-`R`: dimension interface
812
+ * - 1-`ENT`: entity {@link Entity}
813
+ * - 2-`ID`: id type {@link KeyValue}
814
+ * - 3-`DIMS`: dimensions for presentation layer {@link DefDims}
815
+ *
716
816
  * @see {@link DbRepoLike#$toDim}
717
817
  * @method
718
818
  *
719
819
  * @param {Entity} doc - document
720
820
  * @param {DefDims} dim - dimension
721
821
  * */
722
- export type DbRepoToDim<R, ID extends KeyValue, ENTITY extends Entity<ID>, DIMS extends DefDims = DefDims> = (doc: ENTITY, dim: DIMS | undefined) => Promise<R>;
822
+ export type DbRepoToDim<R, ENT extends Entity<ID>, ID extends KeyValue, DIMS extends DefDims = DefDims> = (doc: ENT, dim: DIMS | undefined) => Promise<R>;
723
823
  /**
724
824
  * Default model which contains keys
725
825
  * */
@@ -746,7 +846,15 @@ export interface DbIdLike {
746
846
  /**
747
847
  * Lambda to handle several extensions, ie: search, ...
748
848
  *
849
+ * Generics:
850
+ * - 0-`ENT`: entity {@link Entity}
851
+ * - 1-`ID`: id type {@link KeyValue}
852
+ *
749
853
  * @param {Entity} doc - document
750
854
  * @async
751
855
  * */
752
- export type DbRepoExtensionLambda<ID extends KeyValue, ENTITY extends Entity<ID>> = (doc: ENTITY) => Promise<void>;
856
+ export type DbRepoExtensionLambda<ENT extends Entity<ID>, ID extends KeyValue> = (doc: ENT) => Promise<void>;
857
+ /**
858
+ * Urn delimiter literals (options)
859
+ * */
860
+ export type UrnDelimiter = ',' | '|' | ';' | '/';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samet-it/be-db-common",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "Backend DB Common",
5
5
  "repository": {
6
6
  "type": "git",
@@ -64,9 +64,9 @@
64
64
  },
65
65
  "dependencies": {
66
66
  "@leyyo/query": "^1.2.2",
67
- "@leyyo/common": "^1.2.1",
67
+ "@leyyo/common": "^1.2.3",
68
68
  "@leyyo/type": "^1.1.1",
69
- "@samet-it/be-base-common": "^1.1.1",
70
- "@samet-it/be-cache-common": "^1.1.1"
69
+ "@samet-it/be-base-common": "^1.1.3",
70
+ "@samet-it/be-cache-common": "^1.1.3"
71
71
  }
72
72
  }