openworkflow 0.4.0 → 0.5.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 (143) hide show
  1. package/README.md +57 -46
  2. package/dist/backend-postgres/index.d.ts +44 -0
  3. package/dist/backend-postgres/index.d.ts.map +1 -0
  4. package/dist/backend-postgres/index.js +535 -0
  5. package/dist/backend-postgres/index.js.map +1 -0
  6. package/dist/backend-postgres/postgres.d.ts +42 -0
  7. package/dist/backend-postgres/postgres.d.ts.map +1 -0
  8. package/dist/backend-postgres/postgres.js +234 -0
  9. package/dist/backend-postgres/postgres.js.map +1 -0
  10. package/dist/backend-sqlite/index.d.ts +42 -0
  11. package/dist/backend-sqlite/index.d.ts.map +1 -0
  12. package/dist/backend-sqlite/index.js +655 -0
  13. package/dist/backend-sqlite/index.js.map +1 -0
  14. package/dist/backend-sqlite/sqlite.d.ts +61 -0
  15. package/dist/backend-sqlite/sqlite.d.ts.map +1 -0
  16. package/dist/backend-sqlite/sqlite.js +247 -0
  17. package/dist/backend-sqlite/sqlite.js.map +1 -0
  18. package/dist/backend.d.ts +21 -89
  19. package/dist/backend.d.ts.map +1 -1
  20. package/dist/backend.js +0 -21
  21. package/dist/backend.js.map +1 -1
  22. package/dist/bin/openworkflow.d.ts +3 -0
  23. package/dist/bin/openworkflow.d.ts.map +1 -0
  24. package/dist/bin/openworkflow.js +44 -0
  25. package/dist/bin/openworkflow.js.map +1 -0
  26. package/dist/client.d.ts +68 -80
  27. package/dist/client.d.ts.map +1 -1
  28. package/dist/client.js +83 -53
  29. package/dist/client.js.map +1 -1
  30. package/dist/config.d.ts +34 -0
  31. package/dist/config.d.ts.map +1 -0
  32. package/dist/config.js +49 -0
  33. package/dist/config.js.map +1 -0
  34. package/dist/{duration.d.ts → core/duration.d.ts} +5 -2
  35. package/dist/core/duration.d.ts.map +1 -0
  36. package/dist/{duration.js → core/duration.js} +9 -6
  37. package/dist/core/duration.js.map +1 -0
  38. package/dist/core/error.d.ts +14 -0
  39. package/dist/core/error.d.ts.map +1 -0
  40. package/dist/core/error.js +18 -0
  41. package/dist/core/error.js.map +1 -0
  42. package/dist/core/json.d.ts +5 -0
  43. package/dist/core/json.d.ts.map +1 -0
  44. package/dist/core/json.js +2 -0
  45. package/dist/core/json.js.map +1 -0
  46. package/dist/core/result.d.ts +22 -0
  47. package/dist/core/result.d.ts.map +1 -0
  48. package/dist/core/result.js +17 -0
  49. package/dist/core/result.js.map +1 -0
  50. package/dist/core/retry.d.ts +7 -0
  51. package/dist/core/retry.d.ts.map +1 -0
  52. package/dist/core/retry.js +7 -0
  53. package/dist/core/retry.js.map +1 -0
  54. package/dist/core/schema.d.ts.map +1 -0
  55. package/dist/core/schema.js.map +1 -0
  56. package/dist/core/step.d.ts +89 -0
  57. package/dist/core/step.d.ts.map +1 -0
  58. package/dist/core/step.js +66 -0
  59. package/dist/core/step.js.map +1 -0
  60. package/dist/core/workflow.d.ts +63 -0
  61. package/dist/core/workflow.d.ts.map +1 -0
  62. package/dist/core/workflow.js +35 -0
  63. package/dist/core/workflow.js.map +1 -0
  64. package/dist/execution.d.ts +69 -0
  65. package/dist/execution.d.ts.map +1 -0
  66. package/dist/execution.js +188 -0
  67. package/dist/execution.js.map +1 -0
  68. package/dist/index.d.ts +2 -1
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.js +2 -1
  71. package/dist/index.js.map +1 -1
  72. package/dist/internal.d.ts +8 -0
  73. package/dist/internal.d.ts.map +1 -0
  74. package/dist/internal.js +5 -0
  75. package/dist/internal.js.map +1 -0
  76. package/dist/pg/backend.d.ts +42 -0
  77. package/dist/pg/backend.d.ts.map +1 -0
  78. package/dist/pg/backend.js +534 -0
  79. package/dist/pg/backend.js.map +1 -0
  80. package/dist/pg/index.d.ts +3 -0
  81. package/dist/pg/index.d.ts.map +1 -0
  82. package/dist/pg/index.js +3 -0
  83. package/dist/pg/index.js.map +1 -0
  84. package/dist/pg/postgres.d.ts +42 -0
  85. package/dist/pg/postgres.d.ts.map +1 -0
  86. package/dist/pg/postgres.js +234 -0
  87. package/dist/pg/postgres.js.map +1 -0
  88. package/dist/pg/scripts/db-migrate.d.ts +2 -0
  89. package/dist/pg/scripts/db-migrate.d.ts.map +1 -0
  90. package/dist/pg/scripts/db-migrate.js +5 -0
  91. package/dist/pg/scripts/db-migrate.js.map +1 -0
  92. package/dist/pg/scripts/db-reset.d.ts +2 -0
  93. package/dist/pg/scripts/db-reset.d.ts.map +1 -0
  94. package/dist/pg/scripts/db-reset.js +6 -0
  95. package/dist/pg/scripts/db-reset.js.map +1 -0
  96. package/dist/pg/scripts/squawk.d.ts +2 -0
  97. package/dist/pg/scripts/squawk.d.ts.map +1 -0
  98. package/dist/pg/scripts/squawk.js +17 -0
  99. package/dist/pg/scripts/squawk.js.map +1 -0
  100. package/dist/pg/vitest.global-setup.d.ts +3 -0
  101. package/dist/pg/vitest.global-setup.d.ts.map +1 -0
  102. package/dist/pg/vitest.global-setup.js +8 -0
  103. package/dist/pg/vitest.global-setup.js.map +1 -0
  104. package/dist/registry.d.ts +27 -0
  105. package/dist/registry.d.ts.map +1 -0
  106. package/dist/registry.js +49 -0
  107. package/dist/registry.js.map +1 -0
  108. package/dist/sqlite/backend.d.ts +40 -0
  109. package/dist/sqlite/backend.d.ts.map +1 -0
  110. package/dist/sqlite/backend.js +654 -0
  111. package/dist/sqlite/backend.js.map +1 -0
  112. package/dist/sqlite/index.d.ts +3 -0
  113. package/dist/sqlite/index.d.ts.map +1 -0
  114. package/dist/sqlite/index.js +3 -0
  115. package/dist/sqlite/index.js.map +1 -0
  116. package/dist/sqlite/sqlite.d.ts +61 -0
  117. package/dist/sqlite/sqlite.d.ts.map +1 -0
  118. package/dist/sqlite/sqlite.js +247 -0
  119. package/dist/sqlite/sqlite.js.map +1 -0
  120. package/dist/testing/backend.testsuite.d.ts +20 -0
  121. package/dist/testing/backend.testsuite.d.ts.map +1 -0
  122. package/dist/testing/backend.testsuite.js +1091 -0
  123. package/dist/testing/backend.testsuite.js.map +1 -0
  124. package/dist/testing/index.d.ts +2 -0
  125. package/dist/testing/index.d.ts.map +1 -0
  126. package/dist/testing/index.js +2 -0
  127. package/dist/testing/index.js.map +1 -0
  128. package/dist/tsconfig.tsbuildinfo +1 -1
  129. package/dist/worker.d.ts +10 -3
  130. package/dist/worker.d.ts.map +1 -1
  131. package/dist/worker.js +29 -195
  132. package/dist/worker.js.map +1 -1
  133. package/dist/workflow.d.ts +60 -0
  134. package/dist/workflow.d.ts.map +1 -0
  135. package/dist/workflow.js +49 -0
  136. package/dist/workflow.js.map +1 -0
  137. package/package.json +16 -6
  138. package/dist/duration.d.ts.map +0 -1
  139. package/dist/duration.js.map +0 -1
  140. package/dist/schema.d.ts.map +0 -1
  141. package/dist/schema.js.map +0 -1
  142. /package/dist/{schema.d.ts → core/schema.d.ts} +0 -0
  143. /package/dist/{schema.js → core/schema.js} +0 -0
