feat: add MethodRegistry and RpcMethodRegistry, wire into ws.ts (#132, #133)#139
feat: add MethodRegistry and RpcMethodRegistry, wire into ws.ts (#132, #133)#139harrryyd wants to merge 2 commits into
Conversation
…#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
There was a problem hiding this comment.
💡 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".
| ), | ||
| }); | ||
| return { | ||
| ...rpcRegistry.handlers(), |
There was a problem hiding this comment.
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
Closes #132, closes #133.
Summary
MethodRegistry (#132)
Generic utility in
packages/contracts/src/methodRegistry.tsthat wrapsMapwith duplicate-key detection:register(key, value)— throws on duplicateget(key)→Value | undefinedhas(key)→booleanentries()→IterableIterator<[Key, Value]>RpcMethodRegistry (#133)
Uses
MethodRegistryto wrap EffectRpcGroup.make()with individual method registrations:register(methodName, schema, scope, handler)— usesMethodRegistryinternallygetGroup()— lazily builds mergedRpcGroupfrom all registrationsgetScopeMap()— returnsMap<string, AuthEnvironmentScope>for auth middlewarehandlers()— returnsRecord<string, handler>for dispatchWire into ws.ts (#133)
rpcRegistryinstance for server-side userequiredScopeForMethodchecks registry scope map first, falls back to staticRPC_REQUIRED_SCOPEWsRpcGroup.ofhandlers (registry takes priority)WsRpcGroupviaWsRpcGroup.merge