@output.ai/core 0.0.12 → 0.0.14

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.
@@ -1,11 +1,12 @@
1
1
  import { describe, it, expect } from 'vitest';
2
+ import { z } from 'zod';
2
3
  import { validateStep, validateWorkflow, validateCreateWebhook, StaticValidationError } from './static.js';
3
4
 
4
5
  const validArgs = Object.freeze( {
5
6
  name: 'valid_name',
6
7
  description: 'desc',
7
- inputSchema: { type: 'object' },
8
- outputSchema: { type: 'object' },
8
+ inputSchema: z.object( {} ),
9
+ outputSchema: z.object( {} ),
9
10
  fn: () => {}
10
11
  } );
11
12
 
@@ -35,26 +36,24 @@ describe( 'interface/validator', () => {
35
36
  expect( () => validateStep( { ...validArgs, description: 10 } ) ).toThrow( error );
36
37
  } );
37
38
 
38
- it( 'rejects non-object inputSchema', () => {
39
- const error = new StaticValidationError( '✖ Invalid input: expected object, received string\n → at inputSchema' );
40
- expect( () => validateStep( { ...validArgs, inputSchema: 'not-an-object' } ) ).toThrow( error );
39
+ it( 'rejects non-Zod inputSchema', () => {
40
+ const error = new StaticValidationError( '✖ Schema must be a Zod schema\n → at inputSchema' );
41
+ expect( () => validateStep( { ...validArgs, inputSchema: 'not-a-zod-schema' } ) ).toThrow( error );
41
42
  } );
42
43
 
43
- it( 'rejects invalid inputSchema structure', () => {
44
- const error = new StaticValidationError( '✖ data/type must be equal to one of the allowed values, \
45
- data/type must be array, data/type must match a schema in anyOf\n → at inputSchema' );
46
- expect( () => validateStep( { ...validArgs, inputSchema: { type: 1 } } ) ).toThrow( error );
44
+ it( 'rejects JSON Schema inputSchema', () => {
45
+ const error = new StaticValidationError( '✖ Schema must be a Zod schema\n → at inputSchema' );
46
+ expect( () => validateStep( { ...validArgs, inputSchema: { type: 'object' } } ) ).toThrow( error );
47
47
  } );
48
48
 
49
- it( 'rejects non-object outputSchema', () => {
50
- const error = new StaticValidationError( '✖ Invalid input: expected object, received number\n → at outputSchema' );
49
+ it( 'rejects non-Zod outputSchema', () => {
50
+ const error = new StaticValidationError( '✖ Schema must be a Zod schema\n → at outputSchema' );
51
51
  expect( () => validateStep( { ...validArgs, outputSchema: 10 } ) ).toThrow( error );
52
52
  } );
53
53
 
54
- it( 'rejects invalid outputSchema structure', () => {
55
- const error = new StaticValidationError( '✖ data/type must be equal to one of the allowed values, \
56
- data/type must be array, data/type must match a schema in anyOf\n → at outputSchema' );
57
- expect( () => validateStep( { ...validArgs, outputSchema: { type: 1 } } ) ).toThrow( error );
54
+ it( 'rejects JSON Schema outputSchema', () => {
55
+ const error = new StaticValidationError( '✖ Schema must be a Zod schema\n → at outputSchema' );
56
+ expect( () => validateStep( { ...validArgs, outputSchema: { type: 'string' } } ) ).toThrow( error );
58
57
  } );
59
58
 
60
59
  it( 'rejects missing fn', () => {
@@ -2,10 +2,10 @@
2
2
  import { proxyActivities, inWorkflowContext, executeChild, workflowInfo, ApplicationFailure, proxySinks } from '@temporalio/workflow';
3
3
  import { getInvocationDir } from './utils.js';
4
4
  import { setMetadata } from './metadata.js';
5
- import { FatalError, ValidationError } from '../errors.js';
5
+ import { FatalError, ValidationError } from '#errors';
6
6
  import { validateWorkflow } from './validations/static.js';
7
- import { validateWorkflowInput, validateWorkflowOutput } from './validations/runtime.js';
8
7
  import { READ_TRACE_FILE, TraceEvent } from '#consts';
8
+ import { validateWithSchema } from './schema_utils.js';
9
9
 
10
10
  const temporalActivityConfigs = {
11
11
  startToCloseTimeout: '20 minute',
@@ -19,7 +19,13 @@ const temporalActivityConfigs = {
19
19
  };
20
20
 
21
21
  export function workflow( { name, description, inputSchema, outputSchema, fn } ) {
22
- validateWorkflow( { name, description, inputSchema, outputSchema, fn } );
22
+ validateWorkflow( {
23
+ name,
24
+ description,
25
+ inputSchema,
26
+ outputSchema,
27
+ fn
28
+ } );
23
29
  const workflowPath = getInvocationDir();
24
30
 
25
31
  const steps = proxyActivities( temporalActivityConfigs );
@@ -31,16 +37,12 @@ export function workflow( { name, description, inputSchema, outputSchema, fn } )
31
37
  sinks.log.trace( { event: TraceEvent.WORKFLOW_START, input } );
32
38
  }
33
39
 
34
- if ( inputSchema ) {
35
- validateWorkflowInput( name, inputSchema, input );
36
- }
40
+ validateWithSchema( inputSchema, input, `Workflow ${name} input` );
37
41
 
38
42
  // this returns a plain function, for example, in unit tests
39
43
  if ( !inWorkflowContext() ) {
40
44
  const output = await fn( input );
41
- if ( outputSchema ) {
42
- validateWorkflowOutput( name, outputSchema, output );
43
- }
45
+ validateWithSchema( outputSchema, output, `Workflow ${name} output` );
44
46
  return output;
45
47
  }
46
48
 
@@ -64,9 +66,7 @@ export function workflow( { name, description, inputSchema, outputSchema, fn } )
64
66
  }
65
67
  }, input );
66
68
 
67
- if ( outputSchema ) {
68
- validateWorkflowOutput( name, outputSchema, output );
69
- }
69
+ validateWithSchema( outputSchema, output, `Workflow ${name} output` );
70
70
 
71
71
  sinks.log.trace( { event: TraceEvent.WORKFLOW_END, output } );
72
72