@lcap/nasl 3.8.0-beta.6 → 3.8.0-beta.7

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 (206) hide show
  1. package/.mocharc.js +1 -0
  2. package/out/common/BaseNode.d.ts +19 -3
  3. package/out/common/BaseNode.js +85 -7
  4. package/out/common/BaseNode.js.map +1 -1
  5. package/out/concepts/AbstractInterface__.js.map +1 -1
  6. package/out/concepts/Annotation__.js +1 -1
  7. package/out/concepts/Annotation__.js.map +1 -1
  8. package/out/concepts/App__.d.ts +3 -0
  9. package/out/concepts/App__.js +964 -4
  10. package/out/concepts/App__.js.map +1 -1
  11. package/out/concepts/Argument__.js +3 -3
  12. package/out/concepts/Argument__.js.map +1 -1
  13. package/out/concepts/BatchAssignment__.d.ts +1 -1
  14. package/out/concepts/BatchAssignment__.js +2 -2
  15. package/out/concepts/BatchAssignment__.js.map +1 -1
  16. package/out/concepts/BindAttribute__.js +3 -4
  17. package/out/concepts/BindAttribute__.js.map +1 -1
  18. package/out/concepts/BindDirective__.js +3 -4
  19. package/out/concepts/BindDirective__.js.map +1 -1
  20. package/out/concepts/BusinessComponent__.d.ts +2 -0
  21. package/out/concepts/BusinessComponent__.js +48 -0
  22. package/out/concepts/BusinessComponent__.js.map +1 -1
  23. package/out/concepts/BusinessLogic__.d.ts +1 -0
  24. package/out/concepts/BusinessLogic__.js +10 -0
  25. package/out/concepts/BusinessLogic__.js.map +1 -1
  26. package/out/concepts/CallEvent__.d.ts +2 -0
  27. package/out/concepts/CallEvent__.js +75 -0
  28. package/out/concepts/CallEvent__.js.map +1 -1
  29. package/out/concepts/CallInterface__.d.ts +1 -0
  30. package/out/concepts/CallInterface__.js +26 -15
  31. package/out/concepts/CallInterface__.js.map +1 -1
  32. package/out/concepts/CallLogic__.d.ts +4 -0
  33. package/out/concepts/CallLogic__.js +59 -3
  34. package/out/concepts/CallLogic__.js.map +1 -1
  35. package/out/concepts/Entity__.d.ts +3 -3
  36. package/out/concepts/Entity__.js +4 -0
  37. package/out/concepts/Entity__.js.map +1 -1
  38. package/out/concepts/Event__.d.ts +2 -0
  39. package/out/concepts/Event__.js +30 -0
  40. package/out/concepts/Event__.js.map +1 -1
  41. package/out/concepts/FrontendType__.d.ts +2 -0
  42. package/out/concepts/FrontendType__.js +32 -0
  43. package/out/concepts/FrontendType__.js.map +1 -1
  44. package/out/concepts/Frontend__.d.ts +2 -0
  45. package/out/concepts/Frontend__.js +48 -0
  46. package/out/concepts/Frontend__.js.map +1 -1
  47. package/out/concepts/IfStatement__.js +6 -6
  48. package/out/concepts/IfStatement__.js.map +1 -1
  49. package/out/concepts/InterfaceParam__.d.ts +1 -0
  50. package/out/concepts/InterfaceParam__.js +23 -4
  51. package/out/concepts/InterfaceParam__.js.map +1 -1
  52. package/out/concepts/Interface__.d.ts +2 -1
  53. package/out/concepts/Interface__.js +29 -5
  54. package/out/concepts/Interface__.js.map +1 -1
  55. package/out/concepts/JSBlock__.d.ts +1 -0
  56. package/out/concepts/JSBlock__.js +6 -0
  57. package/out/concepts/JSBlock__.js.map +1 -1
  58. package/out/concepts/LogicDeclaration__.d.ts +1 -0
  59. package/out/concepts/LogicDeclaration__.js +58 -7
  60. package/out/concepts/LogicDeclaration__.js.map +1 -1
  61. package/out/concepts/Logic__.js +32 -22
  62. package/out/concepts/Logic__.js.map +1 -1
  63. package/out/concepts/MatchCase__.js +1 -2
  64. package/out/concepts/MatchCase__.js.map +1 -1
  65. package/out/concepts/Match__.js +3 -18
  66. package/out/concepts/Match__.js.map +1 -1
  67. package/out/concepts/MemberExpression__.js +1 -1
  68. package/out/concepts/MemberExpression__.js.map +1 -1
  69. package/out/concepts/Module__.d.ts +2 -0
  70. package/out/concepts/Module__.js +64 -0
  71. package/out/concepts/Module__.js.map +1 -1
  72. package/out/concepts/NewComposite__.d.ts +1 -1
  73. package/out/concepts/NewComposite__.js +2 -2
  74. package/out/concepts/NewComposite__.js.map +1 -1
  75. package/out/concepts/Paginate__.d.ts +1 -0
  76. package/out/concepts/Paginate__.js +15 -7
  77. package/out/concepts/Paginate__.js.map +1 -1
  78. package/out/concepts/QueryFromExpression__.js +2 -2
  79. package/out/concepts/QueryFromExpression__.js.map +1 -1
  80. package/out/concepts/StringLiteral__.js +3 -4
  81. package/out/concepts/StringLiteral__.js.map +1 -1
  82. package/out/concepts/TypeAnnotation__.js +1 -0
  83. package/out/concepts/TypeAnnotation__.js.map +1 -1
  84. package/out/concepts/ViewElement__.d.ts +2 -0
  85. package/out/concepts/ViewElement__.js +8 -5
  86. package/out/concepts/ViewElement__.js.map +1 -1
  87. package/out/concepts/View__.d.ts +1 -0
  88. package/out/concepts/View__.js +55 -1
  89. package/out/concepts/View__.js.map +1 -1
  90. package/out/generator/genBundleFiles.js +14 -11
  91. package/out/generator/genBundleFiles.js.map +1 -1
  92. package/out/generator/genHash.d.ts +2 -2
  93. package/out/generator/genHash.js +30 -30
  94. package/out/generator/genHash.js.map +1 -1
  95. package/out/generator/permission.d.ts +8 -1
  96. package/out/generator/permission.js +321 -23
  97. package/out/generator/permission.js.map +1 -1
  98. package/out/generator/release-body/body.js +18 -4
  99. package/out/generator/release-body/body.js.map +1 -1
  100. package/out/generator/release-body/data.js +6 -2
  101. package/out/generator/release-body/data.js.map +1 -1
  102. package/out/generator/release-body/utils.js +3 -3
  103. package/out/generator/release-body/utils.js.map +1 -1
  104. package/out/generator/release-body/validation.js +2 -2
  105. package/out/generator/release-body/validation.js.map +1 -1
  106. package/out/index.d.ts +1 -1
  107. package/out/index.js.map +1 -1
  108. package/out/natural/genNaturalTS.d.ts +2 -2
  109. package/out/natural/genNaturalTS.js +7 -7
  110. package/out/natural/genNaturalTS.js.map +1 -1
  111. package/out/natural/getContext/index.d.ts +1 -1
  112. package/out/natural/getContext/index.js +15 -9
  113. package/out/natural/getContext/index.js.map +1 -1
  114. package/out/natural/transformTS2UI.js +30 -11
  115. package/out/natural/transformTS2UI.js.map +1 -1
  116. package/out/natural/transformTSCode.js +30 -11
  117. package/out/natural/transformTSCode.js.map +1 -1
  118. package/out/server/entity2LogicNamespace.d.ts +2 -2
  119. package/out/server/entity2LogicNamespace.js +321 -310
  120. package/out/server/entity2LogicNamespace.js.map +1 -1
  121. package/out/server/extendBaseNode.js +25 -0
  122. package/out/server/extendBaseNode.js.map +1 -1
  123. package/out/server/naslServer.d.ts +1 -1
  124. package/out/server/naslServer.js +23 -16
  125. package/out/server/naslServer.js.map +1 -1
  126. package/out/server/translator.js +12 -0
  127. package/out/server/translator.js.map +1 -1
  128. package/out/templator/genCreateBlock.js +3 -3
  129. package/out/templator/genCreateBlock.js.map +1 -1
  130. package/out/templator/genCurdEditMultipleKeyBlock.js +2 -2
  131. package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
  132. package/out/templator/genCurdMultipleKeyBlock.js +4 -4
  133. package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
  134. package/out/templator/genEditTableBlock.js +1 -1
  135. package/out/templator/genEditTableBlock.js.map +1 -1
  136. package/out/templator/genGetBlock.js.map +1 -1
  137. package/out/templator/genGridViewBlock.js.map +1 -1
  138. package/out/templator/genSelectBlock.js.map +1 -1
  139. package/out/templator/genTableBlock.js.map +1 -1
  140. package/out/templator/genUpdateBlock.js +3 -3
  141. package/out/templator/genUpdateBlock.js.map +1 -1
  142. package/out/templator/utils.js +1 -1
  143. package/out/templator/utils.js.map +1 -1
  144. package/package.json +5 -5
  145. package/src/common/BaseNode.ts +91 -11
  146. package/src/concepts/AbstractInterface__.ts +1 -0
  147. package/src/concepts/Annotation__.ts +1 -1
  148. package/src/concepts/App__.ts +104 -4
  149. package/src/concepts/Argument__.ts +3 -3
  150. package/src/concepts/BatchAssignment__.ts +2 -2
  151. package/src/concepts/BindAttribute__.ts +3 -4
  152. package/src/concepts/BindDirective__.ts +3 -4
  153. package/src/concepts/BusinessComponent__.ts +54 -1
  154. package/src/concepts/BusinessLogic__.ts +10 -1
  155. package/src/concepts/CallEvent__.ts +66 -0
  156. package/src/concepts/CallInterface__.ts +21 -9
  157. package/src/concepts/CallLogic__.ts +59 -3
  158. package/src/concepts/Entity__.ts +7 -1
  159. package/src/concepts/Event__.ts +32 -0
  160. package/src/concepts/FrontendType__.ts +34 -1
  161. package/src/concepts/Frontend__.ts +51 -0
  162. package/src/concepts/IfStatement__.ts +6 -6
  163. package/src/concepts/InterfaceParam__.ts +23 -4
  164. package/src/concepts/Interface__.ts +29 -5
  165. package/src/concepts/JSBlock__.ts +5 -0
  166. package/src/concepts/LogicDeclaration__.ts +65 -7
  167. package/src/concepts/Logic__.ts +34 -25
  168. package/src/concepts/MatchCase__.ts +1 -2
  169. package/src/concepts/Match__.ts +3 -21
  170. package/src/concepts/MemberExpression__.ts +1 -1
  171. package/src/concepts/Module__.ts +75 -0
  172. package/src/concepts/NewComposite__.ts +2 -2
  173. package/src/concepts/Paginate__.ts +14 -7
  174. package/src/concepts/QueryFromExpression__.ts +2 -2
  175. package/src/concepts/StringLiteral__.ts +3 -4
  176. package/src/concepts/TypeAnnotation__.ts +1 -0
  177. package/src/concepts/ViewElement__.ts +9 -5
  178. package/src/concepts/View__.ts +56 -1
  179. package/src/generator/genBundleFiles.ts +14 -11
  180. package/src/generator/genHash.ts +32 -6
  181. package/src/generator/permission.ts +333 -23
  182. package/src/generator/release-body/body.ts +24 -5
  183. package/src/generator/release-body/data.ts +7 -2
  184. package/src/generator/release-body/utils.ts +3 -3
  185. package/src/generator/release-body/validation.ts +1 -1
  186. package/src/index.ts +13 -1
  187. package/src/natural/genNaturalTS.ts +9 -7
  188. package/src/natural/getContext/index.ts +17 -11
  189. package/src/natural/transformTS2UI.ts +28 -11
  190. package/src/natural/transformTSCode.ts +28 -11
  191. package/src/server/entity2LogicNamespace.ts +13 -1
  192. package/src/server/extendBaseNode.ts +31 -0
  193. package/src/server/naslServer.ts +32 -23
  194. package/src/server/translator.ts +15 -0
  195. package/src/templator/genCreateBlock.ts +4 -4
  196. package/src/templator/genCurdEditMultipleKeyBlock.ts +2 -2
  197. package/src/templator/genCurdMultipleKeyBlock.ts +7 -7
  198. package/src/templator/genEditTableBlock.ts +4 -4
  199. package/src/templator/genGetBlock.ts +1 -1
  200. package/src/templator/genGridViewBlock.ts +2 -2
  201. package/src/templator/genSelectBlock.ts +3 -3
  202. package/src/templator/genTableBlock.ts +2 -2
  203. package/src/templator/genUpdateBlock.ts +6 -6
  204. package/src/templator/utils.ts +1 -1
  205. package/test/concepts/string-literal/__snapshots__/toVue.spec.ts.snap +1 -1
  206. package/test/concepts/view-element/__snapshots__/toVue.spec.ts.snap +6 -2
@@ -1,4 +1,8 @@
1
1
  import { queryNodeByPath } from '../service/storage/jsoner';
2
+ import {
3
+ withSourceMap,
4
+ createCompilerState,
5
+ } from '../translator';
2
6
  import { getNaslNodeByNodeCallee, getNodeByNodeCallee } from '../automate/engine/utils';
3
7
  import type ConfigProperty from './ConfigProperty__';
4
8
  import type TypeAnnotation from './TypeAnnotation__';
@@ -4428,16 +4432,20 @@ export class App extends BaseNode {
4428
4432
  }
4429
4433
 
4430
4434
  getExtensionsCallbackLogics() {
4431
- let resultLogics: string[] = [];
4435
+ const resultLogics: Set<string> = new Set();
4432
4436
  this.frontendTypes.forEach((frontendType) => {
4433
4437
  frontendType?.frontends?.forEach((frontend) => {
4434
- resultLogics = [...resultLogics, ...frontend.getExtensionsCallbackLogics()];
4438
+ frontend.getExtensionsCallbackLogics().forEach((logic) => {
4439
+ resultLogics.add(logic);
4440
+ })
4435
4441
  });
4436
4442
  frontendType?.businessComponents?.forEach((businessComponent) => {
4437
- resultLogics = [...resultLogics, ...(businessComponent?.getViewCallLogics?.() || [])];
4443
+ (businessComponent?.getViewCallLogics?.() || []).forEach((logic) => {
4444
+ resultLogics.add(logic);
4445
+ })
4438
4446
  });
4439
4447
  });
4440
- return Array.from(new Set(resultLogics));
4448
+ return Array.from(resultLogics);
4441
4449
  }
