@lcap/nasl 0.3.9 → 0.3.10-beta

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 (154) hide show
  1. package/out/service/create/errHandles.js +7 -2
  2. package/out/service/create/errHandles.js.map +1 -1
  3. package/out/service/debugger/debugger.d.ts +3 -0
  4. package/out/service/debugger/debugger.js +95 -0
  5. package/out/service/debugger/debugger.js.map +1 -0
  6. package/out/service/logic/logic.d.ts +27 -0
  7. package/out/service/logic/logic.js +20 -0
  8. package/out/service/logic/logic.js.map +1 -1
  9. package/out/service/page/element.d.ts +9 -0
  10. package/out/service/page/element.js +6 -0
  11. package/out/service/page/element.js.map +1 -1
  12. package/out/service/permission/api.d.ts +57 -0
  13. package/out/service/permission/api.js +41 -0
  14. package/out/service/permission/api.js.map +1 -0
  15. package/out/service/permission/index.d.ts +2 -0
  16. package/out/service/permission/index.js +17 -0
  17. package/out/service/permission/index.js.map +1 -0
  18. package/out/service/webFile/index.js +5 -0
  19. package/out/service/webFile/index.js.map +1 -1
  20. package/out/types/app/App.d.ts +4 -1
  21. package/out/types/app/App.js +24 -0
  22. package/out/types/app/App.js.map +1 -1
  23. package/out/types/app/Service.d.ts +2 -2
  24. package/out/types/app/Service.js +28 -3
  25. package/out/types/app/Service.js.map +1 -1
  26. package/out/types/cache.d.ts +6 -0
  27. package/out/types/cache.js +54 -0
  28. package/out/types/cache.js.map +1 -0
  29. package/out/types/common/Vertex.d.ts +25 -0
  30. package/out/types/common/Vertex.js +40 -0
  31. package/out/types/common/Vertex.js.map +1 -1
  32. package/out/types/data/Entity.js +1 -0
  33. package/out/types/data/Entity.js.map +1 -1
  34. package/out/types/data/Enum.d.ts +5 -0
  35. package/out/types/data/Enum.js +5 -0
  36. package/out/types/data/Enum.js.map +1 -1
  37. package/out/types/data/Interface.js +5 -3
  38. package/out/types/data/Interface.js.map +1 -1
  39. package/out/types/data/genBlock/genCreateBlock.js +5 -5
  40. package/out/types/data/genBlock/genCreateBlock.js.map +1 -1
  41. package/out/types/data/genBlock/genCurdBlock.js +3 -3
  42. package/out/types/data/genBlock/genCurdBlock.js.map +1 -1
  43. package/out/types/data/genBlock/genEnumSelectBlock.d.ts +1 -1
  44. package/out/types/data/genBlock/genEnumSelectBlock.js +2 -2
  45. package/out/types/data/genBlock/genEnumSelectBlock.js.map +1 -1
  46. package/out/types/data/genBlock/genGridViewBlock.js +12 -1
  47. package/out/types/data/genBlock/genGridViewBlock.js.map +1 -1
  48. package/out/types/data/genBlock/genListViewBlock.js +2 -2
  49. package/out/types/data/genBlock/genSelectBlock.js +2 -2
  50. package/out/types/data/genBlock/genTableBlock.js +14 -3
  51. package/out/types/data/genBlock/genTableBlock.js.map +1 -1
  52. package/out/types/data/genBlock/genUpdateBlock.js +5 -5
  53. package/out/types/data/genBlock/genUpdateBlock.js.map +1 -1
  54. package/out/types/data/systemTypes.js +47 -0
  55. package/out/types/data/systemTypes.js.map +1 -1
  56. package/out/types/enum.d.ts +6 -0
  57. package/out/types/enum.js +11 -0
  58. package/out/types/enum.js.map +1 -0
  59. package/out/types/generator/hotReload.d.ts +2 -0
  60. package/out/types/generator/hotReload.js +12 -1
  61. package/out/types/generator/hotReload.js.map +1 -1
  62. package/out/types/index.d.ts +7 -1
  63. package/out/types/index.js +11 -2
  64. package/out/types/index.js.map +1 -1
  65. package/out/types/logic/BreakPoint.d.ts +42 -0
  66. package/out/types/logic/BreakPoint.js +155 -0
  67. package/out/types/logic/BreakPoint.js.map +1 -0
  68. package/out/types/logic/Debugger.d.ts +156 -0
  69. package/out/types/logic/Debugger.js +912 -0
  70. package/out/types/logic/Debugger.js.map +1 -0
  71. package/out/types/logic/Logic.d.ts +40 -0
  72. package/out/types/logic/Logic.js +130 -31
  73. package/out/types/logic/Logic.js.map +1 -1
  74. package/out/types/logic/LogicItem.d.ts +21 -1
  75. package/out/types/logic/LogicItem.js +227 -24
  76. package/out/types/logic/LogicItem.js.map +1 -1
  77. package/out/types/logic/Param.d.ts +1 -0
  78. package/out/types/logic/Param.js +38 -20
  79. package/out/types/logic/Param.js.map +1 -1
  80. package/out/types/logic/Return.js +14 -19
  81. package/out/types/logic/Return.js.map +1 -1
  82. package/out/types/logic/Variable.js +14 -19
  83. package/out/types/logic/Variable.js.map +1 -1
  84. package/out/types/logic/translator.js +0 -2
  85. package/out/types/logic/translator.js.map +1 -1
  86. package/out/types/nuims/Nuims.d.ts +1 -1
  87. package/out/types/nuims/Nuims.js +11 -4
  88. package/out/types/nuims/Nuims.js.map +1 -1
  89. package/out/types/page/Element.d.ts +5 -0
  90. package/out/types/page/Element.js +114 -130
  91. package/out/types/page/Element.js.map +1 -1
  92. package/out/types/page/Event.js.map +1 -1
  93. package/out/types/page/Page.d.ts +1 -0
  94. package/out/types/page/Page.js +59 -27
  95. package/out/types/page/Page.js.map +1 -1
  96. package/out/types/page/View.d.ts +17 -3
  97. package/out/types/page/View.js +53 -37
  98. package/out/types/page/View.js.map +1 -1
  99. package/out/types/page/ViewParam.d.ts +1 -0
  100. package/out/types/page/ViewParam.js +23 -4
  101. package/out/types/page/ViewParam.js.map +1 -1
  102. package/out/types/page/ViewVariable.js +13 -18
  103. package/out/types/page/ViewVariable.js.map +1 -1
  104. package/out/types/permission/Permission.d.ts +41 -0
  105. package/out/types/permission/Permission.js +122 -0
  106. package/out/types/permission/Permission.js.map +1 -0
  107. package/package.json +2 -2
  108. package/src/service/create/errHandles.js +6 -2
  109. package/src/service/debugger/debugger.js +90 -0
  110. package/src/service/developPermission/api.js +37 -0
  111. package/src/service/developPermission/index.js +13 -0
  112. package/src/service/logic/logic.js +20 -0
  113. package/src/service/page/element.js +6 -0
  114. package/src/service/permission/api.js +38 -0
  115. package/src/service/permission/index.js +13 -0
  116. package/src/service/webFile/index.js +6 -1
  117. package/src/types/app/App.ts +27 -1
  118. package/src/types/app/Service.ts +32 -3
  119. package/src/types/cache.ts +50 -0
  120. package/src/types/common/Vertex.ts +30 -0
  121. package/src/types/data/Entity.ts +1 -0
  122. package/src/types/data/Enum.ts +5 -0
  123. package/src/types/data/Interface.ts +4 -3
  124. package/src/types/data/genBlock/genCreateBlock.ts +5 -5
  125. package/src/types/data/genBlock/genCurdBlock.ts +3 -3
  126. package/src/types/data/genBlock/genEnumSelectBlock.ts +2 -2
  127. package/src/types/data/genBlock/genGridViewBlock.ts +12 -1
  128. package/src/types/data/genBlock/genListViewBlock.ts +2 -2
  129. package/src/types/data/genBlock/genSelectBlock.ts +2 -2
  130. package/src/types/data/genBlock/genTableBlock.ts +14 -3
  131. package/src/types/data/genBlock/genUpdateBlock.ts +5 -5
  132. package/src/types/data/systemTypes.ts +47 -0
  133. package/src/types/enum.ts +6 -0
  134. package/src/types/generator/hotReload.ts +10 -0
  135. package/src/types/index.ts +7 -1
  136. package/src/types/logic/BreakPoint.ts +200 -0
  137. package/src/types/logic/Debugger.ts +1140 -0
  138. package/src/types/logic/Logic.ts +133 -28
  139. package/src/types/logic/LogicItem.ts +250 -28
  140. package/src/types/logic/Param.ts +26 -8
  141. package/src/types/logic/Return.ts +4 -9
  142. package/src/types/logic/Variable.ts +4 -8
  143. package/src/types/logic/translator.d.ts +16 -0
  144. package/src/types/logic/translator.js +144 -88
  145. package/src/types/logic/translator_backup.js +5 -16
  146. package/src/types/nuims/Nuims.ts +11 -5
  147. package/src/types/page/Element.ts +63 -75
  148. package/src/types/page/Event.ts +0 -3
  149. package/src/types/page/Page.ts +73 -40
  150. package/src/types/page/View.ts +45 -18
  151. package/src/types/page/ViewParam.ts +22 -3
  152. package/src/types/page/ViewVariable.ts +4 -8
  153. package/src/types/permission/Permission.ts +112 -0
  154. package/tsconfig.json +1 -1
