@decaf-ts/decorator-validation 1.5.8 → 1.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/decorator-validation.bundle.min.js +2 -0
- package/dist/esm/decorator-validation.bundle.min.esm.js +2 -0
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/model/Model.d.ts +1 -0
- package/lib/esm/model/Model.js +6 -1
- package/lib/esm/model/index.d.ts +0 -1
- package/lib/esm/model/index.js +0 -1
- package/lib/esm/utils/hashing.d.ts +0 -14
- package/lib/esm/utils/hashing.js +0 -17
- package/lib/esm/utils/index.d.ts +1 -0
- package/lib/esm/utils/index.js +1 -0
- package/lib/esm/utils/serialization.d.ts +4 -30
- package/lib/esm/utils/serialization.js +2 -1
- package/lib/esm/utils/types.d.ts +29 -0
- package/lib/esm/validation/Validation.d.ts +1 -1
- package/lib/esm/validation/Validators/DateValidator.d.ts +1 -1
- package/lib/esm/validation/Validators/EmailValidator.d.ts +1 -1
- package/lib/esm/validation/Validators/ListValidator.d.ts +1 -1
- package/lib/esm/validation/Validators/MaxLengthValidator.d.ts +1 -1
- package/lib/esm/validation/Validators/MaxValidator.d.ts +1 -1
- package/lib/esm/validation/Validators/MinLengthValidator.d.ts +1 -1
- package/lib/esm/validation/Validators/MinValidator.d.ts +1 -1
- package/lib/esm/validation/Validators/PasswordValidator.d.ts +1 -1
- package/lib/esm/validation/Validators/PatternValidator.d.ts +1 -1
- package/lib/esm/validation/Validators/RequiredValidator.d.ts +1 -1
- package/lib/esm/validation/Validators/StepValidator.d.ts +1 -1
- package/lib/esm/validation/Validators/TypeValidator.d.ts +1 -1
- package/lib/esm/validation/Validators/URLValidator.d.ts +1 -1
- package/lib/esm/validation/Validators/Validator.d.ts +1 -1
- package/lib/esm/validation/Validators/ValidatorRegistry.d.ts +2 -2
- package/lib/esm/validation/Validators/index.d.ts +0 -1
- package/lib/esm/validation/Validators/index.js +0 -1
- package/lib/esm/validation/types.d.ts +88 -0
- package/lib/{index.js → index.cjs} +4 -4
- package/lib/index.d.ts +1 -1
- package/lib/model/{Model.js → Model.cjs} +15 -9
- package/lib/model/Model.d.ts +1 -0
- package/lib/model/{construction.js → construction.cjs} +1 -1
- package/lib/model/{decorators.js → decorators.cjs} +3 -3
- package/lib/{utils/index.js → model/index.cjs} +7 -7
- package/lib/model/index.d.ts +0 -1
- package/lib/model/{validation.js → validation.cjs} +7 -7
- package/lib/utils/{dates.js → dates.cjs} +2 -2
- package/lib/utils/{decorators.js → decorators.cjs} +1 -1
- package/lib/utils/{hashing.js → hashing.cjs} +0 -18
- package/lib/utils/hashing.d.ts +0 -14
- package/lib/{model/index.js → utils/index.cjs} +8 -8
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/{serialization.js → serialization.cjs} +5 -4
- package/lib/utils/serialization.d.ts +4 -30
- package/lib/utils/types.d.ts +29 -0
- package/lib/validation/{Validation.js → Validation.cjs} +2 -2
- package/lib/validation/Validation.d.ts +1 -1
- package/lib/validation/Validators/{DateValidator.js → DateValidator.cjs} +3 -3
- package/lib/validation/Validators/DateValidator.d.ts +1 -1
- package/lib/validation/Validators/{EmailValidator.js → EmailValidator.cjs} +3 -3
- package/lib/validation/Validators/EmailValidator.d.ts +1 -1
- package/lib/validation/Validators/{ListValidator.js → ListValidator.cjs} +3 -3
- package/lib/validation/Validators/ListValidator.d.ts +1 -1
- package/lib/validation/Validators/{MaxLengthValidator.js → MaxLengthValidator.cjs} +3 -3
- package/lib/validation/Validators/MaxLengthValidator.d.ts +1 -1
- package/lib/validation/Validators/{MaxValidator.js → MaxValidator.cjs} +3 -3
- package/lib/validation/Validators/MaxValidator.d.ts +1 -1
- package/lib/validation/Validators/{MinLengthValidator.js → MinLengthValidator.cjs} +3 -3
- package/lib/validation/Validators/MinLengthValidator.d.ts +1 -1
- package/lib/validation/Validators/{MinValidator.js → MinValidator.cjs} +3 -3
- package/lib/validation/Validators/MinValidator.d.ts +1 -1
- package/lib/validation/Validators/{PasswordValidator.js → PasswordValidator.cjs} +3 -3
- package/lib/validation/Validators/PasswordValidator.d.ts +1 -1
- package/lib/validation/Validators/{PatternValidator.js → PatternValidator.cjs} +3 -3
- package/lib/validation/Validators/PatternValidator.d.ts +1 -1
- package/lib/validation/Validators/{RequiredValidator.js → RequiredValidator.cjs} +3 -3
- package/lib/validation/Validators/RequiredValidator.d.ts +1 -1
- package/lib/validation/Validators/{StepValidator.js → StepValidator.cjs} +3 -3
- package/lib/validation/Validators/StepValidator.d.ts +1 -1
- package/lib/validation/Validators/{TypeValidator.js → TypeValidator.cjs} +5 -5
- package/lib/validation/Validators/TypeValidator.d.ts +1 -1
- package/lib/validation/Validators/{URLValidator.js → URLValidator.cjs} +3 -3
- package/lib/validation/Validators/URLValidator.d.ts +1 -1
- package/lib/validation/Validators/{Validator.js → Validator.cjs} +2 -2
- package/lib/validation/Validators/Validator.d.ts +1 -1
- package/lib/validation/Validators/ValidatorRegistry.d.ts +2 -2
- package/lib/validation/Validators/{constants.js → constants.cjs} +1 -1
- package/lib/validation/Validators/{decorators.js → decorators.cjs} +2 -2
- package/lib/validation/Validators/index.cjs +68 -0
- package/lib/validation/{decorators.js → decorators.cjs} +5 -5
- package/lib/validation/{index.js → index.cjs} +4 -4
- package/lib/validation/types.d.ts +88 -0
- package/package.json +1 -1
- package/dist/decorator-validation.js +0 -2
- package/dist/esm/decorator-validation.js +0 -2
- package/lib/esm/model/utils.d.ts +0 -2
- package/lib/esm/model/utils.js +0 -8
- package/lib/model/utils.d.ts +0 -2
- package/lib/model/utils.js +0 -11
- package/lib/validation/Validators/decorators.d.ts +0 -12
- package/lib/validation/Validators/index.d.ts +0 -52
- package/lib/validation/Validators/index.js +0 -69
- package/lib/validation/Validators/types.d.ts +0 -88
- /package/dist/{decorator-validation.js.LICENSE.txt → decorator-validation.bundle.min.js.LICENSE.txt} +0 -0
- /package/dist/esm/{decorator-validation.js.LICENSE.txt → decorator-validation.bundle.min.esm.js.LICENSE.txt} +0 -0
- /package/lib/esm/{validation/Validators → utils}/types.js +0 -0
- /package/lib/model/{ModelErrorDefinition.js → ModelErrorDefinition.cjs} +0 -0
- /package/lib/model/{constants.js → constants.cjs} +0 -0
- /package/lib/model/{types.js → types.cjs} +0 -0
- /package/lib/utils/{constants.js → constants.cjs} +0 -0
- /package/lib/utils/{registry.js → registry.cjs} +0 -0
- /package/lib/utils/{strings.js → strings.cjs} +0 -0
- /package/lib/{validation/Validators/types.js → utils/types.cjs} +0 -0
- /package/lib/validation/Validators/{ValidatorRegistry.js → ValidatorRegistry.cjs} +0 -0
- /package/lib/validation/{types.js → types.cjs} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PatternValidator } from "./PatternValidator";
|
|
2
|
-
import { PatternValidatorOptions } from "
|
|
2
|
+
import { PatternValidatorOptions } from "../types";
|
|
3
3
|
/**
|
|
4
4
|
* @summary URL Validator
|
|
5
5
|
* @description Pattern from {@link https://gist.github.com/dperini/729294}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ValidatorDefinition } from "
|
|
2
|
-
import { IValidatorRegistry } from "
|
|
1
|
+
import { ValidatorDefinition } from "../types";
|
|
2
|
+
import { IValidatorRegistry } from "../types";
|
|
3
3
|
import type { Validator } from "./Validator";
|
|
4
4
|
/**
|
|
5
5
|
* @summary Duck typing for Validators
|
|
@@ -24,7 +24,6 @@ export * from "./PasswordValidator";
|
|
|
24
24
|
export * from "./PatternValidator";
|
|
25
25
|
export * from "./RequiredValidator";
|
|
26
26
|
export * from "./StepValidator";
|
|
27
|
-
export * from "./types";
|
|
28
27
|
export * from "./TypeValidator";
|
|
29
28
|
export * from "./URLValidator";
|
|
30
29
|
export * from "./Validator";
|
|
@@ -24,7 +24,6 @@ export * from "./PasswordValidator";
|
|
|
24
24
|
export * from "./PatternValidator";
|
|
25
25
|
export * from "./RequiredValidator";
|
|
26
26
|
export * from "./StepValidator";
|
|
27
|
-
export * from "./types";
|
|
28
27
|
export * from "./TypeValidator";
|
|
29
28
|
export * from "./URLValidator";
|
|
30
29
|
export * from "./Validator";
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { DecoratorMetadata } from "@decaf-ts/reflection";
|
|
2
|
+
import { Constructor } from "../model";
|
|
3
|
+
import { Validator } from "./Validators";
|
|
4
|
+
import { IRegistry } from "../utils";
|
|
2
5
|
/**
|
|
3
6
|
* @summary Type for validation decorator metadata
|
|
4
7
|
* @memberOf module:decorator-validation.Reflection
|
|
@@ -44,3 +47,88 @@ export type ValidationElementDefinition = {
|
|
|
44
47
|
* @category Validation
|
|
45
48
|
*/
|
|
46
49
|
export type ModelErrors = Record<string, Record<string, string | undefined>>;
|
|
50
|
+
/**
|
|
51
|
+
* @summary Util type for {@link Validator} configuration
|
|
52
|
+
* @memberOf module:decorator-validation.Validation
|
|
53
|
+
* @category Validation
|
|
54
|
+
*/
|
|
55
|
+
export type ValidatorDefinition = {
|
|
56
|
+
validator: Constructor<Validator>;
|
|
57
|
+
validationKey: string;
|
|
58
|
+
save: boolean;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* @summary Base API for a {@link Validator} registry
|
|
62
|
+
*
|
|
63
|
+
* @interface ValidatorRegistry
|
|
64
|
+
* @extends IRegistry
|
|
65
|
+
*
|
|
66
|
+
* @category Validation
|
|
67
|
+
*/
|
|
68
|
+
export interface IValidatorRegistry<T extends Validator> extends IRegistry<T> {
|
|
69
|
+
/**
|
|
70
|
+
* @summary retrieves the custom keys
|
|
71
|
+
* @method
|
|
72
|
+
*/
|
|
73
|
+
getCustomKeys(): Record<string, string>;
|
|
74
|
+
/**
|
|
75
|
+
* @summary Retrieves the Registered validator keys
|
|
76
|
+
* @return {string[]} the registered validators keys
|
|
77
|
+
* @method
|
|
78
|
+
*/
|
|
79
|
+
getKeys(): string[];
|
|
80
|
+
/**
|
|
81
|
+
* @summary Registers the provided validators onto the registry
|
|
82
|
+
*
|
|
83
|
+
* @typedef T extends Validator
|
|
84
|
+
* @param {T[] | ValidatorDefinition[]} validator
|
|
85
|
+
* @method
|
|
86
|
+
*/
|
|
87
|
+
register<T extends Validator>(...validator: (T | ValidatorDefinition)[]): void;
|
|
88
|
+
/**
|
|
89
|
+
* @summary Retrieves the Validator constructor if registered
|
|
90
|
+
*
|
|
91
|
+
* @typedef T extends Validator
|
|
92
|
+
* @param {string} key one of the {@link ValidationKeys}
|
|
93
|
+
* @return {Validator | undefined} the registered Validator or undefined if there is nono matching the provided key
|
|
94
|
+
* @method
|
|
95
|
+
*/
|
|
96
|
+
get<T extends Validator>(key: string): T | undefined;
|
|
97
|
+
}
|
|
98
|
+
export type ValidatorOptions = {
|
|
99
|
+
message?: string;
|
|
100
|
+
};
|
|
101
|
+
export interface URLValidatorOptions extends ValidatorOptions {
|
|
102
|
+
types: string | string[] | {
|
|
103
|
+
name: string;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
export interface TypeValidatorOptions extends ValidatorOptions {
|
|
107
|
+
types: string | string[] | {
|
|
108
|
+
name: string;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
export interface StepValidatorOptions extends ValidatorOptions {
|
|
112
|
+
step: number | string;
|
|
113
|
+
}
|
|
114
|
+
export interface PatternValidatorOptions extends ValidatorOptions {
|
|
115
|
+
pattern?: RegExp | string;
|
|
116
|
+
}
|
|
117
|
+
export interface MinValidatorOptions extends ValidatorOptions {
|
|
118
|
+
min: number | Date | string;
|
|
119
|
+
}
|
|
120
|
+
export interface MinLengthValidatorOptions extends ValidatorOptions {
|
|
121
|
+
minLength: number;
|
|
122
|
+
}
|
|
123
|
+
export interface MaxValidatorOptions extends ValidatorOptions {
|
|
124
|
+
max: number | Date | string;
|
|
125
|
+
}
|
|
126
|
+
export interface MaxLengthValidatorOptions extends ValidatorOptions {
|
|
127
|
+
maxLength: number;
|
|
128
|
+
}
|
|
129
|
+
export interface ListValidatorOptions extends ValidatorOptions {
|
|
130
|
+
clazz: string[];
|
|
131
|
+
}
|
|
132
|
+
export interface DateValidatorOptions extends ValidatorOptions {
|
|
133
|
+
format?: string;
|
|
134
|
+
}
|
|
@@ -53,7 +53,7 @@ exports.VERSION = void 0;
|
|
|
53
53
|
* @namespace Format
|
|
54
54
|
* @memberOf module:decorator-validation
|
|
55
55
|
*/
|
|
56
|
-
__exportStar(require("./utils"), exports);
|
|
57
|
-
__exportStar(require("./validation"), exports);
|
|
58
|
-
__exportStar(require("./model"), exports);
|
|
59
|
-
exports.VERSION = "1.5.
|
|
56
|
+
__exportStar(require("./utils/index.cjs"), exports);
|
|
57
|
+
__exportStar(require("./validation/index.cjs"), exports);
|
|
58
|
+
__exportStar(require("./model/index.cjs"), exports);
|
|
59
|
+
exports.VERSION = "1.5.8";
|
package/lib/index.d.ts
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Model = exports.ModelRegistryManager = void 0;
|
|
4
|
+
exports.isPropertyModel = isPropertyModel;
|
|
4
5
|
exports.isModel = isModel;
|
|
5
6
|
exports.bulkModelRegister = bulkModelRegister;
|
|
6
|
-
const serialization_1 = require("../utils/serialization");
|
|
7
|
+
const serialization_1 = require("../utils/serialization.cjs");
|
|
7
8
|
const reflection_1 = require("@decaf-ts/reflection");
|
|
8
|
-
const validation_1 = require("./validation");
|
|
9
|
-
const hashing_1 = require("../utils/hashing");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const constants_3 = require("./constants");
|
|
9
|
+
const validation_1 = require("./validation.cjs");
|
|
10
|
+
const hashing_1 = require("../utils/hashing.cjs");
|
|
11
|
+
const constants_1 = require("../utils/constants.cjs");
|
|
12
|
+
const constants_2 = require("../validation/Validators/constants.cjs");
|
|
13
|
+
const strings_1 = require("../utils/strings.cjs");
|
|
14
|
+
const constants_3 = require("./constants.cjs");
|
|
15
15
|
let modelBuilderFunction;
|
|
16
16
|
let actingModelRegistry;
|
|
17
|
+
function isPropertyModel(target, attribute) {
|
|
18
|
+
if (isModel(target[attribute]))
|
|
19
|
+
return true;
|
|
20
|
+
const metadata = Reflect.getMetadata(constants_1.ModelKeys.TYPE, target, attribute);
|
|
21
|
+
return Model.get(metadata.name) ? metadata.name : undefined;
|
|
22
|
+
}
|
|
17
23
|
/**
|
|
18
24
|
* @summary For Serialization/deserialization purposes.
|
|
19
25
|
* @description Reads the {@link ModelKeys.ANCHOR} property of a {@link Model} to discover the class to instantiate
|
|
@@ -211,7 +217,7 @@ class Model {
|
|
|
211
217
|
obj[prop] || undefined;
|
|
212
218
|
if (typeof self[prop] !== "object")
|
|
213
219
|
continue;
|
|
214
|
-
const propM =
|
|
220
|
+
const propM = isPropertyModel(self, prop);
|
|
215
221
|
if (propM) {
|
|
216
222
|
try {
|
|
217
223
|
self[prop] = Model.build(self[prop], typeof propM === "string" ? propM : undefined);
|
package/lib/model/Model.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BuilderRegistry } from "../utils/registry";
|
|
2
2
|
import { ModelErrorDefinition } from "./ModelErrorDefinition";
|
|
3
3
|
import { Comparable, Constructor, Hashable, ModelArg, ModelBuilderFunction, ModelConstructor, Serializable, Validatable } from "./types";
|
|
4
|
+
export declare function isPropertyModel<M extends Model>(target: M, attribute: string): boolean | string | undefined;
|
|
4
5
|
/**
|
|
5
6
|
* @summary For Serialization/deserialization purposes.
|
|
6
7
|
* @description Reads the {@link ModelKeys.ANCHOR} property of a {@link Model} to discover the class to instantiate
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.construct = construct;
|
|
4
4
|
exports.findLastProtoBeforeObject = findLastProtoBeforeObject;
|
|
5
5
|
exports.bindModelPrototype = bindModelPrototype;
|
|
6
|
-
const Model_1 = require("./Model");
|
|
6
|
+
const Model_1 = require("./Model.cjs");
|
|
7
7
|
/**
|
|
8
8
|
* @summary Helper Function to override constructors
|
|
9
9
|
*
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.model = model;
|
|
4
4
|
exports.hashedBy = hashedBy;
|
|
5
5
|
exports.serializedBy = serializedBy;
|
|
6
|
-
const construction_1 = require("./construction");
|
|
7
|
-
const constants_1 = require("../utils/constants");
|
|
8
|
-
const Model_1 = require("./Model");
|
|
6
|
+
const construction_1 = require("./construction.cjs");
|
|
7
|
+
const constants_1 = require("../utils/constants.cjs");
|
|
8
|
+
const Model_1 = require("./Model.cjs");
|
|
9
9
|
const reflection_1 = require("@decaf-ts/reflection");
|
|
10
10
|
/**
|
|
11
11
|
* @summary Defines a class as a Model class
|
|
@@ -14,10 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./constants"), exports);
|
|
18
|
-
__exportStar(require("./
|
|
19
|
-
__exportStar(require("./decorators"), exports);
|
|
20
|
-
__exportStar(require("./
|
|
21
|
-
__exportStar(require("./
|
|
22
|
-
__exportStar(require("./
|
|
23
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./constants.cjs"), exports);
|
|
18
|
+
__exportStar(require("./construction.cjs"), exports);
|
|
19
|
+
__exportStar(require("./decorators.cjs"), exports);
|
|
20
|
+
__exportStar(require("./Model.cjs"), exports);
|
|
21
|
+
__exportStar(require("./ModelErrorDefinition.cjs"), exports);
|
|
22
|
+
__exportStar(require("./types.cjs"), exports);
|
|
23
|
+
__exportStar(require("./validation.cjs"), exports);
|
package/lib/model/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validate = validate;
|
|
4
|
-
const ModelErrorDefinition_1 = require("./ModelErrorDefinition");
|
|
4
|
+
const ModelErrorDefinition_1 = require("./ModelErrorDefinition.cjs");
|
|
5
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");
|
|
6
|
+
const constants_1 = require("../utils/constants.cjs");
|
|
7
|
+
const strings_1 = require("../utils/strings.cjs");
|
|
8
|
+
const constants_2 = require("./constants.cjs");
|
|
9
|
+
const Model_1 = require("./Model.cjs");
|
|
10
|
+
const Validation_1 = require("../validation/Validation.cjs");
|
|
11
|
+
const constants_3 = require("../validation/Validators/constants.cjs");
|
|
12
12
|
/**
|
|
13
13
|
* @summary Analyses the decorations of the properties and validates the obj according to them
|
|
14
14
|
*
|
|
@@ -7,8 +7,8 @@ exports.twoDigitPad = twoDigitPad;
|
|
|
7
7
|
exports.formatDate = formatDate;
|
|
8
8
|
exports.parseDate = parseDate;
|
|
9
9
|
require("reflect-metadata");
|
|
10
|
-
const constants_1 = require("../validation/Validators/constants");
|
|
11
|
-
const strings_1 = require("./strings");
|
|
10
|
+
const constants_1 = require("../validation/Validators/constants.cjs");
|
|
11
|
+
const strings_1 = require("./strings.cjs");
|
|
12
12
|
/**
|
|
13
13
|
* @summary Reverses the process from {@link formatDate}
|
|
14
14
|
*
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.prop = prop;
|
|
4
4
|
exports.propMetadata = propMetadata;
|
|
5
5
|
const reflection_1 = require("@decaf-ts/reflection");
|
|
6
|
-
const constants_1 = require("./constants");
|
|
6
|
+
const constants_1 = require("./constants.cjs");
|
|
7
7
|
function prop(key = constants_1.ModelKeys.ATTRIBUTE) {
|
|
8
8
|
return (model, propertyKey) => {
|
|
9
9
|
let props;
|
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Hashing = exports.DefaultHashingMethod = void 0;
|
|
4
4
|
exports.hashCode = hashCode;
|
|
5
|
-
exports.hashSerialization = hashSerialization;
|
|
6
5
|
exports.hashObj = hashObj;
|
|
7
|
-
const serialization_1 = require("./serialization");
|
|
8
6
|
/**
|
|
9
7
|
* @summary Mimics Java's String's Hash implementation
|
|
10
8
|
*
|
|
@@ -25,22 +23,6 @@ function hashCode(obj) {
|
|
|
25
23
|
}
|
|
26
24
|
return hash.toString();
|
|
27
25
|
}
|
|
28
|
-
/**
|
|
29
|
-
* @summary Hashes an object serializing it and then hashing the string
|
|
30
|
-
* @description The Serialization algorithm used by default (JSON.stringify)
|
|
31
|
-
* is not deterministic and should not be used for hashing
|
|
32
|
-
*
|
|
33
|
-
* @param {Record<string, any>} obj
|
|
34
|
-
* @return {string} the resulting hash
|
|
35
|
-
*
|
|
36
|
-
* @function hashSerialization
|
|
37
|
-
* @memberOf module:decorator-validation.Utils.Hashing
|
|
38
|
-
*
|
|
39
|
-
* @category Hashing
|
|
40
|
-
*/
|
|
41
|
-
function hashSerialization(obj) {
|
|
42
|
-
return hashCode(serialization_1.Serialization.serialize(obj));
|
|
43
|
-
}
|
|
44
26
|
/**
|
|
45
27
|
* @summary Hashes an object by combining the hash of all its properties
|
|
46
28
|
*
|
package/lib/utils/hashing.d.ts
CHANGED
|
@@ -15,20 +15,6 @@ export declare function hashCode(obj: string | number | symbol | Date): string;
|
|
|
15
15
|
* @category Hashing
|
|
16
16
|
*/
|
|
17
17
|
export type HashingFunction = (value: any, ...args: any[]) => string;
|
|
18
|
-
/**
|
|
19
|
-
* @summary Hashes an object serializing it and then hashing the string
|
|
20
|
-
* @description The Serialization algorithm used by default (JSON.stringify)
|
|
21
|
-
* is not deterministic and should not be used for hashing
|
|
22
|
-
*
|
|
23
|
-
* @param {Record<string, any>} obj
|
|
24
|
-
* @return {string} the resulting hash
|
|
25
|
-
*
|
|
26
|
-
* @function hashSerialization
|
|
27
|
-
* @memberOf module:decorator-validation.Utils.Hashing
|
|
28
|
-
*
|
|
29
|
-
* @category Hashing
|
|
30
|
-
*/
|
|
31
|
-
export declare function hashSerialization(obj: Record<string, any> | any[]): string;
|
|
32
18
|
/**
|
|
33
19
|
* @summary Hashes an object by combining the hash of all its properties
|
|
34
20
|
*
|
|
@@ -14,11 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./constants"), exports);
|
|
18
|
-
__exportStar(require("./
|
|
19
|
-
__exportStar(require("./decorators"), exports);
|
|
20
|
-
__exportStar(require("./
|
|
21
|
-
__exportStar(require("./
|
|
22
|
-
__exportStar(require("./
|
|
23
|
-
__exportStar(require("./
|
|
24
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./constants.cjs"), exports);
|
|
18
|
+
__exportStar(require("./dates.cjs"), exports);
|
|
19
|
+
__exportStar(require("./decorators.cjs"), exports);
|
|
20
|
+
__exportStar(require("./hashing.cjs"), exports);
|
|
21
|
+
__exportStar(require("./registry.cjs"), exports);
|
|
22
|
+
__exportStar(require("./serialization.cjs"), exports);
|
|
23
|
+
__exportStar(require("./strings.cjs"), exports);
|
|
24
|
+
__exportStar(require("./types.cjs"), exports);
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Serialization = exports.
|
|
4
|
-
const Model_1 = require("../model/Model");
|
|
5
|
-
const constants_1 = require("./constants");
|
|
3
|
+
exports.Serialization = exports.JSONSerializer = exports.DefaultSerializationMethod = void 0;
|
|
4
|
+
const Model_1 = require("../model/Model.cjs");
|
|
5
|
+
const constants_1 = require("./constants.cjs");
|
|
6
|
+
exports.DefaultSerializationMethod = "json";
|
|
6
7
|
/**
|
|
7
8
|
* @summary Concrete implementation of a {@link Serializer} in JSON format
|
|
8
9
|
* @description JS's native JSON.stringify (used here) is not deterministic
|
|
@@ -17,6 +18,7 @@ const constants_1 = require("./constants");
|
|
|
17
18
|
* @category Serialization
|
|
18
19
|
*/
|
|
19
20
|
class JSONSerializer {
|
|
21
|
+
constructor() { }
|
|
20
22
|
/**
|
|
21
23
|
* @summary prepares the model for serialization
|
|
22
24
|
* @description returns a shallow copy of the object, containing an enumerable {@link ModelKeys#ANCHOR} property
|
|
@@ -57,7 +59,6 @@ class JSONSerializer {
|
|
|
57
59
|
}
|
|
58
60
|
}
|
|
59
61
|
exports.JSONSerializer = JSONSerializer;
|
|
60
|
-
exports.DefaultSerializationMethod = "json";
|
|
61
62
|
class Serialization {
|
|
62
63
|
static { this.current = exports.DefaultSerializationMethod; }
|
|
63
64
|
static { this.cache = {
|
|
@@ -1,33 +1,7 @@
|
|
|
1
|
-
import { Model } from "../model/Model";
|
|
2
1
|
import { Constructor } from "../model/types";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @interface Serializer
|
|
7
|
-
* @category Serialization
|
|
8
|
-
*/
|
|
9
|
-
export interface Serializer<T extends Model> {
|
|
10
|
-
/**
|
|
11
|
-
* @summary Serializes a model
|
|
12
|
-
* @param {T} model
|
|
13
|
-
*
|
|
14
|
-
* @param args
|
|
15
|
-
* @method
|
|
16
|
-
*
|
|
17
|
-
* @throws {Error}
|
|
18
|
-
*/
|
|
19
|
-
serialize(model: T, ...args: any[]): string;
|
|
20
|
-
/**
|
|
21
|
-
* @summary Rebuilds a model from serialization
|
|
22
|
-
* @param {string} str
|
|
23
|
-
*
|
|
24
|
-
* @param args
|
|
25
|
-
* @method
|
|
26
|
-
*
|
|
27
|
-
* @throws {Error}
|
|
28
|
-
*/
|
|
29
|
-
deserialize(str: string, ...args: any[]): T;
|
|
30
|
-
}
|
|
2
|
+
import { Serializer } from "./types";
|
|
3
|
+
import { Model } from "../model/Model";
|
|
4
|
+
export declare const DefaultSerializationMethod = "json";
|
|
31
5
|
/**
|
|
32
6
|
* @summary Concrete implementation of a {@link Serializer} in JSON format
|
|
33
7
|
* @description JS's native JSON.stringify (used here) is not deterministic
|
|
@@ -42,6 +16,7 @@ export interface Serializer<T extends Model> {
|
|
|
42
16
|
* @category Serialization
|
|
43
17
|
*/
|
|
44
18
|
export declare class JSONSerializer<T extends Model> implements Serializer<T> {
|
|
19
|
+
constructor();
|
|
45
20
|
/**
|
|
46
21
|
* @summary prepares the model for serialization
|
|
47
22
|
* @description returns a shallow copy of the object, containing an enumerable {@link ModelKeys#ANCHOR} property
|
|
@@ -66,7 +41,6 @@ export declare class JSONSerializer<T extends Model> implements Serializer<T> {
|
|
|
66
41
|
*/
|
|
67
42
|
serialize(model: T): string;
|
|
68
43
|
}
|
|
69
|
-
export declare const DefaultSerializationMethod = "json";
|
|
70
44
|
export declare class Serialization {
|
|
71
45
|
private static current;
|
|
72
46
|
private static cache;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Model } from "../model";
|
|
2
|
+
/**
|
|
3
|
+
* @summary Helper in serialization
|
|
4
|
+
*
|
|
5
|
+
* @interface Serializer
|
|
6
|
+
* @category Serialization
|
|
7
|
+
*/
|
|
8
|
+
export interface Serializer<T extends Model> {
|
|
9
|
+
/**
|
|
10
|
+
* @summary Serializes a model
|
|
11
|
+
* @param {T} model
|
|
12
|
+
*
|
|
13
|
+
* @param args
|
|
14
|
+
* @method
|
|
15
|
+
*
|
|
16
|
+
* @throws {Error}
|
|
17
|
+
*/
|
|
18
|
+
serialize(model: T, ...args: any[]): string;
|
|
19
|
+
/**
|
|
20
|
+
* @summary Rebuilds a model from serialization
|
|
21
|
+
* @param {string} str
|
|
22
|
+
*
|
|
23
|
+
* @param args
|
|
24
|
+
* @method
|
|
25
|
+
*
|
|
26
|
+
* @throws {Error}
|
|
27
|
+
*/
|
|
28
|
+
deserialize(str: string, ...args: any[]): T;
|
|
29
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Validation = void 0;
|
|
4
|
-
const ValidatorRegistry_1 = require("./Validators/ValidatorRegistry");
|
|
5
|
-
const constants_1 = require("./Validators/constants");
|
|
4
|
+
const ValidatorRegistry_1 = require("./Validators/ValidatorRegistry.cjs");
|
|
5
|
+
const constants_1 = require("./Validators/constants.cjs");
|
|
6
6
|
/**
|
|
7
7
|
* @summary Static class acting as a namespace for the Validation
|
|
8
8
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Validator } from "./Validators/Validator";
|
|
2
|
-
import { IValidatorRegistry, ValidatorDefinition } from "./
|
|
2
|
+
import { IValidatorRegistry, ValidatorDefinition } from "./types";
|
|
3
3
|
/**
|
|
4
4
|
* @summary Static class acting as a namespace for the Validation
|
|
5
5
|
*
|
|
@@ -10,9 +10,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.DateValidator = void 0;
|
|
13
|
-
const Validator_1 = require("./Validator");
|
|
14
|
-
const constants_1 = require("./constants");
|
|
15
|
-
const decorators_1 = require("./decorators");
|
|
13
|
+
const Validator_1 = require("./Validator.cjs");
|
|
14
|
+
const constants_1 = require("./constants.cjs");
|
|
15
|
+
const decorators_1 = require("./decorators.cjs");
|
|
16
16
|
/**
|
|
17
17
|
* @summary Date Validator
|
|
18
18
|
*
|
|
@@ -10,9 +10,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.EmailValidator = void 0;
|
|
13
|
-
const constants_1 = require("./constants");
|
|
14
|
-
const PatternValidator_1 = require("./PatternValidator");
|
|
15
|
-
const decorators_1 = require("./decorators");
|
|
13
|
+
const constants_1 = require("./constants.cjs");
|
|
14
|
+
const PatternValidator_1 = require("./PatternValidator.cjs");
|
|
15
|
+
const decorators_1 = require("./decorators.cjs");
|
|
16
16
|
/**
|
|
17
17
|
* @summary Email Validator
|
|
18
18
|
*
|
|
@@ -10,9 +10,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.ListValidator = void 0;
|
|
13
|
-
const Validator_1 = require("./Validator");
|
|
14
|
-
const constants_1 = require("./constants");
|
|
15
|
-
const decorators_1 = require("./decorators");
|
|
13
|
+
const Validator_1 = require("./Validator.cjs");
|
|
14
|
+
const constants_1 = require("./constants.cjs");
|
|
15
|
+
const decorators_1 = require("./decorators.cjs");
|
|
16
16
|
/**
|
|
17
17
|
* @summary List Validator
|
|
18
18
|
*
|
|
@@ -10,9 +10,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.MaxLengthValidator = void 0;
|
|
13
|
-
const Validator_1 = require("./Validator");
|
|
14
|
-
const constants_1 = require("./constants");
|
|
15
|
-
const decorators_1 = require("./decorators");
|
|
13
|
+
const Validator_1 = require("./Validator.cjs");
|
|
14
|
+
const constants_1 = require("./constants.cjs");
|
|
15
|
+
const decorators_1 = require("./decorators.cjs");
|
|
16
16
|
/**
|
|
17
17
|
* @summary Maximum Length Validator
|
|
18
18
|
* @description Validates strings and Arrays on their maximum length
|