@powerhousedao/reactor 4.1.0-staging.1 → 5.0.0-staging.10

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 (147) hide show
  1. package/dist/bench/event-bus.bench.js +17 -27
  2. package/dist/bench/event-bus.bench.js.map +1 -1
  3. package/dist/bench/queue-only.bench.js +8 -2
  4. package/dist/bench/queue-only.bench.js.map +1 -1
  5. package/dist/bench/reactor-throughput.bench.js +42 -35
  6. package/dist/bench/reactor-throughput.bench.js.map +1 -1
  7. package/dist/src/events/event-bus.d.ts +3 -3
  8. package/dist/src/events/event-bus.d.ts.map +1 -1
  9. package/dist/src/events/event-bus.js.map +1 -1
  10. package/dist/src/events/interfaces.d.ts +1 -1
  11. package/dist/src/events/interfaces.d.ts.map +1 -1
  12. package/dist/src/events/types.d.ts +1 -1
  13. package/dist/src/events/types.d.ts.map +1 -1
  14. package/dist/src/events/types.js.map +1 -1
  15. package/dist/src/executor/interfaces.d.ts +31 -54
  16. package/dist/src/executor/interfaces.d.ts.map +1 -1
  17. package/dist/src/executor/simple-job-executor-manager.d.ts +27 -0
  18. package/dist/src/executor/simple-job-executor-manager.d.ts.map +1 -0
  19. package/dist/src/executor/simple-job-executor-manager.js +128 -0
  20. package/dist/src/executor/simple-job-executor-manager.js.map +1 -0
  21. package/dist/src/executor/simple-job-executor.d.ts +19 -0
  22. package/dist/src/executor/simple-job-executor.d.ts.map +1 -0
  23. package/dist/src/executor/simple-job-executor.js +69 -0
  24. package/dist/src/executor/simple-job-executor.js.map +1 -0
  25. package/dist/src/executor/types.d.ts +23 -8
  26. package/dist/src/executor/types.d.ts.map +1 -1
  27. package/dist/src/executor/types.js.map +1 -1
  28. package/dist/src/index.d.ts +9 -2
  29. package/dist/src/index.d.ts.map +1 -1
  30. package/dist/src/index.js +8 -2
  31. package/dist/src/index.js.map +1 -1
  32. package/dist/src/interfaces/reactor.d.ts +121 -0
  33. package/dist/src/interfaces/reactor.d.ts.map +1 -0
  34. package/dist/src/interfaces/reactor.js +2 -0
  35. package/dist/src/interfaces/reactor.js.map +1 -0
  36. package/dist/src/queue/interfaces.d.ts +45 -5
  37. package/dist/src/queue/interfaces.d.ts.map +1 -1
  38. package/dist/src/queue/job-execution-handle.d.ts +24 -0
  39. package/dist/src/queue/job-execution-handle.d.ts.map +1 -0
  40. package/dist/src/queue/job-execution-handle.js +62 -0
  41. package/dist/src/queue/job-execution-handle.js.map +1 -0
  42. package/dist/src/queue/queue.d.ts +54 -5
  43. package/dist/src/queue/queue.d.ts.map +1 -1
  44. package/dist/src/queue/queue.js +237 -23
  45. package/dist/src/queue/queue.js.map +1 -1
  46. package/dist/src/queue/types.d.ts +26 -1
  47. package/dist/src/queue/types.d.ts.map +1 -1
  48. package/dist/src/queue/types.js +12 -0
  49. package/dist/src/queue/types.js.map +1 -1
  50. package/dist/src/reactor.d.ts +100 -0
  51. package/dist/src/reactor.d.ts.map +1 -0
  52. package/dist/src/reactor.js +591 -0
  53. package/dist/src/reactor.js.map +1 -0
  54. package/dist/src/registry/implementation.d.ts +62 -0
  55. package/dist/src/registry/implementation.d.ts.map +1 -0
  56. package/dist/src/registry/implementation.js +96 -0
  57. package/dist/src/registry/implementation.js.map +1 -0
  58. package/dist/src/registry/index.d.ts +3 -0
  59. package/dist/src/registry/index.d.ts.map +1 -0
  60. package/dist/src/registry/index.js +2 -0
  61. package/dist/src/registry/index.js.map +1 -0
  62. package/dist/src/registry/interfaces.d.ts +39 -0
  63. package/dist/src/registry/interfaces.d.ts.map +1 -0
  64. package/dist/src/registry/interfaces.js +2 -0
  65. package/dist/src/registry/interfaces.js.map +1 -0
  66. package/dist/src/shared/factories.d.ts +16 -0
  67. package/dist/src/shared/factories.d.ts.map +1 -0
  68. package/dist/src/shared/factories.js +33 -0
  69. package/dist/src/shared/factories.js.map +1 -0
  70. package/dist/src/shared/types.d.ts +83 -19
  71. package/dist/src/shared/types.d.ts.map +1 -1
  72. package/dist/src/shared/types.js +30 -1
  73. package/dist/src/shared/types.js.map +1 -1
  74. package/dist/src/shared/utils.d.ts +3 -0
  75. package/dist/src/shared/utils.d.ts.map +1 -0
  76. package/dist/src/shared/utils.js +8 -0
  77. package/dist/src/shared/utils.js.map +1 -0
  78. package/dist/src/utils.d.ts +11 -0
  79. package/dist/src/utils.d.ts.map +1 -0
  80. package/dist/src/utils.js +31 -0
  81. package/dist/src/utils.js.map +1 -0
  82. package/dist/test/event-bus.test.js +19 -10
  83. package/dist/test/event-bus.test.js.map +1 -1
  84. package/dist/test/executor/executor-integration.test.d.ts +2 -0
  85. package/dist/test/executor/executor-integration.test.d.ts.map +1 -0
  86. package/dist/test/executor/executor-integration.test.js +287 -0
  87. package/dist/test/executor/executor-integration.test.js.map +1 -0
  88. package/dist/test/executor/job-execution-handle.test.d.ts +2 -0
  89. package/dist/test/executor/job-execution-handle.test.d.ts.map +1 -0
  90. package/dist/test/executor/job-execution-handle.test.js +272 -0
  91. package/dist/test/executor/job-execution-handle.test.js.map +1 -0
  92. package/dist/test/executor/simple-job-executor-manager.test.d.ts +2 -0
  93. package/dist/test/executor/simple-job-executor-manager.test.d.ts.map +1 -0
  94. package/dist/test/executor/simple-job-executor-manager.test.js +132 -0
  95. package/dist/test/executor/simple-job-executor-manager.test.js.map +1 -0
  96. package/dist/test/executor/simple-job-executor.test.d.ts +2 -0
  97. package/dist/test/executor/simple-job-executor.test.d.ts.map +1 -0
  98. package/dist/test/executor/simple-job-executor.test.js +139 -0
  99. package/dist/test/executor/simple-job-executor.test.js.map +1 -0
  100. package/dist/test/factories.d.ts +123 -0
  101. package/dist/test/factories.d.ts.map +1 -0
  102. package/dist/test/factories.js +319 -0
  103. package/dist/test/factories.js.map +1 -0
  104. package/dist/test/integration/document-drive-integration.test.d.ts +2 -0
  105. package/dist/test/integration/document-drive-integration.test.d.ts.map +1 -0
  106. package/dist/test/integration/document-drive-integration.test.js +1102 -0
  107. package/dist/test/integration/document-drive-integration.test.js.map +1 -0
  108. package/dist/test/integration/reactor-read.test.d.ts +2 -0
  109. package/dist/test/integration/reactor-read.test.d.ts.map +1 -0
  110. package/dist/test/integration/reactor-read.test.js +291 -0
  111. package/dist/test/integration/reactor-read.test.js.map +1 -0
  112. package/dist/test/queue/queue-integration.test.d.ts +2 -0
  113. package/dist/test/queue/queue-integration.test.d.ts.map +1 -0
  114. package/dist/test/queue/queue-integration.test.js +322 -0
  115. package/dist/test/queue/queue-integration.test.js.map +1 -0
  116. package/dist/test/{queue.test.d.ts.map → queue/queue.test.d.ts.map} +1 -1
  117. package/dist/test/queue/queue.test.js +770 -0
  118. package/dist/test/queue/queue.test.js.map +1 -0
  119. package/dist/test/registry/registry.test.d.ts +2 -0
  120. package/dist/test/registry/registry.test.d.ts.map +1 -0
  121. package/dist/test/registry/registry.test.js +182 -0
  122. package/dist/test/registry/registry.test.js.map +1 -0
  123. package/dist/test/utils.test.d.ts +2 -0
  124. package/dist/test/utils.test.d.ts.map +1 -0
  125. package/dist/test/utils.test.js +66 -0
  126. package/dist/test/utils.test.js.map +1 -0
  127. package/dist/tsconfig.tsbuildinfo +1 -1
  128. package/dist/vitest.config.d.ts +3 -0
  129. package/dist/vitest.config.d.ts.map +1 -0
  130. package/dist/vitest.config.js +11 -0
  131. package/dist/vitest.config.js.map +1 -0
  132. package/package.json +6 -1
  133. package/dist/bench/end-to-end-flow.bench.d.ts +0 -2
  134. package/dist/bench/end-to-end-flow.bench.d.ts.map +0 -1
  135. package/dist/bench/end-to-end-flow.bench.js +0 -256
  136. package/dist/bench/end-to-end-flow.bench.js.map +0 -1
  137. package/dist/src/executor/job-executor.d.ts +0 -62
  138. package/dist/src/executor/job-executor.d.ts.map +0 -1
  139. package/dist/src/executor/job-executor.js +0 -325
  140. package/dist/src/executor/job-executor.js.map +0 -1
  141. package/dist/test/job-executor.test.d.ts +0 -2
  142. package/dist/test/job-executor.test.d.ts.map +0 -1
  143. package/dist/test/job-executor.test.js +0 -581
  144. package/dist/test/job-executor.test.js.map +0 -1
  145. package/dist/test/queue.test.js +0 -396
  146. package/dist/test/queue.test.js.map +0 -1
  147. /package/dist/test/{queue.test.d.ts → queue/queue.test.d.ts} +0 -0
@@ -0,0 +1,128 @@
1
+ import { QueueEventTypes } from "../queue/types.js";
2
+ /**
3
+ * Manages multiple job executors and coordinates job distribution.
4
+ * Listens for job available events and dispatches jobs to executors.
5
+ */
6
+ export class SimpleJobExecutorManager {
7
+ executorFactory;
8
+ eventBus;
9
+ queue;
10
+ executors = [];
11
+ isRunning = false;
12
+ activeJobs = 0;
13
+ totalJobsProcessed = 0;
14
+ unsubscribe;
15
+ constructor(executorFactory, eventBus, queue) {
16
+ this.executorFactory = executorFactory;
17
+ this.eventBus = eventBus;
18
+ this.queue = queue;
19
+ }
20
+ async start(numExecutors) {
21
+ if (this.isRunning) {
22
+ throw new Error("JobExecutorManager is already running");
23
+ }
24
+ if (numExecutors < 1) {
25
+ throw new Error("Number of executors must be at least 1");
26
+ }
27
+ // Create executors
28
+ this.executors = [];
29
+ for (let i = 0; i < numExecutors; i++) {
30
+ this.executors.push(this.executorFactory());
31
+ }
32
+ // Start listening for job available events
33
+ this.unsubscribe = this.eventBus.subscribe(QueueEventTypes.JOB_AVAILABLE, async () => {
34
+ // Only process if we have capacity (simple round-robin for now)
35
+ if (this.activeJobs < this.executors.length) {
36
+ await this.processNextJob();
37
+ }
38
+ });
39
+ this.isRunning = true;
40
+ // Process any existing jobs in the queue
41
+ await this.processExistingJobs();
42
+ }
43
+ async stop(graceful = true) {
44
+ if (!this.isRunning) {
45
+ return;
46
+ }
47
+ // Stop listening for new jobs
48
+ if (this.unsubscribe) {
49
+ this.unsubscribe();
50
+ this.unsubscribe = undefined;
51
+ }
52
+ if (graceful) {
53
+ // Wait for active jobs to complete
54
+ while (this.activeJobs > 0) {
55
+ await new Promise((resolve) => setTimeout(resolve, 100));
56
+ }
57
+ }
58
+ this.executors = [];
59
+ this.isRunning = false;
60
+ }
61
+ getExecutors() {
62
+ return [...this.executors];
63
+ }
64
+ getStatus() {
65
+ return {
66
+ isRunning: this.isRunning,
67
+ numExecutors: this.executors.length,
68
+ activeJobs: this.activeJobs,
69
+ totalJobsProcessed: this.totalJobsProcessed,
70
+ };
71
+ }
72
+ async processNextJob() {
73
+ try {
74
+ // Dequeue next available job
75
+ const handle = await this.queue.dequeueNext();
76
+ if (!handle) {
77
+ return;
78
+ }
79
+ this.activeJobs++;
80
+ // Find an available executor (simple round-robin)
81
+ const executorIndex = this.totalJobsProcessed % this.executors.length;
82
+ const executor = this.executors[executorIndex];
83
+ // Execute the job
84
+ const result = await executor.executeJob(handle.job);
85
+ // Update job status in queue
86
+ if (result.success) {
87
+ await this.queue.completeJob(handle.job.id);
88
+ }
89
+ else {
90
+ // Handle retry logic
91
+ const retryCount = handle.job.retryCount || 0;
92
+ const maxRetries = handle.job.maxRetries || 0;
93
+ if (retryCount < maxRetries) {
94
+ await this.queue.retryJob(handle.job.id, result.error?.message);
95
+ }
96
+ else {
97
+ await this.queue.failJob(handle.job.id, result.error?.message);
98
+ }
99
+ }
100
+ this.totalJobsProcessed++;
101
+ }
102
+ catch (error) {
103
+ console.error("Error processing job:", error);
104
+ }
105
+ finally {
106
+ this.activeJobs--;
107
+ // Check if there are more jobs to process
108
+ if (this.isRunning) {
109
+ const hasMore = await this.queue.hasJobs();
110
+ if (hasMore) {
111
+ await this.processNextJob();
112
+ }
113
+ }
114
+ }
115
+ }
116
+ async processExistingJobs() {
117
+ const hasJobs = await this.queue.hasJobs();
118
+ if (hasJobs) {
119
+ // Start processing up to the number of executors
120
+ const promises = [];
121
+ for (let i = 0; i < Math.min(this.executors.length, 5); i++) {
122
+ promises.push(this.processNextJob());
123
+ }
124
+ await Promise.all(promises);
125
+ }
126
+ }
127
+ }
128
+ //# sourceMappingURL=simple-job-executor-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simple-job-executor-manager.js","sourceRoot":"","sources":["../../../src/executor/simple-job-executor-manager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,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AO,EAAE,CAAC;oBACZ,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;gBAC9B,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,mBAAmB;QAC/B,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QAC3C,IAAI,OAAO,EAAE,CAAC;YACZ,iDAAiD;YACjD,MAAM,QAAQ,GAAoB,EAAE,CAAC;YACrC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC5D,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;YACvC,CAAC;YACD,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,19 @@
1
+ import type { IDocumentOperationStorage, IDocumentStorage } from "document-drive/storage/types";
2
+ import type { Job } from "../queue/types.js";
3
+ import type { IDocumentModelRegistry } from "../registry/interfaces.js";
4
+ import type { IJobExecutor } from "./interfaces.js";
5
+ import type { JobResult } from "./types.js";
6
+ /**
7
+ * Simple job executor that processes a job by applying actions through document model reducers.
8
+ */
9
+ export declare class SimpleJobExecutor implements IJobExecutor {
10
+ private registry;
11
+ private documentStorage;
12
+ private operationStorage;
13
+ constructor(registry: IDocumentModelRegistry, documentStorage: IDocumentStorage, operationStorage: IDocumentOperationStorage);
14
+ /**
15
+ * Execute a single job by applying its action through the appropriate reducer.
16
+ */
17
+ executeJob(job: Job): Promise<JobResult>;
18
+ }
19
+ //# sourceMappingURL=simple-job-executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simple-job-executor.d.ts","sourceRoot":"","sources":["../../../src/executor/simple-job-executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,gBAAgB,EACjB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C;;GAEG;AACH,qBAAa,iBAAkB,YAAW,YAAY;IAElD,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,eAAe;IACvB,OAAO,CAAC,gBAAgB;gBAFhB,QAAQ,EAAE,sBAAsB,EAChC,eAAe,EAAE,gBAAgB,EACjC,gBAAgB,EAAE,yBAAyB;IAGrD;;OAEG;IACG,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC;CA+D/C"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Simple job executor that processes a job by applying actions through document model reducers.
3
+ */
4
+ export class SimpleJobExecutor {
5
+ registry;
6
+ documentStorage;
7
+ operationStorage;
8
+ constructor(registry, documentStorage, operationStorage) {
9
+ this.registry = registry;
10
+ this.documentStorage = documentStorage;
11
+ this.operationStorage = operationStorage;
12
+ }
13
+ /**
14
+ * Execute a single job by applying its action through the appropriate reducer.
15
+ */
16
+ async executeJob(job) {
17
+ const startTime = Date.now();
18
+ let document;
19
+ try {
20
+ document = await this.documentStorage.get(job.documentId);
21
+ }
22
+ catch (error) {
23
+ return {
24
+ job,
25
+ success: false,
26
+ error: error instanceof Error ? error : new Error(String(error)),
27
+ duration: Date.now() - startTime,
28
+ };
29
+ }
30
+ let module;
31
+ try {
32
+ module = this.registry.getModule(document.header.documentType);
33
+ }
34
+ catch (error) {
35
+ return {
36
+ job,
37
+ success: false,
38
+ error: error instanceof Error ? error : new Error(String(error)),
39
+ duration: Date.now() - startTime,
40
+ };
41
+ }
42
+ const updatedDocument = module.reducer(document, job.operation.action);
43
+ const scope = job.scope || "global";
44
+ const operations = updatedDocument.operations[scope];
45
+ if (operations.length === 0) {
46
+ throw new Error("No operation generated from action");
47
+ }
48
+ const newOperation = operations[operations.length - 1];
49
+ // Write the operation to legacy storage
50
+ try {
51
+ await this.operationStorage.addDocumentOperations(job.documentId, [newOperation], updatedDocument);
52
+ }
53
+ catch (error) {
54
+ return {
55
+ job,
56
+ success: false,
57
+ error: error instanceof Error ? error : new Error(String(error)),
58
+ duration: Date.now() - startTime,
59
+ };
60
+ }
61
+ return {
62
+ job,
63
+ success: true,
64
+ operation: newOperation,
65
+ duration: Date.now() - startTime,
66
+ };
67
+ }
68
+ }
69
+ //# sourceMappingURL=simple-job-executor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simple-job-executor.js","sourceRoot":"","sources":["../../../src/executor/simple-job-executor.ts"],"names":[],"mappings":"AAUA;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAElB;IACA;IACA;IAHV,YACU,QAAgC,EAChC,eAAiC,EACjC,gBAA2C;QAF3C,aAAQ,GAAR,QAAQ,CAAwB;QAChC,oBAAe,GAAf,eAAe,CAAkB;QACjC,qBAAgB,GAAhB,gBAAgB,CAA2B;IAClD,CAAC;IAEJ;;OAEG;IACH,KAAK,CAAC,UAAU,CAAC,GAAQ;QACvB,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAE7B,IAAI,QAAoB,CAAC;QACzB,IAAI,CAAC;YACH,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC5D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,GAAG;gBACH,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAA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AAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBAChE,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;aACjC,CAAC;QACJ,CAAC;QAED,OAAO;YACL,GAAG;YACH,OAAO,EAAE,IAAI;YACb,SAAS,EAAE,YAAY;YACvB,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;SACjC,CAAC;IACJ,CAAC;CACF"}
@@ -1,4 +1,4 @@
1
- import { Job } from "../queue/types.js";
1
+ import type { Job } from "../queue/types.js";
2
2
  /**
3
3
  * Represents the result of a job execution
4
4
  */
@@ -7,12 +7,14 @@ export type JobResult = {
7
7
  job: Job;
8
8
  /** Whether the job executed successfully */
9
9
  success: boolean;
10
- /** Error message if the job failed */
11
- error?: string;
10
+ /** Error if the job failed */
11
+ error?: Error;
12
+ /** The operation generated from the action (if successful) */
13
+ operation?: any;
12
14
  /** Timestamp when the job execution completed */
13
- completedAt: string;
15
+ completedAt?: string;
14
16
  /** Duration of job execution in milliseconds */
15
- duration: number;
17
+ duration?: number;
16
18
  /** Any additional metadata from the execution */
17
19
  metadata?: Record<string, any>;
18
20
  };
@@ -23,11 +25,11 @@ export type JobExecutorConfig = {
23
25
  /** Maximum number of concurrent jobs to execute */
24
26
  maxConcurrency?: number;
25
27
  /** Maximum time in milliseconds a job can run before being considered timed out */
26
- jobTimeout?: number;
28
+ jobTimeoutMs?: number;
27
29
  /** Base delay in milliseconds for exponential backoff retries */
28
- retryBaseDelay?: number;
30
+ retryBaseDelayMs?: number;
29
31
  /** Maximum delay in milliseconds for exponential backoff retries */
30
- retryMaxDelay?: number;
32
+ retryMaxDelayMs?: number;
31
33
  };
