@dabble/patches 0.4.4 → 0.4.6
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.
- package/dist/algorithms/client/applyCommittedChanges.d.ts +8 -2
- package/dist/algorithms/client/applyCommittedChanges.js +30 -38
- package/dist/algorithms/client/batching.d.ts +8 -2
- package/dist/algorithms/client/batching.js +38 -37
- package/dist/algorithms/client/breakChange.d.ts +8 -2
- package/dist/algorithms/client/breakChange.js +191 -240
- package/dist/algorithms/client/createStateFromSnapshot.d.ts +8 -2
- package/dist/algorithms/client/createStateFromSnapshot.js +7 -8
- package/dist/algorithms/client/getJSONByteSize.d.ts +3 -1
- package/dist/algorithms/client/getJSONByteSize.js +12 -11
- package/dist/algorithms/client/makeChange.d.ts +8 -2
- package/dist/algorithms/client/makeChange.js +28 -36
- package/dist/algorithms/server/commitChanges.d.ts +9 -3
- package/dist/algorithms/server/commitChanges.js +69 -78
- package/dist/algorithms/server/createVersion.d.ts +9 -3
- package/dist/algorithms/server/createVersion.js +21 -27
- package/dist/algorithms/server/getSnapshotAtRevision.d.ts +9 -3
- package/dist/algorithms/server/getSnapshotAtRevision.js +27 -28
- package/dist/algorithms/server/getStateAtRevision.d.ts +9 -3
- package/dist/algorithms/server/getStateAtRevision.js +13 -17
- package/dist/algorithms/server/handleOfflineSessionsAndBatches.d.ts +9 -3
- package/dist/algorithms/server/handleOfflineSessionsAndBatches.js +60 -77
- package/dist/algorithms/server/transformIncomingChanges.d.ts +8 -2
- package/dist/algorithms/server/transformIncomingChanges.js +27 -39
- package/dist/algorithms/shared/applyChanges.d.ts +8 -2
- package/dist/algorithms/shared/applyChanges.js +11 -16
- package/dist/algorithms/shared/rebaseChanges.d.ts +8 -2
- package/dist/algorithms/shared/rebaseChanges.js +30 -49
- package/dist/chunk-IZ2YBCUP.js +56 -0
- package/dist/client/InMemoryStore.d.ts +9 -3
- package/dist/client/InMemoryStore.js +92 -101
- package/dist/client/IndexedDBStore.d.ts +9 -3
- package/dist/client/IndexedDBStore.js +378 -491
- package/dist/client/Patches.d.ts +18 -13
- package/dist/client/Patches.js +152 -207
- package/dist/client/PatchesDoc.d.ts +14 -8
- package/dist/client/PatchesDoc.js +147 -154
- package/dist/client/PatchesHistoryClient.d.ts +12 -5
- package/dist/client/PatchesHistoryClient.js +110 -117
- package/dist/client/PatchesStore.d.ts +9 -3
- package/dist/client/PatchesStore.js +0 -1
- package/dist/client/index.d.ts +12 -6
- package/dist/client/index.js +5 -5
- package/dist/data/change.d.ts +9 -3
- package/dist/data/change.js +23 -15
- package/dist/data/version.d.ts +9 -3
- package/dist/data/version.js +11 -15
- package/dist/event-signal.d.ts +7 -6
- package/dist/event-signal.js +24 -39
- package/dist/index-CvQws3AB.d.ts +36 -0
- package/dist/index.d.ts +27 -5
- package/dist/index.js +10 -4
- package/dist/json-patch/JSONPatch.d.ts +9 -5
- package/dist/json-patch/JSONPatch.js +175 -183
- package/dist/json-patch/applyPatch.d.ts +5 -2
- package/dist/json-patch/applyPatch.js +27 -35
- package/dist/json-patch/composePatch.d.ts +5 -2
- package/dist/json-patch/composePatch.js +34 -34
- package/dist/json-patch/createJSONPatch.d.ts +7 -2
- package/dist/json-patch/createJSONPatch.js +11 -38
- package/dist/json-patch/index.d.ts +14 -6
- package/dist/json-patch/index.js +20 -9
- package/dist/json-patch/invertPatch.d.ts +5 -2
- package/dist/json-patch/invertPatch.js +31 -30
- package/dist/json-patch/ops/add.d.ts +5 -2
- package/dist/json-patch/ops/add.js +53 -51
- package/dist/json-patch/ops/bitmask.d.ts +8 -5
- package/dist/json-patch/ops/bitmask.js +41 -44
- package/dist/json-patch/ops/copy.d.ts +5 -2
- package/dist/json-patch/ops/copy.js +32 -33
- package/dist/json-patch/ops/increment.d.ts +5 -2
- package/dist/json-patch/ops/increment.js +21 -20
- package/dist/json-patch/ops/index.d.ts +10 -21
- package/dist/json-patch/ops/index.js +34 -24
- package/dist/json-patch/ops/move.d.ts +5 -2
- package/dist/json-patch/ops/move.js +132 -198
- package/dist/json-patch/ops/remove.d.ts +5 -2
- package/dist/json-patch/ops/remove.js +33 -30
- package/dist/json-patch/ops/replace.d.ts +5 -2
- package/dist/json-patch/ops/replace.js +45 -43
- package/dist/json-patch/ops/test.d.ts +5 -2
- package/dist/json-patch/ops/test.js +25 -21
- package/dist/json-patch/ops/text.d.ts +5 -2
- package/dist/json-patch/ops/text.js +54 -54
- package/dist/json-patch/pathProxy.d.ts +9 -3
- package/dist/json-patch/pathProxy.js +27 -48
- package/dist/json-patch/state.d.ts +5 -2
- package/dist/json-patch/state.js +11 -7
- package/dist/json-patch/transformPatch.d.ts +6 -2
- package/dist/json-patch/transformPatch.js +21 -24
- package/dist/json-patch/types.d.ts +9 -7
- package/dist/json-patch/types.js +0 -1
- package/dist/json-patch/utils/deepEqual.d.ts +3 -1
- package/dist/json-patch/utils/deepEqual.js +32 -28
- package/dist/json-patch/utils/exit.d.ts +5 -2
- package/dist/json-patch/utils/exit.js +7 -3
- package/dist/json-patch/utils/get.d.ts +5 -2
- package/dist/json-patch/utils/get.js +8 -4
- package/dist/json-patch/utils/getOpData.d.ts +5 -2
- package/dist/json-patch/utils/getOpData.js +12 -9
- package/dist/json-patch/utils/getType.d.ts +6 -3
- package/dist/json-patch/utils/getType.js +9 -4
- package/dist/json-patch/utils/index.d.ts +15 -14
- package/dist/json-patch/utils/index.js +14 -14
- package/dist/json-patch/utils/log.d.ts +4 -2
- package/dist/json-patch/utils/log.js +8 -3
- package/dist/json-patch/utils/ops.d.ts +8 -5
- package/dist/json-patch/utils/ops.js +83 -100
- package/dist/json-patch/utils/paths.d.ts +12 -9
- package/dist/json-patch/utils/paths.js +54 -51
- package/dist/json-patch/utils/pluck.d.ts +8 -5
- package/dist/json-patch/utils/pluck.js +32 -26
- package/dist/json-patch/utils/shallowCopy.d.ts +3 -1
- package/dist/json-patch/utils/shallowCopy.js +22 -18
- package/dist/json-patch/utils/softWrites.d.ts +6 -3
- package/dist/json-patch/utils/softWrites.js +17 -16
- package/dist/json-patch/utils/toArrayIndex.d.ts +3 -1
- package/dist/json-patch/utils/toArrayIndex.js +14 -10
- package/dist/json-patch/utils/toKeys.d.ts +3 -1
- package/dist/json-patch/utils/toKeys.js +15 -11
- package/dist/json-patch/utils/updateArrayIndexes.d.ts +5 -2
- package/dist/json-patch/utils/updateArrayIndexes.js +33 -37
- package/dist/json-patch/utils/updateArrayPath.d.ts +5 -2
- package/dist/json-patch/utils/updateArrayPath.js +29 -42
- package/dist/net/PatchesClient.d.ts +128 -0
- package/dist/net/PatchesClient.js +161 -0
- package/dist/net/PatchesSync.d.ts +19 -9
- package/dist/net/PatchesSync.js +291 -386
- package/dist/net/error.d.ts +3 -1
- package/dist/net/error.js +9 -6
- package/dist/net/http/FetchTransport.d.ts +21 -0
- package/dist/net/http/FetchTransport.js +34 -0
- package/dist/net/index.d.ts +26 -12
- package/dist/net/index.js +12 -10
- package/dist/net/protocol/JSONRPCClient.d.ts +11 -4
- package/dist/net/protocol/JSONRPCClient.js +95 -103
- package/dist/net/protocol/JSONRPCServer.d.ts +15 -8
- package/dist/net/protocol/JSONRPCServer.js +101 -123
- package/dist/net/protocol/types.d.ts +21 -15
- package/dist/net/protocol/types.js +0 -1
- package/dist/net/protocol/utils.d.ts +12 -0
- package/dist/net/protocol/utils.js +15 -0
- package/dist/net/types.d.ts +4 -2
- package/dist/net/types.js +0 -1
- package/dist/net/webrtc/WebRTCAwareness.d.ts +14 -4
- package/dist/net/webrtc/WebRTCAwareness.js +111 -120
- package/dist/net/webrtc/WebRTCTransport.d.ts +16 -8
- package/dist/net/webrtc/WebRTCTransport.js +149 -157
- package/dist/net/webrtc/index.d.ts +10 -2
- package/dist/net/webrtc/index.js +2 -2
- package/dist/net/websocket/AuthorizationProvider.d.ts +7 -5
- package/dist/net/websocket/AuthorizationProvider.js +12 -17
- package/dist/net/websocket/PatchesWebSocket.d.ts +14 -109
- package/dist/net/websocket/PatchesWebSocket.js +37 -184
- package/dist/net/websocket/RPCServer.d.ts +19 -10
- package/dist/net/websocket/RPCServer.js +190 -192
- package/dist/net/websocket/SignalingService.d.ts +12 -32
- package/dist/net/websocket/SignalingService.js +126 -133
- package/dist/net/websocket/WebSocketServer.d.ts +17 -4
- package/dist/net/websocket/WebSocketServer.js +64 -72
- package/dist/net/websocket/WebSocketTransport.d.ts +13 -5
- package/dist/net/websocket/WebSocketTransport.js +178 -207
- package/dist/net/websocket/onlineState.d.ts +6 -3
- package/dist/net/websocket/onlineState.js +25 -21
- package/dist/server/PatchesBranchManager.d.ts +12 -5
- package/dist/server/PatchesBranchManager.js +132 -142
- package/dist/server/PatchesHistoryManager.d.ts +11 -3
- package/dist/server/PatchesHistoryManager.js +81 -84
- package/dist/server/PatchesServer.d.ts +16 -10
- package/dist/server/PatchesServer.js +131 -137
- package/dist/server/index.d.ts +7 -2
- package/dist/server/index.js +9 -3
- package/dist/server/types.d.ts +9 -3
- package/dist/server/types.js +0 -1
- package/dist/types.d.ts +49 -19
- package/dist/types.js +1 -1
- package/dist/utils/concurrency.d.ts +7 -5
- package/dist/utils/concurrency.js +43 -53
- package/dist/utils/deferred.d.ts +4 -2
- package/dist/utils/deferred.js +25 -21
- package/package.json +5 -7
|
@@ -1,106 +1,97 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const patch = buf.committed.filter(c => c.rev > buf.pending[0].baseRev).flatMap(c => c.ops);
|
|
20
|
-
const offset = committedRev - buf.pending[0].baseRev;
|
|
21
|
-
buf.pending.forEach(ch => {
|
|
22
|
-
ch.rev += offset;
|
|
23
|
-
ch.ops = transformPatch(state, patch, ch.ops);
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
return {
|
|
27
|
-
state,
|
|
28
|
-
rev: committedRev,
|
|
29
|
-
changes: [...buf.pending],
|
|
30
|
-
};
|
|
1
|
+
import "../chunk-IZ2YBCUP.js";
|
|
2
|
+
import { applyChanges } from "../algorithms/shared/applyChanges.js";
|
|
3
|
+
import { transformPatch } from "../json-patch/transformPatch.js";
|
|
4
|
+
class InMemoryStore {
|
|
5
|
+
docs = /* @__PURE__ */ new Map();
|
|
6
|
+
// ─── Reconstruction ────────────────────────────────────────────────────
|
|
7
|
+
async getDoc(docId) {
|
|
8
|
+
const buf = this.docs.get(docId);
|
|
9
|
+
if (!buf || buf.deleted) return void 0;
|
|
10
|
+
const state = applyChanges(buf.snapshot?.state ?? null, buf.committed);
|
|
11
|
+
const committedRev = buf.committed.at(-1)?.rev ?? buf.snapshot?.rev ?? 0;
|
|
12
|
+
if (buf.pending.length && buf.pending[0].baseRev < committedRev) {
|
|
13
|
+
const patch = buf.committed.filter((c) => c.rev > buf.pending[0].baseRev).flatMap((c) => c.ops);
|
|
14
|
+
const offset = committedRev - buf.pending[0].baseRev;
|
|
15
|
+
buf.pending.forEach((ch) => {
|
|
16
|
+
ch.rev += offset;
|
|
17
|
+
ch.ops = transformPatch(state, patch, ch.ops);
|
|
18
|
+
});
|
|
31
19
|
}
|
|
32
|
-
|
|
33
|
-
|
|
20
|
+
return {
|
|
21
|
+
state,
|
|
22
|
+
rev: committedRev,
|
|
23
|
+
changes: [...buf.pending]
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
async getPendingChanges(docId) {
|
|
27
|
+
return this.docs.get(docId)?.pending.slice() ?? [];
|
|
28
|
+
}
|
|
29
|
+
async getLastRevs(docId) {
|
|
30
|
+
const buf = this.docs.get(docId);
|
|
31
|
+
if (!buf) return [0, 0];
|
|
32
|
+
const committedRev = buf.committed.at(-1)?.rev ?? buf.snapshot?.rev ?? 0;
|
|
33
|
+
const pendingRev = buf.pending.at(-1)?.rev ?? committedRev;
|
|
34
|
+
return [committedRev, pendingRev];
|
|
35
|
+
}
|
|
36
|
+
async listDocs(includeDeleted = false) {
|
|
37
|
+
return Array.from(this.docs.entries()).filter(([, b]) => includeDeleted || !b.deleted).map(([docId, buf]) => ({
|
|
38
|
+
docId,
|
|
39
|
+
committedRev: buf.snapshot?.rev ?? buf.committed.at(-1)?.rev ?? 0,
|
|
40
|
+
deleted: buf.deleted
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
// ─── Writes ────────────────────────────────────────────────────────────
|
|
44
|
+
async saveDoc(docId, snapshot) {
|
|
45
|
+
this.docs.set(docId, { snapshot, committed: [], pending: [] });
|
|
46
|
+
}
|
|
47
|
+
async savePendingChanges(docId, changes) {
|
|
48
|
+
const buf = this.docs.get(docId) ?? { committed: [], pending: [] };
|
|
49
|
+
if (!this.docs.has(docId)) this.docs.set(docId, buf);
|
|
50
|
+
buf.pending.push(...changes);
|
|
51
|
+
}
|
|
52
|
+
async saveCommittedChanges(docId, changes, sentPendingRange) {
|
|
53
|
+
const buf = this.docs.get(docId) ?? { committed: [], pending: [] };
|
|
54
|
+
if (!this.docs.has(docId)) this.docs.set(docId, buf);
|
|
55
|
+
buf.committed.push(...changes);
|
|
56
|
+
if (sentPendingRange) {
|
|
57
|
+
const [min, max] = sentPendingRange;
|
|
58
|
+
buf.pending = buf.pending.filter((p) => p.rev < min || p.rev > max);
|
|
34
59
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
docId,
|
|
48
|
-
committedRev: buf.snapshot?.rev ?? buf.committed.at(-1)?.rev ?? 0,
|
|
49
|
-
deleted: buf.deleted,
|
|
50
|
-
}));
|
|
51
|
-
}
|
|
52
|
-
// ─── Writes ────────────────────────────────────────────────────────────
|
|
53
|
-
async saveDoc(docId, snapshot) {
|
|
54
|
-
this.docs.set(docId, { snapshot, committed: [], pending: [] });
|
|
55
|
-
}
|
|
56
|
-
async savePendingChanges(docId, changes) {
|
|
57
|
-
const buf = this.docs.get(docId) ?? { committed: [], pending: [] };
|
|
58
|
-
if (!this.docs.has(docId))
|
|
59
|
-
this.docs.set(docId, buf);
|
|
60
|
-
buf.pending.push(...changes);
|
|
61
|
-
}
|
|
62
|
-
async saveCommittedChanges(docId, changes, sentPendingRange) {
|
|
63
|
-
const buf = this.docs.get(docId) ?? { committed: [], pending: [] };
|
|
64
|
-
if (!this.docs.has(docId))
|
|
65
|
-
this.docs.set(docId, buf);
|
|
66
|
-
buf.committed.push(...changes);
|
|
67
|
-
if (sentPendingRange) {
|
|
68
|
-
const [min, max] = sentPendingRange;
|
|
69
|
-
buf.pending = buf.pending.filter(p => p.rev < min || p.rev > max);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
async replacePendingChanges(docId, changes) {
|
|
73
|
-
const buf = this.docs.get(docId) ?? { committed: [], pending: [] };
|
|
74
|
-
if (!this.docs.has(docId))
|
|
75
|
-
this.docs.set(docId, buf);
|
|
76
|
-
buf.pending = [...changes];
|
|
77
|
-
}
|
|
78
|
-
// ─── Metadata / Tracking ───────────────────────────────────────────
|
|
79
|
-
async trackDocs(docIds) {
|
|
80
|
-
for (const docId of docIds) {
|
|
81
|
-
const buf = this.docs.get(docId) ?? { committed: [], pending: [] };
|
|
82
|
-
buf.deleted = undefined; // Ensure not marked as deleted
|
|
83
|
-
if (!this.docs.has(docId)) {
|
|
84
|
-
this.docs.set(docId, buf);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
async untrackDocs(docIds) {
|
|
89
|
-
docIds.forEach(this.docs.delete, this.docs);
|
|
90
|
-
}
|
|
91
|
-
// ─── Misc / Lifecycle ────────────────────────────────────────────────
|
|
92
|
-
async deleteDoc(docId) {
|
|
93
|
-
const buf = this.docs.get(docId) ?? { committed: [], pending: [] };
|
|
94
|
-
buf.deleted = true;
|
|
95
|
-
buf.committed = [];
|
|
96
|
-
buf.pending = [];
|
|
97
|
-
buf.snapshot = undefined;
|
|
60
|
+
}
|
|
61
|
+
async replacePendingChanges(docId, changes) {
|
|
62
|
+
const buf = this.docs.get(docId) ?? { committed: [], pending: [] };
|
|
63
|
+
if (!this.docs.has(docId)) this.docs.set(docId, buf);
|
|
64
|
+
buf.pending = [...changes];
|
|
65
|
+
}
|
|
66
|
+
// ─── Metadata / Tracking ───────────────────────────────────────────
|
|
67
|
+
async trackDocs(docIds) {
|
|
68
|
+
for (const docId of docIds) {
|
|
69
|
+
const buf = this.docs.get(docId) ?? { committed: [], pending: [] };
|
|
70
|
+
buf.deleted = void 0;
|
|
71
|
+
if (!this.docs.has(docId)) {
|
|
98
72
|
this.docs.set(docId, buf);
|
|
73
|
+
}
|
|
99
74
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
75
|
+
}
|
|
76
|
+
async untrackDocs(docIds) {
|
|
77
|
+
docIds.forEach(this.docs.delete, this.docs);
|
|
78
|
+
}
|
|
79
|
+
// ─── Misc / Lifecycle ────────────────────────────────────────────────
|
|
80
|
+
async deleteDoc(docId) {
|
|
81
|
+
const buf = this.docs.get(docId) ?? { committed: [], pending: [] };
|
|
82
|
+
buf.deleted = true;
|
|
83
|
+
buf.committed = [];
|
|
84
|
+
buf.pending = [];
|
|
85
|
+
buf.snapshot = void 0;
|
|
86
|
+
this.docs.set(docId, buf);
|
|
87
|
+
}
|
|
88
|
+
async confirmDeleteDoc(docId) {
|
|
89
|
+
this.docs.delete(docId);
|
|
90
|
+
}
|
|
91
|
+
async close() {
|
|
92
|
+
this.docs.clear();
|
|
93
|
+
}
|
|
106
94
|
}
|
|
95
|
+
export {
|
|
96
|
+
InMemoryStore
|
|
97
|
+
};
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { PatchesSnapshot, PatchesState, Change } from '../types.js';
|
|
2
|
+
import { PatchesStore, TrackedDoc } from './PatchesStore.js';
|
|
3
|
+
import '../json-patch/JSONPatch.js';
|
|
4
|
+
import '@dabble/delta';
|
|
5
|
+
import '../json-patch/types.js';
|
|
6
|
+
|
|
3
7
|
/**
|
|
4
8
|
* Creates a new IndexedDB database with stores:
|
|
5
9
|
* - snapshots<{ docId: string; rev: number; state: any }> (primary key: docId)
|
|
@@ -12,7 +16,7 @@ import type { PatchesStore, TrackedDoc } from './PatchesStore.js';
|
|
|
12
16
|
* After every 200 committed changes, the class will save the current state to the snapshot store and delete the committed changes that went into it.
|
|
13
17
|
* A snapshot will not be created if there are pending changes based on revisions older than the 200th committed change until those pending changes are committed.
|
|
14
18
|
*/
|
|
15
|
-
|
|
19
|
+
declare class IndexedDBStore implements PatchesStore {
|
|
16
20
|
private db;
|
|
17
21
|
private dbName?;
|
|
18
22
|
private dbPromise;
|
|
@@ -110,3 +114,5 @@ export declare class IndexedDBStore implements PatchesStore {
|
|
|
110
114
|
*/
|
|
111
115
|
getLastRevs(docId: string): Promise<[number, number]>;
|
|
112
116
|
}
|
|
117
|
+
|
|
118
|
+
export { IndexedDBStore };
|