@samet-it/be-db-common 1.1.7 → 1.1.8

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 CHANGED
@@ -35,6 +35,12 @@ npm i @samet-it/be-db-common
35
35
  - [function dbLines()](./src/line/db-lines.impl.ts)
36
36
  - [abstract class DbRepo](./src/repo/db.repo.ts)
37
37
 
38
+ ## Errors
39
+ - `base error` [DbError](./src/error/db.error.ts)
40
+ - `execute error` [DbExecuteError](./src/error/db-execute.error.ts)
41
+ - `invalid value error` [DbInvalidValueError](./src/error/db-invalid-value.error.ts)
42
+ - `not supported error` [DbNotSupportedError](./src/error/db-not-supported.error.ts)
43
+
38
44
  ## Development
39
45
  > You can start to develop on it
40
46
  >
@@ -157,3 +157,14 @@ export type DbEvent = 'connected' | 'disconnected' | 'first-connected';
157
157
  * - It uses ASL
158
158
  * */
159
159
  export type UserFetcherLambda = () => Promise<KeyValue>;
160
+ /**
161
+ * Db direct connection option
162
+ * */
163
+ export interface DbConnDirectOpt extends DbConnOpt {
164
+ /**
165
+ * logger name
166
+ *
167
+ * @type {string}
168
+ * */
169
+ name?: string;
170
+ }
@@ -53,7 +53,7 @@ export declare abstract class DbRepo<CONN extends DbConnectionLike, OPT extends
53
53
  /**
54
54
  * Check array keys as id list or urn list
55
55
  * */
56
- protected _checkKeys(keys: Array<KeyValue>): DbCheckKeysResult<ID>;
56
+ protected _checkKeys(keys: Array<unknown>): DbCheckKeysResult<ID>;
57
57
  protected _isUrn(key: KeyValue): boolean;
58
58
  protected _keyToUrn(key: KeyValue): string;
59
59
  /** @inheritDoc */
@@ -145,7 +145,7 @@ export declare abstract class DbRepo<CONN extends DbConnectionLike, OPT extends
145
145
  /** @inheritDoc */
146
146
  $toUrnTuple(urnRec: URN): UrnTuple;
147
147
  /** @inheritDoc */
148
- get(k1: KeyValue, p1?: OPT | string): Promise<ENT | undefined>;
148
+ get(keyLike: PORTION | KeyValue, p1?: OPT | string): Promise<ENT | undefined>;
149
149
  /** @inheritDoc */
150
150
  getByPrimary(key: string, p1?: OPT | string, ignoreCheck?: boolean): Promise<ENT | undefined>;
151
151
  /** @inheritDoc */
@@ -155,7 +155,7 @@ export declare abstract class DbRepo<CONN extends DbConnectionLike, OPT extends
155
155
  /** @inheritDoc */
156
156
  abstract $getBySecondary(key: KeyValue, p1?: OPT | string, ignoreCheck?: boolean): Promise<ENT | undefined>;
157
157
  /** @inheritDoc */
158
- exists(k1: KeyValue, p1?: OPT | string): Promise<boolean>;
158
+ exists(keyLike: PORTION | KeyValue, p1?: OPT | string): Promise<boolean>;
159
159
  /** @inheritDoc */
160
160
  existsByPrimary(key: string, p1?: OPT | string, ignoreCheck?: boolean): Promise<boolean>;
161
161
  /** @inheritDoc */
@@ -165,7 +165,7 @@ export declare abstract class DbRepo<CONN extends DbConnectionLike, OPT extends
165
165
  /** @inheritDoc */
166
166
  abstract $existsBySecondary(key: KeyValue, p1?: OPT | string, ignoreCheck?: boolean): Promise<boolean>;
167
167
  /** @inheritDoc */
168
- list(keys: Array<KeyValue>, p1?: OPT | string, ignoreCheck?: boolean): Promise<Array<ENT>>;
168
+ list(keyLikes: Array<PORTION | KeyValue>, p1?: OPT | string, ignoreCheck?: boolean): Promise<Array<ENT>>;
169
169
  /** @inheritDoc */
170
170
  abstract $listByPrimary(keys: string[], p1?: OPT | string, ignoreCheck?: boolean): Promise<Array<ENT>>;
171
171
  /** @inheritDoc */
@@ -189,7 +189,7 @@ export declare abstract class DbRepo<CONN extends DbConnectionLike, OPT extends
189
189
  /** @inheritDoc */
