@decaf-ts/db-decorators 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.cjs +1 -1
- package/lib/esm/index.js +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 +8 -8
- package/lib/types/index.d.mts +8 -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 +1 -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,62 +0,0 @@
|
|
|
1
|
-
import { Context } from "./Context";
|
|
2
|
-
import { ExtendedMetadata, Model } from "@decaf-ts/decorator-validation";
|
|
3
|
-
import { OperationKeys } from "../operations";
|
|
4
|
-
import { Constructor } from "@decaf-ts/decoration";
|
|
5
|
-
import { Logger } from "@decaf-ts/logging";
|
|
6
|
-
import { IRepository } from "../interfaces/index";
|
|
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>;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { IRepository } from "../interfaces/IRepository";
|
|
2
|
-
import { Model, ModelErrorDefinition } from "@decaf-ts/decorator-validation";
|
|
3
|
-
import { Context } from "./Context";
|
|
4
|
-
import { ContextOfRepository } from "./types";
|
|
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;
|
|
@@ -1,39 +0,0 @@
|
|
|
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;
|
|
@@ -1,45 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import "./validation";
|
|
2
|
-
import { Model, Serializer } from "@decaf-ts/decorator-validation";
|
|
3
|
-
import { OperationKeys } from "../operations/constants";
|
|
4
|
-
import { IRepository } from "../interfaces/IRepository";
|
|
5
|
-
import { Constructor } from "@decaf-ts/decoration";
|
|
6
|
-
import { ContextOfRepository } from "../repository/index";
|
|
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;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Validator, ValidatorDefinition, IValidatorRegistry } from "@decaf-ts/decorator-validation";
|
|
2
|
-
declare module "@decaf-ts/decorator-validation" {
|
|
3
|
-
class Validation {
|
|
4
|
-
private static actingValidatorRegistry?;
|
|
5
|
-
private constructor();
|
|
6
|
-
/**
|
|
7
|
-
* @summary Defines the acting ValidatorRegistry
|
|
8
|
-
*
|
|
9
|
-
* @param {IValidatorRegistry} validatorRegistry the new implementation of the validator Registry
|
|
10
|
-
* @param {function(Validator): Validator} [migrationHandler] the method to map the validator if required;
|
|
11
|
-
*/
|
|
12
|
-
static setRegistry(validatorRegistry: IValidatorRegistry<Validator>, migrationHandler?: (validator: Validator) => Validator): void;
|
|
13
|
-
/**
|
|
14
|
-
* @summary Returns the current ValidatorRegistry
|
|
15
|
-
*
|
|
16
|
-
* @return IValidatorRegistry, defaults to {@link ValidatorRegistry}
|
|
17
|
-
*/
|
|
18
|
-
private static getRegistry;
|
|
19
|
-
/**
|
|
20
|
-
* @summary Retrieves a validator
|
|
21
|
-
*
|
|
22
|
-
* @param {string} validatorKey one of the {@link ValidationKeys}
|
|
23
|
-
* @return {Validator | undefined} the registered Validator or undefined if there is nono matching the provided key
|
|
24
|
-
*/
|
|
25
|
-
static get<T extends Validator>(validatorKey: string): T | undefined;
|
|
26
|
-
/**
|
|
27
|
-
* @summary Registers the provided validators onto the registry
|
|
28
|
-
*
|
|
29
|
-
* @param {T[] | ValidatorDefinition[]} validator
|
|
30
|
-
*/
|
|
31
|
-
static register<T extends Validator>(...validator: (ValidatorDefinition | T)[]): void;
|
|
32
|
-
/**
|
|
33
|
-
* @summary Builds the key to store as Metadata under Reflections
|
|
34
|
-
* @description concatenates {@link ValidationKeys#REFLECT} with the provided key
|
|
35
|
-
*
|
|
36
|
-
* @param {string} key
|
|
37
|
-
*/
|
|
38
|
-
static key(key: string): string;
|
|
39
|
-
static updateKey(key: string): string;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Validator } from "@decaf-ts/decorator-validation";
|
|
2
|
-
/**
|
|
3
|
-
* @description A validator that ensures properties marked as readonly cannot be modified during updates.
|
|
4
|
-
* @summary Validator for the {@link readonly} decorator that checks if a value has been changed during an update operation. It compares the new value with the old value and returns an error message if they are not equal.
|
|
5
|
-
* @param {any} value - The value to be validated
|
|
6
|
-
* @param {any} oldValue - The previous value to compare against
|
|
7
|
-
* @param {string} [message] - Optional custom error message
|
|
8
|
-
* @class ReadOnlyValidator
|
|
9
|
-
* @example
|
|
10
|
-
* // Using ReadOnlyValidator with a readonly property
|
|
11
|
-
* class User {
|
|
12
|
-
* @readonly()
|
|
13
|
-
* id: string;
|
|
14
|
-
*
|
|
15
|
-
* name: string;
|
|
16
|
-
*
|
|
17
|
-
* constructor(id: string, name: string) {
|
|
18
|
-
* this.id = id;
|
|
19
|
-
* this.name = name;
|
|
20
|
-
* }
|
|
21
|
-
* }
|
|
22
|
-
*
|
|
23
|
-
* // This will trigger validation error when trying to update
|
|
24
|
-
* const user = new User('123', 'John');
|
|
25
|
-
* user.id = '456'; // Will be prevented by ReadOnlyValidator
|
|
26
|
-
* @category Validators
|
|
27
|
-
*/
|
|
28
|
-
export declare class ReadOnlyValidator extends Validator {
|
|
29
|
-
constructor();
|
|
30
|
-
/**
|
|
31
|
-
* @description Implementation of the base validator's hasErrors method.
|
|
32
|
-
* @summary This method is required by the Validator interface but not used in this validator as validation only happens during updates.
|
|
33
|
-
* @param {any} value - The value to validate
|
|
34
|
-
* @param {any[]} args - Additional arguments
|
|
35
|
-
* @return {string | undefined} Always returns undefined as this validator only works during updates
|
|
36
|
-
*/
|
|
37
|
-
hasErrors(value: any, ...args: any[]): string | undefined;
|
|
38
|
-
/**
|
|
39
|
-
* @description Checks if a value has been modified during an update operation.
|
|
40
|
-
* @summary Validates a value has not changed by comparing it with the previous value using deep equality.
|
|
41
|
-
* @param {any} value - The new value to validate
|
|
42
|
-
* @param {any} oldValue - The original value to compare against
|
|
43
|
-
* @param {string} [message] - Optional custom error message to override the default
|
|
44
|
-
* @return {string | undefined} An error message if validation fails, undefined otherwise
|
|
45
|
-
*/
|
|
46
|
-
updateHasErrors(value: any, oldValue: any, message?: string): string | undefined;
|
|
47
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { Validator } from "@decaf-ts/decorator-validation";
|
|
2
|
-
/**
|
|
3
|
-
* @description A validator that ensures timestamp values are only updated with newer timestamps.
|
|
4
|
-
* @summary Validates the update of a timestamp by comparing the new timestamp with the old one, ensuring the new timestamp is more recent.
|
|
5
|
-
* @param {Date|string|number} value - The timestamp value to validate
|
|
6
|
-
* @param {Date|string|number} oldValue - The previous timestamp to compare against
|
|
7
|
-
* @param {string} [message] - Optional custom error message
|
|
8
|
-
* @class TimestampValidator
|
|
9
|
-
* @example
|
|
10
|
-
* // Using TimestampValidator with a timestamp property
|
|
11
|
-
* class Document {
|
|
12
|
-
* @timestamp()
|
|
13
|
-
* updatedAt: Date;
|
|
14
|
-
*
|
|
15
|
-
* title: string;
|
|
16
|
-
*
|
|
17
|
-
* constructor(title: string) {
|
|
18
|
-
* this.title = title;
|
|
19
|
-
* this.updatedAt = new Date();
|
|
20
|
-
* }
|
|
21
|
-
* }
|
|
22
|
-
*
|
|
23
|
-
* // This will trigger validation error when trying to update with an older timestamp
|
|
24
|
-
* const doc = new Document('My Document');
|
|
25
|
-
* const oldDate = new Date(2020, 0, 1);
|
|
26
|
-
* doc.updatedAt = oldDate; // Will be prevented by TimestampValidator
|
|
27
|
-
* @category Validators
|
|
28
|
-
*/
|
|
29
|
-
export declare class TimestampValidator extends Validator {
|
|
30
|
-
constructor();
|
|
31
|
-
/**
|
|
32
|
-
* @description Implementation of the base validator's hasErrors method.
|
|
33
|
-
* @summary This method is required by the Validator interface but not used in this validator as validation only happens during updates.
|
|
34
|
-
* @param {any} value - The timestamp value to validate
|
|
35
|
-
* @param {any[]} args - Additional arguments
|
|
36
|
-
* @return {string | undefined} Always returns undefined as this validator only works during updates
|
|
37
|
-
*/
|
|
38
|
-
hasErrors(value: any, ...args: any[]): string | undefined;
|
|
39
|
-
/**
|
|
40
|
-
* @description Validates that a timestamp is newer than its previous value.
|
|
41
|
-
* @summary Checks if a timestamp has been updated with a more recent value by converting both values to Date objects and comparing them.
|
|
42
|
-
* @param {Date|string|number} value - The new timestamp value to validate
|
|
43
|
-
* @param {Date|string|number} oldValue - The original timestamp to compare against
|
|
44
|
-
* @param {string} [message] - Optional custom error message to override the default
|
|
45
|
-
* @return {string | undefined} An error message if validation fails (new timestamp is not newer), undefined otherwise
|
|
46
|
-
*/
|
|
47
|
-
updateHasErrors(value: Date | string | number, oldValue: Date | string | number, message?: string): string | undefined;
|
|
48
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { Validator } from "@decaf-ts/decorator-validation";
|
|
2
|
-
/**
|
|
3
|
-
* @description Abstract base class for validators that compare new values with old values during updates.
|
|
4
|
-
* @summary Base class for an Update validator that provides a framework for implementing validation logic that compares a new value with its previous state.
|
|
5
|
-
* @param {string} [message] - Error message. Defaults to {@link DecoratorMessages#DEFAULT}
|
|
6
|
-
* @param {string[]} [acceptedTypes] - The accepted value types by the decorator
|
|
7
|
-
* @class UpdateValidator
|
|
8
|
-
* @example
|
|
9
|
-
* // Extending UpdateValidator to create a custom validator
|
|
10
|
-
* class MyCustomValidator extends UpdateValidator {
|
|
11
|
-
* constructor() {
|
|
12
|
-
* super("Custom validation failed");
|
|
13
|
-
* }
|
|
14
|
-
*
|
|
15
|
-
* public updateHasErrors(value: any, oldValue: any): string | undefined {
|
|
16
|
-
* // Custom validation logic
|
|
17
|
-
* if (value === oldValue) {
|
|
18
|
-
* return this.message;
|
|
19
|
-
* }
|
|
20
|
-
* return undefined;
|
|
21
|
-
* }
|
|
22
|
-
*
|
|
23
|
-
* hasErrors(value: any): string | undefined {
|
|
24
|
-
* return undefined; // Not used for update validators
|
|
25
|
-
* }
|
|
26
|
-
* }
|
|
27
|
-
* @category Validators
|
|
28
|
-
*/
|
|
29
|
-
export declare abstract class UpdateValidator extends Validator {
|
|
30
|
-
protected constructor(message?: string, ...acceptedTypes: string[]);
|
|
31
|
-
/**
|
|
32
|
-
* @description Abstract method that must be implemented by subclasses to perform update validation.
|
|
33
|
-
* @summary Validates a value by comparing it to its old version to determine if the update is valid.
|
|
34
|
-
* @param {any} value - The new value to validate
|
|
35
|
-
* @param {any} oldValue - The previous value to compare against
|
|
36
|
-
* @param {any[]} args - Additional arguments that may be needed for validation
|
|
37
|
-
* @return {string | undefined} An error message if validation fails, undefined if validation passes
|
|
38
|
-
*/
|
|
39
|
-
abstract updateHasErrors(value: any, oldValue: any, ...args: any[]): string | undefined;
|
|
40
|
-
}
|