@lcap/nasl 2.18.0-beta.5 → 2.18.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 (88) hide show
  1. package/out/common/BaseNode.js +1 -0
  2. package/out/common/BaseNode.js.map +1 -1
  3. package/out/concepts/BatchAssignment__.js +63 -46
  4. package/out/concepts/BatchAssignment__.js.map +1 -1
  5. package/out/concepts/CallLogic__.d.ts +2 -1
  6. package/out/concepts/CallLogic__.js +26 -11
  7. package/out/concepts/CallLogic__.js.map +1 -1
  8. package/out/concepts/Destination__.d.ts +2 -1
  9. package/out/concepts/Destination__.js +90 -22
  10. package/out/concepts/Destination__.js.map +1 -1
  11. package/out/concepts/Logic__.js +6 -7
  12. package/out/concepts/Logic__.js.map +1 -1
  13. package/out/concepts/MatchExpression__.d.ts +97 -0
  14. package/out/concepts/MatchExpression__.js +281 -0
  15. package/out/concepts/MatchExpression__.js.map +1 -0
  16. package/out/concepts/ViewElement__.js +1 -1
  17. package/out/concepts/ViewElement__.js.map +1 -1
  18. package/out/concepts/View__.js +4 -0
  19. package/out/concepts/View__.js.map +1 -1
  20. package/out/generator/genBundleFiles.js +32 -182
  21. package/out/generator/genBundleFiles.js.map +1 -1
  22. package/out/generator/genMetaData.d.ts +1 -10
  23. package/out/generator/genMetaData.js +189 -50
  24. package/out/generator/genMetaData.js.map +1 -1
  25. package/out/generator/genReleaseBody.js +11 -2
  26. package/out/generator/genReleaseBody.js.map +1 -1
  27. package/out/server/extendBaseNode.js +4 -18
  28. package/out/server/extendBaseNode.js.map +1 -1
  29. package/out/server/formatTsUtils.d.ts +1 -2
  30. package/out/server/formatTsUtils.js +30 -47
  31. package/out/server/formatTsUtils.js.map +1 -1
  32. package/out/server/getProcesses.js +1 -1
  33. package/out/server/getProcesses.js.map +1 -1
  34. package/out/server/naslServer.js +8 -7
  35. package/out/server/naslServer.js.map +1 -1
  36. package/out/server/translator.js +19 -4
  37. package/out/server/translator.js.map +1 -1
  38. package/out/templator/sql-parser/index.d.ts +1 -0
  39. package/out/templator/sql-parser/index.js +228 -0
  40. package/out/templator/sql-parser/index.js.map +1 -0
  41. package/out/templator/sql-parser/parser.js +26664 -0
  42. package/out/templator/sql-parser/parser.js.map +1 -0
  43. package/package.json +2 -2
  44. package/sandbox/stdlib/dist/nasl.logging.js +0 -0
  45. package/sandbox/stdlib/nasl.util.ts +1 -1
  46. package/src/automate/engine/dist/index.dev.js +517 -0
  47. package/src/common/BaseNode.ts +1 -0
  48. package/src/common/dist/BaseNode.js +1101 -0
  49. package/src/concepts/BatchAssignment__.ts +66 -50
  50. package/src/concepts/CallLogic__.ts +26 -11
  51. package/src/concepts/Destination__.ts +92 -22
  52. package/src/concepts/Logic__.ts +6 -7
  53. package/src/concepts/ViewElement__.ts +8 -29
  54. package/src/concepts/View__.ts +4 -0
  55. package/src/concepts/basics/stdlib/dist/nasl.util.js +1503 -0
  56. package/src/concepts/basics/stdlib/dist/reference2TypeAnnotationList.js +24 -0
  57. package/src/concepts/dist/Anchor__.js +179 -0
  58. package/src/concepts/dist/Assignment__.js +301 -0
  59. package/src/concepts/dist/CallFunction__.js +513 -0
  60. package/src/concepts/dist/CallInterface__.js +533 -0
  61. package/src/concepts/dist/CallLogic__.js +892 -0
  62. package/src/concepts/dist/ForEachStatement__.js +426 -0
  63. package/src/concepts/dist/MatchCase__.js +587 -0
  64. package/src/concepts/dist/Match__.js +631 -0
  65. package/src/concepts/dist/MemberExpression__.js +348 -0
  66. package/src/concepts/dist/Param__.js +538 -0
  67. package/src/concepts/dist/Return__.js +494 -0
  68. package/src/concepts/dist/Variable__.js +537 -0
  69. package/src/concepts/dist/ViewElement__.js +1680 -0
  70. package/src/generator/dist/genBundleFiles.js +261 -0
  71. package/src/generator/dist/genMetaData.js +249 -0
  72. package/src/generator/genBundleFiles.ts +34 -219
  73. package/src/generator/genMetaData.ts +182 -77
  74. package/src/generator/genReleaseBody.ts +10 -3
  75. package/src/server/dist/formatTsUtils.js +683 -0
  76. package/src/server/dist/naslServer.js +3474 -0
  77. package/src/server/extendBaseNode.ts +4 -19
  78. package/src/server/formatTsUtils.ts +30 -46
  79. package/src/server/getProcesses.ts +1 -1
  80. package/src/server/naslServer.ts +8 -7
  81. package/src/server/translator.ts +18 -4
  82. package/src/service/storage/dist/init.js +572 -0
  83. package/ts-worker/dist/webpack.config.dev.js +108 -0
  84. package/dist/bundle.js +0 -3962
  85. package/dist/bundle.js.LICENSE.txt +0 -16
  86. package/out/generator/release.d.ts +0 -1
  87. package/out/generator/release.js +0 -51
  88. package/out/generator/release.js.map +0 -1
