@fluidgrids/workflows 2026.1029.1 → 2026.1030.1

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 (118) hide show
  1. package/README.md +112 -4
  2. package/dist/{activation-CESehfYi.d.cts → activation-DqUfpHzk.d.cts} +1 -1
  3. package/dist/{activation-BnVQMv9y.d.ts → activation-xpx1oWuo.d.ts} +1 -1
  4. package/dist/{chunk-MJ5TGYVG.js → chunk-2D3MYIIF.js} +969 -153
  5. package/dist/{chunk-2B37XAFQ.cjs → chunk-3U2NU7YC.cjs} +24 -11
  6. package/dist/{chunk-NEIUQASE.cjs → chunk-4QKB4ARC.cjs} +3 -3
  7. package/dist/{chunk-GBQ33SIZ.cjs → chunk-54FLQNUM.cjs} +12 -1
  8. package/dist/{chunk-2DDULZFM.js → chunk-5HIVIV53.js} +86 -75
  9. package/dist/chunk-5MFVJM76.js +1222 -0
  10. package/dist/{chunk-EWYADREB.cjs → chunk-672KMMBK.cjs} +2 -2
  11. package/dist/{chunk-KXJDRQ6G.js → chunk-6A2FGSUS.js} +22 -2
  12. package/dist/{chunk-OIX4O6UR.js → chunk-6OLN6BMB.js} +16 -3
  13. package/dist/{chunk-6FSHT5IL.js → chunk-7EZIANC7.js} +1 -1
  14. package/dist/chunk-A5SXCA62.cjs +93 -0
  15. package/dist/chunk-AC6ZEXVR.js +85 -0
  16. package/dist/{chunk-FWBRQWRX.js → chunk-AE5Q6ZAJ.js} +167 -10
  17. package/dist/{chunk-7ILGCUI6.js → chunk-C4F5KJTI.js} +142 -3
  18. package/dist/{chunk-WXXNCHUY.js → chunk-G5H32GIG.js} +1 -1
  19. package/dist/{chunk-OMY3CKUZ.cjs → chunk-GEQDGUGB.cjs} +1042 -226
  20. package/dist/{chunk-25BKWR2O.js → chunk-HCM7ZC7Q.js} +1 -1
  21. package/dist/{chunk-I47EENR4.cjs → chunk-HMZUGSMU.cjs} +673 -156
  22. package/dist/{chunk-NXFBVDOI.cjs → chunk-IQPXHQQQ.cjs} +8 -4
  23. package/dist/{chunk-RUQIMTN5.cjs → chunk-ISOIA7NV.cjs} +178 -15
  24. package/dist/chunk-JSC75O5C.cjs +167 -0
  25. package/dist/{chunk-BD7ZPG53.js → chunk-NWQ5WRLE.js} +10 -2
  26. package/dist/chunk-ODZ2IAR2.cjs +1247 -0
  27. package/dist/{chunk-FQSJI5NV.js → chunk-SR7TR5KX.js} +6 -2
  28. package/dist/{chunk-OKX3FYIM.cjs → chunk-TCTE7DX5.cjs} +3 -3
  29. package/dist/{chunk-3FIDHONL.cjs → chunk-TYF56RGB.cjs} +99 -80
  30. package/dist/{chunk-J3PYFGKA.cjs → chunk-VA4OFR72.cjs} +162 -4
  31. package/dist/chunk-VU5S5A7V.js +150 -0
  32. package/dist/{chunk-A36CCOWS.js → chunk-YEHR4NNE.js} +633 -128
  33. package/dist/{chunk-ELL2RBML.cjs → chunk-ZCGKGDCL.cjs} +23 -1
  34. package/dist/codegen/index.d.cts +2 -2
  35. package/dist/codegen/index.d.ts +2 -2
  36. package/dist/{collect-BTHjQaSp.d.ts → collect-6NIEufHd.d.ts} +20 -3
  37. package/dist/{collect-CSyOg5XC.d.cts → collect-CcTCKqx6.d.cts} +20 -3
  38. package/dist/{file-cgL9l9l8.d.cts → file-BxYpwjRQ.d.cts} +250 -15
  39. package/dist/{file-olQudcx5.d.ts → file-CFdPQJI9.d.ts} +250 -15
  40. package/dist/history/index.cjs +283 -106
  41. package/dist/history/index.d.cts +549 -10
  42. package/dist/history/index.d.ts +549 -10
  43. package/dist/history/index.js +5 -4
  44. package/dist/index.cjs +146 -53
  45. package/dist/index.d.cts +38 -14
  46. package/dist/index.d.ts +38 -14
  47. package/dist/index.js +6 -5
  48. package/dist/interceptors-CNcr2dlk.d.ts +159 -0
  49. package/dist/interceptors-CqkNZVfI.d.cts +159 -0
  50. package/dist/ir/index.cjs +339 -36
  51. package/dist/ir/index.d.cts +244 -8
  52. package/dist/ir/index.d.ts +244 -8
  53. package/dist/ir/index.js +306 -21
  54. package/dist/{lower-3S6PsqjJ.d.cts → lower-BtRfIW2A.d.cts} +23 -9
  55. package/dist/{lower-DmZpQ8hJ.d.ts → lower-CpsMFOFX.d.ts} +23 -9
  56. package/dist/{manifest-BJjrQt77.d.ts → manifest-D-I_twys.d.ts} +1 -1
  57. package/dist/{manifest-gRI2Q5Fj.d.cts → manifest-DahBQVM8.d.cts} +1 -1
  58. package/dist/node-evaluator-DGQDPSPI.cjs +24 -0
  59. package/dist/node-evaluator-LEEVD7H7.js +14 -0
  60. package/dist/payload-fields-BVRQn2yH.d.cts +122 -0
  61. package/dist/payload-fields-oOBWxDiG.d.ts +122 -0
  62. package/dist/quickjs/index.cjs +27 -27
  63. package/dist/quickjs/index.d.cts +6 -6
  64. package/dist/quickjs/index.d.ts +6 -6
  65. package/dist/quickjs/index.js +9 -9
  66. package/dist/roundtrip/index.cjs +72 -66
  67. package/dist/roundtrip/index.d.cts +25 -11
  68. package/dist/roundtrip/index.d.ts +25 -11
  69. package/dist/roundtrip/index.js +13 -11
  70. package/dist/runtime/index.cjs +19 -19
  71. package/dist/runtime/index.d.cts +139 -12
  72. package/dist/runtime/index.d.ts +139 -12
  73. package/dist/runtime/index.js +6 -6
  74. package/dist/testing/index.cjs +688 -121
  75. package/dist/testing/index.d.cts +174 -10
  76. package/dist/testing/index.d.ts +174 -10
  77. package/dist/testing/index.js +646 -82
  78. package/dist/{types-CnIOinoz.d.ts → types-Bv2i4cBX.d.cts} +126 -23
  79. package/dist/{types-CQKOhPTa.d.cts → types-DGx-b9eq.d.ts} +126 -23
  80. package/dist/{types-Bb2wRnJ5.d.cts → types-V7jEEUaL.d.cts} +1 -1
  81. package/dist/{types-Bb2wRnJ5.d.ts → types-V7jEEUaL.d.ts} +1 -1
  82. package/dist/{workflow-8uRU9rhL.d.ts → workflow-B18OeF7g.d.ts} +2 -2
  83. package/dist/{workflow-DWTPHFbt.d.ts → workflow-BGnv8SS6.d.ts} +261 -14
  84. package/dist/{workflow-CZOXUlQ5.d.cts → workflow-BJPFv3cp.d.cts} +2 -2
  85. package/dist/{workflow-O6e64ZcG.d.cts → workflow-DS32Gtws.d.cts} +261 -14
  86. package/fixtures/histories/activity-options-updated.history.json +159 -0
  87. package/fixtures/histories/activity-paused-unpaused.history.json +160 -0
  88. package/fixtures/histories/codec-opaque.history.json +229 -0
  89. package/fixtures/histories/dynamic-workflow.history.json +150 -0
  90. package/fixtures/histories/interceptor-headers.history.json +339 -0
  91. package/fixtures/histories/query-custom.history.json +213 -0
  92. package/fixtures/histories/query-default-handler.history.json +120 -0
  93. package/fixtures/histories/reset-forked-reapplied-signals.history.json +239 -0
  94. package/fixtures/histories/reset-reapplied-update-admitted.history.json +228 -0
  95. package/fixtures/histories/search-attributes-upserted.history.json +177 -0
  96. package/fixtures/histories/update-accepted-completed.history.json +45 -30
  97. package/fixtures/histories/update-default-handler.history.json +246 -0
  98. package/fixtures/histories/update-handler-awaits-activity.history.json +196 -0
  99. package/fixtures/histories/update-not-handled.history.json +138 -0
  100. package/fixtures/histories/update-rejected-no-event.history.json +190 -0
  101. package/fixtures/histories/update-with-start-admitted.history.json +150 -0
  102. package/fixtures/histories/user-activity-cancel.history.json +149 -0
  103. package/fixtures/histories/user-activity-retry.history.json +143 -0
  104. package/fixtures/histories/user-activity.history.json +149 -0
  105. package/package.json +1 -1
  106. package/schema/bridge-v2.schema.json +1062 -0
  107. package/schema/history-file.schema.json +255 -81
  108. package/schema/ir-v2.schema.json +246 -1
  109. package/schema/payload-fields.json +162 -0
  110. package/schema/run-event.schema.json +239 -80
  111. package/schema/workflow-command.schema.json +210 -84
  112. package/schema/workflow-task.schema.json +532 -167
  113. package/dist/chunk-6QPOJZT6.cjs +0 -1180
  114. package/dist/chunk-A2OHX3UQ.js +0 -1156
  115. package/dist/chunk-PWIUEWC3.js +0 -81
  116. package/dist/chunk-YHBVMOMK.cjs +0 -87
  117. package/dist/node-evaluator-SOADN23V.js +0 -14
  118. package/dist/node-evaluator-YGDEXK4U.cjs +0 -24
