@automerge/automerge-repo 2.0.0-alpha.20 → 2.0.0-alpha.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/README.md +8 -8
- package/dist/DocHandle.d.ts +10 -22
- package/dist/DocHandle.d.ts.map +1 -1
- package/dist/DocHandle.js +21 -51
- package/dist/FindProgress.d.ts +30 -0
- package/dist/FindProgress.d.ts.map +1 -0
- package/dist/FindProgress.js +1 -0
- package/dist/Repo.d.ts +9 -4
- package/dist/Repo.d.ts.map +1 -1
- package/dist/Repo.js +166 -69
- package/dist/helpers/abortable.d.ts +39 -0
- package/dist/helpers/abortable.d.ts.map +1 -0
- package/dist/helpers/abortable.js +45 -0
- package/dist/helpers/tests/network-adapter-tests.d.ts.map +1 -1
- package/dist/helpers/tests/network-adapter-tests.js +13 -13
- package/dist/synchronizer/CollectionSynchronizer.d.ts +2 -1
- package/dist/synchronizer/CollectionSynchronizer.d.ts.map +1 -1
- package/dist/synchronizer/CollectionSynchronizer.js +18 -14
- package/dist/synchronizer/DocSynchronizer.d.ts +3 -2
- package/dist/synchronizer/DocSynchronizer.d.ts.map +1 -1
- package/dist/synchronizer/DocSynchronizer.js +43 -27
- package/fuzz/fuzz.ts +3 -3
- package/package.json +3 -4
- package/src/DocHandle.ts +23 -51
- package/src/FindProgress.ts +48 -0
- package/src/Repo.ts +187 -67
- package/src/helpers/abortable.ts +61 -0
- package/src/helpers/tests/network-adapter-tests.ts +14 -13
- package/src/synchronizer/CollectionSynchronizer.ts +18 -14
- package/src/synchronizer/DocSynchronizer.ts +51 -32
- package/test/CollectionSynchronizer.test.ts +4 -4
- package/test/DocHandle.test.ts +25 -74
- package/test/Repo.test.ts +169 -216
- package/test/remoteHeads.test.ts +27 -12
package/README.md
CHANGED
|
@@ -40,9 +40,9 @@ A `Repo` exposes these methods:
|
|
|
40
40
|
|
|
41
41
|
- `create<T>(initialValue: T?)`
|
|
42
42
|
Creates a new `Automerge.Doc` and returns a `DocHandle` for it. Accepts an optional initial value for the document. Produces an empty document (potentially violating the type!) otherwise.
|
|
43
|
-
- `find<T>(docId: DocumentId)
|
|
43
|
+
- `find<T>(docId: DocumentId): Promise<DocHandle<T>>`
|
|
44
44
|
Looks up a given document either on the local machine or (if necessary) over any configured
|
|
45
|
-
networks.
|
|
45
|
+
networks. Returns a promise that resolves when the document is loaded or throws if load fails.
|
|
46
46
|
- `delete(docId: DocumentId)`
|
|
47
47
|
Deletes the local copy of a document from the local cache and local storage. _This does not currently delete the document from any other peers_.
|
|
48
48
|
- `import(binary: Uint8Array)`
|
|
@@ -57,10 +57,9 @@ A `Repo` exposes these methods:
|
|
|
57
57
|
A `DocHandle` is a wrapper around an `Automerge.Doc`. Its primary function is to dispatch changes to
|
|
58
58
|
the document.
|
|
59
59
|
|
|
60
|
-
- `handle.doc()`
|
|
61
|
-
Returns a `
|
|
62
|
-
|
|
63
|
-
returning a value.
|
|
60
|
+
- `handle.doc()`
|
|
61
|
+
Returns a `Doc<T>` that will contain the current value of the document.
|
|
62
|
+
Throws an error if the document is deleted.
|
|
64
63
|
- `handle.change((doc: T) => void)`
|
|
65
64
|
Calls the provided callback with an instrumented mutable object
|
|
66
65
|
representing the document. Any changes made to the document will be recorded and distributed to
|
|
@@ -233,14 +232,14 @@ Now import it and add it to your list of network adapters:
|
|
|
233
232
|
|
|
234
233
|
```ts
|
|
235
234
|
// main.tsx
|
|
236
|
-
import {
|
|
235
|
+
import { WebSocketClientAdapter } from "@automerge/automerge-repo-network-websocket" // <-- add this line
|
|
237
236
|
|
|
238
237
|
// ...
|
|
239
238
|
|
|
240
239
|
const repo = new Repo({
|
|
241
240
|
network: [
|
|
242
241
|
new BroadcastChannelNetworkAdapter(),
|
|
243
|
-
new
|
|
242
|
+
new WebSocketClientAdapter("ws://localhost:3030"), // <-- add this line
|
|
244
243
|
],
|
|
245
244
|
storage: new IndexedDBStorageAdapter(),
|
|
246
245
|
})
|
|
@@ -262,3 +261,4 @@ With gratitude for contributions by:
|
|
|
262
261
|
- Jeremy Rose
|
|
263
262
|
- Alex Currie-Clark
|
|
264
263
|
- Dylan Mackenzie
|
|
264
|
+
- Maciek Sakrejda
|
package/dist/DocHandle.d.ts
CHANGED
|
@@ -65,34 +65,23 @@ export declare class DocHandle<T> extends EventEmitter<DocHandleEvents<T>> {
|
|
|
65
65
|
*/
|
|
66
66
|
whenReady(awaitStates?: HandleState[]): Promise<void>;
|
|
67
67
|
/**
|
|
68
|
-
*
|
|
68
|
+
* Returns the current state of the Automerge document this handle manages.
|
|
69
|
+
*
|
|
70
|
+
* @returns the current document
|
|
71
|
+
* @throws on deleted and unavailable documents
|
|
69
72
|
*
|
|
70
|
-
* This is the recommended way to access a handle's document. Note that this waits for the handle
|
|
71
|
-
* to be ready if necessary. If loading (or synchronization) fails, this will never resolve.
|
|
72
73
|
*/
|
|
73
|
-
doc(
|
|
74
|
-
/** states to wait for, such as "LOADING". mostly for internal use. */
|
|
75
|
-
awaitStates?: HandleState[]): Promise<A.Doc<T> | undefined>;
|
|
74
|
+
doc(): A.Doc<T>;
|
|
76
75
|
/**
|
|
77
|
-
* Synchronously returns the current state of the Automerge document this handle manages, or
|
|
78
|
-
* undefined. Consider using `await handle.doc()` instead. Check `isReady()`, or use `whenReady()`
|
|
79
|
-
* if you want to make sure loading is complete first.
|
|
80
|
-
*
|
|
81
|
-
* Not to be confused with the SyncState of the document, which describes the state of the
|
|
82
|
-
* synchronization process.
|
|
83
76
|
*
|
|
84
|
-
*
|
|
85
|
-
|
|
86
|
-
*
|
|
87
|
-
* @returns the current document, or undefined if the document is not ready.
|
|
88
|
-
*/
|
|
89
|
-
docSync(): A.Doc<T> | undefined;
|
|
77
|
+
* @deprecated */
|
|
78
|
+
docSync(): A.Doc<T>;
|
|
90
79
|
/**
|
|
91
80
|
* Returns the current "heads" of the document, akin to a git commit.
|
|
92
81
|
* This precisely defines the state of a document.
|
|
93
82
|
* @returns the current document's heads, or undefined if the document is not ready
|
|
94
83
|
*/
|
|
95
|
-
heads(): UrlHeads
|
|
84
|
+
heads(): UrlHeads;
|
|
96
85
|
begin(): void;
|
|
97
86
|
/**
|
|
98
87
|
* Returns an array of all past "heads" for the document in topological order.
|
|
@@ -108,8 +97,8 @@ export declare class DocHandle<T> extends EventEmitter<DocHandleEvents<T>> {
|
|
|
108
97
|
*/
|
|
109
98
|
history(): UrlHeads[] | undefined;
|
|
110
99
|
/**
|
|
111
|
-
* Creates a
|
|
112
|
-
* by the `heads` passed in. The return value is the same type as
|
|
100
|
+
* Creates a fixed "view" of an automerge document at the given point in time represented
|
|
101
|
+
* by the `heads` passed in. The return value is the same type as doc() and will return
|
|
113
102
|
* undefined if the object hasn't finished loading.
|
|
114
103
|
*
|
|
115
104
|
* @remarks
|
|
@@ -245,7 +234,6 @@ export interface DocHandleEvents<T> {
|
|
|
245
234
|
"heads-changed": (payload: DocHandleEncodedChangePayload<T>) => void;
|
|
246
235
|
change: (payload: DocHandleChangePayload<T>) => void;
|
|
247
236
|
delete: (payload: DocHandleDeletePayload<T>) => void;
|
|
248
|
-
unavailable: (payload: DocHandleUnavailablePayload<T>) => void;
|
|
249
237
|
"ephemeral-message": (payload: DocHandleEphemeralMessagePayload<T>) => void;
|
|
250
238
|
"ephemeral-message-outbound": (payload: DocHandleOutboundEphemeralMessagePayload<T>) => void;
|
|
251
239
|
"remote-heads": (payload: DocHandleRemoteHeadsPayload) => void;
|
package/dist/DocHandle.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DocHandle.d.ts","sourceRoot":"","sources":["../src/DocHandle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,gCAAgC,CAAA;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAU5C,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,oBA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AE,SAAS,CAAA;IACpB,KAAK,EAAE,QAAQ,CAAA;CAChB;AAMD;;GAEG;AACH,eAAO,MAAM,WAAW;IACtB,kEAAkE;;IAElE,mDAAmD;;IAEnD,6EAA6E;;IAE7E,gCAAgC;;IAEhC,2EAA2E;;IAE3E,kDAAkD;;IAElD,4EAA4E;;CAEpE,CAAA;AACV,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAA;AAExE,eAAO,MACL,IAAI,UACJ,OAAO,aACP,UAAU,gBACV,KAAK,WACL,QAAQ,cACR,OAAO,aACP,WAAW,eACE,CAAA"}
|
package/dist/DocHandle.js
CHANGED
|
@@ -64,12 +64,12 @@ export class DocHandle extends EventEmitter {
|
|
|
64
64
|
this.emit("delete", { handle: this });
|
|
65
65
|
return { doc: A.init() };
|
|
66
66
|
}),
|
|
67
|
+
onUnavailable: assign(() => {
|
|
68
|
+
return { doc: A.init() };
|
|
69
|
+
}),
|
|
67
70
|
onUnload: assign(() => {
|
|
68
71
|
return { doc: A.init() };
|
|
69
72
|
}),
|
|
70
|
-
onUnavailable: () => {
|
|
71
|
-
this.emit("unavailable", { handle: this });
|
|
72
|
-
},
|
|
73
73
|
},
|
|
74
74
|
}).createMachine({
|
|
75
75
|
/** @xstate-layout N4IgpgJg5mDOIC5QAoC2BDAxgCwJYDswBKAYgFUAFAEQEEAVAUQG0AGAXUVAAcB7WXAC64e+TiAAeiAOwAOAKwA6ACxSAzKqks1ATjlTdAGhABPRAFolAJksKN2y1KtKAbFLla5AX09G0WPISkVAwAMgyMrBxIILz8QiJikggAjCzOijKqLEqqybJyLizaRqYIFpbJtro5Uo7J2o5S3r4YOATECrgQADZgJADCAEoM9MzsYrGCwqLRSeoyCtra8pa5adquySXmDjY5ac7JljLJeepKzSB+bYGdPX0AYgCSAHJUkRN8UwmziM7HCgqyVcUnqcmScmcMm2ZV2yiyzkOx1OalUFx8V1aAQ63R46AgBCgJGGAEUyAwAMp0D7RSbxGagJKHFgKOSWJTJGRSCosCpKaEmRCqbQKU5yXINeTaer6LwY67YogKXH4wkkKgAeX6AH1hjQqABNGncL70xKIJQ5RY5BHOJag6wwpRyEWImQVeT1aWrVSXBXtJUqgn4Ik0ADqNCedG1L3CYY1gwA0saYqbpuaEG4pKLksKpFDgcsCjDhTnxTKpTLdH6sQGFOgAO7oKYhl5gAQNngAJwA1iRY3R40ndSNDSm6enfpm5BkWAVkvy7bpuTCKq7ndZnfVeSwuTX-HWu2AAI4AVzgQhD6q12rILxoADVIyEaAAhMLjtM-RmIE4LVSQi4nLLDIGzOCWwLKA0cgyLBoFWNy+43B0R5nheaqajqepjuMtJfgyEh-FoixqMCoKqOyhzgYKCDOq6UIeuCSxHOoSGKgop74OgABuzbdOgABGvTXlho5GrhJpxJOP4pLulT6KoMhpJY2hzsWNF0QobqMV6LG+pc+A8BAcBiP6gSfFJ36EQgKksksKxrHamwwmY7gLKB85QjBzoAWxdZdL0FnfARST8ooLC7qoTnWBU4pyC5ViVMKBQaHUDQuM4fm3EGhJBWaU7-CysEAUp3LpEpWw0WYRw2LmqzgqciIsCxWUdI2zaXlAbYdt2PZ5dJ1n5jY2iJY1ikOIcMJHCyUWHC62hRZkUVNPKta3Kh56wJ1-VWUyzhFc64JWJCtQNBBzhQW4cHwbsrVKpxPF8YJgV4ZZIWIKkiKiiNSkqZYWjzCWaQ5hFh0AcCuR3QoR74qUknBRmzholpv3OkpRQNNRpTzaKTWKbIWR5FDxm9AIkA7e9skUYCWayLILBZGoLkUSKbIyIdpxHPoyTeN4QA */
|
|
@@ -229,53 +229,26 @@ export class DocHandle extends EventEmitter {
|
|
|
229
229
|
await withTimeout(this.#statePromise(awaitStates), this.#timeoutDelay);
|
|
230
230
|
}
|
|
231
231
|
/**
|
|
232
|
-
*
|
|
232
|
+
* Returns the current state of the Automerge document this handle manages.
|
|
233
|
+
*
|
|
234
|
+
* @returns the current document
|
|
235
|
+
* @throws on deleted and unavailable documents
|
|
233
236
|
*
|
|
234
|
-
* This is the recommended way to access a handle's document. Note that this waits for the handle
|
|
235
|
-
* to be ready if necessary. If loading (or synchronization) fails, this will never resolve.
|
|
236
237
|
*/
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
try {
|
|
241
|
-
// wait for the document to enter one of the desired states
|
|
242
|
-
await this.#statePromise(awaitStates);
|
|
243
|
-
}
|
|
244
|
-
catch (error) {
|
|
245
|
-
// if we timed out, return undefined
|
|
246
|
-
return undefined;
|
|
247
|
-
}
|
|
248
|
-
// If we have fixed heads, return a view at those heads
|
|
238
|
+
doc() {
|
|
239
|
+
if (!this.isReady())
|
|
240
|
+
throw new Error("DocHandle is not ready");
|
|
249
241
|
if (this.#fixedHeads) {
|
|
250
|
-
|
|
251
|
-
if (!doc || this.isUnavailable())
|
|
252
|
-
return undefined;
|
|
253
|
-
return A.view(doc, decodeHeads(this.#fixedHeads));
|
|
242
|
+
return A.view(this.#doc, decodeHeads(this.#fixedHeads));
|
|
254
243
|
}
|
|
255
|
-
|
|
256
|
-
return !this.isUnavailable() ? this.#doc : undefined;
|
|
244
|
+
return this.#doc;
|
|
257
245
|
}
|
|
258
246
|
/**
|
|
259
|
-
* Synchronously returns the current state of the Automerge document this handle manages, or
|
|
260
|
-
* undefined. Consider using `await handle.doc()` instead. Check `isReady()`, or use `whenReady()`
|
|
261
|
-
* if you want to make sure loading is complete first.
|
|
262
|
-
*
|
|
263
|
-
* Not to be confused with the SyncState of the document, which describes the state of the
|
|
264
|
-
* synchronization process.
|
|
265
247
|
*
|
|
266
|
-
*
|
|
267
|
-
* unambigous.
|
|
268
|
-
*
|
|
269
|
-
* @returns the current document, or undefined if the document is not ready.
|
|
270
|
-
*/
|
|
248
|
+
* @deprecated */
|
|
271
249
|
docSync() {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
if (this.#fixedHeads) {
|
|
275
|
-
const doc = this.#doc;
|
|
276
|
-
return doc ? A.view(doc, decodeHeads(this.#fixedHeads)) : undefined;
|
|
277
|
-
}
|
|
278
|
-
return this.#doc;
|
|
250
|
+
console.warn("docSync is deprecated. Use doc() instead. This function will be removed as part of the 2.0 release.");
|
|
251
|
+
return this.doc();
|
|
279
252
|
}
|
|
280
253
|
/**
|
|
281
254
|
* Returns the current "heads" of the document, akin to a git commit.
|
|
@@ -284,7 +257,7 @@ export class DocHandle extends EventEmitter {
|
|
|
284
257
|
*/
|
|
285
258
|
heads() {
|
|
286
259
|
if (!this.isReady())
|
|
287
|
-
|
|
260
|
+
throw new Error("DocHandle is not ready");
|
|
288
261
|
if (this.#fixedHeads) {
|
|
289
262
|
return this.#fixedHeads;
|
|
290
263
|
}
|
|
@@ -313,8 +286,8 @@ export class DocHandle extends EventEmitter {
|
|
|
313
286
|
return A.topoHistoryTraversal(this.#doc).map(h => encodeHeads([h]));
|
|
314
287
|
}
|
|
315
288
|
/**
|
|
316
|
-
* Creates a
|
|
317
|
-
* by the `heads` passed in. The return value is the same type as
|
|
289
|
+
* Creates a fixed "view" of an automerge document at the given point in time represented
|
|
290
|
+
* by the `heads` passed in. The return value is the same type as doc() and will return
|
|
318
291
|
* undefined if the object hasn't finished loading.
|
|
319
292
|
*
|
|
320
293
|
* @remarks
|
|
@@ -367,7 +340,7 @@ export class DocHandle extends EventEmitter {
|
|
|
367
340
|
if (!otherHeads)
|
|
368
341
|
throw new Error("Other document's heads not available");
|
|
369
342
|
// Create a temporary merged doc to verify shared history and compute diff
|
|
370
|
-
const mergedDoc = A.merge(A.clone(doc), first.
|
|
343
|
+
const mergedDoc = A.merge(A.clone(doc), first.doc());
|
|
371
344
|
// Use the merged doc to compute the diff
|
|
372
345
|
return A.diff(mergedDoc, decodeHeads(this.heads()), decodeHeads(otherHeads));
|
|
373
346
|
}
|
|
@@ -499,10 +472,7 @@ export class DocHandle extends EventEmitter {
|
|
|
499
472
|
if (this.#fixedHeads) {
|
|
500
473
|
throw new Error(`DocHandle#${this.documentId} is in view-only mode at specific heads. Use clone() to create a new document from this state.`);
|
|
501
474
|
}
|
|
502
|
-
const mergingDoc = otherHandle.
|
|
503
|
-
if (!mergingDoc) {
|
|
504
|
-
throw new Error("The document to be merged in is falsy, aborting.");
|
|
505
|
-
}
|
|
475
|
+
const mergingDoc = otherHandle.doc();
|
|
506
476
|
this.update(doc => {
|
|
507
477
|
return A.merge(doc, mergingDoc);
|
|
508
478
|
});
|
|
@@ -543,7 +513,7 @@ export class DocHandle extends EventEmitter {
|
|
|
543
513
|
broadcast(message) {
|
|
544
514
|
this.emit("ephemeral-message-outbound", {
|
|
545
515
|
handle: this,
|
|
546
|
-
data: encode(message),
|
|
516
|
+
data: new Uint8Array(encode(message)),
|
|
547
517
|
});
|
|
548
518
|
}
|
|
549
519
|
metrics() {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { DocHandle } from "./DocHandle.js";
|
|
2
|
+
export type FindProgressState = "loading" | "ready" | "failed" | "aborted" | "unavailable";
|
|
3
|
+
interface FindProgressBase<T> {
|
|
4
|
+
state: FindProgressState;
|
|
5
|
+
handle: DocHandle<T>;
|
|
6
|
+
}
|
|
7
|
+
interface FindProgressLoading<T> extends FindProgressBase<T> {
|
|
8
|
+
state: "loading";
|
|
9
|
+
progress: number;
|
|
10
|
+
}
|
|
11
|
+
interface FindProgressReady<T> extends FindProgressBase<T> {
|
|
12
|
+
state: "ready";
|
|
13
|
+
}
|
|
14
|
+
interface FindProgressFailed<T> extends FindProgressBase<T> {
|
|
15
|
+
state: "failed";
|
|
16
|
+
error: Error;
|
|
17
|
+
}
|
|
18
|
+
interface FindProgressUnavailable<T> extends FindProgressBase<T> {
|
|
19
|
+
state: "unavailable";
|
|
20
|
+
}
|
|
21
|
+
interface FindProgressAborted<T> extends FindProgressBase<T> {
|
|
22
|
+
state: "aborted";
|
|
23
|
+
}
|
|
24
|
+
export type FindProgress<T> = FindProgressLoading<T> | FindProgressReady<T> | FindProgressFailed<T> | FindProgressUnavailable<T> | FindProgressAborted<T>;
|
|
25
|
+
export type FindProgressWithMethods<T> = FindProgress<T> & {
|
|
26
|
+
next: () => Promise<FindProgressWithMethods<T>>;
|
|
27
|
+
untilReady: (allowableStates: string[]) => Promise<DocHandle<T>>;
|
|
28
|
+
};
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=FindProgress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FindProgress.d.ts","sourceRoot":"","sources":["../src/FindProgress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,MAAM,MAAM,iBAAiB,GACzB,SAAS,GACT,OAAO,GACP,QAAQ,GACR,SAAS,GACT,aAAa,CAAA;AAEjB,UAAU,gBAAgB,CAAC,CAAC;IAC1B,KAAK,EAAE,iBAAiB,CAAA;IACxB,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,CAAA;CACrB;AAED,UAAU,mBAAmB,CAAC,CAAC,CAAE,SAAQ,gBAAgB,CAAC,CAAC,CAAC;IAC1D,KAAK,EAAE,SAAS,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,UAAU,iBAAiB,CAAC,CAAC,CAAE,SAAQ,gBAAgB,CAAC,CAAC,CAAC;IACxD,KAAK,EAAE,OAAO,CAAA;CACf;AAED,UAAU,kBAAkB,CAAC,CAAC,CAAE,SAAQ,gBAAgB,CAAC,CAAC,CAAC;IACzD,KAAK,EAAE,QAAQ,CAAA;IACf,KAAK,EAAE,KAAK,CAAA;CACb;AAED,UAAU,uBAAuB,CAAC,CAAC,CAAE,SAAQ,gBAAgB,CAAC,CAAC,CAAC;IAC9D,KAAK,EAAE,aAAa,CAAA;CACrB;AAED,UAAU,mBAAmB,CAAC,CAAC,CAAE,SAAQ,gBAAgB,CAAC,CAAC,CAAC;IAC1D,KAAK,EAAE,SAAS,CAAA;CACjB;AAED,MAAM,MAAM,YAAY,CAAC,CAAC,IACtB,mBAAmB,CAAC,CAAC,CAAC,GACtB,iBAAiB,CAAC,CAAC,CAAC,GACpB,kBAAkB,CAAC,CAAC,CAAC,GACrB,uBAAuB,CAAC,CAAC,CAAC,GAC1B,mBAAmB,CAAC,CAAC,CAAC,CAAA;AAE1B,MAAM,MAAM,uBAAuB,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,GAAG;IACzD,IAAI,EAAE,MAAM,OAAO,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAA;IAE/C,UAAU,EAAE,CAAC,eAAe,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;CACjE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/Repo.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ import { StorageId } from "./storage/types.js";
|
|
|
8
8
|
import { CollectionSynchronizer } from "./synchronizer/CollectionSynchronizer.js";
|
|
9
9
|
import { DocSyncMetrics } from "./synchronizer/Synchronizer.js";
|
|
10
10
|
import type { AnyDocumentId, AutomergeUrl, DocumentId, PeerId } from "./types.js";
|
|
11
|
+
import { AbortOptions } from "./helpers/abortable.js";
|
|
12
|
+
import { FindProgress, FindProgressWithMethods } from "./FindProgress.js";
|
|
11
13
|
/** A Repo is a collection of documents with networking, syncing, and storage capabilities. */
|
|
12
14
|
/** The `Repo` is the main entry point of this library
|
|
13
15
|
*
|
|
@@ -57,17 +59,17 @@ export declare class Repo extends EventEmitter<RepoEvents> {
|
|
|
57
59
|
* Any peers this `Repo` is connected to for whom `sharePolicy` returns `true` will
|
|
58
60
|
* be notified of the newly created DocHandle.
|
|
59
61
|
*
|
|
60
|
-
* @throws if the cloned handle is not yet ready or if
|
|
61
|
-
* `clonedHandle.docSync()` returns `undefined` (i.e. the handle is unavailable).
|
|
62
62
|
*/
|
|
63
63
|
clone<T>(clonedHandle: DocHandle<T>): DocHandle<T>;
|
|
64
|
+
findWithProgress<T>(id: AnyDocumentId, options?: AbortOptions): FindProgressWithMethods<T> | FindProgress<T>;
|
|
65
|
+
find<T>(id: AnyDocumentId, options?: RepoFindOptions & AbortOptions): Promise<DocHandle<T>>;
|
|
64
66
|
/**
|
|
65
67
|
* Retrieves a document by id. It gets data from the local system, but also emits a `document`
|
|
66
68
|
* event to advertise interest in the document.
|
|
67
69
|
*/
|
|
68
|
-
|
|
70
|
+
findClassic<T>(
|
|
69
71
|
/** The url or documentId of the handle to retrieve */
|
|
70
|
-
id: AnyDocumentId): DocHandle<T
|
|
72
|
+
id: AnyDocumentId, options?: RepoFindOptions & AbortOptions): Promise<DocHandle<T>>;
|
|
71
73
|
delete(
|
|
72
74
|
/** The url or documentId of the handle to delete */
|
|
73
75
|
id: AnyDocumentId): void;
|
|
@@ -151,6 +153,9 @@ export interface RepoEvents {
|
|
|
151
153
|
"unavailable-document": (arg: DeleteDocumentPayload) => void;
|
|
152
154
|
"doc-metrics": (arg: DocMetrics) => void;
|
|
153
155
|
}
|
|
156
|
+
export interface RepoFindOptions {
|
|
157
|
+
allowableStates?: string[];
|
|
158
|
+
}
|
|
154
159
|
export interface DocumentPayload {
|
|
155
160
|
handle: DocHandle<any>;
|
|
156
161
|
}
|
package/dist/Repo.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Repo.d.ts","sourceRoot":"","sources":["../src/Repo.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAQ5C,OAAO,EAEL,SAAS,EAKV,MAAM,gBAAgB,CAAA;AAIvB,OAAO,EACL,uBAAuB,EACvB,KAAK,YAAY,EAClB,MAAM,sCAAsC,CAAA;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAEhE,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAA;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA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