@muziehdesign/forms 0.0.1-alpha.102

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.
@@ -0,0 +1,353 @@
1
+ import * as i0 from '@angular/core';
2
+ import { Injectable, Component, Input, NgModule } from '@angular/core';
3
+ import * as Yup from 'yup';
4
+ import { object } from 'yup';
5
+ import 'reflect-metadata';
6
+ import * as i1 from '@angular/common';
7
+ import { CommonModule } from '@angular/common';
8
+ import { BehaviorSubject, switchMap, from } from 'rxjs';
9
+
10
+ class ModelValidator {
11
+ constructor(modelSchema) {
12
+ this.schema = modelSchema;
13
+ }
14
+ validate(model) {
15
+ return this.schema
16
+ .validate(model, { abortEarly: false })
17
+ .then(() => {
18
+ return [];
19
+ })
20
+ .catch((e) => {
21
+ return e.inner.map((error) => ({ path: error.path, type: error.type, message: error.message }));
22
+ });
23
+ }
24
+ }
25
+
26
+ const SCHEMA_METADATA_NAMESPACE = 'custom:muziehdesign:annotations';
27
+
28
+ const METADATA_KEY = 'custom:muziehdesign:annotations';
29
+ var ConstraintType;
30
+ (function (ConstraintType) {
31
+ ConstraintType[ConstraintType["string"] = 0] = "string";
32
+ ConstraintType[ConstraintType["boolean"] = 1] = "boolean";
33
+ ConstraintType[ConstraintType["date"] = 2] = "date";
34
+ })(ConstraintType || (ConstraintType = {}));
35
+ const registerMetadata = (target, propertyKey, constraint) => {
36
+ const metadata = Reflect.getMetadata(METADATA_KEY, target) || new Map();
37
+ metadata.set(propertyKey, constraint);
38
+ Reflect.defineMetadata(METADATA_KEY, metadata, target);
39
+ };
40
+ function Annotate(a) {
41
+ return function (target, propertyKey) {
42
+ registerMetadata(target, propertyKey, a.annotations);
43
+ };
44
+ }
45
+ function StringType(...annotations) {
46
+ return function (target, propertyKey) {
47
+ const o = Object.assign({}, ...annotations);
48
+ o.constraintType = ConstraintType.string;
49
+ registerMetadata(target, propertyKey, o);
50
+ };
51
+ }
52
+ function BooleanType(...annotations) {
53
+ return function (target, propertyKey) {
54
+ const o = Object.assign({}, ...annotations);
55
+ o.constraintType = ConstraintType.boolean;
56
+ registerMetadata(target, propertyKey, o);
57
+ };
58
+ }
59
+ function required(message) {
60
+ return { required: { required: true, message: message } };
61
+ }
62
+ function pattern(regex, message) {
63
+ return { pattern: { pattern: regex, message: message } };
64
+ }
65
+ function length(length, message) {
66
+ return { length: { length: length, message: message } };
67
+ }
68
+ function maxLength(maxLength, message) {
69
+ return { maxLength: { maxLength: maxLength, message: message } };
70
+ }
71
+ function minLength(minLength, message) {
72
+ return { minLength: { minLength: minLength, message: message } };
73
+ }
74
+ function ofValues(values, message) {
75
+ return { ofValues: { values: values, message: message } };
76
+ }
77
+ function equals(value, message) {
78
+ return { equals: { equals: value, message: message } };
79
+ }
80
+ class AnnotationType {
81
+ }
82
+ class StringType2 extends AnnotationType {
83
+ constructor() {
84
+ super(...arguments);
85
+ this.name = 'StringType';
86
+ this.annotations = {
87
+ constraintType: ConstraintType.string, // TODO
88
+ };
89
+ }
90
+ required(message) {
91
+ this.annotations.required = { required: true, message: message };
92
+ return this;
93
+ }
94
+ pattern(pattern, message) {
95
+ this.annotations.pattern = { pattern: pattern, message: message };
96
+ return this;
97
+ }
98
+ }
99
+ class BooleanType2 extends AnnotationType {
100
+ constructor() {
101
+ super(...arguments);
102
+ this.name = 'BooleanType';
103
+ this.annotations = {
104
+ constraintType: ConstraintType.boolean, // TODO
105
+ };
106
+ }
107
+ required(message) {
108
+ this.annotations.required = { required: true, message: message };
109
+ return this;
110
+ }
111
+ equals(v, message) {
112
+ this.annotations.equals = { equals: v, message: message };
113
+ return this;
114
+ }
115
+ }
116
+ function string() {
117
+ return new StringType2();
118
+ }
119
+ function boolean() {
120
+ return new BooleanType2();
121
+ }
122
+ class DateType extends AnnotationType {
123
+ constructor() {
124
+ super(...arguments);
125
+ this.name = 'DateType';
126
+ this.annotations = {
127
+ constraintType: ConstraintType.date, // TODO
128
+ };
129
+ }
130
+ required(message) {
131
+ this.annotations.required = { required: true, message: message };
132
+ return this;
133
+ }
134
+ min(v, message) {
135
+ this.annotations.min = { min: v, message: message };
136
+ return this;
137
+ }
138
+ max(v, message) {
139
+ this.annotations.max = { max: v, message: message };
140
+ return this;
141
+ }
142
+ test(name, v, message) {
143
+ this.annotations.test = { name: name, test: v, message: message };
144
+ return this;
145
+ }
146
+ }
147
+ function date() {
148
+ return new DateType();
149
+ }
150
+
151
+ /*
152
+ Schema rules need to be built in the order they need to be evaluated in.
153
+ For example,
154
+ ```
155
+ schema.required().max(...).matches(...);
156
+ ```
157
+ evaluates the 3 rules in this order
158
+ - required
159
+ - max
160
+ - matches
161
+ */
162
+ class ModelSchemaFactory {
163
+ constructor() { }
164
+ build(model) {
165
+ const metadata = Reflect.getMetadata(SCHEMA_METADATA_NAMESPACE, model);
166
+ let shape = {};
167
+ metadata.forEach((value, key) => {
168
+ if (value.constraintType == ConstraintType.string) {
169
+ shape[key] = this.buildStringSchema(value);
170
+ }
171
+ else if (value.constraintType == ConstraintType.boolean) {
172
+ shape[key] = this.buildBooleanSchema(value);
173
+ }
174
+ else if (value.constraintType == ConstraintType.date) {
175
+ shape[key] = this.buildDateSchema(value);
176
+ }
177
+ });
178
+ const schema = object(shape);
179
+ return new ModelValidator(schema);
180
+ }
181
+ buildStringSchema(options) {
182
+ let schema = Yup.string();
183
+ if (options.required) {
184
+ schema = schema.required(options.required.message);
185
+ }
186
+ if (options.length) {
187
+ schema = schema.length(options.length.length, options.length.message);
188
+ }
189
+ if (options.maxLength) {
190
+ schema = schema.max(options.maxLength.maxLength, options.maxLength.message);
191
+ }
192
+ if (options.minLength) {
193
+ schema = schema.min(options.minLength.minLength, options.minLength.message);
194
+ }
195
+ if (options.pattern) {
196
+ schema = schema.matches(options.pattern.pattern, options.pattern.message);
197
+ }
198
+ return schema;
199
+ }
200
+ buildBooleanSchema(options) {
201
+ let schema = Yup.boolean();
202
+ if (options.required) {
203
+ schema = schema.required(options.required.message);
204
+ }
205
+ if (options.equals) {
206
+ if (options.equals.equals) {
207
+ schema = schema.isTrue(options.equals.message);
208
+ }
209
+ else {
210
+ schema = schema.isFalse(options.equals.message);
211
+ }
212
+ }
213
+ return schema;
214
+ }
215
+ buildDateSchema(options) {
216
+ let schema = Yup.date();
217
+ if (options.required) {
218
+ schema = schema.required(options.required.message);
219
+ }
220
+ if (options.min) {
221
+ schema = schema.min(options.min.min, options.min.message);
222
+ }
223
+ if (options.max) {
224
+ schema = schema.max(options.max.max, options.max.message);
225
+ }
226
+ if (options.test) {
227
+ schema = schema.test({
228
+ name: options.test.name,
229
+ message: options.test.message,
230
+ test: (d, context) => {
231
+ return options.test.test(d);
232
+ }
233
+ });
234
+ }
235
+ return schema;
236
+ }
237
+ }
238
+ ModelSchemaFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: ModelSchemaFactory, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
239
+ ModelSchemaFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: ModelSchemaFactory, providedIn: 'root' });
240
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: ModelSchemaFactory, decorators: [{
241
+ type: Injectable,
242
+ args: [{
243
+ providedIn: 'root',
244
+ }]
245
+ }], ctorParameters: function () { return []; } });
246
+
247
+ class FieldErrorsComponent {
248
+ constructor() { }
249
+ ngOnInit() { }
250
+ }
251
+ FieldErrorsComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: FieldErrorsComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
252
+ FieldErrorsComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.0.5", type: FieldErrorsComponent, selector: "mz-field-errors", inputs: { field: "field" }, ngImport: i0, template: "<div>\n field errors:\n {{ field?.errors | json }}\n</div>\n", styles: [""], dependencies: [{ kind: "pipe", type: i1.JsonPipe, name: "json" }] });
253
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: FieldErrorsComponent, decorators: [{
254
+ type: Component,
255
+ args: [{ selector: 'mz-field-errors', template: "<div>\n field errors:\n {{ field?.errors | json }}\n</div>\n" }]
256
+ }], ctorParameters: function () { return []; }, propDecorators: { field: [{
257
+ type: Input
258
+ }] } });
259
+
260
+ class FormsModule {
261
+ }
262
+ FormsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: FormsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
263
+ FormsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.0.5", ngImport: i0, type: FormsModule, declarations: [FieldErrorsComponent], imports: [CommonModule // TODO: can remove once done with temp error displaying
264
+ ], exports: [FieldErrorsComponent] });
265
+ FormsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: FormsModule, imports: [CommonModule // TODO: can remove once done with temp error displaying
266
+ ] });
267
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: FormsModule, decorators: [{
268
+ type: NgModule,
269
+ args: [{
270
+ providers: [],
271
+ declarations: [
272
+ FieldErrorsComponent
273
+ ],
274
+ exports: [
275
+ FieldErrorsComponent
276
+ ],
277
+ imports: [
278
+ CommonModule // TODO: can remove once done with temp error displaying
279
+ ]
280
+ }]
281
+ }] });
282
+
283
+ class NgFormModelStateFactory {
284
+ constructor(factory) {
285
+ this.factory = factory;
286
+ }
287
+ create(form, model, options) {
288
+ const modelState = new NgFormModelState(form, this.factory.build(model), model, options);
289
+ return modelState;
290
+ }
291
+ }
292
+ NgFormModelStateFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: NgFormModelStateFactory, deps: [{ token: ModelSchemaFactory }], target: i0.ɵɵFactoryTarget.Injectable });
293
+ NgFormModelStateFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: NgFormModelStateFactory, providedIn: 'root' });
294
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: NgFormModelStateFactory, decorators: [{
295
+ type: Injectable,
296
+ args: [{
297
+ providedIn: 'root',
298
+ }]
299
+ }], ctorParameters: function () { return [{ type: ModelSchemaFactory }]; } });
300
+ class NgFormModelState {
301
+ constructor(form, modelValidator, model, options) {
302
+ this.form = form;
303
+ this.modelValidator = modelValidator;
304
+ this.model = model;
305
+ this.errors = new BehaviorSubject([]);
306
+ this.errors$ = this.errors.asObservable();
307
+ this.form.form.valueChanges
308
+ .pipe(switchMap(async (x) => {
309
+ this.model = x;
310
+ return from(this.runValidations(options?.onValidate));
311
+ }))
312
+ .subscribe();
313
+ this.errors$.subscribe((list) => {
314
+ const grouped = list.reduce((grouped, v) => grouped.set(v.path, [...(grouped.get(v.path) || []), v]), new Map());
315
+ grouped.forEach((value, key) => {
316
+ let validationErrors = {};
317
+ value.forEach((v) => (validationErrors[v.type] = v.message));
318
+ try {
319
+ this.form.controls[key].setErrors(validationErrors);
320
+ }
321
+ catch (e) {
322
+ console.log('error setting form control', key);
323
+ throw e;
324
+ }
325
+ });
326
+ });
327
+ }
328
+ isValid() {
329
+ return this.errors.value.length == 0;
330
+ }
331
+ setErrors(errors) {
332
+ this.errors.next(errors);
333
+ }
334
+ async validate() {
335
+ return await this.runValidations();
336
+ }
337
+ async runValidations(callback) {
338
+ const list = await this.modelValidator.validate(this.model);
339
+ const final = callback?.(list) || list;
340
+ this.errors.next(final);
341
+ }
342
+ }
343
+
344
+ /*
345
+ * Public API Surface of forms
346
+ */
347
+
348
+ /**
349
+ * Generated bundle index. Do not edit.
350
+ */
351
+
352
+ export { Annotate, AnnotationType, BooleanType, BooleanType2, ConstraintType, DateType, FieldErrorsComponent, FormsModule, ModelSchemaFactory, ModelValidator, NgFormModelState, NgFormModelStateFactory, StringType, StringType2, boolean, date, equals, length, maxLength, minLength, ofValues, pattern, required, string };
353
+ //# sourceMappingURL=muziehdesign-forms.mjs.map
@@ -0,0 +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/field-errors/field-errors.component.ts","../../../../projects/muziehdesign/forms/src/lib/field-errors/field-errors.component.html","../../../../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';\n\nconst METADATA_KEY = 'custom:muziehdesign:annotations';\n\nexport enum ConstraintType {\n string,\n boolean,\n date,\n}\n\nexport interface ConstraintAnnotations {\n constraintType: ConstraintType;\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 DateTypeAnnotations extends ConstraintAnnotations {\n required?: RequiredAnnotation;\n min?: MinimumAnnotation<Date>;\n max?: MaximumAnnotation<Date>;\n test?: TestAnnotation;\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 MinimumAnnotation<T> extends ValidationAnnotation {\n min: T;\n}\n\nexport interface MaximumAnnotation<T> extends ValidationAnnotation {\n max: T;\n}\n\nexport interface TestAnnotation extends ValidationAnnotation {\n test: (d:Date) => boolean;\n name: string;\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\nexport function Annotate<T extends ConstraintAnnotations>(a: AnnotationType<T>) {\n return function (target: Object, propertyKey: string) {\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\nexport class DateType extends AnnotationType<DateTypeAnnotations> {\n public readonly name: string = 'DateType';\n public annotations: DateTypeAnnotations = {\n constraintType: ConstraintType.date, // TODO\n };\n\n public required(message?: string) {\n this.annotations.required = { required: true, message: message };\n return this;\n }\n\n public min(v: Date, message?: string) {\n this.annotations.min = { min: v, message: message };\n return this;\n }\n\n public max(v: Date, message?: string) {\n this.annotations.max = { max: v, message: message };\n return this;\n }\n\n public test(name: string, v: (d: Date) => boolean, message?: string) {\n this.annotations.test = { name: name, test: v, message: message };\n return this;\n }\n}\n\nexport function date() {\n return new DateType();\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, DateTypeAnnotations, StringType2, StringTypeAnnotations } from './type-annotations';\nimport * as Yup from 'yup';\n\n/*\nSchema rules need to be built in the order they need to be evaluated in.\nFor example,\n ```\n schema.required().max(...).matches(...);\n ```\nevaluates the 3 rules in this order\n - required\n - max\n - matches\n*/\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 } else if (value.constraintType == ConstraintType.date) {\n shape[key] = this.buildDateSchema(value as DateTypeAnnotations);\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 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 private buildDateSchema(options: DateTypeAnnotations) {\n let schema = Yup.date();\n if (options.required) {\n schema = schema.required(options.required.message);\n }\n if (options.min) {\n schema = schema.min(options.min.min, options.min.message);\n }\n if (options.max) {\n schema = schema.max(options.max.max, options.max.message);\n }\n if (options.test) {\n schema = schema.test({\n name: options.test.name,\n message: options.test.message,\n test: (d?: Date, context?: any) => {\n return options.test!.test(d!);\n }});\n }\n\n return schema;\n }\n}\n","import { Component, Input, OnInit } from '@angular/core';\nimport { AbstractControl, NgControl, NgModel } from '@angular/forms';\n\n@Component({\n selector: 'mz-field-errors',\n templateUrl: './field-errors.component.html',\n styleUrls: ['./field-errors.component.css']\n})\nexport class FieldErrorsComponent implements OnInit {\n\n @Input() field?: NgControl;\n constructor() {}\n\n ngOnInit(): void { }\n\n}\n","<div>\n field errors:\n {{ field?.errors | json }}\n</div>\n","import { CommonModule } from '@angular/common';\nimport { NgModule } from '@angular/core';\nimport { FieldErrorsComponent } from './field-errors/field-errors.component';\n\n\n\n@NgModule({\n providers: [],\n declarations: [\n FieldErrorsComponent\n ],\n exports: [\n FieldErrorsComponent\n ],\n imports: [\n CommonModule // TODO: can remove once done with temp error displaying\n ]\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, options?: ModelStateOptions) {\n const modelState = new NgFormModelState<T>(form, this.factory.build(model), model, options);\n return modelState;\n }\n}\n\nexport interface ModelStateOptions {\n onValidate: (errors: FieldError[]) => FieldError[]\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, options?: ModelStateOptions) {\n this.form.form.valueChanges\n .pipe(\n switchMap(async (x) => {\n this.model = x;\n return from(this.runValidations(options?.onValidate))\n })\n )\n .subscribe();\n\n this.errors$.subscribe((list) => {\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 try {\n this.form.controls[key].setErrors(validationErrors);\n } catch (e) {\n console.log('error setting form control', key);\n throw e;\n }\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 async validate(): Promise<void> {\n return await this.runValidations();\n }\n\n private async runValidations(callback?: (list:FieldError[])=>FieldError[]): Promise<void> {\n const list = await this.modelValidator.validate(this.model);\n const final = callback?.(list) || list;\n this.errors.next(final);\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';\nexport * from './lib/field-errors/field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ACL,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;AAED,IAAA,MAAM,QAAQ,GAAA;AACZ,QAAA,OAAO,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;KACpC;IAEO,MAAM,cAAc,CAAC,QAA4C,EAAA;AACvE,QAAA,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC5D,MAAM,KAAK,GAAG,QAAQ,GAAG,IAAI,CAAC,IAAI,IAAI,CAAC;AACvC,QAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;KACzB;AACF;;ACtED;;AAEG;;ACFH;;AAEG;;;;"}
package/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Generated bundle index. Do not edit.
3
+ */
4
+ /// <amd-module name="@muziehdesign/forms" />
5
+ export * from './public-api';
@@ -0,0 +1 @@
1
+ export declare const SCHEMA_METADATA_NAMESPACE = "custom:muziehdesign:annotations";
@@ -0,0 +1,5 @@
1
+ export interface FieldError {
2
+ path: string;
3
+ type: string;
4
+ message: string;
5
+ }
@@ -0,0 +1,10 @@
1
+ import { OnInit } from '@angular/core';
2
+ import { NgControl } from '@angular/forms';
3
+ import * as i0 from "@angular/core";
4
+ export declare class FieldErrorsComponent implements OnInit {
5
+ field?: NgControl;
6
+ constructor();
7
+ ngOnInit(): void;
8
+ static ɵfac: i0.ɵɵFactoryDeclaration<FieldErrorsComponent, never>;
9
+ static ɵcmp: i0.ɵɵComponentDeclaration<FieldErrorsComponent, "mz-field-errors", never, { "field": "field"; }, {}, never, never, false>;
10
+ }
@@ -0,0 +1,8 @@
1
+ import * as i0 from "@angular/core";
2
+ import * as i1 from "./field-errors/field-errors.component";
3
+ import * as i2 from "@angular/common";
4
+ export declare class FormsModule {
5
+ static ɵfac: i0.ɵɵFactoryDeclaration<FormsModule, never>;
6
+ static ɵmod: i0.ɵɵNgModuleDeclaration<FormsModule, [typeof i1.FieldErrorsComponent], [typeof i2.CommonModule], [typeof i1.FieldErrorsComponent]>;
7
+ static ɵinj: i0.ɵɵInjectorDeclaration<FormsModule>;
8
+ }
@@ -0,0 +1,11 @@
1
+ import { ModelValidator } from './model-validator';
2
+ import * as i0 from "@angular/core";
3
+ export declare class ModelSchemaFactory {
4
+ constructor();
5
+ build<T>(model: T): ModelValidator<T>;
6
+ private buildStringSchema;
7
+ private buildBooleanSchema;
8
+ private buildDateSchema;
9
+ static ɵfac: i0.ɵɵFactoryDeclaration<ModelSchemaFactory, never>;
10
+ static ɵprov: i0.ɵɵInjectableDeclaration<ModelSchemaFactory>;
11
+ }
@@ -0,0 +1,7 @@
1
+ import { SchemaOf } from 'yup';
2
+ import { FieldError } from './field-error';
3
+ export declare class ModelValidator<T> {
4
+ private schema;
5
+ constructor(modelSchema: SchemaOf<T>);
6
+ validate<T>(model: T): Promise<FieldError[]>;
7
+ }
@@ -0,0 +1,27 @@
1
+ import { NgForm } from '@angular/forms';
2
+ import { FieldError } from './field-error';
3
+ import { ModelSchemaFactory } from './model-schema.factory';
4
+ import { ModelValidator } from './model-validator';
5
+ import * as i0 from "@angular/core";
6
+ export declare class NgFormModelStateFactory {
7
+ private factory;
8
+ constructor(factory: ModelSchemaFactory);
9
+ create<T>(form: NgForm, model: T, options?: ModelStateOptions): NgFormModelState<T>;
10
+ static ɵfac: i0.ɵɵFactoryDeclaration<NgFormModelStateFactory, never>;
11
+ static ɵprov: i0.ɵɵInjectableDeclaration<NgFormModelStateFactory>;
12
+ }
13
+ export interface ModelStateOptions {
14
+ onValidate: (errors: FieldError[]) => FieldError[];
15
+ }
16
+ export declare class NgFormModelState<T> {
17
+ private form;
18
+ private modelValidator;
19
+ private model;
20
+ private errors;
21
+ errors$: import("rxjs").Observable<FieldError[]>;
22
+ constructor(form: NgForm, modelValidator: ModelValidator<T>, model: T, options?: ModelStateOptions);
23
+ isValid(): boolean;
24
+ setErrors(errors: FieldError[]): void;
25
+ validate(): Promise<void>;
26
+ private runValidations;
27
+ }
@@ -0,0 +1,115 @@
1
+ import 'reflect-metadata';
2
+ export declare enum ConstraintType {
3
+ string = 0,
4
+ boolean = 1,
5
+ date = 2
6
+ }
7
+ export interface ConstraintAnnotations {
8
+ constraintType: ConstraintType;
9
+ }
10
+ export interface StringTypeAnnotations extends ConstraintAnnotations {
11
+ required?: RequiredAnnotation;
12
+ length?: LengthAnnotation;
13
+ pattern?: PatternAnnotation;
14
+ maxLength?: MaxLengthAnnotation;
15
+ minLength?: MinLengthAnnotation;
16
+ }
17
+ export interface BooleanTypeAnnotations extends ConstraintAnnotations {
18
+ required?: RequiredAnnotation;
19
+ equals?: EqualsAnnotation<boolean>;
20
+ }
21
+ export interface DateTypeAnnotations extends ConstraintAnnotations {
22
+ required?: RequiredAnnotation;
23
+ min?: MinimumAnnotation<Date>;
24
+ max?: MaximumAnnotation<Date>;
25
+ test?: TestAnnotation;
26
+ }
27
+ export interface ValidationAnnotation {
28
+ message?: string;
29
+ }
30
+ export interface RequiredAnnotation extends ValidationAnnotation {
31
+ required: boolean;
32
+ }
33
+ export interface LengthAnnotation extends ValidationAnnotation {
34
+ length: number;
35
+ }
36
+ export interface PatternAnnotation extends ValidationAnnotation {
37
+ pattern: RegExp;
38
+ }
39
+ export interface OfValuesAnnotation extends ValidationAnnotation {
40
+ values: [];
41
+ }
42
+ export interface EqualsAnnotation<T> extends ValidationAnnotation {
43
+ equals: T;
44
+ }
45
+ export interface MinimumAnnotation<T> extends ValidationAnnotation {
46
+ min: T;
47
+ }
48
+ export interface MaximumAnnotation<T> extends ValidationAnnotation {
49
+ max: T;
50
+ }
51
+ export interface TestAnnotation extends ValidationAnnotation {
52
+ test: (d: Date) => boolean;
53
+ name: string;
54
+ }
55
+ export interface MaxLengthAnnotation extends ValidationAnnotation {
56
+ maxLength: number;
57
+ }
58
+ export interface MinLengthAnnotation extends ValidationAnnotation {
59
+ minLength: number;
60
+ }
61
+ export declare function Annotate<T extends ConstraintAnnotations>(a: AnnotationType<T>): (target: Object, propertyKey: string) => void;
62
+ export declare function StringType(...annotations: {
63
+ [key: string]: ValidationAnnotation;
64
+ }[]): (target: Object, propertyKey: string) => void;
65
+ export declare function BooleanType(...annotations: {
66
+ [key: string]: ValidationAnnotation;
67
+ }[]): (target: Object, propertyKey: string) => void;
68
+ export declare function required(message?: string): {
69
+ [key: string]: RequiredAnnotation;
70
+ };
71
+ export declare function pattern(regex: RegExp, message?: string): {
72
+ [key: string]: PatternAnnotation;
73
+ };
74
+ export declare function length(length: number, message?: string): {
75
+ [key: string]: LengthAnnotation;
76
+ };
77
+ export declare function maxLength(maxLength: number, message?: string): {
78
+ [key: string]: MaxLengthAnnotation;
79
+ };
80
+ export declare function minLength(minLength: number, message?: string): {
81
+ [key: string]: MinLengthAnnotation;
82
+ };
83
+ export declare function ofValues(values: [], message?: string): {
84
+ [key: string]: OfValuesAnnotation;
85
+ };
86
+ export declare function equals<T>(value: T, message?: string): {
87
+ [key: string]: EqualsAnnotation<T>;
88
+ };
89
+ export declare abstract class AnnotationType<T> {
90
+ abstract readonly name: string;
91
+ abstract annotations?: T;
92
+ }
93
+ export declare class StringType2 extends AnnotationType<StringTypeAnnotations> {
94
+ readonly name: string;
95
+ annotations: StringTypeAnnotations;
96
+ required(message?: string): this;
97
+ pattern(pattern: RegExp, message?: string): this;
98
+ }
99
+ export declare class BooleanType2 extends AnnotationType<BooleanTypeAnnotations> {
100
+ readonly name: string;
101
+ annotations: BooleanTypeAnnotations;
102
+ required(message?: string): this;
103
+ equals(v: boolean, message?: string): this;
104
+ }
105
+ export declare function string(): StringType2;
106
+ export declare function boolean(): BooleanType2;
107
+ export declare class DateType extends AnnotationType<DateTypeAnnotations> {
108
+ readonly name: string;
109
+ annotations: DateTypeAnnotations;
110
+ required(message?: string): this;
111
+ min(v: Date, message?: string): this;
112
+ max(v: Date, message?: string): this;
113
+ test(name: string, v: (d: Date) => boolean, message?: string): this;
114
+ }
115
+ export declare function date(): DateType;
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@muziehdesign/forms",
3
+ "version": "0.0.1-alpha.102",
4
+ "peerDependencies": {
5
+ "@angular/common": "^14.0.0",
6
+ "@angular/core": "^14.0.0"
7
+ },
8
+ "dependencies": {
9
+ "tslib": "^2.3.0"
10
+ },
11
+ "module": "fesm2015/muziehdesign-forms.mjs",
12
+ "es2020": "fesm2020/muziehdesign-forms.mjs",
13
+ "esm2020": "esm2020/muziehdesign-forms.mjs",
14
+ "fesm2020": "fesm2020/muziehdesign-forms.mjs",
15
+ "fesm2015": "fesm2015/muziehdesign-forms.mjs",
16
+ "typings": "index.d.ts",
17
+ "exports": {
18
+ "./package.json": {
19
+ "default": "./package.json"
20
+ },
21
+ ".": {
22
+ "types": "./index.d.ts",
23
+ "esm2020": "./esm2020/muziehdesign-forms.mjs",
24
+ "es2020": "./fesm2020/muziehdesign-forms.mjs",
25
+ "es2015": "./fesm2015/muziehdesign-forms.mjs",
26
+ "node": "./fesm2015/muziehdesign-forms.mjs",
27
+ "default": "./fesm2020/muziehdesign-forms.mjs"
28
+ }
29
+ },
30
+ "sideEffects": false
31
+ }
@@ -0,0 +1,7 @@
1
+ export * from './lib/field-error';
2
+ export * from './lib/model-schema.factory';
3
+ export * from './lib/model-validator';
4
+ export * from './lib/type-annotations';
5
+ export * from './lib/forms.module';
6
+ export * from './lib/ng-form-model-state.service';
7
+ export * from './lib/field-errors/field-errors.component';