bunqueue-client 0.1.9 → 0.2.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 (580) hide show
  1. package/CHANGELOG.md +150 -0
  2. package/LEGACY.md +460 -0
  3. package/README.md +204 -349
  4. package/dist/ack-batcher.js +7 -67
  5. package/dist/canonical-manifest.json +930 -0
  6. package/dist/chunk-b967v3w3.js +79 -0
  7. package/dist/chunk-fekm0ma6.js +110 -0
  8. package/dist/chunk-jxkszwqp.js +573 -0
  9. package/dist/embedded.js +16418 -0
  10. package/dist/frame.js +14 -57
  11. package/dist/index.d.ts +1 -27
  12. package/dist/index.js +10905 -16
  13. package/dist/legacy.d.ts +1 -0
  14. package/dist/legacy.js +2081 -0
  15. package/dist/{ack-batcher.d.ts → types/sdk/typescript/src/ack-batcher.d.ts} +3 -3
  16. package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/aging.d.ts +2 -2
  17. package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/batch.d.ts +2 -2
  18. package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/bunqueue-api.d.ts +5 -5
  19. package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/bunqueue.d.ts +13 -13
  20. package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/circuit-breaker.d.ts +2 -2
  21. package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/dedup-debounce.d.ts +2 -2
  22. package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/dlq-rate-limit.d.ts +2 -2
  23. package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/rate-gate.d.ts +1 -1
  24. package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/retry.d.ts +1 -1
  25. package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/triggers.d.ts +3 -3
  26. package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/ttl.d.ts +1 -1
  27. package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/types.d.ts +4 -4
  28. package/dist/types/sdk/typescript/src/canonical-transport/bun-sqlite-types.d.ts +21 -0
  29. package/dist/{connection-pool.d.ts → types/sdk/typescript/src/connection-pool.d.ts} +1 -1
  30. package/dist/{connection-types.d.ts → types/sdk/typescript/src/connection-types.d.ts} +1 -1
  31. package/dist/{connection.d.ts → types/sdk/typescript/src/connection.d.ts} +6 -19
  32. package/dist/{errors.d.ts → types/sdk/typescript/src/errors.d.ts} +3 -0
  33. package/dist/types/sdk/typescript/src/flow-commit.d.ts +5 -0
  34. package/dist/types/sdk/typescript/src/flow-plan-legacy.d.ts +13 -0
  35. package/dist/types/sdk/typescript/src/flow-plan.d.ts +29 -0
  36. package/dist/{flow-types.d.ts → types/sdk/typescript/src/flow-types.d.ts} +7 -4
  37. package/dist/{flow.d.ts → types/sdk/typescript/src/flow.d.ts} +6 -10
  38. package/dist/{frame.d.ts → types/sdk/typescript/src/frame.d.ts} +1 -1
  39. package/dist/types/sdk/typescript/src/index.d.ts +10 -0
  40. package/dist/{job.d.ts → types/sdk/typescript/src/job.d.ts} +4 -3
  41. package/dist/types/sdk/typescript/src/legacy.d.ts +27 -0
  42. package/dist/{observability.d.ts → types/sdk/typescript/src/observability.d.ts} +14 -0
  43. package/dist/{queue-admin.d.ts → types/sdk/typescript/src/queue-admin.d.ts} +3 -4
  44. package/dist/{queue-control.d.ts → types/sdk/typescript/src/queue-control.d.ts} +5 -5
  45. package/dist/{queue-query.d.ts → types/sdk/typescript/src/queue-query.d.ts} +3 -3
  46. package/dist/{queue.d.ts → types/sdk/typescript/src/queue.d.ts} +8 -8
  47. package/dist/{responses.d.ts → types/sdk/typescript/src/responses.d.ts} +2 -2
  48. package/dist/types/sdk/typescript/src/serialization.d.ts +10 -0
  49. package/dist/{socket-factory.d.ts → types/sdk/typescript/src/socket-factory.d.ts} +1 -1
  50. package/dist/types/sdk/typescript/src/terminal-outcome.d.ts +8 -0
  51. package/dist/{types.d.ts → types/sdk/typescript/src/types.d.ts} +5 -2
  52. package/dist/{worker-base.d.ts → types/sdk/typescript/src/worker-base.d.ts} +6 -6
  53. package/dist/types/sdk/typescript/src/worker-slot-signal.d.ts +6 -0
  54. package/dist/{worker-types.d.ts → types/sdk/typescript/src/worker-types.d.ts} +3 -3
  55. package/dist/{worker.d.ts → types/sdk/typescript/src/worker.d.ts} +3 -2
  56. package/dist/types/src/application/background/dlq.d.ts +2 -0
  57. package/dist/types/src/application/background/lifecycle.d.ts +4 -0
  58. package/dist/types/src/application/background/recovery/active.d.ts +5 -0
  59. package/dist/types/src/application/background/recovery/index.d.ts +2 -0
  60. package/dist/types/src/application/background/recovery/pending.d.ts +3 -0
  61. package/dist/types/src/application/background/recovery/restore.d.ts +5 -0
  62. package/dist/types/src/application/background/recovery/shared.d.ts +6 -0
  63. package/dist/types/src/application/background/timeouts.d.ts +25 -0
  64. package/dist/types/src/application/backgroundTasks.d.ts +7 -0
  65. package/dist/types/src/application/cleanupTasks.d.ts +10 -0
  66. package/dist/types/src/application/clientTracking.d.ts +44 -0
  67. package/dist/types/src/application/completedCleanup.d.ts +34 -0
  68. package/dist/types/src/application/completedRetry.d.ts +21 -0
  69. package/dist/types/src/application/contextFactory.d.ts +49 -0
  70. package/dist/types/src/application/dependencyCompletions.d.ts +63 -0
  71. package/dist/types/src/application/dependencyProcessor.d.ts +15 -0
  72. package/dist/types/src/application/dependencyResultTracker.d.ts +18 -0
  73. package/dist/types/src/application/dlqManager.d.ts +49 -0
  74. package/dist/types/src/application/dlqRetry.d.ts +12 -0
  75. package/dist/types/src/application/emptyQueueCleanup.d.ts +3 -0
  76. package/dist/types/src/application/eventsManager.d.ts +50 -0
  77. package/dist/types/src/application/flowFailureRecovery.d.ts +20 -0
  78. package/dist/types/src/application/flowParentBackpatch.d.ts +27 -0
  79. package/dist/types/src/application/jobLogsManager.d.ts +21 -0
  80. package/dist/types/src/application/latencyTracker.d.ts +39 -0
  81. package/dist/types/src/application/lockManager.d.ts +15 -0
  82. package/dist/types/src/application/lockOperations.d.ts +38 -0
  83. package/dist/types/src/application/metricsExporter.d.ts +27 -0
  84. package/dist/types/src/application/monitoringChecks.d.ts +36 -0
  85. package/dist/types/src/application/operations/ack/batch.d.ts +8 -0
  86. package/dist/types/src/application/operations/ack/completion.d.ts +3 -0
  87. package/dist/types/src/application/operations/ack/failure.d.ts +3 -0
  88. package/dist/types/src/application/operations/ack.d.ts +5 -0
  89. package/dist/types/src/application/operations/ackHelpers.d.ts +36 -0
  90. package/dist/types/src/application/operations/customId.d.ts +51 -0
  91. package/dist/types/src/application/operations/flowPush.d.ts +9 -0
  92. package/dist/types/src/application/operations/flowTopologyValidation.d.ts +3 -0
  93. package/dist/types/src/application/operations/flowValidation.d.ts +3 -0
  94. package/dist/types/src/application/operations/jobClaim.d.ts +17 -0
  95. package/dist/types/src/application/operations/jobManagement.d.ts +43 -0
  96. package/dist/types/src/application/operations/jobMoveOperations.d.ts +9 -0
  97. package/dist/types/src/application/operations/jobPromotion.d.ts +7 -0
  98. package/dist/types/src/application/operations/jobStateTransitions.d.ts +15 -0
  99. package/dist/types/src/application/operations/parentLink.d.ts +36 -0
  100. package/dist/types/src/application/operations/parentLinkInput.d.ts +8 -0
  101. package/dist/types/src/application/operations/pull.d.ts +20 -0
  102. package/dist/types/src/application/operations/pullFinalization.d.ts +6 -0
  103. package/dist/types/src/application/operations/pullStateTransition.d.ts +51 -0
  104. package/dist/types/src/application/operations/push.d.ts +13 -0
  105. package/dist/types/src/application/operations/pushAdmission.d.ts +36 -0
  106. package/dist/types/src/application/operations/pushBatch.d.ts +4 -0
  107. package/dist/types/src/application/operations/pushContext.d.ts +48 -0
  108. package/dist/types/src/application/operations/pushDeduplication.d.ts +42 -0
  109. package/dist/types/src/application/operations/pushInsert.d.ts +39 -0
  110. package/dist/types/src/application/operations/pushLocks.d.ts +15 -0
  111. package/dist/types/src/application/operations/query/collect.d.ts +12 -0
  112. package/dist/types/src/application/operations/query/jobLookup.d.ts +9 -0
  113. package/dist/types/src/application/operations/query/pagination.d.ts +8 -0
  114. package/dist/types/src/application/operations/query/state.d.ts +4 -0
  115. package/dist/types/src/application/operations/queryOperations.d.ts +5 -0
  116. package/dist/types/src/application/operations/queueControl.d.ts +50 -0
  117. package/dist/types/src/application/prometheusOperationalMetrics.d.ts +31 -0
  118. package/dist/types/src/application/queue-manager/ack.d.ts +23 -0
  119. package/dist/types/src/application/queue-manager/configuration.d.ts +27 -0
  120. package/dist/types/src/application/queue-manager/context.d.ts +5 -0
  121. package/dist/types/src/application/queue-manager/control.d.ts +20 -0
  122. package/dist/types/src/application/queue-manager/delivery.d.ts +33 -0
  123. package/dist/types/src/application/queue-manager/dependencies.d.ts +8 -0
  124. package/dist/types/src/application/queue-manager/dependency-runtime.d.ts +8 -0
  125. package/dist/types/src/application/queue-manager/flow-failures.d.ts +18 -0
  126. package/dist/types/src/application/queue-manager/flow-options.d.ts +8 -0
  127. package/dist/types/src/application/queue-manager/job-management.d.ts +17 -0
  128. package/dist/types/src/application/queue-manager/lifecycle.d.ts +4 -0
  129. package/dist/types/src/application/queue-manager/limits.d.ts +58 -0
  130. package/dist/types/src/application/queue-manager/locks.d.ts +21 -0
  131. package/dist/types/src/application/queue-manager/observability.d.ts +16 -0
  132. package/dist/types/src/application/queue-manager/queries.d.ts +24 -0
  133. package/dist/types/src/application/queue-manager/repeat.d.ts +4 -0
  134. package/dist/types/src/application/queue-manager/services.d.ts +19 -0
  135. package/dist/types/src/application/queue-manager/state.d.ts +96 -0
  136. package/dist/types/src/application/queue-manager/stats.d.ts +28 -0
  137. package/dist/types/src/application/queueManager.d.ts +5 -0
  138. package/dist/types/src/application/queueStatsAggregator.d.ts +23 -0
  139. package/dist/types/src/application/queueTelemetryJournal.d.ts +24 -0
  140. package/dist/types/src/application/repeatJobs.d.ts +7 -0
  141. package/dist/types/src/application/stallDetection.d.ts +10 -0
  142. package/dist/types/src/application/statsManager.d.ts +59 -0
  143. package/dist/types/src/application/taskErrorTracking.d.ts +22 -0
  144. package/dist/types/src/application/throughputTracker.d.ts +34 -0
  145. package/dist/types/src/application/types/ack.d.ts +136 -0
  146. package/dist/types/src/application/types/background.d.ts +18 -0
  147. package/dist/types/src/application/types/config.d.ts +41 -0
  148. package/dist/types/src/application/types/contextFactory.d.ts +87 -0
  149. package/dist/types/src/application/types/contexts.d.ts +114 -0
  150. package/dist/types/src/application/types/index.d.ts +7 -0
  151. package/dist/types/src/application/types/query.d.ts +23 -0
  152. package/dist/types/src/application/types/queueManager.d.ts +98 -0
  153. package/dist/types/src/application/webhookManager.d.ts +47 -0
  154. package/dist/types/src/application/workerManager.d.ts +61 -0
  155. package/dist/types/src/client/bunqueue/aging.d.ts +16 -0
  156. package/dist/types/src/client/bunqueue/batch.d.ts +16 -0
  157. package/dist/types/src/client/bunqueue/cancellation.d.ts +21 -0
  158. package/dist/types/src/client/bunqueue/circuitBreaker.d.ts +21 -0
  159. package/dist/types/src/client/bunqueue/dedupDebounce.d.ts +12 -0
  160. package/dist/types/src/client/bunqueue/dlqRateLimit.d.ts +26 -0
  161. package/dist/types/src/client/bunqueue/retry.d.ts +8 -0
  162. package/dist/types/src/client/bunqueue/runtime.d.ts +35 -0
  163. package/dist/types/src/client/bunqueue/triggers.d.ts +17 -0
  164. package/dist/types/src/client/bunqueue/ttl.d.ts +17 -0
  165. package/dist/types/src/client/bunqueue/types.d.ts +147 -0
  166. package/dist/types/src/client/bunqueue.d.ts +73 -0
  167. package/dist/types/src/client/dlqConversion.d.ts +5 -0
  168. package/dist/types/src/client/errors.d.ts +24 -0
  169. package/dist/types/src/client/events.d.ts +85 -0
  170. package/dist/types/src/client/flow.d.ts +70 -0
  171. package/dist/types/src/client/flowAtomic.d.ts +9 -0
  172. package/dist/types/src/client/flowJobCoreMethods.d.ts +28 -0
  173. package/dist/types/src/client/flowJobDependencies.d.ts +7 -0
  174. package/dist/types/src/client/flowJobFactory.d.ts +24 -0
  175. package/dist/types/src/client/flowJobMoveMethods.d.ts +16 -0
  176. package/dist/types/src/client/flowJobTypes.d.ts +29 -0
  177. package/dist/types/src/client/flowLegacyPlan.d.ts +16 -0
  178. package/dist/types/src/client/flowOptions.d.ts +10 -0
  179. package/dist/types/src/client/flowPlan.d.ts +16 -0
  180. package/dist/types/src/client/flowPush.d.ts +27 -0
  181. package/dist/types/src/client/flowReader.d.ts +10 -0
  182. package/dist/types/src/client/flowResults.d.ts +11 -0
  183. package/dist/types/src/client/flowTypes.d.ts +77 -0
  184. package/dist/types/src/client/forwarder.d.ts +74 -0
  185. package/dist/types/src/client/groupId.d.ts +1 -0
  186. package/dist/types/src/client/index.d.ts +46 -0
  187. package/dist/types/src/client/jobConversion.d.ts +10 -0
  188. package/dist/types/src/client/jobConversionHelpers.d.ts +28 -0
  189. package/dist/types/src/client/jobConversionTypes.d.ts +88 -0
  190. package/dist/types/src/client/jobDeduplication.d.ts +6 -0
  191. package/dist/types/src/client/jobHelpers.d.ts +31 -0
  192. package/dist/types/src/client/legacyConnectionOptions.d.ts +8 -0
  193. package/dist/types/src/client/manager.d.ts +15 -0
  194. package/dist/types/src/client/pro.d.ts +9 -0
  195. package/dist/types/src/client/queue/addBatcher.d.ts +59 -0
  196. package/dist/types/src/client/queue/bullmqCompat.d.ts +57 -0
  197. package/dist/types/src/client/queue/deduplication.d.ts +14 -0
  198. package/dist/types/src/client/queue/dlq.d.ts +61 -0
  199. package/dist/types/src/client/queue/dlqJobMethods.d.ts +9 -0
  200. package/dist/types/src/client/queue/dlqOps.d.ts +26 -0
  201. package/dist/types/src/client/queue/dlqStats.d.ts +3 -0
  202. package/dist/types/src/client/queue/failWire.d.ts +17 -0
  203. package/dist/types/src/client/queue/helpers.d.ts +19 -0
  204. package/dist/types/src/client/queue/job-proxy/dependencies.d.ts +9 -0
  205. package/dist/types/src/client/queue/job-proxy/reflection.d.ts +2 -0
  206. package/dist/types/src/client/queue/job-proxy/simple.d.ts +3 -0
  207. package/dist/types/src/client/queue/job-proxy/tcp.d.ts +4 -0
  208. package/dist/types/src/client/queue/jobMetadata.d.ts +10 -0
  209. package/dist/types/src/client/queue/jobMove.d.ts +32 -0
  210. package/dist/types/src/client/queue/jobProxy.d.ts +4 -0
  211. package/dist/types/src/client/queue/operations/add/bulk.d.ts +7 -0
  212. package/dist/types/src/client/queue/operations/add/payload.d.ts +25 -0
  213. package/dist/types/src/client/queue/operations/add/single.d.ts +3 -0
  214. package/dist/types/src/client/queue/operations/add.d.ts +2 -0
  215. package/dist/types/src/client/queue/operations/control.d.ts +42 -0
  216. package/dist/types/src/client/queue/operations/counts.d.ts +48 -0
  217. package/dist/types/src/client/queue/operations/groups.d.ts +24 -0
  218. package/dist/types/src/client/queue/operations/management.d.ts +51 -0
  219. package/dist/types/src/client/queue/operations/query.d.ts +50 -0
  220. package/dist/types/src/client/queue/operations/queryStates.d.ts +13 -0
  221. package/dist/types/src/client/queue/operations/queryTcpPages.d.ts +14 -0
  222. package/dist/types/src/client/queue/queue.d.ts +12 -0
  223. package/dist/types/src/client/queue/rateLimit.d.ts +46 -0
  224. package/dist/types/src/client/queue/runtime/compatibility.d.ts +13 -0
  225. package/dist/types/src/client/queue/runtime/configuration.d.ts +46 -0
  226. package/dist/types/src/client/queue/runtime/connection.d.ts +6 -0
  227. package/dist/types/src/client/queue/runtime/control.d.ts +41 -0
  228. package/dist/types/src/client/queue/runtime/queries.d.ts +66 -0
  229. package/dist/types/src/client/queue/runtime/scheduling.d.ts +33 -0
  230. package/dist/types/src/client/queue/runtime/state.d.ts +101 -0
  231. package/dist/types/src/client/queue/scheduler.d.ts +58 -0
  232. package/dist/types/src/client/queue/schedulerPagination.d.ts +7 -0
  233. package/dist/types/src/client/queue/stall.d.ts +20 -0
  234. package/dist/types/src/client/queue/types/add.d.ts +40 -0
  235. package/dist/types/src/client/queue/types/contexts.d.ts +33 -0
  236. package/dist/types/src/client/queue/types/index.d.ts +3 -0
  237. package/dist/types/src/client/queue/types/job.d.ts +50 -0
  238. package/dist/types/src/client/queue/types/runtime.d.ts +35 -0
  239. package/dist/types/src/client/queue/workers.d.ts +36 -0
  240. package/dist/types/src/client/queue-events/tcpSubscription.d.ts +23 -0
  241. package/dist/types/src/client/queue.d.ts +5 -0
  242. package/dist/types/src/client/queueGroup.d.ts +51 -0
  243. package/dist/types/src/client/resolveToken.d.ts +10 -0
  244. package/dist/types/src/client/sandboxed/index.d.ts +7 -0
  245. package/dist/types/src/client/sandboxed/queueOps.d.ts +24 -0
  246. package/dist/types/src/client/sandboxed/runtime/dispatch.d.ts +13 -0
  247. package/dist/types/src/client/sandboxed/runtime/lifecycle.d.ts +20 -0
  248. package/dist/types/src/client/sandboxed/runtime/log.d.ts +1 -0
  249. package/dist/types/src/client/sandboxed/runtime/pool.d.ts +11 -0
  250. package/dist/types/src/client/sandboxed/runtime/recovery.d.ts +11 -0
  251. package/dist/types/src/client/sandboxed/runtime/state.d.ts +39 -0
  252. package/dist/types/src/client/sandboxed/types/index.d.ts +2 -0
  253. package/dist/types/src/client/sandboxed/types/options.d.ts +27 -0
  254. package/dist/types/src/client/sandboxed/types/process.d.ts +39 -0
  255. package/dist/types/src/client/sandboxed/worker.d.ts +4 -0
  256. package/dist/types/src/client/sandboxed/wrapper.d.ts +12 -0
  257. package/dist/types/src/client/sandboxedWorker.d.ts +6 -0
  258. package/dist/types/src/client/tcp/client.d.ts +6 -0
  259. package/dist/types/src/client/tcp/commandQueue.d.ts +23 -0
  260. package/dist/types/src/client/tcp/connection.d.ts +4 -0
  261. package/dist/types/src/client/tcp/errors.d.ts +6 -0
  262. package/dist/types/src/client/tcp/health.d.ts +60 -0
  263. package/dist/types/src/client/tcp/index.d.ts +11 -0
  264. package/dist/types/src/client/tcp/reconnect.d.ts +47 -0
  265. package/dist/types/src/client/tcp/runtime/commands.d.ts +9 -0
  266. package/dist/types/src/client/tcp/runtime/connectivity.d.ts +13 -0
  267. package/dist/types/src/client/tcp/runtime/health.d.ts +14 -0
  268. package/dist/types/src/client/tcp/runtime/lifecycle.d.ts +8 -0
  269. package/dist/types/src/client/tcp/runtime/state.d.ts +50 -0
  270. package/dist/types/src/client/tcp/shared.d.ts +12 -0
  271. package/dist/types/src/client/tcp/transport.d.ts +18 -0
  272. package/dist/types/src/client/tcp/types/command.d.ts +9 -0
  273. package/dist/types/src/client/tcp/types/connection.d.ts +31 -0
  274. package/dist/types/src/client/tcp/types/index.d.ts +5 -0
  275. package/dist/types/src/client/tcp/types/socket.d.ts +8 -0
  276. package/dist/types/src/client/tcp/types/tls.d.ts +4 -0
  277. package/dist/types/src/client/tcp/types.d.ts +2 -0
  278. package/dist/types/src/client/tcpClient.d.ts +6 -0
  279. package/dist/types/src/client/tcpPool.d.ts +69 -0
  280. package/dist/types/src/client/types/connection.d.ts +30 -0
  281. package/dist/types/src/client/types/dlq.d.ts +45 -0
  282. package/dist/types/src/client/types/events.d.ts +54 -0
  283. package/dist/types/src/client/types/flow.d.ts +22 -0
  284. package/dist/types/src/client/types/index.d.ts +10 -0
  285. package/dist/types/src/client/types/job.d.ts +131 -0
  286. package/dist/types/src/client/types/metrics.d.ts +1 -0
  287. package/dist/types/src/client/types/options.d.ts +70 -0
  288. package/dist/types/src/client/types/worker.d.ts +54 -0
  289. package/dist/types/src/client/types.d.ts +2 -0
  290. package/dist/types/src/client/worker/ackBatcher.d.ts +55 -0
  291. package/dist/types/src/client/worker/ackFrontier.d.ts +21 -0
  292. package/dist/types/src/client/worker/ackOutcome.d.ts +8 -0
  293. package/dist/types/src/client/worker/batchExecution.d.ts +14 -0
  294. package/dist/types/src/client/worker/constants.d.ts +7 -0
  295. package/dist/types/src/client/worker/groupConcurrency.d.ts +49 -0
  296. package/dist/types/src/client/worker/handlers/completion.d.ts +29 -0
  297. package/dist/types/src/client/worker/handlers/dependencies.d.ts +11 -0
  298. package/dist/types/src/client/worker/handlers/mutations.d.ts +23 -0
  299. package/dist/types/src/client/worker/handlers/queries.d.ts +15 -0
  300. package/dist/types/src/client/worker/jobParser.d.ts +9 -0
  301. package/dist/types/src/client/worker/processor.d.ts +11 -0
  302. package/dist/types/src/client/worker/processorHandlers.d.ts +4 -0
  303. package/dist/types/src/client/worker/processorOutcome.d.ts +14 -0
  304. package/dist/types/src/client/worker/processorResult.d.ts +2 -0
  305. package/dist/types/src/client/worker/runtime/buffer.d.ts +8 -0
  306. package/dist/types/src/client/worker/runtime/control.d.ts +28 -0
  307. package/dist/types/src/client/worker/runtime/execution.d.ts +16 -0
  308. package/dist/types/src/client/worker/runtime/lifecycle.d.ts +7 -0
  309. package/dist/types/src/client/worker/runtime/manual.d.ts +10 -0
  310. package/dist/types/src/client/worker/runtime/options.d.ts +5 -0
  311. package/dist/types/src/client/worker/runtime/polling.d.ts +14 -0
  312. package/dist/types/src/client/worker/runtime/state.d.ts +121 -0
  313. package/dist/types/src/client/worker/types/index.d.ts +5 -0
  314. package/dist/types/src/client/worker/types/manual.d.ts +7 -0
  315. package/dist/types/src/client/worker/types/options.d.ts +26 -0
  316. package/dist/types/src/client/worker/types/outcome.d.ts +23 -0
  317. package/dist/types/src/client/worker/types/processor.d.ts +25 -0
  318. package/dist/types/src/client/worker/types/transport.d.ts +11 -0
  319. package/dist/types/src/client/worker/worker.d.ts +6 -0
  320. package/dist/types/src/client/worker/workerHeartbeat.d.ts +15 -0
  321. package/dist/types/src/client/worker/workerPull.d.ts +24 -0
  322. package/dist/types/src/client/worker/workerRateLimiter.d.ts +51 -0
  323. package/dist/types/src/client/worker.d.ts +6 -0
  324. package/dist/types/src/client/workflow/admission.d.ts +45 -0
  325. package/dist/types/src/client/workflow/clock.d.ts +60 -0
  326. package/dist/types/src/client/workflow/compensationChild.d.ts +33 -0
  327. package/dist/types/src/client/workflow/compensationClaim.d.ts +11 -0
  328. package/dist/types/src/client/workflow/compensationPass.d.ts +17 -0
  329. package/dist/types/src/client/workflow/compensationSupport.d.ts +24 -0
  330. package/dist/types/src/client/workflow/compensator.d.ts +34 -0
  331. package/dist/types/src/client/workflow/definitionGuard.d.ts +11 -0
  332. package/dist/types/src/client/workflow/emitter.d.ts +17 -0
  333. package/dist/types/src/client/workflow/engine.d.ts +66 -0
  334. package/dist/types/src/client/workflow/eventTypes.d.ts +44 -0
  335. package/dist/types/src/client/workflow/executionFence.d.ts +15 -0
  336. package/dist/types/src/client/workflow/executionTypes.d.ts +133 -0
  337. package/dist/types/src/client/workflow/executor.d.ts +52 -0
  338. package/dist/types/src/client/workflow/executorLifecycle.d.ts +19 -0
  339. package/dist/types/src/client/workflow/executorNodes.d.ts +18 -0
  340. package/dist/types/src/client/workflow/executorQueue.d.ts +9 -0
  341. package/dist/types/src/client/workflow/forEachRunner.d.ts +4 -0
  342. package/dist/types/src/client/workflow/identity.d.ts +48 -0
  343. package/dist/types/src/client/workflow/index.d.ts +23 -0
  344. package/dist/types/src/client/workflow/loops.d.ts +11 -0
  345. package/dist/types/src/client/workflow/mapRunner.d.ts +4 -0
  346. package/dist/types/src/client/workflow/recovery.d.ts +32 -0
  347. package/dist/types/src/client/workflow/rollbackControl.d.ts +37 -0
  348. package/dist/types/src/client/workflow/runner.d.ts +23 -0
  349. package/dist/types/src/client/workflow/runnerTiming.d.ts +14 -0
  350. package/dist/types/src/client/workflow/stepTypes.d.ts +171 -0
  351. package/dist/types/src/client/workflow/store.d.ts +83 -0
  352. package/dist/types/src/client/workflow/storeCodec.d.ts +7 -0
  353. package/dist/types/src/client/workflow/storeExecutionCodec.d.ts +11 -0
  354. package/dist/types/src/client/workflow/storeListing.d.ts +11 -0
  355. package/dist/types/src/client/workflow/storeMaintenance.d.ts +4 -0
  356. package/dist/types/src/client/workflow/storeSignals.d.ts +70 -0
  357. package/dist/types/src/client/workflow/subWorkflowRunner.d.ts +14 -0
  358. package/dist/types/src/client/workflow/types.d.ts +4 -0
  359. package/dist/types/src/client/workflow/unwindPlan.d.ts +87 -0
  360. package/dist/types/src/client/workflow/waitFor.d.ts +56 -0
  361. package/dist/types/src/client/workflow/workflow.d.ts +70 -0
  362. package/dist/types/src/client/workflow/workflowDecisions.d.ts +11 -0
  363. package/dist/types/src/client/workflow/workflowDefinition.d.ts +16 -0
  364. package/dist/types/src/client/workflow/workflowIntrospection.d.ts +5 -0
  365. package/dist/types/src/client/workflow/workflowValidation.d.ts +44 -0
  366. package/dist/types/src/config/index.d.ts +9 -0
  367. package/dist/types/src/config/loader.d.ts +7 -0
  368. package/dist/types/src/config/resolve.d.ts +59 -0
  369. package/dist/types/src/config/types.d.ts +88 -0
  370. package/dist/types/src/domain/job/constants.d.ts +12 -0
  371. package/dist/types/src/domain/job/create.d.ts +2 -0
  372. package/dist/types/src/domain/job/groupFifoOrder.d.ts +9 -0
  373. package/dist/types/src/domain/job/ids.d.ts +7 -0
  374. package/dist/types/src/domain/job/locks.d.ts +4 -0
  375. package/dist/types/src/domain/job/payload.d.ts +18 -0
  376. package/dist/types/src/domain/job/state.d.ts +8 -0
  377. package/dist/types/src/domain/job/terminal.d.ts +3 -0
  378. package/dist/types/src/domain/queue/dependencyTracker.d.ts +78 -0
  379. package/dist/types/src/domain/queue/dlqShard.d.ts +66 -0
  380. package/dist/types/src/domain/queue/groupLimiterManager.d.ts +30 -0
  381. package/dist/types/src/domain/queue/groupScheduler.d.ts +31 -0
  382. package/dist/types/src/domain/queue/groupSchedulerOrder.d.ts +6 -0
  383. package/dist/types/src/domain/queue/limiterManager.d.ts +68 -0
  384. package/dist/types/src/domain/queue/priorityQueue.d.ts +54 -0
  385. package/dist/types/src/domain/queue/priorityQueueOrder.d.ts +3 -0
  386. package/dist/types/src/domain/queue/shard/dependencies.d.ts +11 -0
  387. package/dist/types/src/domain/queue/shard/dlq.d.ts +26 -0
  388. package/dist/types/src/domain/queue/shard/keys.d.ts +19 -0
  389. package/dist/types/src/domain/queue/shard/lifecycle.d.ts +10 -0
  390. package/dist/types/src/domain/queue/shard/limits.d.ts +47 -0
  391. package/dist/types/src/domain/queue/shard/metrics.d.ts +32 -0
  392. package/dist/types/src/domain/queue/shard/state.d.ts +40 -0
  393. package/dist/types/src/domain/queue/shard.d.ts +7 -0
  394. package/dist/types/src/domain/queue/shardCounters.d.ts +35 -0
  395. package/dist/types/src/domain/queue/temporalIndex.d.ts +24 -0
  396. package/dist/types/src/domain/queue/temporalManager.d.ts +72 -0
  397. package/dist/types/src/domain/queue/uniqueKeyManager.d.ts +33 -0
  398. package/dist/types/src/domain/queue/waiterManager.d.ts +18 -0
  399. package/dist/types/src/domain/response/builders.d.ts +15 -0
  400. package/dist/types/src/domain/types/command.d.ts +2 -0
  401. package/dist/types/src/domain/types/commands/base.d.ts +5 -0
  402. package/dist/types/src/domain/types/commands/core.d.ts +110 -0
  403. package/dist/types/src/domain/types/commands/cron.d.ts +36 -0
  404. package/dist/types/src/domain/types/commands/dashboard.d.ts +13 -0
  405. package/dist/types/src/domain/types/commands/dlq.d.ts +44 -0
  406. package/dist/types/src/domain/types/commands/extended.d.ts +63 -0
  407. package/dist/types/src/domain/types/commands/index.d.ts +12 -0
  408. package/dist/types/src/domain/types/commands/limits.d.ts +108 -0
  409. package/dist/types/src/domain/types/commands/management.d.ts +73 -0
  410. package/dist/types/src/domain/types/commands/monitoring.d.ts +49 -0
  411. package/dist/types/src/domain/types/commands/protocol.d.ts +20 -0
  412. package/dist/types/src/domain/types/commands/query.d.ts +46 -0
  413. package/dist/types/src/domain/types/commands/union.d.ts +13 -0
  414. package/dist/types/src/domain/types/commands/workers.d.ts +39 -0
  415. package/dist/types/src/domain/types/cron.d.ts +91 -0
  416. package/dist/types/src/domain/types/deduplication.d.ts +43 -0
  417. package/dist/types/src/domain/types/dlq.d.ts +136 -0
  418. package/dist/types/src/domain/types/flow.d.ts +25 -0
  419. package/dist/types/src/domain/types/group.d.ts +26 -0
  420. package/dist/types/src/domain/types/job.d.ts +8 -0
  421. package/dist/types/src/domain/types/jobs/model.d.ts +153 -0
  422. package/dist/types/src/domain/types/metrics.d.ts +16 -0
  423. package/dist/types/src/domain/types/priorityQueue.d.ts +13 -0
  424. package/dist/types/src/domain/types/protocol.d.ts +5 -0
  425. package/dist/types/src/domain/types/queue.d.ts +110 -0
  426. package/dist/types/src/domain/types/response.d.ts +3 -0
  427. package/dist/types/src/domain/types/responses/model.d.ts +152 -0
  428. package/dist/types/src/domain/types/shard.d.ts +4 -0
  429. package/dist/types/src/domain/types/stall.d.ts +48 -0
  430. package/dist/types/src/domain/types/webhook.d.ts +42 -0
  431. package/dist/types/src/domain/types/worker.d.ts +40 -0
  432. package/dist/types/src/infrastructure/backup/backupTelemetry.d.ts +30 -0
  433. package/dist/types/src/infrastructure/backup/s3BackupConfig.d.ts +80 -0
  434. package/dist/types/src/infrastructure/cloud/types/config.d.ts +18 -0
  435. package/dist/types/src/infrastructure/cloud/types/event.d.ts +14 -0
  436. package/dist/types/src/infrastructure/cloud/types/snapshot.d.ts +52 -0
  437. package/dist/types/src/infrastructure/cloud/types/snapshotCore.d.ts +125 -0
  438. package/dist/types/src/infrastructure/cloud/types/snapshotJobs.d.ts +124 -0
  439. package/dist/types/src/infrastructure/cloud/types/snapshotTelemetry.d.ts +100 -0
  440. package/dist/types/src/infrastructure/cloud/types.d.ts +3 -0
  441. package/dist/types/src/infrastructure/persistence/batchInsert.d.ts +13 -0
  442. package/dist/types/src/infrastructure/persistence/completedJobCountSchema.d.ts +6 -0
  443. package/dist/types/src/infrastructure/persistence/dependencyCompletionSchema.d.ts +6 -0
  444. package/dist/types/src/infrastructure/persistence/dependencyCompletionStore.d.ts +40 -0
  445. package/dist/types/src/infrastructure/persistence/index.d.ts +5 -0
  446. package/dist/types/src/infrastructure/persistence/jobOptionsBlob.d.ts +19 -0
  447. package/dist/types/src/infrastructure/persistence/legacyNameMigration.d.ts +17 -0
  448. package/dist/types/src/infrastructure/persistence/migrationProgressSchema.d.ts +2 -0
  449. package/dist/types/src/infrastructure/persistence/migrations.d.ts +3 -0
  450. package/dist/types/src/infrastructure/persistence/schema.d.ts +8 -0
  451. package/dist/types/src/infrastructure/persistence/sqlite/admission.d.ts +9 -0
  452. package/dist/types/src/infrastructure/persistence/sqlite/completed.d.ts +17 -0
  453. package/dist/types/src/infrastructure/persistence/sqlite/control.d.ts +48 -0
  454. package/dist/types/src/infrastructure/persistence/sqlite/flows.d.ts +26 -0
  455. package/dist/types/src/infrastructure/persistence/sqlite/jobLifecycle.d.ts +17 -0
  456. package/dist/types/src/infrastructure/persistence/sqlite/jobs.d.ts +15 -0
  457. package/dist/types/src/infrastructure/persistence/sqlite/lifecycle.d.ts +6 -0
  458. package/dist/types/src/infrastructure/persistence/sqlite/mutations.d.ts +27 -0
  459. package/dist/types/src/infrastructure/persistence/sqlite/queries.d.ts +23 -0
  460. package/dist/types/src/infrastructure/persistence/sqlite/queueDeletionSql.d.ts +3 -0
  461. package/dist/types/src/infrastructure/persistence/sqlite/records.d.ts +24 -0
  462. package/dist/types/src/infrastructure/persistence/sqlite/state.d.ts +42 -0
  463. package/dist/types/src/infrastructure/persistence/sqlite/telemetry.d.ts +17 -0
  464. package/dist/types/src/infrastructure/persistence/sqlite/telemetryStore.d.ts +30 -0
  465. package/dist/types/src/infrastructure/persistence/sqlite/telemetryWrites.d.ts +47 -0
  466. package/dist/types/src/infrastructure/persistence/sqlite.d.ts +6 -0
  467. package/dist/types/src/infrastructure/persistence/sqliteBatch.d.ts +4 -0
  468. package/dist/types/src/infrastructure/persistence/sqliteMigration.d.ts +5 -0
  469. package/dist/types/src/infrastructure/persistence/sqliteSerializer.d.ts +50 -0
  470. package/dist/types/src/infrastructure/persistence/statements.d.ts +86 -0
  471. package/dist/types/src/infrastructure/persistence/types/admission.d.ts +8 -0
  472. package/dist/types/src/infrastructure/persistence/types/batch.d.ts +12 -0
  473. package/dist/types/src/infrastructure/persistence/types/sqlite.d.ts +27 -0
  474. package/dist/types/src/infrastructure/persistence/writeBuffer.d.ts +48 -0
  475. package/dist/types/src/infrastructure/persistence/writeBufferPending.d.ts +11 -0
  476. package/dist/types/src/infrastructure/scheduler/cron/execution.d.ts +12 -0
  477. package/dist/types/src/infrastructure/scheduler/cron/persisted.d.ts +5 -0
  478. package/dist/types/src/infrastructure/scheduler/cron/runtime.d.ts +31 -0
  479. package/dist/types/src/infrastructure/scheduler/cron/validation.d.ts +3 -0
  480. package/dist/types/src/infrastructure/scheduler/cronParser.d.ts +45 -0
  481. package/dist/types/src/infrastructure/scheduler/cronScheduler.d.ts +5 -0
  482. package/dist/types/src/infrastructure/scheduler/types/cronScheduler.d.ts +16 -0
  483. package/dist/types/src/infrastructure/server/protocol/commands.d.ts +8 -0
  484. package/dist/types/src/infrastructure/server/protocol/frameParser.d.ts +16 -0
  485. package/dist/types/src/infrastructure/server/protocol/lineBuffer.d.ts +6 -0
  486. package/dist/types/src/infrastructure/server/protocol/validation.d.ts +10 -0
  487. package/dist/types/src/infrastructure/server/protocol.d.ts +6 -0
  488. package/dist/types/src/infrastructure/server/socketWriteQueue.d.ts +66 -0
  489. package/dist/types/src/infrastructure/server/types/protocol.d.ts +4 -0
  490. package/dist/types/src/require-bun.d.ts +13 -0
  491. package/dist/types/src/shared/asyncLock.d.ts +13 -0
  492. package/dist/types/src/shared/boundedMap.d.ts +30 -0
  493. package/dist/types/src/shared/boundedSet.d.ts +26 -0
  494. package/dist/types/src/shared/hash.d.ts +30 -0
  495. package/dist/types/src/shared/histogram.d.ts +23 -0
  496. package/dist/types/src/shared/lock.d.ts +13 -0
  497. package/dist/types/src/shared/lockError.d.ts +3 -0
  498. package/dist/types/src/shared/lockTimeout.d.ts +2 -0
  499. package/dist/types/src/shared/logger.d.ts +48 -0
  500. package/dist/types/src/shared/lru.d.ts +9 -0
  501. package/dist/types/src/shared/lruMap.d.ts +42 -0
  502. package/dist/types/src/shared/lruSet.d.ts +36 -0
  503. package/dist/types/src/shared/minHeap.d.ts +43 -0
  504. package/dist/types/src/shared/msgpack.d.ts +3 -0
  505. package/dist/types/src/shared/pausedView.d.ts +19 -0
  506. package/dist/types/src/shared/rwLock.d.ts +22 -0
  507. package/dist/types/src/shared/serialization.d.ts +24 -0
  508. package/dist/types/src/shared/skipList.d.ts +97 -0
  509. package/dist/types/src/shared/skipListNodes.d.ts +6 -0
  510. package/dist/types/src/shared/storageHealth.d.ts +9 -0
  511. package/dist/types/src/shared/ttlMap.d.ts +81 -0
  512. package/dist/types/src/shared/types/lock.d.ts +7 -0
  513. package/dist/types/src/shared/types/skipList.d.ts +4 -0
  514. package/dist/types/src/shared/version.d.ts +4 -0
  515. package/dist/types/src/shared/webhookValidation.d.ts +6 -0
  516. package/package.json +27 -9
  517. package/src/ack-batcher.ts +8 -5
  518. package/src/bunqueue/bunqueue-api.ts +1 -1
  519. package/src/bunqueue/bunqueue.ts +2 -1
  520. package/src/canonical-transport/bun-sqlite-types.ts +22 -0
  521. package/src/canonical-transport/dlq.ts +12 -0
  522. package/src/canonical-transport/embedded.ts +55 -0
  523. package/src/canonical-transport/runtime.ts +49 -0
  524. package/src/canonical-transport/thread-worker.ts +83 -0
  525. package/src/canonical-transport/transport.ts +153 -0
  526. package/src/connection.ts +25 -30
  527. package/src/errors.ts +3 -0
  528. package/src/flow-commit.ts +45 -0
  529. package/src/flow-plan-legacy.ts +117 -0
  530. package/src/flow-plan.ts +209 -0
  531. package/src/flow-types.ts +4 -0
  532. package/src/flow.ts +31 -163
  533. package/src/frame.ts +5 -2
  534. package/src/index.ts +7 -75
  535. package/src/job.ts +43 -9
  536. package/src/legacy.ts +91 -0
  537. package/src/observability.ts +59 -1
  538. package/src/queue-admin.ts +5 -5
  539. package/src/queue-control.ts +8 -6
  540. package/src/queue.ts +10 -6
  541. package/src/serialization.ts +93 -0
  542. package/src/terminal-outcome.ts +58 -0
  543. package/src/types.ts +3 -6
  544. package/src/worker-base.ts +9 -6
  545. package/src/worker-slot-signal.ts +23 -0
  546. package/src/worker.ts +11 -5
  547. package/dist/backpressure.js +0 -39
  548. package/dist/bunqueue/aging.js +0 -53
  549. package/dist/bunqueue/batch.js +0 -60
  550. package/dist/bunqueue/bunqueue-api.js +0 -116
  551. package/dist/bunqueue/bunqueue.js +0 -194
  552. package/dist/bunqueue/cancellation.js +0 -48
  553. package/dist/bunqueue/circuit-breaker.js +0 -69
  554. package/dist/bunqueue/dedup-debounce.js +0 -37
  555. package/dist/bunqueue/dlq-rate-limit.js +0 -65
  556. package/dist/bunqueue/rate-gate.js +0 -61
  557. package/dist/bunqueue/retry.js +0 -56
  558. package/dist/bunqueue/triggers.js +0 -42
  559. package/dist/bunqueue/ttl.js +0 -31
  560. package/dist/bunqueue/types.js +0 -6
  561. package/dist/connection-pool.js +0 -60
  562. package/dist/connection-types.js +0 -2
  563. package/dist/connection.js +0 -281
  564. package/dist/errors.js +0 -25
  565. package/dist/flow-types.js +0 -2
  566. package/dist/flow.js +0 -212
  567. package/dist/job.js +0 -155
  568. package/dist/observability.js +0 -110
  569. package/dist/queue-admin.js +0 -158
  570. package/dist/queue-control.js +0 -107
  571. package/dist/queue-query.js +0 -187
  572. package/dist/queue.js +0 -92
  573. package/dist/responses.js +0 -10
  574. package/dist/socket-factory.js +0 -47
  575. package/dist/types.js +0 -50
  576. package/dist/worker-base.js +0 -159
  577. package/dist/worker-types.js +0 -5
  578. package/dist/worker.js +0 -211
  579. /package/dist/{backpressure.d.ts → types/sdk/typescript/src/backpressure.d.ts} +0 -0
  580. /package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/cancellation.d.ts +0 -0
