@telstra/messaging
Version:
Telstra SDK Messaging
24 lines (23 loc) • 657 B
JavaScript
import { AssertionError } from '@telstra/core';
import Ajv from 'ajv';
import { MessagingErrorCode } 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({
...MessagingErrorCode.InvalidSchema,
message: errors?.map((e) => e.message).join('\n') || '',
});
}
}
}