@tldraw/sync-core 4.6.0-internal.c7df3c92455a → 4.6.0-next.0eb36d65eec3

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.
Files changed (48) hide show
  1. package/dist-cjs/index.js +1 -1
  2. package/dist-cjs/index.js.map +2 -2
  3. package/dist-cjs/lib/ClientWebSocketAdapter.js +1 -1
  4. package/dist-cjs/lib/ClientWebSocketAdapter.js.map +2 -2
  5. package/dist-cjs/lib/DurableObjectSqliteSyncWrapper.js.map +2 -2
  6. package/dist-cjs/lib/InMemorySyncStorage.js.map +2 -2
  7. package/dist-cjs/lib/RoomSession.js.map +1 -1
  8. package/dist-cjs/lib/ServerSocketAdapter.js +1 -1
  9. package/dist-cjs/lib/ServerSocketAdapter.js.map +1 -1
  10. package/dist-cjs/lib/TLSocketRoom.js +1 -1
  11. package/dist-cjs/lib/TLSocketRoom.js.map +2 -2
  12. package/dist-cjs/lib/TLSyncClient.js +1 -1
  13. package/dist-cjs/lib/TLSyncClient.js.map +1 -1
  14. package/dist-cjs/lib/protocol.js.map +1 -1
  15. package/dist-esm/index.mjs +1 -1
  16. package/dist-esm/index.mjs.map +2 -2
  17. package/dist-esm/lib/ClientWebSocketAdapter.mjs +1 -1
  18. package/dist-esm/lib/ClientWebSocketAdapter.mjs.map +2 -2
  19. package/dist-esm/lib/DurableObjectSqliteSyncWrapper.mjs.map +2 -2
  20. package/dist-esm/lib/InMemorySyncStorage.mjs.map +2 -2
  21. package/dist-esm/lib/RoomSession.mjs.map +1 -1
  22. package/dist-esm/lib/ServerSocketAdapter.mjs +1 -1
  23. package/dist-esm/lib/ServerSocketAdapter.mjs.map +1 -1
  24. package/dist-esm/lib/TLSocketRoom.mjs +1 -1
  25. package/dist-esm/lib/TLSocketRoom.mjs.map +2 -2
  26. package/dist-esm/lib/TLSyncClient.mjs +1 -1
  27. package/dist-esm/lib/TLSyncClient.mjs.map +1 -1
  28. package/dist-esm/lib/protocol.mjs.map +1 -1
  29. package/package.json +7 -7
  30. package/src/index.ts +2 -0
  31. package/src/lib/ClientWebSocketAdapter.test.ts +2 -2
  32. package/src/lib/ClientWebSocketAdapter.ts +5 -5
  33. package/src/lib/DurableObjectSqliteSyncWrapper.ts +1 -2
  34. package/src/lib/InMemorySyncStorage.ts +3 -3
  35. package/src/lib/RoomSession.ts +1 -1
  36. package/src/lib/ServerSocketAdapter.test.ts +1 -1
  37. package/src/lib/ServerSocketAdapter.ts +7 -7
  38. package/src/lib/TLSocketRoom.ts +7 -7
  39. package/src/lib/TLSyncClient.test.ts +4 -7
  40. package/src/lib/TLSyncClient.ts +1 -1
  41. package/src/lib/protocol.ts +2 -0
  42. package/src/test/RandomSource.ts +1 -1
  43. package/src/test/SQLiteSyncStorage.test.ts +1 -1
  44. package/src/test/TLSocketRoom.test.ts +8 -12
  45. package/src/test/TLSyncRoom.test.ts +1 -1
  46. package/src/test/TestSocketPair.ts +2 -2
  47. package/src/test/upgradeDowngrade.test.ts +2 -2
  48. package/src/test/validation.test.ts +1 -1
@@ -265,9 +265,9 @@ export class InMemorySyncStorage<R extends UnknownRecord> implements TLSyncStora
265
265
  *
266
266
  * @internal
267
267
  */
