@lcap/nasl 3.8.2-beta.7 → 3.8.2-beta.8

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": "3.8.2-beta.7",
4
+ "version": "3.8.2-beta.8",
5
5
  "author": "Forrest <rainforest92@126.com>",
6
6
  "main": "./out",
7
7
  "license": "MIT",
@@ -1657,7 +1657,7 @@ export class BusinessComponent extends BaseNode {
1657
1657
  logics: [newLogic],
1658
1658
  },
1659
1659
  this,
1660
- 'events',
1660
+ 'bindEvents',
1661
1661
  );
1662
1662
  this.addBindEvent(event);
1663
1663
  } else {
@@ -368,7 +368,8 @@ export class CallInterface extends LogicItem {
368
368
  if (!this.calleeNamespace || !this.calleeName) throw new Error('调用接口为空');
369
369
  throw new Error(`${_name}下的${_interfaceName}接口未找到`);
370
370
  }
371
- let isSimpleBody = false; // 兼容body只有基本类型的
371
+ // 兼容 body 基本类型、List、Object
372
+ let bodyType: 'primitive' | 'List' = null;
372
373
  const _params = (_interface as Interface).params;
373
374
  const _queries = _params.filter((item) => item.in === 'query').map((item) => item.name);
374
375
  const _headers = _params.filter((item) => item.in === 'header').map((item) => item.name);
@@ -376,7 +377,9 @@ export class CallInterface extends LogicItem {
376
377
  .filter((item) => item.in === 'body')
377
378
  .map((item) => {
378
379
  if (item.typeAnnotation.typeKind === 'primitive') {
379
- isSimpleBody = true;
380
+ bodyType = 'primitive';
381
+ } else if (item.typeAnnotation.typeKind === 'generic' && item.typeAnnotation.typeName === 'List') {
382
+ bodyType = 'List';
380
383
  }
381
384
  return item.name;
382
385
  });
@@ -420,9 +423,13 @@ export class CallInterface extends LogicItem {
420
423
  code = setArgumentCode(completeArguments, _headers, code, true, false);
421
424
  code += `},\n`;
422
425
 
423
- if (isSimpleBody) {
426
+ if (bodyType === 'primitive') {
424
427
  code += `body: `;
425
428
  code = setArgumentCode(completeArguments, _body, code, false, false);
429
+ } else if (bodyType === 'List') {
430
+ code += `body: [`;
431
+ code = setArgumentCode(completeArguments, _body, code, false, true);
432
+ code += ']';
426
433
  } else {
427
434
  code += `body: {`;
428
435
  code = setArgumentCode(completeArguments, _body, code, false, true);
@@ -211,8 +211,8 @@ export class EnumItem extends BaseNode {
211
211
  toNaturalTS(state = createCompilerState()): string {
212
212
  let code = '';
213
213
 
214
- if (state.descriptionComment)
215
- code += createDescriptionComment(state, this, ['label']);
214
+ // if (state.descriptionComment)
215
+ // code += createDescriptionComment(state, this, ['label']);
216
216
  code += `'${this.value}' = '${this.label?.value}'`;
217
217
 
218
218
  return code;
@@ -1915,7 +1915,6 @@ export class ViewElement extends Annotatable {
1915
1915
  noNeedParams: true,
1916
1916
  callLogicNoIife: true,
1917
1917
  };
1918
- debugger;
1919
1918
  const value = yield* attr.expression.toEmbeddedTS(
1920
1919
  shiftState(state, code, attr.expression.concept === 'CallLogic' ? extraParams : {}),
1921
1920
  );
@@ -3186,6 +3185,7 @@ export class ViewElement extends Annotatable {
3186
3185
 
3187
3186
  result && parts.push(result);
3188
3187
  });
3188
+ let preAnnoParts:any = []
3189
3189
  const genDirectiveByAnno = (viewElement: ViewElement) => {
3190
3190
  if (viewElement?.applyAnnotations?.length > 0) {
3191
3191
  // todo: 根据注解生成自定义指令 v-annoName="context"
@@ -3203,22 +3203,12 @@ export class ViewElement extends Annotatable {
3203
3203
  };
3204
3204
  let argsList = aa.arguments.map((arg: any) => getExpressionValue(arg.expression));
3205
3205
  let annoArgs = {
3206
+ annotationName:aa.annotationName,
3206
3207
  argsList,
3207
3208
  dataRefList,
3208
3209
  };
3209
- // 所有参数序列化之后当字符串传进指令参数 (目前不支持<div v-demo="{ color: 'white', text: 'hello!' }"></div>
3210
- let expression = StringLiteral.from({
3211
- concept: 'StringLiteral',
3212
- kind: 'Expression',
3213
- name: '',
3214
- value: JSON.stringify(annoArgs),
3215
- });
3216
- let annoDirective = BindDirective.from({
3217
- name: aa.annotationName,
3218
- // arg:'arg',
3219
- expression,
3220
- });
3221
- return annoDirective;
3210
+ return annoArgs
3211
+
3222
3212
  });
3223
3213
  }
3224
3214
  };
@@ -3258,9 +3248,8 @@ export class ViewElement extends Annotatable {
3258
3248
  propName: attr?.expression.toUI()?.replace('current.item.', ''),
3259
3249
  };
3260
3250
  dataRefList.push(ref);
3261
- // 要考虑 多个元素 每个元素有多个注解的情况
3262
- let result = (genDirectiveByAnno(viewElement) as any)?.map((d: any) => d?.toVue());
3263
- result && result?.length > 0 && parts.push(...result);
3251
+ let result = (genDirectiveByAnno(viewElement) as any)
3252
+ result && result?.length > 0 && preAnnoParts.push(...result);
3264
3253
  }
3265
3254
  }
3266
3255
  }
@@ -3309,8 +3298,9 @@ export class ViewElement extends Annotatable {
3309
3298
  propName: entityPropName,
3310
3299
  };
3311
3300
  dataRefList.push(ref);
3312
- let result = (genDirectiveByAnno(viewElement) as any)?.map((d: any) => d?.toVue());
3313
- result && result?.length > 0 && parts.push(...result);
3301
+
3302
+ let result = (genDirectiveByAnno(viewElement) as any)
3303
+ result && result?.length > 0 && preAnnoParts.push(...result);
3314
3304
  }