@@ -1,10 +1,44 @@
1
1
  import { immutable, excludedInJSON, circular, action } from '../decorators';
2
2
  import { config, history, utils, Vertex, LEVEL_ENUM, Interface, Param, Return, Variable, vertexsMap, typeCheck, ProcessComponent, ProcessInterface, Process, ActionOptions } from '..';
3
3
  import { logicService, paramService } from '../../service/logic';
4
+ import { sourceMapService } from '../../service/debugger/debugger';
4
5
  import View from '../page/View';
5
6
  import { ExpressionNode, LogicItem, LogicNode } from './LogicItem';
6
7
  import { convert2SchemaType } from '../data/dataTypeUtils';
7
8
  import { isPlainObject, throttle } from 'lodash';
9
+ interface sourceMapObj {
10
+ node: LogicItem,
11
+ classIdentify: string,
12
+ from: number,
13
+ lineFrom: number,
14
+ end: number
15
+ vertexId: string,
16
+ logicId: string,
17
+ }
18
+ import { refreshInterfaces, refreshView, refreshPages } from '../cache';
19
+ import { BusinessCode } from '../enum';
20
+
21
+ export function catchFn(logic: Logic) {
22
+ return async (err: any) => {
23
+ const code = err?.code;
24
+ if([BusinessCode.ElementExist, BusinessCode.ElementNotExist].includes(code)) {
25
+ if(logic.interface) {
26
+ await refreshInterfaces();
27
+ } else if(logic.view) {
28
+ await refreshView(logic.view);
29
+ }
30
+ } else if(code === BusinessCode.ParentElementNotExist) { // 父节点不存在。视图添加逻辑,发现视图不存在
31
+ if(logic.view) {
32
+ await refreshPages();
33
+ }
34
+ } else
35
+ config.defaultApp?.emit('saved', err);
36
+
37
+ config.defaultApp?.history.load();
38
+
39
+ throw err;
40
+ }
41
+ }
8
42
 
9
43
  /**
10
44
  * 逻辑类
@@ -115,6 +149,10 @@ export class Logic extends Vertex {
115
149
  */
116
150
  @excludedInJSON()
117
151
  public contentPromise: Promise<any> = undefined;
152
+ @excludedInJSON()
153
+ public sourceMap: {
154
+ [id: string]: Partial<sourceMapObj>
155
+ } = {};
118
156
  /**
119
157
  * 树组件的子节点字段
120
158
  */
@@ -123,6 +161,19 @@ export class Logic extends Vertex {
123
161
  /**
124
162
  * @param source 需要合并的部分参数
125
163
  */
164
+ /**
165
+ * 逻辑配置的cron表达式
166
+ */
167
+ @immutable()
168
+ public cron: string = undefined;
169
+ /**
170
+ * 定时类型,当前只能是cronTrigger
171
+ */
172
+ @immutable()
173
+ public triggerType: string = undefined;
174
+ /**
175
+ * 定时任务
176
+ */
126
177
  constructor(source?: Partial<Logic>) {
127
178
  super();
128
179
  source && this.assign(source);
@@ -152,7 +203,7 @@ export class Logic extends Vertex {
152
203
  operationDesc: actionOptions?.actionDesc || `添加逻辑"${this.name}"`,
153
204
  },
154
205
  body,
155
- });
206
+ }).catch(catchFn(this));
156
207
  this.deepPick(result, ['id']);
157
208
  this.pick(result, ['playgroundId']);
158
209
  this.assign({ body: result.body.map((logicNode) => LogicNode.from(logicNode, this, null)) });
@@ -180,9 +231,8 @@ export class Logic extends Vertex {
180
231
  */
181
232
  @action('删除逻辑')
182
233
  async delete(none?: void, actionOptions?: ActionOptions) {
183
- config.defaultApp?.emit('saving');
184
-
185
234
  if (this.id) {
235
+ config.defaultApp?.emit('saving');
186
236
  const body = this.toPlainJSON();
187
237
  if (this.view) {
188
238
  body.moduleId = this.view.id;
@@ -191,19 +241,15 @@ export class Logic extends Vertex {
191
241
  body.moduleId = this.interface.service.id;
192
242
  body.moduleType = 'microService';
193
243
  }
194
- try {
195
- await logicService.delete({
196
- headers: {
197
- appId: config.defaultApp?.id,
198
- operationAction: actionOptions?.actionName || 'Logic.delete',
199
- operationDesc: actionOptions?.actionDesc || `删除逻辑"${this.name}"`,
200
- },
201
- body,
202
- });
203
- } catch (err) {
204
- await config.defaultApp?.history.load();
205
- throw err;
206
- }
244
+
245
+ await logicService.delete({
246
+ headers: {
247
+ appId: config.defaultApp?.id,
248
+ operationAction: actionOptions?.actionName || 'Logic.delete',
249
+ operationDesc: actionOptions?.actionDesc || `删除逻辑"${this.name}"`,
250
+ },
251
+ body,
252
+ }).catch(catchFn(this));
207
253
 
208
254
  if (this.view) {
209
255
  const { logics } = this.view.$def;
@@ -249,7 +295,7 @@ export class Logic extends Vertex {
249
295
  operationDesc: actionOptions?.actionDesc || `修改逻辑"${this.name}"`,
250
296
  },
251
297
  body,
252
- });
298
+ }).catch(catchFn(this));
253
299
 
254
300
  await then?.();
255
301
  await config.defaultApp?.history.load();
@@ -305,17 +351,16 @@ export class Logic extends Vertex {
305
351
  return this.contentPromise;
306
352
 
307
353
  return this.contentPromise = (async () => {
308
- try {
309
- const result = await logicService.loadDetail({
310
- query: {
311
- moduleId: this.moduleId,
312
- moduleType: this.moduleType,
313
- id: this.id,
314
- },
315
- });
316
- const newLogic = Logic.from(result, this.interface || this.view || this.processComponent, this);
317
- this.assign(newLogic);
318
- } catch (err) {}
354
+ const result = await logicService.loadDetail({
355
+ query: {
356
+ moduleId: this.moduleId,
357
+ moduleType: this.moduleType,
358
+ id: this.id,
359
+ },
360
+ config: { noErrorTip: true },
361
+ }).catch(catchFn(this));
362
+ const newLogic = Logic.from(result, this.interface || this.view || this.processComponent, this);
363
+ this.assign(newLogic);
319
364
  return this;
320
365
  })().finally(() => this.contentPromise = undefined);
321
366
  }
@@ -387,6 +432,16 @@ export class Logic extends Vertex {
387
432
 
388
433
  return result as LogicItem;
389
434
  }
435
+ // async loadSourceMap() {
436
+ // if (!logic.view) {
437
+ // const result = await sourceMapService.getSourceMap({
438
+ // query: {
439
+ // scopeId: this.id,
440
+ // },
441
+ // });
442
+ // this.sourceMap = result;
443
+ // }
444
+ // }
390
445
  /**
391
446
  * 从后端 JSON 生成规范的 Logic 对象
392
447
  */
@@ -437,6 +492,56 @@ export class Logic extends Vertex {
437
492
 
438
493
  return logic;
439
494
  }
495
+ /**
496
+ * 更新定时任务
497
+ */
498
+ @action('更新定时任务')
499
+ async updateTimer(cron: string) {
500
+ this.assign({ cron });
501
+ this.triggerType = 'cronTrigger';
502
+ await this.update(undefined, {
503
+ actionDesc: `设置定时任务"为"${cron}"`,
504
+ });
505
+
506
+ if (this.view) {
507
+ this.view.page.service.emit('pageTreeChange');
508
+ this.emit('change');
509
+ }
510
+ return this;
511
+ }
512
+ /**
513
+ * 验证表达式正确与否
514
+ */
515
+ async validateTimer() {
516
+ const body = this.toPlainJSON();
517
+ const result = await logicService.validateTimer({
518
+ body,
519
+ config: {
520
+ noErrorTip: true,
521
+ },
522
+ });
523
+ return result;
524
+ }
525
+ /**
526
+ * 输出最近十次运行结果
527
+ */
528
+ async testTimer() {
529
+ const body = this.toPlainJSON();
530
+ const result = await logicService.testTimer({
531
+ body,
532
+ });
533
+ return result;
534
+ }
535
+ /**
536
+ * 更新接口缓存
537
+ */
538
+ async updateCronCache() {
539
+ const body = this.toPlainJSON();
540
+ const result = await logicService.updateCronCache({
541
+ body,
542
+ });
543
+ return result;
544
+ }
440
545
  }
441
546
 
442
547
  export default Logic;
@@ -1,11 +1,12 @@
1
- import { immutable, excludedInJSON, circular, action } from '../decorators';
2
- import { config, history, typeCheck, utils, Vertex, Service, LEVEL_ENUM, Interface, Param, Return, Variable, Logic, View, Schema, ActionOptions, ACTION_MODE } from '..';
1
+ import { immutable, excludedInJSON, action } from '../decorators';
2
+ import { config, typeCheck, utils, Vertex, LEVEL_ENUM, Logic, Schema, ActionOptions, ACTION_MODE, BreakPoint } from '..';
3
3
  import { logicService } from '../../service/logic';
4
- import { assert } from 'console';
5
4
  import { traverse } from '../utils';
6
5
  import { vertexsMap } from '../cacheData';
7
6
  import { getSchemaOfExpressionNode } from './tools';
8
7
  import Structure from '../data/Structure';
8
+ import { refreshLogic } from '../cache';
9
+ import { BusinessCode } from '../enum';
9
10
 
