@lcap/nasl 2.20.1-beta.1 → 2.20.1-beta.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 (264) hide show
  1. package/docs/classes/EntityProperty.html +1 -1
  2. package/out/automate/engine/operators.d.ts +10 -1
  3. package/out/automate/engine/operators.js +14 -5
  4. package/out/automate/engine/operators.js.map +1 -1
  5. package/out/automate/engine/viewCache.d.ts +1 -0
  6. package/out/automate/template/myProcess.d.ts +1 -0
  7. package/out/automate/template/myProcess.js +9021 -9021
  8. package/out/automate/template/myProcess.js.map +1 -1
  9. package/out/bak/translator.js +3 -3
  10. package/out/bak/translator.js.map +1 -1
  11. package/out/common/BaseNode.js.map +1 -1
  12. package/out/common/Command.d.ts +1 -1
  13. package/out/common/EventEmitter.d.ts +1 -1
  14. package/out/concepts/Abort__.d.ts +25 -0
  15. package/out/concepts/Abort__.js +80 -0
  16. package/out/concepts/Abort__.js.map +1 -0
  17. package/out/concepts/Anchor__.js.map +1 -1
  18. package/out/concepts/AnonymousFunction__.js.map +1 -1
  19. package/out/concepts/App__.js.map +1 -1
  20. package/out/concepts/Argument__.js.map +1 -1
  21. package/out/concepts/Assignee__.js.map +1 -1
  22. package/out/concepts/AssignmentLine__.js.map +1 -1
  23. package/out/concepts/Assignment__.js.map +1 -1
  24. package/out/concepts/Attribute__.js.map +1 -1
  25. package/out/concepts/BatchAssignment__.js.map +1 -1
  26. package/out/concepts/BinaryExpression__.js.map +1 -1
  27. package/out/concepts/BindAttribute__.js +7 -6
  28. package/out/concepts/BindAttribute__.js.map +1 -1
  29. package/out/concepts/BindDirective__.js +7 -6
  30. package/out/concepts/BindDirective__.js.map +1 -1
  31. package/out/concepts/BindEvent__.js.map +1 -1
  32. package/out/concepts/BindStyle__.js +10 -10
  33. package/out/concepts/BindStyle__.js.map +1 -1
  34. package/out/concepts/BooleanLiteral__.js.map +1 -1
  35. package/out/concepts/CallFunction__.js.map +1 -1
  36. package/out/concepts/CallInterface__.d.ts +1 -0
  37. package/out/concepts/CallInterface__.js +32 -2
  38. package/out/concepts/CallInterface__.js.map +1 -1
  39. package/out/concepts/CallLogic__.js +3 -3
  40. package/out/concepts/CallLogic__.js.map +1 -1
  41. package/out/concepts/CallQueryComponent__.js.map +1 -1
  42. package/out/concepts/Comment__.js.map +1 -1
  43. package/out/concepts/CompletionProperty__.js.map +1 -1
  44. package/out/concepts/ConfigGroup__.js.map +1 -1
  45. package/out/concepts/ConfigPropertyValue__.js.map +1 -1
  46. package/out/concepts/ConfigProperty__.js.map +1 -1
  47. package/out/concepts/Configuration__.js.map +1 -1
  48. package/out/concepts/Constant__.js.map +1 -1
  49. package/out/concepts/DataElement__.js.map +1 -1
  50. package/out/concepts/DataSource__.js +11 -3
  51. package/out/concepts/DataSource__.js.map +1 -1
  52. package/out/concepts/DatabaseTypeAnnotation__.d.ts +31 -0
  53. package/out/concepts/DatabaseTypeAnnotation__.js +78 -0
  54. package/out/concepts/DatabaseTypeAnnotation__.js.map +1 -0
  55. package/out/concepts/Destination__.js +7 -7
  56. package/out/concepts/Destination__.js.map +1 -1
  57. package/out/concepts/End__.js.map +1 -1
  58. package/out/concepts/EntityIndex__.d.ts +1 -1
  59. package/out/concepts/EntityIndex__.js.map +1 -1
  60. package/out/concepts/EntityProperty__.d.ts +1 -1
  61. package/out/concepts/EntityProperty__.js.map +1 -1
  62. package/out/concepts/Entity__.js.map +1 -1
  63. package/out/concepts/EnumItem__.js.map +1 -1
  64. package/out/concepts/Enum__.js.map +1 -1
  65. package/out/concepts/Event__.js.map +1 -1
  66. package/out/concepts/ExternalDestination__.js.map +1 -1
  67. package/out/concepts/ForEachStatement__.js.map +1 -1
  68. package/out/concepts/FrontendLibrary__.js.map +1 -1
  69. package/out/concepts/Frontend__.js.map +1 -1
  70. package/out/concepts/Function__.js.map +1 -1
  71. package/out/concepts/Identifier__.js.map +1 -1
  72. package/out/concepts/IfStatement__.js.map +1 -1
  73. package/out/concepts/Integration__.d.ts +53 -0
  74. package/out/concepts/Integration__.js +143 -0
  75. package/out/concepts/Integration__.js.map +1 -0
  76. package/out/concepts/InterfaceParam__.js.map +1 -1
  77. package/out/concepts/Interface__.d.ts +9 -0
  78. package/out/concepts/Interface__.js +54 -0
  79. package/out/concepts/Interface__.js.map +1 -1
  80. package/out/concepts/JSBlock__.js.map +1 -1
  81. package/out/concepts/JavaLogic__.d.ts +42 -0
  82. package/out/concepts/JavaLogic__.js +122 -0
  83. package/out/concepts/JavaLogic__.js.map +1 -0
  84. package/out/concepts/LogicItem__.js.map +1 -1
  85. package/out/concepts/Logic__.js +2 -2
  86. package/out/concepts/Logic__.js.map +1 -1
  87. package/out/concepts/MatchCase__.js.map +1 -1
  88. package/out/concepts/Match__.d.ts +3 -0
  89. package/out/concepts/Match__.js +73 -2
  90. package/out/concepts/Match__.js.map +1 -1
  91. package/out/concepts/MemberExpression__.js.map +1 -1
  92. package/out/concepts/MicroApp__.d.ts +51 -0
  93. package/out/concepts/MicroApp__.js +113 -0
  94. package/out/concepts/MicroApp__.js.map +1 -0
  95. package/out/concepts/Module__.d.ts +1 -1
  96. package/out/concepts/Module__.js.map +1 -1
  97. package/out/concepts/Namespace__.js.map +1 -1
  98. package/out/concepts/NewComposite__.d.ts +1 -0
  99. package/out/concepts/NewComposite__.js +20 -2
  100. package/out/concepts/NewComposite__.js.map +1 -1
  101. package/out/concepts/NewList__.js.map +1 -1
  102. package/out/concepts/NewMap__.js.map +1 -1
  103. package/out/concepts/New__.js.map +1 -1
  104. package/out/concepts/NullLiteral__.js.map +1 -1
  105. package/out/concepts/NumericLiteral__.js.map +1 -1
  106. package/out/concepts/OqlQueryComponent__.js +2 -0
  107. package/out/concepts/OqlQueryComponent__.js.map +1 -1
  108. package/out/concepts/Param__.js +1 -1
  109. package/out/concepts/Param__.js.map +1 -1
  110. package/out/concepts/Point__.js.map +1 -1
  111. package/out/concepts/ProcessComponent__.js.map +1 -1
  112. package/out/concepts/ProcessElement__.js.map +1 -1
  113. package/out/concepts/ProcessOutcome__.js.map +1 -1
  114. package/out/concepts/ProcessOutcomes__.js.map +1 -1
  115. package/out/concepts/Process__.js.map +1 -1
  116. package/out/concepts/QueryAggregateExpression__.js.map +1 -1
  117. package/out/concepts/QueryFieldExpression__.js.map +1 -1
  118. package/out/concepts/QueryFromExpression__.js.map +1 -1
  119. package/out/concepts/QueryGroupByExpression__.js.map +1 -1
  120. package/out/concepts/QueryJoinExpression__.js.map +1 -1
  121. package/out/concepts/QueryLimitExpression__.js.map +1 -1
  122. package/out/concepts/QueryOrderByExpression__.js.map +1 -1
  123. package/out/concepts/QuerySelectExpression__.js.map +1 -1
  124. package/out/concepts/Rect__.js.map +1 -1
  125. package/out/concepts/Return__.js.map +1 -1
  126. package/out/concepts/Role__.js.map +1 -1
  127. package/out/concepts/SelectMembers__.js.map +1 -1
  128. package/out/concepts/Slot__.js.map +1 -1
  129. package/out/concepts/SqlQueryComponent__.js.map +1 -1
  130. package/out/concepts/Start__.js.map +1 -1
  131. package/out/concepts/StringInterpolation__.js.map +1 -1
  132. package/out/concepts/StringLiteral__.js.map +1 -1
  133. package/out/concepts/StructureProperty__.js.map +1 -1
  134. package/out/concepts/Structure__.js.map +1 -1
  135. package/out/concepts/SwitchCase__.js.map +1 -1
  136. package/out/concepts/SwitchStatement__.js.map +1 -1
  137. package/out/concepts/Theme__.js.map +1 -1
  138. package/out/concepts/Transactional__.js.map +1 -1
  139. package/out/concepts/TypeAnnotation__.js.map +1 -1
  140. package/out/concepts/TypeParam__.js.map +1 -1
  141. package/out/concepts/UnaryExpression__.js.map +1 -1
  142. package/out/concepts/Unparsed__.js.map +1 -1
  143. package/out/concepts/UseComponent__.js.map +1 -1
  144. package/out/concepts/ValidationRule__.js.map +1 -1
  145. package/out/concepts/Variable__.js.map +1 -1
  146. package/out/concepts/ViewBlock__.js.map +1 -1
  147. package/out/concepts/ViewComponent__.js.map +1 -1
  148. package/out/concepts/ViewElement__.d.ts +1 -0
  149. package/out/concepts/ViewElement__.js +7 -0
  150. package/out/concepts/ViewElement__.js.map +1 -1
  151. package/out/concepts/View__.js +8 -3
  152. package/out/concepts/View__.js.map +1 -1
  153. package/out/concepts/WhileStatement__.js.map +1 -1
  154. package/out/config.d.ts +1 -1
  155. package/out/decorators/index.d.ts +2 -2
  156. package/out/generator/genReleaseBody.d.ts +1 -0
  157. package/out/generator/genReleaseBody.js +1 -0
  158. package/out/generator/genReleaseBody.js.map +1 -1
  159. package/out/generator/icestark.d.ts +2 -0
  160. package/out/generator/icestark.js +48 -0
  161. package/out/generator/icestark.js.map +1 -0
  162. package/out/generator/microApp.d.ts +2 -0
  163. package/out/generator/microApp.js +35 -0
  164. package/out/generator/microApp.js.map +1 -0
  165. package/out/generator/permission.d.ts +2 -1
  166. package/out/generator/permission.js +17 -8
  167. package/out/generator/permission.js.map +1 -1
  168. package/out/generator/qiankun.d.ts +2 -0
  169. package/out/generator/qiankun.js +52 -0
  170. package/out/generator/qiankun.js.map +1 -0
  171. package/out/index.d.ts +1 -1
  172. package/out/index.js +2 -1
  173. package/out/index.js.map +1 -1
  174. package/out/manager/stepRecorder.d.ts +20 -0
  175. package/out/manager/stepRecorder.js +110 -0
  176. package/out/manager/stepRecorder.js.map +1 -0
  177. package/out/sentry/index.d.ts +29 -0
  178. package/out/sentry/index.js +111 -0
  179. package/out/sentry/index.js.map +1 -0
  180. package/out/server/getMemberIdentifier.js +3 -2
  181. package/out/server/getMemberIdentifier.js.map +1 -1
  182. package/out/server/getProcesses.d.ts +3 -3
  183. package/out/server/getScope.d.ts +1 -1
  184. package/out/server/naslServer.d.ts +1 -1
  185. package/out/server/naslServer.js +22 -5
  186. package/out/server/naslServer.js.map +1 -1
  187. package/out/service/creator/add.configs.js +2 -0
  188. package/out/service/creator/add.configs.js.map +1 -1
  189. package/out/service/creator/errHandles.js +5 -0
  190. package/out/service/creator/errHandles.js.map +1 -1
  191. package/out/service/creator/index.js +2 -0
  192. package/out/service/creator/index.js.map +1 -1
  193. package/out/service/storage/api.d.ts +18 -0
  194. package/out/service/storage/api.js +12 -0
  195. package/out/service/storage/api.js.map +1 -1
  196. package/out/service/storage/init.d.ts +41 -1
  197. package/out/service/storage/init.js +172 -42
  198. package/out/service/storage/init.js.map +1 -1
  199. package/out/service/storage/service.d.ts +9 -1
  200. package/out/service/storage/service.js +27 -1
  201. package/out/service/storage/service.js.map +1 -1
  202. package/out/templator/genCreateBlock.js +1 -1
  203. package/out/templator/genCreateBlock.js.map +1 -1
  204. package/out/templator/genCurdEditMultipleKeyBlock.js +4 -4
  205. package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
  206. package/out/templator/genCurdMultipleKeyBlock.js +4 -5
  207. package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
  208. package/out/templator/genEditTableBlock.js +2 -2
  209. package/out/templator/genEditTableBlock.js.map +1 -1
  210. package/out/templator/genSelectBlock.js +1 -1
  211. package/out/templator/genTableBlock.js +2 -2
  212. package/out/templator/genTableBlock.js.map +1 -1
  213. package/out/templator/genUpdateBlock.js +1 -1
  214. package/out/templator/genUpdateBlock.js.map +1 -1
  215. package/out/translator/index.d.ts +1 -1
  216. package/out/translator/index.js +4 -1
  217. package/out/translator/index.js.map +1 -1
  218. package/out/translator/lsp.d.ts +3 -3
  219. package/out/utils/index.d.ts +4 -4
  220. package/package.json +2 -2
  221. package/sandbox/stdlib/nasl.oql.ts +4 -0
  222. package/src/automate/engine/operators.js +13 -5
  223. package/src/automate/template/myProcess.js +11451 -11452
  224. package/src/automate/upgrader/2.20.js +1 -0
  225. package/src/bak/translator.js +3 -3
  226. package/src/concepts/BindAttribute__.ts +7 -5
  227. package/src/concepts/BindDirective__.ts +7 -5
  228. package/src/concepts/BindStyle__.ts +7 -6
  229. package/src/concepts/CallInterface__.ts +34 -20
  230. package/src/concepts/CallLogic__.ts +3 -3
  231. package/src/concepts/ConfigGroup__.ts +2 -2
  232. package/src/concepts/DataSource__.ts +11 -7
  233. package/src/concepts/Destination__.ts +7 -7
  234. package/src/concepts/Interface__.ts +59 -7
  235. package/src/concepts/Logic__.ts +2 -2
  236. package/src/concepts/Match__.ts +77 -2
  237. package/src/concepts/NewComposite__.ts +20 -2
  238. package/src/concepts/OqlQueryComponent__.ts +2 -0
  239. package/src/concepts/Param__.ts +1 -1
  240. package/src/concepts/ViewElement__.ts +9 -1
  241. package/src/concepts/View__.ts +11 -8
  242. package/src/generator/genReleaseBody.ts +2 -1
  243. package/src/generator/permission.ts +17 -7
  244. package/src/index.ts +1 -1
  245. package/src/server/getMemberIdentifier.ts +5 -2
  246. package/src/server/naslServer.ts +17 -5
  247. package/src/service/creator/add.configs.js +3 -0
  248. package/src/service/creator/errHandles.js +6 -0
  249. package/src/service/creator/index.js +3 -0
  250. package/src/service/storage/api.js +12 -0
  251. package/src/service/storage/init.ts +204 -41
  252. package/src/service/storage/service.ts +29 -1
  253. package/src/templator/genCreateBlock.ts +1 -1
  254. package/src/templator/genCurdEditMultipleKeyBlock.ts +4 -4
  255. package/src/templator/genCurdMultipleKeyBlock.ts +4 -5
  256. package/src/templator/genEditTableBlock.ts +2 -2
  257. package/src/templator/genSelectBlock.ts +1 -1
  258. package/src/templator/genTableBlock.ts +2 -2
  259. package/src/templator/genUpdateBlock.ts +1 -1
  260. package/src/translator/index.ts +3 -1
  261. package/out/automate/engine/2.14-components.d.ts +0 -1115
  262. package/out/automate/engine/2.14-components.js +0 -1087
  263. package/out/automate/engine/2.14-components.js.map +0 -1
  264. package/yarn-error.log +0 -2087
