MCPcopy Index your code
hub / github.com/IQEngine/IQEngine / validator

Function validator

client/src/utils/validators.ts:17–43  ·  view source on GitHub ↗
(value: string, schema: any, validator: any, path: string = null)

Source from the content-addressed store, hash-verified

15}
16
17export function validator(value: string, schema: any, validator: any, path: string = null) {
18 const ajv = new Ajv({ strict: false, allErrors: true });
19 addFormats(ajv);
20 try {
21 const jsonValue = JSON.parse(value);
22
23 const validate = ajv.compile(schema);
24 const valid = validate(jsonValue);
25
26 if (valid) {
27 validator.errors = [];
28 } else {
29 validator.errors = validate.errors;
30 if (path) {
31 validator.errors = validator.errors.filter((error) => error?.instancePath?.startsWith(path));
32 }
33 }
34 } catch (e) {
35 if (e instanceof SyntaxError) {
36 validator.errors = [{ message: 'Syntax Error: ' + e.message }];
37 } else {
38 validator.errors = [{ message: 'Error' + e.message }];
39 }
40 }
41
42 return validator;
43}

Callers 14

metadataValidatorFunction · 0.85
handleStringChangeFunction · 0.85
StringQueryFunction · 0.85
handleDateChangeFunction · 0.85
renderDividerButtonClassFunction · 0.85
DateQueryFunction · 0.85
FreqQueryFunction · 0.85
handleFreqChangeFunction · 0.85
renderDividerButtonClassFunction · 0.85
handleSelectionFunction · 0.85
handleSelectionFunction · 0.85
handleRadiusChangeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected