@dabble/patches 0.2.10 → 0.2.12
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/client/Patches.d.ts +9 -1
- package/dist/client/Patches.js +9 -1
- package/dist/client/PatchesDoc.d.ts +13 -1
- package/dist/client/PatchesDoc.js +17 -3
- package/dist/json-patch/createJSONPatch.d.ts +1 -1
- package/dist/json-patch/createJSONPatch.js +2 -2
- package/dist/json-patch/patchProxy.d.ts +41 -0
- package/dist/json-patch/patchProxy.js +125 -0
- package/dist/json-patch/state.d.ts +2 -0
- package/dist/json-patch/state.js +8 -0
- package/dist/json-patch/transformPatch.d.ts +19 -0
- package/dist/json-patch/transformPatch.js +37 -0
- package/dist/json-patch/types.d.ts +52 -0
- package/dist/json-patch/types.js +1 -0
- package/dist/json-patch/utils/deepEqual.d.ts +1 -0
- package/dist/json-patch/utils/deepEqual.js +33 -0
- package/dist/json-patch/utils/exit.d.ts +2 -0
- package/dist/json-patch/utils/exit.js +4 -0
- package/dist/json-patch/utils/get.d.ts +2 -0
- package/dist/json-patch/utils/get.js +6 -0
- package/dist/json-patch/utils/getOpData.d.ts +2 -0
- package/dist/json-patch/utils/getOpData.js +10 -0
- package/dist/json-patch/utils/getType.d.ts +3 -0
- package/dist/json-patch/utils/getType.js +6 -0
- package/dist/json-patch/utils/index.d.ts +14 -0
- package/dist/json-patch/utils/index.js +14 -0
- package/dist/json-patch/utils/log.d.ts +2 -0
- package/dist/json-patch/utils/log.js +7 -0
- package/dist/json-patch/utils/ops.d.ts +14 -0
- package/dist/json-patch/utils/ops.js +103 -0
- package/dist/json-patch/utils/paths.d.ts +9 -0
- package/dist/json-patch/utils/paths.js +53 -0
- package/dist/json-patch/utils/pluck.d.ts +5 -0
- package/dist/json-patch/utils/pluck.js +30 -0
- package/dist/json-patch/utils/shallowCopy.d.ts +1 -0
- package/dist/json-patch/utils/shallowCopy.js +20 -0
- package/dist/json-patch/utils/softWrites.d.ts +7 -0
- package/dist/json-patch/utils/softWrites.js +18 -0
- package/dist/json-patch/utils/toArrayIndex.d.ts +1 -0
- package/dist/json-patch/utils/toArrayIndex.js +12 -0
- package/dist/json-patch/utils/toKeys.d.ts +1 -0
- package/dist/json-patch/utils/toKeys.js +15 -0
- package/dist/json-patch/utils/updateArrayIndexes.d.ts +5 -0
- package/dist/json-patch/utils/updateArrayIndexes.js +38 -0
- package/dist/json-patch/utils/updateArrayPath.d.ts +5 -0
- package/dist/json-patch/utils/updateArrayPath.js +45 -0
- package/dist/net/AbstractTransport.d.ts +47 -0
- package/dist/net/AbstractTransport.js +39 -0
- package/dist/net/PatchesSync.d.ts +52 -0
- package/dist/net/PatchesSync.js +293 -0
- package/dist/net/index.d.ts +9 -0
- package/dist/net/index.js +7 -0
- package/dist/net/protocol/JSONRPCClient.d.ts +55 -0
- package/dist/net/protocol/JSONRPCClient.js +106 -0
- package/dist/net/protocol/types.d.ts +142 -0
- package/dist/net/protocol/types.js +1 -0
- package/dist/net/types.d.ts +6 -0
- package/dist/net/types.js +1 -0
- package/dist/net/webrtc/WebRTCAwareness.d.ts +81 -0
- package/dist/net/webrtc/WebRTCAwareness.js +119 -0
- package/dist/net/webrtc/WebRTCTransport.d.ts +80 -0
- package/dist/net/webrtc/WebRTCTransport.js +157 -0
- package/dist/net/websocket/PatchesWebSocket.d.ts +107 -0
- package/dist/net/websocket/PatchesWebSocket.js +144 -0
- package/dist/net/websocket/SignalingService.d.ts +91 -0
- package/dist/net/websocket/SignalingService.js +140 -0
- package/dist/net/websocket/WebSocketTransport.d.ts +58 -0
- package/dist/net/websocket/WebSocketTransport.js +190 -0
- package/dist/net/websocket/onlineState.d.ts +9 -0
- package/dist/net/websocket/onlineState.js +18 -0
- package/dist/persist/InMemoryStore.d.ts +23 -0
- package/dist/persist/InMemoryStore.js +103 -0
- package/dist/persist/IndexedDBStore.d.ts +81 -0
- package/dist/persist/IndexedDBStore.js +377 -0
- package/dist/persist/PatchesStore.d.ts +38 -0
- package/dist/persist/PatchesStore.js +1 -0
- package/dist/persist/index.d.ts +3 -0
- package/dist/persist/index.js +3 -0
- package/dist/server/PatchesBranchManager.d.ts +40 -0
- package/dist/server/PatchesBranchManager.js +138 -0
- package/dist/server/PatchesHistoryManager.d.ts +43 -0
- package/dist/server/PatchesHistoryManager.js +59 -0
- package/dist/server/PatchesServer.d.ts +129 -0
- package/dist/server/PatchesServer.js +358 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.js +3 -0
- package/dist/types.d.ts +166 -0
- package/dist/types.js +1 -0
- package/dist/utils/batching.d.ts +3 -0
- package/dist/utils/batching.js +41 -0
- package/dist/utils/breakChange.d.ts +10 -0
- package/dist/utils/breakChange.js +303 -0
- package/dist/utils/getJSONByteSize.d.ts +2 -0
- package/dist/utils/getJSONByteSize.js +13 -0
- package/dist/utils.d.ts +36 -0
- package/dist/utils.js +103 -0
- package/package.json +1 -1
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { createId } from 'crypto-id';
|
|
2
|
+
/**
|
|
3
|
+
* Helps manage branches for a document. A branch is a document that is branched from another document. Its first
|
|
4
|
+
* version will be the point-in-time of the original document at the time of the branch. Branches allow for parallel
|
|
5
|
+
* development of a document with the ability to merge changes back into the original document later.
|
|
6
|
+
*/
|
|
7
|
+
export class PatchesBranchManager {
|
|
8
|
+
constructor(store, patchesServer) {
|
|
9
|
+
this.store = store;
|
|
10
|
+
this.patchesServer = patchesServer;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Lists all open branches for a document.
|
|
14
|
+
* @param docId - The ID of the document.
|
|
15
|
+
* @returns The branches.
|
|
16
|
+
*/
|
|
17
|
+
async listBranches(docId) {
|
|
18
|
+
return await this.store.listBranches(docId);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new branch for a document.
|
|
22
|
+
* @param docId - The ID of the document to branch from.
|
|
23
|
+
* @param rev - The revision of the document to branch from.
|
|
24
|
+
* @param branchName - Optional name for the branch.
|
|
25
|
+
* @param metadata - Additional optional metadata to store with the branch.
|
|
26
|
+
* @returns The ID of the new branch document.
|
|
27
|
+
*/
|
|
28
|
+
async createBranch(docId, rev, branchName, metadata) {
|
|
29
|
+
// Prevent branching off a branch
|
|
30
|
+
const maybeBranch = await this.store.loadBranch(docId);
|
|
31
|
+
if (maybeBranch) {
|
|
32
|
+
throw new Error('Cannot create a branch from another branch.');
|
|
33
|
+
}
|
|
34
|
+
// 1. Get the state at the branch point
|
|
35
|
+
const stateAtRev = (await this.patchesServer._getStateAtRevision(docId, rev)).state;
|
|
36
|
+
const branchDocId = createId();
|
|
37
|
+
const now = Date.now();
|
|
38
|
+
// Create an initial version at the branch point rev (for snapshotting/large docs)
|
|
39
|
+
const initialVersionMetadata = {
|
|
40
|
+
id: createId(),
|
|
41
|
+
origin: 'main', // Branch doc versions are 'main' until merged
|
|
42
|
+
startDate: now,
|
|
43
|
+
endDate: now,
|
|
44
|
+
rev,
|
|
45
|
+
baseRev: rev,
|
|
46
|
+
name: branchName,
|
|
47
|
+
groupId: branchDocId,
|
|
48
|
+
branchName,
|
|
49
|
+
};
|
|
50
|
+
await this.store.createVersion(branchDocId, initialVersionMetadata, stateAtRev, []);
|
|
51
|
+
// 2. Create the branch metadata record
|
|
52
|
+
const branch = {
|
|
53
|
+
id: branchDocId,
|
|
54
|
+
branchedFromId: docId,
|
|
55
|
+
branchedRev: rev,
|
|
56
|
+
created: now,
|
|
57
|
+
name: branchName,
|
|
58
|
+
status: 'open',
|
|
59
|
+
...(metadata && { metadata }),
|
|
60
|
+
};
|
|
61
|
+
await this.store.createBranch(branch);
|
|
62
|
+
return branchDocId;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Closes a branch, marking it as merged or deleted.
|
|
66
|
+
* @param branchId - The ID of the branch to close.
|
|
67
|
+
* @param status - The status to set for the branch.
|
|
68
|
+
*/
|
|
69
|
+
async closeBranch(branchId, status = 'closed') {
|
|
70
|
+
await this.store.updateBranch(branchId, { status });
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Merges changes from a branch back into its source document.
|
|
74
|
+
* @param branchId - The ID of the branch document to merge.
|
|
75
|
+
* @returns The server commit change(s) applied to the source document.
|
|
76
|
+
* @throws Error if branch not found, already closed/merged, or merge fails.
|
|
77
|
+
*/
|
|
78
|
+
async mergeBranch(branchId) {
|
|
79
|
+
// 1. Load branch metadata
|
|
80
|
+
const branch = await this.store.loadBranch(branchId);
|
|
81
|
+
if (!branch) {
|
|
82
|
+
throw new Error(`Branch with ID ${branchId} not found.`);
|
|
83
|
+
}
|
|
84
|
+
if (branch.status !== 'open') {
|
|
85
|
+
throw new Error(`Branch ${branchId} is not open (status: ${branch.status}). Cannot merge.`);
|
|
86
|
+
}
|
|
87
|
+
const sourceDocId = branch.branchedFromId;
|
|
88
|
+
const branchStartRevOnSource = branch.branchedRev;
|
|
89
|
+
// 2. Get all committed server changes made on the branch document since it was created.
|
|
90
|
+
const branchChanges = await this.store.listChanges(branchId, {});
|
|
91
|
+
if (branchChanges.length === 0) {
|
|
92
|
+
console.log(`Branch ${branchId} has no changes to merge.`);
|
|
93
|
+
await this.closeBranch(branchId, 'merged');
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
// 3. Get all versions from the branch doc (skip offline versions)
|
|
97
|
+
const branchVersions = await this.store.listVersions(branchId, { origin: 'main' });
|
|
98
|
+
// 4. For each version, create a corresponding version in the main doc with updated fields
|
|
99
|
+
let lastVersionId;
|
|
100
|
+
for (const v of branchVersions) {
|
|
101
|
+
const newVersionId = createId();
|
|
102
|
+
const newVersionMetadata = {
|
|
103
|
+
...v,
|
|
104
|
+
id: newVersionId,
|
|
105
|
+
origin: 'branch',
|
|
106
|
+
baseRev: branchStartRevOnSource,
|
|
107
|
+
groupId: branchId,
|
|
108
|
+
branchName: branch.name,
|
|
109
|
+
parentId: lastVersionId,
|
|
110
|
+
};
|
|
111
|
+
const state = await this.store.loadVersionState(branchId, v.id);
|
|
112
|
+
const changes = await this.store.loadVersionChanges(branchId, v.id);
|
|
113
|
+
await this.store.createVersion(sourceDocId, newVersionMetadata, state, changes);
|
|
114
|
+
lastVersionId = newVersionId;
|
|
115
|
+
}
|
|
116
|
+
// 5. Flatten all branch changes into a single change for the main doc
|
|
117
|
+
const now = Date.now();
|
|
118
|
+
const flattenedChange = {
|
|
119
|
+
id: createId(12),
|
|
120
|
+
ops: branchChanges.flatMap(c => c.ops),
|
|
121
|
+
rev: branchStartRevOnSource + branchChanges.length,
|
|
122
|
+
baseRev: branchStartRevOnSource,
|
|
123
|
+
created: now,
|
|
124
|
+
};
|
|
125
|
+
// 6. Commit the flattened change to the main doc
|
|
126
|
+
let committedMergeChanges = [];
|
|
127
|
+
try {
|
|
128
|
+
[, committedMergeChanges] = await this.patchesServer.commitChanges(sourceDocId, [flattenedChange]);
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
console.error(`Failed to merge branch ${branchId} into ${sourceDocId}:`, error);
|
|
132
|
+
throw new Error(`Merge failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
133
|
+
}
|
|
134
|
+
// 7. Merge succeeded. Update the branch status.
|
|
135
|
+
await this.closeBranch(branchId, 'merged');
|
|
136
|
+
return committedMergeChanges;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Change, ListVersionsOptions, PatchesStoreBackend, VersionMetadata } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Helps retrieve historical information (versions, changes) for a document
|
|
4
|
+
* using the new versioning model based on IDs and metadata.
|
|
5
|
+
*/
|
|
6
|
+
export declare class PatchesHistoryManager {
|
|
7
|
+
private readonly docId;
|
|
8
|
+
private readonly store;
|
|
9
|
+
constructor(docId: string, store: PatchesStoreBackend);
|
|
10
|
+
/**
|
|
11
|
+
* Lists version metadata for the document, supporting various filters.
|
|
12
|
+
* @param options Filtering and sorting options (e.g., limit, reverse, origin, groupId, date range).
|
|
13
|
+
* @returns A list of version metadata objects.
|
|
14
|
+
*/
|
|
15
|
+
listVersions(options?: ListVersionsOptions): Promise<VersionMetadata[]>;
|
|
16
|
+
/**
|
|
17
|
+
* Loads the full document state snapshot for a specific version by its ID.
|
|
18
|
+
* @param versionId - The unique ID of the version.
|
|
19
|
+
* @returns The document state at that version.
|
|
20
|
+
* @throws Error if the version ID is not found or state loading fails.
|
|
21
|
+
*/
|
|
22
|
+
getStateAtVersion(versionId: string): Promise<any>;
|
|
23
|
+
/**
|
|
24
|
+
* Loads the list of original client changes that were included in a specific version.
|
|
25
|
+
* Useful for replaying/scrubbing through the operations within an offline or online session.
|
|
26
|
+
* @param versionId - The unique ID of the version.
|
|
27
|
+
* @returns An array of Change objects.
|
|
28
|
+
* @throws Error if the version ID is not found or change loading fails.
|
|
29
|
+
*/
|
|
30
|
+
getChangesForVersion(versionId: string): Promise<Change[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Lists committed server changes for the document, typically used for server-side processing
|
|
33
|
+
* or deep history analysis based on raw revisions.
|
|
34
|
+
* @param options - Options like start/end revision, limit.
|
|
35
|
+
* @returns The list of committed Change objects.
|
|
36
|
+
*/
|
|
37
|
+
listServerChanges(options?: {
|
|
38
|
+
limit?: number;
|
|
39
|
+
startAfterRev?: number;
|
|
40
|
+
endBeforeRev?: number;
|
|
41
|
+
reverse?: boolean;
|
|
42
|
+
}): Promise<Change[]>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helps retrieve historical information (versions, changes) for a document
|
|
3
|
+
* using the new versioning model based on IDs and metadata.
|
|
4
|
+
*/
|
|
5
|
+
export class PatchesHistoryManager {
|
|
6
|
+
constructor(docId, store) {
|
|
7
|
+
this.docId = docId;
|
|
8
|
+
this.store = store;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Lists version metadata for the document, supporting various filters.
|
|
12
|
+
* @param options Filtering and sorting options (e.g., limit, reverse, origin, groupId, date range).
|
|
13
|
+
* @returns A list of version metadata objects.
|
|
14
|
+
*/
|
|
15
|
+
async listVersions(options = {}) {
|
|
16
|
+
return await this.store.listVersions(this.docId, options);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Loads the full document state snapshot for a specific version by its ID.
|
|
20
|
+
* @param versionId - The unique ID of the version.
|
|
21
|
+
* @returns The document state at that version.
|
|
22
|
+
* @throws Error if the version ID is not found or state loading fails.
|
|
23
|
+
*/
|
|
24
|
+
async getStateAtVersion(versionId) {
|
|
25
|
+
try {
|
|
26
|
+
return await this.store.loadVersionState(this.docId, versionId);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error(`Failed to load state for version ${versionId} of doc ${this.docId}.`, error);
|
|
30
|
+
throw new Error(`Could not load state for version ${versionId}.`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Loads the list of original client changes that were included in a specific version.
|
|
35
|
+
* Useful for replaying/scrubbing through the operations within an offline or online session.
|
|
36
|
+
* @param versionId - The unique ID of the version.
|
|
37
|
+
* @returns An array of Change objects.
|
|
38
|
+
* @throws Error if the version ID is not found or change loading fails.
|
|
39
|
+
*/
|
|
40
|
+
async getChangesForVersion(versionId) {
|
|
41
|
+
try {
|
|
42
|
+
return await this.store.loadVersionChanges(this.docId, versionId);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
console.error(`Failed to load changes for version ${versionId} of doc ${this.docId}.`, error);
|
|
46
|
+
throw new Error(`Could not load changes for version ${versionId}.`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Lists committed server changes for the document, typically used for server-side processing
|
|
51
|
+
* or deep history analysis based on raw revisions.
|
|
52
|
+
* @param options - Options like start/end revision, limit.
|
|
53
|
+
* @returns The list of committed Change objects.
|
|
54
|
+
*/
|
|
55
|
+
async listServerChanges(options = {}) {
|
|
56
|
+
// Added return type
|
|
57
|
+
return await this.store.listChanges(this.docId, options);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { Change, ListVersionsOptions, PatchesSnapshot, PatchesState, PatchesStoreBackend, VersionMetadata } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for the PatchesServer.
|
|
4
|
+
*/
|
|
5
|
+
export interface PatchesServerOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The maximum time difference in minutes between consecutive changes
|
|
8
|
+
* to be considered part of the same editing session for versioning.
|
|
9
|
+
* Defaults to 30 minutes.
|
|
10
|
+
*/
|
|
11
|
+
sessionTimeoutMinutes?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Handles the server-side Operational Transformation (OT) logic,
|
|
15
|
+
* coordinating batches of changes, managing versioning based on sessions (including offline),
|
|
16
|
+
* and persisting data using a backend store.
|
|
17
|
+
*/
|
|
18
|
+
export declare class PatchesServer {
|
|
19
|
+
private readonly store;
|
|
20
|
+
private readonly sessionTimeoutMillis;
|
|
21
|
+
constructor(store: PatchesStoreBackend, options?: PatchesServerOptions);
|
|
22
|
+
/**
|
|
23
|
+
* Subscribes the connected client to one or more documents.
|
|
24
|
+
* @param ids Document ID(s) to subscribe to.
|
|
25
|
+
* @returns A list of document IDs the client is now successfully subscribed to.
|
|
26
|
+
*/
|
|
27
|
+
subscribe(clientId: string, ids: string | string[]): Promise<string[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Unsubscribes the connected client from one or more documents.
|
|
30
|
+
* @param ids Document ID(s) to unsubscribe from.
|
|
31
|
+
*/
|
|
32
|
+
unsubscribe(clientId: string, ids: string | string[]): Promise<string[]>;
|
|
33
|
+
/**
|
|
34
|
+
* Get the latest version of a document and changes since the last version.
|
|
35
|
+
* @param docId - The ID of the document.
|
|
36
|
+
* @returns The latest version of the document and changes since the last version.
|
|
37
|
+
*/
|
|
38
|
+
getDoc(docId: string, atRev?: number): Promise<PatchesSnapshot>;
|
|
39
|
+
/**
|
|
40
|
+
* Get changes that occurred after a specific revision.
|
|
41
|
+
* @param docId - The ID of the document.
|
|
42
|
+
* @param rev - The revision number.
|
|
43
|
+
* @returns The changes that occurred after the specified revision.
|
|
44
|
+
*/
|
|
45
|
+
getChangesSince(docId: string, rev: number): Promise<Change[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Commits a set of changes to a document, applying operational transformation as needed.
|
|
48
|
+
* @param docId - The ID of the document.
|
|
49
|
+
* @param changes - The changes to commit.
|
|
50
|
+
* @returns A tuple of [committedChanges, transformedChanges] where:
|
|
51
|
+
* - committedChanges: Changes that were already committed to the server after the client's base revision
|
|
52
|
+
* - transformedChanges: The client's changes after being transformed against concurrent changes
|
|
53
|
+
*/
|
|
54
|
+
commitChanges(docId: string, changes: Change[]): Promise<[Change[], Change[]]>;
|
|
55
|
+
/**
|
|
56
|
+
* Handles offline/large batch versioning logic for multi-batch uploads.
|
|
57
|
+
* Groups changes into sessions, merges with previous batch if needed, and creates/extends versions.
|
|
58
|
+
* @param docId Document ID
|
|
59
|
+
* @param changes The incoming changes (all with the same batchId)
|
|
60
|
+
* @param baseRev The base revision for the batch
|
|
61
|
+
* @param batchId The batch identifier
|
|
62
|
+
* @returns The collapsed changes for transformation
|
|
63
|
+
*/
|
|
64
|
+
private handleOfflineBatches;
|
|
65
|
+
/**
|
|
66
|
+
* Deletes a document.
|
|
67
|
+
* @param docId The document ID.
|
|
68
|
+
*/
|
|
69
|
+
deleteDoc(docId: string): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Create a new named version snapshot of a document's current state.
|
|
72
|
+
* @param docId The document ID.
|
|
73
|
+
* @param name The name of the version.
|
|
74
|
+
* @returns The ID of the created version.
|
|
75
|
+
*/
|
|
76
|
+
createVersion(docId: string, name: string): Promise<string>;
|
|
77
|
+
/**
|
|
78
|
+
* Lists version metadata for a document, supporting various filters.
|
|
79
|
+
* @param docId The document ID.
|
|
80
|
+
* @param options Filtering and sorting options.
|
|
81
|
+
* @returns A list of version metadata objects.
|
|
82
|
+
*/
|
|
83
|
+
listVersions(docId: string, options: ListVersionsOptions): Promise<VersionMetadata[]>;
|
|
84
|
+
/**
|
|
85
|
+
* Get the state snapshot for a specific version ID.
|
|
86
|
+
* @param docId The document ID.
|
|
87
|
+
* @param versionId The ID of the version.
|
|
88
|
+
* @returns The state snapshot for the specified version.
|
|
89
|
+
*/
|
|
90
|
+
getVersionState(docId: string, versionId: string): Promise<PatchesState>;
|
|
91
|
+
/**
|
|
92
|
+
* Get the original Change objects associated with a specific version ID.
|
|
93
|
+
* @param docId The document ID.
|
|
94
|
+
* @param versionId The ID of the version.
|
|
95
|
+
* @returns The original Change objects for the specified version.
|
|
96
|
+
*/
|
|
97
|
+
getVersionChanges(docId: string, versionId: string): Promise<Change[]>;
|
|
98
|
+
/**
|
|
99
|
+
* Update the name of a specific version.
|
|
100
|
+
* @param docId The document ID.
|
|
101
|
+
* @param versionId The ID of the version.
|
|
102
|
+
* @param name The new name for the version.
|
|
103
|
+
*/
|
|
104
|
+
updateVersion(docId: string, versionId: string, name: string): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Retrieves the document state of the version before the given revision and changes after up to that revision or all
|
|
107
|
+
* changes since that version.
|
|
108
|
+
* @param docId The document ID.
|
|
109
|
+
* @param rev The revision number. If not provided, the latest state, its revision, and all changes since are returned.
|
|
110
|
+
* @returns The document state at the last version before the revision, its revision number, and all changes up to the specified revision (or all changes if no revision is provided).
|
|
111
|
+
*/
|
|
112
|
+
_getSnapshotAtRevision(docId: string, rev?: number): Promise<PatchesSnapshot>;
|
|
113
|
+
/**
|
|
114
|
+
* Gets the state at a specific revision.
|
|
115
|
+
* @param docId The document ID.
|
|
116
|
+
* @param rev The revision number. If not provided, the latest state and its revision is returned.
|
|
117
|
+
* @returns The state at the specified revision *and* its revision number.
|
|
118
|
+
*/
|
|
119
|
+
_getStateAtRevision(docId: string, rev?: number): Promise<PatchesState>;
|
|
120
|
+
/**
|
|
121
|
+
* Creates a new version snapshot of a document's current state.
|
|
122
|
+
* @param docId The document ID.
|
|
123
|
+
* @param state The document state at the time of the version.
|
|
124
|
+
* @param changes The changes since the last version that created the state (the last change's rev is the state's rev and will be the version's rev).
|
|
125
|
+
* @param name The name of the version.
|
|
126
|
+
* @returns The ID of the created version.
|
|
127
|
+
*/
|
|
128
|
+
_createVersion(docId: string, state: any, changes: Change[], name?: string): Promise<VersionMetadata | undefined>;
|
|
129
|
+
}
|