tinybase 9.1.0 → 9.1.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.
- package/@types/schematizers/index.d.ts +27 -9
- package/@types/schematizers/schematizer-arktype/index.d.ts +8 -7
- package/@types/schematizers/schematizer-effect/index.d.ts +7 -5
- package/@types/schematizers/schematizer-typebox/index.d.ts +8 -7
- package/@types/schematizers/schematizer-valibot/index.d.ts +8 -7
- package/@types/schematizers/schematizer-yup/index.d.ts +5 -4
- package/@types/schematizers/schematizer-zod/index.d.ts +8 -7
- package/agents.md +12 -6
- package/min/schematizers/index.js +1 -1
- package/min/schematizers/index.js.gz +0 -0
- package/min/schematizers/schematizer-arktype/index.js +1 -1
- package/min/schematizers/schematizer-arktype/index.js.gz +0 -0
- package/min/schematizers/schematizer-arktype/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-arktype/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-effect/index.js +1 -1
- package/min/schematizers/schematizer-effect/index.js.gz +0 -0
- package/min/schematizers/schematizer-effect/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-effect/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-typebox/index.js +1 -1
- package/min/schematizers/schematizer-typebox/index.js.gz +0 -0
- package/min/schematizers/schematizer-typebox/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-typebox/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-valibot/index.js +1 -1
- package/min/schematizers/schematizer-valibot/index.js.gz +0 -0
- package/min/schematizers/schematizer-valibot/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-valibot/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-yup/index.js +1 -1
- package/min/schematizers/schematizer-yup/index.js.gz +0 -0
- package/min/schematizers/schematizer-yup/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-yup/with-schemas/index.js.gz +0 -0
- package/min/schematizers/schematizer-zod/index.js +1 -1
- package/min/schematizers/schematizer-zod/index.js.gz +0 -0
- package/min/schematizers/schematizer-zod/with-schemas/index.js +1 -1
- package/min/schematizers/schematizer-zod/with-schemas/index.js.gz +0 -0
- package/min/schematizers/with-schemas/index.js +1 -1
- package/min/schematizers/with-schemas/index.js.gz +0 -0
- package/package.json +2 -2
- package/readme.md +14 -14
- package/releases.md +61 -61
- package/schematizers/index.js +21 -6
- package/schematizers/schematizer-arktype/index.js +52 -17
- package/schematizers/schematizer-arktype/with-schemas/index.js +52 -17
- package/schematizers/schematizer-effect/index.js +41 -11
- package/schematizers/schematizer-effect/with-schemas/index.js +41 -11
- package/schematizers/schematizer-typebox/index.js +49 -9
- package/schematizers/schematizer-typebox/with-schemas/index.js +49 -9
- package/schematizers/schematizer-valibot/index.js +38 -10
- package/schematizers/schematizer-valibot/with-schemas/index.js +38 -10
- package/schematizers/schematizer-yup/index.js +29 -7
- package/schematizers/schematizer-yup/with-schemas/index.js +29 -7
- package/schematizers/schematizer-zod/index.js +29 -14
- package/schematizers/schematizer-zod/with-schemas/index.js +29 -14
- package/schematizers/with-schemas/index.js +21 -6
|
@@ -10,6 +10,7 @@ const DEFAULT = 'default';
|
|
|
10
10
|
const ALLOW_NULL = 'allowNull';
|
|
11
11
|
const NULL = 'null';
|
|
12
12
|
const ANY_OF = 'anyOf';
|
|
13
|
+
const REQUIRED = 'required';
|
|
13
14
|
|
|
14
15
|
const getIfNotFunction = (predicate) => (value, then, otherwise) =>
|
|
15
16
|
predicate(value)
|
|
@@ -22,9 +23,11 @@ const ifNotNullish = getIfNotFunction(isNullish);
|
|
|
22
23
|
const ifNotUndefined = getIfNotFunction(isUndefined);
|
|
23
24
|
const size = (arrayOrString) => arrayOrString.length;
|
|
24
25
|
|
|
26
|
+
const arrayHas = (array, value) => array.includes(value);
|
|
25
27
|
const arrayEvery = (array, cb) => array.every(cb);
|
|
26
28
|
const arrayForEach = (array, cb) => array.forEach(cb);
|
|
27
29
|
const arrayFilter = (array, cb) => array.filter(cb);
|
|
30
|
+
const arrayFind = (array, cb) => array.find(cb);
|
|
28
31
|
|
|
29
32
|
const object = Object;
|
|
30
33
|
const getPrototypeOf = (obj) => object.getPrototypeOf(obj);
|
|
@@ -48,9 +51,14 @@ const objForEach = (obj, cb) =>
|
|
|
48
51
|
const objSize = (obj) => size(objIds(obj));
|
|
49
52
|
const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
|
|
50
53
|
|
|
51
|
-
const createCustomSchematizer = (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
const createCustomSchematizer = (
|
|
55
|
+
unwrapSchema,
|
|
56
|
+
getProperties,
|
|
57
|
+
getPropertyRequired,
|
|
58
|
+
) => {
|
|
59
|
+
const toCellOrValueSchema = (schema, required) => {
|
|
60
|
+
const [unwrapped, defaultValue, allowNull, unwrappedRequired = required] =
|
|
61
|
+
unwrapSchema(schema, void 0, void 0, required);
|
|
54
62
|
const type = unwrapped?.type;
|
|
55
63
|
if (
|
|
56
64
|
type !== STRING &&
|
|
@@ -68,6 +76,9 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
|
|
|
68
76
|
if (allowNull) {
|
|
69
77
|
cellOrValueSchema[ALLOW_NULL] = true;
|
|
70
78
|
}
|
|
79
|
+
if (unwrappedRequired && isUndefined(defaultValue)) {
|
|
80
|
+
cellOrValueSchema[REQUIRED] = true;
|
|
81
|
+
}
|
|
71
82
|
return cellOrValueSchema;
|
|
72
83
|
};
|
|
73
84
|
const toTablesSchema = (schemas) => {
|
|
@@ -76,9 +87,15 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
|
|
|
76
87
|
const tableSchema = objNew();
|
|
77
88
|
ifNotUndefined(getProperties(schema), (properties) =>
|
|
78
89
|
objForEach(properties, (cellSchema, cellId) =>
|
|
79
|
-
ifNotUndefined(
|
|
80
|
-
|
|
81
|
-
|
|
90
|
+
ifNotUndefined(
|
|
91
|
+
toCellOrValueSchema(
|
|
92
|
+
cellSchema,
|
|
93
|
+
getPropertyRequired?.(schema, cellId, cellSchema),
|
|
94
|
+
),
|
|
95
|
+
(cellSchema2) => {
|
|
96
|
+
tableSchema[cellId] = cellSchema2;
|
|
97
|
+
},
|
|
98
|
+
),
|
|
82
99
|
),
|
|
83
100
|
);
|
|
84
101
|
if (!objIsEmpty(tableSchema)) {
|
|
@@ -102,7 +119,20 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
|
|
|
102
119
|
});
|
|
103
120
|
};
|
|
104
121
|
|
|
105
|
-
const
|
|
122
|
+
const TYPEBOX_OPTIONAL = 'Symbol(TypeBox.Optional)';
|
|
123
|
+
const isTypeBoxOptional = (schema) =>
|
|
124
|
+
!isUndefined(
|
|
125
|
+
arrayFind(
|
|
126
|
+
Object.getOwnPropertySymbols(schema ?? {}),
|
|
127
|
+
(symbol) => String(symbol) == TYPEBOX_OPTIONAL,
|
|
128
|
+
),
|
|
129
|
+
);
|
|
130
|
+
const unwrapSchema = (
|
|
131
|
+
schema,
|
|
132
|
+
defaultValue,
|
|
133
|
+
allowNull,
|
|
134
|
+
required = !isTypeBoxOptional(schema),
|
|
135
|
+
) => {
|
|
106
136
|
if (schema?.[ANY_OF]) {
|
|
107
137
|
const types = schema[ANY_OF];
|
|
108
138
|
const hasNull = types.some((t) => t?.type === NULL);
|
|
@@ -116,13 +146,23 @@ const unwrapSchema = (schema, defaultValue, allowNull) => {
|
|
|
116
146
|
firstNonNullType,
|
|
117
147
|
defaultValue ?? schema?.[DEFAULT],
|
|
118
148
|
hasNull || allowNull,
|
|
149
|
+
required,
|
|
119
150
|
);
|
|
120
151
|
}
|
|
121
152
|
}
|
|
122
|
-
return [
|
|
153
|
+
return [
|
|
154
|
+
schema,
|
|
155
|
+
defaultValue ?? schema?.[DEFAULT],
|
|
156
|
+
allowNull ?? false,
|
|
157
|
+
required,
|
|
158
|
+
];
|
|
123
159
|
};
|
|
124
160
|
const getProperties = (schema) => schema?.properties;
|
|
161
|
+
const getPropertyRequired = (schema, propertyId) =>
|
|
162
|
+
isUndefined(schema?.properties)
|
|
163
|
+
? void 0
|
|
164
|
+
: arrayHas(schema?.[REQUIRED] ?? [], propertyId);
|
|
125
165
|
const createTypeBoxSchematizer = () =>
|
|
126
|
-
createCustomSchematizer(unwrapSchema, getProperties);
|
|
166
|
+
createCustomSchematizer(unwrapSchema, getProperties, getPropertyRequired);
|
|
127
167
|
|
|
128
168
|
export {createTypeBoxSchematizer};
|
|
@@ -11,6 +11,7 @@ const ALLOW_NULL = 'allowNull';
|
|
|
11
11
|
const FALLBACK = 'fallback';
|
|
12
12
|
const NULLABLE = 'nullable';
|
|
13
13
|
const OPTIONAL = 'optional';
|
|
14
|
+
const REQUIRED = 'required';
|
|
14
15
|
const WRAPPED = 'wrapped';
|
|
15
16
|
const RECORD = 'record';
|
|
16
17
|
|
|
@@ -51,9 +52,14 @@ const objForEach = (obj, cb) =>
|
|
|
51
52
|
const objSize = (obj) => size(objIds(obj));
|
|
52
53
|
const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
|
|
53
54
|
|
|
54
|
-
const createCustomSchematizer = (
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
const createCustomSchematizer = (
|
|
56
|
+
unwrapSchema,
|
|
57
|
+
getProperties,
|
|
58
|
+
getPropertyRequired,
|
|
59
|
+
) => {
|
|
60
|
+
const toCellOrValueSchema = (schema, required) => {
|
|
61
|
+
const [unwrapped, defaultValue, allowNull, unwrappedRequired = required] =
|
|
62
|
+
unwrapSchema(schema, void 0, void 0, required);
|
|
57
63
|
const type = unwrapped?.type;
|
|
58
64
|
if (
|
|
59
65
|
type !== STRING &&
|
|
@@ -71,6 +77,9 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
|
|
|
71
77
|
if (allowNull) {
|
|
72
78
|
cellOrValueSchema[ALLOW_NULL] = true;
|
|
73
79
|
}
|
|
80
|
+
if (unwrappedRequired && isUndefined(defaultValue)) {
|
|
81
|
+
cellOrValueSchema[REQUIRED] = true;
|
|
82
|
+
}
|
|
74
83
|
return cellOrValueSchema;
|
|
75
84
|
};
|
|
76
85
|
const toTablesSchema = (schemas) => {
|
|
@@ -79,9 +88,15 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
|
|
|
79
88
|
const tableSchema = objNew();
|
|
80
89
|
ifNotUndefined(getProperties(schema), (properties) =>
|
|
81
90
|
objForEach(properties, (cellSchema, cellId) =>
|
|
82
|
-
ifNotUndefined(
|
|
83
|
-
|
|
84
|
-
|
|
91
|
+
ifNotUndefined(
|
|
92
|
+
toCellOrValueSchema(
|
|
93
|
+
cellSchema,
|
|
94
|
+
getPropertyRequired?.(schema, cellId, cellSchema),
|
|
95
|
+
),
|
|
96
|
+
(cellSchema2) => {
|
|
97
|
+
tableSchema[cellId] = cellSchema2;
|
|
98
|
+
},
|
|
99
|
+
),
|
|
85
100
|
),
|
|
86
101
|
);
|
|
87
102
|
if (!objIsEmpty(tableSchema)) {
|
|
@@ -107,31 +122,44 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
|
|
|
107
122
|
|
|
108
123
|
const LITERAL = 'literal';
|
|
109
124
|
const PICKLIST = 'picklist';
|
|
110
|
-
const unwrapSchema = (schema, defaultValue, allowNull) => {
|
|
125
|
+
const unwrapSchema = (schema, defaultValue, allowNull, required = true) => {
|
|
111
126
|
const type = schema?.type;
|
|
112
127
|
return type === OPTIONAL
|
|
113
|
-
? unwrapSchema(
|
|
128
|
+
? unwrapSchema(
|
|
129
|
+
schema[WRAPPED],
|
|
130
|
+
defaultValue ?? schema?.[DEFAULT],
|
|
131
|
+
allowNull,
|
|
132
|
+
false,
|
|
133
|
+
)
|
|
114
134
|
: type === NULLABLE
|
|
115
|
-
? unwrapSchema(schema[WRAPPED], defaultValue, true)
|
|
135
|
+
? unwrapSchema(schema[WRAPPED], defaultValue, true, required)
|
|
116
136
|
: type === RECORD
|
|
117
137
|
? [
|
|
118
138
|
{type: OBJECT},
|
|
119
139
|
defaultValue ?? schema?.[FALLBACK],
|
|
120
140
|
allowNull ?? false,
|
|
141
|
+
required,
|
|
121
142
|
]
|
|
122
143
|
: type === PICKLIST && arrayEvery(schema.options, isString)
|
|
123
144
|
? [
|
|
124
145
|
{[TYPE]: STRING},
|
|
125
146
|
defaultValue ?? schema?.[FALLBACK],
|
|
126
147
|
allowNull ?? false,
|
|
148
|
+
required,
|
|
127
149
|
]
|
|
128
150
|
: type === LITERAL && isString(schema.literal)
|
|
129
151
|
? [
|
|
130
152
|
{[TYPE]: STRING},
|
|
131
153
|
defaultValue ?? schema?.[FALLBACK],
|
|
132
154
|
allowNull ?? false,
|
|
155
|
+
required,
|
|
133
156
|
]
|
|
134
|
-
: [
|
|
157
|
+
: [
|
|
158
|
+
schema,
|
|
159
|
+
defaultValue ?? schema?.[FALLBACK],
|
|
160
|
+
allowNull ?? false,
|
|
161
|
+
required,
|
|
162
|
+
];
|
|
135
163
|
};
|
|
136
164
|
const getProperties = (schema) => schema?.entries;
|
|
137
165
|
const createValibotSchematizer = () =>
|
|
@@ -11,6 +11,7 @@ const ALLOW_NULL = 'allowNull';
|
|
|
11
11
|
const FALLBACK = 'fallback';
|
|
12
12
|
const NULLABLE = 'nullable';
|
|
13
13
|
const OPTIONAL = 'optional';
|
|
14
|
+
const REQUIRED = 'required';
|
|
14
15
|
const WRAPPED = 'wrapped';
|
|
15
16
|
const RECORD = 'record';
|
|
16
17
|
|
|
@@ -51,9 +52,14 @@ const objForEach = (obj, cb) =>
|
|
|
51
52
|
const objSize = (obj) => size(objIds(obj));
|
|
52
53
|
const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
|
|
53
54
|
|
|
54
|
-
const createCustomSchematizer = (
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
const createCustomSchematizer = (
|
|
56
|
+
unwrapSchema,
|
|
57
|
+
getProperties,
|
|
58
|
+
getPropertyRequired,
|
|
59
|
+
) => {
|
|
60
|
+
const toCellOrValueSchema = (schema, required) => {
|
|
61
|
+
const [unwrapped, defaultValue, allowNull, unwrappedRequired = required] =
|
|
62
|
+
unwrapSchema(schema, void 0, void 0, required);
|
|
57
63
|
const type = unwrapped?.type;
|
|
58
64
|
if (
|
|
59
65
|
type !== STRING &&
|
|
@@ -71,6 +77,9 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
|
|
|
71
77
|
if (allowNull) {
|
|
72
78
|
cellOrValueSchema[ALLOW_NULL] = true;
|
|
73
79
|
}
|
|
80
|
+
if (unwrappedRequired && isUndefined(defaultValue)) {
|
|
81
|
+
cellOrValueSchema[REQUIRED] = true;
|
|
82
|
+
}
|
|
74
83
|
return cellOrValueSchema;
|
|
75
84
|
};
|
|
76
85
|
const toTablesSchema = (schemas) => {
|
|
@@ -79,9 +88,15 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
|
|
|
79
88
|
const tableSchema = objNew();
|
|
80
89
|
ifNotUndefined(getProperties(schema), (properties) =>
|
|
81
90
|
objForEach(properties, (cellSchema, cellId) =>
|
|
82
|
-
ifNotUndefined(
|
|
83
|
-
|
|
84
|
-
|
|
91
|
+
ifNotUndefined(
|
|
92
|
+
toCellOrValueSchema(
|
|
93
|
+
cellSchema,
|
|
94
|
+
getPropertyRequired?.(schema, cellId, cellSchema),
|
|
95
|
+
),
|
|
96
|
+
(cellSchema2) => {
|
|
97
|
+
tableSchema[cellId] = cellSchema2;
|
|
98
|
+
},
|
|
99
|
+
),
|
|
85
100
|
),
|
|
86
101
|
);
|
|
87
102
|
if (!objIsEmpty(tableSchema)) {
|
|
@@ -107,31 +122,44 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
|
|
|
107
122
|
|
|
108
123
|
const LITERAL = 'literal';
|
|
109
124
|
const PICKLIST = 'picklist';
|
|
110
|
-
const unwrapSchema = (schema, defaultValue, allowNull) => {
|
|
125
|
+
const unwrapSchema = (schema, defaultValue, allowNull, required = true) => {
|
|
111
126
|
const type = schema?.type;
|
|
112
127
|
return type === OPTIONAL
|
|
113
|
-
? unwrapSchema(
|
|
128
|
+
? unwrapSchema(
|
|
129
|
+
schema[WRAPPED],
|
|
130
|
+
defaultValue ?? schema?.[DEFAULT],
|
|
131
|
+
allowNull,
|
|
132
|
+
false,
|
|
133
|
+
)
|
|
114
134
|
: type === NULLABLE
|
|
115
|
-
? unwrapSchema(schema[WRAPPED], defaultValue, true)
|
|
135
|
+
? unwrapSchema(schema[WRAPPED], defaultValue, true, required)
|
|
116
136
|
: type === RECORD
|
|
117
137
|
? [
|
|
118
138
|
{type: OBJECT},
|
|
119
139
|
defaultValue ?? schema?.[FALLBACK],
|
|
120
140
|
allowNull ?? false,
|
|
141
|
+
required,
|
|
121
142
|
]
|
|
122
143
|
: type === PICKLIST && arrayEvery(schema.options, isString)
|
|
123
144
|
? [
|
|
124
145
|
{[TYPE]: STRING},
|
|
125
146
|
defaultValue ?? schema?.[FALLBACK],
|
|
126
147
|
allowNull ?? false,
|
|
148
|
+
required,
|
|
127
149
|
]
|
|
128
150
|
: type === LITERAL && isString(schema.literal)
|
|
129
151
|
? [
|
|
130
152
|
{[TYPE]: STRING},
|
|
131
153
|
defaultValue ?? schema?.[FALLBACK],
|
|
132
154
|
allowNull ?? false,
|
|
155
|
+
required,
|
|
133
156
|
]
|
|
134
|
-
: [
|
|
157
|
+
: [
|
|
158
|
+
schema,
|
|
159
|
+
defaultValue ?? schema?.[FALLBACK],
|
|
160
|
+
allowNull ?? false,
|
|
161
|
+
required,
|
|
162
|
+
];
|
|
135
163
|
};
|
|
136
164
|
const getProperties = (schema) => schema?.entries;
|
|
137
165
|
const createValibotSchematizer = () =>
|
|
@@ -9,6 +9,8 @@ const TYPE = 'type';
|
|
|
9
9
|
const DEFAULT = 'default';
|
|
10
10
|
const ALLOW_NULL = 'allowNull';
|
|
11
11
|
const NULLABLE = 'nullable';
|
|
12
|
+
const OPTIONAL = 'optional';
|
|
13
|
+
const REQUIRED = 'required';
|
|
12
14
|
|
|
13
15
|
const getIfNotFunction = (predicate) => (value, then, otherwise) =>
|
|
14
16
|
predicate(value)
|
|
@@ -47,9 +49,14 @@ const objForEach = (obj, cb) =>
|
|
|
47
49
|
const objSize = (obj) => size(objIds(obj));
|
|
48
50
|
const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
|
|
49
51
|
|
|
50
|
-
const createCustomSchematizer = (
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
const createCustomSchematizer = (
|
|
53
|
+
unwrapSchema,
|
|
54
|
+
getProperties,
|
|
55
|
+
getPropertyRequired,
|
|
56
|
+
) => {
|
|
57
|
+
const toCellOrValueSchema = (schema, required) => {
|
|
58
|
+
const [unwrapped, defaultValue, allowNull, unwrappedRequired = required] =
|
|
59
|
+
unwrapSchema(schema, void 0, void 0, required);
|
|
53
60
|
const type = unwrapped?.type;
|
|
54
61
|
if (
|
|
55
62
|
type !== STRING &&
|
|
@@ -67,6 +74,9 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
|
|
|
67
74
|
if (allowNull) {
|
|
68
75
|
cellOrValueSchema[ALLOW_NULL] = true;
|
|
69
76
|
}
|
|
77
|
+
if (unwrappedRequired && isUndefined(defaultValue)) {
|
|
78
|
+
cellOrValueSchema[REQUIRED] = true;
|
|
79
|
+
}
|
|
70
80
|
return cellOrValueSchema;
|
|
71
81
|
};
|
|
72
82
|
const toTablesSchema = (schemas) => {
|
|
@@ -75,9 +85,15 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
|
|
|
75
85
|
const tableSchema = objNew();
|
|
76
86
|
ifNotUndefined(getProperties(schema), (properties) =>
|
|
77
87
|
objForEach(properties, (cellSchema, cellId) =>
|
|
78
|
-
ifNotUndefined(
|
|
79
|
-
|
|
80
|
-
|
|
88
|
+
ifNotUndefined(
|
|
89
|
+
toCellOrValueSchema(
|
|
90
|
+
cellSchema,
|
|
91
|
+
getPropertyRequired?.(schema, cellId, cellSchema),
|
|
92
|
+
),
|
|
93
|
+
(cellSchema2) => {
|
|
94
|
+
tableSchema[cellId] = cellSchema2;
|
|
95
|
+
},
|
|
96
|
+
),
|
|
81
97
|
),
|
|
82
98
|
);
|
|
83
99
|
if (!objIsEmpty(tableSchema)) {
|
|
@@ -102,7 +118,12 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
|
|
|
102
118
|
};
|
|
103
119
|
|
|
104
120
|
const MIXED = 'mixed';
|
|
105
|
-
const unwrapSchema = (
|
|
121
|
+
const unwrapSchema = (
|
|
122
|
+
schema,
|
|
123
|
+
defaultValue,
|
|
124
|
+
allowNull,
|
|
125
|
+
required = schema?.spec?.[OPTIONAL] === false,
|
|
126
|
+
) => {
|
|
106
127
|
const oneOf = schema?._whitelist ? Array.from(schema._whitelist) : [];
|
|
107
128
|
return [
|
|
108
129
|
{
|
|
@@ -113,6 +134,7 @@ const unwrapSchema = (schema, defaultValue, allowNull) => {
|
|
|
113
134
|
},
|
|
114
135
|
defaultValue ?? schema?.spec?.[DEFAULT],
|
|
115
136
|
allowNull || schema?.spec?.[NULLABLE] || false,
|
|
137
|
+
required,
|
|
116
138
|
];
|
|
117
139
|
};
|
|
118
140
|
const getProperties = (schema) => schema?.fields;
|
|
@@ -9,6 +9,8 @@ const TYPE = 'type';
|
|
|
9
9
|
const DEFAULT = 'default';
|
|
10
10
|
const ALLOW_NULL = 'allowNull';
|
|
11
11
|
const NULLABLE = 'nullable';
|
|
12
|
+
const OPTIONAL = 'optional';
|
|
13
|
+
const REQUIRED = 'required';
|
|
12
14
|
|
|
13
15
|
const getIfNotFunction = (predicate) => (value, then, otherwise) =>
|
|
14
16
|
predicate(value)
|
|
@@ -47,9 +49,14 @@ const objForEach = (obj, cb) =>
|
|
|
47
49
|
const objSize = (obj) => size(objIds(obj));
|
|
48
50
|
const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
|
|
49
51
|
|
|
50
|
-
const createCustomSchematizer = (
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
const createCustomSchematizer = (
|
|
53
|
+
unwrapSchema,
|
|
54
|
+
getProperties,
|
|
55
|
+
getPropertyRequired,
|
|
56
|
+
) => {
|
|
57
|
+
const toCellOrValueSchema = (schema, required) => {
|
|
58
|
+
const [unwrapped, defaultValue, allowNull, unwrappedRequired = required] =
|
|
59
|
+
unwrapSchema(schema, void 0, void 0, required);
|
|
53
60
|
const type = unwrapped?.type;
|
|
54
61
|
if (
|
|
55
62
|
type !== STRING &&
|
|
@@ -67,6 +74,9 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
|
|
|
67
74
|
if (allowNull) {
|
|
68
75
|
cellOrValueSchema[ALLOW_NULL] = true;
|
|
69
76
|
}
|
|
77
|
+
if (unwrappedRequired && isUndefined(defaultValue)) {
|
|
78
|
+
cellOrValueSchema[REQUIRED] = true;
|
|
79
|
+
}
|
|
70
80
|
return cellOrValueSchema;
|
|
71
81
|
};
|
|
72
82
|
const toTablesSchema = (schemas) => {
|
|
@@ -75,9 +85,15 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
|
|
|
75
85
|
const tableSchema = objNew();
|
|
76
86
|
ifNotUndefined(getProperties(schema), (properties) =>
|
|
77
87
|
objForEach(properties, (cellSchema, cellId) =>
|
|
78
|
-
ifNotUndefined(
|
|
79
|
-
|
|
80
|
-
|
|
88
|
+
ifNotUndefined(
|
|
89
|
+
toCellOrValueSchema(
|
|
90
|
+
cellSchema,
|
|
91
|
+
getPropertyRequired?.(schema, cellId, cellSchema),
|
|
92
|
+
),
|
|
93
|
+
(cellSchema2) => {
|
|
94
|
+
tableSchema[cellId] = cellSchema2;
|
|
95
|
+
},
|
|
96
|
+
),
|
|
81
97
|
),
|
|
82
98
|
);
|
|
83
99
|
if (!objIsEmpty(tableSchema)) {
|
|
@@ -102,7 +118,12 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
|
|
|
102
118
|
};
|
|
103
119
|
|
|
104
120
|
const MIXED = 'mixed';
|
|
105
|
-
const unwrapSchema = (
|
|
121
|
+
const unwrapSchema = (
|
|
122
|
+
schema,
|
|
123
|
+
defaultValue,
|
|
124
|
+
allowNull,
|
|
125
|
+
required = schema?.spec?.[OPTIONAL] === false,
|
|
126
|
+
) => {
|
|
106
127
|
const oneOf = schema?._whitelist ? Array.from(schema._whitelist) : [];
|
|
107
128
|
return [
|
|
108
129
|
{
|
|
@@ -113,6 +134,7 @@ const unwrapSchema = (schema, defaultValue, allowNull) => {
|
|
|
113
134
|
},
|
|
114
135
|
defaultValue ?? schema?.spec?.[DEFAULT],
|
|
115
136
|
allowNull || schema?.spec?.[NULLABLE] || false,
|
|
137
|
+
required,
|
|
116
138
|
];
|
|
117
139
|
};
|
|
118
140
|
const getProperties = (schema) => schema?.fields;
|
|
@@ -10,6 +10,7 @@ const DEFAULT = 'default';
|
|
|
10
10
|
const ALLOW_NULL = 'allowNull';
|
|
11
11
|
const NULLABLE = 'nullable';
|
|
12
12
|
const OPTIONAL = 'optional';
|
|
13
|
+
const REQUIRED = 'required';
|
|
13
14
|
const RECORD = 'record';
|
|
14
15
|
|
|
15
16
|
const getIfNotFunction = (predicate) => (value, then, otherwise) =>
|
|
@@ -49,9 +50,14 @@ const objForEach = (obj, cb) =>
|
|
|
49
50
|
const objSize = (obj) => size(objIds(obj));
|
|
50
51
|
const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
|
|
51
52
|
|
|
52
|
-
const createCustomSchematizer = (
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
const createCustomSchematizer = (
|
|
54
|
+
unwrapSchema,
|
|
55
|
+
getProperties,
|
|
56
|
+
getPropertyRequired,
|
|
57
|
+
) => {
|
|
58
|
+
const toCellOrValueSchema = (schema, required) => {
|
|
59
|
+
const [unwrapped, defaultValue, allowNull, unwrappedRequired = required] =
|
|
60
|
+
unwrapSchema(schema, void 0, void 0, required);
|
|
55
61
|
const type = unwrapped?.type;
|
|
56
62
|
if (
|
|
57
63
|
type !== STRING &&
|
|
@@ -69,6 +75,9 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
|
|
|
69
75
|
if (allowNull) {
|
|
70
76
|
cellOrValueSchema[ALLOW_NULL] = true;
|
|
71
77
|
}
|
|
78
|
+
if (unwrappedRequired && isUndefined(defaultValue)) {
|
|
79
|
+
cellOrValueSchema[REQUIRED] = true;
|
|
80
|
+
}
|
|
72
81
|
return cellOrValueSchema;
|
|
73
82
|
};
|
|
74
83
|
const toTablesSchema = (schemas) => {
|
|
@@ -77,9 +86,15 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
|
|
|
77
86
|
const tableSchema = objNew();
|
|
78
87
|
ifNotUndefined(getProperties(schema), (properties) =>
|
|
79
88
|
objForEach(properties, (cellSchema, cellId) =>
|
|
80
|
-
ifNotUndefined(
|
|
81
|
-
|
|
82
|
-
|
|
89
|
+
ifNotUndefined(
|
|
90
|
+
toCellOrValueSchema(
|
|
91
|
+
cellSchema,
|
|
92
|
+
getPropertyRequired?.(schema, cellId, cellSchema),
|
|
93
|
+
),
|
|
94
|
+
(cellSchema2) => {
|
|
95
|
+
tableSchema[cellId] = cellSchema2;
|
|
96
|
+
},
|
|
97
|
+
),
|
|
83
98
|
),
|
|
84
99
|
);
|
|
85
100
|
if (!objIsEmpty(tableSchema)) {
|
|
@@ -106,22 +121,22 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
|
|
|
106
121
|
const ENUM = 'enum';
|
|
107
122
|
const LITERAL = 'literal';
|
|
108
123
|
const getDef = (schema) => schema?.def ?? schema?._zod?.def;
|
|
109
|
-
const unwrapSchema = (schema, defaultValue, allowNull) => {
|
|
124
|
+
const unwrapSchema = (schema, defaultValue, allowNull, required = true) => {
|
|
110
125
|
const def = getDef(schema);
|
|
111
126
|
const type = def?.type;
|
|
112
127
|
return type === OPTIONAL
|
|
113
|
-
? unwrapSchema(def.innerType, defaultValue, allowNull)
|
|
128
|
+
? unwrapSchema(def.innerType, defaultValue, allowNull, false)
|
|
114
129
|
: type === NULLABLE
|
|
115
|
-
? unwrapSchema(def.innerType, defaultValue, true)
|
|
130
|
+
? unwrapSchema(def.innerType, defaultValue, true, required)
|
|
116
131
|
: type === DEFAULT
|
|
117
|
-
? unwrapSchema(def.innerType, def.defaultValue, allowNull)
|
|
132
|
+
? unwrapSchema(def.innerType, def.defaultValue, allowNull, false)
|
|
118
133
|
: type === RECORD
|
|
119
|
-
? [{type: OBJECT}, defaultValue, allowNull ?? false]
|
|
134
|
+
? [{type: OBJECT}, defaultValue, allowNull ?? false, required]
|
|
120
135
|
: type === ENUM
|
|
121
|
-
? [{[TYPE]: STRING}, defaultValue, allowNull ?? false]
|
|
136
|
+
? [{[TYPE]: STRING}, defaultValue, allowNull ?? false, required]
|
|
122
137
|
: type === LITERAL && arrayEvery(def.values, isString)
|
|
123
|
-
? [{[TYPE]: STRING}, defaultValue, allowNull ?? false]
|
|
124
|
-
: [schema, defaultValue, allowNull ?? false];
|
|
138
|
+
? [{[TYPE]: STRING}, defaultValue, allowNull ?? false, required]
|
|
139
|
+
: [schema, defaultValue, allowNull ?? false, required];
|
|
125
140
|
};
|
|
126
141
|
const getProperties = (schema) => getDef(schema)?.shape;
|
|
127
142
|
const createZodSchematizer = () =>
|
|
@@ -10,6 +10,7 @@ const DEFAULT = 'default';
|
|
|
10
10
|
const ALLOW_NULL = 'allowNull';
|
|
11
11
|
const NULLABLE = 'nullable';
|
|
12
12
|
const OPTIONAL = 'optional';
|
|
13
|
+
const REQUIRED = 'required';
|
|
13
14
|
const RECORD = 'record';
|
|
14
15
|
|
|
15
16
|
const getIfNotFunction = (predicate) => (value, then, otherwise) =>
|
|
@@ -49,9 +50,14 @@ const objForEach = (obj, cb) =>
|
|
|
49
50
|
const objSize = (obj) => size(objIds(obj));
|
|
50
51
|
const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
|
|
51
52
|
|
|
52
|
-
const createCustomSchematizer = (
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
const createCustomSchematizer = (
|
|
54
|
+
unwrapSchema,
|
|
55
|
+
getProperties,
|
|
56
|
+
getPropertyRequired,
|
|
57
|
+
) => {
|
|
58
|
+
const toCellOrValueSchema = (schema, required) => {
|
|
59
|
+
const [unwrapped, defaultValue, allowNull, unwrappedRequired = required] =
|
|
60
|
+
unwrapSchema(schema, void 0, void 0, required);
|
|
55
61
|
const type = unwrapped?.type;
|
|
56
62
|
if (
|
|
57
63
|
type !== STRING &&
|
|
@@ -69,6 +75,9 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
|
|
|
69
75
|
if (allowNull) {
|
|
70
76
|
cellOrValueSchema[ALLOW_NULL] = true;
|
|
71
77
|
}
|
|
78
|
+
if (unwrappedRequired && isUndefined(defaultValue)) {
|
|
79
|
+
cellOrValueSchema[REQUIRED] = true;
|
|
80
|
+
}
|
|
72
81
|
return cellOrValueSchema;
|
|
73
82
|
};
|
|
74
83
|
const toTablesSchema = (schemas) => {
|
|
@@ -77,9 +86,15 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
|
|
|
77
86
|
const tableSchema = objNew();
|
|
78
87
|
ifNotUndefined(getProperties(schema), (properties) =>
|
|
79
88
|
objForEach(properties, (cellSchema, cellId) =>
|
|
80
|
-
ifNotUndefined(
|
|
81
|
-
|
|
82
|
-
|
|
89
|
+
ifNotUndefined(
|
|
90
|
+
toCellOrValueSchema(
|
|
91
|
+
cellSchema,
|
|
92
|
+
getPropertyRequired?.(schema, cellId, cellSchema),
|
|
93
|
+
),
|
|
94
|
+
(cellSchema2) => {
|
|
95
|
+
tableSchema[cellId] = cellSchema2;
|
|
96
|
+
},
|
|
97
|
+
),
|
|
83
98
|
),
|
|
84
99
|
);
|
|
85
100
|
if (!objIsEmpty(tableSchema)) {
|
|
@@ -106,22 +121,22 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
|
|
|
106
121
|
const ENUM = 'enum';
|
|
107
122
|
const LITERAL = 'literal';
|
|
108
123
|
const getDef = (schema) => schema?.def ?? schema?._zod?.def;
|
|
109
|
-
const unwrapSchema = (schema, defaultValue, allowNull) => {
|
|
124
|
+
const unwrapSchema = (schema, defaultValue, allowNull, required = true) => {
|
|
110
125
|
const def = getDef(schema);
|
|
111
126
|
const type = def?.type;
|
|
112
127
|
return type === OPTIONAL
|
|
113
|
-
? unwrapSchema(def.innerType, defaultValue, allowNull)
|
|
128
|
+
? unwrapSchema(def.innerType, defaultValue, allowNull, false)
|
|
114
129
|
: type === NULLABLE
|
|
115
|
-
? unwrapSchema(def.innerType, defaultValue, true)
|
|
130
|
+
? unwrapSchema(def.innerType, defaultValue, true, required)
|
|
116
131
|
: type === DEFAULT
|
|
117
|
-
? unwrapSchema(def.innerType, def.defaultValue, allowNull)
|
|
132
|
+
? unwrapSchema(def.innerType, def.defaultValue, allowNull, false)
|
|
118
133
|
: type === RECORD
|
|
119
|
-
? [{type: OBJECT}, defaultValue, allowNull ?? false]
|
|
134
|
+
? [{type: OBJECT}, defaultValue, allowNull ?? false, required]
|
|
120
135
|
: type === ENUM
|
|
121
|
-
? [{[TYPE]: STRING}, defaultValue, allowNull ?? false]
|
|
136
|
+
? [{[TYPE]: STRING}, defaultValue, allowNull ?? false, required]
|
|
122
137
|
: type === LITERAL && arrayEvery(def.values, isString)
|
|
123
|
-
? [{[TYPE]: STRING}, defaultValue, allowNull ?? false]
|
|
124
|
-
: [schema, defaultValue, allowNull ?? false];
|
|
138
|
+
? [{[TYPE]: STRING}, defaultValue, allowNull ?? false, required]
|
|
139
|
+
: [schema, defaultValue, allowNull ?? false, required];
|
|
125
140
|
};
|
|
126
141
|
const getProperties = (schema) => getDef(schema)?.shape;
|
|
127
142
|
const createZodSchematizer = () =>
|