@korajs/sync 1.0.0-beta.10 → 1.0.0-beta.11

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.
@@ -1,4 +1,4 @@
1
- import { c as SyncTransport, T as TransportOptions, a as SyncMessage, d as TransportMessageHandler, e as TransportCloseHandler, f as TransportErrorHandler, Q as QueueStorage } from './transport-B2GQerqJ.cjs';
1
+ import { c as SyncTransport, T as TransportOptions, a as SyncMessage, d as TransportMessageHandler, e as TransportCloseHandler, f as TransportErrorHandler, Q as QueueStorage } from './transport-iXX0KA_W.cjs';
2
2
  import { Operation } from '@korajs/core';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { c as SyncTransport, T as TransportOptions, a as SyncMessage, d as TransportMessageHandler, e as TransportCloseHandler, f as TransportErrorHandler, Q as QueueStorage } from './transport-B2GQerqJ.js';
1
+ import { c as SyncTransport, T as TransportOptions, a as SyncMessage, d as TransportMessageHandler, e as TransportCloseHandler, f as TransportErrorHandler, Q as QueueStorage } from './transport-iXX0KA_W.js';
2
2
  import { Operation } from '@korajs/core';
3
3
 
4
4
  /**
@@ -93,14 +93,27 @@ type SyncState = (typeof SYNC_STATES)[number];
93
93
  /**
94
94
  * Developer-facing sync status. Simplified view of the internal state.
95
95
  */
96
- declare const SYNC_STATUSES: readonly ["connected", "reconnecting", "syncing", "synced", "offline", "clock-error", "error", "schema-mismatch"];
96
+ declare const SYNC_STATUSES: readonly ["connected", "reconnecting", "syncing", "synced", "offline", "clock-error", "error", "schema-mismatch", "auth-required"];
97
97
  type SyncStatus = (typeof SYNC_STATUSES)[number];
98
+ type SyncPhase = 'suspended' | 'offline' | 'connecting' | 'authenticating' | 'handshaking' | 'uploading' | 'receiving' | 'applying' | 'streaming' | 'blocked';
99
+ interface ActiveApplyFailure {
100
+ operationId: string;
101
+ collection: string;
102
+ recordId: string;
103
+ code: string;
104
+ message: string;
105
+ retriable: boolean;
106
+ firstSeenAt: number;
107
+ retryCount: number;
108
+ }
98
109
  /**
99
110
  * Sync status information exposed to developers.
100
111
  */
