@aptre/protobuf-es-lite 0.2.10 → 0.2.12
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/bin/protoc-gen-es-lite +2 -2
- package/dist/assert.js +4 -11
- package/dist/binary-encoding.js +69 -42
- package/dist/binary.js +87 -105
- package/dist/codegen-info.d.ts +0 -1
- package/dist/codegen-info.js +12 -16
- package/dist/create-descriptor-set.js +114 -118
- package/dist/descriptor-set.js +1 -2
- package/dist/enum.js +2 -7
- package/dist/feature-set.d.ts +1 -1
- package/dist/feature-set.js +18 -22
- package/dist/field-wrapper.js +12 -17
- package/dist/field.js +35 -34
- package/dist/google/index.js +9 -41
- package/dist/google/protobuf/any.pb.d.ts +2 -2
- package/dist/google/protobuf/any.pb.js +3 -6
- package/dist/google/protobuf/api.pb.d.ts +2 -2
- package/dist/google/protobuf/api.pb.js +56 -21
- package/dist/google/protobuf/compiler/plugin.pb.d.ts +2 -2
- package/dist/google/protobuf/compiler/plugin.pb.js +15 -18
- package/dist/google/protobuf/descriptor.pb.d.ts +19 -19
- package/dist/google/protobuf/descriptor.pb.js +831 -223
- package/dist/google/protobuf/duration.pb.d.ts +2 -2
- package/dist/google/protobuf/duration.pb.js +3 -6
- package/dist/google/protobuf/empty.pb.d.ts +2 -2
- package/dist/google/protobuf/empty.pb.js +3 -6
- package/dist/google/protobuf/source_context.pb.d.ts +2 -2
- package/dist/google/protobuf/source_context.pb.js +3 -6
- package/dist/google/protobuf/struct.pb.d.ts +3 -3
- package/dist/google/protobuf/struct.pb.js +31 -18
- package/dist/google/protobuf/timestamp.pb.d.ts +2 -2
- package/dist/google/protobuf/timestamp.pb.js +3 -6
- package/dist/google/protobuf/type.pb.d.ts +5 -5
- package/dist/google/protobuf/type.pb.js +74 -36
- package/dist/google/protobuf/wrappers.pb.d.ts +2 -2
- package/dist/google/protobuf/wrappers.pb.js +11 -14
- package/dist/index.js +12 -60
- package/dist/is-message.js +9 -16
- package/dist/json.d.ts +0 -9
- package/dist/json.js +72 -102
- package/dist/message.d.ts +3 -3
- package/dist/message.js +50 -57
- package/dist/names.js +12 -23
- package/dist/partial.js +15 -24
- package/dist/proto-base64.js +1 -4
- package/dist/proto-double.js +1 -4
- package/dist/proto-int64.js +9 -12
- package/dist/protoc-gen-es-lite/protoc-gen-es-lite-plugin.js +4 -7
- package/dist/protoc-gen-es-lite/typescript.js +27 -36
- package/dist/protoplugin/create-es-plugin.js +14 -18
- package/dist/protoplugin/ecmascript/file-preamble.js +5 -9
- package/dist/protoplugin/ecmascript/generated-file.js +16 -20
- package/dist/protoplugin/ecmascript/import-path.js +13 -20
- package/dist/protoplugin/ecmascript/import-symbol.js +1 -5
- package/dist/protoplugin/ecmascript/index.js +2 -7
- package/dist/protoplugin/ecmascript/jsdoc.js +1 -5
- package/dist/protoplugin/ecmascript/opaque-printables.js +1 -2
- package/dist/protoplugin/ecmascript/parameter.js +10 -14
- package/dist/protoplugin/ecmascript/reify-wkt.js +12 -16
- package/dist/protoplugin/ecmascript/runtime-imports.js +5 -9
- package/dist/protoplugin/ecmascript/schema.js +16 -20
- package/dist/protoplugin/ecmascript/target.js +1 -2
- package/dist/protoplugin/ecmascript/transpile.js +15 -42
- package/dist/protoplugin/error.js +4 -10
- package/dist/protoplugin/index.js +2 -7
- package/dist/protoplugin/plugin.js +1 -2
- package/dist/protoplugin/run-node.js +6 -10
- package/dist/scalar.js +9 -15
- package/dist/service-type.js +4 -7
- package/dist/text-format.js +25 -30
- package/dist/unknown.js +7 -12
- package/dist/util.d.ts +1 -1
- package/dist/util.js +49 -55
- package/dist/varint.js +7 -17
- package/example/example.pb.ts +24 -18
- package/package.json +10 -7
- package/tsconfig.base.json +3 -3
- package/dist/type-registry.d.ts +0 -43
- package/dist/type-registry.js +0 -15
package/dist/binary.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const scalar_js_1 = require("./scalar.js");
|
|
9
|
-
const assert_js_1 = require("./assert.js");
|
|
10
|
-
const binary_encoding_js_1 = require("./binary-encoding.js");
|
|
11
|
-
function readField(target, // eslint-disable-line @typescript-eslint/no-explicit-any -- `any` is the best choice for dynamic access
|
|
1
|
+
import { isFieldSet, resolveMessageType, } from "./field.js";
|
|
2
|
+
import { handleUnknownField, unknownFieldsSymbol } from "./unknown.js";
|
|
3
|
+
import { wrapField } from "./field-wrapper.js";
|
|
4
|
+
import { LongType, ScalarType, scalarZeroValue, } from "./scalar.js";
|
|
5
|
+
import { assert } from "./assert.js";
|
|
6
|
+
import { BinaryReader, BinaryWriter, WireType, } from "./binary-encoding.js";
|
|
7
|
+
export function readField(target, // eslint-disable-line @typescript-eslint/no-explicit-any -- `any` is the best choice for dynamic access
|
|
12
8
|
reader, field, wireType, options) {
|
|
13
9
|
let { repeated, localName } = field;
|
|
14
10
|
if (field.oneof) {
|
|
@@ -26,7 +22,7 @@ reader, field, wireType, options) {
|
|
|
26
22
|
switch (field.kind) {
|
|
27
23
|
case "scalar":
|
|
28
24
|
case "enum":
|
|
29
|
-
const scalarType = field.kind == "enum" ?
|
|
25
|
+
const scalarType = field.kind == "enum" ? ScalarType.INT32 : field.T;
|
|
30
26
|
let read = readScalar;
|
|
31
27
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison -- acceptable since it's covered by tests
|
|
32
28
|
if (field.kind == "scalar" && field.L > 0) {
|
|
@@ -37,9 +33,9 @@ reader, field, wireType, options) {
|
|
|
37
33
|
if (!Array.isArray(tgtArr)) {
|
|
38
34
|
tgtArr = target[localName] = [];
|
|
39
35
|
}
|
|
40
|
-
const isPacked = wireType ==
|
|
41
|
-
scalarType !=
|
|
42
|
-
scalarType !=
|
|
36
|
+
const isPacked = wireType == WireType.LengthDelimited &&
|
|
37
|
+
scalarType != ScalarType.STRING &&
|
|
38
|
+
scalarType != ScalarType.BYTES;
|
|
43
39
|
if (isPacked) {
|
|
44
40
|
let e = reader.uint32() + reader.pos;
|
|
45
41
|
while (reader.pos < e) {
|
|
@@ -62,17 +58,12 @@ reader, field, wireType, options) {
|
|
|
62
58
|
if (!Array.isArray(tgtArr)) {
|
|
63
59
|
tgtArr = target[localName] = [];
|
|
64
60
|
}
|
|
65
|
-
tgtArr.push(readMessageField(reader,
|
|
61
|
+
tgtArr.push(readMessageField(reader, {}, messageType.fields, options, field));
|
|
66
62
|
}
|
|
67
63
|
else {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
else {
|
|
72
|
-
target[localName] = readMessageField(reader, messageType.create(), messageType.fields, options, field);
|
|
73
|
-
if (messageType.fieldWrapper && !field.oneof && !field.repeated) {
|
|
74
|
-
target[localName] = messageType.fieldWrapper.unwrapField(target[localName]);
|
|
75
|
-
}
|
|
64
|
+
target[localName] = readMessageField(reader, {}, messageType.fields, options, field);
|
|
65
|
+
if (messageType.fieldWrapper && !field.oneof && !field.repeated) {
|
|
66
|
+
target[localName] = messageType.fieldWrapper.unwrapField(target[localName]);
|
|
76
67
|
}
|
|
77
68
|
}
|
|
78
69
|
break;
|
|
@@ -86,9 +77,8 @@ reader, field, wireType, options) {
|
|
|
86
77
|
break;
|
|
87
78
|
}
|
|
88
79
|
}
|
|
89
|
-
exports.readField = readField;
|
|
90
80
|
// Read a map field, expecting key field = 1, value field = 2
|
|
91
|
-
function readMapEntry(field, reader, options) {
|
|
81
|
+
export function readMapEntry(field, reader, options) {
|
|
92
82
|
const length = reader.uint32(), end = reader.pos + length;
|
|
93
83
|
let key, val;
|
|
94
84
|
while (reader.pos < end) {
|
|
@@ -106,15 +96,15 @@ function readMapEntry(field, reader, options) {
|
|
|
106
96
|
val = reader.int32();
|
|
107
97
|
break;
|
|
108
98
|
case "message":
|
|
109
|
-
const messageType =
|
|
110
|
-
val = readMessageField(reader,
|
|
99
|
+
const messageType = resolveMessageType(field.V.T);
|
|
100
|
+
val = readMessageField(reader, {}, messageType.fields, options, undefined);
|
|
111
101
|
break;
|
|
112
102
|
}
|
|
113
103
|
break;
|
|
114
104
|
}
|
|
115
105
|
}
|
|
116
106
|
if (key === undefined) {
|
|
117
|
-
key =
|
|
107
|
+
key = scalarZeroValue(field.K, LongType.BIGINT);
|
|
118
108
|
}
|
|
119
109
|
if (typeof key != "string" && typeof key != "number") {
|
|
120
110
|
key = key.toString();
|
|
@@ -123,61 +113,58 @@ function readMapEntry(field, reader, options) {
|
|
|
123
113
|
const fieldKind = field.V.kind;
|
|
124
114
|
switch (fieldKind) {
|
|
125
115
|
case "scalar":
|
|
126
|
-
val =
|
|
116
|
+
val = scalarZeroValue(field.V.T, LongType.BIGINT);
|
|
127
117
|
break;
|
|
128
118
|
case "enum":
|
|
129
119
|
val = field.V.T.values[0].no;
|
|
130
120
|
break;
|
|
131
121
|
case "message":
|
|
132
|
-
val =
|
|
122
|
+
val = {};
|
|
133
123
|
break;
|
|
134
124
|
}
|
|
135
125
|
}
|
|
136
126
|
return [key, val];
|
|
137
127
|
}
|
|
138
|
-
|
|
139
|
-
function readScalar(reader, type) {
|
|
128
|
+
export function readScalar(reader, type) {
|
|
140
129
|
switch (type) {
|
|
141
|
-
case
|
|
130
|
+
case ScalarType.STRING:
|
|
142
131
|
return reader.string();
|
|
143
|
-
case
|
|
132
|
+
case ScalarType.BOOL:
|
|
144
133
|
return reader.bool();
|
|
145
|
-
case
|
|
134
|
+
case ScalarType.DOUBLE:
|
|
146
135
|
return reader.double();
|
|
147
|
-
case
|
|
136
|
+
case ScalarType.FLOAT:
|
|
148
137
|
return reader.float();
|
|
149
|
-
case
|
|
138
|
+
case ScalarType.INT32:
|
|
150
139
|
return reader.int32();
|
|
151
|
-
case
|
|
140
|
+
case ScalarType.INT64:
|
|
152
141
|
return reader.int64();
|
|
153
|
-
case
|
|
142
|
+
case ScalarType.UINT64:
|
|
154
143
|
return reader.uint64();
|
|
155
|
-
case
|
|
144
|
+
case ScalarType.FIXED64:
|
|
156
145
|
return reader.fixed64();
|
|
157
|
-
case
|
|
146
|
+
case ScalarType.BYTES:
|
|
158
147
|
return reader.bytes();
|
|
159
|
-
case
|
|
148
|
+
case ScalarType.FIXED32:
|
|
160
149
|
return reader.fixed32();
|
|
161
|
-
case
|
|
150
|
+
case ScalarType.SFIXED32:
|
|
162
151
|
return reader.sfixed32();
|
|
163
|
-
case
|
|
152
|
+
case ScalarType.SFIXED64:
|
|
164
153
|
return reader.sfixed64();
|
|
165
|
-
case
|
|
154
|
+
case ScalarType.SINT64:
|
|
166
155
|
return reader.sint64();
|
|
167
|
-
case
|
|
156
|
+
case ScalarType.UINT32:
|
|
168
157
|
return reader.uint32();
|
|
169
|
-
case
|
|
158
|
+
case ScalarType.SINT32:
|
|
170
159
|
return reader.sint32();
|
|
171
160
|
}
|
|
172
161
|
}
|
|
173
|
-
exports.readScalar = readScalar;
|
|
174
162
|
// Read a scalar value, but return 64 bit integral types (int64, uint64,
|
|
175
163
|
// sint64, fixed64, sfixed64) as string instead of bigint.
|
|
176
|
-
function readScalarLTString(reader, type) {
|
|
164
|
+
export function readScalarLTString(reader, type) {
|
|
177
165
|
const v = readScalar(reader, type);
|
|
178
166
|
return typeof v == "bigint" ? v.toString() : v;
|
|
179
167
|
}
|
|
180
|
-
exports.readScalarLTString = readScalarLTString;
|
|
181
168
|
// Read a message, avoiding MessageType.fromBinary() to re-use the
|
|
182
169
|
// BinaryReadOptions and the IBinaryReader.
|
|
183
170
|
function readMessageField(reader, message, fields, options, field) {
|
|
@@ -189,52 +176,49 @@ function readMessageField(reader, message, fields, options, field) {
|
|
|
189
176
|
// Default options for parsing binary data.
|
|
190
177
|
const readDefaults = {
|
|
191
178
|
readUnknownFields: true,
|
|
192
|
-
readerFactory: (bytes) => new
|
|
179
|
+
readerFactory: (bytes) => new BinaryReader(bytes),
|
|
193
180
|
};
|
|
194
181
|
// Default options for serializing binary data.
|
|
195
182
|
const writeDefaults = {
|
|
196
183
|
writeUnknownFields: true,
|
|
197
|
-
writerFactory: () => new
|
|
184
|
+
writerFactory: () => new BinaryWriter(),
|
|
198
185
|
};
|
|
199
|
-
function makeReadOptions(options) {
|
|
186
|
+
export function makeReadOptions(options) {
|
|
200
187
|
return options ? { ...readDefaults, ...options } : readDefaults;
|
|
201
188
|
}
|
|
202
|
-
|
|
203
|
-
function makeWriteOptions(options) {
|
|
189
|
+
export function makeWriteOptions(options) {
|
|
204
190
|
return options ? { ...writeDefaults, ...options } : writeDefaults;
|
|
205
191
|
}
|
|
206
|
-
|
|
207
|
-
function readMessage(message, fields, reader, lengthOrEndTagFieldNo, options, delimitedMessageEncoding) {
|
|
192
|
+
export function readMessage(message, fields, reader, lengthOrEndTagFieldNo, options, delimitedMessageEncoding) {
|
|
208
193
|
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
209
194
|
const end = delimitedMessageEncoding ? reader.len : reader.pos + lengthOrEndTagFieldNo;
|
|
210
195
|
let fieldNo, wireType;
|
|
211
196
|
while (reader.pos < end) {
|
|
212
197
|
[fieldNo, wireType] = reader.tag();
|
|
213
|
-
if (wireType ==
|
|
198
|
+
if (wireType == WireType.EndGroup) {
|
|
214
199
|
break;
|
|
215
200
|
}
|
|
216
201
|
const field = fields.find(fieldNo);
|
|
217
202
|
if (!field) {
|
|
218
203
|
const data = reader.skip(wireType);
|
|
219
204
|
if (options.readUnknownFields) {
|
|
220
|
-
|
|
205
|
+
handleUnknownField(message, fieldNo, wireType, data);
|
|
221
206
|
}
|
|
222
207
|
continue;
|
|
223
208
|
}
|
|
224
209
|
readField(message, reader, field, wireType, options);
|
|
225
210
|
}
|
|
226
211
|
if (delimitedMessageEncoding && // eslint-disable-line @typescript-eslint/strict-boolean-expressions
|
|
227
|
-
(wireType !=
|
|
212
|
+
(wireType != WireType.EndGroup || fieldNo !== lengthOrEndTagFieldNo)) {
|
|
228
213
|
throw new Error(`invalid end group tag`);
|
|
229
214
|
}
|
|
230
215
|
}
|
|
231
|
-
exports.readMessage = readMessage;
|
|
232
216
|
/**
|
|
233
217
|
* Serialize a message to binary data.
|
|
234
218
|
*/
|
|
235
|
-
function writeMessage(message, fields, writer, options) {
|
|
219
|
+
export function writeMessage(message, fields, writer, options) {
|
|
236
220
|
for (const field of fields.byNumber()) {
|
|
237
|
-
if (!
|
|
221
|
+
if (!isFieldSet(field, message)) {
|
|
238
222
|
if (field.req) {
|
|
239
223
|
throw new Error(`cannot encode field ${field.name} to binary: required field not set`);
|
|
240
224
|
}
|
|
@@ -249,16 +233,15 @@ function writeMessage(message, fields, writer, options) {
|
|
|
249
233
|
writeUnknownFields(message, writer);
|
|
250
234
|
}
|
|
251
235
|
}
|
|
252
|
-
exports.writeMessage = writeMessage;
|
|
253
236
|
function writeField(field, value, writer, options) {
|
|
254
|
-
|
|
237
|
+
assert(value !== undefined);
|
|
255
238
|
const repeated = field.repeated;
|
|
256
239
|
switch (field.kind) {
|
|
257
240
|
case "scalar":
|
|
258
241
|
case "enum":
|
|
259
|
-
let scalarType = field.kind == "enum" ?
|
|
242
|
+
let scalarType = field.kind == "enum" ? ScalarType.INT32 : field.T;
|
|
260
243
|
if (repeated) {
|
|
261
|
-
|
|
244
|
+
assert(Array.isArray(value));
|
|
262
245
|
if (field.packed) {
|
|
263
246
|
writePacked(writer, scalarType, field.no, value);
|
|
264
247
|
}
|
|
@@ -274,7 +257,7 @@ function writeField(field, value, writer, options) {
|
|
|
274
257
|
break;
|
|
275
258
|
case "message":
|
|
276
259
|
if (repeated) {
|
|
277
|
-
|
|
260
|
+
assert(Array.isArray(value));
|
|
278
261
|
for (const item of value) {
|
|
279
262
|
writeMessageField(writer, options, field, item);
|
|
280
263
|
}
|
|
@@ -284,7 +267,7 @@ function writeField(field, value, writer, options) {
|
|
|
284
267
|
}
|
|
285
268
|
break;
|
|
286
269
|
case "map":
|
|
287
|
-
|
|
270
|
+
assert(typeof value == "object" && value != null);
|
|
288
271
|
for (const [key, val] of Object.entries(value)) {
|
|
289
272
|
writeMapEntry(writer, options, field, key, val);
|
|
290
273
|
}
|
|
@@ -293,7 +276,7 @@ function writeField(field, value, writer, options) {
|
|
|
293
276
|
}
|
|
294
277
|
function writeUnknownFields(message, writer) {
|
|
295
278
|
const m = message;
|
|
296
|
-
const c = m[
|
|
279
|
+
const c = m[unknownFieldsSymbol];
|
|
297
280
|
if (c) {
|
|
298
281
|
for (const f of c) {
|
|
299
282
|
writer.tag(f.no, f.wireType).raw(f.data);
|
|
@@ -302,21 +285,21 @@ function writeUnknownFields(message, writer) {
|
|
|
302
285
|
}
|
|
303
286
|
// Value must not be undefined
|
|
304
287
|
function writeMessageField(writer, options, field, value) {
|
|
305
|
-
const messageType =
|
|
306
|
-
const message =
|
|
288
|
+
const messageType = resolveMessageType(field.T);
|
|
289
|
+
const message = wrapField(messageType.fieldWrapper, value);
|
|
307
290
|
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
308
291
|
if (field.delimited)
|
|
309
292
|
writer
|
|
310
|
-
.tag(field.no,
|
|
293
|
+
.tag(field.no, WireType.StartGroup)
|
|
311
294
|
.raw(messageType.toBinary(message, options))
|
|
312
|
-
.tag(field.no,
|
|
295
|
+
.tag(field.no, WireType.EndGroup);
|
|
313
296
|
else
|
|
314
297
|
writer
|
|
315
|
-
.tag(field.no,
|
|
298
|
+
.tag(field.no, WireType.LengthDelimited)
|
|
316
299
|
.bytes(messageType.toBinary(message, options));
|
|
317
300
|
}
|
|
318
301
|
function writeScalar(writer, type, fieldNo, value) {
|
|
319
|
-
|
|
302
|
+
assert(value !== undefined);
|
|
320
303
|
let [wireType, method] = scalarTypeInfo(type);
|
|
321
304
|
writer.tag(fieldNo, wireType)[method](value);
|
|
322
305
|
}
|
|
@@ -324,7 +307,7 @@ function writePacked(writer, type, fieldNo, value) {
|
|
|
324
307
|
if (!value.length) {
|
|
325
308
|
return;
|
|
326
309
|
}
|
|
327
|
-
writer.tag(fieldNo,
|
|
310
|
+
writer.tag(fieldNo, WireType.LengthDelimited).fork();
|
|
328
311
|
let [, method] = scalarTypeInfo(type);
|
|
329
312
|
for (let i = 0; i < value.length; i++) {
|
|
330
313
|
writer[method](value[i]);
|
|
@@ -343,44 +326,44 @@ function writePacked(writer, type, fieldNo, value) {
|
|
|
343
326
|
*/
|
|
344
327
|
// TODO replace call-sites writeScalar() and writePacked(), then remove
|
|
345
328
|
function scalarTypeInfo(type) {
|
|
346
|
-
let wireType =
|
|
329
|
+
let wireType = WireType.Varint;
|
|
347
330
|
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- INT32, UINT32, SINT32 are covered by the defaults
|
|
348
331
|
switch (type) {
|
|
349
|
-
case
|
|
350
|
-
case
|
|
351
|
-
wireType =
|
|
332
|
+
case ScalarType.BYTES:
|
|
333
|
+
case ScalarType.STRING:
|
|
334
|
+
wireType = WireType.LengthDelimited;
|
|
352
335
|
break;
|
|
353
|
-
case
|
|
354
|
-
case
|
|
355
|
-
case
|
|
356
|
-
wireType =
|
|
336
|
+
case ScalarType.DOUBLE:
|
|
337
|
+
case ScalarType.FIXED64:
|
|
338
|
+
case ScalarType.SFIXED64:
|
|
339
|
+
wireType = WireType.Bit64;
|
|
357
340
|
break;
|
|
358
|
-
case
|
|
359
|
-
case
|
|
360
|
-
case
|
|
361
|
-
wireType =
|
|
341
|
+
case ScalarType.FIXED32:
|
|
342
|
+
case ScalarType.SFIXED32:
|
|
343
|
+
case ScalarType.FLOAT:
|
|
344
|
+
wireType = WireType.Bit32;
|
|
362
345
|
break;
|
|
363
346
|
}
|
|
364
|
-
const method =
|
|
347
|
+
const method = ScalarType[type].toLowerCase();
|
|
365
348
|
return [wireType, method];
|
|
366
349
|
}
|
|
367
|
-
function writeMapEntry(writer, options, field, key, value) {
|
|
368
|
-
writer.tag(field.no,
|
|
350
|
+
export function writeMapEntry(writer, options, field, key, value) {
|
|
351
|
+
writer.tag(field.no, WireType.LengthDelimited);
|
|
369
352
|
writer.fork();
|
|
370
353
|
// javascript only allows number or string for object properties
|
|
371
354
|
// we convert from our representation to the protobuf type
|
|
372
355
|
let keyValue = key;
|
|
373
356
|
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- we deliberately handle just the special cases for map keys
|
|
374
357
|
switch (field.K) {
|
|
375
|
-
case
|
|
376
|
-
case
|
|
377
|
-
case
|
|
378
|
-
case
|
|
379
|
-
case
|
|
358
|
+
case ScalarType.INT32:
|
|
359
|
+
case ScalarType.FIXED32:
|
|
360
|
+
case ScalarType.UINT32:
|
|
361
|
+
case ScalarType.SFIXED32:
|
|
362
|
+
case ScalarType.SINT32:
|
|
380
363
|
keyValue = Number.parseInt(key);
|
|
381
364
|
break;
|
|
382
|
-
case
|
|
383
|
-
|
|
365
|
+
case ScalarType.BOOL:
|
|
366
|
+
assert(key == "true" || key == "false");
|
|
384
367
|
keyValue = key == "true";
|
|
385
368
|
break;
|
|
386
369
|
}
|
|
@@ -392,16 +375,15 @@ function writeMapEntry(writer, options, field, key, value) {
|
|
|
392
375
|
writeScalar(writer, field.V.T, 2, value);
|
|
393
376
|
break;
|
|
394
377
|
case "enum":
|
|
395
|
-
writeScalar(writer,
|
|
378
|
+
writeScalar(writer, ScalarType.INT32, 2, value);
|
|
396
379
|
break;
|
|
397
380
|
case "message":
|
|
398
|
-
|
|
399
|
-
const messageType =
|
|
381
|
+
assert(value !== undefined);
|
|
382
|
+
const messageType = resolveMessageType(field.V.T);
|
|
400
383
|
writer
|
|
401
|
-
.tag(2,
|
|
384
|
+
.tag(2, WireType.LengthDelimited)
|
|
402
385
|
.bytes(messageType.toBinary(value, options));
|
|
403
386
|
break;
|
|
404
387
|
}
|
|
405
388
|
writer.join();
|
|
406
389
|
}
|
|
407
|
-
exports.writeMapEntry = writeMapEntry;
|
package/dist/codegen-info.d.ts
CHANGED
|
@@ -32,7 +32,6 @@ export declare const codegenInfo: {
|
|
|
32
32
|
readonly LongType: RuntimeSymbolInfo;
|
|
33
33
|
readonly MethodKind: RuntimeSymbolInfo;
|
|
34
34
|
readonly MethodIdempotency: RuntimeSymbolInfo;
|
|
35
|
-
readonly IMessageTypeRegistry: RuntimeSymbolInfo;
|
|
36
35
|
readonly createEnumType: RuntimeSymbolInfo;
|
|
37
36
|
readonly createMessageType: RuntimeSymbolInfo;
|
|
38
37
|
};
|
package/dist/codegen-info.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// Copyright 2024 Aperture Robotics, LLC.
|
|
3
2
|
// Copyright 2021-2024 Buf Technologies, Inc.
|
|
4
3
|
//
|
|
@@ -13,16 +12,14 @@
|
|
|
13
12
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
13
|
// See the License for the specific language governing permissions and
|
|
15
14
|
// limitations under the License.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const scalar_js_1 = require("./scalar.js");
|
|
21
|
-
exports.packageName = "@aptre/protobuf-es-lite";
|
|
15
|
+
import { localName, safeIdentifier, safeObjectProperty } from "./names.js";
|
|
16
|
+
import { getUnwrappedFieldType } from "./field-wrapper.js";
|
|
17
|
+
import { scalarZeroValue } from "./scalar.js";
|
|
18
|
+
export const packageName = "@aptre/protobuf-es-lite";
|
|
22
19
|
const symbolInfo = (typeOnly, privateImportPath) => ({
|
|
23
20
|
typeOnly,
|
|
24
21
|
privateImportPath,
|
|
25
|
-
publicImportPath:
|
|
22
|
+
publicImportPath: packageName,
|
|
26
23
|
});
|
|
27
24
|
const symbols = {
|
|
28
25
|
Message: symbolInfo(false, "./message.js"),
|
|
@@ -42,18 +39,17 @@ const symbols = {
|
|
|
42
39
|
LongType: symbolInfo(false, "./scalar.js"),
|
|
43
40
|
MethodKind: symbolInfo(false, "./service-type.js"),
|
|
44
41
|
MethodIdempotency: symbolInfo(false, "./service-type.js"),
|
|
45
|
-
IMessageTypeRegistry: symbolInfo(true, "./type-registry.js"),
|
|
46
42
|
createEnumType: symbolInfo(false, "./enum.js"),
|
|
47
43
|
createMessageType: symbolInfo(false, "./message.js"),
|
|
48
44
|
};
|
|
49
45
|
// prettier-ignore
|
|
50
|
-
|
|
51
|
-
packageName
|
|
52
|
-
localName
|
|
53
|
-
getUnwrappedFieldType
|
|
54
|
-
scalarZeroValue
|
|
55
|
-
safeIdentifier
|
|
56
|
-
safeObjectProperty
|
|
46
|
+
export const codegenInfo = {
|
|
47
|
+
packageName,
|
|
48
|
+
localName,
|
|
49
|
+
getUnwrappedFieldType,
|
|
50
|
+
scalarZeroValue,
|
|
51
|
+
safeIdentifier,
|
|
52
|
+
safeObjectProperty,
|
|
57
53
|
symbols,
|
|
58
54
|
wktSourceFiles: [
|
|
59
55
|
"google/protobuf/compiler/plugin.proto",
|