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

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,12 @@
1
1
  import type { QueryResult, QueryMetaData } from 'couchbase';
2
2
  import { type IgnoreFieldsByType, type ReplaceType } from "@leyyo/common";
3
3
  import { DbConnection, type DbLines } from "@samet-it/be-db-common";
4
- import type { CbConnectionLike, CbConnOpt, CbExecOpt, CbConnProps } from "./index.types";
5
- import type { CbRepoDef } from "../repo";
4
+ import type { CbConnectionLike, CbConnOpt, CbExecOpt, CbConnProps, CbRepoLink } from "./index.types";
6
5
  import type { DbQueryResultMore, DbQueryResultOne } from "@samet-it/be-db-common";
7
6
  /**
8
7
  * Couchbase connection abstract class
9
8
  * */
10
- export declare abstract class CbConnection extends DbConnection<CbRepoDef, QueryMetaData, CbExecOpt> implements CbConnectionLike {
9
+ export declare abstract class CbConnection extends DbConnection<CbRepoLink, QueryMetaData, CbExecOpt> implements CbConnectionLike {
11
10
  /** {@inheritDoc} */
12
11
  protected _props: CbConnProps;
13
12
  protected constructor(opt?: CbConnOpt);
@@ -28,9 +27,9 @@ export declare abstract class CbConnection extends DbConnection<CbRepoDef, Query
28
27
  /** {@inheritDoc} */
29
28
  castDatesForList<T>(given: Array<ReplaceType<T, Date, string> | T>, ...fields: Array<IgnoreFieldsByType<T, Date>>): void;
30
29
  /** {@inheritDoc} */
31
- more<T>(repo: CbRepoDef, lines: string | DbLines, p1?: string | CbExecOpt): Promise<DbQueryResultMore<T, QueryMetaData>>;
30
+ more<T>(link: CbRepoLink, lines: string | DbLines, p1?: string | CbExecOpt): Promise<DbQueryResultMore<T, QueryMetaData>>;
32
31
  /** {@inheritDoc} */
33
- one<T>(repo: CbRepoDef, lines: string | DbLines, p1?: string | CbExecOpt): Promise<DbQueryResultOne<T, QueryMetaData>>;
32
+ one<T>(link: CbRepoLink, lines: string | DbLines, p1?: string | CbExecOpt): Promise<DbQueryResultOne<T, QueryMetaData>>;
34
33
  /** {@inheritDoc} */
35
34
  connect(): Promise<boolean>;
36
35
  /** {@inheritDoc} */
@@ -160,15 +160,15 @@ class CbConnection extends be_db_common_1.DbConnection {
160
160
  // endregion transcoders
161
161
  // region query
162
162
  /** {@inheritDoc} */
163
- more(repo, lines, p1) {
163
+ more(link, lines, p1) {
164
164
  return __awaiter(this, void 0, void 0, function* () {
165
165
  const opt = this.buildOpt(p1);
166
166
  const sql = (0, type_1.isObjectValid)(lines) ? lines.end() : lines;
167
167
  if (opt.printSql) {
168
- this.logger.log(`${repo.props.path} > SQL${opt.name}`, sql);
168
+ this.logger.log(`${link.path} > SQL${opt.name}`, sql);
169
169
  }
170
170
  try {
171
- const result = yield repo.props.scope.query(sql, opt);
171
+ const result = yield link.scope.query(sql, opt);
172
172
  return {
173
173
  success: true,
174
174
  rows: result.rows,
@@ -186,15 +186,15 @@ class CbConnection extends be_db_common_1.DbConnection {
186
186
  });
187
187
  }
188
188
  /** {@inheritDoc} */
189
- one(repo, lines, p1) {
189
+ one(link, lines, p1) {
190
190
  return __awaiter(this, void 0, void 0, function* () {
191
191
  const opt = this.buildOpt(p1);
192
192
  const sql = (0, type_1.isObjectValid)(lines) ? lines.end() : lines;
193
193
  if (opt.printSql) {
194
- this.logger.log(`${repo.props.path} > SQL${opt.name}`, sql);
194
+ this.logger.log(`${link.path} > SQL${opt.name}`, sql);
195
195
  }
196
196
  try {
197
- const result = yield repo.props.scope.query(sql, opt);
197
+ const result = yield link.scope.query(sql, opt);
198
198
  return {
199
199
  success: true,
200
200
  row: (Array.isArray(result.rows) && result.rows.length > 0) ? result.rows[0] : undefined,
@@ -1,12 +1,12 @@
1
- import type { Cluster, QueryMetaData, QueryOptions, QueryResult } from "couchbase";
1
+ import type { Cluster, QueryMetaData, QueryOptions, QueryResult, Scope } from "couchbase";
2
2
  import type { IgnoreFieldsByType, KeyValue, ReplaceType } from "@leyyo/common";
3
- import type { CbRepoDef, CbRepoDirectOpt, CbRepoLike } from "../repo";
4
- import type { DbConnectionLike, DbConnOpt, DbConnProps, DbExecOpt } from "@samet-it/be-db-common";
3
+ import type { CbRepoDirectOpt, CbRepoLike } from "../repo";
4
+ import type { DbConnectionLike, DbConnOpt, DbConnProps, DbExecOpt, DbRepoLink } from "@samet-it/be-db-common";
5
5
  import type { DefDims, Entity, UrnDocLike, Pair, Portion, View } from "@samet-it/be-base-common";
6
6
  /**
7
7
  * Couchbase connection interface
8
8
  * */
9
- export interface CbConnectionLike extends DbConnectionLike<CbRepoDef, QueryMetaData, CbExecOpt> {
9
+ export interface CbConnectionLike extends DbConnectionLike<CbRepoLink, QueryMetaData, CbExecOpt> {
10
10
  /** @inheritDoc */
11
11
  get props(): Readonly<CbConnProps>;
12
12
  /**
@@ -91,4 +91,7 @@ type CbIgnoreFields<T, I> = {
91
91
  type CbReplaceType<T, O, N> = {
92
92
  [P in keyof T]: T[P] extends O ? N : T[P];
93
93
  };
94
+ export interface CbRepoLink extends DbRepoLink {
95
+ scope: Scope;
96
+ }
94
97
  export {};
@@ -1,7 +1,7 @@
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, CbRepoDef, CbRepoProps, CbRepoLike, CbRepoOpt } from "./index.types";
4
+ import type { CbExistsOpt, CbGetOpt, CbInsertOpt, CbReplaceOpt, CbRepoProps, CbRepoLike, CbRepoOpt } from "./index.types";
5
5
  import { DbRepo } from "@samet-it/be-db-common";
6
6
  import type { DefDims, Entity, Pair, Portion, UrnDocLike, View } from "@samet-it/be-base-common";
7
7
  import type { QueryRegular } from "@leyyo/query";
@@ -65,8 +65,6 @@ export declare abstract class CbRepo<ID extends KeyValue, ENTITY extends Entity<
65
65
  * */
66
66
  protected $createIndices(): Promise<void>;
67
67
  /** @inheritDoc */
68
- get $def(): CbRepoDef;
69
- /** @inheritDoc */
70
68
  get props(): Readonly<CbRepoProps<ID, ENTITY>>;
71
69
  /** @inheritDoc */
72
70
  $getByPrimary(key: string, p1?: CbGetOpt | string, ignoreCheck?: boolean): Promise<ENTITY | undefined>;
@@ -92,7 +92,7 @@ class CbRepo extends be_db_common_1.DbRepo {
92
92
  }
93
93
  name = this._indexName(name);
94
94
  sql = `CREATE INDEX ${conn.f(name)} ON ${full} (${fields.join(', ')}) IF NOT EXISTS`;
95
- yield conn.one(this.$def, sql, {
95
+ yield conn.one(this._props, sql, {
96
96
  name: `${path}.index`,
97
97
  ignoredErrors: [couchbase_1.IndexExistsError.name]
98
98
  });
@@ -129,7 +129,7 @@ class CbRepo extends be_db_common_1.DbRepo {
129
129
  return __awaiter(this, void 0, void 0, function* () {
130
130
  const { full, path, conn } = this._props;
131
131
  const sql = `CREATE PRIMARY INDEX \`pk\` ON ${full} IF NOT EXISTS`;
132
- yield conn.one(this.$def, sql, {
132
+ yield conn.one(this._props, sql, {
133
133
  name: `${path}.pk`,
134
134
  ignoredErrors: [couchbase_1.IndexExistsError.name]
135
135
  });
@@ -226,10 +226,6 @@ class CbRepo extends be_db_common_1.DbRepo {
226
226
  // endregion protected-method
227
227
  // region getter
228
228
  /** @inheritDoc */
229
- get $def() {
230
- return this;
231
- }
232
- /** @inheritDoc */
233
229
  get props() {
234
230
  return this._props;
235
231
  }
@@ -259,7 +255,7 @@ class CbRepo extends be_db_common_1.DbRepo {
259
255
  .add(`WHERE (a.${F_TRASH_ID} is missing)`)
260
256
  .add('LIMIT 1');
261
257
  const parameters = { key };
262
- return (yield conn.one(this.$def, lines.end(), Object.assign(Object.assign({}, opt), { parameters }))).row;
258
+ return (yield conn.one(this._props, lines.end(), Object.assign(Object.assign({}, opt), { parameters }))).row;
263
259
  });
264
260
  }
265
261
  /** @inheritDoc */
@@ -283,7 +279,7 @@ class CbRepo extends be_db_common_1.DbRepo {
283
279
  .no(useSoftDelete, ` AND (a.${F_TRASH_ID} is missing)`)
284
280
  .add('LIMIT 1');
285
281
  const parameters = { key };
286
- return (yield conn.one(this.$def, lines.end(), Object.assign(Object.assign({}, opt), { parameters }))).row;
282
+ return (yield conn.one(this._props, lines.end(), Object.assign(Object.assign({}, opt), { parameters }))).row;
287
283
  });
288
284
  }
289
285
  // endregion get
@@ -308,7 +304,7 @@ class CbRepo extends be_db_common_1.DbRepo {
308
304
  .add(`WHERE (a.${F_TRASH_ID} is missing)`)
309
305
  .add('LIMIT 1');
310
306
  const parameters = { key };
311
- return ((_c = (yield conn.one(this.$def, lines.end(), Object.assign(Object.assign({}, opt), { parameters }))).row) === null || _c === void 0 ? void 0 : _c.x) === undefined;
307
+ return ((_c = (yield conn.one(this._props, lines.end(), Object.assign(Object.assign({}, opt), { parameters }))).row) === null || _c === void 0 ? void 0 : _c.x) === undefined;
312
308
  });
313
309
  }
314
310
  /** @inheritDoc */
@@ -333,7 +329,7 @@ class CbRepo extends be_db_common_1.DbRepo {
333
329
  .yes(useSoftDelete, `WHERE (a.${F_TRASH_ID} IS MISSING)`)
334
330
  .add('LIMIT 1');
335
331
  const parameters = { key };
336
- return ((_a = (yield conn.one(this.$def, lines.end(), Object.assign(Object.assign({}, opt), { parameters }))).row) === null || _a === void 0 ? void 0 : _a.x) === undefined;
332
+ return ((_a = (yield conn.one(this._props, lines.end(), Object.assign(Object.assign({}, opt), { parameters }))).row) === null || _a === void 0 ? void 0 : _a.x) === undefined;
337
333
  });
338
334
  }
339
335
  // endregion exists
@@ -356,7 +352,7 @@ class CbRepo extends be_db_common_1.DbRepo {
356
352
  .add(`USE KEYS $keys`)
357
353
  .yes(useSoftDelete, `WHERE (a.${F_TRASH_ID} is missing)`);
358
354
  const parameters = { keys };
359
- return (yield conn.more(this.$def, lines.end(), Object.assign(Object.assign({}, opt), { parameters }))).rows;
355
+ return (yield conn.more(this._props, lines.end(), Object.assign(Object.assign({}, opt), { parameters }))).rows;
360
356
  });
361
357
  }
362
358
  /** @inheritDoc */
@@ -382,7 +378,7 @@ class CbRepo extends be_db_common_1.DbRepo {
382
378
  .add(`WHERE (a.${F_ID} IN $keys)`)
383
379
  .yes(useSoftDelete, ` AND (a.${F_TRASH_ID} IS MISSING)`);
384
380
  const parameters = { keys };
385
- return (yield conn.more(this.$def, lines.end(), Object.assign(Object.assign({}, opt), { parameters }))).rows;
381
+ return (yield conn.more(this._props, lines.end(), Object.assign(Object.assign({}, opt), { parameters }))).rows;
386
382
  });
387
383
  }
388
384
  // endregion list
@@ -398,7 +394,7 @@ class CbRepo extends be_db_common_1.DbRepo {
398
394
  .add(`SELECT a.*`)
399
395
  .add(`FROM ${full} a`)
400
396
  .both(useSoftDelete, `WHERE (a.${F_TRASH_ID} is missing)`, `WHERE (meta().id is not missing)`);
401
- return (yield conn.more(this.$def, lines.end(), opt)).rows;
397
+ return (yield conn.more(this._props, lines.end(), opt)).rows;
402
398
  });
403
399
  }
404
400
  // endregion filter
@@ -481,7 +477,7 @@ class CbRepo extends be_db_common_1.DbRepo {
481
477
  }
482
478
  lines
483
479
  .yes(useSoftDelete, `WHERE (a.${F_TRASH_ID} is missing)`);
484
- yield conn.one(this.$def, lines.end(), Object.assign(Object.assign({}, opt), { parameters }));
480
+ yield conn.one(this._props, lines.end(), Object.assign(Object.assign({}, opt), { parameters }));
485
481
  return key;
486
482
  }
487
483
  return undefined;
@@ -530,7 +526,7 @@ class CbRepo extends be_db_common_1.DbRepo {
530
526
  .yes(useSoftDelete, ` AND (a.${F_TRASH_ID} is missing)`);
531
527
  parameters['key'] = key;
532
528
  lines.add('RETURNING meta().id \`x\`');
533
- return (_a = (yield conn.one(this.$def, lines.end(), Object.assign(Object.assign({}, opt), { parameters }))).row) === null || _a === void 0 ? void 0 : _a.x;
529
+ return (_a = (yield conn.one(this._props, lines.end(), Object.assign(Object.assign({}, opt), { parameters }))).row) === null || _a === void 0 ? void 0 : _a.x;
534
530
  }
535
531
  return undefined;
536
532
  });
@@ -556,7 +552,7 @@ class CbRepo extends be_db_common_1.DbRepo {
556
552
  .add(`USE KEYS $key`)
557
553
  .yes(useSoftDelete, ` AND (a.${F_TRASH_ID} is missing)`);
558
554
  const parameters = { key };
559
- yield conn.one(this.$def, lines.end(), Object.assign(Object.assign({}, opt), { parameters }));
555
+ yield conn.one(this._props, lines.end(), Object.assign(Object.assign({}, opt), { parameters }));
560
556
  return key;
561
557
  });
562
558
  }
@@ -582,7 +578,7 @@ class CbRepo extends be_db_common_1.DbRepo {
582
578
  .yes(useSoftDelete, ` AND (a.${F_TRASH_ID} is missing)`)
583
579
  .add('RETURNING meta().id \`x\`');
584
580
  const parameters = { key };
585
- return (_a = (yield conn.one(this.$def, lines.end(), Object.assign(Object.assign({}, opt), { parameters }))).row) === null || _a === void 0 ? void 0 : _a.x;
581
+ return (_a = (yield conn.one(this._props, lines.end(), Object.assign(Object.assign({}, opt), { parameters }))).row) === null || _a === void 0 ? void 0 : _a.x;
586
582
  });
587
583
  }
588
584
  // endregion remove
@@ -611,7 +607,7 @@ class CbRepo extends be_db_common_1.DbRepo {
611
607
  trashId: opt.trashId,
612
608
  key,
613
609
  };
614
- yield conn.one(this.$def, lines.end(), Object.assign(Object.assign({}, opt), { parameters }));
610
+ yield conn.one(this._props, lines.end(), Object.assign(Object.assign({}, opt), { parameters }));
615
611
  return key;
616
612
  });
