@dabble/patches 0.5.22 → 0.7.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.
- package/README.md +221 -208
- package/dist/BaseDoc-DkP3tUhT.d.ts +206 -0
- package/dist/algorithms/client/applyCommittedChanges.d.ts +7 -0
- package/dist/algorithms/client/applyCommittedChanges.js +6 -3
- package/dist/algorithms/lww/consolidateOps.d.ts +40 -0
- package/dist/algorithms/lww/consolidateOps.js +103 -0
- package/dist/algorithms/lww/index.d.ts +2 -0
- package/dist/algorithms/lww/index.js +1 -0
- package/dist/algorithms/lww/mergeServerWithLocal.d.ts +22 -0
- package/dist/algorithms/lww/mergeServerWithLocal.js +32 -0
- package/dist/algorithms/server/commitChanges.d.ts +32 -8
- package/dist/algorithms/server/commitChanges.js +24 -10
- package/dist/algorithms/server/createVersion.d.ts +1 -1
- package/dist/algorithms/server/createVersion.js +2 -4
- package/dist/algorithms/server/getSnapshotAtRevision.d.ts +1 -1
- package/dist/algorithms/server/getStateAtRevision.d.ts +1 -1
- package/dist/algorithms/server/handleOfflineSessionsAndBatches.d.ts +1 -1
- package/dist/algorithms/server/handleOfflineSessionsAndBatches.js +5 -7
- package/dist/client/BaseDoc.d.ts +6 -0
- package/dist/client/BaseDoc.js +70 -0
- package/dist/client/ClientAlgorithm.d.ts +101 -0
- package/dist/client/ClientAlgorithm.js +0 -0
- package/dist/client/InMemoryStore.d.ts +5 -7
- package/dist/client/InMemoryStore.js +6 -35
- package/dist/client/IndexedDBStore.d.ts +39 -73
- package/dist/client/IndexedDBStore.js +17 -220
- package/dist/client/LWWAlgorithm.d.ts +43 -0
- package/dist/client/LWWAlgorithm.js +87 -0
- package/dist/client/LWWClientStore.d.ts +73 -0
- package/dist/client/LWWClientStore.js +0 -0
- package/dist/client/LWWDoc.d.ts +56 -0
- package/dist/client/LWWDoc.js +84 -0
- package/dist/client/LWWInMemoryStore.d.ts +88 -0
- package/dist/client/LWWInMemoryStore.js +208 -0
- package/dist/client/LWWIndexedDBStore.d.ts +91 -0
- package/dist/client/LWWIndexedDBStore.js +275 -0
- package/dist/client/OTAlgorithm.d.ts +42 -0
- package/dist/client/OTAlgorithm.js +113 -0
- package/dist/client/OTClientStore.d.ts +50 -0
- package/dist/client/OTClientStore.js +0 -0
- package/dist/client/OTDoc.d.ts +6 -0
- package/dist/client/OTDoc.js +97 -0
- package/dist/client/OTIndexedDBStore.d.ts +84 -0
- package/dist/client/OTIndexedDBStore.js +163 -0
- package/dist/client/Patches.d.ts +36 -16
- package/dist/client/Patches.js +60 -27
- package/dist/client/PatchesDoc.d.ts +4 -113
- package/dist/client/PatchesDoc.js +3 -153
- package/dist/client/PatchesStore.d.ts +8 -105
- package/dist/client/factories.d.ts +72 -0
- package/dist/client/factories.js +80 -0
- package/dist/client/index.d.ts +14 -5
- package/dist/client/index.js +9 -0
- package/dist/compression/index.d.ts +1 -1
- package/dist/data/change.js +4 -3
- package/dist/fractionalIndex.d.ts +67 -0
- package/dist/fractionalIndex.js +241 -0
- package/dist/index.d.ts +13 -4
- package/dist/index.js +1 -1
- package/dist/json-patch/types.d.ts +2 -0
- package/dist/net/PatchesClient.js +15 -15
- package/dist/net/PatchesSync.d.ts +24 -12
- package/dist/net/PatchesSync.js +56 -64
- package/dist/net/index.d.ts +6 -10
- package/dist/net/index.js +6 -1
- package/dist/net/protocol/JSONRPCClient.d.ts +4 -4
- package/dist/net/protocol/JSONRPCClient.js +6 -4
- package/dist/net/protocol/JSONRPCServer.d.ts +45 -9
- package/dist/net/protocol/JSONRPCServer.js +63 -8
- package/dist/net/serverContext.d.ts +38 -0
- package/dist/net/serverContext.js +20 -0
- package/dist/net/webrtc/WebRTCTransport.js +1 -1
- package/dist/net/websocket/AuthorizationProvider.d.ts +3 -3
- package/dist/net/websocket/WebSocketServer.d.ts +29 -20
- package/dist/net/websocket/WebSocketServer.js +23 -12
- package/dist/server/BranchManager.d.ts +50 -0
- package/dist/server/BranchManager.js +0 -0
- package/dist/server/CompressedStoreBackend.d.ts +8 -6
- package/dist/server/CompressedStoreBackend.js +3 -9
- package/dist/server/LWWBranchManager.d.ts +82 -0
- package/dist/server/LWWBranchManager.js +99 -0
- package/dist/server/LWWMemoryStoreBackend.d.ts +78 -0
- package/dist/server/LWWMemoryStoreBackend.js +191 -0
- package/dist/server/LWWServer.d.ts +130 -0
- package/dist/server/LWWServer.js +207 -0
- package/dist/server/{PatchesBranchManager.d.ts → OTBranchManager.d.ts} +32 -12
- package/dist/server/{PatchesBranchManager.js → OTBranchManager.js} +26 -42
- package/dist/server/OTServer.d.ts +108 -0
- package/dist/server/OTServer.js +141 -0
- package/dist/server/PatchesHistoryManager.d.ts +20 -7
- package/dist/server/PatchesHistoryManager.js +26 -3
- package/dist/server/PatchesServer.d.ts +70 -81
- package/dist/server/PatchesServer.js +0 -176
- package/dist/server/branchUtils.d.ts +82 -0
- package/dist/server/branchUtils.js +66 -0
- package/dist/server/index.d.ts +17 -6
- package/dist/server/index.js +33 -4
- package/dist/server/tombstone.d.ts +29 -0
- package/dist/server/tombstone.js +32 -0
- package/dist/server/types.d.ts +129 -27
- package/dist/server/utils.d.ts +12 -0
- package/dist/server/utils.js +23 -0
- package/dist/solid/context.d.ts +5 -4
- package/dist/solid/doc-manager.d.ts +3 -3
- package/dist/solid/index.d.ts +5 -4
- package/dist/solid/primitives.d.ts +2 -3
- package/dist/types.d.ts +16 -14
- package/dist/vue/composables.d.ts +2 -3
- package/dist/vue/doc-manager.d.ts +3 -3
- package/dist/vue/index.d.ts +5 -4
- package/dist/vue/provider.d.ts +5 -4
- package/package.json +1 -1
- package/dist/algorithms/client/collapsePendingChanges.d.ts +0 -30
- package/dist/algorithms/client/collapsePendingChanges.js +0 -78
- package/dist/net/websocket/RPCServer.d.ts +0 -141
- package/dist/net/websocket/RPCServer.js +0 -204
- package/dist/utils/dates.d.ts +0 -43
- package/dist/utils/dates.js +0 -47
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import "../chunk-IZ2YBCUP.js";
|
|
2
|
+
const nonModifiableVersionFields = /* @__PURE__ */ new Set([
|
|
3
|
+
"id",
|
|
4
|
+
"parentId",
|
|
5
|
+
"groupId",
|
|
6
|
+
"origin",
|
|
7
|
+
"branchName",
|
|
8
|
+
"startedAt",
|
|
9
|
+
"endedAt",
|
|
10
|
+
"rev",
|
|
11
|
+
"baseRev"
|
|
12
|
+
]);
|
|
13
|
+
function assertVersionMetadata(metadata) {
|
|
14
|
+
if (!metadata) return;
|
|
15
|
+
for (const key in metadata) {
|
|
16
|
+
if (nonModifiableVersionFields.has(key)) {
|
|
17
|
+
throw new Error(`Cannot modify version field ${key}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
assertVersionMetadata
|
|
23
|
+
};
|
package/dist/solid/context.d.ts
CHANGED
|
@@ -2,15 +2,16 @@ import { JSX } from 'solid-js';
|
|
|
2
2
|
import { Patches } from '../client/Patches.js';
|
|
3
3
|
import { PatchesSync } from '../net/PatchesSync.js';
|
|
4
4
|
import '../event-signal.js';
|
|
5
|
+
import '../json-patch/types.js';
|
|
5
6
|
import '../types.js';
|
|
6
7
|
import '../json-patch/JSONPatch.js';
|
|
7
8
|
import '@dabble/delta';
|
|
8
|
-
import '../
|
|
9
|
-
import '../
|
|
10
|
-
import '../algorithms/shared/changeBatching.js';
|
|
9
|
+
import '../client/ClientAlgorithm.js';
|
|
10
|
+
import '../BaseDoc-DkP3tUhT.js';
|
|
11
11
|
import '../client/PatchesStore.js';
|
|
12
|
-
import '../net/protocol/types.js';
|
|
13
12
|
import '../net/protocol/JSONRPCClient.js';
|
|
13
|
+
import '../net/protocol/types.js';
|
|
14
|
+
import '../algorithms/shared/changeBatching.js';
|
|
14
15
|
import '../net/websocket/PatchesWebSocket.js';
|
|
15
16
|
import '../net/PatchesClient.js';
|
|
16
17
|
import '../net/websocket/WebSocketTransport.js';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Patches } from '../client/Patches.js';
|
|
2
|
-
import { PatchesDoc } from '../
|
|
2
|
+
import { a as PatchesDoc } from '../BaseDoc-DkP3tUhT.js';
|
|
3
3
|
import '../event-signal.js';
|
|
4
|
+
import '../json-patch/types.js';
|
|
4
5
|
import '../types.js';
|
|
5
6
|
import '../json-patch/JSONPatch.js';
|
|
6
7
|
import '@dabble/delta';
|
|
7
|
-
import '../
|
|
8
|
+
import '../client/ClientAlgorithm.js';
|
|
8
9
|
import '../client/PatchesStore.js';
|
|
9
|
-
import '../algorithms/shared/changeBatching.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Reference counting manager for PatchesDoc instances.
|
package/dist/solid/index.d.ts
CHANGED
|
@@ -4,16 +4,17 @@ export { DocManager, getDocManager } from './doc-manager.js';
|
|
|
4
4
|
import 'solid-js';
|
|
5
5
|
import '../client/Patches.js';
|
|
6
6
|
import '../event-signal.js';
|
|
7
|
+
import '../json-patch/types.js';
|
|
7
8
|
import '../types.js';
|
|
8
9
|
import '../json-patch/JSONPatch.js';
|
|
9
10
|
import '@dabble/delta';
|
|
10
|
-
import '../
|
|
11
|
-
import '../
|
|
12
|
-
import '../algorithms/shared/changeBatching.js';
|
|
11
|
+
import '../client/ClientAlgorithm.js';
|
|
12
|
+
import '../BaseDoc-DkP3tUhT.js';
|
|
13
13
|
import '../client/PatchesStore.js';
|
|
14
14
|
import '../net/PatchesSync.js';
|
|
15
|
-
import '../net/protocol/types.js';
|
|
16
15
|
import '../net/protocol/JSONRPCClient.js';
|
|
16
|
+
import '../net/protocol/types.js';
|
|
17
|
+
import '../algorithms/shared/changeBatching.js';
|
|
17
18
|
import '../net/websocket/PatchesWebSocket.js';
|
|
18
19
|
import '../net/PatchesClient.js';
|
|
19
20
|
import '../net/websocket/WebSocketTransport.js';
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Accessor } from 'solid-js';
|
|
2
|
-
import { PatchesDoc } from '../
|
|
2
|
+
import { a as PatchesDoc } from '../BaseDoc-DkP3tUhT.js';
|
|
3
3
|
import { ChangeMutator } from '../types.js';
|
|
4
4
|
import '../event-signal.js';
|
|
5
|
-
import '../
|
|
5
|
+
import '../json-patch/types.js';
|
|
6
6
|
import '../json-patch/JSONPatch.js';
|
|
7
7
|
import '@dabble/delta';
|
|
8
|
-
import '../json-patch/types.js';
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* Options for usePatchesDoc primitive.
|
package/dist/types.d.ts
CHANGED
|
@@ -17,8 +17,8 @@ interface ChangeInput {
|
|
|
17
17
|
baseRev?: number;
|
|
18
18
|
/** Optional revision number. If omitted, server assigns based on current state. */
|
|
19
19
|
rev?: number;
|
|
20
|
-
/**
|
|
21
|
-
createdAt
|
|
20
|
+
/** Unix timestamp in milliseconds when the change was created. If omitted, server sets to current time. */
|
|
21
|
+
createdAt?: number;
|
|
22
22
|
/** Optional batch identifier for grouping changes that belong to the same client batch (for multi-batch offline/large edits). */
|
|
23
23
|
batchId?: string;
|
|
24
24
|
/** Optional arbitrary metadata associated with the change. */
|
|
@@ -33,8 +33,10 @@ interface Change extends ChangeInput {
|
|
|
33
33
|
baseRev: number;
|
|
34
34
|
/** The revision number assigned by the server after commit. */
|
|
35
35
|
rev: number;
|
|
36
|
-
/**
|
|
37
|
-
|
|
36
|
+
/** Unix timestamp in milliseconds when the change was created (always set by server if omitted from input). */
|
|
37
|
+
createdAt: number;
|
|
38
|
+
/** Unix timestamp in milliseconds when the change was committed. */
|
|
39
|
+
committedAt: number;
|
|
38
40
|
}
|
|
39
41
|
/**
|
|
40
42
|
* Represents the state of a document in the OT protocol.
|
|
@@ -71,8 +73,8 @@ interface Branch {
|
|
|
71
73
|
docId: string;
|
|
72
74
|
/** The revision number on the source document where the branch occurred. */
|
|
73
75
|
branchedAtRev: number;
|
|
74
|
-
/**
|
|
75
|
-
createdAt:
|
|
76
|
+
/** Unix timestamp in milliseconds when the branch was created. */
|
|
77
|
+
createdAt: number;
|
|
76
78
|
/** Optional user-friendly name for the branch. */
|
|
77
79
|
name?: string;
|
|
78
80
|
/** Current status of the branch. */
|
|
@@ -89,14 +91,14 @@ type EditableBranchMetadata = Disallowed<Branch, 'id' | 'docId' | 'branchedAtRev
|
|
|
89
91
|
interface DocumentTombstone {
|
|
90
92
|
/** The ID of the deleted document. */
|
|
91
93
|
docId: string;
|
|
92
|
-
/**
|
|
93
|
-
deletedAt:
|
|
94
|
+
/** Unix timestamp in milliseconds when the document was deleted. */
|
|
95
|
+
deletedAt: number;
|
|
94
96
|
/** The last revision number before deletion. */
|
|
95
97
|
lastRev: number;
|
|
96
98
|
/** Optional client ID that initiated the deletion. */
|
|
97
99
|
deletedByClientId?: string;
|
|
98
|
-
/** Optional
|
|
99
|
-
expiresAt?:
|
|
100
|
+
/** Optional Unix timestamp in milliseconds for automatic tombstone expiration. */
|
|
101
|
+
expiresAt?: number;
|
|
100
102
|
}
|
|
101
103
|
/**
|
|
102
104
|
* Options for deleting a document.
|
|
@@ -122,10 +124,10 @@ interface VersionMetadata {
|
|
|
122
124
|
isOffline?: boolean;
|
|
123
125
|
/** User-defined name if origin is 'branch'. */
|
|
124
126
|
branchName?: string;
|
|
125
|
-
/**
|
|
126
|
-
startedAt:
|
|
127
|
-
/**
|
|
128
|
-
endedAt:
|
|
127
|
+
/** Unix timestamp in milliseconds of version start. */
|
|
128
|
+
startedAt: number;
|
|
129
|
+
/** Unix timestamp in milliseconds of version end. */
|
|
130
|
+
endedAt: number;
|
|
129
131
|
/** The ending revision number of this version (the last change's rev). */
|
|
130
132
|
endRev: number;
|
|
131
133
|
/** The starting revision number of this version (the first change's rev). */
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { ShallowRef, Ref, MaybeRef } from 'vue';
|
|
2
|
-
import { PatchesDoc } from '../
|
|
2
|
+
import { a as PatchesDoc } from '../BaseDoc-DkP3tUhT.js';
|
|
3
3
|
import { ChangeMutator } from '../types.js';
|
|
4
4
|
import '../event-signal.js';
|
|
5
|
-
import '../
|
|
5
|
+
import '../json-patch/types.js';
|
|
6
6
|
import '../json-patch/JSONPatch.js';
|
|
7
7
|
import '@dabble/delta';
|
|
8
|
-
import '../json-patch/types.js';
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* Options for usePatchesDoc composable.
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Patches } from '../client/Patches.js';
|
|
2
|
-
import { PatchesDoc } from '../
|
|
2
|
+
import { a as PatchesDoc } from '../BaseDoc-DkP3tUhT.js';
|
|
3
3
|
import '../event-signal.js';
|
|
4
|
+
import '../json-patch/types.js';
|
|
4
5
|
import '../types.js';
|
|
5
6
|
import '../json-patch/JSONPatch.js';
|
|
6
7
|
import '@dabble/delta';
|
|
7
|
-
import '../
|
|
8
|
+
import '../client/ClientAlgorithm.js';
|
|
8
9
|
import '../client/PatchesStore.js';
|
|
9
|
-
import '../algorithms/shared/changeBatching.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Reference counting manager for PatchesDoc instances.
|
package/dist/vue/index.d.ts
CHANGED
|
@@ -4,16 +4,17 @@ export { DocManager, getDocManager } from './doc-manager.js';
|
|
|
4
4
|
import 'vue';
|
|
5
5
|
import '../client/Patches.js';
|
|
6
6
|
import '../event-signal.js';
|
|
7
|
+
import '../json-patch/types.js';
|
|
7
8
|
import '../types.js';
|
|
8
9
|
import '../json-patch/JSONPatch.js';
|
|
9
10
|
import '@dabble/delta';
|
|
10
|
-
import '../
|
|
11
|
-
import '../
|
|
12
|
-
import '../algorithms/shared/changeBatching.js';
|
|
11
|
+
import '../client/ClientAlgorithm.js';
|
|
12
|
+
import '../BaseDoc-DkP3tUhT.js';
|
|
13
13
|
import '../client/PatchesStore.js';
|
|
14
14
|
import '../net/PatchesSync.js';
|
|
15
|
-
import '../net/protocol/types.js';
|
|
16
15
|
import '../net/protocol/JSONRPCClient.js';
|
|
16
|
+
import '../net/protocol/types.js';
|
|
17
|
+
import '../algorithms/shared/changeBatching.js';
|
|
17
18
|
import '../net/websocket/PatchesWebSocket.js';
|
|
18
19
|
import '../net/PatchesClient.js';
|
|
19
20
|
import '../net/websocket/WebSocketTransport.js';
|
package/dist/vue/provider.d.ts
CHANGED
|
@@ -2,15 +2,16 @@ import { InjectionKey, App } from 'vue';
|
|
|
2
2
|
import { Patches } from '../client/Patches.js';
|
|
3
3
|
import { PatchesSync } from '../net/PatchesSync.js';
|
|
4
4
|
import '../event-signal.js';
|
|
5
|
+
import '../json-patch/types.js';
|
|
5
6
|
import '../types.js';
|
|
6
7
|
import '../json-patch/JSONPatch.js';
|
|
7
8
|
import '@dabble/delta';
|
|
8
|
-
import '../
|
|
9
|
-
import '../
|
|
10
|
-
import '../algorithms/shared/changeBatching.js';
|
|
9
|
+
import '../client/ClientAlgorithm.js';
|
|
10
|
+
import '../BaseDoc-DkP3tUhT.js';
|
|
11
11
|
import '../client/PatchesStore.js';
|
|
12
|
-
import '../net/protocol/types.js';
|
|
13
12
|
import '../net/protocol/JSONRPCClient.js';
|
|
13
|
+
import '../net/protocol/types.js';
|
|
14
|
+
import '../algorithms/shared/changeBatching.js';
|
|
14
15
|
import '../net/websocket/PatchesWebSocket.js';
|
|
15
16
|
import '../net/PatchesClient.js';
|
|
16
17
|
import '../net/websocket/WebSocketTransport.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dabble/patches",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Immutable JSON Patch implementation based on RFC 6902 supporting operational transformation and last-writer-wins",
|
|
5
5
|
"author": "Jacob Wright <jacwright@gmail.com>",
|
|
6
6
|
"bugs": {
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Change } from '../../types.js';
|
|
2
|
-
import '../../json-patch/JSONPatch.js';
|
|
3
|
-
import '@dabble/delta';
|
|
4
|
-
import '../../json-patch/types.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Collapses redundant pending changes before sync to reduce network traffic.
|
|
8
|
-
*
|
|
9
|
-
* This optimization automatically detects and collapses multiple "replace" operations
|
|
10
|
-
* on the same JSON path with primitive values (boolean, number, string, null) into
|
|
11
|
-
* a single change containing only the final value.
|
|
12
|
-
*
|
|
13
|
-
* Example: If a user toggles a folder's open state 100 times while offline,
|
|
14
|
-
* this collapses those 100 changes into just 1 change with the final state.
|
|
15
|
-
*
|
|
16
|
-
* Safety guarantees:
|
|
17
|
-
* - Only collapses single-op changes (multi-op changes are atomic, preserve intent)
|
|
18
|
-
* - Only collapses "replace" operations (not add, remove, move)
|
|
19
|
-
* - Only collapses primitive values (not objects/arrays)
|
|
20
|
-
* - Detects path invalidation from structural changes (remove, array shifts, move)
|
|
21
|
-
* - Respects the submission bookmark to never collapse already-submitted changes
|
|
22
|
-
*
|
|
23
|
-
* @param changes Array of pending changes to potentially collapse
|
|
24
|
-
* @param afterRev Optional revision bookmark - changes at or before this rev are not collapsed
|
|
25
|
-
* (they may have been partially submitted to the server)
|
|
26
|
-
* @returns Collapsed array of changes, maintaining correct ordering
|
|
27
|
-
*/
|
|
28
|
-
declare function collapsePendingChanges(changes: Change[], afterRev?: number): Change[];
|
|
29
|
-
|
|
30
|
-
export { collapsePendingChanges };
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import "../../chunk-IZ2YBCUP.js";
|
|
2
|
-
function collapsePendingChanges(changes, afterRev) {
|
|
3
|
-
if (changes.length <= 1) {
|
|
4
|
-
return changes;
|
|
5
|
-
}
|
|
6
|
-
const pathState = /* @__PURE__ */ new Map();
|
|
7
|
-
const outputSlots = new Array(changes.length).fill(null);
|
|
8
|
-
for (let i = 0; i < changes.length; i++) {
|
|
9
|
-
const change = changes[i];
|
|
10
|
-
if (afterRev !== void 0 && change.rev !== void 0 && change.rev <= afterRev) {
|
|
11
|
-
outputSlots[i] = change;
|
|
12
|
-
continue;
|
|
13
|
-
}
|
|
14
|
-
updatePathInvalidations(change, pathState);
|
|
15
|
-
if (!isCollapsibleChange(change)) {
|
|
16
|
-
outputSlots[i] = change;
|
|
17
|
-
continue;
|
|
18
|
-
}
|
|
19
|
-
const path = change.ops[0].path;
|
|
20
|
-
const existing = pathState.get(path);
|
|
21
|
-
if (existing) {
|
|
22
|
-
outputSlots[existing.lastIndex] = null;
|
|
23
|
-
}
|
|
24
|
-
pathState.set(path, { lastChange: change, lastIndex: i });
|
|
25
|
-
outputSlots[i] = change;
|
|
26
|
-
}
|
|
27
|
-
return outputSlots.filter((c) => c !== null);
|
|
28
|
-
}
|
|
29
|
-
function isCollapsibleChange(change) {
|
|
30
|
-
if (change.ops.length !== 1) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
const op = change.ops[0];
|
|
34
|
-
if (op.op !== "replace") {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
return isPrimitiveValue(op.value);
|
|
38
|
-
}
|
|
39
|
-
function isPrimitiveValue(value) {
|
|
40
|
-
if (value === null) return true;
|
|
41
|
-
const type = typeof value;
|
|
42
|
-
return type === "boolean" || type === "number" || type === "string";
|
|
43
|
-
}
|
|
44
|
-
function updatePathInvalidations(change, pathState) {
|
|
45
|
-
for (const op of change.ops) {
|
|
46
|
-
if (op.op === "remove" || op.op === "move") {
|
|
47
|
-
invalidatePathAndChildren(op.path, pathState);
|
|
48
|
-
if (op.op === "move" && "from" in op) {
|
|
49
|
-
invalidatePathAndChildren(op.from, pathState);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (op.op === "add" || op.op === "remove") {
|
|
53
|
-
invalidateShiftedArrayPaths(op.path, pathState);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
function invalidatePathAndChildren(opPath, pathState) {
|
|
58
|
-
for (const trackedPath of pathState.keys()) {
|
|
59
|
-
if (trackedPath === opPath || trackedPath.startsWith(opPath + "/")) {
|
|
60
|
-
pathState.delete(trackedPath);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
function invalidateShiftedArrayPaths(opPath, pathState) {
|
|
65
|
-
const segments = opPath.split("/");
|
|
66
|
-
const lastSegment = segments[segments.length - 1];
|
|
67
|
-
if (/^\d+$/.test(lastSegment)) {
|
|
68
|
-
const arrayPath = segments.slice(0, -1).join("/");
|
|
69
|
-
for (const trackedPath of pathState.keys()) {
|
|
70
|
-
if (trackedPath.startsWith(arrayPath + "/")) {
|
|
71
|
-
pathState.delete(trackedPath);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
export {
|
|
77
|
-
collapsePendingChanges
|
|
78
|
-
};
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { PatchesState, Change, CommitChangesOptions, DeleteDocOptions, ListVersionsOptions, VersionMetadata, EditableVersionMetadata, ListChangesOptions, Branch } from '../../types.js';
|
|
2
|
-
import { PatchesBranchManager } from '../../server/PatchesBranchManager.js';
|
|
3
|
-
import { PatchesHistoryManager } from '../../server/PatchesHistoryManager.js';
|
|
4
|
-
import { PatchesServer } from '../../server/PatchesServer.js';
|
|
5
|
-
import { JSONRPCServer } from '../protocol/JSONRPCServer.js';
|
|
6
|
-
import { AuthorizationProvider, AuthContext } from './AuthorizationProvider.js';
|
|
7
|
-
import '../../json-patch/JSONPatch.js';
|
|
8
|
-
import '@dabble/delta';
|
|
9
|
-
import '../../json-patch/types.js';
|
|
10
|
-
import '../../server/types.js';
|
|
11
|
-
import '../../event-signal.js';
|
|
12
|
-
import '../../compression/index.js';
|
|
13
|
-
import '../../algorithms/shared/lz.js';
|
|
14
|
-
import '../protocol/types.js';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* High-level client for the Patches real-time collaboration service.
|
|
18
|
-
* This class provides document subscription, patch notification handling,
|
|
19
|
-
* versioning, and other OT-specific functionality over a JSON RPC interface.
|
|
20
|
-
*/
|
|
21
|
-
interface RPCServerOptions {
|
|
22
|
-
patches: PatchesServer;
|
|
23
|
-
history?: PatchesHistoryManager;
|
|
24
|
-
branches?: PatchesBranchManager;
|
|
25
|
-
auth?: AuthorizationProvider;
|
|
26
|
-
}
|
|
27
|
-
declare class RPCServer {
|
|
28
|
-
rpc: JSONRPCServer;
|
|
29
|
-
auth: AuthorizationProvider;
|
|
30
|
-
protected patches: PatchesServer;
|
|
31
|
-
protected history?: PatchesHistoryManager;
|
|
32
|
-
protected branches?: PatchesBranchManager;
|
|
33
|
-
/**
|
|
34
|
-
* Creates a new Patches WebSocket client instance.
|
|
35
|
-
* @param patches - The patches server instance to handle document operations
|
|
36
|
-
* @param history - (Optional) History manager instance to handle versioning operations
|
|
37
|
-
* @param branches - (Optional) Branch manager instance to handle branching operations
|
|
38
|
-
* @param auth - (Optional) Authorization provider implementation. Defaults to deny-all for security.
|
|
39
|
-
*/
|
|
40
|
-
constructor({ patches, history, branches, auth }: RPCServerOptions);
|
|
41
|
-
/**
|
|
42
|
-
* Gets the latest state (content and revision) of a document.
|
|
43
|
-
* @param connectionId - The ID of the connection making the request
|
|
44
|
-
* @param params - The document parameters
|
|
45
|
-
* @param params.docId - The ID of the document
|
|
46
|
-
* @param params.atRev - Optional revision number to get document state at
|
|
47
|
-
*/
|
|
48
|
-
getDoc(params: {
|
|
49
|
-
docId: string;
|
|
50
|
-
atRev?: number;
|
|
51
|
-
}, ctx?: AuthContext): Promise<PatchesState<any>>;
|
|
52
|
-
/**
|
|
53
|
-
* Gets changes that occurred for a document after a specific revision number.
|
|
54
|
-
* @param connectionId - The ID of the connection making the request
|
|
55
|
-
* @param params - The change request parameters
|
|
56
|
-
* @param params.docId - The ID of the document
|
|
57
|
-
* @param params.rev - The revision number after which to fetch changes
|
|
58
|
-
*/
|
|
59
|
-
getChangesSince(params: {
|
|
60
|
-
docId: string;
|
|
61
|
-
rev: number;
|
|
62
|
-
}, ctx?: AuthContext): Promise<Change[]>;
|
|
63
|
-
/**
|
|
64
|
-
* Applies a set of client-generated changes to a document on the server.
|
|
65
|
-
* @param connectionId - The ID of the connection making the request
|
|
66
|
-
* @param params - The change parameters
|
|
67
|
-
* @param params.docId - The ID of the document
|
|
68
|
-
* @param params.changes - An array of changes to apply
|
|
69
|
-
* @param params.options - Optional commit settings (e.g., forceCommit for migrations)
|
|
70
|
-
*/
|
|
71
|
-
commitChanges(params: {
|
|
72
|
-
docId: string;
|
|
73
|
-
changes: Change[];
|
|
74
|
-
options?: CommitChangesOptions;
|
|
75
|
-
}, ctx?: AuthContext): Promise<Change[]>;
|
|
76
|
-
/**
|
|
77
|
-
* Deletes a document on the server.
|
|
78
|
-
* @param connectionId - The ID of the connection making the request
|
|
79
|
-
* @param params - The deletion parameters
|
|
80
|
-
* @param params.docId - The ID of the document to delete
|
|
81
|
-
* @param params.options - Optional deletion settings (e.g., skipTombstone)
|
|
82
|
-
*/
|
|
83
|
-
deleteDoc(params: {
|
|
84
|
-
docId: string;
|
|
85
|
-
options?: DeleteDocOptions;
|
|
86
|
-
}, ctx?: AuthContext): Promise<void>;
|
|
87
|
-
/**
|
|
88
|
-
* Removes the tombstone for a deleted document, allowing it to be recreated.
|
|
89
|
-
* @param params - The undelete parameters
|
|
90
|
-
* @param params.docId - The ID of the document to undelete
|
|
91
|
-
*/
|
|
92
|
-
undeleteDoc(params: {
|
|
93
|
-
docId: string;
|
|
94
|
-
}, ctx?: AuthContext): Promise<boolean>;
|
|
95
|
-
listVersions(params: {
|
|
96
|
-
docId: string;
|
|
97
|
-
options?: ListVersionsOptions;
|
|
98
|
-
}, ctx?: AuthContext): Promise<VersionMetadata[]>;
|
|
99
|
-
createVersion(params: {
|
|
100
|
-
docId: string;
|
|
101
|
-
metadata: EditableVersionMetadata;
|
|
102
|
-
}, ctx?: AuthContext): Promise<string | null>;
|
|
103
|
-
updateVersion(params: {
|
|
104
|
-
docId: string;
|
|
105
|
-
versionId: string;
|
|
106
|
-
metadata: EditableVersionMetadata;
|
|
107
|
-
}, ctx?: AuthContext): Promise<void>;
|
|
108
|
-
getVersionState(params: {
|
|
109
|
-
docId: string;
|
|
110
|
-
versionId: string;
|
|
111
|
-
}, ctx?: AuthContext): Promise<any>;
|
|
112
|
-
getVersionChanges(params: {
|
|
113
|
-
docId: string;
|
|
114
|
-
versionId: string;
|
|
115
|
-
}, ctx?: AuthContext): Promise<Change[]>;
|
|
116
|
-
listServerChanges(params: {
|
|
117
|
-
docId: string;
|
|
118
|
-
options?: ListChangesOptions;
|
|
119
|
-
}, ctx?: AuthContext): Promise<Change[]>;
|
|
120
|
-
listBranches(params: {
|
|
121
|
-
docId: string;
|
|
122
|
-
}, ctx?: AuthContext): Promise<Branch[]>;
|
|
123
|
-
createBranch(params: {
|
|
124
|
-
docId: string;
|
|
125
|
-
rev: number;
|
|
126
|
-
metadata?: EditableVersionMetadata;
|
|
127
|
-
}, ctx?: AuthContext): Promise<string>;
|
|
128
|
-
closeBranch(params: {
|
|
129
|
-
branchId: string;
|
|
130
|
-
}, ctx?: AuthContext): Promise<void>;
|
|
131
|
-
mergeBranch(params: {
|
|
132
|
-
branchId: string;
|
|
133
|
-
}, ctx?: AuthContext): Promise<Change[]>;
|
|
134
|
-
protected assertAccess(ctx: AuthContext | undefined, docId: string, kind: 'read' | 'write', method: string, params?: Record<string, any>): Promise<void>;
|
|
135
|
-
assertRead(ctx: AuthContext | undefined, docId: string, method: string, params?: Record<string, any>): Promise<void>;
|
|
136
|
-
assertWrite(ctx: AuthContext | undefined, docId: string, method: string, params?: Record<string, any>): Promise<void>;
|
|
137
|
-
protected assertHistoryEnabled(): void;
|
|
138
|
-
protected assertBranchingEnabled(): void;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export { RPCServer, type RPCServerOptions };
|