All files / rpc-calls/src/caller CalleeCaller.ts

100% Statements 7/7
100% Branches 2/2
100% Functions 4/4
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 321x               1x       23x 23x             51x       29x       2x      
import {Observable, of} from 'rxjs';
import type {Callee} from '../callee/types';
import type {ProcedureReq, ProcedureRes, Procedures} from '../procedures';
import type {ProceduresToCallerMethods, Caller} from './types';
 
/**
 * In-process RPC caller that directly invokes a {@link Callee} instance.
 */
export class CalleeCaller<Ctx = unknown, P extends Procedures<any> = Procedures<Ctx>>
  implements Caller<ProceduresToCallerMethods<P>>
{
  constructor(
    protected readonly callee: Callee<Ctx, P>,
    public ctx: Ctx,
  ) {}
 
  public call$<K extends keyof P>(
    method: K,
    data: Observable<ProcedureReq<P[K]>> | ProcedureReq<P[K]>,
  ): Observable<ProcedureRes<P[K]>> {
    return this.callee.call$(method, data instanceof Observable ? data : of(data), this.ctx);
  }
 
  public call<K extends keyof P>(method: K, request: ProcedureReq<P[K]>): Promise<ProcedureRes<P[K]>> {
    return this.callee.call(method, request, this.ctx);
  }
 
  public notify<K extends keyof P>(method: K, data: ProcedureReq<P[K]>): void {
    this.callee.notify(method, data, this.ctx);
  }
}