@aikirun/task 0.6.0 → 0.7.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/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { SerializableInput } from '@aikirun/types/error';
1
+ import { Serializable } from '@aikirun/types/error';
2
2
  import { RetryStrategy } from '@aikirun/types/retry';
3
3
  import { TaskId } from '@aikirun/types/task';
4
4
  import { WorkflowRunContext } from '@aikirun/workflow';
@@ -74,7 +74,7 @@ type EventsDefinition = Record<string, EventDefinition<unknown>>;
74
74
  * const result = await chargeCard.start(run, { cardId: "123", amount: 9999 });
75
75
  * ```
76
76
  */
77
- declare function task<Input extends SerializableInput = null, Output = void>(params: TaskParams<Input, Output>): Task<Input, Output>;
77
+ declare function task<Input extends Serializable = null, Output = void>(params: TaskParams<Input, Output>): Task<Input, Output>;
78
78
  interface TaskParams<Input, Output> {
79
79
  id: string;
80
80
  handler: (input: Input) => Promise<Output>;
@@ -91,7 +91,7 @@ interface TaskBuilder<Input, Output> {
91
91
  interface Task<Input, Output> {
92
92
  id: TaskId;
93
93
  with(): TaskBuilder<Input, Output>;
94
- start: <WorkflowInput, WorkflowOutput>(run: WorkflowRunContext<WorkflowInput, WorkflowOutput, EventsDefinition>, ...args: Input extends null ? [] : [Input]) => Promise<Output>;
94
+ start: (run: WorkflowRunContext<unknown, unknown, EventsDefinition>, ...args: Input extends null ? [] : [Input]) => Promise<Output>;
95
95
  }
96
96
 
97
97
  export { type Task, type TaskParams, task };
package/dist/index.js CHANGED
@@ -163,10 +163,7 @@ var TaskImpl = class _TaskImpl {
163
163
  async start(run, ...args) {
164
164
  const handle = run[INTERNAL].handle;
165
165
  handle[INTERNAL].assertExecutionAllowed();
166
- const input = isNonEmptyArray(args) ? args[0] : (
167
- // this cast is okay cos if args is empty, Input must be type null
168
- null
169
- );
166
+ const input = isNonEmptyArray(args) ? args[0] : null;
170
167
  const path = await this.getPath(input);
171
168
  const taskState = handle.run.tasksState[path] ?? { status: "none" };
172
169
  if (taskState.status === "completed") {
@@ -252,8 +249,8 @@ var TaskImpl = class _TaskImpl {
252
249
  }
253
250
  async getPath(input) {
254
251
  const inputHash = await sha256(stableStringify(input));
255
- const taskPath = this.params.opts?.idempotencyKey ? `${this.id}/${inputHash}/${this.params.opts.idempotencyKey}` : `${this.id}/${inputHash}`;
256
- return taskPath;
252
+ const path = this.params.opts?.idempotencyKey ? `${this.id}/${inputHash}/${this.params.opts.idempotencyKey}` : `${this.id}/${inputHash}`;
253
+ return path;
257
254
  }
258
255
  };
259
256
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aikirun/task",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Task SDK for Aiki - define reliable tasks with automatic retries, idempotency, and error handling",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -18,8 +18,8 @@
18
18
  "build": "tsup"
19
19
  },
20
20
  "dependencies": {
21
- "@aikirun/types": "0.6.0",
22
- "@aikirun/workflow": "0.6.0"
21
+ "@aikirun/types": "0.7.0",
22
+ "@aikirun/workflow": "0.7.0"
23
23
  },
24
24
  "publishConfig": {
25
25
  "access": "public"