@dxos/echo-pipeline 0.6.12 → 0.6.13-main.548ca8d

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.
Files changed (123) hide show
  1. package/dist/lib/browser/chunk-PESZVYAN.mjs +2050 -0
  2. package/dist/lib/browser/chunk-PESZVYAN.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +3463 -17
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +3 -4
  7. package/dist/lib/browser/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-7HHYCGUR.cjs → chunk-6EZVIJNE.cjs} +89 -47
  9. package/dist/lib/node/chunk-6EZVIJNE.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +3440 -35
  11. package/dist/lib/node/index.cjs.map +4 -4
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/testing/index.cjs +11 -12
  14. package/dist/lib/node/testing/index.cjs.map +3 -3
  15. package/dist/lib/{browser/chunk-UKXIJW43.mjs → node-esm/chunk-4LW7MDPZ.mjs} +76 -36
  16. package/dist/lib/node-esm/chunk-4LW7MDPZ.mjs.map +7 -0
  17. package/dist/lib/{browser/chunk-MPWFDDQK.mjs → node-esm/index.mjs} +1702 -335
  18. package/dist/lib/node-esm/index.mjs.map +7 -0
  19. package/dist/lib/node-esm/meta.json +1 -0
  20. package/dist/lib/node-esm/testing/index.mjs +551 -0
  21. package/dist/lib/node-esm/testing/index.mjs.map +7 -0
  22. package/dist/types/src/automerge/automerge-host.d.ts +24 -1
  23. package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
  24. package/dist/types/src/automerge/collection-synchronizer.d.ts +2 -0
  25. package/dist/types/src/automerge/collection-synchronizer.d.ts.map +1 -1
  26. package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -1
  27. package/dist/types/src/automerge/echo-replicator.d.ts +3 -3
  28. package/dist/types/src/automerge/echo-replicator.d.ts.map +1 -1
  29. package/dist/types/src/automerge/mesh-echo-replicator-connection.d.ts +3 -3
  30. package/dist/types/src/automerge/mesh-echo-replicator-connection.d.ts.map +1 -1
  31. package/dist/types/src/automerge/mesh-echo-replicator.d.ts.map +1 -1
  32. package/dist/types/src/automerge/space-collection.d.ts +3 -2
  33. package/dist/types/src/automerge/space-collection.d.ts.map +1 -1
  34. package/dist/types/src/db-host/automerge-metrics.d.ts +11 -0
  35. package/dist/types/src/db-host/automerge-metrics.d.ts.map +1 -0
  36. package/dist/types/src/db-host/data-service.d.ts +3 -2
  37. package/dist/types/src/db-host/data-service.d.ts.map +1 -1
  38. package/dist/types/src/db-host/database-root.d.ts +20 -0
  39. package/dist/types/src/db-host/database-root.d.ts.map +1 -0
  40. package/dist/types/src/db-host/documents-iterator.d.ts +7 -0
  41. package/dist/types/src/db-host/documents-iterator.d.ts.map +1 -0
  42. package/dist/types/src/db-host/echo-host.d.ts +73 -0
  43. package/dist/types/src/db-host/echo-host.d.ts.map +1 -0
  44. package/dist/types/src/db-host/index.d.ts +5 -0
  45. package/dist/types/src/db-host/index.d.ts.map +1 -1
  46. package/dist/types/src/db-host/migration.d.ts +8 -0
  47. package/dist/types/src/db-host/migration.d.ts.map +1 -0
  48. package/dist/types/src/db-host/query-service.d.ts +25 -0
  49. package/dist/types/src/db-host/query-service.d.ts.map +1 -0
  50. package/dist/types/src/db-host/query-state.d.ts +41 -0
  51. package/dist/types/src/db-host/query-state.d.ts.map +1 -0
  52. package/dist/types/src/db-host/space-state-manager.d.ts +23 -0
  53. package/dist/types/src/db-host/space-state-manager.d.ts.map +1 -0
  54. package/dist/types/src/edge/echo-edge-replicator.d.ts +23 -0
  55. package/dist/types/src/edge/echo-edge-replicator.d.ts.map +1 -0
  56. package/dist/types/src/edge/echo-edge-replicator.test.d.ts +2 -0
  57. package/dist/types/src/edge/echo-edge-replicator.test.d.ts.map +1 -0
  58. package/dist/types/src/edge/index.d.ts +2 -0
  59. package/dist/types/src/edge/index.d.ts.map +1 -0
  60. package/dist/types/src/index.d.ts +1 -0
  61. package/dist/types/src/index.d.ts.map +1 -1
  62. package/dist/types/src/metadata/metadata-store.d.ts +4 -1
  63. package/dist/types/src/metadata/metadata-store.d.ts.map +1 -1
  64. package/dist/types/src/testing/test-agent-builder.d.ts.map +1 -1
  65. package/dist/types/src/testing/test-replicator.d.ts +4 -4
  66. package/dist/types/src/testing/test-replicator.d.ts.map +1 -1
  67. package/package.json +40 -50
  68. package/src/automerge/automerge-host.test.ts +8 -9
  69. package/src/automerge/automerge-host.ts +46 -7
  70. package/src/automerge/automerge-repo.test.ts +18 -16
  71. package/src/automerge/collection-synchronizer.test.ts +10 -5
  72. package/src/automerge/collection-synchronizer.ts +17 -6
  73. package/src/automerge/echo-data-monitor.test.ts +1 -3
  74. package/src/automerge/echo-network-adapter.test.ts +4 -3
  75. package/src/automerge/echo-network-adapter.ts +5 -4
  76. package/src/automerge/echo-replicator.ts +3 -3
  77. package/src/automerge/mesh-echo-replicator-connection.ts +10 -9
  78. package/src/automerge/mesh-echo-replicator.ts +2 -1
  79. package/src/automerge/space-collection.ts +3 -2
  80. package/src/automerge/storage-adapter.test.ts +2 -3
  81. package/src/db-host/automerge-metrics.ts +38 -0
  82. package/src/db-host/data-service.ts +29 -14
  83. package/src/db-host/database-root.ts +86 -0
  84. package/src/db-host/documents-iterator.ts +73 -0
  85. package/src/db-host/documents-synchronizer.test.ts +2 -2
  86. package/src/db-host/echo-host.ts +257 -0
  87. package/src/db-host/index.ts +6 -1
  88. package/src/db-host/migration.ts +57 -0
  89. package/src/db-host/query-service.ts +208 -0
  90. package/src/db-host/query-state.ts +200 -0
  91. package/src/db-host/space-state-manager.ts +90 -0
  92. package/src/edge/echo-edge-replicator.test.ts +96 -0
  93. package/src/edge/echo-edge-replicator.ts +337 -0
  94. package/src/edge/index.ts +5 -0
  95. package/src/index.ts +1 -0
  96. package/src/metadata/metadata-store.ts +20 -0
  97. package/src/pipeline/pipeline-stress.test.ts +44 -47
  98. package/src/pipeline/pipeline.test.ts +3 -4
  99. package/src/space/control-pipeline.test.ts +2 -3
  100. package/src/space/control-pipeline.ts +10 -1
  101. package/src/space/replication.browser.test.ts +2 -8
  102. package/src/space/space-manager.browser.test.ts +6 -5
  103. package/src/space/space-protocol.browser.test.ts +29 -34
  104. package/src/space/space-protocol.test.ts +29 -27
  105. package/src/space/space.test.ts +28 -11
  106. package/src/testing/test-agent-builder.ts +2 -2
  107. package/src/testing/test-replicator.ts +3 -3
  108. package/dist/lib/browser/chunk-MPWFDDQK.mjs.map +0 -7
  109. package/dist/lib/browser/chunk-UKXIJW43.mjs.map +0 -7
  110. package/dist/lib/browser/chunk-XPCF2V5U.mjs +0 -31
  111. package/dist/lib/browser/chunk-XPCF2V5U.mjs.map +0 -7
  112. package/dist/lib/browser/light.mjs +0 -32
  113. package/dist/lib/browser/light.mjs.map +0 -7
  114. package/dist/lib/node/chunk-5DH4KR2S.cjs +0 -2148
  115. package/dist/lib/node/chunk-5DH4KR2S.cjs.map +0 -7
  116. package/dist/lib/node/chunk-7HHYCGUR.cjs.map +0 -7
  117. package/dist/lib/node/chunk-DZVH7HDD.cjs +0 -43
  118. package/dist/lib/node/chunk-DZVH7HDD.cjs.map +0 -7
  119. package/dist/lib/node/light.cjs +0 -52
  120. package/dist/lib/node/light.cjs.map +0 -7
  121. package/dist/types/src/light.d.ts +0 -4
  122. package/dist/types/src/light.d.ts.map +0 -1
  123. package/src/light.ts +0 -7
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/testing/change-metadata.ts", "../../../../src/testing/test-agent-builder.ts", "../../../../src/testing/test-feed-builder.ts", "../../../../src/testing/test-network-adapter.ts", "../../../../src/testing/test-replicator.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { log } from '@dxos/log';\nimport { schema } from '@dxos/protocols/proto';\nimport type { Storage } from '@dxos/random-access-storage';\n\nimport { MetadataStore } from '../metadata';\n\nconst EchoMetadata = schema.getCodecForType('dxos.echo.metadata.EchoMetadata');\n\n/**\n * This function will change the storage version in the metadata.\n * This will break your storage and make it unusable.\n * Use this only for testing purposes.\n */\nexport const changeStorageVersionInMetadata = async (storage: Storage, version: number) => {\n log.info('Changing storage version in metadata. USE ONLY FOR TESTING.');\n const metadata = new MetadataStore(storage.createDirectory('metadata'));\n await metadata.load();\n const echoMetadata = metadata.metadata;\n echoMetadata.version = version;\n const file = metadata._directory.getOrCreateFile('EchoMetadata');\n await metadata._writeFile(file, EchoMetadata, echoMetadata);\n await metadata._directory.flush();\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { Context } from '@dxos/context';\nimport { CredentialGenerator } from '@dxos/credentials';\nimport { type FeedStore } from '@dxos/feed-store';\nimport { type Keyring } from '@dxos/keyring';\nimport { PublicKey } from '@dxos/keys';\nimport { MemorySignalManager, MemorySignalManagerContext, WebsocketSignalManager } from '@dxos/messaging';\nimport { MemoryTransportFactory, SwarmNetworkManager, createSimplePeerTransportFactory } from '@dxos/network-manager';\nimport type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';\nimport { type SpaceMetadata } from '@dxos/protocols/proto/dxos/echo/metadata';\nimport { AdmittedFeed } from '@dxos/protocols/proto/dxos/halo/credentials';\nimport { StorageType, createStorage, type Storage } from '@dxos/random-access-storage';\nimport { Gossip, Presence } from '@dxos/teleport-extension-gossip';\nimport { BlobStore } from '@dxos/teleport-extension-object-sync';\nimport { ComplexMap } from '@dxos/util';\n\nimport { TestFeedBuilder } from './test-feed-builder';\nimport { MetadataStore } from '../metadata';\nimport { MOCK_AUTH_PROVIDER, MOCK_AUTH_VERIFIER, SpaceManager, SpaceProtocol, type Space } from '../space';\n\nexport type NetworkManagerProvider = () => SwarmNetworkManager;\n\nexport const MemoryNetworkManagerProvider =\n (signalContext: MemorySignalManagerContext): NetworkManagerProvider =>\n () =>\n new SwarmNetworkManager({\n signalManager: new MemorySignalManager(signalContext),\n transportFactory: MemoryTransportFactory,\n });\n\nexport const WebsocketNetworkManagerProvider =\n (signalUrl: string): NetworkManagerProvider =>\n () =>\n new SwarmNetworkManager({\n signalManager: new WebsocketSignalManager([{ server: signalUrl }]),\n transportFactory: createSimplePeerTransportFactory(),\n });\n\nexport type TestAgentBuilderOptions = {\n storage?: Storage;\n networkManagerProvider?: NetworkManagerProvider;\n};\n\n/**\n * Factory for test agents.\n */\nexport class TestAgentBuilder {\n private readonly _agents = new ComplexMap<PublicKey, TestAgent>(PublicKey.hash);\n private readonly _storage: Storage;\n private readonly _networkManagerProvider: NetworkManagerProvider;\n\n constructor({ storage, networkManagerProvider }: TestAgentBuilderOptions = {}) {\n this._storage = storage ?? createStorage({ type: StorageType.RAM });\n this._networkManagerProvider =\n networkManagerProvider ?? MemoryNetworkManagerProvider(new MemorySignalManagerContext());\n }\n\n async close() {\n return Promise.all(this.agents.map((agent) => agent.close()));\n }\n\n get agents() {\n return Array.from(this._agents.values());\n }\n\n getAgent(deviceKey: PublicKey) {\n return this._agents.get(deviceKey);\n }\n\n async createPeer(): Promise<TestAgent> {\n // prettier-ignore\n const feedBuilder = new TestFeedBuilder()\n .setStorage(this._storage, `agent-${this._agents.size}`);\n\n const identityKey = await feedBuilder.keyring.createKey();\n const deviceKey = await feedBuilder.keyring.createKey();\n\n const agent = new TestAgent(this._networkManagerProvider, feedBuilder, identityKey, deviceKey);\n this._agents.set(deviceKey, agent);\n return agent;\n }\n}\n\n/**\n * Test agent that enables the creation and replication of multiple spaces.\n */\nexport class TestAgent {\n private readonly _spaces = new ComplexMap<PublicKey, Space>(PublicKey.hash);\n\n public readonly storage: Storage;\n public readonly keyring: Keyring;\n public readonly feedStore: FeedStore<FeedMessage>;\n\n private _metadataStore?: MetadataStore;\n get metadataStore() {\n return (this._metadataStore ??= new MetadataStore(this.storage.createDirectory('metadata')));\n }\n\n private _blobStore?: BlobStore;\n get blobStore() {\n return (this._blobStore ??= new BlobStore(this.storage.createDirectory('blobs')));\n }\n\n constructor(\n private readonly _networkManagerProvider: NetworkManagerProvider,\n private readonly _feedBuilder: TestFeedBuilder,\n public readonly identityKey: PublicKey,\n public readonly deviceKey: PublicKey,\n ) {\n this.storage = this._feedBuilder.storage;\n this.keyring = this._feedBuilder.keyring;\n this.feedStore = this._feedBuilder.createFeedStore();\n }\n\n async close() {\n return Promise.all([...this.spaces.map((space) => space.close())]);\n }\n\n get spaces() {\n return Array.from(this._spaces.values());\n }\n\n getSpace(spaceKey: PublicKey) {\n return this._spaces.get(spaceKey);\n }\n\n private _spaceManager?: SpaceManager;\n get spaceManager() {\n return (this._spaceManager ??= new SpaceManager({\n feedStore: this.feedStore,\n networkManager: this._networkManagerProvider(),\n metadataStore: this.metadataStore,\n blobStore: this.blobStore,\n }));\n }\n\n async createSpace(\n identityKey: PublicKey = this.identityKey,\n spaceKey?: PublicKey,\n genesisKey?: PublicKey,\n dataKey?: PublicKey,\n saveMetadata = false,\n ): Promise<Space> {\n if (!spaceKey) {\n saveMetadata = true;\n spaceKey = await this.keyring.createKey();\n }\n if (!genesisKey) {\n genesisKey = await this.keyring.createKey();\n }\n\n const controlFeed = await this.feedStore.openFeed(genesisKey, { writable: true });\n const dataFeed = await this.feedStore.openFeed(dataKey ?? (await this.keyring.createKey()), {\n writable: true,\n sparse: true,\n });\n\n const metadata: SpaceMetadata = {\n key: spaceKey,\n genesisFeedKey: genesisKey,\n controlFeedKey: controlFeed.key,\n dataFeedKey: dataFeed.key,\n };\n if (saveMetadata) {\n await this.metadataStore.addSpace(metadata);\n }\n\n await this.spaceManager.open();\n const space = await this.spaceManager.constructSpace({\n metadata,\n swarmIdentity: {\n identityKey: this.identityKey,\n peerKey: this.deviceKey,\n credentialProvider: MOCK_AUTH_PROVIDER,\n credentialAuthenticator: MOCK_AUTH_VERIFIER,\n },\n memberKey: identityKey,\n onAuthorizedConnection: (session) => {\n session.addExtension(\n 'dxos.mesh.teleport.gossip',\n this.createGossip().createExtension({ remotePeerId: session.remotePeerId }),\n );\n },\n onDelegatedInvitationStatusChange: async () => {},\n onMemberRolesChanged: async () => {},\n });\n await space.setControlFeed(controlFeed);\n await space.setDataFeed(dataFeed);\n\n await space.open(new Context());\n\n this._spaces.set(spaceKey, space);\n return space;\n }\n\n createSpaceProtocol(topic: PublicKey, gossip?: Gossip) {\n return new SpaceProtocol({\n topic,\n swarmIdentity: {\n identityKey: this.identityKey,\n peerKey: this.deviceKey,\n credentialProvider: MOCK_AUTH_PROVIDER,\n credentialAuthenticator: MOCK_AUTH_VERIFIER,\n },\n networkManager: this._networkManagerProvider(),\n blobStore: this.blobStore,\n onSessionAuth: (session) => {\n session.addExtension(\n 'dxos.mesh.teleport.gossip',\n (gossip ?? this.createGossip()).createExtension({ remotePeerId: session.remotePeerId }),\n );\n },\n });\n }\n\n createGossip() {\n return new Gossip({\n localPeerId: this.deviceKey,\n });\n }\n\n createPresence(gossip?: Gossip) {\n return new Presence({\n announceInterval: 30,\n offlineTimeout: 200,\n identityKey: this.identityKey,\n gossip: gossip ?? this.createGossip(),\n });\n }\n\n async spaceGenesis(space: Space) {\n const generator = new CredentialGenerator(this.keyring, this.identityKey, this.deviceKey);\n const credentials = [\n ...(await generator.createSpaceGenesis(space.key, space.controlFeedKey!)),\n await generator.createFeedAdmission(space.key, space.dataFeedKey!, AdmittedFeed.Designation.DATA),\n await generator.createEpochCredential(space.key),\n ];\n\n for (const credential of credentials) {\n await space.controlPipeline.writer.write({\n credential: { credential },\n });\n }\n }\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { TestBuilder } from '@dxos/feed-store/testing';\nimport type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';\n\nimport { valueEncoding } from '../common';\n\n/**\n * Builder with default encoder and generator.\n */\nexport class TestFeedBuilder extends TestBuilder<FeedMessage> {\n constructor() {\n super({\n valueEncoding,\n });\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { Trigger, sleep } from '@dxos/async';\nimport { type Message, NetworkAdapter, type PeerId } from '@dxos/automerge/automerge-repo';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nexport type TestConnectionStateProvider = () => 'on' | 'off';\n\nexport class TestAdapter extends NetworkAdapter {\n static createPair(connectionStateProvider: TestConnectionStateProvider = () => 'on') {\n const adapter1: TestAdapter = new TestAdapter({\n send: (message: Message) => connectionStateProvider() === 'on' && sleep(10).then(() => adapter2.receive(message)),\n });\n const adapter2: TestAdapter = new TestAdapter({\n send: (message: Message) => connectionStateProvider() === 'on' && sleep(10).then(() => adapter1.receive(message)),\n });\n\n return [adapter1, adapter2];\n }\n\n public onConnect = new Trigger();\n\n constructor(private readonly _params: { send: (message: Message) => void }) {\n super();\n }\n\n // NOTE: Emitting `ready` event in NetworkAdapter`s constructor causes a race condition\n // because `Repo` waits for `ready` event (which it never receives) before it starts using the adapter.\n ready() {\n this.emit('ready', { network: this });\n }\n\n override connect(peerId: PeerId) {\n this.peerId = peerId;\n this.onConnect.wake();\n }\n\n peerCandidate(peerId: PeerId) {\n invariant(peerId, 'PeerId is required');\n this.emit('peer-candidate', { peerId, peerMetadata: {} });\n }\n\n peerDisconnected(peerId: PeerId) {\n invariant(peerId, 'PeerId is required');\n this.emit('peer-disconnected', { peerId });\n }\n\n override send(message: Message) {\n log('send', { from: message.senderId, to: message.targetId, type: message.type });\n this._params.send(message);\n }\n\n override disconnect() {\n this.peerId = undefined;\n }\n\n receive(message: Message) {\n invariant(this.peerId, 'Peer id is not set');\n this.emit('message', message);\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { sleep, synchronized } from '@dxos/async';\nimport { type Message } from '@dxos/automerge/automerge-repo';\nimport { type Context, LifecycleState, Resource } from '@dxos/context';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { AutomergeReplicator, type AutomergeReplicatorFactory } from '@dxos/teleport-extension-automerge-replicator';\n\nimport type {\n EchoReplicator,\n EchoReplicatorContext,\n ReplicatorConnection,\n ShouldAdvertiseParams,\n ShouldSyncCollectionParams,\n} from '../automerge';\n\nexport type TestReplicatorNetworkOptions = {\n latency?: number;\n};\n\nexport class TestReplicationNetwork extends Resource {\n private readonly _replicators = new Set<TestReplicator>();\n private readonly _latency?: number = undefined;\n\n constructor(options: TestReplicatorNetworkOptions = {}) {\n super();\n this._latency = options.latency;\n }\n\n protected override async _close(ctx: Context): Promise<void> {\n for (const replicator of this._replicators) {\n for (const connection of replicator.connections) {\n void connection.writable.abort();\n void connection.readable.cancel();\n }\n }\n }\n\n async createReplicator(): Promise<TestReplicator> {\n const replicator = new TestReplicator({\n onConnect: async () => {\n invariant(this._lifecycleState === LifecycleState.OPEN);\n await this._connectReplicator(replicator);\n },\n onDisconnect: async () => {\n invariant(this._lifecycleState === LifecycleState.OPEN);\n await this._disconnectReplicator(replicator);\n },\n });\n this._replicators.add(replicator);\n return replicator;\n }\n\n @synchronized\n private async _connectReplicator(replicator: TestReplicator) {\n for (const otherReplicator of this._replicators.values()) {\n if (otherReplicator === replicator || !otherReplicator.connected) {\n continue;\n }\n log('create connection', { from: replicator.context!.peerId, to: otherReplicator.context!.peerId });\n const [connection1, connection2] = this._createConnectionPair(\n replicator.context!.peerId,\n otherReplicator.context!.peerId,\n );\n await replicator.context!.onConnectionOpen(connection1);\n await otherReplicator.context!.onConnectionOpen(connection2);\n }\n }\n\n private async _disconnectReplicator(replicator: TestReplicator) {\n for (const connection of replicator.connections) {\n await replicator.context!.onConnectionClosed(connection);\n await connection.otherSide!.owningReplicator!.removeConnection(connection.otherSide!);\n }\n }\n\n private _createConnectionPair(peer1: string, peer2: string): [TestReplicatorConnection, TestReplicatorConnection] {\n const LOG = false;\n\n const forward = new TransformStream({\n transform: async (message, controller) => {\n if (LOG) {\n log.info('replicate', { from: peer1, to: peer2, message });\n }\n\n if (this._latency !== undefined) {\n await sleep(this._latency);\n }\n\n controller.enqueue(message);\n },\n });\n const backwards = new TransformStream({\n transform: async (message, controller) => {\n if (LOG) {\n log.info('replicate', { from: peer2, to: peer1, message });\n }\n\n if (this._latency !== undefined) {\n await sleep(this._latency);\n }\n\n controller.enqueue(message);\n },\n });\n\n const connection1 = new TestReplicatorConnection(peer2, backwards.readable, forward.writable);\n const connection2 = new TestReplicatorConnection(peer1, forward.readable, backwards.writable);\n connection1.otherSide = connection2;\n connection2.otherSide = connection1;\n return [connection1, connection2];\n }\n}\n\ntype TestReplicatorParams = {\n onConnect: () => Promise<void>;\n onDisconnect: () => Promise<void>;\n};\n\nexport class TestReplicator implements EchoReplicator {\n constructor(private readonly _params: TestReplicatorParams) {}\n\n public connected = false;\n public context: EchoReplicatorContext | undefined = undefined;\n public connections = new Set<TestReplicatorConnection>();\n\n async connect(context: EchoReplicatorContext): Promise<void> {\n log('connect', { peerId: context.peerId });\n this.context = context;\n this.connected = true;\n await this._params.onConnect();\n }\n\n async disconnect(): Promise<void> {\n log('disconnect', { peerId: this.context!.peerId });\n this.connected = false;\n await this._params.onDisconnect();\n }\n\n async addConnection(connection: TestReplicatorConnection): Promise<void> {\n connection.owningReplicator = this;\n this.connections.add(connection);\n this.context!.onConnectionOpen(connection);\n }\n\n async removeConnection(connection: TestReplicatorConnection): Promise<void> {\n connection.owningReplicator = undefined;\n this.context!.onConnectionClosed(connection);\n this.connections.delete(connection);\n }\n}\n\nexport class TestReplicatorConnection implements ReplicatorConnection {\n public otherSide: TestReplicatorConnection | undefined = undefined;\n public owningReplicator: TestReplicator | undefined = undefined;\n\n constructor(\n public readonly peerId: string,\n public readonly readable: ReadableStream<Message>,\n public readonly writable: WritableStream<Message>,\n ) {}\n\n async shouldAdvertise(params: ShouldAdvertiseParams): Promise<boolean> {\n return true;\n }\n\n shouldSyncCollection(params: ShouldSyncCollectionParams): boolean {\n return true;\n }\n}\n\nexport const testAutomergeReplicatorFactory: AutomergeReplicatorFactory = (params) => {\n return new AutomergeReplicator(\n {\n ...params[0],\n sendSyncRetryPolicy: {\n retryBackoff: 20,\n retriesBeforeBackoff: 2,\n maxRetries: 3,\n },\n },\n params[1],\n );\n};\n\nexport const brokenAutomergeReplicatorFactory: AutomergeReplicatorFactory = (params) => {\n params[1]!.onSyncMessage = () => {\n throw new Error();\n };\n return testAutomergeReplicatorFactory(params);\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,iBAAoB;AACpB,mBAAuB;ACDvB,qBAAwB;AACxB,yBAAoC;AAGpC,kBAA0B;AAC1B,uBAAwF;AACxF,6BAA8F;AAG9F,IAAAA,sBAA6B;AAC7B,mCAAyD;AACzD,uCAAiC;AACjC,4CAA0B;AAC1B,kBAA2B;ACb3B,qBAA4B;ACA5B,mBAA+B;AAC/B,4BAA0D;AAC1D,uBAA0B;AAC1B,IAAAC,cAAoB;ACHpB,IAAAC,gBAAoC;AAEpC,IAAAC,kBAAuD;AACvD,IAAAC,oBAA0B;AAC1B,IAAAH,cAAoB;AACpB,qDAAqE;;AJCrE,IAAMI,eAAeC,oBAAOC,gBAAgB,iCAAA;AAOrC,IAAMC,iCAAiC,OAAOC,SAAkBC,YAAAA;AACrEC,iBAAIC,KAAK,+DAAA,QAAA;;;;;;AACT,QAAMC,WAAW,IAAIC,oCAAcL,QAAQM,gBAAgB,UAAA,CAAA;AAC3D,QAAMF,SAASG,KAAI;AACnB,QAAMC,eAAeJ,SAASA;AAC9BI,eAAaP,UAAUA;AACvB,QAAMQ,OAAOL,SAASM,WAAWC,gBAAgB,cAAA;AACjD,QAAMP,SAASQ,WAAWH,MAAMb,cAAcY,YAAAA;AAC9C,QAAMJ,SAASM,WAAWG,MAAK;AACjC;AEdO,IAAMC,kBAAN,cAA8BC,2BAAAA;EACnCC,cAAc;AACZ,UAAM;MACJC;IACF,CAAA;EACF;AACF;;ADOO,IAAMC,+BACX,CAACC,kBACD,MACE,IAAIC,2CAAoB;EACtBC,eAAe,IAAIC,qCAAoBH,aAAAA;EACvCI,kBAAkBC;AACpB,CAAA;AAEG,IAAMC,kCACX,CAACC,cACD,MACE,IAAIN,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AASK,mBAAmBrB,UAAAA;AACjC,SAAKC,YAAYoC,OAAOrC,UAAAA;EAC1B;AACF;AAEO,IAAMkC,2BAAN,MAAMA;EAIXrM,YACkB8I,QACAwB,UACA/F,UAChB;SAHgBuE,SAAAA;SACAwB,WAAAA;SACA/F,WAAAA;SANXkH,YAAkDjC;SAClDkC,mBAA+ClC;EAMnD;EAEH,MAAMiD,gBAAgBC,QAAiD;AACrE,WAAO;EACT;EAEAC,qBAAqBD,QAA6C;AAChE,WAAO;EACT;AACF;AAEO,IAAME,iCAA6D,CAACF,WAAAA;AACzE,SAAO,IAAIG,mEACT;IACE,GAAGH,OAAO,CAAA;IACVI,qBAAqB;MACnBC,cAAc;MACdC,sBAAsB;MACtBC,YAAY;IACd;EACF,GACAP,OAAO,CAAA,CAAE;AAEb;AAEO,IAAMQ,mCAA+D,CAACR,WAAAA;AAC3EA,SAAO,CAAA,EAAIS,gBAAgB,MAAA;AACzB,UAAM,IAAIC,MAAAA;EACZ;AACA,SAAOR,+BAA+BF,MAAAA;AACxC;",
6
- "names": ["import_credentials", "import_log", "import_async", "import_context", "import_invariant", "EchoMetadata", "schema", "getCodecForType", "changeStorageVersionInMetadata", "storage", "version", "log", "info", "metadata", "MetadataStore", "createDirectory", "load", "echoMetadata", "file", "_directory", "getOrCreateFile", "_writeFile", "flush", "TestFeedBuilder", "TestBuilder", "constructor", "valueEncoding", "MemoryNetworkManagerProvider", "signalContext", "SwarmNetworkManager", "signalManager", "MemorySignalManager", "transportFactory", "MemoryTransportFactory", "WebsocketNetworkManagerProvider", "signalUrl", "WebsocketSignalManager", "server", "createSimplePeerTransportFactory", "TestAgentBuilder", "networkManagerProvider", "_agents", "ComplexMap", "PublicKey", "hash", "_storage", "createStorage", "type", "StorageType", "RAM", "_networkManagerProvider", "MemorySignalManagerContext", "close", "Promise", "all", "agents", "map", "agent", "Array", "from", "values", "getAgent", "deviceKey", "get", "createPeer", "feedBuilder", "setStorage", "size", "identityKey", "keyring", "createKey", "TestAgent", "set", "metadataStore", "_metadataStore", "blobStore", "_blobStore", "BlobStore", "_feedBuilder", "_spaces", "feedStore", "createFeedStore", "spaces", "space", "getSpace", "spaceKey", "spaceManager", "_spaceManager", "SpaceManager", "networkManager", "createSpace", "genesisKey", "dataKey", "saveMetadata", "controlFeed", "openFeed", "writable", "dataFeed", "sparse", "key", "genesisFeedKey", "controlFeedKey", "dataFeedKey", "addSpace", "open", "constructSpace", "swarmIdentity", "peerKey", "credentialProvider", "MOCK_AUTH_PROVIDER", "credentialAuthenticator", "MOCK_AUTH_VERIFIER", "memberKey", "onAuthorizedConnection", "session", "addExtension", "createGossip", "createExtension", "remotePeerId", "onDelegatedInvitationStatusChange", "onMemberRolesChanged", "setControlFeed", "setDataFeed", "Context", "createSpaceProtocol", "topic", "gossip", "SpaceProtocol", "onSessionAuth", "Gossip", "localPeerId", "createPresence", "Presence", "announceInterval", "offlineTimeout", "spaceGenesis", "generator", "CredentialGenerator", "credentials", "createSpaceGenesis", "createFeedAdmission", "AdmittedFeed", "Designation", "DATA", "createEpochCredential", "credential", "controlPipeline", "writer", "write", "TestAdapter", "NetworkAdapter", "createPair", "connectionStateProvider", "adapter1", "send", "message", "sleep", "then", "adapter2", "receive", "_params", "onConnect", "Trigger", "ready", "emit", "network", "connect", "peerId", "wake", "peerCandidate", "invariant", "peerMetadata", "peerDisconnected", "senderId", "to", "targetId", "disconnect", "undefined", "TestReplicationNetwork", "Resource", "options", "_replicators", "Set", "_latency", "latency", "_close", "ctx", "replicator", "connection", "connections", "abort", "readable", "cancel", "createReplicator", "TestReplicator", "_lifecycleState", "LifecycleState", "OPEN", "_connectReplicator", "onDisconnect", "_disconnectReplicator", "add", "otherReplicator", "connected", "context", "connection1", "connection2", "_createConnectionPair", "onConnectionOpen", "onConnectionClosed", "otherSide", "owningReplicator", "removeConnection", "peer1", "peer2", "LOG", "forward", "TransformStream", "transform", "controller", "enqueue", "backwards", "TestReplicatorConnection", "synchronized", "addConnection", "delete", "shouldAdvertise", "params", "shouldSyncCollection", "testAutomergeReplicatorFactory", "AutomergeReplicator", "sendSyncRetryPolicy", "retryBackoff", "retriesBeforeBackoff", "maxRetries", "brokenAutomergeReplicatorFactory", "onSyncMessage", "Error"]
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { log } from '@dxos/log';\nimport { schema } from '@dxos/protocols/proto';\nimport type { Storage } from '@dxos/random-access-storage';\n\nimport { MetadataStore } from '../metadata';\n\nconst EchoMetadata = schema.getCodecForType('dxos.echo.metadata.EchoMetadata');\n\n/**\n * This function will change the storage version in the metadata.\n * This will break your storage and make it unusable.\n * Use this only for testing purposes.\n */\nexport const changeStorageVersionInMetadata = async (storage: Storage, version: number) => {\n log.info('Changing storage version in metadata. USE ONLY FOR TESTING.');\n const metadata = new MetadataStore(storage.createDirectory('metadata'));\n await metadata.load();\n const echoMetadata = metadata.metadata;\n echoMetadata.version = version;\n const file = metadata._directory.getOrCreateFile('EchoMetadata');\n await metadata._writeFile(file, EchoMetadata, echoMetadata);\n await metadata._directory.flush();\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { Context } from '@dxos/context';\nimport { CredentialGenerator } from '@dxos/credentials';\nimport { type FeedStore } from '@dxos/feed-store';\nimport { type Keyring } from '@dxos/keyring';\nimport { PublicKey } from '@dxos/keys';\nimport { MemorySignalManager, MemorySignalManagerContext, WebsocketSignalManager } from '@dxos/messaging';\nimport { MemoryTransportFactory, SwarmNetworkManager, createRtcTransportFactory } from '@dxos/network-manager';\nimport type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';\nimport { type SpaceMetadata } from '@dxos/protocols/proto/dxos/echo/metadata';\nimport { AdmittedFeed } from '@dxos/protocols/proto/dxos/halo/credentials';\nimport { StorageType, createStorage, type Storage } from '@dxos/random-access-storage';\nimport { Gossip, Presence } from '@dxos/teleport-extension-gossip';\nimport { BlobStore } from '@dxos/teleport-extension-object-sync';\nimport { ComplexMap } from '@dxos/util';\n\nimport { TestFeedBuilder } from './test-feed-builder';\nimport { MetadataStore } from '../metadata';\nimport { MOCK_AUTH_PROVIDER, MOCK_AUTH_VERIFIER, SpaceManager, SpaceProtocol, type Space } from '../space';\n\nexport type NetworkManagerProvider = () => SwarmNetworkManager;\n\nexport const MemoryNetworkManagerProvider =\n (signalContext: MemorySignalManagerContext): NetworkManagerProvider =>\n () =>\n new SwarmNetworkManager({\n signalManager: new MemorySignalManager(signalContext),\n transportFactory: MemoryTransportFactory,\n });\n\nexport const WebsocketNetworkManagerProvider =\n (signalUrl: string): NetworkManagerProvider =>\n () =>\n new SwarmNetworkManager({\n signalManager: new WebsocketSignalManager([{ server: signalUrl }]),\n transportFactory: createRtcTransportFactory(),\n });\n\nexport type TestAgentBuilderOptions = {\n storage?: Storage;\n networkManagerProvider?: NetworkManagerProvider;\n};\n\n/**\n * Factory for test agents.\n */\nexport class TestAgentBuilder {\n private readonly _agents = new ComplexMap<PublicKey, TestAgent>(PublicKey.hash);\n private readonly _storage: Storage;\n private readonly _networkManagerProvider: NetworkManagerProvider;\n\n constructor({ storage, networkManagerProvider }: TestAgentBuilderOptions = {}) {\n this._storage = storage ?? createStorage({ type: StorageType.RAM });\n this._networkManagerProvider =\n networkManagerProvider ?? MemoryNetworkManagerProvider(new MemorySignalManagerContext());\n }\n\n async close() {\n return Promise.all(this.agents.map((agent) => agent.close()));\n }\n\n get agents() {\n return Array.from(this._agents.values());\n }\n\n getAgent(deviceKey: PublicKey) {\n return this._agents.get(deviceKey);\n }\n\n async createPeer(): Promise<TestAgent> {\n // prettier-ignore\n const feedBuilder = new TestFeedBuilder()\n .setStorage(this._storage, `agent-${this._agents.size}`);\n\n const identityKey = await feedBuilder.keyring.createKey();\n const deviceKey = await feedBuilder.keyring.createKey();\n\n const agent = new TestAgent(this._networkManagerProvider, feedBuilder, identityKey, deviceKey);\n this._agents.set(deviceKey, agent);\n return agent;\n }\n}\n\n/**\n * Test agent that enables the creation and replication of multiple spaces.\n */\nexport class TestAgent {\n private readonly _spaces = new ComplexMap<PublicKey, Space>(PublicKey.hash);\n\n public readonly storage: Storage;\n public readonly keyring: Keyring;\n public readonly feedStore: FeedStore<FeedMessage>;\n\n private _metadataStore?: MetadataStore;\n get metadataStore() {\n return (this._metadataStore ??= new MetadataStore(this.storage.createDirectory('metadata')));\n }\n\n private _blobStore?: BlobStore;\n get blobStore() {\n return (this._blobStore ??= new BlobStore(this.storage.createDirectory('blobs')));\n }\n\n constructor(\n private readonly _networkManagerProvider: NetworkManagerProvider,\n private readonly _feedBuilder: TestFeedBuilder,\n public readonly identityKey: PublicKey,\n public readonly deviceKey: PublicKey,\n ) {\n this.storage = this._feedBuilder.storage;\n this.keyring = this._feedBuilder.keyring;\n this.feedStore = this._feedBuilder.createFeedStore();\n }\n\n async close() {\n return Promise.all([...this.spaces.map((space) => space.close())]);\n }\n\n get spaces() {\n return Array.from(this._spaces.values());\n }\n\n getSpace(spaceKey: PublicKey) {\n return this._spaces.get(spaceKey);\n }\n\n private _spaceManager?: SpaceManager;\n get spaceManager() {\n return (this._spaceManager ??= new SpaceManager({\n feedStore: this.feedStore,\n networkManager: this._networkManagerProvider(),\n metadataStore: this.metadataStore,\n blobStore: this.blobStore,\n }));\n }\n\n async createSpace(\n identityKey: PublicKey = this.identityKey,\n spaceKey?: PublicKey,\n genesisKey?: PublicKey,\n dataKey?: PublicKey,\n saveMetadata = false,\n ): Promise<Space> {\n if (!spaceKey) {\n saveMetadata = true;\n spaceKey = await this.keyring.createKey();\n }\n if (!genesisKey) {\n genesisKey = await this.keyring.createKey();\n }\n\n const controlFeed = await this.feedStore.openFeed(genesisKey, { writable: true });\n const dataFeed = await this.feedStore.openFeed(dataKey ?? (await this.keyring.createKey()), {\n writable: true,\n sparse: true,\n });\n\n const metadata: SpaceMetadata = {\n key: spaceKey,\n genesisFeedKey: genesisKey,\n controlFeedKey: controlFeed.key,\n dataFeedKey: dataFeed.key,\n };\n if (saveMetadata) {\n await this.metadataStore.addSpace(metadata);\n }\n\n await this.spaceManager.open();\n const space = await this.spaceManager.constructSpace({\n metadata,\n swarmIdentity: {\n identityKey: this.identityKey,\n peerKey: this.deviceKey,\n credentialProvider: MOCK_AUTH_PROVIDER,\n credentialAuthenticator: MOCK_AUTH_VERIFIER,\n },\n memberKey: identityKey,\n onAuthorizedConnection: (session) => {\n session.addExtension(\n 'dxos.mesh.teleport.gossip',\n this.createGossip().createExtension({ remotePeerId: session.remotePeerId }),\n );\n },\n onDelegatedInvitationStatusChange: async () => {},\n onMemberRolesChanged: async () => {},\n });\n await space.setControlFeed(controlFeed);\n await space.setDataFeed(dataFeed);\n\n await space.open(new Context());\n\n this._spaces.set(spaceKey, space);\n return space;\n }\n\n createSpaceProtocol(topic: PublicKey, gossip?: Gossip) {\n return new SpaceProtocol({\n topic,\n swarmIdentity: {\n identityKey: this.identityKey,\n peerKey: this.deviceKey,\n credentialProvider: MOCK_AUTH_PROVIDER,\n credentialAuthenticator: MOCK_AUTH_VERIFIER,\n },\n networkManager: this._networkManagerProvider(),\n blobStore: this.blobStore,\n onSessionAuth: (session) => {\n session.addExtension(\n 'dxos.mesh.teleport.gossip',\n (gossip ?? this.createGossip()).createExtension({ remotePeerId: session.remotePeerId }),\n );\n },\n });\n }\n\n createGossip() {\n return new Gossip({\n localPeerId: this.deviceKey,\n });\n }\n\n createPresence(gossip?: Gossip) {\n return new Presence({\n announceInterval: 30,\n offlineTimeout: 200,\n identityKey: this.identityKey,\n gossip: gossip ?? this.createGossip(),\n });\n }\n\n async spaceGenesis(space: Space) {\n const generator = new CredentialGenerator(this.keyring, this.identityKey, this.deviceKey);\n const credentials = [\n ...(await generator.createSpaceGenesis(space.key, space.controlFeedKey!)),\n await generator.createFeedAdmission(space.key, space.dataFeedKey!, AdmittedFeed.Designation.DATA),\n await generator.createEpochCredential(space.key),\n ];\n\n for (const credential of credentials) {\n await space.controlPipeline.writer.write({\n credential: { credential },\n });\n }\n }\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { TestBuilder } from '@dxos/feed-store/testing';\nimport type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';\n\nimport { valueEncoding } from '../common';\n\n/**\n * Builder with default encoder and generator.\n */\nexport class TestFeedBuilder extends TestBuilder<FeedMessage> {\n constructor() {\n super({\n valueEncoding,\n });\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { Trigger, sleep } from '@dxos/async';\nimport { type Message, NetworkAdapter, type PeerId } from '@dxos/automerge/automerge-repo';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nexport type TestConnectionStateProvider = () => 'on' | 'off';\n\nexport class TestAdapter extends NetworkAdapter {\n static createPair(connectionStateProvider: TestConnectionStateProvider = () => 'on') {\n const adapter1: TestAdapter = new TestAdapter({\n send: (message: Message) => connectionStateProvider() === 'on' && sleep(10).then(() => adapter2.receive(message)),\n });\n const adapter2: TestAdapter = new TestAdapter({\n send: (message: Message) => connectionStateProvider() === 'on' && sleep(10).then(() => adapter1.receive(message)),\n });\n\n return [adapter1, adapter2];\n }\n\n public onConnect = new Trigger();\n\n constructor(private readonly _params: { send: (message: Message) => void }) {\n super();\n }\n\n // NOTE: Emitting `ready` event in NetworkAdapter`s constructor causes a race condition\n // because `Repo` waits for `ready` event (which it never receives) before it starts using the adapter.\n ready() {\n this.emit('ready', { network: this });\n }\n\n override connect(peerId: PeerId) {\n this.peerId = peerId;\n this.onConnect.wake();\n }\n\n peerCandidate(peerId: PeerId) {\n invariant(peerId, 'PeerId is required');\n this.emit('peer-candidate', { peerId, peerMetadata: {} });\n }\n\n peerDisconnected(peerId: PeerId) {\n invariant(peerId, 'PeerId is required');\n this.emit('peer-disconnected', { peerId });\n }\n\n override send(message: Message) {\n log('send', { from: message.senderId, to: message.targetId, type: message.type });\n this._params.send(message);\n }\n\n override disconnect() {\n this.peerId = undefined;\n }\n\n receive(message: Message) {\n invariant(this.peerId, 'Peer id is not set');\n this.emit('message', message);\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { sleep, synchronized } from '@dxos/async';\nimport { type Context, LifecycleState, Resource } from '@dxos/context';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport type { AutomergeProtocolMessage } from '@dxos/protocols';\nimport { AutomergeReplicator, type AutomergeReplicatorFactory } from '@dxos/teleport-extension-automerge-replicator';\n\nimport type {\n EchoReplicator,\n EchoReplicatorContext,\n ReplicatorConnection,\n ShouldAdvertiseParams,\n ShouldSyncCollectionParams,\n} from '../automerge';\n\nexport type TestReplicatorNetworkOptions = {\n latency?: number;\n};\n\nexport class TestReplicationNetwork extends Resource {\n private readonly _replicators = new Set<TestReplicator>();\n private readonly _latency?: number = undefined;\n\n constructor(options: TestReplicatorNetworkOptions = {}) {\n super();\n this._latency = options.latency;\n }\n\n protected override async _close(ctx: Context): Promise<void> {\n for (const replicator of this._replicators) {\n for (const connection of replicator.connections) {\n void connection.writable.abort();\n void connection.readable.cancel();\n }\n }\n }\n\n async createReplicator(): Promise<TestReplicator> {\n const replicator = new TestReplicator({\n onConnect: async () => {\n invariant(this._lifecycleState === LifecycleState.OPEN);\n await this._connectReplicator(replicator);\n },\n onDisconnect: async () => {\n invariant(this._lifecycleState === LifecycleState.OPEN);\n await this._disconnectReplicator(replicator);\n },\n });\n this._replicators.add(replicator);\n return replicator;\n }\n\n @synchronized\n private async _connectReplicator(replicator: TestReplicator) {\n for (const otherReplicator of this._replicators.values()) {\n if (otherReplicator === replicator || !otherReplicator.connected) {\n continue;\n }\n log('create connection', { from: replicator.context!.peerId, to: otherReplicator.context!.peerId });\n const [connection1, connection2] = this._createConnectionPair(\n replicator.context!.peerId,\n otherReplicator.context!.peerId,\n );\n await replicator.context!.onConnectionOpen(connection1);\n await otherReplicator.context!.onConnectionOpen(connection2);\n }\n }\n\n private async _disconnectReplicator(replicator: TestReplicator) {\n for (const connection of replicator.connections) {\n await replicator.context!.onConnectionClosed(connection);\n await connection.otherSide!.owningReplicator!.removeConnection(connection.otherSide!);\n }\n }\n\n private _createConnectionPair(peer1: string, peer2: string): [TestReplicatorConnection, TestReplicatorConnection] {\n const LOG = false;\n\n const forward = new TransformStream({\n transform: async (message, controller) => {\n if (LOG) {\n log.info('replicate', { from: peer1, to: peer2, message });\n }\n\n if (this._latency !== undefined) {\n await sleep(this._latency);\n }\n\n controller.enqueue(message);\n },\n });\n const backwards = new TransformStream({\n transform: async (message, controller) => {\n if (LOG) {\n log.info('replicate', { from: peer2, to: peer1, message });\n }\n\n if (this._latency !== undefined) {\n await sleep(this._latency);\n }\n\n controller.enqueue(message);\n },\n });\n\n const connection1 = new TestReplicatorConnection(peer2, backwards.readable, forward.writable);\n const connection2 = new TestReplicatorConnection(peer1, forward.readable, backwards.writable);\n connection1.otherSide = connection2;\n connection2.otherSide = connection1;\n return [connection1, connection2];\n }\n}\n\ntype TestReplicatorParams = {\n onConnect: () => Promise<void>;\n onDisconnect: () => Promise<void>;\n};\n\nexport class TestReplicator implements EchoReplicator {\n constructor(private readonly _params: TestReplicatorParams) {}\n\n public connected = false;\n public context: EchoReplicatorContext | undefined = undefined;\n public connections = new Set<TestReplicatorConnection>();\n\n async connect(context: EchoReplicatorContext): Promise<void> {\n log('connect', { peerId: context.peerId });\n this.context = context;\n this.connected = true;\n await this._params.onConnect();\n }\n\n async disconnect(): Promise<void> {\n log('disconnect', { peerId: this.context!.peerId });\n this.connected = false;\n await this._params.onDisconnect();\n }\n\n async addConnection(connection: TestReplicatorConnection): Promise<void> {\n connection.owningReplicator = this;\n this.connections.add(connection);\n this.context!.onConnectionOpen(connection);\n }\n\n async removeConnection(connection: TestReplicatorConnection): Promise<void> {\n connection.owningReplicator = undefined;\n this.context!.onConnectionClosed(connection);\n this.connections.delete(connection);\n }\n}\n\nexport class TestReplicatorConnection implements ReplicatorConnection {\n public otherSide: TestReplicatorConnection | undefined = undefined;\n public owningReplicator: TestReplicator | undefined = undefined;\n\n constructor(\n public readonly peerId: string,\n public readonly readable: ReadableStream<AutomergeProtocolMessage>,\n public readonly writable: WritableStream<AutomergeProtocolMessage>,\n ) {}\n\n async shouldAdvertise(params: ShouldAdvertiseParams): Promise<boolean> {\n return true;\n }\n\n shouldSyncCollection(params: ShouldSyncCollectionParams): boolean {\n return true;\n }\n}\n\nexport const testAutomergeReplicatorFactory: AutomergeReplicatorFactory = (params) => {\n return new AutomergeReplicator(\n {\n ...params[0],\n sendSyncRetryPolicy: {\n retryBackoff: 20,\n retriesBeforeBackoff: 2,\n maxRetries: 3,\n },\n },\n params[1],\n );\n};\n\nexport const brokenAutomergeReplicatorFactory: AutomergeReplicatorFactory = (params) => {\n params[1]!.onSyncMessage = () => {\n throw new Error();\n };\n return testAutomergeReplicatorFactory(params);\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,iBAAoB;AACpB,mBAAuB;ACDvB,qBAAwB;AACxB,yBAAoC;AAGpC,kBAA0B;AAC1B,uBAAwF;AACxF,6BAAuF;AAGvF,IAAAA,sBAA6B;AAC7B,mCAAyD;AACzD,uCAAiC;AACjC,4CAA0B;AAC1B,kBAA2B;ACb3B,qBAA4B;ACA5B,mBAA+B;AAC/B,4BAA0D;AAC1D,uBAA0B;AAC1B,IAAAC,cAAoB;ACHpB,IAAAC,gBAAoC;AACpC,IAAAC,kBAAuD;AACvD,IAAAC,oBAA0B;AAC1B,IAAAH,cAAoB;AAEpB,qDAAqE;;AJCrE,IAAMI,eAAeC,oBAAOC,gBAAgB,iCAAA;AAOrC,IAAMC,iCAAiC,OAAOC,SAAkBC,YAAAA;AACrEC,iBAAIC,KAAK,+DAAA,QAAA;;;;;;AACT,QAAMC,WAAW,IAAIC,oCAAcL,QAAQM,gBAAgB,UAAA,CAAA;AAC3D,QAAMF,SAASG,KAAI;AACnB,QAAMC,eAAeJ,SAASA;AAC9BI,eAAaP,UAAUA;AACvB,QAAMQ,OAAOL,SAASM,WAAWC,gBAAgB,cAAA;AACjD,QAAMP,SAASQ,WAAWH,MAAMb,cAAcY,YAAAA;AAC9C,QA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;;;;;;AACjD,SAAKoC,YAAY;AACjB,UAAM,KAAK3C,QAAQuC,aAAY;EACjC;EAEA,MAAMyB,cAAcpC,YAAqD;AACvEA,eAAWuB,mBAAmB;AAC9B,SAAKtB,YAAYY,IAAIb,UAAAA;AACrB,SAAKgB,QAASI,iBAAiBpB,UAAAA;EACjC;EAEA,MAAMwB,iBAAiBxB,YAAqD;AAC1EA,eAAWuB,mBAAmBlC;AAC9B,SAAK2B,QAASK,mBAAmBrB,UAAAA;AACjC,SAAKC,YAAYoC,OAAOrC,UAAAA;EAC1B;AACF;AAEO,IAAMkC,2BAAN,MAAMA;EAIXrM,YACkB8I,QACAwB,UACA/F,UAChB;SAHgBuE,SAAAA;SACAwB,WAAAA;SACA/F,WAAAA;SANXkH,YAAkDjC;SAClDkC,mBAA+ClC;EAMnD;EAEH,MAAMiD,gBAAgBC,QAAiD;AACrE,WAAO;EACT;EAEAC,qBAAqBD,QAA6C;AAChE,WAAO;EACT;AACF;AAEO,IAAME,iCAA6D,CAACF,WAAAA;AACzE,SAAO,IAAIG,mEACT;IACE,GAAGH,OAAO,CAAA;IACVI,qBAAqB;MACnBC,cAAc;MACdC,sBAAsB;MACtBC,YAAY;IACd;EACF,GACAP,OAAO,CAAA,CAAE;AAEb;AAEO,IAAMQ,mCAA+D,CAACR,WAAAA;AAC3EA,SAAO,CAAA,EAAIS,gBAAgB,MAAA;AACzB,UAAM,IAAIC,MAAAA;EACZ;AACA,SAAOR,+BAA+BF,MAAAA;AACxC;",
6
+ "names": ["import_credentials", "import_log", "import_async", "import_context", "import_invariant", "EchoMetadata", "schema", "getCodecForType", "changeStorageVersionInMetadata", "storage", "version", "log", "info", "metadata", "MetadataStore", "createDirectory", "load", "echoMetadata", "file", "_directory", "getOrCreateFile", "_writeFile", "flush", "TestFeedBuilder", "TestBuilder", "constructor", "valueEncoding", "MemoryNetworkManagerProvider", "signalContext", "SwarmNetworkManager", "signalManager", "MemorySignalManager", "transportFactory", "MemoryTransportFactory", "WebsocketNetworkManagerProvider", "signalUrl", "WebsocketSignalManager", "server", "createRtcTransportFactory", "TestAgentBuilder", "networkManagerProvider", "_agents", "ComplexMap", "PublicKey", "hash", "_storage", "createStorage", "type", "StorageType", "RAM", "_networkManagerProvider", "MemorySignalManagerContext", "close", "Promise", "all", "agents", "map", "agent", "Array", "from", "values", "getAgent", "deviceKey", "get", "createPeer", "feedBuilder", "setStorage", "size", "identityKey", "keyring", "createKey", "TestAgent", "set", "metadataStore", "_metadataStore", "blobStore", "_blobStore", "BlobStore", "_feedBuilder", "_spaces", "feedStore", "createFeedStore", "spaces", "space", "getSpace", "spaceKey", "spaceManager", "_spaceManager", "SpaceManager", "networkManager", "createSpace", "genesisKey", "dataKey", "saveMetadata", "controlFeed", "openFeed", "writable", "dataFeed", "sparse", "key", "genesisFeedKey", "controlFeedKey", "dataFeedKey", "addSpace", "open", "constructSpace", "swarmIdentity", "peerKey", "credentialProvider", "MOCK_AUTH_PROVIDER", "credentialAuthenticator", "MOCK_AUTH_VERIFIER", "memberKey", "onAuthorizedConnection", "session", "addExtension", "createGossip", "createExtension", "remotePeerId", "onDelegatedInvitationStatusChange", "onMemberRolesChanged", "setControlFeed", "setDataFeed", "Context", "createSpaceProtocol", "topic", "gossip", "SpaceProtocol", "onSessionAuth", "Gossip", "localPeerId", "createPresence", "Presence", "announceInterval", "offlineTimeout", "spaceGenesis", "generator", "CredentialGenerator", "credentials", "createSpaceGenesis", "createFeedAdmission", "AdmittedFeed", "Designation", "DATA", "createEpochCredential", "credential", "controlPipeline", "writer", "write", "TestAdapter", "NetworkAdapter", "createPair", "connectionStateProvider", "adapter1", "send", "message", "sleep", "then", "adapter2", "receive", "_params", "onConnect", "Trigger", "ready", "emit", "network", "connect", "peerId", "wake", "peerCandidate", "invariant", "peerMetadata", "peerDisconnected", "senderId", "to", "targetId", "disconnect", "undefined", "TestReplicationNetwork", "Resource", "options", "_replicators", "Set", "_latency", "latency", "_close", "ctx", "replicator", "connection", "connections", "abort", "readable", "cancel", "createReplicator", "TestReplicator", "_lifecycleState", "LifecycleState", "OPEN", "_connectReplicator", "onDisconnect", "_disconnectReplicator", "add", "otherReplicator", "connected", "context", "connection1", "connection2", "_createConnectionPair", "onConnectionOpen", "onConnectionClosed", "otherSide", "owningReplicator", "removeConnection", "peer1", "peer2", "LOG", "forward", "TransformStream", "transform", "controller", "enqueue", "backwards", "TestReplicatorConnection", "synchronized", "addConnection", "delete", "shouldAdvertise", "params", "shouldSyncCollection", "testAutomergeReplicatorFactory", "AutomergeReplicator", "sendSyncRetryPolicy", "retryBackoff", "retriesBeforeBackoff", "maxRetries", "brokenAutomergeReplicatorFactory", "onSyncMessage", "Error"]
7
7
  }
@@ -1,8 +1,4 @@
1
- import "@dxos/node-std/globals";
2
- import {
3
- Buffer,
4
- createIdFromSpaceKey
5
- } from "./chunk-XPCF2V5U.mjs";
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
6
2
 
7
3
  // packages/core/echo/echo-pipeline/src/common/codec.ts
8
4
  import { createCodecEncoding } from "@dxos/hypercore";
@@ -37,17 +33,34 @@ var createMappedFeedWriter = (mapper, writer) => {
37
33
  };
38
34
  };
39
35
 
36
+ // packages/core/echo/echo-pipeline/src/common/space-id.ts
37
+ import { subtleCrypto } from "@dxos/crypto";
38
+ import { PublicKey, SpaceId } from "@dxos/keys";
39
+ import { ComplexMap } from "@dxos/util";
40
+ var SPACE_IDS_CACHE = new ComplexMap(PublicKey.hash);
41
+ var createIdFromSpaceKey = async (spaceKey) => {
42
+ const cachedValue = SPACE_IDS_CACHE.get(spaceKey);
43
+ if (cachedValue !== void 0) {
44
+ return cachedValue;
45
+ }
46
+ const digest = await subtleCrypto.digest("SHA-256", spaceKey.asUint8Array());
47
+ const bytes = new Uint8Array(digest).slice(0, SpaceId.byteLength);
48
+ const spaceId = SpaceId.encode(bytes);
49
+ SPACE_IDS_CACHE.set(spaceKey, spaceId);
50
+ return spaceId;
51
+ };
52
+
40
53
  // packages/core/echo/echo-pipeline/src/metadata/metadata-store.ts
41
54
  import CRC32 from "crc-32";
42
55
  import { Event, scheduleTaskInterval, synchronized } from "@dxos/async";
43
56
  import { Context } from "@dxos/context";
44
57
  import { invariant as invariant2 } from "@dxos/invariant";
45
- import { PublicKey } from "@dxos/keys";
58
+ import { PublicKey as PublicKey2 } from "@dxos/keys";
46
59
  import { log } from "@dxos/log";
47
60
  import { DataCorruptionError, STORAGE_VERSION } from "@dxos/protocols";
48
61
  import { schema as schema2 } from "@dxos/protocols/proto";
49
62
  import { Invitation, SpaceState } from "@dxos/protocols/proto/dxos/client/services";
50
- import { ComplexMap, arrayToBuffer, forEachAsync, isNotNullOrUndefined } from "@dxos/util";
63
+ import { ComplexMap as ComplexMap2, arrayToBuffer, forEachAsync, isNotNullOrUndefined } from "@dxos/util";
51
64
  function _ts_decorate(decorators, target, key, desc) {
52
65
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
53
66
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -68,12 +81,12 @@ var LargeSpaceMetadata = schema2.getCodecForType("dxos.echo.metadata.LargeSpaceM
68
81
  var MetadataStore = class {
69
82
  constructor(directory) {
70
83
  this._metadata = emptyEchoMetadata();
71
- this._spaceLargeMetadata = new ComplexMap(PublicKey.hash);
84
+ this._spaceLargeMetadata = new ComplexMap2(PublicKey2.hash);
72
85
  this._metadataFile = void 0;
73
86
  this.update = new Event();
74
87
  this._invitationCleanupCtx = new Context(void 0, {
75
88
  F: __dxlog_file2,
76
- L: 54
89
+ L: 55
77
90
  });
78
91
  this._directory = directory;
79
92
  }
@@ -104,7 +117,7 @@ var MetadataStore = class {
104
117
  name: file.filename
105
118
  }, {
106
119
  F: __dxlog_file2,
107
- L: 90,
120
+ L: 91,
108
121
  S: this,
109
122
  C: (f, a) => f(...a)
110
123
  });
@@ -140,7 +153,7 @@ var MetadataStore = class {
140
153
  checksum
141
154
  }, {
142
155
  F: __dxlog_file2,
143
- L: 125,
156
+ L: 126,
144
157
  S: this,
145
158
  C: (f, a) => f(...a)
146
159
  });
@@ -173,7 +186,7 @@ var MetadataStore = class {
173
186
  err
174
187
  }, {
175
188
  F: __dxlog_file2,
176
- L: 157,
189
+ L: 158,
177
190
  S: this,
178
191
  C: (f, a) => f(...a)
179
192
  });
@@ -190,7 +203,7 @@ var MetadataStore = class {
190
203
  err
191
204
  }, {
192
205
  F: __dxlog_file2,
193
- L: 169,
206
+ L: 170,
194
207
  S: this,
195
208
  C: (f, a) => f(...a)
196
209
  });
@@ -227,7 +240,7 @@ var MetadataStore = class {
227
240
  err
228
241
  }, {
229
242
  F: __dxlog_file2,
230
- L: 211,
243
+ L: 212,
231
244
  S: this,
232
245
  C: (f, a) => f(...a)
233
246
  });
@@ -248,7 +261,7 @@ var MetadataStore = class {
248
261
  const space = this.spaces.find((space2) => space2.key === spaceKey);
249
262
  invariant2(space, "Space not found", {
250
263
  F: __dxlog_file2,
251
- L: 233,
264
+ L: 234,
252
265
  S: this,
253
266
  A: [
254
267
  "space",
@@ -257,6 +270,12 @@ var MetadataStore = class {
257
270
  });
258
271
  return space;
259
272
  }
273
+ hasSpace(spaceKey) {
274
+ if (this._metadata.identity?.haloSpace.key.equals(spaceKey)) {
275
+ return true;
276
+ }
277
+ return !!this.spaces.find((space) => space.key === spaceKey);
278
+ }
260
279
  _getLargeSpaceMetadata(key) {
261
280
  let entry = this._spaceLargeMetadata.get(key);
262
281
  if (entry) {
@@ -272,7 +291,7 @@ var MetadataStore = class {
272
291
  async clear() {
273
292
  log("clearing all metadata", void 0, {
274
293
  F: __dxlog_file2,
275
- L: 252,
294
+ L: 262,
276
295
  S: this,
277
296
  C: (f, a) => f(...a)
278
297
  });
@@ -285,7 +304,7 @@ var MetadataStore = class {
285
304
  async setIdentityRecord(record) {
286
305
  invariant2(!this._metadata.identity, "Cannot overwrite existing identity in metadata", {
287
306
  F: __dxlog_file2,
288
- L: 262,
307
+ L: 272,
289
308
  S: this,
290
309
  A: [
291
310
  "!this._metadata.identity",
@@ -315,7 +334,7 @@ var MetadataStore = class {
315
334
  async addSpace(record) {
316
335
  invariant2(!(this._metadata.spaces ?? []).find((space) => space.key === record.key), "Cannot overwrite existing space in metadata", {
317
336
  F: __dxlog_file2,
318
- L: 290,
337
+ L: 300,
319
338
  S: this,
320
339
  A: [
321
340
  "!(this._metadata.spaces ?? []).find((space) => space.key === record.key)",
@@ -359,6 +378,14 @@ var MetadataStore = class {
359
378
  await this._saveSpaceLargeMetadata(spaceKey);
360
379
  await this.flush();
361
380
  }
381
+ getSpaceEdgeReplicationSetting(spaceKey) {
382
+ return this.hasSpace(spaceKey) ? this._getSpace(spaceKey).edgeReplication : void 0;
383
+ }
384
+ async setSpaceEdgeReplicationSetting(spaceKey, setting) {
385
+ this._getSpace(spaceKey).edgeReplication = setting;
386
+ await this._save();
387
+ await this.flush();
388
+ }
362
389
  };
363
390
  _ts_decorate([
364
391
  synchronized
@@ -476,10 +503,10 @@ import { Context as Context2, rejectOnDispose } from "@dxos/context";
476
503
  import { failUndefined } from "@dxos/debug";
477
504
  import { FeedSetIterator } from "@dxos/feed-store";
478
505
  import { invariant as invariant4 } from "@dxos/invariant";
479
- import { PublicKey as PublicKey2 } from "@dxos/keys";
506
+ import { PublicKey as PublicKey3 } from "@dxos/keys";
480
507
  import { log as log4 } from "@dxos/log";
481
508
  import { Timeframe as Timeframe2 } from "@dxos/timeframe";
482
- import { ComplexMap as ComplexMap2 } from "@dxos/util";
509
+ import { ComplexMap as ComplexMap3 } from "@dxos/util";
483
510
 
484
511
  // packages/core/echo/echo-pipeline/src/pipeline/message-selector.ts
485
512
  import { invariant as invariant3 } from "@dxos/invariant";
@@ -630,14 +657,14 @@ var PipelineState = class {
630
657
  var Pipeline = class {
631
658
  constructor() {
632
659
  this._timeframeClock = new TimeframeClock(new Timeframe2());
633
- this._feeds = new ComplexMap2(PublicKey2.hash);
660
+ this._feeds = new ComplexMap3(PublicKey3.hash);
634
661
  // External state accessor.
635
662
  this._state = new PipelineState(this._feeds, this._timeframeClock);
636
663
  // Waits for the message consumer to process the message and yield control back to the pipeline.
637
664
  this._processingTrigger = new Trigger().wake();
638
665
  this._pauseTrigger = new Trigger().wake();
639
666
  // Pending downloads.
640
- this._downloads = new ComplexMap2((value) => PublicKey2.hash(value.key));
667
+ this._downloads = new ComplexMap3((value) => PublicKey3.hash(value.key));
641
668
  this._isStopping = false;
642
669
  this._isStarted = false;
643
670
  this._isBeingConsumed = false;
@@ -853,7 +880,7 @@ var Pipeline = class {
853
880
  if (!done) {
854
881
  const block = value ?? failUndefined();
855
882
  this._processingTrigger.reset();
856
- this._timeframeClock.updatePendingTimeframe(PublicKey2.from(block.feedKey), block.seq);
883
+ this._timeframeClock.updatePendingTimeframe(PublicKey3.from(block.feedKey), block.seq);
857
884
  yield block;
858
885
  this._processingTrigger.wake();
859
886
  this._timeframeClock.updateTimeframe();
@@ -1054,7 +1081,7 @@ import { Callback as Callback2 } from "@dxos/util";
1054
1081
  import { DeferredTask, sleepWithContext as sleepWithContext2, trackLeaks } from "@dxos/async";
1055
1082
  import { Context as Context4 } from "@dxos/context";
1056
1083
  import { SpaceStateMachine } from "@dxos/credentials";
1057
- import { PublicKey as PublicKey3 } from "@dxos/keys";
1084
+ import { PublicKey as PublicKey4 } from "@dxos/keys";
1058
1085
  import { log as log6 } from "@dxos/log";
1059
1086
  import { AdmittedFeed } from "@dxos/protocols/proto/dxos/halo/credentials";
1060
1087
  import { Timeframe as Timeframe3 } from "@dxos/timeframe";
@@ -1198,7 +1225,7 @@ var ControlPipeline = class {
1198
1225
  await this._pipeline.unpause();
1199
1226
  log6("save snapshot", {
1200
1227
  key: this._spaceKey,
1201
- snapshot
1228
+ snapshot: getSnapshotLoggerContext(snapshot)
1202
1229
  }, {
1203
1230
  F: __dxlog_file7,
1204
1231
  L: 163,
@@ -1237,7 +1264,7 @@ var ControlPipeline = class {
1237
1264
  if (msg.data.payload.credential) {
1238
1265
  const timer = tracer.mark("dxos.echo.pipeline.control");
1239
1266
  const result = await this._spaceStateMachine.process(msg.data.payload.credential.credential, {
1240
- sourceFeed: PublicKey3.from(msg.feedKey)
1267
+ sourceFeed: PublicKey4.from(msg.feedKey)
1241
1268
  });
1242
1269
  timer.end();
1243
1270
  if (!result) {
@@ -1314,6 +1341,18 @@ ControlPipeline = _ts_decorate4([
1314
1341
  trace.resource(),
1315
1342
  trackLeaks("start", "stop")
1316
1343
  ], ControlPipeline);
1344
+ var getSnapshotLoggerContext = (snapshot) => {
1345
+ return snapshot.messages?.map((msg) => {
1346
+ const issuer = msg.credential.issuer;
1347
+ const subject = msg.credential.subject.id;
1348
+ const type = msg.credential.subject.assertion["@type"];
1349
+ return {
1350
+ issuer,
1351
+ subject,
1352
+ type
1353
+ };
1354
+ });
1355
+ };
1317
1356
 
1318
1357
  // packages/core/echo/echo-pipeline/src/space/space.ts
1319
1358
  function _ts_decorate5(decorators, target, key, desc) {
@@ -1594,15 +1633,15 @@ var CredentialServerExtension = class extends RpcExtension2 {
1594
1633
  };
1595
1634
 
1596
1635
  // packages/core/echo/echo-pipeline/src/space/space-protocol.ts
1597
- import { discoveryKey, subtleCrypto } from "@dxos/crypto";
1598
- import { PublicKey as PublicKey4 } from "@dxos/keys";
1636
+ import { discoveryKey, subtleCrypto as subtleCrypto2 } from "@dxos/crypto";
1637
+ import { PublicKey as PublicKey5 } from "@dxos/keys";
1599
1638
  import { log as log8, logInfo as logInfo2 } from "@dxos/log";
1600
1639
  import { MMSTTopology } from "@dxos/network-manager";
1601
1640
  import { Teleport } from "@dxos/teleport";
1602
1641
  import { BlobSync } from "@dxos/teleport-extension-object-sync";
1603
1642
  import { ReplicatorExtension } from "@dxos/teleport-extension-replicator";
1604
1643
  import { trace as trace3 } from "@dxos/tracing";
1605
- import { CallbackCollection, ComplexMap as ComplexMap3 } from "@dxos/util";
1644
+ import { CallbackCollection, ComplexMap as ComplexMap4 } from "@dxos/util";
1606
1645
  function _ts_decorate6(decorators, target, key, desc) {
1607
1646
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1608
1647
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -1615,7 +1654,7 @@ var MOCK_AUTH_VERIFIER = async (nonce, credential) => true;
1615
1654
  var SpaceProtocol = class {
1616
1655
  constructor({ topic, swarmIdentity, networkManager, onSessionAuth, onAuthFailure, blobStore, disableP2pReplication }) {
1617
1656
  this._feeds = /* @__PURE__ */ new Set();
1618
- this._sessions = new ComplexMap3(PublicKey4.hash);
1657
+ this._sessions = new ComplexMap4(PublicKey5.hash);
1619
1658
  // TODO(burdon): Move to config (with sensible defaults).
1620
1659
  this._topology = new MMSTTopology({
1621
1660
  originateConnections: 4,
@@ -1631,7 +1670,7 @@ var SpaceProtocol = class {
1631
1670
  this.blobSync = new BlobSync({
1632
1671
  blobStore
1633
1672
  });
1634
- this._topic = subtleCrypto.digest("SHA-256", topic.asBuffer()).then(discoveryKey).then(PublicKey4.from);
1673
+ this._topic = subtleCrypto2.digest("SHA-256", topic.asBuffer()).then(discoveryKey).then(PublicKey5.from);
1635
1674
  this._disableP2pReplication = disableP2pReplication ?? false;
1636
1675
  }
1637
1676
  get sessions() {
@@ -1821,10 +1860,10 @@ _ts_decorate6([
1821
1860
  // packages/core/echo/echo-pipeline/src/space/space-manager.ts
1822
1861
  import { synchronized as synchronized4, trackLeaks as trackLeaks3, Trigger as Trigger2 } from "@dxos/async";
1823
1862
  import { failUndefined as failUndefined2 } from "@dxos/debug";
1824
- import { PublicKey as PublicKey5 } from "@dxos/keys";
1863
+ import { PublicKey as PublicKey6 } from "@dxos/keys";
1825
1864
  import { log as log9 } from "@dxos/log";
1826
1865
  import { trace as trace4 } from "@dxos/protocols";
1827
- import { ComplexMap as ComplexMap4 } from "@dxos/util";
1866
+ import { ComplexMap as ComplexMap5 } from "@dxos/util";
1828
1867
  function _ts_decorate7(decorators, target, key, desc) {
1829
1868
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1830
1869
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -1834,8 +1873,8 @@ function _ts_decorate7(decorators, target, key, desc) {
1834
1873
  var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space-manager.ts";
1835
1874
  var SpaceManager = class {
1836
1875
  constructor({ feedStore, networkManager, metadataStore, blobStore, disableP2pReplication }) {
1837
- this._spaces = new ComplexMap4(PublicKey5.hash);
1838
- this._instanceId = PublicKey5.random().toHex();
1876
+ this._spaces = new ComplexMap5(PublicKey6.hash);
1877
+ this._instanceId = PublicKey6.random().toHex();
1839
1878
  this._feedStore = feedStore;
1840
1879
  this._networkManager = networkManager;
1841
1880
  this._metadataStore = metadataStore;
@@ -1981,6 +2020,7 @@ export {
1981
2020
  codec,
1982
2021
  valueEncoding,
1983
2022
  createMappedFeedWriter,
2023
+ createIdFromSpaceKey,
1984
2024
  MetadataStore,
1985
2025
  hasInvitationExpired,
1986
2026
  mapTimeframeToFeedIndexes,
@@ -1999,4 +2039,4 @@ export {
1999
2039
  SpaceProtocolSession,
2000
2040
  SpaceManager
2001
2041
  };
2002
- //# sourceMappingURL=chunk-UKXIJW43.mjs.map
2042
+ //# sourceMappingURL=chunk-4LW7MDPZ.mjs.map