10
11
  export enum LOGIC_TYPE {
11
12
  // LogicNode
@@ -56,6 +57,18 @@ export enum LOGIC_TYPE {
56
57
  QueryAggregateExpression = 'QueryAggregateExpression',
57
58
  }
58
59
 
60
+ const atomicList = [
61
+ LOGIC_TYPE.Identifier,
62
+ LOGIC_TYPE.NumericLiteral,
63
+ LOGIC_TYPE.BooleanLiteral,
64
+ LOGIC_TYPE.StringLiteral,
65
+ LOGIC_TYPE.NullLiteral,
66
+ LOGIC_TYPE.UnaryExpression,
67
+ LOGIC_TYPE.MemberExpression,
68
+ LOGIC_TYPE.Unparsed,
69
+ LOGIC_TYPE.BuiltInFunction,
70
+ ];
71
+
59
72
  export function evaluate(node: LogicNode | ExpressionNode, finalCode = true): string {
60
73
  if (!node)
61
74
  return '';
@@ -76,11 +89,11 @@ export function evaluate(node: LogicNode | ExpressionNode, finalCode = true): st
76
89
 
77
90
  if (node.type === 'BinaryExpression') {
78
91
  let left: string = evaluate(<LogicNode>node.left, finalCode);
79
- if (!finalCode && node.left?.type === LOGIC_TYPE.MemberExpression)
92
+ if (!atomicList.includes(node.left?.type as LOGIC_TYPE) || (!finalCode && node.left?.type === LOGIC_TYPE.MemberExpression))
80
93
  left = `(${left})`;
81
94
 
82
95
  let right: string = evaluate(<LogicNode>node.right, finalCode);
83
- if (!finalCode && node.right?.type === LOGIC_TYPE.MemberExpression)
96
+ if (!atomicList.includes(node.right?.type as LOGIC_TYPE) || (!finalCode && node.left?.type === LOGIC_TYPE.MemberExpression))
84
97
  right = `(${right})`;
85
98
 
86
99
  return `${left} ${node.operator} ${right}`;
@@ -88,13 +101,11 @@ export function evaluate(node: LogicNode | ExpressionNode, finalCode = true): st
88
101
 
89
102
  if (node.type === 'LogicalExpression') {
90
103
  let left: string = evaluate(<LogicNode>node.left, finalCode);
91
- if (!finalCode && node.left?.type === LOGIC_TYPE.MemberExpression)
104
+ if (!atomicList.includes(node.left?.type as LOGIC_TYPE) || (!finalCode && node.left?.type === LOGIC_TYPE.MemberExpression))
92
105
  left = `(${left})`;
93
-
94
106
  let right: string = evaluate(<LogicNode>node.right, finalCode);
95
- if (!finalCode && node.right?.type === LOGIC_TYPE.MemberExpression)
107
+ if (!atomicList.includes(node.right?.type as LOGIC_TYPE) || (!finalCode && node.left?.type === LOGIC_TYPE.MemberExpression))
96
108
  right = `(${right})`;
97
-
98
109
  return `${left} ${node.operator} ${right}`;
99
110
  }
100
111
 
@@ -209,6 +220,18 @@ export const logicItemArrayKeyOfLogicItem: string[] = ['body', 'consequent', 'al
209
220
  'groupBy', 'orderBy', 'selectElementList', 'joinPartList', 'onExpressionList', 'where', 'having',
210
221
  ];
211
222
 
223
+ export function catchFn(logic: Logic) {
224
+ return async (err: any) => {
225
+ if (err.code !== BusinessCode.HasReferenced) // 节点被引用,不用刷新数据
226
+ await refreshLogic(logic);
227
+ else
228
+ config.defaultApp?.emit('saved', err);
229
+
230
+ config.defaultApp?.history.load();
231
+ throw err;
232
+ };
233
+ }
234
+
212
235
  /**
213
236
  * 逻辑项类
214
237
  */
@@ -287,6 +310,14 @@ export class LogicItem extends Vertex {
287
310
  public readonly pageParamKey: any = undefined;
288
311
  @immutable()
289
312
  public readonly pageParamKeyValue: any = undefined;
313
+
314
+ /**
315
+ 断点集合
316
+ */
317
+ @immutable()
318
+ @excludedInJSON()
319
+ public breakPoints: Array<BreakPoint> = [];
320
+ public temporaryBreakPoint: BreakPoint = null;
290
321
  /**
291
322
  * CallQueryComponent 对应的 structure 的 id
292
323
  */
@@ -432,7 +463,7 @@ export class LogicItem extends Vertex {
432
463
  operationIgnore: actionOptions?.actionIgnore,
433
464
  },
434
465
  body,
435
- });
466
+ }).catch(catchFn(this.logic));
436
467
  this.deepPick(result, ['id', 'parentId', 'parentAttr', 'joinPartRef', 'structureRef']);
437
468
  }
438
469
 
@@ -548,7 +579,7 @@ export class LogicItem extends Vertex {
548
579
  offsetY,
549
580
  },
550
581
  },
551
- });
582
+ }).catch(catchFn(this.logic));
552
583
  }
553
584
 
