Files
logikonline 8c300c1f8d Include dist folder for git-based installs
Unignored dist/ so yarn/npm can install from git URL
without needing to build locally.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-07 15:12:47 -05:00

119 lines
3.1 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OfflineQueue = void 0;
const STORAGE_KEY = 'irontelemetry_queue';
/**
* Offline queue for storing events when the network is unavailable
*/
class OfflineQueue {
constructor(maxSize = 500, debug = false) {
this.queue = [];
this.maxSize = maxSize;
this.debug = debug;
this.load();
}
/**
* Add an event to the queue
*/
enqueue(event) {
if (this.queue.length >= this.maxSize) {
// Remove oldest events to make room
this.queue.shift();
if (this.debug) {
console.log('[IronTelemetry] Queue full, dropping oldest event');
}
}
this.queue.push(event);
this.save();
if (this.debug) {
console.log('[IronTelemetry] Event queued, queue size:', this.queue.length);
}
}
/**
* Get all queued events
*/
getAll() {
return [...this.queue];
}
/**
* Remove an event from the queue
*/
remove(eventId) {
this.queue = this.queue.filter((e) => e.eventId !== eventId);
this.save();
}
/**
* Clear all queued events
*/
clear() {
this.queue = [];
this.save();
}
/**
* Get the number of queued events
*/
get size() {
return this.queue.length;
}
/**
* Check if the queue is empty
*/
get isEmpty() {
return this.queue.length === 0;
}
/**
* Load queue from persistent storage
*/
load() {
try {
if (typeof localStorage !== 'undefined') {
const data = localStorage.getItem(STORAGE_KEY);
if (data) {
const parsed = JSON.parse(data);
this.queue = parsed.map((e) => this.deserializeEvent(e));
}
}
}
catch (error) {
if (this.debug) {
console.error('[IronTelemetry] Failed to load queue from storage:', error);
}
}
}
/**
* Save queue to persistent storage
*/
save() {
try {
if (typeof localStorage !== 'undefined') {
localStorage.setItem(STORAGE_KEY, JSON.stringify(this.queue));
}
}
catch (error) {
if (this.debug) {
console.error('[IronTelemetry] Failed to save queue to storage:', error);
}
}
}
/**
* Deserialize an event from storage
*/
deserializeEvent(data) {
return {
...data,
timestamp: new Date(data.timestamp),
breadcrumbs: (data.breadcrumbs ?? []).map((b) => ({
...b,
timestamp: new Date(b.timestamp),
})),
journey: data.journey
? {
...data.journey,
startedAt: new Date(data.journey.startedAt),
}
: undefined,
};
}
}
exports.OfflineQueue = OfflineQueue;
//# sourceMappingURL=queue.js.map