@decaf-ts/core 0.7.2 → 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 +52 -51
- package/lib/esm/persistence/Adapter.js +76 -61
- 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 +81 -66
- package/lib/persistence/Adapter.d.ts +52 -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,38 +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 pk - The primary key property name
|
|
311
317
|
* @param args - optional args for subclassing purposes
|
|
312
318
|
* @return The prepared data
|
|
313
319
|
*/
|
|
314
|
-
prepare(model,
|
|
315
|
-
|
|
316
|
-
...args) {
|
|
317
|
-
const log = this.log.for(this.prepare);
|
|
320
|
+
prepare(model, ...args) {
|
|
321
|
+
const { log } = this.logCtx(args, this.prepare);
|
|
318
322
|
const split = model.segregate();
|
|
319
323
|
const result = Object.entries(split.model).reduce((accum, [key, val]) => {
|
|
320
324
|
if (typeof val === "undefined")
|
|
321
325
|
return accum;
|
|
322
|
-
const mappedProp =
|
|
326
|
+
const mappedProp = decorator_validation_1.Model.columnName(model.constructor, key);
|
|
323
327
|
if (this.isReserved(mappedProp))
|
|
324
328
|
throw new db_decorators_1.InternalError(`Property name ${mappedProp} is reserved`);
|
|
325
329
|
accum[mappedProp] = val;
|
|
326
330
|
return accum;
|
|
327
331
|
}, {});
|
|
328
332
|
if (model[constants_1.PersistenceKeys.METADATA]) {
|
|
333
|
+
// TODO movo to couchdb
|
|
329
334
|
log.silly(`Passing along persistence metadata for ${model[constants_1.PersistenceKeys.METADATA]}`);
|
|
330
335
|
Object.defineProperty(result, constants_1.PersistenceKeys.METADATA, {
|
|
331
336
|
enumerable: false,
|
|
332
|
-
writable:
|
|
337
|
+
writable: true,
|
|
333
338
|
configurable: true,
|
|
334
339
|
value: model[constants_1.PersistenceKeys.METADATA],
|
|
335
340
|
});
|
|
336
341
|
}
|
|
337
342
|
return {
|
|
338
343
|
record: result,
|
|
339
|
-
id: model[pk],
|
|
344
|
+
id: model[decorator_validation_1.Model.pk(model.constructor)],
|
|
340
345
|
transient: split.transient,
|
|
341
346
|
};
|
|
342
347
|
}
|
|
@@ -346,29 +351,29 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
346
351
|
* and reattaching transient properties
|
|
347
352
|
* @template M - The model type
|
|
348
353
|
* @param obj - The database record
|
|
349
|
-
* @param {
|
|
354
|
+
* @param {Constructor<M>} clazz - The model class or name
|
|
350
355
|
* @param pk - The primary key property name
|
|
351
356
|
* @param {string|number|bigint} id - The primary key value
|
|
352
357
|
* @param [transient] - Transient properties to reattach
|
|
353
358
|
* @param [args] - options args for subclassing purposes
|
|
354
359
|
* @return {M} The reconstructed model instance
|
|
355
360
|
*/
|
|
356
|
-
revert(obj, clazz,
|
|
357
|
-
|
|
358
|
-
...args) {
|
|
359
|
-
const log = this.log.for(this.revert);
|
|
361
|
+
revert(obj, clazz, id, transient, ...args) {
|
|
362
|
+
const { log, ctx } = this.logCtx(args, this.revert);
|
|
360
363
|
const ob = {};
|
|
364
|
+
const pk = decorator_validation_1.Model.pk(clazz);
|
|
361
365
|
ob[pk] = id;
|
|
362
|
-
const m =
|
|
366
|
+
const m = new clazz(ob);
|
|
363
367
|
log.silly(`Rebuilding model ${m.constructor.name} id ${id}`);
|
|
364
|
-
const metadata = obj[constants_1.PersistenceKeys.METADATA];
|
|
368
|
+
const metadata = obj[constants_1.PersistenceKeys.METADATA]; // TODO move to couchdb
|
|
365
369
|
const result = Object.keys(m).reduce((accum, key) => {
|
|
366
370
|
if (key === pk)
|
|
367
371
|
return accum;
|
|
368
|
-
accum[key] =
|
|
372
|
+
accum[key] =
|
|
373
|
+
obj[decorator_validation_1.Model.columnName(clazz, key)];
|
|
369
374
|
return accum;
|
|
370
375
|
}, m);
|
|
371
|
-
if (transient) {
|
|
376
|
+
if (ctx.get("rebuildWithTransient") && transient) {
|
|
372
377
|
log.verbose(`re-adding transient properties: ${Object.keys(transient).join(", ")}`);
|
|
373
378
|
Object.entries(transient).forEach(([key, val]) => {
|
|
374
379
|
if (key in result)
|
|
@@ -377,11 +382,12 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
377
382
|
});
|
|
378
383
|
}
|
|
379
384
|
if (metadata) {
|
|
385
|
+
// TODO move to couchdb
|
|
380
386
|
log.silly(`Passing along ${this.flavour} persistence metadata for ${m.constructor.name} id ${id}: ${metadata}`);
|
|
381
387
|
Object.defineProperty(result, constants_1.PersistenceKeys.METADATA, {
|
|
382
388
|
enumerable: false,
|
|
383
|
-
configurable:
|
|
384
|
-
writable:
|
|
389
|
+
configurable: true,
|
|
390
|
+
writable: true,
|
|
385
391
|
value: metadata,
|
|
386
392
|
});
|
|
387
393
|
}
|
|
@@ -396,13 +402,13 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
396
402
|
* @param {...any[]} args - Additional arguments specific to the adapter implementation
|
|
397
403
|
* @return A promise that resolves to an array of created records
|
|
398
404
|
*/
|
|
399
|
-
async createAll(
|
|
405
|
+
async createAll(clazz, id, model, ...args) {
|
|
400
406
|
if (id.length !== model.length)
|
|
401
407
|
throw new db_decorators_1.InternalError("Ids and models must have the same length");
|
|
402
|
-
const log = this.
|
|
403
|
-
|
|
404
|
-
log.debug(`
|
|
405
|
-
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)));
|
|
406
412
|
}
|
|
407
413
|
/**
|
|
408
414
|
* @description Retrieves multiple records from the database
|
|
@@ -412,28 +418,28 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
412
418
|
* @param {...any[]} args - Additional arguments specific to the adapter implementation
|
|
413
419
|
* @return A promise that resolves to an array of retrieved records
|
|
414
420
|
*/
|
|
415
|
-
async readAll(
|
|
416
|
-
const log = this.
|
|
417
|
-
|
|
418
|
-
log.debug(`
|
|
419
|
-
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)));
|
|
420
426
|
}
|
|
421
427
|
/**
|
|
422
428
|
* @description Updates multiple records in the database
|
|
423
429
|
* @summary Modifies multiple existing records with the given IDs in the specified table
|
|
424
|
-
* @param {
|
|
430
|
+
* @param {Constructor<M>} tableName - The name of the table to update
|
|
425
431
|
* @param {string[]|number[]} id - The identifiers of the records to update
|
|
426
432
|
* @param model - The new data for each record
|
|
427
433
|
* @param {...any[]} args - Additional arguments specific to the adapter implementation
|
|
428
434
|
* @return A promise that resolves to an array of updated records
|
|
429
435
|
*/
|
|
430
|
-
async updateAll(
|
|
436
|
+
async updateAll(clazz, id, model, ...args) {
|
|
431
437
|
if (id.length !== model.length)
|
|
432
438
|
throw new db_decorators_1.InternalError("Ids and models must have the same length");
|
|
433
|
-
const log = this.
|
|
434
|
-
|
|
435
|
-
log.debug(`
|
|
436
|
-
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)));
|
|
437
443
|
}
|
|
438
444
|
/**
|
|
439
445
|
* @description Deletes multiple records from the database
|
|
@@ -444,10 +450,9 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
444
450
|
* @return A promise that resolves to an array of deleted records
|
|
445
451
|
*/
|
|
446
452
|
async deleteAll(tableName, id, ...args) {
|
|
447
|
-
const log =
|
|
448
|
-
log.verbose(`Deleting ${id.length} entries ${tableName} table`);
|
|
449
|
-
|
|
450
|
-
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)));
|
|
451
456
|
}
|
|
452
457
|
/**
|
|
453
458
|
* @description Registers an observer for database events
|
|
@@ -464,11 +469,10 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
464
469
|
writable: false,
|
|
465
470
|
});
|
|
466
471
|
this.observerHandler.observe(observer, filter);
|
|
467
|
-
this.log
|
|
468
|
-
|
|
469
|
-
.verbose(`Registering new observer ${observer.toString()}`);
|
|
472
|
+
const log = this.log.for(this.observe);
|
|
473
|
+
log.verbose(`Registering new observer ${observer.toString()}`);
|
|
470
474
|
if (!this.dispatch) {
|
|
471
|
-
|
|
475
|
+
log.info(`Creating dispatch for ${this.alias}`);
|
|
472
476
|
this.dispatch = this.Dispatch();
|
|
473
477
|
this.dispatch.observe(this);
|
|
474
478
|
}
|
|
@@ -500,9 +504,9 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
500
504
|
async updateObservers(table, event, id, ...args) {
|
|
501
505
|
if (!this.observerHandler)
|
|
502
506
|
throw new db_decorators_1.InternalError("ObserverHandler not initialized. Did you register any observables?");
|
|
503
|
-
const log =
|
|
504
|
-
log.verbose(`Updating ${this.observerHandler.count()} observers for adapter ${this.alias}`);
|
|
505
|
-
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);
|
|
506
510
|
}
|
|
507
511
|
/**
|
|
508
512
|
* @description Refreshes data based on a database event
|
|
@@ -522,7 +526,7 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
522
526
|
* @return {string} A string representation of the adapter
|
|
523
527
|
*/
|
|
524
528
|
toString() {
|
|
525
|
-
return `${this.flavour}
|
|
529
|
+
return `${this.flavour} adapter`;
|
|
526
530
|
}
|
|
527
531
|
/**
|
|
528
532
|
* @description Gets the adapter flavor associated with a model
|
|
@@ -553,10 +557,9 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
553
557
|
* @template CONF - The database driver config
|
|
554
558
|
* @template CONN - The database driver instance
|
|
555
559
|
* @template QUERY - The query type
|
|
556
|
-
* @template
|
|
557
|
-
* @template FLAGS - The repository flags type
|
|
560
|
+
* @template CONTEXT - The context type
|
|
558
561
|
* @param {string} flavour - The flavor name of the adapter to retrieve
|
|
559
|
-
* @return {Adapter<CONF, CONN, QUERY, CONTEXT
|
|
562
|
+
* @return {Adapter<CONF, CONN, QUERY, CONTEXT> | undefined} The adapter instance or undefined if not found
|
|
560
563
|
*/
|
|
561
564
|
static get(flavour) {
|
|
562
565
|
if (!flavour)
|
|
@@ -590,6 +593,9 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
590
593
|
}
|
|
591
594
|
}
|
|
592
595
|
static decoration() { }
|
|
596
|
+
static logCtx(args, method) {
|
|
597
|
+
return super.logCtx(args, method);
|
|
598
|
+
}
|
|
593
599
|
get client() {
|
|
594
600
|
if (!this._client) {
|
|
595
601
|
this._client = this.getClient();
|
|
@@ -629,12 +635,21 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
629
635
|
migrations() {
|
|
630
636
|
return decoration_1.Metadata.migrationsFor(this);
|
|
631
637
|
}
|
|
632
|
-
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();
|
|
633
648
|
for (const migration of migrations) {
|
|
634
649
|
try {
|
|
635
650
|
const m = new migration();
|
|
636
|
-
await m.up(
|
|
637
|
-
await m.down(
|
|
651
|
+
await m.up(qr, this, ctx);
|
|
652
|
+
await m.down(qr, this, ctx);
|
|
638
653
|
}
|
|
639
654
|
catch (e) {
|
|
640
655
|
throw new errors_1.MigrationError(e);
|
|
@@ -644,31 +659,31 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
644
659
|
}
|
|
645
660
|
exports.Adapter = Adapter;
|
|
646
661
|
__decorate([
|
|
647
|
-
(0,
|
|
662
|
+
(0, logging_1.final)(),
|
|
648
663
|
__metadata("design:type", Function),
|
|
649
664
|
__metadata("design:paramtypes", [String]),
|
|
650
665
|
__metadata("design:returntype", Promise)
|
|
651
666
|
], Adapter.prototype, "shutdownProxies", null);
|
|
652
667
|
__decorate([
|
|
653
|
-
(0,
|
|
668
|
+
(0, logging_1.final)(),
|
|
654
669
|
__metadata("design:type", Function),
|
|
655
670
|
__metadata("design:paramtypes", [String, Object, Object, Object]),
|
|
656
671
|
__metadata("design:returntype", Promise)
|
|
657
672
|
], Adapter.prototype, "context", null);
|
|
658
673
|
__decorate([
|
|
659
|
-
(0,
|
|
674
|
+
(0, logging_1.final)(),
|
|
660
675
|
__metadata("design:type", Function),
|
|
661
676
|
__metadata("design:paramtypes", [Object, Function]),
|
|
662
677
|
__metadata("design:returntype", void 0)
|
|
663
678
|
], Adapter.prototype, "observe", null);
|
|
664
679
|
__decorate([
|
|
665
|
-
(0,
|
|
680
|
+
(0, logging_1.final)(),
|
|
666
681
|
__metadata("design:type", Function),
|
|
667
682
|
__metadata("design:paramtypes", [Object]),
|
|
668
683
|
__metadata("design:returntype", void 0)
|
|
669
684
|
], Adapter.prototype, "unObserve", null);
|
|
670
685
|
__decorate([
|
|
671
|
-
(0,
|
|
686
|
+
(0, logging_1.final)(),
|
|
672
687
|
__metadata("design:type", Object),
|
|
673
688
|
__metadata("design:paramtypes", [])
|
|
674
689
|
], Adapter.prototype, "client", null);
|