@lcap/nasl 0.3.9 → 0.3.10-beta

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 (154) hide show
  1. package/out/service/create/errHandles.js +7 -2
  2. package/out/service/create/errHandles.js.map +1 -1
  3. package/out/service/debugger/debugger.d.ts +3 -0
  4. package/out/service/debugger/debugger.js +95 -0
  5. package/out/service/debugger/debugger.js.map +1 -0
  6. package/out/service/logic/logic.d.ts +27 -0
  7. package/out/service/logic/logic.js +20 -0
  8. package/out/service/logic/logic.js.map +1 -1
  9. package/out/service/page/element.d.ts +9 -0
  10. package/out/service/page/element.js +6 -0
  11. package/out/service/page/element.js.map +1 -1
  12. package/out/service/permission/api.d.ts +57 -0
  13. package/out/service/permission/api.js +41 -0
  14. package/out/service/permission/api.js.map +1 -0
  15. package/out/service/permission/index.d.ts +2 -0
  16. package/out/service/permission/index.js +17 -0
  17. package/out/service/permission/index.js.map +1 -0
  18. package/out/service/webFile/index.js +5 -0
  19. package/out/service/webFile/index.js.map +1 -1
  20. package/out/types/app/App.d.ts +4 -1
  21. package/out/types/app/App.js +24 -0
  22. package/out/types/app/App.js.map +1 -1
  23. package/out/types/app/Service.d.ts +2 -2
  24. package/out/types/app/Service.js +28 -3
  25. package/out/types/app/Service.js.map +1 -1
  26. package/out/types/cache.d.ts +6 -0
  27. package/out/types/cache.js +54 -0
  28. package/out/types/cache.js.map +1 -0
  29. package/out/types/common/Vertex.d.ts +25 -0
  30. package/out/types/common/Vertex.js +40 -0
  31. package/out/types/common/Vertex.js.map +1 -1
  32. package/out/types/data/Entity.js +1 -0
  33. package/out/types/data/Entity.js.map +1 -1
  34. package/out/types/data/Enum.d.ts +5 -0
  35. package/out/types/data/Enum.js +5 -0
  36. package/out/types/data/Enum.js.map +1 -1
  37. package/out/types/data/Interface.js +5 -3
  38. package/out/types/data/Interface.js.map +1 -1
  39. package/out/types/data/genBlock/genCreateBlock.js +5 -5
  40. package/out/types/data/genBlock/genCreateBlock.js.map +1 -1
  41. package/out/types/data/genBlock/genCurdBlock.js +3 -3
  42. package/out/types/data/genBlock/genCurdBlock.js.map +1 -1
  43. package/out/types/data/genBlock/genEnumSelectBlock.d.ts +1 -1
  44. package/out/types/data/genBlock/genEnumSelectBlock.js +2 -2
  45. package/out/types/data/genBlock/genEnumSelectBlock.js.map +1 -1
  46. package/out/types/data/genBlock/genGridViewBlock.js +12 -1
  47. package/out/types/data/genBlock/genGridViewBlock.js.map +1 -1
  48. package/out/types/data/genBlock/genListViewBlock.js +2 -2
  49. package/out/types/data/genBlock/genSelectBlock.js +2 -2
  50. package/out/types/data/genBlock/genTableBlock.js +14 -3
  51. package/out/types/data/genBlock/genTableBlock.js.map +1 -1
  52. package/out/types/data/genBlock/genUpdateBlock.js +5 -5
  53. package/out/types/data/genBlock/genUpdateBlock.js.map +1 -1
  54. package/out/types/data/systemTypes.js +47 -0
  55. package/out/types/data/systemTypes.js.map +1 -1
  56. package/out/types/enum.d.ts +6 -0
  57. package/out/types/enum.js +11 -0
  58. package/out/types/enum.js.map +1 -0
  59. package/out/types/generator/hotReload.d.ts +2 -0
  60. package/out/types/generator/hotReload.js +12 -1
  61. package/out/types/generator/hotReload.js.map +1 -1
  62. package/out/types/index.d.ts +7 -1
  63. package/out/types/index.js +11 -2
  64. package/out/types/index.js.map +1 -1
  65. package/out/types/logic/BreakPoint.d.ts +42 -0
  66. package/out/types/logic/BreakPoint.js +155 -0
  67. package/out/types/logic/BreakPoint.js.map +1 -0
  68. package/out/types/logic/Debugger.d.ts +156 -0
  69. package/out/types/logic/Debugger.js +912 -0
  70. package/out/types/logic/Debugger.js.map +1 -0
  71. package/out/types/logic/Logic.d.ts +40 -0
  72. package/out/types/logic/Logic.js +130 -31
  73. package/out/types/logic/Logic.js.map +1 -1
  74. package/out/types/logic/LogicItem.d.ts +21 -1
  75. package/out/types/logic/LogicItem.js +227 -24
  76. package/out/types/logic/LogicItem.js.map +1 -1
  77. package/out/types/logic/Param.d.ts +1 -0
  78. package/out/types/logic/Param.js +38 -20
  79. package/out/types/logic/Param.js.map +1 -1
  80. package/out/types/logic/Return.js +14 -19
  81. package/out/types/logic/Return.js.map +1 -1
  82. package/out/types/logic/Variable.js +14 -19
  83. package/out/types/logic/Variable.js.map +1 -1
  84. package/out/types/logic/translator.js +0 -2
  85. package/out/types/logic/translator.js.map +1 -1
  86. package/out/types/nuims/Nuims.d.ts +1 -1
  87. package/out/types/nuims/Nuims.js +11 -4
  88. package/out/types/nuims/Nuims.js.map +1 -1
  89. package/out/types/page/Element.d.ts +5 -0
  90. package/out/types/page/Element.js +114 -130
  91. package/out/types/page/Element.js.map +1 -1
  92. package/out/types/page/Event.js.map +1 -1
  93. package/out/types/page/Page.d.ts +1 -0
  94. package/out/types/page/Page.js +59 -27
  95. package/out/types/page/Page.js.map +1 -1
  96. package/out/types/page/View.d.ts +17 -3
  97. package/out/types/page/View.js +53 -37
  98. package/out/types/page/View.js.map +1 -1
  99. package/out/types/page/ViewParam.d.ts +1 -0
  100. package/out/types/page/ViewParam.js +23 -4
  101. package/out/types/page/ViewParam.js.map +1 -1
  102. package/out/types/page/ViewVariable.js +13 -18
  103. package/out/types/page/ViewVariable.js.map +1 -1
  104. package/out/types/permission/Permission.d.ts +41 -0
  105. package/out/types/permission/Permission.js +122 -0
  106. package/out/types/permission/Permission.js.map +1 -0
  107. package/package.json +2 -2
  108. package/src/service/create/errHandles.js +6 -2
  109. package/src/service/debugger/debugger.js +90 -0
  110. package/src/service/developPermission/api.js +37 -0
  111. package/src/service/developPermission/index.js +13 -0
  112. package/src/service/logic/logic.js +20 -0
  113. package/src/service/page/element.js +6 -0
  114. package/src/service/permission/api.js +38 -0
  115. package/src/service/permission/index.js +13 -0
  116. package/src/service/webFile/index.js +6 -1
  117. package/src/types/app/App.ts +27 -1
  118. package/src/types/app/Service.ts +32 -3
  119. package/src/types/cache.ts +50 -0
  120. package/src/types/common/Vertex.ts +30 -0
  121. package/src/types/data/Entity.ts +1 -0
  122. package/src/types/data/Enum.ts +5 -0
  123. package/src/types/data/Interface.ts +4 -3
  124. package/src/types/data/genBlock/genCreateBlock.ts +5 -5
  125. package/src/types/data/genBlock/genCurdBlock.ts +3 -3
  126. package/src/types/data/genBlock/genEnumSelectBlock.ts +2 -2
  127. package/src/types/data/genBlock/genGridViewBlock.ts +12 -1
  128. package/src/types/data/genBlock/genListViewBlock.ts +2 -2
  129. package/src/types/data/genBlock/genSelectBlock.ts +2 -2
  130. package/src/types/data/genBlock/genTableBlock.ts +14 -3
  131. package/src/types/data/genBlock/genUpdateBlock.ts +5 -5
  132. package/src/types/data/systemTypes.ts +47 -0
  133. package/src/types/enum.ts +6 -0
  134. package/src/types/generator/hotReload.ts +10 -0
  135. package/src/types/index.ts +7 -1
  136. package/src/types/logic/BreakPoint.ts +200 -0
  137. package/src/types/logic/Debugger.ts +1140 -0
  138. package/src/types/logic/Logic.ts +133 -28
  139. package/src/types/logic/LogicItem.ts +250 -28
  140. package/src/types/logic/Param.ts +26 -8
  141. package/src/types/logic/Return.ts +4 -9
  142. package/src/types/logic/Variable.ts +4 -8
  143. package/src/types/logic/translator.d.ts +16 -0
  144. package/src/types/logic/translator.js +144 -88
  145. package/src/types/logic/translator_backup.js +5 -16
  146. package/src/types/nuims/Nuims.ts +11 -5
  147. package/src/types/page/Element.ts +63 -75
  148. package/src/types/page/Event.ts +0 -3
  149. package/src/types/page/Page.ts +73 -40
  150. package/src/types/page/View.ts +45 -18
  151. package/src/types/page/ViewParam.ts +22 -3
  152. package/src/types/page/ViewVariable.ts +4 -8
  153. package/src/types/permission/Permission.ts +112 -0
  154. package/tsconfig.json +1 -1
