@minca/core 0.1.14 → 0.1.16
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 +4 -4
- package/dist/elements/auth-styles.d.ts +1 -1
- package/dist/elements/auth-styles.d.ts.map +1 -1
- package/dist/elements/auth-styles.js +21 -4
- package/dist/elements/auth-styles.js.map +1 -1
- package/dist/elements/minca-auth.d.ts.map +1 -1
- package/dist/elements/minca-auth.js +151 -57
- package/dist/elements/minca-auth.js.map +1 -1
- package/dist/files/space-files.d.ts +15 -3
- package/dist/files/space-files.d.ts.map +1 -1
- package/dist/files/space-files.js +225 -37
- package/dist/files/space-files.js.map +1 -1
- package/dist/identity/abilities.d.ts +2 -0
- package/dist/identity/abilities.d.ts.map +1 -1
- package/dist/identity/abilities.js +2 -0
- package/dist/identity/abilities.js.map +1 -1
- package/dist/identity/account-vault.d.ts +15 -71
- package/dist/identity/account-vault.d.ts.map +1 -1
- package/dist/identity/account-vault.js +45 -104
- package/dist/identity/account-vault.js.map +1 -1
- package/dist/identity/channel.d.ts +3 -9
- package/dist/identity/channel.d.ts.map +1 -1
- package/dist/identity/channel.js +42 -42
- package/dist/identity/channel.js.map +1 -1
- package/dist/identity/contact-key.d.ts +14 -29
- package/dist/identity/contact-key.d.ts.map +1 -1
- package/dist/identity/contact-key.js +31 -51
- package/dist/identity/contact-key.js.map +1 -1
- package/dist/identity/crypto-p256.d.ts.map +1 -1
- package/dist/identity/crypto-p256.js +39 -53
- package/dist/identity/crypto-p256.js.map +1 -1
- package/dist/identity/hpke.d.ts.map +1 -1
- package/dist/identity/hpke.js +19 -19
- package/dist/identity/hpke.js.map +1 -1
- package/dist/identity/identity-manager.d.ts.map +1 -1
- package/dist/identity/identity-manager.js +1 -2
- package/dist/identity/identity-manager.js.map +1 -1
- package/dist/identity/policy.d.ts.map +1 -1
- package/dist/identity/policy.js +35 -61
- package/dist/identity/policy.js.map +1 -1
- package/dist/identity/recovery-code.d.ts +2 -8
- package/dist/identity/recovery-code.d.ts.map +1 -1
- package/dist/identity/recovery-code.js +4 -11
- package/dist/identity/recovery-code.js.map +1 -1
- package/dist/identity/root-signer.d.ts +1 -6
- package/dist/identity/root-signer.d.ts.map +1 -1
- package/dist/identity/root-signer.js +12 -15
- package/dist/identity/root-signer.js.map +1 -1
- package/dist/identity/ucan.d.ts.map +1 -1
- package/dist/identity/ucan.js +48 -39
- package/dist/identity/ucan.js.map +1 -1
- package/dist/identity/webauthn.d.ts +6 -11
- package/dist/identity/webauthn.d.ts.map +1 -1
- package/dist/identity/webauthn.js +18 -30
- package/dist/identity/webauthn.js.map +1 -1
- package/dist/inbox/inbox.d.ts.map +1 -1
- package/dist/inbox/inbox.js +40 -30
- package/dist/inbox/inbox.js.map +1 -1
- package/dist/inbox/index.d.ts +2 -0
- package/dist/inbox/index.d.ts.map +1 -1
- package/dist/inbox/index.js +1 -0
- package/dist/inbox/index.js.map +1 -1
- package/dist/inbox/names.d.ts +54 -0
- package/dist/inbox/names.d.ts.map +1 -0
- package/dist/inbox/names.js +299 -0
- package/dist/inbox/names.js.map +1 -0
- package/dist/index.d.ts +3 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -12
- package/dist/index.js.map +1 -1
- package/dist/network/mesh.d.ts +7 -20
- package/dist/network/mesh.d.ts.map +1 -1
- package/dist/network/mesh.js +267 -245
- package/dist/network/mesh.js.map +1 -1
- package/dist/network/relay-link.d.ts +31 -0
- package/dist/network/relay-link.d.ts.map +1 -0
- package/dist/network/relay-link.js +62 -0
- package/dist/network/relay-link.js.map +1 -0
- package/dist/network/relay-minca.d.ts +12 -1
- package/dist/network/relay-minca.d.ts.map +1 -1
- package/dist/network/relay-minca.js +25 -55
- package/dist/network/relay-minca.js.map +1 -1
- package/dist/network/relay-nostr.d.ts +14 -3
- package/dist/network/relay-nostr.d.ts.map +1 -1
- package/dist/network/relay-nostr.js +34 -72
- package/dist/network/relay-nostr.js.map +1 -1
- package/dist/network/relay-socket.d.ts +1 -1
- package/dist/network/relay-socket.d.ts.map +1 -1
- package/dist/network/relay-socket.js +3 -1
- package/dist/network/relay-socket.js.map +1 -1
- package/dist/network/relays.d.ts +26 -17
- package/dist/network/relays.d.ts.map +1 -1
- package/dist/network/relays.js +21 -28
- package/dist/network/relays.js.map +1 -1
- package/dist/network/rendezvous.d.ts +1 -1
- package/dist/network/rendezvous.d.ts.map +1 -1
- package/dist/network/rendezvous.js +2 -2
- package/dist/network/rendezvous.js.map +1 -1
- package/dist/node/actions.d.ts.map +1 -1
- package/dist/node/actions.js +56 -39
- package/dist/node/actions.js.map +1 -1
- package/dist/node/api.d.ts +6 -0
- package/dist/node/api.d.ts.map +1 -1
- package/dist/node/api.js +6 -0
- package/dist/node/api.js.map +1 -1
- package/dist/node/carrier.d.ts +5 -0
- package/dist/node/carrier.d.ts.map +1 -1
- package/dist/node/carrier.js +94 -73
- package/dist/node/carrier.js.map +1 -1
- package/dist/node/copy.d.ts +8 -7
- package/dist/node/copy.d.ts.map +1 -1
- package/dist/node/copy.js +54 -56
- package/dist/node/copy.js.map +1 -1
- package/dist/node/host.d.ts +39 -65
- package/dist/node/host.d.ts.map +1 -1
- package/dist/node/host.js +362 -379
- package/dist/node/host.js.map +1 -1
- package/dist/node/index.d.ts +2 -2
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +1 -1
- package/dist/node/index.js.map +1 -1
- package/dist/node/node-carriers.d.ts +35 -0
- package/dist/node/node-carriers.d.ts.map +1 -0
- package/dist/node/node-carriers.js +562 -0
- package/dist/node/node-carriers.js.map +1 -0
- package/dist/node/node-contacts.d.ts +11 -0
- package/dist/node/node-contacts.d.ts.map +1 -0
- package/dist/node/node-contacts.js +808 -0
- package/dist/node/node-contacts.js.map +1 -0
- package/dist/node/node-context.d.ts +76 -0
- package/dist/node/node-context.d.ts.map +1 -0
- package/dist/node/node-context.js +54 -0
- package/dist/node/node-context.js.map +1 -0
- package/dist/node/node-hosting.d.ts +20 -0
- package/dist/node/node-hosting.d.ts.map +1 -0
- package/dist/node/node-hosting.js +449 -0
- package/dist/node/node-hosting.js.map +1 -0
- package/dist/node/node-records.d.ts +18 -0
- package/dist/node/node-records.d.ts.map +1 -0
- package/dist/node/node-records.js +262 -0
- package/dist/node/node-records.js.map +1 -0
- package/dist/node/node.d.ts.map +1 -1
- package/dist/node/node.js +197 -1989
- package/dist/node/node.js.map +1 -1
- package/dist/node/remote.d.ts +5 -6
- package/dist/node/remote.d.ts.map +1 -1
- package/dist/node/remote.js +272 -260
- package/dist/node/remote.js.map +1 -1
- package/dist/node/space-catalog.d.ts +40 -0
- package/dist/node/space-catalog.d.ts.map +1 -0
- package/dist/node/space-catalog.js +158 -0
- package/dist/node/space-catalog.js.map +1 -0
- package/dist/node/space-checks.d.ts +25 -0
- package/dist/node/space-checks.d.ts.map +1 -0
- package/dist/node/space-checks.js +343 -0
- package/dist/node/space-checks.js.map +1 -0
- package/dist/node/space-history.d.ts +37 -0
- package/dist/node/space-history.d.ts.map +1 -0
- package/dist/node/space-history.js +350 -0
- package/dist/node/space-history.js.map +1 -0
- package/dist/node/space-holding.d.ts +49 -0
- package/dist/node/space-holding.d.ts.map +1 -0
- package/dist/node/space-holding.js +267 -0
- package/dist/node/space-holding.js.map +1 -0
- package/dist/node/space-index.d.ts +41 -0
- package/dist/node/space-index.d.ts.map +1 -0
- package/dist/node/space-index.js +217 -0
- package/dist/node/space-index.js.map +1 -0
- package/dist/node/space-keys.d.ts +34 -0
- package/dist/node/space-keys.d.ts.map +1 -0
- package/dist/node/space-keys.js +309 -0
- package/dist/node/space-keys.js.map +1 -0
- package/dist/node/space-lines.d.ts +33 -0
- package/dist/node/space-lines.d.ts.map +1 -0
- package/dist/node/space-lines.js +145 -0
- package/dist/node/space-lines.js.map +1 -0
- package/dist/node/space-membership.d.ts +69 -0
- package/dist/node/space-membership.d.ts.map +1 -0
- package/dist/node/space-membership.js +242 -0
- package/dist/node/space-membership.js.map +1 -0
- package/dist/node/space-mirrors.d.ts +43 -0
- package/dist/node/space-mirrors.d.ts.map +1 -0
- package/dist/node/space-mirrors.js +125 -0
- package/dist/node/space-mirrors.js.map +1 -0
- package/dist/node/space-peers.d.ts +104 -0
- package/dist/node/space-peers.d.ts.map +1 -0
- package/dist/node/space-peers.js +595 -0
- package/dist/node/space-peers.js.map +1 -0
- package/dist/node/space-profiles.d.ts +18 -0
- package/dist/node/space-profiles.d.ts.map +1 -0
- package/dist/node/space-profiles.js +105 -0
- package/dist/node/space-profiles.js.map +1 -0
- package/dist/node/space-rules.d.ts +29 -0
- package/dist/node/space-rules.d.ts.map +1 -0
- package/dist/node/space-rules.js +144 -0
- package/dist/node/space-rules.js.map +1 -0
- package/dist/node/space-runtime.d.ts +104 -143
- package/dist/node/space-runtime.d.ts.map +1 -1
- package/dist/node/space-runtime.js +293 -3954
- package/dist/node/space-runtime.js.map +1 -1
- package/dist/node/space-standing.d.ts +20 -0
- package/dist/node/space-standing.d.ts.map +1 -0
- package/dist/node/space-standing.js +317 -0
- package/dist/node/space-standing.js.map +1 -0
- package/dist/node/space-versions.d.ts +104 -0
- package/dist/node/space-versions.d.ts.map +1 -0
- package/dist/node/space-versions.js +153 -0
- package/dist/node/space-versions.js.map +1 -0
- package/dist/node/space-warrants.d.ts +25 -0
- package/dist/node/space-warrants.d.ts.map +1 -0
- package/dist/node/space-warrants.js +214 -0
- package/dist/node/space-warrants.js.map +1 -0
- package/dist/node/space-writing.d.ts +72 -0
- package/dist/node/space-writing.d.ts.map +1 -0
- package/dist/node/space-writing.js +440 -0
- package/dist/node/space-writing.js.map +1 -0
- package/dist/node/stores.d.ts +19 -50
- package/dist/node/stores.d.ts.map +1 -1
- package/dist/node/stores.js +14 -33
- package/dist/node/stores.js.map +1 -1
- package/dist/node/types.d.ts +225 -305
- package/dist/node/types.d.ts.map +1 -1
- package/dist/node/usage.d.ts +2 -24
- package/dist/node/usage.d.ts.map +1 -1
- package/dist/node/usage.js +118 -102
- package/dist/node/usage.js.map +1 -1
- package/dist/node/watch-notifications.d.ts.map +1 -1
- package/dist/node/watch-notifications.js +32 -29
- package/dist/node/watch-notifications.js.map +1 -1
- package/dist/node/worker.d.ts +5 -6
- package/dist/node/worker.d.ts.map +1 -1
- package/dist/node/worker.js +80 -72
- package/dist/node/worker.js.map +1 -1
- package/dist/node/writer-keys.d.ts +5 -6
- package/dist/node/writer-keys.d.ts.map +1 -1
- package/dist/node/writer-keys.js +66 -57
- package/dist/node/writer-keys.js.map +1 -1
- package/dist/node/writers.d.ts +12 -19
- package/dist/node/writers.d.ts.map +1 -1
- package/dist/node/writers.js +7 -15
- package/dist/node/writers.js.map +1 -1
- package/dist/privacy/direct.d.ts.map +1 -1
- package/dist/privacy/direct.js +31 -27
- package/dist/privacy/direct.js.map +1 -1
- package/dist/privacy/space-encryption.d.ts.map +1 -1
- package/dist/privacy/space-encryption.js +5 -9
- package/dist/privacy/space-encryption.js.map +1 -1
- package/dist/query/computed.d.ts.map +1 -1
- package/dist/query/computed.js +78 -77
- package/dist/query/computed.js.map +1 -1
- package/dist/query/engine.d.ts +3 -4
- package/dist/query/engine.d.ts.map +1 -1
- package/dist/query/engine.js +93 -86
- package/dist/query/engine.js.map +1 -1
- package/dist/query/filter.d.ts +8 -10
- package/dist/query/filter.d.ts.map +1 -1
- package/dist/query/filter.js +144 -161
- package/dist/query/filter.js.map +1 -1
- package/dist/records/cel-types.d.ts.map +1 -1
- package/dist/records/cel-types.js +13 -27
- package/dist/records/cel-types.js.map +1 -1
- package/dist/records/cel.d.ts.map +1 -1
- package/dist/records/cel.js +177 -242
- package/dist/records/cel.js.map +1 -1
- package/dist/records/rules.d.ts.map +1 -1
- package/dist/records/rules.js +46 -50
- package/dist/records/rules.js.map +1 -1
- package/dist/records/topics.d.ts.map +1 -1
- package/dist/records/topics.js +18 -22
- package/dist/records/topics.js.map +1 -1
- package/dist/schema/collection-def.d.ts.map +1 -1
- package/dist/schema/collection-def.js +16 -5
- package/dist/schema/collection-def.js.map +1 -1
- package/dist/schemas/automations.d.ts +16 -15
- package/dist/schemas/automations.d.ts.map +1 -1
- package/dist/schemas/automations.js +203 -165
- package/dist/schemas/automations.js.map +1 -1
- package/dist/schemas/blueprints.d.ts.map +1 -1
- package/dist/schemas/blueprints.js +14 -13
- package/dist/schemas/blueprints.js.map +1 -1
- package/dist/schemas/connectors.d.ts +12 -0
- package/dist/schemas/connectors.d.ts.map +1 -1
- package/dist/schemas/connectors.js +16 -11
- package/dist/schemas/connectors.js.map +1 -1
- package/dist/schemas/contacts.d.ts +57 -0
- package/dist/schemas/contacts.d.ts.map +1 -1
- package/dist/schemas/contacts.js +32 -0
- package/dist/schemas/contacts.js.map +1 -1
- package/dist/schemas/cron.d.ts.map +1 -1
- package/dist/schemas/cron.js +27 -28
- package/dist/schemas/cron.js.map +1 -1
- package/dist/schemas/defined.d.ts +6 -0
- package/dist/schemas/defined.d.ts.map +1 -0
- package/dist/schemas/defined.js +7 -0
- package/dist/schemas/defined.js.map +1 -0
- package/dist/schemas/fragments.d.ts +22 -2
- package/dist/schemas/fragments.d.ts.map +1 -1
- package/dist/schemas/fragments.js +20 -12
- package/dist/schemas/fragments.js.map +1 -1
- package/dist/schemas/guides.d.ts +3 -1
- package/dist/schemas/guides.d.ts.map +1 -1
- package/dist/schemas/guides.js +13 -12
- package/dist/schemas/guides.js.map +1 -1
- package/dist/schemas/index.d.ts +2 -2
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +18 -14
- package/dist/schemas/index.js.map +1 -1
- package/dist/schemas/library/annotations.d.ts +30 -0
- package/dist/schemas/library/annotations.d.ts.map +1 -1
- package/dist/schemas/library/annotations.js +1 -0
- package/dist/schemas/library/annotations.js.map +1 -1
- package/dist/schemas/library/community.d.ts +28 -0
- package/dist/schemas/library/community.d.ts.map +1 -1
- package/dist/schemas/library/life.d.ts +62 -2
- package/dist/schemas/library/life.d.ts.map +1 -1
- package/dist/schemas/library/media.d.ts +36 -0
- package/dist/schemas/library/media.d.ts.map +1 -1
- package/dist/schemas/library/money.d.ts +74 -2
- package/dist/schemas/library/money.d.ts.map +1 -1
- package/dist/schemas/library/planning.d.ts +56 -0
- package/dist/schemas/library/planning.d.ts.map +1 -1
- package/dist/schemas/library/publishing.d.ts +80 -4
- package/dist/schemas/library/publishing.d.ts.map +1 -1
- package/dist/schemas/library/social.d.ts +44 -0
- package/dist/schemas/library/social.d.ts.map +1 -1
- package/dist/session/account-hint.d.ts.map +1 -1
- package/dist/session/account-hint.js +8 -5
- package/dist/session/account-hint.js.map +1 -1
- package/dist/session/auth.d.ts +36 -2
- package/dist/session/auth.d.ts.map +1 -1
- package/dist/session/auth.js +95 -2
- package/dist/session/auth.js.map +1 -1
- package/dist/session/connect.d.ts +1 -0
- package/dist/session/connect.d.ts.map +1 -1
- package/dist/session/connect.js +3 -1
- package/dist/session/connect.js.map +1 -1
- package/dist/session/credentials.d.ts +8 -26
- package/dist/session/credentials.d.ts.map +1 -1
- package/dist/session/credentials.js +14 -32
- package/dist/session/credentials.js.map +1 -1
- package/dist/session/index.d.ts +1 -0
- package/dist/session/index.d.ts.map +1 -1
- package/dist/session/index.js +1 -0
- package/dist/session/index.js.map +1 -1
- package/dist/session/pairing.d.ts.map +1 -1
- package/dist/session/pairing.js +92 -88
- package/dist/session/pairing.js.map +1 -1
- package/dist/session/password-strength.d.ts.map +1 -1
- package/dist/session/password-strength.js +37 -37
- package/dist/session/password-strength.js.map +1 -1
- package/dist/session/places.d.ts.map +1 -1
- package/dist/session/places.js +18 -13
- package/dist/session/places.js.map +1 -1
- package/dist/session/popup.d.ts +13 -0
- package/dist/session/popup.d.ts.map +1 -0
- package/dist/session/popup.js +23 -0
- package/dist/session/popup.js.map +1 -0
- package/dist/space/constitution.d.ts.map +1 -1
- package/dist/space/constitution.js +22 -29
- package/dist/space/constitution.js.map +1 -1
- package/dist/space/grants.d.ts.map +1 -1
- package/dist/space/grants.js +37 -39
- package/dist/space/grants.js.map +1 -1
- package/dist/space/invite-link.d.ts.map +1 -1
- package/dist/space/invite-link.js +33 -33
- package/dist/space/invite-link.js.map +1 -1
- package/dist/space/own-automations.d.ts +13 -24
- package/dist/space/own-automations.d.ts.map +1 -1
- package/dist/space/own-automations.js +47 -37
- package/dist/space/own-automations.js.map +1 -1
- package/dist/space/roles.d.ts +56 -80
- package/dist/space/roles.d.ts.map +1 -1
- package/dist/space/roles.js +448 -441
- package/dist/space/roles.js.map +1 -1
- package/dist/space/space-access.d.ts +3 -4
- package/dist/space/space-access.d.ts.map +1 -1
- package/dist/space/space-access.js +3 -8
- package/dist/space/space-access.js.map +1 -1
- package/dist/storage/blob/directory.d.ts.map +1 -1
- package/dist/storage/blob/directory.js +39 -32
- package/dist/storage/blob/directory.js.map +1 -1
- package/dist/storage/blob/s3.d.ts.map +1 -1
- package/dist/storage/blob/s3.js +21 -19
- package/dist/storage/blob/s3.js.map +1 -1
- package/dist/storage/blob-store.d.ts +0 -9
- package/dist/storage/blob-store.d.ts.map +1 -1
- package/dist/storage/directory-access.d.ts +8 -32
- package/dist/storage/directory-access.d.ts.map +1 -1
- package/dist/storage/directory-access.js +11 -36
- package/dist/storage/directory-access.js.map +1 -1
- package/dist/storage/encrypted-adapter.d.ts +12 -32
- package/dist/storage/encrypted-adapter.d.ts.map +1 -1
- package/dist/storage/encrypted-adapter.js +31 -54
- package/dist/storage/encrypted-adapter.js.map +1 -1
- package/dist/storage/folder-adapter.d.ts +12 -26
- package/dist/storage/folder-adapter.d.ts.map +1 -1
- package/dist/storage/folder-adapter.js +37 -54
- package/dist/storage/folder-adapter.js.map +1 -1
- package/dist/storage/folder-reconcile.d.ts +12 -26
- package/dist/storage/folder-reconcile.d.ts.map +1 -1
- package/dist/storage/folder-reconcile.js +39 -48
- package/dist/storage/folder-reconcile.js.map +1 -1
- package/dist/storage/indexeddb-adapter.d.ts +2 -6
- package/dist/storage/indexeddb-adapter.d.ts.map +1 -1
- package/dist/storage/indexeddb-adapter.js +60 -114
- package/dist/storage/indexeddb-adapter.js.map +1 -1
- package/dist/storage/mirror.d.ts +0 -29
- package/dist/storage/mirror.d.ts.map +1 -1
- package/dist/storage/mirror.js +153 -110
- package/dist/storage/mirror.js.map +1 -1
- package/dist/storage/segment.d.ts.map +1 -1
- package/dist/storage/segment.js +3 -7
- package/dist/storage/segment.js.map +1 -1
- package/dist/storage/storage-provider.d.ts +6 -11
- package/dist/storage/storage-provider.d.ts.map +1 -1
- package/dist/storage/storage-provider.js +112 -116
- package/dist/storage/storage-provider.js.map +1 -1
- package/dist/sync/sync-engine.d.ts +10 -44
- package/dist/sync/sync-engine.d.ts.map +1 -1
- package/dist/sync/sync-engine.js +245 -247
- package/dist/sync/sync-engine.js.map +1 -1
- package/dist/sync/sync-messages.d.ts +1 -1
- 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/utils/guards.d.ts +1 -0
- package/dist/utils/guards.d.ts.map +1 -1
- package/dist/utils/guards.js +1 -0
- package/dist/utils/guards.js.map +1 -1
- package/dist/utils/hmac.d.ts +5 -0
- package/dist/utils/hmac.d.ts.map +1 -0
- package/dist/utils/hmac.js +20 -0
- package/dist/utils/hmac.js.map +1 -0
- package/dist/utils/map.d.ts +10 -0
- package/dist/utils/map.d.ts.map +1 -0
- package/dist/utils/map.js +30 -0
- package/dist/utils/map.js.map +1 -0
- package/dist/utils/serial.d.ts +2 -0
- package/dist/utils/serial.d.ts.map +1 -1
- package/dist/utils/serial.js +9 -0
- package/dist/utils/serial.js.map +1 -1
- package/dist/validation/capability-gate.d.ts +7 -15
- package/dist/validation/capability-gate.d.ts.map +1 -1
- package/dist/validation/capability-gate.js +32 -36
- package/dist/validation/capability-gate.js.map +1 -1
- package/dist/validation/crypto-gate.d.ts.map +1 -1
- package/dist/validation/crypto-gate.js +12 -21
- package/dist/validation/crypto-gate.js.map +1 -1
- package/docs/README.md +3 -2
- package/docs/actions.md +47 -20
- package/docs/automations.md +1 -1
- package/docs/blueprints-and-guides.md +57 -13
- package/docs/building-an-app.md +11 -8
- package/docs/collections.md +33 -5
- package/docs/contacts.md +34 -1
- package/docs/contracts.md +1 -1
- package/docs/direct-messages.md +1 -1
- package/docs/inbox.md +5 -11
- package/docs/node.md +36 -26
- package/docs/records-and-queries.md +1 -1
- package/docs/sign-in.md +54 -26
- package/docs/spaces.md +6 -6
- package/docs/standard-library.md +33 -31
- package/docs/storage.md +37 -15
- package/docs/usernames.md +161 -0
- package/docs/warrants.md +1 -1
- package/package.json +2 -21
- package/dist/calls/calls.d.ts +0 -140
- package/dist/calls/calls.d.ts.map +0 -1
- package/dist/calls/calls.js +0 -861
- package/dist/calls/calls.js.map +0 -1
- package/dist/calls/index.d.ts +0 -4
- package/dist/calls/index.d.ts.map +0 -1
- package/dist/calls/index.js +0 -3
- package/dist/calls/index.js.map +0 -1
- package/dist/react/context.d.ts +0 -81
- package/dist/react/context.d.ts.map +0 -1
- package/dist/react/context.js +0 -97
- package/dist/react/context.js.map +0 -1
- package/dist/react/follow.d.ts +0 -11
- package/dist/react/follow.d.ts.map +0 -1
- package/dist/react/follow.js +0 -7
- package/dist/react/follow.js.map +0 -1
- package/dist/react/index.d.ts +0 -44
- package/dist/react/index.d.ts.map +0 -1
- package/dist/react/index.js +0 -40
- package/dist/react/index.js.map +0 -1
- package/dist/react/minca-auth.d.ts +0 -19
- package/dist/react/minca-auth.d.ts.map +0 -1
- package/dist/react/minca-auth.js +0 -36
- package/dist/react/minca-auth.js.map +0 -1
- package/dist/react/use-calls.d.ts +0 -21
- package/dist/react/use-calls.d.ts.map +0 -1
- package/dist/react/use-calls.js +0 -39
- package/dist/react/use-calls.js.map +0 -1
- package/dist/react/use-invite-link.d.ts +0 -24
- package/dist/react/use-invite-link.d.ts.map +0 -1
- package/dist/react/use-invite-link.js +0 -62
- package/dist/react/use-invite-link.js.map +0 -1
- package/dist/react/use-live.d.ts +0 -16
- package/dist/react/use-live.d.ts.map +0 -1
- package/dist/react/use-live.js +0 -56
- package/dist/react/use-live.js.map +0 -1
- package/dist/react/use-my-name.d.ts +0 -12
- package/dist/react/use-my-name.d.ts.map +0 -1
- package/dist/react/use-my-name.js +0 -38
- package/dist/react/use-my-name.js.map +0 -1
- package/dist/react/use-names.d.ts +0 -7
- package/dist/react/use-names.d.ts.map +0 -1
- package/dist/react/use-names.js +0 -13
- package/dist/react/use-names.js.map +0 -1
- package/dist/react/use-network.d.ts +0 -9
- package/dist/react/use-network.d.ts.map +0 -1
- package/dist/react/use-network.js +0 -33
- package/dist/react/use-network.js.map +0 -1
- package/dist/react/use-query.d.ts +0 -14
- package/dist/react/use-query.d.ts.map +0 -1
- package/dist/react/use-query.js +0 -26
- package/dist/react/use-query.js.map +0 -1
- package/dist/react/use-space.d.ts +0 -29
- package/dist/react/use-space.d.ts.map +0 -1
- package/dist/react/use-space.js +0 -57
- package/dist/react/use-space.js.map +0 -1
- package/dist/react/use-spaces.d.ts +0 -29
- package/dist/react/use-spaces.d.ts.map +0 -1
- package/dist/react/use-spaces.js +0 -78
- package/dist/react/use-spaces.js.map +0 -1
- package/docs/calls.md +0 -189
package/dist/sync/sync-engine.js
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keeps one store in step with its peers.
|
|
3
|
+
*
|
|
4
|
+
* 1. A peer says hello with a fingerprint of each collection it keeps. Equal
|
|
5
|
+
* fingerprints mean the same versions.
|
|
6
|
+
* 2. For each collection that differs, the initiator reconciles it with the
|
|
7
|
+
* other (`negentropy.ts`), and ends up knowing which versions each side lacks.
|
|
8
|
+
* 3. The initiator asks for what it lacks, and sends what the other lacks.
|
|
9
|
+
* Everything that arrives passes the gatekeeper before it is stored.
|
|
10
|
+
*
|
|
11
|
+
* Cost follows the difference, not the size. The initiator is the peer whose
|
|
12
|
+
* id sorts first; the other answers a hello with its own, which starts it.
|
|
13
|
+
*
|
|
14
|
+
* A node may hold every collection, or only some (plus `sys.*`, which every
|
|
15
|
+
* node holds), and says which in its hello. Two peers reconcile only what both
|
|
16
|
+
* hold. Whatever a node takes in from a peer, it tells that peer (`stored`), so
|
|
17
|
+
* a node holding part of a space can let go of its own writes.
|
|
18
|
+
*/
|
|
19
|
+
import { getOrAdd } from '../utils/map.js';
|
|
1
20
|
import { cidDigest, cidOfDigest } from '../utils/hash.js';
|
|
2
21
|
import { base64UrlDecode, base64UrlEncode, bytesToHex } from '../utils/encoding.js';
|
|
3
22
|
import { createEmitter } from '../utils/events.js';
|
|
@@ -7,32 +26,39 @@ import { parseSyncMessage, SYNC_PROTOCOL_VERSION, } from './sync-messages.js';
|
|
|
7
26
|
const MAX_WAITING = 1000;
|
|
8
27
|
/** Refusals remembered, so reconciling doesn't ask a peer for the same bad version every round */
|
|
9
28
|
const MAX_REFUSED = 10_000;
|
|
10
|
-
/**
|
|
11
|
-
const holdsCollection = (holds, collection) => collection.startsWith('sys.') || holds === 'all' || holds.has(collection);
|
|
12
|
-
/** Collection definitions first, then records by version — what others depend on comes first */
|
|
13
|
-
const rank = (e) => (e?.collection === 'sys.collection' ? -1 : (e?.seq ?? 0));
|
|
14
|
-
/** Records asked for, or sent, in one message. */
|
|
29
|
+
/** Records asked for, or sent, in one message */
|
|
15
30
|
const MAX_IDS_PER_REQUEST = 200;
|
|
16
31
|
/** `want`s in flight to one peer at a time; the rest queue */
|
|
17
32
|
const MAX_WANTS_IN_FLIGHT = 4;
|
|
18
|
-
/** Largest Negentropy message, in bytes before base64
|
|
33
|
+
/** Largest Negentropy message, in bytes before base64: well inside a data channel's limit */
|
|
19
34
|
const FRAME_SIZE_LIMIT = 32_000;
|
|
35
|
+
/** Collections one hello may name. Past this it is hostile, not big. */
|
|
36
|
+
const MAX_COLLECTIONS = 1000;
|
|
37
|
+
/** Rounds one reconciliation may take before it is given up as runaway */
|
|
38
|
+
const MAX_ROUNDS = 64;
|
|
39
|
+
/** A session or want that has heard nothing for this long is given up on */
|
|
40
|
+
const STALE_MS = 30_000;
|
|
41
|
+
/** Whether a collection is held, given what a node holds */
|
|
42
|
+
const holdsCollection = (holds, collection) => collection.startsWith('sys.') || holds === 'all' || holds.has(collection);
|
|
43
|
+
/** What a hello says the peer holds; anything malformed counts as holding nothing past `sys.*` */
|
|
44
|
+
function readHolds(value) {
|
|
45
|
+
if (value === undefined || value === 'all')
|
|
46
|
+
return 'all';
|
|
47
|
+
if (!Array.isArray(value) || value.length > MAX_COLLECTIONS)
|
|
48
|
+
return new Set();
|
|
49
|
+
return new Set(value.filter((c) => typeof c === 'string'));
|
|
50
|
+
}
|
|
51
|
+
/** Collection definitions first, then records by version: what others depend on comes first */
|
|
52
|
+
const rank = (e) => (e?.collection === 'sys.collection' ? -1 : (e?.seq ?? 0));
|
|
20
53
|
/**
|
|
21
|
-
* Versions in messages of at most `size`,
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* versions that changed or deleted it, and is never shown as it once was —
|
|
25
|
-
* nor waits for the rest while the peer sends everything else.
|
|
54
|
+
* Versions in messages of at most `size`, with every version of one record in
|
|
55
|
+
* the same message where they fit. A message is taken in whole, so a record
|
|
56
|
+
* arrives with the versions that changed or deleted it, never as it once was.
|
|
26
57
|
*/
|
|
27
58
|
function byRecord(versions, size) {
|
|
28
59
|
const records = new Map();
|
|
29
|
-
for (const version of versions)
|
|
30
|
-
|
|
31
|
-
if (record)
|
|
32
|
-
record.push(version);
|
|
33
|
-
else
|
|
34
|
-
records.set(version.key, [version]);
|
|
35
|
-
}
|
|
60
|
+
for (const version of versions)
|
|
61
|
+
getOrAdd(records, version.key, () => []).push(version);
|
|
36
62
|
const messages = [];
|
|
37
63
|
let message = [];
|
|
38
64
|
for (const record of records.values()) {
|
|
@@ -40,7 +66,7 @@ function byRecord(versions, size) {
|
|
|
40
66
|
messages.push(message);
|
|
41
67
|
message = [];
|
|
42
68
|
}
|
|
43
|
-
// A record with more versions than fit in one message goes over several
|
|
69
|
+
// A record with more versions than fit in one message goes over several.
|
|
44
70
|
for (let i = 0; i < record.length; i += size) {
|
|
45
71
|
const part = record.slice(i, i + size);
|
|
46
72
|
if (message.length + part.length > size) {
|
|
@@ -54,73 +80,45 @@ function byRecord(versions, size) {
|
|
|
54
80
|
messages.push(message);
|
|
55
81
|
return messages;
|
|
56
82
|
}
|
|
57
|
-
/** Collections one hello may name. Past this it is hostile, not big. */
|
|
58
|
-
const MAX_COLLECTIONS = 1000;
|
|
59
|
-
/** Rounds one reconciliation may take before it is given up as runaway. */
|
|
60
|
-
const MAX_ROUNDS = 64;
|
|
61
|
-
/** A session that has heard nothing for this long is given up on. */
|
|
62
|
-
const STALE_MS = 30_000;
|
|
63
83
|
/** Creates a sync engine orchestrator. */
|
|
64
84
|
export function createSyncEngine(config) {
|
|
65
85
|
const { storageProvider: storage, sendToPeer, heartbeatInterval = 30000, validate, self } = config;
|
|
66
86
|
const ourHolds = config.holds ?? (() => 'all');
|
|
87
|
+
const { on, off, emit } = createEmitter();
|
|
88
|
+
const report = (err) => emit('error', err);
|
|
67
89
|
/** Peers to say hello to and push to */
|
|
68
90
|
const peers = new Set();
|
|
69
|
-
/** What's in flight with each peer */
|
|
70
91
|
const states = new Map();
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const stamp = (msg) => ({ v: SYNC_PROTOCOL_VERSION, ...msg });
|
|
75
|
-
const send = (peerId, msg) => sendToPeer(peerId, stamp(msg));
|
|
76
|
-
const stateOf = (peerId) => states.get(peerId) ??
|
|
77
|
-
states
|
|
78
|
-
.set(peerId, { sessions: new Map(), wants: new Map(), queued: [], queuedIds: new Set(), holds: 'all' })
|
|
79
|
-
.get(peerId);
|
|
80
|
-
// ─── Taking in versions ────────────────────────────────────────────
|
|
81
|
-
/** Records that could not be judged yet — tried again whenever something new is admitted */
|
|
92
|
+
/** Peers found level with this node, until it takes in or writes anything more */
|
|
93
|
+
const level = new Set();
|
|
94
|
+
/** Records that could not be judged yet, tried again whenever something new is admitted */
|
|
82
95
|
const waiting = new Map();
|
|
83
96
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
* mangled copy shares the real record's id — refusing it must not stop us
|
|
87
|
-
* fetching the real one from someone else.
|
|
97
|
+
* Refused versions, by peer and id, oldest first. An id doesn't cover the
|
|
98
|
+
* signature, so a stranger's mangled copy must not stop us fetching the real one.
|
|
88
99
|
*/
|
|
89
100
|
const refused = new Set();
|
|
90
|
-
/**
|
|
91
|
-
* Which connection to each peer is open now, numbered across all of them:
|
|
92
|
-
* what a message arrived on, so one from a connection since closed is not
|
|
93
|
-
* taken for the new one's.
|
|
94
|
-
*/
|
|
101
|
+
/** Which connection to each peer is open now, so a message from a closed one is dropped */
|
|
95
102
|
const connections = new Map();
|
|
103
|
+
/** Where each peer's messages are up to */
|
|
104
|
+
const inOrder = new Map();
|
|
96
105
|
let lastConnection = 0;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
106
|
+
let intervalId = null;
|
|
107
|
+
let nextId = 1;
|
|
108
|
+
const send = (peerId, msg) => sendToPeer(peerId, { v: SYNC_PROTOCOL_VERSION, ...msg });
|
|
109
|
+
const stateOf = (peerId) => getOrAdd(states, peerId, newPeerState);
|
|
110
|
+
const peerHolds = (peerId, collection) => holdsCollection(states.get(peerId)?.holds ?? 'all', collection);
|
|
111
|
+
const isRefused = (peerId, id) => refused.has(refusal(peerId, id));
|
|
112
|
+
// ─── Taking in versions ────────────────────────────────────────────
|
|
113
|
+
/** Stores a version from a peer if the gatekeeper allows it; one that must wait names what it waits for */
|
|
103
114
|
const admit = async (peerId, version, intake) => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
for (const needed of version.seq > 0 ? [version.genesis, version.prev] : []) {
|
|
112
|
-
if (typeof needed === 'string' && !(await storage.getVersion(needed)))
|
|
113
|
-
intake.firsts.set(needed, version.collection);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
refused.add(refusal(peerId, version.id));
|
|
118
|
-
if (refused.size > MAX_REFUSED)
|
|
119
|
-
refused.delete(refused.values().next().value);
|
|
120
|
-
emit('rejected', peerId, version, verdict.reason);
|
|
121
|
-
}
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
115
|
+
const verdict = validate ? await validate(version) : { valid: true };
|
|
116
|
+
if (!verdict.valid) {
|
|
117
|
+
if (verdict.later)
|
|
118
|
+
await holdBack(peerId, version, intake);
|
|
119
|
+
else
|
|
120
|
+
refuse(peerId, version, verdict.reason);
|
|
121
|
+
return false;
|
|
124
122
|
}
|
|
125
123
|
waiting.delete(version.id);
|
|
126
124
|
await storage.addVersion(version);
|
|
@@ -128,6 +126,21 @@ export function createSyncEngine(config) {
|
|
|
128
126
|
emit('version-received', version);
|
|
129
127
|
return true;
|
|
130
128
|
};
|
|
129
|
+
const holdBack = async (peerId, version, intake) => {
|
|
130
|
+
waiting.set(version.id, { peerId, version });
|
|
131
|
+
dropOldest(waiting, MAX_WAITING);
|
|
132
|
+
const dependsOn = version.seq > 0 ? [version.genesis, version.prev] : [];
|
|
133
|
+
for (const needed of dependsOn) {
|
|
134
|
+
if (typeof needed === 'string' && !(await storage.getVersion(needed)))
|
|
135
|
+
intake.firsts.set(needed, version.collection);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const refuse = (peerId, version, reason) => {
|
|
139
|
+
refused.add(refusal(peerId, version.id));
|
|
140
|
+
dropOldest(refused, MAX_REFUSED);
|
|
141
|
+
emit('rejected', peerId, version, reason);
|
|
142
|
+
};
|
|
143
|
+
/** Tries every waiting version again until nothing more goes in; each sender hears what was stored */
|
|
131
144
|
const retryWaiting = async (intake) => {
|
|
132
145
|
const stored = new Map();
|
|
133
146
|
let progressed = true;
|
|
@@ -138,20 +151,16 @@ export function createSyncEngine(config) {
|
|
|
138
151
|
if (!(await admit(held.peerId, held.version, intake)))
|
|
139
152
|
continue;
|
|
140
153
|
progressed = true;
|
|
141
|
-
(stored
|
|
154
|
+
getOrAdd(stored, held.peerId, () => []).push(id);
|
|
142
155
|
}
|
|
143
156
|
}
|
|
144
|
-
// Stored at last: the peer that sent it hears so, as it would have had it gone in at once.
|
|
145
157
|
for (const [peerId, ids] of stored)
|
|
146
158
|
if (peers.has(peerId))
|
|
147
159
|
send(peerId, { type: 'stored', ids });
|
|
148
160
|
};
|
|
149
161
|
/**
|
|
150
|
-
* Queues
|
|
151
|
-
*
|
|
152
|
-
* may do what decides whether the rest counts. A few wants are in flight at
|
|
153
|
-
* a time: what arrives can then pull what it waits for ahead of the rest,
|
|
154
|
-
* and fewer versions wait at once.
|
|
162
|
+
* Queues ids to ask a peer for, behind the rest or ahead of them (`ahead`,
|
|
163
|
+
* and always for `sys.*`: who may do what decides whether the rest counts).
|
|
155
164
|
*/
|
|
156
165
|
const want = (peerId, collection, ids, ahead = false) => {
|
|
157
166
|
const first = ahead || collection.startsWith('sys.');
|
|
@@ -165,41 +174,21 @@ export function createSyncEngine(config) {
|
|
|
165
174
|
state.queued.push(...entries);
|
|
166
175
|
pump(peerId);
|
|
167
176
|
};
|
|
168
|
-
/** Sends wants from the front of the queue while there is room in flight
|
|
177
|
+
/** Sends wants from the front of the queue while there is room in flight */
|
|
169
178
|
const pump = (peerId) => {
|
|
170
179
|
const state = states.get(peerId);
|
|
171
180
|
if (!state)
|
|
172
181
|
return;
|
|
173
182
|
while (state.wants.size < MAX_WANTS_IN_FLIGHT && state.queuedIds.size > 0) {
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
while (state.queued.length > 0 && ids.length < MAX_IDS_PER_REQUEST) {
|
|
177
|
-
const next = state.queued[0];
|
|
178
|
-
if (!state.queuedIds.has(next.id)) {
|
|
179
|
-
state.queued.shift();
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
if (collection !== null && next.collection !== collection)
|
|
183
|
-
break;
|
|
184
|
-
collection = next.collection;
|
|
185
|
-
state.queued.shift();
|
|
186
|
-
state.queuedIds.delete(next.id);
|
|
187
|
-
ids.push(next.id);
|
|
188
|
-
}
|
|
189
|
-
if (collection === null)
|
|
183
|
+
const batch = takeBatch(state);
|
|
184
|
+
if (!batch)
|
|
190
185
|
break;
|
|
191
|
-
const
|
|
192
|
-
state.wants.set(
|
|
193
|
-
send(peerId, { type: 'want', id
|
|
186
|
+
const id = nextId++;
|
|
187
|
+
state.wants.set(id, { ids: new Set(batch.ids), collection: batch.collection, at: Date.now() });
|
|
188
|
+
send(peerId, { type: 'want', id, ids: batch.ids });
|
|
194
189
|
}
|
|
195
190
|
};
|
|
196
|
-
/**
|
|
197
|
-
const asked = (peerId) => new Set([...(states.get(peerId)?.wants.values() ?? [])].flatMap((w) => [...w.ids]));
|
|
198
|
-
/**
|
|
199
|
-
* Admits a batch: definitions and first versions before what depends on
|
|
200
|
-
* them, so little has to wait. Versions of collections this node doesn't
|
|
201
|
-
* hold are passed over. The peer is told which it now has.
|
|
202
|
-
*/
|
|
191
|
+
/** Admits a batch, what others depend on first, passing over collections not held here */
|
|
203
192
|
const admitAll = async (peerId, versions) => {
|
|
204
193
|
const holds = ourHolds();
|
|
205
194
|
const stored = [];
|
|
@@ -216,23 +205,27 @@ export function createSyncEngine(config) {
|
|
|
216
205
|
send(peerId, { type: 'stored', ids: stored });
|
|
217
206
|
await retryWaiting(intake);
|
|
218
207
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
const inFlight = asked(peerId);
|
|
222
|
-
const byCollection = new Map();
|
|
223
|
-
for (const [id, collection] of intake.firsts) {
|
|
224
|
-
if (inFlight.has(id) || refused.has(refusal(peerId, id)) || (await storage.getVersion(id)))
|
|
225
|
-
continue;
|
|
226
|
-
(byCollection.get(collection) ?? byCollection.set(collection, []).get(collection)).push(id);
|
|
227
|
-
}
|
|
228
|
-
for (const [collection, ids] of byCollection)
|
|
229
|
-
want(peerId, collection, ids, true);
|
|
230
|
-
}
|
|
208
|
+
if (intake.firsts.size > 0 && peers.has(peerId))
|
|
209
|
+
await askFirsts(peerId, intake.firsts);
|
|
231
210
|
if (intake.placed.length > 0) {
|
|
232
211
|
level.clear();
|
|
233
212
|
emit('received', intake.placed);
|
|
234
213
|
}
|
|
235
214
|
};
|
|
215
|
+
/** Asks at once for the versions still waited on, unless asked, refused or already here */
|
|
216
|
+
const askFirsts = async (peerId, firsts) => {
|
|
217
|
+
const inFlight = askedOf(peerId);
|
|
218
|
+
const byCollection = new Map();
|
|
219
|
+
for (const [id, collection] of firsts) {
|
|
220
|
+
if (inFlight.has(id) || isRefused(peerId, id) || (await storage.getVersion(id)))
|
|
221
|
+
continue;
|
|
222
|
+
getOrAdd(byCollection, collection, () => []).push(id);
|
|
223
|
+
}
|
|
224
|
+
for (const [collection, ids] of byCollection)
|
|
225
|
+
want(peerId, collection, ids, true);
|
|
226
|
+
};
|
|
227
|
+
/** Ids asked of a peer and not yet answered */
|
|
228
|
+
const askedOf = (peerId) => new Set([...(states.get(peerId)?.wants.values() ?? [])].flatMap((w) => [...w.ids]));
|
|
236
229
|
// ─── Hello ─────────────────────────────────────────────────────────
|
|
237
230
|
/** A fingerprint of each collection held and kept, hex */
|
|
238
231
|
const ourSums = async (holds) => {
|
|
@@ -252,14 +245,7 @@ export function createSyncEngine(config) {
|
|
|
252
245
|
...(reply ? { reply } : {}),
|
|
253
246
|
});
|
|
254
247
|
};
|
|
255
|
-
|
|
256
|
-
const readHolds = (value) => {
|
|
257
|
-
if (value === undefined || value === 'all')
|
|
258
|
-
return 'all';
|
|
259
|
-
if (!Array.isArray(value) || value.length > MAX_COLLECTIONS)
|
|
260
|
-
return new Set();
|
|
261
|
-
return new Set(value.filter((c) => typeof c === 'string'));
|
|
262
|
-
};
|
|
248
|
+
const sayHello = (peerId, reply = false) => void hello(peerId, reply).catch(report);
|
|
263
249
|
const onHello = async (peerId, theirs, theirHolds, reply) => {
|
|
264
250
|
if (typeof theirs !== 'object' || theirs === null)
|
|
265
251
|
return;
|
|
@@ -270,20 +256,17 @@ export function createSyncEngine(config) {
|
|
|
270
256
|
state.holds = readHolds(theirHolds);
|
|
271
257
|
const holds = ourHolds();
|
|
272
258
|
const ours = await ourSums(holds);
|
|
273
|
-
//
|
|
259
|
+
// Every collection this node holds counts, even one it has nothing of yet.
|
|
274
260
|
const named = new Set([...names, ...Object.keys(ours), ...(holds === 'all' ? [] : holds)]);
|
|
275
261
|
const shared = [...named].filter((c) => holdsCollection(holds, c) && holdsCollection(state.holds, c));
|
|
276
262
|
const differing = shared.filter((c) => theirs[c] !== ours[c]);
|
|
277
263
|
for (const c of shared)
|
|
278
264
|
if (theirs[c] === ours[c])
|
|
279
265
|
emit('level', peerId, c, state.holds === 'all');
|
|
280
|
-
if (differing.length === 0)
|
|
281
|
-
|
|
282
|
-
synced(peerId);
|
|
283
|
-
return;
|
|
284
|
-
}
|
|
266
|
+
if (differing.length === 0)
|
|
267
|
+
return settleIfDone(peerId);
|
|
285
268
|
if (self !== undefined && self > peerId) {
|
|
286
|
-
// The other side starts. It may not have heard from us yet
|
|
269
|
+
// The other side starts. It may not have heard from us yet.
|
|
287
270
|
if (!reply)
|
|
288
271
|
await hello(peerId, true);
|
|
289
272
|
return;
|
|
@@ -297,15 +280,17 @@ export function createSyncEngine(config) {
|
|
|
297
280
|
return !!state && (state.sessions.size > 0 || state.wants.size > 0 || state.queuedIds.size > 0);
|
|
298
281
|
};
|
|
299
282
|
const settleIfDone = (peerId) => {
|
|
300
|
-
if (
|
|
301
|
-
|
|
302
|
-
};
|
|
303
|
-
/** Peers found level with this node, until it takes in or writes anything more */
|
|
304
|
-
const level = new Set();
|
|
305
|
-
const synced = (peerId) => {
|
|
283
|
+
if (busy(peerId))
|
|
284
|
+
return;
|
|
306
285
|
level.add(peerId);
|
|
307
286
|
emit('synced', peerId, states.get(peerId)?.holds === 'all');
|
|
308
287
|
};
|
|
288
|
+
const sendRound = (peerId, session, message) => send(peerId, {
|
|
289
|
+
type: 'reconcile',
|
|
290
|
+
id: session.id,
|
|
291
|
+
collection: session.collection,
|
|
292
|
+
message: base64UrlEncode(message),
|
|
293
|
+
});
|
|
309
294
|
const begin = async (peerId, collection) => {
|
|
310
295
|
if (typeof collection !== 'string')
|
|
311
296
|
return;
|
|
@@ -331,30 +316,38 @@ export function createSyncEngine(config) {
|
|
|
331
316
|
need: [],
|
|
332
317
|
};
|
|
333
318
|
state.sessions.set(collection, session);
|
|
334
|
-
|
|
335
|
-
type: 'reconcile',
|
|
336
|
-
id: session.id,
|
|
337
|
-
collection,
|
|
338
|
-
message: base64UrlEncode(await reconciler.initiate()),
|
|
339
|
-
});
|
|
319
|
+
sendRound(peerId, session, await reconciler.initiate());
|
|
340
320
|
};
|
|
341
321
|
/**
|
|
342
|
-
*
|
|
343
|
-
* peer,
|
|
344
|
-
* knows it is level too — marked a reply, so it never starts another round.
|
|
322
|
+
* When a collection's session and its wants are over, this node is level
|
|
323
|
+
* with the peer, and tells it so in a reply hello that starts no new round.
|
|
345
324
|
*/
|
|
346
325
|
const levelIfDone = (peerId, collection) => {
|
|
347
326
|
const state = states.get(peerId);
|
|
348
327
|
if (!state || state.sessions.has(collection))
|
|
349
328
|
return;
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
if (queued.collection === collection && state.queuedIds.has(queued.id))
|
|
355
|
-
return;
|
|
329
|
+
const wanting = [...state.wants.values()].some((w) => w.collection === collection);
|
|
330
|
+
const queued = state.queued.some((q) => q.collection === collection && state.queuedIds.has(q.id));
|
|
331
|
+
if (wanting || queued)
|
|
332
|
+
return;
|
|
356
333
|
emit('level', peerId, collection, state.holds === 'all');
|
|
357
|
-
|
|
334
|
+
sayHello(peerId, true);
|
|
335
|
+
};
|
|
336
|
+
/**
|
|
337
|
+
* Ends a session: asks for what we lack and sends what they lack, newest
|
|
338
|
+
* first. Only now, since rounds find versions oldest first, and sending as
|
|
339
|
+
* they go would show a record as it once was.
|
|
340
|
+
*/
|
|
341
|
+
const endSession = async (peerId, state, session) => {
|
|
342
|
+
// Asked for before the session goes, so the peer never looks idle in between.
|
|
343
|
+
want(peerId, session.collection, session.need.reverse());
|
|
344
|
+
state.sessions.delete(session.collection);
|
|
345
|
+
const found = await Promise.all(session.have.reverse().map((id) => storage.getVersion(id)));
|
|
346
|
+
const have = found.filter((v) => v !== null);
|
|
347
|
+
for (const versions of byRecord(have, MAX_IDS_PER_REQUEST))
|
|
348
|
+
send(peerId, { type: 'versions', versions });
|
|
349
|
+
if (session.again)
|
|
350
|
+
void begin(peerId, session.collection).catch(report);
|
|
358
351
|
};
|
|
359
352
|
const onReconciled = async (peerId, id, message, held) => {
|
|
360
353
|
const state = states.get(peerId);
|
|
@@ -362,23 +355,9 @@ export function createSyncEngine(config) {
|
|
|
362
355
|
if (!state || !session)
|
|
363
356
|
return; // not ours, or already over
|
|
364
357
|
session.touchedAt = Date.now();
|
|
365
|
-
// What they lack goes, and what we lack is asked for, once the session
|
|
366
|
-
// has found it all — newest first. Rounds find items oldest first, so
|
|
367
|
-
// sending as they go would show a record as it once was (its first
|
|
368
|
-
// version) until the version that deleted or changed it came along.
|
|
369
|
-
const end = async () => {
|
|
370
|
-
// Asked for before the session goes, so the peer never looks idle in between.
|
|
371
|
-
want(peerId, session.collection, session.need.reverse());
|
|
372
|
-
state.sessions.delete(session.collection);
|
|
373
|
-
const have = (await Promise.all(session.have.reverse().map((v) => storage.getVersion(v)))).filter((v) => v !== null);
|
|
374
|
-
for (const versions of byRecord(have, MAX_IDS_PER_REQUEST))
|
|
375
|
-
send(peerId, { type: 'versions', versions });
|
|
376
|
-
if (session.again)
|
|
377
|
-
void begin(peerId, session.collection).catch((err) => emit('error', err));
|
|
378
|
-
};
|
|
379
358
|
if (!held) {
|
|
380
|
-
// They
|
|
381
|
-
await
|
|
359
|
+
// They changed what they hold since their hello.
|
|
360
|
+
await endSession(peerId, state, session);
|
|
382
361
|
return settleIfDone(peerId);
|
|
383
362
|
}
|
|
384
363
|
let round;
|
|
@@ -386,25 +365,23 @@ export function createSyncEngine(config) {
|
|
|
386
365
|
round = await session.reconciler.reconcile(base64UrlDecode(message));
|
|
387
366
|
}
|
|
388
367
|
catch (err) {
|
|
389
|
-
await
|
|
390
|
-
emit('error',
|
|
368
|
+
await endSession(peerId, state, session);
|
|
369
|
+
emit('error', abandoned(peerId, err instanceof Error ? err.message : String(err)));
|
|
391
370
|
return settleIfDone(peerId);
|
|
392
371
|
}
|
|
393
|
-
const
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
return;
|
|
404
|
-
}
|
|
372
|
+
const isNew = (versionId) => {
|
|
373
|
+
if (session.handled.has(versionId))
|
|
374
|
+
return false;
|
|
375
|
+
session.handled.add(versionId);
|
|
376
|
+
return true;
|
|
377
|
+
};
|
|
378
|
+
session.have.push(...round.have.map(cidOfDigest).filter(isNew));
|
|
379
|
+
session.need.push(...round.need.map(cidOfDigest).filter((v) => isNew(v) && !isRefused(peerId, v)));
|
|
380
|
+
if (round.message && ++session.rounds < MAX_ROUNDS)
|
|
381
|
+
return sendRound(peerId, session, round.message);
|
|
405
382
|
if (round.message)
|
|
406
|
-
emit('error',
|
|
407
|
-
await
|
|
383
|
+
emit('error', abandoned(peerId, `more than ${MAX_ROUNDS} rounds`));
|
|
384
|
+
await endSession(peerId, state, session);
|
|
408
385
|
levelIfDone(peerId, session.collection);
|
|
409
386
|
settleIfDone(peerId);
|
|
410
387
|
};
|
|
@@ -434,91 +411,82 @@ export function createSyncEngine(config) {
|
|
|
434
411
|
send(peerId, { type: 'versions', id, versions });
|
|
435
412
|
};
|
|
436
413
|
const onVersions = async (peerId, id, versions) => {
|
|
414
|
+
// Sent unasked, because we lacked them: each still passes the gatekeeper.
|
|
415
|
+
if (id === undefined)
|
|
416
|
+
return admitAll(peerId, versions.slice(0, MAX_IDS_PER_REQUEST));
|
|
437
417
|
const state = states.get(peerId);
|
|
438
|
-
if (id === undefined) {
|
|
439
|
-
// Sent because we lacked them. Nothing is taken on trust: each passes the gatekeeper.
|
|
440
|
-
await admitAll(peerId, versions.slice(0, MAX_IDS_PER_REQUEST));
|
|
441
|
-
return;
|
|
442
|
-
}
|
|
443
418
|
const asked = state?.wants.get(id);
|
|
444
419
|
if (!state || !asked)
|
|
445
420
|
return;
|
|
446
|
-
// Only versions asked for are considered.
|
|
447
421
|
await admitAll(peerId, versions.filter((v) => asked.ids.has(v?.id)));
|
|
448
422
|
state.wants.delete(id);
|
|
449
423
|
pump(peerId);
|
|
450
424
|
levelIfDone(peerId, asked.collection);
|
|
451
425
|
settleIfDone(peerId);
|
|
452
426
|
};
|
|
427
|
+
const onStored = (peerId, ids) => {
|
|
428
|
+
if (!Array.isArray(ids))
|
|
429
|
+
return;
|
|
430
|
+
const named = ids.filter((v) => typeof v === 'string');
|
|
431
|
+
emit('stored', peerId, named.slice(0, 10 * MAX_IDS_PER_REQUEST));
|
|
432
|
+
};
|
|
453
433
|
// ─── Housekeeping ──────────────────────────────────────────────────
|
|
454
|
-
/** Drops sessions and
|
|
434
|
+
/** Drops sessions and wants a peer stopped answering, so a lost message can't wedge sync */
|
|
455
435
|
const sweep = () => {
|
|
456
436
|
const now = Date.now();
|
|
437
|
+
const stale = (at) => now - at > STALE_MS;
|
|
457
438
|
for (const [peerId, state] of states) {
|
|
458
439
|
for (const [collection, session] of state.sessions)
|
|
459
|
-
if (
|
|
440
|
+
if (stale(session.touchedAt))
|
|
460
441
|
state.sessions.delete(collection);
|
|
461
|
-
//
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
if (now - want.at <= STALE_MS)
|
|
465
|
-
continue;
|
|
466
|
-
state.wants.delete(id);
|
|
467
|
-
dropped = true;
|
|
468
|
-
}
|
|
469
|
-
if (!dropped)
|
|
442
|
+
// What a lost want asked for is found again on the next round.
|
|
443
|
+
const lost = [...state.wants].filter(([, want]) => stale(want.at));
|
|
444
|
+
if (lost.length === 0)
|
|
470
445
|
continue;
|
|
446
|
+
for (const [id] of lost)
|
|
447
|
+
state.wants.delete(id);
|
|
471
448
|
pump(peerId);
|
|
472
449
|
settleIfDone(peerId);
|
|
473
450
|
}
|
|
474
451
|
};
|
|
475
|
-
/** Handles one message from a peer; anything that is not a sync message this peer speaks is ignored */
|
|
476
452
|
const handle = async (peerId, message) => {
|
|
477
453
|
try {
|
|
478
454
|
const msg = parseSyncMessage(message);
|
|
479
|
-
//
|
|
480
|
-
//
|
|
481
|
-
// a session waiting. Each side says hello once it adds the other, so
|
|
482
|
-
// nothing said before then is needed.
|
|
455
|
+
// A peer not added yet has no way back for an answer. Each side says
|
|
456
|
+
// hello once it adds the other, so nothing said before then is needed.
|
|
483
457
|
if (!msg || !peers.has(peerId))
|
|
484
458
|
return;
|
|
485
459
|
switch (msg.type) {
|
|
486
460
|
case 'hello':
|
|
487
|
-
await onHello(peerId, msg.sums, msg.holds, msg.reply === true);
|
|
488
|
-
break;
|
|
461
|
+
return await onHello(peerId, msg.sums, msg.holds, msg.reply === true);
|
|
489
462
|
case 'reconcile':
|
|
490
|
-
await onReconcile(peerId, msg.id, msg.collection, msg.message);
|
|
491
|
-
break;
|
|
463
|
+
return await onReconcile(peerId, msg.id, msg.collection, msg.message);
|
|
492
464
|
case 'reconciled':
|
|
493
|
-
await onReconciled(peerId, msg.id, msg.message, msg.held !== false);
|
|
494
|
-
break;
|
|
465
|
+
return await onReconciled(peerId, msg.id, msg.message, msg.held !== false);
|
|
495
466
|
case 'want':
|
|
496
|
-
await serveWant(peerId, msg.id, Array.isArray(msg.ids) ? msg.ids : []);
|
|
497
|
-
break;
|
|
467
|
+
return await serveWant(peerId, msg.id, Array.isArray(msg.ids) ? msg.ids : []);
|
|
498
468
|
case 'versions':
|
|
499
|
-
await onVersions(peerId, msg.id, Array.isArray(msg.versions) ? msg.versions : []);
|
|
500
|
-
break;
|
|
469
|
+
return await onVersions(peerId, msg.id, Array.isArray(msg.versions) ? msg.versions : []);
|
|
501
470
|
case 'push-update':
|
|
502
471
|
if (msg.version && typeof msg.version === 'object')
|
|
503
472
|
await admitAll(peerId, [msg.version]);
|
|
504
|
-
|
|
473
|
+
return;
|
|
505
474
|
case 'want-file':
|
|
506
475
|
case 'file':
|
|
507
476
|
case 'file-done':
|
|
508
|
-
await config.files?.(peerId, msg);
|
|
509
|
-
break;
|
|
477
|
+
return await config.files?.(peerId, msg);
|
|
510
478
|
case 'stored':
|
|
511
|
-
|
|
512
|
-
emit('stored', peerId, msg.ids.filter((v) => typeof v === 'string').slice(0, 10 * MAX_IDS_PER_REQUEST));
|
|
513
|
-
break;
|
|
479
|
+
return onStored(peerId, msg.ids);
|
|
514
480
|
}
|
|
515
481
|
}
|
|
516
482
|
catch (err) {
|
|
517
|
-
|
|
483
|
+
report(err);
|
|
518
484
|
}
|
|
519
485
|
};
|
|
520
|
-
|
|
521
|
-
|
|
486
|
+
const forget = (peerId) => {
|
|
487
|
+
states.delete(peerId);
|
|
488
|
+
level.delete(peerId);
|
|
489
|
+
};
|
|
522
490
|
return {
|
|
523
491
|
start() {
|
|
524
492
|
if (intervalId !== null)
|
|
@@ -526,21 +494,19 @@ export function createSyncEngine(config) {
|
|
|
526
494
|
intervalId = setInterval(() => {
|
|
527
495
|
sweep();
|
|
528
496
|
for (const peer of peers)
|
|
529
|
-
|
|
497
|
+
sayHello(peer);
|
|
530
498
|
}, heartbeatInterval);
|
|
531
499
|
},
|
|
532
500
|
stop() {
|
|
533
|
-
if (intervalId !== null)
|
|
501
|
+
if (intervalId !== null)
|
|
534
502
|
clearInterval(intervalId);
|
|
535
|
-
|
|
536
|
-
}
|
|
503
|
+
intervalId = null;
|
|
537
504
|
states.clear();
|
|
538
505
|
},
|
|
539
506
|
handleMessage(peerId, message) {
|
|
540
|
-
// One peer's messages
|
|
541
|
-
//
|
|
542
|
-
//
|
|
543
|
-
// comes: the peer may be back on a new one, which knows nothing of it.
|
|
507
|
+
// One peer's messages run in the order they came: a hello must not
|
|
508
|
+
// overtake the versions sent before it. One from a connection closed
|
|
509
|
+
// since is dropped when its turn comes.
|
|
544
510
|
const connection = connections.get(peerId);
|
|
545
511
|
const run = (inOrder.get(peerId) ?? Promise.resolve()).then(() => connections.get(peerId) === connection ? handle(peerId, message) : undefined);
|
|
546
512
|
inOrder.set(peerId, run);
|
|
@@ -553,40 +519,72 @@ export function createSyncEngine(config) {
|
|
|
553
519
|
notifyPeers(peerIds) {
|
|
554
520
|
for (const peer of peerIds)
|
|
555
521
|
if (peers.has(peer))
|
|
556
|
-
|
|
522
|
+
sayHello(peer);
|
|
557
523
|
},
|
|
558
524
|
ask(collection, ids) {
|
|
559
525
|
if (ids.length === 0)
|
|
560
526
|
return;
|
|
561
527
|
for (const peer of peers)
|
|
562
|
-
if (
|
|
528
|
+
if (peerHolds(peer, collection))
|
|
563
529
|
want(peer, collection, ids, true);
|
|
564
530
|
},
|
|
565
531
|
levelWith: (peerId) => level.has(peerId),
|
|
566
532
|
onLocalChange(version) {
|
|
567
533
|
level.clear();
|
|
568
|
-
// Not to a peer
|
|
569
|
-
for (const peer of peers)
|
|
570
|
-
if (
|
|
534
|
+
// Not to a peer that doesn't hold the collection: it would pass it by.
|
|
535
|
+
for (const peer of peers)
|
|
536
|
+
if (peerHolds(peer, version.collection))
|
|
571
537
|
send(peer, { type: 'push-update', version });
|
|
572
|
-
}
|
|
573
538
|
},
|
|
574
539
|
addPeer(peerId) {
|
|
575
540
|
// A new connection: nothing half-finished from an earlier one carries over.
|
|
576
541
|
connections.set(peerId, ++lastConnection);
|
|
577
|
-
|
|
578
|
-
level.delete(peerId);
|
|
542
|
+
forget(peerId);
|
|
579
543
|
peers.add(peerId);
|
|
580
544
|
},
|
|
581
545
|
removePeer(peerId) {
|
|
582
|
-
// A dropped peer must not leave half-finished sessions holding memory.
|
|
583
546
|
connections.delete(peerId);
|
|
584
547
|
peers.delete(peerId);
|
|
585
|
-
|
|
586
|
-
level.delete(peerId);
|
|
548
|
+
forget(peerId);
|
|
587
549
|
},
|
|
588
550
|
on,
|
|
589
551
|
off,
|
|
590
552
|
};
|
|
591
553
|
}
|
|
554
|
+
/** Takes up to one want's worth of queued ids, all of one collection, off the front of the queue */
|
|
555
|
+
function takeBatch(state) {
|
|
556
|
+
const ids = [];
|
|
557
|
+
let collection = null;
|
|
558
|
+
while (state.queued.length > 0 && ids.length < MAX_IDS_PER_REQUEST) {
|
|
559
|
+
const next = state.queued[0];
|
|
560
|
+
if (!state.queuedIds.has(next.id)) {
|
|
561
|
+
state.queued.shift();
|
|
562
|
+
continue;
|
|
563
|
+
}
|
|
564
|
+
if (collection !== null && next.collection !== collection)
|
|
565
|
+
break;
|
|
566
|
+
collection = next.collection;
|
|
567
|
+
state.queued.shift();
|
|
568
|
+
state.queuedIds.delete(next.id);
|
|
569
|
+
ids.push(next.id);
|
|
570
|
+
}
|
|
571
|
+
return collection === null ? null : { collection, ids };
|
|
572
|
+
}
|
|
573
|
+
const newPeerState = () => ({
|
|
574
|
+
sessions: new Map(),
|
|
575
|
+
wants: new Map(),
|
|
576
|
+
queued: [],
|
|
577
|
+
queuedIds: new Set(),
|
|
578
|
+
holds: 'all',
|
|
579
|
+
});
|
|
580
|
+
const refusal = (peerId, id) => `${peerId}\n${id}`;
|
|
581
|
+
const abandoned = (peerId, why) => new Error(`Sync with ${peerId} abandoned: ${why}`);
|
|
582
|
+
/** Drops the oldest entry once a map or set is over `max` */
|
|
583
|
+
function dropOldest(items, max) {
|
|
584
|
+
if (items.size <= max)
|
|
585
|
+
return;
|
|
586
|
+
const oldest = items.keys().next();
|
|
587
|
+
if (!oldest.done)
|
|
588
|
+
items.delete(oldest.value);
|
|
589
|
+
}
|
|
592
590
|
//# sourceMappingURL=sync-engine.js.map
|