UNPKG

asl-path-validator

Version:

Validates the path expressions for the Amazon States Language

83 lines 2.84 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.validatePath = void 0; const aslPaths_1 = require("./generated/aslPaths"); const types_1 = require("./types"); const ast_1 = require("./ast"); const validatePath = (path, context) => { let ast = null; try { ast = (0, aslPaths_1.parse)(path); } catch (e) { return { isValid: false, code: types_1.ErrorCodes.parse_error, message: JSON.stringify(e), }; } if (!ast) { return { isValid: false, code: types_1.ErrorCodes.parse_error, message: "no ast returned", }; } switch (context) { case types_1.AslPathContext.PAYLOAD_TEMPLATE: break; case types_1.AslPathContext.PATH: if ((0, ast_1.hasFunctions)(ast)) { return { isValid: false, code: types_1.ErrorCodes.exp_has_functions, }; } break; case types_1.AslPathContext.REFERENCE_PATH: case types_1.AslPathContext.RESULT_PATH: if ((0, ast_1.hasFunctions)(ast)) { return { isValid: false, code: types_1.ErrorCodes.exp_has_functions, }; } if (!(0, ast_1.referencePathChecks)(ast)) { return { isValid: false, code: types_1.ErrorCodes.exp_has_non_reference_path_ops, }; } if (context === types_1.AslPathContext.RESULT_PATH) { if ((0, ast_1.hasVariable)(ast)) { return { isValid: false, code: types_1.ErrorCodes.exp_has_variable, }; } } break; default: { const invalid = context; throw Error(invalid); } } return { isValid: true }; }; exports.validatePath = validatePath; __exportStar(require("./ajv"), exports); //# sourceMappingURL=index.js.map