Fix S.parseOrThrow export - #692
Conversation
WalkthroughAdds 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
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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
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 unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
scenarios/test_codegen/test/S_test.ts (2)
1-3: Importdescribeexplicitly and prefer Node’s strict assert (optional)Avoid relying on global
describeand 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: Avoidas anyin 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_codegenby 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.
📒 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 solidGood coverage for string, number, and bigint via
S.parseOrThrow.
19-21: Invalid input throw path coveredThis verifies the error path for mismatched schema. Looks good.
37-44: Union enum parsing and rejection — LGTMValid/invalid branches are both exercised appropriately.
| parseOrThrow: Sury.parseOrThrow, | ||
| }; |
There was a problem hiding this comment.
💡 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 --noEmitLength 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.
Summary by CodeRabbit