@tldraw/sync-core 4.2.0-canary.fda2467026d5 → 4.2.0-next.47462e908ff5
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-cjs/index.d.ts +5 -273
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/index.js.map +1 -1
- package/dist-cjs/lib/ClientWebSocketAdapter.js.map +2 -2
- package/dist-cjs/lib/TLSyncClient.js +0 -6
- package/dist-cjs/lib/TLSyncClient.js.map +2 -2
- package/dist-esm/index.d.mts +5 -273
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/index.mjs.map +1 -1
- package/dist-esm/lib/ClientWebSocketAdapter.mjs.map +2 -2
- package/dist-esm/lib/TLSyncClient.mjs +0 -6
- package/dist-esm/lib/TLSyncClient.mjs.map +2 -2
- package/package.json +6 -6
- package/src/index.ts +1 -1
- package/src/lib/ClientWebSocketAdapter.ts +1 -4
- package/src/lib/TLSyncClient.test.ts +6 -17
- package/src/lib/TLSyncClient.ts +17 -31
- package/src/test/TestSocketPair.ts +2 -5
package/src/lib/TLSyncClient.ts
CHANGED
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
* @param cb - Callback function that receives the event value
|
|
32
32
|
* @returns Function to call when you want to unsubscribe from the events
|
|
33
33
|
*
|
|
34
|
-
* @
|
|
34
|
+
* @internal
|
|
35
35
|
*/
|
|
36
36
|
export type SubscribingFn<T> = (cb: (val: T) => void) => () => void
|
|
37
37
|
|
|
@@ -149,9 +149,9 @@ export type TLCustomMessageHandler = (this: null, data: any) => void
|
|
|
149
149
|
* Event object describing changes in socket connection status.
|
|
150
150
|
* Contains either a basic status change or an error with details.
|
|
151
151
|
*
|
|
152
|
-
* @
|
|
152
|
+
* @internal
|
|
153
153
|
*/
|
|
154
|
-
export type
|
|
154
|
+
export type TlSocketStatusChangeEvent =
|
|
155
155
|
| {
|
|
156
156
|
/** Connection came online or went offline */
|
|
157
157
|
status: 'online' | 'offline'
|
|
@@ -169,7 +169,7 @@ export type TLSocketStatusChangeEvent =
|
|
|
169
169
|
*
|
|
170
170
|
* @internal
|
|
171
171
|
*/
|
|
172
|
-
export type TLSocketStatusListener = (params:
|
|
172
|
+
export type TLSocketStatusListener = (params: TlSocketStatusChangeEvent) => void
|
|
173
173
|
|
|
174
174
|
/**
|
|
175
175
|
* Possible connection states for a persistent client socket.
|
|
@@ -183,7 +183,7 @@ export type TLPersistentClientSocketStatus = 'online' | 'offline' | 'error'
|
|
|
183
183
|
* Mode for handling presence information in sync sessions.
|
|
184
184
|
* Controls whether presence data (cursors, selections) is shared with other clients.
|
|
185
185
|
*
|
|
186
|
-
* @
|
|
186
|
+
* @internal
|
|
187
187
|
*/
|
|
188
188
|
export type TLPresenceMode =
|
|
189
189
|
/** No presence sharing - client operates independently */
|
|
@@ -217,12 +217,9 @@ export type TLPresenceMode =
|
|
|
217
217
|
* }
|
|
218
218
|
* ```
|
|
219
219
|
*
|
|
220
|
-
* @
|
|
220
|
+
* @internal
|
|
221
221
|
*/
|
|
222
|
-
export interface TLPersistentClientSocket<
|
|
223
|
-
ClientSentMessage extends object = object,
|
|
224
|
-
ServerSentMessage extends object = object,
|
|
225
|
-
> {
|
|
222
|
+
export interface TLPersistentClientSocket<R extends UnknownRecord = UnknownRecord> {
|
|
226
223
|
/** Current connection state - online means actively connected and ready */
|
|
227
224
|
connectionStatus: 'online' | 'offline' | 'error'
|
|
228
225
|
|
|
@@ -230,32 +227,27 @@ export interface TLPersistentClientSocket<
|
|
|
230
227
|
* Send a protocol message to the sync server
|
|
231
228
|
* @param msg - Message to send (connect, push, ping, etc.)
|
|
232
229
|
*/
|
|
233
|
-
sendMessage(msg:
|
|
230
|
+
sendMessage(msg: TLSocketClientSentEvent<R>): void
|
|
234
231
|
|
|
235
232
|
/**
|
|
236
233
|
* Subscribe to messages received from the server
|
|
237
234
|
* @param callback - Function called for each received message
|
|
238
235
|
* @returns Cleanup function to remove the listener
|
|
239
236
|
*/
|
|
240
|
-
onReceiveMessage: SubscribingFn<
|
|
237
|
+
onReceiveMessage: SubscribingFn<TLSocketServerSentEvent<R>>
|
|
241
238
|
|
|
242
239
|
/**
|
|
243
240
|
* Subscribe to connection status changes
|
|
244
241
|
* @param callback - Function called when connection status changes
|
|
245
242
|
* @returns Cleanup function to remove the listener
|
|
246
243
|
*/
|
|
247
|
-
onStatusChange: SubscribingFn<
|
|
244
|
+
onStatusChange: SubscribingFn<TlSocketStatusChangeEvent>
|
|
248
245
|
|
|
249
246
|
/**
|
|
250
247
|
* Force a connection restart (disconnect then reconnect)
|
|
251
248
|
* Used for error recovery or when connection health checks fail
|
|
252
249
|
*/
|
|
253
250
|
restart(): void
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Close the connection
|
|
257
|
-
*/
|
|
258
|
-
close(): void
|
|
259
251
|
}
|
|
260
252
|
|
|
261
253
|
const PING_INTERVAL = 5000
|
|
@@ -320,7 +312,7 @@ const MAX_TIME_TO_WAIT_FOR_SERVER_INTERACTION_BEFORE_RESETTING_CONNECTION = PING
|
|
|
320
312
|
* })
|
|
321
313
|
* ```
|
|
322
314
|
*
|
|
323
|
-
* @
|
|
315
|
+
* @internal
|
|
324
316
|
*/
|
|
325
317
|
export class TLSyncClient<R extends UnknownRecord, S extends Store<R> = Store<R>> {
|
|
326
318
|
/** The last clock time from the most recent server update */
|
|
@@ -343,19 +335,14 @@ export class TLSyncClient<R extends UnknownRecord, S extends Store<R> = Store<R>
|
|
|
343
335
|
|
|
344
336
|
private disposables: Array<() => void> = []
|
|
345
337
|
|
|
346
|
-
/** @internal */
|
|
347
338
|
readonly store: S
|
|
348
|
-
|
|
349
|
-
readonly socket: TLPersistentClientSocket<TLSocketClientSentEvent<R>, TLSocketServerSentEvent<R>>
|
|
339
|
+
readonly socket: TLPersistentClientSocket<R>
|
|
350
340
|
|
|
351
|
-
/** @internal */
|
|
352
341
|
readonly presenceState: Signal<R | null> | undefined
|
|
353
|
-
/** @internal */
|
|
354
342
|
readonly presenceMode: Signal<TLPresenceMode> | undefined
|
|
355
343
|
|
|
356
344
|
// isOnline is true when we have an open socket connection and we have
|
|
357
345
|
// established a connection with the server room (i.e. we have received a 'connect' message)
|
|
358
|
-
/** @internal */
|
|
359
346
|
isConnectedToRoom = false
|
|
360
347
|
|
|
361
348
|
/**
|
|
@@ -379,7 +366,7 @@ export class TLSyncClient<R extends UnknownRecord, S extends Store<R> = Store<R>
|
|
|
379
366
|
* @param details - Connection details
|
|
380
367
|
* - isReadonly - Whether the connection is in read-only mode
|
|
381
368
|
*/
|
|
382
|
-
|
|
369
|
+
public readonly onAfterConnect?: (self: this, details: { isReadonly: boolean }) => void
|
|
383
370
|
|
|
384
371
|
private readonly onCustomMessageReceived?: TLCustomMessageHandler
|
|
385
372
|
|
|
@@ -393,7 +380,7 @@ export class TLSyncClient<R extends UnknownRecord, S extends Store<R> = Store<R>
|
|
|
393
380
|
|
|
394
381
|
private readonly presenceType: R['typeName'] | null
|
|
395
382
|
|
|
396
|
-
|
|
383
|
+
didCancel?: () => boolean
|
|
397
384
|
|
|
398
385
|
/**
|
|
399
386
|
* Creates a new TLSyncClient instance to manage synchronization with a remote server.
|
|
@@ -413,7 +400,7 @@ export class TLSyncClient<R extends UnknownRecord, S extends Store<R> = Store<R>
|
|
|
413
400
|
*/
|
|
414
401
|
constructor(config: {
|
|
415
402
|
store: S
|
|
416
|
-
socket: TLPersistentClientSocket<
|
|
403
|
+
socket: TLPersistentClientSocket<R>
|
|
417
404
|
presence: Signal<R | null>
|
|
418
405
|
presenceMode?: Signal<TLPresenceMode>
|
|
419
406
|
onLoad(self: TLSyncClient<R, S>): void
|
|
@@ -529,7 +516,6 @@ export class TLSyncClient<R extends UnknownRecord, S extends Store<R> = Store<R>
|
|
|
529
516
|
}
|
|
530
517
|
}
|
|
531
518
|
|
|
532
|
-
/** @internal */
|
|
533
519
|
latestConnectRequestId: string | null = null
|
|
534
520
|
|
|
535
521
|
/**
|
|
@@ -655,7 +641,7 @@ export class TLSyncClient<R extends UnknownRecord, S extends Store<R> = Store<R>
|
|
|
655
641
|
this.lastServerClock = event.serverClock
|
|
656
642
|
}
|
|
657
643
|
|
|
658
|
-
|
|
644
|
+
incomingDiffBuffer: TLSocketServerSentDataEvent<R>[] = []
|
|
659
645
|
|
|
660
646
|
/** Handle events received from the server */
|
|
661
647
|
private handleServerEvent(event: TLSocketServerSentEvent<R>) {
|
|
@@ -715,7 +701,7 @@ export class TLSyncClient<R extends UnknownRecord, S extends Store<R> = Store<R>
|
|
|
715
701
|
this.scheduleRebase.cancel?.()
|
|
716
702
|
}
|
|
717
703
|
|
|
718
|
-
|
|
704
|
+
lastPushedPresenceState: R | null = null
|
|
719
705
|
|
|
720
706
|
private pushPresence(nextPresence: R | null) {
|
|
721
707
|
// make sure we push any document changes first
|
|
@@ -62,7 +62,7 @@ export class TestSocketPair<R extends UnknownRecord> {
|
|
|
62
62
|
}
|
|
63
63
|
didReceiveFromClient?: (msg: TLSocketClientSentEvent<R>) => void = undefined
|
|
64
64
|
clientDisconnected?: () => void = undefined
|
|
65
|
-
clientSocket: TLPersistentClientSocket<
|
|
65
|
+
clientSocket: TLPersistentClientSocket<R> = {
|
|
66
66
|
connectionStatus: 'offline',
|
|
67
67
|
onStatusChange: (cb) => {
|
|
68
68
|
this.callbacks.onStatusChange = cb
|
|
@@ -76,7 +76,7 @@ export class TestSocketPair<R extends UnknownRecord> {
|
|
|
76
76
|
this.callbacks.onReceiveMessage = null
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
|
-
sendMessage: (msg) => {
|
|
79
|
+
sendMessage: (msg: TLSocketClientSentEvent<R>) => {
|
|
80
80
|
if (this.clientSocket.connectionStatus !== 'online') {
|
|
81
81
|
throw new Error('trying to send before open')
|
|
82
82
|
}
|
|
@@ -87,9 +87,6 @@ export class TestSocketPair<R extends UnknownRecord> {
|
|
|
87
87
|
this.disconnect()
|
|
88
88
|
this.connect()
|
|
89
89
|
},
|
|
90
|
-
close: () => {
|
|
91
|
-
this.disconnect()
|
|
92
|
-
},
|
|
93
90
|
}
|
|
94
91
|
|
|
95
92
|
callbacks = {
|