@fluidgrids/workflows 2026.1027.1 → 2026.1028.2
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.
- package/README.md +144 -13
- package/dist/activation-BBh1p82z.d.cts +57 -0
- package/dist/activation-DnhG7SmF.d.ts +57 -0
- package/dist/assemble-BLqQ8lSu.d.cts +39 -0
- package/dist/assemble-DWgaXHd-.d.ts +39 -0
- package/dist/chunk-2J6TF7YI.cjs +86 -0
- package/dist/chunk-4LYSEANA.js +199 -0
- package/dist/chunk-623FVQSN.cjs +251 -0
- package/dist/{chunk-W32BSO3M.js → chunk-6FSHT5IL.js} +2 -2
- package/dist/{chunk-E3APHA6O.cjs → chunk-7AAZGVKD.js} +1 -64
- package/dist/chunk-ABFZWYHT.js +612 -0
- package/dist/{chunk-6U446SKY.js → chunk-BD7ZPG53.js} +2 -2
- package/dist/chunk-BO6OVILK.js +79 -0
- package/dist/chunk-C5OLWZ42.js +245 -0
- package/dist/{chunk-OSPTJCDI.cjs → chunk-CPDK3K5N.cjs} +6 -6
- package/dist/chunk-DHTLALBL.cjs +80 -0
- package/dist/chunk-DJYMDLV5.js +227 -0
- package/dist/{chunk-IHKXLG6I.js → chunk-E2VK7J2C.js} +1 -1
- package/dist/{chunk-3M34AUIY.cjs → chunk-FEW3JBYA.cjs} +3 -3
- package/dist/chunk-FMSW2HDF.cjs +267 -0
- package/dist/chunk-FR7KYWRO.cjs +41 -0
- package/dist/{chunk-7YR7DI7B.cjs → chunk-GBQ33SIZ.cjs} +44 -44
- package/dist/{chunk-6AIAC2FP.cjs → chunk-GVTZMA5C.cjs} +4 -4
- package/dist/{chunk-EEAIM35V.js → chunk-HWJZVOG7.js} +64 -23
- package/dist/chunk-I5LR3D2K.js +869 -0
- package/dist/chunk-IISBRUWJ.js +13 -0
- package/dist/chunk-JD2VQIDZ.cjs +15 -0
- package/dist/{chunk-UB2BHU2M.js → chunk-JZ4TOOLN.js} +1 -1
- package/dist/chunk-L24YIZY7.cjs +207 -0
- package/dist/chunk-LNUQE6D6.js +39 -0
- package/dist/chunk-M4BBAERY.cjs +1635 -0
- package/dist/chunk-N23SKIG4.js +73 -0
- package/dist/{chunk-TWOYB4Y7.cjs → chunk-NEIUQASE.cjs} +13 -13
- package/dist/chunk-P6TA5EZT.cjs +634 -0
- package/dist/chunk-PMCM2OH4.js +46 -0
- package/dist/chunk-PZCVF76Q.cjs +868 -0
- package/dist/{chunk-6BEW4QD6.js → chunk-QAN5MZEM.js} +1 -1
- package/dist/{chunk-CSYBNN3V.cjs → chunk-QKZL3ONM.cjs} +2 -2
- package/dist/chunk-QQ6ULXHI.cjs +885 -0
- package/dist/chunk-SAENRNBJ.cjs +52 -0
- package/dist/{chunk-TQF7MYEN.cjs → chunk-SAOBPYYJ.cjs} +134 -96
- package/dist/{chunk-XBIID5DY.js → chunk-SMCANK3F.js} +5 -4
- package/dist/{chunk-UWQWD7BP.cjs → chunk-SX2PNKKT.cjs} +18 -17
- package/dist/{chunk-UJNHTS6D.js → chunk-TBDXTV22.cjs} +8 -45
- package/dist/chunk-UK3WM7YZ.cjs +75 -0
- package/dist/chunk-VOKMAAJP.js +848 -0
- package/dist/chunk-VRHHBPT6.js +1622 -0
- package/dist/{chunk-5AW745OG.js → chunk-XHXIDVEC.js} +1 -1
- package/dist/chunk-XKJA7KX3.js +72 -0
- package/dist/chunk-Z2Y65YOY.cjs +7 -0
- package/dist/codegen/index.cjs +9 -7
- package/dist/codegen/index.d.cts +2 -2
- package/dist/codegen/index.d.ts +2 -2
- package/dist/codegen/index.js +6 -5
- package/dist/file-BOoHZgoQ.d.cts +1557 -0
- package/dist/file-yuPCFU5b.d.ts +1557 -0
- package/dist/history/index.cjs +287 -0
- package/dist/history/index.d.cts +157 -0
- package/dist/history/index.d.ts +157 -0
- package/dist/history/index.js +5 -0
- package/dist/index.cjs +134 -36
- package/dist/index.d.cts +137 -9
- package/dist/index.d.ts +137 -9
- package/dist/index.js +8 -3
- package/dist/ir/index.cjs +152 -158
- package/dist/ir/index.d.cts +14 -4
- package/dist/ir/index.d.ts +14 -4
- package/dist/ir/index.js +41 -50
- package/dist/lower-BzmUz0sq.d.cts +129 -0
- package/dist/lower-_-iT4HYs.d.ts +129 -0
- package/dist/lower-types-DQNBfWQn.d.cts +37 -0
- package/dist/lower-types-DQNBfWQn.d.ts +37 -0
- package/dist/{manifest-Duf-gHdO.d.cts → manifest-0OLw0i7k.d.cts} +1 -1
- package/dist/{manifest-Bp9ZJlav.d.ts → manifest-C8N6HDYl.d.ts} +1 -1
- package/dist/node-evaluator-4MSDKWOG.cjs +22 -0
- package/dist/node-evaluator-SX4LEYQC.js +12 -0
- package/dist/quickjs/index.cjs +236 -12
- package/dist/quickjs/index.d.cts +46 -5
- package/dist/quickjs/index.d.ts +46 -5
- package/dist/quickjs/index.js +230 -9
- package/dist/roundtrip/index.cjs +333 -131
- package/dist/roundtrip/index.d.cts +39 -7
- package/dist/roundtrip/index.d.ts +39 -7
- package/dist/roundtrip/index.js +185 -13
- package/dist/runtime/index.cjs +90 -0
- package/dist/runtime/index.d.cts +297 -0
- package/dist/runtime/index.d.ts +297 -0
- package/dist/runtime/index.js +8 -0
- package/dist/testing/index.cjs +1057 -0
- package/dist/testing/index.d.cts +305 -0
- package/dist/testing/index.d.ts +305 -0
- package/dist/testing/index.js +1037 -0
- package/dist/{types-Dr2Fn1Ax.d.ts → types-BGoPzgcl.d.cts} +1 -1
- package/dist/{types-Dr2Fn1Ax.d.cts → types-BGoPzgcl.d.ts} +1 -1
- package/dist/types-CpBBjaGX.d.cts +380 -0
- package/dist/types-DV-HX_Gt.d.ts +380 -0
- package/dist/{assemble-CrpUyd_3.d.ts → workflow-Bpr3vnA_.d.ts} +40 -160
- package/dist/workflow-C2a05WUJ.d.ts +444 -0
- package/dist/{assemble-DEf3znGD.d.cts → workflow-FXUkpIBc.d.cts} +40 -160
- package/dist/workflow-J-yYixny.d.cts +444 -0
- package/fixtures/README.md +128 -0
- package/fixtures/histories/activity-failure-fails-run.history.json +163 -0
- package/fixtures/histories/activity-retry-then-success.history.json +147 -0
- package/fixtures/histories/cancel-activity-abandon.history.json +126 -0
- package/fixtures/histories/cancel-activity-compensate.history.json +307 -0
- package/fixtures/histories/cancel-concurrent-non-cancellable.history.json +234 -0
- package/fixtures/histories/cancel-concurrent-scope-timeout.history.json +184 -0
- package/fixtures/histories/cancel-condition-after-cancel.history.json +200 -0
- package/fixtures/histories/cancel-during-timer.history.json +123 -0
- package/fixtures/histories/cancel-saga-compensations.history.json +325 -0
- package/fixtures/histories/cancel-scope-timeout.history.json +148 -0
- package/fixtures/histories/child-abandon-outlives-parent.history.json +191 -0
- package/fixtures/histories/child-cancel-default.history.json +234 -0
- package/fixtures/histories/child-cancel-request.history.json +206 -0
- package/fixtures/histories/child-durable-child-side.history.json +124 -0
- package/fixtures/histories/child-durable-result.history.json +163 -0
- package/fixtures/histories/child-failure-caught.history.json +166 -0
- package/fixtures/histories/child-graph-by-key.history.json +138 -0
- package/fixtures/histories/child-terminated-by-parent-close.history.json +85 -0
- package/fixtures/histories/continue-as-new-first-run.history.json +146 -0
- package/fixtures/histories/continue-as-new-history-limit.history.json +489 -0
- package/fixtures/histories/continue-as-new-last-run.history.json +147 -0
- package/fixtures/histories/continue-as-new-suggested.history.json +352 -0
- package/fixtures/histories/details-and-context.history.json +176 -0
- package/fixtures/histories/deterministic-values.history.json +128 -0
- package/fixtures/histories/engine-builtins.history.json +172 -0
- package/fixtures/histories/gather-activities.history.json +291 -0
- package/fixtures/histories/gather-all-settled.history.json +219 -0
- package/fixtures/histories/gather-mixed.history.json +281 -0
- package/fixtures/histories/input-during-running-task.history.json +111 -0
- package/fixtures/histories/nondeterminism-reordered.history.json +218 -0
- package/fixtures/histories/patched-deprecated.history.json +271 -0
- package/fixtures/histories/patched-new-run.history.json +270 -0
- package/fixtures/histories/patched-old-history.history.json +190 -0
- package/fixtures/histories/race-activity-wins.history.json +152 -0
- package/fixtures/histories/race-signal-beats-child.history.json +161 -0
- package/fixtures/histories/race-timeout-wins.history.json +118 -0
- package/fixtures/histories/side-effect-recorded.history.json +153 -0
- package/fixtures/histories/signal-buffered-at-start.history.json +157 -0
- package/fixtures/histories/signal-default-handler.history.json +187 -0
- package/fixtures/histories/signal-handler.history.json +191 -0
- package/fixtures/histories/signal-parent-child-side.history.json +132 -0
- package/fixtures/histories/signal-parent.history.json +202 -0
- package/fixtures/histories/signal-run-delivered.history.json +128 -0
- package/fixtures/histories/signal-run-undelivered.history.json +134 -0
- package/fixtures/histories/signal-wait.history.json +111 -0
- package/fixtures/histories/task-failure-code-error.history.json +137 -0
- package/fixtures/histories/task-failure-then-transient-attempt.history.json +140 -0
- package/fixtures/histories/timer-condition-met.history.json +201 -0
- package/fixtures/histories/timer-condition-timeout.history.json +118 -0
- package/fixtures/histories/timer-sleep-once.history.json +118 -0
- package/fixtures/histories/timer-sleep-sequence.history.json +210 -0
- package/fixtures/histories/update-accepted-completed.history.json +149 -0
- package/fixtures/histories/update-with-start-rejected-validation.history.json +91 -0
- package/package.json +44 -5
- package/schema/history-file.schema.json +2544 -0
- package/schema/ir-v2.schema.json +16 -0
- package/schema/run-event.schema.json +2374 -0
- package/schema/workflow-command.schema.json +1095 -0
- package/schema/workflow-task.schema.json +3560 -0
- package/dist/chunk-MBBKGD7K.js +0 -440
- package/dist/chunk-Y7NWR3WH.cjs +0 -450
- package/dist/lower-CXggJTIo.d.ts +0 -67
- package/dist/lower-DAzvsJCo.d.cts +0 -67
- package/dist/node-evaluator-CH3XCJND.cjs +0 -17
- package/dist/node-evaluator-TULXA3WE.js +0 -8
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { HISTORY_PROTOCOL } from './chunk-DJYMDLV5.js';
|
|
2
|
+
|
|
3
|
+
function failedTaskResult(cause, message) {
|
|
4
|
+
return {
|
|
5
|
+
protocol: HISTORY_PROTOCOL,
|
|
6
|
+
outcome: "failed",
|
|
7
|
+
commands: [],
|
|
8
|
+
failure: { cause, message },
|
|
9
|
+
logs: []
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { failedTaskResult };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk623FVQSN_cjs = require('./chunk-623FVQSN.cjs');
|
|
4
|
+
|
|
5
|
+
function failedTaskResult(cause, message) {
|
|
6
|
+
return {
|
|
7
|
+
protocol: chunk623FVQSN_cjs.HISTORY_PROTOCOL,
|
|
8
|
+
outcome: "failed",
|
|
9
|
+
commands: [],
|
|
10
|
+
failure: { cause, message },
|
|
11
|
+
logs: []
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports.failedTaskResult = failedTaskResult;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/runtime/shims.ts
|
|
4
|
+
var SHIM_VIOLATION = "DeterminismViolation";
|
|
5
|
+
var SHIM_HOOK = "__fluidgridsShims";
|
|
6
|
+
var TASK_PRELUDE = `(() => {
|
|
7
|
+
const NAME = ${JSON.stringify(SHIM_VIOLATION)};
|
|
8
|
+
const fail = (what) => {
|
|
9
|
+
const error = new Error(what + " is not allowed in workflow code: use ctx.now(), ctx.random(), ctx.sleep() or an activity.");
|
|
10
|
+
error.name = NAME;
|
|
11
|
+
throw error;
|
|
12
|
+
};
|
|
13
|
+
let hooks = null;
|
|
14
|
+
const now = (what) => (hooks !== null ? hooks.now() : fail(what + " outside a workflow task"));
|
|
15
|
+
const lock = (target, key, value) =>
|
|
16
|
+
Object.defineProperty(target, key, { value, writable: false, enumerable: false, configurable: false });
|
|
17
|
+
const RealDate = Date;
|
|
18
|
+
// ---- Built-ins that differ between hosts and engines --------------------
|
|
19
|
+
// Local time is UTC whatever the host's TZ, locale formatting is fixed
|
|
20
|
+
// (en-US shapes, no ICU), Intl is absent and garbage collection cannot be
|
|
21
|
+
// observed, so QuickJS and vm on any host run workflow code the same way.
|
|
22
|
+
const proto = RealDate.prototype;
|
|
23
|
+
const hostOffset = proto.getTimezoneOffset;
|
|
24
|
+
const realParse = RealDate.parse;
|
|
25
|
+
const isInvalid = (date) => Number.isNaN(proto.getTime.call(date));
|
|
26
|
+
for (const unit of ["FullYear", "Month", "Date", "Day", "Hours", "Minutes", "Seconds", "Milliseconds"]) {
|
|
27
|
+
lock(proto, "get" + unit, proto["getUTC" + unit]);
|
|
28
|
+
if (unit !== "Day") lock(proto, "set" + unit, proto["setUTC" + unit]);
|
|
29
|
+
}
|
|
30
|
+
lock(proto, "getTimezoneOffset", function getTimezoneOffset() { return isInvalid(this) ? NaN : 0; });
|
|
31
|
+
if (typeof proto.getYear === "function")
|
|
32
|
+
lock(proto, "getYear", function getYear() { return isInvalid(this) ? NaN : this.getUTCFullYear() - 1900; });
|
|
33
|
+
if (typeof proto.setYear === "function")
|
|
34
|
+
lock(proto, "setYear", function setYear(value) {
|
|
35
|
+
const year = Number(value);
|
|
36
|
+
if (Number.isNaN(year)) return this.setTime(NaN);
|
|
37
|
+
const whole = Math.trunc(year);
|
|
38
|
+
const base = new RealDate(isInvalid(this) ? 0 : this.getTime());
|
|
39
|
+
base.setUTCFullYear(whole >= 0 && whole <= 99 ? 1900 + whole : whole);
|
|
40
|
+
return this.setTime(base.getTime());
|
|
41
|
+
});
|
|
42
|
+
const DAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
43
|
+
const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
44
|
+
const pad = (value, width) => String(value).padStart(width, "0");
|
|
45
|
+
const yearText = (year) => (year < 0 ? "-" + pad(-year, 6) : pad(year, 4));
|
|
46
|
+
const dateText = (d) =>
|
|
47
|
+
DAYS[d.getUTCDay()] + " " + MONTHS[d.getUTCMonth()] + " " + pad(d.getUTCDate(), 2) + " " + yearText(d.getUTCFullYear());
|
|
48
|
+
const timeText = (d) =>
|
|
49
|
+
pad(d.getUTCHours(), 2) + ":" + pad(d.getUTCMinutes(), 2) + ":" + pad(d.getUTCSeconds(), 2) + " GMT+0000 (Coordinated Universal Time)";
|
|
50
|
+
const localeDate = (d) => d.getUTCMonth() + 1 + "/" + d.getUTCDate() + "/" + d.getUTCFullYear();
|
|
51
|
+
const localeTime = (d) => {
|
|
52
|
+
const hours = d.getUTCHours();
|
|
53
|
+
return ((hours + 11) % 12) + 1 + ":" + pad(d.getUTCMinutes(), 2) + ":" + pad(d.getUTCSeconds(), 2) + (hours < 12 ? " AM" : " PM");
|
|
54
|
+
};
|
|
55
|
+
const formatter = (format) => function () { return isInvalid(this) ? "Invalid Date" : format(this); };
|
|
56
|
+
lock(proto, "toString", formatter((d) => dateText(d) + " " + timeText(d)));
|
|
57
|
+
lock(proto, "toDateString", formatter(dateText));
|
|
58
|
+
lock(proto, "toTimeString", formatter(timeText));
|
|
59
|
+
lock(proto, "toLocaleString", formatter((d) => localeDate(d) + ", " + localeTime(d)));
|
|
60
|
+
lock(proto, "toLocaleDateString", formatter(localeDate));
|
|
61
|
+
lock(proto, "toLocaleTimeString", formatter(localeTime));
|
|
62
|
+
// A date-time without an offset is local time to the host's parser; read it as UTC.
|
|
63
|
+
const DATE_ONLY = /^[+-]?\\d{4,6}(?:-\\d{2}(?:-\\d{2})?)?$/;
|
|
64
|
+
const ZONE_AFTER_TIME = /\\d:\\d{2}(?::\\d{2}(?:[.,]\\d+)?)?\\s*(?:[AP]M\\s*)?(?:Z|[+-]\\d{2}(?::?\\d{2})?|[ECMP][SD]T)\\s*(?:\\([^)]*\\))?\\s*$/i;
|
|
65
|
+
const NAMED_ZONE = /\\b(?:GMT|UTC|UT)\\b(?:\\s*[+-]\\d{2}:?\\d{2})?\\s*(?:\\([^)]*\\))?\\s*$/i;
|
|
66
|
+
const parse = function parse(value) {
|
|
67
|
+
const text = String(value);
|
|
68
|
+
const time = realParse(text);
|
|
69
|
+
if (Number.isNaN(time)) return time;
|
|
70
|
+
const trimmed = text.trim();
|
|
71
|
+
if (DATE_ONLY.test(trimmed) || ZONE_AFTER_TIME.test(trimmed) || NAMED_ZONE.test(trimmed)) return time;
|
|
72
|
+
return time - hostOffset.call(new RealDate(time)) * 60000;
|
|
73
|
+
};
|
|
74
|
+
const toTimeValue = (value) => {
|
|
75
|
+
if (value instanceof RealDate) return value.getTime();
|
|
76
|
+
let primitive = value;
|
|
77
|
+
if (typeof value === "object" && value !== null) {
|
|
78
|
+
primitive = value.valueOf();
|
|
79
|
+
if (typeof primitive === "object" && primitive !== null) primitive = String(value);
|
|
80
|
+
}
|
|
81
|
+
return typeof primitive === "string" ? parse(primitive) : primitive;
|
|
82
|
+
};
|
|
83
|
+
// ---- Number, string and array locale methods ----------------------------
|
|
84
|
+
const group = (digits) => digits.replace(/\\B(?=(\\d{3})+(?!\\d))/g, ",");
|
|
85
|
+
lock(Number.prototype, "toLocaleString", function toLocaleString() {
|
|
86
|
+
const x = Number.prototype.valueOf.call(this);
|
|
87
|
+
if (Number.isNaN(x)) return "NaN";
|
|
88
|
+
const sign = x < 0 || Object.is(x, -0) ? "-" : "";
|
|
89
|
+
const abs = Math.abs(x);
|
|
90
|
+
if (abs === Infinity) return sign + "\\u221e";
|
|
91
|
+
const fixed = abs < 1e21 ? abs.toFixed(3) : BigInt(abs).toString() + ".000";
|
|
92
|
+
const [whole, fraction] = fixed.split(".");
|
|
93
|
+
const kept = fraction.replace(/0+$/, "");
|
|
94
|
+
return sign + group(whole) + (kept === "" ? "" : "." + kept);
|
|
95
|
+
});
|
|
96
|
+
if (typeof BigInt === "function")
|
|
97
|
+
lock(BigInt.prototype, "toLocaleString", function toLocaleString() {
|
|
98
|
+
const text = BigInt.prototype.toString.call(this);
|
|
99
|
+
return text.startsWith("-") ? "-" + group(text.slice(1)) : group(text);
|
|
100
|
+
});
|
|
101
|
+
lock(String.prototype, "localeCompare", function localeCompare(that) {
|
|
102
|
+
const a = String(this);
|
|
103
|
+
const b = String(that);
|
|
104
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
105
|
+
});
|
|
106
|
+
lock(String.prototype, "toLocaleUpperCase", function toLocaleUpperCase() { return String(this).toUpperCase(); });
|
|
107
|
+
lock(String.prototype, "toLocaleLowerCase", function toLocaleLowerCase() { return String(this).toLowerCase(); });
|
|
108
|
+
const listLocale = function toLocaleString() {
|
|
109
|
+
return Array.prototype.map.call(this, (item) => (item === null || item === undefined ? "" : item.toLocaleString())).join(",");
|
|
110
|
+
};
|
|
111
|
+
lock(Array.prototype, "toLocaleString", listLocale);
|
|
112
|
+
lock(Object.getPrototypeOf(Uint8Array.prototype), "toLocaleString", listLocale);
|
|
113
|
+
// ---- Absent or refused ---------------------------------------------------
|
|
114
|
+
if (!Reflect.deleteProperty(globalThis, "Intl")) lock(globalThis, "Intl", undefined);
|
|
115
|
+
for (const name of ["WeakRef", "FinalizationRegistry"]) {
|
|
116
|
+
lock(globalThis, name, function () { return fail(name + " (garbage collection is not deterministic)"); });
|
|
117
|
+
}
|
|
118
|
+
const LockedDate = function Date(...args) {
|
|
119
|
+
if (new.target === undefined) return new RealDate(now("Date()")).toString();
|
|
120
|
+
if (args.length === 0) return Reflect.construct(RealDate, [now("new Date()")], new.target);
|
|
121
|
+
if (args.length === 1) return Reflect.construct(RealDate, [toTimeValue(args[0])], new.target);
|
|
122
|
+
return Reflect.construct(RealDate, [RealDate.UTC(...args)], new.target);
|
|
123
|
+
};
|
|
124
|
+
lock(LockedDate, "prototype", RealDate.prototype);
|
|
125
|
+
lock(RealDate.prototype, "constructor", LockedDate);
|
|
126
|
+
lock(LockedDate, "now", function now_() { return now("Date.now()"); });
|
|
127
|
+
lock(LockedDate, "parse", parse);
|
|
128
|
+
lock(LockedDate, "UTC", RealDate.UTC);
|
|
129
|
+
lock(globalThis, "Date", LockedDate);
|
|
130
|
+
lock(Math, "random", function random() {
|
|
131
|
+
return hooks !== null ? hooks.random() : fail("Math.random() outside a workflow task");
|
|
132
|
+
});
|
|
133
|
+
const crypto = globalThis.crypto;
|
|
134
|
+
if (crypto !== null && typeof crypto === "object") {
|
|
135
|
+
if (typeof crypto.getRandomValues === "function")
|
|
136
|
+
lock(crypto, "getRandomValues", function getRandomValues(array) {
|
|
137
|
+
if (hooks === null) return fail("crypto.getRandomValues() outside a workflow task");
|
|
138
|
+
for (let i = 0; i < array.length; i++) array[i] = Math.floor(hooks.random() * 256);
|
|
139
|
+
return array;
|
|
140
|
+
});
|
|
141
|
+
if (typeof crypto.randomUUID === "function")
|
|
142
|
+
lock(crypto, "randomUUID", function randomUUID() { return fail("crypto.randomUUID(): use ctx.uuid()"); });
|
|
143
|
+
}
|
|
144
|
+
for (const name of ["setTimeout", "setInterval", "setImmediate", "clearTimeout", "clearInterval", "clearImmediate"]) {
|
|
145
|
+
lock(globalThis, name, function () { return fail(name + "(): use ctx.sleep()"); });
|
|
146
|
+
}
|
|
147
|
+
for (const name of ["fetch", "XMLHttpRequest", "WebSocket", "EventSource"]) {
|
|
148
|
+
lock(globalThis, name, function () { return fail(name + ": do I/O in an activity (ctx.run)"); });
|
|
149
|
+
}
|
|
150
|
+
Object.defineProperty(globalThis, ${JSON.stringify(SHIM_HOOK)}, {
|
|
151
|
+
value: Object.freeze({
|
|
152
|
+
attach(next) { hooks = next; },
|
|
153
|
+
detach() { hooks = null; },
|
|
154
|
+
}),
|
|
155
|
+
writable: false,
|
|
156
|
+
enumerable: false,
|
|
157
|
+
configurable: true,
|
|
158
|
+
});
|
|
159
|
+
})();
|
|
160
|
+
`;
|
|
161
|
+
function isShimControl(value) {
|
|
162
|
+
return typeof value === "object" && value !== null && typeof value.attach === "function" && typeof value.detach === "function";
|
|
163
|
+
}
|
|
164
|
+
function takeShimControl() {
|
|
165
|
+
const holder = globalThis;
|
|
166
|
+
const control = holder[SHIM_HOOK];
|
|
167
|
+
if (!isShimControl(control)) return void 0;
|
|
168
|
+
delete holder[SHIM_HOOK];
|
|
169
|
+
return control;
|
|
170
|
+
}
|
|
171
|
+
function seedOf(text) {
|
|
172
|
+
let hash = 2166136261;
|
|
173
|
+
for (let index = 0; index < text.length; index++) {
|
|
174
|
+
hash ^= text.charCodeAt(index);
|
|
175
|
+
hash = Math.imul(hash, 16777619) >>> 0;
|
|
176
|
+
}
|
|
177
|
+
return hash >>> 0;
|
|
178
|
+
}
|
|
179
|
+
function createRandom(seed) {
|
|
180
|
+
let state = seed >>> 0;
|
|
181
|
+
return () => {
|
|
182
|
+
state = state + 1831565813 >>> 0;
|
|
183
|
+
let t = state;
|
|
184
|
+
t = Math.imul(t ^ t >>> 15, t | 1);
|
|
185
|
+
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
|
|
186
|
+
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function uuidFrom(random) {
|
|
190
|
+
const hex = [];
|
|
191
|
+
for (let index = 0; index < 16; index++) {
|
|
192
|
+
let byte = Math.floor(random() * 256) & 255;
|
|
193
|
+
if (index === 6) byte = byte & 15 | 64;
|
|
194
|
+
if (index === 8) byte = byte & 63 | 128;
|
|
195
|
+
hex.push(byte.toString(16).padStart(2, "0"));
|
|
196
|
+
}
|
|
197
|
+
const text = hex.join("");
|
|
198
|
+
return `${text.slice(0, 8)}-${text.slice(8, 12)}-${text.slice(12, 16)}-${text.slice(16, 20)}-${text.slice(20)}`;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
exports.SHIM_HOOK = SHIM_HOOK;
|
|
202
|
+
exports.SHIM_VIOLATION = SHIM_VIOLATION;
|
|
203
|
+
exports.TASK_PRELUDE = TASK_PRELUDE;
|
|
204
|
+
exports.createRandom = createRandom;
|
|
205
|
+
exports.seedOf = seedOf;
|
|
206
|
+
exports.takeShimControl = takeShimControl;
|
|
207
|
+
exports.uuidFrom = uuidFrom;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/ir/duration.ts
|
|
2
|
+
var SHORT = /^(\d+(?:\.\d+)?)(ms|s|m|h|d|w)$/;
|
|
3
|
+
var ISO = /^P(?:(\d+(?:\.\d+)?)W)?(?:(\d+(?:\.\d+)?)D)?(?:T(?:(\d+(?:\.\d+)?)H)?(?:(\d+(?:\.\d+)?)M)?(?:(\d+(?:\.\d+)?)S)?)?$/;
|
|
4
|
+
var SECOND_MS = 1e3;
|
|
5
|
+
var MINUTE_MS = 60 * SECOND_MS;
|
|
6
|
+
var HOUR_MS = 60 * MINUTE_MS;
|
|
7
|
+
var DAY_MS = 24 * HOUR_MS;
|
|
8
|
+
var WEEK_MS = 7 * DAY_MS;
|
|
9
|
+
var UNIT_MS = {
|
|
10
|
+
ms: 1,
|
|
11
|
+
s: SECOND_MS,
|
|
12
|
+
m: MINUTE_MS,
|
|
13
|
+
h: HOUR_MS,
|
|
14
|
+
d: DAY_MS,
|
|
15
|
+
w: WEEK_MS
|
|
16
|
+
};
|
|
17
|
+
function durationMs(value, numberUnit) {
|
|
18
|
+
if (typeof value === "number") {
|
|
19
|
+
if (!Number.isFinite(value) || value < 0) return void 0;
|
|
20
|
+
return numberUnit === "s" ? value * 1e3 : value;
|
|
21
|
+
}
|
|
22
|
+
if (typeof value !== "string") return void 0;
|
|
23
|
+
const text = value.trim();
|
|
24
|
+
const short = SHORT.exec(text);
|
|
25
|
+
if (short?.[1] !== void 0 && short[2] !== void 0) {
|
|
26
|
+
const unit = UNIT_MS[short[2]];
|
|
27
|
+
return unit === void 0 ? void 0 : Number(short[1]) * unit;
|
|
28
|
+
}
|
|
29
|
+
const iso = ISO.exec(text);
|
|
30
|
+
if (iso && text !== "P" && text !== "PT") {
|
|
31
|
+
const [, weeks, days, hours, minutes, seconds] = iso;
|
|
32
|
+
const parts = [weeks, days, hours, minutes, seconds];
|
|
33
|
+
if (parts.every((part) => part === void 0)) return void 0;
|
|
34
|
+
return Number(weeks ?? 0) * WEEK_MS + Number(days ?? 0) * DAY_MS + Number(hours ?? 0) * HOUR_MS + Number(minutes ?? 0) * MINUTE_MS + Number(seconds ?? 0) * SECOND_MS;
|
|
35
|
+
}
|
|
36
|
+
return void 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { durationMs };
|