protoc-gen-grpc-js
Advanced tools
Comparing version 0.1.4 to 0.2.0
@@ -14,4 +14,3 @@ "use strict"; | ||
function printImports(ctx, file) { | ||
const grpcPkg = ctx.params.includes("grpc_js") ? "@grpc/grpc-js" : "grpc"; | ||
const output = [`const grpc = require(${JSON.stringify(grpcPkg)});`]; | ||
const output = []; | ||
const deps = {}; | ||
@@ -24,2 +23,6 @@ if (file.messages.length) { | ||
} | ||
if (!ctx.params.generatePackageDefinition) { | ||
const grpcPkg = ctx.params.grpcJs ? "@grpc/grpc-js" : "grpc"; | ||
output.push(`const grpc = require(${JSON.stringify(grpcPkg)});`); | ||
} | ||
for (const [key, value] of Object.entries(deps)) { | ||
@@ -67,6 +70,10 @@ const alias = utils_1.getModuleAlias(key); | ||
} | ||
function printService(service) { | ||
const output = [ | ||
`const ${service.name}Service = exports.${service.name}Service = {`, | ||
]; | ||
function printService(ctx, service) { | ||
const output = []; | ||
if (ctx.params.generatePackageDefinition) { | ||
output.push(`const ${service.name}Service = exports[${JSON.stringify(service.fullName)}] = {`); | ||
} | ||
else { | ||
output.push(`const ${service.name}Service = exports.${service.name}Service = {`); | ||
} | ||
for (const method of service.methods) { | ||
@@ -77,7 +84,9 @@ const name = utils_1.lowerCaseFirstLetter(method.name); | ||
output.push("};\n"); | ||
output.push(`exports.${service.name}Client = grpc.makeGenericClientConstructor(${service.name}Service);`); | ||
if (!ctx.params.generatePackageDefinition) { | ||
output.push(`exports.${service.name}Client = grpc.makeGenericClientConstructor(${service.name}Service);`); | ||
} | ||
return output.join("\n"); | ||
} | ||
function printServices(file) { | ||
return file.services.map((svc) => printService(svc)).join("\n\n"); | ||
function printServices(ctx, file) { | ||
return file.services.map((svc) => printService(ctx, svc)).join("\n\n"); | ||
} | ||
@@ -98,3 +107,3 @@ function generateFile(ctx, file) { | ||
${printServices(file)} | ||
${printServices(ctx, file)} | ||
`.trim(); | ||
@@ -101,0 +110,0 @@ } |
import { CodeGeneratorRequest } from "google-protobuf/google/protobuf/compiler/plugin_pb"; | ||
import { DescriptorProto, FileDescriptorProto, MethodDescriptorProto, ServiceDescriptorProto } from "google-protobuf/google/protobuf/descriptor_pb"; | ||
export interface Parameters { | ||
grpcJs: boolean; | ||
generatePackageDefinition: boolean; | ||
} | ||
export declare class Context { | ||
readonly files: readonly InputFile[]; | ||
readonly params: readonly string[]; | ||
readonly params: Readonly<Parameters>; | ||
private readonly messageMap; | ||
@@ -7,0 +11,0 @@ constructor(request: CodeGeneratorRequest); |
@@ -8,8 +8,12 @@ "use strict"; | ||
this.messageMap = new Map(); | ||
const reqParams = (request.getParameter() || "") | ||
.split(",") | ||
.map((x) => x.trim()); | ||
this.files = request | ||
.getProtoFileList() | ||
.map((file) => new InputFile(this, file)); | ||
this.params = (request.getParameter() || "") | ||
.split(",") | ||
.map((x) => x.trim()); | ||
this.params = { | ||
grpcJs: reqParams.includes("grpc_js"), | ||
generatePackageDefinition: reqParams.includes("generate_package_definition"), | ||
}; | ||
for (const file of this.files) { | ||
@@ -16,0 +20,0 @@ for (const msg of file.messages) { |
{ | ||
"name": "protoc-gen-grpc-js", | ||
"version": "0.1.4", | ||
"version": "0.2.0", | ||
"description": "Generate client and service objects for use with Node.js gRPC libraries.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30644
472