@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.
- package/package.json +1 -2
- package/src/configs.js +2 -2
- package/src/configs.spec.js +4 -4
- package/src/index.d.ts +74 -171
- package/src/index.js +2 -1
- package/src/interface/schema_utils.js +34 -0
- package/src/interface/schema_utils.spec.js +67 -0
- package/src/interface/step.js +14 -8
- package/src/interface/validations/static.js +11 -10
- package/src/interface/validations/static.spec.js +14 -15
- package/src/interface/workflow.js +12 -12
- package/src/interface/zod_integration.spec.js +646 -0
- package/src/internal_activities/index.js +14 -2
- package/src/interface/validations/ajv_provider.js +0 -3
- package/src/interface/validations/runtime.js +0 -69
- package/src/interface/validations/runtime.spec.js +0 -50
|
@@ -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:
|
|
8
|
-
outputSchema:
|
|
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-
|
|
39
|
-
const error = new StaticValidationError( '✖
|
|
40
|
-
expect( () => validateStep( { ...validArgs, inputSchema: 'not-
|
|
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
|
|
44
|
-
const error = new StaticValidationError( '✖
|
|
45
|
-
|
|
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-
|
|
50
|
-
const error = new StaticValidationError( '✖
|
|
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
|
|
55
|
-
const error = new StaticValidationError( '✖
|
|
56
|
-
|
|
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 '
|
|
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( {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|