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,558 @@
1
+ "use strict";
2
+ module.exports = Namespace;
3
+
4
+ // extends ReflectionObject
5
+ var ReflectionObject = require("./object");
6
+ ((Namespace.prototype = Object.create(ReflectionObject.prototype)).constructor = Namespace).className = "Namespace";
7
+
8
+ var Field = require("./field"),
9
+ util = require("./util"),
10
+ OneOf = require("./oneof");
11
+
12
+ var Type, // cyclic
13
+ Service,
14
+ Enum;
15
+
16
+ /**
17
+ * Constructs a new namespace instance.
18
+ * @name Namespace
19
+ * @classdesc Reflected namespace.
20
+ * @extends NamespaceBase
21
+ * @constructor
22
+ * @param {string} name Namespace name
23
+ * @param {Object.<string,*>} [options] Declared options
24
+ */
25
+
26
+ /**
27
+ * Constructs a namespace from JSON.
28
+ * @memberof Namespace
29
+ * @function
30
+ * @param {string} name Namespace name
31
+ * @param {Object.<string,*>} json JSON object
32
+ * @param {number} [depth] Current nesting depth, defaults to `0`
33
+ * @returns {Namespace} Created namespace
34
+ * @throws {TypeError} If arguments are invalid
35
+ */
36
+ Namespace.fromJSON = function fromJSON(name, json, depth) {
37
+ depth = util.checkDepth(depth);
38
+ return new Namespace(name, json.options).addJSON(json.nested, depth);
39
+ };
40
+
41
+ /**
42
+ * Converts an array of reflection objects to JSON.
43
+ * @memberof Namespace
44
+ * @param {ReflectionObject[]} array Object array
45
+ * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
46
+ * @returns {Object.<string,*>|undefined} JSON object or `undefined` when array is empty
47
+ */
48
+ function arrayToJSON(array, toJSONOptions) {
49
+ if (!(array && array.length))
50
+ return undefined;
51
+ var obj = {};
52
+ for (var i = 0; i < array.length; ++i)
53
+ obj[array[i].name] = array[i].toJSON(toJSONOptions);
54
+ return obj;
55
+ }
56
+
57
+ Namespace.arrayToJSON = arrayToJSON;
58
+
59
+ /**
60
+ * Tests if the specified id is reserved.
61
+ * @param {Array.<number[]|string>|undefined} reserved Array of reserved ranges and names
62
+ * @param {number} id Id to test
63
+ * @returns {boolean} `true` if reserved, otherwise `false`
64
+ */
65
+ Namespace.isReservedId = function isReservedId(reserved, id) {
66
+ if (reserved)
67
+ for (var i = 0; i < reserved.length; ++i)
68
+ if (typeof reserved[i] !== "string" && reserved[i][0] <= id && reserved[i][1] > id)
69
+ return true;
70
+ return false;
71
+ };
72
+
73
+ /**
74
+ * Tests if the specified name is reserved.
75
+ * @param {Array.<number[]|string>|undefined} reserved Array of reserved ranges and names
76
+ * @param {string} name Name to test
77
+ * @returns {boolean} `true` if reserved, otherwise `false`
78
+ */
79
+ Namespace.isReservedName = function isReservedName(reserved, name) {
80
+ if (reserved)
81
+ for (var i = 0; i < reserved.length; ++i)
82
+ if (reserved[i] === name)
83
+ return true;
84
+ return false;
85
+ };
86
+
87
+ /**
88
+ * Not an actual constructor. Use {@link Namespace} instead.
89
+ * @classdesc Base class of all reflection objects containing nested objects. This is not an actual class but here for the sake of having consistent type definitions.
90
+ * @exports NamespaceBase
91
+ * @extends ReflectionObject
92
+ * @abstract
93
+ * @constructor
94
+ * @param {string} name Namespace name
95
+ * @param {Object.<string,*>} [options] Declared options
96
+ * @see {@link Namespace}
97
+ */
98
+ function Namespace(name, options) {
99
+ ReflectionObject.call(this, name, options);
100
+
101
+ /**
102
+ * Nested objects by name.
103
+ * @type {Object.<string,ReflectionObject>|undefined}
104
+ */
105
+ this.nested = undefined; // toJSON
106
+
107
+ /**
108
+ * Cached nested objects as an array.
109
+ * @type {ReflectionObject[]|null}
110
+ * @private
111
+ */
112
+ this._nestedArray = null;
113
+
114
+ /**
115
+ * Cache lookup calls for any objects contains anywhere under this namespace.
116
+ * This drastically speeds up resolve for large cross-linked protos where the same
117
+ * types are looked up repeatedly.
118
+ * @type {Object.<string,ReflectionObject|null>}
119
+ * @private
120
+ */
121
+ this._lookupCache = Object.create(null);
122
+
123
+ /**
124
+ * Whether or not objects contained in this namespace need feature resolution.
125
+ * @type {boolean}
126
+ * @protected
127
+ */
128
+ this._needsRecursiveFeatureResolution = true;
129
+
130
+ /**
131
+ * Whether or not objects contained in this namespace need a resolve.
132
+ * @type {boolean}
133
+ * @protected
134
+ */
135
+ this._needsRecursiveResolve = true;
136
+ }
137
+
138
+ function clearCache(namespace) {
139
+ namespace._nestedArray = null;
140
+ namespace._lookupCache = Object.create(null);
141
+
142
+ // Also clear parent caches, since they include nested lookups.
143
+ var parent = namespace;
144
+ while(parent = parent.parent) {
145
+ parent._lookupCache = Object.create(null);
146
+ }
147
+ return namespace;
148
+ }
149
+
150
+ /**
151
+ * Nested objects of this namespace as an array for iteration.
152
+ * @name NamespaceBase#nestedArray
153
+ * @type {ReflectionObject[]}
154
+ * @readonly
155
+ */
156
+ Object.defineProperty(Namespace.prototype, "nestedArray", {
157
+ get: function() {
158
+ return this._nestedArray || (this._nestedArray = util.toArray(this.nested));
159
+ }
160
+ });
161
+
162
+ /**
163
+ * Namespace descriptor.
164
+ * @interface INamespace
165
+ * @property {Object.<string,*>} [options] Namespace options
166
+ * @property {Object.<string,AnyNestedObject>} [nested] Nested object descriptors
167
+ */
168
+
169
+ /**
170
+ * Any extension field descriptor.
171
+ * @typedef AnyExtensionField
172
+ * @type {IExtensionField|IExtensionMapField}
173
+ */
174
+
175
+ /**
176
+ * Any nested object descriptor.
177
+ * @typedef AnyNestedObject
178
+ * @type {IEnum|IType|IService|AnyExtensionField|INamespace|IOneOf}
179
+ */
180
+
181
+ /**
182
+ * Converts this namespace to a namespace descriptor.
183
+ * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
184
+ * @returns {INamespace} Namespace descriptor
185
+ */
186
+ Namespace.prototype.toJSON = function toJSON(toJSONOptions) {
187
+ return util.toObject([
188
+ "options" , this.options,
189
+ "nested" , arrayToJSON(this.nestedArray, toJSONOptions)
190
+ ]);
191
+ };
192
+
193
+ /**
194
+ * Adds nested objects to this namespace from nested object descriptors.
195
+ * @param {Object.<string,AnyNestedObject>} nestedJson Any nested object descriptors
196
+ * @param {number} [depth] Current nesting depth, defaults to `0`
197
+ * @returns {Namespace} `this`
198
+ */
199
+ Namespace.prototype.addJSON = function addJSON(nestedJson, depth) {
200
+ depth = util.checkDepth(depth);
201
+ var ns = this;
202
+ /* istanbul ignore else */
203
+ if (nestedJson) {
204
+ for (var names = Object.keys(nestedJson), i = 0, nested; i < names.length; ++i) {
205
+ nested = nestedJson[names[i]];
206
+ ns.add( // most to least likely
207
+ ( nested.fields !== undefined
208
+ ? Type.fromJSON
209
+ : nested.values !== undefined
210
+ ? Enum.fromJSON
211
+ : nested.methods !== undefined
212
+ ? Service.fromJSON
213
+ : nested.id !== undefined
214
+ ? Field.fromJSON
215
+ : Namespace.fromJSON )(names[i], nested, depth + 1)
216
+ );
217
+ }
218
+ }
219
+ return this;
220
+ };
221
+
222
+ /**
223
+ * Gets the nested object of the specified name.
224
+ * @param {string} name Nested object name
225
+ * @returns {ReflectionObject|null} The reflection object or `null` if it doesn't exist
226
+ */
227
+ Namespace.prototype.get = function get(name) {
228
+ return this.nested && Object.prototype.hasOwnProperty.call(this.nested, name)
229
+ ? this.nested[name]
230
+ : null;
231
+ };
232
+
233
+ /**
234
+ * Gets the values of the nested {@link Enum|enum} of the specified name.
235
+ * This methods differs from {@link Namespace#get|get} in that it returns an enum's values directly and throws instead of returning `null`.
236
+ * @param {string} name Nested enum name
237
+ * @returns {Object.<string,number>} Enum values
238
+ * @throws {Error} If there is no such enum
239
+ */
240
+ Namespace.prototype.getEnum = function getEnum(name) {
241
+ if (this.nested && Object.prototype.hasOwnProperty.call(this.nested, name) && this.nested[name] instanceof Enum)
242
+ return this.nested[name].values;
243
+ throw Error("no such enum: " + name);
244
+ };
245
+
246
+ /**
247
+ * Adds a nested object to this namespace.
248
+ * @param {ReflectionObject} object Nested object to add
249
+ * @returns {Namespace} `this`
250
+ * @throws {TypeError} If arguments are invalid
251
+ * @throws {Error} If there is already a nested object with this name
252
+ */
253
+ Namespace.prototype.add = function add(object) {
254
+
255
+ if (!(object instanceof Field && object.extend !== undefined || object instanceof Type || object instanceof OneOf || object instanceof Enum || object instanceof Service || object instanceof Namespace))
256
+ throw TypeError("object must be a valid nested object");
257
+
258
+ if (object.name === "__proto__")
259
+ return this;
260
+
261
+ if (!this.nested)
262
+ this.nested = {};
263
+ else {
264
+ var prev = this.get(object.name);
265
+ if (prev) {
266
+ if (prev instanceof Namespace && object instanceof Namespace && !(prev instanceof Type || prev instanceof Service)) {
267
+ // replace plain namespace but keep existing nested elements and options
268
+ var nested = prev.nestedArray;
269
+ for (var i = 0; i < nested.length; ++i)
270
+ object.add(nested[i]);
271
+ this.remove(prev);
272
+ if (!this.nested)
273
+ this.nested = {};
274
+ object.setOptions(prev.options, true);
275
+
276
+ } else
277
+ throw Error("duplicate name '" + object.name + "' in " + this);
278
+ }
279
+ }
280
+ this.nested[object.name] = object;
281
+
282
+ if (!(this instanceof Type || this instanceof Service || this instanceof Enum || this instanceof Field)) {
283
+ // This is a package or a root namespace.
284
+ if (!object._edition) {
285
+ // Make sure that some edition is set if it hasn't already been specified.
286
+ object._edition = object._defaultEdition;
287
+ }
288
+ }
289
+
290
+ this._needsRecursiveFeatureResolution = true;
291
+ this._needsRecursiveResolve = true;
292
+
293
+ // Also clear parent caches, since they need to recurse down.
294
+ var parent = this;
295
+ while(parent = parent.parent) {
296
+ parent._needsRecursiveFeatureResolution = true;
297
+ parent._needsRecursiveResolve = true;
298
+ }
299
+
300
+ object.onAdd(this);
301
+ return clearCache(this);
302
+ };
303
+
304
+ /**
305
+ * Removes a nested object from this namespace.
306
+ * @param {ReflectionObject} object Nested object to remove
307
+ * @returns {Namespace} `this`
308
+ * @throws {TypeError} If arguments are invalid
309
+ * @throws {Error} If `object` is not a member of this namespace
310
+ */
311
+ Namespace.prototype.remove = function remove(object) {
312
+
313
+ if (!(object instanceof ReflectionObject))
314
+ throw TypeError("object must be a ReflectionObject");
315
+ if (object.parent !== this)
316
+ throw Error(object + " is not a member of " + this);
317
+
318
+ delete this.nested[object.name];
319
+ if (!Object.keys(this.nested).length)
320
+ this.nested = undefined;
321
+
322
+ object.onRemove(this);
323
+ return clearCache(this);
324
+ };
325
+
326
+ /**
327
+ * Defines additial namespaces within this one if not yet existing.
328
+ * @param {string|string[]} path Path to create
329
+ * @param {*} [json] Nested types to create from JSON
330
+ * @returns {Namespace} Pointer to the last namespace created or `this` if path is empty
331
+ */
332
+ Namespace.prototype.define = function define(path, json) {
333
+
334
+ if (util.isString(path))
335
+ path = path.split(".");
336
+ else if (!Array.isArray(path))
337
+ throw TypeError("illegal path");
338
+ if (path && path.length && path[0] === "")
339
+ throw Error("path must be relative");
340
+ if (path.length > util.recursionLimit)
341
+ throw Error("max depth exceeded");
342
+
343
+ var ptr = this;
344
+ while (path.length > 0) {
345
+ var part = path.shift();
346
+ if (ptr.nested && ptr.nested[part]) {
347
+ ptr = ptr.nested[part];
348
+ if (!(ptr instanceof Namespace))
349
+ throw Error("path conflicts with non-namespace objects");
350
+ } else
351
+ ptr.add(ptr = new Namespace(part));
352
+ }
353
+ if (json)
354
+ ptr.addJSON(json);
355
+ return ptr;
356
+ };
357
+
358
+ /**
359
+ * Resolves this namespace's and all its nested objects' type references. Useful to validate a reflection tree, but comes at a cost.
360
+ * @returns {Namespace} `this`
361
+ */
362
+ Namespace.prototype.resolveAll = function resolveAll() {
363
+ if (!this._needsRecursiveResolve) return this;
364
+
365
+ this._resolveFeaturesRecursive(this._edition);
366
+
367
+ var nested = this.nestedArray, i = 0;
368
+ this.resolve();
369
+ while (i < nested.length)
370
+ if (nested[i] instanceof Namespace)
371
+ nested[i++].resolveAll();
372
+ else
373
+ nested[i++].resolve();
374
+ this._needsRecursiveResolve = false;
375
+ return this;
376
+ };
377
+
378
+ /**
379
+ * @override
380
+ */
381
+ Namespace.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(edition) {
382
+ if (!this._needsRecursiveFeatureResolution) return this;
383
+ this._needsRecursiveFeatureResolution = false;
384
+
385
+ edition = this._edition || edition;
386
+
387
+ ReflectionObject.prototype._resolveFeaturesRecursive.call(this, edition);
388
+ this.nestedArray.forEach(nested => {
389
+ nested._resolveFeaturesRecursive(edition);
390
+ });
391
+ return this;
392
+ };
393
+
394
+ /**
395
+ * Recursively looks up the reflection object matching the specified path in the scope of this namespace.
396
+ * @param {string|string[]} path Path to look up
397
+ * @param {*|Array.<*>} filterTypes Filter types, any combination of the constructors of `protobuf.Type`, `protobuf.Enum`, `protobuf.Service` etc.
398
+ * @param {boolean} [parentAlreadyChecked=false] If known, whether the parent has already been checked
399
+ * @returns {ReflectionObject|null} Looked up object or `null` if none could be found
400
+ */
401
+ Namespace.prototype.lookup = function lookup(path, filterTypes, parentAlreadyChecked) {
402
+ /* istanbul ignore next */
403
+ if (typeof filterTypes === "boolean") {
404
+ parentAlreadyChecked = filterTypes;
405
+ filterTypes = undefined;
406
+ } else if (filterTypes && !Array.isArray(filterTypes))
407
+ filterTypes = [ filterTypes ];
408
+
409
+ if (util.isString(path) && path.length) {
410
+ if (path === ".")
411
+ return this.root;
412
+ path = path.split(".");
413
+ } else if (!path.length)
414
+ return this;
415
+
416
+ var flatPath = path.join(".");
417
+
418
+ // Start at root if path is absolute
419
+ if (path[0] === "")
420
+ return this.root.lookup(path.slice(1), filterTypes);
421
+
422
+ // Early bailout for objects with matching absolute paths
423
+ var found = this.root._fullyQualifiedObjects && this.root._fullyQualifiedObjects["." + flatPath];
424
+ if (found && (!filterTypes || filterTypes.indexOf(found.constructor) > -1)) {
425
+ return found;
426
+ }
427
+
428
+ // Do a regular lookup at this namespace and below
429
+ found = this._lookupImpl(path, flatPath);
430
+ if (found && (!filterTypes || filterTypes.indexOf(found.constructor) > -1)) {
431
+ return found;
432
+ }
433
+
434
+ if (parentAlreadyChecked)
435
+ return null;
436
+
437
+ // If there hasn't been a match, walk up the tree and look more broadly
438
+ var current = this;
439
+ while (current.parent) {
440
+ found = current.parent._lookupImpl(path, flatPath);
441
+ if (found && (!filterTypes || filterTypes.indexOf(found.constructor) > -1)) {
442
+ return found;
443
+ }
444
+ current = current.parent;
445
+ }
446
+ return null;
447
+ };
448
+
449
+ /**
450
+ * Internal helper for lookup that handles searching just at this namespace and below along with caching.
451
+ * @param {string[]} path Path to look up
452
+ * @param {string} flatPath Flattened version of the path to use as a cache key
453
+ * @returns {ReflectionObject|null} Looked up object or `null` if none could be found
454
+ * @private
455
+ */
456
+ Namespace.prototype._lookupImpl = function lookup(path, flatPath) {
457
+ if(Object.prototype.hasOwnProperty.call(this._lookupCache, flatPath)) {
458
+ return this._lookupCache[flatPath];
459
+ }
460
+
461
+ // Test if the first part matches any nested object, and if so, traverse if path contains more
462
+ var found = this.get(path[0]);
463
+ var exact = null;
464
+ if (found) {
465
+ if (path.length === 1) {
466
+ exact = found;
467
+ } else if (found instanceof Namespace) {
468
+ path = path.slice(1);
469
+ exact = found._lookupImpl(path, path.join("."));
470
+ }
471
+
472
+ // Otherwise try each nested namespace
473
+ } else {
474
+ for (var i = 0; i < this.nestedArray.length; ++i)
475
+ if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i]._lookupImpl(path, flatPath))) {
476
+ exact = found;
477
+ break;
478
+ }
479
+ }
480
+
481
+ // Set this even when null, so that when we walk up the tree we can quickly bail on repeated checks back down.
482
+ this._lookupCache[flatPath] = exact;
483
+ return exact;
484
+ };
485
+
486
+ /**
487
+ * Looks up the reflection object at the specified path, relative to this namespace.
488
+ * @name NamespaceBase#lookup
489
+ * @function
490
+ * @param {string|string[]} path Path to look up
491
+ * @param {boolean} [parentAlreadyChecked=false] Whether the parent has already been checked
492
+ * @returns {ReflectionObject|null} Looked up object or `null` if none could be found
493
+ * @variation 2
494
+ */
495
+ // lookup(path: string, [parentAlreadyChecked: boolean])
496
+
497
+ /**
498
+ * Looks up the {@link Type|type} at the specified path, relative to this namespace.
499
+ * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
500
+ * @param {string|string[]} path Path to look up
501
+ * @returns {Type} Looked up type
502
+ * @throws {Error} If `path` does not point to a type
503
+ */
504
+ Namespace.prototype.lookupType = function lookupType(path) {
505
+ var found = this.lookup(path, [ Type ]);
506
+ if (!found)
507
+ throw Error("no such type: " + path);
508
+ return found;
509
+ };
510
+
511
+ /**
512
+ * Looks up the values of the {@link Enum|enum} at the specified path, relative to this namespace.
513
+ * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
514
+ * @param {string|string[]} path Path to look up
515
+ * @returns {Enum} Looked up enum
516
+ * @throws {Error} If `path` does not point to an enum
517
+ */
518
+ Namespace.prototype.lookupEnum = function lookupEnum(path) {
519
+ var found = this.lookup(path, [ Enum ]);
520
+ if (!found)
521
+ throw Error("no such Enum '" + path + "' in " + this);
522
+ return found;
523
+ };
524
+
525
+ /**
526
+ * Looks up the {@link Type|type} or {@link Enum|enum} at the specified path, relative to this namespace.
527
+ * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
528
+ * @param {string|string[]} path Path to look up
529
+ * @returns {Type} Looked up type or enum
530
+ * @throws {Error} If `path` does not point to a type or enum
531
+ */
532
+ Namespace.prototype.lookupTypeOrEnum = function lookupTypeOrEnum(path) {
533
+ var found = this.lookup(path, [ Type, Enum ]);
534
+ if (!found)
535
+ throw Error("no such Type or Enum '" + path + "' in " + this);
536
+ return found;
537
+ };
538
+
539
+ /**
540
+ * Looks up the {@link Service|service} at the specified path, relative to this namespace.
541
+ * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
542
+ * @param {string|string[]} path Path to look up
543
+ * @returns {Service} Looked up service
544
+ * @throws {Error} If `path` does not point to a service
545
+ */
546
+ Namespace.prototype.lookupService = function lookupService(path) {
547
+ var found = this.lookup(path, [ Service ]);
548
+ if (!found)
549
+ throw Error("no such Service '" + path + "' in " + this);
550
+ return found;
551
+ };
552
+
553
+ // Sets up cyclic dependencies (called in index-light)
554
+ Namespace._configure = function(Type_, Service_, Enum_) {
555
+ Type = Type_;
556
+ Service = Service_;
557
+ Enum = Enum_;
558
+ };