@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,62 @@
1
+ import { Context } from "./Context.cjs";
2
+ import { ExtendedMetadata, Model } from "@decaf-ts/decorator-validation";
3
+ import { OperationKeys } from "../operations/index.cjs";
4
+ import { Constructor } from "@decaf-ts/decoration";
5
+ import { Logger } from "@decaf-ts/logging";
6
+ import { IRepository } from "../interfaces/index.cjs";
7
+ /**
8
+ * @description Type utility for ensuring model extension.
9
+ * @summary A conditional type that ensures a type extends the Model class.
10
+ * If the type extends Model, it returns the type; otherwise, it returns never.
11
+ * @template M - The type to check, defaults to Model
12
+ * @typedef {M extends Model ? M : never} ModelExtension
13
+ * @memberOf module:db-decorators
14
+ */
15
+ export type ModelExtension<M extends Model = Model> = M extends Model ? M : never;
16
+ export type ContextFlags<LOG extends Logger> = {
17
+ logger: LOG;
18
+ timestamp: Date;
19
+ };
20
+ /**
21
+ * @description Configuration flags for repository operations.
22
+ * @summary Defines the configuration options that control repository behavior during operations.
23
+ * These flags manage context relationships, validation behavior, operation metadata, and error handling.
24
+ * @interface RepositoryFlags
25
+ * @property {Context} [parentContext] - The parent context for hierarchical operations
26
+ * @property {Context[]} [childContexts] - Child contexts spawned from this context
27
+ * @property {any[]} [callArgs] - Arguments passed to the operation
28
+ * @property {string[]} ignoredValidationProperties - Properties to exclude from validation
29
+ * @property affectedTables - Tables or models affected by the operation
30
+ * @property {boolean} writeOperation - Whether the operation modifies data
31
+ * @property {Date} timestamp - When the operation was initiated
32
+ * @property {OperationKeys} [operation] - The type of operation being performed
33
+ * @property {boolean} breakOnHandlerError - Whether to stop processing on handler errors
34
+ * @property {boolean} rebuildWithTransient - Whether to include transient properties when rebuilding models
35
+ * @memberOf module:db-decorators
36
+ */
37
+ export interface RepositoryFlags<LOG extends Logger = Logger> extends ContextFlags<LOG> {
38
+ parentContext?: Context<any>;
39
+ childContexts?: Context<any>[];
40
+ callArgs?: any[];
41
+ ignoredValidationProperties: string[];
42
+ affectedTables: (string | Constructor<ModelExtension>)[] | string | Constructor<ModelExtension>;
43
+ writeOperation: boolean;
44
+ operation?: OperationKeys;
45
+ breakOnHandlerError: boolean;
46
+ rebuildWithTransient: boolean;
47
+ ignoreValidation: boolean;
48
+ ignoreHandlers: boolean | string | RegExp;
49
+ ignoreDevSafeGuards: boolean;
50
+ mergeForUpdate: boolean;
51
+ applyUpdateValidation: boolean;
52
+ correlationId?: string;
53
+ allowGenerationOverride: boolean;
54
+ }
55
+ export type LoggerOfFlags<R extends ContextFlags<any>> = R extends ContextFlags<infer L> ? L : never;
56
+ export type FlagsOfContext<C extends Context<any>> = C extends Context<infer F> ? F : never;
57
+ export type LoggerOfContext<C extends Context<any>> = LoggerOfFlags<FlagsOfContext<C>>;
58
+ export type ContextOfRepository<R extends IRepository<any, any>> = R extends IRepository<any, infer C> ? C : never;
59
+ export type LoggerOfRepository<R extends IRepository<any, any>> = LoggerOfContext<ContextOfRepository<R>>;
60
+ export type FlagsOfRepository<R extends IRepository<any, any>> = R extends IRepository<any, infer C> ? FlagsOfContext<C> : never;
61
+ export type PrimaryKeyType = string | number | bigint;
62
+ export type InferredPrimaryKeyType<M extends Model> = ExtendedMetadata<M>;
@@ -0,0 +1,62 @@
1
+ import { Context } from "./Context.js";
2
+ import { ExtendedMetadata, Model } from "@decaf-ts/decorator-validation";
3
+ import { OperationKeys } from "../operations/index.js";
4
+ import { Constructor } from "@decaf-ts/decoration";
5
+ import { Logger } from "@decaf-ts/logging";
6
+ import { IRepository } from "../interfaces/index.js";
7
+ /**
8
+ * @description Type utility for ensuring model extension.
9
+ * @summary A conditional type that ensures a type extends the Model class.
10
+ * If the type extends Model, it returns the type; otherwise, it returns never.
11
+ * @template M - The type to check, defaults to Model
12
+ * @typedef {M extends Model ? M : never} ModelExtension
13
+ * @memberOf module:db-decorators
14
+ */
15
+ export type ModelExtension<M extends Model = Model> = M extends Model ? M : never;
16
+ export type ContextFlags<LOG extends Logger> = {
17
+ logger: LOG;
18
+ timestamp: Date;
19
+ };
20
+ /**
21
+ * @description Configuration flags for repository operations.
22
+ * @summary Defines the configuration options that control repository behavior during operations.
23
+ * These flags manage context relationships, validation behavior, operation metadata, and error handling.
24
+ * @interface RepositoryFlags
25
+ * @property {Context} [parentContext] - The parent context for hierarchical operations
26
+ * @property {Context[]} [childContexts] - Child contexts spawned from this context
27
+ * @property {any[]} [callArgs] - Arguments passed to the operation
28
+ * @property {string[]} ignoredValidationProperties - Properties to exclude from validation
29
+ * @property affectedTables - Tables or models affected by the operation
30
+ * @property {boolean} writeOperation - Whether the operation modifies data
31
+ * @property {Date} timestamp - When the operation was initiated
32
+ * @property {OperationKeys} [operation] - The type of operation being performed
33
+ * @property {boolean} breakOnHandlerError - Whether to stop processing on handler errors
34
+ * @property {boolean} rebuildWithTransient - Whether to include transient properties when rebuilding models
35
+ * @memberOf module:db-decorators
36
+ */
37
+ export interface RepositoryFlags<LOG extends Logger = Logger> extends ContextFlags<LOG> {
38
+ parentContext?: Context<any>;
39
+ childContexts?: Context<any>[];
40
+ callArgs?: any[];
41
+ ignoredValidationProperties: string[];
42
+ affectedTables: (string | Constructor<ModelExtension>)[] | string | Constructor<ModelExtension>;
43
+ writeOperation: boolean;
44
+ operation?: OperationKeys;
45
+ breakOnHandlerError: boolean;
46
+ rebuildWithTransient: boolean;
47
+ ignoreValidation: boolean;
48
+ ignoreHandlers: boolean | string | RegExp;
49
+ ignoreDevSafeGuards: boolean;
50
+ mergeForUpdate: boolean;
51
+ applyUpdateValidation: boolean;
52
+ correlationId?: string;
53
+ allowGenerationOverride: boolean;
54
+ }
55
+ export type LoggerOfFlags<R extends ContextFlags<any>> = R extends ContextFlags<infer L> ? L : never;
56
+ export type FlagsOfContext<C extends Context<any>> = C extends Context<infer F> ? F : never;
57
+ export type LoggerOfContext<C extends Context<any>> = LoggerOfFlags<FlagsOfContext<C>>;
58
+ export type ContextOfRepository<R extends IRepository<any, any>> = R extends IRepository<any, infer C> ? C : never;
59
+ export type LoggerOfRepository<R extends IRepository<any, any>> = LoggerOfContext<ContextOfRepository<R>>;
60
+ export type FlagsOfRepository<R extends IRepository<any, any>> = R extends IRepository<any, infer C> ? FlagsOfContext<C> : never;
61
+ export type PrimaryKeyType = string | number | bigint;
62
+ export type InferredPrimaryKeyType<M extends Model> = ExtendedMetadata<M>;
@@ -0,0 +1,34 @@
1
+ import { IRepository } from "../interfaces/IRepository.cjs";
2
+ import { Model, ModelErrorDefinition } from "@decaf-ts/decorator-validation";
3
+ import { Context } from "./Context.cjs";
4
+ import { ContextOfRepository } from "./types.cjs";
5
+ export type ContextArgs<C extends Context<any>> = {
6
+ context: C;
7
+ args: [...any[], C];
8
+ };
9
+ export declare function reduceErrorsToPrint(errors: (ModelErrorDefinition | undefined)[]): string | undefined;
10
+ /**
11
+ *
12
+ * @param {IRepository<T>} repo
13
+ * @param context
14
+ * @param {T} model
15
+ * @param operation
16
+ * @param prefix
17
+ *
18
+ * @param oldModel
19
+ * @function enforceDBPropertyDecoratorsAsync
20
+ *
21
+ * @memberOf db-decorators.utils
22
+ */
23
+ export declare function enforceDBDecorators<M extends Model<true | false>, R extends IRepository<M, any>, V extends object = object>(repo: R, context: ContextOfRepository<R>, model: M, operation: string, prefix: string, oldModel?: M): Promise<void>;
24
+ /**
25
+ * Specific for DB Decorators
26
+ * @param {T} model
27
+ * @param {string} operation CRUD {@link OperationKeys}
28
+ * @param {string} [extraPrefix]
29
+ *
30
+ * @function getDbPropertyDecorators
31
+ *
32
+ * @memberOf db-decorators.utils
33
+ */
34
+ export declare function getDbDecorators<T extends Model>(model: T, operation: string, extraPrefix?: string): Record<string, DecoratorMetadata[]> | undefined;
@@ -0,0 +1,34 @@
1
+ import { IRepository } from "../interfaces/IRepository.js";
2
+ import { Model, ModelErrorDefinition } from "@decaf-ts/decorator-validation";
3
+ import { Context } from "./Context.js";
4
+ import { ContextOfRepository } from "./types.js";
5
+ export type ContextArgs<C extends Context<any>> = {
6
+ context: C;
7
+ args: [...any[], C];
8
+ };
9
+ export declare function reduceErrorsToPrint(errors: (ModelErrorDefinition | undefined)[]): string | undefined;
10
+ /**
11
+ *
12
+ * @param {IRepository<T>} repo
13
+ * @param context
14
+ * @param {T} model
15
+ * @param operation
16
+ * @param prefix
17
+ *
18
+ * @param oldModel
19
+ * @function enforceDBPropertyDecoratorsAsync
20
+ *
21
+ * @memberOf db-decorators.utils
22
+ */
23
+ export declare function enforceDBDecorators<M extends Model<true | false>, R extends IRepository<M, any>, V extends object = object>(repo: R, context: ContextOfRepository<R>, model: M, operation: string, prefix: string, oldModel?: M): Promise<void>;
24
+ /**
25
+ * Specific for DB Decorators
26
+ * @param {T} model
27
+ * @param {string} operation CRUD {@link OperationKeys}
28
+ * @param {string} [extraPrefix]
29
+ *
30
+ * @function getDbPropertyDecorators
31
+ *
32
+ * @memberOf db-decorators.utils
33
+ */
34
+ export declare function getDbDecorators<T extends Model>(model: T, operation: string, extraPrefix?: string): Record<string, DecoratorMetadata[]> | undefined;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @summary Util method to change a method of an object prefixing it with another
3
+ * @param {any} obj The Base Object
4
+ * @param {Function} after The original method
5
+ * @param {Function} prefix The Prefix method. The output will be used as arguments in the original method
6
+ * @param {string} [afterName] When the after function anme cannot be extracted, pass it here
7
+ *
8
+ * @function prefixMethod
9
+ *
10
+ * @memberOf module:db-decorators
11
+ */
12
+ export declare function prefixMethod(obj: any, after: (...args: any[]) => any, prefix: (...args: any[]) => any, afterName?: string): void;
13
+ /**
14
+ * @summary Util method to change a method of an object suffixing it with another
15
+ * @param {any} obj The Base Object
16
+ * @param {Function} before The original method
17
+ * @param {Function} suffix The Prefix method. The output will be used as arguments in the original method
18
+ * @param {string} [beforeName] When the after function anme cannot be extracted, pass it here
19
+ *
20
+ * @function suffixMethod
21
+ *
22
+ * @memberOf module:db-decorators.Repository
23
+ */
24
+ export declare function suffixMethod(obj: any, before: (...args: any[]) => any, suffix: (...args: any[]) => any, beforeName?: string): void;
25
+ /**
26
+ * @summary Util method to wrap a method of an object with additional logic
27
+ *
28
+ * @param {any} obj The Base Object
29
+ * @param {Function} before the method to be prefixed
30
+ * @param {Function} method the method to be wrapped
31
+ * @param {Function} after The method to be suffixed
32
+ * @param {string} [methodName] When the after function anme cannot be extracted, pass it here
33
+ *
34
+ * @function wrapMethodWithContext
35
+ *
36
+ * @memberOf module:db-decorators
37
+ */
38
+ export declare function wrapMethodWithContext(obj: any, before: (...args: any[]) => any, method: (...args: any[]) => any, after: (...args: any[]) => any, methodName?: string): void;
39
+ export declare function wrapMethodWithContextForUpdate(obj: any, before: (...args: any[]) => any, method: (...args: any[]) => any, after: (...args: any[]) => any, methodName?: string): void;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @summary Util method to change a method of an object prefixing it with another
3
+ * @param {any} obj The Base Object
4
+ * @param {Function} after The original method
5
+ * @param {Function} prefix The Prefix method. The output will be used as arguments in the original method
6
+ * @param {string} [afterName] When the after function anme cannot be extracted, pass it here
7
+ *
8
+ * @function prefixMethod
9
+ *
10
+ * @memberOf module:db-decorators
11
+ */
12
+ export declare function prefixMethod(obj: any, after: (...args: any[]) => any, prefix: (...args: any[]) => any, afterName?: string): void;
13
+ /**
14
+ * @summary Util method to change a method of an object suffixing it with another
15
+ * @param {any} obj The Base Object
16
+ * @param {Function} before The original method
17
+ * @param {Function} suffix The Prefix method. The output will be used as arguments in the original method
18
+ * @param {string} [beforeName] When the after function anme cannot be extracted, pass it here
19
+ *
20
+ * @function suffixMethod
21
+ *
22
+ * @memberOf module:db-decorators.Repository
23
+ */
24
+ export declare function suffixMethod(obj: any, before: (...args: any[]) => any, suffix: (...args: any[]) => any, beforeName?: string): void;
25
+ /**
26
+ * @summary Util method to wrap a method of an object with additional logic
27
+ *
28
+ * @param {any} obj The Base Object
29
+ * @param {Function} before the method to be prefixed
30
+ * @param {Function} method the method to be wrapped
31
+ * @param {Function} after The method to be suffixed
32
+ * @param {string} [methodName] When the after function anme cannot be extracted, pass it here
33
+ *
34
+ * @function wrapMethodWithContext
35
+ *
36
+ * @memberOf module:db-decorators
37
+ */
38
+ export declare function wrapMethodWithContext(obj: any, before: (...args: any[]) => any, method: (...args: any[]) => any, after: (...args: any[]) => any, methodName?: string): void;
39
+ export declare function wrapMethodWithContextForUpdate(obj: any, before: (...args: any[]) => any, method: (...args: any[]) => any, after: (...args: any[]) => any, methodName?: string): void;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @description Collection of default error messages used by validators.
3
+ * @summary Holds the default error messages for various validation scenarios including ID validation, readonly properties, and timestamps.
4
+ * @typedef {Object} ErrorMessages
5
+ * @property {Object} ID - Error messages for ID validation
6
+ * @property {string} ID.INVALID - Error message when an ID is invalid
7
+ * @property {string} ID.REQUIRED - Error message when an ID is missing
8
+ * @property {Object} READONLY - Error messages for readonly properties
9
+ * @property {string} READONLY.INVALID - Error message when attempting to update a readonly property
10
+ * @property {Object} TIMESTAMP - Error messages for timestamp validation
11
+ * @property {string} TIMESTAMP.REQUIRED - Error message when a timestamp is missing
12
+ * @property {string} TIMESTAMP.DATE - Error message when a timestamp is not a valid date
13
+ * @property {string} TIMESTAMP.INVALID - Error message when a timestamp is not increasing
14
+ * @const DEFAULT_ERROR_MESSAGES
15
+ * @memberOf module:validation
16
+ */
17
+ export declare const DEFAULT_ERROR_MESSAGES: {
18
+ ID: {
19
+ INVALID: string;
20
+ REQUIRED: string;
21
+ };
22
+ READONLY: {
23
+ INVALID: string;
24
+ };
25
+ TIMESTAMP: {
26
+ REQUIRED: string;
27
+ DATE: string;
28
+ INVALID: string;
29
+ };
30
+ };
31
+ /**
32
+ * @description Constants used for reflection-based validation during update operations.
33
+ * @summary Keys used for storing and retrieving validation metadata on model properties during update operations.
34
+ * @typedef {Object} ValidationKeys
35
+ * @property {string} REFLECT - Base reflection key prefix for update validation
36
+ * @property {string} TIMESTAMP - Key for timestamp validation
37
+ * @property {string} READONLY - Key for readonly property validation
38
+ * @const UpdateValidationKeys
39
+ * @memberOf module:validation
40
+ */
41
+ export declare const UpdateValidationKeys: {
42
+ REFLECT: string;
43
+ TIMESTAMP: string;
44
+ READONLY: string;
45
+ };
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @description Collection of default error messages used by validators.
3
+ * @summary Holds the default error messages for various validation scenarios including ID validation, readonly properties, and timestamps.
4
+ * @typedef {Object} ErrorMessages
5
+ * @property {Object} ID - Error messages for ID validation
6
+ * @property {string} ID.INVALID - Error message when an ID is invalid
7
+ * @property {string} ID.REQUIRED - Error message when an ID is missing
8
+ * @property {Object} READONLY - Error messages for readonly properties
9
+ * @property {string} READONLY.INVALID - Error message when attempting to update a readonly property
10
+ * @property {Object} TIMESTAMP - Error messages for timestamp validation
11
+ * @property {string} TIMESTAMP.REQUIRED - Error message when a timestamp is missing
12
+ * @property {string} TIMESTAMP.DATE - Error message when a timestamp is not a valid date
13
+ * @property {string} TIMESTAMP.INVALID - Error message when a timestamp is not increasing
14
+ * @const DEFAULT_ERROR_MESSAGES
15
+ * @memberOf module:validation
16
+ */
17
+ export declare const DEFAULT_ERROR_MESSAGES: {
18
+ ID: {
19
+ INVALID: string;
20
+ REQUIRED: string;
21
+ };
22
+ READONLY: {
23
+ INVALID: string;
24
+ };
25
+ TIMESTAMP: {
26
+ REQUIRED: string;
27
+ DATE: string;
28
+ INVALID: string;
29
+ };
30
+ };
31
+ /**
32
+ * @description Constants used for reflection-based validation during update operations.
33
+ * @summary Keys used for storing and retrieving validation metadata on model properties during update operations.
34
+ * @typedef {Object} ValidationKeys
35
+ * @property {string} REFLECT - Base reflection key prefix for update validation
36
+ * @property {string} TIMESTAMP - Key for timestamp validation
37
+ * @property {string} READONLY - Key for readonly property validation
38
+ * @const UpdateValidationKeys
39
+ * @memberOf module:validation
40
+ */
41
+ export declare const UpdateValidationKeys: {
42
+ REFLECT: string;
43
+ TIMESTAMP: string;
44
+ READONLY: string;
45
+ };
@@ -0,0 +1,143 @@
1
+ import "./validation";
2
+ import { Model, Serializer } from "@decaf-ts/decorator-validation";
3
+ import { OperationKeys } from "../operations/constants.cjs";
4
+ import { IRepository } from "../interfaces/IRepository.cjs";
5
+ import { Constructor } from "@decaf-ts/decoration";
6
+ import { ContextOfRepository } from "../repository/index.cjs";
7
+ /**
8
+ * @description Prevents a property from being modified after initial creation.
9
+ * @summary Marks the property as readonly, causing validation errors if attempts are made to modify it during updates.
10
+ * @param {string} [message] - The error message to display when validation fails. Defaults to {@link DEFAULT_ERROR_MESSAGES.READONLY.INVALID}
11
+ * @return {PropertyDecorator} A decorator function that can be applied to class properties
12
+ * @function readonly
13
+ * @category Property Decorators
14
+ */
15
+ export declare function readonly(message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
16
+ /**
17
+ * @description Handler function that sets a timestamp property to the current timestamp.
18
+ * @summary Updates a model property with the current timestamp from the repository context.
19
+ * @template M - The model type extending Model
20
+ * @template R - The repository type extending IRepository
21
+ * @template V - The data type for the operation
22
+ * @template F - The repository flags type
23
+ * @template C - The context type
24
+ * @param {C} context - The repository context containing the current timestamp
25
+ * @param {V} data - The data being processed
26
+ * @param key - The property key to update
27
+ * @param {M} model - The model instance being updated
28
+ * @return {Promise<void>} A promise that resolves when the timestamp has been set
29
+ * @function timestampHandler
30
+ */
31
+ export declare function timestampHandler<M extends Model, R extends IRepository<M, any>, V>(this: R, context: ContextOfRepository<R>, data: V, key: keyof M, model: M): Promise<void>;
32
+ /**
33
+ * @description Automatically manages timestamp properties for tracking creation and update times.
34
+ * @summary Marks the property as a timestamp, making it required and ensuring it's a valid date. The property will be automatically updated with the current timestamp during specified operations.
35
+ *
36
+ * Date Format:
37
+ *
38
+ * <pre>
39
+ * Using similar formatting as Moment.js, Class DateTimeFormatter (Java), and Class SimpleDateFormat (Java),
40
+ * I implemented a comprehensive solution formatDate(date, patternStr) where the code is easy to read and modify.
41
+ * You can display date, time, AM/PM, etc.
42
+ *
43
+ * Date and Time Patterns
44
+ * yy = 2-digit year; yyyy = full year
45
+ * M = digit month; MM = 2-digit month; MMM = short month name; MMMM = full month name
46
+ * EEEE = full weekday name; EEE = short weekday name
47
+ * d = digit day; dd = 2-digit day
48
+ * h = hours am/pm; hh = 2-digit hours am/pm; H = hours; HH = 2-digit hours
49
+ * m = minutes; mm = 2-digit minutes; aaa = AM/PM
50
+ * s = seconds; ss = 2-digit seconds
51
+ * S = miliseconds
52
+ * </pre>
53
+ *
54
+ * @param {OperationKeys[]} operation - The operations to act on. Defaults to {@link DBOperations.CREATE_UPDATE}
55
+ * @param {string} [format] - The timestamp format. Defaults to {@link DEFAULT_TIMESTAMP_FORMAT}
56
+ * @return {PropertyDecorator} A decorator function that can be applied to class properties
57
+ * @function timestamp
58
+ * @category Property Decorators
59
+ * @mermaid
60
+ * sequenceDiagram
61
+ * participant C as Client
62
+ * participant M as Model
63
+ * participant T as TimestampDecorator
64
+ * participant V as Validator
65
+ *
66
+ * C->>M: Create/Update model
67
+ * M->>T: Process timestamp property
68
+ * T->>M: Apply required validation
69
+ * T->>M: Apply date format validation
70
+ *
71
+ * alt Update operation
72
+ * T->>V: Register timestamp validator
73
+ * V->>M: Validate timestamp is newer
74
+ * end
75
+ *
76
+ * T->>M: Set current timestamp
77
+ * M->>C: Return updated model
78
+ */
79
+ export declare function timestamp(operation?: OperationKeys[], format?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
80
+ /**
81
+ * @description Handler function that serializes a property to JSON string during create and update operations.
82
+ * @summary Converts a complex object property to a JSON string before storing it in the database.
83
+ * @template M - The model type extending Model
84
+ * @template R - The repository type extending IRepository
85
+ * @template V - The data type for the operation
86
+ * @template F - The repository flags type
87
+ * @template C - The context type
88
+ * @param {C} context - The repository context
89
+ * @param {V} data - The data being processed
90
+ * @param key - The property key to serialize
91
+ * @param {M} model - The model instance being processed
92
+ * @return {Promise<void>} A promise that resolves when the property has been serialized
93
+ * @function serializeOnCreateUpdate
94
+ */
95
+ export declare function serializeOnCreateUpdate<M extends Model, R extends IRepository<M, any>>(this: R, context: ContextOfRepository<R>, data: {
96
+ serializer?: Constructor<Serializer<M>>;
97
+ }, key: keyof M, model: M): Promise<void>;
98
+ /**
99
+ * @description Handler function that deserializes a property from JSON string after database operations.
100
+ * @summary Converts a JSON string property back to its original complex object form after retrieving it from the database.
101
+ * @template M - The model type extending Model
102
+ * @template R - The repository type extending IRepository
103
+ * @template V - The data type for the operation
104
+ * @template F - The repository flags type
105
+ * @template C - The context type
106
+ * @param {C} context - The repository context
107
+ * @param {V} data - The data being processed
108
+ * @param key - The property key to deserialize
109
+ * @param {M} model - The model instance being processed
110
+ * @return {Promise<void>} A promise that resolves when the property has been deserialized
111
+ * @function serializeAfterAll
112
+ */
113
+ export declare function serializeAfterAll<M extends Model, R extends IRepository<M, any>>(this: R, context: ContextOfRepository<R>, data: {
114
+ serializer?: Constructor<Serializer<M>>;
115
+ }, key: keyof M, model: M): Promise<void>;
116
+ /**
117
+ * @description Enables automatic JSON serialization and deserialization for complex object properties.
118
+ * @summary Decorator that automatically converts complex objects to JSON strings before storing in the database and back to objects when retrieving them.
119
+ * @return {PropertyDecorator} A decorator function that can be applied to class properties
120
+ * @function serialize
121
+ * @category Property Decorators
122
+ * @mermaid
123
+ * sequenceDiagram
124
+ * participant C as Client
125
+ * participant M as Model
126
+ * participant S as SerializeDecorator
127
+ * participant DB as Database
128
+ *
129
+ * Note over C,DB: Create/Update Flow
130
+ * C->>M: Set complex object property
131
+ * M->>S: Process property (create/update)
132
+ * S->>M: Convert to JSON string
133
+ * M->>DB: Store serialized data
134
+ *
135
+ * Note over C,DB: Retrieval Flow
136
+ * C->>M: Request model
137
+ * M->>DB: Fetch data
138
+ * DB->>M: Return with serialized property
139
+ * M->>S: Process property (after all ops)
140
+ * S->>M: Parse JSON back to object
141
+ * M->>C: Return model with deserialized property
142
+ */
143
+ export declare function serialize(serializer?: Constructor<Serializer<any>>): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor | number) => void;
@@ -0,0 +1,143 @@
1
+ import "./validation";
2
+ import { Model, Serializer } from "@decaf-ts/decorator-validation";
3
+ import { OperationKeys } from "../operations/constants.js";
4
+ import { IRepository } from "../interfaces/IRepository.js";
5
+ import { Constructor } from "@decaf-ts/decoration";
6
+ import { ContextOfRepository } from "../repository/index.js";
7
+ /**
8
+ * @description Prevents a property from being modified after initial creation.
9
+ * @summary Marks the property as readonly, causing validation errors if attempts are made to modify it during updates.
10
+ * @param {string} [message] - The error message to display when validation fails. Defaults to {@link DEFAULT_ERROR_MESSAGES.READONLY.INVALID}
11
+ * @return {PropertyDecorator} A decorator function that can be applied to class properties
12
+ * @function readonly
13
+ * @category Property Decorators
14
+ */
15
+ export declare function readonly(message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
16
+ /**
17
+ * @description Handler function that sets a timestamp property to the current timestamp.
18
+ * @summary Updates a model property with the current timestamp from the repository context.
19
+ * @template M - The model type extending Model
20
+ * @template R - The repository type extending IRepository
21
+ * @template V - The data type for the operation
22
+ * @template F - The repository flags type
23
+ * @template C - The context type
24
+ * @param {C} context - The repository context containing the current timestamp
25
+ * @param {V} data - The data being processed
26
+ * @param key - The property key to update
27
+ * @param {M} model - The model instance being updated
28
+ * @return {Promise<void>} A promise that resolves when the timestamp has been set
29
+ * @function timestampHandler
30
+ */
31
+ export declare function timestampHandler<M extends Model, R extends IRepository<M, any>, V>(this: R, context: ContextOfRepository<R>, data: V, key: keyof M, model: M): Promise<void>;
32
+ /**
33
+ * @description Automatically manages timestamp properties for tracking creation and update times.
34
+ * @summary Marks the property as a timestamp, making it required and ensuring it's a valid date. The property will be automatically updated with the current timestamp during specified operations.
35
+ *
36
+ * Date Format:
37
+ *
38
+ * <pre>
39
+ * Using similar formatting as Moment.js, Class DateTimeFormatter (Java), and Class SimpleDateFormat (Java),
40
+ * I implemented a comprehensive solution formatDate(date, patternStr) where the code is easy to read and modify.
41
+ * You can display date, time, AM/PM, etc.
42
+ *
43
+ * Date and Time Patterns
44
+ * yy = 2-digit year; yyyy = full year
45
+ * M = digit month; MM = 2-digit month; MMM = short month name; MMMM = full month name
46
+ * EEEE = full weekday name; EEE = short weekday name
47
+ * d = digit day; dd = 2-digit day
48
+ * h = hours am/pm; hh = 2-digit hours am/pm; H = hours; HH = 2-digit hours
49
+ * m = minutes; mm = 2-digit minutes; aaa = AM/PM
50
+ * s = seconds; ss = 2-digit seconds
51
+ * S = miliseconds
52
+ * </pre>
53
+ *
54
+ * @param {OperationKeys[]} operation - The operations to act on. Defaults to {@link DBOperations.CREATE_UPDATE}
55
+ * @param {string} [format] - The timestamp format. Defaults to {@link DEFAULT_TIMESTAMP_FORMAT}
56
+ * @return {PropertyDecorator} A decorator function that can be applied to class properties
57
+ * @function timestamp
58
+ * @category Property Decorators
59
+ * @mermaid
60
+ * sequenceDiagram
61
+ * participant C as Client
62
+ * participant M as Model
63
+ * participant T as TimestampDecorator
64
+ * participant V as Validator
65
+ *
66
+ * C->>M: Create/Update model
67
+ * M->>T: Process timestamp property
68
+ * T->>M: Apply required validation
69
+ * T->>M: Apply date format validation
70
+ *
71
+ * alt Update operation
72
+ * T->>V: Register timestamp validator
73
+ * V->>M: Validate timestamp is newer
74
+ * end
75
+ *
76
+ * T->>M: Set current timestamp
77
+ * M->>C: Return updated model
78
+ */
79
+ export declare function timestamp(operation?: OperationKeys[], format?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
80
+ /**
81
+ * @description Handler function that serializes a property to JSON string during create and update operations.
82
+ * @summary Converts a complex object property to a JSON string before storing it in the database.
83
+ * @template M - The model type extending Model
84
+ * @template R - The repository type extending IRepository
85
+ * @template V - The data type for the operation
86
+ * @template F - The repository flags type
87
+ * @template C - The context type
88
+ * @param {C} context - The repository context
89
+ * @param {V} data - The data being processed
90
+ * @param key - The property key to serialize
91
+ * @param {M} model - The model instance being processed
92
+ * @return {Promise<void>} A promise that resolves when the property has been serialized
93
+ * @function serializeOnCreateUpdate
94
+ */
95
+ export declare function serializeOnCreateUpdate<M extends Model, R extends IRepository<M, any>>(this: R, context: ContextOfRepository<R>, data: {
96
+ serializer?: Constructor<Serializer<M>>;
97
+ }, key: keyof M, model: M): Promise<void>;
98
+ /**
99
+ * @description Handler function that deserializes a property from JSON string after database operations.
100
+ * @summary Converts a JSON string property back to its original complex object form after retrieving it from the database.
101
+ * @template M - The model type extending Model
102
+ * @template R - The repository type extending IRepository
103
+ * @template V - The data type for the operation
104
+ * @template F - The repository flags type
105
+ * @template C - The context type
106
+ * @param {C} context - The repository context
107
+ * @param {V} data - The data being processed
108
+ * @param key - The property key to deserialize
109
+ * @param {M} model - The model instance being processed
110
+ * @return {Promise<void>} A promise that resolves when the property has been deserialized
111
+ * @function serializeAfterAll
112
+ */
113
+ export declare function serializeAfterAll<M extends Model, R extends IRepository<M, any>>(this: R, context: ContextOfRepository<R>, data: {
114
+ serializer?: Constructor<Serializer<M>>;
115
+ }, key: keyof M, model: M): Promise<void>;
116
+ /**
117
+ * @description Enables automatic JSON serialization and deserialization for complex object properties.
118
+ * @summary Decorator that automatically converts complex objects to JSON strings before storing in the database and back to objects when retrieving them.
119
+ * @return {PropertyDecorator} A decorator function that can be applied to class properties
120
+ * @function serialize
121
+ * @category Property Decorators
122
+ * @mermaid
123
+ * sequenceDiagram
124
+ * participant C as Client
125
+ * participant M as Model
126
+ * participant S as SerializeDecorator
127
+ * participant DB as Database
128
+ *
129
+ * Note over C,DB: Create/Update Flow
130
+ * C->>M: Set complex object property
131
+ * M->>S: Process property (create/update)
132
+ * S->>M: Convert to JSON string
133
+ * M->>DB: Store serialized data
134
+ *
135
+ * Note over C,DB: Retrieval Flow
136
+ * C->>M: Request model
137
+ * M->>DB: Fetch data
138
+ * DB->>M: Return with serialized property
139
+ * M->>S: Process property (after all ops)
140
+ * S->>M: Parse JSON back to object
141
+ * M->>C: Return model with deserialized property
142
+ */
143
+ export declare function serialize(serializer?: Constructor<Serializer<any>>): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor | number) => void;
@@ -0,0 +1,4 @@
1
+ export * from "./validators/index.cjs";
2
+ export * from "./constants.cjs";
3
+ export * from "./decorators.cjs";
4
+ export * from "./validation.cjs";
@@ -0,0 +1,4 @@
1
+ export * from "./validators/index.js";
2
+ export * from "./constants.js";
3
+ export * from "./decorators.js";
4
+ export * from "./validation.js";