@weaveprotocol/core 0.1.2 → 0.2.1
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 +322 -45
- package/dist/doors/doors.d.ts +139 -0
- package/dist/doors/doors.d.ts.map +1 -0
- package/dist/doors/doors.js +210 -0
- package/dist/doors/doors.js.map +1 -0
- package/dist/doors/index.d.ts +9 -0
- package/dist/doors/index.d.ts.map +1 -0
- package/dist/doors/index.js +7 -0
- package/dist/doors/index.js.map +1 -0
- package/dist/identity/contact-key.d.ts +68 -0
- package/dist/identity/contact-key.d.ts.map +1 -0
- package/dist/identity/contact-key.js +185 -0
- package/dist/identity/contact-key.js.map +1 -0
- package/dist/index.d.ts +16 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -5
- package/dist/index.js.map +1 -1
- package/dist/network/index.d.ts +2 -0
- package/dist/network/index.d.ts.map +1 -1
- package/dist/network/index.js +1 -0
- package/dist/network/index.js.map +1 -1
- package/dist/network/mailbox.d.ts +49 -0
- package/dist/network/mailbox.d.ts.map +1 -0
- package/dist/network/mailbox.js +125 -0
- package/dist/network/mailbox.js.map +1 -0
- package/dist/network/mesh.d.ts +6 -0
- package/dist/network/mesh.d.ts.map +1 -1
- package/dist/network/mesh.js +11 -1
- package/dist/network/mesh.js.map +1 -1
- package/dist/network/multi-signaling.d.ts +12 -2
- package/dist/network/multi-signaling.d.ts.map +1 -1
- package/dist/network/multi-signaling.js +86 -14
- package/dist/network/multi-signaling.js.map +1 -1
- package/dist/network/peer-auth.d.ts +50 -16
- package/dist/network/peer-auth.d.ts.map +1 -1
- package/dist/network/peer-auth.js +52 -15
- package/dist/network/peer-auth.js.map +1 -1
- package/dist/node/carrier.d.ts +87 -0
- package/dist/node/carrier.d.ts.map +1 -1
- package/dist/node/carrier.js +180 -59
- package/dist/node/carrier.js.map +1 -1
- package/dist/node/copy.d.ts.map +1 -1
- package/dist/node/copy.js +6 -3
- package/dist/node/copy.js.map +1 -1
- package/dist/node/host.d.ts +117 -0
- package/dist/node/host.d.ts.map +1 -0
- package/dist/node/host.js +192 -0
- package/dist/node/host.js.map +1 -0
- package/dist/node/index.d.ts +6 -2
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +1 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/node.d.ts.map +1 -1
- package/dist/node/node.js +958 -25
- package/dist/node/node.js.map +1 -1
- package/dist/node/space-runtime.d.ts +42 -25
- package/dist/node/space-runtime.d.ts.map +1 -1
- package/dist/node/space-runtime.js +734 -35
- package/dist/node/space-runtime.js.map +1 -1
- package/dist/node/types.d.ts +375 -3
- package/dist/node/types.d.ts.map +1 -1
- package/dist/privacy/space-encryption.d.ts +16 -0
- package/dist/privacy/space-encryption.d.ts.map +1 -1
- package/dist/privacy/space-encryption.js +40 -0
- package/dist/privacy/space-encryption.js.map +1 -1
- package/dist/query/engine.js +1 -1
- package/dist/query/engine.js.map +1 -1
- package/dist/query/types.d.ts +7 -0
- package/dist/query/types.d.ts.map +1 -1
- package/dist/query/types.js.map +1 -1
- package/dist/react/use-query.d.ts +1 -1
- package/dist/react/use-query.d.ts.map +1 -1
- package/dist/records/topics.d.ts +21 -0
- package/dist/records/topics.d.ts.map +1 -0
- package/dist/records/topics.js +86 -0
- package/dist/records/topics.js.map +1 -0
- package/dist/schema/collection-def.d.ts +7 -0
- package/dist/schema/collection-def.d.ts.map +1 -1
- package/dist/schema/collection-def.js +4 -0
- package/dist/schema/collection-def.js.map +1 -1
- package/dist/schema/expression.d.ts +2 -0
- package/dist/schema/expression.d.ts.map +1 -1
- package/dist/schema/expression.js +1 -0
- package/dist/schema/expression.js.map +1 -1
- package/dist/schemas/contacts.d.ts +214 -0
- package/dist/schemas/contacts.d.ts.map +1 -0
- package/dist/schemas/contacts.js +98 -0
- package/dist/schemas/contacts.js.map +1 -0
- package/dist/schemas/index.d.ts +2 -0
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +1 -0
- package/dist/schemas/index.js.map +1 -1
- package/dist/session/auth.d.ts.map +1 -1
- package/dist/session/auth.js +15 -3
- package/dist/session/auth.js.map +1 -1
- package/dist/session/connect.d.ts +25 -1
- package/dist/session/connect.d.ts.map +1 -1
- package/dist/session/connect.js +9 -2
- package/dist/session/connect.js.map +1 -1
- package/dist/session/hosting.d.ts +155 -0
- package/dist/session/hosting.d.ts.map +1 -0
- package/dist/session/hosting.js +160 -0
- package/dist/session/hosting.js.map +1 -0
- package/dist/space/account-registry.d.ts +6 -0
- package/dist/space/account-registry.d.ts.map +1 -1
- package/dist/space/account-registry.js +16 -4
- package/dist/space/account-registry.js.map +1 -1
- package/dist/space/notify.d.ts +88 -0
- package/dist/space/notify.d.ts.map +1 -0
- package/dist/space/notify.js +127 -0
- package/dist/space/notify.js.map +1 -0
- package/dist/space/pass.d.ts +6 -0
- package/dist/space/pass.d.ts.map +1 -1
- package/dist/space/pass.js +5 -2
- package/dist/space/pass.js.map +1 -1
- package/dist/space/roles.d.ts +71 -0
- package/dist/space/roles.d.ts.map +1 -1
- package/dist/space/roles.js +114 -0
- package/dist/space/roles.js.map +1 -1
- package/dist/space/space-access.d.ts +24 -0
- package/dist/space/space-access.d.ts.map +1 -1
- package/dist/space/space-access.js +24 -0
- package/dist/space/space-access.js.map +1 -1
- package/dist/space/space-manager.d.ts +35 -1
- package/dist/space/space-manager.d.ts.map +1 -1
- package/dist/space/space-manager.js +72 -25
- package/dist/space/space-manager.js.map +1 -1
- package/dist/storage/blob/memory.d.ts +9 -0
- package/dist/storage/blob/memory.d.ts.map +1 -0
- package/dist/storage/blob/memory.js +20 -0
- package/dist/storage/blob/memory.js.map +1 -0
- package/dist/storage/blob/s3.d.ts +16 -0
- package/dist/storage/blob/s3.d.ts.map +1 -0
- package/dist/storage/blob/s3.js +86 -0
- package/dist/storage/blob/s3.js.map +1 -0
- package/dist/storage/blob-store.d.ts +26 -0
- package/dist/storage/blob-store.d.ts.map +1 -0
- package/dist/storage/blob-store.js +2 -0
- package/dist/storage/blob-store.js.map +1 -0
- package/dist/storage/encrypted-adapter.d.ts +3 -3
- package/dist/storage/encrypted-adapter.js +3 -3
- package/dist/storage/folder-adapter.d.ts +8 -8
- package/dist/storage/folder-adapter.d.ts.map +1 -1
- package/dist/storage/folder-adapter.js +7 -7
- package/dist/storage/folder-reconcile.d.ts +12 -14
- package/dist/storage/folder-reconcile.d.ts.map +1 -1
- package/dist/storage/folder-reconcile.js +20 -14
- package/dist/storage/folder-reconcile.js.map +1 -1
- package/dist/storage/index.d.ts +0 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +0 -1
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/indexeddb-adapter.d.ts.map +1 -1
- package/dist/storage/indexeddb-adapter.js +8 -9
- package/dist/storage/indexeddb-adapter.js.map +1 -1
- package/dist/storage/mirror.d.ts +68 -0
- package/dist/storage/mirror.d.ts.map +1 -0
- package/dist/storage/mirror.js +174 -0
- package/dist/storage/mirror.js.map +1 -0
- package/dist/storage/segment.d.ts +20 -0
- package/dist/storage/segment.d.ts.map +1 -0
- package/dist/storage/segment.js +27 -0
- package/dist/storage/segment.js.map +1 -0
- package/dist/storage/storage-provider.d.ts +36 -40
- package/dist/storage/storage-provider.d.ts.map +1 -1
- package/dist/storage/storage-provider.js +208 -117
- package/dist/storage/storage-provider.js.map +1 -1
- package/dist/sync/index.d.ts +1 -1
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +1 -1
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/negentropy.d.ts +68 -0
- package/dist/sync/negentropy.d.ts.map +1 -0
- package/dist/sync/negentropy.js +379 -0
- package/dist/sync/negentropy.js.map +1 -0
- package/dist/sync/sync-engine.d.ts +45 -13
- package/dist/sync/sync-engine.d.ts.map +1 -1
- package/dist/sync/sync-engine.js +290 -207
- package/dist/sync/sync-engine.js.map +1 -1
- package/dist/sync/sync-messages.d.ts +42 -32
- package/dist/sync/sync-messages.d.ts.map +1 -1
- package/dist/sync/sync-messages.js +1 -1
- package/dist/sync/sync-messages.js.map +1 -1
- package/dist/types.d.ts +9 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/hash.d.ts +9 -0
- package/dist/utils/hash.d.ts.map +1 -1
- package/dist/utils/hash.js +33 -0
- package/dist/utils/hash.js.map +1 -1
- package/package.json +8 -3
- package/dist/storage/mst.d.ts +0 -121
- package/dist/storage/mst.d.ts.map +0 -1
- package/dist/storage/mst.js +0 -402
- package/dist/storage/mst.js.map +0 -1
- package/dist/sync/anti-entropy.d.ts +0 -49
- package/dist/sync/anti-entropy.d.ts.map +0 -1
- package/dist/sync/anti-entropy.js +0 -62
- package/dist/sync/anti-entropy.js.map +0 -1
|
@@ -2,17 +2,29 @@
|
|
|
2
2
|
* @module sync-engine
|
|
3
3
|
* Keeps one store in step with its peers.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* 1. A peer says hello with a fingerprint of each collection it keeps. Equal
|
|
6
|
+
* fingerprints mean the same versions: nothing to do for that collection.
|
|
7
|
+
* 2. For each collection that differs, one side — the initiator — reconciles
|
|
8
|
+
* it with the other (`negentropy.ts`). A few rounds of fingerprints of
|
|
9
|
+
* ever smaller ranges end with the initiator knowing which versions each
|
|
10
|
+
* side lacks.
|
|
11
|
+
* 3. The initiator asks for what it lacks, and sends what the other lacks.
|
|
12
|
+
* Everything that arrives passes the gatekeeper before it is stored.
|
|
6
13
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* batches and skipping any subtree that is already part of its own tree.
|
|
10
|
-
* 3. The keys found in the nodes it fetched, less the records it already
|
|
11
|
-
* holds, are what it is missing. It asks for those, and every one of them
|
|
12
|
-
* passes the gatekeeper before it is stored.
|
|
14
|
+
* Cost follows the difference, not the size: two stores differing by one
|
|
15
|
+
* version exchange a few hundred bytes.
|
|
13
16
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
17
|
+
* The initiator is the peer whose id sorts first, so two peers that hear each
|
|
18
|
+
* other's hello at once don't both do the work. A peer that isn't the
|
|
19
|
+
* initiator answers a hello with its own, which starts the other.
|
|
20
|
+
*
|
|
21
|
+
* **Holding part of a space.** A node may hold every collection, or only
|
|
22
|
+
* some (plus the space's own `sys.*`, which every node holds). Each hello
|
|
23
|
+
* says which. Two peers reconcile only the collections both hold, and a
|
|
24
|
+
* version for a collection this node doesn't hold is not taken in. Whatever
|
|
25
|
+
* a node does take in from a peer, it tells that peer it has (`stored`): a
|
|
26
|
+
* node holding part of a space keeps its own writes until enough keepers have
|
|
27
|
+
* said so.
|
|
16
28
|
*/
|
|
17
29
|
import type { Expression } from '../types.js';
|
|
18
30
|
import type { StorageProvider } from '../storage/storage-provider.js';
|
|
@@ -29,9 +41,19 @@ export interface IncomingValidation {
|
|
|
29
41
|
*/
|
|
30
42
|
readonly later?: boolean;
|
|
31
43
|
}
|
|
44
|
+
/** What a node holds of a space: every collection, or these (besides `sys.*`, which every node holds) */
|
|
45
|
+
export type Holds = 'all' | ReadonlySet<string>;
|
|
46
|
+
/** Whether a collection is held, given what a node holds */
|
|
47
|
+
export declare const holdsCollection: (holds: Holds, collection: string) => boolean;
|
|
32
48
|
export interface SyncEngineConfig {
|
|
33
49
|
readonly storageProvider: StorageProvider;
|
|
34
50
|
readonly sendToPeer: (peerId: string, message: SyncMessage) => void;
|
|
51
|
+
/**
|
|
52
|
+
* This node's id among its peers. The one of two peers whose id sorts first
|
|
53
|
+
* starts reconciling. Without it, this node starts whenever it hears of a
|
|
54
|
+
* difference — harmless, just sometimes twice the work.
|
|
55
|
+
*/
|
|
56
|
+
readonly self?: string;
|
|
35
57
|
readonly heartbeatInterval?: number;
|
|
36
58
|
/**
|
|
37
59
|
* Gatekeeper for expressions arriving from peers — typically a
|
|
@@ -42,14 +64,24 @@ export interface SyncEngineConfig {
|
|
|
42
64
|
* for a trusted transport or a test.
|
|
43
65
|
*/
|
|
44
66
|
readonly validate?: (expression: Expression) => Promise<IncomingValidation>;
|
|
67
|
+
/** What this node holds, asked afresh for every hello. Default: everything. */
|
|
68
|
+
readonly holds?: () => Holds;
|
|
45
69
|
}
|
|
46
|
-
|
|
70
|
+
/**
|
|
71
|
+
* - `synced` (peer, full): nothing left in flight with the peer; `full` when the peer holds every collection
|
|
72
|
+
* - `level` (peer, collection, full): this node holds what the peer holds of a
|
|
73
|
+
* collection, as far as it could take it in; `full` when the peer holds every collection
|
|
74
|
+
* - `stored` (peer, ids): the peer says it now has these versions
|
|
75
|
+
* - `expression-received` (version), `rejected` (peer, version, reason), `error` (error)
|
|
76
|
+
*/
|
|
77
|
+
export type SyncEvent = 'synced' | 'level' | 'stored' | 'expression-received' | 'rejected' | 'error';
|
|
47
78
|
type EventHandler = (...args: any[]) => void;
|
|
48
79
|
export interface SyncEngine {
|
|
49
80
|
start(): void;
|
|
50
81
|
stop(): void;
|
|
51
82
|
/** Handles whatever a peer sent; anything that is not a sync message this peer speaks is ignored. */
|
|
52
83
|
handleMessage(peerId: string, message: unknown): Promise<void>;
|
|
84
|
+
/** Says hello to these peers now, rather than at the next heartbeat. */
|
|
53
85
|
notifyPeers(peers: ReadonlyArray<string>): void;
|
|
54
86
|
onLocalChange(expression: Expression): void;
|
|
55
87
|
addPeer(peerId: string): void;
|
|
@@ -57,10 +89,10 @@ export interface SyncEngine {
|
|
|
57
89
|
on(event: SyncEvent, callback: EventHandler): void;
|
|
58
90
|
off(event: SyncEvent, callback: EventHandler): void;
|
|
59
91
|
}
|
|
60
|
-
/**
|
|
61
|
-
export declare const MAX_CIDS_PER_REQUEST = 64;
|
|
62
|
-
/** Records asked for in one message. */
|
|
92
|
+
/** Records asked for, or sent, in one message. */
|
|
63
93
|
export declare const MAX_IDS_PER_REQUEST = 200;
|
|
94
|
+
/** Largest Negentropy message, in bytes before base64. Stays well inside a data channel's limit. */
|
|
95
|
+
export declare const FRAME_SIZE_LIMIT = 32000;
|
|
64
96
|
/**
|
|
65
97
|
* Creates a sync engine orchestrator.
|
|
66
98
|
* @param config Sync engine configuration.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-engine.d.ts","sourceRoot":"","sources":["../../src/sync/sync-engine.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"sync-engine.d.ts","sourceRoot":"","sources":["../../src/sync/sync-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAKtE,OAAO,EAA2C,KAAK,WAAW,EAAwB,MAAM,oBAAoB,CAAC;AAErH,wDAAwD;AACxD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;CAC1B;AAOD,yGAAyG;AACzG,MAAM,MAAM,KAAK,GAAG,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;AAEhD,4DAA4D;AAC5D,eAAO,MAAM,eAAe,GAAI,OAAO,KAAK,EAAE,YAAY,MAAM,KAAG,OACQ,CAAC;AAK5E,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;IAC1C,QAAQ,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC;IACpE;;;;OAIG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IACpC;;;;;;;OAOG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC5E,+EAA+E;IAC/E,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,CAAC;CAC9B;AAED;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,qBAAqB,GAAG,UAAU,GAAG,OAAO,CAAC;AACrG,KAAK,YAAY,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;AAE7C,MAAM,WAAW,UAAU;IACzB,KAAK,IAAI,IAAI,CAAC;IACd,IAAI,IAAI,IAAI,CAAC;IACb,qGAAqG;IACrG,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/D,wEAAwE;IACxE,WAAW,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IAChD,aAAa,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC;IAC5C,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,GAAG,IAAI,CAAC;IACnD,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,GAAG,IAAI,CAAC;CACrD;AAED,kDAAkD;AAClD,eAAO,MAAM,mBAAmB,MAAM,CAAC;AACvC,oGAAoG;AACpG,eAAO,MAAM,gBAAgB,QAAS,CAAC;AAiCvC;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,GAAG,UAAU,CA2WrE"}
|