Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
timostamm committed Dec 7, 2023
1 parent a0d4a3e commit a71585c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 27 deletions.
14 changes: 5 additions & 9 deletions packages/protoc-gen-connect-es/src/declaration.ts
Expand Up @@ -15,11 +15,7 @@
import type { DescService } from "@bufbuild/protobuf";
import { MethodIdempotency, MethodKind } from "@bufbuild/protobuf";
import type { GeneratedFile, Schema } from "@bufbuild/protoplugin/ecmascript";
import {
literalString,
makeJsDoc,
localName,
} from "@bufbuild/protoplugin/ecmascript";
import { localName } from "@bufbuild/protoplugin/ecmascript";

export function generateDts(schema: Schema) {
for (const protoFile of schema.files) {
Expand All @@ -34,14 +30,14 @@ export function generateDts(schema: Schema) {
// prettier-ignore
function generateService(schema: Schema, f: GeneratedFile, service: DescService) {
const { MethodKind: rtMethodKind, MethodIdempotency: rtMethodIdempotency } = schema.runtime;
f.print(makeJsDoc(service));
f.print(f.jsDoc(service));
f.print(f.exportDecl("declare const", localName(service)), ": {");
f.print(` readonly typeName: `, literalString(service.typeName), `,`);
f.print(` readonly typeName: `, f.string(service.typeName), `,`);
f.print(" readonly methods: {");
for (const method of service.methods) {
f.print(makeJsDoc(method, " "));
f.print(f.jsDoc(method, " "));
f.print(" readonly ", localName(method), ": {");
f.print(` readonly name: `, literalString(method.name), `,`);
f.print(` readonly name: `, f.string(method.name), `,`);
f.print(" readonly I: typeof ", method.input, ",");
f.print(" readonly O: typeof ", method.output, ",");
f.print(" readonly kind: ", rtMethodKind, ".", MethodKind[method.methodKind], ",");
Expand Down
14 changes: 5 additions & 9 deletions packages/protoc-gen-connect-es/src/javascript.ts
Expand Up @@ -15,11 +15,7 @@
import type { DescService } from "@bufbuild/protobuf";
import { MethodIdempotency, MethodKind } from "@bufbuild/protobuf";
import type { GeneratedFile, Schema } from "@bufbuild/protoplugin/ecmascript";
import {
literalString,
makeJsDoc,
localName,
} from "@bufbuild/protoplugin/ecmascript";
import { localName } from "@bufbuild/protoplugin/ecmascript";

export function generateJs(schema: Schema) {
for (const protoFile of schema.files) {
Expand All @@ -34,14 +30,14 @@ export function generateJs(schema: Schema) {
// prettier-ignore
function generateService(schema: Schema, f: GeneratedFile, service: DescService) {
const { MethodKind: rtMethodKind, MethodIdempotency: rtMethodIdempotency } = schema.runtime;
f.print(makeJsDoc(service));
f.print(f.jsDoc(service));
f.print(f.exportDecl("const", localName(service)), " = {");
f.print(` typeName: `, literalString(service.typeName), `,`);
f.print(` typeName: `, f.string(service.typeName), `,`);
f.print(" methods: {");
for (const method of service.methods) {
f.print(makeJsDoc(method, " "));
f.print(f.jsDoc(method, " "));
f.print(" ", localName(method), ": {");
f.print(` name: `, literalString(method.name), `,`);
f.print(` name: `, f.string(method.name), `,`);
f.print(" I: ", method.input, ",");
f.print(" O: ", method.output, ",");
f.print(" kind: ", rtMethodKind, ".", MethodKind[method.methodKind], ",");
Expand Down
14 changes: 5 additions & 9 deletions packages/protoc-gen-connect-es/src/typescript.ts
Expand Up @@ -15,11 +15,7 @@
import type { DescService } from "@bufbuild/protobuf";
import { MethodIdempotency, MethodKind } from "@bufbuild/protobuf";
import type { GeneratedFile, Schema } from "@bufbuild/protoplugin/ecmascript";
import {
literalString,
makeJsDoc,
localName,
} from "@bufbuild/protoplugin/ecmascript";
import { localName } from "@bufbuild/protoplugin/ecmascript";

export function generateTs(schema: Schema) {
for (const protoFile of schema.files) {
Expand All @@ -39,14 +35,14 @@ function generateService(
) {
const { MethodKind: rtMethodKind, MethodIdempotency: rtMethodIdempotency } =
schema.runtime;
f.print(makeJsDoc(service));
f.print(f.jsDoc(service));
f.print(f.exportDecl("const", localName(service)), " = {");
f.print(` typeName: `, literalString(service.typeName), `,`);
f.print(` typeName: `, f.string(service.typeName), `,`);
f.print(" methods: {");
for (const method of service.methods) {
f.print(makeJsDoc(method, " "));
f.print(f.jsDoc(method, " "));
f.print(" ", localName(method), ": {");
f.print(` name: `, literalString(method.name), `,`);
f.print(` name: `, f.string(method.name), `,`);
f.print(" I: ", method.input, ",");
f.print(" O: ", method.output, ",");
f.print(
Expand Down

0 comments on commit a71585c

Please sign in to comment.