HyperIndex v2.22.0

Released on 10 June 2025.

Big Clean-up Release

Add context.Entity.getOrCreate and context.Entity.getOrThrow API

// Before:
// let pool = await context.Pool.get(poolId);
// if (!pool) {
//  pool = {
//    id: poolId,
//    totalValueLockedETH: 0n
//  }
//  context.Pool.set(pool);
// }
const pool = await context.Pool.getOrCreate({
  id: poolId,
  totalValueLockedETH: 0n
})

// Before:
// const pool = await context.Pool.get(poolId);
// if (!pool) {
//  throw new Error(`Pool with ID ${poolId} is expected.`)
// }
const pool = await context.Pool.getOrThrow(poolId)
// Will throw: Entity 'Pool' with ID '...' is expected to exist.
// Or you can pass a custom message as a second argument:
const pool = await context.Pool.getOrThrow(poolId, `Pool with ID ${poolId} is expected.`)

These are additional helpers for DX improvements. You can access them from both handlers and loaders.

Loaders Consistency

Loaders are a powerful feature to optimise indexer performance (Docs). The loader function is run twice: the first time in parallel for all events in the batch, and the second time immediately before the handler execution, to obtain up-to-date data. This part is unchanged, but we've done several improvements here:

  • If the loader function fails on the first run, the error will be silently ignored. It may happen, depending on the entity, which will only be available on the second run. We don't want to abort indexing here, because it's a valid case.
  • The HyperIndex test framework runs the loaders twice to match the actual indexer logic.

Clever Batch Creation for Unordered Multichain Mode

Previously, even with Unordered Multichain Mode, we chose events to be batched from all available chains in the order of events on-chain. This is not bad, but for significant indexers relying on loader optimisation, it's better to have all events for a single chain in the batch. This way, there is a higher chance of achieving deduplication or batching optimization.

This is what we've done in the version. Now, we try to create a processing batch using events from one chain as much as possible, and then rotate to another chain for another batch.

Flexible Project Structure

To make HyperIndex run correctly, we used to have several requirements for the user's HyperIndex project, which was confusing and limited flexibility:

  • It required pnpm-workspaces.yaml file
  • It required .npmrc file with shamefully hoisting dependencies
  • It required to have the start script in your package.json with ts-node generated/src/Index.bs.js

Now, none of this is necessary, and you're free to remove them. You can also remove ts-node from dependencies, just replace ts-node generated/src/Index.bs.js with envio start.

Breaking Changes

Unfortunately, it required changing .bs.js suffix to .res.js in our internal code. So if you, for some reason, relied on some internal fiels with .bs.js extention, you need to change them to .res.js manually. Also, for ReScript users, it's now required to configure .res.js suffix in your rescript.json file.

Aggregate Queries Configuration

Note: Aggregate Queries might have a severe hit on Database performance. We generally recommend aggregating data using entities during indexing.

Now it's possible to enable Hasura Aggregate Queries using the ENVIO_HASURA_PUBLIC_AGGREGATE environment variable. You can set environment variables on our Hosted Service on Production plans.

ENVIO_HASURA_PUBLIC_AGGREGATE=["YourEntityName"]

Other Changes

  • Fixed test framework failing to set an entity with Json field the second time #565
  • Generated and exposed types for loaderArgs and handlerArgs per event #540
  • Remove unused scenarios folders #563
  • Librarify the entity config type #554
  • Librarify persistence layer #558
  • Add Prometheus metric to count Effect calls in #582
Contributors
DZakhJonoPrestmoose-code
View on GitHub