feat: copy connector

This commit is contained in:
2023-11-07 12:48:21 +01:00
parent 62d5ea4275
commit 780916eb35
35 changed files with 1121 additions and 119 deletions

View File

@@ -1,6 +1,7 @@
import Ajv, {AnySchema} from 'ajv';
import addFormats from 'ajv-formats';
import schema, {SchemaMap} from '@openstapps/core/schema.json';
import schema from '@openstapps/core/schema.json' assert {type: 'json'};
import type {SchemaMap} from '@openstapps/core/schema.json';
export type RemoveNeverProperties<T> = {
[K in Exclude<
@@ -32,6 +33,7 @@ export class Validator {
this.ajv = new Ajv.default({
schemas: [schema, ...additionalSchemas],
verbose: true,
keywords: ['elasticsearch'],
allowUnionTypes: true,
});
addFormats.default(this.ajv, {
@@ -54,7 +56,8 @@ export class Validator {
*/
public validate<T extends SchemaMap[keyof SchemaMap]>(instance: unknown, schema: NameOf<T>): instance is T;
public validate(instance: unknown, schema: Ajv.Schema): boolean;
public validate(instance: unknown, schema: string): boolean;
public validate(instance: unknown, schema: Ajv.Schema | string): boolean {
return this.ajv.validate(schema, instance);
return this.ajv.validate(typeof schema === 'string' ? `#/definitions/${schema}` : schema, instance);
}
}