tinybase 7.1.0-beta.1 → 7.1.0-beta.3

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 (47) hide show
  1. package/@types/schematizers/index.d.ts +57 -0
  2. package/@types/schematizers/schematizer-typebox/index.d.ts +116 -0
  3. package/@types/schematizers/schematizer-typebox/with-schemas/index.d.ts +8 -0
  4. package/@types/schematizers/schematizer-valibot/index.d.ts +114 -0
  5. package/@types/schematizers/schematizer-valibot/with-schemas/index.d.ts +8 -0
  6. package/@types/schematizers/schematizer-zod/with-schemas/index.d.ts +1 -4
  7. package/index.js +2 -1
  8. package/mergeable-store/index.js +2 -1
  9. package/mergeable-store/with-schemas/index.js +2 -1
  10. package/min/schematizers/index.js +1 -1
  11. package/min/schematizers/index.js.gz +0 -0
  12. package/min/schematizers/schematizer-typebox/index.js +1 -0
  13. package/min/schematizers/schematizer-typebox/index.js.gz +0 -0
  14. package/min/schematizers/schematizer-typebox/with-schemas/index.js +1 -0
  15. package/min/schematizers/schematizer-typebox/with-schemas/index.js.gz +0 -0
  16. package/min/schematizers/schematizer-valibot/index.js +1 -0
  17. package/min/schematizers/schematizer-valibot/index.js.gz +0 -0
  18. package/min/schematizers/schematizer-valibot/with-schemas/index.js +1 -0
  19. package/min/schematizers/schematizer-valibot/with-schemas/index.js.gz +0 -0
  20. package/min/schematizers/schematizer-zod/index.js +1 -1
  21. package/min/schematizers/schematizer-zod/index.js.gz +0 -0
  22. package/min/schematizers/schematizer-zod/with-schemas/index.js +1 -1
  23. package/min/schematizers/schematizer-zod/with-schemas/index.js.gz +0 -0
  24. package/min/schematizers/with-schemas/index.js +1 -1
  25. package/min/schematizers/with-schemas/index.js.gz +0 -0
  26. package/omni/index.js +2 -1
  27. package/omni/with-schemas/index.js +2 -1
  28. package/package.json +81 -1
  29. package/queries/index.js +2 -1
  30. package/queries/with-schemas/index.js +2 -1
  31. package/readme.md +3 -3
  32. package/releases.md +25 -1
  33. package/schematizers/index.js +89 -0
  34. package/schematizers/schematizer-typebox/index.js +107 -0
  35. package/schematizers/schematizer-typebox/with-schemas/index.js +107 -0
  36. package/schematizers/schematizer-valibot/index.js +106 -0
  37. package/schematizers/schematizer-valibot/with-schemas/index.js +106 -0
  38. package/schematizers/schematizer-zod/index.js +39 -35
  39. package/schematizers/schematizer-zod/with-schemas/index.js +39 -35
  40. package/schematizers/with-schemas/index.js +89 -0
  41. package/store/index.js +2 -1
  42. package/store/with-schemas/index.js +2 -1
  43. package/ui-react-dom/index.js +2 -1
  44. package/ui-react-dom/with-schemas/index.js +2 -1
  45. package/ui-react-inspector/index.js +2 -1
  46. package/ui-react-inspector/with-schemas/index.js +2 -1
  47. package/with-schemas/index.js +2 -1
@@ -39,3 +39,60 @@ export interface Schematizer {
39
39
  */
40
40
  toValuesSchema(schemas: any): ValuesSchema;
41
41
  }
