@samet-it/be-couchbase-common 1.0.1

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.
Files changed (39) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +90 -0
  3. package/dist/adapter/cb-adapter.module.d.ts +2 -0
  4. package/dist/adapter/cb-adapter.module.js +23 -0
  5. package/dist/adapter/cb-adapter.service.d.ts +70 -0
  6. package/dist/adapter/cb-adapter.service.js +447 -0
  7. package/dist/adapter/index.d.ts +3 -0
  8. package/dist/adapter/index.js +19 -0
  9. package/dist/adapter/index.types.d.ts +163 -0
  10. package/dist/adapter/index.types.js +2 -0
  11. package/dist/assets/.gitkeep +0 -0
  12. package/dist/assets/source.MD +1 -0
  13. package/dist/config/couchbase-common.config.d.ts +2 -0
  14. package/dist/config/couchbase-common.config.js +13 -0
  15. package/dist/config/index.d.ts +2 -0
  16. package/dist/config/index.js +18 -0
  17. package/dist/config/index.types.d.ts +31 -0
  18. package/dist/config/index.types.js +2 -0
  19. package/dist/filter/cb-filter-util.impl.d.ts +2 -0
  20. package/dist/filter/cb-filter-util.impl.js +88 -0
  21. package/dist/filter/index.d.ts +2 -0
  22. package/dist/filter/index.js +18 -0
  23. package/dist/filter/index.types.d.ts +32 -0
  24. package/dist/filter/index.types.js +2 -0
  25. package/dist/index.d.ts +6 -0
  26. package/dist/index.js +25 -0
  27. package/dist/line/cb-line.impl.d.ts +2 -0
  28. package/dist/line/cb-line.impl.js +90 -0
  29. package/dist/line/index.d.ts +2 -0
  30. package/dist/line/index.js +18 -0
  31. package/dist/line/index.types.d.ts +58 -0
  32. package/dist/line/index.types.js +2 -0
  33. package/dist/repo/cb.repo.d.ts +95 -0
  34. package/dist/repo/cb.repo.js +375 -0
  35. package/dist/repo/index.d.ts +2 -0
  36. package/dist/repo/index.js +18 -0
  37. package/dist/repo/index.types.d.ts +144 -0
  38. package/dist/repo/index.types.js +2 -0
  39. package/package.json +75 -0
