@decaf-ts/db-decorators 0.4.31 → 0.4.33

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 (153) hide show
  1. package/LICENSE.md +0 -0
  2. package/README.md +32 -108
  3. package/dist/db-decorators.js +2 -0
  4. package/dist/{db-decorators.bundle.min.js.LICENSE.txt → db-decorators.js.LICENSE.txt} +0 -0
  5. package/dist/esm/db-decorators.js +2 -0
  6. package/dist/esm/{db-decorators.bundle.min.esm.js.LICENSE.txt → db-decorators.js.LICENSE.txt} +0 -0
  7. package/{lib/esm → dist/types}/identity/decorators.d.ts +0 -0
  8. package/{lib/esm → dist/types}/identity/index.d.ts +0 -0
  9. package/{lib/esm → dist/types}/identity/utils.d.ts +0 -0
  10. package/{lib/esm → dist/types}/index.d.ts +0 -0
  11. package/{lib/esm → dist/types}/interfaces/BulkCrudOperator.d.ts +0 -0
  12. package/{lib/esm → dist/types}/interfaces/Contextual.d.ts +0 -0
  13. package/{lib/esm → dist/types}/interfaces/CrudOperator.d.ts +0 -0
  14. package/{lib/esm → dist/types}/interfaces/IRepository.d.ts +0 -0
  15. package/{lib/esm → dist/types}/interfaces/index.d.ts +0 -0
  16. package/{lib/esm → dist/types}/model/constants.d.ts +0 -0
  17. package/{lib/esm → dist/types}/model/decorators.d.ts +0 -0
  18. package/{lib/esm → dist/types}/model/index.d.ts +0 -0
  19. package/{lib/esm → dist/types}/model/model.d.ts +0 -0
  20. package/{lib/esm → dist/types}/model/validation.d.ts +0 -0
  21. package/{lib/esm → dist/types}/operations/Operations.d.ts +0 -0
  22. package/{lib/esm → dist/types}/operations/OperationsRegistry.d.ts +0 -0
  23. package/{lib/esm → dist/types}/operations/constants.d.ts +0 -0
  24. package/{lib/esm → dist/types}/operations/decorators.d.ts +0 -0
  25. package/{lib/esm → dist/types}/operations/index.d.ts +0 -0
  26. package/{lib/esm → dist/types}/operations/types.d.ts +0 -0
  27. package/{lib/esm → dist/types}/repository/BaseRepository.d.ts +0 -0
  28. package/{lib/esm → dist/types}/repository/Context.d.ts +0 -0
  29. package/{lib/esm → dist/types}/repository/DataCache.d.ts +0 -0
  30. package/{lib/esm → dist/types}/repository/Repository.d.ts +0 -0
  31. package/{lib/esm → dist/types}/repository/errors.d.ts +0 -0
  32. package/{lib/esm → dist/types}/repository/index.d.ts +0 -0
  33. package/{lib/esm → dist/types}/repository/utils.d.ts +0 -0
  34. package/{lib/esm → dist/types}/repository/wrappers.d.ts +0 -0
  35. package/{lib/esm → dist/types}/validation/constants.d.ts +0 -0
  36. package/{lib/esm → dist/types}/validation/decorators.d.ts +0 -0
  37. package/{lib/esm → dist/types}/validation/index.d.ts +0 -0
  38. package/{lib/esm → dist/types}/validation/validation.d.ts +1 -1
  39. package/{lib/esm → dist/types}/validation/validators/ReadOnlyValidator.d.ts +0 -0
  40. package/{lib/esm → dist/types}/validation/validators/TimestampValidator.d.ts +0 -0
  41. package/{lib/esm → dist/types}/validation/validators/UpdateValidator.d.ts +0 -0
  42. package/{lib/esm → dist/types}/validation/validators/index.d.ts +0 -0
  43. package/lib/esm/identity/decorators.js +0 -0
  44. package/lib/esm/identity/index.js +0 -0
  45. package/lib/esm/identity/utils.js +0 -0
  46. package/lib/esm/index.js +0 -0
  47. package/lib/esm/interfaces/BulkCrudOperator.js +0 -0
  48. package/lib/esm/interfaces/Contextual.js +0 -0
  49. package/lib/esm/interfaces/CrudOperator.js +0 -0
  50. package/lib/esm/interfaces/IRepository.js +0 -0
  51. package/lib/esm/interfaces/index.js +0 -0
  52. package/lib/esm/model/constants.js +0 -0
  53. package/lib/esm/model/decorators.js +0 -0
  54. package/lib/esm/model/index.js +0 -0
  55. package/lib/esm/model/model.js +0 -0
  56. package/lib/esm/model/validation.js +0 -0
  57. package/lib/esm/operations/Operations.js +0 -0
  58. package/lib/esm/operations/OperationsRegistry.js +0 -0
  59. package/lib/esm/operations/constants.js +0 -0
  60. package/lib/esm/operations/decorators.js +0 -0
  61. package/lib/esm/operations/index.js +0 -0
  62. package/lib/esm/operations/types.js +0 -0
  63. package/lib/esm/repository/BaseRepository.js +0 -0
  64. package/lib/esm/repository/Context.js +0 -0
  65. package/lib/esm/repository/DataCache.js +0 -0
  66. package/lib/esm/repository/Repository.js +0 -0
  67. package/lib/esm/repository/errors.js +0 -0
  68. package/lib/esm/repository/index.js +0 -0
  69. package/lib/esm/repository/utils.js +0 -0
  70. package/lib/esm/repository/wrappers.js +0 -0
  71. package/lib/esm/validation/constants.js +0 -0
  72. package/lib/esm/validation/decorators.js +0 -0
  73. package/lib/esm/validation/index.js +0 -0
  74. package/lib/esm/validation/validation.js +1 -1
  75. package/lib/esm/validation/validators/ReadOnlyValidator.js +0 -0
  76. package/lib/esm/validation/validators/TimestampValidator.js +0 -0
  77. package/lib/esm/validation/validators/UpdateValidator.js +0 -0
  78. package/lib/esm/validation/validators/index.js +0 -0
  79. package/lib/identity/decorators.cjs +2 -0
  80. package/lib/identity/index.cjs +2 -0
  81. package/lib/identity/utils.cjs +2 -0
  82. package/lib/index.cjs +2 -0
  83. package/lib/interfaces/BulkCrudOperator.cjs +2 -0
  84. package/lib/interfaces/Contextual.cjs +2 -0
  85. package/lib/interfaces/CrudOperator.cjs +2 -0
  86. package/lib/interfaces/IRepository.cjs +2 -0
  87. package/lib/interfaces/index.cjs +2 -0
  88. package/lib/model/constants.cjs +2 -0
  89. package/lib/model/decorators.cjs +2 -0
  90. package/lib/model/index.cjs +2 -0
  91. package/lib/model/model.cjs +2 -0
  92. package/lib/model/validation.cjs +2 -0
  93. package/lib/operations/Operations.cjs +2 -0
  94. package/lib/operations/OperationsRegistry.cjs +2 -0
  95. package/lib/operations/constants.cjs +2 -0
  96. package/lib/operations/decorators.cjs +2 -0
  97. package/lib/operations/index.cjs +2 -0
  98. package/lib/operations/types.cjs +2 -0
  99. package/lib/repository/BaseRepository.cjs +2 -0
  100. package/lib/repository/Context.cjs +2 -0
  101. package/lib/repository/DataCache.cjs +2 -0
  102. package/lib/repository/Repository.cjs +2 -0
  103. package/lib/repository/errors.cjs +2 -0
  104. package/lib/repository/index.cjs +2 -0
  105. package/lib/repository/utils.cjs +2 -0
  106. package/lib/repository/wrappers.cjs +2 -0
  107. package/lib/validation/constants.cjs +2 -0
  108. package/lib/validation/decorators.cjs +2 -0
  109. package/lib/validation/index.cjs +2 -0
  110. package/lib/validation/validation.cjs +2 -0
  111. package/lib/validation/validators/ReadOnlyValidator.cjs +2 -0
  112. package/lib/validation/validators/TimestampValidator.cjs +2 -0
  113. package/lib/validation/validators/UpdateValidator.cjs +2 -0
  114. package/lib/validation/validators/index.cjs +2 -0
  115. package/package.json +27 -16
  116. package/dist/db-decorators.bundle.min.js +0 -2
  117. package/dist/esm/db-decorators.bundle.min.esm.js +0 -2
  118. package/lib/identity/decorators.d.ts +0 -1
  119. package/lib/identity/index.d.ts +0 -2
  120. package/lib/identity/utils.d.ts +0 -34
  121. package/lib/index.d.ts +0 -33
  122. package/lib/interfaces/BulkCrudOperator.d.ts +0 -7
  123. package/lib/interfaces/Contextual.d.ts +0 -6
  124. package/lib/interfaces/CrudOperator.d.ts +0 -42
  125. package/lib/interfaces/IRepository.d.ts +0 -11
  126. package/lib/interfaces/index.d.ts +0 -4
  127. package/lib/model/constants.d.ts +0 -37
  128. package/lib/model/decorators.d.ts +0 -50
  129. package/lib/model/index.d.ts +0 -4
  130. package/lib/model/model.d.ts +0 -112
  131. package/lib/model/validation.d.ts +0 -14
  132. package/lib/operations/Operations.d.ts +0 -19
  133. package/lib/operations/OperationsRegistry.d.ts +0 -34
  134. package/lib/operations/constants.d.ts +0 -24
  135. package/lib/operations/decorators.d.ts +0 -193
  136. package/lib/operations/index.d.ts +0 -5
  137. package/lib/operations/types.d.ts +0 -29
  138. package/lib/repository/BaseRepository.d.ts +0 -36
  139. package/lib/repository/Context.d.ts +0 -17
  140. package/lib/repository/DataCache.d.ts +0 -9
  141. package/lib/repository/Repository.d.ts +0 -10
  142. package/lib/repository/errors.d.ts +0 -69
  143. package/lib/repository/index.d.ts +0 -7
  144. package/lib/repository/utils.d.ts +0 -62
  145. package/lib/repository/wrappers.d.ts +0 -38
  146. package/lib/validation/constants.d.ts +0 -30
  147. package/lib/validation/decorators.d.ts +0 -58
  148. package/lib/validation/index.d.ts +0 -4
  149. package/lib/validation/validation.d.ts +0 -41
  150. package/lib/validation/validators/ReadOnlyValidator.d.ts +0 -23
  151. package/lib/validation/validators/TimestampValidator.d.ts +0 -14
  152. package/lib/validation/validators/UpdateValidator.d.ts +0 -23
  153. package/lib/validation/validators/index.d.ts +0 -3
