@builder-builder/builder 0.0.27 → 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 +9 -10
- package/dist/client/client.d.ts +2 -1
- package/dist/client/client.js +4 -1
- package/dist/client/public.d.ts +2 -2
- package/dist/client/public.js +1 -1
- package/dist/client/schema.d.ts +126 -45
- package/dist/client/schema.js +6 -1
- 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/BuilderRender.svelte.d.ts +2 -2
- package/dist/components/index.d.ts +8 -8
- package/dist/components/index.js +4376 -4258
- package/dist/components/index.min.js +3 -0
- package/dist/entities/collection/collection.d.ts +191 -401
- package/dist/entities/collection/collection.js +7 -4
- package/dist/entities/collection/{when.d.ts → condition.d.ts} +4 -5
- package/dist/entities/collection/condition.js +2 -0
- package/dist/entities/collection/config.d.ts +62 -80
- package/dist/entities/collection/index.d.ts +4 -4
- package/dist/entities/collection/index.js +2 -2
- package/dist/entities/component/component.d.ts +71 -83
- package/dist/entities/component/component.js +4 -4
- package/dist/entities/component/condition.d.ts +10 -0
- package/dist/entities/component/{when.js → condition.js} +3 -9
- package/dist/entities/component/config.d.ts +33 -33
- package/dist/entities/component/config.js +18 -16
- package/dist/entities/component/detail.d.ts +61 -0
- package/dist/entities/component/detail.js +71 -0
- package/dist/entities/component/index.d.ts +6 -6
- package/dist/entities/component/index.js +3 -3
- package/dist/entities/{when.d.ts → condition.d.ts} +23 -36
- 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 +9 -9
- package/dist/entities/index.js +4 -4
- package/dist/entities/kind.d.ts +4 -4
- package/dist/entities/kind.js +24 -25
- 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 +47 -72
- 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 +179 -210
- 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/paths.d.ts +2 -2
- package/dist/entities/pricing/expression.d.ts +16 -39
- package/dist/entities/pricing/expression.js +1 -16
- package/dist/entities/pricing/index.d.ts +1 -1
- package/dist/entities/pricing/rates.d.ts +1 -1
- package/dist/entities/references.d.ts +124 -84
- package/dist/entities/serialise.d.ts +175 -109
- package/dist/entities/serialise.js +32 -27
- package/dist/entities/ui/describe.d.ts +1 -1
- package/dist/entities/ui/input.d.ts +2 -2
- package/dist/entities/ui/page.d.ts +1 -1
- package/dist/entities/ui/pages.d.ts +2 -2
- package/dist/entities/validated.d.ts +3 -3
- package/dist/environment.d.ts +2 -2
- package/dist/errors/errors.d.ts +94 -58
- package/dist/errors/errors.js +41 -7
- package/dist/errors/exception.d.ts +3 -3
- package/dist/errors/index.d.ts +1 -1
- package/dist/errors/index.js +1 -1
- package/dist/errors/public.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/instance.d.ts +53 -9
- package/dist/instance.js +6 -2
- package/dist/mappers/dependencies.d.ts +3 -0
- package/dist/mappers/dependencies.js +45 -0
- package/dist/mappers/index.d.ts +2 -2
- package/dist/mappers/index.js +2 -1
- package/dist/mappers/instance.js +26 -21
- package/dist/mappers/price.js +6 -4
- package/dist/mappers/resolve.js +23 -22
- package/dist/mappers/variants/index.d.ts +1 -2
- package/dist/mappers/variants/index.js +1 -2
- package/dist/mappers/variants/option-graph.d.ts +1 -2
- package/dist/mappers/variants/option-graph.js +4 -18
- package/dist/mappers/variants/variants.d.ts +3 -6
- package/dist/mappers/variants/variants.js +34 -11
- package/dist/primitive.d.ts +3 -0
- package/dist/primitive.js +2 -0
- package/dist/public.d.ts +20 -20
- package/dist/public.js +17 -9
- package/dist/validate/builder.d.ts +2 -2
- package/dist/validate/builder.js +15 -15
- package/dist/validate/expectations.d.ts +2 -2
- package/dist/validate/expectations.js +23 -5
- package/dist/validate/instance.d.ts +2 -2
- package/dist/validate/instance.js +31 -13
- package/dist/validate/model.d.ts +4 -4
- package/dist/validate/model.js +57 -51
- package/dist/validate/paths.d.ts +2 -2
- package/dist/validate/paths.js +19 -14
- package/dist/validate/pricing.d.ts +4 -4
- package/dist/validate/pricing.js +31 -31
- package/dist/validate/resolve.d.ts +2 -2
- package/dist/validate/resolve.js +27 -31
- package/dist/validate/ui.d.ts +4 -4
- package/dist/validate/ui.js +38 -38
- package/dist/validate/variants.d.ts +3 -3
- package/dist/validate/variants.js +32 -31
- package/package.json +4 -2
- 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/component/field.d.ts +0 -59
- package/dist/entities/component/field.js +0 -52
- package/dist/entities/component/when.d.ts +0 -11
- package/dist/entities/option/toggle.d.ts +0 -45
- package/dist/entities/option/toggle.js +0 -66
- 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
|
+
});
|
package/dist/entities/paths.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ export declare const BuilderPathSchema: v.SchemaWithPipe<readonly [v.ArraySchema
|
|
|
3
3
|
export type BuilderPath = v.InferOutput<typeof BuilderPathSchema>;
|
|
4
4
|
export declare const BuilderPathsSchema: v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>, v.NumberSchema<undefined>], undefined>, undefined>, v.ReadonlyAction<(string | number)[]>]>, undefined>, v.ReadonlyAction<(readonly (string | number)[])[]>]>;
|
|
5
5
|
export type BuilderPaths = v.InferOutput<typeof BuilderPathsSchema>;
|
|
6
|
-
export declare const validatePath: (input: unknown, references?: import("./references.js").BuilderReferences,
|
|
7
|
-
export declare const validatePaths: (input: unknown, references?: import("./references.js").BuilderReferences,
|
|
6
|
+
export declare const validatePath: (input: unknown, references?: import("./references.js").BuilderReferences, issues?: import("../errors/errors.js").BuilderIssuesScope) => import("./validated.js").ValidationResult<readonly (string | number)[]>;
|
|
7
|
+
export declare const validatePaths: (input: unknown, references?: import("./references.js").BuilderReferences, issues?: import("../errors/errors.js").BuilderIssuesScope) => import("./validated.js").ValidationResult<readonly (readonly (string | number)[])[]>;
|
|
@@ -9,62 +9,39 @@ export type BuilderPricingLookupKey = {
|
|
|
9
9
|
readonly name: string;
|
|
10
10
|
};
|
|
11
11
|
export declare const BuilderPricingLookupKeySchema: v.GenericSchema<BuilderPricingLookupKey>;
|
|
12
|
-
|
|
12
|
+
type BuilderPricingLiteral = number;
|
|
13
|
+
type BuilderPricingVariantPrice = {
|
|
13
14
|
readonly kind: 'variantPrice';
|
|
14
|
-
}
|
|
15
|
+
};
|
|
16
|
+
export type BuilderPricingLookup = {
|
|
15
17
|
readonly kind: 'lookup';
|
|
16
18
|
readonly rate: string;
|
|
17
19
|
readonly key: BuilderPricingLookupKey;
|
|
18
20
|
readonly reduce?: BuilderPricingReduce;
|
|
19
|
-
}
|
|
21
|
+
};
|
|
22
|
+
export type BuilderPricingVariants = {
|
|
20
23
|
readonly kind: 'variants';
|
|
21
24
|
readonly tag?: string;
|
|
22
25
|
readonly expression: Paramable<BuilderPricingExpression>;
|
|
23
26
|
readonly reduce?: BuilderPricingReduce;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
readonly
|
|
27
|
-
readonly right: Paramable<BuilderPricingExpression>;
|
|
28
|
-
} | {
|
|
29
|
-
readonly kind: 'sub';
|
|
30
|
-
readonly left: Paramable<BuilderPricingExpression>;
|
|
31
|
-
readonly right: Paramable<BuilderPricingExpression>;
|
|
32
|
-
} | {
|
|
33
|
-
readonly kind: 'mul';
|
|
34
|
-
readonly left: Paramable<BuilderPricingExpression>;
|
|
35
|
-
readonly right: Paramable<BuilderPricingExpression>;
|
|
36
|
-
} | {
|
|
37
|
-
readonly kind: 'div';
|
|
27
|
+
};
|
|
28
|
+
type BuilderPricingArithmetic = {
|
|
29
|
+
readonly kind: 'add' | 'sub' | 'mul' | 'div';
|
|
38
30
|
readonly left: Paramable<BuilderPricingExpression>;
|
|
39
31
|
readonly right: Paramable<BuilderPricingExpression>;
|
|
40
32
|
};
|
|
41
|
-
export type
|
|
42
|
-
|
|
43
|
-
} | {
|
|
44
|
-
readonly kind: 'lookup';
|
|
45
|
-
readonly rate: string;
|
|
46
|
-
readonly key: BuilderPricingLookupKey;
|
|
47
|
-
readonly reduce?: BuilderPricingReduce;
|
|
48
|
-
} | {
|
|
33
|
+
export type BuilderPricingExpression = BuilderPricingLiteral | BuilderPricingVariantPrice | BuilderPricingLookup | BuilderPricingVariants | BuilderPricingArithmetic;
|
|
34
|
+
type BuilderPricingVariantsSerialised = {
|
|
49
35
|
readonly kind: 'variants';
|
|
50
36
|
readonly tag?: string;
|
|
51
37
|
readonly expression: ParamableSerialised<BuilderPricingExpressionSerialised>;
|
|
52
38
|
readonly reduce?: BuilderPricingReduce;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
readonly
|
|
56
|
-
readonly right: ParamableSerialised<BuilderPricingExpressionSerialised>;
|
|
57
|
-
} | {
|
|
58
|
-
readonly kind: 'sub';
|
|
59
|
-
readonly left: ParamableSerialised<BuilderPricingExpressionSerialised>;
|
|
60
|
-
readonly right: ParamableSerialised<BuilderPricingExpressionSerialised>;
|
|
61
|
-
} | {
|
|
62
|
-
readonly kind: 'mul';
|
|
63
|
-
readonly left: ParamableSerialised<BuilderPricingExpressionSerialised>;
|
|
64
|
-
readonly right: ParamableSerialised<BuilderPricingExpressionSerialised>;
|
|
65
|
-
} | {
|
|
66
|
-
readonly kind: 'div';
|
|
39
|
+
};
|
|
40
|
+
type BuilderPricingArithmeticSerialised = {
|
|
41
|
+
readonly kind: 'add' | 'sub' | 'mul' | 'div';
|
|
67
42
|
readonly left: ParamableSerialised<BuilderPricingExpressionSerialised>;
|
|
68
43
|
readonly right: ParamableSerialised<BuilderPricingExpressionSerialised>;
|
|
69
44
|
};
|
|
45
|
+
export type BuilderPricingExpressionSerialised = BuilderPricingLiteral | BuilderPricingVariantPrice | BuilderPricingLookup | BuilderPricingVariantsSerialised | BuilderPricingArithmeticSerialised;
|
|
70
46
|
export declare const BuilderPricingExpressionSchema: v.GenericSchema<BuilderPricingExpression>;
|
|
47
|
+
export {};
|
|
@@ -22,22 +22,7 @@ export const BuilderPricingExpressionSchema = v.lazy(() => v.union([
|
|
|
22
22
|
reduce: v.optional(BuilderPricingReduceSchema)
|
|
23
23
|
}),
|
|
24
24
|
v.object({
|
|
25
|
-
kind: v.
|
|
26
|
-
left: paramable(BuilderPricingExpressionSchema),
|
|
27
|
-
right: paramable(BuilderPricingExpressionSchema)
|
|
28
|
-
}),
|
|
29
|
-
v.object({
|
|
30
|
-
kind: v.literal('sub'),
|
|
31
|
-
left: paramable(BuilderPricingExpressionSchema),
|
|
32
|
-
right: paramable(BuilderPricingExpressionSchema)
|
|
33
|
-
}),
|
|
34
|
-
v.object({
|
|
35
|
-
kind: v.literal('mul'),
|
|
36
|
-
left: paramable(BuilderPricingExpressionSchema),
|
|
37
|
-
right: paramable(BuilderPricingExpressionSchema)
|
|
38
|
-
}),
|
|
39
|
-
v.object({
|
|
40
|
-
kind: v.literal('div'),
|
|
25
|
+
kind: v.picklist(['add', 'sub', 'mul', 'div']),
|
|
41
26
|
left: paramable(BuilderPricingExpressionSchema),
|
|
42
27
|
right: paramable(BuilderPricingExpressionSchema)
|
|
43
28
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { BuilderPricingExpression, BuilderPricingLookupKey, BuilderPricingReduce } from './expression';
|
|
1
|
+
export type { BuilderPricingExpression, BuilderPricingLookup, BuilderPricingLookupKey, BuilderPricingReduce, BuilderPricingVariants } from './expression';
|
|
2
2
|
export type { BuilderRates } from './rates';
|
|
3
3
|
export type { BuilderPricingSerialised } from './pricing';
|
|
4
4
|
export { BuilderPricingExpressionSchema, BuilderPricingLookupKeySchema, BuilderPricingReduceSchema } from './expression.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as v from 'valibot';
|
|
2
2
|
export type BuilderRates = Record<string, Record<string, number>>;
|
|
3
3
|
export declare const BuilderRatesSchema: v.GenericSchema<BuilderRates>;
|
|
4
|
-
export declare const validatePricingRates: (input: unknown, references?: import("../references.js").BuilderReferences,
|
|
4
|
+
export declare const validatePricingRates: (input: unknown, references?: import("../references.js").BuilderReferences, issues?: import("../../errors/errors.js").BuilderIssuesScope) => import("../validated.js").ValidationResult<{
|
|
5
5
|
readonly [x: string]: {
|
|
6
6
|
readonly [x: string]: number;
|
|
7
7
|
} & import("../../validate/brand.js").BuilderValidatedBrand;
|