32
34
  /**
33
35
  * Event types for the job executor
@@ -64,4 +66,17 @@ export type ExecutorStoppedEvent = {
64
66
  stoppedAt: string;
65
67
  graceful: boolean;
66
68
  };
69
+ /**
70
+ * Status information for the job executor manager
71
+ */
72
+ export type ExecutorManagerStatus = {
73
+ /** Whether the manager is currently running */
74
+ isRunning: boolean;
75
+ /** Number of executor instances managed */
76
+ numExecutors: number;
77
+ /** Number of jobs currently being processed */
78
+ activeJobs: number;
79
+ /** Total number of jobs processed since start */
80
+ totalJobsProcessed: number;
81
+ };
67
82
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/executor/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAExC;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,gCAAgC;IAChC,GAAG,EAAE,GAAG,CAAC;IAET,4CAA4C;IAC5C,OAAO,EAAE,OAAO,CAAC;IAEjB,sCAAsC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,iDAAiD;IACjD,WAAW,EAAE,MAAM,CAAC;IAEpB,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAC;IAEjB,iDAAiD;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,mDAAmD;IACnD,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,mFAAmF;IACnF,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,iEAAiE;IACjE,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,oEAAoE;IACpE,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;;;;CAMxB,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,GAAG,EAAE,GAAG,CAAC;IACT,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,EAAE,GAAG,CAAC;IACT,MAAM,EAAE,S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F;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;;;;CAMxB,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,GAAG,EAAE,GAAG,CAAC;IACT,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,EAAE,GAAG,CAAC;IACT,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,GAAG,EAAE,GAAG,CAAC;IACT,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,+CAA+C;IAC/C,SAAS,EAAE,OAAO,CAAC;IAEnB,2CAA2C;IAC3C,YAAY,EAAE,MAAM,CAAC;IAErB,+CAA+C;IAC/C,UAAU,EAAE,MAAM,CAAC;IAEnB,iDAAiD;IACjD,kBAAkB,EAAE,MAAM,CAAC;CAC5B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/executor/types.ts"],"names":[],"mappings":"AA0CA;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,WAAW,EAAE,KAAK;IAClB,aAAa,EAAE,KAAK;IACpB,UAAU,EAAE,KAAK;IACjB,gBAAgB,EAAE,KAAK;IACvB,gBAAgB,EAAE,KAAK;CACf,CAAC"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/executor/types.ts"],"names":[],"mappings":"AA6CA;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,WAAW,EAAE,KAAK;IAClB,aAAa,EAAE,KAAK;IACpB,UAAU,EAAE,KAAK;IACjB,gBAAgB,EAAE,KAAK;IACvB,gBAAgB,EAAE,KAAK;CACf,CAAC"}
@@ -1,9 +1,16 @@
1
+ export { type IReactor } from "./interfaces/reactor.js";
2
+ export { Reactor } from "./reactor.js";
3
+ export { createMutableShutdownStatus } from "./shared/factories.js";
4
+ export { JobStatus, PropagationMode, RelationshipChangeType, type JobInfo, type PagedResults, type PagingOptions, type SearchFilter, type ShutdownStatus, type ViewFilter, } from "./shared/types.js";
1
5
  export { EventBus } from "./events/event-bus.js";
