@valbuild/cli 0.125.0 → 0.126.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,94 @@
1
1
  # @valbuild/cli
2
2
 
3
+ ## 0.126.0
4
+
5
+ ### Patch Changes
6
+
7
+ - [#652](https://github.com/valbuild/val/pull/652) [`f2fe70d`](https://github.com/valbuild/val/commit/f2fe70dab2b65000dfaf289f09c70b4a8291467a) Thanks [@freekh](https://github.com/freekh)! - `s.union` is now `s.discriminatedUnion` and `s.enum`.
8
+
9
+ `s.union` did two unrelated jobs and worked out which one you meant from its
10
+ first argument: a string key meant a tagged union of objects, literal schemas
11
+ meant a set of allowed strings. Those are now two schemas with two names.
12
+
13
+ ```ts
14
+ // A fixed set of strings — presents as a dropdown
15
+ s.enum("primary", "secondary", "ghost"); // Schema<"primary" | "secondary" | "ghost">
16
+
17
+ // One of several object shapes, told apart by a tag field
18
+ s.discriminatedUnion(
19
+ "type",
20
+ s.object({ type: s.literal("hero"), heading: s.string() }),
21
+ s.object({ type: s.literal("quote"), text: s.string() }),
22
+ );
23
+ ```
24
+
25
+ `s.enum` takes the strings directly, so the `s.literal(...)` wrapper is gone.
26
+
27
+ **`s.union` still works** — it is deprecated, and it builds exactly the schema
28
+ above, so nothing has to change today:
29
+
30
+ ```ts
31
+ s.union(s.literal("one"), s.literal("two")); // → s.enum("one", "two")
32
+ s.union("type", pageA, pageB); // → s.discriminatedUnion("type", pageA, pageB)
33
+ ```
34
+
35
+ The two are different kinds of node, and that is the reason for the split. A
36
+ discriminated union is a container: the selected variant's fields are the fields
37
+ being edited, and everything that walks a schema descends through it. An enum is
38
+ a leaf — a string with a closed domain — so nothing recurses into it. Told apart
39
+ only by the shape of `key`, every consumer had to re-derive which one it was
40
+ holding; each now has its own serialized type (`"discriminated-union"` and
41
+ `"enum"`) and Val Studio has a field per kind rather than one field that
42
+ branches.
43
+
44
+ Two behaviour changes fall out of the split, both of them fixes:
45
+
46
+ - A value that is not a string at all now fails an enum's validation with a
47
+ type error. `s.union` of literals only ever checked the value against its
48
+ literals when the value WAS a string, so a number or an object where an enum
49
+ was declared validated clean.
50
+ - An enum field now shows its validation errors in Val Studio where the field
51
+ is opened on its own — the module editor and the canvas's fields column — and
52
+ gets the compact error layout inside an inline list row. It is a leaf now, so
53
+ it goes through the same error rendering as every other leaf field; the string
54
+ union bypassed it and showed nothing in those places.
55
+
56
+ Several latent crashes in the old `s.union` are fixed on the way past, all of
57
+ them cases where it threw a `TypeError` instead of reporting:
58
+
59
+ - A required discriminated union holding `null` now reports a type error rather
60
+ than throwing, and resolving a path underneath a nullable one that is `null`
61
+ gives the error the API promises instead of a crash.
62
+ - `s.literal("")` is a legal discriminator tag, and `s.enum("")` a legal value.
63
+ Both used to be treated as absent by a truthiness check — in path resolution,
64
+ in stega encoding, and in the message that lists a union's valid tags. The
65
+ editor's dropdowns handle them too: an empty value is reserved by the select
66
+ component and had to be mapped around.
67
+ - A variant that omits the discriminator entirely is now reported as the schema
68
+ error it is, instead of throwing while the check looked for it.
69
+ - An enum's value is now indexed for search, like every other string leaf. The
70
+ old string union was never indexed at all, so searching for one of its values
71
+ could not find the field.
72
+ - A nullable discriminated union set to `null` no longer renders a spinner that
73
+ never resolves.
74
+
75
+ `s.discriminatedUnion` also requires at least one variant, as `s.enum` requires
76
+ at least one value: a union with nothing to select is not a thing to write, and
77
+ everything downstream reads the first variant where it needs any.
78
+
79
+ If you read serialized schemas yourself, that is the breaking part: `type` is no
80
+ longer `"union"`, an enum carries `values: string[]` instead of a `key` plus
81
+ `items` of literal schemas, and `UnionSchema` is no longer a class.
82
+ `SerializedUnionSchema`, `SerializedStringUnionSchema`,
83
+ `SerializedObjectUnionSchema` and `UnionSchema` remain as deprecated type
84
+ aliases.
85
+
86
+ - Updated dependencies [[`5bfd630`](https://github.com/valbuild/val/commit/5bfd630b63dee2189e238f20fe72ecc5537160f7), [`ccbcda6`](https://github.com/valbuild/val/commit/ccbcda60b3e3c465071229ae1ba28ac735483e63), [`f2fe70d`](https://github.com/valbuild/val/commit/f2fe70dab2b65000dfaf289f09c70b4a8291467a), [`5c18c99`](https://github.com/valbuild/val/commit/5c18c99ecc84651f82123481fc042063db953833), [`171208a`](https://github.com/valbuild/val/commit/171208a20177e68ed5a8b1a6fdaabfe893a6aa5f)]:
87
+ - @valbuild/shared@0.126.0
88
+ - @valbuild/server@0.126.0
89
+ - @valbuild/core@0.126.0
90
+ - @valbuild/language-server@0.126.0
91
+
3
92
  ## 0.125.0
4
93
 
5
94
  ### Patch Changes
@@ -1368,10 +1368,7 @@ function collectSchemaReferences(schema) {
1368
1368
  visit(item, false);
1369
1369
  }
1370
1370
  break;
1371
- case "union":
1372
- if (typeof node.key !== "string") {
1373
- visit(node.key, false);
1374
- }
1371
+ case "discriminated-union":
1375
1372
  for (const item of node.items) {
1376
1373
  visit(item, false);
1377
1374
  }
@@ -1368,10 +1368,7 @@ function collectSchemaReferences(schema) {
1368
1368
  visit(item, false);
1369
1369
  }
1370
1370
  break;
1371
- case "union":
1372
- if (typeof node.key !== "string") {
1373
- visit(node.key, false);
1374
- }
1371
+ case "discriminated-union":
1375
1372
  for (const item of node.items) {
1376
1373
  visit(item, false);
1377
1374
  }
@@ -1336,10 +1336,7 @@ function collectSchemaReferences(schema) {
1336
1336
  visit(item, false);
1337
1337
  }
1338
1338
  break;
1339
- case "union":
1340
- if (typeof node.key !== "string") {
1341
- visit(node.key, false);
1342
- }
1339
+ case "discriminated-union":
1343
1340
  for (const item of node.items) {
1344
1341
  visit(item, false);
1345
1342
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@valbuild/cli",
3
3
  "private": false,
4
- "version": "0.125.0",
4
+ "version": "0.126.0",
5
5
  "description": "Val CLI tools",
6
6
  "repository": {
7
7
  "type": "git",
@@ -24,11 +24,11 @@
24
24
  "jszip": "^3.10.1",
25
25
  "meow": "^9.0.0",
26
26
  "picocolors": "^1.1.1",
27
+ "@valbuild/core": "0.126.0",
27
28
  "@valbuild/eslint-plugin": "0.125.0",
28
- "@valbuild/core": "0.125.0",
29
- "@valbuild/shared": "0.125.0",
30
- "@valbuild/language-server": "0.125.0",
31
- "@valbuild/server": "0.125.0"
29
+ "@valbuild/language-server": "0.126.0",
30
+ "@valbuild/server": "0.126.0",
31
+ "@valbuild/shared": "0.126.0"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "prettier": "*",
@@ -150,10 +150,7 @@ function collectSchemaReferences(schema: SerializedSchema): SchemaReferences {
150
150
  visit(item, false);
151
151
  }
152
152
  break;
153
- case "union":
154
- if (typeof node.key !== "string") {
155
- visit(node.key, false);
156
- }
153
+ case "discriminated-union":
157
154
  for (const item of node.items) {
158
155
  visit(item, false);
159
156
  }