@korajs/store 0.6.0 → 1.0.0-beta.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.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/dist/adapters/better-sqlite3.cjs +94 -40
  3. package/dist/adapters/better-sqlite3.cjs.map +1 -1
  4. package/dist/adapters/better-sqlite3.d.cts +9 -1
  5. package/dist/adapters/better-sqlite3.d.ts +9 -1
  6. package/dist/adapters/better-sqlite3.js +62 -41
  7. package/dist/adapters/better-sqlite3.js.map +1 -1
  8. package/dist/adapters/indexeddb.cjs +24 -13
  9. package/dist/adapters/indexeddb.cjs.map +1 -1
  10. package/dist/adapters/indexeddb.d.cts +2 -2
  11. package/dist/adapters/indexeddb.d.ts +2 -2
  12. package/dist/adapters/indexeddb.js +4 -3
  13. package/dist/adapters/indexeddb.js.map +1 -1
  14. package/dist/adapters/sqlite-wasm.cjs +24 -13
  15. package/dist/adapters/sqlite-wasm.cjs.map +1 -1
  16. package/dist/adapters/sqlite-wasm.d.cts +27 -4
  17. package/dist/adapters/sqlite-wasm.d.ts +27 -4
  18. package/dist/adapters/sqlite-wasm.js +6 -4
  19. package/dist/{backup-JN3LB4YT.js → backup-5XZ7THNJ.js} +3 -3
  20. package/dist/{chunk-EZSTD2XC.js → chunk-5R4QMY3Z.js} +2 -2
  21. package/dist/{chunk-AGN3CIPB.js → chunk-EIVXWF4B.js} +2 -2
  22. package/dist/{chunk-56LL4XP6.js → chunk-ETDJEH2I.js} +42 -1
  23. package/dist/chunk-ETDJEH2I.js.map +1 -0
  24. package/dist/{chunk-XO4LMPAH.js → chunk-IOEFNHHP.js} +2 -35
  25. package/dist/chunk-IOEFNHHP.js.map +1 -0
  26. package/dist/{chunk-7BPETY5Y.js → chunk-OUQDC5Z6.js} +105 -8
  27. package/dist/chunk-OUQDC5Z6.js.map +1 -0
  28. package/dist/{chunk-LAWV6CFH.js → chunk-QL2XVZRN.js} +12 -1
  29. package/dist/chunk-QL2XVZRN.js.map +1 -0
  30. package/dist/{chunk-6AHYGQQT.js → chunk-RBPVEAVM.js} +4 -4
  31. package/dist/chunk-TVJEC5S2.js +40 -0
  32. package/dist/chunk-TVJEC5S2.js.map +1 -0
  33. package/dist/{export-audit-5GV6VRDZ.js → export-audit-VPGQWNR6.js} +3 -3
  34. package/dist/index.cjs +615 -106
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.cts +77 -7
  37. package/dist/index.d.ts +77 -7
  38. package/dist/index.js +423 -44
  39. package/dist/index.js.map +1 -1
  40. package/dist/internal.cjs +100 -30
  41. package/dist/internal.cjs.map +1 -1
  42. package/dist/internal.d.cts +3 -3
  43. package/dist/internal.d.ts +3 -3
  44. package/dist/internal.js +3 -3
  45. package/dist/{sqlite-wasm-channel-I9y_jObg.d.cts → sqlite-wasm-channel-DUDPclTE.d.cts} +2 -15
  46. package/dist/{sqlite-wasm-channel-I9y_jObg.d.ts → sqlite-wasm-channel-DUDPclTE.d.ts} +2 -15
  47. package/dist/sqlite-wasm-channel-H43KEZLM.js +12 -0
  48. package/dist/{types-DepnRDk_.d.cts → types-CJOVKxLw.d.cts} +43 -2
  49. package/dist/{types-DepnRDk_.d.ts → types-CJOVKxLw.d.ts} +43 -2
  50. package/dist/{types-CTr00g_d.d.cts → types-CyjXwrjW.d.cts} +1 -1
  51. package/dist/{types-BMyHmwvn.d.ts → types-DAxCladl.d.ts} +1 -1
  52. package/package.json +4 -2
  53. package/dist/chunk-56LL4XP6.js.map +0 -1
  54. package/dist/chunk-7BPETY5Y.js.map +0 -1
  55. package/dist/chunk-LAWV6CFH.js.map +0 -1
  56. package/dist/chunk-XO4LMPAH.js.map +0 -1
  57. package/dist/sqlite-wasm-channel-HDDW6UBH.js +0 -10
  58. /package/dist/{backup-JN3LB4YT.js.map → backup-5XZ7THNJ.js.map} +0 -0
  59. /package/dist/{chunk-EZSTD2XC.js.map → chunk-5R4QMY3Z.js.map} +0 -0
  60. /package/dist/{chunk-AGN3CIPB.js.map → chunk-EIVXWF4B.js.map} +0 -0
  61. /package/dist/{chunk-6AHYGQQT.js.map → chunk-RBPVEAVM.js.map} +0 -0
  62. /package/dist/{export-audit-5GV6VRDZ.js.map → export-audit-VPGQWNR6.js.map} +0 -0
  63. /package/dist/{sqlite-wasm-channel-HDDW6UBH.js.map → sqlite-wasm-channel-H43KEZLM.js.map} +0 -0
