@builder-builder/builder 0.0.3 → 0.0.4
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/assert/assert.d.ts +6 -6
- package/dist/assert/assert.js +11 -11
- package/dist/assert/expectation.js +2 -2
- package/dist/check.d.ts +8 -0
- package/dist/check.js +18 -0
- package/dist/core/builder.d.ts +5 -3
- package/dist/core/builder.js +45 -21
- package/dist/core/collection/collection.d.ts +2 -2
- package/dist/core/collection/collection.js +4 -4
- package/dist/core/component/graph.d.ts +0 -3
- package/dist/core/component/graph.js +4 -7
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +1 -0
- package/dist/core/option/graph.js +5 -4
- package/dist/core/option/method.d.ts +60 -15
- package/dist/core/option/method.js +18 -4
- package/dist/core/option/option.d.ts +13 -7
- package/dist/core/option/option.js +16 -4
- package/dist/core/option/select.d.ts +6 -1
- package/dist/core/option/select.js +5 -1
- package/dist/core/parameter.d.ts +35 -0
- package/dist/core/parameter.js +25 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/paths.d.ts +2 -2
- package/dist/resolve/instance.d.ts +1 -1
- package/dist/resolve/order.d.ts +2 -2
- package/dist/schemas/index.d.ts +4 -4
- package/dist/schemas/index.js +2 -2
- package/dist/schemas/serialise.d.ts +936 -150
- package/dist/schemas/serialise.js +32 -31
- package/dist/serialise/deserialise.js +11 -6
- package/dist/serialise/serialise.js +12 -1
- package/dist/ui.d.ts +10 -12
- package/dist/ui.js +2 -2
- package/package.json +1 -1
- package/dist/invariant.d.ts +0 -1
- package/dist/invariant.js +0 -6
|
@@ -1,56 +1,57 @@
|
|
|
1
1
|
import * as v from 'valibot';
|
|
2
|
+
import { BuilderParameter } from '../core/parameter.js';
|
|
3
|
+
import { BuilderSelectType } from '../core/option/select.js';
|
|
4
|
+
import { BuilderToggleType } from '../core/option/toggle.js';
|
|
2
5
|
import { BuilderPathSchema, BuilderPathsSchema, BuilderPrimitiveSchema } from './primitives.js';
|
|
3
|
-
const
|
|
6
|
+
export const BuilderParameterSchema = v.instance(BuilderParameter);
|
|
7
|
+
export const BuilderOptionValuesSchema = v.union([
|
|
8
|
+
v.instance(BuilderSelectType),
|
|
9
|
+
v.instance(BuilderToggleType)
|
|
10
|
+
]);
|
|
11
|
+
export const BuilderOptionValuesMapSchema = v.record(v.string(), v.nullable(BuilderOptionValuesSchema));
|
|
12
|
+
export const BuilderSelectTypeSerialisedSchema = v.pipe(v.object({
|
|
4
13
|
type: v.literal('select'),
|
|
5
14
|
options: v.pipe(v.tupleWithRest([v.string()], v.string()), v.readonly()),
|
|
6
15
|
defaultValue: v.nullable(v.string()),
|
|
7
16
|
optional: v.boolean(),
|
|
8
17
|
labels: v.record(v.string(), v.string())
|
|
9
|
-
});
|
|
10
|
-
const
|
|
18
|
+
}), v.readonly());
|
|
19
|
+
export const BuilderToggleTypeSerialisedSchema = v.pipe(v.object({
|
|
11
20
|
type: v.literal('toggle'),
|
|
12
21
|
valueType: v.string(),
|
|
13
22
|
defaultValue: v.nullable(v.union([v.boolean(), v.string(), v.number()])),
|
|
14
23
|
optional: v.boolean()
|
|
15
|
-
});
|
|
16
|
-
export const
|
|
17
|
-
export const
|
|
18
|
-
export const
|
|
19
|
-
const BuilderSerialisedOptionEnableConfigObject = v.object({
|
|
24
|
+
}), v.readonly());
|
|
25
|
+
export const BuilderParameterSerialisedSchema = v.pipe(v.object({ type: v.literal('parameter') }), v.readonly());
|
|
26
|
+
export const BuilderValuesSerialisedSchema = v.pipe(v.variant('type', [BuilderSelectTypeSerialisedSchema, BuilderToggleTypeSerialisedSchema]), v.readonly());
|
|
27
|
+
export const BuilderOptionEnableConfigSerialisedSchema = v.pipe(v.object({
|
|
20
28
|
type: v.literal('enable'),
|
|
21
|
-
values: v.
|
|
22
|
-
});
|
|
23
|
-
const
|
|
29
|
+
values: v.union([BuilderValuesSerialisedSchema, BuilderParameterSerialisedSchema])
|
|
30
|
+
}), v.readonly());
|
|
31
|
+
export const BuilderOptionMatchConfigSerialisedSchema = v.pipe(v.object({
|
|
24
32
|
type: v.literal('match'),
|
|
25
33
|
matchPath: BuilderPathSchema,
|
|
26
|
-
selectMap: v.
|
|
27
|
-
|
|
28
|
-
|
|
34
|
+
selectMap: v.union([
|
|
35
|
+
v.record(v.string(), v.nullable(BuilderValuesSerialisedSchema)),
|
|
36
|
+
BuilderParameterSerialisedSchema
|
|
37
|
+
])
|
|
38
|
+
}), v.readonly());
|
|
39
|
+
export const BuilderOptionUnlessConfigSerialisedSchema = v.pipe(v.object({
|
|
29
40
|
type: v.literal('unless'),
|
|
30
41
|
unlessPath: BuilderPathSchema,
|
|
31
42
|
disabledValues: v.pipe(v.array(BuilderPrimitiveSchema), v.readonly()),
|
|
32
|
-
values: v.
|
|
33
|
-
});
|
|
34
|
-
export const BuilderOptionEnableConfigSerialisedSchema = v.pipe(BuilderSerialisedOptionEnableConfigObject, v.readonly());
|
|
35
|
-
export const BuilderOptionMatchConfigSerialisedSchema = v.pipe(BuilderSerialisedOptionMatchConfigObject, v.readonly());
|
|
36
|
-
export const BuilderOptionUnlessConfigSerialisedSchema = v.pipe(BuilderSerialisedOptionUnlessConfigObject, v.readonly());
|
|
43
|
+
values: v.union([BuilderValuesSerialisedSchema, BuilderParameterSerialisedSchema])
|
|
44
|
+
}), v.readonly());
|
|
37
45
|
export const BuilderOptionWhenConfigSerialisedSchema = v.pipe(v.variant('type', [
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
BuilderOptionEnableConfigSerialisedSchema,
|
|
47
|
+
BuilderOptionMatchConfigSerialisedSchema,
|
|
48
|
+
BuilderOptionUnlessConfigSerialisedSchema
|
|
41
49
|
]), v.readonly());
|
|
42
50
|
export const BuilderOptionSerialisedSchema = v.pipe(v.object({
|
|
43
51
|
name: v.string(),
|
|
44
|
-
values: v.
|
|
45
|
-
BuilderSerialisedSelectTypeObject,
|
|
46
|
-
BuilderSerialisedToggleTypeObject
|
|
47
|
-
]),
|
|
52
|
+
values: v.union([BuilderValuesSerialisedSchema, BuilderParameterSerialisedSchema]),
|
|
48
53
|
gatePaths: BuilderPathsSchema,
|
|
49
|
-
config: v.nullable(
|
|
50
|
-
BuilderSerialisedOptionEnableConfigObject,
|
|
51
|
-
BuilderSerialisedOptionMatchConfigObject,
|
|
52
|
-
BuilderSerialisedOptionUnlessConfigObject
|
|
53
|
-
]))
|
|
54
|
+
config: v.nullable(BuilderOptionWhenConfigSerialisedSchema)
|
|
54
55
|
}), v.readonly());
|
|
55
56
|
export const BuilderComponentSerialisedSchema = v.pipe(v.object({
|
|
56
57
|
name: v.string(),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as v from 'valibot';
|
|
2
|
-
import { BuilderCollection, BuilderComponent,
|
|
2
|
+
import { BuilderCollection, BuilderComponent, BuilderOption, Builder, BuilderParameter, BuilderSelectType, BuilderToggleType } from '../core/index.js';
|
|
3
3
|
import { BuilderSerialisedSchema, BuilderUIItemsSerialisedSchema } from '../schemas/index.js';
|
|
4
4
|
import { BuilderUI } from '../ui.js';
|
|
5
5
|
export const deserialise = {
|
|
@@ -16,10 +16,7 @@ function buildBuilder(data) {
|
|
|
16
16
|
const options = data.options.map(deserialiseOption);
|
|
17
17
|
const components = data.components.map(deserialiseComponent);
|
|
18
18
|
const collections = data.collections.map(deserialiseCollection);
|
|
19
|
-
|
|
20
|
-
const rebuiltComponentGraph = components.reduce((graph, component) => graph.add(component, rebuiltOptionGraph), new BuilderComponentGraph());
|
|
21
|
-
const collectionComponentGraphs = collections.map((collection) => collection.builder.componentGraph);
|
|
22
|
-
return new Builder(options, collections, components, rebuiltOptionGraph, BuilderComponentGraph.merge(rebuiltComponentGraph, ...collectionComponentGraphs));
|
|
19
|
+
return new Builder(options, collections, components);
|
|
23
20
|
}
|
|
24
21
|
function deserialiseOption(data) {
|
|
25
22
|
const values = deserialiseValues(data.values);
|
|
@@ -35,6 +32,9 @@ function deserialiseCollection(data) {
|
|
|
35
32
|
return new BuilderCollection(data.name, built, data.min, data.max, data.gatePaths, config);
|
|
36
33
|
}
|
|
37
34
|
function deserialiseValues(data) {
|
|
35
|
+
if (data.type === 'parameter') {
|
|
36
|
+
return new BuilderParameter();
|
|
37
|
+
}
|
|
38
38
|
if (data.type === 'select') {
|
|
39
39
|
const { optional, options, defaultValue, labels } = data;
|
|
40
40
|
const valueSchema = v.union(options.map((value) => v.literal(value)));
|
|
@@ -63,11 +63,16 @@ function deserialiseOptionWhenConfig(data) {
|
|
|
63
63
|
}
|
|
64
64
|
case 'match': {
|
|
65
65
|
const { matchPath, type } = data;
|
|
66
|
+
if ('type' in data.selectMap && data.selectMap.type === 'parameter') {
|
|
67
|
+
const parameter = new BuilderParameter();
|
|
68
|
+
return { type, matchPath, selectMap: parameter, values: parameter };
|
|
69
|
+
}
|
|
66
70
|
const selectMap = Object.fromEntries(Object.entries(data.selectMap).map(([key, value]) => [
|
|
67
71
|
key,
|
|
68
72
|
value ? deserialiseValues(value) : null
|
|
69
73
|
]));
|
|
70
|
-
|
|
74
|
+
const values = Object.values(selectMap).find((value) => value !== null);
|
|
75
|
+
return { type, matchPath, selectMap, values };
|
|
71
76
|
}
|
|
72
77
|
case 'unless': {
|
|
73
78
|
const { type, unlessPath, disabledValues } = data;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as v from 'valibot';
|
|
2
|
-
import { BuilderCollection, BuilderComponent, BuilderOption, BuilderSelectType } from '../core/index.js';
|
|
2
|
+
import { BuilderCollection, BuilderComponent, BuilderOption, BuilderParameter, BuilderSelectType } from '../core/index.js';
|
|
3
|
+
import { BuilderParameterSchema } from '../schemas/index.js';
|
|
3
4
|
export const serialise = {
|
|
4
5
|
builder: serialiseBuilder,
|
|
5
6
|
ui: serialiseUI
|
|
@@ -40,6 +41,9 @@ function serialiseCollection(collection) {
|
|
|
40
41
|
};
|
|
41
42
|
}
|
|
42
43
|
function serialiseValues(optionValues) {
|
|
44
|
+
if (v.is(BuilderParameterSchema, optionValues)) {
|
|
45
|
+
return { type: 'parameter' };
|
|
46
|
+
}
|
|
43
47
|
if (v.is(v.instance(BuilderSelectType), optionValues)) {
|
|
44
48
|
return {
|
|
45
49
|
type: 'select',
|
|
@@ -65,6 +69,13 @@ function serialiseOptionWhenConfig(config) {
|
|
|
65
69
|
return { type: 'enable', values: serialiseValues(config.values) };
|
|
66
70
|
}
|
|
67
71
|
case 'match': {
|
|
72
|
+
if (v.is(BuilderParameterSchema, config.selectMap)) {
|
|
73
|
+
return {
|
|
74
|
+
type: 'match',
|
|
75
|
+
matchPath: config.matchPath,
|
|
76
|
+
selectMap: { type: 'parameter' }
|
|
77
|
+
};
|
|
78
|
+
}
|
|
68
79
|
return {
|
|
69
80
|
type: 'match',
|
|
70
81
|
matchPath: config.matchPath,
|
package/dist/ui.d.ts
CHANGED
|
@@ -2,17 +2,15 @@ import type { BuilderModelPaths } from './paths';
|
|
|
2
2
|
import type { BuilderCollectionNamesOf, BuilderCollectionOf, BuilderGeneric } from './core/index';
|
|
3
3
|
import type { BuilderUIItems } from './schemas/index';
|
|
4
4
|
export type BuilderUIGeneric = BuilderUI<BuilderGeneric>;
|
|
5
|
-
export type BuilderUIFactory<
|
|
6
|
-
export type BuilderUIPart<
|
|
7
|
-
export type BuilderUIParts<
|
|
8
|
-
export declare class BuilderUI<
|
|
9
|
-
readonly builder:
|
|
5
|
+
export type BuilderUIFactory<Builder extends BuilderGeneric = BuilderGeneric> = (ui: BuilderUI<Builder>) => BuilderUIGeneric;
|
|
6
|
+
export type BuilderUIPart<Builder extends BuilderGeneric = BuilderGeneric> = BuilderUIGeneric | BuilderUIFactory<Builder>;
|
|
7
|
+
export type BuilderUIParts<Builder extends BuilderGeneric = BuilderGeneric> = ReadonlyArray<BuilderUIPart<Builder>>;
|
|
8
|
+
export declare class BuilderUI<Builder extends BuilderGeneric = BuilderGeneric> {
|
|
9
|
+
readonly builder: Builder;
|
|
10
10
|
readonly items: BuilderUIItems;
|
|
11
|
-
constructor(builder:
|
|
12
|
-
page(label: string | null, paths: BuilderModelPaths<
|
|
13
|
-
describe(label: string | null, paths: BuilderModelPaths<
|
|
14
|
-
collection<const Name extends BuilderCollectionNamesOf<
|
|
11
|
+
constructor(builder: Builder, items?: BuilderUIItems);
|
|
12
|
+
page(label: string | null, paths: BuilderModelPaths<Builder>): BuilderUI<Builder>;
|
|
13
|
+
describe(label: string | null, paths: BuilderModelPaths<Builder>): BuilderUI<Builder>;
|
|
14
|
+
collection<const Name extends BuilderCollectionNamesOf<Builder>>(name: Name, label: string, factory: BuilderUIFactory<BuilderCollectionOf<Builder, Name>['builder']>): BuilderUI<Builder>;
|
|
15
15
|
}
|
|
16
|
-
export declare function ui<const
|
|
17
|
-
type CollectionItemBuilder<BuilderInput extends BuilderGeneric, Name extends string> = BuilderCollectionOf<BuilderInput, Name>['builder'] extends BuilderGeneric ? BuilderCollectionOf<BuilderInput, Name>['builder'] : BuilderGeneric;
|
|
18
|
-
export {};
|
|
16
|
+
export declare function ui<const Builder extends BuilderGeneric>(builder: Builder, ...parts: BuilderUIParts<Builder>): BuilderUI<Builder>;
|
package/dist/ui.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as v from 'valibot';
|
|
2
|
-
import {
|
|
2
|
+
import { check } from './check.js';
|
|
3
3
|
export class BuilderUI {
|
|
4
4
|
builder;
|
|
5
5
|
items;
|
|
@@ -15,7 +15,7 @@ export class BuilderUI {
|
|
|
15
15
|
}
|
|
16
16
|
collection(name, label, factory) {
|
|
17
17
|
const foundCollection = this.builder.collections.find((entry) => entry.name === name);
|
|
18
|
-
|
|
18
|
+
check.truthy(foundCollection, `Collection '${name}' not found! ❌`);
|
|
19
19
|
const templateUI = new BuilderUI(foundCollection.builder);
|
|
20
20
|
const result = factory(templateUI);
|
|
21
21
|
return new BuilderUI(this.builder, [
|
package/package.json
CHANGED
package/dist/invariant.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function invariant<Input>(input: Input, message?: `${string}! ❌`): asserts input is Exclude<Input, null | undefined | '' | 0 | false>;
|