package/dist/client.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import type { Backend, WorkflowRun } from "./backend.js";
2
- import { DurationString } from "./duration.js";
3
- import { StandardSchemaV1 } from "./schema.js";
1
+ import type { Backend } from "./backend.js";
2
+ import type { StandardSchemaV1 } from "./core/schema.js";
3
+ import type { SchemaInput, SchemaOutput, WorkflowRun } from "./core/workflow.js";
4
+ import type { WorkflowFunction } from "./execution.js";
4
5
  import { Worker } from "./worker.js";
5
- type SchemaInput<TSchema, Fallback> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema> : Fallback;
6
- type SchemaOutput<TSchema, Fallback> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : Fallback;
6
+ import { type Workflow, type WorkflowSpec } from "./workflow.js";
7
7
  type WorkflowHandlerInput<TSchema, Input> = SchemaOutput<TSchema, Input>;
8
8
  type WorkflowRunInput<TSchema, Input> = SchemaInput<TSchema, Input>;
9
9
  /**
@@ -17,101 +17,76 @@ export interface OpenWorkflowOptions {
17
17
  */
18
18
  export declare class OpenWorkflow {
19
19
  private backend;
20
- private registeredWorkflows;
20
+ private registry;
21
21
  constructor(options: OpenWorkflowOptions);
22
22
  /**
23
23
  * Create a new Worker with this client's backend and workflows.
24
+ * @param options - Worker options
25
+ * @param options.concurrency - Max concurrent workflow runs
26
+ * @returns Worker instance
24
27
  */
25
28
  newWorker(options?: {
26
- concurrency?: number;
29
+ concurrency?: number | undefined;
27
30
  }): Worker;
28
31
  /**
29
- * Define and register a new workflow.
30
- */
31
- 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>>;
32
- }
33
- /**
34
- * Options for WorkflowDefinition.
35
- */
36
- export interface WorkflowDefinitionOptions<Input, Output, RunInput = Input> {
37
- backend: Backend;
38
- name: string;
39
- version?: string;
40
- fn: WorkflowFunction<Input, Output>;
41
- schema?: StandardSchemaV1<RunInput, Input> | undefined;
42
- }
43
- /**
44
- * Config passed to `defineWorkflow()` when defining a workflow.
45
- */
46
- export interface WorkflowDefinitionConfig<TSchema extends StandardSchemaV1 | undefined = undefined> {
47
- /**
48
- * The name of the workflow.
32
+ * Provide the implementation for a declared workflow. This links the workflow
33
+ * specification to its execution logic and registers it with this
34
+ * OpenWorkflow instance for worker execution.
35
+ * @param spec - Workflow spec
36
+ * @param fn - Workflow implementation
49
37
  */
50
- name: string;
38
+ implementWorkflow<Input, Output, RunInput = Input>(spec: WorkflowSpec<Input, Output, RunInput>, fn: WorkflowFunction<Input, Output>): void;
51
39
  /**
52
- * Optional version string for the workflow. Use this to enable zero-downtime
53
- * deployments when changing workflow logic.
40
+ * Run a workflow from its specification. This is the primary way to schedule
41
+ * a workflow using only its WorkflowSpec.
42
+ * @param spec - Workflow spec
43
+ * @param input - Workflow input
44
+ * @param options - Run options
45
+ * @returns Handle for awaiting the result
46
+ * @example
47
+ * ```ts
48
+ * const handle = await ow.runWorkflow(emailWorkflow, { to: 'user@example.com' });
49
+ * const result = await handle.result();
50
+ * ```
54
51
  */
55
- version?: string;
52
+ runWorkflow<Input, Output, RunInput = Input>(spec: WorkflowSpec<Input, Output, RunInput>, input?: RunInput, options?: WorkflowRunOptions): Promise<WorkflowRunHandle<Output>>;
56
53
  /**
57
- * Optional schema used to validate inputs passed to `.run()`.
54
+ * Define and register a new workflow.
55
+ * @param spec - Workflow spec
56
+ * @param fn - Workflow implementation
57
+ * @returns Runnable workflow
58
+ * @example
59
+ * ```ts
60
+ * const workflow = ow.defineWorkflow(
61
+ * { name: 'my-workflow' },
62
+ * async ({ input, step }) => {
63
+ * // workflow implementation
64
+ * },
65
+ * );
66
+ * ```
58
67
  */
59
- schema?: TSchema;
68
+ defineWorkflow<Input, Output, TSchema extends StandardSchemaV1 | undefined = undefined>(spec: WorkflowSpec<WorkflowHandlerInput<TSchema, Input>, Output, WorkflowRunInput<TSchema, Input>>, fn: WorkflowFunction<WorkflowHandlerInput<TSchema, Input>, Output>): RunnableWorkflow<WorkflowHandlerInput<TSchema, Input>, Output, WorkflowRunInput<TSchema, Input>>;
60
69
  }
