UNPKG

declarapi

Version:
50 lines 2.76 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.server = void 0; const elastic_js_1 = __importDefault(require("./elastic.js")); const common_js_1 = require("./common.js"); const kv_js_1 = require("./kv.js"); exports.server = (contracts) => { const valueDef = contracts.map(x => { let handle = 'undefined'; if (x.preferredImplementation && x.preferredImplementation.type === 'elasticsearch') { const codeGenInput = x.method === 'GET' ? { method: x.method, search: x.search || 'idOnly' } : { method: x.method }; handle = elastic_js_1.default(x.preferredImplementation, codeGenInput); } else if (x.preferredImplementation && x.preferredImplementation.type === 'key-value') { const codeGenInput = x.method === 'GET' ? { method: x.method, search: x.search || 'idOnly' } : { method: x.method }; handle = kv_js_1.kvCodeGen(x.preferredImplementation, codeGenInput); } return `${common_js_1.name(x)}: { name: "${x.name}", manageFields: ${JSON.stringify(x.manageFields, undefined, 2)}, authentication: ${JSON.stringify(x.authentication, undefined, 2)}, type: "${x.method}", handle: ${handle}, arguments: ${JSON.stringify(x.arguments)} , returns: ${JSON.stringify(x.returns)}}`; }).join(',\n'); const contractTypeList = contracts.map(x => `${common_js_1.name(x)}: ContractType<${common_js_1.name(x)}Argument, ${common_js_1.name(x)}Returns>`).join('\n'); const elastic = contracts.find(x => { var _a; return ((_a = x.preferredImplementation) === null || _a === void 0 ? void 0 : _a.type) === 'elasticsearch'; }); const kv = contracts.find(x => { var _a; return ((_a = x.preferredImplementation) === null || _a === void 0 ? void 0 : _a.type) === 'key-value'; }); const elasticImport = elastic ? 'import * as elastic from "declarapi-runtime/elastic.js"\n' : ''; const kvImport = kv ? 'import * as kv from "declarapi-runtime/kv.js"\n' : ''; const result = `/********************************************** DO NOT EDIT THIS FILE, IT WILL BE OVERRIDDEN ***********************************************/ import { ContractType } from "declarapi-runtime" ${elasticImport}${kvImport} ${common_js_1.typeDef(contracts)} export type ContractListType = {\n${contractTypeList}\n}\n export const contracts: ContractListType = {\n${valueDef}\n}\n`; return result; }; exports.default = exports.server; //# sourceMappingURL=server.js.map