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

feat(store-indexer): add store indexer service #1198

Merged
merged 27 commits into from
Jul 31, 2023
Merged

Conversation

holic
Copy link
Member

@holic holic commented Jul 27, 2023

pulled out of #1113

@changeset-bot
Copy link

changeset-bot bot commented Jul 27, 2023

🦋 Changeset detected

Latest commit: 99eea46

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When 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

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
Copy link
Member Author

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)

@holic holic changed the base branch from main to holic/store-sync-recs July 28, 2023 15:13
@holic holic force-pushed the holic/store-indexer branch from 2d7ebb7 to b7a3ac0 Compare July 28, 2023 15:17
@holic holic force-pushed the holic/store-indexer branch from 1965124 to c34165a Compare July 28, 2023 15:23
import superjson from "superjson";

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export function createAppRouter() {
Copy link
Member Author

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.

@holic holic marked this pull request as ready for review July 28, 2023 15:38
@holic holic requested a review from alvrs as a code owner July 28, 2023 15:38
// 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
Copy link
Member

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 {
Copy link
Member

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> {
Copy link
Member

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> {
Copy link
Member

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

@holic
Copy link
Member Author

holic commented Jul 31, 2023

TS issue is coming from drizzle-team/drizzle-orm#682

Base automatically changed from holic/store-sync-recs to main July 31, 2023 12:07
"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"
Copy link
Member Author

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.

@holic holic requested a review from alvrs July 31, 2023 13:11
@holic holic merged commit e86fbc1 into main Jul 31, 2023
@holic holic deleted the holic/store-indexer branch July 31, 2023 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants