@whisklabs/grpc
Version:
gRPC generator and http library for typescript
70 lines • 2.69 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.method = exports.services = void 0;
var typeguards_1 = require("@whisklabs/typeguards");
var field_1 = require("./field");
var utils_1 = require("./utils");
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);
}
}
exports.services = services;
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);
}
}
function method(pack, out, item, serv) {
var sName = (0, utils_1.joinPath)(pack, serv.name, item.name);
var input = (0, field_1.pathField)(item.inputType, pack, out);
var output = (0, field_1.pathField)(item.outputType, pack, out);
out.fields.push([input, sName], [output, sName]);
if ((0, typeguards_1.isText)(item.comment)) {
out.dts.push((0, utils_1.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('};');
}
exports.method = method;
// 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