@dabble/patches 0.7.21 → 0.7.23
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/lww/consolidateOps.js +2 -0
- package/dist/algorithms/ot/client/applyCommittedChanges.js +1 -7
- package/dist/algorithms/ot/server/buildVersionState.d.ts +51 -0
- package/dist/algorithms/ot/server/buildVersionState.js +67 -0
- package/dist/algorithms/ot/server/commitChanges.d.ts +16 -14
- package/dist/algorithms/ot/server/commitChanges.js +58 -75
- package/dist/algorithms/ot/server/createVersion.d.ts +36 -7
- package/dist/algorithms/ot/server/createVersion.js +24 -5
- package/dist/algorithms/ot/server/getSnapshotAtRevision.d.ts +13 -1
- package/dist/algorithms/ot/server/getSnapshotAtRevision.js +20 -9
- package/dist/algorithms/ot/server/handleOfflineSessionsAndBatches.d.ts +11 -11
- package/dist/algorithms/ot/server/handleOfflineSessionsAndBatches.js +14 -52
- package/dist/algorithms/ot/server/transformIncomingChanges.d.ts +4 -3
- package/dist/algorithms/ot/server/transformIncomingChanges.js +2 -16
- package/dist/algorithms/ot/shared/applyChanges.js +5 -1
- package/dist/client/LWWInMemoryStore.js +4 -0
- package/dist/client/LWWIndexedDBStore.js +7 -0
- package/dist/client/Patches.js +5 -2
- package/dist/net/PatchesClient.d.ts +4 -1
- package/dist/net/PatchesSync.js +14 -3
- package/dist/net/protocol/JSONRPCServer.js +15 -0
- package/dist/net/protocol/types.d.ts +5 -2
- package/dist/server/CompressedStoreBackend.d.ts +4 -3
- package/dist/server/CompressedStoreBackend.js +8 -13
- package/dist/server/LWWBranchManager.js +12 -3
- package/dist/server/LWWMemoryStoreBackend.d.ts +5 -8
- package/dist/server/LWWMemoryStoreBackend.js +11 -6
- package/dist/server/LWWServer.d.ts +16 -15
- package/dist/server/LWWServer.js +28 -27
- package/dist/server/OTBranchManager.js +9 -6
- package/dist/server/OTServer.d.ts +23 -19
- package/dist/server/OTServer.js +31 -27
- package/dist/server/PatchesHistoryManager.d.ts +23 -4
- package/dist/server/PatchesHistoryManager.js +40 -4
- package/dist/server/PatchesServer.d.ts +25 -9
- package/dist/server/RevConflictError.d.ts +13 -0
- package/dist/server/RevConflictError.js +10 -0
- package/dist/server/index.d.ts +5 -1
- package/dist/server/index.js +15 -0
- package/dist/server/jsonReadable.d.ts +22 -0
- package/dist/server/jsonReadable.js +68 -0
- package/dist/server/types.d.ts +30 -16
- package/package.json +1 -1
package/dist/server/index.d.ts
CHANGED
|
@@ -5,13 +5,17 @@ export { LWWBranchManager } from './LWWBranchManager.js';
|
|
|
5
5
|
export { OTBranchManager, PatchesBranchManager } from './OTBranchManager.js';
|
|
6
6
|
export { LWWMemoryStoreBackend } from './LWWMemoryStoreBackend.js';
|
|
7
7
|
export { PatchesHistoryManager } from './PatchesHistoryManager.js';
|
|
8
|
+
export { buildVersionState, getBaseStateBeforeVersion } from '../algorithms/ot/server/buildVersionState.js';
|
|
9
|
+
export { concatStreams, jsonReadable, parseVersionState, readStreamAsString } from './jsonReadable.js';
|
|
10
|
+
export { blockable, blockableResponse, blocking, singleInvocation } from '../utils/concurrency.js';
|
|
11
|
+
export { RevConflictError } from './RevConflictError.js';
|
|
8
12
|
export { BranchIdGenerator, BranchLoader, assertBranchMetadata, assertBranchOpenForMerge, assertNotABranch, branchManagerApi, createBranchRecord, generateBranchId, wrapMergeCommit } from './branchUtils.js';
|
|
9
13
|
export { CompressedStoreBackend } from './CompressedStoreBackend.js';
|
|
10
14
|
export { createTombstoneIfSupported, isTombstoneStore, removeTombstoneIfExists } from './tombstone.js';
|
|
11
15
|
export { assertVersionMetadata } from './utils.js';
|
|
12
16
|
export { CommitChangesOptions, DeleteDocOptions } from '../types.js';
|
|
13
17
|
export { PatchesServer } from './PatchesServer.js';
|
|
14
|
-
export { BranchingStoreBackend, LWWStoreBackend, ListFieldsOptions, OTStoreBackend, ServerStoreBackend, TombstoneStoreBackend, VersioningStoreBackend } from './types.js';
|
|
18
|
+
export { BranchingStoreBackend, LWWStoreBackend, ListFieldsOptions, OTStoreBackend, ServerStoreBackend, SnapshotResult, TombstoneStoreBackend, VersioningStoreBackend } from './types.js';
|
|
15
19
|
import 'easy-signal';
|
|
16
20
|
import '../net/protocol/JSONRPCServer.js';
|
|
17
21
|
import '../net/websocket/AuthorizationProvider.js';
|
package/dist/server/index.js
CHANGED
|
@@ -5,6 +5,10 @@ import { LWWBranchManager } from "./LWWBranchManager.js";
|
|
|
5
5
|
import { OTBranchManager, PatchesBranchManager } from "./OTBranchManager.js";
|
|
6
6
|
import { LWWMemoryStoreBackend } from "./LWWMemoryStoreBackend.js";
|
|
7
7
|
import { PatchesHistoryManager } from "./PatchesHistoryManager.js";
|
|
8
|
+
import { buildVersionState, getBaseStateBeforeVersion } from "../algorithms/ot/server/buildVersionState.js";
|
|
9
|
+
import { concatStreams, jsonReadable, parseVersionState, readStreamAsString } from "./jsonReadable.js";
|
|
10
|
+
import { blockable, blockableResponse, blocking, singleInvocation } from "../utils/concurrency.js";
|
|
11
|
+
import { RevConflictError } from "./RevConflictError.js";
|
|
8
12
|
import {
|
|
9
13
|
assertBranchMetadata,
|
|
10
14
|
assertBranchOpenForMerge,
|
|
@@ -26,15 +30,26 @@ export {
|
|
|
26
30
|
OTServer,
|
|
27
31
|
PatchesBranchManager,
|
|
28
32
|
PatchesHistoryManager,
|
|
33
|
+
RevConflictError,
|
|
29
34
|
assertBranchMetadata,
|
|
30
35
|
assertBranchOpenForMerge,
|
|
31
36
|
assertNotABranch,
|
|
32
37
|
assertVersionMetadata,
|
|
38
|
+
blockable,
|
|
39
|
+
blockableResponse,
|
|
40
|
+
blocking,
|
|
33
41
|
branchManagerApi,
|
|
42
|
+
buildVersionState,
|
|
43
|
+
concatStreams,
|
|
34
44
|
createBranchRecord,
|
|
35
45
|
createTombstoneIfSupported,
|
|
36
46
|
generateBranchId,
|
|
47
|
+
getBaseStateBeforeVersion,
|
|
37
48
|
isTombstoneStore,
|
|
49
|
+
jsonReadable,
|
|
50
|
+
parseVersionState,
|
|
51
|
+
readStreamAsString,
|
|
38
52
|
removeTombstoneIfExists,
|
|
53
|
+
singleInvocation,
|
|
39
54
|
wrapMergeCommit
|
|
40
55
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a ReadableStream that emits a single string chunk.
|
|
3
|
+
*/
|
|
4
|
+
declare function jsonReadable(json: string): ReadableStream<string>;
|
|
5
|
+
/**
|
|
6
|
+
* Concatenates strings and ReadableStreams into a single ReadableStream.
|
|
7
|
+
* Each source is consumed in order. Backpressure propagates naturally:
|
|
8
|
+
* each stream source is only read when the previous one has been fully consumed.
|
|
9
|
+
*/
|
|
10
|
+
declare function concatStreams(...sources: (string | ReadableStream<string>)[]): ReadableStream<string>;
|
|
11
|
+
/**
|
|
12
|
+
* Parses a version state from store format (string or ReadableStream) into a JS object.
|
|
13
|
+
* Only use in non-hot-path code (explicit operations like captureCurrentVersion, createBranch).
|
|
14
|
+
*/
|
|
15
|
+
declare function parseVersionState(raw: string | ReadableStream<string>): Promise<any>;
|
|
16
|
+
/**
|
|
17
|
+
* Consumes a ReadableStream<string> into a single string.
|
|
18
|
+
* Only use in non-hot-path code (explicit operations like captureCurrentVersion).
|
|
19
|
+
*/
|
|
20
|
+
declare function readStreamAsString(stream: ReadableStream<string>): Promise<string>;
|
|
21
|
+
|
|
22
|
+
export { concatStreams, jsonReadable, parseVersionState, readStreamAsString };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import "../chunk-IZ2YBCUP.js";
|
|
2
|
+
function jsonReadable(json) {
|
|
3
|
+
return new ReadableStream({
|
|
4
|
+
start(controller) {
|
|
5
|
+
controller.enqueue(json);
|
|
6
|
+
controller.close();
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
function concatStreams(...sources) {
|
|
11
|
+
let index = 0;
|
|
12
|
+
let currentReader = null;
|
|
13
|
+
return new ReadableStream({
|
|
14
|
+
async pull(controller) {
|
|
15
|
+
while (index < sources.length) {
|
|
16
|
+
const source = sources[index];
|
|
17
|
+
if (typeof source === "string") {
|
|
18
|
+
controller.enqueue(source);
|
|
19
|
+
index++;
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (!currentReader) {
|
|
23
|
+
currentReader = source.getReader();
|
|
24
|
+
}
|
|
25
|
+
const { done, value } = await currentReader.read();
|
|
26
|
+
if (!done) {
|
|
27
|
+
controller.enqueue(value);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
currentReader = null;
|
|
31
|
+
index++;
|
|
32
|
+
}
|
|
33
|
+
controller.close();
|
|
34
|
+
},
|
|
35
|
+
cancel(reason) {
|
|
36
|
+
if (currentReader) {
|
|
37
|
+
currentReader.cancel(reason);
|
|
38
|
+
}
|
|
39
|
+
const start = currentReader ? index + 1 : index;
|
|
40
|
+
for (let i = start; i < sources.length; i++) {
|
|
41
|
+
const s = sources[i];
|
|
42
|
+
if (typeof s !== "string") {
|
|
43
|
+
s.cancel(reason);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
async function parseVersionState(raw) {
|
|
50
|
+
const json = typeof raw === "string" ? raw : await readStreamAsString(raw);
|
|
51
|
+
return JSON.parse(json);
|
|
52
|
+
}
|
|
53
|
+
async function readStreamAsString(stream) {
|
|
54
|
+
const reader = stream.getReader();
|
|
55
|
+
const chunks = [];
|
|
56
|
+
for (; ; ) {
|
|
57
|
+
const { done, value } = await reader.read();
|
|
58
|
+
if (done) break;
|
|
59
|
+
chunks.push(value);
|
|
60
|
+
}
|
|
61
|
+
return chunks.join("");
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
concatStreams,
|
|
65
|
+
jsonReadable,
|
|
66
|
+
parseVersionState,
|
|
67
|
+
readStreamAsString
|
|
68
|
+
};
|
package/dist/server/types.d.ts
CHANGED
|
@@ -17,24 +17,26 @@ interface ServerStoreBackend {
|
|
|
17
17
|
*/
|
|
18
18
|
interface VersioningStoreBackend {
|
|
19
19
|
/**
|
|
20
|
-
* Saves version metadata
|
|
21
|
-
*
|
|
20
|
+
* Saves version metadata and optionally the original changes.
|
|
21
|
+
* Implementations are responsible for building and persisting version state —
|
|
22
|
+
* inline or queued, but must throw if state creation fails.
|
|
22
23
|
* @param changes - Optional for LWW (which doesn't store changes), required for OT.
|
|
23
24
|
*/
|
|
24
|
-
createVersion(docId: string, metadata: VersionMetadata,
|
|
25
|
+
createVersion(docId: string, metadata: VersionMetadata, changes?: Change[]): Promise<void>;
|
|
25
26
|
/** Lists version metadata based on filtering/sorting options. */
|
|
26
27
|
listVersions(docId: string, options: ListVersionsOptions): Promise<VersionMetadata[]>;
|
|
27
|
-
/** Loads
|
|
28
|
-
|
|
28
|
+
/** Loads metadata for a specific version by its ID. */
|
|
29
|
+
loadVersion(docId: string, versionId: string): Promise<VersionMetadata | undefined>;
|
|
30
|
+
/**
|
|
31
|
+
* Loads the state snapshot for a specific version ID.
|
|
32
|
+
* Returns a JSON string, ReadableStream of JSON chunks, or undefined if not found.
|
|
33
|
+
* ReadableStream allows large state blobs to be streamed without full materialization.
|
|
34
|
+
*/
|
|
35
|
+
loadVersionState(docId: string, versionId: string): Promise<string | ReadableStream<string> | undefined>;
|
|
29
36
|
/** Update a version's metadata. */
|
|
30
37
|
updateVersion(docId: string, versionId: string, metadata: EditableVersionMetadata): Promise<void>;
|
|
31
38
|
/** Loads the original Change objects associated with a specific version ID. */
|
|
32
39
|
loadVersionChanges?(docId: string, versionId: string): Promise<Change[]>;
|
|
33
|
-
/**
|
|
34
|
-
* Appends changes to an existing version, updating its state snapshot, endedAt, and endRev.
|
|
35
|
-
* Used when a session spans multiple batch submissions.
|
|
36
|
-
*/
|
|
37
|
-
appendVersionChanges?(docId: string, versionId: string, changes: Change[], newEndedAt: number, newEndRev: number, newState: any): Promise<void>;
|
|
38
40
|
}
|
|
39
41
|
/**
|
|
40
42
|
* Interface for OT (Operational Transformation) storage backend.
|
|
@@ -42,6 +44,12 @@ interface VersioningStoreBackend {
|
|
|
42
44
|
* for session tracking and state snapshots.
|
|
43
45
|
*/
|
|
44
46
|
interface OTStoreBackend extends ServerStoreBackend, VersioningStoreBackend {
|
|
47
|
+
/**
|
|
48
|
+
* Get the current revision number without loading state.
|
|
49
|
+
* @param docId - The document ID.
|
|
50
|
+
* @returns The current revision number, or 0 if document doesn't exist.
|
|
51
|
+
*/
|
|
52
|
+
getCurrentRev(docId: string): Promise<number>;
|
|
45
53
|
/** Saves a batch of committed server changes. */
|
|
46
54
|
saveChanges(docId: string, changes: Change[]): Promise<void>;
|
|
47
55
|
/** Lists committed server changes based on revision numbers. */
|
|
@@ -55,6 +63,14 @@ type ListFieldsOptions = {
|
|
|
55
63
|
} | {
|
|
56
64
|
paths: string[];
|
|
57
65
|
};
|
|
66
|
+
/**
|
|
67
|
+
* Result from LWW getSnapshot. State is a ReadableStream so large snapshots
|
|
68
|
+
* can be streamed to clients without full materialization.
|
|
69
|
+
*/
|
|
70
|
+
interface SnapshotResult {
|
|
71
|
+
rev: number;
|
|
72
|
+
state: ReadableStream<string>;
|
|
73
|
+
}
|
|
58
74
|
/**
|
|
59
75
|
* Interface for LWW (Last-Write-Wins) storage backend.
|
|
60
76
|
* LWW stores fields (not changes) and reconstructs state from fields.
|
|
@@ -69,13 +85,11 @@ interface LWWStoreBackend extends ServerStoreBackend {
|
|
|
69
85
|
getCurrentRev(docId: string): Promise<number>;
|
|
70
86
|
/**
|
|
71
87
|
* Get the latest snapshot of document state.
|
|
88
|
+
* State is returned as a ReadableStream so it can be streamed to clients.
|
|
72
89
|
* @param docId - The document ID.
|
|
73
|
-
* @returns The snapshot
|
|
90
|
+
* @returns The snapshot revision and state stream, or null if no snapshot exists.
|
|
74
91
|
*/
|
|
75
|
-
getSnapshot(docId: string): Promise<
|
|
76
|
-
state: any;
|
|
77
|
-
rev: number;
|
|
78
|
-
} | null>;
|
|
92
|
+
getSnapshot(docId: string): Promise<SnapshotResult | null>;
|
|
79
93
|
/**
|
|
80
94
|
* Save a snapshot of document state (overwrites previous snapshot).
|
|
81
95
|
* @param docId - The document ID.
|
|
@@ -150,4 +164,4 @@ interface BranchingStoreBackend {
|
|
|
150
164
|
closeBranch(branchId: string): Promise<void>;
|
|
151
165
|
}
|
|
152
166
|
|
|
153
|
-
export type { BranchingStoreBackend, LWWStoreBackend, ListFieldsOptions, OTStoreBackend, ServerStoreBackend, TombstoneStoreBackend, VersioningStoreBackend };
|
|
167
|
+
export type { BranchingStoreBackend, LWWStoreBackend, ListFieldsOptions, OTStoreBackend, ServerStoreBackend, SnapshotResult, TombstoneStoreBackend, VersioningStoreBackend };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dabble/patches",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.23",
|
|
4
4
|
"description": "Immutable JSON Patch implementation based on RFC 6902 supporting operational transformation and last-writer-wins",
|
|
5
5
|
"author": "Jacob Wright <jacwright@gmail.com>",
|
|
6
6
|
"bugs": {
|