From 582388ba5f95c3efde56779058220dbd7aedee0b Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Thu, 3 Aug 2023 10:25:59 -0700 Subject: [PATCH] feat(store-sync): export singletonEntity as const, allow startBlock in syncToRecs (#1235) --- .changeset/metal-cats-double.md | 15 +++++++++++++++ .changeset/nice-moose-love.md | 11 +++++++++++ packages/store-sync/src/recs/index.ts | 1 + packages/store-sync/src/recs/singletonEntity.ts | 3 +++ packages/store-sync/src/recs/syncToRecs.ts | 6 ++---- 5 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 .changeset/metal-cats-double.md create mode 100644 .changeset/nice-moose-love.md create mode 100644 packages/store-sync/src/recs/singletonEntity.ts diff --git a/.changeset/metal-cats-double.md b/.changeset/metal-cats-double.md new file mode 100644 index 0000000000..12b14bbca5 --- /dev/null +++ b/.changeset/metal-cats-double.md @@ -0,0 +1,15 @@ +--- +"@latticexyz/store-sync": patch +--- + +Add `startBlock` option to `syncToRecs`. + +```ts +import { syncToRecs } from "@latticexyz/store-sync/recs"; +import worlds from "contracts/worlds.json"; + +syncToRecs({ + startBlock: worlds['31337'].blockNumber, + ... +}); +``` diff --git a/.changeset/nice-moose-love.md b/.changeset/nice-moose-love.md new file mode 100644 index 0000000000..f5c22dd5fa --- /dev/null +++ b/.changeset/nice-moose-love.md @@ -0,0 +1,11 @@ +--- +"@latticexyz/store-sync": minor +--- + +Export `singletonEntity` as const rather than within the `syncToRecs` result. + +```diff +- const { singletonEntity, ... } = syncToRecs({ ... }); ++ import { singletonEntity, syncToRecs } from "@latticexyz/store-sync/recs"; ++ const { ... } = syncToRecs({ ... }); +``` diff --git a/packages/store-sync/src/recs/index.ts b/packages/store-sync/src/recs/index.ts index 8809c234e0..706b5d4c65 100644 --- a/packages/store-sync/src/recs/index.ts +++ b/packages/store-sync/src/recs/index.ts @@ -4,4 +4,5 @@ export * from "./encodeEntity"; export * from "./entityToHexKeyTuple"; export * from "./hexKeyTupleToEntity"; export * from "./recsStorage"; +export * from "./singletonEntity"; export * from "./syncToRecs"; diff --git a/packages/store-sync/src/recs/singletonEntity.ts b/packages/store-sync/src/recs/singletonEntity.ts new file mode 100644 index 0000000000..53c70810be --- /dev/null +++ b/packages/store-sync/src/recs/singletonEntity.ts @@ -0,0 +1,3 @@ +import { hexKeyTupleToEntity } from "./hexKeyTupleToEntity"; + +export const singletonEntity = hexKeyTupleToEntity([]); diff --git a/packages/store-sync/src/recs/syncToRecs.ts b/packages/store-sync/src/recs/syncToRecs.ts index 870ff12195..de1954b28e 100644 --- a/packages/store-sync/src/recs/syncToRecs.ts +++ b/packages/store-sync/src/recs/syncToRecs.ts @@ -20,13 +20,13 @@ import { import { filter, map, tap, mergeMap, from, concatMap, Observable, share, firstValueFrom } from "rxjs"; import { BlockStorageOperations, blockLogsToStorage } from "../blockLogsToStorage"; import { recsStorage } from "./recsStorage"; -import { hexKeyTupleToEntity } from "./hexKeyTupleToEntity"; import { debug } from "./debug"; import { defineInternalComponents } from "./defineInternalComponents"; import { getTableKey } from "./getTableKey"; import { StoreComponentMetadata, SyncStep } from "./common"; import { encodeEntity } from "./encodeEntity"; import { createIndexerClient } from "../trpc-indexer"; +import { singletonEntity } from "./singletonEntity"; type SyncToRecsOptions< TConfig extends StoreConfig = StoreConfig, @@ -58,7 +58,6 @@ type SyncToRecsResult< > = { // TODO: return publicClient? components: TComponents & ReturnType; - singletonEntity: Entity; latestBlock$: Observable; latestBlockNumber$: Observable; blockLogs$: Observable; @@ -87,7 +86,7 @@ export async function syncToRecs< ...defineInternalComponents(world), }; - const singletonEntity = world.registerEntity({ id: hexKeyTupleToEntity([]) }); + world.registerEntity({ id: singletonEntity }); let startBlock = 0n; @@ -238,7 +237,6 @@ export async function syncToRecs< return { components, - singletonEntity, latestBlock$, latestBlockNumber$, blockLogs$,