UNPKG

flora-exception

Version:

An exception system for FQL.

51 lines (50 loc) 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FrontendYield = exports.DeployBackendYield = exports.BackendYieldFunctionName = exports.BackendYield = exports.expressArgs = void 0; const faunadb_1 = require("faunadb"); const Exception_1 = require("./Exception"); const Raise_1 = require("./Raise"); const { ContainsPath, If, Select, Var, Let, Map, } = faunadb_1.query; const expressArgs = (args, evaluatedArgs, loc) => { return args.map((arg, index) => { return If(ContainsPath(index, evaluatedArgs), Select(index, evaluatedArgs), (0, Exception_1.FloraException)({ name: "UndefinedArgException", msg: `The arg at index ${index} was not defined.`, location: loc })); }); }; exports.expressArgs = expressArgs; const BackendYield = (args) => { return Let({ [bargs]: Select("args", args), [result]: If((0, Exception_1.ContainsException)(Var(bargs)), (0, Raise_1.Reraise)((0, Exception_1.GetExceptions)(Var(bargs)), (0, Exception_1.FloraException)({ name: "ReraisedException", msg: "This exception was reraised in a yield expression.", location: Select("name", args) })), Select("expr", args)) }, Var(result)); }; exports.BackendYield = BackendYield; exports.BackendYieldFunctionName = "Backend-Yield-Flora-Exception"; const DeployBackendYield = () => { }; exports.DeployBackendYield = DeployBackendYield; const bargs = "bargs"; const result = "result"; /** * Yields the result of an expression. * @param args * @returns */ const FrontendYield = (args) => { return Let({ [bargs]: Select("args", args), [result]: If((0, Exception_1.ContainsException)(Var(bargs)), (0, Raise_1.Reraise)((0, Exception_1.GetExceptions)(Var(bargs)), (0, Exception_1.FloraException)({ name: "ReraisedException", msg: "This exception was reraised in a yield expression.", location: Select("name", args) })), args.expr(...(0, exports.expressArgs)(args.args, Var(bargs), args.name))) }, Var(result)); }; exports.FrontendYield = FrontendYield;