diff --git a/src/blockstore/store-meta.ts b/src/blockstore/store-meta.ts index d9cf2028..4e824692 100644 --- a/src/blockstore/store-meta.ts +++ b/src/blockstore/store-meta.ts @@ -114,8 +114,14 @@ export class MetaStoreImpl extends BaseStoreImpl implements MetaStore { ensureLogger(sthis, "MetaStoreImpl"), ); if (remote && opts.gateway.subscribe) { - this.logger.Debug().Str("url", url.toString()).Msg("Subscribing to the gateway"); - opts.gateway.subscribe(url, (message: Uint8Array) => decodeGatewayMetaBytesToDbMeta(this.sthis, message)); + this.onStarted(async () => { + this.logger.Debug().Str("url", this.url().toString()).Msg("Subscribing to the gateway"); + opts.gateway.subscribe?.(this.url(), async (message: Uint8Array) => { + this.logger.Debug().Msg("Received message from gateway"); + const dbMetas = await decodeGatewayMetaBytesToDbMeta(this.sthis, message); + await this.loader?.handleDbMetasFromStore(dbMetas.map((m) => m.dbMeta)); + }); + }); } } diff --git a/tests/fireproof/all-gateway.test.ts b/tests/fireproof/all-gateway.test.ts index b00e04f6..20675008 100644 --- a/tests/fireproof/all-gateway.test.ts +++ b/tests/fireproof/all-gateway.test.ts @@ -388,6 +388,7 @@ describe("Gateway", function () { it("should delete data from Meta Gateway", async function () { const metaUrl = await metaGateway?.buildUrl(metaStore?._url, "main"); await metaGateway?.start(metaStore?._url); + // should we be testing .destroy() instead? const metaDeleteResult = await metaGateway?.delete(metaUrl?.Ok()); expect(metaDeleteResult?.Ok()).toBeFalsy(); });