@lcap/nasl 3.7.0-beta.8 → 3.7.1-alpha.1

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 (45) hide show
  1. package/out/concepts/ConnectorTrigger__.d.ts +0 -18
  2. package/out/concepts/ConnectorTrigger__.js +0 -145
  3. package/out/concepts/ConnectorTrigger__.js.map +1 -1
  4. package/out/concepts/Connector__.d.ts +1 -1
  5. package/out/concepts/Connector__.js +1 -4
  6. package/out/concepts/Connector__.js.map +1 -1
  7. package/out/concepts/TriggerLauncher__.js +2 -2
  8. package/out/concepts/TriggerLauncher__.js.map +1 -1
  9. package/out/config.d.ts +0 -5
  10. package/out/config.js +0 -1
  11. package/out/config.js.map +1 -1
  12. package/out/generator/genBundleFiles.d.ts +0 -3
  13. package/out/generator/genBundleFiles.js +0 -19
  14. package/out/generator/genBundleFiles.js.map +1 -1
  15. package/out/generator/release-body/body.d.ts +1 -7
  16. package/out/generator/release-body/body.js +1 -66
  17. package/out/generator/release-body/body.js.map +1 -1
  18. package/out/generator/release-body/data.js +1 -10
  19. package/out/generator/release-body/data.js.map +1 -1
  20. package/out/generator/release-body/internal.d.ts +0 -9
  21. package/out/generator/release-body/internal.js.map +1 -1
  22. package/out/generator/release-body/utils.d.ts +2 -9
  23. package/out/generator/release-body/utils.js +5 -30
  24. package/out/generator/release-body/utils.js.map +1 -1
  25. package/out/natural/index.d.ts +1 -0
  26. package/out/natural/index.js +1 -0
  27. package/out/natural/index.js.map +1 -1
  28. package/out/natural/transformTS2UI.d.ts +1 -0
  29. package/out/natural/transformTS2UI.js +1173 -0
  30. package/out/natural/transformTS2UI.js.map +1 -0
  31. package/out/server/naslServer.js +1 -2
  32. package/out/server/naslServer.js.map +1 -1
  33. package/package.json +1 -1
  34. package/src/concepts/ConnectorTrigger__.ts +0 -160
  35. package/src/concepts/Connector__.ts +1 -4
  36. package/src/concepts/TriggerLauncher__.ts +2 -2
  37. package/src/config.ts +0 -5
  38. package/src/generator/genBundleFiles.ts +0 -22
  39. package/src/generator/release-body/body.ts +1 -68
  40. package/src/generator/release-body/data.ts +4 -15
  41. package/src/generator/release-body/internal.ts +0 -10
  42. package/src/generator/release-body/utils.ts +8 -35
  43. package/src/natural/index.ts +1 -0
  44. package/src/natural/transformTS2UI.ts +1123 -0
  45. package/src/server/naslServer.ts +0 -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": "3.7.0-beta.8",
4
+ "version": "3.7.1-alpha.1",
5
5
  "author": "Forrest <rainforest92@126.com>",
