@muziehdesign/forms 0.0.1-alpha.55 → 0.0.1-alpha.67
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/esm2020/lib/model-schema.factory.mjs +15 -4
- package/esm2020/lib/type-annotations.mjs +65 -3
- package/fesm2015/muziehdesign-forms.mjs +78 -5
- package/fesm2015/muziehdesign-forms.mjs.map +1 -1
- package/fesm2020/muziehdesign-forms.mjs +78 -5
- package/fesm2020/muziehdesign-forms.mjs.map +1 -1
- package/lib/type-annotations.d.ts +46 -2
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
|
|
|
2
2
|
import { object } from 'yup';
|
|
3
3
|
import { ModelValidator } from './model-validator';
|
|
4
4
|
import { SCHEMA_METADATA_NAMESPACE } from './constants';
|
|
5
|
-
import {
|
|
5
|
+
import { ConstraintType } from './type-annotations';
|
|
6
6
|
import * as Yup from 'yup';
|
|
7
7
|
import * as i0 from "@angular/core";
|
|
8
8
|
export class ModelSchemaFactory {
|
|
@@ -11,14 +11,16 @@ export class ModelSchemaFactory {
|
|
|
11
11
|
const metadata = Reflect.getMetadata(SCHEMA_METADATA_NAMESPACE, model);
|
|
12
12
|
let shape = {};
|
|
13
13
|
metadata.forEach((value, key) => {
|
|
14
|
-
if (value.constraintType ==
|
|
14
|
+
if (value.constraintType == ConstraintType.string) {
|
|
15
15
|
shape[key] = this.buildStringSchema(value);
|
|
16
16
|
}
|
|
17
|
-
else if (value.constraintType ==
|
|
17
|
+
else if (value.constraintType == ConstraintType.boolean) {
|
|
18
18
|
shape[key] = this.buildBooleanSchema(value);
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
21
|
const schema = object(shape);
|
|
22
|
+
console.log(schema);
|
|
23
|
+
console.log(schema.isValidSync({ instructions: null }));
|
|
22
24
|
return new ModelValidator(schema);
|
|
23
25
|
}
|
|
24
26
|
buildStringSchema(options) {
|
|
@@ -29,6 +31,15 @@ export class ModelSchemaFactory {
|
|
|
29
31
|
if (options.length) {
|
|
30
32
|
schema = schema.length(options.length.length, options.length.message);
|
|
31
33
|
}
|
|
34
|
+
if (options.maxLength) {
|
|
35
|
+
schema = schema.max(options.maxLength.maxLength, options.maxLength.message);
|
|
36
|
+
}
|
|
37
|
+
if (options.minLength) {
|
|
38
|
+
schema = schema.min(options.minLength.minLength, options.minLength.message);
|
|
39
|
+
}
|
|
40
|
+
if (options.pattern) {
|
|
41
|
+
schema = schema.matches(options.pattern.pattern, options.pattern.message);
|
|
42
|
+
}
|
|
32
43
|
return schema;
|
|
33
44
|
}
|
|
34
45
|
buildBooleanSchema(options) {
|
|
@@ -55,4 +66,4 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.5", ngImpor
|
|
|
55
66
|
providedIn: 'root',
|
|
56
67
|
}]
|
|
57
68
|
}], ctorParameters: function () { return []; } });
|
|
58
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
69
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibW9kZWwtc2NoZW1hLmZhY3RvcnkuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9wcm9qZWN0cy9tdXppZWhkZXNpZ24vZm9ybXMvc3JjL2xpYi9tb2RlbC1zY2hlbWEuZmFjdG9yeS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sZUFBZSxDQUFDO0FBQzNDLE9BQU8sRUFBRSxNQUFNLEVBQVksTUFBTSxLQUFLLENBQUM7QUFDdkMsT0FBTyxFQUFFLGNBQWMsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBQ25ELE9BQU8sRUFBRSx5QkFBeUIsRUFBRSxNQUFNLGFBQWEsQ0FBQztBQUV4RCxPQUFPLEVBQThELGNBQWMsRUFBc0MsTUFBTSxvQkFBb0IsQ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lKTtcbiAgICB9XG5cbiAgICByZXR1cm4gc2NoZW1hO1xuICB9XG5cbiAgcHJpdmF0ZSBidWlsZEJvb2xlYW5TY2hlbWEob3B0aW9uczogQm9vbGVhblR5cGVBbm5vdGF0aW9ucykge1xuICAgIGxldCBzY2hlbWEgPSBZdXAuYm9vbGVhbigpO1xuICAgIGlmIChvcHRpb25zLnJlcXVpcmVkKSB7XG4gICAgICBzY2hlbWEgPSBzY2hlbWEucmVxdWlyZWQob3B0aW9ucy5yZXF1aXJlZC5tZXNzYWdlKTtcbiAgICB9XG4gICAgaWYgKG9wdGlvbnMuZXF1YWxzKSB7XG4gICAgICBpZiAob3B0aW9ucy5lcXVhbHMuZXF1YWxzKSB7XG4gICAgICAgIHNjaGVtYSA9IHNjaGVtYS5pc1RydWUob3B0aW9ucy5lcXVhbHMubWVzc2FnZSk7XG4gICAgICB9IGVsc2Uge1xuICAgICAgICBzY2hlbWEgPSBzY2hlbWEuaXNGYWxzZShvcHRpb25zLmVxdWFscy5tZXNzYWdlKTtcbiAgICAgIH1cbiAgICB9XG5cbiAgICByZXR1cm4gc2NoZW1hO1xuICB9XG59XG4iXX0=
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
const METADATA_KEY = 'custom:muziehdesign:annotations';
|
|
3
|
+
export var ConstraintType;
|
|
4
|
+
(function (ConstraintType) {
|
|
5
|
+
ConstraintType[ConstraintType["string"] = 0] = "string";
|
|
6
|
+
ConstraintType[ConstraintType["boolean"] = 1] = "boolean";
|
|
7
|
+
})(ConstraintType || (ConstraintType = {}));
|
|
3
8
|
const registerMetadata = (target, propertyKey, constraint) => {
|
|
4
9
|
const metadata = Reflect.getMetadata(METADATA_KEY, target) || new Map();
|
|
5
10
|
metadata.set(propertyKey, constraint);
|
|
@@ -13,30 +18,87 @@ export function OfValues<T>(values: T[], message?: string) {
|
|
|
13
18
|
registerMetadata(target, propertyKey, o);
|
|
14
19
|
};
|
|
15
20
|
}*/
|
|
21
|
+
export function Annotate(a) {
|
|
22
|
+
return function (target, propertyKey) {
|
|
23
|
+
console.log('annotations', a.annotations);
|
|
24
|
+
registerMetadata(target, propertyKey, a.annotations);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
16
27
|
export function StringType(...annotations) {
|
|
17
28
|
return function (target, propertyKey) {
|
|
18
29
|
const o = Object.assign({}, ...annotations);
|
|
19
|
-
o.constraintType =
|
|
30
|
+
o.constraintType = ConstraintType.string;
|
|
20
31
|
registerMetadata(target, propertyKey, o);
|
|
21
32
|
};
|
|
22
33
|
}
|
|
23
34
|
export function BooleanType(...annotations) {
|
|
24
35
|
return function (target, propertyKey) {
|
|
25
36
|
const o = Object.assign({}, ...annotations);
|
|
26
|
-
o.constraintType =
|
|
37
|
+
o.constraintType = ConstraintType.boolean;
|
|
27
38
|
registerMetadata(target, propertyKey, o);
|
|
28
39
|
};
|
|
29
40
|
}
|
|
30
41
|
export function required(message) {
|
|
31
42
|
return { required: { required: true, message: message } };
|
|
32
43
|
}
|
|
44
|
+
export function pattern(regex, message) {
|
|
45
|
+
return { pattern: { pattern: regex, message: message } };
|
|
46
|
+
}
|
|
33
47
|
export function length(length, message) {
|
|
34
48
|
return { length: { length: length, message: message } };
|
|
35
49
|
}
|
|
50
|
+
export function maxLength(maxLength, message) {
|
|
51
|
+
return { maxLength: { maxLength: maxLength, message: message } };
|
|
52
|
+
}
|
|
53
|
+
export function minLength(minLength, message) {
|
|
54
|
+
return { minLength: { minLength: minLength, message: message } };
|
|
55
|
+
}
|
|
36
56
|
export function ofValues(values, message) {
|
|
37
57
|
return { ofValues: { values: values, message: message } };
|
|
38
58
|
}
|
|
39
59
|
export function equals(value, message) {
|
|
40
60
|
return { equals: { equals: value, message: message } };
|
|
41
61
|
}
|
|
42
|
-
|
|
62
|
+
export class AnnotationType {
|
|
63
|
+
}
|
|
64
|
+
export class StringType2 extends AnnotationType {
|
|
65
|
+
constructor() {
|
|
66
|
+
super(...arguments);
|
|
67
|
+
this.name = 'StringType';
|
|
68
|
+
this.annotations = {
|
|
69
|
+
constraintType: ConstraintType.string, // TODO
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
required(message) {
|
|
73
|
+
this.annotations.required = { required: true, message: message };
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
pattern(pattern, message) {
|
|
77
|
+
this.annotations.pattern = { pattern: pattern, message: message };
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export class BooleanType2 extends AnnotationType {
|
|
82
|
+
constructor() {
|
|
83
|
+
super(...arguments);
|
|
84
|
+
this.name = 'BooleanType';
|
|
85
|
+
this.annotations = {
|
|
86
|
+
constraintType: ConstraintType.boolean, // TODO
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
required(message) {
|
|
90
|
+
this.annotations.required = { required: true, message: message };
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
equals(v, message) {
|
|
94
|
+
this.annotations.equals = { equals: v, message: message };
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
export function string() {
|
|
99
|
+
return new StringType2();
|
|
100
|
+
}
|
|
101
|
+
export function boolean() {
|
|
102
|
+
return new BooleanType2();
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZS1hbm5vdGF0aW9ucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3Byb2plY3RzL211emllaGRlc2lnbi9mb3Jtcy9zcmMvbGliL3R5cGUtYW5ub3RhdGlvbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxrQkFBa0IsQ0FBQztBQUsxQixNQUFNLFlBQVksR0FBRyxpQ0FBaUMsQ0FBQztBQUV2RCxNQUFNLENBQU4sSUFBWSxjQUdYO0FBSEQsV0FBWSxjQU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@ class ModelValidator {
|
|
|
25
25
|
const SCHEMA_METADATA_NAMESPACE = 'custom:muziehdesign:annotations';
|
|
26
26
|
|
|
27
27
|
const METADATA_KEY = 'custom:muziehdesign:annotations';
|
|
28
|
+
var ConstraintType;
|
|
29
|
+
(function (ConstraintType) {
|
|
30
|
+
ConstraintType[ConstraintType["string"] = 0] = "string";
|
|
31
|
+
ConstraintType[ConstraintType["boolean"] = 1] = "boolean";
|
|
32
|
+
})(ConstraintType || (ConstraintType = {}));
|
|
28
33
|
const registerMetadata = (target, propertyKey, constraint) => {
|
|
29
34
|
const metadata = Reflect.getMetadata(METADATA_KEY, target) || new Map();
|
|
30
35
|
metadata.set(propertyKey, constraint);
|
|
@@ -38,32 +43,89 @@ export function OfValues<T>(values: T[], message?: string) {
|
|
|
38
43
|
registerMetadata(target, propertyKey, o);
|
|
39
44
|
};
|
|
40
45
|
}*/
|
|
46
|
+
function Annotate(a) {
|
|
47
|
+
return function (target, propertyKey) {
|
|
48
|
+
console.log('annotations', a.annotations);
|
|
49
|
+
registerMetadata(target, propertyKey, a.annotations);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
41
52
|
function StringType(...annotations) {
|
|
42
53
|
return function (target, propertyKey) {
|
|
43
54
|
const o = Object.assign({}, ...annotations);
|
|
44
|
-
o.constraintType =
|
|
55
|
+
o.constraintType = ConstraintType.string;
|
|
45
56
|
registerMetadata(target, propertyKey, o);
|
|
46
57
|
};
|
|
47
58
|
}
|
|
48
59
|
function BooleanType(...annotations) {
|
|
49
60
|
return function (target, propertyKey) {
|
|
50
61
|
const o = Object.assign({}, ...annotations);
|
|
51
|
-
o.constraintType =
|
|
62
|
+
o.constraintType = ConstraintType.boolean;
|
|
52
63
|
registerMetadata(target, propertyKey, o);
|
|
53
64
|
};
|
|
54
65
|
}
|
|
55
66
|
function required(message) {
|
|
56
67
|
return { required: { required: true, message: message } };
|
|
57
68
|
}
|
|
69
|
+
function pattern(regex, message) {
|
|
70
|
+
return { pattern: { pattern: regex, message: message } };
|
|
71
|
+
}
|
|
58
72
|
function length(length, message) {
|
|
59
73
|
return { length: { length: length, message: message } };
|
|
60
74
|
}
|
|
75
|
+
function maxLength(maxLength, message) {
|
|
76
|
+
return { maxLength: { maxLength: maxLength, message: message } };
|
|
77
|
+
}
|
|
78
|
+
function minLength(minLength, message) {
|
|
79
|
+
return { minLength: { minLength: minLength, message: message } };
|
|
80
|
+
}
|
|
61
81
|
function ofValues(values, message) {
|
|
62
82
|
return { ofValues: { values: values, message: message } };
|
|
63
83
|
}
|
|
64
84
|
function equals(value, message) {
|
|
65
85
|
return { equals: { equals: value, message: message } };
|
|
66
86
|
}
|
|
87
|
+
class AnnotationType {
|
|
88
|
+
}
|
|
89
|
+
class StringType2 extends AnnotationType {
|
|
90
|
+
constructor() {
|
|
91
|
+
super(...arguments);
|
|
92
|
+
this.name = 'StringType';
|
|
93
|
+
this.annotations = {
|
|
94
|
+
constraintType: ConstraintType.string, // TODO
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
required(message) {
|
|
98
|
+
this.annotations.required = { required: true, message: message };
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
pattern(pattern, message) {
|
|
102
|
+
this.annotations.pattern = { pattern: pattern, message: message };
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
class BooleanType2 extends AnnotationType {
|
|
107
|
+
constructor() {
|
|
108
|
+
super(...arguments);
|
|
109
|
+
this.name = 'BooleanType';
|
|
110
|
+
this.annotations = {
|
|
111
|
+
constraintType: ConstraintType.boolean, // TODO
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
required(message) {
|
|
115
|
+
this.annotations.required = { required: true, message: message };
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
equals(v, message) {
|
|
119
|
+
this.annotations.equals = { equals: v, message: message };
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function string() {
|
|
124
|
+
return new StringType2();
|
|
125
|
+
}
|
|
126
|
+
function boolean() {
|
|
127
|
+
return new BooleanType2();
|
|
128
|
+
}
|
|
67
129
|
|
|
68
130
|
class ModelSchemaFactory {
|
|
69
131
|
constructor() { }
|
|
@@ -71,14 +133,16 @@ class ModelSchemaFactory {
|
|
|
71
133
|
const metadata = Reflect.getMetadata(SCHEMA_METADATA_NAMESPACE, model);
|
|
72
134
|
let shape = {};
|
|
73
135
|
metadata.forEach((value, key) => {
|
|
74
|
-
if (value.constraintType ==
|
|
136
|
+
if (value.constraintType == ConstraintType.string) {
|
|
75
137
|
shape[key] = this.buildStringSchema(value);
|
|
76
138
|
}
|
|
77
|
-
else if (value.constraintType ==
|
|
139
|
+
else if (value.constraintType == ConstraintType.boolean) {
|
|
78
140
|
shape[key] = this.buildBooleanSchema(value);
|
|
79
141
|
}
|
|
80
142
|
});
|
|
81
143
|
const schema = object(shape);
|
|
144
|
+
console.log(schema);
|
|
145
|
+
console.log(schema.isValidSync({ instructions: null }));
|
|
82
146
|
return new ModelValidator(schema);
|
|
83
147
|
}
|
|
84
148
|
buildStringSchema(options) {
|
|
@@ -89,6 +153,15 @@ class ModelSchemaFactory {
|
|
|
89
153
|
if (options.length) {
|
|
90
154
|
schema = schema.length(options.length.length, options.length.message);
|
|
91
155
|
}
|
|
156
|
+
if (options.maxLength) {
|
|
157
|
+
schema = schema.max(options.maxLength.maxLength, options.maxLength.message);
|
|
158
|
+
}
|
|
159
|
+
if (options.minLength) {
|
|
160
|
+
schema = schema.min(options.minLength.minLength, options.minLength.message);
|
|
161
|
+
}
|
|
162
|
+
if (options.pattern) {
|
|
163
|
+
schema = schema.matches(options.pattern.pattern, options.pattern.message);
|
|
164
|
+
}
|
|
92
165
|
return schema;
|
|
93
166
|
}
|
|
94
167
|
buildBooleanSchema(options) {
|
|
@@ -193,5 +266,5 @@ class NgFormModelState {
|
|
|
193
266
|
* Generated bundle index. Do not edit.
|
|
194
267
|
*/
|
|
195
268
|
|
|
196
|
-
export { BooleanType, FormsModule, ModelSchemaFactory, ModelValidator, NgFormModelState, NgFormModelStateFactory, StringType, equals, length, ofValues, required };
|
|
269
|
+
export { Annotate, AnnotationType, BooleanType, BooleanType2, ConstraintType, FormsModule, ModelSchemaFactory, ModelValidator, NgFormModelState, NgFormModelStateFactory, StringType, StringType2, boolean, equals, length, maxLength, minLength, ofValues, pattern, required, string };
|
|
197
270
|
//# sourceMappingURL=muziehdesign-forms.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"muziehdesign-forms.mjs","sources":["../../../../projects/muziehdesign/forms/src/lib/model-validator.ts","../../../../projects/muziehdesign/forms/src/lib/constants.ts","../../../../projects/muziehdesign/forms/src/lib/type-annotations.ts","../../../../projects/muziehdesign/forms/src/lib/model-schema.factory.ts","../../../../projects/muziehdesign/forms/src/lib/forms.module.ts","../../../../projects/muziehdesign/forms/src/lib/ng-form-model-state.service.ts","../../../../projects/muziehdesign/forms/src/public-api.ts","../../../../projects/muziehdesign/forms/src/muziehdesign-forms.ts"],"sourcesContent":["import { SchemaOf, ValidationError } from 'yup';\nimport { FieldError } from './field-error';\n\nexport class ModelValidator<T> {\n private schema: SchemaOf<T>;\n constructor(modelSchema: SchemaOf<T>) {\n this.schema = modelSchema;\n }\n\n validate<T>(model: T): Promise<FieldError[]> {\n return this.schema\n .validate(model, { abortEarly: false })\n .then(() => {\n return [];\n })\n .catch((e: ValidationError) => {\n return e.inner.map((error) => <FieldError>{ path: error.path, type: error.type, message: error.message });\n });\n }\n}\n","export const SCHEMA_METADATA_NAMESPACE = 'custom:muziehdesign:annotations';\n","import 'reflect-metadata';\nimport { BooleanSchema, SchemaOf, StringSchema } from 'yup';\nimport { PropertySchemaMetadata } from './property-schema-metadata';\nimport { PropertyType } from './property-type.enum';\n\nconst METADATA_KEY = 'custom:muziehdesign:annotations';\n\nexport interface ConstraintAnnotations {\n constraintType: string;\n}\n\n/*\nexport interface OfValuesAnnotations extends ConstraintAnnotations {\n values: [];\n message?: string;\n}*/\n\nexport interface StringTypeAnnotations extends ConstraintAnnotations {\n required?: RequiredAnnotation;\n length: LengthAnnotation;\n}\n\nexport interface BooleanTypeAnnotations extends ConstraintAnnotations {\n required?: RequiredAnnotation;\n equals?: EqualsAnnotation<boolean>;\n}\n\nexport interface ValidationAnnotation {\n message?: string;\n}\n\nexport interface RequiredAnnotation extends ValidationAnnotation {\n required: boolean;\n}\n\nexport interface LengthAnnotation extends ValidationAnnotation {\n length: number;\n}\n\nexport interface OfValuesAnnotation extends ValidationAnnotation {\n values: [];\n}\n\nexport interface EqualsAnnotation<T> extends ValidationAnnotation {\n equals: T;\n}\n\nconst registerMetadata = (target: Object, propertyKey: string, constraint: ConstraintAnnotations) => {\n const metadata: Map<string, any> = Reflect.getMetadata(METADATA_KEY, target) || new Map<string, any>();\n metadata.set(propertyKey, constraint);\n Reflect.defineMetadata(METADATA_KEY, metadata, target);\n};\n\n/*\nexport function OfValues<T>(values: T[], message?: string) {\n return function (target: Object, propertyKey: string) {\n const o = { values: values, message: message } as OfValuesAnnotations;\n o.constraintType = OfValues.name;\n registerMetadata(target, propertyKey, o);\n };\n}*/\n\nexport function StringType(...annotations: { [key: string]: ValidationAnnotation }[]) {\n return function (target: Object, propertyKey: string) {\n const o = Object.assign({}, ...annotations) as StringTypeAnnotations;\n o.constraintType = StringType.name;\n registerMetadata(target, propertyKey, o);\n };\n}\n\nexport function BooleanType(...annotations: { [key: string]: ValidationAnnotation }[]) {\n return function (target: Object, propertyKey: string) {\n const o = Object.assign({}, ...annotations) as BooleanTypeAnnotations;\n o.constraintType = BooleanType.name;\n registerMetadata(target, propertyKey, o);\n };\n}\n\nexport function required(message?: string): { [key: string]: RequiredAnnotation } {\n return { required: { required: true, message: message } };\n}\n\nexport function length(length: number, message?: string): { [key: string]: LengthAnnotation } {\n return { length: { length: length, message: message } };\n}\n\nexport function ofValues(values: [], message?: string): { [key: string]: OfValuesAnnotation } {\n return { ofValues: { values: values, message: message } };\n}\n\nexport function equals<T>(value: T, message?: string) : { [key: string]: EqualsAnnotation<T> } {\n return { equals: { equals: value, message: message } };\n}\n","import { Injectable } from '@angular/core';\nimport { object, SchemaOf } from 'yup';\nimport { ModelValidator } from './model-validator';\nimport { SCHEMA_METADATA_NAMESPACE } from './constants';\nimport { ObjectShape } from 'yup/lib/object';\nimport { BooleanType, BooleanTypeAnnotations, ConstraintAnnotations, StringType, StringTypeAnnotations } from './type-annotations';\nimport * as Yup from 'yup';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class ModelSchemaFactory {\n constructor() {}\n\n build<T>(model: T): ModelValidator<T> {\n const metadata: Map<string, ConstraintAnnotations> = Reflect.getMetadata(SCHEMA_METADATA_NAMESPACE, model);\n let shape: ObjectShape = {};\n metadata.forEach((value, key) => {\n if (value.constraintType == StringType.name) {\n shape[key] = this.buildStringSchema(value as StringTypeAnnotations);\n } else if (value.constraintType == BooleanType.name) {\n shape[key] = this.buildBooleanSchema(value as BooleanTypeAnnotations);\n }\n });\n const schema = object(shape) as SchemaOf<T>;\n return new ModelValidator(schema);\n }\n\n private buildStringSchema(options: StringTypeAnnotations) {\n let schema = Yup.string();\n if (options.required) {\n schema = schema.required(options.required.message);\n }\n if (options.length) {\n schema = schema.length(options.length.length, options.length.message);\n }\n\n return schema;\n }\n\n private buildBooleanSchema(options: BooleanTypeAnnotations) {\n let schema = Yup.boolean();\n if (options.required) {\n schema = schema.required(options.required.message);\n }\n if (options.equals) {\n if (options.equals.equals) {\n schema = schema.isTrue(options.equals.message);\n } else {\n schema = schema.isFalse(options.equals.message);\n }\n }\n\n return schema;\n }\n}\n","import { NgModule } from '@angular/core';\n\n\n\n@NgModule({\n providers: []\n})\nexport class FormsModule { }\n","import { Injectable, NO_ERRORS_SCHEMA } from '@angular/core';\nimport { NgForm, ValidationErrors } from '@angular/forms';\nimport { BehaviorSubject, filter, from, switchMap } from 'rxjs';\nimport { FieldError } from './field-error';\nimport { ModelSchemaFactory } from './model-schema.factory';\nimport { ModelValidator } from './model-validator';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class NgFormModelStateFactory {\n constructor(private factory: ModelSchemaFactory) {}\n\n create<T>(form: NgForm, model: T) {\n const modelState = new NgFormModelState<T>(form, this.factory.build(model), model);\n return modelState;\n }\n}\n\nexport class NgFormModelState<T> {\n private errors: BehaviorSubject<FieldError[]> = new BehaviorSubject<FieldError[]>([]);\n public errors$ = this.errors.asObservable();\n\n constructor(private form: NgForm, private modelValidator: ModelValidator<T>, private model: T) {\n this.form.form.valueChanges\n .pipe(\n switchMap(async (x) => {\n return from(this.runValidations());\n })\n )\n .subscribe();\n\n this.errors$.subscribe((list) => {\n console.log('all errors', list);\n\n const grouped = list.reduce((grouped, v) => grouped.set(v.path, [...(grouped.get(v.path) || []), v]), new Map<string, FieldError[]>());\n\n grouped.forEach((value, key) => {\n let validationErrors = <ValidationErrors>{};\n value.forEach((v) => (validationErrors[v.type] = v.message));\n this.form.controls[key].setErrors(validationErrors);\n });\n });\n }\n\n isValid(): boolean {\n return this.errors.value.length == 0;\n }\n\n setErrors(errors: FieldError[]) {\n this.errors.next(errors);\n }\n\n validate(): Promise<boolean> {\n return this.runValidations().then((x) => true);\n }\n\n private async runValidations(): Promise<void> {\n console.log('validating', this.model);\n const errors = await this.modelValidator.validate(this.model);\n this.errors.next(errors);\n }\n}\n","/*\n * Public API Surface of forms\n */\nexport * from './lib/field-error';\nexport * from './lib/model-schema.factory';\nexport * from './lib/model-validator';\nexport * from './lib/type-annotations';\nexport * from './lib/forms.module';\nexport * from './lib/ng-form-model-state.service';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["i1.ModelSchemaFactory"],"mappings":";;;;;;;;MAGa,cAAc,CAAA;AAEzB,IAAA,WAAA,CAAY,WAAwB,EAAA;AAClC,QAAA,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC;KAC3B;AAED,IAAA,QAAQ,CAAI,KAAQ,EAAA;QAClB,OAAO,IAAI,CAAC,MAAM;aACf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,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC9D,YAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;SAC1B,CAAA,CAAA;AAAA,KAAA;AACF;;AC9DD;;AAEG;;ACFH;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"muziehdesign-forms.mjs","sources":["../../../../projects/muziehdesign/forms/src/lib/model-validator.ts","../../../../projects/muziehdesign/forms/src/lib/constants.ts","../../../../projects/muziehdesign/forms/src/lib/type-annotations.ts","../../../../projects/muziehdesign/forms/src/lib/model-schema.factory.ts","../../../../projects/muziehdesign/forms/src/lib/forms.module.ts","../../../../projects/muziehdesign/forms/src/lib/ng-form-model-state.service.ts","../../../../projects/muziehdesign/forms/src/public-api.ts","../../../../projects/muziehdesign/forms/src/muziehdesign-forms.ts"],"sourcesContent":["import { SchemaOf, ValidationError } from 'yup';\nimport { FieldError } from './field-error';\n\nexport class ModelValidator<T> {\n private schema: SchemaOf<T>;\n constructor(modelSchema: SchemaOf<T>) {\n this.schema = modelSchema;\n }\n\n validate<T>(model: T): Promise<FieldError[]> {\n return this.schema\n .validate(model, { abortEarly: false })\n .then(() => {\n return [];\n })\n .catch((e: ValidationError) => {\n return e.inner.map((error) => <FieldError>{ path: error.path, type: error.type, message: error.message });\n });\n }\n}\n","export const SCHEMA_METADATA_NAMESPACE = 'custom:muziehdesign:annotations';\n","import 'reflect-metadata';\nimport { BooleanSchema, SchemaOf, StringSchema } from 'yup';\nimport { PropertySchemaMetadata } from './property-schema-metadata';\nimport { PropertyType } from './property-type.enum';\n\nconst METADATA_KEY = 'custom:muziehdesign:annotations';\n\nexport enum ConstraintType {\n string,\n boolean\n}\n\nexport interface ConstraintAnnotations {\n constraintType: ConstraintType;\n}\n\n/*\nexport interface OfValuesAnnotations extends ConstraintAnnotations {\n values: [];\n message?: string;\n}*/\n\nexport interface StringTypeAnnotations extends ConstraintAnnotations {\n required?: RequiredAnnotation;\n length?: LengthAnnotation;\n pattern?: PatternAnnotation;\n maxLength?: MaxLengthAnnotation;\n minLength?: MinLengthAnnotation;\n}\n\nexport interface BooleanTypeAnnotations extends ConstraintAnnotations {\n required?: RequiredAnnotation;\n equals?: EqualsAnnotation<boolean>;\n}\n\nexport interface ValidationAnnotation {\n message?: string;\n}\n\nexport interface RequiredAnnotation extends ValidationAnnotation {\n required: boolean;\n}\n\nexport interface LengthAnnotation extends ValidationAnnotation {\n length: number;\n}\n\nexport interface PatternAnnotation extends ValidationAnnotation {\n pattern: RegExp;\n}\n\nexport interface OfValuesAnnotation extends ValidationAnnotation {\n values: [];\n}\n\nexport interface EqualsAnnotation<T> extends ValidationAnnotation {\n equals: T;\n}\n\nexport interface MaxLengthAnnotation extends ValidationAnnotation {\n maxLength: number;\n}\n\nexport interface MinLengthAnnotation extends ValidationAnnotation {\n minLength: number;\n}\n\nconst registerMetadata = (target: Object, propertyKey: string, constraint: ConstraintAnnotations) => {\n const metadata: Map<string, any> = Reflect.getMetadata(METADATA_KEY, target) || new Map<string, any>();\n metadata.set(propertyKey, constraint);\n Reflect.defineMetadata(METADATA_KEY, metadata, target);\n};\n\n/*\nexport function OfValues<T>(values: T[], message?: string) {\n return function (target: Object, propertyKey: string) {\n const o = { values: values, message: message } as OfValuesAnnotations;\n o.constraintType = OfValues.name;\n registerMetadata(target, propertyKey, o);\n };\n}*/\n\nexport function Annotate<T extends ConstraintAnnotations>(a: AnnotationType<T>) {\n return function (target: Object, propertyKey: string) {\n console.log('annotations', a.annotations);\n registerMetadata(target, propertyKey, a.annotations as ConstraintAnnotations);\n };\n}\n\nexport function StringType(...annotations: { [key: string]: ValidationAnnotation }[]) {\n return function (target: Object, propertyKey: string) {\n const o = Object.assign({}, ...annotations) as StringTypeAnnotations;\n o.constraintType = ConstraintType.string;\n registerMetadata(target, propertyKey, o);\n };\n}\n\nexport function BooleanType(...annotations: { [key: string]: ValidationAnnotation }[]) {\n return function (target: Object, propertyKey: string) {\n const o = Object.assign({}, ...annotations) as BooleanTypeAnnotations;\n o.constraintType = ConstraintType.boolean;\n registerMetadata(target, propertyKey, o);\n };\n}\n\nexport function required(message?: string): { [key: string]: RequiredAnnotation } {\n return { required: { required: true, message: message } };\n}\n\nexport function pattern(regex: RegExp, message?: string): { [key: string]: PatternAnnotation } {\n return { pattern: { pattern: regex, message: message } };\n}\n\nexport function length(length: number, message?: string): { [key: string]: LengthAnnotation } {\n return { length: { length: length, message: message } };\n}\n\nexport function maxLength(maxLength: number, message?: string): { [key: string]: MaxLengthAnnotation } {\n return { maxLength: { maxLength: maxLength, message: message } };\n}\n\nexport function minLength(minLength: number, message?: string): { [key: string]: MinLengthAnnotation } {\n return { minLength: { minLength: minLength, message: message } };\n}\n\nexport function ofValues(values: [], message?: string): { [key: string]: OfValuesAnnotation } {\n return { ofValues: { values: values, message: message } };\n}\n\nexport function equals<T>(value: T, message?: string): { [key: string]: EqualsAnnotation<T> } {\n return { equals: { equals: value, message: message } };\n}\n\nexport abstract class AnnotationType<T> {\n public abstract readonly name: string;\n public abstract annotations?: T;\n}\n\nexport class StringType2 extends AnnotationType<StringTypeAnnotations> {\n public readonly name: string = 'StringType';\n public annotations: StringTypeAnnotations = {\n constraintType: ConstraintType.string, // TODO\n };\n\n public required(message?: string) {\n this.annotations.required = { required: true, message: message };\n return this;\n }\n\n public pattern(pattern: RegExp, message?: string) {\n this.annotations.pattern = { pattern: pattern, message: message };\n return this;\n }\n}\n\nexport class BooleanType2 extends AnnotationType<BooleanTypeAnnotations> {\n public readonly name: string = 'BooleanType';\n public annotations: BooleanTypeAnnotations = {\n constraintType: ConstraintType.boolean, // TODO\n };\n\n public required(message?: string) {\n this.annotations.required = { required: true, message: message };\n return this;\n }\n\n public equals(v: boolean, message?: string) {\n this.annotations.equals = { equals: v, message: message };\n return this;\n }\n}\n\nexport function string() {\n return new StringType2();\n}\n\nexport function boolean() {\n return new BooleanType2();\n}\n","import { Injectable } from '@angular/core';\nimport { object, SchemaOf } from 'yup';\nimport { ModelValidator } from './model-validator';\nimport { SCHEMA_METADATA_NAMESPACE } from './constants';\nimport { ObjectShape } from 'yup/lib/object';\nimport { BooleanType, BooleanTypeAnnotations, ConstraintAnnotations, ConstraintType, StringType2, StringTypeAnnotations } from './type-annotations';\nimport * as Yup from 'yup';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class ModelSchemaFactory {\n constructor() {}\n\n build<T>(model: T): ModelValidator<T> {\n const metadata: Map<string, ConstraintAnnotations> = Reflect.getMetadata(SCHEMA_METADATA_NAMESPACE, model);\n let shape: ObjectShape = {};\n metadata.forEach((value, key) => {\n if (value.constraintType == ConstraintType.string) {\n shape[key] = this.buildStringSchema(value as StringTypeAnnotations);\n } else if (value.constraintType == ConstraintType.boolean) {\n shape[key] = this.buildBooleanSchema(value as BooleanTypeAnnotations);\n }\n });\n const schema = object(shape) as SchemaOf<T>;\n console.log(schema);\n console.log(schema.isValidSync({instructions: null}));\n return new ModelValidator(schema);\n }\n\n private buildStringSchema(options: StringTypeAnnotations) {\n let schema = Yup.string();\n if (options.required) {\n schema = schema.required(options.required.message);\n }\n if (options.length) {\n schema = schema.length(options.length.length, options.length.message);\n }\n\n if (options.maxLength) {\n schema = schema.max(options.maxLength.maxLength, options.maxLength.message);\n }\n\n if (options.minLength) {\n schema = schema.min(options.minLength.minLength, options.minLength.message);\n }\n\n if (options.pattern) {\n schema = schema.matches(options.pattern.pattern, options.pattern.message);\n }\n\n return schema;\n }\n\n private buildBooleanSchema(options: BooleanTypeAnnotations) {\n let schema = Yup.boolean();\n if (options.required) {\n schema = schema.required(options.required.message);\n }\n if (options.equals) {\n if (options.equals.equals) {\n schema = schema.isTrue(options.equals.message);\n } else {\n schema = schema.isFalse(options.equals.message);\n }\n }\n\n return schema;\n }\n}\n","import { NgModule } from '@angular/core';\n\n\n\n@NgModule({\n providers: []\n})\nexport class FormsModule { }\n","import { Injectable, NO_ERRORS_SCHEMA } from '@angular/core';\nimport { NgForm, ValidationErrors } from '@angular/forms';\nimport { BehaviorSubject, filter, from, switchMap } from 'rxjs';\nimport { FieldError } from './field-error';\nimport { ModelSchemaFactory } from './model-schema.factory';\nimport { ModelValidator } from './model-validator';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class NgFormModelStateFactory {\n constructor(private factory: ModelSchemaFactory) {}\n\n create<T>(form: NgForm, model: T) {\n const modelState = new NgFormModelState<T>(form, this.factory.build(model), model);\n return modelState;\n }\n}\n\nexport class NgFormModelState<T> {\n private errors: BehaviorSubject<FieldError[]> = new BehaviorSubject<FieldError[]>([]);\n public errors$ = this.errors.asObservable();\n\n constructor(private form: NgForm, private modelValidator: ModelValidator<T>, private model: T) {\n this.form.form.valueChanges\n .pipe(\n switchMap(async (x) => {\n return from(this.runValidations());\n })\n )\n .subscribe();\n\n this.errors$.subscribe((list) => {\n console.log('all errors', list);\n\n const grouped = list.reduce((grouped, v) => grouped.set(v.path, [...(grouped.get(v.path) || []), v]), new Map<string, FieldError[]>());\n\n grouped.forEach((value, key) => {\n let validationErrors = <ValidationErrors>{};\n value.forEach((v) => (validationErrors[v.type] = v.message));\n this.form.controls[key].setErrors(validationErrors);\n });\n });\n }\n\n isValid(): boolean {\n return this.errors.value.length == 0;\n }\n\n setErrors(errors: FieldError[]) {\n this.errors.next(errors);\n }\n\n validate(): Promise<boolean> {\n return this.runValidations().then((x) => true);\n }\n\n private async runValidations(): Promise<void> {\n console.log('validating', this.model);\n const errors = await this.modelValidator.validate(this.model);\n this.errors.next(errors);\n }\n}\n","/*\n * Public API Surface of forms\n */\nexport * from './lib/field-error';\nexport * from './lib/model-schema.factory';\nexport * from './lib/model-validator';\nexport * from './lib/type-annotations';\nexport * from './lib/forms.module';\nexport * from './lib/ng-form-model-state.service';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["i1.ModelSchemaFactory"],"mappings":";;;;;;;;MAGa,cAAc,CAAA;AAEzB,IAAA,WAAA,CAAY,WAAwB,EAAA;AAClC,QAAA,IAAI,CAAC,M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B,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;AAC7D,gBAAA,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;AACtD,aAAC,CAAC,CAAC;AACL,SAAC,CAAC,CAAC;KACJ;IAED,OAAO,GAAA;QACL,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;KACtC;AAED,IAAA,SAAS,CAAC,MAAoB,EAAA;AAC5B,QAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;KAC1B;IAED,QAAQ,GAAA;AACN,QAAA,OAAO,IAAI,CAAC,cAAc,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;KAChD;IAEa,cAAc,GAAA;;YAC1B,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;AACtC,YAAA,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC9D,YAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;SAC1B,CAAA,CAAA;AAAA,KAAA;AACF;;AC9DD;;AAEG;;ACFH;;AAEG;;;;"}
|
|
@@ -24,6 +24,11 @@ class ModelValidator {
|
|
|
24
24
|
const SCHEMA_METADATA_NAMESPACE = 'custom:muziehdesign:annotations';
|
|
25
25
|
|
|
26
26
|
const METADATA_KEY = 'custom:muziehdesign:annotations';
|
|
27
|
+
var ConstraintType;
|
|
28
|
+
(function (ConstraintType) {
|
|
29
|
+
ConstraintType[ConstraintType["string"] = 0] = "string";
|
|
30
|
+
ConstraintType[ConstraintType["boolean"] = 1] = "boolean";
|
|
31
|
+
})(ConstraintType || (ConstraintType = {}));
|
|
27
32
|
const registerMetadata = (target, propertyKey, constraint) => {
|
|
28
33
|
const metadata = Reflect.getMetadata(METADATA_KEY, target) || new Map();
|
|
29
34
|
metadata.set(propertyKey, constraint);
|
|
@@ -37,32 +42,89 @@ export function OfValues<T>(values: T[], message?: string) {
|
|
|
37
42
|
registerMetadata(target, propertyKey, o);
|
|
38
43
|
};
|
|
39
44
|
}*/
|
|
45
|
+
function Annotate(a) {
|
|
46
|
+
return function (target, propertyKey) {
|
|
47
|
+
console.log('annotations', a.annotations);
|
|
48
|
+
registerMetadata(target, propertyKey, a.annotations);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
40
51
|
function StringType(...annotations) {
|
|
41
52
|
return function (target, propertyKey) {
|
|
42
53
|
const o = Object.assign({}, ...annotations);
|
|
43
|
-
o.constraintType =
|
|
54
|
+
o.constraintType = ConstraintType.string;
|
|
44
55
|
registerMetadata(target, propertyKey, o);
|
|
45
56
|
};
|
|
46
57
|
}
|
|
47
58
|
function BooleanType(...annotations) {
|
|
48
59
|
return function (target, propertyKey) {
|
|
49
60
|
const o = Object.assign({}, ...annotations);
|
|
50
|
-
o.constraintType =
|
|
61
|
+
o.constraintType = ConstraintType.boolean;
|
|
51
62
|
registerMetadata(target, propertyKey, o);
|
|
52
63
|
};
|
|
53
64
|
}
|
|
54
65
|
function required(message) {
|
|
55
66
|
return { required: { required: true, message: message } };
|
|
56
67
|
}
|
|
68
|
+
function pattern(regex, message) {
|
|
69
|
+
return { pattern: { pattern: regex, message: message } };
|
|
70
|
+
}
|
|
57
71
|
function length(length, message) {
|
|
58
72
|
return { length: { length: length, message: message } };
|
|
59
73
|
}
|
|
74
|
+
function maxLength(maxLength, message) {
|
|
75
|
+
return { maxLength: { maxLength: maxLength, message: message } };
|
|
76
|
+
}
|
|
77
|
+
function minLength(minLength, message) {
|
|
78
|
+
return { minLength: { minLength: minLength, message: message } };
|
|
79
|
+
}
|
|
60
80
|
function ofValues(values, message) {
|
|
61
81
|
return { ofValues: { values: values, message: message } };
|
|
62
82
|
}
|
|
63
83
|
function equals(value, message) {
|
|
64
84
|
return { equals: { equals: value, message: message } };
|
|
65
85
|
}
|
|
86
|
+
class AnnotationType {
|
|
87
|
+
}
|
|
88
|
+
class StringType2 extends AnnotationType {
|
|
89
|
+
constructor() {
|
|
90
|
+
super(...arguments);
|
|
91
|
+
this.name = 'StringType';
|
|
92
|
+
this.annotations = {
|
|
93
|
+
constraintType: ConstraintType.string, // TODO
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
required(message) {
|
|
97
|
+
this.annotations.required = { required: true, message: message };
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
pattern(pattern, message) {
|
|
101
|
+
this.annotations.pattern = { pattern: pattern, message: message };
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
class BooleanType2 extends AnnotationType {
|
|
106
|
+
constructor() {
|
|
107
|
+
super(...arguments);
|
|
108
|
+
this.name = 'BooleanType';
|
|
109
|
+
this.annotations = {
|
|
110
|
+
constraintType: ConstraintType.boolean, // TODO
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
required(message) {
|
|
114
|
+
this.annotations.required = { required: true, message: message };
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
equals(v, message) {
|
|
118
|
+
this.annotations.equals = { equals: v, message: message };
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function string() {
|
|
123
|
+
return new StringType2();
|
|
124
|
+
}
|
|
125
|
+
function boolean() {
|
|
126
|
+
return new BooleanType2();
|
|
127
|
+
}
|
|
66
128
|
|
|
67
129
|
class ModelSchemaFactory {
|
|
68
130
|
constructor() { }
|
|
@@ -70,14 +132,16 @@ class ModelSchemaFactory {
|
|
|
70
132
|
const metadata = Reflect.getMetadata(SCHEMA_METADATA_NAMESPACE, model);
|
|
71
133
|
let shape = {};
|
|
72
134
|
metadata.forEach((value, key) => {
|
|
73
|
-
if (value.constraintType ==
|
|
135
|
+
if (value.constraintType == ConstraintType.string) {
|
|
74
136
|
shape[key] = this.buildStringSchema(value);
|
|
75
137
|
}
|
|
76
|
-
else if (value.constraintType ==
|
|
138
|
+
else if (value.constraintType == ConstraintType.boolean) {
|
|
77
139
|
shape[key] = this.buildBooleanSchema(value);
|
|
78
140
|
}
|
|
79
141
|
});
|
|
80
142
|
const schema = object(shape);
|
|
143
|
+
console.log(schema);
|
|
144
|
+
console.log(schema.isValidSync({ instructions: null }));
|
|
81
145
|
return new ModelValidator(schema);
|
|
82
146
|
}
|
|
83
147
|
buildStringSchema(options) {
|
|
@@ -88,6 +152,15 @@ class ModelSchemaFactory {
|
|
|
88
152
|
if (options.length) {
|
|
89
153
|
schema = schema.length(options.length.length, options.length.message);
|
|
90
154
|
}
|
|
155
|
+
if (options.maxLength) {
|
|
156
|
+
schema = schema.max(options.maxLength.maxLength, options.maxLength.message);
|
|
157
|
+
}
|
|
158
|
+
if (options.minLength) {
|
|
159
|
+
schema = schema.min(options.minLength.minLength, options.minLength.message);
|
|
160
|
+
}
|
|
161
|
+
if (options.pattern) {
|
|
162
|
+
schema = schema.matches(options.pattern.pattern, options.pattern.message);
|
|
163
|
+
}
|
|
91
164
|
return schema;
|
|
92
165
|
}
|
|
93
166
|
buildBooleanSchema(options) {
|
|
@@ -190,5 +263,5 @@ class NgFormModelState {
|
|
|
190
263
|
* Generated bundle index. Do not edit.
|
|
191
264
|
*/
|
|
192
265
|
|
|
193
|
-
export { BooleanType, FormsModule, ModelSchemaFactory, ModelValidator, NgFormModelState, NgFormModelStateFactory, StringType, equals, length, ofValues, required };
|
|
266
|
+
export { Annotate, AnnotationType, BooleanType, BooleanType2, ConstraintType, FormsModule, ModelSchemaFactory, ModelValidator, NgFormModelState, NgFormModelStateFactory, StringType, StringType2, boolean, equals, length, maxLength, minLength, ofValues, pattern, required, string };
|
|
194
267
|
//# sourceMappingURL=muziehdesign-forms.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"muziehdesign-forms.mjs","sources":["../../../../projects/muziehdesign/forms/src/lib/model-validator.ts","../../../../projects/muziehdesign/forms/src/lib/constants.ts","../../../../projects/muziehdesign/forms/src/lib/type-annotations.ts","../../../../projects/muziehdesign/forms/src/lib/model-schema.factory.ts","../../../../projects/muziehdesign/forms/src/lib/forms.module.ts","../../../../projects/muziehdesign/forms/src/lib/ng-form-model-state.service.ts","../../../../projects/muziehdesign/forms/src/public-api.ts","../../../../projects/muziehdesign/forms/src/muziehdesign-forms.ts"],"sourcesContent":["import { SchemaOf, ValidationError } from 'yup';\nimport { FieldError } from './field-error';\n\nexport class ModelValidator<T> {\n private schema: SchemaOf<T>;\n constructor(modelSchema: SchemaOf<T>) {\n this.schema = modelSchema;\n }\n\n validate<T>(model: T): Promise<FieldError[]> {\n return this.schema\n .validate(model, { abortEarly: false })\n .then(() => {\n return [];\n })\n .catch((e: ValidationError) => {\n return e.inner.map((error) => <FieldError>{ path: error.path, type: error.type, message: error.message });\n });\n }\n}\n","export const SCHEMA_METADATA_NAMESPACE = 'custom:muziehdesign:annotations';\n","import 'reflect-metadata';\nimport { BooleanSchema, SchemaOf, StringSchema } from 'yup';\nimport { PropertySchemaMetadata } from './property-schema-metadata';\nimport { PropertyType } from './property-type.enum';\n\nconst METADATA_KEY = 'custom:muziehdesign:annotations';\n\nexport interface ConstraintAnnotations {\n constraintType: string;\n}\n\n/*\nexport interface OfValuesAnnotations extends ConstraintAnnotations {\n values: [];\n message?: string;\n}*/\n\nexport interface StringTypeAnnotations extends ConstraintAnnotations {\n required?: RequiredAnnotation;\n length: LengthAnnotation;\n}\n\nexport interface BooleanTypeAnnotations extends ConstraintAnnotations {\n required?: RequiredAnnotation;\n equals?: EqualsAnnotation<boolean>;\n}\n\nexport interface ValidationAnnotation {\n message?: string;\n}\n\nexport interface RequiredAnnotation extends ValidationAnnotation {\n required: boolean;\n}\n\nexport interface LengthAnnotation extends ValidationAnnotation {\n length: number;\n}\n\nexport interface OfValuesAnnotation extends ValidationAnnotation {\n values: [];\n}\n\nexport interface EqualsAnnotation<T> extends ValidationAnnotation {\n equals: T;\n}\n\nconst registerMetadata = (target: Object, propertyKey: string, constraint: ConstraintAnnotations) => {\n const metadata: Map<string, any> = Reflect.getMetadata(METADATA_KEY, target) || new Map<string, any>();\n metadata.set(propertyKey, constraint);\n Reflect.defineMetadata(METADATA_KEY, metadata, target);\n};\n\n/*\nexport function OfValues<T>(values: T[], message?: string) {\n return function (target: Object, propertyKey: string) {\n const o = { values: values, message: message } as OfValuesAnnotations;\n o.constraintType = OfValues.name;\n registerMetadata(target, propertyKey, o);\n };\n}*/\n\nexport function StringType(...annotations: { [key: string]: ValidationAnnotation }[]) {\n return function (target: Object, propertyKey: string) {\n const o = Object.assign({}, ...annotations) as StringTypeAnnotations;\n o.constraintType = StringType.name;\n registerMetadata(target, propertyKey, o);\n };\n}\n\nexport function BooleanType(...annotations: { [key: string]: ValidationAnnotation }[]) {\n return function (target: Object, propertyKey: string) {\n const o = Object.assign({}, ...annotations) as BooleanTypeAnnotations;\n o.constraintType = BooleanType.name;\n registerMetadata(target, propertyKey, o);\n };\n}\n\nexport function required(message?: string): { [key: string]: RequiredAnnotation } {\n return { required: { required: true, message: message } };\n}\n\nexport function length(length: number, message?: string): { [key: string]: LengthAnnotation } {\n return { length: { length: length, message: message } };\n}\n\nexport function ofValues(values: [], message?: string): { [key: string]: OfValuesAnnotation } {\n return { ofValues: { values: values, message: message } };\n}\n\nexport function equals<T>(value: T, message?: string) : { [key: string]: EqualsAnnotation<T> } {\n return { equals: { equals: value, message: message } };\n}\n","import { Injectable } from '@angular/core';\nimport { object, SchemaOf } from 'yup';\nimport { ModelValidator } from './model-validator';\nimport { SCHEMA_METADATA_NAMESPACE } from './constants';\nimport { ObjectShape } from 'yup/lib/object';\nimport { BooleanType, BooleanTypeAnnotations, ConstraintAnnotations, StringType, StringTypeAnnotations } from './type-annotations';\nimport * as Yup from 'yup';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class ModelSchemaFactory {\n constructor() {}\n\n build<T>(model: T): ModelValidator<T> {\n const metadata: Map<string, ConstraintAnnotations> = Reflect.getMetadata(SCHEMA_METADATA_NAMESPACE, model);\n let shape: ObjectShape = {};\n metadata.forEach((value, key) => {\n if (value.constraintType == StringType.name) {\n shape[key] = this.buildStringSchema(value as StringTypeAnnotations);\n } else if (value.constraintType == BooleanType.name) {\n shape[key] = this.buildBooleanSchema(value as BooleanTypeAnnotations);\n }\n });\n const schema = object(shape) as SchemaOf<T>;\n return new ModelValidator(schema);\n }\n\n private buildStringSchema(options: StringTypeAnnotations) {\n let schema = Yup.string();\n if (options.required) {\n schema = schema.required(options.required.message);\n }\n if (options.length) {\n schema = schema.length(options.length.length, options.length.message);\n }\n\n return schema;\n }\n\n private buildBooleanSchema(options: BooleanTypeAnnotations) {\n let schema = Yup.boolean();\n if (options.required) {\n schema = schema.required(options.required.message);\n }\n if (options.equals) {\n if (options.equals.equals) {\n schema = schema.isTrue(options.equals.message);\n } else {\n schema = schema.isFalse(options.equals.message);\n }\n }\n\n return schema;\n }\n}\n","import { NgModule } from '@angular/core';\n\n\n\n@NgModule({\n providers: []\n})\nexport class FormsModule { }\n","import { Injectable, NO_ERRORS_SCHEMA } from '@angular/core';\nimport { NgForm, ValidationErrors } from '@angular/forms';\nimport { BehaviorSubject, filter, from, switchMap } from 'rxjs';\nimport { FieldError } from './field-error';\nimport { ModelSchemaFactory } from './model-schema.factory';\nimport { ModelValidator } from './model-validator';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class NgFormModelStateFactory {\n constructor(private factory: ModelSchemaFactory) {}\n\n create<T>(form: NgForm, model: T) {\n const modelState = new NgFormModelState<T>(form, this.factory.build(model), model);\n return modelState;\n }\n}\n\nexport class NgFormModelState<T> {\n private errors: BehaviorSubject<FieldError[]> = new BehaviorSubject<FieldError[]>([]);\n public errors$ = this.errors.asObservable();\n\n constructor(private form: NgForm, private modelValidator: ModelValidator<T>, private model: T) {\n this.form.form.valueChanges\n .pipe(\n switchMap(async (x) => {\n return from(this.runValidations());\n })\n )\n .subscribe();\n\n this.errors$.subscribe((list) => {\n console.log('all errors', list);\n\n const grouped = list.reduce((grouped, v) => grouped.set(v.path, [...(grouped.get(v.path) || []), v]), new Map<string, FieldError[]>());\n\n grouped.forEach((value, key) => {\n let validationErrors = <ValidationErrors>{};\n value.forEach((v) => (validationErrors[v.type] = v.message));\n this.form.controls[key].setErrors(validationErrors);\n });\n });\n }\n\n isValid(): boolean {\n return this.errors.value.length == 0;\n }\n\n setErrors(errors: FieldError[]) {\n this.errors.next(errors);\n }\n\n validate(): Promise<boolean> {\n return this.runValidations().then((x) => true);\n }\n\n private async runValidations(): Promise<void> {\n console.log('validating', this.model);\n const errors = await this.modelValidator.validate(this.model);\n this.errors.next(errors);\n }\n}\n","/*\n * Public API Surface of forms\n */\nexport * from './lib/field-error';\nexport * from './lib/model-schema.factory';\nexport * from './lib/model-validator';\nexport * from './lib/type-annotations';\nexport * from './lib/forms.module';\nexport * from './lib/ng-form-model-state.service';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["i1.ModelSchemaFactory"],"mappings":";;;;;;;MAGa,cAAc,CAAA;AAEzB,IAAA,WAAA,CAAY,WAAwB,EAAA;AAClC,QAAA,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC;KAC3B;AAED,IAAA,QAAQ,CAAI,KAAQ,EAAA;QAClB,OAAO,IAAI,CAAC,MAAM;aACf,QAAQ,CAAC,KAAK,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;aACtC,IAAI,CAAC,MAAK;AACT,YAAA,OAAO,EAAE,CAAC;AACZ,SAAC,CAAC;AACD,aAAA,KAAK,CAAC,CAAC,CAAkB,KAAI;AAC5B,YAAA,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,MAAiB,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI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AAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,KAAI;gBAC7B,IAAI,gBAAgB,GAAqB,EAAE,CAAC;gBAC5C,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;AAC7D,gBAAA,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;AACtD,aAAC,CAAC,CAAC;AACL,SAAC,CAAC,CAAC;KACJ;IAED,OAAO,GAAA;QACL,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;KACtC;AAED,IAAA,SAAS,CAAC,MAAoB,EAAA;AAC5B,QAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;KAC1B;IAED,QAAQ,GAAA;AACN,QAAA,OAAO,IAAI,CAAC,cAAc,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;KAChD;AAEO,IAAA,MAAM,cAAc,GAAA;QAC1B,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;AACtC,QAAA,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC9D,QAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;KAC1B;AACF;;AC9DD;;AAEG;;ACFH;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"muziehdesign-forms.mjs","sources":["../../../../projects/muziehdesign/forms/src/lib/model-validator.ts","../../../../projects/muziehdesign/forms/src/lib/constants.ts","../../../../projects/muziehdesign/forms/src/lib/type-annotations.ts","../../../../projects/muziehdesign/forms/src/lib/model-schema.factory.ts","../../../../projects/muziehdesign/forms/src/lib/forms.module.ts","../../../../projects/muziehdesign/forms/src/lib/ng-form-model-state.service.ts","../../../../projects/muziehdesign/forms/src/public-api.ts","../../../../projects/muziehdesign/forms/src/muziehdesign-forms.ts"],"sourcesContent":["import { SchemaOf, ValidationError } from 'yup';\nimport { FieldError } from './field-error';\n\nexport class ModelValidator<T> {\n private schema: SchemaOf<T>;\n constructor(modelSchema: SchemaOf<T>) {\n this.schema = modelSchema;\n }\n\n validate<T>(model: T): Promise<FieldError[]> {\n return this.schema\n .validate(model, { abortEarly: false })\n .then(() => {\n return [];\n })\n .catch((e: ValidationError) => {\n return e.inner.map((error) => <FieldError>{ path: error.path, type: error.type, message: error.message });\n });\n }\n}\n","export const SCHEMA_METADATA_NAMESPACE = 'custom:muziehdesign:annotations';\n","import 'reflect-metadata';\nimport { BooleanSchema, SchemaOf, StringSchema } from 'yup';\nimport { PropertySchemaMetadata } from './property-schema-metadata';\nimport { PropertyType } from './property-type.enum';\n\nconst METADATA_KEY = 'custom:muziehdesign:annotations';\n\nexport enum ConstraintType {\n string,\n boolean\n}\n\nexport interface ConstraintAnnotations {\n constraintType: ConstraintType;\n}\n\n/*\nexport interface OfValuesAnnotations extends ConstraintAnnotations {\n values: [];\n message?: string;\n}*/\n\nexport interface StringTypeAnnotations extends ConstraintAnnotations {\n required?: RequiredAnnotation;\n length?: LengthAnnotation;\n pattern?: PatternAnnotation;\n maxLength?: MaxLengthAnnotation;\n minLength?: MinLengthAnnotation;\n}\n\nexport interface BooleanTypeAnnotations extends ConstraintAnnotations {\n required?: RequiredAnnotation;\n equals?: EqualsAnnotation<boolean>;\n}\n\nexport interface ValidationAnnotation {\n message?: string;\n}\n\nexport interface RequiredAnnotation extends ValidationAnnotation {\n required: boolean;\n}\n\nexport interface LengthAnnotation extends ValidationAnnotation {\n length: number;\n}\n\nexport interface PatternAnnotation extends ValidationAnnotation {\n pattern: RegExp;\n}\n\nexport interface OfValuesAnnotation extends ValidationAnnotation {\n values: [];\n}\n\nexport interface EqualsAnnotation<T> extends ValidationAnnotation {\n equals: T;\n}\n\nexport interface MaxLengthAnnotation extends ValidationAnnotation {\n maxLength: number;\n}\n\nexport interface MinLengthAnnotation extends ValidationAnnotation {\n minLength: number;\n}\n\nconst registerMetadata = (target: Object, propertyKey: string, constraint: ConstraintAnnotations) => {\n const metadata: Map<string, any> = Reflect.getMetadata(METADATA_KEY, target) || new Map<string, any>();\n metadata.set(propertyKey, constraint);\n Reflect.defineMetadata(METADATA_KEY, metadata, target);\n};\n\n/*\nexport function OfValues<T>(values: T[], message?: string) {\n return function (target: Object, propertyKey: string) {\n const o = { values: values, message: message } as OfValuesAnnotations;\n o.constraintType = OfValues.name;\n registerMetadata(target, propertyKey, o);\n };\n}*/\n\nexport function Annotate<T extends ConstraintAnnotations>(a: AnnotationType<T>) {\n return function (target: Object, propertyKey: string) {\n console.log('annotations', a.annotations);\n registerMetadata(target, propertyKey, a.annotations as ConstraintAnnotations);\n };\n}\n\nexport function StringType(...annotations: { [key: string]: ValidationAnnotation }[]) {\n return function (target: Object, propertyKey: string) {\n const o = Object.assign({}, ...annotations) as StringTypeAnnotations;\n o.constraintType = ConstraintType.string;\n registerMetadata(target, propertyKey, o);\n };\n}\n\nexport function BooleanType(...annotations: { [key: string]: ValidationAnnotation }[]) {\n return function (target: Object, propertyKey: string) {\n const o = Object.assign({}, ...annotations) as BooleanTypeAnnotations;\n o.constraintType = ConstraintType.boolean;\n registerMetadata(target, propertyKey, o);\n };\n}\n\nexport function required(message?: string): { [key: string]: RequiredAnnotation } {\n return { required: { required: true, message: message } };\n}\n\nexport function pattern(regex: RegExp, message?: string): { [key: string]: PatternAnnotation } {\n return { pattern: { pattern: regex, message: message } };\n}\n\nexport function length(length: number, message?: string): { [key: string]: LengthAnnotation } {\n return { length: { length: length, message: message } };\n}\n\nexport function maxLength(maxLength: number, message?: string): { [key: string]: MaxLengthAnnotation } {\n return { maxLength: { maxLength: maxLength, message: message } };\n}\n\nexport function minLength(minLength: number, message?: string): { [key: string]: MinLengthAnnotation } {\n return { minLength: { minLength: minLength, message: message } };\n}\n\nexport function ofValues(values: [], message?: string): { [key: string]: OfValuesAnnotation } {\n return { ofValues: { values: values, message: message } };\n}\n\nexport function equals<T>(value: T, message?: string): { [key: string]: EqualsAnnotation<T> } {\n return { equals: { equals: value, message: message } };\n}\n\nexport abstract class AnnotationType<T> {\n public abstract readonly name: string;\n public abstract annotations?: T;\n}\n\nexport class StringType2 extends AnnotationType<StringTypeAnnotations> {\n public readonly name: string = 'StringType';\n public annotations: StringTypeAnnotations = {\n constraintType: ConstraintType.string, // TODO\n };\n\n public required(message?: string) {\n this.annotations.required = { required: true, message: message };\n return this;\n }\n\n public pattern(pattern: RegExp, message?: string) {\n this.annotations.pattern = { pattern: pattern, message: message };\n return this;\n }\n}\n\nexport class BooleanType2 extends AnnotationType<BooleanTypeAnnotations> {\n public readonly name: string = 'BooleanType';\n public annotations: BooleanTypeAnnotations = {\n constraintType: ConstraintType.boolean, // TODO\n };\n\n public required(message?: string) {\n this.annotations.required = { required: true, message: message };\n return this;\n }\n\n public equals(v: boolean, message?: string) {\n this.annotations.equals = { equals: v, message: message };\n return this;\n }\n}\n\nexport function string() {\n return new StringType2();\n}\n\nexport function boolean() {\n return new BooleanType2();\n}\n","import { Injectable } from '@angular/core';\nimport { object, SchemaOf } from 'yup';\nimport { ModelValidator } from './model-validator';\nimport { SCHEMA_METADATA_NAMESPACE } from './constants';\nimport { ObjectShape } from 'yup/lib/object';\nimport { BooleanType, BooleanTypeAnnotations, ConstraintAnnotations, ConstraintType, StringType2, StringTypeAnnotations } from './type-annotations';\nimport * as Yup from 'yup';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class ModelSchemaFactory {\n constructor() {}\n\n build<T>(model: T): ModelValidator<T> {\n const metadata: Map<string, ConstraintAnnotations> = Reflect.getMetadata(SCHEMA_METADATA_NAMESPACE, model);\n let shape: ObjectShape = {};\n metadata.forEach((value, key) => {\n if (value.constraintType == ConstraintType.string) {\n shape[key] = this.buildStringSchema(value as StringTypeAnnotations);\n } else if (value.constraintType == ConstraintType.boolean) {\n shape[key] = this.buildBooleanSchema(value as BooleanTypeAnnotations);\n }\n });\n const schema = object(shape) as SchemaOf<T>;\n console.log(schema);\n console.log(schema.isValidSync({instructions: null}));\n return new ModelValidator(schema);\n }\n\n private buildStringSchema(options: StringTypeAnnotations) {\n let schema = Yup.string();\n if (options.required) {\n schema = schema.required(options.required.message);\n }\n if (options.length) {\n schema = schema.length(options.length.length, options.length.message);\n }\n\n if (options.maxLength) {\n schema = schema.max(options.maxLength.maxLength, options.maxLength.message);\n }\n\n if (options.minLength) {\n schema = schema.min(options.minLength.minLength, options.minLength.message);\n }\n\n if (options.pattern) {\n schema = schema.matches(options.pattern.pattern, options.pattern.message);\n }\n\n return schema;\n }\n\n private buildBooleanSchema(options: BooleanTypeAnnotations) {\n let schema = Yup.boolean();\n if (options.required) {\n schema = schema.required(options.required.message);\n }\n if (options.equals) {\n if (options.equals.equals) {\n schema = schema.isTrue(options.equals.message);\n } else {\n schema = schema.isFalse(options.equals.message);\n }\n }\n\n return schema;\n }\n}\n","import { NgModule } from '@angular/core';\n\n\n\n@NgModule({\n providers: []\n})\nexport class FormsModule { }\n","import { Injectable, NO_ERRORS_SCHEMA } from '@angular/core';\nimport { NgForm, ValidationErrors } from '@angular/forms';\nimport { BehaviorSubject, filter, from, switchMap } from 'rxjs';\nimport { FieldError } from './field-error';\nimport { ModelSchemaFactory } from './model-schema.factory';\nimport { ModelValidator } from './model-validator';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class NgFormModelStateFactory {\n constructor(private factory: ModelSchemaFactory) {}\n\n create<T>(form: NgForm, model: T) {\n const modelState = new NgFormModelState<T>(form, this.factory.build(model), model);\n return modelState;\n }\n}\n\nexport class NgFormModelState<T> {\n private errors: BehaviorSubject<FieldError[]> = new BehaviorSubject<FieldError[]>([]);\n public errors$ = this.errors.asObservable();\n\n constructor(private form: NgForm, private modelValidator: ModelValidator<T>, private model: T) {\n this.form.form.valueChanges\n .pipe(\n switchMap(async (x) => {\n return from(this.runValidations());\n })\n )\n .subscribe();\n\n this.errors$.subscribe((list) => {\n console.log('all errors', list);\n\n const grouped = list.reduce((grouped, v) => grouped.set(v.path, [...(grouped.get(v.path) || []), v]), new Map<string, FieldError[]>());\n\n grouped.forEach((value, key) => {\n let validationErrors = <ValidationErrors>{};\n value.forEach((v) => (validationErrors[v.type] = v.message));\n this.form.controls[key].setErrors(validationErrors);\n });\n });\n }\n\n isValid(): boolean {\n return this.errors.value.length == 0;\n }\n\n setErrors(errors: FieldError[]) {\n this.errors.next(errors);\n }\n\n validate(): Promise<boolean> {\n return this.runValidations().then((x) => true);\n }\n\n private async runValidations(): Promise<void> {\n console.log('validating', this.model);\n const errors = await this.modelValidator.validate(this.model);\n this.errors.next(errors);\n }\n}\n","/*\n * Public API Surface of forms\n */\nexport * from './lib/field-error';\nexport * from './lib/model-schema.factory';\nexport * from './lib/model-validator';\nexport * from './lib/type-annotations';\nexport * from './lib/forms.module';\nexport * from './lib/ng-form-model-state.service';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["i1.ModelSchemaFactory"],"mappings":";;;;;;;MAGa,cAAc,CAAA;AAEzB,IAAA,WAAA,CAAY,WAAwB,EAAA;AAClC,QAAA,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC;KAC3B;AAED,IAAA,QAAQ,CAAI,KAAQ,EAAA;QAClB,OAAO,IAAI,CAAC,MAAM;aACf,QAAQ,CAAC,KAAK,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;aACtC,IAAI,CAAC,MAAK;AACT,YAAA,OAAO,EAAE,CAAC;AACZ,SAAC,CAAC;AACD,aAAA,KAAK,CAAC,CAAC,CAAkB,KAAI;AAC5B,YAAA,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,MAAiB,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,IA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A;AACN,QAAA,OAAO,IAAI,CAAC,cAAc,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;KAChD;AAEO,IAAA,MAAM,cAAc,GAAA;QAC1B,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;AACtC,QAAA,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC9D,QAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;KAC1B;AACF;;AC9DD;;AAEG;;ACFH;;AAEG;;;;"}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
+
export declare enum ConstraintType {
|
|
3
|
+
string = 0,
|
|
4
|
+
boolean = 1
|
|
5
|
+
}
|
|
2
6
|
export interface ConstraintAnnotations {
|
|
3
|
-
constraintType:
|
|
7
|
+
constraintType: ConstraintType;
|
|
4
8
|
}
|
|
5
9
|
export interface StringTypeAnnotations extends ConstraintAnnotations {
|
|
6
10
|
required?: RequiredAnnotation;
|
|
7
|
-
length
|
|
11
|
+
length?: LengthAnnotation;
|
|
12
|
+
pattern?: PatternAnnotation;
|
|
13
|
+
maxLength?: MaxLengthAnnotation;
|
|
14
|
+
minLength?: MinLengthAnnotation;
|
|
8
15
|
}
|
|
9
16
|
export interface BooleanTypeAnnotations extends ConstraintAnnotations {
|
|
10
17
|
required?: RequiredAnnotation;
|
|
@@ -19,12 +26,22 @@ export interface RequiredAnnotation extends ValidationAnnotation {
|
|
|
19
26
|
export interface LengthAnnotation extends ValidationAnnotation {
|
|
20
27
|
length: number;
|
|
21
28
|
}
|
|
29
|
+
export interface PatternAnnotation extends ValidationAnnotation {
|
|
30
|
+
pattern: RegExp;
|
|
31
|
+
}
|
|
22
32
|
export interface OfValuesAnnotation extends ValidationAnnotation {
|
|
23
33
|
values: [];
|
|
24
34
|
}
|
|
25
35
|
export interface EqualsAnnotation<T> extends ValidationAnnotation {
|
|
26
36
|
equals: T;
|
|
27
37
|
}
|
|
38
|
+
export interface MaxLengthAnnotation extends ValidationAnnotation {
|
|
39
|
+
maxLength: number;
|
|
40
|
+
}
|
|
41
|
+
export interface MinLengthAnnotation extends ValidationAnnotation {
|
|
42
|
+
minLength: number;
|
|
43
|
+
}
|
|
44
|
+
export declare function Annotate<T extends ConstraintAnnotations>(a: AnnotationType<T>): (target: Object, propertyKey: string) => void;
|
|
28
45
|
export declare function StringType(...annotations: {
|
|
29
46
|
[key: string]: ValidationAnnotation;
|
|
30
47
|
}[]): (target: Object, propertyKey: string) => void;
|
|
@@ -34,12 +51,39 @@ export declare function BooleanType(...annotations: {
|
|
|
34
51
|
export declare function required(message?: string): {
|
|
35
52
|
[key: string]: RequiredAnnotation;
|
|
36
53
|
};
|
|
54
|
+
export declare function pattern(regex: RegExp, message?: string): {
|
|
55
|
+
[key: string]: PatternAnnotation;
|
|
56
|
+
};
|
|
37
57
|
export declare function length(length: number, message?: string): {
|
|
38
58
|
[key: string]: LengthAnnotation;
|
|
39
59
|
};
|
|
60
|
+
export declare function maxLength(maxLength: number, message?: string): {
|
|
61
|
+
[key: string]: MaxLengthAnnotation;
|
|
62
|
+
};
|
|
63
|
+
export declare function minLength(minLength: number, message?: string): {
|
|
64
|
+
[key: string]: MinLengthAnnotation;
|
|
65
|
+
};
|
|
40
66
|
export declare function ofValues(values: [], message?: string): {
|
|
41
67
|
[key: string]: OfValuesAnnotation;
|
|
42
68
|
};
|
|
43
69
|
export declare function equals<T>(value: T, message?: string): {
|
|
44
70
|
[key: string]: EqualsAnnotation<T>;
|
|
45
71
|
};
|
|
72
|
+
export declare abstract class AnnotationType<T> {
|
|
73
|
+
abstract readonly name: string;
|
|
74
|
+
abstract annotations?: T;
|
|
75
|
+
}
|
|
76
|
+
export declare class StringType2 extends AnnotationType<StringTypeAnnotations> {
|
|
77
|
+
readonly name: string;
|
|
78
|
+
annotations: StringTypeAnnotations;
|
|
79
|
+
required(message?: string): this;
|
|
80
|
+
pattern(pattern: RegExp, message?: string): this;
|
|
81
|
+
}
|
|
82
|
+
export declare class BooleanType2 extends AnnotationType<BooleanTypeAnnotations> {
|
|
83
|
+
readonly name: string;
|
|
84
|
+
annotations: BooleanTypeAnnotations;
|
|
85
|
+
required(message?: string): this;
|
|
86
|
+
equals(v: boolean, message?: string): this;
|
|
87
|
+
}
|
|
88
|
+
export declare function string(): StringType2;
|
|
89
|
+
export declare function boolean(): BooleanType2;
|