@korajs/sync 1.0.0-beta.1 → 1.0.0-beta.2

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-CZLMdZ0k.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-BGr-_eH8.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-CZLMdZ0k.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-BGr-_eH8.js';
2
2
  import { Operation } from '@korajs/core';
3
3
 
4
4
  /**
@@ -208,6 +208,48 @@ interface QueueStorage {
208
208
  /** Return number of operations in storage */
209
209
  count(): Promise<number>;
210
210
  }
211
+ /**
212
+ * A record of one outbound operation the server permanently refused. Preserved so
213
+ * a rejected op is explainable and reconcilable rather than silently lost.
214
+ */
215
+ interface RejectedOperation {
216
+ /** Content-addressed id of the rejected operation. */
217
+ operationId: string;
218
+ /** Collection the operation targeted. */
219
+ collection: string;
220
+ /** Record the operation targeted. */
221
+ recordId: string;
222
+ /** Stable, machine-readable reason code from the server. */
223
+ code: string;
224
+ /** Human-readable explanation. */
225
+ message: string;
226
+ /** Whether resubmitting the identical operation may later succeed. */
227
+ retriable: boolean;
228
+ /** Wall-clock time (ms since epoch) the rejection was recorded. Display only. */
229
+ rejectedAt: number;
230
+ }
231
+ /**
232
+ * Interface for durably persisting operations the server rejected, so the record
233
+ * survives a page refresh. Keyed by operation id (idempotent on re-rejection).
234
+ */
235
+ interface RejectedOperationStorage {
236
+ /** Record (or overwrite) a rejected operation. */
237
+ record(rejected: RejectedOperation): Promise<void>;
238
+ /** List all recorded rejected operations. */
239
+ list(): Promise<RejectedOperation[]>;
240
+ /** Remove rejected operations by their operation ids (after the app reconciles them). */
241
+ remove(operationIds: string[]): Promise<void>;
242
+ }
243
+ /**
244
+ * In-memory {@link RejectedOperationStorage}. The default when no durable store is
245
+ * provided; suitable for tests and ephemeral sessions.
246
+ */
247
+ declare class MemoryRejectedOperationStorage implements RejectedOperationStorage {
248
+ private readonly rejected;
249
+ record(rejected: RejectedOperation): Promise<void>;
250
+ list(): Promise<RejectedOperation[]>;
251
+ remove(operationIds: string[]): Promise<void>;
252
+ }
211
253
  /**
212
254
  * Thrown when an operation violates sync scope constraints.
213
255
  * This can happen when:
@@ -349,6 +391,33 @@ interface ErrorMessage {
349
391
  message: string;
350
392
  retriable: boolean;
351
393
  }
394
+ /**
395
+ * Server-to-client rejection of ONE specific operation the client submitted.
396
+ *
397
+ * Unlike {@link ErrorMessage}, which is connection-level, this is tied to an
398
+ * `operationId` so the client can divert exactly that operation out of its
399
+ * pending outbound queue and into a durable rejected-operations store — kept and
400
+ * explainable rather than silently retried forever or lost on the batch ack. The
401
+ * operation never entered the server's authoritative log, so no other replica
402
+ * ever sees it; the submitter is told so its optimistic local copy can be
403
+ * reconciled (rolled back or resubmitted) by the app.
404
+ */
405
+ interface OperationRejectedMessage {
406
+ type: 'operation-rejected';
407
+ messageId: string;
408
+ /** Content-addressed id of the rejected operation. */
409
+ operationId: string;
410
+ /** Collection the rejected operation targeted (for app routing / display). */
411
+ collection: string;
412
+ /** Record the rejected operation targeted. */
413
+ recordId: string;
414
+ /** Stable, machine-readable reason code. */
415
+ code: string;
416
+ /** Human-readable explanation. */
417
+ message: string;
418
+ /** Whether resubmitting the identical operation may later succeed. */
419
+ retriable: boolean;
420
+ }
352
421
  /**
353
422
  * Awareness state for a single client (cursor position, user info).
354
423
  * Wire-format representation for JSON transport.
@@ -441,7 +510,7 @@ interface BlobChunkPushMessage {
441
510
  /**
442
511
  * Union of all sync protocol messages.
443
512
  */
444
- type SyncMessage = HandshakeMessage | HandshakeResponseMessage | OperationBatchMessage | AcknowledgmentMessage | ErrorMessage | AwarenessUpdateMessage | YjsDocUpdateMessage | BlobChunkRequestMessage | BlobChunkResponseMessage | BlobChunkPushMessage;
513
+ type SyncMessage = HandshakeMessage | HandshakeResponseMessage | OperationBatchMessage | AcknowledgmentMessage | ErrorMessage | OperationRejectedMessage | AwarenessUpdateMessage | YjsDocUpdateMessage | BlobChunkRequestMessage | BlobChunkResponseMessage | BlobChunkPushMessage;
445
514
  /**
446
515
  * Check if an unknown value is a valid SyncMessage.
447
516
  */
