UNPKG

1.33 kBJavaScriptView Raw
1/** Copyright (c) 2018 Uber Technologies, Inc.
2 *
3 * This source code is licensed under the MIT license found in the
4 * LICENSE file in the root directory of this source tree.
5 *
6 * @flow
7 */
8
9import type {FusionPlugin, Context} from 'fusion-core';
10import {UniversalEventsToken} from 'fusion-plugin-universal-events';
11import {type Fetch, FetchToken} from 'fusion-tokens';
12
13import {
14 RPCHandlersToken,
15 BodyParserOptionsToken,
16 RPCHandlersConfigToken,
17 type HandlerType,
18} from './tokens.js';
19
20type ExtractReturnType = <V>(() => V) => V;
21
22export type RPCDepsType = {
23 emitter: typeof UniversalEventsToken,
24 handlers?: typeof RPCHandlersToken,
25 bodyParserOptions?: typeof BodyParserOptionsToken.optional,
26 fetch?: typeof FetchToken,
27 rpcConfig?: typeof RPCHandlersConfigToken.optional,
28};
29
30export type RPCScopedServiceType = {
31 ctx: ?Context,
32 emitter: ?$Call<ExtractReturnType, typeof UniversalEventsToken>,
33 handlers: ?HandlerType,
34 fetch: ?Fetch,
35
36 request<TArgs, TResult>(method: string, args: TArgs): Promise<TResult>,
37};
38
39export type RPCServiceType = {
40 from: (ctx: Context) => RPCScopedServiceType,
41};
42
43export type RPCPluginType = FusionPlugin<RPCDepsType, RPCServiceType>;
44
45export type IEmitter = $Call<ExtractReturnType, typeof UniversalEventsToken>;
46
47export type RPCConfigType = {
48 apiPath?: string,
49};