@lcap/nasl 0.3.10 → 0.3.11

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 (194) hide show
  1. package/out/service/app/api.d.ts +1 -15
  2. package/out/service/app/api.js +7 -17
  3. package/out/service/app/api.js.map +1 -1
  4. package/out/service/create/errHandles.js +19 -2
  5. package/out/service/create/errHandles.js.map +1 -1
  6. package/out/service/create/index.js +5 -0
  7. package/out/service/create/index.js.map +1 -1
  8. package/out/service/logic/logic.d.ts +50 -14
  9. package/out/service/logic/logic.js +26 -0
  10. package/out/service/logic/logic.js.map +1 -1
  11. package/out/service/page/element.d.ts +9 -0
  12. package/out/service/page/element.js +6 -0
  13. package/out/service/page/element.js.map +1 -1
  14. package/out/service/permission/api.d.ts +57 -0
  15. package/out/service/permission/api.js +41 -0
  16. package/out/service/permission/api.js.map +1 -0
  17. package/out/service/permission/index.d.ts +2 -0
  18. package/out/service/permission/index.js +17 -0
  19. package/out/service/permission/index.js.map +1 -0
  20. package/out/service/webFile/index.js +5 -0
  21. package/out/service/webFile/index.js.map +1 -1
  22. package/out/types/app/App.d.ts +13 -0
  23. package/out/types/app/App.js +55 -1
  24. package/out/types/app/App.js.map +1 -1
  25. package/out/types/app/History.js +3 -2
  26. package/out/types/app/History.js.map +1 -1
  27. package/out/types/app/Service.d.ts +5 -2
  28. package/out/types/app/Service.js +42 -9
  29. package/out/types/app/Service.js.map +1 -1
  30. package/out/types/cache.d.ts +6 -0
  31. package/out/types/cache.js +54 -0
  32. package/out/types/cache.js.map +1 -0
  33. package/out/types/cacheData.js.map +1 -1
  34. package/out/types/common/Vertex.d.ts +25 -0
  35. package/out/types/common/Vertex.js +42 -1
  36. package/out/types/common/Vertex.js.map +1 -1
  37. package/out/types/data/Entity.d.ts +4 -0
  38. package/out/types/data/Entity.js +9 -0
  39. package/out/types/data/Entity.js.map +1 -1
  40. package/out/types/data/EntityProperty.d.ts +5 -0
  41. package/out/types/data/EntityProperty.js +16 -0
  42. package/out/types/data/EntityProperty.js.map +1 -1
  43. package/out/types/data/Enum.d.ts +5 -0
  44. package/out/types/data/Enum.js +5 -0
  45. package/out/types/data/Enum.js.map +1 -1
  46. package/out/types/data/GlobalLogicNode.js +8 -1
  47. package/out/types/data/GlobalLogicNode.js.map +1 -1
  48. package/out/types/data/Interface.js +5 -3
  49. package/out/types/data/Interface.js.map +1 -1
  50. package/out/types/data/dataTypes.js +1 -1
  51. package/out/types/data/dataTypes.js.map +1 -1
  52. package/out/types/data/genBlock/genCreateBlock.js +5 -5
  53. package/out/types/data/genBlock/genCreateBlock.js.map +1 -1
  54. package/out/types/data/genBlock/genCurdBlock.js +3 -3
  55. package/out/types/data/genBlock/genCurdBlock.js.map +1 -1
  56. package/out/types/data/genBlock/genCurdEditTableBlock.d.ts +3 -0
  57. package/out/types/data/genBlock/genCurdEditTableBlock.js +578 -0
  58. package/out/types/data/genBlock/genCurdEditTableBlock.js.map +1 -0
  59. package/out/types/data/genBlock/genEditTableBlock.d.ts +234 -0
  60. package/out/types/data/genBlock/genEditTableBlock.js +419 -0
  61. package/out/types/data/genBlock/genEditTableBlock.js.map +1 -0
  62. package/out/types/data/genBlock/genEnumSelectBlock.d.ts +1 -1
  63. package/out/types/data/genBlock/genEnumSelectBlock.js +2 -2
  64. package/out/types/data/genBlock/genEnumSelectBlock.js.map +1 -1
  65. package/out/types/data/genBlock/genGridViewBlock.js +12 -1
  66. package/out/types/data/genBlock/genGridViewBlock.js.map +1 -1
  67. package/out/types/data/genBlock/genListViewBlock.js +2 -2
  68. package/out/types/data/genBlock/genQueryComponent.d.ts +20 -0
  69. package/out/types/data/genBlock/genQueryComponent.js +57 -1
  70. package/out/types/data/genBlock/genQueryComponent.js.map +1 -1
  71. package/out/types/data/genBlock/genSelectBlock.js +2 -2
  72. package/out/types/data/genBlock/genTableBlock.js +23 -8
  73. package/out/types/data/genBlock/genTableBlock.js.map +1 -1
  74. package/out/types/data/genBlock/genUpdateBlock.js +5 -5
  75. package/out/types/data/genBlock/genUpdateBlock.js.map +1 -1
  76. package/out/types/data/genBlock/index.d.ts +2 -0
  77. package/out/types/data/genBlock/index.js +2 -0
  78. package/out/types/data/genBlock/index.js.map +1 -1
  79. package/out/types/data/genBlock/utils.d.ts +7 -0
  80. package/out/types/data/genBlock/utils.js +38 -1
  81. package/out/types/data/genBlock/utils.js.map +1 -1
  82. package/out/types/data/systemTypes.js +47 -0
  83. package/out/types/data/systemTypes.js.map +1 -1
  84. package/out/types/enum.d.ts +6 -0
  85. package/out/types/enum.js +11 -0
  86. package/out/types/enum.js.map +1 -0
  87. package/out/types/generator/hotReload.d.ts +2 -0
  88. package/out/types/generator/hotReload.js +12 -1
  89. package/out/types/generator/hotReload.js.map +1 -1
  90. package/out/types/index.d.ts +5 -1
  91. package/out/types/index.js +8 -2
  92. package/out/types/index.js.map +1 -1
  93. package/out/types/logic/Logic.d.ts +32 -0
  94. package/out/types/logic/Logic.js +151 -41
  95. package/out/types/logic/Logic.js.map +1 -1
  96. package/out/types/logic/LogicItem.d.ts +1 -0
  97. package/out/types/logic/LogicItem.js +49 -32
  98. package/out/types/logic/LogicItem.js.map +1 -1
  99. package/out/types/logic/Param.d.ts +1 -0
  100. package/out/types/logic/Param.js +43 -33
  101. package/out/types/logic/Param.js.map +1 -1
  102. package/out/types/logic/Return.js +17 -30
  103. package/out/types/logic/Return.js.map +1 -1
  104. package/out/types/logic/Variable.js +17 -25
  105. package/out/types/logic/Variable.js.map +1 -1
  106. package/out/types/logic/translator.js +39 -10
  107. package/out/types/logic/translator.js.map +1 -1
  108. package/out/types/nuims/Nuims.d.ts +1 -1
  109. package/out/types/nuims/Nuims.js +11 -4
  110. package/out/types/nuims/Nuims.js.map +1 -1
  111. package/out/types/page/Element.d.ts +24 -0
  112. package/out/types/page/Element.js +198 -134
  113. package/out/types/page/Element.js.map +1 -1
  114. package/out/types/page/Event.js.map +1 -1
  115. package/out/types/page/Page.d.ts +5 -0
  116. package/out/types/page/Page.js +66 -27
  117. package/out/types/page/Page.js.map +1 -1
  118. package/out/types/page/View.d.ts +19 -1
  119. package/out/types/page/View.js +150 -40
  120. package/out/types/page/View.js.map +1 -1
  121. package/out/types/page/ViewParam.d.ts +1 -0
  122. package/out/types/page/ViewParam.js +23 -4
  123. package/out/types/page/ViewParam.js.map +1 -1
  124. package/out/types/page/ViewVariable.js +13 -24
  125. package/out/types/page/ViewVariable.js.map +1 -1
  126. package/out/types/permission/Permission.d.ts +41 -0
  127. package/out/types/permission/Permission.js +122 -0
  128. package/out/types/permission/Permission.js.map +1 -0
  129. package/out/types/process/ProcessParam.js +3 -1
  130. package/out/types/process/ProcessParam.js.map +1 -1
  131. package/out/types/utils/index.d.ts +1 -0
  132. package/out/types/utils/index.js +16 -7
  133. package/out/types/utils/index.js.map +1 -1
  134. package/package.json +1 -2
  135. package/src/service/app/api.js +8 -17
  136. package/src/service/create/errHandles.js +18 -2
  137. package/src/service/create/index.js +6 -0
  138. package/src/service/developPermission/api.js +37 -0
  139. package/src/service/developPermission/index.js +13 -0
  140. package/src/service/logic/logic.js +26 -0
  141. package/src/service/page/element.js +6 -0
  142. package/src/service/permission/api.js +38 -0
  143. package/src/service/permission/index.js +13 -0
  144. package/src/service/webFile/index.js +6 -1
  145. package/src/types/app/App.ts +58 -2
  146. package/src/types/app/History.ts +3 -2
  147. package/src/types/app/Service.ts +48 -10
  148. package/src/types/cache.ts +50 -0
  149. package/src/types/cacheData.ts +7 -7
  150. package/src/types/common/Vertex.ts +32 -1
  151. package/src/types/data/Entity.ts +8 -0
  152. package/src/types/data/EntityProperty.ts +12 -0
  153. package/src/types/data/Enum.ts +5 -0
  154. package/src/types/data/GlobalLogicNode.ts +8 -1
  155. package/src/types/data/Interface.ts +4 -3
  156. package/src/types/data/dataTypes.ts +1 -1
  157. package/src/types/data/genBlock/genCreateBlock.ts +5 -5
  158. package/src/types/data/genBlock/genCurdBlock.ts +3 -3
  159. package/src/types/data/genBlock/genCurdEditTableBlock.ts +581 -0
  160. package/src/types/data/genBlock/genEditTableBlock.ts +470 -0
  161. package/src/types/data/genBlock/genEnumSelectBlock.ts +2 -2
  162. package/src/types/data/genBlock/genGridViewBlock.ts +12 -1
  163. package/src/types/data/genBlock/genListViewBlock.ts +2 -2
  164. package/src/types/data/genBlock/genQueryComponent.ts +56 -0
  165. package/src/types/data/genBlock/genSelectBlock.ts +2 -2
  166. package/src/types/data/genBlock/genTableBlock.ts +28 -13
  167. package/src/types/data/genBlock/genUpdateBlock.ts +5 -5
  168. package/src/types/data/genBlock/index.ts +2 -0
  169. package/src/types/data/genBlock/utils.ts +38 -0
  170. package/src/types/data/systemTypes.ts +47 -0
  171. package/src/types/enum.ts +6 -0
  172. package/src/types/generator/hotReload.ts +10 -0
  173. package/src/types/index.ts +5 -1
  174. package/src/types/logic/Logic.ts +148 -39
  175. package/src/types/logic/LogicItem.ts +55 -38
  176. package/src/types/logic/Param.ts +43 -35
  177. package/src/types/logic/Return.ts +21 -34
  178. package/src/types/logic/Variable.ts +21 -27
  179. package/src/types/logic/translator.js +41 -14
  180. package/src/types/logic/translator_backup.js +5 -16
  181. package/src/types/nuims/Nuims.ts +11 -5
  182. package/src/types/page/Element.ts +212 -138
  183. package/src/types/page/Event.ts +0 -3
  184. package/src/types/page/Page.ts +80 -40
  185. package/src/types/page/View.ts +154 -39
  186. package/src/types/page/ViewParam.ts +22 -3
  187. package/src/types/page/ViewVariable.ts +16 -26
  188. package/src/types/page/dist/View.js +727 -0
  189. package/src/types/permission/Permission.ts +112 -0
  190. package/src/types/process/ProcessParam.ts +4 -1
  191. package/src/types/utils/index.ts +16 -7
  192. package/out/test/units/config.spec.d.ts +0 -1
  193. package/out/test/units/config.spec.js +0 -12
  194. package/out/test/units/config.spec.js.map +0 -1
