Skip to content

Genericize register signature in src/test.ts - #34

Closed
sethconvex wants to merge 1 commit into
mainfrom
genericize-register-signature
Closed

Genericize register signature in src/test.ts#34
sethconvex wants to merge 1 commit into
mainfrom
genericize-register-signature

Conversation

@sethconvex

Copy link
Copy Markdown

Summary

Match @convex-dev/agent's and @convex-dev/workflow's generic register signature so callers can pass a TestConvex with a specifically-inferred schema:

// before
export function register(
  t: TestConvex<SchemaDefinition<GenericSchema, boolean>>,
  name: string = "rateLimiter",
) { ... }

// after
export function register<
  Schema extends SchemaDefinition<GenericSchema, boolean>,
>(t: TestConvex<Schema>, name: string = "rateLimiter") { ... }

Context

TestConvex is invariant in its schema parameter (it appears in both contravariant input positions like t.query(...) args and covariant return positions). That means a TestConvex<SchemaDefinition<{ tableA: ..., tableB: ... }>> returned by convexTest(schema, modules) with a real schema is not assignable to TestConvex<SchemaDefinition<GenericSchema, boolean>>, even though the value is structurally fine.

Downstream projects currently work around this with a cast at the call site:

rateLimiter.register(
  t as unknown as TestConvex<SchemaDefinition<GenericSchema, boolean>>,
);

@convex-dev/agent already moved to a generic register signature in get-convex/agent@e29f2bb, and @convex-dev/workflow followed in 0.3.12. This PR brings rate-limiter in line so the cast can be dropped. See get-convex/agent#262 for the downstream context.

Test plan

  • npm run typecheck passes
  • npm test — all 94 tests pass
  • npm run lint clean
  • No runtime change — only the parameter type narrows from a fixed wide type to a generic constrained by the same wide type.

Match @convex-dev/agent's and @convex-dev/workflow's generic register
signature so callers can pass a TestConvex with a specifically-inferred
schema. Previously, the non-generic
`TestConvex<SchemaDefinition<GenericSchema, boolean>>` parameter
prevented this — TestConvex is invariant in its schema parameter, so a
specifically-typed `t` (e.g. from `convexTest(schema, modules)` with a
real schema) was not assignable to the wider type, forcing downstream
projects to add a type cast at the call site.

After this change, callers can do:

```ts
const t = convexTest(schema, modules);
agent.register(t);
workflow.register(t);
rateLimiter.register(t);  // no cast needed
```

No runtime change.
@coderabbitai

coderabbitai Bot commented May 10, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@sethconvex has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 50 minutes and 39 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: get-convex/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8577b16a-4166-4851-ba1b-b18c38c3127f

📥 Commits

Reviewing files that changed from the base of the PR and between 89d7dab and 1fb8008.

📒 Files selected for processing (1)
  • src/test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch genericize-register-signature

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.

@pkg-pr-new

pkg-pr-new Bot commented May 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@convex-dev/rate-limiter@34

commit: 1fb8008

@magicseth

Copy link
Copy Markdown

@codex review

@sethconvex
sethconvex requested a review from ianmacartney May 10, 2026 15:12

Copy link
Copy Markdown
Member

If you install the latest convex-test and/or the latest convex packages, this should not be an issue anymore

@sethconvex sethconvex closed this May 11, 2026

Copy link
Copy Markdown
Member

It isn't giving errors on main for me - but if you're still seeing issues after updating lmk! It took some work to get the GenericSchema to work with a specific schema

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