@brickkit/cli 0.14.0 → 0.16.0-beta.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.
Files changed (89) hide show
  1. package/dashboard-dist/{CollapsiblePanel-CbUysOp5.js → CollapsiblePanel-DvJpFahB.js} +2 -2
  2. package/dashboard-dist/Geist-Variable.woff2 +0 -0
  3. package/dashboard-dist/GeistMono-Variable.woff2 +0 -0
  4. package/dashboard-dist/{api-reference-lLhahVJi.js → api-reference-C2_JX174.js} +82 -70
  5. package/dashboard-dist/app.css +2 -2
  6. package/dashboard-dist/app.js +5 -5
  7. package/dashboard-dist/{client-DRtkFydB.js → client-DsITZplk.js} +1 -1
  8. package/dashboard-dist/{core-BSTqZqMg.js → core-sW89OSz5.js} +1 -1
  9. package/dashboard-dist/docs-D3U7gUWq.js +4 -0
  10. package/dashboard-dist/kit.js +1 -1
  11. package/dashboard-dist/{popover-CKxhB1QI.js → popover-Bb2Q3jiK.js} +1 -1
  12. package/dist/bin.d.ts +1 -2
  13. package/dist/bin.js +6 -6
  14. package/dist/bin.js.map +1 -1
  15. package/dist/build.js +5 -1
  16. package/dist/build.js.map +1 -1
  17. package/dist/client-contract-file.js +3 -2
  18. package/dist/client-contract-file.js.map +1 -1
  19. package/dist/compiler.d.ts +1 -2
  20. package/dist/config2.d.ts +1 -2
  21. package/dist/dashboard-extension.d.ts +1 -2
  22. package/dist/dashboard-host.js +26 -7
  23. package/dist/dashboard-host.js.map +1 -1
  24. package/dist/dashboard.d.ts +4 -4
  25. package/dist/definitions.js +1 -0
  26. package/dist/definitions.js.map +1 -1
  27. package/dist/dev-application.js.map +1 -1
  28. package/dist/dev-reporter.d.ts +1 -2
  29. package/dist/dev-reporter.js.map +1 -1
  30. package/dist/dev-telemetry.js.map +1 -1
  31. package/dist/dev-worker.js.map +1 -1
  32. package/dist/index.d.ts +1 -2
  33. package/dist/lint/oxlint.d.ts +1 -2
  34. package/dist/plugin.d.ts +1 -2
  35. package/dist/production-dashboard2.d.ts +1 -2
  36. package/dist/project.js +35 -12
  37. package/dist/project.js.map +1 -1
  38. package/dist/serve.d.ts +1 -2
  39. package/dist/serve2.js.map +1 -1
  40. package/dist/vite.d.ts +1 -2
  41. package/dist/vite.js +2 -1
  42. package/dist/vite.js.map +1 -1
  43. package/dist/workflows.d.ts +1 -2
  44. package/inspector-dist/client/assets/app-Wfnqu2Ic.css +4610 -0
  45. package/inspector-dist/client/assets/{dist-BK8w6xOr.js → dist-CEyPxAJU.js} +2008 -334
  46. package/inspector-dist/client/assets/{entry.client-D9jbgmTR.js → entry.client-Cszf0uLP.js} +4628 -2593
  47. package/inspector-dist/client/assets/highlighted-body-JLMTFACH-CgFt8UnP.js +41 -0
  48. package/inspector-dist/client/assets/{home-hwPlkNhv.js → home-B2m1nnIz.js} +191 -105
  49. package/inspector-dist/client/assets/{jsx-runtime-CPEah4WQ.js → jsx-runtime-DRYYXgdJ.js} +2946 -2001
  50. package/inspector-dist/client/assets/{manifest-0e76e9ac.js → manifest-cfc09adc.js} +1 -1
  51. package/inspector-dist/client/assets/mermaid-WFAXDIZX-BoRESrqm.js +1 -0
  52. package/inspector-dist/client/assets/root-CVescmwt.css +4544 -0
  53. package/inspector-dist/client/assets/{root-SLeEf-sT.js → root-CVhM1JOR.js} +3 -3
  54. package/inspector-dist/client/assets/{run-detail-DYbVkIFH.js → run-detail-BdV01jxD.js} +90 -50
  55. package/inspector-dist/client/assets/tabs-BVrPbzfI.css +66 -0
  56. package/inspector-dist/client/assets/{tabs-CaJisoyb.js → tabs-C2hdi5D4.js} +12496 -8708
  57. package/inspector-dist/client/assets/{zstd-browser-decoder-D94wmfAU.js → zstd-browser-decoder-DQWDmc2d.js} +2 -2
  58. package/inspector-dist/server/assets/{app-DGlfWVUI.js → app-w0nTXgJd.js} +51489 -51478
  59. package/inspector-dist/server/assets/{chunk-RLXIAIE6-F0SJZlei.js → chunk-7TTQLYRW-BO6_qAAU.js} +10986 -7848
  60. package/inspector-dist/server/assets/cjs-DPK66Gxq.js +3600 -0
  61. package/inspector-dist/server/assets/{dist-BCbwm6jl.js → dist-DTHqO9VA.js} +149 -1619
  62. package/inspector-dist/server/assets/{dist-Ce0I2PUv.js → dist-OLuKLJ4s.js} +8 -8
  63. package/inspector-dist/server/assets/{encryption-DdQgC8Rk.js → encryption-DMo4uOFN.js} +5 -5
  64. package/inspector-dist/server/assets/{event-metadata-n7E4zEmT.js → event-metadata-Bx8Ts484.js} +1 -1
  65. package/inspector-dist/server/assets/functions-B9XwHSzK.js +6972 -0
  66. package/inspector-dist/server/assets/{global-singleton-D8sIN5du.js → global-singleton-rNtXNHKV.js} +1 -1
  67. package/inspector-dist/server/assets/highlighted-body-JLMTFACH-B0HDNeQE.js +41 -0
  68. package/inspector-dist/server/assets/mermaid-WFAXDIZX-B-AIJZhh.js +1 -0
  69. package/inspector-dist/server/assets/serialization-DsMds3lJ.js +5716 -0
  70. package/inspector-dist/server/assets/{serialization-format-BbuGfHog.js → serialization-format-B27jSUCM.js} +30 -9
  71. package/inspector-dist/server/assets/state-resolver-DVs_zsEO.js +1422 -0
  72. package/inspector-dist/server/assets/{token-BgMmJNP5.js → token-CvvD8Y5H.js} +1 -1
  73. package/inspector-dist/server/assets/token-CxjWFNNq.js +63 -0
  74. package/inspector-dist/server/assets/token-util-D9IsWeEs.js +3 -0
  75. package/inspector-dist/server/assets/{wrapper-CIC3w0oC.js → wrapper-B_u9Z5Up.js} +58 -26
  76. package/inspector-dist/server/assets/{ws-transport-CxTYB11n.js → ws-transport-CamzQ5O8.js} +24379 -24240
  77. package/inspector-dist/server/assets/{zstd-browser-decoder-D7bCXbGg.js → zstd-browser-decoder-DlGbqUuc.js} +2 -2
  78. package/inspector-dist/server/index.js +1 -1
  79. package/package.json +21 -21
  80. package/dashboard-dist/docs-Cye2p0fM.js +0 -4
  81. package/inspector-dist/client/assets/app-CeSwVsRm.css +0 -2
  82. package/inspector-dist/client/assets/highlighted-body-B3W2YXNL-CfRnuITN.js +0 -34
  83. package/inspector-dist/client/assets/mermaid-3ZIDBTTL-ZDR2PNY_.js +0 -1
  84. package/inspector-dist/client/assets/root-ChBNTZd2.css +0 -2
  85. package/inspector-dist/client/assets/tabs-L5XKzOpP.css +0 -1
  86. package/inspector-dist/server/assets/functions-CNVQtbgg.js +0 -1170
  87. package/inspector-dist/server/assets/highlighted-body-B3W2YXNL-CWRzMxYD.js +0 -34
  88. package/inspector-dist/server/assets/mermaid-3ZIDBTTL-D0v0ngVr.js +0 -1
  89. package/inspector-dist/server/assets/parse-Begau9cA.js +0 -469
@@ -1,5 +1,5 @@
1
1
  import { r as __exportAll } from "./rolldown-runtime-C1I3wEg2.js";
2
- import { i as getEventDataRefFields } from "./event-metadata-n7E4zEmT.js";
2
+ import { i as getEventDataRefFields } from "./event-metadata-Bx8Ts484.js";
3
3
  import crypto from "node:crypto";
4
4
  // ../../node_modules/.bun/zod@4.6.7/node_modules/zod/v4/core/util.js
