@samet-it/be-couchbase-common 1.1.5 → 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/dist/config/couchbase-common.config.js +28 -8
- package/dist/config/index.types.d.ts +4 -0
- package/dist/connection/cb-direct.connection.d.ts +6 -1
- package/dist/connection/cb-direct.connection.js +5 -0
- package/dist/connection/cb.connection.d.ts +5 -0
- package/dist/connection/cb.connection.js +17 -0
- package/dist/connection/index.types.d.ts +12 -1
- package/dist/repo/cb-direct.repo.d.ts +18 -2
- package/dist/repo/cb-direct.repo.js +16 -0
- package/dist/repo/cb.repo.d.ts +35 -17
- package/dist/repo/cb.repo.js +165 -44
- package/dist/repo/index.types.d.ts +59 -24
- package/package.json +6 -6
|
@@ -9,12 +9,32 @@ const env_1 = require("@leyyo/env");
|
|
|
9
9
|
exports.couchbaseCommonConfig = env_1.envCore.configure
|
|
10
10
|
.scope('CouchbaseCommon', 'CB')
|
|
11
11
|
.start()
|
|
12
|
-
|
|
13
|
-
.field('
|
|
14
|
-
.
|
|
15
|
-
.field('
|
|
16
|
-
.
|
|
17
|
-
.
|
|
18
|
-
.field('
|
|
19
|
-
.
|
|
12
|
+
// @formatter:off
|
|
13
|
+
.field('ENABLED')
|
|
14
|
+
.boolean().def(true).end()
|
|
15
|
+
.field('PROTOCOL')
|
|
16
|
+
.off(v => !v.ENABLED)
|
|
17
|
+
.text().def('couchbase').end()
|
|
18
|
+
.field('HOST')
|
|
19
|
+
.off(v => !v.ENABLED)
|
|
20
|
+
.text().required().end()
|
|
21
|
+
.field('PORT')
|
|
22
|
+
.off(v => !v.ENABLED)
|
|
23
|
+
.integer().end()
|
|
24
|
+
.field('USER')
|
|
25
|
+
.off(v => !v.ENABLED)
|
|
26
|
+
.text().required().end()
|
|
27
|
+
.field('PASS')
|
|
28
|
+
.off(v => !v.ENABLED)
|
|
29
|
+
.text().required().end()
|
|
30
|
+
.field('BUCKET')
|
|
31
|
+
.off(v => !v.ENABLED)
|
|
32
|
+
.text().required().end()
|
|
33
|
+
.field('SCOPE')
|
|
34
|
+
.off(v => !v.ENABLED)
|
|
35
|
+
.text().required().end()
|
|
36
|
+
.field('CREATE_INDICES')
|
|
37
|
+
.off(v => !v.ENABLED)
|
|
38
|
+
.boolean().def(false).end()
|
|
39
|
+
// @formatter:on
|
|
20
40
|
.finish();
|
|
@@ -8,7 +8,12 @@ import type { KeyValue, StrKey } from "@leyyo/common";
|
|
|
8
8
|
* Couchbase connection direct class
|
|
9
9
|
* */
|
|
10
10
|
export declare class CbDirectConnection extends CbConnection implements CbDirectConnectionLike {
|
|
11
|
+
/**
|
|
12
|
+
* Constructor
|
|
13
|
+
*
|
|
14
|
+
* @param {CbDirectConnOpt} opt - options
|
|
15
|
+
* */
|
|
11
16
|
constructor(opt?: CbDirectConnOpt);
|
|
12
17
|
/** @inheritDoc */
|
|
13
|
-
newRepo<
|
|
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>;
|
|
14
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);
|
|
@@ -162,6 +167,9 @@ class CbConnection extends be_db_common_1.DbConnection {
|
|
|
162
167
|
/** {@inheritDoc} */
|
|
163
168
|
more(link, lines, p1) {
|
|
164
169
|
return __awaiter(this, void 0, void 0, function* () {
|
|
170
|
+
if (!this._props.enabled) {
|
|
171
|
+
return { success: true, rows: [] };
|
|
172
|
+
}
|
|
165
173
|
const opt = this.buildOpt(p1);
|
|
166
174
|
const sql = (0, type_1.isObjectValid)(lines) ? lines.end() : lines;
|
|
167
175
|
if (opt.printSql) {
|
|
@@ -188,6 +196,9 @@ class CbConnection extends be_db_common_1.DbConnection {
|
|
|
188
196
|
/** {@inheritDoc} */
|
|
189
197
|
one(link, lines, p1) {
|
|
190
198
|
return __awaiter(this, void 0, void 0, function* () {
|
|
199
|
+
if (!this._props.enabled) {
|
|
200
|
+
return { success: true, row: undefined };
|
|
201
|
+
}
|
|
191
202
|
const opt = this.buildOpt(p1);
|
|
192
203
|
const sql = (0, type_1.isObjectValid)(lines) ? lines.end() : lines;
|
|
193
204
|
if (opt.printSql) {
|
|
@@ -216,6 +227,9 @@ class CbConnection extends be_db_common_1.DbConnection {
|
|
|
216
227
|
/** {@inheritDoc} */
|
|
217
228
|
connect() {
|
|
218
229
|
return __awaiter(this, void 0, void 0, function* () {
|
|
230
|
+
if (!this._props.enabled) {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
219
233
|
const { _props: props } = this;
|
|
220
234
|
if (props.isConnected) {
|
|
221
235
|
return true;
|
|
@@ -253,6 +267,9 @@ class CbConnection extends be_db_common_1.DbConnection {
|
|
|
253
267
|
/** {@inheritDoc} */
|
|
254
268
|
ping(next) {
|
|
255
269
|
return __awaiter(this, void 0, void 0, function* () {
|
|
270
|
+
if (!this._props.enabled) {
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
256
273
|
const { _props: props } = this;
|
|
257
274
|
let result = false;
|
|
258
275
|
try {
|
|
@@ -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<
|
|
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>;
|
|
@@ -5,7 +5,23 @@ import type { CbRepoDirectOpt } from "./index.types";
|
|
|
5
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<
|
|
10
|
-
|
|
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) {
|
package/dist/repo/cb.repo.d.ts
CHANGED
|
@@ -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
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<
|
|
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<
|
|
15
|
-
|
|
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<ENTITY extends Entity<ID>, ID extends KeyVa
|
|
|
26
42
|
* @param {string} field - field name
|
|
27
43
|
* @param {string?} name - index name
|
|
28
44
|
* */
|
|
29
|
-
protected _createIndex(field: keyof
|
|
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
|
|
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
|
|
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<ENTITY extends Entity<ID>, ID extends KeyVa
|
|
|
65
81
|
* */
|
|
66
82
|
protected $createIndices(): Promise<void>;
|
|
67
83
|
/** @inheritDoc */
|
|
68
|
-
get props(): Readonly<CbRepoProps<
|
|
84
|
+
get props(): Readonly<CbRepoProps<ENT, ID>>;
|
|
69
85
|
/** @inheritDoc */
|
|
70
|
-
$getByPrimary(key: string, p1?: CbGetOpt | string, ignoreCheck?: boolean): Promise<
|
|
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<
|
|
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<
|
|
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
|
-
$
|
|
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
|
-
$
|
|
100
|
+
$insert(doc: ENT, p1?: CbInsertOpt | string, ignoreCheck?: boolean): Promise<string>;
|
|
83
101
|
/** @inheritDoc */
|
|
84
|
-
$
|
|
102
|
+
$replace(doc: ENT, p1?: CbReplaceOpt | string, ignoreCheck?: boolean): Promise<string>;
|
|
85
103
|
/** @inheritDoc */
|
|
86
|
-
$
|
|
104
|
+
$upsert(doc: ENT, p1?: CbUpsertOpt | string, ignoreCheck?: boolean): Promise<string>;
|
|
87
105
|
/** @inheritDoc */
|
|
88
|
-
$updateByPrimary(key: string, doc: Partial<
|
|
106
|
+
$updateByPrimary(key: string, doc: Partial<ENT>, p1?: CbExecOpt | string, ignoreCheck?: boolean): Promise<string>;
|
|
89
107
|
/** @inheritDoc */
|
|
90
|
-
$updateBySecondary(key: KeyValue, doc: Partial<
|
|
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 */
|
package/dist/repo/cb.repo.js
CHANGED
|
@@ -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',
|
|
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',
|
|
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',
|
|
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,14 @@ 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
|
+
if (!conn.props.enabled) {
|
|
255
|
+
return undefined;
|
|
256
|
+
}
|
|
257
|
+
const opt = conn.buildOpt(p1, '$getById');
|
|
237
258
|
if (!ignoreCheck) {
|
|
238
259
|
(0, type_2.assertText)(key, { field: 'id', where: 'CbRepo', method: '$getByPrimary' });
|
|
239
260
|
}
|
|
240
|
-
const { conn, useSoftDelete, collection, full } = this._props;
|
|
241
|
-
const opt = conn.buildOpt(p1, '$getById');
|
|
242
261
|
if (!useSoftDelete) {
|
|
243
262
|
if (!Array.isArray(opt.ignoredErrors)) {
|
|
244
263
|
opt.ignoredErrors = [];
|
|
@@ -262,6 +281,9 @@ class CbRepo extends be_db_common_1.DbRepo {
|
|
|
262
281
|
$getBySecondary(key, p1, ignoreCheck) {
|
|
263
282
|
return __awaiter(this, void 0, void 0, function* () {
|
|
264
283
|
const { conn, useSoftDelete, useNumericId, full } = this._props;
|
|
284
|
+
if (!conn.props.enabled) {
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
265
287
|
if (!ignoreCheck) {
|
|
266
288
|
if (useNumericId) {
|
|
267
289
|
(0, type_1.assertInteger)(key, { field: 'key', where: 'CbRepo', method: '$getBySecondary' });
|
|
@@ -288,10 +310,13 @@ class CbRepo extends be_db_common_1.DbRepo {
|
|
|
288
310
|
$existsByPrimary(key, p1, ignoreCheck) {
|
|
289
311
|
return __awaiter(this, void 0, void 0, function* () {
|
|
290
312
|
var _a, _b, _c;
|
|
313
|
+
const { useSoftDelete, conn, collection, full } = this._props;
|
|
314
|
+
if (!conn.props.enabled) {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
291
317
|
if (!ignoreCheck) {
|
|
292
318
|
(0, type_2.assertText)(key, { field: 'key', where: 'CbRepo', method: '$existsByPrimary' });
|
|
293
319
|
}
|
|
294
|
-
const { useSoftDelete, conn, collection, full } = this._props;
|
|
295
320
|
const opt = conn.buildOpt(p1, '$existsByPrimary');
|
|
296
321
|
if (!useSoftDelete) {
|
|
297
322
|
return (_b = (_a = (yield conn.exec(collection.exists(key, opt), opt))) === null || _a === void 0 ? void 0 : _a.exists) !== null && _b !== void 0 ? _b : false;
|
|
@@ -312,6 +337,9 @@ class CbRepo extends be_db_common_1.DbRepo {
|
|
|
312
337
|
return __awaiter(this, void 0, void 0, function* () {
|
|
313
338
|
var _a;
|
|
314
339
|
const { useSoftDelete, useNumericId, conn, full } = this._props;
|
|
340
|
+
if (!conn.props.enabled) {
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
315
343
|
if (!ignoreCheck) {
|
|
316
344
|
if (useNumericId) {
|
|
317
345
|
(0, type_1.assertInteger)(key, { field: 'key', where: 'CbRepo', method: '$existsBySecondary' });
|
|
@@ -337,13 +365,16 @@ class CbRepo extends be_db_common_1.DbRepo {
|
|
|
337
365
|
/** @inheritDoc */
|
|
338
366
|
$listByPrimary(keys, p1, ignoreCheck) {
|
|
339
367
|
return __awaiter(this, void 0, void 0, function* () {
|
|
368
|
+
const { useSoftDelete, conn, full } = this._props;
|
|
369
|
+
if (!conn.props.enabled) {
|
|
370
|
+
return [];
|
|
371
|
+
}
|
|
340
372
|
if (!ignoreCheck) {
|
|
341
373
|
(0, type_2.assertArray)(keys, { field: 'keys', where: 'CbRepo', method: '$listByPrimary' });
|
|
342
374
|
keys.forEach((key, index) => {
|
|
343
375
|
(0, type_2.assertText)(key, { field: 'key', where: 'CbRepo', method: '$listByPrimary', index });
|
|
344
376
|
});
|
|
345
377
|
}
|
|
346
|
-
const { useSoftDelete, conn, full } = this._props;
|
|
347
378
|
const opt = conn.buildOpt(p1, '$listByIds');
|
|
348
379
|
const lines = (0, be_db_common_1.dbLines)();
|
|
349
380
|
lines
|
|
@@ -359,6 +390,9 @@ class CbRepo extends be_db_common_1.DbRepo {
|
|
|
359
390
|
$listBySecondary(keys, p1, ignoreCheck) {
|
|
360
391
|
return __awaiter(this, void 0, void 0, function* () {
|
|
361
392
|
const { useSoftDelete, useNumericId, conn, full } = this._props;
|
|
393
|
+
if (!conn.props.enabled) {
|
|
394
|
+
return [];
|
|
395
|
+
}
|
|
362
396
|
if (!ignoreCheck) {
|
|
363
397
|
(0, type_2.assertArray)(keys, { field: 'keys', where: 'CbRepo', method: '$listBySecondary' });
|
|
364
398
|
keys.forEach((key, index) => {
|
|
@@ -387,6 +421,9 @@ class CbRepo extends be_db_common_1.DbRepo {
|
|
|
387
421
|
$filter(query, p1) {
|
|
388
422
|
return __awaiter(this, void 0, void 0, function* () {
|
|
389
423
|
const { useSoftDelete, conn, full } = this._props;
|
|
424
|
+
if (!conn.props.enabled) {
|
|
425
|
+
return [];
|
|
426
|
+
}
|
|
390
427
|
const opt = conn.buildOpt(p1, '$filter');
|
|
391
428
|
// @todo - work for query builder
|
|
392
429
|
const lines = (0, be_db_common_1.dbLines)();
|
|
@@ -402,18 +439,25 @@ class CbRepo extends be_db_common_1.DbRepo {
|
|
|
402
439
|
/** @inheritDoc */
|
|
403
440
|
$insert(doc, p1, ignoreCheck) {
|
|
404
441
|
return __awaiter(this, void 0, void 0, function* () {
|
|
405
|
-
const { conn, collection, useNumericId } = this._props;
|
|
442
|
+
const { conn, collection, noInsert, useNumericId } = this._props;
|
|
443
|
+
if (!conn.props.enabled) {
|
|
444
|
+
return undefined;
|
|
445
|
+
}
|
|
446
|
+
const opt = conn.buildOpt(p1, '$insert');
|
|
447
|
+
const param = { where: 'CbRepo', method: '$insert', queryName: opt.name };
|
|
448
|
+
if (noInsert) {
|
|
449
|
+
throw new be_db_common_1.DbNotSupportedError('Insert', param);
|
|
450
|
+
}
|
|
406
451
|
if (!ignoreCheck) {
|
|
407
|
-
(0, type_2.assertObject)(doc, { field: 'doc'
|
|
408
|
-
(0, type_2.assertText)(doc._urn, { field: 'doc._urn'
|
|
452
|
+
(0, type_2.assertObject)(doc, Object.assign({ field: 'doc' }, param));
|
|
453
|
+
(0, type_2.assertText)(doc._urn, Object.assign({ field: 'doc._urn' }, param));
|
|
409
454
|
if (useNumericId) {
|
|
410
|
-
(0, type_1.assertInteger)(doc.id, { field: 'doc.id'
|
|
455
|
+
(0, type_1.assertInteger)(doc.id, Object.assign({ field: 'doc.id' }, param));
|
|
411
456
|
}
|
|
412
457
|
else {
|
|
413
|
-
(0, type_2.assertText)(doc.id, { field: 'doc.id'
|
|
458
|
+
(0, type_2.assertText)(doc.id, Object.assign({ field: 'doc.id' }, param));
|
|
414
459
|
}
|
|
415
460
|
}
|
|
416
|
-
const opt = conn.buildOpt(p1, '$insert');
|
|
417
461
|
yield conn.exec(collection.insert(doc._urn, doc), opt);
|
|
418
462
|
return doc._urn;
|
|
419
463
|
});
|
|
@@ -423,33 +467,75 @@ class CbRepo extends be_db_common_1.DbRepo {
|
|
|
423
467
|
/** @inheritDoc */
|
|
424
468
|
$replace(doc, p1, ignoreCheck) {
|
|
425
469
|
return __awaiter(this, void 0, void 0, function* () {
|
|
426
|
-
const { conn, collection, useNumericId } = this._props;
|
|
470
|
+
const { conn, collection, noUpdate, useNumericId } = this._props;
|
|
471
|
+
if (!conn.props.enabled) {
|
|
472
|
+
return undefined;
|
|
473
|
+
}
|
|
474
|
+
const opt = conn.buildOpt(p1, '$replace');
|
|
475
|
+
const param = { where: 'CbRepo', method: '$replace', queryName: opt.name };
|
|
476
|
+
if (noUpdate) {
|
|
477
|
+
throw new be_db_common_1.DbNotSupportedError('Update', param);
|
|
478
|
+
}
|
|
427
479
|
if (!ignoreCheck) {
|
|
428
|
-
(0, type_2.assertObject)(doc, { field: 'doc'
|
|
429
|
-
(0, type_2.assertText)(doc._urn, { field: 'doc._urn'
|
|
480
|
+
(0, type_2.assertObject)(doc, Object.assign({ field: 'doc' }, param));
|
|
481
|
+
(0, type_2.assertText)(doc._urn, Object.assign({ field: 'doc._urn' }, param));
|
|
430
482
|
if (useNumericId) {
|
|
431
|
-
(0, type_1.assertInteger)(doc.id, { field: 'doc.id'
|
|
483
|
+
(0, type_1.assertInteger)(doc.id, Object.assign({ field: 'doc.id' }, param));
|
|
432
484
|
}
|
|
433
485
|
else {
|
|
434
|
-
(0, type_2.assertText)(doc.id, { field: 'doc.id'
|
|
486
|
+
(0, type_2.assertText)(doc.id, Object.assign({ field: 'doc.id' }, param));
|
|
435
487
|
}
|
|
436
488
|
}
|
|
437
|
-
const opt = conn.buildOpt(p1, '$replace');
|
|
438
489
|
yield conn.exec(collection.replace(doc._urn, doc), opt);
|
|
439
490
|
return doc._urn;
|
|
440
491
|
});
|
|
441
492
|
}
|
|
442
493
|
// endregion replace
|
|
494
|
+
// region upsert
|
|
495
|
+
/** @inheritDoc */
|
|
496
|
+
$upsert(doc, p1, ignoreCheck) {
|
|
497
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
498
|
+
const { conn, collection, noUpdate, noInsert, useNumericId } = this._props;
|
|
499
|
+
if (!conn.props.enabled) {
|
|
500
|
+
return undefined;
|
|
501
|
+
}
|
|
502
|
+
const opt = conn.buildOpt(p1, '$upsert');
|
|
503
|
+
const param = { where: 'CbRepo', method: '$upsert', queryName: opt.name };
|
|
504
|
+
if (noUpdate || noInsert) {
|
|
505
|
+
throw new be_db_common_1.DbNotSupportedError('Upsert', param);
|
|
506
|
+
}
|
|
507
|
+
if (!ignoreCheck) {
|
|
508
|
+
(0, type_2.assertObject)(doc, Object.assign({ field: 'doc' }, param));
|
|
509
|
+
(0, type_2.assertText)(doc._urn, Object.assign({ field: 'doc._urn' }, param));
|
|
510
|
+
if (useNumericId) {
|
|
511
|
+
(0, type_1.assertInteger)(doc.id, Object.assign({ field: 'doc.id' }, param));
|
|
512
|
+
}
|
|
513
|
+
else {
|
|
514
|
+
(0, type_2.assertText)(doc.id, Object.assign({ field: 'doc.id' }, param));
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
yield conn.exec(collection.upsert(doc._urn, doc), opt);
|
|
518
|
+
return doc._urn;
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
// endregion upsert
|
|
443
522
|
// region update
|
|
444
523
|
/** @inheritDoc */
|
|
445
524
|
$updateByPrimary(key, doc, p1, ignoreCheck) {
|
|
446
525
|
return __awaiter(this, void 0, void 0, function* () {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
526
|
+
const { conn, full, noUpdate, useSoftDelete } = this._props;
|
|
527
|
+
if (!conn.props.enabled) {
|
|
528
|
+
return undefined;
|
|
450
529
|
}
|
|
451
|
-
const { conn, full, useSoftDelete } = this._props;
|
|
452
530
|
const opt = conn.buildOpt(p1, '$updateByPrimary');
|
|
531
|
+
const param = { where: 'CbRepo', method: '$updateByPrimary', queryName: opt.name };
|
|
532
|
+
if (noUpdate) {
|
|
533
|
+
throw new be_db_common_1.DbNotSupportedError('Update', param);
|
|
534
|
+
}
|
|
535
|
+
if (!ignoreCheck) {
|
|
536
|
+
(0, type_2.assertText)(key, Object.assign({ field: 'key' }, param));
|
|
537
|
+
(0, type_2.assertObject)(doc, Object.assign({ field: 'doc' }, param));
|
|
538
|
+
}
|
|
453
539
|
const parameters = {};
|
|
454
540
|
let paramId = 0;
|
|
455
541
|
const set = [];
|
|
@@ -487,17 +573,24 @@ class CbRepo extends be_db_common_1.DbRepo {
|
|
|
487
573
|
$updateBySecondary(key, doc, p1, ignoreCheck) {
|
|
488
574
|
return __awaiter(this, void 0, void 0, function* () {
|
|
489
575
|
var _a;
|
|
490
|
-
const { useNumericId, useSoftDelete, conn, full } = this._props;
|
|
576
|
+
const { useNumericId, noUpdate, useSoftDelete, conn, full } = this._props;
|
|
577
|
+
if (!conn.props.enabled) {
|
|
578
|
+
return undefined;
|
|
579
|
+
}
|
|
580
|
+
const opt = conn.buildOpt(p1, '$updateBySecondary');
|
|
581
|
+
const param = { where: 'CbRepo', method: '$updateBySecondary', queryName: opt.name };
|
|
582
|
+
if (noUpdate) {
|
|
583
|
+
throw new be_db_common_1.DbNotSupportedError('Update', param);
|
|
584
|
+
}
|
|
491
585
|
if (!ignoreCheck) {
|
|
492
586
|
if (useNumericId) {
|
|
493
|
-
(0, type_1.assertInteger)(key, { field: 'key'
|
|
587
|
+
(0, type_1.assertInteger)(key, Object.assign({ field: 'key' }, param));
|
|
494
588
|
}
|
|
495
589
|
else {
|
|
496
|
-
(0, type_2.assertText)(key, { field: 'key'
|
|
590
|
+
(0, type_2.assertText)(key, Object.assign({ field: 'key' }, param));
|
|
497
591
|
}
|
|
498
|
-
(0, type_2.assertObject)(doc, { field: 'doc'
|
|
592
|
+
(0, type_2.assertObject)(doc, Object.assign({ field: 'doc' }, param));
|
|
499
593
|
}
|
|
500
|
-
const opt = conn.buildOpt(p1, '$updateBySecondary');
|
|
501
594
|
const parameters = {};
|
|
502
595
|
let paramId = 0;
|
|
503
596
|
const set = [];
|
|
@@ -536,11 +629,18 @@ class CbRepo extends be_db_common_1.DbRepo {
|
|
|
536
629
|
/** @inheritDoc */
|
|
537
630
|
$removeByPrimary(key, p1, ignoreCheck) {
|
|
538
631
|
return __awaiter(this, void 0, void 0, function* () {
|
|
539
|
-
|
|
540
|
-
|
|
632
|
+
const { useSoftDelete, noRemove, conn, full, collection } = this._props;
|
|
633
|
+
if (!conn.props.enabled) {
|
|
634
|
+
return undefined;
|
|
541
635
|
}
|
|
542
|
-
const { useSoftDelete, conn, full, collection } = this._props;
|
|
543
636
|
const opt = conn.buildOpt(p1, '$removeByPrimary');
|
|
637
|
+
const param = { where: 'CbRepo', method: '$removeByPrimary', queryName: opt.name };
|
|
638
|
+
if (noRemove) {
|
|
639
|
+
throw new be_db_common_1.DbNotSupportedError('Remove', param);
|
|
640
|
+
}
|
|
641
|
+
if (!ignoreCheck) {
|
|
642
|
+
(0, type_2.assertText)(key, Object.assign({ field: 'key' }, param));
|
|
643
|
+
}
|
|
544
644
|
if (!useSoftDelete) {
|
|
545
645
|
yield conn.exec(collection.remove(key, opt), opt);
|
|
546
646
|
return key;
|
|
@@ -560,16 +660,23 @@ class CbRepo extends be_db_common_1.DbRepo {
|
|
|
560
660
|
$removeBySecondary(key, p1, ignoreCheck) {
|
|
561
661
|
return __awaiter(this, void 0, void 0, function* () {
|
|
562
662
|
var _a;
|
|
563
|
-
const { useNumericId, useSoftDelete, conn, full } = this._props;
|
|
663
|
+
const { useNumericId, noRemove, useSoftDelete, conn, full } = this._props;
|
|
664
|
+
if (!conn.props.enabled) {
|
|
665
|
+
return undefined;
|
|
666
|
+
}
|
|
667
|
+
const opt = conn.buildOpt(p1, '$removeBySecondary');
|
|
668
|
+
const param = { where: 'CbRepo', method: '$removeBySecondary', queryName: opt.name };
|
|
669
|
+
if (noRemove) {
|
|
670
|
+
throw new be_db_common_1.DbNotSupportedError('Remove', param);
|
|
671
|
+
}
|
|
564
672
|
if (!ignoreCheck) {
|
|
565
673
|
if (useNumericId) {
|
|
566
|
-
(0, type_1.assertInteger)(key, { field: 'key'
|
|
674
|
+
(0, type_1.assertInteger)(key, Object.assign({ field: 'key' }, param));
|
|
567
675
|
}
|
|
568
676
|
else {
|
|
569
|
-
(0, type_2.assertText)(key, { field: 'key'
|
|
677
|
+
(0, type_2.assertText)(key, Object.assign({ field: 'key' }, param));
|
|
570
678
|
}
|
|
571
679
|
}
|
|
572
|
-
const opt = conn.buildOpt(p1, '$removeBySecondary');
|
|
573
680
|
const lines = (0, be_db_common_1.dbLines)();
|
|
574
681
|
lines
|
|
575
682
|
.add('DELETE')
|
|
@@ -586,14 +693,21 @@ class CbRepo extends be_db_common_1.DbRepo {
|
|
|
586
693
|
/** @inheritDoc */
|
|
587
694
|
$trashByPrimary(key, p1, ignoreCheck) {
|
|
588
695
|
return __awaiter(this, void 0, void 0, function* () {
|
|
589
|
-
const { useSoftDelete, conn, full } = this._props;
|
|
696
|
+
const { useSoftDelete, noTrash, conn, full } = this._props;
|
|
697
|
+
if (!conn.props.enabled) {
|
|
698
|
+
return undefined;
|
|
699
|
+
}
|
|
700
|
+
const opt = conn.buildOpt(p1, '$trashByPrimary');
|
|
701
|
+
const param = { where: 'CbRepo', method: '$trashByPrimary', queryName: opt.name };
|
|
702
|
+
if (noTrash) {
|
|
703
|
+
throw new be_db_common_1.DbNotSupportedError('Trash', param);
|
|
704
|
+
}
|
|
590
705
|
if (!useSoftDelete) {
|
|
591
|
-
throw new be_db_common_1.DbNotSupportedError('Soft delete',
|
|
706
|
+
throw new be_db_common_1.DbNotSupportedError('Soft delete', param);
|
|
592
707
|
}
|
|
593
708
|
if (!ignoreCheck) {
|
|
594
|
-
(0, type_2.assertText)(key, { field: 'key'
|
|
709
|
+
(0, type_2.assertText)(key, Object.assign({ field: 'key' }, param));
|
|
595
710
|
}
|
|
596
|
-
const opt = conn.buildOpt(p1, '$trashByPrimary');
|
|
597
711
|
const lines = (0, be_db_common_1.dbLines)();
|
|
598
712
|
lines
|
|
599
713
|
.add(`UPDATE ${full} a`)
|
|
@@ -615,19 +729,26 @@ class CbRepo extends be_db_common_1.DbRepo {
|
|
|
615
729
|
$trashBySecondary(key, p1, ignoreCheck) {
|
|
616
730
|
return __awaiter(this, void 0, void 0, function* () {
|
|
617
731
|
var _a;
|
|
618
|
-
const { useSoftDelete, useNumericId, conn, full } = this._props;
|
|
732
|
+
const { useSoftDelete, noTrash, useNumericId, conn, full } = this._props;
|
|
733
|
+
if (!conn.props.enabled) {
|
|
734
|
+
return undefined;
|
|
735
|
+
}
|
|
736
|
+
const opt = conn.buildOpt(p1, '$trashBySecondary');
|
|
737
|
+
const param = { where: 'CbRepo', method: '$trashBySecondary', queryName: opt.name };
|
|
738
|
+
if (noTrash) {
|
|
739
|
+
throw new be_db_common_1.DbNotSupportedError('Trash', param);
|
|
740
|
+
}
|
|
619
741
|
if (!useSoftDelete) {
|
|
620
|
-
throw new be_db_common_1.DbNotSupportedError('Soft delete',
|
|
742
|
+
throw new be_db_common_1.DbNotSupportedError('Soft delete', param);
|
|
621
743
|
}
|
|
622
744
|
if (!ignoreCheck) {
|
|
623
745
|
if (useNumericId) {
|
|
624
|
-
(0, type_1.assertInteger)(key, { field: 'key'
|
|
746
|
+
(0, type_1.assertInteger)(key, Object.assign({ field: 'key' }, param));
|
|
625
747
|
}
|
|
626
748
|
else {
|
|
627
|
-
(0, type_2.assertText)(key, { field: 'key'
|
|
749
|
+
(0, type_2.assertText)(key, Object.assign({ field: 'key' }, param));
|
|
628
750
|
}
|
|
629
751
|
}
|
|
630
|
-
const opt = conn.buildOpt(p1, '$trashBySecondary');
|
|
631
752
|
const lines = (0, be_db_common_1.dbLines)();
|
|
632
753
|
lines
|
|
633
754
|
.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
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
7
|
import type { KeyValue, StrKey } 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
|
-
}
|
|
17
8
|
/**
|
|
18
9
|
* Couchbase repository (collection) interface
|
|
19
|
-
*
|
|
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<
|
|
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
|
-
|
|
27
|
+
inserts(docs: Array<ENT>, opt?: CbInsertOpt | string, ignoreCheck?: boolean): Promise<Array<string>>;
|
|
24
28
|
/** @inheritDoc */
|
|
25
|
-
insert(doc:
|
|
29
|
+
$insert(doc: ENT, opt?: CbInsertOpt | string, ignoreCheck?: boolean): Promise<string>;
|
|
26
30
|
/** @inheritDoc */
|
|
27
|
-
|
|
31
|
+
replace(doc: ENT, opt?: CbReplaceOpt | string, ignoreCheck?: boolean): Promise<string>;
|
|
28
32
|
/** @inheritDoc */
|
|
29
|
-
$
|
|
33
|
+
$replace(doc: ENT, opt?: CbReplaceOpt | string, ignoreCheck?: boolean): Promise<string>;
|
|
30
34
|
/** @inheritDoc */
|
|
31
|
-
|
|
35
|
+
upsert(doc: ENT, opt?: CbUpsertOpt | string, ignoreCheck?: boolean): Promise<string>;
|
|
32
36
|
/** @inheritDoc */
|
|
33
|
-
$
|
|
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<ENTITY extends Entity<ID>, ID extends KeyValue = Key
|
|
|
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<
|
|
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<ENTITY extends Entity<ID>, ID extends KeyValue = KeyV
|
|
|
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<
|
|
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<ENTITY extends Entity<ID>, ID extends KeyValue = Ke
|
|
|
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<
|
|
127
|
+
export interface CbRepoPropsPart<SPEC> {
|
|
113
128
|
/**
|
|
114
129
|
* Extended property to hold couchbase specs
|
|
115
130
|
* */
|
|
116
|
-
readonly $spec?:
|
|
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<
|
|
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<ENTITY extends Entity<ID>, ID extends KeyValue
|
|
|
130
152
|
/**
|
|
131
153
|
* Overridable method to easy use
|
|
132
154
|
* */
|
|
133
|
-
toDim?: DbRepoToDim<R,
|
|
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.
|
|
3
|
+
"version": "1.1.8",
|
|
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.
|
|
70
|
-
"@leyyo/env": "^1.2.
|
|
69
|
+
"@leyyo/common": "^1.2.4",
|
|
70
|
+
"@leyyo/env": "^1.2.5",
|
|
71
71
|
"@leyyo/query": "^1.2.1",
|
|
72
72
|
"@leyyo/type": "^1.1.1",
|
|
73
|
-
"@samet-it/be-base-common": "^1.1.
|
|
74
|
-
"@samet-it/be-cache-common": "^1.1.
|
|
75
|
-
"@samet-it/be-db-common": "^1.1.
|
|
73
|
+
"@samet-it/be-base-common": "^1.1.4",
|
|
74
|
+
"@samet-it/be-cache-common": "^1.1.6",
|
|
75
|
+
"@samet-it/be-db-common": "^1.1.5",
|
|
76
76
|
"couchbase": "^4.6.0"
|
|
77
77
|
}
|
|
78
78
|
}
|