@lcap/nasl 0.3.10-beta → 0.3.10-beta.5

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 (61) hide show
  1. package/out/service/logic/logic.d.ts +26 -17
  2. package/out/service/logic/logic.js +6 -0
  3. package/out/service/logic/logic.js.map +1 -1
  4. package/out/types/app/App.d.ts +5 -4
  5. package/out/types/app/App.js +30 -24
  6. package/out/types/app/App.js.map +1 -1
  7. package/out/types/cacheData.js.map +1 -1
  8. package/out/types/data/dataTypes.js +1 -1
  9. package/out/types/data/dataTypes.js.map +1 -1
  10. package/out/types/index.d.ts +2 -4
  11. package/out/types/index.js +3 -6
  12. package/out/types/index.js.map +1 -1
  13. package/out/types/logic/Logic.d.ts +4 -12
  14. package/out/types/logic/Logic.js +26 -14
  15. package/out/types/logic/Logic.js.map +1 -1
  16. package/out/types/logic/LogicItem.d.ts +1 -20
  17. package/out/types/logic/LogicItem.js +0 -184
  18. package/out/types/logic/LogicItem.js.map +1 -1
  19. package/out/types/logic/Param.js +2 -0
  20. package/out/types/logic/Param.js.map +1 -1
  21. package/out/types/logic/translator.js +39 -8
  22. package/out/types/logic/translator.js.map +1 -1
  23. package/out/types/page/Element.d.ts +10 -2
  24. package/out/types/page/Element.js +51 -4
  25. package/out/types/page/Element.js.map +1 -1
  26. package/out/types/page/View.d.ts +10 -16
  27. package/out/types/page/View.js +40 -15
  28. package/out/types/page/View.js.map +1 -1
  29. package/out/types/process/ProcessParam.js +3 -1
  30. package/out/types/process/ProcessParam.js.map +1 -1
  31. package/package.json +1 -2
  32. package/src/service/logic/logic.js +6 -0
  33. package/src/types/app/App.ts +36 -27
  34. package/src/types/cacheData.ts +7 -7
  35. package/src/types/data/dataTypes.ts +1 -1
  36. package/src/types/index.ts +2 -4
  37. package/src/types/logic/Logic.ts +35 -30
  38. package/src/types/logic/LogicItem.ts +5 -207
  39. package/src/types/logic/Param.ts +20 -17
  40. package/src/types/logic/translator.js +125 -153
  41. package/src/types/page/Element.ts +121 -71
  42. package/src/types/page/View.ts +79 -61
  43. package/src/types/page/dist/View.js +727 -0
  44. package/src/types/process/ProcessParam.ts +4 -1
  45. package/tsconfig.json +1 -1
  46. package/out/service/debugger/debugger.d.ts +0 -3
  47. package/out/service/debugger/debugger.js +0 -95
  48. package/out/service/debugger/debugger.js.map +0 -1
  49. package/out/test/units/config.spec.d.ts +0 -1
  50. package/out/test/units/config.spec.js +0 -12
  51. package/out/test/units/config.spec.js.map +0 -1
  52. package/out/types/logic/BreakPoint.d.ts +0 -42
  53. package/out/types/logic/BreakPoint.js +0 -155
  54. package/out/types/logic/BreakPoint.js.map +0 -1
  55. package/out/types/logic/Debugger.d.ts +0 -156
  56. package/out/types/logic/Debugger.js +0 -912
  57. package/out/types/logic/Debugger.js.map +0 -1
  58. package/src/service/debugger/debugger.js +0 -90
  59. package/src/types/logic/BreakPoint.ts +0 -200
  60. package/src/types/logic/Debugger.ts +0 -1140
  61. package/src/types/logic/translator.d.ts +0 -16
@@ -1,5 +1,5 @@
1
1
  import { immutable, excludedInJSON, action } from '../decorators';
2
- import { config, typeCheck, utils, Vertex, LEVEL_ENUM, Logic, Schema, ActionOptions, ACTION_MODE, BreakPoint } from '..';
2
+ import { config, typeCheck, utils, Vertex, LEVEL_ENUM, Logic, Schema, ActionOptions, ACTION_MODE } from '..';
3
3
  import { logicService } from '../../service/logic';
4
4
  import { traverse } from '../utils';
5
5
  import { vertexsMap } from '../cacheData';
@@ -89,11 +89,11 @@ export function evaluate(node: LogicNode | ExpressionNode, finalCode = true): st
89
89
 
