Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 22 lines 587 Bytes
Raw
1 import { parseSchema } from './parse-schema';
2 import type { ParseContext } from '../context';
3 import type { JsonSchemaObject, JsonSchema } from '../types';
4
5 export const parseNot = <S>(
6 jsonSchema: JsonSchemaObject & { not: JsonSchema },
7 ctx: ParseContext<S>
8 ): S => {
9 const { backend } = ctx;
10 return backend.refine<unknown>(
11 backend.any(),
12 value =>
13 !backend.run(
14 parseSchema(jsonSchema.not, {
15 ...ctx,
16 path: [...ctx.path, 'not'],
17 }),
18 value
19 ).success,
20 'Invalid input: Should NOT be valid against schema'
21 );
22 };