@dxos/client-services 0.1.31-next.ea8f0bc → 0.1.31
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/dist/lib/browser/{chunk-ZIQUYEJS.mjs → chunk-DFO3FW2W.mjs} +53 -20
- package/dist/lib/browser/{chunk-ZIQUYEJS.mjs.map → chunk-DFO3FW2W.mjs.map} +3 -3
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/packlets/testing/index.mjs +64 -6
- package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
- package/dist/lib/node/index.cjs +52 -19
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/packlets/testing/index.cjs +114 -22
- package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts +8 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts +4 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts +2 -0
- package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/packlets/tests/text.test.d.ts +2 -0
- package/dist/types/src/packlets/tests/text.test.d.ts.map +1 -0
- package/package.json +31 -30
- package/src/packlets/spaces/data-space-manager.test.ts +60 -0
- package/src/packlets/spaces/data-space-manager.ts +11 -7
- package/src/packlets/spaces/data-space.ts +13 -1
- package/src/packlets/spaces/notarization-plugin.ts +9 -2
- package/src/packlets/spaces/spaces-service.ts +25 -0
- package/src/packlets/testing/test-builder.ts +45 -5
- package/src/packlets/tests/spaces-invitations.test.ts +46 -6
- package/src/packlets/tests/spaces.test.ts +70 -2
- package/src/packlets/tests/text.test.ts +206 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/packlets/testing/credential-utils.ts", "../../../../../src/packlets/testing/host-test-builder.ts", "../../../../../src/packlets/testing/invitation-utils.ts", "../../../../../src/packlets/testing/test-builder.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { createCredential } from '@dxos/credentials';\nimport { Signer } from '@dxos/crypto';\nimport { PublicKey } from '@dxos/keys';\nimport { Credential } from '@dxos/protocols/proto/dxos/halo/credentials';\n\nexport const createMockCredential = async ({\n signer,\n issuer\n}: {\n signer: Signer;\n issuer: PublicKey;\n}): Promise<Credential> =>\n createCredential({\n signer,\n issuer,\n subject: new PublicKey(Buffer.from('test')),\n assertion: {\n '@type': 'example.testing.rpc.MessageWithAny',\n payload: {\n '@type': 'google.protobuf.Any',\n value: Buffer.from('test')\n }\n }\n });\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { createDefaultModelFactory } from '@dxos/client';\nimport { Config } from '@dxos/config';\nimport { createCredentialSignerWithChain, CredentialGenerator } from '@dxos/credentials';\nimport {\n SnapshotStore,\n DataPipelineControllerImpl,\n MetadataStore,\n SigningContext,\n SpaceManager,\n valueEncoding\n} from '@dxos/echo-pipeline';\nimport { testLocalDatabase } from '@dxos/echo-pipeline/testing';\nimport { FeedFactory, FeedStore } from '@dxos/feed-store';\nimport { Keyring } from '@dxos/keyring';\nimport { MemorySignalManager, MemorySignalManagerContext } from '@dxos/messaging';\nimport { MemoryTransportFactory, NetworkManager } from '@dxos/network-manager';\nimport { createStorage, Storage, StorageType } from '@dxos/random-access-storage';\n\nimport { ClientServicesHost, ServiceContext } from '../services';\n\n//\n// TODO(burdon): Replace with test builder.\n//\n\nexport const createServiceHost = (config: Config, signalManagerContext: MemorySignalManagerContext) => {\n const networkManager = new NetworkManager({\n signalManager: new MemorySignalManager(signalManagerContext),\n transportFactory: MemoryTransportFactory\n });\n\n return new ClientServicesHost({\n config,\n networkManager\n });\n};\n\nexport const createServiceContext = ({\n signalContext = new MemorySignalManagerContext(),\n storage = createStorage({ type: StorageType.RAM })\n}: {\n signalContext?: MemorySignalManagerContext;\n storage?: Storage;\n} = {}) => {\n const networkManager = new NetworkManager({\n signalManager: new MemorySignalManager(signalContext),\n transportFactory: MemoryTransportFactory\n });\n\n const modelFactory = createDefaultModelFactory();\n return new ServiceContext(storage, networkManager, modelFactory);\n};\n\nexport const createPeers = async (numPeers: number) => {\n const signalContext = new MemorySignalManagerContext();\n\n return await Promise.all(\n Array.from(Array(numPeers)).map(async () => {\n const peer = createServiceContext({ signalContext });\n await peer.open();\n return peer;\n })\n );\n};\n\nexport const createIdentity = async (peer: ServiceContext) => {\n await peer.createIdentity();\n return peer;\n};\n\n// TODO(burdon): Remove @dxos/client-testing.\n// TODO(burdon): Create builder and make configurable.\nexport const syncItemsLocal = async (db1: DataPipelineControllerImpl, db2: DataPipelineControllerImpl) => {\n await testLocalDatabase(db1, db2);\n await testLocalDatabase(db2, db1);\n};\n\nexport class HostTestBuilder {\n public readonly signalContext = new MemorySignalManagerContext();\n\n createPeer(): TestPeer {\n return new TestPeer(this.signalContext);\n }\n}\n\nexport type TestPeerProps = {\n storage?: Storage;\n feedStore?: FeedStore<any>;\n metadataStore?: MetadataStore;\n keyring?: Keyring;\n networkManager?: NetworkManager;\n spaceManager?: SpaceManager;\n snapshotStore?: SnapshotStore;\n};\n\nexport class TestPeer {\n private _props: TestPeerProps = {};\n\n constructor(private readonly signalContext: MemorySignalManagerContext) {}\n\n get storage() {\n return (this._props.storage ??= createStorage({ type: StorageType.RAM }));\n }\n\n get keyring() {\n return (this._props.keyring ??= new Keyring(this.storage.createDirectory('keyring')));\n }\n\n get feedStore() {\n return (this._props.feedStore ??= new FeedStore({\n factory: new FeedFactory({\n root: this.storage.createDirectory('feeds'),\n signer: this.keyring,\n hypercore: {\n valueEncoding\n }\n })\n }));\n }\n\n get metadataStore() {\n return (this._props.metadataStore ??= new MetadataStore(this.storage.createDirectory('metadata')));\n }\n\n get snapshotStore() {\n return (this._props.snapshotStore ??= new SnapshotStore(this.storage.createDirectory('snapshots')));\n }\n\n get networkManager() {\n return (this._props.networkManager ??= new NetworkManager({\n signalManager: new MemorySignalManager(this.signalContext),\n transportFactory: MemoryTransportFactory\n }));\n }\n\n get spaceManager() {\n return (this._props.spaceManager ??= new SpaceManager({\n feedStore: this.feedStore,\n networkManager: this.networkManager\n }));\n }\n}\n\nexport const createSigningContext = async (keyring: Keyring): Promise<SigningContext> => {\n const identityKey = await keyring.createKey();\n const deviceKey = await keyring.createKey();\n\n return {\n identityKey,\n deviceKey,\n credentialSigner: createCredentialSignerWithChain(\n keyring,\n {\n credential: await new CredentialGenerator(keyring, identityKey, deviceKey).createDeviceAuthorization(deviceKey)\n },\n deviceKey\n ),\n recordCredential: async () => {} // No-op.\n };\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport assert from 'node:assert';\n\nimport { Trigger } from '@dxos/async';\nimport { InvitationsHandler } from '@dxos/client';\nimport { raise } from '@dxos/debug';\nimport { Invitation } from '@dxos/protocols/proto/dxos/client/services';\n\nexport const performInvitation = async <T>(host: InvitationsHandler<T>, guest: InvitationsHandler<T>, context: T) => {\n const done1 = new Trigger<Invitation>(); // peer 1 connected.\n const done2 = new Trigger<Invitation>(); // peer 2 connected.\n const observable1 = await host.createInvitation(context, { type: Invitation.Type.INTERACTIVE_TESTING });\n observable1.subscribe({\n onConnecting: async (invitation1: Invitation) => {\n const observable2 = await guest.acceptInvitation(invitation1, { type: Invitation.Type.INTERACTIVE_TESTING });\n observable2.subscribe({\n onConnecting: async (invitation2: Invitation) => {\n assert(invitation1.swarmKey!.equals(invitation2.swarmKey!));\n },\n onConnected: async (invitation2: Invitation) => {},\n onSuccess: (invitation) => {\n done2.wake(invitation);\n },\n onCancelled: () => raise(new Error()),\n onTimeout: (err: Error) => raise(err),\n onError: (err: Error) => raise(err)\n });\n },\n onConnected: async (invitation1: Invitation) => {},\n onCancelled: () => raise(new Error('cancelled')),\n onSuccess: (invitation) => {\n done1.wake(invitation);\n },\n onTimeout: (err: Error) => raise(err),\n onError: (err: Error) => raise(err)\n });\n\n await done1.wait();\n await done2.wait();\n};\n", "//\n// Copyright 2020 DXOS.org\n//\n\nimport assert from 'node:assert';\n\nimport { asyncTimeout } from '@dxos/async';\nimport { Client, ClientServices, ClientServicesProxy, createDefaultModelFactory } from '@dxos/client';\nimport { Config } from '@dxos/config';\nimport { DocumentModel } from '@dxos/document-model';\nimport { DatabaseBackendProxy, genesisMutation } from '@dxos/echo-db';\nimport { PublicKey } from '@dxos/keys';\nimport { MemorySignalManager, MemorySignalManagerContext, WebsocketSignalManager } from '@dxos/messaging';\nimport { createWebRTCTransportFactory, MemoryTransportFactory, NetworkManager } from '@dxos/network-manager';\nimport { Storage } from '@dxos/random-access-storage';\nimport { createLinkedPorts, createProtoRpcPeer, ProtoRpcPeer } from '@dxos/rpc';\n\nimport { ClientServicesHost, LocalClientServices } from '../services';\n\nexport const testConfigWithLocalSignal = new Config({\n version: 1,\n runtime: {\n services: {\n signal: {\n // TODO(burdon): Port numbers and global consts?\n server: 'ws://localhost:4000/.well-known/dx/signal'\n }\n }\n }\n});\n\n/**\n * Client builder supports different configurations, incl. signaling, transports, storage.\n */\nexport class TestBuilder {\n private readonly _config: Config;\n\n public storage?: Storage;\n\n // prettier-ignore\n constructor (\n config?: Config,\n private readonly _modelFactory = createDefaultModelFactory(),\n private readonly _signalManagerContext = new MemorySignalManagerContext()\n ) {\n this._config = config ?? new Config();\n }\n\n get config(): Config {\n return this._config;\n }\n\n /**\n * Get network manager using local shared memory or remote signal manager.\n */\n get networkManager() {\n const signalServer = this._config.get('runtime.services.signal.server');\n if (signalServer) {\n return new NetworkManager({\n log: true,\n signalManager: new WebsocketSignalManager([signalServer]),\n transportFactory: createWebRTCTransportFactory({\n iceServers: this._config.get('runtime.services.ice')\n })\n });\n }\n\n // Memory transport with shared context.\n return new NetworkManager({\n log: true,\n signalManager: new MemorySignalManager(this._signalManagerContext),\n transportFactory: MemoryTransportFactory\n });\n }\n\n /**\n * Create backend service handlers.\n */\n createClientServicesHost() {\n return new ClientServicesHost({\n config: this._config,\n modelFactory: this._modelFactory,\n networkManager: this.networkManager,\n storage: this.storage\n });\n }\n\n /**\n * Create local services host.\n */\n createLocal() {\n return new LocalClientServices({\n config: this._config,\n modelFactory: this._modelFactory,\n networkManager: this.networkManager,\n storage: this.storage\n });\n }\n\n /**\n * Create client/server.\n */\n createClientServer(host: ClientServicesHost = this.createClientServicesHost()): [Client, ProtoRpcPeer<{}>] {\n const [proxyPort, hostPort] = createLinkedPorts();\n const server = createProtoRpcPeer({\n exposed: host.descriptors,\n handlers: host.services as ClientServices,\n port: hostPort\n });\n // TODO(dmaretskyi): Refactor.\n\n const client = new Client({ services: new ClientServicesProxy(proxyPort) });\n return [client, server];\n }\n}\n\nexport const testSpace = async (create: DatabaseBackendProxy, check: DatabaseBackendProxy = create) => {\n const objectId = PublicKey.random().toHex();\n\n const result = create.mutate(genesisMutation(objectId, DocumentModel.meta.type));\n\n await result.getReceipt();\n // TODO(dmaretskiy): await result.waitToBeProcessed()\n assert(create._itemManager.entities.has(result.objectsCreated[0].id));\n\n await asyncTimeout(\n check._itemManager.update.waitForCondition(() => check._itemManager.entities.has(objectId)),\n 1000\n );\n\n return result;\n};\n\nexport const syncItems = async (db1: DatabaseBackendProxy, db2: DatabaseBackendProxy) => {\n // Check item replicated from 1 => 2.\n await testSpace(db1, db2);\n\n // Check item replicated from 2 => 1.\n await testSpace(db2, db1);\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;AAIA,SAASA,wBAAwB;AAEjC,SAASC,iBAAiB;AAGnB,IAAMC,uBAAuB,OAAO,EACzCC,QACAC,OAAM,MAKNJ,iBAAiB;EACfG;EACAC;EACAC,SAAS,IAAIJ,UAAUK,OAAOC,KAAK,MAAA,CAAA;EACnCC,WAAW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Aa,MAAMzB,MAAM,IAAI0B,MAAAA,CAAAA;QAC7BC,WAAW,CAACC,QAAe5B,MAAM4B,GAAAA;QACjCC,SAAS,CAACD,QAAe5B,MAAM4B,GAAAA;MACjC,CAAA;IACF;IACAP,aAAa,OAAON,gBAA4B;IAAC;IACjDU,aAAa,MAAMzB,MAAM,IAAI0B,MAAM,WAAA,CAAA;IACnCJ,WAAW,CAACC,eAAe;AACzBjB,YAAMkB,KAAKD,UAAAA;IACb;IACAI,WAAW,CAACC,QAAe5B,MAAM4B,GAAAA;IACjCC,SAAS,CAACD,QAAe5B,MAAM4B,GAAAA;EACjC,CAAA;AAEA,QAAMtB,MAAMwB,KAAI;AAChB,QAAMvB,MAAMuB,KAAI;AAClB;;;ACtCA,OAAOC,aAAY;AAEnB,SAASC,
|
|
6
|
-
"names": ["createCredential", "PublicKey", "createMockCredential", "signer", "issuer", "subject", "Buffer", "from", "assertion", "payload", "value", "createDefaultModelFactory", "createCredentialSignerWithChain", "CredentialGenerator", "SnapshotStore", "MetadataStore", "SpaceManager", "valueEncoding", "testLocalDatabase", "FeedFactory", "FeedStore", "Keyring", "MemorySignalManager", "MemorySignalManagerContext", "MemoryTransportFactory", "NetworkManager", "createStorage", "StorageType", "createServiceHost", "config", "signalManagerContext", "networkManager", "NetworkManager", "signalManager", "MemorySignalManager", "transportFactory", "MemoryTransportFactory", "ClientServicesHost", "createServiceContext", "signalContext", "MemorySignalManagerContext", "storage", "createStorage", "type", "StorageType", "RAM", "modelFactory", "createDefaultModelFactory", "ServiceContext", "createPeers", "numPeers", "Promise", "all", "Array", "from", "map", "peer", "open", "createIdentity", "syncItemsLocal", "db1", "db2", "testLocalDatabase", "HostTestBuilder", "createPeer", "TestPeer", "constructor", "_props", "keyring", "Keyring", "createDirectory", "feedStore", "FeedStore", "factory", "FeedFactory", "root", "signer", "hypercore", "valueEncoding", "metadataStore", "MetadataStore", "snapshotStore", "SnapshotStore", "spaceManager", "SpaceManager", "createSigningContext", "identityKey", "createKey", "deviceKey", "credentialSigner", "createCredentialSignerWithChain", "credential", "CredentialGenerator", "createDeviceAuthorization", "recordCredential", "assert", "Trigger", "raise", "Invitation", "performInvitation", "host", "guest", "context", "done1", "done2", "observable1", "createInvitation", "type", "Type", "INTERACTIVE_TESTING", "subscribe", "onConnecting", "invitation1", "observable2", "acceptInvitation", "invitation2", "swarmKey", "equals", "onConnected", "onSuccess", "invitation", "wake", "onCancelled", "Error", "onTimeout", "err", "onError", "wait", "assert", "asyncTimeout", "Client", "ClientServicesProxy", "createDefaultModelFactory", "Config", "DocumentModel", "genesisMutation", "PublicKey", "MemorySignalManager", "MemorySignalManagerContext", "WebsocketSignalManager", "createWebRTCTransportFactory", "MemoryTransportFactory", "NetworkManager", "createLinkedPorts", "createProtoRpcPeer", "testConfigWithLocalSignal", "Config", "version", "runtime", "services", "signal", "server", "TestBuilder", "constructor", "config", "_modelFactory", "createDefaultModelFactory", "_signalManagerContext", "MemorySignalManagerContext", "_config", "networkManager", "signalServer", "get", "NetworkManager", "log", "signalManager", "WebsocketSignalManager", "transportFactory", "createWebRTCTransportFactory", "iceServers", "MemorySignalManager", "MemoryTransportFactory", "createClientServicesHost", "ClientServicesHost", "modelFactory", "storage", "createLocal", "LocalClientServices", "createClientServer", "host", "proxyPort", "hostPort", "createLinkedPorts", "createProtoRpcPeer", "exposed", "descriptors", "handlers", "port", "client", "Client", "ClientServicesProxy", "testSpace", "create", "check", "objectId", "PublicKey", "random", "toHex", "result", "mutate", "genesisMutation", "DocumentModel", "meta", "type", "getReceipt", "assert", "_itemManager", "entities", "has", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { createCredential } from '@dxos/credentials';\nimport { Signer } from '@dxos/crypto';\nimport { PublicKey } from '@dxos/keys';\nimport { Credential } from '@dxos/protocols/proto/dxos/halo/credentials';\n\nexport const createMockCredential = async ({\n signer,\n issuer\n}: {\n signer: Signer;\n issuer: PublicKey;\n}): Promise<Credential> =>\n createCredential({\n signer,\n issuer,\n subject: new PublicKey(Buffer.from('test')),\n assertion: {\n '@type': 'example.testing.rpc.MessageWithAny',\n payload: {\n '@type': 'google.protobuf.Any',\n value: Buffer.from('test')\n }\n }\n });\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { createDefaultModelFactory } from '@dxos/client';\nimport { Config } from '@dxos/config';\nimport { createCredentialSignerWithChain, CredentialGenerator } from '@dxos/credentials';\nimport {\n SnapshotStore,\n DataPipelineControllerImpl,\n MetadataStore,\n SigningContext,\n SpaceManager,\n valueEncoding\n} from '@dxos/echo-pipeline';\nimport { testLocalDatabase } from '@dxos/echo-pipeline/testing';\nimport { FeedFactory, FeedStore } from '@dxos/feed-store';\nimport { Keyring } from '@dxos/keyring';\nimport { MemorySignalManager, MemorySignalManagerContext } from '@dxos/messaging';\nimport { MemoryTransportFactory, NetworkManager } from '@dxos/network-manager';\nimport { createStorage, Storage, StorageType } from '@dxos/random-access-storage';\n\nimport { ClientServicesHost, ServiceContext } from '../services';\n\n//\n// TODO(burdon): Replace with test builder.\n//\n\nexport const createServiceHost = (config: Config, signalManagerContext: MemorySignalManagerContext) => {\n const networkManager = new NetworkManager({\n signalManager: new MemorySignalManager(signalManagerContext),\n transportFactory: MemoryTransportFactory\n });\n\n return new ClientServicesHost({\n config,\n networkManager\n });\n};\n\nexport const createServiceContext = ({\n signalContext = new MemorySignalManagerContext(),\n storage = createStorage({ type: StorageType.RAM })\n}: {\n signalContext?: MemorySignalManagerContext;\n storage?: Storage;\n} = {}) => {\n const networkManager = new NetworkManager({\n signalManager: new MemorySignalManager(signalContext),\n transportFactory: MemoryTransportFactory\n });\n\n const modelFactory = createDefaultModelFactory();\n return new ServiceContext(storage, networkManager, modelFactory);\n};\n\nexport const createPeers = async (numPeers: number) => {\n const signalContext = new MemorySignalManagerContext();\n\n return await Promise.all(\n Array.from(Array(numPeers)).map(async () => {\n const peer = createServiceContext({ signalContext });\n await peer.open();\n return peer;\n })\n );\n};\n\nexport const createIdentity = async (peer: ServiceContext) => {\n await peer.createIdentity();\n return peer;\n};\n\n// TODO(burdon): Remove @dxos/client-testing.\n// TODO(burdon): Create builder and make configurable.\nexport const syncItemsLocal = async (db1: DataPipelineControllerImpl, db2: DataPipelineControllerImpl) => {\n await testLocalDatabase(db1, db2);\n await testLocalDatabase(db2, db1);\n};\n\nexport class HostTestBuilder {\n public readonly signalContext = new MemorySignalManagerContext();\n\n createPeer(): TestPeer {\n return new TestPeer(this.signalContext);\n }\n}\n\nexport type TestPeerProps = {\n storage?: Storage;\n feedStore?: FeedStore<any>;\n metadataStore?: MetadataStore;\n keyring?: Keyring;\n networkManager?: NetworkManager;\n spaceManager?: SpaceManager;\n snapshotStore?: SnapshotStore;\n};\n\nexport class TestPeer {\n private _props: TestPeerProps = {};\n\n constructor(private readonly signalContext: MemorySignalManagerContext) {}\n\n get storage() {\n return (this._props.storage ??= createStorage({ type: StorageType.RAM }));\n }\n\n get keyring() {\n return (this._props.keyring ??= new Keyring(this.storage.createDirectory('keyring')));\n }\n\n get feedStore() {\n return (this._props.feedStore ??= new FeedStore({\n factory: new FeedFactory({\n root: this.storage.createDirectory('feeds'),\n signer: this.keyring,\n hypercore: {\n valueEncoding\n }\n })\n }));\n }\n\n get metadataStore() {\n return (this._props.metadataStore ??= new MetadataStore(this.storage.createDirectory('metadata')));\n }\n\n get snapshotStore() {\n return (this._props.snapshotStore ??= new SnapshotStore(this.storage.createDirectory('snapshots')));\n }\n\n get networkManager() {\n return (this._props.networkManager ??= new NetworkManager({\n signalManager: new MemorySignalManager(this.signalContext),\n transportFactory: MemoryTransportFactory\n }));\n }\n\n get spaceManager() {\n return (this._props.spaceManager ??= new SpaceManager({\n feedStore: this.feedStore,\n networkManager: this.networkManager\n }));\n }\n}\n\nexport const createSigningContext = async (keyring: Keyring): Promise<SigningContext> => {\n const identityKey = await keyring.createKey();\n const deviceKey = await keyring.createKey();\n\n return {\n identityKey,\n deviceKey,\n credentialSigner: createCredentialSignerWithChain(\n keyring,\n {\n credential: await new CredentialGenerator(keyring, identityKey, deviceKey).createDeviceAuthorization(deviceKey)\n },\n deviceKey\n ),\n recordCredential: async () => {} // No-op.\n };\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport assert from 'node:assert';\n\nimport { Trigger } from '@dxos/async';\nimport { InvitationsHandler } from '@dxos/client';\nimport { raise } from '@dxos/debug';\nimport { Invitation } from '@dxos/protocols/proto/dxos/client/services';\n\nexport const performInvitation = async <T>(host: InvitationsHandler<T>, guest: InvitationsHandler<T>, context: T) => {\n const done1 = new Trigger<Invitation>(); // peer 1 connected.\n const done2 = new Trigger<Invitation>(); // peer 2 connected.\n const observable1 = await host.createInvitation(context, { type: Invitation.Type.INTERACTIVE_TESTING });\n observable1.subscribe({\n onConnecting: async (invitation1: Invitation) => {\n const observable2 = await guest.acceptInvitation(invitation1, { type: Invitation.Type.INTERACTIVE_TESTING });\n observable2.subscribe({\n onConnecting: async (invitation2: Invitation) => {\n assert(invitation1.swarmKey!.equals(invitation2.swarmKey!));\n },\n onConnected: async (invitation2: Invitation) => {},\n onSuccess: (invitation) => {\n done2.wake(invitation);\n },\n onCancelled: () => raise(new Error()),\n onTimeout: (err: Error) => raise(err),\n onError: (err: Error) => raise(err)\n });\n },\n onConnected: async (invitation1: Invitation) => {},\n onCancelled: () => raise(new Error('cancelled')),\n onSuccess: (invitation) => {\n done1.wake(invitation);\n },\n onTimeout: (err: Error) => raise(err),\n onError: (err: Error) => raise(err)\n });\n\n await done1.wait();\n await done2.wait();\n};\n", "//\n// Copyright 2020 DXOS.org\n//\n\nimport assert from 'node:assert';\n\nimport { asyncTimeout, Trigger } from '@dxos/async';\nimport { Client, ClientServices, ClientServicesProxy, createDefaultModelFactory, Invitation } from '@dxos/client';\nimport { Config } from '@dxos/config';\nimport { raise } from '@dxos/debug';\nimport { DocumentModel } from '@dxos/document-model';\nimport { DatabaseBackendProxy, genesisMutation } from '@dxos/echo-db';\nimport { PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { MemorySignalManager, MemorySignalManagerContext, WebsocketSignalManager } from '@dxos/messaging';\nimport { createWebRTCTransportFactory, MemoryTransportFactory, NetworkManager } from '@dxos/network-manager';\nimport { Storage } from '@dxos/random-access-storage';\nimport { createLinkedPorts, createProtoRpcPeer, ProtoRpcPeer } from '@dxos/rpc';\n\nimport { ClientServicesHost, LocalClientServices } from '../services';\n\nexport const testConfigWithLocalSignal = new Config({\n version: 1,\n runtime: {\n services: {\n signal: {\n // TODO(burdon): Port numbers and global consts?\n server: 'ws://localhost:4000/.well-known/dx/signal'\n }\n }\n }\n});\n\n/**\n * Client builder supports different configurations, incl. signaling, transports, storage.\n */\nexport class TestBuilder {\n private readonly _config: Config;\n\n public storage?: Storage;\n\n // prettier-ignore\n constructor (\n config?: Config,\n private readonly _modelFactory = createDefaultModelFactory(),\n private readonly _signalManagerContext = new MemorySignalManagerContext()\n ) {\n this._config = config ?? new Config();\n }\n\n get config(): Config {\n return this._config;\n }\n\n /**\n * Get network manager using local shared memory or remote signal manager.\n */\n get networkManager() {\n const signalServer = this._config.get('runtime.services.signal.server');\n if (signalServer) {\n return new NetworkManager({\n log: true,\n signalManager: new WebsocketSignalManager([signalServer]),\n transportFactory: createWebRTCTransportFactory({\n iceServers: this._config.get('runtime.services.ice')\n })\n });\n }\n\n // Memory transport with shared context.\n return new NetworkManager({\n log: true,\n signalManager: new MemorySignalManager(this._signalManagerContext),\n transportFactory: MemoryTransportFactory\n });\n }\n\n /**\n * Create backend service handlers.\n */\n createClientServicesHost() {\n return new ClientServicesHost({\n config: this._config,\n modelFactory: this._modelFactory,\n networkManager: this.networkManager,\n storage: this.storage\n });\n }\n\n /**\n * Create local services host.\n */\n createLocal() {\n return new LocalClientServices({\n config: this._config,\n modelFactory: this._modelFactory,\n networkManager: this.networkManager,\n storage: this.storage\n });\n }\n\n /**\n * Create client/server.\n */\n createClientServer(host: ClientServicesHost = this.createClientServicesHost()): [Client, ProtoRpcPeer<{}>] {\n const [proxyPort, hostPort] = createLinkedPorts();\n const server = createProtoRpcPeer({\n exposed: host.descriptors,\n handlers: host.services as ClientServices,\n port: hostPort\n });\n // TODO(dmaretskyi): Refactor.\n\n const client = new Client({ services: new ClientServicesProxy(proxyPort) });\n return [client, server];\n }\n}\n\nexport const testSpace = async (create: DatabaseBackendProxy, check: DatabaseBackendProxy = create) => {\n const objectId = PublicKey.random().toHex();\n\n const result = create.mutate(genesisMutation(objectId, DocumentModel.meta.type));\n\n await result.batch.getReceipt();\n // TODO(dmaretskiy): await result.waitToBeProcessed()\n assert(create._itemManager.entities.has(result.objectsUpdated[0].id));\n\n await asyncTimeout(\n check.itemUpdate.waitForCondition(() => check._itemManager.entities.has(objectId)),\n 1000\n );\n\n return result;\n};\n\nexport const syncItems = async (db1: DatabaseBackendProxy, db2: DatabaseBackendProxy) => {\n // Check item replicated from 1 => 2.\n await testSpace(db1, db2);\n\n // Check item replicated from 2 => 1.\n await testSpace(db2, db1);\n};\n\nexport const joinCommonSpace = async ([initialPeer, ...peers]: Client[], spaceKey?: PublicKey): Promise<PublicKey> => {\n const rootSpace = spaceKey ? initialPeer.echo.getSpace(spaceKey) : await initialPeer.echo.createSpace();\n assert(rootSpace, 'Space not found.');\n\n await Promise.all(\n peers.map(async (peer) => {\n const hostDone = new Trigger<Invitation>();\n const guestDone = new Trigger<Invitation>();\n\n const hostObservabli = rootSpace.createInvitation({ type: Invitation.Type.INTERACTIVE_TESTING });\n log('invitation created');\n hostObservabli.subscribe({\n onConnecting: (invitation) => {\n const guestObservable = peer.echo.acceptInvitation(invitation);\n log('invitation accepted');\n\n guestObservable.subscribe({\n onSuccess: (invitation: Invitation) => {\n guestDone.wake(invitation);\n log('invitation guestDone');\n },\n onError: (err: Error) => raise(err)\n });\n },\n onSuccess: (invitation) => {\n hostDone.wake(invitation);\n log('invitation hostDone');\n },\n onError: (err) => raise(err)\n });\n\n await Promise.all([hostDone.wait(), guestDone.wait()]);\n })\n );\n\n return rootSpace.key;\n};\n"],
|
|
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OAAMD,GAAAA;QACjC,CAAA;MACF;MACAH,WAAW,CAACH,eAAe;AACzBV,iBAASc,KAAKJ,UAAAA;AACd5E,YAAI,uBAAA,CAAA,GAAA;;;;;;MACN;MACAiF,SAAS,CAACC,QAAQC,OAAMD,GAAAA;IAC1B,CAAA;AAEA,UAAMpB,QAAQC,IAAI;MAACG,SAASkB,KAAI;MAAIhB,UAAUgB,KAAI;KAAG;EACvD,CAAA,CAAA;AAGF,SAAO1B,UAAU2B;AACnB;",
|
|
6
|
+
"names": ["createCredential", "PublicKey", "createMockCredential", "signer", "issuer", "subject", "Buffer", "from", "assertion", "payload", "value", "createDefaultModelFactory", "createCredentialSignerWithChain", "CredentialGenerator", "SnapshotStore", "MetadataStore", "SpaceManager", "valueEncoding", "testLocalDatabase", "FeedFactory", "FeedStore", "Keyring", "MemorySignalManager", "MemorySignalManagerContext", "MemoryTransportFactory", "NetworkManager", "createStorage", "StorageType", "createServiceHost", "config", "signalManagerContext", "networkManager", "NetworkManager", "signalManager", "MemorySignalManager", "transportFactory", "MemoryTransportFactory", "ClientServicesHost", "createServiceContext", "signalContext", "MemorySignalManagerContext", "storage", "createStorage", "type", "StorageType", "RAM", "modelFactory", "createDefaultModelFactory", "ServiceContext", "createPeers", "numPeers", "Promise", "all", "Array", "from", "map", "peer", "open", "createIdentity", "syncItemsLocal", "db1", "db2", "testLocalDatabase", "HostTestBuilder", "createPeer", "TestPeer", "constructor", "_props", "keyring", "Keyring", "createDirectory", "feedStore", "FeedStore", "factory", "FeedFactory", "root", "signer", "hypercore", "valueEncoding", "metadataStore", "MetadataStore", "snapshotStore", "SnapshotStore", "spaceManager", "SpaceManager", "createSigningContext", "identityKey", "createKey", "deviceKey", "credentialSigner", "createCredentialSignerWithChain", "credential", "CredentialGenerator", "createDeviceAuthorization", "recordCredential", "assert", "Trigger", "raise", "Invitation", "performInvitation", "host", "guest", "context", "done1", "done2", "observable1", "createInvitation", "type", "Type", "INTERACTIVE_TESTING", "subscribe", "onConnecting", "invitation1", "observable2", "acceptInvitation", "invitation2", "swarmKey", "equals", "onConnected", "onSuccess", "invitation", "wake", "onCancelled", "Error", "onTimeout", "err", "onError", "wait", "assert", "asyncTimeout", "Trigger", "Client", "ClientServicesProxy", "createDefaultModelFactory", "Invitation", "Config", "raise", "DocumentModel", "genesisMutation", "PublicKey", "log", "MemorySignalManager", "MemorySignalManagerContext", "WebsocketSignalManager", "createWebRTCTransportFactory", "MemoryTransportFactory", "NetworkManager", "createLinkedPorts", "createProtoRpcPeer", "testConfigWithLocalSignal", "Config", "version", "runtime", "services", "signal", "server", "TestBuilder", "constructor", "config", "_modelFactory", "createDefaultModelFactory", "_signalManagerContext", "MemorySignalManagerContext", "_config", "networkManager", "signalServer", "get", "NetworkManager", "log", "signalManager", "WebsocketSignalManager", "transportFactory", "createWebRTCTransportFactory", "iceServers", "MemorySignalManager", "MemoryTransportFactory", "createClientServicesHost", "ClientServicesHost", "modelFactory", "storage", "createLocal", "LocalClientServices", "createClientServer", "host", "proxyPort", "hostPort", "createLinkedPorts", "createProtoRpcPeer", "exposed", "descriptors", "handlers", "port", "client", "Client", "ClientServicesProxy", "testSpace", "create", "check", "objectId", "PublicKey", "random", "toHex", "result", "mutate", "genesisMutation", "DocumentModel", "meta", "type", "batch", "getReceipt", "assert", "_itemManager", "entities", "has", "objectsUpdated", "id", "asyncTimeout", "itemUpdate", "waitForCondition", "syncItems", "db1", "db2", "joinCommonSpace", "initialPeer", "peers", "spaceKey", "rootSpace", "echo", "getSpace", "createSpace", "Promise", "all", "map", "peer", "hostDone", "Trigger", "guestDone", "hostObservabli", "createInvitation", "Invitation", "Type", "INTERACTIVE_TESTING", "subscribe", "onConnecting", "invitation", "guestObservable", "acceptInvitation", "onSuccess", "wake", "onError", "err", "raise", "wait", "key"]
|
|
7
7
|
}
|
package/dist/lib/node/index.cjs
CHANGED
|
@@ -2020,7 +2020,7 @@ var import_credentials10 = require("@dxos/credentials");
|
|
|
2020
2020
|
var import_echo_pipeline2 = require("@dxos/echo-pipeline");
|
|
2021
2021
|
var import_keys8 = require("@dxos/keys");
|
|
2022
2022
|
var import_log8 = require("@dxos/log");
|
|
2023
|
-
var
|
|
2023
|
+
var import_teleport_extension_gossip = require("@dxos/teleport-extension-gossip");
|
|
2024
2024
|
var import_util5 = require("@dxos/util");
|
|
2025
2025
|
|
|
2026
2026
|
// packages/sdk/client-services/src/packlets/spaces/data-space.ts
|
|
@@ -2042,6 +2042,7 @@ var import_protocols4 = require("@dxos/protocols");
|
|
|
2042
2042
|
var import_teleport3 = require("@dxos/teleport");
|
|
2043
2043
|
var import_util3 = require("@dxos/util");
|
|
2044
2044
|
var RETRY_TIMEOUT = 1e3;
|
|
2045
|
+
var SUCCESS_DELAY = 1e3;
|
|
2045
2046
|
var NOTARIZE_TIMEOUT = 1e4;
|
|
2046
2047
|
var NotarizationPlugin = class {
|
|
2047
2048
|
constructor() {
|
|
@@ -2064,7 +2065,7 @@ var NotarizationPlugin = class {
|
|
|
2064
2065
|
credentials
|
|
2065
2066
|
}, {
|
|
2066
2067
|
file: "notarization-plugin.ts",
|
|
2067
|
-
line:
|
|
2068
|
+
line: 50,
|
|
2068
2069
|
scope: this,
|
|
2069
2070
|
callSite: (f, a) => f(...a)
|
|
2070
2071
|
});
|
|
@@ -2076,7 +2077,7 @@ var NotarizationPlugin = class {
|
|
|
2076
2077
|
err
|
|
2077
2078
|
}, {
|
|
2078
2079
|
file: "notarization-plugin.ts",
|
|
2079
|
-
line:
|
|
2080
|
+
line: 59,
|
|
2080
2081
|
scope: this,
|
|
2081
2082
|
callSite: (f, a) => f(...a)
|
|
2082
2083
|
});
|
|
@@ -2087,7 +2088,7 @@ var NotarizationPlugin = class {
|
|
|
2087
2088
|
(0, import_async9.scheduleTask)(ctx, () => {
|
|
2088
2089
|
import_log7.log.warn("Notarization timeout", {}, {
|
|
2089
2090
|
file: "notarization-plugin.ts",
|
|
2090
|
-
line:
|
|
2091
|
+
line: 67,
|
|
2091
2092
|
scope: this,
|
|
2092
2093
|
callSite: (f, a) => f(...a)
|
|
2093
2094
|
});
|
|
@@ -2101,7 +2102,7 @@ var NotarizationPlugin = class {
|
|
|
2101
2102
|
if (this._extensions.size === 0) {
|
|
2102
2103
|
import_log7.log.warn("No peers to notarize with", {}, {
|
|
2103
2104
|
file: "notarization-plugin.ts",
|
|
2104
|
-
line:
|
|
2105
|
+
line: 82,
|
|
2105
2106
|
scope: this,
|
|
2106
2107
|
callSite: (f, a) => f(...a)
|
|
2107
2108
|
});
|
|
@@ -2115,7 +2116,7 @@ var NotarizationPlugin = class {
|
|
|
2115
2116
|
retryIn: RETRY_TIMEOUT
|
|
2116
2117
|
}, {
|
|
2117
2118
|
file: "notarization-plugin.ts",
|
|
2118
|
-
line:
|
|
2119
|
+
line: 89,
|
|
2119
2120
|
scope: this,
|
|
2120
2121
|
callSite: (f, a) => f(...a)
|
|
2121
2122
|
});
|
|
@@ -2129,7 +2130,7 @@ var NotarizationPlugin = class {
|
|
|
2129
2130
|
credentialId: credentials.map((credential) => credential.id)
|
|
2130
2131
|
}, {
|
|
2131
2132
|
file: "notarization-plugin.ts",
|
|
2132
|
-
line:
|
|
2133
|
+
line: 96,
|
|
2133
2134
|
scope: this,
|
|
2134
2135
|
callSite: (f, a) => f(...a)
|
|
2135
2136
|
});
|
|
@@ -2138,14 +2139,15 @@ var NotarizationPlugin = class {
|
|
|
2138
2139
|
});
|
|
2139
2140
|
(0, import_log7.log)("success", {}, {
|
|
2140
2141
|
file: "notarization-plugin.ts",
|
|
2141
|
-
line:
|
|
2142
|
+
line: 100,
|
|
2142
2143
|
scope: this,
|
|
2143
2144
|
callSite: (f, a) => f(...a)
|
|
2144
2145
|
});
|
|
2146
|
+
await (0, import_async9.sleep)(SUCCESS_DELAY);
|
|
2145
2147
|
} catch (err) {
|
|
2146
2148
|
import_log7.log.warn("error notarizing (recoverable)", err, {
|
|
2147
2149
|
file: "notarization-plugin.ts",
|
|
2148
|
-
line:
|
|
2150
|
+
line: 103,
|
|
2149
2151
|
scope: this,
|
|
2150
2152
|
callSite: (f, a) => f(...a)
|
|
2151
2153
|
});
|
|
@@ -2161,7 +2163,7 @@ var NotarizationPlugin = class {
|
|
|
2161
2163
|
]);
|
|
2162
2164
|
(0, import_log7.log)("done", {}, {
|
|
2163
2165
|
file: "notarization-plugin.ts",
|
|
2164
|
-
line:
|
|
2166
|
+
line: 114,
|
|
2165
2167
|
scope: this,
|
|
2166
2168
|
callSite: (f, a) => f(...a)
|
|
2167
2169
|
});
|
|
@@ -2214,7 +2216,7 @@ var NotarizationPlugin = class {
|
|
|
2214
2216
|
peer: extension.localPeerId
|
|
2215
2217
|
}, {
|
|
2216
2218
|
file: "notarization-plugin.ts",
|
|
2217
|
-
line:
|
|
2219
|
+
line: 163,
|
|
2218
2220
|
scope: this,
|
|
2219
2221
|
callSite: (f, a) => f(...a)
|
|
2220
2222
|
});
|
|
@@ -2226,7 +2228,7 @@ var NotarizationPlugin = class {
|
|
|
2226
2228
|
peer: extension.localPeerId
|
|
2227
2229
|
}, {
|
|
2228
2230
|
file: "notarization-plugin.ts",
|
|
2229
|
-
line:
|
|
2231
|
+
line: 168,
|
|
2230
2232
|
scope: this,
|
|
2231
2233
|
callSite: (f, a) => f(...a)
|
|
2232
2234
|
});
|
|
@@ -2285,6 +2287,7 @@ var DataSpace = class DataSpace2 {
|
|
|
2285
2287
|
constructor(params) {
|
|
2286
2288
|
this._ctx = new import_context6.Context();
|
|
2287
2289
|
this._inner = params.inner;
|
|
2290
|
+
this._gossip = params.gossip;
|
|
2288
2291
|
this._presence = params.presence;
|
|
2289
2292
|
this._keyring = params.keyring;
|
|
2290
2293
|
this._feedStore = params.feedStore;
|
|
@@ -2341,6 +2344,12 @@ var DataSpace = class DataSpace2 {
|
|
|
2341
2344
|
await this.notarizationPlugin.close();
|
|
2342
2345
|
await this._presence.destroy();
|
|
2343
2346
|
}
|
|
2347
|
+
async postMessage(channel, message) {
|
|
2348
|
+
return this._gossip.postMessage(channel, message);
|
|
2349
|
+
}
|
|
2350
|
+
listen(channel, callback) {
|
|
2351
|
+
return this._gossip.listen(channel, callback);
|
|
2352
|
+
}
|
|
2344
2353
|
async initializeDataPipeline() {
|
|
2345
2354
|
await this._inner.controlPipeline.state.waitUntilReachedTargetTimeframe({
|
|
2346
2355
|
timeout: CONTROL_PIPELINE_READY_TIMEFRAME
|
|
@@ -2521,11 +2530,14 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2521
2530
|
return space;
|
|
2522
2531
|
}
|
|
2523
2532
|
async _constructSpace(metadata) {
|
|
2524
|
-
const
|
|
2525
|
-
localPeerId: this._signingContext.deviceKey
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2533
|
+
const gossip = new import_teleport_extension_gossip.Gossip({
|
|
2534
|
+
localPeerId: this._signingContext.deviceKey
|
|
2535
|
+
});
|
|
2536
|
+
const presence = new import_teleport_extension_gossip.Presence({
|
|
2537
|
+
announceInterval: 500,
|
|
2538
|
+
offlineTimeout: 5e3,
|
|
2539
|
+
identityKey: this._signingContext.identityKey,
|
|
2540
|
+
gossip
|
|
2529
2541
|
});
|
|
2530
2542
|
const snapshotManager = new import_echo_pipeline2.SnapshotManager(this._snapshotStore);
|
|
2531
2543
|
const controlFeed = metadata.controlFeedKey && await this._feedStore.openFeed(metadata.controlFeedKey, {
|
|
@@ -2542,7 +2554,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2542
2554
|
credentialAuthenticator: (0, import_util5.deferFunction)(() => dataSpace.authVerifier.verifier)
|
|
2543
2555
|
},
|
|
2544
2556
|
onNetworkConnection: (session) => {
|
|
2545
|
-
session.addExtension("dxos.mesh.teleport.
|
|
2557
|
+
session.addExtension("dxos.mesh.teleport.gossip", gossip.createExtension({
|
|
2546
2558
|
remotePeerId: session.remotePeerId
|
|
2547
2559
|
}));
|
|
2548
2560
|
session.addExtension("dxos.mesh.teleport.objectsync", snapshotManager.objectSync.createExtension());
|
|
@@ -2556,6 +2568,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2556
2568
|
modelFactory: this._modelFactory,
|
|
2557
2569
|
metadataStore: this._metadataStore,
|
|
2558
2570
|
snapshotManager,
|
|
2571
|
+
gossip,
|
|
2559
2572
|
presence,
|
|
2560
2573
|
memberKey: this._signingContext.identityKey,
|
|
2561
2574
|
keyring: this._keyring,
|
|
@@ -2619,7 +2632,7 @@ var SpacesServiceImpl = class {
|
|
|
2619
2632
|
spaces
|
|
2620
2633
|
}, {
|
|
2621
2634
|
file: "spaces-service.ts",
|
|
2622
|
-
line:
|
|
2635
|
+
line: 62,
|
|
2623
2636
|
scope: this,
|
|
2624
2637
|
callSite: (f, a) => f(...a)
|
|
2625
2638
|
});
|
|
@@ -2657,6 +2670,25 @@ var SpacesServiceImpl = class {
|
|
|
2657
2670
|
}
|
|
2658
2671
|
});
|
|
2659
2672
|
}
|
|
2673
|
+
async postMessage({ spaceKey, channel, message }) {
|
|
2674
|
+
var _a;
|
|
2675
|
+
const dataSpaceManager = await this._getDataSpaceManager();
|
|
2676
|
+
const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug4.raise)(new import_echo_pipeline3.SpaceNotFoundError(spaceKey));
|
|
2677
|
+
await space.postMessage(getChannelId(channel), message);
|
|
2678
|
+
}
|
|
2679
|
+
subscribeMessages({ spaceKey, channel }) {
|
|
2680
|
+
return new import_codec_protobuf10.Stream(({ ctx, next }) => {
|
|
2681
|
+
(0, import_async12.scheduleTask)(ctx, async () => {
|
|
2682
|
+
var _a;
|
|
2683
|
+
const dataSpaceManager = await this._getDataSpaceManager();
|
|
2684
|
+
const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug4.raise)(new import_echo_pipeline3.SpaceNotFoundError(spaceKey));
|
|
2685
|
+
const handle = space.listen(getChannelId(channel), (message) => {
|
|
2686
|
+
next(message);
|
|
2687
|
+
});
|
|
2688
|
+
ctx.onDispose(() => handle.unsubscribe());
|
|
2689
|
+
});
|
|
2690
|
+
});
|
|
2691
|
+
}
|
|
2660
2692
|
queryCredentials({ spaceKey }) {
|
|
2661
2693
|
return new import_codec_protobuf10.Stream(({ ctx, next }) => {
|
|
2662
2694
|
var _a;
|
|
@@ -2700,6 +2732,7 @@ var SpacesServiceImpl = class {
|
|
|
2700
2732
|
};
|
|
2701
2733
|
}
|
|
2702
2734
|
};
|
|
2735
|
+
var getChannelId = (channel) => `user-channel/${channel}`;
|
|
2703
2736
|
|
|
2704
2737
|
// packages/sdk/client-services/src/packlets/storage/storage.ts
|
|
2705
2738
|
var import_errors = require("@dxos/errors");
|