@@ -1,5 +1,6 @@
1
+
1
2
  import { immutable, circular, action, excludedInJSON } from '../decorators';
2
- import { config, history, LEVEL_ENUM, Vertex, PackageJSON, App, Enum, Service, WebService, Structure, Page, Element, utils, ViewParam, ViewVariable, Lifecycle, genFinalCode, generator, Nuims, ActionOptions, ACTION_MODE, vertexsMap, updateDataTypeList, Interface } from '..';
3
+ import { config, history, LEVEL_ENUM, Vertex, PackageJSON, App, Enum, Service, WebService, Structure, Page, Element, utils, ViewParam, ViewVariable, Lifecycle, genFinalCode, generator, Nuims, ActionOptions, ACTION_MODE, vertexsMap, updateDataTypeList, Interface, LogicItem } from '..';
3
4
  import Block from './Block';
4
5
  import { viewService } from '../../service/page';
5
6
  import { Param } from '../logic/Param';
@@ -16,6 +17,15 @@ import * as babel from '@babel/core';
16
17
  import view from '@/service/page/view';
17
18
  import Entity from '../data/Entity';
18
19
  import { postServiceType } from '../../service/common/preprocess';
20
+ export interface FrontEndsourceMap {
21
+ [id: string]: {
22
+ isLogic: boolean,
23
+ node: LogicItem,
24
+ from: number,
25
+ to: number,
26
+ }
27
+ }
28
+ import { catchFn } from './Page';
19
29
 
20
30
  /**
21
31
  * 子页面类,前端路由控制
@@ -111,6 +121,9 @@ export class View extends Block {
111
121
  */
112
122
  @excludedInJSON()
113
123
  public contentPromise: Promise<any> = undefined;
124
+
125
+ @excludedInJSON()
126
+ public sourceMap: FrontEndsourceMap = {};
114
127
  /**
115
128
  * 输入参数
116
129
  */
@@ -195,30 +208,41 @@ export class View extends Block {
195
208
  // def 情况比较特殊,需要单独处理,防止逻辑重新加载
196
209
  this._syncDef($def);
197
210
  this.attachNodePath(true);
211
+ this.toVueOptions();
198
212
  return this;
199
213
  } catch (err) { }
200
214
  })().finally(() => this.contentPromise = undefined);
201
215
  }
202
- loadAll() {
216
+ loadAll(enableCache = true) {
203
217
  // 如果有正在进行的 Promise,则直接返回它
204
218
  if (this.contentPromise)
205
219
  return this.contentPromise;
206
220
 
207
221
  return this.contentPromise = (async () => {
208
- try {
209
222
  const result: View = await viewService.load({
210
223
  path: {
211
224
  id: this.id,
212
225
  },
226
+ query: {
227
+ enableCache,
228
+ },
229
+ config: { noErrorTip: true },
213
230
  });
214
-
231
+ const oldLogics = this.$def.logics;
232
+ Object.assign(result, {
233
+ children: this.children,
234
+ })
215
235
  const temp = View.from(result, this.parent, this.page, this);
236
+ const newLogics = temp.$def.logics;
237
+ oldLogics.forEach((logic) => {
238
+ if(!newLogics.find((item) => item.id === logic.id))
239
+ logic.destroy();
240
+ });
216
241
  this.assign(temp);
217
242
  utils.traverse((current) => {
218
243
  current.node.attachNodePath(true);
219
244
  }, { node: this });
220
245
  return this;
221
- } catch (err) { }
222
246
  })().finally(() => this.contentPromise = undefined);
223
247
  }
224
248
  isContentLoaded() {
@@ -325,7 +349,7 @@ export class View extends Block {
325
349
  operationDesc: actionOptions?.actionDesc || `添加子页面"${this.name}${this.title ? `(${this.title})` : ''}"`,
326
350
  },
327
351
  body,
328
- });
352
+ }).catch(catchFn());
329
353
  this.deepPick(result.view, ['id']);
