Skip to content

Commit 811c6f2

Browse files
committed
[shcmeatizer] Effect
1 parent 97fee18 commit 811c6f2

15 files changed

Lines changed: 427 additions & 14 deletions

File tree

coverage.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"tests":7168,"assertions":32041,"lines":{"total":2341,"covered":2341,"skipped":0,"pct":100},"statements":{"total":2534,"covered":2534,"skipped":0,"pct":100},"functions":{"total":1010,"covered":1010,"skipped":0,"pct":100},"branches":{"total":892,"covered":892,"skipped":0,"pct":100},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}}
1+
{"tests":7180,"assertions":32053,"lines":{"total":2341,"covered":2341,"skipped":0,"pct":100},"statements":{"total":2534,"covered":2534,"skipped":0,"pct":100},"functions":{"total":1010,"covered":1010,"skipped":0,"pct":100},"branches":{"total":892,"covered":892,"skipped":0,"pct":100},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}}

gulpfile.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const ALL_MODULES = [
4747
'relationships',
4848
'schematizers',
4949
'schematizers/schematizer-arktype',
50+
'schematizers/schematizer-effect',
5051
'schematizers/schematizer-typebox',
5152
'schematizers/schematizer-valibot',
5253
'schematizers/schematizer-yup',

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"@vlcn.io/crsqlite-wasm": "^0.16.0",
3232
"arktype": "^2.1.28",
3333
"bun": "^1.3.3",
34+
"effect": "^3.19.10",
3435
"electric-sql": "^0.12.1",
3536
"expo": "^54.0.10",
3637
"expo-sqlite": "^16.0.10",
@@ -78,6 +79,9 @@
7879
"bun": {
7980
"optional": true
8081
},
82+
"effect": {
83+
"optional": true
84+
},
8185
"electric-sql": {
8286
"optional": true
8387
},
@@ -210,6 +214,7 @@
210214
"bun": "^1.3.4",
211215
"country-flag-emoji-json": "^2.0.0",
212216
"cspell": "^9.4.0",
217+
"effect": "^3.19.10",
213218
"electric-sql": "^0.12.1",
214219
"esbuild": "^0.27.1",
215220
"eslint": "^9.39.1",
@@ -257,4 +262,4 @@
257262
"yup": "^1.7.1",
258263
"zod": "^4.1.13"
259264
}
260-
}
265+
}

site/build.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ const addApi = (docs: Docs): Docs =>
263263
.addApiFile('dist/@types/persisters/persister-yjs/index.d.ts')
264264
.addApiFile('dist/@types/schematizers/index.d.ts')
265265
.addApiFile('dist/@types/schematizers/schematizer-arktype/index.d.ts')
266+
.addApiFile('dist/@types/schematizers/schematizer-effect/index.d.ts')
266267
.addApiFile('dist/@types/schematizers/schematizer-typebox/index.d.ts')
267268
.addApiFile('dist/@types/schematizers/schematizer-valibot/index.d.ts')
268269
.addApiFile('dist/@types/schematizers/schematizer-yup/index.d.ts')

site/extras/effect.svg

Lines changed: 15 additions & 0 deletions
Loading

site/guides/03_schemas/4_using_schematizers.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ from libraries like Zod, TypeBox, and Valibot, and convert them at runtime using
88
a schematizer. The full list of supported schema systems and their entry points
99
is as follows:
1010