2
6
  export { type IEventBus } from "./events/interfaces.js";
3
7
  export { EventBusAggregateError, type Unsubscribe } from "./events/types.js";
4
8
  export { type IQueue } from "./queue/interfaces.js";
5
9
  export { InMemoryQueue } from "./queue/queue.js";
6
10
  export { QueueEventTypes, type Job, type JobAvailableEvent, } from "./queue/types.js";
7
- export { InMemoryJobExecutor, JobExecutorEventTypes, type ExecutorStartedEvent, type ExecutorStoppedEvent, type IJobExecutor, type JobCompletedEvent, type JobExecutorConfig, type JobFailedEvent, type JobResult, type JobStartedEvent, } from "./executor/job-executor.js";
8
- export { type Operation } from "./shared/types.js";
11
+ export { type IJobExecutor, type IJobExecutorManager, } from "./executor/interfaces.js";
12
+ export { SimpleJobExecutorManager, type JobExecutorFactory, } from "./executor/simple-job-executor-manager.js";
13
+ export { SimpleJobExecutor as InMemoryJobExecutor, SimpleJobExecutor, } from "./executor/simple-job-executor.js";
14
+ export { JobExecutorEventTypes, type ExecutorStartedEvent, type ExecutorStoppedEvent, type JobCompletedEvent, type JobExecutorConfig, type JobFailedEvent, type JobResult, type JobStartedEvent, } from "./executor/types.js";
15
+ export { DocumentModelRegistry, DuplicateModuleError, InvalidModuleError, ModuleNotFoundError, type IDocumentModelRegistry, } from "./registry/index.js";
9
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAG7E,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EACL,eAAe,EACf,KAAK,GAAG,EACR,KAAK,iBAAiB,GACvB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,eAAe,GACrB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EACL,SAAS,EACT,eAAe,EACf,sBAAsB,EACtB,KAAK,OAAO,EACZ,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,UAAU,GAChB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAG7E,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EACL,eAAe,EACf,KAAK,GAAG,EACR,KAAK,iBAAiB,GACvB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,mBAAmB,GACzB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,wBAAwB,EACxB,KAAK,kBAAkB,GACxB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACL,iBAAiB,IAAI,mBAAmB,EACxC,iBAAiB,GAClB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,qBAAqB,EACrB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,eAAe,GACrB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,KAAK,sBAAsB,GAC5B,MAAM,qBAAqB,CAAC"}
package/dist/src/index.js CHANGED
@@ -1,8 +1,14 @@
1
+ export { Reactor } from "./reactor.js";
2
+ export { createMutableShutdownStatus } from "./shared/factories.js";
3
+ export { JobStatus, PropagationMode, RelationshipChangeType, } from "./shared/types.js";
1
4
  // Event Bus
