|
1 | | -// [WIP] Extension for reflection interoperability with descriptor.proto types |
2 | | -// var protobuf = require("protobufjs"), |
3 | | -// descriptor = require("protobufjs/ext/descriptor"); |
4 | | -// ... |
5 | 1 | "use strict"; |
6 | 2 |
|
7 | | -var protobuf = require(".."); |
| 3 | +var $protobuf = require(".."); |
8 | 4 |
|
9 | 5 | /** |
10 | 6 | * Descriptor extension (ext/descriptor). |
11 | | - * @namespace |
| 7 | + * @type {Root} |
| 8 | + * @tstype $protobuf.Root |
| 9 | + * @const |
12 | 10 | */ |
13 | | - |
14 | | -var descriptor = module.exports = protobuf.Root.fromJSON(require("../google/protobuf/descriptor.json")).lookup(".google.protobuf"); |
| 11 | +var descriptor = module.exports = $protobuf.Root.fromJSON(require("../google/protobuf/descriptor.json")).lookup(".google.protobuf"); |
15 | 12 |
|
16 | 13 | var google = descriptor, |
17 | | - Root = protobuf.Root, |
18 | | - Enum = protobuf.Enum, |
19 | | - Type = protobuf.Type, |
20 | | - Field = protobuf.Field, |
21 | | - OneOf = protobuf.OneOf, |
22 | | - Service = protobuf.Service, |
23 | | - Method = protobuf.Method; |
| 14 | + Root = $protobuf.Root, |
| 15 | + Enum = $protobuf.Enum, |
| 16 | + Type = $protobuf.Type, |
| 17 | + Field = $protobuf.Field, |
| 18 | + OneOf = $protobuf.OneOf, |
| 19 | + Service = $protobuf.Service, |
| 20 | + Method = $protobuf.Method; |
24 | 21 |
|
25 | 22 | // --- Root --- |
26 | 23 |
|
27 | | -/** |
28 | | - * Reflected type describing a root. |
29 | | - * @name descriptor.FileDescriptorSet |
30 | | - * @type {Type} |
31 | | - */ |
32 | | - |
33 | 24 | /** |
34 | 25 | * @interface IFileDescriptorSet |
35 | 26 | * @property {IFileDescriptorProto[]} file |
@@ -118,12 +109,6 @@ Root.prototype.toDescriptor = function toDescriptor(syntax) { |
118 | 109 |
|
119 | 110 | // --- Type --- |
120 | 111 |
|
121 | | -/** |
122 | | - * Reflected type describing a type. |
123 | | - * @name descriptor.DescriptorProto |
124 | | - * @type {Type} |
125 | | - */ |
126 | | - |
127 | 112 | /** |
128 | 113 | * @interface IDescriptorProto |
129 | 114 | * @property {string} [name] |
@@ -175,15 +160,15 @@ Type.fromDescriptor = function fromDescriptor(descriptor, syntax) { |
175 | 160 | i; |
176 | 161 |
|
177 | 162 | /* Fields */ for (i = 0; i < descriptor.field.length; ++i) |
178 | | - type.add(protobuf.Field.fromDescriptor(descriptor.field[i], syntax)); |
| 163 | + type.add(Field.fromDescriptor(descriptor.field[i], syntax)); |
179 | 164 | /* Extension fields */ for (i = 0; i < descriptor.extension.length; ++i) |
180 | | - type.add(protobuf.Field.fromDescriptor(descriptor.extension[i], syntax)); |
| 165 | + type.add(Field.fromDescriptor(descriptor.extension[i], syntax)); |
181 | 166 | /* Oneofs */ for (i = 0; i < descriptor.oneofDecl.length; ++i) |
182 | | - type.add(protobuf.OneOf.fromDescriptor(descriptor.oneofDecl[i])); |
| 167 | + type.add(OneOf.fromDescriptor(descriptor.oneofDecl[i])); |
183 | 168 | /* Nested types */ for (i = 0; i < descriptor.nestedType.length; ++i) |
184 | | - type.add(protobuf.Type.fromDescriptor(descriptor.nestedType[i], syntax)); |
| 169 | + type.add(Type.fromDescriptor(descriptor.nestedType[i], syntax)); |
185 | 170 | /* Nested enums */ for (i = 0; i < descriptor.enumType.length; ++i) |
186 | | - type.add(protobuf.Enum.fromDescriptor(descriptor.enumType[i])); |
| 171 | + type.add(Enum.fromDescriptor(descriptor.enumType[i])); |
187 | 172 | /* Extension ranges */ if (descriptor.extensionRange.length) { |
188 | 173 | type.extensions = []; |
189 | 174 | for (i = 0; i < descriptor.extensionRange.length; ++i) |
@@ -236,18 +221,10 @@ Type.prototype.toDescriptor = function toDescriptor(syntax) { |
236 | 221 |
|
237 | 222 | // --- Field --- |
238 | 223 |
|
239 | | -/** |
240 | | - * Reflected type describing a field. |
241 | | - * @name descriptor.FieldDescriptorProto |
242 | | - * @type {Type} |
243 | | - * @property {Enum} Label Reflected descriptor describing a field label (rule) |
244 | | - * @property {Enum} Type Reflected descriptor describing a field type |
245 | | - */ |
246 | | - |
247 | 224 | /** |
248 | 225 | * @interface IFieldDescriptorProto |
249 | 226 | * @property {string} [name] |
250 | | - * @property {number} [number} |
| 227 | + * @property {number} [number] |
251 | 228 | * @property {IFieldDescriptorProto_Label} [label] |
252 | 229 | * @property {IFieldDescriptorProto_Type} [type] |
253 | 230 | * @property {string} [typeName] |
@@ -424,24 +401,6 @@ Field.prototype.toDescriptor = function toDescriptor(syntax) { |
424 | 401 |
|
425 | 402 | // --- Enum --- |
426 | 403 |
|
427 | | -/** |
428 | | - * Reflected type describing an enum. |
429 | | - * @name descriptor.EnumDescriptorProto |
430 | | - * @type {Type} |
431 | | - */ |
432 | | - |
433 | | -/** |
434 | | - * Reflected type describing an enum value. |
435 | | - * @name descriptor.EnumValueDescriptorProto |
436 | | - * @type {Type} |
437 | | - */ |
438 | | - |
439 | | -/** |
440 | | - * Reflected type describing enum options. |
441 | | - * @name descriptor.EnumOptions |
442 | | - * @type {Type} |
443 | | - */ |
444 | | - |
445 | 404 | /** |
446 | 405 | * @interface IEnumDescriptorProto |
447 | 406 | * @property {string} [name] |
@@ -511,12 +470,6 @@ Enum.prototype.toDescriptor = function toDescriptor() { |
511 | 470 |
|
512 | 471 | // --- OneOf --- |
513 | 472 |
|
514 | | -/** |
515 | | - * Reflected type describing a oneof. |
516 | | - * @name descriptor.OneofDescriptorProto |
517 | | - * @type {Type} |
518 | | - */ |
519 | | - |
520 | 473 | /** |
521 | 474 | * @interface IOneofDescriptorProto |
522 | 475 | * @property {string} [name] |
@@ -556,12 +509,6 @@ OneOf.prototype.toDescriptor = function toDescriptor() { |
556 | 509 |
|
557 | 510 | // --- Service --- |
558 | 511 |
|
559 | | -/** |
560 | | - * Reflected type describing a service. |
561 | | - * @name descriptor.ServiceDescriptorProto |
562 | | - * @type {Type} |
563 | | - */ |
564 | | - |
565 | 512 | /** |
566 | 513 | * @interface IServiceDescriptorProto |
567 | 514 | * @property {string} [name] |
@@ -610,12 +557,6 @@ Service.prototype.toDescriptor = function toDescriptor() { |
610 | 557 |
|
611 | 558 | // --- Method --- |
612 | 559 |
|
613 | | -/** |
614 | | - * Reflected type describing a method. |
615 | | - * @name descriptor.MethodDescriptorProto |
616 | | - * @type {Type} |
617 | | - */ |
618 | | - |
619 | 560 | /** |
620 | 561 | * @interface IMethodDescriptorProto |
621 | 562 | * @property {string} [name] |
|
0 commit comments