Skip to content

Commit

Permalink
Upgrade to protobuf-es v0.2.0 (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
smaye81 committed Oct 25, 2022
1 parent 3888ec3 commit c6a1e3b
Show file tree
Hide file tree
Showing 16 changed files with 295 additions and 167 deletions.
109 changes: 74 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/connect-web-bench/README.md
Expand Up @@ -10,5 +10,5 @@ it like a web server would usually do.

| code generator | bundle size | minified | compressed |
|----------------|-------------------:|-----------------------:|---------------------:|
| connect-web | 87,973 b | 41,027 b | 11,370 b |
| connect-web | 87,973 b | 41,027 b | 11,368 b |
| grpc-web | 394,473 b | 283,740 b | 51,793 b |
4 changes: 2 additions & 2 deletions packages/connect-web-bench/package.json
Expand Up @@ -7,8 +7,8 @@
},
"dependencies": {
"@bufbuild/connect-web": "0.2.1",
"@bufbuild/protobuf": "0.1.1",
"@bufbuild/protoc-gen-es": "0.1.1",
"@bufbuild/protobuf": "0.2.0",
"@bufbuild/protoc-gen-es": "0.2.0",
"esbuild": "^0.15.10",
"google-protobuf": "^3.21.0",
"grpc-web": "^1.4.1"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/connect-web-test/src/gen/grpc/testing/empty_pb.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/connect-web-test/src/gen/server/v1/server_pb.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/connect-web/package.json
Expand Up @@ -23,7 +23,7 @@
"types": "./dist/types/index.d.ts"
},
"peerDependencies": {
"@bufbuild/protobuf": "0.1.1"
"@bufbuild/protobuf": "0.2.0"
},
"files": [
"dist/**/"
Expand Down
4 changes: 2 additions & 2 deletions packages/example/package.json
Expand Up @@ -9,11 +9,11 @@
},
"dependencies": {
"@bufbuild/connect-web": "^0.2.1",
"@bufbuild/protobuf": "^0.1.1"
"@bufbuild/protobuf": "^0.2.0"
},
"devDependencies": {
"@bufbuild/protoc-gen-connect-web": "^0.2.1",
"@bufbuild/protoc-gen-es": "^0.1.1",
"@bufbuild/protoc-gen-es": "^0.2.0",
"esbuild": "^0.15.10",
"typescript": "^4.8.4"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/example/src/eliza_pb.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/protoc-gen-connect-web/package.json
Expand Up @@ -20,11 +20,11 @@
},
"preferUnplugged": true,
"dependencies": {
"@bufbuild/protoplugin": "0.1.1"
"@bufbuild/protoplugin": "0.2.0"
},
"peerDependencies": {
"@bufbuild/connect-web": "0.2.1",
"@bufbuild/protoc-gen-es": "0.1.1"
"@bufbuild/protoc-gen-es": "0.2.0"
},
"peerDependenciesMeta": {
"@bufbuild/connect-web": {
Expand Down
60 changes: 60 additions & 0 deletions packages/protoc-gen-connect-web/src/declaration.ts
@@ -0,0 +1,60 @@
// Copyright 2021-2022 Buf Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

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";

export function generateDts(schema: Schema) {
for (const protoFile of schema.files) {
if (protoFile.services.length == 0) {
continue;
}
const file = schema.generateFile(protoFile.name + "_connectweb.d.ts");
file.preamble(protoFile);
for (const service of protoFile.services) {
generateService(schema, file, service);
}
}
}

// prettier-ignore
function generateService(schema: Schema, f: GeneratedFile, service: DescService) {
const { MethodKind: rtMethodKind, MethodIdempotency: rtMethodIdempotency } = schema.runtime;
f.print(makeJsDoc(service));
f.print("export declare const ", localName(service), ": {");
f.print(` readonly typeName: `, literalString(service.typeName), `,`);
f.print(" readonly methods: {");
for (const method of service.methods) {
f.print(makeJsDoc(method, " "));
f.print(" readonly ", localName(method), ": {");
f.print(` readonly name: `, literalString(method.name), `,`);
f.print(" readonly I: typeof ", method.input, ",");
f.print(" readonly O: typeof ", method.output, ",");
f.print(" readonly kind: ", rtMethodKind, ".", MethodKind[method.methodKind], ",");
if (method.idempotency !== undefined) {
f.print(" readonly idempotency: ", rtMethodIdempotency, ".", MethodIdempotency[method.idempotency], ",");
}
// In case we start supporting options, we have to surface them here
f.print(" },");
}
f.print(" }");
f.print("};");
f.print();
}

0 comments on commit c6a1e3b

Please sign in to comment.