@korajs/devtools 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,163 +1,6 @@
1
- import { KoraEvent, KoraEventType, KoraEventEmitter, Operation } from '@korajs/core';
2
-
3
- /** A KoraEvent wrapped with a reception timestamp and sequential ID */
4
- interface TimestampedEvent {
5
- /** Auto-incrementing sequential ID */
6
- id: number;
7
- /** The original framework event */
8
- event: KoraEvent;
9
- /** Date.now() when the instrumenter captured the event */
10
- receivedAt: number;
11
- }
12
- /** Event categories for filtering and grouping */
13
- type EventCategory = 'operation' | 'merge' | 'sync' | 'query' | 'connection';
14
- /** Configuration for the Instrumenter */
15
- interface DevtoolsConfig {
16
- /** Max events in the ring buffer (default: 10000) */
17
- bufferSize?: number;
18
- /** Enable message bridge for DevTools panel communication (default: true) */
19
- bridgeEnabled?: boolean;
20
- /** Custom message channel name (default: 'kora-devtools') */
21
- channelName?: string;
22
- }
23
- /** Filter criteria for querying events */
24
- interface EventFilterCriteria {
25
- /** Filter by event categories */
26
- categories?: EventCategory[];
27
- /** Filter by specific event types */
28
- types?: KoraEventType[];
29
- /** Filter by reception time range */
30
- timeRange?: {
31
- start: number;
32
- end: number;
33
- };
34
- /** Filter by collection name (extracted from operation events) */
35
- collection?: string;
36
- }
37
- /** Aggregated statistics computed from a set of events */
38
- interface EventStatistics {
39
- totalEvents: number;
40
- eventsByCategory: Record<EventCategory, number>;
41
- eventsByType: Partial<Record<KoraEventType, number>>;
42
- mergeConflicts: number;
43
- constraintViolations: number;
44
- avgMergeDuration: number | null;
45
- avgQueryDuration: number | null;
46
- syncOperationsSent: number;
47
- syncOperationsReceived: number;
48
- }
49
-
50
- /**
51
- * Communicates between the page context and a DevTools panel via window.postMessage.
52
- * All messages are namespaced with a `source` field to avoid collisions with other
53
- * postMessage consumers on the page.
54
- *
55
- * Safe to instantiate in non-browser environments (SSR/Node) — all operations
56
- * become no-ops when `window` is not available.
57
- */
58
- declare class MessageBridge {
59
- private readonly channelName;
60
- private readonly listeners;
61
- private readonly messageHandler;
62
- private destroyed;
63
- constructor(channelName?: string);
64
- /**
65
- * Post a timestamped event through the bridge.
66
- * No-op if window is not available or the bridge has been destroyed.
67
- */
68
- send(event: TimestampedEvent): void;
69
- /**
70
- * Register a callback for events received through the bridge.
71
- * Returns an unsubscribe function.
72
- */
73
- onReceive(callback: (event: TimestampedEvent) => void): () => void;
74
- /**
75
- * Remove all listeners and detach from window.
76
- * After calling destroy, all operations become no-ops.
77
- */
78
- destroy(): void;
79
- }
80
-
81
- /**
82
- * Fixed-capacity ring buffer for storing timestamped events.
83
- * When the buffer is full, the oldest events are evicted to make room for new ones.
84
- * This prevents unbounded memory growth when events accumulate fast.
85
- */
86
- declare class EventBuffer {
87
- private readonly _capacity;
88
- private readonly buffer;
89
- /** Index where the next event will be written */
90
- private head;
91
- /** Total number of events ever pushed (used to compute readable range) */
92
- private _totalPushed;
93
- constructor(capacity?: number);
94
- /** Maximum number of events the buffer can hold */
95
- get capacity(): number;
96
- /** Current number of events in the buffer */
97
- get size(): number;
98
- /**
99
- * Append an event to the buffer.
100
- * If the buffer is at capacity, the oldest event is evicted.
101
- */
102
- push(event: TimestampedEvent): void;
103
- /**
104
- * Returns all events in insertion order (oldest first).
105
- */
106
- getAll(): readonly TimestampedEvent[];
107
- /**
108
- * Returns events whose sequential IDs fall within [start, end] (inclusive).
109
- */
110
- getRange(start: number, end: number): readonly TimestampedEvent[];
111
- /**
112
- * Returns events matching a specific KoraEventType.
113
- */
114
- getByType(type: KoraEventType): readonly TimestampedEvent[];
115
- /** Remove all events from the buffer */
116
- clear(): void;
117
- }
118
-
119
- /**
120
- * Core orchestrator for Kora DevTools instrumentation.
121
- *
122
- * Attaches to a KoraEventEmitter, records all emitted events into a ring buffer
123
- * with sequential IDs and reception timestamps, and optionally forwards them
124
- * through a MessageBridge for consumption by a DevTools panel.
125
- *
126
- * @example
127
- * ```typescript
128
- * const instrumenter = new Instrumenter(app.emitter, { bufferSize: 5000 })
129
- * const buffer = instrumenter.getBuffer()
130
- * // ... later
131
- * instrumenter.destroy()
132
- * ```
133
- */
134
- declare class Instrumenter {
135
- private readonly emitter;
136
- private readonly buffer;
137
- private readonly bridge;
138
- private readonly unsubscribers;
139
- private nextId;
140
- private paused;
141
- private destroyed;
142
- constructor(emitter: KoraEventEmitter, config?: DevtoolsConfig);
143
- /** Access the underlying event buffer */
144
- getBuffer(): EventBuffer;
145
- /** Access the message bridge, or null if bridge is disabled */
146
- getBridge(): MessageBridge | null;
147
- /** Temporarily stop recording events. Events emitted while paused are dropped. */
148
- pause(): void;
149
- /** Resume recording events after a pause. */
150
- resume(): void;
151
- /** Whether the instrumenter is currently paused */
152
- isPaused(): boolean;
153
- /**
154
- * Detach all listeners from the emitter and destroy the bridge.
155
- * After calling destroy, the instrumenter is inert.
156
- */
157
- destroy(): void;
158
- private attachListeners;
159
- private handleEvent;
160
- }
1
+ import { T as TimestampedEvent, E as EventFilterCriteria, a as EventCategory, b as EventStatistics } from './embed-overlay-Dwys5PYM.cjs';
2
+ export { D as DevtoolsConfig, c as EventBuffer, I as Instrumenter, M as MessageBridge, m as mountKoraDevtoolsOverlay } from './embed-overlay-Dwys5PYM.cjs';
3
+ import { KoraEventType, KoraEvent, Operation } from '@korajs/core';
161
4
 
