@builder-builder/builder 0.0.28 → 0.0.29
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 +5 -6
- package/dist/client/schema.d.ts +49 -29
- package/dist/components/BuilderOption.svelte.d.ts +12 -12
- package/dist/components/BuilderOptionValueBoolean.svelte.d.ts +20 -0
- package/dist/components/BuilderOptionValueNumber.svelte.d.ts +21 -0
- package/dist/components/BuilderOptionValueSelect.svelte.d.ts +21 -0
- package/dist/components/BuilderOptionValueString.svelte.d.ts +21 -0
- package/dist/components/index.d.ts +8 -8
- package/dist/components/index.js +2479 -2435
- package/dist/components/index.min.js +3 -3
- package/dist/entities/collection/collection.d.ts +162 -372
- package/dist/entities/collection/collection.js +7 -4
- package/dist/entities/collection/{when.d.ts → condition.d.ts} +3 -4
- package/dist/entities/collection/condition.js +2 -0
- package/dist/entities/collection/config.d.ts +52 -70
- package/dist/entities/collection/index.d.ts +4 -4
- package/dist/entities/collection/index.js +2 -2
- package/dist/entities/component/component.d.ts +11 -23
- package/dist/entities/component/component.js +4 -4
- package/dist/entities/component/{when.d.ts → condition.d.ts} +3 -4
- package/dist/entities/component/{when.js → condition.js} +3 -9
- package/dist/entities/component/index.d.ts +4 -4
- package/dist/entities/component/index.js +2 -2
- package/dist/entities/{when.d.ts → condition.d.ts} +21 -34
- package/dist/entities/{when.js → condition.js} +20 -25
- package/dist/entities/expectation.d.ts +135 -3
- package/dist/entities/expectation.js +6 -2
- package/dist/entities/index.d.ts +8 -8
- package/dist/entities/index.js +4 -4
- package/dist/entities/kind.d.ts +1 -1
- package/dist/entities/kind.js +4 -5
- package/dist/entities/model/bind.d.ts +5 -5
- package/dist/entities/model/methods.d.ts +18 -27
- package/dist/entities/model/methods.js +4 -22
- package/dist/entities/model/model.d.ts +3 -1
- package/dist/entities/model/model.js +25 -27
- package/dist/entities/option/condition.d.ts +9 -0
- package/dist/entities/option/condition.js +2 -0
- package/dist/entities/option/config.d.ts +44 -69
- package/dist/entities/option/config.js +6 -6
- package/dist/entities/option/expectation.d.ts +6 -1
- package/dist/entities/option/expectation.js +2 -2
- package/dist/entities/option/index.d.ts +8 -8
- package/dist/entities/option/index.js +4 -4
- package/dist/entities/option/option.d.ts +171 -202
- package/dist/entities/option/option.js +4 -4
- package/dist/entities/option/select.d.ts +16 -43
- package/dist/entities/option/select.js +8 -31
- package/dist/entities/option/value.d.ts +73 -0
- package/dist/entities/option/value.js +99 -0
- package/dist/entities/references.d.ts +104 -64
- package/dist/entities/serialise.d.ts +147 -80
- package/dist/entities/serialise.js +26 -21
- package/dist/entities/ui/input.d.ts +1 -1
- package/dist/entities/validated.d.ts +1 -1
- package/dist/errors/errors.d.ts +8 -3
- package/dist/errors/errors.js +5 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/mappers/dependencies.js +4 -3
- package/dist/mappers/resolve.js +23 -22
- package/dist/mappers/variants/option-graph.js +1 -1
- package/dist/public.d.ts +17 -17
- package/dist/public.js +17 -9
- package/dist/validate/expectations.js +21 -3
- package/dist/validate/model.js +8 -11
- package/dist/validate/resolve.js +14 -18
- package/package.json +1 -1
- package/dist/components/BuilderOptionSelect.svelte.d.ts +0 -21
- package/dist/components/BuilderOptionToggleBoolean.svelte.d.ts +0 -20
- package/dist/components/BuilderOptionToggleNumber.svelte.d.ts +0 -21
- package/dist/components/BuilderOptionToggleString.svelte.d.ts +0 -21
- package/dist/entities/collection/when.js +0 -2
- package/dist/entities/option/toggle.d.ts +0 -45
- package/dist/entities/option/toggle.js +0 -71
- package/dist/entities/option/when.d.ts +0 -10
- package/dist/entities/option/when.js +0 -2
package/dist/mappers/resolve.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import * as v from 'valibot';
|
|
2
|
-
import { BuilderCollectionConfigSerialisedSchema,
|
|
2
|
+
import { BuilderCollectionConfigSerialisedSchema, BuilderCollectionConditionSerialisedSchema, BuilderComponentConfigSerialisedSchema, BuilderComponentConditionSerialisedSchema, BuilderOptionConfigSerialisedSchema, BuilderOptionConditionSerialisedSchema, BuilderPathsSchema, modelsMerge, conditionBranches } from '../entities/index.js';
|
|
3
3
|
import { check } from '../errors/index.js';
|
|
4
4
|
import { BuilderInstanceSchema, BuilderInstancesSchema } from '../instance.js';
|
|
5
5
|
import { BuilderPrimitiveSchema, NameSchema, NumberSchema } from '../primitive.js';
|
|
6
6
|
import { BuilderRefSerialisedSchema, paramable } from '../references.js';
|
|
7
7
|
export function resolveOption(option, model, instance, references = []) {
|
|
8
|
-
return resolveEntryInstance(option, BuilderOptionConfigSerialisedSchema,
|
|
8
|
+
return resolveEntryInstance(option, BuilderOptionConfigSerialisedSchema, BuilderOptionConditionSerialisedSchema, model, instance, references);
|
|
9
9
|
}
|
|
10
10
|
export function resolveOptions(option, references = []) {
|
|
11
|
-
return resolveEntryExhaustive(option, BuilderOptionConfigSerialisedSchema,
|
|
11
|
+
return resolveEntryExhaustive(option, BuilderOptionConfigSerialisedSchema, BuilderOptionConditionSerialisedSchema, references);
|
|
12
12
|
}
|
|
13
13
|
export function resolveComponent(component, model, instance, references = []) {
|
|
14
|
-
return resolveEntryInstance(component, BuilderComponentConfigSerialisedSchema,
|
|
14
|
+
return resolveEntryInstance(component, BuilderComponentConfigSerialisedSchema, BuilderComponentConditionSerialisedSchema, model, instance, references);
|
|
15
15
|
}
|
|
16
16
|
export function resolveComponents(component, references = []) {
|
|
17
|
-
return resolveEntryExhaustive(component, BuilderComponentConfigSerialisedSchema,
|
|
17
|
+
return resolveEntryExhaustive(component, BuilderComponentConfigSerialisedSchema, BuilderComponentConditionSerialisedSchema, references);
|
|
18
18
|
}
|
|
19
19
|
export function resolveCollection(collection, model, instance, references = []) {
|
|
20
|
-
return resolveEntryInstance(collection, BuilderCollectionConfigSerialisedSchema,
|
|
20
|
+
return resolveEntryInstance(collection, BuilderCollectionConfigSerialisedSchema, BuilderCollectionConditionSerialisedSchema, model, instance, references);
|
|
21
21
|
}
|
|
22
22
|
export function resolveCollections(collection, references = []) {
|
|
23
|
-
return resolveEntryExhaustive(collection, BuilderCollectionConfigSerialisedSchema,
|
|
23
|
+
return resolveEntryExhaustive(collection, BuilderCollectionConfigSerialisedSchema, BuilderCollectionConditionSerialisedSchema, references);
|
|
24
24
|
}
|
|
25
25
|
export function resolveReference(value, references, schema = v.unknown()) {
|
|
26
26
|
let resolved = value;
|
|
@@ -72,28 +72,29 @@ export function resolveItems(model, instance, pairs, references = []) {
|
|
|
72
72
|
}
|
|
73
73
|
return resolveItems(resolved.model, item, rest, references);
|
|
74
74
|
}
|
|
75
|
-
function resolveEntryInstance(entry, schema,
|
|
76
|
-
const payload = resolveReference(entry.payload, references, paramable(v.union([schema,
|
|
75
|
+
function resolveEntryInstance(entry, schema, conditionSchema, model, instance, references) {
|
|
76
|
+
const payload = resolveReference(entry.payload, references, paramable(v.union([schema, conditionSchema])));
|
|
77
|
+
if (entry.paths != null) {
|
|
78
|
+
check.assert(BuilderPathsSchema, entry.paths);
|
|
79
|
+
if (!entry.paths.every((path) => Boolean(resolvePath(model, instance, path, references)?.value))) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
77
83
|
if (check.is(schema, payload)) {
|
|
78
84
|
return payload;
|
|
79
85
|
}
|
|
80
|
-
check.assert(BuilderPathsSchema, entry.paths);
|
|
81
86
|
const config = payload;
|
|
82
|
-
if (!entry.paths.every((path) => Boolean(resolvePath(model, instance, path, references)?.value))) {
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
87
|
switch (config.type) {
|
|
86
|
-
case 'enable': {
|
|
87
|
-
return config.payload;
|
|
88
|
-
}
|
|
89
88
|
case 'match': {
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
const value = resolvePath(model, instance, config.matchPath, references)?.value;
|
|
90
|
+
if (value == null) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
return config.selectMap[`${value}`] ?? null;
|
|
93
94
|
}
|
|
94
95
|
case 'unless': {
|
|
95
96
|
const value = resolvePath(model, instance, config.unlessPath, references)?.value;
|
|
96
|
-
if (
|
|
97
|
+
if (value == null) {
|
|
97
98
|
return null;
|
|
98
99
|
}
|
|
99
100
|
check.assert(BuilderPrimitiveSchema, value);
|
|
@@ -104,6 +105,6 @@ function resolveEntryInstance(entry, schema, whenSchema, model, instance, refere
|
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
|
-
function resolveEntryExhaustive(entry, schema,
|
|
108
|
-
return
|
|
108
|
+
function resolveEntryExhaustive(entry, schema, conditionSchema, references) {
|
|
109
|
+
return conditionBranches(resolveReference(entry.payload, references, paramable(v.union([schema, conditionSchema]))), schema);
|
|
109
110
|
}
|
|
@@ -69,7 +69,7 @@ export class BuilderOptionGraph {
|
|
|
69
69
|
}, { keys: new Set([...first.keys, first.name]), instances: first.instances });
|
|
70
70
|
}
|
|
71
71
|
#optionValues(name, values) {
|
|
72
|
-
if (values.
|
|
72
|
+
if (values.kind === 'select') {
|
|
73
73
|
return [...values.options];
|
|
74
74
|
}
|
|
75
75
|
if (values.kind === 'boolean') {
|
package/dist/public.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { BB, BBOptions, BuilderEntityValidators } from './bb';
|
|
2
|
-
export type { Builder, BuilderBindings, BuilderBindingsSerialised, BuilderCollection, BuilderCollectionConfig, BuilderCollectionConfigSerialised, BuilderCollections, BuilderCollectionSerialised, BuilderCollectionsSerialised,
|
|
2
|
+
export type { Builder, BuilderBindings, BuilderBindingsSerialised, BuilderCollection, BuilderCollectionConfig, BuilderCollectionConfigSerialised, BuilderCollections, BuilderCollectionSerialised, BuilderCollectionsSerialised, BuilderCollectionCondition, BuilderCollectionConditionSerialised, BuilderComponent, BuilderComponentConfig, BuilderComponentConfigSerialised, BuilderComponentDetail, BuilderComponentDetailKind, BuilderComponentDetails, BuilderComponentDetailSerialised, BuilderComponentDetailsSerialised, BuilderComponents, BuilderComponentSerialised, BuilderComponentsSerialised, BuilderComponentCondition, BuilderComponentConditionSerialised, BuilderDescription, BuilderDescriptionItem, BuilderEntityKind, BuilderEntitySerialised, BuilderExpectation, BuilderExpectationKind, BuilderExpectations, BuilderExpectationSerialised, BuilderExpectationsSerialised, BuilderInstanceOf, BuilderInstanceValidated, BuilderMatchConfig, BuilderMatchSelectMap, BuilderModel, BuilderModels, BuilderModelSerialised, BuilderModelValidated, BuilderOption, BuilderOptionConfig, BuilderOptionConfigSerialised, BuilderOptions, BuilderOptionSerialised, BuilderOptionsSerialised, BuilderOptionCondition, BuilderOptionConditionSerialised, BuilderPath, BuilderPaths, BuilderPricing, BuilderPricingExpression, BuilderPricingLookupKey, BuilderPricingReduce, BuilderPricingSerialised, BuilderReference, BuilderReferences, BuilderSelectConfig, BuilderSerialised, BuilderTags, BuilderValueConfig, BuilderValueConfigSerialised, BuilderValueKind, BuilderValueOptionLabels, BuilderValueOptions, BuilderUI, BuilderUIDescribe, BuilderUIDescribeSerialised, BuilderUIInput, BuilderUIInputMetadata, BuilderUIInputMetadataSerialised, BuilderUIInputs, BuilderUIInputSerialised, BuilderUIInputsSerialised, BuilderUIItem, BuilderUIItems, BuilderUIItemsSerialised, BuilderUIPage, BuilderUIPages, BuilderUIPageSerialised, BuilderUIPagesSerialised, BuilderUIs, BuilderUISerialised, BuilderUIsSerialised, BuilderUIValidated, BuilderUnlessConfig, BuilderValidated, BuilderVariantsValidated, BuilderCondition, BuilderConditionConfig, BuilderConditionSerialised } from './entities/index';
|
|
3
3
|
export type { BuilderEnvironment } from './environment';
|
|
4
4
|
export type { BuilderIssue, BuilderIssueLocation, BuilderIssues } from './errors/index';
|
|
5
5
|
export type { BuilderIssueKind } from './errors/index.js';
|
|
@@ -9,29 +9,29 @@ export type { BuilderPrimitive, BuilderPrimitives } from './primitive';
|
|
|
9
9
|
export type { BuilderParameter, BuilderParameterSerialised, BuilderRef, Paramable, ParamableSerialised } from './references';
|
|
10
10
|
export type { BuilderInstanceValidationResult, BuilderModelValidationResult, BuilderPricingValidationResult, BuilderUIValidationResult, BuilderValidationResult, BuilderVariantsValidationOptions, BuilderVariantsValidationResult } from './validate/index';
|
|
11
11
|
export { bb } from './bb.js';
|
|
12
|
-
export { builder,
|
|
12
|
+
export { builder, input, match, model, pricing, serialise, unless } from './entities/index.js';
|
|
13
13
|
export { BuilderException } from './errors/index.js';
|
|
14
14
|
export { ordinal } from './mappers/index.js';
|
|
15
15
|
export { parameter, ref } from './references.js';
|
|
16
|
-
import { collectionConfig, collectionExpectation, componentConfig, componentExpectation, optionExpectation, uis } from './entities/index.js';
|
|
17
|
-
export declare const collection: typeof collectionConfig
|
|
18
|
-
|
|
19
|
-
match: <const MatchPayload extends import("./references").Paramable<import("./public").BuilderCollectionConfig<import("./references").Paramable<import("./entities/model").BuilderModelGeneric>, import("./references").Paramable<number>, import("./references").Paramable<number>>>, const MatchPath extends import("./references").Paramable<import("./public").BuilderPath>, const SelectMap extends import("./references").Paramable<import("./public").BuilderMatchSelectMap<import("./references").Paramable<import("./public").BuilderCollectionConfig<import("./references").Paramable<import("./entities/model").BuilderModelGeneric>, import("./references").Paramable<number>, import("./references").Paramable<number>>>>>>(matchPath: MatchPath, selectMap: SelectMap) => import("./public").BuilderMatchConfig<MatchPayload, MatchPath, SelectMap>;
|
|
20
|
-
unless: <const Values extends import("./references").Paramable<import("./public").BuilderCollectionConfig<import("./references").Paramable<import("./entities/model").BuilderModelGeneric>, import("./references").Paramable<number>, import("./references").Paramable<number>>>, const UnlessPath extends import("./references").Paramable<import("./public").BuilderPath>>(unlessPath: UnlessPath, disabledValues: import("./primitive").BuilderPrimitivesNonEmpty, values: Values) => import("./public").BuilderUnlessConfig<Values, UnlessPath>;
|
|
21
|
-
};
|
|
22
|
-
export declare const component: typeof componentConfig & {
|
|
23
|
-
enable: <const Payload extends import("./references").Paramable<import("./public").BuilderComponentConfig>>(payload?: Payload) => import("./public").BuilderEnableConfig<Payload>;
|
|
24
|
-
match: <const Payload extends import("./references").Paramable<import("./public").BuilderComponentConfig>, const MatchPath extends import("./references").Paramable<import("./public").BuilderPath>, const SelectMap extends import("./references").Paramable<import("./public").BuilderMatchSelectMap<import("./references").Paramable<import("./public").BuilderComponentConfig>>>>(matchPath: MatchPath, selectMap: SelectMap) => import("./public").BuilderMatchConfig<Payload, MatchPath, SelectMap>;
|
|
25
|
-
unless: <const UnlessPath extends import("./references").Paramable<import("./public").BuilderPath>, const Payload extends import("./references").Paramable<import("./public").BuilderComponentConfig>>(unlessPath: UnlessPath, disabledValues: import("./primitive").BuilderPrimitivesNonEmpty, payload?: Payload) => import("./public").BuilderUnlessConfig<Payload, UnlessPath>;
|
|
26
|
-
};
|
|
16
|
+
import { collectionConfig, collectionExpectation, componentConfig, componentExpectation, detailBoolean, detailImage, detailNumber, detailPrice, detailString, optionExpectation, valueBoolean, valueNumber, valueSelect, valueString, uis } from './entities/index.js';
|
|
17
|
+
export declare const collection: typeof collectionConfig;
|
|
18
|
+
export declare const component: typeof componentConfig;
|
|
27
19
|
export declare const has: {
|
|
28
20
|
collection: typeof collectionExpectation;
|
|
29
21
|
component: typeof componentExpectation;
|
|
30
22
|
option: typeof optionExpectation;
|
|
31
23
|
};
|
|
32
|
-
export declare const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
export declare const detail: {
|
|
25
|
+
boolean: typeof detailBoolean;
|
|
26
|
+
image: typeof detailImage;
|
|
27
|
+
number: typeof detailNumber;
|
|
28
|
+
price: typeof detailPrice;
|
|
29
|
+
string: typeof detailString;
|
|
36
30
|
};
|
|
37
31
|
export declare const ui: typeof uis;
|
|
32
|
+
export declare const value: {
|
|
33
|
+
boolean: typeof valueBoolean;
|
|
34
|
+
number: typeof valueNumber;
|
|
35
|
+
select: typeof valueSelect;
|
|
36
|
+
string: typeof valueString;
|
|
37
|
+
};
|
package/dist/public.js
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
export { bb } from './bb.js';
|
|
2
|
-
export { builder,
|
|
2
|
+
export { builder, input, match, model, pricing, serialise, unless } from './entities/index.js';
|
|
3
3
|
export { BuilderException } from './errors/index.js';
|
|
4
4
|
export { ordinal } from './mappers/index.js';
|
|
5
5
|
export { parameter, ref } from './references.js';
|
|
6
|
-
import { collectionConfig, collectionExpectation,
|
|
7
|
-
export const collection =
|
|
8
|
-
|
|
9
|
-
});
|
|
10
|
-
export const component = Object.assign(componentConfig, {
|
|
11
|
-
...componentWhen
|
|
12
|
-
});
|
|
6
|
+
import { collectionConfig, collectionExpectation, componentConfig, componentExpectation, detailBoolean, detailImage, detailNumber, detailPrice, detailString, optionExpectation, valueBoolean, valueNumber, valueSelect, valueString, uis } from './entities/index.js';
|
|
7
|
+
export const collection = collectionConfig;
|
|
8
|
+
export const component = componentConfig;
|
|
13
9
|
export const has = {
|
|
14
10
|
collection: collectionExpectation,
|
|
15
11
|
component: componentExpectation,
|
|
16
12
|
option: optionExpectation
|
|
17
13
|
};
|
|
18
|
-
export const
|
|
14
|
+
export const detail = {
|
|
15
|
+
boolean: detailBoolean,
|
|
16
|
+
image: detailImage,
|
|
17
|
+
number: detailNumber,
|
|
18
|
+
price: detailPrice,
|
|
19
|
+
string: detailString
|
|
20
|
+
};
|
|
19
21
|
export const ui = uis;
|
|
22
|
+
export const value = {
|
|
23
|
+
boolean: valueBoolean,
|
|
24
|
+
number: valueNumber,
|
|
25
|
+
select: valueSelect,
|
|
26
|
+
string: valueString
|
|
27
|
+
};
|
|
@@ -1,10 +1,28 @@
|
|
|
1
|
+
import { BuilderOptionConfigSerialisedSchema } from '../entities/index.js';
|
|
2
|
+
import { check } from '../errors/index.js';
|
|
1
3
|
export function checkExpectations(model, expectations, issues) {
|
|
2
|
-
expectations.forEach(({ kind, name }, index) => {
|
|
4
|
+
expectations.forEach(({ kind, name, payload }, index) => {
|
|
3
5
|
issues.scope(index, () => {
|
|
4
|
-
|
|
6
|
+
const entry = model[`${kind}s`].find((candidate) => candidate.name === name);
|
|
7
|
+
if (entry == null) {
|
|
8
|
+
issues.modelUnmetExpectation();
|
|
5
9
|
return;
|
|
6
10
|
}
|
|
7
|
-
|
|
11
|
+
if (payload != null && !isExpectedOption(entry.payload, payload)) {
|
|
12
|
+
issues.modelInvalidExpectation();
|
|
13
|
+
}
|
|
8
14
|
});
|
|
9
15
|
});
|
|
10
16
|
}
|
|
17
|
+
function isExpectedOption(payload, expectation) {
|
|
18
|
+
if (!check.is(BuilderOptionConfigSerialisedSchema, payload)) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
if (expectation.kind === 'select') {
|
|
22
|
+
if (payload.kind !== 'select') {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return expectation.options.every((option) => payload.options.includes(option));
|
|
26
|
+
}
|
|
27
|
+
return payload.kind === expectation.kind;
|
|
28
|
+
}
|
package/dist/validate/model.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as v from 'valibot';
|
|
2
|
-
import { BuilderCollectionConfigSerialisedSchema, BuilderComponentConfigSerialisedSchema, BuilderModelSerialisedSchema, BuilderOptionConfigSerialisedSchema, BuilderPathsSchema,
|
|
2
|
+
import { BuilderCollectionConfigSerialisedSchema, BuilderComponentConfigSerialisedSchema, BuilderModelSerialisedSchema, BuilderOptionConfigSerialisedSchema, BuilderPathsSchema, BuilderConditionSerialisedSchema, conditionBranches, model, modelsMerge, serialise, validateCollectionConfig, validateComponentConfig, validateValue } from '../entities/index.js';
|
|
3
3
|
import { BuilderIssuesScope, check } from '../errors/index.js';
|
|
4
4
|
import { dependencies } from '../mappers/index.js';
|
|
5
5
|
import { isParamable } from '../references.js';
|
|
@@ -50,26 +50,23 @@ export function validateModelStructure(input, resolve, issues) {
|
|
|
50
50
|
const modelInput = resolved;
|
|
51
51
|
const childModels = issues.scope('models', () => modelInput.models.flatMap((part, partIndex) => issues.scope(partIndex, () => [walkStructure(part)])));
|
|
52
52
|
const options = issues.scope('options', () => walkEntries(modelInput.options, 'option', (resolved) => {
|
|
53
|
-
|
|
53
|
+
conditionBranches(resolved.payload, BuilderOptionConfigSerialisedSchema)
|
|
54
54
|
.filter((config) => !isParamable(config))
|
|
55
55
|
.forEach((config) => {
|
|
56
|
-
if (config.type === '
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
else if (config.type === 'toggle') {
|
|
60
|
-
validateToggle(config, [], issues);
|
|
56
|
+
if (config.type === 'value') {
|
|
57
|
+
validateValue(config, [], issues);
|
|
61
58
|
}
|
|
62
59
|
});
|
|
63
60
|
}));
|
|
64
61
|
const components = issues.scope('components', () => walkEntries(modelInput.components, 'component', (resolved) => {
|
|
65
|
-
|
|
62
|
+
conditionBranches(resolved.payload, BuilderComponentConfigSerialisedSchema)
|
|
66
63
|
.filter((config) => !isParamable(config))
|
|
67
64
|
.forEach((config) => {
|
|
68
65
|
validateComponentConfig(config, [], issues);
|
|
69
66
|
});
|
|
70
67
|
}));
|
|
71
68
|
const collections = issues.scope('collections', () => walkEntries(modelInput.collections, 'collection', (resolved) => {
|
|
72
|
-
|
|
69
|
+
conditionBranches(resolved.payload, BuilderCollectionConfigSerialisedSchema)
|
|
73
70
|
.filter((config) => !isParamable(config))
|
|
74
71
|
.forEach((config) => {
|
|
75
72
|
validateCollectionConfig(config, [], issues);
|
|
@@ -117,7 +114,7 @@ export function validateModelStructure(input, resolve, issues) {
|
|
|
117
114
|
const resolvedPaths = issues.scope('paths', () => resolve(entry.paths, BuilderPathsSchema));
|
|
118
115
|
paths = resolvedPaths ?? entry.paths;
|
|
119
116
|
}
|
|
120
|
-
const payloadSchema = v.union([payloadSchemaFor(kind),
|
|
117
|
+
const payloadSchema = v.union([payloadSchemaFor(kind), BuilderConditionSerialisedSchema]);
|
|
121
118
|
const payload = issues.scope('payload', () => resolve(entry.payload, payloadSchema));
|
|
122
119
|
const resolvedEntry = { ...entry, paths, payload: payload ?? entry.payload };
|
|
123
120
|
if (seenLocal.has(resolvedEntry.name)) {
|
|
@@ -159,7 +156,7 @@ export function validateModelStructure(input, resolve, issues) {
|
|
|
159
156
|
});
|
|
160
157
|
});
|
|
161
158
|
}
|
|
162
|
-
if (!check.is(
|
|
159
|
+
if (!check.is(BuilderConditionSerialisedSchema, payload)) {
|
|
163
160
|
return;
|
|
164
161
|
}
|
|
165
162
|
if (payload.type === 'match' && Array.isArray(payload.matchPath)) {
|
package/dist/validate/resolve.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as v from 'valibot';
|
|
2
|
-
import { BuilderCollectionConfigSerialisedSchema, BuilderModelSerialisedSchema, BuilderPathSchema,
|
|
2
|
+
import { BuilderCollectionConfigSerialisedSchema, BuilderModelSerialisedSchema, BuilderPathSchema, BuilderConditionSerialisedSchema } from '../entities/index.js';
|
|
3
3
|
import { check } from '../errors/index.js';
|
|
4
4
|
import { NumberSchema, StringSchema } from '../primitive.js';
|
|
5
5
|
import { BuilderParameterSerialisedSchema, BuilderRefSerialisedSchema } from '../references.js';
|
|
@@ -24,8 +24,8 @@ export function resolver(issues, references = [], bindings = {}) {
|
|
|
24
24
|
if (check.is(BuilderRefSerialisedSchema, value)) {
|
|
25
25
|
return resolveReference(value, schema);
|
|
26
26
|
}
|
|
27
|
-
if (check.is(
|
|
28
|
-
return
|
|
27
|
+
if (check.is(BuilderConditionSerialisedSchema, value)) {
|
|
28
|
+
return resolveCondition(value, schema);
|
|
29
29
|
}
|
|
30
30
|
if (check.is(BuilderCollectionConfigSerialisedSchema, value)) {
|
|
31
31
|
return resolveCollectionConfig(value);
|
|
@@ -61,25 +61,21 @@ export function resolver(issues, references = [], bindings = {}) {
|
|
|
61
61
|
}
|
|
62
62
|
return resolveReference(binding, schema);
|
|
63
63
|
}
|
|
64
|
-
function
|
|
65
|
-
if (
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
if (when.type === 'unless') {
|
|
70
|
-
const unlessPath = issues.scope('unlessPath', () => resolve(when.unlessPath, BuilderPathSchema));
|
|
71
|
-
const payload = issues.scope('payload', () => resolve(when.payload, payloadSchema));
|
|
64
|
+
function resolveCondition(condition, payloadSchema) {
|
|
65
|
+
if (condition.type === 'unless') {
|
|
66
|
+
const unlessPath = issues.scope('unlessPath', () => resolve(condition.unlessPath, BuilderPathSchema));
|
|
67
|
+
const payload = issues.scope('payload', () => resolve(condition.payload, payloadSchema));
|
|
72
68
|
return {
|
|
73
|
-
...
|
|
74
|
-
unlessPath: unlessPath ??
|
|
75
|
-
payload: payload ??
|
|
69
|
+
...condition,
|
|
70
|
+
unlessPath: unlessPath ?? condition.unlessPath,
|
|
71
|
+
payload: payload ?? condition.payload
|
|
76
72
|
};
|
|
77
73
|
}
|
|
78
|
-
const matchPath = issues.scope('matchPath', () => resolve(
|
|
74
|
+
const matchPath = issues.scope('matchPath', () => resolve(condition.matchPath, BuilderPathSchema));
|
|
79
75
|
const selectMapSchema = v.record(StringSchema, v.nullable(v.unknown()));
|
|
80
|
-
const map = issues.scope('selectMap', () => resolve(
|
|
76
|
+
const map = issues.scope('selectMap', () => resolve(condition.selectMap, selectMapSchema));
|
|
81
77
|
if (map == null) {
|
|
82
|
-
return { ...
|
|
78
|
+
return { ...condition, matchPath: matchPath ?? condition.matchPath };
|
|
83
79
|
}
|
|
84
80
|
const selectMap = issues.scope('selectMap', () => Object.entries(map).reduce((values, [key, entryValue]) => {
|
|
85
81
|
if (entryValue == null) {
|
|
@@ -88,7 +84,7 @@ export function resolver(issues, references = [], bindings = {}) {
|
|
|
88
84
|
const resolved = issues.scope(key, () => resolve(entryValue, payloadSchema));
|
|
89
85
|
return { ...values, [key]: resolved ?? entryValue };
|
|
90
86
|
}, {}));
|
|
91
|
-
return { ...
|
|
87
|
+
return { ...condition, matchPath: matchPath ?? condition.matchPath, selectMap };
|
|
92
88
|
}
|
|
93
89
|
function resolveCollectionConfig(config) {
|
|
94
90
|
const model = issues.scope('model', () => {
|
package/package.json
CHANGED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
import type { BuilderRenderOption } from '../index.js';
|
|
3
|
-
export type BuilderBuilderOptionSelectProps = {
|
|
4
|
-
readonly option: BuilderRenderOption;
|
|
5
|
-
readonly placeholder?: string;
|
|
6
|
-
readonly id?: string;
|
|
7
|
-
};
|
|
8
|
-
export type BuilderBuilderOptionSelectUpdateEvent = CustomEvent<string | null>;
|
|
9
|
-
declare const __propDef: {
|
|
10
|
-
props: Record<string, never>;
|
|
11
|
-
events: {
|
|
12
|
-
[evt: string]: CustomEvent<any>;
|
|
13
|
-
};
|
|
14
|
-
slots: {};
|
|
15
|
-
};
|
|
16
|
-
export type BuilderOptionSelectProps = typeof __propDef.props;
|
|
17
|
-
export type BuilderOptionSelectEvents = typeof __propDef.events;
|
|
18
|
-
export type BuilderOptionSelectSlots = typeof __propDef.slots;
|
|
19
|
-
export default class BuilderOptionSelect extends SvelteComponentTyped<BuilderOptionSelectProps, BuilderOptionSelectEvents, BuilderOptionSelectSlots> {
|
|
20
|
-
}
|
|
21
|
-
export {};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
import type { BuilderRenderOption } from '../index.js';
|
|
3
|
-
export type BuilderBuilderOptionToggleBooleanProps = {
|
|
4
|
-
readonly option: BuilderRenderOption;
|
|
5
|
-
readonly id?: string;
|
|
6
|
-
};
|
|
7
|
-
export type BuilderBuilderOptionToggleBooleanUpdateEvent = CustomEvent<boolean>;
|
|
8
|
-
declare const __propDef: {
|
|
9
|
-
props: Record<string, never>;
|
|
10
|
-
events: {
|
|
11
|
-
[evt: string]: CustomEvent<any>;
|
|
12
|
-
};
|
|
13
|
-
slots: {};
|
|
14
|
-
};
|
|
15
|
-
export type BuilderOptionToggleBooleanProps = typeof __propDef.props;
|
|
16
|
-
export type BuilderOptionToggleBooleanEvents = typeof __propDef.events;
|
|
17
|
-
export type BuilderOptionToggleBooleanSlots = typeof __propDef.slots;
|
|
18
|
-
export default class BuilderOptionToggleBoolean extends SvelteComponentTyped<BuilderOptionToggleBooleanProps, BuilderOptionToggleBooleanEvents, BuilderOptionToggleBooleanSlots> {
|
|
19
|
-
}
|
|
20
|
-
export {};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
import type { BuilderRenderOption } from '../index.js';
|
|
3
|
-
export type BuilderBuilderOptionToggleNumberProps = {
|
|
4
|
-
readonly option: BuilderRenderOption;
|
|
5
|
-
readonly placeholder?: string;
|
|
6
|
-
readonly id?: string;
|
|
7
|
-
};
|
|
8
|
-
export type BuilderBuilderOptionToggleNumberUpdateEvent = CustomEvent<number>;
|
|
9
|
-
declare const __propDef: {
|
|
10
|
-
props: Record<string, never>;
|
|
11
|
-
events: {
|
|
12
|
-
[evt: string]: CustomEvent<any>;
|
|
13
|
-
};
|
|
14
|
-
slots: {};
|
|
15
|
-
};
|
|
16
|
-
export type BuilderOptionToggleNumberProps = typeof __propDef.props;
|
|
17
|
-
export type BuilderOptionToggleNumberEvents = typeof __propDef.events;
|
|
18
|
-
export type BuilderOptionToggleNumberSlots = typeof __propDef.slots;
|
|
19
|
-
export default class BuilderOptionToggleNumber extends SvelteComponentTyped<BuilderOptionToggleNumberProps, BuilderOptionToggleNumberEvents, BuilderOptionToggleNumberSlots> {
|
|
20
|
-
}
|
|
21
|
-
export {};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
import type { BuilderRenderOption } from '../index.js';
|
|
3
|
-
export type BuilderBuilderOptionToggleStringProps = {
|
|
4
|
-
readonly option: BuilderRenderOption;
|
|
5
|
-
readonly placeholder?: string;
|
|
6
|
-
readonly id?: string;
|
|
7
|
-
};
|
|
8
|
-
export type BuilderBuilderOptionToggleStringUpdateEvent = CustomEvent<string>;
|
|
9
|
-
declare const __propDef: {
|
|
10
|
-
props: Record<string, never>;
|
|
11
|
-
events: {
|
|
12
|
-
[evt: string]: CustomEvent<any>;
|
|
13
|
-
};
|
|
14
|
-
slots: {};
|
|
15
|
-
};
|
|
16
|
-
export type BuilderOptionToggleStringProps = typeof __propDef.props;
|
|
17
|
-
export type BuilderOptionToggleStringEvents = typeof __propDef.events;
|
|
18
|
-
export type BuilderOptionToggleStringSlots = typeof __propDef.slots;
|
|
19
|
-
export default class BuilderOptionToggleString extends SvelteComponentTyped<BuilderOptionToggleStringProps, BuilderOptionToggleStringEvents, BuilderOptionToggleStringSlots> {
|
|
20
|
-
}
|
|
21
|
-
export {};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { BuilderPrimitive } from '../../primitive';
|
|
2
|
-
import type { BuilderTags } from '../tags';
|
|
3
|
-
import * as v from 'valibot';
|
|
4
|
-
export declare const BuilderToggleKindSchema: v.PicklistSchema<["string", "boolean", "number"], undefined>;
|
|
5
|
-
export type BuilderToggleKind = v.InferOutput<typeof BuilderToggleKindSchema>;
|
|
6
|
-
export declare class BuilderToggleConfig<const ValueSchema extends v.GenericSchema<BuilderPrimitive> = v.GenericSchema<BuilderPrimitive>> {
|
|
7
|
-
#private;
|
|
8
|
-
readonly value: v.InferOutput<ValueSchema>;
|
|
9
|
-
readonly type: "toggle";
|
|
10
|
-
readonly kind: BuilderToggleKind;
|
|
11
|
-
readonly valueSchema: ValueSchema;
|
|
12
|
-
readonly defaultValue: v.InferOutput<ValueSchema>;
|
|
13
|
-
readonly isOptional: boolean;
|
|
14
|
-
readonly tags?: BuilderTags;
|
|
15
|
-
constructor(kind: BuilderToggleKind, defaultValue: v.InferOutput<ValueSchema>, optional?: boolean, tags?: BuilderTags);
|
|
16
|
-
default(newDefault: v.InferOutput<ValueSchema>): BuilderToggleConfig<ValueSchema>;
|
|
17
|
-
optional(): BuilderToggleConfig<v.NullableSchema<ValueSchema, undefined>>;
|
|
18
|
-
tag(...tags: Array<string>): BuilderToggleConfig<ValueSchema>;
|
|
19
|
-
}
|
|
20
|
-
export declare function toggleString(): BuilderToggleConfig<v.StringSchema<undefined>>;
|
|
21
|
-
export declare function toggleBoolean(): BuilderToggleConfig<v.BooleanSchema<undefined>>;
|
|
22
|
-
export declare function toggleNumber(): BuilderToggleConfig<v.NumberSchema<undefined>>;
|
|
23
|
-
export declare const BuilderToggleConfigSchema: v.InstanceSchema<typeof BuilderToggleConfig, undefined>;
|
|
24
|
-
export declare const BuilderToggleConfigSerialisedSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
25
|
-
readonly type: v.LiteralSchema<"toggle", undefined>;
|
|
26
|
-
readonly kind: v.PicklistSchema<["string", "boolean", "number"], undefined>;
|
|
27
|
-
readonly defaultValue: v.NullableSchema<v.UnionSchema<[v.BooleanSchema<undefined>, v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, undefined>;
|
|
28
|
-
readonly isOptional: v.BooleanSchema<undefined>;
|
|
29
|
-
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>;
|
|
30
|
-
}, undefined>, v.ReadonlyAction<{
|
|
31
|
-
type: "toggle";
|
|
32
|
-
kind: "string" | "number" | "boolean";
|
|
33
|
-
defaultValue: string | number | boolean | null;
|
|
34
|
-
isOptional: boolean;
|
|
35
|
-
tags?: readonly string[] | undefined;
|
|
36
|
-
}>]>;
|
|
37
|
-
export type BuilderToggleConfigSerialised = v.InferOutput<typeof BuilderToggleConfigSerialisedSchema>;
|
|
38
|
-
export declare function toggleValueSchema(kind: BuilderToggleKind, optional: boolean): v.GenericSchema;
|
|
39
|
-
export declare const validateToggle: (input: unknown, references?: import("..").BuilderReferences, issues?: import("../../errors/errors").BuilderIssuesScope) => import("..").ValidationResult<{
|
|
40
|
-
readonly type: "toggle";
|
|
41
|
-
readonly kind: "string" | "number" | "boolean";
|
|
42
|
-
readonly defaultValue: string | number | boolean | null;
|
|
43
|
-
readonly isOptional: boolean;
|
|
44
|
-
readonly tags?: readonly string[] | undefined;
|
|
45
|
-
}>;
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot';
|
|
2
|
-
import { check } from '../../errors/index.js';
|
|
3
|
-
import { BooleanSchema, NumberSchema, StringSchema } from '../../primitive.js';
|
|
4
|
-
import { createEntityValidator } from '../kind.js';
|
|
5
|
-
import { serialisable } from '../serialisable.js';
|
|
6
|
-
import { BuilderTagsSchema } from '../tags.js';
|
|
7
|
-
export const BuilderToggleKindSchema = v.picklist(['string', 'boolean', 'number']);
|
|
8
|
-
export class BuilderToggleConfig {
|
|
9
|
-
type = 'toggle';
|
|
10
|
-
kind;
|
|
11
|
-
valueSchema;
|
|
12
|
-
defaultValue;
|
|
13
|
-
isOptional;
|
|
14
|
-
tags;
|
|
15
|
-
constructor(kind, defaultValue, optional, tags) {
|
|
16
|
-
this.kind = kind;
|
|
17
|
-
this.valueSchema = toggleValueSchema(kind, optional || false);
|
|
18
|
-
this.defaultValue = defaultValue;
|
|
19
|
-
this.isOptional = optional || false;
|
|
20
|
-
this.tags = tags;
|
|
21
|
-
}
|
|
22
|
-
#next(patch) {
|
|
23
|
-
return new BuilderToggleConfig(this.kind, 'defaultValue' in patch
|
|
24
|
-
? patch.defaultValue
|
|
25
|
-
: this.defaultValue, patch.optional ?? this.isOptional, patch.tags ?? this.tags);
|
|
26
|
-
}
|
|
27
|
-
default(newDefault) {
|
|
28
|
-
return this.#next({ defaultValue: newDefault });
|
|
29
|
-
}
|
|
30
|
-
optional() {
|
|
31
|
-
return this.#next({ optional: true });
|
|
32
|
-
}
|
|
33
|
-
tag(...tags) {
|
|
34
|
-
return this.#next({ tags });
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
export function toggleString() {
|
|
38
|
-
return new BuilderToggleConfig('string', '');
|
|
39
|
-
}
|
|
40
|
-
export function toggleBoolean() {
|
|
41
|
-
return new BuilderToggleConfig('boolean', false);
|
|
42
|
-
}
|
|
43
|
-
export function toggleNumber() {
|
|
44
|
-
return new BuilderToggleConfig('number', 0);
|
|
45
|
-
}
|
|
46
|
-
export const BuilderToggleConfigSchema = v.instance(BuilderToggleConfig);
|
|
47
|
-
export const BuilderToggleConfigSerialisedSchema = serialisable(v.object({
|
|
48
|
-
type: v.literal('toggle'),
|
|
49
|
-
kind: BuilderToggleKindSchema,
|
|
50
|
-
defaultValue: v.nullable(v.union([BooleanSchema, StringSchema, NumberSchema])),
|
|
51
|
-
isOptional: BooleanSchema,
|
|
52
|
-
tags: v.optional(BuilderTagsSchema)
|
|
53
|
-
}));
|
|
54
|
-
export function toggleValueSchema(kind, optional) {
|
|
55
|
-
const kindSchemas = {
|
|
56
|
-
string: StringSchema,
|
|
57
|
-
boolean: BooleanSchema,
|
|
58
|
-
number: NumberSchema
|
|
59
|
-
};
|
|
60
|
-
const baseSchema = kindSchemas[kind];
|
|
61
|
-
return optional ? v.nullable(baseSchema) : baseSchema;
|
|
62
|
-
}
|
|
63
|
-
export const validateToggle = createEntityValidator('toggle', BuilderToggleConfigSerialisedSchema, (input, errors) => {
|
|
64
|
-
if (input.defaultValue == null) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
const valueSchema = toggleValueSchema(input.kind, input.isOptional);
|
|
68
|
-
if (!check.is(valueSchema, input.defaultValue)) {
|
|
69
|
-
errors.scope('defaultValue', () => errors.entityInvalidToggleDefault());
|
|
70
|
-
}
|
|
71
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Paramable } from '../../references';
|
|
2
|
-
import type { BuilderPath } from '../paths';
|
|
3
|
-
import type { BuilderWhen } from '../when';
|
|
4
|
-
import type { BuilderOptionConfig } from './config';
|
|
5
|
-
export type BuilderOptionWhen = BuilderWhen<Paramable<BuilderOptionConfig>, Paramable<BuilderPath>, Paramable<Record<string, Paramable<BuilderOptionConfig> | null>>, Paramable<BuilderPath>>;
|
|
6
|
-
export declare const optionWhen: {
|
|
7
|
-
enable: <const Values extends Paramable<import("./select").BuilderSelectConfig<readonly [string, ...string[]], import("valibot").GenericSchema<string | null>> | import("./toggle").BuilderToggleConfig<import("valibot").GenericSchema<string | number | boolean | null>>>>(values: Values) => import("..").BuilderEnableConfig<Values>;
|
|
8
|
-
match: <const MatchPayload extends Paramable<import("./select").BuilderSelectConfig<readonly [string, ...string[]], import("valibot").GenericSchema<string | null>> | import("./toggle").BuilderToggleConfig<import("valibot").GenericSchema<string | number | boolean | null>>>, const MatchPath extends Paramable<BuilderPath>, const SelectMap extends Paramable<import("..").BuilderMatchSelectMap<Paramable<import("./select").BuilderSelectConfig<readonly [string, ...string[]], import("valibot").GenericSchema<string | null>> | import("./toggle").BuilderToggleConfig<import("valibot").GenericSchema<string | number | boolean | null>>>>>>(matchPath: MatchPath, selectMap: SelectMap) => import("..").BuilderMatchConfig<MatchPayload, MatchPath, SelectMap>;
|
|
9
|
-
unless: <const Values extends Paramable<import("./select").BuilderSelectConfig<readonly [string, ...string[]], import("valibot").GenericSchema<string | null>> | import("./toggle").BuilderToggleConfig<import("valibot").GenericSchema<string | number | boolean | null>>>, const UnlessPath extends Paramable<BuilderPath>>(unlessPath: UnlessPath, disabledValues: import("../../primitive").BuilderPrimitivesNonEmpty, values: Values) => import("..").BuilderUnlessConfig<Values, UnlessPath>;
|
|
10
|
-
};
|