智慧水务管理系统 - 精河县供水工程综合管理平台

index.d.ts 93KB

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