@nightx.co/pulsar 0.0.0-stage → 1.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/README.md +14 -2
  2. package/dist/chunk-3sg08kqp.js +10 -0
  3. package/dist/chunk-3sg08kqp.js.map +9 -0
  4. package/dist/chunk-a9kye38b.js +54 -0
  5. package/dist/chunk-a9kye38b.js.map +12 -0
  6. package/dist/chunk-cpn1qh4e.js +10 -0
  7. package/dist/chunk-cpn1qh4e.js.map +12 -0
  8. package/dist/chunk-rrj8rm04.js +10 -0
  9. package/dist/chunk-rrj8rm04.js.map +11 -0
  10. package/dist/cluster/Nebula.d.ts +30 -0
  11. package/dist/cluster/Nebula.d.ts.map +1 -0
  12. package/dist/helpers/computeConfigDelta.d.ts +18 -0
  13. package/dist/helpers/computeConfigDelta.d.ts.map +1 -0
  14. package/dist/helpers/defineQueue.d.ts +13 -0
  15. package/dist/helpers/defineQueue.d.ts.map +1 -0
  16. package/dist/helpers/generateShaHash.d.ts +2 -0
  17. package/dist/helpers/generateShaHash.d.ts.map +1 -0
  18. package/dist/index.d.ts +6 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +8 -0
  21. package/dist/index.js.map +50 -0
  22. package/dist/integrations/PulsarEventsIntegrations.d.ts +7 -0
  23. package/dist/integrations/PulsarEventsIntegrations.d.ts.map +1 -0
  24. package/dist/integrations/PulsarLoggerIntegrations.d.ts +12 -0
  25. package/dist/integrations/PulsarLoggerIntegrations.d.ts.map +1 -0
  26. package/dist/integrations/index.d.ts +4 -0
  27. package/dist/integrations/index.d.ts.map +1 -0
  28. package/dist/integrations/index.js +8 -0
  29. package/dist/integrations/index.js.map +11 -0
  30. package/dist/modules/Queue.module.d.ts +45 -0
  31. package/dist/modules/Queue.module.d.ts.map +1 -0
  32. package/dist/modules/Scheduler.module.d.ts +42 -0
  33. package/dist/modules/Scheduler.module.d.ts.map +1 -0
  34. package/dist/modules/Tick.module.d.ts +35 -0
  35. package/dist/modules/Tick.module.d.ts.map +1 -0
  36. package/dist/modules/TickController.module.d.ts +36 -0
  37. package/dist/modules/TickController.module.d.ts.map +1 -0
  38. package/dist/monitoring/PulsarMonitoringStreamProducer.d.ts +2 -0
  39. package/dist/monitoring/PulsarMonitoringStreamProducer.d.ts.map +1 -0
  40. package/dist/monitoring/index.d.ts +2 -0
  41. package/dist/monitoring/index.d.ts.map +1 -0
  42. package/dist/monitoring/server/PulsarMonitoringStream.d.ts +2 -0
  43. package/dist/monitoring/server/PulsarMonitoringStream.d.ts.map +1 -0
  44. package/dist/network/NetworkInterface.d.ts +13 -0
  45. package/dist/network/NetworkInterface.d.ts.map +1 -0
  46. package/dist/network/UnifiedTransportManager.d.ts +21 -0
  47. package/dist/network/UnifiedTransportManager.d.ts.map +1 -0
  48. package/dist/network/abstract/BaseNetworkDriver.d.ts +17 -0
  49. package/dist/network/abstract/BaseNetworkDriver.d.ts.map +1 -0
  50. package/dist/network/auth/Authenticator.d.ts +2 -0
  51. package/dist/network/auth/Authenticator.d.ts.map +1 -0
  52. package/dist/network/drivers/HttpNetworkDriver.d.ts +31 -0
  53. package/dist/network/drivers/HttpNetworkDriver.d.ts.map +1 -0
  54. package/dist/network/drivers/WebSocketNetworkDriver.d.ts +23 -0
  55. package/dist/network/drivers/WebSocketNetworkDriver.d.ts.map +1 -0
  56. package/dist/network/helpers/httpQueueOperations.d.ts +2 -0
  57. package/dist/network/helpers/httpQueueOperations.d.ts.map +1 -0
  58. package/dist/network/interfaces/network.types.d.ts +13 -0
  59. package/dist/network/interfaces/network.types.d.ts.map +1 -0
  60. package/dist/run/Queues.d.ts +2 -0
  61. package/dist/run/Queues.d.ts.map +1 -0
  62. package/dist/run/index.d.ts +2 -0
  63. package/dist/run/index.d.ts.map +1 -0
  64. package/dist/run/index2.d.ts +2 -0
  65. package/dist/run/index2.d.ts.map +1 -0
  66. package/dist/runtimes/IsolateRuntime.d.ts +17 -0
  67. package/dist/runtimes/IsolateRuntime.d.ts.map +1 -0
  68. package/dist/runtimes/PersistentRuntime.d.ts +22 -0
  69. package/dist/runtimes/PersistentRuntime.d.ts.map +1 -0
  70. package/dist/runtimes/ServerlessRuntime.d.ts +15 -0
  71. package/dist/runtimes/ServerlessRuntime.d.ts.map +1 -0
  72. package/dist/runtimes/runtimeTypes.d.ts +15 -0
  73. package/dist/runtimes/runtimeTypes.d.ts.map +1 -0
  74. package/dist/server/PulsarRequestHandler.d.ts +41 -0
  75. package/dist/server/PulsarRequestHandler.d.ts.map +1 -0
  76. package/dist/server/helpers/acquireRedisLock.d.ts +14 -0
  77. package/dist/server/helpers/acquireRedisLock.d.ts.map +1 -0
  78. package/dist/server/helpers/checkFencingValidity.d.ts +14 -0
  79. package/dist/server/helpers/checkFencingValidity.d.ts.map +1 -0
  80. package/dist/server/helpers/performIsolateRestart.d.ts +20 -0
  81. package/dist/server/helpers/performIsolateRestart.d.ts.map +1 -0
  82. package/dist/server/index.d.ts +2 -0
  83. package/dist/server/index.d.ts.map +1 -0
  84. package/dist/server/index.js +8 -0
  85. package/dist/server/index.js.map +13 -0
  86. package/dist/server/parser/parseRequest.d.ts +10 -0
  87. package/dist/server/parser/parseRequest.d.ts.map +1 -0
  88. package/dist/server/utility/extract-headers.d.ts +14 -0
  89. package/dist/server/utility/extract-headers.d.ts.map +1 -0
  90. package/dist/service/ConfigurationStore.d.ts +23 -0
  91. package/dist/service/ConfigurationStore.d.ts.map +1 -0
  92. package/dist/service/Isolate.service.d.ts +12 -0
  93. package/dist/service/Isolate.service.d.ts.map +1 -0
  94. package/dist/service/Pulsar.service.d.ts +41 -0
  95. package/dist/service/Pulsar.service.d.ts.map +1 -0
  96. package/dist/service/PulsarBaseService.d.ts +49 -0
  97. package/dist/service/PulsarBaseService.d.ts.map +1 -0
  98. package/dist/service/PulsarEventBus.d.ts +36 -0
  99. package/dist/service/PulsarEventBus.d.ts.map +1 -0
  100. package/dist/service/SwarmBudgetTracker.d.ts +14 -0
  101. package/dist/service/SwarmBudgetTracker.d.ts.map +1 -0
  102. package/dist/service/consumers/PulsarWorker.d.ts +10 -0
  103. package/dist/service/consumers/PulsarWorker.d.ts.map +1 -0
  104. package/dist/shared/PulsarRuntimeCore.d.ts +55 -0
  105. package/dist/shared/PulsarRuntimeCore.d.ts.map +1 -0
  106. package/dist/static/TimingProfile.d.ts +9 -0
  107. package/dist/static/TimingProfile.d.ts.map +1 -0
  108. package/dist/static/static.d.ts +3 -0
  109. package/dist/static/static.d.ts.map +1 -0
  110. package/dist/storage/PulsarStorage.d.ts +42 -0
  111. package/dist/storage/PulsarStorage.d.ts.map +1 -0
  112. package/dist/storage/drivers/PostgresDriver.d.ts +20 -0
  113. package/dist/storage/drivers/PostgresDriver.d.ts.map +1 -0
  114. package/dist/storage/drivers/RedisDriver.d.ts +20 -0
  115. package/dist/storage/drivers/RedisDriver.d.ts.map +1 -0
  116. package/dist/storage/drivers/types.d.ts +27 -0
  117. package/dist/storage/drivers/types.d.ts.map +1 -0
  118. package/dist/storage/index.d.ts +4 -0
  119. package/dist/storage/index.d.ts.map +1 -0
  120. package/dist/storage/index.js +403 -0
  121. package/dist/storage/index.js.map +21 -0
  122. package/dist/storage/repositories/PostgresEngineOperationRepository.d.ts +39 -0
  123. package/dist/storage/repositories/PostgresEngineOperationRepository.d.ts.map +1 -0
  124. package/dist/storage/repositories/PostgresQueueRepository.d.ts +26 -0
  125. package/dist/storage/repositories/PostgresQueueRepository.d.ts.map +1 -0
  126. package/dist/storage/repositories/QueueRepository.d.ts +20 -0
  127. package/dist/storage/repositories/QueueRepository.d.ts.map +1 -0
  128. package/dist/storage/repositories/RedisQueueRepository.d.ts +28 -0
  129. package/dist/storage/repositories/RedisQueueRepository.d.ts.map +1 -0
  130. package/dist/subsys/DeferredTickEvaluator.d.ts +23 -0
  131. package/dist/subsys/DeferredTickEvaluator.d.ts.map +1 -0
  132. package/dist/subsys/EventBus.d.ts +13 -0
  133. package/dist/subsys/EventBus.d.ts.map +1 -0
  134. package/dist/subsys/ExecutionProfileSwitcher.d.ts +10 -0
  135. package/dist/subsys/ExecutionProfileSwitcher.d.ts.map +1 -0
  136. package/dist/subsys/LoggerService.d.ts +15 -0
  137. package/dist/subsys/LoggerService.d.ts.map +1 -0
  138. package/dist/subsys/PulsarClock.d.ts +32 -0
  139. package/dist/subsys/PulsarClock.d.ts.map +1 -0
  140. package/dist/subsys/RuntimeCacheStorage.d.ts +18 -0
  141. package/dist/subsys/RuntimeCacheStorage.d.ts.map +1 -0
  142. package/dist/subsys/RuntimeEventBridge.d.ts +16 -0
  143. package/dist/subsys/RuntimeEventBridge.d.ts.map +1 -0
  144. package/dist/types/base.types.d.ts +65 -0
  145. package/dist/types/base.types.d.ts.map +1 -0
  146. package/dist/types/config.types.d.ts +56 -0
  147. package/dist/types/config.types.d.ts.map +1 -0
  148. package/dist/types/consumer.types.d.ts +36 -0
  149. package/dist/types/consumer.types.d.ts.map +1 -0
  150. package/dist/types/engine.types.d.ts +139 -0
  151. package/dist/types/engine.types.d.ts.map +1 -0
  152. package/dist/types/eventTriggerStrategry.types.d.ts +34 -0
  153. package/dist/types/eventTriggerStrategry.types.d.ts.map +1 -0
  154. package/dist/types/integrations.types.d.ts +16 -0
  155. package/dist/types/integrations.types.d.ts.map +1 -0
  156. package/dist/types/nebula.types.d.ts +65 -0
  157. package/dist/types/nebula.types.d.ts.map +1 -0
  158. package/dist/types/queue.types.d.ts +106 -0
  159. package/dist/types/queue.types.d.ts.map +1 -0
  160. package/dist/types/runtime.types.d.ts +89 -0
  161. package/dist/types/runtime.types.d.ts.map +1 -0
  162. package/package.json +71 -5