6
6
  "scripts": {
7
7
  "clear": "rimraf ./out",
@@ -4,20 +4,7 @@ import Frontend from './Frontend__';
4
4
  import ProcessElement from './ProcessElement__';
5
5
  import Process from './Process__';
6
6
  import Interface from './Interface__';
7
- import Namespace from './Namespace__';
8
- import Connector from './Connector__';
9
7
  import type InterfaceTriggerEvent from './InterfaceTriggerEvent__';
10
- import { EmbeddedTSFileGenerator } from '../utils';
11
- import { CUSTOM_CONNECTOR_EDITABLE_SUFFIX } from './basics/constants';
12
- import {
13
- TranslatorState,
14
- shiftState,
15
- withSourceMap,
16
- createCompilerState,
17
- withSourceMapGenerator,
18
- withGenerator,
19
- TranslatorGenerator,
20
- } from '../translator';
21
8
  //================================================================================
22
9
  // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
23
10
  // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
@@ -195,153 +182,6 @@ export class ConnectorTrigger extends BaseNode {
195
182
  // });
196
183
  this.app?.emit('collect:end');
197
184
  }
198
- /**
199
- * 祖先 Connector
200
- */
201
- get connector() {
202
- return this.getAncestor('Connector') as Connector;
203
- }
204
-
205
- // 是否来自于 集成中心
206
- get integration() {
207
- return this.getAncestor('Integration');
208
- }
209
-
210
- @withSourceMapGenerator
211
- *toEmbeddedTS(state = createCompilerState()): TranslatorGenerator {
212
- const self = this;
213
- let code = '';
214
- code += `export function ${self.tsName} () {\n`;
215
- try {
216
- // code += ';\n';
217
- code += '}\n';
218
- } catch (error) {
219
- console.error('找不到目标服务端逻辑', error);
220
- }
221
- return code;
222
- }
223
-
224
- *toEmbeddedTSFile(): EmbeddedTSFileGenerator {
225
- let code = `namespace ${this.getTsNamespace()} {\n`;
226
- const state = createCompilerState(code, { tabSize: 1 });
227
- try {
228
- code += yield* this.toEmbeddedTS(state);
229
- } catch (err) {
230
- code += '';
231
- console.log(err);
232
- }
233
- code += '}\n';
234
-
235
- return {
236
- code,
237
- filePath: this.getEmbeddedFilePath(),
238
- sourceMap: state.sourceMap,
239
- };
240
- }
241
-
242
- getTsNamespace() {
243
- if (this.parentNode?.concept === 'Connector') {
244
- return `connector.${this.parentNode.tsName}.triggers`;
245
- }
246
- }
247
-
248
- get tsName(): string {
249
- const excludeds = [
250
- 'abstract',
251
- 'arguments',
252
- 'await',
253
- 'boolean',
254
- 'break',
255
- 'byte',
256
- 'case',
257
- 'catch',
258
- 'char',
259
- 'class',
260
- 'const',
261
- 'continue',
262
- 'debugger',
263
- 'default',
264
- 'delete',
265
- 'do',
266
- 'double',
267
- 'decimal',
268
- 'else',
269
- 'enum',
270
- 'eval',
271
- 'export',
272
- 'extends',
273
- 'false',
274
- 'final',
275
- 'finally',
276
- 'float',
277
- 'for',
278
- 'function',
279
- 'goto',
280
- 'if',
281
- 'implements',
282
- 'import',
283
- 'in',
284
- 'instanceof',
285
- 'int',
286
- 'interface',
287
- 'let',
288
- 'long',
289
- 'native',
290
- 'new',
291
- 'null',
292
- 'package',
293
- 'private',
294
- 'protected',
295
- 'public',
296
- 'return',
297
- 'short',
298
- 'static',
299
- 'super',
300
- 'switch',
301
- 'synchronized',
302
- 'this',
303
- 'throw',
304
- 'throws',
305
- 'transient',
306
- 'true',
307
- 'try',
308
- 'typeof',
309
- 'var',
310
- 'void',
311
- 'volatile',
312
- 'while',
313
- 'with',
314
- 'yield,as',
315
- 'any',
316
- 'number',
317
- 'string',
318
- 'get',
319
- 'type',
320
- 'typeof',
321
- 'instanceof',
322
- 'require',
323
- ];
324
- if (excludeds.includes(this.name)) {
325
- return `_${this.name}`;
326
- }
327
- // 来自集成中心,且是连接内部的逻辑,则认为是编辑态的,需要加上后缀
328
- if (this.connector && this.integration) {
329
- return `${this.name}${CUSTOM_CONNECTOR_EDITABLE_SUFFIX}`;
330
- }
331
- return this.name;
332
- }
333
-
334
- /**
335
- * 生成宿主语言的文件路径
336
- * @param name 一般不用传,用于 rename
337
- */
338
- getEmbeddedFilePath(name = this.name) {
339
- // 自定义连接器 编辑态文件对应parentKey 为 connectors,
340
-
341
- if (this.parentNode.concept === 'Connector') {
342
- return `/embedded/${this.app.name}/${this.parentNode.parentKey}/${this.parentNode.name}/triggers/${name}.ts`;
343
- }
344
- }
345
185
 
346
186
  //================================================================================
347
187
  // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
@@ -1215,10 +1215,7 @@ export class Connector extends Module {
1215
1215
  name: namespace.name,
1216
1216
  expanded: true,
1217
1217
  unselectable: true, // 自定义属性。用于标注当前选项是否可以被选择
1218
- children: namespace.logics?.map((logic: any) => {
1219
- logic._exName = `${namespace.name}_${logic.name}`;
1220
- return logic;
1221
- }),
1218
+ children: namespace.logics,
1222
1219
  };
1223
1220
  });
1224
1221
  }
@@ -167,7 +167,6 @@ export class TriggerLauncher extends BaseNode {
167
167
  // 仅仅作引用查找不需要入参校验
168
168
  if (self.concept === 'ConnectorTriggerLauncher') {
169
169
  const connectorTrigger = (self as unknown as ConnectorTriggerLauncher).connectorTrigger
170
- code += `let trigger = connector.${(self as unknown as ConnectorTriggerLauncher).connector.name}.triggers.${connectorTrigger.tsName};\n`
171
170
  let stashParams = ''
172
171
  if (connectorTrigger?.triggerEvent?.callBackLogic?.typeArguments?.[0]) {
173
172
  stashParams = 'params'
@@ -180,8 +179,9 @@ export class TriggerLauncher extends BaseNode {
180
179
  }
181
180
  code += ` = ${self.callBackLogicKey}(${stashParams})`;
182
181
  } else {
183
- code += `${self.callBackLogicKey};\n`;
182
+ code += `${self.callBackLogicKey}`;
184
183
  }
184
+ code += ';\n';
185
185
  code += '}\n';
186
186
  } catch (error) {
187
187
  console.error('找不到目标服务端逻辑', error);
package/src/config.ts CHANGED
@@ -31,11 +31,6 @@ export const config = {
31
31
  * 使用场景:导出源码
32
32
  */
33
33
  frontendPackagesResource: [] as {path: string, isDir: boolean, url: string}[],
34
- assets: [] as Array<{
35
- path: string,
36
- isDir: boolean,
37
- url: string;
38
- }>,
39
34
  };
40
35
 
41
36
  /* eslint-disable no-redeclare */
@@ -11,7 +11,6 @@ import { compileComponent } from './compileComponent';
11
11
 
12
12
  import { genMetaData } from './genMetaData';
13
13
  import { integrateMicroApp } from './microApp';
14
- import type { Asset } from './release-body/internal';
15
14
 
16
15
  export interface Route {
17
16
  path?: string;
@@ -39,8 +38,6 @@ interface Config {
39
38
  miniEnable: boolean;
40
39
  isPreviewFe?: boolean;
41
40
  previewVersion?: string;
42
- assets: Array<Asset>;
43
- assetsMap: Map<string, Asset>;
44
41
  }
45
42
 
46
43
  // 将metaData转成字符串
@@ -775,25 +772,6 @@ export function genBundleFiles(app: App, frontend: Frontend, config: Config) {
775
772
  ${microAppIntegration || 'loadAssets();'}
776
773
  })()
777
774
  `;
778
- const assets = config.assets;
779
- // 导出源码才处理
780
- if (config.isExport && Array.isArray(assets) && assets.length) {
781
- const assetsMap = config.assetsMap;
782
- const regex = new RegExp(assets.map((asset) => asset.fileUrl).join("|"), "g");
783
- content = content.replace(regex, (url) => {
784
- const asset = assetsMap.get(url);
785
- if (asset) {
786
- const path = `/assets/${asset.name}`;
787
- globalConfig.assets.push({
788
- path,
789
- isDir: false,
790
- url,
791
- });
792
- return path;
793
- }
794
- return url;
795
- });
796
- }
797
775
  let minifyObj = { code: '' };
798
776
  // 开发环境加上sourceMap
799
777
  if (config.env === 'dev') {
@@ -10,39 +10,6 @@ import { genPermissionData, genLogicAuthFlag } from '../permission';
10
10
  import { getCallLogicData } from './validation';
11
11
 
12
12
  import * as utils from '../../utils';
13
- import { config as globalConfig } from '../../config'
14
-
15
- /**
16
- * 替换端类型中的资源
17
- * @param frontendTypes
18
- * @param fn
19
- */
20
- export function replaceFrontendTypesAssets(frontendTypes: FrontendType[], fn: Function) {
21
- frontendTypes.forEach((frontendType: FrontendType) => {
22
- utils.traverse((current: {
23
- node: any
24
- }) => {
25
- for (const key in current.node) {
26
- const attr = current.node[key];
27
- if (typeof attr === 'string') {
28
- fn(current.node, key, attr);
29
- }
30
- }
31
- }, { node: frontendType }, {
32
- mode: 'anyObject', excludedKeySet: new Set([
33
- 'parentNode',
34
- 'sourceMap',
35
- 'storageJSON',
36
- 'tsErrorDetail',
37
- 'NaslAnnotatedJSON',
38
- 'calledFrom',
39
- '_events',
40
- '_collectingList',
41
- '_historyList',
42
- ])
43
- });
44
- });
45
- }
46
13
 
47
14
  async function getNaslAnnotatedJSON(app: App, opt: InternalReleaseData) {
48
15
  await utils.delay(500);
@@ -68,40 +35,6 @@ async function getNaslAnnotatedJSON(app: App, opt: InternalReleaseData) {
68
35
  });
69
36
  }
70
37
 
71
- const assets = opt.assets;
72
- if (Array.isArray(assets) && assets.length) {
73
- const assetsMap = opt.assetsMap;
74
- const regex = new RegExp(assets.map((asset) => asset.fileUrl).join("|"), "g");
75
- replaceFrontendTypesAssets(NaslAnnotatedJSON.frontendTypes, (node: any, key: string, url: string) => {
76
- if (['staticStyle'].includes(key)) {
77
- node[key] = url.replace(regex, (url) => {
78
- const asset = assetsMap.get(url);
79
- if (asset) {
80
- const path = `/assets/${asset.name}`;
81
- globalConfig.assets.push({
82
- path,
83
- isDir: false,
84
- url,
85
- });
86
- return path;
87
- }
88
- return url;
89
- });
90
- } else {
91
- const asset = assetsMap.get(url);
92
- if (asset) {
93
- const path = `/assets/${asset.name}`;
94
- globalConfig.assets.push({
95
- path,
96
- isDir: false,
97
- url,
98
- });
99
- node[key] = path;
100
- }
101
- }
102
- });
103
- }
104
-
105
38
  return {
106
39
  name: 'nasl-annotated.json',
107
40
  content: JSON.stringify(NaslAnnotatedJSON),
@@ -144,7 +77,7 @@ async function mergeBodyData(app: App, opt: InternalReleaseData) {
144
77
  await utils.delay(500);
145
78
 
146
79
  const authReport: ReturnType<typeof getAuthReport> = getAuthReport(app, opt.frontends);
147
- await opt.logPublishFunc?.('权限', '分析权限数据成功!');
80
+ await opt.logPublishFunc?.('权限', '分析权限数据成功!');
148
81
  const logicPageResourceDtoList = await genPermissionData(app);
149
82
  const allFrontends = getFrontendByTypes(app?.frontendTypes);
150
83
  const releaseFrontends = allFrontends.map((frontend: Frontend) => ({
@@ -1,10 +1,9 @@
1
1
  import type { App } from '../../concepts';
2
2
  import { ReleaseData, ReleaseMode } from './types';
3
3
  import type { NaslServer } from '../../server/naslServer';
4
- import type { InternalReleaseData, Asset } from './internal';
4
+ import type { InternalReleaseData } from './internal';
5
5
  import { genReleaseBody } from './body';
6
6
  import {
7
- loadFiles,
8
7
  staticResourceSync,
9
8
  getContentType,
10
9
  getPackageInfos,
@@ -14,13 +13,12 @@ import {
14
13
  getValidationRules,
15
14
  } from './utils';
16
15
  import { Logger, File } from '../../utils';
17
- import { config as globalConfig } from '../../config'
18
16
 
19
17
  export async function getReleaseData(app: App, data: ReleaseData, naslServer: NaslServer, inputLogger?: Logger) {
20
18
  const { http, logger: defaultLogger } = naslServer;
21
19
  const logger = inputLogger ?? defaultLogger;
22
20
  defaultLogger.time('前端生成器发布');
23
- const appInfo = await getAppInfo(http, data);
21
+ const appInfo = await getAppInfo(http, data);
24
22
  await logger.info('构建环境', '获取环境信息成功');
25
23
  const { version, fullVersion, dependencies } = await getVersionDetail(http, app);
26
24
  await logger.info('构建环境', '获取版本数据成功');
@@ -29,13 +27,6 @@ export async function getReleaseData(app: App, data: ReleaseData, naslServer: Na
29
27
  const releaseFrontends = inputFrontendNames.length > 0
30
28
  ? allFrontend.filter((item) => data.config.frontendNames.includes(item.name))
31
29
  : allFrontend;
32
- // 当前应用使用到的资源
33
- const assets = await loadFiles(http, data.appId);
34
- const assetsMap = new Map();
35
- assets.forEach((asset: Asset) => {
36
- const { fileUrl } = asset;
37
- assetsMap.set(fileUrl, asset);
38
- });
39
30
  const result: InternalReleaseData = {
40
31
  appInfo: appInfo as any,
41
32
  env: data.env,
@@ -50,8 +41,6 @@ export async function getReleaseData(app: App, data: ReleaseData, naslServer: Na
50
41
  appSpecification: data.appSpecification,
51
42
  frontends: releaseFrontends,
52
43
  validations: {},
53
- assets,
54
- assetsMap,
55
44
  logPublishFunc: (text: string) => logger.info('前端生成器', text),
56
45
  };
57
46
 
@@ -63,7 +52,7 @@ export async function getReleaseData(app: App, data: ReleaseData, naslServer: Na
63
52
 
64
53
  // 私有化环境,需要同步资源;内部环境暂不需要,针对使用 CDN 场景增加判断
65
54
  if (String(appInfo.isPrivatized) === 'true') {
66
- result.staticUrl = await staticResourceSync(http, assets, data.appId, data.env, releaseFrontends);
55
+ result.staticUrl = await staticResourceSync(http, data.appId, data.env, releaseFrontends);
67
56
  await logger.info('构建环境', '私有化部署同步资源成功');
68
57
  }
69
58
 
@@ -96,7 +85,7 @@ export function getReleaseFormData(body: any) {
96
85
  const formData = new FormData();
97
86
 
98
87
  if (!body.isPreviewFe) {
99
- body.files = body.files.map(
88
+ body.files = body.files.map(
100
89
  (item: any) => new File([item.content], item.name, { type: getContentType(item.name) })
101
90
  ) as any;
102
91
  }
@@ -8,14 +8,6 @@ export interface ServerValidationData {
8
8
 
9
9
  export type InputServerValidationData = { [key in string]: ServerValidationData[] };
10
10
 
11
- export interface Asset {
12
- name: string;
13
- type: string;
14
- subType: string;
15
- fileUrl: string;
16
- contentType: string;
17
- }
18
-
19
11
  /** @internal */
20
12
  export interface InternalReleaseData {
21
13
  env: string;
@@ -44,8 +36,6 @@ export interface InternalReleaseData {
44
36
  validations: InputServerValidationData;
45
37
  logPublishFunc: Function;
46
38
  appSpecification?: number;
47
- assets: Array<Asset>;
48
- assetsMap: Map<string, Asset>;
49
39
  }
50
40
 
51
41
  /** @internal */
@@ -10,7 +10,7 @@ import type {
10
10
  import { AxiosInstance } from 'axios';
11
11
  import * as asserts from '../../concepts/utils/asserts';
12
12
  import { ReleaseData, ReleaseMode } from './types';
13
- import { HttpData, VersionDetail, MaterialData, EnvData, TenantData, AppDetailData, Asset } from './internal';
13
+ import { HttpData, VersionDetail, MaterialData, EnvData, TenantData, AppDetailData } from './internal';
14
14
 
15
15
  /**
16
16
  * 权限上报数据
@@ -115,24 +115,13 @@ export function getFrontendByTypes(frontendTypes: FrontendType[] = []) {
115
115
  return (frontendTypes?.map((frontendType) => (frontendType?.frontends || [])) || []).flat(2);
116
116
  }
117
117
 
118
- /**
119
- * 当前应用使用到的资源
120
- * @param axios
121
- * @param id
122
- * @returns
123
- */
124
- export async function loadFiles(axios: AxiosInstance, id: string) {
118
+ export async function getUsedAssets(axios: AxiosInstance, id: string, frontends: Frontend[]) {
125
119
  const { data: res } = await axios.get('/api/v1/user/file', {
126
- params: {
127
- appId: id,
128
- },
120
+ params: {
121
+ appId: id,
122
+ },
129
123
  });
130
124
  const assets = (res as any).result?.list || [];
131
- return assets;
132
- }
133
-
134
- export async function getUsedAssets(axios: AxiosInstance, id: string, frontends: Frontend[]) {
135
- const assets = await loadFiles(axios, id);
136
125
  const urlNameMap: Record<string, string> = {};
137
126
  const assetSet = new Set<string>();
138
127
 
@@ -152,29 +141,13 @@ export async function getUsedAssets(axios: AxiosInstance, id: string, frontends:
152
141
  return Array.from(assetSet);
153
142
  }
154
143
 
155
- export async function staticResourceSync(axios: AxiosInstance, assets: Array<Asset>, id: string, env: string, frontends: Frontend[]) {
156
- const urlNameMap: Record<string, string> = {};
157
- const assetSet = new Set<string>();
158
-
159
- for (const { fileUrl, name } of assets) {
160
- urlNameMap[fileUrl] = name;
161
- }
162
-
163
- frontends.forEach((frontend) => {
164
- frontend.views.forEach((view) => {
165
- view.traverseStrictChildren((ele) => {
166
- if (asserts.isBindAttribute(ele) && urlNameMap[ele.value]) {
167
- assetSet.add(urlNameMap[ele.value]);
168
- }
169
- });
170
- });
171
- });
144
+ export async function staticResourceSync(axios: AxiosInstance, id: string, env: string, frontends: Frontend[]) {
172
145
  // 发起资源同步请求,传递nasl使用到的资源名称
173
- const needSyncResourceNameList = Array.from(assetSet);
146
+ const assets = await getUsedAssets(axios, id, frontends);
174
147
  const { data: res } = await axios.post(
175
148
  '/api/v1/app/env/staticResourceSync',
176
149
  {
177
- needSyncResourceNameList,
150
+ needSyncResourceNameList: assets,
178
151
  },
179
152
  {
180
153
  params: {
@@ -1,3 +1,4 @@
1
1
  export * from './genNaturalTS';
2
2
  export * from './transformTSCode';
3
+ export * from './transformTS2UI';
3
4