diff --git a/src/mapeo-project.js b/src/mapeo-project.js index ab50f2e26..a820d2c1a 100644 --- a/src/mapeo-project.js +++ b/src/mapeo-project.js @@ -51,7 +51,7 @@ import { IconApi } from './icon-api.js' import { readConfig } from './config-import.js' import TranslationApi from './translation-api.js' /** @import { ProjectSettingsValue } from '@comapeo/schema' */ -/** @import { CoreStorage, KeyPair, Namespace } from './types.js' */ +/** @import { CoreStorage, KeyPair, Namespace, ReplicationStream } from './types.js' */ /** @typedef {Omit} EditableProjectSettings */ /** @typedef {ProjectSettingsValue['configMetadata']} ConfigMetadata */ @@ -581,20 +581,30 @@ export class MapeoProject extends TypedEmitter { * and only this project will replicate (to replicate multiple projects you * need to replicate the manager instance via manager[kManagerReplicate]) * - * @param {Parameters[0]} stream A duplex stream, a @hyperswarm/secret-stream, or a Protomux instance + * @param {( + * boolean | + * import('stream').Duplex | + * import('streamx').Duplex + * )} isInitiatorOrStream + * @returns {ReplicationStream} */ - [kProjectReplicate](stream) { - // @ts-expect-error - hypercore types need updating - const replicationStream = this.#coreManager.creatorCore.replicate(stream, { - // @ts-ignore - hypercore types do not currently include this option - ondiscoverykey: async (discoveryKey) => { - const protomux = - /** @type {import('protomux')} */ ( - replicationStream.noiseStream.userData - ) - this.#syncApi[kHandleDiscoveryKey](discoveryKey, protomux) - }, - }) + [kProjectReplicate](isInitiatorOrStream) { + const replicationStream = this.#coreManager.creatorCore.replicate( + isInitiatorOrStream, + /** + * Hypercore types need updating. + * @type {any} + */ ({ + /** @param {Buffer} discoveryKey */ + ondiscoverykey: async (discoveryKey) => { + const protomux = + /** @type {import('protomux')} */ ( + replicationStream.noiseStream.userData + ) + this.#syncApi[kHandleDiscoveryKey](discoveryKey, protomux) + }, + }) + ) return replicationStream }