node-red-contrib-tak-registration 0.11.6 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (388) hide show
  1. package/node_modules/@types/node/README.md +2 -2
  2. package/node_modules/@types/node/assert.d.ts +88 -44
  3. package/node_modules/@types/node/async_hooks.d.ts +17 -15
  4. package/node_modules/@types/node/buffer.d.ts +29 -110
  5. package/node_modules/@types/node/child_process.d.ts +38 -34
  6. package/node_modules/@types/node/cluster.d.ts +165 -19
  7. package/node_modules/@types/node/console.d.ts +64 -27
  8. package/node_modules/@types/node/crypto.d.ts +106 -142
  9. package/node_modules/@types/node/dgram.d.ts +14 -14
  10. package/node_modules/@types/node/diagnostics_channel.d.ts +12 -3
  11. package/node_modules/@types/node/dns/promises.d.ts +79 -28
  12. package/node_modules/@types/node/dns.d.ts +124 -69
  13. package/node_modules/@types/node/dom-events.d.ts +2 -0
  14. package/node_modules/@types/node/domain.d.ts +4 -4
  15. package/node_modules/@types/node/events.d.ts +115 -63
  16. package/node_modules/@types/node/fs/promises.d.ts +34 -12
  17. package/node_modules/@types/node/fs.d.ts +104 -40
  18. package/node_modules/@types/node/globals.d.ts +1 -0
  19. package/node_modules/@types/node/http.d.ts +69 -48
  20. package/node_modules/@types/node/http2.d.ts +83 -47
  21. package/node_modules/@types/node/https.d.ts +3 -3
  22. package/node_modules/@types/node/index.d.ts +1 -0
  23. package/node_modules/@types/node/inspector.d.ts +5 -6
  24. package/node_modules/@types/node/module.d.ts +0 -14
  25. package/node_modules/@types/node/net.d.ts +58 -13
  26. package/node_modules/@types/node/os.d.ts +29 -12
  27. package/node_modules/@types/node/package.json +4 -16
  28. package/node_modules/@types/node/path.d.ts +1 -1
  29. package/node_modules/@types/node/perf_hooks.d.ts +308 -48
  30. package/node_modules/@types/node/process.d.ts +241 -48
  31. package/node_modules/@types/node/punycode.d.ts +4 -4
  32. package/node_modules/@types/node/querystring.d.ts +18 -6
  33. package/node_modules/@types/node/readline/promises.d.ts +9 -9
  34. package/node_modules/@types/node/readline.d.ts +23 -22
  35. package/node_modules/@types/node/repl.d.ts +21 -21
  36. package/node_modules/@types/node/sea.d.ts +153 -0
  37. package/node_modules/@types/node/stream/web.d.ts +3 -2
  38. package/node_modules/@types/node/stream.d.ts +63 -57
  39. package/node_modules/@types/node/string_decoder.d.ts +3 -3
  40. package/node_modules/@types/node/test.d.ts +363 -98
  41. package/node_modules/@types/node/timers/promises.d.ts +10 -6
  42. package/node_modules/@types/node/timers.d.ts +5 -5
  43. package/node_modules/@types/node/tls.d.ts +39 -32
  44. package/node_modules/@types/node/trace_events.d.ts +40 -25
  45. package/node_modules/@types/node/tty.d.ts +8 -8
  46. package/node_modules/@types/node/url.d.ts +15 -7
  47. package/node_modules/@types/node/util.d.ts +131 -22
  48. package/node_modules/@types/node/v8.d.ts +51 -7
  49. package/node_modules/@types/node/vm.d.ts +43 -24
  50. package/node_modules/@types/node/wasi.d.ts +12 -10
  51. package/node_modules/@types/node/worker_threads.d.ts +19 -16
  52. package/node_modules/@types/node/zlib.d.ts +16 -3
  53. package/node_modules/adm-zip/README.md +2 -1
  54. package/node_modules/adm-zip/adm-zip.js +46 -45
  55. package/node_modules/adm-zip/headers/entryHeader.js +14 -12
  56. package/node_modules/adm-zip/headers/mainHeader.js +1 -1
  57. package/node_modules/adm-zip/methods/inflater.js +6 -3
  58. package/node_modules/adm-zip/methods/zipcrypto.js +6 -2
  59. package/node_modules/adm-zip/package.json +2 -2
  60. package/node_modules/adm-zip/util/errors.js +1 -0
  61. package/node_modules/adm-zip/zipEntry.js +64 -43
  62. package/node_modules/adm-zip/zipFile.js +35 -35
  63. package/node_modules/axios/CHANGELOG.md +868 -759
  64. package/node_modules/axios/README.md +65 -17
  65. package/node_modules/axios/dist/axios.js +1330 -583
  66. package/node_modules/axios/dist/axios.js.map +1 -1
  67. package/node_modules/axios/dist/axios.min.js +1 -1
  68. package/node_modules/axios/dist/axios.min.js.map +1 -1
  69. package/node_modules/axios/dist/browser/axios.cjs +696 -316
  70. package/node_modules/axios/dist/browser/axios.cjs.map +1 -1
  71. package/node_modules/axios/dist/esm/axios.js +696 -316
  72. package/node_modules/axios/dist/esm/axios.js.map +1 -1
  73. package/node_modules/axios/dist/esm/axios.min.js +1 -1
  74. package/node_modules/axios/dist/esm/axios.min.js.map +1 -1
  75. package/node_modules/axios/dist/node/axios.cjs +607 -257
  76. package/node_modules/axios/dist/node/axios.cjs.map +1 -1
  77. package/node_modules/axios/index.d.cts +5 -2
  78. package/node_modules/axios/index.d.ts +5 -2
  79. package/node_modules/axios/lib/adapters/adapters.js +3 -1
  80. package/node_modules/axios/lib/adapters/fetch.js +227 -0
  81. package/node_modules/axios/lib/adapters/http.js +1 -1
  82. package/node_modules/axios/lib/adapters/xhr.js +31 -101
  83. package/node_modules/axios/lib/core/Axios.js +17 -11
  84. package/node_modules/axios/lib/core/AxiosHeaders.js +4 -0
  85. package/node_modules/axios/lib/core/mergeConfig.js +1 -1
  86. package/node_modules/axios/lib/defaults/index.js +7 -5
  87. package/node_modules/axios/lib/env/data.js +1 -1
  88. package/node_modules/axios/lib/helpers/AxiosTransformStream.js +9 -8
  89. package/node_modules/axios/lib/helpers/composeSignals.js +46 -0
  90. package/node_modules/axios/lib/helpers/progressEventReducer.js +32 -0
  91. package/node_modules/axios/lib/helpers/resolveConfig.js +57 -0
  92. package/node_modules/axios/lib/helpers/throttle.js +5 -3
  93. package/node_modules/axios/lib/helpers/trackStream.js +55 -0
  94. package/node_modules/axios/lib/platform/common/utils.js +4 -1
  95. package/node_modules/axios/lib/utils.js +7 -2
  96. package/node_modules/axios/package.json +27 -26
  97. package/node_modules/fast-xml-parser/CHANGELOG.md +14 -0
  98. package/node_modules/fast-xml-parser/README.md +7 -14
  99. package/node_modules/fast-xml-parser/package.json +1 -1
  100. package/node_modules/fast-xml-parser/src/fxp.d.ts +4 -4
  101. package/node_modules/fast-xml-parser/src/v5/CharsSymbol.js +16 -0
  102. package/node_modules/fast-xml-parser/src/v5/EntitiesParser.js +107 -0
  103. package/node_modules/fast-xml-parser/src/v5/OptionsBuilder.js +64 -0
  104. package/node_modules/fast-xml-parser/src/v5/OutputBuilders/BaseOutputBuilder.js +71 -0
  105. package/node_modules/fast-xml-parser/src/v5/OutputBuilders/JsArrBuilder.js +103 -0
  106. package/node_modules/fast-xml-parser/src/v5/OutputBuilders/JsMinArrBuilder.js +102 -0
  107. package/node_modules/fast-xml-parser/src/v5/OutputBuilders/JsObjBuilder.js +156 -0
  108. package/node_modules/fast-xml-parser/src/v5/OutputBuilders/ParserOptionsBuilder.js +96 -0
  109. package/node_modules/fast-xml-parser/src/v5/Report.js +0 -0
  110. package/node_modules/fast-xml-parser/src/v5/TagPath.js +81 -0
  111. package/node_modules/fast-xml-parser/src/v5/TagPathMatcher.js +15 -0
  112. package/node_modules/fast-xml-parser/src/v5/XMLParser.js +85 -0
  113. package/node_modules/fast-xml-parser/src/v5/Xml2JsParser.js +237 -0
  114. package/node_modules/fast-xml-parser/src/v5/XmlPartReader.js +212 -0
  115. package/node_modules/fast-xml-parser/src/v5/XmlSpecialTagsReader.js +118 -0
  116. package/node_modules/fast-xml-parser/src/v5/inputSource/BufferSource.js +118 -0
  117. package/node_modules/fast-xml-parser/src/v5/inputSource/StringSource.js +123 -0
  118. package/node_modules/fast-xml-parser/src/v5/valueParsers/EntitiesParser.js +107 -0
  119. package/node_modules/fast-xml-parser/src/v5/valueParsers/booleanParser.js +23 -0
  120. package/node_modules/fast-xml-parser/src/v5/valueParsers/booleanParserExt.js +20 -0
  121. package/node_modules/fast-xml-parser/src/v5/valueParsers/currency.js +31 -0
  122. package/node_modules/fast-xml-parser/src/v5/valueParsers/join.js +14 -0
  123. package/node_modules/fast-xml-parser/src/v5/valueParsers/number.js +16 -0
  124. package/node_modules/fast-xml-parser/src/v5/valueParsers/trim.js +8 -0
  125. package/node_modules/fast-xml-parser/src/validator.js +2 -0
  126. package/node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js +13 -4
  127. package/node_modules/follow-redirects/index.js +1 -1
  128. package/node_modules/follow-redirects/package.json +1 -1
  129. package/node_modules/hasown/CHANGELOG.md +12 -0
  130. package/node_modules/hasown/index.d.ts +2 -2
  131. package/node_modules/hasown/package.json +5 -2
  132. package/node_modules/hasown/tsconfig.json +3 -46
  133. package/node_modules/object-is/.eslintrc +1 -1
  134. package/node_modules/object-is/.nycrc +0 -4
  135. package/node_modules/object-is/CHANGELOG.md +25 -0
  136. package/node_modules/object-is/README.md +20 -20
  137. package/node_modules/object-is/package.json +23 -14
  138. package/node_modules/protobufjs/LICENSE +39 -39
  139. package/node_modules/protobufjs/README.md +727 -740
  140. package/node_modules/protobufjs/dist/light/protobuf.js +6264 -6264
  141. package/node_modules/protobufjs/dist/light/protobuf.js.map +1 -1
  142. package/node_modules/protobufjs/dist/light/protobuf.min.js +2 -2
  143. package/node_modules/protobufjs/dist/light/protobuf.min.js.map +1 -1
  144. package/node_modules/protobufjs/dist/minimal/protobuf.js +1928 -1928
  145. package/node_modules/protobufjs/dist/minimal/protobuf.js.map +1 -1
  146. package/node_modules/protobufjs/dist/minimal/protobuf.min.js +2 -2
  147. package/node_modules/protobufjs/dist/minimal/protobuf.min.js.map +1 -1
  148. package/node_modules/protobufjs/dist/protobuf.js +7978 -7961
  149. package/node_modules/protobufjs/dist/protobuf.js.map +1 -1
  150. package/node_modules/protobufjs/dist/protobuf.min.js +3 -3
  151. package/node_modules/protobufjs/dist/protobuf.min.js.map +1 -1
  152. package/node_modules/protobufjs/ext/debug/README.md +4 -4
  153. package/node_modules/protobufjs/ext/debug/index.js +71 -71
  154. package/node_modules/protobufjs/ext/descriptor/README.md +72 -72
  155. package/node_modules/protobufjs/ext/descriptor/index.d.ts +191 -191
  156. package/node_modules/protobufjs/ext/descriptor/index.js +1052 -1052
  157. package/node_modules/protobufjs/ext/descriptor/test.js +54 -54
  158. package/node_modules/protobufjs/google/LICENSE +27 -27
  159. package/node_modules/protobufjs/google/README.md +1 -1
  160. package/node_modules/protobufjs/google/api/annotations.json +82 -82
  161. package/node_modules/protobufjs/google/api/annotations.proto +10 -10
  162. package/node_modules/protobufjs/google/api/http.json +85 -85
  163. package/node_modules/protobufjs/google/api/http.proto +30 -30
  164. package/node_modules/protobufjs/google/protobuf/api.json +117 -117
  165. package/node_modules/protobufjs/google/protobuf/api.proto +33 -33
  166. package/node_modules/protobufjs/google/protobuf/descriptor.json +738 -738
  167. package/node_modules/protobufjs/google/protobuf/descriptor.proto +286 -286
  168. package/node_modules/protobufjs/google/protobuf/source_context.json +19 -19
  169. package/node_modules/protobufjs/google/protobuf/source_context.proto +7 -7
  170. package/node_modules/protobufjs/google/protobuf/type.json +201 -201
  171. package/node_modules/protobufjs/google/protobuf/type.proto +89 -89
  172. package/node_modules/protobufjs/index.d.ts +2741 -2741
  173. package/node_modules/protobufjs/index.js +4 -4
  174. package/node_modules/protobufjs/light.d.ts +2 -2
  175. package/node_modules/protobufjs/light.js +3 -3
  176. package/node_modules/protobufjs/minimal.d.ts +2 -2
  177. package/node_modules/protobufjs/minimal.js +4 -4
  178. package/node_modules/protobufjs/package.json +111 -111
  179. package/node_modules/protobufjs/scripts/postinstall.js +32 -32
  180. package/node_modules/protobufjs/src/common.js +399 -399
  181. package/node_modules/protobufjs/src/converter.js +301 -301
  182. package/node_modules/protobufjs/src/decoder.js +129 -129
  183. package/node_modules/protobufjs/src/encoder.js +100 -100
  184. package/node_modules/protobufjs/src/enum.js +198 -198
  185. package/node_modules/protobufjs/src/field.js +377 -377
  186. package/node_modules/protobufjs/src/index-light.js +104 -104
  187. package/node_modules/protobufjs/src/index-minimal.js +36 -36
  188. package/node_modules/protobufjs/src/index.js +12 -12
  189. package/node_modules/protobufjs/src/mapfield.js +126 -126
  190. package/node_modules/protobufjs/src/message.js +138 -138
  191. package/node_modules/protobufjs/src/method.js +160 -160
  192. package/node_modules/protobufjs/src/namespace.js +433 -433
  193. package/node_modules/protobufjs/src/object.js +243 -243
  194. package/node_modules/protobufjs/src/oneof.js +203 -203
  195. package/node_modules/protobufjs/src/parse.js +889 -872
  196. package/node_modules/protobufjs/src/reader.js +416 -416
  197. package/node_modules/protobufjs/src/reader_buffer.js +51 -51
  198. package/node_modules/protobufjs/src/root.js +368 -368
  199. package/node_modules/protobufjs/src/roots.js +18 -18
  200. package/node_modules/protobufjs/src/rpc/service.js +142 -142
  201. package/node_modules/protobufjs/src/rpc.js +36 -36
  202. package/node_modules/protobufjs/src/service.js +167 -167
  203. package/node_modules/protobufjs/src/tokenize.js +416 -416
  204. package/node_modules/protobufjs/src/type.js +589 -589
  205. package/node_modules/protobufjs/src/types.js +196 -196
  206. package/node_modules/protobufjs/src/typescript.jsdoc +15 -15
  207. package/node_modules/protobufjs/src/util/longbits.js +200 -200
  208. package/node_modules/protobufjs/src/util/minimal.js +438 -438
  209. package/node_modules/protobufjs/src/util.js +212 -212
  210. package/node_modules/protobufjs/src/verifier.js +176 -176
  211. package/node_modules/protobufjs/src/wrappers.js +102 -102
  212. package/node_modules/protobufjs/src/writer.js +465 -465
  213. package/node_modules/protobufjs/src/writer_buffer.js +85 -85
  214. package/node_modules/protobufjs/tsconfig.json +7 -7
  215. package/node_modules/set-function-length/CHANGELOG.md +11 -0
  216. package/node_modules/set-function-length/env.d.ts +9 -6
  217. package/node_modules/set-function-length/env.js +1 -0
  218. package/node_modules/set-function-length/index.d.ts +6 -6
  219. package/node_modules/set-function-length/index.js +1 -3
  220. package/node_modules/set-function-length/package.json +11 -13
  221. package/node_modules/set-function-length/tsconfig.json +7 -57
  222. package/node_modules/undici-types/LICENSE +21 -0
  223. package/node_modules/undici-types/balanced-pool.d.ts +11 -0
  224. package/node_modules/undici-types/client.d.ts +12 -1
  225. package/node_modules/undici-types/diagnostics-channel.d.ts +1 -2
  226. package/node_modules/undici-types/dispatcher.d.ts +17 -3
  227. package/node_modules/undici-types/eventsource.d.ts +61 -0
  228. package/node_modules/undici-types/fetch.d.ts +22 -23
  229. package/node_modules/undici-types/handlers.d.ts +10 -4
  230. package/node_modules/undici-types/index.d.ts +6 -1
  231. package/node_modules/undici-types/package.json +1 -1
  232. package/node_modules/undici-types/pool.d.ts +11 -0
  233. package/node_modules/undici-types/proxy-agent.d.ts +0 -2
  234. package/node_modules/undici-types/readable.d.ts +2 -3
  235. package/node_modules/undici-types/retry-agent.d.ts +11 -0
  236. package/node_modules/undici-types/retry-handler.d.ts +116 -0
  237. package/node_modules/undici-types/util.d.ts +31 -0
  238. package/node_modules/undici-types/webidl.d.ts +6 -1
  239. package/node_modules/undici-types/websocket.d.ts +22 -1
  240. package/node_modules/uuid/CHANGELOG.md +18 -0
  241. package/node_modules/uuid/README.md +134 -16
  242. package/node_modules/uuid/dist/commonjs-browser/index.js +40 -15
  243. package/node_modules/uuid/dist/commonjs-browser/max.js +7 -0
  244. package/node_modules/uuid/dist/commonjs-browser/md5.js +30 -53
  245. package/node_modules/uuid/dist/commonjs-browser/native.js +3 -4
  246. package/node_modules/uuid/dist/commonjs-browser/nil.js +1 -2
  247. package/node_modules/uuid/dist/commonjs-browser/parse.js +14 -15
  248. package/node_modules/uuid/dist/commonjs-browser/regex.js +1 -2
  249. package/node_modules/uuid/dist/commonjs-browser/rng.js +2 -4
  250. package/node_modules/uuid/dist/commonjs-browser/sha1.js +27 -49
  251. package/node_modules/uuid/dist/commonjs-browser/stringify.js +10 -16
  252. package/node_modules/uuid/dist/commonjs-browser/v1.js +73 -49
  253. package/node_modules/uuid/dist/commonjs-browser/v1ToV6.js +26 -0
  254. package/node_modules/uuid/dist/commonjs-browser/v3.js +3 -8
  255. package/node_modules/uuid/dist/commonjs-browser/v35.js +15 -32
  256. package/node_modules/uuid/dist/commonjs-browser/v4.js +7 -18
  257. package/node_modules/uuid/dist/commonjs-browser/v5.js +3 -8
  258. package/node_modules/uuid/dist/commonjs-browser/v6.js +42 -0
  259. package/node_modules/uuid/dist/commonjs-browser/v6ToV1.js +26 -0
  260. package/node_modules/uuid/dist/commonjs-browser/v7.js +152 -0
  261. package/node_modules/uuid/dist/commonjs-browser/validate.js +2 -7
  262. package/node_modules/uuid/dist/commonjs-browser/version.js +2 -8
  263. package/node_modules/uuid/dist/esm-browser/index.js +9 -4
  264. package/node_modules/uuid/dist/esm-browser/max.js +1 -0
  265. package/node_modules/uuid/dist/esm-browser/md5.js +29 -50
  266. package/node_modules/uuid/dist/esm-browser/native.js +1 -1
  267. package/node_modules/uuid/dist/esm-browser/parse.js +12 -10
  268. package/node_modules/uuid/dist/esm-browser/regex.js +1 -1
  269. package/node_modules/uuid/dist/esm-browser/rng.js +3 -4
  270. package/node_modules/uuid/dist/esm-browser/sha1.js +26 -46
  271. package/node_modules/uuid/dist/esm-browser/stringify.js +9 -11
  272. package/node_modules/uuid/dist/esm-browser/v1.js +74 -44
  273. package/node_modules/uuid/dist/esm-browser/v1ToV6.js +20 -0
  274. package/node_modules/uuid/dist/esm-browser/v3.js +1 -1
  275. package/node_modules/uuid/dist/esm-browser/v35.js +14 -25
  276. package/node_modules/uuid/dist/esm-browser/v4.js +5 -9
  277. package/node_modules/uuid/dist/esm-browser/v5.js +1 -1
  278. package/node_modules/uuid/dist/esm-browser/v6.js +36 -0
  279. package/node_modules/uuid/dist/esm-browser/v6ToV1.js +20 -0
  280. package/node_modules/uuid/dist/esm-browser/v7.js +146 -0
  281. package/node_modules/uuid/dist/esm-browser/validate.js +0 -2
  282. package/node_modules/uuid/dist/esm-browser/version.js +0 -3
  283. package/node_modules/uuid/dist/esm-node/index.js +9 -4
  284. package/node_modules/uuid/dist/esm-node/max.js +1 -0
  285. package/node_modules/uuid/dist/esm-node/md5.js +1 -4
  286. package/node_modules/uuid/dist/esm-node/native.js +1 -1
  287. package/node_modules/uuid/dist/esm-node/parse.js +11 -9
  288. package/node_modules/uuid/dist/esm-node/regex.js +1 -1
  289. package/node_modules/uuid/dist/esm-node/rng.js +1 -3
  290. package/node_modules/uuid/dist/esm-node/sha1.js +1 -4
  291. package/node_modules/uuid/dist/esm-node/stringify.js +7 -9
  292. package/node_modules/uuid/dist/esm-node/v1.js +66 -36
  293. package/node_modules/uuid/dist/esm-node/v1ToV6.js +20 -0
  294. package/node_modules/uuid/dist/esm-node/v35.js +8 -19
  295. package/node_modules/uuid/dist/esm-node/v4.js +4 -8
  296. package/node_modules/uuid/dist/esm-node/v6.js +32 -0
  297. package/node_modules/uuid/dist/esm-node/v6ToV1.js +20 -0
  298. package/node_modules/uuid/dist/esm-node/v7.js +146 -0
  299. package/node_modules/uuid/dist/esm-node/validate.js +0 -2
  300. package/node_modules/uuid/dist/esm-node/version.js +0 -3
  301. package/node_modules/uuid/dist/index.js +40 -15
  302. package/node_modules/uuid/dist/max.js +7 -0
  303. package/node_modules/uuid/dist/md5-browser.js +8 -31
  304. package/node_modules/uuid/dist/md5.js +4 -10
  305. package/node_modules/uuid/dist/native-browser.js +2 -3
  306. package/node_modules/uuid/dist/native.js +5 -9
  307. package/node_modules/uuid/dist/nil.js +1 -2
  308. package/node_modules/uuid/dist/parse.js +13 -14
  309. package/node_modules/uuid/dist/regex.js +1 -2
  310. package/node_modules/uuid/dist/rng-browser.js +1 -3
  311. package/node_modules/uuid/dist/rng.js +3 -10
  312. package/node_modules/uuid/dist/sha1-browser.js +1 -23
  313. package/node_modules/uuid/dist/sha1.js +4 -10
  314. package/node_modules/uuid/dist/stringify.js +8 -14
  315. package/node_modules/uuid/dist/uuid-bin.js +12 -22
  316. package/node_modules/uuid/dist/v1.js +66 -42
  317. package/node_modules/uuid/dist/v1ToV6.js +26 -0
  318. package/node_modules/uuid/dist/v3.js +2 -7
  319. package/node_modules/uuid/dist/v35.js +11 -28
  320. package/node_modules/uuid/dist/v4.js +6 -17
  321. package/node_modules/uuid/dist/v5.js +2 -7
  322. package/node_modules/uuid/dist/v6.js +38 -0
  323. package/node_modules/uuid/dist/v6ToV1.js +26 -0
  324. package/node_modules/uuid/dist/v7.js +152 -0
  325. package/node_modules/uuid/dist/validate.js +2 -7
  326. package/node_modules/uuid/dist/version.js +2 -8
  327. package/node_modules/uuid/package.json +41 -34
  328. package/node_modules/uuid/wrapper.mjs +5 -0
  329. package/package.json +6 -6
  330. package/tak-ingest.js +1 -1
  331. package/tak-registration.js +8 -1
  332. package/node_modules/@types/node/ts4.8/assert/strict.d.ts +0 -8
  333. package/node_modules/@types/node/ts4.8/assert.d.ts +0 -996
  334. package/node_modules/@types/node/ts4.8/async_hooks.d.ts +0 -539
  335. package/node_modules/@types/node/ts4.8/buffer.d.ts +0 -2363
  336. package/node_modules/@types/node/ts4.8/child_process.d.ts +0 -1540
  337. package/node_modules/@types/node/ts4.8/cluster.d.ts +0 -432
  338. package/node_modules/@types/node/ts4.8/console.d.ts +0 -415
  339. package/node_modules/@types/node/ts4.8/constants.d.ts +0 -19
  340. package/node_modules/@types/node/ts4.8/crypto.d.ts +0 -4487
  341. package/node_modules/@types/node/ts4.8/dgram.d.ts +0 -596
  342. package/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +0 -545
  343. package/node_modules/@types/node/ts4.8/dns/promises.d.ts +0 -425
  344. package/node_modules/@types/node/ts4.8/dns.d.ts +0 -809
  345. package/node_modules/@types/node/ts4.8/dom-events.d.ts +0 -122
  346. package/node_modules/@types/node/ts4.8/domain.d.ts +0 -170
  347. package/node_modules/@types/node/ts4.8/events.d.ts +0 -879
  348. package/node_modules/@types/node/ts4.8/fs/promises.d.ts +0 -1239
  349. package/node_modules/@types/node/ts4.8/fs.d.ts +0 -4311
  350. package/node_modules/@types/node/ts4.8/globals.d.ts +0 -411
  351. package/node_modules/@types/node/ts4.8/globals.global.d.ts +0 -1
  352. package/node_modules/@types/node/ts4.8/http.d.ts +0 -1887
  353. package/node_modules/@types/node/ts4.8/http2.d.ts +0 -2382
  354. package/node_modules/@types/node/ts4.8/https.d.ts +0 -550
  355. package/node_modules/@types/node/ts4.8/index.d.ts +0 -88
  356. package/node_modules/@types/node/ts4.8/inspector.d.ts +0 -2747
  357. package/node_modules/@types/node/ts4.8/module.d.ts +0 -315
  358. package/node_modules/@types/node/ts4.8/net.d.ts +0 -954
  359. package/node_modules/@types/node/ts4.8/os.d.ts +0 -478
  360. package/node_modules/@types/node/ts4.8/path.d.ts +0 -191
  361. package/node_modules/@types/node/ts4.8/perf_hooks.d.ts +0 -645
  362. package/node_modules/@types/node/ts4.8/process.d.ts +0 -1561
  363. package/node_modules/@types/node/ts4.8/punycode.d.ts +0 -117
  364. package/node_modules/@types/node/ts4.8/querystring.d.ts +0 -141
  365. package/node_modules/@types/node/ts4.8/readline/promises.d.ts +0 -150
  366. package/node_modules/@types/node/ts4.8/readline.d.ts +0 -539
  367. package/node_modules/@types/node/ts4.8/repl.d.ts +0 -430
  368. package/node_modules/@types/node/ts4.8/stream/consumers.d.ts +0 -12
  369. package/node_modules/@types/node/ts4.8/stream/promises.d.ts +0 -83
  370. package/node_modules/@types/node/ts4.8/stream/web.d.ts +0 -366
  371. package/node_modules/@types/node/ts4.8/stream.d.ts +0 -1701
  372. package/node_modules/@types/node/ts4.8/string_decoder.d.ts +0 -67
  373. package/node_modules/@types/node/ts4.8/test.d.ts +0 -1465
  374. package/node_modules/@types/node/ts4.8/timers/promises.d.ts +0 -93
  375. package/node_modules/@types/node/ts4.8/timers.d.ts +0 -240
  376. package/node_modules/@types/node/ts4.8/tls.d.ts +0 -1210
  377. package/node_modules/@types/node/ts4.8/trace_events.d.ts +0 -182
  378. package/node_modules/@types/node/ts4.8/tty.d.ts +0 -208
  379. package/node_modules/@types/node/ts4.8/url.d.ts +0 -944
  380. package/node_modules/@types/node/ts4.8/util.d.ts +0 -2183
  381. package/node_modules/@types/node/ts4.8/v8.d.ts +0 -764
  382. package/node_modules/@types/node/ts4.8/vm.d.ts +0 -903
  383. package/node_modules/@types/node/ts4.8/wasi.d.ts +0 -179
  384. package/node_modules/@types/node/ts4.8/worker_threads.d.ts +0 -691
  385. package/node_modules/@types/node/ts4.8/zlib.d.ts +0 -517
  386. package/node_modules/object-is/.eslintignore +0 -1
  387. package/node_modules/set-function-length/env.d.ts.map +0 -1
  388. package/node_modules/set-function-length/index.d.ts.map +0 -1
