@decaf-ts/core 0.7.2 → 0.7.4
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 +6 -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 +5 -11
- 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/{ram/model/RamSequenceModel.d.ts → model/SequenceModel.d.ts} +3 -3
- package/lib/esm/{ram/model/RamSequenceModel.js → model/SequenceModel.js} +12 -11
- package/lib/esm/model/SequenceModel.js.map +1 -0
- 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 +5 -4
- package/lib/esm/model/decorators.js +3 -3
- package/lib/esm/model/decorators.js.map +1 -1
- package/lib/esm/model/index.d.ts +1 -0
- package/lib/esm/model/index.js +1 -0
- package/lib/esm/model/index.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 +55 -53
- package/lib/esm/persistence/Adapter.js +85 -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 +34 -25
- package/lib/esm/persistence/Sequence.js +136 -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/generators.d.ts +14 -0
- package/lib/esm/persistence/generators.js +31 -0
- package/lib/esm/persistence/generators.js.map +1 -0
- package/lib/esm/persistence/index.d.ts +1 -0
- package/lib/esm/persistence/index.js +1 -0
- package/lib/esm/persistence/index.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 +22 -31
- package/lib/esm/ram/RamAdapter.js +36 -34
- 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/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 -3
- package/lib/esm/ram/index.js +0 -3
- 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 +107 -203
- package/lib/esm/repository/Repository.js.map +1 -1
- package/lib/esm/repository/decorators.js +4 -3
- 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 +50 -0
- package/lib/esm/utils/Services.js +154 -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 +5 -11
- 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/{ram/model/RamSequenceModel.cjs → model/SequenceModel.cjs} +14 -13
- package/lib/{ram/model/RamSequenceModel.d.ts → model/SequenceModel.d.ts} +3 -3
- package/lib/model/SequenceModel.js.map +1 -0
- 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 +3 -3
- package/lib/model/decorators.d.ts +5 -4
- package/lib/model/decorators.js.map +1 -1
- package/lib/model/index.cjs +1 -0
- package/lib/model/index.d.ts +1 -0
- package/lib/model/index.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 +90 -66
- package/lib/persistence/Adapter.d.ts +55 -53
- 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 +136 -15
- package/lib/persistence/Sequence.d.ts +34 -25
- 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/generators.cjs +36 -0
- package/lib/persistence/generators.d.ts +14 -0
- package/lib/persistence/generators.js.map +1 -0
- package/lib/persistence/index.cjs +1 -0
- package/lib/persistence/index.d.ts +1 -0
- package/lib/persistence/index.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 -33
- package/lib/ram/RamAdapter.d.ts +22 -31
- 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/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 -3
- package/lib/ram/index.d.ts +0 -3
- package/lib/ram/index.js.map +1 -1
- package/lib/ram/types.d.ts +4 -12
- package/lib/repository/Repository.cjs +108 -204
- package/lib/repository/Repository.d.ts +31 -95
- package/lib/repository/Repository.js.map +1 -1
- package/lib/repository/decorators.cjs +2 -1
- 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 +159 -0
- package/lib/utils/Services.d.ts +50 -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/esm/ram/RamSequence.d.ts +0 -75
- package/lib/esm/ram/RamSequence.js +0 -145
- package/lib/esm/ram/RamSequence.js.map +0 -1
- package/lib/esm/ram/model/RamSequenceModel.js.map +0 -1
- package/lib/esm/ram/model/index.d.ts +0 -1
- package/lib/esm/ram/model/index.js +0 -2
- package/lib/esm/ram/model/index.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
- package/lib/ram/RamSequence.cjs +0 -149
- package/lib/ram/RamSequence.d.ts +0 -75
- package/lib/ram/RamSequence.js.map +0 -1
- package/lib/ram/model/RamSequenceModel.js.map +0 -1
- package/lib/ram/model/index.cjs +0 -18
- package/lib/ram/model/index.d.ts +0 -1
- package/lib/ram/model/index.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)
|
|
@@ -262,6 +262,15 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
262
262
|
*/
|
|
263
263
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
264
264
|
async initialize(...args) { }
|
|
265
|
+
/**
|
|
266
|
+
* @description Creates a sequence generator
|
|
267
|
+
* @summary Factory method that creates a sequence generator for generating sequential values
|
|
268
|
+
* @param {SequenceOptions} options - Configuration options for the sequence
|
|
269
|
+
* @return {Promise<Sequence>} A promise that resolves to a new sequence instance
|
|
270
|
+
*/
|
|
271
|
+
async Sequence(options) {
|
|
272
|
+
return new Adapter._baseSequence(options, this);
|
|
273
|
+
}
|
|
265
274
|
/**
|
|
266
275
|
* @description Creates repository flags for an operation
|
|
267
276
|
* @summary Generates a set of flags that describe a database operation, combining default flags with overrides
|
|
@@ -276,12 +285,18 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
276
285
|
async flags(operation, model, flags,
|
|
277
286
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
278
287
|
...args) {
|
|
288
|
+
let log = (flags.logger || logging_2.Logging.for(this.toString()));
|
|
289
|
+
if (flags.correlationId)
|
|
290
|
+
log = log.for({ correlationId: flags.correlationId });
|
|
279
291
|
return Object.assign({}, db_decorators_1.DefaultRepositoryFlags, flags, {
|
|
280
|
-
affectedTables: (
|
|
292
|
+
affectedTables: (Array.isArray(model) ? model : [model]).map(decorator_validation_1.Model.tableName),
|
|
281
293
|
writeOperation: operation !== db_decorators_1.OperationKeys.READ,
|
|
282
294
|
timestamp: new Date(),
|
|
283
295
|
operation: operation,
|
|
284
|
-
ignoredValidationProperties:
|
|
296
|
+
ignoredValidationProperties: Array.isArray(model)
|
|
297
|
+
? []
|
|
298
|
+
: decoration_1.Metadata.validationExceptions(model, operation),
|
|
299
|
+
logger: log,
|
|
285
300
|
});
|
|
286
301
|
}
|
|
287
302
|
/**
|
|
@@ -297,7 +312,7 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
297
312
|
*/
|
|
298
313
|
async context(operation, overrides, model, ...args) {
|
|
299
314
|
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)}`);
|
|
315
|
+
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
316
|
const flags = await this.flags(operation, model, overrides, ...args);
|
|
302
317
|
return new this.Context().accumulate(flags);
|
|
303
318
|
}
|
|
@@ -305,38 +320,37 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
305
320
|
* @description Prepares a model for persistence
|
|
306
321
|
* @summary Converts a model instance into a format suitable for database storage,
|
|
307
322
|
* handling column mapping and separating transient properties
|
|
323
|
+
* handling column mapping and separating transient properties
|
|
308
324
|
* @template M - The model type
|
|
309
325
|
* @param {M} model - The model instance to prepare
|
|
310
|
-
* @param pk - The primary key property name
|
|
311
326
|
* @param args - optional args for subclassing purposes
|
|
312
327
|
* @return The prepared data
|
|
313
328
|
*/
|
|
314
|
-
prepare(model,
|
|
315
|
-
|
|
316
|
-
...args) {
|
|
317
|
-
const log = this.log.for(this.prepare);
|
|
329
|
+
prepare(model, ...args) {
|
|
330
|
+
const { log } = this.logCtx(args, this.prepare);
|
|
318
331
|
const split = model.segregate();
|
|
319
332
|
const result = Object.entries(split.model).reduce((accum, [key, val]) => {
|
|
320
333
|
if (typeof val === "undefined")
|
|
321
334
|
return accum;
|
|
322
|
-
const mappedProp =
|
|
335
|
+
const mappedProp = decorator_validation_1.Model.columnName(model.constructor, key);
|
|
323
336
|
if (this.isReserved(mappedProp))
|
|
324
337
|
throw new db_decorators_1.InternalError(`Property name ${mappedProp} is reserved`);
|
|
325
338
|
accum[mappedProp] = val;
|
|
326
339
|
return accum;
|
|
327
340
|
}, {});
|
|
328
341
|
if (model[constants_1.PersistenceKeys.METADATA]) {
|
|
342
|
+
// TODO movo to couchdb
|
|
329
343
|
log.silly(`Passing along persistence metadata for ${model[constants_1.PersistenceKeys.METADATA]}`);
|
|
330
344
|
Object.defineProperty(result, constants_1.PersistenceKeys.METADATA, {
|
|
331
345
|
enumerable: false,
|
|
332
|
-
writable:
|
|
346
|
+
writable: true,
|
|
333
347
|
configurable: true,
|
|
334
348
|
value: model[constants_1.PersistenceKeys.METADATA],
|
|
335
349
|
});
|
|
336
350
|
}
|
|
337
351
|
return {
|
|
338
352
|
record: result,
|
|
339
|
-
id: model[pk],
|
|
353
|
+
id: model[decorator_validation_1.Model.pk(model.constructor)],
|
|
340
354
|
transient: split.transient,
|
|
341
355
|
};
|
|
342
356
|
}
|
|
@@ -346,29 +360,29 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
346
360
|
* and reattaching transient properties
|
|
347
361
|
* @template M - The model type
|
|
348
362
|
* @param obj - The database record
|
|
349
|
-
* @param {
|
|
363
|
+
* @param {Constructor<M>} clazz - The model class or name
|
|
350
364
|
* @param pk - The primary key property name
|
|
351
365
|
* @param {string|number|bigint} id - The primary key value
|
|
352
366
|
* @param [transient] - Transient properties to reattach
|
|
353
367
|
* @param [args] - options args for subclassing purposes
|
|
354
368
|
* @return {M} The reconstructed model instance
|
|
355
369
|
*/
|
|
356
|
-
revert(obj, clazz,
|
|
357
|
-
|
|
358
|
-
...args) {
|
|
359
|
-
const log = this.log.for(this.revert);
|
|
370
|
+
revert(obj, clazz, id, transient, ...args) {
|
|
371
|
+
const { log, ctx } = this.logCtx(args, this.revert);
|
|
360
372
|
const ob = {};
|
|
373
|
+
const pk = decorator_validation_1.Model.pk(clazz);
|
|
361
374
|
ob[pk] = id;
|
|
362
|
-
const m =
|
|
375
|
+
const m = new clazz(ob);
|
|
363
376
|
log.silly(`Rebuilding model ${m.constructor.name} id ${id}`);
|
|
364
|
-
const metadata = obj[constants_1.PersistenceKeys.METADATA];
|
|
377
|
+
const metadata = obj[constants_1.PersistenceKeys.METADATA]; // TODO move to couchdb
|
|
365
378
|
const result = Object.keys(m).reduce((accum, key) => {
|
|
366
379
|
if (key === pk)
|
|
367
380
|
return accum;
|
|
368
|
-
accum[key] =
|
|
381
|
+
accum[key] =
|
|
382
|
+
obj[decorator_validation_1.Model.columnName(clazz, key)];
|
|
369
383
|
return accum;
|
|
370
384
|
}, m);
|
|
371
|
-
if (transient) {
|
|
385
|
+
if (ctx.get("rebuildWithTransient") && transient) {
|
|
372
386
|
log.verbose(`re-adding transient properties: ${Object.keys(transient).join(", ")}`);
|
|
373
387
|
Object.entries(transient).forEach(([key, val]) => {
|
|
374
388
|
if (key in result)
|
|
@@ -377,11 +391,12 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
377
391
|
});
|
|
378
392
|
}
|
|
379
393
|
if (metadata) {
|
|
394
|
+
// TODO move to couchdb
|
|
380
395
|
log.silly(`Passing along ${this.flavour} persistence metadata for ${m.constructor.name} id ${id}: ${metadata}`);
|
|
381
396
|
Object.defineProperty(result, constants_1.PersistenceKeys.METADATA, {
|
|
382
397
|
enumerable: false,
|
|
383
|
-
configurable:
|
|
384
|
-
writable:
|
|
398
|
+
configurable: true,
|
|
399
|
+
writable: true,
|
|
385
400
|
value: metadata,
|
|
386
401
|
});
|
|
387
402
|
}
|
|
@@ -396,13 +411,13 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
396
411
|
* @param {...any[]} args - Additional arguments specific to the adapter implementation
|
|
397
412
|
* @return A promise that resolves to an array of created records
|
|
398
413
|
*/
|
|
399
|
-
async createAll(
|
|
414
|
+
async createAll(clazz, id, model, ...args) {
|
|
400
415
|
if (id.length !== model.length)
|
|
401
416
|
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(
|
|
417
|
+
const { log, ctxArgs } = this.logCtx(args, this.createAll);
|
|
418
|
+
const tableLabel = decorator_validation_1.Model.tableName(clazz);
|
|
419
|
+
log.debug(`Creating ${id.length} entries ${tableLabel} table`);
|
|
420
|
+
return Promise.all(id.map((i, count) => this.create(clazz, i, model[count], ...ctxArgs)));
|
|
406
421
|
}
|
|
407
422
|
/**
|
|
408
423
|
* @description Retrieves multiple records from the database
|
|
@@ -412,28 +427,28 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
412
427
|
* @param {...any[]} args - Additional arguments specific to the adapter implementation
|
|
413
428
|
* @return A promise that resolves to an array of retrieved records
|
|
414
429
|
*/
|
|
415
|
-
async readAll(
|
|
416
|
-
const log = this.
|
|
417
|
-
|
|
418
|
-
log.debug(`
|
|
419
|
-
return Promise.all(id.map((i) => this.read(
|
|
430
|
+
async readAll(clazz, id, ...args) {
|
|
431
|
+
const { log, ctxArgs } = this.logCtx(args, this.readAll);
|
|
432
|
+
const tableName = decorator_validation_1.Model.tableName(clazz);
|
|
433
|
+
log.debug(`Reading ${id.length} entries ${tableName} table`);
|
|
434
|
+
return Promise.all(id.map((i) => this.read(clazz, i, ...ctxArgs)));
|
|
420
435
|
}
|
|
421
436
|
/**
|
|
422
437
|
* @description Updates multiple records in the database
|
|
423
438
|
* @summary Modifies multiple existing records with the given IDs in the specified table
|
|
424
|
-
* @param {
|
|
439
|
+
* @param {Constructor<M>} tableName - The name of the table to update
|
|
425
440
|
* @param {string[]|number[]} id - The identifiers of the records to update
|
|
426
441
|
* @param model - The new data for each record
|
|
427
442
|
* @param {...any[]} args - Additional arguments specific to the adapter implementation
|
|
428
443
|
* @return A promise that resolves to an array of updated records
|
|
429
444
|
*/
|
|
430
|
-
async updateAll(
|
|
445
|
+
async updateAll(clazz, id, model, ...args) {
|
|
431
446
|
if (id.length !== model.length)
|
|
432
447
|
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(
|
|
448
|
+
const { log, ctxArgs } = this.logCtx(args, this.updateAll);
|
|
449
|
+
const tableLabel = decorator_validation_1.Model.tableName(clazz);
|
|
450
|
+
log.debug(`Updating ${id.length} entries ${tableLabel} table`);
|
|
451
|
+
return Promise.all(id.map((i, count) => this.update(clazz, i, model[count], ...ctxArgs)));
|
|
437
452
|
}
|
|
438
453
|
/**
|
|
439
454
|
* @description Deletes multiple records from the database
|
|
@@ -444,10 +459,9 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
444
459
|
* @return A promise that resolves to an array of deleted records
|
|
445
460
|
*/
|
|
446
461
|
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)));
|
|
462
|
+
const { log, ctxArgs } = Adapter.logCtx(args, this.deleteAll);
|
|
463
|
+
log.verbose(`Deleting ${id.length} entries from ${tableName} table`);
|
|
464
|
+
return Promise.all(id.map((i) => this.delete(tableName, i, ...ctxArgs)));
|
|
451
465
|
}
|
|
452
466
|
/**
|
|
453
467
|
* @description Registers an observer for database events
|
|
@@ -464,11 +478,10 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
464
478
|
writable: false,
|
|
465
479
|
});
|
|
466
480
|
this.observerHandler.observe(observer, filter);
|
|
467
|
-
this.log
|
|
468
|
-
|
|
469
|
-
.verbose(`Registering new observer ${observer.toString()}`);
|
|
481
|
+
const log = this.log.for(this.observe);
|
|
482
|
+
log.verbose(`Registering new observer ${observer.toString()}`);
|
|
470
483
|
if (!this.dispatch) {
|
|
471
|
-
|
|
484
|
+
log.info(`Creating dispatch for ${this.alias}`);
|
|
472
485
|
this.dispatch = this.Dispatch();
|
|
473
486
|
this.dispatch.observe(this);
|
|
474
487
|
}
|
|
@@ -500,9 +513,9 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
500
513
|
async updateObservers(table, event, id, ...args) {
|
|
501
514
|
if (!this.observerHandler)
|
|
502
515
|
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(
|
|
516
|
+
const { log, ctxArgs } = Adapter.logCtx(args, this.updateObservers);
|
|
517
|
+
log.verbose(`Updating ${this.observerHandler.count()} observers for adapter ${this.alias}: Event: `);
|
|
518
|
+
await this.observerHandler.updateObservers(table, event, id, ...ctxArgs);
|
|
506
519
|
}
|
|
507
520
|
/**
|
|
508
521
|
* @description Refreshes data based on a database event
|
|
@@ -522,7 +535,7 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
522
535
|
* @return {string} A string representation of the adapter
|
|
523
536
|
*/
|
|
524
537
|
toString() {
|
|
525
|
-
return `${this.flavour}
|
|
538
|
+
return `${this.flavour} adapter`;
|
|
526
539
|
}
|
|
527
540
|
/**
|
|
528
541
|
* @description Gets the adapter flavor associated with a model
|
|
@@ -553,10 +566,9 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
553
566
|
* @template CONF - The database driver config
|
|
554
567
|
* @template CONN - The database driver instance
|
|
555
568
|
* @template QUERY - The query type
|
|
556
|
-
* @template
|
|
557
|
-
* @template FLAGS - The repository flags type
|
|
569
|
+
* @template CONTEXT - The context type
|
|
558
570
|
* @param {string} flavour - The flavor name of the adapter to retrieve
|
|
559
|
-
* @return {Adapter<CONF, CONN, QUERY, CONTEXT
|
|
571
|
+
* @return {Adapter<CONF, CONN, QUERY, CONTEXT> | undefined} The adapter instance or undefined if not found
|
|
560
572
|
*/
|
|
561
573
|
static get(flavour) {
|
|
562
574
|
if (!flavour)
|
|
@@ -590,6 +602,9 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
590
602
|
}
|
|
591
603
|
}
|
|
592
604
|
static decoration() { }
|
|
605
|
+
static logCtx(args, method) {
|
|
606
|
+
return super.logCtx(args, method);
|
|
607
|
+
}
|
|
593
608
|
get client() {
|
|
594
609
|
if (!this._client) {
|
|
595
610
|
this._client = this.getClient();
|
|
@@ -629,12 +644,21 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
629
644
|
migrations() {
|
|
630
645
|
return decoration_1.Metadata.migrationsFor(this);
|
|
631
646
|
}
|
|
632
|
-
async
|
|
647
|
+
async getQueryRunner() {
|
|
648
|
+
return this;
|
|
649
|
+
}
|
|
650
|
+
async migrate(migrations = this.migrations(), ...args) {
|
|
651
|
+
if (migrations instanceof db_decorators_1.Context) {
|
|
652
|
+
args = [migrations];
|
|
653
|
+
migrations = this.migrations();
|
|
654
|
+
}
|
|
655
|
+
const { ctx } = Adapter.logCtx(args, this.migrate);
|
|
656
|
+
const qr = await this.getQueryRunner();
|
|
633
657
|
for (const migration of migrations) {
|
|
634
658
|
try {
|
|
635
659
|
const m = new migration();
|
|
636
|
-
await m.up(
|
|
637
|
-
await m.down(
|
|
660
|
+
await m.up(qr, this, ctx);
|
|
661
|
+
await m.down(qr, this, ctx);
|
|
638
662
|
}
|
|
639
663
|
catch (e) {
|
|
640
664
|
throw new errors_1.MigrationError(e);
|
|
@@ -644,31 +668,31 @@ class Adapter extends logging_1.LoggedClass {
|
|
|
644
668
|
}
|
|
645
669
|
exports.Adapter = Adapter;
|
|
646
670
|
__decorate([
|
|
647
|
-
(0,
|
|
671
|
+
(0, logging_1.final)(),
|
|
648
672
|
__metadata("design:type", Function),
|
|
649
673
|
__metadata("design:paramtypes", [String]),
|
|
650
674
|
__metadata("design:returntype", Promise)
|
|
651
675
|
], Adapter.prototype, "shutdownProxies", null);
|
|
652
676
|
__decorate([
|
|
653
|
-
(0,
|
|
677
|
+
(0, logging_1.final)(),
|
|
654
678
|
__metadata("design:type", Function),
|
|
655
679
|
__metadata("design:paramtypes", [String, Object, Object, Object]),
|
|
656
680
|
__metadata("design:returntype", Promise)
|
|
657
681
|
], Adapter.prototype, "context", null);
|
|
658
682
|
__decorate([
|
|
659
|
-
(0,
|
|
683
|
+
(0, logging_1.final)(),
|
|
660
684
|
__metadata("design:type", Function),
|
|
661
685
|
__metadata("design:paramtypes", [Object, Function]),
|
|
662
686
|
__metadata("design:returntype", void 0)
|
|
663
687
|
], Adapter.prototype, "observe", null);
|
|
664
688
|
__decorate([
|
|
665
|
-
(0,
|
|
689
|
+
(0, logging_1.final)(),
|
|
666
690
|
__metadata("design:type", Function),
|
|
667
691
|
__metadata("design:paramtypes", [Object]),
|
|
668
692
|
__metadata("design:returntype", void 0)
|
|
669
693
|
], Adapter.prototype, "unObserve", null);
|
|
670
694
|
__decorate([
|
|
671
|
-
(0,
|
|
695
|
+
(0, logging_1.final)(),
|
|
672
696
|
__metadata("design:type", Object),
|
|
673
697
|
__metadata("design:paramtypes", [])
|
|
674
698
|
], Adapter.prototype, "client", null);
|