2
5
  export { EventBus } from "./events/event-bus.js";
3
6
  export { EventBusAggregateError } from "./events/types.js";
4
7
  export { InMemoryQueue } from "./queue/queue.js";
5
8
  export { QueueEventTypes, } from "./queue/types.js";
6
- // Job Executor
7
- export { InMemoryJobExecutor, JobExecutorEventTypes, } from "./executor/job-executor.js";
9
+ export { SimpleJobExecutorManager, } from "./executor/simple-job-executor-manager.js";
10
+ export { SimpleJobExecutor as InMemoryJobExecutor, SimpleJobExecutor, } from "./executor/simple-job-executor.js";
11
+ export { JobExecutorEventTypes, } from "./executor/types.js";
12
+ // Document Model Registry
13
+ export { DocumentModelRegistry, DuplicateModuleError, InvalidModuleError, ModuleNotFoundError, } from "./registry/index.js";
8
14
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY;AACZ,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,sBAAsB,EAAoB,MAAM,mBAAmB,CAAC;AAI7E,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EACL,eAAe,GAGhB,MAAM,kBAAkB,CAAC;AAE1B,eAAe;AACf,OAAO,EACL,mBAAmB,EACnB,qBAAqB,GAStB,MAAM,4BAA4B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EACL,SAAS,EACT,eAAe,EACf,sBAAsB,GAOvB,MAAM,mBAAmB,CAAC;AAE3B,YAAY;AACZ,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,sBAAsB,EAAoB,MAAM,mBAAmB,CAAC;AAI7E,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EACL,eAAe,GAGhB,MAAM,kBAAkB,CAAC;AAO1B,OAAO,EACL,wBAAwB,GAEzB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACL,iBAAiB,IAAI,mBAAmB,EACxC,iBAAiB,GAClB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,qBAAqB,GAQtB,MAAM,qBAAqB,CAAC;AAE7B,0BAA0B;AAC1B,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,GAEpB,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,121 @@
1
+ import type { Action, DocumentModelState, Operation, PHDocument } from "document-model";
2
+ import type { JobInfo, JobStatus, PagedResults, PagingOptions, PropagationMode, SearchFilter, ShutdownStatus, ViewFilter } from "../shared/types.js";
3
+ /**
4
+ * The main Reactor interface that serves as a facade for document operations.
5
+ * This interface provides a unified API for document management, including
6
+ * creation, retrieval, mutation, and deletion operations.
7
+ *
8
+ * Phase 2 of the refactoring plan: IReactor Facade (Strangler Fig Pattern)
9
+ */
10
+ export interface IReactor {
11
+ /**
12
+ * Signals that the reactor should shutdown.
13
+ */
14
+ kill(): ShutdownStatus;
15
+ /**
16
+ * Retrieves a list of document model specifications
17
+ *
18
+ * @param namespace - Optional namespace like "powerhouse" or "sky", defaults to ""
19
+ * @param paging - Optional options for paging data in large queries.
20
+ * @param signal - Optional abort signal to cancel the request
21
+ * @returns List of document models
22
+ */
23
+ getDocumentModels(namespace?: string, paging?: PagingOptions, signal?: AbortSignal): Promise<PagedResults<DocumentModelState>>;
24
+ /**
25
+ * Retrieves a specific PHDocument by id
26
+ *
27
+ * @param id - Required, this is the document id
28
+ * @param view - Optional filter containing branch and scopes information
29
+ * @param signal - Optional abort signal to cancel the request
30
+ * @returns The up-to-date PHDocument with scopes and list of child document ids
31
+ */
32
+ get<TDocument extends PHDocument>(id: string, view?: ViewFilter, signal?: AbortSignal): Promise<{
33
+ document: TDocument;
34
+ childIds: string[];
35
+ }>;
36
+ /**
37
+ * Retrieves a specific PHDocument by slug
38
+ *
39
+ * @param slug - Required, this is the document slug
40
+ * @param view - Optional filter containing branch and scopes information
41
+ * @param signal - Optional abort signal to cancel the request
42
+ * @returns The up-to-date PHDocument with scopes and list of child document ids
43
+ */
44
+ getBySlug<TDocument extends PHDocument>(slug: string, view?: ViewFilter, signal?: AbortSignal): Promise<{
45
+ document: TDocument;
46
+ childIds: string[];
47
+ }>;
48
+ /**
49
+ * Retrieves the operations for a document
50
+ *
51
+ * @param documentId - The document id
52
+ * @param view - Optional filter containing branch and scopes information
53
+ * @param paging - Optional pagination options
54
+ * @param signal - Optional abort signal to cancel the request
55
+ * @returns The list of operations
56
+ */
57
+ getOperations(documentId: string, view?: ViewFilter, paging?: PagingOptions, signal?: AbortSignal): Promise<Record<string, PagedResults<Operation>>>;
58
+ /**
59
+ * Filters documents by criteria and returns a list of them
60
+ *
61
+ * @param search - Search filter options (type, parentId, identifiers)
62
+ * @param view - Optional filter containing branch and scopes information
63
+ * @param paging - Optional pagination options
64
+ * @param signal - Optional abort signal to cancel the request
65
+ * @returns List of documents matching criteria and pagination cursor
66
+ */
67
+ find(search: SearchFilter, view?: ViewFilter, paging?: PagingOptions, signal?: AbortSignal): Promise<PagedResults<PHDocument>>;
68
+ /**
69
+ * Creates a document
70
+ *
71
+ * @param document - Document with optional id, slug, parent, model type, and initial state
72
+ * @param signal - Optional abort signal to cancel the request
73
+ * @returns The job status
74
+ */
75
+ create(document: PHDocument, signal?: AbortSignal): Promise<JobStatus>;
76
+ /**
77
+ * Deletes a document
78
+ *
79
+ * @param id - Document id
80
+ * @param propagate - Optional mode for handling children, CASCADE deletes child documents
81
+ * @param signal - Optional abort signal to cancel the request
82
+ * @returns The job id and status
83
+ */
84
+ deleteDocument(id: string, propagate?: PropagationMode, signal?: AbortSignal): Promise<JobInfo>;
85
+ /**
86
+ * Applies a list of actions to a document.
87
+ *
88
+ * @param id - Document id
89
+ * @param actions - List of actions to apply
90
+ * @returns The job id and status
91
+ */
92
+ mutate(id: string, actions: Action[]): Promise<JobInfo>;
93
+ /**
94
+ * Adds multiple documents as children to another
95
+ *
96
+ * @param parentId - Parent document id
97
+ * @param documentIds - List of document ids to add as children
98
+ * @param view - Optional filter containing branch and scopes information
99
+ * @param signal - Optional abort signal to cancel the request
100
+ * @returns The job id and status
101
+ */
102
+ addChildren(parentId: string, documentIds: string[], view?: ViewFilter, signal?: AbortSignal): Promise<JobInfo>;
103
+ /**
104
+ * Removes multiple documents as children from another
105
+ *
106
+ * @param parentId - Parent document id
107
+ * @param documentIds - List of document ids to remove as children
108
+ * @param view - Optional filter containing branch and scopes information
109
+ * @param signal - Optional abort signal to cancel the request
110
+ * @returns The job id and status
111
+ */
112
+ removeChildren(parentId: string, documentIds: string[], view?: ViewFilter, signal?: AbortSignal): Promise<JobInfo>;
113
+ /**
114
+ * Retrieves the status of a job
115
+ *
116
+ * @param jobId - The job id
117
+ * @returns The job status
118
+ */
119
+ getJobStatus(jobId: string, signal?: AbortSignal): Promise<JobInfo>;
120
+ }
121
+ //# sourceMappingURL=reactor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactor.d.ts","sourceRoot":"","sources":["../../../src/interfaces/reactor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EACN,kBAAkB,EAClB,SAAS,EACT,UAAU,EACX,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EACV,OAAO,EACP,SAAS,EACT,YAAY,EACZ,aAAa,EACb,eAAe,EACf,YAAY,EACZ,cAAc,EACd,UAAU,EACX,MAAM,oBAAoB,CAAC;AAE5B;;;;;;GAMG;AACH,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,IAAI,IAAI,cAAc,CAAC;IAEvB;;;;;;;OAOG;IACH,iBAAiB,CACf,SAAS,CAAC,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,aAAa,EACtB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC,CAAC;IAE7C;;;;;;;OAOG;IACH,GAAG,CAAC,SAAS,SAAS,UAAU,EAC9B,EAAE,EAAE,MAAM,EACV,IAAI,CAAC,EAAE,UAAU,EACjB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC;QACT,QAAQ,EAAE,SAAS,CAAC;Q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EACjB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpB;;;;;;;;OAQG;IACH,cAAc,CACZ,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EAAE,EACrB,IAAI,CAAC,EAAE,UAAU,EACjB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpB;;;;;OAKG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACrE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=reactor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactor.js","sourceRoot":"","sources":["../../../src/interfaces/reactor.ts"],"names":[],"mappings":""}
@@ -1,4 +1,4 @@
1
- import { Job } from "./types.js";
1
+ import type { IJobExecutionHandle, Job } from "./types.js";
2
2
  /**
3
3
  * Interface for a job queue that manages write operations.
4
4
  * Internally organizes jobs by documentId, scope, and branch to ensure proper ordering.
@@ -18,14 +18,16 @@ export interface IQueue {
18
18
  * @param documentId - The document ID to get jobs for
19
19
  * @param scope - The scope to get jobs for
20
20
  * @param branch - The branch to get jobs for
21
- * @returns Promise that resolves to the next job or null if no jobs available
21
+ * @param signal - Optional abort signal to cancel the request
22
+ * @returns Promise that resolves to the next job execution handle or null if no jobs available
22
23
  */