@@ -1,11 +1,12 @@
1
- import { immutable, excludedInJSON, circular, action } from '../decorators';
2
- import { config, history, typeCheck, utils, Vertex, Service, LEVEL_ENUM, Interface, Param, Return, Variable, Logic, View, Schema, ActionOptions, ACTION_MODE } from '..';
1
+ import { immutable, excludedInJSON, action } from '../decorators';
2
+ import { config, typeCheck, utils, Vertex, LEVEL_ENUM, Logic, Schema, ActionOptions, ACTION_MODE } from '..';
3
3
  import { logicService } from '../../service/logic';
4
- import { assert } from 'console';
5
4
  import { traverse } from '../utils';
6
5
  import { vertexsMap } from '../cacheData';
7
6
  import { getSchemaOfExpressionNode } from './tools';
8
7
  import Structure from '../data/Structure';
8
+ import { refreshLogic } from '../cache';
9
+ import { BusinessCode } from '../enum';
9
10
 
10
11
  export enum LOGIC_TYPE {
11
12
  // LogicNode
@@ -56,6 +57,18 @@ export enum LOGIC_TYPE {
56
57
  QueryAggregateExpression = 'QueryAggregateExpression',
57
58
  }
58
59
 
60
+ const atomicList = [
61
+ LOGIC_TYPE.Identifier,
62
+ LOGIC_TYPE.NumericLiteral,
63
+ LOGIC_TYPE.BooleanLiteral,
64
+ LOGIC_TYPE.StringLiteral,
65
+ LOGIC_TYPE.NullLiteral,
66
+ LOGIC_TYPE.UnaryExpression,
67
+ LOGIC_TYPE.MemberExpression,
68
+ LOGIC_TYPE.Unparsed,
69
+ LOGIC_TYPE.BuiltInFunction,
70
+ ];
71
+
59
72
  export function evaluate(node: LogicNode | ExpressionNode, finalCode = true): string {
60
73
  if (!node)
61
74
  return '';
@@ -76,11 +89,11 @@ export function evaluate(node: LogicNode | ExpressionNode, finalCode = true): st
76
89
 
77
90
  if (node.type === 'BinaryExpression') {
78
91
  let left: string = evaluate(<LogicNode>node.left, finalCode);
79
- if (!finalCode && node.left?.type === LOGIC_TYPE.MemberExpression)
92
+ if (!atomicList.includes((node.left as any)?.type) || (!finalCode && node.left?.type === LOGIC_TYPE.MemberExpression))
80
93
  left = `(${left})`;
81
94
 
82
95
  let right: string = evaluate(<LogicNode>node.right, finalCode);
83
- if (!finalCode && node.right?.type === LOGIC_TYPE.MemberExpression)
96
+ if (!atomicList.includes((node.right as any)?.type) || (!finalCode && node.left?.type === LOGIC_TYPE.MemberExpression))
84
97
  right = `(${right})`;
85
98
 
86
99
  return `${left} ${node.operator} ${right}`;
@@ -88,13 +101,11 @@ export function evaluate(node: LogicNode | ExpressionNode, finalCode = true): st
88
101
 
89
102
  if (node.type === 'LogicalExpression') {
90
103
  let left: string = evaluate(<LogicNode>node.left, finalCode);
91
- if (!finalCode && node.left?.type === LOGIC_TYPE.MemberExpression)
104
+ if (!atomicList.includes((node.left as any)?.type) || (!finalCode && node.left?.type === LOGIC_TYPE.MemberExpression))
92
105
  left = `(${left})`;
93
-
94
106
  let right: string = evaluate(<LogicNode>node.right, finalCode);
95
- if (!finalCode && node.right?.type === LOGIC_TYPE.MemberExpression)
107
+ if (!atomicList.includes((node.right as any)?.type) || (!finalCode && node.left?.type === LOGIC_TYPE.MemberExpression))
96
108
  right = `(${right})`;
97
-
98
109
  return `${left} ${node.operator} ${right}`;
99
110
  }
100
111
 
@@ -209,6 +220,18 @@ export const logicItemArrayKeyOfLogicItem: string[] = ['body', 'consequent', 'al
209
220
  'groupBy', 'orderBy', 'selectElementList', 'joinPartList', 'onExpressionList', 'where', 'having',
210
221
  ];
211
222
 
223
+ export function catchFn(logic: Logic) {
224
+ return async (err: any) => {
225
+ if (err.code !== BusinessCode.HasReferenced) // 节点被引用,不用刷新数据
226
+ await refreshLogic(logic);
227
+ else
228
+ config.defaultApp?.emit('saved', err);
229
+
230
+ config.defaultApp?.history.load();
231
+ throw err;
232
+ };
233
+ }
234
+
212
235
  /**
213
236
  * 逻辑项类
214
237
  */
@@ -425,6 +448,7 @@ export class LogicItem extends Vertex {
425
448
  body.logicId = this.logic && this.logic.id;
426
449
  result = await logicService.addItem({
427
450
  headers: {
451
+ moduleType: this.logic && this.logic.moduleType,
428
452
  appId: config.defaultApp?.id,
429
453
  serviceId: this.logic?.interface?.serviceId,
430
454
  operationAction: 'LogicItem.create',
@@ -432,7 +456,7 @@ export class LogicItem extends Vertex {
432
456
  operationIgnore: actionOptions?.actionIgnore,
433
457
  },
434
458
  body,
435
- });
459
+ }).catch(catchFn(this.logic));
436
460
  this.deepPick(result, ['id', 'parentId', 'parentAttr', 'joinPartRef', 'structureRef']);
437
461
  }
438
462
 
@@ -525,8 +549,9 @@ export class LogicItem extends Vertex {
525
549
  if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
526
550
  utils.logger.debug(`在该逻辑节点的属性"${parentAttr}"上插入一个节点"`, body);
527
551
 
528
- const result: LogicItem = await logicService.moveItem({
552
+ await logicService.moveItem({
529
553
  headers: {
554
+ moduleType: this.logic && this.logic.moduleType,
530
555
  appId: config.defaultApp?.id,
531
556
  operationAction: 'LogicItem.move',
532
557
  operationDesc: actionOptions?.actionDesc || `移动逻辑项"${this.label || this.type}"`,
@@ -548,7 +573,7 @@ export class LogicItem extends Vertex {
548
573
  offsetY,
549
574
  },
550
575
  },
551
- });
576
+ }).catch(catchFn(this.logic));
552
577
  }
553
578
 
554
579
  if (!(this.parentId === parentId && this.parentId === this.logic.playgroundId && this.parentAttr === parentAttr)) {
@@ -577,7 +602,7 @@ export class LogicItem extends Vertex {
577
602
  await config.defaultApp?.history.load(actionOptions?.actionMode !== ACTION_MODE.undoRedo && {
578
603
  operationAction: 'LogicItem.move',
579
604
  operationBeforeImage: null,
580
- operationAfterImage: null, // JSON.parse(JSON.stringify(this)),
605
+ operationAfterImage: null,
581
606
  operationDesc: `移动逻辑项"${this.label || this.type}"`,
582
607
  });
583
608
  config.defaultApp?.emit('saved');
@@ -612,6 +637,8 @@ export class LogicItem extends Vertex {
612
637
  * @param targetId
613
638
  */
614
639
  static async paste(logicItems: LogicItem[] | LogicItem, targetType: 'logic' | 'html' | 'processComponent', targetId: string) {
640
+ config.defaultApp?.emit('saving');
641
+
615
642
  if (!Array.isArray(logicItems))
616
643
  logicItems = [logicItems];
617
644
 
@@ -630,7 +657,7 @@ export class LogicItem extends Vertex {
630
657
  operationAction: 'LogicItem.paste',
631
658
  operationDesc: `粘贴逻辑项"${logicItems[0].label || logicItems[0].type}"`,
632
659
  },
633
- });
660
+ }).catch(catchFn(vertexsMap.get(targetId) as Logic));
634
661
 
635
662
  LogicItem.redoPaste(res);
636
663
  }
@@ -778,27 +805,22 @@ export class LogicItem extends Vertex {
778
805
  delete body.index;
779
806
  ///
780
807
 
781
- try {
782
- await logicService.removeItem({
783
- headers: {
784
- appId: config.defaultApp?.id,
785
- serviceId: this.logic?.interface?.serviceId,
786
- operationAction: 'LogicItem.delete',
787
- operationDesc: `删除逻辑项"${this.label || this.type}"`,
788
-
789
- },
790
- body,
791
- });
792
- } catch (err) {
793
- await config.defaultApp?.history.load();
794
- throw err;
795
- }
808
+ await logicService.removeItem({
809
+ headers: {
810
+ moduleType: this.logic?.moduleType,
811
+ appId: config.defaultApp?.id,
812
+ serviceId: this.logic?.interface?.serviceId,
813
+ operationAction: 'LogicItem.delete',
814
+ operationDesc: `删除逻辑项"${this.label || this.type}"`,
815
+ },
816
+ body,
817
+ }).catch(catchFn(this.logic));
796
818
  }
797
819
  }
