@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/node/remote.js
CHANGED
|
@@ -5,92 +5,42 @@ import { storedComputed, storedContract } from '../records/contract-builder.js';
|
|
|
5
5
|
import { isRecord } from '../utils/guards.js';
|
|
6
6
|
import { SESSION_COMMAND } from './node.js';
|
|
7
7
|
import { API, buildNamespaces, callMethod, givenFor } from './api.js';
|
|
8
|
-
/** A definition as plain data: its schema as JSON Schema, a contract or computed fields built in TypeScript as their CEL */
|
|
9
|
-
function storedDefinition(definition) {
|
|
10
|
-
const { contract: _built, computed: _derived, ...rest } = definition;
|
|
11
|
-
const contract = storedContract(definition);
|
|
12
|
-
const computed = storedComputed(definition);
|
|
13
|
-
return {
|
|
14
|
-
...rest,
|
|
15
|
-
schema: toJsonSchema(definition.schema),
|
|
16
|
-
...(contract !== undefined ? { contract } : {}),
|
|
17
|
-
...(computed !== undefined ? { computed } : {}),
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
8
|
/** Tags every message, so a port shared with other traffic can tell ours apart */
|
|
21
9
|
const TAG = 'minca-node';
|
|
10
|
+
const SIGNER_TAG = 'minca-signer';
|
|
22
11
|
/** The node's own methods that cross; every namespace's do (`node/api.ts`) */
|
|
23
12
|
const OWN_METHODS = Object.freeze({ iceServers: true, revokeKey: true, revokeSelf: true });
|
|
24
13
|
/** How often the served side checks for a renewed delegation between calls */
|
|
25
14
|
const DELEGATION_CHECK_MS = 60_000;
|
|
26
|
-
|
|
27
|
-
if (!isRecord(error))
|
|
28
|
-
return { name: 'Error', message: String(error) };
|
|
29
|
-
return {
|
|
30
|
-
name: typeof error.name === 'string' ? error.name : 'Error',
|
|
31
|
-
message: typeof error.message === 'string' ? error.message : 'The node failed',
|
|
32
|
-
...(error.code !== undefined ? { code: error.code } : {}),
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
function received(sent) {
|
|
36
|
-
const fields = isRecord(sent) ? sent : {};
|
|
37
|
-
const error = new Error(typeof fields.message === 'string' ? fields.message : 'The node failed');
|
|
38
|
-
if (typeof fields.name === 'string')
|
|
39
|
-
error.name = fields.name;
|
|
40
|
-
if (fields.code !== undefined)
|
|
41
|
-
Object.assign(error, { code: fields.code });
|
|
42
|
-
return error;
|
|
43
|
-
}
|
|
44
|
-
const stateOf = (node) => ({
|
|
45
|
-
did: node.did,
|
|
46
|
-
sessionDid: node.sessionDid,
|
|
47
|
-
delegation: node.delegation(),
|
|
48
|
-
status: node.network.status(),
|
|
49
|
-
});
|
|
50
|
-
/** The method a call names, bound to its namespace, or null when it is not one that crosses */
|
|
51
|
-
function methodAt(node, path) {
|
|
52
|
-
const parts = path.split('.');
|
|
53
|
-
const [first, second] = parts;
|
|
54
|
-
if (first === undefined || parts.length > 2)
|
|
55
|
-
return null;
|
|
56
|
-
const listed = second === undefined ? OWN_METHODS : Object.hasOwn(API, first) ? Reflect.get(API, first) : null;
|
|
57
|
-
const name = second ?? first;
|
|
58
|
-
const owner = second === undefined ? node : Reflect.get(node, first);
|
|
59
|
-
if (!isRecord(listed) || !Object.hasOwn(listed, name) || !isRecord(owner))
|
|
60
|
-
return null;
|
|
61
|
-
return (...args) => callMethod(owner, name, args);
|
|
62
|
-
}
|
|
15
|
+
const CLOSED = 'That node has closed';
|
|
63
16
|
/**
|
|
64
17
|
* Answers for `node` over `port`, until the returned function is called.
|
|
65
18
|
* Stopping leaves the node running: closing it is its owner's to do, or the
|
|
66
19
|
* other side's, through `close()`.
|
|
67
20
|
*/
|
|
68
21
|
export function serveNode(node, port) {
|
|
22
|
+
const post = (message) => send(port, TAG, message);
|
|
69
23
|
const watches = new Map();
|
|
70
24
|
const holds = new Map();
|
|
71
|
-
let
|
|
72
|
-
let
|
|
25
|
+
let lastHold = 0;
|
|
26
|
+
let sentSig = node.delegation().sig;
|
|
73
27
|
let closed = false;
|
|
74
|
-
|
|
75
|
-
port.postMessage({ [TAG]: true, ...message });
|
|
76
|
-
};
|
|
77
|
-
const sendState = () => {
|
|
28
|
+
function sendState() {
|
|
78
29
|
const state = stateOf(node);
|
|
79
|
-
|
|
30
|
+
sentSig = state.delegation.sig;
|
|
80
31
|
post({ kind: 'state', state });
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (node.delegation().sig !== sent)
|
|
32
|
+
}
|
|
33
|
+
function checkDelegation() {
|
|
34
|
+
if (node.delegation().sig !== sentSig)
|
|
85
35
|
sendState();
|
|
86
|
-
}
|
|
36
|
+
}
|
|
87
37
|
const unsubscribe = node.subscribe((event) => {
|
|
88
38
|
post({ kind: 'event', event });
|
|
89
39
|
if (event.type === 'network')
|
|
90
40
|
sendState();
|
|
91
41
|
});
|
|
92
42
|
const timer = setInterval(checkDelegation, DELEGATION_CHECK_MS);
|
|
93
|
-
|
|
43
|
+
function stop() {
|
|
94
44
|
clearInterval(timer);
|
|
95
45
|
unsubscribe();
|
|
96
46
|
for (const unwatch of watches.values())
|
|
@@ -99,77 +49,91 @@ export function serveNode(node, port) {
|
|
|
99
49
|
for (const release of holds.values())
|
|
100
50
|
void release().catch(() => { });
|
|
101
51
|
holds.clear();
|
|
102
|
-
}
|
|
103
|
-
|
|
52
|
+
}
|
|
53
|
+
/** Calls that are not the node's own methods */
|
|
54
|
+
const special = new Map([
|
|
55
|
+
['hello', async () => stateOf(node)],
|
|
56
|
+
[
|
|
57
|
+
'hold',
|
|
58
|
+
async ([spaceId]) => {
|
|
59
|
+
const id = ++lastHold;
|
|
60
|
+
holds.set(id, await node.spaces.hold(String(spaceId)));
|
|
61
|
+
return id;
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
[
|
|
65
|
+
'release',
|
|
66
|
+
async ([held]) => {
|
|
67
|
+
const release = holds.get(Number(held));
|
|
68
|
+
holds.delete(Number(held));
|
|
69
|
+
await release?.();
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
[
|
|
73
|
+
'close',
|
|
74
|
+
async () => {
|
|
75
|
+
// Later calls are told it has closed.
|
|
76
|
+
closed = true;
|
|
77
|
+
stop();
|
|
78
|
+
await node.close();
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
]);
|
|
82
|
+
async function run(path, args) {
|
|
104
83
|
if (closed)
|
|
105
|
-
throw new Error(
|
|
106
|
-
|
|
107
|
-
return stateOf(node);
|
|
108
|
-
if (path === 'hold') {
|
|
109
|
-
const release = await node.spaces.hold(String(args[0]));
|
|
110
|
-
const id = ++nextHold;
|
|
111
|
-
holds.set(id, release);
|
|
112
|
-
return id;
|
|
113
|
-
}
|
|
114
|
-
if (path === 'release') {
|
|
115
|
-
const release = holds.get(Number(args[0]));
|
|
116
|
-
holds.delete(Number(args[0]));
|
|
117
|
-
await release?.();
|
|
118
|
-
return undefined;
|
|
119
|
-
}
|
|
120
|
-
if (path === 'close') {
|
|
121
|
-
// With the node closed there is nothing left to renew; later calls are told it has closed.
|
|
122
|
-
closed = true;
|
|
123
|
-
stop();
|
|
124
|
-
await node.close();
|
|
125
|
-
return undefined;
|
|
126
|
-
}
|
|
127
|
-
const method = methodAt(node, path);
|
|
84
|
+
throw new Error(CLOSED);
|
|
85
|
+
const method = special.get(path) ?? methodAt(node, path);
|
|
128
86
|
if (!method)
|
|
129
87
|
throw new Error(`A node has no method ${path}`);
|
|
130
|
-
return await method(
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return;
|
|
136
|
-
if (message.kind === 'call' && typeof message.id === 'number' && typeof message.path === 'string') {
|
|
137
|
-
const { id } = message;
|
|
138
|
-
const args = Array.isArray(message.args) ? message.args : [];
|
|
139
|
-
void run(message.path, args).then((value) => {
|
|
140
|
-
try {
|
|
141
|
-
post({ kind: 'reply', id, ok: true, value });
|
|
142
|
-
}
|
|
143
|
-
catch (error) {
|
|
144
|
-
// A value that won't clone: say so, rather than leave the call waiting.
|
|
145
|
-
post({ kind: 'reply', id, ok: false, error: sendable(error) });
|
|
146
|
-
}
|
|
147
|
-
checkDelegation();
|
|
148
|
-
}, (error) => post({ kind: 'reply', id, ok: false, error: sendable(error) }));
|
|
88
|
+
return await method(args);
|
|
89
|
+
}
|
|
90
|
+
function reply(id, value) {
|
|
91
|
+
try {
|
|
92
|
+
post({ kind: 'reply', id, ok: true, value });
|
|
149
93
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const { watch } = message;
|
|
154
|
-
if (!isRecord(message.query)) {
|
|
155
|
-
post({ kind: 'result', watch, error: sendable(new Error('Nothing to watch')) });
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
const unwatch = node.records.watch(message.space,
|
|
159
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- the query runner checks it and reports what's wrong through onError
|
|
160
|
-
message.query, (result) => post({ kind: 'result', watch, result }), (error) => post({ kind: 'result', watch, error: sendable(error) }));
|
|
161
|
-
watches.set(watch, unwatch);
|
|
94
|
+
catch (error) {
|
|
95
|
+
// A value that won't clone: say so, rather than leave the call waiting.
|
|
96
|
+
post({ kind: 'reply', id, ok: false, error: sendable(error) });
|
|
162
97
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
98
|
+
}
|
|
99
|
+
function onCall(message) {
|
|
100
|
+
const { id, path } = message;
|
|
101
|
+
if (typeof id !== 'number' || typeof path !== 'string')
|
|
102
|
+
return;
|
|
103
|
+
const args = Array.isArray(message.args) ? message.args : [];
|
|
104
|
+
void run(path, args).then((value) => {
|
|
105
|
+
reply(id, value);
|
|
106
|
+
checkDelegation();
|
|
107
|
+
}, (error) => post({ kind: 'reply', id, ok: false, error: sendable(error) }));
|
|
108
|
+
}
|
|
109
|
+
function onWatch(message) {
|
|
110
|
+
const { watch, space, query } = message;
|
|
111
|
+
if (typeof watch !== 'number' || typeof space !== 'string')
|
|
112
|
+
return;
|
|
113
|
+
if (!isRecord(query)) {
|
|
114
|
+
post({ kind: 'result', watch, error: sendable(new Error('Nothing to watch')) });
|
|
115
|
+
return;
|
|
166
116
|
}
|
|
117
|
+
const unwatch = node.records.watch(space,
|
|
118
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- the query runner checks it and reports what's wrong through onError
|
|
119
|
+
query, (result) => post({ kind: 'result', watch, result }), (error) => post({ kind: 'result', watch, error: sendable(error) }));
|
|
120
|
+
watches.set(watch, unwatch);
|
|
121
|
+
}
|
|
122
|
+
function onUnwatch({ watch }) {
|
|
123
|
+
if (typeof watch !== 'number')
|
|
124
|
+
return;
|
|
125
|
+
watches.get(watch)?.();
|
|
126
|
+
watches.delete(watch);
|
|
127
|
+
}
|
|
128
|
+
const handlers = {
|
|
129
|
+
call: onCall,
|
|
130
|
+
watch: onWatch,
|
|
131
|
+
unwatch: onUnwatch,
|
|
167
132
|
};
|
|
168
|
-
port
|
|
169
|
-
port.start?.();
|
|
133
|
+
const stopListening = listen(port, TAG, (message) => handlerFor(handlers, message)?.(message));
|
|
170
134
|
return () => {
|
|
171
135
|
stop();
|
|
172
|
-
|
|
136
|
+
stopListening();
|
|
173
137
|
};
|
|
174
138
|
}
|
|
175
139
|
/**
|
|
@@ -177,31 +141,21 @@ export function serveNode(node, port) {
|
|
|
177
141
|
* each call a message. Resolves once the node has said who it is.
|
|
178
142
|
*/
|
|
179
143
|
export async function remoteNode(port) {
|
|
180
|
-
const
|
|
144
|
+
const post = (message) => send(port, TAG, message);
|
|
145
|
+
const calls = createCalls();
|
|
181
146
|
const listeners = new Set();
|
|
182
|
-
let state = null;
|
|
183
147
|
const watchers = new Map();
|
|
148
|
+
let lastWatch = 0;
|
|
149
|
+
let state = null;
|
|
184
150
|
/** Closed from this side: calls fail at once */
|
|
185
151
|
let closed = false;
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const message = event.data;
|
|
192
|
-
if (!isRecord(message) || message[TAG] !== true)
|
|
193
|
-
return;
|
|
194
|
-
if (message.kind === 'reply' && typeof message.id === 'number') {
|
|
195
|
-
const waiting = pending.get(message.id);
|
|
196
|
-
pending.delete(message.id);
|
|
197
|
-
if (message.ok === true)
|
|
198
|
-
waiting?.resolve(message.value);
|
|
199
|
-
else
|
|
200
|
-
waiting?.reject(received(message.error));
|
|
201
|
-
}
|
|
202
|
-
else if (message.kind === 'event' && isRecord(message.event)) {
|
|
152
|
+
const handlers = {
|
|
153
|
+
reply: calls.settle,
|
|
154
|
+
event({ event }) {
|
|
155
|
+
if (!isRecord(event))
|
|
156
|
+
return;
|
|
203
157
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- the served node sent it from its own subscribe
|
|
204
|
-
const nodeEvent =
|
|
158
|
+
const nodeEvent = event;
|
|
205
159
|
for (const listener of listeners) {
|
|
206
160
|
try {
|
|
207
161
|
listener(nodeEvent);
|
|
@@ -210,46 +164,46 @@ export async function remoteNode(port) {
|
|
|
210
164
|
console.error(error);
|
|
211
165
|
}
|
|
212
166
|
}
|
|
213
|
-
}
|
|
214
|
-
|
|
167
|
+
},
|
|
168
|
+
state(message) {
|
|
215
169
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- the served node sent it from its own state
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
170
|
+
if (isRecord(message.state))
|
|
171
|
+
state = message.state;
|
|
172
|
+
},
|
|
173
|
+
result(message) {
|
|
174
|
+
const watcher = typeof message.watch === 'number' ? watchers.get(message.watch) : undefined;
|
|
220
175
|
if (!watcher)
|
|
221
176
|
return;
|
|
222
177
|
if (message.error !== undefined)
|
|
223
178
|
watcher.onError(received(message.error));
|
|
224
179
|
else
|
|
225
180
|
watcher.onResult(message.result);
|
|
226
|
-
}
|
|
181
|
+
},
|
|
227
182
|
};
|
|
228
|
-
port
|
|
229
|
-
port.start?.();
|
|
183
|
+
const stopListening = listen(port, TAG, (message) => handlerFor(handlers, message)?.(message));
|
|
230
184
|
/** Calls a method of the node on the other end; it answers with that method's type */
|
|
231
|
-
const ask = (path, args) =>
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
reject,
|
|
185
|
+
const ask = (path, args) => closed
|
|
186
|
+
? Promise.reject(new Error(CLOSED))
|
|
187
|
+
: calls.call((id) => post({ kind: 'call', id, path, args }));
|
|
188
|
+
function watch(spaceId, query, onResult, onError) {
|
|
189
|
+
const id = ++lastWatch;
|
|
190
|
+
watchers.set(id, {
|
|
191
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- the served node ran this query
|
|
192
|
+
onResult: (result) => onResult(result),
|
|
193
|
+
onError: onError ?? ((error) => console.error(error)),
|
|
241
194
|
});
|
|
242
195
|
try {
|
|
243
|
-
post({ kind: '
|
|
196
|
+
post({ kind: 'watch', watch: id, space: spaceId, query: plainQuery(query) });
|
|
244
197
|
}
|
|
245
198
|
catch (error) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
reject(error instanceof Error ? error : new Error(String(error)));
|
|
199
|
+
watchers.delete(id);
|
|
200
|
+
throw error;
|
|
249
201
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
202
|
+
return () => {
|
|
203
|
+
if (watchers.delete(id))
|
|
204
|
+
post({ kind: 'unwatch', watch: id });
|
|
205
|
+
};
|
|
206
|
+
}
|
|
253
207
|
const initial = await ask('hello', []);
|
|
254
208
|
const current = () => state ?? initial;
|
|
255
209
|
// Every method is asked of the other end, except these.
|
|
@@ -265,33 +219,10 @@ export async function remoteNode(port) {
|
|
|
265
219
|
// Either overload: the record comes back typed as the call asked.
|
|
266
220
|
put: (...args) => ask('records.put', [args[0], collectionName(args[1]), ...args.slice(2)]),
|
|
267
221
|
query: (spaceId, query) => ask('records.query', [spaceId, plainQuery(query)]),
|
|
268
|
-
watch
|
|
269
|
-
const watch = ++nextId;
|
|
270
|
-
watchers.set(watch, {
|
|
271
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- the served node ran this query
|
|
272
|
-
onResult: (result) => onResult(result),
|
|
273
|
-
onError: onError ?? ((error) => console.error(error)),
|
|
274
|
-
});
|
|
275
|
-
try {
|
|
276
|
-
post({ kind: 'watch', watch, space: spaceId, query: plainQuery(query) });
|
|
277
|
-
}
|
|
278
|
-
catch (error) {
|
|
279
|
-
watchers.delete(watch);
|
|
280
|
-
throw error;
|
|
281
|
-
}
|
|
282
|
-
return () => {
|
|
283
|
-
if (!watchers.delete(watch))
|
|
284
|
-
return;
|
|
285
|
-
post({ kind: 'unwatch', watch });
|
|
286
|
-
};
|
|
287
|
-
},
|
|
222
|
+
watch,
|
|
288
223
|
},
|
|
289
224
|
collections: {
|
|
290
|
-
define: async (spaceId, definition) => ask('collections.define', [
|
|
291
|
-
spaceId,
|
|
292
|
-
// Plain data: a contract or computed fields built in TypeScript are functions, which can't be posted.
|
|
293
|
-
storedDefinition(definition),
|
|
294
|
-
]),
|
|
225
|
+
define: async (spaceId, definition) => ask('collections.define', [spaceId, storedDefinition(definition)]),
|
|
295
226
|
},
|
|
296
227
|
network: {
|
|
297
228
|
status: () => current().status,
|
|
@@ -322,90 +253,171 @@ export async function remoteNode(port) {
|
|
|
322
253
|
await ask('close', []);
|
|
323
254
|
closed = true;
|
|
324
255
|
listeners.clear();
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
waiting.reject(new Error('That node has closed'));
|
|
328
|
-
pending.clear();
|
|
256
|
+
stopListening();
|
|
257
|
+
calls.rejectAll(new Error(CLOSED));
|
|
329
258
|
watchers.clear();
|
|
330
259
|
},
|
|
331
260
|
});
|
|
332
261
|
}
|
|
333
|
-
const SIGNER_TAG = 'minca-signer';
|
|
334
262
|
/**
|
|
335
|
-
* Signs session notes for a `remoteSigner` on the other side of `port`:
|
|
336
|
-
* one note a node asks for, everything about the account
|
|
337
|
-
* to its key until a time.
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
* holds it. Returns a function that stops.
|
|
263
|
+
* Signs session notes for a `remoteSigner` on the other side of `port`: only
|
|
264
|
+
* the one note a node asks for, everything about the account
|
|
265
|
+
* (`SESSION_COMMAND`) to its key until a time. The root key stays here: a
|
|
266
|
+
* passkey needs a document, and a key in a tab should stay in that tab.
|
|
267
|
+
* Returns a function that stops.
|
|
341
268
|
*/
|
|
342
269
|
export function serveSigner(signer, port) {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
270
|
+
async function answer(message) {
|
|
271
|
+
if (message.kind === 'hello')
|
|
272
|
+
return { did: signer.did };
|
|
273
|
+
const { params } = message;
|
|
274
|
+
if (message.kind !== 'delegate' || !isSessionRequest(params))
|
|
275
|
+
throw new Error('A signer across a port signs only session notes');
|
|
276
|
+
return signer.delegate({
|
|
277
|
+
audience: params.audience,
|
|
278
|
+
command: SESSION_COMMAND,
|
|
279
|
+
expiration: params.expiration,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
return listen(port, SIGNER_TAG, (message) => {
|
|
350
283
|
const { id } = message;
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
if (message.kind !== 'delegate' ||
|
|
356
|
-
!isRecord(params) ||
|
|
357
|
-
typeof params.audience !== 'string' ||
|
|
358
|
-
typeof params.expiration !== 'number' ||
|
|
359
|
-
params.command !== SESSION_COMMAND ||
|
|
360
|
-
params.subject !== undefined ||
|
|
361
|
-
params.policy !== undefined)
|
|
362
|
-
throw new Error('A signer across a port signs only session notes');
|
|
363
|
-
return signer.delegate({
|
|
364
|
-
audience: params.audience,
|
|
365
|
-
command: SESSION_COMMAND,
|
|
366
|
-
expiration: params.expiration,
|
|
367
|
-
});
|
|
368
|
-
};
|
|
369
|
-
void run().then((value) => post({ kind: 'reply', id, ok: true, value }), (error) => post({ kind: 'reply', id, ok: false, error: sendable(error) }));
|
|
370
|
-
};
|
|
371
|
-
port.addEventListener('message', onMessage);
|
|
372
|
-
port.start?.();
|
|
373
|
-
return () => port.removeEventListener('message', onMessage);
|
|
284
|
+
if (typeof id !== 'number')
|
|
285
|
+
return;
|
|
286
|
+
void answer(message).then((value) => send(port, SIGNER_TAG, { kind: 'reply', id, ok: true, value }), (error) => send(port, SIGNER_TAG, { kind: 'reply', id, ok: false, error: sendable(error) }));
|
|
287
|
+
});
|
|
374
288
|
}
|
|
375
289
|
/** The signer a `serveSigner` keeps on the other side of `port`, for `createNode` to sign sessions with */
|
|
376
290
|
export async function remoteSigner(port) {
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
if (!isRecord(message) || message[SIGNER_TAG] !== true || message.kind !== 'reply')
|
|
382
|
-
return;
|
|
383
|
-
const waiting = pending.get(Number(message.id));
|
|
384
|
-
pending.delete(Number(message.id));
|
|
385
|
-
if (message.ok === true)
|
|
386
|
-
waiting?.resolve(message.value);
|
|
387
|
-
else
|
|
388
|
-
waiting?.reject(received(message.error));
|
|
389
|
-
});
|
|
390
|
-
port.start?.();
|
|
391
|
-
const ask = (message) => new Promise((resolve, reject) => {
|
|
392
|
-
const id = ++nextId;
|
|
393
|
-
pending.set(id, {
|
|
394
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- the signer on the other side answered this call
|
|
395
|
-
resolve: (value) => resolve(value),
|
|
396
|
-
reject,
|
|
397
|
-
});
|
|
398
|
-
port.postMessage({ [SIGNER_TAG]: true, kind: message.kind, params: message.params, id });
|
|
291
|
+
const calls = createCalls();
|
|
292
|
+
listen(port, SIGNER_TAG, (message) => {
|
|
293
|
+
if (message.kind === 'reply')
|
|
294
|
+
calls.settle(message);
|
|
399
295
|
});
|
|
400
|
-
const
|
|
296
|
+
const ask = (kind, params) => calls.call((id) => send(port, SIGNER_TAG, { kind, params, id }));
|
|
297
|
+
const { did } = await ask('hello');
|
|
401
298
|
return Object.freeze({
|
|
402
299
|
did,
|
|
403
300
|
delegate: async (params) => {
|
|
404
|
-
const token = parseDelegation(await ask(
|
|
301
|
+
const token = parseDelegation(await ask('delegate', params));
|
|
405
302
|
if (!token)
|
|
406
303
|
throw new Error('The signer answered with something that is not a delegation');
|
|
407
304
|
return token;
|
|
408
305
|
},
|
|
409
306
|
});
|
|
410
307
|
}
|
|
308
|
+
/** A session note's request, and nothing else: the far end still picks the key and the time */
|
|
309
|
+
function isSessionRequest(params) {
|
|
310
|
+
return (isRecord(params) &&
|
|
311
|
+
typeof params.audience === 'string' &&
|
|
312
|
+
typeof params.expiration === 'number' &&
|
|
313
|
+
params.command === SESSION_COMMAND &&
|
|
314
|
+
params.subject === undefined &&
|
|
315
|
+
params.policy === undefined);
|
|
316
|
+
}
|
|
317
|
+
/** A definition as plain data: its schema as JSON Schema, a contract or computed fields built in TypeScript as their CEL */
|
|
318
|
+
function storedDefinition(definition) {
|
|
319
|
+
const { contract: _built, computed: _derived, ...rest } = definition;
|
|
320
|
+
const contract = storedContract(definition);
|
|
321
|
+
const computed = storedComputed(definition);
|
|
322
|
+
return {
|
|
323
|
+
...rest,
|
|
324
|
+
schema: toJsonSchema(definition.schema),
|
|
325
|
+
...(contract !== undefined ? { contract } : {}),
|
|
326
|
+
...(computed !== undefined ? { computed } : {}),
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
/** The name a typed collection reference stands for; a validator can't be cloned */
|
|
330
|
+
const collectionName = (ref) => isRecord(ref) && typeof ref.name === 'string' ? ref.name : ref;
|
|
331
|
+
const stateOf = (node) => ({
|
|
332
|
+
did: node.did,
|
|
333
|
+
sessionDid: node.sessionDid,
|
|
334
|
+
delegation: node.delegation(),
|
|
335
|
+
status: node.network.status(),
|
|
336
|
+
});
|
|
337
|
+
/** The method a call names, bound to its namespace, or null when it is not one that crosses */
|
|
338
|
+
function methodAt(node, path) {
|
|
339
|
+
const parts = path.split('.');
|
|
340
|
+
const [first, second] = parts;
|
|
341
|
+
if (first === undefined || parts.length > 2)
|
|
342
|
+
return null;
|
|
343
|
+
const listed = second === undefined ? OWN_METHODS : Object.hasOwn(API, first) ? Reflect.get(API, first) : null;
|
|
344
|
+
const name = second ?? first;
|
|
345
|
+
const owner = second === undefined ? node : Reflect.get(node, first);
|
|
346
|
+
if (!isRecord(listed) || !Object.hasOwn(listed, name) || !isRecord(owner))
|
|
347
|
+
return null;
|
|
348
|
+
return (args) => callMethod(owner, name, args);
|
|
349
|
+
}
|
|
350
|
+
function handlerFor(handlers, message) {
|
|
351
|
+
const { kind } = message;
|
|
352
|
+
return typeof kind === 'string' && Object.hasOwn(handlers, kind) ? handlers[kind] : undefined;
|
|
353
|
+
}
|
|
354
|
+
// Messages: tagged, so a port shared with other traffic can tell ours apart.
|
|
355
|
+
function send(port, tag, message) {
|
|
356
|
+
port.postMessage({ [tag]: true, ...message });
|
|
357
|
+
}
|
|
358
|
+
/** Hears the messages tagged `tag` on `port`; returns a function that stops */
|
|
359
|
+
function listen(port, tag, handle) {
|
|
360
|
+
const onMessage = (event) => {
|
|
361
|
+
const message = event.data;
|
|
362
|
+
if (isRecord(message) && message[tag] === true)
|
|
363
|
+
handle(message);
|
|
364
|
+
};
|
|
365
|
+
port.addEventListener('message', onMessage);
|
|
366
|
+
port.start?.();
|
|
367
|
+
return () => port.removeEventListener('message', onMessage);
|
|
368
|
+
}
|
|
369
|
+
/** Calls sent across a port, waiting for their replies by id */
|
|
370
|
+
function createCalls() {
|
|
371
|
+
const waiting = new Map();
|
|
372
|
+
let lastId = 0;
|
|
373
|
+
return {
|
|
374
|
+
/** Sends a call with `post`; resolves with its reply's value */
|
|
375
|
+
call: (post) => new Promise((resolve, reject) => {
|
|
376
|
+
const id = ++lastId;
|
|
377
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- the other side ran the call this one stands for
|
|
378
|
+
waiting.set(id, { resolve: (value) => resolve(value), reject });
|
|
379
|
+
try {
|
|
380
|
+
post(id);
|
|
381
|
+
}
|
|
382
|
+
catch (error) {
|
|
383
|
+
// An argument that won't clone, a function say.
|
|
384
|
+
waiting.delete(id);
|
|
385
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
386
|
+
}
|
|
387
|
+
}),
|
|
388
|
+
settle: (message) => {
|
|
389
|
+
const id = Number(message.id);
|
|
390
|
+
const call = waiting.get(id);
|
|
391
|
+
waiting.delete(id);
|
|
392
|
+
if (message.ok === true)
|
|
393
|
+
call?.resolve(message.value);
|
|
394
|
+
else
|
|
395
|
+
call?.reject(received(message.error));
|
|
396
|
+
},
|
|
397
|
+
rejectAll: (error) => {
|
|
398
|
+
for (const call of waiting.values())
|
|
399
|
+
call.reject(error);
|
|
400
|
+
waiting.clear();
|
|
401
|
+
},
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
// Errors cross as plain fields.
|
|
405
|
+
function sendable(error) {
|
|
406
|
+
if (!isRecord(error))
|
|
407
|
+
return { name: 'Error', message: String(error) };
|
|
408
|
+
return {
|
|
409
|
+
name: typeof error.name === 'string' ? error.name : 'Error',
|
|
410
|
+
message: typeof error.message === 'string' ? error.message : 'The node failed',
|
|
411
|
+
...(error.code !== undefined ? { code: error.code } : {}),
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
function received(sent) {
|
|
415
|
+
const fields = isRecord(sent) ? sent : {};
|
|
416
|
+
const error = new Error(typeof fields.message === 'string' ? fields.message : 'The node failed');
|
|
417
|
+
if (typeof fields.name === 'string')
|
|
418
|
+
error.name = fields.name;
|
|
419
|
+
if (fields.code !== undefined)
|
|
420
|
+
Object.assign(error, { code: fields.code });
|
|
421
|
+
return error;
|
|
422
|
+
}
|
|
411
423
|
//# sourceMappingURL=remote.js.map
|