ts-proto 1.127.0 → 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,10 @@
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
+
1
8
  # [1.127.0](https://github.com/stephenh/ts-proto/compare/v1.126.1...v1.127.0) (2022-10-12)
2
9
 
3
10
 
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.127.0",
3
+ "version": "1.128.0",
4
4
  "description": "",
5
5
  "main": "build/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",