MCPcopy
hub / github.com/colinhacks/zod / handleCatchall

Function handleCatchall

packages/zod/src/v4/core/schemas.ts:1856–1901  ·  view source on GitHub ↗
(
  proms: Promise<any>[],
  input: any,
  payload: ParsePayload,
  ctx: ParseContext,
  def: ReturnType<typeof normalizeDef>,
  inst: $ZodObject
)

Source from the content-addressed store, hash-verified

1854}
1855
1856function handleCatchall(
1857 proms: Promise<any>[],
1858 input: any,
1859 payload: ParsePayload,
1860 ctx: ParseContext,
1861 def: ReturnType<typeof normalizeDef>,
1862 inst: $ZodObject
1863) {
1864 const unrecognized: string[] = [];
1865 const keySet = def.keySet;
1866 const _catchall = def.catchall!._zod;
1867 const t = _catchall.def.type;
1868 const isOptionalIn = _catchall.optin === "optional";
1869 const isOptionalOut = _catchall.optout === "optional";
1870 for (const key in input) {
1871 // skip __proto__ so it can't replace the result prototype via the
1872 // assignment setter on the plain {} we build into
1873 if (key === "__proto__") continue;
1874 if (keySet.has(key)) continue;
1875 if (t === "never") {
1876 unrecognized.push(key);
1877 continue;
1878 }
1879 const r = _catchall.run({ value: input[key], issues: [] }, ctx);
1880
1881 if (r instanceof Promise) {
1882 proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut)));
1883 } else {
1884 handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut);
1885 }
1886 }
1887
1888 if (unrecognized.length) {
1889 payload.issues.push({
1890 code: "unrecognized_keys",
1891 keys: unrecognized,
1892 input,
1893 inst,
1894 });
1895 }
1896
1897 if (!proms.length) return payload;
1898 return Promise.all(proms).then(() => {
1899 return payload;
1900 });
1901}
1902
1903export const $ZodObject: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$constructor("$ZodObject", (inst, def) => {
1904 // requires cast because technically $ZodObject doesn't extend

Callers 1

schemas.tsFile · 0.85

Calls 3

handlePropertyResultFunction · 0.85
hasMethod · 0.80
runMethod · 0.65

Tested by

no test coverage detected