@convex-dev/workflow
Version:
Convex component for durably executing workflows.
42 lines • 1.64 kB
JavaScript
export function setupEnvironment(_ctx) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const global = globalThis;
global.Math.random = () => {
throw new Error("Math.random() isn't currently supported within workflows");
};
const originalDate = global.Date;
delete global.Date;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function Date(...args) {
// `Date()` was called directly, not as a constructor.
if (!(this instanceof Date)) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const date = new Date();
return date.toString();
}
if (args.length === 0) {
const unixTsMs = Date.now();
return new originalDate(unixTsMs);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return new originalDate(...args);
}
Date.now = function () {
throw new Error("Date.now() isn't currently supported within workflows.");
};
Date.parse = originalDate.parse;
Date.UTC = originalDate.UTC;
Date.prototype = originalDate.prototype;
Date.prototype.constructor = Date;
global.Date = Date;
delete global.process;
delete global.Crypto;
delete global.crypto;
delete global.CryptoKey;
delete global.SubtleCrypto;
global.fetch = (_input, _init) => {
throw new Error(`Fetch isn't currently supported within workflows. Perform the fetch within an action and call it with step.runAction().`);
};
return { Date: originalDate };
}
//# sourceMappingURL=environment.js.map