zod 4.6.2 → 4.6.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.
- package/README.md +2 -2
- package/package.json +1 -1
- package/src/v4/classic/checks.ts +1 -0
- package/src/v4/classic/schemas.ts +3 -25
- package/src/v4/classic/tests/cyclic-data.test.ts +2 -11
- package/src/v4/classic/tests/firstparty.test.ts +0 -4
- package/src/v4/classic/tests/instanceof.test.ts +1 -1
- package/src/v4/classic/tests/properties.test.ts +34 -137
- package/src/v4/core/api.ts +4 -7
- package/src/v4/core/checks.ts +61 -1
- package/src/v4/core/compile.ts +8 -18
- package/src/v4/core/json-schema-processors.ts +0 -50
- package/src/v4/core/memoizer.ts +2 -5
- package/src/v4/core/schemas.ts +1 -98
- package/src/v4/core/to-json-schema.ts +1 -1
- package/src/v4/core/util.ts +0 -4
- package/src/v4/core/versions.ts +1 -1
- package/src/v4/core/visit.ts +0 -11
- package/src/v4/mini/checks.ts +1 -0
- package/src/v4/mini/schemas.ts +0 -19
- package/v4/classic/checks.cjs +2 -1
- package/v4/classic/checks.d.cts +1 -1
- package/v4/classic/checks.d.ts +1 -1
- package/v4/classic/checks.js +1 -1
- package/v4/classic/schemas.cjs +2 -11
- package/v4/classic/schemas.d.cts +1 -6
- package/v4/classic/schemas.d.ts +1 -6
- package/v4/classic/schemas.js +1 -9
- package/v4/core/api.cjs +2 -3
- package/v4/core/api.d.cts +2 -2
- package/v4/core/api.d.ts +2 -2
- package/v4/core/api.js +2 -3
- package/v4/core/checks.cjs +32 -1
- package/v4/core/checks.d.cts +16 -0
- package/v4/core/checks.d.ts +16 -0
- package/v4/core/checks.js +31 -0
- package/v4/core/compile.cjs +5 -11
- package/v4/core/compile.js +5 -11
- package/v4/core/json-schema-processors.cjs +1 -34
- package/v4/core/json-schema-processors.d.cts +0 -1
- package/v4/core/json-schema-processors.d.ts +0 -1
- package/v4/core/json-schema-processors.js +1 -33
- package/v4/core/memoizer.cjs +2 -5
- package/v4/core/memoizer.js +2 -5
- package/v4/core/schemas.cjs +1 -62
- package/v4/core/schemas.d.cts +2 -19
- package/v4/core/schemas.d.ts +2 -19
- package/v4/core/schemas.js +0 -61
- package/v4/core/to-json-schema.cjs +0 -1
- package/v4/core/to-json-schema.d.cts +0 -3
- package/v4/core/to-json-schema.d.ts +0 -3
- package/v4/core/to-json-schema.js +1 -1
- package/v4/core/util.cjs +0 -4
- package/v4/core/util.js +0 -4
- package/v4/core/versions.cjs +1 -1
- package/v4/core/versions.js +1 -1
- package/v4/core/visit.cjs +0 -12
- package/v4/core/visit.js +0 -12
- package/v4/mini/checks.cjs +2 -1
- package/v4/mini/checks.d.cts +1 -1
- package/v4/mini/checks.d.ts +1 -1
- package/v4/mini/checks.js +1 -1
- package/v4/mini/schemas.cjs +1 -9
- package/v4/mini/schemas.d.cts +0 -4
- package/v4/mini/schemas.d.ts +0 -4
- package/v4/mini/schemas.js +0 -7
package/src/v4/core/schemas.ts
CHANGED
|
@@ -96,8 +96,7 @@ export interface $ZodTypeDef {
|
|
|
96
96
|
| "promise"
|
|
97
97
|
| "lazy"
|
|
98
98
|
| "function"
|
|
99
|
-
| "custom"
|
|
100
|
-
| "properties";
|
|
99
|
+
| "custom";
|
|
101
100
|
error?: errors.$ZodErrorMap<never> | undefined;
|
|
102
101
|
checks?: checks.$ZodCheck<never>[];
|
|
103
102
|
}
|
|
@@ -5096,101 +5095,6 @@ function handleRefineResult(result: unknown, payload: ParsePayload, input: unkno
|
|
|
5096
5095
|
}
|
|
5097
5096
|
}
|
|
5098
5097
|
|
|
5099
|
-
////////////////////////////////////////
|
|
5100
|
-
////////////////////////////////////////
|
|
5101
|
-
////////// //////////
|
|
5102
|
-
////////// $ZodProperties //////////
|
|
5103
|
-
////////// //////////
|
|
5104
|
-
////////////////////////////////////////
|
|
5105
|
-
////////////////////////////////////////
|
|
5106
|
-
export interface $ZodPropertiesDef<Shape extends $ZodShape = $ZodShape> extends $ZodTypeDef, checks.$ZodCheckDef {
|
|
5107
|
-
type: "properties";
|
|
5108
|
-
check: "properties";
|
|
5109
|
-
shape: Shape;
|
|
5110
|
-
}
|
|
5111
|
-
|
|
5112
|
-
// both sides infer the INPUT type: the shape is asserted and its results discarded, so a default, catch or transform inside it would make an output-typed inference a lie. The check side widens a literal to its primitive, so spreading over a `string` property still type-checks (#6520).
|
|
5113
|
-
export interface $ZodPropertiesInternals<Shape extends $ZodShape = $ZodShape>
|
|
5114
|
-
extends $ZodTypeInternals<$InferObjectInput<Shape, {}>, $InferObjectInput<Shape, {}>>,
|
|
5115
|
-
checks.$ZodCheckInternals<{ -readonly [k in keyof Shape]: util.Widen<core.input<Shape[k]>> }> {
|
|
5116
|
-
def: $ZodPropertiesDef<Shape>;
|
|
5117
|
-
isst: errors.$ZodIssueInvalidType;
|
|
5118
|
-
issc: errors.$ZodIssue;
|
|
5119
|
-
}
|
|
5120
|
-
|
|
5121
|
-
export interface $ZodProperties<Shape extends $ZodShape = $ZodShape> extends $ZodType {
|
|
5122
|
-
_zod: $ZodPropertiesInternals<Shape>;
|
|
5123
|
-
// yields the schema itself, so pre-4.6 `.check(...z.properties(shape))` spread call sites keep working
|
|
5124
|
-
[Symbol.iterator](): Iterator<this>;
|
|
5125
|
-
}
|
|
5126
|
-
|
|
5127
|
-
// asserts in place: the child result's value is discarded, matching z.property(), because a nested object or array schema rebuilds its output even when nothing transformed
|
|
5128
|
-
function handlePropertiesResult(result: ParsePayload, payload: ParsePayload, key: string | symbol): void {
|
|
5129
|
-
if (result.issues.length) {
|
|
5130
|
-
payload.issues.push(...util.prefixIssues(key, result.issues));
|
|
5131
|
-
}
|
|
5132
|
-
}
|
|
5133
|
-
|
|
5134
|
-
export const $ZodProperties: core.$constructor<$ZodProperties> = /*@__PURE__*/ core.$constructor(
|
|
5135
|
-
"$ZodProperties",
|
|
5136
|
-
(inst, def) => {
|
|
5137
|
-
// $ZodType.init prepends an instance that already carries the $ZodCheck trait to its own `checks`, which would run the shape a second time and cost the parse context. Initializing the check trait after it keeps the schema role in `parse`, where the context arrives.
|
|
5138
|
-
$ZodType.init(inst, def);
|
|
5139
|
-
checks.$ZodCheck.init(inst, def);
|
|
5140
|
-
|
|
5141
|
-
const memo = core.globalConfig.memoizer;
|
|
5142
|
-
memo?.attach(inst);
|
|
5143
|
-
|
|
5144
|
-
// key and schema snapshotted together: reading one live and the other cached lets a later mutation of the caller's shape object pair a stale key with a missing schema
|
|
5145
|
-
let entries!: [string | symbol, $ZodType][];
|
|
5146
|
-
const runShape = (payload: ParsePayload, ctx: ParseContextInternal): util.MaybeAsync<void> => {
|
|
5147
|
-
entries ??= Reflect.ownKeys(def.shape).map((key) => [key, (def.shape as any)[key] as $ZodType]);
|
|
5148
|
-
const input = payload.value as any;
|
|
5149
|
-
let proms: Promise<any>[] | undefined;
|
|
5150
|
-
for (const [key, schema] of entries) {
|
|
5151
|
-
const result = schema._zod.run({ value: input[key], issues: [] }, ctx);
|
|
5152
|
-
if (result instanceof Promise) {
|
|
5153
|
-
proms ??= [];
|
|
5154
|
-
proms.push(result.then((result) => handlePropertiesResult(result, payload, key)));
|
|
5155
|
-
} else {
|
|
5156
|
-
handlePropertiesResult(result, payload, key);
|
|
5157
|
-
}
|
|
5158
|
-
}
|
|
5159
|
-
if (proms) return Promise.all(proms).then(() => undefined);
|
|
5160
|
-
return undefined;
|
|
5161
|
-
};
|
|
5162
|
-
|
|
5163
|
-
inst._zod.parse = (payload, ctx) => {
|
|
5164
|
-
const input = payload.value;
|
|
5165
|
-
// as a schema this is the type gate, and it infers an object shape, so a primitive is a type error. A function passes: its properties read like any other object's, and z.instanceof allows one.
|
|
5166
|
-
if (input === null || (typeof input !== "object" && typeof input !== "function")) {
|
|
5167
|
-
payload.issues.push({ expected: "object", code: "invalid_type", input, inst });
|
|
5168
|
-
return payload;
|
|
5169
|
-
}
|
|
5170
|
-
// both sides declare the shape's input type, so the assertion runs forward in either direction; encoding the children backward would reject the very type this schema claims to take
|
|
5171
|
-
if (ctx.direction === "backward") ctx = { ...ctx, direction: "forward" };
|
|
5172
|
-
// the input is its own output here, so it registers as its own memo entry: a cycle re-entering this node hits the bucket instead of recursing forever
|
|
5173
|
-
if (memo) memo.alloc(inst, payload, input, ctx);
|
|
5174
|
-
const result = runShape(payload, ctx);
|
|
5175
|
-
return result instanceof Promise ? result.then(() => payload) : payload;
|
|
5176
|
-
};
|
|
5177
|
-
|
|
5178
|
-
// as a check the base schema already typed the value, so this only asserts the properties — which read on a primitive too, matching z.property() on a string's length. It gets no context of its own, so a cycle through a spread schema is not tracked.
|
|
5179
|
-
inst._zod.check = (payload) => {
|
|
5180
|
-
if (payload.value == null) {
|
|
5181
|
-
payload.issues.push({ expected: "object", code: "invalid_type", input: payload.value, inst });
|
|
5182
|
-
return undefined;
|
|
5183
|
-
}
|
|
5184
|
-
return runShape(payload, {});
|
|
5185
|
-
};
|
|
5186
|
-
},
|
|
5187
|
-
{
|
|
5188
|
-
*[Symbol.iterator]() {
|
|
5189
|
-
yield this;
|
|
5190
|
-
},
|
|
5191
|
-
}
|
|
5192
|
-
);
|
|
5193
|
-
|
|
5194
5098
|
export type $ZodTypes =
|
|
5195
5099
|
| $ZodString
|
|
5196
5100
|
| $ZodNumber
|
|
@@ -5223,7 +5127,6 @@ export type $ZodTypes =
|
|
|
5223
5127
|
| $ZodPrefault
|
|
5224
5128
|
| $ZodTemplateLiteral
|
|
5225
5129
|
| $ZodCustom
|
|
5226
|
-
| $ZodProperties
|
|
5227
5130
|
| $ZodTransform
|
|
5228
5131
|
| $ZodNonOptional
|
|
5229
5132
|
| $ZodReadonly
|
package/src/v4/core/util.ts
CHANGED
|
@@ -1125,10 +1125,6 @@ export function members(proto: object, table: object): void {
|
|
|
1125
1125
|
// a method materializes bound on first read, which is what keeps a detached member working: `const opt = schema.optional; opt()`
|
|
1126
1126
|
else defineBound(proto, key, desc.value);
|
|
1127
1127
|
}
|
|
1128
|
-
// for..in sees no symbol keys, so well-known members like Symbol.iterator install here
|
|
1129
|
-
for (const sym of Object.getOwnPropertySymbols(table)) {
|
|
1130
|
-
defineBound(proto, sym, (table as any)[sym]);
|
|
1131
|
-
}
|
|
1132
1128
|
}
|
|
1133
1129
|
|
|
1134
1130
|
/** Shadows a prototype member with an own value, so a getter that builds from the instance runs once. */
|
package/src/v4/core/versions.ts
CHANGED
package/src/v4/core/visit.ts
CHANGED
|
@@ -158,17 +158,6 @@ export function visit(schema: schemas.SomeType, fnOrHandlers: VisitFn | VisitHan
|
|
|
158
158
|
const { _cachedInner, ...rest } = def;
|
|
159
159
|
return clone(s, { ...rest, getter: () => run(original()) });
|
|
160
160
|
}
|
|
161
|
-
case "properties": {
|
|
162
|
-
const oldShape = def.shape as Record<string | symbol, AnyZod>;
|
|
163
|
-
let changed = false;
|
|
164
|
-
const newShape: Record<string | symbol, AnyZod> = {};
|
|
165
|
-
for (const k of Reflect.ownKeys(oldShape)) {
|
|
166
|
-
const mapped = run(oldShape[k]!);
|
|
167
|
-
if (mapped !== oldShape[k]) changed = true;
|
|
168
|
-
newShape[k] = mapped;
|
|
169
|
-
}
|
|
170
|
-
return changed ? clone(s, { ...def, shape: newShape }) : s;
|
|
171
|
-
}
|
|
172
161
|
// A leaf by choice: `parts` are regex fragments, not data positions.
|
|
173
162
|
case "template_literal":
|
|
174
163
|
// Leaves.
|
package/src/v4/mini/checks.ts
CHANGED
package/src/v4/mini/schemas.ts
CHANGED
|
@@ -1866,25 +1866,6 @@ export const ZodMiniCustom: core.$constructor<ZodMiniCustom> = /*@__PURE__*/ cor
|
|
|
1866
1866
|
}
|
|
1867
1867
|
);
|
|
1868
1868
|
|
|
1869
|
-
// ZodMiniProperties
|
|
1870
|
-
export interface ZodMiniProperties<Shape extends core.$ZodShape = core.$ZodShape>
|
|
1871
|
-
extends _ZodMiniType<core.$ZodPropertiesInternals<Shape>>,
|
|
1872
|
-
core.$ZodProperties<Shape> {}
|
|
1873
|
-
export const ZodMiniProperties: core.$constructor<ZodMiniProperties> = /*@__PURE__*/ core.$constructor(
|
|
1874
|
-
"ZodMiniProperties",
|
|
1875
|
-
(inst, def) => {
|
|
1876
|
-
core.$ZodProperties.init(inst, def);
|
|
1877
|
-
ZodMiniType.init(inst, def);
|
|
1878
|
-
}
|
|
1879
|
-
);
|
|
1880
|
-
|
|
1881
|
-
export function properties<Shape extends core.$ZodShape>(
|
|
1882
|
-
shape: Shape,
|
|
1883
|
-
params?: string | core.$ZodPropertiesParams
|
|
1884
|
-
): ZodMiniProperties<Shape> {
|
|
1885
|
-
return core._properties(ZodMiniProperties, shape, params) as any;
|
|
1886
|
-
}
|
|
1887
|
-
|
|
1888
1869
|
// custom checks
|
|
1889
1870
|
// @__NO_SIDE_EFFECTS__
|
|
1890
1871
|
export function check<O = unknown>(fn: core.CheckFn<O>, params?: string | core.$ZodCustomParams): core.$ZodCheck<O> {
|
package/v4/classic/checks.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.slugify = exports.toUpperCase = exports.toLowerCase = exports.trim = exports.normalize = exports.overwrite = exports.mime = exports.property = exports.endsWith = exports.startsWith = exports.includes = exports.uppercase = exports.lowercase = exports.regex = exports.length = exports.minLength = exports.maxLength = exports.size = exports.minSize = exports.maxSize = exports.multipleOf = exports.nonnegative = exports.nonpositive = exports.negative = exports.positive = exports.gte = exports.gt = exports.lte = exports.lt = void 0;
|
|
3
|
+
exports.slugify = exports.toUpperCase = exports.toLowerCase = exports.trim = exports.normalize = exports.overwrite = exports.mime = exports.properties = exports.property = exports.endsWith = exports.startsWith = exports.includes = exports.uppercase = exports.lowercase = exports.regex = exports.length = exports.minLength = exports.maxLength = exports.size = exports.minSize = exports.maxSize = exports.multipleOf = exports.nonnegative = exports.nonpositive = exports.negative = exports.positive = exports.gte = exports.gt = exports.lte = exports.lt = void 0;
|
|
4
4
|
var index_js_1 = require("../core/index.cjs");
|
|
5
5
|
Object.defineProperty(exports, "lt", { enumerable: true, get: function () { return index_js_1._lt; } });
|
|
6
6
|
Object.defineProperty(exports, "lte", { enumerable: true, get: function () { return index_js_1._lte; } });
|
|
@@ -24,6 +24,7 @@ Object.defineProperty(exports, "includes", { enumerable: true, get: function ()
|
|
|
24
24
|
Object.defineProperty(exports, "startsWith", { enumerable: true, get: function () { return index_js_1._startsWith; } });
|
|
25
25
|
Object.defineProperty(exports, "endsWith", { enumerable: true, get: function () { return index_js_1._endsWith; } });
|
|
26
26
|
Object.defineProperty(exports, "property", { enumerable: true, get: function () { return index_js_1._property; } });
|
|
27
|
+
Object.defineProperty(exports, "properties", { enumerable: true, get: function () { return index_js_1._properties; } });
|
|
27
28
|
Object.defineProperty(exports, "mime", { enumerable: true, get: function () { return index_js_1._mime; } });
|
|
28
29
|
Object.defineProperty(exports, "overwrite", { enumerable: true, get: function () { return index_js_1._overwrite; } });
|
|
29
30
|
Object.defineProperty(exports, "normalize", { enumerable: true, get: function () { return index_js_1._normalize; } });
|
package/v4/classic/checks.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, _slugify as slugify, type $RefinementCtx as RefinementCtx, } from "../core/index.cjs";
|
|
1
|
+
export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _properties as properties, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, _slugify as slugify, type $RefinementCtx as RefinementCtx, } from "../core/index.cjs";
|
package/v4/classic/checks.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, _slugify as slugify, type $RefinementCtx as RefinementCtx, } from "../core/index.js";
|
|
1
|
+
export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _properties as properties, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, _slugify as slugify, type $RefinementCtx as RefinementCtx, } from "../core/index.js";
|
package/v4/classic/checks.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, _slugify as slugify, } from "../core/index.js";
|
|
1
|
+
export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _properties as properties, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, _slugify as slugify, } from "../core/index.js";
|
package/v4/classic/schemas.cjs
CHANGED
|
@@ -27,7 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.ZodIntersection = exports.ZodDiscriminatedUnion = exports.ZodXor = exports.ZodUnion = exports.ZodObject = exports.ZodArray = exports.ZodDate = exports.ZodVoid = exports.ZodNever = exports.ZodUnknown = exports.ZodAny = exports.ZodNull = exports.ZodUndefined = exports.ZodSymbol = exports.ZodBigIntFormat = exports.ZodBigInt = exports.ZodBoolean = exports.ZodNumberFormat = exports.ZodNumber = exports.ZodCustomStringFormat = exports.ZodJWT = exports.ZodIBAN = exports.ZodCreditCard = exports.ZodE164 = exports.ZodBase64URL = exports.ZodBase64 = exports.ZodCIDRv6 = exports.ZodCIDRv4 = exports.ZodIPv6 = exports.ZodMAC = exports.ZodIPv4 = exports.ZodKSUID = exports.ZodXID = exports.ZodULID = exports.ZodCUID2 = exports.ZodCUID = exports.ZodNanoID = exports.ZodEmoji = exports.ZodURL = exports.ZodUUID = exports.ZodGUID = exports.ZodEmail = exports.ZodISODuration = exports.ZodISOTime = exports.ZodISODate = exports.ZodISODateTime = exports.ZodStringFormat = exports.ZodString = exports._ZodString = exports.ZodType = void 0;
|
|
30
|
-
exports.stringbool = exports.ZodInstanceOf = exports.meta = exports.describe = exports.
|
|
30
|
+
exports.stringbool = exports.ZodInstanceOf = exports.meta = exports.describe = exports.ZodCustom = exports.ZodFunction = exports.ZodPromise = exports.ZodLazy = exports.ZodTemplateLiteral = exports.ZodReadonly = exports.ZodPreprocess = exports.ZodCodec = exports.ZodPipe = exports.ZodNaN = exports.ZodCatch = exports.ZodSuccess = exports.ZodNonOptional = exports.ZodPrefault = exports.ZodDefault = exports.ZodNullable = exports.ZodExactOptional = exports.ZodOptional = exports.ZodTransform = exports.ZodFile = exports.ZodLiteral = exports.ZodEnum = exports.ZodSet = exports.ZodMap = exports.ZodRecord = exports.ZodTuple = void 0;
|
|
31
31
|
exports.string = string;
|
|
32
32
|
exports.email = email;
|
|
33
33
|
exports.guid = guid;
|
|
@@ -118,7 +118,6 @@ exports._function = _function;
|
|
|
118
118
|
exports.function = _function;
|
|
119
119
|
exports._function = _function;
|
|
120
120
|
exports.function = _function;
|
|
121
|
-
exports.properties = properties;
|
|
122
121
|
exports.check = check;
|
|
123
122
|
exports.custom = custom;
|
|
124
123
|
exports.refine = refine;
|
|
@@ -1577,14 +1576,6 @@ exports.ZodCustom = core.$constructor("ZodCustom", (inst, def) => {
|
|
|
1577
1576
|
exports.ZodType.init(inst, def);
|
|
1578
1577
|
inst._zod.processJSONSchema = (ctx, json, params) => processors.customProcessor(inst, ctx, json, params);
|
|
1579
1578
|
});
|
|
1580
|
-
exports.ZodProperties = core.$constructor("ZodProperties", (inst, def) => {
|
|
1581
|
-
_ensureDefaultMemoizer();
|
|
1582
|
-
core.$ZodProperties.init(inst, def);
|
|
1583
|
-
exports.ZodType.init(inst, def);
|
|
1584
|
-
});
|
|
1585
|
-
function properties(shape, params) {
|
|
1586
|
-
return core._properties(exports.ZodProperties, shape, params);
|
|
1587
|
-
}
|
|
1588
1579
|
// custom checks
|
|
1589
1580
|
function check(fn) {
|
|
1590
1581
|
const ch = new core.$ZodCheck({
|
|
@@ -1612,7 +1603,7 @@ exports.ZodInstanceOf = core.$constructor("ZodInstanceOf", (inst, def) => {
|
|
|
1612
1603
|
}, {
|
|
1613
1604
|
properties(shape, params) {
|
|
1614
1605
|
// asserts in place, so the narrowed output type is truthful without a wrapper
|
|
1615
|
-
return this.check(
|
|
1606
|
+
return this.check(core._properties(shape, params));
|
|
1616
1607
|
},
|
|
1617
1608
|
});
|
|
1618
1609
|
function _instanceof(cls, params = {}) {
|
package/v4/classic/schemas.d.cts
CHANGED
|
@@ -779,11 +779,6 @@ export interface ZodCustom<O = unknown, I = unknown> extends _ZodType<core.$ZodC
|
|
|
779
779
|
"~standard": ZodStandardSchemaWithJSON<this>;
|
|
780
780
|
}
|
|
781
781
|
export declare const ZodCustom: core.$constructor<ZodCustom>;
|
|
782
|
-
export interface ZodProperties<Shape extends core.$ZodShape = core.$ZodShape> extends _ZodType<core.$ZodPropertiesInternals<Shape>>, core.$ZodProperties<Shape> {
|
|
783
|
-
"~standard": ZodStandardSchemaWithJSON<this>;
|
|
784
|
-
}
|
|
785
|
-
export declare const ZodProperties: core.$constructor<ZodProperties>;
|
|
786
|
-
export declare function properties<Shape extends core.$ZodShape>(shape: Shape, params?: string | core.$ZodPropertiesParams): ZodProperties<Shape>;
|
|
787
782
|
export declare function check<O = unknown>(fn: core.CheckFn<O>): core.$ZodCheck<O>;
|
|
788
783
|
export declare function custom<O>(fn?: (data: unknown) => unknown, _params?: string | core.$ZodCustomParams | undefined): ZodCustom<O, O>;
|
|
789
784
|
export declare function refine<T>(fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>, _params?: string | core.$ZodCustomParams): core.$ZodCheck<T>;
|
|
@@ -792,7 +787,7 @@ export declare const describe: typeof core.describe;
|
|
|
792
787
|
export declare const meta: typeof core.meta;
|
|
793
788
|
type ZodInstanceOfParams = core.Params<ZodCustom, core.$ZodIssueCustom, "type" | "check" | "checks" | "fn" | "abort" | "error" | "params" | "path">;
|
|
794
789
|
export interface ZodInstanceOf<T = unknown> extends ZodCustom<T, T> {
|
|
795
|
-
properties<Shape extends core.$ZodShape>(shape: Shape, params?: string | core.$
|
|
790
|
+
properties<Shape extends core.$ZodShape>(shape: Shape, params?: string | core.$ZodCheckPropertiesParams): ZodInstanceOf<T & core.$InferObjectInput<Shape, {}>>;
|
|
796
791
|
}
|
|
797
792
|
export declare const ZodInstanceOf: core.$constructor<ZodInstanceOf>;
|
|
798
793
|
declare function _instanceof<T extends typeof util.Class>(cls: T, params?: ZodInstanceOfParams): ZodInstanceOf<InstanceType<T>>;
|
package/v4/classic/schemas.d.ts
CHANGED
|
@@ -779,11 +779,6 @@ export interface ZodCustom<O = unknown, I = unknown> extends _ZodType<core.$ZodC
|
|
|
779
779
|
"~standard": ZodStandardSchemaWithJSON<this>;
|
|
780
780
|
}
|
|
781
781
|
export declare const ZodCustom: core.$constructor<ZodCustom>;
|
|
782
|
-
export interface ZodProperties<Shape extends core.$ZodShape = core.$ZodShape> extends _ZodType<core.$ZodPropertiesInternals<Shape>>, core.$ZodProperties<Shape> {
|
|
783
|
-
"~standard": ZodStandardSchemaWithJSON<this>;
|
|
784
|
-
}
|
|
785
|
-
export declare const ZodProperties: core.$constructor<ZodProperties>;
|
|
786
|
-
export declare function properties<Shape extends core.$ZodShape>(shape: Shape, params?: string | core.$ZodPropertiesParams): ZodProperties<Shape>;
|
|
787
782
|
export declare function check<O = unknown>(fn: core.CheckFn<O>): core.$ZodCheck<O>;
|
|
788
783
|
export declare function custom<O>(fn?: (data: unknown) => unknown, _params?: string | core.$ZodCustomParams | undefined): ZodCustom<O, O>;
|
|
789
784
|
export declare function refine<T>(fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>, _params?: string | core.$ZodCustomParams): core.$ZodCheck<T>;
|
|
@@ -792,7 +787,7 @@ export declare const describe: typeof core.describe;
|
|
|
792
787
|
export declare const meta: typeof core.meta;
|
|
793
788
|
type ZodInstanceOfParams = core.Params<ZodCustom, core.$ZodIssueCustom, "type" | "check" | "checks" | "fn" | "abort" | "error" | "params" | "path">;
|
|
794
789
|
export interface ZodInstanceOf<T = unknown> extends ZodCustom<T, T> {
|
|
795
|
-
properties<Shape extends core.$ZodShape>(shape: Shape, params?: string | core.$
|
|
790
|
+
properties<Shape extends core.$ZodShape>(shape: Shape, params?: string | core.$ZodCheckPropertiesParams): ZodInstanceOf<T & core.$InferObjectInput<Shape, {}>>;
|
|
796
791
|
}
|
|
797
792
|
export declare const ZodInstanceOf: core.$constructor<ZodInstanceOf>;
|
|
798
793
|
declare function _instanceof<T extends typeof util.Class>(cls: T, params?: ZodInstanceOfParams): ZodInstanceOf<InstanceType<T>>;
|
package/v4/classic/schemas.js
CHANGED
|
@@ -1455,14 +1455,6 @@ export const ZodCustom = /*@__PURE__*/ core.$constructor("ZodCustom", (inst, def
|
|
|
1455
1455
|
ZodType.init(inst, def);
|
|
1456
1456
|
inst._zod.processJSONSchema = (ctx, json, params) => processors.customProcessor(inst, ctx, json, params);
|
|
1457
1457
|
});
|
|
1458
|
-
export const ZodProperties = /*@__PURE__*/ core.$constructor("ZodProperties", (inst, def) => {
|
|
1459
|
-
_ensureDefaultMemoizer();
|
|
1460
|
-
core.$ZodProperties.init(inst, def);
|
|
1461
|
-
ZodType.init(inst, def);
|
|
1462
|
-
});
|
|
1463
|
-
export function properties(shape, params) {
|
|
1464
|
-
return core._properties(ZodProperties, shape, params);
|
|
1465
|
-
}
|
|
1466
1458
|
// custom checks
|
|
1467
1459
|
export function check(fn) {
|
|
1468
1460
|
const ch = new core.$ZodCheck({
|
|
@@ -1490,7 +1482,7 @@ export const ZodInstanceOf = /*@__PURE__*/ core.$constructor("ZodInstanceOf", (i
|
|
|
1490
1482
|
}, {
|
|
1491
1483
|
properties(shape, params) {
|
|
1492
1484
|
// asserts in place, so the narrowed output type is truthful without a wrapper
|
|
1493
|
-
return this.check(
|
|
1485
|
+
return this.check(core._properties(shape, params));
|
|
1494
1486
|
},
|
|
1495
1487
|
});
|
|
1496
1488
|
function _instanceof(cls, params = {}) {
|
package/v4/core/api.cjs
CHANGED
|
@@ -831,9 +831,8 @@ function _property(property, schema, params) {
|
|
|
831
831
|
});
|
|
832
832
|
}
|
|
833
833
|
// @__NO_SIDE_EFFECTS__
|
|
834
|
-
function _properties(
|
|
835
|
-
return new
|
|
836
|
-
type: "properties",
|
|
834
|
+
function _properties(shape, params) {
|
|
835
|
+
return new checks.$ZodCheckProperties({
|
|
837
836
|
check: "properties",
|
|
838
837
|
shape,
|
|
839
838
|
...util.normalizeParams(params),
|
package/v4/core/api.d.cts
CHANGED
|
@@ -216,8 +216,8 @@ export type $ZodCheckPropertyParams = CheckParams<checks.$ZodCheckProperty, "pro
|
|
|
216
216
|
export declare function _property<K extends string, T extends schemas.$ZodType>(property: K, schema: T, params?: string | $ZodCheckPropertyParams): checks.$ZodCheckProperty<{
|
|
217
217
|
[k in K]: util.Widen<core.input<T>>;
|
|
218
218
|
}>;
|
|
219
|
-
export type $
|
|
220
|
-
export declare function _properties<Shape extends schemas.$ZodShape>(
|
|
219
|
+
export type $ZodCheckPropertiesParams = CheckParams<checks.$ZodCheckProperties, "shape" | "when">;
|
|
220
|
+
export declare function _properties<Shape extends schemas.$ZodShape>(shape: Shape, params?: string | $ZodCheckPropertiesParams): checks.$ZodCheckProperties<Shape>;
|
|
221
221
|
export type $ZodCheckMimeTypeParams = CheckParams<checks.$ZodCheckMimeType, "mime" | "when">;
|
|
222
222
|
export declare function _mime(types: util.MimeTypes[], params?: string | $ZodCheckMimeTypeParams): checks.$ZodCheckMimeType;
|
|
223
223
|
export declare function _overwrite<T>(tx: (input: T) => T): checks.$ZodCheckOverwrite<T>;
|
package/v4/core/api.d.ts
CHANGED
|
@@ -216,8 +216,8 @@ export type $ZodCheckPropertyParams = CheckParams<checks.$ZodCheckProperty, "pro
|
|
|
216
216
|
export declare function _property<K extends string, T extends schemas.$ZodType>(property: K, schema: T, params?: string | $ZodCheckPropertyParams): checks.$ZodCheckProperty<{
|
|
217
217
|
[k in K]: util.Widen<core.input<T>>;
|
|
218
218
|
}>;
|
|
219
|
-
export type $
|
|
220
|
-
export declare function _properties<Shape extends schemas.$ZodShape>(
|
|
219
|
+
export type $ZodCheckPropertiesParams = CheckParams<checks.$ZodCheckProperties, "shape" | "when">;
|
|
220
|
+
export declare function _properties<Shape extends schemas.$ZodShape>(shape: Shape, params?: string | $ZodCheckPropertiesParams): checks.$ZodCheckProperties<Shape>;
|
|
221
221
|
export type $ZodCheckMimeTypeParams = CheckParams<checks.$ZodCheckMimeType, "mime" | "when">;
|
|
222
222
|
export declare function _mime(types: util.MimeTypes[], params?: string | $ZodCheckMimeTypeParams): checks.$ZodCheckMimeType;
|
|
223
223
|
export declare function _overwrite<T>(tx: (input: T) => T): checks.$ZodCheckOverwrite<T>;
|
package/v4/core/api.js
CHANGED
|
@@ -688,9 +688,8 @@ export function _property(property, schema, params) {
|
|
|
688
688
|
});
|
|
689
689
|
}
|
|
690
690
|
// @__NO_SIDE_EFFECTS__
|
|
691
|
-
export function _properties(
|
|
692
|
-
return new
|
|
693
|
-
type: "properties",
|
|
691
|
+
export function _properties(shape, params) {
|
|
692
|
+
return new checks.$ZodCheckProperties({
|
|
694
693
|
check: "properties",
|
|
695
694
|
shape,
|
|
696
695
|
...util.normalizeParams(params),
|
package/v4/core/checks.cjs
CHANGED
|
@@ -24,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
return result;
|
|
25
25
|
};
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.$ZodCheckOverwrite = exports.$ZodCheckMimeType = exports.$ZodCheckProperty = exports.$ZodCheckEndsWith = exports.$ZodCheckStartsWith = exports.$ZodCheckIncludes = exports.$ZodCheckUpperCase = exports.$ZodCheckLowerCase = exports.$ZodCheckRegex = exports.$ZodCheckStringFormat = exports.$ZodCheckLengthEquals = exports.$ZodCheckMinLength = exports.$ZodCheckMaxLength = exports.$ZodCheckSizeEquals = exports.$ZodCheckMinSize = exports.$ZodCheckMaxSize = exports.$ZodCheckBigIntFormat = exports.$ZodCheckNumberFormat = exports.$ZodCheckMultipleOf = exports.$ZodCheckGreaterThan = exports.$ZodCheckLessThan = exports.$ZodCheck = void 0;
|
|
27
|
+
exports.$ZodCheckOverwrite = exports.$ZodCheckMimeType = exports.$ZodCheckProperties = exports.$ZodCheckProperty = exports.$ZodCheckEndsWith = exports.$ZodCheckStartsWith = exports.$ZodCheckIncludes = exports.$ZodCheckUpperCase = exports.$ZodCheckLowerCase = exports.$ZodCheckRegex = exports.$ZodCheckStringFormat = exports.$ZodCheckLengthEquals = exports.$ZodCheckMinLength = exports.$ZodCheckMaxLength = exports.$ZodCheckSizeEquals = exports.$ZodCheckMinSize = exports.$ZodCheckMaxSize = exports.$ZodCheckBigIntFormat = exports.$ZodCheckNumberFormat = exports.$ZodCheckMultipleOf = exports.$ZodCheckGreaterThan = exports.$ZodCheckLessThan = exports.$ZodCheck = void 0;
|
|
28
28
|
const core = __importStar(require("./core.cjs"));
|
|
29
29
|
const regexes = __importStar(require("./regexes.cjs"));
|
|
30
30
|
const util = __importStar(require("./util.cjs"));
|
|
@@ -488,6 +488,37 @@ exports.$ZodCheckProperty = core.$constructor("$ZodCheckProperty", (inst, def) =
|
|
|
488
488
|
return;
|
|
489
489
|
};
|
|
490
490
|
});
|
|
491
|
+
exports.$ZodCheckProperties = core.$constructor("$ZodCheckProperties", (inst, def) => {
|
|
492
|
+
exports.$ZodCheck.init(inst, def);
|
|
493
|
+
util.hide(inst, Symbol.iterator, function* () {
|
|
494
|
+
yield inst;
|
|
495
|
+
});
|
|
496
|
+
// key and schema snapshotted together: reading one live and the other cached lets a later mutation of the caller's shape object pair a stale key with a missing schema
|
|
497
|
+
let entries;
|
|
498
|
+
inst._zod.check = (payload) => {
|
|
499
|
+
// the base schema already typed the value, so only a nullish one is rejected here: the properties read on a primitive too, matching z.property() on a string's length
|
|
500
|
+
if (payload.value == null) {
|
|
501
|
+
payload.issues.push({ expected: "object", code: "invalid_type", input: payload.value, inst });
|
|
502
|
+
return undefined;
|
|
503
|
+
}
|
|
504
|
+
entries ?? (entries = Reflect.ownKeys(def.shape).map((key) => [key, def.shape[key]]));
|
|
505
|
+
const input = payload.value;
|
|
506
|
+
let proms;
|
|
507
|
+
for (const [key, schema] of entries) {
|
|
508
|
+
const result = schema._zod.run({ value: input[key], issues: [] }, {});
|
|
509
|
+
if (result instanceof Promise) {
|
|
510
|
+
proms ?? (proms = []);
|
|
511
|
+
proms.push(result.then((result) => handleCheckPropertyResult(result, payload, key)));
|
|
512
|
+
}
|
|
513
|
+
else {
|
|
514
|
+
handleCheckPropertyResult(result, payload, key);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
if (proms)
|
|
518
|
+
return Promise.all(proms).then(() => undefined);
|
|
519
|
+
return undefined;
|
|
520
|
+
};
|
|
521
|
+
});
|
|
491
522
|
exports.$ZodCheckMimeType = core.$constructor("$ZodCheckMimeType", (inst, def) => {
|
|
492
523
|
exports.$ZodCheck.init(inst, def);
|
|
493
524
|
const mimeSet = new Set(def.mime);
|
package/v4/core/checks.d.cts
CHANGED
|
@@ -250,6 +250,22 @@ export interface $ZodCheckProperty<T extends object = object> extends $ZodCheck<
|
|
|
250
250
|
_zod: $ZodCheckPropertyInternals<T>;
|
|
251
251
|
}
|
|
252
252
|
export declare const $ZodCheckProperty: core.$constructor<$ZodCheckProperty>;
|
|
253
|
+
export interface $ZodCheckPropertiesDef<Shape extends schemas.$ZodShape = schemas.$ZodShape> extends $ZodCheckDef {
|
|
254
|
+
check: "properties";
|
|
255
|
+
shape: Shape;
|
|
256
|
+
}
|
|
257
|
+
export type $ZodCheckPropertiesInput<Shape extends schemas.$ZodShape = schemas.$ZodShape> = {
|
|
258
|
+
-readonly [k in keyof Shape]: util.Widen<core.input<Shape[k]>>;
|
|
259
|
+
};
|
|
260
|
+
export interface $ZodCheckPropertiesInternals<Shape extends schemas.$ZodShape = schemas.$ZodShape> extends $ZodCheckInternals<$ZodCheckPropertiesInput<Shape>> {
|
|
261
|
+
def: $ZodCheckPropertiesDef<Shape>;
|
|
262
|
+
issc: errors.$ZodIssue;
|
|
263
|
+
}
|
|
264
|
+
export interface $ZodCheckProperties<Shape extends schemas.$ZodShape = schemas.$ZodShape> extends $ZodCheck<$ZodCheckPropertiesInput<Shape>> {
|
|
265
|
+
_zod: $ZodCheckPropertiesInternals<Shape>;
|
|
266
|
+
[Symbol.iterator](): Iterator<this>;
|
|
267
|
+
}
|
|
268
|
+
export declare const $ZodCheckProperties: core.$constructor<$ZodCheckProperties>;
|
|
253
269
|
export interface $ZodCheckMimeTypeDef extends $ZodCheckDef {
|
|
254
270
|
check: "mime_type";
|
|
255
271
|
mime: util.MimeTypes[];
|
package/v4/core/checks.d.ts
CHANGED
|
@@ -250,6 +250,22 @@ export interface $ZodCheckProperty<T extends object = object> extends $ZodCheck<
|
|
|
250
250
|
_zod: $ZodCheckPropertyInternals<T>;
|
|
251
251
|
}
|
|
252
252
|
export declare const $ZodCheckProperty: core.$constructor<$ZodCheckProperty>;
|
|
253
|
+
export interface $ZodCheckPropertiesDef<Shape extends schemas.$ZodShape = schemas.$ZodShape> extends $ZodCheckDef {
|
|
254
|
+
check: "properties";
|
|
255
|
+
shape: Shape;
|
|
256
|
+
}
|
|
257
|
+
export type $ZodCheckPropertiesInput<Shape extends schemas.$ZodShape = schemas.$ZodShape> = {
|
|
258
|
+
-readonly [k in keyof Shape]: util.Widen<core.input<Shape[k]>>;
|
|
259
|
+
};
|
|
260
|
+
export interface $ZodCheckPropertiesInternals<Shape extends schemas.$ZodShape = schemas.$ZodShape> extends $ZodCheckInternals<$ZodCheckPropertiesInput<Shape>> {
|
|
261
|
+
def: $ZodCheckPropertiesDef<Shape>;
|
|
262
|
+
issc: errors.$ZodIssue;
|
|
263
|
+
}
|
|
264
|
+
export interface $ZodCheckProperties<Shape extends schemas.$ZodShape = schemas.$ZodShape> extends $ZodCheck<$ZodCheckPropertiesInput<Shape>> {
|
|
265
|
+
_zod: $ZodCheckPropertiesInternals<Shape>;
|
|
266
|
+
[Symbol.iterator](): Iterator<this>;
|
|
267
|
+
}
|
|
268
|
+
export declare const $ZodCheckProperties: core.$constructor<$ZodCheckProperties>;
|
|
253
269
|
export interface $ZodCheckMimeTypeDef extends $ZodCheckDef {
|
|
254
270
|
check: "mime_type";
|
|
255
271
|
mime: util.MimeTypes[];
|
package/v4/core/checks.js
CHANGED
|
@@ -462,6 +462,37 @@ export const $ZodCheckProperty = /*@__PURE__*/ core.$constructor("$ZodCheckPrope
|
|
|
462
462
|
return;
|
|
463
463
|
};
|
|
464
464
|
});
|
|
465
|
+
export const $ZodCheckProperties = /*@__PURE__*/ core.$constructor("$ZodCheckProperties", (inst, def) => {
|
|
466
|
+
$ZodCheck.init(inst, def);
|
|
467
|
+
util.hide(inst, Symbol.iterator, function* () {
|
|
468
|
+
yield inst;
|
|
469
|
+
});
|
|
470
|
+
// key and schema snapshotted together: reading one live and the other cached lets a later mutation of the caller's shape object pair a stale key with a missing schema
|
|
471
|
+
let entries;
|
|
472
|
+
inst._zod.check = (payload) => {
|
|
473
|
+
// the base schema already typed the value, so only a nullish one is rejected here: the properties read on a primitive too, matching z.property() on a string's length
|
|
474
|
+
if (payload.value == null) {
|
|
475
|
+
payload.issues.push({ expected: "object", code: "invalid_type", input: payload.value, inst });
|
|
476
|
+
return undefined;
|
|
477
|
+
}
|
|
478
|
+
entries ?? (entries = Reflect.ownKeys(def.shape).map((key) => [key, def.shape[key]]));
|
|
479
|
+
const input = payload.value;
|
|
480
|
+
let proms;
|
|
481
|
+
for (const [key, schema] of entries) {
|
|
482
|
+
const result = schema._zod.run({ value: input[key], issues: [] }, {});
|
|
483
|
+
if (result instanceof Promise) {
|
|
484
|
+
proms ?? (proms = []);
|
|
485
|
+
proms.push(result.then((result) => handleCheckPropertyResult(result, payload, key)));
|
|
486
|
+
}
|
|
487
|
+
else {
|
|
488
|
+
handleCheckPropertyResult(result, payload, key);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
if (proms)
|
|
492
|
+
return Promise.all(proms).then(() => undefined);
|
|
493
|
+
return undefined;
|
|
494
|
+
};
|
|
495
|
+
});
|
|
465
496
|
export const $ZodCheckMimeType = /*@__PURE__*/ core.$constructor("$ZodCheckMimeType", (inst, def) => {
|
|
466
497
|
$ZodCheck.init(inst, def);
|
|
467
498
|
const mimeSet = new Set(def.mime);
|
package/v4/core/compile.cjs
CHANGED
|
@@ -361,7 +361,7 @@ function generateChecks(doc, ctx, schema, accessor) {
|
|
|
361
361
|
generatePropertyCheck(doc, ctx, def, currentAccessor);
|
|
362
362
|
break;
|
|
363
363
|
case "properties":
|
|
364
|
-
generatePropertiesChecks(doc, ctx, def, currentAccessor
|
|
364
|
+
generatePropertiesChecks(doc, ctx, def, currentAccessor);
|
|
365
365
|
break;
|
|
366
366
|
case "overwrite": {
|
|
367
367
|
// Overwrite transforms the value - create new variable for transformed result
|
|
@@ -489,15 +489,13 @@ function generateMimeTypeCheck(doc, ctx, def, accessor) {
|
|
|
489
489
|
}
|
|
490
490
|
}
|
|
491
491
|
// asserts each named property in place; children compile assert-only because z.properties never rebuilds its input
|
|
492
|
-
function generatePropertiesChecks(doc, ctx, def, accessor
|
|
493
|
-
// a custom `when` gates the assertion at runtime; inside a union a wrongly-run branch is absorbed as a branch failure rather than falling back, so refuse at codegen
|
|
492
|
+
function generatePropertiesChecks(doc, ctx, def, accessor) {
|
|
493
|
+
// a custom `when` gates the assertion at runtime; inside a union a wrongly-run branch is absorbed as a branch failure rather than falling back, so refuse at codegen
|
|
494
494
|
if (def.when) {
|
|
495
495
|
throw new ZodCompileUnsupportedError(`check with a custom "when" condition`);
|
|
496
496
|
}
|
|
497
|
-
// matches the runtime gate
|
|
498
|
-
doc.write(
|
|
499
|
-
? `if (${accessor} === null || (typeof ${accessor} !== "object" && typeof ${accessor} !== "function")) return INVALID;`
|
|
500
|
-
: `if (${accessor} == null) return INVALID;`);
|
|
497
|
+
// matches the runtime gate: the base schema already typed the value, so only a nullish one is rejected
|
|
498
|
+
doc.write(`if (${accessor} == null) return INVALID;`);
|
|
501
499
|
const shape = def.shape;
|
|
502
500
|
for (const key of Reflect.ownKeys(shape)) {
|
|
503
501
|
// a symbol has no source literal, so it is hoisted as a constant
|
|
@@ -848,10 +846,6 @@ function generateCheck(doc, ctx, schema, accessor, needsValue = true) {
|
|
|
848
846
|
case "custom":
|
|
849
847
|
typeAccessor = generateCustomCheck(doc, ctx, schema, accessor);
|
|
850
848
|
break;
|
|
851
|
-
case "properties":
|
|
852
|
-
generatePropertiesChecks(doc, ctx, schema._zod.def, accessor, true);
|
|
853
|
-
typeAccessor = accessor;
|
|
854
|
-
break;
|
|
855
849
|
case "transform":
|
|
856
850
|
typeAccessor = generateTransformCheck(doc, ctx, schema, accessor);
|
|
857
851
|
break;
|
package/v4/core/compile.js
CHANGED
|
@@ -330,7 +330,7 @@ function generateChecks(doc, ctx, schema, accessor) {
|
|
|
330
330
|
generatePropertyCheck(doc, ctx, def, currentAccessor);
|
|
331
331
|
break;
|
|
332
332
|
case "properties":
|
|
333
|
-
generatePropertiesChecks(doc, ctx, def, currentAccessor
|
|
333
|
+
generatePropertiesChecks(doc, ctx, def, currentAccessor);
|
|
334
334
|
break;
|
|
335
335
|
case "overwrite": {
|
|
336
336
|
// Overwrite transforms the value - create new variable for transformed result
|
|
@@ -458,15 +458,13 @@ function generateMimeTypeCheck(doc, ctx, def, accessor) {
|
|
|
458
458
|
}
|
|
459
459
|
}
|
|
460
460
|
// asserts each named property in place; children compile assert-only because z.properties never rebuilds its input
|
|
461
|
-
function generatePropertiesChecks(doc, ctx, def, accessor
|
|
462
|
-
// a custom `when` gates the assertion at runtime; inside a union a wrongly-run branch is absorbed as a branch failure rather than falling back, so refuse at codegen
|
|
461
|
+
function generatePropertiesChecks(doc, ctx, def, accessor) {
|
|
462
|
+
// a custom `when` gates the assertion at runtime; inside a union a wrongly-run branch is absorbed as a branch failure rather than falling back, so refuse at codegen
|
|
463
463
|
if (def.when) {
|
|
464
464
|
throw new ZodCompileUnsupportedError(`check with a custom "when" condition`);
|
|
465
465
|
}
|
|
466
|
-
// matches the runtime gate
|
|
467
|
-
doc.write(
|
|
468
|
-
? `if (${accessor} === null || (typeof ${accessor} !== "object" && typeof ${accessor} !== "function")) return INVALID;`
|
|
469
|
-
: `if (${accessor} == null) return INVALID;`);
|
|
466
|
+
// matches the runtime gate: the base schema already typed the value, so only a nullish one is rejected
|
|
467
|
+
doc.write(`if (${accessor} == null) return INVALID;`);
|
|
470
468
|
const shape = def.shape;
|
|
471
469
|
for (const key of Reflect.ownKeys(shape)) {
|
|
472
470
|
// a symbol has no source literal, so it is hoisted as a constant
|
|
@@ -817,10 +815,6 @@ function generateCheck(doc, ctx, schema, accessor, needsValue = true) {
|
|
|
817
815
|
case "custom":
|
|
818
816
|
typeAccessor = generateCustomCheck(doc, ctx, schema, accessor);
|
|
819
817
|
break;
|
|
820
|
-
case "properties":
|
|
821
|
-
generatePropertiesChecks(doc, ctx, schema._zod.def, accessor, true);
|
|
822
|
-
typeAccessor = accessor;
|
|
823
|
-
break;
|
|
824
818
|
case "transform":
|
|
825
819
|
typeAccessor = generateTransformCheck(doc, ctx, schema, accessor);
|
|
826
820
|
break;
|