@framers/sql-storage-adapter 0.4.2 → 0.5.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 +94 -2
- package/dist/adapters/electron/electronMainAdapter.d.ts +241 -0
- package/dist/adapters/electron/electronMainAdapter.d.ts.map +1 -0
- package/dist/adapters/electron/electronMainAdapter.js +442 -0
- package/dist/adapters/electron/electronMainAdapter.js.map +1 -0
- package/dist/adapters/electron/electronRendererAdapter.d.ts +177 -0
- package/dist/adapters/electron/electronRendererAdapter.d.ts.map +1 -0
- package/dist/adapters/electron/electronRendererAdapter.js +339 -0
- package/dist/adapters/electron/electronRendererAdapter.js.map +1 -0
- package/dist/adapters/electron/index.d.ts +74 -0
- package/dist/adapters/electron/index.d.ts.map +1 -0
- package/dist/adapters/electron/index.js +96 -0
- package/dist/adapters/electron/index.js.map +1 -0
- package/dist/adapters/electron/ipc/channels.d.ts +196 -0
- package/dist/adapters/electron/ipc/channels.d.ts.map +1 -0
- package/dist/adapters/electron/ipc/channels.js +121 -0
- package/dist/adapters/electron/ipc/channels.js.map +1 -0
- package/dist/adapters/electron/ipc/index.d.ts +11 -0
- package/dist/adapters/electron/ipc/index.d.ts.map +1 -0
- package/dist/adapters/electron/ipc/index.js +11 -0
- package/dist/adapters/electron/ipc/index.js.map +1 -0
- package/dist/adapters/electron/ipc/protocol.d.ts +78 -0
- package/dist/adapters/electron/ipc/protocol.d.ts.map +1 -0
- package/dist/adapters/electron/ipc/protocol.js +347 -0
- package/dist/adapters/electron/ipc/protocol.js.map +1 -0
- package/dist/adapters/electron/ipc/types.d.ts +248 -0
- package/dist/adapters/electron/ipc/types.d.ts.map +1 -0
- package/dist/adapters/electron/ipc/types.js +8 -0
- package/dist/adapters/electron/ipc/types.js.map +1 -0
- package/dist/adapters/electron/migration/autoMigrator.d.ts +184 -0
- package/dist/adapters/electron/migration/autoMigrator.d.ts.map +1 -0
- package/dist/adapters/electron/migration/autoMigrator.js +478 -0
- package/dist/adapters/electron/migration/autoMigrator.js.map +1 -0
- package/dist/adapters/electron/migration/index.d.ts +9 -0
- package/dist/adapters/electron/migration/index.d.ts.map +1 -0
- package/dist/adapters/electron/migration/index.js +9 -0
- package/dist/adapters/electron/migration/index.js.map +1 -0
- package/dist/adapters/electron/preload.d.ts +126 -0
- package/dist/adapters/electron/preload.d.ts.map +1 -0
- package/dist/adapters/electron/preload.js +254 -0
- package/dist/adapters/electron/preload.js.map +1 -0
- package/dist/adapters/electron/recovery/corruptionDetector.d.ts +214 -0
- package/dist/adapters/electron/recovery/corruptionDetector.d.ts.map +1 -0
- package/dist/adapters/electron/recovery/corruptionDetector.js +410 -0
- package/dist/adapters/electron/recovery/corruptionDetector.js.map +1 -0
- package/dist/adapters/electron/recovery/index.d.ts +11 -0
- package/dist/adapters/electron/recovery/index.d.ts.map +1 -0
- package/dist/adapters/electron/recovery/index.js +11 -0
- package/dist/adapters/electron/recovery/index.js.map +1 -0
- package/dist/adapters/electron/recovery/walCheckpoint.d.ts +186 -0
- package/dist/adapters/electron/recovery/walCheckpoint.d.ts.map +1 -0
- package/dist/adapters/electron/recovery/walCheckpoint.js +302 -0
- package/dist/adapters/electron/recovery/walCheckpoint.js.map +1 -0
- package/dist/adapters/electron/window/index.d.ts +9 -0
- package/dist/adapters/electron/window/index.d.ts.map +1 -0
- package/dist/adapters/electron/window/index.js +9 -0
- package/dist/adapters/electron/window/index.js.map +1 -0
- package/dist/adapters/electron/window/windowManager.d.ts +190 -0
- package/dist/adapters/electron/window/windowManager.d.ts.map +1 -0
- package/dist/adapters/electron/window/windowManager.js +358 -0
- package/dist/adapters/electron/window/windowManager.js.map +1 -0
- package/dist/core/contracts/context.d.ts +2 -2
- package/dist/core/contracts/context.d.ts.map +1 -1
- package/dist/core/database.d.ts +19 -0
- package/dist/core/database.d.ts.map +1 -1
- package/dist/core/database.js +4 -0
- package/dist/core/database.js.map +1 -1
- package/dist/core/resolver.d.ts +3 -0
- package/dist/core/resolver.d.ts.map +1 -1
- package/dist/core/resolver.js +39 -3
- package/dist/core/resolver.js.map +1 -1
- package/dist/features/sync/conflicts/conflictResolver.d.ts +222 -0
- package/dist/features/sync/conflicts/conflictResolver.d.ts.map +1 -0
- package/dist/features/sync/conflicts/conflictResolver.js +396 -0
- package/dist/features/sync/conflicts/conflictResolver.js.map +1 -0
- package/dist/features/sync/conflicts/index.d.ts +9 -0
- package/dist/features/sync/conflicts/index.d.ts.map +1 -0
- package/dist/features/sync/conflicts/index.js +9 -0
- package/dist/features/sync/conflicts/index.js.map +1 -0
- package/dist/features/sync/crossPlatformSync.d.ts +281 -0
- package/dist/features/sync/crossPlatformSync.d.ts.map +1 -0
- package/dist/features/sync/crossPlatformSync.js +623 -0
- package/dist/features/sync/crossPlatformSync.js.map +1 -0
- package/dist/features/sync/devices/deviceManager.d.ts +243 -0
- package/dist/features/sync/devices/deviceManager.d.ts.map +1 -0
- package/dist/features/sync/devices/deviceManager.js +494 -0
- package/dist/features/sync/devices/deviceManager.js.map +1 -0
- package/dist/features/sync/devices/index.d.ts +10 -0
- package/dist/features/sync/devices/index.d.ts.map +1 -0
- package/dist/features/sync/devices/index.js +10 -0
- package/dist/features/sync/devices/index.js.map +1 -0
- package/dist/features/sync/index.d.ts +37 -0
- package/dist/features/sync/index.d.ts.map +1 -0
- package/dist/features/sync/index.js +47 -0
- package/dist/features/sync/index.js.map +1 -0
- package/dist/features/sync/protocol/index.d.ts +11 -0
- package/dist/features/sync/protocol/index.d.ts.map +1 -0
- package/dist/features/sync/protocol/index.js +11 -0
- package/dist/features/sync/protocol/index.js.map +1 -0
- package/dist/features/sync/protocol/messages.d.ts +348 -0
- package/dist/features/sync/protocol/messages.d.ts.map +1 -0
- package/dist/features/sync/protocol/messages.js +216 -0
- package/dist/features/sync/protocol/messages.js.map +1 -0
- package/dist/features/sync/protocol/vectorClock.d.ts +164 -0
- package/dist/features/sync/protocol/vectorClock.d.ts.map +1 -0
- package/dist/features/sync/protocol/vectorClock.js +286 -0
- package/dist/features/sync/protocol/vectorClock.js.map +1 -0
- package/dist/features/sync/tables/index.d.ts +10 -0
- package/dist/features/sync/tables/index.d.ts.map +1 -0
- package/dist/features/sync/tables/index.js +10 -0
- package/dist/features/sync/tables/index.js.map +1 -0
- package/dist/features/sync/tables/syncLogManager.d.ts +216 -0
- package/dist/features/sync/tables/syncLogManager.d.ts.map +1 -0
- package/dist/features/sync/tables/syncLogManager.js +456 -0
- package/dist/features/sync/tables/syncLogManager.js.map +1 -0
- package/dist/features/sync/transport/httpTransport.d.ts +123 -0
- package/dist/features/sync/transport/httpTransport.d.ts.map +1 -0
- package/dist/features/sync/transport/httpTransport.js +380 -0
- package/dist/features/sync/transport/httpTransport.js.map +1 -0
- package/dist/features/sync/transport/index.d.ts +12 -0
- package/dist/features/sync/transport/index.d.ts.map +1 -0
- package/dist/features/sync/transport/index.js +12 -0
- package/dist/features/sync/transport/index.js.map +1 -0
- package/dist/features/sync/transport/transport.d.ts +259 -0
- package/dist/features/sync/transport/transport.d.ts.map +1 -0
- package/dist/features/sync/transport/transport.js +153 -0
- package/dist/features/sync/transport/transport.js.map +1 -0
- package/dist/features/sync/transport/websocketTransport.d.ts +126 -0
- package/dist/features/sync/transport/websocketTransport.d.ts.map +1 -0
- package/dist/features/sync/transport/websocketTransport.js +374 -0
- package/dist/features/sync/transport/websocketTransport.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/package.json +21 -1
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-Platform Sync Protocol Messages.
|
|
3
|
+
*
|
|
4
|
+
* Defines the message format for device-to-device synchronization.
|
|
5
|
+
* Messages are exchanged over WebSocket or HTTP transport.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import type { VectorClockData } from './vectorClock';
|
|
10
|
+
/**
|
|
11
|
+
* Type of device in the sync network.
|
|
12
|
+
*/
|
|
13
|
+
export type DeviceType = 'electron' | 'capacitor' | 'browser' | 'server';
|
|
14
|
+
/**
|
|
15
|
+
* Device information.
|
|
16
|
+
*/
|
|
17
|
+
export interface DeviceInfo {
|
|
18
|
+
/** Unique device identifier */
|
|
19
|
+
deviceId: string;
|
|
20
|
+
/** Device type */
|
|
21
|
+
deviceType: DeviceType;
|
|
22
|
+
/** Human-readable device name */
|
|
23
|
+
deviceName?: string;
|
|
24
|
+
/** App version running on device */
|
|
25
|
+
appVersion?: string;
|
|
26
|
+
/** Platform info (e.g., "macOS 14.0", "iOS 17.0") */
|
|
27
|
+
platform?: string;
|
|
28
|
+
/** When device was first seen */
|
|
29
|
+
firstSeen?: number;
|
|
30
|
+
/** When device was last active */
|
|
31
|
+
lastSeen?: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Type of database operation.
|
|
35
|
+
*/
|
|
36
|
+
export type ChangeOperation = 'INSERT' | 'UPDATE' | 'DELETE';
|
|
37
|
+
/**
|
|
38
|
+
* A single database change record.
|
|
39
|
+
*/
|
|
40
|
+
export interface ChangeRecord {
|
|
41
|
+
/** Unique change ID (UUID) */
|
|
42
|
+
changeId: string;
|
|
43
|
+
/** Table name */
|
|
44
|
+
table: string;
|
|
45
|
+
/** Record primary key */
|
|
46
|
+
recordId: string;
|
|
47
|
+
/** Type of operation */
|
|
48
|
+
operation: ChangeOperation;
|
|
49
|
+
/** Vector clock at time of change */
|
|
50
|
+
vectorClock: VectorClockData;
|
|
51
|
+
/** Device that made the change */
|
|
52
|
+
deviceId: string;
|
|
53
|
+
/** Record data before change (for UPDATE/DELETE) */
|
|
54
|
+
oldData?: Record<string, unknown>;
|
|
55
|
+
/** Record data after change (for INSERT/UPDATE) */
|
|
56
|
+
newData?: Record<string, unknown>;
|
|
57
|
+
/** When change was made (local timestamp) */
|
|
58
|
+
timestamp: number;
|
|
59
|
+
/** Whether change has been synced */
|
|
60
|
+
synced?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Batch of changes for efficient transfer.
|
|
64
|
+
*/
|
|
65
|
+
export interface ChangeBatch {
|
|
66
|
+
/** Changes in this batch */
|
|
67
|
+
changes: ChangeRecord[];
|
|
68
|
+
/** Batch sequence number */
|
|
69
|
+
sequence: number;
|
|
70
|
+
/** Total batches in this sync */
|
|
71
|
+
totalBatches: number;
|
|
72
|
+
/** Compressed (gzip/brotli) if true */
|
|
73
|
+
compressed?: boolean;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Current sync status.
|
|
77
|
+
*/
|
|
78
|
+
export type SyncStatus = 'idle' | 'connecting' | 'handshaking' | 'syncing' | 'resolving' | 'error' | 'disconnected';
|
|
79
|
+
/**
|
|
80
|
+
* Sync progress information.
|
|
81
|
+
*/
|
|
82
|
+
export interface SyncProgress {
|
|
83
|
+
status: SyncStatus;
|
|
84
|
+
/** Records pushed to remote */
|
|
85
|
+
pushed: number;
|
|
86
|
+
/** Records pulled from remote */
|
|
87
|
+
pulled: number;
|
|
88
|
+
/** Conflicts detected */
|
|
89
|
+
conflicts: number;
|
|
90
|
+
/** Current table being synced */
|
|
91
|
+
currentTable?: string;
|
|
92
|
+
/** Progress percentage (0-100) */
|
|
93
|
+
percent: number;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Base message structure.
|
|
97
|
+
*/
|
|
98
|
+
export interface BaseMessage {
|
|
99
|
+
/** Message type discriminator */
|
|
100
|
+
type: string;
|
|
101
|
+
/** Unique message ID for acknowledgment */
|
|
102
|
+
messageId: string;
|
|
103
|
+
/** Sender device ID */
|
|
104
|
+
deviceId: string;
|
|
105
|
+
/** Message timestamp */
|
|
106
|
+
timestamp: number;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Handshake request - initiates connection.
|
|
110
|
+
*/
|
|
111
|
+
export interface HandshakeRequest extends BaseMessage {
|
|
112
|
+
type: 'handshake_request';
|
|
113
|
+
/** Sender device info */
|
|
114
|
+
device: DeviceInfo;
|
|
115
|
+
/** Current vector clock */
|
|
116
|
+
vectorClock: VectorClockData;
|
|
117
|
+
/** Supported protocol version */
|
|
118
|
+
protocolVersion: number;
|
|
119
|
+
/** Capabilities (e.g., compression, encryption) */
|
|
120
|
+
capabilities: string[];
|
|
121
|
+
/** Tables to sync */
|
|
122
|
+
tables: string[];
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Handshake response - confirms connection.
|
|
126
|
+
*/
|
|
127
|
+
export interface HandshakeResponse extends BaseMessage {
|
|
128
|
+
type: 'handshake_response';
|
|
129
|
+
/** Whether handshake accepted */
|
|
130
|
+
accepted: boolean;
|
|
131
|
+
/** Rejection reason if not accepted */
|
|
132
|
+
rejectionReason?: string;
|
|
133
|
+
/** Server device info */
|
|
134
|
+
device: DeviceInfo;
|
|
135
|
+
/** Server's vector clock */
|
|
136
|
+
vectorClock: VectorClockData;
|
|
137
|
+
/** Negotiated protocol version */
|
|
138
|
+
protocolVersion: number;
|
|
139
|
+
/** Negotiated capabilities */
|
|
140
|
+
capabilities: string[];
|
|
141
|
+
/** Session ID for this connection */
|
|
142
|
+
sessionId: string;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Delta push - send local changes to remote.
|
|
146
|
+
*/
|
|
147
|
+
export interface DeltaPush extends BaseMessage {
|
|
148
|
+
type: 'delta_push';
|
|
149
|
+
/** Batch of changes */
|
|
150
|
+
batch: ChangeBatch;
|
|
151
|
+
/** Current vector clock after changes */
|
|
152
|
+
vectorClock: VectorClockData;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Delta pull request - request changes since clock.
|
|
156
|
+
*/
|
|
157
|
+
export interface DeltaPullRequest extends BaseMessage {
|
|
158
|
+
type: 'delta_pull_request';
|
|
159
|
+
/** Vector clock to sync from */
|
|
160
|
+
sinceVectorClock: VectorClockData;
|
|
161
|
+
/** Tables to pull */
|
|
162
|
+
tables?: string[];
|
|
163
|
+
/** Maximum records to return */
|
|
164
|
+
limit?: number;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Delta pull response - changes from remote.
|
|
168
|
+
*/
|
|
169
|
+
export interface DeltaPullResponse extends BaseMessage {
|
|
170
|
+
type: 'delta_pull_response';
|
|
171
|
+
/** Batch of changes */
|
|
172
|
+
batch: ChangeBatch;
|
|
173
|
+
/** Server's current vector clock */
|
|
174
|
+
vectorClock: VectorClockData;
|
|
175
|
+
/** Whether more changes available */
|
|
176
|
+
hasMore: boolean;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Acknowledgment message.
|
|
180
|
+
*/
|
|
181
|
+
export interface AckMessage extends BaseMessage {
|
|
182
|
+
type: 'ack';
|
|
183
|
+
/** ID of message being acknowledged */
|
|
184
|
+
ackMessageId: string;
|
|
185
|
+
/** Success status */
|
|
186
|
+
success: boolean;
|
|
187
|
+
/** Error message if failed */
|
|
188
|
+
error?: string;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Conflict notification.
|
|
192
|
+
*/
|
|
193
|
+
export interface ConflictMessage extends BaseMessage {
|
|
194
|
+
type: 'conflict';
|
|
195
|
+
/** Table with conflict */
|
|
196
|
+
table: string;
|
|
197
|
+
/** Record ID with conflict */
|
|
198
|
+
recordId: string;
|
|
199
|
+
/** Local version */
|
|
200
|
+
localData: Record<string, unknown>;
|
|
201
|
+
/** Remote version */
|
|
202
|
+
remoteData: Record<string, unknown>;
|
|
203
|
+
/** Local vector clock */
|
|
204
|
+
localClock: VectorClockData;
|
|
205
|
+
/** Remote vector clock */
|
|
206
|
+
remoteClock: VectorClockData;
|
|
207
|
+
/** Suggested resolution */
|
|
208
|
+
suggestedResolution?: 'use_local' | 'use_remote' | 'merge';
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Conflict resolution.
|
|
212
|
+
*/
|
|
213
|
+
export interface ConflictResolution extends BaseMessage {
|
|
214
|
+
type: 'conflict_resolution';
|
|
215
|
+
/** Original conflict message ID */
|
|
216
|
+
conflictMessageId: string;
|
|
217
|
+
/** Resolution strategy */
|
|
218
|
+
resolution: 'use_local' | 'use_remote' | 'use_merged' | 'keep_both' | 'defer';
|
|
219
|
+
/** Merged data if using 'use_merged' */
|
|
220
|
+
mergedData?: Record<string, unknown>;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Device presence update.
|
|
224
|
+
*/
|
|
225
|
+
export interface PresenceMessage extends BaseMessage {
|
|
226
|
+
type: 'presence';
|
|
227
|
+
/** Presence status */
|
|
228
|
+
status: 'online' | 'offline' | 'away' | 'syncing';
|
|
229
|
+
/** Device info */
|
|
230
|
+
device: DeviceInfo;
|
|
231
|
+
/** Current vector clock */
|
|
232
|
+
vectorClock?: VectorClockData;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Heartbeat for connection keep-alive.
|
|
236
|
+
*/
|
|
237
|
+
export interface HeartbeatMessage extends BaseMessage {
|
|
238
|
+
type: 'heartbeat';
|
|
239
|
+
/** Sequence number */
|
|
240
|
+
sequence: number;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Heartbeat acknowledgment.
|
|
244
|
+
*/
|
|
245
|
+
export interface HeartbeatAck extends BaseMessage {
|
|
246
|
+
type: 'heartbeat_ack';
|
|
247
|
+
/** Echo sequence number */
|
|
248
|
+
sequence: number;
|
|
249
|
+
/** Round-trip time if measurable */
|
|
250
|
+
rtt?: number;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Error message.
|
|
254
|
+
*/
|
|
255
|
+
export interface ErrorMessage extends BaseMessage {
|
|
256
|
+
type: 'error';
|
|
257
|
+
/** Error code */
|
|
258
|
+
code: string;
|
|
259
|
+
/** Human-readable message */
|
|
260
|
+
message: string;
|
|
261
|
+
/** Whether error is recoverable */
|
|
262
|
+
recoverable: boolean;
|
|
263
|
+
/** Related message ID if applicable */
|
|
264
|
+
relatedMessageId?: string;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* All possible sync messages.
|
|
268
|
+
*/
|
|
269
|
+
export type SyncMessage = HandshakeRequest | HandshakeResponse | DeltaPush | DeltaPullRequest | DeltaPullResponse | AckMessage | ConflictMessage | ConflictResolution | PresenceMessage | HeartbeatMessage | HeartbeatAck | ErrorMessage;
|
|
270
|
+
/**
|
|
271
|
+
* Message type discriminator values.
|
|
272
|
+
*/
|
|
273
|
+
export type SyncMessageType = SyncMessage['type'];
|
|
274
|
+
/**
|
|
275
|
+
* Generate a unique message ID.
|
|
276
|
+
*/
|
|
277
|
+
export declare function generateMessageId(): string;
|
|
278
|
+
/**
|
|
279
|
+
* Create a base message with common fields.
|
|
280
|
+
*/
|
|
281
|
+
export declare function createBaseMessage(type: string, deviceId: string): Omit<BaseMessage, 'type'> & {
|
|
282
|
+
type: string;
|
|
283
|
+
};
|
|
284
|
+
/**
|
|
285
|
+
* Create a handshake request message.
|
|
286
|
+
*/
|
|
287
|
+
export declare function createHandshakeRequest(device: DeviceInfo, vectorClock: VectorClockData, tables: string[], capabilities?: string[]): HandshakeRequest;
|
|
288
|
+
/**
|
|
289
|
+
* Create an acknowledgment message.
|
|
290
|
+
*/
|
|
291
|
+
export declare function createAck(deviceId: string, ackMessageId: string, success: boolean, error?: string): AckMessage;
|
|
292
|
+
/**
|
|
293
|
+
* Create a heartbeat message.
|
|
294
|
+
*/
|
|
295
|
+
export declare function createHeartbeat(deviceId: string, sequence: number): HeartbeatMessage;
|
|
296
|
+
/**
|
|
297
|
+
* Create an error message.
|
|
298
|
+
*/
|
|
299
|
+
export declare function createError(deviceId: string, code: string, message: string, recoverable?: boolean, relatedMessageId?: string): ErrorMessage;
|
|
300
|
+
/**
|
|
301
|
+
* Check if message is a handshake request.
|
|
302
|
+
*/
|
|
303
|
+
export declare function isHandshakeRequest(msg: SyncMessage): msg is HandshakeRequest;
|
|
304
|
+
/**
|
|
305
|
+
* Check if message is a delta push.
|
|
306
|
+
*/
|
|
307
|
+
export declare function isDeltaPush(msg: SyncMessage): msg is DeltaPush;
|
|
308
|
+
/**
|
|
309
|
+
* Check if message is a conflict.
|
|
310
|
+
*/
|
|
311
|
+
export declare function isConflict(msg: SyncMessage): msg is ConflictMessage;
|
|
312
|
+
/**
|
|
313
|
+
* Check if message is an error.
|
|
314
|
+
*/
|
|
315
|
+
export declare function isError(msg: SyncMessage): msg is ErrorMessage;
|
|
316
|
+
/**
|
|
317
|
+
* Type guard to check if an unknown value is a valid SyncMessage.
|
|
318
|
+
*/
|
|
319
|
+
export declare function isSyncMessage(value: unknown): value is SyncMessage;
|
|
320
|
+
/**
|
|
321
|
+
* Create a delta push message.
|
|
322
|
+
*/
|
|
323
|
+
export declare function createDeltaPushMessage(deviceId: string, changes: ChangeRecord[], vectorClock: VectorClockData, sequence?: number, totalBatches?: number): DeltaPush;
|
|
324
|
+
/**
|
|
325
|
+
* Create a delta pull request message.
|
|
326
|
+
*/
|
|
327
|
+
export declare function createDeltaPullRequest(deviceId: string, sinceVectorClock: VectorClockData, tables?: string[], limit?: number): DeltaPullRequest;
|
|
328
|
+
/**
|
|
329
|
+
* Create a presence message.
|
|
330
|
+
*/
|
|
331
|
+
export declare function createPresenceMessage(device: DeviceInfo, status: 'online' | 'offline' | 'away' | 'syncing', vectorClock?: VectorClockData): PresenceMessage;
|
|
332
|
+
/**
|
|
333
|
+
* Create a heartbeat message.
|
|
334
|
+
*/
|
|
335
|
+
export declare function createHeartbeatMessage(deviceId: string, sequence?: number): HeartbeatMessage;
|
|
336
|
+
/**
|
|
337
|
+
* Create an ack message.
|
|
338
|
+
*/
|
|
339
|
+
export declare function createAckMessage(deviceId: string, ackMessageId: string, success?: boolean, error?: string): AckMessage;
|
|
340
|
+
/**
|
|
341
|
+
* Generate a unique change ID.
|
|
342
|
+
*/
|
|
343
|
+
export declare function generateChangeId(): string;
|
|
344
|
+
/**
|
|
345
|
+
* Create a change record.
|
|
346
|
+
*/
|
|
347
|
+
export declare function createChangeRecord(table: string, recordId: string, operation: ChangeOperation, deviceId: string, vectorClock: VectorClockData, newData?: Record<string, unknown>, oldData?: Record<string, unknown>): ChangeRecord;
|
|
348
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../../src/features/sync/protocol/messages.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAMrD;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEzE;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB;IAClB,UAAU,EAAE,UAAU,CAAC;IACvB,iCAAiC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oCAAoC;IACpC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qDAAqD;IACrD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kCAAkC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAMD;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,8BAA8B;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,yBAAyB;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,wBAAwB;IACxB,SAAS,EAAE,eAAe,CAAC;IAC3B,qCAAqC;IACrC,WAAW,EAAE,eAAe,CAAC;IAC7B,kCAAkC;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,oDAAoD;IACpD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,O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AM,CAAC,EAAE,MAAM,EAAE,EACjB,KAAK,CAAC,EAAE,MAAM,GACb,gBAAgB,CAQlB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,EACjD,WAAW,CAAC,EAAE,eAAe,GAC5B,eAAe,CAQjB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,SAAI,GAAG,gBAAgB,CAMvF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,OAAO,UAAO,EACd,KAAK,CAAC,EAAE,MAAM,GACb,UAAU,CAQZ;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAIzC;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,eAAe,EAC1B,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,eAAe,EAC5B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,YAAY,CAad"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-Platform Sync Protocol Messages.
|
|
3
|
+
*
|
|
4
|
+
* Defines the message format for device-to-device synchronization.
|
|
5
|
+
* Messages are exchanged over WebSocket or HTTP transport.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// Factory Functions
|
|
11
|
+
// ============================================================================
|
|
12
|
+
/**
|
|
13
|
+
* Generate a unique message ID.
|
|
14
|
+
*/
|
|
15
|
+
export function generateMessageId() {
|
|
16
|
+
const timestamp = Date.now().toString(36);
|
|
17
|
+
const random = Math.random().toString(36).substring(2, 10);
|
|
18
|
+
return `msg_${timestamp}_${random}`;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create a base message with common fields.
|
|
22
|
+
*/
|
|
23
|
+
export function createBaseMessage(type, deviceId) {
|
|
24
|
+
return {
|
|
25
|
+
type,
|
|
26
|
+
messageId: generateMessageId(),
|
|
27
|
+
deviceId,
|
|
28
|
+
timestamp: Date.now(),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create a handshake request message.
|
|
33
|
+
*/
|
|
34
|
+
export function createHandshakeRequest(device, vectorClock, tables, capabilities = ['gzip', 'delta']) {
|
|
35
|
+
return {
|
|
36
|
+
...createBaseMessage('handshake_request', device.deviceId),
|
|
37
|
+
type: 'handshake_request',
|
|
38
|
+
device,
|
|
39
|
+
vectorClock,
|
|
40
|
+
protocolVersion: 1,
|
|
41
|
+
capabilities,
|
|
42
|
+
tables,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Create an acknowledgment message.
|
|
47
|
+
*/
|
|
48
|
+
export function createAck(deviceId, ackMessageId, success, error) {
|
|
49
|
+
return {
|
|
50
|
+
...createBaseMessage('ack', deviceId),
|
|
51
|
+
type: 'ack',
|
|
52
|
+
ackMessageId,
|
|
53
|
+
success,
|
|
54
|
+
error,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Create a heartbeat message.
|
|
59
|
+
*/
|
|
60
|
+
export function createHeartbeat(deviceId, sequence) {
|
|
61
|
+
return {
|
|
62
|
+
...createBaseMessage('heartbeat', deviceId),
|
|
63
|
+
type: 'heartbeat',
|
|
64
|
+
sequence,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Create an error message.
|
|
69
|
+
*/
|
|
70
|
+
export function createError(deviceId, code, message, recoverable = true, relatedMessageId) {
|
|
71
|
+
return {
|
|
72
|
+
...createBaseMessage('error', deviceId),
|
|
73
|
+
type: 'error',
|
|
74
|
+
code,
|
|
75
|
+
message,
|
|
76
|
+
recoverable,
|
|
77
|
+
relatedMessageId,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
// ============================================================================
|
|
81
|
+
// Type Guards
|
|
82
|
+
// ============================================================================
|
|
83
|
+
/**
|
|
84
|
+
* Check if message is a handshake request.
|
|
85
|
+
*/
|
|
86
|
+
export function isHandshakeRequest(msg) {
|
|
87
|
+
return msg.type === 'handshake_request';
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Check if message is a delta push.
|
|
91
|
+
*/
|
|
92
|
+
export function isDeltaPush(msg) {
|
|
93
|
+
return msg.type === 'delta_push';
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Check if message is a conflict.
|
|
97
|
+
*/
|
|
98
|
+
export function isConflict(msg) {
|
|
99
|
+
return msg.type === 'conflict';
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Check if message is an error.
|
|
103
|
+
*/
|
|
104
|
+
export function isError(msg) {
|
|
105
|
+
return msg.type === 'error';
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Type guard to check if an unknown value is a valid SyncMessage.
|
|
109
|
+
*/
|
|
110
|
+
export function isSyncMessage(value) {
|
|
111
|
+
if (!value || typeof value !== 'object')
|
|
112
|
+
return false;
|
|
113
|
+
const msg = value;
|
|
114
|
+
if (typeof msg.type !== 'string')
|
|
115
|
+
return false;
|
|
116
|
+
if (typeof msg.messageId !== 'string')
|
|
117
|
+
return false;
|
|
118
|
+
if (typeof msg.deviceId !== 'string')
|
|
119
|
+
return false;
|
|
120
|
+
if (typeof msg.timestamp !== 'number')
|
|
121
|
+
return false;
|
|
122
|
+
const validTypes = [
|
|
123
|
+
'handshake_request', 'handshake_response',
|
|
124
|
+
'delta_push', 'delta_pull_request', 'delta_pull_response',
|
|
125
|
+
'ack', 'conflict', 'conflict_resolution',
|
|
126
|
+
'presence', 'heartbeat', 'heartbeat_ack', 'error',
|
|
127
|
+
];
|
|
128
|
+
return validTypes.includes(msg.type);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Create a delta push message.
|
|
132
|
+
*/
|
|
133
|
+
export function createDeltaPushMessage(deviceId, changes, vectorClock, sequence = 1, totalBatches = 1) {
|
|
134
|
+
return {
|
|
135
|
+
...createBaseMessage('delta_push', deviceId),
|
|
136
|
+
type: 'delta_push',
|
|
137
|
+
batch: {
|
|
138
|
+
changes,
|
|
139
|
+
sequence,
|
|
140
|
+
totalBatches,
|
|
141
|
+
},
|
|
142
|
+
vectorClock,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Create a delta pull request message.
|
|
147
|
+
*/
|
|
148
|
+
export function createDeltaPullRequest(deviceId, sinceVectorClock, tables, limit) {
|
|
149
|
+
return {
|
|
150
|
+
...createBaseMessage('delta_pull_request', deviceId),
|
|
151
|
+
type: 'delta_pull_request',
|
|
152
|
+
sinceVectorClock,
|
|
153
|
+
tables,
|
|
154
|
+
limit,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Create a presence message.
|
|
159
|
+
*/
|
|
160
|
+
export function createPresenceMessage(device, status, vectorClock) {
|
|
161
|
+
return {
|
|
162
|
+
...createBaseMessage('presence', device.deviceId),
|
|
163
|
+
type: 'presence',
|
|
164
|
+
status,
|
|
165
|
+
device,
|
|
166
|
+
vectorClock,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Create a heartbeat message.
|
|
171
|
+
*/
|
|
172
|
+
export function createHeartbeatMessage(deviceId, sequence = 0) {
|
|
173
|
+
return {
|
|
174
|
+
...createBaseMessage('heartbeat', deviceId),
|
|
175
|
+
type: 'heartbeat',
|
|
176
|
+
sequence,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Create an ack message.
|
|
181
|
+
*/
|
|
182
|
+
export function createAckMessage(deviceId, ackMessageId, success = true, error) {
|
|
183
|
+
return {
|
|
184
|
+
...createBaseMessage('ack', deviceId),
|
|
185
|
+
type: 'ack',
|
|
186
|
+
ackMessageId,
|
|
187
|
+
success,
|
|
188
|
+
error,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Generate a unique change ID.
|
|
193
|
+
*/
|
|
194
|
+
export function generateChangeId() {
|
|
195
|
+
const timestamp = Date.now().toString(36);
|
|
196
|
+
const random = Math.random().toString(36).substring(2, 10);
|
|
197
|
+
return `chg_${timestamp}_${random}`;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Create a change record.
|
|
201
|
+
*/
|
|
202
|
+
export function createChangeRecord(table, recordId, operation, deviceId, vectorClock, newData, oldData) {
|
|
203
|
+
return {
|
|
204
|
+
changeId: generateChangeId(),
|
|
205
|
+
table,
|
|
206
|
+
recordId,
|
|
207
|
+
operation,
|
|
208
|
+
deviceId,
|
|
209
|
+
vectorClock,
|
|
210
|
+
newData,
|
|
211
|
+
oldData,
|
|
212
|
+
timestamp: Date.now(),
|
|
213
|
+
synced: false,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../../../src/features/sync/protocol/messages.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAyUH,+EAA+E;AAC/E,oBAAoB;AACpB,+EAA+E;AAE/E;;GAEG;AACH,MAAM,UAAU,iBAAiB;IAC/B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,C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