@zod-utils/core 7.0.1 → 7.2.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.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as z from 'zod';
2
2
  import { z as z$1, util } from 'zod';
3
- import { SomeType, $InferUnionInput, $ZodCheckLessThanDef, $ZodCheckGreaterThanDef, $ZodCheckMultipleOfDef, $ZodCheckNumberFormatDef, $ZodCheckBigIntFormatDef, $ZodCheckMaxSizeDef, $ZodCheckMinSizeDef, $ZodCheckSizeEqualsDef, $ZodCheckMaxLengthDef, $ZodCheckMinLengthDef, $ZodCheckLengthEqualsDef, $ZodCheckStringFormatDef, $ZodCheckRegexDef, $ZodCheckLowerCaseDef, $ZodCheckUpperCaseDef, $ZodCheckIncludesDef, $ZodCheckStartsWithDef, $ZodCheckEndsWithDef, $ZodCheckPropertyDef, $ZodCheckMimeTypeDef, $ZodCheckOverwriteDef } from 'zod/v4/core';
3
+ import { SomeType, $InferUnionInput, $ZodType, $ZodCheckLessThanDef, $ZodCheckGreaterThanDef, $ZodCheckMultipleOfDef, $ZodCheckNumberFormatDef, $ZodCheckMaxSizeDef, $ZodCheckMinSizeDef, $ZodCheckSizeEqualsDef, $ZodCheckMaxLengthDef, $ZodCheckMinLengthDef, $ZodCheckLengthEqualsDef, $ZodCheckStringFormatDef, $ZodCheckRegexDef, $ZodCheckIncludesDef, $ZodCheckStartsWithDef, $ZodCheckEndsWithDef, $ZodCheckMimeTypeDef, $ZodCheckOverwriteDef } from 'zod/v4/core';
4
4
 
5
5
  /**
6
6
  * Simplifies complex TypeScript types for better IDE hover tooltips and error messages.
@@ -365,6 +365,11 @@ type NameAndDiscriminatorProps<TSchema extends z$1.ZodType, TDiscriminatorKey ex
365
365
  */
366
366
  type FieldSelectorProps<TSchema extends z$1.ZodType, TDiscriminatorKey extends DiscriminatorKey<TSchema> = never, TDiscriminatorValue extends DiscriminatorValue<TSchema, TDiscriminatorKey> = never, TFilterType = unknown, TStrict extends boolean = true> = SchemaProps<TSchema> & NameAndDiscriminatorProps<TSchema, TDiscriminatorKey, TDiscriminatorValue, TFilterType, TStrict>;
367
367
 
368
+ /**
369
+ * Type-safe helper to iterate over ZodObject shape entries.
370
+ * @internal
371
+ */
372
+ declare function getShapeEntries(schema: z.ZodObject): Array<[string, z.ZodType | undefined]>;
368
373
  /**
369
374
  * Extracts the default value from a Zod field, recursively unwrapping optional, nullable, and union layers.
370
375
  *
@@ -650,19 +655,45 @@ type ExtractZodUnionMember<TSchema extends z$1.ZodUnion | z$1.ZodDiscriminatedUn
650
655
  * @see {@link ExtractZodUnionMember} for the type-level extraction logic
651
656
  * @since 0.6.0
652
657
  */
