@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObserverHandler.js","sourceRoot":"","sources":["../../src/persistence/ObserverHandler.ts"],"names":[],"mappings":";;;AAEA,
|
|
1
|
+
{"version":3,"file":"ObserverHandler.js","sourceRoot":"","sources":["../../src/persistence/ObserverHandler.ts"],"names":[],"mappings":";;;AAEA,2DAKiC;AAGjC,2CAAoC;AAGpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAa,eAAe;IAA5B;QACE;;;WAGG;QACgB,cAAS,GAGtB,EAAE,CAAC;IAkHX,CAAC;IAhHC;;;;OAIG;IACH,KAAK;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;IAC/B,CAAC;IAED;;;;;;OAMG;IACH,OAAO,CAAC,QAAkB,EAAE,MAAuB;QACjD,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACtE,IAAI,KAAK,KAAK,CAAC,CAAC;YAAE,MAAM,IAAI,6BAAa,CAAC,6BAA6B,CAAC,CAAC;QACzE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED;;;;;OAKG;IACH,SAAS,CAAC,QAAkB;QAC1B,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACtE,IAAI,KAAK,KAAK,CAAC,CAAC;YAAE,MAAM,IAAI,6BAAa,CAAC,yBAAyB,CAAC,CAAC;QACrE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAClC,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Sequence = void 0;
|
|
4
|
-
const
|
|
5
|
-
const logging_1 = require("@decaf-ts/logging");
|
|
4
|
+
const decorator_validation_1 = require("@decaf-ts/decorator-validation");
|
|
6
5
|
const errors_1 = require("./errors.cjs");
|
|
6
|
+
const db_decorators_1 = require("@decaf-ts/db-decorators");
|
|
7
|
+
const ContextualLoggedClass_1 = require("./../utils/ContextualLoggedClass.cjs");
|
|
8
|
+
const Adapter_1 = require("./Adapter.cjs");
|
|
9
|
+
const Repository_1 = require("./../repository/Repository.cjs");
|
|
10
|
+
const SequenceModel_1 = require("./../model/SequenceModel.cjs");
|
|
11
|
+
const generators_1 = require("./generators.cjs");
|
|
7
12
|
/**
|
|
8
13
|
* @description Abstract base class for sequence generation
|
|
9
14
|
* @summary Provides a framework for generating sequential values (like primary keys) in the persistence layer.
|
|
@@ -50,23 +55,136 @@ const errors_1 = require("./errors.cjs");
|
|
|
50
55
|
* const nextId = await sequence.next();
|
|
51
56
|
* ```
|
|
52
57
|
*/
|
|
53
|
-
class Sequence {
|
|
54
|
-
/**
|
|
55
|
-
* @description Accessor for the logger instance
|
|
56
|
-
* @summary Gets or initializes the logger for this sequence
|
|
57
|
-
* @return {Logger} The logger instance
|
|
58
|
-
*/
|
|
59
|
-
get log() {
|
|
60
|
-
if (!this.logger)
|
|
61
|
-
this.logger = logging_1.Logging.for(this);
|
|
62
|
-
return this.logger;
|
|
63
|
-
}
|
|
58
|
+
class Sequence extends ContextualLoggedClass_1.ContextualLoggedClass {
|
|
64
59
|
/**
|
|
65
60
|
* @description Creates a new sequence instance
|
|
66
61
|
* @summary Protected constructor that initializes the sequence with the provided options
|
|
67
62
|
*/
|
|
68
|
-
constructor(options) {
|
|
63
|
+
constructor(options, adapter) {
|
|
64
|
+
super();
|
|
69
65
|
this.options = options;
|
|
66
|
+
this.adapter = adapter;
|
|
67
|
+
this.repo = Repository_1.Repository.forModel(SequenceModel_1.SequenceModel, adapter.alias);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @description Retrieves the current value of the sequence
|
|
71
|
+
* @summary Gets the current value of the sequence from storage. If the sequence
|
|
72
|
+
* doesn't exist yet, it returns the configured starting value.
|
|
73
|
+
* @return A promise that resolves to the current sequence value
|
|
74
|
+
*/
|
|
75
|
+
async current(...args) {
|
|
76
|
+
const contextArgs = await db_decorators_1.Context.args(db_decorators_1.OperationKeys.READ, SequenceModel_1.SequenceModel, args, this.adapter);
|
|
77
|
+
const ctx = contextArgs.context;
|
|
78
|
+
const { name, startWith } = this.options;
|
|
79
|
+
try {
|
|
80
|
+
const sequence = await this.repo.read(name, ctx);
|
|
81
|
+
return this.parse(sequence.current);
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
if (e instanceof db_decorators_1.NotFoundError) {
|
|
85
|
+
if (typeof startWith === "undefined")
|
|
86
|
+
throw new db_decorators_1.InternalError("Starting value is not defined for a non existing sequence");
|
|
87
|
+
try {
|
|
88
|
+
return this.parse(startWith);
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
throw new db_decorators_1.InternalError(`Failed to parse initial value for sequence ${startWith}: ${e}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
throw new db_decorators_1.InternalError(`Failed to retrieve current value for sequence ${name}: ${e}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* @description Increments the sequence value
|
|
99
|
+
* @summary Increases the current sequence value by the specified amount and persists
|
|
100
|
+
* the new value to storage. This method handles both numeric and BigInt sequence types.
|
|
101
|
+
* @param {string | number | bigint} current - The current value of the sequence
|
|
102
|
+
* @param {number} [count] - Optional amount to increment by, defaults to the sequence's incrementBy value
|
|
103
|
+
* @return A promise that resolves to the new sequence value after incrementing
|
|
104
|
+
*/
|
|
105
|
+
async increment(current, count, ctx) {
|
|
106
|
+
const { type, incrementBy, name } = this.options;
|
|
107
|
+
let next;
|
|
108
|
+
const toIncrementBy = count || incrementBy;
|
|
109
|
+
if (toIncrementBy % incrementBy !== 0)
|
|
110
|
+
throw new db_decorators_1.InternalError(`Value to increment does not consider the incrementBy setting: ${incrementBy}`);
|
|
111
|
+
switch (type) {
|
|
112
|
+
case "Number":
|
|
113
|
+
next = this.parse(current) + toIncrementBy;
|
|
114
|
+
break;
|
|
115
|
+
case "BigInt":
|
|
116
|
+
next = this.parse(current) + BigInt(toIncrementBy);
|
|
117
|
+
break;
|
|
118
|
+
case "String":
|
|
119
|
+
next = this.parse(current);
|
|
120
|
+
break;
|
|
121
|
+
case "serial":
|
|
122
|
+
next = generators_1.Serial.instance.generate(current);
|
|
123
|
+
break;
|
|
124
|
+
case "uuid":
|
|
125
|
+
next = generators_1.UUID.instance.generate(current);
|
|
126
|
+
break;
|
|
127
|
+
default:
|
|
128
|
+
throw new db_decorators_1.InternalError("Should never happen");
|
|
129
|
+
}
|
|
130
|
+
let seq;
|
|
131
|
+
// const repo = this.repo.override({
|
|
132
|
+
// ignoredValidationProperties: ["updatedAt"],
|
|
133
|
+
// });
|
|
134
|
+
try {
|
|
135
|
+
seq = await this.repo.update(new SequenceModel_1.SequenceModel({ id: name, current: next }), ctx);
|
|
136
|
+
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
if (!(e instanceof db_decorators_1.NotFoundError)) {
|
|
139
|
+
throw e;
|
|
140
|
+
}
|
|
141
|
+
try {
|
|
142
|
+
seq = await this.repo.create(new SequenceModel_1.SequenceModel({ id: name, current: next }), ctx);
|
|
143
|
+
}
|
|
144
|
+
catch (e) {
|
|
145
|
+
if (!(e instanceof db_decorators_1.ConflictError) || type !== "uuid")
|
|
146
|
+
throw e;
|
|
147
|
+
return this.increment(current, count, ctx); // retries uuids in case of conflict
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return seq.current;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* @description Gets the next value in the sequence
|
|
154
|
+
* @summary Retrieves the current value of the sequence and increments it by the
|
|
155
|
+
* configured increment amount. This is the main method used to get a new sequential value.
|
|
156
|
+
* @return A promise that resolves to the next value in the sequence
|
|
157
|
+
*/
|
|
158
|
+
async next(...argz) {
|
|
159
|
+
const contextArgs = await db_decorators_1.Context.args(db_decorators_1.OperationKeys.UPDATE, SequenceModel_1.SequenceModel, argz, this.adapter);
|
|
160
|
+
const { context, args } = contextArgs;
|
|
161
|
+
const current = await this.current(...args);
|
|
162
|
+
return this.increment(current, undefined, context);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* @description Generates a range of sequential values
|
|
166
|
+
* @summary Retrieves a specified number of sequential values from the sequence.
|
|
167
|
+
* This is useful when you need to allocate multiple IDs at once.
|
|
168
|
+
* The method increments the sequence by the total amount needed and returns all values in the range.
|
|
169
|
+
* @param {number} count - The number of sequential values to generate
|
|
170
|
+
* @return A promise that resolves to an array of sequential values
|
|
171
|
+
*/
|
|
172
|
+
async range(count, ...argz) {
|
|
173
|
+
const contextArgs = await db_decorators_1.Context.args(db_decorators_1.OperationKeys.UPDATE, SequenceModel_1.SequenceModel, argz, this.adapter);
|
|
174
|
+
const { context, args } = contextArgs;
|
|
175
|
+
const current = (await this.current(...args));
|
|
176
|
+
const incrementBy = this.parse(this.options.incrementBy);
|
|
177
|
+
const next = await this.increment(current, this.parse(count) * incrementBy, context);
|
|
178
|
+
const range = [];
|
|
179
|
+
for (let i = 1; i <= count; i++) {
|
|
180
|
+
range.push(current + incrementBy * this.parse(i));
|
|
181
|
+
}
|
|
182
|
+
if (range[range.length - 1] !== next && this.options.type !== "String")
|
|
183
|
+
throw new db_decorators_1.InternalError("Miscalculation of range");
|
|
184
|
+
return range;
|
|
185
|
+
}
|
|
186
|
+
parse(value) {
|
|
187
|
+
return Sequence.parseValue(this.options.type, value);
|
|
70
188
|
}
|
|
71
189
|
/**
|
|
72
190
|
* @description Gets the primary key sequence name for a model
|
|
@@ -76,7 +194,7 @@ class Sequence {
|
|
|
76
194
|
* @return {string} The sequence name for the model's primary key
|
|
77
195
|
*/
|
|
78
196
|
static pk(model) {
|
|
79
|
-
return
|
|
197
|
+
return decorator_validation_1.Model.sequenceName(model, "pk");
|
|
80
198
|
}
|
|
81
199
|
/**
|
|
82
200
|
* @description Parses a sequence value to the appropriate type
|
|
@@ -97,6 +215,8 @@ class Sequence {
|
|
|
97
215
|
return BigInt(value);
|
|
98
216
|
case undefined:
|
|
99
217
|
case "String":
|
|
218
|
+
case "uuid":
|
|
219
|
+
case "serial":
|
|
100
220
|
return value;
|
|
101
221
|
default:
|
|
102
222
|
throw new errors_1.UnsupportedError(`Unsupported sequence type: ${type} for adapter ${this}`);
|
|
@@ -104,4 +224,5 @@ class Sequence {
|
|
|
104
224
|
}
|
|
105
225
|
}
|
|
106
226
|
exports.Sequence = Sequence;
|
|
227
|
+
Adapter_1.Adapter["_baseSequence"] = Sequence;
|
|
107
228
|
//# sourceMappingURL=Sequence.js.map
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
2
|
import { SequenceOptions } from "../interfaces/SequenceOptions";
|
|
3
|
-
import { Logger } from "@decaf-ts/logging";
|
|
4
3
|
import { Constructor } from "@decaf-ts/decoration";
|
|
4
|
+
import { Context } from "@decaf-ts/db-decorators";
|
|
5
|
+
import { ContextualLoggedClass, MaybeContextualArg } from "../utils/ContextualLoggedClass";
|
|
6
|
+
import { Adapter } from "./Adapter";
|
|
7
|
+
import { Repo } from "../repository/Repository";
|
|
8
|
+
import { SequenceModel } from "../model/SequenceModel";
|
|
5
9
|
/**
|
|
6
10
|
* @description Abstract base class for sequence generation
|
|
7
11
|
* @summary Provides a framework for generating sequential values (like primary keys) in the persistence layer.
|
|
@@ -48,43 +52,48 @@ import { Constructor } from "@decaf-ts/decoration";
|
|
|
48
52
|
* const nextId = await sequence.next();
|
|
49
53
|
* ```
|
|
50
54
|
*/
|
|
51
|
-
export declare
|
|
55
|
+
export declare class Sequence extends ContextualLoggedClass<any> {
|
|
52
56
|
protected readonly options: SequenceOptions;
|
|
57
|
+
protected readonly adapter: Adapter<any, any, any>;
|
|
58
|
+
protected repo: Repo<SequenceModel>;
|
|
53
59
|
/**
|
|
54
|
-
* @description
|
|
55
|
-
* @summary
|
|
60
|
+
* @description Creates a new sequence instance
|
|
61
|
+
* @summary Protected constructor that initializes the sequence with the provided options
|
|
56
62
|
*/
|
|
57
|
-
|
|
63
|
+
constructor(options: SequenceOptions, adapter: Adapter<any, any, any>);
|
|
58
64
|
/**
|
|
59
|
-
* @description
|
|
60
|
-
* @summary Gets
|
|
61
|
-
*
|
|
65
|
+
* @description Retrieves the current value of the sequence
|
|
66
|
+
* @summary Gets the current value of the sequence from storage. If the sequence
|
|
67
|
+
* doesn't exist yet, it returns the configured starting value.
|
|
68
|
+
* @return A promise that resolves to the current sequence value
|
|
62
69
|
*/
|
|
63
|
-
|
|
70
|
+
current(...args: MaybeContextualArg<any>): Promise<string | number | bigint>;
|
|
64
71
|
/**
|
|
65
|
-
* @description
|
|
66
|
-
* @summary
|
|
72
|
+
* @description Increments the sequence value
|
|
73
|
+
* @summary Increases the current sequence value by the specified amount and persists
|
|
74
|
+
* the new value to storage. This method handles both numeric and BigInt sequence types.
|
|
75
|
+
* @param {string | number | bigint} current - The current value of the sequence
|
|
76
|
+
* @param {number} [count] - Optional amount to increment by, defaults to the sequence's incrementBy value
|
|
77
|
+
* @return A promise that resolves to the new sequence value after incrementing
|
|
67
78
|
*/
|
|
68
|
-
protected
|
|
79
|
+
protected increment(current: string | number | bigint, count: number | undefined, ctx: Context<any>): Promise<string | number | bigint>;
|
|
69
80
|
/**
|
|
70
81
|
* @description Gets the next value in the sequence
|
|
71
|
-
* @summary Retrieves the
|
|
82
|
+
* @summary Retrieves the current value of the sequence and increments it by the
|
|
83
|
+
* configured increment amount. This is the main method used to get a new sequential value.
|
|
72
84
|
* @return A promise that resolves to the next value in the sequence
|
|
73
85
|
*/
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* @description Gets the current value of the sequence
|
|
77
|
-
* @summary Retrieves the current value of the sequence without incrementing it
|
|
78
|
-
* @return A promise that resolves to the current value in the sequence
|
|
79
|
-
*/
|
|
80
|
-
abstract current(): Promise<string | number | bigint>;
|
|
86
|
+
next(...argz: MaybeContextualArg<any>): Promise<number | string | bigint>;
|
|
81
87
|
/**
|
|
82
|
-
* @description
|
|
83
|
-
* @summary Retrieves
|
|
84
|
-
*
|
|
88
|
+
* @description Generates a range of sequential values
|
|
89
|
+
* @summary Retrieves a specified number of sequential values from the sequence.
|
|
90
|
+
* This is useful when you need to allocate multiple IDs at once.
|
|
91
|
+
* The method increments the sequence by the total amount needed and returns all values in the range.
|
|
92
|
+
* @param {number} count - The number of sequential values to generate
|
|
85
93
|
* @return A promise that resolves to an array of sequential values
|
|
86
94
|
*/
|
|
87
|
-
|
|
95
|
+
range(count: number, ...argz: MaybeContextualArg<any>): Promise<(number | string | bigint)[]>;
|
|
96
|
+
protected parse(value: string | number | bigint): string | number | bigint;
|
|
88
97
|
/**
|
|
89
98
|
* @description Gets the primary key sequence name for a model
|
|
90
99
|
* @summary Utility method that returns the standardized sequence name for a model's primary key
|
|
@@ -100,5 +109,5 @@ export declare abstract class Sequence {
|
|
|
100
109
|
* @param {string|number|bigint} value - The value to convert
|
|
101
110
|
* @return {string|number|bigint} The converted value
|
|
102
111
|
*/
|
|
103
|
-
static parseValue(type: "Number" | "BigInt" | string | undefined, value: string | number | bigint): string | number | bigint;
|
|
112
|
+
static parseValue(type: "Number" | "BigInt" | "uuid" | "serial" | string | undefined, value: string | number | bigint): string | number | bigint;
|
|
104
113
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Sequence.js","sourceRoot":"","sources":["../../src/persistence/Sequence.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"Sequence.js","sourceRoot":"","sources":["../../src/persistence/Sequence.ts"],"names":[],"mappings":";;;AAAA,yEAA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CAAkB,KAAyB;QAClD,OAAO,4BAAK,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACzC,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CACf,IAAkE,EAClE,KAA+B;QAE/B,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,QAAQ;gBACX,OAAO,OAAO,KAAK,KAAK,QAAQ;oBAC9B,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;oBACjB,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ;wBACzB,CAAC,CAAC,KAAK;wBACP,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACtB,KAAK,QAAQ;gBACX,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;YACvB,KAAK,SAAS,CAAC;YACf,KAAK,QAAQ,CAAC;YACd,KAAK,MAAM,CAAC;YACZ,KAAK,QAAQ;gBACX,OAAO,KAAK,CAAC;YACf;gBACE,MAAM,IAAI,yBAAgB,CACxB,8BAA8B,IAAI,gBAAgB,IAAI,EAAE,CACzD,CAAC;QACN,CAAC;IACH,CAAC;CACF;AAhOD,4BAgOC;AAED,iBAAO,CAAC,eAAe,CAAC,GAAG,QAAQ,CAAC"}
|
|
@@ -18,6 +18,7 @@ var PersistenceKeys;
|
|
|
18
18
|
PersistenceKeys["ADAPTER"] = "adapter";
|
|
19
19
|
/** @description Template for injectable adapter names */
|
|
20
20
|
PersistenceKeys["INJECTABLE"] = "decaf_{0}_adapter_for_{1}";
|
|
21
|
+
PersistenceKeys["SERVICE"] = "service";
|
|
21
22
|
/** @description Key for table name metadata */
|
|
22
23
|
PersistenceKeys["TABLE"] = "table";
|
|
23
24
|
/** @description Key for column name metadata */
|
|
@@ -14,6 +14,7 @@ export declare enum PersistenceKeys {
|
|
|
14
14
|
ADAPTER = "adapter",
|
|
15
15
|
/** @description Template for injectable adapter names */
|
|
16
16
|
INJECTABLE = "decaf_{0}_adapter_for_{1}",
|
|
17
|
+
SERVICE = "service",
|
|
17
18
|
/** @description Key for table name metadata */
|
|
18
19
|
TABLE = "table",
|
|
19
20
|
/** @description Key for column name metadata */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/persistence/constants.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,IAAY,
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/persistence/constants.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,IAAY,eA0DX;AA1DD,WAAY,eAAe;IACzB,0CAA0C;IAC1C,kCAAe,CAAA;IAEf,sDAAsD;IACtD,oCAAiB,CAAA;IAEjB,4CAA4C;IAC5C,sCAAmB,CAAA;IAEnB,yDAAyD;IACzD,2DAAwC,CAAA;IAExC,sCAAmB,CAAA;IACnB,+CAA+C;IAC/C,kCAAe,CAAA;IAEf,gDAAgD;IAChD,oCAAiB,CAAA;IAEjB,oDAAoD;IACpD,0CAAuB,CAAA;IAEvB,YAAY;IACZ,yDAAyD;IACzD,0CAAuB,CAAA;IAEvB,yDAAyD;IACzD,sDAAsC,CAAA;IAEtC,yDAAyD;IACzD,sDAAsC,CAAA;IAEtC,YAAY;IAEZ,sDAAsD;IACtD,4CAAyB,CAAA;IAEzB,sDAAsD;IACtD,wCAAqB,CAAA;IAErB,wDAAwD;IACxD,qDAAqC,CAAA;IAErC,yDAAyD;IACzD,uDAAuC,CAAA;IAEvC,yDAAyD;IACzD,uDAAuC,CAAA;IACvC,yDAAyD;IACzD,yDAAyC,CAAA;IAEzC,6CAA6C;IAC7C,wCAAqB,CAAA;IACrB,6CAA6C;IAC7C,8CAA2B,CAAA;IAC3B,6CAA6C;IAC7C,0CAAuB,CAAA;AACzB,CAAC,EA1DW,eAAe,+BAAf,eAAe,QA0D1B"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Serial = exports.UUID = void 0;
|
|
4
|
+
class UUID {
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
|
+
generate(prev) {
|
|
7
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
8
|
+
const r = (Math.random() * 16) | 0, v = c == "x" ? r : (r & 0x3) | 0x8;
|
|
9
|
+
return v.toString(16);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
static get instance() {
|
|
13
|
+
if (!UUID._instance)
|
|
14
|
+
UUID._instance = new UUID();
|
|
15
|
+
return UUID._instance;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.UUID = UUID;
|
|
19
|
+
class Serial {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.count = 14;
|
|
22
|
+
}
|
|
23
|
+
generate(prev) {
|
|
24
|
+
prev = ((prev ? parseInt(prev) : 0) || 0);
|
|
25
|
+
return (prev + 1)
|
|
26
|
+
.toString()
|
|
27
|
+
.padStart(this.count, "0");
|
|
28
|
+
}
|
|
29
|
+
static get instance() {
|
|
30
|
+
if (!Serial._instance)
|
|
31
|
+
Serial._instance = new Serial();
|
|
32
|
+
return Serial._instance;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.Serial = Serial;
|
|
36
|
+
//# sourceMappingURL=generators.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface Generator<OUT extends string | number = string> {
|
|
2
|
+
generate(prev?: OUT): OUT;
|
|
3
|
+
}
|
|
4
|
+
export declare class UUID implements Generator {
|
|
5
|
+
private static _instance;
|
|
6
|
+
generate(prev?: string): string;
|
|
7
|
+
static get instance(): UUID;
|
|
8
|
+
}
|
|
9
|
+
export declare class Serial implements Generator {
|
|
10
|
+
private static _instance;
|
|
11
|
+
private count;
|
|
12
|
+
generate(prev?: string): string;
|
|
13
|
+
static get instance(): Serial;
|
|
14
|
+
}
|
|
@@ -0,0 +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gBC"}
|
|
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
__exportStar(require("./Dispatch.cjs"), exports);
|
|
19
19
|
__exportStar(require("./constants.cjs"), exports);
|
|
20
20
|
__exportStar(require("./errors.cjs"), exports);
|
|
21
|
+
__exportStar(require("./generators.cjs"), exports);
|
|
21
22
|
__exportStar(require("./migrations.cjs"), exports);
|
|
22
23
|
__exportStar(require("./ObserverHandler.cjs"), exports);
|
|
23
24
|
__exportStar(require("./Sequence.cjs"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/persistence/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2BAA2B;AAC3B,iDAA2B;AAC3B,kDAA4B;AAC5B,+CAAyB;AACzB,mDAA6B;AAC7B,wDAAkC;AAClC,iDAA2B;AAC3B,8CAAwB;AACxB,gDAA0B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/persistence/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2BAA2B;AAC3B,iDAA2B;AAC3B,kDAA4B;AAC5B,+CAAyB;AACzB,mDAA6B;AAC7B,mDAA6B;AAC7B,wDAAkC;AAClC,iDAA2B;AAC3B,8CAAwB;AACxB,gDAA0B"}
|
|
@@ -9,6 +9,7 @@ const logging_1 = require("@decaf-ts/logging");
|
|
|
9
9
|
const constants_1 = require("./constants.cjs");
|
|
10
10
|
const decoration_1 = require("@decaf-ts/decoration");
|
|
11
11
|
const errors_1 = require("./errors.cjs");
|
|
12
|
+
const decorator_validation_1 = require("@decaf-ts/decorator-validation");
|
|
12
13
|
function prefixMethod(obj, after, prefix, afterName) {
|
|
13
14
|
async function wrapper(...args) {
|
|
14
15
|
let results;
|
|
@@ -48,14 +49,12 @@ class AbsMigration extends logging_1.LoggedClass {
|
|
|
48
49
|
const flavour = meta.flavour;
|
|
49
50
|
return Adapter_1.Adapter.get(flavour);
|
|
50
51
|
}
|
|
51
|
-
async enforceRules(qr, adapter,
|
|
52
|
+
async enforceRules(qr, adapter, ctx) {
|
|
52
53
|
const rules = decoration_1.Metadata.get(this.constructor, constants_1.PersistenceKeys.MIGRATION)?.rules;
|
|
53
54
|
if (!rules || !rules.length)
|
|
54
55
|
return true;
|
|
55
|
-
let log;
|
|
56
56
|
for (const rule of rules) {
|
|
57
|
-
|
|
58
|
-
const result = await rule(qr, adapter, log);
|
|
57
|
+
const result = await rule(qr, adapter, ctx);
|
|
59
58
|
if (!result)
|
|
60
59
|
return false;
|
|
61
60
|
}
|
|
@@ -71,13 +70,13 @@ class AbsMigration extends logging_1.LoggedClass {
|
|
|
71
70
|
qr = qrOrAdapter;
|
|
72
71
|
qrOrAdapter = this.adapter;
|
|
73
72
|
}
|
|
74
|
-
const
|
|
75
|
-
const allowed = await this.enforceRules(qr, qrOrAdapter,
|
|
73
|
+
const ctx = await db_decorators_1.Context.args("migration", decorator_validation_1.Model, [name], qrOrAdapter);
|
|
74
|
+
const allowed = await this.enforceRules(qr, qrOrAdapter, ctx.context);
|
|
76
75
|
if (!allowed) {
|
|
77
|
-
|
|
76
|
+
ctx.context.logger.verbose(`Skipping migration ${this.constructor.name} due to rules`);
|
|
78
77
|
throw new errors_1.MigrationRuleError("Migration skipped for rule enforcement");
|
|
79
78
|
}
|
|
80
|
-
return [qr, qrOrAdapter,
|
|
79
|
+
return [qr, qrOrAdapter, ctx.context];
|
|
81
80
|
}.bind(this);
|
|
82
81
|
}
|
|
83
82
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { Migration } from "./types";
|
|
1
|
+
import { ContextOf, Migration } from "./types";
|
|
2
2
|
import { Adapter } from "./Adapter";
|
|
3
|
-
import {
|
|
4
|
-
import { LoggedClass, Logger } from "@decaf-ts/logging";
|
|
3
|
+
import { LoggedClass } from "@decaf-ts/logging";
|
|
5
4
|
export declare function prefixMethod(obj: any, after: (...args: any[]) => any, prefix: (...args: any[]) => any, afterName?: string): void;
|
|
6
|
-
export
|
|
5
|
+
export type ConnectionForAdapter<A extends Adapter<any, any, any, any>> = A extends Adapter<any, any, infer CONN, any> ? CONN : never;
|
|
6
|
+
export declare abstract class AbsMigration<A extends Adapter<any, any, any, any>, QUERYRUNNER = ConnectionForAdapter<A>> extends LoggedClass implements Migration<QUERYRUNNER, A> {
|
|
7
7
|
transaction: boolean;
|
|
8
8
|
protected constructor();
|
|
9
9
|
protected get adapter(): A;
|
|
10
|
-
protected abstract getQueryRunner(conn:
|
|
10
|
+
protected abstract getQueryRunner(conn: ConnectionForAdapter<A>): QUERYRUNNER;
|
|
11
11
|
private enforceRules;
|
|
12
12
|
private prefix;
|
|
13
|
-
abstract down(qr: QUERYRUNNER, adapter: A,
|
|
14
|
-
abstract up(qr: QUERYRUNNER, adapter: A,
|
|
13
|
+
abstract down(qr: QUERYRUNNER, adapter: A, ctx: ContextOf<A>): Promise<void>;
|
|
14
|
+
abstract up(qr: QUERYRUNNER, adapter: A, ctx: ContextOf<A>): Promise<void>;
|
|
15
15
|
}
|
|
16
|
-
export type MigrationRule<A extends Adapter<
|
|
16
|
+
export type MigrationRule<A extends Adapter<any, any, any, any> = any, QUERYRUNNER = ConnectionForAdapter<A>> = (qr: QUERYRUNNER, adapter: A, ctx: ContextOf<A>) => Promise<boolean>;
|
|
17
17
|
export type MigrationMetadata = {
|
|
18
18
|
flavour: string;
|
|
19
19
|
rules?: MigrationRule[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.js","sourceRoot":"","sources":["../../src/persistence/migrations.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"migrations.js","sourceRoot":"","sources":["../../src/persistence/migrations.ts"],"names":[],"mappings":";;;AASA,oCA0BC;AAkGD,8BAyBC;AA7JD,2CAAoC;AACpC,2DAAiE;AACjE,+CAAgD;AAChD,+CAA8C;AAC9C,qDAAsE;AACtE,yCAA8C;AAC9C,yEAAuD;AAEvD,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zB,IAAI,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC;KACvB,CAAC;SACD,KAAK,EAAE,CAAC;AACb,CAAC"}
|
|
@@ -1,7 +1,30 @@
|
|
|
1
|
-
import { BulkCrudOperationKeys, Context, OperationKeys, RepositoryFlags } from "@decaf-ts/db-decorators";
|
|
1
|
+
import { BulkCrudOperationKeys, Context, ContextOfRepository, FlagsOfContext, FlagsOfRepository, IRepository, LoggerOfContext, LoggerOfFlags, LoggerOfRepository, OperationKeys, RepositoryFlags } from "@decaf-ts/db-decorators";
|
|
2
2
|
import { Adapter } from "./Adapter";
|
|
3
|
-
import { Observable } from "../interfaces/index";
|
|
3
|
+
import { Observable, type Observer } from "../interfaces/index";
|
|
4
4
|
import { Logger } from "@decaf-ts/logging";
|
|
5
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
6
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
7
|
+
import { ContextualArgs } from "../utils/index";
|
|
8
|
+
export type ContextOf<OBJ extends IRepository<any, any> | Adapter<any, any, any, any>> = OBJ extends Adapter<any, any, any, infer C> ? C : OBJ extends IRepository<any, any> ? ContextOfRepository<OBJ> : never;
|
|
9
|
+
export type LoggerOfAdapter<A extends Adapter<any, any, any, any>> = A extends Adapter<any, any, any, infer C> ? LoggerOfContext<C> : never;
|
|
10
|
+
export type FlagsOfAdapter<A extends Adapter<any, any, any, any>> = A extends Adapter<any, any, any, infer C> ? FlagsOfContext<C> : never;
|
|
11
|
+
export type LoggerOf<OBJ extends RepositoryFlags<any> | Context<any> | Adapter<any, any, any> | IRepository<any, any>> = OBJ extends RepositoryFlags<any> ? LoggerOfFlags<OBJ> : OBJ extends Context<any> ? LoggerOfContext<OBJ> : OBJ extends IRepository<any, any> ? LoggerOfRepository<OBJ> : OBJ extends Adapter<any, any, any> ? LoggerOfAdapter<OBJ> : Logger;
|
|
12
|
+
export type FlagsOf<OBJ extends IRepository<any, any> | Adapter<any, any, any, any> | Context<any>> = OBJ extends Context<any> ? FlagsOfContext<OBJ> : OBJ extends IRepository<any, any> ? FlagsOfRepository<OBJ> : OBJ extends Adapter<any, any, any, any> ? FlagsOfAdapter<OBJ> : never;
|
|
13
|
+
export type PersistenceObservable<CONTEXT extends Context<any>> = Observable<[
|
|
14
|
+
Observer,
|
|
15
|
+
ObserverFilter?
|
|
16
|
+
], [
|
|
17
|
+
Constructor | string,
|
|
18
|
+
OperationKeys | BulkCrudOperationKeys | string,
|
|
19
|
+
EventIds,
|
|
20
|
+
...ContextualArgs<CONTEXT>
|
|
21
|
+
]>;
|
|
22
|
+
export type PersistenceObserver<CONTEXT extends Context<any>> = Observer<[
|
|
23
|
+
Constructor | string,
|
|
24
|
+
OperationKeys | BulkCrudOperationKeys | string,
|
|
25
|
+
EventIds,
|
|
26
|
+
...ContextualArgs<CONTEXT>
|
|
27
|
+
]>;
|
|
5
28
|
/**
|
|
6
29
|
* @description Type representing possible ID formats for database events
|
|
7
30
|
* @summary A union type that defines the possible formats for event identifiers in the persistence layer.
|
|
@@ -10,25 +33,20 @@ import { Logger } from "@decaf-ts/logging";
|
|
|
10
33
|
* @memberOf module:core
|
|
11
34
|
*/
|
|
12
35
|
export type EventIds = string | number | bigint | string[] | number[] | bigint[];
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
* about a specific database event. The filter examines the table name, event type, and affected IDs.
|
|
17
|
-
* @param {string} table - The name of the database table where the event occurred
|
|
18
|
-
* @param {(OperationKeys|BulkCrudOperationKeys|string)} event - The type of operation that triggered the event
|
|
19
|
-
* @param {EventIds} id - The identifier(s) of the affected record(s)
|
|
20
|
-
* @return {boolean} True if the observer should be notified, false otherwise
|
|
21
|
-
* @typedef {Function} ObserverFilter
|
|
22
|
-
* @memberOf module:core
|
|
23
|
-
*/
|
|
24
|
-
export type ObserverFilter = (table: string, event: OperationKeys | BulkCrudOperationKeys | string, id: EventIds) => boolean;
|
|
25
|
-
export type InferredAdapterConfig<A> = A extends Adapter<infer CONF, any, any, any> ? CONF : never;
|
|
26
|
-
export interface AdapterDispatch extends Observable {
|
|
36
|
+
export type ObserverFilter = (table: string | Constructor, event: OperationKeys | BulkCrudOperationKeys | string, id: EventIds, ...args: [...any[], Context<any>]) => boolean;
|
|
37
|
+
export type InferredAdapterConfig<A> = A extends Adapter<infer CONF, any, any> ? CONF : never;
|
|
38
|
+
export interface AdapterDispatch<A extends Adapter<any, any, any, any>> extends PersistenceObservable<ContextOf<A>> {
|
|
27
39
|
close(): Promise<void>;
|
|
28
|
-
updateObservers(table: string, event: OperationKeys | BulkCrudOperationKeys | string, id: EventIds): Promise<void>;
|
|
40
|
+
updateObservers<M extends Model>(table: Constructor<M> | string, event: OperationKeys | BulkCrudOperationKeys | string, id: EventIds, ...args: ContextualArgs<ContextOf<A>>): Promise<void>;
|
|
29
41
|
}
|
|
30
|
-
export interface Migration<QUERYRUNNER, A extends Adapter<
|
|
42
|
+
export interface Migration<QUERYRUNNER, A extends Adapter<any, any, any, any>> {
|
|
31
43
|
transaction: boolean;
|
|
32
|
-
up(qr: QUERYRUNNER, adapter?: A,
|
|
33
|
-
down(qr: QUERYRUNNER, adapter?: A,
|
|
44
|
+
up(qr: QUERYRUNNER, adapter?: A, ctx?: ContextOf<A>): Promise<void>;
|
|
45
|
+
down(qr: QUERYRUNNER, adapter?: A, ctx?: ContextOf<A>): Promise<void>;
|
|
34
46
|
}
|
|
47
|
+
export type RepositoryFor<A extends Adapter<any, any, any, any>> = A extends Adapter<any, any, any, any> ? ReturnType<A["repository"]> : never;
|
|
48
|
+
export type PreparedModel = {
|
|
49
|
+
record: Record<string, any>;
|
|
50
|
+
id: string;
|
|
51
|
+
transient?: Record<string, any>;
|
|
52
|
+
};
|
package/lib/query/Paginator.cjs
CHANGED
|
@@ -81,11 +81,11 @@ class Paginator extends logging_1.LoggedClass {
|
|
|
81
81
|
this.size = size;
|
|
82
82
|
this.clazz = clazz;
|
|
83
83
|
}
|
|
84
|
-
async next() {
|
|
85
|
-
return this.page(this.current + 1);
|
|
84
|
+
async next(...args) {
|
|
85
|
+
return this.page(this.current + 1, ...args);
|
|
86
86
|
}
|
|
87
|
-
async previous() {
|
|
88
|
-
return this.page(this.current - 1);
|
|
87
|
+
async previous(...args) {
|
|
88
|
+
return this.page(this.current - 1, ...args);
|
|
89
89
|
}
|
|
90
90
|
validatePage(page) {
|
|
91
91
|
if (page < 1 || !Number.isInteger(page))
|