@protobase/workflows 0.0.0-stage → 0.68.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.
- package/LICENSE +202 -0
- package/dist/definition/check-definition.d.ts +21 -0
- package/dist/definition/check-definition.js +128 -0
- package/dist/definition/check-reads.js +46 -0
- package/dist/definition/check-schema.js +74 -0
- package/dist/definition/check-trigger.d.ts +7 -0
- package/dist/definition/check-trigger.js +27 -0
- package/dist/definition/expression-fields.js +68 -0
- package/dist/definition/expressions.js +35 -0
- package/dist/definition/graph.js +39 -0
- package/dist/definition/names.js +14 -0
- package/dist/definition/problem.d.ts +13 -0
- package/dist/definition/problem.js +11 -0
- package/dist/definition/reads.js +81 -0
- package/dist/definition/schema.d.ts +259 -0
- package/dist/definition/schema.js +258 -0
- package/dist/definition/types.d.ts +92 -0
- package/dist/definition/visible.js +52 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +16 -0
- package/dist/limits.d.ts +39 -0
- package/dist/limits.js +40 -0
- package/dist/nesting.d.ts +7 -0
- package/dist/nesting.js +19 -0
- package/dist/plugin/connection-error.d.ts +10 -0
- package/dist/plugin/connection-error.js +15 -0
- package/dist/plugin/context.d.ts +99 -0
- package/dist/plugin/define-plugin.d.ts +7 -0
- package/dist/plugin/define-plugin.js +23 -0
- package/dist/plugin/fetch-errors.d.ts +14 -0
- package/dist/plugin/fetch-errors.js +18 -0
- package/dist/plugin/file-value.d.ts +5 -0
- package/dist/plugin/file-value.js +9 -0
- package/dist/plugin/index.d.ts +8 -0
- package/dist/plugin/index.js +6 -0
- package/dist/plugin/load-plugins.d.ts +10 -0
- package/dist/plugin/load-plugins.js +22 -0
- package/dist/plugin/step-handlers.d.ts +12 -0
- package/dist/plugin/step-handlers.js +33 -0
- package/dist/plugin/trigger-checks.d.ts +6 -0
- package/dist/plugin/trigger-checks.js +28 -0
- package/dist/plugin/type-catalog.d.ts +19 -0
- package/dist/plugin/type-catalog.js +26 -0
- package/dist/plugin/type-list.d.ts +26 -0
- package/dist/plugin/type-list.js +26 -0
- package/dist/plugin/types.d.ts +123 -0
- package/dist/run/context.d.ts +18 -0
- package/dist/run/errors.d.ts +20 -0
- package/dist/run/errors.js +39 -0
- package/dist/run/evaluate.js +59 -0
- package/dist/run/fan-out.js +39 -0
- package/dist/run/json-bytes.js +5 -0
- package/dist/run/port.d.ts +105 -0
- package/dist/run/position.js +54 -0
- package/dist/run/recovery.js +76 -0
- package/dist/run/redact.d.ts +16 -0
- package/dist/run/redact.js +39 -0
- package/dist/run/rerun.d.ts +18 -0
- package/dist/run/rerun.js +62 -0
- package/dist/run/result-states.js +115 -0
- package/dist/run/runner.d.ts +29 -0
- package/dist/run/runner.js +60 -0
- package/dist/run/scope.js +127 -0
- package/dist/run/segment.d.ts +35 -0
- package/dist/run/segment.js +58 -0
- package/dist/run/simple-states.js +108 -0
- package/dist/run/step-input.js +22 -0
- package/dist/run/task.js +39 -0
- package/package.json +34 -4
- package/README.md +0 -3
package/dist/run/task.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { limits } from "../limits.js";
|
|
2
|
+
import { StepError, SupersededError } from "./errors.js";
|
|
3
|
+
//#region src/run/task.ts
|
|
4
|
+
const aborted = (signal) => new Promise((_, reject) => {
|
|
5
|
+
if (signal.aborted) return reject(signal.reason);
|
|
6
|
+
signal.addEventListener("abort", () => reject(signal.reason), { once: true });
|
|
7
|
+
});
|
|
8
|
+
/**
|
|
9
|
+
* Runs a Task's step type with its arguments, within its `TimeoutSeconds`: its result, or a `StepError` naming why it
|
|
10
|
+
* failed (`States.Timeout` when the time ran out, `States.TaskFailed` for an error of no name of its own). When the
|
|
11
|
+
* worker stops, the abort is thrown as it is, so the step is not saved and runs again in the next segment.
|
|
12
|
+
*/
|
|
13
|
+
const runTask = async (context, state, args, idempotencyKey, logs) => {
|
|
14
|
+
const handler = context.tasks[state.Resource];
|
|
15
|
+
if (!handler) throw new StepError("States.Runtime", `"${state.Resource}" is not a step type of this app`);
|
|
16
|
+
const timeout = AbortSignal.timeout((state.TimeoutSeconds ?? limits.defaultTaskTimeoutSeconds) * 1e3);
|
|
17
|
+
const signal = AbortSignal.any([context.signal, timeout]);
|
|
18
|
+
const log = (message) => void logs.push({
|
|
19
|
+
at: context.now().toISOString(),
|
|
20
|
+
message
|
|
21
|
+
});
|
|
22
|
+
context.signal.throwIfAborted();
|
|
23
|
+
try {
|
|
24
|
+
return await Promise.race([handler(args, {
|
|
25
|
+
runId: context.runId,
|
|
26
|
+
signal,
|
|
27
|
+
idempotencyKey,
|
|
28
|
+
log,
|
|
29
|
+
redact: context.redactor.text
|
|
30
|
+
}), aborted(signal)]);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
if (context.signal.aborted || error instanceof SupersededError) throw error;
|
|
33
|
+
if (timeout.aborted) throw new StepError("States.Timeout", `The step ran longer than ${state.TimeoutSeconds ?? limits.defaultTaskTimeoutSeconds} seconds`);
|
|
34
|
+
if (error instanceof StepError) throw error;
|
|
35
|
+
throw new StepError("States.TaskFailed", error instanceof Error ? error.message : String(error));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
//#endregion
|
|
39
|
+
export { runTask };
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/workflows",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.68.0",
|
|
4
|
+
"description": "Workflows as state machines with JSONata expressions: their check, a runner that saves every step, and the plugin interface for trigger and step types.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/PrototeamHQ/protobase.git",
|
|
9
|
+
"directory": "packages/workflows"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://docs.protobase.net",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=22.12.0"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": "./dist/index.js",
|
|
19
|
+
"./plugin": "./dist/plugin/index.js"
|
|
20
|
+
},
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsdown",
|
|
27
|
+
"prepack": "tsdown"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"jsonata": "^2.2.2",
|
|
34
|
+
"ajv": "^8.20.0"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/README.md
DELETED