ts-proto 1.121.1 → 1.121.4
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 +21 -0
- package/README.markdown +10 -2
- package/build/main.js +18 -12
- package/build/options.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## [1.121.4](https://github.com/stephenh/ts-proto/compare/v1.121.3...v1.121.4) (2022-08-07)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Performance Improvements
|
|
5
|
+
|
|
6
|
+
* Faster base64FromBytes & bytesFromBase64 on Node.JS ([#649](https://github.com/stephenh/ts-proto/issues/649)) ([82ab341](https://github.com/stephenh/ts-proto/commit/82ab341557fba1a4933c4613d5c20dbf897905fa))
|
|
7
|
+
|
|
8
|
+
## [1.121.3](https://github.com/stephenh/ts-proto/compare/v1.121.2...v1.121.3) (2022-08-06)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* Use underscore separator in snakeToCamel. ([#648](https://github.com/stephenh/ts-proto/issues/648)) ([b374910](https://github.com/stephenh/ts-proto/commit/b374910a8fb1d0efe6c5c5322f8788cc3cc1ca6c))
|
|
14
|
+
|
|
15
|
+
## [1.121.2](https://github.com/stephenh/ts-proto/compare/v1.121.1...v1.121.2) (2022-08-06)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* Fix push_to_buf_registry check. ([22ac914](https://github.com/stephenh/ts-proto/commit/22ac914cd8626258ceb35fd435b899a819518988))
|
|
21
|
+
|
|
1
22
|
## [1.121.1](https://github.com/stephenh/ts-proto/compare/v1.121.0...v1.121.1) (2022-07-28)
|
|
2
23
|
|
|
3
24
|
|
package/README.markdown
CHANGED
|
@@ -339,7 +339,15 @@ Generated code will be placed in the Gradle build directory.
|
|
|
339
339
|
|
|
340
340
|
- With `--ts_proto_opt=lowerCaseServiceMethods=true`, the method names of service methods will be lowered/camel-case, i.e. `service.findFoo` instead of `service.FindFoo`.
|
|
341
341
|
|
|
342
|
-
- With `--ts_proto_opt=snakeToCamel=false`, fields will be kept snake case
|
|
342
|
+
- With `--ts_proto_opt=snakeToCamel=false`, fields will be kept snake case in both the message keys and the `toJSON` / `fromJSON` methods.
|
|
343
|
+
|
|
344
|
+
`snakeToCamel` can also be set as a `_`-delimited list of strings (comma is reserved as the flag delimited), i.e. `--ts_proto_opt=snakeToCamel=keys_json`, where including `keys` will make message keys be camel case and including `json` will make JSON keys be camel case.
|
|
345
|
+
|
|
346
|
+
Empty string, i.e. `snakeToCamel=`, will keep both messages keys and `JSON` keys as snake case (it is the same as `snakeToCamel=false`).
|
|
347
|
+
|
|
348
|
+
Note that to use the `json_name` attribute, you'll have to use the `json`.
|
|
349
|
+
|
|
350
|
+
The default behavior is `keys_json`, i.e. both will be camel cased, and `json_name` will be used if set.
|
|
343
351
|
|
|
344
352
|
- With `--ts_proto_opt=outputEncodeMethods=false`, the `Message.encode` and `Message.decode` methods for working with protobuf-encoded/binary data will not be output.
|
|
345
353
|
|
|
@@ -435,7 +443,7 @@ Generated code will be placed in the Gradle build directory.
|
|
|
435
443
|
Requires `onlyTypes=true`. Implies `useDate=string` and `stringEnums=true`. This option is to generate types that can be directly used with marshalling/unmarshalling Protobuf messages serialized as JSON.
|
|
436
444
|
You may also want to set `useOptionals=all`, as gRPC gateways are not required to send default value for scalar values.
|
|
437
445
|
|
|
438
|
-
- With
|
|
446
|
+
- With `--ts_proto_opt=useNumericEnumForJson=true`, the JSON converter (`toJSON`) will encode enum values as int, rather than a string literal.
|
|
439
447
|
|
|
440
448
|
### NestJS Support
|
|
441
449
|
|
package/build/main.js
CHANGED
|
@@ -290,24 +290,30 @@ function makeByteUtils() {
|
|
|
290
290
|
})();
|
|
291
291
|
`);
|
|
292
292
|
const bytesFromBase64 = (0, ts_poet_1.conditionalOutput)('bytesFromBase64', (0, ts_poet_1.code) `
|
|
293
|
-
const atob: (b64: string) => string = ${globalThis}.atob || ((b64) => ${globalThis}.Buffer.from(b64, 'base64').toString('binary'));
|
|
294
293
|
function bytesFromBase64(b64: string): Uint8Array {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
294
|
+
if (${globalThis}.Buffer) {
|
|
295
|
+
return Uint8Array.from(${globalThis}.Buffer.from(b64, 'base64'));
|
|
296
|
+
} else {
|
|
297
|
+
const bin = ${globalThis}.atob(b64);
|
|
298
|
+
const arr = new Uint8Array(bin.length);
|
|
299
|
+
for (let i = 0; i < bin.length; ++i) {
|
|
300
|
+
arr[i] = bin.charCodeAt(i);
|
|
301
|
+
}
|
|
302
|
+
return arr;
|
|
299
303
|
}
|
|
300
|
-
return arr;
|
|
301
304
|
}
|
|
302
305
|
`);
|
|
303
306
|
const base64FromBytes = (0, ts_poet_1.conditionalOutput)('base64FromBytes', (0, ts_poet_1.code) `
|
|
304
|
-
const btoa : (bin: string) => string = ${globalThis}.btoa || ((bin) => ${globalThis}.Buffer.from(bin, 'binary').toString('base64'));
|
|
305
307
|
function base64FromBytes(arr: Uint8Array): string {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
308
|
+
if (${globalThis}.Buffer) {
|
|
309
|
+
return ${globalThis}.Buffer.from(arr).toString('base64')
|
|
310
|
+
} else {
|
|
311
|
+
const bin: string[] = [];
|
|
312
|
+
arr.forEach((byte) => {
|
|
313
|
+
bin.push(String.fromCharCode(byte));
|
|
314
|
+
});
|
|
315
|
+
return ${globalThis}.btoa(bin.join(''));
|
|
316
|
+
}
|
|
311
317
|
}
|
|
312
318
|
`);
|
|
313
319
|
return { globalThis, bytesFromBase64, base64FromBytes };
|
package/build/options.js
CHANGED
|
@@ -134,7 +134,7 @@ function optionsFromParameter(parameter) {
|
|
|
134
134
|
options.snakeToCamel = ['keys', 'json'];
|
|
135
135
|
}
|
|
136
136
|
else if (typeof options.snakeToCamel === 'string') {
|
|
137
|
-
options.snakeToCamel =
|
|
137
|
+
options.snakeToCamel = options.snakeToCamel.split('_');
|
|
138
138
|
}
|
|
139
139
|
if (options.useJsonWireFormat) {
|
|
140
140
|
if (!options.onlyTypes) {
|