@decaf-ts/decorator-validation 1.14.0 → 1.16.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/constants/errors.cjs +1 -0
- package/lib/cjs/constants/errors.cjs.map +1 -0
- package/lib/cjs/constants/index.cjs +1 -0
- package/lib/cjs/constants/index.cjs.map +1 -0
- package/lib/cjs/constants/validation.cjs +1 -0
- package/lib/cjs/constants/validation.cjs.map +1 -0
- package/lib/cjs/index.cjs +2 -1
- package/lib/cjs/index.cjs.map +1 -0
- package/lib/cjs/model/Builder.cjs +49 -48
- package/lib/cjs/model/Builder.cjs.map +1 -0
- package/lib/cjs/model/Model.cjs +31 -30
- package/lib/cjs/model/Model.cjs.map +1 -0
- package/lib/cjs/model/ModelErrorDefinition.cjs +1 -0
- package/lib/cjs/model/ModelErrorDefinition.cjs.map +1 -0
- package/lib/cjs/model/ModelRegistry.cjs +7 -6
- package/lib/cjs/model/ModelRegistry.cjs.map +1 -0
- package/lib/cjs/model/constants.cjs +2 -13
- package/lib/cjs/model/constants.cjs.map +1 -0
- package/lib/cjs/model/construction.cjs +5 -4
- package/lib/cjs/model/construction.cjs.map +1 -0
- package/lib/cjs/model/decorators.cjs +12 -11
- package/lib/cjs/model/decorators.cjs.map +1 -0
- package/lib/cjs/model/index.cjs +1 -0
- package/lib/cjs/model/index.cjs.map +1 -0
- package/lib/cjs/model/types.cjs +1 -0
- package/lib/cjs/model/types.cjs.map +1 -0
- package/lib/cjs/model/utils.cjs +1 -0
- package/lib/cjs/model/utils.cjs.map +1 -0
- package/lib/cjs/model/validation.cjs +33 -32
- package/lib/cjs/model/validation.cjs.map +1 -0
- package/lib/cjs/overrides/Metadata.cjs +1 -0
- package/lib/cjs/overrides/Metadata.cjs.map +1 -0
- package/lib/cjs/overrides/index.cjs +1 -0
- package/lib/cjs/overrides/index.cjs.map +1 -0
- package/lib/cjs/overrides/overrides.cjs +20 -19
- package/lib/cjs/overrides/overrides.cjs.map +1 -0
- package/lib/cjs/overrides/types.cjs +1 -0
- package/lib/cjs/overrides/types.cjs.map +1 -0
- package/lib/cjs/types/index.cjs +1 -0
- package/lib/cjs/types/index.cjs.map +1 -0
- package/lib/cjs/types/validation.cjs +1 -0
- package/lib/cjs/types/{validation.js.map → validation.cjs.map} +1 -1
- package/lib/cjs/utils/DateBuilder.cjs +1 -0
- package/lib/cjs/utils/DateBuilder.cjs.map +1 -0
- package/lib/cjs/utils/PathProxy.cjs +9 -8
- package/lib/cjs/utils/PathProxy.cjs.map +1 -0
- package/lib/cjs/utils/constants.cjs +2 -21
- package/lib/cjs/utils/constants.cjs.map +1 -0
- package/lib/cjs/utils/dates.cjs +9 -8
- package/lib/cjs/utils/dates.cjs.map +1 -0
- package/lib/cjs/utils/equality.cjs +1 -0
- package/lib/cjs/utils/equality.cjs.map +1 -0
- package/lib/cjs/utils/hashing.cjs +6 -3
- package/lib/cjs/utils/hashing.cjs.map +1 -0
- package/lib/cjs/utils/index.cjs +1 -0
- package/lib/cjs/utils/index.cjs.map +1 -0
- package/lib/cjs/utils/registry.cjs +1 -0
- package/lib/cjs/utils/registry.cjs.map +1 -0
- package/lib/cjs/utils/serialization.cjs +3 -2
- package/lib/cjs/utils/serialization.cjs.map +1 -0
- package/lib/cjs/utils/serializers.cjs +8 -7
- package/lib/cjs/utils/serializers.cjs.map +1 -0
- package/lib/cjs/utils/strings.cjs +1 -0
- package/lib/cjs/utils/strings.cjs.map +1 -0
- package/lib/cjs/utils/types.cjs +1 -0
- package/lib/cjs/utils/types.cjs.map +1 -0
- package/lib/cjs/validation/Validation.cjs +9 -8
- package/lib/cjs/validation/Validation.cjs.map +1 -0
- package/lib/cjs/validation/Validators/AsyncValidator.cjs +5 -4
- package/lib/cjs/validation/Validators/AsyncValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/BaseValidator.cjs +8 -7
- package/lib/cjs/validation/Validators/BaseValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/DateValidator.cjs +17 -11
- package/lib/cjs/validation/Validators/DateValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/DiffValidator.cjs +21 -15
- package/lib/cjs/validation/Validators/DiffValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/EmailValidator.cjs +18 -12
- package/lib/cjs/validation/Validators/EmailValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/EqualsValidator.cjs +21 -15
- package/lib/cjs/validation/Validators/EqualsValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/GreaterThanOrEqualValidator.cjs +24 -18
- package/lib/cjs/validation/Validators/GreaterThanOrEqualValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/GreaterThanValidator.cjs +21 -15
- package/lib/cjs/validation/Validators/GreaterThanValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/LessThanOrEqualValidator.cjs +24 -18
- package/lib/cjs/validation/Validators/LessThanOrEqualValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/LessThanValidator.cjs +21 -15
- package/lib/cjs/validation/Validators/LessThanValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/ListValidator.cjs +17 -11
- package/lib/cjs/validation/Validators/ListValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/MaxLengthValidator.cjs +19 -13
- package/lib/cjs/validation/Validators/MaxLengthValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/MaxValidator.cjs +17 -11
- package/lib/cjs/validation/Validators/MaxValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/MinLengthValidator.cjs +19 -13
- package/lib/cjs/validation/Validators/MinLengthValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/MinValidator.cjs +17 -11
- package/lib/cjs/validation/Validators/MinValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/OptionValidator.cjs +17 -11
- package/lib/cjs/validation/Validators/OptionValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/PasswordValidator.cjs +18 -12
- package/lib/cjs/validation/Validators/PasswordValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/PatternValidator.cjs +17 -11
- package/lib/cjs/validation/Validators/PatternValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/RequiredValidator.cjs +17 -11
- package/lib/cjs/validation/Validators/RequiredValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/StepValidator.cjs +17 -11
- package/lib/cjs/validation/Validators/StepValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/TypeValidator.cjs +23 -17
- package/lib/cjs/validation/Validators/TypeValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/URLValidator.cjs +18 -12
- package/lib/cjs/validation/Validators/URLValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/Validator.cjs +5 -4
- package/lib/cjs/validation/Validators/Validator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/ValidatorRegistry.cjs +4 -3
- package/lib/cjs/validation/Validators/ValidatorRegistry.cjs.map +1 -0
- package/lib/cjs/validation/Validators/constants.cjs +3 -2
- package/lib/cjs/validation/Validators/constants.cjs.map +1 -0
- package/lib/cjs/validation/Validators/decorators.cjs +5 -4
- package/lib/cjs/validation/Validators/decorators.cjs.map +1 -0
- package/lib/cjs/validation/Validators/index.cjs +1 -0
- package/lib/cjs/validation/Validators/index.cjs.map +1 -0
- package/lib/cjs/validation/Validators/utils.cjs +14 -13
- package/lib/cjs/validation/Validators/utils.cjs.map +1 -0
- package/lib/cjs/validation/decorators.cjs +70 -69
- package/lib/cjs/validation/decorators.cjs.map +1 -0
- package/lib/cjs/validation/index.cjs +1 -0
- package/lib/cjs/validation/index.cjs.map +1 -0
- package/lib/cjs/validation/types.cjs +2 -1
- package/lib/cjs/validation/types.cjs.map +1 -0
- package/lib/esm/index.js +1 -1
- package/lib/types/constants/errors.d.cts +17 -0
- package/lib/types/constants/errors.d.mts +17 -0
- package/lib/types/constants/index.d.cts +2 -0
- package/lib/types/constants/index.d.mts +2 -0
- package/lib/types/constants/validation.d.cts +16 -0
- package/lib/types/constants/validation.d.mts +16 -0
- package/lib/types/index.d.cts +20 -0
- package/lib/types/index.d.mts +20 -0
- package/lib/types/index.d.ts +1 -1
- package/lib/types/model/Builder.d.cts +86 -0
- package/lib/types/model/Builder.d.mts +86 -0
- package/lib/types/model/Model.d.cts +286 -0
- package/lib/types/model/Model.d.mts +286 -0
- package/lib/types/model/ModelErrorDefinition.d.cts +22 -0
- package/lib/types/model/ModelErrorDefinition.d.mts +22 -0
- package/lib/types/model/ModelRegistry.d.cts +181 -0
- package/lib/types/model/ModelRegistry.d.mts +181 -0
- package/lib/types/model/constants.d.cts +65 -0
- package/lib/types/model/constants.d.mts +65 -0
- package/lib/types/model/construction.d.cts +46 -0
- package/lib/types/model/construction.d.mts +46 -0
- package/lib/types/model/decorators.d.cts +47 -0
- package/lib/types/model/decorators.d.mts +47 -0
- package/lib/types/model/index.d.cts +10 -0
- package/lib/types/model/index.d.mts +10 -0
- package/lib/types/model/types.d.cts +145 -0
- package/lib/types/model/types.d.mts +145 -0
- package/lib/types/model/utils.d.cts +13 -0
- package/lib/types/model/utils.d.mts +13 -0
- package/lib/types/model/validation.d.cts +92 -0
- package/lib/types/model/validation.d.mts +92 -0
- package/lib/types/overrides/Metadata.d.cts +132 -0
- package/lib/types/overrides/Metadata.d.mts +132 -0
- package/lib/types/overrides/index.d.cts +4 -0
- package/lib/types/overrides/index.d.mts +4 -0
- package/lib/types/overrides/overrides.d.cts +1 -0
- package/lib/types/overrides/overrides.d.mts +1 -0
- package/lib/types/overrides/types.d.cts +17 -0
- package/lib/types/overrides/types.d.mts +17 -0
- package/lib/types/types/index.d.cts +1 -0
- package/lib/types/types/index.d.mts +1 -0
- package/lib/types/types/validation.d.cts +28 -0
- package/lib/types/types/validation.d.mts +28 -0
- package/lib/types/utils/DateBuilder.d.cts +121 -0
- package/lib/types/utils/DateBuilder.d.mts +121 -0
- package/lib/types/utils/PathProxy.d.cts +43 -0
- package/lib/types/utils/PathProxy.d.mts +43 -0
- package/lib/types/utils/constants.d.cts +32 -0
- package/lib/types/utils/constants.d.mts +32 -0
- package/lib/types/utils/dates.d.cts +86 -0
- package/lib/types/utils/dates.d.mts +86 -0
- package/lib/types/utils/equality.d.cts +56 -0
- package/lib/types/utils/equality.d.mts +56 -0
- package/lib/types/utils/hashing.d.cts +82 -0
- package/lib/types/utils/hashing.d.mts +82 -0
- package/lib/types/utils/index.d.cts +11 -0
- package/lib/types/utils/index.d.mts +11 -0
- package/lib/types/utils/registry.d.cts +68 -0
- package/lib/types/utils/registry.d.mts +68 -0
- package/lib/types/utils/serialization.d.cts +12 -0
- package/lib/types/utils/serialization.d.mts +12 -0
- package/lib/types/utils/serializers.d.cts +41 -0
- package/lib/types/utils/serializers.d.mts +41 -0
- package/lib/types/utils/strings.d.cts +25 -0
- package/lib/types/utils/strings.d.mts +25 -0
- package/lib/types/utils/types.d.cts +35 -0
- package/lib/types/utils/types.d.mts +35 -0
- package/lib/types/validation/Validation.d.cts +53 -0
- package/lib/types/validation/Validation.d.mts +53 -0
- package/lib/types/validation/Validators/AsyncValidator.d.cts +72 -0
- package/lib/types/validation/Validators/AsyncValidator.d.mts +72 -0
- package/lib/types/validation/Validators/BaseValidator.d.cts +118 -0
- package/lib/types/validation/Validators/BaseValidator.d.mts +118 -0
- package/lib/types/validation/Validators/DateValidator.d.cts +60 -0
- package/lib/types/validation/Validators/DateValidator.d.mts +60 -0
- package/lib/types/validation/Validators/DiffValidator.d.cts +29 -0
- package/lib/types/validation/Validators/DiffValidator.d.mts +29 -0
- package/lib/types/validation/Validators/EmailValidator.d.cts +60 -0
- package/lib/types/validation/Validators/EmailValidator.d.mts +60 -0
- package/lib/types/validation/Validators/EqualsValidator.d.cts +29 -0
- package/lib/types/validation/Validators/EqualsValidator.d.mts +29 -0
- package/lib/types/validation/Validators/GreaterThanOrEqualValidator.d.cts +29 -0
- package/lib/types/validation/Validators/GreaterThanOrEqualValidator.d.mts +29 -0
- package/lib/types/validation/Validators/GreaterThanValidator.d.cts +29 -0
- package/lib/types/validation/Validators/GreaterThanValidator.d.mts +29 -0
- package/lib/types/validation/Validators/LessThanOrEqualValidator.d.cts +29 -0
- package/lib/types/validation/Validators/LessThanOrEqualValidator.d.mts +29 -0
- package/lib/types/validation/Validators/LessThanValidator.d.cts +29 -0
- package/lib/types/validation/Validators/LessThanValidator.d.mts +29 -0
- package/lib/types/validation/Validators/ListValidator.d.cts +66 -0
- package/lib/types/validation/Validators/ListValidator.d.mts +66 -0
- package/lib/types/validation/Validators/MaxLengthValidator.d.cts +29 -0
- package/lib/types/validation/Validators/MaxLengthValidator.d.mts +29 -0
- package/lib/types/validation/Validators/MaxValidator.d.cts +74 -0
- package/lib/types/validation/Validators/MaxValidator.d.mts +74 -0
- package/lib/types/validation/Validators/MinLengthValidator.d.cts +29 -0
- package/lib/types/validation/Validators/MinLengthValidator.d.mts +29 -0
- package/lib/types/validation/Validators/MinValidator.d.cts +74 -0
- package/lib/types/validation/Validators/MinValidator.d.mts +74 -0
- package/lib/types/validation/Validators/OptionValidator.d.cts +29 -0
- package/lib/types/validation/Validators/OptionValidator.d.mts +29 -0
- package/lib/types/validation/Validators/PasswordValidator.d.cts +28 -0
- package/lib/types/validation/Validators/PasswordValidator.d.mts +28 -0
- package/lib/types/validation/Validators/PatternValidator.d.cts +103 -0
- package/lib/types/validation/Validators/PatternValidator.d.mts +103 -0
- package/lib/types/validation/Validators/RequiredValidator.d.cts +74 -0
- package/lib/types/validation/Validators/RequiredValidator.d.mts +74 -0
- package/lib/types/validation/Validators/StepValidator.d.cts +29 -0
- package/lib/types/validation/Validators/StepValidator.d.mts +29 -0
- package/lib/types/validation/Validators/TypeValidator.d.cts +79 -0
- package/lib/types/validation/Validators/TypeValidator.d.mts +79 -0
- package/lib/types/validation/Validators/URLValidator.d.cts +61 -0
- package/lib/types/validation/Validators/URLValidator.d.mts +61 -0
- package/lib/types/validation/Validators/Validator.d.cts +65 -0
- package/lib/types/validation/Validators/Validator.d.mts +65 -0
- package/lib/types/validation/Validators/ValidatorRegistry.d.cts +41 -0
- package/lib/types/validation/Validators/ValidatorRegistry.d.mts +41 -0
- package/lib/types/validation/Validators/constants.d.cts +157 -0
- package/lib/types/validation/Validators/constants.d.mts +157 -0
- package/lib/types/validation/Validators/decorators.d.cts +12 -0
- package/lib/types/validation/Validators/decorators.d.mts +12 -0
- package/lib/types/validation/Validators/index.d.cts +26 -0
- package/lib/types/validation/Validators/index.d.mts +26 -0
- package/lib/types/validation/Validators/utils.d.cts +75 -0
- package/lib/types/validation/Validators/utils.d.mts +75 -0
- package/lib/types/validation/decorators.d.cts +313 -0
- package/lib/types/validation/decorators.d.mts +313 -0
- package/lib/types/validation/index.d.cts +9 -0
- package/lib/types/validation/index.d.mts +9 -0
- package/lib/types/validation/types.d.cts +309 -0
- package/lib/types/validation/types.d.mts +309 -0
- package/package.json +1 -1
- package/lib/cjs/constants/errors.js.map +0 -1
- package/lib/cjs/constants/index.js.map +0 -1
- package/lib/cjs/constants/validation.js.map +0 -1
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/model/Builder.js.map +0 -1
- package/lib/cjs/model/Model.js.map +0 -1
- package/lib/cjs/model/ModelErrorDefinition.js.map +0 -1
- package/lib/cjs/model/ModelRegistry.js.map +0 -1
- package/lib/cjs/model/constants.js.map +0 -1
- package/lib/cjs/model/construction.js.map +0 -1
- package/lib/cjs/model/decorators.js.map +0 -1
- package/lib/cjs/model/index.js.map +0 -1
- package/lib/cjs/model/types.js.map +0 -1
- package/lib/cjs/model/utils.js.map +0 -1
- package/lib/cjs/model/validation.js.map +0 -1
- package/lib/cjs/overrides/Metadata.js.map +0 -1
- package/lib/cjs/overrides/index.js.map +0 -1
- package/lib/cjs/overrides/overrides.js.map +0 -1
- package/lib/cjs/overrides/types.js.map +0 -1
- package/lib/cjs/types/index.js.map +0 -1
- package/lib/cjs/utils/DateBuilder.js.map +0 -1
- package/lib/cjs/utils/PathProxy.js.map +0 -1
- package/lib/cjs/utils/constants.js.map +0 -1
- package/lib/cjs/utils/dates.js.map +0 -1
- package/lib/cjs/utils/equality.js.map +0 -1
- package/lib/cjs/utils/hashing.js.map +0 -1
- package/lib/cjs/utils/index.js.map +0 -1
- package/lib/cjs/utils/registry.js.map +0 -1
- package/lib/cjs/utils/serialization.js.map +0 -1
- package/lib/cjs/utils/serializers.js.map +0 -1
- package/lib/cjs/utils/strings.js.map +0 -1
- package/lib/cjs/utils/types.js.map +0 -1
- package/lib/cjs/validation/Validation.js.map +0 -1
- package/lib/cjs/validation/Validators/AsyncValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/BaseValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/DateValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/DiffValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/EmailValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/EqualsValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/GreaterThanOrEqualValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/GreaterThanValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/LessThanOrEqualValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/LessThanValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/ListValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/MaxLengthValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/MaxValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/MinLengthValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/MinValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/OptionValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/PasswordValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/PatternValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/RequiredValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/StepValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/TypeValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/URLValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/Validator.js.map +0 -1
- package/lib/cjs/validation/Validators/ValidatorRegistry.js.map +0 -1
- package/lib/cjs/validation/Validators/constants.js.map +0 -1
- package/lib/cjs/validation/Validators/decorators.js.map +0 -1
- package/lib/cjs/validation/Validators/index.js.map +0 -1
- package/lib/cjs/validation/Validators/utils.js.map +0 -1
- package/lib/cjs/validation/decorators.js.map +0 -1
- package/lib/cjs/validation/index.js.map +0 -1
- package/lib/cjs/validation/types.js.map +0 -1
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { Model } from "../model/Model.cjs";
|
|
2
|
+
import "@decaf-ts/decoration";
|
|
3
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
4
|
+
import { designTypeReturn, ExtendedMetadata } from "./types.cjs";
|
|
5
|
+
import { ValidationMetadata } from "../validation/types.cjs";
|
|
6
|
+
declare module "@decaf-ts/decoration" {
|
|
7
|
+
namespace Metadata {
|
|
8
|
+
/**
|
|
9
|
+
* @description Retrieves validation metadata for a specific property of a model
|
|
10
|
+
* @summary Fetches validation rules and constraints that were applied to a property
|
|
11
|
+
* via decorators. The optional key parameter allows drilling down to specific
|
|
12
|
+
* validation types (e.g., 'required', 'min', 'max').
|
|
13
|
+
*
|
|
14
|
+
* @template M - The model type extending from Model
|
|
15
|
+
* @param {Constructor<M>} model - The constructor of the target model class
|
|
16
|
+
* @param {keyof M} property - The property name to retrieve validation for
|
|
17
|
+
* @param {string} [key] - Optional specific validation key to retrieve (e.g., 'required', 'pattern')
|
|
18
|
+
* @return {any} The validation metadata object or value at the specified key
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* class User extends Model {
|
|
22
|
+
* @required()
|
|
23
|
+
* @maxLength(100)
|
|
24
|
+
* name!: string;
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* // Get all validation metadata for 'name'
|
|
28
|
+
* const validations = Metadata.validationFor(User, 'name');
|
|
29
|
+
*
|
|
30
|
+
* // Get specific validation metadata
|
|
31
|
+
* const required = Metadata.validationFor(User, 'name', 'required');
|
|
32
|
+
*/
|
|
33
|
+
function validationFor<M extends Model, P extends keyof M = keyof M, K extends string = string>(this: Metadata, model: Constructor<M>, property?: keyof M, key?: string): (K extends string ? ValidationMetadata : P extends keyof M ? Record<string, ValidationMetadata> : Record<keyof M, Record<string, ValidationMetadata>>) | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* @description Retrieves all validatable for a model
|
|
36
|
+
* @param model
|
|
37
|
+
*/
|
|
38
|
+
function validatableProperties<M extends Model>(model: Constructor<M>, ...propsToIgnore: string[]): string[];
|
|
39
|
+
/**
|
|
40
|
+
* @description Retrieves extended metadata for a model or a specific key within it
|
|
41
|
+
* @summary When called with a constructor only, returns the entire metadata object
|
|
42
|
+
* associated with the model, including validation rules, property types, relationships,
|
|
43
|
+
* and other decorator-applied metadata. This override extends the base Metadata.get
|
|
44
|
+
* method with type-safe support for ExtendedMetadata.
|
|
45
|
+
*
|
|
46
|
+
* @template M - The model type
|
|
47
|
+
* @template META - The extended metadata type, defaults to ExtendedMetadata<M>
|
|
48
|
+
* @param {Constructor<M>} model - The target constructor used to locate the metadata record
|
|
49
|
+
* @param {keyof M} prop - Optional property of the model.
|
|
50
|
+
* @return {META|undefined} The complete metadata object for the model, or undefined if no metadata exists
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* class Article extends Model {
|
|
54
|
+
* @pk()
|
|
55
|
+
* @type(Number)
|
|
56
|
+
* id!: number;
|
|
57
|
+
*
|
|
58
|
+
* @required()
|
|
59
|
+
* @maxLength(200)
|
|
60
|
+
* title!: string;
|
|
61
|
+
*
|
|
62
|
+
* @oneToMany(() => Comment, { update: true, delete: true }, true)
|
|
63
|
+
* comments!: Comment[];
|
|
64
|
+
* }
|
|
65
|
+
*
|
|
66
|
+
* // Get all metadata for the Article model
|
|
67
|
+
* const metadata = Metadata.get<Article>(Article);
|
|
68
|
+
* // metadata contains:
|
|
69
|
+
* // - property definitions
|
|
70
|
+
* // - validation rules
|
|
71
|
+
* // - relationship mappings
|
|
72
|
+
* // - primary key information
|
|
73
|
+
* // - column mappings
|
|
74
|
+
*
|
|
75
|
+
* @remarks
|
|
76
|
+
* The @ts-expect-error directive is used because this declaration intentionally
|
|
77
|
+
* overrides the signature from the base module to provide enhanced type information
|
|
78
|
+
* specific to the decorator-validation system.
|
|
79
|
+
*/
|
|
80
|
+
function get<M, META extends ExtendedMetadata<M> = ExtendedMetadata<M>>(model: Constructor<M>, prop?: keyof M): META | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* @description Retrieves the original constructor name for a model
|
|
83
|
+
* @summary Fetches the original constructor name for a model from the metadata of a model.
|
|
84
|
+
*
|
|
85
|
+
* @template M - The model type extending from Model
|
|
86
|
+
* @param {Constructor<M>} model - The constructor of the target model class
|
|
87
|
+
* @return {string} The metadata object or value
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* class User extends Model {
|
|
91
|
+
*
|
|
92
|
+
* // Get the constructor name for 'User'
|
|
93
|
+
* const constName = Metadata.modelName(User);
|
|
94
|
+
*/
|
|
95
|
+
function modelName<M>(model: Constructor<M>): string;
|
|
96
|
+
/**
|
|
97
|
+
* @description Retrieves all allowed types for a model or a property
|
|
98
|
+
* @summary Retrieves all allowed types for a model or a property from it's metadata.
|
|
99
|
+
*
|
|
100
|
+
* @template M - The model type extending from Model
|
|
101
|
+
* @param {Constructor<M>} model - The constructor of the target model class
|
|
102
|
+
* @param {keyof M} property - The property name to retrieve validation for
|
|
103
|
+
* @return {any[]} An array of the allowed types
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* class User extends Model {
|
|
107
|
+
*
|
|
108
|
+
* // Get all validation metadata for 'User'
|
|
109
|
+
* const allowedTypes = Metadata.meallowedTypestadata(User);
|
|
110
|
+
*/
|
|
111
|
+
function allowedTypes<M>(model: Constructor<M>, property?: keyof M): any[];
|
|
112
|
+
/**
|
|
113
|
+
* @description Retrieves all allowed types for a model or a property
|
|
114
|
+
* @summary Retrieves all allowed types for a model or a property from it's metadata.
|
|
115
|
+
*
|
|
116
|
+
* @template model - The model type extending from Model
|
|
117
|
+
* @param {Constructor<M>} model - The constructor of the target model class
|
|
118
|
+
* @param {keyof M} property - The property name to retrieve validation for
|
|
119
|
+
* @return {designTypeReturn} An object of the designtypes
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* class User extends Model {
|
|
123
|
+
*
|
|
124
|
+
* // Get the designtypes for property name
|
|
125
|
+
* const { designTypes, designType } = Metadata.getPropDesignTypes(User.constructor, 'name');
|
|
126
|
+
*/
|
|
127
|
+
function getPropDesignTypes<M>(model: Constructor<M>, property: keyof M): designTypeReturn;
|
|
128
|
+
function isModel(target: Record<string, any>): boolean;
|
|
129
|
+
function isPropertyModel<M extends Model>(target: M, attribute: string): boolean | string | undefined;
|
|
130
|
+
function getAttributes<V extends Model>(model: Constructor<V> | V): string[];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { Model } from "../model/Model.js";
|
|
2
|
+
import "@decaf-ts/decoration";
|
|
3
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
4
|
+
import { designTypeReturn, ExtendedMetadata } from "./types.js";
|
|
5
|
+
import { ValidationMetadata } from "../validation/types.js";
|
|
6
|
+
declare module "@decaf-ts/decoration" {
|
|
7
|
+
namespace Metadata {
|
|
8
|
+
/**
|
|
9
|
+
* @description Retrieves validation metadata for a specific property of a model
|
|
10
|
+
* @summary Fetches validation rules and constraints that were applied to a property
|
|
11
|
+
* via decorators. The optional key parameter allows drilling down to specific
|
|
12
|
+
* validation types (e.g., 'required', 'min', 'max').
|
|
13
|
+
*
|
|
14
|
+
* @template M - The model type extending from Model
|
|
15
|
+
* @param {Constructor<M>} model - The constructor of the target model class
|
|
16
|
+
* @param {keyof M} property - The property name to retrieve validation for
|
|
17
|
+
* @param {string} [key] - Optional specific validation key to retrieve (e.g., 'required', 'pattern')
|
|
18
|
+
* @return {any} The validation metadata object or value at the specified key
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* class User extends Model {
|
|
22
|
+
* @required()
|
|
23
|
+
* @maxLength(100)
|
|
24
|
+
* name!: string;
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* // Get all validation metadata for 'name'
|
|
28
|
+
* const validations = Metadata.validationFor(User, 'name');
|
|
29
|
+
*
|
|
30
|
+
* // Get specific validation metadata
|
|
31
|
+
* const required = Metadata.validationFor(User, 'name', 'required');
|
|
32
|
+
*/
|
|
33
|
+
function validationFor<M extends Model, P extends keyof M = keyof M, K extends string = string>(this: Metadata, model: Constructor<M>, property?: keyof M, key?: string): (K extends string ? ValidationMetadata : P extends keyof M ? Record<string, ValidationMetadata> : Record<keyof M, Record<string, ValidationMetadata>>) | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* @description Retrieves all validatable for a model
|
|
36
|
+
* @param model
|
|
37
|
+
*/
|
|
38
|
+
function validatableProperties<M extends Model>(model: Constructor<M>, ...propsToIgnore: string[]): string[];
|
|
39
|
+
/**
|
|
40
|
+
* @description Retrieves extended metadata for a model or a specific key within it
|
|
41
|
+
* @summary When called with a constructor only, returns the entire metadata object
|
|
42
|
+
* associated with the model, including validation rules, property types, relationships,
|
|
43
|
+
* and other decorator-applied metadata. This override extends the base Metadata.get
|
|
44
|
+
* method with type-safe support for ExtendedMetadata.
|
|
45
|
+
*
|
|
46
|
+
* @template M - The model type
|
|
47
|
+
* @template META - The extended metadata type, defaults to ExtendedMetadata<M>
|
|
48
|
+
* @param {Constructor<M>} model - The target constructor used to locate the metadata record
|
|
49
|
+
* @param {keyof M} prop - Optional property of the model.
|
|
50
|
+
* @return {META|undefined} The complete metadata object for the model, or undefined if no metadata exists
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* class Article extends Model {
|
|
54
|
+
* @pk()
|
|
55
|
+
* @type(Number)
|
|
56
|
+
* id!: number;
|
|
57
|
+
*
|
|
58
|
+
* @required()
|
|
59
|
+
* @maxLength(200)
|
|
60
|
+
* title!: string;
|
|
61
|
+
*
|
|
62
|
+
* @oneToMany(() => Comment, { update: true, delete: true }, true)
|
|
63
|
+
* comments!: Comment[];
|
|
64
|
+
* }
|
|
65
|
+
*
|
|
66
|
+
* // Get all metadata for the Article model
|
|
67
|
+
* const metadata = Metadata.get<Article>(Article);
|
|
68
|
+
* // metadata contains:
|
|
69
|
+
* // - property definitions
|
|
70
|
+
* // - validation rules
|
|
71
|
+
* // - relationship mappings
|
|
72
|
+
* // - primary key information
|
|
73
|
+
* // - column mappings
|
|
74
|
+
*
|
|
75
|
+
* @remarks
|
|
76
|
+
* The @ts-expect-error directive is used because this declaration intentionally
|
|
77
|
+
* overrides the signature from the base module to provide enhanced type information
|
|
78
|
+
* specific to the decorator-validation system.
|
|
79
|
+
*/
|
|
80
|
+
function get<M, META extends ExtendedMetadata<M> = ExtendedMetadata<M>>(model: Constructor<M>, prop?: keyof M): META | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* @description Retrieves the original constructor name for a model
|
|
83
|
+
* @summary Fetches the original constructor name for a model from the metadata of a model.
|
|
84
|
+
*
|
|
85
|
+
* @template M - The model type extending from Model
|
|
86
|
+
* @param {Constructor<M>} model - The constructor of the target model class
|
|
87
|
+
* @return {string} The metadata object or value
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* class User extends Model {
|
|
91
|
+
*
|
|
92
|
+
* // Get the constructor name for 'User'
|
|
93
|
+
* const constName = Metadata.modelName(User);
|
|
94
|
+
*/
|
|
95
|
+
function modelName<M>(model: Constructor<M>): string;
|
|
96
|
+
/**
|
|
97
|
+
* @description Retrieves all allowed types for a model or a property
|
|
98
|
+
* @summary Retrieves all allowed types for a model or a property from it's metadata.
|
|
99
|
+
*
|
|
100
|
+
* @template M - The model type extending from Model
|
|
101
|
+
* @param {Constructor<M>} model - The constructor of the target model class
|
|
102
|
+
* @param {keyof M} property - The property name to retrieve validation for
|
|
103
|
+
* @return {any[]} An array of the allowed types
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* class User extends Model {
|
|
107
|
+
*
|
|
108
|
+
* // Get all validation metadata for 'User'
|
|
109
|
+
* const allowedTypes = Metadata.meallowedTypestadata(User);
|
|
110
|
+
*/
|
|
111
|
+
function allowedTypes<M>(model: Constructor<M>, property?: keyof M): any[];
|
|
112
|
+
/**
|
|
113
|
+
* @description Retrieves all allowed types for a model or a property
|
|
114
|
+
* @summary Retrieves all allowed types for a model or a property from it's metadata.
|
|
115
|
+
*
|
|
116
|
+
* @template model - The model type extending from Model
|
|
117
|
+
* @param {Constructor<M>} model - The constructor of the target model class
|
|
118
|
+
* @param {keyof M} property - The property name to retrieve validation for
|
|
119
|
+
* @return {designTypeReturn} An object of the designtypes
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* class User extends Model {
|
|
123
|
+
*
|
|
124
|
+
* // Get the designtypes for property name
|
|
125
|
+
* const { designTypes, designType } = Metadata.getPropDesignTypes(User.constructor, 'name');
|
|
126
|
+
*/
|
|
127
|
+
function getPropDesignTypes<M>(model: Constructor<M>, property: keyof M): designTypeReturn;
|
|
128
|
+
function isModel(target: Record<string, any>): boolean;
|
|
129
|
+
function isPropertyModel<M extends Model>(target: M, attribute: string): boolean | string | undefined;
|
|
130
|
+
function getAttributes<V extends Model>(model: Constructor<V> | V): string[];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./Metadata";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./Metadata";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BasicMetadata } from "@decaf-ts/decoration";
|
|
2
|
+
import { ValidatorOptions } from "../validation/types.cjs";
|
|
3
|
+
export type ExtendedMetadata<M> = BasicMetadata<M> & {
|
|
4
|
+
validation: Record<keyof M, ValidatorOptions>;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* @description Return type for design type information.
|
|
8
|
+
* @summary Defines the structure of the return type for functions that provide design type information.
|
|
9
|
+
* @property {any[]} designTypes An array of design types.
|
|
10
|
+
* @property {any} designType The primary design type.
|
|
11
|
+
* @typedef {object} designTypeReturn
|
|
12
|
+
* @memberOf module:decorator-validation
|
|
13
|
+
*/
|
|
14
|
+
export type designTypeReturn = {
|
|
15
|
+
designTypes: any[];
|
|
16
|
+
designType: any;
|
|
17
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BasicMetadata } from "@decaf-ts/decoration";
|
|
2
|
+
import { ValidatorOptions } from "../validation/types.js";
|
|
3
|
+
export type ExtendedMetadata<M> = BasicMetadata<M> & {
|
|
4
|
+
validation: Record<keyof M, ValidatorOptions>;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* @description Return type for design type information.
|
|
8
|
+
* @summary Defines the structure of the return type for functions that provide design type information.
|
|
9
|
+
* @property {any[]} designTypes An array of design types.
|
|
10
|
+
* @property {any} designType The primary design type.
|
|
11
|
+
* @typedef {object} designTypeReturn
|
|
12
|
+
* @memberOf module:decorator-validation
|
|
13
|
+
*/
|
|
14
|
+
export type designTypeReturn = {
|
|
15
|
+
designTypes: any[];
|
|
16
|
+
designType: any;
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./validation.cjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./validation.js";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Model } from "../model/Model.cjs";
|
|
2
|
+
import { ModelErrorDefinition } from "../model/ModelErrorDefinition.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* @description Conditionally wraps a type in a `Promise` based on the `Async` flag.
|
|
5
|
+
* @summary Utility type that resolves to `T` if `Async` is `false`, or to `Promise<T>` if `Async` is `true`.
|
|
6
|
+
* Used to abstract the return type of functions that may be either synchronous or asynchronous depending on a flag.
|
|
7
|
+
*
|
|
8
|
+
* @template Async A boolean flag indicating whether the result should be asynchronous (`true`) or synchronous (`false`).
|
|
9
|
+
* @template T The base type to return directly or to wrap in a `Promise`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // Synchronous result
|
|
14
|
+
* type SyncResult: string | number = ConditionalAsync<false, string | number>;
|
|
15
|
+
*
|
|
16
|
+
* // Asynchronous result
|
|
17
|
+
* type AsyncResult: Promise<string | number> = ConditionalAsync<true, string | number>;
|
|
18
|
+
* ```
|
|
19
|
+
* @memberOf module:decorator-validation
|
|
20
|
+
*/
|
|
21
|
+
export type ConditionalAsync<Async extends boolean, T> = Async extends true ? Promise<T> : T;
|
|
22
|
+
export type DecoratorMetadataAsync = {
|
|
23
|
+
async?: boolean;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* @deprecated
|
|
27
|
+
*/
|
|
28
|
+
export type ModelConditionalAsync<M> = M extends Model<true> ? Promise<ModelErrorDefinition | undefined> : ModelErrorDefinition | undefined;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Model } from "../model/Model.js";
|
|
2
|
+
import { ModelErrorDefinition } from "../model/ModelErrorDefinition.js";
|
|
3
|
+
/**
|
|
4
|
+
* @description Conditionally wraps a type in a `Promise` based on the `Async` flag.
|
|
5
|
+
* @summary Utility type that resolves to `T` if `Async` is `false`, or to `Promise<T>` if `Async` is `true`.
|
|
6
|
+
* Used to abstract the return type of functions that may be either synchronous or asynchronous depending on a flag.
|
|
7
|
+
*
|
|
8
|
+
* @template Async A boolean flag indicating whether the result should be asynchronous (`true`) or synchronous (`false`).
|
|
9
|
+
* @template T The base type to return directly or to wrap in a `Promise`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // Synchronous result
|
|
14
|
+
* type SyncResult: string | number = ConditionalAsync<false, string | number>;
|
|
15
|
+
*
|
|
16
|
+
* // Asynchronous result
|
|
17
|
+
* type AsyncResult: Promise<string | number> = ConditionalAsync<true, string | number>;
|
|
18
|
+
* ```
|
|
19
|
+
* @memberOf module:decorator-validation
|
|
20
|
+
*/
|
|
21
|
+
export type ConditionalAsync<Async extends boolean, T> = Async extends true ? Promise<T> : T;
|
|
22
|
+
export type DecoratorMetadataAsync = {
|
|
23
|
+
async?: boolean;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* @deprecated
|
|
27
|
+
*/
|
|
28
|
+
export type ModelConditionalAsync<M> = M extends Model<true> ? Promise<ModelErrorDefinition | undefined> : ModelErrorDefinition | undefined;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
type DateBuilderField = "Years" | "Months" | "Days" | "Hours" | "Minutes" | "Seconds";
|
|
2
|
+
export type DateBuilderInstance = DateBuilder<DateBuilderField>;
|
|
3
|
+
export type DateTarget = Date | DateBuilderInstance;
|
|
4
|
+
export type OffsetValues = {
|
|
5
|
+
years: number;
|
|
6
|
+
months: number;
|
|
7
|
+
days: number;
|
|
8
|
+
hours: number;
|
|
9
|
+
minutes: number;
|
|
10
|
+
seconds: number;
|
|
11
|
+
};
|
|
12
|
+
export declare function offsetDate(date: Date, direction: 1 | -1, values: OffsetValues): Date;
|
|
13
|
+
type RemoveField<Input extends DateBuilderField, Field extends DateBuilderField> = Input extends Field ? never : Input;
|
|
14
|
+
interface DateBuilderUtilityMethods {
|
|
15
|
+
Now(): Date;
|
|
16
|
+
Tomorrow(): Date;
|
|
17
|
+
Yesterday(): Date;
|
|
18
|
+
DaysAgo(count: number): Date;
|
|
19
|
+
NextDays(count: number): Date;
|
|
20
|
+
YearsAgo(count: number): Date;
|
|
21
|
+
NextYears(count: number): Date;
|
|
22
|
+
MonthsAgo(count: number): Date;
|
|
23
|
+
NextMonths(count: number): Date;
|
|
24
|
+
HoursAgo(count: number): Date;
|
|
25
|
+
NextHours(count: number): Date;
|
|
26
|
+
MinutesAgo(count: number): Date;
|
|
27
|
+
NextMinutes(count: number): Date;
|
|
28
|
+
SecondsAgo(count: number): Date;
|
|
29
|
+
NextSeconds(count: number): Date;
|
|
30
|
+
}
|
|
31
|
+
interface DateBuilderCoreMethods extends DateBuilderUtilityMethods {
|
|
32
|
+
build(reference?: DateTarget): Date;
|
|
33
|
+
from(reference: DateTarget): Date;
|
|
34
|
+
past(reference: DateTarget): Date;
|
|
35
|
+
after(reference: DateTarget): Date;
|
|
36
|
+
until(reference: DateTarget): Date;
|
|
37
|
+
before(reference: DateTarget): Date;
|
|
38
|
+
ago(reference?: DateTarget): Date;
|
|
39
|
+
}
|
|
40
|
+
export type DateBuilderChain<Remaining extends DateBuilderField = DateBuilderField> = DateBuilderCoreMethods & {
|
|
41
|
+
[Field in Remaining]: (value: number) => DateBuilderChain<RemoveField<Remaining, Field>>;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Fluent builder for producing dates relative to a reference point.
|
|
45
|
+
*/
|
|
46
|
+
export declare class DateBuilder<Remaining extends DateBuilderField = DateBuilderField> implements DateBuilderCoreMethods {
|
|
47
|
+
private years;
|
|
48
|
+
private months;
|
|
49
|
+
private days;
|
|
50
|
+
private hours;
|
|
51
|
+
private minutes;
|
|
52
|
+
private seconds;
|
|
53
|
+
private constructor();
|
|
54
|
+
static Years(value: number): DateBuilderChain<RemoveField<DateBuilderField, "Years">>;
|
|
55
|
+
static Months(value: number): DateBuilderChain<RemoveField<DateBuilderField, "Months">>;
|
|
56
|
+
static Days(value: number): DateBuilderChain<RemoveField<DateBuilderField, "Days">>;
|
|
57
|
+
static Hours(value: number): DateBuilderChain<RemoveField<DateBuilderField, "Hours">>;
|
|
58
|
+
static Minutes(value: number): DateBuilderChain<RemoveField<DateBuilderField, "Minutes">>;
|
|
59
|
+
static Seconds(value: number): DateBuilderChain<RemoveField<DateBuilderField, "Seconds">>;
|
|
60
|
+
static Now(): Date;
|
|
61
|
+
static Tomorrow(): Date;
|
|
62
|
+
static Yesterday(): Date;
|
|
63
|
+
static DaysAgo(count: number): Date;
|
|
64
|
+
static NextDays(count: number): Date;
|
|
65
|
+
static YearsAgo(count: number): Date;
|
|
66
|
+
static NextYears(count: number): Date;
|
|
67
|
+
static MonthsAgo(count: number): Date;
|
|
68
|
+
static NextMonths(count: number): Date;
|
|
69
|
+
static HoursAgo(count: number): Date;
|
|
70
|
+
static NextHours(count: number): Date;
|
|
71
|
+
static MinutesAgo(count: number): Date;
|
|
72
|
+
static NextMinutes(count: number): Date;
|
|
73
|
+
static SecondsAgo(count: number): Date;
|
|
74
|
+
static NextSeconds(count: number): Date;
|
|
75
|
+
Years(value: number): DateBuilderChain<RemoveField<Remaining, "Years">>;
|
|
76
|
+
Months(value: number): DateBuilderChain<RemoveField<Remaining, "Months">>;
|
|
77
|
+
Days(value: number): DateBuilderChain<RemoveField<Remaining, "Days">>;
|
|
78
|
+
Hours(value: number): DateBuilderChain<RemoveField<Remaining, "Hours">>;
|
|
79
|
+
Minutes(value: number): DateBuilderChain<RemoveField<Remaining, "Minutes">>;
|
|
80
|
+
Seconds(value: number): DateBuilderChain<RemoveField<Remaining, "Seconds">>;
|
|
81
|
+
build(reference?: DateTarget): Date;
|
|
82
|
+
from(reference: DateTarget): Date;
|
|
83
|
+
past(reference: DateTarget): Date;
|
|
84
|
+
after(reference: DateTarget): Date;
|
|
85
|
+
until(reference: DateTarget): Date;
|
|
86
|
+
before(reference: DateTarget): Date;
|
|
87
|
+
ago(reference?: DateTarget): Date;
|
|
88
|
+
Now(): Date;
|
|
89
|
+
Tomorrow(): Date;
|
|
90
|
+
Yesterday(): Date;
|
|
91
|
+
DaysAgo(count: number): Date;
|
|
92
|
+
NextDays(count: number): Date;
|
|
93
|
+
YearsAgo(count: number): Date;
|
|
94
|
+
NextYears(count: number): Date;
|
|
95
|
+
MonthsAgo(count: number): Date;
|
|
96
|
+
NextMonths(count: number): Date;
|
|
97
|
+
HoursAgo(count: number): Date;
|
|
98
|
+
NextHours(count: number): Date;
|
|
99
|
+
MinutesAgo(count: number): Date;
|
|
100
|
+
NextMinutes(count: number): Date;
|
|
101
|
+
SecondsAgo(count: number): Date;
|
|
102
|
+
NextSeconds(count: number): Date;
|
|
103
|
+
private offsets;
|
|
104
|
+
}
|
|
105
|
+
export declare const Dates: typeof DateBuilder;
|
|
106
|
+
export declare const Now: () => Date;
|
|
107
|
+
export declare const Tomorrow: () => Date;
|
|
108
|
+
export declare const Yesterday: () => Date;
|
|
109
|
+
export declare const DaysAgo: (count: number) => Date;
|
|
110
|
+
export declare const NextDays: (count: number) => Date;
|
|
111
|
+
export declare const YearsAgo: (count: number) => Date;
|
|
112
|
+
export declare const NextYears: (count: number) => Date;
|
|
113
|
+
export declare const MonthsAgo: (count: number) => Date;
|
|
114
|
+
export declare const NextMonths: (count: number) => Date;
|
|
115
|
+
export declare const HoursAgo: (count: number) => Date;
|
|
116
|
+
export declare const NextHours: (count: number) => Date;
|
|
117
|
+
export declare const MinutesAgo: (count: number) => Date;
|
|
118
|
+
export declare const NextMinutes: (count: number) => Date;
|
|
119
|
+
export declare const SecondsAgo: (count: number) => Date;
|
|
120
|
+
export declare const NextSeconds: (count: number) => Date;
|
|
121
|
+
export {};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
type DateBuilderField = "Years" | "Months" | "Days" | "Hours" | "Minutes" | "Seconds";
|
|
2
|
+
export type DateBuilderInstance = DateBuilder<DateBuilderField>;
|
|
3
|
+
export type DateTarget = Date | DateBuilderInstance;
|
|
4
|
+
export type OffsetValues = {
|
|
5
|
+
years: number;
|
|
6
|
+
months: number;
|
|
7
|
+
days: number;
|
|
8
|
+
hours: number;
|
|
9
|
+
minutes: number;
|
|
10
|
+
seconds: number;
|
|
11
|
+
};
|
|
12
|
+
export declare function offsetDate(date: Date, direction: 1 | -1, values: OffsetValues): Date;
|
|
13
|
+
type RemoveField<Input extends DateBuilderField, Field extends DateBuilderField> = Input extends Field ? never : Input;
|
|
14
|
+
interface DateBuilderUtilityMethods {
|
|
15
|
+
Now(): Date;
|
|
16
|
+
Tomorrow(): Date;
|
|
17
|
+
Yesterday(): Date;
|
|
18
|
+
DaysAgo(count: number): Date;
|
|
19
|
+
NextDays(count: number): Date;
|
|
20
|
+
YearsAgo(count: number): Date;
|
|
21
|
+
NextYears(count: number): Date;
|
|
22
|
+
MonthsAgo(count: number): Date;
|
|
23
|
+
NextMonths(count: number): Date;
|
|
24
|
+
HoursAgo(count: number): Date;
|
|
25
|
+
NextHours(count: number): Date;
|
|
26
|
+
MinutesAgo(count: number): Date;
|
|
27
|
+
NextMinutes(count: number): Date;
|
|
28
|
+
SecondsAgo(count: number): Date;
|
|
29
|
+
NextSeconds(count: number): Date;
|
|
30
|
+
}
|
|
31
|
+
interface DateBuilderCoreMethods extends DateBuilderUtilityMethods {
|
|
32
|
+
build(reference?: DateTarget): Date;
|
|
33
|
+
from(reference: DateTarget): Date;
|
|
34
|
+
past(reference: DateTarget): Date;
|
|
35
|
+
after(reference: DateTarget): Date;
|
|
36
|
+
until(reference: DateTarget): Date;
|
|
37
|
+
before(reference: DateTarget): Date;
|
|
38
|
+
ago(reference?: DateTarget): Date;
|
|
39
|
+
}
|
|
40
|
+
export type DateBuilderChain<Remaining extends DateBuilderField = DateBuilderField> = DateBuilderCoreMethods & {
|
|
41
|
+
[Field in Remaining]: (value: number) => DateBuilderChain<RemoveField<Remaining, Field>>;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Fluent builder for producing dates relative to a reference point.
|
|
45
|
+
*/
|
|
46
|
+
export declare class DateBuilder<Remaining extends DateBuilderField = DateBuilderField> implements DateBuilderCoreMethods {
|
|
47
|
+
private years;
|
|
48
|
+
private months;
|
|
49
|
+
private days;
|
|
50
|
+
private hours;
|
|
51
|
+
private minutes;
|
|
52
|
+
private seconds;
|
|
53
|
+
private constructor();
|
|
54
|
+
static Years(value: number): DateBuilderChain<RemoveField<DateBuilderField, "Years">>;
|
|
55
|
+
static Months(value: number): DateBuilderChain<RemoveField<DateBuilderField, "Months">>;
|
|
56
|
+
static Days(value: number): DateBuilderChain<RemoveField<DateBuilderField, "Days">>;
|
|
57
|
+
static Hours(value: number): DateBuilderChain<RemoveField<DateBuilderField, "Hours">>;
|
|
58
|
+
static Minutes(value: number): DateBuilderChain<RemoveField<DateBuilderField, "Minutes">>;
|
|
59
|
+
static Seconds(value: number): DateBuilderChain<RemoveField<DateBuilderField, "Seconds">>;
|
|
60
|
+
static Now(): Date;
|
|
61
|
+
static Tomorrow(): Date;
|
|
62
|
+
static Yesterday(): Date;
|
|
63
|
+
static DaysAgo(count: number): Date;
|
|
64
|
+
static NextDays(count: number): Date;
|
|
65
|
+
static YearsAgo(count: number): Date;
|
|
66
|
+
static NextYears(count: number): Date;
|
|
67
|
+
static MonthsAgo(count: number): Date;
|
|
68
|
+
static NextMonths(count: number): Date;
|
|
69
|
+
static HoursAgo(count: number): Date;
|
|
70
|
+
static NextHours(count: number): Date;
|
|
71
|
+
static MinutesAgo(count: number): Date;
|
|
72
|
+
static NextMinutes(count: number): Date;
|
|
73
|
+
static SecondsAgo(count: number): Date;
|
|
74
|
+
static NextSeconds(count: number): Date;
|
|
75
|
+
Years(value: number): DateBuilderChain<RemoveField<Remaining, "Years">>;
|
|
76
|
+
Months(value: number): DateBuilderChain<RemoveField<Remaining, "Months">>;
|
|
77
|
+
Days(value: number): DateBuilderChain<RemoveField<Remaining, "Days">>;
|
|
78
|
+
Hours(value: number): DateBuilderChain<RemoveField<Remaining, "Hours">>;
|
|
79
|
+
Minutes(value: number): DateBuilderChain<RemoveField<Remaining, "Minutes">>;
|
|
80
|
+
Seconds(value: number): DateBuilderChain<RemoveField<Remaining, "Seconds">>;
|
|
81
|
+
build(reference?: DateTarget): Date;
|
|
82
|
+
from(reference: DateTarget): Date;
|
|
83
|
+
past(reference: DateTarget): Date;
|
|
84
|
+
after(reference: DateTarget): Date;
|
|
85
|
+
until(reference: DateTarget): Date;
|
|
86
|
+
before(reference: DateTarget): Date;
|
|
87
|
+
ago(reference?: DateTarget): Date;
|
|
88
|
+
Now(): Date;
|
|
89
|
+
Tomorrow(): Date;
|
|
90
|
+
Yesterday(): Date;
|
|
91
|
+
DaysAgo(count: number): Date;
|
|
92
|
+
NextDays(count: number): Date;
|
|
93
|
+
YearsAgo(count: number): Date;
|
|
94
|
+
NextYears(count: number): Date;
|
|
95
|
+
MonthsAgo(count: number): Date;
|
|
96
|
+
NextMonths(count: number): Date;
|
|
97
|
+
HoursAgo(count: number): Date;
|
|
98
|
+
NextHours(count: number): Date;
|
|
99
|
+
MinutesAgo(count: number): Date;
|
|
100
|
+
NextMinutes(count: number): Date;
|
|
101
|
+
SecondsAgo(count: number): Date;
|
|
102
|
+
NextSeconds(count: number): Date;
|
|
103
|
+
private offsets;
|
|
104
|
+
}
|
|
105
|
+
export declare const Dates: typeof DateBuilder;
|
|
106
|
+
export declare const Now: () => Date;
|
|
107
|
+
export declare const Tomorrow: () => Date;
|
|
108
|
+
export declare const Yesterday: () => Date;
|
|
109
|
+
export declare const DaysAgo: (count: number) => Date;
|
|
110
|
+
export declare const NextDays: (count: number) => Date;
|
|
111
|
+
export declare const YearsAgo: (count: number) => Date;
|
|
112
|
+
export declare const NextYears: (count: number) => Date;
|
|
113
|
+
export declare const MonthsAgo: (count: number) => Date;
|
|
114
|
+
export declare const NextMonths: (count: number) => Date;
|
|
115
|
+
export declare const HoursAgo: (count: number) => Date;
|
|
116
|
+
export declare const NextHours: (count: number) => Date;
|
|
117
|
+
export declare const MinutesAgo: (count: number) => Date;
|
|
118
|
+
export declare const NextMinutes: (count: number) => Date;
|
|
119
|
+
export declare const SecondsAgo: (count: number) => Date;
|
|
120
|
+
export declare const NextSeconds: (count: number) => Date;
|
|
121
|
+
export {};
|