UNPKG

@whisklabs/grpc

Version:

gRPC generator and http library for typescript

65 lines 2.47 kB
import { isText } from '@whisklabs/typeguards'; import { pathField } from './field'; import { joinPath, toComment } from './utils'; export function services(pack, out, items) { if (items === void 0) { items = []; } for (var _i = 0, items_1 = items; _i < items_1.length; _i++) { var msg = items_1[_i]; service(pack, out, msg); } } function service(pack, out, item) { for (var _i = 0, _a = item.methods; _i < _a.length; _i++) { var msg = _a[_i]; method(pack, out, msg, item); } } export function method(pack, out, item, serv) { var sName = joinPath(pack, serv.name, item.name); var input = pathField(item.inputType, pack, out); var output = pathField(item.outputType, pack, out); out.fields.push([input, sName], [output, sName]); if (isText(item.comment)) { out.dts.push(toComment(item.comment)); } out.dts.push("export type ".concat(sName, " = Service<Field<").concat(input, ">, Field<").concat(output, ">>;")); out.dts.push("export const ".concat(sName, ": ").concat(sName, ";")); out.js.push("export const ".concat(sName, " = {")); out.js.push(" name: \"".concat(pack, ".").concat(serv.name, "/").concat(item.name, "\",")); out.js.push(" encode: ".concat(input, ",")); out.js.push(" decode: ".concat(output, ",")); // const rest = getREST(item.options['google.api.http']); // if (rest) { // out.push(` rest: [`); // for (const [name, url, body] of rest) { // out.push(` { method: "${name}", url: "${url}"${isString(body) ? `, body: "${body}"` : ''} },`); // } // out.push(` ],`); // } out.js.push('};'); } // For REST // const METHODS: Record<string, boolean> = { // get: true, // put: true, // post: true, // delete: true, // patch: true, // }; // function getREST(http: unknown, rest: [string, string, unknown][] = []) { // if (isObject(http)) { // for (const i in http) { // if (METHODS[i]) { // const u = http[i]; // rest.push([i, isString(u) ? u : '', http.body]); // } else if (i === 'custom' && isObject(http.custom)) { // const name = isString(http.custom.kind) ? http.custom.kind : ''; // const url = isString(http.custom.path) ? http.custom.path : ''; // rest.push([name, url, http.body]); // } // } // getREST(http.additional_bindings, rest); // return rest; // } // } //# sourceMappingURL=service.js.map