@builder-builder/builder 0.0.13 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +53 -0
- package/dist/codegen/index.d.ts +7 -0
- package/dist/codegen/index.js +212 -0
- package/dist/codegen/template.d.ts +5 -0
- package/dist/codegen/template.js +17 -0
- package/dist/entities/index.d.ts +3 -3
- package/dist/entities/index.js +1 -1
- package/dist/entities/kind.d.ts +1 -1
- package/dist/entities/serialise.d.ts +554 -8
- package/dist/entities/serialise.js +5 -3
- package/dist/entities/ui/describe.d.ts +222 -8
- package/dist/entities/ui/describe.js +5 -5
- package/dist/entities/ui/index.d.ts +2 -0
- package/dist/entities/ui/index.js +1 -0
- package/dist/entities/ui/input.d.ts +334 -0
- package/dist/entities/ui/input.js +39 -0
- package/dist/entities/ui/page.d.ts +222 -8
- package/dist/entities/ui/page.js +5 -5
- package/dist/entities/ui/ui.d.ts +3 -3
- package/dist/entities/ui/ui.js +7 -4
- package/dist/entities/validated.d.ts +4 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/mappers/index.d.ts +3 -2
- package/dist/mappers/index.js +1 -1
- package/dist/mappers/render/index.d.ts +1 -1
- package/dist/mappers/render/pages.d.ts +8 -0
- package/dist/mappers/render/pages.js +2 -1
- package/dist/mappers/render/render.js +19 -3
- package/dist/mappers/resolve.d.ts +4 -4
- package/dist/mappers/variants/index.d.ts +2 -1
- package/dist/mappers/variants/index.js +2 -1
- package/dist/mappers/variants/variants.d.ts +5 -2
- package/dist/mappers/variants/variants.js +2 -2
- package/dist/validate/brand.d.ts +0 -7
- package/dist/validate/brand.js +5 -5
- package/dist/validate/builder.d.ts +2 -1
- package/dist/validate/builder.js +14 -12
- package/dist/validate/errors.d.ts +130 -0
- package/dist/validate/errors.js +141 -0
- package/dist/validate/expectations.d.ts +3 -10
- package/dist/validate/expectations.js +8 -10
- package/dist/validate/index.d.ts +8 -14
- package/dist/validate/index.js +4 -7
- package/dist/validate/instance.d.ts +2 -15
- package/dist/validate/instance.js +41 -40
- package/dist/validate/model.d.ts +4 -31
- package/dist/validate/model.js +157 -176
- package/dist/validate/resolve.d.ts +3 -15
- package/dist/validate/resolve.js +66 -69
- package/dist/validate/result.d.ts +1 -7
- package/dist/validate/result.js +1 -4
- package/dist/validate/ui.d.ts +4 -4
- package/dist/validate/ui.js +80 -62
- package/dist/validate/variants.d.ts +2 -53
- package/dist/validate/variants.js +83 -86
- package/package.json +12 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { BuilderRefEntities, BuilderValidated } from '../entities/index';
|
|
2
2
|
import type { ValidationResult } from './result';
|
|
3
|
+
import { BuilderValidateErrors } from './errors.js';
|
|
3
4
|
export type BuilderValidationResult = ValidationResult<BuilderValidated>;
|
|
4
|
-
export declare function validateBuilder(input: unknown, references?: BuilderRefEntities): BuilderValidationResult;
|
|
5
|
+
export declare function validateBuilder(input: unknown, references?: BuilderRefEntities, errors?: BuilderValidateErrors): BuilderValidationResult;
|
package/dist/validate/builder.js
CHANGED
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
import { check } from '../check.js';
|
|
2
2
|
import { builder, BuilderSerialisedSchema, modelsMerge, serialise } from '../entities/index.js';
|
|
3
3
|
import { validate } from './brand.js';
|
|
4
|
+
import { BuilderValidateErrors } from './errors.js';
|
|
4
5
|
import { checkModelExpectations, validateModelStructure } from './model.js';
|
|
5
6
|
import { resolver } from './resolve.js';
|
|
6
|
-
import { builderErrorInvalidInput } from './result.js';
|
|
7
7
|
import { checkUIExpectations, validateUIStructure } from './ui.js';
|
|
8
|
-
export function validateBuilder(input, references = []) {
|
|
8
|
+
export function validateBuilder(input, references = [], errors = new BuilderValidateErrors()) {
|
|
9
9
|
if (!check.is(BuilderSerialisedSchema, input)) {
|
|
10
|
-
|
|
11
|
-
return [validate(serialise.builder(builder())), errors];
|
|
10
|
+
errors.invalidInput('builder');
|
|
11
|
+
return [validate(serialise.builder(builder())), errors.errors];
|
|
12
12
|
}
|
|
13
|
-
const resolve = resolver(references, input.bindings);
|
|
14
|
-
const
|
|
15
|
-
const
|
|
13
|
+
const resolve = resolver(errors, references, input.bindings);
|
|
14
|
+
const validatedModel = errors.scope('model', () => validateModelStructure(input.model, resolve, errors));
|
|
15
|
+
const validatedUI = errors.scope('ui', () => validateUIStructure(input.ui, resolve, errors));
|
|
16
16
|
const mergedModel = modelsMerge(validatedModel);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
errors.scope('model', () => {
|
|
18
|
+
checkModelExpectations(mergedModel, validatedModel, errors);
|
|
19
|
+
});
|
|
20
|
+
errors.scope('ui', () => {
|
|
21
|
+
checkUIExpectations(mergedModel, validatedUI, errors);
|
|
22
|
+
});
|
|
21
23
|
const data = validate({
|
|
22
24
|
...serialise.builder(builder()),
|
|
23
25
|
model: mergedModel,
|
|
24
26
|
ui: validatedUI
|
|
25
27
|
});
|
|
26
|
-
return [data,
|
|
28
|
+
return [data, errors.errors];
|
|
27
29
|
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { BuilderExpectationKind } from '../entities/index';
|
|
2
|
+
import type { BuilderErrorLocation, BuilderErrors } from '../exception';
|
|
3
|
+
import type { BuilderInstance } from '../instance';
|
|
4
|
+
export type BuilderInvalidInputTarget = 'builder' | 'model' | 'ui' | 'variants';
|
|
5
|
+
export type BuilderErrorInvalidPathReason = 'shape' | 'out-of-bounds' | 'missing-collection' | 'option-not-found';
|
|
6
|
+
export declare class BuilderValidateErrors {
|
|
7
|
+
#private;
|
|
8
|
+
get errors(): BuilderErrors;
|
|
9
|
+
scope<Result>(part: string | number, fn: () => Result): Result;
|
|
10
|
+
invalidInput(target: BuilderInvalidInputTarget): {
|
|
11
|
+
target: BuilderInvalidInputTarget;
|
|
12
|
+
kind: "invalid-input";
|
|
13
|
+
location: BuilderErrorLocation;
|
|
14
|
+
};
|
|
15
|
+
invalidOption(name: string, value: unknown): {
|
|
16
|
+
name: string;
|
|
17
|
+
value: unknown;
|
|
18
|
+
kind: "invalid-option";
|
|
19
|
+
location: BuilderErrorLocation;
|
|
20
|
+
};
|
|
21
|
+
invalidCollection(name: string): {
|
|
22
|
+
name: string;
|
|
23
|
+
kind: "invalid-collection";
|
|
24
|
+
location: BuilderErrorLocation;
|
|
25
|
+
};
|
|
26
|
+
duplicateName(name: string): {
|
|
27
|
+
name: string;
|
|
28
|
+
kind: "duplicate-name";
|
|
29
|
+
location: BuilderErrorLocation;
|
|
30
|
+
};
|
|
31
|
+
invalidCollectionBounds(name: string, min: number, max: number): {
|
|
32
|
+
name: string;
|
|
33
|
+
min: number;
|
|
34
|
+
max: number;
|
|
35
|
+
kind: "invalid-collection-bounds";
|
|
36
|
+
location: BuilderErrorLocation;
|
|
37
|
+
};
|
|
38
|
+
invalidPath(reason: BuilderErrorInvalidPathReason): {
|
|
39
|
+
reason: BuilderErrorInvalidPathReason;
|
|
40
|
+
kind: "invalid-path";
|
|
41
|
+
location: BuilderErrorLocation;
|
|
42
|
+
};
|
|
43
|
+
invalidSelectMapKey(key: string): {
|
|
44
|
+
key: string;
|
|
45
|
+
kind: "invalid-select-map-key";
|
|
46
|
+
location: BuilderErrorLocation;
|
|
47
|
+
};
|
|
48
|
+
unboundParameter(name: string): {
|
|
49
|
+
name: string;
|
|
50
|
+
kind: "unbound-parameter";
|
|
51
|
+
location: BuilderErrorLocation;
|
|
52
|
+
};
|
|
53
|
+
missingReference(id: string): {
|
|
54
|
+
id: string;
|
|
55
|
+
kind: "missing-reference";
|
|
56
|
+
location: BuilderErrorLocation;
|
|
57
|
+
};
|
|
58
|
+
unmetExpectation(expectationKind: BuilderExpectationKind, name: string): {
|
|
59
|
+
expectationKind: "option" | "component" | "collection";
|
|
60
|
+
name: string;
|
|
61
|
+
kind: "unmet-expectation";
|
|
62
|
+
location: BuilderErrorLocation;
|
|
63
|
+
};
|
|
64
|
+
unvalidated(value: unknown): {
|
|
65
|
+
value: unknown;
|
|
66
|
+
kind: "unvalidated";
|
|
67
|
+
location: BuilderErrorLocation;
|
|
68
|
+
};
|
|
69
|
+
missingComponent(component: string): {
|
|
70
|
+
component: string;
|
|
71
|
+
kind: "missing-component";
|
|
72
|
+
location: BuilderErrorLocation;
|
|
73
|
+
};
|
|
74
|
+
unexpectedComponent(component: string): {
|
|
75
|
+
component: string;
|
|
76
|
+
kind: "unexpected-component";
|
|
77
|
+
location: BuilderErrorLocation;
|
|
78
|
+
};
|
|
79
|
+
missingVariant(component: string, instance: BuilderInstance): {
|
|
80
|
+
component: string;
|
|
81
|
+
instance: BuilderInstance;
|
|
82
|
+
kind: "missing-variant";
|
|
83
|
+
location: BuilderErrorLocation;
|
|
84
|
+
};
|
|
85
|
+
invalidVariant(component: string, instance: BuilderInstance): {
|
|
86
|
+
component: string;
|
|
87
|
+
instance: BuilderInstance;
|
|
88
|
+
kind: "invalid-variant";
|
|
89
|
+
location: BuilderErrorLocation;
|
|
90
|
+
};
|
|
91
|
+
missingDetail(component: string, detail: string, instance: BuilderInstance): {
|
|
92
|
+
component: string;
|
|
93
|
+
detail: string;
|
|
94
|
+
instance: BuilderInstance;
|
|
95
|
+
kind: "missing-detail";
|
|
96
|
+
location: BuilderErrorLocation;
|
|
97
|
+
};
|
|
98
|
+
unexpectedDetail(component: string, detail: string, instance: BuilderInstance): {
|
|
99
|
+
component: string;
|
|
100
|
+
detail: string;
|
|
101
|
+
instance: BuilderInstance;
|
|
102
|
+
kind: "unexpected-detail";
|
|
103
|
+
location: BuilderErrorLocation;
|
|
104
|
+
};
|
|
105
|
+
invalidDetail(component: string, detail: string, instance: BuilderInstance): {
|
|
106
|
+
component: string;
|
|
107
|
+
detail: string;
|
|
108
|
+
instance: BuilderInstance;
|
|
109
|
+
kind: "invalid-detail";
|
|
110
|
+
location: BuilderErrorLocation;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export type BuilderErrorInvalidInput = ReturnType<BuilderValidateErrors['invalidInput']>;
|
|
114
|
+
export type BuilderErrorInvalidOption = ReturnType<BuilderValidateErrors['invalidOption']>;
|
|
115
|
+
export type BuilderErrorInvalidCollection = ReturnType<BuilderValidateErrors['invalidCollection']>;
|
|
116
|
+
export type BuilderErrorDuplicateName = ReturnType<BuilderValidateErrors['duplicateName']>;
|
|
117
|
+
export type BuilderErrorInvalidCollectionBounds = ReturnType<BuilderValidateErrors['invalidCollectionBounds']>;
|
|
118
|
+
export type BuilderErrorInvalidPath = ReturnType<BuilderValidateErrors['invalidPath']>;
|
|
119
|
+
export type BuilderErrorInvalidSelectMapKey = ReturnType<BuilderValidateErrors['invalidSelectMapKey']>;
|
|
120
|
+
export type BuilderErrorUnboundParameter = ReturnType<BuilderValidateErrors['unboundParameter']>;
|
|
121
|
+
export type BuilderErrorMissingReference = ReturnType<BuilderValidateErrors['missingReference']>;
|
|
122
|
+
export type BuilderErrorUnmetExpectation = ReturnType<BuilderValidateErrors['unmetExpectation']>;
|
|
123
|
+
export type BuilderErrorUnvalidated = ReturnType<BuilderValidateErrors['unvalidated']>;
|
|
124
|
+
export type BuilderErrorMissingComponent = ReturnType<BuilderValidateErrors['missingComponent']>;
|
|
125
|
+
export type BuilderErrorUnexpectedComponent = ReturnType<BuilderValidateErrors['unexpectedComponent']>;
|
|
126
|
+
export type BuilderErrorMissingVariant = ReturnType<BuilderValidateErrors['missingVariant']>;
|
|
127
|
+
export type BuilderErrorInvalidVariant = ReturnType<BuilderValidateErrors['invalidVariant']>;
|
|
128
|
+
export type BuilderErrorMissingDetail = ReturnType<BuilderValidateErrors['missingDetail']>;
|
|
129
|
+
export type BuilderErrorUnexpectedDetail = ReturnType<BuilderValidateErrors['unexpectedDetail']>;
|
|
130
|
+
export type BuilderErrorInvalidDetail = ReturnType<BuilderValidateErrors['invalidDetail']>;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { builderError } from '../exception.js';
|
|
2
|
+
export class BuilderValidateErrors {
|
|
3
|
+
#errors = [];
|
|
4
|
+
#location = [];
|
|
5
|
+
get errors() {
|
|
6
|
+
return this.#errors;
|
|
7
|
+
}
|
|
8
|
+
scope(part, fn) {
|
|
9
|
+
this.#location = [...this.#location, part];
|
|
10
|
+
try {
|
|
11
|
+
return fn();
|
|
12
|
+
}
|
|
13
|
+
finally {
|
|
14
|
+
this.#location = this.#location.slice(0, -1);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
invalidInput(target) {
|
|
18
|
+
return this.#addError({
|
|
19
|
+
...builderError('invalid-input', this.#location),
|
|
20
|
+
target
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
invalidOption(name, value) {
|
|
24
|
+
return this.#addError({
|
|
25
|
+
...builderError('invalid-option', this.#location),
|
|
26
|
+
name,
|
|
27
|
+
value
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
invalidCollection(name) {
|
|
31
|
+
return this.#addError({
|
|
32
|
+
...builderError('invalid-collection', this.#location),
|
|
33
|
+
name
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
duplicateName(name) {
|
|
37
|
+
return this.#addError({
|
|
38
|
+
...builderError('duplicate-name', this.#location),
|
|
39
|
+
name
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
invalidCollectionBounds(name, min, max) {
|
|
43
|
+
return this.#addError({
|
|
44
|
+
...builderError('invalid-collection-bounds', this.#location),
|
|
45
|
+
name,
|
|
46
|
+
min,
|
|
47
|
+
max
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
invalidPath(reason) {
|
|
51
|
+
return this.#addError({
|
|
52
|
+
...builderError('invalid-path', this.#location),
|
|
53
|
+
reason
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
invalidSelectMapKey(key) {
|
|
57
|
+
return this.#addError({
|
|
58
|
+
...builderError('invalid-select-map-key', this.#location),
|
|
59
|
+
key
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
unboundParameter(name) {
|
|
63
|
+
return this.#addError({
|
|
64
|
+
...builderError('unbound-parameter', this.#location),
|
|
65
|
+
name
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
missingReference(id) {
|
|
69
|
+
return this.#addError({
|
|
70
|
+
...builderError('missing-reference', this.#location),
|
|
71
|
+
id
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
unmetExpectation(expectationKind, name) {
|
|
75
|
+
return this.#addError({
|
|
76
|
+
...builderError('unmet-expectation', this.#location),
|
|
77
|
+
expectationKind,
|
|
78
|
+
name
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
unvalidated(value) {
|
|
82
|
+
return this.#addError({
|
|
83
|
+
...builderError('unvalidated', this.#location),
|
|
84
|
+
value
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
missingComponent(component) {
|
|
88
|
+
return this.#addError({
|
|
89
|
+
...builderError('missing-component', this.#location),
|
|
90
|
+
component
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
unexpectedComponent(component) {
|
|
94
|
+
return this.#addError({
|
|
95
|
+
...builderError('unexpected-component', this.#location),
|
|
96
|
+
component
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
missingVariant(component, instance) {
|
|
100
|
+
return this.#addError({
|
|
101
|
+
...builderError('missing-variant', this.#location),
|
|
102
|
+
component,
|
|
103
|
+
instance
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
invalidVariant(component, instance) {
|
|
107
|
+
return this.#addError({
|
|
108
|
+
...builderError('invalid-variant', this.#location),
|
|
109
|
+
component,
|
|
110
|
+
instance
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
missingDetail(component, detail, instance) {
|
|
114
|
+
return this.#addError({
|
|
115
|
+
...builderError('missing-detail', this.#location),
|
|
116
|
+
component,
|
|
117
|
+
detail,
|
|
118
|
+
instance
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
unexpectedDetail(component, detail, instance) {
|
|
122
|
+
return this.#addError({
|
|
123
|
+
...builderError('unexpected-detail', this.#location),
|
|
124
|
+
component,
|
|
125
|
+
detail,
|
|
126
|
+
instance
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
invalidDetail(component, detail, instance) {
|
|
130
|
+
return this.#addError({
|
|
131
|
+
...builderError('invalid-detail', this.#location),
|
|
132
|
+
component,
|
|
133
|
+
detail,
|
|
134
|
+
instance
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
#addError(error) {
|
|
138
|
+
this.#errors = [...this.#errors, error];
|
|
139
|
+
return error;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
export declare function
|
|
4
|
-
expectationKind: "option" | "component" | "collection";
|
|
5
|
-
name: string;
|
|
6
|
-
kind: "unmet-expectation";
|
|
7
|
-
location: BuilderErrorLocation;
|
|
8
|
-
};
|
|
9
|
-
export type BuilderErrorUnmetExpectation = ReturnType<typeof builderErrorUnmetExpectation>;
|
|
10
|
-
export declare function checkExpectations(model: BuilderModelSerialised, expectations: BuilderExpectationsSerialised, location: BuilderErrorLocation): BuilderErrors;
|
|
1
|
+
import type { BuilderExpectationsSerialised, BuilderModelSerialised } from '../entities/index';
|
|
2
|
+
import type { BuilderValidateErrors } from './errors';
|
|
3
|
+
export declare function checkExpectations(model: BuilderModelSerialised, expectations: BuilderExpectationsSerialised, errors: BuilderValidateErrors): void;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
return [builderErrorUnmetExpectation(kind, name, [...location, index])];
|
|
1
|
+
export function checkExpectations(model, expectations, errors) {
|
|
2
|
+
expectations.forEach(({ kind, name }, index) => {
|
|
3
|
+
errors.scope(index, () => {
|
|
4
|
+
if (model[`${kind}s`].some((entry) => entry.name === name)) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
errors.unmetExpectation(kind, name);
|
|
8
|
+
});
|
|
11
9
|
});
|
|
12
10
|
}
|
package/dist/validate/index.d.ts
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
export type { BuilderErrorUnvalidated } from './brand';
|
|
2
1
|
export type { BuilderValidationResult } from './builder';
|
|
3
|
-
export type { BuilderErrorUnmetExpectation } from './
|
|
4
|
-
export type {
|
|
5
|
-
export type {
|
|
6
|
-
export type { BuilderErrorMissingReference, BuilderErrorUnboundParameter } from './resolve';
|
|
7
|
-
export type { BuilderErrorInvalidInput } from './result';
|
|
2
|
+
export type { BuilderErrorDuplicateName, BuilderErrorInvalidCollection, BuilderErrorInvalidCollectionBounds, BuilderErrorInvalidDetail, BuilderErrorInvalidInput, BuilderErrorInvalidOption, BuilderErrorInvalidPath, BuilderErrorInvalidPathReason, BuilderErrorInvalidSelectMapKey, BuilderErrorInvalidVariant, BuilderErrorMissingComponent, BuilderErrorMissingDetail, BuilderErrorMissingReference, BuilderErrorMissingVariant, BuilderErrorUnboundParameter, BuilderErrorUnexpectedComponent, BuilderErrorUnexpectedDetail, BuilderErrorUnmetExpectation, BuilderErrorUnvalidated, BuilderInvalidInputTarget } from './errors';
|
|
3
|
+
export type { BuilderInstanceValidationResult } from './instance';
|
|
4
|
+
export type { BuilderModelValidationResult } from './model';
|
|
8
5
|
export type { BuilderUIValidationResult } from './ui';
|
|
9
|
-
export type { BuilderComponentVariantsValidationResult,
|
|
10
|
-
export { assertValidated
|
|
6
|
+
export type { BuilderComponentVariantsValidationResult, BuilderVariantsValidationOptions } from './variants';
|
|
7
|
+
export { assertValidated } from './brand.js';
|
|
11
8
|
export { validateBuilder } from './builder.js';
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
export { builderErrorDuplicateName, builderErrorInvalidCollectionBounds, builderErrorInvalidPath, builderErrorInvalidSelectMapKey, validateModel } from './model.js';
|
|
15
|
-
export { builderErrorMissingReference, builderErrorUnboundParameter } from './resolve.js';
|
|
16
|
-
export { builderErrorInvalidInput } from './result.js';
|
|
9
|
+
export { validateInstance } from './instance.js';
|
|
10
|
+
export { validateModel } from './model.js';
|
|
17
11
|
export { validateUI } from './ui.js';
|
|
18
|
-
export {
|
|
12
|
+
export { validateVariants } from './variants.js';
|
package/dist/validate/index.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
export { assertValidated
|
|
1
|
+
export { assertValidated } from './brand.js';
|
|
2
2
|
export { validateBuilder } from './builder.js';
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export { builderErrorDuplicateName, builderErrorInvalidCollectionBounds, builderErrorInvalidPath, builderErrorInvalidSelectMapKey, validateModel } from './model.js';
|
|
6
|
-
export { builderErrorMissingReference, builderErrorUnboundParameter } from './resolve.js';
|
|
7
|
-
export { builderErrorInvalidInput } from './result.js';
|
|
3
|
+
export { validateInstance } from './instance.js';
|
|
4
|
+
export { validateModel } from './model.js';
|
|
8
5
|
export { validateUI } from './ui.js';
|
|
9
|
-
export {
|
|
6
|
+
export { validateVariants } from './variants.js';
|
|
@@ -1,19 +1,6 @@
|
|
|
1
1
|
import type { BuilderInstanceValidated, BuilderModelValidated } from '../entities/index';
|
|
2
|
-
import type { BuilderErrorLocation } from '../exception';
|
|
3
2
|
import type { BuilderInstance } from '../instance';
|
|
4
3
|
import type { ValidationResult } from './result';
|
|
5
|
-
|
|
6
|
-
name: string;
|
|
7
|
-
value: unknown;
|
|
8
|
-
kind: "invalid-option";
|
|
9
|
-
location: BuilderErrorLocation;
|
|
10
|
-
};
|
|
11
|
-
export type BuilderErrorInvalidOption = ReturnType<typeof builderErrorInvalidOption>;
|
|
12
|
-
export declare function builderErrorInvalidCollection(name: string, location?: BuilderErrorLocation): {
|
|
13
|
-
name: string;
|
|
14
|
-
kind: "invalid-collection";
|
|
15
|
-
location: BuilderErrorLocation;
|
|
16
|
-
};
|
|
17
|
-
export type BuilderErrorInvalidCollection = ReturnType<typeof builderErrorInvalidCollection>;
|
|
4
|
+
import { BuilderValidateErrors } from './errors.js';
|
|
18
5
|
export type BuilderInstanceValidationResult = ValidationResult<BuilderInstanceValidated>;
|
|
19
|
-
export declare function validateInstance(model: BuilderModelValidated, instance: BuilderInstance): BuilderInstanceValidationResult;
|
|
6
|
+
export declare function validateInstance(model: BuilderModelValidated, instance: BuilderInstance, errors?: BuilderValidateErrors): BuilderInstanceValidationResult;
|
|
@@ -1,47 +1,48 @@
|
|
|
1
1
|
import { check } from '../check.js';
|
|
2
2
|
import { optionValueSchema } from '../entities/index.js';
|
|
3
|
-
import { builderError } from '../exception.js';
|
|
4
3
|
import { BuilderInstancesSchema } from '../instance.js';
|
|
5
4
|
import { resolveCollection, resolveOption } from '../mappers/index.js';
|
|
6
5
|
import { validate } from './brand.js';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return { ...builderError('invalid-collection', location), name };
|
|
12
|
-
}
|
|
13
|
-
export function validateInstance(model, instance) {
|
|
14
|
-
const errors = checkInstance(model, instance, ['instance']);
|
|
15
|
-
return [validate(instance), errors];
|
|
16
|
-
}
|
|
17
|
-
function checkInstance(model, instance, location) {
|
|
18
|
-
const { options, collections } = model;
|
|
19
|
-
const optionErrors = options.flatMap((option) => {
|
|
20
|
-
const { name } = option;
|
|
21
|
-
const payload = resolveOption(option, model, instance);
|
|
22
|
-
if (!payload) {
|
|
23
|
-
return [];
|
|
24
|
-
}
|
|
25
|
-
const value = instance[name];
|
|
26
|
-
if (!check.is(optionValueSchema(payload), value)) {
|
|
27
|
-
return [builderErrorInvalidOption(name, value, [...location, name])];
|
|
28
|
-
}
|
|
29
|
-
return [];
|
|
30
|
-
});
|
|
31
|
-
const collectionErrors = collections.flatMap((collection) => {
|
|
32
|
-
const { name } = collection;
|
|
33
|
-
const payload = resolveCollection(collection, model, instance);
|
|
34
|
-
if (!payload) {
|
|
35
|
-
return [];
|
|
36
|
-
}
|
|
37
|
-
const existing = instance[name];
|
|
38
|
-
if (!check.is(BuilderInstancesSchema, existing)) {
|
|
39
|
-
return [builderErrorInvalidCollection(name, [...location, name])];
|
|
40
|
-
}
|
|
41
|
-
return existing.flatMap((itemInstance, index) => checkInstance(payload.model, itemInstance, [...location, name, index]).map((error) => ({
|
|
42
|
-
...error,
|
|
43
|
-
name: `${name}[${index}].${error.name}`
|
|
44
|
-
})));
|
|
6
|
+
import { BuilderValidateErrors } from './errors.js';
|
|
7
|
+
export function validateInstance(model, instance, errors = new BuilderValidateErrors()) {
|
|
8
|
+
errors.scope('instance', () => {
|
|
9
|
+
checkInstance(model, instance);
|
|
45
10
|
});
|
|
46
|
-
return [
|
|
11
|
+
return [validate(instance), errors.errors];
|
|
12
|
+
function checkInstance(scopeModel, scopeInstance, namePrefix = '') {
|
|
13
|
+
scopeModel.options.forEach((option) => {
|
|
14
|
+
const { name } = option;
|
|
15
|
+
const payload = resolveOption(option, scopeModel, scopeInstance);
|
|
16
|
+
if (!payload) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const value = scopeInstance[name];
|
|
20
|
+
if (!check.is(optionValueSchema(payload), value)) {
|
|
21
|
+
errors.scope(name, () => {
|
|
22
|
+
errors.invalidOption(`${namePrefix}${name}`, value);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
scopeModel.collections.forEach((collection) => {
|
|
27
|
+
const { name } = collection;
|
|
28
|
+
const payload = resolveCollection(collection, scopeModel, scopeInstance);
|
|
29
|
+
if (!payload) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const existing = scopeInstance[name];
|
|
33
|
+
if (!check.is(BuilderInstancesSchema, existing)) {
|
|
34
|
+
errors.scope(name, () => {
|
|
35
|
+
errors.invalidCollection(`${namePrefix}${name}`);
|
|
36
|
+
});
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
errors.scope(name, () => {
|
|
40
|
+
existing.forEach((itemInstance, index) => {
|
|
41
|
+
errors.scope(index, () => {
|
|
42
|
+
checkInstance(payload.model, itemInstance, `${namePrefix}${name}[${index}].`);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
47
48
|
}
|
package/dist/validate/model.d.ts
CHANGED
|
@@ -1,36 +1,9 @@
|
|
|
1
1
|
import type { BuilderModelSerialised, BuilderModelValidated, BuilderRefEntities } from '../entities/index';
|
|
2
|
-
import type { BuilderErrorLocation, BuilderErrors } from '../exception';
|
|
3
2
|
import type { ParamableSerialised } from '../references';
|
|
4
3
|
import type { BuilderResolve } from './resolve';
|
|
5
4
|
import type { ValidationResult } from './result';
|
|
5
|
+
import { BuilderValidateErrors } from './errors.js';
|
|
6
6
|
export type BuilderModelValidationResult = ValidationResult<BuilderModelValidated>;
|
|
7
|
-
export declare function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
location: BuilderErrorLocation;
|
|
11
|
-
};
|
|
12
|
-
export type BuilderErrorDuplicateName = ReturnType<typeof builderErrorDuplicateName>;
|
|
13
|
-
export declare function builderErrorInvalidCollectionBounds(name: string, min: number, max: number, location?: BuilderErrorLocation): {
|
|
14
|
-
name: string;
|
|
15
|
-
min: number;
|
|
16
|
-
max: number;
|
|
17
|
-
kind: "invalid-collection-bounds";
|
|
18
|
-
location: BuilderErrorLocation;
|
|
19
|
-
};
|
|
20
|
-
export type BuilderErrorInvalidCollectionBounds = ReturnType<typeof builderErrorInvalidCollectionBounds>;
|
|
21
|
-
export type BuilderErrorInvalidPathReason = 'shape' | 'out-of-bounds' | 'missing-collection' | 'option-not-found';
|
|
22
|
-
export declare function builderErrorInvalidPath(reason: BuilderErrorInvalidPathReason, location?: BuilderErrorLocation): {
|
|
23
|
-
reason: BuilderErrorInvalidPathReason;
|
|
24
|
-
kind: "invalid-path";
|
|
25
|
-
location: BuilderErrorLocation;
|
|
26
|
-
};
|
|
27
|
-
export type BuilderErrorInvalidPath = ReturnType<typeof builderErrorInvalidPath>;
|
|
28
|
-
export declare function builderErrorInvalidSelectMapKey(key: string, location?: BuilderErrorLocation): {
|
|
29
|
-
key: string;
|
|
30
|
-
kind: "invalid-select-map-key";
|
|
31
|
-
location: BuilderErrorLocation;
|
|
32
|
-
};
|
|
33
|
-
export type BuilderErrorInvalidSelectMapKey = ReturnType<typeof builderErrorInvalidSelectMapKey>;
|
|
34
|
-
export declare function validateModel(input: unknown, references?: BuilderRefEntities): BuilderModelValidationResult;
|
|
35
|
-
export declare function checkModelExpectations(mergedModel: BuilderModelSerialised, model: BuilderModelSerialised, location: BuilderErrorLocation): BuilderErrors;
|
|
36
|
-
export declare function validateModelStructure(input: ParamableSerialised<BuilderModelSerialised>, resolve: BuilderResolve, location: BuilderErrorLocation): BuilderModelValidationResult;
|
|
7
|
+
export declare function validateModel(input: unknown, references?: BuilderRefEntities, errors?: BuilderValidateErrors): BuilderModelValidationResult;
|
|
8
|
+
export declare function checkModelExpectations(mergedModel: BuilderModelSerialised, rootModel: BuilderModelSerialised, errors: BuilderValidateErrors): void;
|
|
9
|
+
export declare function validateModelStructure(input: ParamableSerialised<BuilderModelSerialised>, resolve: BuilderResolve, errors: BuilderValidateErrors): BuilderModelValidated;
|