@automerge/automerge-repo 1.0.12 → 1.0.14
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/AutomergeUrl.d.ts +45 -0
- package/dist/AutomergeUrl.d.ts.map +1 -0
- package/dist/AutomergeUrl.js +108 -0
- package/dist/DocHandle.js +1 -1
- package/dist/Repo.d.ts +5 -5
- package/dist/Repo.d.ts.map +1 -1
- package/dist/Repo.js +10 -21
- package/dist/helpers/cbor.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/network/NetworkAdapter.d.ts +3 -3
- package/dist/network/NetworkAdapter.d.ts.map +1 -1
- package/dist/network/messages.d.ts +7 -18
- package/dist/network/messages.d.ts.map +1 -1
- package/dist/storage/StorageAdapter.d.ts +19 -22
- package/dist/storage/StorageAdapter.d.ts.map +1 -1
- package/dist/storage/StorageAdapter.js +2 -2
- package/dist/storage/StorageSubsystem.d.ts +39 -3
- package/dist/storage/StorageSubsystem.d.ts.map +1 -1
- package/dist/storage/StorageSubsystem.js +128 -75
- package/dist/storage/chunkTypeFromKey.d.ts +13 -0
- package/dist/storage/chunkTypeFromKey.d.ts.map +1 -0
- package/dist/storage/chunkTypeFromKey.js +18 -0
- package/dist/storage/keyHash.d.ts +4 -0
- package/dist/storage/keyHash.d.ts.map +1 -0
- package/dist/storage/keyHash.js +15 -0
- package/dist/storage/types.d.ts +37 -0
- package/dist/storage/types.d.ts.map +1 -0
- package/dist/storage/types.js +1 -0
- package/dist/synchronizer/CollectionSynchronizer.js +1 -1
- package/dist/types.d.ts +20 -12
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/AutomergeUrl.ts +144 -0
- package/src/DocHandle.ts +1 -1
- package/src/Repo.ts +14 -26
- package/src/helpers/cbor.ts +1 -1
- package/src/index.ts +12 -4
- package/src/network/NetworkAdapter.ts +3 -3
- package/src/network/messages.ts +8 -21
- package/src/storage/StorageAdapter.ts +23 -30
- package/src/storage/StorageSubsystem.ts +159 -93
- package/src/storage/chunkTypeFromKey.ts +22 -0
- package/src/storage/keyHash.ts +17 -0
- package/src/storage/types.ts +39 -0
- package/src/synchronizer/CollectionSynchronizer.ts +1 -1
- package/src/types.ts +23 -11
- package/test/AutomergeUrl.test.ts +100 -0
- package/test/DocHandle.test.ts +1 -1
- package/test/DocSynchronizer.test.ts +1 -1
- package/test/Repo.test.ts +22 -6
- package/test/StorageSubsystem.test.ts +144 -36
- package/test/helpers/DummyStorageAdapter.ts +2 -4
- package/dist/DocUrl.d.ts +0 -39
- package/dist/DocUrl.d.ts.map +0 -1
- package/dist/DocUrl.js +0 -74
- package/src/DocUrl.ts +0 -96
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { LegacyDocumentId, AutomergeUrl, BinaryDocumentId, DocumentId, AnyDocumentId } from "./types.js";
|
|
2
|
+
export declare const urlPrefix = "automerge:";
|
|
3
|
+
/** Given an Automerge URL, returns the DocumentId in both base58check-encoded form and binary form */
|
|
4
|
+
export declare const parseAutomergeUrl: (url: AutomergeUrl) => {
|
|
5
|
+
/** unencoded DocumentId */
|
|
6
|
+
binaryDocumentId: BinaryDocumentId;
|
|
7
|
+
/** encoded DocumentId */
|
|
8
|
+
documentId: DocumentId;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Given a documentId in either binary or base58check-encoded form, returns an Automerge URL.
|
|
12
|
+
* Throws on invalid input.
|
|
13
|
+
*/
|
|
14
|
+
export declare const stringifyAutomergeUrl: (arg: UrlOptions | DocumentId | BinaryDocumentId) => AutomergeUrl;
|
|
15
|
+
/**
|
|
16
|
+
* Given a string, returns true if it is a valid Automerge URL. This function also acts as a type
|
|
17
|
+
* discriminator in Typescript.
|
|
18
|
+
*/
|
|
19
|
+
export declare const isValidAutomergeUrl: (str: string | undefined | null) => str is AutomergeUrl;
|
|
20
|
+
export declare const isValidDocumentId: (str: string) => str is DocumentId;
|
|
21
|
+
export declare const isValidUuid: (str: string) => str is LegacyDocumentId;
|
|
22
|
+
/**
|
|
23
|
+
* Returns a new Automerge URL with a random UUID documentId. Called by Repo.create(), and also used by tests.
|
|
24
|
+
*/
|
|
25
|
+
export declare const generateAutomergeUrl: () => AutomergeUrl;
|
|
26
|
+
export declare const documentIdToBinary: (docId: DocumentId) => BinaryDocumentId | undefined;
|
|
27
|
+
export declare const binaryToDocumentId: (docId: BinaryDocumentId) => DocumentId;
|
|
28
|
+
export declare const parseLegacyUUID: (str: string) => AutomergeUrl | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Given any valid expression of a document ID, returns a DocumentId in base58check-encoded form.
|
|
31
|
+
*
|
|
32
|
+
* Currently supports:
|
|
33
|
+
* - base58check-encoded DocumentId
|
|
34
|
+
* - Automerge URL
|
|
35
|
+
* - legacy UUID
|
|
36
|
+
* - binary DocumentId
|
|
37
|
+
*
|
|
38
|
+
* Throws on invalid input.
|
|
39
|
+
*/
|
|
40
|
+
export declare const interpretAsDocumentId: (id: AnyDocumentId) => DocumentId;
|
|
41
|
+
type UrlOptions = {
|
|
42
|
+
documentId: DocumentId | BinaryDocumentId;
|
|
43
|
+
};
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=AutomergeUrl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AutomergeUrl.d.ts","sourceRoot":"","sources":["../src/AutomergeUrl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,aAAa,EACd,MAAM,YAAY,CAAA;AAInB,eAAO,MAAM,SAAS,eAAe,CAAA;AAErC,sGAAsG;AACtG,eAAO,MAAM,iBAAiB,QAAS,YAAY;IAQ/C,2BAA2B;;IAE3B,yBAAyB;;CAG5B,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,qBAAqB,QAC3B,UAAU,GAAG,UAAU,GAAG,gBAAgB,iBAoBhD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,mBAAmB,QACzB,MAAM,GAAG,SAAS,GAAG,IAAI,wBAU/B,CAAA;AAED,eAAO,MAAM,iBAAiB,QAAS,MAAM,sBAQ5C,CAAA;AAED,eAAO,MAAM,WAAW,QAAS,MAAM,4BACnB,CAAA;AAEpB;;GAEG;AACH,eAAO,MAAM,oBAAoB,QAAO,YAGvC,CAAA;AAED,eAAO,MAAM,kBAAkB,UAAW,UAAU,iCACW,CAAA;AAE/D,eAAO,MAAM,kBAAkB,UAAW,gBAAgB,eACnB,CAAA;AAEvC,eAAO,MAAM,eAAe,QAAS,MAAM,6BAI1C,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,OAAQ,aAAa,eAqBtD,CAAA;AAID,KAAK,UAAU,GAAG;IAChB,UAAU,EAAE,UAAU,GAAG,gBAAgB,CAAA;CAC1C,CAAA"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import * as Uuid from "uuid";
|
|
2
|
+
import bs58check from "bs58check";
|
|
3
|
+
export const urlPrefix = "automerge:";
|
|
4
|
+
/** Given an Automerge URL, returns the DocumentId in both base58check-encoded form and binary form */
|
|
5
|
+
export const parseAutomergeUrl = (url) => {
|
|
6
|
+
const regex = new RegExp(`^${urlPrefix}(\\w+)$`);
|
|
7
|
+
const [_, docMatch] = url.match(regex) || [];
|
|
8
|
+
const documentId = docMatch;
|
|
9
|
+
const binaryDocumentId = documentIdToBinary(documentId);
|
|
10
|
+
if (!binaryDocumentId)
|
|
11
|
+
throw new Error("Invalid document URL: " + url);
|
|
12
|
+
return {
|
|
13
|
+
/** unencoded DocumentId */
|
|
14
|
+
binaryDocumentId,
|
|
15
|
+
/** encoded DocumentId */
|
|
16
|
+
documentId,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Given a documentId in either binary or base58check-encoded form, returns an Automerge URL.
|
|
21
|
+
* Throws on invalid input.
|
|
22
|
+
*/
|
|
23
|
+
export const stringifyAutomergeUrl = (arg) => {
|
|
24
|
+
let documentId = arg instanceof Uint8Array || typeof arg === "string"
|
|
25
|
+
? arg
|
|
26
|
+
: "documentId" in arg
|
|
27
|
+
? arg.documentId
|
|
28
|
+
: undefined;
|
|
29
|
+
const encodedDocumentId = documentId instanceof Uint8Array
|
|
30
|
+
? binaryToDocumentId(documentId)
|
|
31
|
+
: typeof documentId === "string"
|
|
32
|
+
? documentId
|
|
33
|
+
: undefined;
|
|
34
|
+
if (encodedDocumentId === undefined)
|
|
35
|
+
throw new Error("Invalid documentId: " + documentId);
|
|
36
|
+
return (urlPrefix + encodedDocumentId);
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Given a string, returns true if it is a valid Automerge URL. This function also acts as a type
|
|
40
|
+
* discriminator in Typescript.
|
|
41
|
+
*/
|
|
42
|
+
export const isValidAutomergeUrl = (str) => {
|
|
43
|
+
if (!str || !str.startsWith(urlPrefix))
|
|
44
|
+
return false;
|
|
45
|
+
const automergeUrl = str;
|
|
46
|
+
try {
|
|
47
|
+
const { documentId } = parseAutomergeUrl(automergeUrl);
|
|
48
|
+
return isValidDocumentId(documentId);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
export const isValidDocumentId = (str) => {
|
|
55
|
+
// try to decode from base58
|
|
56
|
+
const binaryDocumentID = documentIdToBinary(str);
|
|
57
|
+
if (binaryDocumentID === undefined)
|
|
58
|
+
return false; // invalid base58check encoding
|
|
59
|
+
// confirm that the document ID is a valid UUID
|
|
60
|
+
const documentId = Uuid.stringify(binaryDocumentID);
|
|
61
|
+
return Uuid.validate(documentId);
|
|
62
|
+
};
|
|
63
|
+
export const isValidUuid = (str) => Uuid.validate(str);
|
|
64
|
+
/**
|
|
65
|
+
* Returns a new Automerge URL with a random UUID documentId. Called by Repo.create(), and also used by tests.
|
|
66
|
+
*/
|
|
67
|
+
export const generateAutomergeUrl = () => {
|
|
68
|
+
const documentId = Uuid.v4(null, new Uint8Array(16));
|
|
69
|
+
return stringifyAutomergeUrl({ documentId });
|
|
70
|
+
};
|
|
71
|
+
export const documentIdToBinary = (docId) => bs58check.decodeUnsafe(docId);
|
|
72
|
+
export const binaryToDocumentId = (docId) => bs58check.encode(docId);
|
|
73
|
+
export const parseLegacyUUID = (str) => {
|
|
74
|
+
if (!Uuid.validate(str))
|
|
75
|
+
return undefined;
|
|
76
|
+
const documentId = Uuid.parse(str);
|
|
77
|
+
return stringifyAutomergeUrl({ documentId });
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Given any valid expression of a document ID, returns a DocumentId in base58check-encoded form.
|
|
81
|
+
*
|
|
82
|
+
* Currently supports:
|
|
83
|
+
* - base58check-encoded DocumentId
|
|
84
|
+
* - Automerge URL
|
|
85
|
+
* - legacy UUID
|
|
86
|
+
* - binary DocumentId
|
|
87
|
+
*
|
|
88
|
+
* Throws on invalid input.
|
|
89
|
+
*/
|
|
90
|
+
export const interpretAsDocumentId = (id) => {
|
|
91
|
+
// binary
|
|
92
|
+
if (id instanceof Uint8Array)
|
|
93
|
+
return binaryToDocumentId(id);
|
|
94
|
+
// url
|
|
95
|
+
if (isValidAutomergeUrl(id))
|
|
96
|
+
return parseAutomergeUrl(id).documentId;
|
|
97
|
+
// base58check
|
|
98
|
+
if (isValidDocumentId(id))
|
|
99
|
+
return id;
|
|
100
|
+
// legacy UUID
|
|
101
|
+
if (isValidUuid(id)) {
|
|
102
|
+
console.warn("Future versions will not support UUIDs as document IDs; use Automerge URLs instead.");
|
|
103
|
+
const binaryDocumentID = Uuid.parse(id);
|
|
104
|
+
return binaryToDocumentId(binaryDocumentID);
|
|
105
|
+
}
|
|
106
|
+
// none of the above
|
|
107
|
+
throw new Error(`Invalid AutomergeUrl: '${id}'`);
|
|
108
|
+
};
|
package/dist/DocHandle.js
CHANGED
|
@@ -3,7 +3,7 @@ import debug from "debug";
|
|
|
3
3
|
import { EventEmitter } from "eventemitter3";
|
|
4
4
|
import { assign, createMachine, interpret, } from "xstate";
|
|
5
5
|
import { waitFor } from "xstate/lib/waitFor.js";
|
|
6
|
-
import { stringifyAutomergeUrl } from "./
|
|
6
|
+
import { stringifyAutomergeUrl } from "./AutomergeUrl.js";
|
|
7
7
|
import { encode } from "./helpers/cbor.js";
|
|
8
8
|
import { headsAreSame } from "./helpers/headsAreSame.js";
|
|
9
9
|
import { withTimeout } from "./helpers/withTimeout.js";
|
package/dist/Repo.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { NetworkAdapter } from "./network/NetworkAdapter.js";
|
|
|
4
4
|
import { NetworkSubsystem } from "./network/NetworkSubsystem.js";
|
|
5
5
|
import { StorageAdapter } from "./storage/StorageAdapter.js";
|
|
6
6
|
import { StorageSubsystem } from "./storage/StorageSubsystem.js";
|
|
7
|
-
import { DocumentId, PeerId
|
|
7
|
+
import type { AnyDocumentId, DocumentId, PeerId } from "./types.js";
|
|
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
10
|
*
|
|
@@ -55,11 +55,11 @@ export declare class Repo extends EventEmitter<RepoEvents> {
|
|
|
55
55
|
* event to advertise interest in the document.
|
|
56
56
|
*/
|
|
57
57
|
find<T>(
|
|
58
|
-
/** The documentId of the handle to retrieve */
|
|
59
|
-
|
|
58
|
+
/** The url or documentId of the handle to retrieve */
|
|
59
|
+
id: AnyDocumentId): DocHandle<T>;
|
|
60
60
|
delete(
|
|
61
|
-
/** The documentId of the handle to delete */
|
|
62
|
-
id:
|
|
61
|
+
/** The url or documentId of the handle to delete */
|
|
62
|
+
id: AnyDocumentId): void;
|
|
63
63
|
}
|
|
64
64
|
export interface RepoConfig {
|
|
65
65
|
/** Our unique identifier */
|
package/dist/Repo.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Repo.d.ts","sourceRoot":"","sources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AM;IACJ,oDAAoD;IACpD,EAAE,EAAE,aAAa;CAUpB;AAED,MAAM,WAAW,UAAU;IACzB,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf,gDAAgD;IAChD,OAAO,CAAC,EAAE,cAAc,CAAA;IAExB,oDAAoD;IACpD,OAAO,EAAE,cAAc,EAAE,CAAA;IAEzB;;;OAGG;IACH,WAAW,CAAC,EAAE,WAAW,CAAA;CAC1B;AAED;;;;;;;KAOK;AACL,MAAM,MAAM,WAAW,GAAG,CACxB,MAAM,EAAE,MAAM,EACd,UAAU,CAAC,EAAE,UAAU,KACpB,OAAO,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
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { next as Automerge } from "@automerge/automerge";
|
|
2
2
|
import debug from "debug";
|
|
3
3
|
import { EventEmitter } from "eventemitter3";
|
|
4
|
+
import { generateAutomergeUrl, interpretAsDocumentId, parseAutomergeUrl, } from "./AutomergeUrl.js";
|
|
4
5
|
import { DocHandle } from "./DocHandle.js";
|
|
5
|
-
import { generateAutomergeUrl, isValidAutomergeUrl, parseAutomergeUrl, parseLegacyUUID, } from "./DocUrl.js";
|
|
6
6
|
import { throttle } from "./helpers/throttle.js";
|
|
7
7
|
import { NetworkSubsystem } from "./network/NetworkSubsystem.js";
|
|
8
8
|
import { StorageSubsystem } from "./storage/StorageSubsystem.js";
|
|
@@ -81,7 +81,7 @@ export class Repo extends EventEmitter {
|
|
|
81
81
|
// TODO Pass the delete on to the network
|
|
82
82
|
// synchronizer.removeDocument(documentId)
|
|
83
83
|
if (storageSubsystem) {
|
|
84
|
-
storageSubsystem.
|
|
84
|
+
storageSubsystem.removeDoc(documentId).catch(err => {
|
|
85
85
|
this.#log("error deleting document", { documentId, err });
|
|
86
86
|
});
|
|
87
87
|
}
|
|
@@ -198,19 +198,9 @@ export class Repo extends EventEmitter {
|
|
|
198
198
|
* event to advertise interest in the document.
|
|
199
199
|
*/
|
|
200
200
|
find(
|
|
201
|
-
/** The documentId of the handle to retrieve */
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
const maybeAutomergeUrl = parseLegacyUUID(automergeUrl);
|
|
205
|
-
if (maybeAutomergeUrl) {
|
|
206
|
-
console.warn("Legacy UUID document ID detected, converting to AutomergeUrl. This will be removed in a future version.");
|
|
207
|
-
automergeUrl = maybeAutomergeUrl;
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
throw new Error(`Invalid AutomergeUrl: '${automergeUrl}'`);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
const { documentId } = parseAutomergeUrl(automergeUrl);
|
|
201
|
+
/** The url or documentId of the handle to retrieve */
|
|
202
|
+
id) {
|
|
203
|
+
const documentId = interpretAsDocumentId(id);
|
|
214
204
|
// If we have the handle cached, return it
|
|
215
205
|
if (this.#handleCache[documentId]) {
|
|
216
206
|
if (this.#handleCache[documentId].isUnavailable()) {
|
|
@@ -228,13 +218,12 @@ export class Repo extends EventEmitter {
|
|
|
228
218
|
return handle;
|
|
229
219
|
}
|
|
230
220
|
delete(
|
|
231
|
-
/** The documentId of the handle to delete */
|
|
221
|
+
/** The url or documentId of the handle to delete */
|
|
232
222
|
id) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
const handle = this.#getHandle(id, false);
|
|
223
|
+
const documentId = interpretAsDocumentId(id);
|
|
224
|
+
const handle = this.#getHandle(documentId, false);
|
|
236
225
|
handle.delete();
|
|
237
|
-
delete this.#handleCache[
|
|
238
|
-
this.emit("delete-document", { documentId
|
|
226
|
+
delete this.#handleCache[documentId];
|
|
227
|
+
this.emit("delete-document", { documentId });
|
|
239
228
|
}
|
|
240
229
|
}
|
package/dist/helpers/cbor.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Encoder, decode as cborXdecode } from "cbor-x";
|
|
2
2
|
export function encode(obj) {
|
|
3
|
-
const encoder = new Encoder({ tagUint8Array: false });
|
|
3
|
+
const encoder = new Encoder({ tagUint8Array: false, useRecords: false });
|
|
4
4
|
return encoder.encode(obj);
|
|
5
5
|
}
|
|
6
6
|
export function decode(buf) {
|
package/dist/index.d.ts
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
28
|
export { DocHandle } from "./DocHandle.js";
|
|
29
|
-
export { isValidAutomergeUrl, parseAutomergeUrl, stringifyAutomergeUrl, } from "./
|
|
29
|
+
export { isValidAutomergeUrl, parseAutomergeUrl, stringifyAutomergeUrl, } from "./AutomergeUrl.js";
|
|
30
30
|
export { Repo } from "./Repo.js";
|
|
31
31
|
export { NetworkAdapter } from "./network/NetworkAdapter.js";
|
|
32
32
|
export { isValidRepoMessage } from "./network/messages.js";
|
|
@@ -36,7 +36,7 @@ export * as cbor from "./helpers/cbor.js";
|
|
|
36
36
|
export type { DocHandleChangePayload, DocHandleDeletePayload, DocHandleEncodedChangePayload, DocHandleEphemeralMessagePayload, DocHandleEvents, DocHandleOptions, DocHandleOutboundEphemeralMessagePayload, HandleState, } from "./DocHandle.js";
|
|
37
37
|
export type { DeleteDocumentPayload, DocumentPayload, RepoConfig, RepoEvents, SharePolicy, } from "./Repo.js";
|
|
38
38
|
export type { NetworkAdapterEvents, OpenPayload, PeerCandidatePayload, PeerDisconnectedPayload, } from "./network/NetworkAdapter.js";
|
|
39
|
-
export type {
|
|
40
|
-
export type { StorageKey } from "./storage/
|
|
39
|
+
export type { DocumentUnavailableMessage, EphemeralMessage, Message, RepoMessage, RequestMessage, SyncMessage, } from "./network/messages.js";
|
|
40
|
+
export type { Chunk, ChunkInfo, ChunkType, StorageKey, } from "./storage/types.js";
|
|
41
41
|
export * from "./types.js";
|
|
42
42
|
//# 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;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAE5D,eAAe;AACf,OAAO,KAAK,IAAI,MAAM,mBAAmB,CAAA;AAIzC,YAAY,EACV,sBAAsB,EACtB,sBAAsB,EACtB,6BAA6B,EAC7B,gCAAgC,EAChC,eAAe,EACf,gBAAgB,EAChB,wCAAwC,EACxC,WAAW,GACZ,MAAM,gBAAgB,CAAA;AAEvB,YAAY,EACV,qBAAqB,EACrB,eAAe,EACf,UAAU,EACV,UAAU,EACV,WAAW,GACZ,MAAM,WAAW,CAAA;AAElB,YAAY,EACV,oBAAoB,EACpB,WAAW,EACX,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,6BAA6B,CAAA;AAEpC,YAAY,EACV,0BAA0B,EAC1B,gBAAgB,EAChB,OAAO,EACP,WAAW,EACX,cAAc,EACd,WAAW,GACZ,MAAM,uBAAuB,CAAA;AAE9B,YAAY,EACV,KAAK,EACL,SAAS,EACT,SAAS,EACT,UAAU,GACX,MAAM,oBAAoB,CAAA;AAE3B,cAAc,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
28
|
export { DocHandle } from "./DocHandle.js";
|
|
29
|
-
export { isValidAutomergeUrl, parseAutomergeUrl, stringifyAutomergeUrl, } from "./
|
|
29
|
+
export { isValidAutomergeUrl, parseAutomergeUrl, stringifyAutomergeUrl, } from "./AutomergeUrl.js";
|
|
30
30
|
export { Repo } from "./Repo.js";
|
|
31
31
|
export { NetworkAdapter } from "./network/NetworkAdapter.js";
|
|
32
32
|
export { isValidRepoMessage } from "./network/messages.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from "eventemitter3";
|
|
2
2
|
import { PeerId } from "../types.js";
|
|
3
|
-
import {
|
|
3
|
+
import { Message } from "./messages.js";
|
|
4
4
|
/** An interface representing some way to connect to other peers
|
|
5
5
|
*
|
|
6
6
|
* @remarks
|
|
@@ -19,7 +19,7 @@ export declare abstract class NetworkAdapter extends EventEmitter<NetworkAdapter
|
|
|
19
19
|
*
|
|
20
20
|
* @argument message - the message to send
|
|
21
21
|
*/
|
|
22
|
-
abstract send(message:
|
|
22
|
+
abstract send(message: Message): void;
|
|
23
23
|
/** Called by the {@link Repo} to disconnect from the network */
|
|
24
24
|
abstract disconnect(): void;
|
|
25
25
|
}
|
|
@@ -33,7 +33,7 @@ export interface NetworkAdapterEvents {
|
|
|
33
33
|
/** Emitted when the network adapter learns that a peer has disconnected */
|
|
34
34
|
"peer-disconnected": (payload: PeerDisconnectedPayload) => void;
|
|
35
35
|
/** Emitted when the network adapter receives a message from a peer */
|
|
36
|
-
message: (payload:
|
|
36
|
+
message: (payload: Message) => void;
|
|
37
37
|
}
|
|
38
38
|
export interface OpenPayload {
|
|
39
39
|
network: NetworkAdapter;
|
|
@@ -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,
|
|
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;;;;;;GAMG;AACH,8BAAsB,cAAe,SAAQ,YAAY,CAAC,oBAAoB,CAAC;IAC7E,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAEtC;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAErC,gEAAgE;IAChE,QAAQ,CAAC,UAAU,IAAI,IAAI;CAC5B;AAID,MAAM,WAAW,oBAAoB;IACnC,mDAAmD;IACnD,KAAK,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,CAAA;IAErC,yCAAyC;IACzC,KAAK,EAAE,MAAM,IAAI,CAAA;IAEjB,+DAA+D;IAC/D,gBAAgB,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,CAAA;IAEzD,2EAA2E;IAC3E,mBAAmB,EAAE,CAAC,OAAO,EAAE,uBAAuB,KAAK,IAAI,CAAA;IAE/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"}
|
|
@@ -65,31 +65,20 @@ export type RequestMessage = {
|
|
|
65
65
|
/** The document ID this message requests */
|
|
66
66
|
documentId: DocumentId;
|
|
67
67
|
};
|
|
68
|
-
/**
|
|
69
|
-
export type
|
|
70
|
-
type: "
|
|
68
|
+
/** (anticipating work in progress) */
|
|
69
|
+
export type AuthMessage<TPayload = any> = {
|
|
70
|
+
type: "auth";
|
|
71
71
|
/** The peer ID of the sender of this message */
|
|
72
72
|
senderId: PeerId;
|
|
73
|
-
/** Arrive messages don't have a targetId */
|
|
74
|
-
targetId: never;
|
|
75
|
-
};
|
|
76
|
-
/** Respond to an arriving peer with our peer ID */
|
|
77
|
-
export type WelcomeMessage = {
|
|
78
|
-
type: "welcome";
|
|
79
|
-
/** The peer ID of the recipient sender this message */
|
|
80
|
-
senderId: PeerId;
|
|
81
73
|
/** The peer ID of the recipient of this message */
|
|
82
74
|
targetId: PeerId;
|
|
75
|
+
/** The payload of the auth message (up to the specific auth provider) */
|
|
76
|
+
payload: TPayload;
|
|
83
77
|
};
|
|
84
78
|
/** These are message types that a {@link NetworkAdapter} surfaces to a {@link Repo}. */
|
|
85
79
|
export type RepoMessage = SyncMessage | EphemeralMessage | RequestMessage | DocumentUnavailableMessage;
|
|
86
|
-
/** These are all the message types that a {@link NetworkAdapter} might see.
|
|
87
|
-
|
|
88
|
-
* @remarks
|
|
89
|
-
* It is not _required_ that a {@link NetworkAdapter} use these types: They are free to use
|
|
90
|
-
* whatever message type makes sense for their transport. However, this type is a useful default.
|
|
91
|
-
* */
|
|
92
|
-
export type Message = RepoMessage | ArriveMessage | WelcomeMessage;
|
|
80
|
+
/** These are all the message types that a {@link NetworkAdapter} might see. */
|
|
81
|
+
export type Message = RepoMessage | AuthMessage;
|
|
93
82
|
/**
|
|
94
83
|
* The contents of a message, without the sender ID or other properties added by the {@link NetworkSubsystem})
|
|
95
84
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/network/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE3D;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAA;IAEZ,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAA;IAEhB,mDAAmD;IACnD,QAAQ,EAAE,MAAM,CAAA;IAEhB,iCAAiC;IACjC,IAAI,EAAE,UAAU,CAAA;IAEhB,0DAA0D;IAC1D,UAAU,EAAE,UAAU,CAAA;CACvB,CAAA;AAED;;;;;;;;;KASK;AACL,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,WAAW,CAAA;IAEjB,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAA;IAEhB,mDAAmD;IACnD,QAAQ,EAAE,MAAM,CAAA;IAEhB,qFAAqF;IACrF,KAAK,EAAE,MAAM,CAAA;IAEb,8GAA8G;IAC9G,SAAS,EAAE,SAAS,CAAA;IAEpB,+CAA+C;IAC/C,UAAU,EAAE,UAAU,CAAA;IAEtB,qCAAqC;IACrC,IAAI,EAAE,UAAU,CAAA;CACjB,CAAA;AAED,uHAAuH;AACvH,MAAM,MAAM,0BAA0B,GAAG;IACv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A4B,QAAS,OAAO,sCACzB,CAAA;AAEhC,eAAO,MAAM,gBAAgB,QAAS,OAAO,0BACrB,CAAA;AAExB,eAAO,MAAM,aAAa,QAAS,OAAO,uBACrB,CAAA;AAErB,eAAO,MAAM,kBAAkB,QAAS,OAAO,4BACrB,CAAA"}
|
|
@@ -1,33 +1,30 @@
|
|
|
1
|
+
import { StorageKey, Chunk } from "./types.js";
|
|
1
2
|
/** A storage adapter represents some way of storing binary data for a {@link Repo}
|
|
2
3
|
*
|
|
3
4
|
* @remarks
|
|
4
|
-
* `StorageAdapter`s
|
|
5
|
-
*
|
|
5
|
+
* `StorageAdapter`s provide a key/value storage interface. The keys are arrays of strings
|
|
6
|
+
* ({@link StorageKey}) and the values are binary blobs.
|
|
6
7
|
*/
|
|
7
8
|
export declare abstract class StorageAdapter {
|
|
8
|
-
/** Load the single
|
|
9
|
+
/** Load the single value corresponding to `key` */
|
|
9
10
|
abstract load(key: StorageKey): Promise<Uint8Array | undefined>;
|
|
10
|
-
/**
|
|
11
|
+
/** Save the value `data` to the key `key` */
|
|
11
12
|
abstract save(key: StorageKey, data: Uint8Array): Promise<void>;
|
|
12
|
-
/**
|
|
13
|
+
/** Remove the value corresponding to `key` */
|
|
13
14
|
abstract remove(key: StorageKey): Promise<void>;
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Load all values with keys that start with `keyPrefix`.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* The `keyprefix` will match any key that starts with the given array. For example:
|
|
20
|
+
* - `[documentId, "incremental"]` will match all incremental saves
|
|
21
|
+
* - `[documentId]` will match all data for a given document.
|
|
22
|
+
*
|
|
23
|
+
* Be careful! `[documentId]` would also match something like `[documentId, "syncState"]`! We
|
|
24
|
+
* aren't using this yet but keep it in mind.)
|
|
25
|
+
*/
|
|
26
|
+
abstract loadRange(keyPrefix: StorageKey): Promise<Chunk[]>;
|
|
27
|
+
/** Remove all values with keys that start with `keyPrefix` */
|
|
20
28
|
abstract removeRange(keyPrefix: StorageKey): Promise<void>;
|
|
21
29
|
}
|
|
22
|
-
/** The type of keys for a {@link StorageAdapter}
|
|
23
|
-
*
|
|
24
|
-
* @remarks
|
|
25
|
-
* Storage keys are arrays because they are hierarchical and the storage
|
|
26
|
-
* subsystem will need to be able to do range queries for all keys that
|
|
27
|
-
* have a particular prefix. For example, incremental changes for a given
|
|
28
|
-
* document might be stored under `[<documentId>, "incremental", <SHA256>]`.
|
|
29
|
-
* `StorageAdapter` implementations should not assume any particular structure
|
|
30
|
-
* though.
|
|
31
|
-
**/
|
|
32
|
-
export type StorageKey = string[];
|
|
33
30
|
//# sourceMappingURL=StorageAdapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageAdapter.d.ts","sourceRoot":"","sources":["../../src/storage/StorageAdapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,8BAAsB,cAAc;
|
|
1
|
+
{"version":3,"file":"StorageAdapter.d.ts","sourceRoot":"","sources":["../../src/storage/StorageAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAE9C;;;;;GAKG;AACH,8BAAsB,cAAc;IAClC,mDAAmD;IACnD,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAE/D,6CAA6C;IAC7C,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAE/D,8CAA8C;IAC9C,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAE/C;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,SAAS,CAAC,SAAS,EAAE,UAAU,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAE3D,8DAA8D;IAC9D,QAAQ,CAAC,WAAW,CAAC,SAAS,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAC3D"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** A storage adapter represents some way of storing binary data for a {@link Repo}
|
|
2
2
|
*
|
|
3
3
|
* @remarks
|
|
4
|
-
* `StorageAdapter`s
|
|
5
|
-
*
|
|
4
|
+
* `StorageAdapter`s provide a key/value storage interface. The keys are arrays of strings
|
|
5
|
+
* ({@link StorageKey}) and the values are binary blobs.
|
|
6
6
|
*/
|
|
7
7
|
export class StorageAdapter {
|
|
8
8
|
}
|
|
@@ -1,12 +1,48 @@
|
|
|
1
1
|
import * as A from "@automerge/automerge/next";
|
|
2
2
|
import { type DocumentId } from "../types.js";
|
|
3
3
|
import { StorageAdapter } from "./StorageAdapter.js";
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* The storage subsystem is responsible for saving and loading Automerge documents to and from
|
|
6
|
+
* storage adapter. It also provides a generic key/value storage interface for other uses.
|
|
7
|
+
*/
|
|
5
8
|
export declare class StorageSubsystem {
|
|
6
9
|
#private;
|
|
7
10
|
constructor(storageAdapter: StorageAdapter);
|
|
8
|
-
|
|
11
|
+
/** Loads a value from storage. */
|
|
12
|
+
load(
|
|
13
|
+
/** Namespace to prevent collisions with other users of the storage subsystem. */
|
|
14
|
+
namespace: string,
|
|
15
|
+
/** Key to load. Typically a UUID or other unique identifier, but could be any string. */
|
|
16
|
+
key: string): Promise<Uint8Array | undefined>;
|
|
17
|
+
/** Saves a value in storage. */
|
|
18
|
+
save(
|
|
19
|
+
/** Namespace to prevent collisions with other users of the storage subsystem. */
|
|
20
|
+
namespace: string,
|
|
21
|
+
/** Key to load. Typically a UUID or other unique identifier, but could be any string. */
|
|
22
|
+
key: string,
|
|
23
|
+
/** Data to save, as a binary blob. */
|
|
24
|
+
data: Uint8Array): Promise<void>;
|
|
25
|
+
/** Removes a value from storage. */
|
|
26
|
+
remove(
|
|
27
|
+
/** Namespace to prevent collisions with other users of the storage subsystem. */
|
|
28
|
+
namespace: string,
|
|
29
|
+
/** Key to remove. Typically a UUID or other unique identifier, but could be any string. */
|
|
30
|
+
key: string): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Loads the Automerge document with the given ID from storage.
|
|
33
|
+
*/
|
|
34
|
+
loadDoc<T>(documentId: DocumentId): Promise<A.Doc<T> | null>;
|
|
35
|
+
/**
|
|
36
|
+
* Saves the provided Automerge document to storage.
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* Under the hood this makes incremental saves until the incremental size is greater than the
|
|
40
|
+
* snapshot size, at which point the document is compacted into a single snapshot.
|
|
41
|
+
*/
|
|
9
42
|
saveDoc(documentId: DocumentId, doc: A.Doc<unknown>): Promise<void>;
|
|
10
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Removes the Automerge document with the given ID from storage
|
|
45
|
+
*/
|
|
46
|
+
removeDoc(documentId: DocumentId): Promise<void>;
|
|
11
47
|
}
|
|
12
48
|
//# sourceMappingURL=StorageSubsystem.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageSubsystem.d.ts","sourceRoot":"","sources":["../../src/storage/StorageSubsystem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"StorageSubsystem.d.ts","sourceRoot":"","sources":["../../src/storage/StorageSubsystem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,2BAA2B,CAAA;AAI9C,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAKpD;;;GAGG;AACH,qBAAa,gBAAgB;;gBAef,cAAc,EAAE,cAAc;IAc1C,kCAAkC;IAC5B,IAAI;IACR,iFAAiF;IACjF,SAAS,EAAE,MAAM;IAEjB,yFAAyF;IACzF,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAKlC,gCAAgC;IAC1B,IAAI;IACR,iFAAiF;IACjF,SAAS,EAAE,MAAM;IAEjB,yFAAyF;IACzF,GAAG,EAAE,MAAM;IAEX,sCAAsC;IACtC,IAAI,EAAE,UAAU,GACf,OAAO,CAAC,IAAI,CAAC;IAKhB,oCAAoC;IAC9B,MAAM;IACV,iFAAiF;IACjF,SAAS,EAAE,MAAM;IAEjB,2FAA2F;IAC3F,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,IAAI,CAAC;IAOhB;;OAEG;IACG,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAmClE;;;;;;OAMG;IACG,OAAO,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAazE;;OAEG;IACG,SAAS,CAAC,UAAU,EAAE,UAAU;CAsGvC"}
|