-
Notifications
You must be signed in to change notification settings - Fork 3
/
zml.d.ts
185 lines (157 loc) · 4.38 KB
/
zml.d.ts
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
type Optional<F> = F extends (arg: infer P) => infer R ? (arg?: P) => R : F
type OptionalInterface<T> = { [K in keyof T]: Optional<T[K]> }
interface InstanceMethod {
sendFile: (path: string, opts: Record<string, string>) => any
download: (url: string, opts?: Record<string, string>) => any
httpRequest: <T>(data: {
url: string
method: string
headers?: Record<string, string>
body?: Record<string, string>
timeout?: number
}) => Promise<{
status: number
statusText: string
headers: Record<string, any>
body: any
}>
fetch: <T>(data: {
url: string
method: string
headers?: Record<string, string>
body?: Record<string, string>
timeout?: number
}) => Promise<T>
request: <T>(data: {
method: string
params: Record<string, any>
}) => Promise<T>
call: (data: { method: string; params: Record<string, any> }) => void
}
interface CallBackInterface {
onReceivedFile: (fileObj: any) => void
onRequest: (
req: { method: string; params: Record<string, any> },
res: (error: any, data: any) => void,
) => any
onCall: (data: { method: string; params: Record<string, any> }) => any
onSettingsChange: (value: {
key: string
newValue: any
oldValue: any
}) => any
}
type AnyFunction = (options: string) => any
declare module '@zeppos/zml/base-app' {
type Instance<
TData extends DataOption,
TCustom extends CustomOption,
> = OptionalInterface<ILifeCycle> & Data<TData> & TCustom
type Options<
TData extends DataOption,
TCustom extends CustomOption,
> = (TCustom & Partial<Data<TData>> & Partial<ILifeCycle>) &
ThisType<Instance<TData, TCustom>>
interface ILifeCycle {
onCreate: AnyFunction
onDestroy: AnyFunction
}
interface Data<D extends DataOption> {
_options: this
globalData: D & {
messaging: any
}
}
type DataOption = Record<string, any>
type CustomOption = Record<string, any>
interface Constructor {
<TData extends DataOption, TCustom extends CustomOption>(
options: Options<TData, TCustom>,
): any
use(opts: (instance: any, ...args: any[]) => this | any): this
}
let BaseApp: Constructor
}
declare module '@zeppos/zml/base-page' {
type Instance<
TData extends DataOption,
TCustom extends CustomOption,
> = OptionalInterface<ILifeCycle> &
Omit<InstanceMethod, 'fetch' | 'download'> &
Data<TData> &
TCustom
type Options<
TData extends DataOption,
TCustom extends CustomOption,
> = (TCustom &
Partial<Data<TData>> &
Partial<ILifeCycle> &
Partial<Omit<CallBackInterface, 'onSettingsChange'>>) &
ThisType<Instance<TData, TCustom>>
interface ILifeCycle {
onInit: AnyFunction
onResume: AnyFunction
build: AnyFunction
onPause: AnyFunction
onDestroy: AnyFunction
}
type DataOption = Record<string, any>
type CustomOption = Record<string, any>
interface Data<D extends DataOption> {
_options: this
state: D
}
interface Constructor {
<TData extends DataOption, TCustom extends CustomOption>(
options: Options<TData, TCustom>,
): any
use(opts: (instance: any, ...args: any[]) => this | any): this
}
let BasePage: Constructor
}
declare module '@zeppos/zml/base-side' {
type Instance<
TData extends DataOption,
TCustom extends CustomOption,
> = OptionalInterface<ILifeCycle> &
Omit<InstanceMethod, 'httpRequest'> &
Data<TData> &
TCustom
type Options<
TData extends DataOption,
TCustom extends CustomOption,
> = (TCustom &
Partial<Data<TData>> &
Partial<ILifeCycle> &
Partial<CallBackInterface>) &
ThisType<Instance<TData, TCustom>>
interface ILifeCycle {
onInit: AnyFunction
onRun: AnyFunction
onDestroy: AnyFunction
}
type DataOption = Record<string, any>
type CustomOption = Record<string, any>
interface Data<D extends DataOption> {
state: D
}
interface Constructor {
<TData extends DataOption, TCustom extends CustomOption>(
options: Options<TData, TCustom>,
): any
use(opts: (instance: any, ...args: any[]) => this | any): this
}
let BaseSideService: Constructor
interface ISettingsLib {
getItem(i: string): any
setItem(i: string, v: any): any
clear(): void
removeItem(i: string): void
getAll(): any
}
let settingsLib: ISettingsLib
interface IConvertLib {
convert(opts: any): Promise<any>
}
let convertLib: IConvertLib
}