@dabble/patches 0.6.0 → 0.7.1
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/lww/consolidateOps.d.ts +40 -0
- package/dist/algorithms/lww/consolidateOps.js +103 -0
- package/dist/algorithms/lww/mergeServerWithLocal.d.ts +22 -0
- package/dist/algorithms/lww/mergeServerWithLocal.js +32 -0
- package/dist/algorithms/{client → ot/client}/applyCommittedChanges.d.ts +10 -3
- package/dist/algorithms/{client → ot/client}/applyCommittedChanges.js +7 -4
- package/dist/algorithms/{client → ot/client}/createStateFromSnapshot.d.ts +3 -3
- package/dist/algorithms/{client → ot/client}/createStateFromSnapshot.js +1 -1
- package/dist/algorithms/ot/server/commitChanges.d.ts +43 -0
- package/dist/algorithms/{server → ot/server}/commitChanges.js +22 -7
- package/dist/algorithms/{server → ot/server}/createVersion.d.ts +5 -5
- package/dist/algorithms/{server → ot/server}/createVersion.js +2 -2
- package/dist/algorithms/{server → ot/server}/getSnapshotAtRevision.d.ts +5 -5
- package/dist/algorithms/{server → ot/server}/getSnapshotAtRevision.js +1 -1
- package/dist/algorithms/{server → ot/server}/getStateAtRevision.d.ts +5 -5
- package/dist/algorithms/{server → ot/server}/getStateAtRevision.js +1 -1
- package/dist/algorithms/{server → ot/server}/handleOfflineSessionsAndBatches.d.ts +5 -5
- package/dist/algorithms/{server → ot/server}/handleOfflineSessionsAndBatches.js +3 -3
- package/dist/algorithms/{server → ot/server}/transformIncomingChanges.d.ts +3 -3
- package/dist/algorithms/{server → ot/server}/transformIncomingChanges.js +3 -3
- package/dist/algorithms/{shared → ot/shared}/applyChanges.d.ts +3 -3
- package/dist/algorithms/{shared → ot/shared}/applyChanges.js +2 -2
- package/dist/algorithms/{shared → ot/shared}/changeBatching.d.ts +3 -3
- package/dist/algorithms/{shared → ot/shared}/changeBatching.js +2 -2
- package/dist/algorithms/{shared → ot/shared}/rebaseChanges.d.ts +3 -3
- package/dist/algorithms/{shared → ot/shared}/rebaseChanges.js +2 -2
- 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 +7 -36
- 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/PatchesHistoryClient.js +1 -1
- 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 +2 -2
- package/dist/compression/index.js +1 -1
- package/dist/{algorithms/shared → compression}/lz.js +1 -1
- package/dist/data/change.js +2 -0
- package/dist/fractionalIndex.d.ts +67 -0
- package/dist/fractionalIndex.js +241 -0
- package/dist/index.d.ts +13 -3
- package/dist/index.js +1 -0
- package/dist/json-patch/types.d.ts +2 -0
- package/dist/net/PatchesClient.js +15 -15
- package/dist/net/PatchesSync.d.ts +20 -8
- package/dist/net/PatchesSync.js +57 -65
- package/dist/net/index.d.ts +7 -11
- 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 +10 -8
- package/dist/server/CompressedStoreBackend.js +7 -13
- 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 +182 -0
- package/dist/server/LWWServer.d.ts +130 -0
- package/dist/server/LWWServer.js +214 -0
- package/dist/server/{PatchesBranchManager.d.ts → OTBranchManager.d.ts} +32 -12
- package/dist/server/{PatchesBranchManager.js → OTBranchManager.js} +27 -42
- package/dist/server/OTServer.d.ts +108 -0
- package/dist/server/OTServer.js +141 -0
- package/dist/server/PatchesHistoryManager.d.ts +21 -16
- package/dist/server/PatchesHistoryManager.js +23 -11
- package/dist/server/PatchesServer.d.ts +70 -81
- package/dist/server/PatchesServer.js +0 -175
- package/dist/server/branchUtils.d.ts +82 -0
- package/dist/server/branchUtils.js +66 -0
- package/dist/server/index.d.ts +18 -7
- 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 +109 -27
- package/dist/server/utils.d.ts +12 -0
- package/dist/server/utils.js +23 -0
- package/dist/solid/context.d.ts +4 -3
- package/dist/solid/doc-manager.d.ts +3 -3
- package/dist/solid/index.d.ts +4 -3
- package/dist/solid/primitives.d.ts +2 -3
- package/dist/types.d.ts +4 -2
- package/dist/vue/composables.d.ts +2 -3
- package/dist/vue/doc-manager.d.ts +3 -3
- package/dist/vue/index.d.ts +4 -3
- package/dist/vue/provider.d.ts +4 -3
- package/package.json +1 -1
- package/dist/algorithms/client/collapsePendingChanges.d.ts +0 -30
- package/dist/algorithms/client/collapsePendingChanges.js +0 -78
- package/dist/algorithms/client/makeChange.d.ts +0 -9
- package/dist/algorithms/client/makeChange.js +0 -29
- package/dist/algorithms/server/commitChanges.d.ts +0 -19
- package/dist/net/websocket/RPCServer.d.ts +0 -141
- package/dist/net/websocket/RPCServer.js +0 -204
- /package/dist/{algorithms/shared → compression}/lz.d.ts +0 -0
|
@@ -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 };
|
|
@@ -1,204 +0,0 @@
|
|
|
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
|
-
this.rpc.registerMethod("undeleteDoc", this.undeleteDoc.bind(this));
|
|
29
|
-
if (this.history) {
|
|
30
|
-
this.rpc.registerMethod("listVersions", this.listVersions.bind(this));
|
|
31
|
-
this.rpc.registerMethod("createVersion", this.createVersion.bind(this));
|
|
32
|
-
this.rpc.registerMethod("updateVersion", this.updateVersion.bind(this));
|
|
33
|
-
this.rpc.registerMethod("getVersionState", this.getVersionState.bind(this));
|
|
34
|
-
this.rpc.registerMethod("getVersionChanges", this.getVersionChanges.bind(this));
|
|
35
|
-
this.rpc.registerMethod("listServerChanges", this.listServerChanges.bind(this));
|
|
36
|
-
}
|
|
37
|
-
if (this.branches) {
|
|
38
|
-
this.rpc.registerMethod("listBranches", this.listBranches.bind(this));
|
|
39
|
-
this.rpc.registerMethod("createBranch", this.createBranch.bind(this));
|
|
40
|
-
this.rpc.registerMethod("closeBranch", this.closeBranch.bind(this));
|
|
41
|
-
this.rpc.registerMethod("mergeBranch", this.mergeBranch.bind(this));
|
|
42
|
-
}
|
|
43
|
-
this.patches.onChangesCommitted((docId, changes, originClientId) => {
|
|
44
|
-
this.rpc.notify("changesCommitted", { docId, changes }, originClientId);
|
|
45
|
-
});
|
|
46
|
-
this.patches.onDocDeleted((docId, options, originClientId) => {
|
|
47
|
-
this.rpc.notify("docDeleted", { docId }, originClientId);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Gets the latest state (content and revision) of a document.
|
|
52
|
-
* @param connectionId - The ID of the connection making the request
|
|
53
|
-
* @param params - The document parameters
|
|
54
|
-
* @param params.docId - The ID of the document
|
|
55
|
-
* @param params.atRev - Optional revision number to get document state at
|
|
56
|
-
*/
|
|
57
|
-
async getDoc(params, ctx) {
|
|
58
|
-
const { docId, atRev } = params;
|
|
59
|
-
await this.assertRead(ctx, docId, "getDoc", params);
|
|
60
|
-
return this.patches.getDoc(docId, atRev);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Gets changes that occurred for a document after a specific revision number.
|
|
64
|
-
* @param connectionId - The ID of the connection making the request
|
|
65
|
-
* @param params - The change request parameters
|
|
66
|
-
* @param params.docId - The ID of the document
|
|
67
|
-
* @param params.rev - The revision number after which to fetch changes
|
|
68
|
-
*/
|
|
69
|
-
async getChangesSince(params, ctx) {
|
|
70
|
-
const { docId, rev } = params;
|
|
71
|
-
await this.assertRead(ctx, docId, "getChangesSince", params);
|
|
72
|
-
return this.patches.getChangesSince(docId, rev);
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Applies a set of client-generated changes to a document on the server.
|
|
76
|
-
* @param connectionId - The ID of the connection making the request
|
|
77
|
-
* @param params - The change parameters
|
|
78
|
-
* @param params.docId - The ID of the document
|
|
79
|
-
* @param params.changes - An array of changes to apply
|
|
80
|
-
* @param params.options - Optional commit settings (e.g., forceCommit for migrations)
|
|
81
|
-
*/
|
|
82
|
-
async commitChanges(params, ctx) {
|
|
83
|
-
const { docId, changes, options } = params;
|
|
84
|
-
await this.assertWrite(ctx, docId, "commitChanges", params);
|
|
85
|
-
const [priorChanges, newChanges] = await this.patches.commitChanges(docId, changes, options, ctx?.clientId);
|
|
86
|
-
return [...priorChanges, ...newChanges];
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Deletes a document on the server.
|
|
90
|
-
* @param connectionId - The ID of the connection making the request
|
|
91
|
-
* @param params - The deletion parameters
|
|
92
|
-
* @param params.docId - The ID of the document to delete
|
|
93
|
-
* @param params.options - Optional deletion settings (e.g., skipTombstone)
|
|
94
|
-
*/
|
|
95
|
-
async deleteDoc(params, ctx) {
|
|
96
|
-
const { docId, options } = params;
|
|
97
|
-
await this.assertWrite(ctx, docId, "deleteDoc", params);
|
|
98
|
-
await this.patches.deleteDoc(docId, options, ctx?.clientId);
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Removes the tombstone for a deleted document, allowing it to be recreated.
|
|
102
|
-
* @param params - The undelete parameters
|
|
103
|
-
* @param params.docId - The ID of the document to undelete
|
|
104
|
-
*/
|
|
105
|
-
async undeleteDoc(params, ctx) {
|
|
106
|
-
const { docId } = params;
|
|
107
|
-
await this.assertWrite(ctx, docId, "undeleteDoc", params);
|
|
108
|
-
return this.patches.undeleteDoc(docId);
|
|
109
|
-
}
|
|
110
|
-
// ---------------------------------------------------------------------------
|
|
111
|
-
// History Manager wrappers
|
|
112
|
-
// ---------------------------------------------------------------------------
|
|
113
|
-
async listVersions(params, ctx) {
|
|
114
|
-
this.assertHistoryEnabled();
|
|
115
|
-
const { docId, options } = params;
|
|
116
|
-
await this.assertRead(ctx, docId, "listVersions", params);
|
|
117
|
-
return this.history.listVersions(docId, options ?? {});
|
|
118
|
-
}
|
|
119
|
-
async createVersion(params, ctx) {
|
|
120
|
-
this.assertHistoryEnabled();
|
|
121
|
-
const { docId, metadata } = params;
|
|
122
|
-
await this.assertWrite(ctx, docId, "createVersion", params);
|
|
123
|
-
return this.history.createVersion(docId, metadata);
|
|
124
|
-
}
|
|
125
|
-
async updateVersion(params, ctx) {
|
|
126
|
-
this.assertHistoryEnabled();
|
|
127
|
-
const { docId, versionId, metadata } = params;
|
|
128
|
-
await this.assertWrite(ctx, docId, "updateVersion", params);
|
|
129
|
-
return this.history.updateVersion(docId, versionId, metadata);
|
|
130
|
-
}
|
|
131
|
-
async getVersionState(params, ctx) {
|
|
132
|
-
this.assertHistoryEnabled();
|
|
133
|
-
const { docId, versionId } = params;
|
|
134
|
-
await this.assertRead(ctx, docId, "getStateAtVersion", params);
|
|
135
|
-
return this.history.getStateAtVersion(docId, versionId);
|
|
136
|
-
}
|
|
137
|
-
async getVersionChanges(params, ctx) {
|
|
138
|
-
this.assertHistoryEnabled();
|
|
139
|
-
const { docId, versionId } = params;
|
|
140
|
-
await this.assertRead(ctx, docId, "getChangesForVersion", params);
|
|
141
|
-
return this.history.getChangesForVersion(docId, versionId);
|
|
142
|
-
}
|
|
143
|
-
async listServerChanges(params, ctx) {
|
|
144
|
-
this.assertHistoryEnabled();
|
|
145
|
-
const { docId, options } = params;
|
|
146
|
-
await this.assertRead(ctx, docId, "listServerChanges", params);
|
|
147
|
-
return this.history.listServerChanges(docId, options ?? {});
|
|
148
|
-
}
|
|
149
|
-
// ---------------------------------------------------------------------------
|
|
150
|
-
// Branch Manager wrappers
|
|
151
|
-
// ---------------------------------------------------------------------------
|
|
152
|
-
async listBranches(params, ctx) {
|
|
153
|
-
this.assertBranchingEnabled();
|
|
154
|
-
const { docId } = params;
|
|
155
|
-
await this.assertRead(ctx, docId, "listBranches", params);
|
|
156
|
-
return this.branches.listBranches(docId);
|
|
157
|
-
}
|
|
158
|
-
async createBranch(params, ctx) {
|
|
159
|
-
this.assertBranchingEnabled();
|
|
160
|
-
const { docId, rev, metadata } = params;
|
|
161
|
-
await this.assertWrite(ctx, docId, "createBranch", params);
|
|
162
|
-
return this.branches.createBranch(docId, rev, metadata);
|
|
163
|
-
}
|
|
164
|
-
async closeBranch(params, ctx) {
|
|
165
|
-
this.assertBranchingEnabled();
|
|
166
|
-
const { branchId } = params;
|
|
167
|
-
await this.assertWrite(ctx, branchId, "closeBranch", params);
|
|
168
|
-
return this.branches.closeBranch(branchId, "closed");
|
|
169
|
-
}
|
|
170
|
-
async mergeBranch(params, ctx) {
|
|
171
|
-
this.assertBranchingEnabled();
|
|
172
|
-
const { branchId } = params;
|
|
173
|
-
await this.assertWrite(ctx, branchId, "mergeBranch", params);
|
|
174
|
-
return this.branches.mergeBranch(branchId);
|
|
175
|
-
}
|
|
176
|
-
// ---------------------------------------------------------------------------
|
|
177
|
-
// Authorization helpers
|
|
178
|
-
// ---------------------------------------------------------------------------
|
|
179
|
-
async assertAccess(ctx, docId, kind, method, params) {
|
|
180
|
-
const ok = await this.auth.canAccess(ctx, docId, kind, method, params);
|
|
181
|
-
if (!ok) {
|
|
182
|
-
throw new StatusError(401, `${kind.toUpperCase()}_FORBIDDEN:${docId}`);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
assertRead(ctx, docId, method, params) {
|
|
186
|
-
return this.assertAccess(ctx, docId, "read", method, params);
|
|
187
|
-
}
|
|
188
|
-
assertWrite(ctx, docId, method, params) {
|
|
189
|
-
return this.assertAccess(ctx, docId, "write", method, params);
|
|
190
|
-
}
|
|
191
|
-
assertHistoryEnabled() {
|
|
192
|
-
if (!this.history) {
|
|
193
|
-
throw new StatusError(404, "History is not enabled");
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
assertBranchingEnabled() {
|
|
197
|
-
if (!this.branches) {
|
|
198
|
-
throw new StatusError(404, "Branching is not enabled");
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
export {
|
|
203
|
-
RPCServer
|
|
204
|
-
};
|
|
File without changes
|