Add contractName and eventName to event types and improve TypeScript event definitions - #1071
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds per-event metadata ( Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Source
participant Internal
participant Codegen
participant Handler
Client->>Source: emit raw event/log
Source->>Internal: construct generic event
Note over Internal: generic event includes\nparams, chainId, block, transaction,\nsrcAddress, logIndex, contractName, eventName
Internal->>Codegen: resolve typed event shape via EvmEvent/FuelEvent/envio.d.ts
Codegen-->>Handler: provide typed event (contractName, eventName, params, block, transaction)
Handler->>Handler: handler logic uses typed fields
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/cli/src/hbs_templating/codegen_templates.rs`:
- Around line 1378-1386: The FuelEventKind::Call arm currently returns "{}"
which drops the to/assetId/amount fields; update the match arm for
system_config::EventKind::Fuel(system_config::FuelEventKind::Call) to return the
same TypeScript shape as the Transfer arm ("{ readonly to: `0x${string}`;
readonly assetId: string; readonly amount: bigint }") so Fuel Call params are
emitted with to, assetId and amount consistent with how HyperFuelSource and
from_fuel_transfer_event expect them.
- Around line 1416-1445: The membership checks use f.name.snake but
selected_block_names/selected_tx_names contain camelCase keys (e.g. parentHash),
so fields explicitly enabled get treated as unselected; update the checks in the
block and transaction field mappings to compare against the camelCase name (use
f.name.camel) or normalize both sides (e.g. to_lowercase) so the if branches for
selected_block_names.contains(...) and selected_tx_names.contains(...) match the
actual keys and emit the non-deprecated types instead of never for enabled
fields.
In `@packages/cli/templates/dynamic/codegen/src/Types.ts.hbs`:
- Around line 42-63: The generics default for TEventName collapses to the
intersection of keys instead of the union because keyof over a union yields
common keys; fix both EvmEvent and FuelEvent by making the TEventName default
distributive so it computes the union per contract — replace the current default
TEventName extends keyof EvmContracts[TContractName] = keyof
EvmContracts[TContractName] with a distributive form like TEventName extends
keyof EvmContracts[TContractName] = TContractName extends any ? keyof
EvmContracts[TContractName] : never (and do the analogous change for FuelEvent
using FuelContracts) so the no-argument form returns the union/discriminated
union as documented.
In `@packages/envio/src/sources/RpcSource.res`:
- Around line 69-105: The regex literals in RpcSource.res (variables like
suggestedRangeRegExp, blockRangeLimitRegExp, alchemyRangeRegExp,
cloudflareRangeRegExp, thirdwebRangeRegExp, blockpiRangeRegExp, baseRangeRegExp,
maxAllowedBlocksRegExp, blastPaidRegExp, chainstackRegExp, coinbaseRegExp,
publicNodeRegExp, hyperliquidRegExp) use JavaScript /.../ syntax which breaks
ReScript; change each literal to the ReScript regex form %re(/.../) preserving
the same patterns so the file compiles (i.e., replace each /pattern/ with
%re(/pattern/) for all the listed RegExp variables).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 81c3a7a8-7b54-4ae3-94f3-d5ea2fefd9c7
⛔ Files ignored due to path filters (5)
packages/cli/src/hbs_templating/snapshots/envio__hbs_templating__codegen_templates__test__envio_dts_code_generated_for_evm.snapis excluded by!**/*.snappackages/cli/src/hbs_templating/snapshots/envio__hbs_templating__codegen_templates__test__envio_dts_code_generated_for_fuel.snapis excluded by!**/*.snappackages/cli/src/hbs_templating/snapshots/envio__hbs_templating__codegen_templates__test__indexer_code_generates_correct_types_and_values.snapis excluded by!**/*.snappackages/cli/src/hbs_templating/snapshots/envio__hbs_templating__codegen_templates__test__indexer_code_multiple_chains.snapis excluded by!**/*.snapscenarios/test_codegen/pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (9)
packages/cli/src/hbs_templating/codegen_templates.rspackages/cli/templates/dynamic/codegen/src/Types.ts.hbspackages/envio/index.d.tspackages/envio/src/Internal.gen.tspackages/envio/src/Internal.respackages/envio/src/SimulateItems.respackages/envio/src/sources/HyperFuelSource.respackages/envio/src/sources/HyperSyncSource.respackages/envio/src/sources/RpcSource.res
There was a problem hiding this comment.
♻️ Duplicate comments (1)
packages/cli/src/hbs_templating/codegen_templates.rs (1)
1382-1394:⚠️ Potential issue | 🟠 MajorFuel
Callparams are still generated as{}.Per the previous review, the runtime treats
CalllikeTransferwithto,assetId, andamountfields (seefrom_fuel_transfer_eventat lines 1002-1004 which handles bothCallandTransfer). The TypeScript type generation should match:🔧 Suggested fix
system_config::EventKind::Fuel(system_config::FuelEventKind::Transfer) => { "{ readonly to: `0x${string}`; readonly assetId: string; readonly amount: bigint }" .to_string() } - system_config::EventKind::Fuel(system_config::FuelEventKind::Call) => "{}".to_string(), + system_config::EventKind::Fuel(system_config::FuelEventKind::Call) => { + "{ readonly to: `0x${string}`; readonly assetId: string; readonly amount: bigint }" + .to_string() + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/cli/src/hbs_templating/codegen_templates.rs` around lines 1382 - 1394, The TypeScript type for Fuel::Call is incorrectly generated as "{}" while the runtime treats Call like Transfer; update the match arm in codegen_templates.rs for system_config::EventKind::Fuel(system_config::FuelEventKind::Call) to return the same TS shape as the Transfer arm ("{ readonly to: `0x${string}`; readonly assetId: string; readonly amount: bigint }".to_string()), so the generated type matches the runtime logic used by from_fuel_transfer_event.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@packages/cli/src/hbs_templating/codegen_templates.rs`:
- Around line 1382-1394: The TypeScript type for Fuel::Call is incorrectly
generated as "{}" while the runtime treats Call like Transfer; update the match
arm in codegen_templates.rs for
system_config::EventKind::Fuel(system_config::FuelEventKind::Call) to return the
same TS shape as the Transfer arm ("{ readonly to: `0x${string}`; readonly
assetId: string; readonly amount: bigint }".to_string()), so the generated type
matches the runtime logic used by from_fuel_transfer_event.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 866a8c29-c73f-452d-a8d6-7fae8dbd01ab
⛔ Files ignored due to path filters (2)
packages/cli/src/hbs_templating/snapshots/envio__hbs_templating__codegen_templates__test__envio_dts_code_generated_for_evm.snapis excluded by!**/*.snappackages/cli/src/hbs_templating/snapshots/envio__hbs_templating__codegen_templates__test__envio_dts_code_generated_for_fuel.snapis excluded by!**/*.snap
📒 Files selected for processing (2)
packages/cli/src/hbs_templating/codegen_templates.rspackages/cli/templates/dynamic/codegen/src/Types.ts.hbs
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/cli/templates/dynamic/codegen/src/Types.ts.hbs
There was a problem hiding this comment.
♻️ Duplicate comments (1)
packages/cli/src/hbs_templating/codegen_templates.rs (1)
1396-1396:⚠️ Potential issue | 🟠 MajorFuel
Callparams are still generated as{}.The
FuelEventKind::Callarm generates an empty object"{}"for params, but the ReScript codegen (lines 1002-1004) usesfrom_fuel_transfer_eventfor bothCallandTransfer, meaning they share the same params shape at runtime (to,assetId,amount).This creates a type mismatch between the generated TypeScript declaration and actual runtime values.
🔧 Suggested fix
system_config::EventKind::Fuel(system_config::FuelEventKind::Transfer) => { "{ readonly to: `0x${string}`; readonly assetId: string; readonly amount: bigint }" .to_string() } - system_config::EventKind::Fuel(system_config::FuelEventKind::Call) => "{}".to_string(), + system_config::EventKind::Fuel(system_config::FuelEventKind::Call) => { + "{ readonly to: `0x${string}`; readonly assetId: string; readonly amount: bigint }" + .to_string() + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/cli/src/hbs_templating/codegen_templates.rs` at line 1396, The FuelEventKind::Call arm in the match for system_config::EventKind::Fuel currently returns an empty params string ("{}"), causing a TypeScript mismatch; modify the FuelEventKind::Call arm in codegen_templates.rs so it generates the same params shape as FuelEventKind::Transfer (i.e., include "to", "assetId", "amount") so it matches the runtime helper from_fuel_transfer_event used by ReScript; update the arm that references FuelEventKind::Call to produce the same object fields as the Transfer arm to keep declarations consistent with runtime values.
🧹 Nitpick comments (1)
packages/cli/src/config_parsing/system_config.rs (1)
1754-1759: Type mapping inconsistency forAccessListandAuthorizationList.These fields use
TypeIdent::Unknownhere, buttry_from_config_field_selection(lines 1904-1911) maps them toTypeApplicationwith specific HyperSyncClient types:// In try_from_config_field_selection: Tx::AccessList => Res::option(Res::Array(Box::new(Res::TypeApplication { name: "HyperSyncClient.ResponseTypes.accessList".to_string(), type_params: vec![], }))),If
all_evm()is used for TypeScript type generation, this could result inunknown[]instead of the proper type. Consider whether these should match, or ifUnknownis intentional for the "all fields" case.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/cli/src/config_parsing/system_config.rs` around lines 1754 - 1759, The TypeIdent mapping for TransactionField::AccessList and ::AuthorizationList currently returns TypeIdent::option(TypeIdent::array(TypeIdent::Unknown)), which conflicts with try_from_config_field_selection's Res::TypeApplication mapping (e.g. "HyperSyncClient.ResponseTypes.accessList"); update the constructors in the match arm to return TypeIdent::option(TypeIdent::array(TypeIdent::TypeApplication { name: "HyperSyncClient.ResponseTypes.accessList".to_string(), type_params: vec![] })) and similarly for authorizationList (matching the names used in try_from_config_field_selection), so TypeScript generation for all_evm() yields the same concrete types rather than unknown[]; if Unknown was intentionally used for an "all fields" fallback, add a comment clarifying that intent instead of changing behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@packages/cli/src/hbs_templating/codegen_templates.rs`:
- Line 1396: The FuelEventKind::Call arm in the match for
system_config::EventKind::Fuel currently returns an empty params string ("{}"),
causing a TypeScript mismatch; modify the FuelEventKind::Call arm in
codegen_templates.rs so it generates the same params shape as
FuelEventKind::Transfer (i.e., include "to", "assetId", "amount") so it matches
the runtime helper from_fuel_transfer_event used by ReScript; update the arm
that references FuelEventKind::Call to produce the same object fields as the
Transfer arm to keep declarations consistent with runtime values.
---
Nitpick comments:
In `@packages/cli/src/config_parsing/system_config.rs`:
- Around line 1754-1759: The TypeIdent mapping for TransactionField::AccessList
and ::AuthorizationList currently returns
TypeIdent::option(TypeIdent::array(TypeIdent::Unknown)), which conflicts with
try_from_config_field_selection's Res::TypeApplication mapping (e.g.
"HyperSyncClient.ResponseTypes.accessList"); update the constructors in the
match arm to return
TypeIdent::option(TypeIdent::array(TypeIdent::TypeApplication { name:
"HyperSyncClient.ResponseTypes.accessList".to_string(), type_params: vec![] }))
and similarly for authorizationList (matching the names used in
try_from_config_field_selection), so TypeScript generation for all_evm() yields
the same concrete types rather than unknown[]; if Unknown was intentionally used
for an "all fields" fallback, add a comment clarifying that intent instead of
changing behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f089e2bc-6195-469b-9b2b-9c94bc423341
⛔ Files ignored due to path filters (2)
packages/cli/src/hbs_templating/snapshots/envio__hbs_templating__codegen_templates__test__envio_dts_code_generated_for_evm.snapis excluded by!**/*.snappackages/cli/src/hbs_templating/snapshots/envio__hbs_templating__codegen_templates__test__envio_dts_code_generated_for_fuel.snapis excluded by!**/*.snap
📒 Files selected for processing (8)
.claude/settings.jsonpackages/cli/src/config_parsing/human_config.rspackages/cli/src/config_parsing/system_config.rspackages/cli/src/hbs_templating/codegen_templates.rspackages/cli/templates/dynamic/codegen/src/Types.ts.hbspackages/envio/src/sources/RpcSource.resscenarios/test_codegen/src/handlers/EventHandlers.tsscenarios/test_codegen/test/CustomSelection.test.ts
💤 Files with no reviewable changes (1)
- scenarios/test_codegen/src/handlers/EventHandlers.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/cli/templates/dynamic/codegen/src/Types.ts.hbs
56dd9e3 to
b4f1569
Compare
- Add contractName and eventName fields to genericEvent for runtime discrimination - Modify EvmContracts/FuelContracts to contain full event types with literal discriminant fields, typed params, block/transaction fields - Generate ALL available block/transaction fields per event (selected with proper types, unselected as never with @deprecated YAML config example including event signature) - Generate FuelTypes interface for Fuel ABI type references - Define EvmEvent<TContractName, TEventName> and FuelEvent types - Remove @Gentype from event/params/block/transaction (exposed via envio.d.ts) - Rename eventArgs to params in generated ReScript - Import Address from envio, BigDecimal from bignumber.js in envio.d.ts - Fix Fuel Call params to match Transfer (to, assetId, amount) - Fix Fuel block fields to not include EVM defaults - Add TypeScript and ReScript tests for event handler field access https://claude.ai/code/session_015qQJTt3EmYtGa7jZKcLBGH
…es, remove eventLog - Fix 4-space indentation for deprecated fields inside module type definitions - Match ReScript @deprecated message to TypeScript format with YAML config example - Pass all_ecosystem_fields to per-event custom field selection for deprecated markers - Remove eventLog type alias, inline Internal.genericEvent in HandlerTypes https://claude.ai/code/session_015qQJTt3EmYtGa7jZKcLBGH
Replace Indexer.eventLog<T> with per-event types (e.g. Indexer.Gravatar.NewGravatar.event) in MockEvents.res and Internal.genericEvent in test files that need the generic form. Remove unused eventLog import from EventHandlers.ts. https://claude.ai/code/session_015qQJTt3EmYtGa7jZKcLBGH
…types The per-event `event` type is nominally different from Internal.genericEvent, which causes type errors when passed to Internal.fromGenericEvent. https://claude.ai/code/session_015qQJTt3EmYtGa7jZKcLBGH
The generated test files require worker threads that time out in the template-tests CI environment which has no database services. https://claude.ai/code/session_015qQJTt3EmYtGa7jZKcLBGH
… CI" This reverts commit 8c154a6.
The generated tests time out in the CI environment. https://claude.ai/code/session_015qQJTt3EmYtGa7jZKcLBGH
d916caf to
c21a93a
Compare
Typo was pre-existing in the template (from #1071) but my previous commit moved the string, so address the CodeRabbit review comment while it is still topical. https://claude.ai/code/session_01YCbJaSa8Vpi5tSgU8WRWcS
* Drop -3 from remaining warnings; migrate deprecated bindings Continues the Js.* → ReScript stdlib migration from #1103 for the places where the -3 warning suppression was still left: - scenarios/test_codegen and scenarios/fuel_test: ran rescript-tools migrate-all, plus manual fixes for Array.sort (now returns unit — switched to Array.toSorted) with Int.compare comparators, and string_of_int/float_of_int → Int.toString/Int.toFloat. - packages/cli/templates/static/{codegen,blank_template}/rescript.json: dropped "warnings": -3. Templates regenerate indexer code, so also updated the Rust codegen: - type_schema.rs: Js.Json.t → JSON.t, Js.Date.t → Date.t, Js.Date.fromFloat → Date.fromTime. - codegen_templates.rs: SingleOrMultiple now uses Array.isArray instead of Js.Json.decodeArray, with JSON.t aliases. - Regenerated insta snapshots. https://claude.ai/code/session_01YCbJaSa8Vpi5tSgU8WRWcS * Fix chainId sort ordering after migrate to Int.compare The migration from Array.sort with subtraction to Array.toSorted with Int.compare changed the runtime behaviour: the old a - b on Obj.magic strings relied on JS numeric coercion, so "137" - "1337" = -1200 sorted numerically. Int.compare uses the < primitive which compares strings lexicographically, so "1337" < "137" and the metric rows came out in the wrong order, breaking the multichain rollback test. Parse the chainId/value strings with Int.fromString before comparing so the sort keeps its original numeric semantics. https://claude.ai/code/session_01YCbJaSa8Vpi5tSgU8WRWcS * Fix typo: interperated → interpreted in SingleOrMultiple error Typo was pre-existing in the template (from #1071) but my previous commit moved the string, so address the CodeRabbit review comment while it is still topical. https://claude.ai/code/session_01YCbJaSa8Vpi5tSgU8WRWcS --------- Co-authored-by: Claude <noreply@anthropic.com>
Summary
This PR enhances event type definitions by adding
contractNameandeventNamefields to all event types, and significantly improves TypeScript type generation for EVM and Fuel contract events with full field selection support.Key Changes
Added contractName and eventName fields: Updated the
genericEventtype in ReScript and TypeScript to includecontractNameandeventNamefields, making event metadata more accessible to indexers.Enhanced TypeScript event type generation: Replaced simple event name unions with full discriminated union types that include:
Improved field selection handling:
ts_typefield toEventParamTypeTemplateandSelectedFieldTemplatefor accurate TypeScript type generationts_transaction_typeandts_block_typetoFieldSelectionstructgenerate_contract_event_ts_type()method to generate complete event types with field selection awarenessUpdated event type structure: Modified
EvmContractsandFuelContractstypes from{ events: string }to nested objects with full event type definitions.Code formatting improvements:
%re()wrapper)Added TypeScript helper types: Introduced
EvmEvent<>andFuelEvent<>generic types in Types.ts.hbs for convenient event type lookups by contract and event name.Updated test snapshots: Regenerated snapshots to reflect the new event type structure with full field definitions.
Implementation Details
The TypeScript event type generation now:
nevertype with@deprecatedJSDoc commentshttps://claude.ai/code/session_015qQJTt3EmYtGa7jZKcLBGH
Summary by CodeRabbit
New Features
Configuration Changes
Tests
Chores