@lunora/workflow 1.0.0-alpha.2 → 1.0.0-alpha.21
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/LICENSE.md +6 -0
- package/dist/do/index.d.mts +16 -16
- package/dist/do/index.d.ts +16 -16
- package/dist/do/index.mjs +1 -32
- package/dist/index.d.mts +127 -132
- package/dist/index.d.ts +127 -132
- package/dist/index.mjs +1 -8
- package/dist/packem_shared/MAX_BRANCHES-L0FzeGTH.mjs +1 -0
- package/dist/packem_shared/NonRetryableError-CXD-mZe4.mjs +1 -0
- package/dist/packem_shared/WorkflowsRestError--PIoe9uw.mjs +1 -0
- package/dist/packem_shared/branch-marker-B2lebQA6.mjs +1 -0
- package/dist/packem_shared/createRunStep-CzGKC1eZ.mjs +1 -0
- package/dist/packem_shared/createWorkflowContext-Dw8a1U68.mjs +1 -0
- package/dist/packem_shared/createWorkflowRunContext-BNh1APpj.mjs +1 -0
- package/dist/packem_shared/createWorkflows-3djec-oS.mjs +1 -0
- package/dist/packem_shared/defineStep-rJ0XPdAx.mjs +1 -0
- package/dist/packem_shared/defineWorkflow-fBuCDkGT.mjs +1 -0
- package/dist/packem_shared/{types.d-CQO_koGe.d.mts → types.d-CZ1pcdmw.d.mts} +162 -81
- package/dist/packem_shared/{types.d-CQO_koGe.d.ts → types.d-CZ1pcdmw.d.ts} +162 -81
- package/package.json +4 -3
- package/dist/packem_shared/NonRetryableError-Dn2dTyBS.mjs +0 -27
- package/dist/packem_shared/WorkflowsRestError-b06i7K5j.mjs +0 -118
- package/dist/packem_shared/createRunStep-8jOXxP2o.mjs +0 -54
- package/dist/packem_shared/createWorkflowContext-D6thzmlF.mjs +0 -14
- package/dist/packem_shared/createWorkflowLogger-DR8P4ZoY.mjs +0 -76
- package/dist/packem_shared/createWorkflows-BoSYVIXg.mjs +0 -23
- package/dist/packem_shared/defineStep-DJQtLw7g.mjs +0 -28
- package/dist/packem_shared/defineWorkflow-DbUC-oCN.mjs +0 -15
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { createRunStep } from './createRunStep-8jOXxP2o.mjs';
|
|
2
|
-
|
|
3
|
-
const trimTrailingSlashes = (value) => {
|
|
4
|
-
let end = value.length;
|
|
5
|
-
while (end > 0 && value[end - 1] === "/") {
|
|
6
|
-
end -= 1;
|
|
7
|
-
}
|
|
8
|
-
return value.slice(0, end);
|
|
9
|
-
};
|
|
10
|
-
const createWorkflowRunner = (options) => {
|
|
11
|
-
const globalFetch = globalThis.fetch;
|
|
12
|
-
const fetchImpl = options.fetchImpl ?? (typeof globalFetch === "function" ? globalFetch.bind(globalThis) : void 0);
|
|
13
|
-
return async (function_, args, runOptions = {}) => {
|
|
14
|
-
if (typeof fetchImpl !== "function") {
|
|
15
|
-
throw new TypeError("@lunora/workflow: no fetch implementation available — pass fetchImpl or run on a platform with global fetch");
|
|
16
|
-
}
|
|
17
|
-
const origin = options.env.LUNORA_ORIGIN_URL;
|
|
18
|
-
if (typeof origin !== "string" || origin.length === 0) {
|
|
19
|
-
throw new Error("@lunora/workflow: `LUNORA_ORIGIN_URL` must be set on the Worker env so a workflow can call back into Lunora functions");
|
|
20
|
-
}
|
|
21
|
-
const token = options.env.LUNORA_ADMIN_TOKEN;
|
|
22
|
-
if (typeof token !== "string" || token.length === 0) {
|
|
23
|
-
throw new Error("@lunora/workflow: `LUNORA_ADMIN_TOKEN` must be set on the Worker env to authenticate workflow function dispatch");
|
|
24
|
-
}
|
|
25
|
-
const url = `${trimTrailingSlashes(origin)}/_lunora/scheduler/dispatch`;
|
|
26
|
-
const response = await fetchImpl(url, {
|
|
27
|
-
body: JSON.stringify({ args: args ?? {}, functionPath: function_.__lunoraRef, shardKey: runOptions.shardKey }),
|
|
28
|
-
headers: { authorization: `Bearer ${token}`, "content-type": "application/json" },
|
|
29
|
-
method: "POST"
|
|
30
|
-
});
|
|
31
|
-
if (!response.ok) {
|
|
32
|
-
throw new Error(`@lunora/workflow: function dispatch failed (${String(response.status)}): ${await response.text()}`);
|
|
33
|
-
}
|
|
34
|
-
const text = await response.text();
|
|
35
|
-
if (text.length === 0) {
|
|
36
|
-
return void 0;
|
|
37
|
-
}
|
|
38
|
-
try {
|
|
39
|
-
return JSON.parse(text);
|
|
40
|
-
} catch {
|
|
41
|
-
return text;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
const createWorkflowLogger = (exportName) => {
|
|
46
|
-
const prefix = `[workflow:${exportName}]`;
|
|
47
|
-
return {
|
|
48
|
-
debug: (message, ...rest) => {
|
|
49
|
-
console.debug(prefix, message, ...rest);
|
|
50
|
-
},
|
|
51
|
-
error: (message, ...rest) => {
|
|
52
|
-
console.error(prefix, message, ...rest);
|
|
53
|
-
},
|
|
54
|
-
info: (message, ...rest) => {
|
|
55
|
-
console.info(prefix, message, ...rest);
|
|
56
|
-
},
|
|
57
|
-
warn: (message, ...rest) => {
|
|
58
|
-
console.warn(prefix, message, ...rest);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
const createWorkflowRunContext = (options) => {
|
|
63
|
-
const log = createWorkflowLogger(options.exportName);
|
|
64
|
-
const run = createWorkflowRunner({ env: options.env, fetchImpl: options.fetchImpl });
|
|
65
|
-
return {
|
|
66
|
-
env: options.env,
|
|
67
|
-
event: options.event,
|
|
68
|
-
log,
|
|
69
|
-
params: options.event.payload,
|
|
70
|
-
run,
|
|
71
|
-
runStep: createRunStep({ env: options.env, log, nonRetryableErrorClass: options.nonRetryableErrorClass, run, step: options.step }),
|
|
72
|
-
step: options.step
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export { createWorkflowLogger, createWorkflowRunContext, createWorkflowRunner };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const handleFor = (binding) => {
|
|
2
|
-
return {
|
|
3
|
-
create: async (options) => binding.create(options),
|
|
4
|
-
createBatch: async (batch) => binding.createBatch(batch),
|
|
5
|
-
get: async (id) => binding.get(id)
|
|
6
|
-
};
|
|
7
|
-
};
|
|
8
|
-
const createWorkflows = (options) => {
|
|
9
|
-
const bindings = options.bindings ?? {};
|
|
10
|
-
return {
|
|
11
|
-
get: (name) => {
|
|
12
|
-
const binding = bindings[name];
|
|
13
|
-
if (binding === void 0) {
|
|
14
|
-
const known = Object.keys(bindings);
|
|
15
|
-
const suffix = known.length === 0 ? "no workflows are declared" : `known workflows: ${known.join(", ")}`;
|
|
16
|
-
throw new Error(`@lunora/workflow: no workflow named "${name}" (${suffix})`);
|
|
17
|
-
}
|
|
18
|
-
return handleFor(binding);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export { createWorkflows as default };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
const defineStep = (name, config) => {
|
|
2
|
-
if (typeof name !== "string" || name.length === 0) {
|
|
3
|
-
throw new TypeError("defineStep: `name` must be a non-empty string (the durable step label)");
|
|
4
|
-
}
|
|
5
|
-
const declaredArgs = config.args;
|
|
6
|
-
if (typeof declaredArgs !== "object" || declaredArgs === null) {
|
|
7
|
-
throw new TypeError("defineStep: `args` must be a validator map (e.g. `{ id: v.string() }`)");
|
|
8
|
-
}
|
|
9
|
-
if (typeof config.handler !== "function") {
|
|
10
|
-
throw new TypeError("defineStep: `handler` must be a function (the step body)");
|
|
11
|
-
}
|
|
12
|
-
if (config.rollback !== void 0 && typeof config.rollback !== "function") {
|
|
13
|
-
throw new TypeError("defineStep: `rollback` must be a function when provided");
|
|
14
|
-
}
|
|
15
|
-
return {
|
|
16
|
-
args: config.args,
|
|
17
|
-
config: config.config,
|
|
18
|
-
handler: config.handler,
|
|
19
|
-
isLunoraStep: true,
|
|
20
|
-
name,
|
|
21
|
-
returns: config.returns,
|
|
22
|
-
rollback: config.rollback,
|
|
23
|
-
rollbackConfig: config.rollbackConfig
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
const isStepDefinition = (value) => typeof value === "object" && value !== null && value.isLunoraStep === true;
|
|
27
|
-
|
|
28
|
-
export { defineStep, isStepDefinition };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const workflowClassName = (exportName) => `${exportName.charAt(0).toUpperCase()}${exportName.slice(1)}Workflow`;
|
|
2
|
-
const workflowBindingName = (exportName) => `WORKFLOW_${exportName.replaceAll(/(?<=[a-z0-9])(?=[A-Z])/g, "_").toUpperCase()}`;
|
|
3
|
-
const workflowDefaultName = (exportName) => exportName.replaceAll(/(?<=[a-z0-9])(?=[A-Z])/g, "-").toLowerCase();
|
|
4
|
-
const defineWorkflow = (config) => {
|
|
5
|
-
if (typeof config.handler !== "function") {
|
|
6
|
-
throw new TypeError("defineWorkflow: `handler` must be a function (the workflow body)");
|
|
7
|
-
}
|
|
8
|
-
if (config.name !== void 0 && (typeof config.name !== "string" || config.name.length === 0)) {
|
|
9
|
-
throw new TypeError("defineWorkflow: `name` must be a non-empty string when provided");
|
|
10
|
-
}
|
|
11
|
-
return { ...config, isLunoraWorkflow: true };
|
|
12
|
-
};
|
|
13
|
-
const isWorkflowDefinition = (value) => typeof value === "object" && value !== null && value.isLunoraWorkflow === true;
|
|
14
|
-
|
|
15
|
-
export { defineWorkflow, isWorkflowDefinition, workflowBindingName, workflowClassName, workflowDefaultName };
|