@lcap/nasl 3.7.2-beta.4 → 3.7.3-beta.2

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 (101) hide show
  1. package/out/common/BaseNode.js +1 -1
  2. package/out/concepts/App__.js +3 -0
  3. package/out/concepts/App__.js.map +1 -1
  4. package/out/concepts/BinaryExpression__.js +49 -2
  5. package/out/concepts/BinaryExpression__.js.map +1 -1
  6. package/out/concepts/BindAttribute__.js +7 -1
  7. package/out/concepts/BindAttribute__.js.map +1 -1
  8. package/out/concepts/BusinessComponent__.d.ts +1 -0
  9. package/out/concepts/BusinessComponent__.js +9 -0
  10. package/out/concepts/BusinessComponent__.js.map +1 -1
  11. package/out/concepts/CallConnector__.js +1 -1
  12. package/out/concepts/CallConnector__.js.map +1 -1
  13. package/out/concepts/Connection__.d.ts +4 -0
  14. package/out/concepts/Connection__.js +15 -0
  15. package/out/concepts/Connection__.js.map +1 -1
  16. package/out/concepts/Entity__.d.ts +1 -0
  17. package/out/concepts/Entity__.js +20 -0
  18. package/out/concepts/Entity__.js.map +1 -1
  19. package/out/concepts/EventDeclaration__.d.ts +1 -0
  20. package/out/concepts/EventDeclaration__.js +38 -0
  21. package/out/concepts/EventDeclaration__.js.map +1 -1
  22. package/out/concepts/LogicDeclaration__.d.ts +1 -0
  23. package/out/concepts/LogicDeclaration__.js +26 -0
  24. package/out/concepts/LogicDeclaration__.js.map +1 -1
  25. package/out/concepts/Logic__.js +2 -2
  26. package/out/concepts/Logic__.js.map +1 -1
  27. package/out/concepts/PropDeclaration__.d.ts +1 -0
  28. package/out/concepts/PropDeclaration__.js +14 -0
  29. package/out/concepts/PropDeclaration__.js.map +1 -1
  30. package/out/concepts/SlotDeclaration__.d.ts +1 -0
  31. package/out/concepts/SlotDeclaration__.js +14 -0
  32. package/out/concepts/SlotDeclaration__.js.map +1 -1
  33. package/out/concepts/Variable__.js +5 -1
  34. package/out/concepts/Variable__.js.map +1 -1
  35. package/out/concepts/ViewComponentDeclaration__.d.ts +1 -0
  36. package/out/concepts/ViewComponentDeclaration__.js +42 -0
  37. package/out/concepts/ViewComponentDeclaration__.js.map +1 -1
  38. package/out/concepts/ViewElement__.js +2 -2
  39. package/out/concepts/ViewElement__.js.map +1 -1
  40. package/out/generator/genBundleFiles.js +3 -2
  41. package/out/generator/genBundleFiles.js.map +1 -1
  42. package/out/generator/genMetaData.js +20 -26
  43. package/out/generator/genMetaData.js.map +1 -1
  44. package/out/generator/release-body/body.js +4 -3
  45. package/out/generator/release-body/body.js.map +1 -1
  46. package/out/natural/genNaturalTS.d.ts +20 -4
  47. package/out/natural/genNaturalTS.js +2 -2
  48. package/out/natural/genNaturalTS.js.map +1 -1
  49. package/out/natural/getContext/getUILib.d.ts +3 -0
  50. package/out/natural/getContext/getUILib.js +90 -2
  51. package/out/natural/getContext/getUILib.js.map +1 -1
  52. package/out/natural/getContext/index.d.ts +11 -3
  53. package/out/natural/getContext/index.js +21 -27
  54. package/out/natural/getContext/index.js.map +1 -1
  55. package/out/natural/index.d.ts +1 -0
  56. package/out/natural/index.js +1 -0
  57. package/out/natural/index.js.map +1 -1
  58. package/out/natural/transformTS2UI.d.ts +1 -1
  59. package/out/natural/transformTS2UI.js +148 -28
  60. package/out/natural/transformTS2UI.js.map +1 -1
  61. package/out/natural/transformTSCode.js +95 -22
  62. package/out/natural/transformTSCode.js.map +1 -1
  63. package/out/server/getLogics.js +3 -6
  64. package/out/server/getLogics.js.map +1 -1
  65. package/out/server/naslServer.js +44 -0
  66. package/out/server/naslServer.js.map +1 -1
  67. package/out/templator/genSelectBlock.js +82 -59
  68. package/out/templator/genSelectBlock.js.map +1 -1
  69. package/out/utils/index.d.ts +17 -0
  70. package/out/utils/index.js +36 -1
  71. package/out/utils/index.js.map +1 -1
  72. package/package.json +1 -1
  73. package/src/common/BaseNode.ts +1 -1
  74. package/src/concepts/App__.ts +3 -0
  75. package/src/concepts/BinaryExpression__.ts +46 -2
  76. package/src/concepts/BindAttribute__.ts +8 -3
  77. package/src/concepts/BusinessComponent__.ts +10 -0
  78. package/src/concepts/CallConnector__.ts +1 -1
  79. package/src/concepts/Connection__.ts +16 -0
  80. package/src/concepts/Entity__.ts +23 -0
  81. package/src/concepts/EventDeclaration__.ts +9 -1
  82. package/src/concepts/LogicDeclaration__.ts +23 -1
  83. package/src/concepts/Logic__.ts +2 -2
  84. package/src/concepts/PropDeclaration__.ts +14 -0
  85. package/src/concepts/SlotDeclaration__.ts +9 -1
  86. package/src/concepts/Variable__.ts +5 -1
  87. package/src/concepts/ViewComponentDeclaration__.ts +40 -1
  88. package/src/concepts/ViewElement__.ts +2 -2
  89. package/src/generator/genBundleFiles.ts +3 -2
  90. package/src/generator/genMetaData.ts +21 -26
  91. package/src/generator/release-body/body.ts +5 -3
  92. package/src/natural/genNaturalTS.ts +4 -4
  93. package/src/natural/getContext/getUILib.ts +139 -71
  94. package/src/natural/getContext/index.ts +29 -35
  95. package/src/natural/index.ts +1 -0
  96. package/src/natural/transformTS2UI.ts +151 -31
  97. package/src/natural/transformTSCode.ts +99 -25
  98. package/src/server/getLogics.ts +3 -6
  99. package/src/server/naslServer.ts +42 -0
  100. package/src/templator/genSelectBlock.ts +88 -61
  101. package/src/utils/index.ts +37 -2
