@samet-it/be-couchbase-common 1.1.4 → 1.1.7

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.
@@ -1,13 +1,19 @@
1
1
  import { CbConnection } from "./cb.connection";
2
+ import { UrnDef } from "@samet-it/be-base-common";
2
3
  import type { DefDims, Entity, UrnDocLike, Pair, Portion, View } from "@samet-it/be-base-common";
3
4
  import { type CbRepoDirectOpt, type CbRepoLike } from "../repo";
4
5
  import type { CbDirectConnectionLike, CbDirectConnOpt } from "./index.types";
5
- import type { KeyValue } from "@leyyo/common";
6
+ import type { KeyValue, StrKey } from "@leyyo/common";
6
7
  /**
7
8
  * Couchbase connection direct class
8
9
  * */
9
10
  export declare class CbDirectConnection extends CbConnection implements CbDirectConnectionLike {
11
+ /**
12
+ * Constructor
13
+ *
14
+ * @param {CbDirectConnOpt} opt - options
15
+ * */
10
16
  constructor(opt?: CbDirectConnOpt);
11
17
  /** @inheritDoc */
12
- newRepo<ID extends KeyValue, ENTITY extends Entity<ID>, URN extends UrnDocLike, KEYS extends string = string, DIMS extends DefDims = DefDims, PAIR extends Pair<ID> = Pair<ID>, VIEW extends View<ID> = View<ID>, PORTION extends Portion<ID> = Portion<ID>, R = unknown>(opt: CbRepoDirectOpt<ID, ENTITY, URN, DIMS, R>): CbRepoLike<ID, ENTITY, URN, KEYS, DIMS, PAIR, VIEW, PORTION>;
18
+ newRepo<ENT extends Entity<ID>, ID extends KeyValue = KeyValue, URN extends UrnDocLike = UrnDef<ID>, VIEW extends View<ID> = ENT, PAIR extends Pair<ID> = Pair<ID>, PORTION extends Portion<ID> = Portion<ID>, KEYS extends string = StrKey<ENT>, DIMS extends DefDims = DefDims, R = unknown>(opt: CbRepoDirectOpt<ENT, ID, URN, DIMS, R>): CbRepoLike<ENT, ID, URN, VIEW, PAIR, PORTION, KEYS, DIMS>;
13
19
  }
@@ -9,6 +9,11 @@ const repo_1 = require("../repo");
9
9
  * Couchbase connection direct class
10
10
  * */