162
5
  /**
163
6
  * Maps a KoraEventType to its EventCategory.
@@ -261,4 +104,4 @@ declare class PortRouter {
261
104
  private attachContent;
262
105
  }
263
106
 
264
- export { type DevtoolsConfig, EventBuffer, type EventCategory, type EventFilterCriteria, type EventStatistics, Instrumenter, MessageBridge, PortRouter, type TimestampedEvent, buildPanelModel, computeStatistics, filterEvents, getEventCategory, renderDevtoolsPanel };
107
+ export { EventCategory, EventFilterCriteria, EventStatistics, PortRouter, TimestampedEvent, buildPanelModel, computeStatistics, filterEvents, getEventCategory, renderDevtoolsPanel };
package/dist/index.d.ts CHANGED
@@ -1,163 +1,6 @@
1
- import { KoraEvent, KoraEventType, KoraEventEmitter, Operation } from '@korajs/core';
2
-
3
- /** A KoraEvent wrapped with a reception timestamp and sequential ID */
4
- interface TimestampedEvent {
5
- /** Auto-incrementing sequential ID */
6
- id: number;
7
- /** The original framework event */
8
- event: KoraEvent;
9
- /** Date.now() when the instrumenter captured the event */
10
- receivedAt: number;
11
- }
12
- /** Event categories for filtering and grouping */
13
- type EventCategory = 'operation' | 'merge' | 'sync' | 'query' | 'connection';
14
- /** Configuration for the Instrumenter */
15
- interface DevtoolsConfig {
16
- /** Max events in the ring buffer (default: 10000) */
17
- bufferSize?: number;
18
- /** Enable message bridge for DevTools panel communication (default: true) */
19
- bridgeEnabled?: boolean;
20
- /** Custom message channel name (default: 'kora-devtools') */
21
- channelName?: string;
22
- }
23
- /** Filter criteria for querying events */
24
- interface EventFilterCriteria {
25
- /** Filter by event categories */
26
- categories?: EventCategory[];
27
- /** Filter by specific event types */
28
- types?: KoraEventType[];
29
- /** Filter by reception time range */
30
- timeRange?: {
31
- start: number;
32
- end: number;
33
- };
34
- /** Filter by collection name (extracted from operation events) */
35
- collection?: string;
36
- }
37
- /** Aggregated statistics computed from a set of events */
38
- interface EventStatistics {
39
- totalEvents: number;
40
- eventsByCategory: Record<EventCategory, number>;
41
- eventsByType: Partial<Record<KoraEventType, number>>;
42
- mergeConflicts: number;
43
- constraintViolations: number;
44
- avgMergeDuration: number | null;
45
- avgQueryDuration: number | null;
46
- syncOperationsSent: number;
47
- syncOperationsReceived: number;
48
- }
49
-
50
- /**
51
- * Communicates between the page context and a DevTools panel via window.postMessage.
52
- * All messages are namespaced with a `source` field to avoid collisions with other
53
- * postMessage consumers on the page.
54
- *
55
- * Safe to instantiate in non-browser environments (SSR/Node) — all operations
56
- * become no-ops when `window` is not available.
57
- */
58
- declare class MessageBridge {
59
- private readonly channelName;
60
- private readonly listeners;
61
- private readonly messageHandler;
62
- private destroyed;
63
- constructor(channelName?: string);
64
- /**
65
- * Post a timestamped event through the bridge.
66
- * No-op if window is not available or the bridge has been destroyed.
67
- */
68
- send(event: TimestampedEvent): void;
69
- /**
70
- * Register a callback for events received through the bridge.
71
- * Returns an unsubscribe function.
72
- */
73
- onReceive(callback: (event: TimestampedEvent) => void): () => void;
74
- /**
75
- * Remove all listeners and detach from window.
76
- * After calling destroy, all operations become no-ops.
77
- */
78
- destroy(): void;
79
- }
80
-
81
- /**
82
- * Fixed-capacity ring buffer for storing timestamped events.
83
- * When the buffer is full, the oldest events are evicted to make room for new ones.
84
- * This prevents unbounded memory growth when events accumulate fast.
85
- */
86
- declare class EventBuffer {
87
- private readonly _capacity;
88
- private readonly buffer;
89
- /** Index where the next event will be written */
90
- private head;
91
- /** Total number of events ever pushed (used to compute readable range) */
92
- private _totalPushed;
93
- constructor(capacity?: number);
94
- /** Maximum number of events the buffer can hold */
95
- get capacity(): number;
96
- /** Current number of events in the buffer */
97
- get size(): number;
98
- /**
99
- * Append an event to the buffer.
100
- * If the buffer is at capacity, the oldest event is evicted.
101
- */
102
- push(event: TimestampedEvent): void;
103
- /**
104
- * Returns all events in insertion order (oldest first).
105
- */
106
- getAll(): readonly TimestampedEvent[];
107
- /**
108
- * Returns events whose sequential IDs fall within [start, end] (inclusive).
109
- */
110
- getRange(start: number, end: number): readonly TimestampedEvent[];
111
- /**
112
- * Returns events matching a specific KoraEventType.
113
- */
114
- getByType(type: KoraEventType): readonly TimestampedEvent[];
115
- /** Remove all events from the buffer */
116
- clear(): void;
117
- }
118
-
119
- /**
120
- * Core orchestrator for Kora DevTools instrumentation.
121
- *
122
- * Attaches to a KoraEventEmitter, records all emitted events into a ring buffer
123
- * with sequential IDs and reception timestamps, and optionally forwards them
124
- * through a MessageBridge for consumption by a DevTools panel.
125
- *
126
- * @example
127
- * ```typescript
128
- * const instrumenter = new Instrumenter(app.emitter, { bufferSize: 5000 })
129
- * const buffer = instrumenter.getBuffer()
130
- * // ... later
131
- * instrumenter.destroy()
132
- * ```
133
- */
134
- declare class Instrumenter {
135
- private readonly emitter;
136
- private readonly buffer;
137
- private readonly bridge;
138
- private readonly unsubscribers;
139
- private nextId;
140
- private paused;
141
- private destroyed;
142
- constructor(emitter: KoraEventEmitter, config?: DevtoolsConfig);
143
- /** Access the underlying event buffer */
144
- getBuffer(): EventBuffer;
145
- /** Access the message bridge, or null if bridge is disabled */
146
- getBridge(): MessageBridge | null;
147
- /** Temporarily stop recording events. Events emitted while paused are dropped. */
148
- pause(): void;
149
- /** Resume recording events after a pause. */
150
- resume(): void;
151
- /** Whether the instrumenter is currently paused */
152
- isPaused(): boolean;
153
- /**
154
- * Detach all listeners from the emitter and destroy the bridge.
155
- * After calling destroy, the instrumenter is inert.
156
- */
157
- destroy(): void;
158
- private attachListeners;
159
- private handleEvent;
160
- }
1
+ import { T as TimestampedEvent, E as EventFilterCriteria, a as EventCategory, b as EventStatistics } from './embed-overlay-Dwys5PYM.js';
2
+ export { D as DevtoolsConfig, c as EventBuffer, I as Instrumenter, M as MessageBridge, m as mountKoraDevtoolsOverlay } from './embed-overlay-Dwys5PYM.js';
3
+ import { KoraEventType, KoraEvent, Operation } from '@korajs/core';
161
4
 
162
5
  /**
163
6
  * Maps a KoraEventType to its EventCategory.
@@ -261,4 +104,4 @@ declare class PortRouter {
261
104
  private attachContent;
262
105
  }
263
106
 
264
- export { type DevtoolsConfig, EventBuffer, type EventCategory, type EventFilterCriteria, type EventStatistics, Instrumenter, MessageBridge, PortRouter, type TimestampedEvent, buildPanelModel, computeStatistics, filterEvents, getEventCategory, renderDevtoolsPanel };
107
+ export { EventCategory, EventFilterCriteria, EventStatistics, PortRouter, TimestampedEvent, buildPanelModel, computeStatistics, filterEvents, getEventCategory, renderDevtoolsPanel };