@@ -0,0 +1,34 @@
1
+ export declare enum EventTriggerStrategy {
2
+ /**
3
+ * Uses PostgreSQL LISTEN/NOTIFY (PG Notify) for real-time event-driven queue triggering.
4
+ *
5
+ * **How it works:** The engine establishes a persistent subscription to a database channel.
6
+ * When an event occurs, Postgres broadcasts an instant notification, triggering the queues
7
+ * immediately with minimal latency and zero polling overhead.
8
+ *
9
+ * **Crucial Infrastructure Requirement:** This strategy **requires a direct, persistent TCP
10
+ * connection URL** provided to the Postgres driver. If your database infrastructure uses serverless
11
+ * proxies, restricted connection pools, or environments that do not support long-lived TCP socket
12
+ * listeners (LISTEN/NOTIFY state), this strategy will fail to receive events.
13
+ */
14
+ POSTGRES_NOTIFY = "POSTGRES_NOTIFY",
15
+ /**
16
+ * Uses an external HTTP webhook driven directly by the database (`pg_net`).
17
+ *
18
+ * **How it works:** This strategy requires an accessible HTTP endpoint to be exposed on the
19
+ * running container or machine. When an event occurs, Postgres utilizes the built-in `pg_net`
20
+ * extension to fire an outbound HTTP request directly to this endpoint, which in turn invokes
21
+ * and executes the event-driven queues.
22
+ */
23
+ WEBHOOK = "WEBHOOK",
24
+ /**
25
+ * Uses a database-backed table polling mechanism.
26
+ *
27
+ * **How it works:** Completely independent of persistent TCP notification sockets or HTTP
28
+ * endpoints. Instead, event producers insert new task rows directly into a designated
29
+ * subscription table. The engine periodically polls this table at a configured interval
30
+ * (e.g., every 500ms) to scan for new rows, process them, and trigger the respective queues.
31
+ */
32
+ POLLING = "POLLING"
33
+ }
34
+ //# sourceMappingURL=eventTriggerStrategry.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eventTriggerStrategry.types.d.ts","sourceRoot":"","sources":["../../src/types/eventTriggerStrategry.types.ts"],"names":[],"mappings":"AAAA,oBAAY,oBAAoB;IAC5B;;;;;;;;;;;OAWG;IACH,eAAe,oBAAoB;IAEnC;;;;;;;OAOG;IACH,OAAO,YAAY;IAEnB;;;;;;;OAOG;IACH,OAAO,YAAY;CACtB"}
@@ -0,0 +1,16 @@
1
+ import type { PulsarEventsIntegrations, PulsarLoggerIntegrations } from "../integrations";
2
+ import type { PulsarCore } from "../service/PulsarBaseService";
3
+ export interface IIntegration {
4
+ module: "API" | "EVENTS" | "LOGGER";
5
+ main: (engine: PulsarCore) => Promise<void>;
6
+ }
7
+ export interface IntegrationMap {
8
+ LOGGER: PulsarLoggerIntegrations;
9
+ API: any;
10
+ EVENTS: PulsarEventsIntegrations;
11
+ }
12
+ export type IntegrationConstructor = new (access: string) => IIntegration;
13
+ export interface HostOptions {
14
+ integrations?: Array<IntegrationConstructor | IIntegration>;
15
+ }
16
+ //# sourceMappingURL=integrations.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integrations.types.d.ts","sourceRoot":"","sources":["../../src/types/integrations.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC1F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE/D,MAAM,WAAW,YAAY;IACzB,MAAM,EAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACrC,IAAI,EAAE,CAAC,MAAM,EAAG,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD;AAED,MAAM,WAAW,cAAc;IAC3B,MAAM,EAAG,wBAAwB,CAAC;IAClC,GAAG,EAAG,GAAG,CAAC;IACV,MAAM,EAAG,wBAAwB,CAAC;CACrC;AAED,MAAM,MAAM,sBAAsB,GAAG,KAAK,MAAM,EAAE,MAAM,KAAK,YAAY,CAAC;AAE1E,MAAM,WAAW,WAAW;IACxB,YAAY,CAAC,EAAG,KAAK,CAAC,sBAAsB,GAAG,YAAY,CAAC,CAAC;CAChE"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Operating execution mode for a Pulsar engine instance inside a Nebula cluster.
3
+ * Determines how the node handles global dynamic job spills versus dedicated queues.
4
+ */
5
+ export type NebulaExecutionMode = 'exclusive' | 'shared' | 'hybrid';
6
+ /**
7
+ * Connection transport strategy to communicate with the Nebula Control Plane.
8
+ * Supports multiple backends for high-availability cluster state synchronization.
9
+ */
10
+ export interface NebulaConnectionConfig {
11
+ /** Target endpoint for HTTP/REST/RPC handshakes (e.g. VPS URL, Edge worker API) */
12
+ endpoint?: string;
13
+ /** Direct client connection for Redis-backed Nebula cluster state */
14
+ redisUrl?: string;
15
+ /** Direct DB client configuration for Postgres-backed cluster state */
16
+ postgresUrl?: string;
17
+ /** Bearer token or cluster secret key for engine-to-control-plane authentication */
18
+ authToken?: string;
19
+ /** Maximum timeout in milliseconds for control plane handshakes */
20
+ timeoutMs?: number;
21
+ }
22
+ /**
23
+ * Heartbeat, lease management, and health-reporting policy for this engine instance.
24
+ * Ensures orphaned workers are automatically reaped and locks are safely revoked.
25
+ */
26
+ export interface NebulaHealthConfig {
27
+ /** Interval in milliseconds between heartbeat pings back to Nebula */
28
+ heartbeatIntervalMs: number;
29
+ /** Time-to-live for the instance lease in the central state store (seconds) */
30
+ leaseTtlSec: number;
31
+ /** Enable automatic lease revocation when the V8 isolate nears execution deadline */
32
+ revokeOnIsolateDeath: boolean;
33
+ }
34
+ /**
35
+ * Main Nebula configuration interface embedded directly in PulsarEngine setup.
36
+ * Coordinates static worker code registries with Nebula's dynamic control plane routing.
37
+ */
38
+ export interface NebulaClusterConfig {
39
+ enabled: boolean;
40
+ /** Cluster name or prefix namespace to isolate environments (e.g. 'prod-eu-1') */
41
+ clusterId: string;
42
+ /**
43
+ * Defines whether this engine instance operates as an exclusive, shared, or hybrid process
44
+ * within the Nebula cluster, controlling how queues are assigned during handshakes:
45
+ * - **'exclusive'**: Locks the instance strictly to its pre-configured static queues (e.g., `q1`, `q2`).
46
+ * Even during high traffic or load spikes, Nebula will never route any other queues to this instance.
47
+ * - **'shared'**: Allows Nebula to dynamically allocate any queues supported by this instance's
48
+ * partition based on current cluster load, backlogs, and scheduling algorithms.
49
+ * - **'hybrid'**: Maintains primary dedicated queue assignments while permitting the node to absorb
50
+ * fallback spillover capacity and overflow traffic whenever resources are idle.
51
+ */
52
+ assignmentScope: NebulaExecutionMode;
53
+ /** Transport configuration for communicating with Nebula */
54
+ connection: NebulaConnectionConfig;
55
+ /** Health check, lease TTL, and heartbeat options */
56
+ health: NebulaHealthConfig;
57
+ /**
58
+ * Strict queue allocation safety guard.
59
+ * If true, throws an error if local static queue configuration collides
60
+ * with assigned Nebula remote queues on startup.
61
+ */
62
+ strictIsolation?: boolean;
63
+ supportedPartitions?: string[];
64
+ }
65
+ //# sourceMappingURL=nebula.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nebula.types.d.ts","sourceRoot":"","sources":["../../src/types/nebula.types.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAC3B,WAAW,GACX,QAAQ,GACR,QAAQ,CAAC;AAEb;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACnC,mFAAmF;IACnF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qEAAqE;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uEAAuE;IACvE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oFAAoF;IACpF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mEAAmE;IACnE,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IAC/B,sEAAsE;IACtE,mBAAmB,EAAE,MAAM,CAAC;IAE5B,+EAA+E;IAC/E,WAAW,EAAE,MAAM,CAAC;IAEpB,qFAAqF;IACrF,oBAAoB,EAAE,OAAO,CAAC;CACjC;AAGD;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAChC,OAAO,EAAG,OAAO,CAAC;IAElB,kFAAkF;IAClF,SAAS,EAAE,MAAM,CAAC;IAElB;;;;;;;;;OASG;IACH,eAAe,EAAE,mBAAmB,CAAC;IAErC,4DAA4D;IAC5D,UAAU,EAAE,sBAAsB,CAAC;IAEnC,qDAAqD;IACrD,MAAM,EAAE,kBAAkB,CAAC;IAE3B;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B,mBAAmB,CAAC,EAAG,MAAM,EAAE,CAAC;CACnC"}
@@ -0,0 +1,106 @@
1
+ import type { TimingProfile, TimingProfileType } from "../static/TimingProfile.d.ts";
2
+ import type { EnginePoolingMode } from "./engine.types.d.ts";
3
+ export type EngineQueuesConfig = {
4
+ queue: string;
5
+ /**
6
+ * Configures the execution cadence and polling intervals for this queue.
7
+ *
8
+ * Accepts a predefined preset (`'REALTIME'`, `'STANDARD'`, `'BALANCED'`, `'RELAXED'`, `'ULTRA_EFFICIENT'`)
9
+ * or a custom `TimingProfile` object to fine-tune active, backoff, and idle delays.
10
+ *
11
+ * @default 'STANDARD'
12
+ */
13
+ profile: TimingProfileType | TimingProfile;
14
+ /**
15
+ * Controls how the queue pulls work from storage.
16
+ *
17
+ * - `'interval-driven-pooler'`: For steady, predictable background workloads that need ongoing processing.
18
+ * - `'event-driven-pooler'`: For instant processing of sporadic or bursty jobs while keeping idle execution costs at zero.
19
+ *
20
+ * @default 'interval-driven-pooler'
21
+ */
22
+ pooler: EnginePoolingMode;
23
+ /** */
24
+ type: "fifo" | "STANDER";
25
+ /**
26
+ * Maximum concurrent worker instances allowed for this queue.
27
+ *
28
+ * @warning High concurrency increases parallel connections, I/O operations, and resource contention on the database and storage layer.
29
+ */
30
+ concurrency: number;
31
+ /** Number of jobs assigned per worker batch */
32
+ n: number;
33
+ /**
34
+ * Maximum aggregate jobs the engine can fetch in a single tick loop.
35
+ * If (concurrency * n) > maxJobsPerTick, active workers will be scaled
36
+ * down automatically to satisfy this limit (Backpressure throttling).
37
+ */
38
+ maxJobsPerTick?: number;
39
+ /**
40
+ * Defines the tick budget (quantum) allocated to this isolate. Once the tick count
41
+ * reaches this threshold, the engine marks the isolate's execution cycle as completed.
42
+ *
43
+ * @default 10
44
+ *
45
+ * @warning Do not set `cycleTickLimit` higher than 20 per queue, especially when running multiple queues.
46
+ * High tick limits keep execution pinned to the same serverless instance, escalating the risk
47
+ * of hitting total execution timeouts (e.g., AWS Lambda, Vercel, or Cloudflare Workers limits).
48
+ */
49
+ cycleTickLimit?: number;
50
+ sleep?: number;
51
+ /**
52
+ * Rules for automatically switching queue performance modes based on active workload.
53
+ *
54
+ * When a queue experiences sustained inactivity, the engine automatically transitions it
55
+ * into an idle state. This significantly reduces database read operations, lowers API and
56
+ * storage costs, and minimizes unnecessary CPU and network utilization during quiet periods.
57
+ *
58
+ * As soon as new jobs are detected, the engine instantly transitions back and restores
59
+ * the queue's original active timing profile without manual intervention or job delivery latency.
60
+ *
61
+ */
62
+ stateTransitionPolicy?: {
63
+ /**
64
+ * Whether automatic state switching is active for this queue.
65
+ *
66
+ * @default true
67
+ */
68
+ enabled?: boolean;
69
+ /**
70
+ * Number of consecutive empty ticks required before the engine transitions into idle mode for this queue.
71
+ *
72
+ * @default 10
73
+ */
74
+ idleThresholdTicks?: number;
75
+ /**
76
+ * The timing profile or custom interval object applied when the queue enters idle mode.
77
+ *
78
+ * Accepts a predefined preset (`RELAXED`, `ULTRA_EFFICIENT`) or a custom `TimingProfile`.
79
+ *
80
+ * maxTimerMs will be ignored
81
+ *
82
+ * @default 'RELAXED'
83
+ */
84
+ idleTimingProfile?: TimingProfileType | TimingProfile;
85
+ };
86
+ /**
87
+ * Defines how and when the Pulsar engine evaluates external cancellation or stop signals
88
+ * sent by an external system to halt a running tick process.
89
+ *
90
+ * - `tick`: Evaluates the stop signal on every single atomic tick iteration (immediate intervention).
91
+ * - `cycle`: Evaluates the stop signal only at the completion of a batch cycle (deferred intervention).
92
+ * - `inherit`: Inherits the default policy from the global engine configuration.
93
+ *
94
+ * @default "inherit"
95
+ */
96
+ interventionPolicy?: "tick" | "cycle" | "inherit";
97
+ deadLetterQueue?: string;
98
+ };
99
+ export type QueueMessage<T = unknown> = {
100
+ msg_id: number;
101
+ read_ct: number;
102
+ enqueued_at: Date;
103
+ vt: Date;
104
+ message: T;
105
+ };
106
+ //# sourceMappingURL=queue.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.types.d.ts","sourceRoot":"","sources":["../../src/types/queue.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EA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/interfaces/network.types.d.ts";
3
+ import type { BaseEngineConfig } from "./base.types.d.ts";
4
+ import type { PersistentEngine, SelfInvokingEngine } from "./engine.types.d.ts";
5
+ import type { EventTriggerStrategy } from "./eventTriggerStrategry.types.d.ts";
6
+ /**
7
+ * Supported runtime execution environments for Pulsar.
8
+ */
9
+ export declare enum PulsarRuntime {
10
+ /**
11
+ * Configuration for ephemeral V8 isolate environments (Cloudflare Workers, Supabase Edge, Deno Deploy).
12
+ *
13
+ * In V8 isolate platforms, incoming requests share the same warm memory space until the isolate shuts down.
14
+ * The engine relies on the required `isolate` instance to monitor remaining isolate lifespan, handle dynamic global
15
+ * state, and sync tick schedules before the V8 isolate gets terminated by the cloud provider.
16
+ */
17
+ V8_ISOLATE = "v8-isolate",
18
+ /**
19
+ * Configuration for containerized or persistent runtime environments (AWS Lambda, GCP Cloud Run, Docker, Node.js VMs).
20
+ *
21
+ * Unlike V8 isolates, these environments operate in dedicated process/container sandboxes with predictable execution limits
22
+ * or persistent process lifetimes. Tracking V8 isolate memory and remaining uptime across HTTP invocations is not strictly required.
23
+ */
24
+ SERVERLESS_VM = "serverless-vm",
25
+ /**
26
+ * Configuration for traditional, long-running persistent environments (AWS EC2, VPS, Dedicated Servers, local Node.js processes).
27
+ *
28
+ * Unlike ephemeral isolates or serverless containers that spin down between invocations, persistent runtimes maintain an uninterrupted
29
+ * execution context and continuous process lifespan. The engine can rely on background event loops, stateful in-memory caching,
30
+ * and non-ephemeral scheduling without relying on cloud provider lifecycle hooks.
31
+ */
32
+ PERSISTENT = "persistent"
33
+ }
34
+ export type PulsarRuntimeType = typeof PulsarRuntime[keyof typeof PulsarRuntime];
35
+ export type ConfigForRuntime<T extends PulsarRuntimeType> = T extends typeof PulsarRuntime.V8_ISOLATE ? V8IsolateConfig : T extends typeof PulsarRuntime.SERVERLESS_VM ? ServerlessVMConfig : PersistentConfig;
36
+ export type V8IsolateConfig = BaseEngineConfig & {
37
+ runtime: typeof PulsarRuntime.V8_ISOLATE;
38
+ engine: SelfInvokingEngine;
39
+ /**
40
+ * Active isolate tracking instance.
41
+ */
42
+ isolate: IsolateInstance;
43
+ };
44
+ export type ServerlessVMConfig = BaseEngineConfig & {
45
+ runtime: typeof PulsarRuntime.SERVERLESS_VM;
46
+ engine: SelfInvokingEngine;
47
+ /**
48
+ * Optional isolate tracking instance if custom lifecycle tracking is desired inside Lambda or containerized workers.
49
+ */
50
+ isolate?: IsolateInstance;
51
+ };
52
+ export type PersistentConfig = BaseEngineConfig & {
53
+ runtime: typeof PulsarRuntime.PERSISTENT;
54
+ /**
55
+ * Optional isolate tracking instance if custom lifecycle tracking is desired inside Lambda or containerized workers.
56
+ */
57
+ isolate?: IsolateInstance;
58
+ networkInterface: {
59
+ /**
60
+ * Determines the operational network mode of the server.
61
+ *
62
+ * - `http`: Opens an HTTP server. Crucial for consumers running dependent workers
63
+ * (e.g., when a consumer cannot initialize local storage configuration directly).
64
+ * Dependent workers use this HTTP server for acks, retries, etc.
65
+ * *(Note: This mode introduces latency and throughput limitations).*
66
+ *
67
+ * - `socket`: Opens a WebSocket server. Both the pulsar and consumers connect to
68
+ * this socket to transport and dispatch jobs. Provides near-realtime job dispatch
69
+ * performance for workers.
70
+ *
71
+ * - `hybrid`: Opens both HTTP and WebSocket servers simultaneously. Ideal for
72
+ * multi-runtime deployed consumers where some instances operate in serverless
73
+ * functions and others on a VPS, allowing each consumer to select its optimal
74
+ * server option based on its specific configuration.
75
+ */
76
+ mode: Exclude<NetworkConfig["mode"], "client">;
77
+ /**
78
+ * The port number on which the server instance will listen for incoming traffic.
79
+ */
80
+ port: NetworkConfig["port"];
81
+ /**
82
+ * Optional hostname or IP address to bind the server to.
83
+ */
84
+ host?: NetworkConfig["host"];
85
+ };
86
+ eventTriggerStrategy: typeof EventTriggerStrategy[keyof typeof EventTriggerStrategy];
87
+ engine: PersistentEngine;
88
+ };
89
+ //# sourceMappingURL=runtime.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.types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,CAAC;IAE1C;;MAEE;IACF,OAAO,CAAC,EAAG,eAAe,CAAC;IAE3B,gBAAgB,EAAG;QACf;;;;;;;;;;;;;;;;UAgBE;QACF,IAAI,EAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,CAAC;QAChD;;UAEE;QACF,IAAI,EAAG,aAAa,CAAC,MAAM,CAAC,CAAC;QAC7B;;UAEE;QACF,IAAI,CAAC,EAAG,aAAa,CAAC,MAAM,CAAC,CAAC;KACjC,CAAA;IAED,oBAAoB,EAAG,OAAO,oBAAoB,CAAC,MAAM,OAAO,oBAAoB,CAAC,CAAC;IACtF,MAAM,EAAG,gBAAgB,CAAC;CAC7B,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,72 @@
1
1
  {
2
- "name": "@nightx.co/pulsar",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@nightx.co/pulsar",
3
+ "version": "1.0.15",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "module": "index.ts",
7
+ "types": "./dist/index.d.ts",
8
+ "private": false,
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "./helpers": {
16
+ "types": "./dist/helpers/index.d.ts",
17
+ "import": "./dist/helpers/index.js",
18
+ "default": "./dist/helpers/index.js"
19
+ },
20
+ "./integrations": {
21
+ "types": "./dist/integrations/index.d.ts",
22
+ "import": "./dist/integrations/index.js",
23
+ "default": "./dist/integrations/index.js"
24
+ },
25
+ "./server": {
26
+ "types": "./dist/server/index.d.ts",
27
+ "import": "./dist/server/index.js",
28
+ "default": "./dist/server/index.js"
29
+ },
30
+ "./storage": {
31
+ "types": "./dist/storage/index.d.ts",
32
+ "import": "./dist/storage/index.js",
33
+ "default": "./dist/storage/index.js"
34
+ }
35
+ },
36
+ "typesVersions": {
37
+ "*": {
38
+ "storage": [
39
+ "./dist/storage/index.d.ts"
40
+ ],
41
+ "server": [
42
+ "./dist/server/index.d.ts"
43
+ ],
44
+ "integrations": [
45
+ "./dist/integrations/index.d.ts"
46
+ ]
47
+ }
48
+ },
49
+ "files": [
50
+ "dist"
51
+ ],
52
+ "scripts": {
53
+ "build": "bun run build.ts;",
54
+ "dev": "bun --preload ./lua-plugin.ts src/run/index.ts"
55
+ },
56
+ "devDependencies": {
57
+ "@types/bun": "latest"
58
+ },
59
+ "peerDependencies": {
60
+ "typescript": "^5"
61
+ },
62
+ "dependencies": {
63
+ "@msgpack/msgpack": "^3.1.3",
64
+ "@upstash/redis": "^1.39.0",
65
+ "crossws": "^0.4.16",
66
+ "eventemitter3": "^5.0.4",
67
+ "ioredis": "^6.0.0",
68
+ "js-sha256": "^1.0.0",
69
+ "postgres": "^3.4.9",
70
+ "srvx": "^1.0.7"
71
+ }
72
+ }