@@ -466,6 +535,10 @@ declare function isAcknowledgmentMessage(value: unknown): value is Acknowledgmen
466
535
  * Check if a value is an ErrorMessage.
467
536
  */
468
537
  declare function isErrorMessage(value: unknown): value is ErrorMessage;
538
+ /**
539
+ * Check if a value is an OperationRejectedMessage.
540
+ */
541
+ declare function isOperationRejectedMessage(value: unknown): value is OperationRejectedMessage;
469
542
  /**
470
543
  * Check if a value is an AwarenessUpdateMessage.
471
544
  */
@@ -529,4 +602,4 @@ interface SyncTransport {
529
602
  isConnected(): boolean;
530
603
  }
531
604
 
532
- export { type AcknowledgmentMessage as A, type BlobChunkRequestMessage as B, isAwarenessUpdateMessage as C, type DeltaCursor as D, type EncryptedPayload as E, isBlobChunkPushMessage as F, isBlobChunkRequestMessage as G, type HandshakeMessage as H, InvalidScopeError as I, isBlobChunkResponseMessage as J, isErrorMessage as K, isHandshakeMessage as L, isHandshakeResponseMessage as M, isOperationBatchMessage as N, type OperationBatchMessage as O, isSyncMessage as P, type QueueStorage as Q, isYjsDocUpdateMessage as R, type SyncScopeMap as S, type TransportOptions as T, operationMatchesQuerySubsets as U, type VersionedKey as V, type WireFormat as W, type YjsDocUpdateMessage as Y, type SyncMessage as a, 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 AwarenessStateWire as o, type AwarenessUpdateMessage as p, type ErrorMessage as q, type HandshakeResponseMessage as r, SYNC_STATES as s, SYNC_STATUSES as t, ScopeViolationError as u, type SyncEncryptionAlgorithm as v, type SyncScopeContext as w, type SyncStatus as x, dedupeQuerySubsets as y, isAcknowledgmentMessage as z };
605
+ 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 };
@@ -208,6 +208,48 @@ interface QueueStorage {
208
208
  /** Return number of operations in storage */
209
209
  count(): Promise<number>;
210
210
  }
211
+ /**
212
+ * A record of one outbound operation the server permanently refused. Preserved so
213
+ * a rejected op is explainable and reconcilable rather than silently lost.
214
+ */
215
+ interface RejectedOperation {
216
+ /** Content-addressed id of the rejected operation. */
217
+ operationId: string;
218
+ /** Collection the operation targeted. */
219
+ collection: string;
220
+ /** Record the operation targeted. */
221
+ recordId: string;
222
+ /** Stable, machine-readable reason code from the server. */
223
+ code: string;
224
+ /** Human-readable explanation. */
225
+ message: string;
226
+ /** Whether resubmitting the identical operation may later succeed. */
227
+ retriable: boolean;
228
+ /** Wall-clock time (ms since epoch) the rejection was recorded. Display only. */
229
+ rejectedAt: number;
230
+ }
231
+ /**
232
+ * Interface for durably persisting operations the server rejected, so the record
233
+ * survives a page refresh. Keyed by operation id (idempotent on re-rejection).
234
+ */
235
+ interface RejectedOperationStorage {
236
+ /** Record (or overwrite) a rejected operation. */
237
+ record(rejected: RejectedOperation): Promise<void>;
238
+ /** List all recorded rejected operations. */
239
+ list(): Promise<RejectedOperation[]>;
240
+ /** Remove rejected operations by their operation ids (after the app reconciles them). */
241
+ remove(operationIds: string[]): Promise<void>;
242
+ }
243
+ /**
244
+ * In-memory {@link RejectedOperationStorage}. The default when no durable store is
245
+ * provided; suitable for tests and ephemeral sessions.
246
+ */
247
+ declare class MemoryRejectedOperationStorage implements RejectedOperationStorage {
248
+ private readonly rejected;
249
+ record(rejected: RejectedOperation): Promise<void>;
250
+ list(): Promise<RejectedOperation[]>;
251
+ remove(operationIds: string[]): Promise<void>;
252
+ }
211
253
  /**
212
254
  * Thrown when an operation violates sync scope constraints.
213
255
  * This can happen when:
@@ -349,6 +391,33 @@ interface ErrorMessage {
349
391
  message: string;
350
392
  retriable: boolean;
351
393
  }
394
+ /**
395
+ * Server-to-client rejection of ONE specific operation the client submitted.
396
+ *
397
+ * Unlike {@link ErrorMessage}, which is connection-level, this is tied to an
398
+ * `operationId` so the client can divert exactly that operation out of its
399
+ * pending outbound queue and into a durable rejected-operations store — kept and
400
+ * explainable rather than silently retried forever or lost on the batch ack. The
401
+ * operation never entered the server's authoritative log, so no other replica
402
+ * ever sees it; the submitter is told so its optimistic local copy can be
403
+ * reconciled (rolled back or resubmitted) by the app.
404
+ */
405
+ interface OperationRejectedMessage {
406
+ type: 'operation-rejected';
407
+ messageId: string;
408
+ /** Content-addressed id of the rejected operation. */
409
+ operationId: string;
410
+ /** Collection the rejected operation targeted (for app routing / display). */
411
+ collection: string;
412
+ /** Record the rejected operation targeted. */
413
+ recordId: string;
414
+ /** Stable, machine-readable reason code. */
415
+ code: string;
416
+ /** Human-readable explanation. */
417
+ message: string;
418
+ /** Whether resubmitting the identical operation may later succeed. */
419
+ retriable: boolean;
420
+ }
352
421
  /**
353
422
  * Awareness state for a single client (cursor position, user info).
354
423
  * Wire-format representation for JSON transport.
@@ -441,7 +510,7 @@ interface BlobChunkPushMessage {
441
510
  /**
442
511
  * Union of all sync protocol messages.
443
512
  */
