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,382 @@
1
+ "use strict";
2
+ module.exports = ReflectionObject;
3
+
4
+ ReflectionObject.className = "ReflectionObject";
5
+
6
+ const OneOf = require("./oneof");
7
+ var util = require("./util");
8
+
9
+ var Root; // cyclic
10
+
11
+ /* eslint-disable no-warning-comments */
12
+ // TODO: Replace with embedded proto.
13
+ var editions2023Defaults = {enum_type: "OPEN", field_presence: "EXPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY"};
14
+ var proto2Defaults = {enum_type: "CLOSED", field_presence: "EXPLICIT", json_format: "LEGACY_BEST_EFFORT", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "EXPANDED", utf8_validation: "NONE"};
15
+ var proto3Defaults = {enum_type: "OPEN", field_presence: "IMPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY"};
16
+
17
+ /**
18
+ * Constructs a new reflection object instance.
19
+ * @classdesc Base class of all reflection objects.
20
+ * @constructor
21
+ * @param {string} name Object name
22
+ * @param {Object.<string,*>} [options] Declared options
23
+ * @abstract
24
+ */
25
+ function ReflectionObject(name, options) {
26
+
27
+ if (!util.isString(name))
28
+ throw TypeError("name must be a string");
29
+
30
+ if (options && !util.isObject(options))
31
+ throw TypeError("options must be an object");
32
+
33
+ /**
34
+ * Options.
35
+ * @type {Object.<string,*>|undefined}
36
+ */
37
+ this.options = options; // toJSON
38
+
39
+ /**
40
+ * Parsed Options.
41
+ * @type {Array.<Object.<string,*>>|undefined}
42
+ */
43
+ this.parsedOptions = null;
44
+
45
+ /**
46
+ * Unique name within its namespace.
47
+ * @type {string}
48
+ */
49
+ this.name = name;
50
+
51
+ /**
52
+ * The edition specified for this object. Only relevant for top-level objects.
53
+ * @type {string}
54
+ * @private
55
+ */
56
+ this._edition = null;
57
+
58
+ /**
59
+ * The default edition to use for this object if none is specified. For legacy reasons,
60
+ * this is proto2 except in the JSON parsing case where it was proto3.
61
+ * @type {string}
62
+ * @private
63
+ */
64
+ this._defaultEdition = "proto2";
65
+
66
+ /**
67
+ * Resolved Features.
68
+ * @type {object}
69
+ * @private
70
+ */
71
+ this._features = {};
72
+
73
+ /**
74
+ * Whether or not features have been resolved.
75
+ * @type {boolean}
76
+ * @private
77
+ */
78
+ this._featuresResolved = false;
79
+
80
+ /**
81
+ * Parent namespace.
82
+ * @type {Namespace|null}
83
+ */
84
+ this.parent = null;
85
+
86
+ /**
87
+ * Whether already resolved or not.
88
+ * @type {boolean}
89
+ */
90
+ this.resolved = false;
91
+
92
+ /**
93
+ * Comment text, if any.
94
+ * @type {string|null}
95
+ */
96
+ this.comment = null;
97
+
98
+ /**
99
+ * Defining file name.
100
+ * @type {string|null}
101
+ */
102
+ this.filename = null;
103
+ }
104
+
105
+ Object.defineProperties(ReflectionObject.prototype, {
106
+
107
+ /**
108
+ * Reference to the root namespace.
109
+ * @name ReflectionObject#root
110
+ * @type {Root}
111
+ * @readonly
112
+ */
113
+ root: {
114
+ get: function() {
115
+ var ptr = this;
116
+ while (ptr.parent !== null)
117
+ ptr = ptr.parent;
118
+ return ptr;
119
+ }
120
+ },
121
+
122
+ /**
123
+ * Full name including leading dot.
124
+ * @name ReflectionObject#fullName
125
+ * @type {string}
126
+ * @readonly
127
+ */
128
+ fullName: {
129
+ get: function() {
130
+ var path = [ this.name ],
131
+ ptr = this.parent;
132
+ while (ptr) {
133
+ path.unshift(ptr.name);
134
+ ptr = ptr.parent;
135
+ }
136
+ return path.join(".");
137
+ }
138
+ }
139
+ });
140
+
141
+ /**
142
+ * Converts this reflection object to its descriptor representation.
143
+ * @returns {Object.<string,*>} Descriptor
144
+ * @abstract
145
+ */
146
+ ReflectionObject.prototype.toJSON = /* istanbul ignore next */ function toJSON() {
147
+ throw Error(); // not implemented, shouldn't happen
148
+ };
149
+
150
+ /**
151
+ * Called when this object is added to a parent.
152
+ * @param {ReflectionObject} parent Parent added to
153
+ * @returns {undefined}
154
+ */
155
+ ReflectionObject.prototype.onAdd = function onAdd(parent) {
156
+ if (this.parent && this.parent !== parent)
157
+ this.parent.remove(this);
158
+ this.parent = parent;
159
+ this.resolved = false;
160
+ var root = parent.root;
161
+ if (root instanceof Root)
162
+ root._handleAdd(this);
163
+ };
164
+
165
+ /**
166
+ * Called when this object is removed from a parent.
167
+ * @param {ReflectionObject} parent Parent removed from
168
+ * @returns {undefined}
169
+ */
170
+ ReflectionObject.prototype.onRemove = function onRemove(parent) {
171
+ var root = parent.root;
172
+ if (root instanceof Root)
173
+ root._handleRemove(this);
174
+ this.parent = null;
175
+ this.resolved = false;
176
+ };
177
+
178
+ /**
179
+ * Resolves this objects type references.
180
+ * @returns {ReflectionObject} `this`
181
+ */
182
+ ReflectionObject.prototype.resolve = function resolve() {
183
+ if (this.resolved)
184
+ return this;
185
+ if (this.root instanceof Root)
186
+ this.resolved = true; // only if part of a root
187
+ return this;
188
+ };
189
+
190
+ /**
191
+ * Resolves this objects editions features.
192
+ * @param {string} edition The edition we're currently resolving for.
193
+ * @returns {ReflectionObject} `this`
194
+ */
195
+ ReflectionObject.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(edition) {
196
+ return this._resolveFeatures(this._edition || edition);
197
+ };
198
+
199
+ /**
200
+ * Resolves child features from parent features
201
+ * @param {string} edition The edition we're currently resolving for.
202
+ * @returns {undefined}
203
+ */
204
+ ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition) {
205
+ if (this._featuresResolved) {
206
+ return;
207
+ }
208
+
209
+ var defaults = {};
210
+
211
+ /* istanbul ignore if */
212
+ if (!edition) {
213
+ throw new Error("Unknown edition for " + this.fullName);
214
+ }
215
+
216
+ var protoFeatures = util.merge({}, this.options && this.options.features,
217
+ this._inferLegacyProtoFeatures(edition));
218
+
219
+ if (this._edition) {
220
+ // For a namespace marked with a specific edition, reset defaults.
221
+ /* istanbul ignore else */
222
+ if (edition === "proto2") {
223
+ defaults = Object.assign({}, proto2Defaults);
224
+ } else if (edition === "proto3") {
225
+ defaults = Object.assign({}, proto3Defaults);
226
+ } else if (edition === "2023") {
227
+ defaults = Object.assign({}, editions2023Defaults);
228
+ } else {
229
+ throw new Error("Unknown edition: " + edition);
230
+ }
231
+ this._features = util.merge(defaults, protoFeatures);
232
+ this._featuresResolved = true;
233
+ return;
234
+ }
235
+
236
+ // fields in Oneofs aren't actually children of them, so we have to
237
+ // special-case it
238
+ /* istanbul ignore else */
239
+ if (this.partOf instanceof OneOf) {
240
+ var lexicalParentFeaturesCopy = util.merge({}, this.partOf._features);
241
+ this._features = util.merge(lexicalParentFeaturesCopy, protoFeatures);
242
+ } else if (this.declaringField) {
243
+ // Skip feature resolution of sister fields.
244
+ } else if (this.parent) {
245
+ var parentFeaturesCopy = util.merge({}, this.parent._features);
246
+ this._features = util.merge(parentFeaturesCopy, protoFeatures);
247
+ } else {
248
+ throw new Error("Unable to find a parent for " + this.fullName);
249
+ }
250
+ if (this.extensionField) {
251
+ // Sister fields should have the same features as their extensions.
252
+ this.extensionField._features = this._features;
253
+ }
254
+ this._featuresResolved = true;
255
+ };
256
+
257
+ /**
258
+ * Infers features from legacy syntax that may have been specified differently.
259
+ * in older editions.
260
+ * @param {string|undefined} edition The edition this proto is on, or undefined if pre-editions
261
+ * @returns {object} The feature values to override
262
+ */
263
+ ReflectionObject.prototype._inferLegacyProtoFeatures = function _inferLegacyProtoFeatures(/*edition*/) {
264
+ return {};
265
+ };
266
+
267
+ /**
268
+ * Gets an option value.
269
+ * @param {string} name Option name
270
+ * @returns {*} Option value or `undefined` if not set
271
+ */
272
+ ReflectionObject.prototype.getOption = function getOption(name) {
273
+ if (this.options)
274
+ return this.options[name];
275
+ return undefined;
276
+ };
277
+
278
+ /**
279
+ * Sets an option.
280
+ * @param {string} name Option name
281
+ * @param {*} value Option value
282
+ * @param {boolean|undefined} [ifNotSet] Sets the option only if it isn't currently set
283
+ * @returns {ReflectionObject} `this`
284
+ */
285
+ ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet) {
286
+ if (name === "__proto__")
287
+ return this;
288
+ if (!this.options)
289
+ this.options = {};
290
+ if (/^features\./.test(name)) {
291
+ util.setProperty(this.options, name, value, ifNotSet);
292
+ } else if (!ifNotSet || this.options[name] === undefined) {
293
+ if (this.getOption(name) !== value) this.resolved = false;
294
+ this.options[name] = value;
295
+ }
296
+
297
+ return this;
298
+ };
299
+
300
+ /**
301
+ * Sets a parsed option.
302
+ * @param {string} name parsed Option name
303
+ * @param {*} value Option value
304
+ * @param {string} propName dot '.' delimited full path of property within the option to set. if undefined\empty, will add a new option with that value
305
+ * @returns {ReflectionObject} `this`
306
+ */
307
+ ReflectionObject.prototype.setParsedOption = function setParsedOption(name, value, propName) {
308
+ if (name === "__proto__")
309
+ return this;
310
+ if (!this.parsedOptions) {
311
+ this.parsedOptions = [];
312
+ }
313
+ var parsedOptions = this.parsedOptions;
314
+ if (propName) {
315
+ // If setting a sub property of an option then try to merge it
316
+ // with an existing option
317
+ var opt = parsedOptions.find(function (opt) {
318
+ return Object.prototype.hasOwnProperty.call(opt, name);
319
+ });
320
+ if (opt) {
321
+ // If we found an existing option - just merge the property value
322
+ // (If it's a feature, will just write over)
323
+ var newValue = opt[name];
324
+ util.setProperty(newValue, propName, value);
325
+ } else {
326
+ // otherwise, create a new option, set its property and add it to the list
327
+ opt = {};
328
+ opt[name] = util.setProperty({}, propName, value);
329
+ parsedOptions.push(opt);
330
+ }
331
+ } else {
332
+ // Always create a new option when setting the value of the option itself
333
+ var newOpt = {};
334
+ newOpt[name] = value;
335
+ parsedOptions.push(newOpt);
336
+ }
337
+
338
+ return this;
339
+ };
340
+
341
+ /**
342
+ * Sets multiple options.
343
+ * @param {Object.<string,*>} options Options to set
344
+ * @param {boolean} [ifNotSet] Sets an option only if it isn't currently set
345
+ * @returns {ReflectionObject} `this`
346
+ */
347
+ ReflectionObject.prototype.setOptions = function setOptions(options, ifNotSet) {
348
+ if (options)
349
+ for (var keys = Object.keys(options), i = 0; i < keys.length; ++i)
350
+ this.setOption(keys[i], options[keys[i]], ifNotSet);
351
+ return this;
352
+ };
353
+
354
+ /**
355
+ * Converts this instance to its string representation.
356
+ * @returns {string} Class name[, space, full name]
357
+ */
358
+ ReflectionObject.prototype.toString = function toString() {
359
+ var className = this.constructor.className,
360
+ fullName = this.fullName;
361
+ if (fullName.length)
362
+ return className + " " + fullName;
363
+ return className;
364
+ };
365
+
366
+ /**
367
+ * Converts the edition this object is pinned to for JSON format.
368
+ * @returns {string|undefined} The edition string for JSON representation
369
+ */
370
+ ReflectionObject.prototype._editionToJSON = function _editionToJSON() {
371
+ if (!this._edition || this._edition === "proto3") {
372
+ // Avoid emitting proto3 since we need to default to it for backwards
373
+ // compatibility anyway.
374
+ return undefined;
375
+ }
376
+ return this._edition;
377
+ };
378
+
379
+ // Sets up cyclic dependencies (called in index-light)
380
+ ReflectionObject._configure = function(Root_) {
381
+ Root = Root_;
382
+ };
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+ module.exports = OneOf;
3
+
4
+ // extends ReflectionObject
5
+ var ReflectionObject = require("./object");
6
+ ((OneOf.prototype = Object.create(ReflectionObject.prototype)).constructor = OneOf).className = "OneOf";
7
+
8
+ var Field = require("./field"),
9
+ util = require("./util");
10
+
11
+ /**
12
+ * Constructs a new oneof instance.
13
+ * @classdesc Reflected oneof.
14
+ * @extends ReflectionObject
15
+ * @constructor
16
+ * @param {string} name Oneof name
17
+ * @param {string[]|Object.<string,*>} [fieldNames] Field names
18
+ * @param {Object.<string,*>} [options] Declared options
19
+ * @param {string} [comment] Comment associated with this field
20
+ */
21
+ function OneOf(name, fieldNames, options, comment) {
22
+ if (!Array.isArray(fieldNames)) {
23
+ options = fieldNames;
24
+ fieldNames = undefined;
25
+ }
26
+ ReflectionObject.call(this, name, options);
27
+
28
+ /* istanbul ignore if */
29
+ if (!(fieldNames === undefined || Array.isArray(fieldNames)))
30
+ throw TypeError("fieldNames must be an Array");
31
+
32
+ /**
33
+ * Field names that belong to this oneof.
34
+ * @type {string[]}
35
+ */
36
+ this.oneof = fieldNames || []; // toJSON, marker
37
+
38
+ /**
39
+ * Fields that belong to this oneof as an array for iteration.
40
+ * @type {Field[]}
41
+ * @readonly
42
+ */
43
+ this.fieldsArray = []; // declared readonly for conformance, possibly not yet added to parent
44
+
45
+ /**
46
+ * Comment for this field.
47
+ * @type {string|null}
48
+ */
49
+ this.comment = comment;
50
+ }
51
+
52
+ /**
53
+ * Oneof descriptor.
54
+ * @interface IOneOf
55
+ * @property {Array.<string>} oneof Oneof field names
56
+ * @property {Object.<string,*>} [options] Oneof options
57
+ */
58
+
59
+ /**
60
+ * Constructs a oneof from a oneof descriptor.
61
+ * @param {string} name Oneof name
62
+ * @param {IOneOf} json Oneof descriptor
63
+ * @returns {OneOf} Created oneof
64
+ * @throws {TypeError} If arguments are invalid
65
+ */
66
+ OneOf.fromJSON = function fromJSON(name, json) {
67
+ return new OneOf(name, json.oneof, json.options, json.comment);
68
+ };
69
+
70
+ /**
71
+ * Converts this oneof to a oneof descriptor.
72
+ * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
73
+ * @returns {IOneOf} Oneof descriptor
74
+ */
75
+ OneOf.prototype.toJSON = function toJSON(toJSONOptions) {
76
+ var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
77
+ return util.toObject([
78
+ "options" , this.options,
79
+ "oneof" , this.oneof,
80
+ "comment" , keepComments ? this.comment : undefined
81
+ ]);
82
+ };
83
+
84
+ /**
85
+ * Adds the fields of the specified oneof to the parent if not already done so.
86
+ * @param {OneOf} oneof The oneof
87
+ * @returns {undefined}
88
+ * @inner
89
+ * @ignore
90
+ */
91
+ function addFieldsToParent(oneof) {
92
+ if (oneof.parent)
93
+ for (var i = 0; i < oneof.fieldsArray.length; ++i)
94
+ if (!oneof.fieldsArray[i].parent)
95
+ oneof.parent.add(oneof.fieldsArray[i]);
96
+ }
97
+
98
+ /**
99
+ * Adds a field to this oneof and removes it from its current parent, if any.
100
+ * @param {Field} field Field to add
101
+ * @returns {OneOf} `this`
102
+ */
103
+ OneOf.prototype.add = function add(field) {
104
+
105
+ /* istanbul ignore if */
106
+ if (!(field instanceof Field))
107
+ throw TypeError("field must be a Field");
108
+
109
+ if (field.parent && field.parent !== this.parent)
110
+ field.parent.remove(field);
111
+ this.oneof.push(field.name);
112
+ this.fieldsArray.push(field);
113
+ field.partOf = this; // field.parent remains null
114
+ addFieldsToParent(this);
115
+ return this;
116
+ };
117
+
118
+ /**
119
+ * Removes a field from this oneof and puts it back to the oneof's parent.
120
+ * @param {Field} field Field to remove
121
+ * @returns {OneOf} `this`
122
+ */
123
+ OneOf.prototype.remove = function remove(field) {
124
+
125
+ /* istanbul ignore if */
126
+ if (!(field instanceof Field))
127
+ throw TypeError("field must be a Field");
128
+
129
+ var index = this.fieldsArray.indexOf(field);
130
+
131
+ /* istanbul ignore if */
132
+ if (index < 0)
133
+ throw Error(field + " is not a member of " + this);
134
+
135
+ this.fieldsArray.splice(index, 1);
136
+ index = this.oneof.indexOf(field.name);
137
+
138
+ /* istanbul ignore else */
139
+ if (index > -1) // theoretical
140
+ this.oneof.splice(index, 1);
141
+
142
+ field.partOf = null;
143
+ return this;
144
+ };
145
+
146
+ /**
147
+ * @override
148
+ */
149
+ OneOf.prototype.onAdd = function onAdd(parent) {
150
+ ReflectionObject.prototype.onAdd.call(this, parent);
151
+ var self = this;
152
+ // Collect present fields
153
+ for (var i = 0; i < this.oneof.length; ++i) {
154
+ var field = parent.get(this.oneof[i]);
155
+ if (field && !field.partOf) {
156
+ field.partOf = self;
157
+ self.fieldsArray.push(field);
158
+ }
159
+ }
160
+ // Add not yet present fields
161
+ addFieldsToParent(this);
162
+ };
163
+
164
+ /**
165
+ * @override
166
+ */
167
+ OneOf.prototype.onRemove = function onRemove(parent) {
168
+ for (var i = 0, field; i < this.fieldsArray.length; ++i)
169
+ if ((field = this.fieldsArray[i]).parent)
170
+ field.parent.remove(field);
171
+ ReflectionObject.prototype.onRemove.call(this, parent);
172
+ };
173
+
174
+ /**
175
+ * Determines whether this field corresponds to a synthetic oneof created for
176
+ * a proto3 optional field. No behavioral logic should depend on this, but it
177
+ * can be relevant for reflection.
178
+ * @name OneOf#isProto3Optional
179
+ * @type {boolean}
180
+ * @readonly
181
+ */
182
+ Object.defineProperty(OneOf.prototype, "isProto3Optional", {
183
+ get: function() {
184
+ if (this.fieldsArray == null || this.fieldsArray.length !== 1) {
185
+ return false;
186
+ }
187
+
188
+ var field = this.fieldsArray[0];
189
+ return field.options != null && field.options["proto3_optional"] === true;
190
+ }
191
+ });
192
+
193
+ /**
194
+ * Decorator function as returned by {@link OneOf.d} (TypeScript).
195
+ * @typedef OneOfDecorator
196
+ * @type {function}
197
+ * @param {Object} prototype Target prototype
198
+ * @param {string} oneofName OneOf name
199
+ * @returns {undefined}
200
+ */
201
+
202
+ /**
203
+ * OneOf decorator (TypeScript).
204
+ * @function
205
+ * @param {...string} fieldNames Field names
206
+ * @returns {OneOfDecorator} Decorator function
207
+ * @template T extends string
208
+ */
209
+ OneOf.d = function decorateOneOf() {
210
+ var fieldNames = new Array(arguments.length),
211
+ index = 0;
212
+ while (index < arguments.length)
213
+ fieldNames[index] = arguments[index++];
214
+ return function oneOfDecorator(prototype, oneofName) {
215
+ util.decorateType(prototype.constructor)
216
+ .add(new OneOf(oneofName, fieldNames));
217
+ Object.defineProperty(prototype, oneofName, {
218
+ get: util.oneOfGetter(fieldNames),
219
+ set: util.oneOfSetter(fieldNames)
220
+ });
221
+ };
222
+ };