330
354
  // 添加数据
331
355
  this.addData(result);
@@ -406,7 +430,6 @@ export class View extends Block {
406
430
  if (!this.parent)
407
431
  throw Error('该子页面为根节点!');
408
432
 
409
- try {
410
433
  await viewService.delete({
411
434
  headers: {
412
435
  appId: config.defaultApp?.id,
@@ -416,11 +439,7 @@ export class View extends Block {
416
439
  path: {
417
440
  id: this.id,
418
441
  },
419
- });
420
- } catch (err) {
421
- await config.defaultApp?.history.load();
422
- throw err;
423
- }
442
+ }).catch(catchFn());
424
443
 
425
444
  const index = this.parent.children.indexOf(this);
426
445
  ~index && this.parent.children.splice(index, 1);
@@ -452,7 +471,7 @@ export class View extends Block {
452
471
  operationDesc: actionOptions?.actionDesc || `修改子页面"${this.name}${this.title ? `(${this.title})` : ''}"`,
453
472
  },
454
473
  body,
455
- });
474
+ }).catch(catchFn());
456
475
 
457
476
  await then?.();
458
477
  await config.defaultApp?.history.load();
@@ -662,7 +681,6 @@ export class View extends Block {
662
681
  let componentOptions = 'const componentOptions = {};';
663
682
  if (this.script)
664
683
  componentOptions = this.script.trim().replace(/export default |module\.exports +=/, 'const componentOptions = ');
665
-
666
684
  const $def = JSON.parse(JSON.stringify(this.$def));
667
685
  $def.title = this.title;
668
686
  $def.crumb = this.crumb;
@@ -688,10 +706,16 @@ export class View extends Block {
688
706
  // );
689
707
  // }
690
708
  // }, { node: $def }, { mode: 'anyObject' });
691
- return `${componentOptions}
692
- ${genFinalCode(translator($def), options && options.finalCode)}
709
+ const {
710
+ output,
711
+ sourceMap,
712
+ } = translator($def, this.script);
713
+ return {
714
+ script: `${componentOptions}${genFinalCode(output, options && options.finalCode)}
693
715
  export default componentOptions;
694
- `;
716
+ `,
717
+ sourceMap,
718
+ };
695
719
  }
696
720
  /**
697
721
  * 转换成 Vue 文件
@@ -725,9 +749,12 @@ export class View extends Block {
725
749
  * @TODO 后面 template 可以优化成 render 函数
726
750
  */
727
751
  toVueOptions(options?: ElementToVueOptions) {
752
+ const { script, sourceMap } = this.toScript(options);
753
+ this.sourceMap = sourceMap;
728
754
  return {
729
755
  template: this.$html.toVue(options),
730
- script: this.toScript(options),
756
+ script,
757
+ sourceMap,
731
758
  // definition: JSON.stringify(this.$def),
732
759
  };
733
760
  }
@@ -5,6 +5,25 @@ import { getBasicTypeDefaultValue } from '../data/basicTypes';
5
5
  import { viewService } from '../../service/page';
6
6
  import { View } from './View';
7
7
  import { schemaService } from '../../service/common';
8
+ import { refreshPages, refreshView } from '../cache';
9
+ import { BusinessCode } from '../enum';
10
+
11
+ export function catchFn(view: View) {
12
+ return async (err: any) => {
13
+ const code = err?.code;
14
+ // 节点已存在; 节点不存在
15
+ if([BusinessCode.ElementExist, BusinessCode.ElementNotExist].includes(code)) {
16
+ await refreshView(view);
17
+ } else if(code === BusinessCode.ParentElementNotExist) { // 父节点不存在。视图添加变量,发现视图不存在
18
+ await refreshPages();
19
+ } else
20
+ config.defaultApp?.emit('saved', err);
21
+
22
+ config.defaultApp?.history.load();
23
+
24
+ throw err;
25
+ }
26
+ }
8
27
 
9
28
  /**
10
29
  * 页面输入参数
@@ -56,7 +75,7 @@ export class ViewParam extends Param {
56
75
  operationDesc: actionOptions?.actionDesc || `添加页面"${this.view.name}"输入参数"${this.name}"`,
57
76
  },
58
77
  body,
59
- });
78
+ }).catch(catchFn(this.view));
60
79
  // convert2RefType(result.schema);
61
80
  this.deepPick(result, ['id']);
62
81
  this.assign({ code: this.genCode() });
@@ -88,7 +107,7 @@ export class ViewParam extends Param {
88
107
  query: {
89
108
  id: this.id,
90
109
  },
91
- });
110
+ }).catch(catchFn(this.view));
92
111
  } catch(err) {
93
112
  await config.defaultApp?.history.load();
94
113
  throw err;
@@ -129,7 +148,7 @@ export class ViewParam extends Param {
129
148
  operationDesc: actionOptions?.actionDesc || `修改页面"${this.view.name}"输入参数"${this.name}"`,
130
149
  },
131
150
  body,
132
- });
151
+ }).catch(catchFn(this.view));
133
152
  // convert2RefType(result.schema);
134
153
  // this.plainAssign(result);
135
154
 
@@ -5,6 +5,7 @@ import { viewService } from '../../service/page';
5
5
  import { convert2RefType, convert2SchemaType } from '../data/dataTypeUtils';
6
6
  import { getBasicTypeDefaultValue } from '../data/basicTypes';
7
7
  import { schemaService } from '../../service/common';
8
+ import { catchFn } from './ViewParam';
8
9
 
9
10
  /**
10
11
  * 页面局部变量
@@ -51,7 +52,7 @@ export class ViewVariable extends Variable {
51
52
  operationDesc: actionOptions?.actionDesc || `添加页面"${this.view.name}"局部变量"${this.name}"`,
52
53
  },
53
54
  body,
54
- });
55
+ }).catch(catchFn(this.view));
55
56
  // convert2RefType(result.schema);
56
57
  this.deepPick(result, ['id']);
57
58
  this.assign({ code: this.genCode() });
@@ -73,7 +74,6 @@ export class ViewVariable extends Variable {
73
74
  config.defaultApp?.emit('saving');
74
75
 
75
76
  if (this.id) {
76
- try {
77
77
  await viewService.deleteViewVariable({
78
78
  headers: {
79
79
  appId: config.defaultApp?.id,
@@ -83,11 +83,7 @@ export class ViewVariable extends Variable {
83
83
  query: {
84
84
  id: this.id,
85
85
  },
86
- });
87
- } catch (err) {
88
- await config.defaultApp?.history.load();
89
- throw err;
90
- }
86
+ }).catch(catchFn(this.view));
91
87
  }
92
88
 
93
89
  const { variables } = this.view.$def;
@@ -122,7 +118,7 @@ export class ViewVariable extends Variable {
122
118
  operationDesc: actionOptions?.actionDesc || `修改页面"${this.view.name}"局部变量"${this.name}"`,
123
119
  },
124
120
  body,
125
- });
121
+ }).catch(catchFn(this.view));
126
122
  // convert2RefType(result.schema);
127
123
  // this.plainAssign(result);
128
124
 
@@ -0,0 +1,112 @@
1
+ import { immutable } from '../decorators';
2
+ import { View, Element } from '..';
3
+ import permissionService from '../../service/permission';
4
+
5
+
6
+ export class Permission {
7
+ /**
8
+ * App Name
9
+ */
10
+ @immutable()
11
+ public readonly domainName: string = undefined;
12
+ /**
13
+ * 上报权限后的资源id
14
+ */
15
+ @immutable()
16
+ public readonly resourceId: string = undefined;
17
+
18
+ /**
19
+ * 应用 id
20
+ */
21
+ @immutable()
22
+ public readonly serviceId: string = undefined;
23
+
24
+ /**
25
+ * view
26
+ */
27
+ @immutable()
28
+ public readonly view: View = undefined;
29
+
30
+ /**
31
+ * element
32
+ */
33
+ @immutable()
34
+ public readonly element: Element = undefined;
35
+
36
+ /**
37
+ * @param source 需要合并的部分参数
38
+ */
39
+ constructor(source?: Partial<Permission>) {
40
+ const { domainName } = source;
41
+ Object.assign(this, source);
42
+ if (!domainName) {
43
+ throw new Error('Permission need domainName!');
44
+ }
45
+ }
46
+
47
+ async createDefaultRoleFromRoleName(roleName: string) {
48
+ if (!roleName)
49
+ return;
50
+ return await permissionService.createRole({
51
+ body: {
52
+ name: roleName,
53
+ serviceId: this.serviceId,
54
+ },
55
+ });
56
+ }
57
+
58
+ async updateRoleName(roleId: string, roleName: string) {
59
+ return await permissionService.updateRole({
60
+ body: {
61
+ id: roleId,
62
+ name: roleName,
63
+ serviceId: this.serviceId,
64
+ }
65
+ })
66
+ }
67
+
68
+ /**
69
+ *
70
+ * @param query {
71
+ * resourceId
72
+ * roleId
73
+ * }
74
+ */
75
+ async attachPermissionResource(query: Object) {
76
+ return await permissionService.attachPermissionResourceAction({ query });
77
+ }
78
+
79
+ async detachPermissionResource(query: Object) {
80
+ return await permissionService.detachPermissionResourceAction({ query });
81
+ }
82
+
83
+ async getInitRoles(resourceId: string) {
84
+ return await permissionService.getRoles({
85
+ query: {
86
+ serviceId: this.serviceId,
87
+ resourceId,
88
+ }
89
+ });
90
+ }
91
+
92
+ async attachDevRole(resourceId: string) {
93
+ const data: any = await this.getInitRoles(resourceId)|| [];
94
+ let roleId;
95
+ data.forEach((item: any) => {
96
+ if (item.name === 'DEV-AdminRole') {
97
+ roleId = item.id;
98
+ }
99
+ })
100
+ // 获取权限树资源Id
101
+ if (roleId) {
102
+ // 默认角色开启
103
+ await this.attachPermissionResource({
104
+ resourceId,
105
+ roleId,
106
+ });
107
+ await this.getInitRoles(resourceId);
108
+ }
109
+ }
110
+ }
111
+
112
+ export default Permission;
package/tsconfig.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "skipLibCheck": true,
9
9
  "esModuleInterop": true,
10
10
  "allowJs": true,
11
- "allowSyntheticDefaultImports": false,
11
+ "allowSyntheticDefaultImports": true,
12
12
  "experimentalDecorators": true,
13
13
  "resolveJsonModule": true,
14
14
  "sourceMap": true,