@samet-it/be-db-common 1.1.3 → 1.1.5
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/connection/db.connection.js +8 -1
- package/dist/connection/index.types.d.ts +18 -5
- package/dist/error/db-invalid-value.error.d.ts +3 -5
- package/dist/error/db-invalid-value.error.js +3 -5
- package/dist/error/db-not-supported.error.d.ts +5 -3
- package/dist/error/db-not-supported.error.js +5 -4
- package/dist/error/db.error.d.ts +1 -2
- package/dist/error/index.d.ts +0 -1
- package/dist/error/index.js +0 -1
- package/dist/repo/db.repo.js +178 -141
- package/dist/repo/index.types.d.ts +9 -0
- package/package.json +4 -4
- package/dist/error/index.types.d.ts +0 -1
- package/dist/error/index.types.js +0 -2
|
@@ -106,7 +106,8 @@ class DbConnection {
|
|
|
106
106
|
checkError(err, opt) {
|
|
107
107
|
var _a, _b, _c;
|
|
108
108
|
const size = be_base_common_1.errorHandler.addStat(err);
|
|
109
|
-
|
|
109
|
+
const ignoredErrors = (_a = opt === null || opt === void 0 ? void 0 : opt.ignoredErrors) !== null && _a !== void 0 ? _a : [];
|
|
110
|
+
if (ignoredErrors.includes(err) || ignoredErrors.includes(err.name)) {
|
|
110
111
|
return;
|
|
111
112
|
}
|
|
112
113
|
if (opt === null || opt === void 0 ? void 0 : opt.silent) {
|
|
@@ -183,6 +184,9 @@ class DbConnection {
|
|
|
183
184
|
/** {@inheritDoc} */
|
|
184
185
|
exec(fn, p1) {
|
|
185
186
|
return __awaiter(this, void 0, void 0, function* () {
|
|
187
|
+
if (!this._props.enabled) {
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
186
190
|
const opt = this.buildOpt(p1);
|
|
187
191
|
try {
|
|
188
192
|
return yield fn;
|
|
@@ -199,6 +203,9 @@ class DbConnection {
|
|
|
199
203
|
* */
|
|
200
204
|
onModuleInit() {
|
|
201
205
|
return __awaiter(this, void 0, void 0, function* () {
|
|
206
|
+
if (!this._props.enabled) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
202
209
|
yield this.connect();
|
|
203
210
|
});
|
|
204
211
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { DbLines } from "../line";
|
|
2
|
-
import type {
|
|
3
|
-
import type { Opt } from "@leyyo/common";
|
|
2
|
+
import type { OmitError, Opt } from "@leyyo/common";
|
|
4
3
|
/**
|
|
5
4
|
* DB query result
|
|
6
5
|
* */
|
|
@@ -16,7 +15,7 @@ export interface DbQueryResult<META> {
|
|
|
16
15
|
/**
|
|
17
16
|
* [when success=false] Couchbase error
|
|
18
17
|
*/
|
|
19
|
-
error?:
|
|
18
|
+
error?: OmitError;
|
|
20
19
|
}
|
|
21
20
|
/**
|
|
22
21
|
* DB query result as a row
|
|
@@ -39,15 +38,23 @@ export interface DbQueryResultMore<E = any, META = unknown> extends DbQueryResul
|
|
|
39
38
|
/**
|
|
40
39
|
* DB query option
|
|
41
40
|
* */
|
|
42
|
-
export interface DbExecOpt {
|
|
41
|
+
export interface DbExecOpt extends Opt {
|
|
43
42
|
/**
|
|
44
43
|
* Name of SQL
|
|
45
44
|
* */
|
|
46
45
|
name?: string;
|
|
46
|
+
/**
|
|
47
|
+
* do not use cache
|
|
48
|
+
* */
|
|
49
|
+
noCache?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Ignore context cache
|
|
52
|
+
* */
|
|
53
|
+
ignoreContext?: string;
|
|
47
54
|
/**
|
|
48
55
|
* Ignored errors
|
|
49
56
|
* */
|
|
50
|
-
ignoredErrors?: Array<string>;
|
|
57
|
+
ignoredErrors?: Array<OmitError | string>;
|
|
51
58
|
/**
|
|
52
59
|
* Print sql?
|
|
53
60
|
* */
|
|
@@ -220,6 +227,12 @@ export interface DbMeta {
|
|
|
220
227
|
* DB connection option
|
|
221
228
|
* */
|
|
222
229
|
export interface DbConnOpt {
|
|
230
|
+
/**
|
|
231
|
+
* Is enabled?
|
|
232
|
+
*
|
|
233
|
+
* @type {boolean}
|
|
234
|
+
* */
|
|
235
|
+
enabled?: boolean;
|
|
223
236
|
/**
|
|
224
237
|
* Protocol
|
|
225
238
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Opt } from "@leyyo/common";
|
|
2
2
|
import { DbError } from "./db.error";
|
|
3
3
|
/**
|
|
4
4
|
* Cache validation error
|
|
@@ -6,9 +6,7 @@ import { DbError } from "./db.error";
|
|
|
6
6
|
export declare class DbInvalidValueError extends DbError {
|
|
7
7
|
/**
|
|
8
8
|
* @param {string} field - invalid field
|
|
9
|
-
* @param {
|
|
10
|
-
* @param {string} where - class name
|
|
11
|
-
* @param {string} method - method name
|
|
9
|
+
* @param {Opt} params - parameters
|
|
12
10
|
* */
|
|
13
|
-
constructor(field: string,
|
|
11
|
+
constructor(field: string, params: Opt);
|
|
14
12
|
}
|
|
@@ -9,12 +9,10 @@ const db_error_1 = require("./db.error");
|
|
|
9
9
|
class DbInvalidValueError extends db_error_1.DbError {
|
|
10
10
|
/**
|
|
11
11
|
* @param {string} field - invalid field
|
|
12
|
-
* @param {
|
|
13
|
-
* @param {string} where - class name
|
|
14
|
-
* @param {string} method - method name
|
|
12
|
+
* @param {Opt} params - parameters
|
|
15
13
|
* */
|
|
16
|
-
constructor(field,
|
|
17
|
-
super(`${field} value is not valid
|
|
14
|
+
constructor(field, params) {
|
|
15
|
+
super(`${field} value is not valid`, Object.assign(Object.assign({}, params), { field }));
|
|
18
16
|
}
|
|
19
17
|
}
|
|
20
18
|
exports.DbInvalidValueError = DbInvalidValueError;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { DbError } from "./db.error";
|
|
2
|
+
import type { Opt } from "@leyyo/common";
|
|
2
3
|
/**
|
|
3
4
|
* DB not-supported error
|
|
4
5
|
* */
|
|
5
6
|
export declare class DbNotSupportedError extends DbError {
|
|
6
7
|
/**
|
|
8
|
+
* Constructor
|
|
9
|
+
*
|
|
7
10
|
* @param {string} feature - feature name
|
|
8
|
-
* @param {
|
|
9
|
-
* @param {string} method - method name
|
|
11
|
+
* @param {Opt} params - parameters
|
|
10
12
|
* */
|
|
11
|
-
constructor(feature: string,
|
|
13
|
+
constructor(feature: string, params: Opt);
|
|
12
14
|
}
|
|
@@ -7,12 +7,13 @@ const db_error_1 = require("./db.error");
|
|
|
7
7
|
* */
|
|
8
8
|
class DbNotSupportedError extends db_error_1.DbError {
|
|
9
9
|
/**
|
|
10
|
+
* Constructor
|
|
11
|
+
*
|
|
10
12
|
* @param {string} feature - feature name
|
|
11
|
-
* @param {
|
|
12
|
-
* @param {string} method - method name
|
|
13
|
+
* @param {Opt} params - parameters
|
|
13
14
|
* */
|
|
14
|
-
constructor(feature,
|
|
15
|
-
super(`${feature} is not supported
|
|
15
|
+
constructor(feature, params) {
|
|
16
|
+
super(`${feature} is not supported`, Object.assign(Object.assign({}, params), { feature }));
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
exports.DbNotSupportedError = DbNotSupportedError;
|
package/dist/error/db.error.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { SametError } from "@samet-it/be-base-common";
|
|
2
|
-
import type { DbErrorOmit } from "./index.types";
|
|
3
2
|
/**
|
|
4
3
|
* General database error
|
|
5
4
|
* */
|
|
6
|
-
export declare class DbError extends SametError
|
|
5
|
+
export declare class DbError extends SametError {
|
|
7
6
|
}
|
package/dist/error/index.d.ts
CHANGED
package/dist/error/index.js
CHANGED
|
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./index.types"), exports);
|
|
18
17
|
__exportStar(require("./db.error"), exports);
|
|
19
18
|
__exportStar(require("./db-execute.error"), exports);
|
|
20
19
|
__exportStar(require("./db-invalid-value.error"), exports);
|
package/dist/repo/db.repo.js
CHANGED
|
@@ -45,7 +45,7 @@ class DbRepo {
|
|
|
45
45
|
* */
|
|
46
46
|
this._opt = {};
|
|
47
47
|
if (!(0, type_1.isObjectFilled)(conn)) {
|
|
48
|
-
throw new error_1.DbInvalidValueError('Connection',
|
|
48
|
+
throw new error_1.DbInvalidValueError('Connection', { where: 'DbRepo', method: 'constructor', type: typeof conn });
|
|
49
49
|
}
|
|
50
50
|
if (!(0, type_1.isObjectBare)(this._opt)) {
|
|
51
51
|
this._opt = {};
|
|
@@ -59,7 +59,7 @@ class DbRepo {
|
|
|
59
59
|
}
|
|
60
60
|
if (this._opt.useVersion) {
|
|
61
61
|
if (typeof this._opt.version !== 'number') {
|
|
62
|
-
throw new error_1.DbInvalidValueError('Model version',
|
|
62
|
+
throw new error_1.DbInvalidValueError('Model version', { where: 'DbRepo', method: 'constructor', type: typeof this._opt.version });
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
else {
|
|
@@ -84,7 +84,7 @@ class DbRepo {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
if (!this._opt.urnPrefix) {
|
|
87
|
-
throw new error_1.DbInvalidValueError('Urn prefix',
|
|
87
|
+
throw new error_1.DbInvalidValueError('Urn prefix', { where: 'DbRepo', method: 'constructor', type: typeof this._opt.urnPrefix });
|
|
88
88
|
}
|
|
89
89
|
this._opt.forbiddenSet = this._checkForbiddenList(this._opt.forbiddenSet, ['id', '_urn', '_trashId', 'createdAt', 'createdBy']);
|
|
90
90
|
this._opt.forbiddenUnset = this._checkForbiddenList(this._opt.forbiddenUnset, ['id', '_urn', '_trashId', 'createdAt', 'createdBy', 'updatedAt', 'updatedBy']);
|
|
@@ -155,14 +155,10 @@ class DbRepo {
|
|
|
155
155
|
* */
|
|
156
156
|
_urnFromDoc(doc, method) {
|
|
157
157
|
const { path } = this._props;
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
(0, type_1.assertObject)(urn, () => {
|
|
163
|
-
return { field: 'urn', where: 'DbRepo', path, method };
|
|
164
|
-
});
|
|
165
|
-
return urn;
|
|
158
|
+
const param = { where: 'DbRepo', path, method };
|
|
159
|
+
(0, type_1.assertObject)(doc, Object.assign({ field: 'doc' }, param));
|
|
160
|
+
(0, type_1.assertText)(doc._urn, Object.assign({ field: 'urn' }, param));
|
|
161
|
+
return doc._urn;
|
|
166
162
|
}
|
|
167
163
|
_checkKey(value) {
|
|
168
164
|
const { useNumericId } = this._props;
|
|
@@ -274,28 +270,31 @@ class DbRepo {
|
|
|
274
270
|
/** @inheritDoc */
|
|
275
271
|
get(k1, p1) {
|
|
276
272
|
return __awaiter(this, void 0, void 0, function* () {
|
|
273
|
+
const { conn } = this._props;
|
|
274
|
+
const opt = conn.buildOpt(p1, 'get');
|
|
277
275
|
const [key, field] = this._checkKey(k1);
|
|
278
276
|
switch (field) {
|
|
279
277
|
case "_urn":
|
|
280
|
-
return this.getByPrimary(key,
|
|
278
|
+
return this.getByPrimary(key, opt, true);
|
|
281
279
|
case "id":
|
|
282
|
-
return this.getBySecondary(key,
|
|
280
|
+
return this.getBySecondary(key, opt, true);
|
|
283
281
|
default:
|
|
284
|
-
(0, type_1.assertMessage)('Invalid key', { field: 'key', value: k1, where: 'DbRepo', method: 'get' });
|
|
282
|
+
(0, type_1.assertMessage)('Invalid key', { field: 'key', value: k1, where: 'DbRepo', method: 'get', queryName: opt.name });
|
|
285
283
|
}
|
|
286
284
|
});
|
|
287
285
|
}
|
|
288
286
|
/** @inheritDoc */
|
|
289
287
|
getByPrimary(key, p1, ignoreCheck) {
|
|
290
288
|
return __awaiter(this, void 0, void 0, function* () {
|
|
291
|
-
const { cache } = this._props;
|
|
289
|
+
const { cache, conn } = this._props;
|
|
290
|
+
const opt = conn.buildOpt(p1, 'getByPrimary');
|
|
292
291
|
if (!ignoreCheck) {
|
|
293
|
-
(0, type_1.assertText)(key, { field: 'key', where: 'DbRepo', method: 'getByPrimary' });
|
|
292
|
+
(0, type_1.assertText)(key, { field: 'key', where: 'DbRepo', method: 'getByPrimary', queryName: opt.name });
|
|
294
293
|
}
|
|
295
294
|
let found;
|
|
296
|
-
if (cache.props.isConnected) {
|
|
295
|
+
if (!opt.noCache && cache.props.isConnected) {
|
|
297
296
|
try {
|
|
298
|
-
found =
|
|
297
|
+
found = yield cache.getByPrimary(key, opt);
|
|
299
298
|
}
|
|
300
299
|
catch (e) {
|
|
301
300
|
this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'getByPrimary', 'cache', 'getByPrimary'));
|
|
@@ -304,9 +303,9 @@ class DbRepo {
|
|
|
304
303
|
return found;
|
|
305
304
|
}
|
|
306
305
|
}
|
|
307
|
-
found = yield this.$getByPrimary(key,
|
|
308
|
-
if (found && cache.props.isConnected) {
|
|
309
|
-
cache.ingestDoc(found)
|
|
306
|
+
found = yield this.$getByPrimary(key, opt, true);
|
|
307
|
+
if (!opt.noCache && found && cache.props.isConnected) {
|
|
308
|
+
cache.ingestDoc(found, opt)
|
|
310
309
|
.then()
|
|
311
310
|
.catch(e => this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'getByPrimary', 'cache', 'ingestDoc')));
|
|
312
311
|
}
|
|
@@ -316,22 +315,23 @@ class DbRepo {
|
|
|
316
315
|
/** @inheritDoc */
|
|
317
316
|
getBySecondary(key, p1, ignoreCheck) {
|
|
318
317
|
return __awaiter(this, void 0, void 0, function* () {
|
|
319
|
-
const { cache, useNumericId, idSame } = this._props;
|
|
318
|
+
const { cache, useNumericId, idSame, conn } = this._props;
|
|
319
|
+
const opt = conn.buildOpt(p1, 'getBySecondary');
|
|
320
320
|
if (!ignoreCheck) {
|
|
321
321
|
if (useNumericId) {
|
|
322
|
-
(0, type_1.assertInteger)(key, { field: 'key', where: 'DbRepo', method: 'getBySecondary' });
|
|
322
|
+
(0, type_1.assertInteger)(key, { field: 'key', where: 'DbRepo', method: 'getBySecondary', queryName: opt.name });
|
|
323
323
|
}
|
|
324
324
|
else {
|
|
325
|
-
(0, type_1.assertText)(key, { field: 'key', where: 'DbRepo', method: 'getBySecondary' });
|
|
325
|
+
(0, type_1.assertText)(key, { field: 'key', where: 'DbRepo', method: 'getBySecondary', queryName: opt.name });
|
|
326
326
|
}
|
|
327
327
|
}
|
|
328
328
|
if (idSame) {
|
|
329
|
-
return this.getByPrimary(this._keyToUrn(key),
|
|
329
|
+
return this.getByPrimary(this._keyToUrn(key), opt, true);
|
|
330
330
|
}
|
|
331
331
|
let found;
|
|
332
|
-
if (cache.props.isConnected) {
|
|
332
|
+
if (!opt.noCache && cache.props.isConnected) {
|
|
333
333
|
try {
|
|
334
|
-
found =
|
|
334
|
+
found = yield cache.getBySecondary(key, opt);
|
|
335
335
|
if (found) {
|
|
336
336
|
return found;
|
|
337
337
|
}
|
|
@@ -340,9 +340,9 @@ class DbRepo {
|
|
|
340
340
|
this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'getBySecondary', 'cache', 'getBySecondary'));
|
|
341
341
|
}
|
|
342
342
|
}
|
|
343
|
-
found = yield this.$getBySecondary(key,
|
|
343
|
+
found = yield this.$getBySecondary(key, opt, true);
|
|
344
344
|
if (found && cache.props.isConnected) {
|
|
345
|
-
cache.ingestDoc(found)
|
|
345
|
+
cache.ingestDoc(found, opt)
|
|
346
346
|
.then()
|
|
347
347
|
.catch(e => this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'getBySecondary', 'cache', 'ingestDoc')));
|
|
348
348
|
}
|
|
@@ -354,14 +354,16 @@ class DbRepo {
|
|
|
354
354
|
/** @inheritDoc */
|
|
355
355
|
exists(k1, p1) {
|
|
356
356
|
return __awaiter(this, void 0, void 0, function* () {
|
|
357
|
+
const { conn } = this._props;
|
|
358
|
+
const opt = conn.buildOpt(p1, 'exists');
|
|
357
359
|
const [key, field] = this._checkKey(k1);
|
|
358
360
|
switch (field) {
|
|
359
361
|
case "_urn":
|
|
360
|
-
return this.existsByPrimary(key,
|
|
362
|
+
return this.existsByPrimary(key, opt, true);
|
|
361
363
|
case "id":
|
|
362
|
-
return this.existsBySecondary(key,
|
|
364
|
+
return this.existsBySecondary(key, opt, true);
|
|
363
365
|
default:
|
|
364
|
-
(0, type_1.assertMessage)('Invalid key', { field: 'key', value: k1, where: 'DbRepo', method: 'exists' });
|
|
366
|
+
(0, type_1.assertMessage)('Invalid key', { field: 'key', value: k1, where: 'DbRepo', method: 'exists', queryName: opt.name });
|
|
365
367
|
break;
|
|
366
368
|
}
|
|
367
369
|
});
|
|
@@ -369,13 +371,14 @@ class DbRepo {
|
|
|
369
371
|
/** @inheritDoc */
|
|
370
372
|
existsByPrimary(key, p1, ignoreCheck) {
|
|
371
373
|
return __awaiter(this, void 0, void 0, function* () {
|
|
372
|
-
const { cache } = this._props;
|
|
374
|
+
const { cache, conn } = this._props;
|
|
375
|
+
const opt = conn.buildOpt(p1, 'existsByPrimary');
|
|
373
376
|
if (!ignoreCheck) {
|
|
374
|
-
(0, type_1.assertText)(key, { field: 'key', where: 'DbRepo', method: 'existsByPrimary' });
|
|
377
|
+
(0, type_1.assertText)(key, { field: 'key', where: 'DbRepo', method: 'existsByPrimary', queryName: opt.name });
|
|
375
378
|
}
|
|
376
|
-
if (cache.props.isConnected) {
|
|
379
|
+
if (!opt.noCache && cache.props.isConnected) {
|
|
377
380
|
try {
|
|
378
|
-
const found =
|
|
381
|
+
const found = yield cache.getByPrimary(key, opt);
|
|
379
382
|
if (found) {
|
|
380
383
|
return true;
|
|
381
384
|
}
|
|
@@ -384,27 +387,28 @@ class DbRepo {
|
|
|
384
387
|
this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'existsByPrimary', 'cache', 'getByPrimary'));
|
|
385
388
|
}
|
|
386
389
|
}
|
|
387
|
-
return this.$existsByPrimary(key,
|
|
390
|
+
return this.$existsByPrimary(key, opt, true);
|
|
388
391
|
});
|
|
389
392
|
}
|
|
390
393
|
/** @inheritDoc */
|
|
391
394
|
existsBySecondary(key, p1, ignoreCheck) {
|
|
392
395
|
return __awaiter(this, void 0, void 0, function* () {
|
|
393
|
-
const { cache, useNumericId, idSame } = this._props;
|
|
396
|
+
const { cache, useNumericId, idSame, conn } = this._props;
|
|
397
|
+
const opt = conn.buildOpt(p1, 'existsBySecondary');
|
|
394
398
|
if (!ignoreCheck) {
|
|
395
399
|
if (useNumericId) {
|
|
396
|
-
(0, type_1.assertInteger)(key, { field: 'key', where: 'DbRepo', method: 'existsBySecondary' });
|
|
400
|
+
(0, type_1.assertInteger)(key, { field: 'key', where: 'DbRepo', method: 'existsBySecondary', queryName: opt.name });
|
|
397
401
|
}
|
|
398
402
|
else {
|
|
399
|
-
(0, type_1.assertText)(key, { field: 'key', where: 'DbRepo', method: 'existsBySecondary' });
|
|
403
|
+
(0, type_1.assertText)(key, { field: 'key', where: 'DbRepo', method: 'existsBySecondary', queryName: opt.name });
|
|
400
404
|
}
|
|
401
405
|
}
|
|
402
406
|
if (!idSame) {
|
|
403
407
|
return this.existsByPrimary(this._keyToUrn(key));
|
|
404
408
|
}
|
|
405
|
-
if (cache.props.isConnected) {
|
|
409
|
+
if (!opt.noCache && cache.props.isConnected) {
|
|
406
410
|
try {
|
|
407
|
-
const found =
|
|
411
|
+
const found = yield cache.getBySecondary(key, opt);
|
|
408
412
|
if (found) {
|
|
409
413
|
return true;
|
|
410
414
|
}
|
|
@@ -413,7 +417,7 @@ class DbRepo {
|
|
|
413
417
|
this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'existsBySecondary', 'cache', 'getBySecondary'));
|
|
414
418
|
}
|
|
415
419
|
}
|
|
416
|
-
return this.$existsBySecondary(key,
|
|
420
|
+
return this.$existsBySecondary(key, opt, true);
|
|
417
421
|
});
|
|
418
422
|
}
|
|
419
423
|
// endregion exists
|
|
@@ -421,11 +425,11 @@ class DbRepo {
|
|
|
421
425
|
/** @inheritDoc */
|
|
422
426
|
list(keys, p1, ignoreCheck) {
|
|
423
427
|
return __awaiter(this, void 0, void 0, function* () {
|
|
424
|
-
if (!ignoreCheck) {
|
|
425
|
-
(0, type_1.assertArray)(keys, { field: 'keys', where: 'DbRepo', method: 'list' });
|
|
426
|
-
}
|
|
427
428
|
const { conn, cache } = this._props;
|
|
428
429
|
const opt = conn.buildOpt(p1, 'list');
|
|
430
|
+
if (!ignoreCheck) {
|
|
431
|
+
(0, type_1.assertArray)(keys, { field: 'keys', where: 'DbRepo', method: 'list', queryName: opt.name });
|
|
432
|
+
}
|
|
429
433
|
const result = this._checkKeys(keys);
|
|
430
434
|
if (result.ordered.length < 1) {
|
|
431
435
|
return [];
|
|
@@ -433,9 +437,9 @@ class DbRepo {
|
|
|
433
437
|
const docs = [];
|
|
434
438
|
let founds = [];
|
|
435
439
|
if (result.urns.length > 0) {
|
|
436
|
-
if (cache.props.isConnected) {
|
|
440
|
+
if (!opt.noCache && cache.props.isConnected) {
|
|
437
441
|
try {
|
|
438
|
-
founds = yield cache.
|
|
442
|
+
founds = yield cache.getByPrimaryMore(result.urns, opt);
|
|
439
443
|
}
|
|
440
444
|
catch (e) {
|
|
441
445
|
this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'list', 'cache', 'getByPrimary'));
|
|
@@ -451,8 +455,8 @@ class DbRepo {
|
|
|
451
455
|
if (result.urns.length > 0) {
|
|
452
456
|
founds = yield this.$listByPrimary(result.urns, opt, true);
|
|
453
457
|
if (founds.length > 0) {
|
|
454
|
-
if (cache.props.isConnected) {
|
|
455
|
-
founds.forEach(found => cache.ingestDoc(found)
|
|
458
|
+
if (!opt.noCache && cache.props.isConnected) {
|
|
459
|
+
founds.forEach(found => cache.ingestDoc(found, opt)
|
|
456
460
|
.then()
|
|
457
461
|
.catch(e => this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'list', 'cache', 'ingestDoc'))));
|
|
458
462
|
}
|
|
@@ -461,9 +465,9 @@ class DbRepo {
|
|
|
461
465
|
}
|
|
462
466
|
}
|
|
463
467
|
if (result.ids.length > 0) {
|
|
464
|
-
if (cache.props.isConnected) {
|
|
468
|
+
if (!opt.noCache && cache.props.isConnected) {
|
|
465
469
|
try {
|
|
466
|
-
founds = yield cache.
|
|
470
|
+
founds = yield cache.getBySecondaryMore(result.ids, opt);
|
|
467
471
|
}
|
|
468
472
|
catch (e) {
|
|
469
473
|
this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'list', 'cache', 'getBySecondary'));
|
|
@@ -479,8 +483,8 @@ class DbRepo {
|
|
|
479
483
|
if (result.ids.length > 0) {
|
|
480
484
|
founds = yield this.$listBySecondary(result.ids, opt, true);
|
|
481
485
|
if (founds.length > 0) {
|
|
482
|
-
if (cache.props.isConnected) {
|
|
483
|
-
founds.forEach(found => cache.ingestDoc(found)
|
|
486
|
+
if (!opt.noCache && cache.props.isConnected) {
|
|
487
|
+
founds.forEach(found => cache.ingestDoc(found, opt)
|
|
484
488
|
.then()
|
|
485
489
|
.catch(e => this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'list', 'cache', 'ingestDoc'))));
|
|
486
490
|
}
|
|
@@ -506,19 +510,21 @@ class DbRepo {
|
|
|
506
510
|
/** @inheritDoc */
|
|
507
511
|
insert(doc, p1, ignoreCheck) {
|
|
508
512
|
return __awaiter(this, void 0, void 0, function* () {
|
|
509
|
-
const { useCreatedAt, noInsert, useNumericId, useCreatedBy, useUpdatedAt, useUpdatedBy } = this._props;
|
|
513
|
+
const { useCreatedAt, conn, noInsert, useNumericId, useCreatedBy, useUpdatedAt, useUpdatedBy } = this._props;
|
|
514
|
+
const opt = conn.buildOpt(p1, 'insert');
|
|
515
|
+
const param = { where: 'DbRepo', method: 'insert', queryName: opt.name };
|
|
510
516
|
if (noInsert) {
|
|
511
|
-
throw new error_1.DbNotSupportedError('Insert',
|
|
517
|
+
throw new error_1.DbNotSupportedError('Insert', param);
|
|
512
518
|
}
|
|
513
519
|
if (!ignoreCheck) {
|
|
514
|
-
(0, type_1.assertObject)(doc, { field: 'doc'
|
|
520
|
+
(0, type_1.assertObject)(doc, Object.assign({ field: 'doc' }, param));
|
|
515
521
|
if (useNumericId) {
|
|
516
|
-
(0, type_1.assertInteger)(doc.id, { field: 'doc.id'
|
|
522
|
+
(0, type_1.assertInteger)(doc.id, Object.assign({ field: 'doc.id' }, param));
|
|
517
523
|
}
|
|
518
524
|
else {
|
|
519
|
-
(0, type_1.assertText)(doc.id, { field: 'doc.id'
|
|
525
|
+
(0, type_1.assertText)(doc.id, Object.assign({ field: 'doc.id' }, param));
|
|
520
526
|
}
|
|
521
|
-
(0, type_1.assertText)(doc._urn, { field: 'doc._urn'
|
|
527
|
+
(0, type_1.assertText)(doc._urn, Object.assign({ field: 'doc._urn' }, param));
|
|
522
528
|
}
|
|
523
529
|
if (!doc._trashId !== undefined) {
|
|
524
530
|
delete doc._trashId;
|
|
@@ -535,22 +541,24 @@ class DbRepo {
|
|
|
535
541
|
if (useUpdatedBy) {
|
|
536
542
|
// todo
|
|
537
543
|
}
|
|
538
|
-
return this.$insert(doc,
|
|
544
|
+
return this.$insert(doc, opt);
|
|
539
545
|
});
|
|
540
546
|
}
|
|
541
547
|
/** @inheritDoc */
|
|
542
548
|
inserts(docs, p1, ignoreCheck) {
|
|
543
549
|
return __awaiter(this, void 0, void 0, function* () {
|
|
544
|
-
const { noInsert } = this._props;
|
|
550
|
+
const { noInsert, conn } = this._props;
|
|
551
|
+
const opt = conn.buildOpt(p1, 'inserts');
|
|
552
|
+
const param = { where: 'DbRepo', method: 'inserts', queryName: opt.name };
|
|
545
553
|
if (noInsert) {
|
|
546
|
-
throw new error_1.DbNotSupportedError('Insert',
|
|
554
|
+
throw new error_1.DbNotSupportedError('Insert', param);
|
|
547
555
|
}
|
|
548
556
|
if (!ignoreCheck) {
|
|
549
|
-
(0, type_1.assertArray)(docs, { field: 'docs'
|
|
557
|
+
(0, type_1.assertArray)(docs, Object.assign({ field: 'docs' }, param));
|
|
550
558
|
}
|
|
551
559
|
const insertedIds = [];
|
|
552
560
|
for (const doc of docs) {
|
|
553
|
-
insertedIds.push(yield this.insert(doc,
|
|
561
|
+
insertedIds.push(yield this.insert(doc, opt, true));
|
|
554
562
|
}
|
|
555
563
|
return insertedIds;
|
|
556
564
|
});
|
|
@@ -560,15 +568,16 @@ class DbRepo {
|
|
|
560
568
|
/** @inheritDoc */
|
|
561
569
|
replace(doc, p1, ignoreCheck) {
|
|
562
570
|
return __awaiter(this, void 0, void 0, function* () {
|
|
563
|
-
const { cache, useNumericId, useUpdatedAt, useUpdatedBy } = this._props;
|
|
571
|
+
const { cache, conn, useNumericId, useUpdatedAt, useUpdatedBy } = this._props;
|
|
572
|
+
const opt = conn.buildOpt(p1, 'replace');
|
|
564
573
|
if (!ignoreCheck) {
|
|
565
|
-
(0, type_1.assertObject)(doc, { field: 'doc', where: 'DbRepo', method: 'replace' });
|
|
566
|
-
(0, type_1.assertText)(doc._urn, { field: 'doc._urn', where: 'DbRepo', method: 'replace' });
|
|
574
|
+
(0, type_1.assertObject)(doc, { field: 'doc', where: 'DbRepo', method: 'replace', queryName: opt.name });
|
|
575
|
+
(0, type_1.assertText)(doc._urn, { field: 'doc._urn', where: 'DbRepo', method: 'replace', queryName: opt.name });
|
|
567
576
|
if (useNumericId) {
|
|
568
|
-
(0, type_1.assertInteger)(doc.id, { field: 'doc.id', where: 'DbRepo', method: 'replace' });
|
|
577
|
+
(0, type_1.assertInteger)(doc.id, { field: 'doc.id', where: 'DbRepo', method: 'replace', queryName: opt.name });
|
|
569
578
|
}
|
|
570
579
|
else {
|
|
571
|
-
(0, type_1.assertText)(doc.id, { field: 'doc.id', where: 'DbRepo', method: 'replace' });
|
|
580
|
+
(0, type_1.assertText)(doc.id, { field: 'doc.id', where: 'DbRepo', method: 'replace', queryName: opt.name });
|
|
572
581
|
}
|
|
573
582
|
}
|
|
574
583
|
if (doc._trashId !== undefined) {
|
|
@@ -580,9 +589,9 @@ class DbRepo {
|
|
|
580
589
|
if (useUpdatedBy) {
|
|
581
590
|
// todo
|
|
582
591
|
}
|
|
583
|
-
const replacedKey = yield this.$replace(doc,
|
|
584
|
-
if (cache.props.isConnected) {
|
|
585
|
-
cache.clearDoc(replacedKey)
|
|
592
|
+
const replacedKey = yield this.$replace(doc, opt, true);
|
|
593
|
+
if (!opt.noCache && cache.props.isConnected) {
|
|
594
|
+
cache.clearDoc(replacedKey, opt)
|
|
586
595
|
.then()
|
|
587
596
|
.catch(e => this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'replace', 'cache', 'clearDoc')));
|
|
588
597
|
}
|
|
@@ -594,18 +603,20 @@ class DbRepo {
|
|
|
594
603
|
/** @inheritDoc */
|
|
595
604
|
upsert(doc, p1, ignoreCheck) {
|
|
596
605
|
return __awaiter(this, void 0, void 0, function* () {
|
|
597
|
-
const { noInsert, noUpdate, cache, useNumericId, useUpdatedAt, useUpdatedBy } = this._props;
|
|
606
|
+
const { noInsert, conn, noUpdate, cache, useNumericId, useUpdatedAt, useUpdatedBy } = this._props;
|
|
607
|
+
const opt = conn.buildOpt(p1, 'upsert');
|
|
608
|
+
const param = { where: 'DbRepo', method: 'upsert', queryName: opt.name };
|
|
598
609
|
if (noInsert || noUpdate) {
|
|
599
|
-
throw new error_1.DbNotSupportedError('Upsert',
|
|
610
|
+
throw new error_1.DbNotSupportedError('Upsert', param);
|
|
600
611
|
}
|
|
601
612
|
if (!ignoreCheck) {
|
|
602
|
-
(0, type_1.assertObject)(doc, { field: 'doc'
|
|
603
|
-
(0, type_1.assertText)(doc._urn, { field: 'doc._urn'
|
|
613
|
+
(0, type_1.assertObject)(doc, Object.assign({ field: 'doc' }, param));
|
|
614
|
+
(0, type_1.assertText)(doc._urn, Object.assign({ field: 'doc._urn' }, param));
|
|
604
615
|
if (useNumericId) {
|
|
605
|
-
(0, type_1.assertInteger)(doc.id, { field: 'doc.id'
|
|
616
|
+
(0, type_1.assertInteger)(doc.id, Object.assign({ field: 'doc.id' }, param));
|
|
606
617
|
}
|
|
607
618
|
else {
|
|
608
|
-
(0, type_1.assertText)(doc.id, { field: 'doc.id'
|
|
619
|
+
(0, type_1.assertText)(doc.id, Object.assign({ field: 'doc.id' }, param));
|
|
609
620
|
}
|
|
610
621
|
}
|
|
611
622
|
if (doc._trashId !== undefined) {
|
|
@@ -617,9 +628,9 @@ class DbRepo {
|
|
|
617
628
|
if (useUpdatedBy) {
|
|
618
629
|
// todo
|
|
619
630
|
}
|
|
620
|
-
const createdKey = yield this.$replace(doc,
|
|
621
|
-
if (cache.props.isConnected) {
|
|
622
|
-
cache.clearDoc(createdKey)
|
|
631
|
+
const createdKey = yield this.$replace(doc, opt, true);
|
|
632
|
+
if (!opt.noCache && cache.props.isConnected) {
|
|
633
|
+
cache.clearDoc(createdKey, opt)
|
|
623
634
|
.then()
|
|
624
635
|
.catch(e => this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'upsert', 'cache', 'clearDoc')));
|
|
625
636
|
}
|
|
@@ -631,30 +642,34 @@ class DbRepo {
|
|
|
631
642
|
/** @inheritDoc */
|
|
632
643
|
update(k1, doc, p1, ignoreCheck) {
|
|
633
644
|
return __awaiter(this, void 0, void 0, function* () {
|
|
645
|
+
const { conn } = this._props;
|
|
646
|
+
const opt = conn.buildOpt(p1, 'update');
|
|
634
647
|
if (!ignoreCheck) {
|
|
635
|
-
(0, type_1.assertObject)(doc, { field: 'doc', where: 'DbRepo', method: 'update' });
|
|
648
|
+
(0, type_1.assertObject)(doc, { field: 'doc', where: 'DbRepo', method: 'update', queryName: opt.name });
|
|
636
649
|
}
|
|
637
650
|
const [key, field] = this._checkKey(k1);
|
|
638
651
|
switch (field) {
|
|
639
652
|
case "_urn":
|
|
640
|
-
return this.updateByPrimary(key, doc,
|
|
653
|
+
return this.updateByPrimary(key, doc, opt, true);
|
|
641
654
|
case "id":
|
|
642
|
-
return this.updateBySecondary(key, doc,
|
|
655
|
+
return this.updateBySecondary(key, doc, opt, true);
|
|
643
656
|
default:
|
|
644
|
-
(0, type_1.assertMessage)('Invalid key', { field: 'key', value: k1, where: 'DbRepo', method: 'update' });
|
|
657
|
+
(0, type_1.assertMessage)('Invalid key', { field: 'key', value: k1, where: 'DbRepo', method: 'update', queryName: opt.name });
|
|
645
658
|
}
|
|
646
659
|
});
|
|
647
660
|
}
|
|
648
661
|
/** @inheritDoc */
|
|
649
662
|
updateByPrimary(key, doc, p1, ignoreCheck) {
|
|
650
663
|
return __awaiter(this, void 0, void 0, function* () {
|
|
651
|
-
const { noUpdate, forbiddenSet, cache, useUpdatedAt, useUpdatedBy } = this._props;
|
|
664
|
+
const { noUpdate, conn, forbiddenSet, cache, useUpdatedAt, useUpdatedBy } = this._props;
|
|
665
|
+
const opt = conn.buildOpt(p1, 'updateByPrimary');
|
|
666
|
+
const param = { where: 'DbRepo', method: 'updateByPrimary', queryName: opt.name };
|
|
652
667
|
if (noUpdate) {
|
|
653
|
-
throw new error_1.DbNotSupportedError('Update',
|
|
668
|
+
throw new error_1.DbNotSupportedError('Update', param);
|
|
654
669
|
}
|
|
655
670
|
if (!ignoreCheck) {
|
|
656
|
-
(0, type_1.assertText)(key, { field: 'key'
|
|
657
|
-
(0, type_1.assertObject)(doc, { field: 'doc'
|
|
671
|
+
(0, type_1.assertText)(key, Object.assign({ field: 'key' }, param));
|
|
672
|
+
(0, type_1.assertObject)(doc, Object.assign({ field: 'doc' }, param));
|
|
658
673
|
}
|
|
659
674
|
if (doc._trashId !== undefined) {
|
|
660
675
|
delete doc._trashId;
|
|
@@ -670,9 +685,9 @@ class DbRepo {
|
|
|
670
685
|
if (useUpdatedBy) {
|
|
671
686
|
// todo
|
|
672
687
|
}
|
|
673
|
-
const updatedKey = yield this.$updateByPrimary(key, doc,
|
|
674
|
-
if (updatedKey && cache.props.isConnected) {
|
|
675
|
-
cache.clearDoc(updatedKey)
|
|
688
|
+
const updatedKey = yield this.$updateByPrimary(key, doc, opt, true);
|
|
689
|
+
if (updatedKey && !opt.noCache && cache.props.isConnected) {
|
|
690
|
+
cache.clearDoc(updatedKey, opt)
|
|
676
691
|
.then()
|
|
677
692
|
.catch(e => this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'updateByPrimary', 'cache', 'clearDoc')));
|
|
678
693
|
}
|
|
@@ -682,21 +697,23 @@ class DbRepo {
|
|
|
682
697
|
/** @inheritDoc */
|
|
683
698
|
updateBySecondary(key, doc, p1, ignoreCheck) {
|
|
684
699
|
return __awaiter(this, void 0, void 0, function* () {
|
|
685
|
-
const { forbiddenSet, noUpdate, cache, useNumericId, idSame, useUpdatedAt, useUpdatedBy } = this._props;
|
|
700
|
+
const { forbiddenSet, noUpdate, cache, useNumericId, idSame, useUpdatedAt, useUpdatedBy, conn } = this._props;
|
|
701
|
+
const opt = conn.buildOpt(p1, 'updateBySecondary');
|
|
702
|
+
const param = { where: 'DbRepo', method: 'updateBySecondary', queryName: opt.name };
|
|
686
703
|
if (noUpdate) {
|
|
687
|
-
throw new error_1.DbNotSupportedError('Update',
|
|
704
|
+
throw new error_1.DbNotSupportedError('Update', param);
|
|
688
705
|
}
|
|
689
706
|
if (!ignoreCheck) {
|
|
690
707
|
if (useNumericId) {
|
|
691
|
-
(0, type_1.assertInteger)(key, { field: 'key'
|
|
708
|
+
(0, type_1.assertInteger)(key, Object.assign({ field: 'key' }, param));
|
|
692
709
|
}
|
|
693
710
|
else {
|
|
694
|
-
(0, type_1.assertText)(key, { field: 'key'
|
|
711
|
+
(0, type_1.assertText)(key, Object.assign({ field: 'key' }, param));
|
|
695
712
|
}
|
|
696
|
-
(0, type_1.assertObject)(doc, { field: 'doc'
|
|
713
|
+
(0, type_1.assertObject)(doc, Object.assign({ field: 'doc' }, param));
|
|
697
714
|
}
|
|
698
715
|
if (idSame) {
|
|
699
|
-
return this.updateBySecondary(this._keyToUrn(key), doc,
|
|
716
|
+
return this.updateBySecondary(this._keyToUrn(key), doc, opt, true);
|
|
700
717
|
}
|
|
701
718
|
if (doc._trashId !== undefined) {
|
|
702
719
|
delete doc._trashId;
|
|
@@ -712,9 +729,9 @@ class DbRepo {
|
|
|
712
729
|
if (useUpdatedBy) {
|
|
713
730
|
// todo
|
|
714
731
|
}
|
|
715
|
-
const updatedKey = yield this.$updateBySecondary(key, doc,
|
|
716
|
-
if (updatedKey && cache.props.isConnected) {
|
|
717
|
-
cache.clearDoc(updatedKey)
|
|
732
|
+
const updatedKey = yield this.$updateBySecondary(key, doc, opt, true);
|
|
733
|
+
if (updatedKey && !opt.noCache && cache.props.isConnected) {
|
|
734
|
+
cache.clearDoc(updatedKey, opt)
|
|
718
735
|
.then()
|
|
719
736
|
.catch(e => this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'updateBySecondary', 'cache', 'clearDoc')));
|
|
720
737
|
}
|
|
@@ -726,24 +743,28 @@ class DbRepo {
|
|
|
726
743
|
/** @inheritDoc */
|
|
727
744
|
set(key, doc, p1, ignoreCheck) {
|
|
728
745
|
return __awaiter(this, void 0, void 0, function* () {
|
|
746
|
+
const { conn } = this._props;
|
|
747
|
+
const opt = conn.buildOpt(p1, 'set');
|
|
729
748
|
if (!ignoreCheck) {
|
|
730
|
-
(0, type_1.assertObject)(doc, { field: 'doc', where: 'DbRepo', method: 'set' });
|
|
749
|
+
(0, type_1.assertObject)(doc, { field: 'doc', where: 'DbRepo', method: 'set', queryName: opt.name });
|
|
731
750
|
}
|
|
732
751
|
for (const [f, v] of Object.entries(doc)) {
|
|
733
752
|
if (v === undefined) { // dont allow undefined
|
|
734
753
|
delete doc[f];
|
|
735
754
|
}
|
|
736
755
|
}
|
|
737
|
-
return this.update(key, doc,
|
|
756
|
+
return this.update(key, doc, opt, false);
|
|
738
757
|
});
|
|
739
758
|
}
|
|
740
759
|
/** @inheritDoc */
|
|
741
760
|
unset(key, fields, p1, ignoreCheck) {
|
|
742
761
|
return __awaiter(this, void 0, void 0, function* () {
|
|
762
|
+
const { conn } = this._props;
|
|
763
|
+
const opt = conn.buildOpt(p1, 'unset');
|
|
743
764
|
if (!ignoreCheck) {
|
|
744
|
-
(0, type_1.assertArray)(fields, { field: 'fields', where: 'DbRepo', method: 'unset' });
|
|
765
|
+
(0, type_1.assertArray)(fields, { field: 'fields', where: 'DbRepo', method: 'unset', queryName: opt.name });
|
|
745
766
|
fields.forEach((field, index) => {
|
|
746
|
-
(0, type_1.assertText)(field, { field: field, where: 'DbRepo', method: 'unset', index });
|
|
767
|
+
(0, type_1.assertText)(field, { field: field, where: 'DbRepo', method: 'unset', index, queryName: opt.name });
|
|
747
768
|
});
|
|
748
769
|
}
|
|
749
770
|
const { forbiddenUnset } = this._props;
|
|
@@ -753,7 +774,7 @@ class DbRepo {
|
|
|
753
774
|
doc[f] = undefined;
|
|
754
775
|
}
|
|
755
776
|
});
|
|
756
|
-
return this.update(key, doc,
|
|
777
|
+
return this.update(key, doc, opt, false);
|
|
757
778
|
});
|
|
758
779
|
}
|
|
759
780
|
// endregion set
|
|
@@ -761,30 +782,34 @@ class DbRepo {
|
|
|
761
782
|
/** @inheritDoc */
|
|
762
783
|
remove(k1, p1) {
|
|
763
784
|
return __awaiter(this, void 0, void 0, function* () {
|
|
785
|
+
const { conn } = this._props;
|
|
786
|
+
const opt = conn.buildOpt(p1, 'remove');
|
|
764
787
|
const [key, field] = this._checkKey(k1);
|
|
765
788
|
switch (field) {
|
|
766
789
|
case "_urn":
|
|
767
|
-
return this.removeByPrimary(key,
|
|
790
|
+
return this.removeByPrimary(key, opt, true);
|
|
768
791
|
case "id":
|
|
769
|
-
return this.removeBySecondary(key,
|
|
792
|
+
return this.removeBySecondary(key, opt, true);
|
|
770
793
|
default:
|
|
771
|
-
(0, type_1.assertMessage)('Invalid key', { field: 'key', value: k1, where: 'DbRepo', method: 'remove' });
|
|
794
|
+
(0, type_1.assertMessage)('Invalid key', { field: 'key', value: k1, where: 'DbRepo', method: 'remove', queryName: opt.name });
|
|
772
795
|
}
|
|
773
796
|
});
|
|
774
797
|
}
|
|
775
798
|
/** @inheritDoc */
|
|
776
799
|
removeByPrimary(key, p1, ignoreCheck) {
|
|
777
800
|
return __awaiter(this, void 0, void 0, function* () {
|
|
778
|
-
const { cache, noRemove } = this._props;
|
|
801
|
+
const { cache, noRemove, conn } = this._props;
|
|
802
|
+
const opt = conn.buildOpt(p1, 'removeByPrimary');
|
|
803
|
+
const param = { where: 'DbRepo', method: 'removeByPrimary', queryName: opt.name };
|
|
779
804
|
if (noRemove) {
|
|
780
|
-
throw new error_1.DbNotSupportedError('Remove',
|
|
805
|
+
throw new error_1.DbNotSupportedError('Remove', param);
|
|
781
806
|
}
|
|
782
807
|
if (!ignoreCheck) {
|
|
783
|
-
(0, type_1.assertText)(key, { field: 'key'
|
|
808
|
+
(0, type_1.assertText)(key, Object.assign({ field: 'key' }, param));
|
|
784
809
|
}
|
|
785
|
-
const removedKey = yield this.$removeByPrimary(key,
|
|
786
|
-
if (removedKey && cache.props.isConnected) {
|
|
787
|
-
cache.clearDoc(removedKey)
|
|
810
|
+
const removedKey = yield this.$removeByPrimary(key, opt, true);
|
|
811
|
+
if (removedKey && !opt.noCache && cache.props.isConnected) {
|
|
812
|
+
cache.clearDoc(removedKey, opt)
|
|
788
813
|
.then()
|
|
789
814
|
.catch(e => this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'removeByPrimary', 'cache', 'clearDoc')));
|
|
790
815
|
}
|
|
@@ -794,22 +819,24 @@ class DbRepo {
|
|
|
794
819
|
/** @inheritDoc */
|
|
795
820
|
removeBySecondary(key, p1, ignoreCheck) {
|
|
796
821
|
return __awaiter(this, void 0, void 0, function* () {
|
|
797
|
-
const { cache, noRemove, useNumericId, idSame } = this._props;
|
|
822
|
+
const { cache, noRemove, useNumericId, idSame, conn } = this._props;
|
|
823
|
+
const opt = conn.buildOpt(p1, 'removeBySecondary');
|
|
824
|
+
const param = { where: 'DbRepo', method: 'removeByPrimary', queryName: opt.name };
|
|
798
825
|
if (noRemove) {
|
|
799
|
-
throw new error_1.DbNotSupportedError('Remove',
|
|
826
|
+
throw new error_1.DbNotSupportedError('Remove', param);
|
|
800
827
|
}
|
|
801
828
|
if (useNumericId) {
|
|
802
|
-
(0, type_1.assertInteger)(key, { field: 'key',
|
|
829
|
+
(0, type_1.assertInteger)(key, { field: 'key', param });
|
|
803
830
|
}
|
|
804
831
|
else {
|
|
805
|
-
(0, type_1.assertText)(key, { field: 'key',
|
|
832
|
+
(0, type_1.assertText)(key, { field: 'key', param });
|
|
806
833
|
}
|
|
807
834
|
if (idSame) {
|
|
808
|
-
return this.removeByPrimary(this._keyToUrn(key),
|
|
835
|
+
return this.removeByPrimary(this._keyToUrn(key), opt, ignoreCheck);
|
|
809
836
|
}
|
|
810
|
-
const removedKey = yield this.$removeBySecondary(key,
|
|
811
|
-
if (removedKey && cache.props.isConnected) {
|
|
812
|
-
cache.clearDoc(removedKey)
|
|
837
|
+
const removedKey = yield this.$removeBySecondary(key, opt, true);
|
|
838
|
+
if (removedKey && !opt.noCache && cache.props.isConnected) {
|
|
839
|
+
cache.clearDoc(removedKey, opt)
|
|
813
840
|
.then()
|
|
814
841
|
.catch(e => this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'removeBySecondary', 'cache', 'clearDoc')));
|
|
815
842
|
}
|
|
@@ -821,34 +848,40 @@ class DbRepo {
|
|
|
821
848
|
/** @inheritDoc */
|
|
822
849
|
trash(k1, p1) {
|
|
823
850
|
return __awaiter(this, void 0, void 0, function* () {
|
|
851
|
+
const { conn } = this._props;
|
|
852
|
+
const opt = conn.buildOpt(p1, 'trash');
|
|
824
853
|
const [key, field] = this._checkKey(k1);
|
|
825
854
|
switch (field) {
|
|
826
855
|
case "_urn":
|
|
827
|
-
return this.trashByPrimary(key,
|
|
856
|
+
return this.trashByPrimary(key, opt, true);
|
|
828
857
|
case "id":
|
|
829
|
-
return this.trashBySecondary(key,
|
|
858
|
+
return this.trashBySecondary(key, opt, true);
|
|
830
859
|
default:
|
|
831
|
-
(0, type_1.assertMessage)('Invalid key', { field: 'key', value: k1, where: 'DbRepo', method: 'trash' });
|
|
860
|
+
(0, type_1.assertMessage)('Invalid key', { field: 'key', value: k1, where: 'DbRepo', method: 'trash', queryName: opt.name });
|
|
832
861
|
}
|
|
833
862
|
});
|
|
834
863
|
}
|
|
835
864
|
/** @inheritDoc */
|
|
836
865
|
trashByPrimary(key, p1, ignoreCheck) {
|
|
837
866
|
return __awaiter(this, void 0, void 0, function* () {
|
|
838
|
-
const { noTrash, conn, cache } = this._props;
|
|
867
|
+
const { noTrash, useSoftDelete, conn, cache } = this._props;
|
|
868
|
+
const opt = conn.buildOpt(p1, 'trashByPrimary');
|
|
869
|
+
const param = { where: 'DbRepo', method: 'trashByPrimary', queryName: opt.name };
|
|
870
|
+
if (!useSoftDelete) {
|
|
871
|
+
throw new error_1.DbNotSupportedError('Soft Delete', param);
|
|
872
|
+
}
|
|
839
873
|
if (noTrash) {
|
|
840
|
-
throw new error_1.DbNotSupportedError('Trash',
|
|
874
|
+
throw new error_1.DbNotSupportedError('Trash', param);
|
|
841
875
|
}
|
|
842
876
|
if (!ignoreCheck) {
|
|
843
|
-
(0, type_1.assertText)(key, { field: 'urn'
|
|
877
|
+
(0, type_1.assertText)(key, Object.assign({ field: 'urn' }, param));
|
|
844
878
|
}
|
|
845
|
-
const opt = conn.buildOpt(p1, 'trashByPrimary');
|
|
846
879
|
if (!(0, type_1.isText)(opt.trashId)) {
|
|
847
880
|
opt.trashId = (0, node_crypto_1.randomUUID)();
|
|
848
881
|
}
|
|
849
882
|
const trashedKey = yield this.$trashByPrimary(key, opt, true);
|
|
850
|
-
if (trashedKey && cache.props.isConnected) {
|
|
851
|
-
cache.clearDoc(trashedKey)
|
|
883
|
+
if (trashedKey && !opt.noCache && cache.props.isConnected) {
|
|
884
|
+
cache.clearDoc(trashedKey, opt)
|
|
852
885
|
.then()
|
|
853
886
|
.catch(e => this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'trashByPrimary', 'cache', 'clearDoc')));
|
|
854
887
|
}
|
|
@@ -858,26 +891,30 @@ class DbRepo {
|
|
|
858
891
|
/** @inheritDoc */
|
|
859
892
|
trashBySecondary(key, p1, ignoreCheck) {
|
|
860
893
|
return __awaiter(this, void 0, void 0, function* () {
|
|
861
|
-
const { noTrash, useNumericId, idSame, conn, cache } = this._props;
|
|
894
|
+
const { noTrash, useSoftDelete, useNumericId, idSame, conn, cache } = this._props;
|
|
895
|
+
const opt = conn.buildOpt(p1, 'trashBySecondary');
|
|
896
|
+
const param = { where: 'DbRepo', method: 'trashBySecondary', queryName: opt.name };
|
|
897
|
+
if (!useSoftDelete) {
|
|
898
|
+
throw new error_1.DbNotSupportedError('Soft Delete', param);
|
|
899
|
+
}
|
|
862
900
|
if (noTrash) {
|
|
863
|
-
throw new error_1.DbNotSupportedError('Trash',
|
|
901
|
+
throw new error_1.DbNotSupportedError('Trash', param);
|
|
864
902
|
}
|
|
865
903
|
if (useNumericId) {
|
|
866
|
-
(0, type_1.assertInteger)(key, { field: 'key'
|
|
904
|
+
(0, type_1.assertInteger)(key, Object.assign({ field: 'key' }, param));
|
|
867
905
|
}
|
|
868
906
|
else {
|
|
869
|
-
(0, type_1.assertText)(key, { field: 'key'
|
|
907
|
+
(0, type_1.assertText)(key, Object.assign({ field: 'key' }, param));
|
|
870
908
|
}
|
|
871
909
|
if (idSame) {
|
|
872
|
-
return this.trashByPrimary(this._keyToUrn(key),
|
|
910
|
+
return this.trashByPrimary(this._keyToUrn(key), opt, ignoreCheck);
|
|
873
911
|
}
|
|
874
|
-
const opt = conn.buildOpt(p1, 'trashBySecondary');
|
|
875
912
|
if (!(0, type_1.isText)(opt.trashId)) {
|
|
876
913
|
opt.trashId = (0, node_crypto_1.randomUUID)();
|
|
877
914
|
}
|
|
878
915
|
const trashedKey = yield this.$trashBySecondary(key, opt, true);
|
|
879
|
-
if (trashedKey && cache.props.isConnected) {
|
|
880
|
-
cache.clearDoc(trashedKey)
|
|
916
|
+
if (trashedKey && !opt.noCache && cache.props.isConnected) {
|
|
917
|
+
cache.clearDoc(trashedKey, opt)
|
|
881
918
|
.then()
|
|
882
919
|
.catch(e => this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'trashBySecondary', 'cache', 'clearDoc')));
|
|
883
920
|
}
|
|
@@ -587,6 +587,15 @@ export interface DbRepoOpt<ENT extends Entity<ID>, ID extends KeyValue> {
|
|
|
587
587
|
* @default false
|
|
588
588
|
* */
|
|
589
589
|
idSame?: boolean;
|
|
590
|
+
/**
|
|
591
|
+
* Ignores soft delete
|
|
592
|
+
* - if yes, it ignores trash case
|
|
593
|
+
* - if no, it validates trash case
|
|
594
|
+
*
|
|
595
|
+
* @fields `_trashId`
|
|
596
|
+
* @default false
|
|
597
|
+
* */
|
|
598
|
+
useSoftDelete?: boolean;
|
|
590
599
|
/**
|
|
591
600
|
* Manages `created at` case, as time by `useIsoDate`
|
|
592
601
|
* - if yes, it builds `createdAt`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@samet-it/be-db-common",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "Backend DB Common",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -64,9 +64,9 @@
|
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@leyyo/query": "^1.2.2",
|
|
67
|
-
"@leyyo/common": "^1.2.
|
|
67
|
+
"@leyyo/common": "^1.2.4",
|
|
68
68
|
"@leyyo/type": "^1.1.1",
|
|
69
|
-
"@samet-it/be-base-common": "^1.1.
|
|
70
|
-
"@samet-it/be-cache-common": "^1.1.
|
|
69
|
+
"@samet-it/be-base-common": "^1.1.4",
|
|
70
|
+
"@samet-it/be-cache-common": "^1.1.6"
|
|
71
71
|
}
|
|
72
72
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type DbErrorOmit = Omit<Error, 'message' | 'name' | 'stack'>;
|