ts-proto 2.0.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.markdown CHANGED
@@ -5,6 +5,26 @@
5
5
 
6
6
  > `ts-proto` transforms your `.proto` files into strongly-typed, idiomatic TypeScript files!
7
7
 
8
+ ## ts-proto 2.x Release Notes
9
+
10
+ The 2.x release of ts-proto migrated the low-level Protobuf serializing that its `encode` and `decode` method use from the venerable, but aging & stagnant, `protobufjs` package to `@bufbuild/protobuf`.
11
+
12
+ If you only used the `encode` and `decode` methods, this should largely be a non-breaking change.
13
+
14
+ However, if you used any code that used the old `protobufjs` `Writer` or `Reader` classes, you'll need to update your code to use the new `@bufbuild/protobuf` classes:
15
+
16
+ ```
17
+ import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
18
+ ```
19
+
20
+ If migrating to `@bufbuild/protobuf` is a blocker for you, you can pin your `ts-proto` version to `1.x`.
21
+
22
+ **Disclaimer & apology:** I had intended to release ts-proto 2.x as an alpha release, but didn't get the semantic-release config correct, and so ts-proto 2.x was published as a major release without a proper alpha/beta cycle.
23
+
24
+ If you could file reports (or better PRs!) for any issues you come across while the release is still fresh, that would be greatly appreciated.
25
+
26
+ Any tips or tricks for others on the migration would also be appreciated!
27
+
8
28
  ## Table of contents
9
29
 
10
30
  - [ts-proto](#ts-proto)
@@ -642,6 +662,11 @@ interface Rpc {
642
662
  If you're working with gRPC, a simple implementation could look like this:
643
663
 
644
664
  ```ts
665
+ const conn = new grpc.Client(
666
+ "localhost:8765",
667
+ grpc.credentials.createInsecure()
668
+ );
669
+
645
670
  type RpcImpl = (service: string, method: string, data: Uint8Array) => Promise<Uint8Array>;
646
671
 
647
672
  const sendRequest: RpcImpl = (service, method, data) => {
@@ -293,11 +293,17 @@ async function getVersions(request) {
293
293
  const { major, minor, patch } = request.compilerVersion;
294
294
  protocVersion = `v${major}.${minor}.${patch}`;
295
295
  }
296
- const path = "../package.json";
297
- const packageJson = await Promise.resolve(`${path}`).then(s => require(s));
296
+ const packageJson = await readPackageJson();
298
297
  const tsProtoVersion = `v${packageJson?.version ?? "unknown"}`;
299
- return {
300
- protocVersion,
301
- tsProtoVersion,
302
- };
298
+ return { protocVersion, tsProtoVersion };
299
+ }
300
+ /** Read from the distributed package.json file, or our local package.json when running ts-proto tests locally. */
301
+ async function readPackageJson() {
302
+ try {
303
+ // Use `as string` to disable hints that the path doesn't exist
304
+ return await Promise.resolve(`${"../../package.json"}`).then(s => require(s));
305
+ }
306
+ catch (e) {
307
+ return await Promise.resolve(`${"../package.json"}`).then(s => require(s));
308
+ }
303
309
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "",
5
5
  "main": "build/src/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",