@lcap/nasl 1.0.0-alpha.5 → 1.0.0-alpha.6

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 (96) hide show
  1. package/package.json +4 -2
  2. package/src/automate/engine/index.js +179 -100
  3. package/src/automate/engine/utils.js +89 -60
  4. package/src/common/BaseNode.ts +11 -1
  5. package/src/common/EventEmitter.ts +1 -0
  6. package/src/concepts/App__.ts +1 -1
  7. package/src/concepts/Argument__.ts +1 -1
  8. package/src/concepts/Assignment__.ts +1 -1
  9. package/src/concepts/Attribute__.ts +1 -1
  10. package/src/concepts/BinaryExpression__.ts +1 -1
  11. package/src/concepts/BindAttribute__.ts +1 -1
  12. package/src/concepts/BindDirective__.ts +4 -2
  13. package/src/concepts/BindEvent__.ts +17 -15
  14. package/src/concepts/BooleanLiteral__.ts +1 -1
  15. package/src/concepts/CallFunction__.ts +1 -1
  16. package/src/concepts/CallInterface__.ts +1 -1
  17. package/src/concepts/CallLogic__.ts +1 -1
  18. package/src/concepts/CallQueryComponent__.ts +1 -1
  19. package/src/concepts/Comment__.ts +1 -1
  20. package/src/concepts/CompletionProperty__.ts +2 -2
  21. package/src/concepts/ConfigGroup__.ts +1 -1
  22. package/src/concepts/ConfigPropertyValue__.ts +1 -1
  23. package/src/concepts/ConfigProperty__.ts +1 -1
  24. package/src/concepts/Configuration__.ts +1 -1
  25. package/src/concepts/Constant__.ts +1 -1
  26. package/src/concepts/DataElement__.ts +1 -1
  27. package/src/concepts/Destination__.ts +1 -1
  28. package/src/concepts/End__.ts +1 -1
  29. package/src/concepts/EntityIndex__.ts +1 -1
  30. package/src/concepts/EntityProperty__.ts +1 -1
  31. package/src/concepts/Entity__.ts +5 -1
  32. package/src/concepts/EnumItem__.ts +1 -1
  33. package/src/concepts/Enum__.ts +12 -3
  34. package/src/concepts/Event__.ts +1 -1
  35. package/src/concepts/ForEachStatement__.ts +1 -1
  36. package/src/concepts/Function__.ts +7 -1
  37. package/src/concepts/Identifier__.ts +21 -4
  38. package/src/concepts/IfStatement__.ts +6 -2
  39. package/src/concepts/InterfaceParam__.ts +1 -1
  40. package/src/concepts/Interface__.ts +43 -41
  41. package/src/concepts/JSBlock__.ts +1 -1
  42. package/src/concepts/LogicItem__.ts +1 -1
  43. package/src/concepts/Logic__.ts +46 -1
  44. package/src/concepts/MemberExpression__.ts +10 -3
  45. package/src/concepts/Module__.ts +125 -150
  46. package/src/concepts/Namespace__.ts +1 -1
  47. package/src/concepts/NullLiteral__.ts +1 -1
  48. package/src/concepts/NumericLiteral__.ts +1 -1
  49. package/src/concepts/Param__.ts +1 -1
  50. package/src/concepts/Point__.ts +1 -1
  51. package/src/concepts/ProcessComponent__.ts +1 -1
  52. package/src/concepts/ProcessElement__.ts +125 -97
  53. package/src/concepts/ProcessOutcome__.ts +1 -1
  54. package/src/concepts/Process__.ts +2 -5
  55. package/src/concepts/QueryAggregateExpression__.ts +1 -1
  56. package/src/concepts/QueryFieldExpression__.ts +1 -1
  57. package/src/concepts/QueryFromExpression__.ts +1 -1
  58. package/src/concepts/QueryGroupByExpression__.ts +1 -1
  59. package/src/concepts/QueryJoinExpression__.ts +1 -1
  60. package/src/concepts/QueryLimitExpression__.ts +1 -1
  61. package/src/concepts/QueryOrderByExpression__.ts +1 -1
  62. package/src/concepts/QuerySelectExpression__.ts +1 -1
  63. package/src/concepts/Rect__.ts +1 -1
  64. package/src/concepts/Return__.ts +1 -1
  65. package/src/concepts/Role__.ts +1 -1
  66. package/src/concepts/Slot__.ts +1 -1
  67. package/src/concepts/SqlQueryComponent__.ts +1 -1
  68. package/src/concepts/Start__.ts +1 -1
  69. package/src/concepts/StringLiteral__.ts +1 -1
  70. package/src/concepts/StructureProperty__.ts +1 -1
  71. package/src/concepts/Structure__.ts +39 -39
  72. package/src/concepts/SwitchCase__.ts +1 -1
  73. package/src/concepts/SwitchStatement__.ts +1 -1
  74. package/src/concepts/Theme__.ts +1 -1
  75. package/src/concepts/Transactional__.ts +1 -1
  76. package/src/concepts/TypeAnnotation__.ts +1 -1
  77. package/src/concepts/TypeParam__.ts +1 -1
  78. package/src/concepts/UnaryExpression__.ts +1 -1
  79. package/src/concepts/Unparsed__.ts +1 -1
  80. package/src/concepts/UseComponent__.ts +1 -1
  81. package/src/concepts/ValidationRule__.ts +1 -1
  82. package/src/concepts/Variable__.ts +1 -1
  83. package/src/concepts/ViewComponent__.ts +1 -1
  84. package/src/concepts/ViewElement__.ts +36 -7
  85. package/src/concepts/View__.ts +8 -2
  86. package/src/concepts/WhileStatement__.ts +6 -2
  87. package/src/concepts/basics/stdlib/nasl.util.ts +29 -0
  88. package/src/decorators/index.ts +6 -3
  89. package/src/server/createUiTs.ts +5 -3
  90. package/src/server/getMemberIdentifier.ts +13 -13
  91. package/src/server/naslServer.ts +117 -37
  92. package/src/server/process2LogicNamespace.ts +3 -2
  93. package/src/service/storage/init.ts +78 -10
  94. package/src/templator/genCreateBlock.ts +4 -7
  95. package/src/templator/genListViewBlock.ts +3 -1
  96. package/src/templator/genSelectBlock.ts +12 -2
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lcap/nasl",
3
3
  "description": "NetEase Application Specific Language",
