ts-proto 1.121.2 → 1.121.5
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 +22 -0
- package/README.markdown +9 -1
- package/build/generate-services.js +2 -2
- package/build/main.js +19 -13
- package/build/options.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
## [1.121.5](https://github.com/stephenh/ts-proto/compare/v1.121.4...v1.121.5) (2022-08-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* remove Record word conflict ([#638](https://github.com/stephenh/ts-proto/issues/638)) ([5664d09](https://github.com/stephenh/ts-proto/commit/5664d097ac33da423b0f4e79f962fd71912358a0))
|
|
7
|
+
* resolve import collisions for services ([#651](https://github.com/stephenh/ts-proto/issues/651)) ([ee0296f](https://github.com/stephenh/ts-proto/commit/ee0296ffe087665b54bac714e964e7243010fb22))
|
|
8
|
+
|
|
9
|
+
## [1.121.4](https://github.com/stephenh/ts-proto/compare/v1.121.3...v1.121.4) (2022-08-07)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Performance Improvements
|
|
13
|
+
|
|
14
|
+
* Faster base64FromBytes & bytesFromBase64 on Node.JS ([#649](https://github.com/stephenh/ts-proto/issues/649)) ([82ab341](https://github.com/stephenh/ts-proto/commit/82ab341557fba1a4933c4613d5c20dbf897905fa))
|
|
15
|
+
|
|
16
|
+
## [1.121.3](https://github.com/stephenh/ts-proto/compare/v1.121.2...v1.121.3) (2022-08-06)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
* Use underscore separator in snakeToCamel. ([#648](https://github.com/stephenh/ts-proto/issues/648)) ([b374910](https://github.com/stephenh/ts-proto/commit/b374910a8fb1d0efe6c5c5322f8788cc3cc1ca6c))
|
|
22
|
+
|
|
1
23
|
## [1.121.2](https://github.com/stephenh/ts-proto/compare/v1.121.1...v1.121.2) (2022-08-06)
|
|
2
24
|
|
|
3
25
|
|
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
|
|
|
@@ -24,7 +24,7 @@ function generateService(ctx, fileDesc, sourceInfo, serviceDesc) {
|
|
|
24
24
|
const chunks = [];
|
|
25
25
|
(0, utils_1.maybeAddComment)(sourceInfo, chunks, (_a = serviceDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
26
26
|
const maybeTypeVar = options.context ? `<${main_1.contextTypeVar}>` : '';
|
|
27
|
-
chunks.push((0, ts_poet_1.code) `export interface ${serviceDesc.name}${maybeTypeVar} {`);
|
|
27
|
+
chunks.push((0, ts_poet_1.code) `export interface ${(0, ts_poet_1.def)(serviceDesc.name)}${maybeTypeVar} {`);
|
|
28
28
|
serviceDesc.method.forEach((methodDesc, index) => {
|
|
29
29
|
var _a;
|
|
30
30
|
(0, utils_1.assertInstanceOf)(methodDesc, utils_1.FormattedMethodDescriptor);
|
|
@@ -144,7 +144,7 @@ function generateServiceClientImpl(ctx, fileDesc, serviceDesc) {
|
|
|
144
144
|
const { name } = serviceDesc;
|
|
145
145
|
const i = options.context ? `${name}<Context>` : name;
|
|
146
146
|
const t = options.context ? `<${main_1.contextTypeVar}>` : '';
|
|
147
|
-
chunks.push((0, ts_poet_1.code) `export class ${name}ClientImpl${t} implements ${i} {`);
|
|
147
|
+
chunks.push((0, ts_poet_1.code) `export class ${name}ClientImpl${t} implements ${(0, ts_poet_1.def)(i)} {`);
|
|
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};`);
|
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 };
|
|
@@ -331,7 +337,7 @@ function makeDeepPartial(options, longs) {
|
|
|
331
337
|
${maybeExport} type Exact<P, I extends P> = P extends ${Builtin}
|
|
332
338
|
? P
|
|
333
339
|
: P &
|
|
334
|
-
{ [K in keyof P]: Exact<P[K], I[K]> } &
|
|
340
|
+
{ [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P> ${maybeExcludeType}>]: never };
|
|
335
341
|
`);
|
|
336
342
|
// Based on the type from ts-essentials
|
|
337
343
|
const keys = options.outputTypeRegistry ? (0, ts_poet_1.code) `Exclude<keyof T, '$type'>` : (0, ts_poet_1.code) `keyof T`;
|
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) {
|