@aikirun/task 0.9.2 → 0.10.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/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Serializable } from '@aikirun/types/serializable';
2
2
  import { TaskName, TaskOptions } from '@aikirun/types/task';
3
- import { Schema } from '@aikirun/types/validator';
4
3
  import { WorkflowRunContext } from '@aikirun/workflow';
4
+ import { StandardSchemaV1 } from '@standard-schema/spec';
5
5
  import { RequireAtLeastOneProp } from '@aikirun/types/utils';
6
6
 
7
7
  type NonEmptyArray<T> = [T, ...T[]];
@@ -25,7 +25,7 @@ type TypeOfValueAtPath<T extends object, Path extends PathFromObject<T>> = Path
25
25
 
26
26
  interface EventDefinition<Data> {
27
27
  _type: Data;
28
- schema?: Schema<Data>;
28
+ schema?: StandardSchemaV1<Data>;
29
29
  }
30
30
  type EventsDefinition = Record<string, EventDefinition<unknown>>;
31
31
 
@@ -78,8 +78,8 @@ interface TaskParams<Input, Output> {
78
78
  handler: (input: Input) => Promise<Output>;
79
79
  opts?: TaskOptions;
80
80
  schema?: RequireAtLeastOneProp<{
81
- input?: Schema<Input>;
82
- output?: Schema<Output>;
81
+ input?: StandardSchemaV1<Input>;
82
+ output?: StandardSchemaV1<Output>;
83
83
  }>;
84
84
  }
85
85
  interface Task<Input, Output> {
package/dist/index.js CHANGED
@@ -182,7 +182,7 @@ var TaskImpl = class _TaskImpl {
182
182
  const handle = run[INTERNAL].handle;
183
183
  handle[INTERNAL].assertExecutionAllowed();
184
184
  const inputRaw = isNonEmptyArray(args) ? args[0] : void 0;
185
- const input = await this.parse(handle, this.params.schema?.input, inputRaw);
185
+ const input = await this.parse(handle, this.params.schema?.input, inputRaw, run.logger);
186
186
  const inputHash = await hashInput(input);
187
187
  const reference = this.params.opts?.reference;
188
188
  const path = getTaskPath(this.name, reference?.id ?? inputHash);
@@ -191,7 +191,7 @@ var TaskImpl = class _TaskImpl {
191
191
  await this.assertUniqueTaskReferenceId(handle, existingTaskInfo, inputHash, reference, run.logger);
192
192
  }
193
193
  if (existingTaskInfo?.state.status === "completed") {
194
- return this.parse(handle, this.params.schema?.output, existingTaskInfo.state.output);
194
+ return this.parse(handle, this.params.schema?.output, existingTaskInfo.state.output, run.logger);
195
195
  }
196
196
  if (existingTaskInfo?.state.status === "failed") {
197
197
  const { state } = existingTaskInfo;
@@ -254,7 +254,7 @@ var TaskImpl = class _TaskImpl {
254
254
  while (true) {
255
255
  try {
256
256
  const outputRaw = await this.params.handler(input);
257
- const output = await this.parse(handle, this.params.schema?.output, outputRaw);
257
+ const output = await this.parse(handle, this.params.schema?.output, outputRaw, logger);
258
258
  return { output, lastAttempt: attempts };
259
259
  } catch (error) {
260
260
  if (error instanceof WorkflowRunFailedError || error instanceof WorkflowRunSuspendedError || error instanceof WorkflowRunConflictError) {
@@ -332,20 +332,25 @@ var TaskImpl = class _TaskImpl {
332
332
  throw new TaskFailedError(taskId, attempts, "Task retry not allowed");
333
333
  }
334
334
  }
335
- async parse(handle, schema, data) {
335
+ async parse(handle, schema, data, logger) {
336
336
  if (!schema) {
337
337
  return data;
338
338
  }
339
- try {
340
- return schema.parse(data);
341
- } catch (error) {
342
- await handle[INTERNAL].transitionState({
343
- status: "failed",
344
- cause: "self",
345
- error: createSerializableError(error)
346
- });
347
- throw new WorkflowRunFailedError(handle.run.id, handle.run.attempts);
339
+ const schemaValidation = schema["~standard"].validate(data);
340
+ const schemaValidationResult = schemaValidation instanceof Promise ? await schemaValidation : schemaValidation;
341
+ if (!schemaValidationResult.issues) {
342
+ return schemaValidationResult.value;
348
343
  }
344
+ logger.error("Invalid task data", { "aiki.issues": schemaValidationResult.issues });
345
+ await handle[INTERNAL].transitionState({
346
+ status: "failed",
347
+ cause: "self",
348
+ error: {
349
+ name: "SchemaValidationError",
350
+ message: JSON.stringify(schemaValidationResult.issues)
351
+ }
352
+ });
353
+ throw new WorkflowRunFailedError(handle.run.id, handle.run.attempts);
349
354
  }
350
355
  };
351
356
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aikirun/task",
3
- "version": "0.9.2",
3
+ "version": "0.10.1",
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,9 @@
18
18
  "build": "tsup"
19
19
  },
20
20
  "dependencies": {
21
- "@aikirun/types": "0.9.2",
22
- "@aikirun/workflow": "0.9.2"
21
+ "@aikirun/types": "0.10.1",
22
+ "@aikirun/workflow": "0.10.1",
23
+ "@standard-schema/spec": "^1.1.0"
23
24
  },
24
25
  "publishConfig": {
25
26
  "access": "public"