@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
|
@@ -1,32 +1,43 @@
|
|
|
1
1
|
import { type DescField, type DescMessage } from "../descriptors.js";
|
|
2
2
|
import type { MessageShape } from "../types.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ReflectList, ReflectMap, ReflectMessage } from "./reflect-types.js";
|
|
4
4
|
/**
|
|
5
5
|
* Create a ReflectMessage.
|
|
6
6
|
*/
|
|
7
|
-
export declare function reflect<Desc extends DescMessage>(messageDesc: Desc, message?: MessageShape<Desc>,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
* improved by disabling validation by setting disableFieldValueCheck to
|
|
17
|
-
* `false`.
|
|
18
|
-
*/
|
|
19
|
-
disableFieldValueCheck?: boolean;
|
|
20
|
-
}): ReflectMessage;
|
|
7
|
+
export declare function reflect<Desc extends DescMessage>(messageDesc: Desc, message?: MessageShape<Desc>,
|
|
8
|
+
/**
|
|
9
|
+
* By default, field values are validated when setting them. For example,
|
|
10
|
+
* a value for an uint32 field must be a ECMAScript Number >= 0.
|
|
11
|
+
*
|
|
12
|
+
* When field values are trusted, performance can be improved by disabling
|
|
13
|
+
* checks.
|
|
14
|
+
*/
|
|
15
|
+
check?: boolean): ReflectMessage;
|
|
21
16
|
/**
|
|
22
17
|
* Create a ReflectList.
|
|
23
18
|
*/
|
|
24
19
|
export declare function reflectList<V>(field: DescField & {
|
|
25
20
|
fieldKind: "list";
|
|
26
|
-
}, unsafeInput?: unknown[],
|
|
21
|
+
}, unsafeInput?: unknown[],
|
|
22
|
+
/**
|
|
23
|
+
* By default, field values are validated when setting them. For example,
|
|
24
|
+
* a value for an uint32 field must be a ECMAScript Number >= 0.
|
|
25
|
+
*
|
|
26
|
+
* When field values are trusted, performance can be improved by disabling
|
|
27
|
+
* checks.
|
|
28
|
+
*/
|
|
29
|
+
check?: boolean): ReflectList<V>;
|
|
27
30
|
/**
|
|
28
31
|
* Create a ReflectMap.
|
|
29
32
|
*/
|
|
30
|
-
export declare function reflectMap<K
|
|
33
|
+
export declare function reflectMap<K = unknown, V = unknown>(field: DescField & {
|
|
31
34
|
fieldKind: "map";
|
|
32
|
-
}, unsafeInput?: Record<string, unknown>,
|
|
35
|
+
}, unsafeInput?: Record<string, unknown>,
|
|
36
|
+
/**
|
|
37
|
+
* By default, field values are validated when setting them. For example,
|
|
38
|
+
* a value for an uint32 field must be a ECMAScript Number >= 0.
|
|
39
|
+
*
|
|
40
|
+
* When field values are trusted, performance can be improved by disabling
|
|
41
|
+
* checks.
|
|
42
|
+
*/
|
|
43
|
+
check?: boolean): ReflectMap<K, V>;
|
|
@@ -19,14 +19,20 @@ import { create } from "../create.js";
|
|
|
19
19
|
import { isWrapper, isWrapperDesc } from "../wkt/wrappers.js";
|
|
20
20
|
import { scalarZeroValue } from "./scalar.js";
|
|
21
21
|
import { protoInt64 } from "../proto-int64.js";
|
|
22
|
-
import { isReflectList, isReflectMap, isReflectMessage } from "./guard.js";
|
|
22
|
+
import { isObject, isReflectList, isReflectMap, isReflectMessage, } from "./guard.js";
|
|
23
23
|
/**
|
|
24
24
|
* Create a ReflectMessage.
|
|
25
25
|
*/
|
|
26
26
|
export function reflect(messageDesc, message,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
/**
|
|
28
|
+
* By default, field values are validated when setting them. For example,
|
|
29
|
+
* a value for an uint32 field must be a ECMAScript Number >= 0.
|
|
30
|
+
*
|
|
31
|
+
* When field values are trusted, performance can be improved by disabling
|
|
32
|
+
* checks.
|
|
33
|
+
*/
|
|
34
|
+
check = true) {
|
|
35
|
+
return new ReflectMessageImpl(messageDesc, message, check);
|
|
30
36
|
}
|
|
31
37
|
class ReflectMessageImpl {
|
|
32
38
|
get sortedFields() {
|
|
@@ -35,9 +41,7 @@ class ReflectMessageImpl {
|
|
|
35
41
|
.concat()
|
|
36
42
|
.sort((a, b) => a.number - b.number)));
|
|
37
43
|
}
|
|
38
|
-
constructor(messageDesc, message,
|
|
39
|
-
// TODO either remove this option, or support it in reflect-list and reflect-map as well
|
|
40
|
-
check = true) {
|
|
44
|
+
constructor(messageDesc, message, check = true) {
|
|
41
45
|
this.lists = new Map();
|
|
42
46
|
this.maps = new Map();
|
|
43
47
|
this.check = check;
|
|
@@ -67,7 +71,7 @@ class ReflectMessageImpl {
|
|
|
67
71
|
}
|
|
68
72
|
get(field) {
|
|
69
73
|
assertOwn(this.message, field);
|
|
70
|
-
|
|
74
|
+
const value = unsafeGet(this.message, field);
|
|
71
75
|
switch (field.fieldKind) {
|
|
72
76
|
case "list":
|
|
73
77
|
// eslint-disable-next-line no-case-declarations
|
|
@@ -84,15 +88,7 @@ class ReflectMessageImpl {
|
|
|
84
88
|
}
|
|
85
89
|
return map;
|
|
86
90
|
case "message":
|
|
87
|
-
|
|
88
|
-
!field.oneof &&
|
|
89
|
-
isWrapperDesc(field.message)) {
|
|
90
|
-
value = {
|
|
91
|
-
$typeName: field.message.typeName,
|
|
92
|
-
value: longToReflect(field.message.fields[0], value),
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
return new ReflectMessageImpl(field.message, value, this.check);
|
|
91
|
+
return messageToReflect(field, value, this.check);
|
|
96
92
|
case "scalar":
|
|
97
93
|
return (value === undefined
|
|
98
94
|
? scalarZeroValue(field.scalar, false)
|
|
@@ -106,22 +102,20 @@ class ReflectMessageImpl {
|
|
|
106
102
|
if (this.check) {
|
|
107
103
|
const err = checkField(field, value);
|
|
108
104
|
if (err) {
|
|
109
|
-
|
|
105
|
+
throw err;
|
|
110
106
|
}
|
|
111
107
|
}
|
|
112
108
|
let local;
|
|
113
|
-
if (
|
|
114
|
-
local = value
|
|
109
|
+
if (field.fieldKind == "message") {
|
|
110
|
+
local = messageToLocal(field, value);
|
|
115
111
|
}
|
|
116
|
-
else if (
|
|
117
|
-
|
|
118
|
-
local = !field.oneof && isWrapper(msg) ? msg.value : msg;
|
|
112
|
+
else if (isReflectMap(value) || isReflectList(value)) {
|
|
113
|
+
local = value[unsafeLocal];
|
|
119
114
|
}
|
|
120
115
|
else {
|
|
121
116
|
local = longToLocal(field, value);
|
|
122
117
|
}
|
|
123
118
|
unsafeSet(this.message, field, local);
|
|
124
|
-
return undefined;
|
|
125
119
|
}
|
|
126
120
|
getUnknown() {
|
|
127
121
|
return this.message.$unknown;
|
|
@@ -138,7 +132,15 @@ function assertOwn(owner, member) {
|
|
|
138
132
|
/**
|
|
139
133
|
* Create a ReflectList.
|
|
140
134
|
*/
|
|
141
|
-
export function reflectList(field, unsafeInput,
|
|
135
|
+
export function reflectList(field, unsafeInput,
|
|
136
|
+
/**
|
|
137
|
+
* By default, field values are validated when setting them. For example,
|
|
138
|
+
* a value for an uint32 field must be a ECMAScript Number >= 0.
|
|
139
|
+
*
|
|
140
|
+
* When field values are trusted, performance can be improved by disabling
|
|
141
|
+
* checks.
|
|
142
|
+
*/
|
|
143
|
+
check = true) {
|
|
142
144
|
return new ReflectListImpl(field, unsafeInput !== null && unsafeInput !== void 0 ? unsafeInput : [], check);
|
|
143
145
|
}
|
|
144
146
|
class ReflectListImpl {
|
|
@@ -161,29 +163,24 @@ class ReflectListImpl {
|
|
|
161
163
|
}
|
|
162
164
|
set(index, item) {
|
|
163
165
|
if (index < 0 || index >= this._arr.length) {
|
|
164
|
-
|
|
166
|
+
throw new FieldError(this._field, `list item #${index + 1}: out of range`);
|
|
165
167
|
}
|
|
166
168
|
if (this.check) {
|
|
167
169
|
const err = checkListItem(this._field, index, item);
|
|
168
170
|
if (err) {
|
|
169
|
-
|
|
171
|
+
throw err;
|
|
170
172
|
}
|
|
171
173
|
}
|
|
172
174
|
this._arr[index] = listItemToLocal(this._field, item);
|
|
173
|
-
return undefined;
|
|
174
175
|
}
|
|
175
|
-
add(
|
|
176
|
+
add(item) {
|
|
176
177
|
if (this.check) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return err;
|
|
181
|
-
}
|
|
178
|
+
const err = checkListItem(this._field, this._arr.length, item);
|
|
179
|
+
if (err) {
|
|
180
|
+
throw err;
|
|
182
181
|
}
|
|
183
182
|
}
|
|
184
|
-
|
|
185
|
-
this._arr.push(listItemToLocal(this._field, item));
|
|
186
|
-
}
|
|
183
|
+
this._arr.push(listItemToLocal(this._field, item));
|
|
187
184
|
return undefined;
|
|
188
185
|
}
|
|
189
186
|
clear() {
|
|
@@ -209,7 +206,15 @@ class ReflectListImpl {
|
|
|
209
206
|
/**
|
|
210
207
|
* Create a ReflectMap.
|
|
211
208
|
*/
|
|
212
|
-
export function reflectMap(field, unsafeInput,
|
|
209
|
+
export function reflectMap(field, unsafeInput,
|
|
210
|
+
/**
|
|
211
|
+
* By default, field values are validated when setting them. For example,
|
|
212
|
+
* a value for an uint32 field must be a ECMAScript Number >= 0.
|
|
213
|
+
*
|
|
214
|
+
* When field values are trusted, performance can be improved by disabling
|
|
215
|
+
* checks.
|
|
216
|
+
*/
|
|
217
|
+
check = true) {
|
|
213
218
|
return new ReflectMapImpl(field, unsafeInput, check);
|
|
214
219
|
}
|
|
215
220
|
class ReflectMapImpl {
|
|
@@ -225,11 +230,11 @@ class ReflectMapImpl {
|
|
|
225
230
|
if (this.check) {
|
|
226
231
|
const err = checkMapEntry(this._field, key, value);
|
|
227
232
|
if (err) {
|
|
228
|
-
|
|
233
|
+
throw err;
|
|
229
234
|
}
|
|
230
235
|
}
|
|
231
236
|
this.obj[mapKeyToLocal(key)] = mapValueToLocal(this._field, value);
|
|
232
|
-
return
|
|
237
|
+
return this;
|
|
233
238
|
}
|
|
234
239
|
delete(key) {
|
|
235
240
|
const k = mapKeyToLocal(key);
|
|
@@ -284,27 +289,68 @@ class ReflectMapImpl {
|
|
|
284
289
|
}
|
|
285
290
|
}
|
|
286
291
|
}
|
|
292
|
+
function messageToLocal(field, value) {
|
|
293
|
+
if (!isReflectMessage(value)) {
|
|
294
|
+
return value;
|
|
295
|
+
}
|
|
296
|
+
if (isWrapper(value.message) &&
|
|
297
|
+
!field.oneof &&
|
|
298
|
+
field.fieldKind == "message") {
|
|
299
|
+
// Types from google/protobuf/wrappers.proto are unwrapped when used in
|
|
300
|
+
// a singular field that is not part of a oneof group.
|
|
301
|
+
return value.message.value;
|
|
302
|
+
}
|
|
303
|
+
if (value.desc.typeName == "google.protobuf.Struct" &&
|
|
304
|
+
field.parent.typeName != "google.protobuf.Value") {
|
|
305
|
+
// google.protobuf.Struct is represented with JsonObject when used in a
|
|
306
|
+
// field, except when used in google.protobuf.Value.
|
|
307
|
+
return wktStructToLocal(value.message);
|
|
308
|
+
}
|
|
309
|
+
return value.message;
|
|
310
|
+
}
|
|
311
|
+
function messageToReflect(field, value, check) {
|
|
312
|
+
if (value !== undefined) {
|
|
313
|
+
if (isWrapperDesc(field.message) &&
|
|
314
|
+
!field.oneof &&
|
|
315
|
+
field.fieldKind == "message") {
|
|
316
|
+
// Types from google/protobuf/wrappers.proto are unwrapped when used in
|
|
317
|
+
// a singular field that is not part of a oneof group.
|
|
318
|
+
value = {
|
|
319
|
+
$typeName: field.message.typeName,
|
|
320
|
+
value: longToReflect(field.message.fields[0], value),
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
else if (field.message.typeName == "google.protobuf.Struct" &&
|
|
324
|
+
field.parent.typeName != "google.protobuf.Value" &&
|
|
325
|
+
isObject(value)) {
|
|
326
|
+
// google.protobuf.Struct is represented with JsonObject when used in a
|
|
327
|
+
// field, except when used in google.protobuf.Value.
|
|
328
|
+
value = wktStructToReflect(value);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return new ReflectMessageImpl(field.message, value, check);
|
|
332
|
+
}
|
|
287
333
|
function listItemToLocal(field, value) {
|
|
288
|
-
if (
|
|
289
|
-
return value
|
|
334
|
+
if (field.listKind == "message") {
|
|
335
|
+
return messageToLocal(field, value);
|
|
290
336
|
}
|
|
291
337
|
return longToLocal(field, value);
|
|
292
338
|
}
|
|
293
339
|
function listItemToReflect(field, value, check) {
|
|
294
340
|
if (field.listKind == "message") {
|
|
295
|
-
return
|
|
341
|
+
return messageToReflect(field, value, check);
|
|
296
342
|
}
|
|
297
343
|
return longToReflect(field, value);
|
|
298
344
|
}
|
|
299
345
|
function mapValueToLocal(field, value) {
|
|
300
|
-
if (
|
|
301
|
-
return value
|
|
346
|
+
if (field.mapKind == "message") {
|
|
347
|
+
return messageToLocal(field, value);
|
|
302
348
|
}
|
|
303
349
|
return longToLocal(field, value);
|
|
304
350
|
}
|
|
305
351
|
function mapValueToReflect(field, value, check) {
|
|
306
352
|
if (field.mapKind == "message") {
|
|
307
|
-
return
|
|
353
|
+
return messageToReflect(field, value, check);
|
|
308
354
|
}
|
|
309
355
|
return value;
|
|
310
356
|
}
|
|
@@ -408,3 +454,81 @@ function longToLocal(field, value) {
|
|
|
408
454
|
}
|
|
409
455
|
return value;
|
|
410
456
|
}
|
|
457
|
+
function wktStructToReflect(json) {
|
|
458
|
+
const struct = {
|
|
459
|
+
$typeName: "google.protobuf.Struct",
|
|
460
|
+
fields: {},
|
|
461
|
+
};
|
|
462
|
+
if (isObject(json)) {
|
|
463
|
+
for (const [k, v] of Object.entries(json)) {
|
|
464
|
+
struct.fields[k] = wktValueToReflect(v);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
return struct;
|
|
468
|
+
}
|
|
469
|
+
function wktStructToLocal(val) {
|
|
470
|
+
const json = {};
|
|
471
|
+
for (const [k, v] of Object.entries(val.fields)) {
|
|
472
|
+
json[k] = wktValueToLocal(v);
|
|
473
|
+
}
|
|
474
|
+
return json;
|
|
475
|
+
}
|
|
476
|
+
function wktValueToLocal(val) {
|
|
477
|
+
switch (val.kind.case) {
|
|
478
|
+
case "structValue":
|
|
479
|
+
return wktStructToLocal(val.kind.value);
|
|
480
|
+
case "listValue":
|
|
481
|
+
return val.kind.value.values.map(wktValueToLocal);
|
|
482
|
+
case "nullValue":
|
|
483
|
+
case undefined:
|
|
484
|
+
return null;
|
|
485
|
+
default:
|
|
486
|
+
return val.kind.value;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
function wktValueToReflect(json) {
|
|
490
|
+
const value = {
|
|
491
|
+
$typeName: "google.protobuf.Value",
|
|
492
|
+
kind: { case: undefined },
|
|
493
|
+
};
|
|
494
|
+
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- invalid input is unselected kind
|
|
495
|
+
switch (typeof json) {
|
|
496
|
+
case "number":
|
|
497
|
+
value.kind = { case: "numberValue", value: json };
|
|
498
|
+
break;
|
|
499
|
+
case "string":
|
|
500
|
+
value.kind = { case: "stringValue", value: json };
|
|
501
|
+
break;
|
|
502
|
+
case "boolean":
|
|
503
|
+
value.kind = { case: "boolValue", value: json };
|
|
504
|
+
break;
|
|
505
|
+
case "object":
|
|
506
|
+
if (json === null) {
|
|
507
|
+
const nullValue = 0;
|
|
508
|
+
value.kind = { case: "nullValue", value: nullValue };
|
|
509
|
+
}
|
|
510
|
+
else if (Array.isArray(json)) {
|
|
511
|
+
const listValue = {
|
|
512
|
+
$typeName: "google.protobuf.ListValue",
|
|
513
|
+
values: [],
|
|
514
|
+
};
|
|
515
|
+
if (Array.isArray(json)) {
|
|
516
|
+
for (const e of json) {
|
|
517
|
+
listValue.values.push(wktValueToReflect(e));
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
value.kind = {
|
|
521
|
+
case: "listValue",
|
|
522
|
+
value: listValue,
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
else {
|
|
526
|
+
value.kind = {
|
|
527
|
+
case: "structValue",
|
|
528
|
+
value: wktStructToReflect(json),
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
break;
|
|
532
|
+
}
|
|
533
|
+
return value;
|
|
534
|
+
}
|
|
@@ -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/esm/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/esm/registry.js
CHANGED
|
@@ -28,28 +28,23 @@ import { protoCamelCase, safeObjectProperty } from "./reflect/names.js";
|
|
|
28
28
|
* For duplicate descriptors (same type name), the one given last wins.
|
|
29
29
|
*/
|
|
30
30
|
export function createRegistry(...input) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
reg.add(i);
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return reg;
|
|
31
|
+
return initBaseRegistry(input);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create a registry that allows adding and removing descriptors.
|
|
35
|
+
*/
|
|
36
|
+
export function createMutableRegistry(...input) {
|
|
37
|
+
const reg = initBaseRegistry(input);
|
|
38
|
+
return Object.assign(Object.assign({}, reg), { remove(desc) {
|
|
39
|
+
var _a;
|
|
40
|
+
if (desc.kind == "extension") {
|
|
41
|
+
(_a = reg.extendees.get(desc.extendee.typeName)) === null || _a === void 0 ? void 0 : _a.delete(desc.number);
|
|
42
|
+
}
|
|
43
|
+
reg.types.delete(desc.typeName);
|
|
44
|
+
} });
|
|
50
45
|
}
|
|
51
46
|
export function createFileRegistry(...args) {
|
|
52
|
-
const registry =
|
|
47
|
+
const registry = createBaseRegistry();
|
|
53
48
|
if ("$typeName" in args[0] &&
|
|
54
49
|
args[0].$typeName == "google.protobuf.FileDescriptorSet") {
|
|
55
50
|
for (const file of args[0].file) {
|
|
@@ -76,14 +71,14 @@ export function createFileRegistry(...args) {
|
|
|
76
71
|
throw new Error(`Unable to resolve ${protoFileName}, imported by ${file.name}`);
|
|
77
72
|
}
|
|
78
73
|
if ("kind" in dep) {
|
|
79
|
-
|
|
74
|
+
registry.addFile(dep, false, true);
|
|
80
75
|
}
|
|
81
76
|
else {
|
|
82
77
|
seen.add(dep.name);
|
|
83
78
|
deps.push(dep);
|
|
84
79
|
}
|
|
85
80
|
}
|
|
86
|
-
return
|
|
81
|
+
return deps.concat(...deps.map(recurseDeps));
|
|
87
82
|
}
|
|
88
83
|
for (const file of [input, ...recurseDeps(input)].reverse()) {
|
|
89
84
|
addFile(file, registry);
|
|
@@ -92,57 +87,53 @@ export function createFileRegistry(...args) {
|
|
|
92
87
|
else {
|
|
93
88
|
for (const fileReg of args) {
|
|
94
89
|
for (const file of fileReg.files) {
|
|
95
|
-
registry.
|
|
96
|
-
for (const type of nestedTypes(file)) {
|
|
97
|
-
registry.add(type);
|
|
98
|
-
}
|
|
90
|
+
registry.addFile(file);
|
|
99
91
|
}
|
|
100
92
|
}
|
|
101
93
|
}
|
|
102
94
|
return registry;
|
|
103
95
|
}
|
|
104
96
|
/**
|
|
105
|
-
* Create a mutable file registry.
|
|
106
97
|
* @private
|
|
107
98
|
*/
|
|
108
|
-
function
|
|
99
|
+
function createBaseRegistry() {
|
|
109
100
|
const types = new Map();
|
|
110
101
|
const extendees = new Map();
|
|
111
102
|
const files = new Map();
|
|
112
103
|
return {
|
|
113
104
|
kind: "registry",
|
|
105
|
+
types,
|
|
106
|
+
extendees,
|
|
114
107
|
[Symbol.iterator]() {
|
|
115
108
|
return types.values();
|
|
116
109
|
},
|
|
117
110
|
get files() {
|
|
118
111
|
return files.values();
|
|
119
112
|
},
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
// eslint-disable-next-line no-fallthrough
|
|
134
|
-
default:
|
|
135
|
-
types.set(desc.typeName, desc);
|
|
113
|
+
addFile(file, skipTypes, withDeps) {
|
|
114
|
+
files.set(file.proto.name, file);
|
|
115
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
116
|
+
if (!skipTypes) {
|
|
117
|
+
for (const type of nestedTypes(file)) {
|
|
118
|
+
this.add(type);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
122
|
+
if (withDeps) {
|
|
123
|
+
for (const f of file.dependencies) {
|
|
124
|
+
this.addFile(f, skipTypes, withDeps);
|
|
125
|
+
}
|
|
136
126
|
}
|
|
137
127
|
},
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
128
|
+
add(desc) {
|
|
129
|
+
if (desc.kind == "extension") {
|
|
130
|
+
let numberToExt = extendees.get(desc.extendee.typeName);
|
|
131
|
+
if (!numberToExt) {
|
|
132
|
+
extendees.set(desc.extendee.typeName, (numberToExt = new Map()));
|
|
133
|
+
}
|
|
134
|
+
numberToExt.set(desc.number, desc);
|
|
145
135
|
}
|
|
136
|
+
types.set(desc.typeName, desc);
|
|
146
137
|
},
|
|
147
138
|
get(typeName) {
|
|
148
139
|
return types.get(typeName);
|
|
@@ -173,16 +164,26 @@ function createMutableRegistry() {
|
|
|
173
164
|
};
|
|
174
165
|
}
|
|
175
166
|
/**
|
|
176
|
-
*
|
|
167
|
+
* @private
|
|
177
168
|
*/
|
|
178
|
-
function
|
|
179
|
-
|
|
180
|
-
for (const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
169
|
+
function initBaseRegistry(inputs) {
|
|
170
|
+
const registry = createBaseRegistry();
|
|
171
|
+
for (const input of inputs) {
|
|
172
|
+
switch (input.kind) {
|
|
173
|
+
case "registry":
|
|
174
|
+
for (const n of input) {
|
|
175
|
+
registry.add(n);
|
|
176
|
+
}
|
|
177
|
+
break;
|
|
178
|
+
case "file":
|
|
179
|
+
registry.addFile(input);
|
|
180
|
+
break;
|
|
181
|
+
default:
|
|
182
|
+
registry.add(input);
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
185
|
}
|
|
186
|
+
return registry;
|
|
186
187
|
}
|
|
187
188
|
// bootstrap-inject google.protobuf.Edition.EDITION_PROTO2: const $name: Edition.$localName = $number;
|
|
188
189
|
const EDITION_PROTO2 = 998;
|
|
@@ -301,7 +302,7 @@ function addFile(proto, reg) {
|
|
|
301
302
|
addFields(message, reg, mapEntries);
|
|
302
303
|
addExtensions(message, reg);
|
|
303
304
|
}
|
|
304
|
-
reg.
|
|
305
|
+
reg.addFile(file, true);
|
|
305
306
|
}
|
|
306
307
|
/**
|
|
307
308
|
* Create descriptors for extensions, and add them to the message / file,
|
package/dist/esm/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/esm/to-binary.js
CHANGED
|
@@ -23,8 +23,8 @@ const writeDefaults = {
|
|
|
23
23
|
function makeWriteOptions(options) {
|
|
24
24
|
return options ? Object.assign(Object.assign({}, writeDefaults), options) : writeDefaults;
|
|
25
25
|
}
|
|
26
|
-
export function toBinary(
|
|
27
|
-
return writeFields(new BinaryWriter(), makeWriteOptions(options), reflect(
|
|
26
|
+
export function toBinary(schema, message, options) {
|
|
27
|
+
return writeFields(new BinaryWriter(), makeWriteOptions(options), reflect(schema, message)).finish();
|
|
28
28
|
}
|
|
29
29
|
function writeFields(writer, opts, msg) {
|
|
30
30
|
var _a;
|