5
5
  function getEnumValues(entries) {
@@ -3491,1490 +3491,6 @@ function registry() {
3491
3491
  }
3492
3492
  (_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
3493
3493
  var globalRegistry = globalThis.__zod_globalRegistry;
3494
- // ../../node_modules/.bun/zod@4.6.7/node_modules/zod/v4/core/compile.js
3495
- /** @internal Sentinel the compiled fast path returns when validation fails. */
3496
- var INVALID = Symbol.for("zod.compile.invalid");
3497
- var FALLBACK_FLAG = Symbol.for("zod.compile.fallback");
3498
- /** Raised when the schema contains async refinements or transforms. Surfaces only under `compile(schema, { strict: true })`. */
3499
- var ZodCompileAsyncError = class extends Error {
3500
- constructor(message = "z.compile does not support async refinements, transforms, or checks") {
3501
- super(message);
3502
- this.name = "ZodCompileAsyncError";
3503
- }
3504
- };
3505
- /**
3506
- * Raised when the schema contains a feature whose semantics the fast path
3507
- * can't fully model. Both the shim in `zod/compile` and the default
3508
- * `compile()` fall back to the runtime parser for that schema; only
3509
- * `compile(schema, { strict: true })` lets it surface.
3510
- */
3511
- var ZodCompileUnsupportedError = class extends Error {
3512
- constructor(feature, islandable = true) {
3513
- super(`z.compile does not support ${feature}; this schema must use the runtime parser`);
3514
- this.name = "ZodCompileUnsupportedError";
3515
- this.islandable = islandable;
3516
- }
3517
- };
3518
- /**
3519
- * Build the validator `validate` calls: the same codegen as the parser with the output construction
3520
- * dropped. A schema the flag cannot express reuses the parser, which still answers correctly — it
3521
- * just builds a value nothing reads.
3522
- */
3523
- function compileValidator(schema, parser) {
3524
- try {
3525
- return compileFn(schema, { assertOnly: true });
3526
- } catch {
3527
- return parser;
3528
- }
3529
- }
3530
- /**
3531
- * AOT-compile a Zod schema. Returns a clone whose `_zod.run` calls a generated
3532
- * fast path first and falls back to the original runtime parser on failure.
3533
- *
3534
- * - Forward direction only. Backward (encode), async, and `skipChecks` paths
3535
- * bypass the fast path and use the runtime directly.
3536
- * - Never throws. A schema the fast path can't model is returned unchanged and
3537
- * keeps using the runtime parser. Pass `{ strict: true }` to get the refusal
3538
- * as a thrown `ZodCompileUnsupportedError` / `ZodCompileAsyncError` instead.
3539
- * - The original schema is unchanged. The clone shares children by reference.
3540
- */
3541
- function compile(schema, options) {
3542
- try {
3543
- const parser = compileFn(schema);
3544
- const clone = withParser(schema, parser);
3545
- clone._zod.bag.validator = compileValidator(schema, parser);
3546
- return clone;
3547
- } catch (err) {
3548
- if (options?.strict) throw err;
3549
- return schema;
3550
- }
3551
- }
3552
- /**
3553
- * Install an already-generated parser as a schema's fast path. Returns a clone; the original is
3554
- * unchanged.
3555
- *
3556
- * The parser takes the input and returns the parsed value, or `INVALID` to hand the parse to the
3557
- * runtime. It must be synchronous and forward-direction, and it must build fresh output rather than
3558
- * return its input — Zod cannot check either, and a wrong *success* is returned to the caller as-is.
3559
- *
3560
- * `compile()` is the ordinary entry point. This is for a build-time or native compiler that produces
3561
- * a parser where `new Function` is unavailable.
3562
- */
3563
- function withParser(schema, parser) {
3564
- if (isRecursiveSchema(schema)) throw new ZodCompileUnsupportedError("a schema whose subtree contains a reference cycle");
3565
- const clone$1 = clone(schema);
3566
- const liveRun = schema._zod.run;
3567
- const originalRun = liveRun.__originalRun ?? liveRun;
3568
- const wrapped = (payload, ctx) => {
3569
- if (ctx?.async || ctx?.direction === "backward" || ctx?.skipChecks || ctx?.[FALLBACK_FLAG]) return originalRun(payload, ctx);
3570
- if (ctx && isBackEdge(ctx, payload.value)) return originalRun(payload, ctx);
3571
- const out = parser(payload.value);
3572
- if (out !== INVALID) {
3573
- payload.value = out;
3574
- return payload;
3575
- }
3576
- if (ctx) ctx[FALLBACK_FLAG] = true;
3577
- return originalRun(payload, ctx);
3578
- };
3579
- wrapped.__originalRun = originalRun;
3580
- clone$1._zod.bag.fallbackRun = originalRun;
3581
- clone$1._zod.bag.validator = parser;
3582
- clone$1._zod.run = wrapped;
3583
- if (!liveRun.__originalRun) installCompiledUserMethods(clone$1, schema, parser);
3584
- return clone$1;
3585
- }
3586
- function installCompiledUserMethods(target, source, parser) {
3587
- const targetAny = target;
3588
- const sourceAny = source;
3589
- if (typeof sourceAny.safeParse === "function") {
3590
- const originalSafeParse = sourceAny.safeParse;
3591
- targetAny.safeParse = (data, params) => {
3592
- const out = parser(data);
3593
- if (out !== INVALID) return {
3594
- success: true,
3595
- data: out
3596
- };
3597
- return originalSafeParse(data, params);
3598
- };
3599
- }
3600
- if (typeof sourceAny.parse === "function") {
3601
- const originalParse = sourceAny.parse;
3602
- targetAny.parse = (data, params) => {
3603
- const out = parser(data);
3604
- if (out !== INVALID) return out;
3605
- return originalParse(data, params);
3606
- };
3607
- }
3608
- }
3609
- /**
3610
- * @internal Generate the standalone compiled function: a parser by default, a validator under
3611
- * `assertOnly`. Returns the parsed value, `true` where nothing reads the output, or `INVALID`. Consumers use `compile()`.
3612
- */
3613
- function compileFn(schema, options) {
3614
- let recursive = true;
3615
- try {
3616
- recursive = isRecursiveSchema(schema);
3617
- } catch {}
3618
- if (recursive) throw new ZodCompileUnsupportedError("a schema whose subtree contains a reference cycle");
3619
- const ctx = {
3620
- constants: /* @__PURE__ */ new Map(),
3621
- constantCounter: 0,
3622
- varCounter: 0,
3623
- definite: true
3624
- };
3625
- const doc = new Doc(["input"]);
3626
- const outputAccessor = generateCheck(doc, ctx, schema, "input", !options?.assertOnly);
3627
- doc.write(outputAccessor === null ? `return true;` : `return ${outputAccessor};`);
3628
- const constantNames = ["INVALID", ...ctx.constants.keys()];
3629
- const constantValues = [INVALID, ...ctx.constants.values()];
3630
- const code = doc.content.join("\n");
3631
- const fullCode = options?.debug ? constantNames.length > 0 ? `// Constants: ${constantNames.join(", ")}\n${code}` : code : "";
3632
- const F = Function;
3633
- const factoryCode = `return (input) => {\n${code}\n}`;
3634
- let fn;
3635
- try {
3636
- fn = new F(...constantNames, factoryCode)(...constantValues);
3637
- } catch (err) {
3638
- throw new ZodCompileUnsupportedError(`this schema (generated code failed to evaluate: ${err.message})`);
3639
- }
3640
- if (options?.debug) fn.code = fullCode;
3641
- fn.definite = ctx.definite;
3642
- return fn;
3643
- }
3644
- function addConstant(ctx, value) {
3645
- for (const [name, v] of ctx.constants) if (v === value) return name;
3646
- const name = `c${ctx.constantCounter++}`;
3647
- ctx.constants.set(name, value);
3648
- return name;
3649
- }
3650
- /** Hoists a user-supplied callback. Anything the schema's author wrote can throw, and generated code can reject an earlier sibling before ever reaching it, so this clears `definite` — a rejection is then no longer proof that the interpreter would have rejected rather than thrown. */
3651
- function addUserConstant(ctx, fn) {
3652
- ctx.definite = false;
3653
- return addConstant(ctx, fn);
3654
- }
3655
- function newVar(ctx) {
3656
- return `v${ctx.varCounter++}`;
3657
- }
3658
- function runtimeRun(schema, value) {
3659
- const result = schema._zod.run({
3660
- value,
3661
- issues: []
3662
- }, {});
3663
- if (result && typeof result.then === "function") return INVALID;
3664
- const r = result;
3665
- return r.issues.length === 0 ? r.value : INVALID;
3666
- }
3667
- function compileChild(doc, ctx, schema, accessor, needsValue = true) {
3668
- const contentLen = doc.content.length;
3669
- const constantCount = ctx.constants.size;
3670
- const constantCounter = ctx.constantCounter;
3671
- const varCounter = ctx.varCounter;
3672
- try {
3673
- return generateCheck(doc, ctx, schema, accessor, needsValue);
3674
- } catch (err) {
3675
- if (!(err instanceof ZodCompileUnsupportedError) || !err.islandable) throw err;
3676
- doc.content.length = contentLen;
3677
- if (ctx.constants.size > constantCount) {
3678
- const trailing = Array.from(ctx.constants.keys()).slice(constantCount);
3679
- for (const k of trailing) ctx.constants.delete(k);
3680
- }
3681
- ctx.constantCounter = constantCounter;
3682
- ctx.varCounter = varCounter;
3683
- return emitRuntimeIsland(doc, ctx, schema, accessor);
3684
- }
3685
- }
3686
- function emitRuntimeIsland(doc, ctx, schema, accessor) {
3687
- ctx.definite = false;
3688
- const schemaConst = addConstant(ctx, schema);
3689
- const runConst = addConstant(ctx, runtimeRun);
3690
- const outVar = newVar(ctx);
3691
- doc.write(`const ${outVar} = ${runConst}(${schemaConst}, ${accessor});`);
3692
- doc.write(`if (${outVar} === INVALID) return INVALID;`);
3693
- return outVar;
3694
- }
3695
- var WHEN_DEFAULTED_CHECKS = /* @__PURE__ */ new Set([
3696
- "max_size",
3697
- "min_size",
3698
- "size_equals",
3699
- "max_length",
3700
- "min_length",
3701
- "length_equals"
3702
- ]);
3703
- function generateChecks(doc, ctx, schema, accessor) {
3704
- const schemaChecks = schema._zod.def.checks;
3705
- if (!schemaChecks || schemaChecks.length === 0) return accessor;
3706
- let currentAccessor = accessor;
3707
- for (const check of schemaChecks) {
3708
- const def = check._zod.def;
3709
- if (def.when && !WHEN_DEFAULTED_CHECKS.has(def.check)) throw new ZodCompileUnsupportedError(`check with a custom "when" condition`);
3710
- switch (def.check) {
3711
- case "greater_than":
3712
- generateGreaterThanCheck(doc, ctx, def, currentAccessor);
3713
- break;
3714
- case "less_than":
3715
- generateLessThanCheck(doc, ctx, def, currentAccessor);
3716
- break;
3717
- case "multiple_of":
3718
- generateMultipleOfCheck(doc, ctx, def, currentAccessor);
3719
- break;
3720
- case "number_format":
3721
- generateNumberFormatCheck(doc, def, currentAccessor);
3722
- break;
3723
- case "min_length": {
3724
- const min = numericOperand(def.minimum, "min_length");
3725
- const len = codePointLengthVar(doc, ctx, currentAccessor, `${currentAccessor}.length >= ${min} && ${currentAccessor}.length < ${def.minimum * 2}`);
3726
- doc.write(`if (${len} < ${min}) return INVALID;`);
3727
- break;
3728
- }
3729
- case "max_length": {
3730
- const max = numericOperand(def.maximum, "max_length");
3731
- const len = codePointLengthVar(doc, ctx, currentAccessor, `${currentAccessor}.length > ${max}`);
3732
- doc.write(`if (${len} > ${max}) return INVALID;`);
3733
- break;
3734
- }
3735
- case "length_equals": {
3736
- const exact = numericOperand(def.length, "length_equals");
3737
- const len = codePointLengthVar(doc, ctx, currentAccessor, `${currentAccessor}.length >= ${exact} && ${currentAccessor}.length <= ${def.length * 2}`);
3738
- doc.write(`if (${len} !== ${exact}) return INVALID;`);
3739
- break;
3740
- }
3741
- case "min_size":
3742
- doc.write(`if (${currentAccessor}.size < ${numericOperand(def.minimum, "min_size")}) return INVALID;`);
3743
- break;
3744
- case "max_size":
3745
- doc.write(`if (${currentAccessor}.size > ${numericOperand(def.maximum, "max_size")}) return INVALID;`);
3746
- break;
3747
- case "size_equals":
3748
- doc.write(`if (${currentAccessor}.size !== ${numericOperand(def.size, "size_equals")}) return INVALID;`);
3749
- break;
3750
- case "string_format":
3751
- currentAccessor = generateStringFormatCheck(doc, ctx, def, currentAccessor);
3752
- break;
3753
- case "custom":
3754
- currentAccessor = generateCustomRefineCheck(doc, ctx, check, currentAccessor);
3755
- break;
3756
- case "bigint_format":
3757
- generateBigIntFormatCheck(doc, def, currentAccessor);
3758
- break;
3759
- case "mime_type":
3760
- generateMimeTypeCheck(doc, ctx, def, currentAccessor);
3761
- break;
3762
- case "property":
3763
- generatePropertyCheck(doc, ctx, def, currentAccessor);
3764
- break;
3765
- case "properties":
3766
- generatePropertiesChecks(doc, ctx, def, currentAccessor);
3767
- break;
3768
- case "overwrite": {
3769
- const newAccessor = newVar(ctx);
3770
- generateOverwriteCheck(doc, ctx, check, currentAccessor, newAccessor);
3771
- currentAccessor = newAccessor;
3772
- break;
3773
- }
3774
- default: throw new ZodCompileUnsupportedError(`check type ${def.check}`);
3775
- }
3776
- }
3777
- return currentAccessor;
3778
- }
3779
- function codePointLengthVar(doc, ctx, accessor, inDoubt) {
3780
- const cpLen = addConstant(ctx, codePointLength);
3781
- const v = newVar(ctx);
3782
- doc.write(`const ${v} = typeof ${accessor} === "string" && ${inDoubt} ? ${cpLen}(${accessor}) : ${accessor}.length;`);
3783
- return v;
3784
- }
3785
- /**
3786
- * A count bound reaches generated source verbatim, so a non-number would be
3787
- * emitted as code rather than as a value — `min('0) {} evil(); if (0')` writes an
3788
- * arbitrary statement into the function body. TypeScript types these as `number`
3789
- * and fromJSONSchema guards them, so this is a backstop rather than a live hole,
3790
- * but generated source is the one place a wrong type stops being a type error.
3791
- */
3792
- function numericOperand(value, label) {
3793
- if (typeof value !== "number" || !Number.isFinite(value)) throw new ZodCompileUnsupportedError(`${label} bound of type ${typeof value}`);
3794
- return `${value}`;
3795
- }
3796
- function comparisonOperand(ctx, value) {
3797
- if (typeof value === "bigint") return `${value}n`;
3798
- if (typeof value === "number") {
3799
- if (Number.isNaN(value)) throw new ZodCompileUnsupportedError("comparison check with NaN bound");
3800
- return `${value}`;
3801
- }
3802
- if (value instanceof Date) {
3803
- if (Number.isNaN(value.getTime())) throw new ZodCompileUnsupportedError("comparison check with Invalid Date bound");
3804
- return addConstant(ctx, value);
3805
- }
3806
- throw new ZodCompileUnsupportedError(`comparison check bound of type ${typeof value}`);
3807
- }
3808
- function generateGreaterThanCheck(doc, ctx, def, accessor) {
3809
- const op = def.inclusive ? "<" : "<=";
3810
- doc.write(`if (${accessor} ${op} ${comparisonOperand(ctx, def.value)}) return INVALID;`);
3811
- }
3812
- function generateLessThanCheck(doc, ctx, def, accessor) {
3813
- const op = def.inclusive ? ">" : ">=";
3814
- doc.write(`if (${accessor} ${op} ${comparisonOperand(ctx, def.value)}) return INVALID;`);
3815
- }
3816
- function generateMultipleOfCheck(doc, ctx, def, accessor) {
3817
- if (typeof def.value === "bigint") {
3818
- if (def.value === BigInt(0)) throw new ZodCompileUnsupportedError("multiple_of check with a zero divisor");
3819
- doc.write(`if (${accessor} % ${def.value}n !== 0n) return INVALID;`);
3820
- } else {
3821
- const remainder = addConstant(ctx, floatSafeRemainder);
3822
- doc.write(`if (${remainder}(${accessor}, ${numericOperand(def.value, "multiple_of")}) !== 0) return INVALID;`);
3823
- }
3824
- }
3825
- function generateNumberFormatCheck(doc, def, accessor) {
3826
- const format = def.format;
3827
- switch (format) {
3828
- case "safeint":
3829
- doc.write(`if (!Number.isSafeInteger(${accessor})) return INVALID;`);
3830
- break;
3831
- case "int32":
3832
- doc.write(`if (!Number.isInteger(${accessor}) || ${accessor} < -2147483648 || ${accessor} > 2147483647) return INVALID;`);
3833
- break;
3834
- case "uint32":
3835
- doc.write(`if (!Number.isInteger(${accessor}) || ${accessor} < 0 || ${accessor} > 4294967295) return INVALID;`);
3836
- break;
3837
- case "float32":
3838
- doc.write(`if (!Number.isFinite(${accessor}) || ${accessor} < -3.4028234663852886e38 || ${accessor} > 3.4028234663852886e38) return INVALID;`);
3839
- break;
3840
- case "float64":
3841
- doc.write(`if (!Number.isFinite(${accessor})) return INVALID;`);
3842
- break;
3843
- default: throw new ZodCompileUnsupportedError(`number format ${format}`);
3844
- }
3845
- }
3846
- function generateBigIntFormatCheck(doc, def, accessor) {
3847
- const format = def.format;
3848
- if (!format) return;
3849
- switch (format) {
3850
- case "int64":
3851
- doc.write(`if (${accessor} < -9223372036854775808n || ${accessor} > 9223372036854775807n) return INVALID;`);
3852
- break;
3853
- case "uint64":
3854
- doc.write(`if (${accessor} < 0n || ${accessor} > 18446744073709551615n) return INVALID;`);
3855
- break;
3856
- default: throw new ZodCompileUnsupportedError(`bigint format ${format}`);
3857
- }
3858
- }
3859
- function generateMimeTypeCheck(doc, ctx, def, accessor) {
3860
- const mimeTypes = def.mime;
3861
- if (mimeTypes && mimeTypes.length > 0) {
3862
- const mimeSet = addConstant(ctx, new Set(mimeTypes));
3863
- doc.write(`if (!${mimeSet}.has(${accessor}.type)) return INVALID;`);
3864
- }
3865
- }
3866
- function generatePropertiesChecks(doc, ctx, def, accessor) {
3867
- if (def.when) throw new ZodCompileUnsupportedError(`check with a custom "when" condition`);
3868
- doc.write(`if (${accessor} == null) return INVALID;`);
3869
- const shape = def.shape;
3870
- for (const key of Reflect.ownKeys(shape)) {
3871
- const keyExpr = typeof key === "symbol" ? addConstant(ctx, key) : esc(key);
3872
- const inputVar = newVar(ctx);
3873
- doc.write(`const ${inputVar} = ${accessor}[${keyExpr}];`);
3874
- compileChild(doc, ctx, shape[key], inputVar, false);
3875
- }
3876
- }
3877
- function generatePropertyCheck(doc, ctx, def, accessor) {
3878
- const propAccessor = `${accessor}[${JSON.stringify(def.property)}]`;
3879
- generateCheck(doc, ctx, def.schema, propAccessor);
3880
- }
3881
- function generateOverwriteCheck(doc, ctx, check, currentAccessor, newAccessor) {
3882
- const tx = check._zod.def.tx;
3883
- if (!tx) throw new ZodCompileUnsupportedError("overwrite check without a transform function");
3884
- if (isAsyncFunction(tx)) throw new ZodCompileAsyncError("z.compile: async overwrite transforms are not supported");
3885
- const txConst = addConstant(ctx, tx);
3886
- doc.write(`const ${newAccessor} = ${txConst}(${currentAccessor});`);
3887
- }
3888
- /** A predicate that hands back a thenable is an async check reached synchronously, and the interpreter throws `$ZodAsyncError` for it. Returning INVALID instead would be a bail-out, and a union reads a bail-out as a rejected branch and answers with a later one — so the throw has to survive into generated code. */
3889
- function throwAsync() {
3890
- throw new $ZodAsyncError();
3891
- }
3892
- /** Shared `addIssue` for the spoofed payloads a refine, check or transform receives. Allocating one per call — a fresh closure plus a `this`-bound method on a fresh literal — pinned every payload-allocating schema at ~2.7M ops/sec against 135M for a plain object literal. It captures nothing per call; it only reaches `this.issues`. */
3893
- function pushIssue(issue) {
3894
- this.issues.push(issue);
3895
- }
3896
- function generateCustomRefineCheck(doc, ctx, check, accessor) {
3897
- const def = check._zod.def;
3898
- if (def.fn) {
3899
- if (isAsyncFunction(def.fn)) throw new ZodCompileAsyncError("z.compile: async .refine() predicates are not supported");
3900
- const fnConst = addUserConstant(ctx, def.fn);
3901
- const throwAsyncConst = addConstant(ctx, throwAsync);
3902
- const resVar = newVar(ctx);
3903
- doc.write(`const ${resVar} = ${fnConst}(${accessor});`);
3904
- doc.write(`if (${resVar} instanceof Promise) ${throwAsyncConst}();`);
3905
- doc.write(`if (!${resVar}) return INVALID;`);
3906
- return accessor;
3907
- }
3908
- if (check._zod.check) {
3909
- if (isAsyncFunction(check._zod.check)) throw new ZodCompileAsyncError("z.compile: async .superRefine() / check functions are not supported");
3910
- const checkFn = check._zod.check;
3911
- const helperFn = (value) => {
3912
- const fakePayload = {
3913
- value,
3914
- issues: [],
3915
- addIssue: pushIssue
3916
- };
3917
- if (checkFn(fakePayload) instanceof Promise) throwAsync();
3918
- return fakePayload.issues.length === 0 ? fakePayload.value : INVALID;
3919
- };
3920
- const helperConst = addUserConstant(ctx, helperFn);
3921
- const outVar = newVar(ctx);
3922
- doc.write(`const ${outVar} = ${helperConst}(${accessor});`);
3923
- doc.write(`if (${outVar} === INVALID) return INVALID;`);
3924
- return outVar;
3925
- }
3926
- throw new ZodCompileUnsupportedError("custom check without a predicate or check function");
3927
- }
3928
- /**
3929
- * Built-in formats that validate with nothing but `def.pattern`, so compiling
3930
- * the regex reproduces the runtime exactly. Deliberately an allowlist: a format
3931
- * missing from it loses its fast path, while a format wrongly added to it
3932
- * silently accepts input the runtime rejects. Formats that layer extra
3933
- * validation over a shape-only pattern (`credit_card`, `base64`, `ipv6`, …) are
3934
- * handled above by hoisting the runtime validator itself.
3935
- */
3936
- var PATTERN_IS_COMPLETE = /* @__PURE__ */ new Set([
3937
- "cidrv4",
3938
- "cuid",
3939
- "cuid2",
3940
- "date",
3941
- "datetime",
3942
- "duration",
3943
- "e164",
3944
- "email",
3945
- "emoji",
3946
- "ends_with",
3947
- "guid",
3948
- "includes",
3949
- "ipv4",
3950
- "ksuid",
3951
- "lowercase",
3952
- "mac",
3953
- "nanoid",
3954
- "regex",
3955
- "starts_with",
3956
- "time",
3957
- "ulid",
3958
- "uppercase",
3959
- "uuid",
3960
- "xid"
3961
- ]);
3962
- function generateStringFormatCheck(doc, ctx, def, accessor, needsValue = true) {
3963
- const fmt = def.format;
3964
- if (fmt === "base64") {
3965
- const validator = addConstant(ctx, isValidBase64);
3966
- doc.write(`if (!${validator}(${accessor})) return INVALID;`);
3967
- return accessor;
3968
- }
3969
- if (fmt === "base64url") {
3970
- const validator = addConstant(ctx, isValidBase64URL);
3971
- doc.write(`if (!${validator}(${accessor})) return INVALID;`);
3972
- return accessor;
3973
- }
3974
- if (fmt === "jwt") {
3975
- const validator = addConstant(ctx, isValidJWT);
3976
- const alg = addConstant(ctx, def.alg ?? null);
3977
- doc.write(`if (!${validator}(${accessor}, ${alg})) return INVALID;`);
3978
- return accessor;
3979
- }
3980
- if (fmt === "ipv6") {
3981
- const validator = addConstant(ctx, isValidIPv6);
3982
- doc.write(`if (!${validator}(${accessor})) return INVALID;`);
3983
- return accessor;
3984
- }
3985
- if (fmt === "cidrv6") {
3986
- const validator = addConstant(ctx, isValidCIDRv6);
3987
- doc.write(`if (!${validator}(${accessor})) return INVALID;`);
3988
- return accessor;
3989
- }
3990
- if (fmt === "credit_card") {
3991
- const validator = addConstant(ctx, isValidCreditCard);
3992
- doc.write(`if (!${validator}(${accessor})) return INVALID;`);
3993
- return accessor;
3994
- }
3995
- if (fmt === "iban") {
3996
- const validator = addConstant(ctx, isValidIBAN);
3997
- doc.write(`if (!${validator}(${accessor})) return INVALID;`);
3998
- return accessor;
3999
- }
4000
- const formatDef = def;
4001
- if (fmt === "url" || fmt === "httpurl" || formatDef.normalize || formatDef.hostname !== void 0 || formatDef.protocol !== void 0) {
4002
- const parseConst = addConstant(ctx, validateURL);
4003
- const defConst = addConstant(ctx, def);
4004
- const trimVar = newVar(ctx);
4005
- const urlVar = newVar(ctx);
4006
- doc.write(`const ${trimVar} = ${accessor}.trim();`);
4007
- doc.write(`const ${urlVar} = ${parseConst}(${trimVar}, ${defConst});`);
4008
- doc.write(`if (typeof ${urlVar} === "number") return INVALID;`);
4009
- if (formatDef.hostname !== void 0) {
4010
- const hostnameConst = addConstant(ctx, urlHostnameOk);
4011
- doc.write(`if (!${hostnameConst}(${urlVar}, ${defConst}.hostname)) return INVALID;`);
4012
- }
4013
- if (formatDef.protocol !== void 0) {
4014
- const protocolConst = addConstant(ctx, urlProtocolOk);
4015
- doc.write(`if (!${protocolConst}(${urlVar}, ${defConst}.protocol)) return INVALID;`);
4016
- }
4017
- if (!needsValue) return null;
4018
- const outputVar = newVar(ctx);
4019
- const outputExpr = formatDef.normalize ? `${urlVar}.href` : `${addConstant(ctx, stripTabAndNewline)}(${trimVar})`;
4020
- doc.write(`const ${outputVar} = ${outputExpr};`);
4021
- return outputVar;
4022
- }
4023
- const customFn = def.fn;
4024
- if (customFn) {
4025
- if (isAsyncFunction(customFn)) throw new ZodCompileUnsupportedError(`async string format ${fmt}`);
4026
- const fnConst = addConstant(ctx, customFn);
4027
- doc.write(`if (!${fnConst}(${accessor})) return INVALID;`);
4028
- return accessor;
4029
- }
4030
- if (PATTERN_IS_COMPLETE.has(fmt) && def.pattern) {
4031
- const patternConst = addConstant(ctx, def.pattern);
4032
- doc.write(`${patternConst}.lastIndex = 0;`);
4033
- doc.write(`if (!${patternConst}.test(${accessor})) return INVALID;`);
4034
- return accessor;
4035
- }
4036
- const format = def.format;
4037
- switch (format) {
4038
- case "regex": throw new ZodCompileUnsupportedError("regex format without a pattern");
4039
- case "lowercase":
4040
- doc.write(`if (${accessor} !== ${accessor}.toLowerCase()) return INVALID;`);
4041
- break;
4042
- case "uppercase":
4043
- doc.write(`if (${accessor} !== ${accessor}.toUpperCase()) return INVALID;`);
4044
- break;
4045
- case "includes":
4046
- doc.write(`if (!${accessor}.includes(${esc(def.includes)})) return INVALID;`);
4047
- break;
4048
- case "starts_with": {
4049
- const prefix = def.prefix;
4050
- doc.write(`if (${accessor}.slice(0, ${prefix.length}) !== ${esc(prefix)}) return INVALID;`);
4051
- break;
4052
- }
4053
- case "ends_with": {
4054
- const suffix = def.suffix;
4055
- doc.write(`if (${accessor}.slice(-${suffix.length}) !== ${esc(suffix)}) return INVALID;`);
4056
- break;
4057
- }
4058
- default: throw new ZodCompileUnsupportedError(`string format ${format}`);
4059
- }
4060
- return accessor;
4061
- }
4062
- function generateCheck(doc, ctx, schema, accessor, needsValue = true) {
4063
- const def = schema._zod.def;
4064
- const type = def.type;
4065
- if (def.coerce) throw new ZodCompileUnsupportedError(`coercion (z.coerce.${type}())`);
4066
- const buildsValue = needsValue || !!def.checks?.length;
4067
- let typeAccessor;
4068
- switch (type) {
4069
- case "string":
4070
- typeAccessor = generateStringCheck(doc, ctx, schema, accessor, buildsValue);
4071
- break;
4072
- case "number":
4073
- typeAccessor = generateNumberCheck(doc, schema, accessor);
4074
- break;
4075
- case "boolean":
4076
- typeAccessor = generateBooleanCheck(doc, accessor);
4077
- break;
4078
- case "bigint":
4079
- typeAccessor = generateBigIntCheck(doc, schema, accessor);
4080
- break;
4081
- case "symbol":
4082
- typeAccessor = generateSymbolCheck(doc, accessor);
4083
- break;
4084
- case "undefined":
4085
- typeAccessor = generateUndefinedCheck(doc, accessor);
4086
- break;
4087
- case "null":
4088
- typeAccessor = generateNullCheck(doc, accessor);
4089
- break;
4090
- case "any":
4091
- case "unknown":
4092
- typeAccessor = accessor;
4093
- break;
4094
- case "never":
4095
- doc.write("return INVALID;");
4096
- typeAccessor = accessor;
4097
- break;
4098
- case "void":
4099
- typeAccessor = generateVoidCheck(doc, accessor);
4100
- break;
4101
- case "nan":
4102
- typeAccessor = generateNaNCheck(doc, accessor);
4103
- break;
4104
- case "date":
4105
- typeAccessor = generateDateCheck(doc, accessor);
4106
- break;
4107
- case "object":
4108
- typeAccessor = generateObjectCheck(doc, ctx, schema, accessor, buildsValue);
4109
- break;
4110
- case "optional":
4111
- typeAccessor = generateOptionalCheck(doc, ctx, schema, accessor, buildsValue);
4112
- break;
4113
- case "nullable":
4114
- typeAccessor = generateNullableCheck(doc, ctx, schema, accessor, buildsValue);
4115
- break;
4116
- case "array":
4117
- typeAccessor = generateArrayCheck(doc, ctx, schema, accessor, buildsValue);
4118
- break;
4119
- case "literal":
4120
- typeAccessor = generateLiteralCheck(doc, ctx, schema, accessor);
4121
- break;
4122
- case "enum":
4123
- typeAccessor = generateEnumCheck(doc, ctx, schema, accessor);
4124
- break;
4125
- case "readonly": {
4126
- const innerOut = generateWrapperCheck(doc, ctx, schema, accessor);
4127
- const frozenVar = newVar(ctx);
4128
- doc.write(`const ${frozenVar} = Object.freeze(${innerOut});`);
4129
- typeAccessor = frozenVar;
4130
- break;
4131
- }
4132
- case "success":
4133
- generateWrapperCheck(doc, ctx, schema, accessor);
4134
- typeAccessor = "true";
4135
- break;
4136
- case "default":
4137
- case "prefault":
4138
- typeAccessor = generateDefaultCheck(doc, ctx, schema, accessor);
4139
- break;
4140
- case "nonoptional":
4141
- typeAccessor = generateNonOptionalCheck(doc, ctx, schema, accessor);
4142
- break;
4143
- case "tuple":
4144
- typeAccessor = generateTupleCheck(doc, ctx, schema, accessor);
4145
- break;
4146
- case "union":
4147
- typeAccessor = generateUnionCheck(doc, ctx, schema, accessor);
4148
- break;
4149
- case "intersection":
4150
- typeAccessor = generateIntersectionCheck(doc, ctx, schema, accessor);
4151
- break;
4152
- case "record":
4153
- typeAccessor = generateRecordCheck(doc, ctx, schema, accessor);
4154
- break;
4155
- case "map":
4156
- typeAccessor = generateMapCheck(doc, ctx, schema, accessor);
4157
- break;
4158
- case "set":
4159
- typeAccessor = generateSetCheck(doc, ctx, schema, accessor);
4160
- break;
4161
- case "file":
4162
- typeAccessor = generateFileCheck(doc, accessor);
4163
- break;
4164
- case "template_literal":
4165
- typeAccessor = generateTemplateLiteralCheck(doc, ctx, schema, accessor);
4166
- break;
4167
- case "lazy":
4168
- typeAccessor = generateLazyCheck(doc, ctx, schema, accessor);
4169
- break;
4170
- case "pipe":
4171
- typeAccessor = generatePipeCheck(doc, ctx, schema, accessor);
4172
- break;
4173
- case "custom":
4174
- typeAccessor = generateCustomCheck(doc, ctx, schema, accessor);
4175
- break;
4176
- case "transform":
4177
- typeAccessor = generateTransformCheck(doc, ctx, schema, accessor);
4178
- break;
4179
- case "catch":
4180
- typeAccessor = generateCatchCheck(doc, ctx, schema, accessor);
4181
- break;
4182
- default: throw new ZodCompileUnsupportedError(`schema type ${type}`);
4183
- }
4184
- if (typeAccessor === null) return null;
4185
- return generateChecks(doc, ctx, schema, typeAccessor);
4186
- }
4187
- function generateStringCheck(doc, ctx, schema, accessor, needsValue = true) {
4188
- doc.write(`if (typeof ${accessor} !== "string") return INVALID;`);
4189
- const def = schema._zod.def;
4190
- if (def.format === void 0) return accessor;
4191
- return generateStringFormatCheck(doc, ctx, def, accessor, needsValue);
4192
- }
4193
- function generateNumberCheck(doc, schema, accessor) {
4194
- doc.write(`if (typeof ${accessor} !== "number" || !Number.isFinite(${accessor})) return INVALID;`);
4195
- const def = schema._zod.def;
4196
- if (def.check === "number_format" && def.format) generateNumberFormatCheck(doc, { format: def.format }, accessor);
4197
- return accessor;
4198
- }
4199
- function generateBooleanCheck(doc, accessor) {
4200
- doc.write(`if (typeof ${accessor} !== "boolean") return INVALID;`);
4201
- return accessor;
4202
- }
4203
- function generateBigIntCheck(doc, schema, accessor) {
4204
- doc.write(`if (typeof ${accessor} !== "bigint") return INVALID;`);
4205
- const def = schema._zod.def;
4206
- if (def.format) switch (def.format) {
4207
- case "int64":
4208
- doc.write(`if (${accessor} < -9223372036854775808n || ${accessor} > 9223372036854775807n) return INVALID;`);
4209
- break;
4210
- case "uint64": doc.write(`if (${accessor} < 0n || ${accessor} > 18446744073709551615n) return INVALID;`);
4211
- }
4212
- return accessor;
4213
- }
4214
- function generateSymbolCheck(doc, accessor) {
4215
- doc.write(`if (typeof ${accessor} !== "symbol") return INVALID;`);
4216
- return accessor;
4217
- }
4218
- function generateUndefinedCheck(doc, accessor) {
4219
- doc.write(`if (${accessor} !== undefined) return INVALID;`);
4220
- return accessor;
4221
- }
4222
- function generateNullCheck(doc, accessor) {
4223
- doc.write(`if (${accessor} !== null) return INVALID;`);
4224
- return accessor;
4225
- }
4226
- function generateVoidCheck(doc, accessor) {
4227
- doc.write(`if (${accessor} !== undefined) return INVALID;`);
4228
- return accessor;
4229
- }
4230
- function generateNaNCheck(doc, accessor) {
4231
- doc.write(`if (typeof ${accessor} !== "number" || !Number.isNaN(${accessor})) return INVALID;`);
4232
- return accessor;
4233
- }
4234
- function generateDateCheck(doc, accessor) {
4235
- doc.write(`if (!(${accessor} instanceof Date) || Number.isNaN(${accessor}.getTime())) return INVALID;`);
4236
- return accessor;
4237
- }
4238
- function generateObjectCheck(doc, ctx, schema, accessor, buildsValue = true) {
4239
- const def = schema._zod.def;
4240
- doc.write(`if (typeof ${accessor} !== "object" || ${accessor} === null || Array.isArray(${accessor})) return INVALID;`);
4241
- const shape = def.shape;
4242
- const keys = Object.keys(shape);
4243
- const symbolKeys = Object.getOwnPropertySymbols(shape);
4244
- const allKeys = symbolKeys.length ? [...keys, ...symbolKeys] : keys;
4245
- const keyExpr = (k) => typeof k === "symbol" ? addConstant(ctx, k) : esc(k);
4246
- const propKey = (k) => typeof k === "symbol" ? `[${keyExpr(k)}]` : esc(k);
4247
- const propShape = shape;
4248
- if (keys.includes("__proto__")) throw new ZodCompileUnsupportedError("object shape key \"__proto__\"");
4249
- const propOutputs = /* @__PURE__ */ new Map();
4250
- for (const key of allKeys) {
4251
- const propSchema = propShape[key];
4252
- const kx = keyExpr(key);
4253
- const inputVar = newVar(ctx);
4254
- doc.write(`const ${inputVar} = ${accessor}[${kx}];`);
4255
- if (propSchema._zod.optin !== void 0) {
4256
- const outputVar = newVar(ctx);
4257
- doc.write(`let ${outputVar} = (() => {`);
4258
- doc.indented((d) => {
4259
- const outputAccessor = compileChild(d, ctx, propSchema, inputVar);
4260
- d.write(`return ${outputAccessor};`);
4261
- });
4262
- doc.write(`})();`);
4263
- if (propSchema._zod.optout === "optional") {
4264
- doc.write(`if (${outputVar} === INVALID) {`);
4265
- doc.indented((d) => {
4266
- d.write(`if (${kx} in ${accessor}) return INVALID;`);
4267
- d.write(`${outputVar} = undefined;`);
4268
- });
4269
- doc.write(`}`);
4270
- } else doc.write(`if (${outputVar} === INVALID) return INVALID;`);
4271
- propOutputs.set(key, outputVar);
4272
- } else {
4273
- if (requiresPresenceCheck(propSchema)) doc.write(`if (!(${kx} in ${accessor})) return INVALID;`);
4274
- const outputAccessor = compileChild(doc, ctx, propSchema, inputVar, buildsValue);
4275
- if (outputAccessor !== null) propOutputs.set(key, outputAccessor);
4276
- }
4277
- }
4278
- const catchall = def.catchall;
4279
- let unknownKeysMode = "none";
4280
- if (catchall) {
4281
- const catchallType = catchall._zod.def.type;
4282
- if (catchallType === "never") {
4283
- const condition = keys.map((k) => `k !== ${esc(k)}`).join(" && ") || "true";
4284
- doc.write(`for (const k in ${accessor}) {`);
4285
- doc.indented((d) => {
4286
- d.write(`if (${condition}) return INVALID;`);
4287
- });
4288
- doc.write(`}`);
4289
- } else if ((catchallType === "unknown" || catchallType === "any") && !catchall._zod.def.checks?.length) unknownKeysMode = "passthrough";
4290
- else unknownKeysMode = "schema";
4291
- }
4292
- const outputVar = newVar(ctx);
4293
- const hasConditionalKeys = allKeys.some((k) => mayOmitUndefined(propShape[k]) || dropsWhenAbsent(propShape[k]));
4294
- if (!buildsValue) {
4295
- if (unknownKeysMode === "schema") {
4296
- const knownSet = keys.length > 0 ? addConstant(ctx, new Set(keys)) : null;
4297
- doc.write(`for (const k in ${accessor}) {`);
4298
- doc.indented((d) => {
4299
- d.write(`if (k === "__proto__") continue;`);
4300
- if (knownSet) d.write(`if (${knownSet}.has(k)) continue;`);
4301
- const valVar = newVar(ctx);
4302
- d.write(`const ${valVar} = ${accessor}[k];`);
4303
- compileChild(d, ctx, catchall, valVar, false);
4304
- });
4305
- doc.write(`}`);
4306
- }
4307
- return null;
4308
- }
4309
- if (!hasConditionalKeys) {
4310
- const propLiterals = allKeys.map((k) => `${propKey(k)}: ${propOutputs.get(k)}`).join(", ");
4311
- doc.write(`const ${outputVar} = { ${propLiterals} };`);
4312
- } else {
4313
- doc.write(`const ${outputVar} = {};`);
4314
- for (const k of allKeys) {
4315
- const kx = keyExpr(k);
4316
- const out = propOutputs.get(k);
4317
- if (dropsWhenAbsent(propShape[k])) doc.write(`if (${kx} in ${accessor}) ${outputVar}[${kx}] = ${out};`);
4318
- else if (mayOmitUndefined(propShape[k])) doc.write(`if (${out} !== undefined || ${kx} in ${accessor}) ${outputVar}[${kx}] = ${out};`);
4319
- else doc.write(`${outputVar}[${kx}] = ${out};`);
4320
- }
4321
- }
4322
- if (unknownKeysMode !== "none") {
4323
- const knownSet = keys.length > 0 ? addConstant(ctx, new Set(keys)) : null;
4324
- doc.write(`for (const k in ${accessor}) {`);
4325
- doc.indented((d) => {
4326
- d.write(`if (k === "__proto__") continue;`);
4327
- if (knownSet) d.write(`if (${knownSet}.has(k)) continue;`);
4328
- if (unknownKeysMode === "passthrough") d.write(`${outputVar}[k] = ${accessor}[k];`);
4329
- else {
4330
- const valVar = newVar(ctx);
4331
- d.write(`const ${valVar} = ${accessor}[k];`);
4332
- const catchallOut = compileChild(d, ctx, catchall, valVar);
4333
- d.write(`${outputVar}[k] = ${catchallOut};`);
4334
- }
4335
- });
4336
- doc.write(`}`);
4337
- }
4338
- return outputVar;
4339
- }
4340
- function generateOptionalCheck(doc, ctx, schema, accessor, buildsValue = true) {
4341
- const def = schema._zod.def;
4342
- if (isExactOptional(schema)) return generateCheck(doc, ctx, def.innerType, accessor, buildsValue);
4343
- if (def.innerType._zod.optin === "defaulted") {
4344
- const outputVar = newVar(ctx);
4345
- const branchVar = newVar(ctx);
4346
- doc.write(`let ${outputVar};`);
4347
- doc.write(`if (${accessor} === undefined) {`);
4348
- doc.indented((d) => {
4349
- d.write(`const ${branchVar} = (() => {`);
4350
- d.indented((d2) => {
4351
- const innerOutput = generateCheck(d2, ctx, def.innerType, accessor);
4352
- d2.write(`return ${innerOutput};`);
4353
- });
4354
- d.write(`})();`);
4355
- d.write(`if (${branchVar} !== INVALID) ${outputVar} = ${branchVar};`);
4356
- });
4357
- doc.write(`} else {`);
4358
- doc.indented((d) => {
4359
- const innerOutput = generateCheck(d, ctx, def.innerType, accessor);
4360
- d.write(`${outputVar} = ${innerOutput};`);
4361
- });
4362
- doc.write(`}`);
4363
- return outputVar;
4364
- }
4365
- const outputVar = buildsValue ? newVar(ctx) : null;
4366
- if (outputVar) doc.write(`let ${outputVar};`);
4367
- doc.write(`if (${accessor} !== undefined) {`);
4368
- doc.indented((d) => {
4369
- const innerOutput = generateCheck(d, ctx, def.innerType, accessor, buildsValue);
4370
- if (outputVar && innerOutput !== null) d.write(`${outputVar} = ${innerOutput};`);
4371
- });
4372
- doc.write(`}`);
4373
- return outputVar;
4374
- }
4375
- function isExactOptional(schema) {
4376
- return schema._zod.traits?.has("$ZodExactOptional") === true;
4377
- }
4378
- function requiresPresenceCheck(schema) {
4379
- return schema._zod.optin === void 0 && fastPathAcceptsAbsence(schema);
4380
- }
4381
- function fastPathAcceptsAbsence(schema) {
4382
- if (schema._zod.def.coerce) return true;
4383
- const def = schema._zod.def;
4384
- switch (def.type) {
4385
- case "any":
4386
- case "unknown":
4387
- case "undefined":
4388
- case "void":
4389
- case "default":
4390
- case "prefault":
4391
- case "transform":
4392
- case "custom":
4393
- case "lazy": return true;
4394
- case "string":
4395
- case "number":
4396
- case "boolean":
4397
- case "bigint":
4398
- case "symbol":
4399
- case "null":
4400
- case "never":
4401
- case "nan":
4402
- case "date":
4403
- case "object":
4404
- case "array":
4405
- case "tuple":
4406
- case "record":
4407
- case "map":
4408
- case "set":
4409
- case "file":
4410
- case "template_literal": return false;
4411
- case "nonoptional": return def.innerType ? fastPathAcceptsAbsence(def.innerType) : false;
4412
- case "literal": return !!def.values?.includes(void 0);
4413
- case "enum": return !!schema._zod.values?.has(void 0);
4414
- case "optional":
4415
- case "nullable":
4416
- case "readonly":
4417
- case "success": return def.innerType ? fastPathAcceptsAbsence(def.innerType) : true;
4418
- case "catch": return true;
4419
- case "union": return def.options ? def.options.some(fastPathAcceptsAbsence) : true;
4420
- case "intersection":
4421
- if (!def.left || !def.right) return true;
4422
- return fastPathAcceptsAbsence(def.left) && fastPathAcceptsAbsence(def.right);
4423
- case "pipe": return def.in ? fastPathAcceptsAbsence(def.in) : true;
4424
- default: return true;
4425
- }
4426
- }
4427
- /** The middle rung permits absence without supplying anything in its place, so an absent key contributes nothing — mirrors the leading gate in `handlePropertyResult`. */
4428
- function dropsWhenAbsent(schema) {
4429
- return schema._zod.optin === "optional" && schema._zod.optout === "optional";
4430
- }
4431
- function mayOmitUndefined(schema) {
4432
- return (schema._zod.optin !== "defaulted" || schema._zod.optout === "optional") && mayOutputUndefined(schema);
4433
- }
4434
- function mayOutputUndefined(schema) {
4435
- const def = schema._zod.def;
4436
- switch (def.type) {
4437
- case "string":
4438
- case "number":
4439
- case "boolean":
4440
- case "bigint":
4441
- case "symbol":
4442
- case "null":
4443
- case "nan":
4444
- case "date":
4445
- case "object":
4446
- case "array":
4447
- case "tuple":
4448
- case "record":
4449
- case "map":
4450
- case "set":
4451
- case "file":
4452
- case "template_literal":
4453
- case "never":
4454
- case "success": return false;
4455
- case "literal": return !!def.values?.includes(void 0);
4456
- case "enum": return !!schema._zod.values?.has(void 0);
4457
- case "optional": return true;
4458
- case "nullable":
4459
- case "readonly":
4460
- case "nonoptional": return def.innerType ? mayOutputUndefined(def.innerType) : true;
4461
- case "union": return def.options ? def.options.some(mayOutputUndefined) : true;
4462
- case "intersection": return !def.left || !def.right || mayOutputUndefined(def.left) || mayOutputUndefined(def.right);
4463
- case "pipe": return def.out ? mayOutputUndefined(def.out) : true;
4464
- default: return true;
4465
- }
4466
- }
4467
- function generateNullableCheck(doc, ctx, schema, accessor, buildsValue = true) {
4468
- const def = schema._zod.def;
4469
- const outputVar = buildsValue ? newVar(ctx) : null;
4470
- if (outputVar) doc.write(`let ${outputVar} = null;`);
4471
- doc.write(`if (${accessor} !== null) {`);
4472
- doc.indented((d) => {
4473
- const innerOutput = generateCheck(d, ctx, def.innerType, accessor, buildsValue);
4474
- if (outputVar && innerOutput !== null) d.write(`${outputVar} = ${innerOutput};`);
4475
- });
4476
- doc.write(`}`);
4477
- return outputVar;
4478
- }
4479
- function generateSizeGate(doc, schema, size) {
4480
- for (const [max, check] of sizeCaps(schema._zod.def.checks)) doc.write(`if (${size} > ${numericOperand(max, check._zod.def.check)}) return INVALID;`);
4481
- }
4482
- function generateArrayCheck(doc, ctx, schema, accessor, buildsValue = true) {
4483
- const def = schema._zod.def;
4484
- doc.write(`if (!Array.isArray(${accessor})) return INVALID;`);
4485
- generateSizeGate(doc, schema, `${accessor}.length`);
4486
- const outputVar = buildsValue ? newVar(ctx) : null;
4487
- const iVar = newVar(ctx);
4488
- const elemVar = newVar(ctx);
4489
- if (outputVar) doc.write(`const ${outputVar} = new Array(${accessor}.length);`);
4490
- doc.write(`for (let ${iVar} = 0; ${iVar} < ${accessor}.length; ${iVar}++) {`);
4491
- doc.indented((d) => {
4492
- d.write(`const ${elemVar} = ${accessor}[${iVar}];`);
4493
- const elemOutput = compileChild(d, ctx, def.element, elemVar, buildsValue);
4494
- if (outputVar && elemOutput !== null) d.write(`${outputVar}[${iVar}] = ${elemOutput};`);
4495
- });
4496
- doc.write(`}`);
4497
- return outputVar;
4498
- }
4499
- function generateLiteralCheck(doc, ctx, schema, accessor) {
4500
- const values = schema._zod.def.values;
4501
- if (values.length !== 1) {
4502
- const literalSet = addConstant(ctx, new Set(values));
4503
- doc.write(`if (!${literalSet}.has(${accessor})) return INVALID;`);
4504
- return accessor;
4505
- }
4506
- const value = values[0];
4507
- if (typeof value === "number" && Number.isNaN(value)) {
4508
- const literalSet = addConstant(ctx, new Set(values));
4509
- doc.write(`if (!${literalSet}.has(${accessor})) return INVALID;`);
4510
- return accessor;
4511
- }
4512
- if (typeof value === "string") doc.write(`if (${accessor} !== ${esc(value)}) return INVALID;`);
4513
- else if (typeof value === "number" || typeof value === "boolean") doc.write(`if (${accessor} !== ${value}) return INVALID;`);
4514
- else if (value === null) doc.write(`if (${accessor} !== null) return INVALID;`);
4515
- else if (value === void 0) doc.write(`if (${accessor} !== undefined) return INVALID;`);
4516
- else if (typeof value === "bigint") doc.write(`if (${accessor} !== ${value}n) return INVALID;`);
4517
- else throw new ZodCompileUnsupportedError(`literal type ${typeof value}`);
4518
- return accessor;
4519
- }
4520
- function generateEnumCheck(doc, ctx, schema, accessor) {
4521
- const values = schema._zod.values;
4522
- if (!values) throw new ZodCompileUnsupportedError("enum schema without enumerated values");
4523
- const enumSet = addConstant(ctx, values);
4524
- doc.write(`if (!${enumSet}.has(${accessor})) return INVALID;`);
4525
- return accessor;
4526
- }
4527
- function generateWrapperCheck(doc, ctx, schema, accessor) {
4528
- const def = schema._zod.def;
4529
- return generateCheck(doc, ctx, def.innerType, accessor);
4530
- }
4531
- function generateDefaultCheck(doc, ctx, schema, accessor) {
4532
- const def = schema._zod.def;
4533
- const defaultGetter = Object.getOwnPropertyDescriptor(schema._zod.def, "defaultValue") ? () => schema._zod.def.defaultValue : void 0;
4534
- if (schema._zod.def.type === "prefault") {
4535
- if (!defaultGetter) return generateCheck(doc, ctx, def.innerType, accessor);
4536
- const defaultFn = addConstant(ctx, defaultGetter);
4537
- const inputVar = newVar(ctx);
4538
- doc.write(`let ${inputVar} = ${accessor};`);
4539
- doc.write(`if (${accessor} === undefined) ${inputVar} = ${defaultFn}();`);
4540
- return generateCheck(doc, ctx, def.innerType, inputVar);
4541
- }
4542
- const outputVar = newVar(ctx);
4543
- if (defaultGetter) {
4544
- const defaultFn = addConstant(ctx, defaultGetter);
4545
- const cloneFn = addConstant(ctx, shallowClone);
4546
- doc.write(`let ${outputVar};`);
4547
- doc.write(`if (${accessor} === undefined) {`);
4548
- doc.indented((d) => {
4549
- d.write(`${outputVar} = ${cloneFn}(${defaultFn}());`);
4550
- });
4551
- doc.write(`} else {`);
4552
- doc.indented((d) => {
4553
- const innerOutput = generateCheck(d, ctx, def.innerType, accessor);
4554
- d.write(`${outputVar} = ${innerOutput} === undefined ? ${cloneFn}(${defaultFn}()) : ${innerOutput};`);
4555
- });
4556
- doc.write(`}`);
4557
- } else {
4558
- doc.write(`let ${outputVar};`);
4559
- doc.write(`if (${accessor} !== undefined) {`);
4560
- doc.indented((d) => {
4561
- const innerOutput = generateCheck(d, ctx, def.innerType, accessor);
4562
- d.write(`${outputVar} = ${innerOutput};`);
4563
- });
4564
- doc.write(`}`);
4565
- }
4566
- return outputVar;
4567
- }
4568
- function generateNonOptionalCheck(doc, ctx, schema, accessor) {
4569
- const def = schema._zod.def;
4570
- const innerOutput = generateCheck(doc, ctx, def.innerType, accessor);
4571
- const outputVar = newVar(ctx);
4572
- doc.write(`const ${outputVar} = ${innerOutput};`);
4573
- doc.write(`if (${outputVar} === undefined) return INVALID;`);
4574
- return outputVar;
4575
- }
4576
- function generateTupleCheck(doc, ctx, schema, accessor) {
4577
- const def = schema._zod.def;
4578
- const items = def.items;
4579
- const rest = def.rest;
4580
- doc.write(`if (!Array.isArray(${accessor})) return INVALID;`);
4581
- const optinStart = getTupleOptStart(items, "optin");
4582
- const optoutStart = getTupleOptStart(items, "optout");
4583
- if (rest) doc.write(`if (${accessor}.length < ${optinStart}) return INVALID;`);
4584
- else doc.write(`if (${accessor}.length < ${optinStart} || ${accessor}.length > ${items.length}) return INVALID;`);
4585
- const outputVar = newVar(ctx);
4586
- doc.write(`const ${outputVar} = [];`);
4587
- for (let i = 0; i < items.length; i++) {
4588
- const itemSchema = items[i];
4589
- if (i >= optoutStart) {
4590
- doc.write(`if (${outputVar}.length === ${i}) {`);
4591
- doc.indented((d) => {
4592
- d.write(`if (${i} < ${accessor}.length) {`);
4593
- d.indented((d2) => {
4594
- const elemVar = newVar(ctx);
4595
- d2.write(`const ${elemVar} = ${accessor}[${i}];`);
4596
- const elemOutput = compileChild(d2, ctx, itemSchema, elemVar);
4597
- d2.write(`${outputVar}[${i}] = ${elemOutput};`);
4598
- });
4599
- d.write(`} else {`);
4600
- d.indented((d2) => {
4601
- if (dropsWhenAbsent(itemSchema)) {
4602
- d2.write(`${outputVar}.length = ${i};`);
4603
- return;
4604
- }
4605
- const elemVar = newVar(ctx);
4606
- const branchVar = newVar(ctx);
4607
- d2.write(`const ${elemVar} = undefined;`);
4608
- d2.write(`const ${branchVar} = (() => {`);
4609
- d2.indented((d3) => {
4610
- const elemOutput = compileChild(d3, ctx, itemSchema, elemVar);
4611
- d3.write(`return ${elemOutput};`);
4612
- });
4613
- d2.write(`})();`);
4614
- d2.write(`if (${branchVar} === INVALID || ${branchVar} === undefined) ${outputVar}.length = ${i};`);
4615
- d2.write(`else ${outputVar}[${i}] = ${branchVar};`);
4616
- });
4617
- d.write(`}`);
4618
- });
4619
- doc.write(`}`);
4620
- } else {
4621
- const elemVar = newVar(ctx);
4622
- doc.write(`const ${elemVar} = ${accessor}[${i}];`);
4623
- const elemOutput = compileChild(doc, ctx, itemSchema, elemVar);
4624
- doc.write(`${outputVar}[${i}] = ${elemOutput};`);
4625
- }
4626
- }
4627
- if (rest) {
4628
- const iVar = newVar(ctx);
4629
- const elemVar = newVar(ctx);
4630
- doc.write(`for (let ${iVar} = ${items.length}; ${iVar} < ${accessor}.length; ${iVar}++) {`);
4631
- doc.indented((d) => {
4632
- d.write(`const ${elemVar} = ${accessor}[${iVar}];`);
4633
- const elemOutput = compileChild(d, ctx, rest, elemVar);
4634
- d.write(`${outputVar}[${iVar}] = ${elemOutput};`);
4635
- });
4636
- doc.write(`}`);
4637
- }
4638
- return outputVar;
4639
- }
4640
- function getTupleOptStart(items, key) {
4641
- for (let i = items.length - 1; i >= 0; i--) if (!(key === "optin" ? items[i]._zod.optin !== void 0 : items[i]._zod.optout === "optional")) return i + 1;
4642
- return 0;
4643
- }
4644
- function generateUnionCheck(doc, ctx, schema, accessor) {
4645
- const def = schema._zod.def;
4646
- const options = def.options;
4647
- if (def.discriminator) return generateDiscriminatedUnionCheck(doc, ctx, def, accessor);
4648
- if (def.inclusive === false) throw new ZodCompileUnsupportedError("exclusive unions (z.xor)");
4649
- if (options.length === 0) {
4650
- doc.write("return INVALID;");
4651
- return accessor;
4652
- }
4653
- if (options.length === 1) return generateCheck(doc, ctx, options[0], accessor);
4654
- if (options.every((opt) => opt._zod.def.type === "literal" && !opt._zod.def.checks?.length)) {
4655
- const valuesConst = addConstant(ctx, new Set(options.flatMap((opt) => opt._zod.def.values)));
4656
- doc.write(`if (!${valuesConst}.has(${accessor})) return INVALID;`);
4657
- return accessor;
4658
- }
4659
- const outputVar = newVar(ctx);
4660
- doc.write(`let ${outputVar};`);
4661
- for (let i = 0; i < options.length; i++) {
4662
- const opt = options[i];
4663
- if (i === 0) doc.write(`${outputVar} = (() => {`);
4664
- else doc.write(`if (${outputVar} === INVALID) ${outputVar} = (() => {`);
4665
- doc.indented((d) => {
4666
- const branchOutput = generateCheck(d, ctx, opt, accessor);
4667
- d.write(`return ${branchOutput};`);
4668
- });
4669
- doc.write(`})();`);
4670
- }
4671
- doc.write(`if (${outputVar} === INVALID) return INVALID;`);
4672
- return outputVar;
4673
- }
4674
- function generateDiscriminatedUnionCheck(doc, ctx, def, accessor) {
4675
- if (def.unionFallback) throw new ZodCompileUnsupportedError("discriminated union with unionFallback");
4676
- if (def.options.length === 0) {
4677
- doc.write("return INVALID;");
4678
- return accessor;
4679
- }
4680
- const discVar = newVar(ctx);
4681
- const outputVar = newVar(ctx);
4682
- doc.write(`const ${discVar} = ${accessor}?.[${esc(def.discriminator)}];`);
4683
- doc.write(`let ${outputVar};`);
4684
- let firstBranch = true;
4685
- const claimed = /* @__PURE__ */ new Set();
4686
- for (const option of def.options) {
4687
- const values = option._zod.propValues?.[def.discriminator];
4688
- if (!values || values.size === 0) throw new ZodCompileUnsupportedError("discriminated union option without static discriminator values");
4689
- for (const value of values) {
4690
- if (claimed.has(value)) throw new ZodCompileUnsupportedError(`duplicate discriminator value ${String(value)}`);
4691
- claimed.add(value);
4692
- }
4693
- const conditions = Array.from(values, (value) => literalEquality(ctx, discVar, value));
4694
- const prefix = firstBranch ? "if" : "else if";
4695
- doc.write(`${prefix} (${conditions.join(" || ")}) {`);
4696
- doc.indented((d) => {
4697
- const branchOutput = generateCheck(d, ctx, option, accessor);
4698
- d.write(`${outputVar} = ${branchOutput};`);
4699
- });
4700
- doc.write(`}`);
4701
- firstBranch = false;
4702
- }
4703
- doc.write(`else { return INVALID; }`);
4704
- return outputVar;
4705
- }
4706
- function literalEquality(ctx, accessor, value) {
4707
- if (typeof value === "string") return `${accessor} === ${esc(value)}`;
4708
- if (typeof value === "number") {
4709
- if (Number.isNaN(value)) return `Number.isNaN(${accessor})`;
4710
- return `${accessor} === ${value}`;
4711
- }
4712
- if (typeof value === "boolean") return `${accessor} === ${value}`;
4713
- if (value === null) return `${accessor} === null`;
4714
- if (value === void 0) return `${accessor} === undefined`;
4715
- if (typeof value === "bigint") return `${accessor} === ${value}n`;
4716
- if (typeof value === "symbol") return `${accessor} === ${addConstant(ctx, value)}`;
4717
- throw new ZodCompileUnsupportedError(`literal discriminator value ${String(value)}`);
4718
- }
4719
- function generateIntersectionCheck(doc, ctx, schema, accessor) {
4720
- const def = schema._zod.def;
4721
- ctx.definite = false;
4722
- const leftOutput = compileChild(doc, ctx, def.left, accessor);
4723
- const rightOutput = compileChild(doc, ctx, def.right, accessor);
4724
- const mergeConst = addConstant(ctx, mergeValues);
4725
- const mergedVar = newVar(ctx);
4726
- doc.write(`const ${mergedVar} = ${mergeConst}(${leftOutput}, ${rightOutput});`);
4727
- doc.write(`if (!${mergedVar}.valid) return INVALID;`);
4728
- return `${mergedVar}.data`;
4729
- }
4730
- function generateRecordCheck(doc, ctx, schema, accessor) {
4731
- const def = schema._zod.def;
4732
- const isPlainObjectConst = addConstant(ctx, isPlainObject);
4733
- doc.write(`if (!${isPlainObjectConst}(${accessor})) return INVALID;`);
4734
- const outputVar = newVar(ctx);
4735
- const kVar = newVar(ctx);
4736
- const valVar = newVar(ctx);
4737
- doc.write(`const ${outputVar} = {};`);
4738
- const recordDef = def;
4739
- const keyValues = recordDef.partial ? void 0 : def.keyType._zod.values;
4740
- if (keyValues) {
4741
- const inputKeys = [];
4742
- for (const key of keyValues) {
4743
- if (!(typeof key === "string" || typeof key === "number" || typeof key === "symbol")) throw new ZodCompileUnsupportedError(`record key value ${String(key)}`);
4744
- const inputKey = typeof key === "number" ? key.toString() : key;
4745
- if (inputKey === "__proto__") throw new ZodCompileUnsupportedError("record key \"__proto__\"");
4746
- inputKeys.push(inputKey);
4747
- const keyConst = addConstant(ctx, key);
4748
- const outKey = generateCheck(doc, ctx, def.keyType, keyConst);
4749
- const valueVar = newVar(ctx);
4750
- doc.write(`const ${valueVar} = ${accessor}[${literalPropertyKey(ctx, inputKey)}];`);
4751
- const valOutput = compileChild(doc, ctx, def.valueType, valueVar);
4752
- doc.write(`${outputVar}[${outKey}] = ${valOutput};`);
4753
- }
4754
- const knownKeysConst = addConstant(ctx, new Set(inputKeys));
4755
- doc.write(`for (const ${kVar} in ${accessor}) {`);
4756
- doc.indented((d) => {
4757
- d.write(`if (${knownKeysConst}.has(${kVar})) continue;`);
4758
- if (recordDef.mode === "loose") d.write(`if (${kVar} !== "__proto__") ${outputVar}[${kVar}] = ${accessor}[${kVar}];`);
4759
- else d.write(`return INVALID;`);
4760
- });
4761
- doc.write(`}`);
4762
- return outputVar;
4763
- }
4764
- const keyDef = def.keyType._zod.def;
4765
- if (!(keyDef.type === "string" && keyDef.format === void 0 && !keyDef.coerce && (keyDef.checks?.length ?? 0) === 0)) {
4766
- const isLoose = def.mode === "loose";
4767
- const keyFn = compileFn(def.keyType);
4768
- if (keyFn.definite === false) ctx.definite = false;
4769
- const keyFast = addConstant(ctx, keyFn);
4770
- const numericConst = addConstant(ctx, number$2);
4771
- const outKeyVar = newVar(ctx);
4772
- emitOwnKeys(doc, ctx, accessor, kVar, (d) => {
4773
- d.write(`let ${outKeyVar} = ${keyFast}(${kVar});`);
4774
- d.write(`if (${outKeyVar} === INVALID && typeof ${kVar} === "string" && ${numericConst}.test(${kVar})) ${outKeyVar} = ${keyFast}(Number(${kVar}));`);
4775
- if (isLoose) d.write(`if (${outKeyVar} === INVALID) { ${outputVar}[${kVar}] = ${accessor}[${kVar}]; continue; }`);
4776
- else d.write(`if (${outKeyVar} === INVALID) return INVALID;`);
4777
- d.write(`if (${outKeyVar} === "__proto__") continue;`);
4778
- const valueVar = newVar(ctx);
4779
- d.write(`const ${valueVar} = ${accessor}[${kVar}];`);
4780
- const valOutput = compileChild(d, ctx, def.valueType, valueVar);
4781
- d.write(`${outputVar}[${outKeyVar}] = ${valOutput};`);
4782
- });
4783
- return outputVar;
4784
- }
4785
- emitOwnKeys(doc, ctx, accessor, kVar, (d) => {
4786
- d.write(`const ${valVar} = ${accessor}[${kVar}];`);
4787
- const valOutput = compileChild(d, ctx, def.valueType, valVar);
4788
- d.write(`${outputVar}[${kVar}] = ${valOutput};`);
4789
- }, `return INVALID;`);
4790
- return outputVar;
4791
- }
4792
- function emitOwnKeys(doc, ctx, accessor, kVar, body, onSymbol) {
4793
- const propIsEnumerableConst = addConstant(ctx, Object.prototype.propertyIsEnumerable);
4794
- const symsVar = newVar(ctx);
4795
- const keysVar = newVar(ctx);
4796
- const iVar = newVar(ctx);
4797
- doc.write(`const ${symsVar} = Object.getOwnPropertySymbols(${accessor});`);
4798
- doc.write(`const ${keysVar} = Object.getOwnPropertyNames(${accessor});`);
4799
- doc.write(`for (let ${iVar} = 0; ${iVar} < ${keysVar}.length; ${iVar}++) {`);
4800
- doc.indented((d) => {
4801
- d.write(`const ${kVar} = ${keysVar}[${iVar}];`);
4802
- d.write(`if (${kVar} === "__proto__" || !${propIsEnumerableConst}.call(${accessor}, ${kVar})) continue;`);
4803
- body(d);
4804
- });
4805
- doc.write(`}`);
4806
- doc.write(`for (let ${iVar} = 0; ${iVar} < ${symsVar}.length; ${iVar}++) {`);
4807
- doc.indented((d) => {
4808
- d.write(`const ${kVar} = ${symsVar}[${iVar}];`);
4809
- d.write(`if (!${propIsEnumerableConst}.call(${accessor}, ${kVar})) continue;`);
4810
- if (onSymbol) d.write(onSymbol);
4811
- else body(d);
4812
- });
4813
- doc.write(`}`);
4814
- }
4815
- function literalPropertyKey(ctx, key) {
4816
- if (typeof key === "string") return esc(key);
4817
- return addConstant(ctx, key);
4818
- }
4819
- function generateMapCheck(doc, ctx, schema, accessor) {
4820
- const def = schema._zod.def;
4821
- doc.write(`if (!(${accessor} instanceof Map)) return INVALID;`);
4822
- generateSizeGate(doc, schema, `${accessor}.size`);
4823
- const outputVar = newVar(ctx);
4824
- const kVar = newVar(ctx);
4825
- const valVar = newVar(ctx);
4826
- doc.write(`const ${outputVar} = new Map();`);
4827
- doc.write(`for (const [${kVar}, ${valVar}] of ${accessor}) {`);
4828
- doc.indented((d) => {
4829
- const keyOutput = generateCheck(d, ctx, def.keyType, kVar);
4830
- const valOutput = generateCheck(d, ctx, def.valueType, valVar);
4831
- d.write(`${outputVar}.set(${keyOutput}, ${valOutput});`);
4832
- });
4833
- doc.write(`}`);
4834
- return outputVar;
4835
- }
4836
- function generateSetCheck(doc, ctx, schema, accessor) {
4837
- const def = schema._zod.def;
4838
- doc.write(`if (!(${accessor} instanceof Set)) return INVALID;`);
4839
- generateSizeGate(doc, schema, `${accessor}.size`);
4840
- const outputVar = newVar(ctx);
4841
- const valVar = newVar(ctx);
4842
- doc.write(`const ${outputVar} = new Set();`);
4843
- doc.write(`for (const ${valVar} of ${accessor}) {`);
4844
- doc.indented((d) => {
4845
- const valOutput = generateCheck(d, ctx, def.valueType, valVar);
4846
- d.write(`${outputVar}.add(${valOutput});`);
4847
- });
4848
- doc.write(`}`);
4849
- return outputVar;
4850
- }
4851
- function generateFileCheck(doc, accessor) {
4852
- doc.write(`if (!(${accessor} instanceof File)) return INVALID;`);
4853
- return accessor;
4854
- }
4855
- function generateTemplateLiteralCheck(doc, ctx, schema, accessor) {
4856
- doc.write(`if (typeof ${accessor} !== "string") return INVALID;`);
4857
- const pattern = schema._zod.pattern;
4858
- if (pattern) {
4859
- const patternConst = addConstant(ctx, pattern);
4860
- doc.write(`${patternConst}.lastIndex = 0;`);
4861
- doc.write(`if (!${patternConst}.test(${accessor})) return INVALID;`);
4862
- }
4863
- return accessor;
4864
- }
4865
- function generateLazyCheck(doc, ctx, schema, accessor) {
4866
- const def = schema._zod.def;
4867
- const getterConst = addUserConstant(ctx, def.getter);
4868
- const cacheConst = addConstant(ctx, { parser: null });
4869
- doc.write(`if (!${cacheConst}.parser) {`);
4870
- doc.indented((d) => {
4871
- d.write(`const inner = ${getterConst}();`);
4872
- d.write(`${cacheConst}.parser = function(input) {`);
4873
- d.indented((d2) => {
4874
- d2.write(`const result = inner._zod.run({ value: input, issues: [] }, {});`);
4875
- d2.write(`return result.issues.length === 0 ? result.value : INVALID;`);
4876
- });
4877
- d.write(`};`);
4878
- });
4879
- doc.write(`}`);
4880
- const outputVar = newVar(ctx);
4881
- doc.write(`const ${outputVar} = ${cacheConst}.parser(${accessor});`);
4882
- doc.write(`if (${outputVar} === INVALID) return INVALID;`);
4883
- return outputVar;
4884
- }
4885
- function generatePipeCheck(doc, ctx, schema, accessor) {
4886
- const def = schema._zod.def;
4887
- const inputOutput = generateCheck(doc, ctx, def.in, accessor);
4888
- if (def.transform) {
4889
- if (isAsyncFunction(def.transform)) throw new ZodCompileAsyncError("z.compile: async transforms in pipes are not supported");
4890
- const transformFn = def.transform;
4891
- const helperFn = (value) => {
4892
- const fakePayload = {
4893
- value,
4894
- issues: [],
4895
- addIssue: pushIssue
4896
- };
4897
- const result = transformFn(value, fakePayload);
4898
- if (result instanceof Promise) return INVALID;
4899
- return fakePayload.issues.length === 0 ? result : INVALID;
4900
- };
4901
- const helperConst = addUserConstant(ctx, helperFn);
4902
- const transformedVar = newVar(ctx);
4903
- doc.write(`const ${transformedVar} = ${helperConst}(${inputOutput});`);
4904
- doc.write(`if (${transformedVar} === INVALID) return INVALID;`);
4905
- return generateCheck(doc, ctx, def.out, transformedVar);
4906
- } else return generateCheck(doc, ctx, def.out, inputOutput);
4907
- }
4908
- function isAsyncFunction(fn) {
4909
- return typeof fn === "function" && (fn.constructor.name === "AsyncFunction" || fn[Symbol.toStringTag] === "AsyncFunction");
4910
- }
4911
- function generateCustomCheck(doc, ctx, schema, accessor) {
4912
- const def = schema._zod.def;
4913
- if (def.fn) {
4914
- if (isAsyncFunction(def.fn)) throw new ZodCompileAsyncError("z.compile: async custom predicates are not supported");
4915
- const fnConst = addUserConstant(ctx, def.fn);
4916
- const throwAsyncConst = addConstant(ctx, throwAsync);
4917
- const resVar = newVar(ctx);
4918
- doc.write(`const ${resVar} = ${fnConst}(${accessor});`);
4919
- doc.write(`if (${resVar} instanceof Promise) ${throwAsyncConst}();`);
4920
- doc.write(`if (!${resVar}) return INVALID;`);
4921
- } else throw new ZodCompileUnsupportedError("custom schema without a predicate function");
4922
- return accessor;
4923
- }
4924
- function runtimeCatch(innerSchema, catchValue, value) {
4925
- const result = innerSchema._zod.run({
4926
- value,
4927
- issues: []
4928
- }, {});
4929
- if (result && typeof result.then === "function") return INVALID;
4930
- const r = result;
4931
- if (r.issues.length === 0) return r.value;
4932
- return catchValue();
4933
- }
4934
- function generateCatchCheck(doc, ctx, schema, accessor) {
4935
- const def = schema._zod.def;
4936
- if (!def.catchValue["~constantCatch"]) throw new ZodCompileUnsupportedError("catch with a callback (only a constant catch value compiles)", false);
4937
- const outputVar = newVar(ctx);
4938
- doc.write(`let ${outputVar} = (() => {`);
4939
- doc.indented((d) => {
4940
- const innerOut = compileChild(d, ctx, def.innerType, accessor);
4941
- d.write(`return ${innerOut};`);
4942
- });
4943
- doc.write(`})();`);
4944
- const innerConst = addConstant(ctx, def.innerType);
4945
- const catchConst = addUserConstant(ctx, def.catchValue);
4946
- const catchHelperConst = addConstant(ctx, runtimeCatch);
4947
- doc.write(`if (${outputVar} === INVALID) {`);
4948
- doc.indented((d) => {
4949
- d.write(`${outputVar} = ${catchHelperConst}(${innerConst}, ${catchConst}, ${accessor});`);
4950
- d.write(`if (${outputVar} === INVALID) return INVALID;`);
4951
- });
4952
- doc.write(`}`);
4953
- return outputVar;
4954
- }
4955
- function generateTransformCheck(doc, ctx, schema, accessor) {
4956
- const def = schema._zod.def;
4957
- if (def.transform) {
4958
- if (isAsyncFunction(def.transform)) throw new ZodCompileAsyncError("z.compile: async transforms are not supported");
4959
- const transformFn = def.transform;
4960
- const helperFn = (value) => {
4961
- const fakePayload = {
4962
- value,
4963
- issues: [],
4964
- addIssue: pushIssue
4965
- };
4966
- const result = transformFn(value, fakePayload);
4967
- if (result instanceof Promise) return INVALID;
4968
- return fakePayload.issues.length === 0 ? result : INVALID;
4969
- };
4970
- const helperConst = addUserConstant(ctx, helperFn);
4971
- const outputVar = newVar(ctx);
4972
- doc.write(`const ${outputVar} = ${helperConst}(${accessor});`);
4973
- doc.write(`if (${outputVar} === INVALID) return INVALID;`);
4974
- return outputVar;
4975
- }
4976
- return accessor;
4977
- }
4978
3494
  // ../../node_modules/.bun/zod@4.6.7/node_modules/zod/v4/core/api.js
4979
3495
  function snapshotChecks(def) {
4980
3496
  if (def.checks) def.checks = [...def.checks];
@@ -7624,14 +6140,14 @@ function applyAttributeChanges(existing, changes) {
7624
6140
  else next[key] = value;
7625
6141
  return next;
7626
6142
  }
7627
- // ../../node_modules/.bun/@workflow+world@5.1.0/node_modules/@workflow/world/dist/attributes.js
6143
+ // ../../node_modules/.bun/@workflow+world@5.2.0/node_modules/@workflow/world/dist/attributes.js
7628
6144
  var textEncoder = new TextEncoder();
7629
- var AttributeKeySchema = compile(string().min(1, { error: "Attribute key must not be empty" }).max(256, { error: `Attribute key exceeds limit 256` }));
7630
- var AttributeValueSchema = compile(string().refine((value) => textEncoder.encode(value).length <= 256, { error: `Attribute value exceeds limit 256 UTF-8 bytes` }).nullable());
7631
- var AttributeChangesSchema = compile(array(compile(object({
6145
+ var AttributeKeySchema = string().min(1, { error: "Attribute key must not be empty" }).max(256, { error: `Attribute key exceeds limit 256` });
6146
+ var AttributeValueSchema = string().refine((value) => textEncoder.encode(value).length <= 256, { error: `Attribute value exceeds limit 256 UTF-8 bytes` }).nullable();
6147
+ var AttributeChangesSchema = array(object({
7632
6148
  key: AttributeKeySchema,
7633
6149
  value: AttributeValueSchema
7634
- }))).superRefine((changes, context) => {
6150
+ })).superRefine((changes, context) => {
7635
6151
  try {
7636
6152
  validateAttributeBatchConstraints(changes);
7637
6153
  } catch (error) {
@@ -7642,15 +6158,15 @@ var AttributeChangesSchema = compile(array(compile(object({
7642
6158
  input: changes
7643
6159
  });
7644
6160
  }
7645
- }));
6161
+ });
7646
6162
  /**
7647
6163
  * Union schema that accepts both v2+ (Uint8Array) and legacy (any) serialized data.
7648
6164
  * Use this for validation when data may come from either specVersion.
7649
6165
  */
7650
- var SerializedDataSchema = compile(union([compile(_instanceof(Uint8Array)), compile(any())]));
7651
- // ../../node_modules/.bun/@workflow+world@5.1.0/node_modules/@workflow/world/dist/start-hook.js
6166
+ var SerializedDataSchema = union([_instanceof(Uint8Array), any()]);
6167
+ // ../../node_modules/.bun/@workflow+world@5.2.0/node_modules/@workflow/world/dist/start-hook.js
7652
6168
  /**
7653
- * Atomic start Hook admission: `start(workflow, args, { hook: { token } })`.
6169
+ * Atomic start Hook admission: `start(workflow, args, { experimental_hook: { token } })`.
7654
6170
  *
7655
6171
  * The World creates a Hook for the token while it admits the run, so at most
7656
6172
  * one run owns the token and a duplicate start is refused before it becomes a
@@ -7781,7 +6297,7 @@ function isStartHookId(runId, hookId) {
7781
6297
  return runId.startsWith("wrun_") && hookId === startHookId(runId);
7782
6298
  }
7783
6299
  /**
7784
- * Wire codes a remote World (workflow-server) answers a start Hook admission
6300
+ * Wire codes a remote World (e.g. world-vercel) answers a start Hook admission
7785
6301
  * with, in the JSON error body's `error` (or `code`) field:
7786
6302
  *
7787
6303
  * - `409 start-hook-conflict`: the candidate was refused. The body carries
@@ -7811,8 +6327,8 @@ var START_HOOK_WIRE_CODES = {
7811
6327
  disabled: "start-hook-disabled",
7812
6328
  candidateCancelled: "start-hook-candidate-cancelled"
7813
6329
  };
7814
- // ../../node_modules/.bun/@workflow+world@5.1.0/node_modules/@workflow/world/dist/events.js
7815
- var EventTypeSchema = compile(_enum([
6330
+ // ../../node_modules/.bun/@workflow+world@5.2.0/node_modules/@workflow/world/dist/events.js
6331
+ var EventTypeSchema = _enum([
7816
6332
  "run_created",
7817
6333
  "run_started",
7818
6334
  "run_completed",
@@ -7831,7 +6347,7 @@ var EventTypeSchema = compile(_enum([
7831
6347
  "wait_created",
7832
6348
  "wait_completed",
7833
6349
  "noop"
7834
- ]));
6350
+ ]);
7835
6351
  EventTypeSchema.extract([
7836
6352
  "run_created",
7837
6353
  "run_started",
@@ -7839,11 +6355,11 @@ EventTypeSchema.extract([
7839
6355
  "run_failed",
7840
6356
  "run_cancelled"
7841
6357
  ]).options;
7842
- var TERMINAL_RUN_EVENT_TYPES = compile(EventTypeSchema.extract([
6358
+ var TERMINAL_RUN_EVENT_TYPES = EventTypeSchema.extract([
7843
6359
  "run_completed",
7844
6360
  "run_failed",
7845
6361
  "run_cancelled"
7846
- ])).options;
6362
+ ]).options;
7847
6363
  function isTerminalRunEventType(eventType) {
7848
6364
  return TERMINAL_RUN_EVENT_TYPES.includes(eventType);
7849
6365
  }
@@ -7908,11 +6424,11 @@ function stripEventDataRefs(event, resolveData) {
7908
6424
  ...Object.keys(stripped).length > 0 ? { eventData: stripped } : {}
7909
6425
  };
7910
6426
  }
7911
- var BaseEventSchema = compile(object({
6427
+ var BaseEventSchema = object({
7912
6428
  eventType: EventTypeSchema,
7913
6429
  correlationId: string().optional(),
7914
6430
  specVersion: number$1().optional()
7915
- }));
6431
+ });
7916
6432
  var stepLatencyTelemetryFields = {
7917
6433
  ttfs: number$1().optional(),
7918
6434
  stso: number$1().optional(),
@@ -8029,7 +6545,7 @@ var StepCreatedEventSchema = BaseEventSchema.extend({
8029
6545
  * Event created when a hook is first invoked. The World implementation
8030
6546
  * atomically creates both the event and the hook entity.
8031
6547
  */
8032
- var HookCreatedEventSchema = compile(BaseEventSchema.extend({
6548
+ var HookCreatedEventSchema = BaseEventSchema.extend({
8033
6549
  eventType: literal("hook_created"),
8034
6550
  correlationId: string(),
8035
6551
  eventData: object({
@@ -8062,12 +6578,13 @@ var HookCreatedEventSchema = compile(BaseEventSchema.extend({
8062
6578
  runSpecVersion: number$1().optional()
8063
6579
  }).optional()
8064
6580
  })
8065
- }));
6581
+ });
8066
6582
  var HookReceivedEventSchema = BaseEventSchema.extend({
8067
6583
  eventType: literal("hook_received"),
8068
6584
  correlationId: string(),
8069
6585
  eventData: object({
8070
6586
  token: string().optional(),
6587
+ workflowName: string().optional(),
8071
6588
  payload: SerializedDataSchema
8072
6589
  })
8073
6590
  });
@@ -8110,7 +6627,7 @@ var HookConflictEventSchema = BaseEventSchema.extend({
8110
6627
  * understand the involuntary disposal — the forced hook gets the
8111
6628
  * ordinary `HookConflictError` it opted out of instead of stranding
8112
6629
  * that run. Absent on a conflict answered by a World that does not
8113
- * implement forcing at all. (A run's `start({ hook })` Hook is taken like
6630
+ * implement forcing at all. (A run's `start({ experimental_hook })` Hook is taken like
8114
6631
  * any other Hook, so it is never a reason to refuse.)
8115
6632
  */
8116
6633
  forceRefusedReason: literal("victim-spec-version").optional()
@@ -8220,6 +6737,11 @@ var RunCreatedEventSchema = BaseEventSchema.extend({
8220
6737
  * when the run_created event failed (e.g., storage outage during start()), the
8221
6738
  * runtime passes the run input through the queue so the server can create the run
8222
6739
  * on the run_started call if it doesn't exist yet.
6740
+ *
6741
+ * On a spec >= 9 run, a `run_started` that created its run may also be stored
6742
+ * with that data at the run's first slot, standing for the run's creation, with
6743
+ * no `run_created` in the log. Readers accept that shape (`isRunCreationEvent`);
6744
+ * nothing in this SDK asks a World to write it yet.
8223
6745
  */
8224
6746
  var RunStartedEventSchema = BaseEventSchema.extend({
8225
6747
  eventType: literal("run_started"),
@@ -8278,7 +6800,7 @@ var RunCancelledEventSchema = BaseEventSchema.extend({
8278
6800
  eventType: literal("run_cancelled"),
8279
6801
  eventData: object({ cancelReason: string().max(512).optional() }).optional()
8280
6802
  });
8281
- compile(discriminatedUnion("eventType", [
6803
+ discriminatedUnion("eventType", [
8282
6804
  RunCreatedEventSchema,
8283
6805
  RunStartedEventSchema,
8284
6806
  RunCompletedEventSchema,
@@ -8295,8 +6817,8 @@ compile(discriminatedUnion("eventType", [
8295
6817
  HookDisposedEventSchema,
8296
6818
  WaitCreatedEventSchema,
8297
6819
  WaitCompletedEventSchema
8298
- ]));
8299
- var EventSchema = compile(discriminatedUnion("eventType", [
6820
+ ]);
6821
+ var EventSchema = discriminatedUnion("eventType", [
8300
6822
  RunCreatedEventSchema,
8301
6823
  RunStartedEventSchema,
8302
6824
  RunCompletedEventSchema,
@@ -8329,25 +6851,25 @@ var EventSchema = compile(discriminatedUnion("eventType", [
8329
6851
  * on legacy (non-lazy) resumes.
8330
6852
  */
8331
6853
  resumeId: string().optional()
8332
- })));
6854
+ }));
8333
6855
  /** Includes lazy step_started requests that create their step on demand. */
8334
6856
  function isChildEntityCreationEvent(event) {
8335
6857
  if (isChildEntityCreationEventType(event.eventType)) return true;
8336
6858
  return event.eventType === "step_started" && typeof event.eventData?.stepName === "string" && event.eventData.input !== void 0;
8337
6859
  }
8338
- // ../../node_modules/.bun/@workflow+world@5.1.0/node_modules/@workflow/world/dist/runs.js
8339
- var WorkflowRunStatusSchema = compile(_enum([
6860
+ // ../../node_modules/.bun/@workflow+world@5.2.0/node_modules/@workflow/world/dist/runs.js
6861
+ var WorkflowRunStatusSchema = _enum([
8340
6862
  "pending",
8341
6863
  "running",
8342
6864
  "completed",
8343
6865
  "failed",
8344
6866
  "cancelled"
8345
- ]));
8346
- var TERMINAL_WORKFLOW_RUN_STATUSES = compile(WorkflowRunStatusSchema.extract([
6867
+ ]);
6868
+ var TERMINAL_WORKFLOW_RUN_STATUSES = WorkflowRunStatusSchema.extract([
8347
6869
  "completed",
8348
6870
  "failed",
8349
6871
  "cancelled"
8350
- ])).options;
6872
+ ]).options;
8351
6873
  function isTerminalWorkflowRunStatus(status) {
8352
6874
  return TERMINAL_WORKFLOW_RUN_STATUSES.includes(status);
8353
6875
  }
@@ -8359,7 +6881,7 @@ function isTerminalWorkflowRunStatus(status) {
8359
6881
  * - specVersion >= 2: Uint8Array (binary devalue format)
8360
6882
  * - specVersion 1: any (legacy JSON format)
8361
6883
  */
8362
- var WorkflowRunBaseSchema = compile(object({
6884
+ var WorkflowRunBaseSchema = object({
8363
6885
  runId: string(),
8364
6886
  status: WorkflowRunStatusSchema,
8365
6887
  deploymentId: string(),
@@ -8448,7 +6970,7 @@ var WorkflowRunBaseSchema = compile(object({
8448
6970
  */
8449
6971
  encryptionPublicKey: string().optional(),
8450
6972
  /**
8451
- * The start Hook this run was admitted with through `start({ hook })`,
6973
+ * The start Hook this run was admitted with through `start({ experimental_hook })`,
8452
6974
  * echoed by a World that admitted it (see `start-hook.ts`), with its
8453
6975
  * `hookId` (`startHookId(runId)`). Required on the `run_created` response,
8454
6976
  * on `runs.get` and on the `run_started` response. Never forwarded when a
@@ -8460,8 +6982,8 @@ var WorkflowRunBaseSchema = compile(object({
8460
6982
  completedAt: date().optional(),
8461
6983
  createdAt: date(),
8462
6984
  updatedAt: date()
8463
- }));
8464
- var WorkflowRunSchema = compile(discriminatedUnion("status", [
6985
+ });
6986
+ var WorkflowRunSchema = discriminatedUnion("status", [
8465
6987
  WorkflowRunBaseSchema.extend({
8466
6988
  status: _enum(["pending", "running"]),
8467
6989
  output: _undefined().optional(),
@@ -8486,7 +7008,7 @@ var WorkflowRunSchema = compile(discriminatedUnion("status", [
8486
7008
  error: SerializedDataSchema.optional(),
8487
7009
  completedAt: date()
8488
7010
  })
8489
- ]));
7011
+ ]);
8490
7012
  /**
8491
7013
  * Request payload for cancelling many runs in a single operation.
8492
7014
  *
@@ -8494,10 +7016,10 @@ var WorkflowRunSchema = compile(discriminatedUnion("status", [
8494
7016
  * `cancelReason` (max 512 chars) is recorded on each run_cancelled event,
8495
7017
  * mirroring the single-run {@link CancelRunOptions.cancelReason}.
8496
7018
  */
8497
- var BulkCancelWorkflowRunsRequestSchema = compile(object({
7019
+ var BulkCancelWorkflowRunsRequestSchema = object({
8498
7020
  runIds: array(string()).min(1).max(500).refine((ids) => new Set(ids).size === ids.length, { message: "runIds must not contain duplicates" }),
8499
7021
  cancelReason: string().max(512).optional()
8500
- }));
7022
+ });
8501
7023
  /**
8502
7024
  * Per-run outcome of a bulk cancellation.
8503
7025
  *
@@ -8509,7 +7031,7 @@ var BulkCancelWorkflowRunsRequestSchema = compile(object({
8509
7031
  * - `failed`: cancellation failed; `code` is a machine-readable error code
8510
7032
  * and `retryable` indicates whether retrying may succeed.
8511
7033
  */
8512
- var BulkCancelWorkflowRunResultSchema = compile(discriminatedUnion("outcome", [
7034
+ var BulkCancelWorkflowRunResultSchema = discriminatedUnion("outcome", [
8513
7035
  object({
8514
7036
  runId: string(),
8515
7037
  outcome: literal("cancelled")
@@ -8533,12 +7055,12 @@ var BulkCancelWorkflowRunResultSchema = compile(discriminatedUnion("outcome", [
8533
7055
  code: string(),
8534
7056
  retryable: boolean()
8535
7057
  })
8536
- ]));
7058
+ ]);
8537
7059
  /**
8538
7060
  * Aggregate result of a bulk cancellation. `results` preserves the order of
8539
7061
  * the requested `runIds`; `summary` counts each outcome.
8540
7062
  */
8541
- var BulkCancelWorkflowRunsResultSchema = compile(object({
7063
+ var BulkCancelWorkflowRunsResultSchema = object({
8542
7064
  summary: object({
8543
7065
  requested: number$1(),
8544
7066
  cancelled: number$1(),
@@ -8548,15 +7070,15 @@ var BulkCancelWorkflowRunsResultSchema = compile(object({
8548
7070
  failed: number$1()
8549
7071
  }),
8550
7072
  results: array(BulkCancelWorkflowRunResultSchema)
8551
- }));
8552
- // ../../node_modules/.bun/@workflow+world@5.1.0/node_modules/@workflow/world/dist/steps.js
8553
- var StepStatusSchema = compile(_enum([
7073
+ });
7074
+ // ../../node_modules/.bun/@workflow+world@5.2.0/node_modules/@workflow/world/dist/steps.js
7075
+ var StepStatusSchema = _enum([
8554
7076
  "pending",
8555
7077
  "running",
8556
7078
  "completed",
8557
7079
  "failed",
8558
7080
  "cancelled"
8559
- ]));
7081
+ ]);
8560
7082
  /**
8561
7083
  * Schema for workflow steps.
8562
7084
  *
@@ -8564,7 +7086,7 @@ var StepStatusSchema = compile(_enum([
8564
7086
  * - specVersion >= 2: Uint8Array (binary devalue format)
8565
7087
  * - specVersion 1: any (legacy JSON format)
8566
7088
  */
8567
- var StepSchema = compile(object({
7089
+ var StepSchema = object({
8568
7090
  runId: string(),
8569
7091
  stepId: string(),
8570
7092
  /**
@@ -8613,18 +7135,18 @@ var StepSchema = compile(object({
8613
7135
  updatedAt: date(),
8614
7136
  retryAfter: date().optional(),
8615
7137
  specVersion: number$1().optional()
8616
- }));
8617
- var TERMINAL_STEP_STATUSES = compile(StepStatusSchema.extract([
7138
+ });
7139
+ var TERMINAL_STEP_STATUSES = StepStatusSchema.extract([
8618
7140
  "completed",
8619
7141
  "failed",
8620
7142
  "cancelled"
8621
- ])).options;
7143
+ ]).options;
8622
7144
  function isTerminalStepStatus(status) {
8623
7145
  return TERMINAL_STEP_STATUSES.includes(status);
8624
7146
  }
8625
- // ../../node_modules/.bun/@workflow+world@5.1.0/node_modules/@workflow/world/dist/waits.js
8626
- var WaitStatusSchema = compile(_enum(["waiting", "completed"]));
8627
- var WaitSchema = compile(object({
7147
+ // ../../node_modules/.bun/@workflow+world@5.2.0/node_modules/@workflow/world/dist/waits.js
7148
+ var WaitStatusSchema = _enum(["waiting", "completed"]);
7149
+ var WaitSchema = object({
8628
7150
  waitId: string(),
8629
7151
  runId: string(),
8630
7152
  status: WaitStatusSchema,
@@ -8633,8 +7155,8 @@ var WaitSchema = compile(object({
8633
7155
  createdAt: date(),
8634
7156
  updatedAt: date(),
8635
7157
  specVersion: number$1().optional()
8636
- }));
8637
- // ../../node_modules/.bun/@workflow+world@5.1.0/node_modules/@workflow/world/dist/analytics.js
7158
+ });
7159
+ // ../../node_modules/.bun/@workflow+world@5.2.0/node_modules/@workflow/world/dist/analytics.js
8638
7160
  /**
8639
7161
  * Timezone-naive datetime string, e.g. `2026-07-13 17:09:11.593`: the
8640
7162
  * shape ClickHouse-backed analytics endpoints serialize `DateTime64`
@@ -8654,14 +7176,14 @@ var NAIVE_DATETIME = /^\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}:\d{2}(?:\.\d+)?$/;
8654
7176
  * offset), and non-string inputs (Date, epoch number), are forwarded
8655
7177
  * without modification before coercion.
8656
7178
  */
8657
- var UTCDateSchema = compile(preprocess((value) => {
7179
+ var UTCDateSchema = preprocess((value) => {
8658
7180
  if (typeof value === "string" && NAIVE_DATETIME.test(value)) return `${value.replace(" ", "T")}Z`;
8659
7181
  return value;
8660
- }, date()));
8661
- var NullableDateSchema = compile(UTCDateSchema.nullable().optional());
8662
- var NullableStringSchema = compile(string().nullable().optional());
8663
- var NullableBooleanSchema = compile(boolean().nullable().optional());
8664
- var AnalyticsRunSchema = compile(object({
7182
+ }, date());
7183
+ var NullableDateSchema = UTCDateSchema.nullable().optional();
7184
+ var NullableStringSchema = string().nullable().optional();
7185
+ var NullableBooleanSchema = boolean().nullable().optional();
7186
+ var AnalyticsRunSchema = object({
8665
7187
  runId: string(),
8666
7188
  status: WorkflowRunStatusSchema,
8667
7189
  deploymentId: string(),
@@ -8675,8 +7197,8 @@ var AnalyticsRunSchema = compile(object({
8675
7197
  errorCode: NullableStringSchema,
8676
7198
  workflowCoreVersion: NullableStringSchema,
8677
7199
  workflowEncryptionEnabled: NullableBooleanSchema
8678
- }));
8679
- var AnalyticsStepSchema = compile(object({
7200
+ });
7201
+ var AnalyticsStepSchema = object({
8680
7202
  runId: string(),
8681
7203
  stepId: string(),
8682
7204
  stepName: NullableStringSchema,
@@ -8692,8 +7214,8 @@ var AnalyticsStepSchema = compile(object({
8692
7214
  workflowEncryptionEnabled: NullableBooleanSchema,
8693
7215
  /** Compute instance of the latest attempt's `step_started`. */
8694
7216
  computeInstanceId: NullableStringSchema
8695
- }));
8696
- var AnalyticsEventSchema = compile(object({
7217
+ });
7218
+ var AnalyticsEventSchema = object({
8697
7219
  runId: string(),
8698
7220
  eventId: string(),
8699
7221
  eventType: EventTypeSchema,
@@ -8717,8 +7239,8 @@ var AnalyticsEventSchema = compile(object({
8717
7239
  isWebhook: NullableBooleanSchema,
8718
7240
  isSystem: NullableBooleanSchema,
8719
7241
  workflowEncryptionEnabled: NullableBooleanSchema
8720
- }));
8721
- var AnalyticsHookSchema = compile(object({
7242
+ });
7243
+ var AnalyticsHookSchema = object({
8722
7244
  runId: string(),
8723
7245
  hookId: string(),
8724
7246
  status: _enum([
@@ -8735,8 +7257,8 @@ var AnalyticsHookSchema = compile(object({
8735
7257
  isSystem: NullableBooleanSchema,
8736
7258
  workflowCoreVersion: NullableStringSchema,
8737
7259
  workflowEncryptionEnabled: NullableBooleanSchema
8738
- }));
8739
- var AnalyticsWaitSchema = compile(object({
7260
+ });
7261
+ var AnalyticsWaitSchema = object({
8740
7262
  runId: string(),
8741
7263
  waitId: string(),
8742
7264
  status: WaitStatusSchema,
@@ -8746,13 +7268,13 @@ var AnalyticsWaitSchema = compile(object({
8746
7268
  completedAt: NullableDateSchema,
8747
7269
  workflowCoreVersion: NullableStringSchema,
8748
7270
  workflowEncryptionEnabled: NullableBooleanSchema
8749
- }));
8750
- var AnalyticsAttributeKeySchema = compile(object({
7271
+ });
7272
+ var AnalyticsAttributeKeySchema = object({
8751
7273
  key: string(),
8752
7274
  runCount: number(),
8753
7275
  firstSeenAt: UTCDateSchema,
8754
7276
  lastSeenAt: UTCDateSchema
8755
- }));
7277
+ });
8756
7278
  /**
8757
7279
  * Maximum `pagination.limit` the run-scoped analytics listings accept:
8758
7280
  * `events.list`, `events.listByCorrelationId`, `steps.list`, `waits.list`.
@@ -8764,7 +7286,7 @@ var AnalyticsAttributeKeySchema = compile(object({
8764
7286
  * empty result. Failing in-process with the bound named is diagnosable.
8765
7287
  */
8766
7288
  var ANALYTICS_RUN_SCOPED_PAGE_LIMIT = 1e3;
8767
- // ../../node_modules/.bun/@workflow+world@5.1.0/node_modules/@workflow/world/dist/capabilities.js
7289
+ // ../../node_modules/.bun/@workflow+world@5.2.0/node_modules/@workflow/world/dist/capabilities.js
8768
7290
  var flag = boolean().optional().catch(void 0);
8769
7291
  var activeFlag = object({ active: boolean() }).optional().catch(void 0);
8770
7292
  /**
@@ -8801,7 +7323,7 @@ function parseWorldCapabilities(value) {
8801
7323
  if (!parsed) return void 0;
8802
7324
  return Object.fromEntries(Object.entries(parsed).filter(([, v]) => v !== void 0));
8803
7325
  }
8804
- // ../../node_modules/.bun/@workflow+world@5.1.0/node_modules/@workflow/world/dist/env-config.js
7326
+ // ../../node_modules/.bun/@workflow+world@5.2.0/node_modules/@workflow/world/dist/env-config.js
8805
7327
  /**
8806
7328
  * Helpers for resolving numeric runtime-tuning constants from environment
8807
7329
  * variables.
@@ -8908,27 +7430,17 @@ function getMaxEventsForRun(run) {
8908
7430
  */
8909
7431
  var SPEC_VERSION_ENV_VAR = "WORKFLOW_SPEC_VERSION";
8910
7432
  /**
8911
- * Environment variable that opts new runs out of the sealed log: `0` or
8912
- * `false` creates runs at {@link SPEC_VERSION_SUPPORTS_SLOT_IDENTITY}, as it
8913
- * did before {@link SPEC_VERSION_ENV_VAR} existed. Read only while
8914
- * {@link SPEC_VERSION_ENV_VAR} is unset.
8915
- *
8916
- * @deprecated Set {@link SPEC_VERSION_ENV_VAR} instead.
8917
- */
8918
- var SEALED_LOG_ENV_VAR = "WORKFLOW_SEALED_LOG";
8919
- /**
8920
7433
  * The spec version a World should stamp on the runs it creates.
8921
7434
  *
8922
7435
  * | `WORKFLOW_SPEC_VERSION` | `inBandFence` | returns |
8923
7436
  * |---|---|---|
8924
- * | unset | any | {@link SPEC_VERSION_DEFAULT_MINTED} (8), or {@link SPEC_VERSION_SUPPORTS_SLOT_IDENTITY} (6) with `WORKFLOW_SEALED_LOG=0` |
7437
+ * | unset | any | {@link SPEC_VERSION_DEFAULT_MINTED} (8) |
8925
7438
  * | `9` | `true` | {@link SPEC_VERSION_SINGLE_ORCHESTRATOR} |
8926
7439
  * | `9` | not `true` | the default, with a warning once per process |
8927
7440
  * | `6` to `8` | any | that version |
8928
7441
  * | anything else | any | the default, with a warning once per process |
8929
7442
  *
8930
- * Values are trimmed. When both variables are set, `WORKFLOW_SPEC_VERSION`
8931
- * wins and a warning is logged once.
7443
+ * Values are trimmed.
8932
7444
  *
8933
7445
  * A call with no options never returns 9. A World written to an earlier
8934
7446
  * "Building a World" guide, which declares `specVersion: mintedSpecVersion()`,
@@ -8952,14 +7464,11 @@ var SEALED_LOG_ENV_VAR = "WORKFLOW_SEALED_LOG";
8952
7464
  * created.
8953
7465
  */
8954
7466
  function mintedSpecVersion(env = process.env, options = {}) {
8955
- const sealedLogRaw = env[SEALED_LOG_ENV_VAR];
8956
- const sealedLogSet = sealedLogRaw !== void 0 && sealedLogRaw !== "";
8957
- const fallback = envFlag("WORKFLOW_SEALED_LOG", true, env) ? 8 : 6;
7467
+ const fallback = 8;
8958
7468
  const requested = env[SPEC_VERSION_ENV_VAR]?.trim();
8959
7469
  if (requested !== void 0 && requested !== "") {
8960
7470
  const version = Number(requested);
8961
7471
  if (/^\d+$/.test(requested) && version >= 6 && version <= 9) {
8962
- if (sealedLogSet) warnOnce(`${SEALED_LOG_ENV_VAR}+${SPEC_VERSION_ENV_VAR}`, `${SPEC_VERSION_ENV_VAR} and ${SEALED_LOG_ENV_VAR} are both set; new runs use ${SPEC_VERSION_ENV_VAR}=${version} and ${SEALED_LOG_ENV_VAR} is ignored.`);
8963
7472
  if (version >= 9 && options.inBandFence !== true) {
8964
7473
  warnOnce(`${SPEC_VERSION_ENV_VAR}=${requested}:no-fence`, `Ignoring ${SPEC_VERSION_ENV_VAR}=${version}: the World does not declare the in-band writer fence (capabilities.inBandFence) that spec 9 runs need, so new runs use spec ${fallback}.`);
8965
7474
  return fallback;
@@ -8996,7 +7505,7 @@ function requiresNewerWorld(v) {
8996
7505
  if (v === void 0 || v === null) return false;
8997
7506
  return v > 9;
8998
7507
  }
8999
- // ../../node_modules/.bun/@workflow+world@5.1.0/node_modules/@workflow/world/dist/queue.js
7508
+ // ../../node_modules/.bun/@workflow+world@5.2.0/node_modules/@workflow/world/dist/queue.js
9000
7509
  /**
9001
7510
  * Pattern matching valid queue prefixes:
9002
7511
  * - `__wkf_workflow_` (default, no namespace)
@@ -9004,9 +7513,9 @@ function requiresNewerWorld(v) {
9004
7513
  *
9005
7514
  * Namespace must be lowercase alphanumeric starting with a letter.
9006
7515
  */
9007
- var QueuePrefix = compile(string().regex(/^__(?:[a-z][a-z0-9]*_)?wkf_workflow_$/, "Must match __wkf_workflow_ or __{namespace}_wkf_workflow_"));
9008
- var ValidQueueName = compile(string().regex(/^__(?:[a-z][a-z0-9]*_)?wkf_workflow_.+$/, "Must be a valid queue name with a recognized prefix"));
9009
- var QueueNamespace = compile(string().regex(/^[a-z][a-z0-9]*$/, "Must be lowercase alphanumeric, starting with a letter"));
7516
+ var QueuePrefix = string().regex(/^__(?:[a-z][a-z0-9]*_)?wkf_workflow_$/, "Must match __wkf_workflow_ or __{namespace}_wkf_workflow_");
7517
+ var ValidQueueName = string().regex(/^__(?:[a-z][a-z0-9]*_)?wkf_workflow_.+$/, "Must be a valid queue name with a recognized prefix");
7518
+ var QueueNamespace = string().regex(/^[a-z][a-z0-9]*$/, "Must be lowercase alphanumeric, starting with a letter");
9010
7519
  /**
9011
7520
  * Resolves the active queue namespace from an explicit argument or the
9012
7521
  * `WORKFLOW_QUEUE_NAMESPACE` env var.
@@ -9067,18 +7576,18 @@ function parseQueueName(name) {
9067
7576
  id: match[2]
9068
7577
  };
9069
7578
  }
9070
- var MessageId = compile(string().brand().describe("A stored queue message ID"));
7579
+ var MessageId = string().brand().describe("A stored queue message ID");
9071
7580
  /**
9072
7581
  * OpenTelemetry trace context for distributed tracing
9073
7582
  */
9074
- var TraceCarrierSchema = compile(record(string(), string()));
7583
+ var TraceCarrierSchema = record(string(), string());
9075
7584
  /**
9076
7585
  * Run creation data carried through the queue for resilient start.
9077
7586
  * Only present on the first queue delivery: re-enqueues omit this.
9078
7587
  * When the runtime processes the message, it passes this data to the
9079
7588
  * run_started event so the server can create the run if it doesn't exist yet.
9080
7589
  */
9081
- var RunInputSchema = compile(object({
7590
+ var RunInputSchema = object({
9082
7591
  input: unknown(),
9083
7592
  deploymentId: string(),
9084
7593
  workflowName: string(),
@@ -9130,7 +7639,7 @@ var RunInputSchema = compile(object({
9130
7639
  }).refine((value) => value.dynamicWorkflowCode === void 0 || value.dynamicWorkflowCodeRef === void 0, {
9131
7640
  path: ["dynamicWorkflowCodeRef"],
9132
7641
  message: "dynamicWorkflowCode and dynamicWorkflowCodeRef are mutually exclusive"
9133
- }));
7642
+ });
9134
7643
  /**
9135
7644
  * Legacy lazy hook resume data carried through the queue alongside a workflow
9136
7645
  * invocation. Older producers publish this invocation and write no event of
@@ -9166,7 +7675,7 @@ var RunInputSchema = compile(object({
9166
7675
  * it publishes a step message only after its `step_created` write. The schema
9167
7676
  * keeps accepting it so a message that carries it still parses.
9168
7677
  */
9169
- var StepDispatchInputSchema = compile(object({
7678
+ var StepDispatchInputSchema = object({
9170
7679
  /**
9171
7680
  * The serialized step input, reused verbatim from the direct write. Always
9172
7681
  * binary: producers only attach `stepInput` when the dehydrated input is a
@@ -9175,7 +7684,7 @@ var StepDispatchInputSchema = compile(object({
9175
7684
  * message parse instead of being silently written into a `step_created` as
9176
7685
  * non-binary data. `Buffer` is a `Uint8Array` subclass and passes.
9177
7686
  */
9178
- input: custom((value) => value instanceof Uint8Array, { message: "stepInput.input must be a Uint8Array" }) }));
7687
+ input: custom((value) => value instanceof Uint8Array, { message: "stepInput.input must be a Uint8Array" }) });
9179
7688
  /**
9180
7689
  * Immutable run identity carried on a step-execution message so the consumer
9181
7690
  * can start the step without a blocking `runs.get` round trip. Every field is
@@ -9188,7 +7697,7 @@ input: custom((value) => value instanceof Uint8Array, { message: "stepInput.inpu
9188
7697
  * still fetch it lazily; messages without this field (older producers) take
9189
7698
  * the legacy `runs.get` prologue.
9190
7699
  */
9191
- var RunDispatchContextSchema = compile(object({
7700
+ var RunDispatchContextSchema = object({
9192
7701
  /** The deployment the run is pinned to (`WorkflowRun.deploymentId`). */
9193
7702
  deploymentId: string(),
9194
7703
  /** The run's spec version (`WorkflowRun.specVersion`). */
@@ -9198,8 +7707,8 @@ var RunDispatchContextSchema = compile(object({
9198
7707
  startedAt: number$1().optional(),
9199
7708
  /** The run's lineage root (its `$rootRunId` attribute, or its own id). */
9200
7709
  rootRunId: string().optional()
9201
- }));
9202
- var HookResumeInputSchema = compile(object({
7710
+ });
7711
+ var HookResumeInputSchema = object({
9203
7712
  /** Stable idempotency key minted once per `resumeHook()` call. */
9204
7713
  resumeId: string(),
9205
7714
  /** The hook being resumed. */
@@ -9231,7 +7740,7 @@ var HookResumeInputSchema = compile(object({
9231
7740
  * check (the authoritative guard before replay still protects them).
9232
7741
  */
9233
7742
  deploymentId: string().optional()
9234
- }));
7743
+ });
9235
7744
  /**
9236
7745
  * Wall-clock boundaries of a hook-triggered resume, carried on the queue
9237
7746
  * message so the SDK can report end-to-end time-to-resume (TTR, entry into
@@ -9254,14 +7763,14 @@ var HookResumeInputSchema = compile(object({
9254
7763
  * Every field is advisory and the whole object is optional, in all three
9255
7764
  * directions that matter for a rolling deploy: a new producer's timing is
9256
7765
  * ignored by an old consumer, a new consumer reports no TTR for an old
9257
- * message, and workflow-server never reads it at all.
7766
+ * message, and the world-vercel backend never reads it at all.
9258
7767
  *
9259
7768
  * `strategy` and `setupSource` are deliberately typed as plain strings rather
9260
7769
  * than enums: an unrecognized value from a newer producer must not fail the
9261
7770
  * parse of the whole invocation payload (which would wedge the run), since it
9262
7771
  * is only ever forwarded to a span attribute.
9263
7772
  */
9264
- var HookResumeTimingSchema = compile(object({
7773
+ var HookResumeTimingSchema = object({
9265
7774
  /** Epoch ms at entry into `resumeHook()`: the start of the TTR window. */
9266
7775
  resumeRequestedAtMs: number$1(),
9267
7776
  /** Epoch ms immediately before the queue publish was requested. */
@@ -9280,8 +7789,8 @@ var HookResumeTimingSchema = compile(object({
9280
7789
  nextStepEncounteredAtMs: number$1().optional(),
9281
7790
  /** How the consumer initialized replay state: see `ResumeSetupSource`. */
9282
7791
  setupSource: string().optional()
9283
- }));
9284
- var WorkflowInvokePayloadSchema = compile(object({
7792
+ });
7793
+ var WorkflowInvokePayloadSchema = object({
9285
7794
  runId: string(),
9286
7795
  /**
9287
7796
  * The run's persisted spec version (`WorkflowRun.specVersion`), which picks
@@ -9472,7 +7981,7 @@ var WorkflowInvokePayloadSchema = compile(object({
9472
7981
  * telemetry field. Anything unparseable degrades to "no measurement".
9473
7982
  */
9474
7983
  hookResumeTiming: HookResumeTimingSchema.optional().catch(void 0)
9475
- }));
7984
+ });
9476
7985
  /**
9477
7986
  * Health check MUST come first.
9478
7987
  *
@@ -9487,7 +7996,7 @@ var WorkflowInvokePayloadSchema = compile(object({
9487
7996
  * Ordering health check first is safe in the other direction: it requires
9488
7997
  * `__healthCheck: true`, which an invoke payload never carries.
9489
7998
  */
9490
- var QueuePayloadSchema = compile(union([compile(object({
7999
+ var QueuePayloadSchema = union([object({
9491
8000
  __healthCheck: literal(true),
9492
8001
  correlationId: string(),
9493
8002
  /**
@@ -9514,7 +8023,7 @@ var QueuePayloadSchema = compile(union([compile(object({
9514
8023
  * back from this deployment; never sent.
9515
8024
  */
9516
8025
  runId: string().optional()
9517
- })), WorkflowInvokePayloadSchema]));
8026
+ }), WorkflowInvokePayloadSchema]);
9518
8027
  /**
9519
8028
  * The run whose orchestrator a queue message is a delivery for, or
9520
8029
  * `undefined` when the message is not an orchestrator delivery.
@@ -9693,18 +8202,18 @@ function singleOrchestratorContinuationPayload(payload) {
9693
8202
  continuation.runSpecVersion = messageRunSpecVersion(payload);
9694
8203
  return continuation;
9695
8204
  }
9696
- // ../../node_modules/.bun/@workflow+world@5.1.0/node_modules/@workflow/world/dist/hooks.js
8205
+ // ../../node_modules/.bun/@workflow+world@5.2.0/node_modules/@workflow/world/dist/hooks.js
9697
8206
  /**
9698
8207
  * Minimal, immutable slice of a hook's owning run needed to resume it:
9699
8208
  * enough for encryption-key resolution, serialization/compression capability
9700
8209
  * selection, queue routing, and trace linking, without fetching the full run.
9701
8210
  *
9702
- * Persisted on new hook records (workflow-server) and also returned inline by
8211
+ * Persisted on new hook records (world-vercel) and also returned inline by
9703
8212
  * `getByToken`, so a resume can skip the separate `runs.get`. Deliberately
9704
8213
  * excludes the run's mutable state (e.g. status), inputs/outputs, attributes,
9705
8214
  * and any secret: only fields that are fixed at hook-creation time.
9706
8215
  */
9707
- var HookResumeContextSchema = compile(object({
8216
+ var HookResumeContextSchema = object({
9708
8217
  deploymentId: string(),
9709
8218
  workflowName: string(),
9710
8219
  runSpecVersion: number$1().optional(),
@@ -9713,7 +8222,7 @@ var HookResumeContextSchema = compile(object({
9713
8222
  traceCarrier: TraceCarrierSchema.optional(),
9714
8223
  encryptionPublicKey: string().optional(),
9715
8224
  hookResumeInputVersion: number$1().optional()
9716
- }));
8225
+ });
9717
8226
  /**
9718
8227
  * Backend-attested capabilities for lazy hook resume, computed FRESH on every
9719
8228
  * by-token hook lookup and returned inline on {@link HookSchema.resumeCapabilities}.
@@ -9726,7 +8235,7 @@ var HookResumeContextSchema = compile(object({
9726
8235
  * `hookResumeInputVersion`, which attests the *consumer* and is fixed at run
9727
8236
  * creation.)
9728
8237
  */
9729
- var HookResumeCapabilitiesSchema = compile(object({ hookResumeDedupVersion: number$1() }));
8238
+ var HookResumeCapabilitiesSchema = object({ hookResumeDedupVersion: number$1() });
9730
8239
  /**
9731
8240
  * Schema for workflow hooks.
9732
8241
  *
@@ -9746,14 +8255,14 @@ var HookResumeCapabilitiesSchema = compile(object({ hookResumeDedupVersion: numb
9746
8255
  * for a legacy victim; when absent the runtime skips the wake and the victim
9747
8256
  * reads the row on its next invocation.
9748
8257
  */
9749
- var HookClaimedFromSchema = compile(object({
8258
+ var HookClaimedFromSchema = object({
9750
8259
  runId: string(),
9751
8260
  hookId: string(),
9752
8261
  workflowName: string().optional(),
9753
8262
  deploymentId: string().optional(),
9754
8263
  runSpecVersion: number$1().optional()
9755
- }));
9756
- var HookSchema = compile(object({
8264
+ });
8265
+ var HookSchema = object({
9757
8266
  runId: string(),
9758
8267
  hookId: string(),
9759
8268
  token: string(),
@@ -9769,8 +8278,8 @@ var HookSchema = compile(object({
9769
8278
  resumeContext: HookResumeContextSchema.optional(),
9770
8279
  resumeCapabilities: HookResumeCapabilitiesSchema.optional(),
9771
8280
  claimedFrom: HookClaimedFromSchema.optional()
9772
- }));
9773
- // ../../node_modules/.bun/@workflow+world@5.1.0/node_modules/@workflow/world/dist/node-http-flag.js
8281
+ });
8282
+ // ../../node_modules/.bun/@workflow+world@5.2.0/node_modules/@workflow/world/dist/node-http-flag.js
9774
8283
  /**
9775
8284
  * Transport selection for the HTTP-backed Worlds (Vercel and local).
9776
8285
  *
@@ -9805,7 +8314,7 @@ var NODE_HTTP_ENV_VAR = "WORKFLOW_NODE_HTTP";
9805
8314
  function isNodeHttpEnabled(env = process.env) {
9806
8315
  return envFlag(NODE_HTTP_ENV_VAR, false, env);
9807
8316
  }
9808
- // ../../node_modules/.bun/@workflow+world@5.1.0/node_modules/@workflow/world/dist/recovery.js
8317
+ // ../../node_modules/.bun/@workflow+world@5.2.0/node_modules/@workflow/world/dist/recovery.js
9809
8318
  /**
9810
8319
  * Re-enqueue all active (pending/running) workflow runs so they resume
9811
8320
  * processing after a world restart. The workflow handler is idempotent
@@ -9874,7 +8383,7 @@ function isDebugEnabled() {
9874
8383
  if (typeof debug !== "string") return false;
9875
8384
  return debug.includes("workflow:") || debug === "*";
9876
8385
  }
9877
- // ../../node_modules/.bun/@workflow+world@5.1.0/node_modules/@workflow/world/dist/shared.js
8386
+ // ../../node_modules/.bun/@workflow+world@5.2.0/node_modules/@workflow/world/dist/shared.js
9878
8387
  var zodJsonSchema = lazy(() => {
9879
8388
  return union([
9880
8389
  string(),
@@ -9885,26 +8394,26 @@ var zodJsonSchema = lazy(() => {
9885
8394
  record(string(), zodJsonSchema)
9886
8395
  ]);
9887
8396
  });
9888
- var PageInfoSchema = compile(object({
8397
+ var PageInfoSchema = object({
9889
8398
  currentLookbackDays: number$1(),
9890
8399
  maxLookbackDays: number$1(),
9891
8400
  currentWindowStart: date(),
9892
8401
  maxWindowStart: date(),
9893
8402
  upgradeAvailable: boolean()
9894
- }));
8403
+ });
9895
8404
  var paginatedResponseSchemas = /* @__PURE__ */ new WeakMap();
9896
- function compilePaginatedResponse(dataSchema) {
9897
- return compile(object({
8405
+ function buildPaginatedResponse(dataSchema) {
8406
+ return object({
9898
8407
  data: array(dataSchema),
9899
8408
  cursor: string().nullable(),
9900
8409
  hasMore: boolean(),
9901
8410
  pageInfo: PageInfoSchema.optional()
9902
- }));
8411
+ });
9903
8412
  }
9904
8413
  var PaginatedResponseSchema = (dataSchema) => {
9905
8414
  const cached = paginatedResponseSchemas.get(dataSchema);
9906
8415
  if (cached) return cached;
9907
- const schema = compilePaginatedResponse(dataSchema);
8416
+ const schema = buildPaginatedResponse(dataSchema);
9908
8417
  paginatedResponseSchemas.set(dataSchema, schema);
9909
8418
  return schema;
9910
8419
  };
@@ -9918,11 +8427,11 @@ function entityResolveData(resolveData) {
9918
8427
  /**
9919
8428
  * A standard error schema shape for propogating errors from runs and steps
9920
8429
  */
9921
- var StructuredErrorSchema = compile(object({
8430
+ var StructuredErrorSchema = object({
9922
8431
  message: string(),
9923
8432
  stack: string().optional(),
9924
8433
  code: string().optional()
9925
- }));
8434
+ });
9926
8435
  /**
9927
8436
  * Leading zeros a slot body must carry.
9928
8437
  *
@@ -9980,7 +8489,28 @@ function eventIdToSlot(eventId) {
9980
8489
  const slot = Number(body);
9981
8490
  return Number.isSafeInteger(slot) && slot >= 1 ? slot : null;
9982
8491
  }
9983
- // ../../node_modules/.bun/@workflow+world@5.1.0/node_modules/@workflow/world/dist/snapshots.js
8492
+ /**
8493
+ * Whether `event` records its run's creation: the run's `run_created`, or a
8494
+ * `run_started` at the first slot.
8495
+ *
8496
+ * On a single-orchestrator (spec >= 9) run whose resilient `run_started`
8497
+ * created it, that `run_started` takes the first slot with the creation data
8498
+ * a `run_created` would carry (`input`, `deploymentId`, `workflowName`,
8499
+ * `executionContext`, `attributes`, `encryptionPublicKey`, `startHook`), and
8500
+ * the log has no `run_created`. Only a creation can hold the first slot, so
8501
+ * the position identifies it even when the event was listed without its
8502
+ * payload.
8503
+ *
8504
+ * A World that writes this shape keeps the in-band count a log with a
8505
+ * `run_created` would have: the creation holds `IN_BAND_SEQ_AT_RUN_CREATION`
8506
+ * and the start the next position, and the `run_started` write reports
8507
+ * `allocated: 1`. Its writer cannot infer that allocation from the slot, which
8508
+ * it may already count as the creation's.
8509
+ */
8510
+ function isRunCreationEvent(event) {
8511
+ return event.eventType === "run_created" || event.eventType === "run_started" && eventIdToSlot(event.eventId) === 1;
8512
+ }
8513
+ // ../../node_modules/.bun/@workflow+world@5.2.0/node_modules/@workflow/world/dist/snapshots.js
9984
8514
  /**
9985
8515
  * VM snapshot storage types and helpers backing
9986
8516
  * `Storage.experimental_snapshots`.
@@ -10261,15 +8791,15 @@ function ulid(seedTime, prng) {
10261
8791
  const currentPRNG = prng || detectPRNG();
10262
8792
  return encodeTime(!seedTime || isNaN(seedTime) ? Date.now() : seedTime, 10) + encodeRandom(RANDOM_LEN, currentPRNG);
10263
8793
  }
10264
- // ../../node_modules/.bun/@workflow+world@5.1.0/node_modules/@workflow/world/dist/ulid.js
10265
- var UlidSchema = compile(string().ulid());
8794
+ // ../../node_modules/.bun/@workflow+world@5.2.0/node_modules/@workflow/world/dist/ulid.js
8795
+ var UlidSchema = string().ulid();
10266
8796
  /**
10267
8797
  * A workflow run ID: the `wrun_` prefix followed by a 26-char ULID (minted
10268
8798
  * client-side in core's `start()`). Validates the exact shape (prefix plus a
10269
8799
  * well-formed ULID) rather than a loose length bound, so callers can't smuggle
10270
8800
  * arbitrary strings through APIs that persist a run ID verbatim.
10271
8801
  */
10272
- var workflowRunIdSchema = compile(templateLiteral(["wrun_", ulid$1()]));
8802
+ var workflowRunIdSchema = templateLiteral(["wrun_", ulid$1()]);
10273
8803
  /**
10274
8804
  * Default threshold for ULID timestamps in the past (24 hours).
10275
8805
  *
@@ -10320,6 +8850,6 @@ function validateUlidTimestamp(prefixedUlid, prefix, pastThresholdMs = DEFAULT_T
10320
8850
  if (diffMs <= 0 && -diffMs <= futureThresholdMs) return null;
10321
8851
  return `Invalid runId timestamp: embedded timestamp is ${Math.round(Math.abs(diffMs) / 1e3)}s in the ${diffMs > 0 ? "past" : "future"} (threshold: ${Math.round((diffMs > 0 ? pastThresholdMs : futureThresholdMs) / 1e3)}s)`;
10322
8852
  }
10323
- // ../../node_modules/.bun/@workflow+world@5.1.0/node_modules/@workflow/world/dist/index.js
8853
+ // ../../node_modules/.bun/@workflow+world@5.2.0/node_modules/@workflow/world/dist/index.js
10324
8854
  var dist_exports = /* @__PURE__ */ __exportAll({ HookSchema: () => HookSchema });
10325
- export { WorkflowRunSchema as $, resolveQueueNamespace as A, _instanceof as At, ANALYTICS_RUN_SCOPED_PAGE_LIMIT as B, record as Bt, WORKFLOW_FLOW_ROUTE as C, readRunRetention as Ct, orchestratorRunIdOf as D, number as Dt, isSingleOrchestratorMessage as E, date as Et, requiresNewerWorld as F, discriminatedUnion as Ft, AnalyticsStepSchema as G, _isoDateTime as Gt, AnalyticsEventSchema as H, union as Ht, envNumber as I, literal as It, StepSchema as J, AnalyticsWaitSchema as K, compile as Kt, getMaxEventsForRun as L, number$1 as Lt, singleOrchestratorRunIdOf as M, any as Mt, isLegacySpecVersion as N, array as Nt, parseQueueName as O, ZodISODateTime as Ot, mintedSpecVersion as P, boolean as Pt, WorkflowRunBaseSchema as Q, getMaxEventsPerRun as R, object as Rt, ValidQueueName as S, applyAttributeChanges as St, getRunQueueNamespace as T, validateAttributeEventDataSize as Tt, AnalyticsHookSchema as U, unknown as Ut, AnalyticsAttributeKeySchema as V, string as Vt, AnalyticsRunSchema as W, ZodError as Wt, BulkCancelWorkflowRunsRequestSchema as X, isTerminalStepStatus as Y, BulkCancelWorkflowRunsResultSchema as Z, isNodeHttpEnabled as _, AttributeValueSchema as _t, decodeTime as a, isHookLifecycleEventType as at, QueuePayloadSchema as b, RETENTION_ATTRIBUTE as bt, decodeSnapshotEnvelope as c, isTerminalStepEventType as ct, isSlotEventId as d, START_HOOK_CANDIDATE_MAX_AGE_MS as dt, isTerminalWorkflowRunStatus as et, slotToEventId as f, START_HOOK_WIRE_CODES as ft, reenqueueActiveRuns as g, AttributeKeySchema as gt, entityResolveData as h, SerializedDataSchema as ht, workflowRunIdSchema as i, isHookEventRequiringExistence as it, singleOrchestratorContinuationPayload as j, _undefined as jt, parseQueueRoute as k, _enum as kt, encodeSnapshotEnvelope as l, isWaitEventType as lt, StructuredErrorSchema as m, startHookId as mt, ulidToDate as n, EventTypeSchema as nt, monotonicFactory as o, isStepEventType as ot, PaginatedResponseSchema as p, isStartHookId as pt, WaitSchema as q, validateUlidTimestamp as r, isChildEntityCreationEvent as rt, ulid as s, isTerminalRunEventType as st, dist_exports as t, EventSchema as tt, eventIdToSlot as u, stripEventDataRefs as ut, HookSchema as v, AttributeValidationError as vt, getQueueTopicPrefix as w, validateAttributeChanges as wt, QueuePrefix as x, ROOT_RUN_ID_ATTRIBUTE as xt, MessageId as y, PARENT_RUN_ID_ATTRIBUTE as yt, parseWorldCapabilities as z, preprocess as zt };
8855
+ export { WorkflowRunBaseSchema as $, isValidIBAN as $t, parseQueueRoute as A, _enum as At, parseWorldCapabilities as B, preprocess as Bt, ValidQueueName as C, applyAttributeChanges as Ct, isSingleOrchestratorMessage as D, date as Dt, getRunQueueNamespace as E, validateAttributeEventDataSize as Et, mintedSpecVersion as F, boolean as Ft, AnalyticsRunSchema as G, ZodError as Gt, AnalyticsAttributeKeySchema as H, string as Ht, requiresNewerWorld as I, discriminatedUnion as It, WaitSchema as J, isRecursiveSchema as Jt, AnalyticsStepSchema as K, _isoDateTime as Kt, envNumber as L, literal as Lt, singleOrchestratorContinuationPayload as M, _undefined as Mt, singleOrchestratorRunIdOf as N, any as Nt, orchestratorRunIdOf as O, number as Ot, isLegacySpecVersion as P, array as Pt, BulkCancelWorkflowRunsResultSchema as Q, isValidCreditCard as Qt, getMaxEventsForRun as R, number$1 as Rt, QueuePrefix as S, ROOT_RUN_ID_ATTRIBUTE as St, getQueueTopicPrefix as T, validateAttributeChanges as Tt, AnalyticsEventSchema as U, union as Ut, ANALYTICS_RUN_SCOPED_PAGE_LIMIT as V, record as Vt, AnalyticsHookSchema as W, unknown as Wt, isTerminalStepStatus as X, isValidBase64URL as Xt, StepSchema as Y, isValidBase64 as Yt, BulkCancelWorkflowRunsRequestSchema as Z, isValidCIDRv6 as Zt, reenqueueActiveRuns as _, sizeCaps as _n, AttributeKeySchema as _t, decodeTime as a, urlProtocolOk as an, isHookEventRequiringExistence as at, MessageId as b, PARENT_RUN_ID_ATTRIBUTE as bt, decodeSnapshotEnvelope as c, number$2 as cn, isTerminalRunEventType as ct, isRunCreationEvent as d, clone as dn, stripEventDataRefs as dt, isValidIPv6 as en, WorkflowRunSchema as et, isSlotEventId as f, codePointLength as fn, START_HOOK_CANDIDATE_MAX_AGE_MS as ft, entityResolveData as g, shallowClone as gn, SerializedDataSchema as gt, StructuredErrorSchema as h, isPlainObject as hn, startHookId as ht, workflowRunIdSchema as i, urlHostnameOk as in, isChildEntityCreationEvent as it, resolveQueueNamespace as j, _instanceof as jt, parseQueueName as k, ZodISODateTime as kt, encodeSnapshotEnvelope as l, $ZodAsyncError as ln, isTerminalStepEventType as lt, PaginatedResponseSchema as m, floatSafeRemainder as mn, isStartHookId as mt, ulidToDate as n, mergeValues as nn, EventSchema as nt, monotonicFactory as o, validateURL as on, isHookLifecycleEventType as ot, slotToEventId as p, esc as pn, START_HOOK_WIRE_CODES as pt, AnalyticsWaitSchema as q, isBackEdge as qt, validateUlidTimestamp as r, stripTabAndNewline as rn, EventTypeSchema as rt, ulid as s, Doc as sn, isStepEventType as st, dist_exports as t, isValidJWT as tn, isTerminalWorkflowRunStatus as tt, eventIdToSlot as u, CONSTANT_CATCH as un, isWaitEventType as ut, isNodeHttpEnabled as v, AttributeValueSchema as vt, WORKFLOW_FLOW_ROUTE as w, readRunRetention as wt, QueuePayloadSchema as x, RETENTION_ATTRIBUTE as xt, HookSchema as y, AttributeValidationError as yt, getMaxEventsPerRun as z, object as zt };