bootifyjs 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/api.d.ts +1 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +1 -0
- package/dist/api.js.map +1 -1
- package/dist/auth/examples/basic-usage.d.ts +2 -1
- package/dist/auth/examples/basic-usage.d.ts.map +1 -1
- package/dist/auth/examples/basic-usage.js +3 -2
- package/dist/auth/examples/basic-usage.js.map +1 -1
- package/dist/auth/index.d.ts +6 -8
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +11 -11
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/middleware/AuthMiddleware.js.map +1 -1
- package/dist/cache/bootstrap.js +1 -1
- package/dist/cache/bootstrap.js.map +1 -1
- package/dist/cache/index.d.ts +2 -1
- package/dist/cache/index.d.ts.map +1 -1
- package/dist/cache/index.js +4 -1
- package/dist/cache/index.js.map +1 -1
- package/dist/cache/{in-memory-cache.store.d.ts → stores/in-memory-cache.store.d.ts} +1 -1
- package/dist/cache/stores/in-memory-cache.store.d.ts.map +1 -0
- package/dist/cache/{in-memory-cache.store.js → stores/in-memory-cache.store.js} +1 -1
- package/dist/cache/stores/in-memory-cache.store.js.map +1 -0
- package/dist/cache/stores/index.d.ts +3 -0
- package/dist/cache/stores/index.d.ts.map +1 -0
- package/dist/cache/stores/index.js +20 -0
- package/dist/cache/stores/index.js.map +1 -0
- package/dist/cache/stores/redis-cache.store.d.ts +8 -0
- package/dist/cache/stores/redis-cache.store.d.ts.map +1 -0
- package/dist/cache/stores/redis-cache.store.js +39 -0
- package/dist/cache/stores/redis-cache.store.js.map +1 -0
- package/dist/core/router.d.ts.map +1 -1
- package/dist/core/router.js +3 -3
- package/dist/core/router.js.map +1 -1
- package/dist/events/bootstrap.d.ts +13 -1
- package/dist/events/bootstrap.d.ts.map +1 -1
- package/dist/events/bootstrap.js +30 -2
- package/dist/events/bootstrap.js.map +1 -1
- package/dist/events/buffered-event-bus.service.d.ts +135 -0
- package/dist/events/buffered-event-bus.service.d.ts.map +1 -0
- package/dist/events/buffered-event-bus.service.js +420 -0
- package/dist/events/buffered-event-bus.service.js.map +1 -0
- package/dist/events/config/buffered-event-config.d.ts +153 -0
- package/dist/events/config/buffered-event-config.d.ts.map +1 -0
- package/dist/events/config/buffered-event-config.js +181 -0
- package/dist/events/config/buffered-event-config.js.map +1 -0
- package/dist/events/index.d.ts +3 -0
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +3 -0
- package/dist/events/index.js.map +1 -1
- package/dist/events/metrics/event-metrics.d.ts +175 -0
- package/dist/events/metrics/event-metrics.d.ts.map +1 -0
- package/dist/events/metrics/event-metrics.js +235 -0
- package/dist/events/metrics/event-metrics.js.map +1 -0
- package/dist/events/monitoring/health-monitor.d.ts +142 -0
- package/dist/events/monitoring/health-monitor.d.ts.map +1 -0
- package/dist/events/monitoring/health-monitor.js +492 -0
- package/dist/events/monitoring/health-monitor.js.map +1 -0
- package/dist/events/retry/retry-handler.d.ts +112 -0
- package/dist/events/retry/retry-handler.d.ts.map +1 -0
- package/dist/events/retry/retry-handler.js +218 -0
- package/dist/events/retry/retry-handler.js.map +1 -0
- package/dist/events/shared-buffer.d.ts +92 -0
- package/dist/events/shared-buffer.d.ts.map +1 -0
- package/dist/events/shared-buffer.js +179 -0
- package/dist/events/shared-buffer.js.map +1 -0
- package/dist/events/worker/event-processor.worker.d.ts +75 -0
- package/dist/events/worker/event-processor.worker.d.ts.map +1 -0
- package/dist/events/worker/event-processor.worker.js +293 -0
- package/dist/events/worker/event-processor.worker.js.map +1 -0
- package/dist/events/worker/worker-manager.d.ts +132 -0
- package/dist/events/worker/worker-manager.d.ts.map +1 -0
- package/dist/events/worker/worker-manager.js +436 -0
- package/dist/events/worker/worker-manager.js.map +1 -0
- package/dist/examples/auth/auth.middleware.d.ts +0 -26
- package/dist/examples/auth/auth.middleware.d.ts.map +1 -1
- package/dist/examples/auth/auth.middleware.js +0 -185
- package/dist/examples/auth/auth.middleware.js.map +1 -1
- package/dist/examples/controllers/auth.controller.d.ts +0 -63
- package/dist/examples/controllers/auth.controller.d.ts.map +1 -1
- package/dist/examples/controllers/auth.controller.js +247 -282
- package/dist/examples/controllers/auth.controller.js.map +1 -1
- package/dist/examples/events/buffered-event-example.d.ts +71 -0
- package/dist/examples/events/buffered-event-example.d.ts.map +1 -0
- package/dist/examples/events/buffered-event-example.js +182 -0
- package/dist/examples/events/buffered-event-example.js.map +1 -0
- package/dist/examples/events/integration-test.d.ts +10 -0
- package/dist/examples/events/integration-test.d.ts.map +1 -0
- package/dist/examples/events/integration-test.js +147 -0
- package/dist/examples/events/integration-test.js.map +1 -0
- package/dist/examples/index.d.ts +1 -0
- package/dist/examples/index.d.ts.map +1 -1
- package/dist/examples/index.js +9 -6
- package/dist/examples/index.js.map +1 -1
- package/dist/examples/todos/schema.d.ts +4 -4
- package/package.json +1 -1
- package/dist/cache/in-memory-cache.store.d.ts.map +0 -1
- package/dist/cache/in-memory-cache.store.js.map +0 -1
- package/dist/examples/authorization-examples.d.ts +0 -67
- package/dist/examples/authorization-examples.d.ts.map +0 -1
- package/dist/examples/authorization-examples.js +0 -202
- package/dist/examples/authorization-examples.js.map +0 -1
- package/dist/examples/controllers/todo-updated.controller.d.ts +0 -103
- package/dist/examples/controllers/todo-updated.controller.d.ts.map +0 -1
- package/dist/examples/controllers/todo-updated.controller.js +0 -328
- package/dist/examples/controllers/todo-updated.controller.js.map +0 -1
- package/dist/examples/controllers/todo-with-jwt-auth.controller.d.ts +0 -114
- package/dist/examples/controllers/todo-with-jwt-auth.controller.d.ts.map +0 -1
- package/dist/examples/controllers/todo-with-jwt-auth.controller.js +0 -329
- package/dist/examples/controllers/todo-with-jwt-auth.controller.js.map +0 -1
- package/dist/examples/jwt-auth-example.d.ts +0 -47
- package/dist/examples/jwt-auth-example.d.ts.map +0 -1
- package/dist/examples/jwt-auth-example.js +0 -316
- package/dist/examples/jwt-auth-example.js.map +0 -1
- package/dist/examples/services/user.service.d.ts +0 -99
- package/dist/examples/services/user.service.d.ts.map +0 -1
- package/dist/examples/services/user.service.js +0 -281
- package/dist/examples/services/user.service.js.map +0 -1
- package/dist/examples/test-auth-flow.d.ts +0 -56
- package/dist/examples/test-auth-flow.d.ts.map +0 -1
- package/dist/examples/test-auth-flow.js +0 -449
- package/dist/examples/test-auth-flow.js.map +0 -1
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RetryHandler = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Handles retry logic with exponential backoff for failed events
|
|
6
|
+
*/
|
|
7
|
+
class RetryHandler {
|
|
8
|
+
constructor(config) {
|
|
9
|
+
this.deadLetterQueue = [];
|
|
10
|
+
this.retryStats = {
|
|
11
|
+
totalRetries: 0,
|
|
12
|
+
successfulRetries: 0,
|
|
13
|
+
failedRetries: 0,
|
|
14
|
+
deadLetterCount: 0,
|
|
15
|
+
averageRetryDelay: 0
|
|
16
|
+
};
|
|
17
|
+
this.config = config;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Handle event with retry logic
|
|
21
|
+
* @param event Event to process
|
|
22
|
+
* @param handler Event handler function
|
|
23
|
+
* @returns Promise that resolves when event is processed or moved to DLQ
|
|
24
|
+
*/
|
|
25
|
+
async handleWithRetry(event, handler) {
|
|
26
|
+
const retryableEvent = this.createRetryableEvent(event);
|
|
27
|
+
for (let attempt = 0; attempt <= this.config.retryAttempts; attempt++) {
|
|
28
|
+
try {
|
|
29
|
+
// Update retry count
|
|
30
|
+
retryableEvent.retryCount = attempt;
|
|
31
|
+
// Execute handler
|
|
32
|
+
await handler.handle(retryableEvent);
|
|
33
|
+
// Success - update stats and return
|
|
34
|
+
if (attempt > 0) {
|
|
35
|
+
this.retryStats.successfulRetries++;
|
|
36
|
+
}
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
const retryAttempt = {
|
|
41
|
+
attempt,
|
|
42
|
+
timestamp: Date.now(),
|
|
43
|
+
error: error
|
|
44
|
+
};
|
|
45
|
+
retryableEvent.retryAttempts.push(retryAttempt);
|
|
46
|
+
retryableEvent.lastError = error;
|
|
47
|
+
this.retryStats.totalRetries++;
|
|
48
|
+
// Check if we should retry
|
|
49
|
+
if (attempt < this.config.retryAttempts) {
|
|
50
|
+
const delay = this.calculateRetryDelay(attempt);
|
|
51
|
+
retryAttempt.nextRetryAt = Date.now() + delay;
|
|
52
|
+
console.warn(`Event ${retryableEvent.type} failed (attempt ${attempt + 1}/${this.config.retryAttempts + 1}). ` +
|
|
53
|
+
`Retrying in ${delay}ms. Error:`, error);
|
|
54
|
+
await this.delay(delay);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
// Max retries exceeded - move to dead letter queue
|
|
58
|
+
this.moveToDeadLetterQueue(retryableEvent, error);
|
|
59
|
+
this.retryStats.failedRetries++;
|
|
60
|
+
console.error(`Event ${retryableEvent.type} failed after ${this.config.retryAttempts + 1} attempts. ` +
|
|
61
|
+
`Moved to dead letter queue. Final error:`, error);
|
|
62
|
+
throw new Error(`Event processing failed after ${this.config.retryAttempts + 1} attempts`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Calculate retry delay using exponential backoff with jitter
|
|
69
|
+
* @param attempt Current attempt number (0-based)
|
|
70
|
+
* @returns Delay in milliseconds
|
|
71
|
+
*/
|
|
72
|
+
calculateRetryDelay(attempt) {
|
|
73
|
+
// Use configured delays if available
|
|
74
|
+
if (attempt < this.config.retryDelays.length) {
|
|
75
|
+
const baseDelay = this.config.retryDelays[attempt];
|
|
76
|
+
// Add jitter (±25% of base delay)
|
|
77
|
+
const jitter = baseDelay * 0.25 * (Math.random() - 0.5);
|
|
78
|
+
return Math.max(100, baseDelay + jitter); // Minimum 100ms
|
|
79
|
+
}
|
|
80
|
+
// Fallback to exponential backoff
|
|
81
|
+
const baseDelay = 1000; // 1 second
|
|
82
|
+
const exponentialDelay = baseDelay * Math.pow(2, attempt);
|
|
83
|
+
const maxDelay = 30000; // 30 seconds max
|
|
84
|
+
// Add jitter
|
|
85
|
+
const jitter = exponentialDelay * 0.25 * (Math.random() - 0.5);
|
|
86
|
+
return Math.min(maxDelay, Math.max(100, exponentialDelay + jitter));
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Create retryable event from regular event
|
|
90
|
+
*/
|
|
91
|
+
createRetryableEvent(event) {
|
|
92
|
+
return {
|
|
93
|
+
...event,
|
|
94
|
+
retryCount: event.retryCount || 0,
|
|
95
|
+
retryAttempts: [],
|
|
96
|
+
maxRetries: this.config.retryAttempts
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Move event to dead letter queue
|
|
101
|
+
*/
|
|
102
|
+
moveToDeadLetterQueue(event, finalError) {
|
|
103
|
+
const deadLetterEntry = {
|
|
104
|
+
event,
|
|
105
|
+
finalError,
|
|
106
|
+
timestamp: Date.now(),
|
|
107
|
+
totalAttempts: event.retryAttempts.length
|
|
108
|
+
};
|
|
109
|
+
this.deadLetterQueue.push(deadLetterEntry);
|
|
110
|
+
this.retryStats.deadLetterCount++;
|
|
111
|
+
// Limit DLQ size to prevent memory issues
|
|
112
|
+
const maxDLQSize = 1000;
|
|
113
|
+
if (this.deadLetterQueue.length > maxDLQSize) {
|
|
114
|
+
this.deadLetterQueue.shift(); // Remove oldest entry
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Get dead letter queue entries
|
|
119
|
+
*/
|
|
120
|
+
getDeadLetterQueue() {
|
|
121
|
+
return [...this.deadLetterQueue];
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Get retry statistics
|
|
125
|
+
*/
|
|
126
|
+
getRetryStats() {
|
|
127
|
+
// Calculate average retry delay
|
|
128
|
+
if (this.retryStats.totalRetries > 0) {
|
|
129
|
+
const totalDelay = this.config.retryDelays.reduce((sum, delay) => sum + delay, 0);
|
|
130
|
+
this.retryStats.averageRetryDelay = totalDelay / this.config.retryDelays.length;
|
|
131
|
+
}
|
|
132
|
+
return { ...this.retryStats };
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Clear dead letter queue
|
|
136
|
+
*/
|
|
137
|
+
clearDeadLetterQueue() {
|
|
138
|
+
this.deadLetterQueue.length = 0;
|
|
139
|
+
this.retryStats.deadLetterCount = 0;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Reprocess events from dead letter queue
|
|
143
|
+
* @param handler Event handler to use for reprocessing
|
|
144
|
+
* @param maxEvents Maximum number of events to reprocess
|
|
145
|
+
*/
|
|
146
|
+
async reprocessDeadLetterQueue(handler, maxEvents = 10) {
|
|
147
|
+
const eventsToProcess = this.deadLetterQueue.splice(0, maxEvents);
|
|
148
|
+
let processed = 0;
|
|
149
|
+
let failed = 0;
|
|
150
|
+
for (const entry of eventsToProcess) {
|
|
151
|
+
try {
|
|
152
|
+
// Reset retry count for reprocessing
|
|
153
|
+
const event = {
|
|
154
|
+
...entry.event,
|
|
155
|
+
retryCount: 0,
|
|
156
|
+
retryAttempts: [],
|
|
157
|
+
lastError: undefined
|
|
158
|
+
};
|
|
159
|
+
await this.handleWithRetry(event, handler);
|
|
160
|
+
processed++;
|
|
161
|
+
this.retryStats.deadLetterCount--;
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
// Put back in DLQ if still failing
|
|
165
|
+
this.deadLetterQueue.push(entry);
|
|
166
|
+
failed++;
|
|
167
|
+
console.error('Failed to reprocess dead letter event:', error);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return { processed, failed };
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Check if event should be retried based on error type
|
|
174
|
+
*/
|
|
175
|
+
shouldRetry(error) {
|
|
176
|
+
// Don't retry certain types of errors
|
|
177
|
+
const nonRetryableErrors = [
|
|
178
|
+
'ValidationError',
|
|
179
|
+
'AuthenticationError',
|
|
180
|
+
'AuthorizationError',
|
|
181
|
+
'SyntaxError',
|
|
182
|
+
'TypeError'
|
|
183
|
+
];
|
|
184
|
+
return !nonRetryableErrors.includes(error.constructor.name);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Delay execution for specified milliseconds
|
|
188
|
+
*/
|
|
189
|
+
delay(ms) {
|
|
190
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Reset retry statistics
|
|
194
|
+
*/
|
|
195
|
+
resetStats() {
|
|
196
|
+
this.retryStats = {
|
|
197
|
+
totalRetries: 0,
|
|
198
|
+
successfulRetries: 0,
|
|
199
|
+
failedRetries: 0,
|
|
200
|
+
deadLetterCount: this.deadLetterQueue.length,
|
|
201
|
+
averageRetryDelay: 0
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Get configuration
|
|
206
|
+
*/
|
|
207
|
+
getConfig() {
|
|
208
|
+
return this.config;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Update configuration
|
|
212
|
+
*/
|
|
213
|
+
updateConfig(config) {
|
|
214
|
+
this.config = config;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
exports.RetryHandler = RetryHandler;
|
|
218
|
+
//# sourceMappingURL=retry-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry-handler.js","sourceRoot":"","sources":["../../../src/events/retry/retry-handler.ts"],"names":[],"mappings":";;;AA6CA;;GAEG;AACH,MAAa,YAAY;IAWvB,YAAY,MAA2B;QAT/B,oBAAe,GAAsB,EAAE,CAAC;QACxC,eAAU,GAAe;YAC/B,YAAY,EAAE,CAAC;YACf,iBAAiB,EAAE,C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AAC,CAAC;gBACjC,MAAM,EAAE,CAAC;gBACT,OAAO,CAAC,KAAK,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAC;YACjE,CAAC;QACH,CAAC;QAED,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;IAC/B,CAAC;IAED;;OAEG;IACK,WAAW,CAAC,KAAY;QAC9B,sCAAsC;QACtC,MAAM,kBAAkB,GAAG;YACzB,iBAAiB;YACjB,qBAAqB;YACrB,oBAAoB;YACpB,aAAa;YACb,WAAW;SACZ,CAAC;QAEF,OAAO,CAAC,kBAAkB,CAAC,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC9D,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,EAAU;QACtB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IACzD,CAAC;IAED;;OAEG;IACH,UAAU;QACR,IAAI,CAAC,UAAU,GAAG;YAChB,YAAY,EAAE,CAAC;YACf,iBAAiB,EAAE,CAAC;YACpB,aAAa,EAAE,CAAC;YAChB,eAAe,EAAE,IAAI,CAAC,eAAe,CAAC,MAAM;YAC5C,iBAAiB,EAAE,CAAC;SACrB,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,YAAY,CAAC,MAA2B;QACtC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAxPD,oCAwPC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { IEvent } from './event.types';
|
|
2
|
+
/**
|
|
3
|
+
* Priority levels for events
|
|
4
|
+
*/
|
|
5
|
+
export type EventPriority = 'critical' | 'normal' | 'low';
|
|
6
|
+
/**
|
|
7
|
+
* Extended event interface with priority and metadata
|
|
8
|
+
*/
|
|
9
|
+
export interface PriorityEvent extends IEvent {
|
|
10
|
+
priority?: EventPriority;
|
|
11
|
+
timestamp?: number;
|
|
12
|
+
retryCount?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Configuration for shared buffer
|
|
16
|
+
*/
|
|
17
|
+
export interface SharedBufferConfig {
|
|
18
|
+
maxEvents: number;
|
|
19
|
+
maxEventSize: number;
|
|
20
|
+
totalMemoryMB: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Thread-safe circular buffer for event processing
|
|
24
|
+
* Uses SharedArrayBuffer for zero-copy inter-thread communication
|
|
25
|
+
*/
|
|
26
|
+
export declare class SharedEventBuffer {
|
|
27
|
+
private buffer;
|
|
28
|
+
private writeIndex;
|
|
29
|
+
private readIndex;
|
|
30
|
+
private eventCount;
|
|
31
|
+
private eventData;
|
|
32
|
+
private maxEvents;
|
|
33
|
+
private maxEventSize;
|
|
34
|
+
private eventSlotSize;
|
|
35
|
+
constructor(config?: SharedBufferConfig);
|
|
36
|
+
/**
|
|
37
|
+
* Enqueue an event to the buffer (thread-safe)
|
|
38
|
+
* @param event Event to enqueue
|
|
39
|
+
* @returns true if successful, false if buffer is full
|
|
40
|
+
*/
|
|
41
|
+
enqueue(event: PriorityEvent): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Dequeue an event from the buffer (thread-safe)
|
|
44
|
+
* @returns Event or null if buffer is empty
|
|
45
|
+
*/
|
|
46
|
+
dequeue(): PriorityEvent | null;
|
|
47
|
+
/**
|
|
48
|
+
* Get current queue size
|
|
49
|
+
*/
|
|
50
|
+
size(): number;
|
|
51
|
+
/**
|
|
52
|
+
* Check if buffer is full
|
|
53
|
+
*/
|
|
54
|
+
isFull(): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Check if buffer is empty
|
|
57
|
+
*/
|
|
58
|
+
isEmpty(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Get buffer utilization percentage
|
|
61
|
+
*/
|
|
62
|
+
getUtilization(): number;
|
|
63
|
+
/**
|
|
64
|
+
* Get buffer statistics
|
|
65
|
+
*/
|
|
66
|
+
getStats(): {
|
|
67
|
+
size: number;
|
|
68
|
+
maxEvents: number;
|
|
69
|
+
utilization: number;
|
|
70
|
+
isFull: boolean;
|
|
71
|
+
isEmpty: boolean;
|
|
72
|
+
writeIndex: number;
|
|
73
|
+
readIndex: number;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Serialize event to Uint8Array
|
|
77
|
+
*/
|
|
78
|
+
private serializeEvent;
|
|
79
|
+
/**
|
|
80
|
+
* Deserialize event from Uint8Array
|
|
81
|
+
*/
|
|
82
|
+
private deserializeEvent;
|
|
83
|
+
/**
|
|
84
|
+
* Clear all events from buffer (for testing/debugging)
|
|
85
|
+
*/
|
|
86
|
+
clear(): void;
|
|
87
|
+
/**
|
|
88
|
+
* Get the underlying SharedArrayBuffer (for worker initialization)
|
|
89
|
+
*/
|
|
90
|
+
getSharedBuffer(): SharedArrayBuffer;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=shared-buffer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-buffer.d.ts","sourceRoot":"","sources":["../../src/events/shared-buffer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,QAAQ,GAAG,KAAK,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,aAAc,SAAQ,MAAM;IAC3C,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,aAAa,CAAS;gBAElB,MAAM,GAAE,kBAInB;IA6BD;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO;IAmCtC;;;OAGG;IACH,OAAO,IAAI,aAAa,GAAG,IAAI;IA0C/B;;OAEG;IACH,IAAI,IAAI,MAAM;IAId;;OAEG;IACH,MAAM,IAAI,OAAO;IAIjB;;OAEG;IACH,OAAO,IAAI,OAAO;IAIlB;;OAEG;IACH,cAAc,IAAI,MAAM;IAIxB;;OAEG;IACH,QAAQ;;;;;;;;;IAYR;;OAEG;IACH,OAAO,CAAC,cAAc;IAatB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAKxB;;OAEG;IACH,KAAK,IAAI,IAAI;IAMb;;OAEG;IACH,eAAe,IAAI,iBAAiB;CAGrC"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SharedEventBuffer = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Thread-safe circular buffer for event processing
|
|
6
|
+
* Uses SharedArrayBuffer for zero-copy inter-thread communication
|
|
7
|
+
*/
|
|
8
|
+
class SharedEventBuffer {
|
|
9
|
+
constructor(config = {
|
|
10
|
+
maxEvents: 10000,
|
|
11
|
+
maxEventSize: 5120, // 5KB
|
|
12
|
+
totalMemoryMB: 50
|
|
13
|
+
}) {
|
|
14
|
+
this.maxEvents = config.maxEvents;
|
|
15
|
+
this.maxEventSize = config.maxEventSize;
|
|
16
|
+
// Calculate slot size (event size + metadata)
|
|
17
|
+
this.eventSlotSize = this.maxEventSize + 64; // Extra space for metadata
|
|
18
|
+
// Calculate total buffer size
|
|
19
|
+
const metadataSize = 12; // 3 Int32 values (writeIndex, readIndex, eventCount)
|
|
20
|
+
const dataSize = this.maxEvents * this.eventSlotSize;
|
|
21
|
+
const totalSize = metadataSize + dataSize;
|
|
22
|
+
// Create shared buffer
|
|
23
|
+
this.buffer = new SharedArrayBuffer(totalSize);
|
|
24
|
+
// Initialize metadata arrays
|
|
25
|
+
this.writeIndex = new Int32Array(this.buffer, 0, 1);
|
|
26
|
+
this.readIndex = new Int32Array(this.buffer, 4, 1);
|
|
27
|
+
this.eventCount = new Int32Array(this.buffer, 8, 1);
|
|
28
|
+
// Initialize event data array
|
|
29
|
+
this.eventData = new Uint8Array(this.buffer, metadataSize);
|
|
30
|
+
// Initialize indices
|
|
31
|
+
Atomics.store(this.writeIndex, 0, 0);
|
|
32
|
+
Atomics.store(this.readIndex, 0, 0);
|
|
33
|
+
Atomics.store(this.eventCount, 0, 0);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Enqueue an event to the buffer (thread-safe)
|
|
37
|
+
* @param event Event to enqueue
|
|
38
|
+
* @returns true if successful, false if buffer is full
|
|
39
|
+
*/
|
|
40
|
+
enqueue(event) {
|
|
41
|
+
// Check if buffer is full
|
|
42
|
+
const currentCount = Atomics.load(this.eventCount, 0);
|
|
43
|
+
if (currentCount >= this.maxEvents) {
|
|
44
|
+
return false; // Buffer full
|
|
45
|
+
}
|
|
46
|
+
// Serialize event
|
|
47
|
+
const serializedEvent = this.serializeEvent(event);
|
|
48
|
+
if (serializedEvent.length > this.maxEventSize) {
|
|
49
|
+
throw new Error(`Event size ${serializedEvent.length} exceeds maximum ${this.maxEventSize}`);
|
|
50
|
+
}
|
|
51
|
+
// Get current write position
|
|
52
|
+
const writePos = Atomics.load(this.writeIndex, 0);
|
|
53
|
+
const slotOffset = writePos * this.eventSlotSize;
|
|
54
|
+
// Write event size first (4 bytes)
|
|
55
|
+
const sizeView = new Int32Array(this.buffer, 12 + slotOffset, 1);
|
|
56
|
+
Atomics.store(sizeView, 0, serializedEvent.length);
|
|
57
|
+
// Write event data
|
|
58
|
+
const eventView = new Uint8Array(this.buffer, 12 + slotOffset + 4, serializedEvent.length);
|
|
59
|
+
eventView.set(serializedEvent);
|
|
60
|
+
// Update write index atomically
|
|
61
|
+
const nextWritePos = (writePos + 1) % this.maxEvents;
|
|
62
|
+
Atomics.store(this.writeIndex, 0, nextWritePos);
|
|
63
|
+
// Increment event count
|
|
64
|
+
Atomics.add(this.eventCount, 0, 1);
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Dequeue an event from the buffer (thread-safe)
|
|
69
|
+
* @returns Event or null if buffer is empty
|
|
70
|
+
*/
|
|
71
|
+
dequeue() {
|
|
72
|
+
// Check if buffer is empty
|
|
73
|
+
const currentCount = Atomics.load(this.eventCount, 0);
|
|
74
|
+
if (currentCount === 0) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
// Get current read position
|
|
78
|
+
const readPos = Atomics.load(this.readIndex, 0);
|
|
79
|
+
const slotOffset = readPos * this.eventSlotSize;
|
|
80
|
+
// Read event size
|
|
81
|
+
const sizeView = new Int32Array(this.buffer, 12 + slotOffset, 1);
|
|
82
|
+
const eventSize = Atomics.load(sizeView, 0);
|
|
83
|
+
if (eventSize === 0 || eventSize > this.maxEventSize) {
|
|
84
|
+
// Invalid event size, skip this slot
|
|
85
|
+
const nextReadPos = (readPos + 1) % this.maxEvents;
|
|
86
|
+
Atomics.store(this.readIndex, 0, nextReadPos);
|
|
87
|
+
Atomics.sub(this.eventCount, 0, 1);
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
// Read event data
|
|
91
|
+
const eventView = new Uint8Array(this.buffer, 12 + slotOffset + 4, eventSize);
|
|
92
|
+
const eventData = new Uint8Array(eventSize);
|
|
93
|
+
eventData.set(eventView);
|
|
94
|
+
// Update read index atomically
|
|
95
|
+
const nextReadPos = (readPos + 1) % this.maxEvents;
|
|
96
|
+
Atomics.store(this.readIndex, 0, nextReadPos);
|
|
97
|
+
// Decrement event count
|
|
98
|
+
Atomics.sub(this.eventCount, 0, 1);
|
|
99
|
+
// Clear the slot
|
|
100
|
+
Atomics.store(sizeView, 0, 0);
|
|
101
|
+
// Deserialize and return event
|
|
102
|
+
return this.deserializeEvent(eventData);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get current queue size
|
|
106
|
+
*/
|
|
107
|
+
size() {
|
|
108
|
+
return Atomics.load(this.eventCount, 0);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Check if buffer is full
|
|
112
|
+
*/
|
|
113
|
+
isFull() {
|
|
114
|
+
return this.size() >= this.maxEvents;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Check if buffer is empty
|
|
118
|
+
*/
|
|
119
|
+
isEmpty() {
|
|
120
|
+
return this.size() === 0;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Get buffer utilization percentage
|
|
124
|
+
*/
|
|
125
|
+
getUtilization() {
|
|
126
|
+
return (this.size() / this.maxEvents) * 100;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get buffer statistics
|
|
130
|
+
*/
|
|
131
|
+
getStats() {
|
|
132
|
+
return {
|
|
133
|
+
size: this.size(),
|
|
134
|
+
maxEvents: this.maxEvents,
|
|
135
|
+
utilization: this.getUtilization(),
|
|
136
|
+
isFull: this.isFull(),
|
|
137
|
+
isEmpty: this.isEmpty(),
|
|
138
|
+
writeIndex: Atomics.load(this.writeIndex, 0),
|
|
139
|
+
readIndex: Atomics.load(this.readIndex, 0)
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Serialize event to Uint8Array
|
|
144
|
+
*/
|
|
145
|
+
serializeEvent(event) {
|
|
146
|
+
// Add timestamp and priority if not present
|
|
147
|
+
const enrichedEvent = {
|
|
148
|
+
...event,
|
|
149
|
+
timestamp: event.timestamp || Date.now(),
|
|
150
|
+
priority: event.priority || 'normal',
|
|
151
|
+
retryCount: event.retryCount || 0
|
|
152
|
+
};
|
|
153
|
+
const jsonString = JSON.stringify(enrichedEvent);
|
|
154
|
+
return new TextEncoder().encode(jsonString);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Deserialize event from Uint8Array
|
|
158
|
+
*/
|
|
159
|
+
deserializeEvent(data) {
|
|
160
|
+
const jsonString = new TextDecoder().decode(data);
|
|
161
|
+
return JSON.parse(jsonString);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Clear all events from buffer (for testing/debugging)
|
|
165
|
+
*/
|
|
166
|
+
clear() {
|
|
167
|
+
Atomics.store(this.writeIndex, 0, 0);
|
|
168
|
+
Atomics.store(this.readIndex, 0, 0);
|
|
169
|
+
Atomics.store(this.eventCount, 0, 0);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Get the underlying SharedArrayBuffer (for worker initialization)
|
|
173
|
+
*/
|
|
174
|
+
getSharedBuffer() {
|
|
175
|
+
return this.buffer;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
exports.SharedEventBuffer = SharedEventBuffer;
|
|
179
|
+
//# sourceMappingURL=shared-buffer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-buffer.js","sourceRoot":"","sources":["../../src/events/shared-buffer.ts"],"names":[],"mappings":";;;AAyBA;;;GAGG;AACH,MAAa,iBAAiB;IAU5B,YAAY,SAA6B;QACvC,SAAS,EAAE,KAAK;QAChB,YAAY,EAAE,IAAI,EAAE,MAAM;QAC1B,aAAa,EAAE,EAAE;KAClB;QACC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QAClC,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;QAExC,8CAA8C;QAC9C,IAAI,CA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AE,CAAC,CAAC;SAC3C,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,cAAc,CAAC,KAAoB;QACzC,4CAA4C;QAC5C,MAAM,aAAa,GAAG;YACpB,GAAG,KAAK;YACR,SAAS,EAAE,KAAK,CAAC,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE;YACxC,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,QAAQ;YACpC,UAAU,EAAE,KAAK,CAAC,UAAU,IAAI,CAAC;SAClC,CAAC;QAEF,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;QACjD,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACK,gBAAgB,CAAC,IAAgB;QACvC,MAAM,UAAU,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAClD,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAkB,CAAC;IACjD,CAAC;IAED;;OAEG;IACH,KAAK;QACH,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACrC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACpC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,eAAe;QACb,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AAnND,8CAmNC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event processor worker implementation
|
|
3
|
+
*/
|
|
4
|
+
declare class EventProcessorWorker {
|
|
5
|
+
private workerId;
|
|
6
|
+
private config;
|
|
7
|
+
private buffer;
|
|
8
|
+
private retryHandler;
|
|
9
|
+
private handlers;
|
|
10
|
+
private isRunning;
|
|
11
|
+
private isShuttingDown;
|
|
12
|
+
private eventsProcessed;
|
|
13
|
+
private eventsSucceeded;
|
|
14
|
+
private eventsFailed;
|
|
15
|
+
private processingTimes;
|
|
16
|
+
private startTime;
|
|
17
|
+
private lastActivity;
|
|
18
|
+
private healthCheckInterval?;
|
|
19
|
+
private processingLoop?;
|
|
20
|
+
constructor();
|
|
21
|
+
/**
|
|
22
|
+
* Setup message handling with main thread
|
|
23
|
+
*/
|
|
24
|
+
private setupMessageHandling;
|
|
25
|
+
/**
|
|
26
|
+
* Handle messages from main thread
|
|
27
|
+
*/
|
|
28
|
+
private handleMessage;
|
|
29
|
+
/**
|
|
30
|
+
* Initialize worker with configuration and shared buffer
|
|
31
|
+
*/
|
|
32
|
+
private initialize;
|
|
33
|
+
/**
|
|
34
|
+
* Register event handler
|
|
35
|
+
*/
|
|
36
|
+
private registerHandler;
|
|
37
|
+
/**
|
|
38
|
+
* Start the main event processing loop
|
|
39
|
+
*/
|
|
40
|
+
private startProcessingLoop;
|
|
41
|
+
/**
|
|
42
|
+
* Process a single event
|
|
43
|
+
*/
|
|
44
|
+
private processEvent;
|
|
45
|
+
/**
|
|
46
|
+
* Start health monitoring
|
|
47
|
+
*/
|
|
48
|
+
private startHealthMonitoring;
|
|
49
|
+
/**
|
|
50
|
+
* Send health status to main thread
|
|
51
|
+
*/
|
|
52
|
+
private sendHealthStatus;
|
|
53
|
+
/**
|
|
54
|
+
* Send worker statistics
|
|
55
|
+
*/
|
|
56
|
+
private sendStats;
|
|
57
|
+
/**
|
|
58
|
+
* Shutdown worker gracefully
|
|
59
|
+
*/
|
|
60
|
+
private shutdown;
|
|
61
|
+
/**
|
|
62
|
+
* Send message to main thread
|
|
63
|
+
*/
|
|
64
|
+
private sendMessage;
|
|
65
|
+
/**
|
|
66
|
+
* Send error message to main thread
|
|
67
|
+
*/
|
|
68
|
+
private sendError;
|
|
69
|
+
/**
|
|
70
|
+
* Sleep for specified milliseconds
|
|
71
|
+
*/
|
|
72
|
+
private sleep;
|
|
73
|
+
}
|
|
74
|
+
export { EventProcessorWorker };
|
|
75
|
+
//# sourceMappingURL=event-processor.worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-processor.worker.d.ts","sourceRoot":"","sources":["../../../src/events/worker/event-processor.worker.ts"],"names":[],"mappings":"AAqCA;;GAEG;AACH,cAAM,oBAAoB;IACxB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,QAAQ,CAAyC;IACzD,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,cAAc,CAAS;IAG/B,OAAO,CAAC,eAAe,CAAK;IAC5B,OAAO,CAAC,eAAe,CAAK;IAC5B,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,eAAe,CAAgB;IACvC,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,YAAY,CAAc;IAGlC,OAAO,CAAC,mBAAmB,CAAC,CAAiB;IAC7C,OAAO,CAAC,cAAc,CAAC,CAAgB;;IAOvC;;OAEG;IACH,OAAO,CAAC,oBAAoB;IA2B5B;;OAEG;YACW,aAAa;IA2B3B;;OAEG;YACW,UAAU;IAwBxB;;OAEG;IACH,OAAO,CAAC,eAAe;IAiBvB;;OAEG;YACW,mBAAmB;IA0BjC;;OAEG;YACW,YAAY;IA8C1B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAM7B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IA8BxB;;OAEG;IACH,OAAO,CAAC,SAAS;IAiBjB;;OAEG;YACW,QAAQ;IA6BtB;;OAEG;IACH,OAAO,CAAC,WAAW;IAMnB;;OAEG;IACH,OAAO,CAAC,SAAS;IAIjB;;OAEG;IACH,OAAO,CAAC,KAAK;CAGd;AAOD,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
|