@connect-soft/form-generator 1.1.1 → 1.1.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/dist/index.js +30 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -3
- package/dist/index.mjs.map +1 -1
- package/dist/types/components/form/form-utils.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3859,6 +3859,33 @@ function buildArrayItemSchema(arrayField) {
|
|
|
3859
3859
|
}
|
|
3860
3860
|
return zod.z.object(itemShape);
|
|
3861
3861
|
}
|
|
3862
|
+
function setNestedShape(shape, path, validator) {
|
|
3863
|
+
const parts = path.split('.');
|
|
3864
|
+
if (parts.length === 1) {
|
|
3865
|
+
shape[path] = validator;
|
|
3866
|
+
return;
|
|
3867
|
+
}
|
|
3868
|
+
const [head, ...rest] = parts;
|
|
3869
|
+
const nestedPath = rest.join('.');
|
|
3870
|
+
const existingNested = shape[head];
|
|
3871
|
+
const nestedShape = existingNested ? {
|
|
3872
|
+
...existingNested.shape
|
|
3873
|
+
} : {};
|
|
3874
|
+
setNestedShape(nestedShape, nestedPath, validator);
|
|
3875
|
+
shape[head] = zod.z.object(nestedShape);
|
|
3876
|
+
}
|
|
3877
|
+
function setNestedValue(obj, path, value) {
|
|
3878
|
+
const parts = path.split('.');
|
|
3879
|
+
if (parts.length === 1) {
|
|
3880
|
+
obj[path] = value;
|
|
3881
|
+
return;
|
|
3882
|
+
}
|
|
3883
|
+
const [head, ...rest] = parts;
|
|
3884
|
+
if (!(head in obj) || typeof obj[head] !== 'object' || obj[head] === null) {
|
|
3885
|
+
obj[head] = {};
|
|
3886
|
+
}
|
|
3887
|
+
setNestedValue(obj[head], rest.join('.'), value);
|
|
3888
|
+
}
|
|
3862
3889
|
function buildSchema(fields) {
|
|
3863
3890
|
const shape = {};
|
|
3864
3891
|
for (const field of fields) {
|
|
@@ -3870,10 +3897,10 @@ function buildSchema(fields) {
|
|
|
3870
3897
|
if (field.maxItems !== undefined) {
|
|
3871
3898
|
arraySchema = arraySchema.max(field.maxItems);
|
|
3872
3899
|
}
|
|
3873
|
-
shape
|
|
3900
|
+
setNestedShape(shape, field.name, arraySchema);
|
|
3874
3901
|
} else {
|
|
3875
3902
|
const validator = getValidatorForField(field);
|
|
3876
|
-
shape
|
|
3903
|
+
setNestedShape(shape, field.name, field.required ? validator : validator.optional());
|
|
3877
3904
|
}
|
|
3878
3905
|
}
|
|
3879
3906
|
return zod.z.object(shape);
|
|
@@ -3901,7 +3928,7 @@ function buildDefaultValues(fields) {
|
|
|
3901
3928
|
values[field.name] = [];
|
|
3902
3929
|
}
|
|
3903
3930
|
} else {
|
|
3904
|
-
values
|
|
3931
|
+
setNestedValue(values, field.name, (_a = field.defaultValue) !== null && _a !== void 0 ? _a : '');
|
|
3905
3932
|
}
|
|
3906
3933
|
}
|
|
3907
3934
|
return values;
|