Skip to content

Fix S.parseOrThrow export - #692

Merged
DZakh merged 2 commits into
mainfrom
dz/fix-parseorthrow-export
Aug 18, 2025
Merged

Fix S.parseOrThrow export#692
DZakh merged 2 commits into
mainfrom
dz/fix-parseorthrow-export

Conversation

@DZakh

@DZakh DZakh commented Aug 18, 2025

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features
    • Exposed parseOrThrow on the S public API for strict parsing with exceptions, enabling direct validation of primitives, bigints, object schemas with optional fields, and unions. No breaking changes.
  • Tests
    • Added comprehensive coverage for parsing of strings, numbers, bigints, object schemas with optional fields, unions, and expected error scenarios on invalid input.

@coderabbitai

coderabbitai Bot commented Aug 18, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds S.parseOrThrow to the public S mapping in codegenerator/cli/npm/envio/index.js, delegating to Sury.parseOrThrow. Introduces a new TypeScript test suite validating S.parseOrThrow and related schema primitives, optionals, and unions with Mocha.

Changes

Cohort / File(s) Summary
Public API mapping
codegenerator/cli/npm/envio/index.js
Exposes parseOrThrow via exports.S.parseOrThrow = Sury.parseOrThrow, expanding the exported S surface without changing existing mappings.
Test coverage for S.parseOrThrow and primitives
scenarios/test_codegen/test/S_test.ts
Adds Mocha tests covering S.parseOrThrow, primitives (string, number, bigint), schema, optional, and union, including valid parses and throw-on-invalid cases.

Sequence Diagram(s)

sequenceDiagram
  participant Consumer
  participant S as exports.S
  participant Sury

  Consumer->>S: parseOrThrow(input, schema)
  S->>Sury: parseOrThrow(input, schema)
  Sury-->>S: parsed value or throw
  S-->>Consumer: parsed value or propagated error
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • JonoPrest

Poem

I hop through code with whiskers bright,
A parse-or-throw now sees the light.
Schemas bloom, unions sing,
Optional fields do gentle spring.
With tests that thump a steady drum—
Ship it quick—then off I run! 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dz/fix-parseorthrow-export

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
scenarios/test_codegen/test/S_test.ts (2)

1-3: Import describe explicitly and prefer Node’s strict assert (optional)

Avoid relying on global describe and use the strict assert module to reduce default-import pitfalls with CJS.

Apply this diff:

-import assert from "assert";
-import { it } from "mocha";
+import assert from "node:assert/strict";
+import { describe, it } from "mocha";
 import { S } from "envio";

23-35: Avoid as any in optional-field assertion
The cast weakens test type-safety. Prefer accessing the optional property directly (Option A) or checking its absence (Option B):

Option A — typed optional:

-    assert.strictEqual((value as any).b, undefined);
+    assert.strictEqual(value.b, undefined);

Option B — property absence:

-    assert.strictEqual((value as any).b, undefined);
+    assert.ok(!('b' in value));

Also, please verify that everything compiles in scenarios/test_codegen by running:

cd scenarios/test_codegen
pnpm install
pnpm exec tsc --noEmit
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between cef9a67 and 809f675.

📒 Files selected for processing (2)
  • codegenerator/cli/npm/envio/index.js (1 hunks)
  • scenarios/test_codegen/test/S_test.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
scenarios/test_codegen/**/*.ts

📄 CodeRabbit Inference Engine (scenarios/test_codegen/.cursor/rules/hyperindex.mdc)

scenarios/test_codegen/**/*.ts: After changing any TypeScript files, run: pnpm tsc --noEmit to ensure successful compilation
When updating existing entities in handlers, always use the spread operator to create updated objects before persisting
For any external call (e.g., fetch), wrap it in an Effect via experimental_createEffect and consume via context.effect
Use !context.isPreload to skip logic that should not run during preload
In TypeScript, set relationship fields using *_id properties (e.g., token_id) rather than object references
Always cast timestamps from events to BigInt (e.g., BigInt(event.block.timestamp))
When matching addresses in configuration objects within code, ensure keys are lowercase and compare using address.toLowerCase()
Use string | undefined for optional string fields instead of string | null
Always normalize token amounts to a standard decimal (e.g., 18) before addition across tokens; use helpers like normalizeAmountToUSD()

Files:

  • scenarios/test_codegen/test/S_test.ts
codegenerator/cli/npm/envio/**

📄 CodeRabbit Inference Engine (.cursor/rules/navigation.mdc)

Library-fied runtime shared across indexers lives in codegenerator/cli/npm/envio.

Files:

  • codegenerator/cli/npm/envio/index.js
🧠 Learnings (4)
📚 Learning: 2025-08-11T08:49:57.399Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: scenarios/test_codegen/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-11T08:49:57.399Z
Learning: Applies to scenarios/test_codegen/**/*.ts : After changing any TypeScript files, run: pnpm tsc --noEmit to ensure successful compilation

