@builder-builder/builder 0.0.9 → 0.0.10
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/entities/bind.d.ts +4 -0
- package/dist/entities/bind.js +44 -0
- package/dist/entities/builder/bind.d.ts +85 -0
- package/dist/entities/builder/bind.js +9 -0
- package/dist/entities/builder/builder.d.ts +111 -92
- package/dist/entities/builder/builder.js +11 -8
- package/dist/entities/builder/builders.d.ts +23 -8
- package/dist/entities/builder/builders.js +6 -5
- package/dist/entities/builder/index.d.ts +3 -3
- package/dist/entities/builder/index.js +1 -1
- package/dist/entities/builder/methods.d.ts +17 -17
- package/dist/entities/builder/state.d.ts +4 -4
- package/dist/entities/builder/validate.js +7 -7
- package/dist/entities/collection/collection.d.ts +6 -5
- package/dist/entities/collection/collection.js +6 -5
- package/dist/entities/collection/config.d.ts +280 -232
- package/dist/entities/collection/config.js +4 -4
- package/dist/entities/collection/index.d.ts +1 -1
- package/dist/entities/collection/index.js +1 -1
- package/dist/entities/collection/when.d.ts +5 -5
- package/dist/entities/component/component.d.ts +91 -90
- package/dist/entities/component/component.js +5 -4
- package/dist/entities/component/details.d.ts +16 -16
- package/dist/entities/component/details.js +2 -2
- package/dist/entities/component/index.d.ts +1 -1
- package/dist/entities/component/index.js +1 -1
- package/dist/entities/component/when.d.ts +5 -5
- package/dist/entities/index.d.ts +10 -8
- package/dist/entities/index.js +7 -6
- package/dist/entities/kind.d.ts +6 -0
- package/dist/entities/kind.js +6 -0
- package/dist/entities/option/index.d.ts +1 -1
- package/dist/entities/option/index.js +1 -1
- package/dist/entities/option/option.d.ts +39 -38
- package/dist/entities/option/option.js +5 -4
- package/dist/entities/option/values.d.ts +5 -7
- package/dist/entities/option/values.js +4 -4
- package/dist/entities/option/when.d.ts +5 -5
- package/dist/entities/serialise.d.ts +1582 -2226
- package/dist/entities/serialise.js +52 -22
- package/dist/entities/ui/bind.d.ts +10 -0
- package/dist/entities/ui/bind.js +9 -0
- package/dist/entities/ui/describe.d.ts +26 -51
- package/dist/entities/ui/describe.js +3 -4
- package/dist/entities/ui/index.d.ts +5 -7
- package/dist/entities/ui/index.js +2 -3
- package/dist/entities/ui/page.d.ts +26 -51
- package/dist/entities/ui/page.js +3 -4
- package/dist/entities/ui/pages.d.ts +17 -405
- package/dist/entities/ui/pages.js +6 -6
- package/dist/entities/ui/ui.d.ts +307 -688
- package/dist/entities/ui/ui.js +16 -17
- package/dist/entities/ui/uis.d.ts +11 -5
- package/dist/entities/ui/uis.js +9 -10
- package/dist/entities/ui/validate.d.ts +2 -2
- package/dist/entities/ui/validate.js +3 -3
- package/dist/entities/validate.d.ts +3 -3
- package/dist/entities/when.d.ts +45 -44
- package/dist/entities/when.js +10 -7
- package/dist/index.d.ts +19 -15
- package/dist/index.js +6 -3
- package/dist/mappers/assert/builder.js +13 -13
- package/dist/mappers/assert/ui.js +4 -4
- package/dist/mappers/index.d.ts +2 -0
- package/dist/mappers/index.js +1 -0
- package/dist/mappers/refs.d.ts +12 -0
- package/dist/mappers/refs.js +36 -0
- package/dist/mappers/render/render.js +3 -3
- package/dist/model.d.ts +29 -8
- package/dist/model.js +9 -1
- package/dist/references.d.ts +55 -29
- package/dist/references.js +25 -10
- package/dist/walker/walker.d.ts +13 -5
- package/dist/walker/walker.js +39 -27
- package/dist/walker/walkers.d.ts +4 -3
- package/dist/walker/walkers.js +18 -14
- package/package.json +9 -7
- package/dist/entities/builder/parameter.d.ts +0 -62
- package/dist/entities/builder/parameter.js +0 -18
- 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
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
import * as v from 'valibot';
|
|
2
2
|
import { check } from '../../check.js';
|
|
3
|
-
import {
|
|
3
|
+
import { BuilderParametersSerialisedSchema, BuilderReferencesSchema } from '../../references.js';
|
|
4
4
|
import { serialisable } from '../../serialisable.js';
|
|
5
5
|
import { BuilderCollectionsSerialisedSchema } from '../collection/index.js';
|
|
6
6
|
import { BuilderComponentDetailsSchema, BuilderComponentsSerialisedSchema, componentDetails } from '../component/index.js';
|
|
7
7
|
import { BuilderExpectationsSerialisedSchema } from '../expectation.js';
|
|
8
8
|
import { BuilderOptionsSerialisedSchema } from '../option/index.js';
|
|
9
9
|
import { builderCollectionMethod, builderComponentMethod, builderOptionMethod } from './methods.js';
|
|
10
|
-
import { bindBuilder } from './
|
|
10
|
+
import { bindBuilder } from './bind.js';
|
|
11
11
|
import { validateDuplicates, validatePaths } from './validate.js';
|
|
12
12
|
export class Builder {
|
|
13
|
-
|
|
13
|
+
parameters;
|
|
14
14
|
options;
|
|
15
15
|
components;
|
|
16
16
|
collections;
|
|
17
17
|
expectations;
|
|
18
|
+
references;
|
|
18
19
|
id = crypto.randomUUID();
|
|
19
|
-
constructor(
|
|
20
|
-
this.
|
|
20
|
+
constructor(parameters = [], options = [], components = [], collections = [], expectations = [], references = []) {
|
|
21
|
+
this.parameters = parameters;
|
|
21
22
|
this.options = options;
|
|
22
23
|
this.components = components;
|
|
23
24
|
this.collections = collections;
|
|
24
25
|
this.expectations = expectations;
|
|
26
|
+
this.references = references;
|
|
25
27
|
validateDuplicates(this);
|
|
26
28
|
validatePaths(this);
|
|
27
29
|
}
|
|
@@ -71,14 +73,15 @@ export class Builder {
|
|
|
71
73
|
return bindBuilder(this, bindings);
|
|
72
74
|
}
|
|
73
75
|
#next(patch) {
|
|
74
|
-
return new Builder(this.
|
|
76
|
+
return new Builder(this.parameters, patch.options ?? this.options, patch.components ?? this.components, patch.collections ?? this.collections, patch.expectations ?? this.expectations, this.references);
|
|
75
77
|
}
|
|
76
78
|
}
|
|
77
79
|
export const BuilderSchema = v.instance(Builder);
|
|
78
80
|
export const BuilderSerialisedSchema = serialisable(Builder, v.object({
|
|
79
|
-
|
|
81
|
+
parameters: BuilderParametersSerialisedSchema,
|
|
80
82
|
options: BuilderOptionsSerialisedSchema,
|
|
81
83
|
components: BuilderComponentsSerialisedSchema,
|
|
82
84
|
collections: BuilderCollectionsSerialisedSchema,
|
|
83
|
-
expectations: BuilderExpectationsSerialisedSchema
|
|
85
|
+
expectations: BuilderExpectationsSerialisedSchema,
|
|
86
|
+
references: BuilderReferencesSchema
|
|
84
87
|
}));
|
|
@@ -1,20 +1,35 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BuilderParameter } from '../../references';
|
|
2
|
+
import type { BuilderGeneric, BuilderParts, BuilderStateOf } from './builder';
|
|
2
3
|
import type { BuilderState, BuilderStateEmpty } from './state';
|
|
3
4
|
import { Builder } from './builder.js';
|
|
4
|
-
export declare function builders<const
|
|
5
|
+
export declare function builders<const Parts extends BuilderParts>(...builders: Parts): Builder<BuilderBuildersMerge<Parts>>;
|
|
5
6
|
export declare function mergeBuilderParts(parts: ReadonlyArray<unknown>): {
|
|
6
|
-
|
|
7
|
-
options: import("..").BuilderOption<string, import("../..").
|
|
8
|
-
components: import("..").BuilderComponent<string, import("../..").
|
|
9
|
-
collections: import("..").BuilderCollection<string, import("../..").
|
|
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)[])[]>>[];
|
|
10
11
|
expectations: import("..").BuilderExpectation<string, unknown, "option" | "component" | "collection" | "detail">[];
|
|
12
|
+
references: Readonly<{
|
|
13
|
+
parameter: string;
|
|
14
|
+
id: string;
|
|
15
|
+
}>[];
|
|
11
16
|
};
|
|
12
|
-
export type BuilderBuildersMerge<
|
|
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;
|
|
13
21
|
type BuilderStateMerge<Left extends BuilderState, Right extends BuilderState> = {
|
|
14
22
|
model: Left['model'] & Right['model'];
|
|
15
|
-
|
|
23
|
+
parameters: readonly [...Left['parameters'], ...Right['parameters']];
|
|
16
24
|
options: [...Left['options'], ...Right['options']];
|
|
17
25
|
components: [...Left['components'], ...Right['components']];
|
|
18
26
|
collections: [...Left['collections'], ...Right['collections']];
|
|
19
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
|
+
};
|
|
20
35
|
export {};
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import * as v from 'valibot';
|
|
2
|
-
import {
|
|
2
|
+
import { isParameter } from '../../references.js';
|
|
3
3
|
import { Builder, BuilderSchema } from './builder.js';
|
|
4
4
|
export function builders(...builders) {
|
|
5
|
-
const
|
|
5
|
+
const parameters = builders.filter((payload) => isParameter(payload));
|
|
6
6
|
const merged = mergeBuilderParts(builders);
|
|
7
|
-
return new Builder([...
|
|
7
|
+
return new Builder([...parameters, ...merged.parameters], merged.options, merged.components, merged.collections, merged.expectations, merged.references);
|
|
8
8
|
}
|
|
9
9
|
export function mergeBuilderParts(parts) {
|
|
10
10
|
const instances = parts.filter((part) => v.is(BuilderSchema, part));
|
|
11
11
|
return {
|
|
12
|
-
|
|
12
|
+
parameters: instances.flatMap((builder) => [...builder.parameters]),
|
|
13
13
|
options: instances.flatMap((builder) => [...builder.options]),
|
|
14
14
|
components: instances.flatMap((builder) => [...builder.components]),
|
|
15
15
|
collections: instances.flatMap((builder) => [...builder.collections]),
|
|
16
|
-
expectations: instances.flatMap((builder) => [...builder.expectations])
|
|
16
|
+
expectations: instances.flatMap((builder) => [...builder.expectations]),
|
|
17
|
+
references: instances.flatMap((builder) => [...builder.references])
|
|
17
18
|
};
|
|
18
19
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export type { BuilderGeneric, BuilderInstanceOf,
|
|
1
|
+
export type { BuilderGeneric, BuilderInstanceOf, BuilderPart, BuilderParts, BuilderSerialised, BuilderStateOf } from './builder';
|
|
2
2
|
export type { BuilderStateAsserted, ModelAsserted, ModelExpected } from './expectation';
|
|
3
|
-
export type { BindingModelType, BuilderBindings, BuilderBoundState } from './
|
|
3
|
+
export type { BindingModelType, BuilderBindings, BuilderBoundState } from './bind';
|
|
4
4
|
export type { BuilderState, BuilderStateAppend, BuilderStateEmpty } from './state';
|
|
5
5
|
export { Builder, BuilderSchema, BuilderSerialisedSchema } from './builder.js';
|
|
6
6
|
export { builders, mergeBuilderParts } from './builders.js';
|
|
7
|
-
export { bindBuilder } from './
|
|
7
|
+
export { bindBuilder } from './bind.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BuilderPaths } from '../../paths';
|
|
2
|
-
import type {
|
|
2
|
+
import type { BuilderParameter, Paramable } from '../../references';
|
|
3
3
|
import type { WhenConfigPayload } from '../when';
|
|
4
4
|
import type { BuilderCollectionConfig, BuilderCollectionWhen } from '../collection/index';
|
|
5
5
|
import type { BuilderComponentDetails, BuilderComponentWhen } from '../component/index';
|
|
@@ -11,20 +11,20 @@ import { BuilderCollection } from '../collection/index.js';
|
|
|
11
11
|
import { BuilderComponent } from '../component/index.js';
|
|
12
12
|
import { BuilderOption } from '../option/index.js';
|
|
13
13
|
export type BuilderOptionMethod<State extends BuilderState> = {
|
|
14
|
-
<const Name extends string, const Payload extends
|
|
15
|
-
when: <const GatePaths extends
|
|
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
16
|
};
|
|
17
17
|
export type BuilderComponentMethod<State extends BuilderState> = {
|
|
18
|
-
<const Name extends string, const Payload extends
|
|
19
|
-
when: <const GatePaths extends
|
|
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
20
|
};
|
|
21
21
|
export type BuilderCollectionMethod<State extends BuilderState> = {
|
|
22
|
-
<const Name extends string, const Payload extends
|
|
23
|
-
when: <const GatePaths extends
|
|
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
24
|
};
|
|
25
|
-
type OptionWhenResolver<Name extends string, Payload extends
|
|
26
|
-
type ComponentWhenResolver<Name extends string, Payload extends
|
|
27
|
-
type CollectionWhenResolver<Name extends string, Payload extends
|
|
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
28
|
type OptionStateAppend<State extends BuilderState, Option extends BuilderOption, ModelType = OptionModelOf<Option>> = Builder<BuilderStateAppend<State, {
|
|
29
29
|
model: State['model'] & {
|
|
30
30
|
[K in Option['name']]: ModelType;
|
|
@@ -38,7 +38,7 @@ type CollectionStateAppend<State extends BuilderState, Collection extends Builde
|
|
|
38
38
|
model: State['model'] & Record<Collection['name'], ModelType>;
|
|
39
39
|
collections: [...State['collections'], Collection];
|
|
40
40
|
}>>;
|
|
41
|
-
type OptionModelOf<Option extends BuilderOption> = Option['payload'] extends
|
|
41
|
+
type OptionModelOf<Option extends BuilderOption> = Option['payload'] extends BuilderParameter ? string : Option['payload'] extends {
|
|
42
42
|
readonly value: infer Value;
|
|
43
43
|
} ? Value : never;
|
|
44
44
|
type CollectionModelOf<Collection extends BuilderCollection> = [Collection['payload']] extends [
|
|
@@ -46,13 +46,13 @@ type CollectionModelOf<Collection extends BuilderCollection> = [Collection['payl
|
|
|
46
46
|
] ? null : Collection['payload'] extends BuilderCollectionConfig ? Collection['payload']['builder'] extends Builder<infer State extends BuilderState> ? CollectionShape<Collection, State['model']> : ReadonlyArray<unknown> : ReadonlyArray<unknown>;
|
|
47
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
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:
|
|
50
|
-
when(gatePaths:
|
|
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
51
|
};
|
|
52
|
-
export declare function builderComponentMethod(): ((name: string, payload?:
|
|
53
|
-
when(gatePaths:
|
|
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
54
|
};
|
|
55
|
-
export declare function builderCollectionMethod(): ((name: string, payload:
|
|
56
|
-
when(gatePaths:
|
|
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
57
|
};
|
|
58
58
|
export {};
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import type { Prettify } from '../../prettify';
|
|
2
|
-
import type {
|
|
2
|
+
import type { BuilderParameters } from '../../references';
|
|
3
3
|
import type { BuilderCollections } from '../collection/index';
|
|
4
4
|
import type { BuilderComponents } from '../component/index';
|
|
5
5
|
import type { BuilderOptions } from '../option/index';
|
|
6
6
|
export type BuilderState = {
|
|
7
7
|
model: unknown;
|
|
8
|
-
|
|
8
|
+
parameters: BuilderParameters;
|
|
9
9
|
options: BuilderOptions;
|
|
10
10
|
components: BuilderComponents;
|
|
11
11
|
collections: BuilderCollections;
|
|
12
12
|
};
|
|
13
13
|
export type BuilderStateEmpty = {
|
|
14
14
|
readonly model: unknown;
|
|
15
|
-
readonly
|
|
15
|
+
readonly parameters: [];
|
|
16
16
|
readonly options: [];
|
|
17
17
|
readonly components: [];
|
|
18
18
|
readonly collections: [];
|
|
19
19
|
};
|
|
20
20
|
export type BuilderStateAppend<State extends BuilderState, Patch extends Partial<BuilderState>> = {
|
|
21
21
|
model: Prettify<'model' extends keyof Patch ? Patch['model'] : State['model']>;
|
|
22
|
-
|
|
22
|
+
parameters: 'parameters' extends keyof Patch ? Extract<Patch['parameters'], BuilderParameters> : State['parameters'];
|
|
23
23
|
options: Extract<'options' extends keyof Patch ? Patch['options'] : State['options'], BuilderOptions>;
|
|
24
24
|
components: Extract<'components' extends keyof Patch ? Patch['components'] : State['components'], BuilderComponents>;
|
|
25
25
|
collections: Extract<'collections' extends keyof Patch ? Patch['collections'] : State['collections'], BuilderCollections>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as v from 'valibot';
|
|
2
2
|
import { BuilderException } from '../../exception.js';
|
|
3
|
-
import {
|
|
3
|
+
import { isParameter } from '../../references.js';
|
|
4
4
|
import { BuilderCollectionConfigSchema } from '../collection/index.js';
|
|
5
5
|
import { BuilderWhenMatchSchema, BuilderWhenUnlessSchema } from '../when.js';
|
|
6
6
|
export function validateDuplicates(builder) {
|
|
@@ -37,7 +37,7 @@ function collectPathErrors(builder) {
|
|
|
37
37
|
return allEntries.flatMap((entry) => pathsForEntry(entry).flatMap((path) => collectEntryPathErrors(builder, entry.name, path)));
|
|
38
38
|
}
|
|
39
39
|
function pathsForEntry(entry) {
|
|
40
|
-
const gatePaths = entry.gatePaths != null && !
|
|
40
|
+
const gatePaths = entry.gatePaths != null && !isParameter(entry.gatePaths)
|
|
41
41
|
? entry.gatePaths
|
|
42
42
|
: [];
|
|
43
43
|
const configPaths = pathsFromWhen(entry.payload);
|
|
@@ -46,11 +46,11 @@ function pathsForEntry(entry) {
|
|
|
46
46
|
function pathsFromWhen(payload) {
|
|
47
47
|
if (v.is(BuilderWhenMatchSchema, payload)) {
|
|
48
48
|
const matchPath = payload.matchPath;
|
|
49
|
-
return
|
|
49
|
+
return isParameter(matchPath) ? [] : [matchPath];
|
|
50
50
|
}
|
|
51
51
|
if (v.is(BuilderWhenUnlessSchema, payload)) {
|
|
52
52
|
const unlessPath = payload.unlessPath;
|
|
53
|
-
return
|
|
53
|
+
return isParameter(unlessPath) ? [] : [unlessPath];
|
|
54
54
|
}
|
|
55
55
|
return [];
|
|
56
56
|
}
|
|
@@ -88,14 +88,14 @@ function descendCollection(builder, collectionName, index) {
|
|
|
88
88
|
return [];
|
|
89
89
|
}
|
|
90
90
|
const configs = possibleConfigs(collection.payload);
|
|
91
|
-
const withinBounds = configs.filter((config) =>
|
|
91
|
+
const withinBounds = configs.filter((config) => isParameter(config.max) || index < config.max);
|
|
92
92
|
if (withinBounds.length === 0 && configs.length > 0) {
|
|
93
93
|
return null;
|
|
94
94
|
}
|
|
95
|
-
return withinBounds.flatMap((config) => (
|
|
95
|
+
return withinBounds.flatMap((config) => (isParameter(config.builder) ? [] : [config.builder]));
|
|
96
96
|
}
|
|
97
97
|
function possibleConfigs(payload) {
|
|
98
|
-
if (
|
|
98
|
+
if (isParameter(payload)) {
|
|
99
99
|
return [];
|
|
100
100
|
}
|
|
101
101
|
if (v.is(BuilderCollectionConfigSchema, payload)) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BuilderPaths } from '../../paths';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Paramable, ParamableSerialised } from '../../references';
|
|
3
3
|
import type { BuilderState } from '../builder/index';
|
|
4
4
|
import type { BuilderWhen, WhenSerialised } from '../when';
|
|
5
5
|
import type { BuilderCollectionConfigSerialised } from './config';
|
|
@@ -11,8 +11,8 @@ export type BuilderErrorInvalidCollectionBounds = {
|
|
|
11
11
|
readonly min: number;
|
|
12
12
|
readonly max: number;
|
|
13
13
|
};
|
|
14
|
-
export type BuilderCollectionPayload = BuilderCollectionConfig | BuilderWhen<
|
|
15
|
-
export declare class BuilderCollection<const Name extends string = string, const Payload extends
|
|
14
|
+
export type BuilderCollectionPayload = BuilderCollectionConfig | BuilderWhen<Paramable<BuilderCollectionConfig>>;
|
|
15
|
+
export declare class BuilderCollection<const Name extends string = string, const Payload extends Paramable<BuilderCollectionPayload> = Paramable<BuilderCollectionPayload>, const GatePaths extends Paramable<BuilderPaths> = Paramable<BuilderPaths>> {
|
|
16
16
|
readonly type: 'collection';
|
|
17
17
|
readonly name: Name;
|
|
18
18
|
readonly payload: Payload;
|
|
@@ -23,10 +23,11 @@ export declare const BuilderCollectionSchema: v.InstanceSchema<typeof BuilderCol
|
|
|
23
23
|
export type BuilderCollections = ReadonlyArray<BuilderCollection>;
|
|
24
24
|
export declare const BuilderCollectionWhenSerialisedSchema: v.GenericSchema;
|
|
25
25
|
export type BuilderCollectionWhenSerialised = WhenSerialised<BuilderCollectionConfigSerialised>;
|
|
26
|
+
export declare const BuilderCollectionSelectMapSerialisedSchema: v.GenericSchema;
|
|
26
27
|
export type BuilderCollectionSerialised = {
|
|
27
28
|
readonly name: string;
|
|
28
|
-
readonly gatePaths?:
|
|
29
|
-
readonly payload:
|
|
29
|
+
readonly gatePaths?: ParamableSerialised<BuilderPaths>;
|
|
30
|
+
readonly payload: ParamableSerialised<BuilderCollectionConfigSerialised | BuilderCollectionWhenSerialised>;
|
|
30
31
|
};
|
|
31
32
|
export declare const BuilderCollectionSerialisedSchema: v.GenericSchema<BuilderCollectionSerialised>;
|
|
32
33
|
export declare const BuilderCollectionsSerialisedSchema: v.SchemaWithPipe<readonly [v.ArraySchema<v.GenericSchema<BuilderCollectionSerialised>, undefined>, v.ReadonlyAction<BuilderCollectionSerialised[]>]>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as v from 'valibot';
|
|
2
2
|
import { BuilderException } from '../../exception.js';
|
|
3
3
|
import { BuilderPathsSchema } from '../../paths.js';
|
|
4
|
-
import {
|
|
4
|
+
import { isParameter, paramable } from '../../references.js';
|
|
5
5
|
import { serialisable } from '../../serialisable.js';
|
|
6
|
-
import { createWhenSerialisedSchema } from '../when.js';
|
|
6
|
+
import { createSelectMapSerialisedSchema, createWhenSerialisedSchema } from '../when.js';
|
|
7
7
|
import { BuilderCollectionConfig, BuilderCollectionConfigSerialisedSchema } from './config.js';
|
|
8
8
|
export class BuilderCollection {
|
|
9
9
|
name;
|
|
@@ -21,7 +21,7 @@ function validateCollectionBounds(name, payload) {
|
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
const { min, max } = payload;
|
|
24
|
-
if (
|
|
24
|
+
if (isParameter(min) || isParameter(max)) {
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
27
|
const minValue = min;
|
|
@@ -34,9 +34,10 @@ function validateCollectionBounds(name, payload) {
|
|
|
34
34
|
}
|
|
35
35
|
export const BuilderCollectionSchema = v.instance(BuilderCollection);
|
|
36
36
|
export const BuilderCollectionWhenSerialisedSchema = createWhenSerialisedSchema(BuilderCollectionConfigSerialisedSchema);
|
|
37
|
+
export const BuilderCollectionSelectMapSerialisedSchema = createSelectMapSerialisedSchema(BuilderCollectionConfigSerialisedSchema);
|
|
37
38
|
export const BuilderCollectionSerialisedSchema = serialisable(BuilderCollection, v.object({
|
|
38
39
|
name: v.string(),
|
|
39
|
-
payload:
|
|
40
|
-
gatePaths: v.optional(
|
|
40
|
+
payload: paramable(v.union([BuilderCollectionConfigSerialisedSchema, BuilderCollectionWhenSerialisedSchema])),
|
|
41
|
+
gatePaths: v.optional(paramable(BuilderPathsSchema))
|
|
41
42
|
}));
|
|
42
43
|
export const BuilderCollectionsSerialisedSchema = v.pipe(v.array(BuilderCollectionSerialisedSchema), v.readonly());
|