@@ -1,8 +1,4 @@
1
- import {
2
- App, Module, View, Entity, Structure, Enum,
3
- uiStructures, collectionStructures, interfaceStructures, processStructures,
4
- Logic, Interface, Process,
5
- } from '../concepts';
1
+ import { App, Module, View } from '../concepts';
6
2
  import * as utils from '../utils';
7
3
  import { genHash, RawOptions } from '.';
8
4
  import { compileComponent } from './compileComponent';
@@ -13,6 +9,8 @@ import parserBabel = require('prettier/parser-babel');
13
9
 
14
10
  import * as UglifyJS from 'uglify-js-export';
15
11
 
12
+ import { genMetaData } from './genMetaData';
13
+
16
14
  export interface Route {
17
15
  path?: string;
18
16
  component?: RawOptions; // ExtendedVue<Vue, unknown, unknown, unknown, Record<never, any>>;
@@ -41,42 +39,11 @@ export function genBundleFiles(app: App,
41
39
  const fnLowcodeDomain = config?.envLcpDomain?.[config?.env]?.lcpDomain || config?.lowcodeDomain;
42
40
  const modules: Module[] = [];
43
41
  const views: View[] = [];
44
- const entities: Entity[] = [];
45
- const structures: Structure[] = [];
46
- const enums: Enum[] = [];
47
- const logics: Logic[] = [];
48
- const interfaces: Interface[] = [];
49
- const processes: Process[] = [];
50
-
51
- app.views && views.push(...app.views);
52
- if (Array.isArray(app.dataSources)) {
53
- app.dataSources.forEach((dataSource) => {
54
- if (Array.isArray(dataSource.entities)) {
55
- entities.push(...dataSource.entities);
56
- }
57
- });
58
- }
59
- app.structures && structures.push(...app.structures);
60
- app.enums && enums.push(...app.enums);
61
- app.logics && logics.push(...app.logics);
62
- app.processes && processes.push(...app.processes);
63
-
64
42
  app.dependencies && modules.push(...app.dependencies);
65
43
  app.interfaceDependencies && modules.push(...app.interfaceDependencies);
66
-
44
+ app.views && views.push(...app.views);
67
45
  modules.forEach((module: Module) => {
68
46
  module.views && views.push(...module.views);
69
- module.structures && structures.push(...module.structures);
70
- module.enums && enums.push(...module.enums);
71
- module.logics && logics.push(...module.logics);
72
- module.interfaces && interfaces.push(...module.interfaces);
73
- if (Array.isArray(module.dataSources)) {
74
- module.dataSources.forEach((dataSource) => {
75
- if (Array.isArray(dataSource.entities)) {
76
- entities.push(...dataSource.entities);
77
- }
78
- });
79
- }
80
47
  });
81
48
 
82
49
  const componentMap: {
@@ -95,31 +62,6 @@ export function genBundleFiles(app: App,
95
62
  * vue.config.js page options
96
63
  */
97
64
  const routes: Route[] = [];
98
- const dataTypes: (Entity | Structure | Enum)[] = [];
99
- const dataTypesMap: {
100
- [id: string]: Object;
101
- } = {};
102
- const frontendVariables = app.frontendVariables;
103
- const enumsMap: {
104
- [name: string]: {
105
- [label: string]: string;
106
- };
107
- } = {};
108
- const logicsMap: {
109
- [id: string]: {
110
- config: {
111
- serviceType: string;
112
- };
113
- url: {
114
- method: string;
115
- path: string;
116
- };
117
- };
118
- } = {};
119
- const _custom: {
120
- [id: string]: any;
121
- } = {};
122
- const allLogics: Logic[] = [];
123
65
  // 开启了权限的页面
124
66
  const authResourceViews: View[] = [];
125
67
  const baseResourcePaths: string[] = [];
@@ -218,10 +160,14 @@ export function genBundleFiles(app: App,
218
160
  let content = `{
219
161
  path: '${route.path}',\n`;
220
162
  if (route?.component?.script) {
163
+ let template = route.component.template;
164
+ if (config.env !== 'dev') {
165
+ template = template.replace(/[\t\r\n]/g, '');
166
+ }
221
167
  content += `component: (function(){
222
168
  var componentOptions = ${route.component.script ? '(function(){\n' + route.component.script.trim().replace(/export default |module\.exports +=/, 'return ') + '\n})()' : '{}'};
223
169
  Object.assign(componentOptions, {
224
- template: \`${route.component.template.replace(/[`$]/g, (m) => '\\' + m)}\`,
170
+ template: \`${template.replace(/[`$]/g, (m) => '\\' + m)}\`,
225
171
  });
226
172
  return componentOptions;
227
173
  })(),\n`;
