@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 @@
|
|
|
1
|
+
{"version":3,"file":"indexeddb-adapter.js","sourceRoot":"","sources":["../../src/storage/indexeddb-adapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;GAGG;AACH,MAAM,UAAU,GAAG,CAAC,CAAC;AAErB;;;;GAIG;AACH,SAAS,UAAU,CAAI,OAAsB;IAC3C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,OAAO,CAAC,SAAS,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAClD,OAAO,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,SAAS,cAAc,CACrB,EAAe,EACf,MAAgB,EAChB,IAAwB;IAExB,MAAM,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACxC,MAAM,QAAQ,GAAG,IAAI,OAAO,CAAO,C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AC;gBACvB,CAAC;YACH,CAAC;YACD,MAAM,QAAQ,CAAC;QACjB,CAAC;QAED,KAAK,CAAC,KAAK;YACT,EAAE,CAAC,KAAK,EAAE,CAAC;QACb,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module mst
|
|
3
|
+
* Merkle Search Tree (MST) — a deterministic, content-addressed ordered map.
|
|
4
|
+
*
|
|
5
|
+
* Every key carries a height derived from its own hash (see {@link nodeHeight}),
|
|
6
|
+
* and a key lives in the node at exactly that height. Because the height comes
|
|
7
|
+
* from the key rather than from insertion order, the same set of entries always
|
|
8
|
+
* produces the same tree — and therefore the same root CID — no matter what
|
|
9
|
+
* order it was built in. That determinism is what makes the root usable as a
|
|
10
|
+
* one-word summary of a peer's state, and what lets two peers skip any subtree
|
|
11
|
+
* whose CID they both already hold.
|
|
12
|
+
*
|
|
13
|
+
* Nodes are immutable: an insert rewrites only the path from the touched node
|
|
14
|
+
* up to the root, which is O(log N) nodes rather than the whole tree.
|
|
15
|
+
*/
|
|
16
|
+
import type { StorageAdapter } from '../types.js';
|
|
17
|
+
/**
|
|
18
|
+
* A node in the Merkle Search Tree.
|
|
19
|
+
*
|
|
20
|
+
* Every key in `keys` hashes to `height`. `children` always holds one more
|
|
21
|
+
* entry than `keys`: `children[i]` is the subtree at `height - 1` covering the
|
|
22
|
+
* keys that sort between `keys[i - 1]` and `keys[i]`.
|
|
23
|
+
*/
|
|
24
|
+
export interface MSTNode {
|
|
25
|
+
readonly height: number;
|
|
26
|
+
readonly keys: ReadonlyArray<string>;
|
|
27
|
+
readonly values: ReadonlyArray<string>;
|
|
28
|
+
readonly children: ReadonlyArray<string | null>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Creates an empty MST node at the given height.
|
|
32
|
+
* @param height The height the node sits at.
|
|
33
|
+
* @returns An empty node.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createEmptyNode(height?: number): MSTNode;
|
|
36
|
+
/**
|
|
37
|
+
* Canonical JSON serialization of an MST node.
|
|
38
|
+
* @param node The node to serialize.
|
|
39
|
+
* @returns The canonical bytes.
|
|
40
|
+
*/
|
|
41
|
+
export declare function serializeNode(node: MSTNode): Uint8Array;
|
|
42
|
+
/**
|
|
43
|
+
* Deserialize an MST node.
|
|
44
|
+
* @param data The canonical bytes.
|
|
45
|
+
* @returns The node.
|
|
46
|
+
*/
|
|
47
|
+
export declare function deserializeNode(data: Uint8Array): MSTNode;
|
|
48
|
+
/**
|
|
49
|
+
* Hashes a node to get its CID.
|
|
50
|
+
* @param node The node to hash.
|
|
51
|
+
* @returns The node's CID.
|
|
52
|
+
*/
|
|
53
|
+
export declare function hashNode(node: MSTNode): Promise<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Calculate the deterministic height of a key using SHA-256.
|
|
56
|
+
* Counts leading zero bits in the hash, divided by 4 — so roughly one key in
|
|
57
|
+
* 16 sits a level higher than the last, giving the tree its branching factor.
|
|
58
|
+
* @param key The key to place.
|
|
59
|
+
* @returns The height the key belongs at.
|
|
60
|
+
*/
|
|
61
|
+
export declare function nodeHeight(key: string): Promise<number>;
|
|
62
|
+
/**
|
|
63
|
+
* Load a node from the storage adapter.
|
|
64
|
+
* @param adapter The storage adapter.
|
|
65
|
+
* @param cid The node's CID.
|
|
66
|
+
* @returns The node.
|
|
67
|
+
*/
|
|
68
|
+
export declare function loadNode(adapter: StorageAdapter, cid: string): Promise<MSTNode>;
|
|
69
|
+
/**
|
|
70
|
+
* Save a node to the storage adapter and return its CID.
|
|
71
|
+
* @param adapter The storage adapter.
|
|
72
|
+
* @param node The node to store.
|
|
73
|
+
* @returns The node's CID.
|
|
74
|
+
*/
|
|
75
|
+
export declare function saveNode(adapter: StorageAdapter, node: MSTNode): Promise<string>;
|
|
76
|
+
/**
|
|
77
|
+
* Every node CID reachable from a root: the tree as it stands, without the
|
|
78
|
+
* orphans older versions left behind in the store. Sync uses it to decide
|
|
79
|
+
* which of a peer's subtrees it already holds; garbage collection uses it to
|
|
80
|
+
* decide what to keep.
|
|
81
|
+
* @param adapter The storage adapter.
|
|
82
|
+
* @param rootCid The root, or null for an empty tree.
|
|
83
|
+
*/
|
|
84
|
+
export declare function collectReachableCids(adapter: StorageAdapter, rootCid: string | null): Promise<Set<string>>;
|
|
85
|
+
/**
|
|
86
|
+
* Insert a key-value pair into the MST.
|
|
87
|
+
* @param adapter The storage adapter.
|
|
88
|
+
* @param rootCid The current root, or null for an empty tree.
|
|
89
|
+
* @param key The key to insert.
|
|
90
|
+
* @param value The value to store against it.
|
|
91
|
+
* @returns The new root CID.
|
|
92
|
+
*/
|
|
93
|
+
export declare function insertIntoMST(adapter: StorageAdapter, rootCid: string | null, key: string, value: string): Promise<string>;
|
|
94
|
+
/**
|
|
95
|
+
* Delete a key from the MST.
|
|
96
|
+
* @param adapter The storage adapter.
|
|
97
|
+
* @param rootCid The current root, or null for an empty tree.
|
|
98
|
+
* @param key The key to remove.
|
|
99
|
+
* @returns The new root CID, or null once the tree is empty.
|
|
100
|
+
*/
|
|
101
|
+
export declare function deleteFromMST(adapter: StorageAdapter, rootCid: string | null, key: string): Promise<string | null>;
|
|
102
|
+
/**
|
|
103
|
+
* Lookup a value by key.
|
|
104
|
+
* @param adapter The storage adapter.
|
|
105
|
+
* @param rootCid The root to search from.
|
|
106
|
+
* @param key The key to find.
|
|
107
|
+
* @returns The value, or null when absent.
|
|
108
|
+
*/
|
|
109
|
+
export declare function lookupInMST(adapter: StorageAdapter, rootCid: string | null, key: string): Promise<string | null>;
|
|
110
|
+
/**
|
|
111
|
+
* Lists entries — keys with their values — in key order: all of them, or
|
|
112
|
+
* those under a prefix, reading only the nodes that can hold them.
|
|
113
|
+
* @param adapter The storage adapter.
|
|
114
|
+
* @param rootCid The root, or null for an empty tree.
|
|
115
|
+
* @param prefix Only keys starting with this
|
|
116
|
+
*/
|
|
117
|
+
export declare function listMSTEntries(adapter: StorageAdapter, rootCid: string | null, prefix?: string): Promise<Array<{
|
|
118
|
+
key: string;
|
|
119
|
+
value: string;
|
|
120
|
+
}>>;
|
|
121
|
+
//# sourceMappingURL=mst.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mst.d.ts","sourceRoot":"","sources":["../../src/storage/mst.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAIlD;;;;;;GAMG;AACH,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACrC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACvC,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CACjD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,SAAI,GAAG,OAAO,CAOnD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,UAAU,CASvD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAQzD;AAED;;;;GAIG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAG7D;AAED;;;;;;GAMG;AACH,wBAAsB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAiB7D;AAED;;;;;GAKG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAIrF;AAED;;;;;GAKG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAKtF;AA+PD;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAEhH;AAED;;;;;;;GAOG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,MAAM,CAAC,CAuBjB;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAexB;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CASxB;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,MAAM,SAAK,GACV,OAAO,CAAC,KAAK,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CAIhD"}
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module mst
|
|
3
|
+
* Merkle Search Tree (MST) — a deterministic, content-addressed ordered map.
|
|
4
|
+
*
|
|
5
|
+
* Every key carries a height derived from its own hash (see {@link nodeHeight}),
|
|
6
|
+
* and a key lives in the node at exactly that height. Because the height comes
|
|
7
|
+
* from the key rather than from insertion order, the same set of entries always
|
|
8
|
+
* produces the same tree — and therefore the same root CID — no matter what
|
|
9
|
+
* order it was built in. That determinism is what makes the root usable as a
|
|
10
|
+
* one-word summary of a peer's state, and what lets two peers skip any subtree
|
|
11
|
+
* whose CID they both already hold.
|
|
12
|
+
*
|
|
13
|
+
* Nodes are immutable: an insert rewrites only the path from the touched node
|
|
14
|
+
* up to the root, which is O(log N) nodes rather than the whole tree.
|
|
15
|
+
*/
|
|
16
|
+
import { utf8Encode, utf8Decode } from '../utils/encoding.js';
|
|
17
|
+
import { sha256, cidFromBytes } from '../utils/hash.js';
|
|
18
|
+
/**
|
|
19
|
+
* Creates an empty MST node at the given height.
|
|
20
|
+
* @param height The height the node sits at.
|
|
21
|
+
* @returns An empty node.
|
|
22
|
+
*/
|
|
23
|
+
export function createEmptyNode(height = 0) {
|
|
24
|
+
return Object.freeze({
|
|
25
|
+
height,
|
|
26
|
+
keys: Object.freeze([]),
|
|
27
|
+
values: Object.freeze([]),
|
|
28
|
+
children: Object.freeze([null])
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Canonical JSON serialization of an MST node.
|
|
33
|
+
* @param node The node to serialize.
|
|
34
|
+
* @returns The canonical bytes.
|
|
35
|
+
*/
|
|
36
|
+
export function serializeNode(node) {
|
|
37
|
+
// Field order is fixed so the same node always hashes to the same CID.
|
|
38
|
+
const obj = {
|
|
39
|
+
height: node.height,
|
|
40
|
+
keys: node.keys,
|
|
41
|
+
values: node.values,
|
|
42
|
+
children: node.children
|
|
43
|
+
};
|
|
44
|
+
return utf8Encode(JSON.stringify(obj));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Deserialize an MST node.
|
|
48
|
+
* @param data The canonical bytes.
|
|
49
|
+
* @returns The node.
|
|
50
|
+
*/
|
|
51
|
+
export function deserializeNode(data) {
|
|
52
|
+
const obj = JSON.parse(utf8Decode(data));
|
|
53
|
+
return Object.freeze({
|
|
54
|
+
height: obj.height ?? 0,
|
|
55
|
+
keys: Object.freeze([...obj.keys]),
|
|
56
|
+
values: Object.freeze([...obj.values]),
|
|
57
|
+
children: Object.freeze([...obj.children])
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Hashes a node to get its CID.
|
|
62
|
+
* @param node The node to hash.
|
|
63
|
+
* @returns The node's CID.
|
|
64
|
+
*/
|
|
65
|
+
export async function hashNode(node) {
|
|
66
|
+
const bytes = serializeNode(node);
|
|
67
|
+
return cidFromBytes(bytes);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Calculate the deterministic height of a key using SHA-256.
|
|
71
|
+
* Counts leading zero bits in the hash, divided by 4 — so roughly one key in
|
|
72
|
+
* 16 sits a level higher than the last, giving the tree its branching factor.
|
|
73
|
+
* @param key The key to place.
|
|
74
|
+
* @returns The height the key belongs at.
|
|
75
|
+
*/
|
|
76
|
+
export async function nodeHeight(key) {
|
|
77
|
+
const hashBytes = await sha256(utf8Encode(key));
|
|
78
|
+
let zeros = 0;
|
|
79
|
+
for (let i = 0; i < hashBytes.length; i++) {
|
|
80
|
+
const byte = hashBytes[i];
|
|
81
|
+
if (byte === 0) {
|
|
82
|
+
zeros += 8;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
let temp = byte;
|
|
86
|
+
while ((temp & 0x80) === 0) {
|
|
87
|
+
zeros++;
|
|
88
|
+
temp <<= 1;
|
|
89
|
+
}
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return Math.floor(zeros / 4);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Load a node from the storage adapter.
|
|
97
|
+
* @param adapter The storage adapter.
|
|
98
|
+
* @param cid The node's CID.
|
|
99
|
+
* @returns The node.
|
|
100
|
+
*/
|
|
101
|
+
export async function loadNode(adapter, cid) {
|
|
102
|
+
const data = await adapter.get(cid);
|
|
103
|
+
if (!data)
|
|
104
|
+
throw new Error(`Node not found: ${cid}`);
|
|
105
|
+
return deserializeNode(data);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Save a node to the storage adapter and return its CID.
|
|
109
|
+
* @param adapter The storage adapter.
|
|
110
|
+
* @param node The node to store.
|
|
111
|
+
* @returns The node's CID.
|
|
112
|
+
*/
|
|
113
|
+
export async function saveNode(adapter, node) {
|
|
114
|
+
const bytes = serializeNode(node);
|
|
115
|
+
const cid = await cidFromBytes(bytes);
|
|
116
|
+
await adapter.put(cid, bytes);
|
|
117
|
+
return cid;
|
|
118
|
+
}
|
|
119
|
+
// --------------------------------------------------------------- internals
|
|
120
|
+
/** Index of the first key that is greater than or equal to `target`. */
|
|
121
|
+
function lowerBound(keys, target) {
|
|
122
|
+
let lo = 0;
|
|
123
|
+
let hi = keys.length;
|
|
124
|
+
while (lo < hi) {
|
|
125
|
+
const mid = (lo + hi) >> 1;
|
|
126
|
+
if (keys[mid] < target)
|
|
127
|
+
lo = mid + 1;
|
|
128
|
+
else
|
|
129
|
+
hi = mid;
|
|
130
|
+
}
|
|
131
|
+
return lo;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Stores a node, unless it carries nothing at all — an empty node with no
|
|
135
|
+
* surviving child is simply an absent subtree, and representing it as `null`
|
|
136
|
+
* keeps the tree canonical.
|
|
137
|
+
*/
|
|
138
|
+
async function saveOrPrune(adapter, node) {
|
|
139
|
+
if (node.keys.length === 0 && node.children.every(child => child === null))
|
|
140
|
+
return null;
|
|
141
|
+
return saveNode(adapter, node);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Wraps a subtree in empty parent nodes until it sits at `toHeight`.
|
|
145
|
+
*
|
|
146
|
+
* A height gap has to be filled with real nodes rather than skipped, because
|
|
147
|
+
* every tree holding the same keys must produce the same CIDs.
|
|
148
|
+
*/
|
|
149
|
+
async function lift(adapter, cid, fromHeight, toHeight) {
|
|
150
|
+
if (cid === null)
|
|
151
|
+
return null;
|
|
152
|
+
let current = cid;
|
|
153
|
+
for (let h = fromHeight + 1; h <= toHeight; h++) {
|
|
154
|
+
current = await saveNode(adapter, Object.freeze({
|
|
155
|
+
height: h,
|
|
156
|
+
keys: Object.freeze([]),
|
|
157
|
+
values: Object.freeze([]),
|
|
158
|
+
children: Object.freeze([current])
|
|
159
|
+
}));
|
|
160
|
+
}
|
|
161
|
+
return current;
|
|
162
|
+
}
|
|
163
|
+
/** Builds a subtree topped at `topHeight` holding exactly one entry. */
|
|
164
|
+
async function singleton(adapter, key, value, keyHeight, topHeight) {
|
|
165
|
+
const leaf = await saveNode(adapter, Object.freeze({
|
|
166
|
+
height: keyHeight,
|
|
167
|
+
keys: Object.freeze([key]),
|
|
168
|
+
values: Object.freeze([value]),
|
|
169
|
+
children: Object.freeze([null, null])
|
|
170
|
+
}));
|
|
171
|
+
return (await lift(adapter, leaf, keyHeight, topHeight));
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Splits a subtree into the entries below `key` and those above it, both
|
|
175
|
+
* returned at the input subtree's height.
|
|
176
|
+
*/
|
|
177
|
+
async function splitSubtree(adapter, cid, key) {
|
|
178
|
+
if (cid === null)
|
|
179
|
+
return [null, null];
|
|
180
|
+
const node = await loadNode(adapter, cid);
|
|
181
|
+
const idx = lowerBound(node.keys, key);
|
|
182
|
+
// The child at `idx` straddles the split point, so it splits too.
|
|
183
|
+
const [childLeft, childRight] = await splitSubtree(adapter, node.children[idx] ?? null, key);
|
|
184
|
+
const left = {
|
|
185
|
+
height: node.height,
|
|
186
|
+
keys: node.keys.slice(0, idx),
|
|
187
|
+
values: node.values.slice(0, idx),
|
|
188
|
+
children: [...node.children.slice(0, idx), childLeft]
|
|
189
|
+
};
|
|
190
|
+
const right = {
|
|
191
|
+
height: node.height,
|
|
192
|
+
keys: node.keys.slice(idx),
|
|
193
|
+
values: node.values.slice(idx),
|
|
194
|
+
children: [childRight, ...node.children.slice(idx + 1)]
|
|
195
|
+
};
|
|
196
|
+
return [await saveOrPrune(adapter, left), await saveOrPrune(adapter, right)];
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Merges two adjacent subtrees of equal height, where every key on the left
|
|
200
|
+
* sorts before every key on the right.
|
|
201
|
+
*/
|
|
202
|
+
async function mergeSubtrees(adapter, left, right) {
|
|
203
|
+
if (left === null)
|
|
204
|
+
return right;
|
|
205
|
+
if (right === null)
|
|
206
|
+
return left;
|
|
207
|
+
const leftNode = await loadNode(adapter, left);
|
|
208
|
+
const rightNode = await loadNode(adapter, right);
|
|
209
|
+
// The two subtrees meet at the left's last child and the right's first.
|
|
210
|
+
const middle = await mergeSubtrees(adapter, leftNode.children[leftNode.children.length - 1] ?? null, rightNode.children[0] ?? null);
|
|
211
|
+
return saveOrPrune(adapter, {
|
|
212
|
+
height: leftNode.height,
|
|
213
|
+
keys: [...leftNode.keys, ...rightNode.keys],
|
|
214
|
+
values: [...leftNode.values, ...rightNode.values],
|
|
215
|
+
children: [...leftNode.children.slice(0, -1), middle, ...rightNode.children.slice(1)]
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
/** Inserts into a subtree known to sit at `subtreeHeight`. */
|
|
219
|
+
async function insertInto(adapter, cid, subtreeHeight, key, value, keyHeight) {
|
|
220
|
+
if (cid === null)
|
|
221
|
+
return singleton(adapter, key, value, keyHeight, subtreeHeight);
|
|
222
|
+
const node = await loadNode(adapter, cid);
|
|
223
|
+
const idx = lowerBound(node.keys, key);
|
|
224
|
+
if (keyHeight === node.height) {
|
|
225
|
+
if (node.keys[idx] === key) {
|
|
226
|
+
const values = [...node.values];
|
|
227
|
+
values[idx] = value;
|
|
228
|
+
return saveNode(adapter, { ...node, values });
|
|
229
|
+
}
|
|
230
|
+
// The key lands between two existing keys, so the subtree that currently
|
|
231
|
+
// spans that gap has to be split around it.
|
|
232
|
+
const [childLeft, childRight] = await splitSubtree(adapter, node.children[idx] ?? null, key);
|
|
233
|
+
return saveNode(adapter, {
|
|
234
|
+
height: node.height,
|
|
235
|
+
keys: [...node.keys.slice(0, idx), key, ...node.keys.slice(idx)],
|
|
236
|
+
values: [...node.values.slice(0, idx), value, ...node.values.slice(idx)],
|
|
237
|
+
children: [...node.children.slice(0, idx), childLeft, childRight, ...node.children.slice(idx + 1)]
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
// The key belongs further down; only this child changes.
|
|
241
|
+
const child = await insertInto(adapter, node.children[idx] ?? null, node.height - 1, key, value, keyHeight);
|
|
242
|
+
const children = [...node.children];
|
|
243
|
+
children[idx] = child;
|
|
244
|
+
return saveNode(adapter, { ...node, children });
|
|
245
|
+
}
|
|
246
|
+
/** Removes from a subtree, returning its new CID, or `null` if nothing is left. */
|
|
247
|
+
async function deleteFrom(adapter, cid, key, keyHeight) {
|
|
248
|
+
if (cid === null)
|
|
249
|
+
return null;
|
|
250
|
+
const node = await loadNode(adapter, cid);
|
|
251
|
+
// A key sitting above this node cannot appear anywhere beneath it.
|
|
252
|
+
if (keyHeight > node.height)
|
|
253
|
+
return cid;
|
|
254
|
+
const idx = lowerBound(node.keys, key);
|
|
255
|
+
if (keyHeight === node.height) {
|
|
256
|
+
if (node.keys[idx] !== key)
|
|
257
|
+
return cid;
|
|
258
|
+
// Removing the separator joins the subtrees on either side of it.
|
|
259
|
+
const merged = await mergeSubtrees(adapter, node.children[idx] ?? null, node.children[idx + 1] ?? null);
|
|
260
|
+
return saveOrPrune(adapter, {
|
|
261
|
+
height: node.height,
|
|
262
|
+
keys: [...node.keys.slice(0, idx), ...node.keys.slice(idx + 1)],
|
|
263
|
+
values: [...node.values.slice(0, idx), ...node.values.slice(idx + 1)],
|
|
264
|
+
children: [...node.children.slice(0, idx), merged, ...node.children.slice(idx + 2)]
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
const existing = node.children[idx] ?? null;
|
|
268
|
+
const child = await deleteFrom(adapter, existing, key, keyHeight);
|
|
269
|
+
if (child === existing)
|
|
270
|
+
return cid;
|
|
271
|
+
const children = [...node.children];
|
|
272
|
+
children[idx] = child;
|
|
273
|
+
return saveOrPrune(adapter, { ...node, children });
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Walks the entries whose keys start with `prefix`, in key order, skipping
|
|
277
|
+
* every subtree that lies wholly outside that range.
|
|
278
|
+
*/
|
|
279
|
+
async function walkEntries(adapter, cid, prefix, visit) {
|
|
280
|
+
if (cid === null)
|
|
281
|
+
return;
|
|
282
|
+
const node = await loadNode(adapter, cid);
|
|
283
|
+
const { keys } = node;
|
|
284
|
+
// Child i holds the keys between keys[i - 1] and keys[i].
|
|
285
|
+
for (let i = 0; i <= keys.length; i++) {
|
|
286
|
+
const below = keys[i - 1];
|
|
287
|
+
const above = keys[i];
|
|
288
|
+
const afterRange = below !== undefined && below > prefix && !below.startsWith(prefix);
|
|
289
|
+
if (afterRange)
|
|
290
|
+
return;
|
|
291
|
+
const beforeRange = above !== undefined && above < prefix;
|
|
292
|
+
if (!beforeRange)
|
|
293
|
+
await walkEntries(adapter, node.children[i] ?? null, prefix, visit);
|
|
294
|
+
if (above !== undefined && above.startsWith(prefix))
|
|
295
|
+
visit(above, node.values[i]);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
/** Collects the CID of every node reachable from `cid`. */
|
|
299
|
+
async function collectCids(adapter, cid, out = new Set()) {
|
|
300
|
+
if (cid === null || out.has(cid))
|
|
301
|
+
return out;
|
|
302
|
+
out.add(cid);
|
|
303
|
+
const node = await loadNode(adapter, cid);
|
|
304
|
+
for (const child of node.children) {
|
|
305
|
+
await collectCids(adapter, child ?? null, out);
|
|
306
|
+
}
|
|
307
|
+
return out;
|
|
308
|
+
}
|
|
309
|
+
// ------------------------------------------------------------ public API
|
|
310
|
+
/**
|
|
311
|
+
* Every node CID reachable from a root: the tree as it stands, without the
|
|
312
|
+
* orphans older versions left behind in the store. Sync uses it to decide
|
|
313
|
+
* which of a peer's subtrees it already holds; garbage collection uses it to
|
|
314
|
+
* decide what to keep.
|
|
315
|
+
* @param adapter The storage adapter.
|
|
316
|
+
* @param rootCid The root, or null for an empty tree.
|
|
317
|
+
*/
|
|
318
|
+
export async function collectReachableCids(adapter, rootCid) {
|
|
319
|
+
return collectCids(adapter, rootCid);
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Insert a key-value pair into the MST.
|
|
323
|
+
* @param adapter The storage adapter.
|
|
324
|
+
* @param rootCid The current root, or null for an empty tree.
|
|
325
|
+
* @param key The key to insert.
|
|
326
|
+
* @param value The value to store against it.
|
|
327
|
+
* @returns The new root CID.
|
|
328
|
+
*/
|
|
329
|
+
export async function insertIntoMST(adapter, rootCid, key, value) {
|
|
330
|
+
const keyHeight = await nodeHeight(key);
|
|
331
|
+
if (rootCid === null)
|
|
332
|
+
return singleton(adapter, key, value, keyHeight, keyHeight);
|
|
333
|
+
const root = await loadNode(adapter, rootCid);
|
|
334
|
+
if (keyHeight > root.height) {
|
|
335
|
+
// The key outranks everything already stored, so it becomes the new root
|
|
336
|
+
// and the existing tree is split to sit beneath it.
|
|
337
|
+
const [left, right] = await splitSubtree(adapter, rootCid, key);
|
|
338
|
+
return saveNode(adapter, {
|
|
339
|
+
height: keyHeight,
|
|
340
|
+
keys: [key],
|
|
341
|
+
values: [value],
|
|
342
|
+
children: [
|
|
343
|
+
await lift(adapter, left, root.height, keyHeight - 1),
|
|
344
|
+
await lift(adapter, right, root.height, keyHeight - 1)
|
|
345
|
+
]
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
return insertInto(adapter, rootCid, root.height, key, value, keyHeight);
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Delete a key from the MST.
|
|
352
|
+
* @param adapter The storage adapter.
|
|
353
|
+
* @param rootCid The current root, or null for an empty tree.
|
|
354
|
+
* @param key The key to remove.
|
|
355
|
+
* @returns The new root CID, or null once the tree is empty.
|
|
356
|
+
*/
|
|
357
|
+
export async function deleteFromMST(adapter, rootCid, key) {
|
|
358
|
+
if (!rootCid)
|
|
359
|
+
return null;
|
|
360
|
+
const keyHeight = await nodeHeight(key);
|
|
361
|
+
let next = await deleteFrom(adapter, rootCid, key, keyHeight);
|
|
362
|
+
// Removing the tallest key can leave empty wrappers on top; drop them so the
|
|
363
|
+
// root is always the highest node that actually holds a key.
|
|
364
|
+
while (next !== null) {
|
|
365
|
+
const node = await loadNode(adapter, next);
|
|
366
|
+
if (node.keys.length > 0)
|
|
367
|
+
break;
|
|
368
|
+
next = node.children[0] ?? null;
|
|
369
|
+
}
|
|
370
|
+
return next;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Lookup a value by key.
|
|
374
|
+
* @param adapter The storage adapter.
|
|
375
|
+
* @param rootCid The root to search from.
|
|
376
|
+
* @param key The key to find.
|
|
377
|
+
* @returns The value, or null when absent.
|
|
378
|
+
*/
|
|
379
|
+
export async function lookupInMST(adapter, rootCid, key) {
|
|
380
|
+
let cid = rootCid;
|
|
381
|
+
while (cid !== null) {
|
|
382
|
+
const node = await loadNode(adapter, cid);
|
|
383
|
+
const idx = lowerBound(node.keys, key);
|
|
384
|
+
if (node.keys[idx] === key)
|
|
385
|
+
return node.values[idx];
|
|
386
|
+
cid = node.children[idx] ?? null;
|
|
387
|
+
}
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Lists entries — keys with their values — in key order: all of them, or
|
|
392
|
+
* those under a prefix, reading only the nodes that can hold them.
|
|
393
|
+
* @param adapter The storage adapter.
|
|
394
|
+
* @param rootCid The root, or null for an empty tree.
|
|
395
|
+
* @param prefix Only keys starting with this
|
|
396
|
+
*/
|
|
397
|
+
export async function listMSTEntries(adapter, rootCid, prefix = '') {
|
|
398
|
+
const entries = [];
|
|
399
|
+
await walkEntries(adapter, rootCid, prefix, (key, value) => { entries.push({ key, value }); });
|
|
400
|
+
return entries;
|
|
401
|
+
}
|
|
402
|
+
//# sourceMappingURL=mst.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mst.js","sourceRoot":"","sources":["../../src/storage/mst.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAG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1D,MAAM,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/F,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module storage-provider
|
|
3
|
+
* A space's store: record versions, and the Merkle Search Tree that indexes them.
|
|
4
|
+
*
|
|
5
|
+
* The tree maps **record keys to version ids**:
|
|
6
|
+
*
|
|
7
|
+
* ```
|
|
8
|
+
* r/<key> → the current version (every record)
|
|
9
|
+
* g/<key> → the record's first version (once it has been edited)
|
|
10
|
+
* h/<key>/<seq>/<id> → a superseded version (only if marked `retain`)
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* A version that arrives is compared with the one at `r/<key>` by the ordering
|
|
14
|
+
* rule (`records/version.ts`). The winner takes `r/<key>`; the loser's body is
|
|
15
|
+
* dropped — unless it is the record's first version, kept as proof of who
|
|
16
|
+
* created it, or its writer marked it `retain`. The same set of versions gives
|
|
17
|
+
* the same tree whatever order they arrive in, which is what lets two peers
|
|
18
|
+
* converge.
|
|
19
|
+
*/
|
|
20
|
+
import type { StorageAdapter, Expression } from '../types.js';
|
|
21
|
+
export interface StorageProvider {
|
|
22
|
+
/**
|
|
23
|
+
* Takes in a version of a record: it becomes current if it supersedes the
|
|
24
|
+
* current one, and is kept or dropped otherwise. Idempotent.
|
|
25
|
+
* @returns The new tree root
|
|
26
|
+
*/
|
|
27
|
+
addExpression(expression: Expression): Promise<string | null>;
|
|
28
|
+
/** Drops a version from the tree and the store, wherever it is indexed. */
|
|
29
|
+
removeExpression(id: string): Promise<string | null>;
|
|
30
|
+
/** A version by its id, current or not, if this store holds it. */
|
|
31
|
+
getExpression(id: string): Promise<Expression | null>;
|
|
32
|
+
/** The current version of a record — possibly a delete. */
|
|
33
|
+
getCurrent(key: string): Promise<Expression | null>;
|
|
34
|
+
/** The record's first version, when it has been edited and so is stored apart. */
|
|
35
|
+
getGenesis(key: string): Promise<Expression | null>;
|
|
36
|
+
/** Every version of a record this store keeps: current, first, and retained. Newest first. */
|
|
37
|
+
history(key: string): Promise<Expression[]>;
|
|
38
|
+
/** {@link history} for every record whose key starts with `prefix`, reading only that part of the tree. */
|
|
39
|
+
histories(prefix: string): Promise<Map<string, Expression[]>>;
|
|
40
|
+
/** Current versions of every record, deletes included. */
|
|
41
|
+
listCurrent(): Promise<Expression[]>;
|
|
42
|
+
/** Current versions in one collection, deletes included — found through the store's collection index. */
|
|
43
|
+
queryExpressions(collection: string): Promise<Expression[]>;
|
|
44
|
+
/** Every tree entry, for sync and copying: `r/…`, `g/…`, `h/…` keys and the version ids under them. */
|
|
45
|
+
entries(): Promise<Array<{
|
|
46
|
+
key: string;
|
|
47
|
+
value: string;
|
|
48
|
+
}>>;
|
|
49
|
+
/** Get the current MST root CID. */
|
|
50
|
+
getRootCid(): Promise<string | null>;
|
|
51
|
+
/**
|
|
52
|
+
* Deletes the tree nodes the root no longer reaches. Every change rewrites
|
|
53
|
+
* the path to one entry and leaves the old path behind, so without this a
|
|
54
|
+
* store grows with every edit ever made rather than with its records.
|
|
55
|
+
*
|
|
56
|
+
* Tabs share a browser's store, and a change another tab has in flight may
|
|
57
|
+
* build on nodes this one's root has left. So a node is deleted only once it
|
|
58
|
+
* was already unreachable at a compaction at least `graceMs` earlier —
|
|
59
|
+
* remembered in the store, so it holds across sessions. A store whose other
|
|
60
|
+
* writers can lag by more than that — a folder behind a sync service — must
|
|
61
|
+
* not be compacted at all.
|
|
62
|
+
* @returns How many nodes were deleted
|
|
63
|
+
*/
|
|
64
|
+
compact(): Promise<number>;
|
|
65
|
+
/** Get the underlying storage adapter. */
|
|
66
|
+
getAdapter(): StorageAdapter;
|
|
67
|
+
/** Close the storage adapter. */
|
|
68
|
+
close(): Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
export interface StorageProviderOptions {
|
|
71
|
+
/** Compact on its own after this many changes (see `compact`). Off by default. */
|
|
72
|
+
readonly compactEvery?: number;
|
|
73
|
+
/** How long a node stays unreachable before `compact` deletes it. Default a minute. */
|
|
74
|
+
readonly graceMs?: number;
|
|
75
|
+
}
|
|
76
|
+
export declare const CURRENT_PREFIX = "r/";
|
|
77
|
+
export declare const GENESIS_PREFIX = "g/";
|
|
78
|
+
export declare const HISTORY_PREFIX = "h/";
|
|
79
|
+
/**
|
|
80
|
+
* Creates a StorageProvider wrapping an adapter.
|
|
81
|
+
* @param adapter The initialized storage adapter.
|
|
82
|
+
* @returns The StorageProvider orchestrator.
|
|
83
|
+
*/
|
|
84
|
+
export declare function createStorageProvider(adapter: StorageAdapter, options?: StorageProviderOptions): StorageProvider;
|
|
85
|
+
//# sourceMappingURL=storage-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-provider.d.ts","sourceRoot":"","sources":["../../src/storage/storage-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAW,MAAM,aAAa,CAAC;AAKvE,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,aAAa,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC9D,2EAA2E;IAC3E,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACrD,mEAAmE;IACnE,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IACtD,2DAA2D;IAC3D,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IACpD,kFAAkF;IAClF,UAAU,CAA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