@@ -3,6 +3,7 @@ import { ElementToVueOptions } from './ViewElement__';
3
3
  import MemberExpression from './MemberExpression__';
4
4
  import StructureProperty from './StructureProperty__';
5
5
  import App from './App__';
6
+ import { genHash } from '../generator';
6
7
  //================================================================================
7
8
  // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
8
9
  // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
@@ -1215,7 +1216,7 @@ export class NewComposite extends LogicItem {
1215
1216
  }
1216
1217
  });
1217
1218
  code += 'return {\n';
1218
- code += `__name: "AStructure_${this.typeAnnotation.hash}" as const,\n`;
1219
+ code += `__name: "AStructure_${genHash(JSON.stringify(this))}" as const,\n`;
1219
1220
  this.properties.forEach((property) => {
1220
1221
  code += `${property.name},\n`;
1221
1222
  });
@@ -1266,7 +1267,7 @@ export class NewComposite extends LogicItem {
1266
1267
  }
1267
1268
  });
1268
1269
  code += '\nreturn {\n';
1269
- code += `__name: "AStructure_${this.typeAnnotation.hash}" as const,\n`;
1270
+ code += `__name: "AStructure_${genHash(JSON.stringify(this))}" as const,\n`;
1270
1271
  this.properties.forEach((property) => {
1271
1272
  code += `${property.name},\n`;
1272
1273
  });