4
- "version": "1.0.0-alpha.5",
4
+ "version": "1.0.0-alpha.6",
5
5
  "author": "Forrest <rainforest92@126.com>",
6
6
  "scripts": {
7
7
  "dev": "tsc -watch -p ./",
@@ -34,6 +34,7 @@
34
34
  "@types/json-stringify-safe": "^5.0.0",
35
35
  "axios": "^0.21.1",
36
36
  "faker": "^5.4.0",
37
+ "fs-extra": "^10.1.0",
37
38
  "json-stringify-safe": "^5.0.1",
38
39
  "lodash": "^4.17.21",
39
40
  "module-alias": "^2.2.2",
@@ -43,7 +44,8 @@
43
44
  "request-pre": "^0.4.3",
44
45
  "socket.io-client": "^2.4.0",
45
46
  "uuid": "^8.3.2",
46
- "vue-template-compiler": "^2.6.10"
47
+ "vue": "2.6.14",
48
+ "vue-template-compiler": "2.6.14"
47
49
  },
48
50
  "devDependencies": {
49
51
  "@types/chai": "^4.2.14",
@@ -1,24 +1,26 @@
1
- import { v4 as uuidv4 } from 'uuid';
2
- import { uniq } from 'lodash';
1
+ import { v4 as uuidv4 } from 'uuid';
2
+ import { uniq, omit } from 'lodash';
3
3
  import { BaseNode } from '../../common/BaseNode';
4
- import {
4
+ import {
5
5
  tracking,
6
6
  TRACK_TYPE,
7
- } from './utils'
8
- import {
9
- getConceptConstructor, getConceptMeta
7
+ IGNORE_PROPERTY,
8
+ } from './utils';
9
+ import {
10
+ getConceptConstructor, getConceptMeta,
10
11
  } from '../../decorators/index';
11
12
  let id = 0;
12
13
  class TemplateMeta {
13
14
  constructor(node) {
14
15
  // this.name = `t_${uuidv4().replace(/-/g, '')}`;
15
- this.name = `t_${node.concept}_${node.name ? node.name.replace(/-/g, ''): 'unknown'}_${id++}`
16
+ this.name = `t_${node.concept}_${node.name ? node.name.replace(/-/g, '') : 'unknown'}_${id++}`;
16
17
  this.node = node;
17
18
  this.isRoot = false;
18
19
  this.rootBinds = [];
19
20
  this.binds = [];
20
21
  this.callees = [];
21
22
  this.modules = [];
23
+ this.rolebinds = [];
22
24
  }
23
25
 
24
26
  addRootBinds(propertyName, templateMeta) {
@@ -26,7 +28,7 @@ class TemplateMeta {
26
28
  this.rootBinds.push({
27
29
  propertyName,
28
30
  value: templateMeta.name,
29
- })
31
+ });
30
32
  }
31
33
 
32
34
  addBinds(type, propertyName, templateMeta) {
@@ -36,53 +38,51 @@ class TemplateMeta {
36
38
  type,
37
39
  propertyName,
38
40
  value: templateMeta.name,
39
- })
41
+ });
40
42
  }
