-
Notifications
You must be signed in to change notification settings - Fork 202
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
feat(store-indexer): add store indexer service #1198
Conversation
🦋 Changeset detectedLatest commit: 99eea46 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
add usage example
let startBlock = env.START_BLOCK; | ||
try { | ||
const currentChainStates = database.select().from(chainState).where(eq(chainState.chainId, chain.id)).all(); | ||
// TODO: figure out if TS offers an option to turn on `undefined` as a possible outcome of getting an item from an array by index |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it does (noUncheckedIndexedAccess
) but it seems to trickle downstream and reveals a bunch of errors we can't really fix (e.g. in react packages)
2d7ebb7
to
b7a3ac0
Compare
1965124
to
c34165a
Compare
import superjson from "superjson"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type | ||
export function createAppRouter() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find an easy way to define the AppRouter
type manually to give this function a return type, so we'll disable the explicit return type for now.
// Resume from latest block stored in DB. This will throw if the DB doesn't exist yet, so we wrap in a try/catch and ignore the error. | ||
try { | ||
const currentChainStates = database.select().from(chainState).where(eq(chainState.chainId, chain.id)).all(); | ||
// TODO: replace this type workaround with `noUncheckedIndexedAccess: true` when we can fix all the issues related |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we create an issue for this? (the comment by itself requires context on what the issues are that need to be fixed before we can enable noUncheckedIndexedAccess: true
and remove this workaround)
maxBlockRange: bigint; | ||
}; | ||
|
||
export function createIndexer({ database, publicClient, startBlock, maxBlockRange }: CreateIndexerOptions): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we add some tsdoc style code documentation to this function? (ideally for all functions exported by the package)
import { StorageAdapter } from "@latticexyz/store-sync/trpc-indexer"; | ||
import { debug } from "../debug"; | ||
|
||
export async function createStorageAdapter(database: BaseSQLiteDatabase<"sync", any>): Promise<StorageAdapter> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's add some tsdoc style code docs here too
url: string; | ||
}; | ||
|
||
export function createIndexerClient({ url }: CreateIndexerClientOptions): CreateTRPCProxyClient<AppRouter> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's add a tsdoc code comment here too
TS issue is coming from drizzle-team/drizzle-orm#682 |
Co-authored-by: alvarius <[email protected]>
"start:local": "SQLITE_FILENAME=anvil.db CHAIN_ID=31337 pnpm start", | ||
"start:testnet": "SQLITE_FILENAME=testnet.db CHAIN_ID=4242 START_BLOCK=19037160 pnpm start", | ||
"start:testnet2": "SQLITE_FILENAME=testnet2.db CHAIN_ID=4243 pnpm start", | ||
"test": "tsc --noEmit --skipLibCheck" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should remove the skipLibCheck
flag once drizzle-team/drizzle-orm#682 is fixed.
pulled out of #1113