diff --git a/package-lock.json b/package-lock.json index 76e1326cd..a84b45f15 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,7 +24,7 @@ "eslint": "^8.33.0", "eslint-plugin-node": "^11.1.0", "prettier": "^2.8.7", - "typescript": "^4.9.5" + "typescript": "^5.0.3" }, "engines": { "node": ">=16", @@ -5288,16 +5288,16 @@ } }, "node_modules/typescript": { - "version": "4.9.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", - "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.3.tgz", + "integrity": "sha512-xv8mOEDnigb/tN9PSMTwSEqAnUvkoXMQlicOb0IUVDBSQCgBSaAAROUZYy2IcUy5qU6XajK5jjjO7TMWqBTKZA==", "dev": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" }, "engines": { - "node": ">=4.2.0" + "node": ">=12.20" } }, "node_modules/ua-parser-js": { @@ -5643,7 +5643,7 @@ "@bufbuild/protoc-gen-es": "^1.2.0", "@types/express": "^4.17.15", "esbuild": "^0.16.12", - "typescript": "^4.9.5" + "typescript": "^5.0.3" }, "engines": { "node": ">=16" diff --git a/package.json b/package.json index 674ed5a55..28a72fbc8 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "npm": ">=8" }, "devDependencies": { - "typescript": "^4.9.5", + "typescript": "^5.0.3", "@typescript-eslint/eslint-plugin": "^5.57.0", "@typescript-eslint/parser": "^5.57.0", "eslint": "^8.33.0", diff --git a/packages/connect-express/package.json b/packages/connect-express/package.json index ae28e0dff..ab3890324 100644 --- a/packages/connect-express/package.json +++ b/packages/connect-express/package.json @@ -12,7 +12,7 @@ "clean": "rm -rf ./dist/cjs/* ./dist/esm/* ./dist/types/*", "build": "npm run build:cjs && npm run build:esm+types", "build:cjs": "tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", - "build:esm+types": "tsc --project tsconfig.json --module ES2015 --outDir ./dist/esm --declaration --declarationDir ./dist/types" + "build:esm+types": "tsc --project tsconfig.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/types" }, "main": "./dist/cjs/index.js", "type": "module", diff --git a/packages/connect-express/src/express-connect-middleware.ts b/packages/connect-express/src/express-connect-middleware.ts index 02d80f9d3..cd81a3316 100644 --- a/packages/connect-express/src/express-connect-middleware.ts +++ b/packages/connect-express/src/express-connect-middleware.ts @@ -14,12 +14,11 @@ import type { JsonValue } from "@bufbuild/protobuf"; import { - ConnectRouter, createConnectRouter, - ConnectRouterOptions, Code, connectErrorFromReason, } from "@bufbuild/connect"; +import type { ConnectRouter, ConnectRouterOptions } from "@bufbuild/connect"; import type { UniversalHandler } from "@bufbuild/connect/protocol"; import { compressionBrotli, compressionGzip } from "@bufbuild/connect-node"; import { diff --git a/packages/connect-fastify/package.json b/packages/connect-fastify/package.json index 8a4967f4b..077ec3245 100644 --- a/packages/connect-fastify/package.json +++ b/packages/connect-fastify/package.json @@ -12,7 +12,7 @@ "clean": "rm -rf ./dist/cjs/* ./dist/esm/* ./dist/types/*", "build": "npm run build:cjs && npm run build:esm+types", "build:cjs": "tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", - "build:esm+types": "tsc --project tsconfig.json --module ES2015 --outDir ./dist/esm --declaration --declarationDir ./dist/types" + "build:esm+types": "tsc --project tsconfig.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/types" }, "main": "./dist/cjs/index.js", "type": "module", diff --git a/packages/connect-fastify/src/fastify-connect-plugin.ts b/packages/connect-fastify/src/fastify-connect-plugin.ts index c1f69079c..49ec002f7 100644 --- a/packages/connect-fastify/src/fastify-connect-plugin.ts +++ b/packages/connect-fastify/src/fastify-connect-plugin.ts @@ -16,10 +16,9 @@ import type { JsonValue } from "@bufbuild/protobuf"; import { Code, connectErrorFromReason, - ConnectRouter, - ConnectRouterOptions, createConnectRouter, } from "@bufbuild/connect"; +import type { ConnectRouter, ConnectRouterOptions } from "@bufbuild/connect"; import * as protoConnect from "@bufbuild/connect/protocol-connect"; import * as protoGrpcWeb from "@bufbuild/connect/protocol-grpc-web"; import * as protoGrpc from "@bufbuild/connect/protocol-grpc"; diff --git a/packages/connect-next/package.json b/packages/connect-next/package.json index 42704ee7a..5eb79b2f9 100644 --- a/packages/connect-next/package.json +++ b/packages/connect-next/package.json @@ -12,7 +12,7 @@ "clean": "rm -rf ./dist/cjs/* ./dist/esm/* ./dist/types/*", "build": "npm run build:cjs && npm run build:esm+types", "build:cjs": "tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", - "build:esm+types": "tsc --project tsconfig.json --module ES2015 --outDir ./dist/esm --declaration --declarationDir ./dist/types" + "build:esm+types": "tsc --project tsconfig.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/types" }, "main": "./dist/cjs/index.js", "type": "module", diff --git a/packages/connect-next/src/connect-nextjs-adapter.ts b/packages/connect-next/src/connect-nextjs-adapter.ts index 9f67d3240..5aaabe859 100644 --- a/packages/connect-next/src/connect-nextjs-adapter.ts +++ b/packages/connect-next/src/connect-nextjs-adapter.ts @@ -12,11 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { - ConnectRouter, - ConnectRouterOptions, - createConnectRouter, -} from "@bufbuild/connect"; +import { createConnectRouter } from "@bufbuild/connect"; +import type { ConnectRouter, ConnectRouterOptions } from "@bufbuild/connect"; import type { UniversalHandler } from "@bufbuild/connect/protocol"; import { compressionBrotli, diff --git a/packages/connect-node-test/package.json b/packages/connect-node-test/package.json index 2516d02e5..061caf3b5 100644 --- a/packages/connect-node-test/package.json +++ b/packages/connect-node-test/package.json @@ -4,7 +4,7 @@ "scripts": { "clean": "rm -rf ./dist/esm/*", "generate": "buf generate", - "build": "tsc --project tsconfig.json --module ES2015 --outDir ./dist/esm", + "build": "tsc --project tsconfig.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm", "jasmine": "jasmine --config=jasmine.json" }, "type": "module", diff --git a/packages/connect-node-test/src/crosstest/timeout_on_sleeping_server.spec.ts b/packages/connect-node-test/src/crosstest/timeout_on_sleeping_server.spec.ts index b7abadc1e..90f7641d0 100644 --- a/packages/connect-node-test/src/crosstest/timeout_on_sleeping_server.spec.ts +++ b/packages/connect-node-test/src/crosstest/timeout_on_sleeping_server.spec.ts @@ -13,13 +13,13 @@ // limitations under the License. import { - CallOptions, Code, ConnectError, createCallbackClient, createPromiseClient, connectErrorFromReason, } from "@bufbuild/connect"; +import type { CallOptions } from "@bufbuild/connect"; import { TestService } from "../gen/grpc/testing/test_connect.js"; import { StreamingOutputCallRequest } from "../gen/grpc/testing/messages_pb.js"; import { createTestServers } from "../helpers/testserver.js"; diff --git a/packages/connect-node-test/src/express-readme.spec.ts b/packages/connect-node-test/src/express-readme.spec.ts index af9c51dd2..674440bd3 100644 --- a/packages/connect-node-test/src/express-readme.spec.ts +++ b/packages/connect-node-test/src/express-readme.spec.ts @@ -14,7 +14,8 @@ import * as http from "http"; import { Message, MethodKind, proto3 } from "@bufbuild/protobuf"; -import { ConnectRouter, createPromiseClient } from "@bufbuild/connect"; +import { createPromiseClient } from "@bufbuild/connect"; +import type { ConnectRouter } from "@bufbuild/connect"; import { expressConnectMiddleware } from "@bufbuild/connect-express"; import { createGrpcWebTransport } from "@bufbuild/connect-node"; import { importExpress } from "./helpers/import-express.js"; diff --git a/packages/connect-node-test/src/extra/create-grpc-definition.ts b/packages/connect-node-test/src/extra/create-grpc-definition.ts index 94452f9f0..0e84720cb 100644 --- a/packages/connect-node-test/src/extra/create-grpc-definition.ts +++ b/packages/connect-node-test/src/extra/create-grpc-definition.ts @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { +import { MethodKind } from "@bufbuild/protobuf"; +import type { AnyMessage, BinaryReadOptions, BinaryWriteOptions, - MethodKind, PartialMessage, ServiceType, } from "@bufbuild/protobuf"; diff --git a/packages/connect-node-test/src/helpers/test-routes.ts b/packages/connect-node-test/src/helpers/test-routes.ts index a259add36..7168fc207 100644 --- a/packages/connect-node-test/src/helpers/test-routes.ts +++ b/packages/connect-node-test/src/helpers/test-routes.ts @@ -15,11 +15,10 @@ import { Code, ConnectError, - ConnectRouter, decodeBinaryHeader, encodeBinaryHeader, - ServiceImpl, } from "@bufbuild/connect"; +import type { ConnectRouter, ServiceImpl } from "@bufbuild/connect"; import { TestService } from "../gen/grpc/testing/test_connect.js"; import type { StreamingOutputCallRequest } from "../gen/grpc/testing/messages_pb.js"; import { interop } from "./interop.js"; diff --git a/packages/connect-node-test/src/helpers/testserver.ts b/packages/connect-node-test/src/helpers/testserver.ts index 7a0532881..0c36177c1 100644 --- a/packages/connect-node-test/src/helpers/testserver.ts +++ b/packages/connect-node-test/src/helpers/testserver.ts @@ -28,8 +28,8 @@ import { } from "@bufbuild/connect-node"; import { fastifyConnectPlugin } from "@bufbuild/connect-fastify"; import { expressConnectMiddleware } from "@bufbuild/connect-express"; -import { - fastify, +import { fastify } from "fastify"; +import type { FastifyBaseLogger, FastifyInstance, FastifyTypeProviderDefault, diff --git a/packages/connect-node-test/src/node-readme.spec.ts b/packages/connect-node-test/src/node-readme.spec.ts index 345f04060..73d57714f 100644 --- a/packages/connect-node-test/src/node-readme.spec.ts +++ b/packages/connect-node-test/src/node-readme.spec.ts @@ -14,7 +14,8 @@ import * as http2 from "http2"; import { Message, MethodKind, proto3 } from "@bufbuild/protobuf"; -import { ConnectRouter, createPromiseClient } from "@bufbuild/connect"; +import { createPromiseClient } from "@bufbuild/connect"; +import type { ConnectRouter } from "@bufbuild/connect"; import { connectNodeAdapter, createGrpcTransport, diff --git a/packages/connect-node/package.json b/packages/connect-node/package.json index 68bb6c8ee..b1aadd541 100644 --- a/packages/connect-node/package.json +++ b/packages/connect-node/package.json @@ -11,7 +11,7 @@ "clean": "rm -rf ./dist/cjs/* ./dist/esm/* ./dist/types/*", "build": "npm run build:cjs && npm run build:esm+types", "build:cjs": "tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", - "build:esm+types": "tsc --project tsconfig.json --module ES2015 --outDir ./dist/esm --declaration --declarationDir ./dist/types", + "build:esm+types": "tsc --project tsconfig.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/types", "jasmine": "jasmine --config=jasmine.json" }, "main": "./dist/cjs/index.js", diff --git a/packages/connect-node/src/connect-node-adapter.ts b/packages/connect-node/src/connect-node-adapter.ts index 0334b99b5..e548e73ef 100644 --- a/packages/connect-node/src/connect-node-adapter.ts +++ b/packages/connect-node/src/connect-node-adapter.ts @@ -15,18 +15,19 @@ import { Code, connectErrorFromReason, - ConnectRouter, - ConnectRouterOptions, createConnectRouter, } from "@bufbuild/connect"; +import type { ConnectRouter, ConnectRouterOptions } from "@bufbuild/connect"; import type { UniversalHandler } from "@bufbuild/connect/protocol"; import { uResponseNotFound } from "@bufbuild/connect/protocol"; import { + universalRequestFromNodeRequest, + universalResponseToNodeResponse, +} from "./node-universal-handler.js"; +import type { NodeHandlerFn, NodeServerRequest, NodeServerResponse, - universalRequestFromNodeRequest, - universalResponseToNodeResponse, } from "./node-universal-handler.js"; import { compressionBrotli, compressionGzip } from "./compression.js"; diff --git a/packages/connect-node/src/connect-transport.ts b/packages/connect-node/src/connect-transport.ts index ef69718fe..fd807f48a 100644 --- a/packages/connect-node/src/connect-transport.ts +++ b/packages/connect-node/src/connect-transport.ts @@ -21,10 +21,10 @@ import type { import type { Interceptor, Transport } from "@bufbuild/connect"; import type { Compression } from "@bufbuild/connect/protocol"; import { createTransport } from "@bufbuild/connect/protocol-connect"; -import { +import { validateNodeTransportOptions } from "./validate-node-transport-options.js"; +import type { NodeHttp1TransportOptions, NodeHttp2TransportOptions, - validateNodeTransportOptions, } from "./validate-node-transport-options.js"; /** diff --git a/packages/connect-web-bench/README.md b/packages/connect-web-bench/README.md index c89f7cd6d..7557d1f48 100644 --- a/packages/connect-web-bench/README.md +++ b/packages/connect-web-bench/README.md @@ -10,5 +10,5 @@ it like a web server would usually do. | code generator | bundle size | minified | compressed | |----------------|-------------------:|-----------------------:|---------------------:| -| connect | 107,215 b | 46,955 b | 12,525 b | +| connect | 107,197 b | 46,935 b | 12,539 b | | grpc-web | 414,906 b | 301,127 b | 53,279 b | diff --git a/packages/connect-web-test/package.json b/packages/connect-web-test/package.json index c35149819..5f68b2675 100644 --- a/packages/connect-web-test/package.json +++ b/packages/connect-web-test/package.json @@ -4,7 +4,7 @@ "scripts": { "clean": "rm -rf ./dist/esm/*", "generate": "buf generate", - "build": "tsc --project tsconfig.json --module ES2015 --outDir ./dist/esm", + "build": "tsc --project tsconfig.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm", "jasmine": "jasmine --config=jasmine.json", "karma": "karma start karma.conf.cjs", "karma-serve": "karma start karma.serve.conf.cjs", diff --git a/packages/connect-web-test/src/cancellation.spec.ts b/packages/connect-web-test/src/cancellation.spec.ts index 9b7947ef8..60020ccc2 100644 --- a/packages/connect-web-test/src/cancellation.spec.ts +++ b/packages/connect-web-test/src/cancellation.spec.ts @@ -13,12 +13,12 @@ // limitations under the License. import { - CallOptions, Code, ConnectError, createCallbackClient, createPromiseClient, } from "@bufbuild/connect"; +import type { CallOptions } from "@bufbuild/connect"; import { describeTransports } from "./helpers/crosstestserver.js"; import { TestService } from "./gen/grpc/testing/test_connect.js"; diff --git a/packages/connect-web/package.json b/packages/connect-web/package.json index 53400c178..29caaef99 100644 --- a/packages/connect-web/package.json +++ b/packages/connect-web/package.json @@ -12,7 +12,7 @@ "clean": "rm -rf ./dist/cjs/* ./dist/esm/* ./dist/types/*", "build": "npm run build:cjs && npm run build:esm+types", "build:cjs": "tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", - "build:esm+types": "tsc --project tsconfig.json --module ES2015 --outDir ./dist/esm --declaration --declarationDir ./dist/types" + "build:esm+types": "tsc --project tsconfig.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/types" }, "main": "./dist/cjs/index.js", "type": "module", diff --git a/packages/connect-web/src/connect-transport.ts b/packages/connect-web/src/connect-transport.ts index 6fa259d16..e84f4063e 100644 --- a/packages/connect-web/src/connect-transport.ts +++ b/packages/connect-web/src/connect-transport.ts @@ -12,32 +12,31 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { +import { Message, MethodKind } from "@bufbuild/protobuf"; +import type { AnyMessage, BinaryReadOptions, BinaryWriteOptions, JsonReadOptions, JsonValue, JsonWriteOptions, - Message, MethodInfo, - MethodKind, PartialMessage, ServiceType, } from "@bufbuild/protobuf"; -import type { - Interceptor, - Transport, - UnaryRequest, - UnaryResponse, -} from "@bufbuild/connect"; import { appendHeaders, Code, connectErrorFromReason, runStreaming, runUnary, +} from "@bufbuild/connect"; +import type { + Interceptor, StreamResponse, + Transport, + UnaryRequest, + UnaryResponse, } from "@bufbuild/connect"; import { createClientMethodSerializers, diff --git a/packages/connect-web/src/grpc-web-transport.ts b/packages/connect-web/src/grpc-web-transport.ts index 2278ce056..41c2cd801 100644 --- a/packages/connect-web/src/grpc-web-transport.ts +++ b/packages/connect-web/src/grpc-web-transport.ts @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { +import { Message, MethodKind } from "@bufbuild/protobuf"; +import type { AnyMessage, BinaryReadOptions, BinaryWriteOptions, JsonReadOptions, JsonWriteOptions, - Message, MethodInfo, - MethodKind, PartialMessage, ServiceType, } from "@bufbuild/protobuf"; @@ -28,9 +27,11 @@ import type { UnaryRequest } from "@bufbuild/connect"; import { Code, connectErrorFromReason, - Interceptor, runStreaming, runUnary, +} from "@bufbuild/connect"; +import type { + Interceptor, StreamResponse, Transport, UnaryResponse, diff --git a/packages/connect-web/src/index.ts b/packages/connect-web/src/index.ts index f95c80893..851ad7920 100644 --- a/packages/connect-web/src/index.ts +++ b/packages/connect-web/src/index.ts @@ -21,8 +21,6 @@ export type { GrpcWebTransportOptions } from "./grpc-web-transport.js"; // please please import from @bufbuild/connect instead // TODO(TCN-1261) import { - CallbackClient, - CallOptions, Code, ConnectError, connectErrorDetails, @@ -31,6 +29,10 @@ import { createPromiseClient, decodeBinaryHeader, encodeBinaryHeader, +} from "@bufbuild/connect"; +import type { + CallbackClient, + CallOptions, Interceptor, PromiseClient, StreamRequest, diff --git a/packages/connect/package.json b/packages/connect/package.json index cd042dac2..242c1a7f8 100644 --- a/packages/connect/package.json +++ b/packages/connect/package.json @@ -14,7 +14,7 @@ "generate": "buf generate src/protocol-grpc/proto", "build": "npm run build:cjs && npm run build:esm+types", "build:cjs": "tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", - "build:esm+types": "tsc --project tsconfig.json --module ES2015 --outDir ./dist/esm --declaration --declarationDir ./dist/types && echo >./dist/esm/package.json '{\"type\":\"module\", \"sideEffects\":false}'", + "build:esm+types": "tsc --project tsconfig.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/types && echo >./dist/esm/package.json '{\"type\":\"module\", \"sideEffects\":false}'", "jasmine": "jasmine --config=jasmine.json" }, "main": "./dist/cjs/index.js", diff --git a/packages/connect/src/connect-error.ts b/packages/connect/src/connect-error.ts index 9aedb3fb9..ecc4e8f84 100644 --- a/packages/connect/src/connect-error.ts +++ b/packages/connect/src/connect-error.ts @@ -13,12 +13,11 @@ // limitations under the License. import { Code } from "./code.js"; -import { +import { createRegistry, Message } from "@bufbuild/protobuf"; +import type { AnyMessage, - createRegistry, IMessageTypeRegistry, JsonValue, - Message, MessageType, } from "@bufbuild/protobuf"; import { codeToString } from "./protocol-connect/index.js"; diff --git a/packages/connect/src/promise-client.ts b/packages/connect/src/promise-client.ts index 9eeabebba..c635045b4 100644 --- a/packages/connect/src/promise-client.ts +++ b/packages/connect/src/promise-client.ts @@ -12,16 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { +import { Message, MethodKind } from "@bufbuild/protobuf"; +import type { + PartialMessage, + ServiceType, MethodInfo, MethodInfoBiDiStreaming, MethodInfoClientStreaming, MethodInfoServerStreaming, MethodInfoUnary, - PartialMessage, - ServiceType, - Message, - MethodKind, } from "@bufbuild/protobuf"; import { createAsyncIterable } from "./protocol/index.js"; import type { Transport } from "./transport.js"; diff --git a/packages/connect/src/protocol-connect/error-json.ts b/packages/connect/src/protocol-connect/error-json.ts index 90a20cba8..69eacd1fc 100644 --- a/packages/connect/src/protocol-connect/error-json.ts +++ b/packages/connect/src/protocol-connect/error-json.ts @@ -12,12 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { +import { Message, protoBase64 } from "@bufbuild/protobuf"; +import type { JsonObject, JsonValue, JsonWriteOptions, - Message, - protoBase64, } from "@bufbuild/protobuf"; import { Code } from "../code.js"; import { ConnectError } from "../connect-error.js"; diff --git a/packages/connect/src/protocol-connect/handler-factory.spec.ts b/packages/connect/src/protocol-connect/handler-factory.spec.ts index eaa8f061b..16b7e54b9 100644 --- a/packages/connect/src/protocol-connect/handler-factory.spec.ts +++ b/packages/connect/src/protocol-connect/handler-factory.spec.ts @@ -15,15 +15,14 @@ import { Int32Value, Message, - MethodInfo, MethodKind, - ServiceType, StringValue, } from "@bufbuild/protobuf"; +import type { MethodInfo, ServiceType } from "@bufbuild/protobuf"; import { createHandlerFactory } from "./handler-factory.js"; +import { createMethodImplSpec } from "../implementation.js"; import type { HandlerContext, MethodImpl } from "../implementation.js"; import type { UniversalHandlerOptions } from "../protocol/index.js"; -import { createMethodImplSpec } from "../implementation.js"; import { errorFromJsonBytes } from "./error-json.js"; import { ConnectError } from "../connect-error.js"; import { Code } from "../code.js"; @@ -76,8 +75,12 @@ describe("createHandlerFactory()", function () { yield new ctx.method.O(); } as unknown as MethodImpl; break; - default: - throw new Error("not implemented"); + case MethodKind.ClientStreaming: + case MethodKind.BiDiStreaming: + implDefault = (() => { + throw new Error("not implemented"); + }) as unknown as MethodImpl; + break; } const spec = createMethodImplSpec( opt.service ?? testService, diff --git a/packages/connect/src/protocol-connect/handler-factory.ts b/packages/connect/src/protocol-connect/handler-factory.ts index 2d1aadf8d..af47110d3 100644 --- a/packages/connect/src/protocol-connect/handler-factory.ts +++ b/packages/connect/src/protocol-connect/handler-factory.ts @@ -12,25 +12,22 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Message, MethodInfo, MethodKind } from "@bufbuild/protobuf"; +import { Message, MethodKind } from "@bufbuild/protobuf"; +import type { MethodInfo } from "@bufbuild/protobuf"; import { ConnectError, connectErrorFromReason } from "../connect-error.js"; import { Code } from "../code.js"; -import { createHandlerContext, MethodImplSpec } from "../implementation.js"; +import { createHandlerContext } from "../implementation.js"; +import type { MethodImplSpec } from "../implementation.js"; import { assertByteStreamRequest, - Compression, compressionNegotiate, contentTypeMatcher, createMethodSerializationLookup, createMethodUrl, - EnvelopedMessage, invokeUnaryImplementation, - MethodSerializationLookup, validateUniversalHandlerOptions, pipe, - ProtocolHandlerFactory, readAllBytes, - Serialization, transformCatchFinally, transformCompressEnvelope, transformDecompressEnvelope, @@ -40,13 +37,20 @@ import { transformPrepend, transformSerializeEnvelope, transformSplitEnvelope, + uResponseMethodNotAllowed, + uResponseOk, + uResponseUnsupportedMediaType, +} from "../protocol/index.js"; +import type { + Compression, + EnvelopedMessage, + MethodSerializationLookup, + ProtocolHandlerFactory, + Serialization, UniversalHandlerFn, UniversalHandlerOptions, UniversalServerRequest, UniversalServerResponse, - uResponseMethodNotAllowed, - uResponseOk, - uResponseUnsupportedMediaType, } from "../protocol/index.js"; import { contentTypeStreamJson, @@ -57,11 +61,8 @@ import { contentTypeUnaryRegExp, parseContentType, } from "./content-type.js"; -import { - createEndStreamSerialization, - endStreamFlag, - EndStreamResponse, -} from "./end-stream.js"; +import { createEndStreamSerialization, endStreamFlag } from "./end-stream.js"; +import type { EndStreamResponse } from "./end-stream.js"; import { headerContentType, headerStreamAcceptEncoding, diff --git a/packages/connect/src/protocol-connect/transport.ts b/packages/connect/src/protocol-connect/transport.ts index 1c97cc436..6ffcc129e 100644 --- a/packages/connect/src/protocol-connect/transport.ts +++ b/packages/connect/src/protocol-connect/transport.ts @@ -25,6 +25,8 @@ import { ConnectError, runStreaming, runUnary, +} from "../index.js"; +import type { StreamRequest, StreamResponse, Transport, @@ -32,7 +34,6 @@ import { UnaryResponse, } from "../index.js"; import { - CommonTransportOptions, createAsyncIterable, createMethodSerializationLookup, createMethodUrl, @@ -47,6 +48,7 @@ import { transformSerializeEnvelope, transformSplitEnvelope, } from "../protocol/index.js"; +import type { CommonTransportOptions } from "../protocol/index.js"; import { requestHeaderWithCompression } from "./request-header.js"; import { headerUnaryContentLength, headerUnaryEncoding } from "./headers.js"; import { validateResponseWithCompression } from "./validate-response.js"; diff --git a/packages/connect/src/protocol-grpc-web/handler-factory.ts b/packages/connect/src/protocol-grpc-web/handler-factory.ts index 0997759b8..91e6d25e2 100644 --- a/packages/connect/src/protocol-grpc-web/handler-factory.ts +++ b/packages/connect/src/protocol-grpc-web/handler-factory.ts @@ -15,18 +15,13 @@ import type { Message } from "@bufbuild/protobuf"; import { ConnectError } from "../connect-error.js"; import { Code } from "../code.js"; -import { MethodImplSpec, createHandlerContext } from "../implementation.js"; +import { createHandlerContext } from "../implementation.js"; +import type { MethodImplSpec } from "../implementation.js"; import { - ProtocolHandlerFactory, - UniversalHandlerOptions, validateUniversalHandlerOptions, - UniversalServerRequest, - UniversalServerResponse, uResponseMethodNotAllowed, uResponseOk, uResponseUnsupportedMediaType, - Serialization, - EnvelopedMessage, assertByteStreamRequest, compressionNegotiate, contentTypeMatcher, @@ -43,6 +38,13 @@ import { transformCatchFinally, transformInvokeImplementation, } from "../protocol/index.js"; +import type { Serialization, EnvelopedMessage } from "../protocol/index.js"; +import type { + ProtocolHandlerFactory, + UniversalHandlerOptions, + UniversalServerRequest, + UniversalServerResponse, +} from "../protocol/index.js"; import { grpcStatusOk, setTrailerStatus } from "../protocol-grpc/index.js"; import { createTrailerSerialization, trailerFlag } from "./trailer.js"; import { diff --git a/packages/connect/src/protocol-grpc-web/transport.ts b/packages/connect/src/protocol-grpc-web/transport.ts index bb9e52266..eda9ec3f1 100644 --- a/packages/connect/src/protocol-grpc-web/transport.ts +++ b/packages/connect/src/protocol-grpc-web/transport.ts @@ -19,11 +19,8 @@ import type { PartialMessage, ServiceType, } from "@bufbuild/protobuf"; -import { - Code, - ConnectError, - runStreaming, - runUnary, +import { Code, ConnectError, runStreaming, runUnary } from "../index.js"; +import type { StreamRequest, StreamResponse, Transport, @@ -31,7 +28,6 @@ import { UnaryResponse, } from "../index.js"; import { - CommonTransportOptions, createAsyncIterable, createMethodSerializationLookup, createMethodUrl, @@ -45,6 +41,7 @@ import { transformSerializeEnvelope, transformSplitEnvelope, } from "../protocol/index.js"; +import type { CommonTransportOptions } from "../protocol/index.js"; import { validateTrailer } from "../protocol-grpc/validate-trailer.js"; import { requestHeaderWithCompression } from "./request-header.js"; import { validateResponseWithCompression } from "./validate-response.js"; diff --git a/packages/connect/src/protocol-grpc/handler-factory.ts b/packages/connect/src/protocol-grpc/handler-factory.ts index b9085be89..31fe5ec6c 100644 --- a/packages/connect/src/protocol-grpc/handler-factory.ts +++ b/packages/connect/src/protocol-grpc/handler-factory.ts @@ -13,15 +13,12 @@ // limitations under the License. import type { Message } from "@bufbuild/protobuf"; -import { createHandlerContext, MethodImplSpec } from "../implementation.js"; +import { createHandlerContext } from "../implementation.js"; +import type { MethodImplSpec } from "../implementation.js"; import { ConnectError } from "../connect-error.js"; import { Code } from "../code.js"; import { - ProtocolHandlerFactory, - UniversalHandlerOptions, validateUniversalHandlerOptions, - UniversalServerRequest, - UniversalServerResponse, uResponseMethodNotAllowed, uResponseOk, uResponseUnsupportedMediaType, @@ -41,6 +38,12 @@ import { transformSplitEnvelope, transformInvokeImplementation, } from "../protocol/index.js"; +import type { + ProtocolHandlerFactory, + UniversalHandlerOptions, + UniversalServerRequest, + UniversalServerResponse, +} from "../protocol/index.js"; import { contentTypeJson, contentTypeProto, diff --git a/packages/connect/src/protocol-grpc/transport.ts b/packages/connect/src/protocol-grpc/transport.ts index db7523869..7fb093610 100644 --- a/packages/connect/src/protocol-grpc/transport.ts +++ b/packages/connect/src/protocol-grpc/transport.ts @@ -19,11 +19,8 @@ import type { PartialMessage, ServiceType, } from "@bufbuild/protobuf"; -import { - Code, - ConnectError, - runStreaming, - runUnary, +import { Code, ConnectError, runStreaming, runUnary } from "../index.js"; +import type { StreamRequest, StreamResponse, Transport, @@ -31,7 +28,6 @@ import { UnaryResponse, } from "../index.js"; import { - CommonTransportOptions, createAsyncIterable, createMethodSerializationLookup, createMethodUrl, @@ -45,6 +41,7 @@ import { transformSerializeEnvelope, transformSplitEnvelope, } from "../protocol/index.js"; +import type { CommonTransportOptions } from "../protocol/index.js"; import { requestHeaderWithCompression } from "./request-header.js"; import { validateResponseWithCompression } from "./validate-response.js"; import { validateTrailer } from "./validate-trailer.js"; diff --git a/packages/connect/src/protocol/async-iterable-story.spec.ts b/packages/connect/src/protocol/async-iterable-story.spec.ts index 77a37c24e..c6e93b510 100644 --- a/packages/connect/src/protocol/async-iterable-story.spec.ts +++ b/packages/connect/src/protocol/async-iterable-story.spec.ts @@ -32,8 +32,8 @@ import { transformParseEnvelope, createAsyncIterable, createWritableIterable, - WritableIterable, } from "./async-iterable.js"; +import type { WritableIterable } from "./async-iterable.js"; // These tests aim to model the usage of iterable transforms in clients and servers. // Note that the tests were written as a proof of concept, and the coverage is diff --git a/packages/connect/src/protocol/compression.spec.ts b/packages/connect/src/protocol/compression.spec.ts index 1eff30a08..a9e614e59 100644 --- a/packages/connect/src/protocol/compression.spec.ts +++ b/packages/connect/src/protocol/compression.spec.ts @@ -12,7 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Compression, compressionNegotiate } from "./compression.js"; +import { compressionNegotiate } from "./compression.js"; +import type { Compression } from "./compression.js"; import { ConnectError } from "../connect-error.js"; import { node16FetchHeadersPolyfill } from "../node16-polyfill-helper.spec.js"; diff --git a/packages/connect/src/protocol/envelope.spec.ts b/packages/connect/src/protocol/envelope.spec.ts index 3736bc145..1535e44da 100644 --- a/packages/connect/src/protocol/envelope.spec.ts +++ b/packages/connect/src/protocol/envelope.spec.ts @@ -17,8 +17,8 @@ import { encodeEnvelopes, envelopeCompress, envelopeDecompress, - EnvelopedMessage, } from "./envelope.js"; +import type { EnvelopedMessage } from "./envelope.js"; import type { Compression } from "./compression.js"; import { ConnectError, connectErrorFromReason } from "../connect-error.js"; import { Code } from "../code.js"; diff --git a/packages/connect/src/protocol/envelope.ts b/packages/connect/src/protocol/envelope.ts index 5701d27b9..abf749e03 100644 --- a/packages/connect/src/protocol/envelope.ts +++ b/packages/connect/src/protocol/envelope.ts @@ -14,7 +14,8 @@ import { ConnectError } from "../connect-error.js"; import { Code } from "../code.js"; -import { compressedFlag, Compression } from "./compression.js"; +import { compressedFlag } from "./compression.js"; +import type { Compression } from "./compression.js"; /** * Represents an Enveloped-Message of the Connect protocol. diff --git a/packages/connect/src/protocol/invoke-implementation.ts b/packages/connect/src/protocol/invoke-implementation.ts index f134035f7..6a7547124 100644 --- a/packages/connect/src/protocol/invoke-implementation.ts +++ b/packages/connect/src/protocol/invoke-implementation.ts @@ -12,7 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Message, MethodKind, PartialMessage } from "@bufbuild/protobuf"; +import { Message, MethodKind } from "@bufbuild/protobuf"; +import type { PartialMessage } from "@bufbuild/protobuf"; import { ConnectError } from "../connect-error.js"; import { Code } from "../code.js"; import type { HandlerContext, MethodImplSpec } from "../implementation.js"; diff --git a/packages/connect/src/protocol/serialization.spec.ts b/packages/connect/src/protocol/serialization.spec.ts index f388375eb..fc6f269d3 100644 --- a/packages/connect/src/protocol/serialization.spec.ts +++ b/packages/connect/src/protocol/serialization.spec.ts @@ -17,8 +17,8 @@ import { createBinarySerialization, createJsonSerialization, limitSerialization, - Serialization, } from "./serialization.js"; +import type { Serialization } from "./serialization.js"; import { ConnectError, connectErrorFromReason } from "../connect-error.js"; describe("createBinarySerialization()", function () { diff --git a/packages/connect/src/protocol/universal-handler.spec.ts b/packages/connect/src/protocol/universal-handler.spec.ts index 586ac3c67..8fd2afeb8 100644 --- a/packages/connect/src/protocol/universal-handler.spec.ts +++ b/packages/connect/src/protocol/universal-handler.spec.ts @@ -16,9 +16,11 @@ import type { ServiceType } from "@bufbuild/protobuf"; import { Int32Value, MethodKind, StringValue } from "@bufbuild/protobuf"; import { negotiateProtocol, + validateUniversalHandlerOptions, +} from "./universal-handler.js"; +import type { UniversalHandler, UniversalHandlerOptions, - validateUniversalHandlerOptions, } from "./universal-handler.js"; import type { Compression } from "./compression.js"; import { contentTypeMatcher } from "./content-type-matcher.js"; diff --git a/packages/connect/src/protocol/universal-handler.ts b/packages/connect/src/protocol/universal-handler.ts index 63e447817..d91877865 100644 --- a/packages/connect/src/protocol/universal-handler.ts +++ b/packages/connect/src/protocol/universal-handler.ts @@ -12,27 +12,27 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { +import { MethodKind } from "@bufbuild/protobuf"; +import type { BinaryReadOptions, BinaryWriteOptions, JsonReadOptions, JsonWriteOptions, MethodInfo, - MethodKind, ServiceType, } from "@bufbuild/protobuf"; import type { MethodImplSpec, ServiceImplSpec } from "../implementation.js"; import { - UniversalHandlerFn, - UniversalServerRequest, uResponseMethodNotAllowed, uResponseUnsupportedMediaType, uResponseVersionNotSupported, } from "./universal.js"; -import { - ContentTypeMatcher, - contentTypeMatcher, -} from "./content-type-matcher.js"; +import type { + UniversalHandlerFn, + UniversalServerRequest, +} from "./universal.js"; +import { contentTypeMatcher } from "./content-type-matcher.js"; +import type { ContentTypeMatcher } from "./content-type-matcher.js"; import type { Compression } from "./compression.js"; import type { ProtocolHandlerFactory } from "./protocol-handler-factory.js"; import { validateReadWriteMaxBytes } from "./limit-io.js"; diff --git a/packages/connect/src/router-transport.ts b/packages/connect/src/router-transport.ts index eb0b7c11f..dc9f05145 100644 --- a/packages/connect/src/router-transport.ts +++ b/packages/connect/src/router-transport.ts @@ -15,11 +15,8 @@ import { createTransport } from "./protocol-connect/transport.js"; import type { CommonTransportOptions } from "./protocol/transport-options.js"; import { createUniversalHandlerClient } from "./protocol/universal-handler-client.js"; -import { - ConnectRouter, - ConnectRouterOptions, - createConnectRouter, -} from "./router.js"; +import { createConnectRouter } from "./router.js"; +import type { ConnectRouter, ConnectRouterOptions } from "./router.js"; /** * Creates a Transport that routes requests to the configured router. Useful for testing diff --git a/packages/connect/src/router.ts b/packages/connect/src/router.ts index aae4c406d..fdbaa465c 100644 --- a/packages/connect/src/router.ts +++ b/packages/connect/src/router.ts @@ -18,17 +18,18 @@ import { Code } from "./code.js"; import { createMethodImplSpec, createServiceImplSpec, - MethodImpl, - ServiceImpl, } from "./implementation.js"; +import type { MethodImpl, ServiceImpl } from "./implementation.js"; import { - ProtocolHandlerFactory, - UniversalHandler, - UniversalHandlerOptions, validateUniversalHandlerOptions, createUniversalMethodHandler, createUniversalServiceHandlers, } from "./protocol/index.js"; +import type { + ProtocolHandlerFactory, + UniversalHandler, + UniversalHandlerOptions, +} from "./protocol/index.js"; import { createHandlerFactory as handlerFactoryGrpcWeb } from "./protocol-grpc-web/handler-factory.js"; import { createHandlerFactory as handlerFactoryGrpc } from "./protocol-grpc/handler-factory.js"; import { createHandlerFactory as handlerFactoryConnect } from "./protocol-connect/handler-factory.js"; diff --git a/packages/connect/src/transport-stub.ts b/packages/connect/src/transport-stub.ts index 6ef983d32..7ea31e05d 100644 --- a/packages/connect/src/transport-stub.ts +++ b/packages/connect/src/transport-stub.ts @@ -20,10 +20,9 @@ import type { } from "@bufbuild/protobuf"; import type { Transport } from "./transport.js"; import type { ConnectError } from "./connect-error.js"; -import { +import { runStreaming, runUnary } from "./interceptor.js"; +import type { Interceptor, - runStreaming, - runUnary, StreamResponse, StreamRequest, UnaryRequest, diff --git a/packages/example/package.json b/packages/example/package.json index f5a2ba5bd..f5aec46c0 100644 --- a/packages/example/package.json +++ b/packages/example/package.json @@ -23,6 +23,6 @@ "@bufbuild/protoc-gen-es": "^1.2.0", "@types/express": "^4.17.15", "esbuild": "^0.16.12", - "typescript": "^4.9.5" + "typescript": "^5.0.3" } } diff --git a/packages/example/src/server.ts b/packages/example/src/server.ts index 8572d1f5b..d32cfc5d6 100644 --- a/packages/example/src/server.ts +++ b/packages/example/src/server.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { ConnectRouter } from "@bufbuild/connect"; +import type { ConnectRouter } from "@bufbuild/connect"; import { connectNodeAdapter } from "@bufbuild/connect-node"; import { ElizaService } from "./gen/eliza_connect.js"; import type { diff --git a/packages/example/tsconfig.json b/packages/example/tsconfig.json index f6c1c2f6a..d129daaf9 100644 --- a/packages/example/tsconfig.json +++ b/packages/example/tsconfig.json @@ -8,13 +8,13 @@ "strict": true, "sourceMap": true, "resolveJsonModule": true, - "isolatedModules": true, "esModuleInterop": true, "noEmit": true, "noUnusedLocals": true, "noUnusedParameters": true, "noImplicitReturns": true, - "skipLibCheck": true + "skipLibCheck": true, + "verbatimModuleSyntax": true }, "include": ["src/**/*.ts"] } diff --git a/tsconfig.base.json b/tsconfig.base.json index fec4a6097..d7e5c6163 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -9,7 +9,6 @@ "ES2018.AsyncIterable" ], "esModuleInterop": false, - "importsNotUsedAsValues": "error", "forceConsistentCasingInFileNames": true, "strict": true, "noImplicitAny": true, @@ -26,9 +25,6 @@ // We need node's module resolution, so we do not have to skip lib checks "moduleResolution": "Node", - "skipLibCheck": false, - - // To support bundlers that transpile files in isolation - "isolatedModules": true + "skipLibCheck": false } }