-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathschema-gate.js
More file actions
25 lines (22 loc) · 790 Bytes
/
Copy pathschema-gate.js
File metadata and controls
25 lines (22 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import Ajv2020 from 'ajv/dist/2020.js';
import addFormats from 'ajv-formats';
import { readFileSync } from 'node:fs';
import { join, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const schemaPath = join(__dirname, '..', 'references', 'input-schema.json');
const schema = JSON.parse(readFileSync(schemaPath, 'utf8'));
const ajv = new Ajv2020({ allErrors: true, strict: false });
addFormats(ajv);
const validate = ajv.compile(schema);
export function validateLogicCoreSchema(input) {
const valid = validate(input);
return {
valid,
errors: valid ? [] : (validate.errors || []).map(e => ({
path: e.instancePath || '(root)',
message: e.message,
params: e.params,
})),
};
}