@minca/core 0.1.15 → 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 +2 -2
- 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/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.map +1 -1
- package/dist/network/relay-minca.js +11 -49
- package/dist/network/relay-minca.js.map +1 -1
- package/dist/network/relay-nostr.d.ts.map +1 -1
- package/dist/network/relay-nostr.js +23 -63
- 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/node/actions.d.ts.map +1 -1
- package/dist/node/actions.js +50 -38
- 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 +198 -1990
- 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 +103 -142
- package/dist/node/space-runtime.d.ts.map +1 -1
- package/dist/node/space-runtime.js +290 -3963
- 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 -306
- 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/schemas/automations.d.ts +8 -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.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/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/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 +1 -0
- package/docs/actions.md +1 -1
- package/docs/automations.md +1 -1
- package/docs/blueprints-and-guides.md +17 -1
- package/docs/building-an-app.md +7 -4
- package/docs/collections.md +3 -3
- 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 +22 -14
- 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 +7 -6
- package/docs/storage.md +4 -5
- package/docs/usernames.md +161 -0
- package/docs/warrants.md +1 -1
- package/package.json +1 -1
package/dist/node/writers.d.ts
CHANGED
|
@@ -3,31 +3,24 @@
|
|
|
3
3
|
* A key's writes in each collection of a space form one line: its log
|
|
4
4
|
* (spec 02 §4.10).
|
|
5
5
|
*
|
|
6
|
-
* Each version
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* version leaves it.
|
|
6
|
+
* Each version takes the next place in its key's line for its collection,
|
|
7
|
+
* naming the one before. Two versions at one place are a fork, which only a
|
|
8
|
+
* key used in two places at once can make. So a node hands out each place
|
|
9
|
+
* once, one write at a time per key and space, and remembers it before the
|
|
10
|
+
* version leaves.
|
|
12
11
|
*
|
|
13
|
-
* A key made for this run
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* place a second time. Such a key can be signing in more than one node at a
|
|
18
|
-
* time: every tab of an app signs with the app's key. So each place is taken
|
|
19
|
-
* under a lock shared by every tab and worker of the origin, and read afresh
|
|
20
|
-
* from where it is kept, never from a copy in memory another tab has moved on.
|
|
12
|
+
* A key made for this run keeps its places in memory: they go with it. A key
|
|
13
|
+
* that outlives the node keeps them beside it, or a restart would reuse a
|
|
14
|
+
* place. Such a key can sign in several tabs at once, so each place is taken
|
|
15
|
+
* under a lock every tab and worker shares, and read afresh where it is kept.
|
|
21
16
|
*/
|
|
22
17
|
import type { Version, WriterLog } from '../types.js';
|
|
23
18
|
import type { HeadStore } from './writer-keys.js';
|
|
24
19
|
export interface Writers {
|
|
25
20
|
/**
|
|
26
|
-
* Signs the next version of `did`'s log in a space
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* space go one at a time; the place is remembered before this returns, so
|
|
30
|
-
* before the version can leave the node.
|
|
21
|
+
* Signs the next version of `did`'s log in a space's collection. `sign` gets
|
|
22
|
+
* the place and returns the version, or throws to give it back. The place is
|
|
23
|
+
* remembered before this returns.
|
|
31
24
|
*/
|
|
32
25
|
append(did: string, spaceId: string, collection: string, sign: (log: WriterLog) => Promise<Version>): Promise<Version>;
|
|
33
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writers.d.ts","sourceRoot":"","sources":["../../src/node/writers.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"writers.d.ts","sourceRoot":"","sources":["../../src/node/writers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAUlD,MAAM,WAAW,OAAO;IACtB;;;;OAIG;IACH,MAAM,CACJ,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,CAAC,GAAG,EAAE,SAAS,KAAK,OAAO,CAAC,OAAO,CAAC,GACzC,OAAO,CAAC,OAAO,CAAC,CAAC;CACrB;AAiDD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,SAAS,GAAG,IAAI,GAAG,OAAO,CAwCjF"}
|
package/dist/node/writers.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { utf8Decode, utf8Encode } from '../utils/encoding.js';
|
|
2
2
|
import { isRecord } from '../utils/guards.js';
|
|
3
|
-
/**
|
|
4
|
-
* Where a key's places in a space are kept. `head/` held them while a key had
|
|
5
|
-
* one line across a space's collections, whose places no peer accepts any
|
|
6
|
-
* more, so a key carried over from then starts each line afresh.
|
|
7
|
-
*/
|
|
3
|
+
/** Where a key's places in a space are kept. (The old `head/` keys held places no peer accepts any more.) */
|
|
8
4
|
const headKey = (did, spaceId) => `lines/${did}/${spaceId}`;
|
|
9
5
|
const isHead = (value) => isRecord(value) &&
|
|
10
6
|
typeof value.n === 'number' &&
|
|
@@ -30,11 +26,9 @@ function readPlaces(bytes) {
|
|
|
30
26
|
/** Locks held in this process, by name, where there are no Web Locks */
|
|
31
27
|
const held = new Map();
|
|
32
28
|
/**
|
|
33
|
-
* Runs `work`
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* share a key there are in one process, since the CLI locks its keys per
|
|
37
|
-
* process.
|
|
29
|
+
* Runs `work` under a lock every tab and worker of this origin shares. Without
|
|
30
|
+
* Web Locks (Node before 24) the lock is per process, which is enough: the CLI
|
|
31
|
+
* locks its keys per process.
|
|
38
32
|
*/
|
|
39
33
|
function exclusively(name, work) {
|
|
40
34
|
const locks = globalThis.navigator?.locks;
|
|
@@ -58,13 +52,12 @@ export function createWriters(storeOf) {
|
|
|
58
52
|
async function placesOf(did, spaceId) {
|
|
59
53
|
const key = headKey(did, spaceId);
|
|
60
54
|
const store = storeOf(did);
|
|
61
|
-
// A kept key's places are read where they are kept, every time: another node may share the key.
|
|
62
55
|
if (!store)
|
|
63
56
|
return kept.get(key) ?? null;
|
|
57
|
+
// Read afresh every time: another node may share the key.
|
|
64
58
|
const stored = readPlaces(await store.get(key));
|
|
65
|
-
//
|
|
66
|
-
//
|
|
67
|
-
// what the key wrote. Better to sign nothing.
|
|
59
|
+
// Behind what this node took itself means the store was emptied under it:
|
|
60
|
+
// signing on would fork the line, so sign nothing.
|
|
68
61
|
for (const [collection, head] of Object.entries(kept.get(key)?.collections ?? {}))
|
|
69
62
|
if ((stored?.collections[collection]?.n ?? -1) < head.n)
|
|
70
63
|
throw new Error('This key’s places were lost while it was signing, so it signs nothing more.');
|
|
@@ -87,7 +80,6 @@ export function createWriters(storeOf) {
|
|
|
87
80
|
};
|
|
88
81
|
const run = (queues.get(key) ?? Promise.resolve())
|
|
89
82
|
.catch(() => { })
|
|
90
|
-
// A key kept where other nodes can reach it takes each place under the lock they share.
|
|
91
83
|
.then(() => (storeOf(did) ? exclusively(`minca-writer:${key}`, take) : take()));
|
|
92
84
|
queues.set(key, run);
|
|
93
85
|
return run;
|
package/dist/node/writers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writers.js","sourceRoot":"","sources":["../../src/node/writers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"writers.js","sourceRoot":"","sources":["../../src/node/writers.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AA2B9C,6GAA6G;AAC7G,MAAM,OAAO,GAAG,CAAC,GAAW,EAAE,OAAe,EAAE,EAAE,CAAC,SAAS,GAAG,IAAI,OAAO,EAAE,CAAC;AAE5E,MAAM,MAAM,GAAG,CAAC,KAAc,EAAiB,EAAE,CAC/C,QAAQ,CAAC,KAAK,CAAC;IACf,OAAO,KAAK,CAAC,CAAC,KAAK,QAAQ;IAC3B,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7B,OAAO,KAAK,CAAC,EAAE,KAAK,QAAQ,CAAC;AAE/B,SAAS,UAAU,CAAC,KAAwB;IAC1C,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,IAAI,CAAC;QACH,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;QACtD,IAAI,CAAC,QAAQ,CAAC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
|
1
|
-
{"version":3,"file":"direct.d.ts","sourceRoot":"","sources":["../../src/privacy/direct.ts"],"names":[],"mappings":"AAYA,8EAA8E;AAC9E,eAAO,MAAM,aAAa,KAAK,CAAC;AAEhC,iGAAiG;AACjG,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;QAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACjF;AAED,6CAA6C;AAC7C,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,CAE/F;AAOD,yGAAyG;AACzG,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,aAAa,CAAC,MAAM,CAAC;;;;EAEnF;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,aAAa,CAAC,MAAM,CAAC,EACzB,OAAO,EAAE,aAAa,EACtB,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GACtC,OAAO,CAAC,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"direct.d.ts","sourceRoot":"","sources":["../../src/privacy/direct.ts"],"names":[],"mappings":"AAYA,8EAA8E;AAC9E,eAAO,MAAM,aAAa,KAAK,CAAC;AAEhC,iGAAiG;AACjG,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;QAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACjF;AAED,6CAA6C;AAC7C,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,CAE/F;AAOD,yGAAyG;AACzG,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,aAAa,CAAC,MAAM,CAAC;;;;EAEnF;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,aAAa,CAAC,MAAM,CAAC,EACzB,OAAO,EAAE,aAAa,EACtB,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GACtC,OAAO,CAAC,UAAU,CAAC,CAmBrB;AAED;;;;;;GAMG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,MAAM,EACd,SAAS,EAAE;IAAE,QAAQ,CAAC,UAAU,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GACxE,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAe/B"}
|
package/dist/privacy/direct.js
CHANGED
|
@@ -39,22 +39,17 @@ export async function sealDirect(spaceId, from, to, content, memberKeys) {
|
|
|
39
39
|
throw new Error(`A direct message can be for ${MAX_DIRECT_TO} people at most`);
|
|
40
40
|
const bound = directBound(spaceId, from, recipients);
|
|
41
41
|
const key = await generateSpaceKey();
|
|
42
|
-
const
|
|
42
|
+
const sealedKey = { key: base64UrlEncode(key.raw) };
|
|
43
43
|
const boxes = [];
|
|
44
44
|
for (const reader of [...recipients, from]) {
|
|
45
45
|
const publicKey = memberKeys.get(reader);
|
|
46
46
|
if (!publicKey)
|
|
47
47
|
throw new Error(`${reader} can't be written to here yet: they have no member key in this space`);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
sealed: await sealValueTo(publicKey, BOX_LABEL, { ...bound, reader }, { key: raw }),
|
|
51
|
-
});
|
|
48
|
+
const sealed = await sealValueTo(publicKey, BOX_LABEL, { ...bound, reader }, sealedKey);
|
|
49
|
+
boxes.push({ to: reader, sealed });
|
|
52
50
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
data: await sealValue(key.seal, TEXT_LABEL, bound, { text: content.text }),
|
|
56
|
-
boxes,
|
|
57
|
-
};
|
|
51
|
+
const data = await sealValue(key.seal, TEXT_LABEL, bound, { text: content.text });
|
|
52
|
+
return { to: recipients, data, boxes };
|
|
58
53
|
}
|
|
59
54
|
/**
|
|
60
55
|
* Opens a direct message for one of its readers.
|
|
@@ -64,33 +59,42 @@ export async function sealDirect(spaceId, from, to, content, memberKeys) {
|
|
|
64
59
|
* @returns The content, or null when it isn't for this reader, or anything in it doesn't open
|
|
65
60
|
*/
|
|
66
61
|
export async function openDirect(spaceId, from, body, reader, memberKey) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
!Array.isArray(body.to) ||
|
|
70
|
-
!Array.isArray(body.boxes))
|
|
62
|
+
const direct = readDirectBody(body);
|
|
63
|
+
if (!direct || (reader !== from && !direct.to.includes(reader)))
|
|
71
64
|
return null;
|
|
72
|
-
const
|
|
73
|
-
if (to.length !== body.to.length)
|
|
74
|
-
return null;
|
|
75
|
-
if (reader !== from && !to.includes(reader))
|
|
76
|
-
return null;
|
|
77
|
-
const box = body.boxes.find((candidate) => isRecord(candidate) && candidate.to === reader);
|
|
65
|
+
const box = direct.boxes.find((candidate) => isRecord(candidate) && candidate.to === reader);
|
|
78
66
|
if (!isRecord(box) || typeof box.sealed !== 'string')
|
|
79
67
|
return null;
|
|
80
|
-
const bound = directBound(spaceId, from, to);
|
|
68
|
+
const bound = directBound(spaceId, from, direct.to);
|
|
81
69
|
const opened = await openValueFrom(memberKey, BOX_LABEL, { ...bound, reader }, box.sealed);
|
|
82
70
|
if (!isRecord(opened) || typeof opened.key !== 'string')
|
|
83
71
|
return null;
|
|
84
|
-
|
|
72
|
+
const key = await keyFrom(opened.key);
|
|
73
|
+
if (!key)
|
|
74
|
+
return null;
|
|
75
|
+
const content = await openValue(key.seal, TEXT_LABEL, bound, direct.data);
|
|
76
|
+
if (!isRecord(content) || typeof content.text !== 'string')
|
|
77
|
+
return null;
|
|
78
|
+
return { text: content.text };
|
|
79
|
+
}
|
|
80
|
+
/** A body's fields, unchecked boxes and all, or null when it isn't shaped like a direct message */
|
|
81
|
+
function readDirectBody(body) {
|
|
82
|
+
if (!isRecord(body) || typeof body.data !== 'string')
|
|
83
|
+
return null;
|
|
84
|
+
if (!Array.isArray(body.to) || !Array.isArray(body.boxes))
|
|
85
|
+
return null;
|
|
86
|
+
const to = body.to.filter((did) => typeof did === 'string');
|
|
87
|
+
if (to.length !== body.to.length)
|
|
88
|
+
return null;
|
|
89
|
+
const boxes = body.boxes;
|
|
90
|
+
return { to, data: body.data, boxes };
|
|
91
|
+
}
|
|
92
|
+
async function keyFrom(raw) {
|
|
85
93
|
try {
|
|
86
|
-
|
|
94
|
+
return await spaceKeyFromRaw(base64UrlDecode(raw));
|
|
87
95
|
}
|
|
88
96
|
catch {
|
|
89
97
|
return null;
|
|
90
98
|
}
|
|
91
|
-
const content = await openValue(key.seal, TEXT_LABEL, bound, body.data);
|
|
92
|
-
if (!isRecord(content) || typeof content.text !== 'string')
|
|
93
|
-
return null;
|
|
94
|
-
return { text: content.text };
|
|
95
99
|
}
|
|
96
100
|
//# sourceMappingURL=direct.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"direct.js","sourceRoot":"","sources":["../../src/privacy/direct.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE1E,8EAA8E;AAC9E,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,CAAC;AAchC;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,EAAyB;IACtE,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;AAC/D,CAAC;AAED,oDAAoD;AACpD,MAAM,UAAU,GAAG,sBAAsB,CAAC;AAC1C,yCAAyC;AACzC,MAAM,SAAS,GAAG,qBAAqB,CAAC;AAExC,yGAAyG;AACzG,MAAM,UAAU,WAAW,CAAC,OAAe,EAAE,IAAY,EAAE,EAAyB;IAClF,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,gBAAgB,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AAC5E,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,OAAe,EACf,IAAY,EACZ,EAAyB,EACzB,OAAsB,EACtB,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,MAAM,eAAe,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC;IACrD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"space-encryption.d.ts","sourceRoot":"","sources":["../../src/privacy/space-encryption.ts"],"names":[],"mappings":"AAoBA,8FAA8F;AAC9F,eAAO,MAAM,kBAAkB,0BAA0B,CAAC;AAC1D,2FAA2F;AAC3F,eAAO,MAAM,gBAAgB,wBAAwB,CAAC;AAEtD,+BAA+B;AAC/B,MAAM,WAAW,QAAQ;IACvB,8FAA8F;IAC9F,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,mFAAmF;IACnF,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC;IACzB,qGAAqG;IACrG,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,6CAA6C;AAC7C,MAAM,WAAW,oBAAoB;IACnC,+CAA+C;IAC/C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,wFAAwF;AACxF,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,qBAAqB;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;
|
|
1
|
+
{"version":3,"file":"space-encryption.d.ts","sourceRoot":"","sources":["../../src/privacy/space-encryption.ts"],"names":[],"mappings":"AAoBA,8FAA8F;AAC9F,eAAO,MAAM,kBAAkB,0BAA0B,CAAC;AAC1D,2FAA2F;AAC3F,eAAO,MAAM,gBAAgB,wBAAwB,CAAC;AAEtD,+BAA+B;AAC/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RECORD_BODY_LABEL = 'minca/record-body/v1';
|
|
|
20
20
|
export const EARLIER_KEYS_LABEL = 'minca/earlier-keys/v1';
|
|
21
21
|
/** The envelope label of a reader's note, sealed for a connection; bound to `{ space }` */
|
|
22
22
|
export const MEMBERSHIP_LABEL = 'minca/membership/v1';
|
|
23
|
-
/** A space key's id, from its raw bytes */
|
|
24
|
-
async function spaceKeyId(raw) {
|
|
25
|
-
return base64UrlEncode(await hkdf(raw, KEY_ID_INFO, KEY_ID_BYTES));
|
|
26
|
-
}
|
|
27
23
|
/**
|
|
28
24
|
* A space key from its raw bytes. Its id is derived from them, so a key
|
|
29
25
|
* handed over (in an invite, a box) can be checked against the id a space or
|
|
@@ -34,7 +30,7 @@ export async function spaceKeyFromRaw(raw, createdAt = new Date().toISOString())
|
|
|
34
30
|
throw new Error('A space key is 32 bytes');
|
|
35
31
|
const bytes = new Uint8Array(raw);
|
|
36
32
|
return Object.freeze({
|
|
37
|
-
id: await
|
|
33
|
+
id: base64UrlEncode(await hkdf(bytes, KEY_ID_INFO, KEY_ID_BYTES)),
|
|
38
34
|
raw: bytes,
|
|
39
35
|
seal: await hkdfAesKey(bytes, SEAL_INFO),
|
|
40
36
|
createdAt,
|
|
@@ -45,10 +41,10 @@ export async function spaceKeyFromRaw(raw, createdAt = new Date().toISOString())
|
|
|
45
41
|
export function generateSpaceKey() {
|
|
46
42
|
return spaceKeyFromRaw(globalThis.crypto.getRandomValues(new Uint8Array(SPACE_KEY_BYTES)));
|
|
47
43
|
}
|
|
48
|
-
const bodyBound = (
|
|
49
|
-
space
|
|
50
|
-
collection
|
|
51
|
-
key
|
|
44
|
+
const bodyBound = ({ space, collection, key }, keyId) => ({
|
|
45
|
+
space,
|
|
46
|
+
collection,
|
|
47
|
+
key,
|
|
52
48
|
keyId,
|
|
53
49
|
});
|
|
54
50
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"space-encryption.js","sourceRoot":"","sources":["../../src/privacy/space-encryption.ts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AED,qDAAqD;AACrD,eAAO,MAAM,QAAQ,MAAO,UAAU,GAAG,IAAI,KAAG,CAAC,IAAI,UAA2C,CAAC;AAiBjG;;;GAGG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,cAAc,CAAC,CAyBzB"}
|
package/dist/query/computed.js
CHANGED
|
@@ -3,6 +3,7 @@ import { INT, STRING, typeOfCel, typeOfSchema, versionType } from '../records/ce
|
|
|
3
3
|
import { versionValue } from '../records/contracts.js';
|
|
4
4
|
import { LINK_REL_PATTERN } from '../records/links.js';
|
|
5
5
|
import { isRecord } from '../utils/guards.js';
|
|
6
|
+
import { getOrAdd } from '../utils/map.js';
|
|
6
7
|
/** At most this many per collection: each is worked out for every record read */
|
|
7
8
|
const MAX_COMPUTED = 16;
|
|
8
9
|
/** Characters in one field's expression, as for a contract's condition */
|
|
@@ -23,7 +24,10 @@ const NAMES = new Set([
|
|
|
23
24
|
'createdAt',
|
|
24
25
|
'updatedAt',
|
|
25
26
|
]);
|
|
27
|
+
/** A `linked(collection, rel)` call's key in a map */
|
|
28
|
+
const linkedKey = (collection, rel) => `${collection}\u0000${rel}`;
|
|
26
29
|
const parsed = new Map();
|
|
30
|
+
/** An expression's parse, cached; or why it doesn't parse */
|
|
27
31
|
function parse(source) {
|
|
28
32
|
const cached = parsed.get(source);
|
|
29
33
|
if (cached)
|
|
@@ -48,26 +52,31 @@ export function checkComputed(computed, at = 'computed') {
|
|
|
48
52
|
return `${at}: at most ${MAX_COMPUTED} computed fields`;
|
|
49
53
|
const count = { nodes: 0 };
|
|
50
54
|
for (const [name, source] of entries) {
|
|
51
|
-
const
|
|
52
|
-
if (!NAME.test(name))
|
|
53
|
-
return `${here}: a name is lower camel case, like "done" or "thumbsUp"`;
|
|
54
|
-
if (typeof source !== 'string' || !source.trim() || source.length > MAX_LENGTH)
|
|
55
|
-
return `${here} is a CEL expression, at most ${MAX_LENGTH} characters`;
|
|
56
|
-
const node = parse(source);
|
|
57
|
-
if (typeof node === 'string')
|
|
58
|
-
return `${here}: ${node}`;
|
|
59
|
-
const problem = checkCel(node, { names: NAMES, linked: true, linkRel: LINK_REL_PATTERN }, count);
|
|
55
|
+
const problem = checkField(name, source, count);
|
|
60
56
|
if (problem)
|
|
61
|
-
return `${
|
|
62
|
-
for (const [collection] of linkedCalls(node)) {
|
|
63
|
-
if (!COLLECTION.test(collection))
|
|
64
|
-
return `${here}: linked() takes a collection name, like "app.reaction"; "${collection}" is not one`;
|
|
65
|
-
}
|
|
57
|
+
return `${at}.${name}${problem}`;
|
|
66
58
|
if (count.nodes > MAX_NODES)
|
|
67
59
|
return `${at}: computed fields are too large (at most ${MAX_NODES} parts)`;
|
|
68
60
|
}
|
|
69
61
|
return null;
|
|
70
62
|
}
|
|
63
|
+
/** Why one computed field can't be used, said after its name; `count` adds up the parts of all of them */
|
|
64
|
+
function checkField(name, source, count) {
|
|
65
|
+
if (!NAME.test(name))
|
|
66
|
+
return ': a name is lower camel case, like "done" or "thumbsUp"';
|
|
67
|
+
if (typeof source !== 'string' || !source.trim() || source.length > MAX_LENGTH)
|
|
68
|
+
return ` is a CEL expression, at most ${MAX_LENGTH} characters`;
|
|
69
|
+
const node = parse(source);
|
|
70
|
+
if (typeof node === 'string')
|
|
71
|
+
return `: ${node}`;
|
|
72
|
+
const problem = checkCel(node, { names: NAMES, linked: true, linkRel: LINK_REL_PATTERN }, count);
|
|
73
|
+
if (problem)
|
|
74
|
+
return `: ${problem}`;
|
|
75
|
+
const bad = linkedCalls(node).find(([collection]) => !COLLECTION.test(collection));
|
|
76
|
+
if (bad)
|
|
77
|
+
return `: linked() takes a collection name, like "app.reaction"; "${bad[0]}" is not one`;
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
71
80
|
/** Every `linked(collection, rel)` an expression calls */
|
|
72
81
|
function linkedCalls(node, into = []) {
|
|
73
82
|
if (node.k === 'call' && !node.target && node.fn === 'linked') {
|
|
@@ -96,14 +105,29 @@ function typesOfComputed(name, computed, schema, definitionOf, at = 'computed')
|
|
|
96
105
|
const clash = computedClash(computed, schema, at);
|
|
97
106
|
if (clash)
|
|
98
107
|
return clash;
|
|
99
|
-
const
|
|
100
|
-
const
|
|
101
|
-
const
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
names
|
|
105
|
-
|
|
106
|
-
|
|
108
|
+
const names = namesOf(schema);
|
|
109
|
+
const linked = linkedType(name, definitionOf);
|
|
110
|
+
const types = {};
|
|
111
|
+
for (const [field, source] of Object.entries(computed)) {
|
|
112
|
+
const node = parse(source);
|
|
113
|
+
const type = typeof node === 'string' ? node : typeOfCel(node, names, linked);
|
|
114
|
+
if (typeof type === 'string')
|
|
115
|
+
return `${at}.${field}: ${type}`;
|
|
116
|
+
types[field] = type;
|
|
117
|
+
}
|
|
118
|
+
return types;
|
|
119
|
+
}
|
|
120
|
+
/** The types of what a computed field reads of its record */
|
|
121
|
+
function namesOf(schema) {
|
|
122
|
+
const version = versionType(typeOfSchema(schema));
|
|
123
|
+
const names = new Map(Object.entries(version.t === 'object' ? version.fields : {}));
|
|
124
|
+
names.delete('id');
|
|
125
|
+
names.delete('deleted');
|
|
126
|
+
return names.set('creator', STRING).set('updatedAt', STRING).set('seq', INT);
|
|
127
|
+
}
|
|
128
|
+
/** The type of a `linked(collection, rel)` from collection `name`, or why it can't be called */
|
|
129
|
+
function linkedType(name, definitionOf) {
|
|
130
|
+
return (collection, rel) => {
|
|
107
131
|
const linking = definitionOf(collection);
|
|
108
132
|
if (!linking) {
|
|
109
133
|
return collection.startsWith('std.')
|
|
@@ -111,47 +135,33 @@ function typesOfComputed(name, computed, schema, definitionOf, at = 'computed')
|
|
|
111
135
|
: `${collection} is not defined in this space: define it first`;
|
|
112
136
|
}
|
|
113
137
|
const declared = linking.links ?? {};
|
|
114
|
-
const roles = Object.keys(declared);
|
|
115
138
|
const role = Object.hasOwn(declared, rel) ? declared[rel] : undefined;
|
|
116
139
|
if (!role)
|
|
117
|
-
return `${collection} declares no link role "${rel}"; ${
|
|
140
|
+
return `${collection} declares no link role "${rel}"; ${declaredRoles(declared)}`;
|
|
118
141
|
if (role.to !== '*' && !role.to.includes(name))
|
|
119
142
|
return `${collection}'s "${rel}" links point at ${role.to.join(', ')}, not ${name}`;
|
|
120
143
|
return typeOfSchema(linking.schema);
|
|
121
144
|
};
|
|
122
|
-
const types = {};
|
|
123
|
-
for (const [field, source] of Object.entries(computed)) {
|
|
124
|
-
const node = parse(source);
|
|
125
|
-
if (typeof node === 'string')
|
|
126
|
-
return `${at}.${field}: ${node}`;
|
|
127
|
-
const type = typeOfCel(node, names, linked);
|
|
128
|
-
if (typeof type === 'string')
|
|
129
|
-
return `${at}.${field}: ${type}`;
|
|
130
|
-
types[field] = type;
|
|
131
|
-
}
|
|
132
|
-
return types;
|
|
133
145
|
}
|
|
146
|
+
function declaredRoles(declared) {
|
|
147
|
+
const roles = Object.keys(declared);
|
|
148
|
+
return roles.length ? `it declares ${roles.map((r) => `"${r}"`).join(', ')}` : 'it declares none';
|
|
149
|
+
}
|
|
150
|
+
const JSON_TYPES = {
|
|
151
|
+
bool: 'boolean',
|
|
152
|
+
int: 'integer',
|
|
153
|
+
uint: 'integer',
|
|
154
|
+
double: 'number',
|
|
155
|
+
string: 'string',
|
|
156
|
+
null: 'null',
|
|
157
|
+
object: 'object',
|
|
158
|
+
};
|
|
134
159
|
/** The JSON Schema of a value of this type, as far as it says */
|
|
135
160
|
function schemaOfType(type) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
case 'uint':
|
|
141
|
-
return { type: 'integer' };
|
|
142
|
-
case 'double':
|
|
143
|
-
return { type: 'number' };
|
|
144
|
-
case 'string':
|
|
145
|
-
return { type: 'string' };
|
|
146
|
-
case 'null':
|
|
147
|
-
return { type: 'null' };
|
|
148
|
-
case 'list':
|
|
149
|
-
return { type: 'array', items: schemaOfType(type.item) };
|
|
150
|
-
case 'object':
|
|
151
|
-
return { type: 'object' };
|
|
152
|
-
default:
|
|
153
|
-
return {};
|
|
154
|
-
}
|
|
161
|
+
if (type.t === 'list')
|
|
162
|
+
return { type: 'array', items: schemaOfType(type.item) };
|
|
163
|
+
const name = JSON_TYPES[type.t];
|
|
164
|
+
return name ? { type: name } : {};
|
|
155
165
|
}
|
|
156
166
|
/**
|
|
157
167
|
* Each of a collection's computed fields as JSON Schema, `readOnly`, for an
|
|
@@ -162,10 +172,8 @@ function schemaOfType(type) {
|
|
|
162
172
|
export function computedSchemas(definition, definitionOf) {
|
|
163
173
|
const computed = definition.computed ?? {};
|
|
164
174
|
const types = typesOfComputed(definition.name, computed, definition.schema, definitionOf);
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
{ ...(typeof types === 'string' ? {} : schemaOfType(types[field] ?? { t: 'dyn' })), readOnly: true },
|
|
168
|
-
]));
|
|
175
|
+
const schemaOf = (field) => typeof types === 'string' ? {} : schemaOfType(types[field] ?? { t: 'dyn' });
|
|
176
|
+
return Object.fromEntries(Object.keys(computed).map((field) => [field, { ...schemaOf(field), readOnly: true }]));
|
|
169
177
|
}
|
|
170
178
|
/**
|
|
171
179
|
* A computed field named like a field of the body's schema, or null. A bare
|
|
@@ -175,11 +183,10 @@ function computedClash(computed, schema, at = 'computed') {
|
|
|
175
183
|
const body = typeOfSchema(schema);
|
|
176
184
|
if (body.t !== 'object')
|
|
177
185
|
return null;
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
return null;
|
|
186
|
+
const field = Object.keys(computed).find((name) => Object.hasOwn(body.fields, name));
|
|
187
|
+
if (field === undefined)
|
|
188
|
+
return null;
|
|
189
|
+
return `${at}.${field}: the body has a field "${field}" too; give the computed field another name`;
|
|
183
190
|
}
|
|
184
191
|
/**
|
|
185
192
|
* A definition's computed fields as everything that reads them takes them:
|
|
@@ -232,7 +239,7 @@ export function linkedReads(fields) {
|
|
|
232
239
|
if (typeof node === 'string')
|
|
233
240
|
continue;
|
|
234
241
|
for (const [collection, rel] of linkedCalls(node))
|
|
235
|
-
reads.set(
|
|
242
|
+
reads.set(linkedKey(collection, rel), { collection, rel });
|
|
236
243
|
}
|
|
237
244
|
return [...reads.values()];
|
|
238
245
|
}
|
|
@@ -251,11 +258,12 @@ export async function causeOf(source, record, fields, holds) {
|
|
|
251
258
|
// Each collection and role looked up once; taking records away filters what was found.
|
|
252
259
|
const found = new Map();
|
|
253
260
|
for (const { collection, rel } of linkedReads(fields)) {
|
|
254
|
-
|
|
261
|
+
const linking = await source.linked(record.key, { rel, collection });
|
|
262
|
+
found.set(linkedKey(collection, rel), linking.filter(readable));
|
|
255
263
|
}
|
|
256
264
|
const gone = new Set();
|
|
257
265
|
const without = {
|
|
258
|
-
linked: async (_key, { rel, collection }) => (found.get(
|
|
266
|
+
linked: async (_key, { rel, collection }) => (found.get(linkedKey(collection, rel)) ?? []).filter((r) => !gone.has(r.key)),
|
|
259
267
|
};
|
|
260
268
|
if (!holds(await computeValues(without, record, fields)))
|
|
261
269
|
return null;
|
|
@@ -301,17 +309,10 @@ export async function computeValues(source, record, fields) {
|
|
|
301
309
|
]);
|
|
302
310
|
// Fields often read the same links: each is looked up once per record.
|
|
303
311
|
const found = new Map();
|
|
304
|
-
const linked = (collection, rel) => {
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
list = source
|
|
309
|
-
.linked(record.key, { rel, collection })
|
|
310
|
-
.then((records) => records.filter(readable).map(asVersion));
|
|
311
|
-
found.set(at, list);
|
|
312
|
-
}
|
|
313
|
-
return list;
|
|
314
|
-
};
|
|
312
|
+
const linked = (collection, rel) => getOrAdd(found, linkedKey(collection, rel), async () => {
|
|
313
|
+
const linking = await source.linked(record.key, { rel, collection });
|
|
314
|
+
return linking.filter(readable).map(asVersion);
|
|
315
|
+
});
|
|
315
316
|
const values = {};
|
|
316
317
|
for (const [name, source] of Object.entries(fields)) {
|
|
317
318
|
const node = parse(source);
|