@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,19 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Never use this in production as it allows unrestricted access.
|
|
5
|
-
*/
|
|
6
|
-
export const allowAll = {
|
|
7
|
-
canAccess: () => true,
|
|
1
|
+
import "../../chunk-IZ2YBCUP.js";
|
|
2
|
+
const allowAll = {
|
|
3
|
+
canAccess: () => true
|
|
8
4
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
},
|
|
5
|
+
const denyAll = {
|
|
6
|
+
canAccess: () => {
|
|
7
|
+
console.warn("Authorization check failed: No authorization provider configured. Access denied.");
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
allowAll,
|
|
13
|
+
denyAll
|
|
19
14
|
};
|
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
1
|
+
import { Signal } from '../../event-signal.js';
|
|
2
|
+
import { PatchesClient } from '../PatchesClient.js';
|
|
3
|
+
import { ConnectionState } from '../protocol/types.js';
|
|
4
|
+
import { WebSocketTransport, WebSocketOptions } from './WebSocketTransport.js';
|
|
5
|
+
import '../../types.js';
|
|
6
|
+
import '../../json-patch/JSONPatch.js';
|
|
7
|
+
import '@dabble/delta';
|
|
8
|
+
import '../../json-patch/types.js';
|
|
9
|
+
import '../protocol/JSONRPCClient.js';
|
|
10
|
+
|
|
5
11
|
/**
|
|
6
12
|
* High-level client for the Patches real-time collaboration service.
|
|
7
13
|
* This class provides document subscription, patch notification handling,
|
|
8
14
|
* versioning, and other OT-specific functionality
|
|
9
15
|
* over a WebSocket connection.
|
|
10
16
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
private transport;
|
|
17
|
+
declare class PatchesWebSocket extends PatchesClient {
|
|
18
|
+
transport: WebSocketTransport;
|
|
14
19
|
/** Signal emitted when the underlying WebSocket connection state changes. */
|
|
15
20
|
readonly onStateChange: Signal<(state: ConnectionState) => void>;
|
|
16
|
-
/** Signal emitted when the server pushes document changes. */
|
|
17
|
-
readonly onChangesCommitted: Signal<(docId: string, changes: Change[]) => void>;
|
|
18
21
|
/**
|
|
19
22
|
* Creates a new Patches WebSocket client instance.
|
|
20
23
|
* @param url - The WebSocket server URL to connect to
|
|
@@ -30,104 +33,6 @@ export declare class PatchesWebSocket implements PatchesAPI {
|
|
|
30
33
|
* Terminates the connection to the Patches server.
|
|
31
34
|
*/
|
|
32
35
|
disconnect(): void;
|
|
33
|
-
/**
|
|
34
|
-
* Subscribes the client to one or more documents to receive real-time updates.
|
|
35
|
-
* @param ids - Document ID or IDs to subscribe to.
|
|
36
|
-
* @returns A promise resolving with the list of successfully subscribed document IDs.
|
|
37
|
-
*/
|
|
38
|
-
subscribe(ids: string | string[]): Promise<string[]>;
|
|
39
|
-
/**
|
|
40
|
-
* Unsubscribes the client from one or more documents.
|
|
41
|
-
* @param ids - Document ID or IDs to unsubscribe from.
|
|
42
|
-
* @returns A promise resolving when the unsubscription is confirmed.
|
|
43
|
-
*/
|
|
44
|
-
unsubscribe(ids: string | string[]): Promise<void>;
|
|
45
|
-
/**
|
|
46
|
-
* Gets the latest state (content and revision) of a document.
|
|
47
|
-
* @param docId - The ID of the document.
|
|
48
|
-
* @returns A promise resolving with the document snapshot.
|
|
49
|
-
*/
|
|
50
|
-
getDoc(docId: string, atRev?: number): Promise<PatchesState>;
|
|
51
|
-
/**
|
|
52
|
-
* Gets changes that occurred for a document after a specific revision number.
|
|
53
|
-
* @param docId - The ID of the document.
|
|
54
|
-
* @param rev - The revision number after which to fetch changes.
|
|
55
|
-
* @returns A promise resolving with an array of changes.
|
|
56
|
-
*/
|
|
57
|
-
getChangesSince(docId: string, rev: number): Promise<Change[]>;
|
|
58
|
-
/**
|
|
59
|
-
* Applies a set of client-generated changes to a document on the server.
|
|
60
|
-
* @param docId - The ID of the document.
|
|
61
|
-
* @param changes - An array of changes to apply.
|
|
62
|
-
* @returns A promise resolving with the changes as committed by the server (potentially transformed).
|
|
63
|
-
*/
|
|
64
|
-
commitChanges(docId: string, changes: Change[]): Promise<Change[]>;
|
|
65
|
-
/**
|
|
66
|
-
* Deletes a document on the server.
|
|
67
|
-
* @param docId - The ID of the document to delete.
|
|
68
|
-
* @returns A promise resolving when the deletion is confirmed.
|
|
69
|
-
*/
|
|
70
|
-
deleteDoc(docId: string): Promise<void>;
|
|
71
|
-
/**
|
|
72
|
-
* Creates a named version snapshot of a document's current state on the server.
|
|
73
|
-
* @param docId - The ID of the document.
|
|
74
|
-
* @param name - A descriptive name for the version.
|
|
75
|
-
* @returns A promise resolving with the unique ID of the newly created version.
|
|
76
|
-
*/
|
|
77
|
-
createVersion(docId: string, metadata: EditableVersionMetadata): Promise<string>;
|
|
78
|
-
/**
|
|
79
|
-
* Lists metadata for saved versions of a document.
|
|
80
|
-
* @param docId - The ID of the document.
|
|
81
|
-
* @param options - Options for filtering or pagination (e.g., limit, offset).
|
|
82
|
-
* @returns A promise resolving with an array of version metadata objects.
|
|
83
|
-
*/
|
|
84
|
-
listVersions(docId: string, options?: ListVersionsOptions): Promise<VersionMetadata[]>;
|
|
85
|
-
/**
|
|
86
|
-
* Gets the document state snapshot corresponding to a specific version ID.
|
|
87
|
-
* @param docId - The ID of the document.
|
|
88
|
-
* @param versionId - The ID of the version to retrieve.
|
|
89
|
-
* @returns A promise resolving with the document snapshot for that version.
|
|
90
|
-
*/
|
|
91
|
-
getVersionState(docId: string, versionId: string): Promise<PatchesSnapshot>;
|
|
92
|
-
/**
|
|
93
|
-
* Gets the original changes associated with a specific version ID.
|
|
94
|
-
* @param docId - The ID of the document.
|
|
95
|
-
* @param versionId - The ID of the version.
|
|
96
|
-
* @returns A promise resolving with an array of changes that constitute that version.
|
|
97
|
-
*/
|
|
98
|
-
getVersionChanges(docId: string, versionId: string): Promise<Change[]>;
|
|
99
|
-
/**
|
|
100
|
-
* Updates the name of a specific version.
|
|
101
|
-
* @param docId - The ID of the document.
|
|
102
|
-
* @param versionId - The ID of the version to update.
|
|
103
|
-
* @param name - The new name for the version.
|
|
104
|
-
* @returns A promise resolving when the update is confirmed.
|
|
105
|
-
*/
|
|
106
|
-
updateVersion(docId: string, versionId: string, metadata: EditableVersionMetadata): Promise<void>;
|
|
107
|
-
/**
|
|
108
|
-
* Lists all branches for a document.
|
|
109
|
-
* @param docId - The ID of the document.
|
|
110
|
-
* @returns A promise resolving with an array of branch metadata objects.
|
|
111
|
-
*/
|
|
112
|
-
listBranches(docId: string): Promise<VersionMetadata[]>;
|
|
113
|
-
/**
|
|
114
|
-
* Creates a new branch for a document.
|
|
115
|
-
* @param docId - The ID of the document.
|
|
116
|
-
* @param rev - The revision number to base the new branch on.
|
|
117
|
-
* @param metadata - Optional metadata for the new branch.
|
|
118
|
-
* @returns A promise resolving with the unique ID of the newly created branch.
|
|
119
|
-
*/
|
|
120
|
-
createBranch(docId: string, rev: number, metadata?: EditableVersionMetadata): Promise<string>;
|
|
121
|
-
/**
|
|
122
|
-
* Closes a branch on the server.
|
|
123
|
-
* @param branchId - The ID of the branch to close.
|
|
124
|
-
* @returns A promise resolving when the branch is closed.
|
|
125
|
-
*/
|
|
126
|
-
closeBranch(branchId: string): Promise<void>;
|
|
127
|
-
/**
|
|
128
|
-
* Merges a branch on the server.
|
|
129
|
-
* @param branchId - The ID of the branch to merge.
|
|
130
|
-
* @returns A promise resolving when the merge is confirmed.
|
|
131
|
-
*/
|
|
132
|
-
mergeBranch(branchId: string): Promise<void>;
|
|
133
36
|
}
|
|
37
|
+
|
|
38
|
+
export { PatchesWebSocket };
|
|
@@ -1,185 +1,38 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Establishes a connection to the Patches server.
|
|
37
|
-
* @returns A promise that resolves when the connection is established
|
|
38
|
-
*/
|
|
39
|
-
async connect() {
|
|
40
|
-
await this.transport.connect();
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Terminates the connection to the Patches server.
|
|
44
|
-
*/
|
|
45
|
-
disconnect() {
|
|
46
|
-
// Unsubscribe rpc listeners? JSONRPCClient should handle this if transport disconnects.
|
|
47
|
-
this.transport.disconnect();
|
|
48
|
-
// Consider clearing signal listeners here if needed, though they are instance-based.
|
|
49
|
-
}
|
|
50
|
-
// --- Patches API Methods ---
|
|
51
|
-
// === Subscription Operations ===
|
|
52
|
-
/**
|
|
53
|
-
* Subscribes the client to one or more documents to receive real-time updates.
|
|
54
|
-
* @param ids - Document ID or IDs to subscribe to.
|
|
55
|
-
* @returns A promise resolving with the list of successfully subscribed document IDs.
|
|
56
|
-
*/
|
|
57
|
-
async subscribe(ids) {
|
|
58
|
-
return this.rpc.request('subscribe', { ids });
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Unsubscribes the client from one or more documents.
|
|
62
|
-
* @param ids - Document ID or IDs to unsubscribe from.
|
|
63
|
-
* @returns A promise resolving when the unsubscription is confirmed.
|
|
64
|
-
*/
|
|
65
|
-
async unsubscribe(ids) {
|
|
66
|
-
return this.rpc.request('unsubscribe', { ids });
|
|
67
|
-
}
|
|
68
|
-
// === Document Operations ===
|
|
69
|
-
/**
|
|
70
|
-
* Gets the latest state (content and revision) of a document.
|
|
71
|
-
* @param docId - The ID of the document.
|
|
72
|
-
* @returns A promise resolving with the document snapshot.
|
|
73
|
-
*/
|
|
74
|
-
async getDoc(docId, atRev) {
|
|
75
|
-
return this.rpc.request('getDoc', { docId, atRev });
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Gets changes that occurred for a document after a specific revision number.
|
|
79
|
-
* @param docId - The ID of the document.
|
|
80
|
-
* @param rev - The revision number after which to fetch changes.
|
|
81
|
-
* @returns A promise resolving with an array of changes.
|
|
82
|
-
*/
|
|
83
|
-
async getChangesSince(docId, rev) {
|
|
84
|
-
return this.rpc.request('getChangesSince', { docId, rev });
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Applies a set of client-generated changes to a document on the server.
|
|
88
|
-
* @param docId - The ID of the document.
|
|
89
|
-
* @param changes - An array of changes to apply.
|
|
90
|
-
* @returns A promise resolving with the changes as committed by the server (potentially transformed).
|
|
91
|
-
*/
|
|
92
|
-
async commitChanges(docId, changes) {
|
|
93
|
-
return this.rpc.request('commitChanges', { docId, changes });
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Deletes a document on the server.
|
|
97
|
-
* @param docId - The ID of the document to delete.
|
|
98
|
-
* @returns A promise resolving when the deletion is confirmed.
|
|
99
|
-
*/
|
|
100
|
-
async deleteDoc(docId) {
|
|
101
|
-
return this.rpc.request('deleteDoc', { docId });
|
|
102
|
-
}
|
|
103
|
-
// === Version Operations ===
|
|
104
|
-
/**
|
|
105
|
-
* Creates a named version snapshot of a document's current state on the server.
|
|
106
|
-
* @param docId - The ID of the document.
|
|
107
|
-
* @param name - A descriptive name for the version.
|
|
108
|
-
* @returns A promise resolving with the unique ID of the newly created version.
|
|
109
|
-
*/
|
|
110
|
-
async createVersion(docId, metadata) {
|
|
111
|
-
return this.rpc.request('createVersion', { docId, metadata });
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Lists metadata for saved versions of a document.
|
|
115
|
-
* @param docId - The ID of the document.
|
|
116
|
-
* @param options - Options for filtering or pagination (e.g., limit, offset).
|
|
117
|
-
* @returns A promise resolving with an array of version metadata objects.
|
|
118
|
-
*/
|
|
119
|
-
async listVersions(docId, options) {
|
|
120
|
-
return this.rpc.request('listVersions', { docId, options });
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Gets the document state snapshot corresponding to a specific version ID.
|
|
124
|
-
* @param docId - The ID of the document.
|
|
125
|
-
* @param versionId - The ID of the version to retrieve.
|
|
126
|
-
* @returns A promise resolving with the document snapshot for that version.
|
|
127
|
-
*/
|
|
128
|
-
async getVersionState(docId, versionId) {
|
|
129
|
-
return this.rpc.request('getVersionState', { docId, versionId });
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Gets the original changes associated with a specific version ID.
|
|
133
|
-
* @param docId - The ID of the document.
|
|
134
|
-
* @param versionId - The ID of the version.
|
|
135
|
-
* @returns A promise resolving with an array of changes that constitute that version.
|
|
136
|
-
*/
|
|
137
|
-
async getVersionChanges(docId, versionId) {
|
|
138
|
-
return this.rpc.request('getVersionChanges', { docId, versionId });
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Updates the name of a specific version.
|
|
142
|
-
* @param docId - The ID of the document.
|
|
143
|
-
* @param versionId - The ID of the version to update.
|
|
144
|
-
* @param name - The new name for the version.
|
|
145
|
-
* @returns A promise resolving when the update is confirmed.
|
|
146
|
-
*/
|
|
147
|
-
async updateVersion(docId, versionId, metadata) {
|
|
148
|
-
return this.rpc.request('updateVersion', { docId, versionId, metadata });
|
|
149
|
-
}
|
|
150
|
-
// === Branch Operations ===
|
|
151
|
-
/**
|
|
152
|
-
* Lists all branches for a document.
|
|
153
|
-
* @param docId - The ID of the document.
|
|
154
|
-
* @returns A promise resolving with an array of branch metadata objects.
|
|
155
|
-
*/
|
|
156
|
-
async listBranches(docId) {
|
|
157
|
-
return this.rpc.request('listBranches', { docId });
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Creates a new branch for a document.
|
|
161
|
-
* @param docId - The ID of the document.
|
|
162
|
-
* @param rev - The revision number to base the new branch on.
|
|
163
|
-
* @param metadata - Optional metadata for the new branch.
|
|
164
|
-
* @returns A promise resolving with the unique ID of the newly created branch.
|
|
165
|
-
*/
|
|
166
|
-
async createBranch(docId, rev, metadata) {
|
|
167
|
-
return this.rpc.request('createBranch', { docId, rev, metadata });
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Closes a branch on the server.
|
|
171
|
-
* @param branchId - The ID of the branch to close.
|
|
172
|
-
* @returns A promise resolving when the branch is closed.
|
|
173
|
-
*/
|
|
174
|
-
async closeBranch(branchId) {
|
|
175
|
-
return this.rpc.request('closeBranch', { branchId });
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Merges a branch on the server.
|
|
179
|
-
* @param branchId - The ID of the branch to merge.
|
|
180
|
-
* @returns A promise resolving when the merge is confirmed.
|
|
181
|
-
*/
|
|
182
|
-
async mergeBranch(branchId) {
|
|
183
|
-
return this.rpc.request('mergeBranch', { branchId });
|
|
184
|
-
}
|
|
1
|
+
import "../../chunk-IZ2YBCUP.js";
|
|
2
|
+
import {} from "../../event-signal.js";
|
|
3
|
+
import { PatchesClient } from "../PatchesClient.js";
|
|
4
|
+
import { WebSocketTransport } from "./WebSocketTransport.js";
|
|
5
|
+
class PatchesWebSocket extends PatchesClient {
|
|
6
|
+
transport;
|
|
7
|
+
// --- Public Signals ---
|
|
8
|
+
/** Signal emitted when the underlying WebSocket connection state changes. */
|
|
9
|
+
onStateChange;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new Patches WebSocket client instance.
|
|
12
|
+
* @param url - The WebSocket server URL to connect to
|
|
13
|
+
* @param wsOptions - Optional configuration for the underlying WebSocket connection
|
|
14
|
+
*/
|
|
15
|
+
constructor(url, wsOptions) {
|
|
16
|
+
const transport = new WebSocketTransport(url, wsOptions);
|
|
17
|
+
super(transport);
|
|
18
|
+
this.transport = transport;
|
|
19
|
+
this.onStateChange = this.transport.onStateChange;
|
|
20
|
+
}
|
|
21
|
+
// --- Connection Management ---
|
|
22
|
+
/**
|
|
23
|
+
* Establishes a connection to the Patches server.
|
|
24
|
+
* @returns A promise that resolves when the connection is established
|
|
25
|
+
*/
|
|
26
|
+
async connect() {
|
|
27
|
+
await this.transport.connect();
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Terminates the connection to the Patches server.
|
|
31
|
+
*/
|
|
32
|
+
disconnect() {
|
|
33
|
+
this.transport.disconnect();
|
|
34
|
+
}
|
|
185
35
|
}
|
|
36
|
+
export {
|
|
37
|
+
PatchesWebSocket
|
|
38
|
+
};
|
|
@@ -1,21 +1,28 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { PatchesState, Change, 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
5
|
import { JSONRPCServer } from '../protocol/JSONRPCServer.js';
|
|
6
|
-
import {
|
|
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 '../protocol/types.js';
|
|
13
|
+
|
|
7
14
|
/**
|
|
8
15
|
* High-level client for the Patches real-time collaboration service.
|
|
9
16
|
* This class provides document subscription, patch notification handling,
|
|
10
17
|
* versioning, and other OT-specific functionality over a JSON RPC interface.
|
|
11
18
|
*/
|
|
12
|
-
|
|
19
|
+
interface RPCServerOptions {
|
|
13
20
|
patches: PatchesServer;
|
|
14
21
|
history?: PatchesHistoryManager;
|
|
15
22
|
branches?: PatchesBranchManager;
|
|
16
23
|
auth?: AuthorizationProvider;
|
|
17
24
|
}
|
|
18
|
-
|
|
25
|
+
declare class RPCServer {
|
|
19
26
|
rpc: JSONRPCServer;
|
|
20
27
|
auth: AuthorizationProvider;
|
|
21
28
|
protected patches: PatchesServer;
|
|
@@ -39,7 +46,7 @@ export declare class RPCServer {
|
|
|
39
46
|
getDoc(params: {
|
|
40
47
|
docId: string;
|
|
41
48
|
atRev?: number;
|
|
42
|
-
}, ctx?: AuthContext): Promise<
|
|
49
|
+
}, ctx?: AuthContext): Promise<PatchesState<any>>;
|
|
43
50
|
/**
|
|
44
51
|
* Gets changes that occurred for a document after a specific revision number.
|
|
45
52
|
* @param connectionId - The ID of the connection making the request
|
|
@@ -74,7 +81,7 @@ export declare class RPCServer {
|
|
|
74
81
|
listVersions(params: {
|
|
75
82
|
docId: string;
|
|
76
83
|
options?: ListVersionsOptions;
|
|
77
|
-
}, ctx?: AuthContext): Promise<
|
|
84
|
+
}, ctx?: AuthContext): Promise<VersionMetadata[]>;
|
|
78
85
|
createVersion(params: {
|
|
79
86
|
docId: string;
|
|
80
87
|
metadata: EditableVersionMetadata;
|
|
@@ -98,7 +105,7 @@ export declare class RPCServer {
|
|
|
98
105
|
}, ctx?: AuthContext): Promise<Change[]>;
|
|
99
106
|
listBranches(params: {
|
|
100
107
|
docId: string;
|
|
101
|
-
}, ctx?: AuthContext): Promise<
|
|
108
|
+
}, ctx?: AuthContext): Promise<Branch[]>;
|
|
102
109
|
createBranch(params: {
|
|
103
110
|
docId: string;
|
|
104
111
|
rev: number;
|
|
@@ -116,3 +123,5 @@ export declare class RPCServer {
|
|
|
116
123
|
protected assertHistoryEnabled(): void;
|
|
117
124
|
protected assertBranchingEnabled(): void;
|
|
118
125
|
}
|
|
126
|
+
|
|
127
|
+
export { RPCServer, type RPCServerOptions };
|