forked from protobufjs/protobuf.js
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.d.ts
2694 lines (2227 loc) · 83.3 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// DO NOT EDIT! This is a generated file. Edit the JSDoc in src/*.js instead and run 'npm run types'.
export as namespace protobuf;
/**
* Provides common type definitions.
* Can also be used to provide additional google types or your own custom types.
* @param name Short name as in `google/protobuf/[name].proto` or full file name
* @param json JSON definition within `google.protobuf` if a short name, otherwise the file's root definition
*/
export function common(name: string, json: { [k: string]: any }): void;
export namespace common {
/** Properties of a google.protobuf.Any message. */
interface IAny {
typeUrl?: string;
bytes?: Uint8Array;
}
/** Properties of a google.protobuf.Duration message. */
interface IDuration {
seconds?: (number|Long);
nanos?: number;
}
/** Properties of a google.protobuf.Timestamp message. */
interface ITimestamp {
seconds?: (number|Long);
nanos?: number;
}
/** Properties of a google.protobuf.Empty message. */
interface IEmpty {
}
/** Properties of a google.protobuf.Struct message. */
interface IStruct {
fields?: { [k: string]: IValue };
}
/** Properties of a google.protobuf.Value message. */
interface IValue {
kind?: string;
nullValue?: 0;
numberValue?: number;
stringValue?: string;
boolValue?: boolean;
structValue?: IStruct;
listValue?: IListValue;
}
/** Properties of a google.protobuf.ListValue message. */
interface IListValue {
values?: IValue[];
}
/** Properties of a google.protobuf.DoubleValue message. */
interface IDoubleValue {
value?: number;
}
/** Properties of a google.protobuf.FloatValue message. */
interface IFloatValue {
value?: number;
}
/** Properties of a google.protobuf.Int64Value message. */
interface IInt64Value {
value?: (number|Long);
}
/** Properties of a google.protobuf.UInt64Value message. */
interface IUInt64Value {
value?: (number|Long);
}
/** Properties of a google.protobuf.Int32Value message. */
interface IInt32Value {
value?: number;
}
/** Properties of a google.protobuf.UInt32Value message. */
interface IUInt32Value {
value?: number;
}
/** Properties of a google.protobuf.BoolValue message. */
interface IBoolValue {
value?: boolean;
}
/** Properties of a google.protobuf.StringValue message. */
interface IStringValue {
value?: string;
}
/** Properties of a google.protobuf.BytesValue message. */
interface IBytesValue {
value?: Uint8Array;
}
/**
* Gets the root definition of the specified common proto file.
*
* Bundled definitions are:
* - google/protobuf/any.proto
* - google/protobuf/duration.proto
* - google/protobuf/empty.proto
* - google/protobuf/field_mask.proto
* - google/protobuf/struct.proto
* - google/protobuf/timestamp.proto
* - google/protobuf/wrappers.proto
*
* @param file Proto file name
* @returns Root definition or `null` if not defined
*/
function get(file: string): (INamespace|null);
}
/** Runtime message from/to plain object converters. */
export namespace converter {
/**
* Generates a plain object to runtime message converter specific to the specified message type.
* @param mtype Message type
* @returns Codegen instance
*/
function fromObject(mtype: Type): Codegen;
/**
* Generates a runtime message to plain object converter specific to the specified message type.
* @param mtype Message type
* @returns Codegen instance
*/
function toObject(mtype: Type): Codegen;
}
/**
* Generates a decoder specific to the specified message type.
* @param mtype Message type
* @returns Codegen instance
*/
export function decoder(mtype: Type): Codegen;
/**
* Generates an encoder specific to the specified message type.
* @param mtype Message type
* @returns Codegen instance
*/
export function encoder(mtype: Type): Codegen;
/** Reflected enum. */
export class Enum extends ReflectionObject {
/**
* Constructs a new enum instance.
* @param name Unique name within its namespace
* @param [values] Enum values as an object, by name
* @param [options] Declared options
* @param [comment] The comment for this enum
* @param [comments] The value comments for this enum
*/
constructor(name: string, values?: { [k: string]: number }, options?: { [k: string]: any }, comment?: string, comments?: { [k: string]: string });
/** Enum values by id. */
public valuesById: { [k: number]: string };
/** Enum values by name. */
public values: { [k: string]: number };
/** Enum comment text. */
public comment: (string|null);
/** Value comment texts, if any. */
public comments: { [k: string]: string };
/** Reserved ranges, if any. */
public reserved: (number[]|string)[];
/**
* Constructs an enum from an enum descriptor.
* @param name Enum name
* @param json Enum descriptor
* @returns Created enum
* @throws {TypeError} If arguments are invalid
*/
public static fromJSON(name: string, json: IEnum): Enum;
/**
* Converts this enum to an enum descriptor.
* @param [toJSONOptions] JSON conversion options
* @returns Enum descriptor
*/
public toJSON(toJSONOptions?: IToJSONOptions): IEnum;
/**
* Adds a value to this enum.
* @param name Value name
* @param id Value id
* @param [comment] Comment, if any
* @returns `this`
* @throws {TypeError} If arguments are invalid
* @throws {Error} If there is already a value with this name or id
*/
public add(name: string, id: number, comment?: string): Enum;
/**
* Removes a value from this enum
* @param name Value name
* @returns `this`
* @throws {TypeError} If arguments are invalid
* @throws {Error} If `name` is not a name of this enum
*/
public remove(name: string): Enum;
/**
* Tests if the specified id is reserved.
* @param id Id to test
* @returns `true` if reserved, otherwise `false`
*/
public isReservedId(id: number): boolean;
/**
* Tests if the specified name is reserved.
* @param name Name to test
* @returns `true` if reserved, otherwise `false`
*/
public isReservedName(name: string): boolean;
}
/** Enum descriptor. */
export interface IEnum {
/** Enum values */
values: { [k: string]: number };
/** Enum options */
options?: { [k: string]: any };
}
/** Reflected message field. */
export class Field extends FieldBase {
/**
* Constructs a new message field instance. Note that {@link MapField|map fields} have their own class.
* @param name Unique name within its namespace
* @param id Unique id within its namespace
* @param type Value type
* @param [rule="optional"] Field rule
* @param [extend] Extended type if different from parent
* @param [options] Declared options
*/
constructor(name: string, id: number, type: string, rule?: (string|{ [k: string]: any }), extend?: (string|{ [k: string]: any }), options?: { [k: string]: any });
/**
* Constructs a field from a field descriptor.
* @param name Field name
* @param json Field descriptor
* @returns Created field
* @throws {TypeError} If arguments are invalid
*/
public static fromJSON(name: string, json: IField): Field;
/** Determines whether this field is packed. Only relevant when repeated and working with proto2. */
public readonly packed: boolean;
/**
* Field decorator (TypeScript).
* @param fieldId Field id
* @param fieldType Field type
* @param [fieldRule="optional"] Field rule
* @param [defaultValue] Default value
* @returns Decorator function
*/
public static d<T extends number | number[] | Long | Long[] | string | string[] | boolean | boolean[] | Uint8Array | Uint8Array[] | Buffer | Buffer[]>(fieldId: number, fieldType: ("double"|"float"|"int32"|"uint32"|"sint32"|"fixed32"|"sfixed32"|"int64"|"uint64"|"sint64"|"fixed64"|"sfixed64"|"string"|"bool"|"bytes"|object), fieldRule?: ("optional"|"required"|"repeated"), defaultValue?: T): FieldDecorator;
/**
* Field decorator (TypeScript).
* @param fieldId Field id
* @param fieldType Field type
* @param [fieldRule="optional"] Field rule
* @returns Decorator function
*/
public static d<T extends Message<T>>(fieldId: number, fieldType: (Constructor<T>|string), fieldRule?: ("optional"|"required"|"repeated")): FieldDecorator;
}
/** Base class of all reflected message fields. This is not an actual class but here for the sake of having consistent type definitions. */
export class FieldBase extends ReflectionObject {
/**
* Not an actual constructor. Use {@link Field} instead.
* @param name Unique name within its namespace
* @param id Unique id within its namespace
* @param type Value type
* @param [rule="optional"] Field rule
* @param [extend] Extended type if different from parent
* @param [options] Declared options
* @param [comment] Comment associated with this field
*/
constructor(name: string, id: number, type: string, rule?: (string|{ [k: string]: any }), extend?: (string|{ [k: string]: any }), options?: { [k: string]: any }, comment?: string);
/** Field rule, if any. */
public rule?: string;
/** Field type. */
public type: string;
/** Unique field id. */
public id: number;
/** Extended type if different from parent. */
public extend?: string;
/** Whether this field is required. */
public required: boolean;
/** Whether this field is optional. */
public optional: boolean;
/** Whether this field is repeated. */
public repeated: boolean;
/** Whether this field is a map or not. */
public map: boolean;
/** Message this field belongs to. */
public message: (Type|null);
/** OneOf this field belongs to, if any, */
public partOf: (OneOf|null);
/** The field type's default value. */
public typeDefault: any;
/** The field's default value on prototypes. */
public defaultValue: any;
/** Whether this field's value should be treated as a long. */
public long: boolean;
/** Whether this field's value is a buffer. */
public bytes: boolean;
/** Resolved type if not a basic type. */
public resolvedType: (Type|Enum|null);
/** Sister-field within the extended type if a declaring extension field. */
public extensionField: (Field|null);
/** Sister-field within the declaring namespace if an extended field. */
public declaringField: (Field|null);
/** Comment for this field. */
public comment: (string|null);
/**
* Converts this field to a field descriptor.
* @param [toJSONOptions] JSON conversion options
* @returns Field descriptor
*/
public toJSON(toJSONOptions?: IToJSONOptions): IField;
/**
* Resolves this field's type references.
* @returns `this`
* @throws {Error} If any reference cannot be resolved
*/
public resolve(): Field;
}
/** Field descriptor. */
export interface IField {
/** Field rule */
rule?: string;
/** Field type */
type: string;
/** Field id */
id: number;
/** Field options */
options?: { [k: string]: any };
}
/** Extension field descriptor. */
export interface IExtensionField extends IField {
/** Extended type */
extend: string;
}
/**
* Decorator function as returned by {@link Field.d} and {@link MapField.d} (TypeScript).
* @param prototype Target prototype
* @param fieldName Field name
*/
type FieldDecorator = (prototype: object, fieldName: string) => void;
/**
* A node-style callback as used by {@link load} and {@link Root#load}.
* @param error Error, if any, otherwise `null`
* @param [root] Root, if there hasn't been an error
*/
type LoadCallback = (error: (Error|null), root?: Root) => void;
/**
* Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.
* @param filename One or multiple files to load
* @param root Root namespace, defaults to create a new one if omitted.
* @param callback Callback function
* @see {@link Root#load}
*/
export function load(filename: (string|string[]), root: Root, callback: LoadCallback): void;
/**
* Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.
* @param filename One or multiple files to load
* @param callback Callback function
* @see {@link Root#load}
*/
export function load(filename: (string|string[]), callback: LoadCallback): void;
/**
* Loads one or multiple .proto or preprocessed .json files into a common root namespace and returns a promise.
* @param filename One or multiple files to load
* @param [root] Root namespace, defaults to create a new one if omitted.
* @returns Promise
* @see {@link Root#load}
*/
export function load(filename: (string|string[]), root?: Root): Promise<Root>;
/**
* Synchronously loads one or multiple .proto or preprocessed .json files into a common root namespace (node only).
* @param filename One or multiple files to load
* @param [root] Root namespace, defaults to create a new one if omitted.
* @returns Root namespace
* @throws {Error} If synchronous fetching is not supported (i.e. in browsers) or if a file's syntax is invalid
* @see {@link Root#loadSync}
*/
export function loadSync(filename: (string|string[]), root?: Root): Root;
/** Build type, one of `"full"`, `"light"` or `"minimal"`. */
export const build: string;
/** Reconfigures the library according to the environment. */
export function configure(): void;
/** Reflected map field. */
export class MapField extends FieldBase {
/**
* Constructs a new map field instance.
* @param name Unique name within its namespace
* @param id Unique id within its namespace
* @param keyType Key type
* @param type Value type
* @param [options] Declared options
* @param [comment] Comment associated with this field
*/
constructor(name: string, id: number, keyType: string, type: string, options?: { [k: string]: any }, comment?: string);
/** Key type. */
public keyType: string;
/** Resolved key type if not a basic type. */
public resolvedKeyType: (ReflectionObject|null);
/**
* Constructs a map field from a map field descriptor.
* @param name Field name
* @param json Map field descriptor
* @returns Created map field
* @throws {TypeError} If arguments are invalid
*/
public static fromJSON(name: string, json: IMapField): MapField;
/**
* Converts this map field to a map field descriptor.
* @param [toJSONOptions] JSON conversion options
* @returns Map field descriptor
*/
public toJSON(toJSONOptions?: IToJSONOptions): IMapField;
/**
* Map field decorator (TypeScript).
* @param fieldId Field id
* @param fieldKeyType Field key type
* @param fieldValueType Field value type
* @returns Decorator function
*/
public static d<T extends { [key: string]: number | Long | string | boolean | Uint8Array | Buffer | number[] | Message<{}> }>(fieldId: number, fieldKeyType: ("int32"|"uint32"|"sint32"|"fixed32"|"sfixed32"|"int64"|"uint64"|"sint64"|"fixed64"|"sfixed64"|"bool"|"string"), fieldValueType: ("double"|"float"|"int32"|"uint32"|"sint32"|"fixed32"|"sfixed32"|"int64"|"uint64"|"sint64"|"fixed64"|"sfixed64"|"bool"|"string"|"bytes"|object|Constructor<{}>)): FieldDecorator;
}
/** Map field descriptor. */
export interface IMapField extends IField {
/** Key type */
keyType: string;
}
/** Extension map field descriptor. */
export interface IExtensionMapField extends IMapField {
/** Extended type */
extend: string;
}
/** Abstract runtime message. */
export class Message<T extends object = object> {
/**
* Constructs a new message instance.
* @param [properties] Properties to set
*/
constructor(properties?: Properties<T>);
/** Reference to the reflected type. */
public static readonly $type: Type;
/** Reference to the reflected type. */
public readonly $type: Type;
/**
* Creates a new message of this type using the specified properties.
* @param [properties] Properties to set
* @returns Message instance
*/
public static create<T extends Message<T>>(this: Constructor<T>, properties?: { [k: string]: any }): Message<T>;
/**
* Encodes a message of this type.
* @param message Message to encode
* @param [writer] Writer to use
* @returns Writer
*/
public static encode<T extends Message<T>>(this: Constructor<T>, message: (T|{ [k: string]: any }), writer?: Writer): Writer;
/**
* Encodes a message of this type preceeded by its length as a varint.
* @param message Message to encode
* @param [writer] Writer to use
* @returns Writer
*/
public static encodeDelimited<T extends Message<T>>(this: Constructor<T>, message: (T|{ [k: string]: any }), writer?: Writer): Writer;
/**
* Decodes a message of this type.
* @param reader Reader or buffer to decode
* @returns Decoded message
*/
public static decode<T extends Message<T>>(this: Constructor<T>, reader: (Reader|Uint8Array)): T;
/**
* Decodes a message of this type preceeded by its length as a varint.
* @param reader Reader or buffer to decode
* @returns Decoded message
*/
public static decodeDelimited<T extends Message<T>>(this: Constructor<T>, reader: (Reader|Uint8Array)): T;
/**
* Verifies a message of this type.
* @param message Plain object to verify
* @returns `null` if valid, otherwise the reason why it is not
*/
public static verify(message: { [k: string]: any }): (string|null);
/**
* Creates a new message of this type from a plain object. Also converts values to their respective internal types.
* @param object Plain object
* @returns Message instance
*/
public static fromObject<T extends Message<T>>(this: Constructor<T>, object: { [k: string]: any }): T;
/**
* Creates a plain object from a message of this type. Also converts values to other types if specified.
* @param message Message instance
* @param [options] Conversion options
* @returns Plain object
*/
public static toObject<T extends Message<T>>(this: Constructor<T>, message: T, options?: IConversionOptions): { [k: string]: any };
/**
* Converts this message to JSON.
* @returns JSON object
*/
public toJSON(): { [k: string]: any };
}
/** Reflected service method. */
export class Method extends ReflectionObject {
/**
* Constructs a new service method instance.
* @param name Method name
* @param type Method type, usually `"rpc"`
* @param requestType Request message type
* @param responseType Response message type
* @param [requestStream] Whether the request is streamed
* @param [responseStream] Whether the response is streamed
* @param [options] Declared options
* @param [comment] The comment for this method
*/
constructor(name: string, type: (string|undefined), requestType: string, responseType: string, requestStream?: (boolean|{ [k: string]: any }), responseStream?: (boolean|{ [k: string]: any }), options?: { [k: string]: any }, comment?: string);
/** Method type. */
public type: string;
/** Request type. */
public requestType: string;
/** Whether requests are streamed or not. */
public requestStream?: boolean;
/** Response type. */
public responseType: string;
/** Whether responses are streamed or not. */
public responseStream?: boolean;
/** Resolved request type. */
public resolvedRequestType: (Type|null);
/** Resolved response type. */
public resolvedResponseType: (Type|null);
/** Comment for this method */
public comment: (string|null);
/**
* Constructs a method from a method descriptor.
* @param name Method name
* @param json Method descriptor
* @returns Created method
* @throws {TypeError} If arguments are invalid
*/
public static fromJSON(name: string, json: IMethod): Method;
/**
* Converts this method to a method descriptor.
* @param [toJSONOptions] JSON conversion options
* @returns Method descriptor
*/
public toJSON(toJSONOptions?: IToJSONOptions): IMethod;
}
/** Method descriptor. */
export interface IMethod {
/** Method type */
type?: string;
/** Request type */
requestType: string;
/** Response type */
responseType: string;
/** Whether requests are streamed */
requestStream?: boolean;
/** Whether responses are streamed */
responseStream?: boolean;
/** Method options */
options?: { [k: string]: any };
}
/** Reflected namespace. */
export class Namespace extends NamespaceBase {
/**
* Constructs a new namespace instance.
* @param name Namespace name
* @param [options] Declared options
*/
constructor(name: string, options?: { [k: string]: any });
/**
* Constructs a namespace from JSON.
* @param name Namespace name
* @param json JSON object
* @returns Created namespace
* @throws {TypeError} If arguments are invalid
*/
public static fromJSON(name: string, json: { [k: string]: any }): Namespace;
/**
* Converts an array of reflection objects to JSON.
* @param array Object array
* @param [toJSONOptions] JSON conversion options
* @returns JSON object or `undefined` when array is empty
*/
public static arrayToJSON(array: ReflectionObject[], toJSONOptions?: IToJSONOptions): ({ [k: string]: any }|undefined);
/**
* Tests if the specified id is reserved.
* @param reserved Array of reserved ranges and names
* @param id Id to test
* @returns `true` if reserved, otherwise `false`
*/
public static isReservedId(reserved: ((number[]|string)[]|undefined), id: number): boolean;
/**
* Tests if the specified name is reserved.
* @param reserved Array of reserved ranges and names
* @param name Name to test
* @returns `true` if reserved, otherwise `false`
*/
public static isReservedName(reserved: ((number[]|string)[]|undefined), name: string): boolean;
}
/** Base class of all reflection objects containing nested objects. This is not an actual class but here for the sake of having consistent type definitions. */
export abstract class NamespaceBase extends ReflectionObject {
/** Nested objects by name. */
public nested?: { [k: string]: ReflectionObject };
/** Nested objects of this namespace as an array for iteration. */
public readonly nestedArray: ReflectionObject[];
/**
* Converts this namespace to a namespace descriptor.
* @param [toJSONOptions] JSON conversion options
* @returns Namespace descriptor
*/
public toJSON(toJSONOptions?: IToJSONOptions): INamespace;
/**
* Adds nested objects to this namespace from nested object descriptors.
* @param nestedJson Any nested object descriptors
* @returns `this`
*/
public addJSON(nestedJson: { [k: string]: AnyNestedObject }): Namespace;
/**
* Gets the nested object of the specified name.
* @param name Nested object name
* @returns The reflection object or `null` if it doesn't exist
*/
public get(name: string): (ReflectionObject|null);
/**
* Gets the values of the nested {@link Enum|enum} of the specified name.
* This methods differs from {@link Namespace#get|get} in that it returns an enum's values directly and throws instead of returning `null`.
* @param name Nested enum name
* @returns Enum values
* @throws {Error} If there is no such enum
*/
public getEnum(name: string): { [k: string]: number };
/**
* Adds a nested object to this namespace.
* @param object Nested object to add
* @returns `this`
* @throws {TypeError} If arguments are invalid
* @throws {Error} If there is already a nested object with this name
*/
public add(object: ReflectionObject): Namespace;
/**
* Removes a nested object from this namespace.
* @param object Nested object to remove
* @returns `this`
* @throws {TypeError} If arguments are invalid
* @throws {Error} If `object` is not a member of this namespace
*/
public remove(object: ReflectionObject): Namespace;
/**
* Defines additial namespaces within this one if not yet existing.
* @param path Path to create
* @param [json] Nested types to create from JSON
* @returns Pointer to the last namespace created or `this` if path is empty
*/
public define(path: (string|string[]), json?: any): Namespace;
/**
* Resolves this namespace's and all its nested objects' type references. Useful to validate a reflection tree, but comes at a cost.
* @returns `this`
*/
public resolveAll(): Namespace;
/**
* Recursively looks up the reflection object matching the specified path in the scope of this namespace.
* @param path Path to look up
* @param filterTypes Filter types, any combination of the constructors of `protobuf.Type`, `protobuf.Enum`, `protobuf.Service` etc.
* @param [parentAlreadyChecked=false] If known, whether the parent has already been checked
* @returns Looked up object or `null` if none could be found
*/
public lookup(path: (string|string[]), filterTypes: (any|any[]), parentAlreadyChecked?: boolean): (ReflectionObject|null);
/**
* Looks up the reflection object at the specified path, relative to this namespace.
* @param path Path to look up
* @param [parentAlreadyChecked=false] Whether the parent has already been checked
* @returns Looked up object or `null` if none could be found
*/
public lookup(path: (string|string[]), parentAlreadyChecked?: boolean): (ReflectionObject|null);
/**
* Looks up the {@link Type|type} at the specified path, relative to this namespace.
* Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
* @param path Path to look up
* @returns Looked up type
* @throws {Error} If `path` does not point to a type
*/
public lookupType(path: (string|string[])): Type;
/**
* Looks up the values of the {@link Enum|enum} at the specified path, relative to this namespace.
* Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
* @param path Path to look up
* @returns Looked up enum
* @throws {Error} If `path` does not point to an enum
*/
public lookupEnum(path: (string|string[])): Enum;
/**
* Looks up the {@link Type|type} or {@link Enum|enum} at the specified path, relative to this namespace.
* Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
* @param path Path to look up
* @returns Looked up type or enum
* @throws {Error} If `path` does not point to a type or enum
*/
public lookupTypeOrEnum(path: (string|string[])): Type;
/**
* Looks up the {@link Service|service} at the specified path, relative to this namespace.
* Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
* @param path Path to look up
* @returns Looked up service
* @throws {Error} If `path` does not point to a service
*/
public lookupService(path: (string|string[])): Service;
}
/** Namespace descriptor. */
export interface INamespace {
/** Namespace options */
options?: { [k: string]: any };
/** Nested object descriptors */
nested?: { [k: string]: AnyNestedObject };
}
/** Any extension field descriptor. */
type AnyExtensionField = (IExtensionField|IExtensionMapField);
/** Any nested object descriptor. */
type AnyNestedObject = (IEnum|IType|IService|AnyExtensionField|INamespace);
/** Base class of all reflection objects. */
export abstract class ReflectionObject {
/** Options. */
public options?: { [k: string]: any };
/** Unique name within its namespace. */
public name: string;
/** Parent namespace. */
public parent: (Namespace|null);
/** Whether already resolved or not. */
public resolved: boolean;
/** Comment text, if any. */
public comment: (string|null);
/** Defining file name. */
public filename: (string|null);
/** Reference to the root namespace. */
public readonly root: Root;
/** Full name including leading dot. */
public readonly fullName: string;
/**
* Converts this reflection object to its descriptor representation.
* @returns Descriptor
*/
public toJSON(): { [k: string]: any };
/**
* Called when this object is added to a parent.
* @param parent Parent added to
*/
public onAdd(parent: ReflectionObject): void;
/**
* Called when this object is removed from a parent.
* @param parent Parent removed from
*/
public onRemove(parent: ReflectionObject): void;
/**
* Resolves this objects type references.
* @returns `this`
*/
public resolve(): ReflectionObject;
/**
* Gets an option value.
* @param name Option name
* @returns Option value or `undefined` if not set
*/
public getOption(name: string): any;
/**
* Sets an option.
* @param name Option name
* @param value Option value
* @param [ifNotSet] Sets the option only if it isn't currently set
* @returns `this`
*/
public setOption(name: string, value: any, ifNotSet?: boolean): ReflectionObject;
/**
* Sets multiple options.
* @param options Options to set
* @param [ifNotSet] Sets an option only if it isn't currently set
* @returns `this`
*/
public setOptions(options: { [k: string]: any }, ifNotSet?: boolean): ReflectionObject;
/**
* Converts this instance to its string representation.
* @returns Class name[, space, full name]
*/
public toString(): string;
}
/** Reflected oneof. */
export class OneOf extends ReflectionObject {
/**
* Constructs a new oneof instance.
* @param name Oneof name
* @param [fieldNames] Field names
* @param [options] Declared options
* @param [comment] Comment associated with this field
*/
constructor(name: string, fieldNames?: (string[]|{ [k: string]: any }), options?: { [k: string]: any }, comment?: string);
/** Field names that belong to this oneof. */
public oneof: string[];
/** Fields that belong to this oneof as an array for iteration. */
public readonly fieldsArray: Field[];
/** Comment for this field. */
public comment: (string|null);
/**
* Constructs a oneof from a oneof descriptor.
* @param name Oneof name
* @param json Oneof descriptor
* @returns Created oneof
* @throws {TypeError} If arguments are invalid
*/
public static fromJSON(name: string, json: IOneOf): OneOf;
/**
* Converts this oneof to a oneof descriptor.
* @param [toJSONOptions] JSON conversion options
* @returns Oneof descriptor
*/
public toJSON(toJSONOptions?: IToJSONOptions): IOneOf;
/**
* Adds a field to this oneof and removes it from its current parent, if any.
* @param field Field to add
* @returns `this`
*/
public add(field: Field): OneOf;
/**
* Removes a field from this oneof and puts it back to the oneof's parent.
* @param field Field to remove
* @returns `this`
*/
public remove(field: Field): OneOf;
/**
* OneOf decorator (TypeScript).
* @param fieldNames Field names
* @returns Decorator function
*/
public static d<T extends string>(...fieldNames: string[]): OneOfDecorator;
}
/** Oneof descriptor. */
export interface IOneOf {
/** Oneof field names */