11-
| Library | Creation function |
12-
| -------------------------------------------------- | ------------------------ |
13-
| [Zod](https://github.com/colinhacks/zod) | createZodSchematizer |
14-
| [TypeBox](https://github.com/sinclairzx81/typebox) | createTypeBoxSchematizer |
15-
| [Valibot](https://github.com/valibot/valibot) | createValibotSchematizer |
16-
| [ArkType](https://github.com/arktypeio/arktype) | createArkTypeSchematizer |
17-
| [Yup](https://github.com/jquense/yup) | createYupSchematizer |
11+
| Library | Creation function |
12+
| ---------------------------------------------------- | ------------------------ |
13+
| [Zod](https://github.com/colinhacks/zod) | createZodSchematizer |
14+
| [TypeBox](https://github.com/sinclairzx81/typebox) | createTypeBoxSchematizer |
15+
| [Valibot](https://github.com/valibot/valibot) | createValibotSchematizer |
16+
| [ArkType](https://github.com/arktypeio/arktype) | createArkTypeSchematizer |
17+
| [Yup](https://github.com/jquense/yup) | createYupSchematizer |
18+
| [Effect Schema](https://github.com/Effect-TS/effect) | createEffectSchematizer |
1819

1920
The createCustomSchematizer function also allows you to create your own
2021
schematizer that convert from any schema system not supported directly by

site/guides/16_releases.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,16 @@ console.log(schematizedStore.getRow('pets', 'fido'));
4444
Schematizers perform best-effort conversions, extracting basic type information
4545
(string, number, boolean), defaults, and nullable settings from your schemas.
4646

47-
This release includes support for Zod via the createZodSchematizer function,
48-
TypeBox via the createTypeBoxSchematizer function, Valibot via the
49-
createValibotSchematizer function, and ArkType via the createArkTypeSchematizer
50-
function, with support for additional libraries planned for future releases.
47+
This release includes support for:
48+
49+
- **Zod** via the createZodSchematizer function
50+
- **TypeBox** via the createTypeBoxSchematizer function
51+
- **Valibot** via the createValibotSchematizer function
52+
- **ArkType** via the createArkTypeSchematizer function
53+
- **Yup** via the createYupSchematizer function
54+
- **Effect Schema** via the createEffectSchematizer function
55+
56+
Additional libraries are planned for future releases.
5157

5258
For more information, see the Using Schematizers guide.
5359

site/home/index.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,16 @@
175175
<img width="48" src="/arktype.svg?asImg" /> ArkType
176176
</a>
177177
</div>
178+
<div>
179+
<a href='/api/schematizer-yup/functions/creation/createyupschematizer'>
180+
<img width="48" src="/yup.svg?asImg" /> Yup
181+
</a>
182+
</div>
183+
<div>
184+
<a href='/api/schematizer-effect/functions/creation/createeffectschematizer'>
185+
<img width="48" src="/effect.svg?asImg" /> Effect Schema
186+
</a>
187+
</div>
178188
<p>
179189
(Baffled by all these logos? Check out our
180190
<a href='/guides/the-basics/architectural-options'>architectural
@@ -349,7 +359,7 @@ root.unmount(); // !act
349359
> from the data schemas you apply.
350360
>
351361
> And our 'schematizer' modules let you convert schemas from libraries like Zod,
352-
> TypeBox, and Valibot into TinyBase at runtime.
362+
> TypeBox, Valibot, ArkType, Yup, and Effect Schema into TinyBase at runtime.
353363
>
354364
> Read more about schemas in the Schemas guide.
355365
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/**
2+
* The schematizer-effect module provides conversion utilities for Effect
3+
* Schema schemas.
4+
* @packageDocumentation
5+
* @module schematizer-effect
6+
* @since v7.1.0
7+
*/
8+
/// schematizer-effect
9+
10+
/**
11+
* The EffectSchematizer interface represents a schematizer specifically for
12+
* converting Effect Schema schemas into TinyBase schemas.
13+
* @category Schematizer
14+
* @since v7.1.0
15+
*/
16+
/// EffectSchematizer
17+
18+
/**
19+
* The toTablesSchema method converts a mapping of Effect Schema struct schemas
20+
* into a TinyBase TablesSchema.
21+
*
22+
* This method extracts basic type information (string, number, boolean),
23+
* nullable flags, and optional flags from Effect schemas. Default values are
24+
* not supported as they exist in Effect's runtime transformations, not in the
25+
* schema AST. Complex validation rules, transformations, and refinements are
26+
* ignored.
27+
* @param schemas - A mapping of table IDs to Effect Schema struct schemas.
28+
* @returns A TinyBase TablesSchema.
29+
* @example
30+
* This example converts Effect Schema schemas to TinyBase format.
31+
*
32+
* ```js
33+
* import {Boolean, Number, String, Struct} from 'effect/Schema';
34+
* import {createStore} from 'tinybase';
35+
* import {createEffectSchematizer} from 'tinybase/schematizers/schematizer-effect';
36+
*
37+
* const schematizer = createEffectSchematizer();
38+
*
39+
* const tablesSchema = schematizer.toTablesSchema({
40+
* pets: Struct({
41+
* species: String,
42+
* age: Number,
43+
* sold: Boolean,
44+
* }),
45+
* });
46+
*
47+
* const store = createStore().setTablesSchema(tablesSchema);
48+
* store.setRow('pets', 'fido', {species: 'dog', age: 3, sold: false});
49+
* console.log(store.getRow('pets', 'fido'));
50+
* // -> {species: 'dog', age: 3, sold: false}
51+
* ```
52+
* @category Conversion
53+
* @since v7.1.0
54+
*/
55+
/// EffectSchematizer.toTablesSchema
56+
57+
/**
58+
* The toValuesSchema method converts a mapping of Effect Schema schemas into a
59+
* TinyBase ValuesSchema.
60+
*
61+
* This method extracts basic type information (string, number, boolean),
62+
* nullable flags, and optional flags from Effect schemas. Default values are
63+
* not supported as they exist in Effect's runtime transformations, not in the
64+
* schema AST.
65+
* @param schemas - A mapping of value IDs to Effect Schema schemas.
66+
* @returns A TinyBase ValuesSchema.
67+
* @example
68+
* This example converts Effect Schema schemas to TinyBase values.
69+
*
70+
* ```js
71+
* import {Boolean, Number} from 'effect/Schema';
72+
* import {createStore} from 'tinybase';
73+
* import {createEffectSchematizer} from 'tinybase/schematizers/schematizer-effect';
74+
*
75+
* const schematizer = createEffectSchematizer();
76+
*
77+
* const valuesSchema = schematizer.toValuesSchema({
78+
* open: Boolean,
79+
* employees: Number,
80+
* });
81+
*
82+
* const store = createStore().setValuesSchema(valuesSchema);
83+
* store.setValues({open: true, employees: 3});
84+
* console.log(store.getValues());
85+
* // -> {open: true, employees: 3}
86+
* ```
87+
* @category Conversion
88+
* @since v7.1.0
89+
*/
90+
/// EffectSchematizer.toValuesSchema
91+
92+
/**
93+
* The createEffectSchematizer function creates an EffectSchematizer instance
94+
* for converting Effect Schema schemas to TinyBase schemas.
95+
* @returns A new EffectSchematizer instance.
96+
* @example
97+
* This example creates an Effect Schema schematizer.
98+
*
99+
* ```js
100+
* import {String, Struct} from 'effect/Schema';
101+
* import {createEffectSchematizer} from 'tinybase/schematizers/schematizer-effect';
102+
*
103+
* const schematizer = createEffectSchematizer();
104+
*
105+
* const tablesSchema = schematizer.toTablesSchema({
106+
* pets: Struct({
107+
* species: String,
108+
* }),
109+
* });
110+
*
111+
* console.log(tablesSchema);
112+
* // -> {pets: {species: {type: 'string'}}}
113+
* ```
114+
* @category Creation
115+
* @since v7.1.0
116+
*/
117+
/// createEffectSchematizer
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// schematizer-effect
2+
import type {TablesSchema, ValuesSchema} from '../../store/index.d.ts';
3+
import type {Schematizer} from '../index.d.ts';
4+
5+
/// EffectSchematizer
6+
export interface EffectSchematizer extends Schematizer {
7+
/// EffectSchematizer.toTablesSchema
8+
toTablesSchema(schemas: {[tableId: string]: any}): TablesSchema;
9+
10+
/// EffectSchematizer.toValuesSchema
11+
toValuesSchema(schemas: {[valueId: string]: any}): ValuesSchema;
12+
}
13+
14+
/// createEffectSchematizer
15+
export function createEffectSchematizer(): EffectSchematizer;

0 commit comments

Comments
 (0)