zodselect 1.0.2 → 1.0.3

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.
@@ -1,5 +1,15 @@
1
1
  import { core, z, ZodAny, ZodArray, ZodBoolean, ZodDate, ZodLiteral, ZodNever, ZodNullable, ZodNumber, ZodObject, ZodOptional, ZodRawShape, ZodString, ZodType, ZodUnion, ZodUnknown } from 'zod/v4';
2
2
  import { IsAny, IsJsonType } from './types.js';
3
+ type ApplyOptionalNullable<T, U extends ZodType> = IsAny<T, U, undefined extends T ? null extends T ? ZodOptional<ZodNullable<U>> : ZodOptional<U> : null extends T ? ZodNullable<U> : U>;
4
+ type DepthLimit = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
5
+ type InternalZodify<T, TDepth extends number = 0> = TDepth extends 9 ? ZodType : IsAny<T, ZodAny, T extends string ? string extends T ? ZodString : ZodLiteral<T> : T extends number ? ZodNumber : T extends boolean ? ZodBoolean : T extends Date ? ZodDate : unknown extends T ? ZodUnknown : T extends Array<infer U> ? ZodArray<Zodify<U, NextDepth<TDepth>>> : T extends object ? IsJsonType<T, true, ZodObject<{
6
+ [K in keyof T]-?: Zodify<T[K], NextDepth<TDepth>>;
7
+ }, core.$strict>, ZodType<T>> : never>;
8
+ type IsTuple<T, TTrue = true, TFalse = false> = T extends [infer TFirst, infer TSecond, ...infer TRest] ? TTrue : TFalse;
9
+ type LastOf<T> = UnionToIntersection<T extends any ? () => T : never> extends () => (infer R) ? R : never;
10
+ type NextDepth<T extends number> = T extends 0 ? 1 : T extends 1 ? 2 : T extends 2 ? 3 : T extends 3 ? 4 : T extends 4 ? 5 : T extends 5 ? 6 : T extends 6 ? 7 : T extends 7 ? 8 : T extends 8 ? 9 : 9;
11
+ type Push<T extends any[], V> = [...T, V];
12
+ type ReapplyOptionalNullable<T, U extends z.ZodType> = T extends ZodOptional<ZodNullable<ZodType>> ? ZodOptional<ZodNullable<U>> : T extends ZodNullable<ZodOptional<ZodType>> ? ZodNullable<ZodOptional<U>> : T extends ZodOptional<ZodType> ? ZodOptional<U> : T extends ZodNullable<ZodType> ? ZodNullable<U> : U;
3
13
  export type RefinedSchema<T extends ZodType<object> | ZodUnion, TShape extends RefineSchema<T>> = T extends ZodUnion ? RefinedUnionSchema<T, TShape> : T extends ZodType<object> ? RefinedTypeSchema<z.infer<T>, TShape> : never;
4
14
  export type RefinedTypeSchema<T extends object, TShape, TDepth extends number = 0> = TDepth extends keyof DepthLimit ? ZodObject<{
5
15
  [K in keyof T & keyof TShape]: TShape[K] extends (schema: infer S) => ZodType ? ReturnType<TShape[K]> : TShape[K] extends ZodType ? TShape[K] : TShape[K] extends boolean ? Zodify<T[K]> : TShape[K] extends object ? Exclude<T[K], null | undefined> extends Array<infer U> ? U extends object ? ApplyOptionalNullable<T[K], z.ZodArray<RefinedTypeSchema<U, TShape[K], NextDepth<TDepth>>>> : Zodify<T[K]> : Exclude<T[K], null | undefined> extends object ? ApplyOptionalNullable<T[K], RefinedTypeSchema<Exclude<T[K], null | undefined>, TShape[K], NextDepth<TDepth>>> : ZodNever : ZodNever;
@@ -10,27 +20,17 @@ export type RefinedUnionSchema<T extends ZodUnion, TShape> = ZodUnion<T['options
10
20
  [K in keyof Rest]: Rest[K] extends ZodType ? z.infer<Rest[K]> extends object ? RefinedTypeSchema<z.infer<Rest[K]>, TShape> : Extract<Rest[K], ZodType> : Extract<Rest[K], ZodType>;
11
21
  }
12
22
  ] : never : never>;
23
+ type Refinement<T extends ZodType> = ((schema: T) => ZodType) | boolean | ZodType;
13
24
  export type RefineObject<T extends object> = {
14
25
  [K in keyof T]?: RefineType<T[K]>;
15
26
  };
16
27
  export type RefineSchema<T extends ZodType<object> | ZodUnion> = T extends ZodUnion ? RefineZodUnion<T> : T extends ZodType<object> ? RefineObject<z.infer<T>> : never;
