@builder-builder/builder 0.0.3 → 0.0.5
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/check.d.ts +8 -0
- package/dist/check.js +18 -0
- package/dist/core/builder.d.ts +31 -22
- package/dist/core/builder.js +73 -27
- package/dist/core/collection/collection.d.ts +9 -12
- package/dist/core/collection/collection.js +9 -27
- package/dist/core/collection/index.d.ts +1 -1
- package/dist/core/collection/method.d.ts +22 -43
- package/dist/core/component/component.d.ts +1 -4
- package/dist/core/component/graph.d.ts +0 -3
- package/dist/core/component/graph.js +7 -9
- package/dist/core/component/method.d.ts +7 -9
- package/dist/core/expectation.d.ts +39 -0
- package/dist/{assert → core}/expectation.js +3 -2
- package/dist/core/graph.d.ts +2 -1
- package/dist/core/graph.js +3 -1
- package/dist/core/index.d.ts +8 -4
- package/dist/core/index.js +3 -1
- package/dist/core/option/graph.js +7 -5
- package/dist/core/option/method.d.ts +60 -42
- package/dist/core/option/method.js +7 -3
- package/dist/core/option/option.d.ts +14 -7
- package/dist/core/option/option.js +15 -23
- package/dist/core/option/select.d.ts +6 -1
- package/dist/core/option/select.js +5 -1
- package/dist/core/parameter.d.ts +48 -0
- package/dist/core/parameter.js +31 -0
- package/dist/core/when/config.d.ts +20 -0
- package/dist/core/when/config.js +4 -0
- package/dist/core/when/constrain.d.ts +14 -0
- package/dist/core/when/index.d.ts +5 -0
- package/dist/core/when/index.js +2 -0
- package/dist/core/when/nullability.d.ts +18 -0
- package/dist/core/when/nullability.js +1 -0
- package/dist/core/when/resolve.d.ts +18 -0
- package/dist/core/when/resolve.js +22 -0
- package/dist/index.d.ts +7 -10
- package/dist/index.js +2 -3
- package/dist/{config.d.ts → model.d.ts} +1 -1
- package/dist/model.js +1 -0
- package/dist/paths.d.ts +4 -3
- package/dist/resolve/index.d.ts +2 -2
- package/dist/resolve/instance.d.ts +2 -2
- package/dist/resolve/models.d.ts +1 -1
- package/dist/resolve/order.d.ts +7 -6
- package/dist/resolve/render.d.ts +4 -4
- package/dist/resolve/render.js +49 -60
- package/dist/resolve/validate.d.ts +6 -5
- package/dist/resolve/validate.js +5 -4
- package/dist/schemas/index.d.ts +2 -6
- package/dist/schemas/index.js +1 -3
- package/dist/serialise/deserialise.js +11 -6
- package/dist/serialise/index.d.ts +2 -2
- package/dist/serialise/index.js +1 -1
- package/dist/{schemas/serialise.d.ts → serialise/schemas.d.ts} +1050 -242
- package/dist/{schemas/serialise.js → serialise/schemas.js} +47 -47
- package/dist/serialise/serialise.d.ts +1 -1
- package/dist/serialise/serialise.js +19 -2
- package/dist/ui.d.ts +12 -12
- package/dist/ui.js +23 -16
- package/package.json +1 -1
- package/dist/assert/assert.d.ts +0 -28
- package/dist/assert/assert.js +0 -28
- package/dist/assert/expectation.d.ts +0 -20
- package/dist/assert/index.d.ts +0 -3
- package/dist/assert/index.js +0 -2
- package/dist/invariant.d.ts +0 -1
- package/dist/invariant.js +0 -6
- package/dist/schemas/layout.d.ts +0 -52
- package/dist/schemas/layout.js +0 -6
- /package/dist/{config.js → core/when/constrain.js} +0 -0
package/dist/paths.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
export type { BuilderPath, BuilderPaths } from './schemas/index';
|
|
2
1
|
import type { BuilderGeneric, BuilderModelOf } from './core/index';
|
|
3
2
|
import type { BuilderPath, BuilderPrimitive } from './schemas/index';
|
|
3
|
+
export type { BuilderPath, BuilderPaths } from './schemas/index';
|
|
4
4
|
export type BuilderValidPath<Model, Depth extends ReadonlyArray<never> = []> = Depth['length'] extends 10 ? never : Model extends BuilderPrimitive | null ? never : Model extends ReadonlyArray<infer Item> ? [number] | [number, ...BuilderValidPath<Item, [...Depth, never]>] : {
|
|
5
|
-
[
|
|
5
|
+
[Key in keyof Model & string]: [Key] | (Model[Key] extends BuilderPrimitive | null ? never : [Key, ...BuilderValidPath<Model[Key], [...Depth, never]>]);
|
|
6
6
|
}[keyof Model & string];
|
|
7
|
-
export type
|
|
7
|
+
export type BuilderValidPaths<Model> = ReadonlyArray<BuilderValidPath<Model>>;
|
|
8
|
+
export type BuilderModelPaths<Builder extends BuilderGeneric> = BuilderValidPaths<BuilderModelOf<Builder>>;
|
|
8
9
|
export type BuilderResolvePath<Model, Path extends BuilderPath> = Path extends readonly [
|
|
9
10
|
infer Head extends keyof Model & string
|
|
10
11
|
] ? Model[Head] : Path extends readonly [
|
package/dist/resolve/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type { BuilderOrder } from './order';
|
|
2
|
-
export type {
|
|
2
|
+
export type { BuilderRenderOption, BuilderRenderOptions, BuilderRenderPage, BuilderRenderPages, BuilderRenderResult } from './render';
|
|
3
3
|
export type { BuilderDataValidated, BuilderErrorVariantInvalid, BuilderErrorComponentMissing, BuilderErrorVariantMissing, BuilderErrorComponentUnexpected, BuilderErrorValidate, BuilderErrorsValidate, BuilderValidateResult } from './validate';
|
|
4
|
-
export type { BuilderDescription, BuilderDescriptionItem
|
|
4
|
+
export type { BuilderDescription, BuilderDescriptionItem } from '../schemas/index';
|
|
5
5
|
export { instance } from './instance.js';
|
|
6
6
|
export { models } from './models.js';
|
|
7
7
|
export { order } from './order.js';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { BuilderGeneric, BuilderModelOf } from '../core/index';
|
|
2
|
-
import type {
|
|
3
|
-
export declare function instance<const
|
|
2
|
+
import type { BuilderModelInput } from '../model';
|
|
3
|
+
export declare function instance<const Builder extends BuilderGeneric>(builder: Builder, partial?: BuilderModelInput): BuilderModelOf<Builder>;
|
package/dist/resolve/models.d.ts
CHANGED
package/dist/resolve/order.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { Prettify } from '../prettify';
|
|
2
|
+
import type { BuilderModel, BuilderVariant } from '../model';
|
|
3
|
+
import type { CollectionShape } from '../core/collection/index';
|
|
4
|
+
import type { BuilderCollection, BuilderCollectionEntries, BuilderComponentEntries, BuilderComponentNamesOf, BuilderGeneric } from '../core/index';
|
|
3
5
|
import type { BuilderDataValidated } from './validate';
|
|
4
|
-
export type BuilderOrder<
|
|
6
|
+
export type BuilderOrder<Builder extends BuilderGeneric> = Builder extends {
|
|
5
7
|
readonly _components: infer Components extends BuilderComponentEntries;
|
|
6
8
|
readonly _collections: infer Collections extends BuilderCollectionEntries;
|
|
7
9
|
} ? Prettify<ComponentsOrder<Components> & CollectionsOrder<Collections>> : Record<string, unknown>;
|
|
8
|
-
export declare function order<const
|
|
9
|
-
import type { Prettify } from '../prettify';
|
|
10
|
+
export declare function order<const Builder extends BuilderGeneric>(builder: Builder, model: BuilderModel, componentModels: BuilderDataValidated): BuilderOrder<Builder>;
|
|
10
11
|
type ComponentsOrder<Components extends BuilderComponentEntries> = {
|
|
11
12
|
readonly [Name in BuilderComponentNamesOf<Components>]: BuilderVariant | null;
|
|
12
13
|
};
|
|
@@ -14,5 +15,5 @@ type CollectionsOrder<Collections extends BuilderCollectionEntries> = Collection
|
|
|
14
15
|
infer Head extends BuilderCollection,
|
|
15
16
|
...infer Tail extends BuilderCollectionEntries
|
|
16
17
|
] ? Record<Head['name'], CollectionOrderOf<Head>> & CollectionsOrder<Tail> : {};
|
|
17
|
-
type CollectionOrderOf<Input extends BuilderCollection> = Input extends BuilderCollection<any, infer CollectionRecipe extends BuilderGeneric, infer Min, infer Max> ?
|
|
18
|
+
type CollectionOrderOf<Input extends BuilderCollection> = Input extends BuilderCollection<any, infer CollectionRecipe extends BuilderGeneric, infer Min, infer Max> ? CollectionShape<BuilderOrder<CollectionRecipe>, Min, Max> : ReadonlyArray<Record<string, unknown>>;
|
|
18
19
|
export {};
|
package/dist/resolve/render.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { BuilderGeneric, BuilderOption } from '../core/index';
|
|
2
|
-
import type { BuilderModel } from '../
|
|
2
|
+
import type { BuilderModel } from '../model';
|
|
3
3
|
import type { BuilderDescription, BuilderUIItems, BuilderPrimitive } from '../schemas/index';
|
|
4
4
|
import { BuilderUI } from '../ui.js';
|
|
5
|
-
export type
|
|
5
|
+
export type BuilderRenderOption = {
|
|
6
6
|
readonly value: BuilderPrimitive | null;
|
|
7
7
|
update(model: BuilderModel, value: BuilderPrimitive | null): BuilderModel;
|
|
8
8
|
readonly option: BuilderOption;
|
|
9
9
|
};
|
|
10
|
-
export type
|
|
10
|
+
export type BuilderRenderOptions = ReadonlyArray<BuilderRenderOption>;
|
|
11
11
|
export type BuilderRenderPage = {
|
|
12
12
|
readonly label: string | null;
|
|
13
|
-
readonly options:
|
|
13
|
+
readonly options: BuilderRenderOptions;
|
|
14
14
|
};
|
|
15
15
|
export type BuilderRenderPages = ReadonlyArray<BuilderRenderPage>;
|
|
16
16
|
export type BuilderRenderResult = {
|
package/dist/resolve/render.js
CHANGED
|
@@ -33,7 +33,7 @@ export function render(rootBuilder, rootModel, input) {
|
|
|
33
33
|
}
|
|
34
34
|
if (item.type === 'page') {
|
|
35
35
|
const resolvedOptions = item.paths.flatMap((path) => {
|
|
36
|
-
const option =
|
|
36
|
+
const option = findPageOption(builder, model, path);
|
|
37
37
|
if (!option) {
|
|
38
38
|
return [];
|
|
39
39
|
}
|
|
@@ -61,7 +61,7 @@ export function render(rootBuilder, rootModel, input) {
|
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
63
|
const values = item.paths.flatMap((path) => {
|
|
64
|
-
const value =
|
|
64
|
+
const value = findOptionValue(builder, model, path);
|
|
65
65
|
if (value === MISSING || value == null) {
|
|
66
66
|
return [];
|
|
67
67
|
}
|
|
@@ -81,65 +81,71 @@ export function ordinal(index) {
|
|
|
81
81
|
return ordinals[index] ?? `${index + 1}`;
|
|
82
82
|
}
|
|
83
83
|
const MISSING = {};
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
84
|
+
const ordinals = [
|
|
85
|
+
'First',
|
|
86
|
+
'Second',
|
|
87
|
+
'Third',
|
|
88
|
+
'Fourth',
|
|
89
|
+
'Fifth',
|
|
90
|
+
'Sixth',
|
|
91
|
+
'Seventh',
|
|
92
|
+
'Eighth',
|
|
93
|
+
'Ninth',
|
|
94
|
+
'Tenth',
|
|
95
|
+
'Eleventh',
|
|
96
|
+
'Twelfth',
|
|
97
|
+
'Thirteenth',
|
|
98
|
+
'Fourteenth',
|
|
99
|
+
'Fifteenth'
|
|
100
|
+
];
|
|
101
|
+
function findPageOption(builder, model, path) {
|
|
102
|
+
const resolved = walkCollectionPath(builder, model, path);
|
|
103
|
+
if (!resolved) {
|
|
102
104
|
return null;
|
|
103
105
|
}
|
|
104
|
-
return
|
|
106
|
+
return resolved.builder.options.reduce((found, entry) => {
|
|
105
107
|
if (found) {
|
|
106
108
|
return found;
|
|
107
109
|
}
|
|
108
|
-
const
|
|
109
|
-
return
|
|
110
|
+
const option = entry.resolve(resolved.model);
|
|
111
|
+
return option?.name === resolved.optionName ? option : null;
|
|
110
112
|
}, null);
|
|
111
113
|
}
|
|
112
|
-
function
|
|
114
|
+
function findOptionValue(builder, model, path) {
|
|
115
|
+
const resolved = walkCollectionPath(builder, model, path);
|
|
116
|
+
if (!resolved) {
|
|
117
|
+
return MISSING;
|
|
118
|
+
}
|
|
119
|
+
const hasOption = resolved.builder.options.some((entry) => {
|
|
120
|
+
const option = entry.resolve(resolved.model);
|
|
121
|
+
return option?.name === resolved.optionName;
|
|
122
|
+
});
|
|
123
|
+
if (!hasOption) {
|
|
124
|
+
return MISSING;
|
|
125
|
+
}
|
|
126
|
+
return resolved.model[resolved.optionName];
|
|
127
|
+
}
|
|
128
|
+
function walkCollectionPath(builder, model, path) {
|
|
113
129
|
const optionName = path[path.length - 1];
|
|
114
|
-
const
|
|
130
|
+
const collectionPairs = path.slice(0, -1);
|
|
115
131
|
let currentBuilder = builder;
|
|
116
132
|
let currentModel = model;
|
|
117
|
-
for (let
|
|
133
|
+
for (let pairIndex = 0; pairIndex < collectionPairs.length; pairIndex += 2) {
|
|
118
134
|
if (!currentModel) {
|
|
119
|
-
return
|
|
135
|
+
return null;
|
|
120
136
|
}
|
|
121
|
-
const collection = findCollection(currentBuilder, currentModel,
|
|
137
|
+
const collection = findCollection(currentBuilder, currentModel, collectionPairs[pairIndex]);
|
|
122
138
|
if (!collection) {
|
|
123
|
-
return
|
|
139
|
+
return null;
|
|
124
140
|
}
|
|
125
141
|
currentBuilder = collection.builder;
|
|
126
142
|
const collectionModels = resolveCollectionModels(model, collection.name);
|
|
127
|
-
currentModel = collectionModels[
|
|
143
|
+
currentModel = collectionModels[collectionPairs[pairIndex + 1]];
|
|
128
144
|
}
|
|
129
145
|
if (!currentModel) {
|
|
130
|
-
return
|
|
131
|
-
}
|
|
132
|
-
let found = false;
|
|
133
|
-
currentBuilder.options.forEach((entry) => {
|
|
134
|
-
const option = entry.resolve(currentModel);
|
|
135
|
-
if (option && option.name === optionName) {
|
|
136
|
-
found = true;
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
if (!found) {
|
|
140
|
-
return MISSING;
|
|
146
|
+
return null;
|
|
141
147
|
}
|
|
142
|
-
return currentModel
|
|
148
|
+
return { builder: currentBuilder, model: currentModel, optionName };
|
|
143
149
|
}
|
|
144
150
|
function findCollection(builder, model, collectionName) {
|
|
145
151
|
return builder.collections.reduce((found, entry) => {
|
|
@@ -153,7 +159,7 @@ function findCollection(builder, model, collectionName) {
|
|
|
153
159
|
function setPath(container, path, value) {
|
|
154
160
|
const [head, ...tail] = path;
|
|
155
161
|
if (typeof head === 'number') {
|
|
156
|
-
const arrayContainer = container ? container : [];
|
|
162
|
+
const arrayContainer = container ? [...container] : [];
|
|
157
163
|
arrayContainer[head] = tail.length === 0 ? value : setPath(arrayContainer[head], tail, value);
|
|
158
164
|
return arrayContainer;
|
|
159
165
|
}
|
|
@@ -163,20 +169,3 @@ function setPath(container, path, value) {
|
|
|
163
169
|
[head]: tail.length === 0 ? value : setPath(objectContainer[head], tail, value)
|
|
164
170
|
};
|
|
165
171
|
}
|
|
166
|
-
const ordinals = [
|
|
167
|
-
'First',
|
|
168
|
-
'Second',
|
|
169
|
-
'Third',
|
|
170
|
-
'Fourth',
|
|
171
|
-
'Fifth',
|
|
172
|
-
'Sixth',
|
|
173
|
-
'Seventh',
|
|
174
|
-
'Eighth',
|
|
175
|
-
'Ninth',
|
|
176
|
-
'Tenth',
|
|
177
|
-
'Eleventh',
|
|
178
|
-
'Twelfth',
|
|
179
|
-
'Thirteenth',
|
|
180
|
-
'Fourteenth',
|
|
181
|
-
'Fifteenth'
|
|
182
|
-
];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BuilderData, BuilderModel } from '../
|
|
1
|
+
import type { BuilderData, BuilderModel } from '../model';
|
|
2
2
|
import type { BuilderGeneric } from '../core/index';
|
|
3
3
|
declare const validated: unique symbol;
|
|
4
4
|
export type BuilderDataValidated = BuilderData & {
|
|
@@ -25,8 +25,9 @@ export type BuilderErrorVariantInvalid = {
|
|
|
25
25
|
export type BuilderErrorValidate = BuilderErrorComponentMissing | BuilderErrorComponentUnexpected | BuilderErrorVariantMissing | BuilderErrorVariantInvalid;
|
|
26
26
|
export type BuilderErrorsValidate = ReadonlyArray<BuilderErrorValidate>;
|
|
27
27
|
export type BuilderValidateResult = readonly [BuilderDataValidated, BuilderErrorsValidate];
|
|
28
|
-
export declare
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
export declare const validate: typeof validateBuilder & {
|
|
29
|
+
strict: typeof validateStrict;
|
|
30
|
+
};
|
|
31
|
+
declare function validateBuilder(builder: BuilderGeneric, builderModels: BuilderData): BuilderValidateResult;
|
|
32
|
+
declare function validateStrict(builder: BuilderGeneric, builderModels: BuilderData): BuilderValidateResult;
|
|
32
33
|
export {};
|
package/dist/resolve/validate.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { models } from './models.js';
|
|
2
|
-
export
|
|
2
|
+
export const validate = Object.assign(validateBuilder, { strict: validateStrict });
|
|
3
|
+
function validateBuilder(builder, builderModels) {
|
|
3
4
|
const expected = models(builder);
|
|
4
5
|
let errors = [];
|
|
5
6
|
Object.entries(expected).forEach(([component, expectedModels]) => {
|
|
@@ -30,13 +31,13 @@ export function validate(builder, builderModels) {
|
|
|
30
31
|
});
|
|
31
32
|
return [builderModels, errors];
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
-
const [data, errors] =
|
|
34
|
+
function validateStrict(builder, builderModels) {
|
|
35
|
+
const [data, errors] = validateBuilder(builder, builderModels);
|
|
35
36
|
if (errors.length > 0) {
|
|
36
37
|
throw new ValidateException(errors);
|
|
37
38
|
}
|
|
38
39
|
return [data, []];
|
|
39
|
-
}
|
|
40
|
+
}
|
|
40
41
|
function sortedKey(model) {
|
|
41
42
|
const entries = Object.entries(model).filter(([, value]) => value != null);
|
|
42
43
|
return JSON.stringify(entries.sort(([keyA], [keyB]) => keyA.localeCompare(keyB)));
|
package/dist/schemas/index.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
export type { BuilderDescription, BuilderDescriptionItem } from './description';
|
|
2
2
|
export { BuilderDescriptionItemSchema, BuilderDescriptionSchema } from './description.js';
|
|
3
|
-
export type { BuilderLayout, BuilderLayoutOption, BuilderLayoutOptions, BuilderLayoutPage } from './layout';
|
|
4
|
-
export { BuilderLayoutOptionSchema, BuilderLayoutOptionsSchema, BuilderLayoutPageSchema, BuilderLayoutSchema } from './layout.js';
|
|
5
3
|
export type { BuilderPath, BuilderPaths, BuilderPrimitive, BuilderPrimitives } from './primitives';
|
|
6
4
|
export { BuilderPathSchema, BuilderPathsSchema, BuilderPrimitiveSchema, BuilderPrimitivesSchema } from './primitives.js';
|
|
7
|
-
export type {
|
|
8
|
-
export {
|
|
9
|
-
export type { BuilderUIDescribe, BuilderUICollection, BuilderUIItem, BuilderUIItems, BuilderUIPage } from './ui';
|
|
10
|
-
export { BuilderUIDescribeSchema, BuilderUICollectionSchema, BuilderUIItemSchema, BuilderUIItemsSchema, BuilderUIPageSchema } from './ui.js';
|
|
5
|
+
export type { BuilderUICollection, BuilderUIDescribe, BuilderUIItem, BuilderUIItems, BuilderUIPage } from './ui';
|
|
6
|
+
export { BuilderUICollectionSchema, BuilderUIDescribeSchema, BuilderUIItemSchema, BuilderUIItemsSchema, BuilderUIPageSchema } from './ui.js';
|
package/dist/schemas/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
export { BuilderDescriptionItemSchema, BuilderDescriptionSchema } from './description.js';
|
|
2
|
-
export { BuilderLayoutOptionSchema, BuilderLayoutOptionsSchema, BuilderLayoutPageSchema, BuilderLayoutSchema } from './layout.js';
|
|
3
2
|
export { BuilderPathSchema, BuilderPathsSchema, BuilderPrimitiveSchema, BuilderPrimitivesSchema } from './primitives.js';
|
|
4
|
-
export {
|
|
5
|
-
export { BuilderUIDescribeSchema, BuilderUICollectionSchema, BuilderUIItemSchema, BuilderUIItemsSchema, BuilderUIPageSchema } from './ui.js';
|
|
3
|
+
export { BuilderUICollectionSchema, BuilderUIDescribeSchema, BuilderUIItemSchema, BuilderUIItemsSchema, BuilderUIPageSchema } from './ui.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as v from 'valibot';
|
|
2
|
-
import { BuilderCollection, BuilderComponent,
|
|
3
|
-
import { BuilderSerialisedSchema, BuilderUIItemsSerialisedSchema } from '
|
|
2
|
+
import { BuilderCollection, BuilderComponent, BuilderExpectation, BuilderOption, Builder, BuilderParameter, BuilderSelectType, BuilderToggleType } from '../core/index.js';
|
|
3
|
+
import { BuilderSerialisedSchema, BuilderUIItemsSerialisedSchema } from './schemas.js';
|
|
4
4
|
import { BuilderUI } from '../ui.js';
|
|
5
5
|
export const deserialise = {
|
|
6
6
|
builder: deserialiseBuilder,
|
|
@@ -16,10 +16,8 @@ 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
|
-
const
|
|
20
|
-
|
|
21
|
-
const collectionComponentGraphs = collections.map((collection) => collection.builder.componentGraph);
|
|
22
|
-
return new Builder(options, collections, components, rebuiltOptionGraph, BuilderComponentGraph.merge(rebuiltComponentGraph, ...collectionComponentGraphs));
|
|
19
|
+
const expectations = data.expectations.map((expectation) => new BuilderExpectation(expectation.name, expectation.kind));
|
|
20
|
+
return new Builder(options, collections, components, expectations);
|
|
23
21
|
}
|
|
24
22
|
function deserialiseOption(data) {
|
|
25
23
|
const values = deserialiseValues(data.values);
|
|
@@ -35,6 +33,9 @@ function deserialiseCollection(data) {
|
|
|
35
33
|
return new BuilderCollection(data.name, built, data.min, data.max, data.gatePaths, config);
|
|
36
34
|
}
|
|
37
35
|
function deserialiseValues(data) {
|
|
36
|
+
if (data.type === 'parameter') {
|
|
37
|
+
return new BuilderParameter();
|
|
38
|
+
}
|
|
38
39
|
if (data.type === 'select') {
|
|
39
40
|
const { optional, options, defaultValue, labels } = data;
|
|
40
41
|
const valueSchema = v.union(options.map((value) => v.literal(value)));
|
|
@@ -63,6 +64,10 @@ function deserialiseOptionWhenConfig(data) {
|
|
|
63
64
|
}
|
|
64
65
|
case 'match': {
|
|
65
66
|
const { matchPath, type } = data;
|
|
67
|
+
if ('type' in data.selectMap && data.selectMap.type === 'parameter') {
|
|
68
|
+
const parameter = new BuilderParameter();
|
|
69
|
+
return { type, matchPath, selectMap: parameter };
|
|
70
|
+
}
|
|
66
71
|
const selectMap = Object.fromEntries(Object.entries(data.selectMap).map(([key, value]) => [
|
|
67
72
|
key,
|
|
68
73
|
value ? deserialiseValues(value) : null
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { BuilderCollectionSerialised, BuilderCollectionConfigSerialised, BuilderCollectionEnableConfigSerialised, BuilderCollectionMatchConfigSerialised, BuilderCollectionUnlessConfigSerialised, BuilderCollectionWhenConfigSerialised, BuilderComponentSerialised, BuilderOptionSerialised, BuilderOptionEnableConfigSerialised, BuilderOptionMatchConfigSerialised, BuilderOptionUnlessConfigSerialised, BuilderOptionWhenConfigSerialised, BuilderSerialised, BuilderSelectTypeSerialised, BuilderToggleTypeSerialised, BuilderUISerialised, BuilderUICollectionSerialised, BuilderUIDescribeSerialised, BuilderUIItemSerialised, BuilderUIItemsSerialised, BuilderUIPageSerialised, BuilderValuesSerialised } from '
|
|
2
|
-
export { BuilderCollectionConfigSerialisedSchema, BuilderCollectionEnableConfigSerialisedSchema, BuilderCollectionMatchConfigSerialisedSchema, BuilderCollectionSerialisedSchema, BuilderCollectionUnlessConfigSerialisedSchema, BuilderCollectionWhenConfigSerialisedSchema, BuilderComponentSerialisedSchema, BuilderOptionEnableConfigSerialisedSchema, BuilderOptionMatchConfigSerialisedSchema, BuilderOptionSerialisedSchema, BuilderOptionUnlessConfigSerialisedSchema, BuilderOptionWhenConfigSerialisedSchema, BuilderSerialisedSchema, BuilderSelectTypeSerialisedSchema, BuilderToggleTypeSerialisedSchema, BuilderUICollectionSerialisedSchema, BuilderUIDescribeSerialisedSchema, BuilderUIItemSerialisedSchema, BuilderUIItemsSerialisedSchema, BuilderUIPageSerialisedSchema, BuilderValuesSerialisedSchema } from '
|
|
1
|
+
export type { BuilderCollectionSerialised, BuilderCollectionConfigSerialised, BuilderCollectionEnableConfigSerialised, BuilderCollectionMatchConfigSerialised, BuilderCollectionUnlessConfigSerialised, BuilderCollectionWhenConfigSerialised, BuilderComponentSerialised, BuilderExpectationSerialised, BuilderOptionSerialised, BuilderOptionEnableConfigSerialised, BuilderOptionMatchConfigSerialised, BuilderOptionUnlessConfigSerialised, BuilderOptionWhenConfigSerialised, BuilderSerialised, BuilderSelectTypeSerialised, BuilderToggleTypeSerialised, BuilderUISerialised, BuilderUICollectionSerialised, BuilderUIDescribeSerialised, BuilderUIItemSerialised, BuilderUIItemsSerialised, BuilderUIPageSerialised, BuilderParameterSerialised, BuilderValuesSerialised } from './schemas';
|
|
2
|
+
export { BuilderCollectionConfigSerialisedSchema, BuilderCollectionEnableConfigSerialisedSchema, BuilderCollectionMatchConfigSerialisedSchema, BuilderCollectionSerialisedSchema, BuilderCollectionUnlessConfigSerialisedSchema, BuilderCollectionWhenConfigSerialisedSchema, BuilderComponentSerialisedSchema, BuilderExpectationSerialisedSchema, BuilderOptionEnableConfigSerialisedSchema, BuilderOptionMatchConfigSerialisedSchema, BuilderOptionSerialisedSchema, BuilderOptionUnlessConfigSerialisedSchema, BuilderOptionWhenConfigSerialisedSchema, BuilderSerialisedSchema, BuilderSelectTypeSerialisedSchema, BuilderToggleTypeSerialisedSchema, BuilderUICollectionSerialisedSchema, BuilderUIDescribeSerialisedSchema, BuilderUIItemSerialisedSchema, BuilderUIItemsSerialisedSchema, BuilderUIPageSerialisedSchema, BuilderValuesSerialisedSchema } from './schemas.js';
|
|
3
3
|
export { deserialise } from './deserialise.js';
|
|
4
4
|
export { serialise } from './serialise.js';
|
package/dist/serialise/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { BuilderCollectionConfigSerialisedSchema, BuilderCollectionEnableConfigSerialisedSchema, BuilderCollectionMatchConfigSerialisedSchema, BuilderCollectionSerialisedSchema, BuilderCollectionUnlessConfigSerialisedSchema, BuilderCollectionWhenConfigSerialisedSchema, BuilderComponentSerialisedSchema, BuilderOptionEnableConfigSerialisedSchema, BuilderOptionMatchConfigSerialisedSchema, BuilderOptionSerialisedSchema, BuilderOptionUnlessConfigSerialisedSchema, BuilderOptionWhenConfigSerialisedSchema, BuilderSerialisedSchema, BuilderSelectTypeSerialisedSchema, BuilderToggleTypeSerialisedSchema, BuilderUICollectionSerialisedSchema, BuilderUIDescribeSerialisedSchema, BuilderUIItemSerialisedSchema, BuilderUIItemsSerialisedSchema, BuilderUIPageSerialisedSchema, BuilderValuesSerialisedSchema } from '
|
|
1
|
+
export { BuilderCollectionConfigSerialisedSchema, BuilderCollectionEnableConfigSerialisedSchema, BuilderCollectionMatchConfigSerialisedSchema, BuilderCollectionSerialisedSchema, BuilderCollectionUnlessConfigSerialisedSchema, BuilderCollectionWhenConfigSerialisedSchema, BuilderComponentSerialisedSchema, BuilderExpectationSerialisedSchema, BuilderOptionEnableConfigSerialisedSchema, BuilderOptionMatchConfigSerialisedSchema, BuilderOptionSerialisedSchema, BuilderOptionUnlessConfigSerialisedSchema, BuilderOptionWhenConfigSerialisedSchema, BuilderSerialisedSchema, BuilderSelectTypeSerialisedSchema, BuilderToggleTypeSerialisedSchema, BuilderUICollectionSerialisedSchema, BuilderUIDescribeSerialisedSchema, BuilderUIItemSerialisedSchema, BuilderUIItemsSerialisedSchema, BuilderUIPageSerialisedSchema, BuilderValuesSerialisedSchema } from './schemas.js';
|
|
2
2
|
export { deserialise } from './deserialise.js';
|
|
3
3
|
export { serialise } from './serialise.js';
|