@syncular/server-hono 0.0.1-60 → 0.0.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/src/ws.ts CHANGED
@@ -17,23 +17,12 @@ export interface PresenceEntry {
17
17
  metadata?: Record<string, unknown>;
18
18
  }
19
19
 
20
- /**
21
- * Push response data sent back to the client over WS
22
- */
23
- export interface WsPushResponseData {
24
- requestId: string;
25
- ok: boolean;
26
- status: string;
27
- commitSeq?: number;
28
- results: Array<{ opIndex: number; status: string; [k: string]: unknown }>;
29
- }
30
-
31
20
  /**
32
21
  * WebSocket event data for sync notifications
33
22
  */
34
23
  export interface SyncWebSocketEvent {
35
24
  /** Event type */
36
- event: 'sync' | 'heartbeat' | 'error' | 'presence' | 'push-response';
25
+ event: 'sync' | 'heartbeat' | 'error' | 'presence';
37
26
  /** Data payload */
38
27
  data: {
39
28
  /** New cursor position (for sync events) */
@@ -49,12 +38,6 @@ export interface SyncWebSocketEvent {
49
38
  metadata?: Record<string, unknown>;
50
39
  entries?: PresenceEntry[];
51
40
  };
52
- /** Push response data (for push-response events) */
53
- requestId?: string;
54
- ok?: boolean;
55
- status?: string;
56
- commitSeq?: number;
57
- results?: Array<{ opIndex: number; status: string; [k: string]: unknown }>;
58
41
  /** Timestamp */
59
42
  timestamp: number;
60
43
  };
@@ -64,8 +47,8 @@ export interface SyncWebSocketEvent {
64
47
  * WebSocket connection controller for managing active connections
65
48
  */
66
49
  export interface WebSocketConnection {
67
- /** Send a sync notification, optionally with inline change data */
68
- sendSync(cursor: number, changes?: unknown[]): void;
50
+ /** Send a sync notification */
51
+ sendSync(cursor: number): void;
69
52
  /** Send a heartbeat */
70
53
  sendHeartbeat(): void;
71
54
  /** Send a presence event */
@@ -77,8 +60,6 @@ export interface WebSocketConnection {
77
60
  metadata?: Record<string, unknown>;
78
61
  entries?: PresenceEntry[];
79
62
  }): void;
80
- /** Send a push response back to the client */
81
- sendPushResponse(data: WsPushResponseData): void;
82
63
  /** Send an error and close */
83
64
  sendError(message: string): void;
84
65
  /** Close the connection */
@@ -116,16 +97,15 @@ export function createWebSocketConnection(
116
97
  actorId: args.actorId,
117
98
  clientId: args.clientId,
118
99
  transportPath: args.transportPath,
119
- sendSync(cursor: number, changes?: unknown[]) {
100
+ sendSync(cursor: number) {
120
101
  if (!connection.isOpen) return;
121
- const payload: Record<string, unknown> = {
122
- cursor,
123
- timestamp: Date.now(),
124
- };
125
- if (changes && changes.length > 0) {
126
- payload.changes = changes;
127
- }
128
- const ok = safeSend(ws, JSON.stringify({ event: 'sync', data: payload }));
102
+ const ok = safeSend(
103
+ ws,
104
+ JSON.stringify({
105
+ event: 'sync',
106
+ data: { cursor, timestamp: Date.now() },
107
+ })
108
+ );
129
109
  if (!ok) closed = true;
130
110
  },
131
111
  sendHeartbeat() {
@@ -154,17 +134,6 @@ export function createWebSocketConnection(
154
134
  );
155
135
  if (!ok) closed = true;
156
136
  },
157
- sendPushResponse(data: WsPushResponseData) {
158
- if (!connection.isOpen) return;
159
- const ok = safeSend(
160
- ws,
161
- JSON.stringify({
162
- event: 'push-response',
163
- data: { ...data, timestamp: Date.now() },
164
- })
165
- );
166
- if (!ok) closed = true;
167
- },
168
137
  sendError(message: string) {
169
138
  if (connection.isOpen) {
170
139
  safeSend(
@@ -606,16 +575,10 @@ export class WebSocketConnectionManager {
606
575
  * Notify clients that new data is available for the given scopes.
607
576
  * Dedupes connections that match multiple scopes.
608
577
  */
609
- /**
610
- * Maximum serialized size (bytes) for inline WS change delivery.
611
- * Larger payloads fall back to cursor-only notification.
612
- */
613
- private static readonly WS_INLINE_MAX_BYTES = 64 * 1024;
614
-
615
578
  notifyScopeKeys(
616
579
  scopeKeys: string[],
617
580
  cursor: number,
618
- opts?: { excludeClientIds?: string[]; changes?: unknown[] }
581
+ opts?: { excludeClientIds?: string[] }
619
582
  ): void {
620
583
  const exclude = new Set(opts?.excludeClientIds ?? []);
621
584
  const targets = new Set<WebSocketConnection>();
@@ -626,23 +589,10 @@ export class WebSocketConnectionManager {
626
589
  for (const conn of conns) targets.add(conn);
627
590
  }
628
591
 
629
- // Size guard: only deliver inline changes if under threshold
630
- let inlineChanges: unknown[] | undefined;
631
- if (opts?.changes && opts.changes.length > 0) {
632
- const serialized = JSON.stringify(opts.changes);
633
- if (serialized.length <= WebSocketConnectionManager.WS_INLINE_MAX_BYTES) {
634
- inlineChanges = opts.changes;
635
- }
636
- }
637
-
638
592
  for (const conn of targets) {
639
593
  if (!conn.isOpen) continue;
640
594
  if (exclude.has(conn.clientId)) continue;
641
- if (inlineChanges) {
642
- conn.sendSync(cursor, inlineChanges);
643
- } else {
644
- conn.sendSync(cursor);
645
- }
595
+ conn.sendSync(cursor);
646
596
  }
647
597
  }
648
598