/
leanengine.d.ts
173 lines (141 loc) · 5.11 KB
/
leanengine.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
import {Request, RequestHandler} from 'express';
import {User, Object as LCObject} from 'leancloud-storage';
export * from 'leancloud-storage';
declare namespace Express {
export interface Request {
AV: {
id: string,
key: string,
masterKey: string,
prod: number,
sessionToken: string
};
currentUser?: User;
sessionToken?: string;
}
export interface Response {
saveCurrentUser(user: User): void;
clearCurrentUser(): void;
}
}
interface InitializeOptions {
appId: string,
appKey: string,
masterKey?: string,
hookKey?: string,
}
interface MiddlewareOptions {
timeout?: string,
printFullStack?: boolean,
onError?(err: Error): void,
ignoreInvalidSessionToken?: boolean
}
export function init(options: InitializeOptions): void;
export function express(options?: MiddlewareOptions): RequestHandler;
export function koa(options?: MiddlewareOptions): Function;
export function koa2(options?: MiddlewareOptions): any;
declare class HookObject extends LCObject {
disableBeforeHook(): void;
disableAfterHook(): void;
updatedKeys?: string[];
}
export { HookObject as Object }
export namespace Insight {
type InsightHandler = (result: Object) => Promise<any>;
export function on(event: string, handler: InsightHandler): Promise<any>;
}
export namespace Cloud {
interface DefineOptions {
fetchUser?: boolean
internal?: boolean
}
interface RunOptions {
remote?: boolean,
user?: User,
sessionToken?: string,
req?: Request
}
interface EnqueueOptions {
attempts?: number,
backoff?: number,
delay?: number,
notify?: string,
retryTimeout?: boolean,
}
enum TaskStatus {
Queued = 'queued',
Success = 'success',
Failed = 'failed'
}
interface TaskInfo {
uniqueId: string
status: TaskStatus
finishedAt?: Date
statusCode?: number
result?: any
error?: string
retryAt?: Date
}
interface MiddlewareOptions {
framework?: string
}
interface CookieSessionOptions extends MiddlewareOptions {
secret: string
fetchUser?: boolean
}
interface CloudFunctionRequestMeta {
remoteAddress: string
}
interface CloudFunctionRequest {
meta: CloudFunctionRequestMeta,
params: Object,
currentUser?: User,
sessionToken?: string
}
interface ClassHookRequest {
object: HookObject,
currentUser?: User
}
interface UserHookRequest {
currentUser: User
}
type CloudFunction = (request: CloudFunctionRequest) => Promise<any>;
type ClassHookFunction = (request: ClassHookRequest) => Promise<any>;
type UserHookFunction = (request: UserHookRequest) => Promise<any>;
export class Error {
constructor(message: string, options?: {status?: number, code?: number})
}
export function define(name: string, options: DefineOptions, handler: CloudFunction): void;
export function define(name: string, handler: CloudFunction): void;
export function run(name: string, params?: Object, options?: RunOptions): Promise<any>;
export function rpc(name: string, params?: Object, options?: RunOptions): Promise<any>;
export function enqueue(name: string, params?: Object, options?: EnqueueOptions): Promise<{uniqueId: string}>;
export function getTaskInfo(uniqueId: string): Promise<TaskInfo>;
export function beforeSave(className: string, handler: ClassHookFunction): void;
export function afterSave(className: string, handler: ClassHookFunction): void;
export function beforeUpdate(className: string, handler: ClassHookFunction): void;
export function afterUpdate(className: string, handler: ClassHookFunction): void;
export function beforeDelete(className: string, handler: ClassHookFunction): void;
export function afterDelete(className: string, handler: ClassHookFunction): void;
export function onVerified(handler: UserHookFunction): void;
export function onLogin(handler: UserHookFunction): void;
export function onIMMessageReceived(handler: CloudFunction): void;
export function onIMReceiversOffline(handler: CloudFunction): void;
export function onIMMessageSent(handler: CloudFunction): void;
export function onIMMessageUpdate(handler: CloudFunction): void;
export function onIMConversationStart(handler: CloudFunction): void;
export function onIMConversationStarted(handler: CloudFunction): void;
export function onIMConversationAdd(handler: CloudFunction): void;
export function onIMConversationAdded(handler: CloudFunction): void;
export function onIMConversationRemove(handler: CloudFunction): void;
export function onIMConversationRemoved(handler: CloudFunction): void;
export function onIMConversationUpdate(handler: CloudFunction): void;
export function onIMClientOnline(handler: CloudFunction): void;
export function onIMClientOffline(handler: CloudFunction): void;
export function onIMClientSign(handler: CloudFunction): void;
export function LeanCloudHeaders(options?: MiddlewareOptions): RequestHandler;
export function CookieSession(options?: CookieSessionOptions): RequestHandler;
export function HttpsRedirect(options?: MiddlewareOptions): RequestHandler;
export function start(): void;
export function stop(): void;
}