@lcap/nasl 2.18.0-beta.5 → 2.18.0-beta.7

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 (88) hide show
  1. package/out/common/BaseNode.js +1 -0
  2. package/out/common/BaseNode.js.map +1 -1
  3. package/out/concepts/BatchAssignment__.js +63 -46
  4. package/out/concepts/BatchAssignment__.js.map +1 -1
  5. package/out/concepts/CallLogic__.d.ts +2 -1
  6. package/out/concepts/CallLogic__.js +26 -11
  7. package/out/concepts/CallLogic__.js.map +1 -1
  8. package/out/concepts/Destination__.d.ts +2 -1
  9. package/out/concepts/Destination__.js +90 -22
  10. package/out/concepts/Destination__.js.map +1 -1
  11. package/out/concepts/Logic__.js +6 -7
  12. package/out/concepts/Logic__.js.map +1 -1
  13. package/out/concepts/MatchExpression__.d.ts +97 -0
  14. package/out/concepts/MatchExpression__.js +281 -0
  15. package/out/concepts/MatchExpression__.js.map +1 -0
  16. package/out/concepts/ViewElement__.js +1 -1
  17. package/out/concepts/ViewElement__.js.map +1 -1
  18. package/out/concepts/View__.js +4 -0
  19. package/out/concepts/View__.js.map +1 -1
  20. package/out/generator/genBundleFiles.js +32 -182
  21. package/out/generator/genBundleFiles.js.map +1 -1
  22. package/out/generator/genMetaData.d.ts +1 -10
  23. package/out/generator/genMetaData.js +189 -50
  24. package/out/generator/genMetaData.js.map +1 -1
  25. package/out/generator/genReleaseBody.js +11 -2
  26. package/out/generator/genReleaseBody.js.map +1 -1
  27. package/out/server/extendBaseNode.js +4 -18
  28. package/out/server/extendBaseNode.js.map +1 -1
  29. package/out/server/formatTsUtils.d.ts +1 -2
  30. package/out/server/formatTsUtils.js +30 -47
  31. package/out/server/formatTsUtils.js.map +1 -1
  32. package/out/server/getProcesses.js +1 -1
  33. package/out/server/getProcesses.js.map +1 -1
  34. package/out/server/naslServer.js +8 -7
  35. package/out/server/naslServer.js.map +1 -1
  36. package/out/server/translator.js +19 -4
  37. package/out/server/translator.js.map +1 -1
  38. package/out/templator/sql-parser/index.d.ts +1 -0
  39. package/out/templator/sql-parser/index.js +228 -0
  40. package/out/templator/sql-parser/index.js.map +1 -0
  41. package/out/templator/sql-parser/parser.js +26664 -0
  42. package/out/templator/sql-parser/parser.js.map +1 -0
  43. package/package.json +2 -2
  44. package/sandbox/stdlib/dist/nasl.logging.js +0 -0
  45. package/sandbox/stdlib/nasl.util.ts +1 -1
  46. package/src/automate/engine/dist/index.dev.js +517 -0
  47. package/src/common/BaseNode.ts +1 -0
  48. package/src/common/dist/BaseNode.js +1101 -0
  49. package/src/concepts/BatchAssignment__.ts +66 -50
  50. package/src/concepts/CallLogic__.ts +26 -11
  51. package/src/concepts/Destination__.ts +92 -22
  52. package/src/concepts/Logic__.ts +6 -7
  53. package/src/concepts/ViewElement__.ts +8 -29
  54. package/src/concepts/View__.ts +4 -0
  55. package/src/concepts/basics/stdlib/dist/nasl.util.js +1503 -0
  56. package/src/concepts/basics/stdlib/dist/reference2TypeAnnotationList.js +24 -0
  57. package/src/concepts/dist/Anchor__.js +179 -0
  58. package/src/concepts/dist/Assignment__.js +301 -0
  59. package/src/concepts/dist/CallFunction__.js +513 -0
  60. package/src/concepts/dist/CallInterface__.js +533 -0
  61. package/src/concepts/dist/CallLogic__.js +892 -0
  62. package/src/concepts/dist/ForEachStatement__.js +426 -0
  63. package/src/concepts/dist/MatchCase__.js +587 -0
  64. package/src/concepts/dist/Match__.js +631 -0
  65. package/src/concepts/dist/MemberExpression__.js +348 -0
  66. package/src/concepts/dist/Param__.js +538 -0
  67. package/src/concepts/dist/Return__.js +494 -0
  68. package/src/concepts/dist/Variable__.js +537 -0
  69. package/src/concepts/dist/ViewElement__.js +1680 -0
  70. package/src/generator/dist/genBundleFiles.js +261 -0
  71. package/src/generator/dist/genMetaData.js +249 -0
  72. package/src/generator/genBundleFiles.ts +34 -219
  73. package/src/generator/genMetaData.ts +182 -77
  74. package/src/generator/genReleaseBody.ts +10 -3
  75. package/src/server/dist/formatTsUtils.js +683 -0
  76. package/src/server/dist/naslServer.js +3474 -0
  77. package/src/server/extendBaseNode.ts +4 -19
  78. package/src/server/formatTsUtils.ts +30 -46
  79. package/src/server/getProcesses.ts +1 -1
  80. package/src/server/naslServer.ts +8 -7
  81. package/src/server/translator.ts +18 -4
  82. package/src/service/storage/dist/init.js +572 -0
  83. package/ts-worker/dist/webpack.config.dev.js +108 -0
  84. package/dist/bundle.js +0 -3962
  85. package/dist/bundle.js.LICENSE.txt +0 -16
  86. package/out/generator/release.d.ts +0 -1
  87. package/out/generator/release.js +0 -51
  88. package/out/generator/release.js.map +0 -1
@@ -0,0 +1,892 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ var __assign = (this && this.__assign) || function () {
16
+ __assign = Object.assign || function(t) {
17
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
18
+ s = arguments[i];
19
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
20
+ t[p] = s[p];
21
+ }
22
+ return t;
23
+ };
24
+ return __assign.apply(this, arguments);
25
+ };
26
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
27
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
28
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
29
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
30
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
31
+ };
32
+ exports.__esModule = true;
33
+ exports.CallLogic = void 0;
34
+ var translator_1 = require("../translator");
35
+ var View__1 = require("./View__");
36
+ var utils_1 = require("../automate/engine/utils");
37
+ var utils_2 = require("../utils");
38
+ var decorators_1 = require("../decorators");
39
+ var classMap_1 = require("../common/classMap");
40
+ var TypeAnnotation__1 = require("./TypeAnnotation__");
41
+ var Argument__1 = require("./Argument__");
42
+ var LogicItem__1 = require("./LogicItem__");
43
+ /**
44
+ * 调用逻辑
45
+ */
46
+ var CallLogic = /** @class */ (function (_super) {
47
+ __extends(CallLogic, _super);
48
+ /**
49
+ * @param source 需要合并的部分参数
50
+ */
51
+ function CallLogic(source) {
52
+ var _this = this;
53
+ source = Object.assign({}, CallLogic_1.getDefaultOptions(), source);
54
+ _this = _super.call(this, source) || this;
55
+ /**
56
+ * 产品概念
57
+ */
58
+ _this.concept = 'CallLogic';
59
+ /**
60
+ * 调用逻辑标题
61
+ */
62
+ _this.label = '调用逻辑';
63
+ /**
64
+ * calleeNamespace
65
+ */
66
+ _this.calleeNamespace = undefined;
67
+ /**
68
+ * calleeName
69
+ */
70
+ _this.calleeName = undefined;
71
+ /**
72
+ * shortcut
73
+ */
74
+ _this.shortcut = undefined;
75
+ /**
76
+ * 类型参数
77
+ */
78
+ _this.typeArguments = null;
79
+ /**
80
+ * 实际参数
81
+ */
82
+ _this.arguments = [];
83
+ _super.prototype.subConstructor.call(_this, source);
84
+ return _this;
85
+ }
86
+ CallLogic_1 = CallLogic;
87
+ CallLogic.from = function (source, parentNode, parentKey) {
88
+ return _super.from.call(this, source, parentNode, parentKey);
89
+ };
90
+ CallLogic.prototype._insertTypeAnnotationAt = function (options, index) {
91
+ var typeAnnotationOptions = {};
92
+ var relationOptions = { parentNode: this, parentKey: 'typeArguments' };
93
+ var typeAnnotation;
94
+ if (options instanceof TypeAnnotation__1["default"]) {
95
+ options.ensureDelete(); // 同一实例不支持多处存在
96
+ typeAnnotation = options;
97
+ Object.assign(typeAnnotation, relationOptions);
98
+ }
99
+ else {
100
+ typeAnnotation = TypeAnnotation__1["default"].from(__assign(__assign({}, typeAnnotationOptions), options), this, 'typeArguments');
101
+ }
102
+ this.typeArguments.splice(index, 0, typeAnnotation);
103
+ return typeAnnotation;
104
+ };
105
+ CallLogic.prototype.insertTypeAnnotationAt = function (options, index) {
106
+ var node = this._insertTypeAnnotationAt(options, index);
107
+ node.create({
108
+ index: index,
109
+ parentNode: this,
110
+ parentKey: 'typeArguments'
111
+ });
112
+ return node;
113
+ };
114
+ CallLogic.prototype._addTypeAnnotation = function (options) {
115
+ var index = this.typeArguments.length;
116
+ return this._insertTypeAnnotationAt(options, index);
117
+ };
118
+ CallLogic.prototype.addTypeAnnotation = function (options) {
119
+ var node = this._addTypeAnnotation(options);
120
+ var index = this.typeArguments.indexOf(node);
121
+ node.create({
122
+ index: index,
123
+ parentNode: this,
124
+ parentKey: 'typeArguments'
125
+ });
126
+ return node;
127
+ };
128
+ CallLogic.prototype._insertArgumentAt = function (options, index) {
129
+ var argumentOptions = {};
130
+ var relationOptions = { parentNode: this, parentKey: 'arguments' };
131
+ var argument;
132
+ if (options instanceof Argument__1["default"]) {
133
+ options.ensureDelete(); // 同一实例不支持多处存在
134
+ argument = options;
135
+ Object.assign(argument, relationOptions);
136
+ }
137
+ else {
138
+ argument = Argument__1["default"].from(__assign(__assign({}, argumentOptions), options), this, 'arguments');
139
+ }
140
+ this.arguments.splice(index, 0, argument);
141
+ return argument;
142
+ };
143
+ CallLogic.prototype.insertArgumentAt = function (options, index) {
144
+ var node = this._insertArgumentAt(options, index);
145
+ node.create({
146
+ index: index,
147
+ parentNode: this,
148
+ parentKey: 'arguments'
149
+ });
150
+ return node;
151
+ };
152
+ CallLogic.prototype._addArgument = function (options) {
153
+ var index = this.arguments.length;
154
+ return this._insertArgumentAt(options, index);
155
+ };
156
+ CallLogic.prototype.addArgument = function (options) {
157
+ var node = this._addArgument(options);
158
+ var index = this.arguments.indexOf(node);
159
+ node.create({
160
+ index: index,
161
+ parentNode: this,
162
+ parentKey: 'arguments'
163
+ });
164
+ return node;
165
+ };
166
+ CallLogic.prototype.removeTypeAnnotation = function (options) {
167
+ var typeAnnotation = options;
168
+ return typeAnnotation["delete"]();
169
+ };
170
+ CallLogic.prototype.__removeTypeAnnotation = function (typeAnnotation) {
171
+ var parentKey = typeAnnotation.parentKey;
172
+ var params = {
173
+ parentNode: this,
174
+ parentKey: parentKey,
175
+ index: -1,
176
+ object: null,
177
+ oldObject: typeAnnotation
178
+ };
179
+ if (parentKey) {
180
+ params.parentKey = parentKey;
181
+ if (Array.isArray(this[parentKey])) {
182
+ var index = this[parentKey].indexOf(typeAnnotation);
183
+ ~index && this[parentKey].splice(index, 1);
184
+ params.index = index;
185
+ }
186
+ else if (this[parentKey] === typeAnnotation) {
187
+ params.index = 0;
188
+ this[parentKey] = undefined;
189
+ }
190
+ }
191
+ return params;
192
+ };
193
+ CallLogic.prototype.removeArgument = function (options) {
194
+ var argument = options;
195
+ return argument["delete"]();
196
+ };
197
+ CallLogic.prototype.__removeLogicItem = function (logicItem) {
198
+ var parentKey = logicItem.parentKey;
199
+ var params = {
200
+ parentNode: this,
201
+ parentKey: parentKey,
202
+ index: -1,
203
+ object: null,
204
+ oldObject: logicItem
205
+ };
206
+ if (parentKey) {
207
+ params.parentKey = parentKey;
208
+ if (Array.isArray(this[parentKey])) {
209
+ var index = this[parentKey].indexOf(logicItem);
210
+ ~index && this[parentKey].splice(index, 1);
211
+ params.index = index;
212
+ }
213
+ else if (this[parentKey] === logicItem) {
214
+ params.index = 0;
215
+ this[parentKey] = undefined;
216
+ }
217
+ }
218
+ return params;
219
+ };
220
+ Object.defineProperty(CallLogic.prototype, "tsCalleeNamespace", {
221
+ //================================================================================
222
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
223
+ // 自动生成的代码已结束。下面可以手动编写。
224
+ //================================================================================
225
+ get: function () {
226
+ if (this.calleeNamespace) {
227
+ var tsCalleeNamespace = this.calleeNamespace;
228
+ tsCalleeNamespace = tsCalleeNamespace.replace(/\.[0-9]/g, function (m) { return m.replace('.', '.$'); });
229
+ tsCalleeNamespace = tsCalleeNamespace.replace(/-/g, '_');
230
+ return tsCalleeNamespace;
231
+ }
232
+ return '';
233
+ },
234
+ enumerable: false,
235
+ configurable: true
236
+ });
237
+ Object.defineProperty(CallLogic.prototype, "calleewholeKey", {
238
+ // 用于logic回填
239
+ get: function () {
240
+ if (!this.calleeNamespace && this.calleeName && this.view) {
241
+ // 页面逻辑单独处理
242
+ return this.view.getNamespace() + "." + this.view.name + ".logics." + this.calleeName;
243
+ }
244
+ return this.calleeNamespace + '.' + this.calleeName;
245
+ },
246
+ enumerable: false,
247
+ configurable: true
248
+ });
249
+ Object.defineProperty(CallLogic.prototype, "calleeKey", {
250
+ get: function () {
251
+ var tsCalleeNamespace = this.tsCalleeNamespace;
252
+ var calleeName = this.calleeName;
253
+ if (!tsCalleeNamespace) {
254
+ return calleeName ? "" + calleeName : '__IDENTIFIER__';
255
+ }
256
+ // elements单独处理相对路径,和后缀的问题
257
+ if (tsCalleeNamespace.startsWith('elements') && tsCalleeNamespace.endsWith('logics')) {
258
+ var methodName = tsCalleeNamespace.substring(0, tsCalleeNamespace.length - '.logics'.length);
259
+ return '__' + methodName + ("." + calleeName);
260
+ }
261
+ return calleeName ? tsCalleeNamespace + "." + calleeName : '__IDENTIFIER__';
262
+ },
263
+ enumerable: false,
264
+ configurable: true
265
+ });
266
+ /**
267
+ * 设置argment 触发别的地方的更新
268
+ */
269
+ CallLogic.prototype.setArgumentName = function (_a) {
270
+ var argument = _a.argument;
271
+ // argument.setKeyword(newKeyword);
272
+ // this.arguments = argument;
273
+ };
274
+ /**
275
+ * 设置setCalleeName
276
+ */
277
+ CallLogic.prototype.setCalleeName = function (calleeName) {
278
+ var object = {
279
+ calleeName: calleeName
280
+ };
281
+ this.update(__assign({}, object));
282
+ };
283
+ /**
284
+ * 设置calleeNamespace
285
+ */
286
+ CallLogic.prototype.setCalleeNamespace = function (calleeNamespace) {
287
+ var object = {
288
+ calleeNamespace: calleeNamespace
289
+ };
290
+ this.update(__assign({}, object));
291
+ };
292
+ CallLogic.prototype._setCallee = function (logic) {
293
+ var _this = this;
294
+ this.calleeNamespace = logic.getNamespace();
295
+ if (logic.parentNode instanceof View__1["default"]) {
296
+ this.calleeNamespace = '';
297
+ }
298
+ this.calleeName = logic.name;
299
+ this.arguments = [];
300
+ logic.params.forEach(function (param) {
301
+ _this._addArgument({
302
+ keyword: param.name
303
+ });
304
+ });
305
+ if (logic.typeParams) {
306
+ this.typeArguments = [];
307
+ logic.typeParams.forEach(function () {
308
+ _this._addTypeAnnotation({});
309
+ });
310
+ }
311
+ };
312
+ CallLogic.prototype.setCallee = function (logic) {
313
+ var _this = this;
314
+ var calleeNamespace = logic.getNamespace();
315
+ if (logic.parentNode instanceof View__1["default"]) {
316
+ calleeNamespace = '';
317
+ }
318
+ var calleeName = logic.name;
319
+ var params = logic.params.map(function (param) {
320
+ var relationOptions = { parentNode: _this, parentKey: 'arguments' };
321
+ var argument = Argument__1["default"].from({
322
+ keyword: param.name,
323
+ expression: param.defaultExpression
324
+ }, _this);
325
+ Object.assign(argument, relationOptions);
326
+ return argument;
327
+ });
328
+ var typeArguments = null;
329
+ if (logic.typeParams) {
330
+ typeArguments = logic.typeParams.map(function () {
331
+ var relationOptions = { parentNode: _this, parentKey: 'typeArguments' };
332
+ var typeArgu = new TypeAnnotation__1["default"]();
333
+ Object.assign(typeArgu, relationOptions);
334
+ return typeArgu;
335
+ });
336
+ }
337
+ if (this.app) {
338
+ this.app.emit('collect:start', {
339
+ actionMsg: "\u5207\u6362\u8C03\u7528\u903B\u8F91"
340
+ });
341
+ var parentNode = this.parentNode;
342
+ this.update({
343
+ calleeNamespace: calleeNamespace,
344
+ calleeName: calleeName,
345
+ arguments: params,
346
+ typeArguments: typeArguments,
347
+ folded: false
348
+ });
349
+ if (parentNode.concept === 'MemberExpression') {
350
+ var topNode = parentNode.firstMemberExpressionNode();
351
+ topNode.replaceNode(this);
352
+ }
353
+ this.app.emit('collect:end');
354
+ }
355
+ else {
356
+ this.update({
357
+ calleeNamespace: calleeNamespace,
358
+ calleeName: calleeName,
359
+ arguments: params,
360
+ typeArguments: typeArguments,
361
+ folded: false
362
+ });
363
+ }
364
+ };
365
+ CallLogic.prototype.addCalleeArg = function (logic) {
366
+ var _this = this;
367
+ var newArgs = this.arguments.map(function (argument) {
368
+ return Argument__1["default"].from(__assign({}, argument), _this);
369
+ });
370
+ var relationOptions = { parentNode: this, parentKey: 'arguments' };
371
+ /**
372
+ * 当前两个参数对应上,添加的时候,logic会比参数位内容多,就添加一个 argment
373
+ */
374
+ if (logic.params.length >= newArgs.length) {
375
+ logic.params.forEach(function (param, index) {
376
+ var arg = newArgs[index];
377
+ if (!arg) {
378
+ var newParam = Argument__1["default"].from({
379
+ keyword: param.name
380
+ }, _this);
381
+ Object.assign(newParam, relationOptions);
382
+ newArgs.push(newParam);
383
+ }
384
+ else {
385
+ arg.keyword = param.name;
386
+ }
387
+ });
388
+ }
389
+ else {
390
+ /**
391
+ * 当前calllogic上数量比logic参数还多,他就需要找一个arg使他变成可用的参数
392
+ */
393
+ newArgs.forEach(function (arg, index) {
394
+ var param = logic.params[index];
395
+ if (param) {
396
+ arg.keyword = param.name;
397
+ }
398
+ });
399
+ }
400
+ this.update({
401
+ arguments: newArgs
402
+ });
403
+ };
404
+ CallLogic.prototype.deleteCalleeArg = function (argIndex) {
405
+ var _a, _b;
406
+ /**
407
+ * 传递过下标来,然后直接移动到最后结束
408
+ * 如果原来就是最后一个位置就不移动了
409
+ */
410
+ if (typeof argIndex === 'number') {
411
+ if (!((_a = this.arguments[argIndex]) === null || _a === void 0 ? void 0 : _a.expression)) {
412
+ // 如果本身没有值就直接删除
413
+ return this.arguments[argIndex]["delete"]();
414
+ }
415
+ if (argIndex !== this.arguments.length - 1) {
416
+ (_b = this.arguments[argIndex]) === null || _b === void 0 ? void 0 : _b.moveNode({
417
+ sourceNode: this.arguments[this.arguments.length - 1],
418
+ position: 'insertAfter'
419
+ });
420
+ }
421
+ }
422
+ };
423
+ CallLogic.prototype.toVue = function (options) {
424
+ var code = '';
425
+ if (this.calleeNamespace === 'nasl.browser' || this.calleeNamespace === 'nasl.auth' || this.calleeNamespace === 'nasl.configuration' || this.calleeNamespace === 'nasl.process') {
426
+ code += '$global.';
427
+ }
428
+ code += this.calleeName;
429
+ code += '(';
430
+ var completeArguments = this.completeArguments;
431
+ completeArguments.forEach(function (arg, index) {
432
+ code += arg === null || arg === void 0 ? void 0 : arg.toVue(options);
433
+ if (index !== completeArguments.length - 1)
434
+ code += ', ';
435
+ });
436
+ code += ')';
437
+ return code;
438
+ };
439
+ CallLogic.prototype.toUI = function (state) {
440
+ var code = this.calleeName;
441
+ code += '(';
442
+ var completeArguments = this.completeArguments;
443
+ completeArguments.forEach(function (arg, index) {
444
+ code += arg === null || arg === void 0 ? void 0 : arg.toUI();
445
+ if (index !== completeArguments.length - 1)
446
+ code += ', ';
447
+ });
448
+ code += ')';
449
+ return code;
450
+ };
451
+ CallLogic.prototype.toJS = function (state) {
452
+ var _this = this;
453
+ var _a;
454
+ var code = '';
455
+ if (this.calleeName === 'deleteBy' || this.calleeName === 'updateBy') {
456
+ code += "\nvar __resolveData = __resolveData || ((root) => {\n if (!root)\n return\n // console.log(root.concept)\n delete root.folded\n\n if (root.concept === 'NumericLiteral') {\n root.value = root.value\n } else if (root.concept === \"StringLiteral\") {\n root.value = root.value\n } else if (root.concept === \"NullLiteral\") {\n delete root.value\n } else if (root.concept === \"BooleanLiteral\") {\n root.value = root.value === 'true'\n } else if (root.concept === \"Identifier\") {\n __parseType(root, 'expression')\n } else if (root.concept === \"MemberExpression\") {\n if (root.expression) {\n __parseType(root, 'expression')\n\n }\n }\n\n __resolveData(root.left)\n __resolveData(root.right)\n return root\n})\n\nvar __parseType = __parseType || ((root, prop) => {\n const value = eval(root[prop])\n const type = typeof value\n // console.log('type:', type, value)\n if (type === 'number') {\n root.concept = 'NumericLiteral'\n root.value = value + ''\n } else if (type === 'string') {\n root.concept = 'StringLiteral'\n root.value = value\n } else if (type === 'boolean') {\n root.concept = 'BooleanLiteral'\n root.value = value\n } else if (type === 'object') {\n if (Array.isArray(value)) {\n var itemValue = value[0]\n if(itemValue !== undefined) {\n var itemType = typeof itemValue\n root.concept = 'ListLiteral'\n if (itemType === 'number') {\n root.value = value.map(v => v + '').join(',')\n } else if (itemType === 'string') {\n root.value = value.map(v => \"'\" + v + \"'\").join(',')\n } else if (itemType === 'boolean') {\n root.value = value.join(',')\n }\n }\n }\n }\n})\n";
457
+ }
458
+ code += 'await ';
459
+ // 页面逻辑
460
+ var isViewLogic = true;
461
+ // 组件逻辑
462
+ var isComponentLogic = false;
463
+ var componentName = '';
464
+ var calleeNamespace = this.calleeNamespace;
465
+ var keywordProcessIndex = utils_2.findConceptKeyWordIndexFromNamespace(this.calleeNamespace, 'processes');
466
+ var isProcessLogic = keywordProcessIndex !== -1;
467
+ // calleeNamespace不存在,一定是页面逻辑
468
+ if (calleeNamespace) {
469
+ var namespaceArr = calleeNamespace.split('.');
470
+ var start = namespaceArr[0];
471
+ if (start === 'app' || start === 'extensions') {
472
+ var keywordViewsIndex = utils_2.findConceptKeyWordIndexFromNamespace(this.calleeNamespace, 'views');
473
+ if (keywordViewsIndex === -1) {
474
+ isViewLogic = false;
475
+ }
476
+ }
477
+ else if (start === 'elements' && namespaceArr.length === 3 && namespaceArr[2] === 'logics') {
478
+ isComponentLogic = true;
479
+ componentName = namespaceArr[1];
480
+ }
481
+ }
482
+ var completeArguments = this.completeArguments;
483
+ // 全局逻辑
484
+ if (!isViewLogic) {
485
+ var namespaceArr = calleeNamespace === null || calleeNamespace === void 0 ? void 0 : calleeNamespace.split('.');
486
+ var logic = utils_1.getNodeByNodeCallee(this.app, this.calleewholeKey, function (key, tempPoint) {
487
+ // 处理 NASL 中未定义的假的节点
488
+ if (key === tempPoint.name) {
489
+ return {
490
+ tempPoint: tempPoint,
491
+ state: 1
492
+ };
493
+ }
494
+ var t = tempPoint[key];
495
+ return {
496
+ tempPoint: t,
497
+ state: Array.isArray(t) ? 2 : 1
498
+ };
499
+ });
500
+ var args = (logic === null || logic === void 0 ? void 0 : logic.params) || [];
501
+ var keywordEntitiesIndex = utils_2.findConceptKeyWordIndexFromNamespace(this.calleeNamespace, 'entities');
502
+ code += "this.$logics['" + (this.calleeNamespace ? this.calleeNamespace + "." + this.calleeName : this.calleeName) + "']";
503
+ code += "({\n config: {\n download: false,\n },\n query: {";
504
+ if (isProcessLogic) {
505
+ var argsStr = args
506
+ .map(function (arg, index) {
507
+ var actualArg = completeArguments[index];
508
+ return {
509
+ keyword: arg === null || arg === void 0 ? void 0 : arg.name,
510
+ arg: actualArg
511
+ };
512
+ })
513
+ .map(function (obj) { var _a; return "\n" + (obj === null || obj === void 0 ? void 0 : obj.keyword) + ": " + ((_a = obj === null || obj === void 0 ? void 0 : obj.arg) === null || _a === void 0 ? void 0 : _a.toJS(translator_1.shiftState(state, code))); })
514
+ .join(', ');
515
+ code += argsStr;
516
+ }
517
+ code += "},\n headers: {},\n ";
518
+ if (keywordEntitiesIndex !== -1) {
519
+ var logicArgs = this.arguments;
520
+ var breakBody = false;
521
+ switch (this.calleeName) {
522
+ case 'get':
523
+ case 'delete': {
524
+ logicArgs = [];
525
+ code += "query: {";
526
+ var argsStr = args
527
+ .map(function (arg, index) {
528
+ var _a;
529
+ var actualArg = (_a = _this.arguments) === null || _a === void 0 ? void 0 : _a[index];
530
+ return {
531
+ keyword: arg === null || arg === void 0 ? void 0 : arg.name,
532
+ arg: actualArg
533
+ };
534
+ })
535
+ .map(function (obj) { var _a; return "\n" + (obj === null || obj === void 0 ? void 0 : obj.keyword) + ": " + ((_a = obj === null || obj === void 0 ? void 0 : obj.arg) === null || _a === void 0 ? void 0 : _a.toJS(translator_1.shiftState(state, code))); })
536
+ .join(', ');
537
+ code += argsStr;
538
+ code += "},\n";
539
+ break;
540
+ }
541
+ case 'updateBy': {
542
+ code += "body: {";
543
+ var argsStr = logicArgs
544
+ .filter(function (arg) { return arg.expression; })
545
+ .map(function (arg) {
546
+ var name = arg.expression.returnExpression ? arg.expression.name : 'entity';
547
+ // filter回调函数
548
+ if (arg.expression.returnExpression) {
549
+ var argsStr_1 = JSON.stringify(handleMember(arg.expression.returnExpression));
550
+ return name + ": {\n concept: 'Function',\n name: 'filter',\n returnExpression: __resolveData(" + argsStr_1 + ")\n }";
551
+ }
552
+ else {
553
+ return name + ": " + arg.expression.toJS(translator_1.shiftState(state, code));
554
+ }
555
+ })
556
+ .join(',');
557
+ code += argsStr;
558
+ code += "},\n";
559
+ logicArgs = [];
560
+ breakBody = true;
561
+ break;
562
+ }
563
+ case 'deleteBy': {
564
+ code += "body: ";
565
+ var argsStr = JSON.stringify(handleMember(logicArgs[0].expression.returnExpression));
566
+ code += "{\n concept: 'Function',\n name: 'filter',\n returnExpression: __resolveData(" + argsStr + ")\n }";
567
+ code += ",\n";
568
+ logicArgs = [];
569
+ breakBody = true;
570
+ break;
571
+ }
572
+ }
573
+ var bodyArgument = logicArgs.find(function (arg) { return arg.keyword === 'body'; });
574
+ if (!breakBody) {
575
+ if (bodyArgument) {
576
+ code += "\n" + (bodyArgument === null || bodyArgument === void 0 ? void 0 : bodyArgument.keyword) + ": " + (bodyArgument === null || bodyArgument === void 0 ? void 0 : bodyArgument.toJS(translator_1.shiftState(state, code)));
577
+ }
578
+ else {
579
+ code += "body: {}";
580
+ }
581
+ }
582
+ }
583
+ else {
584
+ code += "path: {},\n body: {";
585
+ if (!isProcessLogic) {
586
+ var argsStr = args
587
+ .map(function (arg, index) {
588
+ var actualArg = completeArguments[index];
589
+ return {
590
+ keyword: arg === null || arg === void 0 ? void 0 : arg.name,
591
+ arg: actualArg
592
+ };
593
+ })
594
+ .map(function (obj) { var _a; return "\n" + (obj === null || obj === void 0 ? void 0 : obj.keyword) + ": " + ((_a = obj === null || obj === void 0 ? void 0 : obj.arg) === null || _a === void 0 ? void 0 : _a.toJS(translator_1.shiftState(state, code))); })
595
+ .join(', ');
596
+ code += argsStr;
597
+ }
598
+ code += '\n}';
599
+ }
600
+ code += '\n})';
601
+ }
602
+ else {
603
+ if (isComponentLogic) {
604
+ code += "this.$refs." + componentName + "." + this.calleeName;
605
+ }
606
+ else if (calleeNamespace === 'nasl.ui' || calleeNamespace === 'nasl.util') {
607
+ switch (this.calleeName) {
608
+ case 'showMessage':
609
+ code += "this.$toast.show";
610
+ break;
611
+ case 'consoleLog':
612
+ code += "this.$utils.ConsoleLog";
613
+ break;
614
+ case 'jsonSerialize':
615
+ code += "JSON.stringify";
616
+ break;
617
+ case 'jsonDeserialize':
618
+ code += "JSON.parse";
619
+ break;
620
+ }
621
+ }
622
+ else if (calleeNamespace === 'nasl.browser' || calleeNamespace === 'nasl.auth' || calleeNamespace === 'nasl.configuration' || calleeNamespace === 'nasl.process' || calleeNamespace === 'nasl.io') {
623
+ code += "this.$global." + this.calleeName;
624
+ }
625
+ else {
626
+ code += "this." + this.calleeName;
627
+ }
628
+ if (calleeNamespace === 'nasl.process' || calleeNamespace === 'nasl.auth') {
629
+ code += '({';
630
+ (_a = this.arguments) === null || _a === void 0 ? void 0 : _a.filter(function (arg) { return arg === null || arg === void 0 ? void 0 : arg.expression; }).forEach(function (arg, index) {
631
+ var _a;
632
+ code += arg.keyword + ": " + (arg === null || arg === void 0 ? void 0 : arg.toJS(translator_1.shiftState(state, code)));
633
+ if (index !== ((_a = _this.arguments) === null || _a === void 0 ? void 0 : _a.length) - 1)
634
+ code += ', ';
635
+ });
636
+ code += '})';
637
+ }
638
+ else {
639
+ code += '(';
640
+ if (Array.isArray(completeArguments) && completeArguments.length) {
641
+ completeArguments.forEach(function (arg, index) {
642
+ code += arg === null || arg === void 0 ? void 0 : arg.toJS(translator_1.shiftState(state, code));
643
+ if (index !== (completeArguments === null || completeArguments === void 0 ? void 0 : completeArguments.length) - 1)
644
+ code += ', ';
645
+ });
646
+ if (calleeNamespace === 'nasl.util' && this.calleeName === 'consoleLog') {
647
+ var arg = this.arguments[0];
648
+ var argTypeAnnotation = arg.typeAnnotation || arg.__TypeAnnotation;
649
+ if (argTypeAnnotation) {
650
+ code += ", '" + (argTypeAnnotation === null || argTypeAnnotation === void 0 ? void 0 : argTypeAnnotation.sortedTypeKey) + "'";
651
+ }
652
+ }
653
+ }
654
+ code += ')';
655
+ }
656
+ }
657
+ function handleMember(root) {
658
+ var _a;
659
+ if (!root)
660
+ return;
661
+ if (root.concept === 'Identifier') {
662
+ return {
663
+ concept: root.concept,
664
+ name: root.name,
665
+ value: root.value,
666
+ expression: root.toJS()
667
+ };
668
+ }
669
+ if (root.concept === 'MemberExpression') {
670
+ var concept_1 = root.concept;
671
+ var value = root.value;
672
+ if ((root === null || root === void 0 ? void 0 : root.object.name) === '_') {
673
+ return {
674
+ concept: concept_1,
675
+ name: root.name,
676
+ value: value,
677
+ object: root.object,
678
+ property: root.property
679
+ };
680
+ }
681
+ var expression = root.toJS();
682
+ if (((_a = root.object) === null || _a === void 0 ? void 0 : _a.namespace) === 'app.enums') {
683
+ value = expression.replace(/^"(.+)"$/, '$1');
684
+ expression = undefined;
685
+ concept_1 = 'StringLiteral';
686
+ }
687
+ return {
688
+ concept: concept_1,
689
+ name: root.name,
690
+ value: value,
691
+ expression: expression
692
+ };
693
+ }
694
+ var left = handleMember(root.left);
695
+ var right = handleMember(root.right);
696
+ return {
697
+ concept: root.concept,
698
+ name: root.name,
699
+ value: root.value,
700
+ expression: root.expression,
701
+ operator: root.operator,
702
+ left: left,
703
+ right: right
704
+ };
705
+ }
706
+ var typeAnnotation = this.typeAnnotation || this.__TypeAnnotation;
707
+ var needGenInitFromSchema = typeAnnotation && (!['primitive', 'union'].includes(typeAnnotation.typeKind)
708
+ || typeAnnotation.typeName === 'DateTime');
709
+ if (needGenInitFromSchema) {
710
+ code = "this.$genInitFromSchema('" + (typeAnnotation === null || typeAnnotation === void 0 ? void 0 : typeAnnotation.sortedTypeKey) + "', " + code + ")";
711
+ }
712
+ return code;
713
+ };
714
+ CallLogic.prototype.toBrief = function () {
715
+ return this.arguments.map(function (a) { return a.toBrief(); }).join('<br />');
716
+ };
717
+ CallLogic.prototype.toEmbeddedTS = function (state) {
718
+ var _this = this;
719
+ var code = this.calleeKey;
720
+ if (Array.isArray(this.typeArguments) && this.typeArguments.length) {
721
+ // 如果有内容
722
+ var typeAnnotation = this.typeArguments[0];
723
+ code += "<";
724
+ code += typeAnnotation.toEmbeddedTS(translator_1.shiftState(state, code, { tabSize: 0 })) + ">";
725
+ }
726
+ var tsCalleeNamespace = this.tsCalleeNamespace;
727
+ if ((tsCalleeNamespace.startsWith('elements') && tsCalleeNamespace.endsWith('logics')) || tsCalleeNamespace.startsWith('nasl.')) {
728
+ code += '(';
729
+ this.arguments.forEach(function (arg, index) {
730
+ // 页面逻辑先都非必填
731
+ code += arg.toEmbeddedTS(translator_1.shiftState(state, code), false);
732
+ if (index !== _this.arguments.length - 1)
733
+ code += ', ';
734
+ });
735
+ code += ')';
736
+ if (this.parentNode.concept !== 'Argument'
737
+ && this.parentKey !== 'test'
738
+ && this.parentKey !== 'patterns'
739
+ && this.parentNode.concept !== 'Assignment'
740
+ && this.parentNode.concept !== 'ForEachStatement'
741
+ && this.parentNode.concept !== 'SelectMembers'
742
+ && this.parentNode.concept !== 'BinaryExpression'
743
+ && this.parentNode.concept !== 'StringInterpolation'
744
+ && this.parentNode.concept !== 'MemberExpression') {
745
+ code += ';';
746
+ }
747
+ }
748
+ else {
749
+ var completeArguments = this.completeArguments;
750
+ if (completeArguments.length) {
751
+ code += '(';
752
+ completeArguments.forEach(function (arg, index) {
753
+ // 取到是不是必填放入参数中
754
+ code += arg.toEmbeddedTS(translator_1.shiftState(state, code), arg === null || arg === void 0 ? void 0 : arg.paramRequired);
755
+ if (index !== _this.arguments.length - 1)
756
+ code += ', ';
757
+ });
758
+ code += ')';
759
+ if (this.parentNode.concept !== 'Argument'
760
+ && this.parentKey !== 'test'
761
+ && this.parentKey !== 'patterns'
762
+ && this.parentNode.concept !== 'Assignment'
763
+ && this.parentNode.concept !== 'ForEachStatement'
764
+ && this.parentNode.concept !== 'SelectMembers'
765
+ && this.parentNode.concept !== 'BinaryExpression'
766
+ && this.parentNode.concept !== 'StringInterpolation'
767
+ && this.parentNode.concept !== 'MemberExpression') {
768
+ code += ';';
769
+ }
770
+ }
771
+ else {
772
+ code += '()';
773
+ if (this.parentNode.concept !== 'Argument'
774
+ && this.parentKey !== 'test'
775
+ && this.parentKey !== 'patterns'
776
+ && this.parentNode.concept !== 'Assignment'
777
+ && this.parentNode.concept !== 'ForEachStatement'
778
+ && this.parentNode.concept !== 'SelectMembers'
779
+ && this.parentNode.concept !== 'BinaryExpression'
780
+ && this.parentNode.concept !== 'StringInterpolation'
781
+ && this.parentNode.concept !== 'MemberExpression') {
782
+ code += ';';
783
+ }
784
+ }
785
+ }
786
+ return code;
787
+ };
788
+ // 通过内容过去节点
789
+ CallLogic.prototype.getCallNode = function () {
790
+ var _this = this;
791
+ var _a;
792
+ var node;
793
+ // 如果是页面局部逻辑
794
+ if (!this.calleeNamespace && this.calleeName && this.view) {
795
+ node = this.view.logics.find(function (l) { return l.name === _this.calleeName; });
796
+ }
797
+ else if ((_a = this.calleeNamespace) === null || _a === void 0 ? void 0 : _a.startsWith('nasl.')) {
798
+ // 如果是平台类型
799
+ node = utils_1.getNaslNodeByNodeCallee(this.calleeNamespace, this.calleeName);
800
+ }
801
+ else {
802
+ // 如果是其余app下自定义逻辑
803
+ try {
804
+ node = utils_1.getNodeByNodeCallee(this.app, this.calleewholeKey, function (key, tempPoint) {
805
+ // 处理 NASL 中未定义的假的节点
806
+ if (key === tempPoint.name) {
807
+ return {
808
+ tempPoint: tempPoint,
809
+ state: 1
810
+ };
811
+ }
812
+ var t = tempPoint[key];
813
+ return {
814
+ tempPoint: t,
815
+ state: Array.isArray(t) ? 2 : 1
816
+ };
817
+ });
818
+ }
819
+ catch (err) { }
820
+ }
821
+ return node;
822
+ };
823
+ Object.defineProperty(CallLogic.prototype, "completeArguments", {
824
+ // 可以设置默认值的节点
825
+ // 目前只开放了app下的,所以这些节点,查找引用吧默认值塞回来
826
+ get: function () {
827
+ var _a;
828
+ var node = this.getCallNode();
829
+ var logicParam = [];
830
+ var Arguments = [];
831
+ if (node) {
832
+ logicParam = node.params;
833
+ }
834
+ if ((_a = this.arguments) === null || _a === void 0 ? void 0 : _a.length) {
835
+ this.arguments.forEach(function (arg, index) {
836
+ var param = logicParam[index] || {};
837
+ // 打开了必填,
838
+ // 或者遗留问题,没有required = undefined 而且没有defaultValue,就是之前的必填项
839
+ arg.paramRequired = Boolean(param.required || (param.required === undefined && !param.defaultValue));
840
+ arg.paramTypeAnnotation = undefined;
841
+ arg.paramDefaultValue = undefined;
842
+ // 取到是不是必填放入参数中
843
+ if (param && !arg.expression) {
844
+ // 非必填时 才会有默认值
845
+ arg.paramTypeAnnotation = param.typeAnnotation;
846
+ arg.paramDefaultValue = param.defaultValue;
847
+ }
848
+ Arguments.push(arg);
849
+ });
850
+ }
851
+ return Arguments;
852
+ },
853
+ enumerable: false,
854
+ configurable: true
855
+ });
856
+ var CallLogic_1;
857
+ __decorate([
858
+ decorators_1.property()
859
+ ], CallLogic.prototype, "concept");
860
+ __decorate([
861
+ decorators_1.property()
862
+ ], CallLogic.prototype, "label");
863
+ __decorate([
864
+ decorators_1.property()
865
+ ], CallLogic.prototype, "calleeNamespace");
866
+ __decorate([
867
+ decorators_1.property()
868
+ ], CallLogic.prototype, "calleeName");
869
+ __decorate([
870
+ decorators_1.property()
871
+ ], CallLogic.prototype, "shortcut");
872
+ __decorate([
873
+ decorators_1.property('TypeAnnotation')
874
+ ], CallLogic.prototype, "typeArguments");
875
+ __decorate([
876
+ decorators_1.property('Argument')
877
+ ], CallLogic.prototype, "arguments");
878
+ __decorate([
879
+ translator_1.withSourceMap()
880
+ ], CallLogic.prototype, "toEmbeddedTS");
881
+ CallLogic = CallLogic_1 = __decorate([
882
+ decorators_1.concept('调用逻辑')
883
+ ], CallLogic);
884
+ return CallLogic;
885
+ }(LogicItem__1["default"]));
886
+ exports.CallLogic = CallLogic;
887
+ classMap_1["default"].CallLogic = CallLogic;
888
+ exports["default"] = CallLogic;
889
+ //================================================================================
890
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
891
+ // 自动生成的代码已结束。下面可以手动编写。
892
+ //================================================================================