28
+ type RefineType<T> = IsTuple<TuplifyUnion<Exclude<T, null | undefined>>, Refinement<Zodify<T>>, Exclude<T, null | undefined> extends string ? Refinement<ApplyOptionalNullable<T, ZodString>> : Exclude<T, null | undefined> extends number ? Refinement<ApplyOptionalNullable<T, ZodNumber>> : Exclude<T, null | undefined> extends boolean ? Refinement<ApplyOptionalNullable<T, ZodBoolean>> : Exclude<T, null | undefined> extends Date ? Refinement<ApplyOptionalNullable<T, ZodDate>> : Exclude<T, null | undefined> extends Array<infer U> ? Exclude<U, null | undefined> extends object ? Refinement<Zodify<T>> | RefineObject<Extract<U, object>> : Refinement<Zodify<T>> : Exclude<T, null | undefined> extends object ? IsJsonType<Exclude<T, null | undefined>, false, Refinement<Zodify<T>> | RefineObject<Extract<T, object>>, Refinement<Zodify<T>>> : unknown extends Exclude<T, null | undefined> ? Refinement<Zodify<T>> : never>;
17
29
  export type RefineZodUnion<T extends ZodUnion> = {
18
30
  [K in keyof UnionToIntersection<T['options'][number] extends ZodObject<infer Shape extends ZodRawShape> ? Shape : object>]?: boolean;
19
31
  };
20
32
  export type TuplifyUnion<T, TDepth extends number = 0, L = LastOf<T>, N = [T] extends [never] ? true : false> = TDepth extends 9 ? [] : true extends N ? [] : Push<TuplifyUnion<Exclude<T, L>, NextDepth<TDepth>>, InternalZodify<L>>;
21
33
  export type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
22
34
  export type Zodify<T, TDepth extends number = 0> = ApplyOptionalNullable<T, IsTuple<TuplifyUnion<Exclude<T, null | undefined>, TDepth>, ZodUnion<TuplifyUnion<Exclude<T, null | undefined>, TDepth>>, InternalZodify<Exclude<T, null | undefined>, TDepth>>>;
23
- type ApplyOptionalNullable<T, U extends ZodType> = IsAny<T, U, undefined extends T ? null extends T ? ZodOptional<ZodNullable<U>> : ZodOptional<U> : null extends T ? ZodNullable<U> : U>;
24
- type DepthLimit = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
25
- type InternalZodify<T, TDepth extends number = 0> = TDepth extends 9 ? ZodType : IsAny<T, ZodAny, T extends string ? string extends T ? ZodString : ZodLiteral<T> : T extends number ? ZodNumber : T extends boolean ? ZodBoolean : T extends Date ? ZodDate : unknown extends T ? ZodUnknown : T extends Array<infer U> ? ZodArray<Zodify<U, NextDepth<TDepth>>> : T extends object ? IsJsonType<T, true, ZodObject<{
26
- [K in keyof T]-?: Zodify<T[K], NextDepth<TDepth>>;
27
- }, core.$strict>, ZodType<T>> : never>;
28
- type IsTuple<T, TTrue = true, TFalse = false> = T extends [infer TFirst, infer TSecond, ...infer TRest] ? TTrue : TFalse;
29
- type LastOf<T> = UnionToIntersection<T extends any ? () => T : never> extends () => (infer R) ? R : never;
30
- type NextDepth<T extends number> = T extends 0 ? 1 : T extends 1 ? 2 : T extends 2 ? 3 : T extends 3 ? 4 : T extends 4 ? 5 : T extends 5 ? 6 : T extends 6 ? 7 : T extends 7 ? 8 : T extends 8 ? 9 : 9;
31
- type Push<T extends any[], V> = [...T, V];
32
- type ReapplyOptionalNullable<T, U extends z.ZodType> = T extends ZodOptional<ZodNullable<ZodType>> ? ZodOptional<ZodNullable<U>> : T extends ZodNullable<ZodOptional<ZodType>> ? ZodNullable<ZodOptional<U>> : T extends ZodOptional<ZodType> ? ZodOptional<U> : T extends ZodNullable<ZodType> ? ZodNullable<U> : U;
33
- type Refinement<T extends ZodType> = ((schema: T) => ZodType) | boolean | ZodType;
34
- type RefineType<T> = IsTuple<TuplifyUnion<Exclude<T, null | undefined>>, Refinement<Zodify<T>>, Exclude<T, null | undefined> extends string ? Refinement<ApplyOptionalNullable<T, ZodString>> : Exclude<T, null | undefined> extends number ? Refinement<ApplyOptionalNullable<T, ZodNumber>> : Exclude<T, null | undefined> extends boolean ? Refinement<ApplyOptionalNullable<T, ZodBoolean>> : Exclude<T, null | undefined> extends Date ? Refinement<ApplyOptionalNullable<T, ZodDate>> : Exclude<T, null | undefined> extends Array<infer U> ? Exclude<U, null | undefined> extends object ? Refinement<Zodify<T>> | RefineObject<Extract<U, object>> : Refinement<Zodify<T>> : Exclude<T, null | undefined> extends object ? IsJsonType<Exclude<T, null | undefined>, false, Refinement<Zodify<T>> | RefineObject<Extract<T, object>>, Refinement<Zodify<T>>> : unknown extends Exclude<T, null | undefined> ? Refinement<Zodify<T>> : never>;
35
35
  export declare function refineSchema<T extends ZodType<object> | ZodUnion, TShape extends RefineSchema<T>>(schema: T, shape: TShape): RefinedSchema<T, TShape>;
36
36
  export {};
package/dist/select.d.ts CHANGED
@@ -2,11 +2,11 @@ import { z, ZodType, ZodUnion } from 'zod/v4';
2
2
  import { RefinedTypeSchema, RefinedUnionSchema, RefineObject, RefineZodUnion } from './refine-schema.js';
3
3
  import { DeepMergeAll, IsEqual } from './types.js';
4
4
  export type InferMergedType<T extends ZodType<object> | ZodUnion, U extends readonly ZodSelect<T>[] | undefined | ZodSelect<T>> = U extends undefined ? z.infer<T> : U extends readonly ZodSelect<T>[] ? DeepMergeAll<InferTuple<T, U>> : U extends ZodSelect<T> ? InferType<T, U> : never;
5
+ type InferTuple<T extends ZodType<object> | ZodUnion, U extends readonly ZodSelect<T>[]> = {
6
+ [K in keyof U]: InferType<T, U[K]>;
7
+ };
5
8
  export type InferType<T extends ZodType<object> | ZodUnion, U extends ZodSelect<T>> = U extends ZodType<object> ? z.infer<U> : U extends ZodUnion ? z.infer<U> : T extends ZodUnion ? (U extends RefineZodUnion<T> ? z.infer<RefinedUnionSchema<T, U>> : z.infer<T>) : T extends ZodType<object> ? (U extends RefineObject<z.infer<T>> ? z.infer<RefinedTypeSchema<z.infer<T>, U>> : z.infer<T>) : z.infer<T>;
6
9
  export type MergeSelect<T extends ZodType<object> | ZodUnion, TSelect1 extends ZodSelect<T>, TSelect2 extends MultiSelect<T>> = TSelect2 extends undefined ? [TSelect1, T] : IsEqual<TSelect2, T, TSelect1, TSelect2 extends [ZodSelect<T>, ...ZodSelect<T>[]] ? [TSelect1, ...TSelect2] : [TSelect1, TSelect2]>;
7
10
  export type MultiSelect<T extends ZodType<object> | ZodUnion> = [ZodSelect<T>, ...ZodSelect<T>[]] | undefined | ZodSelect<T>;
8
11
  export type ZodSelect<T extends ZodType<object> | ZodUnion> = (T extends ZodUnion ? (RefineZodUnion<T> | ZodUnion) : T extends ZodType<object> ? (RefineObject<z.infer<T>> | ZodType<object>) : never);
9
- type InferTuple<T extends ZodType<object> | ZodUnion, U extends readonly ZodSelect<T>[]> = {
10
- [K in keyof U]: InferType<T, U[K]>;
11
- };
12
12
  export {};
package/dist/types.d.ts CHANGED
@@ -9,8 +9,8 @@ export type IsJsonType<T, TDeep extends boolean = true, TTrue = true, TFalse = f
9
9
  } extends {
10
10
  [K in keyof T]: true;
11
11
  } ? TTrue : TFalse : TFalse;
12
+ type JsonType = boolean | null | number | string | undefined;
12
13
  export type Mutable<T> = {
13
14
  -readonly [P in keyof T]: T[P];
14
15
  };
15
- type JsonType = boolean | null | number | string | undefined;
16
16
  export {};
package/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "zodselect",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Type-safe selection utility built on top of Zod. Allows for strongly typed field selection, schema merging, and runtime refinement for frontend or backend use.",
5
5
  "author": "SecureDataSystems",
6
6
  "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/secure-data-systems/zod-select.git"
10
+ },
7
11
  "type": "module",
8
12
  "main": "dist/index.js",
9
13
  "types": "dist/index.d.ts",
@@ -21,15 +25,15 @@
21
25
  }
22
26
  },
23
27
  "devDependencies": {
24
- "@secure-data-systems/eslint-config": "^1.0.2",
25
- "@secure-data-systems/tsconfig": "^1.0.0",
26
- "@types/node": "^24.0.0",
28
+ "@secure-data-systems/eslint-config": "^1.0.6",
29
+ "@secure-data-systems/tsconfig": "^1.0.1",
30
+ "@types/node": "^24.0.4",
27
31
  "glob": "^11.0.3",
28
32
  "tsx": "^4.20.3",
29
33
  "typescript": "^5.8.3"
30
34
  },
31
35
  "dependencies": {
32
- "zod": "^3.25.58"
36
+ "zod": "^3.25.67"
33
37
  },
34
38
  "scripts": {
35
39
  "build": "node scripts/build.mjs && tsc --project tsconfig.build.json",