@dabble/patches 0.7.0 → 0.7.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.
Files changed (89) hide show
  1. package/dist/algorithms/{client → ot/client}/applyCommittedChanges.d.ts +3 -3
  2. package/dist/algorithms/{client → ot/client}/applyCommittedChanges.js +1 -1
  3. package/dist/algorithms/{client → ot/client}/createStateFromSnapshot.d.ts +3 -3
  4. package/dist/algorithms/{client → ot/client}/createStateFromSnapshot.js +1 -1
  5. package/dist/algorithms/{server → ot/server}/commitChanges.d.ts +10 -10
  6. package/dist/algorithms/{server → ot/server}/commitChanges.js +2 -2
  7. package/dist/algorithms/{server → ot/server}/createVersion.d.ts +5 -5
  8. package/dist/algorithms/{server → ot/server}/createVersion.js +2 -2
  9. package/dist/algorithms/{server → ot/server}/getSnapshotAtRevision.d.ts +5 -5
  10. package/dist/algorithms/{server → ot/server}/getSnapshotAtRevision.js +1 -1
  11. package/dist/algorithms/{server → ot/server}/getStateAtRevision.d.ts +5 -5
  12. package/dist/algorithms/{server → ot/server}/getStateAtRevision.js +1 -1
  13. package/dist/algorithms/{server → ot/server}/handleOfflineSessionsAndBatches.d.ts +5 -5
  14. package/dist/algorithms/{server → ot/server}/handleOfflineSessionsAndBatches.js +3 -3
  15. package/dist/algorithms/{server → ot/server}/transformIncomingChanges.d.ts +3 -3
  16. package/dist/algorithms/{server → ot/server}/transformIncomingChanges.js +3 -3
  17. package/dist/algorithms/{shared → ot/shared}/applyChanges.d.ts +3 -3
  18. package/dist/algorithms/{shared → ot/shared}/applyChanges.js +2 -2
  19. package/dist/algorithms/{shared → ot/shared}/changeBatching.d.ts +3 -3
  20. package/dist/algorithms/{shared → ot/shared}/changeBatching.js +2 -2
  21. package/dist/algorithms/{shared → ot/shared}/rebaseChanges.d.ts +3 -3
  22. package/dist/algorithms/{shared → ot/shared}/rebaseChanges.js +2 -2
  23. package/dist/client/InMemoryStore.js +1 -1
  24. package/dist/client/IndexedDBStore.js +1 -1
  25. package/dist/client/LWWAlgorithm.js +3 -2
  26. package/dist/client/LWWDoc.d.ts +3 -1
  27. package/dist/client/LWWDoc.js +4 -2
  28. package/dist/client/OTAlgorithm.js +2 -2
  29. package/dist/client/OTDoc.js +2 -2
  30. package/dist/client/OTIndexedDBStore.js +1 -1
  31. package/dist/client/Patches.d.ts +5 -0
  32. package/dist/client/Patches.js +16 -2
  33. package/dist/client/PatchesHistoryClient.js +1 -1
  34. package/dist/compression/index.d.ts +1 -1
  35. package/dist/compression/index.js +1 -6
  36. package/dist/{algorithms/shared → compression}/lz.js +1 -1
  37. package/dist/net/PatchesSync.d.ts +8 -8
  38. package/dist/net/PatchesSync.js +1 -1
  39. package/dist/net/index.d.ts +1 -2
  40. package/dist/net/protocol/JSONRPCServer.js +5 -3
  41. package/dist/net/webrtc/WebRTCAwareness.js +2 -3
  42. package/dist/net/websocket/AuthorizationProvider.d.ts +2 -2
  43. package/dist/net/websocket/WebSocketTransport.js +5 -2
  44. package/dist/server/CompressedStoreBackend.d.ts +3 -3
  45. package/dist/server/CompressedStoreBackend.js +4 -4
  46. package/dist/server/LWWMemoryStoreBackend.d.ts +5 -5
  47. package/dist/server/LWWMemoryStoreBackend.js +2 -11
  48. package/dist/server/LWWServer.d.ts +1 -1
  49. package/dist/server/LWWServer.js +13 -6
  50. package/dist/server/OTBranchManager.js +3 -3
  51. package/dist/server/OTServer.js +6 -7
  52. package/dist/server/PatchesHistoryManager.d.ts +6 -14
  53. package/dist/server/PatchesHistoryManager.js +2 -13
  54. package/dist/server/index.d.ts +2 -2
  55. package/dist/server/types.d.ts +9 -29
  56. package/dist/shared/doc-manager.d.ts +89 -0
  57. package/dist/shared/doc-manager.js +126 -0
  58. package/dist/shared/utils.d.ts +22 -0
  59. package/dist/shared/utils.js +22 -0
  60. package/dist/solid/context.d.ts +2 -2
  61. package/dist/solid/doc-manager.d.ts +3 -81
  62. package/dist/solid/doc-manager.js +1 -120
  63. package/dist/solid/index.d.ts +6 -4
  64. package/dist/solid/index.js +4 -0
  65. package/dist/solid/managed-docs.d.ts +63 -0
  66. package/dist/solid/managed-docs.js +105 -0
  67. package/dist/solid/primitives.d.ts +73 -68
  68. package/dist/solid/primitives.js +111 -4
  69. package/dist/solid/utils.d.ts +1 -0
  70. package/dist/solid/utils.js +6 -0
  71. package/dist/vue/composables.d.ts +67 -35
  72. package/dist/vue/composables.js +111 -4
  73. package/dist/vue/doc-manager.d.ts +3 -81
  74. package/dist/vue/doc-manager.js +1 -120
  75. package/dist/vue/index.d.ts +6 -4
  76. package/dist/vue/index.js +4 -0
  77. package/dist/vue/managed-docs.d.ts +66 -0
  78. package/dist/vue/managed-docs.js +101 -0
  79. package/dist/vue/provider.d.ts +2 -2
  80. package/dist/vue/utils.d.ts +1 -0
  81. package/dist/vue/utils.js +6 -0
  82. package/package.json +1 -1
  83. package/dist/algorithms/client/makeChange.d.ts +0 -9
  84. package/dist/algorithms/client/makeChange.js +0 -29
  85. package/dist/algorithms/lww/index.d.ts +0 -2
  86. package/dist/algorithms/lww/index.js +0 -1
  87. package/dist/net/types.d.ts +0 -8
  88. package/dist/net/types.js +0 -0
  89. /package/dist/{algorithms/shared → compression}/lz.d.ts +0 -0
