bunqueue-client 0.1.9 → 0.2.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.
- package/CHANGELOG.md +165 -0
- package/LEGACY.md +460 -0
- package/README.md +204 -349
- package/dist/ack-batcher.js +7 -67
- package/dist/canonical-manifest.json +934 -0
- package/dist/chunk-b967v3w3.js +79 -0
- package/dist/chunk-fekm0ma6.js +110 -0
- package/dist/chunk-jxkszwqp.js +573 -0
- package/dist/embedded.js +16510 -0
- package/dist/frame.js +14 -57
- package/dist/index.d.ts +1 -27
- package/dist/index.js +10953 -16
- package/dist/legacy.d.ts +1 -0
- package/dist/legacy.js +2081 -0
- package/dist/{ack-batcher.d.ts → types/sdk/typescript/src/ack-batcher.d.ts} +3 -3
- package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/aging.d.ts +2 -2
- package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/batch.d.ts +2 -2
- package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/bunqueue-api.d.ts +5 -5
- package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/bunqueue.d.ts +13 -13
- package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/circuit-breaker.d.ts +2 -2
- package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/dedup-debounce.d.ts +2 -2
- package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/dlq-rate-limit.d.ts +2 -2
- package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/rate-gate.d.ts +1 -1
- package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/retry.d.ts +1 -1
- package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/triggers.d.ts +3 -3
- package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/ttl.d.ts +1 -1
- package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/types.d.ts +4 -4
- package/dist/types/sdk/typescript/src/canonical-transport/bun-sqlite-types.d.ts +21 -0
- package/dist/{connection-pool.d.ts → types/sdk/typescript/src/connection-pool.d.ts} +1 -1
- package/dist/{connection-types.d.ts → types/sdk/typescript/src/connection-types.d.ts} +1 -1
- package/dist/{connection.d.ts → types/sdk/typescript/src/connection.d.ts} +6 -19
- package/dist/{errors.d.ts → types/sdk/typescript/src/errors.d.ts} +3 -0
- package/dist/types/sdk/typescript/src/flow-commit.d.ts +5 -0
- package/dist/types/sdk/typescript/src/flow-plan-legacy.d.ts +13 -0
- package/dist/types/sdk/typescript/src/flow-plan.d.ts +29 -0
- package/dist/{flow-types.d.ts → types/sdk/typescript/src/flow-types.d.ts} +7 -4
- package/dist/{flow.d.ts → types/sdk/typescript/src/flow.d.ts} +6 -10
- package/dist/{frame.d.ts → types/sdk/typescript/src/frame.d.ts} +1 -1
- package/dist/types/sdk/typescript/src/index.d.ts +10 -0
- package/dist/{job.d.ts → types/sdk/typescript/src/job.d.ts} +4 -3
- package/dist/types/sdk/typescript/src/legacy.d.ts +27 -0
- package/dist/{observability.d.ts → types/sdk/typescript/src/observability.d.ts} +14 -0
- package/dist/{queue-admin.d.ts → types/sdk/typescript/src/queue-admin.d.ts} +3 -4
- package/dist/{queue-control.d.ts → types/sdk/typescript/src/queue-control.d.ts} +5 -5
- package/dist/{queue-query.d.ts → types/sdk/typescript/src/queue-query.d.ts} +3 -3
- package/dist/{queue.d.ts → types/sdk/typescript/src/queue.d.ts} +8 -8
- package/dist/{responses.d.ts → types/sdk/typescript/src/responses.d.ts} +2 -2
- package/dist/types/sdk/typescript/src/serialization.d.ts +10 -0
- package/dist/{socket-factory.d.ts → types/sdk/typescript/src/socket-factory.d.ts} +1 -1
- package/dist/types/sdk/typescript/src/terminal-outcome.d.ts +8 -0
- package/dist/{types.d.ts → types/sdk/typescript/src/types.d.ts} +5 -2
- package/dist/{worker-base.d.ts → types/sdk/typescript/src/worker-base.d.ts} +6 -6
- package/dist/types/sdk/typescript/src/worker-slot-signal.d.ts +6 -0
- package/dist/{worker-types.d.ts → types/sdk/typescript/src/worker-types.d.ts} +3 -3
- package/dist/{worker.d.ts → types/sdk/typescript/src/worker.d.ts} +3 -2
- package/dist/types/src/application/background/dlq.d.ts +2 -0
- package/dist/types/src/application/background/lifecycle.d.ts +4 -0
- package/dist/types/src/application/background/recovery/active.d.ts +5 -0
- package/dist/types/src/application/background/recovery/index.d.ts +2 -0
- package/dist/types/src/application/background/recovery/pending.d.ts +3 -0
- package/dist/types/src/application/background/recovery/restore.d.ts +5 -0
- package/dist/types/src/application/background/recovery/shared.d.ts +6 -0
- package/dist/types/src/application/background/timeouts.d.ts +25 -0
- package/dist/types/src/application/backgroundTasks.d.ts +7 -0
- package/dist/types/src/application/cleanupTasks.d.ts +10 -0
- package/dist/types/src/application/clientOwnership.d.ts +65 -0
- package/dist/types/src/application/clientTracking.d.ts +40 -0
- package/dist/types/src/application/completedCleanup.d.ts +34 -0
- package/dist/types/src/application/completedRetry.d.ts +21 -0
- package/dist/types/src/application/contextFactory.d.ts +49 -0
- package/dist/types/src/application/dependencyCompletions.d.ts +63 -0
- package/dist/types/src/application/dependencyProcessor.d.ts +15 -0
- package/dist/types/src/application/dependencyResultTracker.d.ts +18 -0
- package/dist/types/src/application/dlqManager.d.ts +49 -0
- package/dist/types/src/application/dlqRetry.d.ts +12 -0
- package/dist/types/src/application/emptyQueueCleanup.d.ts +3 -0
- package/dist/types/src/application/eventsManager.d.ts +50 -0
- package/dist/types/src/application/flowFailureRecovery.d.ts +20 -0
- package/dist/types/src/application/flowParentBackpatch.d.ts +27 -0
- package/dist/types/src/application/jobLogsManager.d.ts +21 -0
- package/dist/types/src/application/latencyTracker.d.ts +39 -0
- package/dist/types/src/application/lockManager.d.ts +15 -0
- package/dist/types/src/application/lockOperations.d.ts +38 -0
- package/dist/types/src/application/metricsExporter.d.ts +27 -0
- package/dist/types/src/application/monitoringChecks.d.ts +36 -0
- package/dist/types/src/application/operations/ack/batch.d.ts +8 -0
- package/dist/types/src/application/operations/ack/completion.d.ts +3 -0
- package/dist/types/src/application/operations/ack/failure.d.ts +3 -0
- package/dist/types/src/application/operations/ack.d.ts +5 -0
- package/dist/types/src/application/operations/ackHelpers.d.ts +36 -0
- package/dist/types/src/application/operations/customId.d.ts +51 -0
- package/dist/types/src/application/operations/flowPush.d.ts +9 -0
- package/dist/types/src/application/operations/flowTopologyValidation.d.ts +3 -0
- package/dist/types/src/application/operations/flowValidation.d.ts +3 -0
- package/dist/types/src/application/operations/jobClaim.d.ts +17 -0
- package/dist/types/src/application/operations/jobManagement.d.ts +45 -0
- package/dist/types/src/application/operations/jobMoveOperations.d.ts +9 -0
- package/dist/types/src/application/operations/jobPromotion.d.ts +7 -0
- package/dist/types/src/application/operations/jobStateTransitions.d.ts +15 -0
- package/dist/types/src/application/operations/parentLink.d.ts +36 -0
- package/dist/types/src/application/operations/parentLinkInput.d.ts +8 -0
- package/dist/types/src/application/operations/pull.d.ts +20 -0
- package/dist/types/src/application/operations/pullFinalization.d.ts +6 -0
- package/dist/types/src/application/operations/pullStateTransition.d.ts +51 -0
- package/dist/types/src/application/operations/push.d.ts +13 -0
- package/dist/types/src/application/operations/pushAdmission.d.ts +36 -0
- package/dist/types/src/application/operations/pushBatch.d.ts +4 -0
- package/dist/types/src/application/operations/pushContext.d.ts +48 -0
- package/dist/types/src/application/operations/pushDeduplication.d.ts +42 -0
- package/dist/types/src/application/operations/pushInsert.d.ts +39 -0
- package/dist/types/src/application/operations/pushLocks.d.ts +15 -0
- package/dist/types/src/application/operations/query/collect.d.ts +12 -0
- package/dist/types/src/application/operations/query/jobLookup.d.ts +9 -0
- package/dist/types/src/application/operations/query/pagination.d.ts +8 -0
- package/dist/types/src/application/operations/query/state.d.ts +4 -0
- package/dist/types/src/application/operations/queryOperations.d.ts +5 -0
- package/dist/types/src/application/operations/queueControl.d.ts +50 -0
- package/dist/types/src/application/orphanRecovery.d.ts +25 -0
- package/dist/types/src/application/prometheusOperationalMetrics.d.ts +31 -0
- package/dist/types/src/application/queue-manager/ack.d.ts +23 -0
- package/dist/types/src/application/queue-manager/configuration.d.ts +27 -0
- package/dist/types/src/application/queue-manager/context.d.ts +5 -0
- package/dist/types/src/application/queue-manager/control.d.ts +20 -0
- package/dist/types/src/application/queue-manager/delivery.d.ts +33 -0
- package/dist/types/src/application/queue-manager/dependencies.d.ts +8 -0
- package/dist/types/src/application/queue-manager/dependency-runtime.d.ts +8 -0
- package/dist/types/src/application/queue-manager/flow-failures.d.ts +18 -0
- package/dist/types/src/application/queue-manager/flow-options.d.ts +8 -0
- package/dist/types/src/application/queue-manager/job-management.d.ts +17 -0
- package/dist/types/src/application/queue-manager/lifecycle.d.ts +4 -0
- package/dist/types/src/application/queue-manager/limits.d.ts +58 -0
- package/dist/types/src/application/queue-manager/locks.d.ts +21 -0
- package/dist/types/src/application/queue-manager/observability.d.ts +16 -0
- package/dist/types/src/application/queue-manager/queries.d.ts +24 -0
- package/dist/types/src/application/queue-manager/repeat.d.ts +4 -0
- package/dist/types/src/application/queue-manager/services.d.ts +19 -0
- package/dist/types/src/application/queue-manager/state.d.ts +98 -0
- package/dist/types/src/application/queue-manager/stats.d.ts +28 -0
- package/dist/types/src/application/queueManager.d.ts +5 -0
- package/dist/types/src/application/queueStatsAggregator.d.ts +23 -0
- package/dist/types/src/application/queueTelemetryJournal.d.ts +24 -0
- package/dist/types/src/application/repeatJobs.d.ts +7 -0
- package/dist/types/src/application/stallDetection.d.ts +26 -0
- package/dist/types/src/application/statsManager.d.ts +59 -0
- package/dist/types/src/application/taskErrorTracking.d.ts +22 -0
- package/dist/types/src/application/throughputTracker.d.ts +34 -0
- package/dist/types/src/application/types/ack.d.ts +136 -0
- package/dist/types/src/application/types/background.d.ts +18 -0
- package/dist/types/src/application/types/config.d.ts +41 -0
- package/dist/types/src/application/types/contextFactory.d.ts +89 -0
- package/dist/types/src/application/types/contexts.d.ts +117 -0
- package/dist/types/src/application/types/index.d.ts +7 -0
- package/dist/types/src/application/types/query.d.ts +23 -0
- package/dist/types/src/application/types/queueManager.d.ts +100 -0
- package/dist/types/src/application/webhookManager.d.ts +47 -0
- package/dist/types/src/application/workerManager.d.ts +61 -0
- package/dist/types/src/client/bunqueue/aging.d.ts +16 -0
- package/dist/types/src/client/bunqueue/batch.d.ts +16 -0
- package/dist/types/src/client/bunqueue/cancellation.d.ts +21 -0
- package/dist/types/src/client/bunqueue/circuitBreaker.d.ts +21 -0
- package/dist/types/src/client/bunqueue/dedupDebounce.d.ts +12 -0
- package/dist/types/src/client/bunqueue/dlqRateLimit.d.ts +26 -0
- package/dist/types/src/client/bunqueue/retry.d.ts +8 -0
- package/dist/types/src/client/bunqueue/runtime.d.ts +35 -0
- package/dist/types/src/client/bunqueue/triggers.d.ts +17 -0
- package/dist/types/src/client/bunqueue/ttl.d.ts +17 -0
- package/dist/types/src/client/bunqueue/types.d.ts +147 -0
- package/dist/types/src/client/bunqueue.d.ts +73 -0
- package/dist/types/src/client/dlqConversion.d.ts +5 -0
- package/dist/types/src/client/errors.d.ts +24 -0
- package/dist/types/src/client/events.d.ts +85 -0
- package/dist/types/src/client/flow.d.ts +70 -0
- package/dist/types/src/client/flowAtomic.d.ts +9 -0
- package/dist/types/src/client/flowJobCoreMethods.d.ts +28 -0
- package/dist/types/src/client/flowJobDependencies.d.ts +7 -0
- package/dist/types/src/client/flowJobFactory.d.ts +24 -0
- package/dist/types/src/client/flowJobMoveMethods.d.ts +16 -0
- package/dist/types/src/client/flowJobTypes.d.ts +29 -0
- package/dist/types/src/client/flowLegacyPlan.d.ts +16 -0
- package/dist/types/src/client/flowOptions.d.ts +10 -0
- package/dist/types/src/client/flowPlan.d.ts +16 -0
- package/dist/types/src/client/flowPush.d.ts +27 -0
- package/dist/types/src/client/flowReader.d.ts +10 -0
- package/dist/types/src/client/flowResults.d.ts +11 -0
- package/dist/types/src/client/flowTypes.d.ts +77 -0
- package/dist/types/src/client/forwarder.d.ts +75 -0
- package/dist/types/src/client/groupId.d.ts +1 -0
- package/dist/types/src/client/index.d.ts +46 -0
- package/dist/types/src/client/jobConversion.d.ts +10 -0
- package/dist/types/src/client/jobConversionHelpers.d.ts +28 -0
- package/dist/types/src/client/jobConversionTypes.d.ts +88 -0
- package/dist/types/src/client/jobDeduplication.d.ts +6 -0
- package/dist/types/src/client/jobHelpers.d.ts +31 -0
- package/dist/types/src/client/legacyConnectionOptions.d.ts +8 -0
- package/dist/types/src/client/manager.d.ts +15 -0
- package/dist/types/src/client/pro.d.ts +9 -0
- package/dist/types/src/client/queue/addBatcher.d.ts +59 -0
- package/dist/types/src/client/queue/bullmqCompat.d.ts +57 -0
- package/dist/types/src/client/queue/deduplication.d.ts +14 -0
- package/dist/types/src/client/queue/dlq.d.ts +61 -0
- package/dist/types/src/client/queue/dlqJobMethods.d.ts +9 -0
- package/dist/types/src/client/queue/dlqOps.d.ts +26 -0
- package/dist/types/src/client/queue/dlqStats.d.ts +3 -0
- package/dist/types/src/client/queue/failWire.d.ts +17 -0
- package/dist/types/src/client/queue/helpers.d.ts +19 -0
- package/dist/types/src/client/queue/job-proxy/dependencies.d.ts +9 -0
- package/dist/types/src/client/queue/job-proxy/reflection.d.ts +2 -0
- package/dist/types/src/client/queue/job-proxy/simple.d.ts +3 -0
- package/dist/types/src/client/queue/job-proxy/tcp.d.ts +4 -0
- package/dist/types/src/client/queue/jobMetadata.d.ts +10 -0
- package/dist/types/src/client/queue/jobMove.d.ts +32 -0
- package/dist/types/src/client/queue/jobProxy.d.ts +4 -0
- package/dist/types/src/client/queue/operations/add/bulk.d.ts +7 -0
- package/dist/types/src/client/queue/operations/add/payload.d.ts +25 -0
- package/dist/types/src/client/queue/operations/add/single.d.ts +3 -0
- package/dist/types/src/client/queue/operations/add.d.ts +2 -0
- package/dist/types/src/client/queue/operations/control.d.ts +42 -0
- package/dist/types/src/client/queue/operations/counts.d.ts +48 -0
- package/dist/types/src/client/queue/operations/groups.d.ts +24 -0
- package/dist/types/src/client/queue/operations/management.d.ts +51 -0
- package/dist/types/src/client/queue/operations/query.d.ts +50 -0
- package/dist/types/src/client/queue/operations/queryStates.d.ts +13 -0
- package/dist/types/src/client/queue/operations/queryTcpPages.d.ts +14 -0
- package/dist/types/src/client/queue/queue.d.ts +12 -0
- package/dist/types/src/client/queue/rateLimit.d.ts +46 -0
- package/dist/types/src/client/queue/runtime/compatibility.d.ts +13 -0
- package/dist/types/src/client/queue/runtime/configuration.d.ts +46 -0
- package/dist/types/src/client/queue/runtime/connection.d.ts +6 -0
- package/dist/types/src/client/queue/runtime/control.d.ts +41 -0
- package/dist/types/src/client/queue/runtime/queries.d.ts +66 -0
- package/dist/types/src/client/queue/runtime/scheduling.d.ts +33 -0
- package/dist/types/src/client/queue/runtime/state.d.ts +101 -0
- package/dist/types/src/client/queue/scheduler.d.ts +58 -0
- package/dist/types/src/client/queue/schedulerPagination.d.ts +7 -0
- package/dist/types/src/client/queue/stall.d.ts +20 -0
- package/dist/types/src/client/queue/types/add.d.ts +40 -0
- package/dist/types/src/client/queue/types/contexts.d.ts +33 -0
- package/dist/types/src/client/queue/types/index.d.ts +3 -0
- package/dist/types/src/client/queue/types/job.d.ts +50 -0
- package/dist/types/src/client/queue/types/runtime.d.ts +35 -0
- package/dist/types/src/client/queue/workers.d.ts +36 -0
- package/dist/types/src/client/queue-events/tcpSubscription.d.ts +23 -0
- package/dist/types/src/client/queue.d.ts +5 -0
- package/dist/types/src/client/queueGroup.d.ts +51 -0
- package/dist/types/src/client/resolveToken.d.ts +10 -0
- package/dist/types/src/client/sandboxed/index.d.ts +7 -0
- package/dist/types/src/client/sandboxed/queueOps.d.ts +24 -0
- package/dist/types/src/client/sandboxed/runtime/dispatch.d.ts +13 -0
- package/dist/types/src/client/sandboxed/runtime/lifecycle.d.ts +20 -0
- package/dist/types/src/client/sandboxed/runtime/log.d.ts +1 -0
- package/dist/types/src/client/sandboxed/runtime/pool.d.ts +11 -0
- package/dist/types/src/client/sandboxed/runtime/recovery.d.ts +11 -0
- package/dist/types/src/client/sandboxed/runtime/state.d.ts +39 -0
- package/dist/types/src/client/sandboxed/types/index.d.ts +2 -0
- package/dist/types/src/client/sandboxed/types/options.d.ts +27 -0
- package/dist/types/src/client/sandboxed/types/process.d.ts +39 -0
- package/dist/types/src/client/sandboxed/worker.d.ts +4 -0
- package/dist/types/src/client/sandboxed/wrapper.d.ts +12 -0
- package/dist/types/src/client/sandboxedWorker.d.ts +6 -0
- package/dist/types/src/client/tcp/client.d.ts +6 -0
- package/dist/types/src/client/tcp/commandQueue.d.ts +23 -0
- package/dist/types/src/client/tcp/connection.d.ts +4 -0
- package/dist/types/src/client/tcp/errors.d.ts +6 -0
- package/dist/types/src/client/tcp/health.d.ts +60 -0
- package/dist/types/src/client/tcp/index.d.ts +11 -0
- package/dist/types/src/client/tcp/reconnect.d.ts +47 -0
- package/dist/types/src/client/tcp/runtime/commands.d.ts +9 -0
- package/dist/types/src/client/tcp/runtime/connectivity.d.ts +13 -0
- package/dist/types/src/client/tcp/runtime/health.d.ts +14 -0
- package/dist/types/src/client/tcp/runtime/lifecycle.d.ts +8 -0
- package/dist/types/src/client/tcp/runtime/state.d.ts +50 -0
- package/dist/types/src/client/tcp/shared.d.ts +12 -0
- package/dist/types/src/client/tcp/transport.d.ts +18 -0
- package/dist/types/src/client/tcp/types/command.d.ts +9 -0
- package/dist/types/src/client/tcp/types/connection.d.ts +31 -0
- package/dist/types/src/client/tcp/types/index.d.ts +5 -0
- package/dist/types/src/client/tcp/types/socket.d.ts +8 -0
- package/dist/types/src/client/tcp/types/tls.d.ts +4 -0
- package/dist/types/src/client/tcp/types.d.ts +2 -0
- package/dist/types/src/client/tcpClient.d.ts +6 -0
- package/dist/types/src/client/tcpPool.d.ts +69 -0
- package/dist/types/src/client/types/connection.d.ts +30 -0
- package/dist/types/src/client/types/dlq.d.ts +45 -0
- package/dist/types/src/client/types/events.d.ts +54 -0
- package/dist/types/src/client/types/flow.d.ts +22 -0
- package/dist/types/src/client/types/index.d.ts +10 -0
- package/dist/types/src/client/types/job.d.ts +131 -0
- package/dist/types/src/client/types/metrics.d.ts +1 -0
- package/dist/types/src/client/types/options.d.ts +72 -0
- package/dist/types/src/client/types/worker.d.ts +54 -0
- package/dist/types/src/client/types.d.ts +2 -0
- package/dist/types/src/client/worker/ackBatcher.d.ts +55 -0
- package/dist/types/src/client/worker/ackFrontier.d.ts +21 -0
- package/dist/types/src/client/worker/ackOutcome.d.ts +8 -0
- package/dist/types/src/client/worker/batchExecution.d.ts +14 -0
- package/dist/types/src/client/worker/constants.d.ts +7 -0
- package/dist/types/src/client/worker/groupConcurrency.d.ts +49 -0
- package/dist/types/src/client/worker/handlers/completion.d.ts +29 -0
- package/dist/types/src/client/worker/handlers/dependencies.d.ts +11 -0
- package/dist/types/src/client/worker/handlers/mutations.d.ts +23 -0
- package/dist/types/src/client/worker/handlers/queries.d.ts +15 -0
- package/dist/types/src/client/worker/jobParser.d.ts +9 -0
- package/dist/types/src/client/worker/processor.d.ts +11 -0
- package/dist/types/src/client/worker/processorHandlers.d.ts +4 -0
- package/dist/types/src/client/worker/processorOutcome.d.ts +14 -0
- package/dist/types/src/client/worker/processorResult.d.ts +2 -0
- package/dist/types/src/client/worker/runtime/buffer.d.ts +8 -0
- package/dist/types/src/client/worker/runtime/control.d.ts +28 -0
- package/dist/types/src/client/worker/runtime/execution.d.ts +16 -0
- package/dist/types/src/client/worker/runtime/lifecycle.d.ts +7 -0
- package/dist/types/src/client/worker/runtime/manual.d.ts +10 -0
- package/dist/types/src/client/worker/runtime/options.d.ts +5 -0
- package/dist/types/src/client/worker/runtime/polling.d.ts +14 -0
- package/dist/types/src/client/worker/runtime/state.d.ts +121 -0
- package/dist/types/src/client/worker/types/index.d.ts +5 -0
- package/dist/types/src/client/worker/types/manual.d.ts +7 -0
- package/dist/types/src/client/worker/types/options.d.ts +26 -0
- package/dist/types/src/client/worker/types/outcome.d.ts +23 -0
- package/dist/types/src/client/worker/types/processor.d.ts +25 -0
- package/dist/types/src/client/worker/types/transport.d.ts +11 -0
- package/dist/types/src/client/worker/worker.d.ts +6 -0
- package/dist/types/src/client/worker/workerHeartbeat.d.ts +15 -0
- package/dist/types/src/client/worker/workerPull.d.ts +24 -0
- package/dist/types/src/client/worker/workerRateLimiter.d.ts +51 -0
- package/dist/types/src/client/worker.d.ts +6 -0
- package/dist/types/src/client/workflow/admission.d.ts +45 -0
- package/dist/types/src/client/workflow/clock.d.ts +60 -0
- package/dist/types/src/client/workflow/compensationChild.d.ts +33 -0
- package/dist/types/src/client/workflow/compensationClaim.d.ts +11 -0
- package/dist/types/src/client/workflow/compensationPass.d.ts +17 -0
- package/dist/types/src/client/workflow/compensationSupport.d.ts +24 -0
- package/dist/types/src/client/workflow/compensator.d.ts +34 -0
- package/dist/types/src/client/workflow/definitionGuard.d.ts +11 -0
- package/dist/types/src/client/workflow/emitter.d.ts +17 -0
- package/dist/types/src/client/workflow/engine.d.ts +66 -0
- package/dist/types/src/client/workflow/eventTypes.d.ts +44 -0
- package/dist/types/src/client/workflow/executionFence.d.ts +15 -0
- package/dist/types/src/client/workflow/executionTypes.d.ts +133 -0
- package/dist/types/src/client/workflow/executor.d.ts +52 -0
- package/dist/types/src/client/workflow/executorLifecycle.d.ts +19 -0
- package/dist/types/src/client/workflow/executorNodes.d.ts +18 -0
- package/dist/types/src/client/workflow/executorQueue.d.ts +9 -0
- package/dist/types/src/client/workflow/forEachRunner.d.ts +4 -0
- package/dist/types/src/client/workflow/identity.d.ts +48 -0
- package/dist/types/src/client/workflow/index.d.ts +23 -0
- package/dist/types/src/client/workflow/loops.d.ts +11 -0
- package/dist/types/src/client/workflow/mapRunner.d.ts +4 -0
- package/dist/types/src/client/workflow/recovery.d.ts +32 -0
- package/dist/types/src/client/workflow/rollbackControl.d.ts +37 -0
- package/dist/types/src/client/workflow/runner.d.ts +23 -0
- package/dist/types/src/client/workflow/runnerTiming.d.ts +14 -0
- package/dist/types/src/client/workflow/stepTypes.d.ts +171 -0
- package/dist/types/src/client/workflow/store.d.ts +83 -0
- package/dist/types/src/client/workflow/storeCodec.d.ts +7 -0
- package/dist/types/src/client/workflow/storeExecutionCodec.d.ts +11 -0
- package/dist/types/src/client/workflow/storeListing.d.ts +11 -0
- package/dist/types/src/client/workflow/storeMaintenance.d.ts +4 -0
- package/dist/types/src/client/workflow/storeSignals.d.ts +70 -0
- package/dist/types/src/client/workflow/subWorkflowRunner.d.ts +14 -0
- package/dist/types/src/client/workflow/types.d.ts +4 -0
- package/dist/types/src/client/workflow/unwindPlan.d.ts +87 -0
- package/dist/types/src/client/workflow/waitFor.d.ts +56 -0
- package/dist/types/src/client/workflow/workflow.d.ts +70 -0
- package/dist/types/src/client/workflow/workflowDecisions.d.ts +11 -0
- package/dist/types/src/client/workflow/workflowDefinition.d.ts +16 -0
- package/dist/types/src/client/workflow/workflowIntrospection.d.ts +5 -0
- package/dist/types/src/client/workflow/workflowValidation.d.ts +44 -0
- package/dist/types/src/config/index.d.ts +9 -0
- package/dist/types/src/config/loader.d.ts +7 -0
- package/dist/types/src/config/resolve.d.ts +59 -0
- package/dist/types/src/config/types.d.ts +88 -0
- package/dist/types/src/domain/job/constants.d.ts +14 -0
- package/dist/types/src/domain/job/create.d.ts +9 -0
- package/dist/types/src/domain/job/groupFifoOrder.d.ts +9 -0
- package/dist/types/src/domain/job/ids.d.ts +7 -0
- package/dist/types/src/domain/job/locks.d.ts +16 -0
- package/dist/types/src/domain/job/payload.d.ts +18 -0
- package/dist/types/src/domain/job/state.d.ts +23 -0
- package/dist/types/src/domain/job/terminal.d.ts +3 -0
- package/dist/types/src/domain/queue/dependencyTracker.d.ts +78 -0
- package/dist/types/src/domain/queue/dlqShard.d.ts +66 -0
- package/dist/types/src/domain/queue/groupLimiterManager.d.ts +30 -0
- package/dist/types/src/domain/queue/groupScheduler.d.ts +31 -0
- package/dist/types/src/domain/queue/groupSchedulerOrder.d.ts +6 -0
- package/dist/types/src/domain/queue/limiterManager.d.ts +68 -0
- package/dist/types/src/domain/queue/priorityQueue.d.ts +54 -0
- package/dist/types/src/domain/queue/priorityQueueOrder.d.ts +3 -0
- package/dist/types/src/domain/queue/shard/dependencies.d.ts +11 -0
- package/dist/types/src/domain/queue/shard/dlq.d.ts +26 -0
- package/dist/types/src/domain/queue/shard/keys.d.ts +19 -0
- package/dist/types/src/domain/queue/shard/lifecycle.d.ts +10 -0
- package/dist/types/src/domain/queue/shard/limits.d.ts +47 -0
- package/dist/types/src/domain/queue/shard/metrics.d.ts +32 -0
- package/dist/types/src/domain/queue/shard/state.d.ts +40 -0
- package/dist/types/src/domain/queue/shard.d.ts +7 -0
- package/dist/types/src/domain/queue/shardCounters.d.ts +35 -0
- package/dist/types/src/domain/queue/temporalIndex.d.ts +24 -0
- package/dist/types/src/domain/queue/temporalManager.d.ts +72 -0
- package/dist/types/src/domain/queue/uniqueKeyManager.d.ts +33 -0
- package/dist/types/src/domain/queue/waiterManager.d.ts +18 -0
- package/dist/types/src/domain/response/builders.d.ts +15 -0
- package/dist/types/src/domain/types/command.d.ts +2 -0
- package/dist/types/src/domain/types/commands/base.d.ts +5 -0
- package/dist/types/src/domain/types/commands/core.d.ts +107 -0
- package/dist/types/src/domain/types/commands/cron.d.ts +36 -0
- package/dist/types/src/domain/types/commands/dashboard.d.ts +13 -0
- package/dist/types/src/domain/types/commands/dlq.d.ts +44 -0
- package/dist/types/src/domain/types/commands/extended.d.ts +63 -0
- package/dist/types/src/domain/types/commands/index.d.ts +12 -0
- package/dist/types/src/domain/types/commands/limits.d.ts +108 -0
- package/dist/types/src/domain/types/commands/management.d.ts +73 -0
- package/dist/types/src/domain/types/commands/monitoring.d.ts +49 -0
- package/dist/types/src/domain/types/commands/protocol.d.ts +20 -0
- package/dist/types/src/domain/types/commands/query.d.ts +46 -0
- package/dist/types/src/domain/types/commands/union.d.ts +13 -0
- package/dist/types/src/domain/types/commands/workers.d.ts +39 -0
- package/dist/types/src/domain/types/cron.d.ts +89 -0
- package/dist/types/src/domain/types/deduplication.d.ts +43 -0
- package/dist/types/src/domain/types/dlq.d.ts +136 -0
- package/dist/types/src/domain/types/flow.d.ts +25 -0
- package/dist/types/src/domain/types/group.d.ts +26 -0
- package/dist/types/src/domain/types/job.d.ts +8 -0
- package/dist/types/src/domain/types/jobs/model.d.ts +150 -0
- package/dist/types/src/domain/types/metrics.d.ts +16 -0
- package/dist/types/src/domain/types/priorityQueue.d.ts +13 -0
- package/dist/types/src/domain/types/protocol.d.ts +5 -0
- package/dist/types/src/domain/types/queue.d.ts +110 -0
- package/dist/types/src/domain/types/response.d.ts +3 -0
- package/dist/types/src/domain/types/responses/model.d.ts +152 -0
- package/dist/types/src/domain/types/shard.d.ts +4 -0
- package/dist/types/src/domain/types/stall.d.ts +48 -0
- package/dist/types/src/domain/types/webhook.d.ts +42 -0
- package/dist/types/src/domain/types/worker.d.ts +40 -0
- package/dist/types/src/infrastructure/backup/backupTelemetry.d.ts +30 -0
- package/dist/types/src/infrastructure/backup/s3BackupConfig.d.ts +80 -0
- package/dist/types/src/infrastructure/cloud/types/config.d.ts +18 -0
- package/dist/types/src/infrastructure/cloud/types/event.d.ts +14 -0
- package/dist/types/src/infrastructure/cloud/types/snapshot.d.ts +52 -0
- package/dist/types/src/infrastructure/cloud/types/snapshotCore.d.ts +125 -0
- package/dist/types/src/infrastructure/cloud/types/snapshotJobs.d.ts +124 -0
- package/dist/types/src/infrastructure/cloud/types/snapshotTelemetry.d.ts +100 -0
- package/dist/types/src/infrastructure/cloud/types.d.ts +3 -0
- package/dist/types/src/infrastructure/persistence/batchInsert.d.ts +13 -0
- package/dist/types/src/infrastructure/persistence/completedJobCountSchema.d.ts +6 -0
- package/dist/types/src/infrastructure/persistence/dependencyCompletionSchema.d.ts +6 -0
- package/dist/types/src/infrastructure/persistence/dependencyCompletionStore.d.ts +40 -0
- package/dist/types/src/infrastructure/persistence/index.d.ts +5 -0
- package/dist/types/src/infrastructure/persistence/jobOptionsBlob.d.ts +19 -0
- package/dist/types/src/infrastructure/persistence/legacyNameMigration.d.ts +17 -0
- package/dist/types/src/infrastructure/persistence/migrationProgressSchema.d.ts +2 -0
- package/dist/types/src/infrastructure/persistence/migrations.d.ts +3 -0
- package/dist/types/src/infrastructure/persistence/schema.d.ts +8 -0
- package/dist/types/src/infrastructure/persistence/sqlite/admission.d.ts +9 -0
- package/dist/types/src/infrastructure/persistence/sqlite/completed.d.ts +17 -0
- package/dist/types/src/infrastructure/persistence/sqlite/control.d.ts +48 -0
- package/dist/types/src/infrastructure/persistence/sqlite/flows.d.ts +26 -0
- package/dist/types/src/infrastructure/persistence/sqlite/jobLifecycle.d.ts +17 -0
- package/dist/types/src/infrastructure/persistence/sqlite/jobs.d.ts +15 -0
- package/dist/types/src/infrastructure/persistence/sqlite/lifecycle.d.ts +6 -0
- package/dist/types/src/infrastructure/persistence/sqlite/mutations.d.ts +27 -0
- package/dist/types/src/infrastructure/persistence/sqlite/queries.d.ts +23 -0
- package/dist/types/src/infrastructure/persistence/sqlite/queueDeletionSql.d.ts +3 -0
- package/dist/types/src/infrastructure/persistence/sqlite/records.d.ts +24 -0
- package/dist/types/src/infrastructure/persistence/sqlite/state.d.ts +42 -0
- package/dist/types/src/infrastructure/persistence/sqlite/telemetry.d.ts +17 -0
- package/dist/types/src/infrastructure/persistence/sqlite/telemetryStore.d.ts +30 -0
- package/dist/types/src/infrastructure/persistence/sqlite/telemetryWrites.d.ts +47 -0
- package/dist/types/src/infrastructure/persistence/sqlite.d.ts +6 -0
- package/dist/types/src/infrastructure/persistence/sqliteBatch.d.ts +4 -0
- package/dist/types/src/infrastructure/persistence/sqliteMigration.d.ts +5 -0
- package/dist/types/src/infrastructure/persistence/sqliteSerializer.d.ts +50 -0
- package/dist/types/src/infrastructure/persistence/statements.d.ts +86 -0
- package/dist/types/src/infrastructure/persistence/types/admission.d.ts +8 -0
- package/dist/types/src/infrastructure/persistence/types/batch.d.ts +12 -0
- package/dist/types/src/infrastructure/persistence/types/sqlite.d.ts +27 -0
- package/dist/types/src/infrastructure/persistence/writeBuffer.d.ts +48 -0
- package/dist/types/src/infrastructure/persistence/writeBufferPending.d.ts +11 -0
- package/dist/types/src/infrastructure/scheduler/cron/execution.d.ts +12 -0
- package/dist/types/src/infrastructure/scheduler/cron/persisted.d.ts +5 -0
- package/dist/types/src/infrastructure/scheduler/cron/runtime.d.ts +31 -0
- package/dist/types/src/infrastructure/scheduler/cron/validation.d.ts +3 -0
- package/dist/types/src/infrastructure/scheduler/cronParser.d.ts +45 -0
- package/dist/types/src/infrastructure/scheduler/cronScheduler.d.ts +5 -0
- package/dist/types/src/infrastructure/scheduler/types/cronScheduler.d.ts +16 -0
- package/dist/types/src/infrastructure/server/protocol/commands.d.ts +8 -0
- package/dist/types/src/infrastructure/server/protocol/frameParser.d.ts +16 -0
- package/dist/types/src/infrastructure/server/protocol/lineBuffer.d.ts +6 -0
- package/dist/types/src/infrastructure/server/protocol/validation.d.ts +10 -0
- package/dist/types/src/infrastructure/server/protocol.d.ts +6 -0
- package/dist/types/src/infrastructure/server/socketWriteQueue.d.ts +66 -0
- package/dist/types/src/infrastructure/server/types/protocol.d.ts +4 -0
- package/dist/types/src/require-bun.d.ts +13 -0
- package/dist/types/src/shared/asyncLock.d.ts +13 -0
- package/dist/types/src/shared/boundedMap.d.ts +30 -0
- package/dist/types/src/shared/boundedSet.d.ts +26 -0
- package/dist/types/src/shared/hash.d.ts +30 -0
- package/dist/types/src/shared/histogram.d.ts +23 -0
- package/dist/types/src/shared/lock.d.ts +13 -0
- package/dist/types/src/shared/lockError.d.ts +3 -0
- package/dist/types/src/shared/lockTimeout.d.ts +2 -0
- package/dist/types/src/shared/logger.d.ts +48 -0
- package/dist/types/src/shared/lru.d.ts +9 -0
- package/dist/types/src/shared/lruMap.d.ts +42 -0
- package/dist/types/src/shared/lruSet.d.ts +36 -0
- package/dist/types/src/shared/minHeap.d.ts +43 -0
- package/dist/types/src/shared/msgpack.d.ts +3 -0
- package/dist/types/src/shared/pausedView.d.ts +19 -0
- package/dist/types/src/shared/rwLock.d.ts +22 -0
- package/dist/types/src/shared/serialization.d.ts +24 -0
- package/dist/types/src/shared/skipList.d.ts +97 -0
- package/dist/types/src/shared/skipListNodes.d.ts +6 -0
- package/dist/types/src/shared/storageHealth.d.ts +9 -0
- package/dist/types/src/shared/ttlMap.d.ts +81 -0
- package/dist/types/src/shared/types/lock.d.ts +7 -0
- package/dist/types/src/shared/types/skipList.d.ts +4 -0
- package/dist/types/src/shared/version.d.ts +4 -0
- package/dist/types/src/shared/webhookValidation.d.ts +6 -0
- package/package.json +27 -9
- package/src/ack-batcher.ts +8 -5
- package/src/bunqueue/bunqueue-api.ts +1 -1
- package/src/bunqueue/bunqueue.ts +2 -1
- package/src/canonical-transport/bun-sqlite-types.ts +22 -0
- package/src/canonical-transport/dlq.ts +12 -0
- package/src/canonical-transport/embedded.ts +55 -0
- package/src/canonical-transport/runtime.ts +49 -0
- package/src/canonical-transport/thread-worker.ts +83 -0
- package/src/canonical-transport/transport.ts +153 -0
- package/src/connection.ts +25 -30
- package/src/errors.ts +3 -0
- package/src/flow-commit.ts +45 -0
- package/src/flow-plan-legacy.ts +117 -0
- package/src/flow-plan.ts +209 -0
- package/src/flow-types.ts +4 -0
- package/src/flow.ts +31 -163
- package/src/frame.ts +5 -2
- package/src/index.ts +7 -75
- package/src/job.ts +43 -9
- package/src/legacy.ts +91 -0
- package/src/observability.ts +59 -1
- package/src/queue-admin.ts +5 -5
- package/src/queue-control.ts +8 -6
- package/src/queue.ts +10 -6
- package/src/serialization.ts +93 -0
- package/src/terminal-outcome.ts +58 -0
- package/src/types.ts +3 -6
- package/src/worker-base.ts +9 -6
- package/src/worker-slot-signal.ts +23 -0
- package/src/worker.ts +11 -5
- package/dist/backpressure.js +0 -39
- package/dist/bunqueue/aging.js +0 -53
- package/dist/bunqueue/batch.js +0 -60
- package/dist/bunqueue/bunqueue-api.js +0 -116
- package/dist/bunqueue/bunqueue.js +0 -194
- package/dist/bunqueue/cancellation.js +0 -48
- package/dist/bunqueue/circuit-breaker.js +0 -69
- package/dist/bunqueue/dedup-debounce.js +0 -37
- package/dist/bunqueue/dlq-rate-limit.js +0 -65
- package/dist/bunqueue/rate-gate.js +0 -61
- package/dist/bunqueue/retry.js +0 -56
- package/dist/bunqueue/triggers.js +0 -42
- package/dist/bunqueue/ttl.js +0 -31
- package/dist/bunqueue/types.js +0 -6
- package/dist/connection-pool.js +0 -60
- package/dist/connection-types.js +0 -2
- package/dist/connection.js +0 -281
- package/dist/errors.js +0 -25
- package/dist/flow-types.js +0 -2
- package/dist/flow.js +0 -212
- package/dist/job.js +0 -155
- package/dist/observability.js +0 -110
- package/dist/queue-admin.js +0 -158
- package/dist/queue-control.js +0 -107
- package/dist/queue-query.js +0 -187
- package/dist/queue.js +0 -92
- package/dist/responses.js +0 -10
- package/dist/socket-factory.js +0 -47
- package/dist/types.js +0 -50
- package/dist/worker-base.js +0 -159
- package/dist/worker-types.js +0 -5
- package/dist/worker.js +0 -211
- /package/dist/{backpressure.d.ts → types/sdk/typescript/src/backpressure.d.ts} +0 -0
- /package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/cancellation.d.ts +0 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { embeddedDlq } from './embedded.js';
|
|
2
|
+
|
|
3
|
+
type Operations = ReturnType<typeof embeddedDlq>;
|
|
4
|
+
|
|
5
|
+
export const getDlqConfig: Operations['getDlqConfig'] = (...args) =>
|
|
6
|
+
embeddedDlq().getDlqConfig(...args);
|
|
7
|
+
export const getDlqEntries: Operations['getDlqEntries'] = (...args) =>
|
|
8
|
+
embeddedDlq().getDlqEntries(...args);
|
|
9
|
+
export const getDlqStats: Operations['getDlqStats'] = (...args) =>
|
|
10
|
+
embeddedDlq().getDlqStats(...args);
|
|
11
|
+
export const retryDlqByFilter: Operations['retryDlqByFilter'] = (...args) =>
|
|
12
|
+
embeddedDlq().retryDlqByFilter(...args);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** Load the same embedded engine under Bun without loading bun:sqlite under Node. */
|
|
2
|
+
import type * as Backend from '../../../../scripts/client-portable/embedded-entry.js';
|
|
3
|
+
|
|
4
|
+
type EmbeddedBackend = typeof Backend;
|
|
5
|
+
|
|
6
|
+
// A non-literal specifier keeps bundlers from inlining the Bun-only engine.
|
|
7
|
+
const backendPath = './embedded.js';
|
|
8
|
+
const REQUIRES_BUN = 'Embedded mode requires Bun; use a TCP connection in this runtime.';
|
|
9
|
+
const REBUNDLED =
|
|
10
|
+
'Embedded mode could not load the bunqueue-client engine: this copy was re-bundled ' +
|
|
11
|
+
'without its ESM files. Import the published package, or use a TCP connection.';
|
|
12
|
+
let backend: EmbeddedBackend | undefined;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Bun's require() loads the ESM engine synchronously on first embedded use.
|
|
16
|
+
* The package therefore has no top-level await (CommonJS bundlers reject it),
|
|
17
|
+
* and Node, Deno and Workers never evaluate the engine or bun:sqlite.
|
|
18
|
+
*/
|
|
19
|
+
function loadBackend(): EmbeddedBackend {
|
|
20
|
+
if (backend) return backend;
|
|
21
|
+
const runtime = globalThis.process;
|
|
22
|
+
if (!runtime?.versions?.bun) throw new Error(REQUIRES_BUN);
|
|
23
|
+
// The published ESM file knows its own URL. CommonJS re-bundlers replace it
|
|
24
|
+
// with nothing or with a build-time location that lacks the engine file.
|
|
25
|
+
const location: unknown = import.meta.url;
|
|
26
|
+
if (typeof location !== 'string' || !location) throw new Error(REBUNDLED);
|
|
27
|
+
const { createRequire } = runtime.getBuiltinModule('node:module') as typeof import('node:module');
|
|
28
|
+
try {
|
|
29
|
+
backend = createRequire(location)(backendPath) as EmbeddedBackend;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if ((error as { code?: unknown } | null)?.code !== 'MODULE_NOT_FOUND') throw error;
|
|
32
|
+
throw new Error(REBUNDLED, { cause: error });
|
|
33
|
+
}
|
|
34
|
+
return backend;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function getSharedManager(
|
|
38
|
+
dataPath?: string
|
|
39
|
+
): ReturnType<EmbeddedBackend['getSharedManager']> {
|
|
40
|
+
return loadBackend().getSharedManager(dataPath);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// A shared manager exists only after getSharedManager() loaded the engine, so
|
|
44
|
+
// shutdown and inspection never load it on behalf of TCP-only clients.
|
|
45
|
+
export function shutdownManager(): void {
|
|
46
|
+
backend?.shutdownManager();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function peekSharedManager(): ReturnType<EmbeddedBackend['peekSharedManager']> {
|
|
50
|
+
return backend?.peekSharedManager() ?? null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function embeddedDlq(): EmbeddedBackend['dlq'] {
|
|
54
|
+
return loadBackend().dlq;
|
|
55
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Runtime primitives only: job and scheduling logic stays in the canonical client. */
|
|
2
|
+
import { access, unlink } from 'node:fs/promises';
|
|
3
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
4
|
+
import { availableParallelism } from 'node:os';
|
|
5
|
+
export { ThreadWorker } from './thread-worker.js';
|
|
6
|
+
|
|
7
|
+
export const hardwareConcurrency = (() => {
|
|
8
|
+
try {
|
|
9
|
+
// The embedded engine sizes shards from this exact runtime value. Host
|
|
10
|
+
// CPU inventory can exceed the quota visible to Bun inside a container.
|
|
11
|
+
return globalThis.navigator
|
|
12
|
+
? globalThis.navigator.hardwareConcurrency || 4
|
|
13
|
+
: availableParallelism() || 4;
|
|
14
|
+
} catch {
|
|
15
|
+
return 4;
|
|
16
|
+
}
|
|
17
|
+
})();
|
|
18
|
+
export const sleep = (ms: number): Promise<void> =>
|
|
19
|
+
new Promise((resolve) => setTimeout(resolve, ms));
|
|
20
|
+
|
|
21
|
+
/** Pool identities need a stable token fingerprint, never the token itself. */
|
|
22
|
+
export function hash(value: string): number {
|
|
23
|
+
return createHash('sha256').update(value).digest().readUInt32BE(0);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** RFC 9562 UUIDv7, retaining the canonical public ID format. */
|
|
27
|
+
export function uuid(): string {
|
|
28
|
+
const bytes = randomBytes(16);
|
|
29
|
+
bytes.writeUIntBE(Date.now(), 0, 6);
|
|
30
|
+
bytes[6] = 0x70 | (bytes[6] & 0x0f);
|
|
31
|
+
bytes[8] = 0x80 | (bytes[8] & 0x3f);
|
|
32
|
+
const hex = bytes.toString('hex');
|
|
33
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function file(path: string): { exists(): Promise<boolean>; delete(): Promise<void> } {
|
|
37
|
+
return {
|
|
38
|
+
async exists() {
|
|
39
|
+
try {
|
|
40
|
+
await access(path);
|
|
41
|
+
return true;
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return false;
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
delete: () => unlink(path),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/** Worker-thread boundary for the canonical sandbox pool and generated wrapper. */
|
|
2
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { Worker } from 'node:worker_threads';
|
|
6
|
+
|
|
7
|
+
const BRIDGE = `
|
|
8
|
+
import { parentPort as __bunqueueParentPort } from 'node:worker_threads';
|
|
9
|
+
globalThis.self = globalThis;
|
|
10
|
+
globalThis.postMessage = (message) => __bunqueueParentPort.postMessage(message);
|
|
11
|
+
__bunqueueParentPort.on('message', (data) => {
|
|
12
|
+
Promise.resolve().then(() => globalThis.onmessage?.({ data })).catch((error) => {
|
|
13
|
+
queueMicrotask(() => { throw error; });
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
export interface ThreadError {
|
|
19
|
+
message: string;
|
|
20
|
+
error: Error;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class ThreadWorker {
|
|
24
|
+
onmessage: ((event: { data: unknown }) => void) | null = null;
|
|
25
|
+
onerror: ((event: ThreadError) => void) | null = null;
|
|
26
|
+
private readonly worker: Worker;
|
|
27
|
+
private readonly directory: string;
|
|
28
|
+
private intentionalExit = false;
|
|
29
|
+
private reportedError = false;
|
|
30
|
+
private termination: Promise<number> | undefined;
|
|
31
|
+
|
|
32
|
+
constructor(wrapperPath: string, _options: { smol?: boolean } = {}) {
|
|
33
|
+
// The canonical wrapper contains JavaScript but uses a .ts filename.
|
|
34
|
+
// A private .mjs copy works on Node 20 without a TypeScript loader and
|
|
35
|
+
// retains file-based resolution for the absolute processor import.
|
|
36
|
+
const source = readFileSync(wrapperPath, 'utf8');
|
|
37
|
+
this.directory = mkdtempSync(join(tmpdir(), 'bunqueue-thread-'));
|
|
38
|
+
const entry = join(this.directory, 'wrapper.mjs');
|
|
39
|
+
try {
|
|
40
|
+
writeFileSync(entry, BRIDGE + source, { mode: 0o600 });
|
|
41
|
+
this.worker = new Worker(entry, {
|
|
42
|
+
// Parent stdin/eval module selection does not apply to a worker file.
|
|
43
|
+
execArgv: process.execArgv.filter(
|
|
44
|
+
(argument, index, arguments_) =>
|
|
45
|
+
argument !== '--input-type' &&
|
|
46
|
+
!argument.startsWith('--input-type=') &&
|
|
47
|
+
arguments_[index - 1] !== '--input-type'
|
|
48
|
+
),
|
|
49
|
+
});
|
|
50
|
+
} catch (error) {
|
|
51
|
+
this.cleanup();
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
this.worker.on('message', (data: unknown) => {
|
|
55
|
+
if (!this.intentionalExit) this.onmessage?.({ data });
|
|
56
|
+
});
|
|
57
|
+
this.worker.on('error', (error: Error) => this.reportError(error));
|
|
58
|
+
this.worker.on('exit', (code) => {
|
|
59
|
+
this.cleanup();
|
|
60
|
+
this.reportError(new Error(`Sandboxed worker exited unexpectedly with code ${code}`));
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
postMessage(message: unknown): void {
|
|
65
|
+
if (!this.intentionalExit) this.worker.postMessage(message);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
terminate(): Promise<number> {
|
|
69
|
+
this.intentionalExit = true;
|
|
70
|
+
this.termination ??= this.worker.terminate().finally(() => this.cleanup());
|
|
71
|
+
return this.termination;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private reportError(error: Error): void {
|
|
75
|
+
if (this.intentionalExit || this.reportedError) return;
|
|
76
|
+
this.reportedError = true;
|
|
77
|
+
this.onerror?.({ message: error.message, error });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private cleanup(): void {
|
|
81
|
+
rmSync(this.directory, { recursive: true, force: true });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/** Node socket boundary; command, health, retry and event behavior stays canonical. */
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { createConnection as connectTcp, type Socket } from 'node:net';
|
|
4
|
+
import { connect as connectTls } from 'node:tls';
|
|
5
|
+
import {
|
|
6
|
+
FrameParser,
|
|
7
|
+
FrameSizeError,
|
|
8
|
+
} from '../../../../src/infrastructure/server/protocol/frameParser.js';
|
|
9
|
+
import type { ClientTlsOptions } from '../../../../src/client/tcp/types/tls.js';
|
|
10
|
+
import type { SocketWrapper } from '../../../../src/client/tcp/types/socket.js';
|
|
11
|
+
import type {
|
|
12
|
+
ConnectionEvents,
|
|
13
|
+
ConnectionResult,
|
|
14
|
+
ConnectionTarget,
|
|
15
|
+
} from '../../../../src/client/tcp/transport.js';
|
|
16
|
+
|
|
17
|
+
export type {
|
|
18
|
+
ConnectionEvents,
|
|
19
|
+
ConnectionResult,
|
|
20
|
+
ConnectionTarget,
|
|
21
|
+
} from '../../../../src/client/tcp/transport.js';
|
|
22
|
+
|
|
23
|
+
const MAX_WRITE_QUEUE_BYTES = 64 * 1024 * 1024;
|
|
24
|
+
|
|
25
|
+
export function buildClientTls(
|
|
26
|
+
tls: boolean | ClientTlsOptions | undefined
|
|
27
|
+
): true | Record<string, unknown> | undefined {
|
|
28
|
+
if (!tls) return undefined;
|
|
29
|
+
if (tls === true) return true;
|
|
30
|
+
return {
|
|
31
|
+
...(tls.rejectUnauthorized !== undefined && { rejectUnauthorized: tls.rejectUnauthorized }),
|
|
32
|
+
...(tls.caFile !== undefined && { ca: readFileSync(tls.caFile) }),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function tlsRequiresVerification(tls: boolean | ClientTlsOptions | undefined): boolean {
|
|
37
|
+
return !!tls && (tls === true || tls.rejectUnauthorized !== false);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function createConnection(
|
|
41
|
+
target: ConnectionTarget,
|
|
42
|
+
connectTimeout: number,
|
|
43
|
+
events: ConnectionEvents
|
|
44
|
+
): Promise<ConnectionResult> {
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
const host = target.host ?? 'localhost';
|
|
47
|
+
const port = target.port ?? 6789;
|
|
48
|
+
const description = `${target.host}:${target.port}`;
|
|
49
|
+
const tls = buildClientTls(target.tls);
|
|
50
|
+
const parser = new FrameParser();
|
|
51
|
+
let settled = false;
|
|
52
|
+
// TCP reached the peer during this attempt (Bun's `open`); TLS may still fail.
|
|
53
|
+
let tcpOpened = false;
|
|
54
|
+
// The attempt resolved and the client owns the socket.
|
|
55
|
+
let opened = false;
|
|
56
|
+
let socket: Socket;
|
|
57
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
58
|
+
const cleanup = () => {
|
|
59
|
+
if (timer !== undefined) clearTimeout(timer);
|
|
60
|
+
timer = undefined;
|
|
61
|
+
};
|
|
62
|
+
const fail = (error: Error) => {
|
|
63
|
+
if (settled) return;
|
|
64
|
+
settled = true;
|
|
65
|
+
cleanup();
|
|
66
|
+
reject(error);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
socket =
|
|
71
|
+
tls === undefined
|
|
72
|
+
? connectTcp({ host, port })
|
|
73
|
+
: connectTls({ host, port, ...(tls === true ? {} : tls) });
|
|
74
|
+
} catch (error) {
|
|
75
|
+
fail(new Error(`Failed to connect to ${description}: ${String(error)}`));
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const wrapper: SocketWrapper = {
|
|
80
|
+
frameParser: parser,
|
|
81
|
+
write(data) {
|
|
82
|
+
if (socket.destroyed) return;
|
|
83
|
+
// Node buffers partial writes internally and resumes them on drain.
|
|
84
|
+
socket.write(data);
|
|
85
|
+
if (socket.writableLength > MAX_WRITE_QUEUE_BYTES) socket.destroy();
|
|
86
|
+
},
|
|
87
|
+
end() {
|
|
88
|
+
// Shutdown cancels pending requests in the canonical client first.
|
|
89
|
+
// Destroy also handles a peer that never acknowledges a TCP half-close.
|
|
90
|
+
socket.destroy();
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const open = () => {
|
|
95
|
+
if (settled) {
|
|
96
|
+
// A late socket from an abandoned attempt never reaches the client.
|
|
97
|
+
socket.destroy();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
opened = true;
|
|
101
|
+
settled = true;
|
|
102
|
+
cleanup();
|
|
103
|
+
socket.setNoDelay(true);
|
|
104
|
+
socket.setKeepAlive(true, 15000);
|
|
105
|
+
resolve({ socket: wrapper, cleanup });
|
|
106
|
+
};
|
|
107
|
+
// TLS sockets also emit the TCP-level `connect` before `secureConnect`.
|
|
108
|
+
socket.on('connect', () => {
|
|
109
|
+
if (!settled) tcpOpened = true;
|
|
110
|
+
if (tls === undefined) open();
|
|
111
|
+
});
|
|
112
|
+
if (tls !== undefined) socket.on('secureConnect', open);
|
|
113
|
+
socket.on('data', (data: Buffer) => {
|
|
114
|
+
let frames: Uint8Array[];
|
|
115
|
+
try {
|
|
116
|
+
frames = parser.addData(data);
|
|
117
|
+
} catch (error) {
|
|
118
|
+
const reason =
|
|
119
|
+
error instanceof FrameSizeError
|
|
120
|
+
? new Error(
|
|
121
|
+
`Frame too large: ${error.requestedSize} bytes exceeds maximum ${error.maxSize}`
|
|
122
|
+
)
|
|
123
|
+
: error instanceof Error
|
|
124
|
+
? error
|
|
125
|
+
: new Error(String(error));
|
|
126
|
+
socket.destroy();
|
|
127
|
+
events.onError(reason);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
for (const frame of frames) events.onData(frame);
|
|
131
|
+
});
|
|
132
|
+
socket.on('error', (error: Error) => {
|
|
133
|
+
if (!opened) {
|
|
134
|
+
fail(new Error(`Failed to connect to ${description}: ${error.message}`));
|
|
135
|
+
} else {
|
|
136
|
+
events.onError(error);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
socket.on('close', () => {
|
|
140
|
+
fail(new Error('Connection closed'));
|
|
141
|
+
cleanup();
|
|
142
|
+
// Like Bun, only a socket whose TCP connection opened reports a close. A
|
|
143
|
+
// refused attempt, or one abandoned before TCP opened, only fails the
|
|
144
|
+
// connect: the canonical client keeps queued commands and retries instead
|
|
145
|
+
// of running its lost-connection path.
|
|
146
|
+
if (tcpOpened) events.onClose();
|
|
147
|
+
});
|
|
148
|
+
timer = setTimeout(() => {
|
|
149
|
+
fail(new Error(`Connection timeout to ${description}`));
|
|
150
|
+
socket.destroy();
|
|
151
|
+
}, connectTimeout);
|
|
152
|
+
});
|
|
153
|
+
}
|
package/src/connection.ts
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TCP connection to a bunqueue server — cross-runtime (Node.js, Bun, Deno).
|
|
3
|
-
*
|
|
4
|
-
* Requests carry a `reqId` string; the server echoes it back, enabling
|
|
5
|
-
* pipelining (many in-flight commands per socket). Uses only `node:`
|
|
6
|
-
* builtins (net/tls), which Node, Bun and Deno all support.
|
|
7
|
-
*/
|
|
1
|
+
/** Cross-runtime TCP connection with reqId-based request pipelining. */
|
|
8
2
|
|
|
9
3
|
import { EventEmitter } from 'node:events';
|
|
10
4
|
import type { Socket } from 'node:net';
|
|
11
|
-
import {
|
|
5
|
+
import { unpack } from 'msgpackr';
|
|
12
6
|
import { Backpressure } from './backpressure.js';
|
|
13
7
|
import type {
|
|
14
8
|
Command,
|
|
@@ -18,18 +12,16 @@ import type {
|
|
|
18
12
|
TlsOption,
|
|
19
13
|
} from './connection-types.js';
|
|
20
14
|
import { AuthError, CommandError, CommandTimeoutError, ConnectionClosedError } from './errors.js';
|
|
21
|
-
import {
|
|
15
|
+
import { FrameParser, PROTOCOL_VERSION } from './frame.js';
|
|
22
16
|
import { nowMs, Telemetry } from './observability.js';
|
|
17
|
+
import { serializeCommand } from './serialization.js';
|
|
23
18
|
import { openSocket } from './socket-factory.js';
|
|
24
19
|
|
|
25
20
|
export type { Command, ConnectionOptions, Response, TlsOption } from './connection-types.js';
|
|
26
21
|
|
|
27
22
|
/**
|
|
28
|
-
* A
|
|
29
|
-
*
|
|
30
|
-
* Emits typed lifecycle events for observability: `connect`, `disconnect` and
|
|
31
|
-
* `reconnect_scheduled` (payloads mirror the telemetry events). Attach a
|
|
32
|
-
* telemetry sink via the `onTelemetry` option for per-command latency metrics.
|
|
23
|
+
* A pipelined connection with lifecycle events and an optional structured
|
|
24
|
+
* telemetry sink.
|
|
33
25
|
*/
|
|
34
26
|
export class Connection extends EventEmitter {
|
|
35
27
|
readonly host: string;
|
|
@@ -49,8 +41,7 @@ export class Connection extends EventEmitter {
|
|
|
49
41
|
private connectGeneration = 0;
|
|
50
42
|
private failedAttempts = 0;
|
|
51
43
|
private nextAttemptAt = 0;
|
|
52
|
-
// Half-open recovery
|
|
53
|
-
// socket is presumed dead and torn down so the next call reconnects.
|
|
44
|
+
// Half-open recovery: repeated command timeouts force lazy reconnection.
|
|
54
45
|
private readonly maxCommandTimeouts = 3;
|
|
55
46
|
private consecutiveTimeouts = 0;
|
|
56
47
|
private readonly telemetry: Telemetry;
|
|
@@ -75,11 +66,7 @@ export class Connection extends EventEmitter {
|
|
|
75
66
|
return this.connected;
|
|
76
67
|
}
|
|
77
68
|
|
|
78
|
-
/**
|
|
79
|
-
* Monotonic counter, incremented on every successful (re)connect. Consumers
|
|
80
|
-
* that hold per-connection server state (e.g. a Worker registration) compare
|
|
81
|
-
* it between operations and re-establish that state after a reconnect.
|
|
82
|
-
*/
|
|
69
|
+
/** Successful-connect generation used to restore per-connection state. */
|
|
83
70
|
get generation(): number {
|
|
84
71
|
return this.connectGeneration;
|
|
85
72
|
}
|
|
@@ -117,16 +104,21 @@ export class Connection extends EventEmitter {
|
|
|
117
104
|
|
|
118
105
|
private async doConnect(): Promise<void> {
|
|
119
106
|
const startMs = nowMs();
|
|
120
|
-
const socket = await
|
|
107
|
+
const socket = await this.telemetry.captureAsync(
|
|
108
|
+
'connect',
|
|
109
|
+
openSocket(this.host, this.port, this.tls, this.connectTimeoutMs)
|
|
110
|
+
);
|
|
121
111
|
socket.setNoDelay(true);
|
|
122
|
-
// TCP keepalive
|
|
123
|
-
// drop with no FIN/RST) in seconds instead of ~tcp_retries2 minutes.
|
|
112
|
+
// TCP keepalive surfaces half-open cloud LB/NAT links promptly.
|
|
124
113
|
socket.setKeepAlive(true, 15_000);
|
|
125
114
|
this.parser.clear();
|
|
126
115
|
this.socket = socket;
|
|
127
116
|
|
|
128
117
|
socket.on('data', (chunk: Buffer) => this.handleData(chunk));
|
|
129
|
-
socket.on('error', () =>
|
|
118
|
+
socket.on('error', (error) => {
|
|
119
|
+
this.telemetry.error('socket', error);
|
|
120
|
+
this.teardown();
|
|
121
|
+
});
|
|
130
122
|
socket.on('close', () => this.teardown());
|
|
131
123
|
|
|
132
124
|
this.connected = true;
|
|
@@ -159,6 +151,11 @@ export class Connection extends EventEmitter {
|
|
|
159
151
|
*/
|
|
160
152
|
async call<R = Response>(command: Command, timeoutMs?: number): Promise<R> {
|
|
161
153
|
if (!this.connected) await this.connect();
|
|
154
|
+
this.reqCounter = (this.reqCounter + 1) & 0x7fffffff;
|
|
155
|
+
const reqId = String(this.reqCounter);
|
|
156
|
+
const outbound = this.telemetry.capture('serialization', () =>
|
|
157
|
+
serializeCommand(command, reqId)
|
|
158
|
+
);
|
|
162
159
|
// Backpressure: park here if too many commands are already in flight. The
|
|
163
160
|
// socket may be torn down while parked, so re-check after the gate.
|
|
164
161
|
const gate = this.backpressure.acquire(this.pending.size);
|
|
@@ -166,9 +163,6 @@ export class Connection extends EventEmitter {
|
|
|
166
163
|
const socket = this.socket;
|
|
167
164
|
if (!this.connected || !socket) throw new ConnectionClosedError('not connected');
|
|
168
165
|
|
|
169
|
-
this.reqCounter = (this.reqCounter + 1) & 0x7fffffff;
|
|
170
|
-
const reqId = String(this.reqCounter);
|
|
171
|
-
const payload = pack({ ...compact(command), reqId });
|
|
172
166
|
const gen = this.connectGeneration; // snapshot: a timeout must not tear down a newer conn
|
|
173
167
|
const startMs = nowMs();
|
|
174
168
|
|
|
@@ -199,8 +193,9 @@ export class Connection extends EventEmitter {
|
|
|
199
193
|
timer,
|
|
200
194
|
});
|
|
201
195
|
|
|
202
|
-
socket.write(
|
|
196
|
+
socket.write(outbound, (err) => {
|
|
203
197
|
if (err) {
|
|
198
|
+
this.telemetry.error('write', err);
|
|
204
199
|
const entry = this.pending.get(reqId);
|
|
205
200
|
this.pending.delete(reqId);
|
|
206
201
|
this.backpressure.release();
|
|
@@ -227,7 +222,7 @@ export class Connection extends EventEmitter {
|
|
|
227
222
|
return this.call({
|
|
228
223
|
cmd: 'Hello',
|
|
229
224
|
protocolVersion: PROTOCOL_VERSION,
|
|
230
|
-
capabilities: ['pipelining'],
|
|
225
|
+
capabilities: ['pipelining', 'separate-job-name'],
|
|
231
226
|
});
|
|
232
227
|
}
|
|
233
228
|
|
package/src/errors.ts
CHANGED
|
@@ -16,6 +16,9 @@ export class CommandTimeoutError extends BunqueueError {}
|
|
|
16
16
|
/** The server answered ok=false; message carries the server error. */
|
|
17
17
|
export class CommandError extends BunqueueError {}
|
|
18
18
|
|
|
19
|
+
/** A command cannot be encoded within the protocol's wire constraints. */
|
|
20
|
+
export class SerializationError extends BunqueueError {}
|
|
21
|
+
|
|
19
22
|
/** Authentication with the server failed. */
|
|
20
23
|
export class AuthError extends BunqueueError {}
|
|
21
24
|
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ConnectionLike } from './connection-types.js';
|
|
2
|
+
import type { AtomicFlowJobInput } from './flow-plan.js';
|
|
3
|
+
import type { JobRaw } from './job.js';
|
|
4
|
+
import type { DataResponse } from './responses.js';
|
|
5
|
+
|
|
6
|
+
interface PushFlowResult {
|
|
7
|
+
jobs: JobRaw[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function validateFlowSnapshots(
|
|
11
|
+
jobs: AtomicFlowJobInput[],
|
|
12
|
+
snapshots: unknown
|
|
13
|
+
): Map<string, JobRaw> {
|
|
14
|
+
if (!Array.isArray(snapshots) || snapshots.length !== jobs.length) {
|
|
15
|
+
throw new Error('Invalid PUSHF response: committed job snapshots are missing');
|
|
16
|
+
}
|
|
17
|
+
const expected = new Map(jobs.map((job) => [job.id, job.queue]));
|
|
18
|
+
const byId = new Map<string, JobRaw>();
|
|
19
|
+
for (const value of snapshots) {
|
|
20
|
+
if (!value || typeof value !== 'object') {
|
|
21
|
+
throw new Error('Invalid PUSHF response: job snapshot is invalid');
|
|
22
|
+
}
|
|
23
|
+
const snapshot = value as JobRaw;
|
|
24
|
+
if (typeof snapshot.id !== 'string' || !expected.has(snapshot.id)) {
|
|
25
|
+
throw new Error('Invalid PUSHF response: committed job IDs do not match the request');
|
|
26
|
+
}
|
|
27
|
+
if (byId.has(snapshot.id) || snapshot.queue !== expected.get(snapshot.id)) {
|
|
28
|
+
throw new Error('Invalid PUSHF response: committed job IDs do not match the request');
|
|
29
|
+
}
|
|
30
|
+
byId.set(snapshot.id, snapshot);
|
|
31
|
+
}
|
|
32
|
+
return byId;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function commitFlow(
|
|
36
|
+
connection: ConnectionLike,
|
|
37
|
+
jobs: AtomicFlowJobInput[]
|
|
38
|
+
): Promise<Map<string, JobRaw>> {
|
|
39
|
+
if (jobs.length === 0) return new Map();
|
|
40
|
+
const response = await connection.call<DataResponse<PushFlowResult>>({
|
|
41
|
+
cmd: 'PUSHF',
|
|
42
|
+
jobs,
|
|
43
|
+
});
|
|
44
|
+
return validateFlowSnapshots(jobs, response.data?.jobs);
|
|
45
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import {
|
|
3
|
+
type AtomicFlowJobInput,
|
|
4
|
+
allocateFlowId,
|
|
5
|
+
type FlowIdFactory,
|
|
6
|
+
flowData,
|
|
7
|
+
flowInput,
|
|
8
|
+
} from './flow-plan.js';
|
|
9
|
+
import type { FlowStep } from './flow-types.js';
|
|
10
|
+
|
|
11
|
+
const MAX_FLOW_JOBS = 10_000;
|
|
12
|
+
const QUEUE_RE = /^[a-zA-Z0-9_\-.:]+$/;
|
|
13
|
+
|
|
14
|
+
export interface ChainPlan {
|
|
15
|
+
jobs: AtomicFlowJobInput[];
|
|
16
|
+
ids: string[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface FanInPlan {
|
|
20
|
+
jobs: AtomicFlowJobInput[];
|
|
21
|
+
parallelIds: string[];
|
|
22
|
+
finalId: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function allocateSteps<T>(
|
|
26
|
+
steps: FlowStep<T>[],
|
|
27
|
+
ids: Set<string>,
|
|
28
|
+
idFactory: FlowIdFactory
|
|
29
|
+
): string[] {
|
|
30
|
+
if (steps.length > MAX_FLOW_JOBS) {
|
|
31
|
+
throw new Error(`flow exceeds the ${MAX_FLOW_JOBS} job limit`);
|
|
32
|
+
}
|
|
33
|
+
return steps.map((step) => {
|
|
34
|
+
if (!step || typeof step !== 'object') throw new Error('flow step must be an object');
|
|
35
|
+
if (typeof step.name !== 'string' || !step.name || step.name.length > 256) {
|
|
36
|
+
throw new Error('flow job name must be a non-empty string of at most 256 characters');
|
|
37
|
+
}
|
|
38
|
+
if (
|
|
39
|
+
typeof step.queueName !== 'string' ||
|
|
40
|
+
!step.queueName ||
|
|
41
|
+
step.queueName.length > 256 ||
|
|
42
|
+
!QUEUE_RE.test(step.queueName)
|
|
43
|
+
) {
|
|
44
|
+
throw new Error('flow queueName is invalid');
|
|
45
|
+
}
|
|
46
|
+
const children = (step as FlowStep<T> & { children?: unknown }).children;
|
|
47
|
+
if (children !== undefined && !Array.isArray(children)) {
|
|
48
|
+
throw new Error('flow children must be an array');
|
|
49
|
+
}
|
|
50
|
+
if ((children?.length ?? 0) > 0) {
|
|
51
|
+
throw new Error('nested children are not supported by this flow method');
|
|
52
|
+
}
|
|
53
|
+
return allocateFlowId(step.opts ?? {}, ids, idFactory);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function planChain<T>(
|
|
58
|
+
steps: FlowStep<T>[],
|
|
59
|
+
idFactory: FlowIdFactory = randomUUID
|
|
60
|
+
): ChainPlan {
|
|
61
|
+
const ids = allocateSteps(steps, new Set(), idFactory);
|
|
62
|
+
const jobs = steps.map((step, index): AtomicFlowJobInput => {
|
|
63
|
+
const dependency = index > 0 ? ids[index - 1] : undefined;
|
|
64
|
+
const data = flowData(step.name, step.data, {
|
|
65
|
+
__flowParentId: dependency ?? null,
|
|
66
|
+
});
|
|
67
|
+
return {
|
|
68
|
+
id: ids[index],
|
|
69
|
+
queue: step.queueName,
|
|
70
|
+
input: flowInput(data, step.opts ?? {}, {
|
|
71
|
+
dependsOn: dependency ? [dependency] : undefined,
|
|
72
|
+
}),
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
return { jobs, ids };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function planBulkThen<T>(
|
|
79
|
+
parallel: FlowStep<T>[],
|
|
80
|
+
final: FlowStep<T>,
|
|
81
|
+
idFactory: FlowIdFactory = randomUUID
|
|
82
|
+
): FanInPlan {
|
|
83
|
+
if (parallel.length >= MAX_FLOW_JOBS) {
|
|
84
|
+
throw new Error(`flow exceeds the ${MAX_FLOW_JOBS} job limit`);
|
|
85
|
+
}
|
|
86
|
+
const ids = new Set<string>();
|
|
87
|
+
const parallelIds = allocateSteps(parallel, ids, idFactory);
|
|
88
|
+
const [finalId] = allocateSteps([final], ids, idFactory);
|
|
89
|
+
const parallelJobs = parallel.map((step, index): AtomicFlowJobInput => ({
|
|
90
|
+
id: parallelIds[index],
|
|
91
|
+
queue: step.queueName,
|
|
92
|
+
input: flowInput(
|
|
93
|
+
flowData(step.name, step.data, {
|
|
94
|
+
__parentId: finalId,
|
|
95
|
+
__parentQueue: final.queueName,
|
|
96
|
+
}),
|
|
97
|
+
step.opts ?? {},
|
|
98
|
+
{ parentId: finalId }
|
|
99
|
+
),
|
|
100
|
+
}));
|
|
101
|
+
const finalJob: AtomicFlowJobInput = {
|
|
102
|
+
id: finalId,
|
|
103
|
+
queue: final.queueName,
|
|
104
|
+
input: flowInput(
|
|
105
|
+
flowData(final.name, final.data, {
|
|
106
|
+
__flowParentIds: parallelIds,
|
|
107
|
+
__childrenIds: parallelIds,
|
|
108
|
+
}),
|
|
109
|
+
final.opts ?? {},
|
|
110
|
+
{
|
|
111
|
+
dependsOn: parallelIds.length > 0 ? parallelIds : undefined,
|
|
112
|
+
childrenIds: parallelIds.length > 0 ? parallelIds : undefined,
|
|
113
|
+
}
|
|
114
|
+
),
|
|
115
|
+
};
|
|
116
|
+
return { jobs: [...parallelJobs, finalJob], parallelIds, finalId };
|
|
117
|
+
}
|