653
- declare const extractDiscriminatedSchema: <TSchema extends z$1.ZodType, TDiscriminatorKey extends DiscriminatorKey<TSchema>, TDiscriminatorValue extends DiscriminatorValue<TSchema, TDiscriminatorKey>, ReturnType extends TSchema extends z$1.ZodDiscriminatedUnion ? ExtractZodUnionMember<TSchema, TDiscriminatorKey, TDiscriminatorValue> : never>({ schema, discriminator, }: SchemaAndDiscriminatorProps<TSchema, TDiscriminatorKey, TDiscriminatorValue>) => ReturnType | undefined;
658
+ declare const extractDiscriminatedSchema: <TSchema extends z$1.ZodType, TDiscriminatorKey extends DiscriminatorKey<TSchema>, TDiscriminatorValue extends DiscriminatorValue<TSchema, TDiscriminatorKey>, TUnwrapped extends z$1.ZodType = UnwrapZodType<TSchema> extends z$1.ZodType ? UnwrapZodType<TSchema> : TSchema, ReturnType extends TUnwrapped extends z$1.ZodDiscriminatedUnion ? ExtractZodUnionMember<TUnwrapped, Extract<TDiscriminatorKey, DiscriminatorKey<TUnwrapped>>, Extract<TDiscriminatorValue, DiscriminatorValue<TUnwrapped, Extract<TDiscriminatorKey, DiscriminatorKey<TUnwrapped>>>>> : undefined = TUnwrapped extends z$1.ZodDiscriminatedUnion ? ExtractZodUnionMember<TUnwrapped, Extract<TDiscriminatorKey, DiscriminatorKey<TUnwrapped>>, Extract<TDiscriminatorValue, DiscriminatorValue<TUnwrapped, Extract<TDiscriminatorKey, DiscriminatorKey<TUnwrapped>>>>> : undefined>({ schema, discriminator, }: SchemaAndDiscriminatorProps<TSchema, TDiscriminatorKey, TDiscriminatorValue>) => ReturnType;
654
659
 
655
660
  type Split<S extends string> = S extends `${infer Head}.${infer Tail}` ? [Head, ...Split<Tail>] : [S];
656
661
  type IsNumeric<S extends string> = S extends `${number}` ? true : false;
657
- type Unwrap<T> = T extends z$1.ZodOptional<infer U> ? Unwrap<U> : T extends z$1.ZodNullable<infer U> ? Unwrap<U> : T extends z$1.ZodDefault<infer U> ? Unwrap<U> : T;
662
+ type Unwrap<T> = T extends z$1.ZodOptional<infer U> ? Unwrap<U> : T extends z$1.ZodNullable<infer U> ? Unwrap<U> : T extends z$1.ZodDefault<infer U> ? Unwrap<U> : T extends z$1.ZodPipe<infer In, z$1.ZodType> ? Unwrap<In> : T;
658
663
  type NavigateZod<T, Path extends string[]> = Path extends [
659
664
  infer First extends string,
660
665
  ...infer Rest extends string[]
661
666
  ] ? Unwrap<T> extends z$1.ZodObject<infer Shape> ? First extends keyof Shape ? Rest extends [] ? Shape[First] : NavigateZod<Shape[First], Rest> : never : Unwrap<T> extends z$1.ZodArray<infer Element> ? IsNumeric<First> extends true ? Rest extends [] ? Element : NavigateZod<Element, Rest> : never : never : T;
662
667
  type ExtractZodByPath<Schema, Path extends string> = NavigateZod<Schema, Split<Path>>;
668
+ /**
669
+ * Extract field from a discriminated union variant.
670
+ * First extracts the variant using ExtractZodUnionMember, then navigates through it.
671
+ * @internal
672
+ */
673
+ type ExtractFromDiscriminatedUnion<TSchema extends z$1.ZodType, TName extends string, TDiscriminatorKey extends DiscriminatorKey<TSchema>, TDiscriminatorValue extends DiscriminatorValue<TSchema, TDiscriminatorKey>, TUnwrapped extends z$1.ZodType = UnwrapZodType<TSchema> extends z$1.ZodType ? UnwrapZodType<TSchema> : TSchema, TVariant = TUnwrapped extends z$1.ZodDiscriminatedUnion ? ExtractZodUnionMember<TUnwrapped, Extract<TDiscriminatorKey, DiscriminatorKey<TUnwrapped>>, Extract<TDiscriminatorValue, DiscriminatorValue<TUnwrapped, Extract<TDiscriminatorKey, DiscriminatorKey<TUnwrapped>>>>> : never> = TVariant extends z$1.ZodType ? ExtractZodByPath<TVariant, TName> : never;
674
+ /**
675
+ * Helper type to determine if field extraction should succeed.
676
+ * Returns true when:
677
+ * 1. For discriminated unions: discriminator is provided (trust the user)
678
+ * 2. For non-unions: the path resolves to a valid type (not never)
679
+ * @internal
680
+ */
681
+ type CanExtractField<TSchema extends z$1.ZodType, TName extends string, TDiscriminatorKey extends DiscriminatorKey<TSchema>> = IsDiscriminatedUnion<TSchema> extends true ? [TDiscriminatorKey] extends [never] ? false : true : [
682
+ ExtractZodByPath<TSchema, TName>
683
+ ] extends [never] ? false : true;
684
+ /**
685
+ * Conditional return type for extractFieldFromSchema.
686
+ * For discriminated unions: extracts variant first, then navigates.
687
+ * For non-unions: navigates directly.
688
+ * @internal
689
+ */
690
+ type ExtractFieldResult<TSchema extends z$1.ZodType, TName extends string, TDiscriminatorKey extends DiscriminatorKey<TSchema>, TDiscriminatorValue extends DiscriminatorValue<TSchema, TDiscriminatorKey> = DiscriminatorValue<TSchema, TDiscriminatorKey>> = CanExtractField<TSchema, TName, TDiscriminatorKey> extends true ? IsDiscriminatedUnion<TSchema> extends true ? [
691
+ ExtractFromDiscriminatedUnion<TSchema, TName, TDiscriminatorKey, TDiscriminatorValue>
692
+ ] extends [never] ? z$1.ZodType : ExtractFromDiscriminatedUnion<TSchema, TName, TDiscriminatorKey, TDiscriminatorValue> & z$1.ZodType : // For non-unions: navigate directly
693
+ ExtractZodByPath<TSchema, TName> & z$1.ZodType : (ExtractZodByPath<TSchema, TName> & z$1.ZodType) | undefined;
663
694
  declare function extractFieldFromSchema<TSchema extends z$1.ZodType, TDiscriminatorKey extends DiscriminatorKey<TSchema> = never, TDiscriminatorValue extends DiscriminatorValue<TSchema, TDiscriminatorKey> = never, TFilterType = unknown, TStrict extends boolean = true, TName extends string = string>(params: FieldSelectorProps<TSchema, TDiscriminatorKey, TDiscriminatorValue, TFilterType, TStrict> & {
664
695
  name: TName;
665
- }): (ExtractZodByPath<TSchema, TName> & z$1.ZodType) | undefined;
696
+ }): ExtractFieldResult<TSchema, TName, TDiscriminatorKey, TDiscriminatorValue>;
666
697
  /**
667
698
  * Extends a Zod field with a transformation while preserving its metadata.
668
699
  *
@@ -684,6 +715,115 @@ declare function extractFieldFromSchema<TSchema extends z$1.ZodType, TDiscrimina
684
715
  */
685
716
  declare function extendWithMeta<T extends z$1.ZodType, R extends z$1.ZodType>(field: T, transform: (f: T) => R): R;
686
717
 
718
+ /**
719
+ * Extracts the value of a specific meta key from a Zod field, recursively unwrapping
720
+ * optional, nullable, default, transform, and union layers.
721
+ *
722
+ * For `ZodObject` fields: if the object's own meta contains the target key, returns that
723
+ * value directly (stops recursion). If not, recurses into shape children and returns
724
+ * a nested record of meta values.
725
+ *
726
+ * @param field - The Zod field to extract meta from
727
+ * @param metaKey - The meta property key to extract
728
+ * @returns The meta value if found, undefined otherwise
729
+ *
730
+ * @example
731
+ * ```typescript
732
+ * const field = z.string().meta({ label: 'Name' });
733
+ * extractMeta(field, 'label'); // 'Name'
734
+ * ```
735
+ *
736
+ * @example
737
+ * ```typescript
738
+ * const field = z.string().meta({ label: 'Name' }).optional();
739
+ * extractMeta(field, 'label'); // 'Name' (unwraps optional)
740
+ * ```
741
+ *
742
+ * @see {@link getSchemaMeta} for extracting meta from entire schemas
743
+ * @since 0.3.0
744
+ */
745
+ declare function extractMeta(field: z.ZodType, metaKey: string): unknown;
746
+ /**
747
+ * Extracts the value of a specific meta key from all fields in a Zod schema.
748
+ *
749
+ * Returns a nested record where each key maps to the meta value for that field.
750
+ * Fields without the specified meta key are omitted.
751
+ *
752
+ * For `ZodObject` fields: if the object has the target meta key in its own meta,
753
+ * returns that value directly. Otherwise, recurses into shape children.
754
+ *
755
+ * Supports discriminated unions via the `discriminator` parameter.
756
+ *
757
+ * @param params - Schema and optional discriminator configuration
758
+ * @param metaKey - The meta property key to extract
759
+ * @returns Record mapping field names to their meta values
760
+ *
761
+ * To get typed meta keys with autocomplete, augment Zod's `GlobalMeta` interface:
762
+ *
763
+ * ```typescript
764
+ * // types/zod.ts
765
+ * import * as z from 'zod';
766
+ *
767
+ * declare module 'zod' {
768
+ * interface GlobalMeta {
769
+ * label: string; // static type for all schemas
770
+ * type: z.$output; // resolves to the schema's output type
771
+ * inputType: z.$input; // resolves to the schema's input type
772
+ * placeholder?: string;
773
+ * }
774
+ * }
775
+ * ```
776
+ *
777
+ * With `z.$output` / `z.$input`, Zod automatically types `.meta()` values
778
+ * based on each schema's inferred type:
779
+ *
780
+ * ```typescript
781
+ * z.string().meta({ type: 'hello' }) // ✅ type is string
782
+ * z.string().meta({ type: 42 }) // ❌ TypeScript error — expects string
783
+ * z.number().meta({ type: 42 }) // ✅ type is number
784
+ * ```
785
+ *
786
+ * @example
787
+ * ```typescript
788
+ * const schema = z.object({
789
+ * name: z.string().meta({ label: 'Name' }),
790
+ * age: z.number().meta({ label: 'Age' }),
791
+ * });
792
+ * getSchemaMeta({ schema }, 'label');
793
+ * // { name: 'Name', age: 'Age' }
794
+ * ```
795
+ *
796
+ * @see {@link extractMeta} for extracting meta from individual fields
797
+ * @since 0.3.0
798
+ */
799
+ declare function getSchemaMeta<TSchema extends z.ZodType, TDiscriminatorKey extends DiscriminatorKey<TSchema>, TDiscriminatorValue extends DiscriminatorValue<TSchema, TDiscriminatorKey>>(params: SchemaAndDiscriminatorProps<TSchema, TDiscriminatorKey, TDiscriminatorValue>, metaKey: string): Simplify<Partial<z.input<TSchema>>>;
800
+ /**
801
+ * Combines schema defaults and meta values into a single result.
802
+ * Meta values take precedence over defaults where both exist.
803
+ * For nested objects, performs a deep merge so that fields from both
804
+ * sources are preserved at every level.
805
+ *
806
+ * @param params - Schema and optional discriminator configuration
807
+ * @param metaKey - The meta property key to extract
808
+ * @returns Deep-merged record of defaults and meta values (meta wins on conflict)
809
+ *
810
+ * @example
811
+ * ```typescript
812
+ * const schema = z.object({
813
+ * name: z.string().meta({ label: 'Name' }).default('hello'),
814
+ * age: z.number().meta({ label: 'Age' }),
815
+ * bio: z.string().default(''),
816
+ * });
817
+ * getMergedSchemaDefaults({ schema }, 'label');
818
+ * // { name: 'Name', age: 'Age', bio: '' }
819
+ * ```
820
+ *
821
+ * @see {@link getSchemaDefaults} for extracting only defaults
822
+ * @see {@link getSchemaMeta} for extracting only meta
823
+ * @since 0.5.0
824
+ */
825
+ declare function getMergedSchemaDefaults<TSchema extends z.ZodType, TDiscriminatorKey extends DiscriminatorKey<TSchema>, TDiscriminatorValue extends DiscriminatorValue<TSchema, TDiscriminatorKey>>(params: SchemaAndDiscriminatorProps<TSchema, TDiscriminatorKey, TDiscriminatorValue>, metaKey: string): Simplify<Partial<z.input<TSchema>>>;
826
+
687
827
  /**
688
828
  * Type representing a Zod type that has an unwrap method
689
829
  */
@@ -710,7 +850,7 @@ type Unwrappable = {
710
850
  *
711
851
  * @since 0.1.0
712
852
  */
713
- declare function canUnwrap(field: z$1.ZodTypeAny): field is z$1.ZodTypeAny & Unwrappable;
853
+ declare function canUnwrap(field: z$1.ZodType | $ZodType): field is (z$1.ZodType | $ZodType) & Unwrappable;
714
854
  /**
715
855
  * Type guard that checks if a Zod field is a ZodPipe with a ZodType input.
716
856
  *
@@ -719,7 +859,7 @@ declare function canUnwrap(field: z$1.ZodTypeAny): field is z$1.ZodTypeAny & Unw
719
859
  * @param field - The Zod field to check
720
860
  * @returns True if field is a ZodPipe with a ZodType input
721
861
  */
722
- declare function isPipeWithZodInput(field: z$1.ZodTypeAny): field is z$1.ZodPipe<z$1.ZodType, z$1.ZodTypeAny>;
862
+ declare function isPipeWithZodInput(field: z$1.ZodType | $ZodType): field is z$1.ZodPipe<z$1.ZodType, z$1.ZodTypeAny>;
723
863
  /**
724
864
  * Attempts to strip nullish types from a union and return the single remaining type.
725
865
  *
@@ -816,7 +956,7 @@ declare function tryStripNullishOnly(field: z$1.ZodTypeAny): z$1.ZodType | false
816
956
  * @see {@link tryStripNullishOnly} for union nullish stripping logic
817
957
  * @since 0.1.0
818
958
  */
819
- declare const getPrimitiveType: <T extends z$1.ZodType>(field: T) => z$1.ZodTypeAny;
959
+ declare const getPrimitiveType: <T extends z$1.ZodType>(field: T) => z$1.ZodType;
820
960
  type StripZodDefault<T> = T extends z$1.ZodDefault<infer Inner> ? StripZodDefault<Inner> : T extends z$1.ZodOptional<infer Inner> ? z$1.ZodOptional<StripZodDefault<Inner>> : T extends z$1.ZodNullable<infer Inner> ? z$1.ZodNullable<StripZodDefault<Inner>> : T;
821
961
  /**
822
962
  * Removes default values from a Zod field while preserving other wrapper types.
@@ -948,7 +1088,7 @@ declare const requiresValidInput: <T extends z$1.ZodType>(field: T) => boolean;
948
1088
  *
949
1089
  * @since 0.4.0
950
1090
  */
951
- type ZodUnionCheck = $ZodCheckLessThanDef | $ZodCheckGreaterThanDef | $ZodCheckMultipleOfDef | $ZodCheckNumberFormatDef | $ZodCheckBigIntFormatDef | $ZodCheckMaxSizeDef | $ZodCheckMinSizeDef | $ZodCheckSizeEqualsDef | $ZodCheckMaxLengthDef | $ZodCheckMinLengthDef | $ZodCheckLengthEqualsDef | $ZodCheckStringFormatDef | $ZodCheckRegexDef | $ZodCheckLowerCaseDef | $ZodCheckUpperCaseDef | $ZodCheckIncludesDef | $ZodCheckStartsWithDef | $ZodCheckEndsWithDef | $ZodCheckPropertyDef | $ZodCheckMimeTypeDef | $ZodCheckOverwriteDef;
1091
+ type ZodUnionCheck = $ZodCheckLessThanDef | $ZodCheckGreaterThanDef | $ZodCheckMultipleOfDef | $ZodCheckNumberFormatDef | $ZodCheckMaxSizeDef | $ZodCheckMinSizeDef | $ZodCheckSizeEqualsDef | $ZodCheckMaxLengthDef | $ZodCheckMinLengthDef | $ZodCheckLengthEqualsDef | $ZodCheckStringFormatDef | $ZodCheckRegexDef | $ZodCheckIncludesDef | $ZodCheckStartsWithDef | $ZodCheckEndsWithDef | $ZodCheckMimeTypeDef | $ZodCheckOverwriteDef;
952
1092
  /**
953
1093
  * Extracts all validation check definitions from a Zod schema field.
954
1094
  *
@@ -1024,6 +1164,7 @@ type ZodUnionCheck = $ZodCheckLessThanDef | $ZodCheckGreaterThanDef | $ZodCheckM
1024
1164
  * @see {@link ZodUnionCheck} for all supported check types
1025
1165
  * @since 0.4.0
1026
1166
  */
1027
- declare function getFieldChecks<T extends z$1.ZodTypeAny>(field: T): Array<ZodUnionCheck>;
1167
+ declare function getFieldChecks<T extends z$1.ZodType | $ZodType>(field: T): Array<ZodUnionCheck>;
1168
+ declare function extractCheck(check: z$1.core.$ZodCheck<never>): ZodUnionCheck[];
1028
1169
 
1029
- export { type CommonFields, type DiscriminatedInput, type DiscriminatorKey, type DiscriminatorProps, type DiscriminatorValue, type ExtractZodByPath, type FieldSelectorProps, type FileList, type IsDiscriminatedUnion, type NameAndDiscriminatorProps, type NameProps, type PathImpl, type PathInternal, type Paths, type SchemaAndDiscriminatorProps, type SchemaProps, type Simplify, type UnwrapZodType, type ValidPaths, type ZodUnionCheck, canUnwrap, extendWithMeta, extractDefaultValue, extractDiscriminatedSchema, extractFieldFromSchema, getFieldChecks, getPrimitiveType, getSchemaDefaults, isPipeWithZodInput, removeDefault, requiresValidInput, tryStripNullishOnly };
1170
+ export { type CommonFields, type DiscriminatedInput, type DiscriminatorKey, type DiscriminatorProps, type DiscriminatorValue, type ExtractZodByPath, type ExtractZodUnionMember, type FieldSelectorProps, type FileList, type IsDiscriminatedUnion, type NameAndDiscriminatorProps, type NameProps, type PathImpl, type PathInternal, type Paths, type SchemaAndDiscriminatorProps, type SchemaProps, type Simplify, type UnwrapZodType, type ValidPaths, type ZodUnionCheck, canUnwrap, extendWithMeta, extractCheck, extractDefaultValue, extractDiscriminatedSchema, extractFieldFromSchema, extractMeta, getFieldChecks, getMergedSchemaDefaults, getPrimitiveType, getSchemaDefaults, getSchemaMeta, getShapeEntries, isPipeWithZodInput, removeDefault, requiresValidInput, tryStripNullishOnly };
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var z3 = require('zod');
4
+ var core = require('zod/v4/core');
4
5
 
5
6
  function _interopNamespace(e) {
6
7
  if (e && e.__esModule) return e;
@@ -110,9 +111,65 @@ var requiresValidInput = (field) => {
110
111
  return !undefinedResult && !nullResult && !emptyStringResult && !emptyArrayResult;
111
112
  };
112
113
  function getFieldChecks(field) {
113
- var _a;
114
+ if (!(field instanceof z3.z.ZodType)) return [];
114
115
  const primitiveType = getPrimitiveType(field);
115
- return ((_a = primitiveType.def.checks) == null ? void 0 : _a.map((check) => check._zod.def)) || [];
116
+ if (primitiveType instanceof z3.z.ZodUnion) {
117
+ const allChecks2 = [];
118
+ for (const option of primitiveType.options) {
119
+ const optionChecks = getFieldChecks(option);
120
+ allChecks2.push(...optionChecks);
121
+ }
122
+ return allChecks2;
123
+ }
124
+ const allChecks = [];
125
+ if (primitiveType instanceof z3.ZodStringFormat) {
126
+ const formatCheck = primitiveType.def;
127
+ allChecks.push(formatCheck);
128
+ }
129
+ if (primitiveType.def.checks) {
130
+ for (const check of primitiveType.def.checks) {
131
+ allChecks.push(...extractCheck(check));
132
+ }
133
+ }
134
+ return allChecks;
135
+ }
136
+ function extractCheck(check) {
137
+ if (check instanceof core.$ZodCheckLessThan) {
138
+ return [check._zod.def];
139
+ } else if (check instanceof core.$ZodCheckGreaterThan) {
140
+ return [check._zod.def];
141
+ } else if (check instanceof core.$ZodCheckMultipleOf) {
142
+ return [check._zod.def];
143
+ } else if (check instanceof core.$ZodCheckNumberFormat) {
144
+ return [check._zod.def];
145
+ } else if (check instanceof core.$ZodCheckMaxSize) {
146
+ return [check._zod.def];
147
+ } else if (check instanceof core.$ZodCheckMinSize) {
148
+ return [check._zod.def];
149
+ } else if (check instanceof core.$ZodCheckSizeEquals) {
150
+ return [check._zod.def];
151
+ } else if (check instanceof core.$ZodCheckMaxLength) {
152
+ return [check._zod.def];
153
+ } else if (check instanceof core.$ZodCheckMinLength) {
154
+ return [check._zod.def];
155
+ } else if (check instanceof core.$ZodCheckLengthEquals) {
156
+ return [check._zod.def];
157
+ } else if (check instanceof core.$ZodCheckRegex) {
158
+ return [check._zod.def];
159
+ } else if (check instanceof core.$ZodCheckStringFormat) {
160
+ return [check._zod.def];
161
+ } else if (check instanceof core.$ZodCheckOverwrite) {
162
+ return [check._zod.def];
163
+ } else if (check instanceof core.$ZodCheckMimeType) {
164
+ return [check._zod.def];
165
+ } else if (check instanceof core.$ZodCheckIncludes) {
166
+ return [check._zod.def];
167
+ } else if (check instanceof core.$ZodCheckStartsWith) {
168
+ return [check._zod.def];
169
+ } else if (check instanceof core.$ZodCheckEndsWith) {
170
+ return [check._zod.def];
171
+ }
172
+ return [];
116
173
  }
117
174
 
118
175
  // src/discriminatedSchema.ts
@@ -216,10 +273,12 @@ function extractFieldFromSchema(params) {
216
273
  } else if (newParams.schema instanceof z3.z.ZodObject) {
217
274
  currentSchema = newParams.schema;
218
275
  }
219
- if (!currentSchema) return void 0;
276
+ if (!currentSchema)
277
+ return void 0;
220
278
  const segments = String(newParams.name).split(".");
221
279
  for (const segment of segments) {
222
- if (!currentSchema) return void 0;
280
+ if (!currentSchema)
281
+ return void 0;
223
282
  const unwrapped = getPrimitiveType(currentSchema);
224
283
  if (unwrapped instanceof z3.z.ZodObject) {
225
284
  currentSchema = getShapeField2(unwrapped, segment);
@@ -243,15 +302,109 @@ function extendWithMeta(field, transform) {
243
302
  }
244
303
  return transformedField.meta(__spreadValues({}, meta));
245
304
  }
305
+ function extractMeta(field, metaKey) {
306
+ const meta = field.meta();
307
+ if (meta && metaKey in meta) {
308
+ return meta[metaKey];
309
+ }
310
+ if (field instanceof z3__namespace.ZodObject) {
311
+ const nested = {};
312
+ let hasAny = false;
313
+ for (const [key, nestedField] of getShapeEntries(field)) {
314
+ if (!nestedField) continue;
315
+ const value = extractMeta(nestedField, metaKey);
316
+ if (value !== void 0) {
317
+ nested[key] = value;
318
+ hasAny = true;
319
+ }
320
+ }
321
+ if (hasAny) {
322
+ return nested;
323
+ }
324
+ return void 0;
325
+ }
326
+ if (field instanceof z3__namespace.ZodArray) {
327
+ const elementMeta = extractMeta(field.unwrap(), metaKey);
328
+ if (elementMeta !== void 0) {
329
+ return [elementMeta];
330
+ }
331
+ return void 0;
332
+ }
333
+ if (canUnwrap(field)) {
334
+ return extractMeta(field.unwrap(), metaKey);
335
+ }
336
+ if (field instanceof z3__namespace.ZodUnion) {
337
+ const unwrapped = tryStripNullishOnly(field);
338
+ if (unwrapped !== false) {
339
+ return extractMeta(unwrapped, metaKey);
340
+ }
341
+ return void 0;
342
+ }
343
+ if (isPipeWithZodInput(field)) {
344
+ return extractMeta(field.def.in, metaKey);
345
+ }
346
+ return void 0;
347
+ }
348
+ function getSchemaMeta(params, metaKey) {
349
+ const primitiveSchemaParams = __spreadProps(__spreadValues({}, params), {
350
+ schema: getPrimitiveType(params.schema)
351
+ });
352
+ let targetSchema;
353
+ if (primitiveSchemaParams.schema instanceof z3__namespace.ZodDiscriminatedUnion) {
354
+ targetSchema = extractDiscriminatedSchema(primitiveSchemaParams);
355
+ } else if (primitiveSchemaParams.schema instanceof z3__namespace.ZodObject) {
356
+ targetSchema = primitiveSchemaParams.schema;
357
+ }
358
+ const result = {};
359
+ if (targetSchema) {
360
+ for (const [key, field] of getShapeEntries(targetSchema)) {
361
+ if (!field) continue;
362
+ const value = extractMeta(field, metaKey);
363
+ if (value !== void 0) {
364
+ result[key] = value;
365
+ }
366
+ }
367
+ }
368
+ return result;
369
+ }
370
+ function isPlainObject(value) {
371
+ return typeof value === "object" && value !== null && !Array.isArray(value);
372
+ }
373
+ function deepMerge(target, source) {
374
+ const result = __spreadValues({}, target);
375
+ for (const key of Object.keys(source)) {
376
+ const targetVal = target[key];
377
+ const sourceVal = source[key];
378
+ if (isPlainObject(targetVal) && isPlainObject(sourceVal)) {
379
+ result[key] = deepMerge(targetVal, sourceVal);
380
+ } else {
381
+ result[key] = sourceVal;
382
+ }
383
+ }
384
+ return result;
385
+ }
386
+ function getMergedSchemaDefaults(params, metaKey) {
387
+ const defaults = getSchemaDefaults(params);
388
+ const meta = getSchemaMeta(params, metaKey);
389
+ return deepMerge(
390
+ defaults,
391
+ meta
392
+ );
393
+ }
246
394
 
247
395
  exports.canUnwrap = canUnwrap;
248
396
  exports.extendWithMeta = extendWithMeta;
397
+ exports.extractCheck = extractCheck;
249
398
  exports.extractDefaultValue = extractDefaultValue;
250
399
  exports.extractDiscriminatedSchema = extractDiscriminatedSchema;
251
400
  exports.extractFieldFromSchema = extractFieldFromSchema;
401
+ exports.extractMeta = extractMeta;
252
402
  exports.getFieldChecks = getFieldChecks;
403
+ exports.getMergedSchemaDefaults = getMergedSchemaDefaults;
253
404
  exports.getPrimitiveType = getPrimitiveType;
254
405
  exports.getSchemaDefaults = getSchemaDefaults;
406
+ exports.getSchemaMeta = getSchemaMeta;
407
+ exports.getShapeEntries = getShapeEntries;
255
408
  exports.isPipeWithZodInput = isPipeWithZodInput;
256
409
  exports.removeDefault = removeDefault;
257
410
  exports.requiresValidInput = requiresValidInput;