@telstra/iot-connectivity-manager
Version:
Telstra IoT Connectivity Manager
24 lines (23 loc) • 653 B
JavaScript
import { AssertionError } from '@telstra/core';
import Ajv from 'ajv';
import { ServiceErrorCode } from '../errors/ErrorCode.js';
const ajv = new Ajv({ allErrors: true, format: false });
export class Validator {
data;
constructor(data) {
this.data = data;
}
schemaInline(ref) {
let valid = ajv.validate(ref, this.data);
let errors = ajv.errors;
if (valid) {
return this;
}
else {
throw new AssertionError({
...ServiceErrorCode.InvalidSchema,
message: errors?.map((e) => e.message).join('\n') || '',
});
}
}
}