@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.mjs CHANGED
@@ -3839,6 +3839,33 @@ function buildArrayItemSchema(arrayField) {
3839
3839
  }
3840
3840
  return z.object(itemShape);
3841
3841
  }
3842
+ function setNestedShape(shape, path, validator) {
3843
+ const parts = path.split('.');
3844
+ if (parts.length === 1) {
3845
+ shape[path] = validator;
3846
+ return;
3847
+ }
3848
+ const [head, ...rest] = parts;
3849
+ const nestedPath = rest.join('.');
3850
+ const existingNested = shape[head];
3851
+ const nestedShape = existingNested ? {
3852
+ ...existingNested.shape
3853
+ } : {};
3854
+ setNestedShape(nestedShape, nestedPath, validator);
3855
+ shape[head] = z.object(nestedShape);
3856
+ }
3857
+ function setNestedValue(obj, path, value) {
3858
+ const parts = path.split('.');
3859
+ if (parts.length === 1) {
3860
+ obj[path] = value;
3861
+ return;
3862
+ }
3863
+ const [head, ...rest] = parts;
3864
+ if (!(head in obj) || typeof obj[head] !== 'object' || obj[head] === null) {
3865
+ obj[head] = {};
3866
+ }
3867
+ setNestedValue(obj[head], rest.join('.'), value);
3868
+ }
3842
3869
  function buildSchema(fields) {
3843
3870
  const shape = {};
3844
3871
  for (const field of fields) {
@@ -3850,10 +3877,10 @@ function buildSchema(fields) {
3850
3877
  if (field.maxItems !== undefined) {
3851
3878
  arraySchema = arraySchema.max(field.maxItems);
3852
3879
  }
3853
- shape[field.name] = arraySchema;
3880
+ setNestedShape(shape, field.name, arraySchema);
3854
3881
  } else {
3855
3882
  const validator = getValidatorForField(field);
3856
- shape[field.name] = field.required ? validator : validator.optional();
3883
+ setNestedShape(shape, field.name, field.required ? validator : validator.optional());
3857
3884
  }
3858
3885
  }
3859
3886
  return z.object(shape);
@@ -3881,7 +3908,7 @@ function buildDefaultValues(fields) {
3881
3908
  values[field.name] = [];
3882
3909
  }
3883
3910
  } else {
3884
- values[field.name] = (_a = field.defaultValue) !== null && _a !== void 0 ? _a : '';
3911
+ setNestedValue(values, field.name, (_a = field.defaultValue) !== null && _a !== void 0 ? _a : '');
3885
3912
  }
3886
3913
  }
3887
3914
  return values;