-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.flow.js
104 lines (85 loc) · 2.24 KB
/
types.flow.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* @flow
* @author Jean.h.ma 2020/6/1
*/
declare type QueryEntry = (entries: Array<string>)=>string | null;
declare interface ICerberusCache {
get(hash: string): string | null;
set(hash: string, code: string): any;
has(hash: string): boolean;
remove(hash: string): boolean;
clear(): any
}
declare type BundleRecord = {
secret: string,
hash: string,
bundles: Array<string>
};
declare interface IBundleCache {
get(secret: string): BundleRecord | null;
set(record: BundleRecord): any;
has(secret: string): boolean;
clear(): any;
}
declare type PreloadOptions = {
secret: string,
// bundle缓存
bundleCache?: IBundleCache,
}
declare type CerberusCacheResult = {
cache: ICerberusCache,
preload: (options: PreloadOptions)=>any
};
declare type Bundle = {
hash: string,
entry: Array<string>,
id: string
};
declare type UtilsResult = {
download: (entry: CerberusEntry) => Promise<string>
};
/**
* option参数对应fetch option
*/
declare type CerberusEntry = ?string | ?{ url: string, option?: Object };
declare type CerberusOption = {
/**
* 入口文件,例如:http://DOMAIN/main.js
*/
entry: CerberusEntry,
/**
* 全局唯一,建议使用content hash
*/
hash: string,
/**
* 备选方案,保证可用性,什么时候会触发备选方案?
* 1、当本地缓存不可用时
* 2、当代码编译失败时
*/
backup: ()=>Object,
/**
* 缓存实例,需要实现`ICerberusCache`接口,默认使用存策内存缓存,用户可以自己实现缓略,如果hash为null或者debug=true缓存将不会生效
*/
cache?: ?ICerberusCache,
/**
* 需要注入到小程序的module(自定义modules)
*/
injectModules?: ()=>Object,
/**
* 是否开起debug模式,默认值:false
*/
debug?: boolean,
};
declare type CloudCerberusProps = $Diff<CerberusOption, {| entry: any, hash: any |}> & {
secret: string,
/**
* 查询需要使用的entry,默认情况返回第一个entry
*/
queryEntry?: QueryEntry,
bundleCache?: ?IBundleCache,
// 调试模式的entry
debugEntry?: ?string
}
declare type CerberusContext = {
client: Object
};