@lcap/nasl 1.0.0 → 1.0.1

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 (135) hide show
  1. package/out/automate/engine/index.js +28 -127
  2. package/out/automate/engine/index.js.map +1 -1
  3. package/out/automate/engine/operators.d.ts +13 -0
  4. package/out/automate/engine/operators.js +63 -0
  5. package/out/automate/engine/operators.js.map +1 -0
  6. package/out/automate/engine/uniqueName.d.ts +6 -0
  7. package/out/automate/engine/uniqueName.js +39 -0
  8. package/out/automate/engine/uniqueName.js.map +1 -0
  9. package/out/concepts/App__.js +9 -9
  10. package/out/concepts/App__.js.map +1 -1
  11. package/out/concepts/Assignee__.js +1 -1
  12. package/out/concepts/Assignee__.js.map +1 -1
  13. package/out/concepts/BindAttribute__.js +1 -1
  14. package/out/concepts/BindAttribute__.js.map +1 -1
  15. package/out/concepts/BindDirective__.js +1 -1
  16. package/out/concepts/BindDirective__.js.map +1 -1
  17. package/out/concepts/CallFunction__.js +16 -0
  18. package/out/concepts/CallFunction__.js.map +1 -1
  19. package/out/concepts/CallLogic__.js +3 -3
  20. package/out/concepts/CallLogic__.js.map +1 -1
  21. package/out/concepts/CallQueryComponent__.js +1 -1
  22. package/out/concepts/CallQueryComponent__.js.map +1 -1
  23. package/out/concepts/ConfigGroup__.js +1 -1
  24. package/out/concepts/ConfigGroup__.js.map +1 -1
  25. package/out/concepts/ConfigProperty__.js +1 -1
  26. package/out/concepts/ConfigProperty__.js.map +1 -1
  27. package/out/concepts/Configuration__.js +1 -1
  28. package/out/concepts/Configuration__.js.map +1 -1
  29. package/out/concepts/Destination__.js +5 -2
  30. package/out/concepts/Destination__.js.map +1 -1
  31. package/out/concepts/Entity__.d.ts +0 -3
  32. package/out/concepts/Entity__.js +2 -14
  33. package/out/concepts/Entity__.js.map +1 -1
  34. package/out/concepts/Event__.js +1 -1
  35. package/out/concepts/Event__.js.map +1 -1
  36. package/out/concepts/ForEachStatement__.d.ts +1 -1
  37. package/out/concepts/ForEachStatement__.js +2 -2
  38. package/out/concepts/ForEachStatement__.js.map +1 -1
  39. package/out/concepts/Function__.js +4 -4
  40. package/out/concepts/Function__.js.map +1 -1
  41. package/out/concepts/Interface__.js +2 -2
  42. package/out/concepts/Interface__.js.map +1 -1
  43. package/out/concepts/Logic__.d.ts +4 -0
  44. package/out/concepts/Logic__.js +18 -4
  45. package/out/concepts/Logic__.js.map +1 -1
  46. package/out/concepts/MemberExpression__.js +0 -1
  47. package/out/concepts/MemberExpression__.js.map +1 -1
  48. package/out/concepts/Module__.js +8 -8
  49. package/out/concepts/Module__.js.map +1 -1
  50. package/out/concepts/Namespace__.js +12 -12
  51. package/out/concepts/Namespace__.js.map +1 -1
  52. package/out/concepts/ProcessComponent__.js +2 -2
  53. package/out/concepts/ProcessComponent__.js.map +1 -1
  54. package/out/concepts/ProcessElement__.js +5 -5
  55. package/out/concepts/ProcessElement__.js.map +1 -1
  56. package/out/concepts/Process__.js +4 -4
  57. package/out/concepts/Process__.js.map +1 -1
  58. package/out/concepts/QueryJoinExpression__.js +1 -1
  59. package/out/concepts/QueryJoinExpression__.js.map +1 -1
  60. package/out/concepts/QueryLimitExpression__.js +1 -1
  61. package/out/concepts/QueryLimitExpression__.js.map +1 -1
  62. package/out/concepts/QuerySelectExpression__.js +1 -1
  63. package/out/concepts/QuerySelectExpression__.js.map +1 -1
  64. package/out/concepts/Structure__.js +2 -2
  65. package/out/concepts/Structure__.js.map +1 -1
  66. package/out/concepts/TypeAnnotation__.js +1 -1
  67. package/out/concepts/TypeAnnotation__.js.map +1 -1
  68. package/out/concepts/ViewComponent__.js +5 -5
  69. package/out/concepts/ViewComponent__.js.map +1 -1
  70. package/out/concepts/ViewElement__.js +3 -3
  71. package/out/concepts/ViewElement__.js.map +1 -1
  72. package/out/concepts/View__.d.ts +2 -0
  73. package/out/concepts/View__.js +13 -5
  74. package/out/concepts/View__.js.map +1 -1
  75. package/out/enums/KEYWORDS.js +0 -2
  76. package/out/enums/KEYWORDS.js.map +1 -1
  77. package/out/server/getScope.d.ts +2 -1
  78. package/out/server/getScope.js +26 -14
  79. package/out/server/getScope.js.map +1 -1
  80. package/out/server/naslServer.js +39 -18
  81. package/out/server/naslServer.js.map +1 -1
  82. package/out/service/storage/init.js +13 -0
  83. package/out/service/storage/init.js.map +1 -1
  84. package/out/test/integration/connect-file copy.d.ts +1 -0
  85. package/out/test/integration/connect-file copy.js +50 -0
  86. package/out/test/integration/connect-file copy.js.map +1 -0
  87. package/out/test/integration/node-nasl-server.d.ts +1 -0
  88. package/out/test/integration/node-nasl-server.js +41 -0
  89. package/out/test/integration/node-nasl-server.js.map +1 -0
  90. package/out/utils/index.js +6 -1
  91. package/out/utils/index.js.map +1 -1
  92. package/out/utils/string.d.ts +1 -1
  93. package/out/utils/string.js +38 -9
  94. package/out/utils/string.js.map +1 -1
  95. package/package.json +1 -1
  96. package/src/automate/engine/index.js +26 -127
  97. package/src/automate/engine/operators.js +63 -0
  98. package/src/automate/engine/uniqueName.js +36 -0
  99. package/src/concepts/App__.ts +9 -9
  100. package/src/concepts/Assignee__.ts +1 -1
  101. package/src/concepts/BindAttribute__.ts +1 -1
  102. package/src/concepts/BindDirective__.ts +1 -1
  103. package/src/concepts/CallFunction__.ts +16 -0
  104. package/src/concepts/CallLogic__.ts +34 -3
  105. package/src/concepts/CallQueryComponent__.ts +1 -1
  106. package/src/concepts/ConfigGroup__.ts +1 -1
  107. package/src/concepts/ConfigProperty__.ts +1 -1
  108. package/src/concepts/Configuration__.ts +1 -1
  109. package/src/concepts/Destination__.ts +7 -3
  110. package/src/concepts/Entity__.ts +2 -14
  111. package/src/concepts/Event__.ts +1 -1
  112. package/src/concepts/ForEachStatement__.ts +2 -2
  113. package/src/concepts/Function__.ts +4 -4
  114. package/src/concepts/Interface__.ts +2 -2
  115. package/src/concepts/Logic__.ts +19 -4
  116. package/src/concepts/MemberExpression__.ts +0 -1
  117. package/src/concepts/Module__.ts +8 -8
  118. package/src/concepts/Namespace__.ts +12 -12
  119. package/src/concepts/ProcessComponent__.ts +2 -2
  120. package/src/concepts/ProcessElement__.ts +5 -5
  121. package/src/concepts/Process__.ts +4 -4
  122. package/src/concepts/QueryJoinExpression__.ts +1 -1
  123. package/src/concepts/QueryLimitExpression__.ts +10 -1
  124. package/src/concepts/QuerySelectExpression__.ts +1 -1
  125. package/src/concepts/Structure__.ts +2 -2
  126. package/src/concepts/TypeAnnotation__.ts +1 -1
  127. package/src/concepts/ViewComponent__.ts +5 -5
  128. package/src/concepts/ViewElement__.ts +3 -3
  129. package/src/concepts/View__.ts +13 -5
  130. package/src/enums/KEYWORDS.ts +0 -2
  131. package/src/server/getScope.ts +36 -24
  132. package/src/server/naslServer.ts +37 -18
  133. package/src/service/storage/init.ts +13 -0
  134. package/src/utils/index.ts +6 -1
  135. package/src/utils/string.ts +39 -9