@@ -0,0 +1,95 @@
1
+ import { CbAdapterService, type CbEntity, type CbError, type CbExecMutationOpt, type CbExecOpt, type CbExecTrashOpt } from "../adapter";
2
+ import { Bucket, Cluster, Collection, type QueryOptions, Scope } from "couchbase";
3
+ import type { CbRepoDef, CbRepoLike } from "./index.types";
4
+ export declare abstract class CbRepo<E extends CbEntity, ID> implements CbRepoLike<E, ID> {
5
+ protected colName: string;
6
+ protected cb: CbAdapterService;
7
+ private _scopeName?;
8
+ private _bucketName?;
9
+ /** @inheritDoc */
10
+ readonly fullPath: string;
11
+ /** @inheritDoc */
12
+ readonly path: string;
13
+ /** @inheritDoc */
14
+ readonly cluster: Cluster;
15
+ /** @inheritDoc */
16
+ readonly bucket: Bucket;
17
+ /** @inheritDoc */
18
+ readonly scope: Scope;
19
+ /** @inheritDoc */
20
+ readonly collection: Collection;
21
+ protected constructor(colName: string, cb: CbAdapterService, _scopeName?: string, _bucketName?: string);
22
+ protected _pushIgnoredError<O extends CbExecMutationOpt>(opt: O, err: CbError): O;
23
+ /**
24
+ * Fetch urn from doc as doc._urn
25
+ * */
26
+ protected _urnFromDoc(doc: Partial<E>, method: string): string;
27
+ /**
28
+ * Check array keys as id list or urn list
29
+ * */
30
+ protected _checkKeys<I extends string | number = string>(keys: I[]): I[];
31
+ /**
32
+ * Build update sql as set and unset
33
+ * */
34
+ protected _updateSql<T>(urn: string, doc: T): string;
35
+ /**
36
+ * Create indices
37
+ * */
38
+ protected abstract _createIndices(): Promise<void>;
39
+ /** @inheritDoc */
40
+ get def(): CbRepoDef;
41
+ /** @inheritDoc */
42
+ abstract urn(part: ID): string;
43
+ /** @inheritDoc */
44
+ onModuleInit(): Promise<void>;
45
+ /** @inheritDoc */
46
+ urnByIdExtended(id: string, query: QueryOptions, opt?: CbExecOpt): Promise<string | undefined>;
47
+ /** @inheritDoc */
48
+ urnById(id: string, opt?: CbExecOpt): Promise<string | undefined>;
49
+ /** @inheritDoc */
50
+ existsByUrn(urn: string, opt?: CbExecOpt): Promise<boolean>;
51
+ /** @inheritDoc */
52
+ existsByUrnExtended(urn: string, query: QueryOptions, opt?: CbExecOpt): Promise<boolean>;
53
+ /** @inheritDoc */
54
+ existsById(id: string, opt?: CbExecOpt): Promise<boolean>;
55
+ /** @inheritDoc */
56
+ existsByIdExtended(id: string, query: QueryOptions, opt?: CbExecOpt): Promise<boolean>;
57
+ /** @inheritDoc */
58
+ getByUrn(urn: string, opt?: CbExecOpt): Promise<E | undefined>;
59
+ /** @inheritDoc */
60
+ getByUrnExtended(urn: string, query: QueryOptions, opt?: CbExecOpt): Promise<E | undefined>;
61
+ /** @inheritDoc */
62
+ getById(id: string, opt?: CbExecOpt): Promise<E | undefined>;
63
+ /** @inheritDoc */
64
+ getByIdExtended(id: string, query: QueryOptions, opt?: CbExecOpt): Promise<E | undefined>;
65
+ /** @inheritDoc */
66
+ listByUrn(urnList: string[], opt?: CbExecOpt): Promise<Array<E>>;
67
+ /** @inheritDoc */
68
+ listByUrnExtended(urnList: string[], query: QueryOptions, opt?: CbExecOpt): Promise<Array<E>>;
69
+ /** @inheritDoc */
70
+ listById(ids: string[], opt?: CbExecOpt): Promise<Array<E>>;
71
+ /** @inheritDoc */
72
+ listByIdExtended(ids: string[], query: QueryOptions, opt?: CbExecOpt): Promise<Array<E>>;
73
+ /** @inheritDoc */
74
+ removeByUrn(urn: string, opt?: CbExecOpt): Promise<string>;
75
+ /** @inheritDoc */
76
+ removeByUrnExtended(urn: string, query: QueryOptions, opt?: CbExecOpt): Promise<string>;
77
+ /** @inheritDoc */
78
+ removeById(id: string, opt?: CbExecOpt): Promise<string>;
79
+ /** @inheritDoc */
80
+ removeByIdExtended(id: string, query: QueryOptions, opt?: CbExecOpt): Promise<string>;
81
+ /** @inheritDoc */
82
+ insert(doc: E, opt?: CbExecMutationOpt): Promise<string>;
83
+ /** @inheritDoc */
84
+ replace(doc: E, opt?: CbExecMutationOpt): Promise<string>;
85
+ /** @inheritDoc */
86
+ upsert(doc: E, opt?: CbExecMutationOpt): Promise<string>;
87
+ /** @inheritDoc */
88
+ update(doc: Partial<E>, opt?: CbExecOpt): Promise<unknown>;
89
+ /** @inheritDoc */
90
+ updateExtended(doc: Partial<E>, query: QueryOptions, opt?: CbExecOpt): Promise<unknown>;
91
+ /** @inheritDoc */
92
+ trash(doc: E, opt?: CbExecTrashOpt): Promise<unknown>;
93
+ /** @inheritDoc */
94
+ trashExtended(doc: E, query: QueryOptions, opt?: CbExecTrashOpt): Promise<unknown>;
95
+ }
@@ -0,0 +1,375 @@
1
+ "use strict";
2
+ // ~~console.log(__filename);
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.CbRepo = void 0;
14
+ const common_1 = require("@leyyo/common");
15
+ const config_1 = require("../config");
16
+ const line_1 = require("../line");
17
+ const node_crypto_1 = require("node:crypto");
18
+ let F_ID;
19
+ let F_URN;
20
+ let F_TRASH_ID;
21
+ // noinspection JSUnusedGlobalSymbols
22
+ class CbRepo {
23
+ constructor(colName, cb, _scopeName, _bucketName) {
24
+ this.colName = colName;
25
+ this.cb = cb;
26
+ this._scopeName = _scopeName;
27
+ this._bucketName = _bucketName;
28
+ if (!F_ID) {
29
+ F_ID = this.cb.f('id');
30
+ F_URN = this.cb.f('_urn');
31
+ F_TRASH_ID = this.cb.f('_trashId');
32
+ }
33
+ }
34
+ // noinspection JSUnusedLocalSymbols
35
+ _pushIgnoredError(opt, err) {
36
+ if (!opt) {
37
+ opt = { ignoredErrors: [err] };
38
+ }
39
+ else if (!Array.isArray(opt.ignoredErrors)) {
40
+ opt.ignoredErrors = [err];
41
+ }
42
+ else if (!opt.ignoredErrors.includes(err)) {
43
+ opt.ignoredErrors.push(err);
44
+ }
45
+ return opt;
46
+ }
47
+ /**
48
+ * Fetch urn from doc as doc._urn
49
+ * */
50
+ _urnFromDoc(doc, method) {
51
+ common_1.$assert.object(doc, () => {
52
+ return { field: 'doc', where: 'CbRepo', path: this.path, method };
53
+ });
54
+ const urn = doc._urn;
55
+ common_1.$assert.text(urn, () => {
56
+ return { field: 'urn', where: 'CbRepo', path: this.path, method };
57
+ });
58
+ return urn;
59
+ }
60
+ /**
61
+ * Check array keys as id list or urn list
62
+ * */
63
+ _checkKeys(keys) {
64
+ if (!keys || !Array.isArray(keys) || keys.length < 1) {
65
+ return [];
66
+ }
67
+ return keys
68
+ .map(item => {
69
+ switch (typeof item) {
70
+ case "string":
71
+ const str = item.trim();
72
+ return str ? str : undefined;
73
+ case "number":
74
+ return item;
75
+ default:
76
+ return undefined;
77
+ }
78
+ })
79
+ .filter(item => item !== undefined);
80
+ }
81
+ /**
82
+ * Build update sql as set and unset
83
+ * */
84
+ _updateSql(urn, doc) {
85
+ const set = [];
86
+ const unset = [];
87
+ for (const [k, v] of Object.entries(doc)) {
88
+ if (!['_urn', 'id'].includes(k)) {
89
+ if (v === undefined) {
90
+ unset.push(this.cb.f(k));
91
+ }
92
+ else {
93
+ set.push([this.cb.f(k), this.cb.v(v)]);
94
+ }
95
+ }
96
+ }
97
+ const lines = (0, line_1.cbLine)();
98
+ lines
99
+ .add(`UPDATE ${this.fullPath}`)
100
+ .add(`USE KEYS ${this.cb.s(urn)}`);
101
+ if (unset.length > 0) {
102
+ lines.add('UNSET ', unset.join(', '));
103
+ }
104
+ if (set.length > 0) {
105
+ lines.add('SET ', set.join(',\n '));
106
+ }
107
+ lines.add(`RETURNING meta().id ${F_URN}`);
108
+ return lines.end();
109
+ }
110
+ /** @inheritDoc */
111
+ get def() {
112
+ return this;
113
+ }
114
+ /** @inheritDoc */
115
+ onModuleInit() {
116
+ return __awaiter(this, void 0, void 0, function* () {
117
+ var _a, _b;
118
+ const mutable = this;
119
+ mutable.cluster = yield this.cb.connectDb();
120
+ mutable.bucket = this.cluster.bucket((_a = this._bucketName) !== null && _a !== void 0 ? _a : config_1.couchbaseCommonConfig.raw.CB_BUCKET);
121
+ mutable.scope = this.bucket.scope((_b = this._scopeName) !== null && _b !== void 0 ? _b : config_1.couchbaseCommonConfig.raw.CB_SCOPE);
122
+ mutable.collection = this.scope.collection(this.colName);
123
+ mutable.path = `${this.bucket.name}.${this.scope.name}.${this.collection.name}`;
124
+ mutable.fullPath = this.cb.f(`${this.bucket.name}.${this.scope.name}.${this.collection.name}`);
125
+ if (config_1.couchbaseCommonConfig.raw.CB_CREATE_INDICES) {
126
+ yield this._createIndices();
127
+ }
128
+ });
129
+ }
130
+ /** @inheritDoc */
131
+ urnByIdExtended(id, query, opt) {
132
+ return __awaiter(this, void 0, void 0, function* () {
133
+ var _a;
134
+ const lines = (0, line_1.cbLine)();
135
+ lines
136
+ .add(`SELECT meta().id as ${F_URN}`)
137
+ .add(`FROM ${this.fullPath} a`)
138
+ .add(`WHERE (a.${F_ID} = ${this.cb.s(id)})`)
139
+ .add(`AND (a.${F_TRASH_ID} is missing)`)
140
+ .add('LIMIT 1');
141
+ return (_a = (yield this.cb.execFirstExtended(this, lines.end(), query, opt))) === null || _a === void 0 ? void 0 : _a._urn;
142
+ });
143
+ }
144
+ /** @inheritDoc */
145
+ urnById(id, opt) {
146
+ return __awaiter(this, void 0, void 0, function* () {
147
+ return this.urnByIdExtended(id, undefined, opt);
148
+ });
149
+ }
150
+ /** @inheritDoc */
151
+ existsByUrn(urn, opt) {
152
+ return __awaiter(this, void 0, void 0, function* () {
153
+ return this.existsByUrnExtended(urn, undefined, opt);
154
+ });
155
+ }
156
+ /** @inheritDoc */
157
+ existsByUrnExtended(urn, query, opt) {
158
+ return __awaiter(this, void 0, void 0, function* () {
159
+ var _a;
160
+ const lines = (0, line_1.cbLine)();
161
+ lines
162
+ .add(`SELECT meta().id as ${F_URN}`)
163
+ .add(`FROM ${this.fullPath} a`)
164
+ .add(`WHERE (a.${F_TRASH_ID} is missing)`)
165
+ .add(`USE KEYS ${this.cb.s(urn)}`)
166
+ .add('LIMIT 1');
167
+ return ((_a = (yield this.cb.execFirstExtended(this, lines.end(), query, opt))) === null || _a === void 0 ? void 0 : _a._urn) !== undefined;
168
+ });
169
+ }
170
+ /** @inheritDoc */
171
+ existsById(id, opt) {
172
+ return __awaiter(this, void 0, void 0, function* () {
173
+ return (yield this.urnByIdExtended(id, undefined, opt)) !== undefined;
174
+ });
175
+ }
176
+ /** @inheritDoc */
177
+ existsByIdExtended(id, query, opt) {
178
+ return __awaiter(this, void 0, void 0, function* () {
179
+ return (yield this.urnByIdExtended(id, query, opt)) !== undefined;
180
+ });
181
+ }
182
+ /** @inheritDoc */
183
+ getByUrn(urn, opt) {
184
+ return __awaiter(this, void 0, void 0, function* () {
185
+ return this.getByUrnExtended(urn, undefined, opt);
186
+ });
187
+ }
188
+ /** @inheritDoc */
189
+ getByUrnExtended(urn, query, opt) {
190
+ return __awaiter(this, void 0, void 0, function* () {
191
+ const lines = (0, line_1.cbLine)();
192
+ lines
193
+ .add(`SELECT a.*`)
194
+ .add(`FROM ${this.fullPath} a`)
195
+ .add(`WHERE (a.${F_TRASH_ID} is missing)`)
196
+ .add(`USE KEYS ${this.cb.s(urn)}`)
197
+ .add('LIMIT 1');
198
+ return this.cb.execFirstExtended(this, lines.end(), query, opt);
199
+ });
200
+ }
201
+ /** @inheritDoc */
202
+ getById(id, opt) {
203
+ return __awaiter(this, void 0, void 0, function* () {
204
+ return this.getByIdExtended(id, undefined, opt);
205
+ });
206
+ }
207
+ /** @inheritDoc */
208
+ getByIdExtended(id, query, opt) {
209
+ return __awaiter(this, void 0, void 0, function* () {
210
+ const lines = (0, line_1.cbLine)();
211
+ lines
212
+ .add(`SELECT a.*`)
213
+ .add(`FROM ${this.fullPath} a`)
214
+ .add(`WHERE (a.${F_ID} = ${this.cb.s(id)})`)
215
+ .add(`AND (a.${F_TRASH_ID} is missing)`)
216
+ .add('LIMIT 1');
217
+ return this.cb.first(yield this.cb.execExtended(this, lines.end(), query, opt));
218
+ });
219
+ }
220
+ /** @inheritDoc */
221
+ listByUrn(urnList, opt) {
222
+ return __awaiter(this, void 0, void 0, function* () {
223
+ return this.listByUrnExtended(urnList, undefined, opt);
224
+ });
225
+ }
226
+ /** @inheritDoc */
227
+ listByUrnExtended(urnList, query, opt) {
228
+ return __awaiter(this, void 0, void 0, function* () {
229
+ urnList = this._checkKeys(urnList);
230
+ if (urnList.length < 1) {
231
+ return [];
232
+ }
233
+ const lines = (0, line_1.cbLine)();
234
+ lines
235
+ .add(`SELECT a.*`)
236
+ .add(`FROM ${this.fullPath} a`)
237
+ .add(`WHERE (a.${F_TRASH_ID} is missing)`)
238
+ .add(`USE KEYS [${urnList.map(urn => this.cb.s(urn)).join(',')}]`);
239
+ return this.cb.execExtended(this, lines.end(), query, opt);
240
+ });
241
+ }
242
+ /** @inheritDoc */
243
+ listById(ids, opt) {
244
+ return __awaiter(this, void 0, void 0, function* () {
245
+ return this.listByIdExtended(ids, undefined, opt);
246
+ });
247
+ }
248
+ /** @inheritDoc */
249
+ listByIdExtended(ids, query, opt) {
250
+ return __awaiter(this, void 0, void 0, function* () {
251
+ ids = this._checkKeys(ids);
252
+ if (ids.length < 1) {
253
+ return [];
254
+ }
255
+ const lines = (0, line_1.cbLine)();
256
+ lines
257
+ .add(`SELECT a.*`)
258
+ .add(`FROM ${this.fullPath} a`)
259
+ .add(`WHERE (a.${F_ID} IN [${ids.map(id => this.cb.s(id)).join(',')}])`)
260
+ .add(`AND (a.${F_TRASH_ID} is missing)`);
261
+ return this.cb.execExtended(this, lines.end(), query, opt);
262
+ });
263
+ }
264
+ /** @inheritDoc */
265
+ removeByUrn(urn, opt) {
266
+ return __awaiter(this, void 0, void 0, function* () {
267
+ return this.removeByUrnExtended(urn, undefined, opt);
268
+ });
269
+ }
270
+ /** @inheritDoc */
271
+ removeByUrnExtended(urn, query, opt) {
272
+ return __awaiter(this, void 0, void 0, function* () {
273
+ var _a;
274
+ const lines = (0, line_1.cbLine)();
275
+ lines
276
+ .add(`DELETE
277
+ FROM ${this.fullPath} a`)
278
+ .add(`WHERE (a.${F_TRASH_ID} is missing)`)
279
+ .add(`USE KEYS ${this.cb.s(urn)}`)
280
+ .add(`RETURNING a.${F_ID}`);
281
+ return (_a = (yield this.cb.execFirstExtended(this, lines.end(), query, opt))) === null || _a === void 0 ? void 0 : _a.id;
282
+ });
283
+ }
284
+ /** @inheritDoc */
285
+ removeById(id, opt) {
286
+ return __awaiter(this, void 0, void 0, function* () {
287
+ return this.removeByIdExtended(id, undefined, opt);
288
+ });
289
+ }
290
+ /** @inheritDoc */
291
+ removeByIdExtended(id, query, opt) {
292
+ return __awaiter(this, void 0, void 0, function* () {
293
+ var _a;
294
+ const lines = (0, line_1.cbLine)();
295
+ lines
296
+ .add(`DELETE FROM ${this.fullPath} a`)
297
+ .add(`WHERE (a.${F_ID} = ${this.cb.s(id)})`)
298
+ .add(`AND (a.${F_TRASH_ID} is missing)`)
299
+ .add(`RETURNING meta().id ${F_URN}`);
300
+ return (_a = (yield this.cb.execFirstExtended(this, lines.end(), query, opt))) === null || _a === void 0 ? void 0 : _a._urn;
301
+ });
302
+ }
303
+ /** @inheritDoc */
304
+ insert(doc, opt) {
305
+ return __awaiter(this, void 0, void 0, function* () {
306
+ const urn = this._urnFromDoc(doc, 'insert');
307
+ doc.createdAt = new Date().toISOString();
308
+ doc.updatedAt = new Date().toISOString();
309
+ const result = yield this.cb.exec1(this, this.collection.insert(urn, doc), opt);
310
+ return (result === null || result === void 0 ? void 0 : result.token) ? result.token.toString() : 'inserted';
311
+ });
312
+ }
313
+ /** @inheritDoc */
314
+ replace(doc, opt) {
315
+ return __awaiter(this, void 0, void 0, function* () {
316
+ const urn = this._urnFromDoc(doc, 'replace');
317
+ doc.updatedAt = new Date().toISOString();
318
+ const result = yield this.cb.exec1(this, this.collection.replace(urn, doc), opt);
319
+ return (result === null || result === void 0 ? void 0 : result.token) ? result.token.toString() : 'inserted';
320
+ });
321
+ }
322
+ /** @inheritDoc */
323
+ upsert(doc, opt) {
324
+ return __awaiter(this, void 0, void 0, function* () {
325
+ const urn = this._urnFromDoc(doc, 'upsert');
326
+ doc.updatedAt = new Date().toISOString();
327
+ const result = yield this.cb.exec1(this, this.collection.upsert(urn, doc), opt);
328
+ return (result === null || result === void 0 ? void 0 : result.token) ? result.token.toString() : 'modified';
329
+ });
330
+ }
331
+ /** @inheritDoc */
332
+ update(doc, opt) {
333
+ return __awaiter(this, void 0, void 0, function* () {
334
+ return this.updateExtended(doc, undefined, opt);
335
+ });
336
+ }
337
+ /** @inheritDoc */
338
+ updateExtended(doc, query, opt) {
339
+ return __awaiter(this, void 0, void 0, function* () {
340
+ var _a;
341
+ const urn = this._urnFromDoc(doc, 'update');
342
+ doc.updatedAt = new Date().toISOString();
343
+ doc.updatedAt = new Date().toISOString();
344
+ const sql = this._updateSql(urn, doc);
345
+ return (_a = (yield this.cb.execFirstExtended(this, sql, query, opt))) === null || _a === void 0 ? void 0 : _a._urn;
346
+ });
347
+ }
348
+ /** @inheritDoc */
349
+ trash(doc, opt) {
350
+ return __awaiter(this, void 0, void 0, function* () {
351
+ return this.trashExtended(doc, undefined, opt);
352
+ });
353
+ }
354
+ /** @inheritDoc */
355
+ trashExtended(doc, query, opt) {
356
+ return __awaiter(this, void 0, void 0, function* () {
357
+ const urn = this._urnFromDoc(doc, 'trash');
358
+ if (!opt) {
359
+ opt = { trashId: (0, node_crypto_1.randomUUID)() };
360
+ }
361
+ else if (!opt.trashId) {
362
+ opt.trashId = (0, node_crypto_1.randomUUID)();
363
+ }
364
+ const lines = (0, line_1.cbLine)();
365
+ lines
366
+ .add(`UPDATE ${this.fullPath} a`)
367
+ .add(`SET a.${F_TRASH_ID} = ${this.cb.s(opt.trashId)}`)
368
+ .add(`WHERE (a.${F_TRASH_ID} is missing)`)
369
+ .add(`USE KEYS ${this.cb.s(urn)}`);
370
+ yield this.cb.execExtended(this, lines.end(), query, opt);
371
+ return opt.trashId;
372
+ });
373
+ }
374
+ }
375
+ exports.CbRepo = CbRepo;
@@ -0,0 +1,2 @@
1
+ export * from './index.types';
2
+ export * from './cb.repo';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./index.types"), exports);
18
+ __exportStar(require("./cb.repo"), exports);
@@ -0,0 +1,144 @@
1
+ import type { Bucket, Cluster, Collection, QueryOptions, Scope } from "couchbase";
2
+ import type { CbEntity, CbExecMutationOpt, CbExecOpt, CbExecTrashOpt } from "../adapter";
3
+ export interface CbRepoLike<E extends CbEntity, ID> {
4
+ /**
5
+ * Readable Bucket/Scope/Collection path
6
+ * */
7
+ readonly path: string;
8
+ /**
9
+ * Formatted Bucket/Scope/Collection path
10
+ * */
11
+ readonly fullPath: string;
12
+ /**
13
+ * CB Cluster
14
+ * */
15
+ readonly cluster: Cluster;
16
+ /**
17
+ * CB Bucket
18
+ * */
19
+ readonly bucket: Bucket;
20
+ /**
21
+ * CB Scope
22
+ * */
23
+ readonly scope: Scope;
24
+ /**
25
+ * CB Collection
26
+ * */
27
+ readonly collection: Collection;
28
+ get def(): CbRepoDef;
29
+ /**
30
+ * Build URN with id model
31
+ * */
32
+ urn(part: ID): string;
33
+ /**
34
+ * It will be triggered when module is initialized
35
+ * */
36
+ onModuleInit(): Promise<void>;
37
+ /**
38
+ * Get urn by id
39
+ * */
40
+ urnById(id: string, opt?: CbExecOpt): Promise<string | undefined>;
41
+ /**
42
+ * Get urn by id with CB configuration
43
+ * */
44
+ urnByIdExtended(id: string, query: QueryOptions, opt?: CbExecOpt): Promise<string | undefined>;
45
+ /**
46
+ * Doc exists by urn?
47
+ * */
48
+ existsByUrn(urn: string, opt?: CbExecOpt): Promise<boolean>;
49
+ /**
50
+ * Doc exists by urn? with CB configuration
51
+ * */
52
+ existsByUrnExtended(urn: string, query: QueryOptions, opt?: CbExecOpt): Promise<boolean>;
53
+ /**
54
+ * Doc exists by id?
55
+ * */
56
+ existsById(id: string, opt?: CbExecOpt): Promise<boolean>;
57
+ /**
58
+ * Doc exists by id? with CB configuration
59
+ * */
60
+ existsByIdExtended(id: string, query: QueryOptions, opt?: CbExecOpt): Promise<boolean>;
61
+ /**
62
+ * Get doc by urn
63
+ * */
64
+ getByUrn(urn: string, opt?: CbExecOpt): Promise<E | undefined>;
65
+ /**
66
+ * Get doc by urn with CB configuration
67
+ * */
68
+ getByUrnExtended(urn: string, query: QueryOptions, opt?: CbExecOpt): Promise<E | undefined>;
69
+ /**
70
+ * Get doc by id
71
+ * */
72
+ getById(id: string, opt?: CbExecOpt): Promise<E | undefined>;
73
+ /**
74
+ * Get doc by id with CB configuration
75
+ * */
76
+ getByIdExtended(id: string, query: QueryOptions, opt?: CbExecOpt): Promise<E | undefined>;
77
+ /**
78
+ * Get doc by urn
79
+ * */
80
+ listByUrn(urnList: string[], opt?: CbExecOpt): Promise<Array<E>>;
81
+ /**
82
+ * Get doc by urn with CB configuration
83
+ * */
84
+ listByUrnExtended(urnList: string[], query: QueryOptions, opt?: CbExecOpt): Promise<Array<E>>;
85
+ /**
86
+ * Get doc by id
87
+ * */
88
+ listById(ids: string[], opt?: CbExecOpt): Promise<Array<E>>;
89
+ /**
90
+ * Get doc by id with CB configuration
91
+ * */
92
+ listByIdExtended(ids: string[], query: QueryOptions, opt?: CbExecOpt): Promise<Array<E>>;
93
+ /**
94
+ * Remove doc by urn
95
+ * */
96
+ removeByUrn(urn: string, opt?: CbExecOpt): Promise<string>;
97
+ /**
98
+ * Remove doc by urn with CB configuration
99
+ * */
100
+ removeByUrnExtended(urn: string, query: QueryOptions, opt?: CbExecOpt): Promise<string>;
101
+ /**
102
+ * Remove doc by urn
103
+ * */
104
+ removeById(id: string, opt?: CbExecOpt): Promise<string>;
105
+ /**
106
+ * Remove doc by urn with CB configuration
107
+ * */
108
+ removeByIdExtended(id: string, query: QueryOptions, opt?: CbExecOpt): Promise<string>;
109
+ /**
110
+ * Create doc by entity
111
+ * */
112
+ insert(doc: E, opt?: CbExecMutationOpt): Promise<string>;
113
+ /**
114
+ * Replace doc by entity
115
+ * */
116
+ replace(doc: E, opt?: CbExecMutationOpt): Promise<string>;
117
+ /**
118
+ * Upsert doc by entity (insert vs update)
119
+ * */
120
+ upsert(doc: E, opt?: CbExecMutationOpt): Promise<string>;
121
+ /**
122
+ * Update doc
123
+ * */
124
+ update(doc: Partial<E>, opt?: CbExecOpt): Promise<unknown>;
125
+ /**
126
+ * Update doc with CB configuration
127
+ * */
128
+ updateExtended(doc: Partial<E>, query: QueryOptions, opt?: CbExecOpt): Promise<unknown>;
129
+ /**
130
+ * Trash doc by entity
131
+ * */
132
+ trash(doc: E, opt?: CbExecTrashOpt): Promise<unknown>;
133
+ /**
134
+ * Trash doc by entity with CB configuration
135
+ * */
136
+ trashExtended(doc: E, query: QueryOptions, opt?: CbExecTrashOpt): Promise<unknown>;
137
+ }
138
+ export interface CbOnlyUrnRec {
139
+ _urn: string;
140
+ }
141
+ export interface CbOnlyIdRec {
142
+ id: string;
143
+ }
144
+ export type CbRepoDef = CbRepoLike<CbEntity, Record<string, string>>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });