@zod-utils/core 4.0.0 → 5.0.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/README.md +1082 -341
- package/dist/index.d.mts +10 -8
- package/dist/index.d.ts +10 -8
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -88,15 +88,17 @@ type IsTuple<T extends ReadonlyArray<unknown>> = number extends T['length'] ? fa
|
|
|
88
88
|
type TupleKeys<T extends ReadonlyArray<unknown>> = Exclude<keyof T, keyof unknown[]>;
|
|
89
89
|
type IsEqual<T1, T2> = T1 extends T2 ? (<G>() => G extends T1 ? 1 : 2) extends <G>() => G extends T2 ? 1 : 2 ? true : false : false;
|
|
90
90
|
type AnyIsEqual<T1, T2> = T1 extends T2 ? IsEqual<T1, T2> extends true ? true : never : never;
|
|
91
|
-
type
|
|
91
|
+
type HasMatch<V, TFilterType> = V extends TFilterType ? true : false;
|
|
92
|
+
type IsNullable<V> = null extends V ? true : undefined extends V ? true : false;
|
|
93
|
+
type CheckFilter<V, TFilterType, TStrict extends boolean> = TStrict extends true ? [V] extends [TFilterType] ? true : false : true extends HasMatch<V, TFilterType> ? true : false;
|
|
92
94
|
type ArrayPaths = '${number}' | `${number}`;
|
|
93
|
-
type PathImpl<K extends string | number, V, TraversedTypes,
|
|
94
|
-
type PathInternal<T, TraversedTypes = T,
|
|
95
|
-
[K in TupleKeys<T>]-?: PathImpl<K & string, T[K], TraversedTypes,
|
|
96
|
-
}[TupleKeys<T>] : PathImpl<ArrayKey, V, TraversedTypes,
|
|
97
|
-
[K in keyof T]-?: PathImpl<K & string, T[K], TraversedTypes,
|
|
95
|
+
type PathImpl<K extends string | number, V, TraversedTypes, TFilterType = unknown, TStrict extends boolean = true> = [V] extends [Primitive | BrowserNativeObject] ? CheckFilter<V, TFilterType, TStrict> extends true ? K extends number ? ArrayPaths : `${K}` : never : true extends AnyIsEqual<TraversedTypes, V> ? CheckFilter<V, TFilterType, TStrict> extends true ? `${K}` : never : K extends number ? (CheckFilter<V, TFilterType, TStrict> extends true ? ArrayPaths : never) | `${ArrayPaths}.${PathInternal<V, TraversedTypes | V, TFilterType, TStrict>}` : (CheckFilter<V, TFilterType, TStrict> extends true ? `${K}` : never) | (unknown extends TFilterType ? `${K}.${PathInternal<V, TraversedTypes | V, TFilterType, TStrict>}` : IsNullable<V> extends true ? TStrict extends true ? never : `${K}.${PathInternal<V, TraversedTypes | V, TFilterType, TStrict>}` : `${K}.${PathInternal<V, TraversedTypes | V, TFilterType, TStrict>}`);
|
|
96
|
+
type PathInternal<T, TraversedTypes = T, TFilterType = unknown, TStrict extends boolean = true> = T extends ReadonlyArray<infer V> ? IsTuple<T> extends true ? {
|
|
97
|
+
[K in TupleKeys<T>]-?: PathImpl<K & string, T[K], TraversedTypes, TFilterType, TStrict>;
|
|
98
|
+
}[TupleKeys<T>] : PathImpl<ArrayKey, V, TraversedTypes, TFilterType, TStrict> : {
|
|
99
|
+
[K in keyof T]-?: PathImpl<K & string, T[K], TraversedTypes, TFilterType, TStrict>;
|
|
98
100
|
}[keyof T];
|
|
99
|
-
type Paths<T,
|
|
101
|
+
type Paths<T, TFilterType = unknown, TStrict extends boolean = true> = PathInternal<T, T, TFilterType, TStrict>;
|
|
100
102
|
/**
|
|
101
103
|
* Extracts fields common to all variants in a union type.
|
|
102
104
|
*
|
|
@@ -868,4 +870,4 @@ type ZodUnionCheck = $ZodCheckLessThanDef | $ZodCheckGreaterThanDef | $ZodCheckM
|
|
|
868
870
|
*/
|
|
869
871
|
declare function getFieldChecks<T extends z$1.ZodTypeAny>(field: T): Array<ZodUnionCheck>;
|
|
870
872
|
|
|
871
|
-
export { type CommonFields, type DiscriminatedInput, type Discriminator, type DiscriminatorKey, type DiscriminatorValue, type ExtractZodByPath, type FieldSelector, type InnerFieldSelector, type IsDiscriminatedUnion, type PathImpl, type PathInternal, type Paths, type Simplify, type UnwrapZodType, type ValidPaths, type ZodUnionCheck, canUnwrap, extendWithMeta, extractDefaultValue, extractDiscriminatedSchema, extractFieldFromSchema, getFieldChecks, getPrimitiveType, getSchemaDefaults, removeDefault, requiresValidInput, toFieldSelector, tryStripNullishOnly };
|
|
873
|
+
export { type CommonFields, type DiscriminatedInput, type Discriminator, type DiscriminatorKey, type DiscriminatorValue, type ExtractZodByPath, type FieldSelector, type FileList, type InnerFieldSelector, type IsDiscriminatedUnion, type PathImpl, type PathInternal, type Paths, type Simplify, type UnwrapZodType, type ValidPaths, type ZodUnionCheck, canUnwrap, extendWithMeta, extractDefaultValue, extractDiscriminatedSchema, extractFieldFromSchema, getFieldChecks, getPrimitiveType, getSchemaDefaults, removeDefault, requiresValidInput, toFieldSelector, tryStripNullishOnly };
|
package/dist/index.d.ts
CHANGED
|
@@ -88,15 +88,17 @@ type IsTuple<T extends ReadonlyArray<unknown>> = number extends T['length'] ? fa
|
|
|
88
88
|
type TupleKeys<T extends ReadonlyArray<unknown>> = Exclude<keyof T, keyof unknown[]>;
|
|
89
89
|
type IsEqual<T1, T2> = T1 extends T2 ? (<G>() => G extends T1 ? 1 : 2) extends <G>() => G extends T2 ? 1 : 2 ? true : false : false;
|
|
90
90
|
type AnyIsEqual<T1, T2> = T1 extends T2 ? IsEqual<T1, T2> extends true ? true : never : never;
|
|
91
|
-
type
|
|
91
|
+
type HasMatch<V, TFilterType> = V extends TFilterType ? true : false;
|
|
92
|
+
type IsNullable<V> = null extends V ? true : undefined extends V ? true : false;
|
|
93
|
+
type CheckFilter<V, TFilterType, TStrict extends boolean> = TStrict extends true ? [V] extends [TFilterType] ? true : false : true extends HasMatch<V, TFilterType> ? true : false;
|
|
92
94
|
type ArrayPaths = '${number}' | `${number}`;
|
|
93
|
-
type PathImpl<K extends string | number, V, TraversedTypes,
|
|
94
|
-
type PathInternal<T, TraversedTypes = T,
|
|
95
|
-
[K in TupleKeys<T>]-?: PathImpl<K & string, T[K], TraversedTypes,
|
|
96
|
-
}[TupleKeys<T>] : PathImpl<ArrayKey, V, TraversedTypes,
|
|
97
|
-
[K in keyof T]-?: PathImpl<K & string, T[K], TraversedTypes,
|
|
95
|
+
type PathImpl<K extends string | number, V, TraversedTypes, TFilterType = unknown, TStrict extends boolean = true> = [V] extends [Primitive | BrowserNativeObject] ? CheckFilter<V, TFilterType, TStrict> extends true ? K extends number ? ArrayPaths : `${K}` : never : true extends AnyIsEqual<TraversedTypes, V> ? CheckFilter<V, TFilterType, TStrict> extends true ? `${K}` : never : K extends number ? (CheckFilter<V, TFilterType, TStrict> extends true ? ArrayPaths : never) | `${ArrayPaths}.${PathInternal<V, TraversedTypes | V, TFilterType, TStrict>}` : (CheckFilter<V, TFilterType, TStrict> extends true ? `${K}` : never) | (unknown extends TFilterType ? `${K}.${PathInternal<V, TraversedTypes | V, TFilterType, TStrict>}` : IsNullable<V> extends true ? TStrict extends true ? never : `${K}.${PathInternal<V, TraversedTypes | V, TFilterType, TStrict>}` : `${K}.${PathInternal<V, TraversedTypes | V, TFilterType, TStrict>}`);
|
|
96
|
+
type PathInternal<T, TraversedTypes = T, TFilterType = unknown, TStrict extends boolean = true> = T extends ReadonlyArray<infer V> ? IsTuple<T> extends true ? {
|
|
97
|
+
[K in TupleKeys<T>]-?: PathImpl<K & string, T[K], TraversedTypes, TFilterType, TStrict>;
|
|
98
|
+
}[TupleKeys<T>] : PathImpl<ArrayKey, V, TraversedTypes, TFilterType, TStrict> : {
|
|
99
|
+
[K in keyof T]-?: PathImpl<K & string, T[K], TraversedTypes, TFilterType, TStrict>;
|
|
98
100
|
}[keyof T];
|
|
99
|
-
type Paths<T,
|
|
101
|
+
type Paths<T, TFilterType = unknown, TStrict extends boolean = true> = PathInternal<T, T, TFilterType, TStrict>;
|
|
100
102
|
/**
|
|
101
103
|
* Extracts fields common to all variants in a union type.
|
|
102
104
|
*
|
|
@@ -868,4 +870,4 @@ type ZodUnionCheck = $ZodCheckLessThanDef | $ZodCheckGreaterThanDef | $ZodCheckM
|
|
|
868
870
|
*/
|
|
869
871
|
declare function getFieldChecks<T extends z$1.ZodTypeAny>(field: T): Array<ZodUnionCheck>;
|
|
870
872
|
|
|
871
|
-
export { type CommonFields, type DiscriminatedInput, type Discriminator, type DiscriminatorKey, type DiscriminatorValue, type ExtractZodByPath, type FieldSelector, type InnerFieldSelector, type IsDiscriminatedUnion, type PathImpl, type PathInternal, type Paths, type Simplify, type UnwrapZodType, type ValidPaths, type ZodUnionCheck, canUnwrap, extendWithMeta, extractDefaultValue, extractDiscriminatedSchema, extractFieldFromSchema, getFieldChecks, getPrimitiveType, getSchemaDefaults, removeDefault, requiresValidInput, toFieldSelector, tryStripNullishOnly };
|
|
873
|
+
export { type CommonFields, type DiscriminatedInput, type Discriminator, type DiscriminatorKey, type DiscriminatorValue, type ExtractZodByPath, type FieldSelector, type FileList, type InnerFieldSelector, type IsDiscriminatedUnion, type PathImpl, type PathInternal, type Paths, type Simplify, type UnwrapZodType, type ValidPaths, type ZodUnionCheck, canUnwrap, extendWithMeta, extractDefaultValue, extractDiscriminatedSchema, extractFieldFromSchema, getFieldChecks, getPrimitiveType, getSchemaDefaults, removeDefault, requiresValidInput, toFieldSelector, tryStripNullishOnly };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zod-utils/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Pure TypeScript utilities for Zod schema manipulation and default extraction",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"lint:typescript": "tsc --project tsconfig.json",
|
|
25
25
|
"lint": "biome check . && npm run lint:typescript",
|
|
26
26
|
"lint:fix": "biome check --write .",
|
|
27
|
-
"test": "vitest run",
|
|
27
|
+
"test": "npm run lint:typescript && vitest run",
|
|
28
28
|
"test:watch": "vitest",
|
|
29
29
|
"test:coverage": "vitest run --coverage",
|
|
30
30
|
"bench": "vitest bench --run",
|