lordceaser-baileys 3.4.2 → 3.4.6

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 (301) hide show
  1. package/WAProto/index.js +115856 -5
  2. package/WAProto/package.json +1 -0
  3. package/index.js +37 -21
  4. package/lib/Utils/crypto.js +118 -8
  5. package/lib/Utils/lt-hash.js +8 -3
  6. package/lib/package.json +3 -0
  7. package/node_modules/@protobufjs/aspromise/LICENSE +26 -0
  8. package/node_modules/@protobufjs/aspromise/README.md +13 -0
  9. package/node_modules/@protobufjs/aspromise/index.d.ts +13 -0
  10. package/node_modules/@protobufjs/aspromise/index.js +52 -0
  11. package/node_modules/@protobufjs/aspromise/package.json +21 -0
  12. package/node_modules/@protobufjs/aspromise/tests/index.js +130 -0
  13. package/node_modules/@protobufjs/base64/LICENSE +26 -0
  14. package/node_modules/@protobufjs/base64/README.md +19 -0
  15. package/node_modules/@protobufjs/base64/index.d.ts +32 -0
  16. package/node_modules/@protobufjs/base64/index.js +139 -0
  17. package/node_modules/@protobufjs/base64/package.json +21 -0
  18. package/node_modules/@protobufjs/base64/tests/index.js +46 -0
  19. package/node_modules/@protobufjs/codegen/LICENSE +26 -0
  20. package/node_modules/@protobufjs/codegen/README.md +49 -0
  21. package/node_modules/@protobufjs/codegen/index.d.ts +31 -0
  22. package/node_modules/@protobufjs/codegen/index.js +112 -0
  23. package/node_modules/@protobufjs/codegen/package.json +13 -0
  24. package/node_modules/@protobufjs/codegen/tests/index.js +13 -0
  25. package/node_modules/@protobufjs/eventemitter/CHANGELOG.md +8 -0
  26. package/node_modules/@protobufjs/eventemitter/LICENSE +26 -0
  27. package/node_modules/@protobufjs/eventemitter/README.md +22 -0
  28. package/node_modules/@protobufjs/eventemitter/index.d.ts +45 -0
  29. package/node_modules/@protobufjs/eventemitter/index.js +86 -0
  30. package/node_modules/@protobufjs/eventemitter/package.json +21 -0
  31. package/node_modules/@protobufjs/eventemitter/tests/index.js +83 -0
  32. package/node_modules/@protobufjs/fetch/CHANGELOG.md +8 -0
  33. package/node_modules/@protobufjs/fetch/LICENSE +26 -0
  34. package/node_modules/@protobufjs/fetch/README.md +13 -0
  35. package/node_modules/@protobufjs/fetch/index.d.ts +56 -0
  36. package/node_modules/@protobufjs/fetch/index.js +112 -0
  37. package/node_modules/@protobufjs/fetch/package.json +27 -0
  38. package/node_modules/@protobufjs/fetch/tests/data/file.txt +1 -0
  39. package/node_modules/@protobufjs/fetch/tests/index.js +158 -0
  40. package/node_modules/@protobufjs/fetch/util/fs.js +11 -0
  41. package/node_modules/@protobufjs/float/LICENSE +26 -0
  42. package/node_modules/@protobufjs/float/README.md +102 -0
  43. package/node_modules/@protobufjs/float/bench/index.js +87 -0
  44. package/node_modules/@protobufjs/float/bench/suite.js +46 -0
  45. package/node_modules/@protobufjs/float/index.d.ts +83 -0
  46. package/node_modules/@protobufjs/float/index.js +335 -0
  47. package/node_modules/@protobufjs/float/package.json +26 -0
  48. package/node_modules/@protobufjs/float/tests/index.js +100 -0
  49. package/node_modules/@protobufjs/path/LICENSE +26 -0
  50. package/node_modules/@protobufjs/path/README.md +19 -0
  51. package/node_modules/@protobufjs/path/index.d.ts +22 -0
  52. package/node_modules/@protobufjs/path/index.js +65 -0
  53. package/node_modules/@protobufjs/path/package.json +21 -0
  54. package/node_modules/@protobufjs/path/tests/index.js +60 -0
  55. package/node_modules/@protobufjs/pool/.npmignore +3 -0
  56. package/node_modules/@protobufjs/pool/LICENSE +26 -0
  57. package/node_modules/@protobufjs/pool/README.md +13 -0
  58. package/node_modules/@protobufjs/pool/index.d.ts +32 -0
  59. package/node_modules/@protobufjs/pool/index.js +48 -0
  60. package/node_modules/@protobufjs/pool/package.json +21 -0
  61. package/node_modules/@protobufjs/pool/tests/index.js +33 -0
  62. package/node_modules/@protobufjs/utf8/CHANGELOG.md +8 -0
  63. package/node_modules/@protobufjs/utf8/LICENSE +26 -0
  64. package/node_modules/@protobufjs/utf8/README.md +20 -0
  65. package/node_modules/@protobufjs/utf8/index.d.ts +24 -0
  66. package/node_modules/@protobufjs/utf8/index.js +115 -0
  67. package/node_modules/@protobufjs/utf8/package.json +21 -0
  68. package/node_modules/@protobufjs/utf8/tests/data/surrogate_pair_bug.txt +207 -0
  69. package/node_modules/@protobufjs/utf8/tests/data/utf8.txt +216 -0
  70. package/node_modules/@protobufjs/utf8/tests/index.js +79 -0
  71. package/node_modules/@types/node/LICENSE +21 -0
  72. package/node_modules/@types/node/README.md +15 -0
  73. package/node_modules/@types/node/assert/strict.d.ts +8 -0
  74. package/node_modules/@types/node/assert.d.ts +1062 -0
  75. package/node_modules/@types/node/async_hooks.d.ts +605 -0
  76. package/node_modules/@types/node/buffer.buffer.d.ts +471 -0
  77. package/node_modules/@types/node/buffer.d.ts +1936 -0
  78. package/node_modules/@types/node/child_process.d.ts +1475 -0
  79. package/node_modules/@types/node/cluster.d.ts +577 -0
  80. package/node_modules/@types/node/compatibility/disposable.d.ts +16 -0
  81. package/node_modules/@types/node/compatibility/index.d.ts +9 -0
  82. package/node_modules/@types/node/compatibility/indexable.d.ts +20 -0
  83. package/node_modules/@types/node/compatibility/iterators.d.ts +21 -0
  84. package/node_modules/@types/node/console.d.ts +452 -0
  85. package/node_modules/@types/node/constants.d.ts +21 -0
  86. package/node_modules/@types/node/crypto.d.ts +4590 -0
  87. package/node_modules/@types/node/dgram.d.ts +597 -0
  88. package/node_modules/@types/node/diagnostics_channel.d.ts +578 -0
  89. package/node_modules/@types/node/dns/promises.d.ts +479 -0
  90. package/node_modules/@types/node/dns.d.ts +871 -0
  91. package/node_modules/@types/node/domain.d.ts +170 -0
  92. package/node_modules/@types/node/events.d.ts +977 -0
  93. package/node_modules/@types/node/fs/promises.d.ts +1270 -0
  94. package/node_modules/@types/node/fs.d.ts +4375 -0
  95. package/node_modules/@types/node/globals.d.ts +172 -0
  96. package/node_modules/@types/node/globals.typedarray.d.ts +38 -0
  97. package/node_modules/@types/node/http.d.ts +2049 -0
  98. package/node_modules/@types/node/http2.d.ts +2712 -0
  99. package/node_modules/@types/node/https.d.ts +578 -0
  100. package/node_modules/@types/node/index.d.ts +93 -0
  101. package/node_modules/@types/node/inspector.generated.d.ts +3966 -0
  102. package/node_modules/@types/node/module.d.ts +539 -0
  103. package/node_modules/@types/node/net.d.ts +1031 -0
  104. package/node_modules/@types/node/os.d.ts +506 -0
  105. package/node_modules/@types/node/package.json +140 -0
  106. package/node_modules/@types/node/path.d.ts +200 -0
  107. package/node_modules/@types/node/perf_hooks.d.ts +961 -0
  108. package/node_modules/@types/node/process.d.ts +1961 -0
  109. package/node_modules/@types/node/punycode.d.ts +117 -0
  110. package/node_modules/@types/node/querystring.d.ts +152 -0
  111. package/node_modules/@types/node/readline/promises.d.ts +162 -0
  112. package/node_modules/@types/node/readline.d.ts +589 -0
  113. package/node_modules/@types/node/repl.d.ts +430 -0
  114. package/node_modules/@types/node/sea.d.ts +153 -0
  115. package/node_modules/@types/node/stream/consumers.d.ts +38 -0
  116. package/node_modules/@types/node/stream/promises.d.ts +90 -0
  117. package/node_modules/@types/node/stream/web.d.ts +533 -0
  118. package/node_modules/@types/node/stream.d.ts +1698 -0
  119. package/node_modules/@types/node/string_decoder.d.ts +67 -0
  120. package/node_modules/@types/node/test.d.ts +1787 -0
  121. package/node_modules/@types/node/timers/promises.d.ts +108 -0
  122. package/node_modules/@types/node/timers.d.ts +286 -0
  123. package/node_modules/@types/node/tls.d.ts +1259 -0
  124. package/node_modules/@types/node/trace_events.d.ts +197 -0
  125. package/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +468 -0
  126. package/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +34 -0
  127. package/node_modules/@types/node/ts5.6/index.d.ts +93 -0
  128. package/node_modules/@types/node/tty.d.ts +208 -0
  129. package/node_modules/@types/node/url.d.ts +964 -0
  130. package/node_modules/@types/node/util.d.ts +2331 -0
  131. package/node_modules/@types/node/v8.d.ts +809 -0
  132. package/node_modules/@types/node/vm.d.ts +1001 -0
  133. package/node_modules/@types/node/wasi.d.ts +181 -0
  134. package/node_modules/@types/node/web-globals/abortcontroller.d.ts +34 -0
  135. package/node_modules/@types/node/web-globals/domexception.d.ts +68 -0
  136. package/node_modules/@types/node/web-globals/events.d.ts +97 -0
  137. package/node_modules/@types/node/web-globals/fetch.d.ts +55 -0
  138. package/node_modules/@types/node/worker_threads.d.ts +715 -0
  139. package/node_modules/@types/node/zlib.d.ts +598 -0
  140. package/node_modules/curve25519-js/.prettierrc +6 -0
  141. package/node_modules/curve25519-js/LICENSE +19 -0
  142. package/node_modules/curve25519-js/README.md +111 -0
  143. package/node_modules/curve25519-js/lib/index.d.ts +69 -0
  144. package/node_modules/curve25519-js/lib/index.js +1669 -0
  145. package/node_modules/curve25519-js/package.json +34 -0
  146. package/node_modules/curve25519-js/tsconfig.json +20 -0
  147. package/node_modules/curve25519-js/tslint.json +10 -0
  148. package/node_modules/libsignal/LICENSE +621 -0
  149. package/node_modules/libsignal/README.md +64 -0
  150. package/node_modules/libsignal/index.d.ts +55 -0
  151. package/node_modules/libsignal/index.js +10 -0
  152. package/node_modules/libsignal/package.json +34 -0
  153. package/node_modules/libsignal/src/.eslintrc.json +31 -0
  154. package/node_modules/libsignal/src/WhisperTextProtocol.js +933 -0
  155. package/node_modules/libsignal/src/base_key_type.js +7 -0
  156. package/node_modules/libsignal/src/chain_type.js +6 -0
  157. package/node_modules/libsignal/src/crypto.d.ts +19 -0
  158. package/node_modules/libsignal/src/crypto.js +98 -0
  159. package/node_modules/libsignal/src/curve.d.ts +22 -0
  160. package/node_modules/libsignal/src/curve.js +142 -0
  161. package/node_modules/libsignal/src/errors.js +33 -0
  162. package/node_modules/libsignal/src/keyhelper.js +45 -0
  163. package/node_modules/libsignal/src/numeric_fingerprint.js +72 -0
  164. package/node_modules/libsignal/src/protobufs.js +10 -0
  165. package/node_modules/libsignal/src/protocol_address.js +40 -0
  166. package/node_modules/libsignal/src/queue_job.js +69 -0
  167. package/node_modules/libsignal/src/session_builder.js +164 -0
  168. package/node_modules/libsignal/src/session_cipher.js +336 -0
  169. package/node_modules/libsignal/src/session_record.js +316 -0
  170. package/node_modules/long/LICENSE +202 -0
  171. package/node_modules/long/README.md +286 -0
  172. package/node_modules/long/index.d.ts +2 -0
  173. package/node_modules/long/index.js +1581 -0
  174. package/node_modules/long/package.json +58 -0
  175. package/node_modules/long/types.d.ts +474 -0
  176. package/node_modules/long/umd/index.d.ts +3 -0
  177. package/node_modules/long/umd/index.js +1622 -0
  178. package/node_modules/long/umd/package.json +3 -0
  179. package/node_modules/long/umd/types.d.ts +474 -0
  180. package/node_modules/protobufjs/LICENSE +39 -0
  181. package/node_modules/protobufjs/README.md +727 -0
  182. package/node_modules/protobufjs/dist/light/protobuf.js +8094 -0
  183. package/node_modules/protobufjs/dist/light/protobuf.js.map +1 -0
  184. package/node_modules/protobufjs/dist/light/protobuf.min.js +8 -0
  185. package/node_modules/protobufjs/dist/light/protobuf.min.js.map +1 -0
  186. package/node_modules/protobufjs/dist/minimal/protobuf.js +2811 -0
  187. package/node_modules/protobufjs/dist/minimal/protobuf.js.map +1 -0
  188. package/node_modules/protobufjs/dist/minimal/protobuf.min.js +8 -0
  189. package/node_modules/protobufjs/dist/minimal/protobuf.min.js.map +1 -0
  190. package/node_modules/protobufjs/dist/protobuf.js +9921 -0
  191. package/node_modules/protobufjs/dist/protobuf.js.map +1 -0
  192. package/node_modules/protobufjs/dist/protobuf.min.js +8 -0
  193. package/node_modules/protobufjs/dist/protobuf.min.js.map +1 -0
  194. package/node_modules/protobufjs/ext/debug/README.md +4 -0
  195. package/node_modules/protobufjs/ext/debug/index.js +71 -0
  196. package/node_modules/protobufjs/ext/descriptor/README.md +72 -0
  197. package/node_modules/protobufjs/ext/descriptor/index.d.ts +195 -0
  198. package/node_modules/protobufjs/ext/descriptor/index.js +1186 -0
  199. package/node_modules/protobufjs/ext/descriptor/test.js +54 -0
  200. package/node_modules/protobufjs/google/LICENSE +27 -0
  201. package/node_modules/protobufjs/google/README.md +1 -0
  202. package/node_modules/protobufjs/google/api/annotations.json +83 -0
  203. package/node_modules/protobufjs/google/api/annotations.proto +11 -0
  204. package/node_modules/protobufjs/google/api/http.json +86 -0
  205. package/node_modules/protobufjs/google/api/http.proto +31 -0
  206. package/node_modules/protobufjs/google/protobuf/api.json +118 -0
  207. package/node_modules/protobufjs/google/protobuf/api.proto +34 -0
  208. package/node_modules/protobufjs/google/protobuf/descriptor.json +1382 -0
  209. package/node_modules/protobufjs/google/protobuf/descriptor.proto +535 -0
  210. package/node_modules/protobufjs/google/protobuf/source_context.json +20 -0
  211. package/node_modules/protobufjs/google/protobuf/source_context.proto +7 -0
  212. package/node_modules/protobufjs/google/protobuf/type.json +202 -0
  213. package/node_modules/protobufjs/google/protobuf/type.proto +89 -0
  214. package/node_modules/protobufjs/index.d.ts +2832 -0
  215. package/node_modules/protobufjs/index.js +4 -0
  216. package/node_modules/protobufjs/light.d.ts +2 -0
  217. package/node_modules/protobufjs/light.js +4 -0
  218. package/node_modules/protobufjs/minimal.d.ts +2 -0
  219. package/node_modules/protobufjs/minimal.js +4 -0
  220. package/node_modules/protobufjs/package.json +119 -0
  221. package/node_modules/protobufjs/scripts/postinstall.js +32 -0
  222. package/node_modules/protobufjs/src/common.js +399 -0
  223. package/node_modules/protobufjs/src/converter.js +318 -0
  224. package/node_modules/protobufjs/src/decoder.js +164 -0
  225. package/node_modules/protobufjs/src/encoder.js +103 -0
  226. package/node_modules/protobufjs/src/enum.js +226 -0
  227. package/node_modules/protobufjs/src/field.js +453 -0
  228. package/node_modules/protobufjs/src/index-light.js +104 -0
  229. package/node_modules/protobufjs/src/index-minimal.js +36 -0
  230. package/node_modules/protobufjs/src/index.js +12 -0
  231. package/node_modules/protobufjs/src/mapfield.js +126 -0
  232. package/node_modules/protobufjs/src/message.js +143 -0
  233. package/node_modules/protobufjs/src/method.js +160 -0
  234. package/node_modules/protobufjs/src/namespace.js +558 -0
  235. package/node_modules/protobufjs/src/object.js +382 -0
  236. package/node_modules/protobufjs/src/oneof.js +222 -0
  237. package/node_modules/protobufjs/src/parse.js +992 -0
  238. package/node_modules/protobufjs/src/reader.js +446 -0
  239. package/node_modules/protobufjs/src/reader_buffer.js +51 -0
  240. package/node_modules/protobufjs/src/root.js +412 -0
  241. package/node_modules/protobufjs/src/roots.js +18 -0
  242. package/node_modules/protobufjs/src/rpc/service.js +142 -0
  243. package/node_modules/protobufjs/src/rpc.js +36 -0
  244. package/node_modules/protobufjs/src/service.js +193 -0
  245. package/node_modules/protobufjs/src/tokenize.js +416 -0
  246. package/node_modules/protobufjs/src/type.js +632 -0
  247. package/node_modules/protobufjs/src/types.js +196 -0
  248. package/node_modules/protobufjs/src/typescript.jsdoc +15 -0
  249. package/node_modules/protobufjs/src/util/fs.js +11 -0
  250. package/node_modules/protobufjs/src/util/longbits.js +200 -0
  251. package/node_modules/protobufjs/src/util/minimal.js +491 -0
  252. package/node_modules/protobufjs/src/util/patterns.js +7 -0
  253. package/node_modules/protobufjs/src/util.js +230 -0
  254. package/node_modules/protobufjs/src/verifier.js +180 -0
  255. package/node_modules/protobufjs/src/wrappers.js +111 -0
  256. package/node_modules/protobufjs/src/writer.js +467 -0
  257. package/node_modules/protobufjs/src/writer_buffer.js +85 -0
  258. package/node_modules/protobufjs/tsconfig.json +8 -0
  259. package/node_modules/undici-types/LICENSE +21 -0
  260. package/node_modules/undici-types/README.md +6 -0
  261. package/node_modules/undici-types/agent.d.ts +31 -0
  262. package/node_modules/undici-types/api.d.ts +43 -0
  263. package/node_modules/undici-types/balanced-pool.d.ts +29 -0
  264. package/node_modules/undici-types/cache.d.ts +36 -0
  265. package/node_modules/undici-types/client.d.ts +108 -0
  266. package/node_modules/undici-types/connector.d.ts +34 -0
  267. package/node_modules/undici-types/content-type.d.ts +21 -0
  268. package/node_modules/undici-types/cookies.d.ts +28 -0
  269. package/node_modules/undici-types/diagnostics-channel.d.ts +66 -0
  270. package/node_modules/undici-types/dispatcher.d.ts +256 -0
  271. package/node_modules/undici-types/env-http-proxy-agent.d.ts +21 -0
  272. package/node_modules/undici-types/errors.d.ts +149 -0
  273. package/node_modules/undici-types/eventsource.d.ts +61 -0
  274. package/node_modules/undici-types/fetch.d.ts +209 -0
  275. package/node_modules/undici-types/file.d.ts +39 -0
  276. package/node_modules/undici-types/filereader.d.ts +54 -0
  277. package/node_modules/undici-types/formdata.d.ts +108 -0
  278. package/node_modules/undici-types/global-dispatcher.d.ts +9 -0
  279. package/node_modules/undici-types/global-origin.d.ts +7 -0
  280. package/node_modules/undici-types/handlers.d.ts +15 -0
  281. package/node_modules/undici-types/header.d.ts +4 -0
  282. package/node_modules/undici-types/index.d.ts +71 -0
  283. package/node_modules/undici-types/interceptors.d.ts +17 -0
  284. package/node_modules/undici-types/mock-agent.d.ts +50 -0
  285. package/node_modules/undici-types/mock-client.d.ts +25 -0
  286. package/node_modules/undici-types/mock-errors.d.ts +12 -0
  287. package/node_modules/undici-types/mock-interceptor.d.ts +93 -0
  288. package/node_modules/undici-types/mock-pool.d.ts +25 -0
  289. package/node_modules/undici-types/package.json +55 -0
  290. package/node_modules/undici-types/patch.d.ts +33 -0
  291. package/node_modules/undici-types/pool-stats.d.ts +19 -0
  292. package/node_modules/undici-types/pool.d.ts +39 -0
  293. package/node_modules/undici-types/proxy-agent.d.ts +28 -0
  294. package/node_modules/undici-types/readable.d.ts +65 -0
  295. package/node_modules/undici-types/retry-agent.d.ts +8 -0
  296. package/node_modules/undici-types/retry-handler.d.ts +116 -0
  297. package/node_modules/undici-types/util.d.ts +18 -0
  298. package/node_modules/undici-types/webidl.d.ts +228 -0
  299. package/node_modules/undici-types/websocket.d.ts +150 -0
  300. package/package.json +65 -29
  301. package/WAProto/_orig.js +0 -115856
