{"version":3,"file":"platform-serialize-DkiTdHOt.mjs","names":[],"sources":["../src/utils/test/platform-serialize.ts"],"sourcesContent":["/**\n * Validate and serialize a value as it would cross the Platform JSON boundary.\n *\n * Mirrors the runtime checks the platform performs on workflow arguments,\n * wait payloads, and trigger inputs so that local tests fail in the same\n * places production fails.\n *\n * Throws on:\n * - `NaN` / `Infinity` / `-Infinity` (`JSON.stringify` would silently emit `null`)\n * - `BigInt` (TypeError is thrown by `JSON.stringify`; we emit a clearer message)\n * - Non-plain objects (class instances, including `Date`, `Map`, `Set`, `Error`,\n *   and user-defined DTOs whose prototype is not `Object.prototype`)\n *\n * The replacer reads `this[key]` so the check sees the original value before\n * any `toJSON` conversion (e.g. `Date.prototype.toJSON`).\n * @param value - Value to validate and round-trip\n * @returns The JSON-normalized value (undefined/function properties stripped, etc.)\n */\nexport function platformSerialize<T>(value: T): T {\n  // Top-level undefined is allowed (jobs may take no input).\n  if (value === undefined) return undefined as T;\n\n  // Root function/symbol stringify to `undefined`; throw a specific message here.\n  if (typeof value === \"function\") {\n    throw new TypeError(\"platformSerialize: function is not JSON-serializable at <root>\");\n  }\n  if (typeof value === \"symbol\") {\n    throw new TypeError(\"platformSerialize: Symbol is not JSON-serializable at <root>\");\n  }\n\n  const serialized = JSON.stringify(value, function (key, val) {\n    if (typeof val === \"number\" && !Number.isFinite(val)) {\n      throw new TypeError(\n        `platformSerialize: non-finite number at ${formatPath(key)}: ${String(val)}`,\n      );\n    }\n    if (typeof val === \"bigint\") {\n      throw new TypeError(\n        `platformSerialize: BigInt is not JSON-serializable at ${formatPath(key)}`,\n      );\n    }\n    // Look at the pre-toJSON value so Date/Map/Set/etc. can be detected.\n    const raw = (this as Record<string, unknown>)[key];\n    if (raw !== null && typeof raw === \"object\" && !Array.isArray(raw)) {\n      const proto = Object.getPrototypeOf(raw);\n      if (proto !== Object.prototype && proto !== null) {\n        const ctor = (raw as { constructor?: { name?: string } }).constructor?.name ?? \"anonymous\";\n        throw new TypeError(\n          `platformSerialize: non-plain object at ${formatPath(key)} (${ctor} instance)`,\n        );\n      }\n    }\n    return val;\n  });\n\n  // `JSON.stringify` returns `undefined` when the root collapses (e.g. a `toJSON`\n  // returning `undefined`); parsing that would throw opaquely.\n  // JSON.stringify returns undefined for non-serializable values\n  // oxlint-disable-next-line typescript/no-unnecessary-condition\n  if (serialized === undefined) {\n    throw new TypeError(\"platformSerialize: value is not JSON-serializable at <root>\");\n  }\n\n  return JSON.parse(serialized) as T;\n}\n\nfunction formatPath(key: string): string {\n  return key === \"\" ? \"<root>\" : `\"${key}\"`;\n}\n"],"mappings":"AAkBA,SAAgB,kBAAqB,EAAa,CAEhD,GAAI,IAAU,IAAA,GAAW,OAGzB,GAAI,OAAO,GAAU,WACnB,MAAU,UAAU,gEAAgE,EAEtF,GAAI,OAAO,GAAU,SACnB,MAAU,UAAU,8DAA8D,EAGpF,IAAM,EAAa,KAAK,UAAU,EAAO,SAAU,EAAK,EAAK,CAC3D,GAAI,OAAO,GAAQ,UAAY,CAAC,OAAO,SAAS,CAAG,EACjD,MAAU,UACR,2CAA2C,WAAW,CAAG,EAAE,IAAI,OAAO,CAAG,GAC3E,EAEF,GAAI,OAAO,GAAQ,SACjB,MAAU,UACR,yDAAyD,WAAW,CAAG,GACzE,EAGF,IAAM,EAAO,KAAiC,GAC9C,GAAoB,OAAO,GAAQ,UAA/B,GAA2C,CAAC,MAAM,QAAQ,CAAG,EAAG,CAClE,IAAM,EAAQ,OAAO,eAAe,CAAG,EACvC,GAAI,IAAU,OAAO,WAAa,IAAU,KAAM,CAChD,IAAM,EAAQ,EAA4C,aAAa,MAAQ,YAC/E,MAAU,UACR,0CAA0C,WAAW,CAAG,EAAE,IAAI,EAAK,WACrE,CACF,CACF,CACA,OAAO,CACT,CAAC,EAMD,GAAI,IAAe,IAAA,GACjB,MAAU,UAAU,6DAA6D,EAGnF,OAAO,KAAK,MAAM,CAAU,CAC9B,CAEA,SAAS,WAAW,EAAqB,CACvC,OAAO,IAAQ,GAAK,SAAW,IAAI,EAAI,EACzC"}