@@ -370,8 +370,12 @@ export class View extends BaseNode {
370
370
  }
371
371
 
372
372
 
373
+ getParamExistingNames(excludedList: Array<Param> = []) {
374
+ const excludedSet = new Set(excludedList);
375
+ return (this.params || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
376
+ }
373
377
  getParamUniqueName(name = 'param1') {
374
- return utils.unique(name, this.getVarExistingNames());
378
+ return utils.unique(name, this.getParamExistingNames(), undefined, false);
375
379
  }
376
380
 
377
381
  /**
@@ -508,8 +512,12 @@ export class View extends BaseNode {
508
512
  }
509
513
 
510
514
 
515
+ getVariableExistingNames(excludedList: Array<Variable> = []) {
516
+ const excludedSet = new Set(excludedList);
517
+ return (this.variables || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
518
+ }
511
519
  getVariableUniqueName(name = 'variable1') {
512
- return utils.unique(name, this.getVarExistingNames());
520
+ return utils.unique(name, this.getVariableExistingNames(), undefined, false);
513
521
  }
514
522
 
515
523
  /**
@@ -651,7 +659,7 @@ export class View extends BaseNode {
651
659
  return (this.logics || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
652
660
  }
653
661
  getLogicUniqueName(name = 'logic1') {
654
- return utils.unique(name, this.getLogicExistingNames());
662
+ return utils.unique(name, this.getLogicExistingNames(), undefined, false);
655
663
  }
656
664
 
657
665
  /**
@@ -793,7 +801,7 @@ export class View extends BaseNode {
793
801
  return (this.bindEvents || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
794
802
  }
795
803
  getBindEventUniqueName(name = 'bindEvent1') {
796
- return utils.unique(name, this.getBindEventExistingNames());
804
+ return utils.unique(name, this.getBindEventExistingNames(), undefined, false);
797
805
  }
798
806
 
799
807
  /**
@@ -937,7 +945,7 @@ export class View extends BaseNode {
937
945
  return (this.children || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
938
946
  }
939
947
  getViewUniqueName(name = 'view1') {
940
- return utils.unique(name, this.getViewExistingNames());
948
+ return utils.unique(name, this.getViewExistingNames(), undefined, false);
941
949
  }
942
950
 
943
951
  /**
@@ -130,8 +130,6 @@ export const KEYWORDS = [
130
130
  'out',
131
131
  'override',
132
132
  'package',
133
- 'param',
134
- 'params',
135
133
  'path',
136
134
  'pc',
137
135
  'private',
@@ -1,4 +1,4 @@
1
- import { Logic, View, Process } from "..";
1
+ import { Logic, View, Process } from '..';
2
2
 
3
3
  type wordScope = {
4
4
  Param?: string[]
@@ -7,44 +7,56 @@ type wordScope = {
7
7
  Constant?: string[]
8
8
  }
9
9
 
10
- export function getLogicScopeWords(logic: Logic): wordScope{
10
+ export function getLogicScopeWords(logic: Logic): wordScope {
11
11
  const scope: wordScope = {
12
- Param: logic.params.map(p => p.name),
13
- Return: logic.returns.map(p => p.name),
14
- Variable: logic.variables.map(p => p.name),
15
- }
12
+ Param: logic.params.map((p) => p.name),
13
+ Return: logic.returns.map((p) => p.name),
14
+ Variable: logic.variables.map((p) => p.name),
15
+ Constant: [],
16
+ };
16
17
  return scope;
17
18
  }
18
19
 
19
- export function getViewScopeWords(view: View): wordScope{
20
+ export function getViewScopeWords(view: View): wordScope {
20
21
  const scope: wordScope = {
21
- Param: view.params.map(p => p.name),
22
- // returns: View.returns.map(p => p.name),
23
- Variable: view.variables.map(p => p.name),
24
- }
22
+ Param: view.params.map((p) => p.name),
23
+ Variable: view.variables.map((p) => p.name),
24
+ Return: [],
25
+ Constant: [],
26
+ };
25
27
  return scope;
26
28
  }
27
29
 
28
- export function getProcessScopeWords(process: Process): wordScope{
30
+ export function getProcessScopeWords(process: Process): wordScope {
29
31
  const processName = process.name;
30
32
  const scope: wordScope = {
31
- Param: process.params.map(p => `${processName}.${p.name}`),
32
- Return: process.returns.map(p => `${processName}.${p.name}`),
33
- Constant: process.constants.map(p => `${processName}.${p.name}`),
33
+ Param: process.params.map((p) => `${processName}.${p.name}`),
34
+ Return: process.returns.map((p) => `${processName}.${p.name}`),
35
+ Constant: process.constants.map((p) => `${processName}.${p.name}`),
34
36
  Variable: [],
35
- }
37
+ };
36
38
 
37
- process.elements.forEach(el => {
39
+ process.elements.forEach((el) => {
38
40
  const elname = el.name;
39
- el.variables.forEach(v => {
40
- scope.Variable.push(`${processName}.${elname}.${v.name}`)
41
+ el.variables.forEach((v) => {
42
+ scope.Variable.push(`${processName}.${elname}.${v.name}`);
41
43
  });
42
- el.returns.forEach(v => {
43
- scope.Return.push(`${processName}.${elname}.${v.name}`)
44
+ el.returns.forEach((v) => {
45
+ scope.Return.push(`${processName}.${elname}.${v.name}`);
44
46
  });
45
- el.constants.forEach(v => {
46
- scope.Constant.push(`${processName}.${elname}.${v.name}`)
47
+ el.constants.forEach((v) => {
48
+ scope.Constant.push(`${processName}.${elname}.${v.name}`);
47
49
  });
48
- })
50
+ });
51
+ return scope;
52
+ }
53
+
54
+ export function combineScope(a: wordScope, b: wordScope) : wordScope {
55
+ const scope: wordScope = {
56
+ Param: [...a.Param, ...b.Param],
57
+ Return: [...a.Return, ...b.Return],
58
+ Constant: [...a.Constant, ...b.Constant],
59
+ Variable: [...a.Variable, ...b.Variable],
60
+ };
49
61
  return scope;
50
62
  }
@@ -798,19 +798,26 @@ const naslServer = {
798
798
  }
799
799
  // 如果节点是MemberExpression表达式
800
800
  if (minRange.node instanceof MemberExpression) {
801
- // 匹配到的内容,当前这一行的内容;
802
- // 因为要用下面的点位信息
803
- const a = record.lineText;
804
- // 之前的内容
805
- const oldValue = minRange.node.getValue();
806
- const index = a.indexOf(oldValue);
807
- const start = record.start.offset - index - 1;
808
- const end = record.end.offset - index - 1;
809
- const newTextValue = oldValue.substring(0, start) + newValue + oldValue.substring(end, oldValue.length);
810
- // MemberExpression可能改的是多层中的某一个
811
- // 倒序, 对比看是哪里发生了修改
812
- // 比较特殊就把新匹配到的值返回内部自己看要改那个地方的值
813
- minRange.newValue = newTextValue;
801
+ // 枚举key的特殊性,因为它不是原来的key+value形式的
802
+ // 是加了中括号啥的,所以直接赋值新值
803
+ if (node instanceof EnumItem) {
804
+ const newTextValue = node.parentNode.name + '.' + newValue;
805
+ minRange.newValue = newTextValue;
806
+ } else {
807
+ // 匹配到的内容,当前这一行的内容;
808
+ // 因为要用下面的点位信息
809
+ const a = record.lineText;
810
+ // 之前的内容
811
+ const oldValue = minRange.node.getValue();
812
+ const index = a.indexOf(oldValue);
813
+ const start = record.start.offset - index - 1;
814
+ const end = record.end.offset - index - 1;
815
+ const newTextValue = oldValue.substring(0, start) + newValue + oldValue.substring(end, oldValue.length);
816
+ // MemberExpression可能改的是多层中的某一个
817
+ // 倒序, 对比看是哪里发生了修改
818
+ // 比较特殊就把新匹配到的值返回内部自己看要改那个地方的值
819
+ minRange.newValue = newTextValue;
820
+ }
814
821
  }
815
822
  // 如果是修改实体,引发节点依赖实体发生改变的
816
823
  if (minRange.node instanceof EntityProperty && node instanceof Entity) {
@@ -936,6 +943,10 @@ const naslServer = {
936
943
  const newBindRoles = str.split(',');
937
944
  minRange.newValue = newBindRoles;
938
945
  }
946
+ // 修改枚举值找到了EntityProperty就说明给了默认值
947
+ if (minRange.node instanceof EntityProperty && node instanceof EnumItem) {
948
+ minRange.setTypeMethods = 'setDefaultValue';
949
+ }
939
950
  if (minRange.node instanceof QueryFieldExpression && node instanceof Entity) {
940
951
  minRange.setTypeMethods = 'setEntityAsName';
941
952
  }
@@ -1387,11 +1398,19 @@ BaseNode.prototype.changeName = async function changeName(newValue: string, upda
1387
1398
  * 先修改之
1388
1399
  */
1389
1400
  const closeCallBack = () => {
1390
- const oldValue = this.name;
1391
- this.name = oldValue + ' ';
1392
- setTimeout(() => {
1393
- this.name = oldValue;
1394
- }, 0);
1401
+ if (this.concept === 'EnumItem') {
1402
+ const oldValue = (this as EnumItem).value;
1403
+ (this as EnumItem).value = oldValue + ' ';
1404
+ setTimeout(() => {
1405
+ (this as EnumItem).value = oldValue;
1406
+ }, 0);
1407
+ } else {
1408
+ const oldValue = this.name;
1409
+ this.name = oldValue + ' ';
1410
+ setTimeout(() => {
1411
+ this.name = oldValue;
1412
+ }, 0);
1413
+ }
1395
1414
  };
1396
1415
  updateAll ? callback(true) : invokeCommand('tsConfirm.open', confirmParms, callback, closeCallBack);
1397
1416
 
@@ -256,6 +256,7 @@ function handleApp(app: any) {
256
256
  app._historyList = [];
257
257
  app._historyIndex = 0;
258
258
  app._historying = false;
259
+ app._timer = null;
259
260
 
260
261
  app.on('undo', () => {
261
262
  app._historying = true;
@@ -269,6 +270,15 @@ function handleApp(app: any) {
269
270
  * 开启收集
270
271
  */
271
272
  app.on('collect:start', (event: any) => {
273
+ if (app._timer) {
274
+ clearTimeout(app._timer);
275
+ }
276
+ if (!event.noTimer) {
277
+ app._timer = setTimeout(() => {
278
+ console.error('收集超时,请及时排查原因');
279
+ app.emit('refresh');
280
+ }, 800);
281
+ }
272
282
  if (!app._isCollectingCount) {
273
283
  app._actionMsg = event?.actionMsg;
274
284
  app._action = event?.action;
@@ -282,6 +292,9 @@ function handleApp(app: any) {
282
292
  app.on('collect:end', async () => {
283
293
  app._isCollectingCount--;
284
294
  if (app._isCollectingCount === 0) {
295
+ if (app._timer) {
296
+ clearTimeout(app._timer);
297
+ }
285
298
  if (Array.isArray(app._collectingList) && app._collectingList.length) {
286
299
  embeddedTSEmitter.emit('change', {
287
300
  value: app._collectingList,
@@ -37,6 +37,9 @@ export const waitPromise = (wait: number) => new Promise((res) => setTimeout(()
37
37
 
38
38
  // 官方扩展组件暂时不包含 css 文件
39
39
  export const officialCustoms = [
40
+ 'u-sider-modal',
41
+ 'timer-count-down',
42
+ 'u-calendar-table',
40
43
  'lcap-login',
41
44
  'lcap-video',
42
45
  'lcap-amap-nav',
@@ -45,12 +48,14 @@ export const officialCustoms = [
45
48
  'lcap-echarts-line',
46
49
  'lcap-echarts-pie',
47
50
  'lcap-report',
48
- 'lcap-h5-iframe',
49
51
  'lcap-wang-editor',
52
+ 'lcap-clock',
50
53
  ];
51
54
  // 特殊官方组件,部分低版本有 css,高版本没有 css
52
55
  export const specialOfficialCustoms = [{ name: 'lcap-rich-text-editor', version: '1.3.10' }];
56
+ // lcap-h5 开头表示官方 H5 扩展组件
53
57
  export const shouldLoadCss = (name: string, version: string): boolean => (!officialCustoms.includes(name)
58
+ && !/lcap-h5/.test(name)
54
59
  && !specialOfficialCustoms.find((extra) => extra.name === name && compare(version, extra.version, '>=')));
55
60
 
56
61
  // https://github.com/Microsoft/TypeScript/issues/27024#issuecomment-421529650
@@ -27,15 +27,45 @@ export const firstLowerCase = (value: string) => value.replace(/^\S/, (letter) =
27
27
  * @param set 数据集合,Array | Map | Set
28
28
  * @param start 数字起始
29
29
  */
30
- export function unique(key: string, set: Set<string> | Map<string, any> | Array<string> | { [name: string]: string }, start: number = 1) {
31
- const has = (_key: string) => {
32
- if (set instanceof Set || set instanceof Map)
33
- return set.has(_key);
34
- else if (Array.isArray(set))
35
- return set.includes(_key);
36
- else
37
- return set[_key];
38
- };
30
+ export function unique(key: string,
31
+ set: Set<string> | Map<string, any> | Array<string> | { [name: string]: string },
32
+ start: number = 1,
33
+ insensitive: boolean = false) {
34
+ let has;
35
+ if (insensitive) {
36
+ has = (_key: string) => {
37
+ const lkey = _key.toLowerCase();
38
+ if (set instanceof Set || set instanceof Map) {
39
+ // return set.has(_key);
40
+ const iterator = set.keys();
41
+ let i = iterator.next();
42
+ while (!i.done) {
43
+ const name = i.value;
44
+ if (name.toLowerCase() === lkey) {
45
+ return true;
46
+ }
47
+ i = iterator.next();
48
+ }
49
+ return false;
50
+ } else if (Array.isArray(set))
51
+ // return set.includes(_key);
52
+ return set.some((s) => s.toLowerCase() === lkey);
53
+ else {
54
+ // return set[_key];
55
+ const keys = Object.keys(set);
56
+ return keys.some((k) => k.toLowerCase() === lkey);
57
+ }
58
+ };
59
+ } else {
60
+ has = (_key: string) => {
61
+ if (set instanceof Set || set instanceof Map)
62
+ return set.has(_key);
63
+ else if (Array.isArray(set))
64
+ return set.includes(_key);
65
+ else
66
+ return set[_key];
67
+ };
68
+ }
39
69
 
40
70
  while (has(key))
41
71
  key = key.replace(/\d*$/, (m) => String(m === '' ? start : +m + 1));