ts-proto 1.143.0 → 1.144.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/build/main.js +29 -16
- package/package.json +1 -1
package/build/main.js
CHANGED
|
@@ -580,6 +580,9 @@ function generateInterfaceDeclaration(ctx, fullName, messageDesc, sourceInfo, fu
|
|
|
580
580
|
const q = (0, types_1.isOptionalProperty)(fieldDesc, messageDesc.options, options) ? "?" : "";
|
|
581
581
|
chunks.push((0, ts_poet_1.code) `${maybeReadonly(options)}${name}${q}: ${type}, `);
|
|
582
582
|
});
|
|
583
|
+
if (ctx.options.unknownFields) {
|
|
584
|
+
chunks.push((0, ts_poet_1.code) `_unknownFields?: {[key: number]: Uint8Array[]},`);
|
|
585
|
+
}
|
|
583
586
|
chunks.push((0, ts_poet_1.code) `}`);
|
|
584
587
|
return (0, ts_poet_1.joinCode)(chunks, { on: "\n" });
|
|
585
588
|
}
|
|
@@ -649,6 +652,9 @@ function generateBaseInstanceFactory(ctx, fullName, messageDesc, fullTypeName) {
|
|
|
649
652
|
if (ctx.options.outputTypeRegistry) {
|
|
650
653
|
fields.unshift((0, ts_poet_1.code) `$type: '${fullTypeName}'`);
|
|
651
654
|
}
|
|
655
|
+
if (ctx.options.unknownFields && ctx.options.initializeFieldsAsUndefined) {
|
|
656
|
+
fields.push((0, ts_poet_1.code) `_unknownFields: {}`);
|
|
657
|
+
}
|
|
652
658
|
return (0, ts_poet_1.code) `
|
|
653
659
|
function createBase${fullName}(): ${fullName} {
|
|
654
660
|
return { ${(0, ts_poet_1.joinCode)(fields, { on: "," })} };
|
|
@@ -674,9 +680,6 @@ function generateDecode(ctx, fullName, messageDesc) {
|
|
|
674
680
|
let end = length === undefined ? reader.len : reader.pos + length;
|
|
675
681
|
`);
|
|
676
682
|
chunks.push((0, ts_poet_1.code) `const message = ${createBase}${maybeAsAny(options)};`);
|
|
677
|
-
if (options.unknownFields) {
|
|
678
|
-
chunks.push((0, ts_poet_1.code) `(message as any)._unknownFields = {}`);
|
|
679
|
-
}
|
|
680
683
|
// start the tag loop
|
|
681
684
|
chunks.push((0, ts_poet_1.code) `
|
|
682
685
|
while (reader.pos < end) {
|
|
@@ -837,16 +840,26 @@ function generateDecode(ctx, fullName, messageDesc) {
|
|
|
837
840
|
break;
|
|
838
841
|
`);
|
|
839
842
|
if (options.unknownFields) {
|
|
843
|
+
let unknownFieldsInitializerSnippet = "";
|
|
844
|
+
let maybeNonNullAssertion = options.initializeFieldsAsUndefined ? "!" : "";
|
|
845
|
+
if (!options.initializeFieldsAsUndefined) {
|
|
846
|
+
unknownFieldsInitializerSnippet = `
|
|
847
|
+
if(message._unknownFields === undefined)
|
|
848
|
+
message._unknownFields = {};
|
|
849
|
+
`;
|
|
850
|
+
}
|
|
840
851
|
chunks.push((0, ts_poet_1.code) `
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
852
|
+
const startPos = reader.pos;
|
|
853
|
+
reader.skipType(tag & 7);
|
|
854
|
+
const buf = reader.buf.slice(startPos, reader.pos);
|
|
855
|
+
|
|
856
|
+
${unknownFieldsInitializerSnippet}
|
|
857
|
+
const list = message._unknownFields${maybeNonNullAssertion}[tag];
|
|
845
858
|
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
859
|
+
if(list === undefined)
|
|
860
|
+
message._unknownFields${maybeNonNullAssertion}[tag] = [buf];
|
|
861
|
+
else
|
|
862
|
+
list.push(buf);
|
|
850
863
|
`);
|
|
851
864
|
}
|
|
852
865
|
else {
|
|
@@ -1067,12 +1080,12 @@ function generateEncode(ctx, fullName, messageDesc) {
|
|
|
1067
1080
|
}
|
|
1068
1081
|
});
|
|
1069
1082
|
if (options.unknownFields) {
|
|
1070
|
-
chunks.push((0, ts_poet_1.code) `if (
|
|
1071
|
-
const
|
|
1072
|
-
|
|
1073
|
-
const
|
|
1083
|
+
chunks.push((0, ts_poet_1.code) `if (message._unknownFields !== undefined) {
|
|
1084
|
+
for (const key in message._unknownFields) {
|
|
1085
|
+
const values = message._unknownFields[key];
|
|
1086
|
+
const tag = parseInt(key, 10);
|
|
1074
1087
|
for (const value of values) {
|
|
1075
|
-
writer.uint32(
|
|
1088
|
+
writer.uint32(tag);
|
|
1076
1089
|
(writer as any)['_push'](
|
|
1077
1090
|
(val: Uint8Array, buf: Buffer, pos: number) => buf.set(val, pos),
|
|
1078
1091
|
value.length,
|