@@ -1,740 +1,727 @@
1
- <h1><p align="center"><img alt="protobuf.js" src="https://github.com/dcodeIO/protobuf.js/raw/master/pbjs.png" width="120" height="104" /></p></h1>
2
- <p align="center"><a href="https://npmjs.org/package/protobufjs"><img src="https://img.shields.io/npm/v/protobufjs.svg" alt=""></a> <a href="https://travis-ci.org/dcodeIO/protobuf.js"><img src="https://travis-ci.org/dcodeIO/protobuf.js.svg?branch=master" alt=""></a> <a href="https://npmjs.org/package/protobufjs"><img src="https://img.shields.io/npm/dm/protobufjs.svg" alt=""></a> <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=dcode%40dcode.io&item_name=Open%20Source%20Software%20Donation&item_number=dcodeIO%2Fprotobuf.js"><img alt="donate ❤" src="https://img.shields.io/badge/donate-❤-ff2244.svg"></a></p>
3
-
4
- **Protocol Buffers** are a language-neutral, platform-neutral, extensible way of serializing structured data for use in communications protocols, data storage, and more, originally designed at Google ([see](https://developers.google.com/protocol-buffers/)).
5
-
6
- **protobuf.js** is a pure JavaScript implementation with [TypeScript](https://www.typescriptlang.org) support for [node.js](https://nodejs.org) and the browser. It's easy to use, blazingly fast and works out of the box with [.proto](https://developers.google.com/protocol-buffers/docs/proto) files!
7
-
8
- Contents
9
- --------
10
-
11
- * [Installation](#installation)<br />
12
- How to include protobuf.js in your project.
13
-
14
- * [Usage](#usage)<br />
15
- A brief introduction to using the toolset.
16
-
17
- * [Valid Message](#valid-message)
18
- * [Toolset](#toolset)<br />
19
-
20
- * [Examples](#examples)<br />
21
- A few examples to get you started.
22
-
23
- * [Using .proto files](#using-proto-files)
24
- * [Using JSON descriptors](#using-json-descriptors)
25
- * [Using reflection only](#using-reflection-only)
26
- * [Using custom classes](#using-custom-classes)
27
- * [Using services](#using-services)
28
- * [Usage with TypeScript](#usage-with-typescript)<br />
29
-
30
- * [Additional documentation](#additional-documentation)<br />
31
- A list of available documentation resources.
32
-
33
- * [Performance](#performance)<br />
34
- A few internals and a benchmark on performance.
35
-
36
- * [Compatibility](#compatibility)<br />
37
- Notes on compatibility regarding browsers and optional libraries.
38
-
39
- * [Building](#building)<br />
40
- How to build the library and its components yourself.
41
-
42
- Installation
43
- ---------------
44
-
45
- ### node.js
46
-
47
- ```
48
- $> npm install protobufjs [--save --save-prefix=~]
49
- ```
50
-
51
- ```js
52
- var protobuf = require("protobufjs");
53
- ```
54
-
55
- The command line utility lives in the protobufjs-cli package and must be installed separately:
56
-
57
- ```
58
- $> npm install protobufjs-cli [--save --save-prefix=~]
59
- ```
60
-
61
- **Note** that this library's versioning scheme is not semver-compatible for historical reasons. For guaranteed backward compatibility, always depend on `~6.A.B` instead of `^6.A.B` (hence the `--save-prefix` above).
62
-
63
- ### Browsers
64
-
65
- Development:
66
-
67
- ```
68
- <script src="//cdn.jsdelivr.net/npm/protobufjs@7.X.X/dist/protobuf.js"></script>
69
- ```
70
-
71
- Production:
72
-
73
- ```
74
- <script src="//cdn.jsdelivr.net/npm/protobufjs@7.X.X/dist/protobuf.min.js"></script>
75
- ```
76
-
77
- **Remember** to replace the version tag with the exact [release](https://github.com/protobufjs/protobuf.js/tags) your project depends upon.
78
-
79
- The library supports CommonJS and AMD loaders and also exports globally as `protobuf`.
80
-
81
- ### Distributions
82
-
83
- Where bundle size is a factor, there are additional stripped-down versions of the [full library][dist-full] (~19kb gzipped) available that exclude certain functionality:
84
-
85
- * When working with JSON descriptors (i.e. generated by [pbjs](cli/README.md#pbjs-for-javascript)) and/or reflection only, see the [light library][dist-light] (~16kb gzipped) that excludes the parser. CommonJS entry point is:
86
-
87
- ```js
88
- var protobuf = require("protobufjs/light");
89
- ```
90
-
91
- * When working with statically generated code only, see the [minimal library][dist-minimal] (~6.5kb gzipped) that also excludes reflection. CommonJS entry point is:
92
-
93
- ```js
94
- var protobuf = require("protobufjs/minimal");
95
- ```
96
-
97
- | Distribution | Location
98
- |------------|-----------------------------------
99
- | Full | <https://cdn.jsdelivr.net/npm/protobufjs/dist/>
100
- | Light | <https://cdn.jsdelivr.net/npm/protobufjs/dist/light/>
101
- | Minimal | <https://cdn.jsdelivr.net/npm/protobufjs/dist/minimal/>
102
-
103
- Usage
104
- -----
105
-
106
- Because JavaScript is a dynamically typed language, protobuf.js introduces the concept of a **valid message** in order to provide the best possible [performance](#performance) (and, as a side product, proper typings):
107
-
108
- ### Valid message
109
-
110
- > A valid message is an object (1) not missing any required fields and (2) exclusively composed of JS types understood by the wire format writer.
111
-
112
- There are two possible types of valid messages and the encoder is able to work with both of these for convenience:
113
-
114
- * **Message instances** (explicit instances of message classes with default values on their prototype) always (have to) satisfy the requirements of a valid message by design and
115
- * **Plain JavaScript objects** that just so happen to be composed in a way satisfying the requirements of a valid message as well.
116
-
117
- In a nutshell, the wire format writer understands the following types:
118
-
119
- | Field type | Expected JS type (create, encode) | Conversion (fromObject)
120
- |------------|-----------------------------------|------------------------
121
- | s-/u-/int32<br />s-/fixed32 | `number` (32 bit integer) | <code>value &#124; 0</code> if signed<br />`value >>> 0` if unsigned
122
- | s-/u-/int64<br />s-/fixed64 | `Long`-like (optimal)<br />`number` (53 bit integer) | `Long.fromValue(value)` with long.js<br />`parseInt(value, 10)` otherwise
123
- | float<br />double | `number` | `Number(value)`
124
- | bool | `boolean` | `Boolean(value)`
125
- | string | `string` | `String(value)`
126
- | bytes | `Uint8Array` (optimal)<br />`Buffer` (optimal under node)<br />`Array.<number>` (8 bit integers) | `base64.decode(value)` if a `string`<br />`Object` with non-zero `.length` is assumed to be buffer-like
127
- | enum | `number` (32 bit integer) | Looks up the numeric id if a `string`
128
- | message | Valid message | `Message.fromObject(value)`
129
-
130
- * Explicit `undefined` and `null` are considered as not set if the field is optional.
131
- * Repeated fields are `Array.<T>`.
132
- * Map fields are `Object.<string,T>` with the key being the string representation of the respective value or an 8 characters long binary hash string for `Long`-likes.
133
- * Types marked as *optimal* provide the best performance because no conversion step (i.e. number to low and high bits or base64 string to buffer) is required.
134
-
135
- ### Toolset
136
-
137
- With that in mind and again for performance reasons, each message class provides a distinct set of methods with each method doing just one thing. This avoids unnecessary assertions / redundant operations where performance is a concern but also forces a user to perform verification (of plain JavaScript objects that *might* just so happen to be a valid message) explicitly where necessary - for example when dealing with user input.
138
-
139
- **Note** that `Message` below refers to any message class.
140
-
141
- * **Message.verify**(message: `Object`): `null|string`<br />
142
- verifies that a **plain JavaScript object** satisfies the requirements of a valid message and thus can be encoded without issues. Instead of throwing, it returns the error message as a string, if any.
143
-
144
- ```js
145
- var payload = "invalid (not an object)";
146
- var err = AwesomeMessage.verify(payload);
147
- if (err)
148
- throw Error(err);
149
- ```
150
-
151
- * **Message.encode**(message: `Message|Object` [, writer: `Writer`]): `Writer`<br />
152
- encodes a **message instance** or valid **plain JavaScript object**. This method does not implicitly verify the message and it's up to the user to make sure that the payload is a valid message.
153
-
154
- ```js
155
- var buffer = AwesomeMessage.encode(message).finish();
156
- ```
157
-
158
- * **Message.encodeDelimited**(message: `Message|Object` [, writer: `Writer`]): `Writer`<br />
159
- works like `Message.encode` but additionally prepends the length of the message as a varint.
160
-
161
- * **Message.decode**(reader: `Reader|Uint8Array`): `Message`<br />
162
- decodes a buffer to a **message instance**. If required fields are missing, it throws a `util.ProtocolError` with an `instance` property set to the so far decoded message. If the wire format is invalid, it throws an `Error`.
163
-
164
- ```js
165
- try {
166
- var decodedMessage = AwesomeMessage.decode(buffer);
167
- } catch (e) {
168
- if (e instanceof protobuf.util.ProtocolError) {
169
- // e.instance holds the so far decoded message with missing required fields
170
- } else {
171
- // wire format is invalid
172
- }
173
- }
174
- ```
175
-
176
- * **Message.decodeDelimited**(reader: `Reader|Uint8Array`): `Message`<br />
177
- works like `Message.decode` but additionally reads the length of the message prepended as a varint.
178
-
179
- * **Message.create**(properties: `Object`): `Message`<br />
180
- creates a new **message instance** from a set of properties that satisfy the requirements of a valid message. Where applicable, it is recommended to prefer `Message.create` over `Message.fromObject` because it doesn't perform possibly redundant conversion.
181
-
182
- ```js
183
- var message = AwesomeMessage.create({ awesomeField: "AwesomeString" });
184
- ```
185
-
186
- * **Message.fromObject**(object: `Object`): `Message`<br />
187
- converts any non-valid **plain JavaScript object** to a **message instance** using the conversion steps outlined within the table above.
188
-
189
- ```js
190
- var message = AwesomeMessage.fromObject({ awesomeField: 42 });
191
- // converts awesomeField to a string
192
- ```
193
-
194
- * **Message.toObject**(message: `Message` [, options: `ConversionOptions`]): `Object`<br />
195
- converts a **message instance** to an arbitrary **plain JavaScript object** for interoperability with other libraries or storage. The resulting plain JavaScript object *might* still satisfy the requirements of a valid message depending on the actual conversion options specified, but most of the time it does not.
196
-
197
- ```js
198
- var object = AwesomeMessage.toObject(message, {
199
- enums: String, // enums as string names
200
- longs: String, // longs as strings (requires long.js)
201
- bytes: String, // bytes as base64 encoded strings
202
- defaults: true, // includes default values
203
- arrays: true, // populates empty arrays (repeated fields) even if defaults=false
204
- objects: true, // populates empty objects (map fields) even if defaults=false
205
- oneofs: true // includes virtual oneof fields set to the present field's name
206
- });
207
- ```
208
-
209
- For reference, the following diagram aims to display relationships between the different methods and the concept of a valid message:
210
-
211
- <p align="center"><img alt="Toolset Diagram" src="https://protobufjs.github.io/protobuf.js/toolset.svg" /></p>
212
-
213
- > In other words: `verify` indicates that calling `create` or `encode` directly on the plain object will [result in a valid message respectively] succeed. `fromObject`, on the other hand, does conversion from a broader range of plain objects to create valid messages. ([ref](https://github.com/dcodeIO/protobuf.js/issues/748#issuecomment-291925749))
214
-
215
- Examples
216
- --------
217
-
218
- ### Using .proto files
219
-
220
- It is possible to load existing .proto files using the full library, which parses and compiles the definitions to ready to use (reflection-based) message classes:
221
-
222
- ```protobuf
223
- // awesome.proto
224
- package awesomepackage;
225
- syntax = "proto3";
226
-
227
- message AwesomeMessage {
228
- string awesome_field = 1; // becomes awesomeField
229
- }
230
- ```
231
-
232
- ```js
233
- protobuf.load("awesome.proto", function(err, root) {
234
- if (err)
235
- throw err;
236
-
237
- // Obtain a message type
238
- var AwesomeMessage = root.lookupType("awesomepackage.AwesomeMessage");
239
-
240
- // Exemplary payload
241
- var payload = { awesomeField: "AwesomeString" };
242
-
243
- // Verify the payload if necessary (i.e. when possibly incomplete or invalid)
244
- var errMsg = AwesomeMessage.verify(payload);
245
- if (errMsg)
246
- throw Error(errMsg);
247
-
248
- // Create a new message
249
- var message = AwesomeMessage.create(payload); // or use .fromObject if conversion is necessary
250
-
251
- // Encode a message to an Uint8Array (browser) or Buffer (node)
252
- var buffer = AwesomeMessage.encode(message).finish();
253
- // ... do something with buffer
254
-
255
- // Decode an Uint8Array (browser) or Buffer (node) to a message
256
- var message = AwesomeMessage.decode(buffer);
257
- // ... do something with message
258
-
259
- // If the application uses length-delimited buffers, there is also encodeDelimited and decodeDelimited.
260
-
261
- // Maybe convert the message back to a plain object
262
- var object = AwesomeMessage.toObject(message, {
263
- longs: String,
264
- enums: String,
265
- bytes: String,
266
- // see ConversionOptions
267
- });
268
- });
269
- ```
270
-
271
- Additionally, promise syntax can be used by omitting the callback, if preferred:
272
-
273
- ```js
274
- protobuf.load("awesome.proto")
275
- .then(function(root) {
276
- ...
277
- });
278
- ```
279
-
280
- ### Using JSON descriptors
281
-
282
- The library utilizes JSON descriptors that are equivalent to a .proto definition. For example, the following is identical to the .proto definition seen above:
283
-
284
- ```json
285
- // awesome.json
286
- {
287
- "nested": {
288
- "awesomepackage": {
289
- "nested": {
290
- "AwesomeMessage": {
291
- "fields": {
292
- "awesomeField": {
293
- "type": "string",
294
- "id": 1
295
- }
296
- }
297
- }
298
- }
299
- }
300
- }
301
- }
302
- ```
303
-
304
- JSON descriptors closely resemble the internal reflection structure:
305
-
306
- | Type (T) | Extends | Type-specific properties
307
- |--------------------|--------------------|-------------------------
308
- | *ReflectionObject* | | options
309
- | *Namespace* | *ReflectionObject* | nested
310
- | Root | *Namespace* | **nested**
311
- | Type | *Namespace* | **fields**
312
- | Enum | *ReflectionObject* | **values**
313
- | Field | *ReflectionObject* | rule, **type**, **id**
314
- | MapField | Field | **keyType**
315
- | OneOf | *ReflectionObject* | **oneof** (array of field names)
316
- | Service | *Namespace* | **methods**
317
- | Method | *ReflectionObject* | type, **requestType**, **responseType**, requestStream, responseStream
318
-
319
- * **Bold properties** are required. *Italic types* are abstract.
320
- * `T.fromJSON(name, json)` creates the respective reflection object from a JSON descriptor
321
- * `T#toJSON()` creates a JSON descriptor from the respective reflection object (its name is used as the key within the parent)
322
-
323
- Exclusively using JSON descriptors instead of .proto files enables the use of just the light library (the parser isn't required in this case).
324
-
325
- A JSON descriptor can either be loaded the usual way:
326
-
327
- ```js
328
- protobuf.load("awesome.json", function(err, root) {
329
- if (err) throw err;
330
-
331
- // Continue at "Obtain a message type" above
332
- });
333
- ```
334
-
335
- Or it can be loaded inline:
336
-
337
- ```js
338
- var jsonDescriptor = require("./awesome.json"); // exemplary for node
339
-
340
- var root = protobuf.Root.fromJSON(jsonDescriptor);
341
-
342
- // Continue at "Obtain a message type" above
343
- ```
344
-
345
- ### Using reflection only
346
-
347
- Both the full and the light library include full reflection support. One could, for example, define the .proto definitions seen in the examples above using just reflection:
348
-
349
- ```js
350
- ...
351
- var Root = protobuf.Root,
352
- Type = protobuf.Type,
353
- Field = protobuf.Field;
354
-
355
- var AwesomeMessage = new Type("AwesomeMessage").add(new Field("awesomeField", 1, "string"));
356
-
357
- var root = new Root().define("awesomepackage").add(AwesomeMessage);
358
-
359
- // Continue at "Create a new message" above
360
- ...
361
- ```
362
-
363
- Detailed information on the reflection structure is available within the [API documentation](#additional-documentation).
364
-
365
- ### Using custom classes
366
-
367
- Message classes can also be extended with custom functionality and it is also possible to register a custom constructor with a reflected message type:
368
-
369
- ```js
370
- ...
371
-
372
- // Define a custom constructor
373
- function AwesomeMessage(properties) {
374
- // custom initialization code
375
- ...
376
- }
377
-
378
- // Register the custom constructor with its reflected type (*)
379
- root.lookupType("awesomepackage.AwesomeMessage").ctor = AwesomeMessage;
380
-
381
- // Define custom functionality
382
- AwesomeMessage.customStaticMethod = function() { ... };
383
- AwesomeMessage.prototype.customInstanceMethod = function() { ... };
384
-
385
- // Continue at "Create a new message" above
386
- ```
387
-
388
- (*) Besides referencing its reflected type through `AwesomeMessage.$type` and `AwesomeMesage#$type`, the respective custom class is automatically populated with:
389
-
390
- * `AwesomeMessage.create`
391
- * `AwesomeMessage.encode` and `AwesomeMessage.encodeDelimited`
392
- * `AwesomeMessage.decode` and `AwesomeMessage.decodeDelimited`
393
- * `AwesomeMessage.verify`
394
- * `AwesomeMessage.fromObject`, `AwesomeMessage.toObject` and `AwesomeMessage#toJSON`
395
-
396
- Afterwards, decoded messages of this type are `instanceof AwesomeMessage`.
397
-
398
- Alternatively, it is also possible to reuse and extend the internal constructor if custom initialization code is not required:
399
-
400
- ```js
401
- ...
402
-
403
- // Reuse the internal constructor
404
- var AwesomeMessage = root.lookupType("awesomepackage.AwesomeMessage").ctor;
405
-
406
- // Define custom functionality
407
- AwesomeMessage.customStaticMethod = function() { ... };
408
- AwesomeMessage.prototype.customInstanceMethod = function() { ... };
409
-
410
- // Continue at "Create a new message" above
411
- ```
412
-
413
- ### Using services
414
-
415
- The library also supports consuming services but it doesn't make any assumptions about the actual transport channel. Instead, a user must provide a suitable RPC implementation, which is an asynchronous function that takes the reflected service method, the binary request and a node-style callback as its parameters:
416
-
417
- ```js
418
- function rpcImpl(method, requestData, callback) {
419
- // perform the request using an HTTP request or a WebSocket for example
420
- var responseData = ...;
421
- // and call the callback with the binary response afterwards:
422
- callback(null, responseData);
423
- }
424
- ```
425
-
426
- Below is a working example with a typescript implementation using grpc npm package.
427
- ```ts
428
- const grpc = require('grpc')
429
-
430
- const Client = grpc.makeGenericClientConstructor({})
431
- const client = new Client(
432
- grpcServerUrl,
433
- grpc.credentials.createInsecure()
434
- )
435
-
436
- const rpcImpl = function(method, requestData, callback) {
437
- client.makeUnaryRequest(
438
- method.name,
439
- arg => arg,
440
- arg => arg,
441
- requestData,
442
- callback
443
- )
444
- }
445
- ```
446
-
447
- Example:
448
-
449
- ```protobuf
450
- // greeter.proto
451
- syntax = "proto3";
452
-
453
- service Greeter {
454
- rpc SayHello (HelloRequest) returns (HelloReply) {}
455
- }
456
-
457
- message HelloRequest {
458
- string name = 1;
459
- }
460
-
461
- message HelloReply {
462
- string message = 1;
463
- }
464
- ```
465
-
466
- ```js
467
- ...
468
- var Greeter = root.lookup("Greeter");
469
- var greeter = Greeter.create(/* see above */ rpcImpl, /* request delimited? */ false, /* response delimited? */ false);
470
-
471
- greeter.sayHello({ name: 'you' }, function(err, response) {
472
- console.log('Greeting:', response.message);
473
- });
474
- ```
475
-
476
- Services also support promises:
477
-
478
- ```js
479
- greeter.sayHello({ name: 'you' })
480
- .then(function(response) {
481
- console.log('Greeting:', response.message);
482
- });
483
- ```
484
-
485
- There is also an [example for streaming RPC](https://github.com/dcodeIO/protobuf.js/blob/master/examples/streaming-rpc.js).
486
-
487
- Note that the service API is meant for clients. Implementing a server-side endpoint pretty much always requires transport channel (i.e. http, websocket, etc.) specific code with the only common denominator being that it decodes and encodes messages.
488
-
489
- ### Usage with TypeScript
490
-
491
- The library ships with its own [type definitions](https://github.com/dcodeIO/protobuf.js/blob/master/index.d.ts) and modern editors like [Visual Studio Code](https://code.visualstudio.com/) will automatically detect and use them for code completion.
492
-
493
- The npm package depends on [@types/node](https://www.npmjs.com/package/@types/node) because of `Buffer` and [@types/long](https://www.npmjs.com/package/@types/long) because of `Long`. If you are not building for node and/or not using long.js, it should be safe to exclude them manually.
494
-
495
- #### Using the JS API
496
-
497
- The API shown above works pretty much the same with TypeScript. However, because everything is typed, accessing fields on instances of dynamically generated message classes requires either using bracket-notation (i.e. `message["awesomeField"]`) or explicit casts. Alternatively, it is possible to use a [typings file generated for its static counterpart](#pbts-for-typescript).
498
-
499
- ```ts
500
- import { load } from "protobufjs"; // respectively "./node_modules/protobufjs"
501
-
502
- load("awesome.proto", function(err, root) {
503
- if (err)
504
- throw err;
505
-
506
- // example code
507
- const AwesomeMessage = root.lookupType("awesomepackage.AwesomeMessage");
508
-
509
- let message = AwesomeMessage.create({ awesomeField: "hello" });
510
- console.log(`message = ${JSON.stringify(message)}`);
511
-
512
- let buffer = AwesomeMessage.encode(message).finish();
513
- console.log(`buffer = ${Array.prototype.toString.call(buffer)}`);
514
-
515
- let decoded = AwesomeMessage.decode(buffer);
516
- console.log(`decoded = ${JSON.stringify(decoded)}`);
517
- });
518
- ```
519
-
520
- #### Using generated static code
521
-
522
- If you generated static code to `bundle.js` using the CLI and its type definitions to `bundle.d.ts`, then you can just do:
523
-
524
- ```ts
525
- import { AwesomeMessage } from "./bundle.js";
526
-
527
- // example code
528
- let message = AwesomeMessage.create({ awesomeField: "hello" });
529
- let buffer = AwesomeMessage.encode(message).finish();
530
- let decoded = AwesomeMessage.decode(buffer);
531
- ```
532
-
533
- #### Using decorators
534
-
535
- The library also includes an early implementation of [decorators](https://www.typescriptlang.org/docs/handbook/decorators.html).
536
-
537
- **Note** that decorators are an experimental feature in TypeScript and that declaration order is important depending on the JS target. For example, `@Field.d(2, AwesomeArrayMessage)` requires that `AwesomeArrayMessage` has been defined earlier when targeting `ES5`.
538
-
539
- ```ts
540
- import { Message, Type, Field, OneOf } from "protobufjs/light"; // respectively "./node_modules/protobufjs/light.js"
541
-
542
- export class AwesomeSubMessage extends Message<AwesomeSubMessage> {
543
-
544
- @Field.d(1, "string")
545
- public awesomeString: string;
546
-
547
- }
548
-
549
- export enum AwesomeEnum {
550
- ONE = 1,
551
- TWO = 2
552
- }
553
-
554
- @Type.d("SuperAwesomeMessage")
555
- export class AwesomeMessage extends Message<AwesomeMessage> {
556
-
557
- @Field.d(1, "string", "optional", "awesome default string")
558
- public awesomeField: string;
559
-
560
- @Field.d(2, AwesomeSubMessage)
561
- public awesomeSubMessage: AwesomeSubMessage;
562
-
563
- @Field.d(3, AwesomeEnum, "optional", AwesomeEnum.ONE)
564
- public awesomeEnum: AwesomeEnum;
565
-
566
- @OneOf.d("awesomeSubMessage", "awesomeEnum")
567
- public which: string;
568
-
569
- }
570
-
571
- // example code
572
- let message = new AwesomeMessage({ awesomeField: "hello" });
573
- let buffer = AwesomeMessage.encode(message).finish();
574
- let decoded = AwesomeMessage.decode(buffer);
575
- ```
576
-
577
- Supported decorators are:
578
-
579
- * **Type.d(typeName?: `string`)** &nbsp; *(optional)*<br />
580
- annotates a class as a protobuf message type. If `typeName` is not specified, the constructor's runtime function name is used for the reflected type.
581
-
582
- * **Field.d&lt;T>(fieldId: `number`, fieldType: `string | Constructor<T>`, fieldRule?: `"optional" | "required" | "repeated"`, defaultValue?: `T`)**<br />
583
- annotates a property as a protobuf field with the specified id and protobuf type.
584
-
585
- * **MapField.d&lt;T extends { [key: string]: any }>(fieldId: `number`, fieldKeyType: `string`, fieldValueType. `string | Constructor<{}>`)**<br />
586
- annotates a property as a protobuf map field with the specified id, protobuf key and value type.
587
-
588
- * **OneOf.d&lt;T extends string>(...fieldNames: `string[]`)**<br />
589
- annotates a property as a protobuf oneof covering the specified fields.
590
-
591
- Other notes:
592
-
593
- * Decorated types reside in `protobuf.roots["decorated"]` using a flat structure, so no duplicate names.
594
- * Enums are copied to a reflected enum with a generic name on decorator evaluation because referenced enum objects have no runtime name the decorator could use.
595
- * Default values must be specified as arguments to the decorator instead of using a property initializer for proper prototype behavior.
596
- * Property names on decorated classes must not be renamed on compile time (i.e. by a minifier) because decorators just receive the original field name as a string.
597
-
598
- **ProTip!** Not as pretty, but you can [use decorators in plain JavaScript](https://github.com/dcodeIO/protobuf.js/blob/master/examples/js-decorators.js) as well.
599
-
600
- Additional documentation
601
- ------------------------
602
-
603
- #### Protocol Buffers
604
- * [Google's Developer Guide](https://developers.google.com/protocol-buffers/docs/overview)
605
-
606
- #### protobuf.js
607
- * [API Documentation](https://protobufjs.github.io/protobuf.js)
608
- * [CHANGELOG](https://github.com/dcodeIO/protobuf.js/blob/master/CHANGELOG.md)
609
- * [Frequently asked questions](https://github.com/dcodeIO/protobuf.js/wiki) on our wiki
610
-
611
- #### Community
612
- * [Questions and answers](http://stackoverflow.com/search?tab=newest&q=protobuf.js) on StackOverflow
613
-
614
- Performance
615
- -----------
616
- The package includes a benchmark that compares protobuf.js performance to native JSON (as far as this is possible) and [Google's JS implementation](https://github.com/google/protobuf/tree/master/js). On an i7-2600K running node 6.9.1 it yields:
617
-
618
- ```
619
- benchmarking encoding performance ...
620
-
621
- protobuf.js (reflect) x 541,707 ops/sec ±1.13% (87 runs sampled)
622
- protobuf.js (static) x 548,134 ops/sec ±1.38% (89 runs sampled)
623
- JSON (string) x 318,076 ops/sec ±0.63% (93 runs sampled)
624
- JSON (buffer) x 179,165 ops/sec ±2.26% (91 runs sampled)
625
- google-protobuf x 74,406 ops/sec ±0.85% (86 runs sampled)
626
-
627
- protobuf.js (static) was fastest
628
- protobuf.js (reflect) was 0.9% ops/sec slower (factor 1.0)
629
- JSON (string) was 41.5% ops/sec slower (factor 1.7)
630
- JSON (buffer) was 67.6% ops/sec slower (factor 3.1)
631
- google-protobuf was 86.4% ops/sec slower (factor 7.3)
632
-
633
- benchmarking decoding performance ...
634
-
635
- protobuf.js (reflect) x 1,383,981 ops/sec ±0.88% (93 runs sampled)
636
- protobuf.js (static) x 1,378,925 ops/sec ±0.81% (93 runs sampled)
637
- JSON (string) x 302,444 ops/sec ±0.81% (93 runs sampled)
638
- JSON (buffer) x 264,882 ops/sec ±0.81% (93 runs sampled)
639
- google-protobuf x 179,180 ops/sec ±0.64% (94 runs sampled)
640
-
641
- protobuf.js (reflect) was fastest
642
- protobuf.js (static) was 0.3% ops/sec slower (factor 1.0)
643
- JSON (string) was 78.1% ops/sec slower (factor 4.6)
644
- JSON (buffer) was 80.8% ops/sec slower (factor 5.2)
645
- google-protobuf was 87.0% ops/sec slower (factor 7.7)
646
-
647
- benchmarking combined performance ...
648
-
649
- protobuf.js (reflect) x 275,900 ops/sec ±0.78% (90 runs sampled)
650
- protobuf.js (static) x 290,096 ops/sec ±0.96% (90 runs sampled)
651
- JSON (string) x 129,381 ops/sec ±0.77% (90 runs sampled)
652
- JSON (buffer) x 91,051 ops/sec ±0.94% (90 runs sampled)
653
- google-protobuf x 42,050 ops/sec ±0.85% (91 runs sampled)
654
-
655
- protobuf.js (static) was fastest
656
- protobuf.js (reflect) was 4.7% ops/sec slower (factor 1.0)
657
- JSON (string) was 55.3% ops/sec slower (factor 2.2)
658
- JSON (buffer) was 68.6% ops/sec slower (factor 3.2)
659
- google-protobuf was 85.5% ops/sec slower (factor 6.9)
660
- ```
661
-
662
- These results are achieved by
663
-
664
- * generating type-specific encoders, decoders, verifiers and converters at runtime
665
- * configuring the reader/writer interface according to the environment
666
- * using node-specific functionality where beneficial and, of course
667
- * avoiding unnecessary operations through splitting up [the toolset](#toolset).
668
-
669
- You can also run [the benchmark](https://github.com/dcodeIO/protobuf.js/blob/master/bench/index.js) ...
670
-
671
- ```
672
- $> npm run bench
673
- ```
674
-
675
- and [the profiler](https://github.com/dcodeIO/protobuf.js/blob/master/bench/prof.js) yourself (the latter requires a recent version of node):
676
-
677
- ```
678
- $> npm run prof <encode|decode|encode-browser|decode-browser> [iterations=10000000]
679
- ```
680
-
681
- Note that as of this writing, the benchmark suite performs significantly slower on node 7.2.0 compared to 6.9.1 because moths.
682
-
683
- Compatibility
684
- -------------
685
-
686
- * Works in all modern and not-so-modern browsers except IE8.
687
- * Because the internals of this package do not rely on `google/protobuf/descriptor.proto`, options are parsed and presented literally.
688
- * If typed arrays are not supported by the environment, plain arrays will be used instead.
689
- * Support for pre-ES5 environments (except IE8) can be achieved by [using a polyfill](https://github.com/dcodeIO/protobuf.js/blob/master/scripts/polyfill.js).
690
- * Support for [Content Security Policy](https://w3c.github.io/webappsec-csp/)-restricted environments (like Chrome extensions without [unsafe-eval](https://developer.chrome.com/extensions/contentSecurityPolicy#relaxing-eval)) can be achieved by generating and using static code instead.
691
- * If a proper way to work with 64 bit values (uint64, int64 etc.) is required, just install [long.js](https://github.com/dcodeIO/long.js) alongside this library. All 64 bit numbers will then be returned as a `Long` instance instead of a possibly unsafe JavaScript number ([see](https://github.com/dcodeIO/long.js)).
692
- * For descriptor.proto interoperability, see [ext/descriptor](https://github.com/dcodeIO/protobuf.js/tree/master/ext/descriptor)
693
-
694
- Building
695
- --------
696
-
697
- To build the library or its components yourself, clone it from GitHub and install the development dependencies:
698
-
699
- ```
700
- $> git clone https://github.com/dcodeIO/protobuf.js.git
701
- $> cd protobuf.js
702
- $> npm install
703
- ```
704
-
705
- Building the respective development and production versions with their respective source maps to `dist/`:
706
-
707
- ```
708
- $> npm run build
709
- ```
710
-
711
- Building the documentation to `docs/`:
712
-
713
- ```
714
- $> npm run docs
715
- ```
716
-
717
- Building the TypeScript definition to `index.d.ts`:
718
-
719
- ```
720
- $> npm run types
721
- ```
722
-
723
- ### Browserify integration
724
-
725
- By default, protobuf.js integrates into any browserify build-process without requiring any optional modules. Hence:
726
-
727
- * If int64 support is required, explicitly require the `long` module somewhere in your project as it will be excluded otherwise. This assumes that a global `require` function is present that protobuf.js can call to obtain the long module.
728
-
729
- If there is no global `require` function present after bundling, it's also possible to assign the long module programmatically:
730
-
731
- ```js
732
- var Long = ...;
733
-
734
- protobuf.util.Long = Long;
735
- protobuf.configure();
736
- ```
737
-
738
- * If you have any special requirements, there is [the bundler](https://github.com/dcodeIO/protobuf.js/blob/master/scripts/bundle.js) for reference.
739
-
740
- **License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause)
1
+ <h1><p align="center"><img alt="protobuf.js" src="https://github.com/protobufjs/protobuf.js/raw/master/pbjs.svg" height="100" /><br/>protobuf.js</p></h1>
2
+ <p align="center">
3
+ <a href="https://github.com/protobufjs/protobuf.js/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/protobufjs/protobuf.js/test.yml?branch=master&label=build&logo=github" alt=""></a>
4
+ <a href="https://github.com/protobufjs/protobuf.js/actions/workflows/release.yaml"><img src="https://img.shields.io/github/actions/workflow/status/protobufjs/protobuf.js/release.yaml?branch=master&label=release&logo=github" alt=""></a>
5
+ <a href="https://npmjs.org/package/protobufjs"><img src="https://img.shields.io/npm/v/protobufjs.svg?logo=npm" alt=""></a>
6
+ <a href="https://npmjs.org/package/protobufjs"><img src="https://img.shields.io/npm/dm/protobufjs.svg?label=downloads&logo=npm" alt=""></a>
7
+ <a href="https://www.jsdelivr.com/package/npm/protobufjs"><img src="https://img.shields.io/jsdelivr/npm/hm/protobufjs?label=requests&logo=jsdelivr" alt=""></a>
8
+ </p>
9
+
10
+ **Protocol Buffers** are a language-neutral, platform-neutral, extensible way of serializing structured data for use in communications protocols, data storage, and more, originally designed at Google ([see](https://protobuf.dev/)).
11
+
12
+ **protobuf.js** is a pure JavaScript implementation with [TypeScript](https://www.typescriptlang.org) support for [Node.js](https://nodejs.org) and the browser. It's easy to use, does not sacrifice on performance, has good conformance and works out of the box with [.proto](https://protobuf.dev/programming-guides/proto3/) files!
13
+
14
+ Contents
15
+ --------
16
+
17
+ * [Installation](#installation)<br />
18
+ How to include protobuf.js in your project.
19
+
20
+ * [Usage](#usage)<br />
21
+ A brief introduction to using the toolset.
22
+
23
+ * [Valid Message](#valid-message)
24
+ * [Toolset](#toolset)<br />
25
+
26
+ * [Examples](#examples)<br />
27
+ A few examples to get you started.
28
+
29
+ * [Using .proto files](#using-proto-files)
30
+ * [Using JSON descriptors](#using-json-descriptors)
31
+ * [Using reflection only](#using-reflection-only)
32
+ * [Using custom classes](#using-custom-classes)
33
+ * [Using services](#using-services)
34
+ * [Usage with TypeScript](#usage-with-typescript)<br />
35
+
36
+ * [Additional documentation](#additional-documentation)<br />
37
+ A list of available documentation resources.
38
+
39
+ * [Performance](#performance)<br />
40
+ A few internals and a benchmark on performance.
41
+
42
+ * [Compatibility](#compatibility)<br />
43
+ Notes on compatibility regarding browsers and optional libraries.
44
+
45
+ * [Building](#building)<br />
46
+ How to build the library and its components yourself.
47
+
48
+ Installation
49
+ ---------------
50
+
51
+ ### Node.js
52
+
53
+ ```sh
54
+ npm install protobufjs --save
55
+ ```
56
+
57
+ ```js
58
+ // Static code + Reflection + .proto parser
59
+ var protobuf = require("protobufjs");
60
+
61
+ // Static code + Reflection
62
+ var protobuf = require("protobufjs/light");
63
+
64
+ // Static code only
65
+ var protobuf = require("protobufjs/minimal");
66
+ ```
67
+
68
+ The optional [command line utility](./cli/) to generate static code and reflection bundles lives in the `protobufjs-cli` package and can be installed separately:
69
+
70
+ ```sh
71
+ npm install protobufjs-cli --save-dev
72
+ ```
73
+
74
+ ### Browsers
75
+
76
+ Pick the variant matching your needs and replace the version tag with the exact [release](https://github.com/protobufjs/protobuf.js/tags) your project depends upon. For example, to use the minified full variant:
77
+
78
+ ```html
79
+ <script src="//cdn.jsdelivr.net/npm/protobufjs@7.X.X/dist/protobuf.min.js"></script>
80
+ ```
81
+
82
+ | Distribution | Location
83
+ |--------------|--------------------------------------------------------
84
+ | Full | <https://cdn.jsdelivr.net/npm/protobufjs/dist/>
85
+ | Light | <https://cdn.jsdelivr.net/npm/protobufjs/dist/light/>
86
+ | Minimal | <https://cdn.jsdelivr.net/npm/protobufjs/dist/minimal/>
87
+
88
+ All variants support CommonJS and AMD loaders and export globally as `window.protobuf`.
89
+
90
+ Usage
91
+ -----
92
+
93
+ Because JavaScript is a dynamically typed language, protobuf.js utilizes the concept of a **valid message** in order to provide the best possible [performance](#performance) (and, as a side product, proper typings):
94
+
95
+ ### Valid message
96
+
97
+ > A valid message is an object (1) not missing any required fields and (2) exclusively composed of JS types understood by the wire format writer.
98
+
99
+ There are two possible types of valid messages and the encoder is able to work with both of these for convenience:
100
+
101
+ * **Message instances** (explicit instances of message classes with default values on their prototype) naturally satisfy the requirements of a valid message and
102
+ * **Plain JavaScript objects** that just so happen to be composed in a way satisfying the requirements of a valid message as well.
103
+
104
+ In a nutshell, the wire format writer understands the following types:
105
+
106
+ | Field type | Expected JS type (create, encode) | Conversion (fromObject)
107
+ |------------|-----------------------------------|------------------------
108
+ | s-/u-/int32<br />s-/fixed32 | `number` (32 bit integer) | <code>value &#124; 0</code> if signed<br />`value >>> 0` if unsigned
109
+ | s-/u-/int64<br />s-/fixed64 | `Long`-like (optimal)<br />`number` (53 bit integer) | `Long.fromValue(value)` with long.js<br />`parseInt(value, 10)` otherwise
110
+ | float<br />double | `number` | `Number(value)`
111
+ | bool | `boolean` | `Boolean(value)`
112
+ | string | `string` | `String(value)`
113
+ | bytes | `Uint8Array` (optimal)<br />`Buffer` (optimal under node)<br />`Array.<number>` (8 bit integers) | `base64.decode(value)` if a `string`<br />`Object` with non-zero `.length` is assumed to be buffer-like
114
+ | enum | `number` (32 bit integer) | Looks up the numeric id if a `string`
115
+ | message | Valid message | `Message.fromObject(value)`
116
+ | repeated T | `Array<T>` | Copy
117
+ | map<K, V> | `Object<K,V>` | Copy
118
+
119
+ * Explicit `undefined` and `null` are considered as not set if the field is optional.
120
+ * Maps are objects where the key is the string representation of the respective value or an 8 characters long hash string for `Long`-likes.
121
+
122
+ ### Toolset
123
+
124
+ With that in mind and again for performance reasons, each message class provides a distinct set of methods with each method doing just one thing. This avoids unnecessary assertions / redundant operations where performance is a concern but also forces a user to perform verification (of plain JavaScript objects that *might* just so happen to be a valid message) explicitly where necessary - for example when dealing with user input.
125
+
126
+ **Note** that `Message` below refers to any message class.
127
+
128
+ * **Message.verify**(message: `Object`): `null|string`<br />
129
+ verifies that a **plain JavaScript object** satisfies the requirements of a valid message and thus can be encoded without issues. Instead of throwing, it returns the error message as a string, if any.
130
+
131
+ ```js
132
+ var payload = "invalid (not an object)";
133
+ var err = AwesomeMessage.verify(payload);
134
+ if (err)
135
+ throw Error(err);
136
+ ```
137
+
138
+ * **Message.encode**(message: `Message|Object` [, writer: `Writer`]): `Writer`<br />
139
+ encodes a **message instance** or valid **plain JavaScript object**. This method does not implicitly verify the message and it's up to the user to make sure that the payload is a valid message.
140
+
141
+ ```js
142
+ var buffer = AwesomeMessage.encode(message).finish();
143
+ ```
144
+
145
+ * **Message.encodeDelimited**(message: `Message|Object` [, writer: `Writer`]): `Writer`<br />
146
+ works like `Message.encode` but additionally prepends the length of the message as a varint.
147
+
148
+ * **Message.decode**(reader: `Reader|Uint8Array`): `Message`<br />
149
+ decodes a buffer to a **message instance**. If required fields are missing, it throws a `util.ProtocolError` with an `instance` property set to the so far decoded message. If the wire format is invalid, it throws an `Error`.
150
+
151
+ ```js
152
+ try {
153
+ var decodedMessage = AwesomeMessage.decode(buffer);
154
+ } catch (e) {
155
+ if (e instanceof protobuf.util.ProtocolError) {
156
+ // e.instance holds the so far decoded message with missing required fields
157
+ } else {
158
+ // wire format is invalid
159
+ }
160
+ }
161
+ ```
162
+
163
+ * **Message.decodeDelimited**(reader: `Reader|Uint8Array`): `Message`<br />
164
+ works like `Message.decode` but additionally reads the length of the message prepended as a varint.
165
+
166
+ * **Message.create**(properties: `Object`): `Message`<br />
167
+ creates a new **message instance** from a set of properties that satisfy the requirements of a valid message. Where applicable, it is recommended to prefer `Message.create` over `Message.fromObject` because it doesn't perform possibly redundant conversion.
168
+
169
+ ```js
170
+ var message = AwesomeMessage.create({ awesomeField: "AwesomeString" });
171
+ ```
172
+
173
+ * **Message.fromObject**(object: `Object`): `Message`<br />
174
+ converts any non-valid **plain JavaScript object** to a **message instance** using the conversion steps outlined within the table above.
175
+
176
+ ```js
177
+ var message = AwesomeMessage.fromObject({ awesomeField: 42 });
178
+ // converts awesomeField to a string
179
+ ```
180
+
181
+ * **Message.toObject**(message: `Message` [, options: `ConversionOptions`]): `Object`<br />
182
+ converts a **message instance** to an arbitrary **plain JavaScript object** for interoperability with other libraries or storage. The resulting plain JavaScript object *might* still satisfy the requirements of a valid message depending on the actual conversion options specified, but most of the time it does not.
183
+
184
+ ```js
185
+ var object = AwesomeMessage.toObject(message, {
186
+ enums: String, // enums as string names
187
+ longs: String, // longs as strings (requires long.js)
188
+ bytes: String, // bytes as base64 encoded strings
189
+ defaults: true, // includes default values
190
+ arrays: true, // populates empty arrays (repeated fields) even if defaults=false
191
+ objects: true, // populates empty objects (map fields) even if defaults=false
192
+ oneofs: true // includes virtual oneof fields set to the present field's name
193
+ });
194
+ ```
195
+
196
+ For reference, the following diagram aims to display relationships between the different methods and the concept of a valid message:
197
+
198
+ <p align="center"><img alt="Toolset Diagram" src="https://protobufjs.github.io/protobuf.js/toolset.svg" /></p>
199
+
200
+ > In other words: `verify` indicates that calling `create` or `encode` directly on the plain object will [result in a valid message respectively] succeed. `fromObject`, on the other hand, does conversion from a broader range of plain objects to create valid messages. ([ref](https://github.com/protobufjs/protobuf.js/issues/748#issuecomment-291925749))
201
+
202
+ Examples
203
+ --------
204
+
205
+ ### Using .proto files
206
+
207
+ It is possible to load existing .proto files using the full library, which parses and compiles the definitions to ready to use (reflection-based) message classes:
208
+
209
+ ```protobuf
210
+ // awesome.proto
211
+ package awesomepackage;
212
+ syntax = "proto3";
213
+
214
+ message AwesomeMessage {
215
+ string awesome_field = 1; // becomes awesomeField
216
+ }
217
+ ```
218
+
219
+ ```js
220
+ protobuf.load("awesome.proto", function(err, root) {
221
+ if (err)
222
+ throw err;
223
+
224
+ // Obtain a message type
225
+ var AwesomeMessage = root.lookupType("awesomepackage.AwesomeMessage");
226
+
227
+ // Exemplary payload
228
+ var payload = { awesomeField: "AwesomeString" };
229
+
230
+ // Verify the payload if necessary (i.e. when possibly incomplete or invalid)
231
+ var errMsg = AwesomeMessage.verify(payload);
232
+ if (errMsg)
233
+ throw Error(errMsg);
234
+
235
+ // Create a new message
236
+ var message = AwesomeMessage.create(payload); // or use .fromObject if conversion is necessary
237
+
238
+ // Encode a message to an Uint8Array (browser) or Buffer (node)
239
+ var buffer = AwesomeMessage.encode(message).finish();
240
+ // ... do something with buffer
241
+
242
+ // Decode an Uint8Array (browser) or Buffer (node) to a message
243
+ var message = AwesomeMessage.decode(buffer);
244
+ // ... do something with message
245
+
246
+ // If the application uses length-delimited buffers, there is also encodeDelimited and decodeDelimited.
247
+
248
+ // Maybe convert the message back to a plain object
249
+ var object = AwesomeMessage.toObject(message, {
250
+ longs: String,
251
+ enums: String,
252
+ bytes: String,
253
+ // see ConversionOptions
254
+ });
255
+ });
256
+ ```
257
+
258
+ Additionally, promise syntax can be used by omitting the callback, if preferred:
259
+
260
+ ```js
261
+ protobuf.load("awesome.proto")
262
+ .then(function(root) {
263
+ ...
264
+ });
265
+ ```
266
+
267
+ ### Using JSON descriptors
268
+
269
+ The library utilizes JSON descriptors that are equivalent to a .proto definition. For example, the following is identical to the .proto definition seen above:
270
+
271
+ ```json
272
+ // awesome.json
273
+ {
274
+ "nested": {
275
+ "awesomepackage": {
276
+ "nested": {
277
+ "AwesomeMessage": {
278
+ "fields": {
279
+ "awesomeField": {
280
+ "type": "string",
281
+ "id": 1
282
+ }
283
+ }
284
+ }
285
+ }
286
+ }
287
+ }
288
+ }
289
+ ```
290
+
291
+ JSON descriptors closely resemble the internal reflection structure:
292
+
293
+ | Type (T) | Extends | Type-specific properties
294
+ |--------------------|--------------------|-------------------------
295
+ | *ReflectionObject* | | options
296
+ | *Namespace* | *ReflectionObject* | nested
297
+ | Root | *Namespace* | **nested**
298
+ | Type | *Namespace* | **fields**
299
+ | Enum | *ReflectionObject* | **values**
300
+ | Field | *ReflectionObject* | rule, **type**, **id**
301
+ | MapField | Field | **keyType**
302
+ | OneOf | *ReflectionObject* | **oneof** (array of field names)
303
+ | Service | *Namespace* | **methods**
304
+ | Method | *ReflectionObject* | type, **requestType**, **responseType**, requestStream, responseStream
305
+
306
+ * **Bold properties** are required. *Italic types* are abstract.
307
+ * `T.fromJSON(name, json)` creates the respective reflection object from a JSON descriptor
308
+ * `T#toJSON()` creates a JSON descriptor from the respective reflection object (its name is used as the key within the parent)
309
+
310
+ Exclusively using JSON descriptors instead of .proto files enables the use of just the light library (the parser isn't required in this case).
311
+
312
+ A JSON descriptor can either be loaded the usual way:
313
+
314
+ ```js
315
+ protobuf.load("awesome.json", function(err, root) {
316
+ if (err) throw err;
317
+
318
+ // Continue at "Obtain a message type" above
319
+ });
320
+ ```
321
+
322
+ Or it can be loaded inline:
323
+
324
+ ```js
325
+ var jsonDescriptor = require("./awesome.json"); // exemplary for node
326
+
327
+ var root = protobuf.Root.fromJSON(jsonDescriptor);
328
+
329
+ // Continue at "Obtain a message type" above
330
+ ```
331
+
332
+ ### Using reflection only
333
+
334
+ Both the full and the light library include full reflection support. One could, for example, define the .proto definitions seen in the examples above using just reflection:
335
+
336
+ ```js
337
+ ...
338
+ var Root = protobuf.Root,
339
+ Type = protobuf.Type,
340
+ Field = protobuf.Field;
341
+
342
+ var AwesomeMessage = new Type("AwesomeMessage").add(new Field("awesomeField", 1, "string"));
343
+
344
+ var root = new Root().define("awesomepackage").add(AwesomeMessage);
345
+
346
+ // Continue at "Create a new message" above
347
+ ...
348
+ ```
349
+
350
+ Detailed information on the reflection structure is available within the [API documentation](#additional-documentation).
351
+
352
+ ### Using custom classes
353
+
354
+ Message classes can also be extended with custom functionality and it is also possible to register a custom constructor with a reflected message type:
355
+
356
+ ```js
357
+ ...
358
+
359
+ // Define a custom constructor
360
+ function AwesomeMessage(properties) {
361
+ // custom initialization code
362
+ ...
363
+ }
364
+
365
+ // Register the custom constructor with its reflected type (*)
366
+ root.lookupType("awesomepackage.AwesomeMessage").ctor = AwesomeMessage;
367
+
368
+ // Define custom functionality
369
+ AwesomeMessage.customStaticMethod = function() { ... };
370
+ AwesomeMessage.prototype.customInstanceMethod = function() { ... };
371
+
372
+ // Continue at "Create a new message" above
373
+ ```
374
+
375
+ (*) Besides referencing its reflected type through `AwesomeMessage.$type` and `AwesomeMesage#$type`, the respective custom class is automatically populated with:
376
+
377
+ * `AwesomeMessage.create`
378
+ * `AwesomeMessage.encode` and `AwesomeMessage.encodeDelimited`
379
+ * `AwesomeMessage.decode` and `AwesomeMessage.decodeDelimited`
380
+ * `AwesomeMessage.verify`
381
+ * `AwesomeMessage.fromObject`, `AwesomeMessage.toObject` and `AwesomeMessage#toJSON`
382
+
383
+ Afterwards, decoded messages of this type are `instanceof AwesomeMessage`.
384
+
385
+ Alternatively, it is also possible to reuse and extend the internal constructor if custom initialization code is not required:
386
+
387
+ ```js
388
+ ...
389
+
390
+ // Reuse the internal constructor
391
+ var AwesomeMessage = root.lookupType("awesomepackage.AwesomeMessage").ctor;
392
+
393
+ // Define custom functionality
394
+ AwesomeMessage.customStaticMethod = function() { ... };
395
+ AwesomeMessage.prototype.customInstanceMethod = function() { ... };
396
+
397
+ // Continue at "Create a new message" above
398
+ ```
399
+
400
+ ### Using services
401
+
402
+ The library also supports consuming services but it doesn't make any assumptions about the actual transport channel. Instead, a user must provide a suitable RPC implementation, which is an asynchronous function that takes the reflected service method, the binary request and a node-style callback as its parameters:
403
+
404
+ ```js
405
+ function rpcImpl(method, requestData, callback) {
406
+ // perform the request using an HTTP request or a WebSocket for example
407
+ var responseData = ...;
408
+ // and call the callback with the binary response afterwards:
409
+ callback(null, responseData);
410
+ }
411
+ ```
412
+
413
+ Below is a working example with a typescript implementation using grpc npm package.
414
+ ```ts
415
+ const grpc = require('grpc')
416
+
417
+ const Client = grpc.makeGenericClientConstructor({})
418
+ const client = new Client(
419
+ grpcServerUrl,
420
+ grpc.credentials.createInsecure()
421
+ )
422
+
423
+ const rpcImpl = function(method, requestData, callback) {
424
+ client.makeUnaryRequest(
425
+ method.name,
426
+ arg => arg,
427
+ arg => arg,
428
+ requestData,
429
+ callback
430
+ )
431
+ }
432
+ ```
433
+
434
+ Example:
435
+
436
+ ```protobuf
437
+ // greeter.proto
438
+ syntax = "proto3";
439
+
440
+ service Greeter {
441
+ rpc SayHello (HelloRequest) returns (HelloReply) {}
442
+ }
443
+
444
+ message HelloRequest {
445
+ string name = 1;
446
+ }
447
+
448
+ message HelloReply {
449
+ string message = 1;
450
+ }
451
+ ```
452
+
453
+ ```js
454
+ ...
455
+ var Greeter = root.lookup("Greeter");
456
+ var greeter = Greeter.create(/* see above */ rpcImpl, /* request delimited? */ false, /* response delimited? */ false);
457
+
458
+ greeter.sayHello({ name: 'you' }, function(err, response) {
459
+ console.log('Greeting:', response.message);
460
+ });
461
+ ```
462
+
463
+ Services also support promises:
464
+
465
+ ```js
466
+ greeter.sayHello({ name: 'you' })
467
+ .then(function(response) {
468
+ console.log('Greeting:', response.message);
469
+ });
470
+ ```
471
+
472
+ There is also an [example for streaming RPC](https://github.com/protobufjs/protobuf.js/blob/master/examples/streaming-rpc.js).
473
+
474
+ Note that the service API is meant for clients. Implementing a server-side endpoint pretty much always requires transport channel (i.e. http, websocket, etc.) specific code with the only common denominator being that it decodes and encodes messages.
475
+
476
+ ### Usage with TypeScript
477
+
478
+ The library ships with its own [type definitions](https://github.com/protobufjs/protobuf.js/blob/master/index.d.ts) and modern editors like [Visual Studio Code](https://code.visualstudio.com/) will automatically detect and use them for code completion.
479
+
480
+ The npm package depends on [@types/node](https://www.npmjs.com/package/@types/node) because of `Buffer` and [@types/long](https://www.npmjs.com/package/@types/long) because of `Long`. If you are not building for node and/or not using long.js, it should be safe to exclude them manually.
481
+
482
+ #### Using the JS API
483
+
484
+ The API shown above works pretty much the same with TypeScript. However, because everything is typed, accessing fields on instances of dynamically generated message classes requires either using bracket-notation (i.e. `message["awesomeField"]`) or explicit casts. Alternatively, it is possible to use a [typings file generated for its static counterpart](#pbts-for-typescript).
485
+
486
+ ```ts
487
+ import { load } from "protobufjs"; // respectively "./node_modules/protobufjs"
488
+
489
+ load("awesome.proto", function(err, root) {
490
+ if (err)
491
+ throw err;
492
+
493
+ // example code
494
+ const AwesomeMessage = root.lookupType("awesomepackage.AwesomeMessage");
495
+
496
+ let message = AwesomeMessage.create({ awesomeField: "hello" });
497
+ console.log(`message = ${JSON.stringify(message)}`);
498
+
499
+ let buffer = AwesomeMessage.encode(message).finish();
500
+ console.log(`buffer = ${Array.prototype.toString.call(buffer)}`);
501
+
502
+ let decoded = AwesomeMessage.decode(buffer);
503
+ console.log(`decoded = ${JSON.stringify(decoded)}`);
504
+ });
505
+ ```
506
+
507
+ #### Using generated static code
508
+
509
+ If you generated static code to `bundle.js` using the CLI and its type definitions to `bundle.d.ts`, then you can just do:
510
+
511
+ ```ts
512
+ import { AwesomeMessage } from "./bundle.js";
513
+
514
+ // example code
515
+ let message = AwesomeMessage.create({ awesomeField: "hello" });
516
+ let buffer = AwesomeMessage.encode(message).finish();
517
+ let decoded = AwesomeMessage.decode(buffer);
518
+ ```
519
+
520
+ #### Using decorators
521
+
522
+ The library also includes an early implementation of [decorators](https://www.typescriptlang.org/docs/handbook/decorators.html).
523
+
524
+ **Note** that decorators are an experimental feature in TypeScript and that declaration order is important depending on the JS target. For example, `@Field.d(2, AwesomeArrayMessage)` requires that `AwesomeArrayMessage` has been defined earlier when targeting `ES5`.
525
+
526
+ ```ts
527
+ import { Message, Type, Field, OneOf } from "protobufjs/light"; // respectively "./node_modules/protobufjs/light.js"
528
+
529
+ export class AwesomeSubMessage extends Message<AwesomeSubMessage> {
530
+
531
+ @Field.d(1, "string")
532
+ public awesomeString: string;
533
+
534
+ }
535
+
536
+ export enum AwesomeEnum {
537
+ ONE = 1,
538
+ TWO = 2
539
+ }
540
+
541
+ @Type.d("SuperAwesomeMessage")
542
+ export class AwesomeMessage extends Message<AwesomeMessage> {
543
+
544
+ @Field.d(1, "string", "optional", "awesome default string")
545
+ public awesomeField: string;
546
+
547
+ @Field.d(2, AwesomeSubMessage)
548
+ public awesomeSubMessage: AwesomeSubMessage;
549
+
550
+ @Field.d(3, AwesomeEnum, "optional", AwesomeEnum.ONE)
551
+ public awesomeEnum: AwesomeEnum;
552
+
553
+ @OneOf.d("awesomeSubMessage", "awesomeEnum")
554
+ public which: string;
555
+
556
+ }
557
+
558
+ // example code
559
+ let message = new AwesomeMessage({ awesomeField: "hello" });
560
+ let buffer = AwesomeMessage.encode(message).finish();
561
+ let decoded = AwesomeMessage.decode(buffer);
562
+ ```
563
+
564
+ Supported decorators are:
565
+
566
+ * **Type.d(typeName?: `string`)** &nbsp; *(optional)*<br />
567
+ annotates a class as a protobuf message type. If `typeName` is not specified, the constructor's runtime function name is used for the reflected type.
568
+
569
+ * **Field.d&lt;T>(fieldId: `number`, fieldType: `string | Constructor<T>`, fieldRule?: `"optional" | "required" | "repeated"`, defaultValue?: `T`)**<br />
570
+ annotates a property as a protobuf field with the specified id and protobuf type.
571
+
572
+ * **MapField.d&lt;T extends { [key: string]: any }>(fieldId: `number`, fieldKeyType: `string`, fieldValueType. `string | Constructor<{}>`)**<br />
573
+ annotates a property as a protobuf map field with the specified id, protobuf key and value type.
574
+
575
+ * **OneOf.d&lt;T extends string>(...fieldNames: `string[]`)**<br />
576
+ annotates a property as a protobuf oneof covering the specified fields.
577
+
578
+ Other notes:
579
+
580
+ * Decorated types reside in `protobuf.roots["decorated"]` using a flat structure, so no duplicate names.
581
+ * Enums are copied to a reflected enum with a generic name on decorator evaluation because referenced enum objects have no runtime name the decorator could use.
582
+ * Default values must be specified as arguments to the decorator instead of using a property initializer for proper prototype behavior.
583
+ * Property names on decorated classes must not be renamed on compile time (i.e. by a minifier) because decorators just receive the original field name as a string.
584
+
585
+ **ProTip!** Not as pretty, but you can [use decorators in plain JavaScript](https://github.com/protobufjs/protobuf.js/blob/master/examples/js-decorators.js) as well.
586
+
587
+ Additional documentation
588
+ ------------------------
589
+
590
+ #### Protocol Buffers
591
+ * [Google's Developer Guide](https://protobuf.dev/overview/)
592
+
593
+ #### protobuf.js
594
+ * [API Documentation](https://protobufjs.github.io/protobuf.js)
595
+ * [CHANGELOG](https://github.com/protobufjs/protobuf.js/blob/master/CHANGELOG.md)
596
+ * [Frequently asked questions](https://github.com/protobufjs/protobuf.js/wiki) on our wiki
597
+
598
+ #### Community
599
+ * [Questions and answers](http://stackoverflow.com/search?tab=newest&q=protobuf.js) on StackOverflow
600
+
601
+ Performance
602
+ -----------
603
+ The package includes a benchmark that compares protobuf.js performance to native JSON (as far as this is possible) and [Google's JS implementation](https://github.com/google/protobuf/tree/master/js). On an i7-2600K running node 6.9.1 it yields:
604
+
605
+ ```
606
+ benchmarking encoding performance ...
607
+
608
+ protobuf.js (reflect) x 541,707 ops/sec ±1.13% (87 runs sampled)
609
+ protobuf.js (static) x 548,134 ops/sec ±1.38% (89 runs sampled)
610
+ JSON (string) x 318,076 ops/sec ±0.63% (93 runs sampled)
611
+ JSON (buffer) x 179,165 ops/sec ±2.26% (91 runs sampled)
612
+ google-protobuf x 74,406 ops/sec ±0.85% (86 runs sampled)
613
+
614
+ protobuf.js (static) was fastest
615
+ protobuf.js (reflect) was 0.9% ops/sec slower (factor 1.0)
616
+ JSON (string) was 41.5% ops/sec slower (factor 1.7)
617
+ JSON (buffer) was 67.6% ops/sec slower (factor 3.1)
618
+ google-protobuf was 86.4% ops/sec slower (factor 7.3)
619
+
620
+ benchmarking decoding performance ...
621
+
622
+ protobuf.js (reflect) x 1,383,981 ops/sec ±0.88% (93 runs sampled)
623
+ protobuf.js (static) x 1,378,925 ops/sec ±0.81% (93 runs sampled)
624
+ JSON (string) x 302,444 ops/sec ±0.81% (93 runs sampled)
625
+ JSON (buffer) x 264,882 ops/sec ±0.81% (93 runs sampled)
626
+ google-protobuf x 179,180 ops/sec ±0.64% (94 runs sampled)
627
+
628
+ protobuf.js (reflect) was fastest
629
+ protobuf.js (static) was 0.3% ops/sec slower (factor 1.0)
630
+ JSON (string) was 78.1% ops/sec slower (factor 4.6)
631
+ JSON (buffer) was 80.8% ops/sec slower (factor 5.2)
632
+ google-protobuf was 87.0% ops/sec slower (factor 7.7)
633
+
634
+ benchmarking combined performance ...
635
+
636
+ protobuf.js (reflect) x 275,900 ops/sec ±0.78% (90 runs sampled)
637
+ protobuf.js (static) x 290,096 ops/sec ±0.96% (90 runs sampled)
638
+ JSON (string) x 129,381 ops/sec ±0.77% (90 runs sampled)
639
+ JSON (buffer) x 91,051 ops/sec ±0.94% (90 runs sampled)
640
+ google-protobuf x 42,050 ops/sec ±0.85% (91 runs sampled)
641
+
642
+ protobuf.js (static) was fastest
643
+ protobuf.js (reflect) was 4.7% ops/sec slower (factor 1.0)
644
+ JSON (string) was 55.3% ops/sec slower (factor 2.2)
645
+ JSON (buffer) was 68.6% ops/sec slower (factor 3.2)
646
+ google-protobuf was 85.5% ops/sec slower (factor 6.9)
647
+ ```
648
+
649
+ These results are achieved by
650
+
651
+ * generating type-specific encoders, decoders, verifiers and converters at runtime
652
+ * configuring the reader/writer interface according to the environment
653
+ * using node-specific functionality where beneficial and, of course
654
+ * avoiding unnecessary operations through splitting up [the toolset](#toolset).
655
+
656
+ You can also run [the benchmark](https://github.com/protobufjs/protobuf.js/blob/master/bench/index.js) ...
657
+
658
+ ```
659
+ $> npm run bench
660
+ ```
661
+
662
+ and [the profiler](https://github.com/protobufjs/protobuf.js/blob/master/bench/prof.js) yourself (the latter requires a recent version of node):
663
+
664
+ ```
665
+ $> npm run prof <encode|decode|encode-browser|decode-browser> [iterations=10000000]
666
+ ```
667
+
668
+ Note that as of this writing, the benchmark suite performs significantly slower on node 7.2.0 compared to 6.9.1 because moths.
669
+
670
+ Compatibility
671
+ -------------
672
+
673
+ * Works in all modern and not-so-modern browsers except IE8.
674
+ * Because the internals of this package do not rely on `google/protobuf/descriptor.proto`, options are parsed and presented literally.
675
+ * If typed arrays are not supported by the environment, plain arrays will be used instead.
676
+ * Support for pre-ES5 environments (except IE8) can be achieved by [using a polyfill](https://github.com/protobufjs/protobuf.js/blob/master/lib/polyfill.js).
677
+ * Support for [Content Security Policy](https://w3c.github.io/webappsec-csp/)-restricted environments (like Chrome extensions without unsafe-eval) can be achieved by generating and using static code instead.
678
+ * If a proper way to work with 64 bit values (uint64, int64 etc.) is required, just install [long.js](https://github.com/dcodeIO/long.js) alongside this library. All 64 bit numbers will then be returned as a `Long` instance instead of a possibly unsafe JavaScript number ([see](https://github.com/dcodeIO/long.js)).
679
+ * For descriptor.proto interoperability, see [ext/descriptor](https://github.com/protobufjs/protobuf.js/tree/master/ext/descriptor)
680
+
681
+ Building
682
+ --------
683
+
684
+ To build the library or its components yourself, clone it from GitHub and install the development dependencies:
685
+
686
+ ```
687
+ $> git clone https://github.com/protobufjs/protobuf.js.git
688
+ $> cd protobuf.js
689
+ $> npm install
690
+ ```
691
+
692
+ Building the respective development and production versions with their respective source maps to `dist/`:
693
+
694
+ ```
695
+ $> npm run build
696
+ ```
697
+
698
+ Building the documentation to `docs/`:
699
+
700
+ ```
701
+ $> npm run docs
702
+ ```
703
+
704
+ Building the TypeScript definition to `index.d.ts`:
705
+
706
+ ```
707
+ $> npm run build:types
708
+ ```
709
+
710
+ ### Browserify integration
711
+
712
+ By default, protobuf.js integrates into any browserify build-process without requiring any optional modules. Hence:
713
+
714
+ * If int64 support is required, explicitly require the `long` module somewhere in your project as it will be excluded otherwise. This assumes that a global `require` function is present that protobuf.js can call to obtain the long module.
715
+
716
+ If there is no global `require` function present after bundling, it's also possible to assign the long module programmatically:
717
+
718
+ ```js
719
+ var Long = ...;
720
+
721
+ protobuf.util.Long = Long;
722
+ protobuf.configure();
723
+ ```
724
+
725
+ * If you have any special requirements, there is [the bundler](https://github.com/protobufjs/protobuf.js/blob/master/scripts/bundle.js) for reference.
726
+
727
+ **License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause)