@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
|
@@ -5,6 +5,7 @@ import { quickAddBody } from '../schema/quick-add.js';
|
|
|
5
5
|
import { schemaProblem } from '../schema/collection-def.js';
|
|
6
6
|
import { isObject } from '../utils/guards.js';
|
|
7
7
|
import { checkCron, cronMatches } from './cron.js';
|
|
8
|
+
import { definedNames } from './defined.js';
|
|
8
9
|
import { about, define, one, person, text, typed, when as moment, words } from './fragments.js';
|
|
9
10
|
export const automation = typed()({
|
|
10
11
|
name: 'std.automation',
|
|
@@ -88,10 +89,10 @@ export function activeNow(body, now = Date.now()) {
|
|
|
88
89
|
* where the space keeps no `std.activity`.
|
|
89
90
|
*/
|
|
90
91
|
export async function setActivity(node, space, on, state, label) {
|
|
91
|
-
if (!(await node
|
|
92
|
+
if (!(await definedNames(node, space)).has(activity.name))
|
|
92
93
|
return null;
|
|
93
|
-
const
|
|
94
|
-
|
|
94
|
+
const mine = await node.records.linked(space, on, { rel: 'about', collection: activity.name });
|
|
95
|
+
const kept = label ?? mine.find((record) => record.root === node.did && !record.deleted)?.body?.label;
|
|
95
96
|
const body = {
|
|
96
97
|
state,
|
|
97
98
|
...(kept ? { label: kept.slice(0, 120) } : {}),
|
|
@@ -181,36 +182,34 @@ export function checkAutomation(value) {
|
|
|
181
182
|
return 'An automation that changes a record needs a when';
|
|
182
183
|
if (typeof value.since !== 'string' || !Number.isFinite(Date.parse(value.since)))
|
|
183
184
|
return 'since must be a date';
|
|
184
|
-
if (value.open !== undefined &&
|
|
185
|
+
if (value.open !== undefined && !isWebAddress(value.open))
|
|
185
186
|
return 'open must be an https:// address';
|
|
186
|
-
if (isObject(value.app) &&
|
|
187
|
+
if (isObject(value.app) && !isOrigin(value.app.origin))
|
|
187
188
|
return 'app.origin must be a web origin';
|
|
188
189
|
return null;
|
|
189
190
|
}
|
|
190
191
|
/** An https:// address, or http:// on this machine */
|
|
191
192
|
function isWebAddress(value) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
return (url.protocol === 'https:' ||
|
|
195
|
-
(url.protocol === 'http:' && ['localhost', '127.0.0.1'].includes(url.hostname)));
|
|
196
|
-
}
|
|
197
|
-
catch {
|
|
198
|
-
return false;
|
|
199
|
-
}
|
|
193
|
+
const url = parseUrl(value);
|
|
194
|
+
return url?.protocol === 'https:' || (url?.protocol === 'http:' && LOCAL_HOSTS.includes(url.hostname));
|
|
200
195
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
*/
|
|
196
|
+
const LOCAL_HOSTS = ['localhost', '127.0.0.1'];
|
|
197
|
+
/** A browser extension's origin, which `URL` gives none */
|
|
198
|
+
const EXTENSION_ORIGIN = /^(chrome|moz|safari-web)-extension:\/\/[a-z0-9-]{1,64}$/i;
|
|
199
|
+
/** `https://chat.example`, nothing after it: what a browser reports as a message's origin */
|
|
206
200
|
function isOrigin(value) {
|
|
207
|
-
if (
|
|
208
|
-
return
|
|
201
|
+
if (typeof value !== 'string')
|
|
202
|
+
return false;
|
|
203
|
+
return EXTENSION_ORIGIN.test(value) || parseUrl(value)?.origin === value;
|
|
204
|
+
}
|
|
205
|
+
function parseUrl(value) {
|
|
206
|
+
if (typeof value !== 'string')
|
|
207
|
+
return null;
|
|
209
208
|
try {
|
|
210
|
-
return new URL(value)
|
|
209
|
+
return new URL(value);
|
|
211
210
|
}
|
|
212
211
|
catch {
|
|
213
|
-
return
|
|
212
|
+
return null;
|
|
214
213
|
}
|
|
215
214
|
}
|
|
216
215
|
const isAutomation = (value) => checkAutomation(value) === null;
|
|
@@ -229,59 +228,75 @@ export function asRunner(value, me) {
|
|
|
229
228
|
export async function matching(node, space, ruleWhen, me, limit = 200) {
|
|
230
229
|
const when = asRunner(ruleWhen, me);
|
|
231
230
|
const query = plainQuery(when.query);
|
|
232
|
-
const counted =
|
|
233
|
-
const include = Object.fromEntries(Object.entries(query.include ?? {}).map(([name, found]) => {
|
|
234
|
-
if (!found.count)
|
|
235
|
-
return [name, found];
|
|
236
|
-
counted.add(name);
|
|
237
|
-
const { count: _count, limit: _limit, ...listed } = found;
|
|
238
|
-
return [name, listed];
|
|
239
|
-
}));
|
|
231
|
+
const { include, counted } = countsAsLists(query.include ?? {});
|
|
240
232
|
const { records } = await node.records.query(space, {
|
|
241
233
|
...query,
|
|
242
234
|
include,
|
|
243
235
|
sort: query.sort ?? { '@updatedAt': 'desc' },
|
|
244
236
|
limit: query.limit ?? limit,
|
|
245
237
|
});
|
|
246
|
-
|
|
247
|
-
const
|
|
248
|
-
const fields = (await node.collections.list(space)).find((c) => c.name === name)?.computed ?? {};
|
|
249
|
-
const named = { ...namedComputed(fields, query.where), ...namedComputed(fields, when.holds) };
|
|
250
|
-
const reads = Object.keys(named).length > 0;
|
|
251
|
-
const source = {
|
|
252
|
-
linked: (key, o) => node.records.linked(space, key, o),
|
|
253
|
-
};
|
|
238
|
+
const holds = (subject) => when.holds === undefined || matches(subject, when.holds);
|
|
239
|
+
const causeIn = await causeFinder(node, space, query, when.holds, holds);
|
|
254
240
|
const found = [];
|
|
255
241
|
for (const record of records) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
for (const [name, value] of Object.entries(record.included)) {
|
|
259
|
-
if (typeof value === 'number') {
|
|
260
|
-
included[name] = value;
|
|
261
|
-
continue;
|
|
262
|
-
}
|
|
263
|
-
for (const one of value)
|
|
264
|
-
latest = Math.max(latest, Date.parse(one.createdAt));
|
|
265
|
-
included[name] = counted.has(name) ? value.length : value;
|
|
266
|
-
}
|
|
267
|
-
if (when.holds !== undefined && !matches({ ...record, included }, when.holds))
|
|
242
|
+
const { included, newest } = readIncluded(record, counted);
|
|
243
|
+
if (!holds({ ...record, included }))
|
|
268
244
|
continue;
|
|
269
|
-
|
|
270
|
-
const cause = reads
|
|
271
|
-
? await causeOf(source, record, named, (computed) => {
|
|
272
|
-
const subject = { ...record, included, computed };
|
|
273
|
-
return (matches(subject, query.where ?? {}) && (when.holds === undefined || matches(subject, when.holds)));
|
|
274
|
-
})
|
|
275
|
-
: record;
|
|
245
|
+
const cause = await causeIn(record, included);
|
|
276
246
|
// What made it hold can't be told: better quiet than set off by the wrong one.
|
|
277
247
|
if (!cause)
|
|
278
248
|
continue;
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
found.push({ record, included, moment: latest, cause });
|
|
249
|
+
const moment = cause === record ? newest : Math.max(newest, Date.parse(cause.updatedAt));
|
|
250
|
+
found.push({ record, included, moment, cause });
|
|
282
251
|
}
|
|
283
252
|
return found;
|
|
284
253
|
}
|
|
254
|
+
/** A query's includes, with those that count turned into lists, and the names of those */
|
|
255
|
+
function countsAsLists(include) {
|
|
256
|
+
const counted = new Set();
|
|
257
|
+
const lists = Object.fromEntries(Object.entries(include).map(([name, found]) => {
|
|
258
|
+
if (!found.count)
|
|
259
|
+
return [name, found];
|
|
260
|
+
counted.add(name);
|
|
261
|
+
const { count: _count, limit: _limit, ...listed } = found;
|
|
262
|
+
return [name, listed];
|
|
263
|
+
}));
|
|
264
|
+
return { include: lists, counted };
|
|
265
|
+
}
|
|
266
|
+
/** What a record's includes found, counted ones as numbers, and the newest moment among it and them */
|
|
267
|
+
function readIncluded(record, counted) {
|
|
268
|
+
let newest = Date.parse(record.updatedAt);
|
|
269
|
+
const included = {};
|
|
270
|
+
for (const [name, value] of Object.entries(record.included)) {
|
|
271
|
+
if (typeof value === 'number') {
|
|
272
|
+
included[name] = value;
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
for (const one of value)
|
|
276
|
+
newest = Math.max(newest, Date.parse(one.createdAt));
|
|
277
|
+
included[name] = counted.has(name) ? value.length : value;
|
|
278
|
+
}
|
|
279
|
+
return { included, newest };
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* How to tell what made a record hold. A computed field the automation reads
|
|
283
|
+
* changes when what it reads is written: a 👍 can make a todo done. It is what
|
|
284
|
+
* made it hold, not what came last: a 😡 after the second 👍 sets nothing off.
|
|
285
|
+
*/
|
|
286
|
+
async function causeFinder(node, space, query, holdsFilter, holds) {
|
|
287
|
+
const name = nameOf(query.collection);
|
|
288
|
+
const fields = (await node.collections.list(space)).find((c) => c.name === name)?.computed ?? {};
|
|
289
|
+
const read = { ...namedComputed(fields, query.where), ...namedComputed(fields, holdsFilter) };
|
|
290
|
+
if (Object.keys(read).length === 0)
|
|
291
|
+
return async (record) => record;
|
|
292
|
+
const source = {
|
|
293
|
+
linked: (key, o) => node.records.linked(space, key, o),
|
|
294
|
+
};
|
|
295
|
+
return (record, included) => causeOf(source, record, read, (computed) => {
|
|
296
|
+
const subject = { ...record, included, computed };
|
|
297
|
+
return matches(subject, query.where ?? {}) && holds(subject);
|
|
298
|
+
});
|
|
299
|
+
}
|
|
285
300
|
/** What a record is called, for `{title}`: its first text among the usual names, or its key */
|
|
286
301
|
function titleOf(record) {
|
|
287
302
|
const body = isObject(record.body) ? record.body : {};
|
|
@@ -310,33 +325,32 @@ export function fillAutomationText(text, match, title = titleOf) {
|
|
|
310
325
|
/** Does what an automation says, as whoever runs it; says what happened */
|
|
311
326
|
export async function act(node, trigger, options = {}) {
|
|
312
327
|
const { automation: active, match } = trigger;
|
|
313
|
-
const space = active.space;
|
|
314
|
-
const body = active.body;
|
|
315
328
|
const at = new Date().toISOString();
|
|
316
|
-
const
|
|
317
|
-
const
|
|
329
|
+
const fill = (template) => fillAutomationText(template, match, options.title);
|
|
330
|
+
const space = active.space;
|
|
331
|
+
const then = active.body.then;
|
|
318
332
|
try {
|
|
319
333
|
switch (then.kind) {
|
|
320
334
|
case 'notify': {
|
|
321
|
-
const
|
|
322
|
-
|
|
335
|
+
const text = fill(then.text);
|
|
336
|
+
const shown = options.notify?.(active.body.name, text, match?.record) ?? false;
|
|
337
|
+
return { did: shown ? `Notified: ${text}` : 'Nothing here could notify', ok: shown, at };
|
|
323
338
|
}
|
|
324
|
-
case 'ask':
|
|
339
|
+
case 'ask':
|
|
325
340
|
if (!options.ask)
|
|
326
341
|
return { did: 'Nothing here can ask an agent', ok: false, at };
|
|
327
342
|
return { ...(await options.ask(trigger)), at };
|
|
328
|
-
}
|
|
329
343
|
case 'add': {
|
|
330
344
|
const collections = await node.collections.list(space);
|
|
331
345
|
const target = collections.find((c) => c.name === then.collection && c.version !== null);
|
|
332
346
|
const thing = (target?.title ?? then.collection.split('.').pop() ?? then.collection).toLowerCase();
|
|
333
|
-
const fresh = target ? quickAddBody(target.schema,
|
|
347
|
+
const fresh = target ? quickAddBody(target.schema, fill(then.text)) : null;
|
|
334
348
|
if (!target || !fresh)
|
|
335
349
|
return { did: `This space can't add a ${thing} from a line of text`, ok: false, at };
|
|
336
350
|
// Without a record, as when the time set it off, a link to it has nothing to point at.
|
|
337
351
|
const links = (then.links ?? []).flatMap((l) => l.to !== IT ? [l] : match ? [{ rel: l.rel, to: match.record.key }] : []);
|
|
338
352
|
const made = await node.records.put(space, target.name, fresh, { links });
|
|
339
|
-
return { did: `Added a ${thing}: ${
|
|
353
|
+
return { did: `Added a ${thing}: ${fill(then.text)}`, ok: true, at, made: made.key };
|
|
340
354
|
}
|
|
341
355
|
case 'set': {
|
|
342
356
|
const current = match ? await node.records.get(space, match.record.key) : null;
|
|
@@ -346,7 +360,7 @@ export async function act(node, trigger, options = {}) {
|
|
|
346
360
|
if (!(await node.records.can(space, 'edit', current.key)))
|
|
347
361
|
return { did: 'Only whoever made it can change it', ok: false, at };
|
|
348
362
|
await node.records.update(space, current.key, { ...was, [then.field]: then.value });
|
|
349
|
-
return { did: `${
|
|
363
|
+
return { did: `${fill('“{title}”')}: set ${then.field} to ${String(then.value)}`, ok: true, at };
|
|
350
364
|
}
|
|
351
365
|
}
|
|
352
366
|
}
|
|
@@ -357,9 +371,12 @@ export async function act(node, trigger, options = {}) {
|
|
|
357
371
|
/** Whether someone holds one of these roles; `member` is any place at all, and a founder holds every role's power */
|
|
358
372
|
const holdsOneOf = (access, did, names) => {
|
|
359
373
|
const member = access?.members.find((one) => one.did === did);
|
|
360
|
-
|
|
361
|
-
|
|
374
|
+
if (!member)
|
|
375
|
+
return false;
|
|
376
|
+
return member.founder || names.includes('member') || member.roles.some((role) => names.includes(role));
|
|
362
377
|
};
|
|
378
|
+
/** Whether an automation can run where `options` are: one that asks needs an agent */
|
|
379
|
+
const runnable = (active, options) => active.body.then.kind !== 'ask' || !!options.ask;
|
|
363
380
|
/**
|
|
364
381
|
* The automations in a space that `account` runs, none paused and none whose
|
|
365
382
|
* current version an agent wrote: those it made without `by`, and those
|
|
@@ -374,22 +391,28 @@ export async function automationsFor(node, space, account, access) {
|
|
|
374
391
|
// A key given records only, an agent's, may suggest an automation; it runs once the person saves it themselves.
|
|
375
392
|
if (!record.verified || record.recordsOnly || !maker || !body || body.paused)
|
|
376
393
|
continue;
|
|
377
|
-
|
|
378
|
-
? maker === account
|
|
379
|
-
: body.by === account &&
|
|
380
|
-
(maker === account ||
|
|
381
|
-
(!!access?.members.some((member) => member.did === maker) &&
|
|
382
|
-
(await node.spaces.may(space, INSTRUCT, {}, maker))));
|
|
383
|
-
if (runs)
|
|
394
|
+
if (await runsIt(node, space, account, maker, body.by, access))
|
|
384
395
|
active.push({ space, key: record.key, maker, body });
|
|
385
396
|
}
|
|
386
397
|
return active;
|
|
387
398
|
}
|
|
399
|
+
/** Whether `account` runs an automation: its own without `by`, or one naming it whose maker may instruct it */
|
|
400
|
+
async function runsIt(node, space, account, maker, by, access) {
|
|
401
|
+
if (by === undefined)
|
|
402
|
+
return maker === account;
|
|
403
|
+
if (by !== account)
|
|
404
|
+
return false;
|
|
405
|
+
if (maker === account)
|
|
406
|
+
return true;
|
|
407
|
+
const isMember = access?.members.some((member) => member.did === maker) ?? false;
|
|
408
|
+
return isMember && node.spaces.may(space, INSTRUCT, {}, maker);
|
|
409
|
+
}
|
|
388
410
|
/** How many automations in a space an agent wrote for `account`, waiting for the person to save them */
|
|
389
411
|
export async function suggestedAutomations(node, space, account) {
|
|
390
412
|
const records = await node.records.list(space, { collection: automation.name });
|
|
391
413
|
return records.filter((record) => record.createdBy === account && record.recordsOnly).length;
|
|
392
414
|
}
|
|
415
|
+
const linkTo = (record, rel) => record.links.find((l) => l.rel === rel)?.to;
|
|
393
416
|
/** The records each automation has run for, by automation key, and the records automations wrote */
|
|
394
417
|
async function runsIn(node, space) {
|
|
395
418
|
const by = new Map();
|
|
@@ -397,13 +420,12 @@ async function runsIn(node, space) {
|
|
|
397
420
|
for (const run of await node.records.list(space, { collection: automationRun.name })) {
|
|
398
421
|
if (isObject(run.body) && typeof run.body.made === 'string')
|
|
399
422
|
made.add(run.body.made);
|
|
400
|
-
const ran = run
|
|
401
|
-
const on = run
|
|
423
|
+
const ran = linkTo(run, 'automation');
|
|
424
|
+
const on = linkTo(run, 'about');
|
|
402
425
|
if (!ran || !on)
|
|
403
426
|
continue;
|
|
404
427
|
const seen = by.get(ran) ?? new Set();
|
|
405
|
-
seen.add(on);
|
|
406
|
-
by.set(ran, seen);
|
|
428
|
+
by.set(ran, seen.add(on));
|
|
407
429
|
}
|
|
408
430
|
return { by, made };
|
|
409
431
|
}
|
|
@@ -412,75 +434,51 @@ async function runsIn(node, space) {
|
|
|
412
434
|
* claim a record before either hears the other; after a wait, the earlier
|
|
413
435
|
* claim (by time, then key) acts and the later is taken back.
|
|
414
436
|
*/
|
|
415
|
-
async function
|
|
437
|
+
async function actsFirst(node, space, mine, wait) {
|
|
416
438
|
if (wait <= 0)
|
|
417
439
|
return true;
|
|
418
440
|
await new Promise((resolve) => setTimeout(resolve, wait));
|
|
419
|
-
const ran = mine
|
|
420
|
-
const on = mine
|
|
441
|
+
const ran = linkTo(mine, 'automation');
|
|
442
|
+
const on = linkTo(mine, 'about');
|
|
421
443
|
if (!ran || !on)
|
|
422
444
|
return true;
|
|
423
|
-
const
|
|
424
|
-
const
|
|
445
|
+
const runs = await node.records.linked(space, on, { rel: 'about', collection: automationRun.name });
|
|
446
|
+
const claims = runs.filter((run) => run.links.some((l) => l.rel === 'automation' && l.to === ran));
|
|
447
|
+
const earliest = claims.sort((a, b) => a.createdAt.localeCompare(b.createdAt) || a.key.localeCompare(b.key))[0];
|
|
425
448
|
if (!earliest || earliest.key === mine.key)
|
|
426
449
|
return true;
|
|
427
450
|
await node.records.delete(space, mine.key).catch(() => { });
|
|
428
451
|
return false;
|
|
429
452
|
}
|
|
430
453
|
/**
|
|
431
|
-
* Runs, once, every automation `account` runs in a space: acts for each record
|
|
432
|
-
* automation newly holds for, and leaves a run for it. `startAutomations`
|
|
433
|
-
* records change; a device can call it itself.
|
|
454
|
+
* Runs, once, every automation `account` runs in a space: acts for each record
|
|
455
|
+
* an automation newly holds for, and leaves a run for it. `startAutomations`
|
|
456
|
+
* calls it when records change; a device can call it itself.
|
|
434
457
|
*/
|
|
435
458
|
export async function runAutomations(node, space, account, options = {}) {
|
|
436
|
-
const
|
|
437
|
-
|
|
438
|
-
if (!defined(automation.name) || !defined(automationRun.name))
|
|
459
|
+
const defined = await definedNames(node, space);
|
|
460
|
+
if (!defined.has(automation.name) || !defined.has(automationRun.name))
|
|
439
461
|
return;
|
|
440
462
|
const access = await node.spaces.access(space).catch(() => undefined);
|
|
441
|
-
const rules = (await automationsFor(node, space, account, access)).filter((r) => r.body.when && (r
|
|
463
|
+
const rules = (await automationsFor(node, space, account, access)).filter((r) => r.body.when && runnable(r, options));
|
|
442
464
|
if (rules.length === 0)
|
|
443
465
|
return;
|
|
444
466
|
const busy = options.busy ?? new Set();
|
|
445
467
|
const { by: runs, made } = await runsIn(node, space);
|
|
446
468
|
for (const active of rules) {
|
|
447
469
|
const when = active.body.when;
|
|
448
|
-
if (!defined(nameOf(when.query.collection)))
|
|
470
|
+
if (!when || !defined.has(nameOf(when.query.collection)))
|
|
449
471
|
continue;
|
|
450
472
|
const since = Date.parse(active.body.since);
|
|
451
473
|
for (const match of await matching(node, space, when, account)) {
|
|
452
|
-
const
|
|
453
|
-
const
|
|
454
|
-
const
|
|
455
|
-
|
|
456
|
-
if (match.moment < since ||
|
|
457
|
-
made.has(record.key) ||
|
|
458
|
-
runs.get(active.key)?.has(record.key) ||
|
|
459
|
-
busy.has(claim))
|
|
460
|
-
continue;
|
|
461
|
-
// What the runner's agent, or the bot, wrote itself never sets an automation off: an agent asked to act can't set itself off.
|
|
462
|
-
if (by === account && (cause.recordsOnly || options.bot))
|
|
463
|
-
continue;
|
|
464
|
-
if (when.from && !holdsOneOf(access, by ?? '', when.from))
|
|
465
|
-
continue;
|
|
466
|
-
if (when.others && by === account)
|
|
474
|
+
const key = match.record.key;
|
|
475
|
+
const claim = `${active.key} ${key}`;
|
|
476
|
+
const handled = made.has(key) || runs.get(active.key)?.has(key) || busy.has(claim);
|
|
477
|
+
if (match.moment < since || handled || !setsOff(match, when, account, access, options.bot))
|
|
467
478
|
continue;
|
|
468
479
|
busy.add(claim);
|
|
469
480
|
try {
|
|
470
|
-
|
|
471
|
-
{ rel: 'automation', to: active.key },
|
|
472
|
-
{ rel: 'about', to: record.key },
|
|
473
|
-
];
|
|
474
|
-
// Claimed first, so a second look while this acts leaves it alone.
|
|
475
|
-
const run = await node.records.put(space, automationRun.name, { did: 'Running…', ok: true, at: new Date().toISOString() }, { links });
|
|
476
|
-
if (!(await first(node, space, run, options.claimMs ?? 0)))
|
|
477
|
-
continue;
|
|
478
|
-
const trigger = { automation: active, match };
|
|
479
|
-
const done = await act(node, trigger, options);
|
|
480
|
-
if (done.made)
|
|
481
|
-
made.add(done.made);
|
|
482
|
-
await node.records.update(space, run.key, done, { links });
|
|
483
|
-
options.onRun?.(trigger, done);
|
|
481
|
+
await claimAndAct(node, active, match, options, made);
|
|
484
482
|
}
|
|
485
483
|
finally {
|
|
486
484
|
busy.delete(claim);
|
|
@@ -488,6 +486,35 @@ export async function runAutomations(node, space, account, options = {}) {
|
|
|
488
486
|
}
|
|
489
487
|
}
|
|
490
488
|
}
|
|
489
|
+
/** Whether whoever made a match hold may set the automation off for its runner */
|
|
490
|
+
function setsOff(match, when, account, access, bot) {
|
|
491
|
+
const cause = match.cause ?? match.record;
|
|
492
|
+
const by = cause.createdBy ?? cause.root;
|
|
493
|
+
// What the runner's agent, or the bot, wrote itself never sets an automation off: it would set itself off.
|
|
494
|
+
if (by === account && (cause.recordsOnly || bot))
|
|
495
|
+
return false;
|
|
496
|
+
if (when.from && !holdsOneOf(access, by ?? '', when.from))
|
|
497
|
+
return false;
|
|
498
|
+
return !(when.others && by === account);
|
|
499
|
+
}
|
|
500
|
+
/** Claims the record with a run first, so a second look leaves it alone, then acts and fills the run in */
|
|
501
|
+
async function claimAndAct(node, active, match, options, made) {
|
|
502
|
+
const space = active.space;
|
|
503
|
+
const links = [
|
|
504
|
+
{ rel: 'automation', to: active.key },
|
|
505
|
+
{ rel: 'about', to: match.record.key },
|
|
506
|
+
];
|
|
507
|
+
const claim = { did: 'Running…', ok: true, at: new Date().toISOString() };
|
|
508
|
+
const run = await node.records.put(space, automationRun.name, claim, { links });
|
|
509
|
+
if (!(await actsFirst(node, space, run, options.claimMs ?? 0)))
|
|
510
|
+
return;
|
|
511
|
+
const trigger = { automation: active, match };
|
|
512
|
+
const done = await act(node, trigger, options);
|
|
513
|
+
if (done.made)
|
|
514
|
+
made.add(done.made);
|
|
515
|
+
await node.records.update(space, run.key, done, { links });
|
|
516
|
+
options.onRun?.(trigger, done);
|
|
517
|
+
}
|
|
491
518
|
/**
|
|
492
519
|
* Runs the automations `account` runs, in every space it follows, until stopped:
|
|
493
520
|
* once at the start, after each change in a space, and at the times automations
|
|
@@ -499,6 +526,7 @@ export function startAutomations(node, options) {
|
|
|
499
526
|
const now = options.now ?? (() => new Date());
|
|
500
527
|
let stopped = false;
|
|
501
528
|
let spaces = [];
|
|
529
|
+
/** The automations it runs, by space */
|
|
502
530
|
const kept = new Map();
|
|
503
531
|
let shown = null;
|
|
504
532
|
let running = null;
|
|
@@ -506,39 +534,49 @@ export function startAutomations(node, options) {
|
|
|
506
534
|
const dirty = new Set([null]);
|
|
507
535
|
/** The minute each timed automation last ran, so it runs once in it */
|
|
508
536
|
const ranAt = new Map();
|
|
509
|
-
const
|
|
537
|
+
const allKept = () => [...kept.values()].flat();
|
|
510
538
|
async function run() {
|
|
511
539
|
while (dirty.size && !stopped) {
|
|
512
540
|
const changed = [...dirty];
|
|
513
541
|
dirty.clear();
|
|
514
542
|
try {
|
|
515
|
-
if (changed
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
if (!spaces.includes(space))
|
|
519
|
-
kept.delete(space);
|
|
520
|
-
const looking = changed.includes(null)
|
|
521
|
-
? spaces
|
|
522
|
-
: changed.filter((s) => !!s && spaces.includes(s));
|
|
523
|
-
for (const space of looking) {
|
|
524
|
-
if (stopped)
|
|
525
|
-
return;
|
|
526
|
-
const access = await node.spaces.access(space).catch(() => undefined);
|
|
527
|
-
kept.set(space, (await automationsFor(node, space, account, access)).filter(runnable));
|
|
528
|
-
await runAutomations(node, space, account, { ...options, busy });
|
|
529
|
-
}
|
|
530
|
-
const all = [...kept.values()].flat();
|
|
531
|
-
const names = all.map((r) => `${r.space}/${r.key}/${r.body.name}`).join();
|
|
532
|
-
if (names !== shown) {
|
|
533
|
-
shown = names;
|
|
534
|
-
options.onRules?.(all);
|
|
535
|
-
}
|
|
543
|
+
if (!(await look(changed)))
|
|
544
|
+
return;
|
|
545
|
+
announce();
|
|
536
546
|
}
|
|
537
547
|
catch (error) {
|
|
538
548
|
options.onError?.(error);
|
|
539
549
|
}
|
|
540
550
|
}
|
|
541
551
|
}
|
|
552
|
+
/** Runs the automations of the spaces that changed; false when stopped part way */
|
|
553
|
+
async function look(changed) {
|
|
554
|
+
const everySpace = changed.includes(null);
|
|
555
|
+
if (everySpace)
|
|
556
|
+
spaces = (await node.spaces.list()).map((space) => space.id);
|
|
557
|
+
for (const space of kept.keys())
|
|
558
|
+
if (!spaces.includes(space))
|
|
559
|
+
kept.delete(space);
|
|
560
|
+
const looking = everySpace ? spaces : changed.filter((s) => !!s && spaces.includes(s));
|
|
561
|
+
for (const space of looking) {
|
|
562
|
+
if (stopped)
|
|
563
|
+
return false;
|
|
564
|
+
const access = await node.spaces.access(space).catch(() => undefined);
|
|
565
|
+
const rules = await automationsFor(node, space, account, access);
|
|
566
|
+
kept.set(space, rules.filter((r) => runnable(r, options)));
|
|
567
|
+
await runAutomations(node, space, account, { ...options, busy });
|
|
568
|
+
}
|
|
569
|
+
return true;
|
|
570
|
+
}
|
|
571
|
+
/** Tells `onRules` the automations it runs, when they changed */
|
|
572
|
+
function announce() {
|
|
573
|
+
const all = allKept();
|
|
574
|
+
const names = all.map((r) => `${r.space}/${r.key}/${r.body.name}`).join();
|
|
575
|
+
if (names === shown)
|
|
576
|
+
return;
|
|
577
|
+
shown = names;
|
|
578
|
+
options.onRules?.(all);
|
|
579
|
+
}
|
|
542
580
|
function kick() {
|
|
543
581
|
running ??= run().finally(() => {
|
|
544
582
|
running = null;
|
|
@@ -546,6 +584,20 @@ export function startAutomations(node, options) {
|
|
|
546
584
|
kick();
|
|
547
585
|
});
|
|
548
586
|
}
|
|
587
|
+
/** Runs each timed automation that names this minute, once in it */
|
|
588
|
+
function tick() {
|
|
589
|
+
const at = now();
|
|
590
|
+
const minute = `${at.getFullYear()}-${at.getMonth()}-${at.getDate()} ${at.getHours()}:${at.getMinutes()}`;
|
|
591
|
+
for (const active of allKept()) {
|
|
592
|
+
const every = active.body.every;
|
|
593
|
+
const id = `${active.space}/${active.key}`;
|
|
594
|
+
if (!every || ranAt.get(id) === minute || !cronMatches(every, at))
|
|
595
|
+
continue;
|
|
596
|
+
ranAt.set(id, minute);
|
|
597
|
+
const trigger = { automation: active, at };
|
|
598
|
+
void act(node, trigger, options).then((done) => options.onRun?.(trigger, done), (error) => options.onError?.(error));
|
|
599
|
+
}
|
|
600
|
+
}
|
|
549
601
|
const unsubscribe = node.subscribe((event) => {
|
|
550
602
|
if (event.type === 'spaces' || event.type === 'account')
|
|
551
603
|
dirty.add(null);
|
|
@@ -556,25 +608,11 @@ export function startAutomations(node, options) {
|
|
|
556
608
|
kick();
|
|
557
609
|
});
|
|
558
610
|
kick();
|
|
559
|
-
const
|
|
560
|
-
? undefined
|
|
561
|
-
: setInterval(() => {
|
|
562
|
-
const at = now();
|
|
563
|
-
const minute = `${at.getFullYear()}-${at.getMonth()}-${at.getDate()} ${at.getHours()}:${at.getMinutes()}`;
|
|
564
|
-
for (const active of [...kept.values()].flat()) {
|
|
565
|
-
const every = active.body.every;
|
|
566
|
-
const id = `${active.space}/${active.key}`;
|
|
567
|
-
if (!every || ranAt.get(id) === minute || !cronMatches(every, at))
|
|
568
|
-
continue;
|
|
569
|
-
ranAt.set(id, minute);
|
|
570
|
-
const trigger = { automation: active, at };
|
|
571
|
-
void act(node, trigger, options).then((done) => options.onRun?.(trigger, done), (error) => options.onError?.(error));
|
|
572
|
-
}
|
|
573
|
-
}, options.tickMs ?? 15_000);
|
|
611
|
+
const timer = options.timed === false ? undefined : setInterval(tick, options.tickMs ?? 15_000);
|
|
574
612
|
return () => {
|
|
575
613
|
stopped = true;
|
|
576
|
-
if (
|
|
577
|
-
clearInterval(
|
|
614
|
+
if (timer)
|
|
615
|
+
clearInterval(timer);
|
|
578
616
|
unsubscribe();
|
|
579
617
|
};
|
|
580
618
|
}
|