tinybase 7.1.0-beta.0 → 7.1.0-beta.2
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/@types/persisters/index.d.ts +3 -3
- package/@types/persisters/with-schemas/index.d.ts +6 -6
- package/@types/schematizers/index.d.ts +41 -0
- package/@types/schematizers/schematizer-typebox/index.d.ts +116 -0
- package/@types/schematizers/schematizer-typebox/with-schemas/index.d.ts +8 -0
- package/@types/schematizers/schematizer-zod/index.d.ts +113 -0
- package/@types/schematizers/schematizer-zod/with-schemas/index.d.ts +7 -0
- package/@types/schematizers/with-schemas/index.d.ts +12 -0
- package/@types/ui-react/index.d.ts +2 -2
- package/@types/ui-react/with-schemas/index.d.ts +4 -4
- package/agents.md +144 -0
- package/index.js +2 -1
- package/mergeable-store/index.js +2 -1
- package/mergeable-store/with-schemas/index.js +2 -1
- package/min/schematizers/index.js +1 -0
- package/min/schematizers/index.js.gz +0 -0
- package/min/schematizers/schematizer-typebox/index.js +1 -0
- package/min/schematizers/schematizer-typebox/index.js.gz +0 -0
- package/min/schematizers/schematizer-typebox/with-schemas/index.js +1 -0
- package/min/schematizers/schematizer-typebox/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-zod/index.js +1 -0
- package/min/schematizers/schematizer-zod/index.js.gz +0 -0
- package/min/schematizers/schematizer-zod/with-schemas/index.js +1 -0
- package/min/schematizers/schematizer-zod/with-schemas/index.js.gz +0 -0
- package/min/schematizers/with-schemas/index.js +1 -0
- package/min/schematizers/with-schemas/index.js.gz +0 -0
- package/omni/index.js +2 -1
- package/omni/with-schemas/index.js +2 -1
- package/package.json +121 -5
- package/queries/index.js +2 -1
- package/queries/with-schemas/index.js +2 -1
- package/readme.md +13 -13
- package/releases.md +62 -38
- package/schematizers/index.js +1 -0
- package/schematizers/schematizer-typebox/index.js +106 -0
- package/schematizers/schematizer-typebox/with-schemas/index.js +106 -0
- package/schematizers/schematizer-zod/index.js +102 -0
- package/schematizers/schematizer-zod/with-schemas/index.js +102 -0
- package/schematizers/with-schemas/index.js +1 -0
- package/store/index.js +2 -1
- package/store/with-schemas/index.js +2 -1
- package/ui-react-dom/index.js +2 -1
- package/ui-react-dom/with-schemas/index.js +2 -1
- package/ui-react-inspector/index.js +2 -1
- package/ui-react-inspector/with-schemas/index.js +2 -1
- package/with-schemas/index.js +2 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
const getTypeOf = (thing) => typeof thing;
|
|
2
|
+
const EMPTY_STRING = '';
|
|
3
|
+
const STRING = getTypeOf(EMPTY_STRING);
|
|
4
|
+
const BOOLEAN = getTypeOf(true);
|
|
5
|
+
const NUMBER = getTypeOf(0);
|
|
6
|
+
const TYPE = 'type';
|
|
7
|
+
const DEFAULT = 'default';
|
|
8
|
+
const ALLOW_NULL = 'allowNull';
|
|
9
|
+
const NULL = 'null';
|
|
10
|
+
|
|
11
|
+
const getIfNotFunction = (predicate) => (value, then, otherwise) =>
|
|
12
|
+
predicate(value) ? otherwise?.() : then(value);
|
|
13
|
+
const isNullish = (thing) => thing == null;
|
|
14
|
+
const isUndefined = (thing) => thing === void 0;
|
|
15
|
+
const ifNotNullish = getIfNotFunction(isNullish);
|
|
16
|
+
const ifNotUndefined = getIfNotFunction(isUndefined);
|
|
17
|
+
const size = (arrayOrString) => arrayOrString.length;
|
|
18
|
+
|
|
19
|
+
const arrayForEach = (array, cb) => array.forEach(cb);
|
|
20
|
+
|
|
21
|
+
const object = Object;
|
|
22
|
+
const getPrototypeOf = (obj) => object.getPrototypeOf(obj);
|
|
23
|
+
const objEntries = object.entries;
|
|
24
|
+
const isObject = (obj) =>
|
|
25
|
+
!isNullish(obj) &&
|
|
26
|
+
ifNotNullish(
|
|
27
|
+
getPrototypeOf(obj),
|
|
28
|
+
(objPrototype) =>
|
|
29
|
+
objPrototype == object.prototype ||
|
|
30
|
+
isNullish(getPrototypeOf(objPrototype)),
|
|
31
|
+
|
|
32
|
+
/* istanbul ignore next */
|
|
33
|
+
() => true,
|
|
34
|
+
);
|
|
35
|
+
const objIds = object.keys;
|
|
36
|
+
const objFreeze = object.freeze;
|
|
37
|
+
const objNew = (entries = []) => object.fromEntries(entries);
|
|
38
|
+
const objForEach = (obj, cb) =>
|
|
39
|
+
arrayForEach(objEntries(obj), ([id, value]) => cb(value, id));
|
|
40
|
+
const objSize = (obj) => size(objIds(obj));
|
|
41
|
+
const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
|
|
42
|
+
|
|
43
|
+
const ANY_OF = 'anyOf';
|
|
44
|
+
const unwrapSchema = (schema, defaultValue, allowNull) => {
|
|
45
|
+
if (schema?.[ANY_OF]) {
|
|
46
|
+
const types = schema[ANY_OF];
|
|
47
|
+
const hasNull = types.some((t) => t?.type === NULL);
|
|
48
|
+
const nonNullType = types.find((t) => t?.type !== NULL);
|
|
49
|
+
if (hasNull && nonNullType) {
|
|
50
|
+
return unwrapSchema(nonNullType, defaultValue ?? schema?.[DEFAULT], true);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return [schema, defaultValue ?? schema?.[DEFAULT], allowNull ?? false];
|
|
54
|
+
};
|
|
55
|
+
const createTypeBoxSchematizer = () => {
|
|
56
|
+
const toTablesSchema = (schemas) => {
|
|
57
|
+
const tablesSchema = objNew();
|
|
58
|
+
objForEach(schemas, (typeBoxSchema, tableId) => {
|
|
59
|
+
const tableSchema = objNew();
|
|
60
|
+
ifNotUndefined(typeBoxSchema?.properties, (properties) =>
|
|
61
|
+
objForEach(properties, (cellTypeBoxSchema, cellId) =>
|
|
62
|
+
ifNotUndefined(
|
|
63
|
+
toCellOrValueSchema(cellTypeBoxSchema),
|
|
64
|
+
(cellSchema) => {
|
|
65
|
+
tableSchema[cellId] = cellSchema;
|
|
66
|
+
},
|
|
67
|
+
),
|
|
68
|
+
),
|
|
69
|
+
);
|
|
70
|
+
if (!objIsEmpty(tableSchema)) {
|
|
71
|
+
tablesSchema[tableId] = tableSchema;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return tablesSchema;
|
|
75
|
+
};
|
|
76
|
+
const toValuesSchema = (schemas) => {
|
|
77
|
+
const valuesSchema = objNew();
|
|
78
|
+
objForEach(schemas, (typeBoxSchema, valueId) =>
|
|
79
|
+
ifNotUndefined(toCellOrValueSchema(typeBoxSchema), (valueSchema) => {
|
|
80
|
+
valuesSchema[valueId] = valueSchema;
|
|
81
|
+
}),
|
|
82
|
+
);
|
|
83
|
+
return valuesSchema;
|
|
84
|
+
};
|
|
85
|
+
const toCellOrValueSchema = (typeBoxSchema) => {
|
|
86
|
+
const [schema, defaultValue, allowNull] = unwrapSchema(typeBoxSchema);
|
|
87
|
+
const type = schema?.type;
|
|
88
|
+
if (type !== STRING && type !== NUMBER && type !== BOOLEAN) {
|
|
89
|
+
return void 0;
|
|
90
|
+
}
|
|
91
|
+
const cellOrValueSchema = {[TYPE]: type};
|
|
92
|
+
ifNotUndefined(defaultValue, (defaultValue2) => {
|
|
93
|
+
cellOrValueSchema[DEFAULT] = defaultValue2;
|
|
94
|
+
});
|
|
95
|
+
if (allowNull) {
|
|
96
|
+
cellOrValueSchema[ALLOW_NULL] = true;
|
|
97
|
+
}
|
|
98
|
+
return cellOrValueSchema;
|
|
99
|
+
};
|
|
100
|
+
return objFreeze({
|
|
101
|
+
toTablesSchema,
|
|
102
|
+
toValuesSchema,
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export {createTypeBoxSchematizer};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
const getTypeOf = (thing) => typeof thing;
|
|
2
|
+
const EMPTY_STRING = '';
|
|
3
|
+
const STRING = getTypeOf(EMPTY_STRING);
|
|
4
|
+
const BOOLEAN = getTypeOf(true);
|
|
5
|
+
const NUMBER = getTypeOf(0);
|
|
6
|
+
const TYPE = 'type';
|
|
7
|
+
const DEFAULT = 'default';
|
|
8
|
+
const ALLOW_NULL = 'allowNull';
|
|
9
|
+
const NULL = 'null';
|
|
10
|
+
|
|
11
|
+
const getIfNotFunction = (predicate) => (value, then, otherwise) =>
|
|
12
|
+
predicate(value) ? otherwise?.() : then(value);
|
|
13
|
+
const isNullish = (thing) => thing == null;
|
|
14
|
+
const isUndefined = (thing) => thing === void 0;
|
|
15
|
+
const ifNotNullish = getIfNotFunction(isNullish);
|
|
16
|
+
const ifNotUndefined = getIfNotFunction(isUndefined);
|
|
17
|
+
const size = (arrayOrString) => arrayOrString.length;
|
|
18
|
+
|
|
19
|
+
const arrayForEach = (array, cb) => array.forEach(cb);
|
|
20
|
+
|
|
21
|
+
const object = Object;
|
|
22
|
+
const getPrototypeOf = (obj) => object.getPrototypeOf(obj);
|
|
23
|
+
const objEntries = object.entries;
|
|
24
|
+
const isObject = (obj) =>
|
|
25
|
+
!isNullish(obj) &&
|
|
26
|
+
ifNotNullish(
|
|
27
|
+
getPrototypeOf(obj),
|
|
28
|
+
(objPrototype) =>
|
|
29
|
+
objPrototype == object.prototype ||
|
|
30
|
+
isNullish(getPrototypeOf(objPrototype)),
|
|
31
|
+
|
|
32
|
+
/* istanbul ignore next */
|
|
33
|
+
() => true,
|
|
34
|
+
);
|
|
35
|
+
const objIds = object.keys;
|
|
36
|
+
const objFreeze = object.freeze;
|
|
37
|
+
const objNew = (entries = []) => object.fromEntries(entries);
|
|
38
|
+
const objForEach = (obj, cb) =>
|
|
39
|
+
arrayForEach(objEntries(obj), ([id, value]) => cb(value, id));
|
|
40
|
+
const objSize = (obj) => size(objIds(obj));
|
|
41
|
+
const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
|
|
42
|
+
|
|
43
|
+
const ANY_OF = 'anyOf';
|
|
44
|
+
const unwrapSchema = (schema, defaultValue, allowNull) => {
|
|
45
|
+
if (schema?.[ANY_OF]) {
|
|
46
|
+
const types = schema[ANY_OF];
|
|
47
|
+
const hasNull = types.some((t) => t?.type === NULL);
|
|
48
|
+
const nonNullType = types.find((t) => t?.type !== NULL);
|
|
49
|
+
if (hasNull && nonNullType) {
|
|
50
|
+
return unwrapSchema(nonNullType, defaultValue ?? schema?.[DEFAULT], true);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return [schema, defaultValue ?? schema?.[DEFAULT], allowNull ?? false];
|
|
54
|
+
};
|
|
55
|
+
const createTypeBoxSchematizer = () => {
|
|
56
|
+
const toTablesSchema = (schemas) => {
|
|
57
|
+
const tablesSchema = objNew();
|
|
58
|
+
objForEach(schemas, (typeBoxSchema, tableId) => {
|
|
59
|
+
const tableSchema = objNew();
|
|
60
|
+
ifNotUndefined(typeBoxSchema?.properties, (properties) =>
|
|
61
|
+
objForEach(properties, (cellTypeBoxSchema, cellId) =>
|
|
62
|
+
ifNotUndefined(
|
|
63
|
+
toCellOrValueSchema(cellTypeBoxSchema),
|
|
64
|
+
(cellSchema) => {
|
|
65
|
+
tableSchema[cellId] = cellSchema;
|
|
66
|
+
},
|
|
67
|
+
),
|
|
68
|
+
),
|
|
69
|
+
);
|
|
70
|
+
if (!objIsEmpty(tableSchema)) {
|
|
71
|
+
tablesSchema[tableId] = tableSchema;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return tablesSchema;
|
|
75
|
+
};
|
|
76
|
+
const toValuesSchema = (schemas) => {
|
|
77
|
+
const valuesSchema = objNew();
|
|
78
|
+
objForEach(schemas, (typeBoxSchema, valueId) =>
|
|
79
|
+
ifNotUndefined(toCellOrValueSchema(typeBoxSchema), (valueSchema) => {
|
|
80
|
+
valuesSchema[valueId] = valueSchema;
|
|
81
|
+
}),
|
|
82
|
+
);
|
|
83
|
+
return valuesSchema;
|
|
84
|
+
};
|
|
85
|
+
const toCellOrValueSchema = (typeBoxSchema) => {
|
|
86
|
+
const [schema, defaultValue, allowNull] = unwrapSchema(typeBoxSchema);
|
|
87
|
+
const type = schema?.type;
|
|
88
|
+
if (type !== STRING && type !== NUMBER && type !== BOOLEAN) {
|
|
89
|
+
return void 0;
|
|
90
|
+
}
|
|
91
|
+
const cellOrValueSchema = {[TYPE]: type};
|
|
92
|
+
ifNotUndefined(defaultValue, (defaultValue2) => {
|
|
93
|
+
cellOrValueSchema[DEFAULT] = defaultValue2;
|
|
94
|
+
});
|
|
95
|
+
if (allowNull) {
|
|
96
|
+
cellOrValueSchema[ALLOW_NULL] = true;
|
|
97
|
+
}
|
|
98
|
+
return cellOrValueSchema;
|
|
99
|
+
};
|
|
100
|
+
return objFreeze({
|
|
101
|
+
toTablesSchema,
|
|
102
|
+
toValuesSchema,
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export {createTypeBoxSchematizer};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
const getTypeOf = (thing) => typeof thing;
|
|
2
|
+
const EMPTY_STRING = '';
|
|
3
|
+
const STRING = getTypeOf(EMPTY_STRING);
|
|
4
|
+
const BOOLEAN = getTypeOf(true);
|
|
5
|
+
const NUMBER = getTypeOf(0);
|
|
6
|
+
const TYPE = 'type';
|
|
7
|
+
const DEFAULT = 'default';
|
|
8
|
+
const ALLOW_NULL = 'allowNull';
|
|
9
|
+
|
|
10
|
+
const getIfNotFunction = (predicate) => (value, then, otherwise) =>
|
|
11
|
+
predicate(value) ? otherwise?.() : then(value);
|
|
12
|
+
const isNullish = (thing) => thing == null;
|
|
13
|
+
const isUndefined = (thing) => thing === void 0;
|
|
14
|
+
const ifNotNullish = getIfNotFunction(isNullish);
|
|
15
|
+
const ifNotUndefined = getIfNotFunction(isUndefined);
|
|
16
|
+
const size = (arrayOrString) => arrayOrString.length;
|
|
17
|
+
|
|
18
|
+
const arrayForEach = (array, cb) => array.forEach(cb);
|
|
19
|
+
|
|
20
|
+
const object = Object;
|
|
21
|
+
const getPrototypeOf = (obj) => object.getPrototypeOf(obj);
|
|
22
|
+
const objEntries = object.entries;
|
|
23
|
+
const isObject = (obj) =>
|
|
24
|
+
!isNullish(obj) &&
|
|
25
|
+
ifNotNullish(
|
|
26
|
+
getPrototypeOf(obj),
|
|
27
|
+
(objPrototype) =>
|
|
28
|
+
objPrototype == object.prototype ||
|
|
29
|
+
isNullish(getPrototypeOf(objPrototype)),
|
|
30
|
+
|
|
31
|
+
/* istanbul ignore next */
|
|
32
|
+
() => true,
|
|
33
|
+
);
|
|
34
|
+
const objIds = object.keys;
|
|
35
|
+
const objFreeze = object.freeze;
|
|
36
|
+
const objNew = (entries = []) => object.fromEntries(entries);
|
|
37
|
+
const objForEach = (obj, cb) =>
|
|
38
|
+
arrayForEach(objEntries(obj), ([id, value]) => cb(value, id));
|
|
39
|
+
const objSize = (obj) => size(objIds(obj));
|
|
40
|
+
const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
|
|
41
|
+
|
|
42
|
+
const OPTIONAL = 'optional';
|
|
43
|
+
const NULLABLE = 'nullable';
|
|
44
|
+
const unwrapSchema = (schema, defaultValue, allowNull) => {
|
|
45
|
+
const type = schema?.def?.type;
|
|
46
|
+
return type === OPTIONAL
|
|
47
|
+
? unwrapSchema(schema.def.innerType, defaultValue, allowNull)
|
|
48
|
+
: type === NULLABLE
|
|
49
|
+
? unwrapSchema(schema.def.innerType, defaultValue, true)
|
|
50
|
+
: type === DEFAULT
|
|
51
|
+
? unwrapSchema(schema.def.innerType, schema.def.defaultValue, allowNull)
|
|
52
|
+
: [schema, defaultValue, allowNull ?? false];
|
|
53
|
+
};
|
|
54
|
+
const createZodSchematizer = () => {
|
|
55
|
+
const toTablesSchema = (schemas) => {
|
|
56
|
+
const tablesSchema = objNew();
|
|
57
|
+
objForEach(schemas, (zodSchema, tableId) => {
|
|
58
|
+
const tableSchema = objNew();
|
|
59
|
+
ifNotUndefined(zodSchema?.def?.shape, (shape) =>
|
|
60
|
+
objForEach(shape, (cellZodSchema, cellId) =>
|
|
61
|
+
ifNotUndefined(toCellOrValueSchema(cellZodSchema), (cellSchema) => {
|
|
62
|
+
tableSchema[cellId] = cellSchema;
|
|
63
|
+
}),
|
|
64
|
+
),
|
|
65
|
+
);
|
|
66
|
+
if (!objIsEmpty(tableSchema)) {
|
|
67
|
+
tablesSchema[tableId] = tableSchema;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return tablesSchema;
|
|
71
|
+
};
|
|
72
|
+
const toValuesSchema = (schemas) => {
|
|
73
|
+
const valuesSchema = objNew();
|
|
74
|
+
objForEach(schemas, (zodSchema, valueId) =>
|
|
75
|
+
ifNotUndefined(toCellOrValueSchema(zodSchema), (valueSchema) => {
|
|
76
|
+
valuesSchema[valueId] = valueSchema;
|
|
77
|
+
}),
|
|
78
|
+
);
|
|
79
|
+
return valuesSchema;
|
|
80
|
+
};
|
|
81
|
+
const toCellOrValueSchema = (zodSchema) => {
|
|
82
|
+
const [schema, defaultValue, allowNull] = unwrapSchema(zodSchema);
|
|
83
|
+
const type = schema?.type;
|
|
84
|
+
if (type !== STRING && type !== NUMBER && type !== BOOLEAN) {
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
const cellOrValueSchema = {[TYPE]: type};
|
|
88
|
+
ifNotUndefined(defaultValue, (defaultValue2) => {
|
|
89
|
+
cellOrValueSchema[DEFAULT] = defaultValue2;
|
|
90
|
+
});
|
|
91
|
+
if (allowNull) {
|
|
92
|
+
cellOrValueSchema[ALLOW_NULL] = true;
|
|
93
|
+
}
|
|
94
|
+
return cellOrValueSchema;
|
|
95
|
+
};
|
|
96
|
+
return objFreeze({
|
|
97
|
+
toTablesSchema,
|
|
98
|
+
toValuesSchema,
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export {createZodSchematizer};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
const getTypeOf = (thing) => typeof thing;
|
|
2
|
+
const EMPTY_STRING = '';
|
|
3
|
+
const STRING = getTypeOf(EMPTY_STRING);
|
|
4
|
+
const BOOLEAN = getTypeOf(true);
|
|
5
|
+
const NUMBER = getTypeOf(0);
|
|
6
|
+
const TYPE = 'type';
|
|
7
|
+
const DEFAULT = 'default';
|
|
8
|
+
const ALLOW_NULL = 'allowNull';
|
|
9
|
+
|
|
10
|
+
const getIfNotFunction = (predicate) => (value, then, otherwise) =>
|
|
11
|
+
predicate(value) ? otherwise?.() : then(value);
|
|
12
|
+
const isNullish = (thing) => thing == null;
|
|
13
|
+
const isUndefined = (thing) => thing === void 0;
|
|
14
|
+
const ifNotNullish = getIfNotFunction(isNullish);
|
|
15
|
+
const ifNotUndefined = getIfNotFunction(isUndefined);
|
|
16
|
+
const size = (arrayOrString) => arrayOrString.length;
|
|
17
|
+
|
|
18
|
+
const arrayForEach = (array, cb) => array.forEach(cb);
|
|
19
|
+
|
|
20
|
+
const object = Object;
|
|
21
|
+
const getPrototypeOf = (obj) => object.getPrototypeOf(obj);
|
|
22
|
+
const objEntries = object.entries;
|
|
23
|
+
const isObject = (obj) =>
|
|
24
|
+
!isNullish(obj) &&
|
|
25
|
+
ifNotNullish(
|
|
26
|
+
getPrototypeOf(obj),
|
|
27
|
+
(objPrototype) =>
|
|
28
|
+
objPrototype == object.prototype ||
|
|
29
|
+
isNullish(getPrototypeOf(objPrototype)),
|
|
30
|
+
|
|
31
|
+
/* istanbul ignore next */
|
|
32
|
+
() => true,
|
|
33
|
+
);
|
|
34
|
+
const objIds = object.keys;
|
|
35
|
+
const objFreeze = object.freeze;
|
|
36
|
+
const objNew = (entries = []) => object.fromEntries(entries);
|
|
37
|
+
const objForEach = (obj, cb) =>
|
|
38
|
+
arrayForEach(objEntries(obj), ([id, value]) => cb(value, id));
|
|
39
|
+
const objSize = (obj) => size(objIds(obj));
|
|
40
|
+
const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
|
|
41
|
+
|
|
42
|
+
const OPTIONAL = 'optional';
|
|
43
|
+
const NULLABLE = 'nullable';
|
|
44
|
+
const unwrapSchema = (schema, defaultValue, allowNull) => {
|
|
45
|
+
const type = schema?.def?.type;
|
|
46
|
+
return type === OPTIONAL
|
|
47
|
+
? unwrapSchema(schema.def.innerType, defaultValue, allowNull)
|
|
48
|
+
: type === NULLABLE
|
|
49
|
+
? unwrapSchema(schema.def.innerType, defaultValue, true)
|
|
50
|
+
: type === DEFAULT
|
|
51
|
+
? unwrapSchema(schema.def.innerType, schema.def.defaultValue, allowNull)
|
|
52
|
+
: [schema, defaultValue, allowNull ?? false];
|
|
53
|
+
};
|
|
54
|
+
const createZodSchematizer = () => {
|
|
55
|
+
const toTablesSchema = (schemas) => {
|
|
56
|
+
const tablesSchema = objNew();
|
|
57
|
+
objForEach(schemas, (zodSchema, tableId) => {
|
|
58
|
+
const tableSchema = objNew();
|
|
59
|
+
ifNotUndefined(zodSchema?.def?.shape, (shape) =>
|
|
60
|
+
objForEach(shape, (cellZodSchema, cellId) =>
|
|
61
|
+
ifNotUndefined(toCellOrValueSchema(cellZodSchema), (cellSchema) => {
|
|
62
|
+
tableSchema[cellId] = cellSchema;
|
|
63
|
+
}),
|
|
64
|
+
),
|
|
65
|
+
);
|
|
66
|
+
if (!objIsEmpty(tableSchema)) {
|
|
67
|
+
tablesSchema[tableId] = tableSchema;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return tablesSchema;
|
|
71
|
+
};
|
|
72
|
+
const toValuesSchema = (schemas) => {
|
|
73
|
+
const valuesSchema = objNew();
|
|
74
|
+
objForEach(schemas, (zodSchema, valueId) =>
|
|
75
|
+
ifNotUndefined(toCellOrValueSchema(zodSchema), (valueSchema) => {
|
|
76
|
+
valuesSchema[valueId] = valueSchema;
|
|
77
|
+
}),
|
|
78
|
+
);
|
|
79
|
+
return valuesSchema;
|
|
80
|
+
};
|
|
81
|
+
const toCellOrValueSchema = (zodSchema) => {
|
|
82
|
+
const [schema, defaultValue, allowNull] = unwrapSchema(zodSchema);
|
|
83
|
+
const type = schema?.type;
|
|
84
|
+
if (type !== STRING && type !== NUMBER && type !== BOOLEAN) {
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
const cellOrValueSchema = {[TYPE]: type};
|
|
88
|
+
ifNotUndefined(defaultValue, (defaultValue2) => {
|
|
89
|
+
cellOrValueSchema[DEFAULT] = defaultValue2;
|
|
90
|
+
});
|
|
91
|
+
if (allowNull) {
|
|
92
|
+
cellOrValueSchema[ALLOW_NULL] = true;
|
|
93
|
+
}
|
|
94
|
+
return cellOrValueSchema;
|
|
95
|
+
};
|
|
96
|
+
return objFreeze({
|
|
97
|
+
toTablesSchema,
|
|
98
|
+
toValuesSchema,
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export {createZodSchematizer};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/store/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 LISTENER = 'Listener';
|
|
11
12
|
const ADD = 'add';
|
|
12
13
|
const HAS = 'Has';
|
|
@@ -62,7 +63,7 @@ const arrayShift = (array) => array.shift();
|
|
|
62
63
|
|
|
63
64
|
const getCellOrValueType = (cellOrValue) => {
|
|
64
65
|
if (isNull(cellOrValue)) {
|
|
65
|
-
return
|
|
66
|
+
return NULL;
|
|
66
67
|
}
|
|
67
68
|
const type = getTypeOf(cellOrValue);
|
|
68
69
|
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 ADD = 'add';
|
|
12
13
|
const HAS = 'Has';
|
|
@@ -62,7 +63,7 @@ const arrayShift = (array) => array.shift();
|
|
|
62
63
|
|
|
63
64
|
const getCellOrValueType = (cellOrValue) => {
|
|
64
65
|
if (isNull(cellOrValue)) {
|
|
65
|
-
return
|
|
66
|
+
return NULL;
|
|
66
67
|
}
|
|
67
68
|
const type = getTypeOf(cellOrValue);
|
|
68
69
|
return isTypeStringOrBoolean(type) ||
|
package/ui-react-dom/index.js
CHANGED
|
@@ -10,6 +10,7 @@ const STRING = getTypeOf(EMPTY_STRING);
|
|
|
10
10
|
const BOOLEAN = getTypeOf(true);
|
|
11
11
|
const NUMBER = getTypeOf(0);
|
|
12
12
|
const FUNCTION = getTypeOf(getTypeOf);
|
|
13
|
+
const NULL = 'null';
|
|
13
14
|
const LISTENER = 'Listener';
|
|
14
15
|
const RESULT = 'Result';
|
|
15
16
|
const GET = 'get';
|
|
@@ -400,7 +401,7 @@ const useResultSortedRowIds = (
|
|
|
400
401
|
|
|
401
402
|
const getCellOrValueType = (cellOrValue) => {
|
|
402
403
|
if (isNull(cellOrValue)) {
|
|
403
|
-
return
|
|
404
|
+
return NULL;
|
|
404
405
|
}
|
|
405
406
|
const type = getTypeOf(cellOrValue);
|
|
406
407
|
return isTypeStringOrBoolean(type) ||
|
|
@@ -10,6 +10,7 @@ const STRING = getTypeOf(EMPTY_STRING);
|
|
|
10
10
|
const BOOLEAN = getTypeOf(true);
|
|
11
11
|
const NUMBER = getTypeOf(0);
|
|
12
12
|
const FUNCTION = getTypeOf(getTypeOf);
|
|
13
|
+
const NULL = 'null';
|
|
13
14
|
const LISTENER = 'Listener';
|
|
14
15
|
const RESULT = 'Result';
|
|
15
16
|
const GET = 'get';
|
|
@@ -400,7 +401,7 @@ const useResultSortedRowIds = (
|
|
|
400
401
|
|
|
401
402
|
const getCellOrValueType = (cellOrValue) => {
|
|
402
403
|
if (isNull(cellOrValue)) {
|
|
403
|
-
return
|
|
404
|
+
return NULL;
|
|
404
405
|
}
|
|
405
406
|
const type = getTypeOf(cellOrValue);
|
|
406
407
|
return isTypeStringOrBoolean(type) ||
|
|
@@ -44,6 +44,7 @@ const FUNCTION = getTypeOf(getTypeOf);
|
|
|
44
44
|
const TYPE = 'type';
|
|
45
45
|
const DEFAULT = 'default';
|
|
46
46
|
const ALLOW_NULL = 'allowNull';
|
|
47
|
+
const NULL = 'null';
|
|
47
48
|
const LISTENER = 'Listener';
|
|
48
49
|
const RESULT = 'Result';
|
|
49
50
|
const GET = 'get';
|
|
@@ -663,7 +664,7 @@ const createSessionPersister = (store, storageName, onIgnoredError) =>
|
|
|
663
664
|
|
|
664
665
|
const getCellOrValueType = (cellOrValue) => {
|
|
665
666
|
if (isNull(cellOrValue)) {
|
|
666
|
-
return
|
|
667
|
+
return NULL;
|
|
667
668
|
}
|
|
668
669
|
const type = getTypeOf(cellOrValue);
|
|
669
670
|
return isTypeStringOrBoolean(type) ||
|
|
@@ -44,6 +44,7 @@ const FUNCTION = getTypeOf(getTypeOf);
|
|
|
44
44
|
const TYPE = 'type';
|
|
45
45
|
const DEFAULT = 'default';
|
|
46
46
|
const ALLOW_NULL = 'allowNull';
|
|
47
|
+
const NULL = 'null';
|
|
47
48
|
const LISTENER = 'Listener';
|
|
48
49
|
const RESULT = 'Result';
|
|
49
50
|
const GET = 'get';
|
|
@@ -663,7 +664,7 @@ const createSessionPersister = (store, storageName, onIgnoredError) =>
|
|
|
663
664
|
|
|
664
665
|
const getCellOrValueType = (cellOrValue) => {
|
|
665
666
|
if (isNull(cellOrValue)) {
|
|
666
|
-
return
|
|
667
|
+
return NULL;
|
|
667
668
|
}
|
|
668
669
|
const type = getTypeOf(cellOrValue);
|
|
669
670
|
return isTypeStringOrBoolean(type) ||
|
package/with-schemas/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
|
|
98
|
+
return NULL;
|
|
98
99
|
}
|
|
99
100
|
const type = getTypeOf(cellOrValue);
|
|
100
101
|
return isTypeStringOrBoolean(type) ||
|