@syncular/server-hono 0.0.6-135 → 0.0.6-138

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
@@ -39,6 +39,10 @@ export interface SyncWebSocketEvent {
39
39
  data: {
40
40
  /** New cursor position (for sync events) */
41
41
  cursor?: number;
42
+ /** Commit actor metadata (for sync events with inline changes) */
43
+ actorId?: string;
44
+ /** Commit timestamp metadata (for sync events with inline changes) */
45
+ createdAt?: string;
42
46
  /** Error message (for error events) */
43
47
  error?: string;
44
48
  /** Presence data (for presence events) */
@@ -66,7 +70,11 @@ export interface SyncWebSocketEvent {
66
70
  */
67
71
  export interface WebSocketConnection {
68
72
  /** Send a sync notification, optionally with inline change data */
69
- sendSync(cursor: number, changes?: unknown[]): void;
73
+ sendSync(
74
+ cursor: number,
75
+ changes?: unknown[],
76
+ metadata?: { actorId?: string; createdAt?: string }
77
+ ): void;
70
78
  /** Send a heartbeat */
71
79
  sendHeartbeat(): void;
72
80
  /** Send a presence event */
@@ -117,7 +125,11 @@ export function createWebSocketConnection(
117
125
  actorId: args.actorId,
118
126
  clientId: args.clientId,
119
127
  transportPath: args.transportPath,
120
- sendSync(cursor: number, changes?: unknown[]) {
128
+ sendSync(
129
+ cursor: number,
130
+ changes?: unknown[],
131
+ metadata?: { actorId?: string; createdAt?: string }
132
+ ) {
121
133
  if (!connection.isOpen) return;
122
134
  const payload: Record<string, unknown> = {
123
135
  cursor,
@@ -126,6 +138,12 @@ export function createWebSocketConnection(
126
138
  if (changes && changes.length > 0) {
127
139
  payload.changes = changes;
128
140
  }
141
+ if (metadata?.actorId) {
142
+ payload.actorId = metadata.actorId;
143
+ }
144
+ if (metadata?.createdAt) {
145
+ payload.createdAt = metadata.createdAt;
146
+ }
129
147
  const ok = safeSend(ws, JSON.stringify({ event: 'sync', data: payload }));
130
148
  if (!ok) closed = true;
131
149
  },
@@ -550,7 +568,12 @@ export class WebSocketConnectionManager {
550
568
  notifyScopeKeys(
551
569
  scopeKeys: string[],
552
570
  cursor: number,
553
- opts?: { excludeClientIds?: string[]; changes?: unknown[] }
571
+ opts?: {
572
+ excludeClientIds?: string[];
573
+ changes?: unknown[];
574
+ actorId?: string;
575
+ createdAt?: string;
576
+ }
554
577
  ): void {
555
578
  // Size guard: only deliver inline changes if under threshold
556
579
  let inlineChanges: unknown[] | undefined;
@@ -565,7 +588,10 @@ export class WebSocketConnectionManager {
565
588
  scopeKeys,
566
589
  (conn) => {
567
590
  if (inlineChanges) {
568
- conn.sendSync(cursor, inlineChanges);
591
+ conn.sendSync(cursor, inlineChanges, {
592
+ actorId: opts?.actorId,
593
+ createdAt: opts?.createdAt,
594
+ });
569
595
  } else {
570
596
  conn.sendSync(cursor);
571
597
  }