package/dist/index.d.cts CHANGED
@@ -1,9 +1,9 @@
1
- import { C as CollectionRecord, S as StorageAdapter, Q as QueryDescriptor, c as SubscriptionCallback, W as WhereClause, d as OrderByDirection, L as LocalMutationHandler, e as StoreConfig, A as ApplyRemoteOptions, f as MaterializedRowSnapshot } from './types-DepnRDk_.cjs';
2
- export { M as MigrationPlan, g as OrderByClause, h as StoreIsolation, T as Transaction, i as TransactionBufferedEntry, j as TransactionCommitBatch, k as TransactionCommitResult, l as WhereOperators } from './types-DepnRDk_.cjs';
3
- import { Operation, KoraError, VersionVector, SchemaDefinition, MergeTrace, CollectionDefinition, SequenceConfig, HybridLogicalClock, CausalTracker, OperationLog, ApplyResult, StateMachineDefinition, KoraEvent } from '@korajs/core';
1
+ import { C as CollectionRecord, S as StorageAdapter, Q as QueryDescriptor, c as SubscriptionCallback, W as WhereClause, d as OrderByDirection, L as LocalMutationHandler, e as StoreConfig, A as ApplyRemoteOptions, f as MaterializedRowSnapshot, g as RowVersionState } from './types-CJOVKxLw.cjs';
2
+ export { M as MigrationPlan, h as OrderByClause, i as StoreIsolation, T as Transaction, j as TransactionBufferedEntry, k as TransactionCommitBatch, l as TransactionCommitResult, m as WhereOperators } from './types-CJOVKxLw.cjs';
3
+ import { Operation, KoraError, VersionVector, SchemaDefinition, HLCTimestamp, MergeTrace, CollectionDefinition, SequenceConfig, HybridLogicalClock, CausalTracker, OperationLog, ApplyResult, StateMachineDefinition, KoraBytesValue, KoraEvent } from '@korajs/core';
4
4
  export { ApplyResult } from '@korajs/core';
5
- import { R as RelationEnforcer, L as LocalMutationContext } from './types-CTr00g_d.cjs';
6
- export { C as Collection } from './types-CTr00g_d.cjs';
5
+ import { R as RelationEnforcer, L as LocalMutationContext } from './types-CyjXwrjW.cjs';
6
+ export { C as Collection } from './types-CyjXwrjW.cjs';
7
7
  import * as yjs from 'yjs';
8
8
 
