@ohos-ports/confluentinc-kafka-javascript 1.10.0-beta.1

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