@builder-builder/builder 0.0.28 → 0.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bb.js +5 -6
- package/dist/client/schema.d.ts +49 -29
- package/dist/components/BuilderOption.svelte.d.ts +12 -12
- package/dist/components/BuilderOptionValueBoolean.svelte.d.ts +20 -0
- package/dist/components/BuilderOptionValueNumber.svelte.d.ts +21 -0
- package/dist/components/BuilderOptionValueSelect.svelte.d.ts +21 -0
- package/dist/components/BuilderOptionValueString.svelte.d.ts +21 -0
- package/dist/components/index.d.ts +8 -8
- package/dist/components/index.js +2479 -2435
- package/dist/components/index.min.js +3 -3
- package/dist/entities/collection/collection.d.ts +162 -372
- package/dist/entities/collection/collection.js +7 -4
- package/dist/entities/collection/{when.d.ts → condition.d.ts} +3 -4
- package/dist/entities/collection/condition.js +2 -0
- package/dist/entities/collection/config.d.ts +52 -70
- package/dist/entities/collection/index.d.ts +4 -4
- package/dist/entities/collection/index.js +2 -2
- package/dist/entities/component/component.d.ts +11 -23
- package/dist/entities/component/component.js +4 -4
- package/dist/entities/component/{when.d.ts → condition.d.ts} +3 -4
- package/dist/entities/component/{when.js → condition.js} +3 -9
- package/dist/entities/component/index.d.ts +4 -4
- package/dist/entities/component/index.js +2 -2
- package/dist/entities/{when.d.ts → condition.d.ts} +21 -34
- package/dist/entities/{when.js → condition.js} +20 -25
- package/dist/entities/expectation.d.ts +135 -3
- package/dist/entities/expectation.js +6 -2
- package/dist/entities/index.d.ts +8 -8
- package/dist/entities/index.js +4 -4
- package/dist/entities/kind.d.ts +1 -1
- package/dist/entities/kind.js +4 -5
- package/dist/entities/model/bind.d.ts +5 -5
- package/dist/entities/model/methods.d.ts +18 -27
- package/dist/entities/model/methods.js +4 -22
- package/dist/entities/model/model.d.ts +3 -1
- package/dist/entities/model/model.js +25 -27
- package/dist/entities/option/condition.d.ts +9 -0
- package/dist/entities/option/condition.js +2 -0
- package/dist/entities/option/config.d.ts +44 -69
- package/dist/entities/option/config.js +6 -6
- package/dist/entities/option/expectation.d.ts +6 -1
- package/dist/entities/option/expectation.js +2 -2
- package/dist/entities/option/index.d.ts +8 -8
- package/dist/entities/option/index.js +4 -4
- package/dist/entities/option/option.d.ts +171 -202
- package/dist/entities/option/option.js +4 -4
- package/dist/entities/option/select.d.ts +16 -43
- package/dist/entities/option/select.js +8 -31
- package/dist/entities/option/value.d.ts +73 -0
- package/dist/entities/option/value.js +99 -0
- package/dist/entities/references.d.ts +104 -64
- package/dist/entities/serialise.d.ts +147 -80
- package/dist/entities/serialise.js +26 -21
- package/dist/entities/ui/input.d.ts +1 -1
- package/dist/entities/validated.d.ts +1 -1
- package/dist/errors/errors.d.ts +8 -3
- package/dist/errors/errors.js +5 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/mappers/dependencies.js +4 -3
- package/dist/mappers/resolve.js +23 -22
- package/dist/mappers/variants/option-graph.js +1 -1
- package/dist/public.d.ts +17 -17
- package/dist/public.js +17 -9
- package/dist/validate/expectations.js +21 -3
- package/dist/validate/model.js +8 -11
- package/dist/validate/resolve.js +14 -18
- package/package.json +1 -1
- package/dist/components/BuilderOptionSelect.svelte.d.ts +0 -21
- package/dist/components/BuilderOptionToggleBoolean.svelte.d.ts +0 -20
- package/dist/components/BuilderOptionToggleNumber.svelte.d.ts +0 -21
- package/dist/components/BuilderOptionToggleString.svelte.d.ts +0 -21
- package/dist/entities/collection/when.js +0 -2
- package/dist/entities/option/toggle.d.ts +0 -45
- package/dist/entities/option/toggle.js +0 -71
- package/dist/entities/option/when.d.ts +0 -10
- package/dist/entities/option/when.js +0 -2
|
@@ -1,55 +1,28 @@
|
|
|
1
1
|
import type { BuilderTags } from '../tags';
|
|
2
2
|
import * as v from 'valibot';
|
|
3
|
-
export type
|
|
4
|
-
export type
|
|
5
|
-
export declare class BuilderSelectConfig<const
|
|
3
|
+
export type BuilderValueOptions = readonly [string, ...ReadonlyArray<string>];
|
|
4
|
+
export type BuilderValueOptionLabels<Options extends BuilderValueOptions> = Partial<Record<Options[number], string>>;
|
|
5
|
+
export declare class BuilderSelectConfig<const Options extends BuilderValueOptions = BuilderValueOptions, const ValueSchema extends v.GenericSchema<string | null> = v.GenericSchema<string | null>> {
|
|
6
6
|
#private;
|
|
7
7
|
readonly value: v.InferOutput<ValueSchema>;
|
|
8
|
-
readonly type: "
|
|
9
|
-
readonly
|
|
8
|
+
readonly type: "value";
|
|
9
|
+
readonly kind: "select";
|
|
10
|
+
readonly options: Options;
|
|
10
11
|
readonly valueSchema: ValueSchema;
|
|
11
12
|
readonly defaultValue: v.InferOutput<ValueSchema>;
|
|
12
13
|
readonly isOptional: boolean;
|
|
13
|
-
readonly optionLabels:
|
|
14
|
+
readonly optionLabels: BuilderValueOptionLabels<Options>;
|
|
14
15
|
readonly tags?: BuilderTags;
|
|
15
|
-
constructor(
|
|
16
|
-
default(newDefault: v.InferOutput<ValueSchema>): BuilderSelectConfig<
|
|
17
|
-
optional(): BuilderSelectConfig<
|
|
18
|
-
labels(optionLabels:
|
|
19
|
-
tag(...tags: Array<string>): BuilderSelectConfig<
|
|
16
|
+
constructor(options: Options, defaultValue: v.InferOutput<ValueSchema>, optional?: boolean, optionLabels?: BuilderValueOptionLabels<Options>, tags?: BuilderTags);
|
|
17
|
+
default(newDefault: v.InferOutput<ValueSchema>): BuilderSelectConfig<Options, ValueSchema>;
|
|
18
|
+
optional(): BuilderSelectConfig<Options, v.NullableSchema<ValueSchema, undefined>>;
|
|
19
|
+
labels(optionLabels: BuilderValueOptionLabels<Options>): BuilderSelectConfig<Options, ValueSchema>;
|
|
20
|
+
tag(...tags: Array<string>): BuilderSelectConfig<Options, ValueSchema>;
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
-
[K in keyof Values]: v.LiteralSchema<Values[K], undefined>;
|
|
23
|
-
}, undefined>;
|
|
24
|
-
export declare function select<const Values extends BuilderSelectConfigValues>(values: Values): BuilderSelectConfig<Values, SelectSchema<Values>>;
|
|
22
|
+
export declare function valueSelect<const Options extends BuilderValueOptions>(options: Options): BuilderSelectConfig<Options, SelectSchema<Options>>;
|
|
25
23
|
export declare const BuilderSelectConfigSchema: v.InstanceSchema<typeof BuilderSelectConfig, undefined>;
|
|
26
|
-
export declare const BuilderSelectConfigSerialisedSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
27
|
-
readonly type: v.LiteralSchema<"select", undefined>;
|
|
28
|
-
readonly options: v.SchemaWithPipe<readonly [v.TupleWithRestSchema<[v.StringSchema<undefined>], v.StringSchema<undefined>, undefined>, v.ReadonlyAction<[string, ...string[]]>]>;
|
|
29
|
-
readonly defaultValue: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
30
|
-
readonly isOptional: v.BooleanSchema<undefined>;
|
|
31
|
-
readonly optionLabels: v.RecordSchema<v.StringSchema<undefined>, v.StringSchema<undefined>, undefined>;
|
|
32
|
-
readonly tags: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>, undefined>, v.ReadonlyAction<string[]>]>, undefined>;
|
|
33
|
-
}, undefined>, v.ReadonlyAction<{
|
|
34
|
-
type: "select";
|
|
35
|
-
readonly options: readonly [string, ...string[]];
|
|
36
|
-
defaultValue: string | null;
|
|
37
|
-
isOptional: boolean;
|
|
38
|
-
optionLabels: {
|
|
39
|
-
[x: string]: string;
|
|
40
|
-
};
|
|
41
|
-
tags?: readonly string[] | undefined;
|
|
42
|
-
}>]>;
|
|
43
|
-
export type BuilderSelectConfigSerialised = v.InferOutput<typeof BuilderSelectConfigSerialisedSchema>;
|
|
44
24
|
export declare function selectValueSchema(options: ReadonlyArray<string>, optional: boolean): v.GenericSchema<string | null>;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
readonly defaultValue: string | null;
|
|
49
|
-
readonly isOptional: boolean;
|
|
50
|
-
readonly optionLabels: {
|
|
51
|
-
readonly [x: string]: string;
|
|
52
|
-
} & import("../../validate").BuilderValidatedBrand;
|
|
53
|
-
readonly tags?: readonly string[] | undefined;
|
|
54
|
-
}>;
|
|
25
|
+
type SelectSchema<Options extends BuilderValueOptions> = v.UnionSchema<{
|
|
26
|
+
[K in keyof Options]: v.LiteralSchema<Options[K], undefined>;
|
|
27
|
+
}, undefined>;
|
|
55
28
|
export {};
|
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
import * as v from 'valibot';
|
|
2
|
-
import { BooleanSchema, StringSchema } from '../../primitive.js';
|
|
3
|
-
import { createEntityValidator } from '../kind.js';
|
|
4
|
-
import { serialisable } from '../serialisable.js';
|
|
5
|
-
import { BuilderTagsSchema } from '../tags.js';
|
|
6
2
|
export class BuilderSelectConfig {
|
|
7
|
-
type = '
|
|
3
|
+
type = 'value';
|
|
4
|
+
kind = 'select';
|
|
8
5
|
options;
|
|
9
6
|
valueSchema;
|
|
10
7
|
defaultValue;
|
|
11
8
|
isOptional;
|
|
12
9
|
optionLabels;
|
|
13
10
|
tags;
|
|
14
|
-
constructor(
|
|
15
|
-
this.options =
|
|
16
|
-
this.valueSchema = selectValueSchema(
|
|
11
|
+
constructor(options, defaultValue, optional = false, optionLabels = {}, tags) {
|
|
12
|
+
this.options = options;
|
|
13
|
+
this.valueSchema = selectValueSchema(options, optional);
|
|
17
14
|
this.defaultValue = defaultValue;
|
|
18
15
|
this.isOptional = optional;
|
|
19
16
|
this.optionLabels = optionLabels;
|
|
@@ -37,32 +34,12 @@ export class BuilderSelectConfig {
|
|
|
37
34
|
return this.#next({ tags });
|
|
38
35
|
}
|
|
39
36
|
}
|
|
40
|
-
export function
|
|
41
|
-
const [defaultValue] =
|
|
42
|
-
return new BuilderSelectConfig(
|
|
37
|
+
export function valueSelect(options) {
|
|
38
|
+
const [defaultValue] = options;
|
|
39
|
+
return new BuilderSelectConfig(options, defaultValue, false);
|
|
43
40
|
}
|
|
44
41
|
export const BuilderSelectConfigSchema = v.instance(BuilderSelectConfig);
|
|
45
|
-
export const BuilderSelectConfigSerialisedSchema = serialisable(v.object({
|
|
46
|
-
type: v.literal('select'),
|
|
47
|
-
options: v.pipe(v.tupleWithRest([StringSchema], StringSchema), v.readonly()),
|
|
48
|
-
defaultValue: v.nullable(StringSchema),
|
|
49
|
-
isOptional: BooleanSchema,
|
|
50
|
-
optionLabels: v.record(StringSchema, StringSchema),
|
|
51
|
-
tags: v.optional(BuilderTagsSchema)
|
|
52
|
-
}));
|
|
53
42
|
export function selectValueSchema(options, optional) {
|
|
54
43
|
const baseSchema = v.union(options.map((value) => v.literal(value)));
|
|
55
44
|
return optional ? v.nullable(baseSchema) : baseSchema;
|
|
56
45
|
}
|
|
57
|
-
export const validateSelect = createEntityValidator('select', BuilderSelectConfigSerialisedSchema, (input, errors) => {
|
|
58
|
-
if (input.defaultValue != null && !input.options.includes(input.defaultValue)) {
|
|
59
|
-
errors.scope('defaultValue', () => errors.entityInvalidSelectDefault());
|
|
60
|
-
}
|
|
61
|
-
errors.scope('optionLabels', () => {
|
|
62
|
-
Object.keys(input.optionLabels).forEach((key) => {
|
|
63
|
-
if (!input.options.includes(key)) {
|
|
64
|
-
errors.scope(key, () => errors.entityInvalidSelectLabel());
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { BuilderPrimitive } from '../../primitive';
|
|
2
|
+
import type { BuilderTags } from '../tags';
|
|
3
|
+
import * as v from 'valibot';
|
|
4
|
+
export declare const BuilderValueKindSchema: v.PicklistSchema<["string", "boolean", "number", "select"], undefined>;
|
|
5
|
+
export type BuilderValueKind = v.InferOutput<typeof BuilderValueKindSchema>;
|
|
6
|
+
export declare class BuilderValueConfig<const ValueSchema extends v.GenericSchema<BuilderPrimitive> = v.GenericSchema<BuilderPrimitive>> {
|
|
7
|
+
#private;
|
|
8
|
+
readonly value: v.InferOutput<ValueSchema>;
|
|
9
|
+
readonly type: "value";
|
|
10
|
+
readonly kind: 'string' | 'boolean' | 'number';
|
|
11
|
+
readonly valueSchema: ValueSchema;
|
|
12
|
+
readonly defaultValue: v.InferOutput<ValueSchema>;
|
|
13
|
+
readonly isOptional: boolean;
|
|
14
|
+
readonly tags?: BuilderTags;
|
|
15
|
+
constructor(kind: 'string' | 'boolean' | 'number', defaultValue: v.InferOutput<ValueSchema>, optional?: boolean, tags?: BuilderTags);
|
|
16
|
+
default(newDefault: v.InferOutput<ValueSchema>): BuilderValueConfig<ValueSchema>;
|
|
17
|
+
optional(): BuilderValueConfig<v.NullableSchema<ValueSchema, undefined>>;
|
|
18
|
+
tag(...tags: Array<string>): BuilderValueConfig<ValueSchema>;
|
|
19
|
+
}
|
|
20
|
+
export declare function valueString(): BuilderValueConfig<v.StringSchema<undefined>>;
|
|
21
|
+
export declare function valueBoolean(): BuilderValueConfig<v.BooleanSchema<undefined>>;
|
|
22
|
+
export declare function valueNumber(): BuilderValueConfig<v.NumberSchema<undefined>>;
|
|
23
|
+
export declare const BuilderValueConfigSchema: v.InstanceSchema<typeof BuilderValueConfig, undefined>;
|
|
24
|
+
export declare const BuilderValueConfigSerialisedSchema: v.SchemaWithPipe<readonly [v.VariantSchema<"kind", [v.StrictObjectSchema<{
|
|
25
|
+
readonly kind: v.PicklistSchema<["string", "boolean", "number"], undefined>;
|
|
26
|
+
readonly type: v.LiteralSchema<"value", undefined>;
|
|
27
|
+
readonly defaultValue: v.NullableSchema<v.UnionSchema<[v.BooleanSchema<undefined>, v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, undefined>;
|
|
28
|
+
readonly isOptional: v.BooleanSchema<undefined>;
|
|
29
|
+
readonly tags: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>, undefined>, v.ReadonlyAction<string[]>]>, undefined>;
|
|
30
|
+
}, undefined>, v.StrictObjectSchema<{
|
|
31
|
+
readonly kind: v.LiteralSchema<"select", undefined>;
|
|
32
|
+
readonly options: v.SchemaWithPipe<readonly [v.TupleWithRestSchema<[v.StringSchema<undefined>], v.StringSchema<undefined>, undefined>, v.ReadonlyAction<[string, ...string[]]>]>;
|
|
33
|
+
readonly optionLabels: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.StringSchema<undefined>, undefined>, undefined>;
|
|
34
|
+
readonly type: v.LiteralSchema<"value", undefined>;
|
|
35
|
+
readonly defaultValue: v.NullableSchema<v.UnionSchema<[v.BooleanSchema<undefined>, v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, undefined>;
|
|
36
|
+
readonly isOptional: v.BooleanSchema<undefined>;
|
|
37
|
+
readonly tags: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>, undefined>, v.ReadonlyAction<string[]>]>, undefined>;
|
|
38
|
+
}, undefined>], undefined>, v.ReadonlyAction<{
|
|
39
|
+
kind: "string" | "number" | "boolean";
|
|
40
|
+
type: "value";
|
|
41
|
+
defaultValue: string | number | boolean | null;
|
|
42
|
+
isOptional: boolean;
|
|
43
|
+
tags?: readonly string[] | undefined;
|
|
44
|
+
} | {
|
|
45
|
+
kind: "select";
|
|
46
|
+
readonly options: readonly [string, ...string[]];
|
|
47
|
+
optionLabels?: {
|
|
48
|
+
[x: string]: string;
|
|
49
|
+
} | undefined;
|
|
50
|
+
type: "value";
|
|
51
|
+
defaultValue: string | number | boolean | null;
|
|
52
|
+
isOptional: boolean;
|
|
53
|
+
tags?: readonly string[] | undefined;
|
|
54
|
+
}>]>;
|
|
55
|
+
export type BuilderValueConfigSerialised = v.InferOutput<typeof BuilderValueConfigSerialisedSchema>;
|
|
56
|
+
export declare function valueKindSchema(kind: 'string' | 'boolean' | 'number', optional: boolean): v.GenericSchema;
|
|
57
|
+
export declare const validateValue: (input: unknown, references?: import("..").BuilderReferences, issues?: import("../../errors/errors").BuilderIssuesScope) => import("..").ValidationResult<{
|
|
58
|
+
readonly kind: "string" | "number" | "boolean";
|
|
59
|
+
readonly type: "value";
|
|
60
|
+
readonly defaultValue: string | number | boolean | null;
|
|
61
|
+
readonly isOptional: boolean;
|
|
62
|
+
readonly tags?: readonly string[] | undefined;
|
|
63
|
+
} | {
|
|
64
|
+
readonly kind: "select";
|
|
65
|
+
readonly options: readonly [string, ...string[]];
|
|
66
|
+
readonly optionLabels?: ({
|
|
67
|
+
readonly [x: string]: string;
|
|
68
|
+
} & import("../../validate").BuilderValidatedBrand) | undefined;
|
|
69
|
+
readonly type: "value";
|
|
70
|
+
readonly defaultValue: string | number | boolean | null;
|
|
71
|
+
readonly isOptional: boolean;
|
|
72
|
+
readonly tags?: readonly string[] | undefined;
|
|
73
|
+
}>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
import { check } from '../../errors/index.js';
|
|
3
|
+
import { BooleanSchema, NumberSchema, StringSchema } from '../../primitive.js';
|
|
4
|
+
import { createEntityValidator } from '../kind.js';
|
|
5
|
+
import { serialisable } from '../serialisable.js';
|
|
6
|
+
import { BuilderTagsSchema } from '../tags.js';
|
|
7
|
+
export const BuilderValueKindSchema = v.picklist(['string', 'boolean', 'number', 'select']);
|
|
8
|
+
export class BuilderValueConfig {
|
|
9
|
+
type = 'value';
|
|
10
|
+
kind;
|
|
11
|
+
valueSchema;
|
|
12
|
+
defaultValue;
|
|
13
|
+
isOptional;
|
|
14
|
+
tags;
|
|
15
|
+
constructor(kind, defaultValue, optional, tags) {
|
|
16
|
+
this.kind = kind;
|
|
17
|
+
this.valueSchema = valueKindSchema(kind, optional || false);
|
|
18
|
+
this.defaultValue = defaultValue;
|
|
19
|
+
this.isOptional = optional || false;
|
|
20
|
+
this.tags = tags;
|
|
21
|
+
}
|
|
22
|
+
#next(patch) {
|
|
23
|
+
return new BuilderValueConfig(this.kind, 'defaultValue' in patch
|
|
24
|
+
? patch.defaultValue
|
|
25
|
+
: this.defaultValue, patch.optional ?? this.isOptional, patch.tags ?? this.tags);
|
|
26
|
+
}
|
|
27
|
+
default(newDefault) {
|
|
28
|
+
return this.#next({ defaultValue: newDefault });
|
|
29
|
+
}
|
|
30
|
+
optional() {
|
|
31
|
+
return this.#next({ optional: true });
|
|
32
|
+
}
|
|
33
|
+
tag(...tags) {
|
|
34
|
+
return this.#next({ tags });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function valueString() {
|
|
38
|
+
return new BuilderValueConfig('string', '');
|
|
39
|
+
}
|
|
40
|
+
export function valueBoolean() {
|
|
41
|
+
return new BuilderValueConfig('boolean', false);
|
|
42
|
+
}
|
|
43
|
+
export function valueNumber() {
|
|
44
|
+
return new BuilderValueConfig('number', 0);
|
|
45
|
+
}
|
|
46
|
+
export const BuilderValueConfigSchema = v.instance(BuilderValueConfig);
|
|
47
|
+
const valueConfigSerialisedFields = {
|
|
48
|
+
type: v.literal('value'),
|
|
49
|
+
defaultValue: v.nullable(v.union([BooleanSchema, StringSchema, NumberSchema])),
|
|
50
|
+
isOptional: BooleanSchema,
|
|
51
|
+
tags: v.optional(BuilderTagsSchema)
|
|
52
|
+
};
|
|
53
|
+
// The wire shape mirrors the authoring split: `options`/`optionLabels` live only on a `select`, and
|
|
54
|
+
// a `select` must carry `options`. So a hand-built object can't put options on a plain value, nor omit
|
|
55
|
+
// them from a select — the same guarantee the two config classes give, enforced at validation too.
|
|
56
|
+
export const BuilderValueConfigSerialisedSchema = serialisable(v.variant('kind', [
|
|
57
|
+
v.strictObject({
|
|
58
|
+
...valueConfigSerialisedFields,
|
|
59
|
+
kind: v.picklist(['string', 'boolean', 'number'])
|
|
60
|
+
}),
|
|
61
|
+
v.strictObject({
|
|
62
|
+
...valueConfigSerialisedFields,
|
|
63
|
+
kind: v.literal('select'),
|
|
64
|
+
options: v.pipe(v.tupleWithRest([StringSchema], StringSchema), v.readonly()),
|
|
65
|
+
optionLabels: v.optional(v.record(StringSchema, StringSchema))
|
|
66
|
+
})
|
|
67
|
+
]));
|
|
68
|
+
export function valueKindSchema(kind, optional) {
|
|
69
|
+
const kindSchemas = {
|
|
70
|
+
string: StringSchema,
|
|
71
|
+
boolean: BooleanSchema,
|
|
72
|
+
number: NumberSchema
|
|
73
|
+
};
|
|
74
|
+
const baseSchema = kindSchemas[kind];
|
|
75
|
+
return optional ? v.nullable(baseSchema) : baseSchema;
|
|
76
|
+
}
|
|
77
|
+
export const validateValue = createEntityValidator('value', BuilderValueConfigSerialisedSchema, (input, errors) => {
|
|
78
|
+
if (input.kind === 'select') {
|
|
79
|
+
const options = input.options;
|
|
80
|
+
if (input.defaultValue != null && !options.includes(`${input.defaultValue}`)) {
|
|
81
|
+
errors.scope('defaultValue', () => errors.entityInvalidSelectDefault());
|
|
82
|
+
}
|
|
83
|
+
errors.scope('optionLabels', () => {
|
|
84
|
+
Object.keys(input.optionLabels ?? {}).forEach((key) => {
|
|
85
|
+
if (!options.includes(key)) {
|
|
86
|
+
errors.scope(key, () => errors.entityInvalidSelectLabel());
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (input.defaultValue == null) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const valueSchema = valueKindSchema(input.kind, input.isOptional);
|
|
96
|
+
if (!check.is(valueSchema, input.defaultValue)) {
|
|
97
|
+
errors.scope('defaultValue', () => errors.entityInvalidValueDefault());
|
|
98
|
+
}
|
|
99
|
+
});
|
|
@@ -2,55 +2,58 @@ import * as v from 'valibot';
|
|
|
2
2
|
export declare const BuilderReferenceSchema: v.ObjectSchema<{
|
|
3
3
|
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
4
4
|
readonly serialised: v.GenericSchema<string | number | boolean | readonly (string | number)[] | readonly (readonly (string | number)[])[] | import("./index.js").BuilderSerialised | import("./index.js").BuilderModelSerialised | Readonly<{
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
defaultValue: string | null;
|
|
5
|
+
kind: "string" | "number" | "boolean";
|
|
6
|
+
type: "value";
|
|
7
|
+
defaultValue: string | number | boolean | null;
|
|
8
8
|
isOptional: boolean;
|
|
9
|
-
optionLabels: {
|
|
10
|
-
[x: string]: string;
|
|
11
|
-
};
|
|
12
9
|
tags?: readonly string[] | undefined;
|
|
13
10
|
}> | Readonly<{
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
kind: "select";
|
|
12
|
+
readonly options: readonly [string, ...string[]];
|
|
13
|
+
optionLabels?: {
|
|
14
|
+
[x: string]: string;
|
|
15
|
+
} | undefined;
|
|
16
|
+
type: "value";
|
|
16
17
|
defaultValue: string | number | boolean | null;
|
|
17
18
|
isOptional: boolean;
|
|
18
19
|
tags?: readonly string[] | undefined;
|
|
19
|
-
}> | import("./
|
|
20
|
+
}> | import("./condition.js").BuilderMatchSelectMap<Readonly<{
|
|
20
21
|
type: "parameter";
|
|
21
22
|
id: string;
|
|
22
23
|
name: string;
|
|
23
|
-
}> | Readonly<
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
defaultValue: string | null;
|
|
24
|
+
}> | Readonly<{
|
|
25
|
+
kind: "string" | "number" | "boolean";
|
|
26
|
+
type: "value";
|
|
27
|
+
defaultValue: string | number | boolean | null;
|
|
27
28
|
isOptional: boolean;
|
|
28
|
-
|
|
29
|
+
tags?: readonly string[] | undefined;
|
|
30
|
+
}> | Readonly<{
|
|
31
|
+
kind: "select";
|
|
32
|
+
readonly options: readonly [string, ...string[]];
|
|
33
|
+
optionLabels?: {
|
|
29
34
|
[x: string]: string;
|
|
30
|
-
};
|
|
35
|
+
} | undefined;
|
|
36
|
+
type: "value";
|
|
37
|
+
defaultValue: string | number | boolean | null;
|
|
38
|
+
isOptional: boolean;
|
|
31
39
|
tags?: readonly string[] | undefined;
|
|
32
|
-
}>> |
|
|
33
|
-
type: "toggle";
|
|
40
|
+
}>> | import("./condition.js").BuilderConditionSerialised<Readonly<{
|
|
34
41
|
kind: "string" | "number" | "boolean";
|
|
42
|
+
type: "value";
|
|
35
43
|
defaultValue: string | number | boolean | null;
|
|
36
44
|
isOptional: boolean;
|
|
37
45
|
tags?: readonly string[] | undefined;
|
|
38
|
-
}
|
|
39
|
-
|
|
46
|
+
}> | Readonly<{
|
|
47
|
+
kind: "select";
|
|
40
48
|
readonly options: readonly [string, ...string[]];
|
|
41
|
-
|
|
42
|
-
isOptional: boolean;
|
|
43
|
-
optionLabels: {
|
|
49
|
+
optionLabels?: {
|
|
44
50
|
[x: string]: string;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
}>> | Readonly<Readonly<{
|
|
48
|
-
type: "toggle";
|
|
49
|
-
kind: "string" | "number" | "boolean";
|
|
51
|
+
} | undefined;
|
|
52
|
+
type: "value";
|
|
50
53
|
defaultValue: string | number | boolean | null;
|
|
51
54
|
isOptional: boolean;
|
|
52
55
|
tags?: readonly string[] | undefined;
|
|
53
|
-
}
|
|
56
|
+
}>> | Readonly<{
|
|
54
57
|
details: Readonly<{
|
|
55
58
|
type: "parameter";
|
|
56
59
|
id: string;
|
|
@@ -66,7 +69,7 @@ export declare const BuilderReferenceSchema: v.ObjectSchema<{
|
|
|
66
69
|
tags?: readonly string[] | undefined;
|
|
67
70
|
}>[];
|
|
68
71
|
tags?: readonly string[] | undefined;
|
|
69
|
-
}> | import("./
|
|
72
|
+
}> | import("./condition.js").BuilderMatchSelectMap<Readonly<{
|
|
70
73
|
type: "parameter";
|
|
71
74
|
id: string;
|
|
72
75
|
name: string;
|
|
@@ -86,7 +89,7 @@ export declare const BuilderReferenceSchema: v.ObjectSchema<{
|
|
|
86
89
|
tags?: readonly string[] | undefined;
|
|
87
90
|
}>[];
|
|
88
91
|
tags?: readonly string[] | undefined;
|
|
89
|
-
}>> | import("./
|
|
92
|
+
}>> | import("./condition.js").BuilderConditionSerialised<Readonly<{
|
|
90
93
|
details: Readonly<{
|
|
91
94
|
type: "parameter";
|
|
92
95
|
id: string;
|
|
@@ -128,7 +131,7 @@ export declare const BuilderReferenceSchema: v.ObjectSchema<{
|
|
|
128
131
|
id: string;
|
|
129
132
|
}>;
|
|
130
133
|
tags?: readonly string[] | undefined;
|
|
131
|
-
}> | import("./
|
|
134
|
+
}> | import("./condition.js").BuilderMatchSelectMap<Readonly<{
|
|
132
135
|
type: "parameter";
|
|
133
136
|
id: string;
|
|
134
137
|
name: string;
|
|
@@ -158,7 +161,7 @@ export declare const BuilderReferenceSchema: v.ObjectSchema<{
|
|
|
158
161
|
id: string;
|
|
159
162
|
}>;
|
|
160
163
|
tags?: readonly string[] | undefined;
|
|
161
|
-
}>> | import("./
|
|
164
|
+
}>> | import("./condition.js").BuilderConditionSerialised<Readonly<{
|
|
162
165
|
model: Readonly<{
|
|
163
166
|
type: "parameter";
|
|
164
167
|
id: string;
|
|
@@ -381,61 +384,81 @@ export declare const BuilderReferenceSchema: v.ObjectSchema<{
|
|
|
381
384
|
}> | import("./index.js").BuilderUIItemSerialised)[] | import("./index.js").BuilderPricingSerialised | import("./index.js").BuilderRates | readonly Readonly<{
|
|
382
385
|
name: string;
|
|
383
386
|
kind: "option" | "component" | "collection";
|
|
387
|
+
payload?: Readonly<{
|
|
388
|
+
kind: "string" | "number" | "boolean";
|
|
389
|
+
type: "value";
|
|
390
|
+
defaultValue: string | number | boolean | null;
|
|
391
|
+
isOptional: boolean;
|
|
392
|
+
tags?: readonly string[] | undefined;
|
|
393
|
+
}> | Readonly<{
|
|
394
|
+
kind: "select";
|
|
395
|
+
readonly options: readonly [string, ...string[]];
|
|
396
|
+
optionLabels?: {
|
|
397
|
+
[x: string]: string;
|
|
398
|
+
} | undefined;
|
|
399
|
+
type: "value";
|
|
400
|
+
defaultValue: string | number | boolean | null;
|
|
401
|
+
isOptional: boolean;
|
|
402
|
+
tags?: readonly string[] | undefined;
|
|
403
|
+
}> | undefined;
|
|
384
404
|
}>[]>;
|
|
385
405
|
}, undefined>;
|
|
386
406
|
export type BuilderReference = v.InferOutput<typeof BuilderReferenceSchema>;
|
|
387
407
|
export declare const BuilderReferencesSchema: v.ArraySchema<v.ObjectSchema<{
|
|
388
408
|
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
389
409
|
readonly serialised: v.GenericSchema<string | number | boolean | readonly (string | number)[] | readonly (readonly (string | number)[])[] | import("./index.js").BuilderSerialised | import("./index.js").BuilderModelSerialised | Readonly<{
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
defaultValue: string | null;
|
|
410
|
+
kind: "string" | "number" | "boolean";
|
|
411
|
+
type: "value";
|
|
412
|
+
defaultValue: string | number | boolean | null;
|
|
393
413
|
isOptional: boolean;
|
|
394
|
-
optionLabels: {
|
|
395
|
-
[x: string]: string;
|
|
396
|
-
};
|
|
397
414
|
tags?: readonly string[] | undefined;
|
|
398
415
|
}> | Readonly<{
|
|
399
|
-
|
|
400
|
-
|
|
416
|
+
kind: "select";
|
|
417
|
+
readonly options: readonly [string, ...string[]];
|
|
418
|
+
optionLabels?: {
|
|
419
|
+
[x: string]: string;
|
|
420
|
+
} | undefined;
|
|
421
|
+
type: "value";
|
|
401
422
|
defaultValue: string | number | boolean | null;
|
|
402
423
|
isOptional: boolean;
|
|
403
424
|
tags?: readonly string[] | undefined;
|
|
404
|
-
}> | import("./
|
|
425
|
+
}> | import("./condition.js").BuilderMatchSelectMap<Readonly<{
|
|
405
426
|
type: "parameter";
|
|
406
427
|
id: string;
|
|
407
428
|
name: string;
|
|
408
|
-
}> | Readonly<
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
defaultValue: string | null;
|
|
429
|
+
}> | Readonly<{
|
|
430
|
+
kind: "string" | "number" | "boolean";
|
|
431
|
+
type: "value";
|
|
432
|
+
defaultValue: string | number | boolean | null;
|
|
412
433
|
isOptional: boolean;
|
|
413
|
-
|
|
434
|
+
tags?: readonly string[] | undefined;
|
|
435
|
+
}> | Readonly<{
|
|
436
|
+
kind: "select";
|
|
437
|
+
readonly options: readonly [string, ...string[]];
|
|
438
|
+
optionLabels?: {
|
|
414
439
|
[x: string]: string;
|
|
415
|
-
};
|
|
440
|
+
} | undefined;
|
|
441
|
+
type: "value";
|
|
442
|
+
defaultValue: string | number | boolean | null;
|
|
443
|
+
isOptional: boolean;
|
|
416
444
|
tags?: readonly string[] | undefined;
|
|
417
|
-
}>> |
|
|
418
|
-
type: "toggle";
|
|
445
|
+
}>> | import("./condition.js").BuilderConditionSerialised<Readonly<{
|
|
419
446
|
kind: "string" | "number" | "boolean";
|
|
447
|
+
type: "value";
|
|
420
448
|
defaultValue: string | number | boolean | null;
|
|
421
449
|
isOptional: boolean;
|
|
422
450
|
tags?: readonly string[] | undefined;
|
|
423
|
-
}
|
|
424
|
-
|
|
451
|
+
}> | Readonly<{
|
|
452
|
+
kind: "select";
|
|
425
453
|
readonly options: readonly [string, ...string[]];
|
|
426
|
-
|
|
427
|
-
isOptional: boolean;
|
|
428
|
-
optionLabels: {
|
|
454
|
+
optionLabels?: {
|
|
429
455
|
[x: string]: string;
|
|
430
|
-
};
|
|
431
|
-
|
|
432
|
-
}>> | Readonly<Readonly<{
|
|
433
|
-
type: "toggle";
|
|
434
|
-
kind: "string" | "number" | "boolean";
|
|
456
|
+
} | undefined;
|
|
457
|
+
type: "value";
|
|
435
458
|
defaultValue: string | number | boolean | null;
|
|
436
459
|
isOptional: boolean;
|
|
437
460
|
tags?: readonly string[] | undefined;
|
|
438
|
-
}
|
|
461
|
+
}>> | Readonly<{
|
|
439
462
|
details: Readonly<{
|
|
440
463
|
type: "parameter";
|
|
441
464
|
id: string;
|
|
@@ -451,7 +474,7 @@ export declare const BuilderReferencesSchema: v.ArraySchema<v.ObjectSchema<{
|
|
|
451
474
|
tags?: readonly string[] | undefined;
|
|
452
475
|
}>[];
|
|
453
476
|
tags?: readonly string[] | undefined;
|
|
454
|
-
}> | import("./
|
|
477
|
+
}> | import("./condition.js").BuilderMatchSelectMap<Readonly<{
|
|
455
478
|
type: "parameter";
|
|
456
479
|
id: string;
|
|
457
480
|
name: string;
|
|
@@ -471,7 +494,7 @@ export declare const BuilderReferencesSchema: v.ArraySchema<v.ObjectSchema<{
|
|
|
471
494
|
tags?: readonly string[] | undefined;
|
|
472
495
|
}>[];
|
|
473
496
|
tags?: readonly string[] | undefined;
|
|
474
|
-
}>> | import("./
|
|
497
|
+
}>> | import("./condition.js").BuilderConditionSerialised<Readonly<{
|
|
475
498
|
details: Readonly<{
|
|
476
499
|
type: "parameter";
|
|
477
500
|
id: string;
|
|
@@ -513,7 +536,7 @@ export declare const BuilderReferencesSchema: v.ArraySchema<v.ObjectSchema<{
|
|
|
513
536
|
id: string;
|
|
514
537
|
}>;
|
|
515
538
|
tags?: readonly string[] | undefined;
|
|
516
|
-
}> | import("./
|
|
539
|
+
}> | import("./condition.js").BuilderMatchSelectMap<Readonly<{
|
|
517
540
|
type: "parameter";
|
|
518
541
|
id: string;
|
|
519
542
|
name: string;
|
|
@@ -543,7 +566,7 @@ export declare const BuilderReferencesSchema: v.ArraySchema<v.ObjectSchema<{
|
|
|
543
566
|
id: string;
|
|
544
567
|
}>;
|
|
545
568
|
tags?: readonly string[] | undefined;
|
|
546
|
-
}>> | import("./
|
|
569
|
+
}>> | import("./condition.js").BuilderConditionSerialised<Readonly<{
|
|
547
570
|
model: Readonly<{
|
|
548
571
|
type: "parameter";
|
|
549
572
|
id: string;
|
|
@@ -766,6 +789,23 @@ export declare const BuilderReferencesSchema: v.ArraySchema<v.ObjectSchema<{
|
|
|
766
789
|
}> | import("./index.js").BuilderUIItemSerialised)[] | import("./index.js").BuilderPricingSerialised | import("./index.js").BuilderRates | readonly Readonly<{
|
|
767
790
|
name: string;
|
|
768
791
|
kind: "option" | "component" | "collection";
|
|
792
|
+
payload?: Readonly<{
|
|
793
|
+
kind: "string" | "number" | "boolean";
|
|
794
|
+
type: "value";
|
|
795
|
+
defaultValue: string | number | boolean | null;
|
|
796
|
+
isOptional: boolean;
|
|
797
|
+
tags?: readonly string[] | undefined;
|
|
798
|
+
}> | Readonly<{
|
|
799
|
+
kind: "select";
|
|
800
|
+
readonly options: readonly [string, ...string[]];
|
|
801
|
+
optionLabels?: {
|
|
802
|
+
[x: string]: string;
|
|
803
|
+
} | undefined;
|
|
804
|
+
type: "value";
|
|
805
|
+
defaultValue: string | number | boolean | null;
|
|
806
|
+
isOptional: boolean;
|
|
807
|
+
tags?: readonly string[] | undefined;
|
|
808
|
+
}> | undefined;
|
|
769
809
|
}>[]>;
|
|
770
810
|
}, undefined>, undefined>;
|
|
771
811
|
export type BuilderReferences = v.InferOutput<typeof BuilderReferencesSchema>;
|