ts-proto 1.126.1 → 1.128.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ # [1.128.0](https://github.com/stephenh/ts-proto/compare/v1.127.0...v1.128.0) (2022-10-13)
2
+
3
+
4
+ ### Features
5
+
6
+ * added nestJsTimestampTypeWrapper ([#567](https://github.com/stephenh/ts-proto/issues/567)) ([59d451e](https://github.com/stephenh/ts-proto/commit/59d451e2857856ff54a3afe03ae115a1824df66f))
7
+
8
+ # [1.127.0](https://github.com/stephenh/ts-proto/compare/v1.126.1...v1.127.0) (2022-10-12)
9
+
10
+
11
+ ### Features
12
+
13
+ * **client:** allow overriding the service identifier ([#683](https://github.com/stephenh/ts-proto/issues/683)) ([10c7c99](https://github.com/stephenh/ts-proto/commit/10c7c99b1f43705d640ab1e602a7c1799e31ac08))
14
+ * Import CallContext and CallOptions as type ([#684](https://github.com/stephenh/ts-proto/issues/684)) ([8b388f6](https://github.com/stephenh/ts-proto/commit/8b388f6c9f57dac34ca5836a4313d8247bb0fceb)), closes [#677](https://github.com/stephenh/ts-proto/issues/677)
15
+
1
16
  ## [1.126.1](https://github.com/stephenh/ts-proto/compare/v1.126.0...v1.126.1) (2022-09-21)
2
17
 
3
18
 
package/README.markdown CHANGED
@@ -562,7 +562,7 @@ The commands below assume you have **Docker** installed. To use a **local** copy
562
562
  **Contributing**
563
563
 
564
564
  - Run `yarn build:test` and `yarn test` to make sure everything works.
565
- - Run `yarn prettier` to format the typescript files.
565
+ - Run `yarn format` to format the typescript files.
566
566
  - Commit the changes:
567
567
  - Also include the generated `.bin` files for the tests where you added or modified `.proto` files.
568
568
  > These are checked into git so that the test suite can run without having to invoke the `protoc` build chain.
@@ -6,8 +6,8 @@ const case_1 = require("./case");
6
6
  const sourceInfo_1 = require("./sourceInfo");
7
7
  const types_1 = require("./types");
8
8
  const utils_1 = require("./utils");
9
- const CallOptions = (0, ts_poet_1.imp)("CallOptions@nice-grpc-common");
10
- const CallContext = (0, ts_poet_1.imp)("CallContext@nice-grpc-common");
9
+ const CallOptions = (0, ts_poet_1.imp)("t:CallOptions@nice-grpc-common");
10
+ const CallContext = (0, ts_poet_1.imp)("t:CallContext@nice-grpc-common");
11
11
  /**
12
12
  * Generates server / client stubs for `nice-grpc` library.
13
13
  */
@@ -129,7 +129,7 @@ function generateRegularRpcMethod(ctx, fileDesc, serviceDesc, methodDesc) {
129
129
  const data = ${encode};
130
130
  const ${returnVariable} = this.rpc.${rpcMethod}(
131
131
  ${maybeCtx}
132
- "${(0, utils_1.maybePrefixPackage)(fileDesc, serviceDesc.name)}",
132
+ this.service,
133
133
  "${methodDesc.name}",
134
134
  data
135
135
  );
@@ -148,7 +148,10 @@ function generateServiceClientImpl(ctx, fileDesc, serviceDesc) {
148
148
  // Create the constructor(rpc: Rpc)
149
149
  const rpcType = options.context ? "Rpc<Context>" : "Rpc";
150
150
  chunks.push((0, ts_poet_1.code) `private readonly rpc: ${rpcType};`);
151
- chunks.push((0, ts_poet_1.code) `constructor(rpc: ${rpcType}) {`);
151
+ chunks.push((0, ts_poet_1.code) `private readonly service: string;`);
152
+ chunks.push((0, ts_poet_1.code) `constructor(rpc: ${rpcType}, opts?: {service?: string}) {`);
153
+ const serviceID = (0, utils_1.maybePrefixPackage)(fileDesc, serviceDesc.name);
154
+ chunks.push((0, ts_poet_1.code) `this.service = opts?.service || "${serviceID}";`);
152
155
  chunks.push((0, ts_poet_1.code) `this.rpc = rpc;`);
153
156
  // Bind each FooService method to the FooServiceImpl class
154
157
  for (const methodDesc of serviceDesc.method) {
package/build/main.js CHANGED
@@ -67,6 +67,10 @@ function generateFile(ctx, fileDesc) {
67
67
  if (options.nestJs) {
68
68
  const prefix = (0, case_1.camelToSnake)(fileDesc.package.replace(/\./g, "_"));
69
69
  chunks.push((0, ts_poet_1.code) `export const ${prefix}_PACKAGE_NAME = '${fileDesc.package}';`);
70
+ if (options.useDate === options_1.DateOption.DATE &&
71
+ fileDesc.messageType.find((message) => message.field.find((field) => field.typeName === ".google.protobuf.Timestamp"))) {
72
+ chunks.push(makeProtobufTimestampWrapper());
73
+ }
70
74
  }
71
75
  if (options.outputEncodeMethods || options.outputJsonMethods || options.outputTypeRegistry) {
72
76
  // then add the encoder/decoder/base instance
@@ -225,6 +229,21 @@ function makeUtils(options) {
225
229
  };
226
230
  }
227
231
  exports.makeUtils = makeUtils;
232
+ function makeProtobufTimestampWrapper() {
233
+ const wrappers = (0, ts_poet_1.imp)("wrappers@protobufjs");
234
+ return (0, ts_poet_1.code) `
235
+ ${wrappers}['.google.protobuf.Timestamp'] = {
236
+ fromObject(value: Date) {
237
+ return {
238
+ seconds: value.getTime() / 1000,
239
+ nanos: (value.getTime() % 1000) * 1e6,
240
+ };
241
+ },
242
+ toObject(message: { seconds: number; nanos: number }) {
243
+ return new Date(message.seconds * 1000 + message.nanos / 1e6);
244
+ },
245
+ } as any;`;
246
+ }
228
247
  function makeLongUtils(options, bytes) {
229
248
  // Regardless of which `forceLong` config option we're using, we always use
230
249
  // the `long` library to either represent or at least sanity-check 64-bit values
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "1.126.1",
3
+ "version": "1.128.0",
4
4
  "description": "",
5
5
  "main": "build/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",