@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.
Files changed (203) hide show
  1. package/lib/cjs/identity/decorators.cjs +5 -4
  2. package/lib/cjs/identity/decorators.cjs.map +1 -0
  3. package/lib/cjs/identity/index.cjs +1 -0
  4. package/lib/cjs/identity/index.cjs.map +1 -0
  5. package/lib/cjs/index.cjs +2 -1
  6. package/lib/cjs/index.cjs.map +1 -0
  7. package/lib/cjs/interfaces/BulkCrudOperator.cjs +1 -0
  8. package/lib/cjs/interfaces/BulkCrudOperator.cjs.map +1 -0
  9. package/lib/cjs/interfaces/Contextual.cjs +1 -0
  10. package/lib/cjs/interfaces/Contextual.cjs.map +1 -0
  11. package/lib/cjs/interfaces/CrudOperator.cjs +1 -0
  12. package/lib/cjs/interfaces/CrudOperator.cjs.map +1 -0
  13. package/lib/cjs/interfaces/IRepository.cjs +1 -0
  14. package/lib/cjs/interfaces/IRepository.cjs.map +1 -0
  15. package/lib/cjs/interfaces/index.cjs +1 -0
  16. package/lib/cjs/interfaces/index.cjs.map +1 -0
  17. package/lib/cjs/model/constants.cjs +1 -0
  18. package/lib/cjs/model/constants.cjs.map +1 -0
  19. package/lib/cjs/model/decorators.cjs +25 -24
  20. package/lib/cjs/model/decorators.cjs.map +1 -0
  21. package/lib/cjs/model/index.cjs +1 -0
  22. package/lib/cjs/model/index.cjs.map +1 -0
  23. package/lib/cjs/model/model.cjs +1 -0
  24. package/lib/cjs/model/model.cjs.map +1 -0
  25. package/lib/cjs/model/validation.cjs +1 -0
  26. package/lib/cjs/model/validation.cjs.map +1 -0
  27. package/lib/cjs/operations/Operations.cjs +6 -5
  28. package/lib/cjs/operations/Operations.cjs.map +1 -0
  29. package/lib/cjs/operations/OperationsRegistry.cjs +1 -0
  30. package/lib/cjs/operations/OperationsRegistry.cjs.map +1 -0
  31. package/lib/cjs/operations/constants.cjs +15 -39
  32. package/lib/cjs/operations/constants.cjs.map +1 -0
  33. package/lib/cjs/operations/decorators.cjs +42 -41
  34. package/lib/cjs/operations/decorators.cjs.map +1 -0
  35. package/lib/cjs/operations/index.cjs +1 -0
  36. package/lib/cjs/operations/index.cjs.map +1 -0
  37. package/lib/cjs/operations/types.cjs +1 -0
  38. package/lib/cjs/operations/types.cjs.map +1 -0
  39. package/lib/cjs/overrides/Metadata.cjs +1 -0
  40. package/lib/cjs/overrides/Metadata.cjs.map +1 -0
  41. package/lib/cjs/overrides/Model.cjs +1 -0
  42. package/lib/cjs/overrides/Model.cjs.map +1 -0
  43. package/lib/cjs/overrides/ModelBuilderExtensions.cjs +8 -7
  44. package/lib/cjs/overrides/ModelBuilderExtensions.cjs.map +1 -0
  45. package/lib/cjs/overrides/index.cjs +1 -0
  46. package/lib/cjs/overrides/index.cjs.map +1 -0
  47. package/lib/cjs/overrides/overrides.cjs +21 -20
  48. package/lib/cjs/overrides/overrides.cjs.map +1 -0
  49. package/lib/cjs/repository/Context.cjs +3 -2
  50. package/lib/cjs/repository/Context.cjs.map +1 -0
  51. package/lib/cjs/repository/Repository.cjs +42 -41
  52. package/lib/cjs/repository/Repository.cjs.map +1 -0
  53. package/lib/cjs/repository/constants.cjs +1 -0
  54. package/lib/cjs/repository/constants.cjs.map +1 -0
  55. package/lib/cjs/repository/errors.cjs +1 -0
  56. package/lib/cjs/repository/errors.cjs.map +1 -0
  57. package/lib/cjs/repository/index.cjs +1 -0
  58. package/lib/cjs/repository/index.cjs.map +1 -0
  59. package/lib/cjs/repository/types.cjs +1 -0
  60. package/lib/cjs/repository/types.cjs.map +1 -0
  61. package/lib/cjs/repository/utils.cjs +10 -9
  62. package/lib/cjs/repository/utils.cjs.map +1 -0
  63. package/lib/cjs/repository/wrappers.cjs +8 -7
  64. package/lib/cjs/repository/wrappers.cjs.map +1 -0
  65. package/lib/cjs/validation/constants.cjs +4 -3
  66. package/lib/cjs/validation/constants.cjs.map +1 -0
  67. package/lib/cjs/validation/decorators.cjs +22 -21
  68. package/lib/cjs/validation/decorators.cjs.map +1 -0
  69. package/lib/cjs/validation/index.cjs +1 -0
  70. package/lib/cjs/validation/index.cjs.map +1 -0
  71. package/lib/cjs/validation/validation.cjs +3 -2
  72. package/lib/cjs/validation/validation.cjs.map +1 -0
  73. package/lib/cjs/validation/validators/ReadOnlyValidator.cjs +14 -8
  74. package/lib/cjs/validation/validators/ReadOnlyValidator.cjs.map +1 -0
  75. package/lib/cjs/validation/validators/TimestampValidator.cjs +14 -8
  76. package/lib/cjs/validation/validators/TimestampValidator.cjs.map +1 -0
  77. package/lib/cjs/validation/validators/UpdateValidator.cjs +1 -0
  78. package/lib/cjs/validation/validators/UpdateValidator.cjs.map +1 -0
  79. package/lib/cjs/validation/validators/index.cjs +1 -0
  80. package/lib/cjs/validation/validators/index.cjs.map +1 -0
  81. package/lib/esm/index.js +1 -1
  82. package/lib/types/identity/decorators.d.cts +8 -0
  83. package/lib/types/identity/decorators.d.mts +8 -0
  84. package/lib/types/identity/index.d.cts +6 -0
  85. package/lib/types/identity/index.d.mts +6 -0
  86. package/lib/types/index.d.cts +15 -0
  87. package/lib/types/index.d.mts +15 -0
  88. package/lib/types/index.d.ts +1 -1
  89. package/lib/types/interfaces/BulkCrudOperator.d.cts +47 -0
  90. package/lib/types/interfaces/BulkCrudOperator.d.mts +47 -0
  91. package/lib/types/interfaces/Contextual.d.cts +23 -0
  92. package/lib/types/interfaces/Contextual.d.mts +23 -0
  93. package/lib/types/interfaces/CrudOperator.d.cts +46 -0
  94. package/lib/types/interfaces/CrudOperator.d.mts +46 -0
  95. package/lib/types/interfaces/IRepository.d.cts +19 -0
  96. package/lib/types/interfaces/IRepository.d.mts +19 -0
  97. package/lib/types/interfaces/index.d.cts +9 -0
  98. package/lib/types/interfaces/index.d.mts +9 -0
  99. package/lib/types/model/constants.d.cts +37 -0
  100. package/lib/types/model/constants.d.mts +37 -0
  101. package/lib/types/model/decorators.d.cts +145 -0
  102. package/lib/types/model/decorators.d.mts +145 -0
  103. package/lib/types/model/index.d.cts +9 -0
  104. package/lib/types/model/index.d.mts +9 -0
  105. package/lib/types/model/model.d.cts +6 -0
  106. package/lib/types/model/model.d.mts +6 -0
  107. package/lib/types/model/validation.d.cts +57 -0
  108. package/lib/types/model/validation.d.mts +57 -0
  109. package/lib/types/operations/Operations.d.cts +80 -0
  110. package/lib/types/operations/Operations.d.mts +80 -0
  111. package/lib/types/operations/OperationsRegistry.d.cts +72 -0
  112. package/lib/types/operations/OperationsRegistry.d.mts +72 -0
  113. package/lib/types/operations/constants.d.cts +106 -0
  114. package/lib/types/operations/constants.d.mts +106 -0
  115. package/lib/types/operations/decorators.d.cts +348 -0
  116. package/lib/types/operations/decorators.d.mts +348 -0
  117. package/lib/types/operations/index.d.cts +10 -0
  118. package/lib/types/operations/index.d.mts +10 -0
  119. package/lib/types/operations/types.d.cts +60 -0
  120. package/lib/types/operations/types.d.mts +60 -0
  121. package/lib/types/overrides/Metadata.d.cts +54 -0
  122. package/lib/types/overrides/Metadata.d.mts +54 -0
  123. package/lib/types/overrides/Model.d.cts +84 -0
  124. package/lib/types/overrides/Model.d.mts +84 -0
  125. package/lib/types/overrides/ModelBuilderExtensions.d.cts +15 -0
  126. package/lib/types/overrides/ModelBuilderExtensions.d.mts +15 -0
  127. package/lib/types/overrides/index.d.cts +10 -0
  128. package/lib/types/overrides/index.d.mts +10 -0
  129. package/lib/types/overrides/overrides.d.cts +1 -0
  130. package/lib/types/overrides/overrides.d.mts +1 -0
  131. package/lib/types/repository/Context.d.cts +112 -0
  132. package/lib/types/repository/Context.d.mts +112 -0
  133. package/lib/types/repository/Repository.d.cts +352 -0
  134. package/lib/types/repository/Repository.d.mts +352 -0
  135. package/lib/types/repository/constants.d.cts +9 -0
  136. package/lib/types/repository/constants.d.mts +9 -0
  137. package/lib/types/repository/errors.d.cts +126 -0
  138. package/lib/types/repository/errors.d.mts +126 -0
  139. package/lib/types/repository/index.d.cts +12 -0
  140. package/lib/types/repository/index.d.mts +12 -0
  141. package/lib/types/repository/types.d.cts +62 -0
  142. package/lib/types/repository/types.d.mts +62 -0
  143. package/lib/types/repository/utils.d.cts +34 -0
  144. package/lib/types/repository/utils.d.mts +34 -0
  145. package/lib/types/repository/wrappers.d.cts +39 -0
  146. package/lib/types/repository/wrappers.d.mts +39 -0
  147. package/lib/types/validation/constants.d.cts +45 -0
  148. package/lib/types/validation/constants.d.mts +45 -0
  149. package/lib/types/validation/decorators.d.cts +143 -0
  150. package/lib/types/validation/decorators.d.mts +143 -0
  151. package/lib/types/validation/index.d.cts +4 -0
  152. package/lib/types/validation/index.d.mts +4 -0
  153. package/lib/types/validation/validation.d.cts +41 -0
  154. package/lib/types/validation/validation.d.mts +41 -0
  155. package/lib/types/validation/validators/ReadOnlyValidator.d.cts +47 -0
  156. package/lib/types/validation/validators/ReadOnlyValidator.d.mts +47 -0
  157. package/lib/types/validation/validators/TimestampValidator.d.cts +48 -0
  158. package/lib/types/validation/validators/TimestampValidator.d.mts +48 -0
  159. package/lib/types/validation/validators/UpdateValidator.d.cts +40 -0
  160. package/lib/types/validation/validators/UpdateValidator.d.mts +40 -0
  161. package/lib/types/validation/validators/index.d.cts +3 -0
  162. package/lib/types/validation/validators/index.d.mts +3 -0
  163. package/package.json +4 -4
  164. package/lib/cjs/identity/decorators.js.map +0 -1
  165. package/lib/cjs/identity/index.js.map +0 -1
  166. package/lib/cjs/index.js.map +0 -1
  167. package/lib/cjs/interfaces/BulkCrudOperator.js.map +0 -1
  168. package/lib/cjs/interfaces/Contextual.js.map +0 -1
  169. package/lib/cjs/interfaces/CrudOperator.js.map +0 -1
  170. package/lib/cjs/interfaces/IRepository.js.map +0 -1
  171. package/lib/cjs/interfaces/index.js.map +0 -1
  172. package/lib/cjs/model/constants.js.map +0 -1
  173. package/lib/cjs/model/decorators.js.map +0 -1
  174. package/lib/cjs/model/index.js.map +0 -1
  175. package/lib/cjs/model/model.js.map +0 -1
  176. package/lib/cjs/model/validation.js.map +0 -1
  177. package/lib/cjs/operations/Operations.js.map +0 -1
  178. package/lib/cjs/operations/OperationsRegistry.js.map +0 -1
  179. package/lib/cjs/operations/constants.js.map +0 -1
  180. package/lib/cjs/operations/decorators.js.map +0 -1
  181. package/lib/cjs/operations/index.js.map +0 -1
  182. package/lib/cjs/operations/types.js.map +0 -1
  183. package/lib/cjs/overrides/Metadata.js.map +0 -1
  184. package/lib/cjs/overrides/Model.js.map +0 -1
  185. package/lib/cjs/overrides/ModelBuilderExtensions.js.map +0 -1
  186. package/lib/cjs/overrides/index.js.map +0 -1
  187. package/lib/cjs/overrides/overrides.js.map +0 -1
  188. package/lib/cjs/repository/Context.js.map +0 -1
  189. package/lib/cjs/repository/Repository.js.map +0 -1
  190. package/lib/cjs/repository/constants.js.map +0 -1
  191. package/lib/cjs/repository/errors.js.map +0 -1
  192. package/lib/cjs/repository/index.js.map +0 -1
  193. package/lib/cjs/repository/types.js.map +0 -1
  194. package/lib/cjs/repository/utils.js.map +0 -1
  195. package/lib/cjs/repository/wrappers.js.map +0 -1
  196. package/lib/cjs/validation/constants.js.map +0 -1
  197. package/lib/cjs/validation/decorators.js.map +0 -1
  198. package/lib/cjs/validation/index.js.map +0 -1
  199. package/lib/cjs/validation/validation.js.map +0 -1
  200. package/lib/cjs/validation/validators/ReadOnlyValidator.js.map +0 -1
  201. package/lib/cjs/validation/validators/TimestampValidator.js.map +0 -1
  202. package/lib/cjs/validation/validators/UpdateValidator.js.map +0 -1
  203. package/lib/cjs/validation/validators/index.js.map +0 -1