190
190
  abstract $upsert(doc: ENT, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
191
191
  /** @inheritDoc */
192
- update(k1: KeyValue, doc: Partial<ENT>, p1?: OPT | string, ignoreCheck?: boolean): Promise<string>;
192
+ update(k1: PORTION | KeyValue, doc: Partial<ENT>, p1?: OPT | string, ignoreCheck?: boolean): Promise<string>;
193
193
  /** @inheritDoc */
194
194
  updateByPrimary(key: string, doc: Partial<ENT>, p1?: OPT | string, ignoreCheck?: boolean): Promise<string>;
195
195
  /** @inheritDoc */
@@ -199,11 +199,11 @@ export declare abstract class DbRepo<CONN extends DbConnectionLike, OPT extends
199
199
  /** @inheritDoc */
200
200
  abstract $updateBySecondary(key: KeyValue, doc: Partial<ENT>, p1?: OPT | string, ignoreCheck?: boolean): Promise<string>;
201
201
  /** @inheritDoc */
202
- set(key: KeyValue, doc: Partial<ENT>, p1?: OPT | string, ignoreCheck?: boolean): Promise<string>;
202
+ set(key: PORTION | KeyValue, doc: Partial<ENT>, p1?: OPT | string, ignoreCheck?: boolean): Promise<string>;
203
203
  /** @inheritDoc */
204
- unset(key: KeyValue, fields: Array<keyof ENT | KEYS | string>, p1?: OPT | string, ignoreCheck?: boolean): Promise<string>;
204
+ unset(key: PORTION | KeyValue, fields: Array<keyof ENT | KEYS | string>, p1?: OPT | string, ignoreCheck?: boolean): Promise<string>;
205
205
  /** @inheritDoc */
206
- remove(k1: KeyValue, p1?: OPT | string): Promise<string>;
206
+ remove(keyLike: PORTION | KeyValue, p1?: OPT | string): Promise<string>;
207
207
  /** @inheritDoc */
208
208
  removeByPrimary(key: string, p1?: OPT | string, ignoreCheck?: boolean): Promise<string>;
209
209
  /** @inheritDoc */
@@ -213,7 +213,7 @@ export declare abstract class DbRepo<CONN extends DbConnectionLike, OPT extends
213
213
  /** @inheritDoc */
214
214
  abstract $removeBySecondary(key: KeyValue, p1?: OPT | string, ignoreCheck?: boolean): Promise<string>;
215
215
  /** @inheritDoc */
216
- trash(k1: KeyValue, p1?: OPT | string): Promise<string>;
216
+ trash(keyLike: PORTION | KeyValue, p1?: OPT | string): Promise<string>;
217
217
  /** @inheritDoc */
218
218
  trashByPrimary(key: string, p1?: OPT | string, ignoreCheck?: boolean): Promise<string>;
219
219
  /** @inheritDoc */
@@ -225,24 +225,19 @@ export declare abstract class DbRepo<CONN extends DbConnectionLike, OPT extends
225
225
  /** @inheritDoc */
226
226
  $toDim<R extends IdDocLike<ID>>(doc: ENT, dim?: DIMS): Promise<R>;
227
227
  /** @inheritDoc */
228
- getDim<R extends IdDocLike<ID>>(key: KeyValue, dim?: DIMS): Promise<R>;
228
+ getDim<R extends IdDocLike<ID>>(key: PORTION | KeyValue, dim?: DIMS): Promise<R>;
229
229
  /** @inheritDoc */
230
- listDims<R extends IdDocLike<ID>>(keys: Array<KeyValue>, dim?: DIMS, ignoreCheck?: boolean): Promise<Array<R>>;
230
+ listDims<R extends IdDocLike<ID>>(keys: Array<PORTION | KeyValue>, dim?: DIMS, ignoreCheck?: boolean): Promise<Array<R>>;
231
231
  /** @inheritDoc */
232
- $toPair(doc: ENT): Promise<PAIR>;
232
+ getPair(key: PORTION | KeyValue): Promise<PAIR>;
233
233
  /** @inheritDoc */
234
- getPair(key: KeyValue): Promise<PAIR>;
234
+ listPairs(keys: Array<PORTION | KeyValue>, ignoreCheck?: boolean): Promise<Array<PAIR>>;
235
235
  /** @inheritDoc */
236
- listPairs(keys: Array<KeyValue>, ignoreCheck?: boolean): Promise<Array<PAIR>>;
237
- $toView(doc: ENT): Promise<VIEW>;
236
+ getView(key: PORTION | KeyValue): Promise<VIEW>;
238
237
  /** @inheritDoc */
239
- getView(identifier: string): Promise<VIEW>;
238
+ listViews(keys: Array<PORTION | KeyValue>, ignoreCheck?: boolean): Promise<Array<VIEW>>;
240
239
  /** @inheritDoc */
241
- listViews(identifiers: Array<string>, ignoreCheck?: boolean): Promise<Array<VIEW>>;
240
+ getPortion(key: PORTION | KeyValue): Promise<PORTION>;
242
241
  /** @inheritDoc */
243
- $toPortion(doc: ENT): Promise<PORTION>;
244
- /** @inheritDoc */
245
- getPortion(identifier: string): Promise<PORTION>;
246
- /** @inheritDoc */
247
- listPortions(identifiers: Array<string>, ignoreCheck?: boolean): Promise<Array<PORTION>>;
242
+ listPortions(keys: Array<PORTION | KeyValue>, ignoreCheck?: boolean): Promise<Array<PORTION>>;
248
243
  }