@@ -250,93 +196,6 @@ export function genBundleFiles(app: App,
250
196
  }
251
197
  routesStr += ']';
252
198
 
253
- if (Array.isArray(enums)) {
254
- dataTypes.push(...enums);
255
- enums.forEach((node) => {
256
- let { name, enumItems } = node || {};
257
- if (node.module) {
258
- name = `extensions.${node.module.name}.enums.${name}`;
259
- }
260
- const enumObj: {
261
- [value: string]: string;
262
- } = {};
263
- enumItems.forEach(({ label, value }) => {
264
- enumObj[value] = label;
265
- });
266
- enumsMap[name] = enumObj;
267
- });
268
- }
269
-
270
- if (Array.isArray(entities)) {
271
- dataTypes.push(...entities);
272
- entities.forEach((entity) => {
273
- const ns = entity.ns;
274
- if (Array.isArray(ns?.logics)) {
275
- allLogics.push(...ns.logics);
276
- }
277
- });
278
- }
279
- if (Array.isArray(structures)) {
280
- dataTypes.push(...structures);
281
- }
282
-
283
- dataTypes.forEach((node) => {
284
- const namespace = node.getNamespace();
285
- const id = `${namespace}.${node.name}`;
286
- dataTypesMap[id] = node.toJSON?.();
287
- });
288
-
289
- [
290
- {
291
- namespace: 'nasl.ui',
292
- list: uiStructures,
293
- },
294
- {
295
- namespace: 'nasl.collection',
296
- list: collectionStructures,
297
- },
298
- {
299
- namespace: 'nasl.interface',
300
- list: interfaceStructures,
301
- },
302
- {
303
- namespace: 'nasl.process',
304
- list: processStructures,
305
- },
306
- ].forEach((item) => {
307
- const { namespace, list } = item || {};
308
- if (Array.isArray(list)) {
309
- list.forEach((node) => {
310
- const id = `${namespace}.${node.name}`;
311
- dataTypesMap[id] = node.toJSON?.();
312
- });
313
- }
314
- });
315
-
316
- if (Array.isArray(logics)) {
317
- allLogics.push(...logics);
318
- }
319
-
320
- allLogics.forEach((node) => {
321
- const namespace = node.getNamespace();
322
- const id = namespace ? `${namespace}.${node.name}` : node.name;
323
- logicsMap[id] = node.toService();
324
- });
325
-
326
- processes.forEach((process) => {
327
- if (Array.isArray(process.logics)) {
328
- process.logics.forEach((node) => {
329
- const namespace = node.getNamespace();
330
- const id = namespace ? `${namespace}.${node.name}` : node.name;
331
- logicsMap[id] = node.toProcessService();
332
- });
333
- }
334
- });
335
-
336
- interfaces.forEach((interfaceItem: Interface) => {
337
- _custom[`${interfaceItem.getNamespace()}.${interfaceItem.name}`] = interfaceItem.toService();
338
- });
339
-
340
199
  const platformConfig = JSON5.stringify({
341
200
  appConfig: {
342
201
  project: app.name,
@@ -364,61 +223,8 @@ export function genBundleFiles(app: App,
364
223
  miniEnable: config.miniEnable,
365
224
  }, null, 4);
366
225
 
367
- function collectTypeAnnotation(typeAnnotation: any) {
368
- if (typeAnnotation) {
369
- const { sortedTypeKey, properties, typeArguments } = typeAnnotation || {};
370
- if (!dataTypesMap[sortedTypeKey]) {
371
- dataTypesMap[sortedTypeKey] = typeAnnotation?.toJSON?.();
372
- }
373
- if (Array.isArray(properties)) {
374
- properties.forEach((property) => {
375
- collectTypeAnnotation(property?.typeAnnotation);
376
- });
377
- }
378
- if (Array.isArray(typeArguments)) {
379
- typeArguments.forEach((typeArg) => {
380
- collectTypeAnnotation(typeArg);
381
- });
382
- }
383
- }
384
- }
385
-
386
- utils.traverse((current) => {
387
- const { node } = current || {};
388
- const { concept } = node || {};
389
- let typeAnnotation;
390
- if (['Param', 'Variable', 'Return', 'CallFunction', 'CallInterface', 'CallLogic'].includes(concept)) {
391
- typeAnnotation = node.typeAnnotation || node.__TypeAnnotation;
392
- }
393
- collectTypeAnnotation(typeAnnotation);
394
- }, {
395
- node: {
396
- children: views,
397
- } as any,
398
- }, {
399
- mode: 'anyObject',
400
- excludedKeySet: new Set([
401
- 'parentNode',
402
- 'sourceMap',
403
- 'storageJSON',
404
- 'tsErrorDetail',
405
- 'NaslAnnotatedJSON',
406
- 'calledFrom',
407
- '_events',
408
- '_collectingList',
409
- '_historyList',
410
- ]),
411
- });
412
-
413
- const metaData = JSON5.stringify({
414
- frontendVariables,
415
- dataTypesMap,
416
- enumsMap,
417
- logicsMap,
418
- servicesMap: {
419
- _custom,
420
- },
421
- });
226
+ const metaData = genMetaData(app);
227
+ const metaDataStr = JSON5.stringify(metaData);
422
228
 
423
229
  const assetsInfo = app.genAllAssetsInfo(config.STATIC_URL);
424
230
  const customNames = JSON5.stringify(assetsInfo.custom.names);
@@ -456,7 +262,7 @@ export function genBundleFiles(app: App,
456
262
 
457
263
  content += `
458
264
  var platformConfig = ${platformConfig};
459
- var metaData = ${metaData};
265
+ var metaData = ${metaDataStr};
460
266
  var routes = ${routesStr};
461
267
 
462
268
  window.createLcapApp = () => window.appVM = window.cloudAdminDesigner.init(platformConfig.appConfig, platformConfig, routes, metaData);
@@ -465,19 +271,19 @@ export function genBundleFiles(app: App,
465
271
 
466
272
  if (config.env === 'dev') {
467
273
  // 加载资源js
468
- const domain = fnLowcodeDomain.slice(fnLowcodeDomain.indexOf('.') + 1);
469
- const targetUrl = `${typeof location !== 'undefined' ? location.origin : `http://${config.tenant}.${fnLowcodeDomain}`}/empty?url=${domain}&appid=${config.appid}`;
274
+ // const domain = fnLowcodeDomain.slice(fnLowcodeDomain.indexOf('.') + 1);
275
+ // const targetUrl = `${typeof location !== 'undefined' ? location.origin : `http://${config.tenant}.${fnLowcodeDomain}`}/empty?url=${domain}&appid=${config.appid}`;
276
+ // if(!document.querySelector("iframe[name='iframeEmpty']")){
277
+ // var el = document.createElement('iframe');
278
+ // el.setAttribute('src', "${targetUrl}");
279
+ // el.setAttribute('name', 'iframeEmpty');
280
+ // el.setAttribute('width', 0);
281
+ // el.setAttribute('height', 0);
282
+ // el.style.borderWidth = 0
283
+ // el.style.display= "block"
284
+ // document.getElementsByTagName('body')[0].appendChild(el);
285
+ // document.domain = '${domain}'
470
286
  const str = `
471
- if(!document.querySelector("iframe[name='iframeEmpty']")){
472
- var el = document.createElement('iframe');
473
- el.setAttribute('src', "${targetUrl}");
474
- el.setAttribute('name', 'iframeEmpty');
475
- el.setAttribute('width', 0);
476
- el.setAttribute('height', 0);
477
- el.style.borderWidth = 0
478
- el.style.display= "block"
479
- document.getElementsByTagName('body')[0].appendChild(el);
480
- document.domain = '${domain}'
481
287
  var _div = document.createElement('div');
482
288
  _div.classList = "div-load"
483
289
  _div.innerHTML = "<div class='loading-container'></div><div>正在更新最新发布内容...</div>"
@@ -527,7 +333,16 @@ export function genBundleFiles(app: App,
527
333
  }
528
334
  }\`
529
335
  document.getElementsByTagName('body')[0].appendChild(style);
530
- }
336
+ window.addEventListener('message', function (e) {
337
+ console.log('message:',e)
338
+ if(e.data ==="release-start"){
339
+ showLoading()
340
+ }
341
+ if(e.data==="release-end"){
342
+ hideLoading()
343
+ window.location.reload();
344
+ }
345
+ })
531
346
  `;
532
347
  content += str;
533
348
  }
@@ -1,58 +1,92 @@
1
- import { App, View, BaseNode, Module, Interface, Entity, Structure, Enum, uiStructures, collectionStructures, processStructures, Logic, Process, DataSource } from '../concepts';
2
-
3
- export function genMetaData(app: App,
4
- config: {
5
- tenant: string;
6
- env: string;
7
- nuimsDomain: string;
8
- envNuimsDomain: Object;
9
- STATIC_URL: string;
10
- USER_STATIC_URL: string;
11
- extendedConfig: string;
12
- lowcodeDomain: string;
13
- }) {
1
+ import {
2
+ App, Module, View, Entity, Structure, Enum,
3
+ uiStructures, collectionStructures, interfaceStructures, processStructures,
4
+ Logic, Interface, Process, BaseNode,
5
+ } from '../concepts';
6
+ import * as utils from '../utils';
7
+
8
+ // 生成typeKey
9
+ function genSortedTypeKey(typeAnnotation: any) {
10
+ const {
11
+ typeKind, typeNamespace, typeName,
12
+ typeArguments, properties,
13
+ } = typeAnnotation || {};
14
+ const typeKeyArr = [];
15
+ if (typeKind === 'union') { // 联合类型
16
+ if (Array.isArray(typeArguments)) {
17
+ // 按返回的每个具体项排序
18
+ const childTypeArgs: any = typeArguments.map((typeArg) => genSortedTypeKey(typeArg)).sort((name1, name2) => name1 > name2 ? 1 : -1);
19
+ typeKeyArr.push(childTypeArgs.join(' | '));
20
+ }
21
+ } else if (typeKind === 'anonymousStructure') { // 匿名数据结构
22
+ typeKeyArr.push('{');
23
+ if (Array.isArray(properties)) {
24
+ // 按匿名数据结构的key排序
25
+ const childTypeArgs: any = properties.sort(({ name: name1 }, { name: name2 }) => name1 > name2 ? 1 : -1).map((typeArg) => {
26
+ const { name: typeArgName, typeAnnotation: typeArgTypeAnnotation } = typeArg || {};
27
+ return `${typeArgName}: ${genSortedTypeKey(typeArgTypeAnnotation)}`;
28
+ });
29
+ typeKeyArr.push(childTypeArgs.join(', '));
30
+ }
31
+ typeKeyArr.push('}');
32
+ } else {
33
+ const typeArr = [];
34
+ typeNamespace && typeArr.push(typeNamespace);
35
+ typeName && typeArr.push(typeName);
36
+ const typeKey = typeArr.join('.');
37
+ typeKey && typeKeyArr.push(typeKey);
38
+ if (typeKind === 'generic') {
39
+ typeKeyArr.push('<');
40
+ if (Array.isArray(typeArguments)) {
41
+ // 必须按typeArguments定义的顺序,否则实参位置不对
42
+ const childTypeArgs: any = typeArguments.map((typeArg) => genSortedTypeKey(typeArg));
43
+ typeKeyArr.push(childTypeArgs.join(', '));
44
+ }
45
+ typeKeyArr.push('>');
46
+ }
47
+ }
48
+ return typeKeyArr.join('');
49
+ }
50
+
51
+ export function genMetaData(app: App) {
14
52
  const modules: Module[] = [];
15
53
  const views: View[] = [];
16
- const dataSources: DataSource[] = [];
54
+ const entities: Entity[] = [];
17
55
  const structures: Structure[] = [];
18
56
  const enums: Enum[] = [];
19
57
  const logics: Logic[] = [];
20
58
  const interfaces: Interface[] = [];
21
59
  const processes: Process[] = [];
22
60
 
23
- const {
24
- dataSources: appDataSources = [],
25
- structures: appStructures = [],
26
- enums: appEnums = [],
27
- logics: appLogics = [],
28
- interfaceDependencies: appInterfaceDependencies = [],
29
- dependencies: appDependencies = [],
30
- processes: appProcesses = [],
31
- } = app || {};
32
- dataSources.push(...appDataSources);
33
- structures.push(...appStructures);
34
- enums.push(...appEnums);
35
- logics.push(...appLogics);
36
- processes.push(...appProcesses);
37
- if (Array.isArray(appDependencies)) {
38
- modules.push(...appDependencies);
39
- }
40
- if (Array.isArray(appInterfaceDependencies)) {
41
- modules.push(...appInterfaceDependencies);
61
+ app.views && views.push(...app.views);
62
+ if (Array.isArray(app.dataSources)) {
63
+ app.dataSources.forEach((dataSource) => {
64
+ if (Array.isArray(dataSource.entities)) {
65
+ entities.push(...dataSource.entities);
66
+ }
67
+ });
42
68
  }
69
+ app.structures && structures.push(...app.structures);
70
+ app.enums && enums.push(...app.enums);
71
+ app.logics && logics.push(...app.logics);
72
+ app.processes && processes.push(...app.processes);
73
+
74
+ app.dependencies && modules.push(...app.dependencies);
75
+ app.interfaceDependencies && modules.push(...app.interfaceDependencies);
76
+
43
77
  modules.forEach((module: Module) => {
44
- const {
45
- views: moduleViews = [],
46
- structures: moduleStructures = [],
47
- enums: moduleEnums = [],
48
- logics: moduleLogics = [],
49
- interfaces: moduleInterfaces = [],
50
- } = module;
51
- views.push(...moduleViews);
52
- structures.push(...moduleStructures);
53
- enums.push(...moduleEnums);
54
- logics.push(...moduleLogics);
55
- interfaces.push(...moduleInterfaces);
78
+ module.views && views.push(...module.views);
79
+ module.structures && structures.push(...module.structures);
80
+ module.enums && enums.push(...module.enums);
81
+ module.logics && logics.push(...module.logics);
82
+ module.interfaces && interfaces.push(...module.interfaces);
83
+ if (Array.isArray(module.dataSources)) {
84
+ module.dataSources.forEach((dataSource) => {
85
+ if (Array.isArray(dataSource.entities)) {
86
+ entities.push(...dataSource.entities);
87
+ }
88
+ });
89
+ }
56
90
  });
57
91
  const dataTypes: (Entity | Structure | Enum)[] = [];
58
92
 
@@ -80,6 +114,7 @@ export function genMetaData(app: App,
80
114
  [id: string]: any;
81
115
  } = {};
82
116
  const allLogics: Logic[] = [];
117
+
83
118
  if (Array.isArray(enums)) {
84
119
  dataTypes.push(...enums);
85
120
  enums.forEach((node) => {
@@ -96,17 +131,17 @@ export function genMetaData(app: App,
96
131
  enumsMap[name] = enumObj;
97
132
  });
98
133
  }
99
- if (Array.isArray(dataSources)) {
100
- dataSources.forEach((dataSource) => {
101
- dataSource.entities.forEach((entity) => {
102
- dataTypes.push(entity);
103
- const ns = entity.ns;
104
- if (Array.isArray(ns?.logics)) {
105
- allLogics.push(...ns.logics);
106
- }
107
- });
134
+
135
+ if (Array.isArray(entities)) {
136
+ dataTypes.push(...entities);
137
+ entities.forEach((entity) => {
138
+ const ns = entity.ns;
139
+ if (Array.isArray(ns?.logics)) {
140
+ allLogics.push(...ns.logics);
141
+ }
108
142
  });
109
143
  }
144
+
110
145
  if (Array.isArray(structures)) {
111
146
  dataTypes.push(...structures);
112
147
  }
@@ -114,31 +149,47 @@ export function genMetaData(app: App,
114
149
  dataTypes.forEach((node) => {
115
150
  const namespace = node.getNamespace();
116
151
  const id = `${namespace}.${node.name}`;
117
- dataTypesMap[id] = node;
152
+ dataTypesMap[id] = node.toJSON?.();
153
+ const { properties } = (node) as any;
154
+ if (Array.isArray(properties)) {
155
+ properties.forEach((property) => {
156
+ collectTypeAnnotation(property?.typeAnnotation);
157
+ });
158
+ }
118
159
  });
119
- if (Array.isArray(uiStructures)) {
120
- const namespace = 'nasl.ui';
121
- uiStructures.forEach((node) => {
122
- const id = `${namespace}.${node.name}`;
123
- dataTypesMap[id] = node;
124
- });
125
- }
126
160
 
127
- if (Array.isArray(collectionStructures)) {
128
- const namespace = 'nasl.collection';
129
- collectionStructures.forEach((node) => {
130
- const id = `${namespace}.${node.name}`;
131
- dataTypesMap[id] = node;
132
- });
133
- }
134
-
135
- if (Array.isArray(processStructures)) {
136
- const namespace = 'nasl.process';
137
- processStructures.forEach((node) => {
138
- const id = `${namespace}.${node.name}`;
139
- dataTypesMap[id] = node;
140
- });
141
- }
161
+ [
162
+ {
163
+ namespace: 'nasl.ui',
164
+ list: uiStructures,
165
+ },
166
+ {
167
+ namespace: 'nasl.collection',
168
+ list: collectionStructures,
169
+ },
170
+ {
171
+ namespace: 'nasl.interface',
172
+ list: interfaceStructures,
173
+ },
174
+ {
175
+ namespace: 'nasl.process',
176
+ list: processStructures,
177
+ },
178
+ ].forEach((item) => {
179
+ const { namespace, list } = item || {};
180
+ if (Array.isArray(list)) {
181
+ list.forEach((node) => {
182
+ const id = `${namespace}.${node.name}`;
183
+ dataTypesMap[id] = node.toJSON?.();
184
+ const { properties } = (node) as any;
185
+ if (Array.isArray(properties)) {
186
+ properties.forEach((property) => {
187
+ collectTypeAnnotation(property?.typeAnnotation);
188
+ });
189
+ }
190
+ });
191
+ }
192
+ });
142
193
 
143
194
  if (Array.isArray(logics)) {
144
195
  allLogics.push(...logics);
@@ -164,6 +215,60 @@ export function genMetaData(app: App,
164
215
  _custom[`${interfaceItem.getNamespace()}.${interfaceItem.name}`] = interfaceItem.toService();
165
216
  });
166
217
 
218
+ utils.traverse((current) => {
219
+ const { node } = current || {};
220
+ const { concept } = node || {};
221
+ let typeAnnotation;
222
+ if (['Param', 'Variable', 'Return', 'CallFunction', 'CallInterface', 'CallLogic'].includes(concept)) {
223
+ typeAnnotation = node.typeAnnotation || node.__TypeAnnotation;
224
+ }
225
+ collectTypeAnnotation(typeAnnotation);
226
+ }, {
227
+ node: {
228
+ children: views,
229
+ } as any,
230
+ }, {
231
+ mode: 'anyObject',
232
+ excludedKeySet: new Set([
233
+ 'parentNode',
234
+ 'sourceMap',
235
+ 'storageJSON',
236
+ 'tsErrorDetail',
237
+ 'NaslAnnotatedJSON',
238
+ 'calledFrom',
239
+ '_events',
240
+ '_collectingList',
241
+ '_historyList',
242
+ ]),
243
+ });
244
+
245
+ if (Array.isArray(frontendVariables)) {
246
+ frontendVariables.forEach((frontendVariable) => {
247
+ const typeAnnotation = frontendVariable.typeAnnotation || frontendVariable.__TypeAnnotation;
248
+ collectTypeAnnotation(typeAnnotation);
249
+ });
250
+ }
251
+
252
+ function collectTypeAnnotation(typeAnnotation: any) {
253
+ if (typeAnnotation) {
254
+ const sortedTypeKey = genSortedTypeKey(typeAnnotation);
255
+ if (!dataTypesMap[sortedTypeKey]) {
256
+ dataTypesMap[sortedTypeKey] = typeAnnotation?.toJSON?.() ?? typeAnnotation;
257
+ const { properties, typeArguments } = (dataTypesMap[sortedTypeKey] || {}) as any;
258
+ if (Array.isArray(properties)) {
259
+ properties.forEach((property) => {
260
+ collectTypeAnnotation(property?.typeAnnotation);
261
+ });
262
+ }
263
+ if (Array.isArray(typeArguments)) {
264
+ typeArguments.forEach((typeArg) => {
265
+ collectTypeAnnotation(typeArg);
266
+ });
267
+ }
268
+ }
269
+ }
270
+ }
271
+
167
272
  return {
168
273
  frontendVariables,
169
274
  dataTypesMap,
@@ -37,8 +37,13 @@ export async function genReleaseBody(app: App, {
37
37
  generateMini,
38
38
  files: [] as Array<{ name: string, content: string }>,
39
39
  };
40
-
41
- const NaslAnnotatedJSON = await (app as any).naslServer.getNaslAnnotatedJSON(app, true);
40
+ let NaslAnnotatedJSON;
41
+ try {
42
+ NaslAnnotatedJSON = await (app as any).naslServer.getNaslAnnotatedJSON(app, true);
43
+ } catch (err) {
44
+ console.error(err);
45
+ throw new Error('代码标注失败');
46
+ }
42
47
 
43
48
  let files = genBundleFiles(app, Object.assign({}, appInfo, {
44
49
  env,
@@ -59,7 +64,9 @@ export async function genReleaseBody(app: App, {
59
64
  const jsonString = JSON.stringify(NaslAnnotatedJSON);
60
65
 
61
66
  // 打印传给服务端的nasl,为了服务端排查问题方便
62
- console.log(NaslAnnotatedJSON, '标注后的nasl');
67
+ if (globalThis.window) {
68
+ console.log(NaslAnnotatedJSON, '标注后的nasl');
69
+ }
63
70
  files.push({ name: 'nasl-annotated.json', content: jsonString });
64
71
 
65
72
  body.files = files;