package/lib/index.d.ts DELETED
@@ -1,33 +0,0 @@
1
- /**
2
- * @module db-decorators
3
- */
4
- /**
5
- * @namespace Model
6
- * @memberOf module:db-decorators
7
- */
8
- /**
9
- * @namespace Operations
10
- * @memberOf module:db-decorators
11
- */
12
- /**
13
- * @namespace Repository
14
- * @memberOf module:db-decorators
15
- */
16
- /**
17
- * @namespace Validation
18
- * @memberOf module:db-decorators
19
- */
20
- /**
21
- * @namespace Validators
22
- * @memberOf module:db-decorators.Validation
23
- */
24
- /**
25
- * @namespace Utils
26
- * @memberOf module:db-decorators
27
- */
28
- export * from "./identity";
29
- export * from "./interfaces";
30
- export * from "./model";
31
- export * from "./operations";
32
- export * from "./repository";
33
- export * from "./validation";
@@ -1,7 +0,0 @@
1
- import { CrudOperator } from "./CrudOperator";
2
- export interface BulkCrudOperator<M> extends CrudOperator<M> {
3
- createAll(models: M[], ...args: any[]): Promise<M[]>;
4
- readAll(keys: string[] | number[], ...args: any[]): Promise<M[]>;
5
- updateAll(models: M[], ...args: any[]): Promise<M[]>;
6
- deleteAll(keys: string[] | number[], ...args: any[]): Promise<M[]>;
7
- }
@@ -1,6 +0,0 @@
1
- import { OperationKeys } from "../operations";
2
- import { Model } from "@decaf-ts/decorator-validation";
3
- import { Context } from "../repository";
4
- export interface Contextual<M extends Model> {
5
- context<C extends Context<M> = Context<M>>(operation: OperationKeys.CREATE | OperationKeys.READ | OperationKeys.UPDATE | OperationKeys.DELETE, ...args: any[]): Promise<C>;
6
- }
@@ -1,42 +0,0 @@
1
- /**
2
- * @summary Crud API
3
- * @description Exposes a CRUD API
4
- *
5
- * @interface CrudOperator
6
- *
7
- * @category Managers
8
- */
9
- export interface CrudOperator<M> {
10
- /**
11
- * @summary Create a new model
12
- * @param {T} model
13
- * @param {any[]} [args]
14
- *
15
- * @method
16
- */
17
- create(model: M, ...args: any[]): Promise<M>;
18
- /**
19
- * @summary Read a model
20
- * @param {string} key
21
- * @param {any[]} [args]
22
- *
23
- * @method
24
- */
25
- read(key: string | number, ...args: any[]): Promise<M>;
26
- /**
27
- * @summary update a model
28
- * @param {T} model
29
- * @param {any[]} [args]
30
- *
31
- * @method
32
- */
33
- update(model: M, ...args: any[]): Promise<M>;
34
- /**
35
- * @summary delete a model
36
- * @param {string} key
37
- * @param {any[]} [args]
38
- *
39
- * @method
40
- */
41
- delete(key: string | number, ...args: any[]): Promise<M>;
42
- }
@@ -1,11 +0,0 @@
1
- import { Constructor, Model } from "@decaf-ts/decorator-validation";
2
- import { BulkCrudOperator } from "./BulkCrudOperator";
3
- /**
4
- * @summary Interface holding basic CRUD APIs
5
- * @typedef T extends {@link Model}
6
- * @interface IRepository
7
- */
8
- export interface IRepository<M extends Model> extends BulkCrudOperator<M> {
9
- readonly class: Constructor<M>;
10
- readonly pk: string;
11
- }
@@ -1,4 +0,0 @@
1
- export * from "./BulkCrudOperator";
2
- export * from "./Contextual";
3
- export * from "./CrudOperator";
4
- export * from "./IRepository";
@@ -1,37 +0,0 @@
1
- /**
2
- * @summary Holds the Model reflection keys
3
- * @const DBKeys
4
- *
5
- * @memberOf module:db-decorators.Model
6
- */
7
- export declare const DBKeys: {
8
- REFLECT: string;
9
- REPOSITORY: string;
10
- CLASS: string;
11
- ID: string;
12
- INDEX: string;
13
- UNIQUE: string;
14
- SERIALIZE: string;
15
- READONLY: string;
16
- TIMESTAMP: string;
17
- HASH: string;
18
- COMPOSED: string;
19
- VERSION: string;
20
- ORIGINAL: string;
21
- };
22
- /**
23
- * @summary The default separator when concatenating indexes
24
- *
25
- * @const DefaultIndexSeparator
26
- *
27
- * @category Managers
28
- * @subcategory Constants
29
- */
30
- export declare const DefaultSeparator = "_";
31
- /**
32
- * @summary Holds the default timestamp date format
33
- * @constant DEFAULT_TIMESTAMP_FORMAT
34
- *
35
- * @memberOf module:db-decorators.Model
36
- */
37
- export declare const DEFAULT_TIMESTAMP_FORMAT = "dd/MM/yyyy HH:mm:ss:S";
@@ -1,50 +0,0 @@
1
- import { Model } from "@decaf-ts/decorator-validation";
2
- import { IRepository } from "../interfaces/IRepository";
3
- import { Context } from "../repository/Context";
4
- import { CrudOperations } from "../operations";
5
- /**
6
- *
7
- * @param {str} str
8
- * @memberOf db-decorators.model
9
- */
10
- export declare function hashOnCreateUpdate<M extends Model, R extends IRepository<M>, Y = any>(this: R, data: Y, key: string, model: M, oldModel?: M): void;
11
- export declare function hash(): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
12
- export type ComposedFromMetadata = {
13
- args: string[];
14
- separator: string;
15
- hashResult: boolean;
16
- type: "keys" | "values";
17
- prefix?: string;
18
- suffix?: string;
19
- };
20
- export declare function composedFromCreateUpdate<M extends Model, V extends IRepository<M>>(this: V, context: Context<M>, data: ComposedFromMetadata, key: string, model: M): void;
21
- export declare function composedFromKeys(args: string[], separator?: string, hash?: boolean, prefix?: string, suffix?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
22
- export declare function composed(args: string[], separator?: string, hash?: boolean, prefix?: string, suffix?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
23
- /**
24
- * Creates a decorator function that updates the version of a model during create or update operations.
25
- *
26
- * @param {CrudOperations} operation - The type of operation being performed (CREATE or UPDATE).
27
- * @returns {function} A function that updates the version of the model based on the operation type.
28
- *
29
- * @template M - Type extending Model
30
- * @template V - Type extending IRepository<M>
31
- *
32
- * @this {V} - The repository instance
33
- * @param {Context<M>} context - The context of the operation
34
- * @param {unknown} data - Additional data for the operation (not used in this function)
35
- * @param {string} key - The key of the version property in the model
36
- * @param {M} model - The model being updated
37
- * @throws {InternalError} If an invalid operation is provided or if version update fails
38
- */
39
- export declare function versionCreateUpdate(operation: CrudOperations): <M extends Model, V extends IRepository<M>>(this: V, context: Context<M>, data: unknown, key: string, model: M) => void;
40
- /**
41
- * @description Creates a decorator for versioning a property in a model.
42
- * @summary This decorator applies multiple sub-decorators to handle version management during create and update operations.
43
- *
44
- * @returns {Function} A composite decorator that:
45
- * - Sets the type of the property to Number
46
- * - Applies a version update on create operations
47
- * - Applies a version update on update operations
48
- * - Adds metadata indicating this property is used for versioning
49
- */
50
- export declare function version(): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
@@ -1,4 +0,0 @@
1
- export * from "./validation";
2
- export * from "./constants";
3
- export * from "./decorators";
4
- export * from "./model";
@@ -1,112 +0,0 @@
1
- import { Comparable, Hashable, ModelArg, ModelErrorDefinition, Serializable, Validatable, Constructor, ModelBuilderFunction, BuilderRegistry, ModelConstructor } from "@decaf-ts/decorator-validation";
2
- declare module "@decaf-ts/decorator-validation" {
3
- abstract class Model implements Validatable, Serializable, Hashable, Comparable<Model> {
4
- protected constructor(arg?: ModelArg<Model>);
5
- hasErrors(...exclusions: any[]): ModelErrorDefinition | undefined;
6
- hasErrors(previousVersion?: Model | any, ...exclusions: any[]): ModelErrorDefinition | undefined;
7
- /**
8
- * @summary Compare object equality recursively
9
- * @param {any} obj object to compare to
10
- * @param {string} [exceptions] property names to be excluded from the comparison
11
- */
12
- equals(obj: any, ...exceptions: string[]): boolean;
13
- /**
14
- * @summary Returns the serialized model according to the currently defined {@link Serializer}
15
- */
16
- serialize(): string;
17
- /**
18
- * @summary Override the implementation for js's 'toString()' which sucks...
19
- * @override
20
- */
21
- toString(): string;
22
- /**
23
- * @summary Defines a default implementation for object hash. Relies on a very basic implementation based on Java's string hash;
24
- */
25
- hash(): string;
26
- /**
27
- * @summary Deserializes a Model
28
- * @param {string} str
29
- *
30
- * @param args
31
- * @throws {Error} If it fails to parse the string, or if it fails to build the model
32
- */
33
- static deserialize(str: string): any;
34
- /**
35
- * @summary Repopulates the Object properties with the ones from the new object
36
- * @description Iterates all common properties of obj (if existing) and self, and copies them onto self
37
- *
38
- * @param {T} self
39
- * @param {T | Record<string, any>} [obj]
40
- *
41
- */
42
- static fromObject<T extends Model>(self: T, obj?: T | Record<string, any>): T;
43
- /**
44
- * @summary Repopulates the instance with the ones from the new Model Object
45
- * @description Iterates all common properties of obj (if existing) and self, and copies them onto self.
46
- * Is aware of nested Model Objects and rebuilds them also.
47
- * When List properties are decorated with {@link list}, they list items will also be rebuilt
48
- *
49
- * @param {T} self
50
- * @param {T | Record<string, any>} [obj]
51
- *
52
- */
53
- static fromModel<T extends Model>(self: T, obj?: T | Record<string, any>): T;
54
- /**
55
- * @summary Sets the Global {@link ModelBuilderFunction}
56
- * @param {ModelBuilderFunction} [builder]
57
- */
58
- static setBuilder(builder?: ModelBuilderFunction): void;
59
- /**
60
- * @summary Retrieves the current global {@link ModelBuilderFunction}
61
- */
62
- static getBuilder(): ModelBuilderFunction | undefined;
63
- /**
64
- * Returns the current {@link ModelRegistryManager}
65
- *
66
- * @return ModelRegistry, defaults to {@link ModelRegistryManager}
67
- */
68
- private static getRegistry;
69
- /**
70
- * Returns the current actingModelRegistry
71
- *
72
- * @param {BuilderRegistry} modelRegistry the new implementation of Registry
73
- */
74
- static setRegistry(modelRegistry: BuilderRegistry<any>): void;
75
- /**
76
- * @summary register new Models
77
- * @param {any} constructor
78
- * @param {string} [name] when not defined, the name of the constructor will be used
79
- *
80
- * @see ModelRegistry
81
- */
82
- static register<T extends Model>(constructor: ModelConstructor<T>, name?: string): void;
83
- /**
84
- * @summary Gets a registered Model {@link ModelConstructor}
85
- * @param {string} name
86
- *
87
- * @see ModelRegistry
88
- */
89
- static get<T extends Model>(name: string): ModelConstructor<T> | undefined;
90
- /**
91
- * @param {Record<string, any>} obj
92
- * @param {string} [clazz] when provided, it will attempt to find the matching constructor
93
- *
94
- * @throws Error If clazz is not found, or obj is not a {@link Model} meaning it has no {@link ModelKeys.ANCHOR} property
95
- *
96
- * @see ModelRegistry
97
- */
98
- static build<T extends Model>(obj?: Record<string, any>, clazz?: string): T;
99
- static getMetadata<V extends Model>(model: V): any;
100
- static getAttributes<V extends Model>(model: Constructor<V> | V): string[];
101
- static equals<V extends Model>(obj1: V, obj2: V, ...exceptions: any[]): boolean;
102
- static hasErrors<V extends Model>(model: V, ...exceptions: any[]): ModelErrorDefinition | undefined;
103
- static serialize<V extends Model>(model: V): any;
104
- static hash<V extends Model>(model: V): any;
105
- /**
106
- * @summary Builds the key to store as Metadata under Reflections
107
- * @description concatenates {@link ModelKeys#REFLECT} with the provided key
108
- * @param {string} str
109
- */
110
- static key(str: string): string;
111
- }
112
- }
@@ -1,14 +0,0 @@
1
- import { Model, ModelErrorDefinition } from "@decaf-ts/decorator-validation";
2
- /**
3
- * @summary Validates the update of a model
4
- *
5
- * @param {T} oldModel
6
- * @param {T} newModel
7
- * @param {string[]} [exceptions]
8
- *
9
- * @function validateCompare
10
- * @return {ModelErrorDefinition | undefined}
11
- *
12
- * @memberOf module:db-decorators.Model
13
- */
14
- export declare function validateCompare<T extends Model>(oldModel: T, newModel: T, ...exceptions: string[]): ModelErrorDefinition | undefined;
@@ -1,19 +0,0 @@
1
- import { Model } from "@decaf-ts/decorator-validation";
2
- import { OperationHandler } from "./types";
3
- import { OperationKeys } from "./constants";
4
- /**
5
- * @summary Static class holding common Operation Functionality
6
- *
7
- * @class Operations
8
- *
9
- * @category Operations
10
- */
11
- export declare class Operations {
12
- private static registry;
13
- private constructor();
14
- static getHandlerName(handler: OperationHandler<any, any, any>): any;
15
- static key(str: string): string;
16
- static get(targetName: string | Record<string, any>, propKey: string, operation: string): OperationHandler<Model, import("..").IRepository<Model>, unknown>[] | undefined;
17
- private static getOpRegistry;
18
- static register<V extends Model>(handler: OperationHandler<V, any, any>, operation: OperationKeys, target: V, propKey: string | symbol): void;
19
- }
@@ -1,34 +0,0 @@
1
- import { OperationHandler } from "./types";
2
- import { OperationKeys } from "./constants";
3
- import { IRepository } from "../interfaces/IRepository";
4
- import { Model } from "@decaf-ts/decorator-validation";
5
- /**
6
- * @summary Holds the registered operation handlers
7
- *
8
- * @class OperationsRegistry
9
- * @implements IRegistry<OperationHandler<any>>
10
- *
11
- * @see OperationHandler
12
- *
13
- * @category Operations
14
- */
15
- export declare class OperationsRegistry {
16
- private readonly cache;
17
- /**
18
- * @summary retrieves an {@link OperationHandler} if it exists
19
- * @param {string} target
20
- * @param {string} propKey
21
- * @param {string} operation
22
- * @param accum
23
- * @return {OperationHandler | undefined}
24
- */
25
- get<T extends Model, V extends IRepository<T>, Y>(target: string | Record<string, any>, propKey: string, operation: string, accum?: OperationHandler<T, V, Y>[]): OperationHandler<T, V, Y>[] | undefined;
26
- /**
27
- * @summary Registers an {@link OperationHandler}
28
- * @param {OperationHandler} handler
29
- * @param {string} operation
30
- * @param {{}} target
31
- * @param {string | symbol} propKey
32
- */
33
- register<T extends Model, V extends IRepository<T>, Y>(handler: OperationHandler<T, V, Y>, operation: OperationKeys, target: T, propKey: string | symbol): void;
34
- }
@@ -1,24 +0,0 @@
1
- /**
2
- * @summary Set of constants to define db CRUD operations and their equivalent 'on' and 'after' phases
3
- * @const OperationKeys
4
- *
5
- * @memberOf module:db-decorators.Operations
6
- */
7
- export declare enum OperationKeys {
8
- REFLECT = "decaf.model.db.operations.",
9
- CREATE = "create",
10
- READ = "read",
11
- UPDATE = "update",
12
- DELETE = "delete",
13
- ON = "on.",
14
- AFTER = "after."
15
- }
16
- export type CrudOperations = OperationKeys.CREATE | OperationKeys.READ | OperationKeys.UPDATE | OperationKeys.DELETE;
17
- /**
18
- * @summary Maps out groups of CRUD operations for easier mapping of decorators
19
- *
20
- * @constant DBOperations
21
- *
22
- * @memberOf module:db-decorators.Operations
23
- */
24
- export declare const DBOperations: Record<string, CrudOperations[]>;
@@ -1,193 +0,0 @@
1
- import { IdOperationHandler, OperationHandler, StandardOperationHandler, UpdateOperationHandler } from "./types";
2
- import { OperationKeys } from "./constants";
3
- /**
4
- * @summary Defines a behaviour to set on the defined {@link DBOperations.CREATE_UPDATE}
5
- *
6
- * @param {OnOperationHandler<any>} handler The method called upon the operation
7
- * @param data
8
- * @param {any[]} [args] Arguments that will be passed in order to the handler method
9
- *
10
- * @see on
11
- *
12
- * @function onCreateUpdate
13
- *
14
- * @category Decorators
15
- */
16
- export declare function onCreateUpdate<T>(handler: StandardOperationHandler<any, any, T, any> | UpdateOperationHandler<any, any, T, any>, data?: T): (target: object, propertyKey?: any) => void;
17
- /**
18
- * @summary Defines a behaviour to set on the defined {@link DBOperations.UPDATE}
19
- *
20
- * @param {OnOperationHandler<any>} handler The method called upon the operation
21
- * @param data
22
- * @param {any[]} [args] Arguments that will be passed in order to the handler method
23
- *
24
- * @see on
25
- *
26
- * @function onUpdate
27
- *
28
- * @category Decorators
29
- */
30
- export declare function onUpdate<T>(handler: UpdateOperationHandler<any, any, T, any>, data?: T): (target: object, propertyKey?: any) => void;
31
- /**
32
- * @summary Defines a behaviour to set on the defined {@link DBOperations.CREATE}
33
- *
34
- * @param {OnOperationHandler<any>} handler The method called upon the operation
35
- * @param data
36
- *
37
- * @see on
38
- *
39
- * @function onCreate
40
- *
41
- * @category Decorators
42
- */
43
- export declare function onCreate<T>(handler: StandardOperationHandler<any, any, T, any>, data?: T): (target: object, propertyKey?: any) => void;
44
- /**
45
- * @summary Defines a behaviour to set on the defined {@link DBOperations.READ}
46
- *
47
- * @param {OnOperationHandler<any>} handler The method called upon the operation
48
- * @param data
49
- *
50
- * @see on
51
- *
52
- * @function onRead
53
- *
54
- * @category Decorators
55
- */
56
- export declare function onRead<T>(handler: IdOperationHandler<any, any, T, any>, data: T): (target: object, propertyKey?: any) => void;
57
- /**
58
- * @summary Defines a behaviour to set on the defined {@link DBOperations.DELETE}
59
- *
60
- * @param {OnOperationHandler<any>} handler The method called upon the operation
61
- * @param data
62
- *
63
- * @see on
64
- *
65
- * @function onDelete
66
- *
67
- * @category Decorators
68
- */
69
- export declare function onDelete<T>(handler: OperationHandler<any, any, T, any>, data: T): (target: object, propertyKey?: any) => void;
70
- /**
71
- * @summary Defines a behaviour to set on the defined {@link DBOperations.DELETE}
72
- *
73
- * @param {OnOperationHandler<any>} handler The method called upon the operation
74
- * @param data
75
- *
76
- * @see on
77
- *
78
- * @function onAny
79
- *
80
- * @category Decorators
81
- */
82
- export declare function onAny<T>(handler: OperationHandler<any, any, T, any>, data: T): (target: object, propertyKey?: any) => void;
83
- /**
84
- * @summary Defines a behaviour to set on the defined {@link DBOperations}
85
- *
86
- * @param {OperationKeys[] | DBOperations} op One of {@link DBOperations}
87
- * @param {OnOperationHandler<any>} handler The method called upon the operation
88
- * @param data
89
- *
90
- * ex: handler(...args, ...props.map(p => target[p]))
91
- *
92
- * @function on
93
- *
94
- * @category Decorators
95
- */
96
- export declare function on<T>(op: OperationKeys[] | undefined, handler: OperationHandler<any, any, T, any>, data?: T): (target: object, propertyKey?: any) => void;
97
- /**
98
- * @summary Defines a behaviour to set after the defined {@link DBOperations.CREATE_UPDATE}
99
- *
100
- * @param {AfterOperationHandler<any>} handler The method called upon the operation
101
- * @param data
102
- *
103
- * @see after
104
- *
105
- * @function afterCreateUpdate
106
- *
107
- * @category Decorators
108
- */
109
- export declare function afterCreateUpdate<T>(handler: StandardOperationHandler<any, any, T, any> | UpdateOperationHandler<any, any, T, any>, data: T): (target: object, propertyKey?: any) => void;
110
- /**
111
- * @summary Defines a behaviour to set after the defined {@link DBOperations.UPDATE}
112
- *
113
- * @param {AfterOperationHandler<any>} handler The method called upon the operation
114
- * @param data
115
- *
116
- * @see after
117
- *
118
- * @function afterUpdate
119
- *
120
- * @category Decorators
121
- */
122
- export declare function afterUpdate<T>(handler: UpdateOperationHandler<any, any, T, any>, data: T): (target: object, propertyKey?: any) => void;
123
- /**
124
- * @summary Defines a behaviour to set after the defined {@link DBOperations.CREATE}
125
- *
126
- * @param {AfterOperationHandler<any>} handler The method called upon the operation
127
- * @param data
128
- *
129
- * @see after
130
- *
131
- * @function afterCreate
132
- *
133
- * @category Decorators
134
- */
135
- export declare function afterCreate<T>(handler: StandardOperationHandler<any, any, T, any>, data: T): (target: object, propertyKey?: any) => void;
136
- /**
137
- * @summary Defines a behaviour to set after the defined {@link DBOperations.READ}
138
- *
139
- * @param {AfterOperationHandler<any>} handler The method called upon the operation
140
- * @param data
141
- * @param {any[]} [args] Arguments that will be passed in order to the handler method
142
- *
143
- * @see after
144
- *
145
- * @function afterRead
146
- *
147
- * @category Decorators
148
- */
149
- export declare function afterRead<T>(handler: StandardOperationHandler<any, any, T, any>, data?: T): (target: object, propertyKey?: any) => void;
150
- /**
151
- * @summary Defines a behaviour to set after the defined {@link DBOperations.DELETE}
152
- *
153
- * @param {AfterOperationHandler<any>} handler The method called upon the operation
154
- * @param data
155
- * @param {any[]} [args] Arguments that will be passed in order to the handler method
156
- *
157
- * @see after
158
- *
159
- * @function afterDelete
160
- *
161
- * @category Decorators
162
- */
163
- export declare function afterDelete<T>(handler: StandardOperationHandler<any, any, T, any>, data?: T): (target: object, propertyKey?: any) => void;
164
- /**
165
- * @summary Defines a behaviour to set after the defined {@link DBOperations.DELETE}
166
- *
167
- * @param {AfterOperationHandler<any>} handler The method called upon the operation
168
- * @param data
169
- * @param {any[]} [args] Arguments that will be passed in order to the handler method
170
- *
171
- * @see after
172
- *
173
- * @function afterAny
174
- *
175
- * @category Decorators
176
- */
177
- export declare function afterAny<T>(handler: StandardOperationHandler<any, any, T, any>, data?: T): (target: object, propertyKey?: any) => void;
178
- /**
179
- * @summary Defines a behaviour to set on the defined {@link DBOperations}
180
- *
181
- * @param {OperationKeys[] | DBOperations} op One of {@link DBOperations}
182
- * @param {AfterOperationHandler<any>} handler The method called upon the operation
183
- *
184
- * ex: handler(...args, ...props.map(p => target[p]))
185
- *
186
- * @param data
187
- * @param args
188
- * @function after
189
- *
190
- * @category Decorators
191
- */
192
- export declare function after<T>(op: OperationKeys[] | undefined, handler: OperationHandler<any, any, T, any>, data?: T): (target: object, propertyKey?: any) => void;
193
- export declare function operation<T>(baseOp: OperationKeys.ON | OperationKeys.AFTER, operation: OperationKeys[] | undefined, handler: OperationHandler<any, any, T, any>, dataToAdd?: T): (target: object, propertyKey?: any) => void;
@@ -1,5 +0,0 @@
1
- export * from "./constants";
2
- export * from "./decorators";
3
- export * from "./Operations";
4
- export * from "./OperationsRegistry";
5
- export * from "./types";
@@ -1,29 +0,0 @@
1
- import { OperationKeys } from "./constants";
2
- import { IRepository } from "../interfaces/IRepository";
3
- import { Model } from "@decaf-ts/decorator-validation";
4
- import { Context } from "../repository/Context";
5
- export type OperationMetadata<V> = {
6
- operation: OperationKeys;
7
- handler: string;
8
- metadata?: V;
9
- };
10
- /**
11
- * @typedef OperationHandler
12
- * @memberOf db-decorators.operations
13
- */
14
- export type OperationHandler<M extends Model, R extends IRepository<M>, V, C extends Context<M> = Context<M>> = StandardOperationHandler<M, R, V, C> | UpdateOperationHandler<M, R, V, C> | IdOperationHandler<M, R, V, C>;
15
- /**
16
- * @typedef OnOperationHandler
17
- * @memberOf db-decorators.operations
18
- */
19
- export type StandardOperationHandler<M extends Model, R extends IRepository<M>, V, C extends Context<M> = Context<M>> = (this: R, context: C, metadata: V, key: any, model: M) => Promise<void> | void;
20
- /**
21
- * @typedef IdOperationHandler
22
- * @memberOf db-decorators.operations
23
- */
24
- export type IdOperationHandler<M extends Model, R extends IRepository<M>, V, C extends Context<M> = Context<M>> = (this: R, context: C, decorator: V, key: any, id: string) => Promise<void> | void;
25
- /**
26
- * @typedef AfterOperationHandler
27
- * @memberOf db-decorators.operations
28
- */
29
- export type UpdateOperationHandler<M extends Model, R extends IRepository<M>, V, C extends Context<M> = Context<M>> = (this: R, context: C, decorator: V, key: any, model: M, oldModel: M) => Promise<void> | void;