@builder-builder/builder 0.0.10 → 0.0.12
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.d.ts +28 -0
- package/dist/bb.js +49 -0
- package/dist/check.d.ts +1 -1
- package/dist/check.js +4 -2
- package/dist/entities/builder/bind.d.ts +4 -85
- package/dist/entities/builder/bind.js +1 -9
- package/dist/entities/builder/builder.d.ts +17 -509
- package/dist/entities/builder/builder.js +19 -79
- package/dist/entities/builder/factory.d.ts +7 -0
- package/dist/entities/builder/factory.js +4 -0
- package/dist/entities/builder/index.d.ts +3 -6
- package/dist/entities/builder/index.js +1 -2
- package/dist/entities/collection/collection.d.ts +69 -19
- package/dist/entities/collection/collection.js +7 -25
- package/dist/entities/collection/config.d.ts +38 -1095
- package/dist/entities/collection/config.js +8 -8
- package/dist/entities/collection/expectation.d.ts +8 -4
- package/dist/entities/collection/index.d.ts +2 -2
- package/dist/entities/collection/when.d.ts +5 -4
- package/dist/entities/component/component.d.ts +264 -293
- package/dist/entities/component/component.js +5 -5
- package/dist/entities/component/details.d.ts +32 -57
- package/dist/entities/component/details.js +8 -8
- package/dist/entities/component/expectation.d.ts +7 -4
- package/dist/entities/component/expectation.js +0 -3
- package/dist/entities/component/field.d.ts +50 -0
- package/dist/entities/component/field.js +41 -0
- package/dist/entities/component/index.d.ts +4 -2
- package/dist/entities/component/index.js +2 -1
- package/dist/entities/component/when.d.ts +1 -1
- package/dist/entities/component/when.js +2 -2
- package/dist/entities/entry.d.ts +4 -0
- package/dist/entities/expectation.d.ts +10 -22
- package/dist/entities/expectation.js +2 -7
- package/dist/entities/index.d.ts +20 -17
- package/dist/entities/index.js +9 -8
- package/dist/entities/kind.d.ts +8 -5
- package/dist/entities/kind.js +3 -4
- package/dist/entities/model/bind.d.ts +83 -0
- package/dist/entities/model/expectation.d.ts +16 -0
- package/dist/entities/model/index.d.ts +7 -0
- package/dist/entities/model/index.js +2 -0
- package/dist/entities/model/methods.d.ts +57 -0
- package/dist/entities/{builder → model}/methods.js +8 -8
- package/dist/entities/model/model.d.ts +39 -0
- package/dist/entities/model/model.js +73 -0
- package/dist/entities/model/models.d.ts +39 -0
- package/dist/entities/model/models.js +14 -0
- package/dist/entities/{builder → model}/state.d.ts +10 -10
- package/dist/entities/option/index.d.ts +1 -1
- package/dist/entities/option/index.js +1 -1
- package/dist/entities/option/option.d.ts +210 -209
- package/dist/entities/option/option.js +5 -5
- package/dist/entities/option/select.d.ts +2 -12
- package/dist/entities/option/select.js +6 -3
- package/dist/entities/option/toggle.d.ts +2 -9
- package/dist/entities/option/toggle.js +3 -3
- package/dist/entities/option/values.d.ts +3 -21
- package/dist/entities/option/values.js +8 -2
- package/dist/entities/option/when.d.ts +5 -4
- package/dist/entities/refs.d.ts +6 -0
- package/dist/entities/refs.js +1 -0
- package/dist/entities/serialise.d.ts +388 -2919
- package/dist/entities/serialise.js +116 -17
- package/dist/entities/ui/describe.d.ts +22 -31
- package/dist/entities/ui/describe.js +1 -1
- package/dist/entities/ui/index.d.ts +2 -5
- package/dist/entities/ui/index.js +1 -2
- package/dist/entities/ui/page.d.ts +22 -31
- package/dist/entities/ui/page.js +1 -1
- package/dist/entities/ui/pages.d.ts +11 -8
- package/dist/entities/ui/pages.js +1 -1
- package/dist/entities/ui/ui.d.ts +22 -1194
- package/dist/entities/ui/ui.js +16 -28
- package/dist/entities/ui/uis.d.ts +5 -15
- package/dist/entities/ui/uis.js +12 -18
- package/dist/entities/validated.d.ts +35 -0
- package/dist/entities/validated.js +1 -0
- package/dist/entities/when.d.ts +62 -54
- package/dist/entities/when.js +1 -0
- package/dist/environment.d.ts +5 -0
- package/dist/environment.js +2 -0
- package/dist/exception.d.ts +8 -3
- package/dist/exception.js +3 -0
- package/dist/index.d.ts +21 -28
- package/dist/index.js +5 -13
- package/dist/instance.d.ts +56 -0
- package/dist/instance.js +10 -0
- package/dist/mappers/index.d.ts +7 -7
- package/dist/mappers/index.js +5 -4
- package/dist/mappers/instance.d.ts +3 -0
- package/dist/mappers/instance.js +36 -0
- package/dist/mappers/order.d.ts +6 -0
- package/dist/mappers/order.js +22 -0
- package/dist/mappers/render/pages.d.ts +5 -4
- package/dist/mappers/render/render.d.ts +2 -3
- package/dist/mappers/render/render.js +97 -78
- package/dist/mappers/resolve.d.ts +5 -9
- package/dist/mappers/resolve.js +25 -33
- package/dist/mappers/variants/index.d.ts +1 -0
- package/dist/mappers/variants/index.js +1 -0
- package/dist/mappers/variants/option-graph.d.ts +19 -0
- package/dist/mappers/{models → variants}/option-graph.js +33 -22
- package/dist/mappers/variants/variants.d.ts +3 -0
- package/dist/mappers/variants/variants.js +57 -0
- package/dist/private.d.ts +4 -0
- package/dist/private.js +4 -0
- package/dist/references.d.ts +13 -48
- package/dist/references.js +6 -14
- package/dist/serialisable.d.ts +1 -9
- package/dist/serialisable.js +2 -3
- package/dist/validate/brand.d.ts +14 -0
- package/dist/validate/brand.js +17 -0
- package/dist/validate/builder.d.ts +4 -0
- package/dist/validate/builder.js +27 -0
- package/dist/validate/expectations.d.ts +10 -0
- package/dist/validate/expectations.js +12 -0
- package/dist/validate/index.d.ts +18 -0
- package/dist/validate/index.js +9 -0
- package/dist/validate/instance.d.ts +19 -0
- package/dist/validate/instance.js +46 -0
- package/dist/validate/model.d.ts +36 -0
- package/dist/validate/model.js +220 -0
- package/dist/validate/resolve.d.ts +16 -0
- package/dist/validate/resolve.js +91 -0
- package/dist/validate/result.d.ts +8 -0
- package/dist/validate/result.js +4 -0
- package/dist/validate/ui.d.ts +8 -0
- package/dist/validate/ui.js +77 -0
- package/dist/validate/variants.d.ts +59 -0
- package/dist/validate/variants.js +102 -0
- package/package.json +5 -4
- package/dist/entities/bind.d.ts +0 -4
- package/dist/entities/bind.js +0 -44
- package/dist/entities/builder/builders.d.ts +0 -35
- package/dist/entities/builder/builders.js +0 -19
- package/dist/entities/builder/expectation.d.ts +0 -12
- package/dist/entities/builder/methods.d.ts +0 -58
- package/dist/entities/builder/validate.d.ts +0 -3
- package/dist/entities/builder/validate.js +0 -108
- package/dist/entities/errors.d.ts +0 -21
- package/dist/entities/ui/bind.d.ts +0 -10
- package/dist/entities/ui/bind.js +0 -9
- package/dist/entities/ui/validate.d.ts +0 -8
- package/dist/entities/ui/validate.js +0 -21
- package/dist/entities/validate.d.ts +0 -28
- package/dist/mappers/assert/builder.d.ts +0 -2
- package/dist/mappers/assert/builder.js +0 -46
- package/dist/mappers/assert/expectation.d.ts +0 -2
- package/dist/mappers/assert/expectation.js +0 -23
- package/dist/mappers/assert/index.d.ts +0 -6
- package/dist/mappers/assert/index.js +0 -4
- package/dist/mappers/assert/model.d.ts +0 -13
- package/dist/mappers/assert/model.js +0 -47
- package/dist/mappers/assert/models.d.ts +0 -33
- package/dist/mappers/assert/models.js +0 -74
- package/dist/mappers/assert/ui.d.ts +0 -2
- package/dist/mappers/assert/ui.js +0 -22
- package/dist/mappers/instance/index.d.ts +0 -1
- package/dist/mappers/instance/index.js +0 -1
- package/dist/mappers/instance/instance.d.ts +0 -4
- package/dist/mappers/instance/instance.js +0 -33
- package/dist/mappers/models/component-graph.d.ts +0 -9
- package/dist/mappers/models/component-graph.js +0 -51
- package/dist/mappers/models/graph.d.ts +0 -12
- package/dist/mappers/models/graph.js +0 -17
- package/dist/mappers/models/index.d.ts +0 -1
- package/dist/mappers/models/index.js +0 -1
- package/dist/mappers/models/models.d.ts +0 -3
- package/dist/mappers/models/models.js +0 -37
- package/dist/mappers/models/option-graph.d.ts +0 -9
- package/dist/mappers/order/index.d.ts +0 -2
- package/dist/mappers/order/index.js +0 -1
- package/dist/mappers/order/order.d.ts +0 -14
- package/dist/mappers/order/order.js +0 -31
- package/dist/mappers/refs.d.ts +0 -12
- package/dist/mappers/refs.js +0 -36
- package/dist/model.d.ts +0 -35
- package/dist/model.js +0 -9
- package/dist/walker/index.d.ts +0 -2
- package/dist/walker/index.js +0 -1
- package/dist/walker/walkable.d.ts +0 -4
- package/dist/walker/walkable.js +0 -4
- package/dist/walker/walker.d.ts +0 -26
- package/dist/walker/walker.js +0 -115
- package/dist/walker/walkers.d.ts +0 -9
- package/dist/walker/walkers.js +0 -55
- /package/dist/entities/{builder/expectation.js → entry.js} +0 -0
- /package/dist/entities/{builder/state.js → model/bind.js} +0 -0
- /package/dist/entities/{errors.js → model/expectation.js} +0 -0
- /package/dist/entities/{validate.js → model/state.js} +0 -0
package/dist/entities/bind.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot';
|
|
2
|
-
import { isParameter, isRef } from '../references.js';
|
|
3
|
-
import { createWalkerBinding } from '../walker/index.js';
|
|
4
|
-
import { BuilderSchema, BuilderSerialisedSchema } from './builder/index.js';
|
|
5
|
-
import { BuilderUISchema, BuilderUISerialisedSchema } from './ui/index.js';
|
|
6
|
-
export function bind(instance, bindings, construct) {
|
|
7
|
-
const bindingEntries = Object.entries(bindings);
|
|
8
|
-
const refBindings = bindingEntries.filter(([, value]) => isRef(value));
|
|
9
|
-
const partBindingNames = new Set(bindingEntries
|
|
10
|
-
.filter(([, value]) => v.is(BuilderSchema, value) || v.is(BuilderUISchema, value))
|
|
11
|
-
.map(([name]) => name));
|
|
12
|
-
const walk = createWalkerBinding({
|
|
13
|
-
lookupBinding: (parameter) => {
|
|
14
|
-
const binding = bindings[parameter.name];
|
|
15
|
-
if (binding == null || isRef(binding)) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
return binding;
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
const walked = walk(schemaOf(instance), instance);
|
|
22
|
-
const nonRefValues = bindingEntries
|
|
23
|
-
.filter(([, value]) => !isRef(value))
|
|
24
|
-
.map(([, value]) => value);
|
|
25
|
-
const walkedNonRefValues = nonRefValues.map((value) => walkBindable(value, walk));
|
|
26
|
-
const newReferences = refBindings.map(([name, refValue]) => ({
|
|
27
|
-
parameter: name,
|
|
28
|
-
id: refValue.id
|
|
29
|
-
}));
|
|
30
|
-
const remainingParameters = walked.parameters.filter((parameter) => !isParameter(parameter) || !partBindingNames.has(parameter.name));
|
|
31
|
-
return construct(walked, walkedNonRefValues, remainingParameters, newReferences);
|
|
32
|
-
}
|
|
33
|
-
function schemaOf(instance) {
|
|
34
|
-
return v.is(BuilderUISchema, instance) ? BuilderUISerialisedSchema : BuilderSerialisedSchema;
|
|
35
|
-
}
|
|
36
|
-
function walkBindable(value, walk) {
|
|
37
|
-
if (v.is(BuilderUISchema, value)) {
|
|
38
|
-
return walk(BuilderUISerialisedSchema, value);
|
|
39
|
-
}
|
|
40
|
-
if (v.is(BuilderSchema, value)) {
|
|
41
|
-
return walk(BuilderSerialisedSchema, value);
|
|
42
|
-
}
|
|
43
|
-
return value;
|
|
44
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { BuilderParameter } from '../../references';
|
|
2
|
-
import type { BuilderGeneric, BuilderParts, BuilderStateOf } from './builder';
|
|
3
|
-
import type { BuilderState, BuilderStateEmpty } from './state';
|
|
4
|
-
import { Builder } from './builder.js';
|
|
5
|
-
export declare function builders<const Parts extends BuilderParts>(...builders: Parts): Builder<BuilderBuildersMerge<Parts>>;
|
|
6
|
-
export declare function mergeBuilderParts(parts: ReadonlyArray<unknown>): {
|
|
7
|
-
parameters: BuilderParameter<string>[];
|
|
8
|
-
options: import("..").BuilderOption<string, import("../..").Paramable<import("..").BuilderOptionPayload>, import("../..").Paramable<readonly (readonly (string | number)[])[]>>[];
|
|
9
|
-
components: import("..").BuilderComponent<string, import("../..").Paramable<import("..").BuilderComponentPayload>, import("../..").Paramable<readonly (readonly (string | number)[])[]>>[];
|
|
10
|
-
collections: import("..").BuilderCollection<string, import("../..").Paramable<import("..").BuilderCollectionPayload>, import("../..").Paramable<readonly (readonly (string | number)[])[]>>[];
|
|
11
|
-
expectations: import("..").BuilderExpectation<string, unknown, "option" | "component" | "collection" | "detail">[];
|
|
12
|
-
references: Readonly<{
|
|
13
|
-
parameter: string;
|
|
14
|
-
id: string;
|
|
15
|
-
}>[];
|
|
16
|
-
};
|
|
17
|
-
export type BuilderBuildersMerge<Parts extends BuilderParts> = Parts extends readonly [
|
|
18
|
-
infer Head,
|
|
19
|
-
...infer Tail extends BuilderParts
|
|
20
|
-
] ? Head extends BuilderGeneric ? BuilderStateMerge<BuilderStateOf<Head>, BuilderBuildersMerge<Tail>> : Head extends BuilderParameter ? BuilderStateAppendParameter<Head, BuilderBuildersMerge<Tail>> : BuilderBuildersMerge<Tail> : BuilderStateEmpty;
|
|
21
|
-
type BuilderStateMerge<Left extends BuilderState, Right extends BuilderState> = {
|
|
22
|
-
model: Left['model'] & Right['model'];
|
|
23
|
-
parameters: readonly [...Left['parameters'], ...Right['parameters']];
|
|
24
|
-
options: [...Left['options'], ...Right['options']];
|
|
25
|
-
components: [...Left['components'], ...Right['components']];
|
|
26
|
-
collections: [...Left['collections'], ...Right['collections']];
|
|
27
|
-
};
|
|
28
|
-
type BuilderStateAppendParameter<Parameter extends BuilderParameter, State extends BuilderState> = {
|
|
29
|
-
model: State['model'];
|
|
30
|
-
parameters: readonly [Parameter, ...State['parameters']];
|
|
31
|
-
options: State['options'];
|
|
32
|
-
components: State['components'];
|
|
33
|
-
collections: State['collections'];
|
|
34
|
-
};
|
|
35
|
-
export {};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot';
|
|
2
|
-
import { isParameter } from '../../references.js';
|
|
3
|
-
import { Builder, BuilderSchema } from './builder.js';
|
|
4
|
-
export function builders(...builders) {
|
|
5
|
-
const parameters = builders.filter((payload) => isParameter(payload));
|
|
6
|
-
const merged = mergeBuilderParts(builders);
|
|
7
|
-
return new Builder([...parameters, ...merged.parameters], merged.options, merged.components, merged.collections, merged.expectations, merged.references);
|
|
8
|
-
}
|
|
9
|
-
export function mergeBuilderParts(parts) {
|
|
10
|
-
const instances = parts.filter((part) => v.is(BuilderSchema, part));
|
|
11
|
-
return {
|
|
12
|
-
parameters: instances.flatMap((builder) => [...builder.parameters]),
|
|
13
|
-
options: instances.flatMap((builder) => [...builder.options]),
|
|
14
|
-
components: instances.flatMap((builder) => [...builder.components]),
|
|
15
|
-
collections: instances.flatMap((builder) => [...builder.collections]),
|
|
16
|
-
expectations: instances.flatMap((builder) => [...builder.expectations]),
|
|
17
|
-
references: instances.flatMap((builder) => [...builder.references])
|
|
18
|
-
};
|
|
19
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Prettify } from '../../prettify';
|
|
2
|
-
import type { CollectionsAsserted } from '../collection/index';
|
|
3
|
-
import type { ComponentAsserted } from '../component/index';
|
|
4
|
-
import type { BuilderExpectation, BuilderExpectations } from '../expectation';
|
|
5
|
-
import type { BuilderState, BuilderStateAppend } from './state';
|
|
6
|
-
export type BuilderStateAsserted<State extends BuilderState, Expectations extends BuilderExpectations> = BuilderStateAppend<State, {
|
|
7
|
-
model: ModelAsserted<State, Expectations>;
|
|
8
|
-
components: ComponentAsserted<State, Expectations>;
|
|
9
|
-
collections: CollectionsAsserted<State, Expectations>;
|
|
10
|
-
}>;
|
|
11
|
-
export type ModelExpected<Expectations extends BuilderExpectations> = Expectations extends readonly [infer Head, ...infer Tail extends BuilderExpectations] ? (Head extends BuilderExpectation<infer Name, infer Value, 'option'> ? Record<Name, Value> : Head extends BuilderExpectation<infer Name, any, 'collection'> ? Record<Name, ReadonlyArray<unknown>> : unknown) & ModelExpected<Tail> : unknown;
|
|
12
|
-
export type ModelAsserted<State extends BuilderState, Expectations extends BuilderExpectations, Current extends State['model'] = State['model'], Asserted extends ModelExpected<Expectations> = ModelExpected<Expectations>> = unknown extends Current ? Prettify<Asserted> : Prettify<Current & Asserted>;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type { BuilderPaths } from '../../paths';
|
|
2
|
-
import type { BuilderParameter, Paramable } from '../../references';
|
|
3
|
-
import type { WhenConfigPayload } from '../when';
|
|
4
|
-
import type { BuilderCollectionConfig, BuilderCollectionWhen } from '../collection/index';
|
|
5
|
-
import type { BuilderComponentDetails, BuilderComponentWhen } from '../component/index';
|
|
6
|
-
import type { BuilderOptionValues, BuilderOptionWhen } from '../option/index';
|
|
7
|
-
import type { BuilderValidPaths, BuilderWhenConstrained, WhenNullability } from '../when';
|
|
8
|
-
import type { Builder } from './builder';
|
|
9
|
-
import type { BuilderState, BuilderStateAppend } from './state';
|
|
10
|
-
import { BuilderCollection } from '../collection/index.js';
|
|
11
|
-
import { BuilderComponent } from '../component/index.js';
|
|
12
|
-
import { BuilderOption } from '../option/index.js';
|
|
13
|
-
export type BuilderOptionMethod<State extends BuilderState> = {
|
|
14
|
-
<const Name extends string, const Payload extends Paramable<BuilderOptionValues>>(name: Name, payload: Payload): OptionStateAppend<State, BuilderOption<Name, Payload>>;
|
|
15
|
-
when: <const GatePaths extends Paramable<BuilderValidPaths<State>>, const Name extends string, const Payload extends Paramable<BuilderOptionWhen>>(gatePaths: GatePaths, name: Name, payload: Payload & BuilderWhenConstrained<State, Payload>) => OptionStateAppend<State, OptionWhenResolver<Name, Payload>, OptionModelOf<OptionWhenResolver<Name, Payload>> | WhenNullability<State, GatePaths, Payload>>;
|
|
16
|
-
};
|
|
17
|
-
export type BuilderComponentMethod<State extends BuilderState> = {
|
|
18
|
-
<const Name extends string, const Payload extends Paramable<BuilderComponentDetails>>(name: Name, payload?: Payload): ComponentStateAppend<State, BuilderComponent<Name, Payload>>;
|
|
19
|
-
when: <const GatePaths extends Paramable<BuilderValidPaths<State>>, const Name extends string, const Payload extends Paramable<BuilderComponentWhen>>(gatePaths: GatePaths, name: Name, payload?: Payload & BuilderWhenConstrained<State, Payload>) => ComponentStateAppend<State, ComponentWhenResolver<Name, Payload>>;
|
|
20
|
-
};
|
|
21
|
-
export type BuilderCollectionMethod<State extends BuilderState> = {
|
|
22
|
-
<const Name extends string, const Payload extends Paramable<BuilderCollectionConfig>>(name: Name, payload: Payload): CollectionStateAppend<State, BuilderCollection<Name, Payload>>;
|
|
23
|
-
when: <const GatePaths extends Paramable<BuilderValidPaths<State>>, const Name extends string, const Payload extends Paramable<BuilderCollectionWhen>>(gatePaths: GatePaths, name: Name, payload: Payload & BuilderWhenConstrained<State, Payload>) => CollectionStateAppend<State, CollectionWhenResolver<Name, Payload>, CollectionModelOf<CollectionWhenResolver<Name, Payload>> | WhenNullability<State, GatePaths, Payload>>;
|
|
24
|
-
};
|
|
25
|
-
type OptionWhenResolver<Name extends string, Payload extends Paramable<BuilderOptionWhen>> = Payload extends BuilderOptionWhen ? BuilderOption<Name, WhenConfigPayload<Payload, BuilderOptionValues>> : BuilderOption<Name, BuilderParameter>;
|
|
26
|
-
type ComponentWhenResolver<Name extends string, Payload extends Paramable<BuilderComponentWhen>> = Payload extends BuilderComponentWhen ? BuilderComponent<Name, WhenConfigPayload<Payload, BuilderComponentDetails>> : BuilderComponent<Name, BuilderParameter>;
|
|
27
|
-
type CollectionWhenResolver<Name extends string, Payload extends Paramable<BuilderCollectionWhen>> = Payload extends BuilderCollectionWhen ? BuilderCollection<Name, WhenConfigPayload<Payload, BuilderCollectionConfig>> : BuilderCollection<Name, BuilderParameter>;
|
|
28
|
-
type OptionStateAppend<State extends BuilderState, Option extends BuilderOption, ModelType = OptionModelOf<Option>> = Builder<BuilderStateAppend<State, {
|
|
29
|
-
model: State['model'] & {
|
|
30
|
-
[K in Option['name']]: ModelType;
|
|
31
|
-
};
|
|
32
|
-
options: [...State['options'], Option];
|
|
33
|
-
}>>;
|
|
34
|
-
type ComponentStateAppend<State extends BuilderState, Component extends BuilderComponent> = Builder<BuilderStateAppend<State, {
|
|
35
|
-
components: [...State['components'], Component];
|
|
36
|
-
}>>;
|
|
37
|
-
type CollectionStateAppend<State extends BuilderState, Collection extends BuilderCollection, ModelType = CollectionModelOf<Collection>> = Builder<BuilderStateAppend<State, {
|
|
38
|
-
model: State['model'] & Record<Collection['name'], ModelType>;
|
|
39
|
-
collections: [...State['collections'], Collection];
|
|
40
|
-
}>>;
|
|
41
|
-
type OptionModelOf<Option extends BuilderOption> = Option['payload'] extends BuilderParameter ? string : Option['payload'] extends {
|
|
42
|
-
readonly value: infer Value;
|
|
43
|
-
} ? Value : never;
|
|
44
|
-
type CollectionModelOf<Collection extends BuilderCollection> = [Collection['payload']] extends [
|
|
45
|
-
never
|
|
46
|
-
] ? null : Collection['payload'] extends BuilderCollectionConfig ? Collection['payload']['builder'] extends Builder<infer State extends BuilderState> ? CollectionShape<Collection, State['model']> : ReadonlyArray<unknown> : ReadonlyArray<unknown>;
|
|
47
|
-
type CollectionShape<Collection extends BuilderCollection, Item> = Collection['payload'] extends BuilderCollectionConfig ? Collection['payload']['min'] extends number ? Collection['payload']['max'] extends number ? number extends Collection['payload']['min'] ? ReadonlyArray<Item> : number extends Collection['payload']['max'] ? ReadonlyArray<Item> : Collection['payload']['min'] extends Collection['payload']['max'] ? CollectionTuple<Item, Collection['payload']['min']> : ReadonlyArray<Item> : ReadonlyArray<Item> : ReadonlyArray<Item> : ReadonlyArray<Item>;
|
|
48
|
-
type CollectionTuple<Item, Length extends number, Result extends ReadonlyArray<Item> = []> = Result['length'] extends Length ? Result : CollectionTuple<Item, Length, [...Result, Item]>;
|
|
49
|
-
export declare function builderOptionMethod(): ((name: string, payload: Paramable<BuilderOptionValues>) => BuilderOption<string, Paramable<import("..").BuilderSelectType<readonly [string, ...string[]], import("valibot").GenericSchema<string | null>> | import("..").BuilderToggleType<import("valibot").GenericSchema<string | number | boolean | null>>>, Paramable<readonly (readonly (string | number)[])[]>>) & {
|
|
50
|
-
when(gatePaths: Paramable<BuilderPaths>, name: string, payload: Paramable<BuilderOptionWhen>): BuilderOption<string, Paramable<BuilderOptionWhen>, readonly (readonly (string | number)[])[] | BuilderParameter<string>>;
|
|
51
|
-
};
|
|
52
|
-
export declare function builderComponentMethod(): ((name: string, payload?: Paramable<BuilderComponentDetails>) => BuilderComponent<string, Paramable<BuilderComponentDetails<Paramable<readonly import("..").BuilderExpectation<string, unknown, "option" | "component" | "collection" | "detail">[]>>> | import("../when").BuilderEnableConfig<Paramable<BuilderComponentDetails<Paramable<readonly import("..").BuilderExpectation<string, unknown, "option" | "component" | "collection" | "detail">[]>>>>, Paramable<readonly (readonly (string | number)[])[]>>) & {
|
|
53
|
-
when(gatePaths: Paramable<BuilderPaths>, name: string, payload?: Paramable<BuilderComponentWhen>): BuilderComponent<string, Paramable<BuilderComponentWhen>, readonly (readonly (string | number)[])[] | BuilderParameter<string>>;
|
|
54
|
-
};
|
|
55
|
-
export declare function builderCollectionMethod(): ((name: string, payload: Paramable<BuilderCollectionConfig>) => BuilderCollection<string, Paramable<BuilderCollectionConfig<Paramable<import("./builder").BuilderGeneric>, Paramable<number>, Paramable<number>>>, Paramable<readonly (readonly (string | number)[])[]>>) & {
|
|
56
|
-
when(gatePaths: Paramable<BuilderPaths>, name: string, payload: Paramable<BuilderCollectionWhen>): BuilderCollection<string, Paramable<BuilderCollectionWhen>, readonly (readonly (string | number)[])[] | BuilderParameter<string>>;
|
|
57
|
-
};
|
|
58
|
-
export {};
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot';
|
|
2
|
-
import { BuilderException } from '../../exception.js';
|
|
3
|
-
import { isParameter } from '../../references.js';
|
|
4
|
-
import { BuilderCollectionConfigSchema } from '../collection/index.js';
|
|
5
|
-
import { BuilderWhenMatchSchema, BuilderWhenUnlessSchema } from '../when.js';
|
|
6
|
-
export function validateDuplicates(builder) {
|
|
7
|
-
const kinds = [
|
|
8
|
-
{ entryKind: 'option', entries: builder.options },
|
|
9
|
-
{ entryKind: 'component', entries: builder.components },
|
|
10
|
-
{ entryKind: 'collection', entries: builder.collections }
|
|
11
|
-
];
|
|
12
|
-
const errors = kinds.flatMap(({ entryKind, entries }) => {
|
|
13
|
-
const seen = new Set();
|
|
14
|
-
return entries.flatMap((entry) => {
|
|
15
|
-
if (seen.has(entry.name)) {
|
|
16
|
-
return [{ kind: 'duplicate-name', entryKind, name: entry.name }];
|
|
17
|
-
}
|
|
18
|
-
seen.add(entry.name);
|
|
19
|
-
return [];
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
if (errors.length > 0) {
|
|
23
|
-
throw new BuilderException(errors);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
export function validatePaths(builder) {
|
|
27
|
-
const errors = collectPathErrors(builder);
|
|
28
|
-
if (errors.length > 0) {
|
|
29
|
-
throw new BuilderException(errors);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
function collectPathErrors(builder) {
|
|
33
|
-
if (builder.expectations.length > 0) {
|
|
34
|
-
return [];
|
|
35
|
-
}
|
|
36
|
-
const allEntries = [...builder.options, ...builder.components, ...builder.collections];
|
|
37
|
-
return allEntries.flatMap((entry) => pathsForEntry(entry).flatMap((path) => collectEntryPathErrors(builder, entry.name, path)));
|
|
38
|
-
}
|
|
39
|
-
function pathsForEntry(entry) {
|
|
40
|
-
const gatePaths = entry.gatePaths != null && !isParameter(entry.gatePaths)
|
|
41
|
-
? entry.gatePaths
|
|
42
|
-
: [];
|
|
43
|
-
const configPaths = pathsFromWhen(entry.payload);
|
|
44
|
-
return [...gatePaths, ...configPaths];
|
|
45
|
-
}
|
|
46
|
-
function pathsFromWhen(payload) {
|
|
47
|
-
if (v.is(BuilderWhenMatchSchema, payload)) {
|
|
48
|
-
const matchPath = payload.matchPath;
|
|
49
|
-
return isParameter(matchPath) ? [] : [matchPath];
|
|
50
|
-
}
|
|
51
|
-
if (v.is(BuilderWhenUnlessSchema, payload)) {
|
|
52
|
-
const unlessPath = payload.unlessPath;
|
|
53
|
-
return isParameter(unlessPath) ? [] : [unlessPath];
|
|
54
|
-
}
|
|
55
|
-
return [];
|
|
56
|
-
}
|
|
57
|
-
function collectEntryPathErrors(builder, entryName, path) {
|
|
58
|
-
const collectionSegments = path.slice(0, -1);
|
|
59
|
-
const optionName = path.at(-1);
|
|
60
|
-
const reached = traverseCollections([builder], collectionSegments);
|
|
61
|
-
if (reached === null) {
|
|
62
|
-
return [{ kind: 'invalid-gate-path', name: entryName, path }];
|
|
63
|
-
}
|
|
64
|
-
const anyHasOption = reached.some((current) => current.options.some((option) => option.name === optionName));
|
|
65
|
-
return anyHasOption ? [] : [{ kind: 'invalid-gate-path', name: entryName, path }];
|
|
66
|
-
}
|
|
67
|
-
function traverseCollections(candidates, remaining) {
|
|
68
|
-
if (remaining.length === 0) {
|
|
69
|
-
return candidates;
|
|
70
|
-
}
|
|
71
|
-
const [collectionName, index, ...rest] = remaining;
|
|
72
|
-
if (!v.is(v.string(), collectionName) || !v.is(v.number(), index)) {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
const descents = candidates.map((current) => descendCollection(current, collectionName, index));
|
|
76
|
-
if (descents.some((descent) => descent === null)) {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
const nextCandidates = descents.flatMap((descent) => descent ?? []);
|
|
80
|
-
if (nextCandidates.length === 0) {
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
return traverseCollections(nextCandidates, rest);
|
|
84
|
-
}
|
|
85
|
-
function descendCollection(builder, collectionName, index) {
|
|
86
|
-
const collection = builder.collections.find((entry) => entry.name === collectionName);
|
|
87
|
-
if (!collection) {
|
|
88
|
-
return [];
|
|
89
|
-
}
|
|
90
|
-
const configs = possibleConfigs(collection.payload);
|
|
91
|
-
const withinBounds = configs.filter((config) => isParameter(config.max) || index < config.max);
|
|
92
|
-
if (withinBounds.length === 0 && configs.length > 0) {
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
return withinBounds.flatMap((config) => (isParameter(config.builder) ? [] : [config.builder]));
|
|
96
|
-
}
|
|
97
|
-
function possibleConfigs(payload) {
|
|
98
|
-
if (isParameter(payload)) {
|
|
99
|
-
return [];
|
|
100
|
-
}
|
|
101
|
-
if (v.is(BuilderCollectionConfigSchema, payload)) {
|
|
102
|
-
return [payload];
|
|
103
|
-
}
|
|
104
|
-
if (payload.type === 'match') {
|
|
105
|
-
return Object.values(payload.selectMap).flatMap((value) => v.is(BuilderCollectionConfigSchema, value) ? [value] : []);
|
|
106
|
-
}
|
|
107
|
-
return v.is(BuilderCollectionConfigSchema, payload.payload) ? [payload.payload] : [];
|
|
108
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { BuilderPath } from '../paths';
|
|
2
|
-
import type { BuilderExpectationKind } from './expectation';
|
|
3
|
-
export type BuilderErrorUnmetExpectation = {
|
|
4
|
-
readonly kind: 'unmet-expectation';
|
|
5
|
-
readonly expectationKind: BuilderExpectationKind;
|
|
6
|
-
readonly name: string;
|
|
7
|
-
};
|
|
8
|
-
export type BuilderErrorUnboundParameter = {
|
|
9
|
-
readonly kind: 'unbound-parameter';
|
|
10
|
-
readonly name: string;
|
|
11
|
-
};
|
|
12
|
-
export type BuilderErrorInvalidGatePath = {
|
|
13
|
-
readonly kind: 'invalid-gate-path';
|
|
14
|
-
readonly name: string;
|
|
15
|
-
readonly path: BuilderPath;
|
|
16
|
-
};
|
|
17
|
-
export type BuilderErrorDuplicateName = {
|
|
18
|
-
readonly kind: 'duplicate-name';
|
|
19
|
-
readonly entryKind: 'option' | 'component' | 'collection';
|
|
20
|
-
readonly name: string;
|
|
21
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { BuilderRef, Paramable } from '../../references';
|
|
2
|
-
import type { BuilderPaths } from '../../paths';
|
|
3
|
-
import type { BuilderBindings, BuilderGeneric, BuilderStateOf } from '../builder/index';
|
|
4
|
-
import type { BuilderUIItems } from './pages';
|
|
5
|
-
import type { BuilderUIGeneric } from './ui';
|
|
6
|
-
import { BuilderUI } from './ui.js';
|
|
7
|
-
type BuilderUIBindingValue = string | number | boolean | BuilderUIGeneric | BuilderUIItems | BuilderPaths | BuilderGeneric | BuilderRef;
|
|
8
|
-
export type BuilderUIBindings<BuilderType extends Paramable<BuilderGeneric> = BuilderGeneric> = BuilderType extends BuilderGeneric ? Record<string, BuilderUIBindingValue | BuilderBindings<BuilderStateOf<BuilderType>>[keyof BuilderBindings<BuilderStateOf<BuilderType>>]> : Record<string, BuilderUIBindingValue>;
|
|
9
|
-
export declare function bindUI<BuilderType extends Paramable<BuilderGeneric>>(ui: BuilderUI<BuilderType>, bindings: BuilderUIBindings<BuilderType>): BuilderUI<BuilderType>;
|
|
10
|
-
export {};
|
package/dist/entities/ui/bind.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { bind } from '../bind.js';
|
|
2
|
-
import { BuilderUI } from './ui.js';
|
|
3
|
-
import { flattenUIItems, mergeUIParts } from './uis.js';
|
|
4
|
-
export function bindUI(ui, bindings) {
|
|
5
|
-
return bind(ui, bindings, (walked, walkedNonRefValues, remainingParameters, newReferences) => {
|
|
6
|
-
const merged = mergeUIParts(walkedNonRefValues);
|
|
7
|
-
return new BuilderUI(walked.builder, [...remainingParameters, ...merged.parameters], flattenUIItems(walked.items), [...walked.expectations, ...merged.expectations], [...walked.references, ...newReferences, ...merged.references]);
|
|
8
|
-
});
|
|
9
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Paramable } from '../../references';
|
|
2
|
-
import type { BuilderGeneric } from '../builder/index';
|
|
3
|
-
import type { BuilderUIItems } from './pages';
|
|
4
|
-
export type BuilderErrorPagesUnknownCollection = {
|
|
5
|
-
readonly kind: 'pages-unknown-collection';
|
|
6
|
-
readonly name: string;
|
|
7
|
-
};
|
|
8
|
-
export declare function validatePagesCollections(builder: Paramable<BuilderGeneric>, items: Paramable<BuilderUIItems>): void;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { BuilderException } from '../../exception.js';
|
|
2
|
-
import { isParameter } from '../../references.js';
|
|
3
|
-
import { BuilderUIPages } from './pages.js';
|
|
4
|
-
export function validatePagesCollections(builder, items) {
|
|
5
|
-
if (isParameter(builder) || isParameter(items)) {
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
const errors = items.flatMap((item) => {
|
|
9
|
-
if (isParameter(item) || !(item instanceof BuilderUIPages)) {
|
|
10
|
-
return [];
|
|
11
|
-
}
|
|
12
|
-
const exists = builder.collections.some((entry) => entry.name === item.name);
|
|
13
|
-
if (exists) {
|
|
14
|
-
return [];
|
|
15
|
-
}
|
|
16
|
-
return [{ kind: 'pages-unknown-collection', name: item.name }];
|
|
17
|
-
});
|
|
18
|
-
if (errors.length > 0) {
|
|
19
|
-
throw new BuilderException(errors);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { BuilderExpectation } from './expectation';
|
|
2
|
-
import type { BuilderParameter } from '../references';
|
|
3
|
-
import type { Builder, BuilderGeneric } from './builder/index';
|
|
4
|
-
import type { BuilderCollection, BuilderCollectionConfig } from './collection/index';
|
|
5
|
-
import type { BuilderComponent, BuilderComponentDetails } from './component/index';
|
|
6
|
-
import type { BuilderOption, BuilderSelectType, BuilderToggleType } from './option/index';
|
|
7
|
-
import type { BuilderUI, BuilderUIDescribe, BuilderUIGeneric, BuilderUIItem, BuilderUIItems, BuilderUIPage, BuilderUIPages } from './ui/index';
|
|
8
|
-
export type Strip<T> = T extends BuilderParameter ? never : T extends BuilderSelectType | BuilderToggleType | BuilderExpectation ? T : T extends Builder<infer State> ? Builder<Strip<State>> : T extends BuilderOption<infer Name, infer Payload, infer GatePaths> ? StripEntry<BuilderOption<Name, Strip<Payload>, Strip<GatePaths>>, Payload, GatePaths> : T extends BuilderComponent<infer Name, infer Payload, infer GatePaths> ? StripEntry<BuilderComponent<Name, Strip<Payload>, Strip<GatePaths>>, Payload, GatePaths> : T extends BuilderCollection<infer Name, infer Payload, infer GatePaths> ? StripEntry<BuilderCollection<Name, Strip<Payload>, Strip<GatePaths>>, Payload, GatePaths> : T extends BuilderCollectionConfig<infer Inner, infer Min, infer Max> ? BuilderCollectionConfig<Strip<Inner>, Strip<Min>, Strip<Max>> : T extends BuilderComponentDetails<infer Expectations> ? BuilderComponentDetails<Strip<Expectations>> : T extends BuilderUI<infer Inner, infer Items> ? BuilderUI<Strip<Inner>, Strip<Items> & BuilderUIItems> : T extends BuilderUIPage<infer Label, infer Paths> ? BuilderUIPage<Strip<Label>, Strip<Paths>> : T extends BuilderUIDescribe<infer Label, infer Paths> ? BuilderUIDescribe<Strip<Label>, Strip<Paths>> : T extends BuilderUIPages<infer Name, infer Label, infer Items> ? BuilderUIPages<Name, Strip<Label>, Strip<Items>> : T extends ReadonlyArray<unknown> ? StripTuple<T> : T extends object ? {
|
|
9
|
-
readonly [Key in keyof T]: Strip<T[Key]>;
|
|
10
|
-
} : T;
|
|
11
|
-
type StripEntry<Narrowed, Payload, GatePaths> = [Strip<Payload>] extends [never] ? never : [Strip<GatePaths>] extends [never] ? never : Narrowed;
|
|
12
|
-
export type StripTuple<T extends ReadonlyArray<unknown>> = T extends readonly [
|
|
13
|
-
infer Head,
|
|
14
|
-
...infer Rest extends ReadonlyArray<unknown>
|
|
15
|
-
] ? [Strip<Head>] extends [never] ? StripTuple<Rest> : readonly [Strip<Head>, ...StripTuple<Rest>] : T extends readonly [] ? readonly [] : ReadonlyArray<Strip<T[number]>>;
|
|
16
|
-
export type BuilderValidated = Strip<BuilderGeneric>;
|
|
17
|
-
export type BuilderOptionValidated = Strip<BuilderOption>;
|
|
18
|
-
export type BuilderOptionsValidated = ReadonlyArray<BuilderOptionValidated>;
|
|
19
|
-
export type BuilderComponentValidated = Strip<BuilderComponent>;
|
|
20
|
-
export type BuilderComponentsValidated = ReadonlyArray<BuilderComponentValidated>;
|
|
21
|
-
export type BuilderComponentDetailsValidated = Strip<BuilderComponentDetails>;
|
|
22
|
-
export type BuilderCollectionValidated = Strip<BuilderCollection>;
|
|
23
|
-
export type BuilderCollectionsValidated = ReadonlyArray<BuilderCollectionValidated>;
|
|
24
|
-
export type BuilderCollectionConfigValidated = Strip<BuilderCollectionConfig>;
|
|
25
|
-
export type BuilderUIValidated = Strip<BuilderUIGeneric>;
|
|
26
|
-
export type BuilderUIItemValidated = Strip<BuilderUIItem>;
|
|
27
|
-
export type BuilderUIItemsValidated = Strip<BuilderUIItems>;
|
|
28
|
-
export {};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot';
|
|
2
|
-
import { BuilderCollectionConfigSchema, BuilderSerialisedSchema } from '../../entities/index.js';
|
|
3
|
-
import { BuilderException } from '../../exception.js';
|
|
4
|
-
import { isParameter } from '../../references.js';
|
|
5
|
-
import { createWalkerValidation } from '../../walker/index.js';
|
|
6
|
-
import { collectExpectationErrors } from './expectation.js';
|
|
7
|
-
export function assertBuilder(builder) {
|
|
8
|
-
const errors = collectBuilderErrors(builder);
|
|
9
|
-
if (errors.length > 0) {
|
|
10
|
-
throw new BuilderException(errors);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
function collectBuilderErrors(builder) {
|
|
14
|
-
const expectationErrors = collectNestedBuilders(builder).flatMap((inner) => collectExpectationErrors(inner, inner.expectations));
|
|
15
|
-
const parameterWalkErrors = [];
|
|
16
|
-
const walkValidate = createWalkerValidation((parameter) => {
|
|
17
|
-
parameterWalkErrors.push({ kind: 'unbound-parameter', name: parameter.name });
|
|
18
|
-
});
|
|
19
|
-
walkValidate(BuilderSerialisedSchema, builder);
|
|
20
|
-
const parameterErrors = builder.parameters
|
|
21
|
-
.filter(isParameter)
|
|
22
|
-
.map((parameter) => ({ kind: 'unbound-parameter', name: parameter.name }));
|
|
23
|
-
return [...expectationErrors, ...parameterErrors, ...parameterWalkErrors];
|
|
24
|
-
}
|
|
25
|
-
function collectNestedBuilders(builder) {
|
|
26
|
-
const nested = builder.collections.flatMap((collection) => nestedBuildersOf(collection.payload));
|
|
27
|
-
return [builder, ...nested.flatMap((inner) => collectNestedBuilders(inner))];
|
|
28
|
-
}
|
|
29
|
-
function nestedBuildersOf(payload) {
|
|
30
|
-
if (isParameter(payload)) {
|
|
31
|
-
return [];
|
|
32
|
-
}
|
|
33
|
-
if (v.is(BuilderCollectionConfigSchema, payload)) {
|
|
34
|
-
return isParameter(payload.builder) ? [] : [payload.builder];
|
|
35
|
-
}
|
|
36
|
-
const whenPayload = payload;
|
|
37
|
-
if (whenPayload.type === 'match' && whenPayload.selectMap != null) {
|
|
38
|
-
return Object.values(whenPayload.selectMap).flatMap((value) => value && !isParameter(value.builder) ? [value.builder] : []);
|
|
39
|
-
}
|
|
40
|
-
const inner = whenPayload.payload;
|
|
41
|
-
if (inner == null || isParameter(inner)) {
|
|
42
|
-
return [];
|
|
43
|
-
}
|
|
44
|
-
const innerBuilder = inner.builder;
|
|
45
|
-
return isParameter(innerBuilder) ? [] : [innerBuilder];
|
|
46
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export function collectExpectationErrors(builder, expectations) {
|
|
2
|
-
return expectations.flatMap((expectation) => {
|
|
3
|
-
if (expectation.kind === 'detail') {
|
|
4
|
-
return [];
|
|
5
|
-
}
|
|
6
|
-
const lookup = expectation.kind === 'option'
|
|
7
|
-
? builder.options
|
|
8
|
-
: expectation.kind === 'component'
|
|
9
|
-
? builder.components
|
|
10
|
-
: builder.collections;
|
|
11
|
-
const exists = lookup.some((entry) => entry.name === expectation.name);
|
|
12
|
-
if (exists) {
|
|
13
|
-
return [];
|
|
14
|
-
}
|
|
15
|
-
return [
|
|
16
|
-
{
|
|
17
|
-
kind: 'unmet-expectation',
|
|
18
|
-
expectationKind: expectation.kind,
|
|
19
|
-
name: expectation.name
|
|
20
|
-
}
|
|
21
|
-
];
|
|
22
|
-
});
|
|
23
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export type { BuilderErrorInvalidCollection, BuilderErrorInvalidOption } from './model';
|
|
2
|
-
export type { BuilderErrorInvalidVariant, BuilderErrorMissingComponent, BuilderErrorMissingDetail, BuilderErrorMissingVariant, BuilderErrorUnexpectedComponent, BuilderErrorUnexpectedDetail } from './models';
|
|
3
|
-
export { assertBuilder } from './builder.js';
|
|
4
|
-
export { assertModel } from './model.js';
|
|
5
|
-
export { assertModels } from './models.js';
|
|
6
|
-
export { assertUI } from './ui.js';
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { BuilderValidated } from '../../entities/index';
|
|
2
|
-
import type { BuilderModel } from '../../model';
|
|
3
|
-
export type BuilderErrorInvalidOption = {
|
|
4
|
-
readonly kind: 'invalid-option';
|
|
5
|
-
readonly name: string;
|
|
6
|
-
readonly value: unknown;
|
|
7
|
-
};
|
|
8
|
-
export type BuilderErrorInvalidCollection = {
|
|
9
|
-
readonly kind: 'invalid-collection';
|
|
10
|
-
readonly name: string;
|
|
11
|
-
readonly detail: string;
|
|
12
|
-
};
|
|
13
|
-
export declare function assertModel(builder: BuilderValidated, model: BuilderModel): void;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot';
|
|
2
|
-
import { BuilderException } from '../../exception.js';
|
|
3
|
-
import { resolveCollection, resolveOption } from '../resolve.js';
|
|
4
|
-
export function assertModel(builder, model) {
|
|
5
|
-
const errors = collectModelErrors(builder.options, builder.collections, model);
|
|
6
|
-
if (errors.length > 0) {
|
|
7
|
-
throw new BuilderException(errors);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
function collectModelErrors(options, collections, model) {
|
|
11
|
-
const optionErrors = options.flatMap((entry) => {
|
|
12
|
-
const option = resolveOption(entry, model);
|
|
13
|
-
if (!option) {
|
|
14
|
-
return [];
|
|
15
|
-
}
|
|
16
|
-
const value = model[option.name];
|
|
17
|
-
if (!v.is(option.payload.valueSchema, value)) {
|
|
18
|
-
return [{ kind: 'invalid-option', name: option.name, value }];
|
|
19
|
-
}
|
|
20
|
-
return [];
|
|
21
|
-
});
|
|
22
|
-
const collectionErrors = collections.flatMap((entry) => {
|
|
23
|
-
const collection = resolveCollection(entry, model);
|
|
24
|
-
if (!collection) {
|
|
25
|
-
return [];
|
|
26
|
-
}
|
|
27
|
-
const existing = model[collection.name];
|
|
28
|
-
if (!Array.isArray(existing)) {
|
|
29
|
-
return [
|
|
30
|
-
{
|
|
31
|
-
kind: 'invalid-collection',
|
|
32
|
-
name: collection.name,
|
|
33
|
-
detail: 'expected an array'
|
|
34
|
-
}
|
|
35
|
-
];
|
|
36
|
-
}
|
|
37
|
-
const nestedBuilder = collection.payload.builder;
|
|
38
|
-
return existing.flatMap((itemModel, index) => {
|
|
39
|
-
const nestedErrors = collectModelErrors(nestedBuilder.options, nestedBuilder.collections, itemModel);
|
|
40
|
-
return nestedErrors.map((error) => ({
|
|
41
|
-
...error,
|
|
42
|
-
name: `${collection.name}[${String(index)}].${error.name}`
|
|
43
|
-
}));
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
return [...optionErrors, ...collectionErrors];
|
|
47
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { BuilderValidated } from '../../entities/index';
|
|
2
|
-
import type { BuilderData, BuilderModel } from '../../model';
|
|
3
|
-
export type BuilderErrorMissingComponent = {
|
|
4
|
-
readonly kind: 'missing-component';
|
|
5
|
-
readonly component: string;
|
|
6
|
-
};
|
|
7
|
-
export type BuilderErrorUnexpectedComponent = {
|
|
8
|
-
readonly kind: 'unexpected-component';
|
|
9
|
-
readonly component: string;
|
|
10
|
-
};
|
|
11
|
-
export type BuilderErrorMissingVariant = {
|
|
12
|
-
readonly kind: 'missing-variant';
|
|
13
|
-
readonly component: string;
|
|
14
|
-
readonly model: BuilderModel;
|
|
15
|
-
};
|
|
16
|
-
export type BuilderErrorInvalidVariant = {
|
|
17
|
-
readonly kind: 'invalid-variant';
|
|
18
|
-
readonly component: string;
|
|
19
|
-
readonly model: BuilderModel;
|
|
20
|
-
};
|
|
21
|
-
export type BuilderErrorMissingDetail = {
|
|
22
|
-
readonly kind: 'missing-detail';
|
|
23
|
-
readonly component: string;
|
|
24
|
-
readonly detail: string;
|
|
25
|
-
readonly model: BuilderModel;
|
|
26
|
-
};
|
|
27
|
-
export type BuilderErrorUnexpectedDetail = {
|
|
28
|
-
readonly kind: 'unexpected-detail';
|
|
29
|
-
readonly component: string;
|
|
30
|
-
readonly detail: string;
|
|
31
|
-
readonly model: BuilderModel;
|
|
32
|
-
};
|
|
33
|
-
export declare function assertModels(builder: BuilderValidated, builderData: BuilderData): void;
|