ts-proto 2.11.10 → 2.12.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/README.markdown +2 -2
- package/build/src/main.js +9 -2
- package/package.json +1 -1
package/README.markdown
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
## ts-proto 2.x Release Notes
|
|
9
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
|
|
10
|
+
The 2.x release of ts-proto migrated the low-level Protobuf serializing that its `encode` and `decode` method use from the venerable `protobufjs` package to `@bufbuild/protobuf`.
|
|
11
11
|
|
|
12
12
|
If you only used the `encode` and `decode` methods, this should largely be a non-breaking change.
|
|
13
13
|
|
|
@@ -321,7 +321,7 @@ Generated code will be placed in the Gradle build directory.
|
|
|
321
321
|
|
|
322
322
|
With `--ts_proto_opt=forceLong=string`, all 64-bit numbers will be output as strings.
|
|
323
323
|
|
|
324
|
-
With `--ts_proto_opt=forceLong=bigint`, all 64-bit numbers will be output as `BigInt`s. This option still uses the `long` library to encode/decode internally within `protobuf.js`, but then converts to/from `BigInt`s in the ts-proto-generated code.
|
|
324
|
+
With `--ts_proto_opt=forceLong=bigint`, all 64-bit numbers will be output as `BigInt`s. This option still uses the `long` library to encode/decode internally within `protobuf.js`, but then converts to/from `BigInt`s in the ts-proto-generated code. As with `forceLong=long`, `DeepPartial` widens 64-bit fields to `string | number | bigint`, and `fromPartial`/`create` coerce those inputs to `BigInt` (matching what `fromJSON` already does), so you can pass a string or number and get a `BigInt` back.
|
|
325
325
|
|
|
326
326
|
The default behavior is `forceLong=number`, which will internally still use the `long` library to encode/decode values on the wire (so you will still see a `util.Long = Long` line in your output), but will convert the `long` values to `number` automatically for you. Note that a runtime error is thrown if, while doing this conversion, a 64-bit value is larger than can be correctly stored as a `number`.
|
|
327
327
|
|
package/build/src/main.js
CHANGED
|
@@ -492,6 +492,8 @@ function makeDeepPartial(options, longs) {
|
|
|
492
492
|
const maybeExport = options.exportCommonSymbols ? "export" : "";
|
|
493
493
|
// Allow passing longs as numbers or strings, nad we'll convert them
|
|
494
494
|
const maybeLong = options.forceLong === options_1.LongOption.LONG ? (0, ts_poet_1.code) ` : T extends ${longs.Long} ? string | number | Long ` : "";
|
|
495
|
+
// Allow passing bigints as numbers or strings; fromPartial coerces them via BigInt()
|
|
496
|
+
const maybeBigInt = options.forceLong === options_1.LongOption.BIGINT ? (0, ts_poet_1.code) `T extends bigint ? string | number | bigint : ` : "";
|
|
495
497
|
const optionalBuiltins = [];
|
|
496
498
|
if (options.forceLong === options_1.LongOption.BIGINT) {
|
|
497
499
|
optionalBuiltins.push("bigint");
|
|
@@ -512,7 +514,7 @@ function makeDeepPartial(options, longs) {
|
|
|
512
514
|
// Based on the type from ts-essentials
|
|
513
515
|
const keys = (0, options_1.addTypeToMessages)(options) ? (0, ts_poet_1.code) `Exclude<keyof T, '$type'>` : (0, ts_poet_1.code) `keyof T`;
|
|
514
516
|
const DeepPartial = (0, ts_poet_1.conditionalOutput)("DeepPartial", (0, ts_poet_1.code) `
|
|
515
|
-
${maybeExport} type DeepPartial<T> =
|
|
517
|
+
${maybeExport} type DeepPartial<T> = ${maybeBigInt} T extends ${Builtin}
|
|
516
518
|
? T
|
|
517
519
|
${maybeLong}
|
|
518
520
|
: T extends globalThis.Array<infer U>
|
|
@@ -720,7 +722,7 @@ function makeTimestampMethods(options, longs, bytes) {
|
|
|
720
722
|
const seconds = ${seconds};
|
|
721
723
|
const remainder = instant.round({ smallestUnit: "seconds", roundingMode: "floor" }).until(instant);
|
|
722
724
|
const nanos = (remainder.milliseconds * 1_000_000) + (remainder.microseconds * 1_000) + remainder.nanoseconds;
|
|
723
|
-
|
|
725
|
+
|
|
724
726
|
return { ${maybeTypeField} seconds, nanos };
|
|
725
727
|
}
|
|
726
728
|
`
|
|
@@ -2443,6 +2445,11 @@ function generateFromPartial(ctx, fullName, messageDesc) {
|
|
|
2443
2445
|
!(0, types_1.isJsTypeFieldOption)(options, field)) {
|
|
2444
2446
|
return (0, ts_poet_1.code) `Long.fromValue(${from})`;
|
|
2445
2447
|
}
|
|
2448
|
+
else if (((0, types_1.isLong)(field) || (0, types_1.isLongValueType)(field)) &&
|
|
2449
|
+
options.forceLong === options_1.LongOption.BIGINT &&
|
|
2450
|
+
!(0, types_1.isJsTypeFieldOption)(options, field)) {
|
|
2451
|
+
return (0, ts_poet_1.code) `BigInt(${from})`;
|
|
2452
|
+
}
|
|
2446
2453
|
else if ((0, types_1.isObjectId)(field) && options.useMongoObjectId) {
|
|
2447
2454
|
return (0, ts_poet_1.code) `${from} as mongodb.ObjectId`;
|
|
2448
2455
|
}
|