UNPKG

@ch1/rpc

Version:

JavaScript Remote Procedure Call (RPC)

93 lines 2.44 kB
/** * Project interfaces */ /** * tl;dr these are used in `RemoteDesc` to describe given API functions * * js-rpc uses these strings to identify types of "real world" functions that * it can interface with. * * These types are actually used by consumers of the library since they are the * specific strings enforced by `RemoteDesc` * * - ### "nodeCallback" * nodeCallback refers to JavaScript callback functions that strictly follow * two rules: * * - the _last_ parameter passed to a function is the callback * - a "Nullable Error" is the _first_ parameter passed to the callback * * Example: * * ```js * function add(a, b, callback) { * setTimeout(() => { * if (isNumber(a) && (isNumber(b)) { * callback(null, result); * } else { * callback(new TypeError('add is for numbers')); * } * }, 0); * } * * add(1, 2, (err, result) => expect(result).toBe(3); * add(1, 2, (err, result) => expect(error).toBeFalsey(); * add('1', 2), (erro, result) => expect(error instanceof Error).toBe(true); * ``` * * - ### "nodeEvent"/"nodeEventInternal" * nodeEvents are a _limited_ interface to * * [node EventEmitters](https://nodejs.org/api/events.html "docs") * * - ### "observable" * In this case observables refer to * [RxJS5](https://github.com/ReactiveX/rxjs, "RxJS") * * - ### "promise" * promises are es6 promises or any A+ promises that implement `.then` and * `.catch` along with the global `Promise` */ // export type RPCAsyncType = // | 'nodeCallback' // | 'nodeEvent' // | 'nodeEventInternal' // | 'observable' // | 'promise'; export const RPCAsyncType = { observable: 100, promise: 200, }; /** * The Different Types of RPC Events */ // export type RPCEventType = // | 'ack' // | 'addEventListener' // | 'create' // | 'createReturn' // | 'destroy' // | 'destroyReturn' // | 'fnReturn' // | 'invoke' // | 'nodeCallback' // | 'nodeOn' // | 'nodeRemoveListener' // | 'browserRemoveListener' // | 'observe' // | 'promise' // | 'subscribe' // | 'subscribeReturn' // | 'unSubscribeReturn'; export const RPCEventType = Object.freeze({ ack: 1, create: 2, createReturn: 3, destroy: 4, destroyReturn: 5, fnReturn: 6, invoke: 7, promise: 9, subscribe: 10, unsubscribe: 11, }); //# sourceMappingURL=interfaces.js.map