@builder-builder/builder 0.0.27 → 0.0.28

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.
Files changed (98) hide show
  1. package/dist/bb.js +4 -4
  2. package/dist/client/client.d.ts +2 -1
  3. package/dist/client/client.js +4 -1
  4. package/dist/client/public.d.ts +2 -2
  5. package/dist/client/public.js +1 -1
  6. package/dist/client/schema.d.ts +79 -18
  7. package/dist/client/schema.js +6 -1
  8. package/dist/components/BuilderRender.svelte.d.ts +2 -2
  9. package/dist/components/index.js +4377 -4303
  10. package/dist/components/index.min.js +3 -0
  11. package/dist/entities/collection/collection.d.ts +66 -66
  12. package/dist/entities/collection/config.d.ts +17 -17
  13. package/dist/entities/collection/when.d.ts +1 -1
  14. package/dist/entities/component/component.d.ts +64 -64
  15. package/dist/entities/component/config.d.ts +33 -33
  16. package/dist/entities/component/config.js +18 -16
  17. package/dist/entities/component/detail.d.ts +61 -0
  18. package/dist/entities/component/detail.js +71 -0
  19. package/dist/entities/component/index.d.ts +2 -2
  20. package/dist/entities/component/index.js +1 -1
  21. package/dist/entities/component/when.d.ts +2 -2
  22. package/dist/entities/expectation.d.ts +1 -1
  23. package/dist/entities/index.d.ts +4 -4
  24. package/dist/entities/index.js +1 -1
  25. package/dist/entities/kind.d.ts +3 -3
  26. package/dist/entities/kind.js +20 -20
  27. package/dist/entities/model/methods.d.ts +1 -1
  28. package/dist/entities/option/config.d.ts +7 -7
  29. package/dist/entities/option/config.js +1 -1
  30. package/dist/entities/option/index.d.ts +4 -4
  31. package/dist/entities/option/index.js +2 -2
  32. package/dist/entities/option/option.d.ts +22 -22
  33. package/dist/entities/option/select.d.ts +1 -1
  34. package/dist/entities/option/toggle.d.ts +9 -9
  35. package/dist/entities/option/toggle.js +15 -10
  36. package/dist/entities/option/when.d.ts +1 -1
  37. package/dist/entities/paths.d.ts +2 -2
  38. package/dist/entities/pricing/expression.d.ts +16 -39
  39. package/dist/entities/pricing/expression.js +1 -16
  40. package/dist/entities/pricing/index.d.ts +1 -1
  41. package/dist/entities/pricing/rates.d.ts +1 -1
  42. package/dist/entities/references.d.ts +24 -24
  43. package/dist/entities/serialise.d.ts +31 -32
  44. package/dist/entities/serialise.js +7 -7
  45. package/dist/entities/ui/describe.d.ts +1 -1
  46. package/dist/entities/ui/input.d.ts +1 -1
  47. package/dist/entities/ui/page.d.ts +1 -1
  48. package/dist/entities/ui/pages.d.ts +2 -2
  49. package/dist/entities/validated.d.ts +2 -2
  50. package/dist/entities/when.d.ts +5 -5
  51. package/dist/environment.d.ts +2 -2
  52. package/dist/errors/errors.d.ts +86 -55
  53. package/dist/errors/errors.js +36 -5
  54. package/dist/errors/exception.d.ts +3 -3
  55. package/dist/errors/index.d.ts +1 -1
  56. package/dist/errors/index.js +1 -1
  57. package/dist/errors/public.d.ts +1 -1
  58. package/dist/index.d.ts +1 -1
  59. package/dist/index.js +1 -1
  60. package/dist/instance.d.ts +53 -9
  61. package/dist/instance.js +6 -2
  62. package/dist/mappers/dependencies.d.ts +3 -0
  63. package/dist/mappers/dependencies.js +44 -0
  64. package/dist/mappers/index.d.ts +2 -2
  65. package/dist/mappers/index.js +2 -1
  66. package/dist/mappers/instance.js +26 -21
  67. package/dist/mappers/price.js +6 -4
  68. package/dist/mappers/variants/index.d.ts +1 -2
  69. package/dist/mappers/variants/index.js +1 -2
  70. package/dist/mappers/variants/option-graph.d.ts +1 -2
  71. package/dist/mappers/variants/option-graph.js +3 -17
  72. package/dist/mappers/variants/variants.d.ts +3 -6
  73. package/dist/mappers/variants/variants.js +34 -11
  74. package/dist/primitive.d.ts +3 -0
  75. package/dist/primitive.js +2 -0
  76. package/dist/public.d.ts +8 -8
  77. package/dist/public.js +1 -1
  78. package/dist/validate/builder.d.ts +2 -2
  79. package/dist/validate/builder.js +15 -15
  80. package/dist/validate/expectations.d.ts +2 -2
  81. package/dist/validate/expectations.js +3 -3
  82. package/dist/validate/instance.d.ts +2 -2
  83. package/dist/validate/instance.js +31 -13
  84. package/dist/validate/model.d.ts +4 -4
  85. package/dist/validate/model.js +51 -42
  86. package/dist/validate/paths.d.ts +2 -2
  87. package/dist/validate/paths.js +19 -14
  88. package/dist/validate/pricing.d.ts +4 -4
  89. package/dist/validate/pricing.js +31 -31
  90. package/dist/validate/resolve.d.ts +2 -2
  91. package/dist/validate/resolve.js +18 -18
  92. package/dist/validate/ui.d.ts +4 -4
  93. package/dist/validate/ui.js +38 -38
  94. package/dist/validate/variants.d.ts +3 -3
  95. package/dist/validate/variants.js +32 -31
  96. package/package.json +4 -2
  97. package/dist/entities/component/field.d.ts +0 -59
  98. package/dist/entities/component/field.js +0 -52
