tinybase 9.4.0 → 9.5.0-beta.1

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 (126) hide show
  1. package/@types/_internal/store/with-schemas/index.d.ts +43 -8
  2. package/@types/mergeable-store/with-schemas/index.d.ts +30 -11
  3. package/@types/queries/index.d.ts +11 -11
  4. package/@types/queries/with-schemas/index.d.ts +17 -3
  5. package/@types/schematizers/index.d.ts +6 -4
  6. package/@types/schematizers/schematizer-arktype/index.d.ts +6 -6
  7. package/@types/schematizers/schematizer-arktype/with-schemas/index.d.ts +112 -1
  8. package/@types/schematizers/schematizer-effect/index.d.ts +9 -11
  9. package/@types/schematizers/schematizer-effect/with-schemas/index.d.ts +114 -1
  10. package/@types/schematizers/schematizer-typebox/index.d.ts +7 -7
  11. package/@types/schematizers/schematizer-typebox/with-schemas/index.d.ts +114 -1
  12. package/@types/schematizers/schematizer-valibot/index.d.ts +6 -6
  13. package/@types/schematizers/schematizer-valibot/with-schemas/index.d.ts +112 -1
  14. package/@types/schematizers/schematizer-yup/index.d.ts +5 -4
  15. package/@types/schematizers/schematizer-yup/with-schemas/index.d.ts +112 -1
  16. package/@types/schematizers/schematizer-zod/index.d.ts +6 -6
  17. package/@types/schematizers/schematizer-zod/with-schemas/index.d.ts +112 -1
  18. package/@types/schematizers/with-schemas/index.d.ts +113 -4
  19. package/@types/store/index.d.ts +175 -16
  20. package/@types/store/with-schemas/index.d.ts +238 -55
  21. package/@types/synchronizers/with-schemas/index.d.ts +12 -2
  22. package/@types/ui-react/with-schemas/index.d.ts +576 -7
  23. package/@types/ui-react-dom/index.d.ts +10 -10
  24. package/@types/ui-react-dom/with-schemas/index.d.ts +94 -10
  25. package/@types/ui-react-dom-charts/index.d.ts +7 -7
  26. package/@types/ui-react-dom-charts/with-schemas/index.d.ts +7 -7
  27. package/@types/ui-react-inspector/index.d.ts +1 -1
  28. package/@types/ui-react-inspector/with-schemas/index.d.ts +1 -1
  29. package/@types/ui-solid/with-schemas/index.d.ts +340 -7
  30. package/@types/ui-solid-dom/index.d.ts +10 -10
  31. package/@types/ui-solid-dom/with-schemas/index.d.ts +94 -10
  32. package/@types/ui-solid-inspector/index.d.ts +1 -1
  33. package/@types/ui-solid-inspector/with-schemas/index.d.ts +1 -1
  34. package/@types/ui-svelte/with-schemas/index.d.ts +30 -0
  35. package/@types/ui-svelte-dom/index.d.ts +10 -10
  36. package/@types/ui-svelte-dom/with-schemas/index.d.ts +94 -10
  37. package/@types/ui-svelte-inspector/index.d.ts +1 -1
  38. package/@types/ui-svelte-inspector/with-schemas/index.d.ts +1 -1
  39. package/agents.md +4 -0
  40. package/index.js +76 -22
  41. package/mergeable-store/index.js +76 -22
  42. package/mergeable-store/with-schemas/index.js +76 -22
  43. package/min/index.js +1 -1
  44. package/min/index.js.gz +0 -0
  45. package/min/mergeable-store/index.js +1 -1
  46. package/min/mergeable-store/index.js.gz +0 -0
  47. package/min/mergeable-store/with-schemas/index.js +1 -1
  48. package/min/mergeable-store/with-schemas/index.js.gz +0 -0
  49. package/min/omni/index.js +1 -1
  50. package/min/omni/index.js.gz +0 -0
  51. package/min/omni/with-schemas/index.js +1 -1
  52. package/min/omni/with-schemas/index.js.gz +0 -0
  53. package/min/schematizers/index.js +1 -1
  54. package/min/schematizers/index.js.gz +0 -0
  55. package/min/schematizers/schematizer-arktype/index.js +1 -1
  56. package/min/schematizers/schematizer-arktype/index.js.gz +0 -0
  57. package/min/schematizers/schematizer-arktype/with-schemas/index.js +1 -1
  58. package/min/schematizers/schematizer-arktype/with-schemas/index.js.gz +0 -0
  59. package/min/schematizers/schematizer-effect/index.js +1 -1
  60. package/min/schematizers/schematizer-effect/index.js.gz +0 -0
  61. package/min/schematizers/schematizer-effect/with-schemas/index.js +1 -1
  62. package/min/schematizers/schematizer-effect/with-schemas/index.js.gz +0 -0
  63. package/min/schematizers/schematizer-typebox/index.js +1 -1
  64. package/min/schematizers/schematizer-typebox/index.js.gz +0 -0
  65. package/min/schematizers/schematizer-typebox/with-schemas/index.js +1 -1
  66. package/min/schematizers/schematizer-typebox/with-schemas/index.js.gz +0 -0
  67. package/min/schematizers/schematizer-valibot/index.js +1 -1
  68. package/min/schematizers/schematizer-valibot/index.js.gz +0 -0
  69. package/min/schematizers/schematizer-valibot/with-schemas/index.js +1 -1
  70. package/min/schematizers/schematizer-valibot/with-schemas/index.js.gz +0 -0
  71. package/min/schematizers/schematizer-yup/index.js +1 -1
  72. package/min/schematizers/schematizer-yup/index.js.gz +0 -0
  73. package/min/schematizers/schematizer-yup/with-schemas/index.js +1 -1
  74. package/min/schematizers/schematizer-yup/with-schemas/index.js.gz +0 -0
  75. package/min/schematizers/schematizer-zod/index.js +1 -1
  76. package/min/schematizers/schematizer-zod/index.js.gz +0 -0
  77. package/min/schematizers/schematizer-zod/with-schemas/index.js +1 -1
  78. package/min/schematizers/schematizer-zod/with-schemas/index.js.gz +0 -0
  79. package/min/schematizers/with-schemas/index.js +1 -1
  80. package/min/schematizers/with-schemas/index.js.gz +0 -0
  81. package/min/store/index.js +1 -1
  82. package/min/store/index.js.gz +0 -0
  83. package/min/store/with-schemas/index.js +1 -1
  84. package/min/store/with-schemas/index.js.gz +0 -0
  85. package/min/ui-react-inspector/index.js +1 -1
  86. package/min/ui-react-inspector/index.js.gz +0 -0
  87. package/min/ui-react-inspector/with-schemas/index.js +1 -1
  88. package/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
  89. package/min/ui-solid-inspector/index.js +1 -1
  90. package/min/ui-solid-inspector/index.js.gz +0 -0
  91. package/min/ui-solid-inspector/with-schemas/index.js +1 -1
  92. package/min/ui-solid-inspector/with-schemas/index.js.gz +0 -0
  93. package/min/ui-svelte-inspector/index.js +1 -1
  94. package/min/ui-svelte-inspector/index.js.gz +0 -0
  95. package/min/ui-svelte-inspector/with-schemas/index.js +1 -1
  96. package/min/ui-svelte-inspector/with-schemas/index.js.gz +0 -0
  97. package/min/with-schemas/index.js +1 -1
  98. package/min/with-schemas/index.js.gz +0 -0
  99. package/omni/index.js +76 -22
  100. package/omni/with-schemas/index.js +76 -22
  101. package/package.json +2 -2
  102. package/readme.md +14 -14
  103. package/releases.md +95 -65
  104. package/schematizers/index.js +54 -6
  105. package/schematizers/schematizer-arktype/index.js +99 -19
  106. package/schematizers/schematizer-arktype/with-schemas/index.js +99 -19
  107. package/schematizers/schematizer-effect/index.js +101 -11
  108. package/schematizers/schematizer-effect/with-schemas/index.js +101 -11
  109. package/schematizers/schematizer-typebox/index.js +87 -11
  110. package/schematizers/schematizer-typebox/with-schemas/index.js +87 -11
  111. package/schematizers/schematizer-valibot/index.js +125 -21
  112. package/schematizers/schematizer-valibot/with-schemas/index.js +125 -21
  113. package/schematizers/schematizer-yup/index.js +58 -14
  114. package/schematizers/schematizer-yup/with-schemas/index.js +58 -14
  115. package/schematizers/schematizer-zod/index.js +131 -12
  116. package/schematizers/schematizer-zod/with-schemas/index.js +131 -12
  117. package/schematizers/with-schemas/index.js +54 -6
  118. package/store/index.js +76 -22
  119. package/store/with-schemas/index.js +76 -22
  120. package/ui-react-inspector/index.js +76 -22
  121. package/ui-react-inspector/with-schemas/index.js +76 -22
  122. package/ui-solid-inspector/index.js +76 -22
  123. package/ui-solid-inspector/with-schemas/index.js +76 -22
  124. package/ui-svelte-inspector/index.js +76 -22
  125. package/ui-svelte-inspector/with-schemas/index.js +76 -22
  126. package/with-schemas/index.js +76 -22
