Skip to content
This repository was archived by the owner on Oct 5, 2026. It is now read-only.

Detect async schema markers - #6

Closed
olstenlarck wants to merge 4 commits into
tunnckoCore:masterfrom
olstenlarck:agent/valibot-async-detection
Closed

olstenlarck wants to merge 4 commits into
tunnckoCore:masterfrom
olstenlarck:agent/valibot-async-detection

Conversation

@olstenlarck

@olstenlarck olstenlarck commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • infer Promise procedure signatures when input, output, or error schemas expose async: true, including Valibot
  • normalize runtime returns to a Promise for every branch of an async-marked procedure
  • document the remaining Standard Schema limitation and link upstream issue Explicit sync/async schemas standard-schema/standard-schema#22

Testing

  • TypeScript typecheck
  • Biome check
  • package build
  • Vitest: 123 tests passed across 9 files, including the built-package test

Partially #5, will remain open until StandardSchema async is figured out.

Summary by CodeRabbit

New Features

  • Procedures using asynchronous input, output, or error schemas now automatically return Promises.
  • Added support for detecting asynchronous Valibot schemas and inferring Promise-based result types.
  • Mixed synchronous and asynchronous schemas now preserve appropriate return behavior.
  • Async behavior is consistently handled for successful, invalid, and typed error results.

Documentation

  • Clarified async-schema behavior, including when callers must explicitly use await with validators such as Zod.
  • Added a reference to the relevant Standard Schema discussion.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Async schema markers are detected across input, output, and error schemas. Procedures with detected async schemas now expose Promise results and normalize execution with Promise.resolve. Valibot runtime and type-level tests cover synchronous, asynchronous, and union-typed schemas.

Changes

Async schema Promise handling

Layer / File(s) Summary
Schema async detection
src/types.ts
Adds tri-state async schema detection for input, output, and error-map schemas, plus conditional result typing.
Procedure Promise integration
src/index.ts
Updates handler and procedure result types, detects async schemas, and wraps asynchronous execution with Promise.resolve.
Async behavior validation and documentation
test/main.test.ts, test/types-testing.test.ts, README.md
Adds Valibot runtime and compile-time coverage and documents marker-based async detection and explicit await requirements.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant ZagoraHandler
  participant HasAsyncSchema
  participant forwardProcedure
  Caller->>ZagoraHandler: invoke procedure
  ZagoraHandler->>HasAsyncSchema: inspect configured schemas
  HasAsyncSchema-->>ZagoraHandler: async state
  ZagoraHandler->>forwardProcedure: execute procedure
  forwardProcedure-->>ZagoraHandler: result
  ZagoraHandler-->>Caller: direct result or Promise<ZagoraResult>
Loading

Possibly related issues

Possibly related PRs

  • tunnckoCore/zagora#4: Introduces the related async-schema behavior in the same implementation and test areas.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the PR's primary change: detecting async schema markers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Fix failing CI checks
🧪 Generate unit tests (beta)
  • Create PR with 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.

❤️ Share

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

@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 (3)
src/index.ts (1)

207-207: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid erasing the errors() generic contract with any.

Instantiate Zagora with the current generic arguments, including TErrors, instead of suppressing the constructor’s type checking. Confirm the typed construction passes the repository typecheck.

As per coding guidelines, don't use any.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/index.ts` at line 207, Update the Zagora instantiation in the surrounding
construction flow to preserve the existing generic arguments, including TErrors,
instead of casting the result to any. Remove the any cast and ensure the typed
constructor call passes the repository typecheck while retaining the errors()
contract.

Source: Coding guidelines

test/main.test.ts (2)

201-201: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Keep the invalid-input test type-safe.

Use @ts-expect-error for this intentional invalid call so the test also verifies that the public signature rejects numbers.

Proposed fix
-  const invalidInputResult = outputProcedure(123 as any);
+  // `@ts-expect-error` -- intentionally exercise runtime input validation
+  const invalidInputResult = outputProcedure(123);