@@ -0,0 +1,348 @@
1
+ import { GeneralOperationHandler, GeneralUpdateOperationHandler, IdOperationHandler, OperationHandler, StandardOperationHandler, UpdateOperationHandler } from "./types.js";
2
+ import { CrudOperations, OperationKeys, BlockOperationDescriptor, BlockOperationKind, BlockOperationsInput } from "./constants.js";
3
+ import { Model } from "@decaf-ts/decorator-validation";
4
+ import { IRepository } from "../interfaces/index.js";
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 {};
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @description Exports for the operations module.
3
+ * @summary This file exports all the necessary components for the operations functionality, including constants, decorators, and the Operations class.
4
+ * @module db-decorators/operations
5
+ */
6
+ export * from "./constants.cjs";
7
+ export * from "./decorators.cjs";
8
+ export * from "./Operations.cjs";
9
+ export * from "./OperationsRegistry.cjs";
10
+ export * from "./types.cjs";
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @description Exports for the operations module.
3
+ * @summary This file exports all the necessary components for the operations functionality, including constants, decorators, and the Operations class.
4
+ * @module db-decorators/operations
5
+ */
6
+ export * from "./constants.js";
7
+ export * from "./decorators.js";
8
+ export * from "./Operations.js";
9
+ export * from "./OperationsRegistry.js";
10
+ export * from "./types.js";
@@ -0,0 +1,60 @@
1
+ import { OperationKeys } from "./constants.cjs";
2
+ import { IRepository } from "../interfaces/IRepository.cjs";
3
+ import { Model } from "@decaf-ts/decorator-validation";
4
+ import { ContextOfRepository } from "../repository/index.cjs";
5
+ /**
6
+ * @description Metadata for database operations
7
+ * @summary Contains information about an operation, its handler, and associated metadata
8
+ * @template V - Type of the metadata
9
+ * @typedef {Object} OperationMetadata
10
+ * @property {OperationKeys} operation - The type of operation
11
+ * @property {string} handler - The name of the handler function
12
+ * @property {V} [metadata] - Optional metadata associated with the operation
13
+ * @memberOf module:db-decorators
14
+ */
15
+ export type OperationMetadata<V> = {
16
+ operation: OperationKeys;
17
+ handler: string;
18
+ metadata?: V;
19
+ };
20
+ /**
21
+ * @description Union type for all operation handler types
22
+ * @summary Represents any type of operation handler function that can be used with database operations
23
+ * @template M - Model type extending Model
24
+ * @template R - Repository type extending IRepository
25
+ * @template V - Metadata type, defaults to object
26
+ * @template F - Repository flags extending RepositoryFlags
27
+ * @template C - Context type extending Context<F>
28
+ * @memberOf module:db-decorators
29
+ */
30
+ export type OperationHandler<M extends Model, R extends IRepository<M, any>, V = object> = StandardOperationHandler<M, R, V> | UpdateOperationHandler<M, R, V> | IdOperationHandler<M, R, V> | GroupOperationHandler<M, R, V> | GroupUpdateOperationHandler<M, R, V>;
31
+ export type StandardOperationHandler<M extends Model, R extends IRepository<M, any>, V = object> = (this: R, context: ContextOfRepository<R>, metadata: V, key: keyof M, model: M) => Promise<void> | void;
32
+ export type IdOperationHandler<M extends Model, R extends IRepository<M, any>, V = object> = (this: R, context: ContextOfRepository<R>, decorator: V, key: keyof M, id: string) => Promise<void> | void;
33
+ export type UpdateOperationHandler<M extends Model, R extends IRepository<M, any>, V = object> = (this: R, context: ContextOfRepository<R>, decorator: V, key: keyof M, model: M, oldModel: M) => Promise<void> | void;
34
+ export type GroupOperationHandler<M extends Model, R extends IRepository<M, any>, V = object> = (this: R, context: ContextOfRepository<R>, metadata: V[], keys: (keyof M)[], model: M) => Promise<void> | void;
35
+ export type GroupUpdateOperationHandler<M extends Model, R extends IRepository<M, any>, V = object> = (this: R, context: ContextOfRepository<R>, decorator: V[], keys: (keyof M)[], model: M, oldModel: M) => Promise<void> | void;
36
+ /**
37
+ * @description General handler type for database operations
38
+ * @summary Function signature for handlers that process operations like create and read
39
+ * @template M - Model type extending Model
40
+ * @template R - Repository type extending IRepository
41
+ * @template V - Metadata type, defaults to object
42
+ * @template F - Repository flags extending RepositoryFlags
43
+ * @template C - Context type extending Context<F>
44
+ * @typedef {Function} GeneralOperationHandler
45
+ * @return {Promise<void> | void} Nothing or a Promise resolving to nothing
46
+ * @memberOf module:db-decorators
47
+ */
48
+ export type GeneralOperationHandler<M extends Model, R extends IRepository<M, any>, V = object> = StandardOperationHandler<M, R, V> | GroupOperationHandler<M, R, V>;
49
+ /**
50
+ * @description General handler type for group update database operations
51
+ * @summary Function signature for handlers that process update operations with both new and old model states
52
+ * @template M - Model type extending Model
53
+ * @template R - Repository type extending IRepository
54
+ * @template V - Metadata type, defaults to object
55
+ * @template F - Repository flags extending RepositoryFlags
56
+ * @template C - Context type extending Context<F>
57
+ * @typedef {Function} GeneralUpdateOperationHandler
58
+ * @memberOf module:db-decorators
59
+ */
60
+ export type GeneralUpdateOperationHandler<M extends Model, R extends IRepository<M, any>, V = object> = UpdateOperationHandler<M, R, V> | GroupUpdateOperationHandler<M, R, V>;
@@ -0,0 +1,60 @@
1
+ import { OperationKeys } from "./constants.js";
2
+ import { IRepository } from "../interfaces/IRepository.js";
3
+ import { Model } from "@decaf-ts/decorator-validation";
4
+ import { ContextOfRepository } from "../repository/index.js";
5
+ /**
6
+ * @description Metadata for database operations
7
+ * @summary Contains information about an operation, its handler, and associated metadata
8
+ * @template V - Type of the metadata
9
+ * @typedef {Object} OperationMetadata
10
+ * @property {OperationKeys} operation - The type of operation
11
+ * @property {string} handler - The name of the handler function
12
+ * @property {V} [metadata] - Optional metadata associated with the operation
13
+ * @memberOf module:db-decorators
14
+ */
15
+ export type OperationMetadata<V> = {
16
+ operation: OperationKeys;
17
+ handler: string;
18
+ metadata?: V;
19
+ };
20
+ /**
21
+ * @description Union type for all operation handler types
22
+ * @summary Represents any type of operation handler function that can be used with database operations
23
+ * @template M - Model type extending Model
24
+ * @template R - Repository type extending IRepository
25
+ * @template V - Metadata type, defaults to object
26
+ * @template F - Repository flags extending RepositoryFlags
27
+ * @template C - Context type extending Context<F>
28
+ * @memberOf module:db-decorators
29
+ */
30
+ export type OperationHandler<M extends Model, R extends IRepository<M, any>, V = object> = StandardOperationHandler<M, R, V> | UpdateOperationHandler<M, R, V> | IdOperationHandler<M, R, V> | GroupOperationHandler<M, R, V> | GroupUpdateOperationHandler<M, R, V>;
31
+ export type StandardOperationHandler<M extends Model, R extends IRepository<M, any>, V = object> = (this: R, context: ContextOfRepository<R>, metadata: V, key: keyof M, model: M) => Promise<void> | void;
32
+ export type IdOperationHandler<M extends Model, R extends IRepository<M, any>, V = object> = (this: R, context: ContextOfRepository<R>, decorator: V, key: keyof M, id: string) => Promise<void> | void;
33
+ export type UpdateOperationHandler<M extends Model, R extends IRepository<M, any>, V = object> = (this: R, context: ContextOfRepository<R>, decorator: V, key: keyof M, model: M, oldModel: M) => Promise<void> | void;
34
+ export type GroupOperationHandler<M extends Model, R extends IRepository<M, any>, V = object> = (this: R, context: ContextOfRepository<R>, metadata: V[], keys: (keyof M)[], model: M) => Promise<void> | void;
35
+ export type GroupUpdateOperationHandler<M extends Model, R extends IRepository<M, any>, V = object> = (this: R, context: ContextOfRepository<R>, decorator: V[], keys: (keyof M)[], model: M, oldModel: M) => Promise<void> | void;
36
+ /**
37
+ * @description General handler type for database operations
38
+ * @summary Function signature for handlers that process operations like create and read
39
+ * @template M - Model type extending Model
40
+ * @template R - Repository type extending IRepository
41
+ * @template V - Metadata type, defaults to object
42
+ * @template F - Repository flags extending RepositoryFlags
43
+ * @template C - Context type extending Context<F>
44
+ * @typedef {Function} GeneralOperationHandler
45
+ * @return {Promise<void> | void} Nothing or a Promise resolving to nothing
46
+ * @memberOf module:db-decorators
47
+ */
48
+ export type GeneralOperationHandler<M extends Model, R extends IRepository<M, any>, V = object> = StandardOperationHandler<M, R, V> | GroupOperationHandler<M, R, V>;
49
+ /**
50
+ * @description General handler type for group update database operations
51
+ * @summary Function signature for handlers that process update operations with both new and old model states
52
+ * @template M - Model type extending Model
53
+ * @template R - Repository type extending IRepository
54
+ * @template V - Metadata type, defaults to object
55
+ * @template F - Repository flags extending RepositoryFlags
56
+ * @template C - Context type extending Context<F>
57
+ * @typedef {Function} GeneralUpdateOperationHandler
58
+ * @memberOf module:db-decorators
59
+ */
60
+ export type GeneralUpdateOperationHandler<M extends Model, R extends IRepository<M, any>, V = object> = UpdateOperationHandler<M, R, V> | GroupUpdateOperationHandler<M, R, V>;
@@ -0,0 +1,54 @@
1
+ import "@decaf-ts/decoration";
2
+ import type { Constructor } from "@decaf-ts/decoration";
3
+ import type { Model } from "@decaf-ts/decorator-validation";
4
+ declare module "@decaf-ts/decoration" {
5
+ namespace Metadata {
6
+ /**
7
+ * @description Saves metadata under a key for a specific operation
8
+ * @summary Saves metadata under a key for a specific operation
9
+ *
10
+ * @template M - The model type extending from Model
11
+ * @param {Constructor<M>} model - The constructor of the target model class
12
+ * @param {keyof M} propertyKey - The property key to store metadata for
13
+ * @param {string} operation - The type of operation being done. Eg. on.update
14
+ * @param {any} metadata - The metadata to store to for the operation
15
+ * @return {void}
16
+ *
17
+ * @example
18
+ * class User extends Model {
19
+ *
20
+ * // Set metatada for 'User' for key updatedOn, for operation on.create
21
+ * Metadata.saveOperation(User.constructor,'updatedOn','on.create',metadata);
22
+ */
23
+ function saveOperation<M extends Model>(model: Constructor<M>, propertyKey: keyof M, operation: string, metadata: any): void;
24
+ function pk<M extends Model<boolean>>(model: M | Constructor<M>): keyof M;
25
+ function pk<M extends Model<boolean>>(model: M, keyValue: boolean): M[keyof M];
26
+ function pk<M extends Model<boolean>>(model: M | Constructor<M>, keyValue?: boolean): keyof M | M[keyof M];
27
+ /**
28
+ * @description Reads the metadata under a key for a specific operation
29
+ * @summary Reads the metadata under a key for a specific operation
30
+ *
31
+ * @template M - The model type extending from Model
32
+ * @param {Constructor<M>} model - The constructor of the target model class
33
+ * @param {keyof M} propertyKey - The property key to store metadata for
34
+ * @param {string} operation - The type of operation being done. Eg. on.update
35
+ * @return {any} metadata - The metadata to store to for the operation
36
+ *
37
+ * @example
38
+ * class User extends Model {
39
+ *
40
+ * // Get metatada for 'User' for key updatedOn, for operation on.create
41
+ * const metadata = Metadata.readOperation(User.constructor,'updatedOn','on.create');
42
+ */
43
+ function readOperation<M extends Model>(model: Constructor<M>, propertyKey?: keyof M, operation?: string): any;
44
+ /**
45
+ * @description Checks if a model is marked as transient
46
+ * @summary Determines whether a model class has been decorated with the transient decorator
47
+ * @template M - Type extending Model
48
+ * @param {M | Constructor<M>} model - The model instance to check
49
+ * @return {boolean} True if the model is transient, false otherwise
50
+ * @function isTransient
51
+ */
52
+ function isTransient<M extends Model>(model: M | Constructor<M>): boolean;
53
+ }
54
+ }
@@ -0,0 +1,54 @@
1
+ import "@decaf-ts/decoration";
2
+ import type { Constructor } from "@decaf-ts/decoration";
3
+ import type { Model } from "@decaf-ts/decorator-validation";
4
+ declare module "@decaf-ts/decoration" {
5
+ namespace Metadata {
6
+ /**
7
+ * @description Saves metadata under a key for a specific operation
8
+ * @summary Saves metadata under a key for a specific operation
9
+ *
10
+ * @template M - The model type extending from Model
11
+ * @param {Constructor<M>} model - The constructor of the target model class
12
+ * @param {keyof M} propertyKey - The property key to store metadata for
13
+ * @param {string} operation - The type of operation being done. Eg. on.update
14
+ * @param {any} metadata - The metadata to store to for the operation
15
+ * @return {void}
16
+ *
17
+ * @example
18
+ * class User extends Model {
19
+ *
20
+ * // Set metatada for 'User' for key updatedOn, for operation on.create
21
+ * Metadata.saveOperation(User.constructor,'updatedOn','on.create',metadata);
22
+ */
23
+ function saveOperation<M extends Model>(model: Constructor<M>, propertyKey: keyof M, operation: string, metadata: any): void;
24
+ function pk<M extends Model<boolean>>(model: M | Constructor<M>): keyof M;
25
+ function pk<M extends Model<boolean>>(model: M, keyValue: boolean): M[keyof M];
26
+ function pk<M extends Model<boolean>>(model: M | Constructor<M>, keyValue?: boolean): keyof M | M[keyof M];
27
+ /**
28
+ * @description Reads the metadata under a key for a specific operation
29
+ * @summary Reads the metadata under a key for a specific operation
30
+ *
31
+ * @template M - The model type extending from Model
32
+ * @param {Constructor<M>} model - The constructor of the target model class
33
+ * @param {keyof M} propertyKey - The property key to store metadata for
34
+ * @param {string} operation - The type of operation being done. Eg. on.update
35
+ * @return {any} metadata - The metadata to store to for the operation
36
+ *
37
+ * @example
38
+ * class User extends Model {
39
+ *
40
+ * // Get metatada for 'User' for key updatedOn, for operation on.create
41
+ * const metadata = Metadata.readOperation(User.constructor,'updatedOn','on.create');
42
+ */
43
+ function readOperation<M extends Model>(model: Constructor<M>, propertyKey?: keyof M, operation?: string): any;
44
+ /**
45
+ * @description Checks if a model is marked as transient
46
+ * @summary Determines whether a model class has been decorated with the transient decorator
47
+ * @template M - Type extending Model
48
+ * @param {M | Constructor<M>} model - The model instance to check
49
+ * @return {boolean} True if the model is transient, false otherwise
50
+ * @function isTransient
51
+ */
52
+ function isTransient<M extends Model>(model: M | Constructor<M>): boolean;
53
+ }
54
+ }