Skip to content

Test Indexer: Add utilities to read/write entities in-between processing#924

Merged
DZakh merged 6 commits intomainfrom
claude/update-testindexer-entity-Tb83B
Jan 27, 2026
Merged

Test Indexer: Add utilities to read/write entities in-between processing#924
DZakh merged 6 commits intomainfrom
claude/update-testindexer-entity-Tb83B

Conversation

@DZakh
Copy link
Member

@DZakh DZakh commented Jan 20, 2026

const indexer = createTestIndexer();

const user: User = {
  id: "test-user-1",
  address: "0x1234",
  updatesCountOnUserForTesting: 5,
  gravatar_id: undefined,
  accountType: "USER",
};

// Set entity
indexer.User.set(user);

// Get entity
const retrieved = await indexer.User.get("test-user-1");
assert.deepEqual(retrieved, user);

await indexer.process({...}) // The user value will be available from handlers

Summary by CodeRabbit

  • New Features

    • Added direct entity get/set methods on the test indexer, with safeguards to block access during active processing.
  • Tests

    • Added tests covering storage, retrieval, overwrite behavior, and error handling when access occurs during processing.
  • Documentation

    • Updated ReScript guidance to recommend explicit type annotations when using the magic casting utility.

✏️ Tip: You can customize this high-level summary in your review settings.

- Add EntityOps type with get/set methods to TestIndexerFromConfig
- Implement makeEntityGet and makeEntitySet in TestIndexer.res
- Block entity operations during processing with clear error message
- Only expose entity ops for user entities (not internal tables)

This enables direct entity manipulation on test indexer:
  await indexer.Entity.get(id) // returns entity or undefined
  indexer.Entity.set(entity)   // sync, no await needed
- Inline entity operations directly on TestIndexerFromConfig type
- Remove separate TestIndexerEntities type
- Add tests for Entity.get and Entity.set operations
- Test error handling when called during processing
@DZakh DZakh requested a review from JonoPrest January 20, 2026 15:08
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 20, 2026

📝 Walkthrough

Walkthrough

A new public API exposes per-entity get and set operations on TestIndexer, implemented in type declarations and ReScript and guarded to error if invoked while the indexer is processing; unit tests and a small docs note were added.

Changes

Cohort / File(s) Summary
Type Definitions
codegenerator/cli/npm/envio/index.d.ts
Added EntityOps<Entity> type (get/set) and augmented TestIndexerFromConfig<Config> with a mapped type exposing per-entity EntityOps.
ReScript Implementation
codegenerator/cli/npm/envio/src/TestIndexer.res
Added makeEntityGet and makeEntitySet with state checks, introduced entityOps type, and wired per-entity ops into makeCreateTestIndexer result (excluded internal entities).
Tests
scenarios/test_codegen/test/EventHandler_test.ts
Added tests for Entity.set/Entity.get normal behavior, overwrite behavior, undefined for missing, and error cases when called during processing.
Docs
AGENTS.md
Added note about using Utils.magic with explicit type annotations in ReScript examples.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Client as Client
participant TestIndexer as TestIndexer
participant Store as EntityStore
rect rgba(200,200,255,0.5)
Client->>TestIndexer: call Entity.get(id) / Entity.set(entity)
TestIndexer->>TestIndexer: check processing state
alt processing running
TestIndexer-->>Client: throw/error "cannot access while processing"
else not processing
TestIndexer->>Store: read/write entity by id
Store-->>TestIndexer: return entity / ack
TestIndexer-->>Client: return result
end
end

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • JonoPrest
  • JasoonS

Poem

🐰 I nibble bytes in moonlit code,

I hop where entities abode,
Get and set with gentle paw,
But not while engines hum and draw —
Safe and snug, your data's stowed.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding utilities (get/set methods) to read and write entities in the TestIndexer between processing cycles.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

})->Utils.magic,
)

result->Utils.magic
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add explicit types for the type casting in this function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Collaborator

@JonoPrest JonoPrest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great looks good 🙏🏼

Non blocking but would prefer we always have explicit types for casting to make it easier to evolve code.

claude and others added 2 commits January 27, 2026 09:43
- Annotate Utils.magic with explicit input/output types in makeCreateTestIndexer
- Add ReScript coding rule to AGENTS.md about typing Utils.magic calls
@DZakh DZakh enabled auto-merge (squash) January 27, 2026 09:54
@DZakh DZakh merged commit 042d15e into main Jan 27, 2026
2 of 3 checks passed
@DZakh DZakh deleted the claude/update-testindexer-entity-Tb83B branch January 27, 2026 10:07
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.

3 participants