@output.ai/core 0.0.13 → 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/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/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,69 +0,0 @@
|
|
|
1
|
-
import { FatalError } from '#errors';
|
|
2
|
-
import { ajv } from './ajv_provider.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Error type for when the input/output of a step/workflow doesn't match its input/output schema, respectively
|
|
6
|
-
*/
|
|
7
|
-
export class MismatchSchemaError extends FatalError {}
|
|
8
|
-
/**
|
|
9
|
-
* Error type for when the input of a step/workflow doesn't match its input schema
|
|
10
|
-
* @extends MismatchSchemaError
|
|
11
|
-
*/
|
|
12
|
-
export class InvalidInputError extends MismatchSchemaError {}
|
|
13
|
-
/**
|
|
14
|
-
* Error type for when the output of a step/workflow doesn't match its output schema
|
|
15
|
-
* @extends MismatchSchemaError
|
|
16
|
-
*/
|
|
17
|
-
export class InvalidOutputError extends MismatchSchemaError {}
|
|
18
|
-
|
|
19
|
-
const validate = ( ErrorClass, type, name, schema, payload ) => {
|
|
20
|
-
const validate = ajv.compile( schema );
|
|
21
|
-
const valid = validate( payload );
|
|
22
|
-
|
|
23
|
-
if ( !valid ) {
|
|
24
|
-
throw new ErrorClass( `Invalid input at ${type} "${name}": ${ajv.errorsText( validate.errors )}` );
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const validateInput = validate.bind( null, InvalidInputError );
|
|
29
|
-
const validateOutput = validate.bind( null, InvalidOutputError );
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Validates step input
|
|
33
|
-
*
|
|
34
|
-
* @param {name} name - step's name
|
|
35
|
-
* @param {object} schema - step's input schema
|
|
36
|
-
* @param {any} - the input to validate
|
|
37
|
-
* @throws InvalidInputError
|
|
38
|
-
*/
|
|
39
|
-
export const validateStepInput = validateInput.bind( null, 'step' );
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Validates step output
|
|
43
|
-
*
|
|
44
|
-
* @param {name} name - step's name
|
|
45
|
-
* @param {object} schema - step's output schema
|
|
46
|
-
* @param {any} - the output to validate
|
|
47
|
-
* @throws InvalidOutputError
|
|
48
|
-
*/
|
|
49
|
-
export const validateStepOutput = validateOutput.bind( null, 'step' );
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Validates workflow input
|
|
53
|
-
*
|
|
54
|
-
* @param {name} name - workflow's name
|
|
55
|
-
* @param {object} schema - workflow's input schema
|
|
56
|
-
* @param {any} - the input to validate
|
|
57
|
-
* @throws InvalidInputError
|
|
58
|
-
*/
|
|
59
|
-
export const validateWorkflowInput = validateInput.bind( null, 'workflow' );
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Validates workflow output
|
|
63
|
-
*
|
|
64
|
-
* @param {name} name - workflow's name
|
|
65
|
-
* @param {object} schema - workflow's output schema
|
|
66
|
-
* @param {any} - the output to validate
|
|
67
|
-
* @throws InvalidOutputError
|
|
68
|
-
*/
|
|
69
|
-
export const validateWorkflowOutput = validateOutput.bind( null, 'workflow' );
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { validateStepInput, validateWorkflowInput, InvalidInputError } from './runtime.js';
|
|
3
|
-
|
|
4
|
-
describe( 'Runtime validations spec', () => {
|
|
5
|
-
describe( 'validateStepInput', () => {
|
|
6
|
-
it( 'passes with matching payload', () => {
|
|
7
|
-
const schema = {
|
|
8
|
-
type: 'object',
|
|
9
|
-
properties: { id: { type: 'string' }, count: { type: 'integer', minimum: 0 } },
|
|
10
|
-
required: [ 'id' ],
|
|
11
|
-
additionalProperties: false
|
|
12
|
-
};
|
|
13
|
-
expect( () => validateStepInput( 'myStep', schema, { id: 'x', count: 2 } ) ).not.toThrow();
|
|
14
|
-
} );
|
|
15
|
-
|
|
16
|
-
it( 'rejects invalid payload', () => {
|
|
17
|
-
const schema = {
|
|
18
|
-
type: 'object',
|
|
19
|
-
properties: { id: { type: 'string' }, count: { type: 'integer', minimum: 0 } },
|
|
20
|
-
required: [ 'id' ],
|
|
21
|
-
additionalProperties: false
|
|
22
|
-
};
|
|
23
|
-
const error = new InvalidInputError( 'Invalid input at step "myStep": data must have required property \'id\'' );
|
|
24
|
-
expect( () => validateStepInput( 'myStep', schema, { count: -1 } ) ).toThrow( error );
|
|
25
|
-
} );
|
|
26
|
-
} );
|
|
27
|
-
|
|
28
|
-
describe( 'validateWorkflowInput', () => {
|
|
29
|
-
it( 'passes with matching payload', () => {
|
|
30
|
-
const schema = {
|
|
31
|
-
type: 'object',
|
|
32
|
-
properties: { name: { type: 'string' }, enabled: { type: 'boolean' } },
|
|
33
|
-
required: [ 'name' ],
|
|
34
|
-
additionalProperties: false
|
|
35
|
-
};
|
|
36
|
-
expect( () => validateWorkflowInput( 'myWorkflow', schema, { name: 'wf', enabled: true } ) ).not.toThrow();
|
|
37
|
-
} );
|
|
38
|
-
|
|
39
|
-
it( 'rejects invalid payload', () => {
|
|
40
|
-
const schema = {
|
|
41
|
-
type: 'object',
|
|
42
|
-
properties: { name: { type: 'string' }, enabled: { type: 'boolean' } },
|
|
43
|
-
required: [ 'name' ],
|
|
44
|
-
additionalProperties: false
|
|
45
|
-
};
|
|
46
|
-
const error = new InvalidInputError( 'Invalid input at workflow "myWorkflow": data must have required property \'name\'' );
|
|
47
|
-
expect( () => validateWorkflowInput( 'myWorkflow', schema, { enabled: 'yes' } ) ).toThrow( error );
|
|
48
|
-
} );
|
|
49
|
-
} );
|
|
50
|
-
} );
|