{"size": 1067, "ext": "js", "max_stars_repo_path": "demo/src/services/window-messages/message-channel/validate-action/validate-action.js", "max_stars_repo_name": "AndrewRedican/embeddable-editor", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "demo/src/services/window-messages/message-channel/validate-action/validate-action.js", "max_issues_repo_name": "AndrewRedican/embeddable-editor", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "demo/src/services/window-messages/message-channel/validate-action/validate-action.js", "max_forks_repo_name": "AndrewRedican/embeddable-editor", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 42.68, "max_line_length": 157, "alphanum_fraction": 0.6757263355}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateAction = void 0;
var jsonschema_1 = require("jsonschema");
var simpleActionDefaultSchema = {
    type: 'object',
    properties: { type: { type: 'string' } },
    required: ['type'],
    additionalProperties: false
};
var validateAction = function (action, actionList) {
    var actionDescription = actionList.find(function (desc) { return desc.type === action.type; });
    if (actionDescription === undefined)
        throw Error('Action is not listed exist in contract.');
    var actionSchema = actionDescription.data || simpleActionDefaultSchema;
    try {
        (0, jsonschema_1.validate)(action, actionSchema, { throwError: true, nestedErrors: true });
    }
    catch (exception) {
        var error = exception;
        throw Error("Invalid Action { type = ".concat(action.type, " }: ").concat(error.toString().replace('instance.', '').replace('instance', 'It'), "."));
    }
};
exports.validateAction = validateAction;
//# sourceMappingURL=validate-action.js.map