zodselect 1.3.0 → 1.3.1
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/refine-schema.d.ts +5 -1
- package/package.json +1 -1
package/dist/refine-schema.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ type DepthLimit = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
|
|
6
6
|
type Exact<TShape, T> = {
|
|
7
7
|
[K in keyof TShape]: K extends FieldKeys<T> ? TShape[K] extends ((schema: never) => unknown) | boolean | ZodType ? TShape[K] : TShape[K] extends object ? Exact<TShape[K], FieldObjects<FieldAt<T, K>>> : TShape[K] : never;
|
|
8
8
|
};
|
|
9
|
+
/** What {@link refineSchema} takes for `T`: `TShape`, with a key `T` doesn't have, at any depth, a type error even beside valid keys. */
|
|
10
|
+
export type ExactRefineSchema<T extends ZodType<object> | ZodUnion, TShape> = TShape & Exact<TShape, z.infer<T>>;
|
|
9
11
|
/** What the field `TKey` holds in any object of `T`. */
|
|
10
12
|
type FieldAt<T, TKey> = T extends unknown ? TKey extends keyof T ? T[TKey] : never : never;
|
|
11
13
|
/** The declared keys of every object in `T`, each of a union's own. */
|
|
@@ -32,6 +34,8 @@ export type RefinedUnionSchema<T extends ZodUnion, TShape> = ZodUnion<T['options
|
|
|
32
34
|
[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>;
|
|
33
35
|
}
|
|
34
36
|
] : never : never>;
|
|
37
|
+
/** The value of the fields of `T` that `TShape` picks: the output of {@link RefinedTypeSchema}. */
|
|
38
|
+
export type RefinedValue<T extends object, TShape> = z.output<RefinedTypeSchema<T, TShape>>;
|
|
35
39
|
/** One refined schema per variant of a union of objects (a plain object is its own one variant), so the result narrows by variant. */
|
|
36
40
|
type RefinedVariants<T, TShape, TDepth extends number> = T extends object ? RefinedTypeSchema<T, TShape, TDepth> : never;
|
|
37
41
|
type Refinement<T extends ZodType, TIsSimple extends boolean> = TIsSimple extends true ? boolean : ((schema: T) => ZodType) | boolean | ZodType;
|
|
@@ -56,7 +60,7 @@ type ZodifyLiteral<T, TElse> = [
|
|
|
56
60
|
T
|
|
57
61
|
] extends [boolean | number | string] ? [T] extends [boolean] ? boolean extends T ? ZodBoolean : ZodLiteral<T> : string extends T ? [T] extends [string] ? ZodString : TElse : number extends T ? [T] extends [number] ? ZodNumber : TElse : ZodLiteral<T> : TElse;
|
|
58
62
|
/** `shape`'s fields of `schema`. A key the schema doesn't have, at any depth, is a type error. */
|
|
59
|
-
export declare function refineSchema<T extends ZodType<object> | ZodUnion, TShape extends RefineSchema<T, false>>(schema: T, shape:
|
|
63
|
+
export declare function refineSchema<T extends ZodType<object> | ZodUnion, TShape extends RefineSchema<T, false>>(schema: T, shape: ExactRefineSchema<T, TShape>): RefinedSchema<T, TShape, false>;
|
|
60
64
|
/**
|
|
61
65
|
* {@link refineSchema} for a shape whose type is still generic, which the exact key check can't evaluate.
|
|
62
66
|
* Prefer {@link refineSchema}: a key the schema doesn't have is skipped here, not refused.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zodselect",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
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",
|