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