@smithers-orchestrator/driver 0.16.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 +21 -0
- package/package.json +80 -0
- package/src/ContinueAsNewHandler.ts +7 -0
- package/src/CreateWorkflowSession.ts +5 -0
- package/src/CreateWorkflowSessionOptions.ts +9 -0
- package/src/OutputAccessor.ts +20 -0
- package/src/OutputKey.ts +1 -0
- package/src/OutputSnapshot.ts +3 -0
- package/src/RunAuthContext.ts +6 -0
- package/src/RunOptions.ts +42 -0
- package/src/RunResult.ts +9 -0
- package/src/RunStatus.ts +9 -0
- package/src/SafeParser.ts +5 -0
- package/src/SchedulerWaitHandler.ts +6 -0
- package/src/SmithersCtx.js +195 -0
- package/src/SmithersCtxOptions.ts +14 -0
- package/src/SmithersRuntimeConfig.ts +3 -0
- package/src/SmithersTaskRuntime.ts +22 -0
- package/src/SpawnCaptureOptions.ts +12 -0
- package/src/SpawnCaptureResult.ts +5 -0
- package/src/TaskCompletedEvent.ts +5 -0
- package/src/TaskExecutor.ts +7 -0
- package/src/TaskExecutorContext.ts +7 -0
- package/src/TaskFailedEvent.ts +5 -0
- package/src/WaitHandler.ts +8 -0
- package/src/WorkflowDefinition.ts +16 -0
- package/src/WorkflowDriver.js +519 -0
- package/src/WorkflowDriverOptions.ts +27 -0
- package/src/WorkflowElement.ts +5 -0
- package/src/WorkflowGraphRenderer.ts +9 -0
- package/src/WorkflowRuntime.ts +3 -0
- package/src/WorkflowSession.ts +11 -0
- package/src/buildCurrentScopes.js +34 -0
- package/src/child-process.js +222 -0
- package/src/defaultTaskExecutor.js +28 -0
- package/src/filterRowsByNodeId.js +19 -0
- package/src/ignoreSyncError.js +16 -0
- package/src/index.d.ts +411 -0
- package/src/index.js +31 -0
- package/src/interop.js +1 -0
- package/src/normalizeInputRow.js +27 -0
- package/src/task-runtime.js +30 -0
- package/src/withAbort.js +43 -0
- package/src/withLogicalIterationShortcuts.js +46 -0
- package/src/workflow-types.ts +20 -0
package/src/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// @smithers-type-exports-begin
|
|
2
|
+
/** @typedef {import("./RunOptions.ts").HotReloadOptions} HotReloadOptions */
|
|
3
|
+
/**
|
|
4
|
+
* @template [Schema=any]
|
|
5
|
+
* @typedef {import("./OutputAccessor.ts").OutputAccessor<Schema>} OutputAccessor
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* @template T
|
|
9
|
+
* @typedef {import("./OutputAccessor.ts").InferOutputEntry<T>} InferOutputEntry
|
|
10
|
+
*/
|
|
11
|
+
/** @typedef {import("./OutputKey.ts").OutputKey} OutputKey */
|
|
12
|
+
/** @typedef {import("./OutputSnapshot.ts").OutputSnapshot} OutputSnapshot */
|
|
13
|
+
/** @typedef {import("./RunAuthContext.ts").RunAuthContext} RunAuthContext */
|
|
14
|
+
/** @typedef {import("./RunOptions.ts").RunOptions} RunOptions */
|
|
15
|
+
/** @typedef {import("./RunResult.ts").RunResult} RunResult */
|
|
16
|
+
/** @typedef {import("./RunStatus.ts").RunStatus} RunStatus */
|
|
17
|
+
/** @typedef {import("./SmithersCtxOptions.ts").SmithersCtxOptions} SmithersCtxOptions */
|
|
18
|
+
/**
|
|
19
|
+
* @template [Schema=unknown]
|
|
20
|
+
* @typedef {import("./WorkflowDefinition.ts").WorkflowDefinition<Schema>} WorkflowDefinition
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* @template [Schema=unknown]
|
|
24
|
+
* @typedef {import("./WorkflowDriverOptions.ts").WorkflowDriverOptions<Schema>} WorkflowDriverOptions
|
|
25
|
+
*/
|
|
26
|
+
/** @typedef {import("./WorkflowRuntime.ts").WorkflowRuntime} WorkflowRuntime */
|
|
27
|
+
/** @typedef {import("./WorkflowSession.ts").WorkflowSession} WorkflowSession */
|
|
28
|
+
// @smithers-type-exports-end
|
|
29
|
+
|
|
30
|
+
export { WorkflowDriver } from "./WorkflowDriver.js";
|
|
31
|
+
export { SmithersCtx } from "./SmithersCtx.js";
|
package/src/interop.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ignoreSyncError } from "./ignoreSyncError.js";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {unknown} input
|
|
3
|
+
* @returns {unknown}
|
|
4
|
+
*/
|
|
5
|
+
export function normalizeInputRow(input) {
|
|
6
|
+
if (!input || typeof input !== "object")
|
|
7
|
+
return input;
|
|
8
|
+
const inputObj = /** @type {Record<string, unknown>} */ (input);
|
|
9
|
+
if (!("payload" in inputObj))
|
|
10
|
+
return input;
|
|
11
|
+
const keys = Object.keys(inputObj);
|
|
12
|
+
const payloadOnly = keys.every((key) => key === "runId" || key === "payload");
|
|
13
|
+
if (!payloadOnly)
|
|
14
|
+
return input;
|
|
15
|
+
const payload = inputObj.payload;
|
|
16
|
+
if (payload == null)
|
|
17
|
+
return {};
|
|
18
|
+
if (typeof payload === "string") {
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(payload);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return payload;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return payload;
|
|
27
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { SmithersError } from "@smithers-orchestrator/errors/SmithersError";
|
|
3
|
+
/** @typedef {import("./SmithersTaskRuntime.ts").SmithersTaskRuntime} SmithersTaskRuntime */
|
|
4
|
+
|
|
5
|
+
const storage = new AsyncLocalStorage();
|
|
6
|
+
/**
|
|
7
|
+
* @template T
|
|
8
|
+
* @param {SmithersTaskRuntime} runtime
|
|
9
|
+
* @param {() => T} execute
|
|
10
|
+
* @returns {T}
|
|
11
|
+
*/
|
|
12
|
+
export function withTaskRuntime(runtime, execute) {
|
|
13
|
+
return storage.run(runtime, execute);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* @returns {SmithersTaskRuntime | undefined}
|
|
17
|
+
*/
|
|
18
|
+
export function getTaskRuntime() {
|
|
19
|
+
return storage.getStore();
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @returns {SmithersTaskRuntime}
|
|
23
|
+
*/
|
|
24
|
+
export function requireTaskRuntime() {
|
|
25
|
+
const runtime = storage.getStore();
|
|
26
|
+
if (!runtime) {
|
|
27
|
+
throw new SmithersError("TASK_RUNTIME_UNAVAILABLE", "Smithers task runtime is only available while a builder step is executing.");
|
|
28
|
+
}
|
|
29
|
+
return runtime;
|
|
30
|
+
}
|
package/src/withAbort.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @returns {Error}
|
|
3
|
+
*/
|
|
4
|
+
function makeAbortError() {
|
|
5
|
+
const error = new Error("Task aborted");
|
|
6
|
+
error.name = "AbortError";
|
|
7
|
+
return error;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* @param {AbortSignal} [signal]
|
|
11
|
+
*/
|
|
12
|
+
function throwIfAborted(signal) {
|
|
13
|
+
if (signal?.aborted) {
|
|
14
|
+
throw makeAbortError();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @param {AbortSignal} [signal]
|
|
19
|
+
* @returns {Promise<never> | null}
|
|
20
|
+
*/
|
|
21
|
+
function abortPromise(signal) {
|
|
22
|
+
if (!signal)
|
|
23
|
+
return null;
|
|
24
|
+
if (signal.aborted)
|
|
25
|
+
return Promise.reject(makeAbortError());
|
|
26
|
+
return new Promise((_, reject) => {
|
|
27
|
+
signal.addEventListener("abort", () => reject(makeAbortError()), {
|
|
28
|
+
once: true,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @template T
|
|
34
|
+
* @param {Promise<T> | T} value
|
|
35
|
+
* @param {AbortSignal} [signal]
|
|
36
|
+
* @returns {Promise<T>}
|
|
37
|
+
*/
|
|
38
|
+
export async function withAbort(value, signal) {
|
|
39
|
+
throwIfAborted(signal);
|
|
40
|
+
const abort = abortPromise(signal);
|
|
41
|
+
const promise = Promise.resolve(value);
|
|
42
|
+
return abort ? Promise.race([promise, abort]) : promise;
|
|
43
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {Record<string, number>} [iterations]
|
|
3
|
+
* @returns {Record<string, number> | undefined}
|
|
4
|
+
*/
|
|
5
|
+
export function withLogicalIterationShortcuts(iterations) {
|
|
6
|
+
if (!iterations)
|
|
7
|
+
return iterations;
|
|
8
|
+
const logicalIdsWithScope = new Set();
|
|
9
|
+
for (const id of Object.keys(iterations)) {
|
|
10
|
+
const atIdx = id.indexOf("@@");
|
|
11
|
+
if (atIdx >= 0) {
|
|
12
|
+
logicalIdsWithScope.add(id.slice(0, atIdx));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
if (logicalIdsWithScope.size === 0)
|
|
16
|
+
return iterations;
|
|
17
|
+
const normalized = { ...iterations };
|
|
18
|
+
for (const logicalId of logicalIdsWithScope) {
|
|
19
|
+
normalized[logicalId] = 0;
|
|
20
|
+
}
|
|
21
|
+
for (const [id, iter] of Object.entries(iterations)) {
|
|
22
|
+
const atIdx = id.indexOf("@@");
|
|
23
|
+
if (atIdx < 0)
|
|
24
|
+
continue;
|
|
25
|
+
const logicalId = id.slice(0, atIdx);
|
|
26
|
+
const scopeSuffix = id.slice(atIdx + 2);
|
|
27
|
+
let isCurrentScope = true;
|
|
28
|
+
for (const part of scopeSuffix.split(",")) {
|
|
29
|
+
const eqIdx = part.indexOf("=");
|
|
30
|
+
if (eqIdx < 0) {
|
|
31
|
+
isCurrentScope = false;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
const ancestorId = part.slice(0, eqIdx);
|
|
35
|
+
const ancestorIter = Number(part.slice(eqIdx + 1));
|
|
36
|
+
if (normalized[ancestorId] !== ancestorIter) {
|
|
37
|
+
isCurrentScope = false;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (isCurrentScope) {
|
|
42
|
+
normalized[logicalId] = iter;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return normalized;
|
|
46
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
EngineDecision,
|
|
3
|
+
RenderContext,
|
|
4
|
+
TaskOutput,
|
|
5
|
+
WaitReason,
|
|
6
|
+
} from "@smithers-orchestrator/scheduler";
|
|
7
|
+
export type { RunResult } from "@smithers-orchestrator/scheduler";
|
|
8
|
+
export type { ContinueAsNewHandler } from "./ContinueAsNewHandler.ts";
|
|
9
|
+
export type { CreateWorkflowSession } from "./CreateWorkflowSession.ts";
|
|
10
|
+
export type { CreateWorkflowSessionOptions } from "./CreateWorkflowSessionOptions.ts";
|
|
11
|
+
export type { SchedulerWaitHandler } from "./SchedulerWaitHandler.ts";
|
|
12
|
+
export type { TaskExecutor } from "./TaskExecutor.ts";
|
|
13
|
+
export type { TaskExecutorContext } from "./TaskExecutorContext.ts";
|
|
14
|
+
export type { WaitHandler } from "./WaitHandler.ts";
|
|
15
|
+
export type { WorkflowRuntime } from "./WorkflowRuntime.ts";
|
|
16
|
+
export type { WorkflowSession } from "./WorkflowSession.ts";
|
|
17
|
+
export type { WorkflowDriverOptions } from "./WorkflowDriverOptions.ts";
|
|
18
|
+
export type { WorkflowDefinition } from "./WorkflowDefinition.ts";
|
|
19
|
+
export type { WorkflowGraphRenderer } from "./WorkflowGraphRenderer.ts";
|
|
20
|
+
|