@web_of_trust/adapter-automerge 0.1.2
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 +143 -0
- package/dist/AutomergeOutboxStore.d.ts +23 -0
- package/dist/AutomergeOutboxStore.d.ts.map +1 -0
- package/dist/AutomergeReplicationAdapter.d.ts +132 -0
- package/dist/AutomergeReplicationAdapter.d.ts.map +1 -0
- package/dist/AutomergeSpaceMetadataStorage.d.ts +23 -0
- package/dist/AutomergeSpaceMetadataStorage.d.ts.map +1 -0
- package/dist/CompactionService.d.ts +28 -0
- package/dist/CompactionService.d.ts.map +1 -0
- package/dist/EncryptedMessagingNetworkAdapter.d.ts +62 -0
- package/dist/EncryptedMessagingNetworkAdapter.d.ts.map +1 -0
- package/dist/InMemoryRepoStorageAdapter.d.ts +21 -0
- package/dist/InMemoryRepoStorageAdapter.d.ts.map +1 -0
- package/dist/PersonalDocManager.d.ts +166 -0
- package/dist/PersonalDocManager.d.ts.map +1 -0
- package/dist/PersonalNetworkAdapter.d.ts +27 -0
- package/dist/PersonalNetworkAdapter.d.ts.map +1 -0
- package/dist/SyncOnlyStorageAdapter.d.ts +27 -0
- package/dist/SyncOnlyStorageAdapter.d.ts.map +1 -0
- package/dist/index-Dz-MvOzM.js +86 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1621 -0
- package/package.json +53 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { NetworkAdapter, PeerId, DocumentId, Message } from '@automerge/automerge-repo';
|
|
2
|
+
import { MessagingAdapter } from '@web_of_trust/core';
|
|
3
|
+
export declare class PersonalNetworkAdapter extends NetworkAdapter {
|
|
4
|
+
private messaging;
|
|
5
|
+
private personalKey;
|
|
6
|
+
private myDid;
|
|
7
|
+
private documentId;
|
|
8
|
+
private ready;
|
|
9
|
+
private readyResolve?;
|
|
10
|
+
private readyPromise;
|
|
11
|
+
private unsubMessage;
|
|
12
|
+
/** Track message IDs we sent, so we can ignore our own echoes from the relay */
|
|
13
|
+
private sentMessageIds;
|
|
14
|
+
/** Gate incoming messages until the doc handle is confirmed ready (avoids automerge-repo 60s timeout) */
|
|
15
|
+
private docReady;
|
|
16
|
+
constructor(messaging: MessagingAdapter, personalKey: Uint8Array, myDid: string);
|
|
17
|
+
/** Register the personal document ID for routing */
|
|
18
|
+
setDocumentId(documentId: DocumentId): void;
|
|
19
|
+
/** Signal that the doc handle is ready — incoming messages will be emitted to the repo */
|
|
20
|
+
setDocReady(): void;
|
|
21
|
+
isReady(): boolean;
|
|
22
|
+
whenReady(): Promise<void>;
|
|
23
|
+
connect(peerId: PeerId): void;
|
|
24
|
+
send(message: Message): void;
|
|
25
|
+
disconnect(): void;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=PersonalNetworkAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PersonalNetworkAdapter.d.ts","sourceRoot":"","sources":["../src/PersonalNetworkAdapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AACnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAG1D,qBAAa,sBAAuB,SAAQ,cAAc;IACxD,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,WAAW,CAAY;IAC/B,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,UAAU,CAA0B;IAC5C,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,YAAY,CAAC,CAAY;IACjC,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,YAAY,CAA4B;IAChD,gFAAgF;IAChF,OAAO,CAAC,cAAc,CAAoB;IAC1C,yGAAyG;IACzG,OAAO,CAAC,QAAQ,CAAQ;gBAEZ,SAAS,EAAE,gBAAgB,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM;IAU/E,oDAAoD;IACpD,aAAa,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAI3C,0FAA0F;IAC1F,WAAW,IAAI,IAAI;IAMnB,OAAO,IAAI,OAAO;IAIlB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAI1B,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IA+C7B,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAiD5B,UAAU,IAAI,IAAI;CASnB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { StorageAdapterInterface } from '@automerge/automerge-repo';
|
|
2
|
+
type StorageKey = string[];
|
|
3
|
+
type Chunk = {
|
|
4
|
+
key: StorageKey;
|
|
5
|
+
data: Uint8Array | undefined;
|
|
6
|
+
};
|
|
7
|
+
export declare class SyncOnlyStorageAdapter implements StorageAdapterInterface {
|
|
8
|
+
private dbName;
|
|
9
|
+
private db;
|
|
10
|
+
private readyPromise;
|
|
11
|
+
constructor(dbName?: string);
|
|
12
|
+
/** Wait until the IDB is open. */
|
|
13
|
+
ready(): Promise<void>;
|
|
14
|
+
private open;
|
|
15
|
+
private isSyncState;
|
|
16
|
+
private keyToString;
|
|
17
|
+
private stringToKey;
|
|
18
|
+
private keyMatchesPrefix;
|
|
19
|
+
load(key: StorageKey): Promise<Uint8Array | undefined>;
|
|
20
|
+
save(key: StorageKey, data: Uint8Array): Promise<void>;
|
|
21
|
+
remove(key: StorageKey): Promise<void>;
|
|
22
|
+
loadRange(keyPrefix: StorageKey): Promise<Chunk[]>;
|
|
23
|
+
removeRange(keyPrefix: StorageKey): Promise<void>;
|
|
24
|
+
close(): void;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=SyncOnlyStorageAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SyncOnlyStorageAdapter.d.ts","sourceRoot":"","sources":["../src/SyncOnlyStorageAdapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAA;AAExE,KAAK,UAAU,GAAG,MAAM,EAAE,CAAA;AAC1B,KAAK,KAAK,GAAG;IAAE,GAAG,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,UAAU,GAAG,SAAS,CAAA;CAAE,CAAA;AAE9D,qBAAa,sBAAuB,YAAW,uBAAuB;IACpE,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,EAAE,CAA2B;IACrC,OAAO,CAAC,YAAY,CAAe;gBAEvB,MAAM,GAAE,MAA0B;IAK9C,kCAAkC;IAC5B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAId,IAAI;IAoBlB,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,gBAAgB;IAQlB,IAAI,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAatD,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAatD,MAAM,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAatC,SAAS,CAAC,SAAS,EAAE,UAAU,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IA0BlD,WAAW,CAAC,SAAS,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAyBvD,KAAK,IAAI,IAAI;CAMd"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
var j = Object.defineProperty;
|
|
2
|
+
var S = (c, e, o) => e in c ? j(c, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : c[e] = o;
|
|
3
|
+
var u = (c, e, o) => S(c, typeof e != "symbol" ? e + "" : e, o);
|
|
4
|
+
class p {
|
|
5
|
+
/** Create a new {@link IndexedDBStorageAdapter}.
|
|
6
|
+
* @param database - The name of the database to use. Defaults to "automerge".
|
|
7
|
+
* @param store - The name of the object store to use. Defaults to "documents".
|
|
8
|
+
*/
|
|
9
|
+
constructor(e = "automerge", o = "documents") {
|
|
10
|
+
u(this, "database");
|
|
11
|
+
u(this, "store");
|
|
12
|
+
u(this, "dbPromise");
|
|
13
|
+
this.database = e, this.store = o, this.dbPromise = this.createDatabasePromise();
|
|
14
|
+
}
|
|
15
|
+
createDatabasePromise() {
|
|
16
|
+
return new Promise((e, o) => {
|
|
17
|
+
const t = indexedDB.open(this.database, 1);
|
|
18
|
+
t.onerror = () => {
|
|
19
|
+
o(t.error);
|
|
20
|
+
}, t.onupgradeneeded = (r) => {
|
|
21
|
+
r.target.result.createObjectStore(this.store);
|
|
22
|
+
}, t.onsuccess = (r) => {
|
|
23
|
+
const n = r.target.result;
|
|
24
|
+
e(n);
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
async load(e) {
|
|
29
|
+
const t = (await this.dbPromise).transaction(this.store), n = t.objectStore(this.store).get(e);
|
|
30
|
+
return new Promise((s, b) => {
|
|
31
|
+
t.onerror = () => {
|
|
32
|
+
b(n.error);
|
|
33
|
+
}, n.onsuccess = (i) => {
|
|
34
|
+
const a = i.target.result;
|
|
35
|
+
a && typeof a == "object" && "binary" in a ? s(a.binary) : s(void 0);
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
async save(e, o) {
|
|
40
|
+
const r = (await this.dbPromise).transaction(this.store, "readwrite");
|
|
41
|
+
return r.objectStore(this.store).put({ key: e, binary: o }, e), new Promise((s, b) => {
|
|
42
|
+
r.onerror = () => {
|
|
43
|
+
b(r.error);
|
|
44
|
+
}, r.oncomplete = () => {
|
|
45
|
+
s();
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
async remove(e) {
|
|
50
|
+
const t = (await this.dbPromise).transaction(this.store, "readwrite");
|
|
51
|
+
return t.objectStore(this.store).delete(e), new Promise((n, s) => {
|
|
52
|
+
t.onerror = () => {
|
|
53
|
+
s(t.error);
|
|
54
|
+
}, t.oncomplete = () => {
|
|
55
|
+
n();
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async loadRange(e) {
|
|
60
|
+
const o = await this.dbPromise, t = e, r = [...e, ""], n = IDBKeyRange.bound(t, r), s = o.transaction(this.store), i = s.objectStore(this.store).openCursor(n), a = [];
|
|
61
|
+
return new Promise((h, m) => {
|
|
62
|
+
s.onerror = () => {
|
|
63
|
+
m(i.error);
|
|
64
|
+
}, i.onsuccess = (l) => {
|
|
65
|
+
const d = l.target.result;
|
|
66
|
+
d ? (a.push({
|
|
67
|
+
data: d.value.binary,
|
|
68
|
+
key: d.key
|
|
69
|
+
}), d.continue()) : h(a);
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
async removeRange(e) {
|
|
74
|
+
const o = await this.dbPromise, t = e, r = [...e, ""], n = IDBKeyRange.bound(t, r), s = o.transaction(this.store, "readwrite");
|
|
75
|
+
return s.objectStore(this.store).delete(n), new Promise((i, a) => {
|
|
76
|
+
s.onerror = () => {
|
|
77
|
+
a(s.error);
|
|
78
|
+
}, s.oncomplete = () => {
|
|
79
|
+
i();
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export {
|
|
85
|
+
p as IndexedDBStorageAdapter
|
|
86
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { AutomergeReplicationAdapter } from './AutomergeReplicationAdapter';
|
|
2
|
+
export type { AutomergeReplicationAdapterConfig, CompactStore } from './AutomergeReplicationAdapter';
|
|
3
|
+
export { EncryptedMessagingNetworkAdapter } from './EncryptedMessagingNetworkAdapter';
|
|
4
|
+
export { PersonalNetworkAdapter } from './PersonalNetworkAdapter';
|
|
5
|
+
export { initPersonalDoc, getPersonalDoc, isPersonalDocInitialized, changePersonalDoc, onPersonalDocChange, flushPersonalDoc, resetPersonalDoc, deletePersonalDocDB, } from './PersonalDocManager';
|
|
6
|
+
export type { PersonalDoc, ProfileDoc, ContactDoc, VerificationDoc, AttestationDoc, AttestationMetadataDoc, OutboxEntryDoc, PublishStateDoc, CachedGraphEntryDoc, CachedGraphVerificationDoc, CachedGraphAttestationDoc, SpaceMetadataDoc, GroupKeyDoc, } from './PersonalDocManager';
|
|
7
|
+
export { SyncOnlyStorageAdapter } from './SyncOnlyStorageAdapter';
|
|
8
|
+
export { CompactionService } from './CompactionService';
|
|
9
|
+
export type { CompactionRequest, CompactionResponse } from './CompactionService';
|
|
10
|
+
export { InMemoryRepoStorageAdapter } from './InMemoryRepoStorageAdapter';
|
|
11
|
+
export { AutomergeSpaceMetadataStorage } from './AutomergeSpaceMetadataStorage';
|
|
12
|
+
export type { SpaceMetadataDocFunctions } from './AutomergeSpaceMetadataStorage';
|
|
13
|
+
export { AutomergeOutboxStore } from './AutomergeOutboxStore';
|
|
14
|
+
export type { PersonalDocFunctions } from './AutomergeOutboxStore';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAA;AAC3E,YAAY,EAAE,iCAAiC,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AACpG,OAAO,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAA;AACrF,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AAGjE,OAAO,EACL,eAAe,EACf,cAAc,EACd,wBAAwB,EACxB,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,sBAAsB,CAAA;AAC7B,YAAY,EACV,WAAW,EACX,UAAU,EACV,UAAU,EACV,eAAe,EACf,cAAc,EACd,sBAAsB,EACtB,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,0BAA0B,EAC1B,yBAAyB,EACzB,gBAAgB,EAChB,WAAW,GACZ,MAAM,sBAAsB,CAAA;AAG7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAChF,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAA;AACzE,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAA;AAC/E,YAAY,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAA;AAGhF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,YAAY,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA"}
|