@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
|
@@ -15,6 +15,7 @@ export var PersistenceKeys;
|
|
|
15
15
|
PersistenceKeys["ADAPTER"] = "adapter";
|
|
16
16
|
/** @description Template for injectable adapter names */
|
|
17
17
|
PersistenceKeys["INJECTABLE"] = "decaf_{0}_adapter_for_{1}";
|
|
18
|
+
PersistenceKeys["SERVICE"] = "service";
|
|
18
19
|
/** @description Key for table name metadata */
|
|
19
20
|
PersistenceKeys["TABLE"] = "table";
|
|
20
21
|
/** @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,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/persistence/constants.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAN,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,KAAf,eAAe,QA0D1B"}
|
|
@@ -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 +1,31 @@
|
|
|
1
|
+
export class UUID {
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3
|
+
generate(prev) {
|
|
4
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
5
|
+
const r = (Math.random() * 16) | 0, v = c == "x" ? r : (r & 0x3) | 0x8;
|
|
6
|
+
return v.toString(16);
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
static get instance() {
|
|
10
|
+
if (!UUID._instance)
|
|
11
|
+
UUID._instance = new UUID();
|
|
12
|
+
return UUID._instance;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class Serial {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.count = 14;
|
|
18
|
+
}
|
|
19
|
+
generate(prev) {
|
|
20
|
+
prev = ((prev ? parseInt(prev) : 0) || 0);
|
|
21
|
+
return (prev + 1)
|
|
22
|
+
.toString()
|
|
23
|
+
.padStart(this.count, "0");
|
|
24
|
+
}
|
|
25
|
+
static get instance() {
|
|
26
|
+
if (!Serial._instance)
|
|
27
|
+
Serial._instance = new Serial();
|
|
28
|
+
return Serial._instance;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingUR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CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/persistence/index.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,8BAA2B;AAC3B,+BAA4B;AAC5B,4BAAyB;AACzB,gCAA6B;AAC7B,qCAAkC;AAClC,8BAA2B;AAC3B,2BAAwB;AACxB,6BAA0B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/persistence/index.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,8BAA2B;AAC3B,+BAA4B;AAC5B,4BAAyB;AACzB,gCAA6B;AAC7B,gCAA6B;AAC7B,qCAAkC;AAClC,8BAA2B;AAC3B,2BAAwB;AACxB,6BAA0B"}
|
|
@@ -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,9 +1,10 @@
|
|
|
1
1
|
import { Adapter } from "./Adapter.js";
|
|
2
|
-
import {
|
|
2
|
+
import { Context, InternalError } from "@decaf-ts/db-decorators";
|
|
3
3
|
import { LoggedClass } from "@decaf-ts/logging";
|
|
4
4
|
import { PersistenceKeys } from "./constants.js";
|
|
5
5
|
import { Decoration, Metadata, metadata } from "@decaf-ts/decoration";
|
|
6
6
|
import { MigrationRuleError } from "./errors.js";
|
|
7
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
7
8
|
export function prefixMethod(obj, after, prefix, afterName) {
|
|
8
9
|
async function wrapper(...args) {
|
|
9
10
|
let results;
|
|
@@ -43,14 +44,12 @@ export class AbsMigration extends LoggedClass {
|
|
|
43
44
|
const flavour = meta.flavour;
|
|
44
45
|
return Adapter.get(flavour);
|
|
45
46
|
}
|
|
46
|
-
async enforceRules(qr, adapter,
|
|
47
|
+
async enforceRules(qr, adapter, ctx) {
|
|
47
48
|
const rules = Metadata.get(this.constructor, PersistenceKeys.MIGRATION)?.rules;
|
|
48
49
|
if (!rules || !rules.length)
|
|
49
50
|
return true;
|
|
50
|
-
let log;
|
|
51
51
|
for (const rule of rules) {
|
|
52
|
-
|
|
53
|
-
const result = await rule(qr, adapter, log);
|
|
52
|
+
const result = await rule(qr, adapter, ctx);
|
|
54
53
|
if (!result)
|
|
55
54
|
return false;
|
|
56
55
|
}
|
|
@@ -66,13 +65,13 @@ export class AbsMigration extends LoggedClass {
|
|
|
66
65
|
qr = qrOrAdapter;
|
|
67
66
|
qrOrAdapter = this.adapter;
|
|
68
67
|
}
|
|
69
|
-
const
|
|
70
|
-
const allowed = await this.enforceRules(qr, qrOrAdapter,
|
|
68
|
+
const ctx = await Context.args("migration", Model, [name], qrOrAdapter);
|
|
69
|
+
const allowed = await this.enforceRules(qr, qrOrAdapter, ctx.context);
|
|
71
70
|
if (!allowed) {
|
|
72
|
-
|
|
71
|
+
ctx.context.logger.verbose(`Skipping migration ${this.constructor.name} due to rules`);
|
|
73
72
|
throw new MigrationRuleError("Migration skipped for rule enforcement");
|
|
74
73
|
}
|
|
75
|
-
return [qr, qrOrAdapter,
|
|
74
|
+
return [qr, qrOrAdapter, ctx.context];
|
|
76
75
|
}.bind(this);
|
|
77
76
|
}
|
|
78
77
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.js","sourceRoot":"","sources":["../../../src/persistence/migrations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,qBAAkB;AACpC,OAAO,
|
|
1
|
+
{"version":3,"file":"migrations.js","sourceRoot":"","sources":["../../../src/persistence/migrations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,qBAAkB;AACpC,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,uBAAoB;AAC9C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,oBAAiB;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAEvD,MAAM,UAAU,YAAY,CAC1B,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AAC;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
|
+
};
|
|
@@ -2,6 +2,7 @@ import { Adapter } from "../persistence";
|
|
|
2
2
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
3
3
|
import { Constructor } from "@decaf-ts/decoration";
|
|
4
4
|
import { LoggedClass } from "@decaf-ts/logging";
|
|
5
|
+
import { MaybeContextualArg } from "../utils/index";
|
|
5
6
|
/**
|
|
6
7
|
* @description Handles pagination for database queries
|
|
7
8
|
* @summary Provides functionality for navigating through paginated query results
|
|
@@ -59,7 +60,7 @@ import { LoggedClass } from "@decaf-ts/logging";
|
|
|
59
60
|
* Paginator-->>Client: return page results
|
|
60
61
|
*/
|
|
61
62
|
export declare abstract class Paginator<M extends Model, R = M[], Q = any> extends LoggedClass {
|
|
62
|
-
protected readonly adapter: Adapter<any, any, Q, any
|
|
63
|
+
protected readonly adapter: Adapter<any, any, Q, any>;
|
|
63
64
|
protected readonly query: Q;
|
|
64
65
|
readonly size: number;
|
|
65
66
|
protected readonly clazz: Constructor<M>;
|
|
@@ -72,10 +73,10 @@ export declare abstract class Paginator<M extends Model, R = M[], Q = any> exten
|
|
|
72
73
|
get total(): number;
|
|
73
74
|
get count(): number;
|
|
74
75
|
protected get statement(): Q;
|
|
75
|
-
protected constructor(adapter: Adapter<any, any, Q, any
|
|
76
|
+
protected constructor(adapter: Adapter<any, any, Q, any>, query: Q, size: number, clazz: Constructor<M>);
|
|
76
77
|
protected abstract prepare(rawStatement: Q): Q;
|
|
77
|
-
next(): Promise<R[]>;
|
|
78
|
-
previous(): Promise<R[]>;
|
|
78
|
+
next(...args: MaybeContextualArg<any>): Promise<R[]>;
|
|
79
|
+
previous(...args: MaybeContextualArg<any>): Promise<R[]>;
|
|
79
80
|
protected validatePage(page: number): number;
|
|
80
|
-
abstract page(page?: number): Promise<R[]>;
|
|
81
|
+
abstract page(page?: number, ...args: MaybeContextualArg<any>): Promise<R[]>;
|
|
81
82
|
}
|
|
@@ -78,11 +78,11 @@ export class Paginator extends LoggedClass {
|
|
|
78
78
|
this.size = size;
|
|
79
79
|
this.clazz = clazz;
|
|
80
80
|
}
|
|
81
|
-
async next() {
|
|
82
|
-
return this.page(this.current + 1);
|
|
81
|
+
async next(...args) {
|
|
82
|
+
return this.page(this.current + 1, ...args);
|
|
83
83
|
}
|
|
84
|
-
async previous() {
|
|
85
|
-
return this.page(this.current - 1);
|
|
84
|
+
async previous(...args) {
|
|
85
|
+
return this.page(this.current - 1, ...args);
|
|
86
86
|
}
|
|
87
87
|
validatePage(page) {
|
|
88
88
|
if (page < 1 || !Number.isInteger(page))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Paginator.js","sourceRoot":"","sources":["../../../src/query/Paginator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,oBAAiB;AAIvC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"Paginator.js","sourceRoot":"","sources":["../../../src/query/Paginator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,oBAAiB;AAIvC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,MAAM,OAAgB,SAIpB,SAAQ,WAAW;IAQnB,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,IAAc,SAAS;QACrB,IAAI,CAAC,IAAI,CAAC,UAAU;YAAE,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACjE,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,YACqB,OAAkC,EAClC,KAAQ,EAClB,IAAY,EACF,KAAqB;QAExC,KAAK,EAAE,CAAC;QALW,YAAO,GAAP,OAAO,CAA2B;QAClC,UAAK,GAAL,KAAK,CAAG;QAClB,SAAI,GAAJ,IAAI,CAAQ;QACF,UAAK,GAAL,KAAK,CAAgB;IAG1C,CAAC;IAID,KAAK,CAAC,IAAI,CAAC,GAAG,IAA6B;QACzC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,GAAG,IAA6B;QAC7C,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;IAC9C,CAAC;IAES,YAAY,CAAC,IAAY;QACjC,IAAI,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC;YACrC,MAAM,IAAI,WAAW,CACnB,sDAAsD,CACvD,CAAC;QACJ,IAAI,OAAO,IAAI,CAAC,WAAW,KAAK,WAAW,IAAI,IAAI,GAAG,IAAI,CAAC,WAAW;YACpE,MAAM,IAAI,WAAW,CACnB,QAAQ,IAAI,CAAC,WAAW,qCAAqC,IAAI,EAAE,CACpE,CAAC;QACJ,OAAO,IAAI,CAAC;IACd,CAAC;CAGF"}
|
|
@@ -5,10 +5,10 @@ import { Condition } from "./Condition";
|
|
|
5
5
|
import type { CountOption, DistinctOption, LimitOption, MaxOption, MinOption, OffsetOption, OrderAndGroupOption, SelectOption, WhereOption } from "./options";
|
|
6
6
|
import { Paginatable } from "../interfaces/Paginatable";
|
|
7
7
|
import { Paginator } from "./Paginator";
|
|
8
|
-
import { Adapter } from "../persistence";
|
|
8
|
+
import { Adapter, type ContextOf } from "../persistence";
|
|
9
9
|
import { Logger } from "@decaf-ts/logging";
|
|
10
|
-
import { LoggedClass } from "@decaf-ts/logging";
|
|
11
10
|
import { Constructor } from "@decaf-ts/decoration";
|
|
11
|
+
import { type ContextualArgs, ContextualLoggedClass, type MaybeContextualArg } from "../utils/index";
|
|
12
12
|
/**
|
|
13
13
|
* @description Base class for database query statements
|
|
14
14
|
* @summary Provides a foundation for building and executing database queries
|
|
@@ -60,8 +60,8 @@ import { Constructor } from "@decaf-ts/decoration";
|
|
|
60
60
|
* Adapter-->>Statement: return processed results
|
|
61
61
|
* Statement-->>Client: return final results
|
|
62
62
|
*/
|
|
63
|
-
export declare abstract class Statement<
|
|
64
|
-
protected adapter: Adapter<any, any, Q, any
|
|
63
|
+
export declare abstract class Statement<M extends Model, A extends Adapter<any, any, any, any>, R, Q = A extends Adapter<any, any, infer Q, any> ? Q : never> extends ContextualLoggedClass<ContextOf<A>> implements Executor<R>, RawExecutor<Q>, Paginatable<M, R, Q> {
|
|
64
|
+
protected adapter: Adapter<any, any, Q, any>;
|
|
65
65
|
protected readonly selectSelector?: SelectSelector<M>[];
|
|
66
66
|
protected distinctSelector?: SelectSelector<M>;
|
|
67
67
|
protected maxSelector?: SelectSelector<M>;
|
|
@@ -73,7 +73,7 @@ export declare abstract class Statement<Q, M extends Model, R> extends LoggedCla
|
|
|
73
73
|
protected groupBySelector?: GroupBySelector<M>;
|
|
74
74
|
protected limitSelector?: number;
|
|
75
75
|
protected offsetSelector?: number;
|
|
76
|
-
protected constructor(adapter: Adapter<any, any, Q, any
|
|
76
|
+
protected constructor(adapter: Adapter<any, any, Q, any>);
|
|
77
77
|
protected get log(): Logger;
|
|
78
78
|
select<S extends readonly SelectSelector<M>[]>(): SelectOption<M, M[]>;
|
|
79
79
|
select<S extends readonly SelectSelector<M>[]>(selector: readonly [...S]): SelectOption<M, Pick<M, S[number]>[]>;
|
|
@@ -87,9 +87,10 @@ export declare abstract class Statement<Q, M extends Model, R> extends LoggedCla
|
|
|
87
87
|
groupBy(selector: GroupBySelector<M>): LimitOption<M, R>;
|
|
88
88
|
limit(value: number): OffsetOption<R>;
|
|
89
89
|
offset(value: number): Executor<R>;
|
|
90
|
-
execute(): Promise<R>;
|
|
91
|
-
raw<R>(rawInput: Q): Promise<R>;
|
|
90
|
+
execute(...args: MaybeContextualArg<ContextOf<A>>): Promise<R>;
|
|
91
|
+
raw<R>(rawInput: Q, ...args: ContextualArgs<ContextOf<A>>): Promise<R>;
|
|
92
92
|
protected abstract build(): Q;
|
|
93
93
|
protected abstract parseCondition(condition: Condition<M>, ...args: any[]): Q;
|
|
94
|
-
abstract paginate(size: number): Promise<Paginator<M, R, Q>>;
|
|
94
|
+
abstract paginate(size: number, ...args: MaybeContextualArg<ContextOf<A>>): Promise<Paginator<M, R, Q>>;
|
|
95
|
+
toString(): string;
|
|
95
96
|
}
|
|
@@ -10,10 +10,11 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
var _a, _b, _c, _d;
|
|
11
11
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
12
12
|
import { Condition } from "./Condition.js";
|
|
13
|
-
import { InternalError } from "@decaf-ts/db-decorators";
|
|
14
|
-
import { final } from "
|
|
13
|
+
import { Context, InternalError, OperationKeys } from "@decaf-ts/db-decorators";
|
|
14
|
+
import { final } from "@decaf-ts/logging";
|
|
15
|
+
import { Adapter } from "./../persistence/index.js";
|
|
15
16
|
import { QueryError } from "./errors.js";
|
|
16
|
-
import {
|
|
17
|
+
import { ContextualLoggedClass, } from "./../utils/index.js";
|
|
17
18
|
/**
|
|
18
19
|
* @description Base class for database query statements
|
|
19
20
|
* @summary Provides a foundation for building and executing database queries
|
|
@@ -65,7 +66,7 @@ import { LoggedClass } from "@decaf-ts/logging";
|
|
|
65
66
|
* Adapter-->>Statement: return processed results
|
|
66
67
|
* Statement-->>Client: return final results
|
|
67
68
|
*/
|
|
68
|
-
export class Statement extends
|
|
69
|
+
export class Statement extends ContextualLoggedClass {
|
|
69
70
|
constructor(adapter) {
|
|
70
71
|
super();
|
|
71
72
|
this.adapter = adapter;
|
|
@@ -122,28 +123,40 @@ export class Statement extends LoggedClass {
|
|
|
122
123
|
this.offsetSelector = value;
|
|
123
124
|
return this;
|
|
124
125
|
}
|
|
125
|
-
async execute() {
|
|
126
|
+
async execute(...args) {
|
|
127
|
+
let execArgs = args;
|
|
128
|
+
if ((!execArgs.length ||
|
|
129
|
+
!(execArgs[execArgs.length - 1] instanceof Context)) &&
|
|
130
|
+
this.fromSelector) {
|
|
131
|
+
const ctx = await this.adapter.context(OperationKeys.READ, {}, this.fromSelector);
|
|
132
|
+
execArgs = [...execArgs, ctx];
|
|
133
|
+
}
|
|
134
|
+
const { ctx } = Adapter.logCtx(execArgs, this.toString());
|
|
126
135
|
try {
|
|
127
136
|
const query = this.build();
|
|
128
|
-
return (await this.raw(query));
|
|
137
|
+
return (await this.raw(query, ctx));
|
|
129
138
|
}
|
|
130
139
|
catch (e) {
|
|
131
140
|
throw new InternalError(e);
|
|
132
141
|
}
|
|
133
142
|
}
|
|
134
|
-
async raw(rawInput) {
|
|
135
|
-
const
|
|
143
|
+
async raw(rawInput, ...args) {
|
|
144
|
+
const { ctx, ctxArgs } = this.logCtx(args, this.raw);
|
|
145
|
+
const results = await this.adapter.raw(rawInput, ...ctxArgs);
|
|
136
146
|
if (!this.selectSelector)
|
|
137
147
|
return results;
|
|
138
148
|
const pkAttr = Model.pk(this.fromSelector);
|
|
139
149
|
const processor = function recordProcessor(r) {
|
|
140
150
|
const id = r[pkAttr];
|
|
141
|
-
return this.adapter.revert(r, this.fromSelector,
|
|
151
|
+
return this.adapter.revert(r, this.fromSelector, id, undefined, ctx);
|
|
142
152
|
}.bind(this);
|
|
143
153
|
if (Array.isArray(results))
|
|
144
154
|
return results.map(processor);
|
|
145
155
|
return processor(results);
|
|
146
156
|
}
|
|
157
|
+
toString() {
|
|
158
|
+
return `${this.adapter.flavour} statement`;
|
|
159
|
+
}
|
|
147
160
|
}
|
|
148
161
|
__decorate([
|
|
149
162
|
final(),
|
|
@@ -214,7 +227,7 @@ __decorate([
|
|
|
214
227
|
__decorate([
|
|
215
228
|
final(),
|
|
216
229
|
__metadata("design:type", Function),
|
|
217
|
-
__metadata("design:paramtypes", []),
|
|
230
|
+
__metadata("design:paramtypes", [void 0]),
|
|
218
231
|
__metadata("design:returntype", Promise)
|
|
219
232
|
], Statement.prototype, "execute", null);
|
|
220
233
|
//# sourceMappingURL=Statement.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Statement.js","sourceRoot":"","sources":["../../../src/query/Statement.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAQvD,OAAO,EAAE,SAAS,EAAE,uBAAoB;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"Statement.js","sourceRoot":"","sources":["../../../src/query/Statement.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAQvD,OAAO,EAAE,SAAS,EAAE,uBAAoB;AACxC,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAc1C,OAAO,EAAE,OAAO,EAAkB,kCAAuB;AACzD,OAAO,EAAE,UAAU,EAAE,oBAAiB;AAGtC,OAAO,EAEL,qBAAqB,GAEtB,4BAAuB;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,MAAM,OAAgB,SAMpB,SAAQ,qBAAmC;IAe3C,YAAgC,OAAkC;QAChE,KAAK,EAAE,CAAC;QADsB,YAAO,GAAP,OAAO,CAA2B;IAElE,CAAC;IAED,IAAuB,GAAG;QACxB,OAAQ,IAAI,CAAC,OAAe,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAClD,CAAC;IAWD,MAAM,CACJ,QAA0B;QAE1B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,gBAAgB,EAAE;YAC5C,KAAK,EAAE,QAAQ;YACf,QAAQ,EAAE,KAAK;SAChB,CAAC,CAAC;QACH,OAAO,IAAoE,CAAC;IAC9E,CAAC;IAGD,QAAQ,CACN,QAAW;QAEX,IAAI,CAAC,gBAAgB,GAAG,QAAQ,CAAC;QACjC,OAAO,IAAiC,CAAC;IAC3C,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AEN,MAAM,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;YACrB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CACxB,CAAC,EACD,IAAI,CAAC,YAAgC,EACrC,EAAE,EACF,SAAS,EACT,GAAG,CACG,CAAC;QACX,CAAC,CAAC,IAAI,CAAC,IAAW,CAAC,CAAC;QAEpB,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;YAAE,OAAO,OAAO,CAAC,GAAG,CAAC,SAAS,CAAM,CAAC;QAC/D,OAAO,SAAS,CAAC,OAAO,CAAM,CAAC;IACjC,CAAC;IASQ,QAAQ;QACf,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,YAAY,CAAC;IAC7C,CAAC;CACF;AAxIC;IADC,KAAK,EAAE;;;;uCASP;AAGD;IADC,KAAK,EAAE;;yDAEI,CAAC,oBAAD,CAAC;;yCAIZ;AAGD;IADC,KAAK,EAAE;;yDACmC,CAAC,oBAAD,CAAC;;oCAG3C;AAGD;IADC,KAAK,EAAE;;yDACmC,CAAC,oBAAD,CAAC;;oCAG3C;AAGD;IADC,KAAK,EAAE;;yDACsC,CAAC,oBAAD,CAAC;;sCAG9C;AAGM;IADN,KAAK,EAAE;;;;qCAQP;AAGM;IADN,KAAK,EAAE;;qCACgB,SAAS;;sCAGhC;AAGM;IADN,KAAK,EAAE;;;;wCAMP;AAGM;IADN,KAAK,EAAE;;;;wCAIP;AAGM;IADN,KAAK,EAAE;;;;sCAIP;AAGM;IADN,KAAK,EAAE;;;;uCAIP;AAGK;IADL,KAAK,EAAE;;;;wCAsBP"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { RamFlags, RawRamQuery, RamStorage,
|
|
1
|
+
import { RamFlags, RawRamQuery, RamStorage, RamConfig, RamContext } from "./types";
|
|
2
2
|
import { RamStatement } from "./RamStatement";
|
|
3
|
-
import {
|
|
3
|
+
import { Repository } from "../repository/Repository";
|
|
4
4
|
import { Dispatch } from "../persistence/Dispatch";
|
|
5
|
-
import { Adapter
|
|
6
|
-
import { SequenceOptions } from "../interfaces";
|
|
5
|
+
import { Adapter } from "../persistence";
|
|
7
6
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
8
|
-
import { BaseError, OperationKeys } from "@decaf-ts/db-decorators";
|
|
7
|
+
import { BaseError, OperationKeys, PrimaryKeyType } from "@decaf-ts/db-decorators";
|
|
9
8
|
import { Constructor } from "@decaf-ts/decoration";
|
|
10
9
|
/**
|
|
11
10
|
* @description In-memory adapter for data persistence
|
|
@@ -50,7 +49,7 @@ import { Constructor } from "@decaf-ts/decoration";
|
|
|
50
49
|
* RamAdapter-->>Repository: model
|
|
51
50
|
* Repository-->>Client: model
|
|
52
51
|
*/
|
|
53
|
-
export declare class RamAdapter extends Adapter<RamConfig, RamStorage, RawRamQuery
|
|
52
|
+
export declare class RamAdapter extends Adapter<RamConfig, RamStorage, RawRamQuery, RamContext> {
|
|
54
53
|
constructor(conf?: RamConfig, alias?: string);
|
|
55
54
|
/**
|
|
56
55
|
* @description Gets the repository constructor for a model
|
|
@@ -59,7 +58,7 @@ export declare class RamAdapter extends Adapter<RamConfig, RamStorage, RawRamQue
|
|
|
59
58
|
* @template M - The model type for the repository
|
|
60
59
|
* @return {Constructor<RamRepository<M>>} A constructor for creating RAM repositories
|
|
61
60
|
*/
|
|
62
|
-
repository<
|
|
61
|
+
repository<R extends Repository<any, Adapter<any, any, any, any>>>(): Constructor<R>;
|
|
63
62
|
/**
|
|
64
63
|
* @description Creates operation flags with UUID
|
|
65
64
|
* @summary Extends the base flags with a UUID for user identification.
|
|
@@ -71,8 +70,8 @@ export declare class RamAdapter extends Adapter<RamConfig, RamStorage, RawRamQue
|
|
|
71
70
|
* @return {Promise<RamFlags>} Complete flags with UUID
|
|
72
71
|
*/
|
|
73
72
|
flags<M extends Model<boolean>>(operation: OperationKeys, model: Constructor<M>, flags: Partial<RamFlags>): Promise<RamFlags>;
|
|
74
|
-
protected Dispatch(): Dispatch
|
|
75
|
-
Context:
|
|
73
|
+
protected Dispatch(): Dispatch<RamAdapter>;
|
|
74
|
+
Context: Constructor<RamContext>;
|
|
76
75
|
private indexes;
|
|
77
76
|
private lock;
|
|
78
77
|
/**
|
|
@@ -92,9 +91,10 @@ export declare class RamAdapter extends Adapter<RamConfig, RamStorage, RawRamQue
|
|
|
92
91
|
* @param pk - The primary key property name
|
|
93
92
|
* @return Object containing the record and ID
|
|
94
93
|
*/
|
|
95
|
-
prepare<M extends Model>(model: M,
|
|
94
|
+
prepare<M extends Model>(model: M, ...args: [...any[], RamContext]): {
|
|
96
95
|
record: Record<string, any>;
|
|
97
96
|
id: string;
|
|
97
|
+
transient?: Record<string, any>;
|
|
98
98
|
};
|
|
99
99
|
/**
|
|
100
100
|
* @description Converts a stored record back to a model instance
|
|
@@ -102,18 +102,17 @@ export declare class RamAdapter extends Adapter<RamConfig, RamStorage, RawRamQue
|
|
|
102
102
|
* This method is the inverse of the prepare method.
|
|
103
103
|
* @template M - The model type to revert to
|
|
104
104
|
* @param {Record<string, any>} obj - The stored record
|
|
105
|
-
* @param {
|
|
106
|
-
* @param
|
|
107
|
-
* @param {string | number} id - The primary key value
|
|
105
|
+
* @param {Constructor<M>} clazz - The model class or name
|
|
106
|
+
* @param {PrimaryKeyType} id - The primary key value
|
|
108
107
|
* @return {M} The reconstructed model instance
|
|
109
108
|
*/
|
|
110
|
-
revert<M extends Model>(obj: Record<string, any>, clazz:
|
|
109
|
+
revert<M extends Model>(obj: Record<string, any>, clazz: Constructor<M>, id: PrimaryKeyType, transient?: Record<string, any>, ...args: [...any[], RamContext]): M;
|
|
111
110
|
/**
|
|
112
111
|
* @description Creates a new record in the in-memory storage
|
|
113
112
|
* @summary Stores a new record in the specified table with the given ID.
|
|
114
113
|
* This method acquires a lock to ensure thread safety, creates the table if it doesn't exist,
|
|
115
114
|
* checks for conflicts, and stores the model.
|
|
116
|
-
* @param {string}
|
|
115
|
+
* @param {string} clazz - The name of the table to store the record in
|
|
117
116
|
* @param {string | number} id - The unique identifier for the record
|
|
118
117
|
* @param {Record<string, any>} model - The record data to store
|
|
119
118
|
* @return {Promise<Record<string, any>>} A promise that resolves to the stored record
|
|
@@ -137,13 +136,13 @@ export declare class RamAdapter extends Adapter<RamConfig, RamStorage, RawRamQue
|
|
|
137
136
|
* RamAdapter->>RamAdapter: lock.release()
|
|
138
137
|
* RamAdapter-->>Caller: model
|
|
139
138
|
*/
|
|
140
|
-
create(
|
|
139
|
+
create<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ctx: RamContext): Promise<Record<string, any>>;
|
|
141
140
|
/**
|
|
142
141
|
* @description Retrieves a record from in-memory storage
|
|
143
142
|
* @summary Fetches a record with the specified ID from the given table.
|
|
144
143
|
* This method checks if the table and record exist and throws appropriate errors if not.
|
|
145
|
-
* @param {
|
|
146
|
-
* @param {
|
|
144
|
+
* @param {Constructor} clazz - The name of the table to retrieve from
|
|
145
|
+
* @param {PrimaryKeyType} id - The unique identifier of the record to retrieve
|
|
147
146
|
* @return {Promise<Record<string, any>>} A promise that resolves to the retrieved record
|
|
148
147
|
* @mermaid
|
|
149
148
|
* sequenceDiagram
|
|
@@ -164,7 +163,7 @@ export declare class RamAdapter extends Adapter<RamConfig, RamStorage, RawRamQue
|
|
|
164
163
|
* Storage-->>RamAdapter: record
|
|
165
164
|
* RamAdapter-->>Caller: record
|
|
166
165
|
*/
|
|
167
|
-
read(
|
|
166
|
+
read<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, ctx: RamContext): Promise<Record<string, any>>;
|
|
168
167
|
/**
|
|
169
168
|
* @description Updates an existing record in the in-memory storage
|
|
170
169
|
* @summary Updates a record with the specified ID in the given table.
|
|
@@ -194,7 +193,7 @@ export declare class RamAdapter extends Adapter<RamConfig, RamStorage, RawRamQue
|
|
|
194
193
|
* RamAdapter->>RamAdapter: lock.release()
|
|
195
194
|
* RamAdapter-->>Caller: model
|
|
196
195
|
*/
|
|
197
|
-
update(
|
|
196
|
+
update<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ctx: RamContext): Promise<Record<string, any>>;
|
|
198
197
|
/**
|
|
199
198
|
* @description Deletes a record from the in-memory storage
|
|
200
199
|
* @summary Removes a record with the specified ID from the given table.
|
|
@@ -225,7 +224,7 @@ export declare class RamAdapter extends Adapter<RamConfig, RamStorage, RawRamQue
|
|
|
225
224
|
* RamAdapter->>RamAdapter: lock.release()
|
|
226
225
|
* RamAdapter-->>Caller: record
|
|
227
226
|
*/
|
|
228
|
-
delete(
|
|
227
|
+
delete<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, ctx: RamContext): Promise<Record<string, any>>;
|
|
229
228
|
/**
|
|
230
229
|
* @description Gets or creates a table in the in-memory storage
|
|
231
230
|
* @summary Retrieves the Map representing a table for a given model or table name.
|
|
@@ -279,7 +278,7 @@ export declare class RamAdapter extends Adapter<RamConfig, RamStorage, RawRamQue
|
|
|
279
278
|
* end
|
|
280
279
|
* RamAdapter-->>Caller: result
|
|
281
280
|
*/
|
|
282
|
-
raw<R>(rawInput: RawRamQuery<any
|
|
281
|
+
raw<R>(rawInput: RawRamQuery<any>, ctx: RamContext): Promise<R>;
|
|
283
282
|
/**
|
|
284
283
|
* @description Parses and converts errors to appropriate types
|
|
285
284
|
* @summary Ensures that errors are of the correct type for consistent error handling.
|
|
@@ -296,15 +295,7 @@ export declare class RamAdapter extends Adapter<RamConfig, RamStorage, RawRamQue
|
|
|
296
295
|
* @template M - The model type for the statement
|
|
297
296
|
* @return {RamStatement<M, any>} A new statement builder instance
|
|
298
297
|
*/
|
|
299
|
-
Statement<M extends Model<boolean>>(): RamStatement<M, any
|
|
300
|
-
/**
|
|
301
|
-
* @description Creates a new sequence for generating sequential IDs
|
|
302
|
-
* @summary Factory method that creates a new RamSequence instance for ID generation.
|
|
303
|
-
* This method provides a way to create auto-incrementing sequences for entity IDs.
|
|
304
|
-
* @param {SequenceOptions} options - Configuration options for the sequence
|
|
305
|
-
* @return {Promise<Sequence>} A promise that resolves to the new sequence instance
|
|
306
|
-
*/
|
|
307
|
-
Sequence(options: SequenceOptions): Promise<Sequence>;
|
|
298
|
+
Statement<M extends Model<boolean>>(): RamStatement<M, any, Adapter<any, any, RawRamQuery<M>, RamContext>>;
|
|
308
299
|
for(config: Partial<RamConfig>, ...args: any[]): typeof this;
|
|
309
300
|
/**
|
|
310
301
|
* @description Sets up RAM-specific decorations for model properties
|