package/src/legacy.ts ADDED
@@ -0,0 +1,91 @@
1
+ /**
2
+ * bunqueue-client — cross-runtime TypeScript SDK for bunqueue (TCP mode).
3
+ * Works on Node.js ≥20, Bun and Deno ≥2 (uses only node: builtins + msgpackr).
4
+ */
5
+
6
+ // Simple Mode (Bunqueue): all-in-one Queue + Worker, 1:1 with the official client
7
+ export { Bunqueue } from './bunqueue/bunqueue.js';
8
+ export type { DlqFilter, DlqStats } from './bunqueue/dlq-rate-limit.js';
9
+ export type {
10
+ BatchConfig,
11
+ BatchProcessor,
12
+ BunqueueConnection,
13
+ BunqueueDebounceConfig,
14
+ BunqueueDeduplicationConfig,
15
+ BunqueueDlqConfig,
16
+ BunqueueMiddleware,
17
+ BunqueueOptions,
18
+ CircuitBreakerConfig,
19
+ CircuitState,
20
+ JobTtlConfig,
21
+ PriorityAgingConfig,
22
+ RateLimiterOptions,
23
+ RetryConfig,
24
+ RetryStrategy,
25
+ TriggerRule,
26
+ } from './bunqueue/types.js';
27
+ export type { Command, ConnectionOptions, Response, TlsOption } from './connection.js';
28
+ export { Connection } from './connection.js';
29
+ export { ConnectionPool } from './connection-pool.js';
30
+ export type { ConnectionLike } from './connection-types.js';
31
+ export {
32
+ AuthError,
33
+ BunqueueError,
34
+ CommandError,
35
+ CommandTimeoutError,
36
+ ConnectionClosedError,
37
+ SerializationError,
38
+ UnrecoverableError,
39
+ } from './errors.js';
40
+ export { FlowProducer } from './flow.js';
41
+ export type {
42
+ FlowJob,
43
+ FlowOptions,
44
+ FlowProducerOptions,
45
+ FlowStep,
46
+ GetFlowOptions,
47
+ JobNode,
48
+ } from './flow-types.js';
49
+ export { MAX_FRAME_SIZE, PROTOCOL_VERSION } from './frame.js';
50
+ export type { JobRaw } from './job.js';
51
+ export { Job } from './job.js';
52
+ export type {
53
+ Logger,
54
+ LogLevel,
55
+ Observability,
56
+ TelemetryErrorOperation,
57
+ TelemetryEvent,
58
+ TelemetryHandler,
59
+ } from './observability.js';
60
+ export { consoleLogger, noopLogger } from './observability.js';
61
+ export type { BulkJobEntry, QueueOptions } from './queue.js';
62
+ export { Queue } from './queue.js';
63
+ export type { SchedulerOptions } from './queue-admin.js';
64
+ export type {
65
+ BatchResponse,
66
+ CountResponse,
67
+ DataResponse,
68
+ JobCountsResponse,
69
+ JobResponse,
70
+ JobsResponse,
71
+ OkResponse,
72
+ PausedResponse,
73
+ ProgressResponse,
74
+ PulledJobResponse,
75
+ PulledJobsResponse,
76
+ ResultResponse,
77
+ StateResponse,
78
+ WaitJobResponse,
79
+ } from './responses.js';
80
+ export type {
81
+ BackoffOptions,
82
+ DeduplicationOptions,
83
+ JobCounts,
84
+ JobOptions,
85
+ JobStateName,
86
+ RepeatOptions,
87
+ } from './types.js';
88
+ export { Worker } from './worker.js';
89
+ export type { AckBatchOptions, Processor, WorkerEventMap, WorkerOptions } from './worker-types.js';
90
+
91
+ export const __version__ = '0.2.0';
@@ -45,6 +45,8 @@ export function consoleLogger(min: LogLevel = 'info'): Logger {
45
45
  }
