@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.
Files changed (70) hide show
  1. package/LICENSE +202 -0
  2. package/dist/definition/check-definition.d.ts +21 -0
  3. package/dist/definition/check-definition.js +128 -0
  4. package/dist/definition/check-reads.js +46 -0
  5. package/dist/definition/check-schema.js +74 -0
  6. package/dist/definition/check-trigger.d.ts +7 -0
  7. package/dist/definition/check-trigger.js +27 -0
  8. package/dist/definition/expression-fields.js +68 -0
  9. package/dist/definition/expressions.js +35 -0
  10. package/dist/definition/graph.js +39 -0
  11. package/dist/definition/names.js +14 -0
  12. package/dist/definition/problem.d.ts +13 -0
  13. package/dist/definition/problem.js +11 -0
  14. package/dist/definition/reads.js +81 -0
  15. package/dist/definition/schema.d.ts +259 -0
  16. package/dist/definition/schema.js +258 -0
  17. package/dist/definition/types.d.ts +92 -0
  18. package/dist/definition/visible.js +52 -0
  19. package/dist/index.d.ts +19 -0
  20. package/dist/index.js +16 -0
  21. package/dist/limits.d.ts +39 -0
  22. package/dist/limits.js +40 -0
  23. package/dist/nesting.d.ts +7 -0
  24. package/dist/nesting.js +19 -0
  25. package/dist/plugin/connection-error.d.ts +10 -0
  26. package/dist/plugin/connection-error.js +15 -0
  27. package/dist/plugin/context.d.ts +99 -0
  28. package/dist/plugin/define-plugin.d.ts +7 -0
  29. package/dist/plugin/define-plugin.js +23 -0
  30. package/dist/plugin/fetch-errors.d.ts +14 -0
  31. package/dist/plugin/fetch-errors.js +18 -0
  32. package/dist/plugin/file-value.d.ts +5 -0
  33. package/dist/plugin/file-value.js +9 -0
  34. package/dist/plugin/index.d.ts +8 -0
  35. package/dist/plugin/index.js +6 -0
  36. package/dist/plugin/load-plugins.d.ts +10 -0
  37. package/dist/plugin/load-plugins.js +22 -0
  38. package/dist/plugin/step-handlers.d.ts +12 -0
  39. package/dist/plugin/step-handlers.js +33 -0
  40. package/dist/plugin/trigger-checks.d.ts +6 -0
  41. package/dist/plugin/trigger-checks.js +28 -0
  42. package/dist/plugin/type-catalog.d.ts +19 -0
  43. package/dist/plugin/type-catalog.js +26 -0
  44. package/dist/plugin/type-list.d.ts +26 -0
  45. package/dist/plugin/type-list.js +26 -0
  46. package/dist/plugin/types.d.ts +123 -0
  47. package/dist/run/context.d.ts +18 -0
  48. package/dist/run/errors.d.ts +20 -0
  49. package/dist/run/errors.js +39 -0
  50. package/dist/run/evaluate.js +59 -0
  51. package/dist/run/fan-out.js +39 -0
  52. package/dist/run/json-bytes.js +5 -0
  53. package/dist/run/port.d.ts +105 -0
  54. package/dist/run/position.js +54 -0
  55. package/dist/run/recovery.js +76 -0
  56. package/dist/run/redact.d.ts +16 -0
  57. package/dist/run/redact.js +39 -0
  58. package/dist/run/rerun.d.ts +18 -0
  59. package/dist/run/rerun.js +62 -0
  60. package/dist/run/result-states.js +115 -0
  61. package/dist/run/runner.d.ts +29 -0
  62. package/dist/run/runner.js +60 -0
  63. package/dist/run/scope.js +127 -0
  64. package/dist/run/segment.d.ts +35 -0
  65. package/dist/run/segment.js +58 -0
  66. package/dist/run/simple-states.js +108 -0
  67. package/dist/run/step-input.js +22 -0
  68. package/dist/run/task.js +39 -0
  69. package/package.json +34 -4
  70. package/README.md +0 -3
@@ -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.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
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
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.