@@ -2,7 +2,7 @@ import { autoLayout } from './chunk-5LUIDMF4.js';
2
2
  import { makeRef, isPredicate, conditionTreeOf, BuilderError, refModelOf } from './chunk-JZ4TOOLN.js';
3
3
  import { formatRefTemplate } from './chunk-7AAZGVKD.js';
4
4
  import { isRecord, setOwn, cloneJson, ownValue } from './chunk-PMCM2OH4.js';
5
- import { isDurableWorkflow, SDK_VERSION } from './chunk-7ILGCUI6.js';
5
+ import { isDurableWorkflow, SDK_VERSION } from './chunk-C4F5KJTI.js';
6
6
 
7
7
  // src/builder/descriptors.ts
8
8
  function op(nodeType, version, operation) {
@@ -61,7 +61,11 @@ var internalNodes = {
61
61
  respondToWebhook: op("internal:respond-to-webhook"),
62
62
  sendAndWait: op("internal:send-and-wait"),
63
63
  codeWorkflow: op("internal:code-workflow"),
64
- waitForSignal: op("internal:wait-for-signal")
64
+ waitForSignal: op("internal:wait-for-signal"),
65
+ /** Phase C: signal another run (`fluidgrids.run-control`). */
66
+ signalRun: op("internal:signal-run"),
67
+ /** Phase C: upsert the run's search attributes (`fluidgrids.search-attributes`). */
68
+ setSearchAttributes: op("internal:set-search-attributes")
65
69
  };
66
70
  var nodes = {
67
71
  internal: internalNodes,
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunk6QPOJZT6_cjs = require('./chunk-6QPOJZT6.cjs');
3
+ var chunkODZ2IAR2_cjs = require('./chunk-ODZ2IAR2.cjs');
4
4
 
5
5
  // src/generated/vm-worker-source.ts
6
6
  var VM_WORKER_SOURCE = '"use strict";\n\nvar import_node_worker_threads = require("node:worker_threads");\n\nfunction isRecord(value) {\n return typeof value === "object" && value !== null && !Array.isArray(value);\n}\n\nvar DETERMINISM_VIOLATION = "DeterminismViolation";\nvar DETERMINISM_PRELUDE = `(() => {\n const NAME = ${JSON.stringify(DETERMINISM_VIOLATION)};\n const fail = (what) => {\n const error = new Error(\n what + " is not allowed in workflow code: lowering must give the same IR on every build. Read times and random values at run time instead (for example wf.now)."\n );\n error.name = NAME;\n throw error;\n };\n const lock = (target, key, value) =>\n Object.defineProperty(target, key, { value, writable: false, enumerable: false, configurable: false });\n const RealDate = Date;\n const LockedDate = function Date(...args) {\n if (new.target === undefined) return fail("Date()");\n if (args.length === 0) return fail("new Date()");\n return Reflect.construct(RealDate, args, new.target);\n };\n lock(LockedDate, "prototype", RealDate.prototype);\n lock(RealDate.prototype, "constructor", LockedDate);\n lock(LockedDate, "now", function now() { return fail("Date.now()"); });\n lock(LockedDate, "parse", RealDate.parse);\n lock(LockedDate, "UTC", RealDate.UTC);\n lock(globalThis, "Date", LockedDate);\n lock(Math, "random", function random() { return fail("Math.random()"); });\n const crypto = globalThis.crypto;\n if (crypto !== null && typeof crypto === "object") {\n for (const name of ["getRandomValues", "randomUUID"]) {\n if (typeof crypto[name] === "function") lock(crypto, name, function () { return fail("crypto." + name + "()"); });\n }\n }\n const DateTimeFormat = typeof Intl === "object" && Intl !== null ? Intl.DateTimeFormat : undefined;\n if (typeof DateTimeFormat === "function") {\n const proto = DateTimeFormat.prototype;\n const format = Object.getOwnPropertyDescriptor(proto, "format");\n if (format && typeof format.get === "function") {\n const get = format.get;\n Object.defineProperty(proto, "format", {\n get() {\n const bound = get.call(this);\n return (date) => (date === undefined ? fail("Intl.DateTimeFormat format()") : bound(date));\n },\n enumerable: false,\n configurable: false,\n });\n }\n const formatToParts = proto.formatToParts;\n if (typeof formatToParts === "function") {\n lock(proto, "formatToParts", function (date) {\n return date === undefined ? fail("Intl.DateTimeFormat formatToParts()") : formatToParts.call(this, date);\n });\n }\n }\n})();\n`;\nfunction failure(kind, message) {\n return { ok: false, failure: kind, message };\n}\n\nvar import_node_vm = require("node:vm");\nvar import_node_util = require("node:util");\nvar BUNDLE_GLOBAL = "__fluidgridsBundle";\nfunction wrap(code) {\n return `(function () {\n const describe = (error) => {\n let name = "Error";\n let message = "";\n try {\n if (error !== null && (typeof error === "object" || typeof error === "function")) {\n const n = error.name;\n if (typeof n === "string") name = n;\n const m = error.message;\n message = typeof m === "string" ? m : m === undefined ? "" + error : "" + m;\n } else {\n message = "" + error;\n }\n } catch (_) {\n message = "a value whose message cannot be read was thrown";\n }\n return (name === ${JSON.stringify(DETERMINISM_VIOLATION)} ? "D" : "E") + message;\n };\n try {\n${code}\n;const __fluidgridsValue = ${BUNDLE_GLOBAL}.__fluidgrids;\n return typeof __fluidgridsValue === "string" ? "R" + __fluidgridsValue : "N";\n } catch (error) {\n try {\n return describe(error);\n } catch (_) {\n return "Ean error that cannot be described was thrown";\n }\n }\n})()`;\n}\nfunction hostErrorFields(error) {\n if (!import_node_util.types.isNativeError(error)) return {};\n const code = Object.getOwnPropertyDescriptor(error, "code")?.value;\n const message = Object.getOwnPropertyDescriptor(error, "message")?.value;\n return {\n ...typeof code === "string" ? { code } : {},\n ...typeof message === "string" ? { message } : {}\n };\n}\nfunction decode(result) {\n const tag = result.charAt(0);\n const rest = result.slice(1);\n if (tag === "R") return { ok: true, value: rest };\n if (tag === "N")\n return failure("no-collection", "The bundle did not export a workflow collection");\n if (tag === "D") return failure("determinism", rest);\n return failure("error", rest);\n}\nfunction runInVmContext(code, timeoutMs) {\n const context = (0, import_node_vm.createContext)(/* @__PURE__ */ Object.create(null), {\n codeGeneration: { strings: false, wasm: false },\n microtaskMode: "afterEvaluate",\n name: "fluidgrids-workflow-lowering"\n });\n const refuseImport = () => {\n throw new Error("Workflow code may not import modules at run time");\n };\n const deadline = Date.now() + timeoutMs;\n const run = (source, filename) => new import_node_vm.Script(source, { filename, importModuleDynamically: refuseImport }).runInContext(context, {\n timeout: Math.max(1, deadline - Date.now()),\n breakOnSigint: true\n });\n try {\n run(DETERMINISM_PRELUDE, "determinism-prelude.js");\n const result = run(wrap(code), "workflow-bundle.js");\n return typeof result === "string" ? decode(result) : failure("no-collection", "The bundle did not export a workflow collection");\n } catch (error) {\n const fields = hostErrorFields(error);\n if (fields.code === "ERR_SCRIPT_EXECUTION_TIMEOUT" || fields.message !== void 0 && /^Script execution timed out/.test(fields.message)) {\n return failure("timeout", `Evaluating the workflow code timed out after ${timeoutMs} ms`);\n }\n return failure("error", fields.message ?? "The workflow code could not be evaluated");\n }\n}\n\nprocess.on("unhandledRejection", () => void 0);\nvar input = import_node_worker_threads.workerData;\nimport_node_worker_threads.parentPort?.postMessage(\n isRecord(input) && typeof input["code"] === "string" && typeof input["timeoutMs"] === "number" ? runInVmContext(input["code"], input["timeoutMs"]) : failure("crashed", "The evaluation worker received no bundle")\n);\n';
@@ -13,13 +13,13 @@ function createNodeVmEvaluator(options = {}) {
13
13
  return {
14
14
  format: "iife",
15
15
  async evaluate(code) {
16
- const outcome = await chunk6QPOJZT6_cjs.runIsolateWorker({
16
+ const outcome = await chunkODZ2IAR2_cjs.runIsolateWorker({
17
17
  source: VM_WORKER_SOURCE,
18
18
  workerData: { code, timeoutMs },
19
19
  timeoutMs,
20
20
  resourceLimits: { maxOldGenerationSizeMb: Math.max(16, Math.ceil(memoryLimitBytes / MIB)) }
21
21
  });
22
- return chunk6QPOJZT6_cjs.outcomeToCollection(outcome);
22
+ return chunkODZ2IAR2_cjs.outcomeToCollection(outcome);
23
23
  }
24
24
  };
25
25
  }
@@ -1,86 +1,89 @@
1
1
  'use strict';
2
2
 
3
- // src/history/allowlist.ts
4
- var ACTIVITY_INTERNAL_ALLOWLIST = /* @__PURE__ */ new Set([
5
- "internal:http",
6
- "internal:datatable",
7
- "internal:set",
8
- "internal:code"
9
- ]);
10
- var ACTIVITY_NODE_DENYLIST = /* @__PURE__ */ new Set([
11
- "internal:end",
12
- "internal:if",
13
- "internal:switch",
14
- "internal:loop",
15
- "internal:merge",
16
- "internal:wait",
17
- "internal:subworkflow",
18
- "internal:code-workflow",
19
- "internal:wait-for-signal",
20
- "internal:send-and-wait",
21
- "internal:respond-to-webhook",
22
- "internal:failure-triage"
23
- ]);
24
- var ACTIVITY_NODE_ALLOWLIST = {
25
- internal: ACTIVITY_INTERNAL_ALLOWLIST,
26
- refused: ACTIVITY_NODE_DENYLIST,
27
- /** Non-built-in node types (store and registry nodes) are allowed. */
28
- external: "allowed"
29
- };
30
- var LEGACY_SHORT_NAMES = /* @__PURE__ */ new Set([
31
- "if",
32
- "switch",
33
- "loop",
34
- "merge",
35
- "set",
36
- "filter",
37
- "aggregate",
38
- "wait",
39
- "noop",
40
- "code",
41
- "http",
42
- "transform",
43
- "validate",
44
- "log",
45
- "error",
46
- "subworkflow",
47
- "end",
48
- "trigger",
49
- "webhook",
50
- "schedule",
51
- "manual",
52
- "api"
53
- ]);
54
- function canonicalType(nodeType) {
55
- const lower = nodeType.trim().toLowerCase();
56
- return LEGACY_SHORT_NAMES.has(lower) ? `internal:${lower}` : lower;
3
+ // src/history/retry.ts
4
+ var DEFAULT_ACTIVITY_RETRY = Object.freeze({
5
+ retryDelay: 1e3,
6
+ backoffMultiplier: 2,
7
+ maxDelay: 1e5
8
+ });
9
+ var FINAL_TIMEOUTS = /* @__PURE__ */ new Set(["SCHEDULE_TO_START", "SCHEDULE_TO_CLOSE"]);
10
+ function computeRetryDelay(policy, attempt, failure) {
11
+ if (failure?.nonRetryable === true) return { retry: false, reason: "nonRetryable" };
12
+ if (failure?.timeoutType !== void 0 && FINAL_TIMEOUTS.has(failure.timeoutType))
13
+ return { retry: false, reason: "finalTimeout" };
14
+ if (failure?.type !== void 0 && policy.nonRetryableErrorTypes !== void 0 && policy.nonRetryableErrorTypes.includes(failure.type))
15
+ return { retry: false, reason: "typeDenied" };
16
+ if (failure !== void 0 && policy.retryOnErrorTypes !== void 0 && policy.retryOnErrorTypes.length > 0 && !policy.retryOnErrorTypes.includes(failure.errorType))
17
+ return { retry: false, reason: "errorTypeNotListed" };
18
+ if (policy.maxRetries !== void 0 && attempt > policy.maxRetries)
19
+ return { retry: false, reason: "maxRetries" };
20
+ if (failure?.nextRetryDelayMs !== void 0)
21
+ return { retry: true, delayMs: Math.max(0, Math.round(failure.nextRetryDelayMs)) };
22
+ const base = Math.max(0, policy.retryDelay);
23
+ const multiplier = policy.backoffMultiplier ?? 2;
24
+ const cap = policy.maxDelay ?? base * 100;
25
+ const exponent = Math.max(0, attempt - 1);
26
+ const delay = Math.min(base * Math.pow(multiplier, exponent), cap);
27
+ return { retry: true, delayMs: Math.round(Number.isFinite(delay) ? delay : cap) };
57
28
  }
58
- function isActivityNodeTypeAllowed(nodeType) {
59
- if (typeof nodeType !== "string" || nodeType.trim() === "") return false;
60
- const type = canonicalType(nodeType);
61
- if (!type.startsWith("internal:")) return true;
62
- return ACTIVITY_INTERNAL_ALLOWLIST.has(type);
29
+ function explicitRetryPolicy(policy) {
30
+ const retryDelay = policy?.retryDelay ?? DEFAULT_ACTIVITY_RETRY.retryDelay;
31
+ const out = {
32
+ retryDelay,
33
+ backoffMultiplier: policy?.backoffMultiplier ?? DEFAULT_ACTIVITY_RETRY.backoffMultiplier ?? 2,
34
+ maxDelay: policy?.maxDelay ?? (policy?.retryDelay === void 0 ? 1e5 : Math.max(retryDelay, retryDelay * 100))
35
+ };
36
+ if (policy?.maxRetries !== void 0) out.maxRetries = policy.maxRetries;
37
+ if (policy?.retryOnErrorTypes !== void 0)
38
+ out.retryOnErrorTypes = [...policy.retryOnErrorTypes];
39
+ if (policy?.nonRetryableErrorTypes !== void 0)
40
+ out.nonRetryableErrorTypes = [...policy.nonRetryableErrorTypes];
41
+ return out;
63
42
  }
64
- var ActivityNodeTypeNotAllowedError = class extends Error {
65
- constructor(nodeType) {
66
- super(
67
- `${nodeType} cannot run as a durable activity: only store and registry nodes and internal:http, internal:datatable, internal:set and internal:code can`
68
- );
69
- this.nodeType = nodeType;
70
- this.name = "ActivityNodeTypeNotAllowedError";
43
+ function computeRunRetryDelay(policy, attempt, failure) {
44
+ if (policy === void 0) return { retry: false, reason: "noPolicy" };
45
+ if (failure.timeoutType === "WORKFLOW_EXECUTION")
46
+ return { retry: false, reason: "executionTimeout" };
47
+ if (policy.maxAttempts !== void 0 && attempt >= policy.maxAttempts)
48
+ return { retry: false, reason: "maxAttempts" };
49
+ const activityPolicy = {
50
+ retryDelay: policy.initialDelayMs,
51
+ ...policy.backoffMultiplier !== void 0 ? { backoffMultiplier: policy.backoffMultiplier } : {},
52
+ ...policy.maxDelayMs !== void 0 ? { maxDelay: policy.maxDelayMs } : {},
53
+ ...policy.retryOnErrorTypes !== void 0 ? { retryOnErrorTypes: policy.retryOnErrorTypes } : {},
54
+ ...policy.nonRetryableErrorTypes !== void 0 ? { nonRetryableErrorTypes: policy.nonRetryableErrorTypes } : {}
55
+ };
56
+ const classified = { ...failure };
57
+ if (classified.timeoutType === "WORKFLOW_RUN") delete classified.timeoutType;
58
+ const decision = computeRetryDelay(activityPolicy, attempt, classified);
59
+ if (decision.retry) return decision;
60
+ switch (decision.reason) {
61
+ case "nonRetryable":
62
+ case "typeDenied":
63
+ case "errorTypeNotListed":
64
+ return { retry: false, reason: decision.reason };
65
+ default:
66
+ return { retry: false, reason: "maxAttempts" };
71
67
  }
72
- nodeType;
73
- code = "durable.activityTypeNotAllowed";
74
- errorType = "VALIDATION";
75
- nonRetryable = true;
76
- };
77
- function assertActivityNodeType(nodeType) {
78
- if (!isActivityNodeTypeAllowed(nodeType)) throw new ActivityNodeTypeNotAllowedError(nodeType);
68
+ }
69
+ function explicitRunRetryPolicy(policy) {
70
+ const initialDelayMs = policy.initialDelayMs ?? DEFAULT_ACTIVITY_RETRY.retryDelay;
71
+ const out = {
72
+ initialDelayMs,
73
+ backoffMultiplier: policy.backoffMultiplier ?? 2,
74
+ maxDelayMs: policy.maxDelayMs ?? (policy.initialDelayMs === void 0 ? 1e5 : Math.max(initialDelayMs, initialDelayMs * 100))
75
+ };
76
+ if (policy.maxAttempts !== void 0) out.maxAttempts = policy.maxAttempts;
77
+ if (policy.retryOnErrorTypes !== void 0) out.retryOnErrorTypes = [...policy.retryOnErrorTypes];
78
+ if (policy.nonRetryableErrorTypes !== void 0)
79
+ out.nonRetryableErrorTypes = [...policy.nonRetryableErrorTypes];
80
+ return out;
79
81
  }
80
82
 
81
83
  // src/history/types.ts
82
84
  var HISTORY_PROTOCOL = 1;
83
- var RUNTIME_RELEASE = 2;
85
+ var RUNTIME_RELEASE = 3;
86
+ var RUNTIME_CAPABILITIES = ["updates", "queries", "dynamic"];
84
87
  var EVENT_TYPES = [
85
88
  "WORKFLOW_STARTED",
86
89
  "WORKFLOW_TASK_SCHEDULED",
@@ -232,6 +235,14 @@ var WORKFLOW_ID_CONFLICT_POLICIES = [
232
235
  ];
233
236
  var VERSIONING_BEHAVIORS = ["PINNED", "AUTO_UPGRADE"];
234
237
  var WORKFLOW_TIMEOUT_TYPES = ["WORKFLOW_RUN", "WORKFLOW_EXECUTION"];
238
+ var FAIRNESS_KEY_MAX_LENGTH = 255;
239
+ var FAIRNESS_WEIGHT_MIN = 0.1;
240
+ var FAIRNESS_WEIGHT_MAX = 10;
241
+ var ACTIVITY_NAME_PATTERN = "^[A-Za-z_][A-Za-z0-9_.-]{0,127}$";
242
+ var TASK_QUEUE_NAME_PATTERN = "^[a-z0-9][a-z0-9-]{0,62}$";
243
+ var MAX_ACTIVITY_CONNECTIONS = 16;
244
+ var MAX_HEADERS_BYTES = 16 * 1024;
245
+ var MAX_SINK_CALLS = 256;
235
246
  var DEFAULT_HISTORY_LIMIT = { events: 1e4, bytes: 16 * 1024 * 1024 };
236
247
  var CONTINUE_AS_NEW_SUGGESTED_RATIO = 0.8;
237
248
  var HISTORY_LIMIT_EXCEEDED_RATIO = 0.95;
@@ -319,37 +330,45 @@ function isCommandEvent(event) {
319
330
  }
320
331
 
321
332
  exports.ACTIVITY_CANCELLATION_TYPES = ACTIVITY_CANCELLATION_TYPES;
322
- exports.ACTIVITY_INTERNAL_ALLOWLIST = ACTIVITY_INTERNAL_ALLOWLIST;
323
- exports.ACTIVITY_NODE_ALLOWLIST = ACTIVITY_NODE_ALLOWLIST;
324
- exports.ACTIVITY_NODE_DENYLIST = ACTIVITY_NODE_DENYLIST;
325
- exports.ActivityNodeTypeNotAllowedError = ActivityNodeTypeNotAllowedError;
333
+ exports.ACTIVITY_NAME_PATTERN = ACTIVITY_NAME_PATTERN;
326
334
  exports.BUILT_IN_QUERIES = BUILT_IN_QUERIES;
327
335
  exports.CHILD_CANCELLATION_TYPES = CHILD_CANCELLATION_TYPES;
328
336
  exports.COMMAND_EVENTS = COMMAND_EVENTS;
329
337
  exports.COMMAND_EVENT_TYPES = COMMAND_EVENT_TYPES;
330
338
  exports.COMMAND_TYPES = COMMAND_TYPES;
331
339
  exports.CONTINUE_AS_NEW_SUGGESTED_RATIO = CONTINUE_AS_NEW_SUGGESTED_RATIO;
340
+ exports.DEFAULT_ACTIVITY_RETRY = DEFAULT_ACTIVITY_RETRY;
332
341
  exports.DEFAULT_HISTORY_LIMIT = DEFAULT_HISTORY_LIMIT;
333
342
  exports.ERROR_TYPES = ERROR_TYPES;
334
343
  exports.EVENT_TYPES = EVENT_TYPES;
335
344
  exports.EXECUTION_KINDS = EXECUTION_KINDS;
345
+ exports.FAIRNESS_KEY_MAX_LENGTH = FAIRNESS_KEY_MAX_LENGTH;
346
+ exports.FAIRNESS_WEIGHT_MAX = FAIRNESS_WEIGHT_MAX;
347
+ exports.FAIRNESS_WEIGHT_MIN = FAIRNESS_WEIGHT_MIN;
336
348
  exports.HISTORY_LIMIT_EXCEEDED_RATIO = HISTORY_LIMIT_EXCEEDED_RATIO;
337
349
  exports.HISTORY_PROTOCOL = HISTORY_PROTOCOL;
338
350
  exports.INPUT_EVENTS = INPUT_EVENTS;
339
351
  exports.LOCAL_ACTIVITY_MAX_TIMEOUT_MS = LOCAL_ACTIVITY_MAX_TIMEOUT_MS;
352
+ exports.MAX_ACTIVITY_CONNECTIONS = MAX_ACTIVITY_CONNECTIONS;
353
+ exports.MAX_HEADERS_BYTES = MAX_HEADERS_BYTES;
354
+ exports.MAX_SINK_CALLS = MAX_SINK_CALLS;
340
355
  exports.PARENT_CLOSE_POLICIES = PARENT_CLOSE_POLICIES;
341
356
  exports.PHASE_B_CORE_COMMANDS = PHASE_B_CORE_COMMANDS;
342
357
  exports.PHASE_B_PARITY_COMMANDS = PHASE_B_PARITY_COMMANDS;
343
358
  exports.PHASE_C_COMMANDS = PHASE_C_COMMANDS;
359
+ exports.RUNTIME_CAPABILITIES = RUNTIME_CAPABILITIES;
344
360
  exports.RUNTIME_RELEASE = RUNTIME_RELEASE;
345
361
  exports.TASK_FAILURE_CAUSES = TASK_FAILURE_CAUSES;
362
+ exports.TASK_QUEUE_NAME_PATTERN = TASK_QUEUE_NAME_PATTERN;
346
363
  exports.TERMINAL_COMMANDS = TERMINAL_COMMANDS;
347
364
  exports.TERMINAL_EVENTS = TERMINAL_EVENTS;
348
365
  exports.VERSIONING_BEHAVIORS = VERSIONING_BEHAVIORS;
349
366
  exports.WORKFLOW_ID_CONFLICT_POLICIES = WORKFLOW_ID_CONFLICT_POLICIES;
350
367
  exports.WORKFLOW_ID_REUSE_POLICIES = WORKFLOW_ID_REUSE_POLICIES;
351
368
  exports.WORKFLOW_TIMEOUT_TYPES = WORKFLOW_TIMEOUT_TYPES;
352
- exports.assertActivityNodeType = assertActivityNodeType;
353
- exports.isActivityNodeTypeAllowed = isActivityNodeTypeAllowed;
369
+ exports.computeRetryDelay = computeRetryDelay;
370
+ exports.computeRunRetryDelay = computeRunRetryDelay;
371
+ exports.explicitRetryPolicy = explicitRetryPolicy;
372
+ exports.explicitRunRetryPolicy = explicitRunRetryPolicy;
354
373
  exports.isCommandEvent = isCommandEvent;
355
374
  exports.isInputEvent = isInputEvent;
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkFR7KYWRO_cjs = require('./chunk-FR7KYWRO.cjs');
4
- var chunkYHBVMOMK_cjs = require('./chunk-YHBVMOMK.cjs');
4
+ var chunkTYF56RGB_cjs = require('./chunk-TYF56RGB.cjs');
5
5
 
6
6
  // src/durable/durations.ts
7
7
  function toMs(value, what = "duration") {
@@ -49,6 +49,17 @@ function workflow(name, optionsOrFn, maybeFn) {
49
49
  checkRunOptions(name, options);
50
50
  return Object.freeze({ __fluidgrids: DURABLE_MARKER, name, options, fn });
51
51
  }
52
+ function dynamicWorkflow(name, optionsOrFn, maybeFn) {
53
+ const fn = typeof optionsOrFn === "function" ? optionsOrFn : maybeFn;
54
+ const options = typeof optionsOrFn === "function" ? {} : optionsOrFn ?? {};
55
+ if (typeof fn !== "function") throw new TypeError(`dynamicWorkflow("${name}") needs a function`);
56
+ const declared = workflow(
57
+ name,
58
+ options,
59
+ (ctx, input) => fn(ctx, ctx.info.workflowFn, input)
60
+ );
61
+ return Object.freeze({ ...declared, dynamic: true });
62
+ }
52
63
  function isDurableWorkflow(value) {
53
64
  return typeof value === "object" && value !== null && value.__fluidgrids === DURABLE_MARKER && typeof value.fn === "function";
54
65
  }
@@ -102,6 +113,14 @@ function interfaceOf(definition) {
102
113
  for (const update of updates)
103
114
  out.updates[update.name] = update.description !== void 0 ? { description: update.description } : {};
104
115
  }
116
+ const open = definition.options.open;
117
+ if (open !== void 0) {
118
+ const flags = {};
119
+ if (open.signals === true) flags.signals = true;
120
+ if (open.queries === true) flags.queries = true;
121
+ if (open.updates === true) flags.updates = true;
122
+ if (Object.keys(flags).length > 0) out.open = flags;
123
+ }
105
124
  return out;
106
125
  }
107
126
  var RUN_RETRY_OPTION_KEYS = /* @__PURE__ */ new Set([
@@ -135,7 +154,7 @@ function runRetryPolicyOf(retry) {
135
154
  if (retry.maxDelay !== void 0) policy.maxDelayMs = toMs(retry.maxDelay, "retry.maxDelay");
136
155
  if (retry.nonRetryableErrorTypes !== void 0)
137
156
  policy.nonRetryableErrorTypes = [...retry.nonRetryableErrorTypes];
138
- return chunkYHBVMOMK_cjs.explicitRunRetryPolicy(policy);
157
+ return chunkTYF56RGB_cjs.explicitRunRetryPolicy(policy);
139
158
  }
140
159
  function continueAsNewRetryOf(retry) {
141
160
  if (typeof retry !== "object" || retry === null || Array.isArray(retry))
@@ -147,20 +166,159 @@ function continueAsNewRetryOf(retry) {
147
166
  throw new TypeError(
148
167
  "continueAsNew retry mixes the activity retry shape (retryDelay, maxRetries) with the run-level one (maxAttempts, initialDelay); use the run-level keys"
149
168
  );
150
- return chunkYHBVMOMK_cjs.explicitRetryPolicy(retry);
169
+ return chunkTYF56RGB_cjs.explicitRetryPolicy(retry);
151
170
  }
152
171
 
153
172
  // src/generated/version.ts
154
- var SDK_VERSION = "2026.1029.1";
173
+ var SDK_VERSION = "2026.1030.1";
174
+
175
+ // src/durable/interceptors.ts
176
+ var INTERCEPTORS_MARKER = "fluidgrids.workflow-interceptors";
177
+ function workflowInterceptors(factory) {
178
+ if (typeof factory !== "function")
179
+ throw new TypeError("workflowInterceptors() needs a factory function");
180
+ return Object.freeze({ __fluidgrids: INTERCEPTORS_MARKER, factory });
181
+ }
182
+ function interceptorsFactoryOf(value) {
183
+ if (typeof value === "function") {
184
+ return value;
185
+ }
186
+ if (typeof value === "object" && value !== null && value.__fluidgrids === INTERCEPTORS_MARKER && typeof value.factory === "function")
187
+ return value.factory;
188
+ return void 0;
189
+ }
190
+ function resolveWorkflowInterceptors(factories) {
191
+ const inbound = [];
192
+ const outbound = [];
193
+ for (const factory of factories) {
194
+ const made = factory();
195
+ if (typeof made !== "object" || made === null)
196
+ throw new TypeError("An interceptors factory must return { inbound?, outbound? }");
197
+ const lists = made;
198
+ if (lists.inbound !== void 0) {
199
+ if (!Array.isArray(lists.inbound))
200
+ throw new TypeError("interceptors.inbound must be an array");
201
+ inbound.push(...lists.inbound);
202
+ }
203
+ if (lists.outbound !== void 0) {
204
+ if (!Array.isArray(lists.outbound))
205
+ throw new TypeError("interceptors.outbound must be an array");
206
+ outbound.push(...lists.outbound);
207
+ }
208
+ }
209
+ return { inbound, outbound };
210
+ }
211
+ function compose(interceptors, method, terminal) {
212
+ let next = terminal;
213
+ for (let index = interceptors.length - 1; index >= 0; index--) {
214
+ const interceptor = interceptors[index];
215
+ const fn = interceptor?.[method];
216
+ if (typeof fn !== "function") continue;
217
+ const inner = next;
218
+ const call = fn;
219
+ next = (input) => call.call(interceptor, input, inner);
220
+ }
221
+ return next;
222
+ }
223
+
224
+ // src/durable/activities.ts
225
+ var ACTIVITY_MARKER = "fluidgrids.activity";
226
+ var ACTIVITY_IMPL_MARKER = "fluidgrids.activity-impl";
227
+ var ACTIVITY_NAME = new RegExp(chunkTYF56RGB_cjs.ACTIVITY_NAME_PATTERN);
228
+ var TASK_QUEUE_NAME = new RegExp(chunkTYF56RGB_cjs.TASK_QUEUE_NAME_PATTERN);
229
+ var DYNAMIC_ACTIVITY_NAME = "*";
230
+ function checkActivityName(name) {
231
+ if (typeof name !== "string" || !ACTIVITY_NAME.test(name))
232
+ throw new TypeError(
233
+ `An activity name must match ${chunkTYF56RGB_cjs.ACTIVITY_NAME_PATTERN} (got "${String(name)}")`
234
+ );
235
+ }
236
+ function checkTaskQueueName(queue, what = "taskQueue") {
237
+ if (typeof queue !== "string" || !TASK_QUEUE_NAME.test(queue))
238
+ throw new TypeError(`${what} must match ${chunkTYF56RGB_cjs.TASK_QUEUE_NAME_PATTERN} (got "${String(queue)}")`);
239
+ }
240
+ function declareActivity(name, options = {}) {
241
+ checkActivityName(name);
242
+ if (options.taskQueue !== void 0) checkTaskQueueName(options.taskQueue);
243
+ return Object.freeze({ __fluidgrids: ACTIVITY_MARKER, name, options: { ...options } });
244
+ }
245
+ function implementActivity(definition, fn) {
246
+ if (!isActivityDefinition(definition))
247
+ throw new TypeError("implementActivity() needs a declareActivity() value");
248
+ if (typeof fn !== "function") throw new TypeError("implementActivity() needs a function");
249
+ return Object.freeze({
250
+ __fluidgrids: ACTIVITY_MARKER,
251
+ name: definition.name,
252
+ options: definition.options,
253
+ implementation: ACTIVITY_IMPL_MARKER,
254
+ fn,
255
+ dynamic: false
256
+ });
257
+ }
258
+ function defineActivity(name, optionsOrFn, maybeFn) {
259
+ const fn = typeof optionsOrFn === "function" ? optionsOrFn : maybeFn;
260
+ const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
261
+ if (typeof fn !== "function") throw new TypeError(`defineActivity("${name}") needs a function`);
262
+ return implementActivity(declareActivity(name, options), fn);
263
+ }
264
+ function dynamicActivity(fn, options = {}) {
265
+ if (typeof fn !== "function") throw new TypeError("dynamicActivity() needs a function");
266
+ if (options.taskQueue !== void 0) checkTaskQueueName(options.taskQueue);
267
+ return Object.freeze({
268
+ __fluidgrids: ACTIVITY_MARKER,
269
+ name: DYNAMIC_ACTIVITY_NAME,
270
+ options: { ...options },
271
+ implementation: ACTIVITY_IMPL_MARKER,
272
+ fn,
273
+ dynamic: true
274
+ });
275
+ }
276
+ function isActivityDefinition(value) {
277
+ return typeof value === "object" && value !== null && value.__fluidgrids === ACTIVITY_MARKER && typeof value.name === "string";
278
+ }
279
+ function isActivityImplementation(value) {
280
+ return isActivityDefinition(value) && value.implementation === ACTIVITY_IMPL_MARKER && typeof value.fn === "function";
281
+ }
282
+ function findActivityImplementation(implementations, name) {
283
+ return implementations.find((impl) => !impl.dynamic && impl.name === name) ?? implementations.find((impl) => impl.dynamic);
284
+ }
285
+ function executeActivity(implementation, ctx, args, interceptors = []) {
286
+ const fn = implementation.fn;
287
+ const run = compose(
288
+ interceptors,
289
+ "execute",
290
+ async (input) => fn(ctx, input.args)
291
+ );
292
+ return run({ args, headers: ctx.info.headers, info: ctx.info });
293
+ }
155
294
 
295
+ exports.ACTIVITY_IMPL_MARKER = ACTIVITY_IMPL_MARKER;
296
+ exports.ACTIVITY_MARKER = ACTIVITY_MARKER;
156
297
  exports.DURABLE_MARKER = DURABLE_MARKER;
298
+ exports.DYNAMIC_ACTIVITY_NAME = DYNAMIC_ACTIVITY_NAME;
299
+ exports.INTERCEPTORS_MARKER = INTERCEPTORS_MARKER;
157
300
  exports.MAX_WORKFLOW_TASK_TIMEOUT_MS = MAX_WORKFLOW_TASK_TIMEOUT_MS;
158
301
  exports.SDK_VERSION = SDK_VERSION;
302
+ exports.checkActivityName = checkActivityName;
303
+ exports.checkTaskQueueName = checkTaskQueueName;
304
+ exports.compose = compose;
159
305
  exports.continueAsNewRetryOf = continueAsNewRetryOf;
306
+ exports.declareActivity = declareActivity;
307
+ exports.defineActivity = defineActivity;
308
+ exports.dynamicActivity = dynamicActivity;
309
+ exports.dynamicWorkflow = dynamicWorkflow;
310
+ exports.executeActivity = executeActivity;
311
+ exports.findActivityImplementation = findActivityImplementation;
312
+ exports.implementActivity = implementActivity;
313
+ exports.interceptorsFactoryOf = interceptorsFactoryOf;
160
314
  exports.interfaceOf = interfaceOf;
315
+ exports.isActivityDefinition = isActivityDefinition;
316
+ exports.isActivityImplementation = isActivityImplementation;
161
317
  exports.isDurableWorkflow = isDurableWorkflow;
162
318
  exports.jsonSchemaOf = jsonSchemaOf;
163
319
  exports.optionalMs = optionalMs;
320
+ exports.resolveWorkflowInterceptors = resolveWorkflowInterceptors;
164
321
  exports.runRetryPolicyOf = runRetryPolicyOf;
165
322
  exports.toMs = toMs;
166
323
  exports.workflow = workflow;
324
+ exports.workflowInterceptors = workflowInterceptors;
@@ -0,0 +1,150 @@
1
+ // src/history/payload-fields.ts
2
+ var ENCODED_PAYLOAD_MARKER = "$fgp";
3
+ var ENCODED_PAYLOAD_VERSION = 1;
4
+ var PAYLOAD_ENCODINGS = [
5
+ "json/plain",
6
+ "binary/plain",
7
+ "binary/encrypted",
8
+ "kms/envelope"
9
+ ];
10
+ var ENCODED_KEYS = /* @__PURE__ */ new Set(["$fgp", "encoding", "metadata", "data"]);
11
+ var BASE64 = /^[A-Za-z0-9+/]*={0,2}$/;
12
+ function isEncodedPayload(value) {
13
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
14
+ const record = value;
15
+ if (record[ENCODED_PAYLOAD_MARKER] !== ENCODED_PAYLOAD_VERSION) return false;
16
+ if (!Object.keys(record).every((key) => ENCODED_KEYS.has(key))) return false;
17
+ const encoding = record["encoding"];
18
+ if (typeof encoding !== "string" || encoding === "" || encoding === "json/plain") return false;
19
+ const data = record["data"];
20
+ if (typeof data !== "string" || data.length % 4 !== 0 || !BASE64.test(data)) return false;
21
+ const metadata = record["metadata"];
22
+ if (metadata === void 0) return true;
23
+ if (typeof metadata !== "object" || metadata === null || Array.isArray(metadata)) return false;
24
+ return Object.values(metadata).every((entry) => typeof entry === "string");
25
+ }
26
+ function payloadEncodingOf(value) {
27
+ return isEncodedPayload(value) ? value.encoding : "json/plain";
28
+ }
29
+ var PAYLOAD_FIELDS = {
30
+ WORKFLOW_STARTED: ["/input", "/lastCompletionResult", "/context"],
31
+ ACTIVITY_SCHEDULED: ["/args"],
32
+ ACTIVITY_HEARTBEAT: ["/details"],
33
+ ACTIVITY_COMPLETED: ["/result"],
34
+ ACTIVITY_CANCELLED: ["/details"],
35
+ SIGNAL_RECEIVED: ["/payload"],
36
+ UPDATE_ADMITTED: ["/args"],
37
+ UPDATE_ACCEPTED: ["/args"],
38
+ UPDATE_COMPLETED: ["/result"],
39
+ CHILD_RUN_INITIATED: ["/input", "/options/context"],
40
+ CHILD_RUN_COMPLETED: ["/result"],
41
+ EXTERNAL_RUN_SIGNALED: ["/payload"],
42
+ SIDE_EFFECT_RECORDED: ["/value"],
43
+ LOCAL_ACTIVITY_COMPLETED: ["/result"],
44
+ CONTEXT_UPSERTED: ["/entries"],
45
+ MARKER_RECORDED: ["/data/currentDetails"],
46
+ WORKFLOW_COMPLETED: ["/output"],
47
+ WORKFLOW_CANCELLED: ["/details"],
48
+ WORKFLOW_CONTINUED_AS_NEW: ["/input", "/options/context"]
49
+ };
50
+ var FAILURE_FIELDS = {
51
+ WORKFLOW_STARTED: ["/lastFailure"],
52
+ ACTIVITY_FAILED: ["/failure"],
53
+ ACTIVITY_TIMED_OUT: ["/failure"],
54
+ UPDATE_COMPLETED: ["/failure"],
55
+ CHILD_RUN_FAILED: ["/failure"],
56
+ EXTERNAL_RUN_SIGNALED: ["/failure"],
57
+ EXTERNAL_RUN_CANCEL_RESOLVED: ["/failure"],
58
+ LOCAL_ACTIVITY_FAILED: ["/failure"],
59
+ WORKFLOW_FAILED: ["/failure"],
60
+ WORKFLOW_TIMED_OUT: ["/failure"]
61
+ };
62
+ var COMMAND_PAYLOAD_FIELDS = {
63
+ SCHEDULE_ACTIVITY: ["/args"],
64
+ START_CHILD_RUN: ["/input", "/options/context"],
65
+ SIGNAL_RUN: ["/payload"],
66
+ RECORD_SIDE_EFFECT: ["/value"],
67
+ RECORD_MARKER: ["/data/currentDetails"],
68
+ COMPLETE_WORKFLOW: ["/output"],
69
+ UPSERT_CONTEXT: ["/entries"],
70
+ RECORD_LOCAL_ACTIVITY: ["/result"],
71
+ CONTINUE_AS_NEW: ["/input", "/options/context"],
72
+ COMPLETE_UPDATE: ["/result"]
73
+ };
74
+ var COMMAND_FAILURE_FIELDS = {
75
+ FAIL_WORKFLOW: ["/failure"],
76
+ RECORD_LOCAL_ACTIVITY: ["/failure"],
77
+ REJECT_UPDATE: ["/failure"],
78
+ COMPLETE_UPDATE: ["/failure"]
79
+ };
80
+ var FAILURE_PAYLOAD_FIELDS = ["/details"];
81
+ var FAILURE_CAUSE_FIELD = "/cause";
82
+ var PAYLOAD_FIELDS_FORMAT = "fluidgrids.payload-fields";
83
+ var PAYLOAD_FIELDS_DOCUMENT = {
84
+ format: PAYLOAD_FIELDS_FORMAT,
85
+ formatVersion: 2,
86
+ description: 'JSON pointers of user payloads per event type (relative to the payload) and per command type (relative to the command). `events` and `commands` are plain payload pointers. `eventFailures` and `commandFailures` point at failure objects: the payloads of a failure are the `failure.payloads` pointers relative to it, and the same rule applies again to the failure at `failure.cause` (recursively, to the end of the cause chain). Payload codecs and the at-rest envelope apply to these pointers only; everything else stays in clear text. A value that is not plain JSON is carried as {"$fgp": 1, "encoding", "metadata"?, "data" (base64)}.',
87
+ encodedMarker: ENCODED_PAYLOAD_MARKER,
88
+ encodedVersion: ENCODED_PAYLOAD_VERSION,
89
+ encodings: [...PAYLOAD_ENCODINGS],
90
+ events: PAYLOAD_FIELDS,
91
+ commands: COMMAND_PAYLOAD_FIELDS,
92
+ eventFailures: FAILURE_FIELDS,
93
+ commandFailures: COMMAND_FAILURE_FIELDS,
94
+ failure: { payloads: FAILURE_PAYLOAD_FIELDS, cause: FAILURE_CAUSE_FIELD }
95
+ };
96
+ function tokensOf(pointer) {
97
+ if (pointer === "") return [];
98
+ return pointer.slice(1).split("/").map((token) => token.replace(/~1/g, "/").replace(/~0/g, "~"));
99
+ }
100
+ function locate(root, pointer) {
101
+ const tokens = tokensOf(pointer);
102
+ const key = tokens.pop();
103
+ if (key === void 0) return void 0;
104
+ let holder = root;
105
+ for (const token of tokens) {
106
+ if (typeof holder !== "object" || holder === null || Array.isArray(holder)) return void 0;
107
+ holder = holder[token];
108
+ }
109
+ if (typeof holder !== "object" || holder === null || Array.isArray(holder)) return void 0;
110
+ const parent = holder;
111
+ if (!Object.hasOwn(parent, key) || parent[key] === void 0) return void 0;
112
+ return { parent, key };
113
+ }
114
+ function mapAt(root, pointer, fn) {
115
+ const found = locate(root, pointer);
116
+ if (found === void 0) return;
117
+ const current = found.parent[found.key];
118
+ if (current !== void 0) found.parent[found.key] = fn(current, pointer);
119
+ }
120
+ function mapFailureAt(root, pointer, fn) {
121
+ let failure = pointer;
122
+ for (; ; ) {
123
+ const found = locate(root, failure);
124
+ if (found === void 0) return;
125
+ const value = found.parent[found.key];
126
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return;
127
+ for (const field of FAILURE_PAYLOAD_FIELDS) mapAt(root, failure + field, fn);
128
+ failure += FAILURE_CAUSE_FIELD;
129
+ }
130
+ }
131
+ function mapPayloadFields(record, pointers, fn, failures = []) {
132
+ const copy = JSON.parse(JSON.stringify(record));
133
+ for (const pointer of pointers) mapAt(copy, pointer, fn);
134
+ for (const pointer of failures) mapFailureAt(copy, pointer, fn);
135
+ return copy;
136
+ }
137
+ function mapEventPayloads(type, payload, fn) {
138
+ return mapPayloadFields(payload, PAYLOAD_FIELDS[type] ?? [], fn, FAILURE_FIELDS[type] ?? []);
139
+ }
140
+ function mapCommandPayloads(command, fn) {
141
+ const record = command;
142
+ return mapPayloadFields(
143
+ record,
144
+ COMMAND_PAYLOAD_FIELDS[command.type] ?? [],
145
+ fn,
146
+ COMMAND_FAILURE_FIELDS[command.type] ?? []
147
+ );
148
+ }
149
+
150
+ export { COMMAND_FAILURE_FIELDS, COMMAND_PAYLOAD_FIELDS, ENCODED_PAYLOAD_MARKER, ENCODED_PAYLOAD_VERSION, FAILURE_CAUSE_FIELD, FAILURE_FIELDS, FAILURE_PAYLOAD_FIELDS, PAYLOAD_ENCODINGS, PAYLOAD_FIELDS, PAYLOAD_FIELDS_DOCUMENT, PAYLOAD_FIELDS_FORMAT, isEncodedPayload, mapCommandPayloads, mapEventPayloads, mapPayloadFields, payloadEncodingOf };