@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,145 +0,0 @@
|
|
|
1
|
-
import { RamSequenceModel } from "./model/RamSequenceModel.js";
|
|
2
|
-
import { InternalError, NotFoundError } from "@decaf-ts/db-decorators";
|
|
3
|
-
import { Sequence } from "./../persistence/index.js";
|
|
4
|
-
import { Repository } from "./../repository/index.js";
|
|
5
|
-
/**
|
|
6
|
-
* @description RAM-specific sequence implementation
|
|
7
|
-
* @summary Extends the base Sequence class to provide auto-incrementing sequence functionality
|
|
8
|
-
* for the RAM adapter. This class manages sequences stored in memory, allowing for the generation
|
|
9
|
-
* of sequential identifiers for entities.
|
|
10
|
-
* @param {SequenceOptions} options - Configuration options for the sequence
|
|
11
|
-
* @param {RamAdapter} adapter - The RAM adapter instance to use for storage
|
|
12
|
-
* @class RamSequence
|
|
13
|
-
* @category Ram
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* // Create a new numeric sequence starting at 1
|
|
17
|
-
* const sequence = new RamSequence({
|
|
18
|
-
* name: 'order_sequence',
|
|
19
|
-
* type: 'Number',
|
|
20
|
-
* startWith: 1,
|
|
21
|
-
* incrementBy: 1
|
|
22
|
-
* }, ramAdapter);
|
|
23
|
-
*
|
|
24
|
-
* // Get the next value in the sequence
|
|
25
|
-
* const nextId = await sequence.next();
|
|
26
|
-
*
|
|
27
|
-
* // Get a range of values
|
|
28
|
-
* const idRange = await sequence.range(5); // Returns 5 sequential values
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export class RamSequence extends Sequence {
|
|
32
|
-
constructor(options, adapter) {
|
|
33
|
-
super(options);
|
|
34
|
-
this.repo = Repository.forModel(RamSequenceModel, adapter.alias);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* @description Retrieves the current value of the sequence
|
|
38
|
-
* @summary Gets the current value of the sequence from storage. If the sequence
|
|
39
|
-
* doesn't exist yet, it returns the configured starting value.
|
|
40
|
-
* @return A promise that resolves to the current sequence value
|
|
41
|
-
*/
|
|
42
|
-
async current() {
|
|
43
|
-
const { name, startWith } = this.options;
|
|
44
|
-
try {
|
|
45
|
-
const sequence = await this.repo.read(name);
|
|
46
|
-
return this.parse(sequence.current);
|
|
47
|
-
}
|
|
48
|
-
catch (e) {
|
|
49
|
-
if (e instanceof NotFoundError) {
|
|
50
|
-
if (typeof startWith === "undefined")
|
|
51
|
-
throw new InternalError("Starting value is not defined for a non existing sequence");
|
|
52
|
-
try {
|
|
53
|
-
return this.parse(startWith);
|
|
54
|
-
}
|
|
55
|
-
catch (e) {
|
|
56
|
-
throw new InternalError(`Failed to parse initial value for sequence ${startWith}: ${e}`);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
throw new InternalError(`Failed to retrieve current value for sequence ${name}: ${e}`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* @description Parses a value according to the sequence type
|
|
64
|
-
* @summary Converts a value to the appropriate type for the sequence (string, number, or bigint)
|
|
65
|
-
* using the base Sequence class's parseValue method.
|
|
66
|
-
* @param {string | number | bigint} value - The value to parse
|
|
67
|
-
* @return {string | number | bigint} The parsed value in the correct type
|
|
68
|
-
*/
|
|
69
|
-
parse(value) {
|
|
70
|
-
return Sequence.parseValue(this.options.type, value);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* @description Increments the sequence value
|
|
74
|
-
* @summary Increases the current sequence value by the specified amount and persists
|
|
75
|
-
* the new value to storage. This method handles both numeric and BigInt sequence types.
|
|
76
|
-
* @param {string | number | bigint} current - The current value of the sequence
|
|
77
|
-
* @param {number} [count] - Optional amount to increment by, defaults to the sequence's incrementBy value
|
|
78
|
-
* @return A promise that resolves to the new sequence value after incrementing
|
|
79
|
-
*/
|
|
80
|
-
async increment(current, count) {
|
|
81
|
-
const { type, incrementBy, name } = this.options;
|
|
82
|
-
let next;
|
|
83
|
-
const toIncrementBy = count || incrementBy;
|
|
84
|
-
if (toIncrementBy % incrementBy !== 0)
|
|
85
|
-
throw new InternalError(`Value to increment does not consider the incrementBy setting: ${incrementBy}`);
|
|
86
|
-
switch (type) {
|
|
87
|
-
case "Number":
|
|
88
|
-
next = this.parse(current) + toIncrementBy;
|
|
89
|
-
break;
|
|
90
|
-
case "BigInt":
|
|
91
|
-
next = this.parse(current) + BigInt(toIncrementBy);
|
|
92
|
-
break;
|
|
93
|
-
case "String":
|
|
94
|
-
next = this.parse(current);
|
|
95
|
-
break;
|
|
96
|
-
default:
|
|
97
|
-
throw new InternalError("Should never happen");
|
|
98
|
-
}
|
|
99
|
-
let seq;
|
|
100
|
-
const repo = this.repo.override({
|
|
101
|
-
ignoredValidationProperties: ["updatedOn"],
|
|
102
|
-
});
|
|
103
|
-
try {
|
|
104
|
-
seq = await repo.update(new RamSequenceModel({ id: name, current: next }));
|
|
105
|
-
}
|
|
106
|
-
catch (e) {
|
|
107
|
-
if (!(e instanceof NotFoundError)) {
|
|
108
|
-
throw e;
|
|
109
|
-
}
|
|
110
|
-
seq = await repo.create(new RamSequenceModel({ id: name, current: next }));
|
|
111
|
-
}
|
|
112
|
-
return seq.current;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* @description Gets the next value in the sequence
|
|
116
|
-
* @summary Retrieves the current value of the sequence and increments it by the
|
|
117
|
-
* configured increment amount. This is the main method used to get a new sequential value.
|
|
118
|
-
* @return A promise that resolves to the next value in the sequence
|
|
119
|
-
*/
|
|
120
|
-
async next() {
|
|
121
|
-
const current = await this.current();
|
|
122
|
-
return this.increment(current);
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* @description Generates a range of sequential values
|
|
126
|
-
* @summary Retrieves a specified number of sequential values from the sequence.
|
|
127
|
-
* This is useful when you need to allocate multiple IDs at once.
|
|
128
|
-
* The method increments the sequence by the total amount needed and returns all values in the range.
|
|
129
|
-
* @param {number} count - The number of sequential values to generate
|
|
130
|
-
* @return A promise that resolves to an array of sequential values
|
|
131
|
-
*/
|
|
132
|
-
async range(count) {
|
|
133
|
-
const current = (await this.current());
|
|
134
|
-
const incrementBy = this.parse(this.options.incrementBy);
|
|
135
|
-
const next = await this.increment(current, this.parse(count) * incrementBy);
|
|
136
|
-
const range = [];
|
|
137
|
-
for (let i = 1; i <= count; i++) {
|
|
138
|
-
range.push(current + incrementBy * this.parse(i));
|
|
139
|
-
}
|
|
140
|
-
if (range[range.length - 1] !== next && this.options.type !== "String")
|
|
141
|
-
throw new InternalError("Miscalculation of range");
|
|
142
|
-
return range;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
//# sourceMappingURL=RamSequence.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RamSequence.js","sourceRoot":"","sources":["../../../src/ram/RamSequence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,oCAAiC;AAC5D,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,QAAQ,EAAE,kCAAuB;AAG1C,OAAO,EAAQ,UAAU,EAAE,iCAAsB;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,WAAY,SAAQ,QAAQ;IAGvC,YAAY,OAAwB,EAAE,OAAmB;QACvD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACnE,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,OAAO;QACX,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QACzC,IAAI,CAAC;YACH,MAAM,QAAQ,GAAqB,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAc,CAAC,CAAC;YACxE,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAA0B,CAAC,CAAC;QACzD,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,IAAI,CAAC,YAAY,aAAa,EAAE,CAAC;gBAC/B,IAAI,OAAO,SAAS,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AC/C,KAAK,IAAI,CAAC,GAAW,CAAC,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;YACxC,KAAK,CAAC,IAAI,CAAC,OAAO,GAAG,WAAW,GAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAY,CAAC,CAAC;QAChE,CAAC;QACD,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,QAAQ;YACpE,MAAM,IAAI,aAAa,CAAC,yBAAyB,CAAC,CAAC;QACrD,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RamSequenceModel.js","sourceRoot":"","sources":["../../../../src/ram/model/RamSequenceModel.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAEjE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,+BAAoB;AACtD,OAAO,EAAE,EAAE,EAAE,kCAAuB;AAEpC;;;;;;;;;;;;;;;;;GAiBG;AAGI,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,SAAS;IAe7C,YAAY,GAAgC;QAC1C,KAAK,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;CACF,CAAA;AAbC;IADC,EAAE,EAAE;;4CACO;AAQZ;IAFC,QAAQ,EAAE;IACV,KAAK,EAAE;;iDACkB;AAbf,gBAAgB;IAF5B,KAAK,CAAC,eAAe,CAAC;IACtB,KAAK,EAAE;;GACK,gBAAgB,CAkB5B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./RamSequenceModel";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ram/model/index.ts"],"names":[],"mappings":"AAAA,sCAAmC"}
|
package/lib/identity/utils.cjs
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTableName = getTableName;
|
|
4
|
-
exports.getColumnName = getColumnName;
|
|
5
|
-
exports.sequenceNameForModel = sequenceNameForModel;
|
|
6
|
-
const decorator_validation_1 = require("@decaf-ts/decorator-validation");
|
|
7
|
-
const db_decorators_1 = require("@decaf-ts/db-decorators");
|
|
8
|
-
const constants_1 = require("./../persistence/constants.cjs");
|
|
9
|
-
const decoration_1 = require("@decaf-ts/decoration");
|
|
10
|
-
/**
|
|
11
|
-
* @description Gets the table name for a model
|
|
12
|
-
* @summary Retrieves the table name associated with a model by checking metadata or falling back to the constructor name
|
|
13
|
-
* @template M - Type that extends Model
|
|
14
|
-
* @param {M | Constructor<M>} model - The model instance or constructor to get the table name for
|
|
15
|
-
* @return {string} The table name for the model
|
|
16
|
-
* @function getTableName
|
|
17
|
-
* @memberOf module:core
|
|
18
|
-
*/
|
|
19
|
-
function getTableName(model) {
|
|
20
|
-
const obj = model instanceof decorator_validation_1.Model ? decorator_validation_1.Model.get(model.constructor.name) : model;
|
|
21
|
-
if (!obj)
|
|
22
|
-
throw new db_decorators_1.InternalError(`Unable to find model ${model}`);
|
|
23
|
-
const meta = decoration_1.Metadata.get(model instanceof decorator_validation_1.Model ? model.constructor : model, constants_1.PersistenceKeys.TABLE);
|
|
24
|
-
if (meta) {
|
|
25
|
-
return meta;
|
|
26
|
-
}
|
|
27
|
-
if (model instanceof decorator_validation_1.Model) {
|
|
28
|
-
return model.constructor.name;
|
|
29
|
-
}
|
|
30
|
-
return model.name;
|
|
31
|
-
}
|
|
32
|
-
function getColumnName(model, attribute) {
|
|
33
|
-
const metadata = decoration_1.Metadata.get(model instanceof decorator_validation_1.Model ? model.constructor : model, decoration_1.Metadata.key(constants_1.PersistenceKeys.COLUMN, attribute));
|
|
34
|
-
return metadata ? metadata : attribute;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* @description Generates a sequence name for a model
|
|
38
|
-
* @summary Creates a standardized sequence name by combining the table name with additional arguments
|
|
39
|
-
* @template M - Type that extends Model
|
|
40
|
-
* @param {M | Constructor<M>} model - The model instance or constructor to generate the sequence name for
|
|
41
|
-
* @param {...string} args - Additional string arguments to append to the sequence name
|
|
42
|
-
* @return {string} The generated sequence name
|
|
43
|
-
* @function sequenceNameForModel
|
|
44
|
-
* @memberOf module:core
|
|
45
|
-
*/
|
|
46
|
-
function sequenceNameForModel(model, ...args) {
|
|
47
|
-
return [getTableName(model), ...args].join("_");
|
|
48
|
-
}
|
|
49
|
-
//# sourceMappingURL=utils.js.map
|
package/lib/identity/utils.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
|
-
import { Constructor } from "@decaf-ts/decoration";
|
|
3
|
-
/**
|
|
4
|
-
* @description Gets the table name for a model
|
|
5
|
-
* @summary Retrieves the table name associated with a model by checking metadata or falling back to the constructor name
|
|
6
|
-
* @template M - Type that extends Model
|
|
7
|
-
* @param {M | Constructor<M>} model - The model instance or constructor to get the table name for
|
|
8
|
-
* @return {string} The table name for the model
|
|
9
|
-
* @function getTableName
|
|
10
|
-
* @memberOf module:core
|
|
11
|
-
*/
|
|
12
|
-
export declare function getTableName<M extends Model>(model: M | Constructor<M>): string;
|
|
13
|
-
export declare function getColumnName<M extends Model>(model: M | Constructor<M>, attribute: string): string;
|
|
14
|
-
/**
|
|
15
|
-
* @description Generates a sequence name for a model
|
|
16
|
-
* @summary Creates a standardized sequence name by combining the table name with additional arguments
|
|
17
|
-
* @template M - Type that extends Model
|
|
18
|
-
* @param {M | Constructor<M>} model - The model instance or constructor to generate the sequence name for
|
|
19
|
-
* @param {...string} args - Additional string arguments to append to the sequence name
|
|
20
|
-
* @return {string} The generated sequence name
|
|
21
|
-
* @function sequenceNameForModel
|
|
22
|
-
* @memberOf module:core
|
|
23
|
-
*/
|
|
24
|
-
export declare function sequenceNameForModel<M extends Model>(model: M | Constructor<M>, ...args: string[]): string;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/identity/utils.ts"],"names":[],"mappings":";;AAcA,oCAoBC;AAED,sCASC;AAYD,oDAKC;AA9DD,yEAAuD;AACvD,2DAAwD;AACxD,8DAA2D;AAC3D,qDAA6D;AAE7D;;;;;;;;GAQG;AACH,SAAgB,YAAY,CAC1B,KAAyB;IAEzB,MAAM,GAAG,GACP,KAAK,YAAY,4BAAK,CAAC,CAAC,CAAC,4BAAK,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAErE,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,6BAAa,CAAC,wBAAwB,KAAK,EAAE,CAAC,CAAC;IAEnE,MAAM,IAAI,GAAG,qBAAQ,CAAC,GAAG,CACvB,KAAK,YAAY,4BAAK,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAE,KAAa,EAC3D,2BAAe,CAAC,KAAK,CACtB,CAAC;IAEF,IAAI,IAAI,EAAE,CAAC;QACT,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,KAAK,YAAY,4BAAK,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC;IAChC,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC;AACpB,CAAC;AAED,SAAgB,aAAa,CAC3B,KAAyB,EACzB,SAAiB;IAEjB,MAAM,QAAQ,GAAG,qBAAQ,CAAC,GAAG,CAC3B,KAAK,YAAY,4BAAK,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAE,KAAa,EAC3D,qBAAQ,CAAC,GAAG,CAAC,2BAAe,CAAC,MAAM,EAAE,SAAS,CAAC,CAChD,CAAC;IACF,OAAO,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;AACzC,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,oBAAoB,CAClC,KAAyB,EACzB,GAAG,IAAc;IAEjB,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,CAAC"}
|
package/lib/ram/RamContext.cjs
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RamContext = void 0;
|
|
4
|
-
const db_decorators_1 = require("@decaf-ts/db-decorators");
|
|
5
|
-
/**
|
|
6
|
-
* @description Context class for RAM adapter operations
|
|
7
|
-
* @summary Provides a specialized context for RAM adapter operations, extending the base Context with RAM-specific flags. This context is used to pass operation parameters and user information.
|
|
8
|
-
* @class RamContext
|
|
9
|
-
* @category Ram
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* // Create a new RAM context
|
|
13
|
-
* const context = new RamContext();
|
|
14
|
-
* // Optionally set a flag
|
|
15
|
-
* context.set('UUID', '123e4567-e89b-12d3-a456-426614174000');
|
|
16
|
-
* // Access a flag from the context
|
|
17
|
-
* const uuid = context.get('UUID');
|
|
18
|
-
* ```
|
|
19
|
-
* @mermaid
|
|
20
|
-
* sequenceDiagram
|
|
21
|
-
* participant Caller
|
|
22
|
-
* participant RamContext
|
|
23
|
-
* participant BaseContext as Context
|
|
24
|
-
* Caller->>RamContext: new RamContext()
|
|
25
|
-
* RamContext->>BaseContext: super()
|
|
26
|
-
* RamContext-->>Caller: instance
|
|
27
|
-
*/
|
|
28
|
-
class RamContext extends db_decorators_1.Context {
|
|
29
|
-
constructor() {
|
|
30
|
-
super();
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.RamContext = RamContext;
|
|
34
|
-
//# sourceMappingURL=RamContext.js.map
|
package/lib/ram/RamContext.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Context } from "@decaf-ts/db-decorators";
|
|
2
|
-
import { RamFlags } from "./types";
|
|
3
|
-
/**
|
|
4
|
-
* @description Context class for RAM adapter operations
|
|
5
|
-
* @summary Provides a specialized context for RAM adapter operations, extending the base Context with RAM-specific flags. This context is used to pass operation parameters and user information.
|
|
6
|
-
* @class RamContext
|
|
7
|
-
* @category Ram
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* // Create a new RAM context
|
|
11
|
-
* const context = new RamContext();
|
|
12
|
-
* // Optionally set a flag
|
|
13
|
-
* context.set('UUID', '123e4567-e89b-12d3-a456-426614174000');
|
|
14
|
-
* // Access a flag from the context
|
|
15
|
-
* const uuid = context.get('UUID');
|
|
16
|
-
* ```
|
|
17
|
-
* @mermaid
|
|
18
|
-
* sequenceDiagram
|
|
19
|
-
* participant Caller
|
|
20
|
-
* participant RamContext
|
|
21
|
-
* participant BaseContext as Context
|
|
22
|
-
* Caller->>RamContext: new RamContext()
|
|
23
|
-
* RamContext->>BaseContext: super()
|
|
24
|
-
* RamContext-->>Caller: instance
|
|
25
|
-
*/
|
|
26
|
-
export declare class RamContext extends Context<RamFlags> {
|
|
27
|
-
constructor();
|
|
28
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RamContext.js","sourceRoot":"","sources":["../../src/ram/RamContext.ts"],"names":[],"mappings":";;;AAAA,2DAAkD;AAGlD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAa,UAAW,SAAQ,uBAAiB;IAC/C;QACE,KAAK,EAAE,CAAC;IACV,CAAC;CACF;AAJD,gCAIC"}
|
package/lib/ram/RamSequence.cjs
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RamSequence = void 0;
|
|
4
|
-
const RamSequenceModel_1 = require("./model/RamSequenceModel.cjs");
|
|
5
|
-
const db_decorators_1 = require("@decaf-ts/db-decorators");
|
|
6
|
-
const persistence_1 = require("./../persistence/index.cjs");
|
|
7
|
-
const repository_1 = require("./../repository/index.cjs");
|
|
8
|
-
/**
|
|
9
|
-
* @description RAM-specific sequence implementation
|
|
10
|
-
* @summary Extends the base Sequence class to provide auto-incrementing sequence functionality
|
|
11
|
-
* for the RAM adapter. This class manages sequences stored in memory, allowing for the generation
|
|
12
|
-
* of sequential identifiers for entities.
|
|
13
|
-
* @param {SequenceOptions} options - Configuration options for the sequence
|
|
14
|
-
* @param {RamAdapter} adapter - The RAM adapter instance to use for storage
|
|
15
|
-
* @class RamSequence
|
|
16
|
-
* @category Ram
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* // Create a new numeric sequence starting at 1
|
|
20
|
-
* const sequence = new RamSequence({
|
|
21
|
-
* name: 'order_sequence',
|
|
22
|
-
* type: 'Number',
|
|
23
|
-
* startWith: 1,
|
|
24
|
-
* incrementBy: 1
|
|
25
|
-
* }, ramAdapter);
|
|
26
|
-
*
|
|
27
|
-
* // Get the next value in the sequence
|
|
28
|
-
* const nextId = await sequence.next();
|
|
29
|
-
*
|
|
30
|
-
* // Get a range of values
|
|
31
|
-
* const idRange = await sequence.range(5); // Returns 5 sequential values
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
class RamSequence extends persistence_1.Sequence {
|
|
35
|
-
constructor(options, adapter) {
|
|
36
|
-
super(options);
|
|
37
|
-
this.repo = repository_1.Repository.forModel(RamSequenceModel_1.RamSequenceModel, adapter.alias);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* @description Retrieves the current value of the sequence
|
|
41
|
-
* @summary Gets the current value of the sequence from storage. If the sequence
|
|
42
|
-
* doesn't exist yet, it returns the configured starting value.
|
|
43
|
-
* @return A promise that resolves to the current sequence value
|
|
44
|
-
*/
|
|
45
|
-
async current() {
|
|
46
|
-
const { name, startWith } = this.options;
|
|
47
|
-
try {
|
|
48
|
-
const sequence = await this.repo.read(name);
|
|
49
|
-
return this.parse(sequence.current);
|
|
50
|
-
}
|
|
51
|
-
catch (e) {
|
|
52
|
-
if (e instanceof db_decorators_1.NotFoundError) {
|
|
53
|
-
if (typeof startWith === "undefined")
|
|
54
|
-
throw new db_decorators_1.InternalError("Starting value is not defined for a non existing sequence");
|
|
55
|
-
try {
|
|
56
|
-
return this.parse(startWith);
|
|
57
|
-
}
|
|
58
|
-
catch (e) {
|
|
59
|
-
throw new db_decorators_1.InternalError(`Failed to parse initial value for sequence ${startWith}: ${e}`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
throw new db_decorators_1.InternalError(`Failed to retrieve current value for sequence ${name}: ${e}`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* @description Parses a value according to the sequence type
|
|
67
|
-
* @summary Converts a value to the appropriate type for the sequence (string, number, or bigint)
|
|
68
|
-
* using the base Sequence class's parseValue method.
|
|
69
|
-
* @param {string | number | bigint} value - The value to parse
|
|
70
|
-
* @return {string | number | bigint} The parsed value in the correct type
|
|
71
|
-
*/
|
|
72
|
-
parse(value) {
|
|
73
|
-
return persistence_1.Sequence.parseValue(this.options.type, value);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* @description Increments the sequence value
|
|
77
|
-
* @summary Increases the current sequence value by the specified amount and persists
|
|
78
|
-
* the new value to storage. This method handles both numeric and BigInt sequence types.
|
|
79
|
-
* @param {string | number | bigint} current - The current value of the sequence
|
|
80
|
-
* @param {number} [count] - Optional amount to increment by, defaults to the sequence's incrementBy value
|
|
81
|
-
* @return A promise that resolves to the new sequence value after incrementing
|
|
82
|
-
*/
|
|
83
|
-
async increment(current, count) {
|
|
84
|
-
const { type, incrementBy, name } = this.options;
|
|
85
|
-
let next;
|
|
86
|
-
const toIncrementBy = count || incrementBy;
|
|
87
|
-
if (toIncrementBy % incrementBy !== 0)
|
|
88
|
-
throw new db_decorators_1.InternalError(`Value to increment does not consider the incrementBy setting: ${incrementBy}`);
|
|
89
|
-
switch (type) {
|
|
90
|
-
case "Number":
|
|
91
|
-
next = this.parse(current) + toIncrementBy;
|
|
92
|
-
break;
|
|
93
|
-
case "BigInt":
|
|
94
|
-
next = this.parse(current) + BigInt(toIncrementBy);
|
|
95
|
-
break;
|
|
96
|
-
case "String":
|
|
97
|
-
next = this.parse(current);
|
|
98
|
-
break;
|
|
99
|
-
default:
|
|
100
|
-
throw new db_decorators_1.InternalError("Should never happen");
|
|
101
|
-
}
|
|
102
|
-
let seq;
|
|
103
|
-
const repo = this.repo.override({
|
|
104
|
-
ignoredValidationProperties: ["updatedOn"],
|
|
105
|
-
});
|
|
106
|
-
try {
|
|
107
|
-
seq = await repo.update(new RamSequenceModel_1.RamSequenceModel({ id: name, current: next }));
|
|
108
|
-
}
|
|
109
|
-
catch (e) {
|
|
110
|
-
if (!(e instanceof db_decorators_1.NotFoundError)) {
|
|
111
|
-
throw e;
|
|
112
|
-
}
|
|
113
|
-
seq = await repo.create(new RamSequenceModel_1.RamSequenceModel({ id: name, current: next }));
|
|
114
|
-
}
|
|
115
|
-
return seq.current;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* @description Gets the next value in the sequence
|
|
119
|
-
* @summary Retrieves the current value of the sequence and increments it by the
|
|
120
|
-
* configured increment amount. This is the main method used to get a new sequential value.
|
|
121
|
-
* @return A promise that resolves to the next value in the sequence
|
|
122
|
-
*/
|
|
123
|
-
async next() {
|
|
124
|
-
const current = await this.current();
|
|
125
|
-
return this.increment(current);
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* @description Generates a range of sequential values
|
|
129
|
-
* @summary Retrieves a specified number of sequential values from the sequence.
|
|
130
|
-
* This is useful when you need to allocate multiple IDs at once.
|
|
131
|
-
* The method increments the sequence by the total amount needed and returns all values in the range.
|
|
132
|
-
* @param {number} count - The number of sequential values to generate
|
|
133
|
-
* @return A promise that resolves to an array of sequential values
|
|
134
|
-
*/
|
|
135
|
-
async range(count) {
|
|
136
|
-
const current = (await this.current());
|
|
137
|
-
const incrementBy = this.parse(this.options.incrementBy);
|
|
138
|
-
const next = await this.increment(current, this.parse(count) * incrementBy);
|
|
139
|
-
const range = [];
|
|
140
|
-
for (let i = 1; i <= count; i++) {
|
|
141
|
-
range.push(current + incrementBy * this.parse(i));
|
|
142
|
-
}
|
|
143
|
-
if (range[range.length - 1] !== next && this.options.type !== "String")
|
|
144
|
-
throw new db_decorators_1.InternalError("Miscalculation of range");
|
|
145
|
-
return range;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
exports.RamSequence = RamSequence;
|
|
149
|
-
//# sourceMappingURL=RamSequence.js.map
|
package/lib/ram/RamSequence.d.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { RamSequenceModel } from "./model/RamSequenceModel";
|
|
2
|
-
import { Sequence } from "../persistence";
|
|
3
|
-
import { SequenceOptions } from "../interfaces";
|
|
4
|
-
import { RamAdapter } from "./RamAdapter";
|
|
5
|
-
import { Repo } from "../repository";
|
|
6
|
-
/**
|
|
7
|
-
* @description RAM-specific sequence implementation
|
|
8
|
-
* @summary Extends the base Sequence class to provide auto-incrementing sequence functionality
|
|
9
|
-
* for the RAM adapter. This class manages sequences stored in memory, allowing for the generation
|
|
10
|
-
* of sequential identifiers for entities.
|
|
11
|
-
* @param {SequenceOptions} options - Configuration options for the sequence
|
|
12
|
-
* @param {RamAdapter} adapter - The RAM adapter instance to use for storage
|
|
13
|
-
* @class RamSequence
|
|
14
|
-
* @category Ram
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* // Create a new numeric sequence starting at 1
|
|
18
|
-
* const sequence = new RamSequence({
|
|
19
|
-
* name: 'order_sequence',
|
|
20
|
-
* type: 'Number',
|
|
21
|
-
* startWith: 1,
|
|
22
|
-
* incrementBy: 1
|
|
23
|
-
* }, ramAdapter);
|
|
24
|
-
*
|
|
25
|
-
* // Get the next value in the sequence
|
|
26
|
-
* const nextId = await sequence.next();
|
|
27
|
-
*
|
|
28
|
-
* // Get a range of values
|
|
29
|
-
* const idRange = await sequence.range(5); // Returns 5 sequential values
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
export declare class RamSequence extends Sequence {
|
|
33
|
-
protected repo: Repo<RamSequenceModel>;
|
|
34
|
-
constructor(options: SequenceOptions, adapter: RamAdapter);
|
|
35
|
-
/**
|
|
36
|
-
* @description Retrieves the current value of the sequence
|
|
37
|
-
* @summary Gets the current value of the sequence from storage. If the sequence
|
|
38
|
-
* doesn't exist yet, it returns the configured starting value.
|
|
39
|
-
* @return A promise that resolves to the current sequence value
|
|
40
|
-
*/
|
|
41
|
-
current(): Promise<string | number | bigint>;
|
|
42
|
-
/**
|
|
43
|
-
* @description Parses a value according to the sequence type
|
|
44
|
-
* @summary Converts a value to the appropriate type for the sequence (string, number, or bigint)
|
|
45
|
-
* using the base Sequence class's parseValue method.
|
|
46
|
-
* @param {string | number | bigint} value - The value to parse
|
|
47
|
-
* @return {string | number | bigint} The parsed value in the correct type
|
|
48
|
-
*/
|
|
49
|
-
private parse;
|
|
50
|
-
/**
|
|
51
|
-
* @description Increments the sequence value
|
|
52
|
-
* @summary Increases the current sequence value by the specified amount and persists
|
|
53
|
-
* the new value to storage. This method handles both numeric and BigInt sequence types.
|
|
54
|
-
* @param {string | number | bigint} current - The current value of the sequence
|
|
55
|
-
* @param {number} [count] - Optional amount to increment by, defaults to the sequence's incrementBy value
|
|
56
|
-
* @return A promise that resolves to the new sequence value after incrementing
|
|
57
|
-
*/
|
|
58
|
-
private increment;
|
|
59
|
-
/**
|
|
60
|
-
* @description Gets the next value in the sequence
|
|
61
|
-
* @summary Retrieves the current value of the sequence and increments it by the
|
|
62
|
-
* configured increment amount. This is the main method used to get a new sequential value.
|
|
63
|
-
* @return A promise that resolves to the next value in the sequence
|
|
64
|
-
*/
|
|
65
|
-
next(): Promise<number | string | bigint>;
|
|
66
|
-
/**
|
|
67
|
-
* @description Generates a range of sequential values
|
|
68
|
-
* @summary Retrieves a specified number of sequential values from the sequence.
|
|
69
|
-
* This is useful when you need to allocate multiple IDs at once.
|
|
70
|
-
* The method increments the sequence by the total amount needed and returns all values in the range.
|
|
71
|
-
* @param {number} count - The number of sequential values to generate
|
|
72
|
-
* @return A promise that resolves to an array of sequential values
|
|
73
|
-
*/
|
|
74
|
-
range(count: number): Promise<(number | string | bigint)[]>;
|
|
75
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RamSequence.js","sourceRoot":"","sources":["../../src/ram/RamSequence.ts"],"names":[],"mappings":";;;AAAA,mEAA4D;AAC5D,2DAAuE;AACvE,4DAA0C;AAG1C,0DAAiD;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAa,WAAY,SAAQ,sBAAQ;IAGvC,YAAY,OAAwB,EAAE,OAAmB;QACvD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,uBAAU,CAAC,QAAQ,CAAC,mCAAgB,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACnE,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,OAAO;QACX,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QACzC,IAAI,CAAC;YACH,MAAM,QAAQ,GAAqB,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAc,CAAC,CAAC;YACxE,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAA0B,CAAC,CAAC;QACzD,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,IAAI,CAAC,YAAY,6BAAa,EAAE,CAAC;gBAC/B,IAAI,OAAO,SAAS,KAAK,WAAW;oBAClC,MAAM,IAAI,6BAAa,CACrB,2DAA2D,CAC5D,CAAC;gBACJ,IA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AAC,EAAE,EAAE,CAAC;YACxC,KAAK,CAAC,IAAI,CAAC,OAAO,GAAG,WAAW,GAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAY,CAAC,CAAC;QAChE,CAAC;QACD,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,QAAQ;YACpE,MAAM,IAAI,6BAAa,CAAC,yBAAyB,CAAC,CAAC;QACrD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAtID,kCAsIC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RamSequenceModel.js","sourceRoot":"","sources":["../../../src/ram/model/RamSequenceModel.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yEAAiE;AAEjE,mDAAsD;AACtD,yDAAoC;AAEpC;;;;;;;;;;;;;;;;;GAiBG;AAGI,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,iBAAS;IAe7C,YAAY,GAAgC;QAC1C,KAAK,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;CACF,CAAA;AAlBY,4CAAgB;AAK3B;IADC,IAAA,aAAE,GAAE;;4CACO;AAQZ;IAFC,IAAA,+BAAQ,GAAE;IACV,IAAA,aAAK,GAAE;;iDACkB;2BAbf,gBAAgB;IAF5B,IAAA,aAAK,EAAC,eAAe,CAAC;IACtB,IAAA,4BAAK,GAAE;;GACK,gBAAgB,CAkB5B"}
|
package/lib/ram/model/index.cjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./RamSequenceModel.cjs"), exports);
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
package/lib/ram/model/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./RamSequenceModel";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ram/model/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAmC"}
|