@@ -180,14 +180,14 @@ export function genSelectItemAddLogic(entity: Entity, nameGroup: NameGroup, view
180
180
  const callLogics = [];
181
181
  const variableName = view.getVariableUniqueName('itemVariable1');
182
182
  const itemVariable1Snapshot = view.getVariableUniqueName(`${variableName}Snapshot`);
183
- const variables = [
183
+ let variables = [
184
184
  NaslNode.Variable({
185
185
  name: variableName,
186
186
  typeAnnotation: null,
187
187
  }),
188
188
  ];
189
189
  const itemExpression = genLogicParam(`item`, `${variableName}.${nameGroup.textField}`);
190
- if (entity && entity.getNamespace) {
190
+ if (entity && entity.getNamespace) { // item是实体或者数据结构
191
191
  callLogics.push(
192
192
  NaslLogicItem.Assignment({
193
193
  left: NaslLogicItem.Identifier({
@@ -213,57 +213,51 @@ export function genSelectItemAddLogic(entity: Entity, nameGroup: NameGroup, view
213
213
  })
214
214
  );
215
215
  } else {
216
- callLogics.push(
217
- NaslLogicItem.Assignment({
218
- left: NaslLogicItem.Identifier({
219
- name: variableName,
220
- }),
221
- right: {
222
- concept: 'NewComposite',
223
- name: '',
224
- typeAnnotation: {
225
- concept: 'TypeAnnotation',
226
- name: '',
227
- typeKind: 'anonymousStructure',
228
- properties: [
229
- {
230
- concept: 'StructureProperty',
231
- name: nameGroup.textField,
232
- },
216
+ // item是基本类型
217
+ if(nameGroup.schemaRef === 'nasl.core.String'){
218
+ callLogics.push(
219
+ NaslLogicItem.Assignment({
220
+ left: NaslLogicItem.Identifier({
221
+ name: variableName,
222
+ }),
223
+ right: NaslLogicItem.Identifier({
224
+ name: nameGroup.itemInputVariableName,
225
+ }),
226
+ })
227
+ );
228
+ } else if (['nasl.core.Long', 'nasl.core.Decimal'].includes(nameGroup.schemaRef)) {
229
+ const typeAnnotation ={
230
+ concept: 'TypeAnnotation',
231
+ typeKind: 'primitive',
232
+ typeNamespace: 'nasl.core',
233
+ typeName: nameGroup.schemaRef.replace('nasl.core.', ''),
234
+ };
235
+ callLogics.push(
236
+ NaslLogicItem.Assignment({
237
+ left: NaslLogicItem.Identifier({
238
+ name: variableName,
239
+ }),
240
+ right: NaslLogicItem.CallFunction({
241
+ calleeName: 'Convert',
242
+ typeArguments: [typeAnnotation],
243
+ arguments: [
244
+ NaslLogicItem.Argument({
245
+ keyword: 'value',
246
+ expression: NaslLogicItem.Identifier({
247
+ name: nameGroup.itemInputVariableName,
248
+ }),
249
+ }),
233
250
  ],
234
- },
235
- properties: [
236
- {
237
- concept: 'Identifier',
238
- name: nameGroup.textField,
239
- },
240
- ],
241
- rights: [
242
- {
243
- concept: 'SelectMembers',
244
- name: '',
245
- expression: {
246
- concept: 'StringLiteral',
247
- name: '',
248
- value: '',
249
- },
250
- members: [],
251
- },
252
- ],
253
- assignmentLines: [
254
- {
255
- concept: 'AssignmentLine',
256
- name: '',
257
- leftIndex: [0, 0],
258
- rightIndex: [0],
259
- },
260
- ],
261
- hideProperties: false,
262
- hideDefaults: false,
263
- autoConnection: true,
264
- },
265
- })
266
- );
251
+ }),
252
+ })
253
+ );
254
+ } else {
255
+ callLogics.push({
256
+ concept: 'Comment',
257
+ name: '',
258
+ value: '存储输入框的值做处理',
259
+ });
260
+ }
267
261
  }
268
262
 
269
263
  // 该属性可能不是String类型,如Integer,需要转换下,否则问题处会报错
@@ -285,7 +279,7 @@ export function genSelectItemAddLogic(entity: Entity, nameGroup: NameGroup, view
285
279
  }),
286
280
  })
287
281
  );
288
- } else {
282
+ } else if (entity && entity.getNamespace) {
289
283
  callLogics.push(
290
284
  NaslLogicItem.Assignment({
291
285
  left: itemExpression.expression,
@@ -341,6 +335,10 @@ export function genSelectItemAddLogic(entity: Entity, nameGroup: NameGroup, view
341
335
  {
342
336
  concept: 'StructureProperty',
343
337
  name: nameGroup.prefixField,
338
+ typeAnnotation: NaslTypeAnnotation.Reference({
339
+ typeNamespace: entity.getNamespace(),
340
+ typeName: entity.name,
341
+ })
344
342
  },
345
343
  ],
346
344
  },
@@ -390,6 +388,42 @@ export function genSelectItemAddLogic(entity: Entity, nameGroup: NameGroup, view
390
388
  value: '调用后端接口保存数据',
391
389
  });
392
390
  }
391
+ const argumentsTemp = [];
392
+ if(variables.length >= 2) { // 实体
393
+ argumentsTemp.push(
394
+ NaslLogicItem.Argument({
395
+ keyword: 'item',
396
+ expression: NaslLogicItem.Identifier({
397
+ name: itemVariable1Snapshot,
398
+ }),
399
+ })
400
+ );
401
+ } else {
402
+ if(entity && entity.getNamespace || ['nasl.core.String', 'nasl.core.Long', 'nasl.core.Decimal'].includes(nameGroup.schemaRef)) {
403
+ argumentsTemp.push(
404
+ NaslLogicItem.Argument({
405
+ keyword: 'item',
406
+ expression: NaslLogicItem.Identifier({
407
+ name: variableName,
408
+ }),
409
+ })
410
+ );
411
+ } else {
412
+ // 其他类型就置空
413
+ variables = [];
414
+ callLogics.push({
415
+ concept: 'Comment',
416
+ name: '',
417
+ value: '如下调用addItem将数据添加到下拉框里,item参数填上值',
418
+ });
419
+ argumentsTemp.push(
420
+ NaslLogicItem.Argument({
421
+ keyword: 'item',
422
+ expression: null,
423
+ })
424
+ );
425
+ }
426
+ }
393
427
  return NaslNode.Logic({
394
428
  name: nameGroup.viewLogicAddItem,
395
429
  params: [],
@@ -398,14 +432,7 @@ export function genSelectItemAddLogic(entity: Entity, nameGroup: NameGroup, view
398
432
  body: [
399
433
  NaslLogicItem.Start,
400
434
  ...callLogics,
401
- genCallComponentLogic(nameGroup.viewElementMainView, 'addItem', [
402
- NaslLogicItem.Argument({
403
- keyword: 'item',
404
- expression: NaslLogicItem.Identifier({
405
- name: variables.length >= 2 ? itemVariable1Snapshot : variableName,
406
- }),
407
- }),
408
- ]),
435
+ genCallComponentLogic(nameGroup.viewElementMainView, 'addItem', argumentsTemp),
409
436
  NaslLogicItem.End,
410
437
  ],
411
438
  playground: [] as Array<any>,
@@ -224,7 +224,7 @@ function collectAnonymousFn({
224
224
  cb
225
225
  }: {
226
226
  anonymousFnNode: AnonymousFnNode;
227
- cb: (anonymousFnNode: AnonymousFnNode) => void
227
+ cb: (anonymousFnNode: AnonymousFnNode) => void;
228
228
  }) {
229
229
  const descendantsAnonyList: any = cb(anonymousFnNode);
230
230
  const { node } = anonymousFnNode;
@@ -442,7 +442,7 @@ export function hasParamNameOfAnonymousFunction({
442
442
  newName,
443
443
  }: {
444
444
  node: types.SyntaxNode,
445
- newName: string
445
+ newName: string;
446
446
  }) {
447
447
  const ancestorParamNames = getAncestorExistingVarNames(node);
448
448
  const anonymousFnNodesParams = collectAnonymousFnNodesParams(node);
@@ -484,3 +484,38 @@ export function isSameInType(source: TypeAnnotation[], target: TypeAnnotation[])
484
484
  });
485
485
  return flag;
486
486
  }
487
+
488
+ /**
489
+ * 获取节点对应的注释
490
+ */
491
+ export function getDescription(title: string, description: string) {
492
+ let desc = '';
493
+ if (title || description) {
494
+ desc += '// ';
495
+ desc += title ? `${title}` : '';
496
+ desc += (title && description) ? ': ' : '';
497
+ desc += description ? `${description}` : '';
498
+ }
499
+ return desc;
500
+ }
501
+
502
+ /**
503
+ * 将url转换为正则的
504
+ * @param url
505
+ * @returns
506
+ */
507
+ export function transAssetsToRegx(assets: any[], key: string) {
508
+ return new RegExp(assets.map((asset) => {
509
+ return `(https?:)?` + asset[key]?.replace(/^(?:https?:)?/i, '')?.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
510
+ }).join('|'), 'g');
511
+ }
512
+
513
+ /**
514
+ * 获取Asset
515
+ * @param assetsMap
516
+ * @param url
517
+ * @returns
518
+ */
519
+ export function getAssetFromAssetsMap(assetsMap: Map<string, any>, url: string) {
520
+ return assetsMap?.get(url) || assetsMap?.get(`http:${url}`) || assetsMap?.get(`https:${url}`);
521
+ }