@bufbuild/protobuf 0.0.7 → 0.0.10
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 +34 -4
- package/dist/cjs/codegen-info.js +60 -0
- package/dist/cjs/create-descriptor-set.js +952 -0
- package/dist/cjs/create-registry-from-desc.js +380 -0
- package/dist/cjs/create-registry.js +75 -0
- package/dist/cjs/descriptor-set.js +0 -436
- package/dist/cjs/google/protobuf/struct_pb.js +1 -1
- package/dist/cjs/google/protobuf/type_pb.js +1 -1
- package/dist/cjs/index.js +17 -7
- package/dist/cjs/{descriptor-registry.js → legacy-descriptor-registry.js} +18 -10
- package/dist/cjs/legacy-descriptor-set.js +453 -0
- package/dist/cjs/legacy-type-registry.js +104 -0
- package/dist/cjs/private/enum.js +22 -31
- package/dist/cjs/private/field-wrapper.js +30 -1
- package/dist/cjs/private/field.js +1 -1
- package/dist/cjs/private/names.js +168 -29
- package/dist/cjs/proto2.js +2 -2
- package/dist/cjs/proto3.js +2 -2
- package/dist/cjs/type-registry.js +0 -87
- package/dist/esm/codegen-info.js +57 -0
- package/dist/esm/create-descriptor-set.js +947 -0
- package/dist/esm/create-registry-from-desc.js +375 -0
- package/dist/esm/create-registry.js +71 -0
- package/dist/esm/descriptor-set.js +1 -434
- package/dist/esm/google/protobuf/struct_pb.js +1 -1
- package/dist/esm/google/protobuf/type_pb.js +1 -1
- package/dist/esm/index.js +9 -3
- package/dist/esm/{descriptor-registry.js → legacy-descriptor-registry.js} +16 -8
- package/dist/esm/legacy-descriptor-set.js +449 -0
- package/dist/esm/legacy-type-registry.js +100 -0
- package/dist/esm/private/enum.js +22 -31
- package/dist/esm/private/field-wrapper.js +28 -0
- package/dist/esm/private/field.js +2 -2
- package/dist/esm/private/names.js +163 -24
- package/dist/esm/proto2.js +3 -3
- package/dist/esm/proto3.js +3 -3
- package/dist/esm/type-registry.js +1 -85
- package/dist/types/codegen-info.d.ts +19 -0
- package/dist/types/create-descriptor-set.d.ts +16 -0
- package/dist/types/create-registry-from-desc.d.ts +49 -0
- package/dist/types/create-registry.d.ts +8 -0
- package/dist/types/descriptor-set.d.ts +554 -108
- package/dist/types/enum.d.ts +9 -5
- package/dist/types/index.d.ts +9 -3
- package/dist/types/{descriptor-registry.d.ts → legacy-descriptor-registry.d.ts} +8 -6
- package/dist/types/legacy-descriptor-set.d.ts +152 -0
- package/dist/types/legacy-type-registry.d.ts +44 -0
- package/dist/types/private/enum.d.ts +4 -8
- package/dist/types/private/field-wrapper.d.ts +7 -0
- package/dist/types/private/message-type.d.ts +1 -4
- package/dist/types/private/names.d.ts +26 -8
- package/dist/types/private/proto-runtime.d.ts +2 -2
- package/dist/types/private/util.d.ts +1 -6
- package/dist/types/type-registry.d.ts +0 -38
- package/package.json +3 -2
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
// Copyright 2021-2022 Buf Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
import { assert } from "./private/assert.js";
|
|
15
|
+
import { proto3 } from "./proto3.js";
|
|
16
|
+
import { proto2 } from "./proto2.js";
|
|
17
|
+
import { localName } from "./private/names.js";
|
|
18
|
+
import { Timestamp } from "./google/protobuf/timestamp_pb.js";
|
|
19
|
+
import { Duration } from "./google/protobuf/duration_pb.js";
|
|
20
|
+
import { Any } from "./google/protobuf/any_pb.js";
|
|
21
|
+
import { Empty } from "./google/protobuf/empty_pb.js";
|
|
22
|
+
import { FieldMask } from "./google/protobuf/field_mask_pb.js";
|
|
23
|
+
import { ListValue, NullValue, Struct, Value, } from "./google/protobuf/struct_pb.js";
|
|
24
|
+
import { getEnumType } from "./private/enum.js";
|
|
25
|
+
import { BoolValue, BytesValue, DoubleValue, FloatValue, Int32Value, Int64Value, StringValue, UInt32Value, UInt64Value, } from "./google/protobuf/wrappers_pb.js";
|
|
26
|
+
import { FileDescriptorSet } from "./google/protobuf/descriptor_pb.js";
|
|
27
|
+
import { createDescriptorSet } from "./create-descriptor-set.js";
|
|
28
|
+
// well-known message types with specialized JSON representation
|
|
29
|
+
const wkMessages = [
|
|
30
|
+
Any,
|
|
31
|
+
Duration,
|
|
32
|
+
Empty,
|
|
33
|
+
FieldMask,
|
|
34
|
+
Struct,
|
|
35
|
+
Value,
|
|
36
|
+
ListValue,
|
|
37
|
+
Timestamp,
|
|
38
|
+
Duration,
|
|
39
|
+
DoubleValue,
|
|
40
|
+
FloatValue,
|
|
41
|
+
Int64Value,
|
|
42
|
+
Int32Value,
|
|
43
|
+
UInt32Value,
|
|
44
|
+
UInt64Value,
|
|
45
|
+
BoolValue,
|
|
46
|
+
StringValue,
|
|
47
|
+
BytesValue,
|
|
48
|
+
];
|
|
49
|
+
// well-known enum types with specialized JSON representation
|
|
50
|
+
const wkEnums = [getEnumType(NullValue)];
|
|
51
|
+
/**
|
|
52
|
+
* Create a registry from a set of descriptors. The types returned by this
|
|
53
|
+
* registry behave exactly like types from generated code.
|
|
54
|
+
*
|
|
55
|
+
* This function accepts google.protobuf.FileDescriptorSet in serialized or
|
|
56
|
+
* deserialized form. Alternatively, it also accepts a DescriptorSet (see
|
|
57
|
+
* createDescriptorSet()).
|
|
58
|
+
*
|
|
59
|
+
* By default, all well-known types with a specialized JSON representation
|
|
60
|
+
* are replaced with their generated counterpart in this package.
|
|
61
|
+
*/
|
|
62
|
+
export function createRegistryFromDescriptors(input, replaceWkt = true) {
|
|
63
|
+
const set = input instanceof Uint8Array || input instanceof FileDescriptorSet
|
|
64
|
+
? createDescriptorSet(input)
|
|
65
|
+
: input;
|
|
66
|
+
const enums = {};
|
|
67
|
+
const messages = {};
|
|
68
|
+
const services = {};
|
|
69
|
+
if (replaceWkt) {
|
|
70
|
+
for (const mt of wkMessages) {
|
|
71
|
+
messages[mt.typeName] = mt;
|
|
72
|
+
}
|
|
73
|
+
for (const et of wkEnums) {
|
|
74
|
+
enums[et.typeName] = et;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
/**
|
|
79
|
+
* May raise an error on invalid descriptors.
|
|
80
|
+
*/
|
|
81
|
+
findEnum(typeName) {
|
|
82
|
+
const existing = enums[typeName];
|
|
83
|
+
if (existing) {
|
|
84
|
+
return existing;
|
|
85
|
+
}
|
|
86
|
+
const desc = set.enums.get(typeName);
|
|
87
|
+
if (!desc) {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
const runtime = desc.file.syntax == "proto3" ? proto3 : proto2;
|
|
91
|
+
const type = runtime.makeEnumType(typeName, desc.values.map((u) => ({
|
|
92
|
+
no: u.number,
|
|
93
|
+
name: u.name,
|
|
94
|
+
localName: localName(u),
|
|
95
|
+
})), {});
|
|
96
|
+
enums[typeName] = type;
|
|
97
|
+
return type;
|
|
98
|
+
},
|
|
99
|
+
/**
|
|
100
|
+
* May raise an error on invalid descriptors.
|
|
101
|
+
*/
|
|
102
|
+
findMessage(typeName) {
|
|
103
|
+
const existing = messages[typeName];
|
|
104
|
+
if (existing) {
|
|
105
|
+
return existing;
|
|
106
|
+
}
|
|
107
|
+
const desc = set.messages.get(typeName);
|
|
108
|
+
if (!desc) {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
const runtime = desc.file.syntax == "proto3" ? proto3 : proto2;
|
|
112
|
+
const fields = [];
|
|
113
|
+
const type = runtime.makeMessageType(typeName, () => fields, {
|
|
114
|
+
localName: localName(desc),
|
|
115
|
+
});
|
|
116
|
+
messages[typeName] = type;
|
|
117
|
+
for (const field of desc.fields) {
|
|
118
|
+
const fieldInfo = makeFieldInfo(field, this);
|
|
119
|
+
fields.push(fieldInfo);
|
|
120
|
+
}
|
|
121
|
+
return type;
|
|
122
|
+
},
|
|
123
|
+
/**
|
|
124
|
+
* May raise an error on invalid descriptors.
|
|
125
|
+
*/
|
|
126
|
+
findService(typeName) {
|
|
127
|
+
const existing = services[typeName];
|
|
128
|
+
if (existing) {
|
|
129
|
+
return existing;
|
|
130
|
+
}
|
|
131
|
+
const desc = set.services.get(typeName);
|
|
132
|
+
if (!desc) {
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
const methods = {};
|
|
136
|
+
for (const method of desc.methods) {
|
|
137
|
+
const I = this.findMessage(method.input.typeName);
|
|
138
|
+
const O = this.findMessage(method.input.typeName);
|
|
139
|
+
assert(I, `message "${method.input.typeName}" for ${method.toString()} not found`);
|
|
140
|
+
assert(O, `output message "${method.output.typeName}" for ${method.toString()} not found`);
|
|
141
|
+
const m = {
|
|
142
|
+
name: method.name,
|
|
143
|
+
localName: localName(method),
|
|
144
|
+
I,
|
|
145
|
+
O,
|
|
146
|
+
kind: method.methodKind,
|
|
147
|
+
idempotency: method.idempotency,
|
|
148
|
+
options: {},
|
|
149
|
+
};
|
|
150
|
+
methods[m.localName] = m;
|
|
151
|
+
}
|
|
152
|
+
return (services[typeName] = {
|
|
153
|
+
typeName: desc.typeName,
|
|
154
|
+
methods,
|
|
155
|
+
});
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* DescriptorRegistry is a type registry that dynamically creates types
|
|
161
|
+
* from a set of google.protobuf.FileDescriptorProto.
|
|
162
|
+
*
|
|
163
|
+
* By default, all well-known types with a specialized JSON representation
|
|
164
|
+
* are replaced with their generated counterpart in this package.
|
|
165
|
+
*/
|
|
166
|
+
export class DescriptorRegistry {
|
|
167
|
+
constructor(descriptorSet, replaceWkt = true) {
|
|
168
|
+
this.enums = {};
|
|
169
|
+
this.messages = {};
|
|
170
|
+
this.services = {};
|
|
171
|
+
this.desc = descriptorSet;
|
|
172
|
+
if (replaceWkt) {
|
|
173
|
+
for (const mt of wkMessages) {
|
|
174
|
+
this.messages[mt.typeName] = mt;
|
|
175
|
+
}
|
|
176
|
+
for (const et of wkEnums) {
|
|
177
|
+
this.enums[et.typeName] = et;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Conveniently create a DescriptorRegistry from a FileDescriptorSet,
|
|
183
|
+
* or a FileDescriptorSet in binary format.
|
|
184
|
+
*/
|
|
185
|
+
static fromFileDescriptorSet(input) {
|
|
186
|
+
return new DescriptorRegistry(createDescriptorSet(input));
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* May raise an error on invalid descriptors.
|
|
190
|
+
*/
|
|
191
|
+
findEnum(typeName) {
|
|
192
|
+
const existing = this.enums[typeName];
|
|
193
|
+
if (existing) {
|
|
194
|
+
return existing;
|
|
195
|
+
}
|
|
196
|
+
const desc = this.desc.enums.get(typeName);
|
|
197
|
+
if (!desc) {
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
const runtime = desc.file.syntax == "proto3" ? proto3 : proto2;
|
|
201
|
+
const type = runtime.makeEnumType(typeName, desc.values.map((u) => ({
|
|
202
|
+
no: u.number,
|
|
203
|
+
name: u.name,
|
|
204
|
+
localName: localName(u),
|
|
205
|
+
})), {});
|
|
206
|
+
this.enums[typeName] = type;
|
|
207
|
+
return type;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* May raise an error on invalid descriptors.
|
|
211
|
+
*/
|
|
212
|
+
findMessage(typeName) {
|
|
213
|
+
const existing = this.messages[typeName];
|
|
214
|
+
if (existing) {
|
|
215
|
+
return existing;
|
|
216
|
+
}
|
|
217
|
+
const desc = this.desc.messages.get(typeName);
|
|
218
|
+
if (!desc) {
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
const runtime = desc.file.syntax == "proto3" ? proto3 : proto2;
|
|
222
|
+
const fields = [];
|
|
223
|
+
const type = runtime.makeMessageType(typeName, () => fields, {
|
|
224
|
+
localName: localName(desc),
|
|
225
|
+
});
|
|
226
|
+
this.messages[typeName] = type;
|
|
227
|
+
for (const field of desc.fields) {
|
|
228
|
+
const fieldInfo = makeFieldInfo(field, this);
|
|
229
|
+
fields.push(fieldInfo);
|
|
230
|
+
}
|
|
231
|
+
return type;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* May raise an error on invalid descriptors.
|
|
235
|
+
*/
|
|
236
|
+
findService(typeName) {
|
|
237
|
+
const existing = this.services[typeName];
|
|
238
|
+
if (existing) {
|
|
239
|
+
return existing;
|
|
240
|
+
}
|
|
241
|
+
const desc = this.desc.services.get(typeName);
|
|
242
|
+
if (!desc) {
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
const methods = {};
|
|
246
|
+
for (const method of desc.methods) {
|
|
247
|
+
const I = this.findMessage(method.input.typeName);
|
|
248
|
+
const O = this.findMessage(method.input.typeName);
|
|
249
|
+
assert(I, `message "${method.input.typeName}" for ${method.toString()} not found`);
|
|
250
|
+
assert(O, `output message "${method.output.typeName}" for ${method.toString()} not found`);
|
|
251
|
+
const m = {
|
|
252
|
+
name: method.name,
|
|
253
|
+
localName: localName(method),
|
|
254
|
+
I,
|
|
255
|
+
O,
|
|
256
|
+
kind: method.methodKind,
|
|
257
|
+
idempotency: method.idempotency,
|
|
258
|
+
options: {},
|
|
259
|
+
};
|
|
260
|
+
methods[m.localName] = m;
|
|
261
|
+
}
|
|
262
|
+
return (this.services[typeName] = {
|
|
263
|
+
typeName: desc.typeName,
|
|
264
|
+
methods,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
function makeFieldInfo(desc, resolver) {
|
|
269
|
+
switch (desc.kind) {
|
|
270
|
+
case "map_field":
|
|
271
|
+
return makeMapFieldInfo(desc, resolver);
|
|
272
|
+
case "message_field":
|
|
273
|
+
return makeMessageFieldInfo(desc, resolver);
|
|
274
|
+
case "enum_field": {
|
|
275
|
+
const fi = makeEnumFieldInfo(desc, resolver);
|
|
276
|
+
fi.default = desc.getDefaultValue();
|
|
277
|
+
return fi;
|
|
278
|
+
}
|
|
279
|
+
case "scalar_field": {
|
|
280
|
+
const fi = makeScalarFieldInfo(desc);
|
|
281
|
+
fi.default = desc.getDefaultValue();
|
|
282
|
+
return fi;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
function makeMapFieldInfo(field, resolver) {
|
|
287
|
+
const base = {
|
|
288
|
+
kind: "map",
|
|
289
|
+
no: field.number,
|
|
290
|
+
name: field.name,
|
|
291
|
+
jsonName: field.jsonName,
|
|
292
|
+
K: field.mapKey,
|
|
293
|
+
};
|
|
294
|
+
if (field.mapValue.message) {
|
|
295
|
+
const messageType = resolver.findMessage(field.mapValue.message.typeName);
|
|
296
|
+
assert(messageType, `message "${field.mapValue.message.typeName}" for ${field.toString()} not found`);
|
|
297
|
+
return Object.assign(Object.assign({}, base), { V: {
|
|
298
|
+
kind: "message",
|
|
299
|
+
T: messageType,
|
|
300
|
+
} });
|
|
301
|
+
}
|
|
302
|
+
if (field.mapValue.enum) {
|
|
303
|
+
const enumType = resolver.findEnum(field.mapValue.enum.typeName);
|
|
304
|
+
assert(enumType, `enum "${field.mapValue.enum.typeName}" for ${field.toString()} not found`);
|
|
305
|
+
return Object.assign(Object.assign({}, base), { V: {
|
|
306
|
+
kind: "enum",
|
|
307
|
+
T: enumType,
|
|
308
|
+
} });
|
|
309
|
+
}
|
|
310
|
+
return Object.assign(Object.assign({}, base), { V: {
|
|
311
|
+
kind: "scalar",
|
|
312
|
+
T: field.mapValue.scalar,
|
|
313
|
+
} });
|
|
314
|
+
}
|
|
315
|
+
function makeScalarFieldInfo(field) {
|
|
316
|
+
const base = {
|
|
317
|
+
kind: "scalar",
|
|
318
|
+
no: field.number,
|
|
319
|
+
name: field.name,
|
|
320
|
+
jsonName: field.jsonName,
|
|
321
|
+
T: field.scalar,
|
|
322
|
+
};
|
|
323
|
+
if (field.repeated) {
|
|
324
|
+
return Object.assign(Object.assign({}, base), { repeated: true, packed: field.packed, oneof: undefined, T: field.scalar });
|
|
325
|
+
}
|
|
326
|
+
if (field.oneof) {
|
|
327
|
+
return Object.assign(Object.assign({}, base), { oneof: field.oneof.name });
|
|
328
|
+
}
|
|
329
|
+
if (field.optional) {
|
|
330
|
+
return Object.assign(Object.assign({}, base), { opt: true });
|
|
331
|
+
}
|
|
332
|
+
return base;
|
|
333
|
+
}
|
|
334
|
+
function makeMessageFieldInfo(field, resolver) {
|
|
335
|
+
const messageType = resolver.findMessage(field.message.typeName);
|
|
336
|
+
assert(messageType, `message "${field.message.typeName}" for ${field.toString()} not found`);
|
|
337
|
+
const base = {
|
|
338
|
+
kind: "message",
|
|
339
|
+
no: field.number,
|
|
340
|
+
name: field.name,
|
|
341
|
+
jsonName: field.jsonName,
|
|
342
|
+
T: messageType,
|
|
343
|
+
};
|
|
344
|
+
if (field.repeated) {
|
|
345
|
+
return Object.assign(Object.assign({}, base), { repeated: true, packed: field.packed, oneof: undefined });
|
|
346
|
+
}
|
|
347
|
+
if (field.oneof) {
|
|
348
|
+
return Object.assign(Object.assign({}, base), { oneof: field.oneof.name });
|
|
349
|
+
}
|
|
350
|
+
if (field.optional) {
|
|
351
|
+
return Object.assign(Object.assign({}, base), { opt: true });
|
|
352
|
+
}
|
|
353
|
+
return base;
|
|
354
|
+
}
|
|
355
|
+
function makeEnumFieldInfo(field, resolver) {
|
|
356
|
+
const enumType = resolver.findEnum(field.enum.typeName);
|
|
357
|
+
assert(enumType, `enum "${field.enum.typeName}" for ${field.toString()} not found`);
|
|
358
|
+
const base = {
|
|
359
|
+
kind: "enum",
|
|
360
|
+
no: field.number,
|
|
361
|
+
name: field.name,
|
|
362
|
+
jsonName: field.jsonName,
|
|
363
|
+
T: enumType,
|
|
364
|
+
};
|
|
365
|
+
if (field.repeated) {
|
|
366
|
+
return Object.assign(Object.assign({}, base), { repeated: true, packed: field.packed, oneof: undefined });
|
|
367
|
+
}
|
|
368
|
+
if (field.oneof) {
|
|
369
|
+
return Object.assign(Object.assign({}, base), { oneof: field.oneof.name });
|
|
370
|
+
}
|
|
371
|
+
if (field.optional) {
|
|
372
|
+
return Object.assign(Object.assign({}, base), { opt: true });
|
|
373
|
+
}
|
|
374
|
+
return base;
|
|
375
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Copyright 2021-2022 Buf Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
/**
|
|
15
|
+
* Create a new registry from the given types. Note that
|
|
16
|
+
*/
|
|
17
|
+
export function createRegistry(...types) {
|
|
18
|
+
const messages = {};
|
|
19
|
+
const enums = {};
|
|
20
|
+
const services = {};
|
|
21
|
+
const registry = {
|
|
22
|
+
/**
|
|
23
|
+
* Add a type to the registry. For messages, the types used in message
|
|
24
|
+
* fields are added recursively. For services, the message types used
|
|
25
|
+
* for requests and responses are added recursively.
|
|
26
|
+
*/
|
|
27
|
+
add(type) {
|
|
28
|
+
if ("fields" in type) {
|
|
29
|
+
if (!this.findMessage(type.typeName)) {
|
|
30
|
+
messages[type.typeName] = type;
|
|
31
|
+
for (const field of type.fields.list()) {
|
|
32
|
+
if (field.kind == "message") {
|
|
33
|
+
this.add(field.T);
|
|
34
|
+
}
|
|
35
|
+
else if (field.kind == "map" && field.V.kind == "message") {
|
|
36
|
+
this.add(field.V.T);
|
|
37
|
+
}
|
|
38
|
+
else if (field.kind == "enum") {
|
|
39
|
+
this.add(field.T);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else if ("methods" in type) {
|
|
45
|
+
if (!this.findService(type.typeName)) {
|
|
46
|
+
services[type.typeName] = type;
|
|
47
|
+
for (const method of Object.values(type.methods)) {
|
|
48
|
+
this.add(method.I);
|
|
49
|
+
this.add(method.O);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
enums[type.typeName] = type;
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
findMessage(typeName) {
|
|
58
|
+
return messages[typeName];
|
|
59
|
+
},
|
|
60
|
+
findEnum(typeName) {
|
|
61
|
+
return enums[typeName];
|
|
62
|
+
},
|
|
63
|
+
findService(typeName) {
|
|
64
|
+
return services[typeName];
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
for (const type of types) {
|
|
68
|
+
registry.add(type);
|
|
69
|
+
}
|
|
70
|
+
return registry;
|
|
71
|
+
}
|