@builder-builder/builder 0.0.8 → 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 -14
- package/dist/index.js +6 -2
- 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 +10 -8
- package/dist/entities/builder/parameter.d.ts +0 -61
- 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
package/dist/entities/ui/ui.js
CHANGED
|
@@ -1,53 +1,52 @@
|
|
|
1
1
|
import * as v from 'valibot';
|
|
2
|
-
import {
|
|
2
|
+
import { BuilderParametersSerialisedSchema, BuilderReferencesSchema, isParameter, paramable } from '../../references.js';
|
|
3
3
|
import { serialisable } from '../../serialisable.js';
|
|
4
4
|
import { BuilderSerialisedSchema } from '../builder/index.js';
|
|
5
5
|
import { BuilderExpectationsSerialisedSchema } from '../expectation.js';
|
|
6
|
-
import { bindUI } from './
|
|
6
|
+
import { bindUI } from './bind.js';
|
|
7
7
|
import { BuilderUIDescribe } from './describe.js';
|
|
8
|
-
import { BuilderUILabel } from './label.js';
|
|
9
8
|
import { BuilderUIPage } from './page.js';
|
|
10
9
|
import { BuilderUIItemsSerialisedSchema, BuilderUIPages } from './pages.js';
|
|
11
10
|
import { validatePagesCollections } from './validate.js';
|
|
12
11
|
export class BuilderUI {
|
|
13
12
|
builder;
|
|
14
|
-
|
|
13
|
+
parameters;
|
|
15
14
|
items;
|
|
16
15
|
expectations;
|
|
16
|
+
references;
|
|
17
17
|
id = crypto.randomUUID();
|
|
18
|
-
constructor(builder,
|
|
18
|
+
constructor(builder, parameters, items, expectations, references = []) {
|
|
19
19
|
this.builder = builder;
|
|
20
|
-
this.
|
|
20
|
+
this.parameters = parameters;
|
|
21
21
|
this.items = items;
|
|
22
22
|
this.expectations = expectations;
|
|
23
|
+
this.references = references;
|
|
23
24
|
validatePagesCollections(builder, items);
|
|
24
25
|
}
|
|
25
26
|
expect(...expectations) {
|
|
26
|
-
return new BuilderUI(this.builder, this.
|
|
27
|
+
return new BuilderUI(this.builder, this.parameters, this.items, [...this.expectations, ...expectations], this.references
|
|
27
28
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- type narrowing cast, validated at merge time
|
|
28
29
|
);
|
|
29
30
|
}
|
|
30
31
|
page(label, paths) {
|
|
31
|
-
return new BuilderUI(this.builder, this.
|
|
32
|
+
return new BuilderUI(this.builder, this.parameters, [...this.items, new BuilderUIPage(label, paths)], this.expectations, this.references);
|
|
32
33
|
}
|
|
33
34
|
describe(label, paths) {
|
|
34
|
-
return new BuilderUI(this.builder, this.
|
|
35
|
+
return new BuilderUI(this.builder, this.parameters, [...this.items, new BuilderUIDescribe(label, paths)], this.expectations, this.references);
|
|
35
36
|
}
|
|
36
37
|
pages(name, label, itemUI) {
|
|
37
|
-
const items =
|
|
38
|
-
return new BuilderUI(this.builder, this.
|
|
38
|
+
const items = isParameter(itemUI) ? itemUI : itemUI.items;
|
|
39
|
+
return new BuilderUI(this.builder, this.parameters, [...this.items, new BuilderUIPages(name, label, items)], this.expectations, this.references);
|
|
39
40
|
}
|
|
40
41
|
bind(bindings) {
|
|
41
42
|
return bindUI(this, bindings);
|
|
42
43
|
}
|
|
43
|
-
#label(label) {
|
|
44
|
-
return isRef(label) ? label : new BuilderUILabel(label);
|
|
45
|
-
}
|
|
46
44
|
}
|
|
47
45
|
export const BuilderUISchema = v.instance(BuilderUI);
|
|
48
46
|
export const BuilderUISerialisedSchema = serialisable(BuilderUI, v.object({
|
|
49
|
-
builder:
|
|
50
|
-
|
|
47
|
+
builder: paramable(v.lazy(() => BuilderSerialisedSchema)),
|
|
48
|
+
parameters: BuilderParametersSerialisedSchema,
|
|
51
49
|
items: BuilderUIItemsSerialisedSchema,
|
|
52
|
-
expectations: BuilderExpectationsSerialisedSchema
|
|
50
|
+
expectations: BuilderExpectationsSerialisedSchema,
|
|
51
|
+
references: BuilderReferencesSchema
|
|
53
52
|
}));
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import type { BuilderGeneric } from '../builder/index';
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
2
|
+
import type { BuilderUIParts } from './ui';
|
|
3
|
+
import type { BuilderUIItems } from './pages';
|
|
4
|
+
import { BuilderParameter } from '../../references.js';
|
|
4
5
|
import { BuilderUI } from './ui.js';
|
|
5
|
-
export declare function uis(): BuilderUI<
|
|
6
|
-
export declare function uis<const BuilderType extends BuilderGeneric>(uiBuilder: BuilderType, ...parts:
|
|
6
|
+
export declare function uis(): BuilderUI<BuilderParameter>;
|
|
7
|
+
export declare function uis<const BuilderType extends BuilderGeneric>(uiBuilder: BuilderType, ...parts: BuilderUIParts): BuilderUI<BuilderType>;
|
|
7
8
|
export declare function mergeUIParts(parts: ReadonlyArray<unknown>): {
|
|
8
|
-
|
|
9
|
+
parameters: BuilderParameter<string>[];
|
|
9
10
|
expectations: import("..").BuilderExpectation<string, unknown, "option" | "component" | "collection" | "detail">[];
|
|
11
|
+
references: Readonly<{
|
|
12
|
+
parameter: string;
|
|
13
|
+
id: string;
|
|
14
|
+
}>[];
|
|
10
15
|
};
|
|
16
|
+
export declare function flattenUIItems(items: ReadonlyArray<unknown>): BuilderUIItems;
|
package/dist/entities/ui/uis.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import * as v from 'valibot';
|
|
2
|
-
import {
|
|
2
|
+
import { BuilderParameter } from '../../references.js';
|
|
3
3
|
import { BuilderUI, BuilderUISchema } from './ui.js';
|
|
4
4
|
export function uis(uiBuilder, ...parts) {
|
|
5
|
-
const builder = uiBuilder ?? new
|
|
5
|
+
const builder = uiBuilder ?? new BuilderParameter('builder');
|
|
6
6
|
const merged = mergeUIParts(parts);
|
|
7
|
-
return new BuilderUI(builder, merged.
|
|
8
|
-
if (v.is(BuilderUISchema, part)) {
|
|
9
|
-
return [...part.items];
|
|
10
|
-
}
|
|
11
|
-
return [part];
|
|
12
|
-
}), merged.expectations);
|
|
7
|
+
return new BuilderUI(builder, merged.parameters, flattenUIItems(parts), merged.expectations, merged.references);
|
|
13
8
|
}
|
|
14
9
|
export function mergeUIParts(parts) {
|
|
15
10
|
const instances = parts.filter((part) => v.is(BuilderUISchema, part));
|
|
16
11
|
return {
|
|
17
|
-
|
|
18
|
-
expectations: instances.flatMap((instance) => [...instance.expectations])
|
|
12
|
+
parameters: instances.flatMap((instance) => [...instance.parameters]),
|
|
13
|
+
expectations: instances.flatMap((instance) => [...instance.expectations]),
|
|
14
|
+
references: instances.flatMap((instance) => [...instance.references])
|
|
19
15
|
};
|
|
20
16
|
}
|
|
17
|
+
export function flattenUIItems(items) {
|
|
18
|
+
return items.flatMap((item) => v.is(BuilderUISchema, item) ? [...item.items] : [item]);
|
|
19
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Paramable } from '../../references';
|
|
2
2
|
import type { BuilderGeneric } from '../builder/index';
|
|
3
3
|
import type { BuilderUIItems } from './pages';
|
|
4
4
|
export type BuilderErrorPagesUnknownCollection = {
|
|
5
5
|
readonly kind: 'pages-unknown-collection';
|
|
6
6
|
readonly name: string;
|
|
7
7
|
};
|
|
8
|
-
export declare function validatePagesCollections(builder:
|
|
8
|
+
export declare function validatePagesCollections(builder: Paramable<BuilderGeneric>, items: Paramable<BuilderUIItems>): void;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { BuilderException } from '../../exception.js';
|
|
2
|
-
import {
|
|
2
|
+
import { isParameter } from '../../references.js';
|
|
3
3
|
import { BuilderUIPages } from './pages.js';
|
|
4
4
|
export function validatePagesCollections(builder, items) {
|
|
5
|
-
if (
|
|
5
|
+
if (isParameter(builder) || isParameter(items)) {
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
8
8
|
const errors = items.flatMap((item) => {
|
|
9
|
-
if (
|
|
9
|
+
if (isParameter(item) || !(item instanceof BuilderUIPages)) {
|
|
10
10
|
return [];
|
|
11
11
|
}
|
|
12
12
|
const exists = builder.collections.some((entry) => entry.name === item.name);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { BuilderExpectation } from './expectation';
|
|
2
|
-
import type {
|
|
2
|
+
import type { BuilderParameter } from '../references';
|
|
3
3
|
import type { Builder, BuilderGeneric } from './builder/index';
|
|
4
4
|
import type { BuilderCollection, BuilderCollectionConfig } from './collection/index';
|
|
5
5
|
import type { BuilderComponent, BuilderComponentDetails } from './component/index';
|
|
6
6
|
import type { BuilderOption, BuilderSelectType, BuilderToggleType } from './option/index';
|
|
7
|
-
import type { BuilderUI, BuilderUIDescribe, BuilderUIGeneric, BuilderUIItem, BuilderUIItems,
|
|
8
|
-
export type Strip<T> = T extends
|
|
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
9
|
readonly [Key in keyof T]: Strip<T[Key]>;
|
|
10
10
|
} : T;
|
|
11
11
|
type StripEntry<Narrowed, Payload, GatePaths> = [Strip<Payload>] extends [never] ? never : [Strip<GatePaths>] extends [never] ? never : Narrowed;
|
package/dist/entities/when.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BuilderPath, BuilderPaths } from '../paths';
|
|
2
2
|
import type { BuilderPrimitive, BuilderPrimitives } from '../primitive';
|
|
3
|
-
import type {
|
|
3
|
+
import type { BuilderParameter, BuilderParameterSerialised, Paramable } from '../references';
|
|
4
4
|
import type { BuilderGeneric, BuilderState, BuilderStateOf } from './builder/index';
|
|
5
5
|
import * as v from 'valibot';
|
|
6
6
|
export type BuilderEnableConfig<Payload = unknown> = {
|
|
@@ -22,16 +22,16 @@ export type BuilderUnlessConfig<Payload = unknown, UnlessPath = BuilderPath> = {
|
|
|
22
22
|
export type BuilderWhen<Payload = unknown, MatchPath = BuilderPath, MatchSelectMap = Record<string, Payload | null>, UnlessPath = BuilderPath> = BuilderEnableConfig<Payload> | BuilderMatchConfig<Payload, MatchPath, MatchSelectMap> | BuilderUnlessConfig<Payload, UnlessPath>;
|
|
23
23
|
export type WhenSerialised<Payload> = {
|
|
24
24
|
readonly type: 'enable';
|
|
25
|
-
readonly payload: Payload |
|
|
25
|
+
readonly payload: Payload | BuilderParameterSerialised;
|
|
26
26
|
} | {
|
|
27
27
|
readonly type: 'match';
|
|
28
|
-
readonly matchPath:
|
|
29
|
-
readonly selectMap: Record<string, (Payload |
|
|
28
|
+
readonly matchPath: BuilderParameterSerialised | BuilderPath;
|
|
29
|
+
readonly selectMap: Record<string, (Payload | BuilderParameterSerialised) | null> | BuilderParameterSerialised;
|
|
30
30
|
} | {
|
|
31
31
|
readonly type: 'unless';
|
|
32
|
-
readonly unlessPath:
|
|
32
|
+
readonly unlessPath: BuilderParameterSerialised | BuilderPath;
|
|
33
33
|
readonly disabledValues: BuilderPrimitives;
|
|
34
|
-
readonly payload: Payload |
|
|
34
|
+
readonly payload: Payload | BuilderParameterSerialised;
|
|
35
35
|
};
|
|
36
36
|
export type WhenConfigPayload<Config extends BuilderWhenConfig, Payload> = Config extends {
|
|
37
37
|
readonly payload: infer Inner extends Payload;
|
|
@@ -42,37 +42,37 @@ export declare const BuilderWhenEnableSchema: v.ObjectSchema<{
|
|
|
42
42
|
export declare const BuilderWhenMatchSchema: v.ObjectSchema<{
|
|
43
43
|
readonly type: v.LiteralSchema<"match", undefined>;
|
|
44
44
|
readonly matchPath: v.SchemaWithPipe<readonly [v.UnionSchema<[v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
45
|
-
readonly type: v.LiteralSchema<"
|
|
45
|
+
readonly type: v.LiteralSchema<"parameter", undefined>;
|
|
46
46
|
readonly id: v.StringSchema<undefined>;
|
|
47
47
|
readonly name: v.StringSchema<undefined>;
|
|
48
48
|
}, undefined>, v.ReadonlyAction<{
|
|
49
|
-
type: "
|
|
49
|
+
type: "parameter";
|
|
50
50
|
id: string;
|
|
51
51
|
name: string;
|
|
52
|
-
}>]>, v.InstanceSchema<typeof
|
|
53
|
-
type: "
|
|
52
|
+
}>]>, v.InstanceSchema<typeof BuilderParameter, undefined>, v.SchemaWithPipe<readonly [v.ArraySchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, undefined>, v.ReadonlyAction<(string | number)[]>]>], undefined>, v.MetadataAction<readonly (string | number)[] | Readonly<{
|
|
53
|
+
type: "parameter";
|
|
54
54
|
id: string;
|
|
55
55
|
name: string;
|
|
56
|
-
}>, {
|
|
57
|
-
readonly
|
|
56
|
+
}> | BuilderParameter<string>, {
|
|
57
|
+
readonly paramable: v.SchemaWithPipe<readonly [v.ArraySchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, undefined>, v.ReadonlyAction<(string | number)[]>]>;
|
|
58
58
|
}>]>;
|
|
59
59
|
}, undefined>;
|
|
60
60
|
export declare const BuilderWhenUnlessSchema: v.ObjectSchema<{
|
|
61
61
|
readonly type: v.LiteralSchema<"unless", undefined>;
|
|
62
62
|
readonly unlessPath: v.SchemaWithPipe<readonly [v.UnionSchema<[v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
63
|
-
readonly type: v.LiteralSchema<"
|
|
63
|
+
readonly type: v.LiteralSchema<"parameter", undefined>;
|
|
64
64
|
readonly id: v.StringSchema<undefined>;
|
|
65
65
|
readonly name: v.StringSchema<undefined>;
|
|
66
66
|
}, undefined>, v.ReadonlyAction<{
|
|
67
|
-
type: "
|
|
67
|
+
type: "parameter";
|
|
68
68
|
id: string;
|
|
69
69
|
name: string;
|
|
70
|
-
}>]>, v.InstanceSchema<typeof
|
|
71
|
-
type: "
|
|
70
|
+
}>]>, v.InstanceSchema<typeof BuilderParameter, undefined>, v.SchemaWithPipe<readonly [v.ArraySchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, undefined>, v.ReadonlyAction<(string | number)[]>]>], undefined>, v.MetadataAction<readonly (string | number)[] | Readonly<{
|
|
71
|
+
type: "parameter";
|
|
72
72
|
id: string;
|
|
73
73
|
name: string;
|
|
74
|
-
}>, {
|
|
75
|
-
readonly
|
|
74
|
+
}> | BuilderParameter<string>, {
|
|
75
|
+
readonly paramable: v.SchemaWithPipe<readonly [v.ArraySchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, undefined>, v.ReadonlyAction<(string | number)[]>]>;
|
|
76
76
|
}>]>;
|
|
77
77
|
}, undefined>;
|
|
78
78
|
export declare const BuilderWhenConfigSchema: v.SchemaWithPipe<readonly [v.VariantSchema<"type", [v.ObjectSchema<{
|
|
@@ -80,71 +80,72 @@ export declare const BuilderWhenConfigSchema: v.SchemaWithPipe<readonly [v.Varia
|
|
|
80
80
|
}, undefined>, v.ObjectSchema<{
|
|
81
81
|
readonly type: v.LiteralSchema<"match", undefined>;
|
|
82
82
|
readonly matchPath: v.SchemaWithPipe<readonly [v.UnionSchema<[v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
83
|
-
readonly type: v.LiteralSchema<"
|
|
83
|
+
readonly type: v.LiteralSchema<"parameter", undefined>;
|
|
84
84
|
readonly id: v.StringSchema<undefined>;
|
|
85
85
|
readonly name: v.StringSchema<undefined>;
|
|
86
86
|
}, undefined>, v.ReadonlyAction<{
|
|
87
|
-
type: "
|
|
87
|
+
type: "parameter";
|
|
88
88
|
id: string;
|
|
89
89
|
name: string;
|
|
90
|
-
}>]>, v.InstanceSchema<typeof
|
|
91
|
-
type: "
|
|
90
|
+
}>]>, v.InstanceSchema<typeof BuilderParameter, undefined>, v.SchemaWithPipe<readonly [v.ArraySchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, undefined>, v.ReadonlyAction<(string | number)[]>]>], undefined>, v.MetadataAction<readonly (string | number)[] | Readonly<{
|
|
91
|
+
type: "parameter";
|
|
92
92
|
id: string;
|
|
93
93
|
name: string;
|
|
94
|
-
}>, {
|
|
95
|
-
readonly
|
|
94
|
+
}> | BuilderParameter<string>, {
|
|
95
|
+
readonly paramable: v.SchemaWithPipe<readonly [v.ArraySchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, undefined>, v.ReadonlyAction<(string | number)[]>]>;
|
|
96
96
|
}>]>;
|
|
97
97
|
}, undefined>, v.ObjectSchema<{
|
|
98
98
|
readonly type: v.LiteralSchema<"unless", undefined>;
|
|
99
99
|
readonly unlessPath: v.SchemaWithPipe<readonly [v.UnionSchema<[v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
100
|
-
readonly type: v.LiteralSchema<"
|
|
100
|
+
readonly type: v.LiteralSchema<"parameter", undefined>;
|
|
101
101
|
readonly id: v.StringSchema<undefined>;
|
|
102
102
|
readonly name: v.StringSchema<undefined>;
|
|
103
103
|
}, undefined>, v.ReadonlyAction<{
|
|
104
|
-
type: "
|
|
104
|
+
type: "parameter";
|
|
105
105
|
id: string;
|
|
106
106
|
name: string;
|
|
107
|
-
}>]>, v.InstanceSchema<typeof
|
|
108
|
-
type: "
|
|
107
|
+
}>]>, v.InstanceSchema<typeof BuilderParameter, undefined>, v.SchemaWithPipe<readonly [v.ArraySchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, undefined>, v.ReadonlyAction<(string | number)[]>]>], undefined>, v.MetadataAction<readonly (string | number)[] | Readonly<{
|
|
108
|
+
type: "parameter";
|
|
109
109
|
id: string;
|
|
110
110
|
name: string;
|
|
111
|
-
}>, {
|
|
112
|
-
readonly
|
|
111
|
+
}> | BuilderParameter<string>, {
|
|
112
|
+
readonly paramable: v.SchemaWithPipe<readonly [v.ArraySchema<v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, undefined>, v.ReadonlyAction<(string | number)[]>]>;
|
|
113
113
|
}>]>;
|
|
114
114
|
}, undefined>], undefined>, v.ReadonlyAction<{
|
|
115
115
|
type: "enable";
|
|
116
116
|
} | {
|
|
117
117
|
type: "match";
|
|
118
|
-
matchPath: readonly (string | number)[] |
|
|
119
|
-
type: "
|
|
118
|
+
matchPath: readonly (string | number)[] | Readonly<{
|
|
119
|
+
type: "parameter";
|
|
120
120
|
id: string;
|
|
121
121
|
name: string;
|
|
122
|
-
}>;
|
|
122
|
+
}> | BuilderParameter<string>;
|
|
123
123
|
} | {
|
|
124
124
|
type: "unless";
|
|
125
|
-
unlessPath: readonly (string | number)[] |
|
|
126
|
-
type: "
|
|
125
|
+
unlessPath: readonly (string | number)[] | Readonly<{
|
|
126
|
+
type: "parameter";
|
|
127
127
|
id: string;
|
|
128
128
|
name: string;
|
|
129
|
-
}>;
|
|
129
|
+
}> | BuilderParameter<string>;
|
|
130
130
|
}>]>;
|
|
131
131
|
export type BuilderWhenConfig = v.InferOutput<typeof BuilderWhenConfigSchema>;
|
|
132
|
+
export declare function createSelectMapSerialisedSchema(payloadSchema: v.GenericSchema): v.GenericSchema;
|
|
132
133
|
export declare function createWhenSerialisedSchema(payloadSchema: v.GenericSchema): v.GenericSchema;
|
|
133
134
|
export declare function createWhenFactories<Payload>(): {
|
|
134
|
-
enable: <const Values extends
|
|
135
|
-
match: <const MatchPayload extends
|
|
136
|
-
unless: <const Values extends
|
|
135
|
+
enable: <const Values extends Paramable<Payload>>(values: Values) => BuilderEnableConfig<Values>;
|
|
136
|
+
match: <const MatchPayload extends Paramable<Payload>, const MatchPath extends Paramable<BuilderPath>, const SelectMap extends Paramable<BuilderMatchSelectMap<Paramable<Payload>>>>(matchPath: MatchPath, selectMap: SelectMap) => BuilderMatchConfig<MatchPayload, MatchPath, SelectMap>;
|
|
137
|
+
unless: <const Values extends Paramable<Payload>, const UnlessPath extends Paramable<BuilderPath>>(unlessPath: UnlessPath, disabledValues: BuilderPrimitives, values: Values) => BuilderUnlessConfig<Values, UnlessPath>;
|
|
137
138
|
};
|
|
138
139
|
export type BuilderValidPath<State extends BuilderState> = ModelValidPath<State['model']>;
|
|
139
140
|
export type BuilderValidPaths<State extends BuilderState> = ReadonlyArray<BuilderValidPath<State>>;
|
|
140
|
-
export type BuilderValidPathsOf<Input extends
|
|
141
|
-
export type BuilderWhenConstrained<State extends BuilderState, Config> = Config extends
|
|
141
|
+
export type BuilderValidPathsOf<Input extends Paramable<BuilderGeneric>> = BuilderValidPaths<BuilderStateOf<Input>>;
|
|
142
|
+
export type BuilderWhenConstrained<State extends BuilderState, Config> = Config extends BuilderParameter ? Config : Config extends {
|
|
142
143
|
readonly type: 'match';
|
|
143
144
|
readonly matchPath: infer MatchPath extends BuilderPath;
|
|
144
145
|
readonly selectMap: infer SelectMap;
|
|
145
146
|
} ? Config & {
|
|
146
147
|
readonly matchPath: [MatchPath] extends [Readonly<BuilderValidPath<State>>] ? MatchPath : Readonly<BuilderValidPath<State>>;
|
|
147
|
-
readonly selectMap: SelectMap extends
|
|
148
|
+
readonly selectMap: SelectMap extends BuilderParameter ? SelectMap : Record<BuilderResolvePath<State['model'], MatchPath> & string, SelectMap[keyof SelectMap]>;
|
|
148
149
|
} : Config extends {
|
|
149
150
|
readonly type: 'unless';
|
|
150
151
|
readonly unlessPath: infer UnlessPath extends BuilderPath;
|
|
@@ -157,14 +158,14 @@ export type WhenConfigNullable<Config extends BuilderWhenConfig> = Config extend
|
|
|
157
158
|
readonly type: 'match';
|
|
158
159
|
readonly selectMap: infer SelectMap;
|
|
159
160
|
} ? null extends SelectMap[keyof SelectMap] ? null : never : never;
|
|
160
|
-
export type WhenNullability<State extends BuilderState, GatePaths extends
|
|
161
|
+
export type WhenNullability<State extends BuilderState, GatePaths extends Paramable<BuilderPaths>, Config extends Paramable<BuilderWhenConfig>> = [GatePaths] extends [BuilderParameter] ? null : WhenNullabilityFromPaths<State['model'], Extract<GatePaths, BuilderValidPaths<State>>, Config>;
|
|
161
162
|
type BuilderResolvePath<Model, Path extends BuilderPath> = Path extends readonly [
|
|
162
163
|
infer Head extends keyof Model & string
|
|
163
164
|
] ? Model[Head] : Path extends readonly [
|
|
164
165
|
infer Head extends keyof Model & string,
|
|
165
166
|
...infer Tail extends BuilderPath
|
|
166
167
|
] ? Model[Head] extends ReadonlyArray<infer Item> ? Tail extends readonly [number, ...infer Rest extends BuilderPath] ? BuilderResolvePath<Item, Rest> : never : BuilderResolvePath<Model[Head], Tail> : never;
|
|
167
|
-
type WhenNullabilityFromPaths<Model, GatePaths extends BuilderPaths, Config extends
|
|
168
|
+
type WhenNullabilityFromPaths<Model, GatePaths extends BuilderPaths, Config extends Paramable<BuilderWhenConfig>> = Config extends BuilderParameter ? WhenPathsNullable<Model, GatePaths> : Config extends BuilderWhenConfig ? WhenPathsNullable<Model, GatePaths> | WhenConfigNullable<Config> : never;
|
|
168
169
|
type WhenPathsNullable<Model, GatePaths extends BuilderPaths> = GatePaths extends readonly [
|
|
169
170
|
infer Head extends BuilderPath,
|
|
170
171
|
...infer Tail extends BuilderPaths
|
package/dist/entities/when.js
CHANGED
|
@@ -1,34 +1,37 @@
|
|
|
1
1
|
import * as v from 'valibot';
|
|
2
2
|
import { BuilderPathSchema } from '../paths.js';
|
|
3
3
|
import { BuilderPrimitivesSchema } from '../primitive.js';
|
|
4
|
-
import {
|
|
4
|
+
import { paramable } from '../references.js';
|
|
5
5
|
export const BuilderWhenEnableSchema = v.object({
|
|
6
6
|
type: v.literal('enable')
|
|
7
7
|
});
|
|
8
8
|
export const BuilderWhenMatchSchema = v.object({
|
|
9
9
|
type: v.literal('match'),
|
|
10
|
-
matchPath:
|
|
10
|
+
matchPath: paramable(BuilderPathSchema)
|
|
11
11
|
});
|
|
12
12
|
export const BuilderWhenUnlessSchema = v.object({
|
|
13
13
|
type: v.literal('unless'),
|
|
14
|
-
unlessPath:
|
|
14
|
+
unlessPath: paramable(BuilderPathSchema)
|
|
15
15
|
});
|
|
16
16
|
export const BuilderWhenConfigSchema = v.pipe(v.variant('type', [BuilderWhenEnableSchema, BuilderWhenMatchSchema, BuilderWhenUnlessSchema]), v.readonly());
|
|
17
|
+
export function createSelectMapSerialisedSchema(payloadSchema) {
|
|
18
|
+
return v.pipe(v.record(v.string(), v.nullable(paramable(payloadSchema))), v.readonly());
|
|
19
|
+
}
|
|
17
20
|
export function createWhenSerialisedSchema(payloadSchema) {
|
|
18
|
-
const
|
|
21
|
+
const paramablePayload = paramable(payloadSchema);
|
|
19
22
|
return v.pipe(v.variant('type', [
|
|
20
23
|
v.object({
|
|
21
24
|
...BuilderWhenEnableSchema.entries,
|
|
22
|
-
payload:
|
|
25
|
+
payload: paramablePayload
|
|
23
26
|
}),
|
|
24
27
|
v.object({
|
|
25
28
|
...BuilderWhenMatchSchema.entries,
|
|
26
|
-
selectMap:
|
|
29
|
+
selectMap: paramable(createSelectMapSerialisedSchema(payloadSchema))
|
|
27
30
|
}),
|
|
28
31
|
v.object({
|
|
29
32
|
...BuilderWhenUnlessSchema.entries,
|
|
30
33
|
disabledValues: BuilderPrimitivesSchema,
|
|
31
|
-
payload:
|
|
34
|
+
payload: paramablePayload
|
|
32
35
|
})
|
|
33
36
|
]), v.readonly());
|
|
34
37
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
export type { Builder, BuilderCollection, BuilderCollectionConfig, BuilderCollectionConfigSerialised, BuilderCollections, BuilderCollectionSerialised, BuilderCollectionsSerialised, BuilderCollectionWhen, BuilderCollectionWhenSerialised, BuilderComponent, BuilderComponentDetails, BuilderComponentDetailsSerialised, BuilderComponents, BuilderComponentSerialised, BuilderComponentsSerialised, BuilderComponentWhen, BuilderComponentWhenSerialised, BuilderDescription, BuilderDescriptionItem, BuilderErrorDuplicateName, BuilderErrorInvalidCollectionBounds, BuilderErrorInvalidGatePath, BuilderErrorPagesUnknownCollection, BuilderErrorUnboundParameter, BuilderErrorUnmetExpectation, BuilderExpectation, BuilderExpectationKind, BuilderExpectations, BuilderExpectationSerialised, BuilderExpectationsSerialised, BuilderGeneric, BuilderInstanceOf, BuilderOption, BuilderOptions, BuilderOptionSerialised, BuilderOptionsSerialised, BuilderOptionValues, BuilderOptionValuesSerialised, BuilderOptionWhen, BuilderOptionWhenSerialised,
|
|
1
|
+
export type { Builder, BuilderCollection, BuilderCollectionConfig, BuilderCollectionConfigSerialised, BuilderCollections, BuilderCollectionSerialised, BuilderCollectionsSerialised, BuilderCollectionWhen, BuilderCollectionWhenSerialised, BuilderComponent, BuilderComponentDetails, BuilderComponentDetailsSerialised, BuilderComponents, BuilderComponentSerialised, BuilderComponentsSerialised, BuilderComponentWhen, BuilderComponentWhenSerialised, BuilderDescription, BuilderDescriptionItem, BuilderErrorDuplicateName, BuilderErrorInvalidCollectionBounds, BuilderErrorInvalidGatePath, BuilderErrorPagesUnknownCollection, BuilderErrorUnboundParameter, BuilderErrorUnmetExpectation, BuilderExpectation, BuilderExpectationKind, BuilderExpectations, BuilderExpectationSerialised, BuilderExpectationsSerialised, BuilderGeneric, BuilderInstanceOf, BuilderOption, BuilderOptions, BuilderOptionSerialised, BuilderOptionsSerialised, BuilderOptionValues, BuilderOptionValuesSerialised, BuilderOptionWhen, BuilderOptionWhenSerialised, BuilderPart, BuilderParts, BuilderSelectType, BuilderSelectTypeLabels, BuilderSelectTypeSerialised, BuilderSelectTypeValues, BuilderSerialised, BuilderToggleType, BuilderToggleTypeSerialised, BuilderToggleValueType, BuilderUI, BuilderUIDescribe, BuilderUIDescribeSerialised, BuilderUIGeneric, BuilderUIItem, BuilderUIItems, BuilderUIItemsSerialised, BuilderUIPage, BuilderUIPages, BuilderUIPageSerialised, BuilderUIPagesSerialised, BuilderUIPart, BuilderUIParts, BuilderUISerialised, BuilderUIValidated, BuilderValidated, BuilderWhenConfig } from './entities/index';
|
|
2
|
+
export type { BuilderEntity, BuilderEntityKind } from './entities/index';
|
|
2
3
|
export type { BuilderError, BuilderErrors } from './exception';
|
|
3
|
-
export type { BuilderErrorInvalidCollection, BuilderErrorInvalidOption, BuilderErrorInvalidVariant, BuilderErrorMissingComponent, BuilderErrorMissingDetail, BuilderErrorMissingVariant, BuilderErrorUnexpectedComponent, BuilderErrorUnexpectedDetail, BuilderOrder, BuilderRenderOption, BuilderRenderOptions, BuilderRenderPage, BuilderRenderPages, BuilderRenderResult, BuilderRenderUpdate } from './mappers/index';
|
|
4
|
+
export type { BuilderErrorInvalidCollection, BuilderErrorInvalidOption, BuilderErrorInvalidVariant, BuilderErrorMissingComponent, BuilderErrorMissingDetail, BuilderErrorMissingVariant, BuilderErrorUnexpectedComponent, BuilderErrorUnexpectedDetail, BuilderOrder, BuilderRefEntities, BuilderRefEntity, BuilderRenderOption, BuilderRenderOptions, BuilderRenderPage, BuilderRenderPages, BuilderRenderResult, BuilderRenderUpdate } from './mappers/index';
|
|
4
5
|
export type { BuilderData, BuilderModel, BuilderModelInput, BuilderModels, BuilderVariant, BuilderVariants } from './model';
|
|
5
6
|
export type { BuilderPath, BuilderPaths } from './paths';
|
|
6
7
|
export type { BuilderPrimitive, BuilderPrimitives } from './primitive';
|
|
7
|
-
export type { BuilderRef,
|
|
8
|
+
export type { BuilderParameter, BuilderParameterSerialised, BuilderRef, BuilderReference, BuilderReferences, Paramable, ParamableSerialised } from './references';
|
|
8
9
|
import { builders, collectionConfig, collectionExpectation, componentDetails, componentExpectation, detailExpectation, optionExpectation, uis } from './entities/index.js';
|
|
9
10
|
import { createInstance, createModels } from './mappers/index.js';
|
|
10
11
|
export declare const builder: typeof builders;
|
|
11
12
|
export declare const collection: typeof collectionConfig & {
|
|
12
|
-
enable: <const Values extends import("./references").
|
|
13
|
-
match: <const MatchPayload extends import("./references").
|
|
14
|
-
unless: <const Values extends import("./references").
|
|
13
|
+
enable: <const Values extends import("./references").Paramable<import(".").BuilderCollectionConfig<import("./references").Paramable<import(".").BuilderGeneric>, import("./references").Paramable<number>, import("./references").Paramable<number>>>>(values: Values) => import("./entities/when").BuilderEnableConfig<Values>;
|
|
14
|
+
match: <const MatchPayload extends import("./references").Paramable<import(".").BuilderCollectionConfig<import("./references").Paramable<import(".").BuilderGeneric>, import("./references").Paramable<number>, import("./references").Paramable<number>>>, const MatchPath extends import("./references").Paramable<import("./paths").BuilderPath>, const SelectMap extends import("./references").Paramable<import("./entities/when").BuilderMatchSelectMap<import("./references").Paramable<import(".").BuilderCollectionConfig<import("./references").Paramable<import(".").BuilderGeneric>, import("./references").Paramable<number>, import("./references").Paramable<number>>>>>>(matchPath: MatchPath, selectMap: SelectMap) => import("./entities/when").BuilderMatchConfig<MatchPayload, MatchPath, SelectMap>;
|
|
15
|
+
unless: <const Values extends import("./references").Paramable<import(".").BuilderCollectionConfig<import("./references").Paramable<import(".").BuilderGeneric>, import("./references").Paramable<number>, import("./references").Paramable<number>>>, const UnlessPath extends import("./references").Paramable<import("./paths").BuilderPath>>(unlessPath: UnlessPath, disabledValues: import("./primitive").BuilderPrimitives, values: Values) => import("./entities/when").BuilderUnlessConfig<Values, UnlessPath>;
|
|
15
16
|
};
|
|
16
17
|
export declare const component: typeof componentDetails & {
|
|
17
|
-
enable: <const Payload extends import("./references").
|
|
18
|
-
match: <const Payload extends import("./references").
|
|
19
|
-
unless: <const UnlessPath extends import("./references").
|
|
18
|
+
enable: <const Payload extends import("./references").Paramable<import(".").BuilderComponentDetails>>(payload?: Payload) => import("./entities/when").BuilderEnableConfig<Payload>;
|
|
19
|
+
match: <const Payload extends import("./references").Paramable<import(".").BuilderComponentDetails>, const MatchPath extends import("./references").Paramable<import("./paths").BuilderPath>, const SelectMap extends import("./references").Paramable<import("./entities/when").BuilderMatchSelectMap<import("./references").Paramable<import(".").BuilderComponentDetails>>>>(matchPath: MatchPath, selectMap: SelectMap) => import("./entities/when").BuilderMatchConfig<Payload, MatchPath, SelectMap>;
|
|
20
|
+
unless: <const UnlessPath extends import("./references").Paramable<import("./paths").BuilderPath>, const Payload extends import("./references").Paramable<import(".").BuilderComponentDetails>>(unlessPath: UnlessPath, disabledValues: import("./primitive").BuilderPrimitives, payload?: Payload) => import("./entities/when").BuilderUnlessConfig<Payload, UnlessPath>;
|
|
20
21
|
};
|
|
21
22
|
export declare const has: {
|
|
22
23
|
collection: typeof collectionExpectation;
|
|
@@ -27,11 +28,15 @@ export declare const has: {
|
|
|
27
28
|
export declare const instance: typeof createInstance;
|
|
28
29
|
export declare const models: typeof createModels;
|
|
29
30
|
export declare const option: {
|
|
30
|
-
enable: <const Values extends import("./references").
|
|
31
|
-
match: <const MatchPayload extends import("./references").
|
|
32
|
-
unless: <const Values extends import("./references").
|
|
31
|
+
enable: <const Values extends import("./references").Paramable<import(".").BuilderSelectType<readonly [string, ...string[]], import("valibot").GenericSchema<string | null>> | import(".").BuilderToggleType<import("valibot").GenericSchema<string | number | boolean | null>>>>(values: Values) => import("./entities/when").BuilderEnableConfig<Values>;
|
|
32
|
+
match: <const MatchPayload extends import("./references").Paramable<import(".").BuilderSelectType<readonly [string, ...string[]], import("valibot").GenericSchema<string | null>> | import(".").BuilderToggleType<import("valibot").GenericSchema<string | number | boolean | null>>>, const MatchPath extends import("./references").Paramable<import("./paths").BuilderPath>, const SelectMap extends import("./references").Paramable<import("./entities/when").BuilderMatchSelectMap<import("./references").Paramable<import(".").BuilderSelectType<readonly [string, ...string[]], import("valibot").GenericSchema<string | null>> | import(".").BuilderToggleType<import("valibot").GenericSchema<string | number | boolean | null>>>>>>(matchPath: MatchPath, selectMap: SelectMap) => import("./entities/when").BuilderMatchConfig<MatchPayload, MatchPath, SelectMap>;
|
|
33
|
+
unless: <const Values extends import("./references").Paramable<import(".").BuilderSelectType<readonly [string, ...string[]], import("valibot").GenericSchema<string | null>> | import(".").BuilderToggleType<import("valibot").GenericSchema<string | number | boolean | null>>>, const UnlessPath extends import("./references").Paramable<import("./paths").BuilderPath>>(unlessPath: UnlessPath, disabledValues: import("./primitive").BuilderPrimitives, values: Values) => import("./entities/when").BuilderUnlessConfig<Values, UnlessPath>;
|
|
33
34
|
};
|
|
34
35
|
export declare const ui: typeof uis;
|
|
36
|
+
export { BuilderCollectionConfigSerialisedSchema, BuilderCollectionSelectMapSerialisedSchema, BuilderCollectionWhenSerialisedSchema, BuilderComponentDetailsSerialisedSchema, BuilderComponentSelectMapSerialisedSchema, BuilderComponentWhenSerialisedSchema, BuilderExpectationsSerialisedSchema, BuilderOptionSelectMapSerialisedSchema, BuilderOptionValuesSerialisedSchema, BuilderOptionWhenSerialisedSchema, BuilderSelectTypeSerialisedSchema, BuilderSerialisedSchema, BuilderToggleTypeSerialisedSchema, BuilderUIDescribeSerialisedSchema, BuilderUIItemSerialisedSchema, BuilderUIItemsSerialisedSchema, BuilderUIPageSerialisedSchema, BuilderUIPagesSerialisedSchema, BuilderUISerialisedSchema, deserialise, entitiesByKind, parameter, ref, select, serialise, toggleBoolean, toggleNumber, toggleString } from './entities/index.js';
|
|
35
37
|
export { BuilderException } from './exception.js';
|
|
36
|
-
export {
|
|
37
|
-
export { order, ordinal, render } from './mappers/index.js';
|
|
38
|
+
export { BuilderEntityKindSchema, BuilderEntitySchema } from './entities/index.js';
|
|
39
|
+
export { order, ordinal, refs, render } from './mappers/index.js';
|
|
40
|
+
export { BuilderVariantsSchema } from './model.js';
|
|
41
|
+
export { BuilderPathSchema, BuilderPathsSchema } from './paths.js';
|
|
42
|
+
export { isSerialisedParameter } from './references.js';
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,10 @@ export const instance = createInstance;
|
|
|
17
17
|
export const models = createModels;
|
|
18
18
|
export const option = optionWhen;
|
|
19
19
|
export const ui = uis;
|
|
20
|
+
export { BuilderCollectionConfigSerialisedSchema, BuilderCollectionSelectMapSerialisedSchema, BuilderCollectionWhenSerialisedSchema, BuilderComponentDetailsSerialisedSchema, BuilderComponentSelectMapSerialisedSchema, BuilderComponentWhenSerialisedSchema, BuilderExpectationsSerialisedSchema, BuilderOptionSelectMapSerialisedSchema, BuilderOptionValuesSerialisedSchema, BuilderOptionWhenSerialisedSchema, BuilderSelectTypeSerialisedSchema, BuilderSerialisedSchema, BuilderToggleTypeSerialisedSchema, BuilderUIDescribeSerialisedSchema, BuilderUIItemSerialisedSchema, BuilderUIItemsSerialisedSchema, BuilderUIPageSerialisedSchema, BuilderUIPagesSerialisedSchema, BuilderUISerialisedSchema, deserialise, entitiesByKind, parameter, ref, select, serialise, toggleBoolean, toggleNumber, toggleString } from './entities/index.js';
|
|
20
21
|
export { BuilderException } from './exception.js';
|
|
21
|
-
export {
|
|
22
|
-
export { order, ordinal, render } from './mappers/index.js';
|
|
22
|
+
export { BuilderEntityKindSchema, BuilderEntitySchema } from './entities/index.js';
|
|
23
|
+
export { order, ordinal, refs, render } from './mappers/index.js';
|
|
24
|
+
export { BuilderVariantsSchema } from './model.js';
|
|
25
|
+
export { BuilderPathSchema, BuilderPathsSchema } from './paths.js';
|
|
26
|
+
export { isSerialisedParameter } from './references.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as v from 'valibot';
|
|
2
2
|
import { BuilderCollectionConfigSchema, BuilderSerialisedSchema } from '../../entities/index.js';
|
|
3
3
|
import { BuilderException } from '../../exception.js';
|
|
4
|
-
import {
|
|
4
|
+
import { isParameter } from '../../references.js';
|
|
5
5
|
import { createWalkerValidation } from '../../walker/index.js';
|
|
6
6
|
import { collectExpectationErrors } from './expectation.js';
|
|
7
7
|
export function assertBuilder(builder) {
|
|
@@ -12,35 +12,35 @@ export function assertBuilder(builder) {
|
|
|
12
12
|
}
|
|
13
13
|
function collectBuilderErrors(builder) {
|
|
14
14
|
const expectationErrors = collectNestedBuilders(builder).flatMap((inner) => collectExpectationErrors(inner, inner.expectations));
|
|
15
|
-
const
|
|
16
|
-
const walkValidate = createWalkerValidation((
|
|
17
|
-
|
|
15
|
+
const parameterWalkErrors = [];
|
|
16
|
+
const walkValidate = createWalkerValidation((parameter) => {
|
|
17
|
+
parameterWalkErrors.push({ kind: 'unbound-parameter', name: parameter.name });
|
|
18
18
|
});
|
|
19
19
|
walkValidate(BuilderSerialisedSchema, builder);
|
|
20
|
-
const
|
|
21
|
-
.filter(
|
|
22
|
-
.map((
|
|
23
|
-
return [...expectationErrors, ...
|
|
20
|
+
const parameterErrors = builder.parameters
|
|
21
|
+
.filter(isParameter)
|
|
22
|
+
.map((parameter) => ({ kind: 'unbound-parameter', name: parameter.name }));
|
|
23
|
+
return [...expectationErrors, ...parameterErrors, ...parameterWalkErrors];
|
|
24
24
|
}
|
|
25
25
|
function collectNestedBuilders(builder) {
|
|
26
26
|
const nested = builder.collections.flatMap((collection) => nestedBuildersOf(collection.payload));
|
|
27
27
|
return [builder, ...nested.flatMap((inner) => collectNestedBuilders(inner))];
|
|
28
28
|
}
|
|
29
29
|
function nestedBuildersOf(payload) {
|
|
30
|
-
if (
|
|
30
|
+
if (isParameter(payload)) {
|
|
31
31
|
return [];
|
|
32
32
|
}
|
|
33
33
|
if (v.is(BuilderCollectionConfigSchema, payload)) {
|
|
34
|
-
return
|
|
34
|
+
return isParameter(payload.builder) ? [] : [payload.builder];
|
|
35
35
|
}
|
|
36
36
|
const whenPayload = payload;
|
|
37
37
|
if (whenPayload.type === 'match' && whenPayload.selectMap != null) {
|
|
38
|
-
return Object.values(whenPayload.selectMap).flatMap((value) => value && !
|
|
38
|
+
return Object.values(whenPayload.selectMap).flatMap((value) => value && !isParameter(value.builder) ? [value.builder] : []);
|
|
39
39
|
}
|
|
40
40
|
const inner = whenPayload.payload;
|
|
41
|
-
if (inner == null ||
|
|
41
|
+
if (inner == null || isParameter(inner)) {
|
|
42
42
|
return [];
|
|
43
43
|
}
|
|
44
44
|
const innerBuilder = inner.builder;
|
|
45
|
-
return
|
|
45
|
+
return isParameter(innerBuilder) ? [] : [innerBuilder];
|
|
46
46
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BuilderUISerialisedSchema } from '../../entities/index.js';
|
|
2
2
|
import { BuilderException } from '../../exception.js';
|
|
3
|
-
import {
|
|
3
|
+
import { isParameter } from '../../references.js';
|
|
4
4
|
import { createWalkerValidation } from '../../walker/index.js';
|
|
5
5
|
import { collectExpectationErrors } from './expectation.js';
|
|
6
6
|
export function assertUI(ui) {
|
|
@@ -11,11 +11,11 @@ export function assertUI(ui) {
|
|
|
11
11
|
}
|
|
12
12
|
function collectUIErrors(ui) {
|
|
13
13
|
const parameterErrors = [];
|
|
14
|
-
const walkValidate = createWalkerValidation((
|
|
15
|
-
parameterErrors.push({ kind: 'unbound-parameter', name:
|
|
14
|
+
const walkValidate = createWalkerValidation((parameter) => {
|
|
15
|
+
parameterErrors.push({ kind: 'unbound-parameter', name: parameter.name });
|
|
16
16
|
});
|
|
17
17
|
walkValidate(BuilderUISerialisedSchema, ui);
|
|
18
|
-
const expectationErrors =
|
|
18
|
+
const expectationErrors = isParameter(ui.builder)
|
|
19
19
|
? []
|
|
20
20
|
: collectExpectationErrors(ui.builder, ui.expectations);
|
|
21
21
|
return [...parameterErrors, ...expectationErrors];
|
package/dist/mappers/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export type { BuilderErrorInvalidCollection, BuilderErrorInvalidOption, BuilderErrorInvalidVariant, BuilderErrorMissingComponent, BuilderErrorMissingDetail, BuilderErrorMissingVariant, BuilderErrorUnexpectedComponent, BuilderErrorUnexpectedDetail } from './assert/index';
|
|
2
2
|
export type { BuilderOrder } from './order/index';
|
|
3
|
+
export type { BuilderRefEntities, BuilderRefEntity } from './refs';
|
|
3
4
|
export type { BuilderRenderOption, BuilderRenderOptions, BuilderRenderPage, BuilderRenderPages, BuilderRenderResult, BuilderRenderUpdate } from './render/index';
|
|
4
5
|
export { createInstance } from './instance/index.js';
|
|
5
6
|
export { createModels } from './models/index.js';
|
|
6
7
|
export { order } from './order/index.js';
|
|
8
|
+
export { refs } from './refs.js';
|
|
7
9
|
export { ordinal, render } from './render/index.js';
|