@dabble/patches 0.7.8 → 0.7.10
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/{BaseDoc-_Rsau70J.d.ts → BaseDoc-BfVJNeCi.d.ts} +29 -16
- package/dist/client/BaseDoc.d.ts +1 -1
- package/dist/client/BaseDoc.js +31 -11
- package/dist/client/ClientAlgorithm.d.ts +1 -1
- package/dist/client/LWWAlgorithm.d.ts +1 -1
- package/dist/client/LWWDoc.d.ts +1 -1
- package/dist/client/LWWDoc.js +3 -0
- package/dist/client/OTAlgorithm.d.ts +1 -1
- package/dist/client/OTDoc.d.ts +1 -1
- package/dist/client/OTDoc.js +3 -0
- package/dist/client/Patches.d.ts +1 -1
- package/dist/client/PatchesDoc.d.ts +1 -1
- package/dist/client/factories.d.ts +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/net/PatchesSync.d.ts +42 -4
- package/dist/net/PatchesSync.js +158 -23
- package/dist/net/index.d.ts +4 -3
- package/dist/net/protocol/JSONRPCServer.js +8 -2
- package/dist/shared/doc-manager.d.ts +1 -1
- package/dist/shared/utils.d.ts +11 -1
- package/dist/shared/utils.js +5 -1
- package/dist/solid/context.d.ts +2 -1
- package/dist/solid/doc-manager.d.ts +1 -1
- package/dist/solid/index.d.ts +1 -1
- package/dist/solid/primitives.d.ts +1 -1
- package/dist/solid/primitives.js +53 -13
- package/dist/solid/utils.d.ts +4 -0
- package/dist/types.d.ts +24 -7
- package/dist/vue/composables.d.ts +1 -1
- package/dist/vue/composables.js +37 -14
- package/dist/vue/doc-manager.d.ts +1 -1
- package/dist/vue/index.d.ts +1 -1
- package/dist/vue/managed-docs.d.ts +1 -1
- package/dist/vue/provider.d.ts +2 -1
- package/dist/vue/utils.d.ts +4 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Signal, Unsubscriber } from './event-signal.js';
|
|
2
2
|
import { JSONPatchOp } from './json-patch/types.js';
|
|
3
|
-
import { Change, PatchesSnapshot,
|
|
3
|
+
import { Change, PatchesSnapshot, SyncedDoc, DocSyncStatus, ChangeMutator } from './types.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* OT (Operational Transformation) document implementation.
|
|
@@ -96,9 +96,9 @@ interface PatchesDocOptions {
|
|
|
96
96
|
* This interface is implemented by both OTDoc (Operational Transformation)
|
|
97
97
|
* and LWWDoc (Last-Write-Wins) implementations via BaseDoc.
|
|
98
98
|
*
|
|
99
|
-
* Internal methods (
|
|
99
|
+
* Internal methods (updateSyncStatus, applyChanges, import) are on BaseDoc, not this interface.
|
|
100
100
|
*/
|
|
101
|
-
interface PatchesDoc<T extends object = object> {
|
|
101
|
+
interface PatchesDoc<T extends object = object> extends SyncedDoc {
|
|
102
102
|
/** The unique identifier for this document. */
|
|
103
103
|
readonly id: string;
|
|
104
104
|
/** Current local state (committed + pending merged). */
|
|
@@ -107,8 +107,12 @@ interface PatchesDoc<T extends object = object> {
|
|
|
107
107
|
readonly committedRev: number;
|
|
108
108
|
/** Are there local changes that haven't been committed yet? */
|
|
109
109
|
readonly hasPending: boolean;
|
|
110
|
-
/**
|
|
111
|
-
readonly
|
|
110
|
+
/** Current sync status of this document. */
|
|
111
|
+
readonly syncStatus: DocSyncStatus;
|
|
112
|
+
/** Error from the last failed sync attempt, if any. */
|
|
113
|
+
readonly syncError: Error | null;
|
|
114
|
+
/** Whether the document has completed its initial load. Sticky: once true, never reverts to false. */
|
|
115
|
+
readonly isLoaded: boolean;
|
|
112
116
|
/**
|
|
113
117
|
* Subscribe to be notified when the user makes local changes.
|
|
114
118
|
* Emits the JSON Patch ops captured from the change() call.
|
|
@@ -117,8 +121,8 @@ interface PatchesDoc<T extends object = object> {
|
|
|
117
121
|
readonly onChange: Signal<(ops: JSONPatchOp[]) => void>;
|
|
118
122
|
/** Subscribe to be notified whenever state changes from any source. */
|
|
119
123
|
readonly onUpdate: Signal<(newState: T) => void>;
|
|
120
|
-
/** Subscribe to be notified when
|
|
121
|
-
readonly
|
|
124
|
+
/** Subscribe to be notified when sync status changes. */
|
|
125
|
+
readonly onSyncStatus: Signal<(newStatus: DocSyncStatus) => void>;
|
|
122
126
|
/** Subscribe to be notified whenever the state changes (calls immediately with current state). */
|
|
123
127
|
subscribe(onUpdate: (newValue: T) => void): Unsubscriber;
|
|
124
128
|
/**
|
|
@@ -137,13 +141,15 @@ interface PatchesDoc<T extends object = object> {
|
|
|
137
141
|
* apply locally. The algorithm handles packaging ops, persisting them, and updating
|
|
138
142
|
* the doc's state via `applyChanges()`.
|
|
139
143
|
*
|
|
140
|
-
* Internal methods (
|
|
144
|
+
* Internal methods (updateSyncStatus, applyChanges, import) are on this class but not
|
|
141
145
|
* on the PatchesDoc interface, as they're only used by Algorithm and PatchesSync.
|
|
142
146
|
*/
|
|
143
147
|
declare abstract class BaseDoc<T extends object = object> implements PatchesDoc<T> {
|
|
144
148
|
protected _id: string;
|
|
145
149
|
protected _state: T;
|
|
146
|
-
protected
|
|
150
|
+
protected _syncStatus: DocSyncStatus;
|
|
151
|
+
protected _syncError: Error | null;
|
|
152
|
+
protected _isLoaded: boolean;
|
|
147
153
|
/**
|
|
148
154
|
* Subscribe to be notified when the user makes local changes.
|
|
149
155
|
* Emits the JSON Patch ops captured from the change() call.
|
|
@@ -152,8 +158,8 @@ declare abstract class BaseDoc<T extends object = object> implements PatchesDoc<
|
|
|
152
158
|
readonly onChange: Signal<(ops: JSONPatchOp[]) => void>;
|
|
153
159
|
/** Subscribe to be notified whenever state changes from any source. */
|
|
154
160
|
readonly onUpdate: Signal<(newState: T) => void>;
|
|
155
|
-
/** Subscribe to be notified when
|
|
156
|
-
readonly
|
|
161
|
+
/** Subscribe to be notified when sync status changes. */
|
|
162
|
+
readonly onSyncStatus: Signal<(newStatus: DocSyncStatus) => void>;
|
|
157
163
|
/**
|
|
158
164
|
* Creates an instance of BaseDoc.
|
|
159
165
|
* @param id The unique identifier for this document.
|
|
@@ -164,8 +170,12 @@ declare abstract class BaseDoc<T extends object = object> implements PatchesDoc<
|
|
|
164
170
|
get id(): string;
|
|
165
171
|
/** Current local state (committed + pending merged). */
|
|
166
172
|
get state(): T;
|
|
167
|
-
/**
|
|
168
|
-
get
|
|
173
|
+
/** Current sync status of this document. */
|
|
174
|
+
get syncStatus(): DocSyncStatus;
|
|
175
|
+
/** Error from the last failed sync attempt, if any. */
|
|
176
|
+
get syncError(): Error | null;
|
|
177
|
+
/** Whether the document has completed its initial load. Sticky: once true, never reverts to false. */
|
|
178
|
+
get isLoaded(): boolean;
|
|
169
179
|
/** Last committed revision number from the server. */
|
|
170
180
|
abstract get committedRev(): number;
|
|
171
181
|
/** Are there local changes that haven't been committed yet? */
|
|
@@ -179,11 +189,14 @@ declare abstract class BaseDoc<T extends object = object> implements PatchesDoc<
|
|
|
179
189
|
*/
|
|
180
190
|
change(mutator: ChangeMutator<T>): void;
|
|
181
191
|
/**
|
|
182
|
-
* Updates the
|
|
192
|
+
* Updates the sync status of the document.
|
|
183
193
|
* Called by PatchesSync - not part of the app-facing PatchesDoc interface.
|
|
184
|
-
* @param
|
|
194
|
+
* @param status The new sync status.
|
|
195
|
+
* @param error Optional error when status is 'error'.
|
|
185
196
|
*/
|
|
186
|
-
|
|
197
|
+
updateSyncStatus(status: DocSyncStatus, error?: Error): void;
|
|
198
|
+
/** Latches _isLoaded to true when the doc has data or sync has resolved. */
|
|
199
|
+
protected _checkLoaded(): void;
|
|
187
200
|
/**
|
|
188
201
|
* Applies changes to the document state.
|
|
189
202
|
* Called by Algorithm for local changes and broadcasts - not part of PatchesDoc interface.
|
package/dist/client/BaseDoc.d.ts
CHANGED
package/dist/client/BaseDoc.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import "../chunk-IZ2YBCUP.js";
|
|
2
2
|
import { signal } from "../event-signal.js";
|
|
3
3
|
import { createJSONPatch } from "../json-patch/createJSONPatch.js";
|
|
4
|
+
import { isDocLoaded } from "../shared/utils.js";
|
|
4
5
|
class BaseDoc {
|
|
5
6
|
_id;
|
|
6
7
|
_state;
|
|
7
|
-
|
|
8
|
+
_syncStatus = "unsynced";
|
|
9
|
+
_syncError = null;
|
|
10
|
+
_isLoaded = false;
|
|
8
11
|
/**
|
|
9
12
|
* Subscribe to be notified when the user makes local changes.
|
|
10
13
|
* Emits the JSON Patch ops captured from the change() call.
|
|
@@ -13,8 +16,8 @@ class BaseDoc {
|
|
|
13
16
|
onChange = signal();
|
|
14
17
|
/** Subscribe to be notified whenever state changes from any source. */
|
|
15
18
|
onUpdate = signal();
|
|
16
|
-
/** Subscribe to be notified when
|
|
17
|
-
|
|
19
|
+
/** Subscribe to be notified when sync status changes. */
|
|
20
|
+
onSyncStatus = signal();
|
|
18
21
|
/**
|
|
19
22
|
* Creates an instance of BaseDoc.
|
|
20
23
|
* @param id The unique identifier for this document.
|
|
@@ -32,9 +35,17 @@ class BaseDoc {
|
|
|
32
35
|
get state() {
|
|
33
36
|
return this._state;
|
|
34
37
|
}
|
|
35
|
-
/**
|
|
36
|
-
get
|
|
37
|
-
return this.
|
|
38
|
+
/** Current sync status of this document. */
|
|
39
|
+
get syncStatus() {
|
|
40
|
+
return this._syncStatus;
|
|
41
|
+
}
|
|
42
|
+
/** Error from the last failed sync attempt, if any. */
|
|
43
|
+
get syncError() {
|
|
44
|
+
return this._syncError;
|
|
45
|
+
}
|
|
46
|
+
/** Whether the document has completed its initial load. Sticky: once true, never reverts to false. */
|
|
47
|
+
get isLoaded() {
|
|
48
|
+
return this._isLoaded;
|
|
38
49
|
}
|
|
39
50
|
/** Subscribe to be notified whenever the state changes (calls immediately with current state). */
|
|
40
51
|
subscribe(onUpdate) {
|
|
@@ -56,13 +67,22 @@ class BaseDoc {
|
|
|
56
67
|
}
|
|
57
68
|
// --- Internal methods (not on PatchesDoc interface) ---
|
|
58
69
|
/**
|
|
59
|
-
* Updates the
|
|
70
|
+
* Updates the sync status of the document.
|
|
60
71
|
* Called by PatchesSync - not part of the app-facing PatchesDoc interface.
|
|
61
|
-
* @param
|
|
72
|
+
* @param status The new sync status.
|
|
73
|
+
* @param error Optional error when status is 'error'.
|
|
62
74
|
*/
|
|
63
|
-
|
|
64
|
-
this.
|
|
65
|
-
this.
|
|
75
|
+
updateSyncStatus(status, error) {
|
|
76
|
+
this._syncStatus = status;
|
|
77
|
+
this._syncError = status === "error" ? error ?? null : null;
|
|
78
|
+
this._checkLoaded();
|
|
79
|
+
this.onSyncStatus.emit(status);
|
|
80
|
+
}
|
|
81
|
+
/** Latches _isLoaded to true when the doc has data or sync has resolved. */
|
|
82
|
+
_checkLoaded() {
|
|
83
|
+
if (!this._isLoaded && isDocLoaded(this)) {
|
|
84
|
+
this._isLoaded = true;
|
|
85
|
+
}
|
|
66
86
|
}
|
|
67
87
|
}
|
|
68
88
|
export {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JSONPatchOp } from '../json-patch/types.js';
|
|
2
2
|
import { PatchesSnapshot, Change } from '../types.js';
|
|
3
|
-
import { a as PatchesDoc } from '../BaseDoc-
|
|
3
|
+
import { a as PatchesDoc } from '../BaseDoc-BfVJNeCi.js';
|
|
4
4
|
import { PatchesStore, TrackedDoc } from './PatchesStore.js';
|
|
5
5
|
import '../json-patch/JSONPatch.js';
|
|
6
6
|
import '@dabble/delta';
|
|
@@ -2,7 +2,7 @@ import { JSONPatchOp } from '../json-patch/types.js';
|
|
|
2
2
|
import { PatchesSnapshot, Change } from '../types.js';
|
|
3
3
|
import { ClientAlgorithm } from './ClientAlgorithm.js';
|
|
4
4
|
import { LWWClientStore } from './LWWClientStore.js';
|
|
5
|
-
import { a as PatchesDoc } from '../BaseDoc-
|
|
5
|
+
import { a as PatchesDoc } from '../BaseDoc-BfVJNeCi.js';
|
|
6
6
|
import { TrackedDoc } from './PatchesStore.js';
|
|
7
7
|
import '../json-patch/JSONPatch.js';
|
|
8
8
|
import '@dabble/delta';
|
package/dist/client/LWWDoc.d.ts
CHANGED
package/dist/client/LWWDoc.js
CHANGED
|
@@ -21,6 +21,7 @@ class LWWDoc extends BaseDoc {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
+
this._checkLoaded();
|
|
24
25
|
}
|
|
25
26
|
/** Last committed revision number from the server. */
|
|
26
27
|
get committedRev() {
|
|
@@ -45,6 +46,7 @@ class LWWDoc extends BaseDoc {
|
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
}
|
|
49
|
+
this._checkLoaded();
|
|
48
50
|
this.onUpdate.emit(this._state);
|
|
49
51
|
}
|
|
50
52
|
/**
|
|
@@ -78,6 +80,7 @@ class LWWDoc extends BaseDoc {
|
|
|
78
80
|
}
|
|
79
81
|
this._committedRev = lastCommittedRev;
|
|
80
82
|
this._hasPending = hasPending ?? hasPendingChanges;
|
|
83
|
+
this._checkLoaded();
|
|
81
84
|
this.onUpdate.emit(this._state);
|
|
82
85
|
}
|
|
83
86
|
}
|
|
@@ -2,7 +2,7 @@ import { JSONPatchOp } from '../json-patch/types.js';
|
|
|
2
2
|
import { PatchesSnapshot, Change } from '../types.js';
|
|
3
3
|
import { ClientAlgorithm } from './ClientAlgorithm.js';
|
|
4
4
|
import { OTClientStore } from './OTClientStore.js';
|
|
5
|
-
import { P as PatchesDocOptions, a as PatchesDoc } from '../BaseDoc-
|
|
5
|
+
import { P as PatchesDocOptions, a as PatchesDoc } from '../BaseDoc-BfVJNeCi.js';
|
|
6
6
|
import { TrackedDoc } from './PatchesStore.js';
|
|
7
7
|
import '../json-patch/JSONPatch.js';
|
|
8
8
|
import '@dabble/delta';
|
package/dist/client/OTDoc.d.ts
CHANGED
package/dist/client/OTDoc.js
CHANGED
|
@@ -23,6 +23,7 @@ class OTDoc extends BaseDoc {
|
|
|
23
23
|
if (this._pendingChanges.length > 0) {
|
|
24
24
|
this._state = applyChangesToState(this._committedState, this._pendingChanges);
|
|
25
25
|
}
|
|
26
|
+
this._checkLoaded();
|
|
26
27
|
}
|
|
27
28
|
/** Last committed revision number from the server. */
|
|
28
29
|
get committedRev() {
|
|
@@ -48,6 +49,7 @@ class OTDoc extends BaseDoc {
|
|
|
48
49
|
this._committedRev = snapshot.rev;
|
|
49
50
|
this._pendingChanges = snapshot.changes;
|
|
50
51
|
this._state = createStateFromSnapshot(snapshot);
|
|
52
|
+
this._checkLoaded();
|
|
51
53
|
this.onUpdate.emit(this._state);
|
|
52
54
|
}
|
|
53
55
|
/**
|
|
@@ -79,6 +81,7 @@ class OTDoc extends BaseDoc {
|
|
|
79
81
|
this._state = applyChangesToState(this._state, changes);
|
|
80
82
|
this._pendingChanges.push(...changes);
|
|
81
83
|
}
|
|
84
|
+
this._checkLoaded();
|
|
82
85
|
this.onUpdate.emit(this._state);
|
|
83
86
|
}
|
|
84
87
|
/**
|
package/dist/client/Patches.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Unsubscriber, Signal } from '../event-signal.js';
|
|
|
2
2
|
import { JSONPatchOp } from '../json-patch/types.js';
|
|
3
3
|
import { Change } from '../types.js';
|
|
4
4
|
import { ClientAlgorithm } from './ClientAlgorithm.js';
|
|
5
|
-
import { P as PatchesDocOptions, a as PatchesDoc } from '../BaseDoc-
|
|
5
|
+
import { P as PatchesDocOptions, a as PatchesDoc } from '../BaseDoc-BfVJNeCi.js';
|
|
6
6
|
import { AlgorithmName } from './PatchesStore.js';
|
|
7
7
|
import '../json-patch/JSONPatch.js';
|
|
8
8
|
import '@dabble/delta';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import '../event-signal.js';
|
|
2
2
|
import '../json-patch/types.js';
|
|
3
3
|
import '../types.js';
|
|
4
|
-
export { O as OTDoc, a as PatchesDoc, O as PatchesDocClass, P as PatchesDocOptions } from '../BaseDoc-
|
|
4
|
+
export { O as OTDoc, a as PatchesDoc, O as PatchesDocClass, P as PatchesDocOptions } from '../BaseDoc-BfVJNeCi.js';
|
|
5
5
|
import '../json-patch/JSONPatch.js';
|
|
6
6
|
import '@dabble/delta';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AlgorithmName } from './PatchesStore.js';
|
|
2
2
|
import { Patches } from './Patches.js';
|
|
3
|
-
import { P as PatchesDocOptions } from '../BaseDoc-
|
|
3
|
+
import { P as PatchesDocOptions } from '../BaseDoc-BfVJNeCi.js';
|
|
4
4
|
import '../types.js';
|
|
5
5
|
import '../json-patch/JSONPatch.js';
|
|
6
6
|
import '@dabble/delta';
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { B as BaseDoc, O as OTDoc, a as PatchesDoc, O as PatchesDocClass, P as PatchesDocOptions } from '../BaseDoc-
|
|
1
|
+
export { B as BaseDoc, O as OTDoc, a as PatchesDoc, O as PatchesDocClass, P as PatchesDocOptions } from '../BaseDoc-BfVJNeCi.js';
|
|
2
2
|
export { IndexedDBFactoryOptions, MultiAlgorithmFactoryOptions, MultiAlgorithmIndexedDBFactoryOptions, PatchesFactoryOptions, createLWWIndexedDBPatches, createLWWPatches, createMultiAlgorithmIndexedDBPatches, createMultiAlgorithmPatches, createOTIndexedDBPatches, createOTPatches } from './factories.js';
|
|
3
3
|
export { IDBStoreWrapper, IDBTransactionWrapper, IndexedDBStore } from './IndexedDBStore.js';
|
|
4
4
|
export { OTIndexedDBStore } from './OTIndexedDBStore.js';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Delta } from '@dabble/delta';
|
|
2
|
-
export { B as BaseDoc, O as OTDoc, a as PatchesDoc, O as PatchesDocClass, P as PatchesDocOptions } from './BaseDoc-
|
|
2
|
+
export { B as BaseDoc, O as OTDoc, a as PatchesDoc, O as PatchesDocClass, P as PatchesDocOptions } from './BaseDoc-BfVJNeCi.js';
|
|
3
3
|
export { IndexedDBFactoryOptions, MultiAlgorithmFactoryOptions, MultiAlgorithmIndexedDBFactoryOptions, PatchesFactoryOptions, createLWWIndexedDBPatches, createLWWPatches, createMultiAlgorithmIndexedDBPatches, createMultiAlgorithmPatches, createOTIndexedDBPatches, createOTPatches } from './client/factories.js';
|
|
4
4
|
export { IDBStoreWrapper, IDBTransactionWrapper, IndexedDBStore } from './client/IndexedDBStore.js';
|
|
5
5
|
export { OTIndexedDBStore } from './client/OTIndexedDBStore.js';
|
|
@@ -29,7 +29,7 @@ export { createPathProxy, pathProxy } from './json-patch/pathProxy.js';
|
|
|
29
29
|
export { transformPatch } from './json-patch/transformPatch.js';
|
|
30
30
|
export { JSONPatch, PathLike, WriteOptions } from './json-patch/JSONPatch.js';
|
|
31
31
|
export { ApplyJSONPatchOptions, JSONPatchOpHandlerMap as JSONPatchCustomTypes, JSONPatchOp } from './json-patch/types.js';
|
|
32
|
-
export { Branch, BranchStatus, Change, ChangeInput, ChangeMutator, CommitChangesOptions, DeleteDocOptions, DocumentTombstone, EditableBranchMetadata, EditableVersionMetadata, ListChangesOptions, ListVersionsOptions, PatchesSnapshot, PatchesState, PathProxy,
|
|
32
|
+
export { Branch, BranchStatus, Change, ChangeInput, ChangeMutator, CommitChangesOptions, DeleteDocOptions, DocSyncStatus, DocumentTombstone, EditableBranchMetadata, EditableVersionMetadata, ListChangesOptions, ListVersionsOptions, PatchesSnapshot, PatchesState, PathProxy, SyncedDoc, VersionMetadata } from './types.js';
|
|
33
33
|
export { add } from './json-patch/ops/add.js';
|
|
34
34
|
export { copy } from './json-patch/ops/copy.js';
|
|
35
35
|
export { increment } from './json-patch/ops/increment.js';
|
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
import { Signal } from '../event-signal.js';
|
|
2
2
|
import { ConnectionState } from './protocol/types.js';
|
|
3
|
-
import {
|
|
3
|
+
import { DocSyncStatus, SyncedDoc, Change } from '../types.js';
|
|
4
4
|
import { JSONRPCClient } from './protocol/JSONRPCClient.js';
|
|
5
5
|
import { PatchesWebSocket } from './websocket/PatchesWebSocket.js';
|
|
6
6
|
import { WebSocketOptions } from './websocket/WebSocketTransport.js';
|
|
7
7
|
import { SizeCalculator } from '../algorithms/ot/shared/changeBatching.js';
|
|
8
|
+
import { ClientAlgorithm } from '../client/ClientAlgorithm.js';
|
|
8
9
|
import { Patches } from '../client/Patches.js';
|
|
9
10
|
import { AlgorithmName } from '../client/PatchesStore.js';
|
|
10
|
-
|
|
11
|
+
export { isDocLoaded } from '../shared/utils.js';
|
|
11
12
|
import '../json-patch/JSONPatch.js';
|
|
12
13
|
import '@dabble/delta';
|
|
13
14
|
import '../json-patch/types.js';
|
|
14
15
|
import './PatchesClient.js';
|
|
15
16
|
import '../utils/deferred.js';
|
|
16
|
-
import '../BaseDoc-
|
|
17
|
+
import '../BaseDoc-BfVJNeCi.js';
|
|
17
18
|
|
|
18
19
|
interface PatchesSyncState {
|
|
19
20
|
online: boolean;
|
|
20
21
|
connected: boolean;
|
|
21
|
-
|
|
22
|
+
syncStatus: DocSyncStatus;
|
|
23
|
+
syncError: Error | null;
|
|
22
24
|
}
|
|
23
25
|
interface PatchesSyncOptions {
|
|
24
26
|
subscribeFilter?: (docIds: string[]) => string[];
|
|
@@ -30,6 +32,7 @@ interface PatchesSyncOptions {
|
|
|
30
32
|
/** Custom size calculator for storage limit. Falls back to patches.docOptions.sizeCalculator. */
|
|
31
33
|
sizeCalculator?: SizeCalculator;
|
|
32
34
|
}
|
|
35
|
+
|
|
33
36
|
/**
|
|
34
37
|
* Handles WebSocket connection, document subscriptions, and syncing logic between
|
|
35
38
|
* the Patches instance and the server.
|
|
@@ -50,6 +53,7 @@ declare class PatchesSync {
|
|
|
50
53
|
/** Maps docId to the algorithm name used for that doc */
|
|
51
54
|
protected docAlgorithms: Map<string, AlgorithmName>;
|
|
52
55
|
protected _state: PatchesSyncState;
|
|
56
|
+
protected _syncedDocs: Record<string, SyncedDoc>;
|
|
53
57
|
/**
|
|
54
58
|
* Signal emitted when the sync state changes.
|
|
55
59
|
*/
|
|
@@ -65,6 +69,10 @@ declare class PatchesSync {
|
|
|
65
69
|
* Provides the pending changes that were discarded so the application can handle them.
|
|
66
70
|
*/
|
|
67
71
|
readonly onRemoteDocDeleted: Signal<(docId: string, pendingChanges: Change[]) => void>;
|
|
72
|
+
/**
|
|
73
|
+
* Signal emitted when the synced doc map changes.
|
|
74
|
+
*/
|
|
75
|
+
readonly onSyncedDocsChange: Signal<(synced: Record<string, SyncedDoc>) => void>;
|
|
68
76
|
constructor(patches: Patches, url: string, options?: PatchesSyncOptions | undefined);
|
|
69
77
|
/**
|
|
70
78
|
* Gets the algorithm for a document. Uses the open doc's algorithm if available,
|
|
@@ -83,6 +91,11 @@ declare class PatchesSync {
|
|
|
83
91
|
* Gets the current sync state.
|
|
84
92
|
*/
|
|
85
93
|
get state(): PatchesSyncState;
|
|
94
|
+
/**
|
|
95
|
+
* Map of all tracked documents and their current sync status.
|
|
96
|
+
* Updated immutably — new object reference on every change.
|
|
97
|
+
*/
|
|
98
|
+
get syncedDocs(): Record<string, SyncedDoc>;
|
|
86
99
|
/**
|
|
87
100
|
* Gets the JSON-RPC client for making custom RPC calls.
|
|
88
101
|
* Useful for application-specific methods not part of the Patches protocol.
|
|
@@ -142,6 +155,31 @@ declare class PatchesSync {
|
|
|
142
155
|
* Cleans up local state and notifies the application with any pending changes that were lost.
|
|
143
156
|
*/
|
|
144
157
|
protected _handleRemoteDocDeleted(docId: string): Promise<void>;
|
|
158
|
+
/**
|
|
159
|
+
* Adds, updates, or removes a synced doc entry immutably and emits onSyncedChange.
|
|
160
|
+
* - Pass a full SyncedDoc to add a new entry or overwrite an existing one.
|
|
161
|
+
* - Pass a Partial<SyncedDoc> to merge into an existing entry (no-ops if doc not in map).
|
|
162
|
+
* - Pass undefined to remove the entry.
|
|
163
|
+
* No-ops if nothing actually changed.
|
|
164
|
+
*/
|
|
165
|
+
protected _updateSyncedDoc(docId: string, updates: Partial<SyncedDoc> | undefined, emit?: boolean): void;
|
|
166
|
+
protected _emitSyncedChange(): void;
|
|
167
|
+
/**
|
|
168
|
+
* Resets any docs with status 'syncing' back to a stable state on disconnect.
|
|
169
|
+
* Uses hasPending to decide: pending docs become 'synced' (they have local data),
|
|
170
|
+
* docs with no pending and no committed rev become 'unsynced'.
|
|
171
|
+
*/
|
|
172
|
+
protected _resetSyncingStatuses(): void;
|
|
173
|
+
/**
|
|
174
|
+
* Applies the subscribeFilter option to a list of doc IDs, returning the subset
|
|
175
|
+
* that should be sent to ws.subscribe/unsubscribe. Returns the full list if no filter is set.
|
|
176
|
+
*/
|
|
177
|
+
protected _filterSubscribeIds(docIds: string[]): string[];
|
|
178
|
+
/**
|
|
179
|
+
* Returns the set of doc IDs currently subscribed on the server, derived by
|
|
180
|
+
* applying the subscribe filter to the full tracked set.
|
|
181
|
+
*/
|
|
182
|
+
protected _getActiveSubscriptions(): Set<string>;
|
|
145
183
|
/**
|
|
146
184
|
* Helper to detect DOC_DELETED (410) errors from the server.
|
|
147
185
|
*/
|