@forzalabs/remora
Version:
A powerful CLI tool for seamless data translation.
34 lines (33 loc) • 1.59 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Affirm_1 = __importDefault(require("../../core/Affirm"));
const SchemaValidator_1 = __importDefault(require("./SchemaValidator"));
const ConsumerEngine_1 = __importDefault(require("../consumer/ConsumerEngine"));
class SchemaEngineClass {
constructor() {
/**
* If the consumer has a ".schema" then checks that the output shape of the consumer complies with what the JSON schema says
*/
this.enforceConsumerOutputSchema = (consumer) => {
var _a;
(0, Affirm_1.default)(consumer, `Invalid consumer`);
if (!consumer.schema)
return true;
const validator = SchemaValidator_1.default.getSchema(consumer.schema);
const schema = validator.schema;
// TODO: right now I just check that all the required properites are there...
// in the future this needs to be more fleshed (types, ...)
const properties = ConsumerEngine_1.default.compile(consumer);
const matches = (_a = schema.required) === null || _a === void 0 ? void 0 : _a.map(x => ({
exists: properties.find(k => k.consumerAlias === x) ? true : false,
property: x
}));
return matches.every(x => x.exists);
};
}
}
const SchemaEngine = new SchemaEngineClass();
exports.default = SchemaEngine;