@minca/core 0.3.1 → 0.4.0
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 +2 -2
- package/dist/{session → hosting}/hosting.d.ts +1 -1
- package/dist/{session → hosting}/hosting.d.ts.map +1 -1
- package/dist/{session → hosting}/hosting.js.map +1 -1
- package/dist/index.d.ts +20 -28
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -19
- package/dist/index.js.map +1 -1
- package/dist/network/mesh.d.ts.map +1 -1
- package/dist/network/mesh.js +13 -3
- package/dist/network/mesh.js.map +1 -1
- package/dist/network/network-manager.d.ts +5 -0
- package/dist/network/network-manager.d.ts.map +1 -1
- package/dist/network/network-manager.js +3 -0
- package/dist/network/network-manager.js.map +1 -1
- package/dist/network/peer-auth.d.ts +17 -5
- package/dist/network/peer-auth.d.ts.map +1 -1
- package/dist/network/peer-auth.js +19 -9
- package/dist/network/peer-auth.js.map +1 -1
- package/dist/network/rtc-transport.d.ts.map +1 -1
- package/dist/network/rtc-transport.js +1 -0
- package/dist/network/rtc-transport.js.map +1 -1
- package/dist/network/transport.d.ts +12 -0
- package/dist/network/transport.d.ts.map +1 -1
- package/dist/network/ws-transport.d.ts +1 -1
- package/dist/network/ws-transport.d.ts.map +1 -1
- package/dist/network/ws-transport.js +14 -4
- package/dist/network/ws-transport.js.map +1 -1
- package/dist/node/index.d.ts +1 -5
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +0 -3
- package/dist/node/index.js.map +1 -1
- package/dist/node/node-hosting.js +1 -1
- package/dist/node/node-records.js +1 -1
- package/dist/node/node-records.js.map +1 -1
- package/dist/node/node.d.ts.map +1 -1
- package/dist/node/node.js +18 -0
- package/dist/node/node.js.map +1 -1
- package/dist/node/space-mirrors.d.ts +1 -1
- package/dist/node/space-mirrors.d.ts.map +1 -1
- package/dist/node/space-mirrors.js +17 -5
- package/dist/node/space-mirrors.js.map +1 -1
- package/dist/node/space-peers.d.ts +2 -0
- package/dist/node/space-peers.d.ts.map +1 -1
- package/dist/node/space-peers.js +41 -8
- package/dist/node/space-peers.js.map +1 -1
- package/dist/node/space-runtime.d.ts +4 -2
- package/dist/node/space-runtime.d.ts.map +1 -1
- package/dist/node/space-runtime.js +3 -2
- package/dist/node/space-runtime.js.map +1 -1
- package/dist/node/space-standing.d.ts.map +1 -1
- package/dist/node/space-standing.js +12 -38
- package/dist/node/space-standing.js.map +1 -1
- package/dist/node/space-warrants.js +1 -1
- package/dist/node/space-warrants.js.map +1 -1
- package/dist/node/space-writing.d.ts.map +1 -1
- package/dist/node/space-writing.js +12 -32
- package/dist/node/space-writing.js.map +1 -1
- package/dist/node/stores.d.ts +2 -58
- package/dist/node/stores.d.ts.map +1 -1
- package/dist/node/stores.js +1 -74
- package/dist/node/stores.js.map +1 -1
- package/dist/node/types.d.ts +3 -3
- package/dist/node/types.d.ts.map +1 -1
- package/dist/node/writer-keys.d.ts +15 -14
- package/dist/node/writer-keys.d.ts.map +1 -1
- package/dist/node/writer-keys.js +3 -113
- package/dist/node/writer-keys.js.map +1 -1
- package/dist/records/key.d.ts +16 -19
- package/dist/records/key.d.ts.map +1 -1
- package/dist/records/key.js +53 -45
- package/dist/records/key.js.map +1 -1
- package/dist/records/rules.d.ts +1 -1
- package/dist/records/rules.d.ts.map +1 -1
- package/dist/records/rules.js +6 -4
- package/dist/records/rules.js.map +1 -1
- package/dist/storage/body-cache.d.ts +6 -3
- package/dist/storage/body-cache.d.ts.map +1 -1
- package/dist/storage/body-cache.js +37 -14
- package/dist/storage/body-cache.js.map +1 -1
- package/dist/storage/mirror.d.ts.map +1 -1
- package/dist/storage/mirror.js +35 -16
- package/dist/storage/mirror.js.map +1 -1
- package/dist/storage/segment.d.ts +6 -2
- package/dist/storage/segment.d.ts.map +1 -1
- package/dist/storage/segment.js +8 -4
- package/dist/storage/segment.js.map +1 -1
- package/dist/storage/shared-store.d.ts +32 -0
- package/dist/storage/shared-store.d.ts.map +1 -0
- package/dist/storage/{folder-reconcile.js → shared-store.js} +15 -15
- package/dist/storage/shared-store.js.map +1 -0
- package/dist/storage/storage-provider.d.ts +0 -9
- package/dist/storage/storage-provider.d.ts.map +1 -1
- package/dist/storage/storage-provider.js +8 -8
- package/dist/storage/storage-provider.js.map +1 -1
- package/dist/sync/sync-engine.d.ts +7 -0
- package/dist/sync/sync-engine.d.ts.map +1 -1
- package/dist/sync/sync-engine.js +179 -47
- package/dist/sync/sync-engine.js.map +1 -1
- package/dist/sync/sync-messages.d.ts +1 -1
- package/dist/sync/sync-messages.js +1 -1
- package/dist/types.d.ts +19 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -1
- package/dist/utils/index.d.ts +5 -5
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +5 -5
- package/dist/utils/index.js.map +1 -1
- package/docs/README.md +3 -2
- package/docs/building-an-app.md +2 -2
- package/docs/node.md +24 -20
- package/docs/query-format.md +6 -5
- package/docs/records-and-queries.md +12 -13
- package/docs/storage.md +41 -15
- package/package.json +10 -19
- package/dist/identity/account-store.d.ts +0 -83
- package/dist/identity/account-store.d.ts.map +0 -1
- package/dist/identity/account-store.js +0 -234
- package/dist/identity/account-store.js.map +0 -1
- package/dist/identity/device-key.d.ts +0 -26
- package/dist/identity/device-key.d.ts.map +0 -1
- package/dist/identity/device-key.js +0 -48
- package/dist/identity/device-key.js.map +0 -1
- package/dist/identity/idb.d.ts +0 -19
- package/dist/identity/idb.d.ts.map +0 -1
- package/dist/identity/idb.js +0 -56
- package/dist/identity/idb.js.map +0 -1
- package/dist/node/worker.d.ts +0 -91
- package/dist/node/worker.d.ts.map +0 -1
- package/dist/node/worker.js +0 -344
- package/dist/node/worker.js.map +0 -1
- package/dist/node-worker.d.ts +0 -2
- package/dist/node-worker.d.ts.map +0 -1
- package/dist/node-worker.js +0 -16
- package/dist/node-worker.js.map +0 -1
- package/dist/session/account-hint.d.ts +0 -13
- package/dist/session/account-hint.d.ts.map +0 -1
- package/dist/session/account-hint.js +0 -54
- package/dist/session/account-hint.js.map +0 -1
- package/dist/session/channel-room.d.ts +0 -26
- package/dist/session/channel-room.d.ts.map +0 -1
- package/dist/session/channel-room.js +0 -56
- package/dist/session/channel-room.js.map +0 -1
- package/dist/session/connect-code.d.ts +0 -127
- package/dist/session/connect-code.d.ts.map +0 -1
- package/dist/session/connect-code.js +0 -408
- package/dist/session/connect-code.js.map +0 -1
- package/dist/session/connect.d.ts +0 -393
- package/dist/session/connect.d.ts.map +0 -1
- package/dist/session/connect.js +0 -587
- package/dist/session/connect.js.map +0 -1
- package/dist/session/connection.d.ts +0 -141
- package/dist/session/connection.d.ts.map +0 -1
- package/dist/session/connection.js +0 -344
- package/dist/session/connection.js.map +0 -1
- package/dist/session/index.d.ts +0 -24
- package/dist/session/index.d.ts.map +0 -1
- package/dist/session/index.js +0 -18
- package/dist/session/index.js.map +0 -1
- package/dist/session/pairing.d.ts +0 -97
- package/dist/session/pairing.d.ts.map +0 -1
- package/dist/session/pairing.js +0 -251
- package/dist/session/pairing.js.map +0 -1
- package/dist/session/places.d.ts +0 -71
- package/dist/session/places.d.ts.map +0 -1
- package/dist/session/places.js +0 -130
- package/dist/session/places.js.map +0 -1
- package/dist/session/popup.d.ts +0 -13
- package/dist/session/popup.d.ts.map +0 -1
- package/dist/session/popup.js +0 -23
- package/dist/session/popup.js.map +0 -1
- package/dist/session/stay-signed-in.d.ts +0 -48
- package/dist/session/stay-signed-in.d.ts.map +0 -1
- package/dist/session/stay-signed-in.js +0 -141
- package/dist/session/stay-signed-in.js.map +0 -1
- package/dist/storage/blob/directory.d.ts +0 -14
- package/dist/storage/blob/directory.d.ts.map +0 -1
- package/dist/storage/blob/directory.js +0 -87
- package/dist/storage/blob/directory.js.map +0 -1
- package/dist/storage/blob/memory.d.ts +0 -6
- package/dist/storage/blob/memory.d.ts.map +0 -1
- package/dist/storage/blob/memory.js +0 -20
- package/dist/storage/blob/memory.js.map +0 -1
- package/dist/storage/blob/s3.d.ts +0 -16
- package/dist/storage/blob/s3.d.ts.map +0 -1
- package/dist/storage/blob/s3.js +0 -91
- package/dist/storage/blob/s3.js.map +0 -1
- package/dist/storage/directory-access.d.ts +0 -36
- package/dist/storage/directory-access.d.ts.map +0 -1
- package/dist/storage/directory-access.js +0 -89
- package/dist/storage/directory-access.js.map +0 -1
- package/dist/storage/folder-adapter.d.ts +0 -100
- package/dist/storage/folder-adapter.d.ts.map +0 -1
- package/dist/storage/folder-adapter.js +0 -232
- package/dist/storage/folder-adapter.js.map +0 -1
- package/dist/storage/folder-reconcile.d.ts +0 -33
- package/dist/storage/folder-reconcile.d.ts.map +0 -1
- package/dist/storage/folder-reconcile.js.map +0 -1
- package/dist/storage/index.d.ts +0 -6
- package/dist/storage/index.d.ts.map +0 -1
- package/dist/storage/index.js +0 -5
- package/dist/storage/index.js.map +0 -1
- package/dist/storage/indexeddb-adapter.d.ts +0 -8
- package/dist/storage/indexeddb-adapter.d.ts.map +0 -1
- package/dist/storage/indexeddb-adapter.js +0 -128
- package/dist/storage/indexeddb-adapter.js.map +0 -1
- package/dist/storage/sqlite-adapter.d.ts +0 -57
- package/dist/storage/sqlite-adapter.d.ts.map +0 -1
- package/dist/storage/sqlite-adapter.js +0 -213
- package/dist/storage/sqlite-adapter.js.map +0 -1
- /package/dist/{session → hosting}/hosting.js +0 -0
package/docs/building-an-app.md
CHANGED
|
@@ -14,7 +14,7 @@ Every app starts by asking the person for access, with
|
|
|
14
14
|
declare function Todos(): React.JSX.Element;
|
|
15
15
|
// ---cut---
|
|
16
16
|
import { createRoot } from 'react-dom/client';
|
|
17
|
-
import { createMincaConnection } from '@minca/
|
|
17
|
+
import { createMincaConnection } from '@minca/session';
|
|
18
18
|
import { MincaProvider, useConnection } from '@minca/react';
|
|
19
19
|
|
|
20
20
|
const connection = createMincaConnection({
|
|
@@ -58,7 +58,7 @@ The person's account, its settings and its other apps live at their home, not
|
|
|
58
58
|
in your app. Open it from a click, for the account your app acts for:
|
|
59
59
|
|
|
60
60
|
```ts
|
|
61
|
-
import type { MincaConnection } from '@minca/
|
|
61
|
+
import type { MincaConnection } from '@minca/session';
|
|
62
62
|
declare const connection: MincaConnection;
|
|
63
63
|
// ---cut---
|
|
64
64
|
connection.openHome(); // the account page
|
package/docs/node.md
CHANGED
|
@@ -7,7 +7,8 @@ sync. Most apps never make one: the connection starts it for you
|
|
|
7
7
|
that holds the account's keys, such as a script, a server or a test.
|
|
8
8
|
|
|
9
9
|
```ts
|
|
10
|
-
import { createNode, deriveAccountKey, generateSeed,
|
|
10
|
+
import { createNode, deriveAccountKey, generateSeed, rootFromSeed } from '@minca/core';
|
|
11
|
+
import { indexedDBStores } from '@minca/storage/indexeddb';
|
|
11
12
|
|
|
12
13
|
const seed = generateSeed();
|
|
13
14
|
const { signer } = await rootFromSeed(seed);
|
|
@@ -177,22 +178,23 @@ A node asks its `StoreFactory` for stores by path:
|
|
|
177
178
|
It also opens `mirrors/<spaceId>/<n>` for a [mirror](storage.md#mirrors),
|
|
178
179
|
`folder/<spaceId>` for a data folder, and `host` for a host's subscriptions.
|
|
179
180
|
|
|
180
|
-
What a path means is up to the factory
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
181
|
+
What a path means is up to the factory. Each comes from its own entry point
|
|
182
|
+
of `@minca/storage`, so an app bundles only the one it uses:
|
|
183
|
+
|
|
184
|
+
- `indexedDBStores(prefix)` (`@minca/storage/indexeddb`) makes one
|
|
185
|
+
IndexedDB database per path, named `<prefix>:<path with / replaced by :>`.
|
|
186
|
+
It never seals, since the browser profile already guards it.
|
|
187
|
+
- `folderStores(directory, { basePath?, localKey?, local? })`
|
|
188
|
+
(`@minca/storage/folder`) uses a [data folder](storage.md#data-folders).
|
|
189
|
+
The `registry` goes in the folder under `basePath`, sealed under
|
|
190
|
+
`localKey` (`deriveLocalKey(seed)`) when given. Every other path goes in
|
|
191
|
+
`local`, and each space is mirrored to the folder's segments.
|
|
192
|
+
- `directoryStores(directory, { localKey? })` (`@minca/storage/folder`) uses
|
|
193
|
+
a directory on this device, one file per entry and per version, sealing
|
|
194
|
+
the `registry` the same way.
|
|
195
|
+
- `sqliteStores(db, { localKey? })` (`@minca/storage/sqlite`) keeps every
|
|
196
|
+
path in one SQLite database, given its connection
|
|
197
|
+
([SQLite](storage.md#sqlite)), sealing the `registry` the same way.
|
|
196
198
|
|
|
197
199
|
[Sign-in](sign-in.md) picks stores with `storesFor(account)`: IndexedDB with
|
|
198
200
|
prefix `minca:<dataPath with : for />` in the browser, or `folderStores(pod,
|
|
@@ -338,7 +340,8 @@ by default.
|
|
|
338
340
|
```ts
|
|
339
341
|
declare const signer: RootSigner;
|
|
340
342
|
// ---cut---
|
|
341
|
-
import { createNode,
|
|
343
|
+
import { createNode, type RootSigner } from '@minca/core';
|
|
344
|
+
import { indexedDBStores } from '@minca/storage/indexeddb';
|
|
342
345
|
|
|
343
346
|
const node = await createNode({
|
|
344
347
|
signer,
|
|
@@ -872,7 +875,7 @@ starts again unconnected.
|
|
|
872
875
|
`homeAddress(input)` turns what a person typed into the home's connect page:
|
|
873
876
|
|
|
874
877
|
```ts
|
|
875
|
-
import { homeAddress } from '@minca/
|
|
878
|
+
import { homeAddress } from '@minca/session';
|
|
876
879
|
|
|
877
880
|
homeAddress('minca.example.com'); // 'https://minca.example.com/connect'
|
|
878
881
|
```
|
|
@@ -972,7 +975,8 @@ Each tab acts for its own account, and sees other tabs' changes to
|
|
|
972
975
|
`state.accounts`. A tab whose account was connected again elsewhere keeps
|
|
973
976
|
its key until it restarts, then takes the newer grant. One whose key was
|
|
974
977
|
revoked takes up a newer grant rather than forgetting it. A shared worker
|
|
975
|
-
runs a node per key. Switching again before a node has started closes it
|
|
978
|
+
runs a node per key. Switching again before a node has started closes it,
|
|
979
|
+
or stops it waiting for its turn.
|
|
976
980
|
[Spec 06 §2.10](https://github.com/leifriksheim/minca/blob/main/spec/06-nodes-and-sessions.md).
|
|
977
981
|
|
|
978
982
|
### Showing notifications
|
package/docs/query-format.md
CHANGED
|
@@ -83,11 +83,12 @@ open are left out, here and in every include, so a result's `body` is never
|
|
|
83
83
|
`null`. What "stands" means is in
|
|
84
84
|
[spec 02 §9.5](https://github.com/leifriksheim/minca/blob/main/spec/02-records.md).
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
A record whose body or links don't fit its collection's definition is still
|
|
87
|
+
counted, here, in every include and in every count, and comes flagged
|
|
88
|
+
`conforms: false`. Whether it fits depends on the definition in force and on
|
|
89
|
+
the records it links to, which other people write. Leaving it out would let
|
|
90
|
+
whoever defines the collection, or owns a record others link to, hide those
|
|
91
|
+
records from everyone. Show the flag instead.
|
|
91
92
|
|
|
92
93
|
## Field values
|
|
93
94
|
|
|
@@ -204,8 +204,10 @@ signed, not the person. `node.spaces.profiles(space)` maps accounts to names.
|
|
|
204
204
|
|
|
205
205
|
## Keys
|
|
206
206
|
|
|
207
|
-
A record's key says whose it is
|
|
208
|
-
|
|
207
|
+
A record's key says whose it is and which collection it is in. Every key
|
|
208
|
+
starts with its owner's part, a hash of the account and the collection, so no
|
|
209
|
+
one else can create a record there, and no record of another collection can
|
|
210
|
+
take it.
|
|
209
211
|
|
|
210
212
|
Most records just take the fresh key `put` gives them. Some records there is
|
|
211
213
|
one of per account, like settings. For those, pass a name:
|
|
@@ -213,34 +215,31 @@ one of per account, like settings. For those, pass a name:
|
|
|
213
215
|
```typescript
|
|
214
216
|
await node.records.put(space.id, 'app.settings', { theme: 'dark' }, { key: 'settings' });
|
|
215
217
|
|
|
216
|
-
const mine = await node.records.keyFor(space.id, 'settings'); // '
|
|
217
|
-
const theirs = await node.records.keyFor(space.id, 'settings', did); // someone else's, if they wrote one
|
|
218
|
+
const mine = await node.records.keyFor(space.id, 'app.settings', 'settings'); // 'mj6bhbzx5m7tqmu35fjtg4wo4u.settings'
|
|
219
|
+
const theirs = await node.records.keyFor(space.id, 'app.settings', 'settings', did); // someone else's, if they wrote one
|
|
218
220
|
await node.records.get(space.id, theirs);
|
|
219
221
|
```
|
|
220
222
|
|
|
221
|
-
- The name goes in your account's namespace, so two
|
|
222
|
-
choose `settings` get two records
|
|
223
|
+
- The name goes in your account's namespace for that collection, so two
|
|
224
|
+
accounts that both choose `settings` get two records, and so do two
|
|
225
|
+
collections.
|
|
223
226
|
- Names are 1–101 characters of `a`–`z`, `0`–`9` and `: . _ -`.
|
|
224
227
|
- Read and link records by their whole `key`, as `put` gives it, not by the
|
|
225
228
|
name.
|
|
226
|
-
- A name is the same key in every collection, and a record keeps its
|
|
227
|
-
collection for life. So `put` refuses a name you already hold in another
|
|
228
|
-
collection, deleted or not. Put the collection in the name
|
|
229
|
-
(`app.todo.settings`) so two of your apps never clash.
|
|
230
229
|
- Writing a deleted key brings the record back. Pass the whole key when it is
|
|
231
230
|
already yours.
|
|
232
|
-
- A name of the form `one:<hex>` is refused outside a `onePer` collection.
|
|
233
231
|
|
|
234
232
|
In a collection with a `onePer` rule, the node works out the key for you
|
|
235
233
|
from the parts the rule names, and `node.records.onePerKey` tells you what it
|
|
236
234
|
is. With `@author` the key is the writer's. Without, it is a shared `one:…`
|
|
237
|
-
key ([Collections](collections.md#rules)). In a private space it is keyed with
|
|
235
|
+
key of the collection's ([Collections](collections.md#rules)). In a private space it is keyed with
|
|
238
236
|
the space's key, so it says nothing to someone who can't read the space.
|
|
239
237
|
|
|
240
238
|
An account's line in a collection, for contracts, has the key
|
|
241
239
|
`lineKey(account, collection)`, exported by `@minca/core`.
|
|
242
240
|
|
|
243
|
-
Every peer refuses a first version at a key the writer doesn't own
|
|
241
|
+
Every peer refuses a first version at a key the writer doesn't own in that
|
|
242
|
+
collection. The rule
|
|
244
243
|
is in [spec 02 §4.1](https://github.com/leifriksheim/minca/blob/main/spec/02-records.md).
|
|
245
244
|
|
|
246
245
|
## When two devices edit at once
|
package/docs/storage.md
CHANGED
|
@@ -188,7 +188,7 @@ compaction left.
|
|
|
188
188
|
`~/.local/state/minca`, then `<first 16 hex of SHA-256 of the home's
|
|
189
189
|
path>/<account id>/stores`. A
|
|
190
190
|
command and the daemon share it, and the daemon finds the command's writes
|
|
191
|
-
(`
|
|
191
|
+
(`reconcileSharedStore`). Writer keys are beside it in `writer-keys/`. Older
|
|
192
192
|
slots left in the home, and `writers/`, are not read, so two versions of
|
|
193
193
|
minca never sign with one key. `minca agent` and the commands an agent runs
|
|
194
194
|
keep each session's key and stores in a slot of `<home>/agent`
|
|
@@ -258,12 +258,13 @@ last compaction left, it compacts them, keeping only what its store holds.
|
|
|
258
258
|
It keeps its state in the store `mirrors/<space id>/<n>`, where `n` is the
|
|
259
259
|
mirror's index:
|
|
260
260
|
|
|
261
|
-
| Key | Value
|
|
262
|
-
| --------------------------- |
|
|
263
|
-
| `mirror:writer` | The writer id
|
|
264
|
-
| `mirror:counter` | The segment counter, in decimal
|
|
265
|
-
| `mirror:read:<segment key>` | `1`, for each segment read or written
|
|
266
|
-
| `mirror:known:<version id>` | `1`, for each version known to be there
|
|
261
|
+
| Key | Value |
|
|
262
|
+
| --------------------------- | ------------------------------------------------------------------------------------- |
|
|
263
|
+
| `mirror:writer` | The writer id |
|
|
264
|
+
| `mirror:counter` | The segment counter, in decimal |
|
|
265
|
+
| `mirror:read:<segment key>` | `1`, for each segment read or written |
|
|
266
|
+
| `mirror:known:<version id>` | `1`, for each version known to be there |
|
|
267
|
+
| `mirror:left` | How many segments the last compaction left, in decimal: the next waits for twice that |
|
|
267
268
|
|
|
268
269
|
"Known" is everything it uploaded or read, so nobody uploads everyone
|
|
269
270
|
else's versions again. It reads the `mirror:known:` entries once, when it
|
|
@@ -310,10 +311,12 @@ With `commit`, placing a version is one atomic write. Without it, versions go
|
|
|
310
311
|
first, then the entries in one batch, then the deletes. So no entry ever
|
|
311
312
|
names a version that isn't there.
|
|
312
313
|
|
|
313
|
-
The library's adapters are
|
|
314
|
-
(
|
|
315
|
-
|
|
316
|
-
|
|
314
|
+
The library's adapters are in `@minca/storage`, one entry point each:
|
|
315
|
+
IndexedDB (`/indexeddb`, [above](#indexeddb)), a directory (`/folder`, for a
|
|
316
|
+
data folder's registry and a node's stores on disk), SQLite (`/sqlite`,
|
|
317
|
+
[below](#sqlite)), S3 (`/s3`, for [mirrors](#mirrors)) and memory
|
|
318
|
+
(`/memory`, for tests). `@minca/core` keeps the interfaces and the sealing
|
|
319
|
+
wrapper, `createEncryptedAdapter`.
|
|
317
320
|
|
|
318
321
|
A directory store keeps its versions and its entries' keys in memory, so a
|
|
319
322
|
query or a listing reads no directory. It reads the keys again when the node
|
|
@@ -334,7 +337,7 @@ host keeps its stores this way. Pass it a connection: `DatabaseSync` from
|
|
|
334
337
|
imports no driver, so it runs wherever one does.
|
|
335
338
|
|
|
336
339
|
```ts
|
|
337
|
-
import { sqliteStores, type SqliteDatabase } from '@minca/
|
|
340
|
+
import { sqliteStores, type SqliteDatabase } from '@minca/storage/sqlite';
|
|
338
341
|
declare const DatabaseSync: new (file: string) => SqliteDatabase;
|
|
339
342
|
// ---cut---
|
|
340
343
|
// import { DatabaseSync } from 'node:sqlite';
|
|
@@ -359,10 +362,12 @@ version bodies, letting the one used longest ago go first. A body never
|
|
|
359
362
|
changes, so this is always safe. An entry read while a change was landing is
|
|
360
363
|
not kept.
|
|
361
364
|
|
|
362
|
-
Each store keeps up to
|
|
365
|
+
Each store keeps up to 32 MB of bodies of its own, unless its store factory
|
|
363
366
|
has a `cache`. Then all the stores share that one. The SQLite stores share
|
|
364
|
-
|
|
365
|
-
take the same memory however many spaces it holds
|
|
367
|
+
16 MB, since reading a body again is cheap: the bodies a node keeps then
|
|
368
|
+
take the same memory however many spaces it holds, and however large their
|
|
369
|
+
records are. The cache counts bytes, not bodies, and a body larger than a
|
|
370
|
+
quarter of it isn't kept at all. Each open space still
|
|
366
371
|
keeps its sets and entries.
|
|
367
372
|
|
|
368
373
|
When another writer changes the same store, the node reads all of it again
|
|
@@ -415,6 +420,27 @@ a node speaks, and how much it asks for at once, is its own choice:
|
|
|
415
420
|
| Stale after | 30 s | A silent session, or an unanswered `want`, is dropped and found again later |
|
|
416
421
|
| Versions waiting | 1,000 | Versions held back for later wait in memory. Past 1,000 the oldest go |
|
|
417
422
|
| Refusals remembered | 10,000 | A refused version isn't asked of that peer again. Past 10,000 the oldest are forgotten |
|
|
423
|
+
| A message's versions | 1 MB, besides the 200 | Large records go a few to a message, so a space of photos syncs like one of notes |
|
|
424
|
+
| Sending what's lacked | a message at a time | Read from the store as it goes, after the connection drains below 1 MB |
|
|
425
|
+
| Taking in | one message from a peer at a time | Past 8 waiting, the node stops reading from that peer until 2 are left |
|
|
426
|
+
|
|
427
|
+
A node sends what a peer lacks a message at a time, reading it from its
|
|
428
|
+
store as it goes, and only once the connection has under 1 MB left to
|
|
429
|
+
send; it answers a `want` the same way. A record's versions still go
|
|
430
|
+
together: the store is read once to learn which record each version is of,
|
|
431
|
+
then again to send. Until what a session found the peer lacks has been
|
|
432
|
+
sent, the collection isn't level with the peer, and no new session starts
|
|
433
|
+
for it, so a slow link is never sent the same versions twice.
|
|
434
|
+
|
|
435
|
+
So with honest peers, a node's memory follows how many it talks to, not
|
|
436
|
+
how large their spaces are: a host taking in a 150 MB space, or handing it
|
|
437
|
+
to a new device, holds a few megabytes of it at a time. The connection is
|
|
438
|
+
what waits. A sender whose socket is backed up stops reading from its
|
|
439
|
+
store, and a receiver that has stopped reading lets the network hold the
|
|
440
|
+
rest. Pausing needs a connection that can pause: a host's sockets can,
|
|
441
|
+
WebRTC and a browser's WebSocket can't. A dishonest peer can still send
|
|
442
|
+
messages as large as the connection takes, eight of them before a host
|
|
443
|
+
stops reading.
|
|
418
444
|
|
|
419
445
|
The side that starts reconciling begins with the space's own records
|
|
420
446
|
(`sys.*`, profiles among them), then the rest from the collection it holds
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@minca/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "The Minca protocol: identity, signed records, spaces, the network and sync, and a node that holds them",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/leifriksheim/minca.git",
|
|
@@ -21,30 +21,20 @@
|
|
|
21
21
|
"types": "./dist/index.d.ts",
|
|
22
22
|
"import": "./dist/index.js"
|
|
23
23
|
},
|
|
24
|
-
"./storage": {
|
|
25
|
-
"@minca/source": "./src/storage/index.ts",
|
|
26
|
-
"types": "./dist/storage/index.d.ts",
|
|
27
|
-
"import": "./dist/storage/index.js"
|
|
28
|
-
},
|
|
29
|
-
"./node-worker": {
|
|
30
|
-
"@minca/source": "./src/node-worker.ts",
|
|
31
|
-
"types": "./dist/node-worker.d.ts",
|
|
32
|
-
"import": "./dist/node-worker.js"
|
|
33
|
-
},
|
|
34
24
|
"./schemas": {
|
|
35
25
|
"@minca/source": "./src/schemas/index.ts",
|
|
36
26
|
"types": "./dist/schemas/index.d.ts",
|
|
37
27
|
"import": "./dist/schemas/index.js"
|
|
38
28
|
},
|
|
39
|
-
"./session": {
|
|
40
|
-
"@minca/source": "./src/session/index.ts",
|
|
41
|
-
"types": "./dist/session/index.d.ts",
|
|
42
|
-
"import": "./dist/session/index.js"
|
|
43
|
-
},
|
|
44
29
|
"./inbox": {
|
|
45
30
|
"@minca/source": "./src/inbox/index.ts",
|
|
46
31
|
"types": "./dist/inbox/index.d.ts",
|
|
47
32
|
"import": "./dist/inbox/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./utils": {
|
|
35
|
+
"@minca/source": "./src/utils/index.ts",
|
|
36
|
+
"types": "./dist/utils/index.d.ts",
|
|
37
|
+
"import": "./dist/utils/index.js"
|
|
48
38
|
}
|
|
49
39
|
},
|
|
50
40
|
"scripts": {
|
|
@@ -58,7 +48,9 @@
|
|
|
58
48
|
"devDependencies": {
|
|
59
49
|
"@minca/actions": "*",
|
|
60
50
|
"@minca/auth": "*",
|
|
51
|
+
"@minca/session": "*",
|
|
61
52
|
"@minca/std": "*",
|
|
53
|
+
"@minca/storage": "*",
|
|
62
54
|
"@types/ws": "^8.18.2",
|
|
63
55
|
"esbuild": "^0.28.2",
|
|
64
56
|
"tsx": "^4.19.0",
|
|
@@ -74,8 +66,7 @@
|
|
|
74
66
|
"@cfworker/json-schema": "^4.1.1",
|
|
75
67
|
"@noble/curves": "^2.4.0",
|
|
76
68
|
"@noble/hashes": "^2.4.0",
|
|
77
|
-
"@scure/base": "^2.4.0"
|
|
78
|
-
"aws4fetch": "^1.0.20"
|
|
69
|
+
"@scure/base": "^2.4.0"
|
|
79
70
|
},
|
|
80
71
|
"publishConfig": {
|
|
81
72
|
"access": "public"
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module account-store
|
|
3
|
-
* The accounts that live somewhere — in a folder, or in this browser.
|
|
4
|
-
*
|
|
5
|
-
* A folder is a disk, not a person. Several people can keep accounts in one, and
|
|
6
|
-
* one person can keep several: work and personal, or a spare for testing. So the
|
|
7
|
-
* folder holds a list of who has an account in it, and a subtree per account.
|
|
8
|
-
*
|
|
9
|
-
* ```
|
|
10
|
-
* <folder>/
|
|
11
|
-
* accounts.json name, DID and id of each account
|
|
12
|
-
* accounts/<id>/account.json that account's keys, locked
|
|
13
|
-
* accounts/<id>/stores/... that account's spaces
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* **The list is readable without unlocking anything**, which it has to be — you
|
|
17
|
-
* cannot offer someone a choice of accounts without knowing their names. So
|
|
18
|
-
* whoever holds the folder can see how many accounts are in it and what they
|
|
19
|
-
* are called. What they cannot do is open one.
|
|
20
|
-
*
|
|
21
|
-
* A browser with no folder keeps the same shape in IndexedDB, so the app above
|
|
22
|
-
* has one model rather than two.
|
|
23
|
-
*/
|
|
24
|
-
import type { DirectoryHandleLike } from '../storage/folder-adapter.js';
|
|
25
|
-
import { type AccountVault } from './account-vault.js';
|
|
26
|
-
/** What can be known about an account without unlocking it */
|
|
27
|
-
export interface AccountSummary {
|
|
28
|
-
/** Stable, random, and the name of this account's subtree */
|
|
29
|
-
readonly id: string;
|
|
30
|
-
/** What the person called it. A label — never part of any key. */
|
|
31
|
-
readonly name: string;
|
|
32
|
-
readonly did: string;
|
|
33
|
-
readonly createdAt: string;
|
|
34
|
-
/**
|
|
35
|
-
* Where this account's spaces live, relative to the store root.
|
|
36
|
-
*
|
|
37
|
-
* Carried rather than computed so that a row filed again under a fresh id
|
|
38
|
-
* keeps pointing at the subtree its data already lives in.
|
|
39
|
-
*/
|
|
40
|
-
readonly dataPath: string;
|
|
41
|
-
readonly lastUsedAt?: string;
|
|
42
|
-
}
|
|
43
|
-
export interface AccountStore {
|
|
44
|
-
readonly kind: 'folder' | 'browser';
|
|
45
|
-
/**
|
|
46
|
-
* Every account here, most recently used first.
|
|
47
|
-
*
|
|
48
|
-
* At most one entry per identity. Two rows for one DID is always a mistake —
|
|
49
|
-
* they would appear as separate accounts in a picker while being the same
|
|
50
|
-
* person — so a duplicate is collapsed onto the most recently used.
|
|
51
|
-
*/
|
|
52
|
-
list(): Promise<ReadonlyArray<AccountSummary>>;
|
|
53
|
-
/** One account's locked keys */
|
|
54
|
-
read(id: string): Promise<AccountVault | null>;
|
|
55
|
-
/** Adds or replaces an account */
|
|
56
|
-
write(summary: AccountSummary, vault: AccountVault): Promise<void>;
|
|
57
|
-
/** Forgets an account, and everything it owns */
|
|
58
|
-
remove(id: string): Promise<void>;
|
|
59
|
-
}
|
|
60
|
-
/** Where a brand new account keeps its spaces. */
|
|
61
|
-
export declare function accountDataPath(id: string): string;
|
|
62
|
-
/** A short, stable, filename-safe id for a new account. */
|
|
63
|
-
export declare function newAccountId(): string;
|
|
64
|
-
/**
|
|
65
|
-
* Whether an id has the shape {@link newAccountId} gives one.
|
|
66
|
-
*
|
|
67
|
-
* An id names a directory, and `remove` deletes that directory with everything
|
|
68
|
-
* in it. The list it comes from is a plain file in a folder that may be synced
|
|
69
|
-
* or shared, so an id is checked before it is trusted with a path.
|
|
70
|
-
*/
|
|
71
|
-
export declare function isAccountId(id: unknown): id is string;
|
|
72
|
-
/** Opens the accounts kept in a folder. */
|
|
73
|
-
export declare function createFolderAccountStore(dir: DirectoryHandleLike): AccountStore;
|
|
74
|
-
/**
|
|
75
|
-
* Opens the accounts kept in this browser, for when there is no folder.
|
|
76
|
-
*
|
|
77
|
-
* Same shape as a folder store, so nothing above has to know which it got —
|
|
78
|
-
* the difference is only that no other origin can read this one.
|
|
79
|
-
*
|
|
80
|
-
* @param dbName Overridable for tests
|
|
81
|
-
*/
|
|
82
|
-
export declare function createBrowserAccountStore(dbName?: string): Promise<AccountStore>;
|
|
83
|
-
//# sourceMappingURL=account-store.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"account-store.d.ts","sourceRoot":"","sources":["../../src/identity/account-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAExE,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAMvE,8DAA8D;AAC9D,MAAM,WAAW,cAAc;IAC7B,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,kEAAkE;IAClE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAC;IACpC;;;;;;OAMG;IACH,IAAI,IAAI,OAAO,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC,CAAC;IAC/C,gCAAgC;IAChC,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAC/C,kCAAkC;IAClC,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnE,iDAAiD;IACjD,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnC;AAMD,kDAAkD;AAClD,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,2DAA2D;AAC3D,wBAAgB,YAAY,IAAI,MAAM,CAKrC;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,IAAI,MAAM,CAErD;AAgED,2CAA2C;AAC3C,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,mBAAmB,GAAG,YAAY,CAyF/E;AA0BD;;;;;;;GAOG;AACH,wBAAsB,yBAAyB,CAAC,MAAM,SAAU,GAAG,OAAO,CAAC,YAAY,CAAC,CA6BvF"}
|