41
43
 
42
44
  addPlainBinds(propertyName, value) {
43
45
  // this.node.[propertyName] = value
44
- if(typeof value === 'string') {
45
- value = `"${value}"`
46
+ if (typeof value === 'string') {
47
+ value = `"${value}"`;
46
48
  }
47
- if(typeof value === 'object') {
49
+ if (typeof value === 'object') {
48
50
  value = JSON.stringify(value);
49
51
  }
50
52
  this.binds.push({
51
53
  type: TRACK_TYPE.PLAIN,
52
54
  propertyName,
53
55
  value,
54
- })
56
+ });
55
57
  }
56
58
 
57
59
  addModule(m) {
58
60
  this.modules.push({
59
61
  name: m.name,
60
62
  belongs: m.parentKey,
61
- data: m.toTemplateJSON(),
62
- })
63
+ data: m._toJSON(source => {
64
+ return omit(source, IGNORE_PROPERTY);
65
+ }),
66
+ });
63
67
  }
64
68
 
65
- addCallee(
66
- propertyName,
67
- relatedPropertyName,
68
- templateMeta
69
- ) {
69
+ addCallee(propertyName,
70
+ relatedPropertyName,
71
+ templateMeta) {
70
72
  // this.node.[propertyName] = [targetVar].getNamespace();
71
73
  // this.node.[relatedPropertyName] = [targetVar].name;
72
74
  this.callees.push({
73
75
  propertyName,
74
76
  relatedPropertyName,
75
77
  targetVar: templateMeta.name,
76
- })
78
+ });
77
79
  }
78
80
 
