ts-proto 1.101.0 → 1.103.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 +28 -0
- package/build/case.js +2 -1
- package/build/main.js +10 -2
- package/build/options.js +1 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
# [1.103.0](https://github.com/stephenh/ts-proto/compare/v1.102.2...v1.103.0) (2022-01-20)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* add usePrototypeForDefaults option ([#484](https://github.com/stephenh/ts-proto/issues/484)) ([8e8c810](https://github.com/stephenh/ts-proto/commit/8e8c81016968e7d772dfac5ed54800898f039cbe))
|
|
7
|
+
|
|
8
|
+
## [1.102.2](https://github.com/stephenh/ts-proto/compare/v1.102.1...v1.102.2) (2022-01-19)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* Have snakeToCamel leave existing mixed case. ([#482](https://github.com/stephenh/ts-proto/issues/482)) ([c0bf0fc](https://github.com/stephenh/ts-proto/commit/c0bf0fc13da70e2bde923cd1746119d2e7ac4b2f)), closes [#478](https://github.com/stephenh/ts-proto/issues/478)
|
|
14
|
+
|
|
15
|
+
## [1.102.1](https://github.com/stephenh/ts-proto/compare/v1.102.0...v1.102.1) (2022-01-19)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* Pin ts-proto-descriptors to 1.3.1. ([#481](https://github.com/stephenh/ts-proto/issues/481)) ([6f362bf](https://github.com/stephenh/ts-proto/commit/6f362bfd3517a6bcb440d65e7ac63cd2b0bcc293)), closes [#480](https://github.com/stephenh/ts-proto/issues/480)
|
|
21
|
+
|
|
22
|
+
# [1.102.0](https://github.com/stephenh/ts-proto/compare/v1.101.0...v1.102.0) (2022-01-18)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* enable unknown fields for descriptor protos ([#479](https://github.com/stephenh/ts-proto/issues/479)) ([824c996](https://github.com/stephenh/ts-proto/commit/824c9962cd98dc0f9093e8909e3028d900094c54))
|
|
28
|
+
|
|
1
29
|
# [1.101.0](https://github.com/stephenh/ts-proto/compare/v1.100.1...v1.101.0) (2022-01-15)
|
|
2
30
|
|
|
3
31
|
|
package/build/case.js
CHANGED
|
@@ -3,12 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.camelCase = exports.capitalize = exports.camelToSnake = exports.maybeSnakeToCamel = void 0;
|
|
4
4
|
function maybeSnakeToCamel(s, options) {
|
|
5
5
|
if (options.snakeToCamel.includes('keys') && s.includes('_')) {
|
|
6
|
+
const hasLowerCase = !!s.match(/[a-z]/);
|
|
6
7
|
return s
|
|
7
8
|
.split('_')
|
|
8
9
|
.map((word, i) => {
|
|
9
10
|
if (i === 0) {
|
|
10
11
|
// if first symbol is "_" then skip it
|
|
11
|
-
return word ? word[0] + word.substring(1).toLowerCase() : '';
|
|
12
|
+
return word ? word[0] + (hasLowerCase ? word.substring(1) : word.substring(1).toLowerCase()) : '';
|
|
12
13
|
}
|
|
13
14
|
else {
|
|
14
15
|
return capitalize(word.toLowerCase());
|
package/build/main.js
CHANGED
|
@@ -537,6 +537,10 @@ function generateBaseInstanceFactory(ctx, fullName, messageDesc, fullTypeName) {
|
|
|
537
537
|
function generateDecode(ctx, fullName, messageDesc) {
|
|
538
538
|
const { options, utils, typeMap } = ctx;
|
|
539
539
|
const chunks = [];
|
|
540
|
+
let createBase = ts_poet_1.code `createBase${fullName}()`;
|
|
541
|
+
if (options.usePrototypeForDefaults) {
|
|
542
|
+
createBase = ts_poet_1.code `Object.create(${createBase}) as ${fullName}`;
|
|
543
|
+
}
|
|
540
544
|
// create the basic function declaration
|
|
541
545
|
chunks.push(ts_poet_1.code `
|
|
542
546
|
decode(
|
|
@@ -545,7 +549,7 @@ function generateDecode(ctx, fullName, messageDesc) {
|
|
|
545
549
|
): ${fullName} {
|
|
546
550
|
const reader = input instanceof ${Reader} ? input : new ${Reader}(input);
|
|
547
551
|
let end = length === undefined ? reader.len : reader.pos + length;
|
|
548
|
-
const message =
|
|
552
|
+
const message = ${createBase};
|
|
549
553
|
`);
|
|
550
554
|
if (options.unknownFields) {
|
|
551
555
|
chunks.push(ts_poet_1.code `(message as any)._unknownFields = {}`);
|
|
@@ -1221,7 +1225,11 @@ function generateFromPartial(ctx, fullName, messageDesc) {
|
|
|
1221
1225
|
fromPartial(${paramName}: ${utils.DeepPartial}<${fullName}>): ${fullName} {
|
|
1222
1226
|
`);
|
|
1223
1227
|
}
|
|
1224
|
-
|
|
1228
|
+
let createBase = ts_poet_1.code `createBase${fullName}()`;
|
|
1229
|
+
if (options.usePrototypeForDefaults) {
|
|
1230
|
+
createBase = ts_poet_1.code `Object.create(${createBase}) as ${fullName}`;
|
|
1231
|
+
}
|
|
1232
|
+
chunks.push(ts_poet_1.code `const message = ${createBase};`);
|
|
1225
1233
|
// add a check for each incoming field
|
|
1226
1234
|
messageDesc.field.forEach((field) => {
|
|
1227
1235
|
const fieldName = case_1.maybeSnakeToCamel(field.name, options);
|
package/build/options.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-proto",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.103.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/plugin.js",
|
|
6
6
|
"repository": "github:stephenh/ts-proto",
|
|
@@ -64,6 +64,6 @@
|
|
|
64
64
|
"object-hash": "^1.3.1",
|
|
65
65
|
"protobufjs": "^6.8.8",
|
|
66
66
|
"ts-poet": "^4.5.0",
|
|
67
|
-
"ts-proto-descriptors": "
|
|
67
|
+
"ts-proto-descriptors": "1.3.1"
|
|
68
68
|
}
|
|
69
69
|
}
|