46
46
 
47
47
  /** A single telemetry data point. A discriminated union keyed on `type`. */
48
+ export type TelemetryErrorOperation = 'connect' | 'socket' | 'write' | 'serialization';
49
+
48
50
  export type TelemetryEvent =
49
51
  | { type: 'command'; cmd: string; reqId: string; durationMs: number; ok: boolean }
50
52
  | { type: 'command_timeout'; cmd: string; reqId: string }
@@ -52,7 +54,14 @@ export type TelemetryEvent =
52
54
  | { type: 'disconnect'; host: string; port: number; generation: number }
53
55
  | { type: 'reconnect_scheduled'; host: string; port: number; attempt: number; delayMs: number }
54
56
  | { type: 'auth'; ok: boolean }
55
- | { type: 'backpressure'; inFlight: number; maxInFlight: number };
57
+ | { type: 'backpressure'; inFlight: number; maxInFlight: number }
58
+ | {
59
+ type: 'error';
60
+ operation: TelemetryErrorOperation;
61
+ errorType: string;
62
+ message: string;
63
+ code?: string;
64
+ };
56
65
 
57
66
  export type TelemetryHandler = (event: TelemetryEvent) => void;
58
67
 
@@ -74,6 +83,13 @@ export interface Observability {
74
83
  /** High-resolution monotonic clock (Node/Bun/Deno all expose `performance`). */
75
84
  export const nowMs = (): number => performance.now();
76
85
 
86
+ const ERROR_MESSAGES: Record<TelemetryErrorOperation, string> = {
87
+ connect: 'connection failed',
88
+ socket: 'socket failed',
89
+ write: 'socket write failed',
90
+ serialization: 'command serialization failed',
91
+ };
92
+
77
93
  /**
78
94
  * Fans a telemetry event out to (1) the telemetry sink, (2) the logger, and
79
95
  * (3) — for lifecycle events — the owning EventEmitter, so users can both
@@ -147,6 +163,48 @@ export class Telemetry {
147
163
  this.dispatch({ type: 'backpressure', inFlight, maxInFlight });
148
164
  }
149
165
 
166
+ /**
167
+ * Report transport failures without forwarding raw messages: those can
168
+ * contain remote-controlled text or application data in third-party errors.
169
+ */
170
+ error(operation: TelemetryErrorOperation, error: unknown): void {
171
+ const errorType =
172
+ error instanceof Error && /^[A-Za-z][A-Za-z0-9]{0,63}$/.test(error.name)
173
+ ? error.name
174
+ : 'Error';
175
+ const rawCode =
176
+ typeof error === 'object' && error !== null && 'code' in error ? error.code : undefined;
177
+ const code =
178
+ typeof rawCode === 'string' && /^[A-Z0-9_]{1,32}$/.test(rawCode) ? rawCode : undefined;
179
+ const event: TelemetryEvent = {
180
+ type: 'error',
181
+ operation,
182
+ errorType,
183
+ message: ERROR_MESSAGES[operation],
184
+ ...(code ? { code } : {}),
185
+ };
186
+ this.logger.error(event.message, { operation, errorType, ...(code ? { code } : {}) });
187
+ this.dispatch(event);
188
+ }
189
+
190
+ capture<T>(operation: TelemetryErrorOperation, fn: () => T): T {
191
+ try {
192
+ return fn();
193
+ } catch (error) {
194
+ this.error(operation, error);
195
+ throw error;
196
+ }
197
+ }
198
+
199
+ async captureAsync<T>(operation: TelemetryErrorOperation, promise: Promise<T>): Promise<T> {
200
+ try {
201
+ return await promise;
202
+ } catch (error) {
203
+ this.error(operation, error);
204
+ throw error;
205
+ }
206
+ }
207
+
150
208
  private dispatch(event: TelemetryEvent): void {
151
209
  // A throwing sink or lifecycle listener must never break the transport:
152
210
  // dispatch runs inside socket 'data' handlers and the connect path.
@@ -6,7 +6,7 @@
6
6
  import { CommandError } from './errors.js';
7
7
  import { compact } from './frame.js';
8
8
  import type { Queue } from './queue.js';
9
- import { type JobOptions, jobPayload, wireJobOptions } from './types.js';
9
+ import { type JobOptions, wireJobOptions } from './types.js';
10
10
 
11
11
  type Ctx = Queue<unknown>;
12
12
  type Raw = Record<string, unknown>;
@@ -70,9 +70,8 @@ export const adminMethods = {
70
70
 
71
71
  // -------------------------------------------------- rate limit / concurrency
72
72
 
73
- /** `duration` accepted for signature parity; the TCP wire carries only `limit`. */
74
- async setGlobalRateLimit(this: Ctx, max: number, _duration?: number): Promise<void> {
75
- await this.call({ cmd: 'RateLimit', queue: this.name, limit: max });
73
+ async setGlobalRateLimit(this: Ctx, max: number, duration?: number): Promise<void> {
74
+ await this.call({ cmd: 'RateLimit', queue: this.name, limit: max, duration });
76
75
  },
77
76
 
78
77
  async removeGlobalRateLimit(this: Ctx): Promise<void> {
@@ -104,8 +103,9 @@ export const adminMethods = {
104
103
  compact({
105
104
  cmd: 'Cron',
106
105
  name: schedulerId,
106
+ jobName: template.name ?? schedulerId,
107
107
  queue: this.name,
108
- data: jobPayload(template.name ?? schedulerId, template.data ?? {}),
108
+ data: 'data' in template ? template.data : {},
109
109
  schedule: repeat.pattern,
110
110
  repeatEvery: repeat.every,
111
111
  priority: template.opts?.priority,
@@ -110,16 +110,18 @@ export const controlMethods = {
110
110
  await this.call({ cmd: 'ChangePriority', id, priority: opts.priority, lifo: opts.lifo });
111
111
  },
112
112
 
113
- async changeJobDelay(this: Ctx, id: string, delayMs: number): Promise<void> {
114
- await this.call({ cmd: 'ChangeDelay', id, delay: delayMs });
113
+ async changeJobDelay(this: Ctx, id: string, delayMs: number, token?: string): Promise<void> {
114
+ await this.call(compact({ cmd: 'ChangeDelay', id, delay: delayMs, token }) as { cmd: string });
115
115
  },
116
116
 
117
- async moveJobToWait(this: Ctx, id: string): Promise<void> {
118
- await this.call({ cmd: 'MoveToWait', id });
117
+ async moveJobToWait(this: Ctx, id: string, token?: string): Promise<void> {
118
+ await this.call(compact({ cmd: 'MoveToWait', id, token }) as { cmd: string });
119
119
  },
120
120
 
121
- async moveJobToDelayed(this: Ctx, id: string, delayMs: number): Promise<void> {
122
- await this.call({ cmd: 'MoveToDelayed', id, delay: delayMs });
121
+ async moveJobToDelayed(this: Ctx, id: string, delayMs: number, token?: string): Promise<void> {
122
+ await this.call(
123
+ compact({ cmd: 'MoveToDelayed', id, delay: delayMs, token }) as { cmd: string }
124
+ );
123
125
  },
124
126
 
125
127
  async extendJobLock(this: Ctx, id: string, token: string, durationMs: number): Promise<void> {
package/src/queue.ts CHANGED
@@ -41,7 +41,7 @@ export interface BulkJobEntry<T = unknown> {
41
41
  opts?: JobOptions;
42
42
  }
43
43
 
44
- // biome-ignore lint/suspicious/noUnsafeDeclarationMerging: prototype-mixin composition — Object.assign at the bottom installs exactly the methods the merged interface declares
44
+ // oxlint-disable-next-line typescript/no-unsafe-declaration-merging -- prototype-mixin composition installs the declared methods with Object.assign below
45
45
  export class Queue<T = unknown> {
46
46
  readonly name: string;
47
47
  readonly connection: ConnectionLike;
@@ -83,10 +83,10 @@ export class Queue<T = unknown> {
83
83
  const response = await this.call({
84
84
  cmd: 'PUSH',
85
85
  queue: this.name,
86
- data: payload,
86
+ ...payload,
87
87
  ...wireJobOptions(opts),
88
88
  });
89
- return new Job<T>({ id: response.id, queue: this.name, data: payload }, this.connection);
89
+ return new Job<T>({ id: response.id, queue: this.name, ...payload }, this.connection);
90
90
  }
91
91
 
92
92
  /** Add many jobs in one round-trip; returns Job stubs. */
@@ -101,12 +101,16 @@ export class Queue<T = unknown> {
101
101
  opts.customId = opts.jobId;
102
102
  delete opts.jobId;
103
103
  }
104
- return { data: jobPayload(entry.name, entry.data), ...opts };
104
+ return { ...jobPayload(entry.name, entry.data), ...opts };
105
105
  });
106
106
  const response = await this.call({ cmd: 'PUSHB', queue: this.name, jobs: inputs });
107
107
  const ids = (response.ids ?? []) as string[];
108
108
  return ids.map(
109
- (id, i) => new Job<T>({ id, queue: this.name, data: inputs[i].data }, this.connection)
109
+ (id, i) =>
110
+ new Job<T>(
111
+ { id, queue: this.name, name: inputs[i].name, data: inputs[i].data },
112
+ this.connection
113
+ )
110
114
  );
111
115
  }
112
116
 
@@ -134,6 +138,6 @@ export class Queue<T = unknown> {
134
138
  * The declaration merging is intentional and safe: Object.assign below
135
139
  * installs exactly the methods the interface declares. The unused type
136
140
  * parameter is required — merged interfaces must repeat the class generics. */
137
- // biome-ignore lint/correctness/noUnusedVariables: generic must match the class declaration
141
+ // oxlint-disable-next-line no-unused-vars -- generic must match the class declaration
138
142
  export interface Queue<T = unknown> extends QueueQueryApi, QueueControlApi, QueueAdminApi {}
139
143
  Object.assign(Queue.prototype, queryMethods, controlMethods, adminMethods);
@@ -0,0 +1,93 @@
1
+ /** Safe command serialization for the bunqueue wire protocol. */
2
+
3
+ import { pack } from 'msgpackr';
4
+ import type { Command } from './connection-types.js';
5
+ import { SerializationError } from './errors.js';
6
+ import { frame } from './frame.js';
7
+
8
+ const invalid = (reason: string): never => {
9
+ throw new SerializationError(`cannot serialize command as MessagePack: ${reason}`);
10
+ };
11
+
12
+ function normalizeWireValue(value: unknown, active: WeakSet<object>): unknown {
13
+ if (value === null || typeof value === 'string' || typeof value === 'boolean') return value;
14
+ if (typeof value === 'number') {
15
+ if (!Number.isFinite(value)) invalid('numbers must be finite');
16
+ return value;
17
+ }
18
+ if (typeof value === 'bigint') invalid('BigInt is not JavaScript-safe on the broker');
19
+ if (typeof value === 'undefined') invalid('nested undefined values are not portable');
20
+ if (typeof value === 'symbol' || typeof value === 'function') {
21
+ invalid(`${typeof value} values are unsupported`);
22
+ }
23
+ if (typeof value !== 'object') invalid('unsupported value');
24
+ const objectValue = value as object;
25
+
26
+ if (value instanceof Date) {
27
+ if (!Number.isFinite(value.getTime())) invalid('invalid Date');
28
+ return new Date(value.getTime());
29
+ }
30
+ if (value instanceof Uint8Array || value instanceof ArrayBuffer) return value;
31
+ if (active.has(objectValue)) invalid('cyclic structures are unsupported');
32
+ active.add(objectValue);
33
+ try {
34
+ if (Array.isArray(value)) {
35
+ return Array.from(value, (entry) => normalizeWireValue(entry, active));
36
+ }
37
+ if (value instanceof Map) {
38
+ const normalized = new Map<string, unknown>();
39
+ for (const [key, entry] of value) {
40
+ if (typeof key !== 'string') invalid('map keys must be strings');
41
+ normalized.set(key as string, normalizeWireValue(entry, active));
42
+ }
43
+ return normalized;
44
+ }
45
+ const prototype = Object.getPrototypeOf(objectValue);
46
+ if (prototype !== Object.prototype && prototype !== null) {
47
+ invalid('only plain objects, arrays, maps, dates, and binary values are supported');
48
+ }
49
+ const normalized = Object.create(null) as Record<string, unknown>;
50
+ for (const key of Reflect.ownKeys(objectValue)) {
51
+ if (typeof key !== 'string') invalid('symbol object keys are unsupported');
52
+ const stringKey = key as string;
53
+ const descriptor = Object.getOwnPropertyDescriptor(objectValue, stringKey);
54
+ if (!descriptor?.enumerable) continue;
55
+ if (!('value' in descriptor)) invalid('accessor properties are unsupported');
56
+ normalized[stringKey] = normalizeWireValue(descriptor.value, active);
57
+ }
58
+ return normalized;
59
+ } finally {
60
+ active.delete(objectValue);
61
+ }
62
+ }
63
+
64
+ function prepareCommand(command: Command, reqId: string): Record<string, unknown> {
65
+ const envelope = Object.create(null) as Record<string, unknown>;
66
+ for (const key of Reflect.ownKeys(command)) {
67
+ if (typeof key !== 'string') invalid('symbol command keys are unsupported');
68
+ const stringKey = key as string;
69
+ const descriptor = Object.getOwnPropertyDescriptor(command, stringKey);
70
+ if (!descriptor?.enumerable) continue;
71
+ if (!('value' in descriptor)) invalid('accessor command properties are unsupported');
72
+ if (descriptor.value === undefined) continue;
73
+ envelope[stringKey] = descriptor.value;
74
+ }
75
+ envelope.reqId = reqId;
76
+ return normalizeWireValue(envelope, new WeakSet()) as Record<string, unknown>;
77
+ }
78
+
79
+ /**
80
+ * Encode and frame a command before it occupies an in-flight request slot.
81
+ *
82
+ * MessagePack may reject values such as cyclic objects. Normalize every such
83
+ * encoder failure to the public SDK error hierarchy; `frame()` already uses
84
+ * the same typed error for an oversized encoded body.
85
+ */
86
+ export function serializeCommand(command: Command, reqId: string): Buffer {
87
+ try {
88
+ return frame(pack(prepareCommand(command, reqId)));
89
+ } catch (error) {
90
+ if (error instanceof SerializationError) throw error;
91
+ throw new SerializationError('cannot serialize command as MessagePack');
92
+ }
93
+ }
@@ -0,0 +1,58 @@
1
+ interface AckEntry {
2
+ readonly id: string;
3
+ }
4
+
5
+ function record(value: unknown): Record<string, unknown> | null {
6
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
7
+ ? (value as Record<string, unknown>)
8
+ : null;
9
+ }
10
+
11
+ function validatedIndices(value: unknown, size: number): number[] {
12
+ if (!Array.isArray(value)) throw new Error('Invalid ACKB ignoredIndices response');
13
+ const seen = new Set<number>();
14
+ for (const index of value) {
15
+ if (!Number.isInteger(index) || index < 0 || index >= size || seen.has(index)) {
16
+ throw new Error('Invalid ACKB ignoredIndices response');
17
+ }
18
+ seen.add(index);
19
+ }
20
+ return [...seen];
21
+ }
22
+
23
+ function validatedIds(value: unknown): string[] {
24
+ if (!Array.isArray(value) || value.some((id) => typeof id !== 'string')) {
25
+ throw new Error('Invalid ACKB ignoredIds response');
26
+ }
27
+ return value as string[];
28
+ }
29
+
30
+ /** Parse structured ACKB evidence while preserving duplicate job-ID positions. */
31
+ export function ignoredAckIndices(data: unknown, batch: readonly AckEntry[]): ReadonlySet<number> {
32
+ if (data === undefined) return new Set();
33
+ const payload = record(data);
34
+ if (!payload) throw new Error('Invalid ACKB response data');
35
+ const hasIndices = Object.hasOwn(payload, 'ignoredIndices');
36
+ const hasIds = Object.hasOwn(payload, 'ignoredIds');
37
+ if (!hasIndices) throw new Error('Invalid ACKB ignoredIndices response');
38
+
39
+ const ids = hasIds ? validatedIds(payload.ignoredIds) : null;
40
+ const indices = validatedIndices(payload.ignoredIndices, batch.length);
41
+ if (ids) {
42
+ if (ids.length !== indices.length) throw new Error('Mismatched ACKB ignored evidence');
43
+ for (let offset = 0; offset < indices.length; offset++) {
44
+ if (batch[indices[offset]]?.id !== ids[offset]) {
45
+ throw new Error('Mismatched ACKB ignored evidence');
46
+ }
47
+ }
48
+ }
49
+ return new Set(indices);
50
+ }
51
+
52
+ /** Parse a single ACK/FAIL response; historical applied responses have no data. */
53
+ export function terminalOutcomeWasApplied(data: unknown): boolean {
54
+ if (data === undefined) return true;
55
+ const payload = record(data);
56
+ if (payload?.applied === false && payload.reason === 'already-finalized') return false;
57
+ throw new Error('Invalid terminal outcome response data');
58
+ }
package/src/types.ts CHANGED
@@ -104,12 +104,9 @@ export function wireJobOptions(opts: JobOptions = {}): Record<string, unknown> {
104
104
  });
105
105
  }
106
106
 
107
- /** The job name travels inside `data`, mirroring the official client. */
108
- export function jobPayload(name: string, data: unknown): Record<string, unknown> {
109
- if (data && typeof data === 'object' && !Array.isArray(data)) {
110
- return { name, ...(data as Record<string, unknown>) };
111
- }
112
- return data === undefined || data === null ? { name } : { name, payload: data };
107
+ /** Build the protocol-owned name field without changing user data. */
108
+ export function jobPayload(name: string, data: unknown): { name: string; data: unknown } {
109
+ return { name, data };
113
110
  }
114
111
 
115
112
  export interface JobCounts {
@@ -7,6 +7,7 @@ import { randomBytes } from 'node:crypto';
7
7
  import { EventEmitter } from 'node:events';
8
8
  import { hostname } from 'node:os';
9
9
  import { Connection } from './connection.js';
10
+ import type { Response } from './connection-types.js';
10
11
  import {
11
12
  MAX_POLL_TIMEOUT_MS,
12
13
  sleep,
@@ -182,13 +183,15 @@ export class WorkerBase<T = unknown, R = unknown> extends EventEmitter {
182
183
  this.emit('closed');
183
184
  }
184
185
 
185
- /** Dispatch a command, routing failures to 'error'. Returns whether the
186
- * command reached the server — callers gate success-only side effects
187
- * ('completed'/'failed' emits, counters) on it. */
188
- protected async safeCall(command: Record<string, unknown> & { cmd: string }): Promise<boolean> {
186
+ /** Dispatch a command and route failures to 'error'. The optional outcome
187
+ * parser decides whether a successful response authorizes local effects. */
188
+ protected async safeCall(
189
+ command: Record<string, unknown> & { cmd: string },
190
+ outcome: (response: Response) => boolean = () => true
191
+ ): Promise<boolean> {
189
192
  try {
190
- await this.connection.call(command);
191
- return true;
193
+ const response = await this.connection.call(command);
194
+ return outcome(response);
192
195
  } catch (err) {
193
196
  this.emit('error', err instanceof Error ? err : new Error(String(err)));
194
197
  return false;
@@ -0,0 +1,23 @@
1
+ /** One-shot wake-up used by the pull loop while every worker slot is busy. */
2
+ export class SlotSignal {
3
+ private waiter: (() => void) | null = null;
4
+
5
+ wait(timeoutMs: number): Promise<void> {
6
+ return new Promise((resolve) => {
7
+ let settled = false;
8
+ const finish = () => {
9
+ if (settled) return;
10
+ settled = true;
11
+ clearTimeout(timer);
12
+ if (this.waiter === finish) this.waiter = null;
13
+ resolve();
14
+ };
15
+ const timer = setTimeout(finish, timeoutMs);
16
+ this.waiter = finish;
17
+ });
18
+ }
19
+
20
+ notify(): void {
21
+ this.waiter?.();
22
+ }
23
+ }
package/src/worker.ts CHANGED
@@ -12,7 +12,9 @@ import { CommandTimeoutError, ConnectionClosedError, UnrecoverableError } from '
12
12
  import { compact } from './frame.js';
13
13
  import { Job } from './job.js';
14
14
  import type { PulledJobsResponse } from './responses.js';
15
+ import { terminalOutcomeWasApplied } from './terminal-outcome.js';
15
16
  import { WorkerBase } from './worker-base.js';
17
+ import { SlotSignal } from './worker-slot-signal.js';
16
18
  import {
17
19
  MAX_STACK_LINES,
18
20
  type Processor,
@@ -24,6 +26,7 @@ import {
24
26
  export class Worker<T = unknown, R = unknown> extends WorkerBase<T, R> {
25
27
  private readonly processor: Processor<T, R>;
26
28
  private readonly ackBatcher: AckBatcher | null;
29
+ private readonly slotSignal = new SlotSignal();
27
30
 
28
31
  constructor(queue: string, processor: Processor<T, R>, opts: WorkerOptions = {}) {
29
32
  super(queue, opts);
@@ -83,7 +86,7 @@ export class Worker<T = unknown, R = unknown> extends WorkerBase<T, R> {
83
86
  private async pollOnce(): Promise<void> {
84
87
  const free = this.concurrency - this.active.size;
85
88
  if (free <= 0) {
86
- await sleep(20);
89
+ await this.slotSignal.wait(20);
87
90
  return;
88
91
  }
89
92
 
@@ -140,11 +143,11 @@ export class Worker<T = unknown, R = unknown> extends WorkerBase<T, R> {
140
143
  id: job.id,
141
144
  token,
142
145
  result: result ?? undefined,
143
- onSettled: (err) => {
146
+ onSettled: (err, applied) => {
144
147
  this.finishJob(job.id);
145
148
  if (err) {
146
149
  this.emit('error', err instanceof Error ? err : new Error(String(err)));
147
- } else {
150
+ } else if (applied) {
148
151
  this.processed += 1;
149
152
  this.emit('completed', job, result);
150
153
  }
@@ -153,7 +156,8 @@ export class Worker<T = unknown, R = unknown> extends WorkerBase<T, R> {
153
156
  return;
154
157
  }
155
158
  const acked = await this.safeCall(
156
- compact({ cmd: 'ACK', id: job.id, token, result: result ?? undefined }) as { cmd: string }
159
+ compact({ cmd: 'ACK', id: job.id, token, result: result ?? undefined }) as { cmd: string },
160
+ (response) => terminalOutcomeWasApplied(response.data)
157
161
  );
158
162
  // Free the slot BEFORE emitting: a throwing 'completed' listener must
159
163
  // not leak the active slot (same rationale as the batched path).
@@ -177,7 +181,8 @@ export class Worker<T = unknown, R = unknown> extends WorkerBase<T, R> {
177
181
  error: error.message || error.name,
178
182
  stack,
179
183
  unrecoverable: err instanceof UnrecoverableError ? true : undefined,
180
- }) as { cmd: string }
184
+ }) as { cmd: string },
185
+ (response) => terminalOutcomeWasApplied(response.data)
181
186
  );
182
187
  this.finishJob(job.id);
183
188
  // Same asymmetry guard as the ACK path: if the FAIL never reached the
@@ -192,6 +197,7 @@ export class Worker<T = unknown, R = unknown> extends WorkerBase<T, R> {
192
197
  private finishJob(id: string): void {
193
198
  this.active.delete(id);
194
199
  this.cancelledJobs.delete(id);
200
+ this.slotSignal.notify();
195
201
  }
196
202
 
197
203
  // --------------------------------------------------------------- heartbeat
@@ -1,39 +0,0 @@
1
- /**
2
- * Backpressure gate: bounds the number of in-flight commands on a connection.
3
- *
4
- * When the in-flight count reaches `max`, `acquire()` parks the caller until a
5
- * slot frees (a pending command settles). This turns unbounded memory growth
6
- * under a fast producer / slow server into cooperative flow control. `max <= 0`
7
- * disables the gate (unbounded, the default).
8
- */
9
- export class Backpressure {
10
- max;
11
- onWait;
12
- waiters = [];
13
- constructor(max, onWait) {
14
- this.max = max;
15
- this.onWait = onWait;
16
- }
17
- /** Resolve immediately if under the limit, else park until a slot frees. */
18
- acquire(inFlight) {
19
- if (this.max <= 0 || inFlight < this.max)
20
- return;
21
- this.onWait?.();
22
- return new Promise((resolve) => {
23
- this.waiters.push(resolve);
24
- });
25
- }
26
- /** Release one parked caller (call when a pending command settles). */
27
- release() {
28
- this.waiters.shift()?.();
29
- }
30
- /** Release every parked caller (call on teardown so none hang forever). */
31
- clear() {
32
- while (this.waiters.length > 0)
33
- this.waiters.shift()?.();
34
- }
35
- /** Number of callers currently parked. */
36
- get waiting() {
37
- return this.waiters.length;
38
- }
39
- }
@@ -1,53 +0,0 @@
1
- /**
2
- * Bunqueue Simple Mode — priority aging.
3
- * Port of src/client/bunqueue/aging.ts: automatically boosts the priority of
4
- * old waiting jobs. Same semantics; the job scan goes over TCP (GetJobs on
5
- * the waiting and prioritized states) instead of the embedded manager.
6
- */
7
- export class PriorityAger {
8
- timer = null;
9
- config;
10
- queue;
11
- constructor(config, queue) {
12
- this.config = config;
13
- this.queue = queue;
14
- }
15
- start() {
16
- const interval = this.config.interval ?? 60000;
17
- this.timer = setInterval(() => {
18
- void this.tick();
19
- }, interval);
20
- this.timer.unref?.();
21
- }
22
- async tick() {
23
- const minAge = this.config.minAge ?? 60000;
24
- const boost = this.config.boost ?? 1;
25
- const maxPriority = this.config.maxPriority ?? 100;
26
- const maxScan = this.config.maxScan ?? 100;
27
- // Both waiting and prioritized jobs (priority > 0 means "prioritized")
28
- const [waiting, prioritized] = await Promise.all([
29
- this.queue.getJobs({ state: 'waiting', start: 0, end: maxScan }),
30
- this.queue.getJobs({ state: 'prioritized', start: 0, end: maxScan }),
31
- ]);
32
- const jobs = [...waiting, ...prioritized];
33
- const now = Date.now();
34
- for (const job of jobs) {
35
- const age = now - job.timestamp;
36
- if (age >= minAge && job.priority < maxPriority) {
37
- const newPriority = Math.min(job.priority + boost, maxPriority);
38
- try {
39
- await this.queue.changeJobPriority(job.id, { priority: newPriority });
40
- }
41
- catch {
42
- // Best-effort — the job may have been processed meanwhile
43
- }
44
- }
45
- }
46
- }
47
- destroy() {
48
- if (this.timer) {
49
- clearInterval(this.timer);
50
- this.timer = null;
51
- }
52
- }
53
- }