This repository has been archived by the owner on May 17, 2019. It is now read-only.
/
types.js
77 lines (62 loc) · 1.78 KB
/
types.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/** Copyright (c) 2018 Uber Technologies, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import type {Context as KoaContext} from 'koa';
export type Token<T> = {
(): T,
optional: () => void | T,
stacks: Array<{
// eslint-disable-next-line
type:
| 'token'
| 'plugin'
| 'register'
| 'enhance'
| 'alias-from'
| 'alias-to',
stack: string,
}>,
};
type ExtendedKoaContext = KoaContext & {memoized: Map<Object, mixed>};
export type SanitizedHTMLWrapper = Object;
export type SSRContext = {
element: any,
template: {
htmlAttrs: Object,
title: string,
head: Array<SanitizedHTMLWrapper>,
body: Array<SanitizedHTMLWrapper>,
bodyAttrs: {[string]: string},
},
} & ExtendedKoaContext;
export type Context = SSRContext | ExtendedKoaContext;
export type Middleware = (
ctx: Context,
next: () => Promise<void>
) => Promise<*>;
export type MiddlewareWithDeps<Deps> = (
Deps: $ObjMap<Deps, ExtractReturnType>
) => Middleware;
export type ExtractReturnType = <V>(() => V) => V;
export type FusionPlugin<Deps, Service> = {|
__plugin__: boolean,
stack: string,
deps?: Deps,
provides?: (Deps: $ObjMap<Deps & {}, ExtractReturnType>) => Service,
middleware?: (
Deps: $ObjMap<Deps & {}, ExtractReturnType>,
Service: Service
) => Middleware,
cleanup?: (service: Service) => Promise<void>,
|};
export type SSRDecider = Context => boolean;
export type aliaser<TToken> = {
alias: (sourceToken: TToken, destToken: TToken) => aliaser<TToken>,
};
export type cleanupFn = (thing: any) => Promise<void>;
export type SSRBodyTemplate = Context => $PropertyType<Context, 'body'>;
export type RenderType = (any, Context) => any;