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/dist/cjs/index.cjs +7 -5
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.mjs +7 -5
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/cjs/createConfigBuilder.d.cts.map +1 -1
- package/dist/types/esm/createConfigBuilder.d.ts.map +1 -1
- package/dist/types/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/createConfigBuilder.ts +8 -4
package/package.json
CHANGED
|
@@ -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 =
|
|
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
|
-
|
|
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
|
-
|
|
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) => {
|