42
+
43
+ /**
44
+ * The createCustomSchematizer function creates a custom Schematizer that can
45
+ * convert schemas from any validation library into TinyBase schemas.
46
+ *
47
+ * This function allows you to build schematizers for validation libraries not
48
+ * natively supported by TinyBase. You provide two functions: one to unwrap
49
+ * optional/nullable/default wrappers from your library's schemas, and one to
50
+ * extract object properties.
51
+ * @param unwrapSchema - A function that unwraps a schema to extract the base
52
+ * type, default value, and nullable flag. It should recursively unwrap
53
+ * optional/nullable wrappers and return a tuple of [schema, defaultValue,
54
+ * allowNull].
55
+ * @param getProperties - A function that extracts the properties/entries/shape
56
+ * from an object schema. Returns undefined if the schema is not an object.
57
+ * @returns A new Schematizer instance.
58
+ * @example
59
+ * This example creates a custom schematizer for a hypothetical validation
60
+ * library.
61
+ *
62
+ * ```js
63
+ * import {createCustomSchematizer} from 'tinybase/schematizers';
64
+ *
65
+ * // Hypothetical library has schemas like:
66
+ * // {type: 'string'}, {type: 'optional', inner: ...}, etc.
67
+ *
68
+ * const unwrapSchema = (schema, defaultValue, allowNull) => {
69
+ * if (schema.type === 'optional') {
70
+ * return unwrapSchema(schema.inner, defaultValue, allowNull);
71
+ * }
72
+ * if (schema.type === 'nullable') {
73
+ * return unwrapSchema(schema.inner, defaultValue, true);
74
+ * }
75
+ * return [schema, defaultValue ?? schema.default, allowNull ?? false];
76
+ * };
77
+ *
78
+ * const getProperties = (schema) => schema.fields;
79
+ *
80
+ * const schematizer = createCustomSchematizer(unwrapSchema, getProperties);
81
+ *
82
+ * const tablesSchema = schematizer.toTablesSchema({
83
+ * pets: {type: 'object', fields: {name: {type: 'string'}}},
84
+ * });
85
+ * console.log(tablesSchema);
86
+ * // -> {pets: {name: {type: 'string'}}}
87
+ * ```
88
+ * @category Creation
89
+ * @since v7.1.0
90
+ */
91
+ export function createCustomSchematizer(
92
+ unwrapSchema: (
93
+ schema: any,
94
+ defaultValue?: any,
95
+ allowNull?: boolean,
96
+ ) => [any, any, boolean],
97
+ getProperties: (schema: any) => any | undefined,
98
+ ): Schematizer;
@@ -0,0 +1,116 @@
1
+ /**
2
+ * The schematizer-typebox module provides conversion utilities for TypeBox
3
+ * schemas.
4
+ * @packageDocumentation
5
+ * @module schematizer-typebox
6
+ * @since v7.1.0
7
+ */
8
+ import type {TablesSchema, ValuesSchema} from '../../store/index.d.ts';
9
+ import type {Schematizer} from '../index.d.ts';
10
+
11
+ /**
12
+ * The TypeBoxSchematizer interface represents a schematizer specifically for
13
+ * converting TypeBox schemas into TinyBase schemas.
14
+ * @category Schematizer
15
+ * @since v7.1.0
16
+ */
17
+ export interface TypeBoxSchematizer extends Schematizer {
18
+ /**
19
+ * The toTablesSchema method converts a mapping of TypeBox object schemas into a
20
+ * TinyBase TablesSchema.
21
+ *
22
+ * This method extracts basic type information (string, number, boolean),
23
+ * default values, and nullable flags from TypeBox schemas. Complex validation
24
+ * rules like min/max, patterns, formats, and custom validators are ignored.
25
+ * @param schemas - A mapping of table IDs to TypeBox object schemas.
26
+ * @returns A TinyBase TablesSchema.
27
+ * @example
28
+ * This example converts TypeBox schemas to TinyBase format.
29
+ *
30
+ * ```js
31
+ * import {Type} from '@sinclair/typebox';
32
+ * import {createStore} from 'tinybase';
33
+ * import {createTypeBoxSchematizer} from 'tinybase/schematizers/schematizer-typebox';
34
+ *
35
+ * const schematizer = createTypeBoxSchematizer();
36
+ *
37
+ * const tablesSchema = schematizer.toTablesSchema({
38
+ * pets: Type.Object({
39
+ * species: Type.String(),
40
+ * age: Type.Number(),
41
+ * sold: Type.Boolean({default: false}),
42
+ * }),
43
+ * });
44
+ *
45
+ * const store = createStore().setTablesSchema(tablesSchema);
46
+ * store.setRow('pets', 'fido', {species: 'dog', age: 3});
47
+ * console.log(store.getRow('pets', 'fido'));
48
+ * // -> {species: 'dog', age: 3, sold: false}
49
+ * ```
50
+ * @category Conversion
51
+ * @since v7.1.0
52
+ */
53
+ toTablesSchema(schemas: {[tableId: string]: any}): TablesSchema;
54
+
55
+ /**
56
+ * The toValuesSchema method converts a mapping of TypeBox schemas into a
57
+ * TinyBase ValuesSchema.
58
+ *
59
+ * This method extracts basic type information (string, number, boolean),
60
+ * default values, and nullable flags from TypeBox schemas.
61
+ * @param schemas - A mapping of value IDs to TypeBox schemas.
62
+ * @returns A TinyBase ValuesSchema.
63
+ * @example
64
+ * This example converts TypeBox schemas to TinyBase ValuesSchema format.
65
+ *
66
+ * ```js
67
+ * import {Type} from '@sinclair/typebox';
68
+ * import {createStore} from 'tinybase';
69
+ * import {createTypeBoxSchematizer} from 'tinybase/schematizers/schematizer-typebox';
70
+ *
71
+ * const schematizer = createTypeBoxSchematizer();
72
+ *
73
+ * const valuesSchema = schematizer.toValuesSchema({
74
+ * theme: Type.String({default: 'light'}),
75
+ * count: Type.Number(),
76
+ * isOpen: Type.Boolean(),
77
+ * });
78
+ *
79
+ * const store = createStore().setValuesSchema(valuesSchema);
80
+ * store.setValue('count', 42);
81
+ * console.log(store.getValues());
82
+ * // -> {theme: 'light', count: 42}
83
+ * ```
84
+ * @category Conversion
85
+ * @since v7.1.0
86
+ */
87
+ toValuesSchema(schemas: {[valueId: string]: any}): ValuesSchema;
88
+ }
89
+
90
+ /**
91
+ * The createTypeBoxSchematizer function creates a TypeBoxSchematizer object
92
+ * that can convert TypeBox schemas into TinyBase schemas.
93
+ *
94
+ * The schematizer is stateless and can be reused for multiple conversions.
95
+ * @returns A new TypeBoxSchematizer instance.
96
+ * @example
97
+ * This example creates a TypeBox schematizer and uses it to convert schemas.
98
+ *
99
+ * ```js
100
+ * import {Type} from '@sinclair/typebox';
101
+ * import {createTypeBoxSchematizer} from 'tinybase/schematizers/schematizer-typebox';
102
+ *
103
+ * const schematizer = createTypeBoxSchematizer();
104
+ *
105
+ * const tablesSchema = schematizer.toTablesSchema({
106
+ * pets: Type.Object({
107
+ * species: Type.String(),
108
+ * }),
109
+ * });
110
+ * console.log(tablesSchema);
111
+ * // -> {pets: {species: {type: 'string'}}}
112
+ * ```
113
+ * @category Creation
114
+ * @since v7.1.0
115
+ */
116
+ export function createTypeBoxSchematizer(): TypeBoxSchematizer;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The schematizer-typebox module provides conversion utilities for TypeBox
3
+ * schemas.
4
+ * @packageDocumentation
5
+ * @module schematizer-typebox
6
+ * @since v7.1.0
7
+ */
8
+ export type {TypeBoxSchematizer, createTypeBoxSchematizer} from '../index.d.ts';
@@ -0,0 +1,114 @@
1
+ /**
2
+ * The schematizer-valibot module provides conversion utilities for Valibot
3
+ * schemas.
4
+ * @packageDocumentation
5
+ * @module schematizer-valibot
6
+ * @since v7.1.0
7
+ */
8
+ import type {TablesSchema, ValuesSchema} from '../../store/index.d.ts';
9
+ import type {Schematizer} from '../index.d.ts';
10
+
11
+ /**
12
+ * The ValibotSchematizer interface represents a schematizer specifically for
13
+ * converting Valibot schemas into TinyBase schemas.
14
+ * @category Schematizer
15
+ * @since v7.1.0
16
+ */
17
+ export interface ValibotSchematizer extends Schematizer {
18
+ /**
19
+ * The toTablesSchema method converts a mapping of Valibot object schemas into a
20
+ * TinyBase TablesSchema.
21
+ *
22
+ * This method extracts basic type information (string, number, boolean),
23
+ * fallback values, and nullable flags from Valibot schemas. Complex validation
24
+ * rules like min/max, regex patterns, refinements, and transforms are ignored.
25
+ * @param schemas - A mapping of table IDs to Valibot object schemas.
26
+ * @returns A TinyBase TablesSchema.
27
+ * @example
28
+ * This example converts Valibot schemas to TinyBase format.
29
+ *
30
+ * ```js
31
+ * import {createStore} from 'tinybase';
32
+ * import {createValibotSchematizer} from 'tinybase/schematizers/schematizer-valibot';
33
+ * import {boolean, fallback, number, object, string} from 'valibot';
34
+ *
35
+ * const schematizer = createValibotSchematizer();
36
+ *
37
+ * const tablesSchema = schematizer.toTablesSchema({
38
+ * pets: object({
39
+ * species: string(),
40
+ * age: number(),
41
+ * sold: fallback(boolean(), false),
42
+ * }),
43
+ * });
44
+ *
45
+ * const store = createStore().setTablesSchema(tablesSchema);
46
+ * store.setRow('pets', 'fido', {species: 'dog', age: 3});
47
+ * console.log(store.getRow('pets', 'fido'));
48
+ * // -> {species: 'dog', age: 3, sold: false}
49
+ * ```
50
+ * @category Conversion
51
+ * @since v7.1.0
52
+ */
53
+ toTablesSchema(schemas: {[tableId: string]: any}): TablesSchema;
54
+
55
+ /**
56
+ * The toValuesSchema method converts a mapping of Valibot schemas into a
57
+ * TinyBase ValuesSchema.
58
+ *
59
+ * This method extracts basic type information and fallback values from Valibot
60
+ * schemas.
61
+ * @param schemas - A mapping of value IDs to Valibot schemas.
62
+ * @returns A TinyBase ValuesSchema.
63
+ * @example
64
+ * This example converts Valibot value schemas.
65
+ *
66
+ * ```js
67
+ * import {createStore} from 'tinybase';
68
+ * import {createValibotSchematizer} from 'tinybase/schematizers/schematizer-valibot';
69
+ * import {fallback, number, string} from 'valibot';
70
+ *
71
+ * const schematizer = createValibotSchematizer();
72
+ *
73
+ * const valuesSchema = schematizer.toValuesSchema({
74
+ * theme: fallback(string(), 'light'),
75
+ * count: number(),
76
+ * });
77
+ *
78
+ * const store = createStore().setValuesSchema(valuesSchema);
79
+ * console.log(store.getValues());
80
+ * // -> {theme: 'light'}
81
+ * ```
82
+ * @category Conversion
83
+ * @since v7.1.0
84
+ */
85
+ toValuesSchema(schemas: {[valueId: string]: any}): ValuesSchema;
86
+ }
87
+
88
+ /**
89
+ * The createValibotSchematizer function creates a ValibotSchematizer object
90
+ * that can convert Valibot schemas into TinyBase schemas.
91
+ *
92
+ * The schematizer is stateless and can be reused for multiple conversions.
93
+ * @returns A new ValibotSchematizer instance.
94
+ * @example
95
+ * This example creates a Valibot schematizer and uses it to convert schemas.
96
+ *
97
+ * ```js
98
+ * import {createValibotSchematizer} from 'tinybase/schematizers/schematizer-valibot';
99
+ * import {object, string} from 'valibot';
100
+ *
101
+ * const schematizer = createValibotSchematizer();
102
+ *
103
+ * const tablesSchema = schematizer.toTablesSchema({
104
+ * pets: object({
105
+ * species: string(),
106
+ * }),
107
+ * });
108
+ * console.log(tablesSchema);
109
+ * // -> {pets: {species: {type: 'string'}}}
110
+ * ```
111
+ * @category Creation
112
+ * @since v7.1.0
113
+ */
114
+ export function createValibotSchematizer(): ValibotSchematizer;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The schematizer-valibot module provides conversion utilities for Valibot
3
+ * schemas.
4
+ * @packageDocumentation
5
+ * @module schematizer-valibot
6
+ * @since v7.1.0
7
+ */
8
+ export type {ValibotSchematizer} from '../index.d.ts';
@@ -4,7 +4,4 @@
4
4
  * @module schematizer-zod
