UNPKG

rpc_ts

Version:

Remote Procedure Calls in TypeScript made simple

67 lines (66 loc) 2.56 kB
/** * @license * Copyright (c) Aiden.ai * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import { ModuleRpcClient } from '../../client'; import { ModuleRpcCommon } from '../../common'; import { ModuleRpcServer } from '../../server'; /** * This is the type of the request context that results from context decoding by the client * context connector (used client-side). * * In this mock authentication connector, what is provided is the ID of the user * performing the request. */ export declare type AuthRequestContext = { userId: string; }; /** * This is the type of the response context that results from context decoding by the server * context connector (used server-side). * * Here, the server sends an empty context to the client. */ export declare type AuthResponseContext = {}; /** * These are the context keys that the context connectors decode from. */ export declare const authContextKeys: { /** The key for the encoded context entry that stores the ID of the user making the request. */ userId: string; }; /** * This context connector is used client-side. */ export declare class AuthClientContextConnector implements ModuleRpcClient.ClientContextConnector<AuthResponseContext> { private readonly userId; constructor(userId: string); /** * Encode the request context that is sent to the server * (the server decodes it into an `AuthRequestContext` using the `AuthServerContextConnector`) */ provideRequestContext(): Promise<ModuleRpcCommon.EncodedContext>; /** * Decode the response context received from the server into an `AuthResponseContext`. */ decodeResponseContext(_encodedResponseContext: ModuleRpcCommon.EncodedContext): Promise<AuthResponseContext>; } /** * This context connector is used server-side. */ export declare class AuthServerContextConnector implements ModuleRpcServer.ServerContextConnector<AuthRequestContext> { private readonly expectedUserId; constructor(expectedUserId: string); /** * Decode the encode request context sent by the client into an `AuthRequestContext`. */ decodeRequestContext(encodedRequestContext: ModuleRpcCommon.EncodedContext): Promise<AuthRequestContext>; /** * Encode the response context that is sent to the client (the client decodes it * into an `AuthResponseContext` using the `AuthClientContextConnector`). */ provideResponseContext(): Promise<ModuleRpcCommon.EncodedContext>; }