@ch1/rpc
Version:
JavaScript Remote Procedure Call (RPC)
48 lines (47 loc) • 2.85 kB
TypeScript
/**
* Utility functions
*/
import { Dictionary, RPC, RPCDefer, RPCNodeCallback, RPCEvent, RPCError, RPCErrorPayload, RPCInvocationPayload, RPCNotify, RPCReturnPayload } from './interfaces';
/**
* This function is for creating new instances of functions. This is handy for
* "enhancing" and enforcing correctness with certain event emitter libraries
*
* __Note__ this function will likely not work with arrow functions
*
* __Note__ this function uses `new Function`. Consequently functions will be
* created in the global context. In other words, make sure your function is
* pure and does not rely on external variables, unless those variables are
* global.
*/
export declare function createNewFunctionFrom(func: Function): Function;
export declare function isRPC<T>(arg: any): arg is RPC<T>;
export declare const isRPCDefaultAsync: (arg: any) => boolean;
export declare function isDefer<T>(thing: any): thing is RPCDefer<T>;
export declare function isError(err: any): err is Error;
export declare function isFunction(fn: any): fn is Function;
export declare function isObject(obj: any): obj is Object;
export declare function isString(arg: any): arg is string;
export declare function isDictionary<T>(dict: any): dict is Dictionary<T>;
export declare function isPromise<T>(promise: any): promise is Promise<T>;
export declare function isRPCNodeCallback<T>(arg: any): arg is RPCNodeCallback<T>;
export declare function isRPCNotify<T>(arg: any): arg is RPCNotify<T>;
export declare function isRPCEvent(event: any): event is RPCEvent;
export declare function isRPCError(error: any): error is RPCError;
export declare function isRPCErrorPayload(payload: any): payload is RPCErrorPayload;
export declare function isRPCInvocationPayload(payload: any): payload is RPCInvocationPayload;
export declare function isRPCReturnPayload(payload: any): payload is RPCReturnPayload;
export declare function noop(): void;
export declare const pnoop: () => Promise<void>;
export declare function createUidGenerator(): () => string;
export declare function defer<T>(): RPCDefer<T>;
export declare function createRangeError(message: any): RangeError;
export declare function createTypeError(message: any): TypeError;
export declare function rangeError(message: any): void;
export declare function safeInstantiate(fn: Function, args: any[]): any;
export declare function safeInvoke(fn: Function, args: any[]): any;
export declare function throwIfNotDefer(d: any, message?: string): void;
export declare function throwIfNotError(err: any, message?: string): void;
export declare function throwIfNotFunction(fn: any, message?: string): void;
export declare function throwIfNotRPCEvent(event: any, message?: string): void;
export declare function throwIfNotObject(obj: any, message?: string): void;
export declare function typeError(message: any): void;