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