@framers/sql-storage-adapter 0.7.2 → 0.7.4
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 +41 -0
- package/dist/adapters/electron/preload.cjs +289 -0
- package/dist/adapters/electron/renderer.d.ts +9 -0
- package/dist/adapters/electron/renderer.d.ts.map +1 -0
- package/dist/adapters/electron/renderer.js +8 -0
- package/dist/adapters/electron/renderer.js.map +1 -0
- package/dist/cjs/adapters/__tests__/indexedDbAdapter.spec.d.ts +2 -0
- package/dist/cjs/adapters/__tests__/indexedDbAdapter.spec.js +133 -0
- package/dist/cjs/adapters/baseStorageAdapter.d.ts +368 -0
- package/dist/cjs/adapters/baseStorageAdapter.js +744 -0
- package/dist/cjs/adapters/betterSqliteAdapter.d.ts +124 -0
- package/dist/cjs/adapters/betterSqliteAdapter.js +334 -0
- package/dist/cjs/adapters/capacitorSqliteAdapter.d.ts +83 -0
- package/dist/cjs/adapters/capacitorSqliteAdapter.js +250 -0
- package/dist/cjs/adapters/electron/electronMainAdapter.d.ts +251 -0
- package/dist/cjs/adapters/electron/electronMainAdapter.js +392 -0
- package/dist/cjs/adapters/electron/electronRendererAdapter.d.ts +177 -0
- package/dist/cjs/adapters/electron/electronRendererAdapter.js +283 -0
- package/dist/cjs/adapters/electron/index.d.ts +74 -0
- package/dist/cjs/adapters/electron/index.js +86 -0
- package/dist/cjs/adapters/electron/ipc/channels.d.ts +196 -0
- package/dist/cjs/adapters/electron/ipc/channels.js +127 -0
- package/dist/cjs/adapters/electron/ipc/index.d.ts +11 -0
- package/dist/cjs/adapters/electron/ipc/index.js +38 -0
- package/dist/cjs/adapters/electron/ipc/protocol.d.ts +78 -0
- package/dist/cjs/adapters/electron/ipc/protocol.js +341 -0
- package/dist/cjs/adapters/electron/ipc/types.d.ts +248 -0
- package/dist/cjs/adapters/electron/ipc/types.js +15 -0
- package/dist/cjs/adapters/electron/migration/autoMigrator.d.ts +184 -0
- package/dist/cjs/adapters/electron/migration/autoMigrator.js +441 -0
- package/dist/cjs/adapters/electron/migration/index.d.ts +9 -0
- package/dist/cjs/adapters/electron/migration/index.js +29 -0
- package/dist/cjs/adapters/electron/preload.d.ts +126 -0
- package/dist/cjs/adapters/electron/preload.js +233 -0
- package/dist/cjs/adapters/electron/recovery/corruptionDetector.d.ts +214 -0
- package/dist/cjs/adapters/electron/recovery/corruptionDetector.js +359 -0
- package/dist/cjs/adapters/electron/recovery/index.d.ts +11 -0
- package/dist/cjs/adapters/electron/recovery/index.js +34 -0
- package/dist/cjs/adapters/electron/recovery/walCheckpoint.d.ts +186 -0
- package/dist/cjs/adapters/electron/recovery/walCheckpoint.js +263 -0
- package/dist/cjs/adapters/electron/renderer.d.ts +9 -0
- package/dist/cjs/adapters/electron/renderer.js +33 -0
- package/dist/cjs/adapters/electron/window/index.d.ts +9 -0
- package/dist/cjs/adapters/electron/window/index.js +29 -0
- package/dist/cjs/adapters/electron/window/windowManager.d.ts +190 -0
- package/dist/cjs/adapters/electron/window/windowManager.js +321 -0
- package/dist/cjs/adapters/indexedDbAdapter.d.ts +490 -0
- package/dist/cjs/adapters/indexedDbAdapter.js +993 -0
- package/dist/cjs/adapters/postgresAdapter.d.ts +424 -0
- package/dist/cjs/adapters/postgresAdapter.js +889 -0
- package/dist/cjs/adapters/sqlJsAdapter.d.ts +64 -0
- package/dist/cjs/adapters/sqlJsAdapter.js +268 -0
- package/dist/cjs/adapters/supabase.d.ts +58 -0
- package/dist/cjs/adapters/supabase.js +401 -0
- package/dist/cjs/codecs/BrowserBlobCodec.d.ts +14 -0
- package/dist/cjs/codecs/BrowserBlobCodec.js +57 -0
- package/dist/cjs/codecs/NodeBlobCodec.d.ts +14 -0
- package/dist/cjs/codecs/NodeBlobCodec.js +59 -0
- package/dist/cjs/core/contracts/blobCodec.d.ts +15 -0
- package/dist/cjs/core/contracts/blobCodec.js +15 -0
- package/dist/cjs/core/contracts/context.d.ts +221 -0
- package/dist/cjs/core/contracts/context.js +15 -0
- package/dist/cjs/core/contracts/dialect.d.ts +154 -0
- package/dist/cjs/core/contracts/dialect.js +15 -0
- package/dist/cjs/core/contracts/events.d.ts +225 -0
- package/dist/cjs/core/contracts/events.js +15 -0
- package/dist/cjs/core/contracts/exporter.d.ts +13 -0
- package/dist/cjs/core/contracts/exporter.js +15 -0
- package/dist/cjs/core/contracts/extensions.d.ts +73 -0
- package/dist/cjs/core/contracts/extensions.js +15 -0
- package/dist/cjs/core/contracts/features.d.ts +25 -0
- package/dist/cjs/core/contracts/features.js +61 -0
- package/dist/cjs/core/contracts/fts.d.ts +66 -0
- package/dist/cjs/core/contracts/fts.js +15 -0
- package/dist/cjs/core/contracts/hooks.d.ts +481 -0
- package/dist/cjs/core/contracts/hooks.js +140 -0
- package/dist/cjs/core/contracts/index.d.ts +260 -0
- package/dist/cjs/core/contracts/index.js +41 -0
- package/dist/cjs/core/contracts/limitations.d.ts +46 -0
- package/dist/cjs/core/contracts/limitations.js +218 -0
- package/dist/cjs/core/contracts/performance.d.ts +308 -0
- package/dist/cjs/core/contracts/performance.js +144 -0
- package/dist/cjs/core/database.d.ts +220 -0
- package/dist/cjs/core/database.js +136 -0
- package/dist/cjs/core/portable.d.ts +24 -0
- package/dist/cjs/core/portable.js +68 -0
- package/dist/cjs/core/resolver.d.ts +77 -0
- package/dist/cjs/core/resolver.js +235 -0
- package/dist/cjs/dialects/PostgresDialect.d.ts +35 -0
- package/dist/cjs/dialects/PostgresDialect.js +143 -0
- package/dist/cjs/dialects/SqliteDialect.d.ts +35 -0
- package/dist/cjs/dialects/SqliteDialect.js +142 -0
- package/dist/cjs/dialects/shared.d.ts +17 -0
- package/dist/cjs/dialects/shared.js +90 -0
- package/dist/cjs/exporters/PostgresExporter.d.ts +14 -0
- package/dist/cjs/exporters/PostgresExporter.js +61 -0
- package/dist/cjs/exporters/SqliteFileExporter.d.ts +16 -0
- package/dist/cjs/exporters/SqliteFileExporter.js +43 -0
- package/dist/cjs/features/auth/authJsAdapter.d.ts +110 -0
- package/dist/cjs/features/auth/authJsAdapter.js +251 -0
- package/dist/cjs/features/backup/cloudBackup.d.ts +219 -0
- package/dist/cjs/features/backup/cloudBackup.js +209 -0
- package/dist/cjs/features/kv/idb.d.ts +79 -0
- package/dist/cjs/features/kv/idb.js +32 -0
- package/dist/cjs/features/kv/index.d.ts +14 -0
- package/dist/cjs/features/kv/index.js +40 -0
- package/dist/cjs/features/kv/indexedDbKeyValueStore.d.ts +77 -0
- package/dist/cjs/features/kv/indexedDbKeyValueStore.js +116 -0
- package/dist/cjs/features/kv/keyValueStore.d.ts +48 -0
- package/dist/cjs/features/kv/keyValueStore.js +67 -0
- package/dist/cjs/features/kv/sqlKeyValueStore.d.ts +34 -0
- package/dist/cjs/features/kv/sqlKeyValueStore.js +81 -0
- package/dist/cjs/features/kv/valueCodec.d.ts +35 -0
- package/dist/cjs/features/kv/valueCodec.js +426 -0
- package/dist/cjs/features/migrations/dataExport.d.ts +77 -0
- package/dist/cjs/features/migrations/dataExport.js +194 -0
- package/dist/cjs/features/migrations/dataImport.d.ts +54 -0
- package/dist/cjs/features/migrations/dataImport.js +300 -0
- package/dist/cjs/features/migrations/migration.d.ts +89 -0
- package/dist/cjs/features/migrations/migration.js +187 -0
- package/dist/cjs/features/migrations/schemaMigrations.d.ts +93 -0
- package/dist/cjs/features/migrations/schemaMigrations.js +220 -0
- package/dist/cjs/features/sync/conflicts/conflictResolver.d.ts +222 -0
- package/dist/cjs/features/sync/conflicts/conflictResolver.js +366 -0
- package/dist/cjs/features/sync/conflicts/index.d.ts +9 -0
- package/dist/cjs/features/sync/conflicts/index.js +21 -0
- package/dist/cjs/features/sync/crossPlatformSync.d.ts +281 -0
- package/dist/cjs/features/sync/crossPlatformSync.js +551 -0
- package/dist/cjs/features/sync/devices/deviceManager.d.ts +243 -0
- package/dist/cjs/features/sync/devices/deviceManager.js +450 -0
- package/dist/cjs/features/sync/devices/index.d.ts +10 -0
- package/dist/cjs/features/sync/devices/index.js +21 -0
- package/dist/cjs/features/sync/index.d.ts +37 -0
- package/dist/cjs/features/sync/index.js +111 -0
- package/dist/cjs/features/sync/protocol/index.d.ts +11 -0
- package/dist/cjs/features/sync/protocol/index.js +23 -0
- package/dist/cjs/features/sync/protocol/messages.d.ts +348 -0
- package/dist/cjs/features/sync/protocol/messages.js +215 -0
- package/dist/cjs/features/sync/protocol/vectorClock.d.ts +164 -0
- package/dist/cjs/features/sync/protocol/vectorClock.js +256 -0
- package/dist/cjs/features/sync/syncManager.d.ts +348 -0
- package/dist/cjs/features/sync/syncManager.js +455 -0
- package/dist/cjs/features/sync/tables/index.d.ts +10 -0
- package/dist/cjs/features/sync/tables/index.js +21 -0
- package/dist/cjs/features/sync/tables/syncLogManager.d.ts +216 -0
- package/dist/cjs/features/sync/tables/syncLogManager.js +423 -0
- package/dist/cjs/features/sync/transport/httpTransport.d.ts +123 -0
- package/dist/cjs/features/sync/transport/httpTransport.js +346 -0
- package/dist/cjs/features/sync/transport/index.d.ts +12 -0
- package/dist/cjs/features/sync/transport/index.js +25 -0
- package/dist/cjs/features/sync/transport/transport.d.ts +259 -0
- package/dist/cjs/features/sync/transport/transport.js +163 -0
- package/dist/cjs/features/sync/transport/websocketTransport.d.ts +126 -0
- package/dist/cjs/features/sync/transport/websocketTransport.js +342 -0
- package/dist/cjs/fts/PostgresFts.d.ts +29 -0
- package/dist/cjs/fts/PostgresFts.js +77 -0
- package/dist/cjs/fts/SqliteFts5.d.ts +22 -0
- package/dist/cjs/fts/SqliteFts5.js +58 -0
- package/dist/cjs/index.d.ts +31 -0
- package/dist/cjs/index.js +103 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/shared/connectionGate.d.ts +94 -0
- package/dist/cjs/shared/connectionGate.js +77 -0
- package/dist/cjs/shared/errors.d.ts +23 -0
- package/dist/cjs/shared/errors.js +45 -0
- package/dist/cjs/shared/logger.d.ts +26 -0
- package/dist/cjs/shared/logger.js +40 -0
- package/dist/cjs/shared/parameterUtils.d.ts +16 -0
- package/dist/cjs/shared/parameterUtils.js +59 -0
- package/dist/cjs/shared/postgresTarget.d.ts +11 -0
- package/dist/cjs/shared/postgresTarget.js +30 -0
- package/dist/cjs/shared/segment.d.ts +43 -0
- package/dist/cjs/shared/segment.js +63 -0
- package/dist/cjs/shared/serializedTransaction.d.ts +14 -0
- package/dist/cjs/shared/serializedTransaction.js +74 -0
- package/dist/cjs/shared/splitSqlStatements.d.ts +27 -0
- package/dist/cjs/shared/splitSqlStatements.js +163 -0
- package/dist/cjs/shared/sqlPlaceholders.d.ts +48 -0
- package/dist/cjs/shared/sqlPlaceholders.js +263 -0
- package/dist/cjs/types/index.d.ts +29 -0
- package/dist/cjs/types/index.js +33 -0
- package/dist/core/portable.d.ts +24 -0
- package/dist/core/portable.d.ts.map +1 -0
- package/dist/core/portable.js +24 -0
- package/dist/core/portable.js.map +1 -0
- package/dist/features/auth/authJsAdapter.d.ts +110 -0
- package/dist/features/auth/authJsAdapter.d.ts.map +1 -0
- package/dist/features/auth/authJsAdapter.js +248 -0
- package/dist/features/auth/authJsAdapter.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +149 -24
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var windowManager_exports = {};
|
|
19
|
+
__export(windowManager_exports, {
|
|
20
|
+
WindowManager: () => WindowManager,
|
|
21
|
+
createWindowManager: () => createWindowManager
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(windowManager_exports);
|
|
24
|
+
var import_electron = require("electron");
|
|
25
|
+
var import_channels = require("../ipc/channels.js");
|
|
26
|
+
const DEFAULT_CONFIG = {
|
|
27
|
+
broadcastChanges: true,
|
|
28
|
+
trackFocusedWindow: true,
|
|
29
|
+
verbose: false,
|
|
30
|
+
excludeWindows: []
|
|
31
|
+
};
|
|
32
|
+
class WindowManager {
|
|
33
|
+
constructor(config = {}, callbacks = {}) {
|
|
34
|
+
this.windows = /* @__PURE__ */ new Map();
|
|
35
|
+
this.focusedWindowId = null;
|
|
36
|
+
this.isInitialized = false;
|
|
37
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
38
|
+
this.callbacks = callbacks;
|
|
39
|
+
}
|
|
40
|
+
// ============================================================================
|
|
41
|
+
// Initialization
|
|
42
|
+
// ============================================================================
|
|
43
|
+
/**
|
|
44
|
+
* Initialize the window manager.
|
|
45
|
+
*/
|
|
46
|
+
initialize() {
|
|
47
|
+
if (this.isInitialized)
|
|
48
|
+
return;
|
|
49
|
+
if (this.config.trackFocusedWindow) {
|
|
50
|
+
this.setupFocusTracking();
|
|
51
|
+
}
|
|
52
|
+
const allWindows = import_electron.BrowserWindow.getAllWindows();
|
|
53
|
+
for (const win of allWindows) {
|
|
54
|
+
this.registerWindow(win);
|
|
55
|
+
}
|
|
56
|
+
this.isInitialized = true;
|
|
57
|
+
this.log(`Window Manager initialized with ${this.windows.size} windows`);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Dispose the window manager.
|
|
61
|
+
*/
|
|
62
|
+
dispose() {
|
|
63
|
+
this.windows.clear();
|
|
64
|
+
this.focusedWindowId = null;
|
|
65
|
+
this.isInitialized = false;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Set up focus tracking for all windows.
|
|
69
|
+
*/
|
|
70
|
+
setupFocusTracking() {
|
|
71
|
+
const originalGetAllWindows = import_electron.BrowserWindow.getAllWindows.bind(import_electron.BrowserWindow);
|
|
72
|
+
setInterval(() => {
|
|
73
|
+
const currentWindows = originalGetAllWindows();
|
|
74
|
+
for (const win of currentWindows) {
|
|
75
|
+
if (!this.windows.has(win.id)) {
|
|
76
|
+
this.registerWindow(win);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}, 1e3);
|
|
80
|
+
}
|
|
81
|
+
// ============================================================================
|
|
82
|
+
// Window Registration
|
|
83
|
+
// ============================================================================
|
|
84
|
+
/**
|
|
85
|
+
* Register a window for management.
|
|
86
|
+
*/
|
|
87
|
+
registerWindow(window, name) {
|
|
88
|
+
if (this.windows.has(window.id)) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const registration = {
|
|
92
|
+
id: window.id,
|
|
93
|
+
name,
|
|
94
|
+
isFocused: window.isFocused(),
|
|
95
|
+
registeredAt: Date.now(),
|
|
96
|
+
lastActivityAt: Date.now(),
|
|
97
|
+
subscribedToChanges: true
|
|
98
|
+
};
|
|
99
|
+
this.windows.set(window.id, registration);
|
|
100
|
+
window.on("focus", () => {
|
|
101
|
+
this.handleWindowFocus(window.id);
|
|
102
|
+
});
|
|
103
|
+
window.on("blur", () => {
|
|
104
|
+
this.handleWindowBlur(window.id);
|
|
105
|
+
});
|
|
106
|
+
window.on("closed", () => {
|
|
107
|
+
this.unregisterWindow(window.id);
|
|
108
|
+
});
|
|
109
|
+
if (window.isFocused()) {
|
|
110
|
+
this.focusedWindowId = window.id;
|
|
111
|
+
}
|
|
112
|
+
this.log(`Registered window: ${window.id}${name ? ` (${name})` : ""}`);
|
|
113
|
+
this.callbacks.onWindowRegistered?.(registration);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Unregister a window.
|
|
117
|
+
*/
|
|
118
|
+
unregisterWindow(windowId) {
|
|
119
|
+
const registration = this.windows.get(windowId);
|
|
120
|
+
if (!registration)
|
|
121
|
+
return;
|
|
122
|
+
this.windows.delete(windowId);
|
|
123
|
+
if (this.focusedWindowId === windowId) {
|
|
124
|
+
this.focusedWindowId = null;
|
|
125
|
+
}
|
|
126
|
+
this.log(`Unregistered window: ${windowId}`);
|
|
127
|
+
this.callbacks.onWindowUnregistered?.(windowId);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Handle window focus event.
|
|
131
|
+
*/
|
|
132
|
+
handleWindowFocus(windowId) {
|
|
133
|
+
const registration = this.windows.get(windowId);
|
|
134
|
+
if (registration) {
|
|
135
|
+
registration.isFocused = true;
|
|
136
|
+
registration.lastActivityAt = Date.now();
|
|
137
|
+
}
|
|
138
|
+
this.focusedWindowId = windowId;
|
|
139
|
+
this.callbacks.onFocusChanged?.(windowId);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Handle window blur event.
|
|
143
|
+
*/
|
|
144
|
+
handleWindowBlur(windowId) {
|
|
145
|
+
const registration = this.windows.get(windowId);
|
|
146
|
+
if (registration) {
|
|
147
|
+
registration.isFocused = false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// ============================================================================
|
|
151
|
+
// Broadcasting
|
|
152
|
+
// ============================================================================
|
|
153
|
+
/**
|
|
154
|
+
* Broadcast a database change to all windows.
|
|
155
|
+
*/
|
|
156
|
+
broadcastChange(change, excludeWindowId) {
|
|
157
|
+
if (!this.config.broadcastChanges)
|
|
158
|
+
return;
|
|
159
|
+
const event = {
|
|
160
|
+
...change,
|
|
161
|
+
timestamp: Date.now(),
|
|
162
|
+
sourceWindowId: excludeWindowId
|
|
163
|
+
};
|
|
164
|
+
const windows = import_electron.BrowserWindow.getAllWindows();
|
|
165
|
+
for (const win of windows) {
|
|
166
|
+
if (win.id === excludeWindowId)
|
|
167
|
+
continue;
|
|
168
|
+
const registration = this.windows.get(win.id);
|
|
169
|
+
if (registration?.name && this.config.excludeWindows.includes(registration.name)) {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
if (registration && !registration.subscribedToChanges) {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (!win.isDestroyed()) {
|
|
176
|
+
win.webContents.send(import_channels.BROADCAST_CHANNELS.DB_CHANGE, event);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
this.log(`Broadcasted change to ${windows.length - (excludeWindowId ? 1 : 0)} windows`);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Broadcast connection state change to all windows.
|
|
183
|
+
*/
|
|
184
|
+
broadcastConnectionState(state, error) {
|
|
185
|
+
const event = {
|
|
186
|
+
state,
|
|
187
|
+
timestamp: Date.now(),
|
|
188
|
+
error: error ? {
|
|
189
|
+
code: error.name,
|
|
190
|
+
message: error.message
|
|
191
|
+
} : void 0
|
|
192
|
+
};
|
|
193
|
+
const windows = import_electron.BrowserWindow.getAllWindows();
|
|
194
|
+
for (const win of windows) {
|
|
195
|
+
if (!win.isDestroyed()) {
|
|
196
|
+
win.webContents.send(import_channels.BROADCAST_CHANNELS.CONNECTION_STATE, event);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Send a message to a specific window.
|
|
202
|
+
*/
|
|
203
|
+
sendToWindow(windowId, channel, data) {
|
|
204
|
+
const win = import_electron.BrowserWindow.fromId(windowId);
|
|
205
|
+
if (!win || win.isDestroyed()) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
win.webContents.send(channel, data);
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Send a message to the focused window.
|
|
213
|
+
*/
|
|
214
|
+
sendToFocusedWindow(channel, data) {
|
|
215
|
+
if (!this.focusedWindowId) {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
return this.sendToWindow(this.focusedWindowId, channel, data);
|
|
219
|
+
}
|
|
220
|
+
// ============================================================================
|
|
221
|
+
// Subscription Management
|
|
222
|
+
// ============================================================================
|
|
223
|
+
/**
|
|
224
|
+
* Subscribe a window to database changes.
|
|
225
|
+
*/
|
|
226
|
+
subscribeWindow(windowId) {
|
|
227
|
+
const registration = this.windows.get(windowId);
|
|
228
|
+
if (registration) {
|
|
229
|
+
registration.subscribedToChanges = true;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Unsubscribe a window from database changes.
|
|
234
|
+
*/
|
|
235
|
+
unsubscribeWindow(windowId) {
|
|
236
|
+
const registration = this.windows.get(windowId);
|
|
237
|
+
if (registration) {
|
|
238
|
+
registration.subscribedToChanges = false;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// ============================================================================
|
|
242
|
+
// Query Methods
|
|
243
|
+
// ============================================================================
|
|
244
|
+
/**
|
|
245
|
+
* Get all registered windows.
|
|
246
|
+
*/
|
|
247
|
+
getWindows() {
|
|
248
|
+
return Array.from(this.windows.values());
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Get a specific window registration.
|
|
252
|
+
*/
|
|
253
|
+
getWindow(windowId) {
|
|
254
|
+
return this.windows.get(windowId);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Get the focused window ID.
|
|
258
|
+
*/
|
|
259
|
+
getFocusedWindowId() {
|
|
260
|
+
return this.focusedWindowId;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Get the focused window registration.
|
|
264
|
+
*/
|
|
265
|
+
getFocusedWindow() {
|
|
266
|
+
if (!this.focusedWindowId)
|
|
267
|
+
return void 0;
|
|
268
|
+
return this.windows.get(this.focusedWindowId);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Get window count.
|
|
272
|
+
*/
|
|
273
|
+
getWindowCount() {
|
|
274
|
+
return this.windows.size;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Check if a window is registered.
|
|
278
|
+
*/
|
|
279
|
+
hasWindow(windowId) {
|
|
280
|
+
return this.windows.has(windowId);
|
|
281
|
+
}
|
|
282
|
+
// ============================================================================
|
|
283
|
+
// Utilities
|
|
284
|
+
// ============================================================================
|
|
285
|
+
/**
|
|
286
|
+
* Update window activity timestamp.
|
|
287
|
+
*/
|
|
288
|
+
updateActivity(windowId) {
|
|
289
|
+
const registration = this.windows.get(windowId);
|
|
290
|
+
if (registration) {
|
|
291
|
+
registration.lastActivityAt = Date.now();
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Get statistics about windows.
|
|
296
|
+
*/
|
|
297
|
+
getStats() {
|
|
298
|
+
const subscribed = Array.from(this.windows.values()).filter((w) => w.subscribedToChanges).length;
|
|
299
|
+
return {
|
|
300
|
+
totalWindows: this.windows.size,
|
|
301
|
+
subscribedWindows: subscribed,
|
|
302
|
+
focusedWindowId: this.focusedWindowId
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Log a message if verbose mode is enabled.
|
|
307
|
+
*/
|
|
308
|
+
log(message) {
|
|
309
|
+
if (this.config.verbose) {
|
|
310
|
+
console.log(`[WindowManager] ${message}`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function createWindowManager(config = {}, callbacks = {}) {
|
|
315
|
+
return new WindowManager(config, callbacks);
|
|
316
|
+
}
|
|
317
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
318
|
+
0 && (module.exports = {
|
|
319
|
+
WindowManager,
|
|
320
|
+
createWindowManager
|
|
321
|
+
});
|