@automerge/automerge-repo 1.0.1 → 1.0.3
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/DocHandle.d.ts +47 -5
- package/dist/DocHandle.d.ts.map +1 -1
- package/dist/DocHandle.js +40 -3
- package/dist/DocUrl.d.ts +4 -5
- package/dist/DocUrl.d.ts.map +1 -1
- package/dist/DocUrl.js +9 -2
- package/dist/EphemeralData.d.ts +1 -0
- package/dist/EphemeralData.d.ts.map +1 -1
- package/dist/Repo.d.ts +25 -5
- package/dist/Repo.d.ts.map +1 -1
- package/dist/Repo.js +24 -4
- package/dist/index.d.ts +33 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -4
- package/dist/network/NetworkAdapter.d.ts +21 -0
- package/dist/network/NetworkAdapter.d.ts.map +1 -1
- package/dist/network/NetworkAdapter.js +7 -0
- package/dist/network/messages.d.ts +82 -7
- package/dist/network/messages.d.ts.map +1 -1
- package/dist/storage/StorageAdapter.d.ts +21 -0
- package/dist/storage/StorageAdapter.d.ts.map +1 -1
- package/dist/storage/StorageAdapter.js +6 -0
- package/dist/types.d.ts +12 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/DocHandle.ts +47 -4
- package/src/DocUrl.ts +11 -7
- package/src/EphemeralData.ts +1 -0
- package/src/Repo.ts +50 -12
- package/src/index.ts +44 -6
- package/src/network/NetworkAdapter.ts +21 -0
- package/src/network/messages.ts +105 -8
- package/src/storage/StorageAdapter.ts +21 -0
- package/src/types.ts +12 -4
- package/test/Repo.test.ts +31 -0
- package/test/StorageSubsystem.test.ts +1 -1
- package/typedoc.json +5 -0
package/dist/DocHandle.d.ts
CHANGED
|
@@ -2,12 +2,29 @@ import * as A from "@automerge/automerge/next";
|
|
|
2
2
|
import { EventEmitter } from "eventemitter3";
|
|
3
3
|
import { StateValue } from "xstate";
|
|
4
4
|
import type { DocumentId, PeerId, AutomergeUrl } from "./types.js";
|
|
5
|
-
/** DocHandle is a wrapper around a single Automerge document that lets us
|
|
5
|
+
/** DocHandle is a wrapper around a single Automerge document that lets us
|
|
6
|
+
* listen for changes and notify the network and storage of new changes.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* A `DocHandle` represents a document which is being managed by a {@link Repo}.
|
|
10
|
+
* To obtain `DocHandle` use {@link Repo.find} or {@link Repo.create}.
|
|
11
|
+
*
|
|
12
|
+
* To modify the underlying document use either {@link DocHandle.change} or
|
|
13
|
+
* {@link DocHandle.changeAt}. These methods will notify the `Repo` that some
|
|
14
|
+
* change has occured and the `Repo` will save any new changes to the
|
|
15
|
+
* attached {@link StorageAdapter} and send sync messages to connected peers.
|
|
16
|
+
* */
|
|
6
17
|
export declare class DocHandle<T>//
|
|
7
18
|
extends EventEmitter<DocHandleEvents<T>> {
|
|
8
19
|
#private;
|
|
9
20
|
documentId: DocumentId;
|
|
21
|
+
/** The URL of this document
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* This can be used to request the document from an instance of {@link Repo}
|
|
25
|
+
*/
|
|
10
26
|
get url(): AutomergeUrl;
|
|
27
|
+
/** @hidden */
|
|
11
28
|
constructor(documentId: DocumentId, { isNew, timeoutDelay }?: DocHandleOptions);
|
|
12
29
|
/**
|
|
13
30
|
* Checks if the document is ready for accessing or changes.
|
|
@@ -24,6 +41,7 @@ export declare class DocHandle<T>//
|
|
|
24
41
|
isDeleted: () => boolean;
|
|
25
42
|
isUnavailable: () => boolean;
|
|
26
43
|
inState: (states: HandleState[]) => boolean;
|
|
44
|
+
/** @hidden */
|
|
27
45
|
get state(): StateValue;
|
|
28
46
|
/**
|
|
29
47
|
* Use this to block until the document handle has finished loading.
|
|
@@ -51,7 +69,9 @@ export declare class DocHandle<T>//
|
|
|
51
69
|
* @returns the current document, or undefined if the document is not ready
|
|
52
70
|
*/
|
|
53
71
|
docSync(): A.Doc<T> | undefined;
|
|
54
|
-
/** `update` is called by the repo when we receive changes from the network
|
|
72
|
+
/** `update` is called by the repo when we receive changes from the network
|
|
73
|
+
* @hidden
|
|
74
|
+
* */
|
|
55
75
|
update(callback: (doc: A.Doc<T>) => A.Doc<T>): void;
|
|
56
76
|
/** `change` is called by the repo when the document is changed locally */
|
|
57
77
|
change(callback: A.ChangeFn<T>, options?: A.ChangeOptions<T>): void;
|
|
@@ -61,9 +81,13 @@ export declare class DocHandle<T>//
|
|
|
61
81
|
*/
|
|
62
82
|
changeAt(heads: A.Heads, callback: A.ChangeFn<T>, options?: A.ChangeOptions<T>): string[] | undefined;
|
|
63
83
|
unavailable(): void;
|
|
64
|
-
/** `request` is called by the repo when the document is not found in storage
|
|
84
|
+
/** `request` is called by the repo when the document is not found in storage
|
|
85
|
+
* @hidden
|
|
86
|
+
* */
|
|
65
87
|
request(): void;
|
|
88
|
+
/** @hidden */
|
|
66
89
|
awaitNetwork(): void;
|
|
90
|
+
/** @hidden */
|
|
67
91
|
networkReady(): void;
|
|
68
92
|
/** `delete` is called by the repo when the document is deleted */
|
|
69
93
|
delete(): void;
|
|
@@ -75,7 +99,8 @@ export declare class DocHandle<T>//
|
|
|
75
99
|
*/
|
|
76
100
|
broadcast(message: any): void;
|
|
77
101
|
}
|
|
78
|
-
|
|
102
|
+
/** @hidden */
|
|
103
|
+
export interface DocHandleOptions {
|
|
79
104
|
isNew?: boolean;
|
|
80
105
|
timeoutDelay?: number;
|
|
81
106
|
}
|
|
@@ -91,10 +116,15 @@ export interface DocHandleEncodedChangePayload<T> {
|
|
|
91
116
|
export interface DocHandleDeletePayload<T> {
|
|
92
117
|
handle: DocHandle<T>;
|
|
93
118
|
}
|
|
119
|
+
/** Emitted when a document has changed */
|
|
94
120
|
export interface DocHandleChangePayload<T> {
|
|
121
|
+
/** The hande which changed */
|
|
95
122
|
handle: DocHandle<T>;
|
|
123
|
+
/** The value of the document after the change */
|
|
96
124
|
doc: A.Doc<T>;
|
|
125
|
+
/** The patches representing the change that occurred */
|
|
97
126
|
patches: A.Patch[];
|
|
127
|
+
/** Information about the change */
|
|
98
128
|
patchInfo: A.PatchInfo<T>;
|
|
99
129
|
}
|
|
100
130
|
export interface DocHandleEphemeralMessagePayload {
|
|
@@ -114,14 +144,27 @@ export interface DocHandleEvents<T> {
|
|
|
114
144
|
"ephemeral-message": (payload: DocHandleEphemeralMessagePayload) => void;
|
|
115
145
|
"ephemeral-message-outbound": (payload: DocHandleOutboundEphemeralMessagePayload) => void;
|
|
116
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* The state of a document handle
|
|
149
|
+
* @enum
|
|
150
|
+
*
|
|
151
|
+
*/
|
|
117
152
|
export declare const HandleState: {
|
|
153
|
+
/** The handle has been created but not yet loaded or requested */
|
|
118
154
|
readonly IDLE: "idle";
|
|
155
|
+
/** We are waiting for storage to finish loading */
|
|
119
156
|
readonly LOADING: "loading";
|
|
157
|
+
/** We are waiting for the network to be come ready */
|
|
120
158
|
readonly AWAITING_NETWORK: "awaitingNetwork";
|
|
159
|
+
/** We are waiting for someone in the network to respond to a sync request */
|
|
121
160
|
readonly REQUESTING: "requesting";
|
|
161
|
+
/** The document is available */
|
|
122
162
|
readonly READY: "ready";
|
|
163
|
+
/** We were unable to load or request the document for some reason */
|
|
123
164
|
readonly FAILED: "failed";
|
|
165
|
+
/** The document has been deleted from the repo */
|
|
124
166
|
readonly DELETED: "deleted";
|
|
167
|
+
/** The document was not available in storage or from any connected peers */
|
|
125
168
|
readonly UNAVAILABLE: "unavailable";
|
|
126
169
|
};
|
|
127
170
|
export type HandleState = (typeof HandleState)[keyof typeof HandleState];
|
|
@@ -138,5 +181,4 @@ export declare const Event: {
|
|
|
138
181
|
readonly MARK_UNAVAILABLE: "MARK_UNAVAILABLE";
|
|
139
182
|
};
|
|
140
183
|
export declare const IDLE: "idle", LOADING: "loading", AWAITING_NETWORK: "awaitingNetwork", REQUESTING: "requesting", READY: "ready", FAILED: "failed", DELETED: "deleted", UNAVAILABLE: "unavailable";
|
|
141
|
-
export {};
|
|
142
184
|
//# sourceMappingURL=DocHandle.d.ts.map
|
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,2BAA2B,CAAA;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EASL,UAAU,EAEX,MAAM,QAAQ,CAAA;AAKf,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAIlE
|
|
1
|
+
{"version":3,"file":"DocHandle.d.ts","sourceRoot":"","sources":["../src/DocHandle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,2BAA2B,CAAA;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EASL,UAAU,EAEX,MAAM,QAAQ,CAAA;AAKf,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAIlE;;;;;;;;;;;KAWK;AACL,qBAAa,SAAS,CAAC,CAAC,CAAE,EAAE;AAC1B,SAAQ,YAAY,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;;IAkB/B,UAAU,EAAE,UAAU;IAX/B;;;;OAIG;IACH,IAAI,GAAG,IAAI,YAAY,CAEtB;IAED,cAAc;gBAEL,UAAU,EAAE,UAAU,EAC7B,EAAE,KAAa,EAAE,YAAqB,EAAE,GAAE,gBAAqB;IAmMjE;;;;OAIG;IACH,OAAO,gBAA0C;IACjD;;;;;OAKG;IACH,SAAS,gBAA4C;IACrD,aAAa,gBAAgD;IAC7D,OAAO,WAAY,WAAW,EAAE,aACmB;IAEnD,cAAc;IACd,IAAI,KAAK,eAER;IAED;;;;;OAKG;IACG,SAAS,CAAC,WAAW,GAAE,WAAW,EAAY,GAAG,OAAO,CAAC,IAA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AO,MAAM,WAAW;IACtB,kEAAkE;;IAElE,mDAAmD;;IAEnD,sDAAsD;;IAEtD,6EAA6E;;IAE7E,gCAAgC;;IAEhC,qEAAqE;;IAErE,kDAAkD;;IAElD,4EAA4E;;CAEpE,CAAA;AACV,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAA;AAkBxE,eAAO,MAAM,KAAK;;;;;;;;;;;CAWR,CAAA;AA8CV,eAAO,MACL,IAAI,UACJ,OAAO,aACP,gBAAgB,qBAChB,UAAU,gBACV,KAAK,WACL,MAAM,YACN,OAAO,aACP,WAAW,eACE,CAAA"}
|
package/dist/DocHandle.js
CHANGED
|
@@ -8,16 +8,33 @@ import { pause } from "./helpers/pause.js";
|
|
|
8
8
|
import { TimeoutError, withTimeout } from "./helpers/withTimeout.js";
|
|
9
9
|
import { stringifyAutomergeUrl } from "./DocUrl.js";
|
|
10
10
|
import { encode } from "./helpers/cbor.js";
|
|
11
|
-
/** DocHandle is a wrapper around a single Automerge document that lets us
|
|
11
|
+
/** DocHandle is a wrapper around a single Automerge document that lets us
|
|
12
|
+
* listen for changes and notify the network and storage of new changes.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* A `DocHandle` represents a document which is being managed by a {@link Repo}.
|
|
16
|
+
* To obtain `DocHandle` use {@link Repo.find} or {@link Repo.create}.
|
|
17
|
+
*
|
|
18
|
+
* To modify the underlying document use either {@link DocHandle.change} or
|
|
19
|
+
* {@link DocHandle.changeAt}. These methods will notify the `Repo` that some
|
|
20
|
+
* change has occured and the `Repo` will save any new changes to the
|
|
21
|
+
* attached {@link StorageAdapter} and send sync messages to connected peers.
|
|
22
|
+
* */
|
|
12
23
|
export class DocHandle//
|
|
13
24
|
extends EventEmitter {
|
|
14
25
|
documentId;
|
|
15
26
|
#log;
|
|
16
27
|
#machine;
|
|
17
28
|
#timeoutDelay;
|
|
29
|
+
/** The URL of this document
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* This can be used to request the document from an instance of {@link Repo}
|
|
33
|
+
*/
|
|
18
34
|
get url() {
|
|
19
35
|
return stringifyAutomergeUrl({ documentId: this.documentId });
|
|
20
36
|
}
|
|
37
|
+
/** @hidden */
|
|
21
38
|
constructor(documentId, { isNew = false, timeoutDelay = 60_000 } = {}) {
|
|
22
39
|
super();
|
|
23
40
|
this.documentId = documentId;
|
|
@@ -200,6 +217,7 @@ export class DocHandle//
|
|
|
200
217
|
isDeleted = () => this.inState([HandleState.DELETED]);
|
|
201
218
|
isUnavailable = () => this.inState([HandleState.UNAVAILABLE]);
|
|
202
219
|
inState = (states) => states.some(this.#machine?.getSnapshot().matches);
|
|
220
|
+
/** @hidden */
|
|
203
221
|
get state() {
|
|
204
222
|
return this.#machine?.getSnapshot().value;
|
|
205
223
|
}
|
|
@@ -250,7 +268,9 @@ export class DocHandle//
|
|
|
250
268
|
}
|
|
251
269
|
return this.#doc;
|
|
252
270
|
}
|
|
253
|
-
/** `update` is called by the repo when we receive changes from the network
|
|
271
|
+
/** `update` is called by the repo when we receive changes from the network
|
|
272
|
+
* @hidden
|
|
273
|
+
* */
|
|
254
274
|
update(callback) {
|
|
255
275
|
this.#machine.send(UPDATE, {
|
|
256
276
|
payload: { callback },
|
|
@@ -292,15 +312,19 @@ export class DocHandle//
|
|
|
292
312
|
unavailable() {
|
|
293
313
|
this.#machine.send(MARK_UNAVAILABLE);
|
|
294
314
|
}
|
|
295
|
-
/** `request` is called by the repo when the document is not found in storage
|
|
315
|
+
/** `request` is called by the repo when the document is not found in storage
|
|
316
|
+
* @hidden
|
|
317
|
+
* */
|
|
296
318
|
request() {
|
|
297
319
|
if (this.#state === LOADING)
|
|
298
320
|
this.#machine.send(REQUEST);
|
|
299
321
|
}
|
|
322
|
+
/** @hidden */
|
|
300
323
|
awaitNetwork() {
|
|
301
324
|
if (this.#state === LOADING)
|
|
302
325
|
this.#machine.send(AWAIT_NETWORK);
|
|
303
326
|
}
|
|
327
|
+
/** @hidden */
|
|
304
328
|
networkReady() {
|
|
305
329
|
if (this.#state === AWAITING_NETWORK)
|
|
306
330
|
this.#machine.send(NETWORK_READY);
|
|
@@ -324,14 +348,27 @@ export class DocHandle//
|
|
|
324
348
|
}
|
|
325
349
|
// STATE MACHINE TYPES
|
|
326
350
|
// state
|
|
351
|
+
/**
|
|
352
|
+
* The state of a document handle
|
|
353
|
+
* @enum
|
|
354
|
+
*
|
|
355
|
+
*/
|
|
327
356
|
export const HandleState = {
|
|
357
|
+
/** The handle has been created but not yet loaded or requested */
|
|
328
358
|
IDLE: "idle",
|
|
359
|
+
/** We are waiting for storage to finish loading */
|
|
329
360
|
LOADING: "loading",
|
|
361
|
+
/** We are waiting for the network to be come ready */
|
|
330
362
|
AWAITING_NETWORK: "awaitingNetwork",
|
|
363
|
+
/** We are waiting for someone in the network to respond to a sync request */
|
|
331
364
|
REQUESTING: "requesting",
|
|
365
|
+
/** The document is available */
|
|
332
366
|
READY: "ready",
|
|
367
|
+
/** We were unable to load or request the document for some reason */
|
|
333
368
|
FAILED: "failed",
|
|
369
|
+
/** The document has been deleted from the repo */
|
|
334
370
|
DELETED: "deleted",
|
|
371
|
+
/** The document was not available in storage or from any connected peers */
|
|
335
372
|
UNAVAILABLE: "unavailable",
|
|
336
373
|
};
|
|
337
374
|
// events
|
package/dist/DocUrl.d.ts
CHANGED
|
@@ -10,9 +10,6 @@ export declare const parseAutomergeUrl: (url: AutomergeUrl) => {
|
|
|
10
10
|
binaryDocumentId: BinaryDocumentId;
|
|
11
11
|
documentId: DocumentId;
|
|
12
12
|
};
|
|
13
|
-
interface StringifyAutomergeUrlOptions {
|
|
14
|
-
documentId: DocumentId | BinaryDocumentId;
|
|
15
|
-
}
|
|
16
13
|
/**
|
|
17
14
|
* Given a documentId in either canonical form, return an Automerge URL
|
|
18
15
|
* Throws on invalid input.
|
|
@@ -20,7 +17,9 @@ interface StringifyAutomergeUrlOptions {
|
|
|
20
17
|
* @param { documentId: BinaryDocumentId | DocumentId }
|
|
21
18
|
* @returns AutomergeUrl
|
|
22
19
|
*/
|
|
23
|
-
export declare const stringifyAutomergeUrl: ({ documentId, }:
|
|
20
|
+
export declare const stringifyAutomergeUrl: ({ documentId, }: {
|
|
21
|
+
documentId: DocumentId | BinaryDocumentId;
|
|
22
|
+
}) => AutomergeUrl;
|
|
24
23
|
/**
|
|
25
24
|
* Given a string, return true if it is a valid Automerge URL
|
|
26
25
|
* also acts as a type discriminator in Typescript.
|
|
@@ -36,5 +35,5 @@ export declare const isValidAutomergeUrl: (str: string) => str is AutomergeUrl;
|
|
|
36
35
|
export declare const generateAutomergeUrl: () => AutomergeUrl;
|
|
37
36
|
export declare const documentIdToBinary: (docId: DocumentId) => BinaryDocumentId | undefined;
|
|
38
37
|
export declare const binaryToDocumentId: (docId: BinaryDocumentId) => DocumentId;
|
|
39
|
-
export
|
|
38
|
+
export declare const parseLegacyUUID: (str: string) => AutomergeUrl | undefined;
|
|
40
39
|
//# sourceMappingURL=DocUrl.d.ts.map
|
package/dist/DocUrl.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DocUrl.d.ts","sourceRoot":"","sources":["../src/DocUrl.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EAChB,MAAM,YAAY,CAAA;AAInB,eAAO,MAAM,SAAS,eAAe,CAAA;AAErC;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,QAAS,YAAY;;;CAIlD,CAAA;AAED
|
|
1
|
+
{"version":3,"file":"DocUrl.d.ts","sourceRoot":"","sources":["../src/DocUrl.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EAChB,MAAM,YAAY,CAAA;AAInB,eAAO,MAAM,SAAS,eAAe,CAAA;AAErC;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,QAAS,YAAY;;;CAIlD,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB;gBAElB,UAAU,GAAG,gBAAgB;MAAI,YAQhD,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,QAAS,MAAM,wBAK9C,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,QAAO,YAGpC,CAAA;AAEJ,eAAO,MAAM,kBAAkB,UACtB,UAAU,KAChB,gBAAgB,GAAG,SACyC,CAAA;AAE/D,eAAO,MAAM,kBAAkB,UAAW,gBAAgB,KAAG,UACtB,CAAA;AAEvC,eAAO,MAAM,eAAe,QAAS,MAAM,KAAG,YAAY,GAAG,SAM5D,CAAA"}
|
package/dist/DocUrl.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as Uuid from "uuid";
|
|
2
2
|
import bs58check from "bs58check";
|
|
3
3
|
export const urlPrefix = "automerge:";
|
|
4
4
|
/**
|
|
@@ -47,10 +47,17 @@ export const isValidAutomergeUrl = (str) => {
|
|
|
47
47
|
* @returns a new Automerge URL with a random UUID documentId
|
|
48
48
|
*/
|
|
49
49
|
export const generateAutomergeUrl = () => stringifyAutomergeUrl({
|
|
50
|
-
documentId:
|
|
50
|
+
documentId: Uuid.v4(null, new Uint8Array(16)),
|
|
51
51
|
});
|
|
52
52
|
export const documentIdToBinary = (docId) => bs58check.decodeUnsafe(docId);
|
|
53
53
|
export const binaryToDocumentId = (docId) => bs58check.encode(docId);
|
|
54
|
+
export const parseLegacyUUID = (str) => {
|
|
55
|
+
if (Uuid.validate(str)) {
|
|
56
|
+
const uuid = Uuid.parse(str);
|
|
57
|
+
return stringifyAutomergeUrl({ documentId: uuid });
|
|
58
|
+
}
|
|
59
|
+
return undefined;
|
|
60
|
+
};
|
|
54
61
|
/**
|
|
55
62
|
* parts breaks up the URL into constituent pieces,
|
|
56
63
|
* eventually this could include things like heads, so we use this structure
|
package/dist/EphemeralData.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EphemeralData.d.ts","sourceRoot":"","sources":["../src/EphemeralData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;AAGhE,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG;IAAE,WAAW,EAAE,KAAK,CAAA;CAAE,CAAA;AAEvD,MAAM,WAAW,oBAAoB;IACnC,UAAU,EAAE,UAAU,CAAA;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,UAAU,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,CAAA;CAChE;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,OAAO,EAAE,CAAC,KAAK,EAAE,wBAAwB,KAAK,IAAI,CAAA;IAClD,IAAI,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,IAAI,CAAA;CAC5C,CAAA"}
|
|
1
|
+
{"version":3,"file":"EphemeralData.d.ts","sourceRoot":"","sources":["../src/EphemeralData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;AAGhE,0EAA0E;AAC1E,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG;IAAE,WAAW,EAAE,KAAK,CAAA;CAAE,CAAA;AAEvD,MAAM,WAAW,oBAAoB;IACnC,UAAU,EAAE,UAAU,CAAA;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,UAAU,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,CAAA;CAChE;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,OAAO,EAAE,CAAC,KAAK,EAAE,wBAAwB,KAAK,IAAI,CAAA;IAClD,IAAI,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,IAAI,CAAA;CAC5C,CAAA"}
|
package/dist/Repo.d.ts
CHANGED
|
@@ -6,11 +6,21 @@ import { type AutomergeUrl, DocumentId, PeerId } from "./types.js";
|
|
|
6
6
|
import { DocHandle } from "./DocHandle.js";
|
|
7
7
|
import { EventEmitter } from "eventemitter3";
|
|
8
8
|
/** A Repo is a collection of documents with networking, syncing, and storage capabilities. */
|
|
9
|
-
|
|
9
|
+
/** The `Repo` is the main entry point of this library
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* To construct a `Repo` you will need an {@link StorageAdapter} and one or
|
|
13
|
+
* more {@link NetworkAdapter}s. Once you have a `Repo` you can use it to
|
|
14
|
+
* obtain {@link DocHandle}s.
|
|
15
|
+
*/
|
|
16
|
+
export declare class Repo extends EventEmitter<RepoEvents> {
|
|
10
17
|
#private;
|
|
18
|
+
/** @hidden */
|
|
11
19
|
networkSubsystem: NetworkSubsystem;
|
|
20
|
+
/** @hidden */
|
|
12
21
|
storageSubsystem?: StorageSubsystem;
|
|
13
22
|
/** By default, we share generously with all peers. */
|
|
23
|
+
/** @hidden */
|
|
14
24
|
sharePolicy: SharePolicy;
|
|
15
25
|
constructor({ storage, network, peerId, sharePolicy }: RepoConfig);
|
|
16
26
|
/** Returns all the handles we have cached. */
|
|
@@ -45,18 +55,28 @@ export interface RepoConfig {
|
|
|
45
55
|
*/
|
|
46
56
|
sharePolicy?: SharePolicy;
|
|
47
57
|
}
|
|
58
|
+
/** A function that determines whether we should share a document with a peer
|
|
59
|
+
*
|
|
60
|
+
* @remarks
|
|
61
|
+
* This function is called by the {@link Repo} every time a new document is created
|
|
62
|
+
* or discovered (such as when another peer starts syncing with us). If this
|
|
63
|
+
* function returns `true` then the {@link Repo} will begin sharing the new
|
|
64
|
+
* document with the peer given by `peerId`.
|
|
65
|
+
* */
|
|
48
66
|
export type SharePolicy = (peerId: PeerId, documentId?: DocumentId) => Promise<boolean>;
|
|
49
|
-
interface
|
|
67
|
+
export interface RepoEvents {
|
|
68
|
+
/** A new document was created or discovered */
|
|
50
69
|
document: (arg: DocumentPayload) => void;
|
|
70
|
+
/** A document was deleted */
|
|
51
71
|
"delete-document": (arg: DeleteDocumentPayload) => void;
|
|
72
|
+
/** A document was marked as unavailable (we don't have it and none of our peers have it) */
|
|
52
73
|
"unavailable-document": (arg: DeleteDocumentPayload) => void;
|
|
53
74
|
}
|
|
54
|
-
interface DocumentPayload {
|
|
75
|
+
export interface DocumentPayload {
|
|
55
76
|
handle: DocHandle<any>;
|
|
56
77
|
isNew: boolean;
|
|
57
78
|
}
|
|
58
|
-
interface DeleteDocumentPayload {
|
|
79
|
+
export interface DeleteDocumentPayload {
|
|
59
80
|
documentId: DocumentId;
|
|
60
81
|
}
|
|
61
|
-
export {};
|
|
62
82
|
//# sourceMappingURL=Repo.d.ts.map
|
package/dist/Repo.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Repo.d.ts","sourceRoot":"","sources":["../src/Repo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAEhE,OAAO,EAAE,KAAK,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"Repo.d.ts","sourceRoot":"","sources":["../src/Repo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAChE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CAAC,OAAO,CAAC,CAAA;AAGrB,MAAM,WAAW,UAAU;IACzB,+CAA+C;IAC/C,QAAQ,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,IAAI,CAAA;IACxC,6BAA6B;IAC7B,iBAAiB,EAAE,CAAC,GAAG,EAAE,qBAAqB,KAAK,IAAI,CAAA;IACvD,4FAA4F;IAC5F,sBAAsB,EAAE,CAAC,GAAG,EAAE,qBAAqB,KAAK,IAAI,CAAA;CAC7D;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,CAAA;IACtB,KAAK,EAAE,OAAO,CAAA;CACf;AAED,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,UAAU,CAAA;CACvB"}
|
package/dist/Repo.js
CHANGED
|
@@ -2,16 +2,26 @@ import debug from "debug";
|
|
|
2
2
|
import { NetworkSubsystem } from "./network/NetworkSubsystem.js";
|
|
3
3
|
import { StorageSubsystem } from "./storage/StorageSubsystem.js";
|
|
4
4
|
import { CollectionSynchronizer } from "./synchronizer/CollectionSynchronizer.js";
|
|
5
|
-
import { parseAutomergeUrl, generateAutomergeUrl, isValidAutomergeUrl } from "./DocUrl.js";
|
|
5
|
+
import { parseAutomergeUrl, generateAutomergeUrl, isValidAutomergeUrl, parseLegacyUUID, } from "./DocUrl.js";
|
|
6
6
|
import { DocHandle } from "./DocHandle.js";
|
|
7
7
|
import { EventEmitter } from "eventemitter3";
|
|
8
8
|
/** A Repo is a collection of documents with networking, syncing, and storage capabilities. */
|
|
9
|
+
/** The `Repo` is the main entry point of this library
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* To construct a `Repo` you will need an {@link StorageAdapter} and one or
|
|
13
|
+
* more {@link NetworkAdapter}s. Once you have a `Repo` you can use it to
|
|
14
|
+
* obtain {@link DocHandle}s.
|
|
15
|
+
*/
|
|
9
16
|
export class Repo extends EventEmitter {
|
|
10
17
|
#log;
|
|
18
|
+
/** @hidden */
|
|
11
19
|
networkSubsystem;
|
|
20
|
+
/** @hidden */
|
|
12
21
|
storageSubsystem;
|
|
13
22
|
#handleCache = {};
|
|
14
23
|
/** By default, we share generously with all peers. */
|
|
24
|
+
/** @hidden */
|
|
15
25
|
sharePolicy = async () => true;
|
|
16
26
|
constructor({ storage, network, peerId, sharePolicy }) {
|
|
17
27
|
super();
|
|
@@ -49,9 +59,12 @@ export class Repo extends EventEmitter {
|
|
|
49
59
|
}
|
|
50
60
|
else {
|
|
51
61
|
handle.awaitNetwork();
|
|
52
|
-
this.networkSubsystem
|
|
62
|
+
this.networkSubsystem
|
|
63
|
+
.whenReady()
|
|
64
|
+
.then(() => {
|
|
53
65
|
handle.networkReady();
|
|
54
|
-
})
|
|
66
|
+
})
|
|
67
|
+
.catch(err => {
|
|
55
68
|
this.#log("error waiting for network", { err });
|
|
56
69
|
});
|
|
57
70
|
}
|
|
@@ -151,7 +164,14 @@ export class Repo extends EventEmitter {
|
|
|
151
164
|
/** The documentId of the handle to retrieve */
|
|
152
165
|
automergeUrl) {
|
|
153
166
|
if (!isValidAutomergeUrl(automergeUrl)) {
|
|
154
|
-
|
|
167
|
+
let maybeAutomergeUrl = parseLegacyUUID(automergeUrl);
|
|
168
|
+
if (maybeAutomergeUrl) {
|
|
169
|
+
console.warn("Legacy UUID document ID detected, converting to AutomergeUrl. This will be removed in a future version.");
|
|
170
|
+
automergeUrl = maybeAutomergeUrl;
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
throw new Error(`Invalid AutomergeUrl: '${automergeUrl}'`);
|
|
174
|
+
}
|
|
155
175
|
}
|
|
156
176
|
const { documentId } = parseAutomergeUrl(automergeUrl);
|
|
157
177
|
// If we have the handle cached, return it
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* The [`automerge`](https://www.npmjs.com/package/@automerge/automerge) CRDT
|
|
5
|
+
* provides a core CRDT data structure and an implementation of a storage
|
|
6
|
+
* format and sync protocol but doesn't provide the plumbing to use these tools
|
|
7
|
+
* in a JS application. `automerge-repo` provides the plumbing.
|
|
8
|
+
*
|
|
9
|
+
* The main entry point is the {@link Repo} class, which you instantiate with
|
|
10
|
+
* a {@link StorageAdapter} and zero or more {@link NetworkAdapter}s. Once you
|
|
11
|
+
* have a repo you can use it to create {@link DocHandle}s. {@link DocHandle}s
|
|
12
|
+
* are a reference to a document, identified by a {@link AutomergeUrl}, a place to
|
|
13
|
+
* listen for changes to the document, and to make new changes.
|
|
14
|
+
*
|
|
15
|
+
* A typical example of how to use this library then might look like this:
|
|
16
|
+
*
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { Repo } from "@automerge/automerge-repo";
|
|
19
|
+
*
|
|
20
|
+
* const repo = new Repo({
|
|
21
|
+
* storage: <storage adapter>,
|
|
22
|
+
* network: [<network adapter>, <network adapter>]
|
|
23
|
+
* })
|
|
24
|
+
*
|
|
25
|
+
* const handle = repo.create
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export { DocHandle, type HandleState, type DocHandleOptions, type DocHandleEvents } from "./DocHandle.js";
|
|
29
|
+
export type { DocHandleChangePayload, DocHandleDeletePayload, DocHandleEphemeralMessagePayload, DocHandleOutboundEphemeralMessagePayload, DocHandleEncodedChangePayload, } from "./DocHandle.js";
|
|
3
30
|
export { NetworkAdapter } from "./network/NetworkAdapter.js";
|
|
4
|
-
export type { OpenPayload, PeerCandidatePayload, PeerDisconnectedPayload, } from "./network/NetworkAdapter.js";
|
|
5
|
-
export type { Message, NetworkAdapterMessage, EphemeralMessage, SyncMessage, } from "./network/messages.js";
|
|
31
|
+
export type { OpenPayload, PeerCandidatePayload, PeerDisconnectedPayload, NetworkAdapterEvents, } from "./network/NetworkAdapter.js";
|
|
32
|
+
export type { Message, ArriveMessage, WelcomeMessage, NetworkAdapterMessage, EphemeralMessage, RequestMessage, DocumentUnavailableMessage, SyncMessage, SessionId, } from "./network/messages.js";
|
|
6
33
|
export { isValidMessage } from "./network/messages.js";
|
|
7
|
-
export {
|
|
8
|
-
export { Repo, type SharePolicy } from "./Repo.js";
|
|
34
|
+
export { Repo, type SharePolicy, type RepoConfig, type RepoEvents, type DeleteDocumentPayload, type DocumentPayload } from "./Repo.js";
|
|
9
35
|
export { StorageAdapter, type StorageKey } from "./storage/StorageAdapter.js";
|
|
10
|
-
export { StorageSubsystem } from "./storage/StorageSubsystem.js";
|
|
11
|
-
export { CollectionSynchronizer } from "./synchronizer/CollectionSynchronizer.js";
|
|
12
36
|
export { parseAutomergeUrl, isValidAutomergeUrl, stringifyAutomergeUrl as generateAutomergeUrl, } from "./DocUrl.js";
|
|
13
37
|
export * from "./types.js";
|
|
38
|
+
/** @hidden **/
|
|
14
39
|
export * as cbor from "./helpers/cbor.js";
|
|
15
40
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,SAAS,EAAE,KAAK,WAAW,EAAE,KAAK,gBAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACzG,YAAY,EACV,sBAAsB,EACtB,sBAAsB,EACtB,gCAAgC,EAChC,wCAAwC,EACxC,6BAA6B,GAC9B,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,YAAY,EACV,WAAW,EACX,oBAAoB,EACpB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,6BAA6B,CAAA;AAMpC,YAAY,EACV,OAAO,EACP,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,gBAAgB,EAChB,cAAc,EACd,0BAA0B,EAC1B,WAAW,EACX,SAAS,GACV,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEtD,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,KAAK,qBAAqB,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAA;AACtI,OAAO,EAAE,cAAc,EAAE,KAAK,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAC7E,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,IAAI,oBAAoB,GAC9C,MAAM,aAAa,CAAA;AACpB,cAAc,YAAY,CAAA;AAE1B,eAAe;AACf,OAAO,KAAK,IAAI,MAAM,mBAAmB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* The [`automerge`](https://www.npmjs.com/package/@automerge/automerge) CRDT
|
|
5
|
+
* provides a core CRDT data structure and an implementation of a storage
|
|
6
|
+
* format and sync protocol but doesn't provide the plumbing to use these tools
|
|
7
|
+
* in a JS application. `automerge-repo` provides the plumbing.
|
|
8
|
+
*
|
|
9
|
+
* The main entry point is the {@link Repo} class, which you instantiate with
|
|
10
|
+
* a {@link StorageAdapter} and zero or more {@link NetworkAdapter}s. Once you
|
|
11
|
+
* have a repo you can use it to create {@link DocHandle}s. {@link DocHandle}s
|
|
12
|
+
* are a reference to a document, identified by a {@link AutomergeUrl}, a place to
|
|
13
|
+
* listen for changes to the document, and to make new changes.
|
|
14
|
+
*
|
|
15
|
+
* A typical example of how to use this library then might look like this:
|
|
16
|
+
*
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { Repo } from "@automerge/automerge-repo";
|
|
19
|
+
*
|
|
20
|
+
* const repo = new Repo({
|
|
21
|
+
* storage: <storage adapter>,
|
|
22
|
+
* network: [<network adapter>, <network adapter>]
|
|
23
|
+
* })
|
|
24
|
+
*
|
|
25
|
+
* const handle = repo.create
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export { DocHandle } from "./DocHandle.js";
|
|
2
29
|
export { NetworkAdapter } from "./network/NetworkAdapter.js";
|
|
3
30
|
export { isValidMessage } from "./network/messages.js";
|
|
4
|
-
export { NetworkSubsystem } from "./network/NetworkSubsystem.js";
|
|
5
31
|
export { Repo } from "./Repo.js";
|
|
6
32
|
export { StorageAdapter } from "./storage/StorageAdapter.js";
|
|
7
|
-
export { StorageSubsystem } from "./storage/StorageSubsystem.js";
|
|
8
|
-
export { CollectionSynchronizer } from "./synchronizer/CollectionSynchronizer.js";
|
|
9
33
|
export { parseAutomergeUrl, isValidAutomergeUrl, stringifyAutomergeUrl as generateAutomergeUrl, } from "./DocUrl.js";
|
|
10
34
|
export * from "./types.js";
|
|
35
|
+
/** @hidden **/
|
|
11
36
|
export * as cbor from "./helpers/cbor.js";
|
|
@@ -1,17 +1,38 @@
|
|
|
1
1
|
import { EventEmitter } from "eventemitter3";
|
|
2
2
|
import { PeerId } from "../types.js";
|
|
3
3
|
import { Message } from "./messages.js";
|
|
4
|
+
/** An interface representing some way to connect to other peers
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* The {@link Repo} uses one or more `NetworkAdapter`s to connect to other peers.
|
|
8
|
+
* Because the network may take some time to be ready the {@link Repo} will wait
|
|
9
|
+
* until the adapter emits a `ready` event before it starts trying to use it
|
|
10
|
+
*/
|
|
4
11
|
export declare abstract class NetworkAdapter extends EventEmitter<NetworkAdapterEvents> {
|
|
5
12
|
peerId?: PeerId;
|
|
13
|
+
/** Called by the {@link Repo} to start the connection process
|
|
14
|
+
*
|
|
15
|
+
* @argument peerId - the peerId of this repo
|
|
16
|
+
*/
|
|
6
17
|
abstract connect(peerId: PeerId): void;
|
|
18
|
+
/** Called by the {@link Repo} to send a message to a peer
|
|
19
|
+
*
|
|
20
|
+
* @argument message - the message to send
|
|
21
|
+
*/
|
|
7
22
|
abstract send(message: Message): void;
|
|
23
|
+
/** Called by the {@link Repo} to disconnect from the network */
|
|
8
24
|
abstract disconnect(): void;
|
|
9
25
|
}
|
|
10
26
|
export interface NetworkAdapterEvents {
|
|
27
|
+
/** Emitted when the network is ready to be used */
|
|
11
28
|
ready: (payload: OpenPayload) => void;
|
|
29
|
+
/** Emitted when the network is closed */
|
|
12
30
|
close: () => void;
|
|
31
|
+
/** Emitted when the network adapter learns about a new peer */
|
|
13
32
|
"peer-candidate": (payload: PeerCandidatePayload) => void;
|
|
33
|
+
/** Emitted when the network adapter learns that a peer has disconnected */
|
|
14
34
|
"peer-disconnected": (payload: PeerDisconnectedPayload) => void;
|
|
35
|
+
/** Emitted when the network adapter receives a message from a peer */
|
|
15
36
|
message: (payload: Message) => void;
|
|
16
37
|
}
|
|
17
38
|
export interface OpenPayload {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkAdapter.d.ts","sourceRoot":"","sources":["../../src/network/NetworkAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAEvC,8BAAsB,cAAe,SAAQ,YAAY,CAAC,oBAAoB,CAAC;IAC7E,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAEtC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAErC,QAAQ,CAAC,UAAU,IAAI,IAAI;CAC5B;AAID,MAAM,WAAW,oBAAoB;IACnC,KAAK,EA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KAAK,IAAI,CAAA;IACzD,2EAA2E;IAC3E,mBAAmB,EAAE,CAAC,OAAO,EAAE,uBAAuB,KAAK,IAAI,CAAA;IAC/D,sEAAsE;IACtE,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;CACpC;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,cAAc,CAAA;CACxB;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAA;CACf"}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { EventEmitter } from "eventemitter3";
|
|
2
|
+
/** An interface representing some way to connect to other peers
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* The {@link Repo} uses one or more `NetworkAdapter`s to connect to other peers.
|
|
6
|
+
* Because the network may take some time to be ready the {@link Repo} will wait
|
|
7
|
+
* until the adapter emits a `ready` event before it starts trying to use it
|
|
8
|
+
*/
|
|
2
9
|
export class NetworkAdapter extends EventEmitter {
|
|
3
10
|
peerId; // hmmm, maybe not
|
|
4
11
|
}
|