@@ -182,12 +182,12 @@ class DbRepo {
182
182
  return [undefined, undefined];
183
183
  }
184
184
  const obj = value;
185
- if (obj.id !== undefined) {
186
- return this._checkKey(obj.id);
187
- }
188
185
  if (obj.urn !== undefined) {
189
186
  return this._checkKey(obj.urn);
190
187
  }
188
+ if (obj.id !== undefined) {
189
+ return this._checkKey(obj.id);
190
+ }
191
191
  break;
192
192
  }
193
193
  return [undefined, undefined];
@@ -345,6 +345,10 @@ class DbRepo {
345
345
  }
346
346
  /** @inheritDoc */
347
347
  get urnLength() {
348
+ var _a, _b;
349
+ if (!this._props.urnLength) {
350
+ this._props.urnLength = (_b = (_a = this._props.urnPrefix) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
351
+ }
348
352
  return this._props.urnLength;
349
353
  }
350
354
  // endregion getter
@@ -443,17 +447,17 @@ class DbRepo {
443
447
  // endregion urn
444
448
  // region get
445
449
  /** @inheritDoc */
446
- get(k1, p1) {
450
+ get(keyLike, p1) {
447
451
  return __awaiter(this, void 0, void 0, function* () {
448
452
  const opt = this.buildOpt(p1, 'get');
449
- const [key, field] = this._checkKey(k1);
453
+ const [key, field] = this._checkKey(keyLike);
450
454
  switch (field) {
451
455
  case "urn":
452
456
  return this.getByPrimary(key, opt, true);
453
457
  case "id":
454
458
  return this.getBySecondary(key, opt, true);
455
459
  default:
456
- (0, type_1.assertMessage)('Invalid key', { field: 'key', value: k1, where: 'DbRepo', method: 'get', queryName: opt.name });
460
+ (0, type_1.assertMessage)('Invalid key', { field: 'key', value: keyLike, where: 'DbRepo', method: 'get', queryName: opt.name });
457
461
  }
458
462
  });
459
463
  }
@@ -524,17 +528,17 @@ class DbRepo {
524
528
  // endregion get
525
529
  // region exists
526
530
  /** @inheritDoc */
527
- exists(k1, p1) {
531
+ exists(keyLike, p1) {
528
532
  return __awaiter(this, void 0, void 0, function* () {
529
533
  const opt = this.buildOpt(p1, 'exists');
530
- const [key, field] = this._checkKey(k1);
534
+ const [key, field] = this._checkKey(keyLike);
531
535
  switch (field) {
532
536
  case "urn":
533
537
  return this.existsByPrimary(key, opt, true);
534
538
  case "id":
535
539
  return this.existsBySecondary(key, opt, true);
536
540
  default:
537
- (0, type_1.assertMessage)('Invalid key', { field: 'key', value: k1, where: 'DbRepo', method: 'exists', queryName: opt.name });
541
+ (0, type_1.assertMessage)('Invalid key', { field: 'key', value: keyLike, where: 'DbRepo', method: 'exists', queryName: opt.name });
538
542
  break;
539
543
  }
540
544
  });
@@ -592,13 +596,13 @@ class DbRepo {
592
596
  // endregion exists
593
597
  // region list
594
598
  /** @inheritDoc */
595
- list(keys, p1, ignoreCheck) {
599
+ list(keyLikes, p1, ignoreCheck) {
596
600
  return __awaiter(this, void 0, void 0, function* () {
597
601
  const opt = this.buildOpt(p1, 'list');
598
602
  if (!ignoreCheck) {
599
- (0, type_1.assertArray)(keys, { field: 'keys', where: 'DbRepo', method: 'list', queryName: opt.name });
603
+ (0, type_1.assertArray)(keyLikes, { field: 'keys', where: 'DbRepo', method: 'list', queryName: opt.name });
600
604
  }
601
- const result = this._checkKeys(keys);
605
+ const result = this._checkKeys(keyLikes);
602
606
  if (result.ordered.length < 1) {
603
607
  return [];
604
608
  }
@@ -944,17 +948,17 @@ class DbRepo {
944
948
  // endregion set
945
949
  // region remove
946
950
  /** @inheritDoc */
947
- remove(k1, p1) {
951
+ remove(keyLike, p1) {
948
952
  return __awaiter(this, void 0, void 0, function* () {
949
953
  const opt = this.buildOpt(p1, 'remove');
950
- const [key, field] = this._checkKey(k1);
954
+ const [key, field] = this._checkKey(keyLike);
951
955
  switch (field) {
952
956
  case "urn":
953
957
  return this.removeByPrimary(key, opt, true);
954
958
  case "id":
955
959
  return this.removeBySecondary(key, opt, true);
956
960
  default:
957
- (0, type_1.assertMessage)('Invalid key', { field: 'key', value: k1, where: 'DbRepo', method: 'remove', queryName: opt.name });
961
+ (0, type_1.assertMessage)('Invalid key', { field: 'key', value: keyLike, where: 'DbRepo', method: 'remove', queryName: opt.name });
958
962
  }
959
963
  });
960
964
  }
@@ -1007,17 +1011,17 @@ class DbRepo {
1007
1011
  // endregion remove
1008
1012
  // region trash
1009
1013
  /** @inheritDoc */
1010
- trash(k1, p1) {
1014
+ trash(keyLike, p1) {
1011
1015
  return __awaiter(this, void 0, void 0, function* () {
1012
1016
  const opt = this.buildOpt(p1, 'trash');
1013
- const [key, field] = this._checkKey(k1);
1017
+ const [key, field] = this._checkKey(keyLike);
1014
1018
  switch (field) {
1015
1019
  case "urn":
1016
1020
  return this.trashByPrimary(key, opt, true);
1017
1021
  case "id":
1018
1022
  return this.trashBySecondary(key, opt, true);
1019
1023
  default:
1020
- (0, type_1.assertMessage)('Invalid key', { field: 'key', value: k1, where: 'DbRepo', method: 'trash', queryName: opt.name });
1024
+ (0, type_1.assertMessage)('Invalid key', { field: 'key', value: keyLike, where: 'DbRepo', method: 'trash', queryName: opt.name });
1021
1025
  }
1022
1026
  });
1023
1027
  }
@@ -1088,14 +1092,17 @@ class DbRepo {
1088
1092
  return undefined;
1089
1093
  }
1090
1094
  switch (dim) {
1091
- case "portion":
1092
- return yield this.$toPortion(doc);
1093
1095
  case "view":
1094
- return yield this.$toView(doc);
1096
+ return doc;
1095
1097
  case "pair":
1096
- return yield this.$toPair(doc);
1097
- default:
1098
- return yield this.$toPortion(doc);
1098
+ return { id: doc.id, name: doc.name };
1099
+ default: // portion
1100
+ if (this.isIdSame) {
1101
+ return { id: doc.id };
1102
+ }
1103
+ else {
1104
+ return { id: doc.id, urn: doc.urn };
1105
+ }
1099
1106
  }
1100
1107
  });
1101
1108
  }
@@ -1123,15 +1130,6 @@ class DbRepo {
1123
1130
  // endregion dim
1124
1131
  // region pair
1125
1132
  /** @inheritDoc */
1126
- $toPair(doc) {
1127
- return __awaiter(this, void 0, void 0, function* () {
1128
- if (!doc) {
1129
- return undefined;
1130
- }
1131
- return { id: doc === null || doc === void 0 ? void 0 : doc.id, name: doc === null || doc === void 0 ? void 0 : doc.name };
1132
- });
1133
- }
1134
- /** @inheritDoc */
1135
1133
  getPair(key) {
1136
1134
  return __awaiter(this, void 0, void 0, function* () {
1137
1135
  return this.getDim(key, 'pair');
@@ -1145,44 +1143,30 @@ class DbRepo {
1145
1143
  }
1146
1144
  // endregion pair
1147
1145
  // region view
1148
- $toView(doc) {
1149
- return __awaiter(this, void 0, void 0, function* () {
1150
- return doc;
1151
- });
1152
- }
1153
1146
  /** @inheritDoc */
1154
- getView(identifier) {
1147
+ getView(key) {
1155
1148
  return __awaiter(this, void 0, void 0, function* () {
1156
- return this.getDim(identifier, 'view');
1149
+ return this.getDim(key, 'view');
1157
1150
  });
1158
1151
  }
1159
1152
  /** @inheritDoc */
1160
- listViews(identifiers, ignoreCheck) {
1153
+ listViews(keys, ignoreCheck) {
1161
1154
  return __awaiter(this, void 0, void 0, function* () {
1162
- return this.listDims(identifiers, 'view', ignoreCheck);
1155
+ return this.listDims(keys, 'view', ignoreCheck);
1163
1156
  });
1164
1157
  }
1165
1158
  // endregion view
1166
1159
  // region portion
1167
1160
  /** @inheritDoc */
1168
- $toPortion(doc) {
1169
- return __awaiter(this, void 0, void 0, function* () {
1170
- if (!doc) {
1171
- return undefined;
1172
- }
1173
- return { id: doc === null || doc === void 0 ? void 0 : doc.id };
1174
- });
1175
- }
1176
- /** @inheritDoc */
1177
- getPortion(identifier) {
1161
+ getPortion(key) {
1178
1162
  return __awaiter(this, void 0, void 0, function* () {
1179
- return this.getDim(identifier, 'portion');
1163
+ return this.getDim(key, 'portion');
1180
1164
  });
1181
1165
  }
1182
1166
  /** @inheritDoc */
1183
- listPortions(identifiers, ignoreCheck) {
1167
+ listPortions(keys, ignoreCheck) {
1184
1168
  return __awaiter(this, void 0, void 0, function* () {
1185
- return this.listDims(identifiers, 'portion', ignoreCheck);
1169
+ return this.listDims(keys, 'portion', ignoreCheck);
1186
1170
  });
1187
1171
  }
1188
1172
  }
@@ -1,5 +1,5 @@
1
- import type { DefDims, Entity, IdDocLike, Pair, Portion, UrnDocLike, UrnTuple, View } from "@samet-it/be-base-common";
2
- import { DbConnectionLike, UserFetcherLambda } from "../connection";
1
+ import type { DefDims, Entity, IdDocLike, Pair, Portion, UrnDef, UrnDocLike, UrnTuple, View } from "@samet-it/be-base-common";
2
+ import type { DbConnectionLike, UserFetcherLambda } from "../connection";
3
3
  import type { QueryAny, QueryRegular } from "@leyyo/query";
4
4
  import type { CacheChannelLike, CacheConnectionLike, CacheExecOpt } from "@samet-it/be-cache-common";
5
5
  import type { KeyValue, OmitError, Opt, StrKey } from "@leyyo/common";
@@ -255,12 +255,12 @@ export interface DbRepoLike<CONN extends DbConnectionLike, OPT extends DbExecOpt
255
255
  /**
256
256
  * Get document by key (primary or secondary)
257
257
  *
258
- * @param {KeyValue} key - primary or secondary key
258
+ * @param {Portion|KeyValue} key - primary or secondary key
259
259
  * @param {(opt?: OPT|string)?} opt - option or query name
260
260
  * @return {Promise<Entity?>} - document
261
261
  * @async
262
262
  * */
263
- get(key: KeyValue, opt?: OPT | string): Promise<ENT | undefined>;
263
+ get(key: PORTION | KeyValue, opt?: OPT | string): Promise<ENT | undefined>;
264
264
  /**
265
265
  * Get document by primary key
266
266
  *
@@ -304,12 +304,12 @@ export interface DbRepoLike<CONN extends DbConnectionLike, OPT extends DbExecOpt
304
304
  /**
305
305
  * Document exists by key (primary or secondary)
306
306
  *
307
- * @param {KeyValue} key - primary or secondary key
307
+ * @param {Portion|KeyValue} key - primary or secondary key
308
308
  * @param {(opt?: OPT|string)?} opt - option or query name
309
309
  * @return {Promise<boolean>} - exists or not
310
310
  * @async
311
311
  * */
312
- exists(key: KeyValue, opt?: OPT | string): Promise<boolean>;
312
+ exists(key: PORTION | KeyValue, opt?: OPT | string): Promise<boolean>;
313
313
  /**
314
314
  * Document exists by primary key
315
315
  *
@@ -353,13 +353,13 @@ export interface DbRepoLike<CONN extends DbConnectionLike, OPT extends DbExecOpt
353
353
  /**
354
354
  * List documents by keys (primary or secondary)
355
355
  *
356
- * @param {Array<KeyValue>} keys - primary or secondary keys
356
+ * @param {Array<Portion|KeyValue>} keys - primary or secondary keys
357
357
  * @param {(opt?: OPT|string)?} opt - option or query name
358
358
  * @param {boolean?} ignoreCheck - ignores to check input
359
359
  * @return {Promise<Array<Entity>>} - documents
360
360
  * @async
361
361
  * */
362
- list(keys: Array<KeyValue>, opt?: OPT | string, ignoreCheck?: boolean): Promise<Array<ENT>>;
362
+ list(keys: Array<PORTION | KeyValue>, opt?: OPT | string, ignoreCheck?: boolean): Promise<Array<ENT>>;
363
363
  /**
364
364
  * List documents by primary keys
365
365
  *
@@ -464,14 +464,14 @@ export interface DbRepoLike<CONN extends DbConnectionLike, OPT extends DbExecOpt
464
464
  /**
465
465
  * Update document by key (primary or secondary)
466
466
  *
467
- * @param {KeyValue} key - primary or secondary key
467
+ * @param {Portion|KeyValue} key - primary or secondary key
468
468
  * @param {Entity} doc - document
469
469
  * @param {(opt?: OPT|string)?} opt - option or query name
470
470
  * @param {boolean?} ignoreCheck - ignores to check input
471
471
  * @return {Promise<string>}
472
472
  * @async
473
473
  * */
474
- update(key: KeyValue, doc: Partial<ENT>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
474
+ update(key: PORTION | KeyValue, doc: Partial<ENT>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
475
475
  /**
476
476
  * Update document by primary key
477
477
  *
@@ -519,33 +519,33 @@ export interface DbRepoLike<CONN extends DbConnectionLike, OPT extends DbExecOpt
519
519
  /**
520
520
  * Set document with partial data by key (primary or secondary)
521
521
  *
522
- * @param {KeyValue} key - primary or secondary key
522
+ * @param {Portion|KeyValue} key - primary or secondary key
523
523
  * @param {Partial<Entity>} doc - partial entity will be set
524
524
  * @param {(opt?: OPT|string)?} opt - option or query name
525
525
  * @param {boolean?} ignoreCheck - ignores to check input
526
526
  * @return {Promise<string>}
527
527
  * @async
528
528
  * */
529
- set(key: KeyValue, doc: Partial<ENT>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
529
+ set(key: PORTION | KeyValue, doc: Partial<ENT>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
530
530
  /**
531
531
  * Unset document for given fields
532
532
  *
533
- * @param {KeyValue} key - primary or secondary key
533
+ * @param {Portion|KeyValue} key - primary or secondary key
534
534
  * @param {Array<string>} fields - fields will be unset
535
535
  * @param {(opt?: OPT|string)?} opt - option or query name
536
536
  * @param {boolean?} ignoreCheck - ignores to check input
537
537
  * @return {Promise<string>}
538
538
  * @async
539
539
  * */
540
- unset(key: KeyValue, fields: Array<keyof ENT | KEYS | string>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
540
+ unset(key: PORTION | KeyValue, fields: Array<keyof ENT | KEYS | string>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
541
541
  /**
542
542
  * Remove document (hard delete) by key (primary or secondary)
543
543
  *
544
- * @param {KeyValue} key - primary or secondary key
544
+ * @param {Portion|KeyValue} key - primary or secondary key
545
545
  * @param {(opt?: OPT|string)?} opt - option or query name
546
546
  * @async
547
547
  * */
548
- remove(key: KeyValue, opt?: OPT | string): Promise<string>;
548
+ remove(key: PORTION | KeyValue, opt?: OPT | string): Promise<string>;
549
549
  /**
550
550
  * Remove document by primary key (hard delete)
551
551
  *
@@ -585,11 +585,11 @@ export interface DbRepoLike<CONN extends DbConnectionLike, OPT extends DbExecOpt
585
585
  /**
586
586
  * Trash document (soft delete) by key (primary or secondary)
587
587
  *
588
- * @param {KeyValue} key - primary or secondary key
588
+ * @param {Portion|KeyValue} key - primary or secondary key
589
589
  * @param {(opt?: OPT|string)?} opt - option or query name
590
590
  * @async
591
591
  * */
592
- trash(key: KeyValue, opt?: OPT | string): Promise<string>;
592
+ trash(key: PORTION | KeyValue, opt?: OPT | string): Promise<string>;
593
593
  /**
594
594
  * Trash document by primary key (soft delete)
595
595
  *
@@ -644,64 +644,48 @@ export interface DbRepoLike<CONN extends DbConnectionLike, OPT extends DbExecOpt
644
644
  * Generics
645
645
  * - 0-`R`: dim interface {@link IdDocLike}
646
646
  *
647
- * @param {KeyValue} key - primary or secondary key
647
+ * @param {Portion|KeyValue} key - primary or secondary key
648
648
  * @param {string?} dim - dimension, default: `def`
649
649
  * @return {Promise<IdDocLike>} - dim object
650
650
  * @async
651
651
  * */
652
- getDim<R extends IdDocLike<ID>>(key: KeyValue, dim?: DIMS): Promise<R>;
652
+ getDim<R extends IdDocLike<ID>>(key: PORTION | KeyValue, dim?: DIMS): Promise<R>;
653
653
  /**
654
654
  * List dims by keys (primary or secondary)
655
655
  *
656
656
  * Generics
657
657
  * - 0-`R`: dim interface {@link IdDocLike}
658
658
  *
659
- * @param {Array<string>} keys - primary or secondary keys
659
+ * @param {Array<Portion|KeyValue>} keys - primary or secondary keys
660
660
  * @param {string?} dim - dimension, default: `def`
661
661
  * @param {boolean?} ignoreCheck - ignores to check input
662
662
  * @return {Promise<Array<IdDocLike>>} - dim objects
663
663
  * */
664
- listDims<R extends IdDocLike<ID>>(keys: Array<KeyValue>, dim?: DIMS, ignoreCheck?: boolean): Promise<Array<R>>;
665
- /**
666
- * Set pair by document
667
- *
668
- * @param {Entity} doc - document
669
- * @return {Promise<Pair>} - pair object
670
- * @async
671
- * */
672
- $toPair(doc: ENT): Promise<PAIR>;
664
+ listDims<R extends IdDocLike<ID>>(keys: Array<PORTION | KeyValue>, dim?: DIMS, ignoreCheck?: boolean): Promise<Array<R>>;
673
665
  /**
674
666
  * Get pair by key (primary or secondary)
675
667
  *
676
- * @param {KeyValue} key - primary or secondary key
668
+ * @param {Portion|KeyValue} key - primary or secondary key
677
669
  * @return {Promise<Pair>} - pair object
678
670
  * @async
679
671
  * */
680
- getPair(key: KeyValue): Promise<PAIR>;
672
+ getPair(key: PORTION | KeyValue): Promise<PAIR>;
681
673
  /**
682
674
  * List pairs by keys (primary or secondary)
683
675
  *
684
- * @param {Array<KeyValue>} keys - primary or secondary keys
676
+ * @param {Array<Portion|KeyValue>} keys - primary or secondary keys
685
677
  * @param {boolean?} ignoreCheck - ignores to check input
686
678
  * @return {Promise<Array<Pair>>} - pair objects
687
679
  * */
688
- listPairs(keys: Array<KeyValue>, ignoreCheck?: boolean): Promise<Array<PAIR>>;
689
- /**
690
- * Set view by document
691
- *
692
- * @param {Entity} doc - document
693
- * @return {Promise<View>} - view object
694
- * @async
695
- * */
696
- $toView(doc: ENT): Promise<VIEW>;
680
+ listPairs(keys: Array<PORTION | KeyValue>, ignoreCheck?: boolean): Promise<Array<PAIR>>;
697
681
  /**
698
682
  * Get view by key (primary or secondary)
699
683
  *
700
- * @param {KeyValue} key - primary or secondary key
684
+ * @param {Portion|KeyValue} key - primary or secondary key
701
685
  * @return {Promise<View>} - view object
702
686
  * @async
703
687
  * */
704
- getView(key: KeyValue): Promise<VIEW>;
688
+ getView(key: PORTION | KeyValue): Promise<VIEW>;
705
689
  /**
706
690
  * List views by keys (primary or secondary)
707
691
  *
@@ -710,30 +694,22 @@ export interface DbRepoLike<CONN extends DbConnectionLike, OPT extends DbExecOpt
710
694
  * @return {Promise<Array<View>>} - view objects
711
695
  * */
712
696
  listViews(keys: Array<KeyValue>, ignoreCheck?: boolean): Promise<Array<VIEW>>;
713
- /**
714
- * Set portion by document
715
- *
716
- * @param {Entity} doc - document
717
- * @return {Promise<Portion>} - portion object
718
- * @async
719
- * */
720
- $toPortion(doc: ENT): Promise<PORTION>;
721
697
  /**
722
698
  * Get portion by key (primary or secondary)
723
699
  *
724
- * @param {KeyValue} key - primary or secondary key
700
+ * @param {Portion|KeyValue} key - primary or secondary key
725
701
  * @return {Promise<Portion>} - portion object
726
702
  * @async
727
703
  * */
728
- getPortion(key: KeyValue): Promise<PORTION>;
704
+ getPortion(key: PORTION | KeyValue): Promise<PORTION>;
729
705
  /**
730
706
  * List portions by key (primary or secondary)
731
707
  *
732
- * @param {Array<KeyValue>} keys - primary or secondary keys
708
+ * @param {Array<Portion|KeyValue>} keys - primary or secondary keys
733
709
  * @param {boolean?} ignoreCheck - ignores to check input
734
710
  * @return {Promise<Array<Portion>>} - portion objects
735
711
  * */
736
- listPortions(keys: Array<KeyValue>, ignoreCheck?: boolean): Promise<Array<PORTION>>;
712
+ listPortions(keys: Array<PORTION | KeyValue>, ignoreCheck?: boolean): Promise<Array<PORTION>>;
737
713
  }
738
714
  /**
739
715
  * DB repository option
@@ -1036,14 +1012,17 @@ export type DbRepoToUrnTuple<URN extends UrnDocLike = UrnDocLike> = (urnRec: URN
1036
1012
  export type DbRepoToDim<R, ENT extends Entity<ID>, ID extends KeyValue, DIMS extends DefDims = DefDims> = (doc: ENT, dim: DIMS | undefined) => Promise<R>;
1037
1013
  /**
1038
1014
  * Default model which contains keys
1015
+ *
1016
+ * Generics:
1017
+ * - 0-`ID`: id type {@link KeyValue}
1039
1018
  * */
1040
- export interface DbIdLike {
1019
+ export interface DbIdLike<ID extends KeyValue = KeyValue> {
1041
1020
  /**
1042
1021
  * Secondary key for an entity
1043
1022
  *
1044
1023
  * @type {KeyValue}
1045
1024
  */
1046
- id?: KeyValue;
1025
+ id?: ID;
1047
1026
  /**
1048
1027
  * Primary key for an entity
1049
1028
  *
@@ -1106,6 +1085,10 @@ export interface DbExecOpt extends Opt {
1106
1085
  }
1107
1086
  /**
1108
1087
  * DB query result as a row
1088
+ *
1089
+ * Generics:
1090
+ * - 0-`E`: result model, it will be row type
1091
+ * - 1-`META`: query result metadata {@link DbMeta}
1109
1092
  * */
1110
1093
  export interface DbQueryResultOne<E = any, META extends DbMeta = DbMeta> extends DbQueryResult<META> {
1111
1094
  /**
@@ -1115,6 +1098,10 @@ export interface DbQueryResultOne<E = any, META extends DbMeta = DbMeta> extends
1115
1098
  }
1116
1099
  /**
1117
1100
  * DB query result as rows
1101
+ *
1102
+ * Generics:
1103
+ * - 0-`E`: result model, it will be rows item type, `rows: E[]`
1104
+ * - 1-`META`: query result metadata {@link DbMeta}
1118
1105
  * */
1119
1106
  export interface DbQueryResultMore<E = any, META extends DbMeta = DbMeta> extends DbQueryResult<META> {
1120
1107
  /**
@@ -1125,7 +1112,8 @@ export interface DbQueryResultMore<E = any, META extends DbMeta = DbMeta> extend
1125
1112
  /**
1126
1113
  * DB query result
1127
1114
  *
1128
- * Generics
1115
+ * Generics:
1116
+ * - 0-`META`: query result metadata {@link DbMeta}
1129
1117
  * */
1130
1118
  export interface DbQueryResult<META> {
1131
1119
  /**
@@ -1141,3 +1129,31 @@ export interface DbQueryResult<META> {
1141
1129
  */
1142
1130
  error?: OmitError;
1143
1131
  }
1132
+ /**
1133
+ * Couchbase direct repository (collection) option
1134
+ *
1135
+ * Generics:
1136
+ * - 0-`ENT`: entity {@link Entity}
1137
+ * - 1-`ID`: id type {@link KeyValue}
1138
+ * - 2-`URN`: urn interface {@link UrnDocLike}
1139
+ * - 3-`DIMS`: dimensions for presentation layer {@link DefDims}
1140
+ * - 4-`R`: ??
1141
+ * */
1142
+ export interface DbRepoDirectOpt<ENT extends Entity<ID>, ID extends KeyValue = KeyValue, URN extends UrnDocLike = UrnDef<ID>, DIMS extends DefDims = DefDims, R = unknown> extends DbRepoOpt<ENT, ID> {
1143
+ /**
1144
+ * Name of logger class
1145
+ * */
1146
+ name?: string;
1147
+ /**
1148
+ * Overridable method to easy use
1149
+ * */
1150
+ $toUrnTuple?: DbRepoToUrnTuple<URN>;
1151
+ /**
1152
+ * Overridable method to easy use
1153
+ * */
1154
+ $toDim?: DbRepoToDim<R, ENT, ID, DIMS>;
1155
+ /**
1156
+ * Indexed fields
1157
+ * */
1158
+ $indexedFields?: Array<keyof ENT | string>;
1159
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samet-it/be-db-common",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "description": "Backend DB Common",
5
5
  "repository": {
6
6
  "type": "git",