ts-proto 1.121.3 → 1.121.6
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/build/case.js +18 -17
- package/build/generate-services.js +2 -2
- package/build/main.js +19 -13
- package/build/utils.js +5 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
## [1.121.6](https://github.com/stephenh/ts-proto/compare/v1.121.5...v1.121.6) (2022-08-14)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Use jsonName even with snakeToCamel=false. ([#653](https://github.com/stephenh/ts-proto/issues/653)) ([1144886](https://github.com/stephenh/ts-proto/commit/1144886ef43eaf97b780c7aafb2c123fd49b3fe5)), closes [#635](https://github.com/stephenh/ts-proto/issues/635)
|
|
7
|
+
|
|
8
|
+
## [1.121.5](https://github.com/stephenh/ts-proto/compare/v1.121.4...v1.121.5) (2022-08-08)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* remove Record word conflict ([#638](https://github.com/stephenh/ts-proto/issues/638)) ([5664d09](https://github.com/stephenh/ts-proto/commit/5664d097ac33da423b0f4e79f962fd71912358a0))
|
|
14
|
+
* resolve import collisions for services ([#651](https://github.com/stephenh/ts-proto/issues/651)) ([ee0296f](https://github.com/stephenh/ts-proto/commit/ee0296ffe087665b54bac714e964e7243010fb22))
|
|
15
|
+
|
|
16
|
+
## [1.121.4](https://github.com/stephenh/ts-proto/compare/v1.121.3...v1.121.4) (2022-08-07)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Performance Improvements
|
|
20
|
+
|
|
21
|
+
* Faster base64FromBytes & bytesFromBase64 on Node.JS ([#649](https://github.com/stephenh/ts-proto/issues/649)) ([82ab341](https://github.com/stephenh/ts-proto/commit/82ab341557fba1a4933c4613d5c20dbf897905fa))
|
|
22
|
+
|
|
1
23
|
## [1.121.3](https://github.com/stephenh/ts-proto/compare/v1.121.2...v1.121.3) (2022-08-06)
|
|
2
24
|
|
|
3
25
|
|
package/build/case.js
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.camelCase = exports.capitalize = exports.camelToSnake = exports.maybeSnakeToCamel = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return
|
|
8
|
-
.split('_')
|
|
9
|
-
.map((word, i) => {
|
|
10
|
-
// If the word is already mixed case, leave the exist case as-is
|
|
11
|
-
word = hasLowerCase ? word : word.toLowerCase();
|
|
12
|
-
return i === 0 ? word : capitalize(word);
|
|
13
|
-
})
|
|
14
|
-
.join('');
|
|
3
|
+
exports.camelCase = exports.capitalize = exports.camelToSnake = exports.snakeToCamel = exports.maybeSnakeToCamel = void 0;
|
|
4
|
+
/** Converts `key` to TS/JS camel-case idiom, unless overridden not to. */
|
|
5
|
+
function maybeSnakeToCamel(key, options) {
|
|
6
|
+
if (options.snakeToCamel.includes('keys') && key.includes('_')) {
|
|
7
|
+
return snakeToCamel(key);
|
|
15
8
|
}
|
|
16
9
|
else {
|
|
17
|
-
return
|
|
10
|
+
return key;
|
|
18
11
|
}
|
|
19
12
|
}
|
|
20
13
|
exports.maybeSnakeToCamel = maybeSnakeToCamel;
|
|
21
|
-
function
|
|
14
|
+
function snakeToCamel(s) {
|
|
15
|
+
const hasLowerCase = !!s.match(/[a-z]/);
|
|
22
16
|
return s
|
|
23
|
-
.
|
|
24
|
-
|
|
17
|
+
.split('_')
|
|
18
|
+
.map((word, i) => {
|
|
19
|
+
// If the word is already mixed case, leave the existing case as-is
|
|
20
|
+
word = hasLowerCase ? word : word.toLowerCase();
|
|
21
|
+
return i === 0 ? word : capitalize(word);
|
|
25
22
|
})
|
|
26
|
-
.
|
|
23
|
+
.join('');
|
|
24
|
+
}
|
|
25
|
+
exports.snakeToCamel = snakeToCamel;
|
|
26
|
+
function camelToSnake(s) {
|
|
27
|
+
return s.replace(/\w([A-Z])/g, (m) => m[0] + '_' + m[1]).toUpperCase();
|
|
27
28
|
}
|
|
28
29
|
exports.camelToSnake = camelToSnake;
|
|
29
30
|
function capitalize(s) {
|
|
@@ -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/utils.js
CHANGED
|
@@ -151,7 +151,11 @@ function getFieldJsonName(field, options) {
|
|
|
151
151
|
return field.jsonName;
|
|
152
152
|
}
|
|
153
153
|
else {
|
|
154
|
-
|
|
154
|
+
// The user wants to keep snake case in the JSON, but we still want to see if the jsonName
|
|
155
|
+
// attribute is set as an explicit override.
|
|
156
|
+
const probableJsonName = (0, case_1.snakeToCamel)(field.name);
|
|
157
|
+
const isJsonNameSet = probableJsonName !== field.jsonName;
|
|
158
|
+
return isJsonNameSet ? field.jsonName : field.name;
|
|
155
159
|
}
|
|
156
160
|
}
|
|
157
161
|
exports.getFieldJsonName = getFieldJsonName;
|