@@ -1,7 +1,7 @@
1
- import { PatchesSnapshot, Change } from '../../types.js';
2
- import '../../json-patch/JSONPatch.js';
1
+ import { PatchesSnapshot, Change } from '../../../types.js';
2
+ import '../../../json-patch/JSONPatch.js';
3
3
  import '@dabble/delta';
4
- import '../../json-patch/types.js';
4
+ import '../../../json-patch/types.js';
5
5
 
6
6
  /**
7
7
  * Applies incoming changes from the server that were *not* initiated by this client.
@@ -1,4 +1,4 @@
1
- import "../../chunk-IZ2YBCUP.js";
1
+ import "../../../chunk-IZ2YBCUP.js";
2
2
  import { applyChanges } from "../shared/applyChanges.js";
3
3
  import { rebaseChanges } from "../shared/rebaseChanges.js";
4
4
  function applyCommittedChanges(snapshot, committedChangesFromServer) {
@@ -1,7 +1,7 @@
1
- import { PatchesSnapshot } from '../../types.js';
2
- import '../../json-patch/JSONPatch.js';
1
+ import { PatchesSnapshot } from '../../../types.js';
2
+ import '../../../json-patch/JSONPatch.js';
3
3
  import '@dabble/delta';
4
- import '../../json-patch/types.js';
4
+ import '../../../json-patch/types.js';
5
5
 
6
6
  /**
7
7
  * Creates the in-memory state from a snapshot.
@@ -1,4 +1,4 @@
1
- import "../../chunk-IZ2YBCUP.js";
1
+ import "../../../chunk-IZ2YBCUP.js";
2
2
  import { applyChanges } from "../shared/applyChanges.js";
3
3
  function createStateFromSnapshot(snapshot) {
4
4
  return applyChanges(snapshot.state, snapshot.changes);
@@ -1,13 +1,13 @@
1
- import { CommitResult } from '../../server/PatchesServer.js';
2
- import { PatchesStoreBackend } from '../../server/types.js';
3
- import { ChangeInput, CommitChangesOptions } from '../../types.js';
4
- import '../../net/protocol/JSONRPCServer.js';
5
- import '../../event-signal.js';
6
- import '../../net/websocket/AuthorizationProvider.js';
7
- import '../../json-patch/types.js';
8
- import '../../json-patch/JSONPatch.js';
1
+ import { CommitResult } from '../../../server/PatchesServer.js';
2
+ import { OTStoreBackend } from '../../../server/types.js';
3
+ import { ChangeInput, CommitChangesOptions } from '../../../types.js';
4
+ import '../../../net/protocol/JSONRPCServer.js';
5
+ import '../../../event-signal.js';
6
+ import '../../../net/websocket/AuthorizationProvider.js';
7
+ import '../../../json-patch/types.js';
8
+ import '../../../json-patch/JSONPatch.js';
9
9
  import '@dabble/delta';
10
- import '../../net/protocol/types.js';
10
+ import '../../../net/protocol/types.js';
11
11
 
12
12
  /**
13
13
  * Commits a set of changes to a document, applying operational transformation as needed.
@@ -38,6 +38,6 @@ import '../../net/protocol/types.js';
38
38
  * - catchupChanges: Changes the client missed (or a synthetic root-replace for offline-first clients)
39
39
  * - newChanges: The client's changes after transformation
40
40
  */
