From 7ee28208b8a851ba28dcb56ea123582c839d1bb6 Mon Sep 17 00:00:00 2001 From: Paul Sachs <11449728+paul-sachs@users.noreply.github.com> Date: Thu, 14 Dec 2023 09:40:22 -0500 Subject: [PATCH] Added support for cjs output (#303) Fixes #297 Add support for CommonJS with the new plugin option: ### `js_import_style` By default, [protoc-gen-connect-query](https://www.npmjs.com/package/@connectrpc/protoc-gen-connect-query)(and all other plugins based on [@bufbuild/protoplugin](https://www.npmjs.com/package/@bufbuild/protoplugin)) generate ECMAScript `import` and `export` statements. For use cases where CommonJS is difficult to avoid, this option can be used to generate CommonJS`require()` calls. #### Example buf.gen.yaml ``` version: v1 plugins: - plugin: es out: src/gen opt: js_import_style=legacy_commonjs - plugin: connect-query out: src/gen opt: js_import_style=legacy_commonjs ``` --- .eslintrc.js | 2 +- packages/protoc-gen-connect-query/README.md | 14 + .../protoc-gen-connect-query/package.json | 2 +- .../snapshots/buf.gen.yaml | 32 ++- .../v1/eliza-ElizaService_connectquery.d.ts | 4 +- .../v1/eliza-ElizaService_connectquery.js | 41 +++ .../gen_cjs/connectrpc/eliza/v1/eliza_pb.d.ts | 258 ++++++++++++++++++ .../gen_cjs/connectrpc/eliza/v1/eliza_pb.js | 102 +++++++ .../v1/eliza-ElizaService_connectquery.d.ts | 36 +++ .../v1/eliza-ElizaService_connectquery.js | 5 +- .../gen_js/connectrpc/eliza/v1/eliza_pb.d.ts | 258 ++++++++++++++++++ .../gen_js/connectrpc/eliza/v1/eliza_pb.js | 92 +++++++ .../v1/eliza-ElizaService_connectquery.ts | 4 +- .../connectrpc/eliza/v1/eliza_pb.ts | 0 .../src/generateDts.ts | 24 +- .../src/generateTs.ts | 30 +- 16 files changed, 855 insertions(+), 49 deletions(-) rename packages/protoc-gen-connect-query/snapshots/{gen => gen_cjs}/connectrpc/eliza/v1/eliza-ElizaService_connectquery.d.ts (91%) create mode 100644 packages/protoc-gen-connect-query/snapshots/gen_cjs/connectrpc/eliza/v1/eliza-ElizaService_connectquery.js create mode 100644 packages/protoc-gen-connect-query/snapshots/gen_cjs/connectrpc/eliza/v1/eliza_pb.d.ts create mode 100644 packages/protoc-gen-connect-query/snapshots/gen_cjs/connectrpc/eliza/v1/eliza_pb.js create mode 100644 packages/protoc-gen-connect-query/snapshots/gen_js/connectrpc/eliza/v1/eliza-ElizaService_connectquery.d.ts rename packages/protoc-gen-connect-query/snapshots/{gen => gen_js}/connectrpc/eliza/v1/eliza-ElizaService_connectquery.js (86%) create mode 100644 packages/protoc-gen-connect-query/snapshots/gen_js/connectrpc/eliza/v1/eliza_pb.d.ts create mode 100644 packages/protoc-gen-connect-query/snapshots/gen_js/connectrpc/eliza/v1/eliza_pb.js rename packages/protoc-gen-connect-query/snapshots/{gen => gen_ts}/connectrpc/eliza/v1/eliza-ElizaService_connectquery.ts (91%) rename packages/protoc-gen-connect-query/snapshots/{gen => gen_ts}/connectrpc/eliza/v1/eliza_pb.ts (100%) diff --git a/.eslintrc.js b/.eslintrc.js index b413f81d..3e84b5b3 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -120,7 +120,7 @@ const config = { }, }, { - files: ["**/eliza/*", "**/gen/**"], // generated code + files: ["**/eliza/*", "**/gen/**", "**/snapshots/**"], // generated code rules: { "eslint-comments/no-unused-enable": "off", "eslint-comments/no-unused-disable": "off", diff --git a/packages/protoc-gen-connect-query/README.md b/packages/protoc-gen-connect-query/README.md index 9356311a..bae45729 100644 --- a/packages/protoc-gen-connect-query/README.md +++ b/packages/protoc-gen-connect-query/README.md @@ -198,6 +198,20 @@ Unfortunately, not all bundlers and tools have caught up yet, and Deno requires This option exists for other plugins but is not applicable to `protoc-gen-connect-query` because, unlike most other plugins, it does not generate a maximum of one output file for every input proto file. Instead, it generates one output file per service. If you provide a valid proto file that contains no services, `protoc-gen-connect-query` will have no output. +### `js_import_style` + +By default, [protoc-gen-connect-query](https://www.npmjs.com/package/@connectrpc/protoc-gen-connect-query) +(and all other plugins based on [@bufbuild/protoplugin](https://www.npmjs.com/package/@bufbuild/protoplugin)) +generate ECMAScript `import` and `export` statements. For use cases where +CommonJS is difficult to avoid, this option can be used to generate CommonJS +`require()` calls. + +Possible values: + +- `js_import_style=module` generate ECMAScript `import` / `export` statements - + the default behavior. +- `js_import_style=legacy_commonjs` generate CommonJS `require()` calls. + ## Example Generated Code See [`eliza.proto`](../../examples/react/basic/eliza.proto) for example inputs, and look [here](../../examples/react/basic/src/gen) to see the outputs those files generate. diff --git a/packages/protoc-gen-connect-query/package.json b/packages/protoc-gen-connect-query/package.json index c6cb9db5..e88c6d52 100644 --- a/packages/protoc-gen-connect-query/package.json +++ b/packages/protoc-gen-connect-query/package.json @@ -22,7 +22,7 @@ "clean": "rm -rf dist", "build": "pnpm clean && tsc --project tsconfig.build.json", "format": "prettier . --write --ignore-path ./.eslintignore && eslint . --fix && license-header", - "generate": "rm -rf snapshots/gen && cd snapshots && buf generate buf.build/connectrpc/eliza:8b8b971d6fde4dc8ba5d96f9fda7d53c", + "generate": "rm -rf snapshots/gen* && cd snapshots && buf generate buf.build/connectrpc/eliza:8b8b971d6fde4dc8ba5d96f9fda7d53c", "test": "tsc --declaration --declarationDir .type-dump --emitDeclarationOnly" }, "preferUnplugged": true, diff --git a/packages/protoc-gen-connect-query/snapshots/buf.gen.yaml b/packages/protoc-gen-connect-query/snapshots/buf.gen.yaml index adfcd0a1..877ee203 100644 --- a/packages/protoc-gen-connect-query/snapshots/buf.gen.yaml +++ b/packages/protoc-gen-connect-query/snapshots/buf.gen.yaml @@ -1,16 +1,32 @@ -# buf.gen.yaml defines a local generation template. -# For details, see https://docs.buf.build/configuration/v1/buf-gen-yaml version: v1 plugins: + # js - plugin: es - out: gen + out: gen_js + - plugin: connect-query + path: ../bin/protoc-gen-connect-query + out: gen_js + + # cjs + - plugin: es + out: gen_cjs opt: - - target=ts + - js_import_style=legacy_commonjs + - plugin: connect-query + path: ../bin/protoc-gen-connect-query + out: gen_cjs + opt: + - js_import_style=legacy_commonjs + - ts_nocheck=false # we only set this for our tests + # ts + - plugin: es + out: gen_ts + opt: + - target=ts - plugin: connect-query path: ../bin/protoc-gen-connect-query - out: gen + out: gen_ts opt: - - target=ts+dts+js - - import_extension=none - - ts_nocheck=false + - target=ts + - ts_nocheck=false # we only set this for our tests diff --git a/packages/protoc-gen-connect-query/snapshots/gen/connectrpc/eliza/v1/eliza-ElizaService_connectquery.d.ts b/packages/protoc-gen-connect-query/snapshots/gen_cjs/connectrpc/eliza/v1/eliza-ElizaService_connectquery.d.ts similarity index 91% rename from packages/protoc-gen-connect-query/snapshots/gen/connectrpc/eliza/v1/eliza-ElizaService_connectquery.d.ts rename to packages/protoc-gen-connect-query/snapshots/gen_cjs/connectrpc/eliza/v1/eliza-ElizaService_connectquery.d.ts index b1744888..c68f75ea 100644 --- a/packages/protoc-gen-connect-query/snapshots/gen/connectrpc/eliza/v1/eliza-ElizaService_connectquery.d.ts +++ b/packages/protoc-gen-connect-query/snapshots/gen_cjs/connectrpc/eliza/v1/eliza-ElizaService_connectquery.d.ts @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -// @generated by protoc-gen-connect-query v1.0.0 with parameter "target=ts+dts+js,import_extension=none,ts_nocheck=false" +// @generated by protoc-gen-connect-query v1.0.0 with parameter "js_import_style=legacy_commonjs,ts_nocheck=false" // @generated from file connectrpc/eliza/v1/eliza.proto (package connectrpc.eliza.v1, syntax proto3) /* eslint-disable */ -import { SayRequest, SayResponse } from "./eliza_pb"; +import { SayRequest, SayResponse } from "./eliza_pb.js"; import { MethodKind } from "@bufbuild/protobuf"; /** diff --git a/packages/protoc-gen-connect-query/snapshots/gen_cjs/connectrpc/eliza/v1/eliza-ElizaService_connectquery.js b/packages/protoc-gen-connect-query/snapshots/gen_cjs/connectrpc/eliza/v1/eliza-ElizaService_connectquery.js new file mode 100644 index 00000000..d97cba4d --- /dev/null +++ b/packages/protoc-gen-connect-query/snapshots/gen_cjs/connectrpc/eliza/v1/eliza-ElizaService_connectquery.js @@ -0,0 +1,41 @@ +// Copyright 2021-2023 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. + +// @generated by protoc-gen-connect-query v1.0.0 with parameter "js_import_style=legacy_commonjs,ts_nocheck=false" +// @generated from file connectrpc/eliza/v1/eliza.proto (package connectrpc.eliza.v1, syntax proto3) +/* eslint-disable */ + +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); + +const { MethodKind } = require("@bufbuild/protobuf"); +const { SayRequest, SayResponse } = require("./eliza_pb.js"); + +/** + * Say is a unary RPC. Eliza responds to the prompt with a single sentence. + * + * @generated from rpc connectrpc.eliza.v1.ElizaService.Say + */ +const say = { + localName: "say", + name: "Say", + kind: MethodKind.Unary, + I: SayRequest, + O: SayResponse, + service: { + typeName: "connectrpc.eliza.v1.ElizaService", + }, +}; + +exports.say = say; diff --git a/packages/protoc-gen-connect-query/snapshots/gen_cjs/connectrpc/eliza/v1/eliza_pb.d.ts b/packages/protoc-gen-connect-query/snapshots/gen_cjs/connectrpc/eliza/v1/eliza_pb.d.ts new file mode 100644 index 00000000..e65132d1 --- /dev/null +++ b/packages/protoc-gen-connect-query/snapshots/gen_cjs/connectrpc/eliza/v1/eliza_pb.d.ts @@ -0,0 +1,258 @@ +// Copyright 2021-2023 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. + +// @generated by protoc-gen-es v1.6.0 with parameter "js_import_style=legacy_commonjs" +// @generated from file connectrpc/eliza/v1/eliza.proto (package connectrpc.eliza.v1, syntax proto3) +/* eslint-disable */ +// @ts-nocheck + +import type { + BinaryReadOptions, + FieldList, + JsonReadOptions, + JsonValue, + PartialMessage, + PlainMessage, +} from "@bufbuild/protobuf"; +import { Message, proto3 } from "@bufbuild/protobuf"; + +/** + * SayRequest is a single-sentence request. + * + * @generated from message connectrpc.eliza.v1.SayRequest + */ +export declare class SayRequest extends Message { + /** + * @generated from field: string sentence = 1; + */ + sentence: string; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "connectrpc.eliza.v1.SayRequest"; + static readonly fields: FieldList; + + static fromBinary( + bytes: Uint8Array, + options?: Partial, + ): SayRequest; + + static fromJson( + jsonValue: JsonValue, + options?: Partial, + ): SayRequest; + + static fromJsonString( + jsonString: string, + options?: Partial, + ): SayRequest; + + static equals( + a: SayRequest | PlainMessage | undefined, + b: SayRequest | PlainMessage | undefined, + ): boolean; +} + +/** + * SayResponse is a single-sentence response. + * + * @generated from message connectrpc.eliza.v1.SayResponse + */ +export declare class SayResponse extends Message { + /** + * @generated from field: string sentence = 1; + */ + sentence: string; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "connectrpc.eliza.v1.SayResponse"; + static readonly fields: FieldList; + + static fromBinary( + bytes: Uint8Array, + options?: Partial, + ): SayResponse; + + static fromJson( + jsonValue: JsonValue, + options?: Partial, + ): SayResponse; + + static fromJsonString( + jsonString: string, + options?: Partial, + ): SayResponse; + + static equals( + a: SayResponse | PlainMessage | undefined, + b: SayResponse | PlainMessage | undefined, + ): boolean; +} + +/** + * ConverseRequest is a single sentence request sent as part of a + * back-and-forth conversation. + * + * @generated from message connectrpc.eliza.v1.ConverseRequest + */ +export declare class ConverseRequest extends Message { + /** + * @generated from field: string sentence = 1; + */ + sentence: string; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "connectrpc.eliza.v1.ConverseRequest"; + static readonly fields: FieldList; + + static fromBinary( + bytes: Uint8Array, + options?: Partial, + ): ConverseRequest; + + static fromJson( + jsonValue: JsonValue, + options?: Partial, + ): ConverseRequest; + + static fromJsonString( + jsonString: string, + options?: Partial, + ): ConverseRequest; + + static equals( + a: ConverseRequest | PlainMessage | undefined, + b: ConverseRequest | PlainMessage | undefined, + ): boolean; +} + +/** + * ConverseResponse is a single sentence response sent in answer to a + * ConverseRequest. + * + * @generated from message connectrpc.eliza.v1.ConverseResponse + */ +export declare class ConverseResponse extends Message { + /** + * @generated from field: string sentence = 1; + */ + sentence: string; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "connectrpc.eliza.v1.ConverseResponse"; + static readonly fields: FieldList; + + static fromBinary( + bytes: Uint8Array, + options?: Partial, + ): ConverseResponse; + + static fromJson( + jsonValue: JsonValue, + options?: Partial, + ): ConverseResponse; + + static fromJsonString( + jsonString: string, + options?: Partial, + ): ConverseResponse; + + static equals( + a: ConverseResponse | PlainMessage | undefined, + b: ConverseResponse | PlainMessage | undefined, + ): boolean; +} + +/** + * IntroduceRequest asks Eliza to introduce itself to the named user. + * + * @generated from message connectrpc.eliza.v1.IntroduceRequest + */ +export declare class IntroduceRequest extends Message { + /** + * @generated from field: string name = 1; + */ + name: string; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "connectrpc.eliza.v1.IntroduceRequest"; + static readonly fields: FieldList; + + static fromBinary( + bytes: Uint8Array, + options?: Partial, + ): IntroduceRequest; + + static fromJson( + jsonValue: JsonValue, + options?: Partial, + ): IntroduceRequest; + + static fromJsonString( + jsonString: string, + options?: Partial, + ): IntroduceRequest; + + static equals( + a: IntroduceRequest | PlainMessage | undefined, + b: IntroduceRequest | PlainMessage | undefined, + ): boolean; +} + +/** + * IntroduceResponse is one sentence of Eliza's introductory monologue. + * + * @generated from message connectrpc.eliza.v1.IntroduceResponse + */ +export declare class IntroduceResponse extends Message { + /** + * @generated from field: string sentence = 1; + */ + sentence: string; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "connectrpc.eliza.v1.IntroduceResponse"; + static readonly fields: FieldList; + + static fromBinary( + bytes: Uint8Array, + options?: Partial, + ): IntroduceResponse; + + static fromJson( + jsonValue: JsonValue, + options?: Partial, + ): IntroduceResponse; + + static fromJsonString( + jsonString: string, + options?: Partial, + ): IntroduceResponse; + + static equals( + a: IntroduceResponse | PlainMessage | undefined, + b: IntroduceResponse | PlainMessage | undefined, + ): boolean; +} diff --git a/packages/protoc-gen-connect-query/snapshots/gen_cjs/connectrpc/eliza/v1/eliza_pb.js b/packages/protoc-gen-connect-query/snapshots/gen_cjs/connectrpc/eliza/v1/eliza_pb.js new file mode 100644 index 00000000..7868a683 --- /dev/null +++ b/packages/protoc-gen-connect-query/snapshots/gen_cjs/connectrpc/eliza/v1/eliza_pb.js @@ -0,0 +1,102 @@ +// Copyright 2021-2023 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. + +// @generated by protoc-gen-es v1.6.0 with parameter "js_import_style=legacy_commonjs" +// @generated from file connectrpc/eliza/v1/eliza.proto (package connectrpc.eliza.v1, syntax proto3) +/* eslint-disable */ +// @ts-nocheck + +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); + +const { proto3 } = require("@bufbuild/protobuf"); + +/** + * SayRequest is a single-sentence request. + * + * @generated from message connectrpc.eliza.v1.SayRequest + */ +const SayRequest = proto3.makeMessageType( + "connectrpc.eliza.v1.SayRequest", + () => [ + { no: 1, name: "sentence", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + ], +); + +/** + * SayResponse is a single-sentence response. + * + * @generated from message connectrpc.eliza.v1.SayResponse + */ +const SayResponse = proto3.makeMessageType( + "connectrpc.eliza.v1.SayResponse", + () => [ + { no: 1, name: "sentence", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + ], +); + +/** + * ConverseRequest is a single sentence request sent as part of a + * back-and-forth conversation. + * + * @generated from message connectrpc.eliza.v1.ConverseRequest + */ +const ConverseRequest = proto3.makeMessageType( + "connectrpc.eliza.v1.ConverseRequest", + () => [ + { no: 1, name: "sentence", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + ], +); + +/** + * ConverseResponse is a single sentence response sent in answer to a + * ConverseRequest. + * + * @generated from message connectrpc.eliza.v1.ConverseResponse + */ +const ConverseResponse = proto3.makeMessageType( + "connectrpc.eliza.v1.ConverseResponse", + () => [ + { no: 1, name: "sentence", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + ], +); + +/** + * IntroduceRequest asks Eliza to introduce itself to the named user. + * + * @generated from message connectrpc.eliza.v1.IntroduceRequest + */ +const IntroduceRequest = proto3.makeMessageType( + "connectrpc.eliza.v1.IntroduceRequest", + () => [{ no: 1, name: "name", kind: "scalar", T: 9 /* ScalarType.STRING */ }], +); + +/** + * IntroduceResponse is one sentence of Eliza's introductory monologue. + * + * @generated from message connectrpc.eliza.v1.IntroduceResponse + */ +const IntroduceResponse = proto3.makeMessageType( + "connectrpc.eliza.v1.IntroduceResponse", + () => [ + { no: 1, name: "sentence", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + ], +); + +exports.SayRequest = SayRequest; +exports.SayResponse = SayResponse; +exports.ConverseRequest = ConverseRequest; +exports.ConverseResponse = ConverseResponse; +exports.IntroduceRequest = IntroduceRequest; +exports.IntroduceResponse = IntroduceResponse; diff --git a/packages/protoc-gen-connect-query/snapshots/gen_js/connectrpc/eliza/v1/eliza-ElizaService_connectquery.d.ts b/packages/protoc-gen-connect-query/snapshots/gen_js/connectrpc/eliza/v1/eliza-ElizaService_connectquery.d.ts new file mode 100644 index 00000000..6d6c7488 --- /dev/null +++ b/packages/protoc-gen-connect-query/snapshots/gen_js/connectrpc/eliza/v1/eliza-ElizaService_connectquery.d.ts @@ -0,0 +1,36 @@ +// Copyright 2021-2023 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. + +// @generated by protoc-gen-connect-query v1.0.0 +// @generated from file connectrpc/eliza/v1/eliza.proto (package connectrpc.eliza.v1, syntax proto3) +/* eslint-disable */ +// @ts-nocheck + +import { SayRequest, SayResponse } from "./eliza_pb.js"; +import { MethodKind } from "@bufbuild/protobuf"; + +/** + * Say is a unary RPC. Eliza responds to the prompt with a single sentence. + * + * @generated from rpc connectrpc.eliza.v1.ElizaService.Say + */ +export const say: { + readonly name: "Say"; + readonly I: typeof SayRequest; + readonly O: typeof SayResponse; + readonly kind: MethodKind.Unary; + readonly service: { + readonly typeName: "connectrpc.eliza.v1.ElizaService"; + }; +}; diff --git a/packages/protoc-gen-connect-query/snapshots/gen/connectrpc/eliza/v1/eliza-ElizaService_connectquery.js b/packages/protoc-gen-connect-query/snapshots/gen_js/connectrpc/eliza/v1/eliza-ElizaService_connectquery.js similarity index 86% rename from packages/protoc-gen-connect-query/snapshots/gen/connectrpc/eliza/v1/eliza-ElizaService_connectquery.js rename to packages/protoc-gen-connect-query/snapshots/gen_js/connectrpc/eliza/v1/eliza-ElizaService_connectquery.js index 26ea32b0..706a7ca2 100644 --- a/packages/protoc-gen-connect-query/snapshots/gen/connectrpc/eliza/v1/eliza-ElizaService_connectquery.js +++ b/packages/protoc-gen-connect-query/snapshots/gen_js/connectrpc/eliza/v1/eliza-ElizaService_connectquery.js @@ -12,12 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -// @generated by protoc-gen-connect-query v1.0.0 with parameter "target=ts+dts+js,import_extension=none,ts_nocheck=false" +// @generated by protoc-gen-connect-query v1.0.0 // @generated from file connectrpc/eliza/v1/eliza.proto (package connectrpc.eliza.v1, syntax proto3) /* eslint-disable */ +// @ts-nocheck import { MethodKind } from "@bufbuild/protobuf"; -import { SayRequest, SayResponse } from "./eliza_pb"; +import { SayRequest, SayResponse } from "./eliza_pb.js"; /** * Say is a unary RPC. Eliza responds to the prompt with a single sentence. diff --git a/packages/protoc-gen-connect-query/snapshots/gen_js/connectrpc/eliza/v1/eliza_pb.d.ts b/packages/protoc-gen-connect-query/snapshots/gen_js/connectrpc/eliza/v1/eliza_pb.d.ts new file mode 100644 index 00000000..01a14fe5 --- /dev/null +++ b/packages/protoc-gen-connect-query/snapshots/gen_js/connectrpc/eliza/v1/eliza_pb.d.ts @@ -0,0 +1,258 @@ +// Copyright 2021-2023 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. + +// @generated by protoc-gen-es v1.6.0 +// @generated from file connectrpc/eliza/v1/eliza.proto (package connectrpc.eliza.v1, syntax proto3) +/* eslint-disable */ +// @ts-nocheck + +import type { + BinaryReadOptions, + FieldList, + JsonReadOptions, + JsonValue, + PartialMessage, + PlainMessage, +} from "@bufbuild/protobuf"; +import { Message, proto3 } from "@bufbuild/protobuf"; + +/** + * SayRequest is a single-sentence request. + * + * @generated from message connectrpc.eliza.v1.SayRequest + */ +export declare class SayRequest extends Message { + /** + * @generated from field: string sentence = 1; + */ + sentence: string; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "connectrpc.eliza.v1.SayRequest"; + static readonly fields: FieldList; + + static fromBinary( + bytes: Uint8Array, + options?: Partial, + ): SayRequest; + + static fromJson( + jsonValue: JsonValue, + options?: Partial, + ): SayRequest; + + static fromJsonString( + jsonString: string, + options?: Partial, + ): SayRequest; + + static equals( + a: SayRequest | PlainMessage | undefined, + b: SayRequest | PlainMessage | undefined, + ): boolean; +} + +/** + * SayResponse is a single-sentence response. + * + * @generated from message connectrpc.eliza.v1.SayResponse + */ +export declare class SayResponse extends Message { + /** + * @generated from field: string sentence = 1; + */ + sentence: string; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "connectrpc.eliza.v1.SayResponse"; + static readonly fields: FieldList; + + static fromBinary( + bytes: Uint8Array, + options?: Partial, + ): SayResponse; + + static fromJson( + jsonValue: JsonValue, + options?: Partial, + ): SayResponse; + + static fromJsonString( + jsonString: string, + options?: Partial, + ): SayResponse; + + static equals( + a: SayResponse | PlainMessage | undefined, + b: SayResponse | PlainMessage | undefined, + ): boolean; +} + +/** + * ConverseRequest is a single sentence request sent as part of a + * back-and-forth conversation. + * + * @generated from message connectrpc.eliza.v1.ConverseRequest + */ +export declare class ConverseRequest extends Message { + /** + * @generated from field: string sentence = 1; + */ + sentence: string; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "connectrpc.eliza.v1.ConverseRequest"; + static readonly fields: FieldList; + + static fromBinary( + bytes: Uint8Array, + options?: Partial, + ): ConverseRequest; + + static fromJson( + jsonValue: JsonValue, + options?: Partial, + ): ConverseRequest; + + static fromJsonString( + jsonString: string, + options?: Partial, + ): ConverseRequest; + + static equals( + a: ConverseRequest | PlainMessage | undefined, + b: ConverseRequest | PlainMessage | undefined, + ): boolean; +} + +/** + * ConverseResponse is a single sentence response sent in answer to a + * ConverseRequest. + * + * @generated from message connectrpc.eliza.v1.ConverseResponse + */ +export declare class ConverseResponse extends Message { + /** + * @generated from field: string sentence = 1; + */ + sentence: string; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "connectrpc.eliza.v1.ConverseResponse"; + static readonly fields: FieldList; + + static fromBinary( + bytes: Uint8Array, + options?: Partial, + ): ConverseResponse; + + static fromJson( + jsonValue: JsonValue, + options?: Partial, + ): ConverseResponse; + + static fromJsonString( + jsonString: string, + options?: Partial, + ): ConverseResponse; + + static equals( + a: ConverseResponse | PlainMessage | undefined, + b: ConverseResponse | PlainMessage | undefined, + ): boolean; +} + +/** + * IntroduceRequest asks Eliza to introduce itself to the named user. + * + * @generated from message connectrpc.eliza.v1.IntroduceRequest + */ +export declare class IntroduceRequest extends Message { + /** + * @generated from field: string name = 1; + */ + name: string; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "connectrpc.eliza.v1.IntroduceRequest"; + static readonly fields: FieldList; + + static fromBinary( + bytes: Uint8Array, + options?: Partial, + ): IntroduceRequest; + + static fromJson( + jsonValue: JsonValue, + options?: Partial, + ): IntroduceRequest; + + static fromJsonString( + jsonString: string, + options?: Partial, + ): IntroduceRequest; + + static equals( + a: IntroduceRequest | PlainMessage | undefined, + b: IntroduceRequest | PlainMessage | undefined, + ): boolean; +} + +/** + * IntroduceResponse is one sentence of Eliza's introductory monologue. + * + * @generated from message connectrpc.eliza.v1.IntroduceResponse + */ +export declare class IntroduceResponse extends Message { + /** + * @generated from field: string sentence = 1; + */ + sentence: string; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "connectrpc.eliza.v1.IntroduceResponse"; + static readonly fields: FieldList; + + static fromBinary( + bytes: Uint8Array, + options?: Partial, + ): IntroduceResponse; + + static fromJson( + jsonValue: JsonValue, + options?: Partial, + ): IntroduceResponse; + + static fromJsonString( + jsonString: string, + options?: Partial, + ): IntroduceResponse; + + static equals( + a: IntroduceResponse | PlainMessage | undefined, + b: IntroduceResponse | PlainMessage | undefined, + ): boolean; +} diff --git a/packages/protoc-gen-connect-query/snapshots/gen_js/connectrpc/eliza/v1/eliza_pb.js b/packages/protoc-gen-connect-query/snapshots/gen_js/connectrpc/eliza/v1/eliza_pb.js new file mode 100644 index 00000000..99779ba3 --- /dev/null +++ b/packages/protoc-gen-connect-query/snapshots/gen_js/connectrpc/eliza/v1/eliza_pb.js @@ -0,0 +1,92 @@ +// Copyright 2021-2023 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. + +// @generated by protoc-gen-es v1.6.0 +// @generated from file connectrpc/eliza/v1/eliza.proto (package connectrpc.eliza.v1, syntax proto3) +/* eslint-disable */ +// @ts-nocheck + +import { proto3 } from "@bufbuild/protobuf"; + +/** + * SayRequest is a single-sentence request. + * + * @generated from message connectrpc.eliza.v1.SayRequest + */ +export const SayRequest = proto3.makeMessageType( + "connectrpc.eliza.v1.SayRequest", + () => [ + { no: 1, name: "sentence", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + ], +); + +/** + * SayResponse is a single-sentence response. + * + * @generated from message connectrpc.eliza.v1.SayResponse + */ +export const SayResponse = proto3.makeMessageType( + "connectrpc.eliza.v1.SayResponse", + () => [ + { no: 1, name: "sentence", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + ], +); + +/** + * ConverseRequest is a single sentence request sent as part of a + * back-and-forth conversation. + * + * @generated from message connectrpc.eliza.v1.ConverseRequest + */ +export const ConverseRequest = proto3.makeMessageType( + "connectrpc.eliza.v1.ConverseRequest", + () => [ + { no: 1, name: "sentence", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + ], +); + +/** + * ConverseResponse is a single sentence response sent in answer to a + * ConverseRequest. + * + * @generated from message connectrpc.eliza.v1.ConverseResponse + */ +export const ConverseResponse = proto3.makeMessageType( + "connectrpc.eliza.v1.ConverseResponse", + () => [ + { no: 1, name: "sentence", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + ], +); + +/** + * IntroduceRequest asks Eliza to introduce itself to the named user. + * + * @generated from message connectrpc.eliza.v1.IntroduceRequest + */ +export const IntroduceRequest = proto3.makeMessageType( + "connectrpc.eliza.v1.IntroduceRequest", + () => [{ no: 1, name: "name", kind: "scalar", T: 9 /* ScalarType.STRING */ }], +); + +/** + * IntroduceResponse is one sentence of Eliza's introductory monologue. + * + * @generated from message connectrpc.eliza.v1.IntroduceResponse + */ +export const IntroduceResponse = proto3.makeMessageType( + "connectrpc.eliza.v1.IntroduceResponse", + () => [ + { no: 1, name: "sentence", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + ], +); diff --git a/packages/protoc-gen-connect-query/snapshots/gen/connectrpc/eliza/v1/eliza-ElizaService_connectquery.ts b/packages/protoc-gen-connect-query/snapshots/gen_ts/connectrpc/eliza/v1/eliza-ElizaService_connectquery.ts similarity index 91% rename from packages/protoc-gen-connect-query/snapshots/gen/connectrpc/eliza/v1/eliza-ElizaService_connectquery.ts rename to packages/protoc-gen-connect-query/snapshots/gen_ts/connectrpc/eliza/v1/eliza-ElizaService_connectquery.ts index 001109fb..f6ea0628 100644 --- a/packages/protoc-gen-connect-query/snapshots/gen/connectrpc/eliza/v1/eliza-ElizaService_connectquery.ts +++ b/packages/protoc-gen-connect-query/snapshots/gen_ts/connectrpc/eliza/v1/eliza-ElizaService_connectquery.ts @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -// @generated by protoc-gen-connect-query v1.0.0 with parameter "target=ts+dts+js,import_extension=none,ts_nocheck=false" +// @generated by protoc-gen-connect-query v1.0.0 with parameter "target=ts,ts_nocheck=false" // @generated from file connectrpc/eliza/v1/eliza.proto (package connectrpc.eliza.v1, syntax proto3) /* eslint-disable */ import { MethodKind } from "@bufbuild/protobuf"; -import { SayRequest, SayResponse } from "./eliza_pb"; +import { SayRequest, SayResponse } from "./eliza_pb.js"; /** * Say is a unary RPC. Eliza responds to the prompt with a single sentence. diff --git a/packages/protoc-gen-connect-query/snapshots/gen/connectrpc/eliza/v1/eliza_pb.ts b/packages/protoc-gen-connect-query/snapshots/gen_ts/connectrpc/eliza/v1/eliza_pb.ts similarity index 100% rename from packages/protoc-gen-connect-query/snapshots/gen/connectrpc/eliza/v1/eliza_pb.ts rename to packages/protoc-gen-connect-query/snapshots/gen_ts/connectrpc/eliza/v1/eliza_pb.ts diff --git a/packages/protoc-gen-connect-query/src/generateDts.ts b/packages/protoc-gen-connect-query/src/generateDts.ts index 3694f75d..92038b3c 100644 --- a/packages/protoc-gen-connect-query/src/generateDts.ts +++ b/packages/protoc-gen-connect-query/src/generateDts.ts @@ -14,12 +14,8 @@ import type { DescFile, DescService } from "@bufbuild/protobuf"; import { codegenInfo, MethodIdempotency, MethodKind } from "@bufbuild/protobuf"; -import type { Schema } from "@bufbuild/protoplugin"; -import { - literalString, - localName, - makeJsDoc, -} from "@bufbuild/protoplugin/ecmascript"; +import type { Schema } from "@bufbuild/protoplugin/ecmascript"; +import { localName } from "@bufbuild/protoplugin/ecmascript"; import type { PluginInit } from "./utils.js"; @@ -43,22 +39,18 @@ const generateServiceFile = switch (method.methodKind) { case MethodKind.Unary: { - f.print(makeJsDoc(method)); - f.print( - `export const `, - safeIdentifier(localName(method)), - `: {` - ); - f.print(` readonly name: `, literalString(method.name), `,`); + f.print(f.jsDoc(method)); + f.print(f.exportDecl("const", safeIdentifier(localName(method))), ": {"); + 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], ","); if (method.idempotency !== undefined) { f.print(" readonly idempotency: ", rtMethodIdempotency, ".", MethodIdempotency[method.idempotency], ","); } - f.print(` readonly service: {`); - f.print(` readonly typeName: ${literalString(service.typeName)}`); - f.print(` }`); + f.print(" readonly service: {"); + f.print(" readonly typeName: ", f.string(service.typeName)); + f.print(" }"); f.print("};") } break; diff --git a/packages/protoc-gen-connect-query/src/generateTs.ts b/packages/protoc-gen-connect-query/src/generateTs.ts index aba5fb44..b28baeb3 100644 --- a/packages/protoc-gen-connect-query/src/generateTs.ts +++ b/packages/protoc-gen-connect-query/src/generateTs.ts @@ -14,12 +14,8 @@ import type { DescFile, DescService } from "@bufbuild/protobuf"; import { codegenInfo, MethodIdempotency, MethodKind } from "@bufbuild/protobuf"; -import type { Schema } from "@bufbuild/protoplugin"; -import { - literalString, - localName, - makeJsDoc, -} from "@bufbuild/protoplugin/ecmascript"; +import type { Schema } from "@bufbuild/protoplugin/ecmascript"; +import { localName } from "@bufbuild/protoplugin/ecmascript"; import type { PluginInit } from "./utils.js"; @@ -46,20 +42,20 @@ const generateServiceFile = service.methods .filter((method) => method.methodKind === MethodKind.Unary) .forEach((method, index, filteredMethods) => { - f.print(makeJsDoc(method)); - f.print(`export const ${safeIdentifier(localName(method))} = { `); - f.print(` localName: ${literalString(localName(method))},`); - f.print(` name: ${literalString(method.name)},`); - f.print(` kind: `, rtMethodKind, ".", MethodKind[method.methodKind], ","); - f.print(` I: `, method.input, `,`); - f.print(` O: `, method.output, `,`); + f.print(f.jsDoc(method)); + f.print(f.exportDecl("const", safeIdentifier(localName(method))), " = {"); + f.print(" localName: ",f.string(localName(method)), ","); + f.print(" name: ", f.string(method.name), ","); + f.print(" kind: ", rtMethodKind, ".", MethodKind[method.methodKind], ","); + f.print(" I: ", method.input, ","); + f.print(" O: ", method.output, ","); if (method.idempotency !== undefined) { f.print(" idempotency: ", rtMethodIdempotency, ".", MethodIdempotency[method.idempotency], ","); } - f.print(` service: {`); - f.print(` typeName: ${literalString(service.typeName)}`); - f.print(` }`); - f.print(`}`, isTs ? ` as const` : ``, `;`); + f.print(" service: {"); + f.print(" typeName: ", f.string(service.typeName)); + f.print(" }"); + f.print("}", isTs ? " as const" : "", ";"); const lastIndex = index === filteredMethods.length - 1; if (!lastIndex) {