openworkflow 0.4.0 → 0.4.1
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/README.md +17 -11
- package/dist/backend-sqlite/backend.d.ts +38 -0
- package/dist/backend-sqlite/backend.d.ts.map +1 -0
- package/dist/backend-sqlite/backend.js +628 -0
- package/dist/backend-sqlite/backend.js.map +1 -0
- package/dist/backend-sqlite/index.d.ts +2 -0
- package/dist/backend-sqlite/index.d.ts.map +1 -0
- package/dist/backend-sqlite/index.js +2 -0
- package/dist/backend-sqlite/index.js.map +1 -0
- package/dist/backend-sqlite/sqlite.d.ts +45 -0
- package/dist/backend-sqlite/sqlite.d.ts.map +1 -0
- package/dist/backend-sqlite/sqlite.js +229 -0
- package/dist/backend-sqlite/sqlite.js.map +1 -0
- package/dist/config/config.d.ts +102 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +29 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +2 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config.d.ts +28 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +41 -0
- package/dist/config.js.map +1 -0
- package/dist/core/backend-test-suite.d.ts +22 -0
- package/dist/core/backend-test-suite.d.ts.map +1 -0
- package/dist/core/backend-test-suite.js +960 -0
- package/dist/core/backend-test-suite.js.map +1 -0
- package/dist/core/backend.d.ts +103 -0
- package/dist/core/backend.d.ts.map +1 -0
- package/dist/core/backend.js +2 -0
- package/dist/core/backend.js.map +1 -0
- package/dist/core/backend.testsuite.d.ts +21 -0
- package/dist/core/backend.testsuite.d.ts.map +1 -0
- package/dist/core/backend.testsuite.js +958 -0
- package/dist/core/backend.testsuite.js.map +1 -0
- package/dist/{duration.d.ts → core/duration.d.ts} +2 -1
- package/dist/core/duration.d.ts.map +1 -0
- package/dist/{duration.js → core/duration.js} +6 -5
- package/dist/core/duration.js.map +1 -0
- package/dist/core/duration.test.d.ts +2 -0
- package/dist/core/duration.test.d.ts.map +1 -0
- package/dist/core/duration.test.js +264 -0
- package/dist/core/duration.test.js.map +1 -0
- package/dist/core/json.d.ts +5 -0
- package/dist/core/json.d.ts.map +1 -0
- package/dist/core/json.js +2 -0
- package/dist/core/json.js.map +1 -0
- package/dist/core/result.d.ts +12 -0
- package/dist/core/result.d.ts.map +1 -0
- package/dist/core/result.js +7 -0
- package/dist/core/result.js.map +1 -0
- package/dist/core/result.test.d.ts +2 -0
- package/dist/core/result.test.d.ts.map +1 -0
- package/dist/core/result.test.js +11 -0
- package/dist/core/result.test.js.map +1 -0
- package/dist/core/retry.d.ts +16 -0
- package/dist/core/retry.d.ts.map +1 -0
- package/dist/{backend.js → core/retry.js} +1 -3
- package/dist/core/retry.js.map +1 -0
- package/dist/core/retry.test.d.ts +2 -0
- package/dist/core/retry.test.d.ts.map +1 -0
- package/dist/core/retry.test.js +36 -0
- package/dist/core/retry.test.js.map +1 -0
- package/dist/core/schema.d.ts.map +1 -0
- package/dist/core/schema.js.map +1 -0
- package/dist/core/step.d.ts +120 -0
- package/dist/core/step.d.ts.map +1 -0
- package/dist/core/step.js +101 -0
- package/dist/core/step.js.map +1 -0
- package/dist/core/step.test.d.ts +2 -0
- package/dist/core/step.test.d.ts.map +1 -0
- package/dist/core/step.test.js +340 -0
- package/dist/core/step.test.js.map +1 -0
- package/dist/core/workflow.d.ts +108 -0
- package/dist/core/workflow.d.ts.map +1 -0
- package/dist/core/workflow.js +79 -0
- package/dist/core/workflow.js.map +1 -0
- package/dist/core/workflow.test.d.ts +2 -0
- package/dist/core/workflow.test.d.ts.map +1 -0
- package/dist/core/workflow.test.js +216 -0
- package/dist/core/workflow.test.js.map +1 -0
- package/dist/execution/execution.d.ts +91 -0
- package/dist/execution/execution.d.ts.map +1 -0
- package/dist/execution/execution.js +188 -0
- package/dist/execution/execution.js.map +1 -0
- package/dist/execution/execution.test.d.ts +2 -0
- package/dist/execution/execution.test.d.ts.map +1 -0
- package/dist/execution/execution.test.js +382 -0
- package/dist/execution/execution.test.js.map +1 -0
- package/dist/global.d.ts +62 -0
- package/dist/global.d.ts.map +1 -0
- package/dist/global.js +78 -0
- package/dist/global.js.map +1 -0
- package/dist/index.d.ts +9 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/sdk/sdk.d.ts +182 -0
- package/dist/sdk/sdk.d.ts.map +1 -0
- package/dist/sdk/sdk.js +208 -0
- package/dist/sdk/sdk.js.map +1 -0
- package/dist/sdk/sdk.test.d.ts +2 -0
- package/dist/sdk/sdk.test.d.ts.map +1 -0
- package/dist/sdk/sdk.test.js +195 -0
- package/dist/sdk/sdk.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/{worker.d.ts → worker/worker.d.ts} +3 -3
- package/dist/worker/worker.d.ts.map +1 -0
- package/dist/worker/worker.js +208 -0
- package/dist/worker/worker.js.map +1 -0
- package/dist/worker/worker.test.d.ts +2 -0
- package/dist/worker/worker.test.d.ts.map +1 -0
- package/dist/worker/worker.test.js +786 -0
- package/dist/worker/worker.test.js.map +1 -0
- package/package.json +6 -6
- package/dist/backend.d.ts +0 -173
- package/dist/backend.d.ts.map +0 -1
- package/dist/backend.js.map +0 -1
- package/dist/client.d.ts +0 -153
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -151
- package/dist/client.js.map +0 -1
- package/dist/duration.d.ts.map +0 -1
- package/dist/duration.js.map +0 -1
- package/dist/schema.d.ts.map +0 -1
- package/dist/schema.js.map +0 -1
- package/dist/worker.d.ts.map +0 -1
- package/dist/worker.js +0 -384
- package/dist/worker.js.map +0 -1
- /package/dist/{schema.d.ts → core/schema.d.ts} +0 -0
- /package/dist/{schema.js → core/schema.js} +0 -0
package/dist/global.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { OpenWorkflow } from "./sdk/sdk.js";
|
|
2
|
+
/**
|
|
3
|
+
* Get the global OpenWorkflow client instance.
|
|
4
|
+
* This function lazily loads the configuration file and creates a singleton
|
|
5
|
+
* instance on first access.
|
|
6
|
+
*
|
|
7
|
+
* The global client is useful for:
|
|
8
|
+
* - Zero-config DX where you want a single shared client
|
|
9
|
+
* - CLI tools that need to access the configured client
|
|
10
|
+
* - Testing scenarios where you can override the client with setGlobalClient()
|
|
11
|
+
*
|
|
12
|
+
* Note: This function requires Node.js and will only work in Node environments.
|
|
13
|
+
* For non-Node environments (browser, edge), create OpenWorkflow instances manually.
|
|
14
|
+
*
|
|
15
|
+
* @returns The global OpenWorkflow client instance
|
|
16
|
+
* @throws Error if config file is not found or invalid
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { getGlobalClient } from 'openworkflow';
|
|
21
|
+
*
|
|
22
|
+
* const ow = await getGlobalClient();
|
|
23
|
+
* await ow.run(myWorkflow, { input: 'data' });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function getGlobalClient(): Promise<OpenWorkflow>;
|
|
27
|
+
/**
|
|
28
|
+
* Set the global OpenWorkflow client instance.
|
|
29
|
+
* This is primarily useful for testing scenarios where you want to override
|
|
30
|
+
* the default client with a mock or test instance.
|
|
31
|
+
*
|
|
32
|
+
* @param client - The OpenWorkflow instance to set as the global client
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import { setGlobalClient, OpenWorkflow } from 'openworkflow';
|
|
37
|
+
* import { BackendSqlite } from '@openworkflow/backend-sqlite';
|
|
38
|
+
*
|
|
39
|
+
* // In tests
|
|
40
|
+
* const testClient = new OpenWorkflow({
|
|
41
|
+
* backend: BackendSqlite.connect(':memory:')
|
|
42
|
+
* });
|
|
43
|
+
* setGlobalClient(testClient);
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function setGlobalClient(client: OpenWorkflow): void;
|
|
47
|
+
/**
|
|
48
|
+
* Reset the global client to null.
|
|
49
|
+
* This is primarily useful for testing to ensure a clean state between tests.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* import { resetGlobalClient } from 'openworkflow';
|
|
54
|
+
*
|
|
55
|
+
* // In test cleanup
|
|
56
|
+
* afterEach(() => {
|
|
57
|
+
* resetGlobalClient();
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function resetGlobalClient(): void;
|
|
62
|
+
//# sourceMappingURL=global.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global.d.ts","sourceRoot":"","sources":["../global.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AASjD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,YAAY,CAAC,CAQ7D;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAE1D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAExC"}
|
package/dist/global.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { loadConfig } from "./config.js";
|
|
2
|
+
/**
|
|
3
|
+
* Global singleton OpenWorkflow client instance.
|
|
4
|
+
* This is lazily initialized when getGlobalClient() is first called.
|
|
5
|
+
*/
|
|
6
|
+
let globalClient = null;
|
|
7
|
+
/**
|
|
8
|
+
* Get the global OpenWorkflow client instance.
|
|
9
|
+
* This function lazily loads the configuration file and creates a singleton
|
|
10
|
+
* instance on first access.
|
|
11
|
+
*
|
|
12
|
+
* The global client is useful for:
|
|
13
|
+
* - Zero-config DX where you want a single shared client
|
|
14
|
+
* - CLI tools that need to access the configured client
|
|
15
|
+
* - Testing scenarios where you can override the client with setGlobalClient()
|
|
16
|
+
*
|
|
17
|
+
* Note: This function requires Node.js and will only work in Node environments.
|
|
18
|
+
* For non-Node environments (browser, edge), create OpenWorkflow instances manually.
|
|
19
|
+
*
|
|
20
|
+
* @returns The global OpenWorkflow client instance
|
|
21
|
+
* @throws Error if config file is not found or invalid
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import { getGlobalClient } from 'openworkflow';
|
|
26
|
+
*
|
|
27
|
+
* const ow = await getGlobalClient();
|
|
28
|
+
* await ow.run(myWorkflow, { input: 'data' });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export async function getGlobalClient() {
|
|
32
|
+
if (globalClient) {
|
|
33
|
+
return globalClient;
|
|
34
|
+
}
|
|
35
|
+
const config = await loadConfig();
|
|
36
|
+
globalClient = config.ow;
|
|
37
|
+
return globalClient;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Set the global OpenWorkflow client instance.
|
|
41
|
+
* This is primarily useful for testing scenarios where you want to override
|
|
42
|
+
* the default client with a mock or test instance.
|
|
43
|
+
*
|
|
44
|
+
* @param client - The OpenWorkflow instance to set as the global client
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* import { setGlobalClient, OpenWorkflow } from 'openworkflow';
|
|
49
|
+
* import { BackendSqlite } from '@openworkflow/backend-sqlite';
|
|
50
|
+
*
|
|
51
|
+
* // In tests
|
|
52
|
+
* const testClient = new OpenWorkflow({
|
|
53
|
+
* backend: BackendSqlite.connect(':memory:')
|
|
54
|
+
* });
|
|
55
|
+
* setGlobalClient(testClient);
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export function setGlobalClient(client) {
|
|
59
|
+
globalClient = client;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Reset the global client to null.
|
|
63
|
+
* This is primarily useful for testing to ensure a clean state between tests.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* import { resetGlobalClient } from 'openworkflow';
|
|
68
|
+
*
|
|
69
|
+
* // In test cleanup
|
|
70
|
+
* afterEach(() => {
|
|
71
|
+
* resetGlobalClient();
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export function resetGlobalClient() {
|
|
76
|
+
globalClient = null;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=global.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global.js","sourceRoot":"","sources":["../global.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;GAGG;AACH,IAAI,YAAY,GAAwB,IAAI,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe;IACnC,IAAI,YAAY,EAAE,CAAC;QACjB,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,UAAU,EAAE,CAAC;IAClC,YAAY,GAAG,MAAM,CAAC,EAAE,CAAC;IACzB,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,eAAe,CAAC,MAAoB;IAClD,YAAY,GAAG,MAAM,CAAC;AACxB,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,iBAAiB;IAC/B,YAAY,GAAG,IAAI,CAAC;AACtB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
export type { OpenWorkflowOptions } from "./
|
|
2
|
-
export { OpenWorkflow } from "./
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
1
|
+
export type { OpenWorkflowOptions } from "./sdk/sdk.js";
|
|
2
|
+
export { OpenWorkflow, declareWorkflow } from "./sdk/sdk.js";
|
|
3
|
+
export type { WorkerOptions } from "./worker/worker.js";
|
|
4
|
+
export { Worker } from "./worker/worker.js";
|
|
5
|
+
export * from "./core/backend.js";
|
|
6
|
+
export type { JsonValue } from "./core/json.js";
|
|
7
|
+
export type { WorkflowRun } from "./core/workflow.js";
|
|
8
|
+
export type { StepAttempt } from "./core/step.js";
|
|
9
|
+
export { DEFAULT_RETRY_POLICY } from "./core/retry.js";
|
|
6
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,mBAAmB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE7D,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,cAAc,mBAAmB,CAAC;AAClC,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { OpenWorkflow } from "./
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export { OpenWorkflow, declareWorkflow } from "./sdk/sdk.js";
|
|
2
|
+
export { Worker } from "./worker/worker.js";
|
|
3
|
+
export * from "./core/backend.js";
|
|
4
|
+
export { DEFAULT_RETRY_POLICY } from "./core/retry.js";
|
|
4
5
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAG7D,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,cAAc,mBAAmB,CAAC;AAIlC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import type { Backend } from "../core/backend.js";
|
|
2
|
+
import type { StandardSchemaV1 } from "../core/schema.js";
|
|
3
|
+
import type { WorkflowRun } from "../core/workflow.js";
|
|
4
|
+
import type { SchemaInput, SchemaOutput } from "../core/workflow.js";
|
|
5
|
+
import type { WorkflowFunction } from "../execution/execution.js";
|
|
6
|
+
import { Worker } from "../worker/worker.js";
|
|
7
|
+
type WorkflowHandlerInput<TSchema, Input> = SchemaOutput<TSchema, Input>;
|
|
8
|
+
type WorkflowRunInput<TSchema, Input> = SchemaInput<TSchema, Input>;
|
|
9
|
+
/**
|
|
10
|
+
* Options for the OpenWorkflow client.
|
|
11
|
+
*/
|
|
12
|
+
export interface OpenWorkflowOptions {
|
|
13
|
+
backend: Backend;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Client used to register workflows and start runs.
|
|
17
|
+
*/
|
|
18
|
+
export declare class OpenWorkflow {
|
|
19
|
+
private backend;
|
|
20
|
+
private registeredWorkflows;
|
|
21
|
+
constructor(options: OpenWorkflowOptions);
|
|
22
|
+
/**
|
|
23
|
+
* Create a new Worker with this client's backend and workflows.
|
|
24
|
+
*/
|
|
25
|
+
newWorker(options?: {
|
|
26
|
+
concurrency?: number | undefined;
|
|
27
|
+
}): Worker;
|
|
28
|
+
/**
|
|
29
|
+
* Provide the implementation for a declared workflow. This links the workflow
|
|
30
|
+
* specification to its execution logic and registers it with this
|
|
31
|
+
* OpenWorkflow instance for worker execution.
|
|
32
|
+
*/
|
|
33
|
+
implementWorkflow<Input, Output, RunInput = Input>(spec: WorkflowSpec<Input, Output, RunInput>, fn: WorkflowFunction<Input, Output>): void;
|
|
34
|
+
/**
|
|
35
|
+
* Run a workflow from its specification. This is the primary way to schedule
|
|
36
|
+
* a workflow using only its WorkflowSpec.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const handle = await ow.runWorkflow(emailWorkflow, { to: 'user@example.com' });
|
|
41
|
+
* const result = await handle.result();
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
runWorkflow<Input, Output, RunInput = Input>(spec: WorkflowSpec<Input, Output, RunInput>, input?: RunInput, options?: WorkflowRunOptions): Promise<WorkflowRunHandle<Output>>;
|
|
45
|
+
/**
|
|
46
|
+
* Define and register a new workflow.
|
|
47
|
+
*
|
|
48
|
+
* This is a convenience method that combines `declareWorkflow` and
|
|
49
|
+
* `implementWorkflow` into a single call. For better code splitting and to
|
|
50
|
+
* separate declaration from implementation, consider using those methods
|
|
51
|
+
* separately.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const workflow = ow.defineWorkflow(
|
|
56
|
+
* { name: 'my-workflow' },
|
|
57
|
+
* async ({ input, step }) => {
|
|
58
|
+
* // workflow implementation
|
|
59
|
+
* },
|
|
60
|
+
* );
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
defineWorkflow<Input, Output, TSchema extends StandardSchemaV1 | undefined = undefined>(config: WorkflowDefinitionConfig<TSchema>, fn: WorkflowFunction<WorkflowHandlerInput<TSchema, Input>, Output>): WorkflowDefinition<WorkflowHandlerInput<TSchema, Input>, Output, WorkflowRunInput<TSchema, Input>>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Declare a workflow without providing its implementation (which is provided
|
|
67
|
+
* separately via `implementWorkflow`). Returns a lightweight WorkflowSpec
|
|
68
|
+
* that can be used to schedule workflow runs.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* export const emailWorkflow = declareWorkflow({
|
|
73
|
+
* name: 'send-email',
|
|
74
|
+
* schema: z.object({ to: z.string().email() }),
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare function declareWorkflow<Input, Output, TSchema extends StandardSchemaV1 | undefined = undefined>(config: WorkflowDefinitionConfig<TSchema>): WorkflowSpec<WorkflowHandlerInput<TSchema, Input>, Output, WorkflowRunInput<TSchema, Input>>;
|
|
79
|
+
/**
|
|
80
|
+
* Generate a composite key for workflow registration that includes both name
|
|
81
|
+
* and version.
|
|
82
|
+
*
|
|
83
|
+
* @param name - The workflow name
|
|
84
|
+
* @param version - The workflow version (null for unversioned)
|
|
85
|
+
* @returns A composite key string
|
|
86
|
+
*/
|
|
87
|
+
export declare function getWorkflowKey(name: string, version: string | null): string;
|
|
88
|
+
/**
|
|
89
|
+
* Config for declaring a workflow via `declareWorkflow()` or
|
|
90
|
+
* `defineWorkflow()`.
|
|
91
|
+
*/
|
|
92
|
+
export interface WorkflowDefinitionConfig<TSchema extends StandardSchemaV1 | undefined = undefined> {
|
|
93
|
+
/**
|
|
94
|
+
* The name of the workflow.
|
|
95
|
+
*/
|
|
96
|
+
name: string;
|
|
97
|
+
/**
|
|
98
|
+
* Optional version string for the workflow. Use this to enable zero-downtime
|
|
99
|
+
* deployments when changing workflow logic.
|
|
100
|
+
*/
|
|
101
|
+
version?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Optional schema used to validate inputs passed to `.run()`.
|
|
104
|
+
*/
|
|
105
|
+
schema?: TSchema;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* A lightweight, serializable specification for a workflow. This object can be
|
|
109
|
+
* shared between different parts of an application (e.g., API servers and
|
|
110
|
+
* workers) without bringing in implementation dependencies.
|
|
111
|
+
*
|
|
112
|
+
* Use `declareWorkflow()` to create a WorkflowSpec, and `ow.runWorkflow()`
|
|
113
|
+
* to schedule runs using only the spec.
|
|
114
|
+
*/
|
|
115
|
+
export interface WorkflowSpec<Input, Output, RunInput = Input> {
|
|
116
|
+
/** The name of the workflow. */
|
|
117
|
+
name: string;
|
|
118
|
+
/** The version of the workflow, or null if unversioned. */
|
|
119
|
+
version: string | null;
|
|
120
|
+
/** The schema used to validate inputs, or null if none. */
|
|
121
|
+
schema: StandardSchemaV1<RunInput, Input> | null;
|
|
122
|
+
_input?: Input;
|
|
123
|
+
_output?: Output;
|
|
124
|
+
_runInput?: RunInput;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* A fully defined workflow with its implementation. This class is returned by
|
|
128
|
+
* `defineWorkflow` and provides the `.run()` method for scheduling workflow
|
|
129
|
+
* runs.
|
|
130
|
+
*/
|
|
131
|
+
export declare class WorkflowDefinition<Input, Output, RunInput = Input> {
|
|
132
|
+
private readonly ow;
|
|
133
|
+
readonly spec: WorkflowSpec<Input, Output, RunInput>;
|
|
134
|
+
readonly fn: WorkflowFunction<Input, Output>;
|
|
135
|
+
constructor(ow: OpenWorkflow, spec: WorkflowSpec<Input, Output, RunInput>, fn: WorkflowFunction<Input, Output>);
|
|
136
|
+
/**
|
|
137
|
+
* Starts a new workflow run.
|
|
138
|
+
*/
|
|
139
|
+
run(input?: RunInput, options?: WorkflowRunOptions): Promise<WorkflowRunHandle<Output>>;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Options for creating a new workflow run from a workflow definition when
|
|
143
|
+
* calling `workflowDef.run()`.
|
|
144
|
+
*/
|
|
145
|
+
export interface WorkflowRunOptions {
|
|
146
|
+
/**
|
|
147
|
+
* Set a deadline for the workflow run. If the workflow exceeds this deadline,
|
|
148
|
+
* it will be marked as failed.
|
|
149
|
+
*/
|
|
150
|
+
deadlineAt?: Date;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Options for WorkflowHandle.
|
|
154
|
+
*/
|
|
155
|
+
export interface WorkflowHandleOptions {
|
|
156
|
+
backend: Backend;
|
|
157
|
+
workflowRun: WorkflowRun;
|
|
158
|
+
resultPollIntervalMs: number;
|
|
159
|
+
resultTimeoutMs: number;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Represents a started workflow run and provides methods to await its result.
|
|
163
|
+
* Returned from `workflowDef.run()`.
|
|
164
|
+
*/
|
|
165
|
+
export declare class WorkflowRunHandle<Output> {
|
|
166
|
+
private backend;
|
|
167
|
+
readonly workflowRun: WorkflowRun;
|
|
168
|
+
private resultPollIntervalMs;
|
|
169
|
+
private resultTimeoutMs;
|
|
170
|
+
constructor(options: WorkflowHandleOptions);
|
|
171
|
+
/**
|
|
172
|
+
* Waits for the workflow run to complete and returns the result.
|
|
173
|
+
*/
|
|
174
|
+
result(): Promise<Output>;
|
|
175
|
+
/**
|
|
176
|
+
* Cancels the workflow run. Only workflows in pending, running, or sleeping
|
|
177
|
+
* status can be canceled.
|
|
178
|
+
*/
|
|
179
|
+
cancel(): Promise<void>;
|
|
180
|
+
}
|
|
181
|
+
export {};
|
|
182
|
+
//# sourceMappingURL=sdk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../sdk/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAErE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM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@@
|
|
|
1
|
+
import { validateInput } from "../core/workflow.js";
|
|
2
|
+
import { Worker } from "../worker/worker.js";
|
|
3
|
+
const DEFAULT_RESULT_POLL_INTERVAL_MS = 1000; // 1s
|
|
4
|
+
const DEFAULT_RESULT_TIMEOUT_MS = 5 * 60 * 1000; // 5m
|
|
5
|
+
/**
|
|
6
|
+
* Client used to register workflows and start runs.
|
|
7
|
+
*/
|
|
8
|
+
export class OpenWorkflow {
|
|
9
|
+
backend;
|
|
10
|
+
registeredWorkflows = new Map();
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.backend = options.backend;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a new Worker with this client's backend and workflows.
|
|
16
|
+
*/
|
|
17
|
+
newWorker(options) {
|
|
18
|
+
return new Worker({
|
|
19
|
+
backend: this.backend,
|
|
20
|
+
workflows: this.registeredWorkflows,
|
|
21
|
+
concurrency: options?.concurrency,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Provide the implementation for a declared workflow. This links the workflow
|
|
26
|
+
* specification to its execution logic and registers it with this
|
|
27
|
+
* OpenWorkflow instance for worker execution.
|
|
28
|
+
*/
|
|
29
|
+
implementWorkflow(spec, fn) {
|
|
30
|
+
const key = getWorkflowKey(spec.name, spec.version);
|
|
31
|
+
if (this.registeredWorkflows.has(key)) {
|
|
32
|
+
const versionStr = spec.version ? ` (version: ${spec.version})` : "";
|
|
33
|
+
throw new Error(`Workflow "${spec.name}"${versionStr} is already registered`);
|
|
34
|
+
}
|
|
35
|
+
const definition = new WorkflowDefinition(this, spec, fn);
|
|
36
|
+
this.registeredWorkflows.set(key, definition);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Run a workflow from its specification. This is the primary way to schedule
|
|
40
|
+
* a workflow using only its WorkflowSpec.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const handle = await ow.runWorkflow(emailWorkflow, { to: 'user@example.com' });
|
|
45
|
+
* const result = await handle.result();
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
async runWorkflow(spec, input, options) {
|
|
49
|
+
const validationResult = await validateInput(spec.schema, input);
|
|
50
|
+
if (!validationResult.success) {
|
|
51
|
+
throw new Error(validationResult.error);
|
|
52
|
+
}
|
|
53
|
+
const parsedInput = validationResult.value;
|
|
54
|
+
const workflowRun = await this.backend.createWorkflowRun({
|
|
55
|
+
workflowName: spec.name,
|
|
56
|
+
version: spec.version,
|
|
57
|
+
idempotencyKey: null,
|
|
58
|
+
config: {},
|
|
59
|
+
context: null,
|
|
60
|
+
input: parsedInput ?? null,
|
|
61
|
+
availableAt: null,
|
|
62
|
+
deadlineAt: options?.deadlineAt ?? null,
|
|
63
|
+
});
|
|
64
|
+
return new WorkflowRunHandle({
|
|
65
|
+
backend: this.backend,
|
|
66
|
+
workflowRun: workflowRun,
|
|
67
|
+
resultPollIntervalMs: DEFAULT_RESULT_POLL_INTERVAL_MS,
|
|
68
|
+
resultTimeoutMs: DEFAULT_RESULT_TIMEOUT_MS,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Define and register a new workflow.
|
|
73
|
+
*
|
|
74
|
+
* This is a convenience method that combines `declareWorkflow` and
|
|
75
|
+
* `implementWorkflow` into a single call. For better code splitting and to
|
|
76
|
+
* separate declaration from implementation, consider using those methods
|
|
77
|
+
* separately.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* const workflow = ow.defineWorkflow(
|
|
82
|
+
* { name: 'my-workflow' },
|
|
83
|
+
* async ({ input, step }) => {
|
|
84
|
+
* // workflow implementation
|
|
85
|
+
* },
|
|
86
|
+
* );
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
defineWorkflow(config, fn) {
|
|
90
|
+
const spec = declareWorkflow(config);
|
|
91
|
+
const key = getWorkflowKey(spec.name, spec.version);
|
|
92
|
+
const definition = new WorkflowDefinition(this, spec, fn);
|
|
93
|
+
this.registeredWorkflows.set(key, definition);
|
|
94
|
+
return definition;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Declare a workflow without providing its implementation (which is provided
|
|
99
|
+
* separately via `implementWorkflow`). Returns a lightweight WorkflowSpec
|
|
100
|
+
* that can be used to schedule workflow runs.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* export const emailWorkflow = declareWorkflow({
|
|
105
|
+
* name: 'send-email',
|
|
106
|
+
* schema: z.object({ to: z.string().email() }),
|
|
107
|
+
* });
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export function declareWorkflow(config) {
|
|
111
|
+
return {
|
|
112
|
+
name: config.name,
|
|
113
|
+
version: config.version ?? null,
|
|
114
|
+
schema: config.schema ?? null,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Generate a composite key for workflow registration that includes both name
|
|
119
|
+
* and version.
|
|
120
|
+
*
|
|
121
|
+
* @param name - The workflow name
|
|
122
|
+
* @param version - The workflow version (null for unversioned)
|
|
123
|
+
* @returns A composite key string
|
|
124
|
+
*/
|
|
125
|
+
export function getWorkflowKey(name, version) {
|
|
126
|
+
return version ? `${name}@${version}` : name;
|
|
127
|
+
}
|
|
128
|
+
//
|
|
129
|
+
// --- Workflow Definition
|
|
130
|
+
//
|
|
131
|
+
/**
|
|
132
|
+
* A fully defined workflow with its implementation. This class is returned by
|
|
133
|
+
* `defineWorkflow` and provides the `.run()` method for scheduling workflow
|
|
134
|
+
* runs.
|
|
135
|
+
*/
|
|
136
|
+
export class WorkflowDefinition {
|
|
137
|
+
ow;
|
|
138
|
+
spec;
|
|
139
|
+
fn;
|
|
140
|
+
constructor(ow, spec, fn) {
|
|
141
|
+
this.ow = ow;
|
|
142
|
+
this.spec = spec;
|
|
143
|
+
this.fn = fn;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Starts a new workflow run.
|
|
147
|
+
*/
|
|
148
|
+
async run(input, options) {
|
|
149
|
+
return this.ow.runWorkflow(this.spec, input, options);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Represents a started workflow run and provides methods to await its result.
|
|
154
|
+
* Returned from `workflowDef.run()`.
|
|
155
|
+
*/
|
|
156
|
+
export class WorkflowRunHandle {
|
|
157
|
+
backend;
|
|
158
|
+
workflowRun;
|
|
159
|
+
resultPollIntervalMs;
|
|
160
|
+
resultTimeoutMs;
|
|
161
|
+
constructor(options) {
|
|
162
|
+
this.backend = options.backend;
|
|
163
|
+
this.workflowRun = options.workflowRun;
|
|
164
|
+
this.resultPollIntervalMs = options.resultPollIntervalMs;
|
|
165
|
+
this.resultTimeoutMs = options.resultTimeoutMs;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Waits for the workflow run to complete and returns the result.
|
|
169
|
+
*/
|
|
170
|
+
async result() {
|
|
171
|
+
const start = Date.now();
|
|
172
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
173
|
+
while (true) {
|
|
174
|
+
const latest = await this.backend.getWorkflowRun({
|
|
175
|
+
workflowRunId: this.workflowRun.id,
|
|
176
|
+
});
|
|
177
|
+
if (!latest) {
|
|
178
|
+
throw new Error(`Workflow run ${this.workflowRun.id} no longer exists`);
|
|
179
|
+
}
|
|
180
|
+
// 'succeeded' status is deprecated
|
|
181
|
+
if (latest.status === "succeeded" || latest.status === "completed") {
|
|
182
|
+
return latest.output;
|
|
183
|
+
}
|
|
184
|
+
if (latest.status === "failed") {
|
|
185
|
+
throw new Error(`Workflow ${this.workflowRun.workflowName} failed: ${JSON.stringify(latest.error)}`);
|
|
186
|
+
}
|
|
187
|
+
if (latest.status === "canceled") {
|
|
188
|
+
throw new Error(`Workflow ${this.workflowRun.workflowName} was canceled`);
|
|
189
|
+
}
|
|
190
|
+
if (Date.now() - start > this.resultTimeoutMs) {
|
|
191
|
+
throw new Error(`Timed out waiting for workflow run ${this.workflowRun.id} to finish`);
|
|
192
|
+
}
|
|
193
|
+
await new Promise((resolve) => {
|
|
194
|
+
setTimeout(resolve, this.resultPollIntervalMs);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Cancels the workflow run. Only workflows in pending, running, or sleeping
|
|
200
|
+
* status can be canceled.
|
|
201
|
+
*/
|
|
202
|
+
async cancel() {
|
|
203
|
+
await this.backend.cancelWorkflowRun({
|
|
204
|
+
workflowRunId: this.workflowRun.id,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=sdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../sdk/sdk.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,MAAM,+BAA+B,GAAG,IAAI,CAAC,CAAC,KAAK;AACnD,MAAM,yBAAyB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,KAAK;AAetD;;GAEG;AACH,MAAM,OAAO,YAAY;IACf,OAAO,CAAU;IACjB,mBAAmB,GAAG,IAAI,GAAG,EAGlC,CAAC;IAEJ,YAAY,OAA4B;QACtC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,OAA8C;QACtD,OAAO,IAAI,MAAM,CAAC;YAChB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,SAAS,EAAE,IAAI,CAAC,mBAAmB;YACnC,WAAW,EAAE,OAAO,EAAE,WAAW;SAClC,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,iBAAiB,CACf,IAA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