@depup/apollo__protobufjs 1.2.7-depup.0

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.
Files changed (113) hide show
  1. package/LICENSE +39 -0
  2. package/README.md +32 -0
  3. package/bin/pbjs +6 -0
  4. package/bin/pbts +6 -0
  5. package/changes.json +14 -0
  6. package/cli/LICENSE +33 -0
  7. package/cli/README.md +11 -0
  8. package/cli/bin/pbjs +6 -0
  9. package/cli/bin/pbts +6 -0
  10. package/cli/index.d.ts +3 -0
  11. package/cli/index.js +3 -0
  12. package/cli/lib/tsd-jsdoc/LICENSE +21 -0
  13. package/cli/lib/tsd-jsdoc/README.md +23 -0
  14. package/cli/lib/tsd-jsdoc/plugin.js +21 -0
  15. package/cli/lib/tsd-jsdoc/publish.js +693 -0
  16. package/cli/lib/tsd-jsdoc.json +18 -0
  17. package/cli/package.json +7 -0
  18. package/cli/package.standalone.json +32 -0
  19. package/cli/pbjs.d.ts +9 -0
  20. package/cli/pbjs.js +331 -0
  21. package/cli/pbts.d.ts +9 -0
  22. package/cli/pbts.js +198 -0
  23. package/cli/targets/json-module.js +38 -0
  24. package/cli/targets/json.js +8 -0
  25. package/cli/targets/proto.js +326 -0
  26. package/cli/targets/proto2.js +10 -0
  27. package/cli/targets/proto3.js +10 -0
  28. package/cli/targets/static-module.js +29 -0
  29. package/cli/targets/static.js +709 -0
  30. package/cli/util.js +183 -0
  31. package/cli/wrappers/amd.js +7 -0
  32. package/cli/wrappers/closure.js +7 -0
  33. package/cli/wrappers/commonjs.js +7 -0
  34. package/cli/wrappers/default.js +15 -0
  35. package/cli/wrappers/es6.js +5 -0
  36. package/dist/README.md +31 -0
  37. package/dist/light/README.md +31 -0
  38. package/dist/light/protobuf.js +7198 -0
  39. package/dist/light/protobuf.js.map +1 -0
  40. package/dist/light/protobuf.min.js +7 -0
  41. package/dist/light/protobuf.min.js.map +1 -0
  42. package/dist/minimal/README.md +31 -0
  43. package/dist/minimal/protobuf.js +2675 -0
  44. package/dist/minimal/protobuf.js.map +1 -0
  45. package/dist/minimal/protobuf.min.js +7 -0
  46. package/dist/minimal/protobuf.min.js.map +1 -0
  47. package/dist/protobuf.js +8775 -0
  48. package/dist/protobuf.js.map +1 -0
  49. package/dist/protobuf.min.js +7 -0
  50. package/dist/protobuf.min.js.map +1 -0
  51. package/ext/debug/README.md +4 -0
  52. package/ext/debug/index.js +71 -0
  53. package/ext/descriptor/README.md +72 -0
  54. package/ext/descriptor/index.d.ts +191 -0
  55. package/ext/descriptor/index.js +1052 -0
  56. package/ext/descriptor/test.js +54 -0
  57. package/google/LICENSE +27 -0
  58. package/google/README.md +1 -0
  59. package/google/api/annotations.json +83 -0
  60. package/google/api/annotations.proto +11 -0
  61. package/google/api/http.json +86 -0
  62. package/google/api/http.proto +31 -0
  63. package/google/protobuf/api.json +118 -0
  64. package/google/protobuf/api.proto +34 -0
  65. package/google/protobuf/descriptor.json +739 -0
  66. package/google/protobuf/descriptor.proto +286 -0
  67. package/google/protobuf/source_context.json +20 -0
  68. package/google/protobuf/source_context.proto +7 -0
  69. package/google/protobuf/type.json +202 -0
  70. package/google/protobuf/type.proto +89 -0
  71. package/index.d.ts +2628 -0
  72. package/index.js +4 -0
  73. package/light.d.ts +2 -0
  74. package/light.js +4 -0
  75. package/minimal.d.ts +2 -0
  76. package/minimal.js +4 -0
  77. package/package.json +147 -0
  78. package/scripts/postinstall.js +35 -0
  79. package/src/common.js +399 -0
  80. package/src/converter.js +304 -0
  81. package/src/decoder.js +106 -0
  82. package/src/encoder.js +119 -0
  83. package/src/enum.js +181 -0
  84. package/src/field.js +379 -0
  85. package/src/index-light.js +104 -0
  86. package/src/index-minimal.js +36 -0
  87. package/src/index.js +12 -0
  88. package/src/mapfield.js +126 -0
  89. package/src/message.js +139 -0
  90. package/src/method.js +151 -0
  91. package/src/namespace.js +433 -0
  92. package/src/object.js +200 -0
  93. package/src/oneof.js +203 -0
  94. package/src/parse.js +761 -0
  95. package/src/reader.js +405 -0
  96. package/src/reader_buffer.js +44 -0
  97. package/src/root.js +353 -0
  98. package/src/roots.js +18 -0
  99. package/src/rpc/service.js +142 -0
  100. package/src/rpc.js +36 -0
  101. package/src/service.js +167 -0
  102. package/src/tokenize.js +397 -0
  103. package/src/type.js +589 -0
  104. package/src/types.js +196 -0
  105. package/src/typescript.jsdoc +22 -0
  106. package/src/util/longbits.js +200 -0
  107. package/src/util/minimal.js +406 -0
  108. package/src/util.js +178 -0
  109. package/src/verifier.js +191 -0
  110. package/src/wrappers.js +83 -0
  111. package/src/writer.js +459 -0
  112. package/src/writer_buffer.js +81 -0
  113. package/tsconfig.json +7 -0
