tinybase 9.1.0-beta.2 → 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.
Files changed (67) hide show
  1. package/@types/schematizers/index.d.ts +27 -9
  2. package/@types/schematizers/schematizer-arktype/index.d.ts +8 -7
  3. package/@types/schematizers/schematizer-effect/index.d.ts +7 -5
  4. package/@types/schematizers/schematizer-typebox/index.d.ts +8 -7
  5. package/@types/schematizers/schematizer-valibot/index.d.ts +8 -7
  6. package/@types/schematizers/schematizer-yup/index.d.ts +5 -4
  7. package/@types/schematizers/schematizer-zod/index.d.ts +8 -7
  8. package/@types/ui-react-dom/index.d.ts +10 -10
  9. package/@types/ui-react-dom/with-schemas/index.d.ts +10 -10
  10. package/@types/ui-react-dom-charts/index.d.ts +7 -7
  11. package/@types/ui-react-dom-charts/with-schemas/index.d.ts +7 -7
  12. package/@types/ui-react-inspector/index.d.ts +1 -1
  13. package/@types/ui-react-inspector/with-schemas/index.d.ts +1 -1
  14. package/@types/ui-solid-dom/index.d.ts +10 -10
  15. package/@types/ui-solid-dom/with-schemas/index.d.ts +10 -10
  16. package/@types/ui-solid-inspector/index.d.ts +1 -1
  17. package/@types/ui-solid-inspector/with-schemas/index.d.ts +1 -1
  18. package/@types/ui-svelte-dom/index.d.ts +10 -10
  19. package/@types/ui-svelte-dom/with-schemas/index.d.ts +10 -10
  20. package/@types/ui-svelte-inspector/index.d.ts +1 -1
  21. package/@types/ui-svelte-inspector/with-schemas/index.d.ts +1 -1
  22. package/agents.md +12 -6
  23. package/min/schematizers/index.js +1 -1
  24. package/min/schematizers/index.js.gz +0 -0
  25. package/min/schematizers/schematizer-arktype/index.js +1 -1
  26. package/min/schematizers/schematizer-arktype/index.js.gz +0 -0
  27. package/min/schematizers/schematizer-arktype/with-schemas/index.js +1 -1
  28. package/min/schematizers/schematizer-arktype/with-schemas/index.js.gz +0 -0
  29. package/min/schematizers/schematizer-effect/index.js +1 -1
  30. package/min/schematizers/schematizer-effect/index.js.gz +0 -0
  31. package/min/schematizers/schematizer-effect/with-schemas/index.js +1 -1
  32. package/min/schematizers/schematizer-effect/with-schemas/index.js.gz +0 -0
  33. package/min/schematizers/schematizer-typebox/index.js +1 -1
  34. package/min/schematizers/schematizer-typebox/index.js.gz +0 -0
  35. package/min/schematizers/schematizer-typebox/with-schemas/index.js +1 -1
  36. package/min/schematizers/schematizer-typebox/with-schemas/index.js.gz +0 -0
  37. package/min/schematizers/schematizer-valibot/index.js +1 -1
  38. package/min/schematizers/schematizer-valibot/index.js.gz +0 -0
  39. package/min/schematizers/schematizer-valibot/with-schemas/index.js +1 -1
  40. package/min/schematizers/schematizer-valibot/with-schemas/index.js.gz +0 -0
  41. package/min/schematizers/schematizer-yup/index.js +1 -1
  42. package/min/schematizers/schematizer-yup/index.js.gz +0 -0
  43. package/min/schematizers/schematizer-yup/with-schemas/index.js +1 -1
  44. package/min/schematizers/schematizer-yup/with-schemas/index.js.gz +0 -0
  45. package/min/schematizers/schematizer-zod/index.js +1 -1
  46. package/min/schematizers/schematizer-zod/index.js.gz +0 -0
  47. package/min/schematizers/schematizer-zod/with-schemas/index.js +1 -1
  48. package/min/schematizers/schematizer-zod/with-schemas/index.js.gz +0 -0
  49. package/min/schematizers/with-schemas/index.js +1 -1
  50. package/min/schematizers/with-schemas/index.js.gz +0 -0
  51. package/package.json +6 -6
  52. package/readme.md +14 -14
  53. package/releases.md +61 -61
  54. package/schematizers/index.js +21 -6
  55. package/schematizers/schematizer-arktype/index.js +52 -17
  56. package/schematizers/schematizer-arktype/with-schemas/index.js +52 -17
  57. package/schematizers/schematizer-effect/index.js +41 -11
  58. package/schematizers/schematizer-effect/with-schemas/index.js +41 -11
  59. package/schematizers/schematizer-typebox/index.js +49 -9
  60. package/schematizers/schematizer-typebox/with-schemas/index.js +49 -9
  61. package/schematizers/schematizer-valibot/index.js +38 -10
  62. package/schematizers/schematizer-valibot/with-schemas/index.js +38 -10
  63. package/schematizers/schematizer-yup/index.js +29 -7
  64. package/schematizers/schematizer-yup/with-schemas/index.js +29 -7
  65. package/schematizers/schematizer-zod/index.js +29 -14
  66. package/schematizers/schematizer-zod/with-schemas/index.js +29 -14
  67. package/schematizers/with-schemas/index.js +21 -6