As per coding guidelines, don't use any.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/main.test.ts` at line 201, Update the invalid-input test around
outputProcedure to remove the any cast and add a `@ts-expect-error` directive
immediately before the intentional numeric call. Preserve the runtime assertion
while ensuring TypeScript verifies that outputProcedure rejects numbers.

Source: Coding guidelines


3-3: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Replace the Valibot namespace imports with named imports.

Import the Valibot builders used in each test directly and replace the v.* references with named namespace imports.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/main.test.ts` at line 3, Replace the Valibot namespace imports and v.*
usages in test/main.test.ts at lines 3-3 and test/types-testing.test.ts at lines
31-31 with direct named imports for each builder used by the tests; update all
references in both files while preserving their existing behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/main.test.ts`:
- Around line 190-223: Extend the test “Valibot async schemas always return
promises” to cover asynchronous validation failures: call outputProcedure with
"bad" and assert the awaited result is a failed outcome, and call errorProcedure
with "fail" and assert the awaited result is also unsuccessful. Keep the
existing invalid-input and success assertions intact.

---

Nitpick comments:
In `@src/index.ts`:
- Line 207: Update the Zagora instantiation in the surrounding construction flow
to preserve the existing generic arguments, including TErrors, instead of
casting the result to any. Remove the any cast and ensure the typed constructor
call passes the repository typecheck while retaining the errors() contract.

In `@test/main.test.ts`:
- Line 201: Update the invalid-input test around outputProcedure to remove the
any cast and add a `@ts-expect-error` directive immediately before the intentional
numeric call. Preserve the runtime assertion while ensuring TypeScript verifies
that outputProcedure rejects numbers.
- Line 3: Replace the Valibot namespace imports and v.* usages in
test/main.test.ts at lines 3-3 and test/types-testing.test.ts at lines 31-31
with direct named imports for each builder used by the tests; update all
references in both files while preserving their existing behavior.
🪄 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 Plus

Run ID: a6a0e999-44d8-477e-8cf0-f78f3e476823

📥 Commits

Reviewing files that changed from the base of the PR and between 7bce098 and 9f87a0d.

📒 Files selected for processing (5)
  • README.md
  • src/index.ts
  • src/types.ts
  • test/main.test.ts
  • test/types-testing.test.ts

Comment thread test/main.test.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9f87a0d467

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/types.ts Resolved

@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.

🧹 Nitpick comments (1)
src/index.ts (1)

208-208: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid bypassing the errors() return type with any.

Construct the returned Zagora with its explicit generic arguments so the TErrors contract is preserved, instead of asserting the typed builder to any.

Proposed fix
-    return new Zagora({
+    return new Zagora<
+      THandlerFn,
+      TContext,
+      TInputSchema,
+      TOutputSchema,
+      TErrors,
+      TEnvVarsMap,
+      TCacheAdapter,
+      TDisableOptions,
+      TAutoCallable
+    >({
       ...this["~zagora"],
       errorsMap,
-    }) as any;
+    });

As per coding guidelines, “Don't use the any type.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/index.ts` at line 208, Remove the `as any` assertion at the returned
`Zagora` construction and instantiate it with explicit generic arguments,
preserving the `TErrors` contract exposed by `errors()` and maintaining the
existing typed builder behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/index.ts`:
- Line 208: Remove the `as any` assertion at the returned `Zagora` construction
and instantiate it with explicit generic arguments, preserving the `TErrors`
contract exposed by `errors()` and maintaining the existing typed builder
behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 00c3e8de-c36b-4a7b-a0c5-1d993fe73de2

📥 Commits

Reviewing files that changed from the base of the PR and between 9f87a0d and 6471494.

📒 Files selected for processing (4)
  • src/index.ts
  • src/types.ts
  • test/main.test.ts
  • test/types-testing.test.ts

@tunnckoCore

Copy link
Copy Markdown
Owner

the #7 is merged. closing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants