Skip to content

feat: add MethodRegistry and RpcMethodRegistry, wire into ws.ts (#132, #133) - #139

Open
harrryyd wants to merge 2 commits into
mainfrom
t3code/64814c14
Open

harrryyd wants to merge 2 commits into
mainfrom
t3code/64814c14

Conversation

@harrryyd

@harrryyd harrryyd commented Jun 21, 2026 •

Copy link
Copy Markdown
Owner

Closes #132, closes #133.

Summary

MethodRegistry (#132)

Generic utility in packages/contracts/src/methodRegistry.ts that wraps Map with duplicate-key detection:

  • register(key, value) — throws on duplicate
  • get(key) → Value | undefined
  • has(key) → boolean
  • entries() → IterableIterator<[Key, Value]>

RpcMethodRegistry (#133)

Uses MethodRegistry to wrap Effect RpcGroup.make() with individual method registrations:

  • register(methodName, schema, scope, handler) — uses MethodRegistry internally
  • getGroup() — lazily builds merged RpcGroup from all registrations
  • getScopeMap() — returns Map<string, AuthEnvironmentScope> for auth middleware
  • handlers() — returns Record<string, handler> for dispatch

Wire into ws.ts (#133)

  • Exported rpcRegistry instance for server-side use
  • requiredScopeForMethod checks registry scope map first, falls back to static RPC_REQUIRED_SCOPE
  • Handler dispatch merges registry handlers with old WsRpcGroup.of handlers (registry takes priority)
  • WebSocket startup merges registry group with static WsRpcGroup via WsRpcGroup.merge

…#133)

- Add generic MethodRegistry utility in packages/contracts/src/ - supports
  register/get/has/entries with duplicate-key detection
- Add RpcMethodRegistry wrapping MethodRegistry and RpcGroup - lazily builds
  WsRpcGroup from individual method registrations with scope tracking
- Wire rpcRegistry into ws.ts handler dispatch and scope resolution with
  fallback to existing static maps (RPC_REQUIRED_SCOPE, WsRpcGroup.of)
- WsRpcGroup.merge merges registry-built group with static group at startup
- Tests for MethodRegistry and RpcMethodRegistry
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:M labels Jun 21, 2026

@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: f3d49fcc7e

ℹ️ 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 apps/server/src/ws.ts
),
});
return {
...rpcRegistry.handlers(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Apply auth to registered RPC handlers

When a method is added via rpcRegistry.register, its handler is spread directly into the layer here, so it never passes through observeRpcEffect/observeRpcStream and the registered scope is not enforced. In any deployment that uses this registry for extension RPCs, a session without the required scope can call those registered methods successfully, unlike the built-in handlers that are wrapped with authorizeEffect/authorizeStream.

Useful? React with 👍 / 👎.

- Fix CLI.run invocation order for Effect.scoped compatibility
- Add Effect language service plugin, exactOptionalPropertyTypes
- Exclude test files from server tsconfig
@github-actions github-actions Bot added size:L and removed size:M labels Jul 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RPC method registry: core + wire into ws.ts Pre-factor: MethodRegistry generic utility

1 participant