Applied to files:

  • scenarios/test_codegen/test/S_test.ts
📚 Learning: 2025-08-11T08:49:57.399Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: scenarios/test_codegen/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-11T08:49:57.399Z
Learning: Applies to scenarios/test_codegen/**/*.ts : Use string | undefined for optional string fields instead of string | null

Applied to files:

  • scenarios/test_codegen/test/S_test.ts
📚 Learning: 2025-08-11T08:49:57.399Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: scenarios/test_codegen/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-11T08:49:57.399Z
Learning: Applies to scenarios/test_codegen/**/*.ts : In TypeScript, set relationship fields using *_id properties (e.g., token_id) rather than object references

Applied to files:

  • scenarios/test_codegen/test/S_test.ts
📚 Learning: 2025-08-11T08:49:57.399Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: scenarios/test_codegen/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-11T08:49:57.399Z
Learning: Applies to scenarios/test_codegen/**/*.ts : Always cast timestamps from events to BigInt (e.g., BigInt(event.block.timestamp))

Applied to files:

  • scenarios/test_codegen/test/S_test.ts
🔇 Additional comments (3)
scenarios/test_codegen/test/S_test.ts (3)

5-17: Primitives parsing coverage is solid

Good coverage for string, number, and bigint via S.parseOrThrow.


19-21: Invalid input throw path covered

This verifies the error path for mismatched schema. Looks good.


37-44: Union enum parsing and rejection — LGTM

Valid/invalid branches are both exercised appropriately.

Comment on lines +38 to 39
parseOrThrow: Sury.parseOrThrow,
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Expose S.parseOrThrow — LGTM; ensure d.ts stays in sync and TS check passes

The mapping looks correct and consistent with the rest of the S surface. Please verify that the TypeScript declarations (index.d.ts) also expose parseOrThrow, per the “Important! Should match the index.d.ts file” note, and run a TS check.

Run this script to confirm the declaration and type-check the repo:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Searching for envio/index.d.ts and parseOrThrow declaration…"
fd -a -g 'index.d.ts' codegenerator/cli/npm/envio | tee /dev/stderr

# Show S export block and presence of parseOrThrow
fd -a -g 'index.d.ts' codegenerator/cli/npm/envio | while read -r f; do
  echo "---- $f ----"
  rg -n -C3 'export\s+const\s+S\b' "$f" || true
  rg -n 'parseOrThrow' "$f" || true
done

echo "Searching TS usage of S.parseOrThrow…"
rg -n -C2 --type=ts '\bS\.parseOrThrow\b'

echo "Type-checking the workspace (no emit)…"
pnpm tsc --noEmit

Length of output: 312


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Locating index.d.ts in codegenerator/cli/npm/envio..."
files=$(fd --type f -g 'index.d.ts' codegenerator/cli/npm/envio || :)
if [ -z "$files" ]; then
  echo "❌ No index.d.ts found under codegenerator/cli/npm/envio"
  exit 1
fi

for f in $files; do
  echo "---- $f ----"
  grep -nE 'export\s+const\s+S\b' "$f" || echo "❌ Missing ‘export const S’ in $f"
  grep -n 'parseOrThrow' "$f" || echo "❌ ‘parseOrThrow’ not declared in $f"
done

echo "Verification complete."

Length of output: 813


Type declarations are out of sync – index.d.ts needs to export S.parseOrThrow

The .d.ts file currently only exports parseOrThrow at the top level and is missing the S object, so consumers calling S.parseOrThrow will have no type definitions. Please update before approving.

• codegenerator/cli/npm/envio/index.d.ts
– No export const S block
– Has export const parseOrThrow at top level instead of under S

Suggested change (example):

- export const parseOrThrow: typeof Sury.parseOrThrow;
+ export const S: {
+   /* …other members… */
+   parseOrThrow: typeof Sury.parseOrThrow;
+};

After updating, rerun pnpm tsc --noEmit to confirm the TS check passes.

🤖 Prompt for AI Agents
In codegenerator/cli/npm/envio/index.js around lines 38-39, the JS exports
include S.parseOrThrow but the TypeScript declaration file
codegenerator/cli/npm/envio/index.d.ts does not declare an exported S object and
instead only exports parseOrThrow at top-level; update index.d.ts to export a
const S with a parseOrThrow member (matching the runtime shape and types) and
remove or alias the top-level parseOrThrow export if necessary so consumers can
call S.parseOrThrow; after updating run pnpm tsc --noEmit to verify types.

@DZakh
DZakh enabled auto-merge (squash) August 18, 2025 14:30
@DZakh
DZakh merged commit 5c266f1 into main Aug 18, 2025
2 checks passed
@DZakh
DZakh deleted the dz/fix-parseorthrow-export branch August 18, 2025 14:38
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