forked from mx-space/snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.d.ts
132 lines (106 loc) · 2.89 KB
/
global.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
// THIS FILE FOR MONACO EDITOR CODE COMPLETION
// TYPE DECLARATION FOR SERVERLESS FUNCTION
declare interface FunctionContextResponse {
throws(code: number, message: any): void
type(type: string): FunctionContextResponse
status(code: number, statusMessage?: string): FunctionContextResponse
send(data: any): void
}
declare interface FunctionContextRequest {
query: Record<string, string>
headers: Record<string, string>
params: Record<string, string>
method: string
}
declare interface FastifyRequest extends FunctionContextRequest {
body: any
[k: string]: any
}
declare interface ServiceGetter {
getService(name: 'http'): {
axios: any
requestWithCatch: (url: string) => Promise<any>
}
getService(name: 'config'): {
get: (key: string) => Promise<any>
}
}
declare interface Context extends FunctionContextResponse {}
declare interface Context extends FunctionContextRequest {}
declare interface Context extends ServiceGetter {}
declare interface Context {
req: FunctionContextRequest & FastifyRequest
res: FunctionContextResponse
isAuthenticated: boolean
model: SnippetModel
document: SnippetModel & { [key: string]: any }
getMaster: () => Promise<UserModel>
storage: IStorage
name: string
reference: string
writeAsset: (path: string, data: any, options: any) => void
readAsset: (path: string, options: any) => void
secret: Record<string, any>
broadcast: (event: string, data: any) => void
}
declare interface IDb {
get<T = any>(key: string): Promise<T>
set(key: string, value: any): Promise<void>
find<T = any>(condition: Record<string, any>): Promise<T[]>
del(key: string): Promise<void>
insert(key: string, value: any): Promise<void>
update(key: string, value: any): Promise<void>
}
declare interface IStorage {
db: IDb
cache: {
get<T>(key: string): Promise<T>
set(key: string, value: string | object, ttl?: number): Promise<string>
del(key: string): Promise<string>
}
dangerousAccessDbInstance: () => any
}
declare const __dirname: string
declare const __filename: ''
declare class Buffer {
constructor(...args: any[])
from(...args: any[]): Buffer
[x: string]: any
}
declare const logger: Console
declare const process: {
env: Record<string, string>
nextTick: (func: Function) => any
}
declare const context: Context
declare enum SnippetType {
JSON = 'json',
Function = 'function',
Text = 'text',
YAML = 'yaml',
}
declare interface SnippetModel extends BaseModel {
type: SnippetType
private: boolean
raw: string
name: string
reference: string
comment?: string
metatype?: string
}
declare class BaseModel {
created?: Date
id?: string
}
declare class UserModel {
username: string
name: string
introduce?: string
avatar?: string
mail?: string
url?: string
lastLoginTime?: Date
lastLoginIp?: string
socialIds?: any
}
declare function require(id: string, useCache?: boolean): Promise<any>