9
9
  /**
@@ -33,6 +33,18 @@ declare class QueryError extends KoraError {
33
33
  declare class RecordNotFoundError extends KoraError {
34
34
  constructor(collection: string, recordId: string);
35
35
  }
36
+ /**
37
+ * Thrown inside `applyRemoteOperation` when the row's version state changed
38
+ * between the caller's snapshot read and the guarded write (a concurrent local
39
+ * mutation landed in the window). The transaction is rolled back with nothing
40
+ * written; the caller re-reads fresh state, recomputes its merge, and retries.
41
+ * This is the optimistic-concurrency guard that keeps merge-engine results
42
+ * (richtext, add-wins arrays, constraint resolutions) from clobbering newer
43
+ * local edits they never saw.
44
+ */
45
+ declare class OptimisticLockError extends KoraError {
46
+ constructor(collection: string, recordId: string);
47
+ }
36
48
  /**
37
49
  * Thrown when a storage adapter operation fails.
38
50
  */
@@ -101,6 +113,20 @@ declare function computeAckCompactionWatermark(serverVector: VersionVector): Ver
101
113
  */
102
114
  declare function compactOperationLog(adapter: StorageAdapter, schema: SchemaDefinition, strategy: CompactionStrategy, serverVector: VersionVector): Promise<CompactionResult>;
103
115
 
116
+ /**
117
+ * Result of re-stamping unsynced operations after a clock correction.
118
+ */
119
+ interface ClockRebaseResult {
120
+ /** The rewritten operations, in causal order (original HLC total order preserved). */
121
+ operations: Operation[];
122
+ /** Maps each old (pre-rebase) operation id to its new content-addressed id. */
123
+ idMapping: Record<string, string>;
124
+ /** Number of operations that were re-stamped. */
125
+ rebasedCount: number;
126
+ /** Highest timestamp assigned during the rebase, or null when nothing was rebased. */
127
+ newMaxTimestamp: HLCTimestamp | null;
128
+ }
129
+
104
130
  declare const LAST_ACKED_SERVER_VECTOR_META_KEY = "last_acked_server_vector";
105
131
  /**
106
132
  * Serialize a version vector for `_kora_meta` storage.
@@ -715,6 +741,12 @@ declare class Store implements OperationLog {
715
741
  /**
716
742
  * Get the node ID for this store instance.
717
743
  */
744
+ /**
745
+ * Records the offset between server time and this device's clock
746
+ * (serverTime - localTime), learned at sync handshake. Lets the store's HLC
747
+ * validate remote timestamps correctly even when the local clock is wrong.
748
+ */
749
+ setClockReferenceOffset(offsetMs: number): void;
718
750
  getNodeId(): string;
719
751
  /**
720
752
  * Apply a remote operation received from sync.
@@ -722,6 +754,18 @@ declare class Store implements OperationLog {
722
754
  * and updates the version vector.
723
755
  */
724
756
  applyRemoteOperation(op: Operation, options?: ApplyRemoteOptions): Promise<ApplyResult>;
757
+ /**
758
+ * Materialize update/delete operations that were logged for a record BEFORE
759
+ * its insert arrived (reordered delivery). Runs inside the insert's write
760
+ * transaction, folding each orphan in timestamp order through the exact
761
+ * per-field LWW / LWW-delete rules the normal apply paths use, so the final
762
+ * row state equals what a device that received the operations in causal
763
+ * order computed. Called only when the insert created a previously-absent
764
+ * row — in that case every logged update/delete for the record is
765
+ * necessarily an orphan (rows are soft-deleted, never removed, so a row
766
+ * that is absent now was never materialized).
767
+ */
768
+ private foldOrphanedOperations;
725
769
  /**
726
770
  * Get operations from a node within a sequence number range.
727
771
  * Implements the OperationLog interface for computeDelta.
@@ -775,6 +819,14 @@ declare class Store implements OperationLog {
775
819
  * Load a materialized row by ID, including soft-deleted tombstones.
776
820
  */
777
821
  findMaterializedRow(collection: string, recordId: string): Promise<MaterializedRowSnapshot | null>;
