ts-proto 1.143.0 → 1.144.1
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/generate-generic-service-definition.js +3 -4
- package/build/main.js +29 -16
- package/build/schema.js +18 -17
- package/package.json +2 -2
|
@@ -67,12 +67,11 @@ function generateMethodOptions(ctx, options) {
|
|
|
67
67
|
else if (options.idempotencyLevel === ts_proto_descriptors_1.MethodOptions_IdempotencyLevel.NO_SIDE_EFFECTS) {
|
|
68
68
|
chunks.push((0, ts_poet_1.code) `idempotencyLevel: 'NO_SIDE_EFFECTS',`);
|
|
69
69
|
}
|
|
70
|
-
if (
|
|
71
|
-
const msgUnknownFields = options["_unknownFields"];
|
|
70
|
+
if (options._unknownFields !== undefined) {
|
|
72
71
|
const unknownFieldsChunks = [];
|
|
73
72
|
unknownFieldsChunks.push((0, ts_poet_1.code) `{`);
|
|
74
|
-
for (const key
|
|
75
|
-
const values =
|
|
73
|
+
for (const key in options._unknownFields) {
|
|
74
|
+
const values = options._unknownFields[key];
|
|
76
75
|
const valuesChunks = [];
|
|
77
76
|
for (const value of values) {
|
|
78
77
|
valuesChunks.push((0, ts_poet_1.code) `${ctx.options.env == "node" ? "Buffer.from" : "new Uint8Array"}([${value.join(", ")}])`);
|
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,
|
package/build/schema.js
CHANGED
|
@@ -78,8 +78,8 @@ function generateSchema(ctx, fileDesc, sourceInfo) {
|
|
|
78
78
|
};
|
|
79
79
|
let fileOptions;
|
|
80
80
|
if (fileDesc.options) {
|
|
81
|
-
fileOptions = encodedOptionsToOptions(ctx, ".google.protobuf.FileOptions", fileDesc.options
|
|
82
|
-
delete fileDesc.options
|
|
81
|
+
fileOptions = encodedOptionsToOptions(ctx, ".google.protobuf.FileOptions", fileDesc.options._unknownFields);
|
|
82
|
+
delete fileDesc.options._unknownFields;
|
|
83
83
|
}
|
|
84
84
|
const messagesOptions = [];
|
|
85
85
|
(fileDesc.messageType || []).forEach((message) => {
|
|
@@ -93,8 +93,8 @@ function generateSchema(ctx, fileDesc, sourceInfo) {
|
|
|
93
93
|
const methodsOptions = [];
|
|
94
94
|
service.method.forEach((method) => {
|
|
95
95
|
if (method.options) {
|
|
96
|
-
const methodOptions = encodedOptionsToOptions(ctx, ".google.protobuf.MethodOptions", method.options
|
|
97
|
-
delete method.options
|
|
96
|
+
const methodOptions = encodedOptionsToOptions(ctx, ".google.protobuf.MethodOptions", method.options._unknownFields);
|
|
97
|
+
delete method.options._unknownFields;
|
|
98
98
|
if (methodOptions) {
|
|
99
99
|
methodsOptions.push((0, ts_poet_1.code) `'${method.name}': ${methodOptions}`);
|
|
100
100
|
}
|
|
@@ -102,8 +102,8 @@ function generateSchema(ctx, fileDesc, sourceInfo) {
|
|
|
102
102
|
});
|
|
103
103
|
let serviceOptions;
|
|
104
104
|
if (service.options) {
|
|
105
|
-
serviceOptions = encodedOptionsToOptions(ctx, ".google.protobuf.ServiceOptions", service.options
|
|
106
|
-
delete service.options
|
|
105
|
+
serviceOptions = encodedOptionsToOptions(ctx, ".google.protobuf.ServiceOptions", service.options._unknownFields);
|
|
106
|
+
delete service.options._unknownFields;
|
|
107
107
|
}
|
|
108
108
|
if (methodsOptions.length > 0 || serviceOptions) {
|
|
109
109
|
servicesOptions.push((0, ts_poet_1.code) `
|
|
@@ -119,8 +119,8 @@ function generateSchema(ctx, fileDesc, sourceInfo) {
|
|
|
119
119
|
const valuesOptions = [];
|
|
120
120
|
Enum.value.forEach((value) => {
|
|
121
121
|
if (value.options) {
|
|
122
|
-
const valueOptions = encodedOptionsToOptions(ctx, ".google.protobuf.EnumValueOptions", value.options
|
|
123
|
-
delete value.options
|
|
122
|
+
const valueOptions = encodedOptionsToOptions(ctx, ".google.protobuf.EnumValueOptions", value.options._unknownFields);
|
|
123
|
+
delete value.options._unknownFields;
|
|
124
124
|
if (valueOptions) {
|
|
125
125
|
valuesOptions.push((0, ts_poet_1.code) `'${value.name}': ${valueOptions}`);
|
|
126
126
|
}
|
|
@@ -128,8 +128,8 @@ function generateSchema(ctx, fileDesc, sourceInfo) {
|
|
|
128
128
|
});
|
|
129
129
|
let enumOptions;
|
|
130
130
|
if (Enum.options) {
|
|
131
|
-
enumOptions = encodedOptionsToOptions(ctx, ".google.protobuf.EnumOptions", Enum.options
|
|
132
|
-
delete Enum.options
|
|
131
|
+
enumOptions = encodedOptionsToOptions(ctx, ".google.protobuf.EnumOptions", Enum.options._unknownFields);
|
|
132
|
+
delete Enum.options._unknownFields;
|
|
133
133
|
}
|
|
134
134
|
if (valuesOptions.length > 0 || enumOptions) {
|
|
135
135
|
enumsOptions.push((0, ts_poet_1.code) `
|
|
@@ -185,7 +185,8 @@ function encodedOptionsToOptions(ctx, extendee, encodedOptions) {
|
|
|
185
185
|
return undefined;
|
|
186
186
|
}
|
|
187
187
|
const resultOptions = [];
|
|
188
|
-
for (const
|
|
188
|
+
for (const key in encodedOptions) {
|
|
189
|
+
const value = encodedOptions[key];
|
|
189
190
|
const extension = extensionCache[extendee][parseInt(key, 10) >>> 3];
|
|
190
191
|
resultOptions.push(getExtensionValue(ctx, extension, value));
|
|
191
192
|
}
|
|
@@ -198,8 +199,8 @@ function resolveMessageOptions(ctx, message) {
|
|
|
198
199
|
const fieldsOptions = [];
|
|
199
200
|
message.field.forEach((field) => {
|
|
200
201
|
if (field.options) {
|
|
201
|
-
const fieldOptions = encodedOptionsToOptions(ctx, ".google.protobuf.FieldOptions", field.options
|
|
202
|
-
delete field.options
|
|
202
|
+
const fieldOptions = encodedOptionsToOptions(ctx, ".google.protobuf.FieldOptions", field.options._unknownFields);
|
|
203
|
+
delete field.options._unknownFields;
|
|
203
204
|
if (fieldOptions) {
|
|
204
205
|
fieldsOptions.push((0, ts_poet_1.code) `'${field.name}': ${fieldOptions}`);
|
|
205
206
|
}
|
|
@@ -208,8 +209,8 @@ function resolveMessageOptions(ctx, message) {
|
|
|
208
209
|
const oneOfsOptions = [];
|
|
209
210
|
message.oneofDecl.forEach((oneOf) => {
|
|
210
211
|
if (oneOf.options) {
|
|
211
|
-
const oneOfOptions = encodedOptionsToOptions(ctx, ".google.protobuf.OneofOptions", oneOf.options
|
|
212
|
-
delete oneOf.options
|
|
212
|
+
const oneOfOptions = encodedOptionsToOptions(ctx, ".google.protobuf.OneofOptions", oneOf.options._unknownFields);
|
|
213
|
+
delete oneOf.options._unknownFields;
|
|
213
214
|
if (oneOfOptions) {
|
|
214
215
|
oneOfsOptions.push((0, ts_poet_1.code) `'${oneOf.name}': ${oneOfOptions}`);
|
|
215
216
|
}
|
|
@@ -226,8 +227,8 @@ function resolveMessageOptions(ctx, message) {
|
|
|
226
227
|
}
|
|
227
228
|
let messageOptions;
|
|
228
229
|
if (message.options) {
|
|
229
|
-
messageOptions = encodedOptionsToOptions(ctx, ".google.protobuf.MessageOptions", message.options
|
|
230
|
-
delete message.options
|
|
230
|
+
messageOptions = encodedOptionsToOptions(ctx, ".google.protobuf.MessageOptions", message.options._unknownFields);
|
|
231
|
+
delete message.options._unknownFields;
|
|
231
232
|
}
|
|
232
233
|
if (fieldsOptions.length > 0 || oneOfsOptions.length > 0 || nestedOptions.length > 0 || messageOptions) {
|
|
233
234
|
return (0, ts_poet_1.code) `
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-proto",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.144.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/plugin.js",
|
|
6
6
|
"repository": "github:stephenh/ts-proto",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"object-hash": "^1.3.1",
|
|
66
66
|
"protobufjs": "^6.11.3",
|
|
67
67
|
"ts-poet": "^6.4.1",
|
|
68
|
-
"ts-proto-descriptors": "1.
|
|
68
|
+
"ts-proto-descriptors": "1.8.0"
|
|
69
69
|
},
|
|
70
70
|
"packageManager": "yarn@3.3.0"
|
|
71
71
|
}
|