3315
3305
  // typeName "Entity1"
3316
3306
  // typeNamespace "app.dataSources.defaultDS.entities"
@@ -3337,7 +3327,38 @@ export class ViewElement extends Annotatable {
3337
3327
  // 2 向上是线性布局 卡片 template gridView
3338
3328
  };
3339
3329
  getEntityDataRef(this);
3330
+ let annoMap:any = {}
3340
3331
 
3332
+ preAnnoParts?.map((annoArgs:any)=>{
3333
+ let annotationName =annoArgs.annotationName
3334
+ if(!annoMap[annotationName] ){
3335
+ annoMap[annotationName] =[]
3336
+ }
3337
+ annoMap[annotationName] = annoArgs
3338
+ })
3339
+ Object.keys(annoMap)?.map(key=>{
3340
+ let annoArgs =annoMap[key]
3341
+ let {
3342
+ annotationName,
3343
+ argsList,
3344
+ dataRefList,
3345
+ }= annoArgs;
3346
+ // 一个元素可以有多个指令; 其中一个指令可以从多处获取参数 这里就不能直接生成指令了 不然多个参数就变成了多个指令 实现同一个指令多个参数
3347
+ // 所有参数序列化之后当字符串传进指令参数 (目前不支持<div v-demo="{ color: 'white', text: 'hello!' }"></div>
3348
+ let expression = StringLiteral.from({
3349
+ concept: 'StringLiteral',
3350
+ kind: 'Expression',
3351
+ name: '',
3352
+ value: JSON.stringify(annoArgs),
3353
+ });
3354
+ let annoDirective = BindDirective.from({
3355
+ name: annotationName,
3356
+ // arg:'arg',
3357
+ expression,
3358
+ });
3359
+ let directString = annoDirective?.toVue()
3360
+ directString && parts.push(directString)
3361
+ })
3341
3362
  if (vIfs.length === 2) parts.push(`v-if="(${vIfs[0]}) && (${vIfs[1]})"`);
3342
3363
  else if (vIfs.length === 1) parts.push(`v-if="${vIfs[0]}"`);
3343
3364
 