package/index.d.ts ADDED
@@ -0,0 +1,2628 @@
1
+ // DO NOT EDIT! This is a generated file. Edit the JSDoc in src/*.js instead and run 'npm run types'.
2
+
3
+ export as namespace protobuf;
4
+
5
+ /**
6
+ * Provides common type definitions.
7
+ * Can also be used to provide additional google types or your own custom types.
8
+ * @param name Short name as in `google/protobuf/[name].proto` or full file name
9
+ * @param json JSON definition within `google.protobuf` if a short name, otherwise the file's root definition
10
+ */
11
+ export function common(name: string, json: { [k: string]: any }): void;
12
+
13
+ export namespace common {
14
+
15
+ /** Properties of a google.protobuf.Any message. */
16
+ interface IAny {
17
+ typeUrl?: string;
18
+ bytes?: Uint8Array;
19
+ }
20
+
21
+ /** Properties of a google.protobuf.Duration message. */
22
+ interface IDuration {
23
+ seconds?: number;
24
+ nanos?: number;
25
+ }
26
+
27
+ /** Properties of a google.protobuf.Timestamp message. */
28
+ interface ITimestamp {
29
+ seconds?: number;
30
+ nanos?: number;
31
+ }
32
+
33
+ /** Properties of a google.protobuf.Empty message. */
34
+ interface IEmpty {
35
+ }
36
+
37
+ /** Properties of a google.protobuf.Struct message. */
38
+ interface IStruct {
39
+ fields?: { [k: string]: IValue };
40
+ }
41
+
42
+ /** Properties of a google.protobuf.Value message. */
43
+ interface IValue {
44
+ kind?: string;
45
+ nullValue?: 0;
46
+ numberValue?: number;
47
+ stringValue?: string;
48
+ boolValue?: boolean;
49
+ structValue?: IStruct;
50
+ listValue?: IListValue;
51
+ }
52
+
53
+ /** Properties of a google.protobuf.ListValue message. */
54
+ interface IListValue {
55
+ values?: IValue[];
56
+ }
57
+
58
+ /** Properties of a google.protobuf.DoubleValue message. */
59
+ interface IDoubleValue {
60
+ value?: number;
61
+ }
62
+
63
+ /** Properties of a google.protobuf.FloatValue message. */
64
+ interface IFloatValue {
65
+ value?: number;
66
+ }
67
+
68
+ /** Properties of a google.protobuf.Int64Value message. */
69
+ interface IInt64Value {
70
+ value?: number;
71
+ }
72
+
73
+ /** Properties of a google.protobuf.UInt64Value message. */
74
+ interface IUInt64Value {
75
+ value?: number;
76
+ }
77
+
78
+ /** Properties of a google.protobuf.Int32Value message. */
79
+ interface IInt32Value {
80
+ value?: number;
81
+ }
82
+
83
+ /** Properties of a google.protobuf.UInt32Value message. */
84
+ interface IUInt32Value {
85
+ value?: number;
86
+ }
87
+
88
+ /** Properties of a google.protobuf.BoolValue message. */
89
+ interface IBoolValue {
90
+ value?: boolean;
91
+ }
92
+
93
+ /** Properties of a google.protobuf.StringValue message. */
94
+ interface IStringValue {
95
+ value?: string;
96
+ }
97
+
98
+ /** Properties of a google.protobuf.BytesValue message. */
99
+ interface IBytesValue {
100
+ value?: Uint8Array;
101
+ }
102
+
103
+ /**
104
+ * Gets the root definition of the specified common proto file.
105
+ *
106
+ * Bundled definitions are:
107
+ * - google/protobuf/any.proto
108
+ * - google/protobuf/duration.proto
109
+ * - google/protobuf/empty.proto
110
+ * - google/protobuf/field_mask.proto
111
+ * - google/protobuf/struct.proto
112
+ * - google/protobuf/timestamp.proto
113
+ * - google/protobuf/wrappers.proto
114
+ *
115
+ * @param file Proto file name
116
+ * @returns Root definition or `null` if not defined
117
+ */
118
+ function get(file: string): (INamespace|null);
119
+ }
120
+
121
+ /** Runtime message from/to plain object converters. */
122
+ export namespace converter {
123
+
124
+ /**
125
+ * Generates a plain object to runtime message converter specific to the specified message type.
126
+ * @param mtype Message type
127
+ * @returns Codegen instance
128
+ */
129
+ function fromObject(mtype: Type): Codegen;
130
+
131
+ /**
132
+ * Generates a runtime message to plain object converter specific to the specified message type.
133
+ * @param mtype Message type
134
+ * @returns Codegen instance
135
+ */
136
+ function toObject(mtype: Type): Codegen;
137
+ }
138
+
139
+ /**
140
+ * Generates a decoder specific to the specified message type.
141
+ * @param mtype Message type
142
+ * @returns Codegen instance
143
+ */
144
+ export function decoder(mtype: Type): Codegen;
145
+
146
+ /**
147
+ * Generates an encoder specific to the specified message type.
148
+ * @param mtype Message type
149
+ * @returns Codegen instance
150
+ */
151
+ export function encoder(mtype: Type): Codegen;
152
+
153
+ /** Reflected enum. */
154
+ export class Enum extends ReflectionObject {
155
+
156
+ /**
157
+ * Constructs a new enum instance.
158
+ * @param name Unique name within its namespace
159
+ * @param [values] Enum values as an object, by name
160
+ * @param [options] Declared options
161
+ * @param [comment] The comment for this enum
162
+ * @param [comments] The value comments for this enum
163
+ */
164
+ constructor(name: string, values?: { [k: string]: number }, options?: { [k: string]: any }, comment?: string, comments?: { [k: string]: string });
165
+
166
+ /** Enum values by id. */
167
+ public valuesById: { [k: number]: string };
168
+
169
+ /** Enum values by name. */
170
+ public values: { [k: string]: number };
171
+
172
+ /** Enum comment text. */
173
+ public comment: (string|null);
174
+
175
+ /** Value comment texts, if any. */
176
+ public comments: { [k: string]: string };
177
+
178
+ /** Reserved ranges, if any. */
179
+ public reserved: (number[]|string)[];
180
+
181
+ /**
182
+ * Constructs an enum from an enum descriptor.
183
+ * @param name Enum name
184
+ * @param json Enum descriptor
185
+ * @returns Created enum
186
+ * @throws {TypeError} If arguments are invalid
187
+ */
188
+ public static fromJSON(name: string, json: IEnum): Enum;
189
+
190
+ /**
191
+ * Converts this enum to an enum descriptor.
192
+ * @param [toJSONOptions] JSON conversion options
193
+ * @returns Enum descriptor
194
+ */
195
+ public toJSON(toJSONOptions?: IToJSONOptions): IEnum;
196
+
197
+ /**
198
+ * Adds a value to this enum.
199
+ * @param name Value name
200
+ * @param id Value id
201
+ * @param [comment] Comment, if any
202
+ * @returns `this`
203
+ * @throws {TypeError} If arguments are invalid
204
+ * @throws {Error} If there is already a value with this name or id
205
+ */
206
+ public add(name: string, id: number, comment?: string): Enum;
207
+
208
+ /**
209
+ * Removes a value from this enum
210
+ * @param name Value name
211
+ * @returns `this`
212
+ * @throws {TypeError} If arguments are invalid
213
+ * @throws {Error} If `name` is not a name of this enum
214
+ */
215
+ public remove(name: string): Enum;
216
+
217
+ /**
218
+ * Tests if the specified id is reserved.
219
+ * @param id Id to test
220
+ * @returns `true` if reserved, otherwise `false`
221
+ */
222
+ public isReservedId(id: number): boolean;
223
+
224
+ /**
225
+ * Tests if the specified name is reserved.
226
+ * @param name Name to test
227
+ * @returns `true` if reserved, otherwise `false`
228
+ */
229
+ public isReservedName(name: string): boolean;
230
+ }
231
+
232
+ /** Enum descriptor. */
233
+ export interface IEnum {
234
+
235
+ /** Enum values */
236
+ values: { [k: string]: number };
237
+
238
+ /** Enum options */
239
+ options?: { [k: string]: any };
240
+ }
241
+
242
+ /** Reflected message field. */
243
+ export class Field extends FieldBase {
244
+
245
+ /**
246
+ * Constructs a new message field instance. Note that {@link MapField|map fields} have their own class.
247
+ * @param name Unique name within its namespace
248
+ * @param id Unique id within its namespace
249
+ * @param type Value type
250
+ * @param [rule="optional"] Field rule
251
+ * @param [extend] Extended type if different from parent
252
+ * @param [options] Declared options
253
+ */
254
+ constructor(name: string, id: number, type: string, rule?: (string|{ [k: string]: any }), extend?: (string|{ [k: string]: any }), options?: { [k: string]: any });
255
+
256
+ /**
257
+ * Constructs a field from a field descriptor.
258
+ * @param name Field name
259
+ * @param json Field descriptor
260
+ * @returns Created field
261
+ * @throws {TypeError} If arguments are invalid
262
+ */
263
+ public static fromJSON(name: string, json: IField): Field;
264
+
265
+ /** Determines whether this field is packed. Only relevant when repeated and working with proto2. */
266
+ public readonly packed: boolean;
267
+
268
+ /**
269
+ * Field decorator (TypeScript).
270
+ * @param fieldId Field id
271
+ * @param fieldType Field type
272
+ * @param [fieldRule="optional"] Field rule
273
+ * @param [defaultValue] Default value
274
+ * @returns Decorator function
275
+ */
276
+ public static d<T extends number | number[] | 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;
277
+
278
+ /**
279
+ * Field decorator (TypeScript).
280
+ * @param fieldId Field id
281
+ * @param fieldType Field type
282
+ * @param [fieldRule="optional"] Field rule
283
+ * @returns Decorator function
284
+ */
285
+ public static d<T extends Message<T>>(fieldId: number, fieldType: (Constructor<T>|string), fieldRule?: ("optional"|"required"|"repeated")): FieldDecorator;
286
+ }
287
+
288
+ /** Base class of all reflected message fields. This is not an actual class but here for the sake of having consistent type definitions. */
289
+ export class FieldBase extends ReflectionObject {
290
+
291
+ /**
292
+ * Not an actual constructor. Use {@link Field} instead.
293
+ * @param name Unique name within its namespace
294
+ * @param id Unique id within its namespace
295
+ * @param type Value type
296
+ * @param [rule="optional"] Field rule
297
+ * @param [extend] Extended type if different from parent
298
+ * @param [options] Declared options
299
+ * @param [comment] Comment associated with this field
300
+ */
301
+ constructor(name: string, id: number, type: string, rule?: (string|{ [k: string]: any }), extend?: (string|{ [k: string]: any }), options?: { [k: string]: any }, comment?: string);
302
+
303
+ /** Field rule, if any. */
304
+ public rule?: string;
305
+
306
+ /** Field type. */
307
+ public type: string;
308
+
309
+ /** Unique field id. */
310
+ public id: number;
311
+
312
+ /** Extended type if different from parent. */
313
+ public extend?: string;
314
+
315
+ /** Whether this field is required. */
316
+ public required: boolean;
317
+
318
+ /** Whether this field is optional. */
319
+ public optional: boolean;
320
+
321
+ /** Whether this field is repeated. */
322
+ public repeated: boolean;
323
+
324
+ /** Whether this field is a map or not. */
325
+ public map: boolean;
326
+
327
+ /** Message this field belongs to. */
328
+ public message: (Type|null);
329
+
330
+ /** OneOf this field belongs to, if any, */
331
+ public partOf: (OneOf|null);
332
+
333
+ /** The field type's default value. */
334
+ public typeDefault: any;
335
+
336
+ /** The field's default value on prototypes. */
337
+ public defaultValue: any;
338
+
339
+ /** Whether this field's value should be treated as a long. */
340
+ public long: boolean;
341
+
342
+ /** Whether this field's value is a buffer. */
343
+ public bytes: boolean;
344
+
345
+ /** Resolved type if not a basic type. */
346
+ public resolvedType: (Type|Enum|null);
347
+
348
+ /** Sister-field within the extended type if a declaring extension field. */
349
+ public extensionField: (Field|null);
350
+
351
+ /** Sister-field within the declaring namespace if an extended field. */
352
+ public declaringField: (Field|null);
353
+
354
+ /** Comment for this field. */
355
+ public comment: (string|null);
356
+
357
+ /**
358
+ * Converts this field to a field descriptor.
359
+ * @param [toJSONOptions] JSON conversion options
360
+ * @returns Field descriptor
361
+ */
362
+ public toJSON(toJSONOptions?: IToJSONOptions): IField;
363
+
364
+ /**
365
+ * Resolves this field's type references.
366
+ * @returns `this`
367
+ * @throws {Error} If any reference cannot be resolved
368
+ */
369
+ public resolve(): Field;
370
+ }
371
+
372
+ /** Field descriptor. */
373
+ export interface IField {
374
+
375
+ /** Field rule */
376
+ rule?: string;
377
+
378
+ /** Field type */
379
+ type: string;
380
+
381
+ /** Field id */
382
+ id: number;
383
+
384
+ /** Field options */
385
+ options?: { [k: string]: any };
386
+ }
387
+
388
+ /** Extension field descriptor. */
389
+ export interface IExtensionField extends IField {
390
+
391
+ /** Extended type */
392
+ extend: string;
393
+ }
394
+
395
+ /**
396
+ * Decorator function as returned by {@link Field.d} and {@link MapField.d} (TypeScript).
397
+ * @param prototype Target prototype
398
+ * @param fieldName Field name
399
+ */
400
+ type FieldDecorator = (prototype: object, fieldName: string) => void;
401
+
402
+ /**
403
+ * A node-style callback as used by {@link load} and {@link Root#load}.
404
+ * @param error Error, if any, otherwise `null`
405
+ * @param [root] Root, if there hasn't been an error
406
+ */
407
+ type LoadCallback = (error: (Error|null), root?: Root) => void;
408
+
409
+ /**
410
+ * Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.
411
+ * @param filename One or multiple files to load
412
+ * @param root Root namespace, defaults to create a new one if omitted.
413
+ * @param callback Callback function
414
+ * @see {@link Root#load}
415
+ */
416
+ export function load(filename: (string|string[]), root: Root, callback: LoadCallback): void;
417
+
418
+ /**
419
+ * Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.
420
+ * @param filename One or multiple files to load
421
+ * @param callback Callback function
422
+ * @see {@link Root#load}
423
+ */
424
+ export function load(filename: (string|string[]), callback: LoadCallback): void;
425
+
426
+ /**
427
+ * Loads one or multiple .proto or preprocessed .json files into a common root namespace and returns a promise.
428
+ * @param filename One or multiple files to load
429
+ * @param [root] Root namespace, defaults to create a new one if omitted.
430
+ * @returns Promise
431
+ * @see {@link Root#load}
432
+ */
433
+ export function load(filename: (string|string[]), root?: Root): Promise<Root>;
434
+
435
+ /**
436
+ * Synchronously loads one or multiple .proto or preprocessed .json files into a common root namespace (node only).
437
+ * @param filename One or multiple files to load
438
+ * @param [root] Root namespace, defaults to create a new one if omitted.
439
+ * @returns Root namespace
440
+ * @throws {Error} If synchronous fetching is not supported (i.e. in browsers) or if a file's syntax is invalid
441
+ * @see {@link Root#loadSync}
442
+ */
443
+ export function loadSync(filename: (string|string[]), root?: Root): Root;
444
+
445
+ /** Build type, one of `"full"`, `"light"` or `"minimal"`. */
446
+ export const build: string;
447
+
448
+ /** Reconfigures the library according to the environment. */
449
+ export function configure(): void;
450
+
451
+ /** Reflected map field. */
452
+ export class MapField extends FieldBase {
453
+
454
+ /**
455
+ * Constructs a new map field instance.
456
+ * @param name Unique name within its namespace
457
+ * @param id Unique id within its namespace
458
+ * @param keyType Key type
459
+ * @param type Value type
460
+ * @param [options] Declared options
461
+ * @param [comment] Comment associated with this field
462
+ */
463
+ constructor(name: string, id: number, keyType: string, type: string, options?: { [k: string]: any }, comment?: string);
464
+
465
+ /** Key type. */
466
+ public keyType: string;
467
+
468
+ /** Resolved key type if not a basic type. */
469
+ public resolvedKeyType: (ReflectionObject|null);
470
+
471
+ /**
472
+ * Constructs a map field from a map field descriptor.
473
+ * @param name Field name
474
+ * @param json Map field descriptor
475
+ * @returns Created map field
476
+ * @throws {TypeError} If arguments are invalid
477
+ */
478
+ public static fromJSON(name: string, json: IMapField): MapField;
479
+
480
+ /**
481
+ * Converts this map field to a map field descriptor.
482
+ * @param [toJSONOptions] JSON conversion options
483
+ * @returns Map field descriptor
484
+ */
485
+ public toJSON(toJSONOptions?: IToJSONOptions): IMapField;
486
+
487
+ /**
488
+ * Map field decorator (TypeScript).
489
+ * @param fieldId Field id
490
+ * @param fieldKeyType Field key type
491
+ * @param fieldValueType Field value type
492
+ * @returns Decorator function
493
+ */
494
+ public static d<T extends { [key: string]: number | 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;
495
+ }
496
+
497
+ /** Map field descriptor. */
498
+ export interface IMapField extends IField {
499
+
500
+ /** Key type */
501
+ keyType: string;
502
+ }
503
+
504
+ /** Extension map field descriptor. */
505
+ export interface IExtensionMapField extends IMapField {
506
+
507
+ /** Extended type */
508
+ extend: string;
509
+ }
510
+
511
+ /** Abstract runtime message. */
512
+ export class Message<T extends object = object> {
513
+
514
+ /**
515
+ * Constructs a new message instance.
516
+ * @param [properties] Properties to set
517
+ */
518
+ constructor(properties?: Properties<T>);
519
+
520
+ /** Reference to the reflected type. */
521
+ public static readonly $type: Type;
522
+
523
+ /** Reference to the reflected type. */
524
+ public readonly $type: Type;
525
+
526
+ /**
527
+ * Creates a new message of this type using the specified properties.
528
+ * @param [properties] Properties to set
529
+ * @returns Message instance
530
+ */
531
+ public static create<T extends Message<T>>(this: Constructor<T>, properties?: { [k: string]: any }): Message<T>;
532
+
533
+ /**
534
+ * Encodes a message of this type.
535
+ * @param message Message to encode
536
+ * @param [writer] Writer to use
537
+ * @returns Writer
538
+ */
539
+ public static encode<T extends Message<T>>(this: Constructor<T>, message: (T|{ [k: string]: any }), writer?: Writer): Writer;
540
+
541
+ /**
542
+ * Encodes a message of this type preceeded by its length as a varint.
543
+ * @param message Message to encode
544
+ * @param [writer] Writer to use
545
+ * @returns Writer
546
+ */
547
+ public static encodeDelimited<T extends Message<T>>(this: Constructor<T>, message: (T|{ [k: string]: any }), writer?: Writer): Writer;
548
+
549
+ /**
550
+ * Decodes a message of this type.
551
+ * @param reader Reader or buffer to decode
552
+ * @returns Decoded message
553
+ */
554
+ public static decode<T extends Message<T>>(this: Constructor<T>, reader: (Reader|Uint8Array)): T;
555
+
556
+ /**
557
+ * Decodes a message of this type preceeded by its length as a varint.
558
+ * @param reader Reader or buffer to decode
559
+ * @returns Decoded message
560
+ */
561
+ public static decodeDelimited<T extends Message<T>>(this: Constructor<T>, reader: (Reader|Uint8Array)): T;
562
+
563
+ /**
564
+ * Verifies a message of this type.
565
+ * @param message Plain object to verify
566
+ * @returns `null` if valid, otherwise the reason why it is not
567
+ */
568
+ public static verify(message: { [k: string]: any }): (string|null);
569
+
570
+ /**
571
+ * Creates a new message of this type from a plain object. Also converts values to their respective internal types.
572
+ * @param object Plain object
573
+ * @returns Message instance
574
+ */
575
+ public static fromObject<T extends Message<T>>(this: Constructor<T>, object: { [k: string]: any }): T;
576
+
577
+ /**
578
+ * Creates a plain object from a message of this type. Also converts values to other types if specified.
579
+ * @param message Message instance
580
+ * @param [options] Conversion options
581
+ * @returns Plain object
582
+ */
583
+ public static toObject<T extends Message<T>>(this: Constructor<T>, message: T, options?: IConversionOptions): { [k: string]: any };
584
+
585
+ /**
586
+ * Converts this message to JSON.
587
+ * @returns JSON object
588
+ */
589
+ public toJSON(): { [k: string]: any };
590
+ }
591
+
592
+ /** Reflected service method. */
593
+ export class Method extends ReflectionObject {
594
+
595
+ /**
596
+ * Constructs a new service method instance.
597
+ * @param name Method name
598
+ * @param type Method type, usually `"rpc"`
599
+ * @param requestType Request message type
600
+ * @param responseType Response message type
601
+ * @param [requestStream] Whether the request is streamed
602
+ * @param [responseStream] Whether the response is streamed
603
+ * @param [options] Declared options
604
+ * @param [comment] The comment for this method
605
+ */
606
+ 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);
607
+
608
+ /** Method type. */
609
+ public type: string;
610
+
611
+ /** Request type. */
612
+ public requestType: string;
613
+
614
+ /** Whether requests are streamed or not. */
615
+ public requestStream?: boolean;
616
+
617
+ /** Response type. */
618
+ public responseType: string;
619
+
620
+ /** Whether responses are streamed or not. */
621
+ public responseStream?: boolean;
622
+
623
+ /** Resolved request type. */
624
+ public resolvedRequestType: (Type|null);
625
+
626
+ /** Resolved response type. */
627
+ public resolvedResponseType: (Type|null);
628
+
629
+ /** Comment for this method */
630
+ public comment: (string|null);
631
+
632
+ /**
633
+ * Constructs a method from a method descriptor.
634
+ * @param name Method name
635
+ * @param json Method descriptor
636
+ * @returns Created method
637
+ * @throws {TypeError} If arguments are invalid
638
+ */
639
+ public static fromJSON(name: string, json: IMethod): Method;
640
+
641
+ /**
642
+ * Converts this method to a method descriptor.
643
+ * @param [toJSONOptions] JSON conversion options
644
+ * @returns Method descriptor
645
+ */
646
+ public toJSON(toJSONOptions?: IToJSONOptions): IMethod;
647
+ }
648
+
649
+ /** Method descriptor. */
650
+ export interface IMethod {
651
+
652
+ /** Method type */
653
+ type?: string;
654
+
655
+ /** Request type */
656
+ requestType: string;
657
+
658
+ /** Response type */
659
+ responseType: string;
660
+
661
+ /** Whether requests are streamed */
662
+ requestStream?: boolean;
663
+
664
+ /** Whether responses are streamed */
665
+ responseStream?: boolean;
666
+
667
+ /** Method options */
668
+ options?: { [k: string]: any };
669
+ }
670
+
671
+ /** Reflected namespace. */
672
+ export class Namespace extends NamespaceBase {
673
+
674
+ /**
675
+ * Constructs a new namespace instance.
676
+ * @param name Namespace name
677
+ * @param [options] Declared options
678
+ */
679
+ constructor(name: string, options?: { [k: string]: any });
680
+
681
+ /**
682
+ * Constructs a namespace from JSON.
683
+ * @param name Namespace name
684
+ * @param json JSON object
685
+ * @returns Created namespace
686
+ * @throws {TypeError} If arguments are invalid
687
+ */
688
+ public static fromJSON(name: string, json: { [k: string]: any }): Namespace;
689
+
690
+ /**
691
+ * Converts an array of reflection objects to JSON.
692
+ * @param array Object array
693
+ * @param [toJSONOptions] JSON conversion options
694
+ * @returns JSON object or `undefined` when array is empty
695
+ */
696
+ public static arrayToJSON(array: ReflectionObject[], toJSONOptions?: IToJSONOptions): ({ [k: string]: any }|undefined);
697
+
698
+ /**
699
+ * Tests if the specified id is reserved.
700
+ * @param reserved Array of reserved ranges and names
701
+ * @param id Id to test
702
+ * @returns `true` if reserved, otherwise `false`
703
+ */
704
+ public static isReservedId(reserved: ((number[]|string)[]|undefined), id: number): boolean;
705
+
706
+ /**
707
+ * Tests if the specified name is reserved.
708
+ * @param reserved Array of reserved ranges and names
709
+ * @param name Name to test
710
+ * @returns `true` if reserved, otherwise `false`
711
+ */
712
+ public static isReservedName(reserved: ((number[]|string)[]|undefined), name: string): boolean;
713
+ }
714
+
715
+ /** 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. */
716
+ export abstract class NamespaceBase extends ReflectionObject {
717
+
718
+ /** Nested objects by name. */
719
+ public nested?: { [k: string]: ReflectionObject };
720
+
721
+ /** Nested objects of this namespace as an array for iteration. */
722
+ public readonly nestedArray: ReflectionObject[];
723
+
724
+ /**
725
+ * Converts this namespace to a namespace descriptor.
726
+ * @param [toJSONOptions] JSON conversion options
727
+ * @returns Namespace descriptor
728
+ */
729
+ public toJSON(toJSONOptions?: IToJSONOptions): INamespace;
730
+
731
+ /**
732
+ * Adds nested objects to this namespace from nested object descriptors.
733
+ * @param nestedJson Any nested object descriptors
734
+ * @returns `this`
735
+ */
736
+ public addJSON(nestedJson: { [k: string]: AnyNestedObject }): Namespace;
737
+
738
+ /**
739
+ * Gets the nested object of the specified name.
740
+ * @param name Nested object name
741
+ * @returns The reflection object or `null` if it doesn't exist
742
+ */
743
+ public get(name: string): (ReflectionObject|null);
744
+
745
+ /**
746
+ * Gets the values of the nested {@link Enum|enum} of the specified name.
747
+ * This methods differs from {@link Namespace#get|get} in that it returns an enum's values directly and throws instead of returning `null`.
748
+ * @param name Nested enum name
749
+ * @returns Enum values
750
+ * @throws {Error} If there is no such enum
751
+ */
752
+ public getEnum(name: string): { [k: string]: number };
753
+
754
+ /**
755
+ * Adds a nested object to this namespace.
756
+ * @param object Nested object to add
757
+ * @returns `this`
758
+ * @throws {TypeError} If arguments are invalid
759
+ * @throws {Error} If there is already a nested object with this name
760
+ */
761
+ public add(object: ReflectionObject): Namespace;
762
+
763
+ /**
764
+ * Removes a nested object from this namespace.
765
+ * @param object Nested object to remove
766
+ * @returns `this`
767
+ * @throws {TypeError} If arguments are invalid
768
+ * @throws {Error} If `object` is not a member of this namespace
769
+ */
770
+ public remove(object: ReflectionObject): Namespace;
771
+
772
+ /**
773
+ * Defines additial namespaces within this one if not yet existing.
774
+ * @param path Path to create
775
+ * @param [json] Nested types to create from JSON
776
+ * @returns Pointer to the last namespace created or `this` if path is empty
777
+ */
778
+ public define(path: (string|string[]), json?: any): Namespace;
779
+
780
+ /**
781
+ * Resolves this namespace's and all its nested objects' type references. Useful to validate a reflection tree, but comes at a cost.
782
+ * @returns `this`
783
+ */
784
+ public resolveAll(): Namespace;
785
+
786
+ /**
787
+ * Recursively looks up the reflection object matching the specified path in the scope of this namespace.
788
+ * @param path Path to look up
789
+ * @param filterTypes Filter types, any combination of the constructors of `protobuf.Type`, `protobuf.Enum`, `protobuf.Service` etc.
790
+ * @param [parentAlreadyChecked=false] If known, whether the parent has already been checked
791
+ * @returns Looked up object or `null` if none could be found
792
+ */
793
+ public lookup(path: (string|string[]), filterTypes: (any|any[]), parentAlreadyChecked?: boolean): (ReflectionObject|null);
794
+
795
+ /**
796
+ * Looks up the reflection object at the specified path, relative to this namespace.
797
+ * @param path Path to look up
798
+ * @param [parentAlreadyChecked=false] Whether the parent has already been checked
799
+ * @returns Looked up object or `null` if none could be found
800
+ */
801
+ public lookup(path: (string|string[]), parentAlreadyChecked?: boolean): (ReflectionObject|null);
802
+
803
+ /**
804
+ * Looks up the {@link Type|type} at the specified path, relative to this namespace.
805
+ * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
806
+ * @param path Path to look up
807
+ * @returns Looked up type
808
+ * @throws {Error} If `path` does not point to a type
809
+ */
810
+ public lookupType(path: (string|string[])): Type;
811
+
812
+ /**
813
+ * Looks up the values of the {@link Enum|enum} at the specified path, relative to this namespace.
814
+ * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
815
+ * @param path Path to look up
816
+ * @returns Looked up enum
817
+ * @throws {Error} If `path` does not point to an enum
818
+ */
819
+ public lookupEnum(path: (string|string[])): Enum;
820
+
821
+ /**
822
+ * Looks up the {@link Type|type} or {@link Enum|enum} at the specified path, relative to this namespace.
823
+ * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
824
+ * @param path Path to look up
825
+ * @returns Looked up type or enum
826
+ * @throws {Error} If `path` does not point to a type or enum
827
+ */
828
+ public lookupTypeOrEnum(path: (string|string[])): Type;
829
+
830
+ /**
831
+ * Looks up the {@link Service|service} at the specified path, relative to this namespace.
832
+ * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
833
+ * @param path Path to look up
834
+ * @returns Looked up service
835
+ * @throws {Error} If `path` does not point to a service
836
+ */
837
+ public lookupService(path: (string|string[])): Service;
838
+ }
839
+
840
+ /** Namespace descriptor. */
841
+ export interface INamespace {
842
+
843
+ /** Namespace options */
844
+ options?: { [k: string]: any };
845
+
846
+ /** Nested object descriptors */
847
+ nested?: { [k: string]: AnyNestedObject };
848
+ }
849
+
850
+ /** Any extension field descriptor. */
851
+ type AnyExtensionField = (IExtensionField|IExtensionMapField);
852
+
853
+ /** Any nested object descriptor. */
854
+ type AnyNestedObject = (IEnum|IType|IService|AnyExtensionField|INamespace);
855
+
856
+ /** Base class of all reflection objects. */
857
+ export abstract class ReflectionObject {
858
+
859
+ /** Options. */
860
+ public options?: { [k: string]: any };
861
+
862
+ /** Unique name within its namespace. */
863
+ public name: string;
864
+
865
+ /** Parent namespace. */
866
+ public parent: (Namespace|null);
867
+
868
+ /** Whether already resolved or not. */
869
+ public resolved: boolean;
870
+
871
+ /** Comment text, if any. */
872
+ public comment: (string|null);
873
+
874
+ /** Defining file name. */
875
+ public filename: (string|null);
876
+
877
+ /** Reference to the root namespace. */
878
+ public readonly root: Root;
879
+
880
+ /** Full name including leading dot. */
881
+ public readonly fullName: string;
882
+
883
+ /**
884
+ * Converts this reflection object to its descriptor representation.
885
+ * @returns Descriptor
886
+ */
887
+ public toJSON(): { [k: string]: any };
888
+
889
+ /**
890
+ * Called when this object is added to a parent.
891
+ * @param parent Parent added to
892
+ */
893
+ public onAdd(parent: ReflectionObject): void;
894
+
895
+ /**
896
+ * Called when this object is removed from a parent.
897
+ * @param parent Parent removed from
898
+ */
899
+ public onRemove(parent: ReflectionObject): void;
900
+
901
+ /**
902
+ * Resolves this objects type references.
903
+ * @returns `this`
904
+ */
905
+ public resolve(): ReflectionObject;
906
+
907
+ /**
908
+ * Gets an option value.
909
+ * @param name Option name
910
+ * @returns Option value or `undefined` if not set
911
+ */
912
+ public getOption(name: string): any;
913
+
914
+ /**
915
+ * Sets an option.
916
+ * @param name Option name
917
+ * @param value Option value
918
+ * @param [ifNotSet] Sets the option only if it isn't currently set
919
+ * @returns `this`
920
+ */
921
+ public setOption(name: string, value: any, ifNotSet?: boolean): ReflectionObject;
922
+
923
+ /**
924
+ * Sets multiple options.
925
+ * @param options Options to set
926
+ * @param [ifNotSet] Sets an option only if it isn't currently set
927
+ * @returns `this`
928
+ */
929
+ public setOptions(options: { [k: string]: any }, ifNotSet?: boolean): ReflectionObject;
930
+
931
+ /**
932
+ * Converts this instance to its string representation.
933
+ * @returns Class name[, space, full name]
934
+ */
935
+ public toString(): string;
936
+ }
937
+
938
+ /** Reflected oneof. */
939
+ export class OneOf extends ReflectionObject {
940
+
941
+ /**
942
+ * Constructs a new oneof instance.
943
+ * @param name Oneof name
944
+ * @param [fieldNames] Field names
945
+ * @param [options] Declared options
946
+ * @param [comment] Comment associated with this field
947
+ */
948
+ constructor(name: string, fieldNames?: (string[]|{ [k: string]: any }), options?: { [k: string]: any }, comment?: string);
949
+
950
+ /** Field names that belong to this oneof. */
951
+ public oneof: string[];
952
+
953
+ /** Fields that belong to this oneof as an array for iteration. */
954
+ public readonly fieldsArray: Field[];
955
+
956
+ /** Comment for this field. */
957
+ public comment: (string|null);
958
+
959
+ /**
960
+ * Constructs a oneof from a oneof descriptor.
961
+ * @param name Oneof name
962
+ * @param json Oneof descriptor
963
+ * @returns Created oneof
964
+ * @throws {TypeError} If arguments are invalid
965
+ */
966
+ public static fromJSON(name: string, json: IOneOf): OneOf;
967
+
968
+ /**
969
+ * Converts this oneof to a oneof descriptor.
970
+ * @param [toJSONOptions] JSON conversion options
971
+ * @returns Oneof descriptor
972
+ */
973
+ public toJSON(toJSONOptions?: IToJSONOptions): IOneOf;
974
+
975
+ /**
976
+ * Adds a field to this oneof and removes it from its current parent, if any.
977
+ * @param field Field to add
978
+ * @returns `this`
979
+ */
980
+ public add(field: Field): OneOf;
981
+
982
+ /**
983
+ * Removes a field from this oneof and puts it back to the oneof's parent.
984
+ * @param field Field to remove
985
+ * @returns `this`
986
+ */
987
+ public remove(field: Field): OneOf;
988
+
989
+ /**
990
+ * OneOf decorator (TypeScript).
991
+ * @param fieldNames Field names
992
+ * @returns Decorator function
993
+ */
994
+ public static d<T extends string>(...fieldNames: string[]): OneOfDecorator;
995
+ }
996
+
997
+ /** Oneof descriptor. */
998
+ export interface IOneOf {
999
+
1000
+ /** Oneof field names */
1001
+ oneof: string[];
1002
+
1003
+ /** Oneof options */
1004
+ options?: { [k: string]: any };
1005
+ }
1006
+
1007
+ /**
1008
+ * Decorator function as returned by {@link OneOf.d} (TypeScript).
1009
+ * @param prototype Target prototype
1010
+ * @param oneofName OneOf name
1011
+ */
1012
+ type OneOfDecorator = (prototype: object, oneofName: string) => void;
1013
+
1014
+ /**
1015
+ * Parses the given .proto source and returns an object with the parsed contents.
1016
+ * @param source Source contents
1017
+ * @param [options] Parse options. Defaults to {@link parse.defaults} when omitted.
1018
+ * @returns Parser result
1019
+ */
1020
+ export function parse(source: string, options?: IParseOptions): IParserResult;
1021
+
1022
+ /** Result object returned from {@link parse}. */
1023
+ export interface IParserResult {
1024
+
1025
+ /** Package name, if declared */
1026
+ package: (string|undefined);
1027
+
1028
+ /** Imports, if any */
1029
+ imports: (string[]|undefined);
1030
+
1031
+ /** Weak imports, if any */
1032
+ weakImports: (string[]|undefined);
1033
+
1034
+ /** Syntax, if specified (either `"proto2"` or `"proto3"`) */
1035
+ syntax: (string|undefined);
1036
+
1037
+ /** Populated root instance */
1038
+ root: Root;
1039
+ }
1040
+
1041
+ /** Options modifying the behavior of {@link parse}. */
1042
+ export interface IParseOptions {
1043
+
1044
+ /** Keeps field casing instead of converting to camel case */
1045
+ keepCase?: boolean;
1046
+
1047
+ /** Recognize double-slash comments in addition to doc-block comments. */
1048
+ alternateCommentMode?: boolean;
1049
+ }
1050
+
1051
+ /** Options modifying the behavior of JSON serialization. */
1052
+ export interface IToJSONOptions {
1053
+
1054
+ /** Serializes comments. */
1055
+ keepComments?: boolean;
1056
+ }
1057
+
1058
+ /**
1059
+ * Parses the given .proto source and returns an object with the parsed contents.
1060
+ * @param source Source contents
1061
+ * @param root Root to populate
1062
+ * @param [options] Parse options. Defaults to {@link parse.defaults} when omitted.
1063
+ * @returns Parser result
1064
+ */
1065
+ export function parse(source: string, root: Root, options?: IParseOptions): IParserResult;
1066
+
1067
+ /** Wire format reader using `Uint8Array` if available, otherwise `Array`. */
1068
+ export class Reader {
1069
+
1070
+ /**
1071
+ * Constructs a new reader instance using the specified buffer.
1072
+ * @param buffer Buffer to read from
1073
+ */
1074
+ constructor(buffer: Uint8Array);
1075
+
1076
+ /** Read buffer. */
1077
+ public buf: Uint8Array;
1078
+
1079
+ /** Read buffer position. */
1080
+ public pos: number;
1081
+
1082
+ /** Read buffer length. */
1083
+ public len: number;
1084
+
1085
+ /**
1086
+ * Creates a new reader using the specified buffer.
1087
+ * @param buffer Buffer to read from
1088
+ * @returns A {@link BufferReader} if `buffer` is a Buffer, otherwise a {@link Reader}
1089
+ * @throws {Error} If `buffer` is not a valid buffer
1090
+ */
1091
+ public static create(buffer: (Uint8Array|Buffer)): (Reader|BufferReader);
1092
+
1093
+ /**
1094
+ * Reads a varint as an unsigned 32 bit value.
1095
+ * @returns Value read
1096
+ */
1097
+ public uint32(): number;
1098
+
1099
+ /**
1100
+ * Reads a varint as a signed 32 bit value.
1101
+ * @returns Value read
1102
+ */
1103
+ public int32(): number;
1104
+
1105
+ /**
1106
+ * Reads a zig-zag encoded varint as a signed 32 bit value.
1107
+ * @returns Value read
1108
+ */
1109
+ public sint32(): number;
1110
+
1111
+ /**
1112
+ * Reads a varint as a boolean.
1113
+ * @returns Value read
1114
+ */
1115
+ public bool(): boolean;
1116
+
1117
+ /**
1118
+ * Reads fixed 32 bits as an unsigned 32 bit integer.
1119
+ * @returns Value read
1120
+ */
1121
+ public fixed32(): number;
1122
+
1123
+ /**
1124
+ * Reads fixed 32 bits as a signed 32 bit integer.
1125
+ * @returns Value read
1126
+ */
1127
+ public sfixed32(): number;
1128
+
1129
+ /**
1130
+ * Reads a float (32 bit) as a number.
1131
+ * @returns Value read
1132
+ */
1133
+ public float(): number;
1134
+
1135
+ /**
1136
+ * Reads a double (64 bit float) as a number.
1137
+ * @returns Value read
1138
+ */
1139
+ public double(): number;
1140
+
1141
+ /**
1142
+ * Reads a sequence of bytes preceeded by its length as a varint.
1143
+ * @returns Value read
1144
+ */
1145
+ public bytes(): Uint8Array;
1146
+
1147
+ /**
1148
+ * Reads a string preceeded by its byte length as a varint.
1149
+ * @returns Value read
1150
+ */
1151
+ public string(): string;
1152
+
1153
+ /**
1154
+ * Skips the specified number of bytes if specified, otherwise skips a varint.
1155
+ * @param [length] Length if known, otherwise a varint is assumed
1156
+ * @returns `this`
1157
+ */
1158
+ public skip(length?: number): Reader;
1159
+
1160
+ /**
1161
+ * Skips the next element of the specified wire type.
1162
+ * @param wireType Wire type received
1163
+ * @returns `this`
1164
+ */
1165
+ public skipType(wireType: number): Reader;
1166
+ }
1167
+
1168
+ /** Wire format reader using node buffers. */
1169
+ export class BufferReader extends Reader {
1170
+
1171
+ /**
1172
+ * Constructs a new buffer reader instance.
1173
+ * @param buffer Buffer to read from
1174
+ */
1175
+ constructor(buffer: Buffer);
1176
+
1177
+ /**
1178
+ * Reads a sequence of bytes preceeded by its length as a varint.
1179
+ * @returns Value read
1180
+ */
1181
+ public bytes(): Buffer;
1182
+ }
1183
+
1184
+ /** Root namespace wrapping all types, enums, services, sub-namespaces etc. that belong together. */
1185
+ export class Root extends NamespaceBase {
1186
+
1187
+ /**
1188
+ * Constructs a new root namespace instance.
1189
+ * @param [options] Top level options
1190
+ */
1191
+ constructor(options?: { [k: string]: any });
1192
+
1193
+ /** Deferred extension fields. */
1194
+ public deferred: Field[];
1195
+
1196
+ /** Resolved file names of loaded files. */
1197
+ public files: string[];
1198
+
1199
+ /**
1200
+ * Loads a namespace descriptor into a root namespace.
1201
+ * @param json Nameespace descriptor
1202
+ * @param [root] Root namespace, defaults to create a new one if omitted
1203
+ * @returns Root namespace
1204
+ */
1205
+ public static fromJSON(json: INamespace, root?: Root): Root;
1206
+
1207
+ /**
1208
+ * Resolves the path of an imported file, relative to the importing origin.
1209
+ * This method exists so you can override it with your own logic in case your imports are scattered over multiple directories.
1210
+ * @param origin The file name of the importing file
1211
+ * @param target The file name being imported
1212
+ * @returns Resolved path to `target` or `null` to skip the file
1213
+ */
1214
+ public resolvePath(origin: string, target: string): (string|null);
1215
+
1216
+ /**
1217
+ * Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.
1218
+ * @param filename Names of one or multiple files to load
1219
+ * @param options Parse options
1220
+ * @param callback Callback function
1221
+ */
1222
+ public load(filename: (string|string[]), options: IParseOptions, callback: LoadCallback): void;
1223
+
1224
+ /**
1225
+ * Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.
1226
+ * @param filename Names of one or multiple files to load
1227
+ * @param callback Callback function
1228
+ */
1229
+ public load(filename: (string|string[]), callback: LoadCallback): void;
1230
+
1231
+ /**
1232
+ * Loads one or multiple .proto or preprocessed .json files into this root namespace and returns a promise.
1233
+ * @param filename Names of one or multiple files to load
1234
+ * @param [options] Parse options. Defaults to {@link parse.defaults} when omitted.
1235
+ * @returns Promise
1236
+ */
1237
+ public load(filename: (string|string[]), options?: IParseOptions): Promise<Root>;
1238
+
1239
+ /**
1240
+ * Synchronously loads one or multiple .proto or preprocessed .json files into this root namespace (node only).
1241
+ * @param filename Names of one or multiple files to load
1242
+ * @param [options] Parse options. Defaults to {@link parse.defaults} when omitted.
1243
+ * @returns Root namespace
1244
+ * @throws {Error} If synchronous fetching is not supported (i.e. in browsers) or if a file's syntax is invalid
1245
+ */
1246
+ public loadSync(filename: (string|string[]), options?: IParseOptions): Root;
1247
+ }
1248
+
1249
+ /**
1250
+ * Named roots.
1251
+ * This is where pbjs stores generated structures (the option `-r, --root` specifies a name).
1252
+ * Can also be used manually to make roots available accross modules.
1253
+ */
1254
+ export let roots: { [k: string]: Root };
1255
+
1256
+ /** Streaming RPC helpers. */
1257
+ export namespace rpc {
1258
+
1259
+ /**
1260
+ * A service method callback as used by {@link rpc.ServiceMethod|ServiceMethod}.
1261
+ *
1262
+ * Differs from {@link RPCImplCallback} in that it is an actual callback of a service method which may not return `response = null`.
1263
+ * @param error Error, if any
1264
+ * @param [response] Response message
1265
+ */
1266
+ type ServiceMethodCallback<TRes extends Message<TRes>> = (error: (Error|null), response?: TRes) => void;
1267
+
1268
+ /**
1269
+ * A service method part of a {@link rpc.Service} as created by {@link Service.create}.
1270
+ * @param request Request message or plain object
1271
+ * @param [callback] Node-style callback called with the error, if any, and the response message
1272
+ * @returns Promise if `callback` has been omitted, otherwise `undefined`
1273
+ */
1274
+ type ServiceMethod<TReq extends Message<TReq>, TRes extends Message<TRes>> = (request: (TReq|Properties<TReq>), callback?: rpc.ServiceMethodCallback<TRes>) => Promise<Message<TRes>>;
1275
+
1276
+ /** An RPC service as returned by {@link Service#create}. */
1277
+ class Service extends util.EventEmitter {
1278
+
1279
+ /**
1280
+ * Constructs a new RPC service instance.
1281
+ * @param rpcImpl RPC implementation
1282
+ * @param [requestDelimited=false] Whether requests are length-delimited
1283
+ * @param [responseDelimited=false] Whether responses are length-delimited
1284
+ */
1285
+ constructor(rpcImpl: RPCImpl, requestDelimited?: boolean, responseDelimited?: boolean);
1286
+
1287
+ /** RPC implementation. Becomes `null` once the service is ended. */
1288
+ public rpcImpl: (RPCImpl|null);
1289
+
1290
+ /** Whether requests are length-delimited. */
1291
+ public requestDelimited: boolean;
1292
+
1293
+ /** Whether responses are length-delimited. */
1294
+ public responseDelimited: boolean;
1295
+
1296
+ /**
1297
+ * Calls a service method through {@link rpc.Service#rpcImpl|rpcImpl}.
1298
+ * @param method Reflected or static method
1299
+ * @param requestCtor Request constructor
1300
+ * @param responseCtor Response constructor
1301
+ * @param request Request message or plain object
1302
+ * @param callback Service callback
1303
+ */
1304
+ public rpcCall<TReq extends Message<TReq>, TRes extends Message<TRes>>(method: (Method|rpc.ServiceMethod<TReq, TRes>), requestCtor: Constructor<TReq>, responseCtor: Constructor<TRes>, request: (TReq|Properties<TReq>), callback: rpc.ServiceMethodCallback<TRes>): void;
1305
+
1306
+ /**
1307
+ * Ends this service and emits the `end` event.
1308
+ * @param [endedByRPC=false] Whether the service has been ended by the RPC implementation.
1309
+ * @returns `this`
1310
+ */
1311
+ public end(endedByRPC?: boolean): rpc.Service;
1312
+ }
1313
+ }
1314
+
1315
+ /**
1316
+ * RPC implementation passed to {@link Service#create} performing a service request on network level, i.e. by utilizing http requests or websockets.
1317
+ * @param method Reflected or static method being called
1318
+ * @param requestData Request data
1319
+ * @param callback Callback function
1320
+ */
1321
+ type RPCImpl = (method: (Method|rpc.ServiceMethod<Message<{}>, Message<{}>>), requestData: Uint8Array, callback: RPCImplCallback) => void;
1322
+
1323
+ /**
1324
+ * Node-style callback as used by {@link RPCImpl}.
1325
+ * @param error Error, if any, otherwise `null`
1326
+ * @param [response] Response data or `null` to signal end of stream, if there hasn't been an error
1327
+ */
1328
+ type RPCImplCallback = (error: (Error|null), response?: (Uint8Array|null)) => void;
1329
+
1330
+ /** Reflected service. */
1331
+ export class Service extends NamespaceBase {
1332
+
1333
+ /**
1334
+ * Constructs a new service instance.
1335
+ * @param name Service name
1336
+ * @param [options] Service options
1337
+ * @throws {TypeError} If arguments are invalid
1338
+ */
1339
+ constructor(name: string, options?: { [k: string]: any });
1340
+
1341
+ /** Service methods. */
1342
+ public methods: { [k: string]: Method };
1343
+
1344
+ /**
1345
+ * Constructs a service from a service descriptor.
1346
+ * @param name Service name
1347
+ * @param json Service descriptor
1348
+ * @returns Created service
1349
+ * @throws {TypeError} If arguments are invalid
1350
+ */
1351
+ public static fromJSON(name: string, json: IService): Service;
1352
+
1353
+ /**
1354
+ * Converts this service to a service descriptor.
1355
+ * @param [toJSONOptions] JSON conversion options
1356
+ * @returns Service descriptor
1357
+ */
1358
+ public toJSON(toJSONOptions?: IToJSONOptions): IService;
1359
+
1360
+ /** Methods of this service as an array for iteration. */
1361
+ public readonly methodsArray: Method[];
1362
+
1363
+ /**
1364
+ * Creates a runtime service using the specified rpc implementation.
1365
+ * @param rpcImpl RPC implementation
1366
+ * @param [requestDelimited=false] Whether requests are length-delimited
1367
+ * @param [responseDelimited=false] Whether responses are length-delimited
1368
+ * @returns RPC service. Useful where requests and/or responses are streamed.
1369
+ */
1370
+ public create(rpcImpl: RPCImpl, requestDelimited?: boolean, responseDelimited?: boolean): rpc.Service;
1371
+ }
1372
+
1373
+ /** Service descriptor. */
1374
+ export interface IService extends INamespace {
1375
+
1376
+ /** Method descriptors */
1377
+ methods: { [k: string]: IMethod };
1378
+ }
1379
+
1380
+ /**
1381
+ * Gets the next token and advances.
1382
+ * @returns Next token or `null` on eof
1383
+ */
1384
+ type TokenizerHandleNext = () => (string|null);
1385
+
1386
+ /**
1387
+ * Peeks for the next token.
1388
+ * @returns Next token or `null` on eof
1389
+ */
1390
+ type TokenizerHandlePeek = () => (string|null);
1391
+
1392
+ /**
1393
+ * Pushes a token back to the stack.
1394
+ * @param token Token
1395
+ */
1396
+ type TokenizerHandlePush = (token: string) => void;
1397
+
1398
+ /**
1399
+ * Skips the next token.
1400
+ * @param expected Expected token
1401
+ * @param [optional=false] If optional
1402
+ * @returns Whether the token matched
1403
+ * @throws {Error} If the token didn't match and is not optional
1404
+ */
1405
+ type TokenizerHandleSkip = (expected: string, optional?: boolean) => boolean;
1406
+
1407
+ /**
1408
+ * Gets the comment on the previous line or, alternatively, the line comment on the specified line.
1409
+ * @param [line] Line number
1410
+ * @returns Comment text or `null` if none
1411
+ */
1412
+ type TokenizerHandleCmnt = (line?: number) => (string|null);
1413
+
1414
+ /** Handle object returned from {@link tokenize}. */
1415
+ export interface ITokenizerHandle {
1416
+
1417
+ /** Gets the next token and advances (`null` on eof) */
1418
+ next: TokenizerHandleNext;
1419
+
1420
+ /** Peeks for the next token (`null` on eof) */
1421
+ peek: TokenizerHandlePeek;
1422
+
1423
+ /** Pushes a token back to the stack */
1424
+ push: TokenizerHandlePush;
1425
+
1426
+ /** Skips a token, returns its presence and advances or, if non-optional and not present, throws */
1427
+ skip: TokenizerHandleSkip;
1428
+
1429
+ /** Gets the comment on the previous line or the line comment on the specified line, if any */
1430
+ cmnt: TokenizerHandleCmnt;
1431
+
1432
+ /** Current line number */
1433
+ line: number;
1434
+ }
1435
+
1436
+ /**
1437
+ * Tokenizes the given .proto source and returns an object with useful utility functions.
1438
+ * @param source Source contents
1439
+ * @param alternateCommentMode Whether we should activate alternate comment parsing mode.
1440
+ * @returns Tokenizer handle
1441
+ */
1442
+ export function tokenize(source: string, alternateCommentMode: boolean): ITokenizerHandle;
1443
+
1444
+ export namespace tokenize {
1445
+
1446
+ /**
1447
+ * Unescapes a string.
1448
+ * @param str String to unescape
1449
+ * @returns Unescaped string
1450
+ */
1451
+ function unescape(str: string): string;
1452
+ }
1453
+
1454
+ /** Reflected message type. */
1455
+ export class Type extends NamespaceBase {
1456
+
1457
+ /**
1458
+ * Constructs a new reflected message type instance.
1459
+ * @param name Message name
1460
+ * @param [options] Declared options
1461
+ */
1462
+ constructor(name: string, options?: { [k: string]: any });
1463
+
1464
+ /** Message fields. */
1465
+ public fields: { [k: string]: Field };
1466
+
1467
+ /** Oneofs declared within this namespace, if any. */
1468
+ public oneofs: { [k: string]: OneOf };
1469
+
1470
+ /** Extension ranges, if any. */
1471
+ public extensions: number[][];
1472
+
1473
+ /** Reserved ranges, if any. */
1474
+ public reserved: (number[]|string)[];
1475
+
1476
+ /** Message fields by id. */
1477
+ public readonly fieldsById: { [k: number]: Field };
1478
+
1479
+ /** Fields of this message as an array for iteration. */
1480
+ public readonly fieldsArray: Field[];
1481
+
1482
+ /** Oneofs of this message as an array for iteration. */
1483
+ public readonly oneofsArray: OneOf[];
1484
+
1485
+ /**
1486
+ * The registered constructor, if any registered, otherwise a generic constructor.
1487
+ * Assigning a function replaces the internal constructor. If the function does not extend {@link Message} yet, its prototype will be setup accordingly and static methods will be populated. If it already extends {@link Message}, it will just replace the internal constructor.
1488
+ */
1489
+ public ctor: Constructor<{}>;
1490
+
1491
+ /**
1492
+ * Generates a constructor function for the specified type.
1493
+ * @param mtype Message type
1494
+ * @returns Codegen instance
1495
+ */
1496
+ public static generateConstructor(mtype: Type): Codegen;
1497
+
1498
+ /**
1499
+ * Creates a message type from a message type descriptor.
1500
+ * @param name Message name
1501
+ * @param json Message type descriptor
1502
+ * @returns Created message type
1503
+ */
1504
+ public static fromJSON(name: string, json: IType): Type;
1505
+
1506
+ /**
1507
+ * Converts this message type to a message type descriptor.
1508
+ * @param [toJSONOptions] JSON conversion options
1509
+ * @returns Message type descriptor
1510
+ */
1511
+ public toJSON(toJSONOptions?: IToJSONOptions): IType;
1512
+
1513
+ /**
1514
+ * Adds a nested object to this type.
1515
+ * @param object Nested object to add
1516
+ * @returns `this`
1517
+ * @throws {TypeError} If arguments are invalid
1518
+ * @throws {Error} If there is already a nested object with this name or, if a field, when there is already a field with this id
1519
+ */
1520
+ public add(object: ReflectionObject): Type;
1521
+
1522
+ /**
1523
+ * Removes a nested object from this type.
1524
+ * @param object Nested object to remove
1525
+ * @returns `this`
1526
+ * @throws {TypeError} If arguments are invalid
1527
+ * @throws {Error} If `object` is not a member of this type
1528
+ */
1529
+ public remove(object: ReflectionObject): Type;
1530
+
1531
+ /**
1532
+ * Tests if the specified id is reserved.
1533
+ * @param id Id to test
1534
+ * @returns `true` if reserved, otherwise `false`
1535
+ */
1536
+ public isReservedId(id: number): boolean;
1537
+
1538
+ /**
1539
+ * Tests if the specified name is reserved.
1540
+ * @param name Name to test
1541
+ * @returns `true` if reserved, otherwise `false`
1542
+ */
1543
+ public isReservedName(name: string): boolean;
1544
+
1545
+ /**
1546
+ * Creates a new message of this type using the specified properties.
1547
+ * @param [properties] Properties to set
1548
+ * @returns Message instance
1549
+ */
1550
+ public create(properties?: { [k: string]: any }): Message<{}>;
1551
+
1552
+ /**
1553
+ * Sets up {@link Type#encode|encode}, {@link Type#decode|decode} and {@link Type#verify|verify}.
1554
+ * @returns `this`
1555
+ */
1556
+ public setup(): Type;
1557
+
1558
+ /**
1559
+ * Encodes a message of this type. Does not implicitly {@link Type#verify|verify} messages.
1560
+ * @param message Message instance or plain object
1561
+ * @param [writer] Writer to encode to
1562
+ * @returns writer
1563
+ */
1564
+ public encode(message: (Message<{}>|{ [k: string]: any }), writer?: Writer): Writer;
1565
+
1566
+ /**
1567
+ * Encodes a message of this type preceeded by its byte length as a varint. Does not implicitly {@link Type#verify|verify} messages.
1568
+ * @param message Message instance or plain object
1569
+ * @param [writer] Writer to encode to
1570
+ * @returns writer
1571
+ */
1572
+ public encodeDelimited(message: (Message<{}>|{ [k: string]: any }), writer?: Writer): Writer;
1573
+
1574
+ /**
1575
+ * Decodes a message of this type.
1576
+ * @param reader Reader or buffer to decode from
1577
+ * @param [length] Length of the message, if known beforehand
1578
+ * @returns Decoded message
1579
+ * @throws {Error} If the payload is not a reader or valid buffer
1580
+ * @throws {util.ProtocolError<{}>} If required fields are missing
1581
+ */
1582
+ public decode(reader: (Reader|Uint8Array), length?: number): Message<{}>;
1583
+
1584
+ /**
1585
+ * Decodes a message of this type preceeded by its byte length as a varint.
1586
+ * @param reader Reader or buffer to decode from
1587
+ * @returns Decoded message
1588
+ * @throws {Error} If the payload is not a reader or valid buffer
1589
+ * @throws {util.ProtocolError} If required fields are missing
1590
+ */
1591
+ public decodeDelimited(reader: (Reader|Uint8Array)): Message<{}>;
1592
+
1593
+ /**
1594
+ * Verifies that field values are valid and that required fields are present.
1595
+ * @param message Plain object to verify
1596
+ * @returns `null` if valid, otherwise the reason why it is not
1597
+ */
1598
+ public verify(message: { [k: string]: any }): (null|string);
1599
+
1600
+ /**
1601
+ * Creates a new message of this type from a plain object. Also converts values to their respective internal types.
1602
+ * @param object Plain object to convert
1603
+ * @returns Message instance
1604
+ */
1605
+ public fromObject(object: { [k: string]: any }): Message<{}>;
1606
+
1607
+ /**
1608
+ * Creates a plain object from a message of this type. Also converts values to other types if specified.
1609
+ * @param message Message instance
1610
+ * @param [options] Conversion options
1611
+ * @returns Plain object
1612
+ */
1613
+ public toObject(message: Message<{}>, options?: IConversionOptions): { [k: string]: any };
1614
+
1615
+ /**
1616
+ * Type decorator (TypeScript).
1617
+ * @param [typeName] Type name, defaults to the constructor's name
1618
+ * @returns Decorator function
1619
+ */
1620
+ public static d<T extends Message<T>>(typeName?: string): TypeDecorator<T>;
1621
+ }
1622
+
1623
+ /** Message type descriptor. */
1624
+ export interface IType extends INamespace {
1625
+
1626
+ /** Oneof descriptors */
1627
+ oneofs?: { [k: string]: IOneOf };
1628
+
1629
+ /** Field descriptors */
1630
+ fields: { [k: string]: IField };
1631
+
1632
+ /** Extension ranges */
1633
+ extensions?: number[][];
1634
+
1635
+ /** Reserved ranges */
1636
+ reserved?: number[][];
1637
+
1638
+ /** Whether a legacy group or not */
1639
+ group?: boolean;
1640
+ }
1641
+
1642
+ /** Conversion options as used by {@link Type#toObject} and {@link Message.toObject}. */
1643
+ export interface IConversionOptions {
1644
+
1645
+ /**
1646
+ * Long conversion type.
1647
+ * Valid values are `String` and `Number` (the global types).
1648
+ * Defaults to copy the present value, which is a possibly unsafe number without and a {@link Long} with a long library.
1649
+ */
1650
+ longs?: Function;
1651
+
1652
+ /**
1653
+ * Enum value conversion type.
1654
+ * Only valid value is `String` (the global type).
1655
+ * Defaults to copy the present value, which is the numeric id.
1656
+ */
1657
+ enums?: Function;
1658
+
1659
+ /**
1660
+ * Bytes value conversion type.
1661
+ * Valid values are `Array` and (a base64 encoded) `String` (the global types).
1662
+ * Defaults to copy the present value, which usually is a Buffer under node and an Uint8Array in the browser.
1663
+ */
1664
+ bytes?: Function;
1665
+
1666
+ /** Also sets default values on the resulting object */
1667
+ defaults?: boolean;
1668
+
1669
+ /** Sets empty arrays for missing repeated fields even if `defaults=false` */
1670
+ arrays?: boolean;
1671
+
1672
+ /** Sets empty objects for missing map fields even if `defaults=false` */
1673
+ objects?: boolean;
1674
+
1675
+ /** Includes virtual oneof properties set to the present field's name, if any */
1676
+ oneofs?: boolean;
1677
+
1678
+ /** Performs additional JSON compatibility conversions, i.e. NaN and Infinity to strings */
1679
+ json?: boolean;
1680
+ }
1681
+
1682
+ /**
1683
+ * Decorator function as returned by {@link Type.d} (TypeScript).
1684
+ * @param target Target constructor
1685
+ */
1686
+ type TypeDecorator<T extends Message<T>> = (target: Constructor<T>) => void;
1687
+
1688
+ /** Common type constants. */
1689
+ export namespace types {
1690
+
1691
+ /** Basic type wire types. */
1692
+ const basic: {
1693
+ "double": number,
1694
+ "float": number,
1695
+ "int32": number,
1696
+ "uint32": number,
1697
+ "sint32": number,
1698
+ "fixed32": number,
1699
+ "sfixed32": number,
1700
+ "int64": number,
1701
+ "uint64": number,
1702
+ "sint64": number,
1703
+ "fixed64": number,
1704
+ "sfixed64": number,
1705
+ "bool": number,
1706
+ "string": number,
1707
+ "bytes": number
1708
+ };
1709
+
1710
+ /** Basic type defaults. */
1711
+ const defaults: {
1712
+ "double": number,
1713
+ "float": number,
1714
+ "int32": number,
1715
+ "uint32": number,
1716
+ "sint32": number,
1717
+ "fixed32": number,
1718
+ "sfixed32": number,
1719
+ "int64": number,
1720
+ "uint64": number,
1721
+ "sint64": number,
1722
+ "fixed64": number,
1723
+ "sfixed64": number,
1724
+ "bool": boolean,
1725
+ "string": string,
1726
+ "bytes": number[],
1727
+ "message": null
1728
+ };
1729
+
1730
+ /** Basic long type wire types. */
1731
+ const long: {
1732
+ "int64": number,
1733
+ "uint64": number,
1734
+ "sint64": number,
1735
+ "fixed64": number,
1736
+ "sfixed64": number
1737
+ };
1738
+
1739
+ /** Allowed types for map keys with their associated wire type. */
1740
+ const mapKey: {
1741
+ "int32": number,
1742
+ "uint32": number,
1743
+ "sint32": number,
1744
+ "fixed32": number,
1745
+ "sfixed32": number,
1746
+ "int64": number,
1747
+ "uint64": number,
1748
+ "sint64": number,
1749
+ "fixed64": number,
1750
+ "sfixed64": number,
1751
+ "bool": number,
1752
+ "string": number
1753
+ };
1754
+
1755
+ /** Allowed types for packed repeated fields with their associated wire type. */
1756
+ const packed: {
1757
+ "double": number,
1758
+ "float": number,
1759
+ "int32": number,
1760
+ "uint32": number,
1761
+ "sint32": number,
1762
+ "fixed32": number,
1763
+ "sfixed32": number,
1764
+ "int64": number,
1765
+ "uint64": number,
1766
+ "sint64": number,
1767
+ "fixed64": number,
1768
+ "sfixed64": number,
1769
+ "bool": number
1770
+ };
1771
+ }
1772
+
1773
+ /** Constructor type. */
1774
+ export interface Constructor<T> extends Function {
1775
+ new(...params: any[]): T; prototype: T;
1776
+ }
1777
+
1778
+ /** Properties type. */
1779
+ type Properties<T> = { [P in keyof T]?: T[P] };
1780
+
1781
+ /** Type that is convertible to array. */
1782
+ export interface ToArray<T> {
1783
+ toArray(): T[];
1784
+ }
1785
+
1786
+ /**
1787
+ * Any compatible Buffer instance.
1788
+ * This is a minimal stand-alone definition of a Buffer instance. The actual type is that exported by node's typings.
1789
+ */
1790
+ export interface Buffer extends Uint8Array {
1791
+ }
1792
+
1793
+ /**
1794
+ * A OneOf getter as returned by {@link util.oneOfGetter}.
1795
+ * @returns Set field name, if any
1796
+ */
1797
+ type OneOfGetter = () => (string|undefined);
1798
+
1799
+ /**
1800
+ * A OneOf setter as returned by {@link util.oneOfSetter}.
1801
+ * @param value Field name
1802
+ */
1803
+ type OneOfSetter = (value: (string|undefined)) => void;
1804
+
1805
+ /** Various utility functions. */
1806
+ export namespace util {
1807
+
1808
+ /** Helper class for working with the low and high bits of a 64 bit value. */
1809
+ class LongBits {
1810
+
1811
+ /**
1812
+ * Constructs new long bits.
1813
+ * @param lo Low 32 bits, unsigned
1814
+ * @param hi High 32 bits, unsigned
1815
+ */
1816
+ constructor(lo: number, hi: number);
1817
+
1818
+ /** Low bits. */
1819
+ public lo: number;
1820
+
1821
+ /** High bits. */
1822
+ public hi: number;
1823
+
1824
+ /** Zero bits. */
1825
+ public static zero: util.LongBits;
1826
+
1827
+ /** Zero hash. */
1828
+ public static zeroHash: string;
1829
+
1830
+ /**
1831
+ * Constructs new long bits from the specified number.
1832
+ * @param value Value
1833
+ * @returns Instance
1834
+ */
1835
+ public static fromNumber(value: number): util.LongBits;
1836
+
1837
+ /**
1838
+ * Constructs new long bits from a number, long or string.
1839
+ * @param value Value
1840
+ * @returns Instance
1841
+ */
1842
+ public static from(value: (number|string)): util.LongBits;
1843
+
1844
+ /**
1845
+ * Converts this long bits to a possibly unsafe JavaScript number.
1846
+ * @param [unsigned=false] Whether unsigned or not
1847
+ * @returns Possibly unsafe number
1848
+ */
1849
+ public toNumber(unsigned?: boolean): number;
1850
+
1851
+ /**
1852
+ * Constructs new long bits from the specified 8 characters long hash.
1853
+ * @param hash Hash
1854
+ * @returns Bits
1855
+ */
1856
+ public static fromHash(hash: string): util.LongBits;
1857
+
1858
+ /**
1859
+ * Converts this long bits to a 8 characters long hash.
1860
+ * @returns Hash
1861
+ */
1862
+ public toHash(): string;
1863
+
1864
+ /**
1865
+ * Zig-zag encodes this long bits.
1866
+ * @returns `this`
1867
+ */
1868
+ public zzEncode(): util.LongBits;
1869
+
1870
+ /**
1871
+ * Zig-zag decodes this long bits.
1872
+ * @returns `this`
1873
+ */
1874
+ public zzDecode(): util.LongBits;
1875
+
1876
+ /**
1877
+ * Calculates the length of this longbits when encoded as a varint.
1878
+ * @returns Length
1879
+ */
1880
+ public length(): number;
1881
+ }
1882
+
1883
+ /** An immuable empty array. */
1884
+ const emptyArray: any[];
1885
+
1886
+ /** An immutable empty object. */
1887
+ const emptyObject: object;
1888
+
1889
+ /** Whether running within node or not. */
1890
+ const isNode: boolean;
1891
+
1892
+ /**
1893
+ * Tests if the specified value is an integer.
1894
+ * @param value Value to test
1895
+ * @returns `true` if the value is an integer
1896
+ */
1897
+ function isInteger(value: any): boolean;
1898
+
1899
+ /**
1900
+ * Tests if the specified value is a string.
1901
+ * @param value Value to test
1902
+ * @returns `true` if the value is a string
1903
+ */
1904
+ function isString(value: any): boolean;
1905
+
1906
+ /**
1907
+ * Tests if the specified value is a non-null object.
1908
+ * @param value Value to test
1909
+ * @returns `true` if the value is a non-null object
1910
+ */
1911
+ function isObject(value: any): boolean;
1912
+
1913
+ /**
1914
+ * Checks if a property on a message is considered to be present.
1915
+ * This is an alias of {@link util.isSet}.
1916
+ * @param obj Plain object or message instance
1917
+ * @param prop Property name
1918
+ * @returns `true` if considered to be present, otherwise `false`
1919
+ */
1920
+ function isset(obj: object, prop: string): boolean;
1921
+
1922
+ /**
1923
+ * Checks if a property on a message is considered to be present.
1924
+ * @param obj Plain object or message instance
1925
+ * @param prop Property name
1926
+ * @returns `true` if considered to be present, otherwise `false`
1927
+ */
1928
+ function isSet(obj: object, prop: string): boolean;
1929
+
1930
+ /** Node's Buffer class if available. */
1931
+ let Buffer: Constructor<Buffer>;
1932
+
1933
+ /**
1934
+ * Creates a new buffer of whatever type supported by the environment.
1935
+ * @param [sizeOrArray=0] Buffer size or number array
1936
+ * @returns Buffer
1937
+ */
1938
+ function newBuffer(sizeOrArray?: (number|number[])): (Uint8Array|Buffer);
1939
+
1940
+ /** Array implementation used in the browser. `Uint8Array` if supported, otherwise `Array`. */
1941
+ let Array: Constructor<Uint8Array>;
1942
+
1943
+ /** Regular expression used to verify 2 bit (`bool`) map keys. */
1944
+ const key2Re: RegExp;
1945
+
1946
+ /** Regular expression used to verify 32 bit (`int32` etc.) map keys. */
1947
+ const key32Re: RegExp;
1948
+
1949
+ /** Regular expression used to verify 64 bit (`int64` etc.) map keys. */
1950
+ const key64Re: RegExp;
1951
+
1952
+ /**
1953
+ * Merges the properties of the source object into the destination object.
1954
+ * @param dst Destination object
1955
+ * @param src Source object
1956
+ * @param [ifNotSet=false] Merges only if the key is not already set
1957
+ * @returns Destination object
1958
+ */
1959
+ function merge(dst: { [k: string]: any }, src: { [k: string]: any }, ifNotSet?: boolean): { [k: string]: any };
1960
+
1961
+ /**
1962
+ * Converts the first character of a string to lower case.
1963
+ * @param str String to convert
1964
+ * @returns Converted string
1965
+ */
1966
+ function lcFirst(str: string): string;
1967
+
1968
+ /**
1969
+ * Creates a custom error constructor.
1970
+ * @param name Error name
1971
+ * @returns Custom error constructor
1972
+ */
1973
+ function newError(name: string): Constructor<Error>;
1974
+
1975
+ /** Error subclass indicating a protocol specifc error. */
1976
+ class ProtocolError<T extends Message<T>> extends Error {
1977
+
1978
+ /**
1979
+ * Constructs a new protocol error.
1980
+ * @param message Error message
1981
+ * @param [properties] Additional properties
1982
+ */
1983
+ constructor(message: string, properties?: { [k: string]: any });
1984
+
1985
+ /** So far decoded message instance. */
1986
+ public instance: Message<T>;
1987
+ }
1988
+
1989
+ /**
1990
+ * Builds a getter for a oneof's present field name.
1991
+ * @param fieldNames Field names
1992
+ * @returns Unbound getter
1993
+ */
1994
+ function oneOfGetter(fieldNames: string[]): OneOfGetter;
1995
+
1996
+ /**
1997
+ * Builds a setter for a oneof's present field name.
1998
+ * @param fieldNames Field names
1999
+ * @returns Unbound setter
2000
+ */
2001
+ function oneOfSetter(fieldNames: string[]): OneOfSetter;
2002
+
2003
+ /**
2004
+ * Default conversion options used for {@link Message#toJSON} implementations.
2005
+ *
2006
+ * These options are close to proto3's JSON mapping with the exception that internal types like Any are handled just like messages. More precisely:
2007
+ *
2008
+ * - Longs become strings
2009
+ * - Enums become string keys
2010
+ * - Bytes become base64 encoded strings
2011
+ * - (Sub-)Messages become plain objects
2012
+ * - Maps become plain objects with all string keys
2013
+ * - Repeated fields become arrays
2014
+ * - NaN and Infinity for float and double fields become strings
2015
+ *
2016
+ * @see https://developers.google.com/protocol-buffers/docs/proto3?hl=en#json
2017
+ */
2018
+ let toJSONOptions: IConversionOptions;
2019
+
2020
+ /** Node's fs module if available. */
2021
+ let fs: { [k: string]: any };
2022
+
2023
+ /**
2024
+ * Converts an object's values to an array.
2025
+ * @param object Object to convert
2026
+ * @returns Converted array
2027
+ */
2028
+ function toArray(object: { [k: string]: any }): any[];
2029
+
2030
+ /**
2031
+ * Converts an array of keys immediately followed by their respective value to an object, omitting undefined values.
2032
+ * @param array Array to convert
2033
+ * @returns Converted object
2034
+ */
2035
+ function toObject(array: any[]): { [k: string]: any };
2036
+
2037
+ /**
2038
+ * Tests whether the specified name is a reserved word in JS.
2039
+ * @param name Name to test
2040
+ * @returns `true` if reserved, otherwise `false`
2041
+ */
2042
+ function isReserved(name: string): boolean;
2043
+
2044
+ /**
2045
+ * Returns a safe property accessor for the specified property name.
2046
+ * @param prop Property name
2047
+ * @returns Safe accessor
2048
+ */
2049
+ function safeProp(prop: string): string;
2050
+
2051
+ /**
2052
+ * Converts the first character of a string to upper case.
2053
+ * @param str String to convert
2054
+ * @returns Converted string
2055
+ */
2056
+ function ucFirst(str: string): string;
2057
+
2058
+ /**
2059
+ * Converts a string to camel case.
2060
+ * @param str String to convert
2061
+ * @returns Converted string
2062
+ */
2063
+ function camelCase(str: string): string;
2064
+
2065
+ /**
2066
+ * Compares reflected fields by id.
2067
+ * @param a First field
2068
+ * @param b Second field
2069
+ * @returns Comparison value
2070
+ */
2071
+ function compareFieldsById(a: Field, b: Field): number;
2072
+
2073
+ /**
2074
+ * Decorator helper for types (TypeScript).
2075
+ * @param ctor Constructor function
2076
+ * @param [typeName] Type name, defaults to the constructor's name
2077
+ * @returns Reflected type
2078
+ */
2079
+ function decorateType<T extends Message<T>>(ctor: Constructor<T>, typeName?: string): Type;
2080
+
2081
+ /**
2082
+ * Decorator helper for enums (TypeScript).
2083
+ * @param object Enum object
2084
+ * @returns Reflected enum
2085
+ */
2086
+ function decorateEnum(object: object): Enum;
2087
+
2088
+ /** Decorator root (TypeScript). */
2089
+ let decorateRoot: Root;
2090
+
2091
+ /**
2092
+ * Returns a promise from a node-style callback function.
2093
+ * @param fn Function to call
2094
+ * @param ctx Function context
2095
+ * @param params Function arguments
2096
+ * @returns Promisified function
2097
+ */
2098
+ function asPromise(fn: asPromiseCallback, ctx: any, ...params: any[]): Promise<any>;
2099
+
2100
+ /** A minimal base64 implementation for number arrays. */
2101
+ namespace base64 {
2102
+
2103
+ /**
2104
+ * Calculates the byte length of a base64 encoded string.
2105
+ * @param string Base64 encoded string
2106
+ * @returns Byte length
2107
+ */
2108
+ function length(string: string): number;
2109
+
2110
+ /**
2111
+ * Encodes a buffer to a base64 encoded string.
2112
+ * @param buffer Source buffer
2113
+ * @param start Source start
2114
+ * @param end Source end
2115
+ * @returns Base64 encoded string
2116
+ */
2117
+ function encode(buffer: Uint8Array, start: number, end: number): string;
2118
+
2119
+ /**
2120
+ * Decodes a base64 encoded string to a buffer.
2121
+ * @param string Source string
2122
+ * @param buffer Destination buffer
2123
+ * @param offset Destination offset
2124
+ * @returns Number of bytes written
2125
+ * @throws {Error} If encoding is invalid
2126
+ */
2127
+ function decode(string: string, buffer: Uint8Array, offset: number): number;
2128
+
2129
+ /**
2130
+ * Tests if the specified string appears to be base64 encoded.
2131
+ * @param string String to test
2132
+ * @returns `true` if probably base64 encoded, otherwise false
2133
+ */
2134
+ function test(string: string): boolean;
2135
+ }
2136
+
2137
+ /**
2138
+ * Begins generating a function.
2139
+ * @param functionParams Function parameter names
2140
+ * @param [functionName] Function name if not anonymous
2141
+ * @returns Appender that appends code to the function's body
2142
+ */
2143
+ function codegen(functionParams: string[], functionName?: string): Codegen;
2144
+
2145
+ namespace codegen {
2146
+
2147
+ /** When set to `true`, codegen will log generated code to console. Useful for debugging. */
2148
+ let verbose: boolean;
2149
+ }
2150
+
2151
+ /**
2152
+ * Begins generating a function.
2153
+ * @param [functionName] Function name if not anonymous
2154
+ * @returns Appender that appends code to the function's body
2155
+ */
2156
+ function codegen(functionName?: string): Codegen;
2157
+
2158
+ /** A minimal event emitter. */
2159
+ class EventEmitter {
2160
+
2161
+ /** Constructs a new event emitter instance. */
2162
+ constructor();
2163
+
2164
+ /**
2165
+ * Registers an event listener.
2166
+ * @param evt Event name
2167
+ * @param fn Listener
2168
+ * @param [ctx] Listener context
2169
+ * @returns `this`
2170
+ */
2171
+ public on(evt: string, fn: EventEmitterListener, ctx?: any): this;
2172
+
2173
+ /**
2174
+ * Removes an event listener or any matching listeners if arguments are omitted.
2175
+ * @param [evt] Event name. Removes all listeners if omitted.
2176
+ * @param [fn] Listener to remove. Removes all listeners of `evt` if omitted.
2177
+ * @returns `this`
2178
+ */
2179
+ public off(evt?: string, fn?: EventEmitterListener): this;
2180
+
2181
+ /**
2182
+ * Emits an event by calling its listeners with the specified arguments.
2183
+ * @param evt Event name
2184
+ * @param args Arguments
2185
+ * @returns `this`
2186
+ */
2187
+ public emit(evt: string, ...args: any[]): this;
2188
+ }
2189
+
2190
+ /** Reads / writes floats / doubles from / to buffers. */
2191
+ namespace float {
2192
+
2193
+ /**
2194
+ * Writes a 32 bit float to a buffer using little endian byte order.
2195
+ * @param val Value to write
2196
+ * @param buf Target buffer
2197
+ * @param pos Target buffer offset
2198
+ */
2199
+ function writeFloatLE(val: number, buf: Uint8Array, pos: number): void;
2200
+
2201
+ /**
2202
+ * Writes a 32 bit float to a buffer using big endian byte order.
2203
+ * @param val Value to write
2204
+ * @param buf Target buffer
2205
+ * @param pos Target buffer offset
2206
+ */
2207
+ function writeFloatBE(val: number, buf: Uint8Array, pos: number): void;
2208
+
2209
+ /**
2210
+ * Reads a 32 bit float from a buffer using little endian byte order.
2211
+ * @param buf Source buffer
2212
+ * @param pos Source buffer offset
2213
+ * @returns Value read
2214
+ */
2215
+ function readFloatLE(buf: Uint8Array, pos: number): number;
2216
+
2217
+ /**
2218
+ * Reads a 32 bit float from a buffer using big endian byte order.
2219
+ * @param buf Source buffer
2220
+ * @param pos Source buffer offset
2221
+ * @returns Value read
2222
+ */
2223
+ function readFloatBE(buf: Uint8Array, pos: number): number;
2224
+
2225
+ /**
2226
+ * Writes a 64 bit double to a buffer using little endian byte order.
2227
+ * @param val Value to write
2228
+ * @param buf Target buffer
2229
+ * @param pos Target buffer offset
2230
+ */
2231
+ function writeDoubleLE(val: number, buf: Uint8Array, pos: number): void;
2232
+
2233
+ /**
2234
+ * Writes a 64 bit double to a buffer using big endian byte order.
2235
+ * @param val Value to write
2236
+ * @param buf Target buffer
2237
+ * @param pos Target buffer offset
2238
+ */
2239
+ function writeDoubleBE(val: number, buf: Uint8Array, pos: number): void;
2240
+
2241
+ /**
2242
+ * Reads a 64 bit double from a buffer using little endian byte order.
2243
+ * @param buf Source buffer
2244
+ * @param pos Source buffer offset
2245
+ * @returns Value read
2246
+ */
2247
+ function readDoubleLE(buf: Uint8Array, pos: number): number;
2248
+
2249
+ /**
2250
+ * Reads a 64 bit double from a buffer using big endian byte order.
2251
+ * @param buf Source buffer
2252
+ * @param pos Source buffer offset
2253
+ * @returns Value read
2254
+ */
2255
+ function readDoubleBE(buf: Uint8Array, pos: number): number;
2256
+ }
2257
+
2258
+ /**
2259
+ * Fetches the contents of a file.
2260
+ * @param filename File path or url
2261
+ * @param options Fetch options
2262
+ * @param callback Callback function
2263
+ */
2264
+ function fetch(filename: string, options: IFetchOptions, callback: FetchCallback): void;
2265
+
2266
+ /**
2267
+ * Fetches the contents of a file.
2268
+ * @param path File path or url
2269
+ * @param callback Callback function
2270
+ */
2271
+ function fetch(path: string, callback: FetchCallback): void;
2272
+
2273
+ /**
2274
+ * Fetches the contents of a file.
2275
+ * @param path File path or url
2276
+ * @param [options] Fetch options
2277
+ * @returns Promise
2278
+ */
2279
+ function fetch(path: string, options?: IFetchOptions): Promise<(string|Uint8Array)>;
2280
+
2281
+ /**
2282
+ * Requires a module only if available.
2283
+ * @param moduleName Module to require
2284
+ * @returns Required module if available and not empty, otherwise `null`
2285
+ */
2286
+ function inquire(moduleName: string): object;
2287
+
2288
+ /** A minimal path module to resolve Unix, Windows and URL paths alike. */
2289
+ namespace path {
2290
+
2291
+ /**
2292
+ * Tests if the specified path is absolute.
2293
+ * @param path Path to test
2294
+ * @returns `true` if path is absolute
2295
+ */
2296
+ function isAbsolute(path: string): boolean;
2297
+
2298
+ /**
2299
+ * Normalizes the specified path.
2300
+ * @param path Path to normalize
2301
+ * @returns Normalized path
2302
+ */
2303
+ function normalize(path: string): string;
2304
+
2305
+ /**
2306
+ * Resolves the specified include path against the specified origin path.
2307
+ * @param originPath Path to the origin file
2308
+ * @param includePath Include path relative to origin path
2309
+ * @param [alreadyNormalized=false] `true` if both paths are already known to be normalized
2310
+ * @returns Path to the include file
2311
+ */
2312
+ function resolve(originPath: string, includePath: string, alreadyNormalized?: boolean): string;
2313
+ }
2314
+
2315
+ /**
2316
+ * A general purpose buffer pool.
2317
+ * @param alloc Allocator
2318
+ * @param slice Slicer
2319
+ * @param [size=8192] Slab size
2320
+ * @returns Pooled allocator
2321
+ */
2322
+ function pool(alloc: PoolAllocator, slice: PoolSlicer, size?: number): PoolAllocator;
2323
+
2324
+ /** A minimal UTF8 implementation for number arrays. */
2325
+ namespace utf8 {
2326
+
2327
+ /**
2328
+ * Calculates the UTF8 byte length of a string.
2329
+ * @param string String
2330
+ * @returns Byte length
2331
+ */
2332
+ function length(string: string): number;
2333
+
2334
+ /**
2335
+ * Reads UTF8 bytes as a string.
2336
+ * @param buffer Source buffer
2337
+ * @param start Source start
2338
+ * @param end Source end
2339
+ * @returns String read
2340
+ */
2341
+ function read(buffer: Uint8Array, start: number, end: number): string;
2342
+
2343
+ /**
2344
+ * Writes a string as UTF8 bytes.
2345
+ * @param string Source string
2346
+ * @param buffer Destination buffer
2347
+ * @param offset Destination offset
2348
+ * @returns Bytes written
2349
+ */
2350
+ function write(string: string, buffer: Uint8Array, offset: number): number;
2351
+ }
2352
+ }
2353
+
2354
+ /**
2355
+ * Generates a verifier specific to the specified message type.
2356
+ * @param mtype Message type
2357
+ * @returns Codegen instance
2358
+ */
2359
+ export function verifier(mtype: Type): Codegen;
2360
+
2361
+ /** Wrappers for common types. */
2362
+ export const wrappers: { [k: string]: IWrapper };
2363
+
2364
+ /**
2365
+ * From object converter part of an {@link IWrapper}.
2366
+ * @param object Plain object
2367
+ * @returns Message instance
2368
+ */
2369
+ type WrapperFromObjectConverter = (this: Type, object: { [k: string]: any }) => Message<{}>;
2370
+
2371
+ /**
2372
+ * To object converter part of an {@link IWrapper}.
2373
+ * @param message Message instance
2374
+ * @param [options] Conversion options
2375
+ * @returns Plain object
2376
+ */
2377
+ type WrapperToObjectConverter = (this: Type, message: Message<{}>, options?: IConversionOptions) => { [k: string]: any };
2378
+
2379
+ /** Common type wrapper part of {@link wrappers}. */
2380
+ export interface IWrapper {
2381
+
2382
+ /** From object converter */
2383
+ fromObject?: WrapperFromObjectConverter;
2384
+
2385
+ /** To object converter */
2386
+ toObject?: WrapperToObjectConverter;
2387
+ }
2388
+
2389
+ /** Wire format writer using `Uint8Array` if available, otherwise `Array`. */
2390
+ export class Writer {
2391
+
2392
+ /** Constructs a new writer instance. */
2393
+ constructor();
2394
+
2395
+ /** Current length. */
2396
+ public len: number;
2397
+
2398
+ /** Operations head. */
2399
+ public head: object;
2400
+
2401
+ /** Operations tail */
2402
+ public tail: object;
2403
+
2404
+ /** Linked forked states. */
2405
+ public states: (object|null);
2406
+
2407
+ /**
2408
+ * Creates a new writer.
2409
+ * @returns A {@link BufferWriter} when Buffers are supported, otherwise a {@link Writer}
2410
+ */
2411
+ public static create(): (BufferWriter|Writer);
2412
+
2413
+ /**
2414
+ * Allocates a buffer of the specified size.
2415
+ * @param size Buffer size
2416
+ * @returns Buffer
2417
+ */
2418
+ public static alloc(size: number): Uint8Array;
2419
+
2420
+ /**
2421
+ * Writes an unsigned 32 bit value as a varint.
2422
+ * @param value Value to write
2423
+ * @returns `this`
2424
+ */
2425
+ public uint32(value: number): Writer;
2426
+
2427
+ /**
2428
+ * Writes a signed 32 bit value as a varint.
2429
+ * @param value Value to write
2430
+ * @returns `this`
2431
+ */
2432
+ public int32(value: number): Writer;
2433
+
2434
+ /**
2435
+ * Writes a 32 bit value as a varint, zig-zag encoded.
2436
+ * @param value Value to write
2437
+ * @returns `this`
2438
+ */
2439
+ public sint32(value: number): Writer;
2440
+
2441
+ /**
2442
+ * Writes an unsigned 64 bit value as a varint.
2443
+ * @param value Value to write
2444
+ * @returns `this`
2445
+ * @throws {TypeError} If `value` is a string and no long library is present.
2446
+ */
2447
+ public uint64(value: (number|string)): Writer;
2448
+
2449
+ /**
2450
+ * Writes a signed 64 bit value as a varint.
2451
+ * @param value Value to write
2452
+ * @returns `this`
2453
+ * @throws {TypeError} If `value` is a string and no long library is present.
2454
+ */
2455
+ public int64(value: (number|string)): Writer;
2456
+
2457
+ /**
2458
+ * Writes a signed 64 bit value as a varint, zig-zag encoded.
2459
+ * @param value Value to write
2460
+ * @returns `this`
2461
+ * @throws {TypeError} If `value` is a string and no long library is present.
2462
+ */
2463
+ public sint64(value: (number|string)): Writer;
2464
+
2465
+ /**
2466
+ * Writes a boolish value as a varint.
2467
+ * @param value Value to write
2468
+ * @returns `this`
2469
+ */
2470
+ public bool(value: boolean): Writer;
2471
+
2472
+ /**
2473
+ * Writes an unsigned 32 bit value as fixed 32 bits.
2474
+ * @param value Value to write
2475
+ * @returns `this`
2476
+ */
2477
+ public fixed32(value: number): Writer;
2478
+
2479
+ /**
2480
+ * Writes a signed 32 bit value as fixed 32 bits.
2481
+ * @param value Value to write
2482
+ * @returns `this`
2483
+ */
2484
+ public sfixed32(value: number): Writer;
2485
+
2486
+ /**
2487
+ * Writes an unsigned 64 bit value as fixed 64 bits.
2488
+ * @param value Value to write
2489
+ * @returns `this`
2490
+ * @throws {TypeError} If `value` is a string and no long library is present.
2491
+ */
2492
+ public fixed64(value: (number|string)): Writer;
2493
+
2494
+ /**
2495
+ * Writes a signed 64 bit value as fixed 64 bits.
2496
+ * @param value Value to write
2497
+ * @returns `this`
2498
+ * @throws {TypeError} If `value` is a string and no long library is present.
2499
+ */
2500
+ public sfixed64(value: (number|string)): Writer;
2501
+
2502
+ /**
2503
+ * Writes a float (32 bit).
2504
+ * @param value Value to write
2505
+ * @returns `this`
2506
+ */
2507
+ public float(value: number): Writer;
2508
+
2509
+ /**
2510
+ * Writes a double (64 bit float).
2511
+ * @param value Value to write
2512
+ * @returns `this`
2513
+ */
2514
+ public double(value: number): Writer;
2515
+
2516
+ /**
2517
+ * Writes a sequence of bytes.
2518
+ * @param value Buffer or base64 encoded string to write
2519
+ * @returns `this`
2520
+ */
2521
+ public bytes(value: (Uint8Array|string)): Writer;
2522
+
2523
+ /**
2524
+ * Writes a string.
2525
+ * @param value Value to write
2526
+ * @returns `this`
2527
+ */
2528
+ public string(value: string): Writer;
2529
+
2530
+ /**
2531
+ * Forks this writer's state by pushing it to a stack.
2532
+ * Calling {@link Writer#reset|reset} or {@link Writer#ldelim|ldelim} resets the writer to the previous state.
2533
+ * @returns `this`
2534
+ */
2535
+ public fork(): Writer;
2536
+
2537
+ /**
2538
+ * Resets this instance to the last state.
2539
+ * @returns `this`
2540
+ */
2541
+ public reset(): Writer;
2542
+
2543
+ /**
2544
+ * Resets to the last state and appends the fork state's current write length as a varint followed by its operations.
2545
+ * @returns `this`
2546
+ */
2547
+ public ldelim(): Writer;
2548
+
2549
+ /**
2550
+ * Finishes the write operation.
2551
+ * @returns Finished buffer
2552
+ */
2553
+ public finish(): Uint8Array;
2554
+ }
2555
+
2556
+ /** Wire format writer using node buffers. */
2557
+ export class BufferWriter extends Writer {
2558
+
2559
+ /** Constructs a new buffer writer instance. */
2560
+ constructor();
2561
+
2562
+ /**
2563
+ * Finishes the write operation.
2564
+ * @returns Finished buffer
2565
+ */
2566
+ public finish(): Buffer;
2567
+
2568
+ /**
2569
+ * Allocates a buffer of the specified size.
2570
+ * @param size Buffer size
2571
+ * @returns Buffer
2572
+ */
2573
+ public static alloc(size: number): Buffer;
2574
+ }
2575
+
2576
+ /**
2577
+ * Callback as used by {@link util.asPromise}.
2578
+ * @param error Error, if any
2579
+ * @param params Additional arguments
2580
+ */
2581
+ type asPromiseCallback = (error: (Error|null), ...params: any[]) => void;
2582
+
2583
+ /**
2584
+ * Appends code to the function's body or finishes generation.
2585
+ * @param [formatStringOrScope] Format string or, to finish the function, an object of additional scope variables, if any
2586
+ * @param [formatParams] Format parameters
2587
+ * @returns Itself or the generated function if finished
2588
+ * @throws {Error} If format parameter counts do not match
2589
+ */
2590
+ type Codegen = (formatStringOrScope?: (string|{ [k: string]: any }), ...formatParams: any[]) => (Codegen|Function);
2591
+
2592
+ /**
2593
+ * Event listener as used by {@link util.EventEmitter}.
2594
+ * @param args Arguments
2595
+ */
2596
+ type EventEmitterListener = (...args: any[]) => void;
2597
+
2598
+ /**
2599
+ * Node-style callback as used by {@link util.fetch}.
2600
+ * @param error Error, if any, otherwise `null`
2601
+ * @param [contents] File contents, if there hasn't been an error
2602
+ */
2603
+ type FetchCallback = (error: Error, contents?: string) => void;
2604
+
2605
+ /** Options as used by {@link util.fetch}. */
2606
+ export interface IFetchOptions {
2607
+
2608
+ /** Whether expecting a binary response */
2609
+ binary?: boolean;
2610
+
2611
+ /** If `true`, forces the use of XMLHttpRequest */
2612
+ xhr?: boolean;
2613
+ }
2614
+
2615
+ /**
2616
+ * An allocator as used by {@link util.pool}.
2617
+ * @param size Buffer size
2618
+ * @returns Buffer
2619
+ */
2620
+ type PoolAllocator = (size: number) => Uint8Array;
2621
+
2622
+ /**
2623
+ * A slicer as used by {@link util.pool}.
2624
+ * @param start Start offset
2625
+ * @param end End offset
2626
+ * @returns Buffer slice
2627
+ */
2628
+ type PoolSlicer = (this: Uint8Array, start: number, end: number) => Uint8Array;