Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"formatter": {
"enabled": true,
"indentStyle": "space",
"lineWidth": 80
"lineWidth": 120
},
"javascript": {
"formatter": {
Expand Down
124 changes: 0 additions & 124 deletions packages/core/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1005,131 +1005,7 @@ export function _array<T extends schemas.$ZodType>(
}) as schemas.$ZodArray<T>;
}

// ZodObjectLike
export type $ZodObjectLikeParams = util.TypeParams<schemas.$ZodObject, "shape" | "catchall">;

// export type $ZodInterfaceParams = util.TypeParams<schemas.$ZodInterface, "shape">;
// export function _interface<T extends schemas.$ZodLooseShape>(
// Class: util.SchemaClass<schemas.$ZodInterface>,
// shape: T,
// params?: $ZodInterfaceParams
// ): schemas.$ZodInterface<T, {}> {
// const cleaned = util.cached(() => util.cleanInterfaceShape(shape));
// const def: schemas.$ZodInterfaceDef = {
// type: "interface",
// get shape() {
// const _shape = cleaned.value.shape;
// util.assignProp(this, "shape", _shape);
// return _shape;
// // return cleaned.value.shape;
// },
// // get shapeMeta() {
// // return cleaned.value.shapeMeta;
// // },
// ...util.normalizeParams(params),
// };
// return new Class(def) as any;
// }

// // strictInterface
// export function _strictInterface<T extends schemas.$ZodLooseShape>(
// Class: util.SchemaClass<schemas.$ZodInterface>,
// shape: T,
// params?: $ZodInterfaceParams
// ): schemas.$ZodInterface<T, {}> {
// const cleaned = util.cached(() => util.cleanInterfaceShape(shape));
// const def: schemas.$ZodInterfaceDef = {
// type: "interface",
// get shape() {
// const _shape = cleaned.value.shape;
// util.assignProp(this, "shape", _shape);
// return _shape;
// // return cleaned.value.shape;
// },
// // get shapeMeta() {
// // return cleaned.value.shapeMeta;
// // },
// catchall: _never(schemas.$ZodNever),
// ...util.normalizeParams(params),
// };
// return new Class(def) as any;
// }

// // looseInterface
// export function _looseInterface<T extends schemas.$ZodLooseShape>(
// Class: util.SchemaClass<schemas.$ZodInterface>,
// shape: T,
// params?: string | $ZodInterfaceParams
// ): schemas.$ZodInterface<T, Record<string, unknown>> {
// const cleaned = util.cached(() => util.cleanInterfaceShape(shape));
// const def: schemas.$ZodInterfaceDef = {
// type: "interface",

// get shape() {
// const _shape = cleaned.value.shape;
// util.assignProp(this, "shape", _shape);
// return _shape;
// // return cleaned.value.shape;
// },
// // get shapeMeta() {
// // return cleaned.value.shapeMeta;
// // },
// catchall: _unknown(schemas.$ZodUnknown),
// ...util.normalizeParams(params),
// };
// return new Class(def) as any;
// }

export type $ZodObjectParams = util.TypeParams<schemas.$ZodObject, "shape" | "catchall">;
// export function _object<T extends schemas.$ZodShape = Record<never, schemas.$ZodObject>>(
// Class: util.SchemaClass<schemas.$ZodObject>,
// shape?: T,
// params?: $ZodObjectLikeParams
// ): schemas.$ZodObject<T, {}> {
// const def: schemas.$ZodObjectDef = {
// type: "object",
// // shape: shape ?? {},
// get shape() {
// return util.objectShapeMeta(shape ?? {});
// },
// ...util.normalizeParams(params),
// };
// return new Class(def) as any;
// }

// // strictObject
// export function _strictObject<T extends schemas.$ZodShape>(
// Class: util.SchemaClass<schemas.$ZodObject>,
// shape: T,
// params?: $ZodObjectParams
// ): schemas.$ZodObject<T, {}> {
// return new Class({
// type: "object",
// // shape: shape as schemas.$ZodShape,
// get shape() {
// return util.objectShapeMeta(shape ?? {});
// },
// catchall: _never(schemas.$ZodNever),
// ...util.normalizeParams(params),
// }) as any;
// }

// // looseObject
// export function _looseObject<T extends schemas.$ZodShape>(
// Class: util.SchemaClass<schemas.$ZodObject>,
// shape: T,
// params?: $ZodObjectParams
// ): schemas.$ZodObject<T, { [k: string]: unknown }> {
// return new Class({
// type: "object",
// // shape: shape as schemas.$ZodShape,
// get shape() {
// return util.objectShapeMeta(shape ?? {});
// },
// catchall: _unknown(schemas.$ZodUnknown),
// ...util.normalizeParams(params),
// }) as any;
// }

// ZodUnion
export type $ZodUnionParams = util.TypeParams<schemas.$ZodUnion, "options">;
Expand Down
17 changes: 12 additions & 5 deletions packages/core/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,15 @@ export const $ZodType: core.$constructor<$ZodType> = /*@__PURE__*/ core.$constru
if (result instanceof Promise) {
return result.then(({ issues, value }) => {
if (issues.length === 0) return { value } as any;
return { issues: issues.map((iss) => util.finalizeIssue(iss, {}, core.config())) };
return {
issues: issues.map((iss) => util.finalizeIssue(iss, {}, core.config())),
};
});
}
if (result.issues.length === 0) return { value: result.value } as any;
return { issues: result.issues.map((iss) => util.finalizeIssue(iss, {}, core.config())) };
return {
issues: result.issues.map((iss) => util.finalizeIssue(iss, {}, core.config())),
};
},
vendor: "zod",
version: 1 as const,
Expand Down Expand Up @@ -3154,7 +3158,9 @@ export const $ZodCatch: core.$constructor<$ZodCatch> = /*@__PURE__*/ core.$const
if (result.issues.length) {
payload.value = def.catchValue({
...payload,
error: { issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())) },
error: {
issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
},
input: payload.value,
});
payload.issues = [];
Expand All @@ -3168,7 +3174,9 @@ export const $ZodCatch: core.$constructor<$ZodCatch> = /*@__PURE__*/ core.$const
if (result.issues.length) {
payload.value = def.catchValue({
...payload,
error: { issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())) },
error: {
issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
},
input: payload.value,
});
payload.issues = [];
Expand Down Expand Up @@ -3568,7 +3576,6 @@ export type $ZodTypes =
| $ZodVoid
| $ZodArray
| $ZodObject
// | $ZodInterface
| $ZodUnion
| $ZodIntersection
| $ZodTuple
Expand Down
Loading