41
- declare function commitChanges(store: PatchesStoreBackend, docId: string, changes: ChangeInput[], sessionTimeoutMillis: number, options?: CommitChangesOptions, maxStorageBytes?: number): Promise<CommitResult>;
41
+ declare function commitChanges(store: OTStoreBackend, docId: string, changes: ChangeInput[], sessionTimeoutMillis: number, options?: CommitChangesOptions, maxStorageBytes?: number): Promise<CommitResult>;
42
42
 
43
43
  export { CommitChangesOptions, CommitResult, commitChanges };
@@ -1,6 +1,6 @@
1
- import "../../chunk-IZ2YBCUP.js";
1
+ import "../../../chunk-IZ2YBCUP.js";
2
2
  import { createId } from "crypto-id";
3
- import { filterSoftWritesAgainstState } from "../../json-patch/utils/softWrites.js";
3
+ import { filterSoftWritesAgainstState } from "../../../json-patch/utils/softWrites.js";
4
4
  import { applyChanges } from "../shared/applyChanges.js";
5
5
  import { createVersion } from "./createVersion.js";
6
6
  import { getSnapshotAtRevision } from "./getSnapshotAtRevision.js";
@@ -1,7 +1,7 @@
1
- import { PatchesStoreBackend } from '../../server/types.js';
2
- import { Change, EditableVersionMetadata, VersionMetadata } from '../../types.js';
3
- import '../../json-patch/types.js';
4
- import '../../json-patch/JSONPatch.js';
1
+ import { OTStoreBackend } from '../../../server/types.js';
2
+ import { Change, EditableVersionMetadata, VersionMetadata } from '../../../types.js';
3
+ import '../../../json-patch/types.js';
4
+ import '../../../json-patch/JSONPatch.js';
5
5
  import '@dabble/delta';
6
6
 
7
7
  /**
@@ -13,6 +13,6 @@ import '@dabble/delta';
13
13
  * @param metadata Optional additional metadata for the version.
14
14
  * @returns The created version metadata, or undefined if no changes provided.
15
15
  */
16
- declare function createVersion(store: PatchesStoreBackend, docId: string, state: any, changes: Change[], metadata?: EditableVersionMetadata): Promise<VersionMetadata | undefined>;
16
+ declare function createVersion(store: OTStoreBackend, docId: string, state: any, changes: Change[], metadata?: EditableVersionMetadata): Promise<VersionMetadata | undefined>;
17
17
 
18
18
  export { createVersion };