@@ -0,0 +1,467 @@
1
+ "use strict";
2
+ module.exports = Writer;
3
+
4
+ var util = require("./util/minimal");
5
+
6
+ var BufferWriter; // cyclic
7
+
8
+ var LongBits = util.LongBits,
9
+ base64 = util.base64,
10
+ utf8 = util.utf8;
11
+
12
+ /**
13
+ * Constructs a new writer operation instance.
14
+ * @classdesc Scheduled writer operation.
15
+ * @constructor
16
+ * @param {function(*, Uint8Array, number)} fn Function to call
17
+ * @param {number} len Value byte length
18
+ * @param {*} val Value to write
19
+ * @ignore
20
+ */
21
+ function Op(fn, len, val) {
22
+
23
+ /**
24
+ * Function to call.
25
+ * @type {function(Uint8Array, number, *)}
26
+ */
27
+ this.fn = fn;
28
+
29
+ /**
30
+ * Value byte length.
31
+ * @type {number}
32
+ */
33
+ this.len = len;
34
+
35
+ /**
36
+ * Next operation.
37
+ * @type {Writer.Op|undefined}
38
+ */
39
+ this.next = undefined;
40
+
41
+ /**
42
+ * Value to write.
43
+ * @type {*}
44
+ */
45
+ this.val = val; // type varies
46
+ }
47
+
48
+ /* istanbul ignore next */
49
+ function noop() {} // eslint-disable-line no-empty-function
50
+
51
+ /**
52
+ * Constructs a new writer state instance.
53
+ * @classdesc Copied writer state.
54
+ * @memberof Writer
55
+ * @constructor
56
+ * @param {Writer} writer Writer to copy state from
57
+ * @ignore
58
+ */
59
+ function State(writer) {
60
+
61
+ /**
62
+ * Current head.
63
+ * @type {Writer.Op}
64
+ */
65
+ this.head = writer.head;
66
+
67
+ /**
68
+ * Current tail.
69
+ * @type {Writer.Op}
70
+ */
71
+ this.tail = writer.tail;
72
+
73
+ /**
74
+ * Current buffer length.
75
+ * @type {number}
76
+ */
77
+ this.len = writer.len;
78
+
79
+ /**
80
+ * Next state.
81
+ * @type {State|null}
82
+ */
83
+ this.next = writer.states;
84
+ }
85
+
86
+ /**
87
+ * Constructs a new writer instance.
88
+ * @classdesc Wire format writer using `Uint8Array` if available, otherwise `Array`.
89
+ * @constructor
90
+ */
91
+ function Writer() {
92
+
93
+ /**
94
+ * Current length.
95
+ * @type {number}
96
+ */
97
+ this.len = 0;
98
+
99
+ /**
100
+ * Operations head.
101
+ * @type {Object}
102
+ */
103
+ this.head = new Op(noop, 0, 0);
104
+
105
+ /**
106
+ * Operations tail
107
+ * @type {Object}
108
+ */
109
+ this.tail = this.head;
110
+
111
+ /**
112
+ * Linked forked states.
113
+ * @type {Object|null}
114
+ */
115
+ this.states = null;
116
+
117
+ // When a value is written, the writer calculates its byte length and puts it into a linked
118
+ // list of operations to perform when finish() is called. This both allows us to allocate
119
+ // buffers of the exact required size and reduces the amount of work we have to do compared
120
+ // to first calculating over objects and then encoding over objects. In our case, the encoding
121
+ // part is just a linked list walk calling operations with already prepared values.
122
+ }
123
+
124
+ var create = function create() {
125
+ return util.Buffer
126
+ ? function create_buffer_setup() {
127
+ return (Writer.create = function create_buffer() {
128
+ return new BufferWriter();
129
+ })();
130
+ }
131
+ /* istanbul ignore next */
132
+ : function create_array() {
133
+ return new Writer();
134
+ };
135
+ };
136
+
137
+ /**
138
+ * Creates a new writer.
139
+ * @function
140
+ * @returns {BufferWriter|Writer} A {@link BufferWriter} when Buffers are supported, otherwise a {@link Writer}
141
+ */
142
+ Writer.create = create();
143
+
144
+ /**
145
+ * Allocates a buffer of the specified size.
146
+ * @param {number} size Buffer size
147
+ * @returns {Uint8Array} Buffer
148
+ */
149
+ Writer.alloc = function alloc(size) {
150
+ return new util.Array(size);
151
+ };
152
+
153
+ // Use Uint8Array buffer pool in the browser, just like node does with buffers
154
+ /* istanbul ignore else */
155
+ if (util.Array !== Array)
156
+ Writer.alloc = util.pool(Writer.alloc, util.Array.prototype.subarray);
157
+
158
+ /**
159
+ * Pushes a new operation to the queue.
160
+ * @param {function(Uint8Array, number, *)} fn Function to call
161
+ * @param {number} len Value byte length
162
+ * @param {number} val Value to write
163
+ * @returns {Writer} `this`
164
+ * @private
165
+ */
166
+ Writer.prototype._push = function push(fn, len, val) {
167
+ this.tail = this.tail.next = new Op(fn, len, val);
168
+ this.len += len;
169
+ return this;
170
+ };
171
+
172
+ function writeByte(val, buf, pos) {
173
+ buf[pos] = val & 255;
174
+ }
175
+
176
+ function writeVarint32(val, buf, pos) {
177
+ while (val > 127) {
178
+ buf[pos++] = val & 127 | 128;
179
+ val >>>= 7;
180
+ }
181
+ buf[pos] = val;
182
+ }
183
+
184
+ /**
185
+ * Constructs a new varint writer operation instance.
186
+ * @classdesc Scheduled varint writer operation.
187
+ * @extends Op
188
+ * @constructor
189
+ * @param {number} len Value byte length
190
+ * @param {number} val Value to write
191
+ * @ignore
192
+ */
193
+ function VarintOp(len, val) {
194
+ this.len = len;
195
+ this.next = undefined;
196
+ this.val = val;
197
+ }
198
+
199
+ VarintOp.prototype = Object.create(Op.prototype);
200
+ VarintOp.prototype.fn = writeVarint32;
201
+
202
+ /**
203
+ * Writes an unsigned 32 bit value as a varint.
204
+ * @param {number} value Value to write
205
+ * @returns {Writer} `this`
206
+ */
207
+ Writer.prototype.uint32 = function write_uint32(value) {
208
+ // here, the call to this.push has been inlined and a varint specific Op subclass is used.
209
+ // uint32 is by far the most frequently used operation and benefits significantly from this.
210
+ this.len += (this.tail = this.tail.next = new VarintOp(
211
+ (value = value >>> 0)
212
+ < 128 ? 1
213
+ : value < 16384 ? 2
214
+ : value < 2097152 ? 3
215
+ : value < 268435456 ? 4
216
+ : 5,
217
+ value)).len;
218
+ return this;
219
+ };
220
+
221
+ /**
222
+ * Writes a signed 32 bit value as a varint.
223
+ * @function
224
+ * @param {number} value Value to write
225
+ * @returns {Writer} `this`
226
+ */
227
+ Writer.prototype.int32 = function write_int32(value) {
228
+ return (value |= 0) < 0
229
+ ? this._push(writeVarint64, 10, LongBits.fromNumber(value)) // 10 bytes per spec
230
+ : this.uint32(value);
231
+ };
232
+
233
+ /**
234
+ * Writes a 32 bit value as a varint, zig-zag encoded.
235
+ * @param {number} value Value to write
236
+ * @returns {Writer} `this`
237
+ */
238
+ Writer.prototype.sint32 = function write_sint32(value) {
239
+ return this.uint32((value << 1 ^ value >> 31) >>> 0);
240
+ };
241
+
242
+ function writeVarint64(val, buf, pos) {
243
+ var lo = val.lo,
244
+ hi = val.hi;
245
+ while (hi) {
246
+ buf[pos++] = lo & 127 | 128;
247
+ lo = (lo >>> 7 | hi << 25) >>> 0;
248
+ hi >>>= 7;
249
+ }
250
+ while (lo > 127) {
251
+ buf[pos++] = lo & 127 | 128;
252
+ lo = lo >>> 7;
253
+ }
254
+ buf[pos++] = lo;
255
+ }
256
+
257
+ /**
258
+ * Writes an unsigned 64 bit value as a varint.
259
+ * @param {Long|number|string} value Value to write
260
+ * @returns {Writer} `this`
261
+ * @throws {TypeError} If `value` is a string and no long library is present.
262
+ */
263
+ Writer.prototype.uint64 = function write_uint64(value) {
264
+ var bits = LongBits.from(value);
265
+ return this._push(writeVarint64, bits.length(), bits);
266
+ };
267
+
268
+ /**
269
+ * Writes a signed 64 bit value as a varint.
270
+ * @function
271
+ * @param {Long|number|string} value Value to write
272
+ * @returns {Writer} `this`
273
+ * @throws {TypeError} If `value` is a string and no long library is present.
274
+ */
275
+ Writer.prototype.int64 = Writer.prototype.uint64;
276
+
277
+ /**
278
+ * Writes a signed 64 bit value as a varint, zig-zag encoded.
279
+ * @param {Long|number|string} value Value to write
280
+ * @returns {Writer} `this`
281
+ * @throws {TypeError} If `value` is a string and no long library is present.
282
+ */
283
+ Writer.prototype.sint64 = function write_sint64(value) {
284
+ var bits = LongBits.from(value).zzEncode();
285
+ return this._push(writeVarint64, bits.length(), bits);
286
+ };
287
+
288
+ /**
289
+ * Writes a boolish value as a varint.
290
+ * @param {boolean} value Value to write
291
+ * @returns {Writer} `this`
292
+ */
293
+ Writer.prototype.bool = function write_bool(value) {
294
+ return this._push(writeByte, 1, value ? 1 : 0);
295
+ };
296
+
297
+ function writeFixed32(val, buf, pos) {
298
+ buf[pos ] = val & 255;
299
+ buf[pos + 1] = val >>> 8 & 255;
300
+ buf[pos + 2] = val >>> 16 & 255;
301
+ buf[pos + 3] = val >>> 24;
302
+ }
303
+
304
+ /**
305
+ * Writes an unsigned 32 bit value as fixed 32 bits.
306
+ * @param {number} value Value to write
307
+ * @returns {Writer} `this`
308
+ */
309
+ Writer.prototype.fixed32 = function write_fixed32(value) {
310
+ return this._push(writeFixed32, 4, value >>> 0);
311
+ };
312
+
313
+ /**
314
+ * Writes a signed 32 bit value as fixed 32 bits.
315
+ * @function
316
+ * @param {number} value Value to write
317
+ * @returns {Writer} `this`
318
+ */
319
+ Writer.prototype.sfixed32 = Writer.prototype.fixed32;
320
+
321
+ /**
322
+ * Writes an unsigned 64 bit value as fixed 64 bits.
323
+ * @param {Long|number|string} value Value to write
324
+ * @returns {Writer} `this`
325
+ * @throws {TypeError} If `value` is a string and no long library is present.
326
+ */
327
+ Writer.prototype.fixed64 = function write_fixed64(value) {
328
+ var bits = LongBits.from(value);
329
+ return this._push(writeFixed32, 4, bits.lo)._push(writeFixed32, 4, bits.hi);
330
+ };
331
+
332
+ /**
333
+ * Writes a signed 64 bit value as fixed 64 bits.
334
+ * @function
335
+ * @param {Long|number|string} value Value to write
336
+ * @returns {Writer} `this`
337
+ * @throws {TypeError} If `value` is a string and no long library is present.
338
+ */
339
+ Writer.prototype.sfixed64 = Writer.prototype.fixed64;
340
+
341
+ /**
342
+ * Writes a float (32 bit).
343
+ * @function
344
+ * @param {number} value Value to write
345
+ * @returns {Writer} `this`
346
+ */
347
+ Writer.prototype.float = function write_float(value) {
348
+ return this._push(util.float.writeFloatLE, 4, value);
349
+ };
350
+
351
+ /**
352
+ * Writes a double (64 bit float).
353
+ * @function
354
+ * @param {number} value Value to write
355
+ * @returns {Writer} `this`
356
+ */
357
+ Writer.prototype.double = function write_double(value) {
358
+ return this._push(util.float.writeDoubleLE, 8, value);
359
+ };
360
+
361
+ var writeBytes = util.Array.prototype.set
362
+ ? function writeBytes_set(val, buf, pos) {
363
+ buf.set(val, pos); // also works for plain array values
364
+ }
365
+ /* istanbul ignore next */
366
+ : function writeBytes_for(val, buf, pos) {
367
+ for (var i = 0; i < val.length; ++i)
368
+ buf[pos + i] = val[i];
369
+ };
370
+
371
+ /**
372
+ * Writes a sequence of bytes.
373
+ * @param {Uint8Array|string} value Buffer or base64 encoded string to write
374
+ * @returns {Writer} `this`
375
+ */
376
+ Writer.prototype.bytes = function write_bytes(value) {
377
+ var len = value.length >>> 0;
378
+ if (!len)
379
+ return this._push(writeByte, 1, 0);
380
+ if (util.isString(value)) {
381
+ var buf = Writer.alloc(len = base64.length(value));
382
+ base64.decode(value, buf, 0);
383
+ value = buf;
384
+ }
385
+ return this.uint32(len)._push(writeBytes, len, value);
386
+ };
387
+
388
+ /**
389
+ * Writes a string.
390
+ * @param {string} value Value to write
391
+ * @returns {Writer} `this`
392
+ */
393
+ Writer.prototype.string = function write_string(value) {
394
+ var len = utf8.length(value);
395
+ return len
396
+ ? this.uint32(len)._push(utf8.write, len, value)
397
+ : this._push(writeByte, 1, 0);
398
+ };
399
+
400
+ /**
401
+ * Forks this writer's state by pushing it to a stack.
402
+ * Calling {@link Writer#reset|reset} or {@link Writer#ldelim|ldelim} resets the writer to the previous state.
403
+ * @returns {Writer} `this`
404
+ */
405
+ Writer.prototype.fork = function fork() {
406
+ this.states = new State(this);
407
+ this.head = this.tail = new Op(noop, 0, 0);
408
+ this.len = 0;
409
+ return this;
410
+ };
411
+
412
+ /**
413
+ * Resets this instance to the last state.
414
+ * @returns {Writer} `this`
415
+ */
416
+ Writer.prototype.reset = function reset() {
417
+ if (this.states) {
418
+ this.head = this.states.head;
419
+ this.tail = this.states.tail;
420
+ this.len = this.states.len;
421
+ this.states = this.states.next;
422
+ } else {
423
+ this.head = this.tail = new Op(noop, 0, 0);
424
+ this.len = 0;
425
+ }
426
+ return this;
427
+ };
428
+
429
+ /**
430
+ * Resets to the last state and appends the fork state's current write length as a varint followed by its operations.
431
+ * @returns {Writer} `this`
432
+ */
433
+ Writer.prototype.ldelim = function ldelim() {
434
+ var head = this.head,
435
+ tail = this.tail,
436
+ len = this.len;
437
+ this.reset().uint32(len);
438
+ if (len) {
439
+ this.tail.next = head.next; // skip noop
440
+ this.tail = tail;
441
+ this.len += len;
442
+ }
443
+ return this;
444
+ };
445
+
446
+ /**
447
+ * Finishes the write operation.
448
+ * @returns {Uint8Array} Finished buffer
449
+ */
450
+ Writer.prototype.finish = function finish() {
451
+ var head = this.head.next, // skip noop
452
+ buf = this.constructor.alloc(this.len),
453
+ pos = 0;
454
+ while (head) {
455
+ head.fn(head.val, buf, pos);
456
+ pos += head.len;
457
+ head = head.next;
458
+ }
459
+ // this.head = this.tail = null;
460
+ return buf;
461
+ };
462
+
463
+ Writer._configure = function(BufferWriter_) {
464
+ BufferWriter = BufferWriter_;
465
+ Writer.create = create();
466
+ BufferWriter._configure();
467
+ };
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ module.exports = BufferWriter;
3
+
4
+ // extends Writer
5
+ var Writer = require("./writer");
6
+ (BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter;
7
+
8
+ var util = require("./util/minimal");
9
+
10
+ /**
11
+ * Constructs a new buffer writer instance.
12
+ * @classdesc Wire format writer using node buffers.
13
+ * @extends Writer
14
+ * @constructor
15
+ */
16
+ function BufferWriter() {
17
+ Writer.call(this);
18
+ }
19
+
20
+ BufferWriter._configure = function () {
21
+ /**
22
+ * Allocates a buffer of the specified size.
23
+ * @function
24
+ * @param {number} size Buffer size
25
+ * @returns {Buffer} Buffer
26
+ */
27
+ BufferWriter.alloc = util._Buffer_allocUnsafe;
28
+
29
+ BufferWriter.writeBytesBuffer = util.Buffer && util.Buffer.prototype instanceof Uint8Array && util.Buffer.prototype.set.name === "set"
30
+ ? function writeBytesBuffer_set(val, buf, pos) {
31
+ buf.set(val, pos); // faster than copy (requires node >= 4 where Buffers extend Uint8Array and set is properly inherited)
32
+ // also works for plain array values
33
+ }
34
+ /* istanbul ignore next */
35
+ : function writeBytesBuffer_copy(val, buf, pos) {
36
+ if (val.copy) // Buffer values
37
+ val.copy(buf, pos, 0, val.length);
38
+ else for (var i = 0; i < val.length;) // plain array values
39
+ buf[pos++] = val[i++];
40
+ };
41
+ };
42
+
43
+
44
+ /**
45
+ * @override
46
+ */
47
+ BufferWriter.prototype.bytes = function write_bytes_buffer(value) {
48
+ if (util.isString(value))
49
+ value = util._Buffer_from(value, "base64");
50
+ var len = value.length >>> 0;
51
+ this.uint32(len);
52
+ if (len)
53
+ this._push(BufferWriter.writeBytesBuffer, len, value);
54
+ return this;
55
+ };
56
+
57
+ function writeStringBuffer(val, buf, pos) {
58
+ if (val.length < 40) // plain js is faster for short strings (probably due to redundant assertions)
59
+ util.utf8.write(val, buf, pos);
60
+ else if (buf.utf8Write)
61
+ buf.utf8Write(val, pos);
62
+ else
63
+ buf.write(val, pos);
64
+ }
65
+
66
+ /**
67
+ * @override
68
+ */
69
+ BufferWriter.prototype.string = function write_string_buffer(value) {
70
+ var len = util.Buffer.byteLength(value);
71
+ this.uint32(len);
72
+ if (len)
73
+ this._push(writeStringBuffer, len, value);
74
+ return this;
75
+ };
76
+
77
+
78
+ /**
79
+ * Finishes the write operation.
80
+ * @name BufferWriter#finish
81
+ * @function
82
+ * @returns {Buffer} Finished buffer
83
+ */
84
+
85
+ BufferWriter._configure();
@@ -0,0 +1,8 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES5",
4
+ "experimentalDecorators": true,
5
+ "emitDecoratorMetadata": true,
6
+ "esModuleInterop": true,
7
+ }
8
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Matteo Collina and Undici contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,6 @@
1
+ # undici-types
2
+
3
+ This package is a dual-publish of the [undici](https://www.npmjs.com/package/undici) library types. The `undici` package **still contains types**. This package is for users who _only_ need undici types (such as for `@types/node`). It is published alongside every release of `undici`, so you can always use the same version.
4
+
5
+ - [GitHub nodejs/undici](https://github.com/nodejs/undici)
6
+ - [Undici Documentation](https://undici.nodejs.org/#/)
@@ -0,0 +1,31 @@
1
+ import { URL } from 'url'
2
+ import Pool from './pool'
3
+ import Dispatcher from "./dispatcher";
4
+
5
+ export default Agent
6
+
7
+ declare class Agent extends Dispatcher{
8
+ constructor(opts?: Agent.Options)
9
+ /** `true` after `dispatcher.close()` has been called. */
10
+ closed: boolean;
11
+ /** `true` after `dispatcher.destroyed()` has been called or `dispatcher.close()` has been called and the dispatcher shutdown has completed. */
12
+ destroyed: boolean;
13
+ /** Dispatches a request. */
14
+ dispatch(options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean;
15
+ }
16
+
17
+ declare namespace Agent {
18
+ export interface Options extends Pool.Options {
19
+ /** Default: `(origin, opts) => new Pool(origin, opts)`. */
20
+ factory?(origin: string | URL, opts: Object): Dispatcher;
21
+ /** Integer. Default: `0` */
22
+ maxRedirections?: number;
23
+
24
+ interceptors?: { Agent?: readonly Dispatcher.DispatchInterceptor[] } & Pool.Options["interceptors"]
25
+ }
26
+
27
+ export interface DispatchOptions extends Dispatcher.DispatchOptions {
28
+ /** Integer. */
29
+ maxRedirections?: number;
30
+ }
31
+ }
@@ -0,0 +1,43 @@
1
+ import { URL, UrlObject } from 'url'
2
+ import { Duplex } from 'stream'
3
+ import Dispatcher from './dispatcher'
4
+
5
+ export {
6
+ request,
7
+ stream,
8
+ pipeline,
9
+ connect,
10
+ upgrade,
11
+ }
12
+
13
+ /** Performs an HTTP request. */
14
+ declare function request(
15
+ url: string | URL | UrlObject,
16
+ options?: { dispatcher?: Dispatcher } & Omit<Dispatcher.RequestOptions, 'origin' | 'path' | 'method'> & Partial<Pick<Dispatcher.RequestOptions, 'method'>>,
17
+ ): Promise<Dispatcher.ResponseData>;
18
+
19
+ /** A faster version of `request`. */
20
+ declare function stream(
21
+ url: string | URL | UrlObject,
22
+ options: { dispatcher?: Dispatcher } & Omit<Dispatcher.RequestOptions, 'origin' | 'path'>,
23
+ factory: Dispatcher.StreamFactory
24
+ ): Promise<Dispatcher.StreamData>;
25
+
26
+ /** For easy use with `stream.pipeline`. */
27
+ declare function pipeline(
28
+ url: string | URL | UrlObject,
29
+ options: { dispatcher?: Dispatcher } & Omit<Dispatcher.PipelineOptions, 'origin' | 'path'>,
30
+ handler: Dispatcher.PipelineHandler
31
+ ): Duplex;
32
+
33
+ /** Starts two-way communications with the requested resource. */
34
+ declare function connect(
35
+ url: string | URL | UrlObject,
36
+ options?: { dispatcher?: Dispatcher } & Omit<Dispatcher.ConnectOptions, 'origin' | 'path'>
37
+ ): Promise<Dispatcher.ConnectData>;
38
+
39
+ /** Upgrade to a different protocol. */
40
+ declare function upgrade(
41
+ url: string | URL | UrlObject,
42
+ options?: { dispatcher?: Dispatcher } & Omit<Dispatcher.UpgradeOptions, 'origin' | 'path'>
43
+ ): Promise<Dispatcher.UpgradeData>;
@@ -0,0 +1,29 @@
1
+ import Pool from './pool'
2
+ import Dispatcher from './dispatcher'
3
+ import { URL } from 'url'
4
+
5
+ export default BalancedPool
6
+
7
+ type BalancedPoolConnectOptions = Omit<Dispatcher.ConnectOptions, "origin">;
8
+
9
+ declare class BalancedPool extends Dispatcher {
10
+ constructor(url: string | string[] | URL | URL[], options?: Pool.Options);
11
+
12
+ addUpstream(upstream: string | URL): BalancedPool;
13
+ removeUpstream(upstream: string | URL): BalancedPool;
14
+ upstreams: Array<string>;
15
+
16
+ /** `true` after `pool.close()` has been called. */
17
+ closed: boolean;
18
+ /** `true` after `pool.destroyed()` has been called or `pool.close()` has been called and the pool shutdown has completed. */
19
+ destroyed: boolean;
20
+
21
+ // Override dispatcher APIs.
22
+ override connect(
23
+ options: BalancedPoolConnectOptions
24
+ ): Promise<Dispatcher.ConnectData>;
25
+ override connect(
26
+ options: BalancedPoolConnectOptions,
27
+ callback: (err: Error | null, data: Dispatcher.ConnectData) => void
28
+ ): void;
29
+ }