@tinywork/glass 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.ts +472 -541
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,561 +1,492 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* The cookie that was changed.
|
|
19
|
-
*/
|
|
20
|
-
cookie: Cookie,
|
|
21
|
-
/**
|
|
22
|
-
* The cause of the change with one of the following values:
|
|
23
|
-
*/
|
|
24
|
-
cause:
|
|
25
|
-
| "explicit"
|
|
26
|
-
| "overwrite"
|
|
27
|
-
| "expired"
|
|
28
|
-
| "evicted"
|
|
29
|
-
| "expired-overwrite",
|
|
30
|
-
/**
|
|
31
|
-
* `true` if the cookie was removed, `false` otherwise.
|
|
32
|
-
*/
|
|
33
|
-
removed: boolean
|
|
34
|
-
) => void
|
|
35
|
-
): this;
|
|
36
|
-
abstract removeListener(
|
|
37
|
-
event: "changed",
|
|
38
|
-
listener: (
|
|
39
|
-
event: Event,
|
|
40
|
-
/**
|
|
41
|
-
* The cookie that was changed.
|
|
42
|
-
*/
|
|
43
|
-
cookie: Cookie,
|
|
44
|
-
/**
|
|
45
|
-
* The cause of the change with one of the following values:
|
|
46
|
-
*/
|
|
47
|
-
cause:
|
|
48
|
-
| "explicit"
|
|
49
|
-
| "overwrite"
|
|
50
|
-
| "expired"
|
|
51
|
-
| "evicted"
|
|
52
|
-
| "expired-overwrite",
|
|
53
|
-
/**
|
|
54
|
-
* `true` if the cookie was removed, `false` otherwise.
|
|
55
|
-
*/
|
|
56
|
-
removed: boolean
|
|
57
|
-
) => void
|
|
58
|
-
): this;
|
|
59
|
-
}
|
|
60
|
-
export type Session = {
|
|
61
|
-
setProxy: (options: { mode: "direct" }) => Promise<void>;
|
|
62
|
-
cookies: Cookies;
|
|
63
|
-
};
|
|
64
|
-
export abstract class BrowserWindow {
|
|
65
|
-
webContents: {
|
|
66
|
-
session: Session;
|
|
67
|
-
};
|
|
68
|
-
}
|
|
1
|
+
export {};
|
|
2
|
+
|
|
3
|
+
type IGlassExtensionEvent<T> = (params: T) => Promise<T>;
|
|
4
|
+
type IGlassExtensionInvokeResponse<T> = Promise<{
|
|
5
|
+
success: boolean;
|
|
6
|
+
message?: string;
|
|
7
|
+
data?: T;
|
|
8
|
+
}>;
|
|
9
|
+
|
|
10
|
+
declare global {
|
|
11
|
+
namespace Glass {
|
|
12
|
+
type MenuItem = {
|
|
13
|
+
/** 用来click回调时区分 */
|
|
14
|
+
id: string;
|
|
15
|
+
label: string;
|
|
16
|
+
};
|
|
69
17
|
|
|
70
|
-
/** 1-新增,2-修改,3-删除 */
|
|
71
|
-
|
|
18
|
+
/** 1-新增,2-修改,3-删除 */
|
|
19
|
+
type Operation = 1 | 2 | 3;
|
|
72
20
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
declare?: boolean;
|
|
79
|
-
output: { code: string; filename?: string };
|
|
80
|
-
}
|
|
81
|
-
| {
|
|
82
|
-
type: "remove";
|
|
83
|
-
data: DocSchema;
|
|
84
|
-
}
|
|
85
|
-
| {
|
|
86
|
-
type: "bind" | "unbind";
|
|
87
|
-
data: DocSchema;
|
|
88
|
-
}
|
|
89
|
-
| {
|
|
90
|
-
type: "check";
|
|
21
|
+
type Cookie = {
|
|
22
|
+
name: string;
|
|
23
|
+
origin?: string;
|
|
24
|
+
path?: string;
|
|
25
|
+
value?: string;
|
|
91
26
|
};
|
|
92
27
|
|
|
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
|
-
export type DocFullSchema = DocSchema & {
|
|
143
|
-
external: {
|
|
144
|
-
group: string;
|
|
145
|
-
orgId?: string;
|
|
146
|
-
teamId?: string;
|
|
147
|
-
};
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
export type GroupSchema = {
|
|
151
|
-
id: string;
|
|
152
|
-
orgId?: string | null;
|
|
153
|
-
teamId?: string | null;
|
|
154
|
-
parentId: string | null;
|
|
155
|
-
name: string;
|
|
156
|
-
desc?: string;
|
|
157
|
-
origin?: string;
|
|
158
|
-
prefix?: string;
|
|
159
|
-
code?: string;
|
|
160
|
-
status: boolean;
|
|
161
|
-
hash?: string;
|
|
162
|
-
/** 无hash时,用updatedAt */
|
|
163
|
-
updatedAt?: string;
|
|
164
|
-
/** 是否支持app编辑 */
|
|
165
|
-
readonly?: boolean;
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
export type Project = {
|
|
169
|
-
id: string;
|
|
170
|
-
orgId?: string | null;
|
|
171
|
-
teamId?: string | null;
|
|
172
|
-
name: string;
|
|
173
|
-
desc?: string;
|
|
174
|
-
status: boolean;
|
|
175
|
-
actived?: boolean;
|
|
176
|
-
hash?: string;
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
export type Version = {
|
|
180
|
-
id: string;
|
|
181
|
-
projectId: string;
|
|
182
|
-
name: string;
|
|
183
|
-
desc?: string;
|
|
184
|
-
status: boolean;
|
|
185
|
-
actived?: boolean;
|
|
186
|
-
hash?: string;
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
export type Plan = {
|
|
190
|
-
id: string;
|
|
191
|
-
versionId: string;
|
|
192
|
-
name: string;
|
|
193
|
-
desc?: string;
|
|
194
|
-
origin: string;
|
|
195
|
-
prefix: string;
|
|
196
|
-
params?: string;
|
|
197
|
-
headers?: string;
|
|
198
|
-
body?: string;
|
|
199
|
-
/** 校验结果的ts类型声明 */
|
|
200
|
-
assert?: string;
|
|
201
|
-
hash?: string;
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
export type Case = {
|
|
205
|
-
id: string;
|
|
206
|
-
versionId: string;
|
|
207
|
-
planId?: string;
|
|
208
|
-
name: string;
|
|
209
|
-
desc?: string;
|
|
210
|
-
origin: string;
|
|
211
|
-
pathname: string;
|
|
212
|
-
method: "GET" | "POST" | "PUT" | "DELETE";
|
|
213
|
-
params?: Record<string, any>;
|
|
214
|
-
headers?: Record<string, any>;
|
|
215
|
-
body?: any;
|
|
216
|
-
apiId?: string;
|
|
217
|
-
/** 校验结果的ts类型声明 */
|
|
218
|
-
assert?: string;
|
|
219
|
-
hash?: string;
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
export type CaseData = Omit<Case, "params" | "headers" | "body"> & {
|
|
223
|
-
params?: string;
|
|
224
|
-
headers?: string;
|
|
225
|
-
body?: string;
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
export type Association = {
|
|
229
|
-
versionId: string;
|
|
230
|
-
apiId: string;
|
|
231
|
-
tags?: string[];
|
|
232
|
-
hash?: string;
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
export type MockMode = "None" | "Local" | "Advance";
|
|
236
|
-
export type ActionMode = "Modify" | "Add" | "Remove";
|
|
237
|
-
export type ActionTarget = "Origin";
|
|
238
|
-
export type ContextMenuType =
|
|
239
|
-
| "log"
|
|
240
|
-
| "group"
|
|
241
|
-
| "doc"
|
|
242
|
-
| "rule"
|
|
243
|
-
| "project"
|
|
244
|
-
| "version"
|
|
245
|
-
| "plan"
|
|
246
|
-
| "case"
|
|
247
|
-
| "association";
|
|
248
|
-
|
|
249
|
-
export type ContextMenuParams =
|
|
250
|
-
| { type: "log"; data: NetLog }
|
|
251
|
-
| { type: "group"; data: GroupSchema }
|
|
252
|
-
| { type: "doc"; data: DocSchema }
|
|
253
|
-
| { type: "rule"; data: RuleSchema }
|
|
254
|
-
| { type: "project"; data: Project }
|
|
255
|
-
| { type: "version"; data: Version }
|
|
256
|
-
| { type: "plan"; data: Plan }
|
|
257
|
-
| { type: "case"; data: Case }
|
|
258
|
-
| { type: "association"; data: Association };
|
|
259
|
-
|
|
260
|
-
export type SyncDataType =
|
|
261
|
-
| "group"
|
|
262
|
-
| "doc"
|
|
263
|
-
| "rule"
|
|
264
|
-
| "project"
|
|
265
|
-
| "version"
|
|
266
|
-
| "plan"
|
|
267
|
-
| "case";
|
|
268
|
-
|
|
269
|
-
export type SyncDataParams =
|
|
270
|
-
| { type: "group"; data: GroupSchema }
|
|
271
|
-
| { type: "doc"; data: DocSchema }
|
|
272
|
-
| { type: "rule"; data: RuleSchema }
|
|
273
|
-
| { type: "project"; data: Project }
|
|
274
|
-
| { type: "version"; data: Version }
|
|
275
|
-
| { type: "plan"; data: Plan }
|
|
276
|
-
| { type: "case"; data: CaseData };
|
|
277
|
-
|
|
278
|
-
export type MockModelSchema = {
|
|
279
|
-
id: string;
|
|
280
|
-
ruleId?: string;
|
|
281
|
-
contentType?: string;
|
|
282
|
-
example?: string;
|
|
283
|
-
name?: string;
|
|
284
|
-
statusCode?: number;
|
|
285
|
-
status?: boolean;
|
|
286
|
-
updatedAt?: string;
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
export type RewriteActionSchema = {
|
|
290
|
-
id: string;
|
|
291
|
-
ruleId?: string;
|
|
292
|
-
name?: string;
|
|
293
|
-
action?: ActionMode;
|
|
294
|
-
target?: ActionTarget;
|
|
295
|
-
oldValue?: string;
|
|
296
|
-
newValue?: string;
|
|
297
|
-
status?: boolean;
|
|
298
|
-
updatedAt?: string;
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
export type FilterSchema = {
|
|
302
|
-
origin?: string;
|
|
303
|
-
pathname?: string;
|
|
304
|
-
params?: { key: string; value?: string }[];
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
export type RuleSchema = FilterSchema & {
|
|
308
|
-
id: string;
|
|
309
|
-
orgId?: string | null;
|
|
310
|
-
teamId?: string | null;
|
|
311
|
-
mode?: MockMode; // 是否走mock
|
|
312
|
-
name?: string;
|
|
313
|
-
apiId?: string;
|
|
314
|
-
throttle?: number;
|
|
315
|
-
/** 本地匹配规则是排序用 */
|
|
316
|
-
sort?: number;
|
|
317
|
-
tags?: string[];
|
|
318
|
-
localOptions?: MockModelSchema[];
|
|
319
|
-
actions?: RewriteActionSchema[];
|
|
320
|
-
hash?: string;
|
|
321
|
-
updatedAt?: string;
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
export type NetLog = {
|
|
325
|
-
uid: string;
|
|
326
|
-
url: string;
|
|
327
|
-
realUrl: string;
|
|
328
|
-
method: string;
|
|
329
|
-
requestHeaders: string[][];
|
|
330
|
-
query?: string;
|
|
331
|
-
body?: any;
|
|
332
|
-
statusCode?: number;
|
|
333
|
-
responseHeaders?: string[][];
|
|
334
|
-
resourceType?: ResourceType;
|
|
335
|
-
response?: any;
|
|
336
|
-
rule?: RuleSchema;
|
|
337
|
-
};
|
|
338
|
-
export interface IProgress {
|
|
339
|
-
update: (option: { percent: number; text?: string }) => Promise<void>;
|
|
340
|
-
destroy: () => Promise<void>;
|
|
341
|
-
}
|
|
342
|
-
export interface IGlassContext {
|
|
343
|
-
getItem: <T>(key: string) => Promise<T>;
|
|
344
|
-
setItem: <T>(key: string, value: T) => Promise<void>;
|
|
345
|
-
|
|
346
|
-
saveGroup: (
|
|
347
|
-
group: GroupSchema
|
|
348
|
-
) => Promise<{ success: boolean; message?: string }>;
|
|
349
|
-
saveGroups: (
|
|
350
|
-
groups: GroupSchema[]
|
|
351
|
-
) => Promise<{ success: boolean; message?: string }>;
|
|
352
|
-
saveDoc: (
|
|
353
|
-
doc: DocSchema,
|
|
354
|
-
options?: {
|
|
355
|
-
/** 是否触发缓存更新 */
|
|
356
|
-
hooks?: boolean;
|
|
357
|
-
/** 是否根据文档自动生成rule规则 */
|
|
358
|
-
defaultRule?: Partial<{
|
|
359
|
-
name: string;
|
|
360
|
-
origin: string;
|
|
361
|
-
pathname: string;
|
|
362
|
-
params: { key: string; value?: string }[];
|
|
363
|
-
}>;
|
|
364
|
-
}
|
|
365
|
-
) => Promise<{
|
|
366
|
-
success: boolean;
|
|
367
|
-
message?: string;
|
|
368
|
-
data?: {
|
|
28
|
+
type GlassAction = "file" | "remove" | "bind" | "unbind" | "check";
|
|
29
|
+
type GlassActionParams =
|
|
30
|
+
| {
|
|
31
|
+
type: "file";
|
|
32
|
+
data: DocSchema;
|
|
33
|
+
declare?: boolean;
|
|
34
|
+
output: { code: string; filename?: string };
|
|
35
|
+
}
|
|
36
|
+
| {
|
|
37
|
+
type: "remove";
|
|
38
|
+
data: DocSchema;
|
|
39
|
+
}
|
|
40
|
+
| {
|
|
41
|
+
type: "bind" | "unbind";
|
|
42
|
+
data: DocSchema;
|
|
43
|
+
}
|
|
44
|
+
| {
|
|
45
|
+
type: "check";
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
type ResourceType =
|
|
49
|
+
| "Fetch/XHR"
|
|
50
|
+
| "JS"
|
|
51
|
+
| "CSS"
|
|
52
|
+
| "Img"
|
|
53
|
+
| "Media"
|
|
54
|
+
| "Font"
|
|
55
|
+
| "Doc"
|
|
56
|
+
| "WS"
|
|
57
|
+
| "Wasm"
|
|
58
|
+
| "Other";
|
|
59
|
+
|
|
60
|
+
type JSONPropertySchema = {
|
|
61
|
+
type: string;
|
|
62
|
+
description?: string;
|
|
63
|
+
items?: JSONPropertySchema;
|
|
64
|
+
properties?: {
|
|
65
|
+
[key: string]: JSONPropertySchema;
|
|
66
|
+
};
|
|
67
|
+
required?: string[];
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
type JSONSchema = JSONPropertySchema & {
|
|
71
|
+
$schema?: string;
|
|
72
|
+
$id?: string;
|
|
73
|
+
title?: string;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
type DocSchema = {
|
|
369
77
|
apiId: string;
|
|
370
|
-
|
|
78
|
+
groupId: string;
|
|
79
|
+
name: string;
|
|
80
|
+
desc?: string;
|
|
81
|
+
pathname?: string;
|
|
82
|
+
method?: "GET" | "POST" | "PUT" | "DELETE";
|
|
83
|
+
code?: string; // ts声明
|
|
84
|
+
modifier?: string; // 最后操作人
|
|
85
|
+
modifyTime?: string; // 最后操作时间
|
|
86
|
+
tags?: string[] | null;
|
|
87
|
+
status: boolean;
|
|
88
|
+
hash?: string;
|
|
89
|
+
/** 无hash时,用updatedAt */
|
|
90
|
+
updatedAt?: string;
|
|
91
|
+
/** 是否支持app编辑 */
|
|
92
|
+
readonly?: boolean;
|
|
93
|
+
|
|
94
|
+
prefix?: string;
|
|
371
95
|
};
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
params?: { key: string; value?: string }[] | null;
|
|
383
|
-
}[];
|
|
384
|
-
}
|
|
385
|
-
) => Promise<{ success: boolean; message?: string }>;
|
|
386
|
-
/** 批量更新rule的本地数据 */
|
|
387
|
-
saveExamples: (
|
|
388
|
-
ruleId: string,
|
|
389
|
-
examples: {
|
|
96
|
+
|
|
97
|
+
type DocFullSchema = DocSchema & {
|
|
98
|
+
external: {
|
|
99
|
+
group: string;
|
|
100
|
+
orgId?: string;
|
|
101
|
+
teamId?: string;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
type GroupSchema = {
|
|
390
106
|
id: string;
|
|
107
|
+
orgId?: string | null;
|
|
108
|
+
teamId?: string | null;
|
|
109
|
+
parentId: string | null;
|
|
110
|
+
name: string;
|
|
111
|
+
desc?: string;
|
|
112
|
+
origin?: string;
|
|
113
|
+
prefix?: string;
|
|
114
|
+
code?: string;
|
|
115
|
+
status: boolean;
|
|
116
|
+
hash?: string;
|
|
117
|
+
/** 无hash时,用updatedAt */
|
|
118
|
+
updatedAt?: string;
|
|
119
|
+
/** 是否支持app编辑 */
|
|
120
|
+
readonly?: boolean;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
type Project = {
|
|
124
|
+
id: string;
|
|
125
|
+
orgId?: string | null;
|
|
126
|
+
teamId?: string | null;
|
|
127
|
+
name: string;
|
|
128
|
+
desc?: string;
|
|
129
|
+
status: boolean;
|
|
130
|
+
actived?: boolean;
|
|
131
|
+
hash?: string;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
type Version = {
|
|
135
|
+
id: string;
|
|
136
|
+
projectId: string;
|
|
137
|
+
name: string;
|
|
138
|
+
desc?: string;
|
|
139
|
+
status: boolean;
|
|
140
|
+
actived?: boolean;
|
|
141
|
+
hash?: string;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
type Plan = {
|
|
145
|
+
id: string;
|
|
146
|
+
versionId: string;
|
|
147
|
+
name: string;
|
|
148
|
+
desc?: string;
|
|
149
|
+
origin: string;
|
|
150
|
+
prefix: string;
|
|
151
|
+
params?: string;
|
|
152
|
+
headers?: string;
|
|
153
|
+
body?: string;
|
|
154
|
+
/** 校验结果的ts类型声明 */
|
|
155
|
+
assert?: string;
|
|
156
|
+
hash?: string;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
type Case = {
|
|
160
|
+
id: string;
|
|
161
|
+
versionId: string;
|
|
162
|
+
planId?: string;
|
|
163
|
+
name: string;
|
|
164
|
+
desc?: string;
|
|
165
|
+
origin: string;
|
|
166
|
+
pathname: string;
|
|
167
|
+
method: "GET" | "POST" | "PUT" | "DELETE";
|
|
168
|
+
params?: Record<string, any>;
|
|
169
|
+
headers?: Record<string, any>;
|
|
170
|
+
body?: any;
|
|
171
|
+
apiId?: string;
|
|
172
|
+
/** 校验结果的ts类型声明 */
|
|
173
|
+
assert?: string;
|
|
174
|
+
hash?: string;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
type CaseData = Omit<Case, "params" | "headers" | "body"> & {
|
|
178
|
+
params?: string;
|
|
179
|
+
headers?: string;
|
|
180
|
+
body?: string;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
type Association = {
|
|
184
|
+
versionId: string;
|
|
185
|
+
apiId: string;
|
|
186
|
+
tags?: string[];
|
|
187
|
+
hash?: string;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
type MockMode = "None" | "Local" | "Advance";
|
|
191
|
+
type ActionMode = "Modify" | "Add" | "Remove";
|
|
192
|
+
type ActionTarget = "Origin";
|
|
193
|
+
type ContextMenuType =
|
|
194
|
+
| "log"
|
|
195
|
+
| "group"
|
|
196
|
+
| "doc"
|
|
197
|
+
| "rule"
|
|
198
|
+
| "project"
|
|
199
|
+
| "version"
|
|
200
|
+
| "plan"
|
|
201
|
+
| "case"
|
|
202
|
+
| "association";
|
|
203
|
+
|
|
204
|
+
type ContextMenuParams =
|
|
205
|
+
| { type: "log"; data: NetLog }
|
|
206
|
+
| { type: "group"; data: GroupSchema }
|
|
207
|
+
| { type: "doc"; data: DocSchema }
|
|
208
|
+
| { type: "rule"; data: RuleSchema }
|
|
209
|
+
| { type: "project"; data: Project }
|
|
210
|
+
| { type: "version"; data: Version }
|
|
211
|
+
| { type: "plan"; data: Plan }
|
|
212
|
+
| { type: "case"; data: Case }
|
|
213
|
+
| { type: "association"; data: Association };
|
|
214
|
+
|
|
215
|
+
type SyncDataType =
|
|
216
|
+
| "group"
|
|
217
|
+
| "doc"
|
|
218
|
+
| "rule"
|
|
219
|
+
| "project"
|
|
220
|
+
| "version"
|
|
221
|
+
| "plan"
|
|
222
|
+
| "case";
|
|
223
|
+
|
|
224
|
+
type SyncDataParams = (
|
|
225
|
+
| { type: "group"; data: GroupSchema }
|
|
226
|
+
| { type: "doc"; data: DocSchema }
|
|
227
|
+
| { type: "rule"; data: RuleSchema }
|
|
228
|
+
| { type: "project"; data: Project }
|
|
229
|
+
| { type: "version"; data: Version }
|
|
230
|
+
| { type: "plan"; data: Plan }
|
|
231
|
+
| { type: "case"; data: CaseData }
|
|
232
|
+
) & { operation: Operation; orgId?: string | null };
|
|
233
|
+
|
|
234
|
+
type MockModelSchema = {
|
|
235
|
+
id: string;
|
|
236
|
+
ruleId?: string;
|
|
391
237
|
contentType?: string;
|
|
392
238
|
example?: string;
|
|
393
239
|
name?: string;
|
|
394
240
|
statusCode?: number;
|
|
395
241
|
status?: boolean;
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
registerMenu: (id: string, options: MenuItemConstructorOptions) => void;
|
|
400
|
-
unregisterMenu: (id: string) => void;
|
|
401
|
-
|
|
402
|
-
getSession: (id: string, isPersist?: boolean) => Session;
|
|
403
|
-
showInputBox: (option: {
|
|
404
|
-
title?: string;
|
|
405
|
-
placeholder?: string;
|
|
406
|
-
value?: string;
|
|
407
|
-
}) => Promise<string>;
|
|
408
|
-
showMessage: (options: {
|
|
409
|
-
message: string;
|
|
410
|
-
title?: string;
|
|
411
|
-
type?: "success" | "info" | "error";
|
|
412
|
-
}) => Promise<void>;
|
|
413
|
-
showProgress: () => IProgress;
|
|
414
|
-
|
|
415
|
-
transformDocToJsonSchema: (doc: DocFullSchema) => JSONSchema;
|
|
416
|
-
genDataFromDocSchema: (doc: DocFullSchema) => Record<string, any>;
|
|
417
|
-
|
|
418
|
-
postMessage: (message: Partial<NetLog>) => Promise<void>;
|
|
419
|
-
}
|
|
242
|
+
updatedAt?: string;
|
|
243
|
+
};
|
|
420
244
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
245
|
+
type RewriteActionSchema = {
|
|
246
|
+
id: string;
|
|
247
|
+
ruleId?: string;
|
|
248
|
+
name?: string;
|
|
249
|
+
action?: ActionMode;
|
|
250
|
+
target?: ActionTarget;
|
|
251
|
+
oldValue?: string;
|
|
252
|
+
newValue?: string;
|
|
253
|
+
status?: boolean;
|
|
254
|
+
updatedAt?: string;
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
type FilterSchema = {
|
|
258
|
+
origin?: string;
|
|
259
|
+
pathname?: string;
|
|
260
|
+
params?: { key: string; value?: string }[];
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
type RuleSchema = FilterSchema & {
|
|
264
|
+
id: string;
|
|
265
|
+
orgId?: string | null;
|
|
266
|
+
teamId?: string | null;
|
|
267
|
+
mode?: MockMode; // 是否走mock
|
|
268
|
+
name?: string;
|
|
269
|
+
apiId?: string;
|
|
270
|
+
throttle?: number;
|
|
271
|
+
/** 本地匹配规则是排序用 */
|
|
272
|
+
sort?: number;
|
|
273
|
+
tags?: string[];
|
|
274
|
+
localOptions?: MockModelSchema[];
|
|
275
|
+
actions?: RewriteActionSchema[];
|
|
276
|
+
hash?: string;
|
|
277
|
+
updatedAt?: string;
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
type NetLog = {
|
|
281
|
+
uid: string;
|
|
441
282
|
url: string;
|
|
283
|
+
realUrl: string;
|
|
442
284
|
method: string;
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
285
|
+
requestHeaders: string[][];
|
|
286
|
+
query?: string;
|
|
287
|
+
body?: any;
|
|
288
|
+
statusCode?: number;
|
|
289
|
+
responseHeaders?: string[][];
|
|
290
|
+
resourceType?: ResourceType;
|
|
291
|
+
response?: any;
|
|
292
|
+
rule?: RuleSchema;
|
|
293
|
+
};
|
|
294
|
+
interface IProgress {
|
|
295
|
+
update: (option: { percent: number; text?: string }) => Promise<void>;
|
|
296
|
+
destroy: () => Promise<void>;
|
|
446
297
|
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
url: URL
|
|
486
|
-
|
|
487
|
-
|
|
298
|
+
|
|
299
|
+
interface IGlassExtension {
|
|
300
|
+
install?: IGlassExtensionEvent<void>;
|
|
301
|
+
activate?: IGlassExtensionEvent<void>;
|
|
302
|
+
/** 通过设置页面修改数据 */
|
|
303
|
+
onItemChange?: IGlassExtensionEvent<void>;
|
|
304
|
+
/** 要修改url时,直接在params.url = new URL方式修改 */
|
|
305
|
+
onRequest?: IGlassExtensionEvent<{
|
|
306
|
+
/** url为null时表示break了请求 */
|
|
307
|
+
url: URL | null;
|
|
308
|
+
isLocal?: boolean;
|
|
309
|
+
}>;
|
|
310
|
+
/** 在执行请求用例时触发,用于修改config */
|
|
311
|
+
onRequestExec?: IGlassExtensionEvent<{
|
|
312
|
+
url: string;
|
|
313
|
+
method: string;
|
|
314
|
+
headers?: Record<string, any>;
|
|
315
|
+
params?: Record<string, any>;
|
|
316
|
+
data?: any;
|
|
317
|
+
}>;
|
|
318
|
+
|
|
319
|
+
/** 在用例批量执行前触发 */
|
|
320
|
+
beforeCasesExec?: IGlassExtensionEvent<{ list: Case[] }>;
|
|
321
|
+
/** 在单条用例执行时触发 */
|
|
322
|
+
onCaseExec?: IGlassExtensionEvent<Case>;
|
|
323
|
+
/** 在用例批量执行后触发 */
|
|
324
|
+
afterCasesExec?: IGlassExtensionEvent<{
|
|
325
|
+
list: Case[];
|
|
326
|
+
failCases: { id: string; message?: string }[];
|
|
327
|
+
}>;
|
|
328
|
+
|
|
329
|
+
/** 远程服务同步数据至本机 */
|
|
330
|
+
onSyncDownload?: IGlassExtensionEvent<SyncDataParams>;
|
|
331
|
+
/** 本机变更同步数据至远程服务 */
|
|
332
|
+
onSyncUpload?: IGlassExtensionEvent<SyncDataParams>;
|
|
333
|
+
|
|
334
|
+
/** 在postMessage到页面之前 */
|
|
335
|
+
onMessagePost?: IGlassExtensionEvent<{ log: Partial<NetLog> }>;
|
|
336
|
+
onResponse?: IGlassExtensionEvent<{ url: URL }>;
|
|
337
|
+
deactivate?: IGlassExtensionEvent<void>;
|
|
338
|
+
uninstall?: IGlassExtensionEvent<void>;
|
|
339
|
+
|
|
340
|
+
onDocChange?: IGlassExtensionEvent<{
|
|
341
|
+
doc: DocFullSchema | null;
|
|
342
|
+
originDoc: DocFullSchema | null;
|
|
343
|
+
orgId?: string | null;
|
|
344
|
+
}>;
|
|
345
|
+
onGroupChange?: IGlassExtensionEvent<{
|
|
346
|
+
group: GroupSchema | null;
|
|
347
|
+
originGroup: GroupSchema | null;
|
|
348
|
+
orgId?: string | null;
|
|
349
|
+
}>;
|
|
350
|
+
/** glass cli拉取接口文档 */
|
|
351
|
+
onDocCliUpdate?: IGlassExtensionEvent<{
|
|
352
|
+
id: string;
|
|
353
|
+
orgId?: string | null;
|
|
354
|
+
}>;
|
|
355
|
+
/** glass cli执行 */
|
|
356
|
+
onGlassAction?: IGlassExtensionEvent<{
|
|
357
|
+
params: GlassActionParams;
|
|
358
|
+
orgId?: string | null;
|
|
359
|
+
}>;
|
|
360
|
+
/** 右键请求日志 */
|
|
361
|
+
onContextMenu?: IGlassExtensionEvent<{
|
|
362
|
+
params: ContextMenuParams;
|
|
363
|
+
}>;
|
|
364
|
+
|
|
365
|
+
onRuleDefault?: IGlassExtensionEvent<{
|
|
366
|
+
docs: DocSchema[];
|
|
367
|
+
log: NetLog;
|
|
368
|
+
rule?: RuleSchema;
|
|
369
|
+
}>;
|
|
370
|
+
/** 根据doc或者log来初始化case */
|
|
371
|
+
onCaseDefault?: IGlassExtensionEvent<{
|
|
372
|
+
docs: DocSchema[];
|
|
373
|
+
log?: NetLog;
|
|
374
|
+
caseData?: CaseData;
|
|
375
|
+
}>;
|
|
488
376
|
}
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
originDoc: DocFullSchema | null,
|
|
497
|
-
orgId?: string | null
|
|
498
|
-
): Promise<boolean>;
|
|
499
|
-
onGroupChange?(
|
|
500
|
-
context: IGlassContext,
|
|
501
|
-
group: GroupSchema | null,
|
|
502
|
-
originGroup: GroupSchema | null,
|
|
503
|
-
orgId?: string | null
|
|
504
|
-
): Promise<boolean>;
|
|
505
|
-
/** glass cli拉取接口文档 */
|
|
506
|
-
onDocCliUpdate?(
|
|
507
|
-
context: IGlassContext,
|
|
508
|
-
id: string,
|
|
509
|
-
orgId?: string | null
|
|
510
|
-
): Promise<void>;
|
|
511
|
-
/** glass cli执行 */
|
|
512
|
-
onGlassAction?(
|
|
513
|
-
context: IGlassContext,
|
|
514
|
-
params: GlassActionParams,
|
|
515
|
-
orgId?: string | null
|
|
516
|
-
): Promise<void>;
|
|
517
|
-
/** 右键请求日志 */
|
|
518
|
-
onContextMenu?(
|
|
519
|
-
context: IGlassContext,
|
|
520
|
-
params: ContextMenuParams,
|
|
521
|
-
menus?: MenuItemConstructorOptions[]
|
|
522
|
-
): Promise<void>;
|
|
523
|
-
|
|
524
|
-
getDefaultRule?(
|
|
525
|
-
context: IGlassContext,
|
|
526
|
-
docs: DocSchema[],
|
|
527
|
-
log: NetLog,
|
|
528
|
-
rule?: {
|
|
529
|
-
id: string;
|
|
530
|
-
mode: "None";
|
|
531
|
-
} & Partial<{
|
|
377
|
+
|
|
378
|
+
type writeText = (text: string) => Promise<void>;
|
|
379
|
+
type openExternal = (url: string) => Promise<void>;
|
|
380
|
+
type getItem = <T>(key: string) => Promise<T>;
|
|
381
|
+
type setItem = <T>(key: string, value: T) => Promise<void>;
|
|
382
|
+
/** 保存cookie */
|
|
383
|
+
type setCookie = (params: {
|
|
532
384
|
name: string;
|
|
533
|
-
origin
|
|
534
|
-
|
|
535
|
-
|
|
385
|
+
origin?: string;
|
|
386
|
+
path?: string;
|
|
387
|
+
value: string;
|
|
388
|
+
}) => IGlassExtensionInvokeResponse<void>;
|
|
389
|
+
/** 获取cookie */
|
|
390
|
+
type getCookie = (params: {
|
|
391
|
+
name: string;
|
|
392
|
+
origin?: string;
|
|
393
|
+
path?: string;
|
|
394
|
+
}) => IGlassExtensionInvokeResponse<string>;
|
|
395
|
+
/** 保存文档组 */
|
|
396
|
+
type saveGroup = (
|
|
397
|
+
group: GroupSchema
|
|
398
|
+
) => IGlassExtensionInvokeResponse<void>;
|
|
399
|
+
/** 批量保存文档组 */
|
|
400
|
+
type saveGroups = (
|
|
401
|
+
groups: GroupSchema[]
|
|
402
|
+
) => IGlassExtensionInvokeResponse<void>;
|
|
403
|
+
/** 保存文档 */
|
|
404
|
+
type saveDoc = (
|
|
405
|
+
doc: DocSchema,
|
|
406
|
+
options?: {
|
|
407
|
+
/** 是否触发缓存更新 */
|
|
408
|
+
hooks?: boolean;
|
|
409
|
+
/** 是否根据文档自动生成rule规则 */
|
|
410
|
+
defaultRule?: Partial<{
|
|
411
|
+
name: string;
|
|
412
|
+
origin: string;
|
|
413
|
+
pathname: string;
|
|
414
|
+
params: { key: string; value?: string }[];
|
|
415
|
+
}>;
|
|
416
|
+
}
|
|
417
|
+
) => IGlassExtensionInvokeResponse<{
|
|
536
418
|
apiId: string;
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
419
|
+
ruleId?: string;
|
|
420
|
+
}>;
|
|
421
|
+
/** 批量保存文档 */
|
|
422
|
+
type saveDocs = (
|
|
423
|
+
docs: DocSchema[],
|
|
424
|
+
options?: {
|
|
425
|
+
/** 是否根据文档自动生成rule规则 */
|
|
426
|
+
defaultRules?: {
|
|
427
|
+
name: string;
|
|
428
|
+
origin: string;
|
|
429
|
+
pathname: string;
|
|
430
|
+
apiId: string;
|
|
431
|
+
params?: { key: string; value?: string }[] | null;
|
|
432
|
+
}[];
|
|
433
|
+
}
|
|
434
|
+
) => IGlassExtensionInvokeResponse<void>;
|
|
435
|
+
/** 批量更新rule的本地数据 */
|
|
436
|
+
type saveExamples = (
|
|
437
|
+
ruleId: string,
|
|
438
|
+
examples: {
|
|
439
|
+
id: string;
|
|
440
|
+
contentType?: string;
|
|
441
|
+
example?: string;
|
|
442
|
+
name?: string;
|
|
443
|
+
statusCode?: number;
|
|
444
|
+
status?: boolean;
|
|
445
|
+
}[]
|
|
446
|
+
) => IGlassExtensionInvokeResponse<void>;
|
|
447
|
+
/** 注册菜单项 */
|
|
448
|
+
type registerMenu = (
|
|
449
|
+
id: string,
|
|
450
|
+
options: MenuItem
|
|
451
|
+
) => IGlassExtensionInvokeResponse<void>;
|
|
452
|
+
/** 移除菜单 */
|
|
453
|
+
type unregisterMenu = (id: string) => IGlassExtensionInvokeResponse<void>;
|
|
454
|
+
|
|
455
|
+
type showInputBox = (option: {
|
|
456
|
+
title?: string;
|
|
457
|
+
placeholder?: string;
|
|
458
|
+
value?: string;
|
|
459
|
+
}) => IGlassExtensionInvokeResponse<string>;
|
|
460
|
+
type showMessage = (options: {
|
|
461
|
+
message: string;
|
|
462
|
+
title?: string;
|
|
463
|
+
type?: "success" | "info" | "error";
|
|
464
|
+
}) => IGlassExtensionInvokeResponse<void>;
|
|
465
|
+
type showProgress = () => IProgress;
|
|
466
|
+
|
|
467
|
+
type transformDocToJsonSchema = (
|
|
468
|
+
doc: DocFullSchema
|
|
469
|
+
) => IGlassExtensionInvokeResponse<JSONSchema>;
|
|
470
|
+
type genDataFromDocSchema = (
|
|
471
|
+
doc: DocFullSchema
|
|
472
|
+
) => IGlassExtensionInvokeResponse<Record<string, any>>;
|
|
473
|
+
|
|
474
|
+
type postMessage = (
|
|
475
|
+
message: Partial<NetLog>
|
|
476
|
+
) => IGlassExtensionInvokeResponse<void>;
|
|
477
|
+
type openBrowserWindow = (browserWindowOptions: {
|
|
478
|
+
width?: number;
|
|
479
|
+
height?: number;
|
|
480
|
+
minHeight?: number;
|
|
481
|
+
minWidth?: number;
|
|
482
|
+
show?: boolean;
|
|
483
|
+
alwaysOnTop?: boolean;
|
|
484
|
+
url: string;
|
|
485
|
+
until?: {
|
|
486
|
+
mode: "cookie";
|
|
487
|
+
type: "added" | "removed";
|
|
488
|
+
info: Glass.Cookie;
|
|
489
|
+
};
|
|
490
|
+
}) => IGlassExtensionInvokeResponse<Glass.Cookie>;
|
|
491
|
+
}
|
|
546
492
|
}
|
|
547
|
-
|
|
548
|
-
export type writeText = (text: string) => void;
|
|
549
|
-
export type openExternal = (url: string) => void;
|
|
550
|
-
export type openBrowserWindow = (browserWindowOptions: {
|
|
551
|
-
width?: number;
|
|
552
|
-
height?: number;
|
|
553
|
-
minHeight?: number;
|
|
554
|
-
minWidth?: number;
|
|
555
|
-
show?: boolean;
|
|
556
|
-
alwaysOnTop?: boolean;
|
|
557
|
-
url: string;
|
|
558
|
-
webPreferences?: {
|
|
559
|
-
session?: Session;
|
|
560
|
-
};
|
|
561
|
-
}) => Promise<BrowserWindow>;
|