@decaf-ts/core 0.7.1 → 0.7.3
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/README.md +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/lib/esm/identity/decorators.d.ts +3 -4
- package/lib/esm/identity/decorators.js +4 -10
- package/lib/esm/identity/decorators.js.map +1 -1
- package/lib/esm/identity/index.d.ts +0 -1
- package/lib/esm/identity/index.js +0 -1
- package/lib/esm/identity/index.js.map +1 -1
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/interfaces/ContextuallyLogged.d.ts +8 -0
- package/lib/esm/interfaces/ContextuallyLogged.js +2 -0
- package/lib/esm/interfaces/ContextuallyLogged.js.map +1 -0
- package/lib/esm/interfaces/ErrorParser.d.ts +2 -2
- package/lib/esm/interfaces/Executor.d.ts +1 -1
- package/lib/esm/interfaces/Observable.d.ts +8 -8
- package/lib/esm/interfaces/Observer.d.ts +2 -2
- package/lib/esm/interfaces/RawExecutor.d.ts +1 -1
- package/lib/esm/model/BaseModel.d.ts +2 -2
- package/lib/esm/model/BaseModel.js +2 -2
- package/lib/esm/model/construction.d.ts +9 -8
- package/lib/esm/model/construction.js +2 -2
- package/lib/esm/model/construction.js.map +1 -1
- package/lib/esm/model/decorators.d.ts +4 -3
- package/lib/esm/model/decorators.js +2 -2
- package/lib/esm/model/decorators.js.map +1 -1
- package/lib/esm/overrides/Metadata.d.ts +1 -8
- package/lib/esm/overrides/Model.d.ts +75 -0
- package/lib/esm/overrides/Model.js +2 -0
- package/lib/esm/overrides/Model.js.map +1 -0
- package/lib/esm/overrides/index.d.ts +2 -0
- package/lib/esm/overrides/index.js +2 -0
- package/lib/esm/overrides/index.js.map +1 -1
- package/lib/esm/overrides/injectables.d.ts +10 -0
- package/lib/esm/overrides/injectables.js +2 -0
- package/lib/esm/overrides/injectables.js.map +1 -0
- package/lib/esm/overrides/overrides.js +45 -3
- package/lib/esm/overrides/overrides.js.map +1 -1
- package/lib/esm/persistence/Adapter.d.ts +54 -51
- package/lib/esm/persistence/Adapter.js +78 -57
- package/lib/esm/persistence/Adapter.js.map +1 -1
- package/lib/esm/persistence/Dispatch.d.ts +7 -6
- package/lib/esm/persistence/Dispatch.js +25 -18
- package/lib/esm/persistence/Dispatch.js.map +1 -1
- package/lib/esm/persistence/ObserverHandler.d.ts +7 -6
- package/lib/esm/persistence/ObserverHandler.js +5 -4
- package/lib/esm/persistence/ObserverHandler.js.map +1 -1
- package/lib/esm/persistence/Sequence.d.ts +10 -17
- package/lib/esm/persistence/Sequence.js +10 -15
- package/lib/esm/persistence/Sequence.js.map +1 -1
- package/lib/esm/persistence/constants.d.ts +1 -0
- package/lib/esm/persistence/constants.js +1 -0
- package/lib/esm/persistence/constants.js.map +1 -1
- package/lib/esm/persistence/migrations.d.ts +8 -8
- package/lib/esm/persistence/migrations.js +8 -9
- package/lib/esm/persistence/migrations.js.map +1 -1
- package/lib/esm/persistence/types.d.ts +38 -20
- package/lib/esm/query/Paginator.d.ts +6 -5
- package/lib/esm/query/Paginator.js +4 -4
- package/lib/esm/query/Paginator.js.map +1 -1
- package/lib/esm/query/Statement.d.ts +9 -8
- package/lib/esm/query/Statement.js +23 -10
- package/lib/esm/query/Statement.js.map +1 -1
- package/lib/esm/ram/RamAdapter.d.ts +21 -21
- package/lib/esm/ram/RamAdapter.js +36 -23
- package/lib/esm/ram/RamAdapter.js.map +1 -1
- package/lib/esm/ram/RamPaginator.d.ts +2 -1
- package/lib/esm/ram/RamPaginator.js +5 -3
- package/lib/esm/ram/RamPaginator.js.map +1 -1
- package/lib/esm/ram/RamSequence.d.ts +4 -11
- package/lib/esm/ram/RamSequence.js +20 -24
- package/lib/esm/ram/RamSequence.js.map +1 -1
- package/lib/esm/ram/RamStatement.d.ts +7 -7
- package/lib/esm/ram/RamStatement.js.map +1 -1
- package/lib/esm/ram/handlers.d.ts +3 -4
- package/lib/esm/ram/handlers.js.map +1 -1
- package/lib/esm/ram/index.d.ts +0 -1
- package/lib/esm/ram/index.js +0 -1
- package/lib/esm/ram/index.js.map +1 -1
- package/lib/esm/ram/types.d.ts +4 -12
- package/lib/esm/repository/Repository.d.ts +31 -95
- package/lib/esm/repository/Repository.js +106 -201
- package/lib/esm/repository/Repository.js.map +1 -1
- package/lib/esm/repository/decorators.js +3 -2
- package/lib/esm/repository/decorators.js.map +1 -1
- package/lib/esm/repository/utils.d.ts +1 -1
- package/lib/esm/repository/utils.js +2 -3
- package/lib/esm/repository/utils.js.map +1 -1
- package/lib/esm/utils/ContextualLoggedClass.d.ts +16 -0
- package/lib/esm/utils/ContextualLoggedClass.js +29 -0
- package/lib/esm/utils/ContextualLoggedClass.js.map +1 -0
- package/lib/esm/utils/Services.d.ts +28 -0
- package/lib/esm/utils/Services.js +88 -0
- package/lib/esm/utils/Services.js.map +1 -0
- package/lib/esm/utils/decorators.d.ts +1 -9
- package/lib/esm/utils/decorators.js +26 -15
- package/lib/esm/utils/decorators.js.map +1 -1
- package/lib/esm/utils/index.d.ts +2 -1
- package/lib/esm/utils/index.js +2 -1
- package/lib/esm/utils/index.js.map +1 -1
- package/lib/identity/decorators.cjs +3 -9
- package/lib/identity/decorators.d.ts +3 -4
- package/lib/identity/decorators.js.map +1 -1
- package/lib/identity/index.cjs +0 -1
- package/lib/identity/index.d.ts +0 -1
- package/lib/identity/index.js.map +1 -1
- package/lib/index.cjs +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/interfaces/ContextuallyLogged.cjs +3 -0
- package/lib/interfaces/ContextuallyLogged.d.ts +8 -0
- package/lib/interfaces/ContextuallyLogged.js.map +1 -0
- package/lib/interfaces/ErrorParser.d.ts +2 -2
- package/lib/interfaces/Executor.d.ts +1 -1
- package/lib/interfaces/Observable.d.ts +8 -8
- package/lib/interfaces/Observer.d.ts +2 -2
- package/lib/interfaces/RawExecutor.d.ts +1 -1
- package/lib/model/BaseModel.cjs +2 -2
- package/lib/model/BaseModel.d.ts +2 -2
- package/lib/model/construction.cjs +2 -2
- package/lib/model/construction.d.ts +9 -8
- package/lib/model/construction.js.map +1 -1
- package/lib/model/decorators.cjs +1 -1
- package/lib/model/decorators.d.ts +4 -3
- package/lib/model/decorators.js.map +1 -1
- package/lib/overrides/Metadata.d.ts +1 -8
- package/lib/overrides/Model.cjs +4 -0
- package/lib/overrides/Model.d.ts +75 -0
- package/lib/overrides/Model.js.map +1 -0
- package/lib/overrides/index.cjs +2 -0
- package/lib/overrides/index.d.ts +2 -0
- package/lib/overrides/index.js.map +1 -1
- package/lib/overrides/injectables.cjs +4 -0
- package/lib/overrides/injectables.d.ts +10 -0
- package/lib/overrides/injectables.js.map +1 -0
- package/lib/overrides/overrides.cjs +43 -1
- package/lib/overrides/overrides.js.map +1 -1
- package/lib/persistence/Adapter.cjs +83 -62
- package/lib/persistence/Adapter.d.ts +54 -51
- package/lib/persistence/Adapter.js.map +1 -1
- package/lib/persistence/Dispatch.cjs +25 -18
- package/lib/persistence/Dispatch.d.ts +7 -6
- package/lib/persistence/Dispatch.js.map +1 -1
- package/lib/persistence/ObserverHandler.cjs +5 -4
- package/lib/persistence/ObserverHandler.d.ts +7 -6
- package/lib/persistence/ObserverHandler.js.map +1 -1
- package/lib/persistence/Sequence.cjs +10 -15
- package/lib/persistence/Sequence.d.ts +10 -17
- package/lib/persistence/Sequence.js.map +1 -1
- package/lib/persistence/constants.cjs +1 -0
- package/lib/persistence/constants.d.ts +1 -0
- package/lib/persistence/constants.js.map +1 -1
- package/lib/persistence/migrations.cjs +7 -8
- package/lib/persistence/migrations.d.ts +8 -8
- package/lib/persistence/migrations.js.map +1 -1
- package/lib/persistence/types.d.ts +38 -20
- package/lib/query/Paginator.cjs +4 -4
- package/lib/query/Paginator.d.ts +6 -5
- package/lib/query/Paginator.js.map +1 -1
- package/lib/query/Statement.cjs +34 -21
- package/lib/query/Statement.d.ts +9 -8
- package/lib/query/Statement.js.map +1 -1
- package/lib/ram/RamAdapter.cjs +35 -22
- package/lib/ram/RamAdapter.d.ts +21 -21
- package/lib/ram/RamAdapter.js.map +1 -1
- package/lib/ram/RamPaginator.cjs +5 -3
- package/lib/ram/RamPaginator.d.ts +2 -1
- package/lib/ram/RamPaginator.js.map +1 -1
- package/lib/ram/RamSequence.cjs +19 -23
- package/lib/ram/RamSequence.d.ts +4 -11
- package/lib/ram/RamSequence.js.map +1 -1
- package/lib/ram/RamStatement.d.ts +7 -7
- package/lib/ram/RamStatement.js.map +1 -1
- package/lib/ram/handlers.d.ts +3 -4
- package/lib/ram/handlers.js.map +1 -1
- package/lib/ram/index.cjs +0 -1
- package/lib/ram/index.d.ts +0 -1
- package/lib/ram/index.js.map +1 -1
- package/lib/ram/types.d.ts +4 -12
- package/lib/repository/Repository.cjs +107 -202
- package/lib/repository/Repository.d.ts +31 -95
- package/lib/repository/Repository.js.map +1 -1
- package/lib/repository/decorators.cjs +1 -0
- package/lib/repository/decorators.js.map +1 -1
- package/lib/repository/utils.cjs +2 -3
- package/lib/repository/utils.d.ts +1 -1
- package/lib/repository/utils.js.map +1 -1
- package/lib/utils/ContextualLoggedClass.cjs +33 -0
- package/lib/utils/ContextualLoggedClass.d.ts +16 -0
- package/lib/utils/ContextualLoggedClass.js.map +1 -0
- package/lib/utils/Services.cjs +93 -0
- package/lib/utils/Services.d.ts +28 -0
- package/lib/utils/Services.js.map +1 -0
- package/lib/utils/decorators.cjs +27 -16
- package/lib/utils/decorators.d.ts +1 -9
- package/lib/utils/decorators.js.map +1 -1
- package/lib/utils/index.cjs +2 -1
- package/lib/utils/index.d.ts +2 -1
- package/lib/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/lib/esm/identity/utils.d.ts +0 -24
- package/lib/esm/identity/utils.js +0 -44
- package/lib/esm/identity/utils.js.map +0 -1
- package/lib/esm/ram/RamContext.d.ts +0 -28
- package/lib/esm/ram/RamContext.js +0 -30
- package/lib/esm/ram/RamContext.js.map +0 -1
- package/lib/identity/utils.cjs +0 -49
- package/lib/identity/utils.d.ts +0 -24
- package/lib/identity/utils.js.map +0 -1
- package/lib/ram/RamContext.cjs +0 -34
- package/lib/ram/RamContext.d.ts +0 -28
- package/lib/ram/RamContext.js.map +0 -1
|
@@ -13,12 +13,12 @@ exports.Adapter = void 0;
|
|
|
13
13
|
const db_decorators_1 = require("@decaf-ts/db-decorators");
|
|
14
14
|
const decorator_validation_1 = require("@decaf-ts/decorator-validation");
|
|
15
15
|
const constants_1 = require("./constants.cjs");
|
|
16
|
-
const utils_1 = require("./../utils/index.cjs");
|
|
17
|
-
const ObserverHandler_1 = require("./ObserverHandler.cjs");
|
|
18
16
|
const logging_1 = require("@decaf-ts/logging");
|
|
19
|
-
const
|
|
17
|
+
const ObserverHandler_1 = require("./ObserverHandler.cjs");
|
|
18
|
+
const logging_2 = require("@decaf-ts/logging");
|
|
20
19
|
const decoration_1 = require("@decaf-ts/decoration");
|
|
21
20
|
const errors_1 = require("./errors.cjs");
|
|
21
|
+
const ContextualLoggedClass_1 = require("./../utils/ContextualLoggedClass.cjs");
|
|
22
22
|
const flavourResolver = decoration_1.Decoration["flavourResolver"].bind(decoration_1.Decoration);
|
|
23
23
|
decoration_1.Decoration["flavourResolver"] = (obj) => {
|
|
24
24
|
try {
|
|
@@ -138,7 +138,7 @@ decoration_1.Decoration["flavourResolver"] = (obj) => {
|
|
|
138
138
|
* Adapter --|> Observer
|
|
139
139
|
* Adapter --|> ErrorParser
|
|
140
140
|
*/
|
|
141
|
-
class Adapter extends
|
|
141
|
+
class Adapter extends ContextualLoggedClass_1.ContextualLoggedClass {
|
|
142
142
|
static { this._cache = {}; }
|
|
143
143
|
/**
|
|
144
144
|
* @description Gets the native persistence config
|
|
@@ -161,7 +161,7 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
161
161
|
* @description Gets the repository constructor for this adapter
|
|
162
162
|
* @summary Returns the constructor for creating repositories that work with this adapter
|
|
163
163
|
* @template M - The model type
|
|
164
|
-
* @return {Constructor<Repository<
|
|
164
|
+
* @return {Constructor<Repository<any, Adapter<CONF, CONN, QUERY, CONTEXT>>>} The repository constructor
|
|
165
165
|
*/
|
|
166
166
|
repository() {
|
|
167
167
|
if (!Adapter._baseRepository)
|
|
@@ -276,12 +276,18 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
276
276
|
async flags(operation, model, flags,
|
|
277
277
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
278
278
|
...args) {
|
|
279
|
+
let log = (flags.logger || logging_2.Logging.for(this.toString()));
|
|
280
|
+
if (flags.correlationId)
|
|
281
|
+
log = log.for({ correlationId: flags.correlationId });
|
|
279
282
|
return Object.assign({}, db_decorators_1.DefaultRepositoryFlags, flags, {
|
|
280
|
-
affectedTables: (
|
|
283
|
+
affectedTables: (Array.isArray(model) ? model : [model]).map(decorator_validation_1.Model.tableName),
|
|
281
284
|
writeOperation: operation !== db_decorators_1.OperationKeys.READ,
|
|
282
285
|
timestamp: new Date(),
|
|
283
286
|
operation: operation,
|
|
284
|
-
ignoredValidationProperties:
|
|
287
|
+
ignoredValidationProperties: Array.isArray(model)
|
|
288
|
+
? []
|
|
289
|
+
: decoration_1.Metadata.validationExceptions(model, operation),
|
|
290
|
+
logger: log,
|
|
285
291
|
});
|
|
286
292
|
}
|
|
287
293
|
/**
|
|
@@ -297,7 +303,7 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
297
303
|
*/
|
|
298
304
|
async context(operation, overrides, model, ...args) {
|
|
299
305
|
const log = this.log.for(this.context);
|
|
300
|
-
log.debug(`Creating new context for ${operation} operation on ${model.name} model with flag overrides: ${JSON.stringify(overrides)}`);
|
|
306
|
+
log.debug(`Creating new context for ${operation} operation on ${Array.isArray(model) ? model.map((m) => m.name) : model.name} model with flag overrides: ${JSON.stringify(overrides)}`);
|
|
301
307
|
const flags = await this.flags(operation, model, overrides, ...args);
|
|
302
308
|
return new this.Context().accumulate(flags);
|
|
303
309
|
}
|
|
@@ -305,35 +311,37 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
305
311
|
* @description Prepares a model for persistence
|
|
306
312
|
* @summary Converts a model instance into a format suitable for database storage,
|
|
307
313
|
* handling column mapping and separating transient properties
|
|
314
|
+
* handling column mapping and separating transient properties
|
|
308
315
|
* @template M - The model type
|
|
309
316
|
* @param {M} model - The model instance to prepare
|
|
310
|
-
* @param
|
|
317
|
+
* @param args - optional args for subclassing purposes
|
|
311
318
|
* @return The prepared data
|
|
312
319
|
*/
|
|
313
|
-
prepare(model,
|
|
314
|
-
const log = this.
|
|
320
|
+
prepare(model, ...args) {
|
|
321
|
+
const { log } = this.logCtx(args, this.prepare);
|
|
315
322
|
const split = model.segregate();
|
|
316
323
|
const result = Object.entries(split.model).reduce((accum, [key, val]) => {
|
|
317
324
|
if (typeof val === "undefined")
|
|
318
325
|
return accum;
|
|
319
|
-
const mappedProp =
|
|
326
|
+
const mappedProp = decorator_validation_1.Model.columnName(model.constructor, key);
|
|
320
327
|
if (this.isReserved(mappedProp))
|
|
321
328
|
throw new db_decorators_1.InternalError(`Property name ${mappedProp} is reserved`);
|
|
322
329
|
accum[mappedProp] = val;
|
|
323
330
|
return accum;
|
|
324
331
|
}, {});
|
|
325
332
|
if (model[constants_1.PersistenceKeys.METADATA]) {
|
|
333
|
+
// TODO movo to couchdb
|
|
326
334
|
log.silly(`Passing along persistence metadata for ${model[constants_1.PersistenceKeys.METADATA]}`);
|
|
327
335
|
Object.defineProperty(result, constants_1.PersistenceKeys.METADATA, {
|
|
328
336
|
enumerable: false,
|
|
329
|
-
writable:
|
|
337
|
+
writable: true,
|
|
330
338
|
configurable: true,
|
|
331
339
|
value: model[constants_1.PersistenceKeys.METADATA],
|
|
332
340
|
});
|
|
333
341
|
}
|
|
334
342
|
return {
|
|
335
343
|
record: result,
|
|
336
|
-
id: model[pk],
|
|
344
|
+
id: model[decorator_validation_1.Model.pk(model.constructor)],
|
|
337
345
|
transient: split.transient,
|
|
338
346
|
};
|
|
339
347
|
}
|
|
@@ -343,26 +351,29 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
343
351
|
* and reattaching transient properties
|
|
344
352
|
* @template M - The model type
|
|
345
353
|
* @param obj - The database record
|
|
346
|
-
* @param {
|
|
354
|
+
* @param {Constructor<M>} clazz - The model class or name
|
|
347
355
|
* @param pk - The primary key property name
|
|
348
356
|
* @param {string|number|bigint} id - The primary key value
|
|
349
357
|
* @param [transient] - Transient properties to reattach
|
|
358
|
+
* @param [args] - options args for subclassing purposes
|
|
350
359
|
* @return {M} The reconstructed model instance
|
|
351
360
|
*/
|
|
352
|
-
revert(obj, clazz,
|
|
353
|
-
const log = this.
|
|
361
|
+
revert(obj, clazz, id, transient, ...args) {
|
|
362
|
+
const { log, ctx } = this.logCtx(args, this.revert);
|
|
354
363
|
const ob = {};
|
|
364
|
+
const pk = decorator_validation_1.Model.pk(clazz);
|
|
355
365
|
ob[pk] = id;
|
|
356
|
-
const m =
|
|
366
|
+
const m = new clazz(ob);
|
|
357
367
|
log.silly(`Rebuilding model ${m.constructor.name} id ${id}`);
|
|
358
|
-
const metadata = obj[constants_1.PersistenceKeys.METADATA];
|
|
368
|
+
const metadata = obj[constants_1.PersistenceKeys.METADATA]; // TODO move to couchdb
|
|
359
369
|
const result = Object.keys(m).reduce((accum, key) => {
|
|
360
370
|
if (key === pk)
|
|
361
371
|
return accum;
|
|
362
|
-
accum[key] =
|
|
372
|
+
accum[key] =
|
|
373
|
+
obj[decorator_validation_1.Model.columnName(clazz, key)];
|
|
363
374
|
return accum;
|
|
364
375
|
}, m);
|
|
365
|
-
if (transient) {
|
|
376
|
+
if (ctx.get("rebuildWithTransient") && transient) {
|
|
366
377
|
log.verbose(`re-adding transient properties: ${Object.keys(transient).join(", ")}`);
|
|
367
378
|
Object.entries(transient).forEach(([key, val]) => {
|
|
368
379
|
if (key in result)
|
|
@@ -371,11 +382,12 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
371
382
|
});
|
|
372
383
|
}
|
|
373
384
|
if (metadata) {
|
|
385
|
+
// TODO move to couchdb
|
|
374
386
|
log.silly(`Passing along ${this.flavour} persistence metadata for ${m.constructor.name} id ${id}: ${metadata}`);
|
|
375
387
|
Object.defineProperty(result, constants_1.PersistenceKeys.METADATA, {
|
|
376
388
|
enumerable: false,
|
|
377
|
-
configurable:
|
|
378
|
-
writable:
|
|
389
|
+
configurable: true,
|
|
390
|
+
writable: true,
|
|
379
391
|
value: metadata,
|
|
380
392
|
});
|
|
381
393
|
}
|
|
@@ -390,13 +402,13 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
390
402
|
* @param {...any[]} args - Additional arguments specific to the adapter implementation
|
|
391
403
|
* @return A promise that resolves to an array of created records
|
|
392
404
|
*/
|
|
393
|
-
async createAll(
|
|
405
|
+
async createAll(clazz, id, model, ...args) {
|
|
394
406
|
if (id.length !== model.length)
|
|
395
407
|
throw new db_decorators_1.InternalError("Ids and models must have the same length");
|
|
396
|
-
const log = this.
|
|
397
|
-
|
|
398
|
-
log.debug(`
|
|
399
|
-
return Promise.all(id.map((i, count) => this.create(
|
|
408
|
+
const { log, ctxArgs } = this.logCtx(args, this.createAll);
|
|
409
|
+
const tableLabel = decorator_validation_1.Model.tableName(clazz);
|
|
410
|
+
log.debug(`Creating ${id.length} entries ${tableLabel} table`);
|
|
411
|
+
return Promise.all(id.map((i, count) => this.create(clazz, i, model[count], ...ctxArgs)));
|
|
400
412
|
}
|
|
401
413
|
/**
|
|
402
414
|
* @description Retrieves multiple records from the database
|
|
@@ -406,28 +418,28 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
406
418
|
* @param {...any[]} args - Additional arguments specific to the adapter implementation
|
|
407
419
|
* @return A promise that resolves to an array of retrieved records
|
|
408
420
|
*/
|
|
409
|
-
async readAll(
|
|
410
|
-
const log = this.
|
|
411
|
-
|
|
412
|
-
log.debug(`
|
|
413
|
-
return Promise.all(id.map((i) => this.read(
|
|
421
|
+
async readAll(clazz, id, ...args) {
|
|
422
|
+
const { log, ctxArgs } = this.logCtx(args, this.readAll);
|
|
423
|
+
const tableName = decorator_validation_1.Model.tableName(clazz);
|
|
424
|
+
log.debug(`Reading ${id.length} entries ${tableName} table`);
|
|
425
|
+
return Promise.all(id.map((i) => this.read(clazz, i, ...ctxArgs)));
|
|
414
426
|
}
|
|
415
427
|
/**
|
|
416
428
|
* @description Updates multiple records in the database
|
|
417
429
|
* @summary Modifies multiple existing records with the given IDs in the specified table
|
|
418
|
-
* @param {
|
|
430
|
+
* @param {Constructor<M>} tableName - The name of the table to update
|
|
419
431
|
* @param {string[]|number[]} id - The identifiers of the records to update
|
|
420
432
|
* @param model - The new data for each record
|
|
421
433
|
* @param {...any[]} args - Additional arguments specific to the adapter implementation
|
|
422
434
|
* @return A promise that resolves to an array of updated records
|
|
423
435
|
*/
|
|
424
|
-
async updateAll(
|
|
436
|
+
async updateAll(clazz, id, model, ...args) {
|
|
425
437
|
if (id.length !== model.length)
|
|
426
438
|
throw new db_decorators_1.InternalError("Ids and models must have the same length");
|
|
427
|
-
const log = this.
|
|
428
|
-
|
|
429
|
-
log.debug(`
|
|
430
|
-
return Promise.all(id.map((i, count) => this.update(
|
|
439
|
+
const { log, ctxArgs } = this.logCtx(args, this.updateAll);
|
|
440
|
+
const tableLabel = decorator_validation_1.Model.tableName(clazz);
|
|
441
|
+
log.debug(`Updating ${id.length} entries ${tableLabel} table`);
|
|
442
|
+
return Promise.all(id.map((i, count) => this.update(clazz, i, model[count], ...ctxArgs)));
|
|
431
443
|
}
|
|
432
444
|
/**
|
|
433
445
|
* @description Deletes multiple records from the database
|
|
@@ -438,10 +450,9 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
438
450
|
* @return A promise that resolves to an array of deleted records
|
|
439
451
|
*/
|
|
440
452
|
async deleteAll(tableName, id, ...args) {
|
|
441
|
-
const log =
|
|
442
|
-
log.verbose(`Deleting ${id.length} entries ${tableName} table`);
|
|
443
|
-
|
|
444
|
-
return Promise.all(id.map((i) => this.delete(tableName, i, ...args)));
|
|
453
|
+
const { log, ctxArgs } = Adapter.logCtx(args, this.deleteAll);
|
|
454
|
+
log.verbose(`Deleting ${id.length} entries from ${tableName} table`);
|
|
455
|
+
return Promise.all(id.map((i) => this.delete(tableName, i, ...ctxArgs)));
|
|
445
456
|
}
|
|
446
457
|
/**
|
|
447
458
|
* @description Registers an observer for database events
|
|
@@ -458,11 +469,10 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
458
469
|
writable: false,
|
|
459
470
|
});
|
|
460
471
|
this.observerHandler.observe(observer, filter);
|
|
461
|
-
this.log
|
|
462
|
-
|
|
463
|
-
.verbose(`Registering new observer ${observer.toString()}`);
|
|
472
|
+
const log = this.log.for(this.observe);
|
|
473
|
+
log.verbose(`Registering new observer ${observer.toString()}`);
|
|
464
474
|
if (!this.dispatch) {
|
|
465
|
-
|
|
475
|
+
log.info(`Creating dispatch for ${this.alias}`);
|
|
466
476
|
this.dispatch = this.Dispatch();
|
|
467
477
|
this.dispatch.observe(this);
|
|
468
478
|
}
|
|
@@ -494,9 +504,9 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
494
504
|
async updateObservers(table, event, id, ...args) {
|
|
495
505
|
if (!this.observerHandler)
|
|
496
506
|
throw new db_decorators_1.InternalError("ObserverHandler not initialized. Did you register any observables?");
|
|
497
|
-
const log =
|
|
498
|
-
log.verbose(`Updating ${this.observerHandler.count()} observers for adapter ${this.alias}`);
|
|
499
|
-
await this.observerHandler.updateObservers(
|
|
507
|
+
const { log, ctxArgs } = Adapter.logCtx(args, this.updateObservers);
|
|
508
|
+
log.verbose(`Updating ${this.observerHandler.count()} observers for adapter ${this.alias}: Event: `);
|
|
509
|
+
await this.observerHandler.updateObservers(table, event, id, ...ctxArgs);
|
|
500
510
|
}
|
|
501
511
|
/**
|
|
502
512
|
* @description Refreshes data based on a database event
|
|
@@ -516,7 +526,7 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
516
526
|
* @return {string} A string representation of the adapter
|
|
517
527
|
*/
|
|
518
528
|
toString() {
|
|
519
|
-
return `${this.flavour}
|
|
529
|
+
return `${this.flavour} adapter`;
|
|
520
530
|
}
|
|
521
531
|
/**
|
|
522
532
|
* @description Gets the adapter flavor associated with a model
|
|
@@ -547,10 +557,9 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
547
557
|
* @template CONF - The database driver config
|
|
548
558
|
* @template CONN - The database driver instance
|
|
549
559
|
* @template QUERY - The query type
|
|
550
|
-
* @template
|
|
551
|
-
* @template FLAGS - The repository flags type
|
|
560
|
+
* @template CONTEXT - The context type
|
|
552
561
|
* @param {string} flavour - The flavor name of the adapter to retrieve
|
|
553
|
-
* @return {Adapter<CONF, CONN, QUERY, CONTEXT
|
|
562
|
+
* @return {Adapter<CONF, CONN, QUERY, CONTEXT> | undefined} The adapter instance or undefined if not found
|
|
554
563
|
*/
|
|
555
564
|
static get(flavour) {
|
|
556
565
|
if (!flavour)
|
|
@@ -584,6 +593,9 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
584
593
|
}
|
|
585
594
|
}
|
|
586
595
|
static decoration() { }
|
|
596
|
+
static logCtx(args, method) {
|
|
597
|
+
return super.logCtx(args, method);
|
|
598
|
+
}
|
|
587
599
|
get client() {
|
|
588
600
|
if (!this._client) {
|
|
589
601
|
this._client = this.getClient();
|
|
@@ -623,12 +635,21 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
623
635
|
migrations() {
|
|
624
636
|
return decoration_1.Metadata.migrationsFor(this);
|
|
625
637
|
}
|
|
626
|
-
async
|
|
638
|
+
async getQueryRunner() {
|
|
639
|
+
return this;
|
|
640
|
+
}
|
|
641
|
+
async migrate(migrations = this.migrations(), ...args) {
|
|
642
|
+
if (migrations instanceof db_decorators_1.Context) {
|
|
643
|
+
args = [migrations];
|
|
644
|
+
migrations = this.migrations();
|
|
645
|
+
}
|
|
646
|
+
const { ctx } = Adapter.logCtx(args, this.migrate);
|
|
647
|
+
const qr = await this.getQueryRunner();
|
|
627
648
|
for (const migration of migrations) {
|
|
628
649
|
try {
|
|
629
650
|
const m = new migration();
|
|
630
|
-
await m.up(
|
|
631
|
-
await m.down(
|
|
651
|
+
await m.up(qr, this, ctx);
|
|
652
|
+
await m.down(qr, this, ctx);
|
|
632
653
|
}
|
|
633
654
|
catch (e) {
|
|
634
655
|
throw new errors_1.MigrationError(e);
|
|
@@ -638,31 +659,31 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
638
659
|
}
|
|
639
660
|
exports.Adapter = Adapter;
|
|
640
661
|
__decorate([
|
|
641
|
-
(0,
|
|
662
|
+
(0, logging_1.final)(),
|
|
642
663
|
__metadata("design:type", Function),
|
|
643
664
|
__metadata("design:paramtypes", [String]),
|
|
644
665
|
__metadata("design:returntype", Promise)
|
|
645
666
|
], Adapter.prototype, "shutdownProxies", null);
|
|
646
667
|
__decorate([
|
|
647
|
-
(0,
|
|
668
|
+
(0, logging_1.final)(),
|
|
648
669
|
__metadata("design:type", Function),
|
|
649
670
|
__metadata("design:paramtypes", [String, Object, Object, Object]),
|
|
650
671
|
__metadata("design:returntype", Promise)
|
|
651
672
|
], Adapter.prototype, "context", null);
|
|
652
673
|
__decorate([
|
|
653
|
-
(0,
|
|
674
|
+
(0, logging_1.final)(),
|
|
654
675
|
__metadata("design:type", Function),
|
|
655
676
|
__metadata("design:paramtypes", [Object, Function]),
|
|
656
677
|
__metadata("design:returntype", void 0)
|
|
657
678
|
], Adapter.prototype, "observe", null);
|
|
658
679
|
__decorate([
|
|
659
|
-
(0,
|
|
680
|
+
(0, logging_1.final)(),
|
|
660
681
|
__metadata("design:type", Function),
|
|
661
682
|
__metadata("design:paramtypes", [Object]),
|
|
662
683
|
__metadata("design:returntype", void 0)
|
|
663
684
|
], Adapter.prototype, "unObserve", null);
|
|
664
685
|
__decorate([
|
|
665
|
-
(0,
|
|
686
|
+
(0, logging_1.final)(),
|
|
666
687
|
__metadata("design:type", Object),
|
|
667
688
|
__metadata("design:paramtypes", [])
|
|
668
689
|
], Adapter.prototype, "client", null);
|