@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,348 @@
|
|
|
1
|
+
import { GeneralOperationHandler, GeneralUpdateOperationHandler, IdOperationHandler, OperationHandler, StandardOperationHandler, UpdateOperationHandler } from "./types.cjs";
|
|
2
|
+
import { CrudOperations, OperationKeys, BlockOperationDescriptor, BlockOperationKind, BlockOperationsInput } from "./constants.cjs";
|
|
3
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
4
|
+
import { IRepository } from "../interfaces/index.cjs";
|
|
5
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
6
|
+
/**
|
|
7
|
+
* @description Represents sorting parameters for grouping decorators
|
|
8
|
+
* @summary Defines the structure for specifying group sorting options
|
|
9
|
+
* @typedef {Object} GroupSort
|
|
10
|
+
* @property {number} priority - The priority of the sorting operation, lower numbers represent higher priority
|
|
11
|
+
* @property {string} [group] - Optional property to group decorators, used for grouping related operations
|
|
12
|
+
* @property {number} [groupPriority] - Optional property to specify the priority within a group, lower numbers represent higher priority within the group
|
|
13
|
+
* @category Type Definitions
|
|
14
|
+
*/
|
|
15
|
+
export type GroupSort = {
|
|
16
|
+
priority: number;
|
|
17
|
+
group?: string;
|
|
18
|
+
groupPriority?: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* @description DecoratorObject type definition
|
|
22
|
+
* @summary Defines the structure of an object used to represent a decorator in the context of database operations.
|
|
23
|
+
* @typedef {Object} DecoratorObject
|
|
24
|
+
* @property {OperationHandler<any, any, any>} handler - The handler function to be executed during the operation
|
|
25
|
+
* @property {object} data - Optional metadata to be passed to the handler function
|
|
26
|
+
* @property {string} prop - The property key to which the decorator is applied
|
|
27
|
+
* @category Type Definitions
|
|
28
|
+
*/
|
|
29
|
+
export type DecoratorObject = {
|
|
30
|
+
handler: OperationHandler<any, any, any>;
|
|
31
|
+
data: Record<string, any>[];
|
|
32
|
+
prop: string[];
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* @summary retrieves the arguments for the handler
|
|
36
|
+
* @param {any} dec the decorator
|
|
37
|
+
* @param {string} prop the property name
|
|
38
|
+
* @param {{}} m the model
|
|
39
|
+
* @param {{}} [accum] accumulator used for internal recursiveness
|
|
40
|
+
*
|
|
41
|
+
* @function getHandlerArgs
|
|
42
|
+
* @memberOf module:db-decorators.Repository
|
|
43
|
+
*/
|
|
44
|
+
export declare const getHandlerArgs: (dec: any, prop: string, m: Constructor<any>, accum?: Record<string, {
|
|
45
|
+
args: string[];
|
|
46
|
+
}>) => Record<string, {
|
|
47
|
+
args: string[];
|
|
48
|
+
}> | void;
|
|
49
|
+
/**
|
|
50
|
+
* @description Retrieves decorator objects for handling database operations
|
|
51
|
+
* @summary Retrieves a list of decorator objects representing operation handlers for a given model and decorators
|
|
52
|
+
* @template M - Type for the model, defaults to Model<true | false>
|
|
53
|
+
* @template R - Type for the repository, defaults to IRepository<M, F, C>
|
|
54
|
+
* @template V - Type for metadata, defaults to object
|
|
55
|
+
* @template F - Type for repository flags, defaults to RepositoryFlags
|
|
56
|
+
* @template C - Type for context, defaults to Context<F>
|
|
57
|
+
* @param {Model} model - The model for which to retrieve decorator objects
|
|
58
|
+
* @param {Record<string, DecoratorMetadata[]>} decorators - The decorators associated with the model properties
|
|
59
|
+
* @param {string} prefix - The operation prefix (e.g., 'on', 'after')
|
|
60
|
+
* @return {DecoratorObject[]} An array of decorator objects representing operation handlers
|
|
61
|
+
* @function getHandlersDecorators
|
|
62
|
+
* @category Function
|
|
63
|
+
*/
|
|
64
|
+
export declare function getHandlersDecorators<M extends Model<true | false>, R extends IRepository<M, any>, V extends object = object>(model: Model, decorators: Record<string, DecoratorMetadata[]>, prefix: string): DecoratorObject[];
|
|
65
|
+
/**
|
|
66
|
+
* @description Groups decorators based on their group property
|
|
67
|
+
* @summary Groups decorator objects by their group property, combining data and properties within each group
|
|
68
|
+
* @param {DecoratorObject[]} decorators - The array of decorator objects to group
|
|
69
|
+
* @return {DecoratorObject[]} An array of grouped decorator objects
|
|
70
|
+
* @function groupDecorators
|
|
71
|
+
* @category Function
|
|
72
|
+
*/
|
|
73
|
+
export declare function groupDecorators(decorators: DecoratorObject[]): DecoratorObject[];
|
|
74
|
+
/**
|
|
75
|
+
* @description Sorts decorator objects based on their priority
|
|
76
|
+
* @summary Sorts an array of decorator objects by the priority of their first data element
|
|
77
|
+
* @param {DecoratorObject[]} decorators - The array of decorator objects to sort
|
|
78
|
+
* @return {DecoratorObject[]} The sorted array of decorator objects
|
|
79
|
+
* @function sortDecorators
|
|
80
|
+
* @category Function
|
|
81
|
+
*/
|
|
82
|
+
export declare function sortDecorators(decorators: DecoratorObject[]): DecoratorObject[];
|
|
83
|
+
/**
|
|
84
|
+
* @description Decorator for handling create and update operations
|
|
85
|
+
* @summary Defines a behavior to execute during both create and update operations
|
|
86
|
+
* @template V - Type for metadata, defaults to object
|
|
87
|
+
* @param {GeneralOperationHandler<any, any, V, any, any> | GeneralUpdateOperationHandler<any, any, V, any, any>} handler - The method called upon the operation
|
|
88
|
+
* @param {V} [data] - Optional metadata to pass to the handler
|
|
89
|
+
* @return {PropertyDecorator} A decorator that can be applied to class properties
|
|
90
|
+
* @function onCreateUpdate
|
|
91
|
+
* @category Property Decorators
|
|
92
|
+
*/
|
|
93
|
+
export declare function onCreateUpdate<V = object>(handler: GeneralOperationHandler<any, any, V> | GeneralUpdateOperationHandler<any, any, V>, data?: V, groupsort?: GroupSort): (target: any, propertyKey?: any) => void;
|
|
94
|
+
/**
|
|
95
|
+
* @description Decorator for handling update operations
|
|
96
|
+
* @summary Defines a behavior to execute during update operations
|
|
97
|
+
* @template V - Type for metadata, defaults to object
|
|
98
|
+
* @param {UpdateOperationHandler<any, any, V, any>} handler - The method called upon the operation
|
|
99
|
+
* @param {V} [data] - Optional metadata to pass to the handler
|
|
100
|
+
* @return {PropertyDecorator} A decorator that can be applied to class properties
|
|
101
|
+
* @function onUpdate
|
|
102
|
+
* @category Property Decorators
|
|
103
|
+
*/
|
|
104
|
+
export declare function onUpdate<V = object>(handler: UpdateOperationHandler<any, any, V>, data?: V, groupsort?: GroupSort): (target: any, propertyKey?: any) => void;
|
|
105
|
+
/**
|
|
106
|
+
* @description Decorator for handling create operations
|
|
107
|
+
* @summary Defines a behavior to execute during create operations
|
|
108
|
+
* @template V - Type for metadata, defaults to object
|
|
109
|
+
* @param {GeneralOperationHandler<any, any, V>} handler - The method called upon the operation
|
|
110
|
+
* @param {V} [data] - Optional metadata to pass to the handler
|
|
111
|
+
* @return {PropertyDecorator} A decorator that can be applied to class properties
|
|
112
|
+
* @function onCreate
|
|
113
|
+
* @category Property Decorators
|
|
114
|
+
*/
|
|
115
|
+
export declare function onCreate<V = object>(handler: GeneralOperationHandler<any, any, V>, data?: V, groupsort?: GroupSort): (target: any, propertyKey?: any) => void;
|
|
116
|
+
/**
|
|
117
|
+
* @description Decorator for handling read operations
|
|
118
|
+
* @summary Defines a behavior to execute during read operations
|
|
119
|
+
* @template V - Type for metadata, defaults to object
|
|
120
|
+
* @param {IdOperationHandler<any, any, V>} handler - The method called upon the operation
|
|
121
|
+
* @param {V} [data] - Optional metadata to pass to the handler
|
|
122
|
+
* @return {PropertyDecorator} A decorator that can be applied to class properties
|
|
123
|
+
* @function onRead
|
|
124
|
+
* @category Property Decorators
|
|
125
|
+
*/
|
|
126
|
+
export declare function onRead<V = object>(handler: IdOperationHandler<any, any, V>, data: V, groupsort?: GroupSort): (target: any, propertyKey?: any) => void;
|
|
127
|
+
/**
|
|
128
|
+
* @description Decorator for handling delete operations
|
|
129
|
+
* @summary Defines a behavior to execute during delete operations
|
|
130
|
+
* @template V - Type for metadata, defaults to object
|
|
131
|
+
* @param {OperationHandler<any, any, V, any, any>} handler - The method called upon the operation
|
|
132
|
+
* @param {V} [data] - Optional metadata to pass to the handler
|
|
133
|
+
* @return {PropertyDecorator} A decorator that can be applied to class properties
|
|
134
|
+
* @function onDelete
|
|
135
|
+
* @category Property Decorators
|
|
136
|
+
*/
|
|
137
|
+
export declare function onDelete<V = object>(handler: OperationHandler<any, any, V>, data: V, groupsort?: GroupSort): (target: any, propertyKey?: any) => void;
|
|
138
|
+
/**
|
|
139
|
+
* @description Decorator for handling all operation types
|
|
140
|
+
* @summary Defines a behavior to execute during any database operation
|
|
141
|
+
* @template V - Type for metadata, defaults to object
|
|
142
|
+
* @param {OperationHandler<any, any, V, any, any>} handler - The method called upon the operation
|
|
143
|
+
* @param {V} [data] - Optional metadata to pass to the handler
|
|
144
|
+
* @return {PropertyDecorator} A decorator that can be applied to class properties
|
|
145
|
+
* @function onAny
|
|
146
|
+
* @category Property Decorators
|
|
147
|
+
*/
|
|
148
|
+
export declare function onAny<V = object>(handler: OperationHandler<any, any, V>, data: V, groupsort?: GroupSort): (target: any, propertyKey?: any) => void;
|
|
149
|
+
/**
|
|
150
|
+
* @description Base decorator for handling database operations
|
|
151
|
+
* @summary Defines a behavior to execute during specified database operations
|
|
152
|
+
* @template V - Type for metadata, defaults to object
|
|
153
|
+
* @param {OperationKeys[] | DBOperations} [op=DBOperations.ALL] - One or more operation types to handle
|
|
154
|
+
* @param {OperationHandler<any, any, V, any, any>} handler - The method called upon the operation
|
|
155
|
+
* @param {V} [data] - Optional metadata to pass to the handler
|
|
156
|
+
* @return {PropertyDecorator} A decorator that can be applied to class properties
|
|
157
|
+
* @function on
|
|
158
|
+
* @category Property Decorators
|
|
159
|
+
* @example
|
|
160
|
+
* // Example usage:
|
|
161
|
+
* class MyModel {
|
|
162
|
+
* @on(DBOperations.CREATE, myHandler)
|
|
163
|
+
* myProperty: string;
|
|
164
|
+
* }
|
|
165
|
+
*/
|
|
166
|
+
export declare function on<V = object>(op: OperationKeys[] | undefined, handler: OperationHandler<any, any, V>, data?: V, groupsort?: GroupSort): (target: any, propertyKey?: any) => void;
|
|
167
|
+
/**
|
|
168
|
+
* @description Decorator for handling post-create and post-update operations
|
|
169
|
+
* @summary Defines a behavior to execute after both create and update operations
|
|
170
|
+
* @template V - Type for metadata, defaults to object
|
|
171
|
+
* @param {StandardOperationHandler<any, any, V> | UpdateOperationHandler<any, any, V, any, any>} handler - The method called after the operation
|
|
172
|
+
* @param {V} [data] - Optional metadata to pass to the handler
|
|
173
|
+
* @return {PropertyDecorator} A decorator that can be applied to class properties
|
|
174
|
+
* @function afterCreateUpdate
|
|
175
|
+
* @category Property Decorators
|
|
176
|
+
*/
|
|
177
|
+
export declare function afterCreateUpdate<V = object>(handler: StandardOperationHandler<any, any, V> | UpdateOperationHandler<any, any, V>, data: V, groupsort?: GroupSort): (target: any, propertyKey?: any) => void;
|
|
178
|
+
/**
|
|
179
|
+
* @description Decorator for handling post-update operations
|
|
180
|
+
* @summary Defines a behavior to execute after update operations
|
|
181
|
+
* @template V - Type for metadata, defaults to object
|
|
182
|
+
* @param {UpdateOperationHandler<any, any, V>} handler - The method called after the operation
|
|
183
|
+
* @param {V} [data] - Optional metadata to pass to the handler
|
|
184
|
+
* @return {PropertyDecorator} A decorator that can be applied to class properties
|
|
185
|
+
* @function afterUpdate
|
|
186
|
+
* @category Property Decorators
|
|
187
|
+
*/
|
|
188
|
+
export declare function afterUpdate<V = object>(handler: UpdateOperationHandler<any, any, V>, data: V, groupsort?: GroupSort): (target: any, propertyKey?: any) => void;
|
|
189
|
+
/**
|
|
190
|
+
* @description Decorator for handling post-create operations
|
|
191
|
+
* @summary Defines a behavior to execute after create operations
|
|
192
|
+
* @template V - Type for metadata, defaults to object
|
|
193
|
+
* @param {StandardOperationHandler<any, any, V>} handler - The method called after the operation
|
|
194
|
+
* @param {V} [data] - Optional metadata to pass to the handler
|
|
195
|
+
* @return {PropertyDecorator} A decorator that can be applied to class properties
|
|
196
|
+
* @function afterCreate
|
|
197
|
+
* @category Property Decorators
|
|
198
|
+
*/
|
|
199
|
+
export declare function afterCreate<V = object>(handler: StandardOperationHandler<any, any, V>, data: V, groupsort?: GroupSort): (target: any, propertyKey?: any) => void;
|
|
200
|
+
/**
|
|
201
|
+
* @description Decorator for handling post-read operations
|
|
202
|
+
* @summary Defines a behavior to execute after read operations
|
|
203
|
+
* @template V - Type for metadata, defaults to object
|
|
204
|
+
* @param {StandardOperationHandler<any, any, V, any, any>} handler - The method called after the operation
|
|
205
|
+
* @param {V} [data] - Optional metadata to pass to the handler
|
|
206
|
+
* @return {PropertyDecorator} A decorator that can be applied to class properties
|
|
207
|
+
* @function afterRead
|
|
208
|
+
* @category Property Decorators
|
|
209
|
+
*/
|
|
210
|
+
export declare function afterRead<V = object>(handler: StandardOperationHandler<any, any, V>, data?: V, groupsort?: GroupSort): (target: any, propertyKey?: any) => void;
|
|
211
|
+
/**
|
|
212
|
+
* @description Decorator for handling post-delete operations
|
|
213
|
+
* @summary Defines a behavior to execute after delete operations
|
|
214
|
+
* @template V - Type for metadata, defaults to object
|
|
215
|
+
* @param {StandardOperationHandler<any, any, V, any, any>} handler - The method called after the operation
|
|
216
|
+
* @param {V} [data] - Optional metadata to pass to the handler
|
|
217
|
+
* @return {PropertyDecorator} A decorator that can be applied to class properties
|
|
218
|
+
* @function afterDelete
|
|
219
|
+
* @category Property Decorators
|
|
220
|
+
*/
|
|
221
|
+
export declare function afterDelete<V = object>(handler: StandardOperationHandler<any, any, V>, data?: V, groupsort?: GroupSort): (target: any, propertyKey?: any) => void;
|
|
222
|
+
/**
|
|
223
|
+
* @description Decorator for handling post-operation for all operation types
|
|
224
|
+
* @summary Defines a behavior to execute after any database operation
|
|
225
|
+
* @template V - Type for metadata, defaults to object
|
|
226
|
+
* @param {StandardOperationHandler<any, any, V>} handler - The method called after the operation
|
|
227
|
+
* @param {V} [data] - Optional metadata to pass to the handler
|
|
228
|
+
* @return {PropertyDecorator} A decorator that can be applied to class properties
|
|
229
|
+
* @function afterAny
|
|
230
|
+
* @category Property Decorators
|
|
231
|
+
*/
|
|
232
|
+
export declare function afterAny<V = object>(handler: StandardOperationHandler<any, any, V>, data?: V, groupsort?: GroupSort): (target: any, propertyKey?: any) => void;
|
|
233
|
+
/**
|
|
234
|
+
* @description Base decorator for handling post-operation behaviors
|
|
235
|
+
* @summary Defines a behavior to execute after specified database operations
|
|
236
|
+
* @template V - Type for metadata, defaults to object
|
|
237
|
+
* @param {OperationKeys[] | DBOperations} [op=DBOperations.ALL] - One or more operation types to handle
|
|
238
|
+
* @param {OperationHandler<any, any, Vy>} handler - The method called after the operation
|
|
239
|
+
* @param {V} [data] - Optional metadata to pass to the handler
|
|
240
|
+
* @return {PropertyDecorator} A decorator that can be applied to class properties
|
|
241
|
+
* @function after
|
|
242
|
+
* @category Property Decorators
|
|
243
|
+
* @example
|
|
244
|
+
* // Example usage:
|
|
245
|
+
* class MyModel {
|
|
246
|
+
* @after(DBOperations.CREATE, myHandler)
|
|
247
|
+
* myProperty: string;
|
|
248
|
+
* }
|
|
249
|
+
*/
|
|
250
|
+
export declare function after<V = object>(op: OperationKeys[] | undefined, handler: OperationHandler<any, any, V>, data?: V, groupsort?: GroupSort): (target: any, propertyKey?: any) => void;
|
|
251
|
+
/**
|
|
252
|
+
* @description Core decorator factory for operation handlers
|
|
253
|
+
* @summary Creates decorators that register handlers for database operations
|
|
254
|
+
* @template V - Type for metadata, defaults to object
|
|
255
|
+
* @param {OperationKeys.ON | OperationKeys.AFTER} baseOp - Whether the handler runs during or after the operation
|
|
256
|
+
* @param {OperationKeys[]} [operation=DBOperations.ALL] - The specific operations to handle
|
|
257
|
+
* @param {OperationHandler<any, any, V>} handler - The handler function to execute
|
|
258
|
+
* @param {V} [dataToAdd] - Optional metadata to pass to the handler
|
|
259
|
+
* @return {PropertyDecorator} A decorator that can be applied to class properties
|
|
260
|
+
* @function operation
|
|
261
|
+
* @category Property Decorators
|
|
262
|
+
* @mermaid
|
|
263
|
+
* sequenceDiagram
|
|
264
|
+
* participant Client
|
|
265
|
+
* participant Decorator as @operation
|
|
266
|
+
* participant Operations as Operations Registry
|
|
267
|
+
* participant Handler
|
|
268
|
+
*
|
|
269
|
+
* Client->>Decorator: Apply to property
|
|
270
|
+
* Decorator->>Operations: Register handler
|
|
271
|
+
* Decorator->>Decorator: Store metadata
|
|
272
|
+
*
|
|
273
|
+
* Note over Client,Handler: Later, during operation execution
|
|
274
|
+
* Client->>Operations: Execute operation
|
|
275
|
+
* Operations->>Handler: Call registered handler
|
|
276
|
+
* Handler-->>Operations: Return result
|
|
277
|
+
* Operations-->>Client: Return final result
|
|
278
|
+
*/
|
|
279
|
+
export declare function operation<V = object>(baseOp: OperationKeys.ON | OperationKeys.AFTER, operation: OperationKeys[] | undefined, handler: OperationHandler<any, any, V>, dataToAdd?: V, groupsort?: GroupSort): (target: any, propertyKey?: any) => void;
|
|
280
|
+
/**
|
|
281
|
+
* @description
|
|
282
|
+
* Creates a higher-order function that attaches a metadata entry containing a handler
|
|
283
|
+
* and its execution parameters, to be conditionally evaluated later.
|
|
284
|
+
*
|
|
285
|
+
* @summary
|
|
286
|
+
* The `executeIf` function is a decorator factory designed to wrap a handler function
|
|
287
|
+
* and associate it with a specific metadata key. When invoked, it stores both the
|
|
288
|
+
* parameters passed and the handler reference inside the metadata system for deferred
|
|
289
|
+
* or conditional evaluation. This is particularly useful for dynamically applying logic
|
|
290
|
+
* or decorators only when certain conditions are met.
|
|
291
|
+
*
|
|
292
|
+
* @template P - Represents a tuple of any parameter types that the handler function accepts.
|
|
293
|
+
*
|
|
294
|
+
* @param {string} key - The metadata key used to store and later retrieve the handler and its parameters.
|
|
295
|
+
* @param {function(...P):boolean} handler - A predicate or handler function that receives the same parameters as the decorator
|
|
296
|
+
* and determines whether the associated logic should execute.
|
|
297
|
+
*
|
|
298
|
+
* @return {function(...P):function(...Partial<P>):void}
|
|
299
|
+
* Returns a function that, when invoked with the given parameters, stores a metadata object containing
|
|
300
|
+
* both the parameters and the handler reference under the provided key.
|
|
301
|
+
*
|
|
302
|
+
* @function storeHandlerMetadata
|
|
303
|
+
*
|
|
304
|
+
* @mermaid
|
|
305
|
+
* sequenceDiagram
|
|
306
|
+
* participant Dev as Developer
|
|
307
|
+
* participant executeIf as executeIf()
|
|
308
|
+
* participant ReturnedFn as Returned Function
|
|
309
|
+
* participant Metadata as metadata()
|
|
310
|
+
*
|
|
311
|
+
* Dev->>executeIf: Calls executeIf(key, handler)
|
|
312
|
+
* executeIf->>ReturnedFn: Returns function(...params)
|
|
313
|
+
* Dev->>ReturnedFn: Invokes returned function with (...params)
|
|
314
|
+
* ReturnedFn->>Metadata: Calls metadata(key, { args: params, handler })
|
|
315
|
+
* Metadata-->>ReturnedFn: Returns stored metadata reference
|
|
316
|
+
* ReturnedFn-->>Dev: Returns metadata response
|
|
317
|
+
*
|
|
318
|
+
*/
|
|
319
|
+
export declare function storeHandlerMetadata<P extends any[]>(key: string, handler: (...params: P) => boolean): (...params: Partial<P>) => (model: any, prop?: any, descriptor?: PropertyDescriptor | number) => void;
|
|
320
|
+
export declare const BlockOperations: (operations: BlockOperationsInput) => (model: any, prop?: any, descriptor?: PropertyDescriptor | number) => void;
|
|
321
|
+
/**
|
|
322
|
+
* @description
|
|
323
|
+
* Decorator factory that conditionally blocks specific CRUD operations
|
|
324
|
+
* from being executed on a model or controller.
|
|
325
|
+
*
|
|
326
|
+
* @summary
|
|
327
|
+
* The `BlockOperations` decorator integrates with the `executeIf` mechanism to
|
|
328
|
+
* associate metadata that defines which CRUD operations should be restricted.
|
|
329
|
+
* When applied, it registers a conditional handler that evaluates whether a given
|
|
330
|
+
* operation is included in the list of blocked operations. This enables dynamic,
|
|
331
|
+
* metadata-driven control over allowed operations in CRUD-based systems.
|
|
332
|
+
*
|
|
333
|
+
* @template CrudOperations - Enum or type representing valid CRUD operations.
|
|
334
|
+
*
|
|
335
|
+
* @param {function(any[]): boolean} handler - An array of CRUD operations that should be blocked.
|
|
336
|
+
* The handler will later check if the requested operation is part of this list.
|
|
337
|
+
*
|
|
338
|
+
* Returns a decorator that stores metadata indicating which operations are blocked.
|
|
339
|
+
* The metadata can be inspected or enforced later within the application's lifecycle.
|
|
340
|
+
*
|
|
341
|
+
* @function BlockOperationIf
|
|
342
|
+
|
|
343
|
+
* @category decorators
|
|
344
|
+
*/
|
|
345
|
+
type LegacyBlockOperationHandler = (operations: CrudOperations[], operation: CrudOperations) => boolean;
|
|
346
|
+
type BlockOperationIfHandler = (targets: BlockOperationDescriptor[], kind: BlockOperationKind, value: string) => boolean;
|
|
347
|
+
export declare const BlockOperationIf: (handler: LegacyBlockOperationHandler | BlockOperationIfHandler) => (model: any, prop?: any, descriptor?: PropertyDescriptor | number) => void;
|
|
348
|
+
export {};
|