@builder-builder/builder 0.0.9 → 0.0.11
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 -0
- package/dist/entities/builder/builder.d.ts +17 -490
- package/dist/entities/builder/builder.js +19 -76
- 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 +71 -20
- package/dist/entities/collection/collection.js +10 -27
- package/dist/entities/collection/config.d.ts +40 -1049
- package/dist/entities/collection/config.js +11 -11
- package/dist/entities/collection/expectation.d.ts +8 -4
- package/dist/entities/collection/index.d.ts +3 -3
- package/dist/entities/collection/index.js +1 -1
- package/dist/entities/collection/when.d.ts +6 -5
- package/dist/entities/component/component.d.ts +272 -300
- package/dist/entities/component/component.js +9 -8
- package/dist/entities/component/details.d.ts +35 -60
- package/dist/entities/component/details.js +9 -9
- 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 +5 -3
- package/dist/entities/component/index.js +3 -2
- package/dist/entities/component/when.d.ts +5 -5
- 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 +21 -16
- package/dist/entities/index.js +10 -8
- package/dist/entities/kind.d.ts +9 -0
- package/dist/entities/kind.js +5 -0
- 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 +2 -2
- package/dist/entities/option/index.js +2 -2
- package/dist/entities/option/option.d.ts +216 -214
- package/dist/entities/option/option.js +9 -8
- 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 +4 -24
- package/dist/entities/option/values.js +10 -4
- package/dist/entities/option/when.d.ts +6 -5
- package/dist/entities/refs.d.ts +6 -0
- package/dist/entities/refs.js +1 -0
- package/dist/entities/serialise.d.ts +393 -3568
- package/dist/entities/serialise.js +160 -31
- package/dist/entities/ui/describe.d.ts +23 -57
- package/dist/entities/ui/describe.js +4 -5
- package/dist/entities/ui/index.d.ts +4 -9
- package/dist/entities/ui/index.js +2 -4
- package/dist/entities/ui/page.d.ts +23 -57
- package/dist/entities/ui/page.js +4 -5
- package/dist/entities/ui/pages.d.ts +18 -403
- package/dist/entities/ui/pages.js +7 -7
- package/dist/entities/ui/ui.d.ts +22 -1575
- package/dist/entities/ui/ui.js +15 -28
- package/dist/entities/ui/uis.d.ts +5 -9
- package/dist/entities/ui/uis.js +12 -19
- package/dist/entities/validated.d.ts +35 -0
- package/dist/entities/validated.js +1 -0
- package/dist/entities/when.d.ts +79 -70
- package/dist/entities/when.js +11 -7
- 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 -24
- package/dist/index.js +5 -10
- package/dist/instance.d.ts +56 -0
- package/dist/instance.js +10 -0
- package/dist/mappers/index.d.ts +7 -5
- package/dist/mappers/index.js +5 -3
- package/dist/mappers/instance.d.ts +3 -0
- package/dist/mappers/instance.js +35 -0
- package/dist/mappers/order.d.ts +6 -0
- package/dist/mappers/order.js +22 -0
- package/dist/mappers/render/pages.d.ts +4 -4
- package/dist/mappers/render/render.d.ts +2 -3
- package/dist/mappers/render/render.js +83 -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 +27 -36
- package/dist/references.js +19 -12
- 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 +196 -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 +12 -9
- package/dist/entities/builder/builders.d.ts +0 -20
- package/dist/entities/builder/builders.js +0 -18
- package/dist/entities/builder/expectation.d.ts +0 -12
- package/dist/entities/builder/methods.d.ts +0 -58
- package/dist/entities/builder/parameter.d.ts +0 -62
- package/dist/entities/builder/parameter.js +0 -18
- 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/label.d.ts +0 -18
- package/dist/entities/ui/label.js +0 -12
- package/dist/entities/ui/parameter.d.ts +0 -7
- package/dist/entities/ui/parameter.js +0 -29
- 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/model.d.ts +0 -14
- 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 -18
- package/dist/walker/walker.js +0 -103
- package/dist/walker/walkers.d.ts +0 -8
- package/dist/walker/walkers.js +0 -51
- /package/dist/entities/builder/{expectation.js → bind.js} +0 -0
- /package/dist/entities/{builder/state.js → entry.js} +0 -0
- /package/dist/entities/{errors.js → model/bind.js} +0 -0
- /package/dist/entities/{validate.js → model/expectation.js} +0 -0
- /package/dist/{model.js → entities/model/state.js} +0 -0
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot';
|
|
2
|
-
import { isRef } from '../../references.js';
|
|
3
|
-
import { Builder, BuilderSchema } from './builder.js';
|
|
4
|
-
export function builders(...builders) {
|
|
5
|
-
const references = builders.filter((payload) => isRef(payload));
|
|
6
|
-
const merged = mergeBuilderParts(builders);
|
|
7
|
-
return new Builder([...references, ...merged.references], merged.options, merged.components, merged.collections, merged.expectations);
|
|
8
|
-
}
|
|
9
|
-
export function mergeBuilderParts(parts) {
|
|
10
|
-
const instances = parts.filter((part) => v.is(BuilderSchema, part));
|
|
11
|
-
return {
|
|
12
|
-
references: instances.flatMap((builder) => [...builder.references]),
|
|
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
|
-
};
|
|
18
|
-
}
|
|
@@ -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 { BuilderRef, Refable } 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 Refable<BuilderOptionValues>>(name: Name, payload: Payload): OptionStateAppend<State, BuilderOption<Name, Payload>>;
|
|
15
|
-
when: <const GatePaths extends Refable<BuilderValidPaths<State>>, const Name extends string, const Payload extends Refable<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 Refable<BuilderComponentDetails>>(name: Name, payload?: Payload): ComponentStateAppend<State, BuilderComponent<Name, Payload>>;
|
|
19
|
-
when: <const GatePaths extends Refable<BuilderValidPaths<State>>, const Name extends string, const Payload extends Refable<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 Refable<BuilderCollectionConfig>>(name: Name, payload: Payload): CollectionStateAppend<State, BuilderCollection<Name, Payload>>;
|
|
23
|
-
when: <const GatePaths extends Refable<BuilderValidPaths<State>>, const Name extends string, const Payload extends Refable<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 Refable<BuilderOptionWhen>> = Payload extends BuilderOptionWhen ? BuilderOption<Name, WhenConfigPayload<Payload, BuilderOptionValues>> : BuilderOption<Name, BuilderRef>;
|
|
26
|
-
type ComponentWhenResolver<Name extends string, Payload extends Refable<BuilderComponentWhen>> = Payload extends BuilderComponentWhen ? BuilderComponent<Name, WhenConfigPayload<Payload, BuilderComponentDetails>> : BuilderComponent<Name, BuilderRef>;
|
|
27
|
-
type CollectionWhenResolver<Name extends string, Payload extends Refable<BuilderCollectionWhen>> = Payload extends BuilderCollectionWhen ? BuilderCollection<Name, WhenConfigPayload<Payload, BuilderCollectionConfig>> : BuilderCollection<Name, BuilderRef>;
|
|
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 BuilderRef ? 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: Refable<BuilderOptionValues>) => BuilderOption<string, Refable<import("..").BuilderSelectType<readonly [string, ...string[]], import("valibot").GenericSchema<string | null>> | import("..").BuilderToggleType<import("valibot").GenericSchema<string | number | boolean | null>>>, Refable<readonly (readonly (string | number)[])[]>>) & {
|
|
50
|
-
when(gatePaths: Refable<BuilderPaths>, name: string, payload: Refable<BuilderOptionWhen>): BuilderOption<string, Refable<BuilderOptionWhen>, readonly (readonly (string | number)[])[] | BuilderRef>;
|
|
51
|
-
};
|
|
52
|
-
export declare function builderComponentMethod(): ((name: string, payload?: Refable<BuilderComponentDetails>) => BuilderComponent<string, Refable<BuilderComponentDetails<Refable<readonly import("..").BuilderExpectation<string, unknown, "option" | "component" | "collection" | "detail">[]>>> | import("../when").BuilderEnableConfig<Refable<BuilderComponentDetails<Refable<readonly import("..").BuilderExpectation<string, unknown, "option" | "component" | "collection" | "detail">[]>>>>, Refable<readonly (readonly (string | number)[])[]>>) & {
|
|
53
|
-
when(gatePaths: Refable<BuilderPaths>, name: string, payload?: Refable<BuilderComponentWhen>): BuilderComponent<string, Refable<BuilderComponentWhen>, readonly (readonly (string | number)[])[] | BuilderRef>;
|
|
54
|
-
};
|
|
55
|
-
export declare function builderCollectionMethod(): ((name: string, payload: Refable<BuilderCollectionConfig>) => BuilderCollection<string, Refable<BuilderCollectionConfig<Refable<import("./builder").BuilderGeneric>, Refable<number>, Refable<number>>>, Refable<readonly (readonly (string | number)[])[]>>) & {
|
|
56
|
-
when(gatePaths: Refable<BuilderPaths>, name: string, payload: Refable<BuilderCollectionWhen>): BuilderCollection<string, Refable<BuilderCollectionWhen>, readonly (readonly (string | number)[])[] | BuilderRef>;
|
|
57
|
-
};
|
|
58
|
-
export {};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import type { BuilderPaths } from '../../paths';
|
|
2
|
-
import type { BuilderRef, Refable } from '../../references';
|
|
3
|
-
import type { BuilderCollectionPayload } from '../collection/index';
|
|
4
|
-
import type { BuilderComponentPayload } from '../component/index';
|
|
5
|
-
import type { BuilderOptionPayload } from '../option/index';
|
|
6
|
-
import type { BuilderWhenConfig, BuilderWhenConstrained, WhenConfigNullable } from '../when';
|
|
7
|
-
import type { BuilderState, BuilderStateAppend } from './state';
|
|
8
|
-
import { Builder } from './builder.js';
|
|
9
|
-
type ParameterNamesOf<Entries extends ReadonlyArray<EntryLike>> = EntryParameters<Entries>['name'];
|
|
10
|
-
type PayloadForParameter<State extends BuilderState, Name extends string> = Name extends ParameterNamesOf<State['options']> ? BuilderOptionPayload : Name extends ParameterNamesOf<State['collections']> ? BuilderCollectionPayload : Name extends ParameterNamesOf<State['components']> ? BuilderComponentPayload : never;
|
|
11
|
-
export type BuilderBindings<State extends BuilderState> = {
|
|
12
|
-
readonly [Name in ParameterNamesOf<State['options']> | ParameterNamesOf<State['collections']> | ParameterNamesOf<State['components']>]: BuilderWhenConstrained<State, PayloadForParameter<State, Name>>;
|
|
13
|
-
};
|
|
14
|
-
export declare function bindBuilder<State extends BuilderState, Bindings extends BuilderBindings<State>>(builder: Builder<State>, bindings: Bindings): Builder<BuilderBoundState<State, Bindings>>;
|
|
15
|
-
export type BuilderBoundState<State extends BuilderState, Bindings extends BuilderBindings<State>> = BuilderStateAppend<State, {
|
|
16
|
-
options: EntryBound<State['options'], Extract<keyof Bindings, string>>;
|
|
17
|
-
collections: EntryBound<State['collections'], Extract<keyof Bindings, string>>;
|
|
18
|
-
components: EntryBound<State['components'], Extract<keyof Bindings, string>>;
|
|
19
|
-
model: Omit<State['model'], keyof Bindings> & {
|
|
20
|
-
[K in Extract<keyof Bindings, string>]: BindingModelType<Bindings[K]>;
|
|
21
|
-
};
|
|
22
|
-
}>;
|
|
23
|
-
export type BindingModelType<Binding> = BindingValueType<Binding> | BindingConfigNullable<Binding>;
|
|
24
|
-
type BindingValueType<Binding> = Binding extends {
|
|
25
|
-
readonly type: 'match';
|
|
26
|
-
readonly selectMap: infer SelectMap extends Record<string, unknown>;
|
|
27
|
-
} ? NonNullable<SelectMap[keyof SelectMap]> extends {
|
|
28
|
-
readonly value: infer Value;
|
|
29
|
-
} ? Value : string : Binding extends {
|
|
30
|
-
readonly payload: {
|
|
31
|
-
readonly value: infer Value;
|
|
32
|
-
};
|
|
33
|
-
} ? Value : Binding extends {
|
|
34
|
-
readonly value: infer Value;
|
|
35
|
-
} ? Value : string;
|
|
36
|
-
type BindingConfigNullable<Binding> = Binding extends BuilderWhenConfig ? WhenConfigNullable<Binding> : never;
|
|
37
|
-
type EntryLike = {
|
|
38
|
-
readonly name: string;
|
|
39
|
-
readonly payload: unknown;
|
|
40
|
-
readonly gatePaths?: Refable<BuilderPaths>;
|
|
41
|
-
};
|
|
42
|
-
type EntryBound<Entries extends ReadonlyArray<EntryLike>, BoundNames extends string> = Entries extends readonly [
|
|
43
|
-
infer Head extends EntryLike,
|
|
44
|
-
...infer Tail extends ReadonlyArray<EntryLike>
|
|
45
|
-
] ? Head extends {
|
|
46
|
-
readonly payload: infer Payload;
|
|
47
|
-
} ? Payload extends BuilderRef ? Head['name'] extends BoundNames ? [...EntryBound<Tail, BoundNames>] : [Head, ...EntryBound<Tail, BoundNames>] : [Head, ...EntryBound<Tail, BoundNames>] : [Head, ...EntryBound<Tail, BoundNames>] : [];
|
|
48
|
-
type EntryParameters<Entries extends ReadonlyArray<EntryLike>> = Entries[number] extends infer Entry ? Entry extends {
|
|
49
|
-
readonly payload: infer Payload;
|
|
50
|
-
} ? PayloadParameters<Payload> : never : never;
|
|
51
|
-
type PayloadParameters<Payload> = ParameterOf<Payload> | (Payload extends {
|
|
52
|
-
readonly type: 'match';
|
|
53
|
-
readonly selectMap: infer SelectMap;
|
|
54
|
-
} ? ParameterOf<SelectMap[keyof SelectMap]> : never) | (Payload extends {
|
|
55
|
-
readonly type: 'enable' | 'unless';
|
|
56
|
-
readonly payload: infer Inner;
|
|
57
|
-
} ? ParameterOf<Inner> : never);
|
|
58
|
-
type ParameterOf<Value> = Extract<Value, BuilderRef> extends infer Ref extends BuilderRef ? {
|
|
59
|
-
readonly name: Ref['name'];
|
|
60
|
-
readonly payload: Ref;
|
|
61
|
-
} : never;
|
|
62
|
-
export {};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot';
|
|
2
|
-
import { isRef } from '../../references.js';
|
|
3
|
-
import { createWalkerBinding } from '../../walker/index.js';
|
|
4
|
-
import { Builder, BuilderSchema, BuilderSerialisedSchema } from './builder.js';
|
|
5
|
-
import { mergeBuilderParts } from './builders.js';
|
|
6
|
-
export function bindBuilder(builder, bindings) {
|
|
7
|
-
const { expectations, references } = builder;
|
|
8
|
-
const bindingEntries = Object.entries(bindings);
|
|
9
|
-
const boundNames = new Set(bindingEntries.filter(([, value]) => v.is(BuilderSchema, value)).map(([name]) => name));
|
|
10
|
-
const remainingReferences = references.filter((reference) => !isRef(reference) || !boundNames.has(reference.name));
|
|
11
|
-
const bindingLookup = bindings;
|
|
12
|
-
const walkBind = createWalkerBinding({
|
|
13
|
-
lookupBinding: (ref) => bindingLookup[ref.name]
|
|
14
|
-
});
|
|
15
|
-
const walked = walkBind(BuilderSerialisedSchema, builder);
|
|
16
|
-
const merged = mergeBuilderParts(bindingEntries.map(([, value]) => value));
|
|
17
|
-
return new Builder([...remainingReferences, ...merged.references], [...walked.options, ...merged.options], [...walked.components, ...merged.components], [...walked.collections, ...merged.collections], [...expectations, ...merged.expectations]);
|
|
18
|
-
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot';
|
|
2
|
-
import { BuilderException } from '../../exception.js';
|
|
3
|
-
import { isRef } 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 && !isRef(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 isRef(matchPath) ? [] : [matchPath];
|
|
50
|
-
}
|
|
51
|
-
if (v.is(BuilderWhenUnlessSchema, payload)) {
|
|
52
|
-
const unlessPath = payload.unlessPath;
|
|
53
|
-
return isRef(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) => isRef(config.max) || index < config.max);
|
|
92
|
-
if (withinBounds.length === 0 && configs.length > 0) {
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
return withinBounds.flatMap((config) => (isRef(config.builder) ? [] : [config.builder]));
|
|
96
|
-
}
|
|
97
|
-
function possibleConfigs(payload) {
|
|
98
|
-
if (isRef(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,18 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot';
|
|
2
|
-
export declare class BuilderUILabel<const Label extends string = string> {
|
|
3
|
-
readonly type: 'label';
|
|
4
|
-
readonly label: Label;
|
|
5
|
-
constructor(label: Label);
|
|
6
|
-
}
|
|
7
|
-
export declare const BuilderUILabelSchema: v.InstanceSchema<typeof BuilderUILabel, undefined>;
|
|
8
|
-
export declare const BuilderUILabelSerialisedSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
9
|
-
readonly label: v.StringSchema<undefined>;
|
|
10
|
-
}, undefined>, v.MetadataAction<{
|
|
11
|
-
label: string;
|
|
12
|
-
}, {
|
|
13
|
-
readonly serialisable: typeof BuilderUILabel;
|
|
14
|
-
readonly instance: v.InstanceSchema<typeof BuilderUILabel, undefined>;
|
|
15
|
-
}>, v.ReadonlyAction<{
|
|
16
|
-
label: string;
|
|
17
|
-
}>]>;
|
|
18
|
-
export type BuilderUILabelSerialised = v.InferOutput<typeof BuilderUILabelSerialisedSchema>;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot';
|
|
2
|
-
import { serialisable } from '../../serialisable.js';
|
|
3
|
-
export class BuilderUILabel {
|
|
4
|
-
label;
|
|
5
|
-
constructor(label) {
|
|
6
|
-
this.label = label;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export const BuilderUILabelSchema = v.instance(BuilderUILabel);
|
|
10
|
-
export const BuilderUILabelSerialisedSchema = serialisable(BuilderUILabel, v.object({
|
|
11
|
-
label: v.string()
|
|
12
|
-
}));
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Refable } from '../../references';
|
|
2
|
-
import type { BuilderGeneric } from '../builder/index';
|
|
3
|
-
import type { BuilderUIItems } from './pages';
|
|
4
|
-
import type { BuilderUIGeneric } from './ui';
|
|
5
|
-
import { BuilderUI } from './ui.js';
|
|
6
|
-
export type BuilderUIBindings = Record<string, string | BuilderUIGeneric | BuilderUIItems | unknown>;
|
|
7
|
-
export declare function bindUI<BuilderType extends Refable<BuilderGeneric>>(ui: BuilderUI<BuilderType>, bindings: BuilderUIBindings): BuilderUI<BuilderType>;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot';
|
|
2
|
-
import { createWalkerBinding } from '../../walker/index.js';
|
|
3
|
-
import { BuilderUILabel } from './label.js';
|
|
4
|
-
import { BuilderUIItemsSerialisedSchema } from './pages.js';
|
|
5
|
-
import { BuilderUI, BuilderUISchema } from './ui.js';
|
|
6
|
-
import { mergeUIParts } from './uis.js';
|
|
7
|
-
export function bindUI(ui, bindings) {
|
|
8
|
-
const merged = mergeUIParts(Object.values(bindings));
|
|
9
|
-
const walk = createWalkerBinding({
|
|
10
|
-
lookupBinding: (ref) => {
|
|
11
|
-
const binding = bindings[ref.name];
|
|
12
|
-
if (binding == null) {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
if (typeof binding === 'string') {
|
|
16
|
-
return new BuilderUILabel(binding);
|
|
17
|
-
}
|
|
18
|
-
if (v.is(BuilderUISchema, binding)) {
|
|
19
|
-
return [...binding.items];
|
|
20
|
-
}
|
|
21
|
-
return binding;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
const boundItems = walk(BuilderUIItemsSerialisedSchema, ui.items);
|
|
25
|
-
return new BuilderUI(ui.builder, [...ui.references, ...merged.references], boundItems, [
|
|
26
|
-
...ui.expectations,
|
|
27
|
-
...merged.expectations
|
|
28
|
-
]);
|
|
29
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Refable } 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: Refable<BuilderGeneric>, items: Refable<BuilderUIItems>): void;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { BuilderException } from '../../exception.js';
|
|
2
|
-
import { isRef } from '../../references.js';
|
|
3
|
-
import { BuilderUIPages } from './pages.js';
|
|
4
|
-
export function validatePagesCollections(builder, items) {
|
|
5
|
-
if (isRef(builder) || isRef(items)) {
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
const errors = items.flatMap((item) => {
|
|
9
|
-
if (isRef(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 { BuilderRef } 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, BuilderUILabel, BuilderUIPage, BuilderUIPages } from './ui/index';
|
|
8
|
-
export type Strip<T> = T extends BuilderRef ? never : T extends BuilderSelectType | BuilderToggleType | BuilderUILabel | 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 { isRef } 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 parameterErrors = [];
|
|
16
|
-
const walkValidate = createWalkerValidation((ref) => {
|
|
17
|
-
parameterErrors.push({ kind: 'unbound-parameter', name: ref.name });
|
|
18
|
-
});
|
|
19
|
-
walkValidate(BuilderSerialisedSchema, builder);
|
|
20
|
-
const referenceErrors = builder.references
|
|
21
|
-
.filter(isRef)
|
|
22
|
-
.map((reference) => ({ kind: 'unbound-parameter', name: reference.name }));
|
|
23
|
-
return [...expectationErrors, ...referenceErrors, ...parameterErrors];
|
|
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 (isRef(payload)) {
|
|
31
|
-
return [];
|
|
32
|
-
}
|
|
33
|
-
if (v.is(BuilderCollectionConfigSchema, payload)) {
|
|
34
|
-
return isRef(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 && !isRef(value.builder) ? [value.builder] : []);
|
|
39
|
-
}
|
|
40
|
-
const inner = whenPayload.payload;
|
|
41
|
-
if (inner == null || isRef(inner)) {
|
|
42
|
-
return [];
|
|
43
|
-
}
|
|
44
|
-
const innerBuilder = inner.builder;
|
|
45
|
-
return isRef(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;
|