4442
4450
 
4443
4451
  getJavaLogicUniqueName(name = 'javalogic1') {
@@ -5389,6 +5397,98 @@ export class App extends BaseNode {
5389
5397
  // });
5390
5398
  // }
5391
5399
 
5400
+ @withSourceMap()
5401
+ toNaturalTS(state = createCompilerState()): string {
5402
+ let code = '';
5403
+
5404
+ this.dependencies?.forEach((dep) => {
5405
+ code += dep.toNaturalTS(state) + '\n\n';
5406
+ });
5407
+
5408
+ this.interfaceDependencies?.forEach((dep) => {
5409
+ code += dep.toNaturalTS(state) + '\n\n';
5410
+ });
5411
+
5412
+ this.dataSources?.forEach((dataSource) => {
5413
+ code += dataSource.toNaturalTS(state) + '\n';
5414
+ });
5415
+ this.structures?.forEach((structure) => {
5416
+ code += structure.toNaturalTS(state) + '\n';
5417
+ });
5418
+ this.enums?.forEach((enumeration) => {
5419
+ code += enumeration.toNaturalTS(state) + '\n';
5420
+ });
5421
+ this.metadataTypes?.forEach((metadataType) => {
5422
+ code += metadataType.toNaturalTS(state) + '\n';
5423
+ });
5424
+ if (this.metadataTypes.length)
5425
+ code += '\n';
5426
+ this.logics?.forEach((logic) => {
5427
+ code += logic.toNaturalTS(state) + '\n\n';
5428
+ });
5429
+ this.overriddenLogics?.forEach((logic) => {
5430
+ code += logic.toNaturalTS(state) + '\n\n';
5431
+ });
5432
+ this.interfaces?.forEach((inter) => {
5433
+ code += inter.toNaturalTS(state) + '\n';
5434
+ });
5435
+ this.roles?.forEach((role) => {
5436
+ code += role.toNaturalTS(state) + '\n';
5437
+ });
5438
+ this.frontendTypes?.forEach((frontendType, index) => {
5439
+ code += frontendType.toNaturalTS(state);
5440
+ if (index !== this.frontendTypes.length - 1)
5441
+ code += '\n';
5442
+ });
5443
+
5444
+ return code;
5445
+ }
5446
+
5447
+ @withSourceMap()
5448
+ toTextualNASL(state = createCompilerState()): string {
5449
+ let code = '';
5450
+
5451
+ this.dependencies?.forEach((dep) => {
5452
+ code += dep.toTextualNASL(state) + '\n';
5453
+ });
5454
+
5455
+ this.interfaceDependencies?.forEach((dep) => {
5456
+ code += dep.toTextualNASL(state) + '\n';
5457
+ });
5458
+
5459
+ this.dataSources?.forEach((dataSource) => {
5460
+ code += dataSource.toTextualNASL(state) + '\n';
5461
+ });
5462
+ this.structures?.forEach((structure) => {
5463
+ code += structure.toTextualNASL(state) + '\n';
5464
+ });
5465
+ this.enums?.forEach((enumeration) => {
5466
+ code += enumeration.toTextualNASL(state) + '\n';
5467
+ });
5468
+ this.metadataTypes?.forEach((metadataType) => {
5469
+ code += metadataType.toTextualNASL(state) + '\n';
5470
+ });
5471
+ this.logics?.forEach((logic) => {
5472
+ code += logic.toTextualNASL(state) + '\n\n';
5473
+ });
5474
+ this.overriddenLogics?.forEach((logic) => {
5475
+ code += logic.toTextualNASL(state) + '\n\n';
5476
+ });
5477
+ this.interfaces?.forEach((inter) => {
5478
+ code += inter.toTextualNASL(state) + '\n';
5479
+ });
5480
+ this.roles?.forEach((role) => {
5481
+ code += role.toTextualNASL(state) + '\n';
5482
+ });
5483
+ this.frontendTypes?.forEach((frontendType, index) => {
5484
+ code += frontendType.toTextualNASL(state);
5485
+ if (index !== this.frontendTypes.length - 1)
5486
+ code += '\n';
5487
+ });
5488
+
5489
+ return code;
5490
+ }
5491
+
5392
5492
  //================================================================================
5393
5493
  // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
5394
5494
  // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
@@ -220,7 +220,7 @@ export class Argument extends LogicItem {
220
220
  // if ((this.expression as StringLiteral).name === 'ListDistinctByTargetDefaultExpression') {
221
221
  // code += runSync((this.expression as NewList).toEmbeddedIgnoreTS(shiftState(state, code)));
222
222
  // } else {
223
- code += (this.expression as StringLiteral).toNaturalTS(shiftState(state, code), isRequired);
223
+ code += (this.expression as StringLiteral).toNaturalTS(shiftState(state, code, { inline: true }), isRequired);
224
224
  // }
225
225
  } else {
226
226
  code += isRequired ? '__IDENTIFIER__' : 'undefined';
@@ -235,13 +235,13 @@ export class Argument extends LogicItem {
235
235
  toTextualNASL(state = createCompilerState(), isRequired: boolean = true, isHaveKeyWord?: boolean): string {
236
236
  let code = this.spread ? '...' : '';
237
237
  if (isHaveKeyWord) {
238
- code += `${this.tsKeyword}:`;
238
+ code += `${this.tsKeyword} = `;
239
239
  }
240
240
  if (this.expression) {
241
241
  // if ((this.expression as StringLiteral).name === 'ListDistinctByTargetDefaultExpression') {
242
242
  // code += runSync((this.expression as NewList).toEmbeddedIgnoreTS(shiftState(state, code)));
243
243
  // } else {
244
- code += this.expression.toTextualNASL(shiftState(state, code));
244
+ code += this.expression.toTextualNASL(shiftState(state, code, { inline: true }));
245
245
  // }
246
246
  } else {
247
247
  code += isRequired ? '__IDENTIFIER__' : 'undefined';
@@ -526,7 +526,7 @@ export class BatchAssignment extends LogicItem {
526
526
  }
527
527
 
528
528
  // 自动连线算法---addRightIndex : 指右边选择变量后对该selectmember进行自动连线。
529
- async batchAutoConnection(addRightIndex?: number) {
529
+ batchAutoConnection(addRightIndex?: number) {
530
530
  const leftLineSet = new Set();
531
531
  const lineArr: Array<AssignmentLine> = [];
532
532
  const AssignmentLine = getConceptConstructor('AssignmentLine');
@@ -560,7 +560,7 @@ export class BatchAssignment extends LogicItem {
560
560
  this.rights.forEach((selectMember, rightFirstIndex) => {
561
561
  const { members, expression } = selectMember;
562
562
  if (leftLineSet.has(leftSecondIndex)) return;
563
- if (addRightIndex !== -1 && addRightIndex !== rightFirstIndex) return;
563
+ if (![-1, null, undefined].includes(addRightIndex) && addRightIndex !== rightFirstIndex) return;
564
564
  // 右侧父节点也不允许自动连线
565
565
  const rightLineSet = new Set();
566
566
  for (let i = 0; i < members.length - 1; i++) {
@@ -909,10 +909,9 @@ export class BindAttribute extends BaseNode {
909
909
  } else {
910
910
  code = value.replace(/['"`\\]/g, (m) => {
911
911
  let escape = '\\\\';
912
- escape = '\\\\';
913
- /// #if process.env.BUILD_TARGET === 'node'
914
- escape = '\\';
915
- /// #endif
912
+ if (options?.isGeneratorExport) {
913
+ escape = '\\';
914
+ }
916
915
  if (m === '\\') {
917
916
  return `${escape}${escape}`;
918
917
  }
@@ -486,10 +486,9 @@ export class BindDirective extends BaseNode {
486
486
  if (this.type === 'string') {
487
487
  value = value.replace(/['"`\\]/g, (m) => {
488
488
  let escape = '\\\\';
489
- escape = '\\\\';
490
- /// #if process.env.BUILD_TARGET === 'node'
491
- escape = '\\';
492
- /// #endif
489
+ if (options?.isGeneratorExport) {
490
+ escape = '\\';
491
+ }
493
492
  if (m === '\\') {
494
493
  return `${escape}${escape}`;
495
494
  }
@@ -4,7 +4,7 @@ import {
4
4
  returnOrigin,
5
5
  } from '../utils/time-slicing';
6
6
  import type { EmbeddedTSFileGenerator } from '../utils';
7
- import { shiftState, indent, createCompilerState, withSourceMapGenerator, TranslatorGenerator } from '../translator';
7
+ import { shiftState, indent, createCompilerState, withSourceMapGenerator, TranslatorGenerator, withSourceMap, createDecoratorCode } from '../translator';
8
8
  import type Assignment from './Assignment__';
9
9
  import type BatchAssignment from './BatchAssignment__';
10
10
  import type CallFunction from './CallFunction__';
@@ -2475,6 +2475,59 @@ export class BusinessComponent extends BaseNode {
2475
2475
  });
2476
2476
  return callbackLogics;
2477
2477
  }
2478
+
2479
+ @withSourceMap()
2480
+ toNaturalTS(state = createCompilerState()): string {
2481
+ let code = `export namespace ${this.name} {\n`;
2482
+ // this.businessComponents.forEach((component) => {
2483
+ // this.frontends.forEach((frontend) => {
2484
+ // code += frontend.toNaturalTS(state);
2485
+ // code += '\n';
2486
+ // });
2487
+ // });
2488
+ code += '}';
2489
+
2490
+ return code;
2491
+ }
2492
+
2493
+ @withSourceMap()
2494
+ toTextualNASL(state = createCompilerState()): string {
2495
+ let code = '';
2496
+
2497
+ code += createDecoratorCode(state, this, ['title', 'description']);
2498
+
2499
+ code += `viewComponent ${this.name}`;
2500
+
2501
+ code += `(\n`;
2502
+ this.params.forEach((param, index) => {
2503
+ code += param.toTextualNASL(shiftState(state, code, { tabSize: state.tabSize + 1 }));
2504
+ code += ',\n';
2505
+ });
2506
+ this.events.forEach((event, index) => {
2507
+ code += event.toTextualNASL(shiftState(state, code, { tabSize: state.tabSize + 1 }));
2508
+ code += ',\n';
2509
+ });
2510
+ code += ') {\n';
2511
+
2512
+ this.variables.forEach((variable) => {
2513
+ code += `${indent(state.tabSize + 1)}let `;
2514
+ code += variable.toTextualNASL(shiftState(state, code, { tabSize: state.tabSize + 1, inline: true }));
2515
+ code += ';\n';
2516
+ });
2517
+ if (this.variables.length) code += '\n';
2518
+
2519
+ this.logics.forEach((logic) => {
2520
+ code += logic.toTextualNASL(shiftState(state, code, { tabSize: state.tabSize + 1 }));
2521
+ code += '\n';
2522
+ });
2523
+ if (this.logics.length) code += '\n';
2524
+
2525
+ code += this.elements[0].toTextualNASL(shiftState(state, code, { tabSize: state.tabSize + 1 }));
2526
+
2527
+ code += `\n${indent(state.tabSize)}}`;
2528
+
2529
+ return code;
2530
+ }
2478
2531
  //================================================================================
2479
2532
  // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
2480
2533
  // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
@@ -4,7 +4,7 @@ import {
4
4
  returnOrigin,
5
5
  } from '../utils/time-slicing';
6
6
  import { waitOqlQueryComponentChildrenFinish } from '../common';
7
- import { shiftState, indent, createCompilerState, withSourceMapGenerator, TranslatorGenerator } from '../translator';
7
+ import { shiftState, indent, createCompilerState, withSourceMapGenerator, TranslatorGenerator, withSourceMap } from '../translator';
8
8
  import { Variable } from './Variable__';
9
9
  import { Return } from './Return__';
10
10
  import { Assignment } from './Assignment__';
@@ -477,6 +477,15 @@ export class BusinessLogic extends Logic {
477
477
  return code;
478
478
  }
479
479
 
480
+ @withSourceMap()
481
+ toTextualNASL(state = createCompilerState()): string {
482
+ let code = '';
483
+ if (this.isPublic)
484
+ code += 'public ';
485
+ code += super.toTextualNASL(state).trimStart();
486
+ return code;
487
+ }
488
+
480
489
  //================================================================================
481
490
  // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
482
491
  // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
@@ -5,6 +5,8 @@ import {
5
5
  createCompilerState,
6
6
  withSourceMapGenerator,
7
7
  TranslatorGenerator,
8
+ indent,
9
+ withSourceMap,
8
10
  } from '../translator';
9
11
  import type Event from './Event__';
10
12
  import type Param from './Param__';
@@ -305,6 +307,70 @@ export class CallEvent extends LogicItem {
305
307
  code += '\n})';
306
308
  return code;
307
309
  }
310
+
311
+ @withSourceMap()
312
+ toNaturalTS(state = createCompilerState()): string {
313
+ let code = '';
314
+ code = 'on' + utils.firstUpperCase(this.calleeName);
315
+ if (this.arguments.length <= 3) {
316
+ code += '(';
317
+ this.arguments.forEach((arg, index) => {
318
+ if (!arg) {
319
+ code += '__IDENTIFIER__';
320
+ } else {
321
+ code += arg.toNaturalTS(shiftState(state, code, { inline: true }));
322
+ }
323
+ if (index !== this.arguments.length - 1) code += ', ';
324
+ });
325
+ // if (this?.typeArguments?.[0]?.typeKind === 'reference') {
326
+ // if (this.arguments?.length > 0) code += ', ';
327
+ // code += `{ typeNamespace: '${this.typeArguments[0].typeNamespace}' }`;
328
+ // }
329
+ code += `)`;
330
+ } else {
331
+ code += '(\n';
332
+ this.arguments.forEach((arg, index) => {
333
+ if (!arg) {
334
+ code += '__IDENTIFIER__';
335
+ } else {
336
+ code += indent(state.tabSize + 1) + arg.toNaturalTS(shiftState(state, code, { inline: true, tabSize: state.tabSize + 1 }));
337
+ }
338
+ if (index !== this.arguments.length - 1) {
339
+ code += ',\n';
340
+ } else {
341
+ code += '\n';
342
+ }
343
+ });
344
+ code += `${indent(state.tabSize)})`;
345
+ }
346
+ return code;
347
+ }
348
+
349
+ @withSourceMap()
350
+ toTextualNASL(state = createCompilerState()): string {
351
+ let code = '';
352
+ code = 'on' + utils.firstUpperCase(this.calleeName);
353
+ if (this.arguments.length <= 3) {
354
+ code += '(';
355
+ this.arguments.forEach((arg, index) => {
356
+ code += arg.toTextualNASL(shiftState(state, code, { inline: true }));
357
+ if (index !== this.arguments.length - 1) code += ', ';
358
+ });
359
+ code += `)`;
360
+ } else {
361
+ code += '(\n';
362
+ this.arguments.forEach((arg, index) => {
363
+ code += arg.toTextualNASL(shiftState(state, code, { tabSize: state.tabSize + 1 }));
364
+ if (index !== this.arguments.length - 1) {
365
+ code += ',\n';
366
+ } else {
367
+ code += '\n';
368
+ }
369
+ });
370
+ code += `${indent(state.tabSize)})`;
371
+ }
372
+ return code;
373
+ }
308
374
  //================================================================================
309
375
  // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
310
376
  // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
@@ -7,6 +7,8 @@ import {
7
7
  withSourceMapGenerator,
8
8
  withGenerator,
9
9
  TranslatorGenerator,
10
+ textualNamespace,
11
+ indent,
10
12
  } from '../translator';
11
13
  import type Interface from './Interface__';
12
14
  import { ElementToVueOptions } from './ViewElement__';
@@ -476,19 +478,29 @@ export class CallInterface extends LogicItem {
476
478
 
477
479
  let code = `${tsCalleeKey}(`;
478
480
 
479
- if (completeArguments?.length) {
480
- code += '{ ';
481
- completeArguments?.forEach((arg, index) => {
481
+ code += '{\n';
482
+ this.completeArguments?.forEach((arg, index) => {
482
483
  if (!arg) {
483
- code += '__IDENTIFIER__: undefined';
484
+ code += '__IDENTIFIER__: undefined,\n';
484
485
  } else {
485
- code += arg.toNaturalTS(shiftState(state, code), arg.paramRequired, true);
486
+ code += arg.toNaturalTS(shiftState(state, code, { tabSize: state.tabSize + 1 }), arg.paramRequired, true) + ',\n';
486
487
  }
487
- if (index !== this.arguments?.length - 1) code += ', ';
488
488
  });
489
- code += ' }';
490
- }
491
- code += ')';
489
+ code += `${indent(state.tabSize)}})`;
490
+ return code;
491
+ }
492
+
493
+ @withSourceMap()
494
+ toTextualNASL(state = createCompilerState()): string {
495
+ let code = `${textualNamespace(this.tsCalleeKey)}(\n`;
496
+ this.completeArguments.forEach((arg, index) => {
497
+ if (!arg) {
498
+ code += '__IDENTIFIER__ = null,\n';
499
+ } else {
500
+ code += arg.toTextualNASL(shiftState(state, code, { tabSize: state.tabSize + 1 }), arg.paramRequired, true) + ',\n';
501
+ }
502
+ });
503
+ code += `${indent(state.tabSize)})`;
492
504
  return code;
493
505
  }
494
506
 
@@ -14,6 +14,7 @@ import {
14
14
  import type Logic from './Logic__';
15
15
  import type Param from './Param__';
16
16
  import type View from './View__';
17
+ import type BusinessComponent from './BusinessComponent__';
17
18
  import { getNodeByNodeCallee, getNaslNodeByNodeCallee } from '../automate/engine/utils';
18
19
  import { findConceptKeyWordIndexFromNamespace } from '../utils';
19
20
  import {
@@ -668,7 +669,7 @@ export class CallLogic extends LogicItem {
668
669
  for (let i = 0; i < currentIndex; i++) {
669
670
  currentParamList.push(`,current${i === 0 ? '' : i}`);
670
671
  }
671
- code += `(params)=>__${currentElement.name}_handleDataSourceLoad(params${currentParamList.join('')})`;
672
+ code += `$global.useDatabaseCallback()(__${currentElement.name}_handleDataSourceLoad${currentParamList.join('')})`
672
673
  return code;
673
674
  }
674
675
  if (calleeName === 'jsonSerialize') {
@@ -1576,8 +1577,62 @@ export class CallLogic extends LogicItem {
1576
1577
  return code;
1577
1578
  }
1578
1579
 
1580
+ get likeComponent(): View | BusinessComponent {
1581
+ return this.view || (this?.getAncestor('BusinessComponent') as BusinessComponent);
1582
+ }
1583
+
1579
1584
  // 通过内容过去节点
1580
1585
  getCallNode(): Logic | undefined {
1586
+ let node;
1587
+ // 如果是页面/业务组件 局部逻辑
1588
+ if (!this.calleeNamespace && this.calleeName && this.likeComponent) {
1589
+ node = this.likeComponent.logics.find((l) => l.name === this.calleeName);
1590
+ } else if (this.calleeNamespace?.startsWith('nasl.')) {
1591
+ // 如果是页面组件
1592
+ node = getNaslNodeByNodeCallee(this.calleeNamespace, this.calleeName);
1593
+ } else if (this.calleeNamespace?.startsWith('elements.')) {
1594
+ // 查找组件的逻辑,用于展示默认值
1595
+ const elementsLogic = (this.app as any)?.naslServer?.elementsLogic || {};
1596
+ let elementName: string = this.calleeNamespace.split('.')[1];
1597
+ // eslint-disable-next-line prefer-destructuring
1598
+ elementName = elementName.split('_')[0];
1599
+ elementName = elementName[0].toUpperCase() + elementName.slice(1);
1600
+ const logics = elementsLogic[`U${elementName}`] || elementsLogic[`Van${elementName}`] || [];
1601
+ node = logics.find((l: any) => l.name === this.calleeName);
1602
+ } else {
1603
+ // 如果是其余app下自定义逻辑
1604
+ try {
1605
+ node = getNodeByNodeCallee(this.app, this.calleewholeKey, (key: any, tempPoint: any) => {
1606
+ // 处理 NASL 中未定义的假的节点
1607
+ if (key === tempPoint.name) {
1608
+ return {
1609
+ tempPoint,
1610
+ state: 1,
1611
+ };
1612
+ }
1613
+ const t = tempPoint[key];
1614
+ return {
1615
+ tempPoint: t,
1616
+ state: Array.isArray(t) ? 2 : 1,
1617
+ };
1618
+ });
1619
+ } catch (err) {}
1620
+ }
1621
+ return node;
1622
+ }
1623
+
1624
+ getCallNodeUsingCache(frontNdCache : Map<string, Logic>, serverNdCache : Map<string, Logic>, processNdCache : Map<string, Logic>): ['front' | 'server' | 'process', Logic | undefined] {
1625
+ const cwKey = this.calleewholeKey;
1626
+ if (serverNdCache.get(cwKey)) {
1627
+ return ['server', serverNdCache.get(cwKey)];
1628
+ }
1629
+ if (processNdCache.get(cwKey)) {
1630
+ return ['process', processNdCache.get(cwKey)];
1631
+ }
1632
+ if (frontNdCache.get(cwKey)) {
1633
+ return ['front', frontNdCache.get(cwKey)];
1634
+ }
1635
+
1581
1636
  let node;
1582
1637
  // 如果是页面局部逻辑
1583
1638
  if (!this.calleeNamespace && this.calleeName && this.view) {
@@ -1597,7 +1652,7 @@ export class CallLogic extends LogicItem {
1597
1652
  } else {
1598
1653
  // 如果是其余app下自定义逻辑
1599
1654
  try {
1600
- node = getNodeByNodeCallee(this.app, this.calleewholeKey, (key: any, tempPoint: any) => {
1655
+ node = getNodeByNodeCallee(this.app, cwKey, (key: any, tempPoint: any) => {
1601
1656
  // 处理 NASL 中未定义的假的节点
1602
1657
  if (key === tempPoint.name) {
1603
1658
  return {
@@ -1613,7 +1668,8 @@ export class CallLogic extends LogicItem {
1613
1668
  });
1614
1669
  } catch (err) {}
1615
1670
  }
1616
- return node;
1671
+ frontNdCache.set(cwKey, node);
1672
+ return ['front', node];
1617
1673
  }
1618
1674
 
1619
1675
  /** 获取类型标注时的偏移量 */
@@ -35,6 +35,7 @@ import * as asserts from './utils/asserts';
35
35
  import EntityProperty from './EntityProperty__';
36
36
  import EntityIndex from './EntityIndex__';
37
37
  import Annotatable from './Annotatable__';
38
+ import Logic from './Logic__';
38
39
 
39
40
  /**
40
41
  * 实体
@@ -818,7 +819,7 @@ export class Entity extends Annotatable {
818
819
  * 如果修改这里,可能会影响到dataSource的重命名, 在naslserver中,可能要一起修改
819
820
  */
820
821
  code += `\n${indent((state?.tabSize || 0) + 1)}static logics = {\n`;
821
- yield* wrapForEach(ns.logics, function* warpForEachGenerator(logic) {
822
+ yield* wrapForEach(ns.logics, function* warpForEachGenerator(logic : Logic) {
822
823
  code += indent((state?.tabSize || 0) + 1);
823
824
  code += yield* logic.toEmbeddedTS(shiftState(state, code), 'inObject');
824
825
  });
@@ -909,6 +910,11 @@ export class Entity extends Annotatable {
909
910
  return this.ns.logics;
910
911
  }
911
912
 
913
+ get contentUniqueKey() {
914
+ return `${this.getNamespace()}.${this.name} {${this.properties.map(({ name, typeAnnotation }) => `${name}: ${typeAnnotation ? typeAnnotation?.sortedTypeKey : '未知'}`)
915
+ .join(', ')}}`;
916
+ }
917
+
912
918
  *toEmbeddedTSFile(): EmbeddedTSFileGenerator {
913
919
  let code = `namespace ${this.getNamespace()} {\n`;
914
920
  code += ' @nasl.annotation.Entity()\n';
@@ -14,6 +14,7 @@ import {
14
14
  withSourceMapGenerator,
15
15
  withGenerator,
16
16
  TranslatorGenerator,
17
+ createDecoratorCode,
17
18
  } from '../translator';
18
19
  import ViewComponentDeclaration from './ViewComponentDeclaration__';
19
20
  import Module from './Module__';
@@ -356,6 +357,37 @@ export class Event extends BaseNode {
356
357
  field: 'name',
357
358
  });
358
359
  }
360
+
361
+ @withSourceMap()
362
+ toNaturalTS(state = createCompilerState(), dontType?: boolean): string {
363
+ let code = '';
364
+ // code += createDecoratorCode(state, this, ['group', 'title', 'description']);
365
+
366
+ code += 'on' + utils.firstUpperCase(this.name) + ': (';
367
+ this.params.forEach((param, index) => {
368
+ code += param.toNaturalTS(shiftState(state, code, { tabSize: state.tabSize + 1, inline: true }));
369
+ if (index !== this.params.length - 1) code += ', ';
370
+ });
371
+ code += ') => void';
372
+
373
+ return code;
374
+ }
375
+
376
+ @withSourceMap()
377
+ toTextualNASL(state = createCompilerState(), dontType?: boolean): string {
378
+ let code = '';
379
+ code += createDecoratorCode(state, this, ['group', 'title', 'description']);
380
+
381
+ code += 'on' + utils.firstUpperCase(this.name) + ': (';
382
+ this.params.forEach((param, index) => {
383
+ code += param.toNaturalTS(shiftState(state, code, { tabSize: state.tabSize + 1, inline: true }));
384
+ if (index !== this.params.length - 1) code += ', ';
385
+ });
386
+ code += ') => null';
387
+
388
+ return code;
389
+ }
390
+
359
391
  //================================================================================
360
392
  // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
361
393
  // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
@@ -1,5 +1,5 @@
1
1
  import type { EmbeddedTSFileGenerator } from '../utils';
2
- import { createCompilerState, withSourceMapGenerator, TranslatorGenerator } from '../translator';
2
+ import { withSourceMap, createCompilerState, withSourceMapGenerator, TranslatorGenerator, indent, shiftState } from '../translator';
3
3
  import Namespace from './Namespace__';
4
4
  import { AssetsInfo } from './App__';
5
5
 
@@ -811,6 +811,39 @@ export class FrontendType extends BaseNode {
811
811
  return custom;
812
812
  }
813
813
 
814
+ @withSourceMap()
815
+ toNaturalTS(state = createCompilerState()): string {
816
+ let code = `export namespace app.frontendTypes.${this.name} {\n`;
817
+ this.businessComponents.forEach((component) => {
818
+ });
819
+ this.frontends.forEach((frontend, index) => {
820
+ code += frontend.toNaturalTS(shiftState(state, code, { tabSize: state.tabSize + 1 })) + '\n';
821
+ if (index !== this.frontends.length) code += '\n';
822
+ });
823
+ code += `${indent(state.tabSize)}}`;
824
+
825
+ return code;
826
+ }
827
+
828
+ @withSourceMap()
829
+ toTextualNASL(state = createCompilerState()): string {
830
+ let code = `frontend ${this.kind} {\n`;
831
+ this.businessComponents.forEach((component) => {
832
+
833
+ });
834
+ code += `${indent(state.tabSize)}}`;
835
+
836
+ if (this.frontends.length)
837
+ code += `\n\n${indent(state.tabSize)}`;
838
+
839
+ this.frontends.forEach((frontend, index) => {
840
+ code += frontend.toTextualNASL(state) + '\n';
841
+ if (index !== this.frontends.length) code += '\n';
842
+ });
843
+
844
+ return code;
845
+ }
846
+
814
847
  //================================================================================
815
848
  // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
816
849
  // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