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.
- package/CHANGELOG.md +150 -0
- package/LEGACY.md +460 -0
- package/README.md +204 -349
- package/dist/ack-batcher.js +7 -67
- package/dist/canonical-manifest.json +930 -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 +16418 -0
- package/dist/frame.js +14 -57
- package/dist/index.d.ts +1 -27
- package/dist/index.js +10905 -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/clientTracking.d.ts +44 -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 +43 -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/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 +96 -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 +10 -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 +87 -0
- package/dist/types/src/application/types/contexts.d.ts +114 -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 +98 -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 +74 -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 +70 -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 +12 -0
- package/dist/types/src/domain/job/create.d.ts +2 -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 +4 -0
- package/dist/types/src/domain/job/payload.d.ts +18 -0
- package/dist/types/src/domain/job/state.d.ts +8 -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 +110 -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 +91 -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 +153 -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
package/src/flow-plan.ts
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
import type { FlowJob, FlowOptions } from './flow-types.js';
|
|
4
|
+
import { compact } from './frame.js';
|
|
5
|
+
import { type JobOptions, wireJobOptions } from './types.js';
|
|
6
|
+
|
|
7
|
+
const MAX_FLOW_DEPTH = 100;
|
|
8
|
+
const MAX_FLOW_JOBS = 10_000;
|
|
9
|
+
const QUEUE_RE = /^[a-zA-Z0-9_\-.:]+$/;
|
|
10
|
+
|
|
11
|
+
export type FlowIdFactory = () => string;
|
|
12
|
+
|
|
13
|
+
export interface AtomicFlowJobInput {
|
|
14
|
+
id: string;
|
|
15
|
+
queue: string;
|
|
16
|
+
input: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface PlannedFlowNode<T = unknown> {
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
queueName: string;
|
|
23
|
+
data: T | undefined;
|
|
24
|
+
children?: PlannedFlowNode<T>[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface FlowPlan<T = unknown> {
|
|
28
|
+
jobs: AtomicFlowJobInput[];
|
|
29
|
+
roots: PlannedFlowNode<T>[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface PlanState {
|
|
33
|
+
readonly ids: Set<string>;
|
|
34
|
+
readonly seen: WeakSet<object>;
|
|
35
|
+
readonly jobs: AtomicFlowJobInput[];
|
|
36
|
+
readonly idFactory: FlowIdFactory;
|
|
37
|
+
count: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface FlowLinks {
|
|
41
|
+
parentId?: string;
|
|
42
|
+
dependsOn?: string[];
|
|
43
|
+
childrenIds?: string[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function assertNameAndQueue(name: unknown, queueName: unknown, depth: number): void {
|
|
47
|
+
if (typeof name !== 'string' || name.length === 0 || name.length > 256) {
|
|
48
|
+
throw new Error('flow job name must be a non-empty string of at most 256 characters');
|
|
49
|
+
}
|
|
50
|
+
if (
|
|
51
|
+
typeof queueName !== 'string' ||
|
|
52
|
+
queueName.length === 0 ||
|
|
53
|
+
queueName.length > 256 ||
|
|
54
|
+
!QUEUE_RE.test(queueName)
|
|
55
|
+
) {
|
|
56
|
+
throw new Error('flow queueName is invalid');
|
|
57
|
+
}
|
|
58
|
+
if (depth > MAX_FLOW_DEPTH) {
|
|
59
|
+
throw new Error(`flow exceeds the ${MAX_FLOW_DEPTH} level depth limit`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function assertAtomicOptions(opts: JobOptions): void {
|
|
64
|
+
if (opts.repeat !== undefined) throw new Error('repeat is not supported inside an atomic flow');
|
|
65
|
+
if (opts.deduplication !== undefined) {
|
|
66
|
+
throw new Error('deduplication is not supported inside an atomic flow');
|
|
67
|
+
}
|
|
68
|
+
if (opts.debounce !== undefined) {
|
|
69
|
+
throw new Error('debounce is not supported inside an atomic flow');
|
|
70
|
+
}
|
|
71
|
+
if (
|
|
72
|
+
opts.parentId !== undefined ||
|
|
73
|
+
opts.dependsOn !== undefined ||
|
|
74
|
+
opts.childrenIds !== undefined
|
|
75
|
+
) {
|
|
76
|
+
throw new Error('flow topology options are owned by FlowProducer');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function assertUserData(data: unknown): void {
|
|
81
|
+
if (!data || typeof data !== 'object' || Array.isArray(data)) return;
|
|
82
|
+
for (const key of Object.keys(data)) {
|
|
83
|
+
if (key === 'name' || key.startsWith('__')) {
|
|
84
|
+
throw new Error(`flow job data key is reserved: ${key}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function flowData(
|
|
90
|
+
name: string,
|
|
91
|
+
data: unknown,
|
|
92
|
+
internal: Record<string, unknown> = {}
|
|
93
|
+
): Record<string, unknown> {
|
|
94
|
+
assertUserData(data);
|
|
95
|
+
if (data && typeof data === 'object' && !Array.isArray(data)) {
|
|
96
|
+
return { ...(data as Record<string, unknown>), name, ...internal };
|
|
97
|
+
}
|
|
98
|
+
return data === undefined || data === null
|
|
99
|
+
? { name, ...internal }
|
|
100
|
+
: { name, payload: data, ...internal };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function flowInput(
|
|
104
|
+
data: Record<string, unknown>,
|
|
105
|
+
opts: JobOptions,
|
|
106
|
+
links: FlowLinks = {}
|
|
107
|
+
): Record<string, unknown> {
|
|
108
|
+
assertAtomicOptions(opts);
|
|
109
|
+
const mapped = { ...wireJobOptions(opts) };
|
|
110
|
+
delete mapped.jobId;
|
|
111
|
+
delete mapped.parentId;
|
|
112
|
+
delete mapped.dependsOn;
|
|
113
|
+
delete mapped.childrenIds;
|
|
114
|
+
return compact({
|
|
115
|
+
data,
|
|
116
|
+
...mapped,
|
|
117
|
+
customId: opts.jobId,
|
|
118
|
+
parentId: links.parentId,
|
|
119
|
+
dependsOn: links.dependsOn,
|
|
120
|
+
childrenIds: links.childrenIds,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function allocateFlowId(
|
|
125
|
+
opts: JobOptions,
|
|
126
|
+
ids: Set<string>,
|
|
127
|
+
idFactory: FlowIdFactory
|
|
128
|
+
): string {
|
|
129
|
+
const id = opts.jobId ?? idFactory();
|
|
130
|
+
if (typeof id !== 'string' || id.length === 0 || id.length > 1_024 || id.includes(':')) {
|
|
131
|
+
throw new Error('flow jobId must be non-empty and cannot contain a colon');
|
|
132
|
+
}
|
|
133
|
+
if (ids.has(id)) throw new Error(`duplicate flow job id: ${id}`);
|
|
134
|
+
ids.add(id);
|
|
135
|
+
return id;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function visit<T>(
|
|
139
|
+
node: FlowJob<T>,
|
|
140
|
+
parent: { id: string; queue: string } | undefined,
|
|
141
|
+
depth: number,
|
|
142
|
+
options: FlowOptions | undefined,
|
|
143
|
+
state: PlanState
|
|
144
|
+
): PlannedFlowNode<T> {
|
|
145
|
+
if (!node || typeof node !== 'object') throw new Error('flow node must be an object');
|
|
146
|
+
assertNameAndQueue(node.name, node.queueName, depth);
|
|
147
|
+
if (node.children !== undefined && !Array.isArray(node.children)) {
|
|
148
|
+
throw new Error('flow children must be an array');
|
|
149
|
+
}
|
|
150
|
+
if (state.seen.has(node as object)) throw new Error('flow contains a cycle or shared node');
|
|
151
|
+
state.seen.add(node as object);
|
|
152
|
+
state.count += 1;
|
|
153
|
+
if (state.count > MAX_FLOW_JOBS) {
|
|
154
|
+
throw new Error(`flow exceeds the ${MAX_FLOW_JOBS} job limit`);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const defaults = options?.queuesOptions?.[node.queueName];
|
|
158
|
+
const opts = defaults ? { ...defaults, ...node.opts } : (node.opts ?? {});
|
|
159
|
+
assertAtomicOptions(opts);
|
|
160
|
+
const id = allocateFlowId(opts, state.ids, state.idFactory);
|
|
161
|
+
const children = (node.children ?? []).map((child) =>
|
|
162
|
+
visit(child, { id, queue: node.queueName }, depth + 1, options, state)
|
|
163
|
+
);
|
|
164
|
+
const childIds = children.map((child) => child.id);
|
|
165
|
+
const internal: Record<string, unknown> = {};
|
|
166
|
+
if (parent) {
|
|
167
|
+
internal.__parentId = parent.id;
|
|
168
|
+
internal.__parentQueue = parent.queue;
|
|
169
|
+
}
|
|
170
|
+
if (childIds.length > 0) internal.__childrenIds = childIds;
|
|
171
|
+
const data = flowData(node.name, node.data, internal);
|
|
172
|
+
state.jobs.push({
|
|
173
|
+
id,
|
|
174
|
+
queue: node.queueName,
|
|
175
|
+
input: flowInput(data, opts, {
|
|
176
|
+
parentId: parent?.id,
|
|
177
|
+
dependsOn: childIds.length > 0 ? childIds : undefined,
|
|
178
|
+
childrenIds: childIds.length > 0 ? childIds : undefined,
|
|
179
|
+
}),
|
|
180
|
+
});
|
|
181
|
+
return {
|
|
182
|
+
id,
|
|
183
|
+
name: node.name,
|
|
184
|
+
queueName: node.queueName,
|
|
185
|
+
data: node.data,
|
|
186
|
+
children: children.length > 0 ? children : undefined,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function planFlows<T>(
|
|
191
|
+
flows: FlowJob<T>[],
|
|
192
|
+
options?: FlowOptions,
|
|
193
|
+
idFactory: FlowIdFactory = randomUUID
|
|
194
|
+
): FlowPlan<T> {
|
|
195
|
+
for (const defaults of Object.values(options?.queuesOptions ?? {})) {
|
|
196
|
+
if ((defaults as Partial<JobOptions>).jobId !== undefined) {
|
|
197
|
+
throw new Error('jobId cannot be a queue default');
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const state: PlanState = {
|
|
201
|
+
ids: new Set(),
|
|
202
|
+
seen: new WeakSet(),
|
|
203
|
+
jobs: [],
|
|
204
|
+
idFactory,
|
|
205
|
+
count: 0,
|
|
206
|
+
};
|
|
207
|
+
const roots = flows.map((flow) => visit(flow, undefined, 0, options, state));
|
|
208
|
+
return { jobs: state.jobs, roots };
|
|
209
|
+
}
|
package/src/flow-types.ts
CHANGED
|
@@ -13,6 +13,10 @@ export interface FlowJob<T = unknown> {
|
|
|
13
13
|
children?: FlowJob<T>[];
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
export interface FlowOptions {
|
|
17
|
+
queuesOptions?: Record<string, Omit<Partial<JobOptions>, 'jobId'>>;
|
|
18
|
+
}
|
|
19
|
+
|
|
16
20
|
export interface JobNode<T = unknown> {
|
|
17
21
|
job: Job<T>;
|
|
18
22
|
children?: JobNode<T>[];
|
package/src/flow.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* FlowProducer: parent/children
|
|
3
|
-
* Mirrors the official client's TCP flow logic (bottom-up creation,
|
|
4
|
-
* UpdateParent fix-up, rollback via Cancel on failure).
|
|
2
|
+
* FlowProducer: atomic parent/children trees, chains and fan-in flows.
|
|
5
3
|
*/
|
|
6
4
|
|
|
7
5
|
import { Connection } from './connection.js';
|
|
8
6
|
import { CommandError } from './errors.js';
|
|
7
|
+
import { commitFlow } from './flow-commit.js';
|
|
8
|
+
import { type PlannedFlowNode, planFlows } from './flow-plan.js';
|
|
9
|
+
import { planBulkThen, planChain } from './flow-plan-legacy.js';
|
|
9
10
|
import type {
|
|
10
11
|
FlowJob,
|
|
12
|
+
FlowOptions,
|
|
11
13
|
FlowProducerOptions,
|
|
12
14
|
FlowStep,
|
|
13
15
|
GetFlowOptions,
|
|
14
16
|
JobNode,
|
|
15
17
|
} from './flow-types.js';
|
|
16
|
-
import { compact } from './frame.js';
|
|
17
18
|
import { Job } from './job.js';
|
|
18
|
-
import type { JobResponse
|
|
19
|
-
import { type JobOptions, jobPayload, wireJobOptions } from './types.js';
|
|
19
|
+
import type { JobResponse } from './responses.js';
|
|
20
20
|
|
|
21
21
|
export class FlowProducer {
|
|
22
22
|
readonly connection: Connection;
|
|
@@ -36,29 +36,17 @@ export class FlowProducer {
|
|
|
36
36
|
this.ownsConnection = opts.connection === undefined;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
/** Add a flow tree
|
|
40
|
-
async add<T = unknown>(flow: FlowJob<T
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
} catch (err) {
|
|
45
|
-
await this.rollback(created);
|
|
46
|
-
throw err;
|
|
47
|
-
}
|
|
39
|
+
/** Add a flow tree in one broker-side atomic commit. */
|
|
40
|
+
async add<T = unknown>(flow: FlowJob<T>, options?: FlowOptions): Promise<JobNode<T>> {
|
|
41
|
+
const plan = planFlows([flow], options);
|
|
42
|
+
const snapshots = await commitFlow(this.connection, plan.jobs);
|
|
43
|
+
return this.buildNode(plan.roots[0], snapshots);
|
|
48
44
|
}
|
|
49
45
|
|
|
50
46
|
async addBulk<T = unknown>(flows: FlowJob<T>[]): Promise<JobNode<T>[]> {
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
for (const flow of flows) {
|
|
55
|
-
results.push(await this.addNode(flow, null, created));
|
|
56
|
-
}
|
|
57
|
-
return results;
|
|
58
|
-
} catch (err) {
|
|
59
|
-
await this.rollback(created);
|
|
60
|
-
throw err;
|
|
61
|
-
}
|
|
47
|
+
const plan = planFlows(flows);
|
|
48
|
+
const snapshots = await commitFlow(this.connection, plan.jobs);
|
|
49
|
+
return plan.roots.map((root) => this.buildNode(root, snapshots));
|
|
62
50
|
}
|
|
63
51
|
|
|
64
52
|
/** Fetch a flow tree starting from a job id (recursive over childrenIds). */
|
|
@@ -74,32 +62,9 @@ export class FlowProducer {
|
|
|
74
62
|
/** Add a sequential chain: step[0] → step[1] → ... via dependsOn. */
|
|
75
63
|
async addChain<T = unknown>(steps: FlowStep<T>[]): Promise<{ jobIds: string[] }> {
|
|
76
64
|
if (steps.length === 0) return { jobIds: [] };
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
for (const step of steps) {
|
|
81
|
-
const data: Record<string, unknown> = compact({
|
|
82
|
-
...jobPayload(step.name, step.data),
|
|
83
|
-
__flowParentId: prevId ?? undefined,
|
|
84
|
-
});
|
|
85
|
-
// Connection.call compacts internally, so no outer compact() is needed
|
|
86
|
-
// (nesting it confused generic inference of `data`/`response`).
|
|
87
|
-
const response: OkResponse = await this.connection.call<OkResponse>({
|
|
88
|
-
cmd: 'PUSH',
|
|
89
|
-
queue: step.queueName,
|
|
90
|
-
data,
|
|
91
|
-
...wireJobOptions(step.opts),
|
|
92
|
-
dependsOn: prevId ? [prevId] : undefined,
|
|
93
|
-
});
|
|
94
|
-
const id = String(response.id);
|
|
95
|
-
jobIds.push(id);
|
|
96
|
-
prevId = id;
|
|
97
|
-
}
|
|
98
|
-
return { jobIds };
|
|
99
|
-
} catch (err) {
|
|
100
|
-
await this.rollback(jobIds);
|
|
101
|
-
throw err;
|
|
102
|
-
}
|
|
65
|
+
const plan = planChain(steps);
|
|
66
|
+
await commitFlow(this.connection, plan.jobs);
|
|
67
|
+
return { jobIds: plan.ids };
|
|
103
68
|
}
|
|
104
69
|
|
|
105
70
|
/** Parallel jobs converging into a final fan-in job. */
|
|
@@ -107,47 +72,9 @@ export class FlowProducer {
|
|
|
107
72
|
parallel: FlowStep<T>[],
|
|
108
73
|
final: FlowStep<T>
|
|
109
74
|
): Promise<{ parallelIds: string[]; finalId: string }> {
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
parallel.map(async (step) => {
|
|
114
|
-
const response = await this.connection.call<OkResponse>(
|
|
115
|
-
compact({
|
|
116
|
-
cmd: 'PUSH',
|
|
117
|
-
queue: step.queueName,
|
|
118
|
-
data: jobPayload(step.name, step.data),
|
|
119
|
-
...wireJobOptions(step.opts),
|
|
120
|
-
}) as { cmd: string }
|
|
121
|
-
);
|
|
122
|
-
return String(response.id);
|
|
123
|
-
})
|
|
124
|
-
);
|
|
125
|
-
const errors: unknown[] = [];
|
|
126
|
-
for (const r of results) {
|
|
127
|
-
if (r.status === 'fulfilled') parallelIds.push(r.value);
|
|
128
|
-
else errors.push(r.reason);
|
|
129
|
-
}
|
|
130
|
-
if (errors.length > 0) {
|
|
131
|
-
await this.rollback(parallelIds);
|
|
132
|
-
throw errors[0] instanceof Error ? errors[0] : new Error(String(errors[0]));
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const finalData = {
|
|
136
|
-
...jobPayload(final.name, final.data),
|
|
137
|
-
__flowParentIds: parallelIds,
|
|
138
|
-
};
|
|
139
|
-
const finalId = await this.pushWithParent(
|
|
140
|
-
final.queueName,
|
|
141
|
-
finalData,
|
|
142
|
-
final.opts,
|
|
143
|
-
null,
|
|
144
|
-
parallelIds
|
|
145
|
-
);
|
|
146
|
-
return { parallelIds, finalId };
|
|
147
|
-
} catch (err) {
|
|
148
|
-
await this.rollback(parallelIds);
|
|
149
|
-
throw err;
|
|
150
|
-
}
|
|
75
|
+
const plan = planBulkThen(parallel, final);
|
|
76
|
+
await commitFlow(this.connection, plan.jobs);
|
|
77
|
+
return { parallelIds: plan.parallelIds, finalId: plan.finalId };
|
|
151
78
|
}
|
|
152
79
|
|
|
153
80
|
close(): void {
|
|
@@ -156,64 +83,17 @@ export class FlowProducer {
|
|
|
156
83
|
|
|
157
84
|
// ----------------------------------------------------------------- internals
|
|
158
85
|
|
|
159
|
-
private
|
|
160
|
-
node:
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
node.children.map((child) => this.addNode(child, tempParent, created))
|
|
171
|
-
);
|
|
172
|
-
for (const childNode of results) {
|
|
173
|
-
childNodes.push(childNode);
|
|
174
|
-
childIds.push(childNode.job.id);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
const jobData: Record<string, unknown> = jobPayload(node.name, node.data);
|
|
179
|
-
if (parentRef) {
|
|
180
|
-
jobData.__parentId = parentRef.id;
|
|
181
|
-
jobData.__parentQueue = parentRef.queue;
|
|
182
|
-
}
|
|
183
|
-
if (childIds.length > 0) jobData.__childrenIds = childIds;
|
|
184
|
-
|
|
185
|
-
const id = await this.pushWithParent(node.queueName, jobData, node.opts, parentRef, childIds);
|
|
186
|
-
created.push(id);
|
|
187
|
-
|
|
188
|
-
const job = new Job<T>({ id, queue: node.queueName, data: jobData }, this.connection);
|
|
189
|
-
return { job, children: childNodes.length > 0 ? childNodes : undefined };
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
private async pushWithParent(
|
|
193
|
-
queue: string,
|
|
194
|
-
data: Record<string, unknown>,
|
|
195
|
-
opts: JobOptions | undefined,
|
|
196
|
-
parentRef: { id: string; queue: string } | null,
|
|
197
|
-
childIds: string[]
|
|
198
|
-
): Promise<string> {
|
|
199
|
-
const response = await this.connection.call<OkResponse>(
|
|
200
|
-
compact({
|
|
201
|
-
cmd: 'PUSH',
|
|
202
|
-
queue,
|
|
203
|
-
data,
|
|
204
|
-
...wireJobOptions(opts),
|
|
205
|
-
parentId: parentRef?.id,
|
|
206
|
-
childrenIds: childIds.length > 0 ? childIds : undefined,
|
|
207
|
-
dependsOn: childIds.length > 0 ? childIds : undefined,
|
|
208
|
-
}) as { cmd: string }
|
|
209
|
-
);
|
|
210
|
-
const parentJobId = String(response.id);
|
|
211
|
-
|
|
212
|
-
// fix up children with the real parent id (like the official client)
|
|
213
|
-
for (const childId of childIds) {
|
|
214
|
-
await this.connection.call({ cmd: 'UpdateParent', childId, parentId: parentJobId });
|
|
215
|
-
}
|
|
216
|
-
return parentJobId;
|
|
86
|
+
private buildNode<T>(
|
|
87
|
+
node: PlannedFlowNode<T>,
|
|
88
|
+
snapshots: ReadonlyMap<string, Record<string, unknown>>
|
|
89
|
+
): JobNode<T> {
|
|
90
|
+
const snapshot = snapshots.get(node.id);
|
|
91
|
+
if (!snapshot) throw new Error(`Committed flow snapshot missing for ${node.id}`);
|
|
92
|
+
const children = node.children?.map((child) => this.buildNode(child, snapshots));
|
|
93
|
+
return {
|
|
94
|
+
job: new Job<T>(snapshot, this.connection),
|
|
95
|
+
children: children && children.length > 0 ? children : undefined,
|
|
96
|
+
};
|
|
217
97
|
}
|
|
218
98
|
|
|
219
99
|
private async fetchNode<T>(
|
|
@@ -249,16 +129,4 @@ export class FlowProducer {
|
|
|
249
129
|
}
|
|
250
130
|
return { job, children: children.length > 0 ? children : undefined };
|
|
251
131
|
}
|
|
252
|
-
|
|
253
|
-
private async rollback(jobIds: string[]): Promise<void> {
|
|
254
|
-
await Promise.all(
|
|
255
|
-
jobIds.map(async (id) => {
|
|
256
|
-
try {
|
|
257
|
-
await this.connection.call({ cmd: 'Cancel', id });
|
|
258
|
-
} catch {
|
|
259
|
-
// ignore cleanup errors
|
|
260
|
-
}
|
|
261
|
-
})
|
|
262
|
-
);
|
|
263
|
-
}
|
|
264
132
|
}
|
package/src/frame.ts
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* prefix + msgpack payload. Runtime-neutral (plain Buffer operations).
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { ConnectionClosedError } from './errors.js';
|
|
6
|
+
import { ConnectionClosedError, SerializationError } from './errors.js';
|
|
7
7
|
|
|
8
|
-
export const PROTOCOL_VERSION =
|
|
8
|
+
export const PROTOCOL_VERSION = 3;
|
|
9
9
|
export const MAX_FRAME_SIZE = 64 * 1024 * 1024; // mirror server-side limit
|
|
10
10
|
|
|
11
11
|
/** Drop undefined-valued keys so the msgpack frame stays minimal. */
|
|
@@ -19,6 +19,9 @@ export function compact<T extends Record<string, unknown>>(obj: T): T {
|
|
|
19
19
|
|
|
20
20
|
/** Frame a msgpack payload with the 4-byte big-endian length prefix. */
|
|
21
21
|
export function frame(payload: Uint8Array): Buffer {
|
|
22
|
+
if (payload.length > MAX_FRAME_SIZE) {
|
|
23
|
+
throw new SerializationError(`frame size ${payload.length} exceeds maximum ${MAX_FRAME_SIZE}`);
|
|
24
|
+
}
|
|
22
25
|
const framed = Buffer.allocUnsafe(4 + payload.length);
|
|
23
26
|
framed.writeUInt32BE(payload.length, 0);
|
|
24
27
|
framed.set(payload, 4);
|
package/src/index.ts
CHANGED
|
@@ -1,30 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Works on Node.js ≥20, Bun and Deno ≥2 (uses only node: builtins + msgpackr).
|
|
4
|
-
*/
|
|
1
|
+
/** Public API is sourced from the canonical client; the build supplies portable I/O. */
|
|
2
|
+
export * from '../../../src/client/index.js';
|
|
5
3
|
|
|
6
|
-
//
|
|
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';
|
|
4
|
+
// Transport-specific helpers are additive; core client types remain canonical.
|
|
28
5
|
export { Connection } from './connection.js';
|
|
29
6
|
export { ConnectionPool } from './connection-pool.js';
|
|
30
7
|
export type { ConnectionLike } from './connection-types.js';
|
|
@@ -34,19 +11,9 @@ export {
|
|
|
34
11
|
CommandError,
|
|
35
12
|
CommandTimeoutError,
|
|
36
13
|
ConnectionClosedError,
|
|
37
|
-
|
|
14
|
+
SerializationError,
|
|
38
15
|
} from './errors.js';
|
|
39
|
-
export {
|
|
40
|
-
export type {
|
|
41
|
-
FlowJob,
|
|
42
|
-
FlowProducerOptions,
|
|
43
|
-
FlowStep,
|
|
44
|
-
GetFlowOptions,
|
|
45
|
-
JobNode,
|
|
46
|
-
} from './flow-types.js';
|
|
47
|
-
export { MAX_FRAME_SIZE, PROTOCOL_VERSION } from './frame.js';
|
|
48
|
-
export type { JobRaw } from './job.js';
|
|
49
|
-
export { Job } from './job.js';
|
|
16
|
+
export { consoleLogger, noopLogger } from './observability.js';
|
|
50
17
|
export type {
|
|
51
18
|
Logger,
|
|
52
19
|
LogLevel,
|
|
@@ -54,40 +21,5 @@ export type {
|
|
|
54
21
|
TelemetryEvent,
|
|
55
22
|
TelemetryHandler,
|
|
56
23
|
} from './observability.js';
|
|
57
|
-
export {
|
|
58
|
-
export
|
|
59
|
-
export { Queue } from './queue.js';
|
|
60
|
-
export type { SchedulerOptions } from './queue-admin.js';
|
|
61
|
-
export type {
|
|
62
|
-
BatchResponse,
|
|
63
|
-
CountResponse,
|
|
64
|
-
DataResponse,
|
|
65
|
-
JobCountsResponse,
|
|
66
|
-
JobResponse,
|
|
67
|
-
JobsResponse,
|
|
68
|
-
OkResponse,
|
|
69
|
-
PausedResponse,
|
|
70
|
-
ProgressResponse,
|
|
71
|
-
PulledJobResponse,
|
|
72
|
-
PulledJobsResponse,
|
|
73
|
-
ResultResponse,
|
|
74
|
-
StateResponse,
|
|
75
|
-
WaitJobResponse,
|
|
76
|
-
} from './responses.js';
|
|
77
|
-
export type {
|
|
78
|
-
BackoffOptions,
|
|
79
|
-
DeduplicationOptions,
|
|
80
|
-
JobCounts,
|
|
81
|
-
JobOptions,
|
|
82
|
-
JobStateName,
|
|
83
|
-
RepeatOptions,
|
|
84
|
-
} from './types.js';
|
|
85
|
-
export { Worker } from './worker.js';
|
|
86
|
-
export type {
|
|
87
|
-
AckBatchOptions,
|
|
88
|
-
Processor,
|
|
89
|
-
WorkerEventMap,
|
|
90
|
-
WorkerOptions,
|
|
91
|
-
} from './worker-types.js';
|
|
92
|
-
|
|
93
|
-
export const __version__ = '0.1.7';
|
|
24
|
+
export { MAX_FRAME_SIZE, PROTOCOL_VERSION } from './frame.js';
|
|
25
|
+
export const __version__ = '0.2.0';
|
package/src/job.ts
CHANGED
|
@@ -33,19 +33,35 @@ export class Job<T = unknown> {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
get data(): T {
|
|
36
|
-
|
|
36
|
+
const data = this.raw.data;
|
|
37
|
+
if (this.topLevelName() !== undefined) return data as T;
|
|
38
|
+
if (data && typeof data === 'object' && !Array.isArray(data)) {
|
|
39
|
+
const record = data as Record<string, unknown>;
|
|
40
|
+
if (typeof record.name === 'string') {
|
|
41
|
+
const { name: _legacyName, ...userData } = record;
|
|
42
|
+
return userData as T;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return data as T;
|
|
37
46
|
}
|
|
38
47
|
|
|
39
|
-
/** Job name
|
|
48
|
+
/** Job name, with compatibility for pre-name-field data envelopes. */
|
|
40
49
|
get name(): string | undefined {
|
|
50
|
+
const modern = this.topLevelName();
|
|
51
|
+
if (modern !== undefined) return modern;
|
|
41
52
|
const data = this.raw.data;
|
|
42
|
-
if (data && typeof data === 'object' && 'name' in data) {
|
|
53
|
+
if (data && typeof data === 'object' && !Array.isArray(data) && 'name' in data) {
|
|
43
54
|
const name = (data as Record<string, unknown>).name;
|
|
44
|
-
return
|
|
55
|
+
return typeof name === 'string' ? name : undefined;
|
|
45
56
|
}
|
|
46
57
|
return undefined;
|
|
47
58
|
}
|
|
48
59
|
|
|
60
|
+
private topLevelName(): string | undefined {
|
|
61
|
+
const name = this.raw.name;
|
|
62
|
+
return name === undefined || name === null ? undefined : String(name);
|
|
63
|
+
}
|
|
64
|
+
|
|
49
65
|
get priority(): number {
|
|
50
66
|
return Number(this.raw.priority ?? 0);
|
|
51
67
|
}
|
|
@@ -164,16 +180,24 @@ export class Job<T = unknown> {
|
|
|
164
180
|
}
|
|
165
181
|
|
|
166
182
|
async discard(): Promise<void> {
|
|
167
|
-
await this.call({
|
|
183
|
+
await this.call({
|
|
184
|
+
cmd: 'Discard',
|
|
185
|
+
id: this.id,
|
|
186
|
+
...(this.token === undefined ? {} : { token: this.token }),
|
|
187
|
+
});
|
|
168
188
|
}
|
|
169
189
|
|
|
170
190
|
async promote(): Promise<void> {
|
|
171
191
|
await this.call({ cmd: 'Promote', id: this.id });
|
|
172
192
|
}
|
|
173
193
|
|
|
174
|
-
/**
|
|
194
|
+
/** Move the job back to waiting, forwarding a Worker-owned lease when present. */
|
|
175
195
|
async retry(): Promise<void> {
|
|
176
|
-
await this.call({
|
|
196
|
+
await this.call({
|
|
197
|
+
cmd: 'MoveToWait',
|
|
198
|
+
id: this.id,
|
|
199
|
+
...(this.token === undefined ? {} : { token: this.token }),
|
|
200
|
+
});
|
|
177
201
|
}
|
|
178
202
|
|
|
179
203
|
async updateData(data: unknown): Promise<void> {
|
|
@@ -190,10 +214,20 @@ export class Job<T = unknown> {
|
|
|
190
214
|
}
|
|
191
215
|
|
|
192
216
|
async changeDelay(delayMs: number): Promise<void> {
|
|
193
|
-
await this.call({
|
|
217
|
+
await this.call({
|
|
218
|
+
cmd: 'ChangeDelay',
|
|
219
|
+
id: this.id,
|
|
220
|
+
delay: delayMs,
|
|
221
|
+
...(this.token === undefined ? {} : { token: this.token }),
|
|
222
|
+
});
|
|
194
223
|
}
|
|
195
224
|
|
|
196
225
|
async moveToDelayed(delayMs: number): Promise<void> {
|
|
197
|
-
await this.call({
|
|
226
|
+
await this.call({
|
|
227
|
+
cmd: 'MoveToDelayed',
|
|
228
|
+
id: this.id,
|
|
229
|
+
delay: delayMs,
|
|
230
|
+
...(this.token === undefined ? {} : { token: this.token }),
|
|
231
|
+
});
|
|
198
232
|
}
|
|
199
233
|
}
|