diff --git a/package-lock.json b/package-lock.json index af15e4c02..372d90d3a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1108,35 +1108,6 @@ "fast-deep-equal": "^3.1.3" } }, - "node_modules/@grpc/grpc-js": { - "version": "1.10.9", - "dev": true, - "license": "Apache-2.0", - "dependencies": { - "@grpc/proto-loader": "^0.7.13", - "@js-sdsl/ordered-map": "^4.4.2" - }, - "engines": { - "node": ">=12.10.0" - } - }, - "node_modules/@grpc/proto-loader": { - "version": "0.7.13", - "dev": true, - "license": "Apache-2.0", - "dependencies": { - "lodash.camelcase": "^4.3.0", - "long": "^5.0.0", - "protobufjs": "^7.2.5", - "yargs": "^17.7.2" - }, - "bin": { - "proto-loader-gen-types": "build/bin/proto-loader-gen-types.js" - }, - "engines": { - "node": ">=6" - } - }, "node_modules/@humanwhocodes/config-array": { "version": "0.11.14", "dev": true, @@ -1314,15 +1285,6 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, - "node_modules/@js-sdsl/ordered-map": { - "version": "4.4.2", - "dev": true, - "license": "MIT", - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/js-sdsl" - } - }, "node_modules/@next/env": { "version": "13.5.6", "license": "MIT", @@ -1415,60 +1377,6 @@ "url": "https://github.com/prettier/prettier?sponsor=1" } }, - "node_modules/@protobufjs/aspromise": { - "version": "1.1.2", - "dev": true, - "license": "BSD-3-Clause" - }, - "node_modules/@protobufjs/base64": { - "version": "1.1.2", - "dev": true, - "license": "BSD-3-Clause" - }, - "node_modules/@protobufjs/codegen": { - "version": "2.0.4", - "dev": true, - "license": "BSD-3-Clause" - }, - "node_modules/@protobufjs/eventemitter": { - "version": "1.1.0", - "dev": true, - "license": "BSD-3-Clause" - }, - "node_modules/@protobufjs/fetch": { - "version": "1.1.0", - "dev": true, - "license": "BSD-3-Clause", - "dependencies": { - "@protobufjs/aspromise": "^1.1.1", - "@protobufjs/inquire": "^1.1.0" - } - }, - "node_modules/@protobufjs/float": { - "version": "1.0.2", - "dev": true, - "license": "BSD-3-Clause" - }, - "node_modules/@protobufjs/inquire": { - "version": "1.1.0", - "dev": true, - "license": "BSD-3-Clause" - }, - "node_modules/@protobufjs/path": { - "version": "1.1.2", - "dev": true, - "license": "BSD-3-Clause" - }, - "node_modules/@protobufjs/pool": { - "version": "1.1.0", - "dev": true, - "license": "BSD-3-Clause" - }, - "node_modules/@protobufjs/utf8": { - "version": "1.1.0", - "dev": true, - "license": "BSD-3-Clause" - }, "node_modules/@puppeteer/browsers": { "version": "1.9.1", "dev": true, @@ -6353,11 +6261,6 @@ "dev": true, "license": "MIT" }, - "node_modules/lodash.camelcase": { - "version": "4.3.0", - "dev": true, - "license": "MIT" - }, "node_modules/lodash.clonedeep": { "version": "4.5.0", "dev": true, @@ -6405,11 +6308,6 @@ "dev": true, "license": "MIT" }, - "node_modules/long": { - "version": "5.2.3", - "dev": true, - "license": "Apache-2.0" - }, "node_modules/loose-envify": { "version": "1.4.0", "license": "MIT", @@ -7420,29 +7318,6 @@ "node": ">=0.4.0" } }, - "node_modules/protobufjs": { - "version": "7.3.0", - "dev": true, - "hasInstallScript": true, - "license": "BSD-3-Clause", - "dependencies": { - "@protobufjs/aspromise": "^1.1.2", - "@protobufjs/base64": "^1.1.2", - "@protobufjs/codegen": "^2.0.4", - "@protobufjs/eventemitter": "^1.1.0", - "@protobufjs/fetch": "^1.1.0", - "@protobufjs/float": "^1.0.2", - "@protobufjs/inquire": "^1.1.0", - "@protobufjs/path": "^1.1.2", - "@protobufjs/pool": "^1.1.0", - "@protobufjs/utf8": "^1.1.0", - "@types/node": ">=13.7.0", - "long": "^5.0.0" - }, - "engines": { - "node": ">=12.0.0" - } - }, "node_modules/proxy-addr": { "version": "2.0.7", "license": "MIT", @@ -9939,7 +9814,6 @@ }, "devDependencies": { "@connectrpc/connect-conformance": "^1.4.0", - "@grpc/grpc-js": "^1.10.8", "@types/jasmine": "^5.0.0", "jasmine": "^5.1.0" }, diff --git a/packages/connect-cloudflare/package.json b/packages/connect-cloudflare/package.json index 42cccc69b..286e8df53 100644 --- a/packages/connect-cloudflare/package.json +++ b/packages/connect-cloudflare/package.json @@ -1,6 +1,7 @@ { "name": "@connectrpc/connect-cloudflare", "private": true, + "type": "module", "scripts": { "conformance": "tsc --noEmit && npm run conformance:server && npm run conformance:client", "conformance:server": "npx wrangler deploy -c ./conformance/wrangler-server.toml && connectconformance --mode server --conf ./conformance/conformance-cloudflare-server.yaml -v ./conformance/server.ts", diff --git a/packages/connect-conformance/bin/connectconformance b/packages/connect-conformance/bin/connectconformance index 12e63d5b7..d6cab7cb4 100755 --- a/packages/connect-conformance/bin/connectconformance +++ b/packages/connect-conformance/bin/connectconformance @@ -1,5 +1,5 @@ #!/usr/bin/env node -const { run } = require("../dist/cjs/conformance.js"); +import { run } from "../dist/esm/conformance.js"; run(); diff --git a/packages/connect-conformance/package.json b/packages/connect-conformance/package.json index 0dc652cf5..cc1445db2 100644 --- a/packages/connect-conformance/package.json +++ b/packages/connect-conformance/package.json @@ -2,6 +2,7 @@ "name": "@connectrpc/connect-conformance", "version": "1.4.0", "private": true, + "type": "module", "main": "./dist/cjs/index.js", "exports": { ".": { @@ -16,8 +17,8 @@ "generate": "buf generate buf.build/connectrpc/conformance:v1.0.2", "clean": "rm -rf ./dist/*", "build": "npm run build:cjs && npm run build:esm", - "build:cjs": "tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs", - "build:esm": "tsc --project tsconfig.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/esm && echo >./dist/esm/package.json '{\"type\":\"module\"}'" + "build:cjs": "tsc --project tsconfig.json --module commonjs --verbatimModuleSyntax false --moduleResolution node10 --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", + "build:esm": "tsc --project tsconfig.json --outDir ./dist/esm --declaration --declarationDir ./dist/esm" }, "dependencies": { "@bufbuild/protobuf": "^1.10.0", diff --git a/packages/connect-express/package.json b/packages/connect-express/package.json index 0ef6c7781..0149b33d4 100644 --- a/packages/connect-express/package.json +++ b/packages/connect-express/package.json @@ -10,8 +10,8 @@ "scripts": { "clean": "rm -rf ./dist/*", "build": "npm run build:cjs && npm run build:esm", - "build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", - "build:esm": "tsc --project tsconfig.build.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/esm", + "build:cjs": "tsc --project tsconfig.build.json --module commonjs --verbatimModuleSyntax false --moduleResolution node10 --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", + "build:esm": "tsc --project tsconfig.build.json --outDir ./dist/esm --declaration --declarationDir ./dist/esm", "attw": "attw --pack", "jasmine": "jasmine --config=jasmine.json", "conformance": "tsc --noEmit && connectconformance --mode server --conf ./conformance/conformance-express.yaml -v ./conformance/server.ts" diff --git a/packages/connect-fastify/conformance/server.ts b/packages/connect-fastify/conformance/server.ts index 8d5fd95d8..516aaec8e 100755 --- a/packages/connect-fastify/conformance/server.ts +++ b/packages/connect-fastify/conformance/server.ts @@ -31,8 +31,8 @@ import { ServerStreamRequest, UnaryRequest, } from "@connectrpc/connect-conformance"; -import { - fastify, +import { fastify } from "fastify"; +import type { FastifyHttpOptions, FastifyHttpsOptions, FastifyHttp2Options, diff --git a/packages/connect-fastify/package.json b/packages/connect-fastify/package.json index 31c0fe9d6..f20aa3d69 100644 --- a/packages/connect-fastify/package.json +++ b/packages/connect-fastify/package.json @@ -10,8 +10,8 @@ "scripts": { "clean": "rm -rf ./dist/*", "build": "npm run build:cjs && npm run build:esm", - "build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", - "build:esm": "tsc --project tsconfig.build.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/esm", + "build:cjs": "tsc --project tsconfig.build.json --module commonjs --verbatimModuleSyntax false --moduleResolution node10 --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", + "build:esm": "tsc --project tsconfig.build.json --outDir ./dist/esm --declaration --declarationDir ./dist/esm", "attw": "attw --pack", "conformance": "tsc --noEmit && connectconformance --mode server --conf ./conformance/conformance-fastify.yaml -v ./conformance/server.ts" }, diff --git a/packages/connect-fastify/src/fastify-connect-plugin.ts b/packages/connect-fastify/src/fastify-connect-plugin.ts index 4f4bcc396..c75b2763d 100644 --- a/packages/connect-fastify/src/fastify-connect-plugin.ts +++ b/packages/connect-fastify/src/fastify-connect-plugin.ts @@ -29,8 +29,7 @@ import { universalRequestFromNodeRequest, universalResponseToNodeResponse, } from "@connectrpc/connect-node"; -import type { FastifyInstance } from "fastify/types/instance"; -import type { FastifyRequest } from "fastify/types/request"; +import type { FastifyInstance, FastifyRequest } from "fastify"; interface FastifyConnectPluginOptions extends ConnectRouterOptions { /** diff --git a/packages/connect-migrate/package.json b/packages/connect-migrate/package.json index 5abef52d3..78aec0528 100644 --- a/packages/connect-migrate/package.json +++ b/packages/connect-migrate/package.json @@ -14,7 +14,7 @@ }, "scripts": { "clean": "rm -rf ./dist/cjs/*", - "build": "tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs", + "build": "tsc --project tsconfig.json --module commonjs --verbatimModuleSyntax false --moduleResolution node10 --outDir ./dist/cjs", "test": "jasmine --config=jasmine.json", "build+test": "npm run build && npm run test" }, diff --git a/packages/connect-next/package.json b/packages/connect-next/package.json index a78aaba8e..0a3a21c11 100644 --- a/packages/connect-next/package.json +++ b/packages/connect-next/package.json @@ -10,8 +10,8 @@ "scripts": { "clean": "rm -rf ./dist/*", "build": "npm run build:cjs && npm run build:esm", - "build:cjs": "tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", - "build:esm": "tsc --project tsconfig.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/esm", + "build:cjs": "tsc --project tsconfig.json --module commonjs --verbatimModuleSyntax false --moduleResolution node10 --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", + "build:esm": "tsc --project tsconfig.json --outDir ./dist/esm --declaration --declarationDir ./dist/esm", "attw": "attw --pack" }, "type": "module", diff --git a/packages/connect-node/.npmignore b/packages/connect-node/.npmignore index 534593d81..79c72b325 100644 --- a/packages/connect-node/.npmignore +++ b/packages/connect-node/.npmignore @@ -3,4 +3,3 @@ /dist/*/**/*.spec.js /dist/*/**/*.spec.d.ts /dist/*/testdata/ -/dist/*/extra/ diff --git a/packages/connect-node/package.json b/packages/connect-node/package.json index a54638b38..7a7882a61 100644 --- a/packages/connect-node/package.json +++ b/packages/connect-node/package.json @@ -10,8 +10,8 @@ "scripts": { "clean": "rm -rf ./dist/*", "build": "npm run build:cjs && npm run build:esm", - "build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", - "build:esm": "tsc --project tsconfig.build.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/esm", + "build:cjs": "tsc --project tsconfig.build.json --module commonjs --moduleResolution node10 --verbatimModuleSyntax false --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", + "build:esm": "tsc --project tsconfig.build.json --outDir ./dist/esm --declaration --declarationDir ./dist/esm", "attw": "attw --pack", "jasmine": "jasmine --config=jasmine.json", "conformance": "npm run conformance:server && npm run conformance:client", @@ -39,8 +39,7 @@ "devDependencies": { "@types/jasmine": "^5.0.0", "jasmine": "^5.1.0", - "@connectrpc/connect-conformance": "^1.4.0", - "@grpc/grpc-js": "^1.10.8" + "@connectrpc/connect-conformance": "^1.4.0" }, "files": [ "dist/**" diff --git a/packages/connect-node/src/extra/add-grpc-service.spec.ts b/packages/connect-node/src/extra/add-grpc-service.spec.ts deleted file mode 100644 index c2f1f5b7e..000000000 --- a/packages/connect-node/src/extra/add-grpc-service.spec.ts +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2021-2024 The Connect Authors -// -// 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 { ConformanceService } from "@connectrpc/connect-conformance"; -import * as grpc from "@grpc/grpc-js"; -import { addGrpcService } from "./add-grpc-service.js"; - -/* eslint-disable @typescript-eslint/no-unused-vars */ - -describe("addGrpcService()", () => { - it("should not raise errors when adding the service", (done) => { - const server = new grpc.Server(); - addGrpcService(server, ConformanceService, { - unimplemented(call) { - // - }, - idempotentUnary(call, callback) { - // - }, - bidiStream(call) { - // - }, - clientStream(call, callback) { - // - }, - serverStream(call) { - // - }, - unary(call, callback) { - // - }, - }); - server.bindAsync( - "0.0.0.0:8099", - grpc.ServerCredentials.createInsecure(), - (err: Error | null) => { - if (err) { - fail(err); - } else { - server.start(); - server.forceShutdown(); - done(); - } - }, - ); - }); -}); diff --git a/packages/connect-node/src/extra/add-grpc-service.ts b/packages/connect-node/src/extra/add-grpc-service.ts deleted file mode 100644 index dc9726a1e..000000000 --- a/packages/connect-node/src/extra/add-grpc-service.ts +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2021-2024 The Connect Authors -// -// 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 { - BinaryReadOptions, - BinaryWriteOptions, - MethodInfoBiDiStreaming, - MethodInfoClientStreaming, - MethodInfoServerStreaming, - MethodInfoUnary, - PartialMessage, - ServiceType, -} from "@bufbuild/protobuf"; -import type * as grpc from "@grpc/grpc-js"; -import { createGrpcServiceDefinition } from "./create-grpc-definition.js"; - -// prettier-ignore -/** - * GrpcServiceImplementation is identical to a generated @grpc/grpc-js - * service interface, but derived from generated connect service - * metadata. - */ -export type GrpcServiceImplementation = { - [P in keyof T["methods"]]: - T["methods"][P] extends MethodInfoUnary ? grpc.handleUnaryCall> - : T["methods"][P] extends MethodInfoServerStreaming ? grpc.handleServerStreamingCall> - : T["methods"][P] extends MethodInfoClientStreaming ? grpc.handleClientStreamingCall> - : T["methods"][P] extends MethodInfoBiDiStreaming ? grpc.handleBidiStreamingCall> - : never; -}; - -/** - * addGrpcService adds the provided service implementation to the - * provided @grpc/grpc-js server. - */ -export function addGrpcService( - grpcServer: grpc.Server, - service: T, - implementation: GrpcServiceImplementation, - binaryOptions?: Partial, -): void { - const definition = createGrpcServiceDefinition(service, binaryOptions); - grpcServer.addService(definition, implementation); -} diff --git a/packages/connect-node/src/extra/create-grpc-client.spec.ts b/packages/connect-node/src/extra/create-grpc-client.spec.ts deleted file mode 100644 index b6a87af4e..000000000 --- a/packages/connect-node/src/extra/create-grpc-client.spec.ts +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2021-2024 The Connect Authors -// -// 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 { ConformanceService } from "@connectrpc/connect-conformance"; -import * as grpc from "@grpc/grpc-js"; -import { createGrpcClient } from "./create-grpc-client.js"; - -describe("createGrpcClient()", function () { - it("should create the expected methods", function () { - const grpcClient = createGrpcClient(ConformanceService, { - address: "localhost:5002", - channelCredentials: grpc.ChannelCredentials.createInsecure(), - clientOptions: {}, - binaryOptions: {}, - }); - expect(grpcClient).toBeDefined(); - expect(typeof grpcClient.unary).toBe("function"); - expect(typeof grpcClient.idempotentUnary).toBe("function"); - expect(typeof grpcClient.serverStream).toBe("function"); - expect(typeof grpcClient.clientStream).toBe("function"); - expect(typeof grpcClient.bidiStream).toBe("function"); - }); -}); diff --git a/packages/connect-node/src/extra/create-grpc-client.ts b/packages/connect-node/src/extra/create-grpc-client.ts deleted file mode 100644 index 21b0c0c6a..000000000 --- a/packages/connect-node/src/extra/create-grpc-client.ts +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2021-2024 The Connect Authors -// -// 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 { - BinaryReadOptions, - BinaryWriteOptions, - Message, - MethodInfoBiDiStreaming, - MethodInfoClientStreaming, - MethodInfoServerStreaming, - MethodInfoUnary, - PartialMessage, - ServiceType, -} from "@bufbuild/protobuf"; -import * as grpc from "@grpc/grpc-js"; -import { createGrpcServiceDefinition } from "./create-grpc-definition.js"; - -// prettier-ignore -/** - * GrpcClient is identical to a generated @grpc/grpc-js client. - */ -export type GrpcClient = { - [P in keyof T["methods"]]: - T["methods"][P] extends MethodInfoUnary ? C["unary"] - : T["methods"][P] extends MethodInfoServerStreaming ? C["serverStream"] - : T["methods"][P] extends MethodInfoClientStreaming ? C["clientStream"] - : T["methods"][P] extends MethodInfoBiDiStreaming ? C["bidi"] - : never; -}; - -/** - * createGrpcClient() creates a @grpc/grpc-js client from generated connect - * service metadata. It is identical to a generated @grpc/grpc-js - * client. - */ -export function createGrpcClient( - service: T, - options: CreateGrpcClientOptions, -): GrpcClient { - const grpcDefinitions = createGrpcServiceDefinition( - service, - options.binaryOptions, - ); - const grpcClientCtor = grpc.makeGenericClientConstructor( - grpcDefinitions, - service.typeName, - ); - const grpcClient = new grpcClientCtor( - options.address, - options.channelCredentials, - options.clientOptions, - ) as unknown; - return grpcClient as GrpcClient; -} - -export interface CreateGrpcClientOptions { - address: string; - channelCredentials: grpc.ChannelCredentials; - clientOptions?: grpc.ClientOptions; - - /** - * Options for the binary wire format. - */ - binaryOptions?: Partial; -} - -// prettier-ignore -/** - * This interface contains a method signature for each method kind, matching - * the method signature of a @grpc/grpc-js client. - */ -interface C, O extends Message> extends grpc.Client { - unary(argument: PartialMessage, callback: grpc.requestCallback): grpc.ClientUnaryCall; - unary(argument: PartialMessage, metadataOrOptions: grpc.Metadata | grpc.CallOptions | null, callback: grpc.requestCallback): grpc.ClientUnaryCall; - unary(argument: PartialMessage, metadata: grpc.Metadata | null, options: grpc.CallOptions | null, callback: grpc.requestCallback): grpc.ClientUnaryCall; - serverStream(argument: PartialMessage, metadataOrOptions?: grpc.Metadata | grpc.CallOptions | null): grpc.ClientReadableStream; - serverStream(argument: PartialMessage, metadata?: grpc.Metadata | null, options?: grpc.CallOptions | null): grpc.ClientReadableStream; - clientStream(callback: grpc.requestCallback): grpc.ClientWritableStream; - clientStream(metadataOrOptions: grpc.Metadata | grpc.CallOptions | null, callback: grpc.requestCallback): grpc.ClientWritableStream; - clientStream(metadata: grpc.Metadata | null, options: grpc.CallOptions | null, callback: grpc.requestCallback): grpc.ClientWritableStream; - bidi(metadataOrOptions?: grpc.Metadata | grpc.CallOptions | null): grpc.ClientDuplexStream; - bidi(metadata?: grpc.Metadata | null, options?: grpc.CallOptions | null): grpc.ClientDuplexStream; -} diff --git a/packages/connect-node/src/extra/create-grpc-definition.ts b/packages/connect-node/src/extra/create-grpc-definition.ts deleted file mode 100644 index cbd90a834..000000000 --- a/packages/connect-node/src/extra/create-grpc-definition.ts +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2021-2024 The Connect Authors -// -// 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 { MethodKind } from "@bufbuild/protobuf"; -import type { - AnyMessage, - BinaryReadOptions, - BinaryWriteOptions, - PartialMessage, - ServiceType, -} from "@bufbuild/protobuf"; -import type * as grpc from "@grpc/grpc-js"; - -/** - * Create service definition for @grpc/grpc-js from generated connect - * service metadata. - * - * The result is identical to a generated @grpc/grpc-js - * client. - */ -export function createGrpcServiceDefinition( - service: T, - binaryOptions?: Partial, -): Record> { - const def: Record> = {}; - for (const localName of Object.keys(service.methods)) { - def[localName] = createGrpcMethodDefinition( - service, - localName, - binaryOptions, - ); - } - return def; -} - -/** - * Create a method definition for @grpc/grpc-js from generated connect - * service metadata. - */ -function createGrpcMethodDefinition< - T extends ServiceType, - M extends keyof T["methods"], ->( - service: T, - methodLocalName: M, - binaryOptions?: Partial, -): grpc.MethodDefinition { - const info = service.methods[methodLocalName as string]; - return { - path: `/${service.typeName}/${info.name}`, - originalName: info.name, - requestStream: - info.kind === MethodKind.ClientStreaming || - info.kind === MethodKind.BiDiStreaming, - responseStream: - info.kind === MethodKind.ServerStreaming || - info.kind === MethodKind.BiDiStreaming, - requestSerialize(value: AnyMessage | PartialMessage): Buffer { - const message = value instanceof info.I ? value : new info.I(value); - const bytes = message.toBinary(binaryOptions); - return Buffer.from(bytes); - }, - requestDeserialize(bytes: Buffer): AnyMessage { - return info.I.fromBinary(bytes, binaryOptions); - }, - responseSerialize(value: AnyMessage | PartialMessage): Buffer { - const message = value instanceof info.O ? value : new info.O(value); - const bytes = message.toBinary(binaryOptions); - return Buffer.from(bytes); - }, - responseDeserialize(bytes: Buffer): AnyMessage { - return info.O.fromBinary(bytes, binaryOptions); - }, - }; -} diff --git a/packages/connect-web/package.json b/packages/connect-web/package.json index 4468d1d86..541a6857b 100644 --- a/packages/connect-web/package.json +++ b/packages/connect-web/package.json @@ -10,8 +10,8 @@ "scripts": { "clean": "rm -rf ./dist/*", "build": "npm run build:cjs && npm run build:esm", - "build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", - "build:esm": "tsc --project tsconfig.build.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/esm", + "build:cjs": "tsc --project tsconfig.build.json --module commonjs --verbatimModuleSyntax false --moduleResolution node10 --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", + "build:esm": "tsc --project tsconfig.build.json --outDir ./dist/esm --declaration --declarationDir ./dist/esm", "attw": "attw --pack", "conformance:client:chrome": "connectconformance --mode client --conf ./conformance/conformance-web.yaml -v -- ./conformance/client.ts --browser chrome --headless && connectconformance --mode client --conf ./conformance/conformance-web.yaml -v --known-failing @./conformance/known-failing-callback-client.txt -- ./conformance/client.ts --browser chrome --headless --useCallbackClient", "conformance:client:firefox": "connectconformance --mode client --conf ./conformance/conformance-web.yaml -v --known-failing @./conformance/known-failing-promise-client-firefox.txt -- ./conformance/client.ts --browser firefox --headless && connectconformance --mode client --conf ./conformance/conformance-web.yaml -v --known-failing @./conformance/known-failing-callback-client.txt -- ./conformance/client.ts --browser firefox --headless --useCallbackClient", diff --git a/packages/connect/package.json b/packages/connect/package.json index 6cfe7312c..ca0e7fced 100644 --- a/packages/connect/package.json +++ b/packages/connect/package.json @@ -12,8 +12,8 @@ "clean": "rm -rf ./dist/*", "generate": "buf generate src/protocol-grpc/proto", "build": "npm run build:cjs && npm run build:esm && node scripts/update-user-agent.mjs", - "build:cjs": "tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", - "build:esm": "tsc --project tsconfig.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/esm", + "build:cjs": "tsc --project tsconfig.json --module commonjs --verbatimModuleSyntax false --moduleResolution node10 --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", + "build:esm": "tsc --project tsconfig.json --outDir ./dist/esm --declaration --declarationDir ./dist/esm", "jasmine": "jasmine --config=jasmine.json", "attw": "attw --pack" }, diff --git a/packages/connect/src/promise-client.spec.ts b/packages/connect/src/promise-client.spec.ts index dde1ad414..ba89446d7 100644 --- a/packages/connect/src/promise-client.spec.ts +++ b/packages/connect/src/promise-client.spec.ts @@ -21,7 +21,7 @@ import { } from "./promise-client.js"; import { createAsyncIterable } from "./protocol/async-iterable.js"; import { createRouterTransport } from "./router-transport.js"; -import type { HandlerContext } from "./implementation"; +import type { HandlerContext } from "./implementation.js"; import { ConnectError } from "./connect-error.js"; import { Code } from "./code.js"; import { createContextKey, createContextValues } from "./context-values.js"; diff --git a/packages/example/tsconfig.json b/packages/example/tsconfig.json index d129daaf9..feba063fe 100644 --- a/packages/example/tsconfig.json +++ b/packages/example/tsconfig.json @@ -2,9 +2,9 @@ "compilerOptions": { "target": "ESNext", "useDefineForClassFields": true, - "module": "ESNext", + "module": "Node16", "lib": ["ESNext", "DOM"], - "moduleResolution": "Node", + "moduleResolution": "Node16", "strict": true, "sourceMap": true, "resolveJsonModule": true, diff --git a/packages/protoc-gen-connect-es/package.json b/packages/protoc-gen-connect-es/package.json index a891658ec..c71f012a6 100644 --- a/packages/protoc-gen-connect-es/package.json +++ b/packages/protoc-gen-connect-es/package.json @@ -16,7 +16,7 @@ }, "scripts": { "clean": "rm -rf ./dist/cjs/*", - "build": "tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs" + "build": "tsc --project tsconfig.json --module commonjs --verbatimModuleSyntax false --moduleResolution node10 --outDir ./dist/cjs" }, "preferUnplugged": true, "dependencies": { diff --git a/tsconfig.base.json b/tsconfig.base.json index d7e5c6163..34b011d1a 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -24,7 +24,9 @@ "noImplicitOverride": true, // We need node's module resolution, so we do not have to skip lib checks - "moduleResolution": "Node", + "moduleResolution": "Node16", + "module": "Node16", + "verbatimModuleSyntax": true, "skipLibCheck": false } }