forked from protobufjs/protobuf.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
2607 lines (2296 loc) · 79.9 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
// $> pbts --main --global protobuf --out index.d.ts src
// Generated Sat, 31 Dec 2016 00:05:20 UTC
export as namespace protobuf;
/**
* Constructs a class instance, which is also a message prototype.
* @classdesc Runtime class providing the tools to create your own custom classes.
* @constructor
* @param {Type} type Reflected type
*/
export class Class {
/**
* Constructs a class instance, which is also a message prototype.
* @classdesc Runtime class providing the tools to create your own custom classes.
* @constructor
* @param {Type} type Reflected type
*/
constructor(type: Type);
/**
* Constructs a new message prototype for the specified reflected type and sets up its constructor.
* @memberof Class
* @param {Type} type Reflected message type
* @param {*} [ctor] Custom constructor to set up, defaults to create a generic one if omitted
* @returns {Message} Message prototype
*/
static create(type: Type, ctor?: any): Message;
/**
* Encodes a message of this type.
* @name Class#encode
* @function
* @param {Message|Object} message Message to encode
* @param {Writer} [writer] Writer to use
* @returns {Writer} Writer
*/
encode(message: (Message|Object), writer?: Writer): Writer;
/**
* Encodes a message of this type preceeded by its length as a varint.
* @name Class#encodeDelimited
* @function
* @param {Message|Object} message Message to encode
* @param {Writer} [writer] Writer to use
* @returns {Writer} Writer
*/
encodeDelimited(message: (Message|Object), writer?: Writer): Writer;
/**
* Decodes a message of this type.
* @name Class#decode
* @function
* @param {Reader|Uint8Array} readerOrBuffer Reader or buffer to decode
* @returns {Message} Decoded message
*/
decode(readerOrBuffer: (Reader|Uint8Array)): Message;
/**
* Decodes a message of this type preceeded by its length as a varint.
* @name Class#decodeDelimited
* @function
* @param {Reader|Uint8Array} readerOrBuffer Reader or buffer to decode
* @returns {Message} Decoded message
*/
decodeDelimited(readerOrBuffer: (Reader|Uint8Array)): Message;
/**
* Verifies a message of this type.
* @name Class#verify
* @function
* @param {Message|Object} message Message or plain object to verify
* @returns {?string} `null` if valid, otherwise the reason why it is not
*/
verify(message: (Message|Object)): string;
}
/**
* Provides common type definitions.
* Can also be used to provide additional google types or your own custom types.
* @param {string} name Short name as in `google/protobuf/[name].proto` or full file name
* @param {Object.<string,*>} json JSON definition within `google.protobuf` if a short name, otherwise the file's root definition
* @returns {undefined}
* @property {Object.<string,*>} google/protobuf/any.proto Any
* @property {Object.<string,*>} google/protobuf/duration.proto Duration
* @property {Object.<string,*>} google/protobuf/empty.proto Empty
* @property {Object.<string,*>} google/protobuf/struct.proto Struct, Value, NullValue and ListValue
* @property {Object.<string,*>} google/protobuf/timestamp.proto Timestamp
* @property {Object.<string,*>} google/protobuf/wrappers.proto Wrappers
*/
export function common(name: string, json: { [k: string]: any }): void;
/**
* A converter as used by {@link convert}.
* @typedef Converter
* @type {function}
* @param {Field} field Reflected field
* @param {*} value Value to convert
* @param {Object.<string,*>} options Conversion options
* @returns {*} Converted value
*/
type Converter = (field: Field, value: any, options: { [k: string]: any }) => any;
/**
* Converts between JSON objects and messages, based on reflection information.
* @param {Type} type Type
* @param {*} source Source object
* @param {*} destination Destination object
* @param {Object.<string,*>} options Conversion options
* @param {Converter} converter Conversion function
* @returns {*} `destination`
* @property {Converter} toJson To JSON converter using {@link JSONConversionOptions}
* @property {Converter} toMessage To message converter using {@link MessageConversionOptions}
*/
export function convert(type: Type, source: any, destination: any, options: { [k: string]: any }, converter: Converter): any;
/**
* JSON conversion options as used by {@link Message#asJSON} with {@link convert}.
* @typedef JSONConversionOptions
* @type {Object}
* @property {boolean} [fieldsOnly=false] Keeps only properties that reference a field
* @property {*} [longs] Long conversion type. Only relevant with a long library.
* Valid values are `String` and `Number` (the global types).
* Defaults to a possibly unsafe number without, and a `Long` with a long library.
* @property {*} [enums=Number] Enum value conversion type.
* Valid values are `String` and `Number` (the global types).
* Defaults to the numeric ids.
* @property {*} [bytes] Bytes value conversion type.
* Valid values are `Array` and `String` (the global types).
* Defaults to return the underlying buffer type.
* @property {boolean} [defaults=false] Also sets default values on the resulting object
*/
interface JSONConversionOptions {
fieldsOnly?: boolean;
longs?: any;
enums?: any;
bytes?: any;
defaults?: boolean;
}
/**
* Message conversion options as used by {@link Message.from} and {@link Type#from} with {@link convert}.
* @typedef MessageConversionOptions
* @type {Object}
* @property {boolean} [fieldsOnly=false] Keeps only properties that reference a field
*/
interface MessageConversionOptions {
fieldsOnly?: boolean;
}
/**
* Generates a decoder specific to the specified message type.
* @param {Type} mtype Message type
* @returns {Codegen} Codegen instance
*/
export function decoder(mtype: Type): Codegen;
/**
* Generates an encoder specific to the specified message type.
* @param {Type} mtype Message type
* @returns {Codegen} Codegen instance
*/
export function encoder(mtype: Type): Codegen;
/**
* Constructs a new enum instance.
* @classdesc Reflected enum.
* @extends ReflectionObject
* @constructor
* @param {string} name Unique name within its namespace
* @param {Object.<string,number>} [values] Enum values as an object, by name
* @param {Object.<string,*>} [options] Declared options
*/
export class Enum extends ReflectionObject {
/**
* Constructs a new enum instance.
* @classdesc Reflected enum.
* @extends ReflectionObject
* @constructor
* @param {string} name Unique name within its namespace
* @param {Object.<string,number>} [values] Enum values as an object, by name
* @param {Object.<string,*>} [options] Declared options
*/
constructor(name: string, values?: { [k: string]: number }, options?: { [k: string]: any });
/**
* Enum values by name.
* @type {Object.<string,number>}
*/
values: { [k: string]: number };
/**
* Enum values by id.
* @name Enum#valuesById
* @type {Object.<number,string>}
* @readonly
*/
readonly valuesById: { [k: number]: string };
/**
* Gets this enum's values by id. This is an alias of {@link Enum#valuesById|valuesById}'s getter for use within non-ES5 environments.
* @name Enum#getValuesById
* @function
* @returns {Object.<number,string>}
*/
getValuesById(): { [k: number]: string };
/**
* Tests if the specified JSON object describes an enum.
* @param {*} json JSON object to test
* @returns {boolean} `true` if the object describes an enum
*/
static testJSON(json: any): boolean;
/**
* Creates an enum from JSON.
* @param {string} name Enum name
* @param {Object.<string,*>} json JSON object
* @returns {Enum} Created enum
* @throws {TypeError} If arguments are invalid
*/
static fromJSON(name: string, json: { [k: string]: any }): Enum;
/**
* Adds a value to this enum.
* @param {string} name Value name
* @param {number} id Value id
* @returns {Enum} `this`
* @throws {TypeError} If arguments are invalid
* @throws {Error} If there is already a value with this name or id
*/
add(name: string, id: number): Enum;
/**
* Removes a value from this enum
* @param {string} name Value name
* @returns {Enum} `this`
* @throws {TypeError} If arguments are invalid
* @throws {Error} If `name` is not a name of this enum
*/
remove(name: string): Enum;
}
/**
* Constructs a new message field instance. Note that {@link MapField|map fields} have their own class.
* @classdesc Reflected message field.
* @extends ReflectionObject
* @constructor
* @param {string} name Unique name within its namespace
* @param {number} id Unique id within its namespace
* @param {string} type Value type
* @param {string|Object.<string,*>} [rule="optional"] Field rule
* @param {string|Object.<string,*>} [extend] Extended type if different from parent
* @param {Object.<string,*>} [options] Declared options
*/
export class Field extends ReflectionObject {
/**
* Constructs a new message field instance. Note that {@link MapField|map fields} have their own class.
* @classdesc Reflected message field.
* @extends ReflectionObject
* @constructor
* @param {string} name Unique name within its namespace
* @param {number} id Unique id within its namespace
* @param {string} type Value type
* @param {string|Object.<string,*>} [rule="optional"] Field rule
* @param {string|Object.<string,*>} [extend] Extended type if different from parent
* @param {Object.<string,*>} [options] Declared options
*/
constructor(name: string, id: number, type: string, rule?: (string|{ [k: string]: any }), extend?: (string|{ [k: string]: any }), options?: { [k: string]: any });
/**
* Field rule, if any.
* @type {string|undefined}
*/
rule: (string|undefined);
/**
* Field type.
* @type {string}
*/
type: string;
/**
* Unique field id.
* @type {number}
*/
id: number;
/**
* Extended type if different from parent.
* @type {string|undefined}
*/
extend: (string|undefined);
/**
* Whether this field is required.
* @type {boolean}
*/
required: boolean;
/**
* Whether this field is optional.
* @type {boolean}
*/
optional: boolean;
/**
* Whether this field is repeated.
* @type {boolean}
*/
repeated: boolean;
/**
* Whether this field is a map or not.
* @type {boolean}
*/
map: boolean;
/**
* Message this field belongs to.
* @type {?Type}
*/
message: Type;
/**
* OneOf this field belongs to, if any,
* @type {?OneOf}
*/
partOf: OneOf;
/**
* The field's default value. Only relevant when working with proto2.
* @type {*}
*/
defaultValue: any;
/**
* Whether this field's value should be treated as a long.
* @type {boolean}
*/
long: boolean;
/**
* Whether this field's value is a buffer.
* @type {boolean}
*/
bytes: boolean;
/**
* Resolved type if not a basic type.
* @type {?(Type|Enum)}
*/
resolvedType: (Type|Enum);
/**
* Sister-field within the extended type if a declaring extension field.
* @type {?Field}
*/
extensionField: Field;
/**
* Sister-field within the declaring namespace if an extended field.
* @type {?Field}
*/
declaringField: Field;
/**
* Determines whether this field is packed. Only relevant when repeated and working with proto2.
* @name Field#packed
* @type {boolean}
* @readonly
*/
readonly packed: boolean;
/**
* Determines whether this field is packed. This is an alias of {@link Field#packed|packed}'s getter for use within non-ES5 environments.
* @name Field#isPacked
* @function
* @returns {boolean}
*/
isPacked(): boolean;
/**
* Tests if the specified JSON object describes a field.
* @param {*} json Any JSON object to test
* @returns {boolean} `true` if the object describes a field
*/
static testJSON(json: any): boolean;
/**
* Constructs a field from JSON.
* @param {string} name Field name
* @param {Object.<string,*>} json JSON object
* @returns {Field} Created field
* @throws {TypeError} If arguments are invalid
*/
static fromJSON(name: string, json: { [k: string]: any }): Field;
/**
* Resolves this field's type references.
* @returns {Field} `this`
* @throws {Error} If any reference cannot be resolved
*/
resolve(): Field;
}
/**
* A node-style callback as used by {@link load} and {@link Root#load}.
* @typedef LoadCallback
* @type {function}
* @param {?Error} error Error, if any, otherwise `null`
* @param {Root} [root] Root, if there hasn't been an error
* @returns {undefined}
*/
type LoadCallback = (error: Error, root?: Root) => void;
/**
* Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.
* @param {string|string[]} filename One or multiple files to load
* @param {Root} root Root namespace, defaults to create a new one if omitted.
* @param {LoadCallback} callback Callback function
* @returns {undefined}
*/
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.
* @name load
* @function
* @param {string|string[]} filename One or multiple files to load
* @param {LoadCallback} callback Callback function
* @returns {undefined}
* @variation 2
*/
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.
* @name load
* @function
* @param {string|string[]} filename One or multiple files to load
* @param {Root} [root] Root namespace, defaults to create a new one if omitted.
* @returns {Promise<Root>} Promise
* @variation 3
*/
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 {string|string[]} filename One or multiple files to load
* @param {Root} [root] Root namespace, defaults to create a new one if omitted.
* @returns {Root} Root namespace
* @throws {Error} If synchronous fetching is not supported (i.e. in browsers) or if a file's syntax is invalid
*/
export function loadSync(filename: (string|string[]), root?: Root): Root;
/**
* Named roots.
* This is where pbjs stores generated structures (the option `-r, --root` specifies a name).
* Can also be used manually to make roots available accross modules.
* @name roots
* @type {Object.<string,Root>}
*/
export var roots: { [k: string]: Root };
/**
* Reconfigures the library according to the environment.
* @returns {undefined}
*/
export function configure(): void;
/**
* Constructs a new map field instance.
* @classdesc Reflected map field.
* @extends Field
* @constructor
* @param {string} name Unique name within its namespace
* @param {number} id Unique id within its namespace
* @param {string} keyType Key type
* @param {string} type Value type
* @param {Object.<string,*>} [options] Declared options
*/
export class MapField extends Field {
/**
* Constructs a new map field instance.
* @classdesc Reflected map field.
* @extends Field
* @constructor
* @param {string} name Unique name within its namespace
* @param {number} id Unique id within its namespace
* @param {string} keyType Key type
* @param {string} type Value type
* @param {Object.<string,*>} [options] Declared options
*/
constructor(name: string, id: number, keyType: string, type: string, options?: { [k: string]: any });
/**
* Key type.
* @type {string}
*/
keyType: string;
/**
* Resolved key type if not a basic type.
* @type {?ReflectionObject}
*/
resolvedKeyType: ReflectionObject;
/**
* Tests if the specified JSON object describes a map field.
* @param {*} json JSON object to test
* @returns {boolean} `true` if the object describes a field
*/
static testJSON(json: any): boolean;
/**
* Constructs a map field from JSON.
* @param {string} name Field name
* @param {Object.<string,*>} json JSON object
* @returns {MapField} Created map field
* @throws {TypeError} If arguments are invalid
*/
static fromJSON(name: string, json: { [k: string]: any }): MapField;
}
/**
* Constructs a new message instance.
*
* This function should also be called from your custom constructors, i.e. `Message.call(this, properties)`.
* @classdesc Abstract runtime message.
* @constructor
* @param {Object.<string,*>} [properties] Properties to set
* @see {@link Class.create}
*/
export class Message {
/**
* Constructs a new message instance.
*
* This function should also be called from your custom constructors, i.e. `Message.call(this, properties)`.
* @classdesc Abstract runtime message.
* @constructor
* @param {Object.<string,*>} [properties] Properties to set
* @see {@link Class.create}
*/
constructor(properties?: { [k: string]: any });
/**
* Reference to the reflected type.
* @name Message.$type
* @type {Type}
* @readonly
*/
static readonly $type: Type;
/**
* Reference to the reflected type.
* @name Message#$type
* @type {Type}
* @readonly
*/
readonly $type: Type;
/**
* Converts this message to a JSON object.
* @param {JSONConversionOptions} [options] Conversion options
* @returns {Object.<string,*>} JSON object
*/
asJSON(options?: JSONConversionOptions): { [k: string]: any };
/**
* Creates a message from a JSON object by converting strings and numbers to their respective field types.
* @param {Object.<string,*>} object JSON object
* @param {MessageConversionOptions} [options] Options
* @returns {Message} Message instance
*/
static from(object: { [k: string]: any }, options?: MessageConversionOptions): Message;
/**
* Encodes a message of this type.
* @param {Message|Object} message Message to encode
* @param {Writer} [writer] Writer to use
* @returns {Writer} Writer
*/
static encode(message: (Message|Object), writer?: Writer): Writer;
/**
* Encodes a message of this type preceeded by its length as a varint.
* @param {Message|Object} message Message to encode
* @param {Writer} [writer] Writer to use
* @returns {Writer} Writer
*/
static encodeDelimited(message: (Message|Object), writer?: Writer): Writer;
/**
* Decodes a message of this type.
* @name Message.decode
* @function
* @param {Reader|Uint8Array} readerOrBuffer Reader or buffer to decode
* @returns {Message} Decoded message
*/
static decode(readerOrBuffer: (Reader|Uint8Array)): Message;
/**
* Decodes a message of this type preceeded by its length as a varint.
* @name Message.decodeDelimited
* @function
* @param {Reader|Uint8Array} readerOrBuffer Reader or buffer to decode
* @returns {Message} Decoded message
*/
static decodeDelimited(readerOrBuffer: (Reader|Uint8Array)): Message;
/**
* Verifies a message of this type.
* @name Message.verify
* @function
* @param {Message|Object} message Message or plain object to verify
* @returns {?string} `null` if valid, otherwise the reason why it is not
*/
static verify(message: (Message|Object)): string;
}
/**
* Constructs a new service method instance.
* @classdesc Reflected service method.
* @extends ReflectionObject
* @constructor
* @param {string} name Method name
* @param {string|undefined} type Method type, usually `"rpc"`
* @param {string} requestType Request message type
* @param {string} responseType Response message type
* @param {boolean|Object.<string,*>} [requestStream] Whether the request is streamed
* @param {boolean|Object.<string,*>} [responseStream] Whether the response is streamed
* @param {Object.<string,*>} [options] Declared options
*/
export class Method extends ReflectionObject {
/**
* Constructs a new service method instance.
* @classdesc Reflected service method.
* @extends ReflectionObject
* @constructor
* @param {string} name Method name
* @param {string|undefined} type Method type, usually `"rpc"`
* @param {string} requestType Request message type
* @param {string} responseType Response message type
* @param {boolean|Object.<string,*>} [requestStream] Whether the request is streamed
* @param {boolean|Object.<string,*>} [responseStream] Whether the response is streamed
* @param {Object.<string,*>} [options] Declared options
*/
constructor(name: string, type: (string|undefined), requestType: string, responseType: string, requestStream?: (boolean|{ [k: string]: any }), responseStream?: (boolean|{ [k: string]: any }), options?: { [k: string]: any });
/**
* Method type.
* @type {string}
*/
type: string;
/**
* Request type.
* @type {string}
*/
requestType: string;
/**
* Whether requests are streamed or not.
* @type {boolean|undefined}
*/
requestStream: (boolean|undefined);
/**
* Response type.
* @type {string}
*/
responseType: string;
/**
* Whether responses are streamed or not.
* @type {boolean|undefined}
*/
responseStream: (boolean|undefined);
/**
* Resolved request type.
* @type {?Type}
*/
resolvedRequestType: Type;
/**
* Resolved response type.
* @type {?Type}
*/
resolvedResponseType: Type;
/**
* Tests if the specified JSON object describes a service method.
* @param {*} json JSON object
* @returns {boolean} `true` if the object describes a map field
*/
static testJSON(json: any): boolean;
/**
* Constructs a service method from JSON.
* @param {string} name Method name
* @param {Object.<string,*>} json JSON object
* @returns {Method} Created method
* @throws {TypeError} If arguments are invalid
*/
static fromJSON(name: string, json: { [k: string]: any }): Method;
}
/**
* Constructs a new namespace instance.
* @classdesc Reflected namespace and base class of all reflection objects containing nested objects.
* @extends ReflectionObject
* @constructor
* @param {string} name Namespace name
* @param {Object.<string,*>} [options] Declared options
*/
export class Namespace extends ReflectionObject {
/**
* Constructs a new namespace instance.
* @classdesc Reflected namespace and base class of all reflection objects containing nested objects.
* @extends ReflectionObject
* @constructor
* @param {string} name Namespace name
* @param {Object.<string,*>} [options] Declared options
*/
constructor(name: string, options?: { [k: string]: any });
/**
* Nested objects by name.
* @type {Object.<string,ReflectionObject>|undefined}
*/
nested: ({ [k: string]: ReflectionObject }|undefined);
/**
* Nested objects of this namespace as an array for iteration.
* @name Namespace#nestedArray
* @type {ReflectionObject[]}
* @readonly
*/
readonly nestedArray: ReflectionObject[];
/**
* Tests if the specified JSON object describes not another reflection object.
* @param {*} json JSON object
* @returns {boolean} `true` if the object describes not another reflection object
*/
static testJSON(json: any): boolean;
/**
* Constructs a namespace from JSON.
* @param {string} name Namespace name
* @param {Object.<string,*>} json JSON object
* @returns {Namespace} Created namespace
* @throws {TypeError} If arguments are invalid
*/
static fromJSON(name: string, json: { [k: string]: any }): Namespace;
/**
* Converts an array of reflection objects to JSON.
* @memberof Namespace
* @param {ReflectionObject[]} array Object array
* @returns {Object.<string,*>|undefined} JSON object or `undefined` when array is empty
*/
static arrayToJSON(array: ReflectionObject[]): ({ [k: string]: any }|undefined);
/**
* Adds nested elements to this namespace from JSON.
* @param {Object.<string,*>} nestedJson Nested JSON
* @returns {Namespace} `this`
*/
addJSON(nestedJson: { [k: string]: any }): Namespace;
/**
* Gets the nested object of the specified name.
* @param {string} name Nested object name
* @returns {?ReflectionObject} The reflection object or `null` if it doesn't exist
*/
get(name: string): ReflectionObject;
/**
* 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 {string} name Nested enum name
* @returns {Object.<string,number>} Enum values
* @throws {Error} If there is no such enum
*/
getEnum(name: string): { [k: string]: number };
/**
* Adds a nested object to this namespace.
* @param {ReflectionObject} object Nested object to add
* @returns {Namespace} `this`
* @throws {TypeError} If arguments are invalid
* @throws {Error} If there is already a nested object with this name
*/
add(object: ReflectionObject): Namespace;
/**
* Removes a nested object from this namespace.
* @param {ReflectionObject} object Nested object to remove
* @returns {Namespace} `this`
* @throws {TypeError} If arguments are invalid
* @throws {Error} If `object` is not a member of this namespace
*/
remove(object: ReflectionObject): Namespace;
/**
* Defines additial namespaces within this one if not yet existing.
* @param {string|string[]} path Path to create
* @param {*} [json] Nested types to create from JSON
* @returns {Namespace} Pointer to the last namespace created or `this` if path is empty
*/
define(path: (string|string[]), json?: any): Namespace;
/**
* Resolves this namespace's and all its nested objects' type references. Useful to validate a reflection tree.
* @returns {Namespace} `this`
*/
resolveAll(): Namespace;
/**
* Looks up the reflection object at the specified path, relative to this namespace.
* @param {string|string[]} path Path to look up
* @param {function(new: ReflectionObject)} filterType Filter type, one of `protobuf.Type`, `protobuf.Enum`, `protobuf.Service` etc.
* @param {boolean} [parentAlreadyChecked=false] If known, whether the parent has already been checked
* @returns {?ReflectionObject} Looked up object or `null` if none could be found
*/
lookup(path: (string|string[]), filterType: () => any, parentAlreadyChecked?: boolean): ReflectionObject;
/**
* Looks up the reflection object at the specified path, relative to this namespace.
* @name Namespace#lookup
* @function
* @param {string|string[]} path Path to look up
* @param {boolean} [parentAlreadyChecked=false] Whether the parent has already been checked
* @returns {?ReflectionObject} Looked up object or `null` if none could be found
* @variation 2
*/
lookup(path: (string|string[]), parentAlreadyChecked?: boolean): ReflectionObject;
/**
* 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 {string|string[]} path Path to look up
* @returns {Type} Looked up type
* @throws {Error} If `path` does not point to a type
*/
lookupType(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 {string|string[]} path Path to look up
* @returns {Service} Looked up service
* @throws {Error} If `path` does not point to a service
*/
lookupService(path: (string|string[])): Service;
/**
* 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 returns the enum's values directly and throws instead of returning `null`.
* @param {string|string[]} path Path to look up
* @returns {Object.<string,number>} Enum values
* @throws {Error} If `path` does not point to an enum
*/
lookupEnum(path: (string|string[])): { [k: string]: number };
}
/**
* Constructs a new reflection object instance.
* @classdesc Base class of all reflection objects.
* @constructor
* @param {string} name Object name
* @param {Object.<string,*>} [options] Declared options
* @abstract
*/
export abstract class ReflectionObject {
/**
* Options.
* @type {Object.<string,*>|undefined}
*/
options: ({ [k: string]: any }|undefined);
/**
* Unique name within its namespace.
* @type {string}
*/
name: string;
/**
* Parent namespace.
* @type {?Namespace}
*/
parent: Namespace;
/**
* Whether already resolved or not.
* @type {boolean}
*/
resolved: boolean;
/**
* Reference to the root namespace.
* @name ReflectionObject#root
* @type {Root}
* @readonly
*/
readonly root: Root;
/**
* Full name including leading dot.
* @name ReflectionObject#fullName
* @type {string}
* @readonly
*/
readonly fullName: string;
/**
* Converts this reflection object to its JSON representation.
* @returns {Object.<string,*>} JSON object
* @abstract
*/
toJSON(): { [k: string]: any };
/**
* Called when this object is added to a parent.
* @param {ReflectionObject} parent Parent added to
* @returns {undefined}
*/
onAdd(parent: ReflectionObject): void;
/**
* Called when this object is removed from a parent.
* @param {ReflectionObject} parent Parent removed from
* @returns {undefined}
*/
onRemove(parent: ReflectionObject): void;
/**
* Resolves this objects type references.
* @returns {ReflectionObject} `this`
*/
resolve(): ReflectionObject;
/**
* Gets an option value.
* @param {string} name Option name
* @returns {*} Option value or `undefined` if not set
*/
getOption(name: string): any;
/**
* Sets an option.
* @param {string} name Option name
* @param {*} value Option value
* @param {boolean} [ifNotSet] Sets the option only if it isn't currently set
* @returns {ReflectionObject} `this`
*/
setOption(name: string, value: any, ifNotSet?: boolean): ReflectionObject;
/**
* Sets multiple options.
* @param {Object.<string,*>} options Options to set
* @param {boolean} [ifNotSet] Sets an option only if it isn't currently set
* @returns {ReflectionObject} `this`
*/
setOptions(options: { [k: string]: any }, ifNotSet?: boolean): ReflectionObject;
/**
* Converts this instance to its string representation.
* @returns {string} Class name[, space, full name]
*/
toString(): string;
}
/**
* Constructs a new oneof instance.
* @classdesc Reflected oneof.
* @extends ReflectionObject
* @constructor
* @param {string} name Oneof name
* @param {string[]|Object} [fieldNames] Field names
* @param {Object.<string,*>} [options] Declared options
*/
export class OneOf extends ReflectionObject {
/**
* Constructs a new oneof instance.
* @classdesc Reflected oneof.