@decaf-ts/db-decorators 0.16.0 → 0.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/db-decorators.cjs +1 -1
- package/dist/db-decorators.cjs.map +1 -1
- package/dist/db-decorators.js +1 -1
- package/dist/db-decorators.js.map +1 -1
- package/lib/cjs/index.cjs +2 -1
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/esm/index.js +2 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/types/identity/index.d.cts +1 -1
- package/lib/types/identity/index.d.mts +1 -1
- package/lib/types/index.d.cts +9 -8
- package/lib/types/index.d.mts +9 -8
- package/lib/types/interfaces/BulkCrudOperator.d.cts +2 -2
- package/lib/types/interfaces/BulkCrudOperator.d.mts +2 -2
- package/lib/types/interfaces/Contextual.d.cts +2 -2
- package/lib/types/interfaces/Contextual.d.mts +2 -2
- package/lib/types/interfaces/CrudOperator.d.cts +1 -1
- package/lib/types/interfaces/CrudOperator.d.mts +1 -1
- package/lib/types/interfaces/IRepository.d.cts +2 -2
- package/lib/types/interfaces/IRepository.d.mts +2 -2
- package/lib/types/interfaces/index.d.cts +4 -4
- package/lib/types/interfaces/index.d.mts +4 -4
- package/lib/types/model/decorators.d.cts +3 -3
- package/lib/types/model/decorators.d.mts +3 -3
- package/lib/types/model/index.d.cts +4 -4
- package/lib/types/model/index.d.mts +4 -4
- package/lib/types/operations/Operations.d.cts +3 -3
- package/lib/types/operations/Operations.d.mts +3 -3
- package/lib/types/operations/OperationsRegistry.d.cts +3 -3
- package/lib/types/operations/OperationsRegistry.d.mts +3 -3
- package/lib/types/operations/decorators.d.cts +3 -3
- package/lib/types/operations/decorators.d.mts +3 -3
- package/lib/types/operations/index.d.cts +5 -5
- package/lib/types/operations/index.d.mts +5 -5
- package/lib/types/operations/types.d.cts +3 -3
- package/lib/types/operations/types.d.mts +3 -3
- package/lib/types/overrides/Model.d.cts +2 -2
- package/lib/types/overrides/Model.d.mts +2 -2
- package/lib/types/overrides/index.d.cts +4 -4
- package/lib/types/overrides/index.d.mts +4 -4
- package/lib/types/repository/Context.d.cts +4 -4
- package/lib/types/repository/Context.d.mts +4 -4
- package/lib/types/repository/Repository.d.cts +3 -3
- package/lib/types/repository/Repository.d.mts +3 -3
- package/lib/types/repository/constants.d.cts +1 -1
- package/lib/types/repository/constants.d.mts +1 -1
- package/lib/types/repository/index.d.cts +7 -7
- package/lib/types/repository/index.d.mts +7 -7
- package/lib/types/repository/types.d.cts +3 -3
- package/lib/types/repository/types.d.mts +3 -3
- package/lib/types/repository/utils.d.cts +3 -3
- package/lib/types/repository/utils.d.mts +3 -3
- package/lib/types/validation/decorators.d.cts +3 -3
- package/lib/types/validation/decorators.d.mts +3 -3
- package/lib/types/validation/index.d.cts +4 -4
- package/lib/types/validation/index.d.mts +4 -4
- package/lib/types/validation/validators/index.d.cts +3 -3
- package/lib/types/validation/validators/index.d.mts +3 -3
- package/package.json +13 -1
- package/lib/types/identity/decorators.d.ts +0 -8
- package/lib/types/identity/index.d.ts +0 -6
- package/lib/types/index.d.ts +0 -15
- package/lib/types/interfaces/BulkCrudOperator.d.ts +0 -47
- package/lib/types/interfaces/Contextual.d.ts +0 -23
- package/lib/types/interfaces/CrudOperator.d.ts +0 -46
- package/lib/types/interfaces/IRepository.d.ts +0 -19
- package/lib/types/interfaces/index.d.ts +0 -9
- package/lib/types/model/constants.d.ts +0 -37
- package/lib/types/model/decorators.d.ts +0 -145
- package/lib/types/model/index.d.ts +0 -9
- package/lib/types/model/model.d.ts +0 -6
- package/lib/types/model/validation.d.ts +0 -57
- package/lib/types/operations/Operations.d.ts +0 -80
- package/lib/types/operations/OperationsRegistry.d.ts +0 -72
- package/lib/types/operations/constants.d.ts +0 -106
- package/lib/types/operations/decorators.d.ts +0 -348
- package/lib/types/operations/index.d.ts +0 -10
- package/lib/types/operations/types.d.ts +0 -60
- package/lib/types/overrides/Metadata.d.ts +0 -54
- package/lib/types/overrides/Model.d.ts +0 -84
- package/lib/types/overrides/ModelBuilderExtensions.d.ts +0 -15
- package/lib/types/overrides/index.d.ts +0 -10
- package/lib/types/overrides/overrides.d.ts +0 -1
- package/lib/types/repository/Context.d.ts +0 -112
- package/lib/types/repository/Repository.d.ts +0 -352
- package/lib/types/repository/constants.d.ts +0 -9
- package/lib/types/repository/errors.d.ts +0 -126
- package/lib/types/repository/index.d.ts +0 -12
- package/lib/types/repository/types.d.ts +0 -62
- package/lib/types/repository/utils.d.ts +0 -34
- package/lib/types/repository/wrappers.d.ts +0 -39
- package/lib/types/validation/constants.d.ts +0 -45
- package/lib/types/validation/decorators.d.ts +0 -143
- package/lib/types/validation/index.d.ts +0 -4
- package/lib/types/validation/validation.d.ts +0 -41
- package/lib/types/validation/validators/ReadOnlyValidator.d.ts +0 -47
- package/lib/types/validation/validators/TimestampValidator.d.ts +0 -48
- package/lib/types/validation/validators/UpdateValidator.d.ts +0 -40
- package/lib/types/validation/validators/index.d.ts +0 -3
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
|
-
import { IRepository } from "../interfaces/IRepository";
|
|
3
|
-
import { CrudOperations, GroupSort } from "../operations";
|
|
4
|
-
import { ContextOfRepository } from "../repository/index";
|
|
5
|
-
export declare function generated(type?: string): (target: object, prop?: any) => void;
|
|
6
|
-
/**
|
|
7
|
-
* @description Hashes a property value during create or update operations
|
|
8
|
-
* @summary Callback function used by the hash decorator to apply hashing to a property value
|
|
9
|
-
* @template M - Type extending Model
|
|
10
|
-
* @template R - Type extending IRepository
|
|
11
|
-
* @template V - Type for metadata
|
|
12
|
-
* @template F - Type extending RepositoryFlags
|
|
13
|
-
* @template C - Type extending Context
|
|
14
|
-
* @param {C} context - The operation context
|
|
15
|
-
* @param {V} data - Metadata for the operation
|
|
16
|
-
* @param key - The property key to hash
|
|
17
|
-
* @param {M} model - The model being processed
|
|
18
|
-
* @param {M} [oldModel] - The previous model state (for updates)
|
|
19
|
-
* @return {void}
|
|
20
|
-
* @function hashOnCreateUpdate
|
|
21
|
-
* @memberOf module:db-decorators
|
|
22
|
-
*/
|
|
23
|
-
export declare function hashOnCreateUpdate<M extends Model, R extends IRepository<M, any>, V extends object>(this: R, context: ContextOfRepository<R>, data: V, key: keyof M, model: M, oldModel?: M): void;
|
|
24
|
-
/**
|
|
25
|
-
* @description Creates a decorator that hashes a property value
|
|
26
|
-
* @summary Decorator that automatically hashes a property value during create and update operations
|
|
27
|
-
* @return {PropertyDecorator} A decorator that can be applied to class properties
|
|
28
|
-
* @function hash
|
|
29
|
-
* @category Property Decorators
|
|
30
|
-
*/
|
|
31
|
-
export declare function hash(): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor | number) => void;
|
|
32
|
-
/**
|
|
33
|
-
* @description Metadata for composed property decorators
|
|
34
|
-
* @summary Configuration options for property composition from other properties
|
|
35
|
-
* @typedef {Object} ComposedFromMetadata
|
|
36
|
-
* @property {string[]} args - Property names to compose from
|
|
37
|
-
* @property {string} separator - Character used to join the composed values
|
|
38
|
-
* @property {boolean} hashResult - Whether to hash the composed result
|
|
39
|
-
* @property {"keys"|"values"} type - Whether to use property keys or values
|
|
40
|
-
* @property {string} [prefix] - Optional prefix to add to the composed value
|
|
41
|
-
* @property {string} [suffix] - Optional suffix to add to the composed value
|
|
42
|
-
* @memberOf module:db-decorators
|
|
43
|
-
*/
|
|
44
|
-
export type ComposedFromMetadata = {
|
|
45
|
-
args: string[];
|
|
46
|
-
separator: string;
|
|
47
|
-
hashResult: boolean;
|
|
48
|
-
type: "keys" | "values";
|
|
49
|
-
prefix?: string;
|
|
50
|
-
suffix?: string;
|
|
51
|
-
filterEmpty: boolean | string[];
|
|
52
|
-
};
|
|
53
|
-
export declare function composeAttributeValue<M extends Model>(model: M, metadata: ComposedFromMetadata): any;
|
|
54
|
-
/**
|
|
55
|
-
* @description Composes a property value from other properties during create or update operations
|
|
56
|
-
* @summary Callback function used by composed decorators to generate a property value from other properties
|
|
57
|
-
* @template M - Type extending Model
|
|
58
|
-
* @template R - Type extending IRepository
|
|
59
|
-
* @template V - Type extending ComposedFromMetadata
|
|
60
|
-
* @template F - Type extending RepositoryFlags
|
|
61
|
-
* @template C - Type extending Context
|
|
62
|
-
* @param {C} context - The operation context
|
|
63
|
-
* @param {V} data - Metadata for the composition
|
|
64
|
-
* @param key - The property key to set the composed value on
|
|
65
|
-
* @param {M} model - The model being processed
|
|
66
|
-
* @return {void}
|
|
67
|
-
* @function composedFromCreateUpdate
|
|
68
|
-
* @memberOf module:db-decorators
|
|
69
|
-
*/
|
|
70
|
-
export declare function composedFromCreateUpdate<M extends Model, R extends IRepository<M, any>, V extends ComposedFromMetadata>(this: R, context: ContextOfRepository<R>, data: V, key: keyof M, model: M): void;
|
|
71
|
-
/**
|
|
72
|
-
* @description Creates a decorator that composes a property value from property keys
|
|
73
|
-
* @summary Decorator that generates a property value by joining the names of other properties
|
|
74
|
-
* @param {string[]} args - Property names to compose from
|
|
75
|
-
* @param {string} [separator=DefaultSeparator] - Character used to join the property names
|
|
76
|
-
* @param {boolean} [hash=false] - Whether to hash the composed result
|
|
77
|
-
* @param {string} [prefix=""] - Optional prefix to add to the composed value
|
|
78
|
-
* @param {string} [suffix=""] - Optional suffix to add to the composed value
|
|
79
|
-
* @param {GroupSort} groupsort - GroupSort configuration
|
|
80
|
-
* @return {PropertyDecorator} A decorator that can be applied to class properties
|
|
81
|
-
* @function composedFromKeys
|
|
82
|
-
* @category PropertyDecorators
|
|
83
|
-
*/
|
|
84
|
-
export declare function composedFromKeys(args: string[], separator?: string, filterEmpty?: boolean | string[], hash?: boolean, prefix?: string, suffix?: string, groupsort?: GroupSort): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
85
|
-
/**
|
|
86
|
-
* @description Creates a decorator that composes a property value from property values
|
|
87
|
-
* @summary Decorator that generates a property value by joining the values of other properties
|
|
88
|
-
* @param {string[]} args - Property names whose values will be composed
|
|
89
|
-
* @param {string} [separator=DefaultSeparator] - Character used to join the property values
|
|
90
|
-
* @param {boolean} [hash=false] - Whether to hash the composed result
|
|
91
|
-
* @param {string} [prefix=""] - Optional prefix to add to the composed value
|
|
92
|
-
* @param {string} [suffix=""] - Optional suffix to add to the composed value
|
|
93
|
-
* @param {GroupSort} groupsort - GroupSort configuration
|
|
94
|
-
* @return {PropertyDecorator} A decorator that can be applied to class properties
|
|
95
|
-
* @function composed
|
|
96
|
-
* @category PropertyDecorators
|
|
97
|
-
*/
|
|
98
|
-
export declare function composed(args: string[], separator?: string, filterEmpty?: boolean | string[], hash?: boolean, prefix?: string, suffix?: string, groupsort?: GroupSort): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
99
|
-
/**
|
|
100
|
-
* @description Creates a function that updates a version property during operations
|
|
101
|
-
* @summary Factory function that generates a callback for incrementing version numbers
|
|
102
|
-
* @param {CrudOperations} operation - The type of operation (CREATE or UPDATE)
|
|
103
|
-
* @return {Function} A callback function that updates the version property
|
|
104
|
-
* @template M - Type extending Model
|
|
105
|
-
* @template R - Type extending IRepository
|
|
106
|
-
* @template V - Type for metadata
|
|
107
|
-
* @template F - Type extending RepositoryFlags
|
|
108
|
-
* @template C - Type extending Context
|
|
109
|
-
* @function versionCreateUpdate
|
|
110
|
-
* @memberOf module:db-decorators
|
|
111
|
-
* @mermaid
|
|
112
|
-
* sequenceDiagram
|
|
113
|
-
* participant Caller
|
|
114
|
-
* participant versionCreateUpdate
|
|
115
|
-
*
|
|
116
|
-
* Caller->>versionCreateUpdate: operation
|
|
117
|
-
* versionCreateUpdate-->>Caller: callback function
|
|
118
|
-
* Note over Caller,versionCreateUpdate: When callback is executed:
|
|
119
|
-
* Caller->>versionCreateUpdate: context, data, key, model
|
|
120
|
-
* alt operation is CREATE
|
|
121
|
-
* versionCreateUpdate->>versionCreateUpdate: set version to 1
|
|
122
|
-
* else operation is UPDATE
|
|
123
|
-
* versionCreateUpdate->>versionCreateUpdate: increment version
|
|
124
|
-
* else invalid operation
|
|
125
|
-
* versionCreateUpdate->>versionCreateUpdate: throw error
|
|
126
|
-
* end
|
|
127
|
-
* versionCreateUpdate-->>Caller: void
|
|
128
|
-
*/
|
|
129
|
-
export declare function versionCreateUpdate(operation: CrudOperations): <M extends Model, R extends IRepository<M>, V extends object>(this: R, context: ContextOfRepository<R>, data: V, key: keyof M, model: M, oldModel?: M) => void;
|
|
130
|
-
/**
|
|
131
|
-
* @description Creates a decorator for versioning a property in a model
|
|
132
|
-
* @summary This decorator applies multiple sub-decorators to handle version management during create and update operations
|
|
133
|
-
* @return {PropertyDecorator} A composite decorator that sets the type to Number, manages version updates, and adds versioning metadata
|
|
134
|
-
* @function version
|
|
135
|
-
* @category PropertyDecorators
|
|
136
|
-
*/
|
|
137
|
-
export declare function version(): (target: any, propertyKey?: any) => any;
|
|
138
|
-
/**
|
|
139
|
-
* @description Creates a decorator that marks a property as transient
|
|
140
|
-
* @summary Decorator that indicates a property should not be persisted to the database
|
|
141
|
-
* @return {PropertyDecorator} A decorator that can be applied to class properties
|
|
142
|
-
* @function transient
|
|
143
|
-
* @category PropertyDecorators
|
|
144
|
-
*/
|
|
145
|
-
export declare function transient(): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description Exports for the model module.
|
|
3
|
-
* @summary This file exports all the necessary components for the model functionality, including constants, decorators, and the model itself.
|
|
4
|
-
* @module db-decorators/model
|
|
5
|
-
*/
|
|
6
|
-
export * from "./constants";
|
|
7
|
-
export * from "./decorators";
|
|
8
|
-
export * from "./model";
|
|
9
|
-
export * from "./validation";
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { ConditionalAsync, ModelErrorDefinition } from "@decaf-ts/decorator-validation";
|
|
2
|
-
declare module "@decaf-ts/decorator-validation" {
|
|
3
|
-
interface Model<Async extends boolean = false> {
|
|
4
|
-
hasErrors(previousVersion?: Model | any, ...exclusions: any[]): ConditionalAsync<Async, ModelErrorDefinition | undefined>;
|
|
5
|
-
}
|
|
6
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { ConditionalAsync, Model, ModelConditionalAsync } from "@decaf-ts/decorator-validation";
|
|
2
|
-
/**
|
|
3
|
-
* @description
|
|
4
|
-
* Retrieves validation decorator definitions from a model for update operations, including
|
|
5
|
-
* support for special handling of list decorators.
|
|
6
|
-
*
|
|
7
|
-
* @summary
|
|
8
|
-
* Iterates over the model's own enumerable properties and filters out those specified in the
|
|
9
|
-
* `propsToIgnore` array. For each remaining property, retrieves validation decorators specific
|
|
10
|
-
* to update operations using the `UpdateValidationKeys.REFLECT` key. Additionally, it explicitly
|
|
11
|
-
* checks for and appends any `LIST` type decorators to ensure proper validation of collection types.
|
|
12
|
-
*
|
|
13
|
-
* @template M - A generic parameter extending the `Model` class, representing the model type being inspected.
|
|
14
|
-
*
|
|
15
|
-
* @param {M} model - The model instance whose properties are being inspected for update-related validations.
|
|
16
|
-
* @param {string[]} propsToIgnore - A list of property names to exclude from the validation decorator retrieval process.
|
|
17
|
-
*
|
|
18
|
-
* @return {ValidationPropertyDecoratorDefinition[]} An array of validation decorator definitions, including both
|
|
19
|
-
* update-specific and list-type decorators, excluding those for ignored properties.
|
|
20
|
-
*
|
|
21
|
-
* @function getValidatableUpdateProps
|
|
22
|
-
*/
|
|
23
|
-
export declare function getValidatableUpdateProps<M extends Model>(model: M, propsToIgnore: string[]): any[];
|
|
24
|
-
export declare function validateDecorator<M extends Model, Async extends boolean = false>(newModel: M, oldModel: M, prop: string, decorator: any, async?: Async): ConditionalAsync<Async, string | undefined>;
|
|
25
|
-
export declare function validateDecorators<M extends Model, Async extends boolean = false>(newModel: M, oldModel: M, prop: string, decorators: any, async?: Async): ConditionalAsync<Async, Record<string, string>> | undefined;
|
|
26
|
-
/**
|
|
27
|
-
* @description Validates changes between two model versions
|
|
28
|
-
* @summary Compares an old and new model version to validate update operations
|
|
29
|
-
* @template M - Type extending Model
|
|
30
|
-
* @param {M} oldModel - The original model version
|
|
31
|
-
* @param {M} newModel - The updated model version
|
|
32
|
-
* @param {boolean} async - A flag indicating whether validation should be asynchronous.
|
|
33
|
-
* @param {...string[]} propsToIgnore - Properties to exclude from validation
|
|
34
|
-
* @return {ModelErrorDefinition|undefined} Error definition if validation fails, undefined otherwise
|
|
35
|
-
* @function validateCompare
|
|
36
|
-
* @memberOf module:db-decorators
|
|
37
|
-
* @mermaid
|
|
38
|
-
* sequenceDiagram
|
|
39
|
-
* participant Caller
|
|
40
|
-
* participant validateCompare
|
|
41
|
-
* participant Reflection
|
|
42
|
-
* participant Validation
|
|
43
|
-
*
|
|
44
|
-
* Caller->>validateCompare: oldModel, newModel, propsToIgnore
|
|
45
|
-
* validateCompare->>Reflection: get decorated properties
|
|
46
|
-
* Reflection-->>validateCompare: property decorators
|
|
47
|
-
* loop For each decorated property
|
|
48
|
-
* validateCompare->>Validation: get validator
|
|
49
|
-
* Validation-->>validateCompare: validator
|
|
50
|
-
* validateCompare->>validateCompare: validate property update
|
|
51
|
-
* end
|
|
52
|
-
* loop For nested models
|
|
53
|
-
* validateCompare->>validateCompare: validate nested models
|
|
54
|
-
* end
|
|
55
|
-
* validateCompare-->>Caller: validation errors or undefined
|
|
56
|
-
*/
|
|
57
|
-
export declare function validateCompare<M extends Model<any>>(oldModel: M, newModel: M, async: boolean, ...propsToIgnore: string[]): ModelConditionalAsync<M>;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
|
-
import { OperationHandler } from "./types";
|
|
3
|
-
import { OperationKeys } from "./constants";
|
|
4
|
-
import { IRepository } from "../interfaces";
|
|
5
|
-
/**
|
|
6
|
-
* @description Static utility class for database operation management
|
|
7
|
-
* @summary Provides functionality for registering, retrieving, and managing database operation handlers
|
|
8
|
-
* @class Operations
|
|
9
|
-
* @template M - Model type
|
|
10
|
-
* @template R - Repository type
|
|
11
|
-
* @template V - Metadata type
|
|
12
|
-
* @example
|
|
13
|
-
* // Register a handler for a create operation
|
|
14
|
-
* Operations.register(myHandler, OperationKeys.CREATE, targetModel, 'propertyName');
|
|
15
|
-
*
|
|
16
|
-
* // Get handlers for a specific operation
|
|
17
|
-
* const handlers = Operations.get(targetModel.constructor.name, 'propertyName', 'onCreate');
|
|
18
|
-
*
|
|
19
|
-
* @mermaid
|
|
20
|
-
* classDiagram
|
|
21
|
-
* class Operations {
|
|
22
|
-
* -registry: OperationsRegistry
|
|
23
|
-
* +getHandlerName(handler)
|
|
24
|
-
* +key(str)
|
|
25
|
-
* +get(targetName, propKey, operation)
|
|
26
|
-
* -getOpRegistry()
|
|
27
|
-
* +register(handler, operation, target, propKey)
|
|
28
|
-
* }
|
|
29
|
-
* Operations --> OperationsRegistry : uses
|
|
30
|
-
*/
|
|
31
|
-
export declare class Operations {
|
|
32
|
-
private static registry;
|
|
33
|
-
private constructor();
|
|
34
|
-
/**
|
|
35
|
-
* @description Gets a unique name for an operation handler
|
|
36
|
-
* @summary Returns the name of the handler function or generates a hash if name is not available
|
|
37
|
-
* @param {OperationHandler<any, any, any>} handler - The handler function to get the name for
|
|
38
|
-
* @return {string} The name of the handler or a generated hash
|
|
39
|
-
*/
|
|
40
|
-
static getHandlerName(handler: OperationHandler<any, any, any>): any;
|
|
41
|
-
/**
|
|
42
|
-
* @description Generates a reflection metadata key
|
|
43
|
-
* @summary Creates a fully qualified metadata key by prefixing with the reflection namespace
|
|
44
|
-
* @param {string} str - The operation key string to prefix
|
|
45
|
-
* @return {string} The fully qualified metadata key
|
|
46
|
-
*/
|
|
47
|
-
static key(str: string): string;
|
|
48
|
-
/**
|
|
49
|
-
* @description Retrieves operation handlers for a specific target and operation
|
|
50
|
-
* @summary Gets registered handlers from the operations registry for a given target, property, and operation
|
|
51
|
-
* @template M - Model type extending Model
|
|
52
|
-
* @template R - Repository type extending IRepository
|
|
53
|
-
* @template V - Metadata type, defaults to object
|
|
54
|
-
* @template F - Repository flags extending RepositoryFlags
|
|
55
|
-
* @template C - Context type extending Context<F>
|
|
56
|
-
* @param {string | Record<string, any>} targetName - The target class name or object
|
|
57
|
-
* @param {string} propKey - The property key to get handlers for
|
|
58
|
-
* @param {string} operation - The operation key to get handlers for
|
|
59
|
-
* @return {any} The registered handlers for the specified target, property, and operation
|
|
60
|
-
*/
|
|
61
|
-
static get<M extends Model, R extends IRepository<M, any>, V = object>(targetName: string | Record<string, any>, propKey: string, operation: string): OperationHandler<M, R, V>[] | undefined;
|
|
62
|
-
/**
|
|
63
|
-
* @description Gets or initializes the operations registry
|
|
64
|
-
* @summary Returns the existing registry or creates a new one if it doesn't exist
|
|
65
|
-
* @return {OperationsRegistry} The operations registry instance
|
|
66
|
-
* @private
|
|
67
|
-
*/
|
|
68
|
-
private static getOpRegistry;
|
|
69
|
-
/**
|
|
70
|
-
* @description Registers an operation handler for a specific target and operation
|
|
71
|
-
* @summary Adds a handler to the operations registry for a given target, property, and operation
|
|
72
|
-
* @template V - Model type extending Model
|
|
73
|
-
* @param {OperationHandler<V, any, any>} handler - The handler function to register
|
|
74
|
-
* @param {OperationKeys} operation - The operation key to register the handler for
|
|
75
|
-
* @param {V} target - The target model instance
|
|
76
|
-
* @param {string | symbol} propKey - The property key to register the handler for
|
|
77
|
-
* @return {void}
|
|
78
|
-
*/
|
|
79
|
-
static register<V extends Model>(handler: OperationHandler<V, any, any>, operation: OperationKeys, target: V, propKey: string | symbol): void;
|
|
80
|
-
}
|
|
@@ -1,72 +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
|
-
* @description Registry for database operation handlers
|
|
7
|
-
* @summary Manages and stores operation handlers for different model properties and operations
|
|
8
|
-
* @class OperationsRegistry
|
|
9
|
-
* @template M - Model type
|
|
10
|
-
* @template R - Repository type
|
|
11
|
-
* @template V - Metadata type
|
|
12
|
-
* @template F - Repository flags
|
|
13
|
-
* @template C - Context type
|
|
14
|
-
* @example
|
|
15
|
-
* // Create a registry and register a handler
|
|
16
|
-
* const registry = new OperationsRegistry();
|
|
17
|
-
* registry.register(myHandler, OperationKeys.CREATE, targetModel, 'propertyName');
|
|
18
|
-
*
|
|
19
|
-
* // Get handlers for a specific operation
|
|
20
|
-
* const handlers = registry.get(targetModel.constructor.name, 'propertyName', 'onCreate');
|
|
21
|
-
*
|
|
22
|
-
* @mermaid
|
|
23
|
-
* classDiagram
|
|
24
|
-
* class OperationsRegistry {
|
|
25
|
-
* -cache: Record~string, Record~string|symbol, Record~string, Record~string, OperationHandler~~~~
|
|
26
|
-
* +get(target, propKey, operation, accum)
|
|
27
|
-
* +register(handler, operation, target, propKey)
|
|
28
|
-
* }
|
|
29
|
-
*/
|
|
30
|
-
export declare class OperationsRegistry {
|
|
31
|
-
private readonly cache;
|
|
32
|
-
/**
|
|
33
|
-
* @description Retrieves operation handlers for a specific target and operation
|
|
34
|
-
* @summary Finds all registered handlers for a given target, property, and operation, including from parent classes
|
|
35
|
-
* @template M - Model type extending Model
|
|
36
|
-
* @template R - Repository type extending IRepository
|
|
37
|
-
* @template V - Metadata type
|
|
38
|
-
* @param {string | Record<string, any>} target - The target class name or object
|
|
39
|
-
* @param {string} propKey - The property key to get handlers for
|
|
40
|
-
* @param {string} operation - The operation key to get handlers for
|
|
41
|
-
* @param {OperationHandler[]} [accum] - Accumulator for recursive calls
|
|
42
|
-
* @return {OperationHandler[] | undefined} Array of handlers or undefined if none found
|
|
43
|
-
*/
|
|
44
|
-
get<M extends Model, R extends IRepository<M, any>, V>(target: string | Record<string, any>, propKey: string, operation: string, accum?: OperationHandler<M, R, V>[]): OperationHandler<M, R, V>[] | undefined;
|
|
45
|
-
/**
|
|
46
|
-
* @description Registers an operation handler for a specific target and operation
|
|
47
|
-
* @summary Stores a handler in the registry for a given target, property, and operation
|
|
48
|
-
* @template M - Model type extending Model
|
|
49
|
-
* @template R - Repository type extending IRepository
|
|
50
|
-
* @template V - Metadata type
|
|
51
|
-
* @template F - Repository flags extending RepositoryFlags
|
|
52
|
-
* @template C - Context type extending Context<F>
|
|
53
|
-
* @param {OperationHandler} handler - The handler function to register
|
|
54
|
-
* @param {OperationKeys} operation - The operation key to register the handler for
|
|
55
|
-
* @param {M} target - The target model instance
|
|
56
|
-
* @param {string | symbol} propKey - The property key to register the handler for
|
|
57
|
-
* @return {void}
|
|
58
|
-
*/
|
|
59
|
-
register<M extends Model, R extends IRepository<M, any>, V>(handler: OperationHandler<M, R, V>, operation: OperationKeys, target: M, propKey: string | symbol): void;
|
|
60
|
-
private resolveOwner;
|
|
61
|
-
private resolveTargetName;
|
|
62
|
-
private resolveFlavour;
|
|
63
|
-
private selectHandlers;
|
|
64
|
-
private firstBucket;
|
|
65
|
-
/**
|
|
66
|
-
* @description Gets a unique name for an operation handler
|
|
67
|
-
* @summary Returns the name of the handler function or generates a hash if name is not available
|
|
68
|
-
* @param {OperationHandler<any, any, any>} handler - The handler function to get the name for
|
|
69
|
-
* @return {string} The name of the handler or a generated hash
|
|
70
|
-
*/
|
|
71
|
-
static getHandlerName(handler: OperationHandler<any, any, any>): any;
|
|
72
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description Database operation key constants
|
|
3
|
-
* @summary Enum defining CRUD operations and their lifecycle phases
|
|
4
|
-
* @enum {string}
|
|
5
|
-
* @readonly
|
|
6
|
-
* @memberOf module:db-decorators
|
|
7
|
-
*/
|
|
8
|
-
export declare enum OperationKeys {
|
|
9
|
-
REFLECT = "decaf.model.db.operations.",
|
|
10
|
-
CREATE = "create",
|
|
11
|
-
READ = "read",
|
|
12
|
-
UPDATE = "update",
|
|
13
|
-
DELETE = "delete",
|
|
14
|
-
ON = "on.",
|
|
15
|
-
AFTER = "after.",
|
|
16
|
-
BLOCK = "block"
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* @description Database operation key naming constants
|
|
20
|
-
* @summary Enum defining operations naming
|
|
21
|
-
* @enum {string}
|
|
22
|
-
* @readonly
|
|
23
|
-
* @memberOf module:db-decorators
|
|
24
|
-
*/
|
|
25
|
-
export declare enum ModelOperations {
|
|
26
|
-
OPERATIONS = "operations",
|
|
27
|
-
RELATIONS = "relations"
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* @description Type for basic CRUD operations
|
|
31
|
-
* @summary Union type of the four basic database operations: create, read, update, delete
|
|
32
|
-
* @typedef {string} CrudOperations
|
|
33
|
-
* @memberOf module:db-decorators
|
|
34
|
-
*/
|
|
35
|
-
export type CrudOperations = OperationKeys.CREATE | OperationKeys.READ | OperationKeys.UPDATE | OperationKeys.DELETE;
|
|
36
|
-
/**
|
|
37
|
-
* @description Bulk database operation key constants
|
|
38
|
-
* @summary Enum defining bulk CRUD operations for handling multiple records at once
|
|
39
|
-
* @enum {string}
|
|
40
|
-
* @readonly
|
|
41
|
-
* @memberOf module:db-decorators
|
|
42
|
-
*/
|
|
43
|
-
export declare enum BulkCrudOperationKeys {
|
|
44
|
-
CREATE_ALL = "createAll",
|
|
45
|
-
READ_ALL = "readAll",
|
|
46
|
-
UPDATE_ALL = "updateAll",
|
|
47
|
-
DELETE_ALL = "deleteAll"
|
|
48
|
-
}
|
|
49
|
-
export declare enum BulkOperationBlockTarget {
|
|
50
|
-
ALL = "bulkAll"
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* @description Type for bulk CRUD operations
|
|
54
|
-
* @summary Union type of the four bulk database operations for handling multiple records at once
|
|
55
|
-
* @typedef {string} BulkCrudOperations
|
|
56
|
-
* @memberOf module:db-decorators
|
|
57
|
-
*/
|
|
58
|
-
export type BulkCrudOperations = BulkCrudOperationKeys.CREATE_ALL | BulkCrudOperationKeys.READ_ALL | BulkCrudOperationKeys.UPDATE_ALL | BulkCrudOperationKeys.DELETE_ALL;
|
|
59
|
-
/**
|
|
60
|
-
* @description Grouped CRUD operations for decorator mapping
|
|
61
|
-
* @summary Maps out groups of CRUD operations for easier mapping of decorators
|
|
62
|
-
* @const DBOperations
|
|
63
|
-
* @memberOf module:db-decorators
|
|
64
|
-
*/
|
|
65
|
-
export declare const DBOperations: Record<string, CrudOperations[]>;
|
|
66
|
-
/**
|
|
67
|
-
* @description Block target categories
|
|
68
|
-
* @summary Indicates whether the block applies to CRUD ops, prepared statements, or query keys
|
|
69
|
-
* @typedef {"crud" | "statement" | "query"} BlockOperationKind
|
|
70
|
-
* @memberOf module:db-decorators
|
|
71
|
-
*/
|
|
72
|
-
export type BlockOperationKind = "crud" | "statement" | "query" | "bulk";
|
|
73
|
-
/**
|
|
74
|
-
* @description Descriptor for a single blocked operation target
|
|
75
|
-
* @summary Includes the target kind and identifier (CRUD operation, statement name, query key)
|
|
76
|
-
* @typedef BlockOperationDescriptor
|
|
77
|
-
* @property {"crud"} kind
|
|
78
|
-
* @property {CrudOperations} value
|
|
79
|
-
*
|
|
80
|
-
* @property {"statement"} kind
|
|
81
|
-
* @property {string} value
|
|
82
|
-
*
|
|
83
|
-
* @property {"query"} kind
|
|
84
|
-
* @property {string} value
|
|
85
|
-
* @memberOf module:db-decorators
|
|
86
|
-
*/
|
|
87
|
-
export type BlockOperationDescriptor = {
|
|
88
|
-
kind: "crud";
|
|
89
|
-
value: CrudOperations;
|
|
90
|
-
} | {
|
|
91
|
-
kind: "statement";
|
|
92
|
-
value: string;
|
|
93
|
-
} | {
|
|
94
|
-
kind: "query";
|
|
95
|
-
value: string;
|
|
96
|
-
} | {
|
|
97
|
-
kind: "bulk";
|
|
98
|
-
value: BulkCrudOperations | BulkOperationBlockTarget;
|
|
99
|
-
};
|
|
100
|
-
/**
|
|
101
|
-
* @description Inputs accepted by @BlockOperations decorator
|
|
102
|
-
* @summary Accepts either a CRUD operation, a descriptor, or an array of both
|
|
103
|
-
* @typedef {CrudOperations | BlockOperationDescriptor | Array<CrudOperations | BlockOperationDescriptor>} BlockOperationsInput
|
|
104
|
-
* @memberOf module:db-decorators
|
|
105
|
-
*/
|
|
106
|
-
export type BlockOperationsInput = CrudOperations | BulkCrudOperations | BulkOperationBlockTarget | BlockOperationDescriptor | (CrudOperations | BulkCrudOperations | BulkOperationBlockTarget | BlockOperationDescriptor)[];
|