@ohos-ports/514labs-kafka-javascript 0.0.0-stage → 1.7.1-patch-beta.0

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 (639) hide show
  1. package/.claude/settings.local.json +12 -0
  2. package/.editorconfig +5 -0
  3. package/.envrc +1 -0
  4. package/CHANGELOG.md +380 -0
  5. package/CONTRIBUTING.md +257 -0
  6. package/INTRODUCTION.md +1155 -0
  7. package/LICENSE.kafkajs +31 -0
  8. package/LICENSE.node-rdkafka +25 -0
  9. package/LICENSE.txt +20 -0
  10. package/MIGRATION.md +428 -0
  11. package/Makefile +84 -0
  12. package/QUICKSTART.md +70 -0
  13. package/README.md +127 -2
  14. package/SECURITY.md +11 -0
  15. package/binding.gyp +167 -0
  16. package/buf.gen.yaml +8 -0
  17. package/build/Release/confluent-kafka-javascript.node +0 -0
  18. package/configure +15 -0
  19. package/coverage/mocha/base.css +224 -0
  20. package/coverage/mocha/block-navigation.js +87 -0
  21. package/coverage/mocha/coverage-final.json +11 -0
  22. package/coverage/mocha/favicon.png +0 -0
  23. package/coverage/mocha/forked-kafkajs/index.html +116 -0
  24. package/coverage/mocha/forked-kafkajs/lib/client.js.html +2122 -0
  25. package/coverage/mocha/forked-kafkajs/lib/error.js.html +1588 -0
  26. package/coverage/mocha/forked-kafkajs/lib/index.html +236 -0
  27. package/coverage/mocha/forked-kafkajs/lib/kafka-consumer-stream.js.html +1282 -0
  28. package/coverage/mocha/forked-kafkajs/lib/kafka-consumer.js.html +2476 -0
  29. package/coverage/mocha/forked-kafkajs/lib/producer-stream.js.html +1096 -0
  30. package/coverage/mocha/forked-kafkajs/lib/producer.js.html +1300 -0
  31. package/coverage/mocha/forked-kafkajs/lib/topic-partition.js.html +358 -0
  32. package/coverage/mocha/forked-kafkajs/lib/topic.js.html +214 -0
  33. package/coverage/mocha/forked-kafkajs/lib/util.js.html +250 -0
  34. package/coverage/mocha/forked-kafkajs/librdkafka.js.html +121 -0
  35. package/coverage/mocha/index.html +131 -0
  36. package/coverage/mocha/prettify.css +1 -0
  37. package/coverage/mocha/prettify.js +2 -0
  38. package/coverage/mocha/sort-arrow-sprite.png +0 -0
  39. package/coverage/mocha/sorter.js +210 -0
  40. package/cpplint.py +6970 -0
  41. package/deploy.enc +0 -0
  42. package/deps/librdkafka/.clang-format +136 -0
  43. package/deps/librdkafka/.clang-format-cpp +103 -0
  44. package/deps/librdkafka/.dir-locals.el +10 -0
  45. package/deps/librdkafka/.formatignore +33 -0
  46. package/deps/librdkafka/.gdbmacros +19 -0
  47. package/deps/librdkafka/CHANGELOG.md +2225 -0
  48. package/deps/librdkafka/CMakeLists.txt +291 -0
  49. package/deps/librdkafka/CODE_OF_CONDUCT.md +46 -0
  50. package/deps/librdkafka/CONFIGURATION.md +209 -0
  51. package/deps/librdkafka/CONTRIBUTING.md +431 -0
  52. package/deps/librdkafka/Doxyfile +2375 -0
  53. package/deps/librdkafka/INTRODUCTION.md +2481 -0
  54. package/deps/librdkafka/LICENSE +26 -0
  55. package/deps/librdkafka/LICENSE.cjson +22 -0
  56. package/deps/librdkafka/LICENSE.crc32c +28 -0
  57. package/deps/librdkafka/LICENSE.fnv1a +18 -0
  58. package/deps/librdkafka/LICENSE.hdrhistogram +27 -0
  59. package/deps/librdkafka/LICENSE.lz4 +26 -0
  60. package/deps/librdkafka/LICENSE.murmur2 +25 -0
  61. package/deps/librdkafka/LICENSE.nanopb +22 -0
  62. package/deps/librdkafka/LICENSE.opentelemetry +203 -0
  63. package/deps/librdkafka/LICENSE.pycrc +23 -0
  64. package/deps/librdkafka/LICENSE.queue +31 -0
  65. package/deps/librdkafka/LICENSE.regexp +5 -0
  66. package/deps/librdkafka/LICENSE.snappy +36 -0
  67. package/deps/librdkafka/LICENSE.tinycthread +26 -0
  68. package/deps/librdkafka/LICENSE.wingetopt +49 -0
  69. package/deps/librdkafka/LICENSES.txt +625 -0
  70. package/deps/librdkafka/Makefile +125 -0
  71. package/deps/librdkafka/README.md +199 -0
  72. package/deps/librdkafka/README.win32 +26 -0
  73. package/deps/librdkafka/STATISTICS.md +624 -0
  74. package/deps/librdkafka/configure +214 -0
  75. package/deps/librdkafka/configure.self +331 -0
  76. package/deps/librdkafka/dev-conf.sh +123 -0
  77. package/deps/librdkafka/lds-gen.py +73 -0
  78. package/deps/librdkafka/mainpage.doxy +40 -0
  79. package/deps/librdkafka/mklove/Makefile.base +329 -0
  80. package/deps/librdkafka/mklove/modules/configure.atomics +144 -0
  81. package/deps/librdkafka/mklove/modules/configure.base +2484 -0
  82. package/deps/librdkafka/mklove/modules/configure.builtin +70 -0
  83. package/deps/librdkafka/mklove/modules/configure.cc +186 -0
  84. package/deps/librdkafka/mklove/modules/configure.cxx +8 -0
  85. package/deps/librdkafka/mklove/modules/configure.fileversion +65 -0
  86. package/deps/librdkafka/mklove/modules/configure.gitversion +29 -0
  87. package/deps/librdkafka/mklove/modules/configure.good_cflags +18 -0
  88. package/deps/librdkafka/mklove/modules/configure.host +132 -0
  89. package/deps/librdkafka/mklove/modules/configure.lib +49 -0
  90. package/deps/librdkafka/mklove/modules/configure.libcurl +99 -0
  91. package/deps/librdkafka/mklove/modules/configure.libsasl2 +36 -0
  92. package/deps/librdkafka/mklove/modules/configure.libssl +147 -0
  93. package/deps/librdkafka/mklove/modules/configure.libzstd +58 -0
  94. package/deps/librdkafka/mklove/modules/configure.parseversion +95 -0
  95. package/deps/librdkafka/mklove/modules/configure.pic +16 -0
  96. package/deps/librdkafka/mklove/modules/configure.socket +20 -0
  97. package/deps/librdkafka/mklove/modules/configure.zlib +61 -0
  98. package/deps/librdkafka/mklove/modules/patches/README.md +8 -0
  99. package/deps/librdkafka/mklove/modules/patches/libcurl.0000-no-runtime-linking-check.patch +11 -0
  100. package/deps/librdkafka/mklove/modules/patches/libssl.0000-osx-rand-include-fix-OpenSSL-PR16409.patch +56 -0
  101. package/deps/librdkafka/service.yml +172 -0
  102. package/deps/librdkafka/src/CMakeLists.txt +374 -0
  103. package/deps/librdkafka/src/Makefile +103 -0
  104. package/deps/librdkafka/src/README.lz4.md +30 -0
  105. package/deps/librdkafka/src/cJSON.c +2834 -0
  106. package/deps/librdkafka/src/cJSON.h +398 -0
  107. package/deps/librdkafka/src/crc32c.c +430 -0
  108. package/deps/librdkafka/src/crc32c.h +38 -0
  109. package/deps/librdkafka/src/generate_proto.sh +66 -0
  110. package/deps/librdkafka/src/librdkafka_cgrp_synch.png +0 -0
  111. package/deps/librdkafka/src/lz4.c +2727 -0
  112. package/deps/librdkafka/src/lz4.h +842 -0
  113. package/deps/librdkafka/src/lz4frame.c +2078 -0
  114. package/deps/librdkafka/src/lz4frame.h +692 -0
  115. package/deps/librdkafka/src/lz4frame_static.h +47 -0
  116. package/deps/librdkafka/src/lz4hc.c +1631 -0
  117. package/deps/librdkafka/src/lz4hc.h +413 -0
  118. package/deps/librdkafka/src/nanopb/pb.h +917 -0
  119. package/deps/librdkafka/src/nanopb/pb_common.c +388 -0
  120. package/deps/librdkafka/src/nanopb/pb_common.h +49 -0
  121. package/deps/librdkafka/src/nanopb/pb_decode.c +1727 -0
  122. package/deps/librdkafka/src/nanopb/pb_decode.h +193 -0
  123. package/deps/librdkafka/src/nanopb/pb_encode.c +1000 -0
  124. package/deps/librdkafka/src/nanopb/pb_encode.h +185 -0
  125. package/deps/librdkafka/src/opentelemetry/common.pb.c +32 -0
  126. package/deps/librdkafka/src/opentelemetry/common.pb.h +170 -0
  127. package/deps/librdkafka/src/opentelemetry/metrics.options +2 -0
  128. package/deps/librdkafka/src/opentelemetry/metrics.pb.c +67 -0
  129. package/deps/librdkafka/src/opentelemetry/metrics.pb.h +966 -0
  130. package/deps/librdkafka/src/opentelemetry/resource.pb.c +12 -0
  131. package/deps/librdkafka/src/opentelemetry/resource.pb.h +58 -0
  132. package/deps/librdkafka/src/queue.h +850 -0
  133. package/deps/librdkafka/src/rd.h +584 -0
  134. package/deps/librdkafka/src/rdaddr.c +255 -0
  135. package/deps/librdkafka/src/rdaddr.h +202 -0
  136. package/deps/librdkafka/src/rdatomic.h +230 -0
  137. package/deps/librdkafka/src/rdavg.h +260 -0
  138. package/deps/librdkafka/src/rdavl.c +210 -0
  139. package/deps/librdkafka/src/rdavl.h +250 -0
  140. package/deps/librdkafka/src/rdbase64.c +200 -0
  141. package/deps/librdkafka/src/rdbase64.h +43 -0
  142. package/deps/librdkafka/src/rdbuf.c +1884 -0
  143. package/deps/librdkafka/src/rdbuf.h +375 -0
  144. package/deps/librdkafka/src/rdcrc32.c +114 -0
  145. package/deps/librdkafka/src/rdcrc32.h +170 -0
  146. package/deps/librdkafka/src/rddl.c +179 -0
  147. package/deps/librdkafka/src/rddl.h +43 -0
  148. package/deps/librdkafka/src/rdendian.h +175 -0
  149. package/deps/librdkafka/src/rdfloat.h +67 -0
  150. package/deps/librdkafka/src/rdfnv1a.c +113 -0
  151. package/deps/librdkafka/src/rdfnv1a.h +35 -0
  152. package/deps/librdkafka/src/rdgz.c +120 -0
  153. package/deps/librdkafka/src/rdgz.h +46 -0
  154. package/deps/librdkafka/src/rdhdrhistogram.c +721 -0
  155. package/deps/librdkafka/src/rdhdrhistogram.h +87 -0
  156. package/deps/librdkafka/src/rdhttp.c +830 -0
  157. package/deps/librdkafka/src/rdhttp.h +101 -0
  158. package/deps/librdkafka/src/rdinterval.h +177 -0
  159. package/deps/librdkafka/src/rdkafka.c +5505 -0
  160. package/deps/librdkafka/src/rdkafka.h +10686 -0
  161. package/deps/librdkafka/src/rdkafka_admin.c +9794 -0
  162. package/deps/librdkafka/src/rdkafka_admin.h +661 -0
  163. package/deps/librdkafka/src/rdkafka_assignment.c +1010 -0
  164. package/deps/librdkafka/src/rdkafka_assignment.h +73 -0
  165. package/deps/librdkafka/src/rdkafka_assignor.c +1786 -0
  166. package/deps/librdkafka/src/rdkafka_assignor.h +402 -0
  167. package/deps/librdkafka/src/rdkafka_aux.c +409 -0
  168. package/deps/librdkafka/src/rdkafka_aux.h +174 -0
  169. package/deps/librdkafka/src/rdkafka_background.c +221 -0
  170. package/deps/librdkafka/src/rdkafka_broker.c +6337 -0
  171. package/deps/librdkafka/src/rdkafka_broker.h +744 -0
  172. package/deps/librdkafka/src/rdkafka_buf.c +543 -0
  173. package/deps/librdkafka/src/rdkafka_buf.h +1525 -0
  174. package/deps/librdkafka/src/rdkafka_cert.c +576 -0
  175. package/deps/librdkafka/src/rdkafka_cert.h +62 -0
  176. package/deps/librdkafka/src/rdkafka_cgrp.c +7587 -0
  177. package/deps/librdkafka/src/rdkafka_cgrp.h +477 -0
  178. package/deps/librdkafka/src/rdkafka_conf.c +4880 -0
  179. package/deps/librdkafka/src/rdkafka_conf.h +732 -0
  180. package/deps/librdkafka/src/rdkafka_confval.h +97 -0
  181. package/deps/librdkafka/src/rdkafka_coord.c +623 -0
  182. package/deps/librdkafka/src/rdkafka_coord.h +132 -0
  183. package/deps/librdkafka/src/rdkafka_error.c +228 -0
  184. package/deps/librdkafka/src/rdkafka_error.h +80 -0
  185. package/deps/librdkafka/src/rdkafka_event.c +502 -0
  186. package/deps/librdkafka/src/rdkafka_event.h +126 -0
  187. package/deps/librdkafka/src/rdkafka_feature.c +898 -0
  188. package/deps/librdkafka/src/rdkafka_feature.h +104 -0
  189. package/deps/librdkafka/src/rdkafka_fetcher.c +1422 -0
  190. package/deps/librdkafka/src/rdkafka_fetcher.h +44 -0
  191. package/deps/librdkafka/src/rdkafka_header.c +220 -0
  192. package/deps/librdkafka/src/rdkafka_header.h +76 -0
  193. package/deps/librdkafka/src/rdkafka_idempotence.c +807 -0
  194. package/deps/librdkafka/src/rdkafka_idempotence.h +144 -0
  195. package/deps/librdkafka/src/rdkafka_int.h +1260 -0
  196. package/deps/librdkafka/src/rdkafka_interceptor.c +819 -0
  197. package/deps/librdkafka/src/rdkafka_interceptor.h +104 -0
  198. package/deps/librdkafka/src/rdkafka_lz4.c +450 -0
  199. package/deps/librdkafka/src/rdkafka_lz4.h +49 -0
  200. package/deps/librdkafka/src/rdkafka_metadata.c +2209 -0
  201. package/deps/librdkafka/src/rdkafka_metadata.h +345 -0
  202. package/deps/librdkafka/src/rdkafka_metadata_cache.c +1183 -0
  203. package/deps/librdkafka/src/rdkafka_mock.c +3661 -0
  204. package/deps/librdkafka/src/rdkafka_mock.h +610 -0
  205. package/deps/librdkafka/src/rdkafka_mock_cgrp.c +1876 -0
  206. package/deps/librdkafka/src/rdkafka_mock_handlers.c +3113 -0
  207. package/deps/librdkafka/src/rdkafka_mock_int.h +710 -0
  208. package/deps/librdkafka/src/rdkafka_msg.c +2589 -0
  209. package/deps/librdkafka/src/rdkafka_msg.h +614 -0
  210. package/deps/librdkafka/src/rdkafka_msgbatch.h +62 -0
  211. package/deps/librdkafka/src/rdkafka_msgset.h +98 -0
  212. package/deps/librdkafka/src/rdkafka_msgset_reader.c +1806 -0
  213. package/deps/librdkafka/src/rdkafka_msgset_writer.c +1474 -0
  214. package/deps/librdkafka/src/rdkafka_offset.c +1565 -0
  215. package/deps/librdkafka/src/rdkafka_offset.h +150 -0
  216. package/deps/librdkafka/src/rdkafka_op.c +997 -0
  217. package/deps/librdkafka/src/rdkafka_op.h +858 -0
  218. package/deps/librdkafka/src/rdkafka_partition.c +4896 -0
  219. package/deps/librdkafka/src/rdkafka_partition.h +1182 -0
  220. package/deps/librdkafka/src/rdkafka_pattern.c +228 -0
  221. package/deps/librdkafka/src/rdkafka_pattern.h +70 -0
  222. package/deps/librdkafka/src/rdkafka_plugin.c +213 -0
  223. package/deps/librdkafka/src/rdkafka_plugin.h +41 -0
  224. package/deps/librdkafka/src/rdkafka_proto.h +736 -0
  225. package/deps/librdkafka/src/rdkafka_protocol.h +128 -0
  226. package/deps/librdkafka/src/rdkafka_queue.c +1230 -0
  227. package/deps/librdkafka/src/rdkafka_queue.h +1220 -0
  228. package/deps/librdkafka/src/rdkafka_range_assignor.c +1748 -0
  229. package/deps/librdkafka/src/rdkafka_request.c +7089 -0
  230. package/deps/librdkafka/src/rdkafka_request.h +732 -0
  231. package/deps/librdkafka/src/rdkafka_roundrobin_assignor.c +123 -0
  232. package/deps/librdkafka/src/rdkafka_sasl.c +530 -0
  233. package/deps/librdkafka/src/rdkafka_sasl.h +63 -0
  234. package/deps/librdkafka/src/rdkafka_sasl_cyrus.c +722 -0
  235. package/deps/librdkafka/src/rdkafka_sasl_int.h +89 -0
  236. package/deps/librdkafka/src/rdkafka_sasl_oauthbearer.c +1833 -0
  237. package/deps/librdkafka/src/rdkafka_sasl_oauthbearer.h +52 -0
  238. package/deps/librdkafka/src/rdkafka_sasl_oauthbearer_oidc.c +1666 -0
  239. package/deps/librdkafka/src/rdkafka_sasl_oauthbearer_oidc.h +47 -0
  240. package/deps/librdkafka/src/rdkafka_sasl_plain.c +142 -0
  241. package/deps/librdkafka/src/rdkafka_sasl_scram.c +858 -0
  242. package/deps/librdkafka/src/rdkafka_sasl_win32.c +550 -0
  243. package/deps/librdkafka/src/rdkafka_ssl.c +2129 -0
  244. package/deps/librdkafka/src/rdkafka_ssl.h +86 -0
  245. package/deps/librdkafka/src/rdkafka_sticky_assignor.c +4785 -0
  246. package/deps/librdkafka/src/rdkafka_subscription.c +278 -0
  247. package/deps/librdkafka/src/rdkafka_telemetry.c +760 -0
  248. package/deps/librdkafka/src/rdkafka_telemetry.h +52 -0
  249. package/deps/librdkafka/src/rdkafka_telemetry_decode.c +1053 -0
  250. package/deps/librdkafka/src/rdkafka_telemetry_decode.h +59 -0
  251. package/deps/librdkafka/src/rdkafka_telemetry_encode.c +997 -0
  252. package/deps/librdkafka/src/rdkafka_telemetry_encode.h +301 -0
  253. package/deps/librdkafka/src/rdkafka_timer.c +402 -0
  254. package/deps/librdkafka/src/rdkafka_timer.h +117 -0
  255. package/deps/librdkafka/src/rdkafka_topic.c +2161 -0
  256. package/deps/librdkafka/src/rdkafka_topic.h +334 -0
  257. package/deps/librdkafka/src/rdkafka_transport.c +1309 -0
  258. package/deps/librdkafka/src/rdkafka_transport.h +99 -0
  259. package/deps/librdkafka/src/rdkafka_transport_int.h +100 -0
  260. package/deps/librdkafka/src/rdkafka_txnmgr.c +3256 -0
  261. package/deps/librdkafka/src/rdkafka_txnmgr.h +171 -0
  262. package/deps/librdkafka/src/rdkafka_zstd.c +226 -0
  263. package/deps/librdkafka/src/rdkafka_zstd.h +57 -0
  264. package/deps/librdkafka/src/rdlist.c +576 -0
  265. package/deps/librdkafka/src/rdlist.h +434 -0
  266. package/deps/librdkafka/src/rdlog.c +89 -0
  267. package/deps/librdkafka/src/rdlog.h +41 -0
  268. package/deps/librdkafka/src/rdmap.c +508 -0
  269. package/deps/librdkafka/src/rdmap.h +492 -0
  270. package/deps/librdkafka/src/rdmurmur2.c +167 -0
  271. package/deps/librdkafka/src/rdmurmur2.h +35 -0
  272. package/deps/librdkafka/src/rdports.c +61 -0
  273. package/deps/librdkafka/src/rdports.h +38 -0
  274. package/deps/librdkafka/src/rdposix.h +250 -0
  275. package/deps/librdkafka/src/rdrand.c +80 -0
  276. package/deps/librdkafka/src/rdrand.h +43 -0
  277. package/deps/librdkafka/src/rdregex.c +156 -0
  278. package/deps/librdkafka/src/rdregex.h +43 -0
  279. package/deps/librdkafka/src/rdsignal.h +57 -0
  280. package/deps/librdkafka/src/rdstring.c +645 -0
  281. package/deps/librdkafka/src/rdstring.h +98 -0
  282. package/deps/librdkafka/src/rdsysqueue.h +404 -0
  283. package/deps/librdkafka/src/rdtime.h +356 -0
  284. package/deps/librdkafka/src/rdtypes.h +86 -0
  285. package/deps/librdkafka/src/rdunittest.c +549 -0
  286. package/deps/librdkafka/src/rdunittest.h +232 -0
  287. package/deps/librdkafka/src/rdvarint.c +134 -0
  288. package/deps/librdkafka/src/rdvarint.h +165 -0
  289. package/deps/librdkafka/src/rdwin32.h +382 -0
  290. package/deps/librdkafka/src/rdxxhash.c +1030 -0
  291. package/deps/librdkafka/src/rdxxhash.h +328 -0
  292. package/deps/librdkafka/src/regexp.c +1352 -0
  293. package/deps/librdkafka/src/regexp.h +41 -0
  294. package/deps/librdkafka/src/snappy.c +1866 -0
  295. package/deps/librdkafka/src/snappy.h +62 -0
  296. package/deps/librdkafka/src/snappy_compat.h +138 -0
  297. package/deps/librdkafka/src/statistics_schema.json +444 -0
  298. package/deps/librdkafka/src/tinycthread.c +932 -0
  299. package/deps/librdkafka/src/tinycthread.h +503 -0
  300. package/deps/librdkafka/src/tinycthread_extra.c +199 -0
  301. package/deps/librdkafka/src/tinycthread_extra.h +212 -0
  302. package/deps/librdkafka/src/win32_config.h +58 -0
  303. package/deps/librdkafka/src-cpp/CMakeLists.txt +90 -0
  304. package/deps/librdkafka/src-cpp/ConfImpl.cpp +84 -0
  305. package/deps/librdkafka/src-cpp/ConsumerImpl.cpp +244 -0
  306. package/deps/librdkafka/src-cpp/HandleImpl.cpp +436 -0
  307. package/deps/librdkafka/src-cpp/HeadersImpl.cpp +48 -0
  308. package/deps/librdkafka/src-cpp/KafkaConsumerImpl.cpp +296 -0
  309. package/deps/librdkafka/src-cpp/Makefile +55 -0
  310. package/deps/librdkafka/src-cpp/MessageImpl.cpp +38 -0
  311. package/deps/librdkafka/src-cpp/MetadataImpl.cpp +170 -0
  312. package/deps/librdkafka/src-cpp/ProducerImpl.cpp +197 -0
  313. package/deps/librdkafka/src-cpp/QueueImpl.cpp +70 -0
  314. package/deps/librdkafka/src-cpp/README.md +16 -0
  315. package/deps/librdkafka/src-cpp/RdKafka.cpp +59 -0
  316. package/deps/librdkafka/src-cpp/TopicImpl.cpp +124 -0
  317. package/deps/librdkafka/src-cpp/TopicPartitionImpl.cpp +57 -0
  318. package/deps/librdkafka/src-cpp/rdkafkacpp.h +3797 -0
  319. package/deps/librdkafka/src-cpp/rdkafkacpp_int.h +1641 -0
  320. package/deps/librdkafka/tests/0000-unittests.c +72 -0
  321. package/deps/librdkafka/tests/0001-multiobj.c +102 -0
  322. package/deps/librdkafka/tests/0002-unkpart.c +244 -0
  323. package/deps/librdkafka/tests/0003-msgmaxsize.c +173 -0
  324. package/deps/librdkafka/tests/0004-conf.c +934 -0
  325. package/deps/librdkafka/tests/0005-order.c +133 -0
  326. package/deps/librdkafka/tests/0006-symbols.c +163 -0
  327. package/deps/librdkafka/tests/0007-autotopic.c +136 -0
  328. package/deps/librdkafka/tests/0008-reqacks.c +179 -0
  329. package/deps/librdkafka/tests/0009-mock_cluster.c +97 -0
  330. package/deps/librdkafka/tests/0011-produce_batch.c +753 -0
  331. package/deps/librdkafka/tests/0012-produce_consume.c +537 -0
  332. package/deps/librdkafka/tests/0013-null-msgs.c +473 -0
  333. package/deps/librdkafka/tests/0014-reconsume-191.c +512 -0
  334. package/deps/librdkafka/tests/0015-offset_seeks.c +172 -0
  335. package/deps/librdkafka/tests/0016-client_swname.c +181 -0
  336. package/deps/librdkafka/tests/0017-compression.c +140 -0
  337. package/deps/librdkafka/tests/0018-cgrp_term.c +338 -0
  338. package/deps/librdkafka/tests/0019-list_groups.c +289 -0
  339. package/deps/librdkafka/tests/0020-destroy_hang.c +162 -0
  340. package/deps/librdkafka/tests/0021-rkt_destroy.c +72 -0
  341. package/deps/librdkafka/tests/0022-consume_batch.c +279 -0
  342. package/deps/librdkafka/tests/0025-timers.c +147 -0
  343. package/deps/librdkafka/tests/0026-consume_pause.c +547 -0
  344. package/deps/librdkafka/tests/0028-long_topicnames.c +79 -0
  345. package/deps/librdkafka/tests/0029-assign_offset.c +202 -0
  346. package/deps/librdkafka/tests/0030-offset_commit.c +589 -0
  347. package/deps/librdkafka/tests/0031-get_offsets.c +235 -0
  348. package/deps/librdkafka/tests/0033-regex_subscribe.c +536 -0
  349. package/deps/librdkafka/tests/0034-offset_reset.c +398 -0
  350. package/deps/librdkafka/tests/0035-api_version.c +73 -0
  351. package/deps/librdkafka/tests/0036-partial_fetch.c +87 -0
  352. package/deps/librdkafka/tests/0037-destroy_hang_local.c +85 -0
  353. package/deps/librdkafka/tests/0038-performance.c +121 -0
  354. package/deps/librdkafka/tests/0039-event.c +284 -0
  355. package/deps/librdkafka/tests/0040-io_event.c +257 -0
  356. package/deps/librdkafka/tests/0041-fetch_max_bytes.c +97 -0
  357. package/deps/librdkafka/tests/0042-many_topics.c +252 -0
  358. package/deps/librdkafka/tests/0043-no_connection.c +77 -0
  359. package/deps/librdkafka/tests/0044-partition_cnt.c +94 -0
  360. package/deps/librdkafka/tests/0045-subscribe_update.c +1010 -0
  361. package/deps/librdkafka/tests/0046-rkt_cache.c +65 -0
  362. package/deps/librdkafka/tests/0047-partial_buf_tmout.c +98 -0
  363. package/deps/librdkafka/tests/0048-partitioner.c +283 -0
  364. package/deps/librdkafka/tests/0049-consume_conn_close.c +162 -0
  365. package/deps/librdkafka/tests/0050-subscribe_adds.c +145 -0
  366. package/deps/librdkafka/tests/0051-assign_adds.c +126 -0
  367. package/deps/librdkafka/tests/0052-msg_timestamps.c +238 -0
  368. package/deps/librdkafka/tests/0053-stats_cb.cpp +527 -0
  369. package/deps/librdkafka/tests/0054-offset_time.cpp +236 -0
  370. package/deps/librdkafka/tests/0055-producer_latency.c +539 -0
  371. package/deps/librdkafka/tests/0056-balanced_group_mt.c +315 -0
  372. package/deps/librdkafka/tests/0057-invalid_topic.cpp +112 -0
  373. package/deps/librdkafka/tests/0058-log.cpp +123 -0
  374. package/deps/librdkafka/tests/0059-bsearch.cpp +241 -0
  375. package/deps/librdkafka/tests/0060-op_prio.cpp +163 -0
  376. package/deps/librdkafka/tests/0061-consumer_lag.cpp +295 -0
  377. package/deps/librdkafka/tests/0062-stats_event.c +126 -0
  378. package/deps/librdkafka/tests/0063-clusterid.cpp +180 -0
  379. package/deps/librdkafka/tests/0064-interceptors.c +481 -0
  380. package/deps/librdkafka/tests/0065-yield.cpp +140 -0
  381. package/deps/librdkafka/tests/0066-plugins.cpp +129 -0
  382. package/deps/librdkafka/tests/0067-empty_topic.cpp +151 -0
  383. package/deps/librdkafka/tests/0068-produce_timeout.c +136 -0
  384. package/deps/librdkafka/tests/0069-consumer_add_parts.c +119 -0
  385. package/deps/librdkafka/tests/0070-null_empty.cpp +197 -0
  386. package/deps/librdkafka/tests/0072-headers_ut.c +448 -0
  387. package/deps/librdkafka/tests/0073-headers.c +381 -0
  388. package/deps/librdkafka/tests/0074-producev.c +87 -0
  389. package/deps/librdkafka/tests/0075-retry.c +290 -0
  390. package/deps/librdkafka/tests/0076-produce_retry.c +452 -0
  391. package/deps/librdkafka/tests/0077-compaction.c +363 -0
  392. package/deps/librdkafka/tests/0078-c_from_cpp.cpp +96 -0
  393. package/deps/librdkafka/tests/0079-fork.c +93 -0
  394. package/deps/librdkafka/tests/0080-admin_ut.c +3095 -0
  395. package/deps/librdkafka/tests/0081-admin.c +5633 -0
  396. package/deps/librdkafka/tests/0082-fetch_max_bytes.cpp +137 -0
  397. package/deps/librdkafka/tests/0083-cb_event.c +233 -0
  398. package/deps/librdkafka/tests/0084-destroy_flags.c +208 -0
  399. package/deps/librdkafka/tests/0085-headers.cpp +392 -0
  400. package/deps/librdkafka/tests/0086-purge.c +368 -0
  401. package/deps/librdkafka/tests/0088-produce_metadata_timeout.c +162 -0
  402. package/deps/librdkafka/tests/0089-max_poll_interval.c +511 -0
  403. package/deps/librdkafka/tests/0090-idempotence.c +171 -0
  404. package/deps/librdkafka/tests/0091-max_poll_interval_timeout.c +295 -0
  405. package/deps/librdkafka/tests/0092-mixed_msgver.c +103 -0
  406. package/deps/librdkafka/tests/0093-holb.c +200 -0
  407. package/deps/librdkafka/tests/0094-idempotence_msg_timeout.c +231 -0
  408. package/deps/librdkafka/tests/0095-all_brokers_down.cpp +122 -0
  409. package/deps/librdkafka/tests/0097-ssl_verify.cpp +658 -0
  410. package/deps/librdkafka/tests/0098-consumer-txn.cpp +1218 -0
  411. package/deps/librdkafka/tests/0099-commit_metadata.c +194 -0
  412. package/deps/librdkafka/tests/0100-thread_interceptors.cpp +195 -0
  413. package/deps/librdkafka/tests/0101-fetch-from-follower.cpp +446 -0
  414. package/deps/librdkafka/tests/0102-static_group_rebalance.c +836 -0
  415. package/deps/librdkafka/tests/0103-transactions.c +1383 -0
  416. package/deps/librdkafka/tests/0104-fetch_from_follower_mock.c +625 -0
  417. package/deps/librdkafka/tests/0105-transactions_mock.c +3930 -0
  418. package/deps/librdkafka/tests/0106-cgrp_sess_timeout.c +318 -0
  419. package/deps/librdkafka/tests/0107-topic_recreate.c +259 -0
  420. package/deps/librdkafka/tests/0109-auto_create_topics.cpp +278 -0
  421. package/deps/librdkafka/tests/0110-batch_size.cpp +182 -0
  422. package/deps/librdkafka/tests/0111-delay_create_topics.cpp +127 -0
  423. package/deps/librdkafka/tests/0112-assign_unknown_part.c +87 -0
  424. package/deps/librdkafka/tests/0113-cooperative_rebalance.cpp +3473 -0
  425. package/deps/librdkafka/tests/0114-sticky_partitioning.cpp +176 -0
  426. package/deps/librdkafka/tests/0115-producer_auth.cpp +182 -0
  427. package/deps/librdkafka/tests/0116-kafkaconsumer_close.cpp +216 -0
  428. package/deps/librdkafka/tests/0117-mock_errors.c +331 -0
  429. package/deps/librdkafka/tests/0118-commit_rebalance.c +154 -0
  430. package/deps/librdkafka/tests/0119-consumer_auth.cpp +167 -0
  431. package/deps/librdkafka/tests/0120-asymmetric_subscription.c +185 -0
  432. package/deps/librdkafka/tests/0121-clusterid.c +115 -0
  433. package/deps/librdkafka/tests/0122-buffer_cleaning_after_rebalance.c +227 -0
  434. package/deps/librdkafka/tests/0123-connections_max_idle.c +98 -0
  435. package/deps/librdkafka/tests/0124-openssl_invalid_engine.c +69 -0
  436. package/deps/librdkafka/tests/0125-immediate_flush.c +144 -0
  437. package/deps/librdkafka/tests/0126-oauthbearer_oidc.c +528 -0
  438. package/deps/librdkafka/tests/0127-fetch_queue_backoff.cpp +165 -0
  439. package/deps/librdkafka/tests/0128-sasl_callback_queue.cpp +125 -0
  440. package/deps/librdkafka/tests/0129-fetch_aborted_msgs.c +79 -0
  441. package/deps/librdkafka/tests/0130-store_offsets.c +178 -0
  442. package/deps/librdkafka/tests/0131-connect_timeout.c +81 -0
  443. package/deps/librdkafka/tests/0132-strategy_ordering.c +179 -0
  444. package/deps/librdkafka/tests/0133-ssl_keys.c +150 -0
  445. package/deps/librdkafka/tests/0134-ssl_provider.c +92 -0
  446. package/deps/librdkafka/tests/0135-sasl_credentials.cpp +143 -0
  447. package/deps/librdkafka/tests/0136-resolve_cb.c +181 -0
  448. package/deps/librdkafka/tests/0137-barrier_batch_consume.c +619 -0
  449. package/deps/librdkafka/tests/0138-admin_mock.c +281 -0
  450. package/deps/librdkafka/tests/0139-offset_validation_mock.c +950 -0
  451. package/deps/librdkafka/tests/0140-commit_metadata.cpp +108 -0
  452. package/deps/librdkafka/tests/0142-reauthentication.c +515 -0
  453. package/deps/librdkafka/tests/0143-exponential_backoff_mock.c +552 -0
  454. package/deps/librdkafka/tests/0144-idempotence_mock.c +373 -0
  455. package/deps/librdkafka/tests/0145-pause_resume_mock.c +119 -0
  456. package/deps/librdkafka/tests/0146-metadata_mock.c +505 -0
  457. package/deps/librdkafka/tests/0147-consumer_group_consumer_mock.c +952 -0
  458. package/deps/librdkafka/tests/0148-offset_fetch_commit_error_mock.c +563 -0
  459. package/deps/librdkafka/tests/0149-broker-same-host-port.c +140 -0
  460. package/deps/librdkafka/tests/0150-telemetry_mock.c +651 -0
  461. package/deps/librdkafka/tests/0151-purge-brokers.c +566 -0
  462. package/deps/librdkafka/tests/0152-rebootstrap.c +59 -0
  463. package/deps/librdkafka/tests/0153-memberid.c +128 -0
  464. package/deps/librdkafka/tests/1000-unktopic.c +164 -0
  465. package/deps/librdkafka/tests/8000-idle.cpp +60 -0
  466. package/deps/librdkafka/tests/8001-fetch_from_follower_mock_manual.c +113 -0
  467. package/deps/librdkafka/tests/CMakeLists.txt +170 -0
  468. package/deps/librdkafka/tests/LibrdkafkaTestApp.py +291 -0
  469. package/deps/librdkafka/tests/Makefile +182 -0
  470. package/deps/librdkafka/tests/README.md +509 -0
  471. package/deps/librdkafka/tests/autotest.sh +33 -0
  472. package/deps/librdkafka/tests/backtrace.gdb +30 -0
  473. package/deps/librdkafka/tests/broker_version_tests.py +315 -0
  474. package/deps/librdkafka/tests/buildbox.sh +17 -0
  475. package/deps/librdkafka/tests/cleanup-checker-tests.sh +20 -0
  476. package/deps/librdkafka/tests/cluster_testing.py +191 -0
  477. package/deps/librdkafka/tests/delete-test-topics.sh +56 -0
  478. package/deps/librdkafka/tests/fixtures/oauthbearer/jwt_assertion_template.json +10 -0
  479. package/deps/librdkafka/tests/fixtures/ssl/Makefile +8 -0
  480. package/deps/librdkafka/tests/fixtures/ssl/README.md +13 -0
  481. package/deps/librdkafka/tests/fixtures/ssl/client.keystore.intermediate.p12 +0 -0
  482. package/deps/librdkafka/tests/fixtures/ssl/client.keystore.p12 +0 -0
  483. package/deps/librdkafka/tests/fixtures/ssl/client2.certificate.intermediate.pem +72 -0
  484. package/deps/librdkafka/tests/fixtures/ssl/client2.certificate.pem +50 -0
  485. package/deps/librdkafka/tests/fixtures/ssl/client2.intermediate.key +46 -0
  486. package/deps/librdkafka/tests/fixtures/ssl/client2.key +46 -0
  487. package/deps/librdkafka/tests/fixtures/ssl/create_keys.sh +168 -0
  488. package/deps/librdkafka/tests/fuzzers/Makefile +12 -0
  489. package/deps/librdkafka/tests/fuzzers/README.md +31 -0
  490. package/deps/librdkafka/tests/fuzzers/fuzz_regex.c +74 -0
  491. package/deps/librdkafka/tests/fuzzers/helpers.h +90 -0
  492. package/deps/librdkafka/tests/gen-ssl-certs.sh +165 -0
  493. package/deps/librdkafka/tests/interactive_broker_version.py +170 -0
  494. package/deps/librdkafka/tests/interceptor_test/CMakeLists.txt +16 -0
  495. package/deps/librdkafka/tests/interceptor_test/Makefile +22 -0
  496. package/deps/librdkafka/tests/interceptor_test/interceptor_test.c +314 -0
  497. package/deps/librdkafka/tests/interceptor_test/interceptor_test.h +54 -0
  498. package/deps/librdkafka/tests/java/IncrementalRebalanceCli.java +97 -0
  499. package/deps/librdkafka/tests/java/Makefile +13 -0
  500. package/deps/librdkafka/tests/java/Murmur2Cli.java +46 -0
  501. package/deps/librdkafka/tests/java/README.md +14 -0
  502. package/deps/librdkafka/tests/java/TransactionProducerCli.java +162 -0
  503. package/deps/librdkafka/tests/java/run-class.sh +11 -0
  504. package/deps/librdkafka/tests/librdkafka.suppressions +483 -0
  505. package/deps/librdkafka/tests/lz4_manual_test.sh +59 -0
  506. package/deps/librdkafka/tests/multi-broker-version-test.sh +50 -0
  507. package/deps/librdkafka/tests/parse-refcnt.sh +43 -0
  508. package/deps/librdkafka/tests/performance_plot.py +115 -0
  509. package/deps/librdkafka/tests/plugin_test/Makefile +19 -0
  510. package/deps/librdkafka/tests/plugin_test/plugin_test.c +58 -0
  511. package/deps/librdkafka/tests/requirements.txt +2 -0
  512. package/deps/librdkafka/tests/run-all-tests.sh +79 -0
  513. package/deps/librdkafka/tests/run-consumer-tests.sh +16 -0
  514. package/deps/librdkafka/tests/run-producer-tests.sh +16 -0
  515. package/deps/librdkafka/tests/run-test-batches.py +157 -0
  516. package/deps/librdkafka/tests/run-test.sh +140 -0
  517. package/deps/librdkafka/tests/rusage.c +249 -0
  518. package/deps/librdkafka/tests/sasl_test.py +289 -0
  519. package/deps/librdkafka/tests/scenarios/README.md +6 -0
  520. package/deps/librdkafka/tests/scenarios/ak23.json +6 -0
  521. package/deps/librdkafka/tests/scenarios/default.json +5 -0
  522. package/deps/librdkafka/tests/scenarios/noautocreate.json +5 -0
  523. package/deps/librdkafka/tests/sockem.c +801 -0
  524. package/deps/librdkafka/tests/sockem.h +85 -0
  525. package/deps/librdkafka/tests/sockem_ctrl.c +145 -0
  526. package/deps/librdkafka/tests/sockem_ctrl.h +61 -0
  527. package/deps/librdkafka/tests/test.c +7778 -0
  528. package/deps/librdkafka/tests/test.conf.example +27 -0
  529. package/deps/librdkafka/tests/test.h +1028 -0
  530. package/deps/librdkafka/tests/testcpp.cpp +131 -0
  531. package/deps/librdkafka/tests/testcpp.h +388 -0
  532. package/deps/librdkafka/tests/testshared.h +416 -0
  533. package/deps/librdkafka/tests/tools/README.md +4 -0
  534. package/deps/librdkafka/tests/tools/stats/README.md +21 -0
  535. package/deps/librdkafka/tests/tools/stats/filter.jq +42 -0
  536. package/deps/librdkafka/tests/tools/stats/graph.py +150 -0
  537. package/deps/librdkafka/tests/tools/stats/requirements.txt +3 -0
  538. package/deps/librdkafka/tests/tools/stats/to_csv.py +124 -0
  539. package/deps/librdkafka/tests/trivup/trivup-0.14.0.tar.gz +0 -0
  540. package/deps/librdkafka/tests/until-fail.sh +87 -0
  541. package/deps/librdkafka/tests/xxxx-assign_partition.c +122 -0
  542. package/deps/librdkafka/tests/xxxx-metadata.cpp +159 -0
  543. package/deps/librdkafka/vcpkg.json +23 -0
  544. package/deps/librdkafka/win32/README.md +5 -0
  545. package/deps/librdkafka/win32/build-package.bat +3 -0
  546. package/deps/librdkafka/win32/build.bat +19 -0
  547. package/deps/librdkafka/win32/common.vcxproj +84 -0
  548. package/deps/librdkafka/win32/interceptor_test/interceptor_test.vcxproj +87 -0
  549. package/deps/librdkafka/win32/librdkafka.autopkg.template +54 -0
  550. package/deps/librdkafka/win32/librdkafka.master.testing.targets +13 -0
  551. package/deps/librdkafka/win32/librdkafka.sln +226 -0
  552. package/deps/librdkafka/win32/librdkafka.vcxproj +276 -0
  553. package/deps/librdkafka/win32/librdkafkacpp/librdkafkacpp.vcxproj +104 -0
  554. package/deps/librdkafka/win32/msbuild.ps1 +15 -0
  555. package/deps/librdkafka/win32/openssl_engine_example/openssl_engine_example.vcxproj +132 -0
  556. package/deps/librdkafka/win32/package-zip.ps1 +46 -0
  557. package/deps/librdkafka/win32/packages/repositories.config +4 -0
  558. package/deps/librdkafka/win32/push-package.bat +4 -0
  559. package/deps/librdkafka/win32/rdkafka_complex_consumer_example_cpp/rdkafka_complex_consumer_example_cpp.vcxproj +67 -0
  560. package/deps/librdkafka/win32/rdkafka_example/rdkafka_example.vcxproj +97 -0
  561. package/deps/librdkafka/win32/rdkafka_performance/rdkafka_performance.vcxproj +97 -0
  562. package/deps/librdkafka/win32/setup-msys2.ps1 +47 -0
  563. package/deps/librdkafka/win32/setup-vcpkg.ps1 +34 -0
  564. package/deps/librdkafka/win32/tests/test.conf.example +25 -0
  565. package/deps/librdkafka/win32/tests/tests.vcxproj +253 -0
  566. package/deps/librdkafka/win32/win_ssl_cert_store/win_ssl_cert_store.vcxproj +132 -0
  567. package/deps/librdkafka/win32/wingetopt.c +564 -0
  568. package/deps/librdkafka/win32/wingetopt.h +101 -0
  569. package/deps/librdkafka/win32/wintime.h +33 -0
  570. package/deps/librdkafka.gyp +83 -0
  571. package/deps/windows-install.py +80 -0
  572. package/eslint.config.js +75 -0
  573. package/flake.lock +61 -0
  574. package/flake.nix +76 -0
  575. package/index.d.ts +3 -0
  576. package/jest.config.js +8 -0
  577. package/jsdoc.conf +23 -0
  578. package/lib/admin.js +732 -0
  579. package/lib/client.js +679 -0
  580. package/lib/error.js +501 -0
  581. package/lib/index.js +8 -0
  582. package/lib/kafka-consumer-stream.js +399 -0
  583. package/lib/kafka-consumer.js +798 -0
  584. package/lib/kafkajs/_admin.js +1053 -0
  585. package/lib/kafkajs/_common.js +887 -0
  586. package/lib/kafkajs/_consumer.js +2143 -0
  587. package/lib/kafkajs/_consumer_cache.js +310 -0
  588. package/lib/kafkajs/_error.js +298 -0
  589. package/lib/kafkajs/_kafka.js +125 -0
  590. package/lib/kafkajs/_linked-list.js +220 -0
  591. package/lib/kafkajs/_producer.js +863 -0
  592. package/lib/kafkajs/index.js +5 -0
  593. package/lib/producer/high-level-producer.js +400 -0
  594. package/lib/producer-stream.js +337 -0
  595. package/lib/producer.js +405 -0
  596. package/lib/rdkafka.js +44 -0
  597. package/lib/tools/ref-counter.js +53 -0
  598. package/lib/topic-partition.js +91 -0
  599. package/lib/topic.js +43 -0
  600. package/lib/util.js +55 -0
  601. package/librdkafka.js +12 -0
  602. package/make_docs.sh +57 -0
  603. package/package.json +59 -4
  604. package/run_docker.sh +42 -0
  605. package/service.yml +36 -0
  606. package/sonar-project.properties +9 -0
  607. package/src/admin.cc +1597 -0
  608. package/src/admin.h +112 -0
  609. package/src/binding.cc +76 -0
  610. package/src/binding.h +25 -0
  611. package/src/callbacks.cc +676 -0
  612. package/src/callbacks.h +302 -0
  613. package/src/common.cc +1601 -0
  614. package/src/common.h +192 -0
  615. package/src/config.cc +219 -0
  616. package/src/config.h +61 -0
  617. package/src/connection.cc +703 -0
  618. package/src/connection.h +117 -0
  619. package/src/errors.cc +119 -0
  620. package/src/errors.h +60 -0
  621. package/src/kafka-consumer.cc +1539 -0
  622. package/src/kafka-consumer.h +147 -0
  623. package/src/producer.cc +917 -0
  624. package/src/producer.h +124 -0
  625. package/src/topic.cc +173 -0
  626. package/src/topic.h +54 -0
  627. package/src/workers.cc +1714 -0
  628. package/src/workers.h +690 -0
  629. package/tsconfig.json +18 -0
  630. package/types/config.d.ts +1248 -0
  631. package/types/errors.d.ts +373 -0
  632. package/types/kafkajs.d.ts +568 -0
  633. package/types/rdkafka.d.ts +561 -0
  634. package/util/configure.js +34 -0
  635. package/util/generate-docs.sh +18 -0
  636. package/util/get-env.js +6 -0
  637. package/util/test-compile.js +11 -0
  638. package/util/test-producer-delivery.js +100 -0
  639. package/win_install.ps1 +2 -0
