@weaveprotocol/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1106 -0
- package/dist/elements/auth-styles.d.ts +18 -0
- package/dist/elements/auth-styles.d.ts.map +1 -0
- package/dist/elements/auth-styles.js +150 -0
- package/dist/elements/auth-styles.js.map +1 -0
- package/dist/elements/dom.d.ts +28 -0
- package/dist/elements/dom.d.ts.map +1 -0
- package/dist/elements/dom.js +74 -0
- package/dist/elements/dom.js.map +1 -0
- package/dist/elements/index.d.ts +13 -0
- package/dist/elements/index.d.ts.map +1 -0
- package/dist/elements/index.js +11 -0
- package/dist/elements/index.js.map +1 -0
- package/dist/elements/weave-auth.d.ts +52 -0
- package/dist/elements/weave-auth.d.ts.map +1 -0
- package/dist/elements/weave-auth.js +427 -0
- package/dist/elements/weave-auth.js.map +1 -0
- package/dist/identity/account-store.d.ts +113 -0
- package/dist/identity/account-store.d.ts.map +1 -0
- package/dist/identity/account-store.js +305 -0
- package/dist/identity/account-store.js.map +1 -0
- package/dist/identity/account-vault.d.ts +199 -0
- package/dist/identity/account-vault.d.ts.map +1 -0
- package/dist/identity/account-vault.js +251 -0
- package/dist/identity/account-vault.js.map +1 -0
- package/dist/identity/agent-note.d.ts +19 -0
- package/dist/identity/agent-note.d.ts.map +1 -0
- package/dist/identity/agent-note.js +29 -0
- package/dist/identity/agent-note.js.map +1 -0
- package/dist/identity/crypto-p256.d.ts +7 -0
- package/dist/identity/crypto-p256.d.ts.map +1 -0
- package/dist/identity/crypto-p256.js +84 -0
- package/dist/identity/crypto-p256.js.map +1 -0
- package/dist/identity/device-key.d.ts +60 -0
- package/dist/identity/device-key.d.ts.map +1 -0
- package/dist/identity/device-key.js +103 -0
- package/dist/identity/device-key.js.map +1 -0
- package/dist/identity/did.d.ts +22 -0
- package/dist/identity/did.d.ts.map +1 -0
- package/dist/identity/did.js +37 -0
- package/dist/identity/did.js.map +1 -0
- package/dist/identity/folder-account.d.ts +65 -0
- package/dist/identity/folder-account.d.ts.map +1 -0
- package/dist/identity/folder-account.js +115 -0
- package/dist/identity/folder-account.js.map +1 -0
- package/dist/identity/identity-manager.d.ts +36 -0
- package/dist/identity/identity-manager.d.ts.map +1 -0
- package/dist/identity/identity-manager.js +115 -0
- package/dist/identity/identity-manager.js.map +1 -0
- package/dist/identity/index.d.ts +10 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/identity/index.js +10 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/identity/keys.d.ts +24 -0
- package/dist/identity/keys.d.ts.map +1 -0
- package/dist/identity/keys.js +38 -0
- package/dist/identity/keys.js.map +1 -0
- package/dist/identity/pairing.d.ts +83 -0
- package/dist/identity/pairing.d.ts.map +1 -0
- package/dist/identity/pairing.js +120 -0
- package/dist/identity/pairing.js.map +1 -0
- package/dist/identity/passkey-diagnostics.d.ts +54 -0
- package/dist/identity/passkey-diagnostics.d.ts.map +1 -0
- package/dist/identity/passkey-diagnostics.js +178 -0
- package/dist/identity/passkey-diagnostics.js.map +1 -0
- package/dist/identity/recovery-code.d.ts +50 -0
- package/dist/identity/recovery-code.d.ts.map +1 -0
- package/dist/identity/recovery-code.js +116 -0
- package/dist/identity/recovery-code.js.map +1 -0
- package/dist/identity/root-signer.d.ts +59 -0
- package/dist/identity/root-signer.d.ts.map +1 -0
- package/dist/identity/root-signer.js +44 -0
- package/dist/identity/root-signer.js.map +1 -0
- package/dist/identity/ucan.d.ts +164 -0
- package/dist/identity/ucan.d.ts.map +1 -0
- package/dist/identity/ucan.js +273 -0
- package/dist/identity/ucan.js.map +1 -0
- package/dist/identity/webauthn.d.ts +87 -0
- package/dist/identity/webauthn.d.ts.map +1 -0
- package/dist/identity/webauthn.js +155 -0
- package/dist/identity/webauthn.js.map +1 -0
- package/dist/index.d.ts +116 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -0
- package/dist/network/index.d.ts +17 -0
- package/dist/network/index.d.ts.map +1 -0
- package/dist/network/index.js +10 -0
- package/dist/network/index.js.map +1 -0
- package/dist/network/introductions.d.ts +85 -0
- package/dist/network/introductions.d.ts.map +1 -0
- package/dist/network/introductions.js +94 -0
- package/dist/network/introductions.js.map +1 -0
- package/dist/network/local-transport.d.ts +22 -0
- package/dist/network/local-transport.d.ts.map +1 -0
- package/dist/network/local-transport.js +55 -0
- package/dist/network/local-transport.js.map +1 -0
- package/dist/network/mesh.d.ts +31 -0
- package/dist/network/mesh.d.ts.map +1 -0
- package/dist/network/mesh.js +332 -0
- package/dist/network/mesh.js.map +1 -0
- package/dist/network/multi-signaling.d.ts +29 -0
- package/dist/network/multi-signaling.d.ts.map +1 -0
- package/dist/network/multi-signaling.js +125 -0
- package/dist/network/multi-signaling.js.map +1 -0
- package/dist/network/network-manager.d.ts +37 -0
- package/dist/network/network-manager.d.ts.map +1 -0
- package/dist/network/network-manager.js +64 -0
- package/dist/network/network-manager.js.map +1 -0
- package/dist/network/peer-auth.d.ts +98 -0
- package/dist/network/peer-auth.d.ts.map +1 -0
- package/dist/network/peer-auth.js +86 -0
- package/dist/network/peer-auth.js.map +1 -0
- package/dist/network/rtc-transport.d.ts +18 -0
- package/dist/network/rtc-transport.d.ts.map +1 -0
- package/dist/network/rtc-transport.js +149 -0
- package/dist/network/rtc-transport.js.map +1 -0
- package/dist/network/signaling.d.ts +40 -0
- package/dist/network/signaling.d.ts.map +1 -0
- package/dist/network/signaling.js +124 -0
- package/dist/network/signaling.js.map +1 -0
- package/dist/network/transport.d.ts +50 -0
- package/dist/network/transport.d.ts.map +1 -0
- package/dist/network/transport.js +13 -0
- package/dist/network/transport.js.map +1 -0
- package/dist/network/ws-transport.d.ts +42 -0
- package/dist/network/ws-transport.d.ts.map +1 -0
- package/dist/network/ws-transport.js +194 -0
- package/dist/network/ws-transport.js.map +1 -0
- package/dist/node/actions.d.ts +62 -0
- package/dist/node/actions.d.ts.map +1 -0
- package/dist/node/actions.js +500 -0
- package/dist/node/actions.js.map +1 -0
- package/dist/node/carrier.d.ts +85 -0
- package/dist/node/carrier.d.ts.map +1 -0
- package/dist/node/carrier.js +192 -0
- package/dist/node/carrier.js.map +1 -0
- package/dist/node/copy.d.ts +38 -0
- package/dist/node/copy.d.ts.map +1 -0
- package/dist/node/copy.js +53 -0
- package/dist/node/copy.js.map +1 -0
- package/dist/node/index.d.ts +16 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +11 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/node.d.ts +12 -0
- package/dist/node/node.d.ts.map +1 -0
- package/dist/node/node.js +872 -0
- package/dist/node/node.js.map +1 -0
- package/dist/node/space-runtime.d.ts +144 -0
- package/dist/node/space-runtime.d.ts.map +1 -0
- package/dist/node/space-runtime.js +1221 -0
- package/dist/node/space-runtime.js.map +1 -0
- package/dist/node/stores.d.ts +45 -0
- package/dist/node/stores.d.ts.map +1 -0
- package/dist/node/stores.js +31 -0
- package/dist/node/stores.js.map +1 -0
- package/dist/node/types.d.ts +508 -0
- package/dist/node/types.d.ts.map +1 -0
- package/dist/node/types.js +2 -0
- package/dist/node/types.js.map +1 -0
- package/dist/privacy/index.d.ts +4 -0
- package/dist/privacy/index.d.ts.map +1 -0
- package/dist/privacy/index.js +4 -0
- package/dist/privacy/index.js.map +1 -0
- package/dist/privacy/key-distribution.d.ts +42 -0
- package/dist/privacy/key-distribution.d.ts.map +1 -0
- package/dist/privacy/key-distribution.js +50 -0
- package/dist/privacy/key-distribution.js.map +1 -0
- package/dist/privacy/privacy-guard.d.ts +24 -0
- package/dist/privacy/privacy-guard.d.ts.map +1 -0
- package/dist/privacy/privacy-guard.js +87 -0
- package/dist/privacy/privacy-guard.js.map +1 -0
- package/dist/privacy/space-encryption.d.ts +48 -0
- package/dist/privacy/space-encryption.d.ts.map +1 -0
- package/dist/privacy/space-encryption.js +61 -0
- package/dist/privacy/space-encryption.js.map +1 -0
- package/dist/query/engine.d.ts +27 -0
- package/dist/query/engine.d.ts.map +1 -0
- package/dist/query/engine.js +84 -0
- package/dist/query/engine.js.map +1 -0
- package/dist/query/filter.d.ts +15 -0
- package/dist/query/filter.d.ts.map +1 -0
- package/dist/query/filter.js +207 -0
- package/dist/query/filter.js.map +1 -0
- package/dist/query/types.d.ts +144 -0
- package/dist/query/types.d.ts.map +1 -0
- package/dist/query/types.js +22 -0
- package/dist/query/types.js.map +1 -0
- package/dist/react/context.d.ts +81 -0
- package/dist/react/context.d.ts.map +1 -0
- package/dist/react/context.js +95 -0
- package/dist/react/context.js.map +1 -0
- package/dist/react/index.d.ts +40 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +36 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/use-live.d.ts +16 -0
- package/dist/react/use-live.d.ts.map +1 -0
- package/dist/react/use-live.js +55 -0
- package/dist/react/use-live.js.map +1 -0
- package/dist/react/use-query.d.ts +17 -0
- package/dist/react/use-query.d.ts.map +1 -0
- package/dist/react/use-query.js +23 -0
- package/dist/react/use-query.js.map +1 -0
- package/dist/react/use-space.d.ts +29 -0
- package/dist/react/use-space.d.ts.map +1 -0
- package/dist/react/use-space.js +48 -0
- package/dist/react/use-space.js.map +1 -0
- package/dist/react/use-spaces.d.ts +19 -0
- package/dist/react/use-spaces.d.ts.map +1 -0
- package/dist/react/use-spaces.js +55 -0
- package/dist/react/use-spaces.js.map +1 -0
- package/dist/react/use-weave-auth.d.ts +10 -0
- package/dist/react/use-weave-auth.d.ts.map +1 -0
- package/dist/react/use-weave-auth.js +15 -0
- package/dist/react/use-weave-auth.js.map +1 -0
- package/dist/react/weave-auth.d.ts +17 -0
- package/dist/react/weave-auth.d.ts.map +1 -0
- package/dist/react/weave-auth.js +38 -0
- package/dist/react/weave-auth.js.map +1 -0
- package/dist/records/describe.d.ts +38 -0
- package/dist/records/describe.d.ts.map +1 -0
- package/dist/records/describe.js +101 -0
- package/dist/records/describe.js.map +1 -0
- package/dist/records/links.d.ts +14 -0
- package/dist/records/links.d.ts.map +1 -0
- package/dist/records/links.js +25 -0
- package/dist/records/links.js.map +1 -0
- package/dist/records/rules.d.ts +59 -0
- package/dist/records/rules.d.ts.map +1 -0
- package/dist/records/rules.js +118 -0
- package/dist/records/rules.js.map +1 -0
- package/dist/records/version.d.ts +54 -0
- package/dist/records/version.d.ts.map +1 -0
- package/dist/records/version.js +70 -0
- package/dist/records/version.js.map +1 -0
- package/dist/schema/collection-def.d.ts +96 -0
- package/dist/schema/collection-def.d.ts.map +1 -0
- package/dist/schema/collection-def.js +272 -0
- package/dist/schema/collection-def.js.map +1 -0
- package/dist/schema/expression.d.ts +69 -0
- package/dist/schema/expression.d.ts.map +1 -0
- package/dist/schema/expression.js +92 -0
- package/dist/schema/expression.js.map +1 -0
- package/dist/schema/index.d.ts +4 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +4 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/schema-engine.d.ts +42 -0
- package/dist/schema/schema-engine.d.ts.map +1 -0
- package/dist/schema/schema-engine.js +36 -0
- package/dist/schema/schema-engine.js.map +1 -0
- package/dist/schema/signer.d.ts +27 -0
- package/dist/schema/signer.d.ts.map +1 -0
- package/dist/schema/signer.js +36 -0
- package/dist/schema/signer.js.map +1 -0
- package/dist/schemas/apps.d.ts +88 -0
- package/dist/schemas/apps.d.ts.map +1 -0
- package/dist/schemas/apps.js +168 -0
- package/dist/schemas/apps.js.map +1 -0
- package/dist/schemas/index.d.ts +410 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +208 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/screens.d.ts +67 -0
- package/dist/schemas/screens.d.ts.map +1 -0
- package/dist/schemas/screens.js +242 -0
- package/dist/schemas/screens.js.map +1 -0
- package/dist/session/agent-link.d.ts +79 -0
- package/dist/session/agent-link.d.ts.map +1 -0
- package/dist/session/agent-link.js +251 -0
- package/dist/session/agent-link.js.map +1 -0
- package/dist/session/auth.d.ts +233 -0
- package/dist/session/auth.d.ts.map +1 -0
- package/dist/session/auth.js +783 -0
- package/dist/session/auth.js.map +1 -0
- package/dist/session/connect.d.ts +211 -0
- package/dist/session/connect.d.ts.map +1 -0
- package/dist/session/connect.js +355 -0
- package/dist/session/connect.js.map +1 -0
- package/dist/session/connection.d.ts +70 -0
- package/dist/session/connection.d.ts.map +1 -0
- package/dist/session/connection.js +120 -0
- package/dist/session/connection.js.map +1 -0
- package/dist/session/credentials.d.ts +44 -0
- package/dist/session/credentials.d.ts.map +1 -0
- package/dist/session/credentials.js +60 -0
- package/dist/session/credentials.js.map +1 -0
- package/dist/session/index.d.ts +25 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +18 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/pairing.d.ts +59 -0
- package/dist/session/pairing.d.ts.map +1 -0
- package/dist/session/pairing.js +144 -0
- package/dist/session/pairing.js.map +1 -0
- package/dist/session/places.d.ts +62 -0
- package/dist/session/places.d.ts.map +1 -0
- package/dist/session/places.js +101 -0
- package/dist/session/places.js.map +1 -0
- package/dist/session/stay-signed-in.d.ts +37 -0
- package/dist/session/stay-signed-in.d.ts.map +1 -0
- package/dist/session/stay-signed-in.js +124 -0
- package/dist/session/stay-signed-in.js.map +1 -0
- package/dist/space/account-registry.d.ts +64 -0
- package/dist/space/account-registry.d.ts.map +1 -0
- package/dist/space/account-registry.js +66 -0
- package/dist/space/account-registry.js.map +1 -0
- package/dist/space/index.d.ts +3 -0
- package/dist/space/index.d.ts.map +1 -0
- package/dist/space/index.js +3 -0
- package/dist/space/index.js.map +1 -0
- package/dist/space/pass.d.ts +63 -0
- package/dist/space/pass.d.ts.map +1 -0
- package/dist/space/pass.js +54 -0
- package/dist/space/pass.js.map +1 -0
- package/dist/space/presets.d.ts +31 -0
- package/dist/space/presets.d.ts.map +1 -0
- package/dist/space/presets.js +24 -0
- package/dist/space/presets.js.map +1 -0
- package/dist/space/roles.d.ts +186 -0
- package/dist/space/roles.d.ts.map +1 -0
- package/dist/space/roles.js +500 -0
- package/dist/space/roles.js.map +1 -0
- package/dist/space/space-access.d.ts +80 -0
- package/dist/space/space-access.d.ts.map +1 -0
- package/dist/space/space-access.js +135 -0
- package/dist/space/space-access.js.map +1 -0
- package/dist/space/space-manager.d.ts +87 -0
- package/dist/space/space-manager.d.ts.map +1 -0
- package/dist/space/space-manager.js +187 -0
- package/dist/space/space-manager.js.map +1 -0
- package/dist/storage/directory-access.d.ts +78 -0
- package/dist/storage/directory-access.d.ts.map +1 -0
- package/dist/storage/directory-access.js +164 -0
- package/dist/storage/directory-access.js.map +1 -0
- package/dist/storage/encrypted-adapter.d.ts +49 -0
- package/dist/storage/encrypted-adapter.d.ts.map +1 -0
- package/dist/storage/encrypted-adapter.js +106 -0
- package/dist/storage/encrypted-adapter.js.map +1 -0
- package/dist/storage/folder-adapter.d.ts +105 -0
- package/dist/storage/folder-adapter.d.ts.map +1 -0
- package/dist/storage/folder-adapter.js +280 -0
- package/dist/storage/folder-adapter.js.map +1 -0
- package/dist/storage/folder-reconcile.d.ts +53 -0
- package/dist/storage/folder-reconcile.d.ts.map +1 -0
- package/dist/storage/folder-reconcile.js +65 -0
- package/dist/storage/folder-reconcile.js.map +1 -0
- package/dist/storage/index.d.ts +10 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +9 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/indexeddb-adapter.d.ts +12 -0
- package/dist/storage/indexeddb-adapter.d.ts.map +1 -0
- package/dist/storage/indexeddb-adapter.js +190 -0
- package/dist/storage/indexeddb-adapter.js.map +1 -0
- package/dist/storage/mst.d.ts +121 -0
- package/dist/storage/mst.d.ts.map +1 -0
- package/dist/storage/mst.js +402 -0
- package/dist/storage/mst.js.map +1 -0
- package/dist/storage/storage-provider.d.ts +85 -0
- package/dist/storage/storage-provider.d.ts.map +1 -0
- package/dist/storage/storage-provider.js +220 -0
- package/dist/storage/storage-provider.js.map +1 -0
- package/dist/sync/anti-entropy.d.ts +49 -0
- package/dist/sync/anti-entropy.d.ts.map +1 -0
- package/dist/sync/anti-entropy.js +62 -0
- package/dist/sync/anti-entropy.js.map +1 -0
- package/dist/sync/index.d.ts +4 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +4 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/sync-engine.d.ts +71 -0
- package/dist/sync/sync-engine.d.ts.map +1 -0
- package/dist/sync/sync-engine.js +309 -0
- package/dist/sync/sync-engine.js.map +1 -0
- package/dist/sync/sync-messages.d.ts +75 -0
- package/dist/sync/sync-messages.d.ts.map +1 -0
- package/dist/sync/sync-messages.js +12 -0
- package/dist/sync/sync-messages.js.map +1 -0
- package/dist/types.d.ts +243 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/encoding.d.ts +63 -0
- package/dist/utils/encoding.d.ts.map +1 -0
- package/dist/utils/encoding.js +130 -0
- package/dist/utils/encoding.js.map +1 -0
- package/dist/utils/errors.d.ts +43 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +28 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/events.d.ts +19 -0
- package/dist/utils/events.d.ts.map +1 -0
- package/dist/utils/events.js +27 -0
- package/dist/utils/events.js.map +1 -0
- package/dist/utils/hash.d.ts +23 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/utils/hash.js +49 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +9 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/validation/capability-gate.d.ts +50 -0
- package/dist/validation/capability-gate.d.ts.map +1 -0
- package/dist/validation/capability-gate.js +71 -0
- package/dist/validation/capability-gate.js.map +1 -0
- package/dist/validation/crypto-gate.d.ts +16 -0
- package/dist/validation/crypto-gate.d.ts.map +1 -0
- package/dist/validation/crypto-gate.js +37 -0
- package/dist/validation/crypto-gate.js.map +1 -0
- package/dist/validation/index.d.ts +6 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +6 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/stateful-gate.d.ts +15 -0
- package/dist/validation/stateful-gate.d.ts.map +1 -0
- package/dist/validation/stateful-gate.js +50 -0
- package/dist/validation/stateful-gate.js.map +1 -0
- package/dist/validation/structural-gate.d.ts +18 -0
- package/dist/validation/structural-gate.d.ts.map +1 -0
- package/dist/validation/structural-gate.js +54 -0
- package/dist/validation/structural-gate.js.map +1 -0
- package/dist/validation/validation-engine.d.ts +28 -0
- package/dist/validation/validation-engine.d.ts.map +1 -0
- package/dist/validation/validation-engine.js +38 -0
- package/dist/validation/validation-engine.js.map +1 -0
- package/package.json +107 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module query/types
|
|
3
|
+
* A query is plain data: an object you could write by hand, send over a wire,
|
|
4
|
+
* or have an agent produce. No parser, no language — filters borrow Mongo's
|
|
5
|
+
* operators, relationships borrow the `include` map that Prisma, Mongoose and
|
|
6
|
+
* Rails all use, and anything that serialises keeps working the day a daemon
|
|
7
|
+
* answers queries instead of the tab.
|
|
8
|
+
*/
|
|
9
|
+
import type { NodeRecord } from '../node/types.js';
|
|
10
|
+
/** Predicates on one field. Absent operators do not constrain. */
|
|
11
|
+
export interface Operators {
|
|
12
|
+
readonly $eq?: unknown;
|
|
13
|
+
/** True for a missing field too — the one everybody gets wrong */
|
|
14
|
+
readonly $ne?: unknown;
|
|
15
|
+
readonly $gt?: number | string;
|
|
16
|
+
readonly $gte?: number | string;
|
|
17
|
+
readonly $lt?: number | string;
|
|
18
|
+
readonly $lte?: number | string;
|
|
19
|
+
readonly $in?: ReadonlyArray<unknown>;
|
|
20
|
+
readonly $nin?: ReadonlyArray<unknown>;
|
|
21
|
+
readonly $exists?: boolean;
|
|
22
|
+
/** Case-insensitive substring of a text field, or an element of a list. Not search. */
|
|
23
|
+
readonly $contains?: unknown;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Field predicates, all of which must hold.
|
|
27
|
+
*
|
|
28
|
+
* A bare name is a field of the record's body — `done`, `address.city`. A
|
|
29
|
+
* name starting with `@` is about the record itself: `@key`, `@author`,
|
|
30
|
+
* `@root`, `@createdBy`, `@createdAt`, `@updatedAt`, `@seq`.
|
|
31
|
+
*/
|
|
32
|
+
export type Filter = {
|
|
33
|
+
readonly [field: string]: unknown;
|
|
34
|
+
} & {
|
|
35
|
+
readonly $and?: ReadonlyArray<Filter>;
|
|
36
|
+
readonly $or?: ReadonlyArray<Filter>;
|
|
37
|
+
readonly $not?: Filter;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* A collection, by name or by a reference that also carries its records'
|
|
41
|
+
* type: a definition whose schema is a validator (a Zod object), a standard
|
|
42
|
+
* one from `@weaveprotocol/core/schemas`, or a {@link Typed} name. Before a query
|
|
43
|
+
* runs, every reference becomes its name — the query stays plain data.
|
|
44
|
+
*/
|
|
45
|
+
export type CollectionRef = string | {
|
|
46
|
+
readonly name: string;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* A collection name that carries its records' type, for collections whose
|
|
50
|
+
* schema is plain JSON Schema: `const todos: Typed<Todo> = { name: 'app.todo' }`.
|
|
51
|
+
* The type is a promise you make, not something checked when reading.
|
|
52
|
+
*/
|
|
53
|
+
export interface Typed<T> {
|
|
54
|
+
readonly name: string;
|
|
55
|
+
readonly '~body'?: T;
|
|
56
|
+
}
|
|
57
|
+
/** A validator's output type, when it declares one (Standard Schema) */
|
|
58
|
+
type OutputOf<S> = S extends {
|
|
59
|
+
readonly '~standard': {
|
|
60
|
+
readonly types?: infer Types;
|
|
61
|
+
};
|
|
62
|
+
} ? NonNullable<Types> extends {
|
|
63
|
+
readonly output: infer O;
|
|
64
|
+
} ? O : unknown : unknown;
|
|
65
|
+
/**
|
|
66
|
+
* The body type of a collection reference: declared with {@link Typed}, or
|
|
67
|
+
* the output of its definition's validator. `unknown` for a bare name.
|
|
68
|
+
*/
|
|
69
|
+
export type BodyOf<C> = C extends {
|
|
70
|
+
readonly '~body'?: infer T;
|
|
71
|
+
} ? (unknown extends T ? FromSchema<C> : T) : FromSchema<C>;
|
|
72
|
+
type FromSchema<C> = C extends {
|
|
73
|
+
readonly schema: infer S;
|
|
74
|
+
} ? OutputOf<S> : unknown;
|
|
75
|
+
/**
|
|
76
|
+
* What an `include` map finds for each record, typed from the query. A map
|
|
77
|
+
* only known as "some includes" (a query built at run time) gives the loose
|
|
78
|
+
* {@link AnyIncluded}.
|
|
79
|
+
*/
|
|
80
|
+
export type IncludedOf<I> = [I] extends [undefined] ? {} : string extends keyof NonNullable<I> ? AnyIncluded : {
|
|
81
|
+
readonly [K in keyof NonNullable<I>]: NonNullable<I>[K] extends {
|
|
82
|
+
readonly count: true;
|
|
83
|
+
} ? number : ReadonlyArray<QueryRecord<BodyOf<NonNullable<I>[K] extends {
|
|
84
|
+
readonly from?: infer F;
|
|
85
|
+
} ? F : never>, IncludedOf<NonNullable<I>[K] extends {
|
|
86
|
+
readonly include?: infer J;
|
|
87
|
+
} ? J : undefined>>>;
|
|
88
|
+
};
|
|
89
|
+
/** What to pull in alongside each record, by following links. */
|
|
90
|
+
export interface Include {
|
|
91
|
+
/** The link role: 'about', 'replyTo' */
|
|
92
|
+
readonly rel: string;
|
|
93
|
+
/** Only records in this collection — by name, or a reference that carries its type */
|
|
94
|
+
readonly from?: CollectionRef;
|
|
95
|
+
/** `in` (default): records linking *to* this one. `out`: records this one links to. */
|
|
96
|
+
readonly direction?: 'in' | 'out';
|
|
97
|
+
readonly where?: Filter;
|
|
98
|
+
readonly include?: Readonly<Record<string, Include>>;
|
|
99
|
+
readonly limit?: number;
|
|
100
|
+
/** Just the number of them — the usual thing for reactions and votes */
|
|
101
|
+
readonly count?: boolean;
|
|
102
|
+
}
|
|
103
|
+
export type SortDirection = 'asc' | 'desc';
|
|
104
|
+
export interface Query {
|
|
105
|
+
/** By name, or a reference that carries its records' type (see {@link CollectionRef}) */
|
|
106
|
+
readonly collection: CollectionRef;
|
|
107
|
+
readonly where?: Filter;
|
|
108
|
+
readonly include?: Readonly<Record<string, Include>>;
|
|
109
|
+
/** Fields to sort by, in order: `{ done: 'asc', '@createdAt': 'desc' }`. Ties always break on the key. */
|
|
110
|
+
readonly sort?: Readonly<Record<string, SortDirection>>;
|
|
111
|
+
readonly limit?: number;
|
|
112
|
+
/** From the previous page's `cursor` */
|
|
113
|
+
readonly cursor?: string;
|
|
114
|
+
}
|
|
115
|
+
/** What an untyped query's `include` finds */
|
|
116
|
+
export type AnyIncluded = Readonly<Record<string, ReadonlyArray<QueryRecord> | number>>;
|
|
117
|
+
/**
|
|
118
|
+
* A record a query found. Queries only return records this device can read,
|
|
119
|
+
* so `body` is never null here.
|
|
120
|
+
*/
|
|
121
|
+
export interface QueryRecord<T = unknown, I = AnyIncluded> extends Omit<NodeRecord<T>, 'body'> {
|
|
122
|
+
readonly body: T;
|
|
123
|
+
/** What each `include` found: records, or a number when it asked for a count. Empty without `include`. */
|
|
124
|
+
readonly included: I;
|
|
125
|
+
}
|
|
126
|
+
export interface QueryResult<T = unknown, I = AnyIncluded> {
|
|
127
|
+
readonly records: ReadonlyArray<QueryRecord<T, I>>;
|
|
128
|
+
/** Pass back as `cursor` for the next page; null when there is none */
|
|
129
|
+
readonly cursor: string | null;
|
|
130
|
+
}
|
|
131
|
+
/** The result a query gives, typed from the query itself */
|
|
132
|
+
export type ResultOf<Q extends Query> = QueryResult<BodyOf<Q['collection']>, Q extends {
|
|
133
|
+
readonly include: infer I;
|
|
134
|
+
} ? IncludedOf<I> : 'include' extends keyof Q ? AnyIncluded : {}>;
|
|
135
|
+
/** The name a collection reference stands for */
|
|
136
|
+
export declare const nameOf: (ref: CollectionRef) => string;
|
|
137
|
+
/**
|
|
138
|
+
* The query as plain data: every collection reference replaced by its name.
|
|
139
|
+
* What runs, what is sent to an agent, and what is compared, is this.
|
|
140
|
+
* Anything malformed is passed through untouched, for the checker to explain.
|
|
141
|
+
*/
|
|
142
|
+
export declare function plainQuery(query: Query): Query;
|
|
143
|
+
export {};
|
|
144
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/query/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,kEAAkE;AAClE,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IACvB,kEAAkE;IAClE,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAChC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAChC,QAAQ,CAAC,GAAG,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;IACtC,QAAQ,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;IACvC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,uFAAuF;IACvF,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED;;;;;;GAMG;AACH,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;CACnC,GAAG;IACF,QAAQ,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACtC,QAAQ,CAAC,GAAG,CAAC,EAAE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G,EAAE,CACvG,CAAC;AAEF,iDAAiD;AACjD,eAAO,MAAM,MAAM,GAAI,KAAK,aAAa,KAAG,MAAgH,CAAC;AAE7J;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAe9C"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** The name a collection reference stands for */
|
|
2
|
+
export const nameOf = (ref) => (typeof ref === 'object' && ref !== null && typeof ref.name === 'string' ? ref.name : ref);
|
|
3
|
+
/**
|
|
4
|
+
* The query as plain data: every collection reference replaced by its name.
|
|
5
|
+
* What runs, what is sent to an agent, and what is compared, is this.
|
|
6
|
+
* Anything malformed is passed through untouched, for the checker to explain.
|
|
7
|
+
*/
|
|
8
|
+
export function plainQuery(query) {
|
|
9
|
+
const isObject = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
10
|
+
const includes = (map) => isObject(map)
|
|
11
|
+
? Object.fromEntries(Object.entries(map).map(([name, inc]) => [
|
|
12
|
+
name,
|
|
13
|
+
isObject(inc)
|
|
14
|
+
? { ...inc, ...(inc.from !== undefined ? { from: nameOf(inc.from) } : {}), ...(inc.include !== undefined ? { include: includes(inc.include) } : {}) }
|
|
15
|
+
: inc,
|
|
16
|
+
]))
|
|
17
|
+
: map;
|
|
18
|
+
if (!isObject(query))
|
|
19
|
+
return query;
|
|
20
|
+
return { ...query, collection: nameOf(query.collection), ...(query.include !== undefined ? { include: includes(query.include) } : {}) };
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/query/types.ts"],"names":[],"mappings":"AAmJA,iDAAiD;AACjD,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,GAAkB,EAAU,EAAE,CAAC,CAAC,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK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,CAAC,KAAK,CAAC,OAAO,CAAqB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AAC9J,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from 'react';
|
|
2
|
+
import type { AuthState, WeaveAuth, WeaveSession } from '../session/auth.js';
|
|
3
|
+
import type { ConnectionState, WeaveConnection } from '../session/connection.js';
|
|
4
|
+
import type { P2PNode } from '../node/types.js';
|
|
5
|
+
export type WeaveProviderProps = {
|
|
6
|
+
readonly children?: ReactNode;
|
|
7
|
+
} & (
|
|
8
|
+
/** The account itself, signed in on this site — an account home */
|
|
9
|
+
{
|
|
10
|
+
readonly auth: WeaveAuth;
|
|
11
|
+
readonly connection?: undefined;
|
|
12
|
+
readonly node?: undefined;
|
|
13
|
+
}
|
|
14
|
+
/** An app acting for an account through its home — `createWeaveConnection` */
|
|
15
|
+
| {
|
|
16
|
+
readonly connection: WeaveConnection;
|
|
17
|
+
readonly auth?: undefined;
|
|
18
|
+
readonly node?: undefined;
|
|
19
|
+
}
|
|
20
|
+
/** A node you started yourself */
|
|
21
|
+
| {
|
|
22
|
+
readonly node: P2PNode;
|
|
23
|
+
readonly auth?: undefined;
|
|
24
|
+
readonly connection?: undefined;
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* Makes Weave available to every component below it, so they ask for what
|
|
28
|
+
* they need — `useNode()`, `useQuery(space, …)` — instead of having it passed
|
|
29
|
+
* down.
|
|
30
|
+
*
|
|
31
|
+
* ```tsx
|
|
32
|
+
* <WeaveProvider connection={connection}> // an app, through an account home
|
|
33
|
+
* <WeaveProvider auth={auth}> // the home itself
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function WeaveProvider(props: WeaveProviderProps): ReactElement;
|
|
37
|
+
/** The sign-in flow from the nearest `WeaveProvider`, and its state — or nulls, for an app that connects instead. */
|
|
38
|
+
export declare function useWeave(): {
|
|
39
|
+
auth: WeaveAuth | null;
|
|
40
|
+
state: AuthState | null;
|
|
41
|
+
session: WeaveSession | null;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* The sign-in flow and its state, for screens that manage the account —
|
|
45
|
+
* `auth.signOut()`, `auth.addPasskey()`, `state.entry`.
|
|
46
|
+
* @throws Outside a `WeaveProvider` given `auth`
|
|
47
|
+
*/
|
|
48
|
+
export declare function useAuth(): {
|
|
49
|
+
auth: WeaveAuth;
|
|
50
|
+
state: AuthState;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Who is signed in: the account, its identity, and its node.
|
|
54
|
+
* @throws Outside a `WeaveProvider` given `auth`, or before sign-in
|
|
55
|
+
*/
|
|
56
|
+
export declare function useSession(): WeaveSession;
|
|
57
|
+
/**
|
|
58
|
+
* An app's connection to its account home, and its state — for the connect
|
|
59
|
+
* button, and for "access ran out, connect again".
|
|
60
|
+
* @throws Outside a `WeaveProvider` given `connection`
|
|
61
|
+
*/
|
|
62
|
+
export declare function useConnection(): {
|
|
63
|
+
connection: WeaveConnection;
|
|
64
|
+
state: ConnectionState;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* The account this page acts for — signed in here, or connected through a
|
|
68
|
+
* home: its identity (what `root` and `createdBy` on a record name) and name.
|
|
69
|
+
* @throws Before sign-in or connecting
|
|
70
|
+
*/
|
|
71
|
+
export declare function useAccount(): {
|
|
72
|
+
did: string;
|
|
73
|
+
name: string;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* The node acting for the account. For components that only appear once
|
|
77
|
+
* someone is in.
|
|
78
|
+
* @throws Outside a `WeaveProvider`, or before sign-in or connecting
|
|
79
|
+
*/
|
|
80
|
+
export declare function useNode(): P2PNode;
|
|
81
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/react/context.ts"],"names":[],"mappings":"AAAA,OAAO,EA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AAE,SAAS,CAAA;CAAE,CAI/D;AAED;;;GAGG;AACH,wBAAgB,UAAU,IAAI,YAAY,CAIzC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI;IAAE,UAAU,EAAE,eAAe,CAAC;IAAC,KAAK,EAAE,eAAe,CAAA;CAAE,CASvF;AAED;;;;GAIG;AACH,wBAAgB,UAAU,IAAI;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAW1D;AAED;;;;GAIG;AACH,wBAAgB,OAAO,IAAI,OAAO,CAIjC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { createContext, createElement, useContext, useEffect, useSyncExternalStore } from 'react';
|
|
2
|
+
const WeaveContext = createContext({ auth: null, connection: null, node: null });
|
|
3
|
+
const nothing = () => null;
|
|
4
|
+
const never = () => () => { };
|
|
5
|
+
/** Follows a flow's or a connection's state, and starts it; null when there is none. */
|
|
6
|
+
function useStore(store) {
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
void store?.start();
|
|
9
|
+
}, [store]);
|
|
10
|
+
return useSyncExternalStore(store ? store.subscribe : never, store ? store.getState : nothing, store ? store.getState : nothing);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Makes Weave available to every component below it, so they ask for what
|
|
14
|
+
* they need — `useNode()`, `useQuery(space, …)` — instead of having it passed
|
|
15
|
+
* down.
|
|
16
|
+
*
|
|
17
|
+
* ```tsx
|
|
18
|
+
* <WeaveProvider connection={connection}> // an app, through an account home
|
|
19
|
+
* <WeaveProvider auth={auth}> // the home itself
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function WeaveProvider(props) {
|
|
23
|
+
const auth = props.auth ?? null;
|
|
24
|
+
const connection = props.connection ?? null;
|
|
25
|
+
const authState = useStore(auth);
|
|
26
|
+
const connectionState = useStore(connection);
|
|
27
|
+
const node = props.node ?? authState?.session?.node ?? (connectionState?.status === 'ready' ? connectionState.node : null);
|
|
28
|
+
return createElement(WeaveContext.Provider, { value: { auth, connection, node } }, props.children);
|
|
29
|
+
}
|
|
30
|
+
/** The sign-in flow from the nearest `WeaveProvider`, and its state — or nulls, for an app that connects instead. */
|
|
31
|
+
export function useWeave() {
|
|
32
|
+
const { auth } = useContext(WeaveContext);
|
|
33
|
+
const state = useSyncExternalStore(auth ? auth.subscribe : never, auth ? auth.getState : nothing, auth ? auth.getState : nothing);
|
|
34
|
+
return { auth, state, session: state?.session ?? null };
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The sign-in flow and its state, for screens that manage the account —
|
|
38
|
+
* `auth.signOut()`, `auth.addPasskey()`, `state.entry`.
|
|
39
|
+
* @throws Outside a `WeaveProvider` given `auth`
|
|
40
|
+
*/
|
|
41
|
+
export function useAuth() {
|
|
42
|
+
const { auth, state } = useWeave();
|
|
43
|
+
if (!auth || !state)
|
|
44
|
+
throw new Error('useAuth needs a WeaveProvider with an auth flow above it.');
|
|
45
|
+
return { auth, state };
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Who is signed in: the account, its identity, and its node.
|
|
49
|
+
* @throws Outside a `WeaveProvider` given `auth`, or before sign-in
|
|
50
|
+
*/
|
|
51
|
+
export function useSession() {
|
|
52
|
+
const { session } = useWeave();
|
|
53
|
+
if (!session)
|
|
54
|
+
throw new Error('useSession needs someone signed in.');
|
|
55
|
+
return session;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* An app's connection to its account home, and its state — for the connect
|
|
59
|
+
* button, and for "access ran out, connect again".
|
|
60
|
+
* @throws Outside a `WeaveProvider` given `connection`
|
|
61
|
+
*/
|
|
62
|
+
export function useConnection() {
|
|
63
|
+
const { connection } = useContext(WeaveContext);
|
|
64
|
+
const state = useSyncExternalStore(connection ? connection.subscribe : never, connection ? connection.getState : nothing, connection ? connection.getState : nothing);
|
|
65
|
+
if (!connection || !state)
|
|
66
|
+
throw new Error('useConnection needs a WeaveProvider with a connection above it.');
|
|
67
|
+
return { connection, state };
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The account this page acts for — signed in here, or connected through a
|
|
71
|
+
* home: its identity (what `root` and `createdBy` on a record name) and name.
|
|
72
|
+
* @throws Before sign-in or connecting
|
|
73
|
+
*/
|
|
74
|
+
export function useAccount() {
|
|
75
|
+
const { auth, connection } = useContext(WeaveContext);
|
|
76
|
+
const authState = useSyncExternalStore(auth ? auth.subscribe : never, auth ? auth.getState : nothing, auth ? auth.getState : nothing);
|
|
77
|
+
const connectionState = useSyncExternalStore(connection ? connection.subscribe : never, connection ? connection.getState : nothing, connection ? connection.getState : nothing);
|
|
78
|
+
if (authState?.session)
|
|
79
|
+
return { did: authState.session.did, name: authState.session.account.name };
|
|
80
|
+
if (connectionState?.grant)
|
|
81
|
+
return { did: connectionState.grant.did, name: connectionState.grant.name };
|
|
82
|
+
throw new Error('useAccount needs someone signed in or connected.');
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The node acting for the account. For components that only appear once
|
|
86
|
+
* someone is in.
|
|
87
|
+
* @throws Outside a `WeaveProvider`, or before sign-in or connecting
|
|
88
|
+
*/
|
|
89
|
+
export function useNode() {
|
|
90
|
+
const { node } = useContext(WeaveContext);
|
|
91
|
+
if (!node)
|
|
92
|
+
throw new Error('useNode needs a signed-in or connected WeaveProvider above it.');
|
|
93
|
+
return node;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/react/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,oBAAoB,EAAqC,MAAM,OAAO,CAAC;AAWrI,MAAM,YAAY,GAAG,aAAa,CAAoB,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;A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;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO;IACrB,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IAC1C,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;IAC7F,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module react
|
|
3
|
+
* React bindings: follow the sign-in flow, draw it, and keep what you read from
|
|
4
|
+
* a space live as records sync in.
|
|
5
|
+
*
|
|
6
|
+
* ```tsx
|
|
7
|
+
* const auth = createWeaveAuth({ network: { relays } });
|
|
8
|
+
*
|
|
9
|
+
* function Root() {
|
|
10
|
+
* return <WeaveProvider auth={auth}><App /></WeaveProvider>;
|
|
11
|
+
* }
|
|
12
|
+
*
|
|
13
|
+
* function App() {
|
|
14
|
+
* const { state } = useWeave();
|
|
15
|
+
* if (state?.stage !== 'ready') return <WeaveAuth auth={auth} />;
|
|
16
|
+
* return <Todos space={…} />;
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* function Todos({ space }) {
|
|
20
|
+
* const { result } = useQuery(space, { collection: 'app.todo.item', sort: { '@createdAt': 'asc' } });
|
|
21
|
+
* const node = useNode(); // to write: node.records.put(space, 'app.todo.item', { text })
|
|
22
|
+
* …
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* `react` is a peer dependency: this entry point is the only part of the
|
|
27
|
+
* protocol that imports it.
|
|
28
|
+
*/
|
|
29
|
+
export { WeaveProvider, useWeave, useAuth, useSession, useConnection, useAccount, useNode } from './context.js';
|
|
30
|
+
export type { WeaveProviderProps } from './context.js';
|
|
31
|
+
export { useWeaveAuth } from './use-weave-auth.js';
|
|
32
|
+
export { WeaveAuth } from './weave-auth.js';
|
|
33
|
+
export type { WeaveAuthProps } from './weave-auth.js';
|
|
34
|
+
export { useLive } from './use-live.js';
|
|
35
|
+
export { useQuery } from './use-query.js';
|
|
36
|
+
export type { QueryState } from './use-query.js';
|
|
37
|
+
export { useSpaces } from './use-spaces.js';
|
|
38
|
+
export type { SpacesState } from './use-spaces.js';
|
|
39
|
+
export { useOpenSpace, useRecord, useLinked, useCollections, useProfiles, useAccess, useSpaceStatus, useCan } from './use-space.js';
|
|
40
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAChH,YAAY,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module react
|
|
3
|
+
* React bindings: follow the sign-in flow, draw it, and keep what you read from
|
|
4
|
+
* a space live as records sync in.
|
|
5
|
+
*
|
|
6
|
+
* ```tsx
|
|
7
|
+
* const auth = createWeaveAuth({ network: { relays } });
|
|
8
|
+
*
|
|
9
|
+
* function Root() {
|
|
10
|
+
* return <WeaveProvider auth={auth}><App /></WeaveProvider>;
|
|
11
|
+
* }
|
|
12
|
+
*
|
|
13
|
+
* function App() {
|
|
14
|
+
* const { state } = useWeave();
|
|
15
|
+
* if (state?.stage !== 'ready') return <WeaveAuth auth={auth} />;
|
|
16
|
+
* return <Todos space={…} />;
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* function Todos({ space }) {
|
|
20
|
+
* const { result } = useQuery(space, { collection: 'app.todo.item', sort: { '@createdAt': 'asc' } });
|
|
21
|
+
* const node = useNode(); // to write: node.records.put(space, 'app.todo.item', { text })
|
|
22
|
+
* …
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* `react` is a peer dependency: this entry point is the only part of the
|
|
27
|
+
* protocol that imports it.
|
|
28
|
+
*/
|
|
29
|
+
export { WeaveProvider, useWeave, useAuth, useSession, useConnection, useAccount, useNode } from './context.js';
|
|
30
|
+
export { useWeaveAuth } from './use-weave-auth.js';
|
|
31
|
+
export { WeaveAuth } from './weave-auth.js';
|
|
32
|
+
export { useLive } from './use-live.js';
|
|
33
|
+
export { useQuery } from './use-query.js';
|
|
34
|
+
export { useSpaces } from './use-spaces.js';
|
|
35
|
+
export { useOpenSpace, useRecord, useLinked, useCollections, useProfiles, useAccess, useSpaceStatus, useCan } from './use-space.js';
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEhH,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { P2PNode } from '../node/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Loads something from a space, and loads it again whenever that space's
|
|
4
|
+
* records or connection change — locally or by sync. One load at a time; a
|
|
5
|
+
* change during a load triggers one more, never a queue of stale ones.
|
|
6
|
+
*
|
|
7
|
+
* The named hooks (`useRecord`, `useCollections`, …) cover the usual reads;
|
|
8
|
+
* this is for anything else.
|
|
9
|
+
*
|
|
10
|
+
* @param spaceId The space to follow
|
|
11
|
+
* @param load What to read, given the node
|
|
12
|
+
* @param deps When these change, start over
|
|
13
|
+
* @returns The latest value, or undefined until the first load finishes
|
|
14
|
+
*/
|
|
15
|
+
export declare function useLive<T>(spaceId: string, load: (node: P2PNode) => Promise<T>, deps: ReadonlyArray<unknown>): T | undefined;
|
|
16
|
+
//# sourceMappingURL=use-live.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-live.d.ts","sourceRoot":"","sources":["../../src/react/use-live.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAGhD;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,SAAS,CAqC5H"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { useNode } from './context.js';
|
|
3
|
+
/**
|
|
4
|
+
* Loads something from a space, and loads it again whenever that space's
|
|
5
|
+
* records or connection change — locally or by sync. One load at a time; a
|
|
6
|
+
* change during a load triggers one more, never a queue of stale ones.
|
|
7
|
+
*
|
|
8
|
+
* The named hooks (`useRecord`, `useCollections`, …) cover the usual reads;
|
|
9
|
+
* this is for anything else.
|
|
10
|
+
*
|
|
11
|
+
* @param spaceId The space to follow
|
|
12
|
+
* @param load What to read, given the node
|
|
13
|
+
* @param deps When these change, start over
|
|
14
|
+
* @returns The latest value, or undefined until the first load finishes
|
|
15
|
+
*/
|
|
16
|
+
export function useLive(spaceId, load, deps) {
|
|
17
|
+
const node = useNode();
|
|
18
|
+
const [value, setValue] = useState(undefined);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
let stopped = false;
|
|
21
|
+
let running = false;
|
|
22
|
+
let again = false;
|
|
23
|
+
const run = async () => {
|
|
24
|
+
if (running) {
|
|
25
|
+
again = true;
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
running = true;
|
|
29
|
+
do {
|
|
30
|
+
again = false;
|
|
31
|
+
try {
|
|
32
|
+
const next = await load(node);
|
|
33
|
+
if (!stopped)
|
|
34
|
+
setValue(next);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
console.warn('useLive:', error);
|
|
38
|
+
}
|
|
39
|
+
} while (again && !stopped);
|
|
40
|
+
running = false;
|
|
41
|
+
};
|
|
42
|
+
void run();
|
|
43
|
+
const unsubscribe = node.subscribe((event) => {
|
|
44
|
+
if ('space' in event && event.space === spaceId)
|
|
45
|
+
void run();
|
|
46
|
+
});
|
|
47
|
+
return () => {
|
|
48
|
+
stopped = true;
|
|
49
|
+
unsubscribe();
|
|
50
|
+
};
|
|
51
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
52
|
+
}, [node, spaceId, ...deps]);
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=use-live.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-live.js","sourceRoot":"","sources":["../../src/react/use-live.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,OAAO,CAAI,OAAe,EAAE,IAAmC,EAAE,IAA4B;IAC3G,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;IACvB,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAgB,SAAS,CAAC,CAAC;IAE7D,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,IAAI,KAAK,GAAG,KAAK,CAAC;QAClB,MAAM,GAAG,GAAG,KAAK,IAAI,EAAE;YACrB,IAAI,OAAO,EAAE,CAAC;gBACZ,KAAK,GAAG,IAAI,CAAC;gBACb,OAAO;YACT,CAAC;YACD,OAAO,GAAG,IAAI,CAAC;YACf,GAAG,CAAC;gBACF,KAAK,GAAG,KAAK,CAAC;gBACd,IAAI,CAAC;oBACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC;oBAC9B,IAAI,CAAC,OAAO;wBAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;gBAC/B,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;gBAClC,CAAC;YACH,CAAC,QAAQ,KAAK,IAAI,CAAC,OAAO,EAAE;YAC5B,OAAO,GAAG,KAAK,CAAC;QAClB,CAAC,CAAC;QACF,KAAK,GAAG,EAAE,CAAC;QACX,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;YAC3C,IAAI,OAAO,IAAI,KAAK,IAAI,KAAK,CAAC,KAAK,KAAK,OAAO;gBAAE,KAAK,GAAG,EAAE,CAAC;QAC9D,CAAC,CAAC,CAAC;QACH,OAAO,GAAG,EAAE;YACV,OAAO,GAAG,IAAI,CAAC;YACf,WAAW,EAAE,CAAC;QAChB,CAAC,CAAC;QACF,uDAAuD;IACzD,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;IAE7B,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Query, type ResultOf } from '../query/types.js';
|
|
2
|
+
export interface QueryState<R> {
|
|
3
|
+
/** The latest result, or null until the first one arrives */
|
|
4
|
+
readonly result: R | null;
|
|
5
|
+
/** Why the query failed — usually a malformed query, saying what to fix */
|
|
6
|
+
readonly error: Error | null;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Runs a query and keeps it current as records change, locally or by sync.
|
|
10
|
+
* The query is plain data, compared by value, so writing it inline is fine.
|
|
11
|
+
* Name the collection by its definition and the result comes back typed.
|
|
12
|
+
*
|
|
13
|
+
* @param spaceId The space to query
|
|
14
|
+
* @param query What to find
|
|
15
|
+
*/
|
|
16
|
+
export declare function useQuery<const Q extends Query>(spaceId: string, query: Q): QueryState<ResultOf<Q>>;
|
|
17
|
+
//# sourceMappingURL=use-query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-query.d.ts","sourceRoot":"","sources":["../../src/react/use-query.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,KAAK,KAAK,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAG1E,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,6DAA6D;IAC7D,QAAQ,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC;IAC1B,2EAA2E;IAC3E,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CAC9B;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,KAAK,CAAC,CAAC,SAAS,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAiBlG"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { plainQuery } from '../query/types.js';
|
|
3
|
+
import { useNode } from './context.js';
|
|
4
|
+
/**
|
|
5
|
+
* Runs a query and keeps it current as records change, locally or by sync.
|
|
6
|
+
* The query is plain data, compared by value, so writing it inline is fine.
|
|
7
|
+
* Name the collection by its definition and the result comes back typed.
|
|
8
|
+
*
|
|
9
|
+
* @param spaceId The space to query
|
|
10
|
+
* @param query What to find
|
|
11
|
+
*/
|
|
12
|
+
export function useQuery(spaceId, query) {
|
|
13
|
+
const node = useNode();
|
|
14
|
+
const [state, setState] = useState({ result: null, error: null });
|
|
15
|
+
// Compared by its plain form: a definition's validator is not data.
|
|
16
|
+
const key = JSON.stringify(plainQuery(query));
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
setState({ result: null, error: null });
|
|
19
|
+
return node.records.watch(spaceId, JSON.parse(key), (result) => setState({ result: result, error: null }), (error) => setState((previous) => ({ result: previous.result, error })));
|
|
20
|
+
}, [node, spaceId, key]);
|
|
21
|
+
return state;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=use-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-query.js","sourceRoot":"","sources":["../../src/react/use-query.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/**
|
|
3
|
+
* Keeps a space syncing while the component is on screen. Reading or writing
|
|
4
|
+
* opens a space anyway; this is for a view that should hear from peers even
|
|
5
|
+
* before it asks for anything.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useOpenSpace(spaceId: string): void;
|
|
8
|
+
/** A record's current version: undefined while loading, null when there is none. */
|
|
9
|
+
export declare function useRecord<T = unknown>(spaceId: string, key: string): NodeRecord<T> | null | undefined;
|
|
10
|
+
/** The records whose current version points at this one — optionally in one role, or one collection. */
|
|
11
|
+
export declare function useLinked<T = unknown>(spaceId: string, key: string, options?: {
|
|
12
|
+
rel?: string;
|
|
13
|
+
collection?: string;
|
|
14
|
+
}): ReadonlyArray<NodeRecord<T>> | undefined;
|
|
15
|
+
/** What the space holds: its kinds of things, with their schemas and counts. */
|
|
16
|
+
export declare function useCollections(spaceId: string): ReadonlyArray<NodeCollection>;
|
|
17
|
+
/** Who is who in the space: the name each person gave. */
|
|
18
|
+
export declare function useProfiles(spaceId: string): ReadonlyArray<SpaceProfile>;
|
|
19
|
+
/** Who holds what in the space — its roles, members and invites, and your own role. */
|
|
20
|
+
export declare function useAccess(spaceId: string): SpaceAccess | undefined;
|
|
21
|
+
/** Connection, peers, and how many records peers sent that failed checks. */
|
|
22
|
+
export declare function useSpaceStatus(spaceId: string): SpaceStatus | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Whether this account may `create` in a collection (`target` = its name), or
|
|
25
|
+
* `edit` / `delete` a record (`target` = its key). False until known — for
|
|
26
|
+
* hiding a button rather than showing an error.
|
|
27
|
+
*/
|
|
28
|
+
export declare function useCan(spaceId: string, action: 'create' | 'edit' | 'delete', target: string): boolean;
|
|
29
|
+
//# sourceMappingURL=use-space.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-space.d.ts","sourceRoot":"","sources":["../../src/react/use-space.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,Y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