23
- dequeue(documentId: string, scope: string, branch: string): Promise<Job | null>;
24
+ dequeue(documentId: string, scope: string, branch: string, signal?: AbortSignal): Promise<IJobExecutionHandle | null>;
24
25
  /**
25
26
  * Get the next available job from any queue.
26
- * @returns Promise that resolves to the next job or null if no jobs available
27
+ * @param signal - Optional abort signal to cancel the request
28
+ * @returns Promise that resolves to the next job execution handle or null if no jobs available
27
29
  */
28
- dequeueNext(): Promise<Job | null>;
30
+ dequeueNext(signal?: AbortSignal): Promise<IJobExecutionHandle | null>;
29
31
  /**
30
32
  * Get the current size of the queue for a specific document/scope/branch.
31
33
  * @param documentId - The document ID
@@ -58,5 +60,43 @@ export interface IQueue {
58
60
  * @returns Promise that resolves when all queues are cleared
59
61
  */
60
62
  clearAll(): Promise<void>;
63
+ /**
64
+ * Check if there are any jobs in the queue.
65
+ * @returns Promise that resolves to true if there are jobs, false otherwise
66
+ */
67
+ hasJobs(): Promise<boolean>;
68
+ /**
69
+ * Mark a job as completed.
70
+ * @param jobId - The ID of the job to mark as completed
71
+ * @returns Promise that resolves when the job is marked as completed
72
+ */
73
+ completeJob(jobId: string): Promise<void>;
74
+ /**
75
+ * Mark a job as failed.
76
+ * @param jobId - The ID of the job to mark as failed
77
+ * @param error - Optional error message
78
+ * @returns Promise that resolves when the job is marked as failed
79
+ */
80
+ failJob(jobId: string, error?: string): Promise<void>;
81
+ /**
82
+ * Retry a failed job.
83
+ * @param jobId - The ID of the job to retry
84
+ * @param error - Optional error message from the failure
85
+ * @returns Promise that resolves when the job is requeued for retry
86
+ */
87
+ retryJob(jobId: string, error?: string): Promise<void>;
88
+ /**
89
+ * Returns true if and only if all jobs have been resolved.
90
+ */
91
+ get isDrained(): boolean;
92
+ /**
93
+ * Blocks the queue from accepting new jobs.
94
+ * @param onDrained - Optional callback to call when the queue is drained
95
+ */
96
+ block(onDrained?: () => void): void;
97
+ /**
98
+ * Unblocks the queue from accepting new jobs.
99
+ */
100
+ unblock(): void;
61
101
  }