@@ -1,5 +1,5 @@
1
- import "../../chunk-IZ2YBCUP.js";
2
- import { createVersionMetadata } from "../../data/version.js";
1
+ import "../../../chunk-IZ2YBCUP.js";
2
+ import { createVersionMetadata } from "../../../data/version.js";
3
3
  async function createVersion(store, docId, state, changes, metadata) {
4
4
  if (changes.length === 0) return;
5
5
  const startRev = changes[0].rev;
@@ -1,7 +1,7 @@
1
- import { PatchesStoreBackend } from '../../server/types.js';
2
- import { PatchesSnapshot } from '../../types.js';
3
- import '../../json-patch/types.js';
4
- import '../../json-patch/JSONPatch.js';
1
+ import { OTStoreBackend } from '../../../server/types.js';
2
+ import { PatchesSnapshot } from '../../../types.js';
3
+ import '../../../json-patch/types.js';
4
+ import '../../../json-patch/JSONPatch.js';
5
5
  import '@dabble/delta';
6
6
 
7
7
  /**
@@ -11,6 +11,6 @@ import '@dabble/delta';
11
11
  * @param rev The revision number. If not provided, the latest state, its revision, and all changes since are returned.
12
12
  * @returns The document state at the last version before the revision, its revision number, and all changes up to the specified revision (or all changes if no revision is provided).
13
13
  */
14
- declare function getSnapshotAtRevision(store: PatchesStoreBackend, docId: string, rev?: number): Promise<PatchesSnapshot>;
14
+ declare function getSnapshotAtRevision(store: OTStoreBackend, docId: string, rev?: number): Promise<PatchesSnapshot>;
15
15
 
16
16
  export { getSnapshotAtRevision };
@@ -1,4 +1,4 @@
1
- import "../../chunk-IZ2YBCUP.js";
1
+ import "../../../chunk-IZ2YBCUP.js";
2
2
  async function getSnapshotAtRevision(store, docId, rev) {
3
3
  const versions = await store.listVersions(docId, {
4
4
  limit: 1,
@@ -1,7 +1,7 @@
1
- import { PatchesStoreBackend } from '../../server/types.js';
2
- import { PatchesState } from '../../types.js';
3
- import '../../json-patch/types.js';
4
- import '../../json-patch/JSONPatch.js';
1
+ import { OTStoreBackend } from '../../../server/types.js';
2
+ import { PatchesState } from '../../../types.js';
3
+ import '../../../json-patch/types.js';
4
+ import '../../../json-patch/JSONPatch.js';
5
5
  import '@dabble/delta';
6
6
 
7
7
  /**
@@ -10,6 +10,6 @@ import '@dabble/delta';
10
10
  * @param rev The revision number. If not provided, the latest state and its revision is returned.
11
11
  * @returns The state at the specified revision *and* its revision number.
12
12
  */
13
- declare function getStateAtRevision(store: PatchesStoreBackend, docId: string, rev?: number): Promise<PatchesState>;
13
+ declare function getStateAtRevision(store: OTStoreBackend, docId: string, rev?: number): Promise<PatchesState>;
14
14
 
15
15
  export { getStateAtRevision };
@@ -1,4 +1,4 @@
1
- import "../../chunk-IZ2YBCUP.js";
1
+ import "../../../chunk-IZ2YBCUP.js";
2
2
  import { applyChanges } from "../shared/applyChanges.js";
3
3
  import { getSnapshotAtRevision } from "./getSnapshotAtRevision.js";
4
4
  async function getStateAtRevision(store, docId, rev) {
@@ -1,7 +1,7 @@
1
- import { PatchesStoreBackend } from '../../server/types.js';
2
- import { Change } from '../../types.js';
3
- import '../../json-patch/types.js';
4
- import '../../json-patch/JSONPatch.js';
1
+ import { OTStoreBackend } from '../../../server/types.js';
2
+ import { Change } from '../../../types.js';
3
+ import '../../../json-patch/types.js';
4
+ import '../../../json-patch/JSONPatch.js';
5
5
  import '@dabble/delta';
6
6
 
7
7
  /**
@@ -16,6 +16,6 @@ import '@dabble/delta';
16
16
  * @param maxStorageBytes If set, break collapsed changes that exceed this size
17
17
  * @returns The changes (collapsed into one if divergent, unchanged if fast-forward)
18
18
  */
19
- declare function handleOfflineSessionsAndBatches(store: PatchesStoreBackend, sessionTimeoutMillis: number, docId: string, changes: Change[], baseRev: number, batchId?: string, origin?: 'main' | 'offline-branch', isOffline?: boolean, maxStorageBytes?: number): Promise<Change[]>;
19
+ declare function handleOfflineSessionsAndBatches(store: OTStoreBackend, sessionTimeoutMillis: number, docId: string, changes: Change[], baseRev: number, batchId?: string, origin?: 'main' | 'offline-branch', isOffline?: boolean, maxStorageBytes?: number): Promise<Change[]>;
20
20
 
21
21
  export { handleOfflineSessionsAndBatches };
@@ -1,5 +1,5 @@
1
- import "../../chunk-IZ2YBCUP.js";
2
- import { createVersionMetadata } from "../../data/version.js";
1
+ import "../../../chunk-IZ2YBCUP.js";
2
+ import { createVersionMetadata } from "../../../data/version.js";
3
3
  import { applyChanges } from "../shared/applyChanges.js";
4
4
  import { breakChanges } from "../shared/changeBatching.js";
5
5
  import { getStateAtRevision } from "./getStateAtRevision.js";
@@ -26,7 +26,7 @@ async function handleOfflineSessionsAndBatches(store, sessionTimeoutMillis, docI
26
26
  const sessionChanges = changes.slice(sessionStartIndex, i);
27
27
  if (sessionChanges.length > 0) {
28
28
  const isContinuation = !!lastVersion && sessionChanges[0].createdAt - lastVersion.endedAt <= sessionTimeoutMillis;
29
- if (isContinuation) {
29
+ if (isContinuation && store.appendVersionChanges) {
30
30
  const mergedState = applyChanges(offlineBaseState, sessionChanges);
31
31
  const newEndedAt = sessionChanges[sessionChanges.length - 1].createdAt;
32
32
  const newRev = sessionChanges[sessionChanges.length - 1].rev;
@@ -1,7 +1,7 @@
1
- import { Change } from '../../types.js';
2
- import '../../json-patch/JSONPatch.js';
1
+ import { Change } from '../../../types.js';
2
+ import '../../../json-patch/JSONPatch.js';
3
3
  import '@dabble/delta';
4
- import '../../json-patch/types.js';
4
+ import '../../../json-patch/types.js';
5
5
 
6
6
  /**
7
7
  * Transforms incoming changes against committed changes that happened *after* the client's baseRev.
@@ -1,6 +1,6 @@
1
- import "../../chunk-IZ2YBCUP.js";
2
- import { applyPatch } from "../../json-patch/applyPatch.js";
3
- import { transformPatch } from "../../json-patch/transformPatch.js";
1
+ import "../../../chunk-IZ2YBCUP.js";
2
+ import { applyPatch } from "../../../json-patch/applyPatch.js";
3
+ import { transformPatch } from "../../../json-patch/transformPatch.js";
4
4
  function transformIncomingChanges(changes, stateAtBaseRev, committedChanges, currentRev, forceCommit = false) {
5
5
  const committedOps = committedChanges.flatMap((c) => c.ops);
6
6
  let state = stateAtBaseRev;
@@ -1,7 +1,7 @@
1
- import { Change } from '../../types.js';
2
- import '../../json-patch/JSONPatch.js';
1
+ import { Change } from '../../../types.js';
2
+ import '../../../json-patch/JSONPatch.js';
3
3
  import '@dabble/delta';
4
- import '../../json-patch/types.js';
4
+ import '../../../json-patch/types.js';
5
5
 
6
6
  /**
7
7
  * Applies a sequence of changes to a state object.
@@ -1,5 +1,5 @@
1
- import "../../chunk-IZ2YBCUP.js";
2
- import { applyPatch } from "../../json-patch/applyPatch.js";
1
+ import "../../../chunk-IZ2YBCUP.js";
2
+ import { applyPatch } from "../../../json-patch/applyPatch.js";
3
3
  function applyChanges(state, changes) {
4
4
  if (!changes.length) return state;
5
5
  for (const change of changes) {
@@ -1,7 +1,7 @@
1
- import { Change } from '../../types.js';
2
- import '../../json-patch/JSONPatch.js';
1
+ import { Change } from '../../../types.js';
2
+ import '../../../json-patch/JSONPatch.js';
3
3
  import '@dabble/delta';
4
- import '../../json-patch/types.js';
4
+ import '../../../json-patch/types.js';
5
5
 
6
6
  /**
7
7
  * Function that calculates the storage size of data.
@@ -1,6 +1,6 @@
1
- import "../../chunk-IZ2YBCUP.js";
1
+ import "../../../chunk-IZ2YBCUP.js";
2
2
  import { createId } from "crypto-id";
3
- import { createChange } from "../../data/change.js";
3
+ import { createChange } from "../../../data/change.js";
4
4
  function getJSONByteSize(data) {
5
5
  try {
6
6
  const stringified = JSON.stringify(data);
@@ -1,7 +1,7 @@
1
- import { Change } from '../../types.js';
2
- import '../../json-patch/JSONPatch.js';
1
+ import { Change } from '../../../types.js';
2
+ import '../../../json-patch/JSONPatch.js';
3
3
  import '@dabble/delta';
4
- import '../../json-patch/types.js';
4
+ import '../../../json-patch/types.js';
5
5
 
6
6
  /**
7
7
  * Rebases local changes against server changes using operational transformation.
@@ -1,5 +1,5 @@
1
- import "../../chunk-IZ2YBCUP.js";
2
- import { JSONPatch } from "../../json-patch/JSONPatch.js";
1
+ import "../../../chunk-IZ2YBCUP.js";
2
+ import { JSONPatch } from "../../../json-patch/JSONPatch.js";
3
3
  function rebaseChanges(serverChanges, localChanges) {
4
4
  if (!serverChanges.length || !localChanges.length) {
5
5
  return localChanges;
@@ -1,5 +1,5 @@
1
1
  import "../chunk-IZ2YBCUP.js";
2
- import { applyChanges } from "../algorithms/shared/applyChanges.js";
2
+ import { applyChanges } from "../algorithms/ot/shared/applyChanges.js";
3
3
  class InMemoryStore {
4
4
  docs = /* @__PURE__ */ new Map();
5
5
  // ─── Reconstruction ────────────────────────────────────────────────────
@@ -58,7 +58,7 @@ class IndexedDBStore {
58
58
  this.db.close();
59
59
  this.db = null;
60
60
  this.dbPromise = deferred();
61
- this.dbPromise.resolve(null);
61
+ this.dbPromise.reject(new Error("Store has been closed"));
62
62
  }
63
63
  }
64
64
  async deleteDB() {
@@ -26,7 +26,7 @@ class LWWAlgorithm {
26
26
  const committedRev = doc?.committedRev ?? await this.store.getCommittedRev(docId);
27
27
  const changes = [createChange(committedRev, committedRev + 1, timedOps, metadata)];
28
28
  if (doc) {
29
- doc.applyChanges(changes);
29
+ doc.applyChanges(changes, true);
30
30
  }
31
31
  return changes;
32
32
  }
@@ -52,7 +52,8 @@ class LWWAlgorithm {
52
52
  const localOps = [...sendingChange?.ops ?? [], ...pendingOps];
53
53
  const mergedChanges = mergeServerWithLocal(serverChanges, localOps);
54
54
  if (doc) {
55
- doc.applyChanges(mergedChanges);
55
+ const hasPending = localOps.length > 0;
56
+ doc.applyChanges(mergedChanges, hasPending);
56
57
  }
57
58
  return mergedChanges;
58
59
  }
@@ -49,8 +49,10 @@ declare class LWWDoc<T extends object = object> extends BaseDoc<T> {
49
49
  * - `committedAt === 0`: Pending local change (marks hasPending = true)
50
50
  *
51
51
  * @param changes Array of changes to apply
52
+ * @param hasPending If provided, overrides the inferred pending state.
53
+ * Used by LWWAlgorithm which knows the true pending state from the store.
52
54
  */
53
- applyChanges(changes: Change[]): void;
55
+ applyChanges(changes: Change[], hasPending?: boolean): void;
54
56
  }
55
57
 
56
58
  export { LWWDoc };
@@ -57,8 +57,10 @@ class LWWDoc extends BaseDoc {
57
57
  * - `committedAt === 0`: Pending local change (marks hasPending = true)
58
58
  *
59
59
  * @param changes Array of changes to apply
60
+ * @param hasPending If provided, overrides the inferred pending state.
61
+ * Used by LWWAlgorithm which knows the true pending state from the store.
60
62
  */
61
- applyChanges(changes) {
63
+ applyChanges(changes, hasPending) {
62
64
  if (changes.length === 0) return;
63
65
  for (const change of changes) {
64
66
  for (const op of change.ops) {
@@ -75,7 +77,7 @@ class LWWDoc extends BaseDoc {
75
77
  }
76
78
  }
77
79
  this._committedRev = lastCommittedRev;
78
- this._hasPending = hasPendingChanges;
80
+ this._hasPending = hasPending ?? hasPendingChanges;
79
81
  this.onUpdate.emit(this._state);
80
82
  }
81
83
  }
@@ -1,6 +1,6 @@
1
1
  import "../chunk-IZ2YBCUP.js";
2
- import { applyCommittedChanges } from "../algorithms/client/applyCommittedChanges.js";
3
- import { breakChanges } from "../algorithms/shared/changeBatching.js";
2
+ import { applyCommittedChanges } from "../algorithms/ot/client/applyCommittedChanges.js";
3
+ import { breakChanges } from "../algorithms/ot/shared/changeBatching.js";
4
4
  import { createChange } from "../data/change.js";
5
5
  import { OTDoc } from "./OTDoc.js";
6
6
  class OTAlgorithm {
@@ -1,6 +1,6 @@
1
1
  import "../chunk-IZ2YBCUP.js";
2
- import { createStateFromSnapshot } from "../algorithms/client/createStateFromSnapshot.js";
3
- import { applyChanges as applyChangesToState } from "../algorithms/shared/applyChanges.js";
2
+ import { createStateFromSnapshot } from "../algorithms/ot/client/createStateFromSnapshot.js";
3
+ import { applyChanges as applyChangesToState } from "../algorithms/ot/shared/applyChanges.js";
4
4
  import { BaseDoc } from "./BaseDoc.js";
5
5
  class OTDoc extends BaseDoc {
6
6
  /** Base state from the server at the committed revision. */
@@ -5,7 +5,7 @@ import {
5
5
  __runInitializers
6
6
  } from "../chunk-IZ2YBCUP.js";
7
7
  var _applyServerChanges_dec, _getPendingChanges_dec, _savePendingChanges_dec, _saveDoc_dec, _deleteDoc_dec, _getDoc_dec, _a, _init;
8
- import { applyChanges } from "../algorithms/shared/applyChanges.js";
8
+ import { applyChanges } from "../algorithms/ot/shared/applyChanges.js";
9
9
  import { blockable } from "../utils/concurrency.js";
10
10
  import { IndexedDBStore } from "./IndexedDBStore.js";
11
11
  const DB_VERSION = 1;
@@ -50,6 +50,11 @@ declare class Patches {
50
50
  /** Emitted when a doc has pending changes ready to send */
51
51
  readonly onChange: Signal<(docId: string) => void>;
52
52
  constructor(opts: PatchesOptions);
53
+ /**
54
+ * Loads tracked docs from all registered algorithm stores.
55
+ * Extracted as a protected method so subclasses can override initialization behavior.
56
+ */
57
+ protected init(): void;
53
58
  /**
54
59
  * Gets an algorithm by name, throwing if not found.
55
60
  */
@@ -37,8 +37,22 @@ class Patches {
37
37
  throw new Error(`Default algorithm '${this.defaultAlgorithm}' not found in algorithms map`);
38
38
  }
39
39
  this.docOptions = opts.docOptions ?? {};
40
- this._getAlgorithm(this.defaultAlgorithm).listDocs().then((docs) => {
41
- this.trackDocs(docs.map(({ docId }) => docId));
40
+ this.init();
41
+ }
42
+ /**
43
+ * Loads tracked docs from all registered algorithm stores.
44
+ * Extracted as a protected method so subclasses can override initialization behavior.
45
+ */
46
+ init() {
47
+ const algorithms = Object.values(this.algorithms).filter(Boolean);
48
+ Promise.all(
49
+ algorithms.map(
50
+ (algorithm) => algorithm.listDocs().then((docs) => {
51
+ this.trackDocs(docs.map(({ docId }) => docId));
52
+ })
53
+ )
54
+ ).catch((err) => {
55
+ console.error("Failed to load tracked docs during initialization:", err);
42
56
  });
43
57
  }
44
58
  /**
@@ -1,5 +1,5 @@
1
1
  import "../chunk-IZ2YBCUP.js";
2
- import { applyChanges } from "../algorithms/shared/applyChanges.js";
2
+ import { applyChanges } from "../algorithms/ot/shared/applyChanges.js";
3
3
  import { signal } from "../event-signal.js";
4
4
  class LRUCache {
5
5
  constructor(maxSize) {
@@ -1,4 +1,4 @@
1
- export { compressToBase64, compressToUint8Array, decompressFromBase64, decompressFromUint8Array } from '../algorithms/shared/lz.js';
1
+ export { compressToBase64, compressToUint8Array, decompressFromBase64, decompressFromUint8Array } from './lz.js';
2
2
  import { JSONPatchOp } from '../json-patch/types.js';
3
3
 
4
4
  /**
@@ -1,10 +1,5 @@
1
1
  import "../chunk-IZ2YBCUP.js";
2
- import {
3
- compressToBase64,
4
- compressToUint8Array,
5
- decompressFromBase64,
6
- decompressFromUint8Array
7
- } from "../algorithms/shared/lz.js";
2
+ import { compressToBase64, compressToUint8Array, decompressFromBase64, decompressFromUint8Array } from "./lz.js";
8
3
  const compressedSizeBase64 = (data) => {
9
4
  if (data === void 0) return 0;
10
5
  try {
@@ -1,4 +1,4 @@
1
- import "../../chunk-IZ2YBCUP.js";
1
+ import "../chunk-IZ2YBCUP.js";
2
2
  const f = String.fromCharCode;
3
3
  const keyStrBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
4
4
  const keyStrUriSafe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$";
@@ -1,19 +1,19 @@
1
- import { JSONRPCClient } from './protocol/JSONRPCClient.js';
2
1
  import { Signal } from '../event-signal.js';
3
- import { SizeCalculator } from '../algorithms/shared/changeBatching.js';
4
- import { Patches } from '../client/Patches.js';
5
- import { AlgorithmName, ClientAlgorithm } from '../client/ClientAlgorithm.js';
6
- import { SyncingState, Change } from '../types.js';
7
2
  import { ConnectionState } from './protocol/types.js';
3
+ import { SyncingState, Change } from '../types.js';
4
+ import { JSONRPCClient } from './protocol/JSONRPCClient.js';
8
5
  import { PatchesWebSocket } from './websocket/PatchesWebSocket.js';
9
6
  import { WebSocketOptions } from './websocket/WebSocketTransport.js';
10
- import '../json-patch/types.js';
11
- import '../BaseDoc-DkP3tUhT.js';
7
+ import { SizeCalculator } from '../algorithms/ot/shared/changeBatching.js';
8
+ import { Patches } from '../client/Patches.js';
9
+ import { AlgorithmName, ClientAlgorithm } from '../client/ClientAlgorithm.js';
12
10
  import '../json-patch/JSONPatch.js';
13
11
  import '@dabble/delta';
14
- import '../client/PatchesStore.js';
12
+ import '../json-patch/types.js';
15
13
  import './PatchesClient.js';
16
14
  import '../utils/deferred.js';
15
+ import '../BaseDoc-DkP3tUhT.js';
16
+ import '../client/PatchesStore.js';
17
17
 
18
18
  interface PatchesSyncState {
19
19
  online: boolean;
@@ -7,7 +7,7 @@ import {
7
7
  } from "../chunk-IZ2YBCUP.js";
8
8
  var __receiveCommittedChanges_dec, _syncDoc_dec, _init;
9
9
  import { isEqual } from "@dabble/delta";
10
- import { breakChangesIntoBatches } from "../algorithms/shared/changeBatching.js";
10
+ import { breakChangesIntoBatches } from "../algorithms/ot/shared/changeBatching.js";
11
11
  import { BaseDoc } from "../client/BaseDoc.js";
12
12
  import { Patches } from "../client/Patches.js";
13
13
  import { signal } from "../event-signal.js";
@@ -6,7 +6,6 @@ export { AccessLevel, ApiDefinition, ConnectionSignalSubscriber, JSONRPCServer,
6
6
  export { getAuthContext, getClientId } from './serverContext.js';
7
7
  export { AwarenessUpdateNotificationParams, ClientTransport, ConnectionState, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, ListOptions, Message, PatchesAPI, PatchesNotificationParams, ServerTransport, SignalNotificationParams } from './protocol/types.js';
8
8
  export { rpcError, rpcNotification, rpcResponse } from './protocol/utils.js';
9
- export { PatchesState, SyncingState } from './types.js';
10
9
  export { Access, AuthContext, AuthorizationProvider, allowAll, assertNotDeleted, denyAll } from './websocket/AuthorizationProvider.js';
11
10
  export { onlineState } from './websocket/onlineState.js';
12
11
  export { PatchesWebSocket } from './websocket/PatchesWebSocket.js';
@@ -15,7 +14,7 @@ export { WebSocketServer, WebSocketServerOptions } from './websocket/WebSocketSe
15
14
  export { WebSocketOptions, WebSocketTransport } from './websocket/WebSocketTransport.js';
16
15
  export { CommitChangesOptions } from '../types.js';
17
16
  import '../event-signal.js';
18
- import '../algorithms/shared/changeBatching.js';
17
+ import '../algorithms/ot/shared/changeBatching.js';
19
18
  import '../client/Patches.js';
20
19
  import '../json-patch/types.js';
21
20
  import '../client/ClientAlgorithm.js';
@@ -152,9 +152,11 @@ class JSONRPCServer {
152
152
  }
153
153
  const args = Array.isArray(params) ? params : params === void 0 ? [] : [params];
154
154
  setAuthContext(ctx);
155
- const response = handler(...args);
156
- clearAuthContext();
157
- return response;
155
+ try {
156
+ return await handler(...args);
157
+ } finally {
158
+ clearAuthContext();
159
+ }
158
160
  }
159
161
  }
160
162
  export {
@@ -64,9 +64,8 @@ class WebRTCAwareness {
64
64
  * @param value - The new local awareness state to set and broadcast
65
65
  */
66
66
  set localState(value) {
67
- value.id = this.myId;
68
- this._localState = value;
69
- this.transport.send(JSON.stringify(value));
67
+ this._localState = { ...value, id: this.myId };
68
+ this.transport.send(JSON.stringify(this._localState));
70
69
  }
71
70
  /**
72
71
  * Handles a new peer connection by sending the local state to the new peer.
@@ -1,4 +1,4 @@
1
- import { PatchesStoreBackend, TombstoneStoreBackend } from '../../server/types.js';
1
+ import { ServerStoreBackend, TombstoneStoreBackend } from '../../server/types.js';
2
2
  import '../../json-patch/types.js';
3
3
  import '../../types.js';
4
4
  import '../../json-patch/JSONPatch.js';
@@ -75,6 +75,6 @@ declare const denyAll: AuthorizationProvider;
75
75
  * }
76
76
  * };
77
77
  */
78
- declare function assertNotDeleted(store: PatchesStoreBackend & Partial<TombstoneStoreBackend>, docId: string): Promise<void>;
78
+ declare function assertNotDeleted(store: ServerStoreBackend & Partial<TombstoneStoreBackend>, docId: string): Promise<void>;
79
79
 
80
80
  export { type Access, type AuthContext, type AuthorizationProvider, allowAll, assertNotDeleted, denyAll };
@@ -169,9 +169,12 @@ class WebSocketTransport {
169
169
  if (!this.onlineUnsubscriber) {
170
170
  this.onlineUnsubscriber = onlineState.onOnlineChange((isOnline) => {
171
171
  if (isOnline && this.shouldBeConnected && !this.connecting && this.state !== "connected") {
172
- const { resolve, reject } = this.connectionDeferred;
172
+ const oldDeferred = this.connectionDeferred;
173
173
  this.connectionDeferred = null;
174
- this.connect().then(resolve, reject);
174
+ const connectPromise = this.connect();
175
+ if (oldDeferred) {
176
+ connectPromise.then(oldDeferred.resolve, oldDeferred.reject);
177
+ }
175
178
  } else if (!isOnline && this.ws) {
176
179
  this.ws.close();
177
180
  }
@@ -1,7 +1,7 @@
1
1
  import { OpsCompressor } from '../compression/index.js';
2
2
  import { Change, ListChangesOptions, VersionMetadata, EditableVersionMetadata, ListVersionsOptions, DocumentTombstone } from '../types.js';
3
3
  import { OTStoreBackend, TombstoneStoreBackend } from './types.js';
4
- import '../algorithms/shared/lz.js';
4
+ import '../compression/lz.js';
5
5
  import '../json-patch/types.js';
6
6
  import '../json-patch/JSONPatch.js';
7
7
  import '@dabble/delta';
@@ -11,7 +11,7 @@ import '@dabble/delta';
11
11
  */
12
12
  type CompressibleStore = OTStoreBackend & Partial<TombstoneStoreBackend>;
13
13
  /**
14
- * Wraps a PatchesStoreBackend to transparently compress/decompress the ops field of Changes.
14
+ * Wraps an OTStoreBackend to transparently compress/decompress the ops field of Changes.
15
15
  * Compression happens before save and decompression happens after load.
16
16
  *
17
17
  * This allows backends with row-size limits to store larger changes by compressing the payload.
@@ -34,7 +34,7 @@ declare class CompressedStoreBackend implements OTStoreBackend, Partial<Tombston
34
34
  private decompressChange;
35
35
  saveChanges(docId: string, changes: Change[]): Promise<void>;
36
36
  listChanges(docId: string, options: ListChangesOptions): Promise<Change[]>;
37
- createVersion(docId: string, metadata: VersionMetadata, state: any, changes: Change[]): Promise<void>;
37
+ createVersion(docId: string, metadata: VersionMetadata, state: any, changes?: Change[]): Promise<void>;
38
38
  appendVersionChanges(docId: string, versionId: string, changes: Change[], newEndedAt: number, newRev: number, newState: any): Promise<void>;
39
39
  loadVersionChanges(docId: string, versionId: string): Promise<Change[]>;
40
40
  updateVersion(docId: string, versionId: string, metadata: EditableVersionMetadata): Promise<void>;