@@ -5,4 +5,117 @@
5
5
  * @module schematizer-typebox
6
6
  * @since v7.1.0
7
7
  */
8
- export type {TypeBoxSchematizer, createTypeBoxSchematizer} from '../index.d.ts';
8
+ import type {
9
+ TablesSchema,
10
+ ValuesSchema,
11
+ } from '../../../store/with-schemas/index.d.ts';
12
+ import type {Schematizer} from '../../with-schemas/index.d.ts';
13
+
14
+ /**
15
+ * The TypeBoxSchematizer interface represents a schematizer specifically for
16
+ * converting TypeBox schemas into TinyBase schemas.
17
+ * @category Schematizer
18
+ * @since v7.1.0
19
+ */
20
+ export interface TypeBoxSchematizer extends Schematizer {
21
+ /**
22
+ * The toTablesSchema method converts a mapping of TypeBox object schemas into a
23
+ * TinyBase TablesSchema.
24
+ *
25
+ * This method extracts basic type information (string, number, boolean), basic
26
+ * type unions, primitive enums and literals, default values, nullable flags,
27
+ * and required flags from TypeBox schemas. Complex validation rules like
28
+ * min/max, patterns, formats, and custom validators are ignored.
29
+ * @param schemas - A mapping of table IDs to TypeBox object schemas.
30
+ * @returns A TinyBase TablesSchema.
31
+ * @example
32
+ * This example converts TypeBox schemas to TinyBase format.
33
+ *
34
+ * ```js
35
+ * import {Type} from '@sinclair/typebox';
36
+ * import {createStore} from 'tinybase';
37
+ * import {createTypeBoxSchematizer} from 'tinybase/schematizers/schematizer-typebox';
38
+ *
39
+ * const schematizer = createTypeBoxSchematizer();
40
+ *
41
+ * const tablesSchema = schematizer.toTablesSchema({
42
+ * pets: Type.Object({
43
+ * species: Type.String(),
44
+ * age: Type.Number(),
45
+ * sold: Type.Boolean({default: false}),
46
+ * }),
47
+ * });
48
+ *
49
+ * const store = createStore().setTablesSchema(tablesSchema);
50
+ * store.setRow('pets', 'fido', {species: 'dog', age: 3});
51
+ * console.log(store.getRow('pets', 'fido'));
52
+ * // -> {species: 'dog', age: 3, sold: false}
53
+ * ```
54
+ * @category Conversion
55
+ * @since v7.1.0
56
+ */
57
+ toTablesSchema(schemas: {[tableId: string]: any}): TablesSchema;
58
+
59
+ /**
60
+ * The toValuesSchema method converts a mapping of TypeBox schemas into a
61
+ * TinyBase ValuesSchema.
62
+ *
63
+ * This method extracts basic type information (string, number, boolean), basic
64
+ * type unions, primitive enums and literals, default values, nullable flags,
65
+ * and required flags from TypeBox schemas.
66
+ * @param schemas - A mapping of value IDs to TypeBox schemas.
67
+ * @returns A TinyBase ValuesSchema.
68
+ * @example
69
+ * This example converts TypeBox schemas to TinyBase ValuesSchema format.
70
+ *
71
+ * ```js
72
+ * import {Type} from '@sinclair/typebox';
73
+ * import {createStore} from 'tinybase';
74
+ * import {createTypeBoxSchematizer} from 'tinybase/schematizers/schematizer-typebox';
75
+ *
76
+ * const schematizer = createTypeBoxSchematizer();
77
+ *
78
+ * const valuesSchema = schematizer.toValuesSchema({
79
+ * theme: Type.String({default: 'light'}),
80
+ * count: Type.Number(),
81
+ * isOpen: Type.Boolean(),
82
+ * });
83
+ *
84
+ * const store = createStore().setValuesSchema(valuesSchema);
85
+ * store.setValues({count: 42, isOpen: true});
86
+ * console.log(store.getValues());
87
+ * // -> {theme: 'light', count: 42, isOpen: true}
88
+ * ```
89
+ * @category Conversion
90
+ * @since v7.1.0
91
+ */
92
+ toValuesSchema(schemas: {[valueId: string]: any}): ValuesSchema;
93
+ }
94
+
95
+ /**
96
+ * The createTypeBoxSchematizer function creates a TypeBoxSchematizer object
97
+ * that can convert TypeBox schemas into TinyBase schemas.
98
+ *
99
+ * The schematizer is stateless and can be reused for multiple conversions.
100
+ * @returns A new TypeBoxSchematizer instance.
101
+ * @example
102
+ * This example creates a TypeBox schematizer and uses it to convert schemas.
103
+ *
104
+ * ```js
105
+ * import {Type} from '@sinclair/typebox';
106
+ * import {createTypeBoxSchematizer} from 'tinybase/schematizers/schematizer-typebox';
107
+ *
108
+ * const schematizer = createTypeBoxSchematizer();
109
+ *
110
+ * const tablesSchema = schematizer.toTablesSchema({
111
+ * pets: Type.Object({
112
+ * species: Type.String(),
113
+ * }),
114
+ * });
115
+ * console.log(tablesSchema);
116
+ * // -> {pets: {species: {type: 'string', required: true}}}
117
+ * ```
118
+ * @category Creation
119
+ * @since v7.1.0
120
+ */
121
+ export function createTypeBoxSchematizer(): TypeBoxSchematizer;
@@ -19,10 +19,10 @@ export interface ValibotSchematizer extends Schematizer {
19
19
  * The toTablesSchema method converts a mapping of Valibot object schemas into a
20
20
  * TinyBase TablesSchema.
21
21
  *
22
- * This method extracts basic type information (string, number, boolean),
23
- * string picklists, fallback values, nullable flags, and required flags from
24
- * Valibot schemas. Complex validation rules like min/max, regex patterns,
25
- * refinements, and transforms are ignored.
22
+ * This method extracts basic type information (string, number, boolean), basic
23
+ * type unions, primitive picklists and literal unions, fallback values,
24
+ * nullable flags, and required flags from Valibot schemas. Complex validation
25
+ * rules like min/max, regex patterns, refinements, and transforms are ignored.
26
26
  * @param schemas - A mapping of table IDs to Valibot object schemas.
27
27
  * @returns A TinyBase TablesSchema.
28
28
  * @example
@@ -57,8 +57,8 @@ export interface ValibotSchematizer extends Schematizer {
57
57
  * The toValuesSchema method converts a mapping of Valibot schemas into a
58
58
  * TinyBase ValuesSchema.
59
59
  *
60
- * This method extracts basic type information, string picklists, fallback
61
- * values, and required flags from Valibot schemas.
60
+ * This method extracts basic type information and unions, primitive picklists
61
+ * and literal unions, fallback values, and required flags from Valibot schemas.
62
62
  * @param schemas - A mapping of value IDs to Valibot schemas.
63
63
  * @returns A TinyBase ValuesSchema.
64
64
  * @example
@@ -5,4 +5,115 @@
5
5
  * @module schematizer-valibot
6
6
  * @since v7.1.0
7
7
  */
8
- export type {ValibotSchematizer} from '../index.d.ts';
8
+ import type {
9
+ TablesSchema,
10
+ ValuesSchema,
11
+ } from '../../../store/with-schemas/index.d.ts';
12
+ import type {Schematizer} from '../../with-schemas/index.d.ts';
13
+
14
+ /**
15
+ * The ValibotSchematizer interface represents a schematizer specifically for
16
+ * converting Valibot schemas into TinyBase schemas.
17
+ * @category Schematizer
18
+ * @since v7.1.0
19
+ */
20
+ export interface ValibotSchematizer extends Schematizer {
21
+ /**
22
+ * The toTablesSchema method converts a mapping of Valibot object schemas into a
23
+ * TinyBase TablesSchema.
24
+ *
25
+ * This method extracts basic type information (string, number, boolean), basic
26
+ * type unions, primitive picklists and literal unions, fallback values,
27
+ * nullable flags, and required flags from Valibot schemas. Complex validation
28
+ * rules like min/max, regex patterns, refinements, and transforms are ignored.
29
+ * @param schemas - A mapping of table IDs to Valibot object schemas.
30
+ * @returns A TinyBase TablesSchema.
31
+ * @example
32
+ * This example converts Valibot schemas to TinyBase format.
33
+ *
34
+ * ```js
35
+ * import {createStore} from 'tinybase';
36
+ * import {createValibotSchematizer} from 'tinybase/schematizers/schematizer-valibot';
37
+ * import {boolean, fallback, number, object, string} from 'valibot';
38
+ *
39
+ * const schematizer = createValibotSchematizer();
40
+ *
41
+ * const tablesSchema = schematizer.toTablesSchema({
42
+ * pets: object({
43
+ * species: string(),
44
+ * age: number(),
45
+ * sold: fallback(boolean(), false),
46
+ * }),
47
+ * });
48
+ *
49
+ * const store = createStore().setTablesSchema(tablesSchema);
50
+ * store.setRow('pets', 'fido', {species: 'dog', age: 3});
51
+ * console.log(store.getRow('pets', 'fido'));
52
+ * // -> {species: 'dog', age: 3, sold: false}
53
+ * ```
54
+ * @category Conversion
55
+ * @since v7.1.0
56
+ */
57
+ toTablesSchema(schemas: {[tableId: string]: any}): TablesSchema;
58
+
59
+ /**
60
+ * The toValuesSchema method converts a mapping of Valibot schemas into a
61
+ * TinyBase ValuesSchema.
62
+ *
63
+ * This method extracts basic type information and unions, primitive picklists
64
+ * and literal unions, fallback values, and required flags from Valibot schemas.
65
+ * @param schemas - A mapping of value IDs to Valibot schemas.
66
+ * @returns A TinyBase ValuesSchema.
67
+ * @example
68
+ * This example converts Valibot value schemas.
69
+ *
70
+ * ```js
71
+ * import {createStore} from 'tinybase';
72
+ * import {createValibotSchematizer} from 'tinybase/schematizers/schematizer-valibot';
73
+ * import {fallback, number, string} from 'valibot';
74
+ *
75
+ * const schematizer = createValibotSchematizer();
76
+ *
77
+ * const valuesSchema = schematizer.toValuesSchema({
78
+ * theme: fallback(string(), 'light'),
79
+ * count: number(),
80
+ * });
81
+ *
82
+ * const store = createStore().setValuesSchema(valuesSchema);
83
+ * store.setValues({count: 1});
84
+ * console.log(store.getValues());
85
+ * // -> {theme: 'light', count: 1}
86
+ * ```
87
+ * @category Conversion
88
+ * @since v7.1.0
89
+ */
90
+ toValuesSchema(schemas: {[valueId: string]: any}): ValuesSchema;
91
+ }
92
+
93
+ /**
94
+ * The createValibotSchematizer function creates a ValibotSchematizer object
95
+ * that can convert Valibot schemas into TinyBase schemas.
96
+ *
97
+ * The schematizer is stateless and can be reused for multiple conversions.
98
+ * @returns A new ValibotSchematizer instance.
99
+ * @example
100
+ * This example creates a Valibot schematizer and uses it to convert schemas.
101
+ *
102
+ * ```js
103
+ * import {createValibotSchematizer} from 'tinybase/schematizers/schematizer-valibot';
104
+ * import {object, string} from 'valibot';
105
+ *
106
+ * const schematizer = createValibotSchematizer();
107
+ *
108
+ * const tablesSchema = schematizer.toTablesSchema({
109
+ * pets: object({
110
+ * species: string(),
111
+ * }),
112
+ * });
113
+ * console.log(tablesSchema);
114
+ * // -> {pets: {species: {type: 'string', required: true}}}
115
+ * ```
116
+ * @category Creation
117
+ * @since v7.1.0
118
+ */
119
+ export function createValibotSchematizer(): ValibotSchematizer;
@@ -19,8 +19,9 @@ export interface YupSchematizer extends Schematizer {
19
19
  * TinyBase TablesSchema.
20
20
  *
21
21
  * This method extracts basic type information (string, number, boolean),
22
- * string enums, default values, nullable flags, and required flags from Yup
23
- * schemas. Complex validation rules like min/max, regex patterns, tests, and
22
+ * primitive enums and literals, default values, nullable flags, and required
23
+ * flags from Yup schemas. Complex validation rules like min/max, regex
24
+ * patterns, tests, and
24
25
  * transforms are ignored.
25
26
  * @param schemas - A mapping of table IDs to Yup object schemas.
26
27
  * @returns A TinyBase TablesSchema.
@@ -57,8 +58,8 @@ export interface YupSchematizer extends Schematizer {
57
58
  * ValuesSchema.
58
59
  *
59
60
  * This method extracts basic type information (string, number, boolean),
60
- * string enums, default values, nullable flags, and required flags from Yup
61
- * schemas.
61
+ * primitive enums and literals, default values, nullable flags, and required
62
+ * flags from Yup schemas.
62
63
  * @param schemas - A mapping of value IDs to Yup schemas.
63
64
  * @returns A TinyBase ValuesSchema.
64
65
  * @example
@@ -4,4 +4,115 @@
4
4
  * @module schematizer-yup
5
5
  * @since v7.1.0
6
6
  */
7
- export type {YupSchematizer, createYupSchematizer} from '../index.d.ts';
7
+ import type {
8
+ TablesSchema,
9
+ ValuesSchema,
10
+ } from '../../../store/with-schemas/index.d.ts';
11
+ import type {Schematizer} from '../../with-schemas/index.d.ts';
12
+
13
+ /**
14
+ * The YupSchematizer interface represents a schematizer specifically for
15
+ * converting Yup schemas into TinyBase schemas.
16
+ * @category Schematizer
17
+ * @since v7.1.0
18
+ */
19
+ export interface YupSchematizer extends Schematizer {
20
+ /**
21
+ * The toTablesSchema method converts a mapping of Yup object schemas into a
22
+ * TinyBase TablesSchema.
23
+ *
24
+ * This method extracts basic type information (string, number, boolean),
25
+ * primitive enums and literals, default values, nullable flags, and required
26
+ * flags from Yup schemas. Complex validation rules like min/max, regex
27
+ * patterns, tests, and
28
+ * transforms are ignored.
29
+ * @param schemas - A mapping of table IDs to Yup object schemas.
30
+ * @returns A TinyBase TablesSchema.
31
+ * @example
32
+ * This example converts Yup schemas to TinyBase format.
33
+ *
34
+ * ```js
35
+ * import {createStore} from 'tinybase';
36
+ * import {createYupSchematizer} from 'tinybase/schematizers/schematizer-yup';
37
+ * import {boolean, number, object, string} from 'yup';
38
+ *
39
+ * const schematizer = createYupSchematizer();
40
+ *
41
+ * const tablesSchema = schematizer.toTablesSchema({
42
+ * pets: object({
43
+ * species: string(),
44
+ * age: number(),
45
+ * sold: boolean().default(false),
46
+ * }),
47
+ * });
48
+ *
49
+ * const store = createStore().setTablesSchema(tablesSchema);
50
+ * store.setRow('pets', 'fido', {species: 'dog', age: 3});
51
+ * console.log(store.getRow('pets', 'fido'));
52
+ * // -> {species: 'dog', age: 3, sold: false}
53
+ * ```
54
+ * @category Conversion
55
+ * @since v7.1.0
56
+ */
57
+ toTablesSchema(schemas: {[tableId: string]: any}): TablesSchema;
58
+
59
+ /**
60
+ * The toValuesSchema method converts a mapping of Yup schemas into a TinyBase
61
+ * ValuesSchema.
62
+ *
63
+ * This method extracts basic type information (string, number, boolean),
64
+ * primitive enums and literals, default values, nullable flags, and required
65
+ * flags from Yup schemas.
66
+ * @param schemas - A mapping of value IDs to Yup schemas.
67
+ * @returns A TinyBase ValuesSchema.
68
+ * @example
69
+ * This example converts Yup schemas to TinyBase values.
70
+ *
71
+ * ```js
72
+ * import {createStore} from 'tinybase';
73
+ * import {createYupSchematizer} from 'tinybase/schematizers/schematizer-yup';
74
+ * import {boolean, number} from 'yup';
75
+ *
76
+ * const schematizer = createYupSchematizer();
77
+ *
78
+ * const valuesSchema = schematizer.toValuesSchema({
79
+ * open: boolean().default(true),
80
+ * employees: number(),
81
+ * });
82
+ *
83
+ * const store = createStore().setValuesSchema(valuesSchema);
84
+ * console.log(store.getValues());
85
+ * // -> {open: true}
86
+ * ```
87
+ * @category Conversion
88
+ * @since v7.1.0
89
+ */
90
+ toValuesSchema(schemas: {[valueId: string]: any}): ValuesSchema;
91
+ }
92
+
93
+ /**
94
+ * The createYupSchematizer function creates a YupSchematizer instance for
95
+ * converting Yup schemas to TinyBase schemas.
96
+ * @returns A new YupSchematizer instance.
97
+ * @example
98
+ * This example creates a Yup schematizer.
99
+ *
100
+ * ```js
101
+ * import {createYupSchematizer} from 'tinybase/schematizers/schematizer-yup';
102
+ * import {object, string} from 'yup';
103
+ *
104
+ * const schematizer = createYupSchematizer();
105
+ *
106
+ * const tablesSchema = schematizer.toTablesSchema({
107
+ * pets: object({
108
+ * species: string(),
109
+ * }),
110
+ * });
111
+ *
112
+ * console.log(tablesSchema);
113
+ * // -> {pets: {species: {type: 'string'}}}
114
+ * ```
115
+ * @category Creation
116
+ * @since v7.1.0
117
+ */
118
+ export function createYupSchematizer(): YupSchematizer;
@@ -18,10 +18,10 @@ export interface ZodSchematizer extends Schematizer {
18
18
  * The toTablesSchema method converts a mapping of Zod object schemas into a
19
19
  * TinyBase TablesSchema.
20
20
  *
21
- * This method extracts basic type information (string, number, boolean),
22
- * string enums, default values, nullable flags, and required flags from Zod
23
- * schemas. Complex validation rules like min/max, regex patterns,
24
- * refinements, and transforms are ignored.
21
+ * This method extracts basic type information (string, number, boolean), basic
22
+ * type unions, primitive enums and literals, default values, nullable flags,
23
+ * and required flags from Zod schemas. Complex validation rules like min/max,
24
+ * regex patterns, refinements, and transforms are ignored.
25
25
  * @param schemas - A mapping of table IDs to Zod object schemas.
26
26
  * @returns A TinyBase TablesSchema.
27
27
  * @example
@@ -56,8 +56,8 @@ export interface ZodSchematizer extends Schematizer {
56
56
  * The toValuesSchema method converts a mapping of Zod schemas into a TinyBase
57
57
  * ValuesSchema.
58
58
  *
59
- * This method extracts basic type information, string enums, default values,
60
- * and required flags from Zod schemas.
59
+ * This method extracts basic type information and unions, primitive enums and
60
+ * literals, default values, and required flags from Zod schemas.
61
61
  * @param schemas - A mapping of value IDs to Zod schemas.
62
62
  * @returns A TinyBase ValuesSchema.
63
63
  * @example
@@ -4,4 +4,115 @@
4
4
  * @module schematizer-zod
5
5
  * @since v7.1.0
6
6
  */
7
- export type {ZodSchematizer, createZodSchematizer} from '../index.d.ts';
7
+ import type {
8
+ TablesSchema,
9
+ ValuesSchema,
10
+ } from '../../../store/with-schemas/index.d.ts';
11
+ import type {Schematizer} from '../../with-schemas/index.d.ts';
12
+
13
+ /**
14
+ * The ZodSchematizer interface represents a schematizer specifically for
15
+ * converting Zod schemas into TinyBase schemas.
16
+ * @category Schematizer
17
+ * @since v7.1.0
18
+ */
19
+ export interface ZodSchematizer extends Schematizer {
20
+ /**
21
+ * The toTablesSchema method converts a mapping of Zod object schemas into a
22
+ * TinyBase TablesSchema.
23
+ *
24
+ * This method extracts basic type information (string, number, boolean), basic
25
+ * type unions, primitive enums and literals, default values, nullable flags,
26
+ * and required flags from Zod schemas. Complex validation rules like min/max,
27
+ * regex patterns, refinements, and transforms are ignored.
28
+ * @param schemas - A mapping of table IDs to Zod object schemas.
29
+ * @returns A TinyBase TablesSchema.
30
+ * @example
31
+ * This example converts Zod schemas to TinyBase format.
32
+ *
33
+ * ```js
34
+ * import {createStore} from 'tinybase';
35
+ * import {createZodSchematizer} from 'tinybase/schematizers/schematizer-zod';
36
+ * import {z} from 'zod';
37
+ *
38
+ * const schematizer = createZodSchematizer();
39
+ *
40
+ * const tablesSchema = schematizer.toTablesSchema({
41
+ * pets: z.object({
42
+ * species: z.enum(['dog', 'cat']),
43
+ * age: z.number(),
44
+ * sold: z.boolean().default(false),
45
+ * }),
46
+ * });
47
+ *
48
+ * const store = createStore().setTablesSchema(tablesSchema);
49
+ * store.setRow('pets', 'fido', {species: 'dog', age: 3});
50
+ * console.log(store.getRow('pets', 'fido'));
51
+ * // -> {species: 'dog', age: 3, sold: false}
52
+ * ```
53
+ * @category Conversion
54
+ * @since v7.1.0
55
+ */
56
+ toTablesSchema(schemas: {[tableId: string]: any}): TablesSchema;
57
+
58
+ /**
59
+ * The toValuesSchema method converts a mapping of Zod schemas into a TinyBase
60
+ * ValuesSchema.
61
+ *
62
+ * This method extracts basic type information and unions, primitive enums and
63
+ * literals, default values, and required flags from Zod schemas.
64
+ * @param schemas - A mapping of value IDs to Zod schemas.
65
+ * @returns A TinyBase ValuesSchema.
66
+ * @example
67
+ * This example converts Zod value schemas.
68
+ *
69
+ * ```js
70
+ * import {createStore} from 'tinybase';
71
+ * import {createZodSchematizer} from 'tinybase/schematizers/schematizer-zod';
72
+ * import {z} from 'zod';
73
+ *
74
+ * const schematizer = createZodSchematizer();
75
+ *
76
+ * const valuesSchema = schematizer.toValuesSchema({
77
+ * theme: z.string().default('light'),
78
+ * count: z.number(),
79
+ * });
80
+ *
81
+ * const store = createStore().setValuesSchema(valuesSchema);
82
+ * store.setValues({count: 1});
83
+ * console.log(store.getValues());
84
+ * // -> {theme: 'light', count: 1}
85
+ * ```
86
+ * @category Conversion
87
+ * @since v7.1.0
88
+ */
89
+ toValuesSchema(schemas: {[valueId: string]: any}): ValuesSchema;
90
+ }
91
+
92
+ /**
93
+ * The createZodSchematizer function creates a ZodSchematizer object that can
94
+ * convert Zod schemas into TinyBase schemas.
95
+ *
96
+ * The schematizer is stateless and can be reused for multiple conversions.
97
+ * @returns A new ZodSchematizer instance.
98
+ * @example
99
+ * This example creates a Zod schematizer and uses it to convert schemas.
100
+ *
101
+ * ```js
102
+ * import {createZodSchematizer} from 'tinybase/schematizers/schematizer-zod';
103
+ * import {z} from 'zod';
104
+ *
105
+ * const schematizer = createZodSchematizer();
106
+ *
107
+ * const tablesSchema = schematizer.toTablesSchema({
108
+ * pets: z.object({
109
+ * species: z.string(),
110
+ * }),
111
+ * });
112
+ * console.log(tablesSchema);
113
+ * // -> {pets: {species: {type: 'string', required: true}}}
114
+ * ```
115
+ * @category Creation
116
+ * @since v7.1.0
117
+ */
118
+ export function createZodSchematizer(): ZodSchematizer;
@@ -2,11 +2,120 @@
2
2
  * The schematizers module provides utilities for converting schemas from
3
3
  * popular validation libraries into TinyBase's schema format.
4
4
  *
5
- * Schematizers perform "best-effort" conversion, extracting basic type
6
- * information (string, number, boolean) and default values while discarding
7
- * complex validation rules that TinyBase doesn't support.
5
+ * Schematizers perform "best-effort" conversion, extracting basic type and
6
+ * type union, primitive enum and literal, and default information while
7
+ * discarding complex validation rules that TinyBase doesn't support.
8
8
  * @packageDocumentation
9
9
  * @module schematizers
10
10
  * @since v7.1.0
11
11
  */
12
- export type {Schematizer} from '../index.d.ts';
12
+ import type {
13
+ TablesSchema,
14
+ ValuesSchema,
15
+ } from '../../store/with-schemas/index.d.ts';
16
+
17
+ /**
18
+ * The Schematizer interface represents a schema converter that can transform
19
+ * external validation library schemas into TinyBase TablesSchema and
20
+ * ValuesSchema formats.
21
+ * @category Schematizer
22
+ * @since v7.1.0
23
+ */
24
+ export interface Schematizer {
25
+ /**
26
+ * The toTablesSchema method converts a mapping of external schemas into a
27
+ * TinyBase TablesSchema.
28
+ * @param schemas - A mapping of table IDs to external schema objects.
29
+ * @returns A TinyBase TablesSchema.
30
+ * @category Conversion
31
+ * @since v7.1.0
32
+ */
33
+ toTablesSchema(schemas: any): TablesSchema;
34
+
35
+ /**
36
+ * The toValuesSchema method converts a mapping of external schemas into a
37
+ * TinyBase ValuesSchema.
38
+ * @param schemas - A mapping of value IDs to external schema objects.
39
+ * @returns A TinyBase ValuesSchema.
40
+ * @category Conversion
41
+ * @since v7.1.0
42
+ */
43
+ toValuesSchema(schemas: any): ValuesSchema;
44
+ }
45
+
46
+ /**
47
+ * The createCustomSchematizer function creates a custom Schematizer that can
48
+ * convert schemas from any validation library into TinyBase schemas.
49
+ *
50
+ * This function allows you to build schematizers for validation libraries not
51
+ * natively supported by TinyBase. You provide two functions: one to unwrap
52
+ * optional/nullable/default wrappers from your library's schemas, and one to
53
+ * extract object properties.
54
+ * @param unwrapSchema - A function that unwraps a schema to extract the base
55
+ * type, default value, nullable flag, and optional required flag. It should
56
+ * recursively unwrap optional/nullable wrappers and return a tuple of
57
+ * [schema, defaultValue, allowNull, required]. The unwrapped schema should have
58
+ * either a supported `type` property, a non-empty `type` array containing
59
+ * supported types, or a non-empty `enum` property containing primitive values.
60
+ * @param getProperties - A function that extracts the properties/entries/shape
61
+ * from an object schema. Returns undefined if the schema is not an object.
62
+ * @param getPropertyRequired - An optional function that extracts whether an
63
+ * object property is required.
64
+ * @returns A new Schematizer instance.
65
+ * @example
66
+ * This example creates a custom schematizer for a hypothetical validation
67
+ * library.
68
+ *
69
+ * ```js
70
+ * import {createCustomSchematizer} from 'tinybase/schematizers';
71
+ *
72
+ * // Hypothetical library has schemas like:
73
+ * // {type: 'string'}, {type: 'optional', inner: ...}, etc.
74
+ *
75
+ * const unwrapSchema = (
76
+ * schema,
77
+ * defaultValue,
78
+ * allowNull,
79
+ * required = true,
80
+ * ) => {
81
+ * if (schema.type === 'optional') {
82
+ * return unwrapSchema(schema.inner, defaultValue, allowNull, false);
83
+ * }
84
+ * if (schema.type === 'nullable') {
85
+ * return unwrapSchema(schema.inner, defaultValue, true, required);
86
+ * }
87
+ * return [
88
+ * schema,
89
+ * defaultValue ?? schema.default,
90
+ * allowNull ?? false,
91
+ * required,
92
+ * ];
93
+ * };
94
+ *
95
+ * const getProperties = (schema) => schema.fields;
96
+ *
97
+ * const schematizer = createCustomSchematizer(unwrapSchema, getProperties);
98
+ *
99
+ * const tablesSchema = schematizer.toTablesSchema({
100
+ * pets: {type: 'object', fields: {name: {type: 'string'}}},
101
+ * });
102
+ * console.log(tablesSchema);
103
+ * // -> {pets: {name: {type: 'string', required: true}}}
104
+ * ```
105
+ * @category Creation
106
+ * @since v7.1.0
107
+ */
108
+ export function createCustomSchematizer(
109
+ unwrapSchema: (
110
+ schema: any,
111
+ defaultValue?: any,
112
+ allowNull?: boolean,
113
+ required?: boolean,
114
+ ) => [any, any, boolean] | [any, any, boolean, boolean | undefined],
115
+ getProperties: (schema: any) => any | undefined,
116
+ getPropertyRequired?: (
117
+ schema: any,
118
+ propertyId: string,
119
+ propertySchema: any,
120
+ ) => boolean | undefined,
121
+ ): Schematizer;