61
70
  /**
62
- * Represents a workflow definition that can be used to start runs. Returned
63
- * from `client.defineWorkflow()`.
71
+ * A fully defined workflow with its implementation. This class is returned by
72
+ * `client.defineWorkflow` and provides the `.run()` method for scheduling
73
+ * workflow runs.
64
74
  */
65
- export declare class WorkflowDefinition<Input, Output, RunInput = Input> {
66
- private backend;
67
- readonly name: string;
68
- readonly version: string | null;
69
- readonly fn: WorkflowFunction<Input, Output>;
70
- private readonly schema;
71
- constructor(options: WorkflowDefinitionOptions<Input, Output, RunInput>);
75
+ export declare class RunnableWorkflow<Input, Output, RunInput = Input> {
76
+ private readonly ow;
77
+ readonly workflow: Workflow<Input, Output, RunInput>;
78
+ constructor(ow: OpenWorkflow, workflow: Workflow<Input, Output, RunInput>);
72
79
  /**
73
80
  * Starts a new workflow run.
81
+ * @param input - Workflow input
82
+ * @param options - Run options
83
+ * @returns Workflow run handle
74
84
  */
75
85
  run(input?: RunInput, options?: WorkflowRunOptions): Promise<WorkflowRunHandle<Output>>;
76
86
  }
77
87
  /**
78
- * Params passed to a workflow function for the user to use when defining steps.
79
- */
80
- export interface WorkflowFunctionParams<Input> {
81
- input: Input;
82
- step: StepApi;
83
- version: string | null;
84
- }
85
- /**
86
- * The workflow definition's function (defined by the user) that the user uses
87
- * to define the workflow's steps.
88
- */
89
- export type WorkflowFunction<Input, Output> = (params: WorkflowFunctionParams<Input>) => Promise<Output> | Output;
90
- /**
91
- * Config for an individual step defined with `step.run()`.
92
- */
93
- export interface StepFunctionConfig {
94
- /**
95
- * The name of the step.
96
- */
97
- name: string;
98
- }
99
- /**
100
- * Represents the API for defining steps within a workflow. Used within a
101
- * workflow handler to define steps by calling `step.run()`.
102
- */
103
- export interface StepApi {
104
- run<Output>(config: StepFunctionConfig, fn: StepFunction<Output>): Promise<Output>;
105
- sleep(name: string, duration: DurationString): Promise<void>;
106
- }
107
- /**
108
- * The step definition (defined by the user) that executes user code. Can return
109
- * undefined (e.g., when using `return;`) which will be converted to null.
110
- */
111
- export type StepFunction<Output> = () => Promise<Output | undefined> | Output | undefined;
112
- /**
113
- * Options for creating a new workflow run from a workflow definition when
114
- * calling `workflowDef.run()`.
88
+ * Options for creating a new workflow run from a runnable workflow when calling
89
+ * `workflowDef.run()`.
115
90
  */
116
91
  export interface WorkflowRunOptions {
117
92
  /**
@@ -129,6 +104,17 @@ export interface WorkflowHandleOptions {
129
104
  resultPollIntervalMs: number;
130
105
  resultTimeoutMs: number;
131
106
  }
107
+ /**
108
+ * Options for result() on a WorkflowRunHandle.
109
+ */
110
+ export interface WorkflowRunHandleResultOptions {
111
+ /**
112
+ * Time to wait for a workflow run to complete. Throws an error if the timeout
113
+ * is exceeded.
114
+ * @default 300000 (5 minutes)
115
+ */
116
+ timeoutMs?: number;
117
+ }
132
118
  /**
133
119
  * Represents a started workflow run and provides methods to await its result.
134
120
  * Returned from `workflowDef.run()`.
@@ -141,8 +127,10 @@ export declare class WorkflowRunHandle<Output> {
141
127
  constructor(options: WorkflowHandleOptions);
142
128
  /**
143
129
  * Waits for the workflow run to complete and returns the result.
130
+ * @param options - Options for waiting for the result
131
+ * @returns Workflow output
144
132
  */
145
- result(): Promise<Output>;
133
+ result(options?: WorkflowRunHandleResultOptions): Promise<Output>;
146
134
  /**
147
135
  * Cancels the workflow run. Only workflows in pending, running, or sleeping
148
136
  * status can be canceled.
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAKrC,KAAK,WAAW,CAAC,OAAO,EAAE,QAAQ,IAAI,OAAO,SAAS,gBAAgB,GAClE,gBAAgB,CAAC,UAAU,CAAC,OAAO,CAAC,GACpC,QAAQ,CAAC;AAEb,KAAK,YAAY,CAAC,OAAO,EAAE,QAAQ,IAAI,OAAO,SAAS,gBAAgB,GACnE,gBAAgB,CAAC,WAAW,CAAC,OAAO,CAAC,GACrC,QAAQ,CAAC;AAGb,KAAK,oBAAoB,CAAC,OAAO,EAAE,KAAK,IAAI,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AAGzE,KAAK,gBAAgB,CAAC,OAAO,EAAE,KAAK,IAAI,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,m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.js";
2
+ import { WorkflowRegistry } from "./registry.js";
1
3
  import { Worker } from "./worker.js";
4
+ import { defineWorkflow, } from "./workflow.js";
2
5
  const DEFAULT_RESULT_POLL_INTERVAL_MS = 1000; // 1s
3
6
  const DEFAULT_RESULT_TIMEOUT_MS = 5 * 60 * 1000; // 5m
4
7
  /**
@@ -6,77 +9,59 @@ const DEFAULT_RESULT_TIMEOUT_MS = 5 * 60 * 1000; // 5m
6
9
  */
7
10
  export class OpenWorkflow {
8
11
  backend;
9
- registeredWorkflows = new Map();
12
+ registry = new WorkflowRegistry();
10
13
  constructor(options) {
11
14
  this.backend = options.backend;
12
15
  }
13
16
  /**
14
17
  * Create a new Worker with this client's backend and workflows.
18
+ * @param options - Worker options
19
+ * @param options.concurrency - Max concurrent workflow runs
20
+ * @returns Worker instance
15
21
  */
16
22
  newWorker(options) {
17
23
  return new Worker({
18
24
  backend: this.backend,
19
- workflows: [...this.registeredWorkflows.values()],
25
+ workflows: this.registry.getAll(),
20
26
  concurrency: options?.concurrency,
21
27
  });
22
28
  }
23
29
  /**
24
- * Define and register a new workflow.
30
+ * Provide the implementation for a declared workflow. This links the workflow
31
+ * specification to its execution logic and registers it with this
32
+ * OpenWorkflow instance for worker execution.
33
+ * @param spec - Workflow spec
34
+ * @param fn - Workflow implementation
25
35
  */
26
- defineWorkflow(config, fn) {
27
- const { name, version } = config;
28
- if (this.registeredWorkflows.has(name)) {
29
- throw new Error(`Workflow "${name}" is already registered`);
30
- }
31
- const definition = new WorkflowDefinition({
32
- backend: this.backend,
33
- name,
34
- ...(version !== undefined && { version }),
36
+ implementWorkflow(spec, fn) {
37
+ const workflow = {
38
+ spec,
35
39
  fn,
36
- schema: config.schema,
37
- });
38
- this.registeredWorkflows.set(name, definition);
39
- return definition;
40
- }
41
- }
42
- /**
43
- * Represents a workflow definition that can be used to start runs. Returned
44
- * from `client.defineWorkflow()`.
45
- */
46
- export class WorkflowDefinition {
47
- backend;
48
- name;
49
- version;
50
- fn;
51
- schema;
52
- constructor(options) {
53
- this.backend = options.backend;
54
- this.name = options.name;
55
- this.version = options.version ?? null;
56
- this.fn = options.fn;
57
- this.schema = options.schema ?? null;
40
+ };
41
+ this.registry.register(workflow);
58
42
  }
59
43
  /**
60
- * Starts a new workflow run.
44
+ * Run a workflow from its specification. This is the primary way to schedule
45
+ * a workflow using only its WorkflowSpec.
46
+ * @param spec - Workflow spec
47
+ * @param input - Workflow input
48
+ * @param options - Run options
49
+ * @returns Handle for awaiting the result
50
+ * @example
51
+ * ```ts
52
+ * const handle = await ow.runWorkflow(emailWorkflow, { to: 'user@example.com' });
53
+ * const result = await handle.result();
54
+ * ```
61
55
  */
62
- async run(input, options) {
63
- let parsedInput = input;
64
- if (this.schema) {
65
- // https://standardschema.dev
66
- const result = this.schema["~standard"].validate(input);
67
- const resolved = await Promise.resolve(result);
68
- if (resolved.issues) {
69
- const messages = resolved.issues.length > 0
70
- ? resolved.issues.map((issue) => issue.message).join("; ")
71
- : "Validation failed";
72
- throw new Error(messages);
73
- }
74
- parsedInput = resolved.value;
56
+ async runWorkflow(spec, input, options) {
57
+ const validationResult = await validateInput(spec.schema, input);
58
+ if (!validationResult.success) {
59
+ throw new Error(validationResult.error);
75
60
  }
76
- // need to come back and support idempotency keys, scheduling, etc.
61
+ const parsedInput = validationResult.value;
77
62
  const workflowRun = await this.backend.createWorkflowRun({
78
- workflowName: this.name,
79
- version: this.version,
63
+ workflowName: spec.name,
64
+ version: spec.version ?? null,
80
65
  idempotencyKey: null,
81
66
  config: {},
82
67
  context: null,
@@ -91,6 +76,48 @@ export class WorkflowDefinition {
91
76
  resultTimeoutMs: DEFAULT_RESULT_TIMEOUT_MS,
92
77
  });
93
78
  }
79
+ /**
80
+ * Define and register a new workflow.
81
+ * @param spec - Workflow spec
82
+ * @param fn - Workflow implementation
83
+ * @returns Runnable workflow
84
+ * @example
85
+ * ```ts
86
+ * const workflow = ow.defineWorkflow(
87
+ * { name: 'my-workflow' },
88
+ * async ({ input, step }) => {
89
+ * // workflow implementation
90
+ * },
91
+ * );
92
+ * ```
93
+ */
94
+ defineWorkflow(spec, fn) {
95
+ const workflow = defineWorkflow(spec, fn);
96
+ this.registry.register(workflow);
97
+ return new RunnableWorkflow(this, workflow);
98
+ }
99
+ }
100
+ /**
101
+ * A fully defined workflow with its implementation. This class is returned by
102
+ * `client.defineWorkflow` and provides the `.run()` method for scheduling
103
+ * workflow runs.
104
+ */
105
+ export class RunnableWorkflow {
106
+ ow;
107
+ workflow;
108
+ constructor(ow, workflow) {
109
+ this.ow = ow;
110
+ this.workflow = workflow;
111
+ }
112
+ /**
113
+ * Starts a new workflow run.
114
+ * @param input - Workflow input
115
+ * @param options - Run options
116
+ * @returns Workflow run handle
117
+ */
118
+ async run(input, options) {
119
+ return this.ow.runWorkflow(this.workflow.spec, input, options);
120
+ }
94
121
  }
95
122
  /**
96
123
  * Represents a started workflow run and provides methods to await its result.
@@ -109,9 +136,12 @@ export class WorkflowRunHandle {
109
136
  }
110
137
  /**
111
138
  * Waits for the workflow run to complete and returns the result.
139
+ * @param options - Options for waiting for the result
140
+ * @returns Workflow output
112
141
  */
113
- async result() {
142
+ async result(options) {
114
143
  const start = Date.now();
144
+ const timeout = options?.timeoutMs ?? this.resultTimeoutMs;
115
145
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
116
146
  while (true) {
117
147
  const latest = await this.backend.getWorkflowRun({
@@ -130,7 +160,7 @@ export class WorkflowRunHandle {
130
160
  if (latest.status === "canceled") {
131
161
  throw new Error(`Workflow ${this.workflowRun.workflowName} was canceled`);
132
162
  }
133
- if (Date.now() - start > this.resultTimeoutMs) {
163
+ if (Date.now() - start > timeout) {
134
164
  throw new Error(`Timed out waiting for workflow run ${this.workflowRun.id} to finish`);
135
165
  }
136
166
  await new Promise((resolve) => {
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../client.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;A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,CAAC;YAED,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,GAAG,OAAO,EAAE,CAAC;gBACjC,MAAM,IAAI,KAAK,CACb,sCAAsC,IAAI,CAAC,WAAW,CAAC,EAAE,YAAY,CACtE,CAAC;YACJ,CAAC;YAED,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;gBAC5B,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;YACjD,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,MAAM;QACV,MAAM,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC;YACnC,aAAa,EAAE,IAAI,CAAC,WAAW,CAAC,EAAE;SACnC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,34 @@
1
+ import { Backend } from "./backend.js";
2
+ import { WorkerOptions } from "./worker.js";
3
+ export interface OpenWorkflowConfig {
4
+ backend: Backend;
5
+ worker?: WorkerConfig;
6
+ /**
7
+ * Directory or directories to scan for workflow files. All `.ts`, `.js`,
8
+ * `.mjs`, and `.cjs` files in these directories (recursively) will be loaded.
9
+ * Workflow files should export workflows created with `defineWorkflow()`.
10
+ * @example "./openworkflow"
11
+ * @example ["./openworkflow", "./src/openworkflow", "./workflows"]
12
+ */
13
+ dirs?: string | string[];
14
+ }
15
+ export type WorkerConfig = Pick<WorkerOptions, "concurrency">;
16
+ /**
17
+ * Create a typed OpenWorkflow configuration.
18
+ * @param config - the config
19
+ * @returns the config
20
+ */
21
+ export declare function defineConfig(config: OpenWorkflowConfig): OpenWorkflowConfig;
22
+ interface LoadedConfig {
23
+ config: OpenWorkflowConfig;
24
+ configFile: string | undefined;
25
+ }
26
+ /**
27
+ * Load the OpenWorkflow config at openworkflow.config.{js,mjs,cjs}.
28
+ * @param rootDir - Optional root directory to search from (defaults to
29
+ * process.cwd())
30
+ * @returns The loaded configuration and metadata
31
+ */
32
+ export declare function loadConfig(rootDir?: string): Promise<LoadedConfig>;
33
+ export {};
34
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAK5C,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC1B;AAED,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;AAE9D;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,kBAAkB,CAE3E;AAED,UAAU,YAAY;IACpB,MAAM,EAAE,kBAAkB,CAAC;IAC3B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC;AAKD;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAqCxE"}
package/dist/config.js ADDED
@@ -0,0 +1,49 @@
1
+ import { existsSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+ /**
5
+ * Create a typed OpenWorkflow configuration.
6
+ * @param config - the config
7
+ * @returns the config
8
+ */
9
+ export function defineConfig(config) {
10
+ return config;
11
+ }
12
+ const CONFIG_NAME = "openworkflow.config";
13
+ const CONFIG_EXTENSIONS = ["js", "mjs", "cjs"];
14
+ /**
15
+ * Load the OpenWorkflow config at openworkflow.config.{js,mjs,cjs}.
16
+ * @param rootDir - Optional root directory to search from (defaults to
17
+ * process.cwd())
18
+ * @returns The loaded configuration and metadata
19
+ */
20
+ export async function loadConfig(rootDir) {
21
+ const cwd = rootDir ?? process.cwd();
22
+ for (const ext of CONFIG_EXTENSIONS) {
23
+ const fileName = `${CONFIG_NAME}.${ext}`;
24
+ const filePath = path.join(cwd, fileName);
25
+ if (existsSync(filePath)) {
26
+ try {
27
+ const fileUrl = pathToFileURL(filePath).href;
28
+ const mod = (await import(fileUrl));
29
+ const config = mod.default ??
30
+ mod;
31
+ return {
32
+ config,
33
+ configFile: filePath,
34
+ };
35
+ }
36
+ catch (error) {
37
+ throw new Error(`Failed to load config file ${filePath}: ${String(error)}`);
38
+ }
39
+ }
40
+ }
41
+ return {
42
+ // not great, but meant to match the c12 api since that is what was used in
43
+ // the initial implementation of loadConfig
44
+ // this can be easily refactored later
45
+ config: {},
46
+ configFile: undefined, // no config found
47
+ };
48
+ }
49
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAiBzC;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,MAA0B;IACrD,OAAO,MAAM,CAAC;AAChB,CAAC;AAOD,MAAM,WAAW,GAAG,qBAAqB,CAAC;AAC1C,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAU,CAAC;AAExD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAAgB;IAC/C,MAAM,GAAG,GAAG,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAErC,KAAK,MAAM,GAAG,IAAI,iBAAiB,EAAE,CAAC;QACpC,MAAM,QAAQ,GAAG,GAAG,WAAW,IAAI,GAAG,EAAE,CAAC;QACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QAE1C,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YACzB,IAAI,CAAC;gBACH,MAAM,OAAO,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC;gBAE7C,MAAM,GAAG,GAAG,CAAC,MAAM,MAAM,CAAC,OAAO,CAAC,CAEZ,CAAC;gBACvB,MAAM,MAAM,GACT,GAAwC,CAAC,OAAO;oBAChD,GAA0B,CAAC;gBAE9B,OAAO;oBACL,MAAM;oBACN,UAAU,EAAE,QAAQ;iBACrB,CAAC;YACJ,CAAC;YAAC,OAAO,KAAc,EAAE,CAAC;gBACxB,MAAM,IAAI,KAAK,CACb,8BAA8B,QAAQ,KAAK,MAAM,CAAC,KAAK,CAAC,EAAE,CAC3D,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO;QACL,2EAA2E;QAC3E,2CAA2C;QAC3C,sCAAsC;QACtC,MAAM,EAAE,EAAmC;QAC3C,UAAU,EAAE,SAAS,EAAE,kBAAkB;KAC1C,CAAC;AACJ,CAAC"}
@@ -1,3 +1,4 @@
1
+ import type { Result } from "./result.js";
1
2
  type Years = "years" | "year" | "yrs" | "yr" | "y";
2
3
  type Months = "months" | "month" | "mo";
3
4
  type Weeks = "weeks" | "week" | "w";
@@ -10,10 +11,12 @@ type Unit = Years | Months | Weeks | Days | Hours | Minutes | Seconds | Millisec
10
11
  type UnitAnyCase = Capitalize<Unit> | Uppercase<Unit> | Lowercase<Unit>;
11
12
  export type DurationString = `${number}` | `${number}${UnitAnyCase}` | `${number} ${UnitAnyCase}`;
12
13
  /**
13
- * Parse a duration string into milliseconds. Exmaples:
14
+ * Parse a duration string into milliseconds. Examples:
14
15
  * - short units: "1ms", "5s", "30m", "2h", "7d", "3w", "1y"
15
16
  * - long units: "1 millisecond", "5 seconds", "30 minutes", "2 hours", "7 days", "3 weeks", "1 year"
17
+ * @param str - Duration string
18
+ * @returns Milliseconds
16
19
  */
17
- export declare function parseDuration(str: DurationString): number;
20
+ export declare function parseDuration(str: DurationString): Result<number>;
18
21
  export {};
19
22
  //# sourceMappingURL=duration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../../core/duration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAG1C,KAAK,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,GAAG,IAAI,GAAG,GAAG,CAAC;AACnD,KAAK,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,IAAI,CAAC;AACxC,KAAK,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,GAAG,CAAC;AACpC,KAAK,IAAI,GAAG,MAAM,GAAG,KAAK,GAAG,GAAG,CAAC;AACjC,KAAK,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,GAAG,IAAI,GAAG,GAAG,CAAC;AACnD,KAAK,OAAO,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,GAAG,CAAC;AAC3D,KAAK,OAAO,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,GAAG,CAAC;AAC3D,KAAK,YAAY,GAAG,cAAc,GAAG,aAAa,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,CAAC;AAC7E,KAAK,IAAI,GACL,KAAK,GACL,MAAM,GACN,KAAK,GACL,IAAI,GACJ,KAAK,GACL,OAAO,GACP,OAAO,GACP,YAAY,CAAC;AACjB,KAAK,WAAW,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;AACxE,MAAM,MAAM,cAAc,GACtB,GAAG,MAAM,EAAE,GACX,GAAG,MAAM,GAAG,WAAW,EAAE,GACzB,GAAG,MAAM,IAAI,WAAW,EAAE,CAAC;AAE/B;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,CAiEjE"}
@@ -1,18 +1,21 @@
1
+ import { ok, err } from "./result.js";
1
2
  /**
2
- * Parse a duration string into milliseconds. Exmaples:
3
+ * Parse a duration string into milliseconds. Examples:
3
4
  * - short units: "1ms", "5s", "30m", "2h", "7d", "3w", "1y"
4
5
  * - long units: "1 millisecond", "5 seconds", "30 minutes", "2 hours", "7 days", "3 weeks", "1 year"
6
+ * @param str - Duration string
7
+ * @returns Milliseconds
5
8
  */
6
9
  export function parseDuration(str) {
7
10
  if (typeof str !== "string") {
8
- throw new TypeError("Invalid duration format: expected a string but received " + typeof str);
11
+ return err(new TypeError("Invalid duration format: expected a string but received " + typeof str));
9
12
  }
10
13
  if (str.length === 0) {
11
- throw new Error('Invalid duration format: ""');
14
+ return err(new Error('Invalid duration format: ""'));
12
15
  }
13
16
  const match = /^(-?\.?\d+(?:\.\d+)?)\s*([a-z]+)?$/i.exec(str);
14
17
  if (!match?.[1]) {
15
- throw new Error(`Invalid duration format: "${str}"`);
18
+ return err(new Error(`Invalid duration format: "${str}"`));
16
19
  }
17
20
  const numValue = Number.parseFloat(match[1]);
18
21
  const unit = match[2]?.toLowerCase() ?? "ms"; // default to ms if not provided
@@ -54,8 +57,8 @@ export function parseDuration(str) {
54
57
  };
55
58
  const multiplier = multipliers[unit];
56
59
  if (multiplier === undefined) {
57
- throw new Error(`Invalid duration format: "${str}"`);
60
+ return err(new Error(`Invalid duration format: "${str}"`));
58
61
  }
59
- return numValue * multiplier;
62
+ return ok(numValue * multiplier);
60
63
  }
61
64
  //# sourceMappingURL=duration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"duration.js","sourceRoot":"","sources":["../../core/duration.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAyBtC;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,GAAmB;IAC/C,IAAI,OAAO,GAAG,KAAK,Q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I;QAClB,GAAG,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI;QACnB,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI;QACjB,GAAG,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;QACxB,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;QACzB,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;QACtB,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;QAC7B,KAAK,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;QAC9B,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;QAC1B,KAAK,EAAE,aAAa;QACpB,MAAM,EAAE,aAAa;QACrB,EAAE,EAAE,aAAa;QACjB,IAAI,EAAE,cAAc;QACpB,KAAK,EAAE,cAAc;QACrB,EAAE,EAAE,cAAc;QAClB,GAAG,EAAE,cAAc;QACnB,CAAC,EAAE,cAAc;KAClB,CAAC;IAEF,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC7B,OAAO,GAAG,CAAC,IAAI,KAAK,CAAC,6BAA6B,GAAG,GAAG,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED,OAAO,EAAE,CAAC,QAAQ,GAAG,UAAU,CAAC,CAAC;AACnC,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { JsonValue } from "./json.js";
2
+ export interface SerializedError {
3
+ name?: string;
4
+ message: string;
5
+ stack?: string;
6
+ [key: string]: JsonValue;
7
+ }
8
+ /**
9
+ * Serialize an error to a JSON-compatible format.
10
+ * @param error - The error to serialize (can be Error instance or any value)
11
+ * @returns A JSON-serializable error object
12
+ */
13
+ export declare function serializeError(error: unknown): SerializedError;
14
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../core/error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,CAc9D"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Serialize an error to a JSON-compatible format.
3
+ * @param error - The error to serialize (can be Error instance or any value)
4
+ * @returns A JSON-serializable error object
5
+ */
6
+ export function serializeError(error) {
7
+ if (error instanceof Error) {
8
+ const { name, message, stack } = error;
9
+ if (stack) {
10
+ return { name, message, stack };
11
+ }
12
+ return { name, message };
13
+ }
14
+ return {
15
+ message: String(error),
16
+ };
17
+ }
18
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../core/error.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;QAEvC,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QAClC,CAAC;QAED,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC;KACvB,CAAC;AACJ,CAAC"}