@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,193 +1,191 @@
|
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
assertBranchingEnabled() {
|
|
189
|
-
if (!this.branches) {
|
|
190
|
-
throw new StatusError(404, 'Branching is not enabled');
|
|
191
|
-
}
|
|
192
|
-
}
|
|
1
|
+
import "../../chunk-IZ2YBCUP.js";
|
|
2
|
+
import { StatusError } from "../error.js";
|
|
3
|
+
import { JSONRPCServer } from "../protocol/JSONRPCServer.js";
|
|
4
|
+
import { denyAll } from "./AuthorizationProvider.js";
|
|
5
|
+
class RPCServer {
|
|
6
|
+
rpc;
|
|
7
|
+
auth;
|
|
8
|
+
patches;
|
|
9
|
+
history;
|
|
10
|
+
branches;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new Patches WebSocket client instance.
|
|
13
|
+
* @param patches - The patches server instance to handle document operations
|
|
14
|
+
* @param history - (Optional) History manager instance to handle versioning operations
|
|
15
|
+
* @param branches - (Optional) Branch manager instance to handle branching operations
|
|
16
|
+
* @param auth - (Optional) Authorization provider implementation. Defaults to deny-all for security.
|
|
17
|
+
*/
|
|
18
|
+
constructor({ patches, history, branches, auth = denyAll }) {
|
|
19
|
+
this.rpc = new JSONRPCServer();
|
|
20
|
+
this.patches = patches;
|
|
21
|
+
this.history = history;
|
|
22
|
+
this.branches = branches;
|
|
23
|
+
this.auth = auth;
|
|
24
|
+
this.rpc.registerMethod("getDoc", this.getDoc.bind(this));
|
|
25
|
+
this.rpc.registerMethod("getChangesSince", this.getChangesSince.bind(this));
|
|
26
|
+
this.rpc.registerMethod("commitChanges", this.commitChanges.bind(this));
|
|
27
|
+
this.rpc.registerMethod("deleteDoc", this.deleteDoc.bind(this));
|
|
28
|
+
if (this.history) {
|
|
29
|
+
this.rpc.registerMethod("listVersions", this.listVersions.bind(this));
|
|
30
|
+
this.rpc.registerMethod("createVersion", this.createVersion.bind(this));
|
|
31
|
+
this.rpc.registerMethod("updateVersion", this.updateVersion.bind(this));
|
|
32
|
+
this.rpc.registerMethod("getVersionState", this.getVersionState.bind(this));
|
|
33
|
+
this.rpc.registerMethod("getVersionChanges", this.getVersionChanges.bind(this));
|
|
34
|
+
this.rpc.registerMethod("listServerChanges", this.listServerChanges.bind(this));
|
|
35
|
+
}
|
|
36
|
+
if (this.branches) {
|
|
37
|
+
this.rpc.registerMethod("listBranches", this.listBranches.bind(this));
|
|
38
|
+
this.rpc.registerMethod("createBranch", this.createBranch.bind(this));
|
|
39
|
+
this.rpc.registerMethod("closeBranch", this.closeBranch.bind(this));
|
|
40
|
+
this.rpc.registerMethod("mergeBranch", this.mergeBranch.bind(this));
|
|
41
|
+
}
|
|
42
|
+
this.patches.onChangesCommitted((docId, changes, originClientId) => {
|
|
43
|
+
this.rpc.notify("changesCommitted", { docId, changes }, originClientId);
|
|
44
|
+
});
|
|
45
|
+
this.patches.onDocDeleted((docId, originClientId) => {
|
|
46
|
+
this.rpc.notify("docDeleted", { docId }, originClientId);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Gets the latest state (content and revision) of a document.
|
|
51
|
+
* @param connectionId - The ID of the connection making the request
|
|
52
|
+
* @param params - The document parameters
|
|
53
|
+
* @param params.docId - The ID of the document
|
|
54
|
+
* @param params.atRev - Optional revision number to get document state at
|
|
55
|
+
*/
|
|
56
|
+
async getDoc(params, ctx) {
|
|
57
|
+
const { docId, atRev } = params;
|
|
58
|
+
await this.assertRead(ctx, docId, "getDoc", params);
|
|
59
|
+
return this.patches.getDoc(docId, atRev);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Gets changes that occurred for a document after a specific revision number.
|
|
63
|
+
* @param connectionId - The ID of the connection making the request
|
|
64
|
+
* @param params - The change request parameters
|
|
65
|
+
* @param params.docId - The ID of the document
|
|
66
|
+
* @param params.rev - The revision number after which to fetch changes
|
|
67
|
+
*/
|
|
68
|
+
async getChangesSince(params, ctx) {
|
|
69
|
+
const { docId, rev } = params;
|
|
70
|
+
await this.assertRead(ctx, docId, "getChangesSince", params);
|
|
71
|
+
return this.patches.getChangesSince(docId, rev);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Applies a set of client-generated changes to a document on the server.
|
|
75
|
+
* @param connectionId - The ID of the connection making the request
|
|
76
|
+
* @param params - The change parameters
|
|
77
|
+
* @param params.docId - The ID of the document
|
|
78
|
+
* @param params.changes - An array of changes to apply
|
|
79
|
+
*/
|
|
80
|
+
async commitChanges(params, ctx) {
|
|
81
|
+
const { docId, changes } = params;
|
|
82
|
+
await this.assertWrite(ctx, docId, "commitChanges", params);
|
|
83
|
+
const [priorChanges, newChanges] = await this.patches.commitChanges(docId, changes, ctx?.clientId);
|
|
84
|
+
return [...priorChanges, ...newChanges];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Deletes a document on the server.
|
|
88
|
+
* @param connectionId - The ID of the connection making the request
|
|
89
|
+
* @param params - The deletion parameters
|
|
90
|
+
* @param params.docId - The ID of the document to delete
|
|
91
|
+
*/
|
|
92
|
+
async deleteDoc(params, ctx) {
|
|
93
|
+
const { docId } = params;
|
|
94
|
+
await this.assertWrite(ctx, docId, "deleteDoc", params);
|
|
95
|
+
await this.patches.deleteDoc(docId, ctx?.clientId);
|
|
96
|
+
}
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
// History Manager wrappers
|
|
99
|
+
// ---------------------------------------------------------------------------
|
|
100
|
+
async listVersions(params, ctx) {
|
|
101
|
+
this.assertHistoryEnabled();
|
|
102
|
+
const { docId, options } = params;
|
|
103
|
+
await this.assertRead(ctx, docId, "listVersions", params);
|
|
104
|
+
return this.history.listVersions(docId, options ?? {});
|
|
105
|
+
}
|
|
106
|
+
async createVersion(params, ctx) {
|
|
107
|
+
this.assertHistoryEnabled();
|
|
108
|
+
const { docId, metadata } = params;
|
|
109
|
+
await this.assertWrite(ctx, docId, "createVersion", params);
|
|
110
|
+
return this.history.createVersion(docId, metadata);
|
|
111
|
+
}
|
|
112
|
+
async updateVersion(params, ctx) {
|
|
113
|
+
this.assertHistoryEnabled();
|
|
114
|
+
const { docId, versionId, metadata } = params;
|
|
115
|
+
await this.assertWrite(ctx, docId, "updateVersion", params);
|
|
116
|
+
return this.history.updateVersion(docId, versionId, metadata);
|
|
117
|
+
}
|
|
118
|
+
async getVersionState(params, ctx) {
|
|
119
|
+
this.assertHistoryEnabled();
|
|
120
|
+
const { docId, versionId } = params;
|
|
121
|
+
await this.assertRead(ctx, docId, "getStateAtVersion", params);
|
|
122
|
+
return this.history.getStateAtVersion(docId, versionId);
|
|
123
|
+
}
|
|
124
|
+
async getVersionChanges(params, ctx) {
|
|
125
|
+
this.assertHistoryEnabled();
|
|
126
|
+
const { docId, versionId } = params;
|
|
127
|
+
await this.assertRead(ctx, docId, "getChangesForVersion", params);
|
|
128
|
+
return this.history.getChangesForVersion(docId, versionId);
|
|
129
|
+
}
|
|
130
|
+
async listServerChanges(params, ctx) {
|
|
131
|
+
this.assertHistoryEnabled();
|
|
132
|
+
const { docId, options } = params;
|
|
133
|
+
await this.assertRead(ctx, docId, "listServerChanges", params);
|
|
134
|
+
return this.history.listServerChanges(docId, options ?? {});
|
|
135
|
+
}
|
|
136
|
+
// ---------------------------------------------------------------------------
|
|
137
|
+
// Branch Manager wrappers
|
|
138
|
+
// ---------------------------------------------------------------------------
|
|
139
|
+
async listBranches(params, ctx) {
|
|
140
|
+
this.assertBranchingEnabled();
|
|
141
|
+
const { docId } = params;
|
|
142
|
+
await this.assertRead(ctx, docId, "listBranches", params);
|
|
143
|
+
return this.branches.listBranches(docId);
|
|
144
|
+
}
|
|
145
|
+
async createBranch(params, ctx) {
|
|
146
|
+
this.assertBranchingEnabled();
|
|
147
|
+
const { docId, rev, metadata } = params;
|
|
148
|
+
await this.assertWrite(ctx, docId, "createBranch", params);
|
|
149
|
+
return this.branches.createBranch(docId, rev, metadata);
|
|
150
|
+
}
|
|
151
|
+
async closeBranch(params, ctx) {
|
|
152
|
+
this.assertBranchingEnabled();
|
|
153
|
+
const { branchId } = params;
|
|
154
|
+
await this.assertWrite(ctx, branchId, "closeBranch", params);
|
|
155
|
+
return this.branches.closeBranch(branchId, "closed");
|
|
156
|
+
}
|
|
157
|
+
async mergeBranch(params, ctx) {
|
|
158
|
+
this.assertBranchingEnabled();
|
|
159
|
+
const { branchId } = params;
|
|
160
|
+
await this.assertWrite(ctx, branchId, "mergeBranch", params);
|
|
161
|
+
return this.branches.mergeBranch(branchId);
|
|
162
|
+
}
|
|
163
|
+
// ---------------------------------------------------------------------------
|
|
164
|
+
// Authorization helpers
|
|
165
|
+
// ---------------------------------------------------------------------------
|
|
166
|
+
async assertAccess(ctx, docId, kind, method, params) {
|
|
167
|
+
const ok = await this.auth.canAccess(ctx, docId, kind, method, params);
|
|
168
|
+
if (!ok) {
|
|
169
|
+
throw new StatusError(401, `${kind.toUpperCase()}_FORBIDDEN:${docId}`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
assertRead(ctx, docId, method, params) {
|
|
173
|
+
return this.assertAccess(ctx, docId, "read", method, params);
|
|
174
|
+
}
|
|
175
|
+
assertWrite(ctx, docId, method, params) {
|
|
176
|
+
return this.assertAccess(ctx, docId, "write", method, params);
|
|
177
|
+
}
|
|
178
|
+
assertHistoryEnabled() {
|
|
179
|
+
if (!this.history) {
|
|
180
|
+
throw new StatusError(404, "History is not enabled");
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
assertBranchingEnabled() {
|
|
184
|
+
if (!this.branches) {
|
|
185
|
+
throw new StatusError(404, "Branching is not enabled");
|
|
186
|
+
}
|
|
187
|
+
}
|
|
193
188
|
}
|
|
189
|
+
export {
|
|
190
|
+
RPCServer
|
|
191
|
+
};
|
|
@@ -1,41 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
method: string;
|
|
9
|
-
/** Parameters to pass to the remote procedure */
|
|
10
|
-
params?: any;
|
|
11
|
-
/** Request identifier, used to match responses to requests */
|
|
12
|
-
id?: number | string;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Represents a JSON-RPC 2.0 response object.
|
|
16
|
-
*/
|
|
17
|
-
export interface JsonRpcResponse {
|
|
18
|
-
/** JSON-RPC protocol version, always "2.0" */
|
|
19
|
-
jsonrpc: '2.0';
|
|
20
|
-
/** Result of the successful procedure call */
|
|
21
|
-
result?: any;
|
|
22
|
-
/** Error information if the procedure call failed */
|
|
23
|
-
error?: {
|
|
24
|
-
code: number;
|
|
25
|
-
message: string;
|
|
26
|
-
};
|
|
27
|
-
/** Response identifier, matches the id of the corresponding request */
|
|
28
|
-
id: number | string;
|
|
29
|
-
}
|
|
1
|
+
import { JsonRpcRequest, JsonRpcResponse } from '../protocol/types.js';
|
|
2
|
+
import '../../event-signal.js';
|
|
3
|
+
import '../../types.js';
|
|
4
|
+
import '../../json-patch/JSONPatch.js';
|
|
5
|
+
import '@dabble/delta';
|
|
6
|
+
import '../../json-patch/types.js';
|
|
7
|
+
|
|
30
8
|
/** Union type for all possible JSON-RPC message types */
|
|
31
|
-
|
|
9
|
+
type JsonRpcMessage = JsonRpcRequest | JsonRpcResponse;
|
|
32
10
|
/** Function type for sending JSON-RPC messages */
|
|
33
|
-
|
|
11
|
+
type SendFn = (message: JsonRpcMessage) => void;
|
|
34
12
|
/**
|
|
35
13
|
* Service that facilitates WebRTC connection establishment by relaying signaling messages.
|
|
36
14
|
* Acts as a central hub for WebRTC peers to exchange connection information.
|
|
37
15
|
*/
|
|
38
|
-
|
|
16
|
+
declare class SignalingService {
|
|
39
17
|
private clients;
|
|
40
18
|
/**
|
|
41
19
|
* Registers a new client connection with the signaling service.
|
|
@@ -89,3 +67,5 @@ export declare class SignalingService {
|
|
|
89
67
|
*/
|
|
90
68
|
private broadcast;
|
|
91
69
|
}
|
|
70
|
+
|
|
71
|
+
export { type JsonRpcMessage, type SendFn, SignalingService };
|