Skip to content

Commit db1b836

Browse files
committed
[union] Lead release notes with enums
1 parent 3477318 commit db1b836

1 file changed

Lines changed: 28 additions & 28 deletions

File tree

site/guides/20_releases.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,40 @@ highlighted features.
77

88
# v9.5
99

10+
## Native Enum Schemas
11+
12+
CellSchema and ValueSchema can now use an `enum` property instead of `type` to
13+
allow only specific primitive values (as requested in issue
14+
[#38](https://github.com/tinyplex/tinybase/issues/38)). Enums must be non-empty,
15+
can mix strings, finite numbers, and booleans, and continue to use `allowNull`
16+
when `null` is also valid.
17+
18+
```js
19+
import {createStore} from 'tinybase';
20+
21+
const enumStore = createStore().setValuesSchema({
22+
status: {enum: ['available', 'adopted'], default: 'available'},
23+
rating: {enum: ['good', 5, true], allowNull: true},
24+
});
25+
26+
enumStore.setValues({status: 'adopted', rating: true});
27+
enumStore.setValue('status', 'missing');
28+
console.log(enumStore.getValues());
29+
// -> {status: 'available', rating: true}
30+
```
31+
32+
Each schema entry must use exactly one of `type` or `enum`. Defaults are used
33+
only when they are enum members, or are `null` when null is allowed. The
34+
schema-aware Store APIs infer exact unions from enum members, and the Zod,
35+
Valibot, ArkType, Effect Schema, TypeBox, and Yup schematizers now preserve
36+
supported primitive enum and literal constraints in the schemas they produce.
37+
1038
## Native Schema Type Unions
1139

1240
CellSchema and ValueSchema can now accept an array in the `type` property when
1341
a Cell or Value can have more than one broad type:
1442

1543
```js
16-
import {createStore} from 'tinybase';
17-
1844
const unionStore = createStore().setValuesSchema({
1945
reference: {type: ['string', 'number'], default: 'unknown'},
2046
response: {type: ['boolean', 'object'], allowNull: true},
@@ -37,32 +63,6 @@ ArkType, Effect Schema, TypeBox, Valibot, and Zod schematizers also preserve
3763
supported broad type unions, while continuing to preserve literal-only unions
3864
as exact enums.
3965

40-
## Native Enum Schemas
41-
42-
CellSchema and ValueSchema can now use an `enum` property instead of `type` to
43-
allow only specific primitive values (as requested in issue
44-
[#38](https://github.com/tinyplex/tinybase/issues/38)). Enums must be non-empty,
45-
can mix strings, finite numbers, and booleans, and continue to use `allowNull`
46-
when `null` is also valid.
47-
48-
```js
49-
const enumStore = createStore().setValuesSchema({
50-
status: {enum: ['available', 'adopted'], default: 'available'},
51-
rating: {enum: ['good', 5, true], allowNull: true},
52-
});
53-
54-
enumStore.setValues({status: 'adopted', rating: true});
55-
enumStore.setValue('status', 'missing');
56-
console.log(enumStore.getValues());
57-
// -> {status: 'available', rating: true}
58-
```
59-
60-
Each schema entry must use exactly one of `type` or `enum`. Defaults are used
61-
only when they are enum members, or are `null` when null is allowed. The
62-
schema-aware Store APIs infer exact unions from enum members, and the Zod,
63-
Valibot, ArkType, Effect Schema, TypeBox, and Yup schematizers now preserve
64-
supported primitive enum and literal constraints in the schemas they produce.
65-
6666
---
6767

6868
# v9.4

0 commit comments

Comments
 (0)