@decaf-ts/decorator-validation 1.5.7 → 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 +66 -0
- package/lib/esm/model/Model.js +93 -2
- package/lib/esm/model/index.d.ts +0 -2
- package/lib/esm/model/index.js +0 -2
- package/lib/esm/model/validation.js +2 -2
- 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} +107 -12
- package/lib/model/Model.d.ts +66 -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 -2
- package/lib/model/{validation.js → validation.cjs} +9 -9
- 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 -9
- 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/Registry.d.ts +0 -59
- package/lib/esm/model/Registry.js +0 -73
- package/lib/esm/model/utils.d.ts +0 -11
- package/lib/esm/model/utils.js +0 -25
- package/lib/esm/validation/Validators/types.d.ts +0 -88
- package/lib/model/Registry.d.ts +0 -59
- package/lib/model/Registry.js +0 -78
- package/lib/model/utils.d.ts +0 -11
- package/lib/model/utils.js +0 -29
- 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/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,73 +0,0 @@
|
|
|
1
|
-
import { Model } from "./Model";
|
|
2
|
-
import { sf } from "../utils/strings";
|
|
3
|
-
import { isModel } from "./utils";
|
|
4
|
-
/**
|
|
5
|
-
* @summary Util class to enable serialization and correct rebuilding
|
|
6
|
-
*
|
|
7
|
-
* @param {string} anchorKey defaults to {@link ModelKeys.ANCHOR}. The property name where the registered class name is stored;
|
|
8
|
-
* @param {function(Record<string, any>): boolean} [testFunction] method to test if the provided object is a Model Object. defaults to {@link isModel}
|
|
9
|
-
*
|
|
10
|
-
* @class ModelRegistryManager
|
|
11
|
-
* @implements ModelRegistry
|
|
12
|
-
*
|
|
13
|
-
* @category Model
|
|
14
|
-
*/
|
|
15
|
-
export class ModelRegistryManager {
|
|
16
|
-
constructor(testFunction = isModel) {
|
|
17
|
-
this.cache = {};
|
|
18
|
-
this.testFunction = testFunction;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* @summary register new Models
|
|
22
|
-
* @param {any} constructor
|
|
23
|
-
* @param {string} [name] when not defined, the name of the constructor will be used
|
|
24
|
-
*/
|
|
25
|
-
register(constructor, name) {
|
|
26
|
-
if (typeof constructor !== "function")
|
|
27
|
-
throw new Error("Model registering failed. Missing Class name or constructor");
|
|
28
|
-
name = name || constructor.name;
|
|
29
|
-
this.cache[name] = constructor;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* @summary Gets a registered Model {@link ModelConstructor}
|
|
33
|
-
* @param {string} name
|
|
34
|
-
*/
|
|
35
|
-
get(name) {
|
|
36
|
-
try {
|
|
37
|
-
return this.cache[name];
|
|
38
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* @param {Record<string, any>} obj
|
|
46
|
-
* @param {string} [clazz] when provided, it will attempt to find the matching constructor
|
|
47
|
-
*
|
|
48
|
-
* @throws Error If clazz is not found, or obj is not a {@link Model} meaning it has no {@link ModelKeys.ANCHOR} property
|
|
49
|
-
*/
|
|
50
|
-
build(obj = {}, clazz) {
|
|
51
|
-
if (!clazz && !this.testFunction(obj))
|
|
52
|
-
throw new Error("Provided obj is not a Model object");
|
|
53
|
-
const name = clazz || Model.getMetadata(obj);
|
|
54
|
-
if (!(name in this.cache))
|
|
55
|
-
throw new Error(sf("Provided class {0} is not a registered Model object", name));
|
|
56
|
-
return new this.cache[name](obj);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* @summary Bulk Registers Models
|
|
61
|
-
* @description Useful when using bundlers that might not evaluate all the code at once
|
|
62
|
-
*
|
|
63
|
-
* @param {Array<Constructor<T>> | Array<{name: string, constructor: Constructor<T>}>} [models]
|
|
64
|
-
*
|
|
65
|
-
* @memberOf module:decorator-validation.Model
|
|
66
|
-
* @category Model
|
|
67
|
-
*/
|
|
68
|
-
export function bulkModelRegister(...models) {
|
|
69
|
-
models.forEach((m) => {
|
|
70
|
-
const constructor = (m.constructor ? m.constructor : m);
|
|
71
|
-
Model.register(constructor, m.name);
|
|
72
|
-
});
|
|
73
|
-
}
|
package/lib/esm/model/utils.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Model } from "./Model";
|
|
2
|
-
export declare function isPropertyModel<M extends Model>(target: M, attribute: string): boolean | string | undefined;
|
|
3
|
-
/**
|
|
4
|
-
* @summary For Serialization/deserialization purposes.
|
|
5
|
-
* @description Reads the {@link ModelKeys.ANCHOR} property of a {@link Model} to discover the class to instantiate
|
|
6
|
-
*
|
|
7
|
-
* @function isModel
|
|
8
|
-
* @memberOf module:decorator-validation.Validation
|
|
9
|
-
* @category Validation
|
|
10
|
-
*/
|
|
11
|
-
export declare function isModel(target: Record<string, any>): boolean;
|
package/lib/esm/model/utils.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { ModelKeys } from "../utils/constants";
|
|
2
|
-
import { Model } from "./Model";
|
|
3
|
-
export function isPropertyModel(target, attribute) {
|
|
4
|
-
if (isModel(target[attribute]))
|
|
5
|
-
return true;
|
|
6
|
-
const metadata = Reflect.getMetadata(ModelKeys.TYPE, target, attribute);
|
|
7
|
-
return Model.get(metadata.name) ? metadata.name : undefined;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* @summary For Serialization/deserialization purposes.
|
|
11
|
-
* @description Reads the {@link ModelKeys.ANCHOR} property of a {@link Model} to discover the class to instantiate
|
|
12
|
-
*
|
|
13
|
-
* @function isModel
|
|
14
|
-
* @memberOf module:decorator-validation.Validation
|
|
15
|
-
* @category Validation
|
|
16
|
-
*/
|
|
17
|
-
export function isModel(target) {
|
|
18
|
-
try {
|
|
19
|
-
return target instanceof Model || !!Model.getMetadata(target);
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
21
|
-
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
2
|
-
import { IRegistry } from "../../utils/registry";
|
|
3
|
-
import { Constructor } from "../../model/types";
|
|
4
|
-
/**
|
|
5
|
-
* @summary Util type for {@link Validator} configuration
|
|
6
|
-
* @memberOf module:decorator-validation.Validation
|
|
7
|
-
* @category Validation
|
|
8
|
-
*/
|
|
9
|
-
export type ValidatorDefinition = {
|
|
10
|
-
validator: Constructor<Validator>;
|
|
11
|
-
validationKey: string;
|
|
12
|
-
save: boolean;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* @summary Base API for a {@link Validator} registry
|
|
16
|
-
*
|
|
17
|
-
* @interface ValidatorRegistry
|
|
18
|
-
* @extends IRegistry
|
|
19
|
-
*
|
|
20
|
-
* @category Validation
|
|
21
|
-
*/
|
|
22
|
-
export interface IValidatorRegistry<T extends Validator> extends IRegistry<T> {
|
|
23
|
-
/**
|
|
24
|
-
* @summary retrieves the custom keys
|
|
25
|
-
* @method
|
|
26
|
-
*/
|
|
27
|
-
getCustomKeys(): Record<string, string>;
|
|
28
|
-
/**
|
|
29
|
-
* @summary Retrieves the Registered validator keys
|
|
30
|
-
* @return {string[]} the registered validators keys
|
|
31
|
-
* @method
|
|
32
|
-
*/
|
|
33
|
-
getKeys(): string[];
|
|
34
|
-
/**
|
|
35
|
-
* @summary Registers the provided validators onto the registry
|
|
36
|
-
*
|
|
37
|
-
* @typedef T extends Validator
|
|
38
|
-
* @param {T[] | ValidatorDefinition[]} validator
|
|
39
|
-
* @method
|
|
40
|
-
*/
|
|
41
|
-
register<T extends Validator>(...validator: (T | ValidatorDefinition)[]): void;
|
|
42
|
-
/**
|
|
43
|
-
* @summary Retrieves the Validator constructor if registered
|
|
44
|
-
*
|
|
45
|
-
* @typedef T extends Validator
|
|
46
|
-
* @param {string} key one of the {@link ValidationKeys}
|
|
47
|
-
* @return {Validator | undefined} the registered Validator or undefined if there is nono matching the provided key
|
|
48
|
-
* @method
|
|
49
|
-
*/
|
|
50
|
-
get<T extends Validator>(key: string): T | undefined;
|
|
51
|
-
}
|
|
52
|
-
export type ValidatorOptions = {
|
|
53
|
-
message?: string;
|
|
54
|
-
};
|
|
55
|
-
export interface URLValidatorOptions extends ValidatorOptions {
|
|
56
|
-
types: string | string[] | {
|
|
57
|
-
name: string;
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
export interface TypeValidatorOptions extends ValidatorOptions {
|
|
61
|
-
types: string | string[] | {
|
|
62
|
-
name: string;
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
export interface StepValidatorOptions extends ValidatorOptions {
|
|
66
|
-
step: number | string;
|
|
67
|
-
}
|
|
68
|
-
export interface PatternValidatorOptions extends ValidatorOptions {
|
|
69
|
-
pattern?: RegExp | string;
|
|
70
|
-
}
|
|
71
|
-
export interface MinValidatorOptions extends ValidatorOptions {
|
|
72
|
-
min: number | Date | string;
|
|
73
|
-
}
|
|
74
|
-
export interface MinLengthValidatorOptions extends ValidatorOptions {
|
|
75
|
-
minLength: number;
|
|
76
|
-
}
|
|
77
|
-
export interface MaxValidatorOptions extends ValidatorOptions {
|
|
78
|
-
max: number | Date | string;
|
|
79
|
-
}
|
|
80
|
-
export interface MaxLengthValidatorOptions extends ValidatorOptions {
|
|
81
|
-
maxLength: number;
|
|
82
|
-
}
|
|
83
|
-
export interface ListValidatorOptions extends ValidatorOptions {
|
|
84
|
-
clazz: string[];
|
|
85
|
-
}
|
|
86
|
-
export interface DateValidatorOptions extends ValidatorOptions {
|
|
87
|
-
format?: string;
|
|
88
|
-
}
|
package/lib/model/Registry.d.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { Model } from "./Model";
|
|
2
|
-
import { BuilderRegistry } from "../utils/registry";
|
|
3
|
-
import { Constructor, ModelConstructor } from "./types";
|
|
4
|
-
/**
|
|
5
|
-
* @summary ModelRegistry Interface
|
|
6
|
-
*
|
|
7
|
-
* @interface ModelRegistry
|
|
8
|
-
* @extends BuilderRegistry<Model>
|
|
9
|
-
*
|
|
10
|
-
* @category Model
|
|
11
|
-
*/
|
|
12
|
-
export type ModelRegistry<T extends Model> = BuilderRegistry<T>;
|
|
13
|
-
/**
|
|
14
|
-
* @summary Util class to enable serialization and correct rebuilding
|
|
15
|
-
*
|
|
16
|
-
* @param {string} anchorKey defaults to {@link ModelKeys.ANCHOR}. The property name where the registered class name is stored;
|
|
17
|
-
* @param {function(Record<string, any>): boolean} [testFunction] method to test if the provided object is a Model Object. defaults to {@link isModel}
|
|
18
|
-
*
|
|
19
|
-
* @class ModelRegistryManager
|
|
20
|
-
* @implements ModelRegistry
|
|
21
|
-
*
|
|
22
|
-
* @category Model
|
|
23
|
-
*/
|
|
24
|
-
export declare class ModelRegistryManager<T extends Model> implements ModelRegistry<T> {
|
|
25
|
-
private cache;
|
|
26
|
-
private readonly testFunction;
|
|
27
|
-
constructor(testFunction?: (obj: Record<string, any>) => boolean);
|
|
28
|
-
/**
|
|
29
|
-
* @summary register new Models
|
|
30
|
-
* @param {any} constructor
|
|
31
|
-
* @param {string} [name] when not defined, the name of the constructor will be used
|
|
32
|
-
*/
|
|
33
|
-
register(constructor: ModelConstructor<T>, name?: string): void;
|
|
34
|
-
/**
|
|
35
|
-
* @summary Gets a registered Model {@link ModelConstructor}
|
|
36
|
-
* @param {string} name
|
|
37
|
-
*/
|
|
38
|
-
get(name: string): ModelConstructor<T> | undefined;
|
|
39
|
-
/**
|
|
40
|
-
* @param {Record<string, any>} obj
|
|
41
|
-
* @param {string} [clazz] when provided, it will attempt to find the matching constructor
|
|
42
|
-
*
|
|
43
|
-
* @throws Error If clazz is not found, or obj is not a {@link Model} meaning it has no {@link ModelKeys.ANCHOR} property
|
|
44
|
-
*/
|
|
45
|
-
build(obj?: Record<string, any>, clazz?: string): T;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* @summary Bulk Registers Models
|
|
49
|
-
* @description Useful when using bundlers that might not evaluate all the code at once
|
|
50
|
-
*
|
|
51
|
-
* @param {Array<Constructor<T>> | Array<{name: string, constructor: Constructor<T>}>} [models]
|
|
52
|
-
*
|
|
53
|
-
* @memberOf module:decorator-validation.Model
|
|
54
|
-
* @category Model
|
|
55
|
-
*/
|
|
56
|
-
export declare function bulkModelRegister<T extends Model>(...models: (Constructor<T> | {
|
|
57
|
-
name: string;
|
|
58
|
-
constructor: Constructor<T>;
|
|
59
|
-
})[]): void;
|
package/lib/model/Registry.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModelRegistryManager = void 0;
|
|
4
|
-
exports.bulkModelRegister = bulkModelRegister;
|
|
5
|
-
const Model_1 = require("./Model");
|
|
6
|
-
const strings_1 = require("../utils/strings");
|
|
7
|
-
const utils_1 = require("./utils");
|
|
8
|
-
/**
|
|
9
|
-
* @summary Util class to enable serialization and correct rebuilding
|
|
10
|
-
*
|
|
11
|
-
* @param {string} anchorKey defaults to {@link ModelKeys.ANCHOR}. The property name where the registered class name is stored;
|
|
12
|
-
* @param {function(Record<string, any>): boolean} [testFunction] method to test if the provided object is a Model Object. defaults to {@link isModel}
|
|
13
|
-
*
|
|
14
|
-
* @class ModelRegistryManager
|
|
15
|
-
* @implements ModelRegistry
|
|
16
|
-
*
|
|
17
|
-
* @category Model
|
|
18
|
-
*/
|
|
19
|
-
class ModelRegistryManager {
|
|
20
|
-
constructor(testFunction = utils_1.isModel) {
|
|
21
|
-
this.cache = {};
|
|
22
|
-
this.testFunction = testFunction;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* @summary register new Models
|
|
26
|
-
* @param {any} constructor
|
|
27
|
-
* @param {string} [name] when not defined, the name of the constructor will be used
|
|
28
|
-
*/
|
|
29
|
-
register(constructor, name) {
|
|
30
|
-
if (typeof constructor !== "function")
|
|
31
|
-
throw new Error("Model registering failed. Missing Class name or constructor");
|
|
32
|
-
name = name || constructor.name;
|
|
33
|
-
this.cache[name] = constructor;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* @summary Gets a registered Model {@link ModelConstructor}
|
|
37
|
-
* @param {string} name
|
|
38
|
-
*/
|
|
39
|
-
get(name) {
|
|
40
|
-
try {
|
|
41
|
-
return this.cache[name];
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
43
|
-
}
|
|
44
|
-
catch (e) {
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* @param {Record<string, any>} obj
|
|
50
|
-
* @param {string} [clazz] when provided, it will attempt to find the matching constructor
|
|
51
|
-
*
|
|
52
|
-
* @throws Error If clazz is not found, or obj is not a {@link Model} meaning it has no {@link ModelKeys.ANCHOR} property
|
|
53
|
-
*/
|
|
54
|
-
build(obj = {}, clazz) {
|
|
55
|
-
if (!clazz && !this.testFunction(obj))
|
|
56
|
-
throw new Error("Provided obj is not a Model object");
|
|
57
|
-
const name = clazz || Model_1.Model.getMetadata(obj);
|
|
58
|
-
if (!(name in this.cache))
|
|
59
|
-
throw new Error((0, strings_1.sf)("Provided class {0} is not a registered Model object", name));
|
|
60
|
-
return new this.cache[name](obj);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.ModelRegistryManager = ModelRegistryManager;
|
|
64
|
-
/**
|
|
65
|
-
* @summary Bulk Registers Models
|
|
66
|
-
* @description Useful when using bundlers that might not evaluate all the code at once
|
|
67
|
-
*
|
|
68
|
-
* @param {Array<Constructor<T>> | Array<{name: string, constructor: Constructor<T>}>} [models]
|
|
69
|
-
*
|
|
70
|
-
* @memberOf module:decorator-validation.Model
|
|
71
|
-
* @category Model
|
|
72
|
-
*/
|
|
73
|
-
function bulkModelRegister(...models) {
|
|
74
|
-
models.forEach((m) => {
|
|
75
|
-
const constructor = (m.constructor ? m.constructor : m);
|
|
76
|
-
Model_1.Model.register(constructor, m.name);
|
|
77
|
-
});
|
|
78
|
-
}
|
package/lib/model/utils.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Model } from "./Model";
|
|
2
|
-
export declare function isPropertyModel<M extends Model>(target: M, attribute: string): boolean | string | undefined;
|
|
3
|
-
/**
|
|
4
|
-
* @summary For Serialization/deserialization purposes.
|
|
5
|
-
* @description Reads the {@link ModelKeys.ANCHOR} property of a {@link Model} to discover the class to instantiate
|
|
6
|
-
*
|
|
7
|
-
* @function isModel
|
|
8
|
-
* @memberOf module:decorator-validation.Validation
|
|
9
|
-
* @category Validation
|
|
10
|
-
*/
|
|
11
|
-
export declare function isModel(target: Record<string, any>): boolean;
|
package/lib/model/utils.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isPropertyModel = isPropertyModel;
|
|
4
|
-
exports.isModel = isModel;
|
|
5
|
-
const constants_1 = require("../utils/constants");
|
|
6
|
-
const Model_1 = require("./Model");
|
|
7
|
-
function isPropertyModel(target, attribute) {
|
|
8
|
-
if (isModel(target[attribute]))
|
|
9
|
-
return true;
|
|
10
|
-
const metadata = Reflect.getMetadata(constants_1.ModelKeys.TYPE, target, attribute);
|
|
11
|
-
return Model_1.Model.get(metadata.name) ? metadata.name : undefined;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* @summary For Serialization/deserialization purposes.
|
|
15
|
-
* @description Reads the {@link ModelKeys.ANCHOR} property of a {@link Model} to discover the class to instantiate
|
|
16
|
-
*
|
|
17
|
-
* @function isModel
|
|
18
|
-
* @memberOf module:decorator-validation.Validation
|
|
19
|
-
* @category Validation
|
|
20
|
-
*/
|
|
21
|
-
function isModel(target) {
|
|
22
|
-
try {
|
|
23
|
-
return target instanceof Model_1.Model || !!Model_1.Model.getMetadata(target);
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
25
|
-
}
|
|
26
|
-
catch (e) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
2
|
-
/**
|
|
3
|
-
* @summary Marks the class as a validator for a certain key.
|
|
4
|
-
* @description Registers the class in the {@link Validation} with the provided key
|
|
5
|
-
*
|
|
6
|
-
* @param {string} keys the validation key
|
|
7
|
-
*
|
|
8
|
-
* @function validator
|
|
9
|
-
*
|
|
10
|
-
* @category Decorators
|
|
11
|
-
*/
|
|
12
|
-
export declare function validator<T extends Validator>(...keys: string[]): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { DateValidator } from "./DateValidator";
|
|
2
|
-
import { TypeValidator } from "./TypeValidator";
|
|
3
|
-
import { PasswordValidator } from "./PasswordValidator";
|
|
4
|
-
import { StepValidator } from "./StepValidator";
|
|
5
|
-
import { URLValidator } from "./URLValidator";
|
|
6
|
-
import { PatternValidator } from "./PatternValidator";
|
|
7
|
-
import { MinValidator } from "./MinValidator";
|
|
8
|
-
import { MinLengthValidator } from "./MinLengthValidator";
|
|
9
|
-
import { MaxValidator } from "./MaxValidator";
|
|
10
|
-
import { MaxLengthValidator } from "./MaxLengthValidator";
|
|
11
|
-
import { RequiredValidator } from "./RequiredValidator";
|
|
12
|
-
import { EmailValidator } from "./EmailValidator";
|
|
13
|
-
import { ListValidator } from "./ListValidator";
|
|
14
|
-
export * from "./constants";
|
|
15
|
-
export * from "./DateValidator";
|
|
16
|
-
export * from "./decorators";
|
|
17
|
-
export * from "./EmailValidator";
|
|
18
|
-
export * from "./ListValidator";
|
|
19
|
-
export * from "./MaxLengthValidator";
|
|
20
|
-
export * from "./MaxValidator";
|
|
21
|
-
export * from "./MinLengthValidator";
|
|
22
|
-
export * from "./MinValidator";
|
|
23
|
-
export * from "./PasswordValidator";
|
|
24
|
-
export * from "./PatternValidator";
|
|
25
|
-
export * from "./RequiredValidator";
|
|
26
|
-
export * from "./StepValidator";
|
|
27
|
-
export * from "./types";
|
|
28
|
-
export * from "./TypeValidator";
|
|
29
|
-
export * from "./URLValidator";
|
|
30
|
-
export * from "./Validator";
|
|
31
|
-
export * from "./ValidatorRegistry";
|
|
32
|
-
/**
|
|
33
|
-
* @summary constant holding all {@link Validator}s
|
|
34
|
-
* @constant Validators
|
|
35
|
-
* @memberOf module:decorator-validation.Validation.Validators
|
|
36
|
-
* @category Validation
|
|
37
|
-
*/
|
|
38
|
-
export declare const Validators: {
|
|
39
|
-
DateValidator: typeof DateValidator;
|
|
40
|
-
EmailValidator: typeof EmailValidator;
|
|
41
|
-
ListValidator: typeof ListValidator;
|
|
42
|
-
MaxLengthValidator: typeof MaxLengthValidator;
|
|
43
|
-
MaxValidator: typeof MaxValidator;
|
|
44
|
-
MinLengthValidator: typeof MinLengthValidator;
|
|
45
|
-
MinValidator: typeof MinValidator;
|
|
46
|
-
PasswordValidator: typeof PasswordValidator;
|
|
47
|
-
PatternValidator: typeof PatternValidator;
|
|
48
|
-
RequiredValidator: typeof RequiredValidator;
|
|
49
|
-
StepValidator: typeof StepValidator;
|
|
50
|
-
TypeValidator: typeof TypeValidator;
|
|
51
|
-
URLValidator: typeof URLValidator;
|
|
52
|
-
};
|
|
@@ -1,69 +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
|
-
exports.Validators = void 0;
|
|
18
|
-
const DateValidator_1 = require("./DateValidator");
|
|
19
|
-
const TypeValidator_1 = require("./TypeValidator");
|
|
20
|
-
const PasswordValidator_1 = require("./PasswordValidator");
|
|
21
|
-
const StepValidator_1 = require("./StepValidator");
|
|
22
|
-
const URLValidator_1 = require("./URLValidator");
|
|
23
|
-
const PatternValidator_1 = require("./PatternValidator");
|
|
24
|
-
const MinValidator_1 = require("./MinValidator");
|
|
25
|
-
const MinLengthValidator_1 = require("./MinLengthValidator");
|
|
26
|
-
const MaxValidator_1 = require("./MaxValidator");
|
|
27
|
-
const MaxLengthValidator_1 = require("./MaxLengthValidator");
|
|
28
|
-
const RequiredValidator_1 = require("./RequiredValidator");
|
|
29
|
-
const EmailValidator_1 = require("./EmailValidator");
|
|
30
|
-
const ListValidator_1 = require("./ListValidator");
|
|
31
|
-
__exportStar(require("./constants"), exports);
|
|
32
|
-
__exportStar(require("./DateValidator"), exports);
|
|
33
|
-
__exportStar(require("./decorators"), exports);
|
|
34
|
-
__exportStar(require("./EmailValidator"), exports);
|
|
35
|
-
__exportStar(require("./ListValidator"), exports);
|
|
36
|
-
__exportStar(require("./MaxLengthValidator"), exports);
|
|
37
|
-
__exportStar(require("./MaxValidator"), exports);
|
|
38
|
-
__exportStar(require("./MinLengthValidator"), exports);
|
|
39
|
-
__exportStar(require("./MinValidator"), exports);
|
|
40
|
-
__exportStar(require("./PasswordValidator"), exports);
|
|
41
|
-
__exportStar(require("./PatternValidator"), exports);
|
|
42
|
-
__exportStar(require("./RequiredValidator"), exports);
|
|
43
|
-
__exportStar(require("./StepValidator"), exports);
|
|
44
|
-
__exportStar(require("./types"), exports);
|
|
45
|
-
__exportStar(require("./TypeValidator"), exports);
|
|
46
|
-
__exportStar(require("./URLValidator"), exports);
|
|
47
|
-
__exportStar(require("./Validator"), exports);
|
|
48
|
-
__exportStar(require("./ValidatorRegistry"), exports);
|
|
49
|
-
/**
|
|
50
|
-
* @summary constant holding all {@link Validator}s
|
|
51
|
-
* @constant Validators
|
|
52
|
-
* @memberOf module:decorator-validation.Validation.Validators
|
|
53
|
-
* @category Validation
|
|
54
|
-
*/
|
|
55
|
-
exports.Validators = {
|
|
56
|
-
DateValidator: DateValidator_1.DateValidator,
|
|
57
|
-
EmailValidator: EmailValidator_1.EmailValidator,
|
|
58
|
-
ListValidator: ListValidator_1.ListValidator,
|
|
59
|
-
MaxLengthValidator: MaxLengthValidator_1.MaxLengthValidator,
|
|
60
|
-
MaxValidator: MaxValidator_1.MaxValidator,
|
|
61
|
-
MinLengthValidator: MinLengthValidator_1.MinLengthValidator,
|
|
62
|
-
MinValidator: MinValidator_1.MinValidator,
|
|
63
|
-
PasswordValidator: PasswordValidator_1.PasswordValidator,
|
|
64
|
-
PatternValidator: PatternValidator_1.PatternValidator,
|
|
65
|
-
RequiredValidator: RequiredValidator_1.RequiredValidator,
|
|
66
|
-
StepValidator: StepValidator_1.StepValidator,
|
|
67
|
-
TypeValidator: TypeValidator_1.TypeValidator,
|
|
68
|
-
URLValidator: URLValidator_1.URLValidator,
|
|
69
|
-
};
|
/package/dist/{decorator-validation.js.LICENSE.txt → decorator-validation.bundle.min.js.LICENSE.txt}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|