zod 3.14.5 → 3.15.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/lib/index.mjs +18 -18
- package/lib/index.umd.js +18 -18
- package/lib/types.d.ts +2 -2
- package/lib/types.js +18 -18
- package/package.json +1 -1
package/lib/index.mjs
CHANGED
|
@@ -2506,22 +2506,22 @@ class ZodEffects extends ZodType {
|
|
|
2506
2506
|
});
|
|
2507
2507
|
}
|
|
2508
2508
|
}
|
|
2509
|
+
const checkCtx = {
|
|
2510
|
+
addIssue: (arg) => {
|
|
2511
|
+
addIssueToContext(ctx, arg);
|
|
2512
|
+
if (arg.fatal) {
|
|
2513
|
+
status.abort();
|
|
2514
|
+
}
|
|
2515
|
+
else {
|
|
2516
|
+
status.dirty();
|
|
2517
|
+
}
|
|
2518
|
+
},
|
|
2519
|
+
get path() {
|
|
2520
|
+
return ctx.path;
|
|
2521
|
+
},
|
|
2522
|
+
};
|
|
2523
|
+
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
2509
2524
|
if (effect.type === "refinement") {
|
|
2510
|
-
const checkCtx = {
|
|
2511
|
-
addIssue: (arg) => {
|
|
2512
|
-
addIssueToContext(ctx, arg);
|
|
2513
|
-
if (arg.fatal) {
|
|
2514
|
-
status.abort();
|
|
2515
|
-
}
|
|
2516
|
-
else {
|
|
2517
|
-
status.dirty();
|
|
2518
|
-
}
|
|
2519
|
-
},
|
|
2520
|
-
get path() {
|
|
2521
|
-
return ctx.path;
|
|
2522
|
-
},
|
|
2523
|
-
};
|
|
2524
|
-
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
2525
2525
|
const executeRefinement = (acc
|
|
2526
2526
|
// effect: RefinementEffect<any>
|
|
2527
2527
|
) => {
|
|
@@ -2575,11 +2575,11 @@ class ZodEffects extends ZodType {
|
|
|
2575
2575
|
// }
|
|
2576
2576
|
if (!isValid(base))
|
|
2577
2577
|
return base;
|
|
2578
|
-
const result = effect.transform(base.value);
|
|
2578
|
+
const result = effect.transform(base.value, checkCtx);
|
|
2579
2579
|
if (result instanceof Promise) {
|
|
2580
2580
|
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
2581
2581
|
}
|
|
2582
|
-
return
|
|
2582
|
+
return { status: status.value, value: result };
|
|
2583
2583
|
}
|
|
2584
2584
|
else {
|
|
2585
2585
|
return this._def.schema
|
|
@@ -2591,7 +2591,7 @@ class ZodEffects extends ZodType {
|
|
|
2591
2591
|
// if (base.status === "dirty") {
|
|
2592
2592
|
// return { status: "dirty", value: base.value };
|
|
2593
2593
|
// }
|
|
2594
|
-
return Promise.resolve(effect.transform(base.value)).then(OK);
|
|
2594
|
+
return Promise.resolve(effect.transform(base.value, checkCtx)).then(OK);
|
|
2595
2595
|
});
|
|
2596
2596
|
}
|
|
2597
2597
|
}
|
package/lib/index.umd.js
CHANGED
|
@@ -2512,22 +2512,22 @@
|
|
|
2512
2512
|
});
|
|
2513
2513
|
}
|
|
2514
2514
|
}
|
|
2515
|
+
const checkCtx = {
|
|
2516
|
+
addIssue: (arg) => {
|
|
2517
|
+
addIssueToContext(ctx, arg);
|
|
2518
|
+
if (arg.fatal) {
|
|
2519
|
+
status.abort();
|
|
2520
|
+
}
|
|
2521
|
+
else {
|
|
2522
|
+
status.dirty();
|
|
2523
|
+
}
|
|
2524
|
+
},
|
|
2525
|
+
get path() {
|
|
2526
|
+
return ctx.path;
|
|
2527
|
+
},
|
|
2528
|
+
};
|
|
2529
|
+
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
2515
2530
|
if (effect.type === "refinement") {
|
|
2516
|
-
const checkCtx = {
|
|
2517
|
-
addIssue: (arg) => {
|
|
2518
|
-
addIssueToContext(ctx, arg);
|
|
2519
|
-
if (arg.fatal) {
|
|
2520
|
-
status.abort();
|
|
2521
|
-
}
|
|
2522
|
-
else {
|
|
2523
|
-
status.dirty();
|
|
2524
|
-
}
|
|
2525
|
-
},
|
|
2526
|
-
get path() {
|
|
2527
|
-
return ctx.path;
|
|
2528
|
-
},
|
|
2529
|
-
};
|
|
2530
|
-
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
2531
2531
|
const executeRefinement = (acc
|
|
2532
2532
|
// effect: RefinementEffect<any>
|
|
2533
2533
|
) => {
|
|
@@ -2581,11 +2581,11 @@
|
|
|
2581
2581
|
// }
|
|
2582
2582
|
if (!isValid(base))
|
|
2583
2583
|
return base;
|
|
2584
|
-
const result = effect.transform(base.value);
|
|
2584
|
+
const result = effect.transform(base.value, checkCtx);
|
|
2585
2585
|
if (result instanceof Promise) {
|
|
2586
2586
|
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
2587
2587
|
}
|
|
2588
|
-
return
|
|
2588
|
+
return { status: status.value, value: result };
|
|
2589
2589
|
}
|
|
2590
2590
|
else {
|
|
2591
2591
|
return this._def.schema
|
|
@@ -2597,7 +2597,7 @@
|
|
|
2597
2597
|
// if (base.status === "dirty") {
|
|
2598
2598
|
// return { status: "dirty", value: base.value };
|
|
2599
2599
|
// }
|
|
2600
|
-
return Promise.resolve(effect.transform(base.value)).then(OK);
|
|
2600
|
+
return Promise.resolve(effect.transform(base.value, checkCtx)).then(OK);
|
|
2601
2601
|
});
|
|
2602
2602
|
}
|
|
2603
2603
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -71,7 +71,7 @@ export declare abstract class ZodType<Output = any, Def extends ZodTypeDef = Zod
|
|
|
71
71
|
promise(): ZodPromise<this>;
|
|
72
72
|
or<T extends ZodTypeAny>(option: T): ZodUnion<[this, T]>;
|
|
73
73
|
and<T extends ZodTypeAny>(incoming: T): ZodIntersection<this, T>;
|
|
74
|
-
transform<NewOut>(transform: (arg: Output) => NewOut | Promise<NewOut>): ZodEffects<this, NewOut>;
|
|
74
|
+
transform<NewOut>(transform: (arg: Output, ctx: RefinementCtx) => NewOut | Promise<NewOut>): ZodEffects<this, NewOut>;
|
|
75
75
|
default(def: util.noUndefined<Input>): ZodDefault<this>;
|
|
76
76
|
default(def: () => util.noUndefined<Input>): ZodDefault<this>;
|
|
77
77
|
describe(description: string): this;
|
|
@@ -569,7 +569,7 @@ export declare type RefinementEffect<T> = {
|
|
|
569
569
|
};
|
|
570
570
|
export declare type TransformEffect<T> = {
|
|
571
571
|
type: "transform";
|
|
572
|
-
transform: (arg: T) => any;
|
|
572
|
+
transform: (arg: T, ctx: RefinementCtx) => any;
|
|
573
573
|
};
|
|
574
574
|
export declare type PreprocessEffect<T> = {
|
|
575
575
|
type: "preprocess";
|
package/lib/types.js
CHANGED
|
@@ -2115,22 +2115,22 @@ class ZodEffects extends ZodType {
|
|
|
2115
2115
|
});
|
|
2116
2116
|
}
|
|
2117
2117
|
}
|
|
2118
|
+
const checkCtx = {
|
|
2119
|
+
addIssue: (arg) => {
|
|
2120
|
+
(0, parseUtil_1.addIssueToContext)(ctx, arg);
|
|
2121
|
+
if (arg.fatal) {
|
|
2122
|
+
status.abort();
|
|
2123
|
+
}
|
|
2124
|
+
else {
|
|
2125
|
+
status.dirty();
|
|
2126
|
+
}
|
|
2127
|
+
},
|
|
2128
|
+
get path() {
|
|
2129
|
+
return ctx.path;
|
|
2130
|
+
},
|
|
2131
|
+
};
|
|
2132
|
+
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
2118
2133
|
if (effect.type === "refinement") {
|
|
2119
|
-
const checkCtx = {
|
|
2120
|
-
addIssue: (arg) => {
|
|
2121
|
-
(0, parseUtil_1.addIssueToContext)(ctx, arg);
|
|
2122
|
-
if (arg.fatal) {
|
|
2123
|
-
status.abort();
|
|
2124
|
-
}
|
|
2125
|
-
else {
|
|
2126
|
-
status.dirty();
|
|
2127
|
-
}
|
|
2128
|
-
},
|
|
2129
|
-
get path() {
|
|
2130
|
-
return ctx.path;
|
|
2131
|
-
},
|
|
2132
|
-
};
|
|
2133
|
-
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
2134
2134
|
const executeRefinement = (acc
|
|
2135
2135
|
// effect: RefinementEffect<any>
|
|
2136
2136
|
) => {
|
|
@@ -2184,11 +2184,11 @@ class ZodEffects extends ZodType {
|
|
|
2184
2184
|
// }
|
|
2185
2185
|
if (!(0, parseUtil_1.isValid)(base))
|
|
2186
2186
|
return base;
|
|
2187
|
-
const result = effect.transform(base.value);
|
|
2187
|
+
const result = effect.transform(base.value, checkCtx);
|
|
2188
2188
|
if (result instanceof Promise) {
|
|
2189
2189
|
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
2190
2190
|
}
|
|
2191
|
-
return
|
|
2191
|
+
return { status: status.value, value: result };
|
|
2192
2192
|
}
|
|
2193
2193
|
else {
|
|
2194
2194
|
return this._def.schema
|
|
@@ -2200,7 +2200,7 @@ class ZodEffects extends ZodType {
|
|
|
2200
2200
|
// if (base.status === "dirty") {
|
|
2201
2201
|
// return { status: "dirty", value: base.value };
|
|
2202
2202
|
// }
|
|
2203
|
-
return Promise.resolve(effect.transform(base.value)).then(parseUtil_1.OK);
|
|
2203
|
+
return Promise.resolve(effect.transform(base.value, checkCtx)).then(parseUtil_1.OK);
|
|
2204
2204
|
});
|
|
2205
2205
|
}
|
|
2206
2206
|
}
|