@firtoz/collection-sync 4.0.0 → 5.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firtoz/collection-sync",
3
- "version": "4.0.0",
3
+ "version": "5.0.0",
4
4
  "description": "WebSocket sync protocol and bridges for TanStack DB collections",
5
5
  "main": "./src/index.ts",
6
6
  "module": "./src/index.ts",
@@ -59,22 +59,22 @@
59
59
  "access": "public"
60
60
  },
61
61
  "dependencies": {
62
- "@firtoz/db-helpers": "^2.1.0",
62
+ "@firtoz/db-helpers": "^2.1.1",
63
63
  "@firtoz/maybe-error": "^1.5.2",
64
64
  "zod": "^4.3.6"
65
65
  },
66
66
  "peerDependencies": {
67
- "@firtoz/websocket-do": "^10.0.0",
67
+ "@firtoz/websocket-do": "^12.0.0",
68
68
  "@standard-schema/spec": ">=1.1.0",
69
- "@tanstack/db": ">=0.6.1",
70
- "@tanstack/react-db": ">=0.1.79",
69
+ "@tanstack/db": ">=0.6.3",
70
+ "@tanstack/react-db": ">=0.1.82",
71
71
  "react": ">=19.2.4"
72
72
  },
73
73
  "devDependencies": {
74
- "@firtoz/websocket-do": "^10.0.0",
74
+ "@firtoz/websocket-do": "^12.0.0",
75
75
  "@standard-schema/spec": "^1.1.0",
76
- "@tanstack/db": "^0.6.1",
77
- "@tanstack/react-db": "0.1.79",
76
+ "@tanstack/db": "^0.6.4",
77
+ "@tanstack/react-db": "0.1.82",
78
78
  "@types/react": "^19.2.14",
79
79
  "react": "^19.2.4",
80
80
  "typescript": "^6.0.2"
@@ -1,6 +1,6 @@
1
1
  import { exhaustiveGuard } from "@firtoz/maybe-error";
2
2
  import type { SyncMessage } from "@firtoz/db-helpers";
3
- import { ZodWebSocketClient } from "@firtoz/websocket-do/zod-client";
3
+ import { StandardSchemaWebSocketClient } from "@firtoz/websocket-do/schema-client";
4
4
  import type { PartialSyncClientBridge } from "./partial-sync-client-bridge";
5
5
  import type { SyncClientBridge } from "./sync-client-bridge";
6
6
  import {
@@ -241,7 +241,7 @@ export function connectPartialSync<
241
241
  await drainRangePatchCoalesceBuffer();
242
242
  };
243
243
 
244
- const zodClient = new ZodWebSocketClient({
244
+ const schemaClient = new StandardSchemaWebSocketClient({
245
245
  url: options.url,
246
246
  clientSchema,
247
247
  serverSchema,
@@ -278,18 +278,22 @@ export function connectPartialSync<
278
278
  const flushPendingOutbound = () => {
279
279
  while (
280
280
  pendingOutbound.length > 0 &&
281
- zodClient.socket.readyState === WebSocket.OPEN
281
+ schemaClient.socket.readyState === WebSocket.OPEN
282
282
  ) {
283
283
  const message = pendingOutbound.shift();
284
284
  if (message !== undefined) {
285
- zodClient.send(message);
285
+ void schemaClient.send(message).catch((err: unknown) => {
286
+ console.error("[connectPartialSync] WebSocket send failed", err);
287
+ });
286
288
  }
287
289
  }
288
290
  };
289
291
 
290
292
  options.setTransportSend((message) => {
291
- if (zodClient.socket.readyState === WebSocket.OPEN) {
292
- zodClient.send(message);
293
+ if (schemaClient.socket.readyState === WebSocket.OPEN) {
294
+ void schemaClient.send(message).catch((err: unknown) => {
295
+ console.error("[connectPartialSync] WebSocket send failed", err);
296
+ });
293
297
  } else {
294
298
  pendingOutbound.push(message);
295
299
  }
@@ -308,10 +312,10 @@ export function connectPartialSync<
308
312
  mutationBridge?.setConnected(false);
309
313
  };
310
314
 
311
- zodClient.socket.addEventListener("open", onOpen);
312
- zodClient.socket.addEventListener("close", onClose);
315
+ schemaClient.socket.addEventListener("open", onOpen);
316
+ schemaClient.socket.addEventListener("close", onClose);
313
317
 
314
- if (zodClient.socket.readyState === WebSocket.OPEN) {
318
+ if (schemaClient.socket.readyState === WebSocket.OPEN) {
315
319
  onOpen();
316
320
  }
317
321
 
@@ -338,12 +342,12 @@ export function connectPartialSync<
338
342
  cancelCoalescedRangePatchDeferredFlush();
339
343
  inboundWorkQueue.length = 0;
340
344
  rangePatchCoalesceBuffer = [];
341
- zodClient.socket.removeEventListener("open", onOpen);
342
- zodClient.socket.removeEventListener("close", onClose);
345
+ schemaClient.socket.removeEventListener("open", onOpen);
346
+ schemaClient.socket.removeEventListener("close", onClose);
343
347
  pendingOutbound.length = 0;
344
348
  bridge.setConnected(false);
345
349
  mutationBridge?.setConnected(false);
346
350
  options.setTransportSend(() => {});
347
- zodClient.close();
351
+ schemaClient.close();
348
352
  };
349
353
  }
@@ -1,4 +1,4 @@
1
- import { ZodWebSocketClient } from "@firtoz/websocket-do/zod-client";
1
+ import { StandardSchemaWebSocketClient } from "@firtoz/websocket-do/schema-client";
2
2
  import type { SyncClientBridge } from "./sync-client-bridge";
3
3
  import type { PartialSyncRowShape } from "./partial-sync-row-key";
4
4
  import {
@@ -25,7 +25,7 @@ export type ConnectSyncOptions<TItem = unknown> = {
25
25
  };
26
26
 
27
27
  /**
28
- * Connects a {@link SyncClientBridge} to a WebSocket using the same codec as {@link ZodSession} on the server.
28
+ * Connects a {@link SyncClientBridge} to a WebSocket using the same codec as `StandardSchemaSession` (`@firtoz/websocket-do`) on the server.
29
29
  */
30
30
  export function connectSync<TItem extends PartialSyncRowShape>(
31
31
  bridge: SyncClientBridge<TItem>,
@@ -35,7 +35,7 @@ export function connectSync<TItem extends PartialSyncRowShape>(
35
35
  const serverSchema = createServerMessageSchema<TItem>();
36
36
  const useMsgpack = options.transport === "msgpack";
37
37
 
38
- const zodClient = new ZodWebSocketClient({
38
+ const schemaClient = new StandardSchemaWebSocketClient({
39
39
  url: options.url,
40
40
  clientSchema,
41
41
  serverSchema,
@@ -53,7 +53,9 @@ export function connectSync<TItem extends PartialSyncRowShape>(
53
53
  });
54
54
 
55
55
  options.setTransportSend((message) => {
56
- zodClient.send(message);
56
+ void schemaClient.send(message).catch((err: unknown) => {
57
+ console.error("[connectSync] WebSocket send failed", err);
58
+ });
57
59
  });
58
60
 
59
61
  bridge.setConnected(false);
@@ -65,18 +67,18 @@ export function connectSync<TItem extends PartialSyncRowShape>(
65
67
  bridge.setConnected(false);
66
68
  };
67
69
 
68
- zodClient.socket.addEventListener("open", onOpen);
69
- zodClient.socket.addEventListener("close", onClose);
70
+ schemaClient.socket.addEventListener("open", onOpen);
71
+ schemaClient.socket.addEventListener("close", onClose);
70
72
 
71
- if (zodClient.socket.readyState === WebSocket.OPEN) {
73
+ if (schemaClient.socket.readyState === WebSocket.OPEN) {
72
74
  onOpen();
73
75
  }
74
76
 
75
77
  return () => {
76
- zodClient.socket.removeEventListener("open", onOpen);
77
- zodClient.socket.removeEventListener("close", onClose);
78
+ schemaClient.socket.removeEventListener("open", onOpen);
79
+ schemaClient.socket.removeEventListener("close", onClose);
78
80
  bridge.setConnected(false);
79
81
  options.setTransportSend(() => {});
80
- zodClient.close();
82
+ schemaClient.close();
81
83
  };
82
84
  }