@@ -0,0 +1,1053 @@
1
+ const { OffsetSpec } = require('../admin');
2
+ const RdKafka = require('../rdkafka');
3
+ const { kafkaJSToRdKafkaConfig,
4
+ createKafkaJsErrorFromLibRdKafkaError,
5
+ DefaultLogger,
6
+ CompatibilityErrorMessages,
7
+ createBindingMessageMetadata,
8
+ logLevel,
9
+ checkAllowedKeys,
10
+ loggerTrampoline,
11
+ severityToLogLevel,
12
+ } = require('./_common');
13
+ const error = require('./_error');
14
+ const { hrtime } = require('process');
15
+
16
+ const AdminState = Object.freeze({
17
+ INIT: 0,
18
+ CONNECTING: 1,
19
+ CONNECTED: 4,
20
+ DISCONNECTING: 5,
21
+ DISCONNECTED: 6,
22
+ });
23
+
24
+ /**
25
+ * Admin client for administering Kafka clusters (promise-based, async API).
26
+ *
27
+ * This client is the way you can interface with the Kafka Admin APIs.
28
+ * This class should not be instantiated directly, and rather, an instance of
29
+ * [Kafka]{@link KafkaJS.Kafka} should be used to create it, or an existing
30
+ * Producer or Consumer's `dependentAdmin` method may be used.
31
+ *
32
+ * @example
33
+ * const { Kafka } = require('@confluentinc/kafka-javascript');
34
+ * // From a Kafka object.
35
+ * const kafka = new Kafka({ 'bootstrap.servers': 'localhost:9092' });
36
+ * const admin = kafka.admin();
37
+ * await admin.connect();
38
+ * await admin.createTopics({ });
39
+ *
40
+ * // From a producer/consumer
41
+ * const admin = preExistingProducer.dependentAdmin();
42
+ * await admin.connect();
43
+ * await admin.createTopics({ });
44
+ *
45
+ * @memberof KafkaJS
46
+ * @see [Admin client examples]{@link https://github.com/confluentinc/confluent-kafka-javascript/blob/master/examples/kafkajs/admin}
47
+ */
48
+ class Admin {
49
+ /**
50
+ * The config supplied by the user.
51
+ * @type {import("../../types/kafkajs").AdminConstructorConfig|null}
52
+ */
53
+ #userConfig = null;
54
+
55
+ /**
56
+ * The config realized after processing any compatibility options.
57
+ * @type {import("../../types/config").GlobalConfig|null}
58
+ */
59
+ #internalConfig = null;
60
+
61
+ /**
62
+ * internalClient is the node-rdkafka client used by the API.
63
+ * @type {import("../rdkafka").AdminClient|null}
64
+ */
65
+ #internalClient = null;
66
+ /**
67
+ * state is the current state of the admin client.
68
+ * @type {AdminState}
69
+ */
70
+ #state = AdminState.INIT;
71
+
72
+ /**
73
+ * A logger for the admin client.
74
+ * @type {import("../../types/kafkajs").Logger}
75
+ */
76
+ #logger = new DefaultLogger();
77
+
78
+ /**
79
+ * connectPromiseFunc is the set of promise functions used to resolve/reject the connect() promise.
80
+ * @type {{resolve: Function, reject: Function}|{}}
81
+ */
82
+ #connectPromiseFunc = null;
83
+
84
+ /**
85
+ * Stores the first error encountered while connecting (if any). This is what we
86
+ * want to reject with.
87
+ * @type {Error|null}
88
+ */
89
+ #connectionError = null;
90
+
91
+ /**
92
+ * The client name used by the admin client for logging - determined by librdkafka
93
+ * using a combination of clientId and an integer.
94
+ * @type {string|undefined}
95
+ */
96
+ #clientName = undefined;
97
+
98
+ /**
99
+ * The existing client to use as basis for this admin client, if any is provided.
100
+ */
101
+ #existingClient = null;
102
+
103
+ // Convenience function to create the metadata object needed for logging.
104
+ #createAdminBindingMessageMetadata() {
105
+ return createBindingMessageMetadata(this.#clientName);
106
+ }
107
+
108
+ /**
109
+ * @constructor
110
+ * @param {import("../../types/kafkajs").AdminConstructorConfig?} config
111
+ * @param {import("../../types/kafkajs").Client?} existingClient
112
+ */
113
+ constructor(config, existingClient) {
114
+ this.#userConfig = config;
115
+ this.#existingClient = existingClient;
116
+ }
117
+
118
+ #config() {
119
+ if (!this.#internalConfig)
120
+ this.#internalConfig = this.#finalizedConfig();
121
+ return this.#internalConfig;
122
+ }
123
+
124
+ #kafkaJSToAdminConfig(kjsConfig) {
125
+ if (!kjsConfig || Object.keys(kjsConfig).length === 0) {
126
+ return {};
127
+ }
128
+
129
+ const disallowedKey = checkAllowedKeys('admin', kjsConfig);
130
+ if (disallowedKey) {
131
+ throw new error.KafkaJSError(CompatibilityErrorMessages.unsupportedKey(disallowedKey), { code: error.ErrorCodes.ERR__INVALID_ARG });
132
+ }
133
+
134
+ const rdKafkaConfig = kafkaJSToRdKafkaConfig(kjsConfig);
135
+
136
+ /* Set the logger */
137
+ if (Object.hasOwn(kjsConfig, 'logger')) {
138
+ this.#logger = kjsConfig.logger;
139
+ }
140
+
141
+ /* Set the log level - INFO for compatibility with kafkaJS, or DEBUG if that is turned
142
+ * on using the logLevel property. rdKafkaConfig.log_level is guaranteed to be set if we're
143
+ * here, and containing the correct value. */
144
+ this.#logger.setLogLevel(severityToLogLevel[rdKafkaConfig.log_level]);
145
+
146
+ return rdKafkaConfig;
147
+ }
148
+
149
+ #finalizedConfig() {
150
+ let compatibleConfig = this.#kafkaJSToAdminConfig(this.#userConfig.kafkaJS);
151
+
152
+ /* There can be multiple different and conflicting config directives for setting the log level:
153
+ * 1. If there's a kafkaJS block:
154
+ * a. If there's a logLevel directive in the kafkaJS block, set the logger level accordingly.
155
+ * b. If there's no logLevel directive, set the logger level to INFO.
156
+ * (both these are already handled in the conversion method above).
157
+ * 2. If there is a log_level or debug directive in the main config, set the logger level accordingly.
158
+ * !This overrides any different value provided in the kafkaJS block!
159
+ * a. If there's a log_level directive, set the logger level accordingly.
160
+ * b. If there's a debug directive, set the logger level to DEBUG regardless of anything else. This is because
161
+ * librdkafka ignores log_level if debug is set, and our behaviour should be identical.
162
+ * 3. There's nothing at all. Take no action in this case, let the logger use its default log level.
163
+ */
164
+ if (Object.hasOwn(this.#userConfig, 'log_level')) {
165
+ this.#logger.setLogLevel(severityToLogLevel[this.#userConfig.log_level]);
166
+ }
167
+
168
+ if (Object.hasOwn(this.#userConfig, 'debug')) {
169
+ this.#logger.setLogLevel(logLevel.DEBUG);
170
+ }
171
+
172
+ let rdKafkaConfig = Object.assign(compatibleConfig, this.#userConfig);
173
+
174
+ /* Delete properties which are already processed, or cannot be passed to node-rdkafka */
175
+ delete rdKafkaConfig.kafkaJS;
176
+
177
+ if (Object.hasOwn(rdKafkaConfig, 'stats_cb')) {
178
+ if (typeof rdKafkaConfig['stats_cb'] === 'function')
179
+ this.#statsCb = rdKafkaConfig['stats_cb'];
180
+ delete rdKafkaConfig['stats_cb'];
181
+ }
182
+
183
+ return rdKafkaConfig;
184
+ }
185
+
186
+ #readyCb() {
187
+ if (this.#state !== AdminState.CONNECTING) {
188
+ /* The connectPromiseFunc might not be set, so we throw such an error. It's a state error that we can't recover from. Probably a bug. */
189
+ throw new error.KafkaJSError(`Ready callback called in invalid state ${this.#state}`, { code: error.ErrorCodes.ERR__STATE });
190
+ }
191
+ this.#state = AdminState.CONNECTED;
192
+
193
+ // Resolve the promise.
194
+ this.#connectPromiseFunc['resolve']();
195
+ }
196
+
197
+ /**
198
+ * Callback for the event.error event, either fails the initial connect(), or logs the error.
199
+ * @param {Error} err
200
+ * @private
201
+ */
202
+ #errorCb(err) {
203
+ /* If we get an error in the middle of connecting, reject the promise later with this error. */
204
+ if (this.#state < AdminState.CONNECTED) {
205
+ if (!this.#connectionError)
206
+ this.#connectionError = err;
207
+ } else {
208
+ this.#logger.error(`Error: ${err.message}`, this.#createAdminBindingMessageMetadata());
209
+ }
210
+ }
211
+
212
+ /**
213
+ * Callback for the event.stats event, if defined.
214
+ * @private
215
+ */
216
+ #statsCb = null;
217
+
218
+ /**
219
+ * Set up the client and connect to the bootstrap brokers.
220
+ * @returns {Promise<void>} Resolves when connection is complete, rejects on error.
221
+ */
222
+ async connect() {
223
+ if (this.#state !== AdminState.INIT) {
224
+ throw new error.KafkaJSError("Connect has already been called elsewhere.", { code: error.ErrorCodes.ERR__STATE });
225
+ }
226
+
227
+ this.#state = AdminState.CONNECTING;
228
+
229
+ return new Promise((resolve, reject) => {
230
+ try {
231
+ /* AdminClient creation is a synchronous operation for node-rdkafka */
232
+ this.#connectPromiseFunc = { resolve, reject };
233
+ if (!this.#existingClient) {
234
+ const config = this.#config();
235
+ this.#internalClient = RdKafka.AdminClient.create(config, {
236
+ 'error': this.#errorCb.bind(this),
237
+ 'ready': this.#readyCb.bind(this),
238
+ 'event.log': (msg) => loggerTrampoline(msg, this.#logger),
239
+ });
240
+ if (this.#statsCb) {
241
+ this.#internalClient.on('event.stats', this.#statsCb.bind(this));
242
+ }
243
+ } else {
244
+ const underlyingClient = this.#existingClient._getInternalClient();
245
+ if (!underlyingClient) {
246
+ throw new error.KafkaJSError("Underlying client is not connected.", { code: error.ErrorCodes.ERR__STATE });
247
+ }
248
+ this.#logger = this.#existingClient.logger();
249
+ this.#internalClient = RdKafka.AdminClient.createFrom(underlyingClient, {
250
+ 'ready': this.#readyCb.bind(this),
251
+ });
252
+ }
253
+
254
+ this.#clientName = this.#internalClient.name;
255
+ this.#logger.info("Admin client connected", this.#createAdminBindingMessageMetadata());
256
+ } catch (err) {
257
+ this.#state = AdminState.DISCONNECTED;
258
+ const rejectionError = this.#connectionError ? this.#connectionError : err;
259
+ reject(createKafkaJsErrorFromLibRdKafkaError(rejectionError));
260
+ }
261
+ });
262
+ }
263
+
264
+ /**
265
+ * Disconnect from the brokers, clean-up and tear down the client.
266
+ * @returns {Promise<void>} Resolves when disconnect is complete, rejects on error.
267
+ */
268
+ async disconnect() {
269
+ /* Not yet connected - no error. */
270
+ if (this.#state === AdminState.INIT) {
271
+ return;
272
+ }
273
+
274
+ /* Already disconnecting, or disconnected. */
275
+ if (this.#state >= AdminState.DISCONNECTING) {
276
+ return;
277
+ }
278
+
279
+ this.#state = AdminState.DISCONNECTING;
280
+ return new Promise((resolve, reject) => {
281
+ try {
282
+ /* AdminClient disconnect for node-rdkakfa is synchronous. */
283
+ this.#internalClient.disconnect();
284
+ this.#state = AdminState.DISCONNECTED;
285
+ this.#logger.info("Admin client disconnected", this.#createAdminBindingMessageMetadata());
286
+ resolve();
287
+ } catch (err) {
288
+ reject(createKafkaJsErrorFromLibRdKafkaError(err));
289
+ }
290
+ });
291
+ }
292
+
293
+
294
+ /**
295
+ * Converts a topic configuration object from kafkaJS to a format suitable for node-rdkafka.
296
+ * @param {import("../../types/kafkajs").ITopicConfig} topic
297
+ * @returns {import("../../index").NewTopic}
298
+ * @private
299
+ */
300
+ #topicConfigToRdKafka(topic) {
301
+ let topicConfig = { topic: topic.topic };
302
+ topicConfig.topic = topic.topic;
303
+ topicConfig.num_partitions = topic.numPartitions ?? -1;
304
+ topicConfig.replication_factor = topic.replicationFactor ?? -1;
305
+
306
+ if (Object.hasOwn(topic, "replicaAssignment")) {
307
+ throw new error.KafkaJSError("replicaAssignment is not yet implemented.", { code: error.ErrorCodes.ERR__NOT_IMPLEMENTED });
308
+ }
309
+
310
+ topicConfig.config = {};
311
+ topic.configEntries = topic.configEntries ?? [];
312
+ for (const configEntry of topic.configEntries) {
313
+ topicConfig.config[configEntry.name] = configEntry.value;
314
+ }
315
+
316
+ return topicConfig;
317
+ }
318
+
319
+ /**
320
+ * Create topics with the given configuration.
321
+ * @param {object} options
322
+ * @param {number?} options.timeout - The request timeout in milliseconds (default: 5000).
323
+ * @param {Array<{topic: string, numPartitions: number | null, replicationFactor: number | null, configEntries: Array<{name: string, value: string}> | null}>} options.topics
324
+ * The topics to create and optionally, the configuration for each topic.
325
+ * @returns {Promise<boolean>} Resolves true when the topics are created, false if topic exists already, rejects on error.
326
+ * In case even one topic already exists, this will return false.
327
+ */
328
+ async createTopics(options) {
329
+ if (this.#state !== AdminState.CONNECTED) {
330
+ throw new error.KafkaJSError("Admin client is not connected.", { code: error.ErrorCodes.ERR__STATE });
331
+ }
332
+
333
+ if (Object.hasOwn(options, "validateOnly")) {
334
+ throw new error.KafkaJSError("validateOnly is not yet implemented.", { code: error.ErrorCodes.ERR__NOT_IMPLEMENTED });
335
+ }
336
+
337
+ if (Object.hasOwn(options, "waitForLeaders")) {
338
+ throw new error.KafkaJSError("waitForLeaders is not yet implemented.", { code: error.ErrorCodes.ERR__NOT_IMPLEMENTED });
339
+ }
340
+
341
+ /* Convert each topic to a format suitable for node-rdkafka, and dispatch the call. */
342
+ let allTopicsCreated = true;
343
+ const errors = [];
344
+ const ret =
345
+ options.topics
346
+ .map(this.#topicConfigToRdKafka)
347
+ .map(topicConfig => new Promise(resolve => {
348
+ this.#internalClient.createTopic(topicConfig, options.timeout ?? 5000, (err) => {
349
+ if (err) {
350
+ if (err.code === error.ErrorCodes.ERR_TOPIC_ALREADY_EXISTS) {
351
+ allTopicsCreated = false;
352
+ resolve();
353
+ return;
354
+ }
355
+ const e = createKafkaJsErrorFromLibRdKafkaError(err);
356
+ const createTopicError = new error.KafkaJSCreateTopicError(e, topicConfig.topic, e /* includes the properties */);
357
+ errors.push(createTopicError);
358
+ resolve(); // Don't reject this promise, instead, look at the errors array later.
359
+ } else {
360
+ resolve();
361
+ }
362
+ });
363
+ }));
364
+
365
+ await Promise.allSettled(ret);
366
+ if (errors.length > 0) {
367
+ throw new error.KafkaJSAggregateError("Topic creation errors", errors);
368
+ }
369
+ return allTopicsCreated;
370
+ }
371
+
372
+ /**
373
+ * Deletes given topics.
374
+ * @param {object} options
375
+ * @param {Array<string>} options.topics - The topics to delete.
376
+ * @param {number?} options.timeout - The request timeout in milliseconds (default: 5000).
377
+ * @returns {Promise<void>} Resolves when the topics are deleted, rejects on error.
378
+ */
379
+ async deleteTopics(options) {
380
+ if (this.#state !== AdminState.CONNECTED) {
381
+ throw new error.KafkaJSError("Admin client is not connected.", { code: error.ErrorCodes.ERR__STATE });
382
+ }
383
+
384
+ return Promise.all(
385
+ options.topics.map(topic => new Promise((resolve, reject) => {
386
+ this.#internalClient.deleteTopic(topic, options.timeout ?? 5000, err => {
387
+ if (err) {
388
+ reject(createKafkaJsErrorFromLibRdKafkaError(err));
389
+ } else {
390
+ resolve();
391
+ }
392
+ });
393
+ }))
394
+ );
395
+ }
396
+
397
+ /**
398
+ * List consumer groups.
399
+ *
400
+ * @param {object?} options
401
+ * @param {number?} options.timeout - The request timeout in milliseconds.
402
+ * May be unset (default: 5000).
403
+ * @param {Array<KafkaJS.ConsumerGroupStates>?} options.matchConsumerGroupStates -
404
+ * A list of consumer group states to match. May be unset, fetches all states (default: unset).
405
+ * @param {Array<KafkaJS.ConsumerGroupTypes>?} options.matchConsumerGroupTypes -
406
+ * A list of consumer group types to match. May be unset, fetches all types (default: unset).
407
+ * @returns {Promise<{ groups: Array<{groupId: string, protocolType: string, isSimpleConsumerGroup: boolean, state: KafkaJS.ConsumerGroupStates, type: KafkaJS.ConsumerGroupTypes}>, errors: Array<RdKafka.LibrdKafkaError> }>}
408
+ * Resolves with the list of consumer groups, rejects on error.
409
+ */
410
+ async listGroups(options = {}) {
411
+ if (this.#state !== AdminState.CONNECTED) {
412
+ throw new error.KafkaJSError("Admin client is not connected.", { code: error.ErrorCodes.ERR__STATE });
413
+ }
414
+
415
+ return new Promise((resolve, reject) => {
416
+ this.#internalClient.listGroups(options, (err, groups) => {
417
+ if (err) {
418
+ reject(createKafkaJsErrorFromLibRdKafkaError(err));
419
+ } else {
420
+ resolve(groups);
421
+ }
422
+ });
423
+ });
424
+ }
425
+
426
+ /**
427
+ * Describe consumer groups.
428
+ *
429
+ * @param {Array<string>} groups - The names of the groups to describe.
430
+ * @param {object?} options
431
+ * @param {number?} options.timeout - The request timeout in milliseconds.
432
+ * May be unset (default: 5000)
433
+ * @param {boolean?} options.includeAuthorizedOperations - If true, include operations allowed on the group by the calling client (default: false).
434
+ * @returns {Promise<{groups: Array<object>}>} The descriptions of the requested groups.
435
+ */
436
+ async describeGroups(groups, options = {}) {
437
+ if (this.#state !== AdminState.CONNECTED) {
438
+ throw new error.KafkaJSError("Admin client is not connected.", { code: error.ErrorCodes.ERR__STATE });
439
+ }
440
+
441
+ return new Promise((resolve, reject) => {
442
+ this.#internalClient.describeGroups(groups, options, (err, descriptions) => {
443
+ if (err) {
444
+ reject(createKafkaJsErrorFromLibRdKafkaError(err));
445
+ } else {
446
+ resolve(descriptions);
447
+ }
448
+ });
449
+ });
450
+ }
451
+
452
+ /**
453
+ * Delete consumer groups.
454
+ * @param {Array<string>} groups - The names of the groups to delete.
455
+ * @param {object?} options
456
+ * @param {number?} options.timeout - The request timeout in milliseconds.
457
+ * May be unset (default: 5000)
458
+ * @returns {Promise<Array<{groupId: string, errorCode: number | null, error: RdKafka.LibrdKafkaError | null}>>}
459
+ * Resolves with the list of deletion reports (including per-group errors).
460
+ */
461
+ async deleteGroups(groups, options = {}) {
462
+ if (this.#state !== AdminState.CONNECTED) {
463
+ throw new error.KafkaJSError("Admin client is not connected.", { code: error.ErrorCodes.ERR__STATE });
464
+ }
465
+
466
+ return new Promise((resolve, reject) => {
467
+ this.#internalClient.deleteGroups(groups, options, (err, reports) => {
468
+ if (err) {
469
+ reject(createKafkaJsErrorFromLibRdKafkaError(err));
470
+ return;
471
+ }
472
+
473
+ /* Convert group-level errors to KafkaJS errors if required. */
474
+ let errorsPresent = false;
475
+ reports = reports.map(groupReport => {
476
+ if (groupReport.error) {
477
+ errorsPresent = true;
478
+ groupReport.error = createKafkaJsErrorFromLibRdKafkaError(groupReport.error);
479
+ }
480
+ return groupReport;
481
+ });
482
+
483
+ if (errorsPresent) {
484
+ reject(new error.KafkaJSDeleteGroupsError('Error in DeleteGroups', reports));
485
+ return;
486
+ }
487
+ resolve(reports);
488
+ });
489
+ });
490
+ }
491
+
492
+ /**
493
+ * List topics.
494
+ *
495
+ * @param {object?} options
496
+ * @param {number?} options.timeout - The request timeout in milliseconds.
497
+ * May be unset (default: 5000).
498
+ * @returns {Promise<Array<string>>} The list of all topics.
499
+ */
500
+ async listTopics(options = {}) {
501
+ if (this.#state !== AdminState.CONNECTED) {
502
+ throw new error.KafkaJSError("Admin client is not connected.", { code: error.ErrorCodes.ERR__STATE });
503
+ }
504
+
505
+ return new Promise((resolve, reject) => {
506
+ this.#internalClient.listTopics(options, (err, topics) => {
507
+ if (err) {
508
+ reject(createKafkaJsErrorFromLibRdKafkaError(err));
509
+ } else {
510
+ resolve(topics);
511
+ }
512
+ });
513
+ });
514
+ }
515
+
516
+ /**
517
+ * Fetch the offsets for topic partition(s) for consumer group(s).
518
+ *
519
+ * @param {object?} options
520
+ * @param {string} options.groupId - The group ID to fetch offsets for.
521
+ * @param {Array<string> | Array<{topic: string, partitions: Array<number>}>} options.topics
522
+ * The topics to fetch offsets for. Can be specified as a list of topics (in case offsets for all topics are fetched),
523
+ * or as a list of objects, each containing a topic and a list of partitions.
524
+ * @param {number?} options.timeout - The request timeout in milliseconds.
525
+ * May be unset (default: 5000).
526
+ * @param {boolean?} options.requireStableOffsets - Whether broker should return stable offsets
527
+ * (transaction-committed). (default: false).
528
+ *
529
+ * @returns {Promise<Array<{topic: string, partitions: Array<object>}>>}
530
+ * The list of requested offsets.
531
+ */
532
+ async fetchOffsets(options = {}) {
533
+ if (this.#state !== AdminState.CONNECTED) {
534
+ throw new error.KafkaJSError("Admin client is not connected.", { code: error.ErrorCodes.ERR__STATE });
535
+ }
536
+
537
+ if (Object.hasOwn(options, "resolveOffsets")) {
538
+ throw new error.KafkaJSError("resolveOffsets is not yet implemented.", { code: error.ErrorCodes.ERR__NOT_IMPLEMENTED });
539
+ }
540
+
541
+ const { groupId, topics } = options;
542
+
543
+ if (!groupId) {
544
+ throw new error.KafkaJSError("groupId is required.", { code: error.ErrorCodes.ERR__INVALID_ARG });
545
+ }
546
+
547
+ let partitions = null;
548
+ let originalTopics = null;
549
+
550
+ /*
551
+ If the input is a list of topic string, the user expects us to
552
+ fetch offsets for all all partitions of all the input topics. In
553
+ librdkafka, we can only fetch offsets by topic partitions, or else,
554
+ we can fetch all of them. Thus, we must fetch offsets for all topic
555
+ partitions (by settings partitions to null) and filter by the topic strings later.
556
+ */
557
+ if (topics && Array.isArray(topics)) {
558
+ if (typeof topics[0] === 'string') {
559
+ originalTopics = topics;
560
+ partitions = null;
561
+ } else if (typeof topics[0] === 'object' && Array.isArray(topics[0].partitions)) {
562
+ partitions = topics.flatMap(topic => topic.partitions.map(partition => ({
563
+ topic: topic.topic,
564
+ partition
565
+ })));
566
+ } else {
567
+ throw new error.KafkaJSError("Invalid topics format.", { code: error.ErrorCodes.ERR__INVALID_ARG });
568
+ }
569
+ }
570
+
571
+ const listGroupOffsets = [{
572
+ groupId,
573
+ partitions
574
+ }];
575
+
576
+
577
+ return new Promise((resolve, reject) => {
578
+ this.#internalClient.listConsumerGroupOffsets(listGroupOffsets, options, (err, offsets) => {
579
+ if (err) {
580
+ reject(createKafkaJsErrorFromLibRdKafkaError(err));
581
+ } else {
582
+
583
+ /**
584
+ * Offsets is an array of group results, each containing a group id,
585
+ * an error and an array of partitions.
586
+ * We need to convert it to the required format of an array of topics, each
587
+ * containing an array of partitions.
588
+ */
589
+ const topicPartitionMap = new Map();
590
+
591
+ if (offsets.length !== 1) {
592
+ reject(new error.KafkaJSError("Unexpected number of group results."));
593
+ return;
594
+ }
595
+
596
+ const groupResult = offsets[0];
597
+
598
+ if (groupResult.error) {
599
+ reject(createKafkaJsErrorFromLibRdKafkaError(groupResult.error));
600
+ return;
601
+ }
602
+
603
+ // Traverse the partitions and group them by topic
604
+ groupResult.partitions.forEach(partitionObj => {
605
+ const { topic, partition, offset, leaderEpoch, metadata, error } = partitionObj;
606
+ const fetchOffsetsPartition = {
607
+ partition: partition,
608
+ offset: String(offset),
609
+ metadata: metadata || null,
610
+ leaderEpoch: leaderEpoch || null,
611
+ error: error || null
612
+ };
613
+
614
+ // Group partitions by topic
615
+ if (!topicPartitionMap.has(topic)) {
616
+ topicPartitionMap.set(topic, []);
617
+ }
618
+ topicPartitionMap.get(topic).push(fetchOffsetsPartition);
619
+ });
620
+
621
+ // Convert the map back to the desired array format
622
+ let convertedOffsets = Array.from(topicPartitionMap, ([topic, partitions]) => ({
623
+ topic,
624
+ partitions
625
+ }));
626
+
627
+ if (originalTopics !== null) {
628
+ convertedOffsets = convertedOffsets.filter(convertedOffset => originalTopics.includes(convertedOffset.topic));
629
+ }
630
+ resolve(convertedOffsets);
631
+ }
632
+ });
633
+ });
634
+ }
635
+
636
+ /**
637
+ * Deletes records (messages) in topic partitions older than the offsets provided.
638
+ *
639
+ * Provide -1 as offset to delete all records in the partition.
640
+ *
641
+ * @param {object} options
642
+ * @param {string} options.topic - The topic to delete offsets for.
643
+ * @param {Array<{partition: number, offset: string}>} options.partitions
644
+ * The partitions and associated offsets to delete up until.
645
+ * @param {number?} options.operationTimeout - The operation timeout in milliseconds.
646
+ * May be unset (default: 60000).
647
+ * @param {number?} options.timeout - The request timeout in milliseconds.
648
+ * May be unset (default: 5000).
649
+ *
650
+ * @returns {Promise<Array<{topic: string, partition: number, lowWatermark: number, error: RdKafka.LibrdKafkaError | null}>>}
651
+ * A list of results for each partition.
652
+ */
653
+ async deleteTopicRecords(options = {}) {
654
+ if (this.#state !== AdminState.CONNECTED) {
655
+ throw new error.KafkaJSError("Admin client is not connected.", { code: error.ErrorCodes.ERR__STATE });
656
+ }
657
+
658
+ if (!Object.hasOwn(options, 'topic') || !Object.hasOwn(options, 'partitions') || !Array.isArray(options.partitions)) {
659
+ throw new error.KafkaJSError("Options must include 'topic' and 'partitions', and 'partitions' must be an array.", { code: error.ErrorCodes.ERR__INVALID_ARG });
660
+ }
661
+
662
+ const { topic, partitions } = options;
663
+
664
+ // Create an array of TopicPartitionOffset objects
665
+ const topicPartitionOffsets = [];
666
+
667
+ for (const partition of partitions) {
668
+ if (partition.offset === null || partition.offset === undefined) {
669
+ throw new error.KafkaJSError("Each partition must have a valid offset.", { code: error.ErrorCodes.ERR__INVALID_ARG });
670
+ }
671
+
672
+ const offset = +partition.offset;
673
+ if (isNaN(offset)) {
674
+ throw new error.KafkaJSError("Offset must be a valid number.", { code: error.ErrorCodes.ERR__INVALID_ARG });
675
+ }
676
+
677
+ topicPartitionOffsets.push({
678
+ topic,
679
+ partition: partition.partition,
680
+ offset: offset,
681
+ });
682
+ }
683
+
684
+ return new Promise((resolve, reject) => {
685
+ this.#internalClient.deleteRecords(topicPartitionOffsets, options, (err, results) => {
686
+ if (err) {
687
+ reject(createKafkaJsErrorFromLibRdKafkaError(err));
688
+ return;
689
+ }
690
+
691
+ let errorsPresent = false;
692
+ results = results.map(result => {
693
+ if (result.error) {
694
+ errorsPresent = true;
695
+ result.error = createKafkaJsErrorFromLibRdKafkaError(result.error);
696
+ }
697
+ return result;
698
+ });
699
+
700
+ if (errorsPresent) {
701
+ const partitionsWithError =
702
+ {
703
+ /* Note that, for API compatibility, we must filter out partitions
704
+ * without errors, even though it is more useful to return all of
705
+ * them so the user can check offsets. */
706
+ partitions:
707
+ results.filter(result => result.error).map(result => ({
708
+ partition: result.partition,
709
+ offset: String(result.lowWatermark),
710
+ error: result.error,
711
+ }))
712
+ };
713
+ reject(new error.KafkaJSDeleteTopicRecordsError(partitionsWithError));
714
+ return;
715
+ }
716
+ resolve(results);
717
+ });
718
+ });
719
+ }
720
+
721
+ /**
722
+ * Describe topics.
723
+ *
724
+ * @param {object?} options
725
+ * @param {Array<string>} options.topics - The topics to describe.
726
+ * If unset, all topics will be described.
727
+ * @param {number?} options.timeout - The request timeout in milliseconds.
728
+ * May be unset (default: 5000).
729
+ * @param {boolean?} options.includeAuthorizedOperations - If true, include operations allowed on the topic
730
+ * by the calling client (default: false).
731
+ *
732
+ * @returns {Promise<{ topics: Array<object> }>}
733
+ */
734
+ async fetchTopicMetadata(options = {}) {
735
+ if (this.#state !== AdminState.CONNECTED) {
736
+ throw new error.KafkaJSError("Admin client is not connected.", { code: error.ErrorCodes.ERR__STATE });
737
+ }
738
+
739
+ let topics = options.topics;
740
+ if (!Object.hasOwn(options, 'topics')) {
741
+ try {
742
+ topics = await this.listTopics();
743
+ } catch (err) {
744
+ throw createKafkaJsErrorFromLibRdKafkaError(err);
745
+ }
746
+ }
747
+
748
+ return new Promise((resolve, reject) => {
749
+ this.#internalClient.describeTopics(topics, options, (err, metadata) => {
750
+ if (err) {
751
+ reject(createKafkaJsErrorFromLibRdKafkaError(err));
752
+ } else {
753
+
754
+ let errs = metadata.filter(topic => topic.error);
755
+ if (errs.length > 0) {
756
+ reject(createKafkaJsErrorFromLibRdKafkaError(errs[0].error));
757
+ return;
758
+ }
759
+ const convertedMetadata = metadata.map(topic => ({
760
+ name: topic.name,
761
+ topicId: topic.topicId,
762
+ isInternal: topic.isInternal,
763
+ partitions: topic.partitions.map(partition => ({
764
+ partitionErrorCode: error.ErrorCodes.ERR_NO_ERROR,
765
+ partitionId: partition.partition,
766
+ leader: partition.leader.id,
767
+ leaderNode: partition.leader,
768
+ replicas: partition.replicas.map(replica => replica.id),
769
+ replicaNodes: partition.replicas,
770
+ isr: partition.isr.map(isrNode => isrNode.id),
771
+ isrNodes: partition.isr
772
+ })),
773
+ authorizedOperations: topic.authorizedOperations
774
+ }));
775
+
776
+ resolve(convertedMetadata);
777
+ }
778
+ });
779
+ });
780
+ }
781
+
782
+ /**
783
+ * List offsets for the specified topic partition(s).
784
+ *
785
+ * @param {string} topic - The topic to fetch offsets for.
786
+ * @param {object?} options
787
+ * @param {number?} options.timeout - The request timeout in milliseconds.
788
+ * May be unset (default: 5000)
789
+ * @param {KafkaJS.IsolationLevel?} options.isolationLevel - The isolation level for reading the offsets.
790
+ * (default: READ_UNCOMMITTED)
791
+ *
792
+ * @returns {Promise<Array<{partition: number, offset: string, high: string, low: string}>>}
793
+ */
794
+ async fetchTopicOffsets(topic, options = {}) {
795
+ if (this.#state !== AdminState.CONNECTED) {
796
+ throw new error.KafkaJSError("Admin client is not connected.", { code: error.ErrorCodes.ERR__STATE });
797
+ }
798
+
799
+ if (!Object.hasOwn(options, 'timeout')) {
800
+ options.timeout = 5000;
801
+ }
802
+
803
+ let topicData;
804
+ let startTime, endTime, timeTaken;
805
+
806
+ try {
807
+ // Measure time taken for fetchTopicMetadata
808
+ startTime = hrtime.bigint();
809
+ topicData = await this.fetchTopicMetadata({ topics: [topic], timeout: options.timeout });
810
+ endTime = hrtime.bigint();
811
+ timeTaken = Number(endTime - startTime) / 1e6; // Convert nanoseconds to milliseconds
812
+
813
+ // Adjust timeout for the next request
814
+ options.timeout -= timeTaken;
815
+ if (options.timeout <= 0) {
816
+ throw new error.KafkaJSError("Timeout exceeded while fetching topic metadata.", { code: error.ErrorCodes.ERR__TIMED_OUT });
817
+ }
818
+ } catch (err) {
819
+ throw new createKafkaJsErrorFromLibRdKafkaError(err);
820
+ }
821
+
822
+ const partitionIds = topicData.flatMap(topic =>
823
+ topic.partitions.map(partition => partition.partitionId)
824
+ );
825
+
826
+ const topicPartitionOffsetsLatest = partitionIds.map(partitionId => ({
827
+ topic,
828
+ partition: partitionId,
829
+ offset: OffsetSpec.LATEST
830
+ }));
831
+
832
+ const topicPartitionOffsetsEarliest = partitionIds.map(partitionId => ({
833
+ topic,
834
+ partition: partitionId,
835
+ offset: OffsetSpec.EARLIEST
836
+ }));
837
+
838
+ try {
839
+ // Measure time taken for listOffsets (latest)
840
+ startTime = hrtime.bigint();
841
+ const latestOffsets = await this.#listOffsets(topicPartitionOffsetsLatest, options);
842
+ endTime = hrtime.bigint();
843
+ timeTaken = Number(endTime - startTime) / 1e6; // Convert nanoseconds to milliseconds
844
+
845
+ // Adjust timeout for the next request
846
+ options.timeout -= timeTaken;
847
+ if (options.timeout <= 0) {
848
+ throw new error.KafkaJSError("Timeout exceeded while fetching latest offsets.", { code: error.ErrorCodes.ERR__TIMED_OUT });
849
+ }
850
+
851
+ // Measure time taken for listOffsets (earliest)
852
+ startTime = hrtime.bigint();
853
+ const earliestOffsets = await this.#listOffsets(topicPartitionOffsetsEarliest, options);
854
+ endTime = hrtime.bigint();
855
+ timeTaken = Number(endTime - startTime) / 1e6; // Convert nanoseconds to milliseconds
856
+
857
+ // Adjust timeout for the next request
858
+ options.timeout -= timeTaken;
859
+ if (options.timeout <= 0) {
860
+ throw new error.KafkaJSError("Timeout exceeded while fetching earliest offsets.", { code: error.ErrorCodes.ERR__TIMED_OUT });
861
+ }
862
+
863
+ const combinedResults = partitionIds.map(partitionId => {
864
+ const latest = latestOffsets.find(offset => offset.partition === partitionId);
865
+ const earliest = earliestOffsets.find(offset => offset.partition === partitionId);
866
+
867
+ return {
868
+ partition: partitionId,
869
+ offset: latest.offset.toString(),
870
+ high: latest.offset.toString(),
871
+ low: earliest.offset.toString()
872
+ };
873
+ });
874
+
875
+ return combinedResults;
876
+ } catch (err) {
877
+ throw createKafkaJsErrorFromLibRdKafkaError(err);
878
+ }
879
+ }
880
+
881
+ #listOffsets(partitionOffsets, options) {
882
+ return new Promise((resolve, reject) => {
883
+ this.#internalClient.listOffsets(partitionOffsets, options, (err, offsets) => {
884
+ if (err) {
885
+ reject(createKafkaJsErrorFromLibRdKafkaError(err));
886
+ } else {
887
+ resolve(offsets);
888
+ }
889
+ });
890
+ });
891
+ }
892
+
893
+ /**
894
+ * List offsets for the topic partition(s) by timestamp.
895
+ *
896
+ * @param {string} topic - The topic to fetch offsets for.
897
+ * @param {number?} timestamp - The timestamp to fetch offsets for.
898
+ * @param {object?} options
899
+ * @param {number?} options.timeout - The request timeout in milliseconds.
900
+ * May be unset (default: 5000)
901
+ * @param {KafkaJS.IsolationLevel?} options.isolationLevel - The isolation level for reading the offsets.
902
+ * (default: READ_UNCOMMITTED)
903
+ *
904
+ * The returned topic partitions contain the earliest offset whose timestamp is greater than or equal to
905
+ * the given timestamp. If there is no such offset, or if the timestamp is unset, the latest offset is returned instead.
906
+ *
907
+ * @returns {Promise<Array<{partition: number, offset: string}>>}
908
+ */
909
+ async fetchTopicOffsetsByTimestamp(topic, timestamp, options = {}) {
910
+ if (this.#state !== AdminState.CONNECTED) {
911
+ throw new error.KafkaJSError("Admin client is not connected.", { code: error.ErrorCodes.ERR__STATE });
912
+ }
913
+
914
+ if (!Object.hasOwn(options, 'timeout')) {
915
+ options.timeout = 5000;
916
+ }
917
+
918
+ let topicData;
919
+ let startTime, endTime, timeTaken;
920
+
921
+ try {
922
+ // Measure time taken for fetchTopicMetadata
923
+ startTime = hrtime.bigint();
924
+ topicData = await this.fetchTopicMetadata({ topics: [topic], timeout: options.timeout });
925
+ endTime = hrtime.bigint();
926
+ timeTaken = Number(endTime - startTime) / 1e6; // Convert nanoseconds to milliseconds
927
+
928
+ // Adjust timeout for the next request
929
+ options.timeout -= timeTaken;
930
+ if (options.timeout <= 0) {
931
+ throw new error.KafkaJSError("Timeout exceeded while fetching topic metadata.", { code: error.ErrorCodes.ERR__TIMED_OUT });
932
+ }
933
+ } catch (err) {
934
+ throw new createKafkaJsErrorFromLibRdKafkaError(err);
935
+ }
936
+
937
+ const partitionIds = topicData.flatMap(topic =>
938
+ topic.partitions.map(partition => partition.partitionId)
939
+ );
940
+ let topicPartitionOffset = [];
941
+ if (typeof timestamp === 'undefined') {
942
+ topicPartitionOffset = partitionIds.map(partitionId => ({
943
+ topic,
944
+ partition: partitionId,
945
+ offset: OffsetSpec.LATEST
946
+ }));
947
+ }
948
+ else {
949
+ topicPartitionOffset = partitionIds.map(partitionId => ({
950
+ topic,
951
+ partition: partitionId,
952
+ offset: new OffsetSpec(timestamp)
953
+ }));
954
+ }
955
+
956
+ const topicPartitionOffsetsLatest = partitionIds.map(partitionId => ({
957
+ topic,
958
+ partition: partitionId,
959
+ offset: OffsetSpec.LATEST
960
+ }));
961
+
962
+ try {
963
+ // Measure time taken for listOffsets (by timestamp)
964
+ startTime = hrtime.bigint();
965
+ const offsetsByTimeStamp = await this.#listOffsets(topicPartitionOffset, options);
966
+ endTime = hrtime.bigint();
967
+ timeTaken = Number(endTime - startTime) / 1e6; // Convert nanoseconds to milliseconds
968
+
969
+ // Adjust timeout for the next request
970
+ options.timeout -= timeTaken;
971
+ if (options.timeout <= 0) {
972
+ throw new error.KafkaJSError("Timeout exceeded while fetching offsets.", { code: error.ErrorCodes.ERR__TIMED_OUT });
973
+ }
974
+
975
+ if (typeof timestamp === 'undefined') {
976
+ // Return result from offsetsByTimestamp if timestamp is undefined
977
+ return offsetsByTimeStamp.map(offset => ({
978
+ partition: offset.partition,
979
+ offset: offset.offset.toString(),
980
+ }));
981
+ } else {
982
+ // Measure time taken for listOffsets(latest)
983
+ startTime = hrtime.bigint();
984
+ const latestOffsets = await this.#listOffsets(topicPartitionOffsetsLatest, options);
985
+ endTime = hrtime.bigint();
986
+ timeTaken = Number(endTime - startTime) / 1e6; // Convert nanoseconds to milliseconds
987
+
988
+ // Adjust timeout for the next request
989
+ options.timeout -= timeTaken;
990
+ if (options.timeout <= 0) {
991
+ throw new error.KafkaJSError("Timeout exceeded while fetching latest offsets.", { code: error.ErrorCodes.ERR__TIMED_OUT });
992
+ }
993
+
994
+ const combinedResults = partitionIds.map(partitionId => {
995
+ const latest = latestOffsets.find(offset => offset.partition === partitionId);
996
+ const timestampOffset = offsetsByTimeStamp.find(offset => offset.partition === partitionId);
997
+
998
+ if (timestampOffset.offset === -1) {
999
+ return {
1000
+ partition: partitionId,
1001
+ offset: latest.offset.toString(),
1002
+ };
1003
+ } else {
1004
+ return {
1005
+ partition: partitionId,
1006
+ offset: timestampOffset.offset.toString(),
1007
+ };
1008
+ }
1009
+ });
1010
+
1011
+ return combinedResults;
1012
+ }
1013
+ } catch (err) {
1014
+ throw createKafkaJsErrorFromLibRdKafkaError(err);
1015
+ }
1016
+ }
1017
+ }
1018
+
1019
+ module.exports = {
1020
+ Admin,
1021
+ /**
1022
+ * A list of consumer group states.
1023
+ * @enum {number}
1024
+ * @readonly
1025
+ * @memberof KafkaJS
1026
+ * @see RdKafka.ConsumerGroupStates
1027
+ */
1028
+ ConsumerGroupStates: RdKafka.AdminClient.ConsumerGroupStates,
1029
+ /**
1030
+ * A list of consumer group types.
1031
+ * @enum {number}
1032
+ * @readonly
1033
+ * @memberof KafkaJS
1034
+ * @see RdKafka.ConsumerGroupTypes
1035
+ */
1036
+ ConsumerGroupTypes: RdKafka.AdminClient.ConsumerGroupTypes,
1037
+ /**
1038
+ * A list of ACL operation types.
1039
+ * @enum {number}
1040
+ * @readonly
1041
+ * @memberof KafkaJS
1042
+ * @see RdKafka.AclOperationTypes
1043
+ */
1044
+ AclOperationTypes: RdKafka.AdminClient.AclOperationTypes,
1045
+ /**
1046
+ * A list of isolation levels.
1047
+ * @enum {number}
1048
+ * @readonly
1049
+ * @memberof KafkaJS
1050
+ * @see RdKafka.IsolationLevel
1051
+ */
1052
+ IsolationLevel: RdKafka.AdminClient.IsolationLevel
1053
+ };