@@ -8,6 +8,7 @@ const ARRAY = 'array';
8
8
  const TYPE = 'type';
9
9
  const DEFAULT = 'default';
10
10
  const ALLOW_NULL = 'allowNull';
11
+ const REQUIRED = 'required';
11
12
 
12
13
  const getIfNotFunction = (predicate) => (value, then, otherwise) =>
13
14
  predicate(value)
@@ -44,9 +45,14 @@ const objForEach = (obj, cb) =>
44
45
  const objSize = (obj) => size(objIds(obj));
45
46
  const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
46
47
 
47
- const createCustomSchematizer = (unwrapSchema, getProperties) => {
48
- const toCellOrValueSchema = (schema) => {
49
- const [unwrapped, defaultValue, allowNull] = unwrapSchema(schema);
48
+ const createCustomSchematizer = (
49
+ unwrapSchema,
50
+ getProperties,
51
+ getPropertyRequired,
52
+ ) => {
53
+ const toCellOrValueSchema = (schema, required) => {
54
+ const [unwrapped, defaultValue, allowNull, unwrappedRequired = required] =
55
+ unwrapSchema(schema, void 0, void 0, required);
50
56
  const type = unwrapped?.type;
51
57
  if (
52
58
  type !== STRING &&
@@ -64,6 +70,9 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
64
70
  if (allowNull) {
65
71
  cellOrValueSchema[ALLOW_NULL] = true;
66
72
  }
73
+ if (unwrappedRequired && isUndefined(defaultValue)) {
74
+ cellOrValueSchema[REQUIRED] = true;
75
+ }
67
76
  return cellOrValueSchema;
68
77
  };
69
78
  const toTablesSchema = (schemas) => {
@@ -72,9 +81,15 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
72
81
  const tableSchema = objNew();
73
82
  ifNotUndefined(getProperties(schema), (properties) =>
74
83
  objForEach(properties, (cellSchema, cellId) =>
75
- ifNotUndefined(toCellOrValueSchema(cellSchema), (cellSchema2) => {
76
- tableSchema[cellId] = cellSchema2;
77
- }),
84
+ ifNotUndefined(
85
+ toCellOrValueSchema(
86
+ cellSchema,
87
+ getPropertyRequired?.(schema, cellId, cellSchema),
88
+ ),
89
+ (cellSchema2) => {
90
+ tableSchema[cellId] = cellSchema2;
91
+ },
92
+ ),
78
93
  ),
79
94
  );
80
95
  if (!objIsEmpty(tableSchema)) {
@@ -58,9 +58,14 @@ const objForEach = (obj, cb) =>
58
58
  const objSize = (obj) => size(objIds(obj));
59
59
  const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
60
60
 
61
- const createCustomSchematizer = (unwrapSchema, getProperties) => {
62
- const toCellOrValueSchema = (schema) => {
63
- const [unwrapped, defaultValue, allowNull] = unwrapSchema(schema);
61
+ const createCustomSchematizer = (
62
+ unwrapSchema,
63
+ getProperties,
64
+ getPropertyRequired,
65
+ ) => {
66
+ const toCellOrValueSchema = (schema, required) => {
67
+ const [unwrapped, defaultValue, allowNull, unwrappedRequired = required] =
68
+ unwrapSchema(schema, void 0, void 0, required);
64
69
  const type = unwrapped?.type;
65
70
  if (
66
71
  type !== STRING &&
@@ -78,6 +83,9 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
78
83
  if (allowNull) {
79
84
  cellOrValueSchema[ALLOW_NULL] = true;
80
85
  }
86
+ if (unwrappedRequired && isUndefined(defaultValue)) {
87
+ cellOrValueSchema[REQUIRED] = true;
88
+ }
81
89
  return cellOrValueSchema;
82
90
  };
83
91
  const toTablesSchema = (schemas) => {
@@ -86,9 +94,15 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
86
94
  const tableSchema = objNew();
87
95
  ifNotUndefined(getProperties(schema), (properties) =>
88
96
  objForEach(properties, (cellSchema, cellId) =>
89
- ifNotUndefined(toCellOrValueSchema(cellSchema), (cellSchema2) => {
90
- tableSchema[cellId] = cellSchema2;
91
- }),
97
+ ifNotUndefined(
98
+ toCellOrValueSchema(
99
+ cellSchema,
100
+ getPropertyRequired?.(schema, cellId, cellSchema),
101
+ ),
102
+ (cellSchema2) => {
103
+ tableSchema[cellId] = cellSchema2;
104
+ },
105
+ ),
92
106
  ),
93
107
  );
94
108
  if (!objIsEmpty(tableSchema)) {
@@ -112,7 +126,7 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
112
126
  });
113
127
  };
114
128
 
115
- const unwrapSchema = (schema, defaultValue, allowNull) => {
129
+ const unwrapSchema = (schema, defaultValue, allowNull, required = true) => {
116
130
  const schemaData = schema?.json ?? schema;
117
131
  if (isArray(schemaData)) {
118
132
  const hasNull = !arrayEvery(
@@ -124,10 +138,10 @@ const unwrapSchema = (schema, defaultValue, allowNull) => {
124
138
  isFalse(schemaData[0]?.[UNIT]) &&
125
139
  isTrue(schemaData[1]?.[UNIT])
126
140
  ) {
127
- return [{[TYPE]: BOOLEAN}, defaultValue, allowNull ?? false];
141
+ return [{[TYPE]: BOOLEAN}, defaultValue, allowNull ?? false, required];
128
142
  }
129
143
  if (arrayEvery(schemaData, (item) => isString(item?.[UNIT] ?? item))) {
130
- return [{[TYPE]: STRING}, defaultValue, allowNull ?? false];
144
+ return [{[TYPE]: STRING}, defaultValue, allowNull ?? false, required];
131
145
  }
132
146
  if (hasNull) {
133
147
  const nonNullItem = arrayFind(
@@ -135,20 +149,21 @@ const unwrapSchema = (schema, defaultValue, allowNull) => {
135
149
  (item) => !isNull(item?.[UNIT]) && !isNull(item) && item !== '=',
136
150
  );
137
151
  if (nonNullItem) {
138
- return unwrapSchema(nonNullItem, defaultValue, true);
152
+ return unwrapSchema(nonNullItem, defaultValue, true, required);
139
153
  }
140
154
  }
141
155
  }
142
156
  if (!isArray(schemaData) && !isUndefined(schemaData?.[SEQUENCE])) {
143
- return [{[TYPE]: ARRAY}, defaultValue, allowNull ?? false];
157
+ return [{[TYPE]: ARRAY}, defaultValue, allowNull ?? false, required];
144
158
  }
145
159
  if (!isArray(schemaData) && isString(schemaData?.[UNIT])) {
146
- return [{[TYPE]: STRING}, defaultValue, allowNull ?? false];
160
+ return [{[TYPE]: STRING}, defaultValue, allowNull ?? false, required];
147
161
  }
148
162
  return [
149
163
  {[TYPE]: schemaData?.[DOMAIN] || schemaData},
150
164
  defaultValue,
151
165
  allowNull ?? false,
166
+ required,
152
167
  ];
153
168
  };
154
169
  const getProperties = (schema) => {
@@ -170,17 +185,37 @@ const getProperties = (schema) => {
170
185
  }
171
186
  return objIsEmpty(properties) ? void 0 : properties;
172
187
  };
173
- const unwrapSchemaWithDefaults = (schema, defaultValue, allowNull) => {
188
+ const getPropertyRequired = (schema, fieldId) => {
189
+ const schemaData = schema?.json ?? schema;
190
+ return isArray(schemaData?.[REQUIRED]) || isArray(schemaData?.[OPTIONAL])
191
+ ? !isUndefined(
192
+ arrayFind(
193
+ schemaData?.[REQUIRED] ?? [],
194
+ (field) => field[KEY] === fieldId,
195
+ ),
196
+ )
197
+ : void 0;
198
+ };
199
+ const unwrapSchemaWithDefaults = (
200
+ schema,
201
+ defaultValue,
202
+ allowNull,
203
+ required = true,
204
+ ) => {
174
205
  if (isArray(schema) && size(schema) === 3 && schema[1] === '=') {
175
206
  const schemaValue = schema[0]?.json ?? schema[0];
176
- return unwrapSchema(schemaValue, schema[2], allowNull);
207
+ return unwrapSchema(schemaValue, schema[2], allowNull, false);
177
208
  }
178
209
  if (schema?.[_VALUE] && !isUndefined(schema?.[DEFAULT])) {
179
- return unwrapSchema(schema[_VALUE], schema[DEFAULT], allowNull);
210
+ return unwrapSchema(schema[_VALUE], schema[DEFAULT], allowNull, false);
180
211
  }
181
- return unwrapSchema(schema, defaultValue, allowNull);
212
+ return unwrapSchema(schema, defaultValue, allowNull, required);
182
213
  };
183
214
  const createArkTypeSchematizer = () =>
184
- createCustomSchematizer(unwrapSchemaWithDefaults, getProperties);
215
+ createCustomSchematizer(
216
+ unwrapSchemaWithDefaults,
217
+ getProperties,
218
+ getPropertyRequired,
219
+ );
185
220
 
186
221
  export {createArkTypeSchematizer};
@@ -58,9 +58,14 @@ const objForEach = (obj, cb) =>
58
58
  const objSize = (obj) => size(objIds(obj));
59
59
  const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
60
60
 
61
- const createCustomSchematizer = (unwrapSchema, getProperties) => {
62
- const toCellOrValueSchema = (schema) => {
63
- const [unwrapped, defaultValue, allowNull] = unwrapSchema(schema);
61
+ const createCustomSchematizer = (
62
+ unwrapSchema,
63
+ getProperties,
64
+ getPropertyRequired,
65
+ ) => {
66
+ const toCellOrValueSchema = (schema, required) => {
67
+ const [unwrapped, defaultValue, allowNull, unwrappedRequired = required] =
68
+ unwrapSchema(schema, void 0, void 0, required);
64
69
  const type = unwrapped?.type;
65
70
  if (
66
71
  type !== STRING &&
@@ -78,6 +83,9 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
78
83
  if (allowNull) {
79
84
  cellOrValueSchema[ALLOW_NULL] = true;
80
85
  }
86
+ if (unwrappedRequired && isUndefined(defaultValue)) {
87
+ cellOrValueSchema[REQUIRED] = true;
88
+ }
81
89
  return cellOrValueSchema;
82
90
  };
83
91
  const toTablesSchema = (schemas) => {
@@ -86,9 +94,15 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
86
94
  const tableSchema = objNew();
87
95
  ifNotUndefined(getProperties(schema), (properties) =>
88
96
  objForEach(properties, (cellSchema, cellId) =>
89
- ifNotUndefined(toCellOrValueSchema(cellSchema), (cellSchema2) => {
90
- tableSchema[cellId] = cellSchema2;
91
- }),
97
+ ifNotUndefined(
98
+ toCellOrValueSchema(
99
+ cellSchema,
100
+ getPropertyRequired?.(schema, cellId, cellSchema),
101
+ ),
102
+ (cellSchema2) => {
103
+ tableSchema[cellId] = cellSchema2;
104
+ },
105
+ ),
92
106
  ),
93
107
  );
94
108
  if (!objIsEmpty(tableSchema)) {
@@ -112,7 +126,7 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
112
126
  });
113
127
  };
114
128
 
115
- const unwrapSchema = (schema, defaultValue, allowNull) => {
129
+ const unwrapSchema = (schema, defaultValue, allowNull, required = true) => {
116
130
  const schemaData = schema?.json ?? schema;
117
131
  if (isArray(schemaData)) {
118
132
  const hasNull = !arrayEvery(
@@ -124,10 +138,10 @@ const unwrapSchema = (schema, defaultValue, allowNull) => {
124
138
  isFalse(schemaData[0]?.[UNIT]) &&
125
139
  isTrue(schemaData[1]?.[UNIT])
126
140
  ) {
127
- return [{[TYPE]: BOOLEAN}, defaultValue, allowNull ?? false];
141
+ return [{[TYPE]: BOOLEAN}, defaultValue, allowNull ?? false, required];
128
142
  }
129
143
  if (arrayEvery(schemaData, (item) => isString(item?.[UNIT] ?? item))) {
130
- return [{[TYPE]: STRING}, defaultValue, allowNull ?? false];
144
+ return [{[TYPE]: STRING}, defaultValue, allowNull ?? false, required];
131
145
  }
132
146
  if (hasNull) {
133
147
  const nonNullItem = arrayFind(
@@ -135,20 +149,21 @@ const unwrapSchema = (schema, defaultValue, allowNull) => {
135
149
  (item) => !isNull(item?.[UNIT]) && !isNull(item) && item !== '=',
136
150
  );
137
151
  if (nonNullItem) {
138
- return unwrapSchema(nonNullItem, defaultValue, true);
152
+ return unwrapSchema(nonNullItem, defaultValue, true, required);
139
153
  }
140
154
  }
141
155
  }
142
156
  if (!isArray(schemaData) && !isUndefined(schemaData?.[SEQUENCE])) {
143
- return [{[TYPE]: ARRAY}, defaultValue, allowNull ?? false];
157
+ return [{[TYPE]: ARRAY}, defaultValue, allowNull ?? false, required];
144
158
  }
145
159
  if (!isArray(schemaData) && isString(schemaData?.[UNIT])) {
146
- return [{[TYPE]: STRING}, defaultValue, allowNull ?? false];
160
+ return [{[TYPE]: STRING}, defaultValue, allowNull ?? false, required];
147
161
  }
148
162
  return [
149
163
  {[TYPE]: schemaData?.[DOMAIN] || schemaData},
150
164
  defaultValue,
151
165
  allowNull ?? false,
166
+ required,
152
167
  ];
153
168
  };
154
169
  const getProperties = (schema) => {
@@ -170,17 +185,37 @@ const getProperties = (schema) => {
170
185
  }
171
186
  return objIsEmpty(properties) ? void 0 : properties;
172
187
  };
173
- const unwrapSchemaWithDefaults = (schema, defaultValue, allowNull) => {
188
+ const getPropertyRequired = (schema, fieldId) => {
189
+ const schemaData = schema?.json ?? schema;
190
+ return isArray(schemaData?.[REQUIRED]) || isArray(schemaData?.[OPTIONAL])
191
+ ? !isUndefined(
192
+ arrayFind(
193
+ schemaData?.[REQUIRED] ?? [],
194
+ (field) => field[KEY] === fieldId,
195
+ ),
196
+ )
197
+ : void 0;
198
+ };
199
+ const unwrapSchemaWithDefaults = (
200
+ schema,
201
+ defaultValue,
202
+ allowNull,
203
+ required = true,
204
+ ) => {
174
205
  if (isArray(schema) && size(schema) === 3 && schema[1] === '=') {
175
206
  const schemaValue = schema[0]?.json ?? schema[0];
176
- return unwrapSchema(schemaValue, schema[2], allowNull);
207
+ return unwrapSchema(schemaValue, schema[2], allowNull, false);
177
208
  }
178
209
  if (schema?.[_VALUE] && !isUndefined(schema?.[DEFAULT])) {
179
- return unwrapSchema(schema[_VALUE], schema[DEFAULT], allowNull);
210
+ return unwrapSchema(schema[_VALUE], schema[DEFAULT], allowNull, false);
180
211
  }
181
- return unwrapSchema(schema, defaultValue, allowNull);
212
+ return unwrapSchema(schema, defaultValue, allowNull, required);
182
213
  };
183
214
  const createArkTypeSchematizer = () =>
184
- createCustomSchematizer(unwrapSchemaWithDefaults, getProperties);
215
+ createCustomSchematizer(
216
+ unwrapSchemaWithDefaults,
217
+ getProperties,
218
+ getPropertyRequired,
219
+ );
185
220
 
186
221
  export {createArkTypeSchematizer};
@@ -8,6 +8,7 @@ const ARRAY = 'array';
8
8
  const TYPE = 'type';
9
9
  const DEFAULT = 'default';
10
10
  const ALLOW_NULL = 'allowNull';
11
+ const REQUIRED = 'required';
11
12
  const LITERAL = 'Literal';
12
13
  const PROPERTY_SIGNATURES = 'propertySignatures';
13
14
  const STRING_KEYWORD = 'StringKeyword';
@@ -54,9 +55,14 @@ const objForEach = (obj, cb) =>
54
55
  const objSize = (obj) => size(objIds(obj));
55
56
  const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
56
57
 
57
- const createCustomSchematizer = (unwrapSchema, getProperties) => {
58
- const toCellOrValueSchema = (schema) => {
59
- const [unwrapped, defaultValue, allowNull] = unwrapSchema(schema);
58
+ const createCustomSchematizer = (
59
+ unwrapSchema,
60
+ getProperties,
61
+ getPropertyRequired,
62
+ ) => {
63
+ const toCellOrValueSchema = (schema, required) => {
64
+ const [unwrapped, defaultValue, allowNull, unwrappedRequired = required] =
65
+ unwrapSchema(schema, void 0, void 0, required);
60
66
  const type = unwrapped?.type;
61
67
  if (
62
68
  type !== STRING &&
@@ -74,6 +80,9 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
74
80
  if (allowNull) {
75
81
  cellOrValueSchema[ALLOW_NULL] = true;
76
82
  }
83
+ if (unwrappedRequired && isUndefined(defaultValue)) {
84
+ cellOrValueSchema[REQUIRED] = true;
85
+ }
77
86
  return cellOrValueSchema;
78
87
  };
79
88
  const toTablesSchema = (schemas) => {
@@ -82,9 +91,15 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
82
91
  const tableSchema = objNew();
83
92
  ifNotUndefined(getProperties(schema), (properties) =>
84
93
  objForEach(properties, (cellSchema, cellId) =>
85
- ifNotUndefined(toCellOrValueSchema(cellSchema), (cellSchema2) => {
86
- tableSchema[cellId] = cellSchema2;
87
- }),
94
+ ifNotUndefined(
95
+ toCellOrValueSchema(
96
+ cellSchema,
97
+ getPropertyRequired?.(schema, cellId, cellSchema),
98
+ ),
99
+ (cellSchema2) => {
100
+ tableSchema[cellId] = cellSchema2;
101
+ },
102
+ ),
88
103
  ),
89
104
  );
90
105
  if (!objIsEmpty(tableSchema)) {
@@ -108,11 +123,13 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
108
123
  });
109
124
  };
110
125
 
111
- const unwrapSchema = (schema, defaultValue, allowNull) => {
126
+ const unwrapSchema = (schema, defaultValue, allowNull, required = true) => {
112
127
  const ast = schema.ast || schema;
113
- const type = ast._tag;
128
+ const typeAst = ast.type || ast;
129
+ required = required && !ast.isOptional;
130
+ const type = typeAst._tag;
114
131
  if (type === UNION) {
115
- const types = ast.types;
132
+ const types = typeAst.types;
116
133
  const nonNullType = arrayFind(
117
134
  types,
118
135
  (t) => !(t._tag === LITERAL && isNull(t.literal)),
@@ -122,9 +139,15 @@ const unwrapSchema = (schema, defaultValue, allowNull) => {
122
139
  defaultValue,
123
140
  allowNull ||
124
141
  !!arrayFind(types, (t) => t._tag === LITERAL && isNull(t.literal)),
142
+ required,
125
143
  ];
126
144
  }
127
- return [{[TYPE]: getSimpleType(ast)}, defaultValue, allowNull || false];
145
+ return [
146
+ {[TYPE]: getSimpleType(typeAst)},
147
+ defaultValue,
148
+ allowNull || false,
149
+ required,
150
+ ];
128
151
  };
129
152
  const getSimpleType = (ast) => {
130
153
  const tag = ast?._tag;
@@ -160,7 +183,14 @@ const getProperties = (schema) => {
160
183
  }
161
184
  }
162
185
  };
186
+ const getPropertyRequired = (schema, propertyId) => {
187
+ const signatures = schema.ast?.[PROPERTY_SIGNATURES];
188
+ const signature = signatures
189
+ ? arrayFind(signatures, (sig) => sig.name === propertyId)
190
+ : void 0;
191
+ return signature ? !signature.isOptional : void 0;
192
+ };
163
193
  const createEffectSchematizer = () =>
164
- createCustomSchematizer(unwrapSchema, getProperties);
194
+ createCustomSchematizer(unwrapSchema, getProperties, getPropertyRequired);
165
195
 
166
196
  export {createEffectSchematizer};
@@ -8,6 +8,7 @@ const ARRAY = 'array';
8
8
  const TYPE = 'type';
9
9
  const DEFAULT = 'default';
10
10
  const ALLOW_NULL = 'allowNull';
11
+ const REQUIRED = 'required';
11
12
  const LITERAL = 'Literal';
12
13
  const PROPERTY_SIGNATURES = 'propertySignatures';
13
14
  const STRING_KEYWORD = 'StringKeyword';
@@ -54,9 +55,14 @@ const objForEach = (obj, cb) =>
54
55
  const objSize = (obj) => size(objIds(obj));
55
56
  const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
56
57
 
57
- const createCustomSchematizer = (unwrapSchema, getProperties) => {
58
- const toCellOrValueSchema = (schema) => {
59
- const [unwrapped, defaultValue, allowNull] = unwrapSchema(schema);
58
+ const createCustomSchematizer = (
59
+ unwrapSchema,
60
+ getProperties,
61
+ getPropertyRequired,
62
+ ) => {
63
+ const toCellOrValueSchema = (schema, required) => {
64
+ const [unwrapped, defaultValue, allowNull, unwrappedRequired = required] =
65
+ unwrapSchema(schema, void 0, void 0, required);
60
66
  const type = unwrapped?.type;
61
67
  if (
62
68
  type !== STRING &&
@@ -74,6 +80,9 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
74
80
  if (allowNull) {
75
81
  cellOrValueSchema[ALLOW_NULL] = true;
76
82
  }
83
+ if (unwrappedRequired && isUndefined(defaultValue)) {
84
+ cellOrValueSchema[REQUIRED] = true;
85
+ }
77
86
  return cellOrValueSchema;
78
87
  };
79
88
  const toTablesSchema = (schemas) => {
@@ -82,9 +91,15 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
82
91
  const tableSchema = objNew();
83
92
  ifNotUndefined(getProperties(schema), (properties) =>
84
93
  objForEach(properties, (cellSchema, cellId) =>
85
- ifNotUndefined(toCellOrValueSchema(cellSchema), (cellSchema2) => {
86
- tableSchema[cellId] = cellSchema2;
87
- }),
94
+ ifNotUndefined(
95
+ toCellOrValueSchema(
96
+ cellSchema,
97
+ getPropertyRequired?.(schema, cellId, cellSchema),
98
+ ),
99
+ (cellSchema2) => {
100
+ tableSchema[cellId] = cellSchema2;
101
+ },
102
+ ),
88
103
  ),
89
104
  );
90
105
  if (!objIsEmpty(tableSchema)) {
@@ -108,11 +123,13 @@ const createCustomSchematizer = (unwrapSchema, getProperties) => {
108
123
  });
109
124
  };
110
125
 
111
- const unwrapSchema = (schema, defaultValue, allowNull) => {
126
+ const unwrapSchema = (schema, defaultValue, allowNull, required = true) => {
112
127
  const ast = schema.ast || schema;
113
- const type = ast._tag;
128
+ const typeAst = ast.type || ast;
129
+ required = required && !ast.isOptional;
130
+ const type = typeAst._tag;
114
131
  if (type === UNION) {
115
- const types = ast.types;
132
+ const types = typeAst.types;
116
133
  const nonNullType = arrayFind(
117
134
  types,
118
135
  (t) => !(t._tag === LITERAL && isNull(t.literal)),
@@ -122,9 +139,15 @@ const unwrapSchema = (schema, defaultValue, allowNull) => {
122
139
  defaultValue,
123
140
  allowNull ||
124
141
  !!arrayFind(types, (t) => t._tag === LITERAL && isNull(t.literal)),
142
+ required,
125
143
  ];
126
144
  }
127
- return [{[TYPE]: getSimpleType(ast)}, defaultValue, allowNull || false];
145
+ return [
146
+ {[TYPE]: getSimpleType(typeAst)},
147
+ defaultValue,
148
+ allowNull || false,
149
+ required,
150
+ ];
128
151
  };
129
152
  const getSimpleType = (ast) => {
130
153
  const tag = ast?._tag;
@@ -160,7 +183,14 @@ const getProperties = (schema) => {
160
183
  }
161
184
  }
162
185
  };
186
+ const getPropertyRequired = (schema, propertyId) => {
187
+ const signatures = schema.ast?.[PROPERTY_SIGNATURES];
188
+ const signature = signatures
189
+ ? arrayFind(signatures, (sig) => sig.name === propertyId)
190
+ : void 0;
191
+ return signature ? !signature.isOptional : void 0;
192
+ };
163
193
  const createEffectSchematizer = () =>
164
- createCustomSchematizer(unwrapSchema, getProperties);
194
+ createCustomSchematizer(unwrapSchema, getProperties, getPropertyRequired);
165
195
 
166
196
  export {createEffectSchematizer};
@@ -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 = (unwrapSchema, getProperties) => {
52
- const toCellOrValueSchema = (schema) => {
53
- const [unwrapped, defaultValue, allowNull] = unwrapSchema(schema);
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(toCellOrValueSchema(cellSchema), (cellSchema2) => {
80
- tableSchema[cellId] = cellSchema2;
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 unwrapSchema = (schema, defaultValue, allowNull) => {
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 [schema, defaultValue ?? schema?.[DEFAULT], allowNull ?? false];
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};