5
5
  * @since v7.1.0
6
6
  */
7
- export type {
8
- ZodSchematizer,
9
- createZodSchematizer,
10
- } from '../../schematizer-zod/index.d.ts';
7
+ export type {ZodSchematizer, createZodSchematizer} from '../index.d.ts';
package/index.js CHANGED
@@ -7,6 +7,7 @@ const FUNCTION = getTypeOf(getTypeOf);
7
7
  const TYPE = 'type';
8
8
  const DEFAULT = 'default';
9
9
  const ALLOW_NULL = 'allowNull';
10
+ const NULL = 'null';
10
11
  const SUM = 'sum';
11
12
  const AVG = 'avg';
12
13
  const MIN = 'min';
@@ -94,7 +95,7 @@ const arrayShift = (array) => array.shift();
94
95
 
95
96
  const getCellOrValueType = (cellOrValue) => {
96
97
  if (isNull(cellOrValue)) {
97
- return 'null';
98
+ return NULL;
98
99
  }
99
100
  const type = getTypeOf(cellOrValue);
100
101
  return isTypeStringOrBoolean(type) ||
@@ -7,6 +7,7 @@ const FUNCTION = getTypeOf(getTypeOf);
7
7
  const TYPE = 'type';
8
8
  const DEFAULT = 'default';
9
9
  const ALLOW_NULL = 'allowNull';
10
+ const NULL = 'null';
10
11
  const LISTENER = 'Listener';
11
12
  const SET = 'set';
12
13
  const ADD = 'add';
@@ -63,7 +64,7 @@ const tryCatch = async (action, then1, then2) => {
63
64
 
64
65
  const getCellOrValueType = (cellOrValue) => {
65
66
  if (isNull(cellOrValue)) {
66
- return 'null';
67
+ return NULL;
67
68
  }
68
69
  const type = getTypeOf(cellOrValue);
69
70
  return isTypeStringOrBoolean(type) ||
@@ -7,6 +7,7 @@ const FUNCTION = getTypeOf(getTypeOf);
7
7
  const TYPE = 'type';
8
8
  const DEFAULT = 'default';
9
9
  const ALLOW_NULL = 'allowNull';
10
+ const NULL = 'null';
10
11
  const LISTENER = 'Listener';
11
12
  const SET = 'set';
12
13
  const ADD = 'add';
@@ -63,7 +64,7 @@ const tryCatch = async (action, then1, then2) => {
63
64
 
64
65
  const getCellOrValueType = (cellOrValue) => {
65
66
  if (isNull(cellOrValue)) {
66
- return 'null';
67
+ return NULL;
67
68
  }
68
69
  const type = getTypeOf(cellOrValue);
69
70
  return isTypeStringOrBoolean(type) ||
@@ -1 +1 @@
1
-
1
+ const t=t=>typeof t,e=t(""),o=t(!0),r=t(0),n="type",s=t=>(e,o,r)=>t(e)?r?.():o(e),c=t=>null==t,l=s(c),u=s(t=>void 0===t),a=Object,f=t=>a.getPrototypeOf(t),p=a.entries,y=a.keys,h=a.freeze,i=(t=[])=>a.fromEntries(t),m=(t,e)=>((t,e)=>t.forEach(e))(p(t),([t,o])=>e(o,t)),b=(t,s)=>{const p=s=>{const[c,l,a]=t(s),f=c?.type;if(f!==e&&f!==r&&f!==o)return;const p={[n]:f};return u(l,t=>{p.default=t}),a&&(p.allowNull=!0),p};return h({toTablesSchema:t=>{const e=i();return m(t,(t,o)=>{const r=i();var n;u(s(t),t=>m(t,(t,e)=>u(p(t),t=>{r[e]=t}))),(t=>!c(t)&&l(f(t),t=>t==a.prototype||c(f(t)),()=>!0))(n=r)&&0==(t=>y(t).length)(n)||(e[o]=r)}),e},toValuesSchema:t=>{const e=i();return m(t,(t,o)=>u(p(t),t=>{e[o]=t})),e}})};export{b as createCustomSchematizer};
Binary file
@@ -0,0 +1 @@
1
+ const t=t=>typeof t,e=t(""),r=t(!0),n=t(0),o="type",s="default",c="null",l=t=>(e,r,n)=>t(e)?n?.():r(e),u=t=>null==t,f=l(u),p=l(t=>void 0===t),a=Object,y=t=>a.getPrototypeOf(t),i=a.entries,h=a.keys,m=a.freeze,d=(t=[])=>a.fromEntries(t),O=(t,e)=>((t,e)=>t.forEach(e))(i(t),([t,r])=>e(r,t)),b="anyOf",g=(t,e,r)=>{if(t?.[b]){const r=t[b],n=r.some(t=>t?.type===c),o=r.find(t=>t?.type!==c);if(n&&o)return g(o,e??t?.[s],!0)}return[t,e??t?.[s],r??!1]},v=t=>t?.properties,E=()=>((t,c)=>{const l=c=>{const[l,u,f]=t(c),a=l?.type;if(a!==e&&a!==n&&a!==r)return;const y={[o]:a};return p(u,t=>{y[s]=t}),f&&(y.allowNull=!0),y};return m({toTablesSchema:t=>{const e=d();return O(t,(t,r)=>{const n=d();var o;p(c(t),t=>O(t,(t,e)=>p(l(t),t=>{n[e]=t}))),(t=>!u(t)&&f(y(t),t=>t==a.prototype||u(y(t)),()=>!0))(o=n)&&0==(t=>h(t).length)(o)||(e[r]=n)}),e},toValuesSchema:t=>{const e=d();return O(t,(t,r)=>p(l(t),t=>{e[r]=t})),e}})})(g,v);export{E as createTypeBoxSchematizer};
@@ -0,0 +1 @@
1
+ const t=t=>typeof t,e=t(""),r=t(!0),n=t(0),o="type",s="default",c="null",l=t=>(e,r,n)=>t(e)?n?.():r(e),u=t=>null==t,f=l(u),p=l(t=>void 0===t),a=Object,y=t=>a.getPrototypeOf(t),i=a.entries,h=a.keys,m=a.freeze,d=(t=[])=>a.fromEntries(t),O=(t,e)=>((t,e)=>t.forEach(e))(i(t),([t,r])=>e(r,t)),b="anyOf",g=(t,e,r)=>{if(t?.[b]){const r=t[b],n=r.some(t=>t?.type===c),o=r.find(t=>t?.type!==c);if(n&&o)return g(o,e??t?.[s],!0)}return[t,e??t?.[s],r??!1]},v=t=>t?.properties,E=()=>((t,c)=>{const l=c=>{const[l,u,f]=t(c),a=l?.type;if(a!==e&&a!==n&&a!==r)return;const y={[o]:a};return p(u,t=>{y[s]=t}),f&&(y.allowNull=!0),y};return m({toTablesSchema:t=>{const e=d();return O(t,(t,r)=>{const n=d();var o;p(c(t),t=>O(t,(t,e)=>p(l(t),t=>{n[e]=t}))),(t=>!u(t)&&f(y(t),t=>t==a.prototype||u(y(t)),()=>!0))(o=n)&&0==(t=>h(t).length)(o)||(e[r]=n)}),e},toValuesSchema:t=>{const e=d();return O(t,(t,r)=>p(l(t),t=>{e[r]=t})),e}})})(g,v);export{E as createTypeBoxSchematizer};
@@ -0,0 +1 @@
1
+ const t=t=>typeof t,e=t(""),r=t(!0),o=t(0),n="type",l=t=>(e,r,o)=>t(e)?o?.():r(e),s=t=>null==t,a=l(s),c=l(t=>void 0===t),p=Object,u=t=>p.getPrototypeOf(t),f=p.entries,y=p.keys,i=p.freeze,b=(t=[])=>p.fromEntries(t),h=(t,e)=>((t,e)=>t.forEach(e))(f(t),([t,r])=>e(r,t)),d="wrapped",m=(t,e,r)=>{const o=t?.type;return"optional"===o?m(t[d],e,r):"nullable"===o?m(t[d],e,!0):[t,e??t?.fallback,r??!1]},g=t=>t?.entries,k=()=>((t,l)=>{const f=l=>{const[s,a,p]=t(l),u=s?.type;if(u!==e&&u!==o&&u!==r)return;const f={[n]:u};return c(a,t=>{f.default=t}),p&&(f.allowNull=!0),f};return i({toTablesSchema:t=>{const e=b();return h(t,(t,r)=>{const o=b();var n;c(l(t),t=>h(t,(t,e)=>c(f(t),t=>{o[e]=t}))),(t=>!s(t)&&a(u(t),t=>t==p.prototype||s(u(t)),()=>!0))(n=o)&&0==(t=>y(t).length)(n)||(e[r]=o)}),e},toValuesSchema:t=>{const e=b();return h(t,(t,r)=>c(f(t),t=>{e[r]=t})),e}})})(m,g);export{k as createValibotSchematizer};
@@ -0,0 +1 @@
1
+ const t=t=>typeof t,e=t(""),r=t(!0),o=t(0),n="type",l=t=>(e,r,o)=>t(e)?o?.():r(e),s=t=>null==t,a=l(s),c=l(t=>void 0===t),p=Object,u=t=>p.getPrototypeOf(t),f=p.entries,y=p.keys,i=p.freeze,b=(t=[])=>p.fromEntries(t),h=(t,e)=>((t,e)=>t.forEach(e))(f(t),([t,r])=>e(r,t)),d="wrapped",m=(t,e,r)=>{const o=t?.type;return"optional"===o?m(t[d],e,r):"nullable"===o?m(t[d],e,!0):[t,e??t?.fallback,r??!1]},g=t=>t?.entries,k=()=>((t,l)=>{const f=l=>{const[s,a,p]=t(l),u=s?.type;if(u!==e&&u!==o&&u!==r)return;const f={[n]:u};return c(a,t=>{f.default=t}),p&&(f.allowNull=!0),f};return i({toTablesSchema:t=>{const e=b();return h(t,(t,r)=>{const o=b();var n;c(l(t),t=>h(t,(t,e)=>c(f(t),t=>{o[e]=t}))),(t=>!s(t)&&a(u(t),t=>t==p.prototype||s(u(t)),()=>!0))(n=o)&&0==(t=>y(t).length)(n)||(e[r]=o)}),e},toValuesSchema:t=>{const e=b();return h(t,(t,r)=>c(f(t),t=>{e[r]=t})),e}})})(m,g);export{k as createValibotSchematizer};
@@ -1 +1 @@
1
- const e=e=>typeof e,t=e(""),n=e(!0),r=e(0),o="type",l="default",f=e=>(t,n,r)=>e(t)?r?.():n(t),s=e=>null==e,a=f(s),p=f(e=>void 0===e),u=Object,c=e=>u.getPrototypeOf(e),y=u.entries,d=u.keys,i=u.freeze,h=(e=[])=>u.fromEntries(e),T=(e,t)=>((e,t)=>e.forEach(t))(y(e),([e,n])=>t(n,e)),b=(e,t,n)=>{const r=e?.def?.type;return"optional"===r?b(e.def.innerType,t,n):"nullable"===r?b(e.def.innerType,t,!0):r===l?b(e.def.innerType,e.def.defaultValue,n):[e,t,n??!1]},m=()=>{const e=e=>{const[f,s,a]=b(e),u=f?.type;if(u!==t&&u!==r&&u!==n)return;const c={[o]:u};return p(s,e=>{c[l]=e}),a&&(c.allowNull=!0),c};return i({toTablesSchema:t=>{const n=h();return T(t,(t,r)=>{const o=h();var l;p(t?.def?.shape,t=>T(t,(t,n)=>p(e(t),e=>{o[n]=e}))),(e=>!s(e)&&a(c(e),e=>e==u.prototype||s(c(e)),()=>!0))(l=o)&&0==(e=>d(e).length)(l)||(n[r]=o)}),n},toValuesSchema:t=>{const n=h();return T(t,(t,r)=>p(e(t),e=>{n[r]=e})),n}})};export{m as createZodSchematizer};
1
+ const e=e=>typeof e,t=e(""),n=e(!0),r=e(0),o="type",l="default",f=e=>(t,n,r)=>e(t)?r?.():n(t),s=e=>null==e,a=f(s),p=f(e=>void 0===e),u=Object,c=e=>u.getPrototypeOf(e),y=u.entries,d=u.keys,i=u.freeze,h=(e=[])=>u.fromEntries(e),T=(e,t)=>((e,t)=>e.forEach(t))(y(e),([e,n])=>t(n,e)),b=(e,t,n)=>{const r=e?.def?.type;return"optional"===r?b(e.def.innerType,t,n):"nullable"===r?b(e.def.innerType,t,!0):r===l?b(e.def.innerType,e.def.defaultValue,n):[e,t,n??!1]},m=e=>e?.def?.shape,g=()=>((e,f)=>{const y=f=>{const[s,a,u]=e(f),c=s?.type;if(c!==t&&c!==r&&c!==n)return;const y={[o]:c};return p(a,e=>{y[l]=e}),u&&(y.allowNull=!0),y};return i({toTablesSchema:e=>{const t=h();return T(e,(e,n)=>{const r=h();var o;p(f(e),e=>T(e,(e,t)=>p(y(e),e=>{r[t]=e}))),(e=>!s(e)&&a(c(e),e=>e==u.prototype||s(c(e)),()=>!0))(o=r)&&0==(e=>d(e).length)(o)||(t[n]=r)}),t},toValuesSchema:e=>{const t=h();return T(e,(e,n)=>p(y(e),e=>{t[n]=e})),t}})})(b,m);export{g as createZodSchematizer};
@@ -1 +1 @@
1
- const e=e=>typeof e,t=e(""),n=e(!0),r=e(0),o="type",l="default",f=e=>(t,n,r)=>e(t)?r?.():n(t),s=e=>null==e,a=f(s),p=f(e=>void 0===e),u=Object,c=e=>u.getPrototypeOf(e),y=u.entries,d=u.keys,i=u.freeze,h=(e=[])=>u.fromEntries(e),T=(e,t)=>((e,t)=>e.forEach(t))(y(e),([e,n])=>t(n,e)),b=(e,t,n)=>{const r=e?.def?.type;return"optional"===r?b(e.def.innerType,t,n):"nullable"===r?b(e.def.innerType,t,!0):r===l?b(e.def.innerType,e.def.defaultValue,n):[e,t,n??!1]},m=()=>{const e=e=>{const[f,s,a]=b(e),u=f?.type;if(u!==t&&u!==r&&u!==n)return;const c={[o]:u};return p(s,e=>{c[l]=e}),a&&(c.allowNull=!0),c};return i({toTablesSchema:t=>{const n=h();return T(t,(t,r)=>{const o=h();var l;p(t?.def?.shape,t=>T(t,(t,n)=>p(e(t),e=>{o[n]=e}))),(e=>!s(e)&&a(c(e),e=>e==u.prototype||s(c(e)),()=>!0))(l=o)&&0==(e=>d(e).length)(l)||(n[r]=o)}),n},toValuesSchema:t=>{const n=h();return T(t,(t,r)=>p(e(t),e=>{n[r]=e})),n}})};export{m as createZodSchematizer};
1
+ const e=e=>typeof e,t=e(""),n=e(!0),r=e(0),o="type",l="default",f=e=>(t,n,r)=>e(t)?r?.():n(t),s=e=>null==e,a=f(s),p=f(e=>void 0===e),u=Object,c=e=>u.getPrototypeOf(e),y=u.entries,d=u.keys,i=u.freeze,h=(e=[])=>u.fromEntries(e),T=(e,t)=>((e,t)=>e.forEach(t))(y(e),([e,n])=>t(n,e)),b=(e,t,n)=>{const r=e?.def?.type;return"optional"===r?b(e.def.innerType,t,n):"nullable"===r?b(e.def.innerType,t,!0):r===l?b(e.def.innerType,e.def.defaultValue,n):[e,t,n??!1]},m=e=>e?.def?.shape,g=()=>((e,f)=>{const y=f=>{const[s,a,u]=e(f),c=s?.type;if(c!==t&&c!==r&&c!==n)return;const y={[o]:c};return p(a,e=>{y[l]=e}),u&&(y.allowNull=!0),y};return i({toTablesSchema:e=>{const t=h();return T(e,(e,n)=>{const r=h();var o;p(f(e),e=>T(e,(e,t)=>p(y(e),e=>{r[t]=e}))),(e=>!s(e)&&a(c(e),e=>e==u.prototype||s(c(e)),()=>!0))(o=r)&&0==(e=>d(e).length)(o)||(t[n]=r)}),t},toValuesSchema:e=>{const t=h();return T(e,(e,n)=>p(y(e),e=>{t[n]=e})),t}})})(b,m);export{g as createZodSchematizer};
@@ -1 +1 @@
1
-
1
+ const t=t=>typeof t,e=t(""),o=t(!0),r=t(0),n="type",s=t=>(e,o,r)=>t(e)?r?.():o(e),c=t=>null==t,l=s(c),u=s(t=>void 0===t),a=Object,f=t=>a.getPrototypeOf(t),p=a.entries,y=a.keys,h=a.freeze,i=(t=[])=>a.fromEntries(t),m=(t,e)=>((t,e)=>t.forEach(e))(p(t),([t,o])=>e(o,t)),b=(t,s)=>{const p=s=>{const[c,l,a]=t(s),f=c?.type;if(f!==e&&f!==r&&f!==o)return;const p={[n]:f};return u(l,t=>{p.default=t}),a&&(p.allowNull=!0),p};return h({toTablesSchema:t=>{const e=i();return m(t,(t,o)=>{const r=i();var n;u(s(t),t=>m(t,(t,e)=>u(p(t),t=>{r[e]=t}))),(t=>!c(t)&&l(f(t),t=>t==a.prototype||c(f(t)),()=>!0))(n=r)&&0==(t=>y(t).length)(n)||(e[o]=r)}),e},toValuesSchema:t=>{const e=i();return m(t,(t,o)=>u(p(t),t=>{e[o]=t})),e}})};export{b as createCustomSchematizer};
package/omni/index.js CHANGED
@@ -19,6 +19,7 @@ const TRUE = 'true';
19
19
  const TYPE = 'type';
20
20
  const DEFAULT = 'default';
21
21
  const ALLOW_NULL = 'allowNull';
22
+ const NULL = 'null';
22
23
  const UTF8 = 'utf8';
23
24
  const SUM = 'sum';
24
25
  const AVG = 'avg';
@@ -151,7 +152,7 @@ const arrayWith = (array, index, value) => array.with(index, value);
151
152
 
152
153
  const getCellOrValueType = (cellOrValue) => {
153
154
  if (isNull(cellOrValue)) {
154
- return 'null';
155
+ return NULL;
155
156
  }
156
157
  const type = getTypeOf(cellOrValue);
157
158
  return isTypeStringOrBoolean(type) ||
@@ -19,6 +19,7 @@ const TRUE = 'true';
19
19
  const TYPE = 'type';
20
20
  const DEFAULT = 'default';
21
21
  const ALLOW_NULL = 'allowNull';
22
+ const NULL = 'null';
22
23
  const UTF8 = 'utf8';
23
24
  const SUM = 'sum';
24
25
  const AVG = 'avg';
@@ -151,7 +152,7 @@ const arrayWith = (array, index, value) => array.with(index, value);
151
152
 
152
153
  const getCellOrValueType = (cellOrValue) => {
153
154
  if (isNull(cellOrValue)) {
154
- return 'null';
155
+ return NULL;
155
156
  }
156
157
  const type = getTypeOf(cellOrValue);
157
158
  return isTypeStringOrBoolean(type) ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinybase",
3
- "version": "7.1.0-beta.1",
3
+ "version": "7.1.0-beta.3",
4
4
  "author": "jamesgpearce",
5
5
  "repository": "github:tinyplex/tinybase",
6
6
  "license": "MIT",
@@ -26,6 +26,7 @@
26
26
  "@electric-sql/pglite": "^0.3.14",
27
27
  "@libsql/client": "^0.15.15",
28
28
  "@powersync/common": "^1.43.1",
29
+ "@sinclair/typebox": "^0.34.41",
29
30
  "@sqlite.org/sqlite-wasm": "^3.50.4-build1",
30
31
  "@vlcn.io/crsqlite-wasm": "^0.16.0",
31
32
  "bun": "^1.3.3",
@@ -40,6 +41,7 @@
40
41
  "react-native-mmkv": "4.1.0",
41
42
  "react-native-sqlite-storage": "^6.0.1",
42
43
  "sqlite3": "^5.1.7",
44
+ "valibot": "^1.2.0",
43
45
  "ws": "^8.18.3",
44
46
  "yjs": "^13.6.27",
45
47
  "zod": "^4.1.13"
@@ -60,6 +62,9 @@
60
62
  "@powersync/common": {
61
63
  "optional": true
62
64
  },
65
+ "@sinclair/typebox": {
66
+ "optional": true
67
+ },
63
68
  "@sqlite.org/sqlite-wasm": {
64
69
  "optional": true
65
70
  },
@@ -102,6 +107,9 @@
102
107
  "sqlite3": {
103
108
  "optional": true
104
109
  },
110
+ "valibot": {
111
+ "optional": true
112
+ },
105
113
  "ws": {
106
114
  "optional": true
107
115
  },
@@ -314,6 +322,18 @@
314
322
  "schematizers/with-schemas": [
315
323
  "./@types/schematizers/with-schemas/index.d.ts"
316
324
  ],
325
+ "schematizers/schematizer-typebox": [
326
+ "./@types/schematizers/schematizer-typebox/index.d.ts"
327
+ ],
328
+ "schematizers/schematizer-typebox/with-schemas": [
329
+ "./@types/schematizers/schematizer-typebox/with-schemas/index.d.ts"
330
+ ],
331
+ "schematizers/schematizer-valibot": [
332
+ "./@types/schematizers/schematizer-valibot/index.d.ts"
333
+ ],
334
+ "schematizers/schematizer-valibot/with-schemas": [
335
+ "./@types/schematizers/schematizer-valibot/with-schemas/index.d.ts"
336
+ ],
317
337
  "schematizers/schematizer-zod": [
318
338
  "./@types/schematizers/schematizer-zod/index.d.ts"
319
339
  ],
@@ -584,6 +604,18 @@
584
604
  "min/schematizers/with-schemas": [
585
605
  "./@types/schematizers/with-schemas/index.d.ts"
586
606
  ],
607
+ "min/schematizers/schematizer-typebox": [
608
+ "./@types/schematizers/schematizer-typebox/index.d.ts"
609
+ ],
610
+ "min/schematizers/schematizer-typebox/with-schemas": [
611
+ "./@types/schematizers/schematizer-typebox/with-schemas/index.d.ts"
612
+ ],
613
+ "min/schematizers/schematizer-valibot": [
614
+ "./@types/schematizers/schematizer-valibot/index.d.ts"
615
+ ],
616
+ "min/schematizers/schematizer-valibot/with-schemas": [
617
+ "./@types/schematizers/schematizer-valibot/with-schemas/index.d.ts"
618
+ ],
587
619
  "min/schematizers/schematizer-zod": [
588
620
  "./@types/schematizers/schematizer-zod/index.d.ts"
589
621
  ],
@@ -1055,6 +1087,30 @@
1055
1087
  "default": "./schematizers/index.js"
1056
1088
  }
1057
1089
  },
1090
+ "./schematizers/schematizer-typebox": {
1091
+ "default": {
1092
+ "types": "./@types/schematizers/schematizer-typebox/index.d.ts",
1093
+ "default": "./schematizers/schematizer-typebox/index.js"
1094
+ }
1095
+ },
1096
+ "./schematizers/schematizer-typebox/with-schemas": {
1097
+ "default": {
1098
+ "types": "./@types/schematizers/schematizer-typebox/with-schemas/index.d.ts",
1099
+ "default": "./schematizers/schematizer-typebox/index.js"
1100
+ }
1101
+ },
1102
+ "./schematizers/schematizer-valibot": {
1103
+ "default": {
1104
+ "types": "./@types/schematizers/schematizer-valibot/index.d.ts",
1105
+ "default": "./schematizers/schematizer-valibot/index.js"
1106
+ }
1107
+ },
1108
+ "./schematizers/schematizer-valibot/with-schemas": {
1109
+ "default": {
1110
+ "types": "./@types/schematizers/schematizer-valibot/with-schemas/index.d.ts",
1111
+ "default": "./schematizers/schematizer-valibot/index.js"
1112
+ }
1113
+ },
1058
1114
  "./schematizers/schematizer-zod": {
1059
1115
  "default": {
1060
1116
  "types": "./@types/schematizers/schematizer-zod/index.d.ts",
@@ -1595,6 +1651,30 @@
1595
1651
  "default": "./min/schematizers/index.js"
1596
1652
  }
1597
1653
  },
1654
+ "./min/schematizers/schematizer-typebox": {
1655
+ "default": {
1656
+ "types": "./@types/schematizers/schematizer-typebox/index.d.ts",
1657
+ "default": "./min/schematizers/schematizer-typebox/index.js"
1658
+ }
1659
+ },
1660
+ "./min/schematizers/schematizer-typebox/with-schemas": {
1661
+ "default": {
1662
+ "types": "./@types/schematizers/schematizer-typebox/with-schemas/index.d.ts",
1663
+ "default": "./min/schematizers/schematizer-typebox/index.js"
1664
+ }
1665
+ },
1666
+ "./min/schematizers/schematizer-valibot": {
1667
+ "default": {
1668
+ "types": "./@types/schematizers/schematizer-valibot/index.d.ts",
1669
+ "default": "./min/schematizers/schematizer-valibot/index.js"
1670
+ }
1671
+ },
1672
+ "./min/schematizers/schematizer-valibot/with-schemas": {
1673
+ "default": {
1674
+ "types": "./@types/schematizers/schematizer-valibot/with-schemas/index.d.ts",
1675
+ "default": "./min/schematizers/schematizer-valibot/index.js"
1676
+ }
1677
+ },
1598
1678
  "./min/schematizers/schematizer-zod": {
1599
1679
  "default": {
1600
1680
  "types": "./@types/schematizers/schematizer-zod/index.d.ts",
package/queries/index.js CHANGED
@@ -4,6 +4,7 @@ const STRING = getTypeOf(EMPTY_STRING);
4
4
  const BOOLEAN = getTypeOf(true);
5
5
  const NUMBER = getTypeOf(0);
6
6
  const FUNCTION = getTypeOf(getTypeOf);
7
+ const NULL = 'null';
7
8
  const SUM = 'sum';
8
9
  const AVG = 'avg';
9
10
  const MIN = 'min';
@@ -173,7 +174,7 @@ const getAggregateValue = (
173
174
 
174
175
  const getCellOrValueType = (cellOrValue) => {
175
176
  if (isNull(cellOrValue)) {
176
- return 'null';
177
+ return NULL;
177
178
  }
178
179
  const type = getTypeOf(cellOrValue);
179
180
  return isTypeStringOrBoolean(type) ||
@@ -4,6 +4,7 @@ const STRING = getTypeOf(EMPTY_STRING);
4
4
  const BOOLEAN = getTypeOf(true);
5
5
  const NUMBER = getTypeOf(0);
6
6
  const FUNCTION = getTypeOf(getTypeOf);
7
+ const NULL = 'null';
7
8
  const SUM = 'sum';
8
9
  const AVG = 'avg';
9
10
  const MIN = 'min';
@@ -173,7 +174,7 @@ const getAggregateValue = (
173
174
 
174
175
  const getCellOrValueType = (cellOrValue) => {
175
176
  if (isNull(cellOrValue)) {
176
- return 'null';
177
+ return NULL;
177
178
  }
178
179
  const type = getTypeOf(cellOrValue);
179
180
  return isTypeStringOrBoolean(type) ||