@bufbuild/protobuf 2.0.0-alpha.4 → 2.0.0-beta.2
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/README.md +2 -3
- package/dist/cjs/clone.d.ts +1 -1
- package/dist/cjs/clone.js +5 -16
- package/dist/cjs/codegenv1/embed.js +25 -25
- package/dist/cjs/codegenv1/enum.d.ts +2 -1
- package/dist/cjs/codegenv1/file.js +1 -1
- package/dist/cjs/codegenv1/message.d.ts +2 -1
- package/dist/cjs/codegenv1/scalar.d.ts +4 -0
- package/dist/cjs/codegenv1/scalar.js +30 -1
- package/dist/cjs/codegenv1/symbols.d.ts +10 -0
- package/dist/cjs/codegenv1/symbols.js +2 -0
- package/dist/cjs/codegenv1/types.d.ts +7 -5
- package/dist/cjs/codegenv1/types.js +2 -1
- package/dist/cjs/create.d.ts +1 -1
- package/dist/cjs/create.js +47 -20
- package/dist/cjs/equals.d.ts +1 -1
- package/dist/cjs/equals.js +8 -15
- package/dist/cjs/from-binary.d.ts +2 -2
- package/dist/cjs/from-binary.js +6 -6
- package/dist/cjs/from-json.d.ts +14 -6
- package/dist/cjs/from-json.js +35 -33
- package/dist/cjs/is-message.d.ts +1 -1
- package/dist/cjs/is-message.js +3 -3
- package/dist/cjs/reflect/reflect-types.d.ts +13 -42
- package/dist/cjs/reflect/reflect.d.ts +29 -18
- package/dist/cjs/reflect/reflect.js +169 -45
- package/dist/cjs/reflect/scalar.d.ts +1 -1
- package/dist/cjs/registry.d.ts +18 -2
- package/dist/cjs/registry.js +63 -61
- package/dist/cjs/to-binary.d.ts +1 -1
- package/dist/cjs/to-binary.js +2 -2
- package/dist/cjs/to-json.d.ts +14 -4
- package/dist/cjs/to-json.js +26 -13
- package/dist/cjs/types.d.ts +9 -0
- package/dist/cjs/wire/size-delimited.d.ts +1 -1
- package/dist/cjs/wkt/any.d.ts +7 -7
- package/dist/cjs/wkt/any.js +5 -5
- package/dist/cjs/wkt/gen/google/protobuf/any_pb.d.ts +9 -3
- package/dist/cjs/wkt/gen/google/protobuf/any_pb.js +4 -4
- package/dist/cjs/wkt/gen/google/protobuf/api_pb.d.ts +88 -9
- package/dist/cjs/wkt/gen/google/protobuf/api_pb.js +8 -8
- package/dist/cjs/wkt/gen/google/protobuf/compiler/plugin_pb.d.ts +107 -11
- package/dist/cjs/wkt/gen/google/protobuf/compiler/plugin_pb.js +11 -11
- package/dist/cjs/wkt/gen/google/protobuf/descriptor_pb.d.ts +1005 -92
- package/dist/cjs/wkt/gen/google/protobuf/descriptor_pb.js +86 -86
- package/dist/cjs/wkt/gen/google/protobuf/duration_pb.d.ts +7 -3
- package/dist/cjs/wkt/gen/google/protobuf/duration_pb.js +4 -4
- package/dist/cjs/wkt/gen/google/protobuf/empty_pb.d.ts +7 -3
- package/dist/cjs/wkt/gen/google/protobuf/empty_pb.js +4 -4
- package/dist/cjs/wkt/gen/google/protobuf/field_mask_pb.d.ts +7 -3
- package/dist/cjs/wkt/gen/google/protobuf/field_mask_pb.js +4 -4
- package/dist/cjs/wkt/gen/google/protobuf/source_context_pb.d.ts +12 -3
- package/dist/cjs/wkt/gen/google/protobuf/source_context_pb.js +4 -4
- package/dist/cjs/wkt/gen/google/protobuf/struct_pb.d.ts +25 -8
- package/dist/cjs/wkt/gen/google/protobuf/struct_pb.js +9 -9
- package/dist/cjs/wkt/gen/google/protobuf/timestamp_pb.d.ts +7 -3
- package/dist/cjs/wkt/gen/google/protobuf/timestamp_pb.js +4 -4
- package/dist/cjs/wkt/gen/google/protobuf/type_pb.d.ts +165 -16
- package/dist/cjs/wkt/gen/google/protobuf/type_pb.js +15 -15
- package/dist/cjs/wkt/gen/google/protobuf/wrappers_pb.d.ts +55 -19
- package/dist/cjs/wkt/gen/google/protobuf/wrappers_pb.js +20 -20
- package/dist/cjs/wkt/timestamp.js +1 -2
- package/dist/esm/clone.d.ts +1 -1
- package/dist/esm/clone.js +5 -16
- package/dist/esm/codegenv1/embed.js +26 -26
- package/dist/esm/codegenv1/enum.d.ts +2 -1
- package/dist/esm/codegenv1/file.js +2 -2
- package/dist/esm/codegenv1/message.d.ts +2 -1
- package/dist/esm/codegenv1/scalar.d.ts +4 -0
- package/dist/esm/codegenv1/scalar.js +28 -0
- package/dist/esm/codegenv1/symbols.d.ts +10 -0
- package/dist/esm/codegenv1/symbols.js +2 -0
- package/dist/esm/codegenv1/types.d.ts +7 -5
- package/dist/esm/codegenv1/types.js +2 -1
- package/dist/esm/create.d.ts +1 -1
- package/dist/esm/create.js +47 -20
- package/dist/esm/equals.d.ts +1 -1
- package/dist/esm/equals.js +8 -15
- package/dist/esm/from-binary.d.ts +2 -2
- package/dist/esm/from-binary.js +6 -6
- package/dist/esm/from-json.d.ts +14 -6
- package/dist/esm/from-json.js +33 -33
- package/dist/esm/is-message.d.ts +1 -1
- package/dist/esm/is-message.js +3 -3
- package/dist/esm/reflect/reflect-types.d.ts +13 -42
- package/dist/esm/reflect/reflect-types.js +0 -1
- package/dist/esm/reflect/reflect.d.ts +29 -18
- package/dist/esm/reflect/reflect.js +170 -46
- package/dist/esm/reflect/scalar.d.ts +1 -1
- package/dist/esm/registry.d.ts +18 -2
- package/dist/esm/registry.js +61 -60
- package/dist/esm/to-binary.d.ts +1 -1
- package/dist/esm/to-binary.js +2 -2
- package/dist/esm/to-json.d.ts +14 -4
- package/dist/esm/to-json.js +24 -12
- package/dist/esm/types.d.ts +9 -0
- package/dist/esm/wire/size-delimited.d.ts +1 -1
- package/dist/esm/wkt/any.d.ts +7 -7
- package/dist/esm/wkt/any.js +6 -6
- package/dist/esm/wkt/gen/google/protobuf/any_pb.d.ts +9 -3
- package/dist/esm/wkt/gen/google/protobuf/any_pb.js +3 -3
- package/dist/esm/wkt/gen/google/protobuf/api_pb.d.ts +88 -9
- package/dist/esm/wkt/gen/google/protobuf/api_pb.js +9 -9
- package/dist/esm/wkt/gen/google/protobuf/compiler/plugin_pb.d.ts +107 -11
- package/dist/esm/wkt/gen/google/protobuf/compiler/plugin_pb.js +11 -11
- package/dist/esm/wkt/gen/google/protobuf/descriptor_pb.d.ts +1005 -92
- package/dist/esm/wkt/gen/google/protobuf/descriptor_pb.js +84 -84
- package/dist/esm/wkt/gen/google/protobuf/duration_pb.d.ts +7 -3
- package/dist/esm/wkt/gen/google/protobuf/duration_pb.js +3 -3
- package/dist/esm/wkt/gen/google/protobuf/empty_pb.d.ts +7 -3
- package/dist/esm/wkt/gen/google/protobuf/empty_pb.js +3 -3
- package/dist/esm/wkt/gen/google/protobuf/field_mask_pb.d.ts +7 -3
- package/dist/esm/wkt/gen/google/protobuf/field_mask_pb.js +3 -3
- package/dist/esm/wkt/gen/google/protobuf/source_context_pb.d.ts +12 -3
- package/dist/esm/wkt/gen/google/protobuf/source_context_pb.js +3 -3
- package/dist/esm/wkt/gen/google/protobuf/struct_pb.d.ts +25 -8
- package/dist/esm/wkt/gen/google/protobuf/struct_pb.js +8 -8
- package/dist/esm/wkt/gen/google/protobuf/timestamp_pb.d.ts +7 -3
- package/dist/esm/wkt/gen/google/protobuf/timestamp_pb.js +3 -3
- package/dist/esm/wkt/gen/google/protobuf/type_pb.d.ts +165 -16
- package/dist/esm/wkt/gen/google/protobuf/type_pb.js +16 -16
- package/dist/esm/wkt/gen/google/protobuf/wrappers_pb.d.ts +55 -19
- package/dist/esm/wkt/gen/google/protobuf/wrappers_pb.js +19 -19
- package/dist/esm/wkt/timestamp.js +2 -3
- package/package.json +8 -5
|
@@ -27,9 +27,15 @@ const guard_js_1 = require("./guard.js");
|
|
|
27
27
|
* Create a ReflectMessage.
|
|
28
28
|
*/
|
|
29
29
|
function reflect(messageDesc, message,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
/**
|
|
31
|
+
* By default, field values are validated when setting them. For example,
|
|
32
|
+
* a value for an uint32 field must be a ECMAScript Number >= 0.
|
|
33
|
+
*
|
|
34
|
+
* When field values are trusted, performance can be improved by disabling
|
|
35
|
+
* checks.
|
|
36
|
+
*/
|
|
37
|
+
check = true) {
|
|
38
|
+
return new ReflectMessageImpl(messageDesc, message, check);
|
|
33
39
|
}
|
|
34
40
|
exports.reflect = reflect;
|
|
35
41
|
class ReflectMessageImpl {
|
|
@@ -39,9 +45,7 @@ class ReflectMessageImpl {
|
|
|
39
45
|
.concat()
|
|
40
46
|
.sort((a, b) => a.number - b.number)));
|
|
41
47
|
}
|
|
42
|
-
constructor(messageDesc, message,
|
|
43
|
-
// TODO either remove this option, or support it in reflect-list and reflect-map as well
|
|
44
|
-
check = true) {
|
|
48
|
+
constructor(messageDesc, message, check = true) {
|
|
45
49
|
this.lists = new Map();
|
|
46
50
|
this.maps = new Map();
|
|
47
51
|
this.check = check;
|
|
@@ -71,7 +75,7 @@ class ReflectMessageImpl {
|
|
|
71
75
|
}
|
|
72
76
|
get(field) {
|
|
73
77
|
assertOwn(this.message, field);
|
|
74
|
-
|
|
78
|
+
const value = (0, unsafe_js_1.unsafeGet)(this.message, field);
|
|
75
79
|
switch (field.fieldKind) {
|
|
76
80
|
case "list":
|
|
77
81
|
// eslint-disable-next-line no-case-declarations
|
|
@@ -88,15 +92,7 @@ class ReflectMessageImpl {
|
|
|
88
92
|
}
|
|
89
93
|
return map;
|
|
90
94
|
case "message":
|
|
91
|
-
|
|
92
|
-
!field.oneof &&
|
|
93
|
-
(0, wrappers_js_1.isWrapperDesc)(field.message)) {
|
|
94
|
-
value = {
|
|
95
|
-
$typeName: field.message.typeName,
|
|
96
|
-
value: longToReflect(field.message.fields[0], value),
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
return new ReflectMessageImpl(field.message, value, this.check);
|
|
95
|
+
return messageToReflect(field, value, this.check);
|
|
100
96
|
case "scalar":
|
|
101
97
|
return (value === undefined
|
|
102
98
|
? (0, scalar_js_1.scalarZeroValue)(field.scalar, false)
|
|
@@ -110,22 +106,20 @@ class ReflectMessageImpl {
|
|
|
110
106
|
if (this.check) {
|
|
111
107
|
const err = (0, reflect_check_js_1.checkField)(field, value);
|
|
112
108
|
if (err) {
|
|
113
|
-
|
|
109
|
+
throw err;
|
|
114
110
|
}
|
|
115
111
|
}
|
|
116
112
|
let local;
|
|
117
|
-
if (
|
|
118
|
-
local = value
|
|
113
|
+
if (field.fieldKind == "message") {
|
|
114
|
+
local = messageToLocal(field, value);
|
|
119
115
|
}
|
|
120
|
-
else if ((0, guard_js_1.
|
|
121
|
-
|
|
122
|
-
local = !field.oneof && (0, wrappers_js_1.isWrapper)(msg) ? msg.value : msg;
|
|
116
|
+
else if ((0, guard_js_1.isReflectMap)(value) || (0, guard_js_1.isReflectList)(value)) {
|
|
117
|
+
local = value[unsafe_js_1.unsafeLocal];
|
|
123
118
|
}
|
|
124
119
|
else {
|
|
125
120
|
local = longToLocal(field, value);
|
|
126
121
|
}
|
|
127
122
|
(0, unsafe_js_1.unsafeSet)(this.message, field, local);
|
|
128
|
-
return undefined;
|
|
129
123
|
}
|
|
130
124
|
getUnknown() {
|
|
131
125
|
return this.message.$unknown;
|
|
@@ -142,7 +136,15 @@ function assertOwn(owner, member) {
|
|
|
142
136
|
/**
|
|
143
137
|
* Create a ReflectList.
|
|
144
138
|
*/
|
|
145
|
-
function reflectList(field, unsafeInput,
|
|
139
|
+
function reflectList(field, unsafeInput,
|
|
140
|
+
/**
|
|
141
|
+
* By default, field values are validated when setting them. For example,
|
|
142
|
+
* a value for an uint32 field must be a ECMAScript Number >= 0.
|
|
143
|
+
*
|
|
144
|
+
* When field values are trusted, performance can be improved by disabling
|
|
145
|
+
* checks.
|
|
146
|
+
*/
|
|
147
|
+
check = true) {
|
|
146
148
|
return new ReflectListImpl(field, unsafeInput !== null && unsafeInput !== void 0 ? unsafeInput : [], check);
|
|
147
149
|
}
|
|
148
150
|
exports.reflectList = reflectList;
|
|
@@ -166,29 +168,24 @@ class ReflectListImpl {
|
|
|
166
168
|
}
|
|
167
169
|
set(index, item) {
|
|
168
170
|
if (index < 0 || index >= this._arr.length) {
|
|
169
|
-
|
|
171
|
+
throw new error_js_1.FieldError(this._field, `list item #${index + 1}: out of range`);
|
|
170
172
|
}
|
|
171
173
|
if (this.check) {
|
|
172
174
|
const err = (0, reflect_check_js_1.checkListItem)(this._field, index, item);
|
|
173
175
|
if (err) {
|
|
174
|
-
|
|
176
|
+
throw err;
|
|
175
177
|
}
|
|
176
178
|
}
|
|
177
179
|
this._arr[index] = listItemToLocal(this._field, item);
|
|
178
|
-
return undefined;
|
|
179
180
|
}
|
|
180
|
-
add(
|
|
181
|
+
add(item) {
|
|
181
182
|
if (this.check) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
return err;
|
|
186
|
-
}
|
|
183
|
+
const err = (0, reflect_check_js_1.checkListItem)(this._field, this._arr.length, item);
|
|
184
|
+
if (err) {
|
|
185
|
+
throw err;
|
|
187
186
|
}
|
|
188
187
|
}
|
|
189
|
-
|
|
190
|
-
this._arr.push(listItemToLocal(this._field, item));
|
|
191
|
-
}
|
|
188
|
+
this._arr.push(listItemToLocal(this._field, item));
|
|
192
189
|
return undefined;
|
|
193
190
|
}
|
|
194
191
|
clear() {
|
|
@@ -214,7 +211,15 @@ class ReflectListImpl {
|
|
|
214
211
|
/**
|
|
215
212
|
* Create a ReflectMap.
|
|
216
213
|
*/
|
|
217
|
-
function reflectMap(field, unsafeInput,
|
|
214
|
+
function reflectMap(field, unsafeInput,
|
|
215
|
+
/**
|
|
216
|
+
* By default, field values are validated when setting them. For example,
|
|
217
|
+
* a value for an uint32 field must be a ECMAScript Number >= 0.
|
|
218
|
+
*
|
|
219
|
+
* When field values are trusted, performance can be improved by disabling
|
|
220
|
+
* checks.
|
|
221
|
+
*/
|
|
222
|
+
check = true) {
|
|
218
223
|
return new ReflectMapImpl(field, unsafeInput, check);
|
|
219
224
|
}
|
|
220
225
|
exports.reflectMap = reflectMap;
|
|
@@ -231,11 +236,11 @@ class ReflectMapImpl {
|
|
|
231
236
|
if (this.check) {
|
|
232
237
|
const err = (0, reflect_check_js_1.checkMapEntry)(this._field, key, value);
|
|
233
238
|
if (err) {
|
|
234
|
-
|
|
239
|
+
throw err;
|
|
235
240
|
}
|
|
236
241
|
}
|
|
237
242
|
this.obj[mapKeyToLocal(key)] = mapValueToLocal(this._field, value);
|
|
238
|
-
return
|
|
243
|
+
return this;
|
|
239
244
|
}
|
|
240
245
|
delete(key) {
|
|
241
246
|
const k = mapKeyToLocal(key);
|
|
@@ -290,27 +295,68 @@ class ReflectMapImpl {
|
|
|
290
295
|
}
|
|
291
296
|
}
|
|
292
297
|
}
|
|
298
|
+
function messageToLocal(field, value) {
|
|
299
|
+
if (!(0, guard_js_1.isReflectMessage)(value)) {
|
|
300
|
+
return value;
|
|
301
|
+
}
|
|
302
|
+
if ((0, wrappers_js_1.isWrapper)(value.message) &&
|
|
303
|
+
!field.oneof &&
|
|
304
|
+
field.fieldKind == "message") {
|
|
305
|
+
// Types from google/protobuf/wrappers.proto are unwrapped when used in
|
|
306
|
+
// a singular field that is not part of a oneof group.
|
|
307
|
+
return value.message.value;
|
|
308
|
+
}
|
|
309
|
+
if (value.desc.typeName == "google.protobuf.Struct" &&
|
|
310
|
+
field.parent.typeName != "google.protobuf.Value") {
|
|
311
|
+
// google.protobuf.Struct is represented with JsonObject when used in a
|
|
312
|
+
// field, except when used in google.protobuf.Value.
|
|
313
|
+
return wktStructToLocal(value.message);
|
|
314
|
+
}
|
|
315
|
+
return value.message;
|
|
316
|
+
}
|
|
317
|
+
function messageToReflect(field, value, check) {
|
|
318
|
+
if (value !== undefined) {
|
|
319
|
+
if ((0, wrappers_js_1.isWrapperDesc)(field.message) &&
|
|
320
|
+
!field.oneof &&
|
|
321
|
+
field.fieldKind == "message") {
|
|
322
|
+
// Types from google/protobuf/wrappers.proto are unwrapped when used in
|
|
323
|
+
// a singular field that is not part of a oneof group.
|
|
324
|
+
value = {
|
|
325
|
+
$typeName: field.message.typeName,
|
|
326
|
+
value: longToReflect(field.message.fields[0], value),
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
else if (field.message.typeName == "google.protobuf.Struct" &&
|
|
330
|
+
field.parent.typeName != "google.protobuf.Value" &&
|
|
331
|
+
(0, guard_js_1.isObject)(value)) {
|
|
332
|
+
// google.protobuf.Struct is represented with JsonObject when used in a
|
|
333
|
+
// field, except when used in google.protobuf.Value.
|
|
334
|
+
value = wktStructToReflect(value);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return new ReflectMessageImpl(field.message, value, check);
|
|
338
|
+
}
|
|
293
339
|
function listItemToLocal(field, value) {
|
|
294
|
-
if (
|
|
295
|
-
return value
|
|
340
|
+
if (field.listKind == "message") {
|
|
341
|
+
return messageToLocal(field, value);
|
|
296
342
|
}
|
|
297
343
|
return longToLocal(field, value);
|
|
298
344
|
}
|
|
299
345
|
function listItemToReflect(field, value, check) {
|
|
300
346
|
if (field.listKind == "message") {
|
|
301
|
-
return
|
|
347
|
+
return messageToReflect(field, value, check);
|
|
302
348
|
}
|
|
303
349
|
return longToReflect(field, value);
|
|
304
350
|
}
|
|
305
351
|
function mapValueToLocal(field, value) {
|
|
306
|
-
if (
|
|
307
|
-
return value
|
|
352
|
+
if (field.mapKind == "message") {
|
|
353
|
+
return messageToLocal(field, value);
|
|
308
354
|
}
|
|
309
355
|
return longToLocal(field, value);
|
|
310
356
|
}
|
|
311
357
|
function mapValueToReflect(field, value, check) {
|
|
312
358
|
if (field.mapKind == "message") {
|
|
313
|
-
return
|
|
359
|
+
return messageToReflect(field, value, check);
|
|
314
360
|
}
|
|
315
361
|
return value;
|
|
316
362
|
}
|
|
@@ -414,3 +460,81 @@ function longToLocal(field, value) {
|
|
|
414
460
|
}
|
|
415
461
|
return value;
|
|
416
462
|
}
|
|
463
|
+
function wktStructToReflect(json) {
|
|
464
|
+
const struct = {
|
|
465
|
+
$typeName: "google.protobuf.Struct",
|
|
466
|
+
fields: {},
|
|
467
|
+
};
|
|
468
|
+
if ((0, guard_js_1.isObject)(json)) {
|
|
469
|
+
for (const [k, v] of Object.entries(json)) {
|
|
470
|
+
struct.fields[k] = wktValueToReflect(v);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return struct;
|
|
474
|
+
}
|
|
475
|
+
function wktStructToLocal(val) {
|
|
476
|
+
const json = {};
|
|
477
|
+
for (const [k, v] of Object.entries(val.fields)) {
|
|
478
|
+
json[k] = wktValueToLocal(v);
|
|
479
|
+
}
|
|
480
|
+
return json;
|
|
481
|
+
}
|
|
482
|
+
function wktValueToLocal(val) {
|
|
483
|
+
switch (val.kind.case) {
|
|
484
|
+
case "structValue":
|
|
485
|
+
return wktStructToLocal(val.kind.value);
|
|
486
|
+
case "listValue":
|
|
487
|
+
return val.kind.value.values.map(wktValueToLocal);
|
|
488
|
+
case "nullValue":
|
|
489
|
+
case undefined:
|
|
490
|
+
return null;
|
|
491
|
+
default:
|
|
492
|
+
return val.kind.value;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
function wktValueToReflect(json) {
|
|
496
|
+
const value = {
|
|
497
|
+
$typeName: "google.protobuf.Value",
|
|
498
|
+
kind: { case: undefined },
|
|
499
|
+
};
|
|
500
|
+
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- invalid input is unselected kind
|
|
501
|
+
switch (typeof json) {
|
|
502
|
+
case "number":
|
|
503
|
+
value.kind = { case: "numberValue", value: json };
|
|
504
|
+
break;
|
|
505
|
+
case "string":
|
|
506
|
+
value.kind = { case: "stringValue", value: json };
|
|
507
|
+
break;
|
|
508
|
+
case "boolean":
|
|
509
|
+
value.kind = { case: "boolValue", value: json };
|
|
510
|
+
break;
|
|
511
|
+
case "object":
|
|
512
|
+
if (json === null) {
|
|
513
|
+
const nullValue = 0;
|
|
514
|
+
value.kind = { case: "nullValue", value: nullValue };
|
|
515
|
+
}
|
|
516
|
+
else if (Array.isArray(json)) {
|
|
517
|
+
const listValue = {
|
|
518
|
+
$typeName: "google.protobuf.ListValue",
|
|
519
|
+
values: [],
|
|
520
|
+
};
|
|
521
|
+
if (Array.isArray(json)) {
|
|
522
|
+
for (const e of json) {
|
|
523
|
+
listValue.values.push(wktValueToReflect(e));
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
value.kind = {
|
|
527
|
+
case: "listValue",
|
|
528
|
+
value: listValue,
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
else {
|
|
532
|
+
value.kind = {
|
|
533
|
+
case: "structValue",
|
|
534
|
+
value: wktStructToReflect(json),
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
break;
|
|
538
|
+
}
|
|
539
|
+
return value;
|
|
540
|
+
}
|
|
@@ -6,7 +6,7 @@ export type ScalarValue<T = ScalarType, LongAsString extends boolean = false> =
|
|
|
6
6
|
/**
|
|
7
7
|
* Returns true if both scalar values are equal.
|
|
8
8
|
*/
|
|
9
|
-
export declare function scalarEquals(type: ScalarType, a:
|
|
9
|
+
export declare function scalarEquals(type: ScalarType, a: ScalarValue | undefined, b: ScalarValue | undefined): boolean;
|
|
10
10
|
/**
|
|
11
11
|
* Returns the zero value for the given scalar type.
|
|
12
12
|
*/
|
package/dist/cjs/registry.d.ts
CHANGED
|
@@ -39,8 +39,20 @@ export interface Registry {
|
|
|
39
39
|
getService(typeName: string): DescService | undefined;
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
|
-
* A
|
|
43
|
-
|
|
42
|
+
* A registry that allows adding and removing descriptors.
|
|
43
|
+
*/
|
|
44
|
+
export interface MutableRegistry extends Registry {
|
|
45
|
+
/**
|
|
46
|
+
* Adds the given descriptor - but not types nested within - to the registry.
|
|
47
|
+
*/
|
|
48
|
+
add(desc: DescMessage | DescEnum | DescExtension | DescService): void;
|
|
49
|
+
/**
|
|
50
|
+
* Remove the given descriptor - but not types nested within - from the registry.
|
|
51
|
+
*/
|
|
52
|
+
remove(desc: DescMessage | DescEnum | DescExtension | DescService): void;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A registry that includes files.
|
|
44
56
|
*/
|
|
45
57
|
export interface FileRegistry extends Registry {
|
|
46
58
|
/**
|
|
@@ -64,6 +76,10 @@ export interface FileRegistry extends Registry {
|
|
|
64
76
|
* For duplicate descriptors (same type name), the one given last wins.
|
|
65
77
|
*/
|
|
66
78
|
export declare function createRegistry(...input: (Registry | DescFile | DescMessage | DescEnum | DescExtension | DescService)[]): Registry;
|
|
79
|
+
/**
|
|
80
|
+
* Create a registry that allows adding and removing descriptors.
|
|
81
|
+
*/
|
|
82
|
+
export declare function createMutableRegistry(...input: (Registry | DescFile | DescMessage | DescEnum | DescExtension | DescService)[]): MutableRegistry;
|
|
67
83
|
/**
|
|
68
84
|
* Create a registry (including file descriptors) from a google.protobuf.FileDescriptorSet
|
|
69
85
|
* message.
|
package/dist/cjs/registry.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// See the License for the specific language governing permissions and
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.maximumEdition = exports.minimumEdition = exports.createFileRegistry = exports.createRegistry = void 0;
|
|
16
|
+
exports.maximumEdition = exports.minimumEdition = exports.createFileRegistry = exports.createMutableRegistry = exports.createRegistry = void 0;
|
|
17
17
|
const descriptors_js_1 = require("./descriptors.js");
|
|
18
18
|
const text_format_js_1 = require("./wire/text-format.js");
|
|
19
19
|
const nested_types_js_1 = require("./reflect/nested-types.js");
|
|
@@ -31,29 +31,25 @@ const names_js_1 = require("./reflect/names.js");
|
|
|
31
31
|
* For duplicate descriptors (same type name), the one given last wins.
|
|
32
32
|
*/
|
|
33
33
|
function createRegistry(...input) {
|
|
34
|
-
|
|
35
|
-
for (const i of input) {
|
|
36
|
-
switch (i.kind) {
|
|
37
|
-
case "registry":
|
|
38
|
-
for (const n of i) {
|
|
39
|
-
reg.add(n);
|
|
40
|
-
}
|
|
41
|
-
break;
|
|
42
|
-
case "file":
|
|
43
|
-
for (const n of (0, nested_types_js_1.nestedTypes)(i)) {
|
|
44
|
-
reg.add(n);
|
|
45
|
-
}
|
|
46
|
-
break;
|
|
47
|
-
default:
|
|
48
|
-
reg.add(i);
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return reg;
|
|
34
|
+
return initBaseRegistry(input);
|
|
53
35
|
}
|
|
54
36
|
exports.createRegistry = createRegistry;
|
|
37
|
+
/**
|
|
38
|
+
* Create a registry that allows adding and removing descriptors.
|
|
39
|
+
*/
|
|
40
|
+
function createMutableRegistry(...input) {
|
|
41
|
+
const reg = initBaseRegistry(input);
|
|
42
|
+
return Object.assign(Object.assign({}, reg), { remove(desc) {
|
|
43
|
+
var _a;
|
|
44
|
+
if (desc.kind == "extension") {
|
|
45
|
+
(_a = reg.extendees.get(desc.extendee.typeName)) === null || _a === void 0 ? void 0 : _a.delete(desc.number);
|
|
46
|
+
}
|
|
47
|
+
reg.types.delete(desc.typeName);
|
|
48
|
+
} });
|
|
49
|
+
}
|
|
50
|
+
exports.createMutableRegistry = createMutableRegistry;
|
|
55
51
|
function createFileRegistry(...args) {
|
|
56
|
-
const registry =
|
|
52
|
+
const registry = createBaseRegistry();
|
|
57
53
|
if ("$typeName" in args[0] &&
|
|
58
54
|
args[0].$typeName == "google.protobuf.FileDescriptorSet") {
|
|
59
55
|
for (const file of args[0].file) {
|
|
@@ -80,14 +76,14 @@ function createFileRegistry(...args) {
|
|
|
80
76
|
throw new Error(`Unable to resolve ${protoFileName}, imported by ${file.name}`);
|
|
81
77
|
}
|
|
82
78
|
if ("kind" in dep) {
|
|
83
|
-
|
|
79
|
+
registry.addFile(dep, false, true);
|
|
84
80
|
}
|
|
85
81
|
else {
|
|
86
82
|
seen.add(dep.name);
|
|
87
83
|
deps.push(dep);
|
|
88
84
|
}
|
|
89
85
|
}
|
|
90
|
-
return
|
|
86
|
+
return deps.concat(...deps.map(recurseDeps));
|
|
91
87
|
}
|
|
92
88
|
for (const file of [input, ...recurseDeps(input)].reverse()) {
|
|
93
89
|
addFile(file, registry);
|
|
@@ -96,10 +92,7 @@ function createFileRegistry(...args) {
|
|
|
96
92
|
else {
|
|
97
93
|
for (const fileReg of args) {
|
|
98
94
|
for (const file of fileReg.files) {
|
|
99
|
-
registry.
|
|
100
|
-
for (const type of (0, nested_types_js_1.nestedTypes)(file)) {
|
|
101
|
-
registry.add(type);
|
|
102
|
-
}
|
|
95
|
+
registry.addFile(file);
|
|
103
96
|
}
|
|
104
97
|
}
|
|
105
98
|
}
|
|
@@ -107,47 +100,46 @@ function createFileRegistry(...args) {
|
|
|
107
100
|
}
|
|
108
101
|
exports.createFileRegistry = createFileRegistry;
|
|
109
102
|
/**
|
|
110
|
-
* Create a mutable file registry.
|
|
111
103
|
* @private
|
|
112
104
|
*/
|
|
113
|
-
function
|
|
105
|
+
function createBaseRegistry() {
|
|
114
106
|
const types = new Map();
|
|
115
107
|
const extendees = new Map();
|
|
116
108
|
const files = new Map();
|
|
117
109
|
return {
|
|
118
110
|
kind: "registry",
|
|
111
|
+
types,
|
|
112
|
+
extendees,
|
|
119
113
|
[Symbol.iterator]() {
|
|
120
114
|
return types.values();
|
|
121
115
|
},
|
|
122
116
|
get files() {
|
|
123
117
|
return files.values();
|
|
124
118
|
},
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
// eslint-disable-next-line no-fallthrough
|
|
139
|
-
default:
|
|
140
|
-
types.set(desc.typeName, desc);
|
|
119
|
+
addFile(file, skipTypes, withDeps) {
|
|
120
|
+
files.set(file.proto.name, file);
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
122
|
+
if (!skipTypes) {
|
|
123
|
+
for (const type of (0, nested_types_js_1.nestedTypes)(file)) {
|
|
124
|
+
this.add(type);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
128
|
+
if (withDeps) {
|
|
129
|
+
for (const f of file.dependencies) {
|
|
130
|
+
this.addFile(f, skipTypes, withDeps);
|
|
131
|
+
}
|
|
141
132
|
}
|
|
142
133
|
},
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
134
|
+
add(desc) {
|
|
135
|
+
if (desc.kind == "extension") {
|
|
136
|
+
let numberToExt = extendees.get(desc.extendee.typeName);
|
|
137
|
+
if (!numberToExt) {
|
|
138
|
+
extendees.set(desc.extendee.typeName, (numberToExt = new Map()));
|
|
139
|
+
}
|
|
140
|
+
numberToExt.set(desc.number, desc);
|
|
150
141
|
}
|
|
142
|
+
types.set(desc.typeName, desc);
|
|
151
143
|
},
|
|
152
144
|
get(typeName) {
|
|
153
145
|
return types.get(typeName);
|
|
@@ -178,16 +170,26 @@ function createMutableRegistry() {
|
|
|
178
170
|
};
|
|
179
171
|
}
|
|
180
172
|
/**
|
|
181
|
-
*
|
|
173
|
+
* @private
|
|
182
174
|
*/
|
|
183
|
-
function
|
|
184
|
-
|
|
185
|
-
for (const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
175
|
+
function initBaseRegistry(inputs) {
|
|
176
|
+
const registry = createBaseRegistry();
|
|
177
|
+
for (const input of inputs) {
|
|
178
|
+
switch (input.kind) {
|
|
179
|
+
case "registry":
|
|
180
|
+
for (const n of input) {
|
|
181
|
+
registry.add(n);
|
|
182
|
+
}
|
|
183
|
+
break;
|
|
184
|
+
case "file":
|
|
185
|
+
registry.addFile(input);
|
|
186
|
+
break;
|
|
187
|
+
default:
|
|
188
|
+
registry.add(input);
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
190
191
|
}
|
|
192
|
+
return registry;
|
|
191
193
|
}
|
|
192
194
|
// bootstrap-inject google.protobuf.Edition.EDITION_PROTO2: const $name: Edition.$localName = $number;
|
|
193
195
|
const EDITION_PROTO2 = 998;
|
|
@@ -306,7 +308,7 @@ function addFile(proto, reg) {
|
|
|
306
308
|
addFields(message, reg, mapEntries);
|
|
307
309
|
addExtensions(message, reg);
|
|
308
310
|
}
|
|
309
|
-
reg.
|
|
311
|
+
reg.addFile(file, true);
|
|
310
312
|
}
|
|
311
313
|
/**
|
|
312
314
|
* Create descriptors for extensions, and add them to the message / file,
|
package/dist/cjs/to-binary.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface BinaryWriteOptions {
|
|
|
17
17
|
*/
|
|
18
18
|
writeUnknownFields: boolean;
|
|
19
19
|
}
|
|
20
|
-
export declare function toBinary<Desc extends DescMessage>(
|
|
20
|
+
export declare function toBinary<Desc extends DescMessage>(schema: Desc, message: MessageShape<Desc>, options?: Partial<BinaryWriteOptions>): Uint8Array;
|
|
21
21
|
/**
|
|
22
22
|
* @private
|
|
23
23
|
*/
|
package/dist/cjs/to-binary.js
CHANGED
|
@@ -26,8 +26,8 @@ const writeDefaults = {
|
|
|
26
26
|
function makeWriteOptions(options) {
|
|
27
27
|
return options ? Object.assign(Object.assign({}, writeDefaults), options) : writeDefaults;
|
|
28
28
|
}
|
|
29
|
-
function toBinary(
|
|
30
|
-
return writeFields(new binary_encoding_js_1.BinaryWriter(), makeWriteOptions(options), (0, reflect_js_1.reflect)(
|
|
29
|
+
function toBinary(schema, message, options) {
|
|
30
|
+
return writeFields(new binary_encoding_js_1.BinaryWriter(), makeWriteOptions(options), (0, reflect_js_1.reflect)(schema, message)).finish();
|
|
31
31
|
}
|
|
32
32
|
exports.toBinary = toBinary;
|
|
33
33
|
function writeFields(writer, opts, msg) {
|
package/dist/cjs/to-json.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type DescMessage } from "./descriptors.js";
|
|
1
|
+
import { type DescEnum, type DescMessage } from "./descriptors.js";
|
|
2
2
|
import type { JsonValue } from "./json-value.js";
|
|
3
3
|
import type { Registry } from "./registry.js";
|
|
4
|
-
import type { MessageShape } from "./types.js";
|
|
4
|
+
import type { EnumJsonType, EnumShape, MessageJsonType, MessageShape } from "./types.js";
|
|
5
5
|
/**
|
|
6
6
|
* Options for serializing to JSON.
|
|
7
7
|
*/
|
|
@@ -44,8 +44,18 @@ export interface JsonWriteStringOptions extends JsonWriteOptions {
|
|
|
44
44
|
* Serialize the message to a JSON value, a JavaScript value that can be
|
|
45
45
|
* passed to JSON.stringify().
|
|
46
46
|
*/
|
|
47
|
-
export declare function toJson<Desc extends DescMessage>(
|
|
47
|
+
export declare function toJson<Desc extends DescMessage, Opts extends Partial<JsonWriteOptions> | undefined = undefined>(schema: Desc, message: MessageShape<Desc>, options?: Opts): ToJson<Desc, Opts>;
|
|
48
|
+
type ToJson<Desc extends DescMessage, Opts extends undefined | Partial<JsonWriteOptions>> = Opts extends undefined | {
|
|
49
|
+
alwaysEmitImplicit?: false;
|
|
50
|
+
enumAsInteger?: false;
|
|
51
|
+
useProtoFieldName?: false;
|
|
52
|
+
} ? MessageJsonType<Desc> : JsonValue;
|
|
48
53
|
/**
|
|
49
54
|
* Serialize the message to a JSON string.
|
|
50
55
|
*/
|
|
51
|
-
export declare function toJsonString<Desc extends DescMessage>(
|
|
56
|
+
export declare function toJsonString<Desc extends DescMessage>(schema: Desc, message: MessageShape<Desc>, options?: Partial<JsonWriteStringOptions>): string;
|
|
57
|
+
/**
|
|
58
|
+
* Serialize a single enum value to JSON.
|
|
59
|
+
*/
|
|
60
|
+
export declare function enumToJson<Desc extends DescEnum>(descEnum: Desc, value: EnumShape<Desc>): EnumJsonType<Desc>;
|
|
61
|
+
export {};
|