1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | import type {FusionPlugin, Context} from 'fusion-core';
|
10 | import {UniversalEventsToken} from 'fusion-plugin-universal-events';
|
11 | import {type Fetch, FetchToken} from 'fusion-tokens';
|
12 |
|
13 | import {
|
14 | RPCHandlersToken,
|
15 | BodyParserOptionsToken,
|
16 | RPCHandlersConfigToken,
|
17 | type HandlerType,
|
18 | } from './tokens.js';
|
19 |
|
20 | type ExtractReturnType = <V>(() => V) => V;
|
21 |
|
22 | export 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 |
|
30 | export 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 |
|
39 | export type RPCServiceType = {
|
40 | from: (ctx: Context) => RPCScopedServiceType,
|
41 | };
|
42 |
|
43 | export type RPCPluginType = FusionPlugin<RPCDepsType, RPCServiceType>;
|
44 |
|
45 | export type IEmitter = $Call<ExtractReturnType, typeof UniversalEventsToken>;
|
46 |
|
47 | export type RPCConfigType = {
|
48 | apiPath?: string,
|
49 | };
|