101
112
  interface SyncStatusInfo {
102
113
  /** Current developer-facing status */
103
114
  status: SyncStatus;
115
+ phase?: SyncPhase;
116
+ reason?: string;
104
117
  /** True when the engine is actively trying to re-establish a transport session. */
105
118
  reconnecting: boolean;
106
119
  /** Number of operations waiting to be sent */
@@ -115,7 +128,47 @@ interface SyncStatusInfo {
115
128
  conflicts: number;
116
129
  /** serverTime - localTime in ms measured at the last handshake, or null before first connect. Negative = this device's clock is fast. */
117
130
  clockSkewMs: number | null;
131
+ inFlightUploadOperations?: number;
132
+ hasInFlightDeliveryBatch?: boolean;
133
+ activeViewId?: string;
134
+ activeViewComplete?: boolean;
135
+ initialSync?: {
136
+ complete: boolean;
137
+ receivedBatches: number;
138
+ totalBatches: number | null;
139
+ progress: number | null;
140
+ };
141
+ deliveryWatermark?: number;
142
+ serverFrontier?: number | null;
143
+ blockedFailure?: ActiveApplyFailure | null;
144
+ }
145
+ interface SyncSettlementOptions {
146
+ upload?: boolean;
147
+ download?: 'active-view' | false;
148
+ timeoutMs?: number;
149
+ signal?: AbortSignal;
118
150
  }
151
+ type SyncSettlementResult = {
152
+ outcome: 'settled';
153
+ status: SyncStatusInfo;
154
+ } | {
155
+ outcome: 'offline';
156
+ status: SyncStatusInfo;
157
+ } | {
158
+ outcome: 'suspended';
159
+ reason: string;
160
+ status: SyncStatusInfo;
161
+ } | {
162
+ outcome: 'blocked';
163
+ failure: ActiveApplyFailure;
164
+ status: SyncStatusInfo;
165
+ } | {
166
+ outcome: 'timeout';
167
+ status: SyncStatusInfo;
168
+ } | {
169
+ outcome: 'aborted';
170
+ status: SyncStatusInfo;
171
+ };
119
172
  /**
120
173
  * Per-collection sync scope map. Maps collection names to field-value filters.
121
174
  * Empty filter `{}` means no restriction (all records visible).
@@ -134,6 +187,14 @@ interface SyncConfig {
134
187
  auth?: () => Promise<{
135
188
  token: string;
136
189
  }>;
190
+ /** Auth readiness gate. A suspended result prevents transport creation and retries. */
191
+ authState?: () => Promise<{
192
+ state: 'loading' | 'signed-out' | 'anonymous' | 'authenticated';
193
+ mayConnectAnonymously?: boolean;
194
+ }>;
195
+ querySubsets?: {
196
+ mode?: 'reactive' | 'static' | 'disabled';
197
+ };
137
198
  /** Sync scopes per collection. Limits which records sync to this client. */
138
199
  scopes?: Record<string, (ctx: SyncScopeContext) => Record<string, unknown>>;
139
200
  /**
@@ -307,10 +368,10 @@ interface SyncQuerySubset {
307
368
  * for its collection. Collections without query subsets pass through.
308
369
  */
309
370
  declare function operationMatchesQuerySubsets(op: Operation, subsets: SyncQuerySubset[] | undefined, fullRecord?: Record<string, unknown> | null): boolean;
310
- /**
311
- * Deduplicate query subsets by collection + where JSON key.
312
- */
371
+ /** Canonicalize equality subsets and remove subsets already covered by a broader one. */
313
372
  declare function dedupeQuerySubsets(subsets: SyncQuerySubset[]): SyncQuerySubset[];
373
+ /** True when every record selected by `narrow` is also selected by `broad`. */
374
+ declare function querySubsetContains(broad: SyncQuerySubset[], narrow: SyncQuerySubset[]): boolean;
314
375
 
315
376
  type WireFormat = 'json' | 'protobuf';
316
377
  /**
@@ -663,4 +724,4 @@ interface SyncTransport {
663
724
  isConnected(): boolean;
664
725
  }
665
726
 
666
- export { isYjsDocUpdateMessage as $, type AcknowledgmentMessage as A, type BlobChunkRequestMessage as B, dedupeQuerySubsets as C, type DeltaCursor as D, type EncryptedPayload as E, isAcknowledgmentMessage as F, isAwarenessUpdateMessage as G, type HandshakeMessage as H, InvalidScopeError as I, isBlobChunkPushMessage as J, isBlobChunkRequestMessage as K, isBlobChunkResponseMessage as L, MemoryRejectedOperationStorage as M, isErrorMessage as N, type OperationBatchMessage as O, isHandshakeMessage as P, type QueueStorage as Q, type RejectedOperationStorage as R, type SyncScopeMap as S, type TransportOptions as T, isHandshakeResponseMessage as U, type VersionedKey as V, type WireFormat as W, isOperationBatchMessage as X, type YjsDocUpdateMessage as Y, isOperationRejectedMessage as Z, isSyncMessage as _, type SyncMessage as a, operationMatchesQuerySubsets as a0, type SerializedOperation as b, type SyncTransport as c, type TransportMessageHandler as d, type TransportCloseHandler as e, type TransportErrorHandler as f, type BlobChunkResponseMessage as g, type BlobChunkPushMessage as h, type SyncEncryptionConfig as i, type SyncState as j, type SyncStatusInfo as k, type SyncConfig as l, type SyncStatePersistence as m, type SyncQuerySubset as n, type RejectedOperation as o, type AwarenessStateWire as p, type AwarenessUpdateMessage as q, type ErrorMessage as r, type HandshakeResponseMessage as s, type OperationRejectedMessage as t, SYNC_STATES as u, SYNC_STATUSES as v, ScopeViolationError as w, type SyncEncryptionAlgorithm as x, type SyncScopeContext as y, type SyncStatus as z };
727
+ export { isHandshakeResponseMessage as $, type AcknowledgmentMessage as A, type BlobChunkRequestMessage as B, type SyncScopeContext as C, type DeltaCursor as D, type EncryptedPayload as E, type SyncSettlementOptions as F, type SyncSettlementResult as G, type HandshakeMessage as H, InvalidScopeError as I, type SyncStatus as J, dedupeQuerySubsets as K, isAcknowledgmentMessage as L, MemoryRejectedOperationStorage as M, isAwarenessUpdateMessage as N, type OperationBatchMessage as O, isBlobChunkPushMessage as P, type QueueStorage as Q, type RejectedOperationStorage as R, type SyncScopeMap as S, type TransportOptions as T, isBlobChunkRequestMessage as U, type VersionedKey as V, type WireFormat as W, isBlobChunkResponseMessage as X, type YjsDocUpdateMessage as Y, isErrorMessage as Z, isHandshakeMessage as _, type SyncMessage as a, isOperationBatchMessage as a0, isOperationRejectedMessage as a1, isSyncMessage as a2, isYjsDocUpdateMessage as a3, operationMatchesQuerySubsets as a4, querySubsetContains as a5, type SerializedOperation as b, type SyncTransport as c, type TransportMessageHandler as d, type TransportCloseHandler as e, type TransportErrorHandler as f, type BlobChunkResponseMessage as g, type BlobChunkPushMessage as h, type SyncEncryptionConfig as i, type SyncState as j, type SyncStatusInfo as k, type SyncConfig as l, type SyncStatePersistence as m, type SyncQuerySubset as n, type RejectedOperation as o, type ActiveApplyFailure as p, type AwarenessStateWire as q, type AwarenessUpdateMessage as r, type ErrorMessage as s, type HandshakeResponseMessage as t, type OperationRejectedMessage as u, SYNC_STATES as v, SYNC_STATUSES as w, ScopeViolationError as x, type SyncEncryptionAlgorithm as y, type SyncPhase as z };
@@ -93,14 +93,27 @@ type SyncState = (typeof SYNC_STATES)[number];
93
93
  /**
94
94
  * Developer-facing sync status. Simplified view of the internal state.
95
95
  */
96
- declare const SYNC_STATUSES: readonly ["connected", "reconnecting", "syncing", "synced", "offline", "clock-error", "error", "schema-mismatch"];
96
+ declare const SYNC_STATUSES: readonly ["connected", "reconnecting", "syncing", "synced", "offline", "clock-error", "error", "schema-mismatch", "auth-required"];
97
97
  type SyncStatus = (typeof SYNC_STATUSES)[number];
98
+ type SyncPhase = 'suspended' | 'offline' | 'connecting' | 'authenticating' | 'handshaking' | 'uploading' | 'receiving' | 'applying' | 'streaming' | 'blocked';
99
+ interface ActiveApplyFailure {
100
+ operationId: string;
101
+ collection: string;
102
+ recordId: string;
103
+ code: string;
104
+ message: string;
105
+ retriable: boolean;
106
+ firstSeenAt: number;
107
+ retryCount: number;
108
+ }
98
109
  /**
99
110
  * Sync status information exposed to developers.
100
111
  */
101
112
  interface SyncStatusInfo {
102
113
  /** Current developer-facing status */
103
114
  status: SyncStatus;
115
+ phase?: SyncPhase;
116
+ reason?: string;
104
117
  /** True when the engine is actively trying to re-establish a transport session. */
105
118
  reconnecting: boolean;
106
119
  /** Number of operations waiting to be sent */
@@ -115,7 +128,47 @@ interface SyncStatusInfo {
115
128
  conflicts: number;
116
129
  /** serverTime - localTime in ms measured at the last handshake, or null before first connect. Negative = this device's clock is fast. */
117
130
  clockSkewMs: number | null;
131
+ inFlightUploadOperations?: number;
132
+ hasInFlightDeliveryBatch?: boolean;
133
+ activeViewId?: string;
134
+ activeViewComplete?: boolean;
135
+ initialSync?: {
136
+ complete: boolean;
137
+ receivedBatches: number;
138
+ totalBatches: number | null;
139
+ progress: number | null;
140
+ };
141
+ deliveryWatermark?: number;
142
+ serverFrontier?: number | null;
143
+ blockedFailure?: ActiveApplyFailure | null;
144
+ }
145
+ interface SyncSettlementOptions {
146
+ upload?: boolean;
147
+ download?: 'active-view' | false;
148
+ timeoutMs?: number;
149
+ signal?: AbortSignal;
118
150
  }
151
+ type SyncSettlementResult = {
152
+ outcome: 'settled';
153
+ status: SyncStatusInfo;
154
+ } | {
155
+ outcome: 'offline';
156
+ status: SyncStatusInfo;
157
+ } | {
158
+ outcome: 'suspended';
159
+ reason: string;
160
+ status: SyncStatusInfo;
161
+ } | {
162
+ outcome: 'blocked';
163
+ failure: ActiveApplyFailure;
164
+ status: SyncStatusInfo;
165
+ } | {
166
+ outcome: 'timeout';
167
+ status: SyncStatusInfo;
168
+ } | {
169
+ outcome: 'aborted';
170
+ status: SyncStatusInfo;
171
+ };
119
172
  /**
120
173
  * Per-collection sync scope map. Maps collection names to field-value filters.
121
174
  * Empty filter `{}` means no restriction (all records visible).
@@ -134,6 +187,14 @@ interface SyncConfig {
134
187
  auth?: () => Promise<{
135
188
  token: string;
136
189
  }>;
190
+ /** Auth readiness gate. A suspended result prevents transport creation and retries. */
191
+ authState?: () => Promise<{
192
+ state: 'loading' | 'signed-out' | 'anonymous' | 'authenticated';
193
+ mayConnectAnonymously?: boolean;
194
+ }>;
195
+ querySubsets?: {
196
+ mode?: 'reactive' | 'static' | 'disabled';
197
+ };
137
198
  /** Sync scopes per collection. Limits which records sync to this client. */
138
199
  scopes?: Record<string, (ctx: SyncScopeContext) => Record<string, unknown>>;
139
200
  /**
@@ -307,10 +368,10 @@ interface SyncQuerySubset {
307
368
  * for its collection. Collections without query subsets pass through.
308
369
  */
309
370
  declare function operationMatchesQuerySubsets(op: Operation, subsets: SyncQuerySubset[] | undefined, fullRecord?: Record<string, unknown> | null): boolean;
310
- /**
311
- * Deduplicate query subsets by collection + where JSON key.
312
- */
371
+ /** Canonicalize equality subsets and remove subsets already covered by a broader one. */
313
372
  declare function dedupeQuerySubsets(subsets: SyncQuerySubset[]): SyncQuerySubset[];
373
+ /** True when every record selected by `narrow` is also selected by `broad`. */
374
+ declare function querySubsetContains(broad: SyncQuerySubset[], narrow: SyncQuerySubset[]): boolean;
314
375
 
315
376
  type WireFormat = 'json' | 'protobuf';
316
377
  /**
@@ -663,4 +724,4 @@ interface SyncTransport {
663
724
  isConnected(): boolean;
664
725
  }
665
726
 
666
- export { isYjsDocUpdateMessage as $, type AcknowledgmentMessage as A, type BlobChunkRequestMessage as B, dedupeQuerySubsets as C, type DeltaCursor as D, type EncryptedPayload as E, isAcknowledgmentMessage as F, isAwarenessUpdateMessage as G, type HandshakeMessage as H, InvalidScopeError as I, isBlobChunkPushMessage as J, isBlobChunkRequestMessage as K, isBlobChunkResponseMessage as L, MemoryRejectedOperationStorage as M, isErrorMessage as N, type OperationBatchMessage as O, isHandshakeMessage as P, type QueueStorage as Q, type RejectedOperationStorage as R, type SyncScopeMap as S, type TransportOptions as T, isHandshakeResponseMessage as U, type VersionedKey as V, type WireFormat as W, isOperationBatchMessage as X, type YjsDocUpdateMessage as Y, isOperationRejectedMessage as Z, isSyncMessage as _, type SyncMessage as a, operationMatchesQuerySubsets as a0, type SerializedOperation as b, type SyncTransport as c, type TransportMessageHandler as d, type TransportCloseHandler as e, type TransportErrorHandler as f, type BlobChunkResponseMessage as g, type BlobChunkPushMessage as h, type SyncEncryptionConfig as i, type SyncState as j, type SyncStatusInfo as k, type SyncConfig as l, type SyncStatePersistence as m, type SyncQuerySubset as n, type RejectedOperation as o, type AwarenessStateWire as p, type AwarenessUpdateMessage as q, type ErrorMessage as r, type HandshakeResponseMessage as s, type OperationRejectedMessage as t, SYNC_STATES as u, SYNC_STATUSES as v, ScopeViolationError as w, type SyncEncryptionAlgorithm as x, type SyncScopeContext as y, type SyncStatus as z };
727
+ export { isHandshakeResponseMessage as $, type AcknowledgmentMessage as A, type BlobChunkRequestMessage as B, type SyncScopeContext as C, type DeltaCursor as D, type EncryptedPayload as E, type SyncSettlementOptions as F, type SyncSettlementResult as G, type HandshakeMessage as H, InvalidScopeError as I, type SyncStatus as J, dedupeQuerySubsets as K, isAcknowledgmentMessage as L, MemoryRejectedOperationStorage as M, isAwarenessUpdateMessage as N, type OperationBatchMessage as O, isBlobChunkPushMessage as P, type QueueStorage as Q, type RejectedOperationStorage as R, type SyncScopeMap as S, type TransportOptions as T, isBlobChunkRequestMessage as U, type VersionedKey as V, type WireFormat as W, isBlobChunkResponseMessage as X, type YjsDocUpdateMessage as Y, isErrorMessage as Z, isHandshakeMessage as _, type SyncMessage as a, isOperationBatchMessage as a0, isOperationRejectedMessage as a1, isSyncMessage as a2, isYjsDocUpdateMessage as a3, operationMatchesQuerySubsets as a4, querySubsetContains as a5, type SerializedOperation as b, type SyncTransport as c, type TransportMessageHandler as d, type TransportCloseHandler as e, type TransportErrorHandler as f, type BlobChunkResponseMessage as g, type BlobChunkPushMessage as h, type SyncEncryptionConfig as i, type SyncState as j, type SyncStatusInfo as k, type SyncConfig as l, type SyncStatePersistence as m, type SyncQuerySubset as n, type RejectedOperation as o, type ActiveApplyFailure as p, type AwarenessStateWire as q, type AwarenessUpdateMessage as r, type ErrorMessage as s, type HandshakeResponseMessage as t, type OperationRejectedMessage as u, SYNC_STATES as v, SYNC_STATUSES as w, ScopeViolationError as x, type SyncEncryptionAlgorithm as y, type SyncPhase as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@korajs/sync",
3
- "version": "1.0.0-beta.10",
3
+ "version": "1.0.0-beta.11",
4
4
  "description": "Sync protocol and transports for Kora.js with delta sync, causal ordering, and automatic reconnection",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -34,8 +34,8 @@
34
34
  ],
35
35
  "dependencies": {
36
36
  "protobufjs": "^8.0.1",
37
- "@korajs/core": "1.0.0-beta.10",
38
- "@korajs/merge": "1.0.0-beta.10"
37
+ "@korajs/core": "1.0.0-beta.11",
38
+ "@korajs/merge": "1.0.0-beta.11"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@fast-check/vitest": "0.2.0",