554
585
  if (!(this.parentId === parentId && this.parentId === this.logic.playgroundId && this.parentAttr === parentAttr)) {
@@ -612,6 +643,8 @@ export class LogicItem extends Vertex {
612
643
  * @param targetId
613
644
  */
614
645
  static async paste(logicItems: LogicItem[] | LogicItem, targetType: 'logic' | 'html' | 'processComponent', targetId: string) {
646
+ config.defaultApp?.emit('saving');
647
+
615
648
  if (!Array.isArray(logicItems))
616
649
  logicItems = [logicItems];
617
650
 
@@ -630,7 +663,7 @@ export class LogicItem extends Vertex {
630
663
  operationAction: 'LogicItem.paste',
631
664
  operationDesc: `粘贴逻辑项"${logicItems[0].label || logicItems[0].type}"`,
632
665
  },
633
- });
666
+ }).catch(catchFn(vertexsMap.get(targetId) as Logic));
634
667
 
635
668
  LogicItem.redoPaste(res);
636
669
  }
@@ -773,26 +806,23 @@ export class LogicItem extends Vertex {
773
806
 
774
807
  if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
775
808
  if (this.id) {
809
+ await this.removeAllBreakPointsOfDescendants();
810
+
776
811
  const body = this.toPlainJSON();
777
812
  /// @TODO: 不知道哪里来的 index
778
813
  delete body.index;
779
814
  ///
780
815
 
781
- try {
782
- await logicService.removeItem({
783
- headers: {
784
- appId: config.defaultApp?.id,
785
- serviceId: this.logic?.interface?.serviceId,
786
- operationAction: 'LogicItem.delete',
787
- operationDesc: `删除逻辑项"${this.label || this.type}"`,
788
-
789
- },
790
- body,
791
- });
792
- } catch (err) {
793
- await config.defaultApp?.history.load();
794
- throw err;
795
- }
816
+ await logicService.removeItem({
817
+ headers: {
818
+ appId: config.defaultApp?.id,
819
+ serviceId: this.logic?.interface?.serviceId,
820
+ operationAction: 'LogicItem.delete',
821
+ operationDesc: `删除逻辑项"${this.label || this.type}"`,
822
+
823
+ },
824
+ body,
825
+ }).catch(catchFn(this.logic));
796
826
  }
797
827
  }
798
828
 
@@ -883,7 +913,7 @@ export class LogicItem extends Vertex {
883
913
  operationIgnore: actionOptions?.actionIgnore,
884
914
  },
885
915
  body,
886
- });
916
+ }).catch(catchFn(this.logic));
887
917
  // this.deepPick(result, ['id', 'parentId', 'parentAttr']);
888
918
 
889
919
  // 合并params里的id
@@ -1119,6 +1149,158 @@ export class LogicItem extends Vertex {
1119
1149
  parentAttr: activeImage.parentAttr,
1120
1150
  };
1121
1151
  }
