tinybase 9.2.0-beta.0 → 9.3.0-beta.0

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 (53) 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/agents.md +74 -14
  9. package/min/schematizers/index.js +1 -1
  10. package/min/schematizers/index.js.gz +0 -0
  11. package/min/schematizers/schematizer-arktype/index.js +1 -1
  12. package/min/schematizers/schematizer-arktype/index.js.gz +0 -0
  13. package/min/schematizers/schematizer-arktype/with-schemas/index.js +1 -1
  14. package/min/schematizers/schematizer-arktype/with-schemas/index.js.gz +0 -0
  15. package/min/schematizers/schematizer-effect/index.js +1 -1
  16. package/min/schematizers/schematizer-effect/index.js.gz +0 -0
  17. package/min/schematizers/schematizer-effect/with-schemas/index.js +1 -1
  18. package/min/schematizers/schematizer-effect/with-schemas/index.js.gz +0 -0
  19. package/min/schematizers/schematizer-typebox/index.js +1 -1
  20. package/min/schematizers/schematizer-typebox/index.js.gz +0 -0
  21. package/min/schematizers/schematizer-typebox/with-schemas/index.js +1 -1
  22. package/min/schematizers/schematizer-typebox/with-schemas/index.js.gz +0 -0
  23. package/min/schematizers/schematizer-valibot/index.js +1 -1
  24. package/min/schematizers/schematizer-valibot/index.js.gz +0 -0
  25. package/min/schematizers/schematizer-valibot/with-schemas/index.js +1 -1
  26. package/min/schematizers/schematizer-valibot/with-schemas/index.js.gz +0 -0
  27. package/min/schematizers/schematizer-yup/index.js +1 -1
  28. package/min/schematizers/schematizer-yup/index.js.gz +0 -0
  29. package/min/schematizers/schematizer-yup/with-schemas/index.js +1 -1
  30. package/min/schematizers/schematizer-yup/with-schemas/index.js.gz +0 -0
  31. package/min/schematizers/schematizer-zod/index.js +1 -1
  32. package/min/schematizers/schematizer-zod/index.js.gz +0 -0
  33. package/min/schematizers/schematizer-zod/with-schemas/index.js +1 -1
  34. package/min/schematizers/schematizer-zod/with-schemas/index.js.gz +0 -0
  35. package/min/schematizers/with-schemas/index.js +1 -1
  36. package/min/schematizers/with-schemas/index.js.gz +0 -0
  37. package/package.json +12 -5
  38. package/readme.md +3 -3
  39. package/releases.md +8 -2
  40. package/schematizers/index.js +21 -6
  41. package/schematizers/schematizer-arktype/index.js +52 -17
  42. package/schematizers/schematizer-arktype/with-schemas/index.js +52 -17
  43. package/schematizers/schematizer-effect/index.js +41 -11
  44. package/schematizers/schematizer-effect/with-schemas/index.js +41 -11
  45. package/schematizers/schematizer-typebox/index.js +49 -9
  46. package/schematizers/schematizer-typebox/with-schemas/index.js +49 -9
  47. package/schematizers/schematizer-valibot/index.js +38 -10
  48. package/schematizers/schematizer-valibot/with-schemas/index.js +38 -10
  49. package/schematizers/schematizer-yup/index.js +29 -7
  50. package/schematizers/schematizer-yup/with-schemas/index.js +29 -7
  51. package/schematizers/schematizer-zod/index.js +29 -14
  52. package/schematizers/schematizer-zod/with-schemas/index.js +29 -14
  53. package/schematizers/with-schemas/index.js +21 -6
@@ -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 = (unwrapSchema, getProperties) => {
55
- const toCellOrValueSchema = (schema) => {
56
- const [unwrapped, defaultValue, allowNull] = unwrapSchema(schema);
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(toCellOrValueSchema(cellSchema), (cellSchema2) => {
83
- tableSchema[cellId] = cellSchema2;
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(schema[WRAPPED], defaultValue, allowNull)
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
- : [schema, defaultValue ?? schema?.[FALLBACK], allowNull ?? false];
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 = (unwrapSchema, getProperties) => {
51
- const toCellOrValueSchema = (schema) => {
52
- const [unwrapped, defaultValue, allowNull] = unwrapSchema(schema);
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(toCellOrValueSchema(cellSchema), (cellSchema2) => {
79
- tableSchema[cellId] = cellSchema2;
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 = (schema, defaultValue, allowNull) => {
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 = (unwrapSchema, getProperties) => {
51
- const toCellOrValueSchema = (schema) => {
52
- const [unwrapped, defaultValue, allowNull] = unwrapSchema(schema);
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(toCellOrValueSchema(cellSchema), (cellSchema2) => {
79
- tableSchema[cellId] = cellSchema2;
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 = (schema, defaultValue, allowNull) => {
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 = (unwrapSchema, getProperties) => {
53
- const toCellOrValueSchema = (schema) => {
54
- const [unwrapped, defaultValue, allowNull] = unwrapSchema(schema);
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(toCellOrValueSchema(cellSchema), (cellSchema2) => {
81
- tableSchema[cellId] = cellSchema2;
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 = (unwrapSchema, getProperties) => {
53
- const toCellOrValueSchema = (schema) => {
54
- const [unwrapped, defaultValue, allowNull] = unwrapSchema(schema);
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(toCellOrValueSchema(cellSchema), (cellSchema2) => {
81
- tableSchema[cellId] = cellSchema2;
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 = () =>
@@ -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)) {