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