@@ -1,23 +1,23 @@
1
1
  import { BuilderModelSerialisedSchema, BuilderPathSchema, BuilderUIInputMetadataSchema, BuilderUIInputSerialisedSchema, BuilderUIInputsSerialisedSchema, BuilderUIItemSerialisedSchema, BuilderUIItemsSerialisedSchema, BuilderUISerialisedSchema, modelsMerge, serialise, uis, validateUIDescribe, validateUIInput, validateUIPage, validateUIPages } from '../entities/index.js';
2
- import { BuilderErrorsScope, check } from '../errors/index.js';
2
+ import { BuilderIssuesScope, check } from '../errors/index.js';
3
3
  import { resolveCollections } from '../mappers/index.js';
4
4
  import { StringSchema } from '../primitive.js';
5
5
  import { validate } from './brand.js';
6
6
  import { checkExpectations } from './expectations.js';
7
7
  import { checkPath } from './paths.js';
8
8
  import { resolver } from './resolve.js';
9
- export function validateUI(input, references = [], errors = new BuilderErrorsScope(input)) {
9
+ export function validateUI(input, references = [], issues = new BuilderIssuesScope(input)) {
10
10
  if (!check.is(BuilderUISerialisedSchema, input)) {
11
- errors.entityInvalid('ui');
12
- return [validate(serialise.ui(uis())), errors.errors];
11
+ issues.entityInvalid('ui');
12
+ return [validate(serialise.ui(uis())), issues.errors, issues.warnings];
13
13
  }
14
- const resolve = resolver(errors, references);
15
- const structure = validateUIStructure(input, resolve, errors);
16
- return [validate(structure), errors.errors];
14
+ const resolve = resolver(issues, references);
15
+ const structure = validateUIStructure(input, resolve, issues);
16
+ return [validate(structure), issues.errors, issues.warnings];
17
17
  }
18
- export function validateUIStructure(ui, resolve, errors) {
18
+ export function validateUIStructure(ui, resolve, issues) {
19
19
  const childUIs = walkChildUIs();
20
- const items = errors.scope('items', () => walkItems(ui.items));
20
+ const items = issues.scope('items', () => walkItems(ui.items));
21
21
  const data = {
22
22
  ...ui,
23
23
  uis: childUIs,
@@ -25,40 +25,40 @@ export function validateUIStructure(ui, resolve, errors) {
25
25
  };
26
26
  return data;
27
27
  function walkChildUIs() {
28
- return errors.scope('uis', () => ui.uis.flatMap((part, partIndex) => errors.scope(partIndex, () => {
28
+ return issues.scope('uis', () => ui.uis.flatMap((part, partIndex) => issues.scope(partIndex, () => {
29
29
  const resolved = resolve(part, BuilderUISerialisedSchema);
30
30
  if (resolved == null) {
31
31
  return [];
32
32
  }
33
- return [validateUIStructure(resolved, resolve, errors)];
33
+ return [validateUIStructure(resolved, resolve, issues)];
34
34
  })));
35
35
  }
36
36
  function walkItems(parts) {
37
- return parts.map((item, itemIndex) => errors.scope(itemIndex, () => {
37
+ return parts.map((item, itemIndex) => issues.scope(itemIndex, () => {
38
38
  const resolved = resolve(item, BuilderUIItemSerialisedSchema);
39
39
  return walkUIItem((resolved ?? item));
40
40
  }));
41
41
  }
42
42
  function walkUIItem(item) {
43
43
  if (item.type === 'page') {
44
- validateUIPage(item, [], errors);
44
+ validateUIPage(item, [], issues);
45
45
  }
46
46
  else if (item.type === 'pages') {
47
- validateUIPages(item, [], errors);
47
+ validateUIPages(item, [], issues);
48
48
  }
49
49
  else if (item.type === 'describe') {
50
- validateUIDescribe(item, [], errors);
50
+ validateUIDescribe(item, [], issues);
51
51
  }
52
- const label = errors.scope('label', () => resolve(item.label, StringSchema) ?? item.label);
52
+ const label = issues.scope('label', () => resolve(item.label, StringSchema) ?? item.label);
53
53
  if (item.type === 'pages') {
54
- const innerItems = errors.scope('items', () => {
54
+ const innerItems = issues.scope('items', () => {
55
55
  const resolved = resolve(item.items, BuilderUIItemsSerialisedSchema);
56
56
  const resolvedItems = (Array.isArray(resolved) ? resolved : item.items);
57
57
  return walkItems(resolvedItems);
58
58
  });
59
59
  return { ...item, label, items: innerItems };
60
60
  }
61
- const inputs = errors.scope('inputs', () => {
61
+ const inputs = issues.scope('inputs', () => {
62
62
  const resolved = resolve(item.inputs, BuilderUIInputsSerialisedSchema);
63
63
  if (!Array.isArray(resolved)) {
64
64
  return resolved ?? item.inputs;
@@ -68,18 +68,18 @@ export function validateUIStructure(ui, resolve, errors) {
68
68
  return { ...item, label, inputs };
69
69
  }
70
70
  function walkInputs(inputs) {
71
- return inputs.map((entry, entryIndex) => errors.scope(entryIndex, () => {
71
+ return inputs.map((entry, entryIndex) => issues.scope(entryIndex, () => {
72
72
  const resolvedEntry = resolve(entry, BuilderUIInputSerialisedSchema);
73
73
  return walkInput((resolvedEntry ?? entry));
74
74
  }));
75
75
  }
76
76
  function walkInput(value) {
77
- validateUIInput(value, [], errors);
78
- const path = errors.scope('path', () => resolve(value.path, BuilderPathSchema) ?? value.path);
77
+ validateUIInput(value, [], issues);
78
+ const path = issues.scope('path', () => resolve(value.path, BuilderPathSchema) ?? value.path);
79
79
  const displayName = value.displayName &&
80
- errors.scope('displayName', () => resolve(value.displayName, StringSchema) ?? value.displayName);
81
- const kind = value.kind && errors.scope('kind', () => resolve(value.kind, StringSchema) ?? value.kind);
82
- const metadata = value.metadata && errors.scope('metadata', () => walkMetadata(value.metadata));
80
+ issues.scope('displayName', () => resolve(value.displayName, StringSchema) ?? value.displayName);
81
+ const kind = value.kind && issues.scope('kind', () => resolve(value.kind, StringSchema) ?? value.kind);
82
+ const metadata = value.metadata && issues.scope('metadata', () => walkMetadata(value.metadata));
83
83
  return { ...value, path, displayName, kind, metadata };
84
84
  }
85
85
  function walkMetadata(rawMetadata) {
@@ -88,28 +88,28 @@ export function validateUIStructure(ui, resolve, errors) {
88
88
  return rawMetadata;
89
89
  }
90
90
  return Object.entries(resolved).reduce((entries, [key, entryValue]) => {
91
- const resolvedValue = errors.scope(key, () => resolve(entryValue));
91
+ const resolvedValue = issues.scope(key, () => resolve(entryValue));
92
92
  return { ...entries, [key]: resolvedValue ?? entryValue };
93
93
  }, {});
94
94
  }
95
95
  }
96
- export function checkUIExpectations(mergedModel, ui, errors) {
96
+ export function checkUIExpectations(mergedModel, ui, issues) {
97
97
  const expectedOptionNames = collectExpectedOptionNames(ui);
98
- errors.scope('expectations', () => {
99
- checkExpectations(mergedModel, ui.expectations, errors);
98
+ issues.scope('expectations', () => {
99
+ checkExpectations(mergedModel, ui.expectations, issues);
100
100
  });
101
- errors.scope('items', () => walkItems(mergedModel, ui.items));
102
- errors.scope('uis', () => {
101
+ issues.scope('items', () => walkItems(mergedModel, ui.items));
102
+ issues.scope('uis', () => {
103
103
  ui.uis.forEach((nested, nestedIndex) => {
104
- errors.scope(nestedIndex, () => {
105
- checkUIExpectations(mergedModel, nested, errors);
104
+ issues.scope(nestedIndex, () => {
105
+ checkUIExpectations(mergedModel, nested, issues);
106
106
  });
107
107
  });
108
108
  });
109
109
  function walkItems(model, items) {
110
110
  items.forEach((entry, itemIndex) => {
111
111
  const item = entry;
112
- errors.scope(itemIndex, () => {
112
+ issues.scope(itemIndex, () => {
113
113
  if (item.type === 'pages') {
114
114
  walkPages(model, item);
115
115
  return;
@@ -118,8 +118,8 @@ export function checkUIExpectations(mergedModel, ui, errors) {
118
118
  if (!Array.isArray(inputs)) {
119
119
  return;
120
120
  }
121
- errors.scope('inputs', () => inputs.forEach((input, entryIndex) => {
122
- errors.scope(entryIndex, () => walkInput(model, input));
121
+ issues.scope('inputs', () => inputs.forEach((input, entryIndex) => {
122
+ issues.scope(entryIndex, () => walkInput(model, input));
123
123
  }));
124
124
  });
125
125
  });
@@ -132,7 +132,7 @@ export function checkUIExpectations(mergedModel, ui, errors) {
132
132
  const innerModels = resolveCollections(collection).flatMap(({ model: configModel }) => check.is(BuilderModelSerialisedSchema, configModel) ? [configModel] : []);
133
133
  innerModels.forEach((innerModel) => {
134
134
  const mergedInnerModel = modelsMerge(innerModel);
135
- errors.scope('items', () => walkItems(mergedInnerModel, pages.items));
135
+ issues.scope('items', () => walkItems(mergedInnerModel, pages.items));
136
136
  });
137
137
  }
138
138
  function walkInput(model, input) {
@@ -144,8 +144,8 @@ export function checkUIExpectations(mergedModel, ui, errors) {
144
144
  if (typeof leaf === 'string' && expectedOptionNames.has(leaf)) {
145
145
  return;
146
146
  }
147
- errors.scope('path', () => {
148
- checkPath(model, path, errors);
147
+ issues.scope('path', () => {
148
+ checkPath(model, path, issues);
149
149
  });
150
150
  }
151
151
  }
@@ -1,7 +1,7 @@
1
- import type { BuilderModelValidated, BuilderVariantsValidated, ValidationResult } from '../entities/index';
2
- import { BuilderErrorsScope } from '../errors/index.js';
1
+ import type { BuilderModelValidated, BuilderReferences, BuilderVariantsValidated, ValidationResult } from '../entities/index';
2
+ import { BuilderIssuesScope } from '../errors/index.js';
3
3
  export type BuilderVariantsValidationOptions = {
4
4
  readonly partial?: boolean;
5
5
  };
6
6
  export type BuilderVariantsValidationResult = ValidationResult<BuilderVariantsValidated>;
7
- export declare function validateVariants(model: BuilderModelValidated, input: unknown, options?: BuilderVariantsValidationOptions, errors?: BuilderErrorsScope): BuilderVariantsValidationResult;
7
+ export declare function validateVariants(model: BuilderModelValidated, input: unknown, options?: BuilderVariantsValidationOptions, references?: BuilderReferences, issues?: BuilderIssuesScope): BuilderVariantsValidationResult;
@@ -1,46 +1,46 @@
1
1
  import { BuilderComponentConfigSerialisedSchema, detailValueSchema } from '../entities/index.js';
2
- import { BuilderErrorsScope, check } from '../errors/index.js';
2
+ import { BuilderIssuesScope, check } from '../errors/index.js';
3
3
  import { BuilderVariantsSchema } from '../instance.js';
4
4
  import { createVariants } from '../mappers/index.js';
5
5
  import { validate } from './brand.js';
6
- export function validateVariants(model, input, options = {}, errors = new BuilderErrorsScope(input)) {
6
+ export function validateVariants(model, input, options = {}, references = [], issues = new BuilderIssuesScope(input)) {
7
7
  if (!check.is(BuilderVariantsSchema, input)) {
8
- errors.variantsInvalid();
9
- return [validate({}), errors.errors];
8
+ issues.variantsInvalid();
9
+ return [validate({}), issues.errors, issues.warnings];
10
10
  }
11
11
  const variants = input;
12
- const expected = createVariants(model);
12
+ const expected = createVariants(model, references);
13
13
  if (Object.keys(expected).length === 0) {
14
- errors.modelEmptyComponents();
15
- return [validate({}), errors.errors];
14
+ issues.modelEmptyComponents();
15
+ return [validate({}), issues.errors, issues.warnings];
16
16
  }
17
- errors.scope('variants', () => {
17
+ issues.scope('variants', () => {
18
18
  checkVariants();
19
19
  checkComponents();
20
20
  checkDetails();
21
21
  function checkVariants() {
22
22
  Object.entries(expected).forEach(([component, expectedVariants]) => {
23
23
  const componentVariants = variants[component];
24
- errors.scope(component, () => {
24
+ issues.scope(component, () => {
25
25
  if (componentVariants == null) {
26
26
  if (options.partial !== false) {
27
- errors.variantsMissingComponent();
27
+ issues.variantsMissingComponent();
28
28
  }
29
29
  return;
30
30
  }
31
31
  const expectedKeys = new Map(expectedVariants.map(({ instance }) => [sortedKey(instance), instance]));
32
32
  const actualKeys = new Set(componentVariants.map(({ instance }) => sortedKey(instance)));
33
33
  componentVariants.forEach((variant, index) => {
34
- errors.scope(index, () => {
34
+ issues.scope(index, () => {
35
35
  const { instance } = variant;
36
36
  if (!expectedKeys.has(sortedKey(instance))) {
37
- errors.variantsInvalidVariant();
37
+ issues.variantsInvalidVariant();
38
38
  }
39
39
  });
40
40
  });
41
41
  Array.from(expectedKeys).forEach(([key, instance]) => {
42
42
  if (!actualKeys.has(key)) {
43
- errors.variantsMissingVariant(instance);
43
+ issues.variantsMissingVariant(instance);
44
44
  }
45
45
  });
46
46
  });
@@ -48,9 +48,9 @@ export function validateVariants(model, input, options = {}, errors = new Builde
48
48
  }
49
49
  function checkComponents() {
50
50
  Object.keys(variants).forEach((component) => {
51
- errors.scope(component, () => {
51
+ issues.scope(component, () => {
52
52
  if (expected[component] == null) {
53
- errors.variantsUnexpectedComponent();
53
+ issues.variantsUnexpectedComponent();
54
54
  }
55
55
  });
56
56
  });
@@ -58,32 +58,33 @@ export function validateVariants(model, input, options = {}, errors = new Builde
58
58
  function checkDetails() {
59
59
  const componentByName = new Map(model.components.map((entry) => [entry.name, entry]));
60
60
  Object.entries(variants).forEach(([component, componentVariants]) => {
61
- errors.scope(component, () => {
61
+ issues.scope(component, () => {
62
62
  const entry = componentByName.get(component);
63
63
  if (entry == null) {
64
64
  return;
65
65
  }
66
66
  componentVariants.forEach(({ instance, details = {} }, index) => {
67
- errors.scope(index, () => {
67
+ issues.scope(index, () => {
68
68
  const resolved = variantDetails(entry, instance);
69
- const fields = resolved?.fields ?? [];
70
- const expectedNames = new Set(fields.map(({ name }) => name));
71
- errors.scope('details', () => {
72
- fields.forEach(({ name, valueType, isOptional }) => {
73
- errors.scope(name, () => {
74
- if (!(name in details)) {
75
- errors.variantsMissingDetail();
69
+ const expected = resolved?.details ?? [];
70
+ const expectedNames = new Set(expected.map(({ name }) => name));
71
+ issues.scope('details', () => {
72
+ expected.forEach(({ name, kind, isOptional }) => {
73
+ issues.scope(name, () => {
74
+ const detail = details[name];
75
+ if (detail == null) {
76
+ issues.variantsMissingDetail();
76
77
  return;
77
78
  }
78
- if (!check.is(detailValueSchema(valueType, isOptional), details[name])) {
79
- errors.variantsInvalidDetail();
79
+ if (!check.is(detailValueSchema(kind, isOptional), detail.value)) {
80
+ issues.variantsInvalidDetail();
80
81
  }
81
82
  });
82
83
  });
83
- Object.keys(details).forEach((detail) => {
84
- if (!expectedNames.has(detail)) {
85
- errors.scope(detail, () => {
86
- errors.variantsUnexpectedDetail();
84
+ Object.keys(details).forEach((name) => {
85
+ if (!expectedNames.has(name)) {
86
+ issues.scope(name, () => {
87
+ issues.variantsUnexpectedDetail();
87
88
  });
88
89
  }
89
90
  });
@@ -94,7 +95,7 @@ export function validateVariants(model, input, options = {}, errors = new Builde
94
95
  });
95
96
  }
96
97
  });
97
- return [validate(variants), errors.errors];
98
+ return [validate(variants), issues.errors, issues.warnings];
98
99
  }
99
100
  function variantDetails(component, variantInstance) {
100
101
  const { payload } = component;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder-builder/builder",
3
- "version": "0.0.27",
3
+ "version": "0.0.28",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=24"
@@ -24,6 +24,8 @@
24
24
  ],
25
25
  "svelte": "./dist/public.js",
26
26
  "types": "./dist/public.d.ts",
27
+ "unpkg": "./dist/components/index.min.js",
28
+ "jsdelivr": "./dist/components/index.min.js",
27
29
  "publishConfig": {
28
30
  "access": "public"
29
31
  },
@@ -34,7 +36,7 @@
34
36
  "build": "NODE_ENV=production vite build",
35
37
  "package": "svelte-kit sync && npm run package:lib && npm run package:components",
36
38
  "package:lib": "svelte-package --input src/lib/builder",
37
- "package:components": "vite build --mode components && rm -f dist/components/*.svelte",
39
+ "package:components": "NODE_ENV=production vite build --mode components && rm -f dist/components/*.svelte",
38
40
  "preview": "vite preview",
39
41
  "prepare": "svelte-kit sync && npm run messages || echo ''",
40
42
  "prepublishOnly": "npm run test && npm run package",
@@ -1,59 +0,0 @@
1
- import type { BuilderPrimitive } from '../../primitive';
2
- import type { BuilderTags } from '../tags';
3
- import * as v from 'valibot';
4
- export declare const BuilderComponentFieldValueTypeSchema: v.PicklistSchema<["string", "boolean", "number"], undefined>;
5
- export type BuilderComponentFieldValueType = v.InferOutput<typeof BuilderComponentFieldValueTypeSchema>;
6
- export declare class BuilderComponentField<const Name extends string = string, const ValueSchema extends v.GenericSchema<BuilderPrimitive> = v.GenericSchema<BuilderPrimitive>> {
7
- #private;
8
- readonly value: v.InferOutput<ValueSchema>;
9
- readonly type: "component-field";
10
- readonly name: Name;
11
- readonly valueType: BuilderComponentFieldValueType;
12
- readonly valueSchema: ValueSchema;
13
- readonly isOptional: boolean;
14
- readonly tags?: BuilderTags;
15
- constructor(name: Name, valueType: BuilderComponentFieldValueType, optional?: boolean, tags?: BuilderTags);
16
- optional(): BuilderComponentField<Name, v.NullableSchema<ValueSchema, undefined>>;
17
- tag(...tags: Array<string>): BuilderComponentField<Name, ValueSchema>;
18
- }
19
- export declare function detailString<const Name extends string>(name: Name): BuilderComponentField<Name, v.StringSchema<undefined>>;
20
- export declare function detailNumber<const Name extends string>(name: Name): BuilderComponentField<Name, v.NumberSchema<undefined>>;
21
- export declare function detailBoolean<const Name extends string>(name: Name): BuilderComponentField<Name, v.BooleanSchema<undefined>>;
22
- export declare const BuilderComponentFieldSchema: v.InstanceSchema<typeof BuilderComponentField, undefined>;
23
- export declare const BuilderComponentFieldsSchema: v.SchemaWithPipe<readonly [v.ArraySchema<v.InstanceSchema<typeof BuilderComponentField, undefined>, undefined>, v.ReadonlyAction<BuilderComponentField<string, v.GenericSchema<string | number | boolean | null>>[]>]>;
24
- export type BuilderComponentFields = v.InferOutput<typeof BuilderComponentFieldsSchema>;
25
- export declare const BuilderComponentFieldSerialisedSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
26
- readonly type: v.LiteralSchema<"component-field", undefined>;
27
- readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
28
- readonly valueType: v.PicklistSchema<["string", "boolean", "number"], undefined>;
29
- readonly isOptional: v.BooleanSchema<undefined>;
30
- 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>;
31
- }, undefined>, v.ReadonlyAction<{
32
- type: "component-field";
33
- name: string;
34
- valueType: "string" | "number" | "boolean";
35
- isOptional: boolean;
36
- tags?: readonly string[] | undefined;
37
- }>]>;
38
- export type BuilderComponentFieldSerialised = v.InferOutput<typeof BuilderComponentFieldSerialisedSchema>;
39
- export declare const BuilderComponentFieldsSerialisedSchema: v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.ObjectSchema<{
40
- readonly type: v.LiteralSchema<"component-field", undefined>;
41
- readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
42
- readonly valueType: v.PicklistSchema<["string", "boolean", "number"], undefined>;
43
- readonly isOptional: v.BooleanSchema<undefined>;
44
- 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>;
45
- }, undefined>, v.ReadonlyAction<{
46
- type: "component-field";
47
- name: string;
48
- valueType: "string" | "number" | "boolean";
49
- isOptional: boolean;
50
- tags?: readonly string[] | undefined;
51
- }>]>, undefined>, v.ReadonlyAction<Readonly<{
52
- type: "component-field";
53
- name: string;
54
- valueType: "string" | "number" | "boolean";
55
- isOptional: boolean;
56
- tags?: readonly string[] | undefined;
57
- }>[]>]>;
58
- export type BuilderComponentFieldsSerialised = v.InferOutput<typeof BuilderComponentFieldsSerialisedSchema>;
59
- export declare function detailValueSchema(valueType: BuilderComponentFieldValueType, optional: boolean): v.GenericSchema<BuilderPrimitive>;
@@ -1,52 +0,0 @@
1
- import * as v from 'valibot';
2
- import { BooleanSchema, NameSchema, NumberSchema, StringSchema } from '../../primitive.js';
3
- import { serialisable } from '../serialisable.js';
4
- import { BuilderTagsSchema } from '../tags.js';
5
- export const BuilderComponentFieldValueTypeSchema = v.picklist(['string', 'boolean', 'number']);
6
- export class BuilderComponentField {
7
- type = 'component-field';
8
- name;
9
- valueType;
10
- valueSchema;
11
- isOptional;
12
- tags;
13
- constructor(name, valueType, optional = false, tags) {
14
- this.name = name;
15
- this.valueType = valueType;
16
- this.valueSchema = detailValueSchema(valueType, optional);
17
- this.isOptional = optional;
18
- this.tags = tags;
19
- }
20
- #next(patch) {
21
- return new BuilderComponentField(this.name, this.valueType, patch.optional ?? this.isOptional, patch.tags ?? this.tags);
22
- }
23
- optional() {
24
- return this.#next({ optional: true });
25
- }
26
- tag(...tags) {
27
- return this.#next({ tags });
28
- }
29
- }
30
- export function detailString(name) {
31
- return new BuilderComponentField(name, 'string');
32
- }
33
- export function detailNumber(name) {
34
- return new BuilderComponentField(name, 'number');
35
- }
36
- export function detailBoolean(name) {
37
- return new BuilderComponentField(name, 'boolean');
38
- }
39
- export const BuilderComponentFieldSchema = v.instance(BuilderComponentField);
40
- export const BuilderComponentFieldsSchema = v.pipe(v.array(BuilderComponentFieldSchema), v.readonly());
41
- export const BuilderComponentFieldSerialisedSchema = serialisable(v.object({
42
- type: v.literal('component-field'),
43
- name: NameSchema,
44
- valueType: BuilderComponentFieldValueTypeSchema,
45
- isOptional: BooleanSchema,
46
- tags: v.optional(BuilderTagsSchema)
47
- }));
48
- export const BuilderComponentFieldsSerialisedSchema = v.pipe(v.array(BuilderComponentFieldSerialisedSchema), v.readonly());
49
- export function detailValueSchema(valueType, optional) {
50
- const baseSchema = valueType === 'string' ? StringSchema : valueType === 'boolean' ? BooleanSchema : NumberSchema;
51
- return optional ? v.nullable(baseSchema) : baseSchema;
52
- }