UNPKG

api-core

Version:

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

47 lines 2.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ApiEdgeMethod = exports.ApiEdgeMethodOutput = exports.ApiEdgeMethodScope = void 0; const ApiRequest_1 = require("../request/ApiRequest"); const ApiEdgeError_1 = require("../query/ApiEdgeError"); var ApiEdgeMethodScope; (function (ApiEdgeMethodScope) { ApiEdgeMethodScope[ApiEdgeMethodScope["Edge"] = 1] = "Edge"; ApiEdgeMethodScope[ApiEdgeMethodScope["Entry"] = 2] = "Entry"; ApiEdgeMethodScope[ApiEdgeMethodScope["Collection"] = 3] = "Collection"; })(ApiEdgeMethodScope = exports.ApiEdgeMethodScope || (exports.ApiEdgeMethodScope = {})); var ApiEdgeMethodOutput; (function (ApiEdgeMethodOutput) { ApiEdgeMethodOutput[ApiEdgeMethodOutput["Entry"] = 1] = "Entry"; ApiEdgeMethodOutput[ApiEdgeMethodOutput["List"] = 2] = "List"; })(ApiEdgeMethodOutput = exports.ApiEdgeMethodOutput || (exports.ApiEdgeMethodOutput = {})); class ApiEdgeMethod { constructor(nameOrOptions, execute, scope = ApiEdgeMethodScope.Edge, acceptedTypes = ApiRequest_1.ApiRequestType.Any, parametersOrData = [], requiresData = true) { this.acceptedTypes = ApiRequest_1.ApiRequestType.Any; this.scope = ApiEdgeMethodScope.Edge; this.output = ApiEdgeMethodOutput.Entry; if (typeof nameOrOptions === 'object') { this.name = nameOrOptions.name; this.requiresData = typeof nameOrOptions.requiresData === 'boolean' ? nameOrOptions.requiresData : true; this.acceptedTypes = nameOrOptions.acceptedTypes || ApiRequest_1.ApiRequestType.Any; this.scope = nameOrOptions.scope || ApiEdgeMethodScope.Edge; this.output = nameOrOptions.output || ApiEdgeMethodOutput.Entry; this.execute = nameOrOptions.execute; this.parameters = nameOrOptions.parameters || []; } else { let parameters = []; if (typeof parametersOrData === 'boolean') requiresData = parametersOrData; else parameters = parametersOrData; this.name = nameOrOptions; this.scope = scope; this.execute = execute || (() => Promise.reject(new ApiEdgeError_1.ApiEdgeError(400, 'Not Implemented'))); this.acceptedTypes = acceptedTypes; this.requiresData = requiresData; this.parameters = parameters; } } } exports.ApiEdgeMethod = ApiEdgeMethod; //# sourceMappingURL=ApiEdgeMethod.js.map