@lcap/nasl 1.0.0-alpha.8 → 1.0.0-alpha.9

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.
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.8",
4
+ "version": "1.0.0-alpha.9",
5
5
  "author": "Forrest <rainforest92@126.com>",
6
6
  "scripts": {
7
7
  "dev": "tsc -watch -p ./",
@@ -1,8 +1,8 @@
1
1
  // const { v4: uuidv4 } = require('uuid');
2
2
  const { uniq, omit } = require('lodash');
3
- const { BaseNode } = require('../../common/BaseNode');
3
+ const { BaseNode } = require('../../../out/common/BaseNode');
4
4
  const { tracking, TRACK_TYPE, IGNORE_PROPERTY } = require('./utils');
5
- const { getConceptConstructor, getConceptMeta } = require('../../decorators/index');
5
+ const { getConceptConstructor, getConceptMeta } = require('../../../out/decorators/index');
6
6
  let id = 0;
7
7
  class TemplateMeta {
8
8
  constructor(node) {
@@ -38,7 +38,10 @@ class TemplateMeta {
38
38
  addPlainBinds(propertyName, value) {
39
39
  // this.node.[propertyName] = value
40
40
  if (typeof value === 'string') {
41
- value = value.split(/\n/).map(c => `"${c}"`).join(" +\n");
41
+ value = value
42
+ .split(/\n/)
43
+ .map((c) => `"${c}"`)
44
+ .join(' +\n');
42
45
  }
43
46
  if (typeof value === 'object') {
44
47
  value = JSON.stringify(value);
@@ -2,8 +2,8 @@
2
2
  // BaseNode,
3
3
  // Module
4
4
  // } from '../../concepts';
5
- const { BaseNode } = require('../../concepts');
6
- const { getConceptMeta } = require('../../decorators/index');
5
+ const { BaseNode } = require('../../../out/concepts');
6
+ const { getConceptMeta } = require('../../../out/decorators/index');
7
7
 
8
8
  /*
9
9
  根据 namespace 字符串来获取 node
@@ -168,13 +168,10 @@ export class BaseNode extends EventEmitter {
168
168
  subConstructor(source?: Partial<BaseNode>) {
169
169
  const propertyMap = getConceptPropertyMap(this.constructor.name);
170
170
 
171
- const properties = Array.from(new Set([...Object.keys(this), ...Object.keys(source)])).filter((key) => {
172
- const property = propertyMap.get(key);
173
- return !!property;
174
- });
171
+ const properties = Array.from(new Set([...Object.keys(this), ...Object.keys(source)])).filter((key) => propertyMap.has(key));
175
172
  properties.forEach((key) => {
176
173
  const property = propertyMap.get(key);
177
- const sourceItem = (source as any)[key] || (this as any)[key];
174
+ const sourceItem = (source as any)[key] ?? (this as any)[key];
178
175
  const { objectRef: propertyObjectRef } = property;
179
176
  let objectRefCtor;
180
177
  try {
@@ -250,15 +247,7 @@ export class BaseNode extends EventEmitter {
250
247
  if (!$event.eventStop) {
251
248
  $event.eventList.push($event);
252
249
  // 页面逻辑需要冒泡到页面
253
- if ([
254
- 'Process',
255
- 'View',
256
- 'Interface',
257
- 'Entity',
258
- 'Structure',
259
- 'Enum',
260
- 'ConfigProperty',
261
- ].includes(this.concept) || this.concept === 'Logic' && this.parentNode?.concept !== 'View') {
250
+ if (['Process', 'View', 'Interface', 'Entity', 'Structure', 'Enum', 'ConfigProperty'].includes(this.concept) || (this.concept === 'Logic' && this.parentNode?.concept !== 'View')) {
262
251
  $event.eventStop = true;
263
252
  }
264
253
  }
@@ -458,13 +447,16 @@ export class BaseNode extends EventEmitter {
458
447
  * 获取当前的TsName
459
448
  */
460
449
  get tsName() {
461
- let tsName = this.name;
462
- if (/^\d/.test(tsName)) {
463
- tsName = '$' + tsName;
450
+ if (this.name) {
451
+ let tsName = this.name;
452
+ if (/^\d/.test(tsName)) {
453
+ tsName = '$' + tsName;
454
+ }
455
+ // 匹配所有特殊字符都转为_
456
+ tsName = tsName.replace(/\W/g, '_');
457
+ return tsName;
464
458
  }
465
- // 匹配所有特殊字符都转为_
466
- tsName = tsName.replace(/\W/g, '_');
467
- return tsName;
459
+ return '';
468
460
  }
469
461
  /**
470
462
  * 激活 JSON 内部实例
@@ -384,7 +384,7 @@ export class CallFunction extends LogicItem {
384
384
  }
385
385
 
386
386
  toUI(): string {
387
- let code = `$utils['${this.calleeName}']`;
387
+ let code = this.calleeName;
388
388
  code += '(';
389
389
  this.arguments.forEach((arg, index) => {
390
390
  code += arg.toUI();
@@ -432,19 +432,19 @@ export class CallFunction extends LogicItem {
432
432
  return argument;
433
433
  });
434
434
  let typeArguments = null;
435
- if(func.typeParams) {
435
+ if (func.typeParams) {
436
436
  typeArguments = func.typeParams.map(() => {
437
437
  const relationOptions = { parentNode: this, parentKey: 'typeArguments' };
438
438
  const typeArgu = new TypeAnnotation();
439
439
  Object.assign(typeArgu, relationOptions);
440
440
  return typeArgu;
441
- })
441
+ });
442
442
  }
443
443
  this.update({
444
444
  calleeNamespace,
445
445
  calleeName,
446
446
  arguments: params,
447
- typeArguments
447
+ typeArguments,
448
448
  });
449
449
  }
450
450
 
@@ -922,7 +922,7 @@ export class CallQueryComponent extends LogicItem {
922
922
  concept: 'TypeAnnotation',
923
923
  typeKind: 'reference',
924
924
  typeName: source.name,
925
- typeNamespace: `app.${this.app.name}.structures`,
925
+ typeNamespace: `app.structures`,
926
926
  }, this);
927
927
  this.update({
928
928
  typeAnnotation,
@@ -963,8 +963,8 @@ export class CallQueryComponent extends LogicItem {
963
963
  .map((entity) => ({
964
964
  concept: 'Entity',
965
965
  name: entity.name,
966
- children: entity.properties.map((property) =>
967
- new CompletionProperty({
966
+ children: entity.properties.map((property) => {
967
+ const completionProperty = new CompletionProperty({
968
968
  concept: 'CompletionProperty',
969
969
  name: property.name,
970
970
  value: `${entity.name}.${property.name}`,
@@ -975,12 +975,19 @@ export class CallQueryComponent extends LogicItem {
975
975
  entityAsName: entity.name,
976
976
  propertyName: property.name,
977
977
  }),
978
- })),
978
+ });
979
+ completionProperty.icon = 'property';
980
+ return completionProperty;
981
+ }),
979
982
  }));
980
983
  if (children.length === 0)
981
984
  return;
982
985
 
983
- return { name: '实体', children };
986
+ return {
987
+ name: '实体',
988
+ icon: 'category',
989
+ children,
990
+ };
984
991
  }
985
992
 
986
993
  getCompletionPropertyOfAggregateAsNames() {
@@ -331,6 +331,17 @@ export class EntityProperty extends BaseNode {
331
331
  // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
332
332
  // 自动生成的代码已结束。下面可以手动编写。
333
333
  //================================================================================
334
+ /**
335
+ * 设置是否必填
336
+ */
337
+ setSequence(sequence: string) {
338
+ const object = {
339
+ sequence,
340
+ };
341
+ this.update({
342
+ ...object,
343
+ });
344
+ }
334
345
  /**
335
346
  * 设置是否必填
336
347
  */
@@ -129,7 +129,7 @@ export class Identifier extends LogicItem {
129
129
  // 如果是nasl.util.Enum 的子集里的 Identifier > MemberExpression > Argument > callfunction
130
130
  // nasl.util.Enum 的 右侧是转成字符串的
131
131
  // 如果是identifier 而且枚举
132
- if (this.parentNode.parentNode.parentNode instanceof CallFunction) {
132
+ if (this.parentNode?.parentNode?.parentNode instanceof CallFunction) {
133
133
  const calleeNamespace = this.parentNode.parentNode.parentNode.calleeNamespace;
134
134
  const calleeName = this.parentNode.parentNode.parentNode.calleeName;
135
135
  if (calleeNamespace + '.' + calleeName === 'nasl.util.Enum') {
@@ -137,7 +137,6 @@ export class Identifier extends LogicItem {
137
137
  return str.includes('.enums.') ? str : str + '.toString()';
138
138
  }
139
139
  }
140
-
141
140
  return this.namespace ? this.namespace + '.' + this.name : this.name || '__IDENTIFIER__';
142
141
  }
143
142
 
@@ -2,6 +2,8 @@ import { dataTypesMap } from './basics/types';
2
2
  import { TranslatorState, shiftState, withSourceMap, indent, createCompilerState } from '../translator';
3
3
  import Entity from './Entity__';
4
4
  import Structure from './Structure__';
5
+ import { getNodeByNodeCallee } from '@nasl/automate/engine/utils';
6
+
5
7
 
6
8
  //================================================================================
7
9
  // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
@@ -274,27 +276,11 @@ export class InterfaceParam extends BaseNode {
274
276
 
275
277
  getSelectRef() {
276
278
  const { typeName, typeKind, typeNamespace } = this.typeAnnotation;
277
- const moduleNames = typeNamespace.split('.');
278
279
  let completionChildren;
279
280
  if (typeKind === 'reference') {
280
- let type: 'entities' | 'structures';
281
- if (typeNamespace.endsWith('entities')) {
282
- type = 'entities';
283
- } else if (typeNamespace.endsWith('structures')) {
284
- // 数据结构比较复杂,会有
285
- type = 'structures';
286
- }
287
- // 内置模块
288
- // if (typeNamespace.startsWith('nasl.')) {
289
- // } else {
290
- const data = this.app[type] as Array<Entity | Structure>;
291
- if (data) {
292
- const properties = data.find((item) => item.name === typeName)?.properties;
293
- completionChildren = properties;
294
- } else {
295
- completionChildren = undefined;
296
- }
297
- // }
281
+ const node = getNodeByNodeCallee(this.app, typeNamespace + '.' + typeName);
282
+ const properties = node.properties || [];
283
+ completionChildren = properties;
298
284
  } else {
299
285
  completionChildren = undefined;
300
286
  }
@@ -1298,7 +1298,16 @@ export class Logic extends BaseNode {
1298
1298
  // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
1299
1299
  // 自动生成的代码已结束。下面可以手动编写。
1300
1300
  //================================================================================
1301
-
1301
+ // 设置定时任务
1302
+ setCronAndTriggerType(cron: string, triggerType: string) {
1303
+ const object = {
1304
+ cron,
1305
+ triggerType,
1306
+ };
1307
+ this.update({
1308
+ ...object,
1309
+ });
1310
+ }
1302
1311
  findLogicItemByConcept(concept: string) {
1303
1312
  let result: any;
1304
1313
 
@@ -6,6 +6,7 @@ import Entity from './Entity__';
6
6
  import EntityProperty from './EntityProperty__';
7
7
  import Structure from './Structure__';
8
8
  import StructureProperty from './StructureProperty__';
9
+ import { getNodeByNodeCallee } from '@nasl/automate/engine/utils';
9
10
 
10
11
  //================================================================================
11
12
  // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
@@ -300,9 +301,9 @@ export class Param extends BaseNode {
300
301
  }
301
302
  const object = {
302
303
  typeAnnotation,
303
- // 处理下拉属性
304
- completionChildren: this.getSelectRef(),
305
304
  };
305
+ // 处理下拉属性
306
+ this.completionChildren = this.getSelectRef();
306
307
  return this.update({
307
308
  ...object,
308
309
  });
@@ -328,27 +329,11 @@ export class Param extends BaseNode {
328
329
 
329
330
  getSelectRef() {
330
331
  const { typeName, typeKind, typeNamespace } = this.typeAnnotation;
331
- const moduleNames = typeNamespace.split('.');
332
332
  let completionChildren;
333
333
  if (typeKind === 'reference') {
334
- let type: 'entities' | 'structures';
335
- if (typeNamespace.endsWith('entities')) {
336
- type = 'entities';
337
- } else if (typeNamespace.endsWith('structures')) {
338
- // 数据结构比较复杂,会有
339
- type = 'structures';
340
- }
341
- // 内置模块
342
- // if (typeNamespace.startsWith('nasl.')) {
343
- // } else {
344
- const data = this.app[type] as Array<Entity | Structure>;
345
- if (data) {
346
- const properties = data.find((item) => item.name === typeName)?.properties;
347
- completionChildren = properties;
348
- } else {
349
- completionChildren = undefined;
350
- }
351
- // }
334
+ const node = getNodeByNodeCallee(this.app, typeNamespace + '.' + typeName);
335
+ const properties = node.properties || [];
336
+ completionChildren = properties;
352
337
  } else {
353
338
  completionChildren = undefined;
354
339
  }
@@ -5,6 +5,7 @@ import Entity from './Entity__';
5
5
  import EntityProperty from './EntityProperty__';
6
6
  import Structure from './Structure__';
7
7
  import StructureProperty from './StructureProperty__';
8
+ import { getNodeByNodeCallee } from '@nasl/automate/engine/utils';
8
9
 
9
10
  //================================================================================
10
11
  // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
@@ -268,11 +269,10 @@ export class Return extends BaseNode {
268
269
  const relationOptions = { parentId: this.id, parentConcept: this.concept, parentNode: this };
269
270
  Object.assign(typeAnnotation, relationOptions);
270
271
  }
271
-
272
+ // 处理下拉属性
273
+ this.completionChildren = this.getSelectRef();
272
274
  const object = {
273
275
  typeAnnotation,
274
- // 处理下拉属性
275
- // completionChildren: this.getSelectRef(),
276
276
  };
277
277
 
278
278
  return this.update({
@@ -300,27 +300,11 @@ export class Return extends BaseNode {
300
300
 
301
301
  getSelectRef() {
302
302
  const { typeName, typeKind, typeNamespace } = this.typeAnnotation;
303
- const moduleNames = typeNamespace.split('.');
304
303
  let completionChildren;
305
304
  if (typeKind === 'reference') {
306
- let type: 'entities' | 'structures';
307
- if (typeNamespace.endsWith('entities')) {
308
- type = 'entities';
309
- } else if (typeNamespace.endsWith('structures')) {
310
- // 数据结构比较复杂,会有
311
- type = 'structures';
312
- }
313
- // 内置模块
314
- // if (typeNamespace.startsWith('nasl.')) {
315
- // } else {
316
- const data = this.app[type] as Array<Entity | Structure>;
317
- if (data) {
318
- const properties = data.find((item) => item.name === typeName)?.properties;
319
- completionChildren = properties;
320
- } else {
321
- completionChildren = undefined;
322
- }
323
- // }
305
+ const node = getNodeByNodeCallee(this.app, typeNamespace + '.' + typeName);
306
+ const properties = node.properties || [];
307
+ completionChildren = properties;
324
308
  } else {
325
309
  completionChildren = undefined;
326
310
  }
@@ -36,6 +36,12 @@ export class Role extends BaseNode {
36
36
  @property()
37
37
  uuid: string = uuidv4().replace(/-/g, '');
38
38
 
39
+ /**
40
+ * 创建时间
41
+ */
42
+ @property()
43
+ createdTime: string = undefined;
44
+
39
45
  /**
40
46
  * 角色描述
41
47
  */
@@ -2,6 +2,7 @@ import { dataTypesMap } from './basics/types';
2
2
  import { TranslatorState, shiftState, withSourceMap, indent, createCompilerState } from '../translator';
3
3
  import EntityProperty from './EntityProperty__';
4
4
  import Entity from './Entity__';
5
+ import { getNodeByNodeCallee } from '@nasl/automate/engine/utils';
5
6
 
6
7
  //================================================================================
7
8
  // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
@@ -295,27 +296,11 @@ export class StructureProperty extends BaseNode {
295
296
 
296
297
  getSelectRef() {
297
298
  const { typeName, typeKind, typeNamespace } = this.typeAnnotation;
298
- const moduleNames = typeNamespace.split('.');
299
299
  let completionChildren;
300
300
  if (typeKind === 'reference') {
301
- let type: 'entities' | 'structures';
302
- if (typeNamespace.endsWith('entities')) {
303
- type = 'entities';
304
- } else if (typeNamespace.endsWith('structures')) {
305
- // 数据结构比较复杂,会有
306
- type = 'structures';
307
- }
308
- // 内置模块
309
- // if (typeNamespace.startsWith('nasl.')) {
310
- // } else {
311
- const data = this.app[type] as Array<Entity | Structure>;
312
- if (data) {
313
- const properties = data.find((item) => item.name === typeName)?.properties;
314
- completionChildren = properties;
315
- } else {
316
- completionChildren = undefined;
317
- }
318
- // }
301
+ const node = getNodeByNodeCallee(this.app, typeNamespace + '.' + typeName);
302
+ const properties = node.properties || [];
303
+ completionChildren = properties;
319
304
  } else {
320
305
  completionChildren = undefined;
321
306
  }
@@ -323,7 +323,7 @@ export class TypeAnnotation extends BaseNode {
323
323
  toEmbeddedTS(state?: TranslatorState): string {
324
324
  if (this.typeKind === 'primitive' || this.typeKind === 'reference') {
325
325
  if (this.typeKind === 'reference' && this.typeNamespace.endsWith('enums')) {
326
- return `ReturnType<typeof ${this.tsCalleeNamespace}.${this.typeName}.toList>`;
326
+ return `${this.tsCalleeNamespace}.${this.typeName}`;
327
327
  }
328
328
  return `${this.tsCalleeNamespace}.${this.typeName}`;
329
329
  } else if (this.typeKind === 'generic') {
@@ -3,6 +3,8 @@ import { TranslatorState, shiftState, withSourceMap } from '../translator';
3
3
  import Entity from './Entity__';
4
4
  import Structure from './Structure__';
5
5
  import { ElementToVueOptions } from './ViewElement__';
6
+ import { getNodeByNodeCallee } from '@nasl/automate/engine/utils';
7
+ import EntityProperty from './EntityProperty__';
6
8
  //================================================================================
7
9
  // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
8
10
  // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
@@ -211,6 +213,11 @@ export class Variable extends BaseNode {
211
213
  // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
212
214
  // 自动生成的代码已结束。下面可以手动编写。
213
215
  //================================================================================
216
+ /**
217
+ * 自动补全的字段列表
218
+ */
219
+ completionChildren: Array<EntityProperty | StructureProperty> = undefined;
220
+
214
221
  toVue(options?: ElementToVueOptions): string {
215
222
  return this.name;
216
223
  }
@@ -257,6 +264,8 @@ export class Variable extends BaseNode {
257
264
  const relationOptions = { parentId: this.id, parentConcept: this.concept, parentNode: this };
258
265
  Object.assign(typeAnnotation, relationOptions);
259
266
  }
267
+ // 处理下拉属性
268
+ this.completionChildren = this.getSelectRef();
260
269
  const object = {
261
270
  typeAnnotation,
262
271
  };
@@ -286,27 +295,11 @@ export class Variable extends BaseNode {
286
295
 
287
296
  getSelectRef() {
288
297
  const { typeName, typeKind, typeNamespace } = this.typeAnnotation;
289
- const moduleNames = typeNamespace.split('.');
290
298
  let completionChildren;
291
299
  if (typeKind === 'reference') {
292
- let type: 'entities' | 'structures';
293
- if (typeNamespace.endsWith('entities')) {
294
- type = 'entities';
295
- } else if (typeNamespace.endsWith('structures')) {
296
- // 数据结构比较复杂,会有
297
- type = 'structures';
298
- }
299
- // 内置模块
300
- // if (typeNamespace.startsWith('nasl.')) {
301
- // } else {
302
- const data = this.app[type] as Array<Entity | Structure>;
303
- if (data) {
304
- const properties = data.find((item) => item.name === typeName)?.properties;
305
- completionChildren = properties;
306
- } else {
307
- completionChildren = undefined;
308
- }
309
- // }
300
+ const node = getNodeByNodeCallee(this.app, typeNamespace + '.' + typeName);
301
+ const properties = node.properties || [];
302
+ completionChildren = properties;
310
303
  } else {
311
304
  completionChildren = undefined;
312
305
  }
@@ -227,6 +227,8 @@ export class ViewElement extends BaseNode {
227
227
  super.subConstructor(source);
228
228
  }
229
229
 
230
+
231
+
230
232
  /**
231
233
  * 从父级删除该节点
232
234
  * @internal
@@ -263,7 +265,7 @@ export class ViewElement extends BaseNode {
263
265
  });
264
266
  }
265
267
 
266
- getBindAttributeExistingNames(excludedList: Array<BindAttribute> = []) {
268
+ getBindAttributeExistingNames(excludedList: Array<BindAttribute> = []) {
267
269
  const excludedSet = new Set(excludedList);
268
270
  return (this.bindAttrs || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
269
271
  }
@@ -272,24 +274,24 @@ export class ViewElement extends BaseNode {
272
274
  }
273
275
 
274
276
  /**
275
- * 插入元素绑定属性
276
- * @internal
277
- * @param name 元素绑定属性名称,如果不填会自动生成一个唯一名称
278
- */
277
+ * 插入元素绑定属性
278
+ * @internal
279
+ * @param name 元素绑定属性名称,如果不填会自动生成一个唯一名称
280
+ */
279
281
  _insertBindAttributeAt(name: string, index: number): BindAttribute;
280
282
 
281
283
  /**
282
- * 插入元素绑定属性
283
- * @internal
284
- * @param bindAttributeOptions 元素绑定属性参数
285
- */
284
+ * 插入元素绑定属性
285
+ * @internal
286
+ * @param bindAttributeOptions 元素绑定属性参数
287
+ */
286
288
  _insertBindAttributeAt(bindAttributeOptions: Partial<BindAttribute>, index: number): BindAttribute;
287
289
 
288
290
  /**
289
- * 插入元素绑定属性
290
- * @internal
291
- * @param bindAttribute 已有的元素绑定属性实例
292
- */
291
+ * 插入元素绑定属性
292
+ * @internal
293
+ * @param bindAttribute 已有的元素绑定属性实例
294
+ */
293
295
  _insertBindAttributeAt(bindAttribute: BindAttribute, index: number): BindAttribute;
294
296
 
295
297
  _insertBindAttributeAt(options: string | Partial<BindAttribute> | BindAttribute, index: number) {
@@ -404,6 +406,7 @@ export class ViewElement extends BaseNode {
404
406
  return node;
405
407
  }
406
408
 
409
+
407
410
  getBindEventExistingNames(excludedList: Array<BindEvent> = []) {
408
411
  const excludedSet = new Set(excludedList);
409
412
  return (this.bindEvents || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
@@ -413,24 +416,24 @@ export class ViewElement extends BaseNode {
413
416
  }
414
417
 
415
418
  /**
416
- * 插入元素绑定事件
417
- * @internal
418
- * @param name 元素绑定事件名称,如果不填会自动生成一个唯一名称
419
- */
419
+ * 插入元素绑定事件
420
+ * @internal
421
+ * @param name 元素绑定事件名称,如果不填会自动生成一个唯一名称
422
+ */
420
423
  _insertBindEventAt(name: string, index: number): BindEvent;
421
424
 
422
425
  /**
423
- * 插入元素绑定事件
424
- * @internal
425
- * @param bindEventOptions 元素绑定事件参数
426
- */
426
+ * 插入元素绑定事件
427
+ * @internal
428
+ * @param bindEventOptions 元素绑定事件参数
429
+ */
427
430
  _insertBindEventAt(bindEventOptions: Partial<BindEvent>, index: number): BindEvent;
428
431
 
429
432
  /**
430
- * 插入元素绑定事件
431
- * @internal
432
- * @param bindEvent 已有的元素绑定事件实例
433
- */
433
+ * 插入元素绑定事件
434
+ * @internal
435
+ * @param bindEvent 已有的元素绑定事件实例
436
+ */
434
437
  _insertBindEventAt(bindEvent: BindEvent, index: number): BindEvent;
435
438
 
436
439
  _insertBindEventAt(options: string | Partial<BindEvent> | BindEvent, index: number) {
@@ -545,6 +548,7 @@ export class ViewElement extends BaseNode {
545
548
  return node;
546
549
  }
547
550
 
551
+
548
552
  getBindDirectiveExistingNames(excludedList: Array<BindDirective> = []) {
549
553
  const excludedSet = new Set(excludedList);
550
554
  return (this.bindDirectives || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
@@ -554,24 +558,24 @@ export class ViewElement extends BaseNode {
554
558
  }
555
559
 
556
560
  /**
557
- * 插入元素指令
558
- * @internal
559
- * @param name 元素指令名称,如果不填会自动生成一个唯一名称
560
- */
561
+ * 插入元素指令
562
+ * @internal
563
+ * @param name 元素指令名称,如果不填会自动生成一个唯一名称
564
+ */
561
565
  _insertBindDirectiveAt(name: string, index: number): BindDirective;
562
566
 
563
567
  /**
564
- * 插入元素指令
565
- * @internal
566
- * @param bindDirectiveOptions 元素指令参数
567
- */
568
+ * 插入元素指令
569
+ * @internal
570
+ * @param bindDirectiveOptions 元素指令参数
571
+ */
568
572
  _insertBindDirectiveAt(bindDirectiveOptions: Partial<BindDirective>, index: number): BindDirective;
569
573
 
570
574
  /**
571
- * 插入元素指令
572
- * @internal
573
- * @param bindDirective 已有的元素指令实例
574
- */
575
+ * 插入元素指令
576
+ * @internal
577
+ * @param bindDirective 已有的元素指令实例
578
+ */
575
579
  _insertBindDirectiveAt(bindDirective: BindDirective, index: number): BindDirective;
576
580
 
577
581
  _insertBindDirectiveAt(options: string | Partial<BindDirective> | BindDirective, index: number) {
@@ -686,25 +690,30 @@ export class ViewElement extends BaseNode {
686
690
  return node;
687
691
  }
688
692
 
693
+
694
+
695
+
696
+
697
+
689
698
  /**
690
- * 插入页面元素
691
- * @internal
692
- * @param name 页面元素名称,如果不填会自动生成一个唯一名称
693
- */
699
+ * 插入页面元素
700
+ * @internal
701
+ * @param name 页面元素名称,如果不填会自动生成一个唯一名称
702
+ */
694
703
  _insertViewElementAt(name: string, index: number): ViewElement;
695
704
 
696
705
  /**
697
- * 插入页面元素
698
- * @internal
699
- * @param viewElementOptions 页面元素参数
700
- */
706
+ * 插入页面元素
707
+ * @internal
708
+ * @param viewElementOptions 页面元素参数
709
+ */
701
710
  _insertViewElementAt(viewElementOptions: Partial<ViewElement>, index: number): ViewElement;
702
711
 
703
712
  /**
704
- * 插入页面元素
705
- * @internal
706
- * @param viewElement 已有的页面元素实例
707
- */
713
+ * 插入页面元素
714
+ * @internal
715
+ * @param viewElement 已有的页面元素实例
716
+ */
708
717
  _insertViewElementAt(viewElement: ViewElement, index: number): ViewElement;
709
718
 
710
719
  _insertViewElementAt(options: string | Partial<ViewElement> | ViewElement, index: number) {
@@ -819,10 +828,13 @@ export class ViewElement extends BaseNode {
819
828
  return node;
820
829
  }
821
830
 
831
+
832
+
833
+
822
834
  /**
823
- * 删除元素绑定属性
824
- * @param name 元素绑定属性名称
825
- */
835
+ * 删除元素绑定属性
836
+ * @param name 元素绑定属性名称
837
+ */
826
838
  removeBindAttribute(name: string): void;
827
839
 
828
840
  /**
@@ -867,10 +879,12 @@ export class ViewElement extends BaseNode {
867
879
  return params;
868
880
  }
869
881
 
882
+
883
+
870
884
  /**
871
- * 删除元素绑定事件
872
- * @param name 元素绑定事件名称
873
- */
885
+ * 删除元素绑定事件
886
+ * @param name 元素绑定事件名称
887
+ */
874
888
  removeBindEvent(name: string): void;
875
889
 
876
890
  /**
@@ -915,10 +929,12 @@ export class ViewElement extends BaseNode {
915
929
  return params;
916
930
  }
917
931
 
932
+
933
+
918
934
  /**
919
- * 删除元素指令
920
- * @param name 元素指令名称
921
- */
935
+ * 删除元素指令
936
+ * @param name 元素指令名称
937
+ */
922
938
  removeBindDirective(name: string): void;
923
939
 
924
940
  /**
@@ -963,10 +979,12 @@ export class ViewElement extends BaseNode {
963
979
  return params;
964
980
  }
965
981
 
982
+
983
+
966
984
  /**
967
- * 删除页面元素
968
- * @param name 页面元素名称
969
- */
985
+ * 删除页面元素
986
+ * @param name 页面元素名称
987
+ */
970
988
  removeViewElement(name: string): void;
971
989
 
972
990
  /**
@@ -1046,33 +1064,6 @@ export class ViewElement extends BaseNode {
1046
1064
  return this.bindAttrs.find((bindAttr) => bindAttr.name === name);
1047
1065
  }
1048
1066
 
1049
- /**
1050
- * 角色
1051
- */
1052
- @property()
1053
- roles: Array<{
1054
- namespace: string;
1055
- name: string;
1056
- }> = [];
1057
-
1058
- toggleRole(role: Role) {
1059
- const index = this.roles.findIndex((roleItem) => roleItem.name === role.name);
1060
- const roles = [...this.roles];
1061
- if (index !== -1) {
1062
- roles.splice(index, 1);
1063
- } else {
1064
- roles.push({
1065
- namespace: role.getNamespace(),
1066
- name: role.name,
1067
- });
1068
- }
1069
- const object = {
1070
- roles,
1071
- };
1072
- this.update({
1073
- ...object,
1074
- });
1075
- }
1076
1067
  toHump(name: string): string {
1077
1068
  return name.replace(/\-(\w)/g, (all, letter) => letter.toUpperCase());
1078
1069
  }
@@ -1116,7 +1107,7 @@ export class ViewElement extends BaseNode {
1116
1107
  let parentNode = this.parentNode;
1117
1108
  let haveScopeFlag = false;
1118
1109
  while (!haveScopeFlag && parentNode.concept !== 'View') {
1119
- if (this.haveScope((parentNode) as ViewElement)) {
1110
+ if (this.haveScope(parentNode as ViewElement)) {
1120
1111
  // type d = nasl.ui.GetItemTypeFromDataSource<typeof listStructure>['tableRelation']
1121
1112
  const tsArr = expressionTs.split('.');
1122
1113
  const parentbindAttrs = (parentNode as ViewElement).bindAttrs;
@@ -1203,25 +1194,27 @@ export class ViewElement extends BaseNode {
1203
1194
  if (Array.isArray(this.children)) {
1204
1195
  code += indent(state.tabSize + 1);
1205
1196
 
1206
- let levelIndex = parentLevel || 0;
1207
- if (this.haveScope(this)) {
1208
- code += `slotDefault: (scope${levelIndex || ''})=> [\n`;
1209
- levelIndex++;
1210
- } else {
1211
- code += `slotDefault: ()=> [\n`;
1212
- }
1213
1197
  if (Array.isArray(this.bindAttrs)) {
1214
- code += indent(state.tabSize + 2) + `() => [\n`;
1198
+ code += `bindAttr: () => [\n`;
1215
1199
  this.bindAttrs.forEach((attr) => {
1216
1200
  if (attr.expression) {
1217
1201
  code
1218
1202
  += attr.expression.toEmbeddedTS(shiftState(state, code, {
1219
- tabSize: state.tabSize + 3,
1203
+ tabSize: state.tabSize + 2,
1220
1204
  })) + ',\n';
1221
1205
  }
1222
1206
  });
1223
1207
  code += indent(state.tabSize + 2) + '],\n';
1224
1208
  }
1209
+
1210
+ let levelIndex = parentLevel || 0;
1211
+ if (this.haveScope(this)) {
1212
+ code += `slotDefault: (scope)=> [\n`;
1213
+ levelIndex++;
1214
+ } else {
1215
+ code += `slotDefault: ()=> [\n`;
1216
+ }
1217
+
1225
1218
  this.children.forEach((element) => {
1226
1219
  code += element.toEmbeddedTS(shiftState(state, code, {
1227
1220
  tabSize: state.tabSize + 2,
@@ -1590,7 +1583,7 @@ export class ViewElement extends BaseNode {
1590
1583
  if (apiOfAttr && !apiOfAttr.type.includes('string'))
1591
1584
  return '';
1592
1585
  }
1593
- return `${name}="{{ ${value.replace(/"/g, "'")} }}"`;
1586
+ return `${name}="{{ ${value.replace(/"/g, "'").replace(/\$utils\['(.+?)'\]/g, '$1')} }}"`;
1594
1587
  });
1595
1588
  else
1596
1589
  return defaultResult;
@@ -1685,7 +1678,7 @@ export class ViewElement extends BaseNode {
1685
1678
  //================================================================================
1686
1679
  }
1687
1680
 
1688
- classMap.ViewElement = ViewElement;
1681
+ classMap['ViewElement'] = ViewElement;
1689
1682
  export default ViewElement;
1690
1683
  //================================================================================
1691
1684
  // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
@@ -234,6 +234,8 @@ export class View extends BaseNode {
234
234
  });
235
235
  }
236
236
 
237
+
238
+
237
239
  /**
238
240
  * 插入页面元素
239
241
  * @internal
@@ -367,6 +369,7 @@ export class View extends BaseNode {
367
369
  return node;
368
370
  }
369
371
 
372
+
370
373
  getParamExistingNames(excludedList: Array<Param> = []) {
371
374
  const excludedSet = new Set(excludedList);
372
375
  return (this.params || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
@@ -508,6 +511,7 @@ export class View extends BaseNode {
508
511
  return node;
509
512
  }
510
513
 
514
+
511
515
  getVariableExistingNames(excludedList: Array<Variable> = []) {
512
516
  const excludedSet = new Set(excludedList);
513
517
  return (this.variables || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
@@ -649,6 +653,7 @@ export class View extends BaseNode {
649
653
  return node;
650
654
  }
651
655
 
656
+
652
657
  getLogicExistingNames(excludedList: Array<Logic> = []) {
653
658
  const excludedSet = new Set(excludedList);
654
659
  return (this.logics || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
@@ -790,6 +795,7 @@ export class View extends BaseNode {
790
795
  return node;
791
796
  }
792
797
 
798
+
793
799
  getBindEventExistingNames(excludedList: Array<BindEvent> = []) {
794
800
  const excludedSet = new Set(excludedList);
795
801
  return (this.bindEvents || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
@@ -931,6 +937,9 @@ export class View extends BaseNode {
931
937
  return node;
932
938
  }
933
939
 
940
+
941
+
942
+
934
943
  getViewExistingNames(excludedList: Array<View> = []) {
935
944
  const excludedSet = new Set(excludedList);
936
945
  return (this.children || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
@@ -1072,6 +1081,9 @@ export class View extends BaseNode {
1072
1081
  return node;
1073
1082
  }
1074
1083
 
1084
+
1085
+
1086
+
1075
1087
  /**
1076
1088
  * 删除页面元素
1077
1089
  * @param name 页面元素名称
@@ -1120,6 +1132,8 @@ export class View extends BaseNode {
1120
1132
  return params;
1121
1133
  }
1122
1134
 
1135
+
1136
+
1123
1137
  /**
1124
1138
  * 删除输入参数
1125
1139
  * @param name 输入参数名称
@@ -1168,6 +1182,8 @@ export class View extends BaseNode {
1168
1182
  return params;
1169
1183
  }
1170
1184
 
1185
+
1186
+
1171
1187
  /**
1172
1188
  * 删除局部变量
1173
1189
  * @param name 局部变量名称
@@ -1216,6 +1232,8 @@ export class View extends BaseNode {
1216
1232
  return params;
1217
1233
  }
1218
1234
 
1235
+
1236
+
1219
1237
  /**
1220
1238
  * 删除逻辑
1221
1239
  * @param name 逻辑名称
@@ -1264,6 +1282,8 @@ export class View extends BaseNode {
1264
1282
  return params;
1265
1283
  }
1266
1284
 
1285
+
1286
+
1267
1287
  /**
1268
1288
  * 删除元素绑定事件
1269
1289
  * @param name 元素绑定事件名称
@@ -1312,6 +1332,8 @@ export class View extends BaseNode {
1312
1332
  return params;
1313
1333
  }
1314
1334
 
1335
+
1336
+
1315
1337
  /**
1316
1338
  * 删除页面
1317
1339
  * @param name 页面名称
@@ -1521,36 +1543,6 @@ export class View extends BaseNode {
1521
1543
  return [...this.params, ...this.variables].filter((item) => !excludedSet.has(item)).map((item) => item.name);
1522
1544
  }
1523
1545
 
1524
- /**
1525
- * 角色
1526
- */
1527
- @property()
1528
- roles: Array<{
1529
- namespace: string;
1530
- name: string;
1531
- }> = [];
1532
-
1533
- toggleRole(role: Role) {
1534
- const index = this.roles.findIndex((roleItem) => roleItem.name === role.name);
1535
- const roles = [...this.roles];
1536
- if (index !== -1) {
1537
- roles.splice(index, 1);
1538
- this.roles = roles;
1539
- } else {
1540
- roles.push({
1541
- namespace: role.getNamespace(),
1542
- name: role.name,
1543
- });
1544
- }
1545
- const object = {
1546
- roles,
1547
- };
1548
-
1549
- this.update({
1550
- ...object,
1551
- });
1552
- }
1553
-
1554
1546
  /**
1555
1547
  * 生成 Vue 中需要的 JS 代码
1556
1548
  * @TODO 这一版先做成 componentOptions 式的,后面再美化
@@ -1638,7 +1630,6 @@ export class View extends BaseNode {
1638
1630
  throw new Error('无法获取命名空间,请设置 parentNode!');
1639
1631
  }
1640
1632
 
1641
-
1642
1633
  // 获取当前element,铺平
1643
1634
  elementsMethods(elements: Array<ViewElement>, allMethods: Array<ViewElement>) {
1644
1635
  if (elements) {
@@ -1857,7 +1848,7 @@ export class View extends BaseNode {
1857
1848
  //================================================================================
1858
1849
  }
1859
1850
 
1860
- classMap.View = View;
1851
+ classMap['View'] = View;
1861
1852
  export default View;
1862
1853
  //================================================================================
1863
1854
  // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
@@ -6,6 +6,7 @@ export const primitiveTypeList: Array<TypeAnnotation> = [
6
6
  TypeAnnotation.createPrimitive('Long', { text: 'Long 长整数' }),
7
7
  TypeAnnotation.createPrimitive('Double', { text: 'Double 小数' }),
8
8
  TypeAnnotation.createPrimitive('String', { text: 'String 字符串' }),
9
+ TypeAnnotation.createPrimitive('Text', { text: 'Text 长文本' }),
9
10
  TypeAnnotation.createPrimitive('Binary', { text: 'Binary 二进制流' }),
10
11
  TypeAnnotation.createPrimitive('Date', { text: 'Date 日期' }),
11
12
  TypeAnnotation.createPrimitive('Time', { text: 'Time 时间' }),
@@ -53,18 +53,21 @@ export default function formatUiTs(allComponent: any) {
53
53
  export class lRoot<T> extends VueComponent{
54
54
  constructor(
55
55
  options?: {
56
+ bindAttr?: () => Array<any>,
56
57
  slotDefault?: ()=> Array<any>,
57
58
  }){super()}
58
59
  }
59
60
  export class div<T> extends VueComponent {
60
61
  constructor(
61
62
  options?: {
63
+ bindAttr?: () => Array<any>,
62
64
  slotDefault?: ()=> Array<any>,
63
65
  }){super()}
64
66
  }
65
67
  export class template<T> extends VueComponent {
66
68
  constructor(
67
69
  options?: {
70
+ bindAttr?: () => Array<any>,
68
71
  slotDefault?: ()=> Array<any>,
69
72
  }){super()}
70
73
  }
@@ -79,7 +82,8 @@ export default function formatUiTs(allComponent: any) {
79
82
  value += `export class ${componentName}<T> extends VueComponent{\n
80
83
  constructor(\n
81
84
  options?: {\n
82
- [propname: string]: any,\n`;
85
+ [propname: string]: any,
86
+ bindAttr?: () => Array<any>,\n`;
83
87
  // 生成slot
84
88
  if (Object.prototype.toString.call(item.slots) === '[object Array]') {
85
89
  let hasDefault = false;
@@ -1,4 +1,4 @@
1
- import { BaseNode, CompletionProperty, App, Identifier, MemberExpression, Enum, NullLiteral, BooleanLiteral, Param, BindAttribute } from '..';
1
+ import { BaseNode, CompletionProperty, App, Identifier, MemberExpression, Enum, NullLiteral, BooleanLiteral, Param, BindAttribute, LogicItem } from '..';
2
2
  import naslServer from './naslServer';
3
3
 
4
4
  interface variableItem {
@@ -109,7 +109,66 @@ function formatLiterals() {
109
109
  }
110
110
 
111
111
  function formatGlobalVariable() {
112
- return [];
112
+ const newList = [];
113
+ const globalVariable = {
114
+ name: 'userInfo',
115
+ children: [
116
+ { name: 'Status' },
117
+ { name: 'UserInfoExtend',
118
+ children: [
119
+ { name: 'Company' },
120
+ { name: 'JobLevel' },
121
+ { name: 'JobNum' },
122
+ { name: 'RealName' },
123
+ { name: 'JobYear' },
124
+ ],
125
+ },
126
+ { name: 'UserName' },
127
+ { name: 'Email' },
128
+ { name: 'UserId' },
129
+ { name: 'Phone' },
130
+ { name: 'CreateTime' },
131
+ { name: 'UpdateTime' },
132
+ { name: 'LoginCount' },
133
+ { name: 'Source' },
134
+ ],
135
+ };
136
+ const userInfoIdentifier = new Identifier({
137
+ name: 'userInfo',
138
+ namespace: 'nasl.brower',
139
+ });
140
+ const userCompletionProperty = new CompletionProperty({
141
+ name: 'userInfo',
142
+ expression: userInfoIdentifier,
143
+ children: [],
144
+ });
145
+ userCompletionProperty.icon = 'variable';
146
+ newList.push(userCompletionProperty);
147
+ globalVariable.children.forEach((item) => {
148
+ const expression = new MemberExpression({
149
+ object: userInfoIdentifier,
150
+ property: new Identifier({ name: item.name }),
151
+ });
152
+ (item as any).expression = expression;
153
+ const completionProperty = new CompletionProperty(item as any);
154
+ completionProperty.icon = 'literal';
155
+ if (item.children) {
156
+ const children: LogicItem[] = [];
157
+ item.children.forEach((child) => {
158
+ const childExpression = new MemberExpression({
159
+ object: expression,
160
+ property: new Identifier({ name: child.name }),
161
+ });
162
+ (child as any).expression = childExpression;
163
+ const childProperty = new CompletionProperty(child as any);
164
+ childProperty.icon = 'literal';
165
+ children.push(childProperty as any);
166
+ });
167
+ completionProperty.children = children;
168
+ }
169
+ userCompletionProperty.children.push(completionProperty as any);
170
+ });
171
+ return newList;
113
172
  }
114
173
 
115
174
 
@@ -269,14 +269,14 @@ const naslServer = {
269
269
  return this.messager.requestCommand('updateFiles', args);
270
270
  },
271
271
  _debugInFileStorage(node: BaseNode, openFiles: Array<tsProtocol.OpenRequestArgs>) {
272
- let app = node;
273
- if (node.concept !== 'App') {
274
- app = (node as any).rootNode || (node as any).app;
275
- }
276
- return Promise.all(openFiles.map(async (file) => {
277
- const res = await axios.post('/api/App/debugEmbedded?id=' + app.id, file);
278
- return res.data;
279
- }));
272
+ // let app = node;
273
+ // if (node.concept !== 'App') {
274
+ // app = (node as any).rootNode || (node as any).app;
275
+ // }
276
+ // return Promise.all(openFiles.map(async (file) => {
277
+ // const res = await axios.post('/api/App/debugEmbedded?id=' + app.id, file);
278
+ // return res.data;
279
+ // }));
280
280
  },
281
281
  open() {
282
282
  return this.messager.requestCommand('open');
@@ -26,6 +26,9 @@ async function doAction(app: any, actionItem: any) {
26
26
  } else {
27
27
  hasBackEnd = true;
28
28
  }
29
+ if (emitTarget.concept === 'CallLogic') {
30
+ hasBackEnd = true;
31
+ }
29
32
  event.eventList.forEach(({
30
33
  action,
31
34
  path,
@@ -108,7 +111,7 @@ async function doAction(app: any, actionItem: any) {
108
111
  }
109
112
 
110
113
  function handleApp(app: any) {
111
- app._isCollecting = false;
114
+ app._isCollectingCount = 0;
112
115
  app._collectingList = [];
113
116
  app._historyList = [];
114
117
  app._historyIndex = 0;
@@ -126,7 +129,7 @@ function handleApp(app: any) {
126
129
  * 开启收集
127
130
  */
128
131
  app.on('collect:start', (event: any) => {
129
- app._isCollecting = true;
132
+ app._isCollectingCount++;
130
133
  app._actionMsg = event?.actionMsg;
131
134
  app._action = event?.action;
132
135
  });
@@ -145,7 +148,7 @@ function handleApp(app: any) {
145
148
  action: app._action,
146
149
  });
147
150
  }
148
- app._isCollecting = false;
151
+ app._isCollectingCount--;
149
152
  app._collectingList = [];
150
153
  app._actionMsg = '';
151
154
  app._action = '';
@@ -156,7 +159,7 @@ function handleApp(app: any) {
156
159
  */
157
160
  app.on('storage', (event: any) => {
158
161
  // 是否正在收集
159
- if (!app._isCollecting) {
162
+ if (app._isCollectingCount === 0) {
160
163
  embeddedTSEmitter.emit('change', {
161
164
  value: [event],
162
165
  });
@@ -234,6 +237,7 @@ export async function loadApp(appId?: string) {
234
237
  }
235
238
  config.scope = app.scope;
236
239
  handleApp(app);
240
+ (app as any)._isCollectingCount = 0;
237
241
  return app as App;
238
242
  }
239
243