UNPKG

api-core

Version:

Model-based dynamic multi-level APIs for any provider, plus multiple consumption channels

43 lines 1.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ApiQuery = void 0; const ApiEdgeQueryContext_1 = require("../edge/ApiEdgeQueryContext"); const ApiEdgeQueryResponse_1 = require("../edge/ApiEdgeQueryResponse"); const uuid = require('uuid/v4'); class ApiQuery { constructor() { this.steps = []; this.unshift = (step) => { this.steps.unshift(step); return this; }; this.execute = (identity = null) => { return new Promise((resolve, reject) => { let next = (scope) => { let step = this.steps[scope.step]; if (step) { scope.step++; if (scope.step < this.steps.length) { step.execute(scope).then(next).catch(reject); } else { step.execute(scope).then(scope => resolve(scope.response || new ApiEdgeQueryResponse_1.ApiEdgeQueryResponse(null))).catch(reject); } } }; next({ context: new ApiEdgeQueryContext_1.ApiEdgeQueryContext(), body: null, request: this.request, response: null, query: this, step: 0, identity }); }); }; this.id = uuid(); } } exports.ApiQuery = ApiQuery; //# sourceMappingURL=ApiQuery.js.map