@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,92 @@
|
|
|
1
|
+
import { utf8Encode } from '../utils/encoding.js';
|
|
2
|
+
import { cidFromBytes } from '../utils/hash.js';
|
|
3
|
+
import { newRecordKey } from '../records/version.js';
|
|
4
|
+
/**
|
|
5
|
+
* Deterministically serializes an object into a JSON string with sorted keys.
|
|
6
|
+
* Recursively processes nested objects.
|
|
7
|
+
*
|
|
8
|
+
* @param obj The object to canonicalize
|
|
9
|
+
* @returns Deterministic JSON string representation
|
|
10
|
+
*/
|
|
11
|
+
export function canonicalize(obj) {
|
|
12
|
+
if (obj === null || typeof obj !== 'object') {
|
|
13
|
+
return JSON.stringify(obj) ?? 'null';
|
|
14
|
+
}
|
|
15
|
+
if (Array.isArray(obj)) {
|
|
16
|
+
return `[${obj.map(item => canonicalize(item)).join(',')}]`;
|
|
17
|
+
}
|
|
18
|
+
const keys = Object.keys(obj).sort();
|
|
19
|
+
const pairs = keys.map(key => {
|
|
20
|
+
const value = obj[key];
|
|
21
|
+
// Remove undefined values to match standard JSON.stringify behavior
|
|
22
|
+
if (value === undefined)
|
|
23
|
+
return undefined;
|
|
24
|
+
return `${JSON.stringify(key)}:${canonicalize(value)}`;
|
|
25
|
+
}).filter((pair) => pair !== undefined);
|
|
26
|
+
return `{${pairs.join(',')}}`;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Creates an unsigned expression with a generated timestamp (if not provided).
|
|
30
|
+
* @param params Parameters to create the expression
|
|
31
|
+
* @returns Unsigned expression object
|
|
32
|
+
*/
|
|
33
|
+
export function createExpression(params) {
|
|
34
|
+
return Object.freeze({
|
|
35
|
+
author: params.author,
|
|
36
|
+
collection: params.collection,
|
|
37
|
+
body: params.body,
|
|
38
|
+
createdAt: params.createdAt ?? new Date().toISOString(),
|
|
39
|
+
...(params.space ? { space: params.space } : {}),
|
|
40
|
+
...(params.proof ? { proof: params.proof } : {}),
|
|
41
|
+
key: params.version?.key ?? newRecordKey(),
|
|
42
|
+
seq: params.version?.seq ?? 0,
|
|
43
|
+
...(params.version?.prev ? { prev: params.version.prev } : {}),
|
|
44
|
+
...(params.version?.genesis ? { genesis: params.version.genesis } : {}),
|
|
45
|
+
...(params.retain ? { retain: true } : {}),
|
|
46
|
+
...(params.seen ? { seen: params.seen } : {}),
|
|
47
|
+
...(params.deleted ? { deleted: true } : {}),
|
|
48
|
+
...(params.links?.length ? { links: params.links } : {}),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* What the author signed and the id hashes: everything but the id and the
|
|
53
|
+
* signature. Both checks — id and signature — must drop exactly these, or a
|
|
54
|
+
* field added later is hashed on one side and not the other.
|
|
55
|
+
* @param expression A signed expression
|
|
56
|
+
* @returns Its unsigned payload
|
|
57
|
+
*/
|
|
58
|
+
export function signedPart(expression) {
|
|
59
|
+
const { id: _id, signature: _signature, ...payload } = expression;
|
|
60
|
+
return payload;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Computes the CID for an unsigned expression by hashing its canonical serialization.
|
|
64
|
+
* @param expr The unsigned expression
|
|
65
|
+
* @returns Promise resolving to the CID string
|
|
66
|
+
*/
|
|
67
|
+
export async function getExpressionId(expr) {
|
|
68
|
+
const json = canonicalize(expr);
|
|
69
|
+
const bytes = utf8Encode(json);
|
|
70
|
+
return await cidFromBytes(bytes);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Serializes an Expression to canonical JSON bytes.
|
|
74
|
+
* @param expr The expression to serialize
|
|
75
|
+
* @returns Uint8Array containing canonical JSON bytes
|
|
76
|
+
*/
|
|
77
|
+
export function serializeExpression(expr) {
|
|
78
|
+
const json = canonicalize(expr);
|
|
79
|
+
return utf8Encode(json);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Parses an Expression from canonical JSON bytes.
|
|
83
|
+
* Note: Does not verify signature or ID.
|
|
84
|
+
* @param bytes The bytes to deserialize
|
|
85
|
+
* @returns Parsed Expression
|
|
86
|
+
*/
|
|
87
|
+
export function deserializeExpression(bytes) {
|
|
88
|
+
const decoder = new TextDecoder('utf-8');
|
|
89
|
+
const json = decoder.decode(bytes);
|
|
90
|
+
return Object.freeze(JSON.parse(json));
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=expression.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expression.js","sourceRoot":"","sources":["../../src/schema/expression.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AA6BrD;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,GAAY;IACvC,IAAI,GAAG,KAAK,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5C,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC;IACvC,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,OAA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C,IAAI,CAAC,CAAC;IAChC,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IAC/B,OAAO,MAAM,YAAY,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAgB;IAClD,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IAChC,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAiB;IACrD,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;IACzC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACnC,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAe,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schema/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schema/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { CollectionDef, StandardSchemaIssue } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Result of validating an object against a schema.
|
|
4
|
+
*/
|
|
5
|
+
export interface ValidationResult {
|
|
6
|
+
readonly valid: boolean;
|
|
7
|
+
readonly issues?: ReadonlyArray<StandardSchemaIssue>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Registry and validation engine for collection schemas.
|
|
11
|
+
*/
|
|
12
|
+
export interface SchemaEngine {
|
|
13
|
+
/**
|
|
14
|
+
* Registers a collection with its Standard Schema validator.
|
|
15
|
+
* @param def The collection definition to register
|
|
16
|
+
*/
|
|
17
|
+
registerCollection(def: CollectionDef): void;
|
|
18
|
+
/**
|
|
19
|
+
* Gets a registered collection by name.
|
|
20
|
+
* @param name The name of the collection
|
|
21
|
+
* @returns The collection definition or undefined if not found
|
|
22
|
+
*/
|
|
23
|
+
getCollection(name: string): CollectionDef | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Lists all registered collection names.
|
|
26
|
+
* @returns Array of registered collection names
|
|
27
|
+
*/
|
|
28
|
+
listCollections(): ReadonlyArray<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Validates data against the schema of the specified collection.
|
|
31
|
+
* @param collection The name of the collection
|
|
32
|
+
* @param data The data to validate
|
|
33
|
+
* @returns Promise resolving to a ValidationResult
|
|
34
|
+
*/
|
|
35
|
+
validate(collection: string, data: unknown): Promise<ValidationResult>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new SchemaEngine instance.
|
|
39
|
+
* @returns A new SchemaEngine
|
|
40
|
+
*/
|
|
41
|
+
export declare function createSchemaEngine(): SchemaEngine;
|
|
42
|
+
//# sourceMappingURL=schema-engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-engine.d.ts","sourceRoot":"","sources":["../../src/schema/schema-engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAC;CACtD;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,kBAAkB,CAAC,GAAG,EAAE,aAAa,GAAG,IAAI,CAAC;IAE7C;;;;OAIG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAAC;IAEvD;;;OAGG;IACH,eAAe,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;IAEzC;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CACxE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,YAAY,CAoCjD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new SchemaEngine instance.
|
|
3
|
+
* @returns A new SchemaEngine
|
|
4
|
+
*/
|
|
5
|
+
export function createSchemaEngine() {
|
|
6
|
+
const collections = new Map();
|
|
7
|
+
return Object.freeze({
|
|
8
|
+
registerCollection(def) {
|
|
9
|
+
collections.set(def.name, Object.freeze({ ...def }));
|
|
10
|
+
},
|
|
11
|
+
getCollection(name) {
|
|
12
|
+
return collections.get(name);
|
|
13
|
+
},
|
|
14
|
+
listCollections() {
|
|
15
|
+
return Object.freeze(Array.from(collections.keys()));
|
|
16
|
+
},
|
|
17
|
+
async validate(collectionName, data) {
|
|
18
|
+
const def = collections.get(collectionName);
|
|
19
|
+
if (!def) {
|
|
20
|
+
return Object.freeze({
|
|
21
|
+
valid: false,
|
|
22
|
+
issues: Object.freeze([{ message: `Collection not found: ${collectionName}` }]),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const result = await def.schema['~standard'].validate(data);
|
|
26
|
+
if (result.issues) {
|
|
27
|
+
return Object.freeze({
|
|
28
|
+
valid: false,
|
|
29
|
+
issues: Object.freeze([...result.issues]),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return Object.freeze({ valid: true });
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=schema-engine.js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AAC,MAAM,CAAC,CAAC;iBAC1C,CAAC,CAAC;YACL,CAAC;YAED,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACxC,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CryptoProvider, Expression, UnsignedExpression } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* JWS-style signing and verification for expressions.
|
|
4
|
+
*/
|
|
5
|
+
export interface Signer {
|
|
6
|
+
/**
|
|
7
|
+
* Signs an unsigned payload, returning a complete Expression.
|
|
8
|
+
* @param payload The unsigned expression to sign
|
|
9
|
+
* @param privateKey The private CryptoKey for signing
|
|
10
|
+
* @returns Promise resolving to the signed Expression
|
|
11
|
+
*/
|
|
12
|
+
sign<T>(payload: UnsignedExpression<T>, privateKey: CryptoKey): Promise<Expression<T>>;
|
|
13
|
+
/**
|
|
14
|
+
* Verifies the signature and ID of an Expression.
|
|
15
|
+
* @param expression The expression to verify
|
|
16
|
+
* @param publicKey The public CryptoKey for verification
|
|
17
|
+
* @returns Promise resolving to true if valid, false otherwise
|
|
18
|
+
*/
|
|
19
|
+
verify<T>(expression: Expression<T>, publicKey: CryptoKey): Promise<boolean>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Creates a Signer instance using the provided CryptoProvider.
|
|
23
|
+
* @param provider The CryptoProvider for cryptographic operations
|
|
24
|
+
* @returns A Signer instance
|
|
25
|
+
*/
|
|
26
|
+
export declare function createSigner(provider: CryptoProvider): Signer;
|
|
27
|
+
//# sourceMappingURL=signer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/schema/signer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAIlF;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB;;;;;OAKG;IACH,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IAEvF;;;;;OAKG;IACH,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC9E;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,CAkC7D"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { canonicalize, getExpressionId, signedPart } from './expression.js';
|
|
2
|
+
import { utf8Encode, base64UrlEncode, base64UrlDecode } from '../utils/encoding.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a Signer instance using the provided CryptoProvider.
|
|
5
|
+
* @param provider The CryptoProvider for cryptographic operations
|
|
6
|
+
* @returns A Signer instance
|
|
7
|
+
*/
|
|
8
|
+
export function createSigner(provider) {
|
|
9
|
+
return Object.freeze({
|
|
10
|
+
async sign(payload, privateKey) {
|
|
11
|
+
const canonicalStr = canonicalize(payload);
|
|
12
|
+
const payloadBytes = utf8Encode(canonicalStr);
|
|
13
|
+
const signatureBytes = await provider.sign(privateKey, payloadBytes);
|
|
14
|
+
const signature = base64UrlEncode(signatureBytes);
|
|
15
|
+
const id = await getExpressionId(payload);
|
|
16
|
+
// Everything that was signed, and nothing else: listing fields one by
|
|
17
|
+
// one would silently drop any field added later from the record.
|
|
18
|
+
return Object.freeze({ id, ...payload, signature });
|
|
19
|
+
},
|
|
20
|
+
async verify(expression, publicKey) {
|
|
21
|
+
const { id, signature } = expression;
|
|
22
|
+
const unsignedPayload = signedPart(expression);
|
|
23
|
+
// Verify ID
|
|
24
|
+
const expectedId = await getExpressionId(unsignedPayload);
|
|
25
|
+
if (id !== expectedId) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
// Verify Signature
|
|
29
|
+
const canonicalStr = canonicalize(unsignedPayload);
|
|
30
|
+
const payloadBytes = utf8Encode(canonicalStr);
|
|
31
|
+
const signatureBytes = base64UrlDecode(signature);
|
|
32
|
+
return await provider.verify(publicKey, signatureBytes, payloadBytes);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=signer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../../src/schema/signer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAuBpF;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,QAAwB;IACnD,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,KAAK,CAAC,IAAI,CAAI,OAA8B,EAAE,UAAqB;YACjE,MAAM,YAAY,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;YAC3C,MAAM,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;YAE9C,MAAM,cAAc,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;YACrE,MAAM,SAAS,GAAG,eAAe,CAAC,cAAc,CAAC,CAAC;YAElD,MAAM,EAAE,GAAG,MAAM,eAAe,CAAC,OAAO,CAAC,CAAC;YAE1C,sEAAsE;YACtE,iEAAiE;YACjE,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;QACtD,CAAC;QAED,KAAK,CAAC,MAAM,CAAI,UAAyB,EAAE,SAAoB;YAC7D,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,GAAG,UAAU,CAAC;YACrC,MAAM,eAAe,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;YAE/C,YAAY;YACZ,MAAM,UAAU,GAAG,MAAM,eAAe,CAAC,eAAe,CAAC,CAAC;YAC1D,IAAI,EAAE,KAAK,UAAU,EAAE,CAAC;gBACtB,OAAO,KAAK,CAAC;YACf,CAAC;YAED,mBAAmB;YACnB,MAAM,YAAY,GAAG,YAAY,CAAC,eAAe,CAAC,CAAC;YACnD,MAAM,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;YAC9C,MAAM,cAAc,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;YAElD,OAAO,MAAM,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC;QACxE,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module schemas/apps
|
|
3
|
+
* An app as a record: a title, and the collections it needs.
|
|
4
|
+
*
|
|
5
|
+
* Someone — often an agent — proposes a way of working together by writing
|
|
6
|
+
* one `std.app` record. Nothing is defined yet, so a proposal can't break
|
|
7
|
+
* anything. A person allowed to define collections reads what it would do
|
|
8
|
+
* (in sentences worked out from its rules, `describeCollection`) and adds it:
|
|
9
|
+
* their node defines each collection, signed by them. From then on every app
|
|
10
|
+
* that draws a space from its definitions shows it, with nothing deployed.
|
|
11
|
+
*
|
|
12
|
+
* An agent can propose but never add: every peer ignores definitions signed
|
|
13
|
+
* under an agent's note (see `identity/agent-note.ts`).
|
|
14
|
+
*/
|
|
15
|
+
import type { DefineCollection, NodeCollection, NodeRecord, P2PNode } from '../node/types.js';
|
|
16
|
+
import type { Typed } from '../query/types.js';
|
|
17
|
+
import type { JsonSchema } from '../schema/collection-def.js';
|
|
18
|
+
import type { LinkDeclaration } from '../records/links.js';
|
|
19
|
+
import type { CollectionRules } from '../records/rules.js';
|
|
20
|
+
/** One collection an app needs, as `collections_define` takes it — without a version, which the space decides */
|
|
21
|
+
export interface AppDefinition {
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly title?: string;
|
|
24
|
+
readonly description?: string;
|
|
25
|
+
readonly schema: JsonSchema;
|
|
26
|
+
readonly history?: 'latest' | 'all';
|
|
27
|
+
readonly links?: Readonly<Record<string, LinkDeclaration>>;
|
|
28
|
+
readonly permissions?: ReadonlyArray<string>;
|
|
29
|
+
readonly rules?: CollectionRules;
|
|
30
|
+
/** Its own screen: one HTML document, run sealed (see `schemas/screens.ts`) */
|
|
31
|
+
readonly screen?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface App {
|
|
34
|
+
readonly title: string;
|
|
35
|
+
/** What it is for, in its proposer's words — shown as theirs, never as what it does */
|
|
36
|
+
readonly description?: string;
|
|
37
|
+
readonly needs: ReadonlyArray<AppDefinition>;
|
|
38
|
+
/** Where it was copied from: `<space id>/<record key>` */
|
|
39
|
+
readonly from?: string;
|
|
40
|
+
}
|
|
41
|
+
/** At most this many collections in one app */
|
|
42
|
+
export declare const MAX_APP_COLLECTIONS = 10;
|
|
43
|
+
/** A way of working together that someone proposed: what it's called, and the collections it needs. */
|
|
44
|
+
export declare const app: DefineCollection & Typed<App>;
|
|
45
|
+
/** Why this can't be an app, or null when it can */
|
|
46
|
+
export declare function checkApp(value: unknown): string | null;
|
|
47
|
+
/** What adding one collection would do in a space */
|
|
48
|
+
export interface AppNeedReview {
|
|
49
|
+
readonly definition: AppDefinition;
|
|
50
|
+
/** `new`: not in the space yet. `same`: already there, as is. `change`: there, and this would change it. */
|
|
51
|
+
readonly status: 'new' | 'same' | 'change';
|
|
52
|
+
/** What it allows, from its rules — never from its description */
|
|
53
|
+
readonly summary: ReadonlyArray<string>;
|
|
54
|
+
/** For a change: what would be different, in words */
|
|
55
|
+
readonly changes: ReadonlyArray<string>;
|
|
56
|
+
}
|
|
57
|
+
export interface AppReview {
|
|
58
|
+
readonly needs: ReadonlyArray<AppNeedReview>;
|
|
59
|
+
/** Every collection it needs is in the space, as it says */
|
|
60
|
+
readonly added: boolean;
|
|
61
|
+
/** Why it can't be added as it stands, or null */
|
|
62
|
+
readonly problem: string | null;
|
|
63
|
+
}
|
|
64
|
+
/** The screen an app brings, if any: the first of its collections that carries one */
|
|
65
|
+
export declare function appScreen(body: App): {
|
|
66
|
+
readonly collection: string;
|
|
67
|
+
readonly screen: string;
|
|
68
|
+
} | null;
|
|
69
|
+
/**
|
|
70
|
+
* What adding an app would do in a space: which of its collections are new,
|
|
71
|
+
* already there, or would change one that is — each with what it allows.
|
|
72
|
+
*/
|
|
73
|
+
export declare function reviewApp(body: App, collections: ReadonlyArray<NodeCollection>): AppReview;
|
|
74
|
+
/**
|
|
75
|
+
* Proposes an app in a space: one `std.app` record. Anyone in the space may,
|
|
76
|
+
* an agent included; nothing is defined until a person adds it.
|
|
77
|
+
*/
|
|
78
|
+
export declare function proposeApp(node: P2PNode, spaceId: string, body: App): Promise<NodeRecord<App>>;
|
|
79
|
+
/**
|
|
80
|
+
* Adds a proposed app: defines each collection it needs that the space
|
|
81
|
+
* doesn't have as it says — new ones, and changes to ones it has. Signed by
|
|
82
|
+
* whoever adds it, so they must be allowed to define collections here; an
|
|
83
|
+
* agent never is.
|
|
84
|
+
*/
|
|
85
|
+
export declare function addApp(node: P2PNode, spaceId: string, key: string): Promise<AppReview>;
|
|
86
|
+
/** Copies an app into another space, as a proposal there — people in that space decide for themselves. */
|
|
87
|
+
export declare function copyApp(node: P2PNode, fromSpace: string, key: string, toSpace: string): Promise<NodeRecord<App>>;
|
|
88
|
+
//# sourceMappingURL=apps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apps.d.ts","sourceRoot":"","sources":["../../src/schemas/apps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC9F,OAA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AC1G,wBAAsB,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAKtH"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { checkStoredCollection } from '../schema/collection-def.js';
|
|
2
|
+
import { canonicalize } from '../schema/expression.js';
|
|
3
|
+
import { describeCollection } from '../records/describe.js';
|
|
4
|
+
/** At most this many collections in one app */
|
|
5
|
+
export const MAX_APP_COLLECTIONS = 10;
|
|
6
|
+
/** A way of working together that someone proposed: what it's called, and the collections it needs. */
|
|
7
|
+
export const app = {
|
|
8
|
+
name: 'std.app',
|
|
9
|
+
title: 'App',
|
|
10
|
+
description: 'A way of working together: what it is called, and the collections it needs, not yet added.',
|
|
11
|
+
schema: {
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
title: { type: 'string', minLength: 1, maxLength: 100 },
|
|
15
|
+
description: { type: 'string', maxLength: 1000 },
|
|
16
|
+
needs: { type: 'array', minItems: 1, maxItems: MAX_APP_COLLECTIONS, items: { type: 'object' } },
|
|
17
|
+
from: { type: 'string', maxLength: 300 },
|
|
18
|
+
},
|
|
19
|
+
required: ['title', 'needs'],
|
|
20
|
+
},
|
|
21
|
+
permissions: ['moderate'],
|
|
22
|
+
rules: { edit: 'creator', delete: ['creator', 'can:moderate'] },
|
|
23
|
+
};
|
|
24
|
+
/** Why this can't be an app, or null when it can */
|
|
25
|
+
export function checkApp(value) {
|
|
26
|
+
const body = value;
|
|
27
|
+
if (!body || typeof body !== 'object')
|
|
28
|
+
return 'An app must be an object';
|
|
29
|
+
if (typeof body.title !== 'string' || !body.title.trim() || body.title.length > 100)
|
|
30
|
+
return 'An app needs a title of 1–100 characters';
|
|
31
|
+
if (body.description !== undefined && (typeof body.description !== 'string' || body.description.length > 1000)) {
|
|
32
|
+
return 'An app\'s description is at most 1000 characters';
|
|
33
|
+
}
|
|
34
|
+
if (!Array.isArray(body.needs) || body.needs.length === 0 || body.needs.length > MAX_APP_COLLECTIONS) {
|
|
35
|
+
return `An app needs 1–${MAX_APP_COLLECTIONS} collections`;
|
|
36
|
+
}
|
|
37
|
+
const names = new Set();
|
|
38
|
+
for (const [index, need] of body.needs.entries()) {
|
|
39
|
+
const at = `needs[${index}]`;
|
|
40
|
+
if (!need || typeof need !== 'object')
|
|
41
|
+
return `${at} must be a collection definition`;
|
|
42
|
+
if (typeof need.name === 'string' && need.name.startsWith('sys.'))
|
|
43
|
+
return `${at}: sys.* collections are the protocol's own`;
|
|
44
|
+
if ('version' in need)
|
|
45
|
+
return `${at}: leave out "version" — the space decides it when the app is added`;
|
|
46
|
+
const problem = checkStoredCollection({ ...need, version: 1 });
|
|
47
|
+
if (problem)
|
|
48
|
+
return `${at}: ${problem}`;
|
|
49
|
+
if (names.has(need.name))
|
|
50
|
+
return `${at}: ${need.name} is listed twice`;
|
|
51
|
+
names.add(need.name);
|
|
52
|
+
try {
|
|
53
|
+
describeCollection(need);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
return `${at}: ${error instanceof Error ? error.message : String(error)}`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
/** The parts of a definition that decide what it is, in one comparable form */
|
|
62
|
+
function essence(definition) {
|
|
63
|
+
return {
|
|
64
|
+
title: definition.title ?? '',
|
|
65
|
+
description: definition.description ?? '',
|
|
66
|
+
schema: canonicalize(definition.schema ?? null),
|
|
67
|
+
history: definition.history ?? 'latest',
|
|
68
|
+
links: canonicalize(definition.links ?? {}),
|
|
69
|
+
permissions: canonicalize([...(definition.permissions ?? [])].sort()),
|
|
70
|
+
rules: canonicalize(definition.rules ?? {}),
|
|
71
|
+
screen: definition.screen ?? '',
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const fieldNames = (schema) => Object.keys(schema?.properties ?? {});
|
|
75
|
+
/** What would change, in words, going from what the space has to what the app says */
|
|
76
|
+
function differences(held, wanted) {
|
|
77
|
+
const a = essence(held);
|
|
78
|
+
const b = essence(wanted);
|
|
79
|
+
const out = [];
|
|
80
|
+
const before = new Set(fieldNames(held.schema));
|
|
81
|
+
const after = new Set(fieldNames(wanted.schema));
|
|
82
|
+
const added = [...after].filter((field) => !before.has(field));
|
|
83
|
+
const removed = [...before].filter((field) => !after.has(field));
|
|
84
|
+
if (added.length)
|
|
85
|
+
out.push(`adds ${added.map((f) => `“${f}”`).join(', ')}`);
|
|
86
|
+
if (removed.length)
|
|
87
|
+
out.push(`drops ${removed.map((f) => `“${f}”`).join(', ')}`);
|
|
88
|
+
if (!added.length && !removed.length && a.schema !== b.schema)
|
|
89
|
+
out.push('changes the shape of its fields');
|
|
90
|
+
if (a.rules !== b.rules || a.permissions !== b.permissions)
|
|
91
|
+
out.push('changes who may do what');
|
|
92
|
+
if (a.links !== b.links)
|
|
93
|
+
out.push('changes what it points at');
|
|
94
|
+
if (a.history !== b.history)
|
|
95
|
+
out.push(b.history === 'all' ? 'starts keeping every version' : 'stops keeping old versions');
|
|
96
|
+
if (a.screen !== b.screen)
|
|
97
|
+
out.push(!b.screen ? 'takes its screen away' : !a.screen ? 'gives it a screen' : 'changes its screen');
|
|
98
|
+
if (a.title !== b.title || a.description !== b.description)
|
|
99
|
+
out.push('renames or redescribes it');
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
/** The screen an app brings, if any: the first of its collections that carries one */
|
|
103
|
+
export function appScreen(body) {
|
|
104
|
+
const found = body.needs.find((need) => typeof need.screen === 'string' && need.screen.trim());
|
|
105
|
+
return found ? { collection: found.name, screen: found.screen } : null;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* What adding an app would do in a space: which of its collections are new,
|
|
109
|
+
* already there, or would change one that is — each with what it allows.
|
|
110
|
+
*/
|
|
111
|
+
export function reviewApp(body, collections) {
|
|
112
|
+
const problem = checkApp(body);
|
|
113
|
+
if (problem)
|
|
114
|
+
return { needs: [], added: false, problem };
|
|
115
|
+
const byName = new Map(collections.filter((c) => c.version !== null).map((c) => [c.name, c]));
|
|
116
|
+
const needs = body.needs.map((definition) => {
|
|
117
|
+
const summary = describeCollection(definition);
|
|
118
|
+
const held = byName.get(definition.name);
|
|
119
|
+
if (!held)
|
|
120
|
+
return { definition, status: 'new', summary, changes: [] };
|
|
121
|
+
const changes = differences(held, definition);
|
|
122
|
+
return { definition, status: changes.length ? 'change' : 'same', summary, changes };
|
|
123
|
+
});
|
|
124
|
+
return { needs, added: needs.every((need) => need.status === 'same'), problem: null };
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Proposes an app in a space: one `std.app` record. Anyone in the space may,
|
|
128
|
+
* an agent included; nothing is defined until a person adds it.
|
|
129
|
+
*/
|
|
130
|
+
export async function proposeApp(node, spaceId, body) {
|
|
131
|
+
const problem = checkApp(body);
|
|
132
|
+
if (problem)
|
|
133
|
+
throw new Error(problem);
|
|
134
|
+
return node.records.put(spaceId, app.name, body);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Adds a proposed app: defines each collection it needs that the space
|
|
138
|
+
* doesn't have as it says — new ones, and changes to ones it has. Signed by
|
|
139
|
+
* whoever adds it, so they must be allowed to define collections here; an
|
|
140
|
+
* agent never is.
|
|
141
|
+
*/
|
|
142
|
+
export async function addApp(node, spaceId, key) {
|
|
143
|
+
const record = await node.records.get(spaceId, key);
|
|
144
|
+
if (!record?.body || record.collection !== app.name)
|
|
145
|
+
throw new Error(`No app ${key} in this space`);
|
|
146
|
+
// Knowing std.app itself means its own rules hold from now on: only its proposer edits a proposal.
|
|
147
|
+
const known = await node.collections.list(spaceId);
|
|
148
|
+
if (!known.some((c) => c.name === app.name && c.version !== null))
|
|
149
|
+
await node.collections.define(spaceId, app);
|
|
150
|
+
const review = reviewApp(record.body, known);
|
|
151
|
+
if (review.problem)
|
|
152
|
+
throw new Error(review.problem);
|
|
153
|
+
for (const need of review.needs) {
|
|
154
|
+
if (need.status === 'same')
|
|
155
|
+
continue;
|
|
156
|
+
await node.collections.define(spaceId, need.definition);
|
|
157
|
+
}
|
|
158
|
+
return reviewApp(record.body, await node.collections.list(spaceId));
|
|
159
|
+
}
|
|
160
|
+
/** Copies an app into another space, as a proposal there — people in that space decide for themselves. */
|
|
161
|
+
export async function copyApp(node, fromSpace, key, toSpace) {
|
|
162
|
+
const record = await node.records.get(fromSpace, key);
|
|
163
|
+
if (!record?.body || record.collection !== app.name)
|
|
164
|
+
throw new Error(`No app ${key} in this space`);
|
|
165
|
+
const { title, description, needs } = record.body;
|
|
166
|
+
return proposeApp(node, toSpace, { title, ...(description !== undefined ? { description } : {}), needs, from: `${fromSpace}/${key}` });
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=apps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apps.js","sourceRoot":"","sources":["../../src/schemas/apps.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAGvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAyB5D,+CAA+C;AAC/C,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAEtC,uGAAuG;AACvG,MAAM,CAAC,MAAM,GAAG,GAAkC;IAChD,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,KAAK;IACZ,WAAW,EAAE,4FAA4F;IACzG,MAAM,EAAE;QACN,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE;YACvD,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE;YAChD,KAA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