1152
+
1153
+ addBreakPointInstance(bp: BreakPoint) {
1154
+ const finded = this.breakPoints.find((item) => item.offset === bp.offset);
1155
+ if (!finded) {
1156
+ this.breakPoints.push(bp);
1157
+ }
1158
+ }
1159
+
1160
+ async addBreakPoint(appId: string, offsetLine = 0) {
1161
+ let bp = this.breakPoints.find((bp) => bp.offset === offsetLine);
1162
+ if (bp) {
1163
+ return bp;
1164
+ }
1165
+ bp = new BreakPoint();
1166
+ await bp.create({
1167
+ appId,
1168
+ logicItem: this,
1169
+ offset: offsetLine,
1170
+ });
1171
+ this.breakPoints.push(bp);
1172
+ const app = config.defaultApp;
1173
+ app.debuggerClient.breakPoints.push(bp);
1174
+ return bp;
1175
+ }
1176
+
1177
+ getBreakPointByLineNumber(lineNumber: number) {
1178
+ return this.breakPoints.find((bp) => bp.lineNumberStart === lineNumber);
1179
+ }
1180
+
1181
+ addTemperaryBreakPoint(offsetLine = 0) {
1182
+ const bp = new BreakPoint({
1183
+ target: this.logic && this.logic.view ? 'Frontend' : 'Backend',
1184
+ logicItem: this,
1185
+ logicItemId: this.id,
1186
+ componentId: this.logic && this.logic.view && this.logic.view.id,
1187
+ component: this.logic && this.logic.view,
1188
+ logic: this.logic,
1189
+ status: 'Enabled',
1190
+ offset: offsetLine,
1191
+ isTemporary: true,
1192
+ });
1193
+ bp.attachSourceMap();
1194
+ this.temporaryBreakPoint = bp;
1195
+ return bp;
1196
+ }
1197
+
1198
+ get breakPoint(): BreakPoint {
1199
+ if (this.parent?.type === 'SwitchCase' && this.parentAttr === 'test')
1200
+ return this.parent.breakPoint;
1201
+
1202
+ return this.breakPoints?.find((bp) => bp.offset === 0);
1203
+ }
1204
+
1205
+ get hasBreakPoint(): boolean {
1206
+ if (this.parent?.type === 'SwitchCase' && this.parentAttr === 'test')
1207
+ return this.parent.hasBreakPoint;
1208
+
1209
+ return !!(this.temporaryBreakPoint || this.breakPoint);
1210
+ }
1211
+
1212
+ get isBreakPointEnabled(): boolean {
1213
+ if (this.parent?.type === 'SwitchCase' && this.parentAttr === 'test')
1214
+ return this.parent.isBreakPointEnabled;
1215
+
1216
+ return this.breakPoint?.status === 'Enabled';
1217
+ }
1218
+
1219
+ get isBreakPointDisabled(): boolean {
1220
+ if (this.parent?.type === 'SwitchCase' && this.parentAttr === 'test')
1221
+ return this.parent.isBreakPointDisabled;
1222
+
1223
+ return this.breakPoint?.status === 'Disabled';
1224
+ }
1225
+
1226
+ get isBreakPointActive(): boolean {
1227
+ if (this.parent?.type === 'SwitchCase' && this.parentAttr === 'test')
1228
+ return this.parent.isBreakPointActive;
1229
+ if (config.defaultApp.debuggerClient?.currentThread) {
1230
+ const bp = this.temporaryBreakPoint || this.breakPoint;
1231
+ return bp === config.defaultApp.debuggerClient?.currentThread.breakPoint;
1232
+ }
1233
+ return false;
1234
+ // if (this.temporaryBreakPoint) {
1235
+ // return true;
1236
+ // }
1237
+ // return this.breakPoint === config.defaultApp.debuggerClient?.currentBreakPoint;
1238
+ }
1239
+
1240
+ async setBreakPoint(offsetLine = 0) {
1241
+ const app = config.defaultApp;
1242
+ if (app.debuggerClient?.isConnected) {
1243
+ const breakPoint = new BreakPoint({
1244
+ target: this.logic && this.logic.view ? 'Frontend' : 'Backend',
1245
+ logicItem: this,
1246
+ logicItemId: this.id,
1247
+ componentId: this.logic && this.logic.view && this.logic.view.id,
1248
+ component: this.logic && this.logic.view,
1249
+ logic: this.logic,
1250
+ status: 'Enabled',
1251
+ offset: offsetLine,
1252
+ });
1253
+ const attachResult = breakPoint.attachSourceMap();
1254
+ if (attachResult) {
1255
+ await app.debuggerClient.setRemoteBreakPoint(breakPoint);
1256
+ await this.addBreakPoint(app.id, offsetLine);
1257
+ } else {
1258
+ this.emit('breakpointattacherror', {
1259
+ message: '未在sourceMap中找到'
1260
+ });
1261
+ }
1262
+ } else {
1263
+ await this.addBreakPoint(app.id, offsetLine);
1264
+ }
1265
+ }
1266
+
1267
+ async removeBreakPoint(offsetLine = 0) {
1268
+ const app = config.defaultApp;
1269
+ const breakPoints = this.parent?.type === 'SwitchCase' && this.parentAttr === 'test' ? this.parent.breakPoints : this.breakPoints;
1270
+ const breakPoint = breakPoints.find((bp) => bp.offset === offsetLine);
1271
+ await app.debuggerClient?.removeRemoteBreakPoint(breakPoint);
1272
+ await breakPoint?.remove();
1273
+ }
1274
+
1275
+ async removeAllBreakPointsOfDescendants() {
1276
+ const promises: Array<Promise<void>> = [];
1277
+ utils.traverse(({ node }) => {
1278
+ if (node.breakPoints?.length > 0) {
1279
+ node.breakPoints.forEach((bp) => {
1280
+ promises.push(node.removeBreakPoint(bp.offset));
1281
+ });
1282
+ }
1283
+ }, { node: this }, {
1284
+ mode: 'anyObject',
1285
+ excludedKeySet: this.JSON_EXCLUDED_KEYS,
1286
+ });
1287
+ await Promise.all(promises);
1288
+ }
1289
+
1290
+ async disableAllBreakPointsOfDescendants() {
1291
+ const promises: Array<Promise<void>> = [];
1292
+ utils.traverse(({ node }) => {
1293
+ if (node.breakPoints?.length > 0) {
1294
+ node.breakPoints.forEach((bp) => {
1295
+ promises.push(bp.disable());
1296
+ });
1297
+ }
1298
+ }, { node: this }, {
1299
+ mode: 'anyObject',
1300
+ excludedKeySet: this.JSON_EXCLUDED_KEYS,
1301
+ });
1302
+ await Promise.all(promises);
1303
+ }
1122
1304
  }
1123
1305
 
