UNPKG

@bitblit/epsilon

Version:

Tiny adapter to simplify building API gateway Lambda APIS

90 lines 3.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BackgroundValidator = void 0; const common_1 = require("@bitblit/ratchet/common"); /** * Handles all submission of work to the background processing system. */ class BackgroundValidator { constructor(cfg, modelValidator) { this.cfg = cfg; this.modelValidator = modelValidator; } findProcessor(typeName) { const rval = this.cfg.processors.find((s) => s.typeName === typeName); return rval; } validType(type) { return !!this.findProcessor(type); } validateEntry(entry) { const rval = []; if (!entry) { rval.push('Entry is null'); } else if (!common_1.StringRatchet.trimToNull(entry.type)) { rval.push('Entry type is null or empty'); const proc = this.findProcessor(entry.type); if (!proc) { rval.push('Entry type is invalid'); } } return rval; } validateEntryAndThrowException(entry) { const errors = this.validateEntry(entry); if (errors.length > 0) { common_1.Logger.warn('Invalid entry %j : errors : %j', entry, errors); common_1.ErrorRatchet.throwFormattedErr('Invalid entry %j : errors : %j', entry, errors); } } static validateAndMapProcessors(processorInput, modelValidator) { const rval = new Map(); processorInput.forEach((p, idx) => { if (!p) { common_1.ErrorRatchet.throwFormattedErr('Null processor provided at index %d', idx); } if (!common_1.StringRatchet.trimToNull(p.typeName)) { common_1.ErrorRatchet.throwFormattedErr('Processor at index %d defines no name', idx); } if (rval.has(p.typeName)) { common_1.ErrorRatchet.throwFormattedErr('More than one processor defined for type %s', p.typeName); } rval.set(p.typeName, p); }); return rval; } static validateAwsConfig(cfg) { const rval = []; if (!cfg) { rval.push('Null config'); } else { if (!cfg.notificationArn) { rval.push('AWS config missing notificationArn'); } if (!cfg.queueUrl) { rval.push('AWS config missing queueUrl'); } if ((cfg.sendNotificationOnBackgroundError || cfg.sendNotificationOnBackgroundValidationFailure) && !cfg.backgroundProcessFailureSnsArn) { rval.push('At least one send notification flag set to true but no sns arn set'); } } return rval; } static validateConfig(cfg) { const rval = []; if (!cfg) { rval.push('Null config'); } else { if (!cfg.processors || cfg.processors.length === 0) { rval.push('No processes specified'); } } return rval; } } exports.BackgroundValidator = BackgroundValidator; //# sourceMappingURL=background-validator.js.map