zodselect 1.0.13 → 1.0.14
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.
|
@@ -210,4 +210,33 @@ describe('.buildSelectSchema()', () => {
|
|
|
210
210
|
}
|
|
211
211
|
});
|
|
212
212
|
});
|
|
213
|
+
it('should allow nested object sub-selection in union members', () => {
|
|
214
|
+
const account = z.object({
|
|
215
|
+
_id: z.string(),
|
|
216
|
+
name: z.string()
|
|
217
|
+
});
|
|
218
|
+
const individual = z.object({
|
|
219
|
+
account: account.optional(),
|
|
220
|
+
name: z.object({ first: z.string(), last: z.string() }),
|
|
221
|
+
type: z.literal('individual')
|
|
222
|
+
});
|
|
223
|
+
const organization = z.object({
|
|
224
|
+
account: account.optional(),
|
|
225
|
+
name: z.string(),
|
|
226
|
+
type: z.literal('organization')
|
|
227
|
+
});
|
|
228
|
+
const contact = z.union([individual, organization]);
|
|
229
|
+
const selectSchema = buildSelectSchema(contact);
|
|
230
|
+
// Runtime: nested sub-selection on a shared nested object field should parse
|
|
231
|
+
const result = selectSchema.parse({
|
|
232
|
+
account: { _id: true, name: true },
|
|
233
|
+
type: true
|
|
234
|
+
});
|
|
235
|
+
assert.deepStrictEqual(result, {
|
|
236
|
+
account: { _id: true, name: true },
|
|
237
|
+
type: true
|
|
238
|
+
});
|
|
239
|
+
const nested = { account: { _id: true, name: true }, type: true };
|
|
240
|
+
void nested;
|
|
241
|
+
});
|
|
213
242
|
});
|
package/dist/refine-schema.d.ts
CHANGED
|
@@ -30,9 +30,11 @@ export type RefineZodTuple<T extends ZodTuple> = {
|
|
|
30
30
|
[K in keyof UnionToIntersection<T['def']['items'][number] extends ZodObject<infer Shape extends ZodRawShape> ? Shape : object>]?: boolean;
|
|
31
31
|
};
|
|
32
32
|
export type RefineZodUnion<T extends ZodUnion> = {
|
|
33
|
-
[K in keyof
|
|
33
|
+
[K in keyof UnionMergedShape<T>]?: UnionMergedShape<T>[K] extends ZodType ? UnionFieldType<UnionMergedShape<T>[K]> : boolean;
|
|
34
34
|
};
|
|
35
35
|
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>>;
|
|
36
|
+
type UnionFieldType<T extends ZodType> = z.infer<T> extends Array<infer U> ? Exclude<U, null | undefined> extends object ? boolean | RefineObject<Extract<U, object>, true> : boolean : Exclude<z.infer<T>, null | undefined> extends object ? boolean | RefineObject<Exclude<z.infer<T>, null | undefined>, true> : boolean;
|
|
37
|
+
type UnionMergedShape<T extends ZodUnion> = UnionToIntersection<T['options'][number] extends ZodObject<infer Shape extends ZodRawShape> ? Shape : object>;
|
|
36
38
|
export type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
|
|
37
39
|
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>>>;
|
|
38
40
|
export declare function refineSchema<T extends ZodType<object> | ZodUnion, TShape extends RefineSchema<T, false>>(schema: T, shape: TShape): RefinedSchema<T, TShape, false>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zodselect",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
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",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@secure-data-systems/tsconfig": "^1.0.5",
|
|
30
30
|
"@types/node": "^25.6.0",
|
|
31
31
|
"tsx": "^4.21.0",
|
|
32
|
-
"typescript": "^6.0.
|
|
32
|
+
"typescript": "^6.0.3"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"zod": "^4.3.6"
|