79
- addCalleeTemplate(
80
- propertyName,
81
- relatedPropertyName,
81
+ addCalleeTemplate(propertyName,
82
+ relatedPropertyName,
82
83
  nstemplate,
83
84
  nametemplate,
84
- arguVars,
85
- ) {
85
+ arguVars) {
86
86
  // this.node.[propertyName] = nstemplate([arguVars]);
87
87
  // this.node.[relatedPropertyName] = nametemplate([arguVars]);
88
88
  this.callees.push({
@@ -90,36 +90,44 @@ class TemplateMeta {
90
90
  relatedPropertyName,
91
91
  nstemplate,
92
92
  nametemplate,
93
+ arguVars,
94
+ });
95
+ }
96
+
97
+ addRoleTemplate(
98
+ propertyName,
99
+ arguVars
100
+ ) {
101
+ this.rolebinds.push({
102
+ propertyName,
93
103
  arguVars
94
104
  })
95
105
  }
96
106
 
97
107
  genComment(part) {
98
- return `/*---------${this.node.concept} ${this.node.name} ${part} -----------*/`
108
+ return `/*---------${this.node.concept} ${this.node.name} ${part} -----------*/`;
99
109
  }
100
110
 
101
111
  genCreate() {
102
112
  // [this.name] = create[this.node.concept]();
103
-
113
+
104
114
  // return `${this.genComment('create')}
105
115
  // _tempConstructor = getConceptConstructor("${this.node.concept}");
106
116
  // const ${this.name} = new _tempConstructor();`
107
117
  return `${this.genComment('create')}
108
- const ${this.name} = _create("${this.node.concept}");`
118
+ let ${this.name} = _create("${this.node.concept}");`;
109
119
  }
110
120
 
111
- genBind() {
112
- return this.binds.map(bind => {
121
+ genBind() {
122
+ return this.binds.map((bind) => {
113
123
  const {
114
- type, propertyName, value
124
+ type, propertyName, value,
115
125
  } = bind;
116
- switch(type) {
126
+ switch (type) {
117
127
  case TRACK_TYPE.PROPERTY:
118
128
  case TRACK_TYPE.PLAIN:
119
- // return `${this.name}.${propertyName} = ${value}`;
120
- return `_set(${this.name}, "${propertyName}", ${value})`
129
+ return `_set(${this.name}, "${propertyName}", ${value})`;
121
130
  case TRACK_TYPE.ARRAY:
122
- // return `${this.name}.${propertyName}.push(${value});
123
131
  return `_push(${this.name}, "${propertyName}", ${value});`;
124
132
  }
125
133
  return '';
@@ -127,61 +135,94 @@ class TemplateMeta {
127
135
  }
128
136
 
129
137
  genRootBind() {
130
- return this.rootBinds.map(bind => {
131
- const {
132
- propertyName, value
138
+ return this.rootBinds.map((bind) => {
139
+ const {
140
+ propertyName, value,
133
141
  } = bind;
142
+ if(propertyName === 'roles') {
143
+ return `
144
+ if(roleCallback) {
145
+ ${value} = roleCallback(${value})
146
+ } else {
147
+ _push(app, "roles", ${value});
148
+ }`
149
+ }
134
150
  // return `app.${propertyName}.push(${value});
135
151
  return `_push(app, "${propertyName}", ${value});`;
136
- })
152
+ });
137
153
  }
138
154
 
139
155
  genEntryBind() {
140
- if(this.isRoot) {
141
- return `rootBindCallback(${this.name})`
156
+ if (this.isRoot) {
157
+ return `rootBindCallback(${this.name})`;
142
158
  }
143
159
  return '';
144
160
  }
145
-
161
+
162
+ genRootReturn() {
163
+ if (this.isRoot) {
164
+ return `return ${this.name};`;
165
+ }
166
+ return '';
167
+ }
168
+
146
169
  genName() {
147
170
  // [this.name].name = this.parent.genUniqueXXXName();
148
171
  // return `${this.name}.name = (${this.name}.parentNode.gen${this.node.concept}UniqueName ? ${this.name}.parentNode.gen${this.node.concept}UniqueName() : ${this.name}.name)`
172
+ if(this.node.concept === 'Role') {
173
+ return '';
174
+ }
175
+ if(this.node.concept === 'Entity') {
176
+ return `${this.name}.name = getGenUniqNameFunctionName(${this.name}, "${this.node.concept}")
177
+ ${this.name}.setTableName(${this.name}.name + app.id.substring(0,5))`;
178
+
179
+ }
149
180
  return `${this.name}.name = getGenUniqNameFunctionName(${this.name}, "${this.node.concept}")`;
150
181
  }
151
182
 
183
+ genRoleBind() {
184
+ return this.rolebinds.map(role => {
185
+ const {
186
+ propertyName,
187
+ arguVars
188
+ } = role;
189
+
190
+ return `_set(${this.name}, "${propertyName}", _bindRoles(${arguVars}));`
191
+ })
192
+ }
193
+
152
194
  genCallee() {
153
- return this.callees.map(callee => {
195
+ return this.callees.map((callee) => {
154
196
  const {
155
- propertyName,
156
- relatedPropertyName,
197
+ propertyName,
198
+ relatedPropertyName,
157
199
  targetVar,
158
200
  nstemplate,
159
201
  nametemplate,
160
- arguVars
202
+ arguVars,
161
203
  } = callee;
162
204
 
163
- if(arguVars && nstemplate && nametemplate) {
164
- // return `${this.name}.${propertyName} = (${nstemplate}(${arguVars}));
165
- // ${this.name}.${relatedPropertyName} = (${nametemplate}(${arguVars}))`
205
+ if (arguVars && nstemplate && nametemplate) {
206
+ // return `${this.name}.${propertyName} = (${nstemplate}(${arguVars}));
207
+ // ${this.name}.${relatedPropertyName} = (${nametemplate}(${arguVars}))`
166
208
  return `_set(${this.name}, "${propertyName}", (${nstemplate}(${arguVars})));
167
- _set(${this.name}, "${relatedPropertyName}", (${nametemplate}(${arguVars})))`
168
-
169
- } else {
170
- // return `${this.name}.${propertyName} = ${targetVar}.getNamespace();
171
- // ${this.name}.${relatedPropertyName} = ${targetVar}.name;`
209
+ _set(${this.name}, "${relatedPropertyName}", (${nametemplate}(${arguVars})))`;
210
+ } else {
211
+ // return `${this.name}.${propertyName} = ${targetVar}.getNamespace();
212
+ // ${this.name}.${relatedPropertyName} = ${targetVar}.name;`
172
213
  return `_set(${this.name}, "${propertyName}", ${targetVar}.getNamespace());
173
- _set(${this.name}, "${relatedPropertyName}", ${targetVar}.name);`
214
+ _set(${this.name}, "${relatedPropertyName}", ${targetVar}.name);`;
174
215
  }
175
- })
216
+ });
176
217
  }
177
218
 
178
219
  genModule() {
179
- return this.modules.map(meta => {
180
- const {
220
+ return this.modules.map((meta) => {
221
+ const {
181
222
  name, belongs, data,
182
223
  } = meta;
183
224
  return `_addModule(app, "${name}", "${belongs}", ${JSON.stringify(data)});`;
184
- })
225
+ });
185
226
  }
186
227
  }
187
228
 
@@ -189,16 +230,27 @@ function autoScript(stack) {
189
230
  const createBlock = [];
190
231
  let rootBindBlock = [];
191
232
  let bindBlock = [];
233
+ let rolebindBlock = [];
192
234
  let appBindBlock = [];
193
235
  const nameBlock = [];
194
236
  let calleeBlock = [];
195
237
  let moduleBlock = [];
238
+ let returnBlock = [];
239
+ let roleNASL = []
240
+
196
241
 
197
- stack.forEach(temp => {
242
+ stack.forEach((temp) => {
198
243
  createBlock.push(temp.genCreate());
199
- if(temp.isRoot) {
244
+ if (temp.isRoot) {
200
245
  rootBindBlock = rootBindBlock.concat(temp.genEntryBind());
246
+ returnBlock = returnBlock.concat(temp.genRootReturn());
201
247
  }
248
+ if (temp.node.concept === 'Role') {
249
+ roleNASL = roleNASL.concat(temp.node._toJSON(source => {
250
+ return omit(source, IGNORE_PROPERTY);
251
+ }))
252
+ }
253
+ rolebindBlock = rolebindBlock.concat(temp.genRoleBind());
202
254
  bindBlock = bindBlock.concat(temp.genBind());
203
255
  appBindBlock = uniq(appBindBlock.concat(temp.genRootBind()));
204
256
  nameBlock.push(temp.genName());
@@ -287,13 +339,22 @@ function autoScript(stack) {
287
339
  }
288
340
  }
289
341
 
342
+ function _bindRoles(){
343
+ return Array.prototype.map.call(arguments, r => r.name);
344
+ }
290
345
  // let _tempConstructor;
291
346
 
292
- return function(app, getCtor, getCMeta, base, rootBindCallback) {
347
+ const exportRoles = function() {
348
+ return ${JSON.stringify(roleNASL)};
349
+ }
350
+
351
+ const execTemplate = function(app, getCtor, getCMeta, base, rootBindCallback, roleCallback) {
293
352
  BaseNodeConstructor = base;
294
353
  getConceptConstructor = getCtor;
295
354
  getConceptMeta = getCMeta;
296
- app.emit('collect:start');
355
+ app.emit('collect:start', {
356
+ actionMsg: '导入页面模板'
357
+ });
297
358
  /*---- create ---- */
298
359
  ${createBlock.join('\n\t\t')}
299
360
 
@@ -309,39 +370,50 @@ function autoScript(stack) {
309
370
  /*---- reset name ---- */
310
371
  ${nameBlock.join('\n\t\t')}
311
372
 
373
+ /*--- role bind ---*/
374
+ ${rolebindBlock.join('\n\t\t')}
375
+
312
376
  /*---- reset callee ---- */
313
377
  ${calleeBlock.join('\n\t\t')}
314
378
 
315
379
  /*---- add module ----*/
316
380
  ${moduleBlock.join('\n\t\t')}
317
381
  app.emit('collect:end');
382
+
383
+ /*---- return root -----*/
384
+ ${returnBlock.join('\n\t\t')}
318
385
  }
319
- })();`
320
386
 
387
+ return {
388
+ execTemplate,
389
+ exportRoles
390
+ }
391
+ })();`;
321
392
  }
322
- let i = 0;
393
+ const i = 0;
323
394
  export function autoTemplate(node) {
324
395
  const visitedMap = new WeakMap();
325
396
  const stack = [];
326
- let startNode = node;
327
- let rootNode = true;;
397
+ const startNode = node;
398
+ let rootNode = true;
328
399
  function iterator(node) {
329
- if(node && !visitedMap.has(node)) {
400
+ if (node && !visitedMap.has(node)) {
330
401
  const meta = new TemplateMeta(node);
331
- if(rootNode) {
402
+ if (rootNode) {
332
403
  meta.isRoot = true;
333
404
  }
334
405
  rootNode = false;
335
406
  stack.push(meta);
336
- visitedMap.set(node, meta)
337
- tracking(node, startNode, function(type, propertyName, property, options = {}) {
407
+ visitedMap.set(node, meta);
408
+ tracking(node, startNode, (type, propertyName, property, options = {}) => {
338
409
  const {
339
410
  rootNode,
340
411
  calleeNode,
341
412
  relatedPropertyName,
342
413
  AppPropertyName,
414
+ metaNodes,
343
415
  } = options;
344
- switch(type) {
416
+ switch (type) {
345
417
  case TRACK_TYPE.PLAIN:
346
418
  meta.addPlainBinds(propertyName, property);
347
419
  break;
@@ -351,17 +423,13 @@ export function autoTemplate(node) {
351
423
  const pmeta = visitedMap.get(property);
352
424
  meta.addBinds(type, propertyName, pmeta);
353
425
  break;
354
- case TRACK_TYPE.CALLEE:
426
+ case TRACK_TYPE.CALLEE:
355
427
  iterator(rootNode);
356
- const cmeta = visitedMap.get(calleeNode)
357
- if(AppPropertyName) {
428
+ const cmeta = visitedMap.get(calleeNode);
429
+ if (AppPropertyName) {
358
430
  meta.addRootBinds(AppPropertyName, visitedMap.get(rootNode));
359
431
  }
360
- meta.addCallee(
361
- propertyName,
362
- relatedPropertyName,
363
- cmeta,
364
- );
432
+ meta.addCallee(propertyName, relatedPropertyName, cmeta);
365
433
  break;
366
434
  case TRACK_TYPE.MODULE:
367
435
  meta.addModule(property);
@@ -370,29 +438,36 @@ export function autoTemplate(node) {
370
438
  const {
371
439
  nstemplate,
372
440
  nametemplate,
373
- metaNodes,
374
441
  } = options;
375
442
  iterator(rootNode);
376
- const arguVars = metaNodes.map(n => visitedMap.get(n).name).join(',')
377
- if(AppPropertyName) {
443
+ const arguVars = metaNodes.map((n) => visitedMap.get(n).name).join(',');
444
+ if (AppPropertyName) {
378
445
  meta.addRootBinds(AppPropertyName, visitedMap.get(rootNode));
379
446
  }
380
- meta.addCalleeTemplate(
447
+ meta.addCalleeTemplate(propertyName, relatedPropertyName, nstemplate, nametemplate, arguVars);
448
+ break;
449
+ case TRACK_TYPE.ROLE_TEMPLATE:
450
+ let roleMetaNames = [];
451
+ metaNodes.forEach(node => {
452
+ iterator(node);
453
+ const m = visitedMap.get(node);
454
+ m.addRootBinds('roles', m);
455
+ roleMetaNames.push(m.name);
456
+ })
457
+
458
+ meta.addRoleTemplate(
381
459
  propertyName,
382
- relatedPropertyName,
383
- nstemplate,
384
- nametemplate,
385
- arguVars,
460
+ roleMetaNames
386
461
  )
462
+
387
463
  break;
388
-
389
464
  default:
390
465
  break;
391
466
  }
392
467
  });
393
468
  return meta;
394
- } else if(node){
395
- return visitedMap.get(node)
469
+ } else if (node) {
470
+ return visitedMap.get(node);
396
471
  } else {
397
472
  return null;
398
473
  }
@@ -402,21 +477,25 @@ export function autoTemplate(node) {
402
477
  return autoScript(stack);
403
478
  }
404
479
 
405
-
406
480
  /* 使用模板的代码 */
407
- /*
481
+ /*
408
482
  const view = this.view;
409
483
  const app = view.rootNode;
410
484
  applyTemplate(script, app, (rootNode) => {
411
485
  const names = app.getViewExistingNames();
412
- if(names.includes(rootNode.name)) {
486
+ if(names.includes(rootNode.name)) {
413
487
  const name = app.getViewUniqueName();
414
488
  rootNode.name = name;
415
489
  }
416
490
  app.addView(rootNode);
417
- })
491
+ })
418
492
  */
419
- export function applyTemplate(script, app, rootBindCallback) {
420
- const rebuild = eval(script);
421
- rebuild(app, getConceptConstructor, getConceptMeta, BaseNode, rootBindCallback);
422
- }
493
+
494
+ export function getRoles(script) {
495
+ const { exportRoles } = eval(script);
496
+ return exportRoles();
497
+ }
498
+ export function applyTemplate(script, app, rootBindCallback, roleCallback) {
499
+ const { execTemplate } = eval(script);
500
+ execTemplate(app, getConceptConstructor, getConceptMeta, BaseNode, rootBindCallback, roleCallback);
501
+ }