@decaf-ts/db-decorators 0.11.0 → 0.13.0
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/lib/cjs/identity/decorators.cjs +5 -4
- package/lib/cjs/identity/decorators.cjs.map +1 -0
- package/lib/cjs/identity/index.cjs +1 -0
- package/lib/cjs/identity/index.cjs.map +1 -0
- package/lib/cjs/index.cjs +2 -1
- package/lib/cjs/index.cjs.map +1 -0
- package/lib/cjs/interfaces/BulkCrudOperator.cjs +1 -0
- package/lib/cjs/interfaces/BulkCrudOperator.cjs.map +1 -0
- package/lib/cjs/interfaces/Contextual.cjs +1 -0
- package/lib/cjs/interfaces/Contextual.cjs.map +1 -0
- package/lib/cjs/interfaces/CrudOperator.cjs +1 -0
- package/lib/cjs/interfaces/CrudOperator.cjs.map +1 -0
- package/lib/cjs/interfaces/IRepository.cjs +1 -0
- package/lib/cjs/interfaces/IRepository.cjs.map +1 -0
- package/lib/cjs/interfaces/index.cjs +1 -0
- package/lib/cjs/interfaces/index.cjs.map +1 -0
- package/lib/cjs/model/constants.cjs +1 -0
- package/lib/cjs/model/constants.cjs.map +1 -0
- package/lib/cjs/model/decorators.cjs +25 -24
- package/lib/cjs/model/decorators.cjs.map +1 -0
- package/lib/cjs/model/index.cjs +1 -0
- package/lib/cjs/model/index.cjs.map +1 -0
- package/lib/cjs/model/model.cjs +1 -0
- package/lib/cjs/model/model.cjs.map +1 -0
- package/lib/cjs/model/validation.cjs +1 -0
- package/lib/cjs/model/validation.cjs.map +1 -0
- package/lib/cjs/operations/Operations.cjs +6 -5
- package/lib/cjs/operations/Operations.cjs.map +1 -0
- package/lib/cjs/operations/OperationsRegistry.cjs +1 -0
- package/lib/cjs/operations/OperationsRegistry.cjs.map +1 -0
- package/lib/cjs/operations/constants.cjs +15 -39
- package/lib/cjs/operations/constants.cjs.map +1 -0
- package/lib/cjs/operations/decorators.cjs +42 -41
- package/lib/cjs/operations/decorators.cjs.map +1 -0
- package/lib/cjs/operations/index.cjs +1 -0
- package/lib/cjs/operations/index.cjs.map +1 -0
- package/lib/cjs/operations/types.cjs +1 -0
- package/lib/cjs/operations/types.cjs.map +1 -0
- package/lib/cjs/overrides/Metadata.cjs +1 -0
- package/lib/cjs/overrides/Metadata.cjs.map +1 -0
- package/lib/cjs/overrides/Model.cjs +1 -0
- package/lib/cjs/overrides/Model.cjs.map +1 -0
- package/lib/cjs/overrides/ModelBuilderExtensions.cjs +8 -7
- package/lib/cjs/overrides/ModelBuilderExtensions.cjs.map +1 -0
- package/lib/cjs/overrides/index.cjs +1 -0
- package/lib/cjs/overrides/index.cjs.map +1 -0
- package/lib/cjs/overrides/overrides.cjs +21 -20
- package/lib/cjs/overrides/overrides.cjs.map +1 -0
- package/lib/cjs/repository/Context.cjs +3 -2
- package/lib/cjs/repository/Context.cjs.map +1 -0
- package/lib/cjs/repository/Repository.cjs +42 -41
- package/lib/cjs/repository/Repository.cjs.map +1 -0
- package/lib/cjs/repository/constants.cjs +1 -0
- package/lib/cjs/repository/constants.cjs.map +1 -0
- package/lib/cjs/repository/errors.cjs +1 -0
- package/lib/cjs/repository/errors.cjs.map +1 -0
- package/lib/cjs/repository/index.cjs +1 -0
- package/lib/cjs/repository/index.cjs.map +1 -0
- package/lib/cjs/repository/types.cjs +1 -0
- package/lib/cjs/repository/types.cjs.map +1 -0
- package/lib/cjs/repository/utils.cjs +10 -9
- package/lib/cjs/repository/utils.cjs.map +1 -0
- package/lib/cjs/repository/wrappers.cjs +8 -7
- package/lib/cjs/repository/wrappers.cjs.map +1 -0
- package/lib/cjs/validation/constants.cjs +4 -3
- package/lib/cjs/validation/constants.cjs.map +1 -0
- package/lib/cjs/validation/decorators.cjs +22 -21
- package/lib/cjs/validation/decorators.cjs.map +1 -0
- package/lib/cjs/validation/index.cjs +1 -0
- package/lib/cjs/validation/index.cjs.map +1 -0
- package/lib/cjs/validation/validation.cjs +3 -2
- package/lib/cjs/validation/validation.cjs.map +1 -0
- package/lib/cjs/validation/validators/ReadOnlyValidator.cjs +14 -8
- package/lib/cjs/validation/validators/ReadOnlyValidator.cjs.map +1 -0
- package/lib/cjs/validation/validators/TimestampValidator.cjs +14 -8
- package/lib/cjs/validation/validators/TimestampValidator.cjs.map +1 -0
- package/lib/cjs/validation/validators/UpdateValidator.cjs +1 -0
- package/lib/cjs/validation/validators/UpdateValidator.cjs.map +1 -0
- package/lib/cjs/validation/validators/index.cjs +1 -0
- package/lib/cjs/validation/validators/index.cjs.map +1 -0
- package/lib/esm/index.js +1 -1
- package/lib/types/identity/decorators.d.cts +8 -0
- package/lib/types/identity/decorators.d.mts +8 -0
- package/lib/types/identity/index.d.cts +6 -0
- package/lib/types/identity/index.d.mts +6 -0
- package/lib/types/index.d.cts +15 -0
- package/lib/types/index.d.mts +15 -0
- package/lib/types/index.d.ts +1 -1
- package/lib/types/interfaces/BulkCrudOperator.d.cts +47 -0
- package/lib/types/interfaces/BulkCrudOperator.d.mts +47 -0
- package/lib/types/interfaces/Contextual.d.cts +23 -0
- package/lib/types/interfaces/Contextual.d.mts +23 -0
- package/lib/types/interfaces/CrudOperator.d.cts +46 -0
- package/lib/types/interfaces/CrudOperator.d.mts +46 -0
- package/lib/types/interfaces/IRepository.d.cts +19 -0
- package/lib/types/interfaces/IRepository.d.mts +19 -0
- package/lib/types/interfaces/index.d.cts +9 -0
- package/lib/types/interfaces/index.d.mts +9 -0
- package/lib/types/model/constants.d.cts +37 -0
- package/lib/types/model/constants.d.mts +37 -0
- package/lib/types/model/decorators.d.cts +145 -0
- package/lib/types/model/decorators.d.mts +145 -0
- package/lib/types/model/index.d.cts +9 -0
- package/lib/types/model/index.d.mts +9 -0
- package/lib/types/model/model.d.cts +6 -0
- package/lib/types/model/model.d.mts +6 -0
- package/lib/types/model/validation.d.cts +57 -0
- package/lib/types/model/validation.d.mts +57 -0
- package/lib/types/operations/Operations.d.cts +80 -0
- package/lib/types/operations/Operations.d.mts +80 -0
- package/lib/types/operations/OperationsRegistry.d.cts +72 -0
- package/lib/types/operations/OperationsRegistry.d.mts +72 -0
- package/lib/types/operations/constants.d.cts +106 -0
- package/lib/types/operations/constants.d.mts +106 -0
- package/lib/types/operations/decorators.d.cts +348 -0
- package/lib/types/operations/decorators.d.mts +348 -0
- package/lib/types/operations/index.d.cts +10 -0
- package/lib/types/operations/index.d.mts +10 -0
- package/lib/types/operations/types.d.cts +60 -0
- package/lib/types/operations/types.d.mts +60 -0
- package/lib/types/overrides/Metadata.d.cts +54 -0
- package/lib/types/overrides/Metadata.d.mts +54 -0
- package/lib/types/overrides/Model.d.cts +84 -0
- package/lib/types/overrides/Model.d.mts +84 -0
- package/lib/types/overrides/ModelBuilderExtensions.d.cts +15 -0
- package/lib/types/overrides/ModelBuilderExtensions.d.mts +15 -0
- package/lib/types/overrides/index.d.cts +10 -0
- package/lib/types/overrides/index.d.mts +10 -0
- package/lib/types/overrides/overrides.d.cts +1 -0
- package/lib/types/overrides/overrides.d.mts +1 -0
- package/lib/types/repository/Context.d.cts +112 -0
- package/lib/types/repository/Context.d.mts +112 -0
- package/lib/types/repository/Repository.d.cts +352 -0
- package/lib/types/repository/Repository.d.mts +352 -0
- package/lib/types/repository/constants.d.cts +9 -0
- package/lib/types/repository/constants.d.mts +9 -0
- package/lib/types/repository/errors.d.cts +126 -0
- package/lib/types/repository/errors.d.mts +126 -0
- package/lib/types/repository/index.d.cts +12 -0
- package/lib/types/repository/index.d.mts +12 -0
- package/lib/types/repository/types.d.cts +62 -0
- package/lib/types/repository/types.d.mts +62 -0
- package/lib/types/repository/utils.d.cts +34 -0
- package/lib/types/repository/utils.d.mts +34 -0
- package/lib/types/repository/wrappers.d.cts +39 -0
- package/lib/types/repository/wrappers.d.mts +39 -0
- package/lib/types/validation/constants.d.cts +45 -0
- package/lib/types/validation/constants.d.mts +45 -0
- package/lib/types/validation/decorators.d.cts +143 -0
- package/lib/types/validation/decorators.d.mts +143 -0
- package/lib/types/validation/index.d.cts +4 -0
- package/lib/types/validation/index.d.mts +4 -0
- package/lib/types/validation/validation.d.cts +41 -0
- package/lib/types/validation/validation.d.mts +41 -0
- package/lib/types/validation/validators/ReadOnlyValidator.d.cts +47 -0
- package/lib/types/validation/validators/ReadOnlyValidator.d.mts +47 -0
- package/lib/types/validation/validators/TimestampValidator.d.cts +48 -0
- package/lib/types/validation/validators/TimestampValidator.d.mts +48 -0
- package/lib/types/validation/validators/UpdateValidator.d.cts +40 -0
- package/lib/types/validation/validators/UpdateValidator.d.mts +40 -0
- package/lib/types/validation/validators/index.d.cts +3 -0
- package/lib/types/validation/validators/index.d.mts +3 -0
- package/package.json +4 -4
- package/lib/cjs/identity/decorators.js.map +0 -1
- package/lib/cjs/identity/index.js.map +0 -1
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/interfaces/BulkCrudOperator.js.map +0 -1
- package/lib/cjs/interfaces/Contextual.js.map +0 -1
- package/lib/cjs/interfaces/CrudOperator.js.map +0 -1
- package/lib/cjs/interfaces/IRepository.js.map +0 -1
- package/lib/cjs/interfaces/index.js.map +0 -1
- package/lib/cjs/model/constants.js.map +0 -1
- package/lib/cjs/model/decorators.js.map +0 -1
- package/lib/cjs/model/index.js.map +0 -1
- package/lib/cjs/model/model.js.map +0 -1
- package/lib/cjs/model/validation.js.map +0 -1
- package/lib/cjs/operations/Operations.js.map +0 -1
- package/lib/cjs/operations/OperationsRegistry.js.map +0 -1
- package/lib/cjs/operations/constants.js.map +0 -1
- package/lib/cjs/operations/decorators.js.map +0 -1
- package/lib/cjs/operations/index.js.map +0 -1
- package/lib/cjs/operations/types.js.map +0 -1
- package/lib/cjs/overrides/Metadata.js.map +0 -1
- package/lib/cjs/overrides/Model.js.map +0 -1
- package/lib/cjs/overrides/ModelBuilderExtensions.js.map +0 -1
- package/lib/cjs/overrides/index.js.map +0 -1
- package/lib/cjs/overrides/overrides.js.map +0 -1
- package/lib/cjs/repository/Context.js.map +0 -1
- package/lib/cjs/repository/Repository.js.map +0 -1
- package/lib/cjs/repository/constants.js.map +0 -1
- package/lib/cjs/repository/errors.js.map +0 -1
- package/lib/cjs/repository/index.js.map +0 -1
- package/lib/cjs/repository/types.js.map +0 -1
- package/lib/cjs/repository/utils.js.map +0 -1
- package/lib/cjs/repository/wrappers.js.map +0 -1
- package/lib/cjs/validation/constants.js.map +0 -1
- package/lib/cjs/validation/decorators.js.map +0 -1
- package/lib/cjs/validation/index.js.map +0 -1
- package/lib/cjs/validation/validation.js.map +0 -1
- package/lib/cjs/validation/validators/ReadOnlyValidator.js.map +0 -1
- package/lib/cjs/validation/validators/TimestampValidator.js.map +0 -1
- package/lib/cjs/validation/validators/UpdateValidator.js.map +0 -1
- package/lib/cjs/validation/validators/index.js.map +0 -1
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
2
|
+
import "@decaf-ts/decorator-validation";
|
|
3
|
+
import { ComposedFromMetadata } from "../model/index.cjs";
|
|
4
|
+
import { Context } from "../repository/index.cjs";
|
|
5
|
+
declare module "@decaf-ts/decorator-validation" {
|
|
6
|
+
interface Model {
|
|
7
|
+
isTransient(): boolean;
|
|
8
|
+
segregate<M extends Model<boolean>>(this: M): {
|
|
9
|
+
model: M;
|
|
10
|
+
transient?: Record<keyof M, M[keyof M]>;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
namespace Model {
|
|
14
|
+
/**
|
|
15
|
+
* @description Retrieves primary key information for a model
|
|
16
|
+
* @summary Retrieves primary key information or it's value for a model from it's metadata.
|
|
17
|
+
*
|
|
18
|
+
* @template model - The model type extending from Model
|
|
19
|
+
* @param {M | Constructor<M>} model - The model class or it's constructor
|
|
20
|
+
* @param {boolean} keyValue - Optional keyValue flag, to return the value of the id instead of the property. Does not work with constructor.
|
|
21
|
+
* @return {any} The property of the id of the model, or it's value
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* class User extends Model {
|
|
25
|
+
*
|
|
26
|
+
* const idProp = Model.pk(newModel);
|
|
27
|
+
* const id = Model.pk(newModel, true);
|
|
28
|
+
*/
|
|
29
|
+
function pk<M extends Model<boolean>>(model: M | Constructor<M>): keyof M;
|
|
30
|
+
function pk<M extends Model<boolean>>(model: M, keyValue: boolean): M[keyof M];
|
|
31
|
+
function pk<M extends Model<boolean>>(model: M | Constructor<M>, keyValue?: boolean): keyof M | M[keyof M];
|
|
32
|
+
function pkProps<M extends Model<boolean>>(model: Constructor<M>): any;
|
|
33
|
+
function isTransient<M extends Model<boolean>>(model: M | Constructor<M>): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* @description Separates transient properties from a model
|
|
36
|
+
* @summary Extracts properties marked as transient into a separate object
|
|
37
|
+
* @template M - Type extending Model
|
|
38
|
+
* @param {M} model - The model instance to process
|
|
39
|
+
* @return {Object} Object containing the model without transient properties and a separate transient object
|
|
40
|
+
* @property {M} model - The model with transient properties removed
|
|
41
|
+
* @property {Record<string, any>} [transient] - Object containing the transient properties
|
|
42
|
+
* @function segregate
|
|
43
|
+
* @mermaid
|
|
44
|
+
* sequenceDiagram
|
|
45
|
+
* participant Caller
|
|
46
|
+
* participant modelToTransient
|
|
47
|
+
* participant isTransient
|
|
48
|
+
* participant Metadata.validatableProperties
|
|
49
|
+
*
|
|
50
|
+
* Caller->>modelToTransient: model
|
|
51
|
+
* modelToTransient->>isTransient: check if model is transient
|
|
52
|
+
* isTransient-->>modelToTransient: transient status
|
|
53
|
+
* alt model is not transient
|
|
54
|
+
* modelToTransient-->>Caller: {model}
|
|
55
|
+
* else model is transient
|
|
56
|
+
* modelToTransient->>Metadata.validatableProperties: get decorated properties, combine with model props
|
|
57
|
+
* modelToTransient->>get transient properties from Metadata
|
|
58
|
+
* modelToTransient->>modelToTransient: separate properties
|
|
59
|
+
* modelToTransient->>Model.build: rebuild model without transient props
|
|
60
|
+
* modelToTransient-->>Caller: {model, transient}
|
|
61
|
+
* end
|
|
62
|
+
*/
|
|
63
|
+
function segregate<M extends Model<boolean>>(model: M): {
|
|
64
|
+
model: M;
|
|
65
|
+
transient?: Record<keyof M, M[keyof M]>;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* @description Merges two model instances into a new instance.
|
|
69
|
+
* @summary Creates a new model instance by combining properties from an old model and a new model.
|
|
70
|
+
* Properties from the new model override properties from the old model if they are defined.
|
|
71
|
+
* @param {M} oldModel - The original model instance
|
|
72
|
+
* @param {M} model - The new model instance with updated properties
|
|
73
|
+
* @return {M} A new model instance with merged properties
|
|
74
|
+
*/
|
|
75
|
+
function merge<M extends Model<boolean>>(oldModel: M, newModel: M, constructor?: Constructor<M>): M;
|
|
76
|
+
function composed<M extends Model<boolean>>(model: Constructor<M>): boolean;
|
|
77
|
+
function composed<M extends Model<boolean>>(model: Constructor<M> | M, prop: keyof M): ComposedFromMetadata | undefined;
|
|
78
|
+
function composed<M extends Model<boolean>>(model: Constructor<M> | M, prop?: keyof M): boolean | ComposedFromMetadata | undefined;
|
|
79
|
+
function generated<M extends Model>(model: M | Constructor<M>, prop: keyof M): boolean | string;
|
|
80
|
+
function shouldGenerate<M extends Model>(model: M, prop: keyof M, ctx: Context<any>): boolean;
|
|
81
|
+
function versionProp<M extends Model<boolean>>(model: M): keyof M;
|
|
82
|
+
function versionOf<M extends Model<boolean>>(model: M): number;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
2
|
+
import "@decaf-ts/decorator-validation";
|
|
3
|
+
import { ComposedFromMetadata } from "../model/index.js";
|
|
4
|
+
import { Context } from "../repository/index.js";
|
|
5
|
+
declare module "@decaf-ts/decorator-validation" {
|
|
6
|
+
interface Model {
|
|
7
|
+
isTransient(): boolean;
|
|
8
|
+
segregate<M extends Model<boolean>>(this: M): {
|
|
9
|
+
model: M;
|
|
10
|
+
transient?: Record<keyof M, M[keyof M]>;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
namespace Model {
|
|
14
|
+
/**
|
|
15
|
+
* @description Retrieves primary key information for a model
|
|
16
|
+
* @summary Retrieves primary key information or it's value for a model from it's metadata.
|
|
17
|
+
*
|
|
18
|
+
* @template model - The model type extending from Model
|
|
19
|
+
* @param {M | Constructor<M>} model - The model class or it's constructor
|
|
20
|
+
* @param {boolean} keyValue - Optional keyValue flag, to return the value of the id instead of the property. Does not work with constructor.
|
|
21
|
+
* @return {any} The property of the id of the model, or it's value
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* class User extends Model {
|
|
25
|
+
*
|
|
26
|
+
* const idProp = Model.pk(newModel);
|
|
27
|
+
* const id = Model.pk(newModel, true);
|
|
28
|
+
*/
|
|
29
|
+
function pk<M extends Model<boolean>>(model: M | Constructor<M>): keyof M;
|
|
30
|
+
function pk<M extends Model<boolean>>(model: M, keyValue: boolean): M[keyof M];
|
|
31
|
+
function pk<M extends Model<boolean>>(model: M | Constructor<M>, keyValue?: boolean): keyof M | M[keyof M];
|
|
32
|
+
function pkProps<M extends Model<boolean>>(model: Constructor<M>): any;
|
|
33
|
+
function isTransient<M extends Model<boolean>>(model: M | Constructor<M>): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* @description Separates transient properties from a model
|
|
36
|
+
* @summary Extracts properties marked as transient into a separate object
|
|
37
|
+
* @template M - Type extending Model
|
|
38
|
+
* @param {M} model - The model instance to process
|
|
39
|
+
* @return {Object} Object containing the model without transient properties and a separate transient object
|
|
40
|
+
* @property {M} model - The model with transient properties removed
|
|
41
|
+
* @property {Record<string, any>} [transient] - Object containing the transient properties
|
|
42
|
+
* @function segregate
|
|
43
|
+
* @mermaid
|
|
44
|
+
* sequenceDiagram
|
|
45
|
+
* participant Caller
|
|
46
|
+
* participant modelToTransient
|
|
47
|
+
* participant isTransient
|
|
48
|
+
* participant Metadata.validatableProperties
|
|
49
|
+
*
|
|
50
|
+
* Caller->>modelToTransient: model
|
|
51
|
+
* modelToTransient->>isTransient: check if model is transient
|
|
52
|
+
* isTransient-->>modelToTransient: transient status
|
|
53
|
+
* alt model is not transient
|
|
54
|
+
* modelToTransient-->>Caller: {model}
|
|
55
|
+
* else model is transient
|
|
56
|
+
* modelToTransient->>Metadata.validatableProperties: get decorated properties, combine with model props
|
|
57
|
+
* modelToTransient->>get transient properties from Metadata
|
|
58
|
+
* modelToTransient->>modelToTransient: separate properties
|
|
59
|
+
* modelToTransient->>Model.build: rebuild model without transient props
|
|
60
|
+
* modelToTransient-->>Caller: {model, transient}
|
|
61
|
+
* end
|
|
62
|
+
*/
|
|
63
|
+
function segregate<M extends Model<boolean>>(model: M): {
|
|
64
|
+
model: M;
|
|
65
|
+
transient?: Record<keyof M, M[keyof M]>;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* @description Merges two model instances into a new instance.
|
|
69
|
+
* @summary Creates a new model instance by combining properties from an old model and a new model.
|
|
70
|
+
* Properties from the new model override properties from the old model if they are defined.
|
|
71
|
+
* @param {M} oldModel - The original model instance
|
|
72
|
+
* @param {M} model - The new model instance with updated properties
|
|
73
|
+
* @return {M} A new model instance with merged properties
|
|
74
|
+
*/
|
|
75
|
+
function merge<M extends Model<boolean>>(oldModel: M, newModel: M, constructor?: Constructor<M>): M;
|
|
76
|
+
function composed<M extends Model<boolean>>(model: Constructor<M>): boolean;
|
|
77
|
+
function composed<M extends Model<boolean>>(model: Constructor<M> | M, prop: keyof M): ComposedFromMetadata | undefined;
|
|
78
|
+
function composed<M extends Model<boolean>>(model: Constructor<M> | M, prop?: keyof M): boolean | ComposedFromMetadata | undefined;
|
|
79
|
+
function generated<M extends Model>(model: M | Constructor<M>, prop: keyof M): boolean | string;
|
|
80
|
+
function shouldGenerate<M extends Model>(model: M, prop: keyof M, ctx: Context<any>): boolean;
|
|
81
|
+
function versionProp<M extends Model<boolean>>(model: M): keyof M;
|
|
82
|
+
function versionOf<M extends Model<boolean>>(model: M): number;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import "@decaf-ts/decorator-validation";
|
|
2
|
+
declare module "@decaf-ts/decorator-validation" {
|
|
3
|
+
interface ModelBuilder<M> {
|
|
4
|
+
generated<N extends keyof M>(attr: N, type?: string): ModelBuilder<M>;
|
|
5
|
+
hash<N extends keyof M>(attr: N): ModelBuilder<M>;
|
|
6
|
+
composedFromKeys<N extends keyof M>(attr: N, args: string[], separator?: string, filterEmpty?: boolean | string[], hash?: boolean, prefix?: string, suffix?: string, groupsort?: {
|
|
7
|
+
priority: number;
|
|
8
|
+
}): ModelBuilder<M>;
|
|
9
|
+
composed<N extends keyof M>(attr: N, args: string[], separator?: string, filterEmpty?: boolean | string[], hash?: boolean, prefix?: string, suffix?: string, groupsort?: {
|
|
10
|
+
priority: number;
|
|
11
|
+
}): ModelBuilder<M>;
|
|
12
|
+
version<N extends keyof M>(attr: N): ModelBuilder<M>;
|
|
13
|
+
transient<N extends keyof M>(attr: N): ModelBuilder<M>;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import "@decaf-ts/decorator-validation";
|
|
2
|
+
declare module "@decaf-ts/decorator-validation" {
|
|
3
|
+
interface ModelBuilder<M> {
|
|
4
|
+
generated<N extends keyof M>(attr: N, type?: string): ModelBuilder<M>;
|
|
5
|
+
hash<N extends keyof M>(attr: N): ModelBuilder<M>;
|
|
6
|
+
composedFromKeys<N extends keyof M>(attr: N, args: string[], separator?: string, filterEmpty?: boolean | string[], hash?: boolean, prefix?: string, suffix?: string, groupsort?: {
|
|
7
|
+
priority: number;
|
|
8
|
+
}): ModelBuilder<M>;
|
|
9
|
+
composed<N extends keyof M>(attr: N, args: string[], separator?: string, filterEmpty?: boolean | string[], hash?: boolean, prefix?: string, suffix?: string, groupsort?: {
|
|
10
|
+
priority: number;
|
|
11
|
+
}): ModelBuilder<M>;
|
|
12
|
+
version<N extends keyof M>(attr: N): ModelBuilder<M>;
|
|
13
|
+
transient<N extends keyof M>(attr: N): ModelBuilder<M>;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Exports for the overrides module.
|
|
3
|
+
* @summary This file exports all the necessary components for the overrides functionality, including Model, overrides, and Metadata.
|
|
4
|
+
* @module db-decorators/overrides
|
|
5
|
+
*/
|
|
6
|
+
import "./overrides";
|
|
7
|
+
export * from "./Model.cjs";
|
|
8
|
+
export * from "./overrides.cjs";
|
|
9
|
+
export * from "./Metadata.cjs";
|
|
10
|
+
export * from "./ModelBuilderExtensions.cjs";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Exports for the overrides module.
|
|
3
|
+
* @summary This file exports all the necessary components for the overrides functionality, including Model, overrides, and Metadata.
|
|
4
|
+
* @module db-decorators/overrides
|
|
5
|
+
*/
|
|
6
|
+
import "./overrides";
|
|
7
|
+
export * from "./Model.js";
|
|
8
|
+
export * from "./overrides.js";
|
|
9
|
+
export * from "./Metadata.js";
|
|
10
|
+
export * from "./ModelBuilderExtensions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { ContextArgs } from "./utils.cjs";
|
|
2
|
+
import { Contextual, FlagsOf } from "../interfaces/Contextual.cjs";
|
|
3
|
+
import { OperationKeys } from "../operations/constants.cjs";
|
|
4
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
5
|
+
import { ObjectAccumulator } from "typed-object-accumulator";
|
|
6
|
+
import { ContextFlags, FlagsOfContext, LoggerOfFlags, RepositoryFlags } from "./types.cjs";
|
|
7
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
8
|
+
/**
|
|
9
|
+
* @description Factory type for creating context instances.
|
|
10
|
+
* @summary Defines a function type that creates context instances with specific repository flags.
|
|
11
|
+
* @template F - The repository flags type extending RepositoryFlags
|
|
12
|
+
* @typedef {Function} ContextFactory
|
|
13
|
+
* @memberOf module:db-decorators
|
|
14
|
+
*/
|
|
15
|
+
export type ContextFactory<C extends Context<any>> = (arg: Partial<Omit<FlagsOf<C>, "timestamp">>) => C;
|
|
16
|
+
/**
|
|
17
|
+
* @description Default factory for creating context instances.
|
|
18
|
+
* @summary A factory function that creates new Context instances with the provided repository flags.
|
|
19
|
+
* It automatically adds a timestamp to the context and returns a properly typed context instance.
|
|
20
|
+
* @const DefaultContextFactory
|
|
21
|
+
* @memberOf module:db-decorators
|
|
22
|
+
*/
|
|
23
|
+
export declare const DefaultContextFactory: ContextFactory<any>;
|
|
24
|
+
/**
|
|
25
|
+
* @description A context management class for handling repository operations.
|
|
26
|
+
* @summary The Context class provides a mechanism for managing repository operations with flags,
|
|
27
|
+
* parent-child relationships, and state accumulation. It allows for hierarchical context chains
|
|
28
|
+
* and maintains operation-specific configurations while supporting type safety through generics.
|
|
29
|
+
*
|
|
30
|
+
* @template F - Type extending RepositoryFlags that defines the context configuration
|
|
31
|
+
*
|
|
32
|
+
* @param {ObjectAccumulator<F>} cache - The internal cache storing accumulated values
|
|
33
|
+
*
|
|
34
|
+
* @class
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* // Creating a new context with repository flags
|
|
39
|
+
* const context = new Context<RepositoryFlags>();
|
|
40
|
+
*
|
|
41
|
+
* // Accumulating values
|
|
42
|
+
* const enrichedContext = context.accumulate({
|
|
43
|
+
* writeOperation: true,
|
|
44
|
+
* affectedTables: ['users'],
|
|
45
|
+
* operation: OperationKeys.CREATE
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* // Accessing values
|
|
49
|
+
* const isWrite = enrichedContext.get('writeOperation'); // true
|
|
50
|
+
* const tables = enrichedContext.get('affectedTables'); // ['users']
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @mermaid
|
|
54
|
+
* sequenceDiagram
|
|
55
|
+
* participant C as Client
|
|
56
|
+
* participant Ctx as Context
|
|
57
|
+
* participant Cache as ObjectAccumulator
|
|
58
|
+
*
|
|
59
|
+
* C->>Ctx: new Context()
|
|
60
|
+
* Ctx->>Cache: create cache
|
|
61
|
+
*
|
|
62
|
+
* C->>Ctx: accumulate(value)
|
|
63
|
+
* Ctx->>Cache: accumulate(value)
|
|
64
|
+
* Cache-->>Ctx: updated cache
|
|
65
|
+
* Ctx-->>C: updated context
|
|
66
|
+
*
|
|
67
|
+
* C->>Ctx: get(key)
|
|
68
|
+
* Ctx->>Cache: get(key)
|
|
69
|
+
* alt Key exists in cache
|
|
70
|
+
* Cache-->>Ctx: value
|
|
71
|
+
* else Key not found
|
|
72
|
+
* Ctx->>Ctx: check parent context
|
|
73
|
+
* alt Parent exists
|
|
74
|
+
* Ctx->>Parent: get(key)
|
|
75
|
+
* Parent-->>Ctx: value
|
|
76
|
+
* else No parent
|
|
77
|
+
* Ctx-->>C: throw error
|
|
78
|
+
* end
|
|
79
|
+
* end
|
|
80
|
+
* Ctx-->>C: requested value
|
|
81
|
+
*/
|
|
82
|
+
export declare class Context<F extends ContextFlags<any> = RepositoryFlags<any>> {
|
|
83
|
+
constructor(ctx?: Context<F>);
|
|
84
|
+
static factory: ContextFactory<any>;
|
|
85
|
+
readonly cache: RepositoryFlags<any> & ObjectAccumulator<any>;
|
|
86
|
+
/**
|
|
87
|
+
* @description Accumulates new values into the context.
|
|
88
|
+
* @summary Merges the provided value object with the existing context state,
|
|
89
|
+
* creating a new immutable cache state.
|
|
90
|
+
*/
|
|
91
|
+
accumulate<V extends object>(value: V): Context<F & V>;
|
|
92
|
+
get logger(): LoggerOfFlags<F>;
|
|
93
|
+
get timestamp(): F["timestamp"];
|
|
94
|
+
/**
|
|
95
|
+
* @description Retrieves a value from the context by key.
|
|
96
|
+
* @param {string} key
|
|
97
|
+
* @return {any}
|
|
98
|
+
*/
|
|
99
|
+
get<K extends keyof F>(key: K): F[K];
|
|
100
|
+
/**
|
|
101
|
+
* @description Creates a child context from another context
|
|
102
|
+
*/
|
|
103
|
+
static childFrom<C extends Context<any>>(context: C, overrides?: Partial<FlagsOf<C>>): C;
|
|
104
|
+
/**
|
|
105
|
+
* @description Creates a new context from operation parameters
|
|
106
|
+
*/
|
|
107
|
+
static from<M extends Model, C extends Context<any>>(operation: OperationKeys.CREATE | OperationKeys.READ | OperationKeys.UPDATE | OperationKeys.DELETE | string, overrides: Partial<FlagsOfContext<C>>, model: Constructor<M>, ...args: any[]): Promise<C>;
|
|
108
|
+
/**
|
|
109
|
+
* @description Prepares arguments for context operations
|
|
110
|
+
*/
|
|
111
|
+
static args<M extends Model<any>, C extends Context<any>>(operation: OperationKeys.CREATE | OperationKeys.READ | OperationKeys.UPDATE | OperationKeys.DELETE | string, model: Constructor<M>, args: any[], contextual?: Contextual<C>, overrides?: Partial<FlagsOf<C>>): Promise<ContextArgs<C>>;
|
|
112
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { ContextArgs } from "./utils.js";
|
|
2
|
+
import { Contextual, FlagsOf } from "../interfaces/Contextual.js";
|
|
3
|
+
import { OperationKeys } from "../operations/constants.js";
|
|
4
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
5
|
+
import { ObjectAccumulator } from "typed-object-accumulator";
|
|
6
|
+
import { ContextFlags, FlagsOfContext, LoggerOfFlags, RepositoryFlags } from "./types.js";
|
|
7
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
8
|
+
/**
|
|
9
|
+
* @description Factory type for creating context instances.
|
|
10
|
+
* @summary Defines a function type that creates context instances with specific repository flags.
|
|
11
|
+
* @template F - The repository flags type extending RepositoryFlags
|
|
12
|
+
* @typedef {Function} ContextFactory
|
|
13
|
+
* @memberOf module:db-decorators
|
|
14
|
+
*/
|
|
15
|
+
export type ContextFactory<C extends Context<any>> = (arg: Partial<Omit<FlagsOf<C>, "timestamp">>) => C;
|
|
16
|
+
/**
|
|
17
|
+
* @description Default factory for creating context instances.
|
|
18
|
+
* @summary A factory function that creates new Context instances with the provided repository flags.
|
|
19
|
+
* It automatically adds a timestamp to the context and returns a properly typed context instance.
|
|
20
|
+
* @const DefaultContextFactory
|
|
21
|
+
* @memberOf module:db-decorators
|
|
22
|
+
*/
|
|
23
|
+
export declare const DefaultContextFactory: ContextFactory<any>;
|
|
24
|
+
/**
|
|
25
|
+
* @description A context management class for handling repository operations.
|
|
26
|
+
* @summary The Context class provides a mechanism for managing repository operations with flags,
|
|
27
|
+
* parent-child relationships, and state accumulation. It allows for hierarchical context chains
|
|
28
|
+
* and maintains operation-specific configurations while supporting type safety through generics.
|
|
29
|
+
*
|
|
30
|
+
* @template F - Type extending RepositoryFlags that defines the context configuration
|
|
31
|
+
*
|
|
32
|
+
* @param {ObjectAccumulator<F>} cache - The internal cache storing accumulated values
|
|
33
|
+
*
|
|
34
|
+
* @class
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* // Creating a new context with repository flags
|
|
39
|
+
* const context = new Context<RepositoryFlags>();
|
|
40
|
+
*
|
|
41
|
+
* // Accumulating values
|
|
42
|
+
* const enrichedContext = context.accumulate({
|
|
43
|
+
* writeOperation: true,
|
|
44
|
+
* affectedTables: ['users'],
|
|
45
|
+
* operation: OperationKeys.CREATE
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* // Accessing values
|
|
49
|
+
* const isWrite = enrichedContext.get('writeOperation'); // true
|
|
50
|
+
* const tables = enrichedContext.get('affectedTables'); // ['users']
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @mermaid
|
|
54
|
+
* sequenceDiagram
|
|
55
|
+
* participant C as Client
|
|
56
|
+
* participant Ctx as Context
|
|
57
|
+
* participant Cache as ObjectAccumulator
|
|
58
|
+
*
|
|
59
|
+
* C->>Ctx: new Context()
|
|
60
|
+
* Ctx->>Cache: create cache
|
|
61
|
+
*
|
|
62
|
+
* C->>Ctx: accumulate(value)
|
|
63
|
+
* Ctx->>Cache: accumulate(value)
|
|
64
|
+
* Cache-->>Ctx: updated cache
|
|
65
|
+
* Ctx-->>C: updated context
|
|
66
|
+
*
|
|
67
|
+
* C->>Ctx: get(key)
|
|
68
|
+
* Ctx->>Cache: get(key)
|
|
69
|
+
* alt Key exists in cache
|
|
70
|
+
* Cache-->>Ctx: value
|
|
71
|
+
* else Key not found
|
|
72
|
+
* Ctx->>Ctx: check parent context
|
|
73
|
+
* alt Parent exists
|
|
74
|
+
* Ctx->>Parent: get(key)
|
|
75
|
+
* Parent-->>Ctx: value
|
|
76
|
+
* else No parent
|
|
77
|
+
* Ctx-->>C: throw error
|
|
78
|
+
* end
|
|
79
|
+
* end
|
|
80
|
+
* Ctx-->>C: requested value
|
|
81
|
+
*/
|
|
82
|
+
export declare class Context<F extends ContextFlags<any> = RepositoryFlags<any>> {
|
|
83
|
+
constructor(ctx?: Context<F>);
|
|
84
|
+
static factory: ContextFactory<any>;
|
|
85
|
+
readonly cache: RepositoryFlags<any> & ObjectAccumulator<any>;
|
|
86
|
+
/**
|
|
87
|
+
* @description Accumulates new values into the context.
|
|
88
|
+
* @summary Merges the provided value object with the existing context state,
|
|
89
|
+
* creating a new immutable cache state.
|
|
90
|
+
*/
|
|
91
|
+
accumulate<V extends object>(value: V): Context<F & V>;
|
|
92
|
+
get logger(): LoggerOfFlags<F>;
|
|
93
|
+
get timestamp(): F["timestamp"];
|
|
94
|
+
/**
|
|
95
|
+
* @description Retrieves a value from the context by key.
|
|
96
|
+
* @param {string} key
|
|
97
|
+
* @return {any}
|
|
98
|
+
*/
|
|
99
|
+
get<K extends keyof F>(key: K): F[K];
|
|
100
|
+
/**
|
|
101
|
+
* @description Creates a child context from another context
|
|
102
|
+
*/
|
|
103
|
+
static childFrom<C extends Context<any>>(context: C, overrides?: Partial<FlagsOf<C>>): C;
|
|
104
|
+
/**
|
|
105
|
+
* @description Creates a new context from operation parameters
|
|
106
|
+
*/
|
|
107
|
+
static from<M extends Model, C extends Context<any>>(operation: OperationKeys.CREATE | OperationKeys.READ | OperationKeys.UPDATE | OperationKeys.DELETE | string, overrides: Partial<FlagsOfContext<C>>, model: Constructor<M>, ...args: any[]): Promise<C>;
|
|
108
|
+
/**
|
|
109
|
+
* @description Prepares arguments for context operations
|
|
110
|
+
*/
|
|
111
|
+
static args<M extends Model<any>, C extends Context<any>>(operation: OperationKeys.CREATE | OperationKeys.READ | OperationKeys.UPDATE | OperationKeys.DELETE | string, model: Constructor<M>, args: any[], contextual?: Contextual<C>, overrides?: Partial<FlagsOf<C>>): Promise<ContextArgs<C>>;
|
|
112
|
+
}
|