617
613
  }
@@ -646,7 +642,7 @@ class CbRepo extends be_db_common_1.DbRepo {
646
642
  trashId: opt.trashId,
647
643
  key,
648
644
  };
649
- return (_a = (yield conn.one(this.$def, lines.end(), Object.assign(Object.assign({}, opt), { parameters }))).row) === null || _a === void 0 ? void 0 : _a.x;
645
+ return (_a = (yield conn.one(this._props, lines.end(), Object.assign(Object.assign({}, opt), { parameters }))).row) === null || _a === void 0 ? void 0 : _a.x;
650
646
  });
651
647
  }
652
648
  }
@@ -19,8 +19,6 @@ export interface CbResultX {
19
19
  * @abstract
20
20
  * */
21
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> {
22
- /** @inheritDoc */
23
- get $def(): CbRepoDef;
24
22
  /** @inheritDoc */
25
23
  get props(): Readonly<CbRepoProps<ID, ENTITY>>;
26
24
  /** @inheritDoc */
@@ -44,10 +42,6 @@ export interface CbRepoLike<ID extends KeyValue, ENTITY extends Entity<ID>, URN
44
42
  /** @inheritDoc */
45
43
  $removeBySecondary(key: KeyValue, opt?: CbRemoveOpt | string, ignoreCheck?: boolean): Promise<string>;
46
44
  }
47
- /**
48
- * Couchbase default repository (collection) without any generics
49
- * */
50
- export type CbRepoDef = CbRepoLike<KeyValue, Entity<KeyValue>, UrnDocLike>;
51
45
  /**
52
46
  * Couchbase repository (collection) option
53
47
  * */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samet-it/be-couchbase-common",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Couchbase common component",
5
5
  "keywords": [
6
6
  "Couchbase"
@@ -72,7 +72,7 @@
72
72
  "@leyyo/type": "^1.1.1",
73
73
  "@samet-it/be-base-common": "^1.1.1",
74
74
  "@samet-it/be-cache-common": "^1.1.1",
75
- "@samet-it/be-db-common": "^1.0.11",
75
+ "@samet-it/be-db-common": "^1.1.2",
76
76
  "couchbase": "^4.6.0"
77
77
  }
78
78
  }