822
+ /**
823
+ * Raw version state of a materialized row, for optimistic-concurrency guarded
824
+ * applies: capture this snapshot before computing a merge, pass it as
825
+ * `guardRowState`, and the apply refuses to write if the row changed since.
826
+ * Returns null when no row exists (which is itself a valid guard state — the
827
+ * apply then requires the row to still be absent).
828
+ */
829
+ getRowVersionState(collection: string, recordId: string): Promise<RowVersionState | null>;
778
830
  /**
779
831
  * Latest operation from this device for a record (used for delete-vs-update merge on sync).
780
832
  */
@@ -798,6 +850,18 @@ declare class Store implements OperationLog {
798
850
  * Local operations not yet reflected on the server version vector.
799
851
  */
800
852
  getUnsyncedOperations(serverVector: VersionVector): Promise<Operation[]>;
853
+ /**
854
+ * Re-stamp never-acknowledged local operations after a fast device clock was
855
+ * corrected, so sync can resume immediately. Safe because unacknowledged
856
+ * operations are private to this device (like unpushed git commits);
857
+ * acknowledged/shared operations are immutable and never touched.
858
+ *
859
+ * After the rewrite the store's HLC is advanced past the highest new
860
+ * timestamp so subsequent local writes keep sorting after the rebased ops.
861
+ * No data-change notifications are emitted: materialized values are
862
+ * unchanged, only version stamps move.
863
+ */
864
+ rebaseUnsyncedOperations(unsyncedOpIds: string[], correctedNowMs: number): Promise<ClockRebaseResult>;
801
865
  /**
802
866
  * Count of local operations ahead of the server version vector.
803
867
  */
@@ -1185,8 +1249,14 @@ declare function asRichTextSyncEngine(engine: unknown): RichTextSyncEngine | nul
1185
1249
  type RichtextInput = string | Uint8Array | ArrayBuffer | null | undefined;
1186
1250
  /**
1187
1251
  * Encodes richtext values into Yjs document updates.
1252
+ *
1253
+ * Also accepts the tagged `{ $koraBytes }` form that binary richtext values
1254
+ * take inside `op.data` (and, for old dev databases, the pre-fix numeric-key
1255
+ * object shape), so every consumer that writes op-data values to columns
1256
+ * inherits the decoding. Plain strings keep their exact historical behavior:
1257
+ * encoded as a fresh Yjs document containing the string.
1188
1258
  */
1189
- declare function encodeRichtext(value: RichtextInput): Uint8Array | null;
1259
+ declare function encodeRichtext(value: RichtextInput | KoraBytesValue): Uint8Array | null;
1190
1260
  /**
1191
1261
  * Decodes driver-provided richtext values into Uint8Array.
1192
1262
  */
@@ -1287,4 +1357,4 @@ declare function readAuditExportManifest(data: Uint8Array): AuditExportManifest;
1287
1357
  */
1288
1358
  declare function verifyAuditExportChecksum(data: Uint8Array): Promise<boolean>;
1289
1359
 
1290
- export { AdapterError, ApplyRemoteOptions, type AuditExportManifest, type AuditExportOptions, type AuditExportPayload, type AuditExportProgress, type AuditTraceQuery, type BackupManifest, type BackupOptions, type BackupProgress, COMPACTION_BASELINE_META_KEY, type CollectionAccessor, CollectionRecord, type CompactionResult, type CompactionStrategy, type CreateRichTextControllerOptions, InvalidStateTransitionError, LAST_ACKED_SERVER_VECTOR_META_KEY, LocalMutationHandler, MaterializedRowSnapshot, OrderByDirection, type PersistedAuditTrace, PersistenceError, QueryBuilder, QueryDescriptor, QueryError, QueryStore, QueryStoreCache, RecordNotFoundError, type ReplaySnapshot, type RestoreOptions, type RestoreResult, type RichTextAwarenessUser, type RichTextController, type RichTextControllerSnapshot, type RichTextCursorInfo, type RichTextSyncEngine, SequenceManager, StorageAdapter, Store, StoreConfig, StoreNotOpenError, SubscriptionBloomFilter, SubscriptionCallback, SubscriptionManager, type SubscriptionManagerOptions, type SubscriptionStats, type TransactionCollectionAccessor, TransactionContext, type TransactionContextConfig, WhereClause, WorkerInitError, WorkerTimeoutError, asRichTextSyncEngine, assertQueryReady, collectOperationsAheadOfServer, compactOperationLog, computeAckCompactionWatermark, createRichTextController, decodeAuditExport, decodeRichtext, deserializeVersionVectorFromMeta, encodeRichtext, exportBackup, getSharedQueryStoreCache, mergeVersionVectors, persistedAuditTraceFromEvent, pluralize, readAuditExportManifest, readBackupManifest, restoreBackup, richtextStatesEqual, richtextToPlainText, serializeVersionVectorToMeta, singularize, validateStateTransition, validateUpdateStateMachine, verifyAuditExportChecksum, verifyBackupChecksum };
1360
+ export { AdapterError, ApplyRemoteOptions, type AuditExportManifest, type AuditExportOptions, type AuditExportPayload, type AuditExportProgress, type AuditTraceQuery, type BackupManifest, type BackupOptions, type BackupProgress, COMPACTION_BASELINE_META_KEY, type ClockRebaseResult, type CollectionAccessor, CollectionRecord, type CompactionResult, type CompactionStrategy, type CreateRichTextControllerOptions, InvalidStateTransitionError, LAST_ACKED_SERVER_VECTOR_META_KEY, LocalMutationHandler, MaterializedRowSnapshot, OptimisticLockError, OrderByDirection, type PersistedAuditTrace, PersistenceError, QueryBuilder, QueryDescriptor, QueryError, QueryStore, QueryStoreCache, RecordNotFoundError, type ReplaySnapshot, type RestoreOptions, type RestoreResult, type RichTextAwarenessUser, type RichTextController, type RichTextControllerSnapshot, type RichTextCursorInfo, type RichTextSyncEngine, RowVersionState, SequenceManager, StorageAdapter, Store, StoreConfig, StoreNotOpenError, SubscriptionBloomFilter, SubscriptionCallback, SubscriptionManager, type SubscriptionManagerOptions, type SubscriptionStats, type TransactionCollectionAccessor, TransactionContext, type TransactionContextConfig, WhereClause, WorkerInitError, WorkerTimeoutError, asRichTextSyncEngine, assertQueryReady, collectOperationsAheadOfServer, compactOperationLog, computeAckCompactionWatermark, createRichTextController, decodeAuditExport, decodeRichtext, deserializeVersionVectorFromMeta, encodeRichtext, exportBackup, getSharedQueryStoreCache, mergeVersionVectors, persistedAuditTraceFromEvent, pluralize, readAuditExportManifest, readBackupManifest, restoreBackup, richtextStatesEqual, richtextToPlainText, serializeVersionVectorToMeta, singularize, validateStateTransition, validateUpdateStateMachine, verifyAuditExportChecksum, verifyBackupChecksum };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { C as CollectionRecord, S as StorageAdapter, Q as QueryDescriptor, c as SubscriptionCallback, W as WhereClause, d as OrderByDirection, L as LocalMutationHandler, e as StoreConfig, A as ApplyRemoteOptions, f as MaterializedRowSnapshot } from './types-DepnRDk_.js';
2
- export { M as MigrationPlan, g as OrderByClause, h as StoreIsolation, T as Transaction, i as TransactionBufferedEntry, j as TransactionCommitBatch, k as TransactionCommitResult, l as WhereOperators } from './types-DepnRDk_.js';
3
- import { Operation, KoraError, VersionVector, SchemaDefinition, MergeTrace, CollectionDefinition, SequenceConfig, HybridLogicalClock, CausalTracker, OperationLog, ApplyResult, StateMachineDefinition, KoraEvent } from '@korajs/core';
1
+ import { C as CollectionRecord, S as StorageAdapter, Q as QueryDescriptor, c as SubscriptionCallback, W as WhereClause, d as OrderByDirection, L as LocalMutationHandler, e as StoreConfig, A as ApplyRemoteOptions, f as MaterializedRowSnapshot, g as RowVersionState } from './types-CJOVKxLw.js';
2
+ export { M as MigrationPlan, h as OrderByClause, i as StoreIsolation, T as Transaction, j as TransactionBufferedEntry, k as TransactionCommitBatch, l as TransactionCommitResult, m as WhereOperators } from './types-CJOVKxLw.js';
3
+ import { Operation, KoraError, VersionVector, SchemaDefinition, HLCTimestamp, MergeTrace, CollectionDefinition, SequenceConfig, HybridLogicalClock, CausalTracker, OperationLog, ApplyResult, StateMachineDefinition, KoraBytesValue, KoraEvent } from '@korajs/core';
4
4
  export { ApplyResult } from '@korajs/core';
5
- import { R as RelationEnforcer, L as LocalMutationContext } from './types-BMyHmwvn.js';
6
- export { C as Collection } from './types-BMyHmwvn.js';
5
+ import { R as RelationEnforcer, L as LocalMutationContext } from './types-DAxCladl.js';
6
+ export { C as Collection } from './types-DAxCladl.js';
7
7
  import * as yjs from 'yjs';
8
8
 
9
9
  /**
@@ -33,6 +33,18 @@ declare class QueryError extends KoraError {
33
33
  declare class RecordNotFoundError extends KoraError {
34
34
  constructor(collection: string, recordId: string);
35
35
  }
36
+ /**
37
+ * Thrown inside `applyRemoteOperation` when the row's version state changed
38
+ * between the caller's snapshot read and the guarded write (a concurrent local
39
+ * mutation landed in the window). The transaction is rolled back with nothing
40
+ * written; the caller re-reads fresh state, recomputes its merge, and retries.
41
+ * This is the optimistic-concurrency guard that keeps merge-engine results
42
+ * (richtext, add-wins arrays, constraint resolutions) from clobbering newer
43
+ * local edits they never saw.
44
+ */
45
+ declare class OptimisticLockError extends KoraError {
46
+ constructor(collection: string, recordId: string);
47
+ }
36
48
  /**
37
49
  * Thrown when a storage adapter operation fails.
38
50
  */
@@ -101,6 +113,20 @@ declare function computeAckCompactionWatermark(serverVector: VersionVector): Ver
101
113
  */
102
114
  declare function compactOperationLog(adapter: StorageAdapter, schema: SchemaDefinition, strategy: CompactionStrategy, serverVector: VersionVector): Promise<CompactionResult>;
103
115
 
116
+ /**
117
+ * Result of re-stamping unsynced operations after a clock correction.
118
+ */
119
+ interface ClockRebaseResult {
120
+ /** The rewritten operations, in causal order (original HLC total order preserved). */
121
+ operations: Operation[];
122
+ /** Maps each old (pre-rebase) operation id to its new content-addressed id. */
123
+ idMapping: Record<string, string>;
124
+ /** Number of operations that were re-stamped. */
125
+ rebasedCount: number;
126
+ /** Highest timestamp assigned during the rebase, or null when nothing was rebased. */
127
+ newMaxTimestamp: HLCTimestamp | null;
128
+ }
129
+
104
130
  declare const LAST_ACKED_SERVER_VECTOR_META_KEY = "last_acked_server_vector";
105
131
  /**
106
132
  * Serialize a version vector for `_kora_meta` storage.
@@ -715,6 +741,12 @@ declare class Store implements OperationLog {
715
741
  /**
716
742
  * Get the node ID for this store instance.
717
743
  */
744
+ /**
745
+ * Records the offset between server time and this device's clock
746
+ * (serverTime - localTime), learned at sync handshake. Lets the store's HLC
747
+ * validate remote timestamps correctly even when the local clock is wrong.
748
+ */
749
+ setClockReferenceOffset(offsetMs: number): void;
718
750
  getNodeId(): string;
719
751
  /**
720
752
  * Apply a remote operation received from sync.
@@ -722,6 +754,18 @@ declare class Store implements OperationLog {
722
754
  * and updates the version vector.
723
755
  */
724
756
  applyRemoteOperation(op: Operation, options?: ApplyRemoteOptions): Promise<ApplyResult>;
757
+ /**
758
+ * Materialize update/delete operations that were logged for a record BEFORE
759
+ * its insert arrived (reordered delivery). Runs inside the insert's write
760
+ * transaction, folding each orphan in timestamp order through the exact
761
+ * per-field LWW / LWW-delete rules the normal apply paths use, so the final
762
+ * row state equals what a device that received the operations in causal
763
+ * order computed. Called only when the insert created a previously-absent
764
+ * row — in that case every logged update/delete for the record is
765
+ * necessarily an orphan (rows are soft-deleted, never removed, so a row
766
+ * that is absent now was never materialized).
767
+ */
768
+ private foldOrphanedOperations;
725
769
  /**
726
770
  * Get operations from a node within a sequence number range.
727
771
  * Implements the OperationLog interface for computeDelta.
@@ -775,6 +819,14 @@ declare class Store implements OperationLog {
775
819
  * Load a materialized row by ID, including soft-deleted tombstones.
776
820
  */
777
821
  findMaterializedRow(collection: string, recordId: string): Promise<MaterializedRowSnapshot | null>;
822
+ /**
823
+ * Raw version state of a materialized row, for optimistic-concurrency guarded
824
+ * applies: capture this snapshot before computing a merge, pass it as
825
+ * `guardRowState`, and the apply refuses to write if the row changed since.
826
+ * Returns null when no row exists (which is itself a valid guard state — the
827
+ * apply then requires the row to still be absent).
828
+ */
829
+ getRowVersionState(collection: string, recordId: string): Promise<RowVersionState | null>;
778
830
  /**
779
831
  * Latest operation from this device for a record (used for delete-vs-update merge on sync).
780
832
  */
@@ -798,6 +850,18 @@ declare class Store implements OperationLog {
798
850
  * Local operations not yet reflected on the server version vector.
799
851
  */
800
852
  getUnsyncedOperations(serverVector: VersionVector): Promise<Operation[]>;
853
+ /**
854
+ * Re-stamp never-acknowledged local operations after a fast device clock was
855
+ * corrected, so sync can resume immediately. Safe because unacknowledged
856
+ * operations are private to this device (like unpushed git commits);
857
+ * acknowledged/shared operations are immutable and never touched.
858
+ *
859
+ * After the rewrite the store's HLC is advanced past the highest new
860
+ * timestamp so subsequent local writes keep sorting after the rebased ops.
861
+ * No data-change notifications are emitted: materialized values are
862
+ * unchanged, only version stamps move.
863
+ */
864
+ rebaseUnsyncedOperations(unsyncedOpIds: string[], correctedNowMs: number): Promise<ClockRebaseResult>;
801
865
  /**
802
866
  * Count of local operations ahead of the server version vector.
803
867
  */
@@ -1185,8 +1249,14 @@ declare function asRichTextSyncEngine(engine: unknown): RichTextSyncEngine | nul
1185
1249
  type RichtextInput = string | Uint8Array | ArrayBuffer | null | undefined;
1186
1250
  /**
1187
1251
  * Encodes richtext values into Yjs document updates.
1252
+ *
1253
+ * Also accepts the tagged `{ $koraBytes }` form that binary richtext values
1254
+ * take inside `op.data` (and, for old dev databases, the pre-fix numeric-key
1255
+ * object shape), so every consumer that writes op-data values to columns
1256
+ * inherits the decoding. Plain strings keep their exact historical behavior:
1257
+ * encoded as a fresh Yjs document containing the string.
1188
1258
  */
1189
- declare function encodeRichtext(value: RichtextInput): Uint8Array | null;
1259
+ declare function encodeRichtext(value: RichtextInput | KoraBytesValue): Uint8Array | null;
1190
1260
  /**
1191
1261
  * Decodes driver-provided richtext values into Uint8Array.
1192
1262
  */
@@ -1287,4 +1357,4 @@ declare function readAuditExportManifest(data: Uint8Array): AuditExportManifest;
1287
1357
  */
1288
1358
  declare function verifyAuditExportChecksum(data: Uint8Array): Promise<boolean>;
1289
1359
 
1290
- export { AdapterError, ApplyRemoteOptions, type AuditExportManifest, type AuditExportOptions, type AuditExportPayload, type AuditExportProgress, type AuditTraceQuery, type BackupManifest, type BackupOptions, type BackupProgress, COMPACTION_BASELINE_META_KEY, type CollectionAccessor, CollectionRecord, type CompactionResult, type CompactionStrategy, type CreateRichTextControllerOptions, InvalidStateTransitionError, LAST_ACKED_SERVER_VECTOR_META_KEY, LocalMutationHandler, MaterializedRowSnapshot, OrderByDirection, type PersistedAuditTrace, PersistenceError, QueryBuilder, QueryDescriptor, QueryError, QueryStore, QueryStoreCache, RecordNotFoundError, type ReplaySnapshot, type RestoreOptions, type RestoreResult, type RichTextAwarenessUser, type RichTextController, type RichTextControllerSnapshot, type RichTextCursorInfo, type RichTextSyncEngine, SequenceManager, StorageAdapter, Store, StoreConfig, StoreNotOpenError, SubscriptionBloomFilter, SubscriptionCallback, SubscriptionManager, type SubscriptionManagerOptions, type SubscriptionStats, type TransactionCollectionAccessor, TransactionContext, type TransactionContextConfig, WhereClause, WorkerInitError, WorkerTimeoutError, asRichTextSyncEngine, assertQueryReady, collectOperationsAheadOfServer, compactOperationLog, computeAckCompactionWatermark, createRichTextController, decodeAuditExport, decodeRichtext, deserializeVersionVectorFromMeta, encodeRichtext, exportBackup, getSharedQueryStoreCache, mergeVersionVectors, persistedAuditTraceFromEvent, pluralize, readAuditExportManifest, readBackupManifest, restoreBackup, richtextStatesEqual, richtextToPlainText, serializeVersionVectorToMeta, singularize, validateStateTransition, validateUpdateStateMachine, verifyAuditExportChecksum, verifyBackupChecksum };
1360
+ export { AdapterError, ApplyRemoteOptions, type AuditExportManifest, type AuditExportOptions, type AuditExportPayload, type AuditExportProgress, type AuditTraceQuery, type BackupManifest, type BackupOptions, type BackupProgress, COMPACTION_BASELINE_META_KEY, type ClockRebaseResult, type CollectionAccessor, CollectionRecord, type CompactionResult, type CompactionStrategy, type CreateRichTextControllerOptions, InvalidStateTransitionError, LAST_ACKED_SERVER_VECTOR_META_KEY, LocalMutationHandler, MaterializedRowSnapshot, OptimisticLockError, OrderByDirection, type PersistedAuditTrace, PersistenceError, QueryBuilder, QueryDescriptor, QueryError, QueryStore, QueryStoreCache, RecordNotFoundError, type ReplaySnapshot, type RestoreOptions, type RestoreResult, type RichTextAwarenessUser, type RichTextController, type RichTextControllerSnapshot, type RichTextCursorInfo, type RichTextSyncEngine, RowVersionState, SequenceManager, StorageAdapter, Store, StoreConfig, StoreNotOpenError, SubscriptionBloomFilter, SubscriptionCallback, SubscriptionManager, type SubscriptionManagerOptions, type SubscriptionStats, type TransactionCollectionAccessor, TransactionContext, type TransactionContextConfig, WhereClause, WorkerInitError, WorkerTimeoutError, asRichTextSyncEngine, assertQueryReady, collectOperationsAheadOfServer, compactOperationLog, computeAckCompactionWatermark, createRichTextController, decodeAuditExport, decodeRichtext, deserializeVersionVectorFromMeta, encodeRichtext, exportBackup, getSharedQueryStoreCache, mergeVersionVectors, persistedAuditTraceFromEvent, pluralize, readAuditExportManifest, readBackupManifest, restoreBackup, richtextStatesEqual, richtextToPlainText, serializeVersionVectorToMeta, singularize, validateStateTransition, validateUpdateStateMachine, verifyAuditExportChecksum, verifyBackupChecksum };