@builder-builder/builder 0.0.27 → 0.0.28
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/bb.js +4 -4
- package/dist/client/client.d.ts +2 -1
- package/dist/client/client.js +4 -1
- package/dist/client/public.d.ts +2 -2
- package/dist/client/public.js +1 -1
- package/dist/client/schema.d.ts +79 -18
- package/dist/client/schema.js +6 -1
- package/dist/components/BuilderRender.svelte.d.ts +2 -2
- package/dist/components/index.js +4377 -4303
- package/dist/components/index.min.js +3 -0
- package/dist/entities/collection/collection.d.ts +66 -66
- package/dist/entities/collection/config.d.ts +17 -17
- package/dist/entities/collection/when.d.ts +1 -1
- package/dist/entities/component/component.d.ts +64 -64
- package/dist/entities/component/config.d.ts +33 -33
- package/dist/entities/component/config.js +18 -16
- package/dist/entities/component/detail.d.ts +61 -0
- package/dist/entities/component/detail.js +71 -0
- package/dist/entities/component/index.d.ts +2 -2
- package/dist/entities/component/index.js +1 -1
- package/dist/entities/component/when.d.ts +2 -2
- package/dist/entities/expectation.d.ts +1 -1
- package/dist/entities/index.d.ts +4 -4
- package/dist/entities/index.js +1 -1
- package/dist/entities/kind.d.ts +3 -3
- package/dist/entities/kind.js +20 -20
- package/dist/entities/model/methods.d.ts +1 -1
- package/dist/entities/option/config.d.ts +7 -7
- package/dist/entities/option/config.js +1 -1
- package/dist/entities/option/index.d.ts +4 -4
- package/dist/entities/option/index.js +2 -2
- package/dist/entities/option/option.d.ts +22 -22
- package/dist/entities/option/select.d.ts +1 -1
- package/dist/entities/option/toggle.d.ts +9 -9
- package/dist/entities/option/toggle.js +15 -10
- package/dist/entities/option/when.d.ts +1 -1
- package/dist/entities/paths.d.ts +2 -2
- package/dist/entities/pricing/expression.d.ts +16 -39
- package/dist/entities/pricing/expression.js +1 -16
- package/dist/entities/pricing/index.d.ts +1 -1
- package/dist/entities/pricing/rates.d.ts +1 -1
- package/dist/entities/references.d.ts +24 -24
- package/dist/entities/serialise.d.ts +31 -32
- package/dist/entities/serialise.js +7 -7
- package/dist/entities/ui/describe.d.ts +1 -1
- package/dist/entities/ui/input.d.ts +1 -1
- package/dist/entities/ui/page.d.ts +1 -1
- package/dist/entities/ui/pages.d.ts +2 -2
- package/dist/entities/validated.d.ts +2 -2
- package/dist/entities/when.d.ts +5 -5
- package/dist/environment.d.ts +2 -2
- package/dist/errors/errors.d.ts +86 -55
- package/dist/errors/errors.js +36 -5
- package/dist/errors/exception.d.ts +3 -3
- package/dist/errors/index.d.ts +1 -1
- package/dist/errors/index.js +1 -1
- package/dist/errors/public.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/instance.d.ts +53 -9
- package/dist/instance.js +6 -2
- package/dist/mappers/dependencies.d.ts +3 -0
- package/dist/mappers/dependencies.js +44 -0
- package/dist/mappers/index.d.ts +2 -2
- package/dist/mappers/index.js +2 -1
- package/dist/mappers/instance.js +26 -21
- package/dist/mappers/price.js +6 -4
- package/dist/mappers/variants/index.d.ts +1 -2
- package/dist/mappers/variants/index.js +1 -2
- package/dist/mappers/variants/option-graph.d.ts +1 -2
- package/dist/mappers/variants/option-graph.js +3 -17
- package/dist/mappers/variants/variants.d.ts +3 -6
- package/dist/mappers/variants/variants.js +34 -11
- package/dist/primitive.d.ts +3 -0
- package/dist/primitive.js +2 -0
- package/dist/public.d.ts +8 -8
- package/dist/public.js +1 -1
- package/dist/validate/builder.d.ts +2 -2
- package/dist/validate/builder.js +15 -15
- package/dist/validate/expectations.d.ts +2 -2
- package/dist/validate/expectations.js +3 -3
- package/dist/validate/instance.d.ts +2 -2
- package/dist/validate/instance.js +31 -13
- package/dist/validate/model.d.ts +4 -4
- package/dist/validate/model.js +51 -42
- package/dist/validate/paths.d.ts +2 -2
- package/dist/validate/paths.js +19 -14
- package/dist/validate/pricing.d.ts +4 -4
- package/dist/validate/pricing.js +31 -31
- package/dist/validate/resolve.d.ts +2 -2
- package/dist/validate/resolve.js +18 -18
- package/dist/validate/ui.d.ts +4 -4
- package/dist/validate/ui.js +38 -38
- package/dist/validate/variants.d.ts +3 -3
- package/dist/validate/variants.js +32 -31
- package/package.json +4 -2
- package/dist/entities/component/field.d.ts +0 -59
- package/dist/entities/component/field.js +0 -52
package/dist/validate/ui.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { BuilderModelSerialisedSchema, BuilderPathSchema, BuilderUIInputMetadataSchema, BuilderUIInputSerialisedSchema, BuilderUIInputsSerialisedSchema, BuilderUIItemSerialisedSchema, BuilderUIItemsSerialisedSchema, BuilderUISerialisedSchema, modelsMerge, serialise, uis, validateUIDescribe, validateUIInput, validateUIPage, validateUIPages } from '../entities/index.js';
|
|
2
|
-
import {
|
|
2
|
+
import { BuilderIssuesScope, check } from '../errors/index.js';
|
|
3
3
|
import { resolveCollections } from '../mappers/index.js';
|
|
4
4
|
import { StringSchema } from '../primitive.js';
|
|
5
5
|
import { validate } from './brand.js';
|
|
6
6
|
import { checkExpectations } from './expectations.js';
|
|
7
7
|
import { checkPath } from './paths.js';
|
|
8
8
|
import { resolver } from './resolve.js';
|
|
9
|
-
export function validateUI(input, references = [],
|
|
9
|
+
export function validateUI(input, references = [], issues = new BuilderIssuesScope(input)) {
|
|
10
10
|
if (!check.is(BuilderUISerialisedSchema, input)) {
|
|
11
|
-
|
|
12
|
-
return [validate(serialise.ui(uis())), errors.
|
|
11
|
+
issues.entityInvalid('ui');
|
|
12
|
+
return [validate(serialise.ui(uis())), issues.errors, issues.warnings];
|
|
13
13
|
}
|
|
14
|
-
const resolve = resolver(
|
|
15
|
-
const structure = validateUIStructure(input, resolve,
|
|
16
|
-
return [validate(structure), errors.
|
|
14
|
+
const resolve = resolver(issues, references);
|
|
15
|
+
const structure = validateUIStructure(input, resolve, issues);
|
|
16
|
+
return [validate(structure), issues.errors, issues.warnings];
|
|
17
17
|
}
|
|
18
|
-
export function validateUIStructure(ui, resolve,
|
|
18
|
+
export function validateUIStructure(ui, resolve, issues) {
|
|
19
19
|
const childUIs = walkChildUIs();
|
|
20
|
-
const items =
|
|
20
|
+
const items = issues.scope('items', () => walkItems(ui.items));
|
|
21
21
|
const data = {
|
|
22
22
|
...ui,
|
|
23
23
|
uis: childUIs,
|
|
@@ -25,40 +25,40 @@ export function validateUIStructure(ui, resolve, errors) {
|
|
|
25
25
|
};
|
|
26
26
|
return data;
|
|
27
27
|
function walkChildUIs() {
|
|
28
|
-
return
|
|
28
|
+
return issues.scope('uis', () => ui.uis.flatMap((part, partIndex) => issues.scope(partIndex, () => {
|
|
29
29
|
const resolved = resolve(part, BuilderUISerialisedSchema);
|
|
30
30
|
if (resolved == null) {
|
|
31
31
|
return [];
|
|
32
32
|
}
|
|
33
|
-
return [validateUIStructure(resolved, resolve,
|
|
33
|
+
return [validateUIStructure(resolved, resolve, issues)];
|
|
34
34
|
})));
|
|
35
35
|
}
|
|
36
36
|
function walkItems(parts) {
|
|
37
|
-
return parts.map((item, itemIndex) =>
|
|
37
|
+
return parts.map((item, itemIndex) => issues.scope(itemIndex, () => {
|
|
38
38
|
const resolved = resolve(item, BuilderUIItemSerialisedSchema);
|
|
39
39
|
return walkUIItem((resolved ?? item));
|
|
40
40
|
}));
|
|
41
41
|
}
|
|
42
42
|
function walkUIItem(item) {
|
|
43
43
|
if (item.type === 'page') {
|
|
44
|
-
validateUIPage(item, [],
|
|
44
|
+
validateUIPage(item, [], issues);
|
|
45
45
|
}
|
|
46
46
|
else if (item.type === 'pages') {
|
|
47
|
-
validateUIPages(item, [],
|
|
47
|
+
validateUIPages(item, [], issues);
|
|
48
48
|
}
|
|
49
49
|
else if (item.type === 'describe') {
|
|
50
|
-
validateUIDescribe(item, [],
|
|
50
|
+
validateUIDescribe(item, [], issues);
|
|
51
51
|
}
|
|
52
|
-
const label =
|
|
52
|
+
const label = issues.scope('label', () => resolve(item.label, StringSchema) ?? item.label);
|
|
53
53
|
if (item.type === 'pages') {
|
|
54
|
-
const innerItems =
|
|
54
|
+
const innerItems = issues.scope('items', () => {
|
|
55
55
|
const resolved = resolve(item.items, BuilderUIItemsSerialisedSchema);
|
|
56
56
|
const resolvedItems = (Array.isArray(resolved) ? resolved : item.items);
|
|
57
57
|
return walkItems(resolvedItems);
|
|
58
58
|
});
|
|
59
59
|
return { ...item, label, items: innerItems };
|
|
60
60
|
}
|
|
61
|
-
const inputs =
|
|
61
|
+
const inputs = issues.scope('inputs', () => {
|
|
62
62
|
const resolved = resolve(item.inputs, BuilderUIInputsSerialisedSchema);
|
|
63
63
|
if (!Array.isArray(resolved)) {
|
|
64
64
|
return resolved ?? item.inputs;
|
|
@@ -68,18 +68,18 @@ export function validateUIStructure(ui, resolve, errors) {
|
|
|
68
68
|
return { ...item, label, inputs };
|
|
69
69
|
}
|
|
70
70
|
function walkInputs(inputs) {
|
|
71
|
-
return inputs.map((entry, entryIndex) =>
|
|
71
|
+
return inputs.map((entry, entryIndex) => issues.scope(entryIndex, () => {
|
|
72
72
|
const resolvedEntry = resolve(entry, BuilderUIInputSerialisedSchema);
|
|
73
73
|
return walkInput((resolvedEntry ?? entry));
|
|
74
74
|
}));
|
|
75
75
|
}
|
|
76
76
|
function walkInput(value) {
|
|
77
|
-
validateUIInput(value, [],
|
|
78
|
-
const path =
|
|
77
|
+
validateUIInput(value, [], issues);
|
|
78
|
+
const path = issues.scope('path', () => resolve(value.path, BuilderPathSchema) ?? value.path);
|
|
79
79
|
const displayName = value.displayName &&
|
|
80
|
-
|
|
81
|
-
const kind = value.kind &&
|
|
82
|
-
const metadata = value.metadata &&
|
|
80
|
+
issues.scope('displayName', () => resolve(value.displayName, StringSchema) ?? value.displayName);
|
|
81
|
+
const kind = value.kind && issues.scope('kind', () => resolve(value.kind, StringSchema) ?? value.kind);
|
|
82
|
+
const metadata = value.metadata && issues.scope('metadata', () => walkMetadata(value.metadata));
|
|
83
83
|
return { ...value, path, displayName, kind, metadata };
|
|
84
84
|
}
|
|
85
85
|
function walkMetadata(rawMetadata) {
|
|
@@ -88,28 +88,28 @@ export function validateUIStructure(ui, resolve, errors) {
|
|
|
88
88
|
return rawMetadata;
|
|
89
89
|
}
|
|
90
90
|
return Object.entries(resolved).reduce((entries, [key, entryValue]) => {
|
|
91
|
-
const resolvedValue =
|
|
91
|
+
const resolvedValue = issues.scope(key, () => resolve(entryValue));
|
|
92
92
|
return { ...entries, [key]: resolvedValue ?? entryValue };
|
|
93
93
|
}, {});
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
export function checkUIExpectations(mergedModel, ui,
|
|
96
|
+
export function checkUIExpectations(mergedModel, ui, issues) {
|
|
97
97
|
const expectedOptionNames = collectExpectedOptionNames(ui);
|
|
98
|
-
|
|
99
|
-
checkExpectations(mergedModel, ui.expectations,
|
|
98
|
+
issues.scope('expectations', () => {
|
|
99
|
+
checkExpectations(mergedModel, ui.expectations, issues);
|
|
100
100
|
});
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
issues.scope('items', () => walkItems(mergedModel, ui.items));
|
|
102
|
+
issues.scope('uis', () => {
|
|
103
103
|
ui.uis.forEach((nested, nestedIndex) => {
|
|
104
|
-
|
|
105
|
-
checkUIExpectations(mergedModel, nested,
|
|
104
|
+
issues.scope(nestedIndex, () => {
|
|
105
|
+
checkUIExpectations(mergedModel, nested, issues);
|
|
106
106
|
});
|
|
107
107
|
});
|
|
108
108
|
});
|
|
109
109
|
function walkItems(model, items) {
|
|
110
110
|
items.forEach((entry, itemIndex) => {
|
|
111
111
|
const item = entry;
|
|
112
|
-
|
|
112
|
+
issues.scope(itemIndex, () => {
|
|
113
113
|
if (item.type === 'pages') {
|
|
114
114
|
walkPages(model, item);
|
|
115
115
|
return;
|
|
@@ -118,8 +118,8 @@ export function checkUIExpectations(mergedModel, ui, errors) {
|
|
|
118
118
|
if (!Array.isArray(inputs)) {
|
|
119
119
|
return;
|
|
120
120
|
}
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
issues.scope('inputs', () => inputs.forEach((input, entryIndex) => {
|
|
122
|
+
issues.scope(entryIndex, () => walkInput(model, input));
|
|
123
123
|
}));
|
|
124
124
|
});
|
|
125
125
|
});
|
|
@@ -132,7 +132,7 @@ export function checkUIExpectations(mergedModel, ui, errors) {
|
|
|
132
132
|
const innerModels = resolveCollections(collection).flatMap(({ model: configModel }) => check.is(BuilderModelSerialisedSchema, configModel) ? [configModel] : []);
|
|
133
133
|
innerModels.forEach((innerModel) => {
|
|
134
134
|
const mergedInnerModel = modelsMerge(innerModel);
|
|
135
|
-
|
|
135
|
+
issues.scope('items', () => walkItems(mergedInnerModel, pages.items));
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
138
|
function walkInput(model, input) {
|
|
@@ -144,8 +144,8 @@ export function checkUIExpectations(mergedModel, ui, errors) {
|
|
|
144
144
|
if (typeof leaf === 'string' && expectedOptionNames.has(leaf)) {
|
|
145
145
|
return;
|
|
146
146
|
}
|
|
147
|
-
|
|
148
|
-
checkPath(model, path,
|
|
147
|
+
issues.scope('path', () => {
|
|
148
|
+
checkPath(model, path, issues);
|
|
149
149
|
});
|
|
150
150
|
}
|
|
151
151
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { BuilderModelValidated, BuilderVariantsValidated, ValidationResult } from '../entities/index';
|
|
2
|
-
import {
|
|
1
|
+
import type { BuilderModelValidated, BuilderReferences, BuilderVariantsValidated, ValidationResult } from '../entities/index';
|
|
2
|
+
import { BuilderIssuesScope } from '../errors/index.js';
|
|
3
3
|
export type BuilderVariantsValidationOptions = {
|
|
4
4
|
readonly partial?: boolean;
|
|
5
5
|
};
|
|
6
6
|
export type BuilderVariantsValidationResult = ValidationResult<BuilderVariantsValidated>;
|
|
7
|
-
export declare function validateVariants(model: BuilderModelValidated, input: unknown, options?: BuilderVariantsValidationOptions,
|
|
7
|
+
export declare function validateVariants(model: BuilderModelValidated, input: unknown, options?: BuilderVariantsValidationOptions, references?: BuilderReferences, issues?: BuilderIssuesScope): BuilderVariantsValidationResult;
|
|
@@ -1,46 +1,46 @@
|
|
|
1
1
|
import { BuilderComponentConfigSerialisedSchema, detailValueSchema } from '../entities/index.js';
|
|
2
|
-
import {
|
|
2
|
+
import { BuilderIssuesScope, check } from '../errors/index.js';
|
|
3
3
|
import { BuilderVariantsSchema } from '../instance.js';
|
|
4
4
|
import { createVariants } from '../mappers/index.js';
|
|
5
5
|
import { validate } from './brand.js';
|
|
6
|
-
export function validateVariants(model, input, options = {},
|
|
6
|
+
export function validateVariants(model, input, options = {}, references = [], issues = new BuilderIssuesScope(input)) {
|
|
7
7
|
if (!check.is(BuilderVariantsSchema, input)) {
|
|
8
|
-
|
|
9
|
-
return [validate({}), errors.
|
|
8
|
+
issues.variantsInvalid();
|
|
9
|
+
return [validate({}), issues.errors, issues.warnings];
|
|
10
10
|
}
|
|
11
11
|
const variants = input;
|
|
12
|
-
const expected = createVariants(model);
|
|
12
|
+
const expected = createVariants(model, references);
|
|
13
13
|
if (Object.keys(expected).length === 0) {
|
|
14
|
-
|
|
15
|
-
return [validate({}), errors.
|
|
14
|
+
issues.modelEmptyComponents();
|
|
15
|
+
return [validate({}), issues.errors, issues.warnings];
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
issues.scope('variants', () => {
|
|
18
18
|
checkVariants();
|
|
19
19
|
checkComponents();
|
|
20
20
|
checkDetails();
|
|
21
21
|
function checkVariants() {
|
|
22
22
|
Object.entries(expected).forEach(([component, expectedVariants]) => {
|
|
23
23
|
const componentVariants = variants[component];
|
|
24
|
-
|
|
24
|
+
issues.scope(component, () => {
|
|
25
25
|
if (componentVariants == null) {
|
|
26
26
|
if (options.partial !== false) {
|
|
27
|
-
|
|
27
|
+
issues.variantsMissingComponent();
|
|
28
28
|
}
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
31
|
const expectedKeys = new Map(expectedVariants.map(({ instance }) => [sortedKey(instance), instance]));
|
|
32
32
|
const actualKeys = new Set(componentVariants.map(({ instance }) => sortedKey(instance)));
|
|
33
33
|
componentVariants.forEach((variant, index) => {
|
|
34
|
-
|
|
34
|
+
issues.scope(index, () => {
|
|
35
35
|
const { instance } = variant;
|
|
36
36
|
if (!expectedKeys.has(sortedKey(instance))) {
|
|
37
|
-
|
|
37
|
+
issues.variantsInvalidVariant();
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
});
|
|
41
41
|
Array.from(expectedKeys).forEach(([key, instance]) => {
|
|
42
42
|
if (!actualKeys.has(key)) {
|
|
43
|
-
|
|
43
|
+
issues.variantsMissingVariant(instance);
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
46
|
});
|
|
@@ -48,9 +48,9 @@ export function validateVariants(model, input, options = {}, errors = new Builde
|
|
|
48
48
|
}
|
|
49
49
|
function checkComponents() {
|
|
50
50
|
Object.keys(variants).forEach((component) => {
|
|
51
|
-
|
|
51
|
+
issues.scope(component, () => {
|
|
52
52
|
if (expected[component] == null) {
|
|
53
|
-
|
|
53
|
+
issues.variantsUnexpectedComponent();
|
|
54
54
|
}
|
|
55
55
|
});
|
|
56
56
|
});
|
|
@@ -58,32 +58,33 @@ export function validateVariants(model, input, options = {}, errors = new Builde
|
|
|
58
58
|
function checkDetails() {
|
|
59
59
|
const componentByName = new Map(model.components.map((entry) => [entry.name, entry]));
|
|
60
60
|
Object.entries(variants).forEach(([component, componentVariants]) => {
|
|
61
|
-
|
|
61
|
+
issues.scope(component, () => {
|
|
62
62
|
const entry = componentByName.get(component);
|
|
63
63
|
if (entry == null) {
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
66
|
componentVariants.forEach(({ instance, details = {} }, index) => {
|
|
67
|
-
|
|
67
|
+
issues.scope(index, () => {
|
|
68
68
|
const resolved = variantDetails(entry, instance);
|
|
69
|
-
const
|
|
70
|
-
const expectedNames = new Set(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
69
|
+
const expected = resolved?.details ?? [];
|
|
70
|
+
const expectedNames = new Set(expected.map(({ name }) => name));
|
|
71
|
+
issues.scope('details', () => {
|
|
72
|
+
expected.forEach(({ name, kind, isOptional }) => {
|
|
73
|
+
issues.scope(name, () => {
|
|
74
|
+
const detail = details[name];
|
|
75
|
+
if (detail == null) {
|
|
76
|
+
issues.variantsMissingDetail();
|
|
76
77
|
return;
|
|
77
78
|
}
|
|
78
|
-
if (!check.is(detailValueSchema(
|
|
79
|
-
|
|
79
|
+
if (!check.is(detailValueSchema(kind, isOptional), detail.value)) {
|
|
80
|
+
issues.variantsInvalidDetail();
|
|
80
81
|
}
|
|
81
82
|
});
|
|
82
83
|
});
|
|
83
|
-
Object.keys(details).forEach((
|
|
84
|
-
if (!expectedNames.has(
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
Object.keys(details).forEach((name) => {
|
|
85
|
+
if (!expectedNames.has(name)) {
|
|
86
|
+
issues.scope(name, () => {
|
|
87
|
+
issues.variantsUnexpectedDetail();
|
|
87
88
|
});
|
|
88
89
|
}
|
|
89
90
|
});
|
|
@@ -94,7 +95,7 @@ export function validateVariants(model, input, options = {}, errors = new Builde
|
|
|
94
95
|
});
|
|
95
96
|
}
|
|
96
97
|
});
|
|
97
|
-
return [validate(variants), errors.
|
|
98
|
+
return [validate(variants), issues.errors, issues.warnings];
|
|
98
99
|
}
|
|
99
100
|
function variantDetails(component, variantInstance) {
|
|
100
101
|
const { payload } = component;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builder-builder/builder",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.28",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=24"
|
|
@@ -24,6 +24,8 @@
|
|
|
24
24
|
],
|
|
25
25
|
"svelte": "./dist/public.js",
|
|
26
26
|
"types": "./dist/public.d.ts",
|
|
27
|
+
"unpkg": "./dist/components/index.min.js",
|
|
28
|
+
"jsdelivr": "./dist/components/index.min.js",
|
|
27
29
|
"publishConfig": {
|
|
28
30
|
"access": "public"
|
|
29
31
|
},
|
|
@@ -34,7 +36,7 @@
|
|
|
34
36
|
"build": "NODE_ENV=production vite build",
|
|
35
37
|
"package": "svelte-kit sync && npm run package:lib && npm run package:components",
|
|
36
38
|
"package:lib": "svelte-package --input src/lib/builder",
|
|
37
|
-
"package:components": "vite build --mode components && rm -f dist/components/*.svelte",
|
|
39
|
+
"package:components": "NODE_ENV=production vite build --mode components && rm -f dist/components/*.svelte",
|
|
38
40
|
"preview": "vite preview",
|
|
39
41
|
"prepare": "svelte-kit sync && npm run messages || echo ''",
|
|
40
42
|
"prepublishOnly": "npm run test && npm run package",
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import type { BuilderPrimitive } from '../../primitive';
|
|
2
|
-
import type { BuilderTags } from '../tags';
|
|
3
|
-
import * as v from 'valibot';
|
|
4
|
-
export declare const BuilderComponentFieldValueTypeSchema: v.PicklistSchema<["string", "boolean", "number"], undefined>;
|
|
5
|
-
export type BuilderComponentFieldValueType = v.InferOutput<typeof BuilderComponentFieldValueTypeSchema>;
|
|
6
|
-
export declare class BuilderComponentField<const Name extends string = string, const ValueSchema extends v.GenericSchema<BuilderPrimitive> = v.GenericSchema<BuilderPrimitive>> {
|
|
7
|
-
#private;
|
|
8
|
-
readonly value: v.InferOutput<ValueSchema>;
|
|
9
|
-
readonly type: "component-field";
|
|
10
|
-
readonly name: Name;
|
|
11
|
-
readonly valueType: BuilderComponentFieldValueType;
|
|
12
|
-
readonly valueSchema: ValueSchema;
|
|
13
|
-
readonly isOptional: boolean;
|
|
14
|
-
readonly tags?: BuilderTags;
|
|
15
|
-
constructor(name: Name, valueType: BuilderComponentFieldValueType, optional?: boolean, tags?: BuilderTags);
|
|
16
|
-
optional(): BuilderComponentField<Name, v.NullableSchema<ValueSchema, undefined>>;
|
|
17
|
-
tag(...tags: Array<string>): BuilderComponentField<Name, ValueSchema>;
|
|
18
|
-
}
|
|
19
|
-
export declare function detailString<const Name extends string>(name: Name): BuilderComponentField<Name, v.StringSchema<undefined>>;
|
|
20
|
-
export declare function detailNumber<const Name extends string>(name: Name): BuilderComponentField<Name, v.NumberSchema<undefined>>;
|
|
21
|
-
export declare function detailBoolean<const Name extends string>(name: Name): BuilderComponentField<Name, v.BooleanSchema<undefined>>;
|
|
22
|
-
export declare const BuilderComponentFieldSchema: v.InstanceSchema<typeof BuilderComponentField, undefined>;
|
|
23
|
-
export declare const BuilderComponentFieldsSchema: v.SchemaWithPipe<readonly [v.ArraySchema<v.InstanceSchema<typeof BuilderComponentField, undefined>, undefined>, v.ReadonlyAction<BuilderComponentField<string, v.GenericSchema<string | number | boolean | null>>[]>]>;
|
|
24
|
-
export type BuilderComponentFields = v.InferOutput<typeof BuilderComponentFieldsSchema>;
|
|
25
|
-
export declare const BuilderComponentFieldSerialisedSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
26
|
-
readonly type: v.LiteralSchema<"component-field", undefined>;
|
|
27
|
-
readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
28
|
-
readonly valueType: v.PicklistSchema<["string", "boolean", "number"], undefined>;
|
|
29
|
-
readonly isOptional: v.BooleanSchema<undefined>;
|
|
30
|
-
readonly tags: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>, undefined>, v.ReadonlyAction<string[]>]>, undefined>;
|
|
31
|
-
}, undefined>, v.ReadonlyAction<{
|
|
32
|
-
type: "component-field";
|
|
33
|
-
name: string;
|
|
34
|
-
valueType: "string" | "number" | "boolean";
|
|
35
|
-
isOptional: boolean;
|
|
36
|
-
tags?: readonly string[] | undefined;
|
|
37
|
-
}>]>;
|
|
38
|
-
export type BuilderComponentFieldSerialised = v.InferOutput<typeof BuilderComponentFieldSerialisedSchema>;
|
|
39
|
-
export declare const BuilderComponentFieldsSerialisedSchema: v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
40
|
-
readonly type: v.LiteralSchema<"component-field", undefined>;
|
|
41
|
-
readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
42
|
-
readonly valueType: v.PicklistSchema<["string", "boolean", "number"], undefined>;
|
|
43
|
-
readonly isOptional: v.BooleanSchema<undefined>;
|
|
44
|
-
readonly tags: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>, undefined>, v.ReadonlyAction<string[]>]>, undefined>;
|
|
45
|
-
}, undefined>, v.ReadonlyAction<{
|
|
46
|
-
type: "component-field";
|
|
47
|
-
name: string;
|
|
48
|
-
valueType: "string" | "number" | "boolean";
|
|
49
|
-
isOptional: boolean;
|
|
50
|
-
tags?: readonly string[] | undefined;
|
|
51
|
-
}>]>, undefined>, v.ReadonlyAction<Readonly<{
|
|
52
|
-
type: "component-field";
|
|
53
|
-
name: string;
|
|
54
|
-
valueType: "string" | "number" | "boolean";
|
|
55
|
-
isOptional: boolean;
|
|
56
|
-
tags?: readonly string[] | undefined;
|
|
57
|
-
}>[]>]>;
|
|
58
|
-
export type BuilderComponentFieldsSerialised = v.InferOutput<typeof BuilderComponentFieldsSerialisedSchema>;
|
|
59
|
-
export declare function detailValueSchema(valueType: BuilderComponentFieldValueType, optional: boolean): v.GenericSchema<BuilderPrimitive>;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot';
|
|
2
|
-
import { BooleanSchema, NameSchema, NumberSchema, StringSchema } from '../../primitive.js';
|
|
3
|
-
import { serialisable } from '../serialisable.js';
|
|
4
|
-
import { BuilderTagsSchema } from '../tags.js';
|
|
5
|
-
export const BuilderComponentFieldValueTypeSchema = v.picklist(['string', 'boolean', 'number']);
|
|
6
|
-
export class BuilderComponentField {
|
|
7
|
-
type = 'component-field';
|
|
8
|
-
name;
|
|
9
|
-
valueType;
|
|
10
|
-
valueSchema;
|
|
11
|
-
isOptional;
|
|
12
|
-
tags;
|
|
13
|
-
constructor(name, valueType, optional = false, tags) {
|
|
14
|
-
this.name = name;
|
|
15
|
-
this.valueType = valueType;
|
|
16
|
-
this.valueSchema = detailValueSchema(valueType, optional);
|
|
17
|
-
this.isOptional = optional;
|
|
18
|
-
this.tags = tags;
|
|
19
|
-
}
|
|
20
|
-
#next(patch) {
|
|
21
|
-
return new BuilderComponentField(this.name, this.valueType, patch.optional ?? this.isOptional, patch.tags ?? this.tags);
|
|
22
|
-
}
|
|
23
|
-
optional() {
|
|
24
|
-
return this.#next({ optional: true });
|
|
25
|
-
}
|
|
26
|
-
tag(...tags) {
|
|
27
|
-
return this.#next({ tags });
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export function detailString(name) {
|
|
31
|
-
return new BuilderComponentField(name, 'string');
|
|
32
|
-
}
|
|
33
|
-
export function detailNumber(name) {
|
|
34
|
-
return new BuilderComponentField(name, 'number');
|
|
35
|
-
}
|
|
36
|
-
export function detailBoolean(name) {
|
|
37
|
-
return new BuilderComponentField(name, 'boolean');
|
|
38
|
-
}
|
|
39
|
-
export const BuilderComponentFieldSchema = v.instance(BuilderComponentField);
|
|
40
|
-
export const BuilderComponentFieldsSchema = v.pipe(v.array(BuilderComponentFieldSchema), v.readonly());
|
|
41
|
-
export const BuilderComponentFieldSerialisedSchema = serialisable(v.object({
|
|
42
|
-
type: v.literal('component-field'),
|
|
43
|
-
name: NameSchema,
|
|
44
|
-
valueType: BuilderComponentFieldValueTypeSchema,
|
|
45
|
-
isOptional: BooleanSchema,
|
|
46
|
-
tags: v.optional(BuilderTagsSchema)
|
|
47
|
-
}));
|
|
48
|
-
export const BuilderComponentFieldsSerialisedSchema = v.pipe(v.array(BuilderComponentFieldSerialisedSchema), v.readonly());
|
|
49
|
-
export function detailValueSchema(valueType, optional) {
|
|
50
|
-
const baseSchema = valueType === 'string' ? StringSchema : valueType === 'boolean' ? BooleanSchema : NumberSchema;
|
|
51
|
-
return optional ? v.nullable(baseSchema) : baseSchema;
|
|
52
|
-
}
|