268
- class InMemorySyncStorageTransaction<R extends UnknownRecord>
269
- implements TLSyncStorageTransaction<R>
270
- {
268
+ class InMemorySyncStorageTransaction<
269
+ R extends UnknownRecord,
270
+ > implements TLSyncStorageTransaction<R> {
271
271
  private _clock
272
272
  private _closed = false
273
273
 
@@ -1,6 +1,6 @@
1
1
  import { SerializedSchema, UnknownRecord } from '@tldraw/store'
2
- import { TLRoomSocket } from './TLSyncRoom'
3
2
  import { TLSocketServerSentDataEvent } from './protocol'
3
+ import { TLRoomSocket } from './TLSyncRoom'
4
4
 
5
5
  /**
6
6
  * Enumeration of possible states for a room session during its lifecycle.
@@ -1,7 +1,7 @@
1
1
  import { UnknownRecord } from '@tldraw/store'
2
2
  import { describe, expect, it, vi } from 'vitest'
3
- import { ServerSocketAdapter, WebSocketMinimal } from './ServerSocketAdapter'
4
3
  import { TLSocketServerSentEvent } from './protocol'
4
+ import { ServerSocketAdapter, WebSocketMinimal } from './ServerSocketAdapter'
5
5
 
6
6
  // Mock WebSocket implementations for testing different scenarios
7
7
  class MockWebSocket implements WebSocketMinimal {
@@ -1,6 +1,6 @@
1
1
  import { UnknownRecord } from '@tldraw/store'
2
- import { TLRoomSocket } from './TLSyncRoom'
3
2
  import { TLSocketServerSentEvent } from './protocol'
3
+ import { TLRoomSocket } from './TLSyncRoom'
4
4
 
5
5
  /**
6
6
  * Minimal server-side WebSocket interface that is compatible with various WebSocket implementations.
@@ -34,7 +34,7 @@ export interface WebSocketMinimal {
34
34
  * @param type - The event type to listen for
35
35
  * @param listener - The event handler function
36
36
  */
37
- // eslint-disable-next-line @typescript-eslint/method-signature-style
37
+ // eslint-disable-next-line tldraw/method-signature-style
38
38
  addEventListener?: (type: 'message' | 'close' | 'error', listener: (event: any) => void) => void
39
39
 
40
40
  /**
@@ -44,7 +44,7 @@ export interface WebSocketMinimal {
44
44
  * @param type - The event type to stop listening for
45
45
  * @param listener - The event handler function to remove
46
46
  */
47
- // eslint-disable-next-line @typescript-eslint/method-signature-style
47
+ // eslint-disable-next-line tldraw/method-signature-style
48
48
  removeEventListener?: (
49
49
  type: 'message' | 'close' | 'error',
50
50
  listener: (event: any) => void
@@ -55,7 +55,7 @@ export interface WebSocketMinimal {
55
55
  *
56
56
  * @param data - The string data to send
57
57
  */
58
- // eslint-disable-next-line @typescript-eslint/method-signature-style
58
+ // eslint-disable-next-line tldraw/method-signature-style
59
59
  send: (data: string) => void
60
60
 
61
61
  /**
@@ -64,7 +64,7 @@ export interface WebSocketMinimal {
64
64
  * @param code - Optional close code (default: 1000 for normal closure)
65
65
  * @param reason - Optional human-readable close reason
66
66
  */
67
- // eslint-disable-next-line @typescript-eslint/method-signature-style
67
+ // eslint-disable-next-line tldraw/method-signature-style
68
68
  close: (code?: number, reason?: string) => void
69
69
 
70
70
  /**
@@ -93,7 +93,7 @@ export interface ServerSocketAdapterOptions<R extends UnknownRecord> {
93
93
  * @param msg - The message object being sent
94
94
  * @param stringified - The JSON stringified version of the message
95
95
  */
96
- // eslint-disable-next-line @typescript-eslint/method-signature-style
96
+ // eslint-disable-next-line tldraw/method-signature-style
97
97
  readonly onBeforeSendMessage?: (msg: TLSocketServerSentEvent<R>, stringified: string) => void
98
98
  }
99
99
 
@@ -140,7 +140,7 @@ export class ServerSocketAdapter<R extends UnknownRecord> implements TLRoomSocke
140
140
  *
141
141
  * @returns True if the connection is open (readyState === 1), false otherwise
142
142
  */
143
- // eslint-disable-next-line no-restricted-syntax
143
+ // eslint-disable-next-line tldraw/no-setter-getter
144
144
  get isOpen(): boolean {
145
145
  return this.opts.ws.readyState === 1 // ready state open
146
146
  }
@@ -1,7 +1,9 @@
1
1
  import type { SerializedSchema, StoreSchema, UnknownRecord } from '@tldraw/store'
2
2
  import { createTLSchema, TLInstancePresence, TLStoreSnapshot } from '@tldraw/tlschema'
3
3
  import { getOwnProperty, hasOwnProperty, isEqual, structuredClone } from '@tldraw/utils'
4
+ import { JsonChunkAssembler } from './chunk'
4
5
  import { DEFAULT_INITIAL_SNAPSHOT, InMemorySyncStorage } from './InMemorySyncStorage'
6
+ import { TLSocketServerSentEvent } from './protocol'
5
7
  import { RoomSessionState } from './RoomSession'
6
8
  import { ServerSocketAdapter, WebSocketMinimal } from './ServerSocketAdapter'
7
9
  import { TLSyncErrorCloseEventReason } from './TLSyncClient'
@@ -11,8 +13,6 @@ import {
11
13
  loadSnapshotIntoStorage,
12
14
  TLSyncStorage,
13
15
  } from './TLSyncStorage'
14
- import { JsonChunkAssembler } from './chunk'
15
- import { TLSocketServerSentEvent } from './protocol'
16
16
 
17
17
  /**
18
18
  * Strip potentially large fields from a tldraw instance_presence record so the
@@ -96,13 +96,13 @@ export interface TLSocketRoomOptions<R extends UnknownRecord, SessionMeta> {
96
96
  clientTimeout?: number
97
97
  log?: TLSyncLog
98
98
  // a callback that is called when a client is disconnected
99
- // eslint-disable-next-line @typescript-eslint/method-signature-style
99
+ // eslint-disable-next-line tldraw/method-signature-style
100
100
  onSessionRemoved?: (
101
101
  room: TLSocketRoom<R, SessionMeta>,
102
102
  args: { sessionId: string; numSessionsRemaining: number; meta: SessionMeta }
103
103
  ) => void
104
104
  // a callback that is called whenever a message is sent
105
- // eslint-disable-next-line @typescript-eslint/method-signature-style
105
+ // eslint-disable-next-line tldraw/method-signature-style
106
106
  onBeforeSendMessage?: (args: {
107
107
  sessionId: string
108
108
  /** @internal keep the protocol private for now */
@@ -110,7 +110,7 @@ export interface TLSocketRoomOptions<R extends UnknownRecord, SessionMeta> {
110
110
  stringified: string
111
111
  meta: SessionMeta
112
112
  }) => void
113
- // eslint-disable-next-line @typescript-eslint/method-signature-style
113
+ // eslint-disable-next-line tldraw/method-signature-style
114
114
  onAfterReceiveMessage?: (args: {
115
115
  sessionId: string
116
116
  /** @internal keep the protocol private for now */
@@ -126,7 +126,7 @@ export interface TLSocketRoomOptions<R extends UnknownRecord, SessionMeta> {
126
126
  * Use for persisting snapshots to WebSocket attachments (e.g. Cloudflare hibernation).
127
127
  * The room clears any pending snapshot when the session closes.
128
128
  */
129
- // eslint-disable-next-line @typescript-eslint/method-signature-style
129
+ // eslint-disable-next-line tldraw/method-signature-style
130
130
  onSessionSnapshot?: (sessionId: string, snapshot: SessionStateSnapshot) => void
131
131
  }
132
132
 
@@ -194,7 +194,7 @@ export class TLSocketRoom<R extends UnknownRecord = UnknownRecord, SessionMeta =
194
194
  private room: TLSyncRoom<R, SessionMeta>
195
195
  private readonly sessions = new Map<
196
196
  string,
197
- // eslint-disable-next-line @typescript-eslint/method-signature-style
197
+ // eslint-disable-next-line tldraw/method-signature-style
198
198
  { assembler: JsonChunkAssembler; socket: WebSocketMinimal; unlisten: () => void }
199
199
  >()
200
200
  readonly log?: TLSyncLog
@@ -30,13 +30,10 @@ const protocolVersion = getTlsyncProtocolVersion()
30
30
  type TestRecord = TLRecord
31
31
 
32
32
  // Mock socket implementation for testing
33
- class MockSocket
34
- implements
35
- TLPersistentClientSocket<
36
- TLSocketClientSentEvent<TestRecord>,
37
- TLSocketServerSentEvent<TestRecord>
38
- >
39
- {
33
+ class MockSocket implements TLPersistentClientSocket<
34
+ TLSocketClientSentEvent<TestRecord>,
35
+ TLSocketServerSentEvent<TestRecord>
36
+ > {
40
37
  connectionStatus: 'online' | 'offline' | 'error' = 'offline'
41
38
  private messageListeners: Array<(msg: TLSocketServerSentEvent<TestRecord>) => void> = []
42
39
  private statusListeners: Array<(event: TLSocketStatusChangeEvent) => void> = []
@@ -903,7 +903,7 @@ export class TLSyncClient<R extends UnknownRecord, S extends Store<R> = Store<R>
903
903
  }
904
904
  }
905
905
 
906
- // eslint-disable-next-line local/prefer-class-methods
906
+ // eslint-disable-next-line tldraw/prefer-class-methods
907
907
  private rebase = () => {
908
908
  // need to make sure that our speculative changes are in sync with the actual store instance before
909
909
  // proceeding, to avoid inconsistency bugs.
@@ -69,8 +69,10 @@ export const TLIncompatibilityReason = {
69
69
  * @internal
70
70
  * @deprecated replaced by websocket .close status/reason
71
71
  */
72
+ /* eslint-disable @typescript-eslint/no-deprecated */
72
73
  export type TLIncompatibilityReason =
73
74
  (typeof TLIncompatibilityReason)[keyof typeof TLIncompatibilityReason]
75
+ /* eslint-enable @typescript-eslint/no-deprecated */
74
76
 
75
77
  /**
76
78
  * Union type representing all possible message types that can be sent from server to client.
@@ -19,7 +19,7 @@ export class RandomSource {
19
19
  }
20
20
 
21
21
  randomAction<Result>(
22
- // eslint-disable-next-line @typescript-eslint/method-signature-style
22
+ // eslint-disable-next-line tldraw/method-signature-style
23
23
  choices: Array<(() => Result) | { weight: number; do: () => any }>,
24
24
  randomWeights?: boolean
25
25
  ): Result {
@@ -1,3 +1,4 @@
1
+ import { DatabaseSync } from 'node:sqlite'
1
2
  import {
2
3
  BaseRecord,
3
4
  createMigrationSequence,
@@ -13,7 +14,6 @@ import {
13
14
  TLRecord,
14
15
  } from '@tldraw/tlschema'
15
16
  import { IndexKey, ZERO_INDEX_KEY } from '@tldraw/utils'
16
- import { DatabaseSync } from 'node:sqlite'
17
17
  import { vi } from 'vitest'
18
18
  import { MAX_TOMBSTONES, TOMBSTONE_PRUNE_BUFFER_SIZE } from '../lib/InMemorySyncStorage'
19
19
  import { NodeSqliteWrapper } from '../lib/NodeSqliteWrapper'
@@ -1344,12 +1344,10 @@ describe('TLSocketRoom.updateStore', () => {
1344
1344
  document.name = 'My lovely document'
1345
1345
  store.put(document)
1346
1346
  })
1347
- expect(
1348
- (
1349
- storage.getSnapshot().documents.find((r) => r.state.id === 'document:document')
1350
- ?.state as any
1351
- ).name
1352
- ).toBe('My lovely document')
1347
+ const docRecord = storage
1348
+ .getSnapshot()
1349
+ .documents.find((r) => r.state.id === 'document:document') as any
1350
+ expect(docRecord.state.name).toBe('My lovely document')
1353
1351
  expect(clock).toBeLessThan(storage.getClock())
1354
1352
  })
1355
1353
 
@@ -1359,12 +1357,10 @@ describe('TLSocketRoom.updateStore', () => {
1359
1357
  const document = store.get('document:document') as TLDocument
1360
1358
  document.name = 'My lovely document'
1361
1359
  })
1362
- expect(
1363
- (
1364
- storage.getSnapshot().documents.find((r) => r.state.id === 'document:document')
1365
- ?.state as any
1366
- ).name
1367
- ).toBe('')
1360
+ const docRecord = storage
1361
+ .getSnapshot()
1362
+ .documents.find((r) => r.state.id === 'document:document') as any
1363
+ expect(docRecord.state.name).toBe('')
1368
1364
  expect(clock).toBe(storage.getClock())
1369
1365
  })
1370
1366
 
@@ -16,13 +16,13 @@ import {
16
16
  import { IndexKey, ZERO_INDEX_KEY, mockUniqueId, sortById } from '@tldraw/utils'
17
17
  import { vi } from 'vitest'
18
18
  import { InMemorySyncStorage } from '../lib/InMemorySyncStorage'
19
- import { RoomSnapshot, TLRoomSocket, TLSyncRoom } from '../lib/TLSyncRoom'
20
19
  import {
21
20
  TLConnectRequest,
22
21
  TLPushRequest,
23
22
  TLSocketServerSentEvent,
24
23
  getTlsyncProtocolVersion,
25
24
  } from '../lib/protocol'
25
+ import { RoomSnapshot, TLRoomSocket, TLSyncRoom } from '../lib/TLSyncRoom'
26
26
 
27
27
  const schema = createTLSchema()
28
28
  const compareById = (a: { id: string }, b: { id: string }) => a.id.localeCompare(b.id)
@@ -1,5 +1,6 @@
1
1
  import { UnknownRecord } from '@tldraw/store'
2
2
  import { structuredClone } from '@tldraw/utils'
3
+ import { TLSocketClientSentEvent, TLSocketServerSentEvent } from '../lib/protocol'
3
4
  import {
4
5
  TLPersistentClientSocket,
5
6
  TLSocketStatusListener,
@@ -7,7 +8,6 @@ import {
7
8
  TLSyncErrorCloseEventReason,
8
9
  } from '../lib/TLSyncClient'
9
10
  import { TLRoomSocket } from '../lib/TLSyncRoom'
10
- import { TLSocketClientSentEvent, TLSocketServerSentEvent } from '../lib/protocol'
11
11
  import { TestServer } from './TestServer'
12
12
 
13
13
  export class TestSocketPair<R extends UnknownRecord> {
@@ -97,7 +97,7 @@ export class TestSocketPair<R extends UnknownRecord> {
97
97
  onStatusChange: null as null | TLSocketStatusListener,
98
98
  }
99
99
 
100
- // eslint-disable-next-line no-restricted-syntax
100
+ // eslint-disable-next-line tldraw/no-setter-getter
101
101
  get isConnected() {
102
102
  return this.clientSocket.connectionStatus === 'online'
103
103
  }
@@ -11,10 +11,10 @@ import {
11
11
  createRecordType,
12
12
  } from '@tldraw/store'
13
13
  import { vi, type Mock } from 'vitest'
14
- import { TLSyncClient, TLSyncErrorCloseEventReason } from '../lib/TLSyncClient'
15
- import { RoomSnapshot, TLRoomSocket } from '../lib/TLSyncRoom'
16
14
  import { RecordOpType, ValueOpType } from '../lib/diff'
17
15
  import { TLSocketServerSentEvent, getTlsyncProtocolVersion } from '../lib/protocol'
16
+ import { TLSyncClient, TLSyncErrorCloseEventReason } from '../lib/TLSyncClient'
17
+ import { RoomSnapshot, TLRoomSocket } from '../lib/TLSyncRoom'
18
18
  import { TestServer } from './TestServer'
19
19
  import { TestSocketPair } from './TestSocketPair'
20
20
 
@@ -1,8 +1,8 @@
1
1
  import { computed } from '@tldraw/state'
2
2
  import { RecordId, Store, StoreSchema, UnknownRecord, createRecordType } from '@tldraw/store'
3
3
  import { vi } from 'vitest'
4
- import { TLSyncClient, TLSyncErrorCloseEventReason } from '../lib/TLSyncClient'
5
4
  import { RecordOpType } from '../lib/diff'
5
+ import { TLSyncClient, TLSyncErrorCloseEventReason } from '../lib/TLSyncClient'
6
6
  import { TestServer } from './TestServer'
7
7
  import { TestSocketPair } from './TestSocketPair'
8
8