@@ -191,7 +191,7 @@ export function getEnums(app: App, state: TranslatorState) {
191
191
  const namespace = 'app.enums';
192
192
  const data = [] as Snippet[];
193
193
  app.enums.forEach((enumeration) => {
194
- const temp = `${enumeration?.toNaturalTS({ ...state, needNamespace: true })}`;
194
+ const temp = `${enumeration?.toNaturalTS({ ...state, needNamespace: true, })}`;
195
195
  data.push({ description: enumeration?.description || enumeration?.name, code: temp });
196
196
  });
197
197
  return { namespace, enums: { namespace, data } };
@@ -201,7 +201,7 @@ export const getEnumsCode = (enums: any) => {
201
201
  let code = '';
202
202
  code += `declare namespace ${enums?.namespace} {\n`;
203
203
  enums?.data?.forEach((item: any) => {
204
- code += item?.description ? `/* ${item.description} */ \n` : '';
204
+ // code += item?.description ? `/* ${item.description} */ \n` : '';
205
205
  code += `${item.code}\n`;
206
206
  });
207
207
  code += `}\n`;
@@ -338,6 +338,7 @@ export const getModuleInterfacesCode = (interfaceDependencies: any, codeType: 'd
338
338
  if (requiredIndexes?.length && !requiredIndexes?.includes(interfaceIndex)) return;
339
339
  if (codeType === 'short') {
340
340
  const tempCode = item.code.replace(`${interfaceDependency?.logics.namespace}.`, '');
341
+ // code += `[${interfaceIndex}] \`${tempCode}\`\n`;
341
342
  code += `[${interfaceIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
342
343
  } else {
343
344
  code += item.codeWithDetail;
@@ -457,7 +458,8 @@ export const getConnectorsCode = (connections: any, codeType: 'detail' | 'short'
457
458
  if (codeType === 'short') {
458
459
  const namespace = item?.namespace || connection?.logics.namespace;
459
460
  const tempCode = item.code.replace(`${namespace}.`, '');
460
- code += `[${interfaceIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
461
+ code += `[${interfaceIndex}] \`${tempCode}\`\n`;
462
+ // code += `[${interfaceIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
461
463
  } else {
462
464
  code += item.codeWithDetail;
463
465
  }
@@ -527,7 +529,8 @@ export const getDependenciesCode = (dependencies: any, codeType: 'detail' | 'sho
527
529
  if (requiredIndexes?.length && !requiredIndexes?.includes(logicIndex)) return;
528
530
  if (codeType === 'short') {
529
531
  const tempCode = item.code.replace(`${dependency?.logics.namespace}.`, '');
530
- code += `[${logicIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
532
+ code += `[${logicIndex}] \`${tempCode}\`\n`;
533
+ // code += `[${logicIndex}] ${item.description ? `${item.description}: ` : ''}\`${tempCode}\`\n`;
531
534
  } else {
532
535
  code += item.codeWithDetail;
533
536
  }
@@ -632,7 +635,7 @@ export function getCurrentNodeContext(currentNode: BaseNode, focusedNodePath?: s
632
635
  function (state) {
633
636
  let code = '';
634
637
  code += `\n${indent(state.tabSize)}`;
635
-
638
+
636
639
  if (experimental) {
637
640
  code += this.elements[0].toNaturalTS(shiftState(state, code, { tabSize: state.tabSize + 1 }));
638
641
  } else {
@@ -80,7 +80,9 @@ export const getUnImportedModulesForLogic = (json: BaseNode, app: App, material:
80
80
  // 如果 连接器 不存在,则需要导入并初始化连接
81
81
  if (!connectorNode) {
82
82
  item.operator = 'importAndInit';
83
- item.version = material?.connectors?.find((node: any) => node.name === item.symbol)?.version;
83
+ const curDep = material?.connectors?.find((node: any) => node.name === item.symbol)
84
+ item.version = curDep?.version;
85
+ item.provider = curDep?.provider || '资产中心';
84
86
  needImportModule.needImportConnector = true;
85
87
  needImportModule.connectors.set(item.symbol, item);
86
88
  } else {
@@ -104,7 +106,9 @@ export const getUnImportedModulesForLogic = (json: BaseNode, app: App, material:
104
106
  item.category = 'library';
105
107
  const logicNode = app.dependencies?.find((node: any) => node.name === item.symbol);
106
108
  if (!logicNode) {
107
- item.version = material?.dependencies?.find((node: any) => node.name === item.symbol)?.version;
109
+ const curDep = material?.dependencies?.find((node: any) => node.name === item.symbol);
110
+ item.version = curDep?.version;
111
+ item.provider = curDep?.provider || '资产中心';
108
112
  needImportModule.library.set(item.symbol, item);
109
113
  }
110
114
  } else if (item.node.concept === 'ViewElement') {
@@ -116,7 +120,9 @@ export const getUnImportedModulesForLogic = (json: BaseNode, app: App, material:
116
120
  item.category = 'library';
117
121
  item.key = `${libraryName}-${name}`;
118
122
  item.symbol = libraryName;
119
- item.version = material?.dependencies?.find((node: any) => node.name === libraryName)?.version;
123
+ const curDep = material?.dependencies?.find((node: any) => node.name === item.symbol);
124
+ item.version = curDep?.version;
125
+ item.provider = curDep?.provider || '';
120
126
  needImportModule.extensionMaterials.set(name, item);
121
127
  }
122
128
  }
@@ -416,6 +416,7 @@ class NaslServer {
416
416
 
417
417
  // 处理一堆api.ts的类型
418
418
  const convertTsCode = (code: string) => {
419
+ code = code || '';
419
420
  code = code.replace(/nasl.core.Integer/g, 'nasl.core.Long')
420
421
  // 匹配union类型的正则
421
422
  const unionReg = /\s*['"].*['"](\s*\|\s*['"].*['"])+/g;