798
820
 
799
821
  if (this.id) {
800
822
  typeCheck.delete(this.id);
801
- this.logic.interface?.service?.syncStructures(); // 处理 CallQueryComponent 嵌套的情形
823
+ this.logic?.interface?.service?.syncStructures(); // 处理 CallQueryComponent 嵌套的情形
802
824
 
803
825
  const parent: LogicItem = this.parent;
804
826
  if (parent && parent.checkType) {
@@ -858,7 +880,6 @@ export class LogicItem extends Vertex {
858
880
  }
859
881
  this.assign(source);
860
882
  }
861
- // const body = this.toPlainJSON();
862
883
  const body = this.toJSON();
863
884
 
864
885
  body.params = (this as any).params && JSON.parse(JSON.stringify((this as any).params));
@@ -877,14 +898,14 @@ export class LogicItem extends Vertex {
877
898
  if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
878
899
  const result = await logicService.updateItem({
879
900
  headers: {
901
+ moduleType: this.logic.moduleType,
880
902
  appId: config.defaultApp?.id,
881
903
  operationAction: 'LogicItem.update',
882
904
  operationDesc: `修改逻辑项"${this.label || this.type}"`,
883
905
  operationIgnore: actionOptions?.actionIgnore,
884
906
  },
885
907
  body,
886
- });
887
- // this.deepPick(result, ['id', 'parentId', 'parentAttr']);
908
+ }).catch(catchFn(this.logic));
888
909
 
889
910
  // 合并params里的id
890
911
  if (body.params && body.params.length) {
@@ -904,7 +925,6 @@ export class LogicItem extends Vertex {
904
925
  let eachSchema = getSchemaOfExpressionNode(each);
905
926
  if (eachSchema) {
906
927
  eachSchema = eachSchema.schema || eachSchema;
907
- // eachSchema = convert2SchemaType(eachSchema);
908
928
  (item as any).schema = eachSchema.items; // 兼容老的items形式
909
929
  if (eachSchema.type === 'genericType') {
910
930
  (item as any).schema = eachSchema.typeInstantiation.typeParams[0].typeParamValue;
@@ -925,7 +945,7 @@ export class LogicItem extends Vertex {
925
945
 
926
946
  await config.defaultApp?.history.load(actionOptions?.actionMode !== ACTION_MODE.undoRedo && {
927
947
  operationAction: 'LogicItem.update',
928
- operationBeforeImage: null, // JSON.parse(JSON.stringify(this)),
948
+ operationBeforeImage: null,
929
949
  operationAfterImage: null,
930
950
  operationDesc: `修改逻辑项"${this.label || this.type}"`,
931
951
  });
@@ -1062,7 +1082,6 @@ export class LogicItem extends Vertex {
1062
1082
  if (!typeCheckResult || !logicItem || typeof typeCheckResult !== 'object')
1063
1083
  return;
1064
1084
 
1065
- // if(logicItem.id === typeCheckResult.id)
1066
1085
  logicItem.typeCheckNote = typeCheckResult.typeCheckNote;
1067
1086
 
1068
1087
  for (const [key, object] of Object.entries(typeCheckResult)) {
@@ -1200,8 +1219,6 @@ export class LogicNode extends LogicItem {
1200
1219
  const hasInstantiated = source && source.id && vertexsMap.get(source.id) instanceof LogicNode;
1201
1220
  if (hasInstantiated) {
1202
1221
  console.warn(`LogicNode (${source.id}) 多次实例化`);
1203
- // Object.assign(vertexsMap.get(source.id), source);
1204
- // return vertexsMap.get(source.id) as LogicNode;
1205
1222
  }
1206
1223
 
1207
1224
  source && this.assign(source);
@@ -1,9 +1,30 @@
1
- import { immutable, excludedInJSON, action } from '../decorators';
2
- import { config, history, utils, LEVEL_ENUM, Vertex, Logic, PackageJSON, App, WebService, Page, Block, Schema, BaseVariable, ActionOptions, Interface } from '..';
1
+ import { immutable, action } from '../decorators';
2
+ import { config, utils, LEVEL_ENUM, Vertex, Logic, Schema, BaseVariable, ActionOptions, Interface } from '..';
3
3
  import { paramService } from '../../service/logic';
4
- import { convert2RefType, convert2SchemaType } from '../data/dataTypeUtils';
4
+ import { convert2RefType } from '../data/dataTypeUtils';
5
5
  import { getBasicTypeDefaultValue } from '../data/basicTypes';
6
6
  import { schemaService } from '../../service/common';
7
+ import { refreshLogic, refreshInterfaces, refreshView } from '../cache';
8
+ import { BusinessCode } from '../enum';
9
+
10
+ export function catchFn(logic: Logic) {
11
+ return async (err: any) => {
12
+ const code = err?.code;
13
+ // 节点已存在; 节点不存在
14
+ if ([BusinessCode.ElementExist, BusinessCode.ElementNotExist].includes(code)) {
15
+ await refreshLogic(logic);
16
+ } else if (code === BusinessCode.ParentElementNotExist) { // 父节点不存在,即逻辑不存在
17
+ if (logic.interface) {
18
+ await refreshInterfaces();
19
+ } else if (logic.view) {
20
+ await refreshView(logic.view);
21
+ }
22
+ } else
23
+ config.defaultApp?.emit('saved', err);
24
+ config.defaultApp?.history.load();
25
+ throw err;
26
+ };
27
+ }
7
28
 
8
29
  /**
9
30
  * 逻辑输入参数
@@ -50,23 +71,21 @@ export class Param extends BaseVariable {
50
71
  config.defaultApp?.emit('saving');
51
72
 
52
73
  const body = this.toJSON();
53
- // convert2SchemaType(body.schema);
54
74
  body._posIndex = this.logic.params.indexOf(this);
55
75
  utils.logger.debug('添加逻辑输入参数', body);
56
76
  const result: Param = await paramService.create({
57
77
  headers: {
78
+ moduleType: this.logic && this.logic.moduleType,
58
79
  appId: config.defaultApp?.id,
59
80
  operationAction: actionOptions?.actionName || 'Param.create',
60
81
  operationDesc: actionOptions?.actionDesc || `添加逻辑"${this.logic.name}"输入参数"${this.name}"`,
61
82
  },
62
83
  body,
63
- });
64
- // convert2RefType(result.schema);
84
+ }).catch(catchFn(this.logic));
65
85
  this.deepPick(result, ['id']);
66
86
  this.assign({ code: this.genCode() });
67
87
  if (this.logic.interface) {
68
88
  const interfaceItem = Vertex.getVertexByRef(this.logic.interface.id) as Interface;
69
- // this.logic.interface.service.emit('interfacesChange');
70
89
  interfaceItem.setParamAndReturn();
71
90
  } else if (this.logic.view) {
72
91
  this.logic.view.page.service.emit('pageTreeChange');
@@ -75,6 +94,9 @@ export class Param extends BaseVariable {
75
94
 
76
95
  await config.defaultApp?.history.load();
77
96
  config.defaultApp?.emit('saved');
97
+
98
+ // 更新所有调用此Logic的LogicItem
99
+ // await this.logic.callLogicUpdate();
78
100
  return this;
79
101
  }
80
102
  /**
@@ -85,29 +107,24 @@ export class Param extends BaseVariable {
85
107
  config.defaultApp?.emit('saving');
86
108
 
87
109
  if (this.id) {
88
- try {
89
- await paramService.delete({
90
- headers: {
91
- appId: config.defaultApp?.id,
92
- operationAction: actionOptions?.actionName || 'Param.create',
93
- operationDesc: actionOptions?.actionDesc || `删除逻辑"${this.logic.name}"输入参数"${this.name}"`,
94
- },
95
- query: {
96
- loValId: this.id,
97
- logicId: this.logic.id,
98
- },
99
- });
100
- } catch(err) {
101
- await config.defaultApp?.history.load();
102
- throw err;
103
- }
110
+ await paramService.delete({
111
+ headers: {
112
+ moduleType: this.logic && this.logic.moduleType,
113
+ appId: config.defaultApp?.id,
114
+ operationAction: actionOptions?.actionName || 'Param.create',
115
+ operationDesc: actionOptions?.actionDesc || `删除逻辑"${this.logic.name}"输入参数"${this.name}"`,
116
+ },
117
+ query: {
118
+ loValId: this.id,
119
+ logicId: this.logic.id,
120
+ },
121
+ }).catch(catchFn(this.logic));
104
122
  }
105
123
 
106
124
  const index = this.logic.params.indexOf(this);
107
125
  ~index && this.logic.params.splice(index, 1);
108
126
  this.destroy();
109
127
  if (this.logic.interface) {
110
- // this.logic.interface.service.emit('interfacesChange');
111
128
  this.logic.interface.setParamAndReturn();
112
129
  } else if (this.logic.view) {
113
130
  this.logic.view.page.service.emit('pageTreeChange');
@@ -124,20 +141,17 @@ export class Param extends BaseVariable {
124
141
  config.defaultApp?.emit('saving');
125
142
 
126
143
  const body = this.toJSON();
127
- // convert2SchemaType(body.schema);
128
144
  utils.logger.debug('修改逻辑输入参数', body);
129
145
  const result = await paramService.update({
130
146
  headers: {
147
+ moduleType: this.logic && this.logic.moduleType,
131
148
  appId: config.defaultApp?.id,
132
149
  operationAction: actionOptions?.actionName || 'Param.update',
133
150
  operationDesc: actionOptions?.actionDesc || `修改逻辑输入参数"${this.name}"`,
134
151
  },
135
152
  body,
136
- });
153
+ }).catch(catchFn(this.logic));
137
154
  this.schema.id = result.schema.id;
138
- // convert2RefType(result.schema);
139
- // this.plainAssign(result);
140
-
141
155
  await then?.();
142
156
  await config.defaultApp?.history.load();
143
157
  config.defaultApp?.emit('saved');
@@ -156,7 +170,6 @@ export class Param extends BaseVariable {
156
170
  });
157
171
 
158
172
  if (this.logic.interface) {
159
- // this.logic.interface.service.emit('interfacesChange');
160
173
  this.logic.interface.setParamAndReturn();
161
174
  } else if (this.logic.view) {
162
175
  this.logic.view.page.service.emit('pageTreeChange');
@@ -213,7 +226,6 @@ export class Param extends BaseVariable {
213
226
  typeInstantiation: undefined,
214
227
  });
215
228
  Object.assign(this.schema, schema);
216
- // if (this.defaultValue)
217
229
  this.assign({ defaultValue: getBasicTypeDefaultValue() });
218
230
 
219
231
  try {
@@ -223,7 +235,6 @@ export class Param extends BaseVariable {
223
235
  this.genSchemaChildren();
224
236
 
225
237
  if (this.logic.interface) {
226
- // this.logic.interface.service.emit('interfacesChange');
227
238
  this.logic.interface.setParamAndReturn();
228
239
  } else if (this.logic.view) {
229
240
  this.logic.view.page.service.emit('pageTreeChange');
@@ -250,7 +261,6 @@ export class Param extends BaseVariable {
250
261
  this.genSchemaChildren();
251
262
 
252
263
  if (this.logic.interface) {
253
- // this.logic.interface.service.emit('interfacesChange');
254
264
  this.logic.interface.setParamAndReturn();
255
265
  } else if (this.logic.view) {
256
266
  this.logic.view.page.service.emit('pageTreeChange');
@@ -286,7 +296,6 @@ export class Param extends BaseVariable {
286
296
  });
287
297
 
288
298
  if (this.logic.interface) {
289
- // this.logic.interface.service.emit('interfacesChange');
290
299
  this.logic.interface.setParamAndReturn();
291
300
  } else if (this.logic.view) {
292
301
  this.logic.view.page.service.emit('pageTreeChange');
@@ -305,7 +314,6 @@ export class Param extends BaseVariable {
305
314
  });
306
315
 
307
316
  if (this.logic.interface) {
308
- // this.logic.interface.service.emit('interfacesChange');
309
317
  this.logic.interface.setParamAndReturn();
310
318
  } else if (this.logic.view) {
311
319
  this.logic.view.page.service.emit('pageTreeChange');
@@ -1,10 +1,10 @@
1
- import { immutable, excludedInJSON, action } from '../decorators';
2
- import { config, history, utils, ActionOptions, LEVEL_ENUM, Vertex, Logic, PackageJSON, App, WebService, Page, Block, Schema, BaseVariable, genRefSchemaChildren } from '..';
1
+ import { immutable, action } from '../decorators';
2
+ import { config, utils, ActionOptions, LEVEL_ENUM, Logic, Schema, BaseVariable, genRefSchemaChildren } from '..';
3
3
  import { paramService } from '../../service/logic';
4
- import { convert2RefType, convert2SchemaType } from '../data/dataTypeUtils';
4
+ import { convert2RefType } from '../data/dataTypeUtils';
5
5
  import { getBasicTypeDefaultValue } from '../data/basicTypes';
6
6
  import { schemaService } from '../../service/common';
7
-
7
+ import { catchFn } from './Param';
8
8
  /**
9
9
  * 逻辑输出参数
10
10
  */
@@ -40,23 +40,21 @@ export class Return extends BaseVariable {
40
40
  config.defaultApp?.emit('saving');
41
41
 
42
42
  const body = this.toJSON();
43
- // convert2SchemaType(body.schema);
44
43
  body._posIndex = this.logic.returns.indexOf(this);
45
44
  utils.logger.debug('添加逻辑输出参数', body);
46
45
  const result: Return = await paramService.create({
47
46
  headers: {
47
+ moduleType: this.logic && this.logic.moduleType,
48
48
  appId: config.defaultApp?.id,
49
49
  operationAction: actionOptions?.actionName || 'Return.create',
50
50
  operationDesc: actionOptions?.actionDesc || `添加逻辑"${this.logic.name}"输出参数"${this.name}"`,
51
51
  },
52
52
  body,
53
- });
54
- // convert2RefType(result.schema);
53
+ }).catch(catchFn(this.logic));
55
54
  this.deepPick(result, ['id']);
56
55
  this.assign({ code: this.genCode() });
57
56
 
58
57
  if (this.logic.interface) {
59
- // this.logic.interface.service.emit('interfacesChange');
60
58
  this.logic.interface.setParamAndReturn();
61
59
  } else if (this.logic.view) {
62
60
  this.logic.view.page.service.emit('pageTreeChange');
@@ -75,29 +73,24 @@ export class Return extends BaseVariable {
75
73
  config.defaultApp?.emit('saving');
76
74
 
77
75
  if (this.id) {
78
- try {
79
- await paramService.delete({
80
- headers: {
81
- appId: config.defaultApp?.id,
82
- operationAction: actionOptions?.actionName || 'Return.create',
83
- operationDesc: `删除逻辑"${this.logic.name}"输出参数"${this.name}"`,
84
- },
85
- query: {
86
- loValId: this.id,
87
- logicId: this.logic.id,
88
- },
89
- });
90
- } catch(err) {
91
- await config.defaultApp?.history.load();
92
- throw err;
93
- }
76
+ await paramService.delete({
77
+ headers: {
78
+ moduleType: this.logic && this.logic.moduleType,
79
+ appId: config.defaultApp?.id,
80
+ operationAction: actionOptions?.actionName || 'Return.create',
81
+ operationDesc: `删除逻辑"${this.logic.name}"输出参数"${this.name}"`,
82
+ },
83
+ query: {
84
+ loValId: this.id,
85
+ logicId: this.logic.id,
86
+ },
87
+ }).catch(catchFn(this.logic));
94
88
  }
95
89
 
96
90
  const index = this.logic.returns.indexOf(this);
97
91
  ~index && this.logic.returns.splice(index, 1);
98
92
 
99
93
  if (this.logic.interface) {
100
- // this.logic.interface.service.emit('interfacesChange');
101
94
  this.logic.interface.setParamAndReturn();
102
95
  } else if (this.logic.view) {
103
96
  this.logic.view.page.service.emit('pageTreeChange');
@@ -114,19 +107,17 @@ export class Return extends BaseVariable {
114
107
  config.defaultApp?.emit('saving');
115
108
 
116
109
  const body = this.toJSON();
117
- // convert2SchemaType(body.schema);
118
110
  utils.logger.debug('修改逻辑输出参数', body);
119
111
  const result = await paramService.update({
120
112
  headers: {
113
+ moduleType: this.logic && this.logic.moduleType,
121
114
  appId: config.defaultApp?.id,
122
115
  operationAction: actionOptions?.actionName || 'Return.update',
123
116
  operationDesc: actionOptions?.actionDesc || `修改逻辑输出参数"${this.name}"`,
124
117
  },
125
118
  body,
126
- });
119
+ }).catch(catchFn(this.logic));
127
120
  this.schema.id = result.schema.id;
128
- // convert2RefType(result.schema);
129
- // this.plainAssign(result);
130
121
 
131
122
  await then?.();
132
123
  await config.defaultApp?.history.load();
@@ -146,7 +137,6 @@ export class Return extends BaseVariable {
146
137
  });
147
138
 
148
139
  if (this.logic.interface) {
149
- // this.logic.interface.service.emit('interfacesChange');
150
140
  this.logic.interface.setParamAndReturn();
151
141
  } else if (this.logic.view) {
152
142
  this.logic.view.page.service.emit('pageTreeChange');
@@ -197,13 +187,12 @@ export class Return extends BaseVariable {
197
187
  defaultValue: this.defaultValue,
198
188
  };
199
189
  Object.assign(this.schema, {
200
- $ref: undefined, //引用到Entity或者structure
190
+ $ref: undefined, // 引用到Entity或者structure
201
191
  type: undefined,
202
192
  format: undefined,
203
193
  typeInstantiation: undefined,
204
194
  });
205
195
  Object.assign(this.schema, schema);
206
- // if (this.defaultValue)
207
196
  this.assign({ defaultValue: getBasicTypeDefaultValue() });
208
197
  try {
209
198
  await this.update(undefined, {
@@ -212,7 +201,6 @@ export class Return extends BaseVariable {
212
201
  this.genSchemaChildren();
213
202
 
214
203
  if (this.logic.interface) {
215
- // this.logic.interface.service.emit('interfacesChange');
216
204
  this.logic.interface.setParamAndReturn();
217
205
  } else if (this.logic.view) {
218
206
  this.logic.view.page.service.emit('pageTreeChange');
@@ -239,7 +227,6 @@ export class Return extends BaseVariable {
239
227
  this.genSchemaChildren();
240
228
 
241
229
  if (this.logic.interface) {
242
- // this.logic.interface.service.emit('interfacesChange');
243
230
  this.logic.interface.setParamAndReturn();
244
231
  } else if (this.logic.view) {
245
232
  this.logic.view.page.service.emit('pageTreeChange');
@@ -1,9 +1,10 @@
1
- import { immutable, excludedInJSON, action } from '../decorators';
2
- import { config, history, utils, LEVEL_ENUM, Vertex, Logic, PackageJSON, App, WebService, Page, Block, Schema, BaseVariable, ActionOptions } from '..';
1
+ import { immutable, action } from '../decorators';
2
+ import { config, utils, LEVEL_ENUM, Logic, Schema, BaseVariable, ActionOptions } from '..';
3
3
  import { paramService } from '../../service/logic';
4
- import { convert2RefType, convert2SchemaType } from '../data/dataTypeUtils';
4
+ import { convert2RefType } from '../data/dataTypeUtils';
5
5
  import { getBasicTypeDefaultValue } from '../data/basicTypes';
6
6
  import { schemaService } from '../../service/common';
7
+ import { catchFn } from './Param';
7
8
 
8
9
  /**
9
10
  * 逻辑局部变量
@@ -39,18 +40,18 @@ export class Variable extends BaseVariable {
39
40
  config.defaultApp?.emit('saving');
40
41
 
41
42
  const body = this.toJSON();
42
- // convert2SchemaType(body.schema);
43
43
  body._posIndex = this.logic.variables.indexOf(this);
44
44
  utils.logger.debug('添加逻辑局部变量', body);
45
45
  const result: Variable = await paramService.create({
46
46
  headers: {
47
+ moduleType: this.logic && this.logic.moduleType,
47
48
  appId: config.defaultApp?.id,
48
49
  operationAction: actionOptions?.actionName || 'Variable.create',
49
50
  operationDesc: actionOptions?.actionDesc || `添加逻辑"${this.logic.name}"局部变量"${this.name}"`,
50
51
  },
51
52
  body,
52
- });
53
- // convert2RefType(result.schema);
53
+ }).catch(catchFn(this.logic));
54
+
54
55
  this.deepPick(result, ['id']);
55
56
  this.assign({ code: this.genCode() });
56
57
 
@@ -73,22 +74,18 @@ export class Variable extends BaseVariable {
73
74
  config.defaultApp?.emit('saving');
74
75
 
75
76
  if (this.id) {
76
- try {
77
- await paramService.delete({
78
- headers: {
79
- appId: config.defaultApp?.id,
80
- operationAction: actionOptions?.actionName || 'Param.create',
81
- operationDesc: actionOptions?.actionDesc || `删除逻辑"${this.logic.name}"局部变量"${this.name}"`,
82
- },
83
- query: {
84
- loValId: this.id,
85
- logicId: this.logic.id,
86
- },
87
- });
88
- } catch(err) {
89
- await config.defaultApp?.history.load();
90
- throw err;
91
- }
77
+ await paramService.delete({
78
+ headers: {
79
+ moduleType: this.logic && this.logic.moduleType,
80
+ appId: config.defaultApp?.id,
81
+ operationAction: actionOptions?.actionName || 'Param.create',
82
+ operationDesc: actionOptions?.actionDesc || `删除逻辑"${this.logic.name}"局部变量"${this.name}"`,
83
+ },
84
+ query: {
85
+ loValId: this.id,
86
+ logicId: this.logic.id,
87
+ },
88
+ }).catch(catchFn(this.logic));
92
89
  }
93
90
 
94
91
  const index = this.logic.variables.indexOf(this);
@@ -111,19 +108,17 @@ export class Variable extends BaseVariable {
111
108
  config.defaultApp?.emit('saving');
112
109
 
113
110
  const body = this.toJSON();
114
- // convert2SchemaType(body.schema);
115
111
  utils.logger.debug('修改逻辑局部变量', body);
116
112
  const result = await paramService.update({
117
113
  headers: {
114
+ moduleType: this.logic && this.logic.moduleType,
118
115
  appId: config.defaultApp?.id,
119
116
  operationAction: actionOptions?.actionName || 'Param.update',
120
117
  operationDesc: actionOptions?.actionDesc || `修改逻辑局部变量"${this.name}"`,
121
118
  },
122
119
  body,
123
- });
120
+ }).catch(catchFn(this.logic));
124
121
  this.schema.id = result.schema.id;
125
- // convert2RefType(result.schema);
126
- // this.plainAssign(result);
127
122
 
128
123
  await then?.();
129
124
  await config.defaultApp?.history.load();
@@ -199,7 +194,6 @@ export class Variable extends BaseVariable {
199
194
  typeInstantiation: undefined,
200
195
  });
201
196
  Object.assign(this.schema, schema);
202
- // if (this.defaultValue)
203
197
  this.assign({ defaultValue: getBasicTypeDefaultValue() });
204
198
  try {
205
199
  await this.update(undefined, {