1124
1306
  export class LogicNode extends LogicItem {
@@ -1254,4 +1436,44 @@ export class ExpressionNode extends LogicItem {
1254
1436
  super();
1255
1437
  source && this.assign(source);
1256
1438
  }
1439
+
1440
+ addBreakPoint(appId: string, offsetLine = 0) {
1441
+ // let switchParent = this.parent;
1442
+ // let switchCase;
1443
+ // while (switchParent && switchParent.type !== 'SwitchStatement') {
1444
+ // if (switchParent.type === 'SwitchCase') {
1445
+ // switchCase = switchParent;
1446
+ // }
1447
+ // switchParent = switchParent.parent;
1448
+ // }
1449
+
1450
+ // switchCase 是个 logicNode,直接加好了
1451
+ if (this.parent?.type === 'SwitchCase' && this.parentAttr === 'test')
1452
+ return this.parent.addBreakPoint(appId, offsetLine);
1453
+ // const index = switchParent.cases.findIndex((c) => c === switchCase);
1454
+ // const id = switchCase.id;
1455
+
1456
+ // const view = this.logic.view;
1457
+ // const sourceMap = view.sourceMap;
1458
+ // const componentId = view.id;
1459
+ // // const id = `${switchParent.id}-case${index}`;
1460
+ // const map = sourceMap[id];
1461
+ // if (map) {
1462
+ // const lineNumberStart = map.from + offsetLine;
1463
+ // let bp = this.breakPoints.find((bp) => bp.lineNumberStart === lineNumberStart);
1464
+ // if (bp) {
1465
+ // return bp;
1466
+ // }
1467
+ // bp = new BreakPoint({
1468
+ // lineNumberStart,
1469
+ // logicItem: switchCase,
1470
+ // logicItemId: switchCase.id,
1471
+ // componentId,
1472
+ // });
1473
+ // switchCase.breakPoints.push(bp);
1474
+ // return bp;
1475
+ // }
1476
+ // return null;
1477
+ return super.addBreakPoint(appId, offsetLine);
1478
+ }
1257
1479
  }
@@ -4,6 +4,29 @@ import { paramService } from '../../service/logic';
4
4
  import { convert2RefType, convert2SchemaType } from '../data/dataTypeUtils';
5
5
  import { getBasicTypeDefaultValue } from '../data/basicTypes';
6
6
  import { schemaService } from '../../service/common';
7
+ import { refreshLogic, refreshInterfaces, refreshView } from '../cache';
8
+ import { BusinessCode } from '../enum';
9
+
10
+ export function catchFn(logic: Logic) {
11
+ return async (err: any) => {
12
+ const code = err?.code;
13
+ // 节点已存在; 节点不存在
14
+ if([BusinessCode.ElementExist, BusinessCode.ElementNotExist].includes(code)) {
15
+ await refreshLogic(logic);
16
+ } else if(code === BusinessCode.ParentElementNotExist) { // 父节点不存在,即逻辑不存在
17
+ if(logic.interface) {
18
+ await refreshInterfaces();
19
+ } else if(logic.view) {
20
+ await refreshView(logic.view);
21
+ }
22
+ } else
23
+ config.defaultApp?.emit('saved', err);
24
+
25
+ config.defaultApp?.history.load();
26
+
27
+ throw err;
28
+ }
29
+ }
7
30
 
8
31
  /**
9
32
  * 逻辑输入参数
@@ -60,7 +83,7 @@ export class Param extends BaseVariable {
60
83
  operationDesc: actionOptions?.actionDesc || `添加逻辑"${this.logic.name}"输入参数"${this.name}"`,
61
84
  },
62
85
  body,
63
- });
86
+ }).catch(catchFn(this.logic));
64
87
  // convert2RefType(result.schema);
65
88
  this.deepPick(result, ['id']);
66
89
  this.assign({ code: this.genCode() });
@@ -85,7 +108,6 @@ export class Param extends BaseVariable {
85
108
  config.defaultApp?.emit('saving');
86
109
 
87
110
  if (this.id) {
88
- try {
89
111
  await paramService.delete({
90
112
  headers: {
91
113
  appId: config.defaultApp?.id,
@@ -96,11 +118,7 @@ export class Param extends BaseVariable {
96
118
  loValId: this.id,
97
119
  logicId: this.logic.id,
98
120
  },
99
- });
100
- } catch(err) {
101
- await config.defaultApp?.history.load();
102
- throw err;
103
- }
121
+ }).catch(catchFn(this.logic));
104
122
  }
105
123
 
106
124
  const index = this.logic.params.indexOf(this);
@@ -133,7 +151,7 @@ export class Param extends BaseVariable {
133
151
  operationDesc: actionOptions?.actionDesc || `修改逻辑输入参数"${this.name}"`,
134
152
  },
135
153
  body,
136
- });
154
+ }).catch(catchFn(this.logic));
137
155
  this.schema.id = result.schema.id;
138
156
  // convert2RefType(result.schema);
139
157
  // this.plainAssign(result);