@connectrpc/protoc-gen-connect-query
Advanced tools
Comparing version 2.0.0-beta.3 to 2.0.0-rc.1
{ | ||
"name": "@connectrpc/protoc-gen-connect-query", | ||
"version": "2.0.0-beta.3", | ||
"version": "2.0.0-rc.1", | ||
"description": "Code generator for connect-query", | ||
@@ -25,3 +25,3 @@ "license": "Apache-2.0", | ||
"format": "prettier . --write --ignore-path ./.eslintignore && eslint . --fix && license-header", | ||
"generate": "cd snapshots && buf generate", | ||
"generate": "rm -rf snapshots/gen* && cd snapshots && buf generate buf.build/connectrpc/eliza:8b8b971d6fde4dc8ba5d96f9fda7d53c", | ||
"test": "tsc --declaration --declarationDir .type-dump --emitDeclarationOnly" | ||
@@ -32,5 +32,6 @@ }, | ||
"@bufbuild/buf": "1.43.0", | ||
"@bufbuild/protoc-gen-es": "^2.2.0", | ||
"@connectrpc/connect": "^2.0.0-beta.2", | ||
"@bufbuild/protoc-gen-es": "^1.10.0", | ||
"@connectrpc/connect": "^1.5.0", | ||
"@connectrpc/connect-query": "workspace:*", | ||
"@connectrpc/protoc-gen-connect-es": "^1.5.0", | ||
"@tanstack/react-query": "^5.56.2", | ||
@@ -40,7 +41,7 @@ "typescript": "^5.5.4" | ||
"dependencies": { | ||
"@bufbuild/protobuf": "^2.2.0", | ||
"@bufbuild/protoplugin": "^2.2.0" | ||
"@bufbuild/protobuf": "^1.10.0", | ||
"@bufbuild/protoplugin": "^1.10.0" | ||
}, | ||
"peerDependencies": { | ||
"@bufbuild/protoc-gen-es": "2.x" | ||
"@bufbuild/protoc-gen-es": "1.x" | ||
}, | ||
@@ -47,0 +48,0 @@ "peerDependenciesMeta": { |
@@ -17,3 +17,5 @@ "use strict"; | ||
exports.generateDts = void 0; | ||
const protoplugin_1 = require("@bufbuild/protoplugin"); | ||
const protobuf_1 = require("@bufbuild/protobuf"); | ||
const ecmascript_1 = require("@bufbuild/protoplugin/ecmascript"); | ||
const { safeIdentifier } = protobuf_1.codegenInfo; | ||
// prettier-ignore | ||
@@ -24,10 +26,22 @@ /** | ||
const generateServiceFile = (schema, protoFile) => (service) => { | ||
const f = schema.generateFile(`${protoFile.name}-${service.name}_connectquery.d.ts`); | ||
const { MethodKind: rtMethodKind, MethodIdempotency: rtMethodIdempotency } = schema.runtime; | ||
const f = schema.generateFile(`${protoFile.name}-${(0, ecmascript_1.localName)(service)}_connectquery.d.ts`); | ||
f.preamble(protoFile); | ||
service.methods.forEach((method) => { | ||
switch (method.methodKind) { | ||
case "unary": | ||
case protobuf_1.MethodKind.Unary: | ||
{ | ||
f.print(f.jsDoc(method)); | ||
f.print(f.export("const", (0, protoplugin_1.safeIdentifier)(method.localName)), ": typeof ", f.importSchema(service), '["method"]["', method.localName, '"];'); | ||
f.print(f.exportDecl("const", safeIdentifier((0, ecmascript_1.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, ".", protobuf_1.MethodKind[method.methodKind], ","); | ||
if (method.idempotency !== undefined) { | ||
f.print(" readonly idempotency: ", rtMethodIdempotency, ".", protobuf_1.MethodIdempotency[method.idempotency], ","); | ||
} | ||
f.print(" readonly service: {"); | ||
f.print(" readonly typeName: ", f.string(service.typeName)); | ||
f.print(" }"); | ||
f.print("};"); | ||
} | ||
@@ -34,0 +48,0 @@ break; |
@@ -17,3 +17,5 @@ "use strict"; | ||
exports.generateTs = void 0; | ||
const protoplugin_1 = require("@bufbuild/protoplugin"); | ||
const protobuf_1 = require("@bufbuild/protobuf"); | ||
const ecmascript_1 = require("@bufbuild/protoplugin/ecmascript"); | ||
const { safeIdentifier } = protobuf_1.codegenInfo; | ||
// prettier-ignore | ||
@@ -26,9 +28,23 @@ /** | ||
const generateServiceFile = (schema, protoFile, extension) => (service) => { | ||
const f = schema.generateFile(`${protoFile.name}-${service.name}_connectquery.${extension}`); | ||
const isTs = extension === "ts"; | ||
const f = schema.generateFile(`${protoFile.name}-${(0, ecmascript_1.localName)(service)}_connectquery.${extension}`); | ||
f.preamble(protoFile); | ||
const { MethodKind: rtMethodKind, MethodIdempotency: rtMethodIdempotency } = schema.runtime; | ||
service.methods | ||
.filter((method) => method.methodKind === "unary") | ||
.filter((method) => method.methodKind === protobuf_1.MethodKind.Unary) | ||
.forEach((method, index, filteredMethods) => { | ||
f.print(f.jsDoc(method)); | ||
f.print(f.export("const", (0, protoplugin_1.safeIdentifier)(method.localName)), " = ", f.importSchema(service), ".method.", method.localName, ";"); | ||
f.print(f.exportDecl("const", safeIdentifier((0, ecmascript_1.localName)(method))), " = {"); | ||
f.print(" localName: ", f.string((0, ecmascript_1.localName)(method)), ","); | ||
f.print(" name: ", f.string(method.name), ","); | ||
f.print(" kind: ", rtMethodKind, ".", protobuf_1.MethodKind[method.methodKind], ","); | ||
f.print(" I: ", method.input, ","); | ||
f.print(" O: ", method.output, ","); | ||
if (method.idempotency !== undefined) { | ||
f.print(" idempotency: ", rtMethodIdempotency, ".", protobuf_1.MethodIdempotency[method.idempotency], ","); | ||
} | ||
f.print(" service: {"); | ||
f.print(" typeName: ", f.string(service.typeName)); | ||
f.print(" }"); | ||
f.print("}", isTs ? " as const" : "", ";"); | ||
const lastIndex = index === filteredMethods.length - 1; | ||
@@ -35,0 +51,0 @@ if (!lastIndex) { |
{ | ||
"name": "@connectrpc/protoc-gen-connect-query", | ||
"version": "2.0.0-beta.3", | ||
"version": "2.0.0-rc.1", | ||
"description": "Code generator for connect-query", | ||
@@ -24,14 +24,15 @@ "license": "Apache-2.0", | ||
"@bufbuild/buf": "1.43.0", | ||
"@bufbuild/protoc-gen-es": "^2.2.0", | ||
"@connectrpc/connect": "^2.0.0-beta.2", | ||
"@bufbuild/protoc-gen-es": "^1.10.0", | ||
"@connectrpc/connect": "^1.5.0", | ||
"@connectrpc/protoc-gen-connect-es": "^1.5.0", | ||
"@tanstack/react-query": "^5.56.2", | ||
"typescript": "^5.5.4", | ||
"@connectrpc/connect-query": "2.0.0-beta.3" | ||
"@connectrpc/connect-query": "2.0.0-rc.1" | ||
}, | ||
"dependencies": { | ||
"@bufbuild/protobuf": "^2.2.0", | ||
"@bufbuild/protoplugin": "^2.2.0" | ||
"@bufbuild/protobuf": "^1.10.0", | ||
"@bufbuild/protoplugin": "^1.10.0" | ||
}, | ||
"peerDependencies": { | ||
"@bufbuild/protoc-gen-es": "2.x" | ||
"@bufbuild/protoc-gen-es": "1.x" | ||
}, | ||
@@ -47,5 +48,5 @@ "peerDependenciesMeta": { | ||
"format": "prettier . --write --ignore-path ./.eslintignore && eslint . --fix && license-header", | ||
"generate": "cd snapshots && buf generate", | ||
"generate": "rm -rf snapshots/gen* && cd snapshots && buf generate buf.build/connectrpc/eliza:8b8b971d6fde4dc8ba5d96f9fda7d53c", | ||
"test": "tsc --declaration --declarationDir .type-dump --emitDeclarationOnly" | ||
} | ||
} |
@@ -14,6 +14,6 @@ # @connectrpc/protoc-gen-connect-query | ||
- [`target`](#target) | ||
- [`import_extension`](#import_extension) | ||
- [`import_extension=.js`](#import_extensionjs) | ||
- [`keep_empty_files=true`](#keep_empty_filestrue) | ||
- [`js_import_style`](#js_import_style) | ||
- [`ts_nocheck=true`](#ts_nochecktrue) | ||
- [`ts_nocheck=false`](#ts_nocheckfalse) | ||
- [Example Generated Code](#example-generated-code) | ||
@@ -78,10 +78,10 @@ | ||
```yaml | ||
version: v2 | ||
version: v1 | ||
plugins: | ||
# This will invoke protoc-gen-es and write output to src/gen | ||
- local: protoc-gen-es | ||
- name: es | ||
out: src/gen | ||
opt: target=ts | ||
# This will invoke protoc-gen-connect-query | ||
- local: protoc-gen-connect-query | ||
- name: connect-query | ||
out: src/gen | ||
@@ -128,3 +128,3 @@ opt: target=ts | ||
... | ||
"buf:generate": "buf generate" | ||
"buf:generate": "npx @bufbuild/buf generate example.proto" | ||
}, | ||
@@ -191,10 +191,13 @@ ``` | ||
### `import_extension` | ||
### `import_extension=.js` | ||
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)) doesn't add file extensions to import paths. However, some environments require an import extension. For example, using ECMAScript modules in Node.js requires the `.js` extension, and Deno requires `.ts`. With this plugin option, you can add `.js`/`.ts` extensions in import paths with the given value. Possible values: | ||
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)) uses a `.js` file extensions in import paths, even in TypeScript files. | ||
- `import_extension=none`: Doesn't add an extension. (Default) | ||
- `import_extension=js`: Adds the `.js` extension. | ||
- `import_extension=ts`. Adds the `.ts` extension. | ||
This is unintuitive, but necessary for [ECMAScript modules in Node.js](https://www.typescriptlang.org/docs/handbook/esm-node.html). | ||
Unfortunately, not all bundlers and tools have caught up yet, and Deno requires `.ts`. With this plugin option, you can replace `.js` extensions in import paths with the given value. For example, set | ||
- `import_extension=none` to remove the `.js` extension | ||
- `import_extension=.ts` to replace the `.js` extension with `.ts` | ||
### `js_import_style` | ||
@@ -218,8 +221,15 @@ | ||
### `ts_nocheck=true` | ||
### `ts_nocheck=false` | ||
[protoc-gen-connect-query](https://www.npmjs.com/package/@connectrpc/protoc-gen-connect-query) generates valid TypeScript for current versions of the TypeScript compiler with standard settings. If you use compiler settings that yield an error for generated code, setting this option generates an annotation at the top of each file to skip type checks: `// @ts-nocheck`. | ||
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 an annotation at the top of each file: `// @ts-nocheck`. | ||
We generate the annotation to support a wide range of compiler configurations and | ||
future changes to the language. But there can be situations where the annotation | ||
shadows an underlying problem, for example an unresolvable import. To remove | ||
the annotation and to enable type checks, set the plugin option `ts_nocheck=false`. | ||
## 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. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38554
181
231
7
+ Added@bufbuild/protobuf@1.10.0(transitive)
+ Added@bufbuild/protoc-gen-es@1.10.0(transitive)
+ Added@bufbuild/protoplugin@1.10.0(transitive)
+ Addedtypescript@4.5.2(transitive)
- Removed@bufbuild/protobuf@2.2.3(transitive)
- Removed@bufbuild/protoc-gen-es@2.2.3(transitive)
- Removed@bufbuild/protoplugin@2.2.3(transitive)
- Removedtypescript@5.4.5(transitive)
Updated@bufbuild/protobuf@^1.10.0