zcb 0.1.1 → 0.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zcb",
3
3
  "description": "Build configs with type safety from zod schema.",
4
- "version": "0.1.1",
4
+ "version": "0.1.2",
5
5
  "author": "Dylan Aubrey",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/badbatch/zod-config-builder",
@@ -1,4 +1,5 @@
1
1
  import { type JSONSchema7 } from 'json-schema';
2
+ import { cloneDeep, merge } from 'lodash-es';
2
3
  import { type ZodError, type z } from 'zod';
3
4
  import { zodToJsonSchema } from 'zod-to-json-schema';
4
5
  import { cloneNonEnumerableValues } from './transformers/cloneNonEnumerableValues.ts';
@@ -51,7 +52,8 @@ export const createConfigBuilder = <ZodTypes>(
51
52
  };
52
53
 
53
54
  type DerivedValueCallback<K extends keyof Config = keyof Config> = (c: Config) => Config[K];
54
- let config = initialValues as Config;
55
+ let config = cloneDeep(initialValues) as Config;
56
+ const defaultValues = {} as Partial<Config>;
55
57
 
56
58
  Object.defineProperty(config, NonEmumeralProperties.ZCB, {
57
59
  configurable: false,
@@ -95,7 +97,7 @@ export const createConfigBuilder = <ZodTypes>(
95
97
  },
96
98
  $flush: () => {
97
99
  const values = configBuilder.$values();
98
- config = {} as Config;
100
+ config = cloneDeep(defaultValues) as Config;
99
101
 
100
102
  Object.defineProperty(config, NonEmumeralProperties.ZCB, {
101
103
  configurable: false,
@@ -155,7 +157,7 @@ export const createConfigBuilder = <ZodTypes>(
155
157
 
156
158
  if (isValidPropertyDefinition(propertyDefinition)) {
157
159
  if (propertyDefinition.default) {
158
- config[castProperty] = propertyDefinition.default as Config[keyof Config];
160
+ defaultValues[castProperty] = propertyDefinition.default as Config[keyof Config];
159
161
  }
160
162
 
161
163
  if (propertyDefinition.type === 'array' && arrayHasInvalidDefaults(propertyDefinition)) {
@@ -178,9 +180,11 @@ export const createConfigBuilder = <ZodTypes>(
178
180
  const propertyDefaults = collateObjectPropertyDefaults(propertyDefinition);
179
181
 
180
182
  if (propertyDefaults) {
181
- config[castProperty] = propertyDefaults as Config[keyof Config];
183
+ defaultValues[castProperty] = propertyDefaults as Config[keyof Config];
182
184
  }
183
185
  }
186
+
187
+ merge(config, cloneDeep(defaultValues));
184
188
  }
185
189
 
186
190
  configBuilder[castProperty] = ((value: Config[keyof Config] | DerivedValueCallback, override?: boolean) => {