UNPKG

prostgles-client

Version:

Reactive client for Postgres

33 lines (32 loc) 1.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getMethods = void 0; const prostgles_types_1 = require("prostgles-types"); const getMethods = ({ onDebug, methods, socket, }) => { let methodSchema = {}; const methodHandlers = {}; const _methods = JSON.parse(JSON.stringify(methods)); _methods.map(({ name, description, input, output }) => { const onRun = async function (input) { await (onDebug === null || onDebug === void 0 ? void 0 : onDebug({ type: "method", command: name, data: { params: input } })); return new Promise((resolve, reject) => { socket.emit(prostgles_types_1.CHANNELS.METHOD, { name, input }, (err, res) => { if (err) reject(err); else resolve(res); }); }); }; methodSchema[name] = { description, input, output, run: onRun, }; methodHandlers[name] = onRun; }); methodSchema = Object.freeze(methodSchema); return { methodSchema, methodHandlers }; }; exports.getMethods = getMethods;