Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

makes subscribe work on poll connectors #238

Merged
merged 1 commit into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/blockstore/store-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
});
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/fireproof/all-gateway.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down