@@ -1279,9 +1280,23 @@ export class NewComposite extends LogicItem {
1279
1280
  return code;
1280
1281
  }
1281
1282
 
1283
+ __addIdentifier() {
1284
+ this.app.emit('collect:start', {
1285
+ actionMsg: '添加匿名数据结构属性',
1286
+ });
1287
+ const node = this.addIdentifier({ name: this.getIdentifierUniqueName('property1') });
1288
+ const struct = StructureProperty.from({
1289
+ name: node.name,
1290
+ typeAnnotation: null,
1291
+ });
1292
+ this.typeAnnotation.addStructureProperty(struct);
1293
+ this.app.emit('collect:end');
1294
+ }
1295
+
1282
1296
  __deleteIdentifier(property: Identifier) {
1283
1297
  const index = this.properties.findIndex((p) => p === property);
1284
1298
  const newLines: AssignmentLine[] = [];
1299
+ const newProperties = this.typeAnnotation.properties.filter((item) => item.name !== property.name);
1285
1300
  this.assignmentLines.forEach((line) => {
1286
1301
  const { leftIndex } = line;
1287
1302
  if (leftIndex[1] < index) {
@@ -1295,6 +1310,9 @@ export class NewComposite extends LogicItem {
1295
1310
  actionMsg: '删除匿名数据结属性',
1296
1311
  });
1297
1312
  this.setAssignmentLines(newLines);
1313
+ this.typeAnnotation.update({
1314
+ properties: newProperties,
1315
+ });
1298
1316
  property.delete();
1299
1317
  this.app.emit('collect:end');
1300
1318
  }
@@ -339,6 +339,8 @@ export class OqlQueryComponent extends LogicItem {
339
339
  },
340
340
  }).then((res: any) => {
341
341
  this.codeSourceMap = res || { typescript: '', lexicalErrorCode: 1001 };
342
+ }).catch(() => {
343
+ this.codeSourceMap = { typescript: '', lexicalErrorCode: 1001 };
342
344
  });
