@decaf-ts/decorator-validation 1.5.8 → 1.5.10
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/LICENSE.md +0 -0
- package/README.md +0 -0
- package/dist/decorator-validation.js +1 -1
- package/dist/decorator-validation.js.LICENSE.txt +0 -0
- package/dist/esm/decorator-validation.js +1 -1
- package/dist/esm/decorator-validation.js.LICENSE.txt +0 -0
- package/{lib/esm → dist/types}/index.d.ts +1 -1
- package/{lib/esm → dist/types}/model/Model.d.ts +1 -0
- package/{lib/esm → dist/types}/model/ModelErrorDefinition.d.ts +0 -0
- package/{lib/esm → dist/types}/model/constants.d.ts +0 -0
- package/{lib/esm → dist/types}/model/construction.d.ts +0 -0
- package/{lib/esm → dist/types}/model/decorators.d.ts +0 -0
- package/{lib/esm → dist/types}/model/index.d.ts +0 -1
- package/{lib/esm → dist/types}/model/types.d.ts +0 -0
- package/{lib/esm → dist/types}/model/validation.d.ts +0 -0
- package/{lib/esm → dist/types}/utils/constants.d.ts +0 -0
- package/{lib/esm → dist/types}/utils/dates.d.ts +0 -0
- package/{lib/esm → dist/types}/utils/decorators.d.ts +0 -0
- package/{lib → dist/types}/utils/hashing.d.ts +0 -14
- package/{lib → dist/types}/utils/index.d.ts +1 -0
- package/{lib/esm → dist/types}/utils/registry.d.ts +0 -0
- package/{lib → dist/types}/utils/serialization.d.ts +4 -30
- package/{lib/esm → dist/types}/utils/strings.d.ts +0 -0
- package/dist/types/utils/types.d.ts +29 -0
- package/{lib → dist/types}/validation/Validation.d.ts +1 -1
- package/{lib → dist/types}/validation/Validators/DateValidator.d.ts +1 -1
- package/{lib → dist/types}/validation/Validators/EmailValidator.d.ts +1 -1
- package/{lib → dist/types}/validation/Validators/ListValidator.d.ts +1 -1
- package/{lib → dist/types}/validation/Validators/MaxLengthValidator.d.ts +1 -1
- package/{lib/esm → dist/types}/validation/Validators/MaxValidator.d.ts +1 -1
- package/{lib/esm → dist/types}/validation/Validators/MinLengthValidator.d.ts +1 -1
- package/{lib/esm → dist/types}/validation/Validators/MinValidator.d.ts +1 -1
- package/{lib/esm → dist/types}/validation/Validators/PasswordValidator.d.ts +1 -1
- package/{lib → dist/types}/validation/Validators/PatternValidator.d.ts +1 -1
- package/{lib/esm → dist/types}/validation/Validators/RequiredValidator.d.ts +1 -1
- package/{lib/esm → dist/types}/validation/Validators/StepValidator.d.ts +1 -1
- package/{lib → dist/types}/validation/Validators/TypeValidator.d.ts +1 -1
- package/{lib/esm → dist/types}/validation/Validators/URLValidator.d.ts +1 -1
- package/{lib/esm → dist/types}/validation/Validators/Validator.d.ts +1 -1
- package/{lib/esm → dist/types}/validation/Validators/ValidatorRegistry.d.ts +2 -2
- package/{lib/esm → dist/types}/validation/Validators/constants.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/decorators.d.ts +0 -0
- package/dist/types/validation/Validators/index.d.ts +17 -0
- package/{lib/esm → dist/types}/validation/decorators.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/index.d.ts +0 -0
- package/{lib/validation/Validators → dist/types/validation}/types.d.ts +49 -3
- package/lib/esm/index.js +3 -1
- package/lib/esm/model/Model.js +8 -1
- package/lib/esm/model/ModelErrorDefinition.js +2 -0
- package/lib/esm/model/constants.js +2 -0
- package/lib/esm/model/construction.js +2 -0
- package/lib/esm/model/decorators.js +2 -0
- package/lib/esm/model/index.js +2 -1
- package/lib/esm/model/types.js +2 -0
- package/lib/esm/model/validation.js +2 -0
- package/lib/esm/utils/constants.js +2 -0
- package/lib/esm/utils/dates.js +2 -0
- package/lib/esm/utils/decorators.js +2 -0
- package/lib/esm/utils/hashing.js +2 -17
- package/lib/esm/utils/index.js +3 -0
- package/lib/esm/utils/registry.js +2 -0
- package/lib/esm/utils/serialization.js +4 -1
- package/lib/esm/utils/strings.js +2 -0
- package/lib/esm/utils/types.js +3 -0
- package/lib/esm/validation/Validation.js +2 -0
- package/lib/esm/validation/Validators/DateValidator.js +2 -0
- package/lib/esm/validation/Validators/EmailValidator.js +2 -0
- package/lib/esm/validation/Validators/ListValidator.js +2 -0
- package/lib/esm/validation/Validators/MaxLengthValidator.js +2 -0
- package/lib/esm/validation/Validators/MaxValidator.js +2 -0
- package/lib/esm/validation/Validators/MinLengthValidator.js +2 -0
- package/lib/esm/validation/Validators/MinValidator.js +2 -0
- package/lib/esm/validation/Validators/PasswordValidator.js +2 -0
- package/lib/esm/validation/Validators/PatternValidator.js +2 -0
- package/lib/esm/validation/Validators/RequiredValidator.js +2 -0
- package/lib/esm/validation/Validators/StepValidator.js +2 -0
- package/lib/esm/validation/Validators/TypeValidator.js +2 -0
- package/lib/esm/validation/Validators/URLValidator.js +2 -0
- package/lib/esm/validation/Validators/Validator.js +2 -0
- package/lib/esm/validation/Validators/ValidatorRegistry.js +2 -0
- package/lib/esm/validation/Validators/constants.js +2 -0
- package/lib/esm/validation/Validators/decorators.js +2 -0
- package/lib/esm/validation/Validators/index.js +2 -35
- package/lib/esm/validation/decorators.js +2 -0
- package/lib/esm/validation/index.js +2 -0
- package/lib/esm/validation/types.js +2 -0
- package/lib/index.cjs +61 -0
- package/lib/model/Model.cjs +397 -0
- package/lib/model/ModelErrorDefinition.cjs +58 -0
- package/lib/model/constants.cjs +74 -0
- package/lib/model/construction.cjs +70 -0
- package/lib/model/decorators.cjs +69 -0
- package/lib/model/index.cjs +25 -0
- package/lib/model/types.cjs +4 -0
- package/lib/model/validation.cjs +140 -0
- package/lib/utils/constants.cjs +32 -0
- package/lib/utils/dates.cjs +253 -0
- package/lib/utils/decorators.cjs +24 -0
- package/lib/utils/hashing.cjs +90 -0
- package/lib/utils/index.cjs +26 -0
- package/lib/utils/registry.cjs +4 -0
- package/lib/utils/serialization.cjs +96 -0
- package/lib/utils/strings.cjs +37 -0
- package/lib/utils/types.cjs +4 -0
- package/lib/validation/Validation.cjs +77 -0
- package/lib/validation/Validators/DateValidator.cjs +59 -0
- package/lib/validation/Validators/EmailValidator.cjs +55 -0
- package/lib/validation/Validators/ListValidator.cjs +72 -0
- package/lib/validation/Validators/MaxLengthValidator.cjs +57 -0
- package/lib/validation/Validators/MaxValidator.cjs +62 -0
- package/lib/validation/Validators/MinLengthValidator.cjs +57 -0
- package/lib/validation/Validators/MinValidator.cjs +62 -0
- package/lib/validation/Validators/PasswordValidator.cjs +55 -0
- package/lib/validation/Validators/PatternValidator.cjs +75 -0
- package/lib/validation/Validators/RequiredValidator.cjs +62 -0
- package/lib/validation/Validators/StepValidator.cjs +57 -0
- package/lib/validation/Validators/TypeValidator.cjs +65 -0
- package/lib/validation/Validators/URLValidator.cjs +54 -0
- package/lib/validation/Validators/Validator.cjs +53 -0
- package/lib/validation/Validators/ValidatorRegistry.cjs +87 -0
- package/lib/validation/Validators/constants.cjs +139 -0
- package/lib/validation/Validators/decorators.cjs +30 -0
- package/lib/validation/Validators/index.cjs +35 -0
- package/lib/validation/decorators.cjs +306 -0
- package/lib/validation/{index.js → index.cjs} +6 -4
- package/lib/validation/types.cjs +4 -0
- package/package.json +2 -2
- package/lib/esm/model/utils.d.ts +0 -2
- package/lib/esm/model/utils.js +0 -8
- package/lib/esm/utils/hashing.d.ts +0 -52
- package/lib/esm/utils/index.d.ts +0 -7
- package/lib/esm/utils/serialization.d.ts +0 -79
- package/lib/esm/validation/Validation.d.ts +0 -51
- package/lib/esm/validation/Validators/DateValidator.d.ts +0 -28
- package/lib/esm/validation/Validators/EmailValidator.d.ts +0 -28
- package/lib/esm/validation/Validators/ListValidator.d.ts +0 -28
- package/lib/esm/validation/Validators/MaxLengthValidator.d.ts +0 -29
- package/lib/esm/validation/Validators/PatternValidator.d.ts +0 -37
- package/lib/esm/validation/Validators/TypeValidator.d.ts +0 -25
- package/lib/esm/validation/Validators/index.d.ts +0 -52
- package/lib/esm/validation/Validators/types.js +0 -1
- package/lib/esm/validation/types.d.ts +0 -46
- package/lib/index.d.ts +0 -42
- package/lib/index.js +0 -59
- package/lib/model/Model.d.ts +0 -203
- package/lib/model/Model.js +0 -389
- package/lib/model/ModelErrorDefinition.d.ts +0 -22
- package/lib/model/ModelErrorDefinition.js +0 -56
- package/lib/model/constants.d.ts +0 -56
- package/lib/model/constants.js +0 -72
- package/lib/model/construction.d.ts +0 -29
- package/lib/model/construction.js +0 -68
- package/lib/model/decorators.d.ts +0 -25
- package/lib/model/decorators.js +0 -67
- package/lib/model/index.d.ts +0 -8
- package/lib/model/index.js +0 -24
- package/lib/model/types.d.ts +0 -79
- package/lib/model/types.js +0 -2
- package/lib/model/utils.d.ts +0 -2
- package/lib/model/utils.js +0 -11
- package/lib/model/validation.d.ts +0 -14
- package/lib/model/validation.js +0 -138
- package/lib/utils/constants.d.ts +0 -26
- package/lib/utils/constants.js +0 -30
- package/lib/utils/dates.d.ts +0 -76
- package/lib/utils/dates.js +0 -251
- package/lib/utils/decorators.d.ts +0 -2
- package/lib/utils/decorators.js +0 -22
- package/lib/utils/hashing.js +0 -106
- package/lib/utils/index.js +0 -23
- package/lib/utils/registry.d.ts +0 -68
- package/lib/utils/registry.js +0 -2
- package/lib/utils/serialization.js +0 -93
- package/lib/utils/strings.d.ts +0 -25
- package/lib/utils/strings.js +0 -35
- package/lib/validation/Validation.js +0 -75
- package/lib/validation/Validators/DateValidator.js +0 -57
- package/lib/validation/Validators/EmailValidator.js +0 -53
- package/lib/validation/Validators/ListValidator.js +0 -70
- package/lib/validation/Validators/MaxLengthValidator.js +0 -55
- package/lib/validation/Validators/MaxValidator.d.ts +0 -28
- package/lib/validation/Validators/MaxValidator.js +0 -60
- package/lib/validation/Validators/MinLengthValidator.d.ts +0 -29
- package/lib/validation/Validators/MinLengthValidator.js +0 -55
- package/lib/validation/Validators/MinValidator.d.ts +0 -28
- package/lib/validation/Validators/MinValidator.js +0 -60
- package/lib/validation/Validators/PasswordValidator.d.ts +0 -28
- package/lib/validation/Validators/PasswordValidator.js +0 -53
- package/lib/validation/Validators/PatternValidator.js +0 -73
- package/lib/validation/Validators/RequiredValidator.d.ts +0 -28
- package/lib/validation/Validators/RequiredValidator.js +0 -60
- package/lib/validation/Validators/StepValidator.d.ts +0 -29
- package/lib/validation/Validators/StepValidator.js +0 -55
- package/lib/validation/Validators/TypeValidator.js +0 -63
- package/lib/validation/Validators/URLValidator.d.ts +0 -27
- package/lib/validation/Validators/URLValidator.js +0 -52
- package/lib/validation/Validators/Validator.d.ts +0 -41
- package/lib/validation/Validators/Validator.js +0 -51
- package/lib/validation/Validators/ValidatorRegistry.d.ts +0 -47
- package/lib/validation/Validators/ValidatorRegistry.js +0 -85
- package/lib/validation/Validators/constants.d.ts +0 -96
- package/lib/validation/Validators/constants.js +0 -137
- package/lib/validation/Validators/decorators.d.ts +0 -12
- package/lib/validation/Validators/decorators.js +0 -28
- package/lib/validation/Validators/index.d.ts +0 -52
- package/lib/validation/Validators/index.js +0 -69
- package/lib/validation/Validators/types.js +0 -2
- package/lib/validation/decorators.d.ts +0 -178
- package/lib/validation/decorators.js +0 -304
- package/lib/validation/index.d.ts +0 -4
- package/lib/validation/types.d.ts +0 -46
- package/lib/validation/types.js +0 -2
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @summary defines the tpe os an InstanceCallback function
|
|
3
|
-
*
|
|
4
|
-
* @memberOf module:decorator-validation.Model
|
|
5
|
-
*/
|
|
6
|
-
export type InstanceCallback = (instance: any, ...args: any[]) => void;
|
|
7
|
-
/**
|
|
8
|
-
* @summary Defines a class as a Model class
|
|
9
|
-
* @description
|
|
10
|
-
*
|
|
11
|
-
* - Registers the class under the model registry so it can be easily rebuilt;
|
|
12
|
-
* - Overrides the class constructor;
|
|
13
|
-
* - Runs the global {@link ModelBuilderFunction} if defined;
|
|
14
|
-
* - Runs the optional {@link InstanceCallback} if provided;
|
|
15
|
-
*
|
|
16
|
-
* @param {InstanceCallback} [instanceCallback] optional callback that will be called with the instance upon instantiation. defaults to undefined
|
|
17
|
-
*
|
|
18
|
-
* @function model
|
|
19
|
-
*
|
|
20
|
-
* @memberOf module:decorator-validation.Model
|
|
21
|
-
*
|
|
22
|
-
*/
|
|
23
|
-
export declare function model(instanceCallback?: InstanceCallback): any;
|
|
24
|
-
export declare function hashedBy(algorithm: string, ...args: any[]): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
|
|
25
|
-
export declare function serializedBy(serializer: string, ...args: any[]): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
|
package/lib/model/decorators.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.model = model;
|
|
4
|
-
exports.hashedBy = hashedBy;
|
|
5
|
-
exports.serializedBy = serializedBy;
|
|
6
|
-
const construction_1 = require("./construction");
|
|
7
|
-
const constants_1 = require("../utils/constants");
|
|
8
|
-
const Model_1 = require("./Model");
|
|
9
|
-
const reflection_1 = require("@decaf-ts/reflection");
|
|
10
|
-
/**
|
|
11
|
-
* @summary Defines a class as a Model class
|
|
12
|
-
* @description
|
|
13
|
-
*
|
|
14
|
-
* - Registers the class under the model registry so it can be easily rebuilt;
|
|
15
|
-
* - Overrides the class constructor;
|
|
16
|
-
* - Runs the global {@link ModelBuilderFunction} if defined;
|
|
17
|
-
* - Runs the optional {@link InstanceCallback} if provided;
|
|
18
|
-
*
|
|
19
|
-
* @param {InstanceCallback} [instanceCallback] optional callback that will be called with the instance upon instantiation. defaults to undefined
|
|
20
|
-
*
|
|
21
|
-
* @function model
|
|
22
|
-
*
|
|
23
|
-
* @memberOf module:decorator-validation.Model
|
|
24
|
-
*
|
|
25
|
-
*/
|
|
26
|
-
function model(instanceCallback) {
|
|
27
|
-
return ((original) => {
|
|
28
|
-
// the new constructor behaviour
|
|
29
|
-
const newConstructor = function (...args) {
|
|
30
|
-
const instance = (0, construction_1.construct)(original, ...args);
|
|
31
|
-
(0, construction_1.bindModelPrototype)(instance);
|
|
32
|
-
// run a builder function if defined with the first argument (The ModelArg)
|
|
33
|
-
const builder = Model_1.Model.getBuilder();
|
|
34
|
-
if (builder)
|
|
35
|
-
builder(instance, args.length ? args[0] : undefined);
|
|
36
|
-
(0, reflection_1.metadata)(Model_1.Model.key(constants_1.ModelKeys.MODEL), original.name)(instance.constructor);
|
|
37
|
-
if (instanceCallback)
|
|
38
|
-
instanceCallback(instance, ...args);
|
|
39
|
-
return instance;
|
|
40
|
-
};
|
|
41
|
-
// copy prototype so instanceof operator still works
|
|
42
|
-
newConstructor.prototype = original.prototype;
|
|
43
|
-
// Sets the proper constructor name for type verification
|
|
44
|
-
Object.defineProperty(newConstructor, "name", {
|
|
45
|
-
writable: false,
|
|
46
|
-
enumerable: true,
|
|
47
|
-
configurable: false,
|
|
48
|
-
value: original.prototype.constructor.name,
|
|
49
|
-
});
|
|
50
|
-
(0, reflection_1.metadata)(Model_1.Model.key(constants_1.ModelKeys.MODEL), original.name)(original);
|
|
51
|
-
Model_1.Model.register(newConstructor, original.name);
|
|
52
|
-
// return new constructor (will override original)
|
|
53
|
-
return newConstructor;
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
function hashedBy(algorithm, ...args) {
|
|
57
|
-
return (0, reflection_1.metadata)(Model_1.Model.key(constants_1.ModelKeys.HASHING), {
|
|
58
|
-
algorithm: algorithm,
|
|
59
|
-
args: args,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
function serializedBy(serializer, ...args) {
|
|
63
|
-
return (0, reflection_1.metadata)(Model_1.Model.key(constants_1.ModelKeys.SERIALIZATION), {
|
|
64
|
-
serializer: serializer,
|
|
65
|
-
args: args,
|
|
66
|
-
});
|
|
67
|
-
}
|
package/lib/model/index.d.ts
DELETED
package/lib/model/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./constants"), exports);
|
|
18
|
-
__exportStar(require("./construction"), exports);
|
|
19
|
-
__exportStar(require("./decorators"), exports);
|
|
20
|
-
__exportStar(require("./Model"), exports);
|
|
21
|
-
__exportStar(require("./ModelErrorDefinition"), exports);
|
|
22
|
-
__exportStar(require("./types"), exports);
|
|
23
|
-
__exportStar(require("./utils"), exports);
|
|
24
|
-
__exportStar(require("./validation"), exports);
|
package/lib/model/types.d.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { ModelErrorDefinition } from "./ModelErrorDefinition";
|
|
2
|
-
import { Model } from "./Model";
|
|
3
|
-
/**
|
|
4
|
-
* @summary Typo of a Model builder function
|
|
5
|
-
* @memberOf module:decorator-validation.Construction
|
|
6
|
-
* @category Construction
|
|
7
|
-
*/
|
|
8
|
-
export type ModelBuilderFunction = <T extends Model>(self: T, obj?: T | Record<string, any>) => T;
|
|
9
|
-
/**
|
|
10
|
-
* @summary Definition of a Model Constructor Argument
|
|
11
|
-
*
|
|
12
|
-
* @memberOf module:decorator-validation.Model
|
|
13
|
-
* @category Model
|
|
14
|
-
*
|
|
15
|
-
* @see ModelConstructor
|
|
16
|
-
*/
|
|
17
|
-
export type ModelArg<T> = T | Record<string, any>;
|
|
18
|
-
/**
|
|
19
|
-
* @summary Definition of a Class Constructor
|
|
20
|
-
* @description Generic type for Constructor functions
|
|
21
|
-
*
|
|
22
|
-
* @typedef Constructor
|
|
23
|
-
*
|
|
24
|
-
* @param {any[]} [args]
|
|
25
|
-
* @memberOf module:decorator-validation.Model
|
|
26
|
-
* @category Model
|
|
27
|
-
*/
|
|
28
|
-
export type Constructor<T> = {
|
|
29
|
-
new (...args: any[]): T;
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* @summary Definition of a Model Constructor
|
|
33
|
-
* @description Generic type for all Model Constructor functions
|
|
34
|
-
*
|
|
35
|
-
* @typedef ModelConstructor
|
|
36
|
-
*
|
|
37
|
-
* @param {ModelArg<T>} [model]
|
|
38
|
-
* @param {any[]} [args]
|
|
39
|
-
* @memberOf module:decorator-validation.Model
|
|
40
|
-
* @category Construction
|
|
41
|
-
*/
|
|
42
|
-
export type ModelConstructor<T extends Model> = {
|
|
43
|
-
new (model?: ModelArg<T>, ...args: any[]): T;
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* @summary Defines the Validation API for validatable models
|
|
47
|
-
* @interface Validatable
|
|
48
|
-
*
|
|
49
|
-
* @category Validation
|
|
50
|
-
*/
|
|
51
|
-
export interface Validatable {
|
|
52
|
-
/**
|
|
53
|
-
* @summary Validates the model and returns the {@link ModelErrorDefinition} if any
|
|
54
|
-
* @param {any} [args]
|
|
55
|
-
*
|
|
56
|
-
* @method
|
|
57
|
-
*/
|
|
58
|
-
hasErrors(...args: any[]): ModelErrorDefinition | undefined;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* @summary Serializable interface
|
|
62
|
-
*
|
|
63
|
-
* @interface Serializable
|
|
64
|
-
*
|
|
65
|
-
* @category Serialization
|
|
66
|
-
*/
|
|
67
|
-
export interface Serializable {
|
|
68
|
-
/**
|
|
69
|
-
* @summary serializes the model
|
|
70
|
-
* @method
|
|
71
|
-
*/
|
|
72
|
-
serialize(): string;
|
|
73
|
-
}
|
|
74
|
-
export interface Hashable {
|
|
75
|
-
hash(): string;
|
|
76
|
-
}
|
|
77
|
-
export interface Comparable<T> {
|
|
78
|
-
equals(other: T, ...args: any[]): boolean;
|
|
79
|
-
}
|
package/lib/model/types.js
DELETED
package/lib/model/utils.d.ts
DELETED
package/lib/model/utils.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isPropertyModel = isPropertyModel;
|
|
4
|
-
const constants_1 = require("../utils/constants");
|
|
5
|
-
const Model_1 = require("./Model");
|
|
6
|
-
function isPropertyModel(target, attribute) {
|
|
7
|
-
if ((0, Model_1.isModel)(target[attribute]))
|
|
8
|
-
return true;
|
|
9
|
-
const metadata = Reflect.getMetadata(constants_1.ModelKeys.TYPE, target, attribute);
|
|
10
|
-
return Model_1.Model.get(metadata.name) ? metadata.name : undefined;
|
|
11
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ModelErrorDefinition } from "./ModelErrorDefinition";
|
|
2
|
-
import { Model } from "./Model";
|
|
3
|
-
/**
|
|
4
|
-
* @summary Analyses the decorations of the properties and validates the obj according to them
|
|
5
|
-
*
|
|
6
|
-
* @typedef T extends Model
|
|
7
|
-
* @prop {T} obj Model object to validate
|
|
8
|
-
* @prop {string[]} [propsToIgnore] object properties to ignore in the validation
|
|
9
|
-
*
|
|
10
|
-
* @function validate
|
|
11
|
-
* @memberOf module:decorator-validation.Validation
|
|
12
|
-
* @category Validation
|
|
13
|
-
*/
|
|
14
|
-
export declare function validate<T extends Model>(obj: T, ...propsToIgnore: string[]): ModelErrorDefinition | undefined;
|
package/lib/model/validation.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validate = validate;
|
|
4
|
-
const ModelErrorDefinition_1 = require("./ModelErrorDefinition");
|
|
5
|
-
const reflection_1 = require("@decaf-ts/reflection");
|
|
6
|
-
const constants_1 = require("../utils/constants");
|
|
7
|
-
const strings_1 = require("../utils/strings");
|
|
8
|
-
const constants_2 = require("./constants");
|
|
9
|
-
const Model_1 = require("./Model");
|
|
10
|
-
const Validation_1 = require("../validation/Validation");
|
|
11
|
-
const constants_3 = require("../validation/Validators/constants");
|
|
12
|
-
/**
|
|
13
|
-
* @summary Analyses the decorations of the properties and validates the obj according to them
|
|
14
|
-
*
|
|
15
|
-
* @typedef T extends Model
|
|
16
|
-
* @prop {T} obj Model object to validate
|
|
17
|
-
* @prop {string[]} [propsToIgnore] object properties to ignore in the validation
|
|
18
|
-
*
|
|
19
|
-
* @function validate
|
|
20
|
-
* @memberOf module:decorator-validation.Validation
|
|
21
|
-
* @category Validation
|
|
22
|
-
*/
|
|
23
|
-
function validate(obj, ...propsToIgnore) {
|
|
24
|
-
const decoratedProperties = [];
|
|
25
|
-
for (const prop in obj)
|
|
26
|
-
if (Object.prototype.hasOwnProperty.call(obj, prop) &&
|
|
27
|
-
propsToIgnore.indexOf(prop) === -1)
|
|
28
|
-
decoratedProperties.push(reflection_1.Reflection.getPropertyDecorators(constants_3.ValidationKeys.REFLECT, obj, prop));
|
|
29
|
-
let result = undefined;
|
|
30
|
-
for (const decoratedProperty of decoratedProperties) {
|
|
31
|
-
const { prop, decorators } = decoratedProperty;
|
|
32
|
-
if (!decorators || !decorators.length)
|
|
33
|
-
continue;
|
|
34
|
-
const defaultTypeDecorator = decorators[0];
|
|
35
|
-
// tries to find any type decorators or other decorators that already enforce type (the ones with the allowed types property defined). if so, skip the default type verification
|
|
36
|
-
if (decorators.find((d) => {
|
|
37
|
-
if (d.key === constants_3.ValidationKeys.TYPE)
|
|
38
|
-
return true;
|
|
39
|
-
return !!d.props.types?.find((t) => t === defaultTypeDecorator.props.name);
|
|
40
|
-
})) {
|
|
41
|
-
decorators.shift(); // remove the design:type decorator, since the type will already be checked
|
|
42
|
-
}
|
|
43
|
-
let errs = undefined;
|
|
44
|
-
for (const decorator of decorators) {
|
|
45
|
-
const validator = Validation_1.Validation.get(decorator.key);
|
|
46
|
-
if (!validator) {
|
|
47
|
-
throw new Error(`Missing validator for ${decorator.key}`);
|
|
48
|
-
}
|
|
49
|
-
const decoratorProps = decorator.key === constants_1.ModelKeys.TYPE
|
|
50
|
-
? [decorator.props]
|
|
51
|
-
: decorator.props || {};
|
|
52
|
-
const err = validator.hasErrors(obj[prop.toString()], decoratorProps);
|
|
53
|
-
if (err) {
|
|
54
|
-
errs = errs || {};
|
|
55
|
-
errs[decorator.key] = err;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
if (errs) {
|
|
59
|
-
result = result || {};
|
|
60
|
-
result[decoratedProperty.prop.toString()] = errs;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// tests nested classes
|
|
64
|
-
for (const prop of Object.keys(obj).filter((k) => !result || !result[k])) {
|
|
65
|
-
let err;
|
|
66
|
-
// if a nested Model
|
|
67
|
-
const allDecorators = reflection_1.Reflection.getPropertyDecorators(constants_3.ValidationKeys.REFLECT, obj, prop).decorators;
|
|
68
|
-
const decorators = reflection_1.Reflection.getPropertyDecorators(constants_3.ValidationKeys.REFLECT, obj, prop).decorators.filter((d) => [constants_1.ModelKeys.TYPE, constants_3.ValidationKeys.TYPE].indexOf(d.key) !== -1);
|
|
69
|
-
if (!decorators || !decorators.length)
|
|
70
|
-
continue;
|
|
71
|
-
const dec = decorators.pop();
|
|
72
|
-
const clazz = dec.props.name
|
|
73
|
-
? [dec.props.name]
|
|
74
|
-
: Array.isArray(dec.props.customTypes)
|
|
75
|
-
? dec.props.customTypes
|
|
76
|
-
: [dec.props.customTypes];
|
|
77
|
-
const reserved = Object.values(constants_2.ReservedModels).map((v) => v.toLowerCase());
|
|
78
|
-
for (const c of clazz) {
|
|
79
|
-
if (reserved.indexOf(c.toLowerCase()) === -1) {
|
|
80
|
-
const typeDecoratorKey = Array.isArray(obj[prop])
|
|
81
|
-
? constants_3.ValidationKeys.LIST
|
|
82
|
-
: constants_3.ValidationKeys.TYPE;
|
|
83
|
-
const types = allDecorators.find((d) => d.key === typeDecoratorKey) || {};
|
|
84
|
-
let allowedTypes = [];
|
|
85
|
-
if (types && types.props) {
|
|
86
|
-
const customTypes = Array.isArray(obj[prop])
|
|
87
|
-
? types.props.class
|
|
88
|
-
: types.props.customTypes;
|
|
89
|
-
if (customTypes)
|
|
90
|
-
allowedTypes = Array.isArray(customTypes)
|
|
91
|
-
? customTypes.map((t) => `${t}`.toLowerCase())
|
|
92
|
-
: [customTypes.toLowerCase()];
|
|
93
|
-
}
|
|
94
|
-
const validate = (prop, value) => {
|
|
95
|
-
if (typeof value === "object" || typeof value === "function")
|
|
96
|
-
return (0, Model_1.isModel)(value)
|
|
97
|
-
? value.hasErrors()
|
|
98
|
-
: allowedTypes.includes(typeof value)
|
|
99
|
-
? undefined
|
|
100
|
-
: "Value has no validatable type";
|
|
101
|
-
};
|
|
102
|
-
switch (c) {
|
|
103
|
-
case Array.name:
|
|
104
|
-
case Set.name:
|
|
105
|
-
if (allDecorators.length) {
|
|
106
|
-
const listDec = allDecorators.find((d) => d.key === constants_3.ValidationKeys.LIST);
|
|
107
|
-
if (listDec) {
|
|
108
|
-
err = (c === Array.name
|
|
109
|
-
? obj[prop]
|
|
110
|
-
: // If it's a Set
|
|
111
|
-
obj[prop].values())
|
|
112
|
-
.map((v) => validate(prop, v))
|
|
113
|
-
.filter((e) => !!e);
|
|
114
|
-
if (!err?.length) {
|
|
115
|
-
// if the result is an empty list...
|
|
116
|
-
err = undefined;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
break;
|
|
121
|
-
default:
|
|
122
|
-
try {
|
|
123
|
-
if (obj[prop])
|
|
124
|
-
err = validate(prop, obj[prop]);
|
|
125
|
-
}
|
|
126
|
-
catch (e) {
|
|
127
|
-
console.warn((0, strings_1.sf)("Model should be validatable but its not: " + e));
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (err) {
|
|
132
|
-
result = result || {};
|
|
133
|
-
result[prop] = err;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return result ? new ModelErrorDefinition_1.ModelErrorDefinition(result) : undefined;
|
|
138
|
-
}
|
package/lib/utils/constants.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @summary Defines the various Model keys used for reflection
|
|
3
|
-
*
|
|
4
|
-
* @property {string} REFLECT prefix to all other keys
|
|
5
|
-
* @property {string} TYPE type key
|
|
6
|
-
* @property {string} PARAMS method params key
|
|
7
|
-
* @property {string} RETURN method return key
|
|
8
|
-
* @property {string} MODEL model key
|
|
9
|
-
* @property {string} ANCHOR anchor key. will serve as a ghost property in the model
|
|
10
|
-
*
|
|
11
|
-
* @constant ModelKeys
|
|
12
|
-
* @memberOf module:decorator-validation.Model
|
|
13
|
-
* @category Model
|
|
14
|
-
*/
|
|
15
|
-
export declare enum ModelKeys {
|
|
16
|
-
REFLECT = "decaf.model.",
|
|
17
|
-
TYPE = "design:type",
|
|
18
|
-
PARAMS = "design:paramtypes",
|
|
19
|
-
RETURN = "design:returntype",
|
|
20
|
-
MODEL = "model",
|
|
21
|
-
ANCHOR = "__model",
|
|
22
|
-
CONSTRUCTION = "constructed-by",
|
|
23
|
-
ATTRIBUTE = "__attributes",
|
|
24
|
-
HASHING = "hashing",
|
|
25
|
-
SERIALIZATION = "serialization"
|
|
26
|
-
}
|
package/lib/utils/constants.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModelKeys = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* @summary Defines the various Model keys used for reflection
|
|
6
|
-
*
|
|
7
|
-
* @property {string} REFLECT prefix to all other keys
|
|
8
|
-
* @property {string} TYPE type key
|
|
9
|
-
* @property {string} PARAMS method params key
|
|
10
|
-
* @property {string} RETURN method return key
|
|
11
|
-
* @property {string} MODEL model key
|
|
12
|
-
* @property {string} ANCHOR anchor key. will serve as a ghost property in the model
|
|
13
|
-
*
|
|
14
|
-
* @constant ModelKeys
|
|
15
|
-
* @memberOf module:decorator-validation.Model
|
|
16
|
-
* @category Model
|
|
17
|
-
*/
|
|
18
|
-
var ModelKeys;
|
|
19
|
-
(function (ModelKeys) {
|
|
20
|
-
ModelKeys["REFLECT"] = "decaf.model.";
|
|
21
|
-
ModelKeys["TYPE"] = "design:type";
|
|
22
|
-
ModelKeys["PARAMS"] = "design:paramtypes";
|
|
23
|
-
ModelKeys["RETURN"] = "design:returntype";
|
|
24
|
-
ModelKeys["MODEL"] = "model";
|
|
25
|
-
ModelKeys["ANCHOR"] = "__model";
|
|
26
|
-
ModelKeys["CONSTRUCTION"] = "constructed-by";
|
|
27
|
-
ModelKeys["ATTRIBUTE"] = "__attributes";
|
|
28
|
-
ModelKeys["HASHING"] = "hashing";
|
|
29
|
-
ModelKeys["SERIALIZATION"] = "serialization";
|
|
30
|
-
})(ModelKeys || (exports.ModelKeys = ModelKeys = {}));
|
package/lib/utils/dates.d.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
/**
|
|
3
|
-
* @summary Reverses the process from {@link formatDate}
|
|
4
|
-
*
|
|
5
|
-
* @param {string} date the date string to be converted back into date
|
|
6
|
-
* @param {string} format the date format
|
|
7
|
-
* @return {Date} the date from the format or the standard new Date({@prop date}) if the string couldn't be parsed (are you sure the format matches the string?)
|
|
8
|
-
*
|
|
9
|
-
* @function dateFromFormat
|
|
10
|
-
* @memberOf module:decorator-validation.Utils.Dates
|
|
11
|
-
* @category Format
|
|
12
|
-
*/
|
|
13
|
-
export declare function dateFromFormat(date: string, format: string): Date;
|
|
14
|
-
/**
|
|
15
|
-
* @summary Binds a date format to a string
|
|
16
|
-
* @param {Date} [date]
|
|
17
|
-
* @param {string} [format]
|
|
18
|
-
* @memberOf module:decorator-validation.Utils.Format
|
|
19
|
-
* @category Utilities
|
|
20
|
-
*/
|
|
21
|
-
export declare function bindDateToString(date: Date | undefined, format: string): Date | undefined;
|
|
22
|
-
/**
|
|
23
|
-
* @summary Helper function to be used instead of instanceOf Date
|
|
24
|
-
* @param date
|
|
25
|
-
* @memberOf module:decorator-validation.Utils.Dates
|
|
26
|
-
* @category Validation
|
|
27
|
-
*/
|
|
28
|
-
export declare function isValidDate(date: any): boolean;
|
|
29
|
-
/**
|
|
30
|
-
* @summary Util function to pad numbers
|
|
31
|
-
* @param {number} num
|
|
32
|
-
*
|
|
33
|
-
* @return {string}
|
|
34
|
-
*
|
|
35
|
-
* @function twoDigitPad
|
|
36
|
-
* @memberOf module:decorator-validation.Utils.Format
|
|
37
|
-
* @category Format
|
|
38
|
-
*/
|
|
39
|
-
export declare function twoDigitPad(num: number): string;
|
|
40
|
-
/**
|
|
41
|
-
* @summary Date Format Handling
|
|
42
|
-
* @description Code from {@link https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date}
|
|
43
|
-
*
|
|
44
|
-
* <pre>
|
|
45
|
-
* Using similar formatting as Moment.js, Class DateTimeFormatter (Java), and Class SimpleDateFormat (Java),
|
|
46
|
-
* I implemented a comprehensive solution formatDate(date, patternStr) where the code is easy to read and modify.
|
|
47
|
-
* You can display date, time, AM/PM, etc.
|
|
48
|
-
*
|
|
49
|
-
* Date and Time Patterns
|
|
50
|
-
* yy = 2-digit year; yyyy = full year
|
|
51
|
-
* M = digit month; MM = 2-digit month; MMM = short month name; MMMM = full month name
|
|
52
|
-
* EEEE = full weekday name; EEE = short weekday name
|
|
53
|
-
* d = digit day; dd = 2-digit day
|
|
54
|
-
* h = hours am/pm; hh = 2-digit hours am/pm; H = hours; HH = 2-digit hours
|
|
55
|
-
* m = minutes; mm = 2-digit minutes; aaa = AM/PM
|
|
56
|
-
* s = seconds; ss = 2-digit seconds
|
|
57
|
-
* S = miliseconds
|
|
58
|
-
* </pre>
|
|
59
|
-
*
|
|
60
|
-
* @param {Date} date
|
|
61
|
-
* @param {string} [patternStr] defaults to 'yyyy/MM/dd'
|
|
62
|
-
* @return {string} the formatted date
|
|
63
|
-
*
|
|
64
|
-
* @function formatDate
|
|
65
|
-
* @memberOf module:decorator-validation.Utils.Dates
|
|
66
|
-
* @category Format
|
|
67
|
-
*/
|
|
68
|
-
export declare function formatDate(date: Date, patternStr?: string): string;
|
|
69
|
-
/**
|
|
70
|
-
* @summary Parses a date from a specified format
|
|
71
|
-
* @param {string} format
|
|
72
|
-
* @param {string | Date | number} [v]
|
|
73
|
-
* @memberOf module:decorator-validation.Utils.Dates
|
|
74
|
-
* @category Format
|
|
75
|
-
*/
|
|
76
|
-
export declare function parseDate(format: string, v?: string | Date | number): Date | undefined;
|