62
102
  //# sourceMappingURL=interfaces.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../src/queue/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEjC;;;;GAIG;AACH,MAAM,WAAW,MAAM;IACrB;;;;;;OAMG;IACH,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjC;;;;;;OAMG;IACH,OAAO,CACL,UAAU,EAAE,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AAC;IAEvE;;;;;;OAMG;IACH,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEzE;;;OAGG;IACH,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAE7B;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAExC;;;;;;OAMG;IACH,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAExE;;;OAGG;IACH,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1B;;;OAGG;IACH,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAE5B;;;;OAIG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1C;;;;;OAKG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtD;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvD;;OAEG;IACH,IAAI,SAAS,IAAI,OAAO,CAAC;IAEzB;;;OAGG;IACH,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IAEpC;;OAEG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB"}
@@ -0,0 +1,24 @@
1
+ import type { IJobExecutionHandle, Job } from "./types.js";
2
+ import { JobQueueState } from "./types.js";
3
+ /**
4
+ * Implementation of the IJobExecutionHandle interface
5
+ */
6
+ export declare class JobExecutionHandle implements IJobExecutionHandle {
7
+ private _state;
8
+ private _job;
9
+ private onStart?;
10
+ private onComplete?;
11
+ private onFail?;
12
+ private getStateName;
13
+ constructor(job: Job, initialState: JobQueueState, callbacks?: {
14
+ onStart?: () => void;
15
+ onComplete?: () => void;
16
+ onFail?: (reason: string) => void;
17
+ });
18
+ get job(): Job;
19
+ get state(): JobQueueState;
20
+ start(): void;
21
+ complete(): void;
22
+ fail(reason: string): void;
23
+ }
24
+ //# sourceMappingURL=job-execution-handle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"job-execution-handle.d.ts","sourceRoot":"","sources":["../../../src/queue/job-execution-handle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C;;GAEG;AACH,qBAAa,kBAAmB,YAAW,mBAAmB;IAC5D,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,IAAI,CAAM;IAClB,OAAO,CAAC,OAAO,CAAC,CAAa;IAC7B,OAAO,CAAC,UAAU,CAAC,CAAa;IAChC,OAAO,CAAC,MAAM,CAAC,CAA2B;IAE1C,OAAO,CAAC,YAAY;gBAkBlB,GAAG,EAAE,GAAG,EACR,YAAY,EAAE,aAAa,EAC3B,SAAS,CAAC,EAAE;QACV,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;QACrB,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;QACxB,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;KACnC;IASH,IAAI,GAAG,IAAI,GAAG,CAEb;IAED,IAAI,KAAK,IAAI,aAAa,CAEzB;IAED,KAAK,IAAI,IAAI;IAUb,QAAQ,IAAI,IAAI;IAUhB,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;CAS3B"}