90
90
  if (node.type === 'BinaryExpression') {
91
91
  let left: string = evaluate(<LogicNode>node.left, finalCode);
92
- if (!atomicList.includes(node.left?.type as LOGIC_TYPE) || (!finalCode && node.left?.type === LOGIC_TYPE.MemberExpression))
92
+ if (!atomicList.includes((node.left as any)?.type) || (!finalCode && node.left?.type === LOGIC_TYPE.MemberExpression))
93
93
  left = `(${left})`;
94
94
 
95
95
  let right: string = evaluate(<LogicNode>node.right, finalCode);
96
- if (!atomicList.includes(node.right?.type as LOGIC_TYPE) || (!finalCode && node.left?.type === LOGIC_TYPE.MemberExpression))
96
+ if (!atomicList.includes((node.right as any)?.type) || (!finalCode && node.left?.type === LOGIC_TYPE.MemberExpression))
97
97
  right = `(${right})`;
98
98
 
99
99
  return `${left} ${node.operator} ${right}`;
@@ -101,10 +101,10 @@ export function evaluate(node: LogicNode | ExpressionNode, finalCode = true): st
101
101
 
102
102
  if (node.type === 'LogicalExpression') {
103
103
  let left: string = evaluate(<LogicNode>node.left, finalCode);
104
- if (!atomicList.includes(node.left?.type as LOGIC_TYPE) || (!finalCode && node.left?.type === LOGIC_TYPE.MemberExpression))
104
+ if (!atomicList.includes((node.left as any)?.type) || (!finalCode && node.left?.type === LOGIC_TYPE.MemberExpression))
105
105
  left = `(${left})`;
106
106
  let right: string = evaluate(<LogicNode>node.right, finalCode);
107
- if (!atomicList.includes(node.right?.type as LOGIC_TYPE) || (!finalCode && node.left?.type === LOGIC_TYPE.MemberExpression))
107
+ if (!atomicList.includes((node.right as any)?.type) || (!finalCode && node.left?.type === LOGIC_TYPE.MemberExpression))
108
108
  right = `(${right})`;
109
109
  return `${left} ${node.operator} ${right}`;
110
110
  }
@@ -310,14 +310,6 @@ export class LogicItem extends Vertex {
310
310
  public readonly pageParamKey: any = undefined;
311
311
  @immutable()
312
312
  public readonly pageParamKeyValue: any = undefined;
313
-
314
- /**
315
- 断点集合
316
- */
317
- @immutable()
318
- @excludedInJSON()
319
- public breakPoints: Array<BreakPoint> = [];
320
- public temporaryBreakPoint: BreakPoint = null;
321
313
  /**
322
314
  * CallQueryComponent 对应的 structure 的 id
323
315
  */
@@ -806,8 +798,6 @@ export class LogicItem extends Vertex {
806
798
 
807
799
  if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
808
800
  if (this.id) {
809
- await this.removeAllBreakPointsOfDescendants();
810
-
811
801
  const body = this.toPlainJSON();
812
802
  /// @TODO: 不知道哪里来的 index
813
803
  delete body.index;
@@ -1149,158 +1139,6 @@ export class LogicItem extends Vertex {
1149
1139
  parentAttr: activeImage.parentAttr,
1150
1140
  };
1151
1141
  }
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
- }
1304
1142
  }
1305
1143
 
1306
1144
  export class LogicNode extends LogicItem {
@@ -1436,44 +1274,4 @@ export class ExpressionNode extends LogicItem {
1436
1274
  super();
1437
1275
  source && this.assign(source);
1438
1276
  }
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
- }
1479
1277
  }
@@ -11,21 +11,21 @@ export function catchFn(logic: Logic) {
11
11
  return async (err: any) => {
12
12
  const code = err?.code;
13
13
  // 节点已存在; 节点不存在
14
- if([BusinessCode.ElementExist, BusinessCode.ElementNotExist].includes(code)) {
14
+ if ([BusinessCode.ElementExist, BusinessCode.ElementNotExist].includes(code)) {
15
15
  await refreshLogic(logic);
16
- } else if(code === BusinessCode.ParentElementNotExist) { // 父节点不存在,即逻辑不存在
17
- if(logic.interface) {
16
+ } else if (code === BusinessCode.ParentElementNotExist) { // 父节点不存在,即逻辑不存在
17
+ if (logic.interface) {
18
18
  await refreshInterfaces();
19
- } else if(logic.view) {
19
+ } else if (logic.view) {
20
20
  await refreshView(logic.view);
21
21
  }
22
22
  } else
23
23
  config.defaultApp?.emit('saved', err);
24
-
24
+
25
25
  config.defaultApp?.history.load();
26
26
 
27
27
  throw err;
28
- }
28
+ };
29
29
  }
30
30
 
31
31
  /**
@@ -98,6 +98,9 @@ export class Param extends BaseVariable {
98
98
 
99
99
  await config.defaultApp?.history.load();
100
100
  config.defaultApp?.emit('saved');
101
+
102
+ // 更新所有调用此Logic的LogicItem
103
+ await this.logic.callLogicUpdate();
101
104
  return this;
102
105
  }
103
106
  /**
@@ -108,17 +111,17 @@ export class Param extends BaseVariable {
108
111
  config.defaultApp?.emit('saving');
109
112
 
110
113
  if (this.id) {
111
- await paramService.delete({
112
- headers: {
113
- appId: config.defaultApp?.id,
114
- operationAction: actionOptions?.actionName || 'Param.create',
115
- operationDesc: actionOptions?.actionDesc || `删除逻辑"${this.logic.name}"输入参数"${this.name}"`,
116
- },
117
- query: {
118
- loValId: this.id,
119
- logicId: this.logic.id,
120
- },
121
- }).catch(catchFn(this.logic));
114
+ await paramService.delete({
115
+ headers: {
116
+ appId: config.defaultApp?.id,
117
+ operationAction: actionOptions?.actionName || 'Param.create',
118
+ operationDesc: actionOptions?.actionDesc || `删除逻辑"${this.logic.name}"输入参数"${this.name}"`,
119
+ },
120
+ query: {
121
+ loValId: this.id,
122
+ logicId: this.logic.id,
123
+ },
124
+ }).catch(catchFn(this.logic));
122
125
  }
123
126
 
124
127
  const index = this.logic.params.indexOf(this);