@dabble/patches 0.2.32 → 0.3.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/dist/algorithms/client/applyCommittedChanges.d.ts +8 -0
- package/dist/algorithms/client/applyCommittedChanges.js +40 -0
- package/dist/{utils → algorithms/client}/batching.d.ts +1 -1
- package/dist/{utils → algorithms/client}/batching.js +2 -2
- package/dist/{utils → algorithms/client}/breakChange.d.ts +2 -3
- package/dist/algorithms/client/breakChange.js +258 -0
- package/dist/algorithms/client/createStateFromSnapshot.d.ts +7 -0
- package/dist/algorithms/client/createStateFromSnapshot.js +9 -0
- package/dist/algorithms/client/getJSONByteSize.js +12 -0
- package/dist/algorithms/client/makeChange.d.ts +3 -0
- package/dist/algorithms/client/makeChange.js +37 -0
- package/dist/algorithms/server/commitChanges.d.ts +12 -0
- package/dist/algorithms/server/commitChanges.js +80 -0
- package/dist/algorithms/server/createVersion.d.ts +12 -0
- package/dist/algorithms/server/createVersion.js +28 -0
- package/dist/algorithms/server/getSnapshotAtRevision.d.ts +10 -0
- package/dist/algorithms/server/getSnapshotAtRevision.js +29 -0
- package/dist/algorithms/server/getStateAtRevision.d.ts +9 -0
- package/dist/algorithms/server/getStateAtRevision.js +18 -0
- package/dist/algorithms/server/handleOfflineSessionsAndBatches.d.ts +12 -0
- package/dist/algorithms/server/handleOfflineSessionsAndBatches.js +80 -0
- package/dist/algorithms/server/transformIncomingChanges.d.ts +11 -0
- package/dist/algorithms/server/transformIncomingChanges.js +40 -0
- package/dist/algorithms/shared/applyChanges.d.ts +10 -0
- package/dist/algorithms/shared/applyChanges.js +17 -0
- package/dist/{utils.d.ts → algorithms/shared/rebaseChanges.d.ts} +1 -11
- package/dist/{utils.js → algorithms/shared/rebaseChanges.js} +3 -43
- package/dist/client/InMemoryStore.d.ts +2 -1
- package/dist/client/InMemoryStore.js +9 -3
- package/dist/client/IndexedDBStore.d.ts +34 -2
- package/dist/client/IndexedDBStore.js +399 -282
- package/dist/client/Patches.d.ts +11 -41
- package/dist/client/Patches.js +197 -208
- package/dist/client/PatchesDoc.d.ts +24 -41
- package/dist/client/PatchesDoc.js +57 -214
- package/dist/client/PatchesHistoryClient.js +1 -1
- package/dist/client/PatchesStore.d.ts +186 -9
- package/dist/data/change.d.ts +3 -0
- package/dist/data/change.js +20 -0
- package/dist/data/version.d.ts +12 -0
- package/dist/data/version.js +17 -0
- package/dist/json-patch/ops/add.js +1 -1
- package/dist/json-patch/ops/move.js +1 -1
- package/dist/json-patch/ops/remove.js +1 -1
- package/dist/json-patch/ops/replace.js +1 -1
- package/dist/json-patch/utils/get.js +0 -1
- package/dist/json-patch/utils/log.d.ts +4 -1
- package/dist/json-patch/utils/log.js +2 -5
- package/dist/json-patch/utils/ops.d.ts +1 -1
- package/dist/json-patch/utils/ops.js +4 -1
- package/dist/json-patch/utils/paths.js +2 -2
- package/dist/json-patch/utils/toArrayIndex.js +1 -1
- package/dist/net/PatchesSync.d.ts +55 -24
- package/dist/net/PatchesSync.js +336 -258
- package/dist/net/protocol/types.d.ts +1 -1
- package/dist/net/websocket/AuthorizationProvider.d.ts +9 -2
- package/dist/net/websocket/AuthorizationProvider.js +14 -2
- package/dist/net/websocket/PatchesWebSocket.d.ts +2 -2
- package/dist/net/websocket/PatchesWebSocket.js +3 -2
- package/dist/net/websocket/RPCServer.d.ts +2 -2
- package/dist/net/websocket/RPCServer.js +3 -3
- package/dist/net/websocket/SignalingService.js +1 -1
- package/dist/net/websocket/WebSocketServer.d.ts +1 -1
- package/dist/net/websocket/WebSocketServer.js +2 -2
- package/dist/net/websocket/WebSocketTransport.js +1 -1
- package/dist/net/websocket/onlineState.d.ts +2 -2
- package/dist/net/websocket/onlineState.js +9 -3
- package/dist/server/PatchesBranchManager.js +9 -16
- package/dist/server/PatchesHistoryManager.js +1 -1
- package/dist/server/PatchesServer.d.ts +11 -38
- package/dist/server/PatchesServer.js +32 -255
- package/dist/server/index.d.ts +4 -4
- package/dist/server/index.js +3 -3
- package/dist/server/types.d.ts +1 -1
- package/dist/types.d.ts +8 -6
- package/dist/utils/concurrency.d.ts +26 -0
- package/dist/utils/concurrency.js +60 -0
- package/dist/utils/deferred.d.ts +7 -0
- package/dist/utils/deferred.js +23 -0
- package/package.json +11 -5
- package/dist/utils/breakChange.js +0 -302
- package/dist/utils/getJSONByteSize.js +0 -12
- /package/dist/{utils → algorithms/client}/getJSONByteSize.d.ts +0 -0
|
@@ -6,7 +6,7 @@ export declare function isAdd(state: State, op: JSONPatchOp, pathName: 'from' |
|
|
|
6
6
|
/**
|
|
7
7
|
* Transforms an array of ops, returning the original if there is no change, filtering out ops that are dropped.
|
|
8
8
|
*/
|
|
9
|
-
export declare function mapAndFilterOps(ops: JSONPatchOp[], iterator: (op: JSONPatchOp, index: number, breakAfter: (keepRest?: boolean) =>
|
|
9
|
+
export declare function mapAndFilterOps(ops: JSONPatchOp[], iterator: (op: JSONPatchOp, index: number, breakAfter: (keepRest?: boolean) => void) => JSONPatchOp | JSONPatchOp[] | null): JSONPatchOp[];
|
|
10
10
|
/**
|
|
11
11
|
* Remove operations that apply to a value which was removed.
|
|
12
12
|
*/
|
|
@@ -17,7 +17,10 @@ export function mapAndFilterOps(ops, iterator) {
|
|
|
17
17
|
const mapped = [];
|
|
18
18
|
let shouldBreak = false;
|
|
19
19
|
let keepRest;
|
|
20
|
-
const breakAfter = (keep) =>
|
|
20
|
+
const breakAfter = (keep) => {
|
|
21
|
+
shouldBreak = true;
|
|
22
|
+
keepRest = keep;
|
|
23
|
+
};
|
|
21
24
|
for (let i = 0; i < ops.length; i++) {
|
|
22
25
|
const original = ops[i];
|
|
23
26
|
// If an op was copied or moved to the same path, it is a no-op and should be removed
|
|
@@ -23,7 +23,7 @@ export function isArrayPath(path, state) {
|
|
|
23
23
|
if (!state || !state.root || !state.root[''])
|
|
24
24
|
return true;
|
|
25
25
|
// Double-check if this is an array or not
|
|
26
|
-
const [
|
|
26
|
+
const [, , target] = getOpData(state, path);
|
|
27
27
|
return Array.isArray(target) || target == null;
|
|
28
28
|
}
|
|
29
29
|
export function getArrayPrefixAndIndex(state, path, pathLength) {
|
|
@@ -31,7 +31,7 @@ export function getArrayPrefixAndIndex(state, path, pathLength) {
|
|
|
31
31
|
path = path.slice(0, path.indexOf('/', pathLength));
|
|
32
32
|
if (!arrayPathExp.test(path))
|
|
33
33
|
return EMPTY;
|
|
34
|
-
const [
|
|
34
|
+
const [, , target] = getOpData(state, path);
|
|
35
35
|
if (!Array.isArray(target))
|
|
36
36
|
return EMPTY;
|
|
37
37
|
const [prefix, indexStr] = getPrefixAndProp(path);
|
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
import { Patches } from '../client/Patches.js';
|
|
2
|
+
import type { Change, SyncingState } from '../types.js';
|
|
3
|
+
import type { ConnectionState } from './protocol/types.js';
|
|
2
4
|
import type { WebSocketOptions } from './websocket/WebSocketTransport.js';
|
|
3
|
-
export interface PatchesSyncOptions {
|
|
4
|
-
/** WebSocket connection options */
|
|
5
|
-
wsOptions?: WebSocketOptions;
|
|
6
|
-
/**
|
|
7
|
-
* Maximum size in bytes for a single payload (network message).
|
|
8
|
-
* Changes exceeding this will be automatically split.
|
|
9
|
-
*/
|
|
10
|
-
maxPayloadBytes?: number;
|
|
11
|
-
}
|
|
12
5
|
export interface PatchesSyncState {
|
|
13
6
|
online: boolean;
|
|
14
7
|
connected: boolean;
|
|
15
|
-
syncing:
|
|
8
|
+
syncing: SyncingState;
|
|
16
9
|
}
|
|
17
10
|
/**
|
|
18
11
|
* Handles WebSocket connection, document subscriptions, and syncing logic between
|
|
@@ -22,31 +15,69 @@ export declare class PatchesSync {
|
|
|
22
15
|
private ws;
|
|
23
16
|
private patches;
|
|
24
17
|
private store;
|
|
25
|
-
private
|
|
18
|
+
private maxPayloadBytes?;
|
|
26
19
|
private trackedDocs;
|
|
27
|
-
private isFlushing;
|
|
28
|
-
private globalSyncTimeout;
|
|
29
20
|
private _state;
|
|
21
|
+
/**
|
|
22
|
+
* Signal emitted when the sync state changes.
|
|
23
|
+
*/
|
|
30
24
|
readonly onStateChange: import("../event-signal.js").Signal<(state: PatchesSyncState) => void>;
|
|
25
|
+
/**
|
|
26
|
+
* Signal emitted when an error occurs.
|
|
27
|
+
*/
|
|
31
28
|
readonly onError: import("../event-signal.js").Signal<(error: Error, context?: {
|
|
32
29
|
docId?: string;
|
|
33
30
|
}) => void>;
|
|
34
|
-
constructor(
|
|
31
|
+
constructor(patches: Patches, url: string, wsOptions?: WebSocketOptions);
|
|
32
|
+
/**
|
|
33
|
+
* Gets the current sync state.
|
|
34
|
+
*/
|
|
35
35
|
get state(): PatchesSyncState;
|
|
36
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Updates the sync state.
|
|
38
|
+
* @param update - The partial state to update.
|
|
39
|
+
*/
|
|
40
|
+
protected updateState(update: Partial<PatchesSyncState>): void;
|
|
41
|
+
/**
|
|
42
|
+
* Connects to the WebSocket server and starts syncing if online. If not online, it will wait for online state.
|
|
43
|
+
*/
|
|
37
44
|
connect(): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Disconnects from the WebSocket server and stops syncing.
|
|
47
|
+
*/
|
|
38
48
|
disconnect(): void;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Syncs all known docs when initially connected.
|
|
51
|
+
*/
|
|
52
|
+
protected syncAllKnownDocs(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Syncs a single document.
|
|
55
|
+
* @param docId The ID of the document to sync.
|
|
56
|
+
*/
|
|
57
|
+
protected syncDoc(docId: string): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Flushes a document to the server.
|
|
60
|
+
* @param docId The ID of the document to flush.
|
|
61
|
+
*/
|
|
62
|
+
protected flushDoc(docId: string): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Receives committed changes from the server and applies them to the document. This is a blockable function, so it
|
|
65
|
+
* is separate from applyServerChangesToDoc, which is called by other blockable functions. Ensuring this is blockable
|
|
66
|
+
* ensures that while a doc is sending changes to the server, it isn't receiving changes from the server which could
|
|
67
|
+
* cause a race condition.
|
|
68
|
+
*/
|
|
69
|
+
protected _receiveCommittedChanges(docId: string, serverChanges: Change[]): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Applies server changes to a document using the centralized sync algorithm.
|
|
72
|
+
* This ensures consistent OT behavior regardless of whether the doc is open in memory.
|
|
73
|
+
*/
|
|
74
|
+
protected _applyServerChangesToDoc(docId: string, serverChanges: Change[], sentPendingRange?: [number, number]): Promise<void>;
|
|
43
75
|
/**
|
|
44
76
|
* Initiates the deletion process for a document both locally and on the server.
|
|
45
77
|
* This now delegates the local tombstone marking to Patches.
|
|
46
78
|
*/
|
|
47
|
-
_handleDocDeleted(docId: string): Promise<void>;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
private _handleDocsUntracked;
|
|
79
|
+
protected _handleDocDeleted(docId: string): Promise<void>;
|
|
80
|
+
protected _handleConnectionChange(connectionState: ConnectionState): void;
|
|
81
|
+
protected _handleDocsTracked(docIds: string[]): Promise<void>;
|
|
82
|
+
protected _handleDocsUntracked(docIds: string[]): Promise<void>;
|
|
52
83
|
}
|