Skip to content

Commit

Permalink
HandlersContext helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Jan 30, 2025
1 parent b789dc0 commit b7e371f
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions packages/rpc/src/RpcGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,7 @@ export interface RpcGroup<Rpcs extends Rpc.Any> extends Pipeable {
Rpc.ToHandler<Rpcs>,
EX,
| Exclude<RX, Scope>
| (
keyof Handlers extends infer K ? K extends keyof Handlers & string ? Handlers[K] extends (...args: any) =>
| Stream.Stream<infer _A, infer _E, infer _R>
| Effect.Effect<
ReadonlyMailbox<infer _A, infer _E>,
infer _EX,
infer _R
> ? Exclude<Rpc.ExcludeProvides<_R, Rpcs, K>, Scope> :
Handlers[K] extends (...args: any) => Effect.Effect<infer _A, infer _E, infer _R> ? _R
: never
: never
: never
)
| HandlersContext<Rpcs, Handlers>
>

/**
Expand Down Expand Up @@ -123,6 +111,23 @@ export type HandlersFrom<Rpc extends Rpc.Any> = {
>
}

/**
* @since 1.0.0
* @category groups
*/
export type HandlersContext<Rpcs extends Rpc.Any, Handlers> = keyof Handlers extends infer K ?
K extends keyof Handlers & string ? Handlers[K] extends (...args: any) =>
| Stream.Stream<infer _A, infer _E, infer _R>
| Effect.Effect<
ReadonlyMailbox<infer _A, infer _E>,
infer _EX,
infer _R
> ? Exclude<Rpc.ExcludeProvides<_R, Rpcs, K>, Scope> :
Handlers[K] extends (...args: any) => Effect.Effect<infer _A, infer _E, infer _R> ? _R
: never
: never
: never

const RpcGroupProto = {
add(this: RpcGroup<any>, ...rpcs: Array<any>) {
return makeProto({
Expand Down

0 comments on commit b7e371f

Please sign in to comment.