444
- type SyncMessage = HandshakeMessage | HandshakeResponseMessage | OperationBatchMessage | AcknowledgmentMessage | ErrorMessage | AwarenessUpdateMessage | YjsDocUpdateMessage | BlobChunkRequestMessage | BlobChunkResponseMessage | BlobChunkPushMessage;
513
+ type SyncMessage = HandshakeMessage | HandshakeResponseMessage | OperationBatchMessage | AcknowledgmentMessage | ErrorMessage | OperationRejectedMessage | AwarenessUpdateMessage | YjsDocUpdateMessage | BlobChunkRequestMessage | BlobChunkResponseMessage | BlobChunkPushMessage;
445
514
  /**
446
515
  * Check if an unknown value is a valid SyncMessage.
447
516
  */
@@ -466,6 +535,10 @@ declare function isAcknowledgmentMessage(value: unknown): value is Acknowledgmen
466
535
  * Check if a value is an ErrorMessage.
467
536
  */
468
537
  declare function isErrorMessage(value: unknown): value is ErrorMessage;
538
+ /**
539
+ * Check if a value is an OperationRejectedMessage.
540
+ */
541
+ declare function isOperationRejectedMessage(value: unknown): value is OperationRejectedMessage;
469
542
  /**
470
543
  * Check if a value is an AwarenessUpdateMessage.
471
544
  */
@@ -529,4 +602,4 @@ interface SyncTransport {
529
602
  isConnected(): boolean;
530
603
  }
531
604
 
532
- export { type AcknowledgmentMessage as A, type BlobChunkRequestMessage as B, isAwarenessUpdateMessage as C, type DeltaCursor as D, type EncryptedPayload as E, isBlobChunkPushMessage as F, isBlobChunkRequestMessage as G, type HandshakeMessage as H, InvalidScopeError as I, isBlobChunkResponseMessage as J, isErrorMessage as K, isHandshakeMessage as L, isHandshakeResponseMessage as M, isOperationBatchMessage as N, type OperationBatchMessage as O, isSyncMessage as P, type QueueStorage as Q, isYjsDocUpdateMessage as R, type SyncScopeMap as S, type TransportOptions as T, operationMatchesQuerySubsets as U, type VersionedKey as V, type WireFormat as W, type YjsDocUpdateMessage as Y, type SyncMessage as a, 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 AwarenessStateWire as o, type AwarenessUpdateMessage as p, type ErrorMessage as q, type HandshakeResponseMessage as r, SYNC_STATES as s, SYNC_STATUSES as t, ScopeViolationError as u, type SyncEncryptionAlgorithm as v, type SyncScopeContext as w, type SyncStatus as x, dedupeQuerySubsets as y, isAcknowledgmentMessage as z };
605
+ 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@korajs/sync",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.2",
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.1",
38
- "@korajs/merge": "1.0.0-beta.1"
37
+ "@korajs/core": "1.0.0-beta.2",
38
+ "@korajs/merge": "1.0.0-beta.2"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@fast-check/vitest": "0.2.0",