@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
@@ -32,15 +32,44 @@ exports.firstLowerCase = firstLowerCase;
32
32
  * @param set 数据集合,Array | Map | Set
33
33
  * @param start 数字起始
34
34
  */
35
- function unique(key, set, start = 1) {
36
- const has = (_key) => {
37
- if (set instanceof Set || set instanceof Map)
38
- return set.has(_key);
39
- else if (Array.isArray(set))
40
- return set.includes(_key);
41
- else
42
- return set[_key];
43
- };
35
+ function unique(key, set, start = 1, insensitive = false) {
36
+ let has;
37
+ if (insensitive) {
38
+ has = (_key) => {
39
+ const lkey = _key.toLowerCase();
40
+ if (set instanceof Set || set instanceof Map) {
41
+ // return set.has(_key);
42
+ const iterator = set.keys();
43
+ let i = iterator.next();
44
+ while (!i.done) {
45
+ const name = i.value;
46
+ if (name.toLowerCase() === lkey) {
47
+ return true;
48
+ }
49
+ i = iterator.next();
50
+ }
51
+ return false;
52
+ }
53
+ else if (Array.isArray(set))
54
+ // return set.includes(_key);
55
+ return set.some((s) => s.toLowerCase() === lkey);
56
+ else {
57
+ // return set[_key];
58
+ const keys = Object.keys(set);
59
+ return keys.some((k) => k.toLowerCase() === lkey);
60
+ }
61
+ };
62
+ }
63
+ else {
64
+ has = (_key) => {
65
+ if (set instanceof Set || set instanceof Map)
66
+ return set.has(_key);
67
+ else if (Array.isArray(set))
68
+ return set.includes(_key);
69
+ else
70
+ return set[_key];
71
+ };
72
+ }
44
73
  while (has(key))
45
74
  key = key.replace(/\d*$/, (m) => String(m === '' ? start : +m + 1));
46
75
  return key;
@@ -1 +1 @@
1
- {"version":3,"file":"string.js","sourceRoot":"","sources":["../../src/utils/string.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACI,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;AAAnG,QAAA,WAAW,eAAwF;AAEhH;;;;GAIG;AACI,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;AAA3H,QAAA,WAAW,eAAgH;AACxI;;;GAGG;AACI,MAAM,cAAc,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;AAA3F,QAAA,cAAc,kBAA6E;AACxG;;;GAGG;AACI,MAAM,cAAc,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;AAA3F,QAAA,cAAc,kBAA6E;AAExG;;;;GAIG;AACH,SAAgB,MAAM,CAAC,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1",
5
5
  "author": "Forrest <rainforest92@126.com>",
6
6
  "scripts": {
7
7
  "dev": "tsc -watch -p ./",
@@ -2,6 +2,10 @@ import { uniq, omit } from 'lodash';
2
2
  import { BaseNode } from '../../common/BaseNode';
3
3
  import { tracking, TRACK_TYPE, IGNORE_PROPERTY } from './utils';
4
4
  import { getConceptConstructor, getConceptMeta } from '../../decorators/index';
5
+ // import { unique, firstUpperCase } from '../../utils/string';
6
+ import uniqueNameModule from './uniqueName';
7
+ import operatorModule from './operators';
8
+
5
9
  let id = 0;
6
10
  class TemplateMeta {
7
11
  constructor(node) {
@@ -168,7 +172,7 @@ class TemplateMeta {
168
172
  // return `_set(${this.name}, "name", getGenUniqNameFunctionName(${this.name}, "${this.node.concept}"));`;
169
173
  // _setTableName(${this.name}, ${this.name}.name + '_' + app.id.slice(0,6));`;
170
174
  // }
171
- return `_set(${this.name}, "name", getGenUniqNameFunctionName(${this.name}, "${this.node.concept}", app), (updatedObj) => { ${this.name} = updatedObj; })`;
175
+ return `_set(${this.name}, "name", _uniqueName.getGenUniqNameFunctionName(${this.name}, "${this.node.concept}", app), (updatedObj) => { ${this.name} = updatedObj; })`;
172
176
  }
173
177
 
174
178
  genRoleBind() {
@@ -245,126 +249,7 @@ function autoScript(stack) {
245
249
 
246
250
  return `
247
251
  (function () {
248
- function unique(key, set, start = 1) {
249
- const has = (_key) => {
250
- if (set instanceof Set || set instanceof Map)
251
- return set.has(_key);
252
- else if (Array.isArray(set))
253
- return set.includes(_key);
254
- else
255
- return set[_key];
256
- };
257
-
258
- while (has(key))
259
- key = key.replace(/\\d*$/, (m) => String(m === '' ? start : (+m) + 1));
260
- return key;
261
- }
262
-
263
- function alphaUpper(name) {
264
- if (!name) {
265
- return '';
266
- }
267
- return name[0].toUpperCase() + name.substring(1);
268
- }
269
-
270
- const NamesWeakMap = new Map();
271
-
272
- function initAppUniqueNames(app) {
273
- NamesWeakMap.set('Entity', new Set(app.getEntityExistingNames()));
274
- NamesWeakMap.set('Structure', new Set(app.getStructureExistingNames()));
275
- NamesWeakMap.set('Enum', new Set(app.getEnumExistingNames()));
276
- NamesWeakMap.set('Logic', new Set(app.getLogicExistingNames()));
277
- NamesWeakMap.set('Interface', new Set(app.getInterfaceExistingNames()));
278
- NamesWeakMap.set('View', new Set(app.getViewExistingNames()));
279
- NamesWeakMap.set('Process', new Set(app.getProcessExistingNames()));
280
- NamesWeakMap.set('Role', new Set(app.getRoleExistingNames()));
281
- }
282
-
283
- function getGenUniqNameFunctionName(item, concept, app) {
284
- const p = item.parentNode;
285
- if(!p) {
286
- const nameSet = NamesWeakMap.get(concept);
287
- const n = unique(item.name, nameSet);
288
- nameSet.add(n);
289
- return n;
290
- }
291
- const f1 = p["get" + concept + "UniqueName"];
292
- const f2 = p["get" + concept + "ExistingNames"]
293
- if(f1 && f2) {
294
- const names = f2.call(p);
295
- const t = names.filter(n => n === item.name);
296
- if(t.length > 1) {
297
- return f1.call(p, item.name);
298
- }
299
- }
300
- return item.name;
301
- }
302
-
303
- let BaseNodeConstructor;
304
- let getConceptConstructor;
305
- let getConceptMeta;
306
-
307
- function instanceOfBaseNode(item) {
308
- return (item instanceof BaseNodeConstructor);
309
- }
310
-
311
- function _set(item, propertyName, value, callback) {
312
- if(instanceOfBaseNode(value)) {
313
- value.parentNode = item;
314
- value.parentKey = propertyName;
315
- }
316
- if(item[propertyName] !== value) {
317
- item.update({
318
- [propertyName]: value,
319
- });
320
-
321
- if(instanceOfBaseNode(value) && callback) {
322
- callback(item[propertyName]);
323
- }
324
- }
325
- }
326
-
327
- function _push(item, propertyName, value) {
328
- if(!item[propertyName]){
329
- item[propertyName] = [];
330
- }
331
- value.parentNode = item;
332
- value.parentKey = propertyName;
333
- item[propertyName].push(value);
334
- const index = item[propertyName].length;
335
- value.create({
336
- index,
337
- parentNode: item,
338
- parentKey: propertyName,
339
- });
340
- }
341
-
342
- function _create(concept) {
343
- const _ctor = getConceptConstructor(concept);
344
- const item = new _ctor();
345
- const { propertyMap } = getConceptMeta(concept);
346
- for(const p of propertyMap) {
347
- const [propertyName] = p;
348
- const t = item[propertyName];
349
- if(Array.isArray(t)) {
350
- _set(item, propertyName, []);
351
- }
352
- }
353
- return item;
354
- }
355
-
356
- function _addModule(app, name, belongs, data) {
357
- const ms = app[belongs];
358
- const exist = ms.find(m => m.name === name);
359
- if(!exist) {
360
- app["addModuleIn" + alphaUpper(belongs)](data);
361
- }
362
- }
363
-
364
- function _bindRoles(){
365
- return Array.prototype.map.call(arguments, r => r.name);
366
- }
367
- // let _tempConstructor;
252
+ const injectModule = {};
368
253
 
369
254
  const exportRoles = function() {
370
255
  return ${JSON.stringify(roleNASL)};
@@ -372,11 +257,17 @@ function autoScript(stack) {
372
257
 
373
258
  const execTemplate = function(app, getCtor, getCMeta, base, rootBindCallback, roleCallback, finalCallback) {
374
259
  let _templateObjects = [];
375
- BaseNodeConstructor = base;
376
- getConceptConstructor = getCtor;
377
- getConceptMeta = getCMeta;
260
+ const {
261
+ _set,
262
+ _push,
263
+ _create,
264
+ _addModule,
265
+ _bindRoles
266
+ } = injectModule.operators;
378
267
 
379
- initAppUniqueNames(app);
268
+ const _uniqueName = new injectModule.uniqueName();
269
+
270
+ _uniqueName.initAppUniqueNames(app);
380
271
 
381
272
  app.emit('collect:start', {
382
273
  actionMsg: '导入页面模板'
@@ -420,7 +311,10 @@ function autoScript(stack) {
420
311
 
421
312
  return {
422
313
  execTemplate,
423
- exportRoles
314
+ exportRoles,
315
+ importModule(key, m) {
316
+ injectModule[key] = m;
317
+ },
424
318
  }
425
319
  })();`;
426
320
  }
@@ -527,6 +421,11 @@ export function getRoles(script) {
527
421
  return exportRoles();
528
422
  }
529
423
  export function applyTemplate(script, app, rootBindCallback, roleCallback, finalCallback) {
530
- const { execTemplate } = eval(script);
424
+ const { execTemplate, importModule } = eval(script);
425
+ // 为了兼容 2.11 老模板
426
+ if(importModule) {
427
+ importModule('operators', operatorModule);
428
+ importModule('uniqueName', uniqueNameModule);
429
+ }
531
430
  execTemplate(app, getConceptConstructor, getConceptMeta, BaseNode, rootBindCallback, roleCallback, finalCallback);
532
431
  }
@@ -0,0 +1,63 @@
1
+ import { BaseNode } from '../../common/BaseNode';
2
+ import { getConceptConstructor, getConceptMeta } from '../../decorators/index';
3
+ import { firstUpperCase } from '../../utils/string';
4
+
5
+ function instanceOfBaseNode(item) {
6
+ return (item instanceof BaseNode);
7
+ }
8
+ const ops = {
9
+ _set(item, propertyName, value, callback) {
10
+ if(instanceOfBaseNode(value)) {
11
+ value.parentNode = item;
12
+ value.parentKey = propertyName;
13
+ }
14
+ if(item[propertyName] !== value) {
15
+ item.update({
16
+ [propertyName]: value,
17
+ });
18
+
19
+ if(instanceOfBaseNode(value) && callback) {
20
+ callback(item[propertyName]);
21
+ }
22
+ }
23
+ },
24
+ _push(item, propertyName, value) {
25
+ if(!item[propertyName]){
26
+ item[propertyName] = [];
27
+ }
28
+ value.parentNode = item;
29
+ value.parentKey = propertyName;
30
+ item[propertyName].push(value);
31
+ const index = item[propertyName].length;
32
+ value.create({
33
+ index,
34
+ parentNode: item,
35
+ parentKey: propertyName,
36
+ });
37
+ },
38
+ _create(concept) {
39
+ const _ctor = getConceptConstructor(concept);
40
+ const item = new _ctor();
41
+ const { propertyMap } = getConceptMeta(concept);
42
+ for(const p of propertyMap) {
43
+ const [propertyName] = p;
44
+ const t = item[propertyName];
45
+ if(Array.isArray(t)) {
46
+ ops._set(item, propertyName, []);
47
+ }
48
+ }
49
+ return item;
50
+ },
51
+ _addModule(app, name, belongs, data) {
52
+ const ms = app[belongs];
53
+ const exist = ms.find(m => m.name === name);
54
+ if(!exist) {
55
+ app["addModuleIn" + firstUpperCase(belongs)](data);
56
+ }
57
+ },
58
+ _bindRoles(){
59
+ return Array.prototype.map.call(arguments, r => r.name);
60
+ }
61
+ }
62
+
63
+ export default ops;
@@ -0,0 +1,36 @@
1
+ import { unique } from '../../utils/string';
2
+ class uniqueName {
3
+ NamesWeakMap = new Map();
4
+ initAppUniqueNames(app) {
5
+ const NamesWeakMap = this.NamesWeakMap;
6
+ NamesWeakMap.set('Entity', new Set(app.getEntityExistingNames()));
7
+ NamesWeakMap.set('Structure', new Set(app.getStructureExistingNames()));
8
+ NamesWeakMap.set('Enum', new Set(app.getEnumExistingNames()));
9
+ NamesWeakMap.set('Logic', new Set(app.getLogicExistingNames()));
10
+ NamesWeakMap.set('Interface', new Set(app.getInterfaceExistingNames()));
11
+ NamesWeakMap.set('View', new Set(app.getViewExistingNames()));
12
+ NamesWeakMap.set('Process', new Set(app.getProcessExistingNames()));
13
+ NamesWeakMap.set('Role', new Set(app.getRoleExistingNames()));
14
+ }
15
+ getGenUniqNameFunctionName(item, concept) {
16
+ const p = item.parentNode;
17
+ const NamesWeakMap = this.NamesWeakMap;
18
+ if(!p) {
19
+ const nameSet = NamesWeakMap.get(concept);
20
+ const n = unique(item.name, nameSet, 1, true);
21
+ nameSet.add(n);
22
+ return n;
23
+ }
24
+ const f1 = p["get" + concept + "UniqueName"];
25
+ const f2 = p["get" + concept + "ExistingNames"]
26
+ if(f1 && f2) {
27
+ const names = f2.call(p);
28
+ const t = names.filter(n => n === item.name);
29
+ if(t.length > 1) {
30
+ return f1.call(p, item.name);
31
+ }
32
+ }
33
+ return item.name;
34
+ }
35
+ }
36
+ export default uniqueName;
@@ -242,7 +242,7 @@ export class App extends BaseNode {
242
242
  return (this.entities || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
243
243
  }
244
244
  getEntityUniqueName(name = 'Entity1') {
245
- return utils.unique(name, this.getEntityExistingNames());
245
+ return utils.unique(name, this.getEntityExistingNames(), undefined, true);
246
246
  }
247
247
 
248
248
  /**
@@ -384,7 +384,7 @@ export class App extends BaseNode {
384
384
  return (this.structures || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
385
385
  }
386
386
  getStructureUniqueName(name = 'Structure1') {
387
- return utils.unique(name, this.getStructureExistingNames());
387
+ return utils.unique(name, this.getStructureExistingNames(), undefined, true);
388
388
  }
389
389
 
390
390
  /**
@@ -526,7 +526,7 @@ export class App extends BaseNode {
526
526
  return (this.enums || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
527
527
  }
528
528
  getEnumUniqueName(name = 'Enum1') {
529
- return utils.unique(name, this.getEnumExistingNames());
529
+ return utils.unique(name, this.getEnumExistingNames(), undefined, true);
530
530
  }
531
531
 
532
532
  /**
@@ -668,7 +668,7 @@ export class App extends BaseNode {
668
668
  return (this.logics || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
669
669
  }
670
670
  getLogicUniqueName(name = 'logic1') {
671
- return utils.unique(name, this.getLogicExistingNames());
671
+ return utils.unique(name, this.getLogicExistingNames(), undefined, true);
672
672
  }
673
673
 
674
674
  /**
@@ -810,7 +810,7 @@ export class App extends BaseNode {
810
810
  return (this.interfaces || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
811
811
  }
812
812
  getInterfaceUniqueName(name = 'Interface1') {
813
- return utils.unique(name, this.getInterfaceExistingNames());
813
+ return utils.unique(name, this.getInterfaceExistingNames(), undefined, true);
814
814
  }
815
815
 
816
816
  /**
@@ -952,7 +952,7 @@ export class App extends BaseNode {
952
952
  return (this.views || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
953
953
  }
954
954
  getViewUniqueName(name = 'view1') {
955
- return utils.unique(name, this.getViewExistingNames());
955
+ return utils.unique(name, this.getViewExistingNames(), undefined, true);
956
956
  }
957
957
 
958
958
  /**
@@ -1094,7 +1094,7 @@ export class App extends BaseNode {
1094
1094
  return (this.processes || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
1095
1095
  }
1096
1096
  getProcessUniqueName(name = 'Process1') {
1097
- return utils.unique(name, this.getProcessExistingNames());
1097
+ return utils.unique(name, this.getProcessExistingNames(), undefined, true);
1098
1098
  }
1099
1099
 
1100
1100
  /**
@@ -1236,7 +1236,7 @@ export class App extends BaseNode {
1236
1236
  return (this.roles || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
1237
1237
  }
1238
1238
  getRoleUniqueName(name = 'role1') {
1239
- return utils.unique(name, this.getRoleExistingNames());
1239
+ return utils.unique(name, this.getRoleExistingNames(), undefined, true);
1240
1240
  }
1241
1241
 
1242
1242
  /**
@@ -1378,7 +1378,7 @@ export class App extends BaseNode {
1378
1378
  return (this.dependencies || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
1379
1379
  }
1380
1380
  getModuleUniqueName(name = 'module1') {
1381
- return utils.unique(name, this.getModuleExistingNames());
1381
+ return utils.unique(name, this.getModuleExistingNames(), undefined, false);
1382
1382
  }
1383
1383
 
1384
1384
  /**
@@ -71,7 +71,7 @@ export class Assignee extends LogicItem {
71
71
  return (this.dynamicUsers || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
72
72
  }
73
73
  getLogicItemUniqueName(name = 'logicItem1') {
74
- return utils.unique(name, this.getLogicItemExistingNames());
74
+ return utils.unique(name, this.getLogicItemExistingNames(), undefined, false);
75
75
  }
76
76
 
77
77
  /**
@@ -223,7 +223,7 @@ export class BindAttribute extends BaseNode {
223
223
  return (this.rules || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
224
224
  }
225
225
  getValidationRuleUniqueName(name = 'validationRule1') {
226
- return utils.unique(name, this.getValidationRuleExistingNames());
226
+ return utils.unique(name, this.getValidationRuleExistingNames(), undefined, false);
227
227
  }
228
228
 
229
229
  /**
@@ -218,7 +218,7 @@ export class BindDirective extends BaseNode {
218
218
  if (this.expression) {
219
219
  value = this.expression.toVue(options);
220
220
  if (this.expression.concept === 'StringLiteral') {
221
- value = `'${value}'`;
221
+ value = `${value}`;
222
222
  }
223
223
  value = value?.replace(/"/g, "'");
224
224
  }
@@ -380,6 +380,14 @@ export class CallFunction extends LogicItem {
380
380
  if (index !== this.arguments?.length - 1)
381
381
  code += ', ';
382
382
  });
383
+ if (this.typeArguments && this.typeArguments.length) {
384
+ code += ', ';
385
+ this.typeArguments?.forEach((arg, index) => {
386
+ code += arg?.toJS();
387
+ if (index !== this.arguments?.length - 1)
388
+ code += ', ';
389
+ });
390
+ }
383
391
  code += ')';
384
392
  return code;
385
393
  }
@@ -392,6 +400,14 @@ export class CallFunction extends LogicItem {
392
400
  if (index !== this.arguments?.length - 1)
393
401
  code += ', ';
394
402
  });
403
+ if (this.typeArguments && this.typeArguments.length) {
404
+ code += ', ';
405
+ this.typeArguments?.forEach((arg, index) => {
406
+ code += arg?.typeName;
407
+ if (index !== this.arguments?.length - 1)
408
+ code += ', ';
409
+ });
410
+ }
395
411
  code += ')';
396
412
  return code;
397
413
  }
@@ -66,6 +66,8 @@ export class CallLogic extends LogicItem {
66
66
  @property('Argument')
67
67
  arguments: Array<Argument> = [];
68
68
 
69
+
70
+
69
71
  /**
70
72
  * @param source 需要合并的部分参数
71
73
  */
@@ -79,6 +81,13 @@ export class CallLogic extends LogicItem {
79
81
  return super.from(source, parentNode, parentKey) as CallLogic;
80
82
  }
81
83
 
84
+
85
+
86
+
87
+
88
+
89
+
90
+
82
91
  /**
83
92
  * 插入类型标注
84
93
  * @internal
@@ -111,6 +120,8 @@ export class CallLogic extends LogicItem {
111
120
  return typeAnnotation;
112
121
  }
113
122
 
123
+
124
+
114
125
  /**
115
126
  * 插入类型标注
116
127
  * @param typeAnnotationOptions 类型标注参数
@@ -133,6 +144,8 @@ export class CallLogic extends LogicItem {
133
144
  return node;
134
145
  }
135
146
 
147
+
148
+
136
149
  /**
137
150
  * 添加类型标注
138
151
  * @internal
@@ -152,6 +165,8 @@ export class CallLogic extends LogicItem {
152
165
  return this._insertTypeAnnotationAt(options as any, index);
153
166
  }
154
167
 
168
+
169
+
155
170
  /**
156
171
  * 添加类型标注
157
172
  * @param typeAnnotationOptions 类型标注参数
@@ -175,6 +190,11 @@ export class CallLogic extends LogicItem {
175
190
  return node;
176
191
  }
177
192
 
193
+
194
+
195
+
196
+
197
+
178
198
  /**
179
199
  * 插入实际参数
180
200
  * @internal
@@ -207,6 +227,8 @@ export class CallLogic extends LogicItem {
207
227
  return argument;
208
228
  }
209
229
 
230
+
231
+
210
232
  /**
211
233
  * 插入实际参数
212
234
  * @param argumentOptions 实际参数参数
@@ -229,6 +251,8 @@ export class CallLogic extends LogicItem {
229
251
  return node;
230
252
  }
231
253
 
254
+
255
+
232
256
  /**
233
257
  * 添加实际参数
234
258
  * @internal
@@ -248,6 +272,8 @@ export class CallLogic extends LogicItem {
248
272
  return this._insertArgumentAt(options as any, index);
249
273
  }
250
274
 
275
+
276
+
251
277
  /**
252
278
  * 添加实际参数
253
279
  * @param argumentOptions 实际参数参数
@@ -271,6 +297,9 @@ export class CallLogic extends LogicItem {
271
297
  return node;
272
298
  }
273
299
 
300
+
301
+
302
+
274
303
  /**
275
304
  * 删除类型标注
276
305
  * @param typeAnnotation 已有的类型标注实例
@@ -278,7 +307,7 @@ export class CallLogic extends LogicItem {
278
307
  removeTypeAnnotation(typeAnnotation: TypeAnnotation): void;
279
308
 
280
309
  removeTypeAnnotation(options: TypeAnnotation) {
281
- const typeAnnotation: TypeAnnotation = options;
310
+ let typeAnnotation: TypeAnnotation = options;
282
311
  return typeAnnotation.delete();
283
312
  }
284
313
 
@@ -305,6 +334,8 @@ export class CallLogic extends LogicItem {
305
334
  return params;
306
335
  }
307
336
 
337
+
338
+
308
339
  /**
309
340
  * 删除实际参数
310
341
  * @param argument 已有的实际参数实例
@@ -312,7 +343,7 @@ export class CallLogic extends LogicItem {
312
343
  removeArgument(argument: Argument): void;
313
344
 
314
345
  removeArgument(options: Argument) {
315
- const argument: Argument = options;
346
+ let argument: Argument = options;
316
347
  return argument.delete();
317
348
  }
318
349
 
@@ -705,7 +736,7 @@ export class CallLogic extends LogicItem {
705
736
  //================================================================================
706
737
  }
707
738
 
708
- classMap.CallLogic = CallLogic;
739
+ classMap['CallLogic'] = CallLogic;
709
740
  export default CallLogic;
710
741
  //================================================================================
711
742
  // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
@@ -208,7 +208,7 @@ export class CallQueryComponent extends LogicItem {
208
208
  return (this.groupBy || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
209
209
  }
210
210
  getQueryGroupByExpressionUniqueName(name = 'queryGroupByExpression1') {
211
- return utils.unique(name, this.getQueryGroupByExpressionExistingNames());
211
+ return utils.unique(name, this.getQueryGroupByExpressionExistingNames(), undefined, false);
212
212
  }
213
213
 
214
214
  /**
@@ -84,7 +84,7 @@ export class ConfigGroup extends BaseNode {
84
84
  return (this.properties || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
85
85
  }
86
86
  getConfigPropertyUniqueName(name = 'configProperty1') {
87
- return utils.unique(name, this.getConfigPropertyExistingNames());
87
+ return utils.unique(name, this.getConfigPropertyExistingNames(), undefined, false);
88
88
  }
89
89
 
90
90
  /**
@@ -90,7 +90,7 @@ export class ConfigProperty extends BaseNode {
90
90
  return (this.values || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
91
91
  }
92
92
  getConfigPropertyValueUniqueName(name = 'configPropertyValue1') {
93
- return utils.unique(name, this.getConfigPropertyValueExistingNames());
93
+ return utils.unique(name, this.getConfigPropertyValueExistingNames(), undefined, false);
94
94
  }
95
95
 
96
96
  /**
@@ -68,7 +68,7 @@ export class Configuration extends BaseNode {
68
68
  return (this.groups || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
69
69
  }
70
70
  getConfigGroupUniqueName(name = 'configGroup1') {
71
- return utils.unique(name, this.getConfigGroupExistingNames());
71
+ return utils.unique(name, this.getConfigGroupExistingNames(), undefined, false);
72
72
  }
73
73
 
74
74
  /**