11
11
  class CbDirectConnection extends cb_connection_1.CbConnection {
12
+ /**
13
+ * Constructor
14
+ *
15
+ * @param {CbDirectConnOpt} opt - options
16
+ * */
12
17
  constructor(opt) {
13
18
  super(opt);
14
19
  this.logger = be_base_common_1.logger.of(`CbConnection${(opt === null || opt === void 0 ? void 0 : opt.name) ? '#' + (opt === null || opt === void 0 ? void 0 : opt.name) : ''}`);
@@ -9,6 +9,11 @@ import type { DbQueryResultMore, DbQueryResultOne } from "@samet-it/be-db-common
9
9
  export declare abstract class CbConnection extends DbConnection<CbRepoLink, QueryMetaData, CbExecOpt> implements CbConnectionLike {
10
10
  /** {@inheritDoc} */
11
11
  protected _props: CbConnProps;
12
+ /**
13
+ * Constructor
14
+ *
15
+ * @param {CbConnOpt} opt - options
16
+ * */
12
17
  protected constructor(opt?: CbConnOpt);
13
18
  /**
14
19
  * Read configuration by variant
@@ -54,6 +54,11 @@ const type_1 = require("@leyyo/type");
54
54
  * */
55
55
  class CbConnection extends be_db_common_1.DbConnection {
56
56
  // endregion protected-property
57
+ /**
58
+ * Constructor
59
+ *
60
+ * @param {CbConnOpt} opt - options
61
+ * */
57
62
  constructor(opt) {
58
63
  super(opt);
59
64
  filter_1.cbFilterUtil.$set(this);
@@ -1,8 +1,8 @@
1
1
  import type { Cluster, QueryMetaData, QueryOptions, QueryResult, Scope } from "couchbase";
2
- import type { IgnoreFieldsByType, KeyValue, ReplaceType } from "@leyyo/common";
2
+ import type { IgnoreFieldsByType, KeyValue, ReplaceType, StrKey } from "@leyyo/common";
3
3
  import type { CbRepoDirectOpt, CbRepoLike } from "../repo";
4
4
  import type { DbConnectionLike, DbConnOpt, DbConnProps, DbExecOpt, DbRepoLink } from "@samet-it/be-db-common";
5
- import type { DefDims, Entity, UrnDocLike, Pair, Portion, View } from "@samet-it/be-base-common";
5
+ import type { DefDims, Entity, UrnDocLike, Pair, Portion, View, UrnDef } from "@samet-it/be-base-common";
6
6
  /**
7
7
  * Couchbase connection interface
8
8
  * */
@@ -78,10 +78,21 @@ export interface CbDirectConnectionLike extends CbConnectionLike {
78
78
  /**
79
79
  * Creates new direct repo without dependency injection
80
80
  *
81
+ * Generics:
82
+ * - 0-`ENT`: entity {@link Entity}
83
+ * - 1-`ID`: id type {@link KeyValue}
84
+ * - 2-`URN`: urn interface {@link UrnDocLike}
85
+ * - 3-`VIEW`: view interface for presentation layer {@link View}
86
+ * - 4-`PAIR`: pair interface for presentation layer {@link Pair}
87
+ * - 5-`PORTION`: portion interface for presentation layer {@link Portion}
88
+ * - 6-`KEYS`: keys to autocomplete, def: keys of {@link Entity}
89
+ * - 7-`DIMS`: dimensions for presentation layer {@link DefDims}
90
+ * - 8-`R`: ???
91
+ *
81
92
  * @param {CbRepoDirectOpt} opt - options
82
93
  * @return {CbRepoLike} - created repository
83
94
  * */
84
- newRepo<ID extends KeyValue, ENTITY extends Entity<ID>, URN extends UrnDocLike, KEYS extends string = string, DIMS extends DefDims = DefDims, PAIR extends Pair<ID> = Pair<ID>, VIEW extends View<ID> = View<ID>, PORTION extends Portion<ID> = Portion<ID>, R = unknown>(opt: CbRepoDirectOpt<ID, ENTITY, URN, DIMS, R>): CbRepoLike<ID, ENTITY, URN, KEYS, DIMS, PAIR, VIEW, PORTION>;
95
+ newRepo<ENT extends Entity<ID>, ID extends KeyValue = KeyValue, URN extends UrnDocLike = UrnDef, VIEW extends View<ID> = ENT, PAIR extends Pair<ID> = Pair<ID>, PORTION extends Portion<ID> = Portion<ID>, KEYS extends string = StrKey<ENT>, DIMS extends DefDims = DefDims, R = unknown>(opt: CbRepoDirectOpt<ENT, ID, URN, DIMS, R>): CbRepoLike<ENT, ID, URN, VIEW, PAIR, PORTION, KEYS, DIMS>;
85
96
  }
86
97
  export type CbIgnoreDate<T> = CbReplaceType<T, Date, string>;
87
98
  export type CbIgnoreDateKeys<T> = CbIgnoreFields<T, Date>;
@@ -1,11 +1,27 @@
1
1
  import { CbRepo } from "./cb.repo";
2
- import type { DefDims, Entity, Pair, Portion, UrnDocLike, View } from "@samet-it/be-base-common";
2
+ import type { DefDims, Entity, Pair, Portion, UrnDef, UrnDocLike, View } from "@samet-it/be-base-common";
3
3
  import type { CbConnectionLike } from "../connection";
4
4
  import type { CbRepoDirectOpt } from "./index.types";
5
- import type { KeyValue } from "@leyyo/common";
5
+ import type { KeyValue, StrKey } from "@leyyo/common";
6
6
  /**
7
7
  * Couchbase repository direct class
8
+ *
9
+ * Generics:
10
+ * - 0-`ENT`: entity {@link Entity}
11
+ * - 1-`ID`: id type {@link KeyValue}
12
+ * - 2-`URN`: urn interface {@link UrnDocLike}
13
+ * - 3-`VIEW`: view interface for presentation layer {@link View}
14
+ * - 4-`PAIR`: pair interface for presentation layer {@link Pair}
15
+ * - 5-`PORTION`: portion interface for presentation layer {@link Portion}
16
+ * - 6-`KEYS`: keys to autocomplete, def: keys of {@link Entity}
17
+ * - 7-`DIMS`: dimensions for presentation layer {@link DefDims}
8
18
  * */
9
- export declare class CbDirectRepo<ID extends KeyValue, ENTITY extends Entity<ID>, URN extends UrnDocLike, KEYS extends string = string, DIMS extends DefDims = DefDims, PAIR extends Pair<ID> = Pair<ID>, VIEW extends View<ID> = View<ID>, PORTION extends Portion<ID> = Portion<ID>> extends CbRepo<ID, ENTITY, URN, KEYS, DIMS, PAIR, VIEW, PORTION> {
10
- constructor(conn: CbConnectionLike, opt: CbRepoDirectOpt<ID, ENTITY, URN, DIMS>);
19
+ export declare class CbDirectRepo<ENT extends Entity<ID>, ID extends KeyValue = KeyValue, URN extends UrnDocLike = UrnDef<ID>, VIEW extends View<ID> = ENT, PAIR extends Pair<ID> = Pair<ID>, PORTION extends Portion<ID> = Portion<ID>, KEYS extends string = StrKey<ENT>, DIMS extends DefDims = DefDims> extends CbRepo<ENT, ID, URN, VIEW, PAIR, PORTION, KEYS, DIMS> {
20
+ /**
21
+ * Constructor
22
+ *
23
+ * @param {CbConnectionLike} conn - couchbase connection
24
+ * @param {CbRepoDirectOpt} opt - options
25
+ * */
26
+ constructor(conn: CbConnectionLike, opt: CbRepoDirectOpt<ENT, ID, URN, DIMS>);
11
27
  }
@@ -14,8 +14,24 @@ const cb_repo_1 = require("./cb.repo");
14
14
  const be_base_common_1 = require("@samet-it/be-base-common");
15
15
  /**
16
16
  * Couchbase repository direct class
17
+ *
18
+ * Generics:
19
+ * - 0-`ENT`: entity {@link Entity}
20
+ * - 1-`ID`: id type {@link KeyValue}
21
+ * - 2-`URN`: urn interface {@link UrnDocLike}
22
+ * - 3-`VIEW`: view interface for presentation layer {@link View}
23
+ * - 4-`PAIR`: pair interface for presentation layer {@link Pair}
24
+ * - 5-`PORTION`: portion interface for presentation layer {@link Portion}
25
+ * - 6-`KEYS`: keys to autocomplete, def: keys of {@link Entity}
26
+ * - 7-`DIMS`: dimensions for presentation layer {@link DefDims}
17
27
  * */
18
28
  class CbDirectRepo extends cb_repo_1.CbRepo {
29
+ /**
30
+ * Constructor
31
+ *
32
+ * @param {CbConnectionLike} conn - couchbase connection
33
+ * @param {CbRepoDirectOpt} opt - options
34
+ * */
19
35
  constructor(conn, opt) {
20
36
  super(conn, opt);
21
37
  if (opt) {
@@ -1,18 +1,34 @@
1
1
  import type { CbConnectionLike, CbExecOpt } from "../connection";
2
2
  import type { KeyValue } from "@leyyo/common";
3
3
  import type { StrKey } from "@leyyo/common";
4
- import type { CbExistsOpt, CbGetOpt, CbInsertOpt, CbReplaceOpt, CbRepoProps, CbRepoLike, CbRepoOpt } from "./index.types";
4
+ import type { CbExistsOpt, CbGetOpt, CbInsertOpt, CbReplaceOpt, CbRepoProps, CbRepoLike, CbRepoOpt, CbUpsertOpt } from "./index.types";
5
5
  import { DbRepo } from "@samet-it/be-db-common";
6
- import type { DefDims, Entity, Pair, Portion, UrnDocLike, View } from "@samet-it/be-base-common";
6
+ import type { DefDims, Entity, Pair, Portion, UrnDef, UrnDocLike, View } from "@samet-it/be-base-common";
7
7
  import type { QueryRegular } from "@leyyo/query";
8
8
  /**
9
9
  * Couchbase repository abstract class
10
+ *
11
+ * Generics:
12
+ * - 0-`ENT`: entity {@link Entity}
13
+ * - 1-`ID`: id type {@link KeyValue}
14
+ * - 2-`URN`: urn interface {@link UrnDocLike}
15
+ * - 3-`VIEW`: view interface for presentation layer {@link View}
16
+ * - 4-`PAIR`: pair interface for presentation layer {@link Pair}
17
+ * - 5-`PORTION`: portion interface for presentation layer {@link Portion}
18
+ * - 6-`KEYS`: keys to autocomplete, def: keys of {@link Entity}
19
+ * - 7-`DIMS`: dimensions for presentation layer {@link DefDims}
10
20
  * */
11
- export declare abstract class CbRepo<ID extends KeyValue, ENTITY extends Entity<ID>, URN extends UrnDocLike, KEYS extends string = string, DIMS extends DefDims = DefDims, PAIR extends Pair<ID> = Pair<ID>, VIEW extends View<ID> = View<ID>, PORTION extends Portion<ID> = Portion<ID>> extends DbRepo<CbConnectionLike, CbExecOpt, ID, ENTITY, URN, KEYS, DIMS, PAIR, VIEW, PORTION> implements CbRepoLike<ID, ENTITY, URN, KEYS, DIMS, PAIR, VIEW, PORTION> {
21
+ export declare abstract class CbRepo<ENT extends Entity<ID>, ID extends KeyValue = KeyValue, URN extends UrnDocLike = UrnDef<ID>, VIEW extends View<ID> = ENT, PAIR extends Pair<ID> = Pair<ID>, PORTION extends Portion<ID> = Portion<ID>, KEYS extends string = StrKey<ENT>, DIMS extends DefDims = DefDims> extends DbRepo<CbConnectionLike, CbExecOpt, ENT, ID, URN, VIEW, PAIR, PORTION, KEYS, DIMS> implements CbRepoLike<ENT, ID, URN, VIEW, PAIR, PORTION, KEYS, DIMS> {
12
22
  private static _specs;
13
23
  /** @inheritDoc */
14
- protected _props: CbRepoProps<ID, ENTITY>;
15
- protected constructor(conn: CbConnectionLike, opt?: CbRepoOpt<ID, ENTITY>);
24
+ protected _props: CbRepoProps<ENT, ID>;
25
+ /**
26
+ * Constructor
27
+ *
28
+ * @param {CbConnectionLike} conn - couchbase connection
29
+ * @param {CbRepoOpt} opt - options
30
+ * */
31
+ protected constructor(conn: CbConnectionLike, opt?: CbRepoOpt<ENT, ID>);
16
32
  /**
17
33
  * Check property name
18
34
  *
@@ -26,20 +42,20 @@ export declare abstract class CbRepo<ID extends KeyValue, ENTITY extends Entity<
26
42
  * @param {string} field - field name
27
43
  * @param {string?} name - index name
28
44
  * */
29
- protected _createIndex(field: keyof ENTITY | string, name?: string): Promise<void>;
45
+ protected _createIndex(field: keyof ENT | string, name?: string): Promise<void>;
30
46
  /**
31
47
  * Execute the creation of index for complex fields
32
48
  *
33
49
  * @param {Array<string>} fields - field names
34
50
  * @param {string} name - index name
35
51
  * */
36
- protected _createIndex(fields: Array<keyof ENTITY | string>, name: string): Promise<void>;
52
+ protected _createIndex(fields: Array<keyof ENT | string>, name: string): Promise<void>;
37
53
  /**
38
54
  * Execute the creation of indexes with keys
39
55
  *
40
56
  * @param {...Array<string>} keys - keys of model
41
57
  * */
42
- protected _createMoreIndices(...keys: Array<keyof ENTITY>): Promise<void>;
58
+ protected _createMoreIndices(...keys: Array<keyof ENT>): Promise<void>;
43
59
  /**
44
60
  * Execute the creation of primary key
45
61
  * */
@@ -65,29 +81,31 @@ export declare abstract class CbRepo<ID extends KeyValue, ENTITY extends Entity<
65
81
  * */
66
82
  protected $createIndices(): Promise<void>;
67
83
  /** @inheritDoc */
68
- get props(): Readonly<CbRepoProps<ID, ENTITY>>;
84
+ get props(): Readonly<CbRepoProps<ENT, ID>>;
69
85
  /** @inheritDoc */
70
- $getByPrimary(key: string, p1?: CbGetOpt | string, ignoreCheck?: boolean): Promise<ENTITY | undefined>;
86
+ $getByPrimary(key: string, p1?: CbGetOpt | string, ignoreCheck?: boolean): Promise<ENT | undefined>;
71
87
  /** @inheritDoc */
72
- $getBySecondary(key: KeyValue, p1?: CbGetOpt | string, ignoreCheck?: boolean): Promise<ENTITY | undefined>;
88
+ $getBySecondary(key: KeyValue, p1?: CbGetOpt | string, ignoreCheck?: boolean): Promise<ENT | undefined>;
73
89
  /** @inheritDoc */
74
90
  $existsByPrimary(key: string, p1?: CbExistsOpt | string, ignoreCheck?: boolean): Promise<boolean>;
75
91
  /** @inheritDoc */
76
92
  $existsBySecondary(key: KeyValue, p1?: CbExistsOpt | string, ignoreCheck?: boolean): Promise<boolean>;
77
93
  /** @inheritDoc */
78
- $listByPrimary(keys: string[], p1?: CbExecOpt | string, ignoreCheck?: boolean): Promise<Array<ENTITY>>;
94
+ $listByPrimary(keys: string[], p1?: CbExecOpt | string, ignoreCheck?: boolean): Promise<Array<ENT>>;
95
+ /** @inheritDoc */
96
+ $listBySecondary(keys: KeyValue[], p1?: CbExecOpt | string, ignoreCheck?: boolean): Promise<Array<ENT>>;
79
97
  /** @inheritDoc */
80
- $listBySecondary(keys: KeyValue[], p1?: CbExecOpt | string, ignoreCheck?: boolean): Promise<Array<ENTITY>>;
98
+ $filter<R = ENT, K2 extends string = StrKey<R>>(query: QueryRegular<K2 | KEYS | StrKey<ENT>>, p1?: string | CbExecOpt): Promise<Array<R>>;
81
99
  /** @inheritDoc */
82
- $filter<R = ENTITY, K2 extends string = StrKey<R>>(query: QueryRegular<K2 | KEYS | StrKey<ENTITY>>, p1?: string | CbExecOpt): Promise<Array<R>>;
100
+ $insert(doc: ENT, p1?: CbInsertOpt | string, ignoreCheck?: boolean): Promise<string>;
83
101
  /** @inheritDoc */
84
- $insert(doc: ENTITY, p1?: CbInsertOpt | string, ignoreCheck?: boolean): Promise<string>;
102
+ $replace(doc: ENT, p1?: CbReplaceOpt | string, ignoreCheck?: boolean): Promise<string>;
85
103
  /** @inheritDoc */
86
- $replace(doc: ENTITY, p1?: CbReplaceOpt | string, ignoreCheck?: boolean): Promise<string>;
104
+ $upsert(doc: ENT, p1?: CbUpsertOpt | string, ignoreCheck?: boolean): Promise<string>;
87
105
  /** @inheritDoc */
88
- $updateByPrimary(key: string, doc: Partial<ENTITY>, p1?: CbExecOpt | string, ignoreCheck?: boolean): Promise<string>;
106
+ $updateByPrimary(key: string, doc: Partial<ENT>, p1?: CbExecOpt | string, ignoreCheck?: boolean): Promise<string>;
89
107
  /** @inheritDoc */
90
- $updateBySecondary(key: KeyValue, doc: Partial<ENTITY>, p1?: CbExecOpt | string, ignoreCheck?: boolean): Promise<string>;
108
+ $updateBySecondary(key: KeyValue, doc: Partial<ENT>, p1?: CbExecOpt | string, ignoreCheck?: boolean): Promise<string>;
91
109
  /** @inheritDoc */
92
110
  $removeByPrimary(key: string, p1?: CbExecOpt | string, ignoreCheck?: boolean): Promise<string>;
93
111
  /** @inheritDoc */
@@ -20,9 +20,25 @@ let F_ID;
20
20
  let F_TRASH_ID;
21
21
  /**
22
22
  * Couchbase repository abstract class
23
+ *
24
+ * Generics:
25
+ * - 0-`ENT`: entity {@link Entity}
26
+ * - 1-`ID`: id type {@link KeyValue}
27
+ * - 2-`URN`: urn interface {@link UrnDocLike}
28
+ * - 3-`VIEW`: view interface for presentation layer {@link View}
29
+ * - 4-`PAIR`: pair interface for presentation layer {@link Pair}
30
+ * - 5-`PORTION`: portion interface for presentation layer {@link Portion}
31
+ * - 6-`KEYS`: keys to autocomplete, def: keys of {@link Entity}
32
+ * - 7-`DIMS`: dimensions for presentation layer {@link DefDims}
23
33
  * */
24
34
  class CbRepo extends be_db_common_1.DbRepo {
25
35
  // endregion protected-property
36
+ /**
37
+ * Constructor
38
+ *
39
+ * @param {CbConnectionLike} conn - couchbase connection
40
+ * @param {CbRepoOpt} opt - options
41
+ * */
26
42
  constructor(conn, opt) {
27
43
  var _a, _b, _c;
28
44
  super(conn, opt);
@@ -35,13 +51,13 @@ class CbRepo extends be_db_common_1.DbRepo {
35
51
  props.scopeName = (_b = props.scopeName) !== null && _b !== void 0 ? _b : conn.props.scopeName;
36
52
  props.createIndices = (_c = props.createIndices) !== null && _c !== void 0 ? _c : conn.props.createIndices;
37
53
  if (!props.bucketName) {
38
- throw new be_db_common_1.DbInvalidValueError('Bucket', typeof props.bucketName, 'CbRepo', 'constructor');
54
+ throw new be_db_common_1.DbInvalidValueError('Bucket', { where: 'CbRepo', method: 'constructor', type: typeof props.bucketName });
39
55
  }
40
56
  if (!props.scopeName) {
41
- throw new be_db_common_1.DbInvalidValueError('Scope', typeof props.scopeName, 'CbRepo', 'constructor');
57
+ throw new be_db_common_1.DbInvalidValueError('Scope', { where: 'CbRepo', method: 'constructor', type: typeof props.scopeName });
42
58
  }
43
59
  if (!props.collectionName) {
44
- throw new be_db_common_1.DbInvalidValueError('Collection', typeof props.collectionName, 'CbRepo', 'constructor');
60
+ throw new be_db_common_1.DbInvalidValueError('Collection', { where: 'CbRepo', method: 'constructor', type: typeof props.collectionName });
45
61
  }
46
62
  if (!F_URN) {
47
63
  F_URN = props.conn.f('_urn');
@@ -234,11 +250,11 @@ class CbRepo extends be_db_common_1.DbRepo {
234
250
  /** @inheritDoc */
235
251
  $getByPrimary(key, p1, ignoreCheck) {
236
252
  return __awaiter(this, void 0, void 0, function* () {
253
+ const { conn, useSoftDelete, collection, full } = this._props;
254
+ const opt = conn.buildOpt(p1, '$getById');
237
255
  if (!ignoreCheck) {
238
256
  (0, type_2.assertText)(key, { field: 'id', where: 'CbRepo', method: '$getByPrimary' });
239
257
  }
240
- const { conn, useSoftDelete, collection, full } = this._props;
241
- const opt = conn.buildOpt(p1, '$getById');
242
258
  if (!useSoftDelete) {
243
259
  if (!Array.isArray(opt.ignoredErrors)) {
244
260
  opt.ignoredErrors = [];
@@ -402,18 +418,22 @@ class CbRepo extends be_db_common_1.DbRepo {
402
418
  /** @inheritDoc */
403
419
  $insert(doc, p1, ignoreCheck) {
404
420
  return __awaiter(this, void 0, void 0, function* () {
405
- const { conn, collection, useNumericId } = this._props;
421
+ const { conn, collection, noInsert, useNumericId } = this._props;
422
+ const opt = conn.buildOpt(p1, '$insert');
423
+ const param = { where: 'CbRepo', method: '$insert', queryName: opt.name };
424
+ if (noInsert) {
425
+ throw new be_db_common_1.DbNotSupportedError('Insert', param);
426
+ }
406
427
  if (!ignoreCheck) {
407
- (0, type_2.assertObject)(doc, { field: 'doc', where: 'CbRepo', method: '$insert' });
408
- (0, type_2.assertText)(doc._urn, { field: 'doc._urn', where: 'CbRepo', method: '$insert' });
428
+ (0, type_2.assertObject)(doc, Object.assign({ field: 'doc' }, param));
429
+ (0, type_2.assertText)(doc._urn, Object.assign({ field: 'doc._urn' }, param));
409
430
  if (useNumericId) {
410
- (0, type_1.assertInteger)(doc.id, { field: 'doc.id', where: 'CbRepo', method: '$insert' });
431
+ (0, type_1.assertInteger)(doc.id, Object.assign({ field: 'doc.id' }, param));
411
432
  }
412
433
  else {
413
- (0, type_2.assertText)(doc.id, { field: 'doc.id', where: 'CbRepo', method: '$insert' });
434
+ (0, type_2.assertText)(doc.id, Object.assign({ field: 'doc.id' }, param));
414
435
  }
415
436
  }
416
- const opt = conn.buildOpt(p1, '$insert');
417
437
  yield conn.exec(collection.insert(doc._urn, doc), opt);
418
438
  return doc._urn;
419
439
  });
@@ -423,33 +443,66 @@ class CbRepo extends be_db_common_1.DbRepo {
423
443
  /** @inheritDoc */
424
444
  $replace(doc, p1, ignoreCheck) {
425
445
  return __awaiter(this, void 0, void 0, function* () {
426
- const { conn, collection, useNumericId } = this._props;
446
+ const { conn, collection, noUpdate, useNumericId } = this._props;
447
+ const opt = conn.buildOpt(p1, '$replace');
448
+ const param = { where: 'CbRepo', method: '$replace', queryName: opt.name };
449
+ if (noUpdate) {
450
+ throw new be_db_common_1.DbNotSupportedError('Update', param);
451
+ }
427
452
  if (!ignoreCheck) {
428
- (0, type_2.assertObject)(doc, { field: 'doc', where: 'CbRepo', method: '$replace' });
429
- (0, type_2.assertText)(doc._urn, { field: 'doc._urn', where: 'CbRepo', method: '$replace' });
453
+ (0, type_2.assertObject)(doc, Object.assign({ field: 'doc' }, param));
454
+ (0, type_2.assertText)(doc._urn, Object.assign({ field: 'doc._urn' }, param));
430
455
  if (useNumericId) {
431
- (0, type_1.assertInteger)(doc.id, { field: 'doc.id', where: 'CbRepo', method: '$replace' });
456
+ (0, type_1.assertInteger)(doc.id, Object.assign({ field: 'doc.id' }, param));
432
457
  }
433
458
  else {
434
- (0, type_2.assertText)(doc.id, { field: 'doc.id', where: 'CbRepo', method: '$replace' });
459
+ (0, type_2.assertText)(doc.id, Object.assign({ field: 'doc.id' }, param));
435
460
  }
436
461
  }
437
- const opt = conn.buildOpt(p1, '$replace');
438
462
  yield conn.exec(collection.replace(doc._urn, doc), opt);
439
463
  return doc._urn;
440
464
  });
441
465
  }
442
466
  // endregion replace
467
+ // region upsert
468
+ /** @inheritDoc */
469
+ $upsert(doc, p1, ignoreCheck) {
470
+ return __awaiter(this, void 0, void 0, function* () {
471
+ const { conn, collection, noUpdate, noInsert, useNumericId } = this._props;
472
+ const opt = conn.buildOpt(p1, '$upsert');
473
+ const param = { where: 'CbRepo', method: '$upsert', queryName: opt.name };
474
+ if (noUpdate || noInsert) {
475
+ throw new be_db_common_1.DbNotSupportedError('Upsert', param);
476
+ }
477
+ if (!ignoreCheck) {
478
+ (0, type_2.assertObject)(doc, Object.assign({ field: 'doc' }, param));
479
+ (0, type_2.assertText)(doc._urn, Object.assign({ field: 'doc._urn' }, param));
480
+ if (useNumericId) {
481
+ (0, type_1.assertInteger)(doc.id, Object.assign({ field: 'doc.id' }, param));
482
+ }
483
+ else {
484
+ (0, type_2.assertText)(doc.id, Object.assign({ field: 'doc.id' }, param));
485
+ }
486
+ }
487
+ yield conn.exec(collection.upsert(doc._urn, doc), opt);
488
+ return doc._urn;
489
+ });
490
+ }
491
+ // endregion upsert
443
492
  // region update
444
493
  /** @inheritDoc */
445
494
  $updateByPrimary(key, doc, p1, ignoreCheck) {
446
495
  return __awaiter(this, void 0, void 0, function* () {
496
+ const { conn, full, noUpdate, useSoftDelete } = this._props;
497
+ const opt = conn.buildOpt(p1, '$updateByPrimary');
498
+ const param = { where: 'CbRepo', method: '$updateByPrimary', queryName: opt.name };
499
+ if (noUpdate) {
500
+ throw new be_db_common_1.DbNotSupportedError('Update', param);
501
+ }
447
502
  if (!ignoreCheck) {
448
- (0, type_2.assertText)(key, { field: 'key', where: 'CbRepo', method: '$updateByPrimary' });
449
- (0, type_2.assertObject)(doc, { field: 'doc', where: 'CbRepo', method: '$updateByPrimary' });
503
+ (0, type_2.assertText)(key, Object.assign({ field: 'key' }, param));
504
+ (0, type_2.assertObject)(doc, Object.assign({ field: 'doc' }, param));
450
505
  }
451
- const { conn, full, useSoftDelete } = this._props;
452
- const opt = conn.buildOpt(p1, '$updateByPrimary');
453
506
  const parameters = {};
454
507
  let paramId = 0;
455
508
  const set = [];
@@ -487,17 +540,21 @@ class CbRepo extends be_db_common_1.DbRepo {
487
540
  $updateBySecondary(key, doc, p1, ignoreCheck) {
488
541
  return __awaiter(this, void 0, void 0, function* () {
489
542
  var _a;
490
- const { useNumericId, useSoftDelete, conn, full } = this._props;
543
+ const { useNumericId, noUpdate, useSoftDelete, conn, full } = this._props;
544
+ const opt = conn.buildOpt(p1, '$updateBySecondary');
545
+ const param = { where: 'CbRepo', method: '$updateBySecondary', queryName: opt.name };
546
+ if (noUpdate) {
547
+ throw new be_db_common_1.DbNotSupportedError('Update', param);
548
+ }
491
549
  if (!ignoreCheck) {
492
550
  if (useNumericId) {
493
- (0, type_1.assertInteger)(key, { field: 'key', where: 'CbRepo', method: '$updateBySecondary' });
551
+ (0, type_1.assertInteger)(key, Object.assign({ field: 'key' }, param));
494
552
  }
495
553
  else {
496
- (0, type_2.assertText)(key, { field: 'key', where: 'CbRepo', method: '$updateBySecondary' });
554
+ (0, type_2.assertText)(key, Object.assign({ field: 'key' }, param));
497
555
  }
498
- (0, type_2.assertObject)(doc, { field: 'doc', where: 'CbRepo', method: '$updateBySecondary' });
556
+ (0, type_2.assertObject)(doc, Object.assign({ field: 'doc' }, param));
499
557
  }
500
- const opt = conn.buildOpt(p1, '$updateBySecondary');
501
558
  const parameters = {};
502
559
  let paramId = 0;
503
560
  const set = [];
@@ -536,11 +593,15 @@ class CbRepo extends be_db_common_1.DbRepo {
536
593
  /** @inheritDoc */
537
594
  $removeByPrimary(key, p1, ignoreCheck) {
538
595
  return __awaiter(this, void 0, void 0, function* () {
596
+ const { useSoftDelete, noRemove, conn, full, collection } = this._props;
597
+ const opt = conn.buildOpt(p1, '$removeByPrimary');
598
+ const param = { where: 'CbRepo', method: '$removeByPrimary', queryName: opt.name };
599
+ if (noRemove) {
600
+ throw new be_db_common_1.DbNotSupportedError('Remove', param);
601
+ }
539
602
  if (!ignoreCheck) {
540
- (0, type_2.assertText)(key, { field: 'key', where: 'CbRepo', method: '$removeByPrimary' });
603
+ (0, type_2.assertText)(key, Object.assign({ field: 'key' }, param));
541
604
  }
542
- const { useSoftDelete, conn, full, collection } = this._props;
543
- const opt = conn.buildOpt(p1, '$removeByPrimary');
544
605
  if (!useSoftDelete) {
545
606
  yield conn.exec(collection.remove(key, opt), opt);
546
607
  return key;
@@ -560,16 +621,20 @@ class CbRepo extends be_db_common_1.DbRepo {
560
621
  $removeBySecondary(key, p1, ignoreCheck) {
561
622
  return __awaiter(this, void 0, void 0, function* () {
562
623
  var _a;
563
- const { useNumericId, useSoftDelete, conn, full } = this._props;
624
+ const { useNumericId, noRemove, useSoftDelete, conn, full } = this._props;
625
+ const opt = conn.buildOpt(p1, '$removeBySecondary');
626
+ const param = { where: 'CbRepo', method: '$removeBySecondary', queryName: opt.name };
627
+ if (noRemove) {
628
+ throw new be_db_common_1.DbNotSupportedError('Remove', param);
629
+ }
564
630
  if (!ignoreCheck) {
565
631
  if (useNumericId) {
566
- (0, type_1.assertInteger)(key, { field: 'key', where: 'CbRepo', method: '$removeBySecondary' });
632
+ (0, type_1.assertInteger)(key, Object.assign({ field: 'key' }, param));
567
633
  }
568
634
  else {
569
- (0, type_2.assertText)(key, { field: 'key', where: 'CbRepo', method: '$removeBySecondary' });
635
+ (0, type_2.assertText)(key, Object.assign({ field: 'key' }, param));
570
636
  }
571
637
  }
572
- const opt = conn.buildOpt(p1, '$removeBySecondary');
573
638
  const lines = (0, be_db_common_1.dbLines)();
574
639
  lines
575
640
  .add('DELETE')
@@ -586,14 +651,18 @@ class CbRepo extends be_db_common_1.DbRepo {
586
651
  /** @inheritDoc */
587
652
  $trashByPrimary(key, p1, ignoreCheck) {
588
653
  return __awaiter(this, void 0, void 0, function* () {
589
- const { useSoftDelete, conn, full } = this._props;
654
+ const { useSoftDelete, noTrash, conn, full } = this._props;
655
+ const opt = conn.buildOpt(p1, '$trashByPrimary');
656
+ const param = { where: 'CbRepo', method: '$trashByPrimary', queryName: opt.name };
657
+ if (noTrash) {
658
+ throw new be_db_common_1.DbNotSupportedError('Trash', param);
659
+ }
590
660
  if (!useSoftDelete) {
591
- throw new be_db_common_1.DbNotSupportedError('Soft delete', 'CbRepo', '$trashByPrimary');
661
+ throw new be_db_common_1.DbNotSupportedError('Soft delete', param);
592
662
  }
593
663
  if (!ignoreCheck) {
594
- (0, type_2.assertText)(key, { field: 'key', where: 'CbRepo', method: '$trashByPrimary' });
664
+ (0, type_2.assertText)(key, Object.assign({ field: 'key' }, param));
595
665
  }
596
- const opt = conn.buildOpt(p1, '$trashByPrimary');
597
666
  const lines = (0, be_db_common_1.dbLines)();
598
667
  lines
599
668
  .add(`UPDATE ${full} a`)
@@ -615,19 +684,23 @@ class CbRepo extends be_db_common_1.DbRepo {
615
684
  $trashBySecondary(key, p1, ignoreCheck) {
616
685
  return __awaiter(this, void 0, void 0, function* () {
617
686
  var _a;
618
- const { useSoftDelete, useNumericId, conn, full } = this._props;
687
+ const { useSoftDelete, noTrash, useNumericId, conn, full } = this._props;
688
+ const opt = conn.buildOpt(p1, '$trashBySecondary');
689
+ const param = { where: 'CbRepo', method: '$trashBySecondary', queryName: opt.name };
690
+ if (noTrash) {
691
+ throw new be_db_common_1.DbNotSupportedError('Trash', param);
692
+ }
619
693
  if (!useSoftDelete) {
620
- throw new be_db_common_1.DbNotSupportedError('Soft delete', 'CbRepo', '$trashBySecondary');
694
+ throw new be_db_common_1.DbNotSupportedError('Soft delete', param);
621
695
  }
622
696
  if (!ignoreCheck) {
623
697
  if (useNumericId) {
624
- (0, type_1.assertInteger)(key, { field: 'key', where: 'CbRepo', method: '$trashBySecondary' });
698
+ (0, type_1.assertInteger)(key, Object.assign({ field: 'key' }, param));
625
699
  }
626
700
  else {
627
- (0, type_2.assertText)(key, { field: 'key', where: 'CbRepo', method: '$trashBySecondary' });
701
+ (0, type_2.assertText)(key, Object.assign({ field: 'key' }, param));
628
702
  }
629
703
  }
630
- const opt = conn.buildOpt(p1, '$trashBySecondary');
631
704
  const lines = (0, be_db_common_1.dbLines)();
632
705
  lines
633
706
  .add(`UPDATE ${full} a`)
@@ -1,36 +1,40 @@
1
- import type { Bucket, BucketSettings, Cluster, Collection, CollectionSpec, RemoveOptions, Scope, ScopeSpec } from "couchbase";
1
+ import type { Bucket, BucketSettings, Cluster, Collection, CollectionSpec, RemoveOptions, Scope, ScopeSpec, UpsertOptions } from "couchbase";
2
2
  import type { CbConnectionLike, CbExecOpt } from "../connection";
3
3
  import type { DbRepoLike, DbRepoOpt, DbRepoToDim, DbRepoToUrnTuple } from "@samet-it/be-db-common";
4
- import type { DefDims, Entity, Pair, Portion, UrnDocLike, View } from "@samet-it/be-base-common";
4
+ import type { DefDims, Entity, Pair, Portion, UrnDef, UrnDocLike, View } from "@samet-it/be-base-common";
5
5
  import type { ExistsOptions, GetOptions, InsertOptions, ReplaceOptions } from "couchbase";
6
6
  import type { DbRepoProps } from "@samet-it/be-db-common";
7
- import type { KeyValue } from "@leyyo/common";
8
- /**
9
- * General result for mutable queries to return key
10
- * */
11
- export interface CbResultX {
12
- /**
13
- * It should be `meta().id`
14
- * */
15
- x: string;
16
- }
7
+ import type { KeyValue, StrKey } from "@leyyo/common";
17
8
  /**
18
9
  * Couchbase repository (collection) interface
19
- * @abstract
10
+ *
11
+ * Generics:
12
+ * - 0-`ENT`: entity {@link Entity}
13
+ * - 1-`ID`: id type {@link KeyValue}
14
+ * - 2-`URN`: urn interface {@link UrnDocLike}
15
+ * - 3-`VIEW`: view interface for presentation layer {@link View}
16
+ * - 4-`PAIR`: pair interface for presentation layer {@link Pair}
17
+ * - 5-`PORTION`: portion interface for presentation layer {@link Portion}
18
+ * - 6-`KEYS`: keys to autocomplete, def: keys of {@link Entity}
19
+ * - 7-`DIMS`: dimensions for presentation layer {@link DefDims}
20
20
  * */
21
- export interface CbRepoLike<ID extends KeyValue, ENTITY extends Entity<ID>, URN extends UrnDocLike, KEYS extends string = string, DIMS extends DefDims = DefDims, PAIR extends Pair<ID> = Pair<ID>, VIEW extends View<ID> = View<ID>, PORTION extends Portion<ID> = Portion<ID>> extends DbRepoLike<CbConnectionLike, CbExecOpt, ID, ENTITY, URN, KEYS, DIMS, PAIR, VIEW, PORTION> {
21
+ export interface CbRepoLike<ENT extends Entity<ID>, ID extends KeyValue = KeyValue, URN extends UrnDocLike = UrnDef<ID>, VIEW extends View<ID> = ENT, PAIR extends Pair<ID> = Pair<ID>, PORTION extends Portion<ID> = Portion<ID>, KEYS extends string = StrKey<ENT>, DIMS extends DefDims = DefDims> extends DbRepoLike<CbConnectionLike, CbExecOpt, ENT, ID, URN, VIEW, PAIR, PORTION, KEYS, DIMS> {
22
+ /** @inheritDoc */
23
+ get props(): Readonly<CbRepoProps<ENT, ID>>;
24
+ /** @inheritDoc */
25
+ insert(doc: ENT, opt?: CbInsertOpt | string, ignoreCheck?: boolean): Promise<string>;
22
26
  /** @inheritDoc */
23
- get props(): Readonly<CbRepoProps<ID, ENTITY>>;
27
+ inserts(docs: Array<ENT>, opt?: CbInsertOpt | string, ignoreCheck?: boolean): Promise<Array<string>>;
24
28
  /** @inheritDoc */
25
- insert(doc: ENTITY, opt?: CbInsertOpt | string, ignoreCheck?: boolean): Promise<string>;
29
+ $insert(doc: ENT, opt?: CbInsertOpt | string, ignoreCheck?: boolean): Promise<string>;
26
30
  /** @inheritDoc */
27
- inserts(docs: Array<ENTITY>, opt?: CbInsertOpt | string, ignoreCheck?: boolean): Promise<Array<string>>;
31
+ replace(doc: ENT, opt?: CbReplaceOpt | string, ignoreCheck?: boolean): Promise<string>;
28
32
  /** @inheritDoc */
29
- $insert(doc: ENTITY, opt?: CbInsertOpt | string, ignoreCheck?: boolean): Promise<string>;
33
+ $replace(doc: ENT, opt?: CbReplaceOpt | string, ignoreCheck?: boolean): Promise<string>;
30
34
  /** @inheritDoc */
31
- replace(doc: ENTITY, opt?: CbReplaceOpt | string, ignoreCheck?: boolean): Promise<string>;
35
+ upsert(doc: ENT, opt?: CbUpsertOpt | string, ignoreCheck?: boolean): Promise<string>;
32
36
  /** @inheritDoc */
33
- $replace(doc: ENTITY, opt?: CbReplaceOpt | string, ignoreCheck?: boolean): Promise<string>;
37
+ $upsert(doc: ENT, opt?: CbUpsertOpt | string, ignoreCheck?: boolean): Promise<string>;
34
38
  /** @inheritDoc */
35
39
  remove(key: KeyValue, opt?: CbRemoveOpt | string, ignoreCheck?: boolean): Promise<string>;
36
40
  /** @inheritDoc */
@@ -44,8 +48,12 @@ export interface CbRepoLike<ID extends KeyValue, ENTITY extends Entity<ID>, URN
44
48
  }
45
49
  /**
46
50
  * Couchbase repository (collection) option
51
+ *
52
+ * Generics:
53
+ * - 0-`ENT`: entity {@link Entity}
54
+ * - 1-`ID`: id type {@link KeyValue}
47
55
  * */
48
- export interface CbRepoOpt<ID extends KeyValue, ENTITY extends Entity<ID>> extends DbRepoOpt<ID, ENTITY> {
56
+ export interface CbRepoOpt<ENT extends Entity<ID>, ID extends KeyValue = KeyValue> extends DbRepoOpt<ENT, ID> {
49
57
  /**
50
58
  * Bucket name
51
59
  *
@@ -73,8 +81,12 @@ export interface CbRepoOpt<ID extends KeyValue, ENTITY extends Entity<ID>> exten
73
81
  }
74
82
  /**
75
83
  * Couchbase repository (collection) props
84
+ *
85
+ * Generics:
86
+ * - 0-`ENT`: entity {@link Entity}
87
+ * - 1-`ID`: id type {@link KeyValue}
76
88
  * */
77
- export interface CbRepoProps<ID extends KeyValue, ENTITY extends Entity<ID>> extends CbRepoOpt<ID, ENTITY>, DbRepoProps<CbConnectionLike, ID, ENTITY> {
89
+ export interface CbRepoProps<ENT extends Entity<ID>, ID extends KeyValue = KeyValue> extends CbRepoOpt<ENT, ID>, DbRepoProps<CbConnectionLike, ENT, ID> {
78
90
  /**
79
91
  * Cluster
80
92
  *
@@ -108,17 +120,27 @@ export interface CbRepoProps<ID extends KeyValue, ENTITY extends Entity<ID>> ext
108
120
  }
109
121
  /**
110
122
  * Couchbase repository (collection) props part for extended usage
123
+ *
124
+ * Generics:
125
+ * - 0-`SPEC`: spec model
111
126
  * */
112
- export interface CbRepoPropsPart<S> {
127
+ export interface CbRepoPropsPart<SPEC> {
113
128
  /**
114
129
  * Extended property to hold couchbase specs
115
130
  * */
116
- readonly $spec?: S;
131
+ readonly $spec?: SPEC;
117
132
  }
118
133
  /**
119
134
  * Couchbase direct repository (collection) option
135
+ *
136
+ * Generics:
137
+ * - 0-`ENT`: entity {@link Entity}
138
+ * - 1-`ID`: id type {@link KeyValue}
139
+ * - 2-`URN`: urn interface {@link UrnDocLike}
140
+ * - 3-`DIMS`: dimensions for presentation layer {@link DefDims}
141
+ * - 4-`R`: ??
120
142
  * */
121
- export interface CbRepoDirectOpt<ID extends KeyValue, ENTITY extends Entity<ID>, URN extends UrnDocLike, DIMS extends DefDims = DefDims, R = unknown> extends CbRepoOpt<ID, ENTITY> {
143
+ export interface CbRepoDirectOpt<ENT extends Entity<ID>, ID extends KeyValue = KeyValue, URN extends UrnDocLike = UrnDef<ID>, DIMS extends DefDims = DefDims, R = unknown> extends CbRepoOpt<ENT, ID> {
122
144
  /**
123
145
  * Name of logger class
124
146
  * */
@@ -130,7 +152,7 @@ export interface CbRepoDirectOpt<ID extends KeyValue, ENTITY extends Entity<ID>,
130
152
  /**
131
153
  * Overridable method to easy use
132
154
  * */
133
- toDim?: DbRepoToDim<R, ID, ENTITY, DIMS>;
155
+ toDim?: DbRepoToDim<R, ENT, ID, DIMS>;
134
156
  }
135
157
  /**
136
158
  * Couchbase insert query option
@@ -152,3 +174,16 @@ export type CbExistsOpt = CbExecOpt & ExistsOptions;
152
174
  * Couchbase get query option
153
175
  * */
154
176
  export type CbGetOpt = CbExecOpt & GetOptions;
177
+ /**
178
+ * Couchbase upsert query option
179
+ * */
180
+ export type CbUpsertOpt = CbExecOpt & UpsertOptions;
181
+ /**
182
+ * General result for mutable queries to return key
183
+ * */
184
+ export interface CbResultX {
185
+ /**
186
+ * It should be `meta().id`
187
+ * */
188
+ x: string;
189
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samet-it/be-couchbase-common",
3
- "version": "1.1.4",
3
+ "version": "1.1.7",
4
4
  "description": "Couchbase common component",
5
5
  "keywords": [
6
6
  "Couchbase"
@@ -66,13 +66,13 @@
66
66
  }
67
67
  },
68
68
  "dependencies": {
69
- "@leyyo/common": "^1.2.1",
69
+ "@leyyo/common": "^1.2.3",
70
70
  "@leyyo/env": "^1.2.1",
71
71
  "@leyyo/query": "^1.2.1",
72
72
  "@leyyo/type": "^1.1.1",
73
- "@samet-it/be-base-common": "^1.1.1",
74
- "@samet-it/be-cache-common": "^1.1.1",
75
- "@samet-it/be-db-common": "^1.1.2",
73
+ "@samet-it/be-base-common": "^1.1.3",
74
+ "@samet-it/be-cache-common": "^1.1.3",
75
+ "@samet-it/be-db-common": "^1.1.4",
76
76
  "couchbase": "^4.6.0"
77
77
  }
78
78
  }