343
345
  } else {
344
346
  this.codeSourceMap = { typescript: '', lexicalErrorCode: 1001 };
@@ -302,7 +302,7 @@ export class Param extends BaseNode {
302
302
  parsedValue = tryJSONParse(defaultValue) ?? defaultValue;
303
303
  }
304
304
  }
305
- code += `${this.name} || (this.$route.query.hasOwnProperty('${this.name}') ? this.$genInitFromSchema('${typeAnnotation?.sortedTypeKey}', this.$route.query.${this.name}) : ${JSON.stringify(this.defaultValue)})`;
305
+ code += `${this.name} !== undefined ? ${this.name} : (this.$route.query.hasOwnProperty('${this.name}') ? this.$genInitFromSchema('${typeAnnotation?.sortedTypeKey}', this.$route.query.${this.name}) : ${JSON.stringify(this.defaultValue)})`;
306
306
 
307
307
  if (needGenInitFromSchema) {
308
308
  code += `)`;
@@ -1079,7 +1079,7 @@ export class ViewElement extends BaseNode {
1079
1079
  }
1080
1080
 
1081
1081
 
1082
-
1082
+
1083
1083
 
1084
1084
  /**
1085
1085
  * 删除元素绑定属性
@@ -1348,6 +1348,10 @@ export class ViewElement extends BaseNode {
1348
1348
  return `${this.view.path}/${this.name}`;
1349
1349
  }
1350
1350
 
1351
+ get auth() {
1352
+ return this.bindDirectives.find((directive) => directive.name === 'auth');
1353
+ }
1354
+
1351
1355
  getViewElementUniqueName(name = 'viewElement1') {
1352
1356
  return this.view?.getViewElementUniqueName(name);
1353
1357
  }
@@ -2141,6 +2145,10 @@ export class ViewElement extends BaseNode {
2141
2145
  }
2142
2146
  });
2143
2147
  }
2148
+ // 部分组件增加 key 唯一标识,防止 vue 判断重复节点,导致渲染异常
2149
+ if (this.name && ['u-table-view', 'u-list-view', 'u-grid-view', 'u-list-components', 'u-form', 'u-select'].includes(this.tag)) {
2150
+ this.name && parts.push(`key="${this.name}"`);
2151
+ }
2144
2152
 
2145
2153
  let partsLength = 0;
2146
2154
  let partsString = '';
@@ -2021,12 +2021,15 @@ export class View extends BaseNode {
2021
2021
  this.elements.forEach((item) => {
2022
2022
  utils.traverse((current) => {
2023
2023
  const { node } = current as any;
2024
- // 处理三种情况
2025
- if (
2026
- ['BindAttribute', 'BindDirective', 'BindStyle'].includes(node.concept)
2027
- && node.needReplaceWithIdentifier
2028
- ) {
2029
- bindExpressions.push(node);
2024
+ //// 处理三种情况
2025
+ //if (
2026
+ // ['BindAttribute', 'BindDirective', 'BindStyle'].includes(node.concept)
2027
+ // && node.needReplaceWithIdentifier
2028
+ //) {
2029
+ // bindExpressions.push(node);
2030
+ //}
2031
+ if (node.concept === 'Match') {
2032
+ bindExpressions.push(node as Match);
2030
2033
  }
2031
2034
  }, {
2032
2035
  node: item,
@@ -2237,8 +2240,8 @@ export class View extends BaseNode {
2237
2240
  return code;
2238
2241
  }
2239
2242
 
2240
- getViewCallLogics():string[] {
2241
- const callbackLogics :string[] = [];
2243
+ getViewCallLogics(): string[] {
2244
+ const callbackLogics: string[] = [];
2242
2245
  this.traverseChildren((el) => {
2243
2246
  if (el instanceof Identifier && el.namespace?.endsWith('logics')) {
2244
2247
  callbackLogics.push(el.namespace + '.' + el.name);
@@ -1,6 +1,6 @@
1
1
  import { App, Assignment, BatchAssignment, CallFunction, CallInterface, CallLogic, ForEachStatement, IfStatement, Logic, LogicItem, Match, MatchCase, MemberExpression, Role, SwitchCase, SwitchStatement, View, ViewElement, WhileStatement, StringInterpolation, Frontend, ExternalDestination, NewComposite, SelectMembers, NewList } from '../concepts';
2
2
  import { genFrontendBundleFiles } from './genBundleFiles';
3
- import { genPermissionData } from './permission';
3
+ import { genPermissionData, genLogicAuthFlag } from './permission';
4
4
  import * as utils from '../utils';
5
5
 
6
6
  export async function genReleaseBody(app: App, {
@@ -47,6 +47,7 @@ export async function genReleaseBody(app: App, {
47
47
  const body = {
48
48
  ...authReport, // 如果发布需要上报权限,导出源码不需要
49
49
  logicPageResourceDtoList,
50
+ logicAuthFlag: genLogicAuthFlag(app),
50
51
  noAuthApiPathList: getAuthApiPathList(app, frontends),
51
52
  reportIdList: findAllReportIdList(app, frontends),
52
53
  appId: app.id,
@@ -102,13 +102,11 @@ function findResourcesOfUI(view: View | ViewElement) {
102
102
  path: node.authPath,
103
103
  type: 'page',
104
104
  });
105
- else if (node instanceof ViewElement) {
106
- const hasAuth = node.bindDirectives.find((directive) => directive.name === 'auth');
107
- if (hasAuth)
108
- res.push({
109
- path: node.authPath,
110
- type: 'component',
111
- });
105
+ else if (node instanceof ViewElement && node.auth) {
106
+ res.push({
107
+ path: node.authPath,
108
+ type: 'component',
109
+ });
112
110
  }
113
111
  node = node.parentNode;
114
112
  }
@@ -275,3 +273,15 @@ export async function genPermissionData(app: App) {
275
273
  // console.timeEnd('xxx');
276
274
  return logicPageResourceDtoList;
277
275
  }
276
+
277
+ export function genLogicAuthFlag(app: App) {
278
+ let flag = false;
279
+ app.traverseChildren((node) => {
280
+ if(flag) return;
281
+
282
+ if((node instanceof View || node instanceof ViewElement) && node.auth)
283
+ flag = true;
284
+ });
285
+
286
+ return flag;
287
+ }
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { EventEmitter, EventPayload, BaseNode } from './common';
2
2
  export * from './concepts';
3
- export { genBundleFiles, genFrontendBundleFiles, genMetaData, genReleaseBody, genPermissionData } from './generator';
3
+ export { genBundleFiles, genFrontendBundleFiles, genMetaData, genReleaseBody, genPermissionData, genLogicAuthFlag } from './generator';
4
4
  export * from './translator';
5
5
  // export { default as diagnosticManager } from './manager/diagnostic';
6
6
  export { default as server, NaslServer } from './server';
@@ -150,8 +150,11 @@ function getCurrentLogic(node: BaseNode,
150
150
  expanded: boolean;
151
151
  icon: string;
152
152
  }[]) {
153
- // 只有data-source可以
154
- if (node instanceof Identifier && node.parentNode instanceof BindAttribute && (node.parentNode.name === 'data-source' || node.parentNode.name === 'check-file')) {
153
+ // 只有data-source check-file可以
154
+ if (
155
+ (node instanceof BindAttribute && (node.name === 'data-source' || node.name === 'check-file'))
156
+ || (node instanceof Identifier && node.parentNode instanceof BindAttribute && (node.parentNode.name === 'data-source' || node.parentNode.name === 'check-file'))
157
+ ) {
155
158
  const view = node.view;
156
159
  const viewLogics = view.logics;
157
160
  const logicVariable = viewLogics.map((item) => {
@@ -214,6 +214,9 @@ export class NaslServer {
214
214
  if (data && data.event === 'publishDiagnostics') {
215
215
  const records = await this._resolveDiagnosticRecords(data.records);
216
216
  this.diagnosticManager.pushAll(records);
217
+ try {
218
+ invokeCommand('naslServer:nodeChange');
219
+ } catch (e) { console.log('no "naslServer:nodeChange" event received'); }
217
220
  }
218
221
  },
219
222
  });
@@ -1679,8 +1682,8 @@ export class NaslServer {
1679
1682
  const diagnostic = {
1680
1683
  node,
1681
1684
  severity: 'error',
1682
- message: '匹配分支:表达式不能为空',
1683
- titleTip: '表达式不能为空',
1685
+ message: '匹配分支:返回内容不能为空',
1686
+ titleTip: '返回内容不能为空',
1684
1687
  };
1685
1688
  node.tsErrorDetail = diagnostic;
1686
1689
  diagnostics.push(diagnostic);
@@ -1792,11 +1795,16 @@ export class NaslServer {
1792
1795
  'nasl.collection.Map<nasl.core.String, nasl.core.String>',
1793
1796
  'nasl.collection.Map<nasl.core.String, nasl.core.Text>',
1794
1797
  'nasl.collection.Map<nasl.core.String, nasl.core.Email>',
1798
+ ];
1799
+ const excludeList2 = [
1795
1800
  'nasl.collection.List<>',
1801
+ 'nasl.collection.List<T>',
1796
1802
  ];
1797
1803
  // 先特殊处理等 类型合并后就可以去掉了
1798
1804
  if (excludeList.includes(leftType.sortedTypeKey) && excludeList.includes(rightType.sortedTypeKey)) {
1799
1805
  return null;
1806
+ } else if (excludeList2.includes(leftType.sortedTypeKey) || excludeList2.includes(rightType.sortedTypeKey)) {
1807
+ return null;
1800
1808
  }
1801
1809
  const diagnostic = {
1802
1810
  node: node.right,
@@ -3056,7 +3064,11 @@ export class NaslServer {
3056
3064
  }
3057
3065
  } else if (node.concept === 'Match') {
3058
3066
  // 去查return 后面的返回值,变成函数调用
3059
- fileDetail.line = item.range.end.line - 1;
3067
+ if (item.code?.endsWith(';\n')) {
3068
+ fileDetail.line = item.range.end.line - 1;
3069
+ } else {
3070
+ fileDetail.line = item.range.end.line;
3071
+ }
3060
3072
  const indexOf = item.code.indexOf('return __MatchExpressionFuntion');
3061
3073
  let newCode = item.code.substring(0, indexOf);
3062
3074
  newCode = newCode.substring(newCode.lastIndexOf('\n'), indexOf);
@@ -3108,8 +3120,8 @@ export class NaslServer {
3108
3120
  // 直接从最后一项的返回值取,有就有没有就没有
3109
3121
  if (node.body?.length) {
3110
3122
  const last = node.body[node.body.length - 1];
3111
- if (last.__TypeAnnotation) {
3112
- types.set(node, last.__TypeAnnotation);
3123
+ if (types.get(last)) {
3124
+ types.set(node, types.get(last));
3113
3125
  }
3114
3126
  }
3115
3127
  }
@@ -22,6 +22,9 @@ function httpCode(response, params, requestInfo) {
22
22
  }
23
23
 
24
24
  function shortResponse(response, params, requestInfo) {
25
+ if(params === false)
26
+ return response;
27
+
25
28
  if (response.data && response.data.result !== undefined) {
26
29
  return response.data.result;
27
30
  } else {
@@ -32,6 +32,12 @@ export default {
32
32
  return;
33
33
  }
34
34
 
35
+ // 检测到当前应用已在新 tab 页打开
36
+ if(err.code === 500502) {
37
+ eventBus.emit('multiTabOpened');
38
+ return;
39
+ }
40
+
35
41
  if (versionStatus[err.code])
36
42
  eventBus.emit('updateVersionStatus', {
37
43
  status: versionStatus[err.code],
@@ -48,6 +48,9 @@ const requester = function (requestInfo) {
48
48
  withCredentials: !baseURL,
49
49
  };
50
50
 
51
+ if(config.timeout)
52
+ requestOptions.timeout = config.timeout;
53
+
51
54
  if (aslConfig.debugRequestAll || (aslConfig.debugRequest && requestOptions.method !== 'GET')) {
52
55
  console.debug('[Request Debug]', requestOptions);
53
56
  }
@@ -11,4 +11,16 @@ export default {
11
11
  path: '/proxy/nasl-storage/api/storage/batchAction',
12
12
  },
13
13
  },
14
+ batchInstruct: {
15
+ url: {
16
+ method: 'post',
17
+ path: '/proxy/nasl-storage/api/storage/batchInstruct',
18
+ },
19
+ },
20
+ saveFrontendNasl: {
21
+ url: {
22
+ method: 'post',
23
+ path: '/proxy/nasl-storage/api/storage/saveFrontendNasl',
24
+ },
25
+ },
14
26
  };
@@ -3,6 +3,7 @@ import { getConceptConstructor } from '../../decorators';
3
3
  import { config } from '../../config';
4
4
  import Vue from 'vue';
5
5
  import storageService from './service';
6
+ import { v4 as uuidv4 } from 'uuid';
6
7
  /// #if !process.env.NODE_ENV || process.env.BUILD_TARGET === 'node'
7
8
  import * as fs from 'fs-extra';
8
9
  import * as jsoner from './jsoner';
@@ -10,6 +11,9 @@ import * as jsoner from './jsoner';
10
11
 
11
12
  export const batchQuery = storageService.batchQuery;
12
13
  export const batchAction = storageService.batchAction;
14
+ export const batchInstruct = storageService.batchInstruct;
15
+
16
+ let tabTimestamp: string;
13
17
 
14
18
  function getLogic(key: string, app: any, diffLogicList: string[]) {
15
19
  if (!diffLogicList.includes(key)) {
@@ -123,7 +127,6 @@ function getMiniAppChange(target: any, obj: any, action: string) {
123
127
  * 执行更新
124
128
  */
125
129
  async function doAction(app: any, actionItem: any) {
126
- app.emit('saving');
127
130
  let hasFrontEnd = false;
128
131
  let hasBackEnd = false;
129
132
  const actionList: any[] = [];
@@ -265,9 +268,186 @@ async function doAction(app: any, actionItem: any) {
265
268
  }
266
269
  } catch (error) {
267
270
  console.log(error);
271
+ taskQueue.refreshNasl(app, {
272
+ errorInfo: {
273
+ message: error?.message,
274
+ stack: error?.stack,
275
+ },
276
+ });
277
+ return;
278
+ }
279
+
280
+ const instructList = [{
281
+ uuid: uuidv4().replace(/-/g, ''),
282
+ actions: actionList,
283
+ }];
284
+ saveNasl({app, hasFrontEnd, hasBackEnd, instructList });
285
+
286
+ if (!app._historying) {
287
+ if (app._historyIndex !== app._historyList.length) {
288
+ app._historyList = app._historyList.splice(0, app._historyIndex);
289
+ }
290
+ app._historyList.push({
291
+ actionMsg,
292
+ list: list.map((item: any) => item.originEvent),
293
+ });
294
+ app._historyIndex = app._historyList.length;
295
+ } else {
296
+ const actionMap = {
297
+ undo: '已撤销操作:',
298
+ redo: '已重做操作:',
299
+ };
300
+ let msg = actionMap[action as 'undo' | 'redo'];
301
+ msg += actionMsg;
302
+ Vue.prototype.$toast.info(msg);
303
+ app._historying = false;
304
+ }
305
+ }
306
+
307
+ type Instruct = {
308
+ uuid: string,
309
+ actions: any[],
310
+ };
311
+ type TaskOption = {
312
+ app: any,
313
+ hasFrontEnd: boolean,
314
+ hasBackEnd: boolean,
315
+ instructList: Instruct[],
316
+ };
317
+ enum TaskQueueStatus {
318
+ ExceedMaxTaskCount,
319
+ Retrying,
320
+ };
321
+ type RefreshNaslOptions = {
322
+ errorInfo: {
323
+ message?: string,
324
+ stack?: string,
325
+ }
326
+ };
327
+
328
+ class TaskQueue {
329
+ queue: TaskOption[] = []
330
+ lastQueue: TaskOption[] = []
331
+ running: Boolean = false
332
+ maxTaskCount: number = 10
333
+ status?: TaskQueueStatus = undefined
334
+
335
+ addTask(task: TaskOption) {
336
+ this.queue.push(task);
337
+
338
+ if(this.queue.length >= this.maxTaskCount) {
339
+ this.status = TaskQueueStatus.ExceedMaxTaskCount;
340
+ task.app.emit('ExceedMaxTaskCount');
341
+ }
342
+
343
+ this.run();
344
+ }
345
+
346
+ clear() {
347
+ this.queue = [];
348
+ this.lastQueue = [];
349
+ this.status = undefined;
350
+ this.running = false;
351
+ }
352
+
353
+ async run(queue = this.queue) {
354
+ if(this.running) return;
355
+ if(queue.length === 0) return;
356
+
357
+ const app = queue[0].app;
358
+ let hasFrontEnd = false;
359
+ let hasBackEnd = false;
360
+ let instructList: Instruct[] = [];
361
+
362
+ for(const task of queue) {
363
+ if(task.hasFrontEnd) hasFrontEnd = true;
364
+ if(task.hasBackEnd) hasBackEnd = true;
365
+ instructList = instructList.concat(task.instructList);
366
+ }
367
+
368
+ if(queue === this.queue) {
369
+ this.lastQueue = [...queue];
370
+ this.queue = [];
371
+ }
372
+
373
+ this.running = true;
374
+ const error = await _saveNasl({
375
+ app, hasFrontEnd, hasBackEnd, instructList,
376
+ });
377
+
378
+ // code: 401650, 检测到当前应用拉取操作已被强制结束, 用户确认后再刷新
379
+ // code: 500502 msg: "该应用已在新tab 页打开,请刷新!" 不重试或刷新
380
+ if(!error)
381
+ this.recover(app);
382
+ else if (![401650, 500502].includes(error.code)) {
383
+ // 连接失败,或超时,或后端持久化异常
384
+ if((error.message === 'Network Error' || error.message?.includes('timeout') || error.code === 500500)
385
+ && this.status !== TaskQueueStatus.Retrying) {
386
+ this.running = false;
387
+ this.retry();
388
+ } else
389
+ this.refreshNasl(app);
390
+
391
+ return;
392
+ }
393
+
394
+ this.running = false;
395
+
396
+ this.run();
397
+ }
398
+
399
+ retry() {
400
+ if(this.lastQueue.length === 0) return;
401
+
402
+ const app = this.lastQueue[0].app;
403
+ this.status = TaskQueueStatus.Retrying;
404
+ app.emit('Retrying');
405
+ this.run(this.lastQueue);
406
+ }
407
+
408
+ async refreshNasl(app: App, options: RefreshNaslOptions = { errorInfo: {} }) {
409
+ const failedQueue = this.lastQueue.map(({ hasFrontEnd, hasBackEnd, instructList }) => ({
410
+ hasFrontEnd, hasBackEnd, instructList,
411
+ }));
412
+ const queue = this.queue.map(({ hasFrontEnd, hasBackEnd, instructList }) => ({
413
+ hasFrontEnd, hasBackEnd, instructList,
414
+ }));
415
+ await storageService.saveFrontendNasl({
416
+ body: {
417
+ nasl: app.toJSON(),
418
+ failedQueue,
419
+ queue,
420
+ errorInfo: options.errorInfo,
421
+ },
422
+ }).catch((err: any) => {
423
+ console.log('备份 nasl 失败:', err);
424
+ });
425
+ this.clear();
268
426
  app.emit('refresh');
269
427
  }
270
428
 
429
+ recover(app: App) {
430
+ switch(this.status) {
431
+ case TaskQueueStatus.ExceedMaxTaskCount:
432
+ app.emit('BelowMaxTaskCount');
433
+ this.status = undefined;
434
+ break;
435
+ case TaskQueueStatus.Retrying:
436
+ app.emit('SuccessRetry');
437
+ this.status = undefined;
438
+ break;
439
+ }
440
+ }
441
+ }
442
+
443
+ export const taskQueue = new TaskQueue();
444
+ async function saveNasl(options: TaskOption) {
445
+ taskQueue.addTask(options);
446
+ }
447
+
448
+ async function _saveNasl(options: TaskOption) {
449
+ const { app, hasFrontEnd, hasBackEnd, instructList } = options;
450
+ app.emit('saving');
271
451
  let ChangedNASLType = '';
272
452
  if (hasFrontEnd && hasBackEnd) {
273
453
  ChangedNASLType = 'both';
@@ -279,50 +459,35 @@ async function doAction(app: any, actionItem: any) {
279
459
  let err;
280
460
  if (config.storage.protocol === 'http') {
281
461
  try {
282
- await storageService.batchAction({
283
- body: actionList,
462
+ await storageService.batchInstruct({
463
+ body: instructList,
284
464
  headers: {
285
465
  appId: app.id,
286
466
  ChangedNASLType,
467
+ tabTimestamp,
287
468
  // 其他封装在 storageService 里了
288
469
  },
289
470
  });
290
471
  } catch (error) {
291
472
  err = error;
292
-
293
- // 401650, 检测到当前应用拉取操作已被强制结束, 用户确认后再刷新
294
- if (error?.code !== 401650)
295
- app.emit('refresh');
296
473
  }
297
474
  } else if (config.storage.protocol === 'mock') {
298
475
  // Do nothing
299
476
  } else {
300
477
  const json = await fs.readJSON(config.storage.basePath);
478
+
479
+ let actionList: any[] = [];
480
+ for(const { actions } of instructList) {
481
+ actionList = actionList.concat(actions);
482
+ }
483
+
301
484
  jsoner.batchAction(json, actionList);
302
485
  await fs.writeJSON(config.storage.basePath, json, {
303
486
  spaces: 4,
304
487
  });
305
488
  }
306
489
  app.emit('saved', err);
307
- if (!app._historying) {
308
- if (app._historyIndex !== app._historyList.length) {
309
- app._historyList = app._historyList.splice(0, app._historyIndex);
310
- }
311
- app._historyList.push({
312
- actionMsg,
313
- list: list.map((item: any) => item.originEvent),
314
- });
315
- app._historyIndex = app._historyList.length;
316
- } else {
317
- const actionMap = {
318
- undo: '已撤销操作:',
319
- redo: '已重做操作:',
320
- };
321
- let msg = actionMap[action as 'undo' | 'redo'] || '';
322
- msg += actionMsg;
323
- Vue.prototype.$toast.info(msg);
324
- app._historying = false;
325
- }
490
+ return err;
326
491
  }
327
492
 
328
493
  export function handleApp(app: any) {
@@ -354,7 +519,11 @@ export function handleApp(app: any) {
354
519
  if (!app._noTimer) {
355
520
  app._timer = setTimeout(() => {
356
521
  console.error('收集超时,请及时排查原因');
357
- app.emit('refresh');
522
+ taskQueue.refreshNasl(app, {
523
+ errorInfo: {
524
+ message: '收集超时,请及时排查原因',
525
+ }
526
+ });
358
527
  }, 2500);
359
528
  }
360
529
  if (!app._isCollectingCount) {
@@ -443,7 +612,7 @@ export async function loadApp(appId?: string) {
443
612
  let app: App;
444
613
  if (config.storage.protocol === 'http') {
445
614
  // 请求
446
- const data = await storageService.batchQuery({
615
+ const res = await storageService.batchQuery({
447
616
  body: [
448
617
  {
449
618
  path: 'app',
@@ -452,22 +621,16 @@ export async function loadApp(appId?: string) {
452
621
  ],
453
622
  headers: {
454
623
  appId,
624
+ checkTabOpenTime: 'true',
455
625
  // 其他封装在 storageService 里了
456
626
  },
627
+ config: {
628
+ shortResponse: false,
629
+ },
457
630
  });
458
- // const data = res?.data?.result;
459
- // // mock数据,需要删除
460
- // data[0].frontends = [];
461
- // data?.[0].frontends.push({
462
- // id: '111',
463
- // concept: 'Frontend',
464
- // name: 'pcFrontend1',
465
- // title: 'pc端',
466
- // type: 'pc',
467
- // views: data?.[0].views,
468
- // variables: data?.[0].frontendVariables,
469
- // componentDependencies: data?.[0].componentDependencies,
470
- // });
631
+
632
+ tabTimestamp = res?.headers?.tabtimestamp;
633
+ const data = res?.data?.result;
471
634
  app = new App(Object.assign(data?.[0], { id: appId }));
472
635
  } else if (config.storage.protocol === 'mock') {
473
636
  app = new App({