@dabble/patches 0.3.1 → 0.4.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 (37) hide show
  1. package/dist/algorithms/client/makeChange.d.ts +2 -3
  2. package/dist/algorithms/client/makeChange.js +1 -1
  3. package/dist/algorithms/server/getSnapshotAtRevision.d.ts +1 -1
  4. package/dist/algorithms/server/getStateAtRevision.d.ts +1 -1
  5. package/dist/algorithms/server/handleOfflineSessionsAndBatches.d.ts +1 -1
  6. package/dist/client/InMemoryStore.js +1 -3
  7. package/dist/client/IndexedDBStore.js +345 -342
  8. package/dist/client/Patches.js +156 -156
  9. package/dist/client/PatchesDoc.d.ts +4 -5
  10. package/dist/client/PatchesDoc.js +16 -13
  11. package/dist/client/PatchesHistoryClient.js +12 -8
  12. package/dist/json-patch/JSONPatch.js +2 -0
  13. package/dist/json-patch/createJSONPatch.d.ts +15 -17
  14. package/dist/json-patch/createJSONPatch.js +18 -20
  15. package/dist/json-patch/patchProxy.d.ts +16 -35
  16. package/dist/json-patch/patchProxy.js +30 -106
  17. package/dist/json-patch/utils/getType.d.ts +1 -1
  18. package/dist/net/PatchesSync.d.ts +14 -7
  19. package/dist/net/PatchesSync.js +307 -292
  20. package/dist/net/error.js +1 -0
  21. package/dist/net/protocol/JSONRPCClient.js +4 -3
  22. package/dist/net/protocol/JSONRPCServer.js +6 -8
  23. package/dist/net/webrtc/WebRTCAwareness.js +12 -7
  24. package/dist/net/webrtc/WebRTCTransport.d.ts +1 -1
  25. package/dist/net/webrtc/WebRTCTransport.js +27 -21
  26. package/dist/net/websocket/PatchesWebSocket.js +7 -2
  27. package/dist/net/websocket/RPCServer.js +5 -0
  28. package/dist/net/websocket/SignalingService.js +1 -3
  29. package/dist/net/websocket/WebSocketServer.js +2 -0
  30. package/dist/net/websocket/WebSocketTransport.js +21 -19
  31. package/dist/net/websocket/onlineState.js +2 -2
  32. package/dist/server/PatchesBranchManager.js +2 -0
  33. package/dist/server/PatchesHistoryManager.js +2 -0
  34. package/dist/server/PatchesServer.d.ts +2 -2
  35. package/dist/server/PatchesServer.js +7 -5
  36. package/dist/types.d.ts +15 -0
  37. package/package.json +15 -12
@@ -1,3 +1,2 @@
1
- import type { JSONPatch } from '../..';
2
- import type { Change, PatchesSnapshot } from '../../types.js';
3
- export declare function makeChange<T = any>(snapshot: PatchesSnapshot<T>, mutator: (draft: T, patch: JSONPatch) => void, changeMetadata?: Record<string, any>, maxPayloadBytes?: number): Change[];
1
+ import type { Change, ChangeMutator, PatchesSnapshot } from '../../types.js';
2
+ export declare function makeChange<T = any>(snapshot: PatchesSnapshot<T>, mutator: ChangeMutator<T>, changeMetadata?: Record<string, any>, maxPayloadBytes?: number): Change[];
@@ -6,7 +6,7 @@ export function makeChange(snapshot, mutator, changeMetadata, maxPayloadBytes) {
6
6
  const pendingChanges = snapshot.changes;
7
7
  const pendingRev = pendingChanges[pendingChanges.length - 1]?.rev ?? snapshot.rev;
8
8
  const state = createStateFromSnapshot(snapshot); // Current state including pending
9
- const patch = createJSONPatch(state, mutator);
9
+ const patch = createJSONPatch(mutator);
10
10
  if (patch.ops.length === 0) {
11
11
  return [];
12
12
  }
@@ -1,4 +1,4 @@
1
- import type { PatchesStoreBackend } from '../../server.js';
1
+ import type { PatchesStoreBackend } from '../../server/types.js';
2
2
  import type { PatchesSnapshot } from '../../types.js';
3
3
  /**
4
4
  * Retrieves the document state of the version before the given revision and changes after up to that revision or all
@@ -1,4 +1,4 @@
1
- import type { PatchesStoreBackend } from '../../server.js';
1
+ import type { PatchesStoreBackend } from '../../server/types.js';
2
2
  import type { PatchesState } from '../../types.js';
3
3
  /**
4
4
  * Gets the state at a specific revision.
@@ -1,4 +1,4 @@
1
- import type { PatchesStoreBackend } from '../../server.js';
1
+ import type { PatchesStoreBackend } from '../../server/types.js';
2
2
  import type { Change } from '../../types.js';
3
3
  /**
4
4
  * Handles offline/large batch versioning logic for multi-batch uploads.
@@ -6,9 +6,7 @@ import { transformPatch } from '../json-patch/transformPatch.js';
6
6
  * Useful for unit tests or when you want the old 'stateless realtime' behaviour.
7
7
  */
8
8
  export class InMemoryStore {
9
- constructor() {
10
- this.docs = new Map();
11
- }
9
+ docs = new Map();
12
10
  // ─── Reconstruction ────────────────────────────────────────────────────
13
11
  async getDoc(docId) {
14
12
  const buf = this.docs.get(docId);