@lcap/nasl 2.22.1 → 2.22.2

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 (116) hide show
  1. package/out/breakpoint/generator/AfterStartNode.d.ts +7 -0
  2. package/out/breakpoint/generator/AfterStartNode.js +27 -0
  3. package/out/breakpoint/generator/AfterStartNode.js.map +1 -0
  4. package/out/breakpoint/generator/BeforeEndNode.d.ts +7 -0
  5. package/out/breakpoint/generator/BeforeEndNode.js +27 -0
  6. package/out/breakpoint/generator/BeforeEndNode.js.map +1 -0
  7. package/out/breakpoint/generator/BreakpointNode.d.ts +14 -0
  8. package/out/breakpoint/generator/BreakpointNode.js +200 -0
  9. package/out/breakpoint/generator/BreakpointNode.js.map +1 -0
  10. package/out/breakpoint/generator/index.d.ts +4 -0
  11. package/out/breakpoint/generator/index.js +98 -0
  12. package/out/breakpoint/generator/index.js.map +1 -0
  13. package/out/breakpoint/index.d.ts +3 -0
  14. package/out/breakpoint/index.js +20 -0
  15. package/out/breakpoint/index.js.map +1 -0
  16. package/out/breakpoint/shared/constants.d.ts +31 -0
  17. package/out/breakpoint/shared/constants.js +89 -0
  18. package/out/breakpoint/shared/constants.js.map +1 -0
  19. package/out/breakpoint/shared/index.d.ts +3 -0
  20. package/out/breakpoint/shared/index.js +33 -0
  21. package/out/breakpoint/shared/index.js.map +1 -0
  22. package/out/breakpoint/shared/operations.d.ts +10 -0
  23. package/out/breakpoint/shared/operations.js +25 -0
  24. package/out/breakpoint/shared/operations.js.map +1 -0
  25. package/out/breakpoint/shared/socket.d.ts +47 -0
  26. package/out/breakpoint/shared/socket.js +210 -0
  27. package/out/breakpoint/shared/socket.js.map +1 -0
  28. package/out/breakpoint/shared/utils.d.ts +23 -0
  29. package/out/breakpoint/shared/utils.js +165 -0
  30. package/out/breakpoint/shared/utils.js.map +1 -0
  31. package/out/breakpoint/store/core.d.ts +32 -0
  32. package/out/breakpoint/store/core.js +388 -0
  33. package/out/breakpoint/store/core.js.map +1 -0
  34. package/out/breakpoint/store/dock.d.ts +1 -0
  35. package/out/breakpoint/store/dock.js +127 -0
  36. package/out/breakpoint/store/dock.js.map +1 -0
  37. package/out/breakpoint/store/index.d.ts +2 -0
  38. package/out/breakpoint/store/index.js +19 -0
  39. package/out/breakpoint/store/index.js.map +1 -0
  40. package/out/common/asyncFuncMap.d.ts +2 -0
  41. package/out/common/asyncFuncMap.js +16 -0
  42. package/out/common/asyncFuncMap.js.map +1 -0
  43. package/out/concepts/AnonymousFunction__.js +1 -1
  44. package/out/concepts/AnonymousFunction__.js.map +1 -1
  45. package/out/concepts/AuthInterface__.d.ts +37 -0
  46. package/out/concepts/AuthInterface__.js +141 -0
  47. package/out/concepts/AuthInterface__.js.map +1 -0
  48. package/out/concepts/AuthLogicForCallInterface__.d.ts +138 -0
  49. package/out/concepts/AuthLogicForCallInterface__.js +493 -0
  50. package/out/concepts/AuthLogicForCallInterface__.js.map +1 -0
  51. package/out/concepts/AuthLogic__.d.ts +66 -0
  52. package/out/concepts/AuthLogic__.js +206 -0
  53. package/out/concepts/AuthLogic__.js.map +1 -0
  54. package/out/concepts/BackendVariable__.d.ts +137 -0
  55. package/out/concepts/BackendVariable__.js +422 -0
  56. package/out/concepts/BackendVariable__.js.map +1 -0
  57. package/out/concepts/Backend__.d.ts +134 -0
  58. package/out/concepts/Backend__.js +274 -0
  59. package/out/concepts/Backend__.js.map +1 -0
  60. package/out/concepts/CallAuthInterface__.d.ts +126 -0
  61. package/out/concepts/CallAuthInterface__.js +408 -0
  62. package/out/concepts/CallAuthInterface__.js.map +1 -0
  63. package/out/concepts/Destination__.js +6 -4
  64. package/out/concepts/Destination__.js.map +1 -1
  65. package/out/concepts/FrontendVariable__.d.ts +21 -0
  66. package/out/concepts/FrontendVariable__.js +64 -0
  67. package/out/concepts/FrontendVariable__.js.map +1 -0
  68. package/out/concepts/Match__.js +25 -6
  69. package/out/concepts/Match__.js.map +1 -1
  70. package/out/concepts/OverriddenLogic__.d.ts +643 -0
  71. package/out/concepts/OverriddenLogic__.js +1602 -0
  72. package/out/concepts/OverriddenLogic__.js.map +1 -0
  73. package/out/concepts/Param__.js +1 -1
  74. package/out/concepts/Param__.js.map +1 -1
  75. package/out/concepts/basics/stdlib/nasl.http.d.ts +7 -0
  76. package/out/concepts/basics/stdlib/nasl.http.js +167 -0
  77. package/out/concepts/basics/stdlib/nasl.http.js.map +1 -0
  78. package/out/server/naslServer.js +4 -0
  79. package/out/server/naslServer.js.map +1 -1
  80. package/out/service/creator/errHandles.js +5 -0
  81. package/out/service/creator/errHandles.js.map +1 -1
  82. package/out/templator/genCreateBlock.js +2 -1
  83. package/out/templator/genCreateBlock.js.map +1 -1
  84. package/out/templator/genCurdEditMultipleKeyBlock.js +6 -3
  85. package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
  86. package/out/templator/genCurdMultipleKeyBlock.js +4 -2
  87. package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
  88. package/out/templator/genEditTableBlock.js +2 -1
  89. package/out/templator/genEditTableBlock.js.map +1 -1
  90. package/out/templator/genUpdateBlock.js +2 -1
  91. package/out/templator/genUpdateBlock.js.map +1 -1
  92. package/package.json +2 -2
  93. package/src/concepts/AnonymousFunction__.ts +1 -1
  94. package/src/concepts/Destination__.ts +7 -5
  95. package/src/concepts/Match__.ts +24 -6
  96. package/src/concepts/Param__.ts +1 -1
  97. package/src/concepts/dist/App__.js +2204 -0
  98. package/src/concepts/dist/CallLogic__.js +1149 -0
  99. package/src/concepts/dist/Destination__.js +756 -0
  100. package/src/concepts/dist/Logic__.js +1612 -0
  101. package/src/concepts/dist/Match__.js +768 -0
  102. package/src/concepts/dist/MsgTriggerEvent__.js +245 -0
  103. package/src/concepts/dist/OqlQueryComponent__.js +377 -0
  104. package/src/concepts/dist/Param__.js +1 -1
  105. package/src/generator/dist/genBundleFiles.js +15 -4
  106. package/src/generator/dist/genReleaseBody.js +501 -0
  107. package/src/server/dist/naslServer.js +25 -6
  108. package/src/server/naslServer.ts +4 -0
  109. package/src/service/creator/errHandles.js +8 -3
  110. package/src/service/storage/dist/init.js +34 -32
  111. package/src/templator/genCreateBlock.ts +2 -1
  112. package/src/templator/genCurdEditMultipleKeyBlock.ts +6 -3
  113. package/src/templator/genCurdMultipleKeyBlock.ts +4 -2
  114. package/src/templator/genEditTableBlock.ts +2 -1
  115. package/src/templator/genUpdateBlock.ts +2 -1
  116. package/test/examples/qzbusiness.json +1 -98265
@@ -0,0 +1,768 @@
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
33
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
34
+ return new (P || (P = Promise))(function (resolve, reject) {
35
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
36
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
37
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
38
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
39
+ });
40
+ };
41
+ var __generator = (this && this.__generator) || function (thisArg, body) {
42
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
43
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
44
+ function verb(n) { return function (v) { return step([n, v]); }; }
45
+ function step(op) {
46
+ if (f) throw new TypeError("Generator is already executing.");
47
+ while (_) try {
48
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
49
+ if (y = 0, t) op = [op[0] & 2, t.value];
50
+ switch (op[0]) {
51
+ case 0: case 1: t = op; break;
52
+ case 4: _.label++; return { value: op[1], done: false };
53
+ case 5: _.label++; y = op[1]; op = [0]; continue;
54
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
55
+ default:
56
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
57
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
58
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
59
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
60
+ if (t[2]) _.ops.pop();
61
+ _.trys.pop(); continue;
62
+ }
63
+ op = body.call(thisArg, _);
64
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
65
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
66
+ }
67
+ };
68
+ exports.__esModule = true;
69
+ exports.Match = void 0;
70
+ var translator_1 = require("../translator");
71
+ var TypeAnnotation__1 = require("./TypeAnnotation__");
72
+ var BooleanLiteral__1 = require("./BooleanLiteral__");
73
+ var MemberExpression__1 = require("./MemberExpression__");
74
+ var getMemberIdentifier_1 = require("../server/getMemberIdentifier");
75
+ var Identifier__1 = require("./Identifier__");
76
+ var decorators_1 = require("../decorators");
77
+ var classMap_1 = require("../common/classMap");
78
+ var LogicItem__1 = require("./LogicItem__");
79
+ var MatchCase__1 = require("./MatchCase__");
80
+ /**
81
+ * 匹配
82
+ */
83
+ var Match = /** @class */ (function (_super) {
84
+ __extends(Match, _super);
85
+ /**
86
+ * @param source 需要合并的部分参数
87
+ */
88
+ function Match(source) {
89
+ var _this = this;
90
+ source = Object.assign({}, Match_1.getDefaultOptions(), source);
91
+ _this = _super.call(this, source) || this;
92
+ /**
93
+ * 产品概念
94
+ */
95
+ _this.concept = 'Match';
96
+ /**
97
+ * 逻辑项
98
+ */
99
+ _this.expression = undefined;
100
+ /**
101
+ * 是否表达式形态
102
+ */
103
+ _this.isExpression = false;
104
+ /**
105
+ * 匹配分支列表
106
+ */
107
+ _this.cases = [];
108
+ _super.prototype.subConstructor.call(_this, source);
109
+ return _this;
110
+ }
111
+ Match_1 = Match;
112
+ Match.prototype.getClassName = function () {
113
+ return 'Match';
114
+ };
115
+ Match.from = function (source, parentNode, parentKey) {
116
+ return _super.from.call(this, source, parentNode, parentKey);
117
+ };
118
+ Match.prototype._insertMatchCaseAt = function (options, index) {
119
+ var matchCaseOptions = {};
120
+ var relationOptions = { parentNode: this, parentKey: 'cases' };
121
+ var matchCase;
122
+ if (options instanceof MatchCase__1["default"]) {
123
+ options.ensureDelete(); // 同一实例不支持多处存在
124
+ matchCase = options;
125
+ Object.assign(matchCase, relationOptions);
126
+ }
127
+ else {
128
+ matchCase = MatchCase__1["default"].from(__assign(__assign({}, matchCaseOptions), options), this, 'cases');
129
+ }
130
+ this.cases.splice(index, 0, matchCase);
131
+ return matchCase;
132
+ };
133
+ Match.prototype.insertMatchCaseAt = function (options, index) {
134
+ var node = this._insertMatchCaseAt(options, index);
135
+ node.create({
136
+ index: index,
137
+ parentNode: this,
138
+ parentKey: 'cases'
139
+ });
140
+ return node;
141
+ };
142
+ Match.prototype._addMatchCase = function (options) {
143
+ var index = this.cases.length;
144
+ return this._insertMatchCaseAt(options, index);
145
+ };
146
+ Match.prototype.addMatchCase = function (options) {
147
+ var node = this._addMatchCase(options);
148
+ var index = this.cases.indexOf(node);
149
+ node.create({
150
+ index: index,
151
+ parentNode: this,
152
+ parentKey: 'cases'
153
+ });
154
+ return node;
155
+ };
156
+ Match.prototype.removeExpression = function (options) {
157
+ var expression;
158
+ if (typeof options === 'string') {
159
+ expression = this.expression;
160
+ if (!expression) {
161
+ throw new Error('找不到逻辑项 ' + options);
162
+ }
163
+ }
164
+ else {
165
+ expression = options;
166
+ }
167
+ return expression["delete"]();
168
+ };
169
+ Match.prototype.removeMatchCaseInCases = function (options) {
170
+ var matchCase = options;
171
+ return matchCase["delete"]();
172
+ };
173
+ Match.prototype.__removeLogicItem = function (logicItem) {
174
+ var parentKey = logicItem.parentKey;
175
+ var params = {
176
+ parentNode: this,
177
+ parentKey: parentKey,
178
+ index: -1,
179
+ object: null,
180
+ oldObject: logicItem
181
+ };
182
+ if (parentKey) {
183
+ params.parentKey = parentKey;
184
+ if (Array.isArray(this[parentKey])) {
185
+ var index = this[parentKey].indexOf(logicItem);
186
+ ~index && this[parentKey].splice(index, 1);
187
+ params.index = index;
188
+ }
189
+ else if (this[parentKey] === logicItem) {
190
+ params.index = 0;
191
+ this[parentKey] = undefined;
192
+ }
193
+ }
194
+ return params;
195
+ };
196
+ Object.defineProperty(Match.prototype, "isEnumerable", {
197
+ get: function () {
198
+ var _a;
199
+ return !!((_a = this.enumerableItems) === null || _a === void 0 ? void 0 : _a.length);
200
+ },
201
+ enumerable: false,
202
+ configurable: true
203
+ });
204
+ Match.prototype.cacheStatus = function () {
205
+ return __awaiter(this, void 0, void 0, function () {
206
+ var _a;
207
+ return __generator(this, function (_b) {
208
+ switch (_b.label) {
209
+ case 0:
210
+ _a = this;
211
+ return [4 /*yield*/, this.getEnumerableItems()];
212
+ case 1:
213
+ _a.enumerableItems = _b.sent();
214
+ return [2 /*return*/];
215
+ }
216
+ });
217
+ });
218
+ };
219
+ Object.defineProperty(Match.prototype, "canAddCase", {
220
+ /**
221
+ * 是否允许新建case
222
+ */
223
+ get: function () {
224
+ var cases = this === null || this === void 0 ? void 0 : this.cases;
225
+ if (Array.isArray(cases) && cases.length > 1) {
226
+ var enumerableItems = this.enumerableItems;
227
+ if (Array.isArray(enumerableItems)) {
228
+ var map_1 = {};
229
+ cases.forEach(function (caseItem) {
230
+ var patterns = (caseItem || {}).patterns;
231
+ if (Array.isArray(patterns)) {
232
+ patterns.forEach(function (pattern) {
233
+ if (pattern instanceof TypeAnnotation__1["default"]) {
234
+ var patternTypeKey = pattern.typeKey;
235
+ map_1[patternTypeKey] = true;
236
+ }
237
+ else if (pattern instanceof MemberExpression__1["default"] || pattern instanceof BooleanLiteral__1["default"]) {
238
+ var patternValue = pattern.getValue();
239
+ map_1[patternValue] = true;
240
+ }
241
+ });
242
+ }
243
+ });
244
+ var enumerableKeys = Object.keys(map_1);
245
+ if (enumerableKeys.length === enumerableItems.length) {
246
+ return false;
247
+ }
248
+ }
249
+ }
250
+ return true;
251
+ },
252
+ enumerable: false,
253
+ configurable: true
254
+ });
255
+ // 获取可枚举项
256
+ Match.prototype.getEnumerableItems = function (typeAnnotation) {
257
+ return __awaiter(this, void 0, void 0, function () {
258
+ var expression, currTypeAnnotation, _a, typeKind, typeNamespace, typeName, typeArguments, nameArr, typeNode, enums, children;
259
+ return __generator(this, function (_b) {
260
+ switch (_b.label) {
261
+ case 0:
262
+ expression = this.expression;
263
+ currTypeAnnotation = typeAnnotation;
264
+ if (!!currTypeAnnotation) return [3 /*break*/, 2];
265
+ return [4 /*yield*/, (expression === null || expression === void 0 ? void 0 : expression.getCurrentTypeAnnotation())];
266
+ case 1:
267
+ currTypeAnnotation = _b.sent();
268
+ _b.label = 2;
269
+ case 2:
270
+ _a = currTypeAnnotation || {}, typeKind = _a.typeKind, typeNamespace = _a.typeNamespace, typeName = _a.typeName, typeArguments = _a.typeArguments;
271
+ if (typeKind === 'union' && Array.isArray(typeArguments)) {
272
+ return [2 /*return*/, typeArguments.map(function (typeArg) {
273
+ var typeArgJson = typeArg;
274
+ if (typeArg instanceof TypeAnnotation__1["default"]) {
275
+ typeArgJson = typeArg.toJSON();
276
+ }
277
+ return new TypeAnnotation__1["default"](typeArgJson);
278
+ })];
279
+ }
280
+ else if (typeKind === 'reference') {
281
+ nameArr = [typeName];
282
+ if (typeNamespace) {
283
+ nameArr.unshift(typeNamespace);
284
+ }
285
+ typeNode = this.app.findNodeByCompleteName(nameArr.join('.')) || {};
286
+ if (typeNode.concept === 'Enum') {
287
+ enums = getMemberIdentifier_1.formatEnums([typeNode]);
288
+ children = ((enums === null || enums === void 0 ? void 0 : enums[0]) || {}).children;
289
+ if (Array.isArray(children)) {
290
+ return [2 /*return*/, children.map(function (child) { return child === null || child === void 0 ? void 0 : child.expression; })];
291
+ }
292
+ }
293
+ }
294
+ else if (typeKind === 'primitive' && typeNamespace === 'nasl.core' && typeName === 'Boolean') {
295
+ return [2 /*return*/, [
296
+ new BooleanLiteral__1["default"]({
297
+ value: 'true'
298
+ }),
299
+ new BooleanLiteral__1["default"]({
300
+ value: 'false'
301
+ }),
302
+ ]];
303
+ }
304
+ return [2 /*return*/];
305
+ }
306
+ });
307
+ });
308
+ };
309
+ Match.prototype.setIsExpression = function (isExpression) {
310
+ var object = {
311
+ isExpression: isExpression
312
+ };
313
+ this.update(__assign({}, object));
314
+ };
315
+ /**
316
+ * 设置逻辑项
317
+ */
318
+ Match.prototype.setExpression = function (expression) {
319
+ if (expression) {
320
+ expression._delete();
321
+ var relationOptions = { parentNode: this, parentKey: 'expression' };
322
+ Object.assign(expression, relationOptions);
323
+ }
324
+ var object = {
325
+ expression: expression
326
+ };
327
+ this.update(__assign({}, object));
328
+ };
329
+ // 设置 expression ,如果 expression 是可枚举类型,加上默认匹配条件
330
+ Match.prototype.setExpressionWitchCase = function (expression) {
331
+ var _a;
332
+ return __awaiter(this, void 0, void 0, function () {
333
+ var oldExpression;
334
+ return __generator(this, function (_b) {
335
+ switch (_b.label) {
336
+ case 0:
337
+ oldExpression = this.expression;
338
+ this.app.emit('collect:start', {
339
+ actionMsg: "\u4FEE\u6539" + ((this === null || this === void 0 ? void 0 : this.name) || (this === null || this === void 0 ? void 0 : this.label) || ((_a = this === null || this === void 0 ? void 0 : this.constructor) === null || _a === void 0 ? void 0 : _a.nodeTitle))
340
+ });
341
+ this.setExpression(expression);
342
+ // expression切换并且自动生成分支
343
+ return [4 /*yield*/, this.autoGenCases(oldExpression)];
344
+ case 1:
345
+ // expression切换并且自动生成分支
346
+ _b.sent();
347
+ this.app.emit('collect:end');
348
+ return [2 /*return*/];
349
+ }
350
+ });
351
+ });
352
+ };
353
+ // 自动生成分支
354
+ Match.prototype.autoGenCases = function (oldExpression) {
355
+ return __awaiter(this, void 0, void 0, function () {
356
+ var expression, oldTypeAnnotation, currTypeAnnotation, oldTypeName, oldTypeNamespace, oldTypeKind, typeName, typeNamespace, typeKind;
357
+ return __generator(this, function (_a) {
358
+ switch (_a.label) {
359
+ case 0:
360
+ expression = this.expression;
361
+ // 没有新的expression要保留分支不去更新
362
+ if (!expression) {
363
+ return [2 /*return*/];
364
+ }
365
+ // 如果没有旧的oldExpression, 但是已有就分支了,就不去更新了
366
+ if (!oldExpression && this.cases.length) {
367
+ // 而且case的 patterns 有长度,就说明里面是有值的,就不去更新了,其余就去更新
368
+ if (this.cases.some(function (item) { return item.patterns.length; })) {
369
+ return [2 /*return*/];
370
+ }
371
+ }
372
+ // 如果新旧nasl一样,就算类型变了也不重新计算
373
+ if (JSON.stringify(oldExpression === null || oldExpression === void 0 ? void 0 : oldExpression.toJSON()) === JSON.stringify(expression === null || expression === void 0 ? void 0 : expression.toJSON())) {
374
+ return [2 /*return*/];
375
+ }
376
+ oldTypeAnnotation = oldExpression === null || oldExpression === void 0 ? void 0 : oldExpression.__TypeAnnotation;
377
+ return [4 /*yield*/, (expression === null || expression === void 0 ? void 0 : expression.getCurrentTypeAnnotation())];
378
+ case 1:
379
+ currTypeAnnotation = _a.sent();
380
+ // 如果nasl变了,但是新旧类型都是union就return
381
+ if ((currTypeAnnotation === null || currTypeAnnotation === void 0 ? void 0 : currTypeAnnotation.typeKind) === 'union' && (oldTypeAnnotation === null || oldTypeAnnotation === void 0 ? void 0 : oldTypeAnnotation.typeKind) === 'union') {
382
+ return [2 /*return*/];
383
+ }
384
+ // 如果不可枚举 变 不可枚举,都会保留分支
385
+ // 原来不是 布尔类型 也不是枚举类型, 现在 也不是布尔类型 也不是枚举类型
386
+ // 就满足了
387
+ if (expression && oldExpression && currTypeAnnotation && oldTypeAnnotation) {
388
+ oldTypeName = oldTypeAnnotation.typeName, oldTypeNamespace = oldTypeAnnotation.typeNamespace, oldTypeKind = oldTypeAnnotation.typeKind;
389
+ typeName = currTypeAnnotation.typeName, typeNamespace = currTypeAnnotation.typeNamespace, typeKind = currTypeAnnotation.typeKind;
390
+ // 类型的 name 和 namespace都有值,而且都不是 可枚举
391
+ if (oldTypeName && oldTypeNamespace && typeName && typeNamespace && oldTypeName !== 'Boolean' && !oldTypeNamespace.endsWith('enums') && oldTypeKind !== 'union' && typeName !== 'Boolean' && !typeNamespace.endsWith('enums') && typeKind !== 'union') {
392
+ return [2 /*return*/];
393
+ }
394
+ else if (oldTypeName && oldTypeNamespace && oldTypeName !== 'Boolean' && !oldTypeNamespace.endsWith('enums') && oldTypeKind !== 'union' && typeKind === 'anonymousStructure') {
395
+ /**
396
+ * 新旧都是匿名数据结构
397
+ * 匿名到 可枚举 动
398
+ * 可枚举到匿名 动
399
+ * 匿名到 不可枚举 不动
400
+ * 不可枚举到匿名 不动
401
+ * 匿名到匿名 不动
402
+ * 因为不能在match上不能直接 匿名数据结构替换匿名数据结构
403
+ * 而且 匿名数据结构不能 直接换别的分支,所以下面的直留 不可枚举到匿名数据结构的情况
404
+ * */
405
+ // 不可枚举到匿名 不动
406
+ return [2 /*return*/];
407
+ }
408
+ else if ((typeKind === 'anonymousStructure' && oldTypeKind === typeKind)) {
409
+ // 匿名到匿名 不动
410
+ return [2 /*return*/];
411
+ }
412
+ // else if (currTypeName && typeNamespace && currTypeName !== 'Boolean' && !typeNamespace.endsWith('enums') && oldTypeKind === 'anonymousStructure') {
413
+ // // 匿名到 不可枚举 不动
414
+ // return;
415
+ // }
416
+ }
417
+ // 修改分支
418
+ return [4 /*yield*/, this.changeGenCases()];
419
+ case 2:
420
+ // 修改分支
421
+ _a.sent();
422
+ return [2 /*return*/];
423
+ }
424
+ });
425
+ });
426
+ };
427
+ // jflow缓存模式下的传过来参数
428
+ Match.prototype.autoGenCasesAST = function (_a) {
429
+ var oldAst = _a.oldAst, cacheType = _a.cacheType;
430
+ return __awaiter(this, void 0, void 0, function () {
431
+ var obj, oldExpression;
432
+ return __generator(this, function (_b) {
433
+ switch (_b.label) {
434
+ case 0:
435
+ try {
436
+ obj = JSON.parse(oldAst);
437
+ }
438
+ catch (err) {
439
+ }
440
+ oldExpression = LogicItem__1["default"].from(obj);
441
+ oldExpression.__TypeAnnotation = cacheType;
442
+ return [4 /*yield*/, this.autoGenCases(oldExpression)];
443
+ case 1:
444
+ _b.sent();
445
+ return [2 /*return*/];
446
+ }
447
+ });
448
+ });
449
+ };
450
+ Match.prototype.changeGenCases = function () {
451
+ return __awaiter(this, void 0, void 0, function () {
452
+ var expression, currTypeAnnotation, cases, isMatchedTypeEnumable, enumerableItems, bodys, lastCaseBody, otherCase;
453
+ var _this = this;
454
+ return __generator(this, function (_a) {
455
+ switch (_a.label) {
456
+ case 0:
457
+ expression = this.expression;
458
+ return [4 /*yield*/, (expression === null || expression === void 0 ? void 0 : expression.getCurrentTypeAnnotation())];
459
+ case 1:
460
+ currTypeAnnotation = _a.sent();
461
+ cases = [];
462
+ isMatchedTypeEnumable = false;
463
+ if (!currTypeAnnotation) return [3 /*break*/, 3];
464
+ cases = [new MatchCase__1["default"]()];
465
+ return [4 /*yield*/, this.getEnumerableItems()];
466
+ case 2:
467
+ enumerableItems = _a.sent();
468
+ if (Array.isArray(enumerableItems) && enumerableItems.length) {
469
+ isMatchedTypeEnumable = true;
470
+ cases = enumerableItems.map(function (enumerableItem) { return new MatchCase__1["default"]({
471
+ patterns: [enumerableItem],
472
+ isMatchedTypeEnumable: isMatchedTypeEnumable
473
+ }); });
474
+ }
475
+ _a.label = 3;
476
+ case 3:
477
+ bodys = [];
478
+ if (Array.isArray(this.cases) && this.cases.length) {
479
+ // 将原分支body中存在的内容拿出来
480
+ this.cases.forEach(function (caseItem, index) {
481
+ var body = (caseItem || {}).body;
482
+ if (Array.isArray(body) && body.length) {
483
+ // “其他”分支单独处理
484
+ if (index < _this.cases.length - 1) {
485
+ bodys.push({
486
+ body: body,
487
+ isMatchedTypeEnumable: currTypeAnnotation ? isMatchedTypeEnumable : true
488
+ });
489
+ }
490
+ else {
491
+ lastCaseBody = body;
492
+ }
493
+ }
494
+ });
495
+ // 将原分支body中存在的内容拿出来赋到新的分支中去
496
+ bodys.forEach(function (_a, index) {
497
+ var body = _a.body, isMatchedTypeEnumable = _a.isMatchedTypeEnumable;
498
+ var caseItem = cases[index];
499
+ if (!caseItem) {
500
+ caseItem = new MatchCase__1["default"]({
501
+ isMatchedTypeEnumable: isMatchedTypeEnumable
502
+ });
503
+ cases.push(caseItem);
504
+ }
505
+ caseItem.update({
506
+ body: body
507
+ });
508
+ });
509
+ }
510
+ // 如果分支项存在时,加上“其他”项
511
+ if (cases.length) {
512
+ otherCase = new MatchCase__1["default"]();
513
+ // “其他”项body存在内容时,给新的分支上加上内容
514
+ if (lastCaseBody) {
515
+ otherCase.update({
516
+ body: lastCaseBody
517
+ });
518
+ }
519
+ cases.push(otherCase);
520
+ }
521
+ this.update({
522
+ cases: cases
523
+ });
524
+ return [2 /*return*/];
525
+ }
526
+ });
527
+ });
528
+ };
529
+ Match.getDefaultOptions = function () {
530
+ return {
531
+ label: '匹配'
532
+ };
533
+ };
534
+ Match.prototype.isTypeMatching = function () {
535
+ return __awaiter(this, void 0, void 0, function () {
536
+ var typeAnnotation, _a, typeKind, typeArguments;
537
+ return __generator(this, function (_b) {
538
+ switch (_b.label) {
539
+ case 0:
540
+ if (!this.expression) return [3 /*break*/, 2];
541
+ return [4 /*yield*/, this.expression.getCurrentTypeAnnotation()];
542
+ case 1:
543
+ typeAnnotation = _b.sent();
544
+ _a = typeAnnotation || {}, typeKind = _a.typeKind, typeArguments = _a.typeArguments;
545
+ if (typeKind === 'union' && Array.isArray(typeArguments)) {
546
+ return [2 /*return*/, true];
547
+ }
548
+ _b.label = 2;
549
+ case 2: return [2 /*return*/, false];
550
+ }
551
+ });
552
+ });
553
+ };
554
+ Match.prototype.onChange = function ($event) {
555
+ var _a, _b;
556
+ var _c = $event || {}, action = _c.action, object = _c.object, eventList = _c.eventList;
557
+ // expression修改时,通知tsserver,让tsserver重新生成ts文件,为了后续能获取expression的类型
558
+ if (action === 'update' && object.hasOwnProperty('expression')) {
559
+ (_b = (_a = this.app) === null || _a === void 0 ? void 0 : _a.naslServer) === null || _b === void 0 ? void 0 : _b.embeddedTSEmitter.emit('change', {
560
+ value: eventList
561
+ });
562
+ }
563
+ this.emit('change', $event);
564
+ };
565
+ Object.defineProperty(Match.prototype, "expressionNameInView", {
566
+ // 获取在页面中的名字
567
+ get: function () {
568
+ var nameList = [];
569
+ var node = this;
570
+ while (node) {
571
+ if (node === this) {
572
+ nameList.unshift('viewMatchExpression');
573
+ }
574
+ else {
575
+ nameList.unshift(node.name);
576
+ }
577
+ if (node.concept === 'ViewElement') {
578
+ node = null;
579
+ }
580
+ else {
581
+ nameList.unshift(node.parentKey);
582
+ node = node.parentNode;
583
+ }
584
+ }
585
+ return nameList.join('_').replace(/-/g, '_');
586
+ },
587
+ enumerable: false,
588
+ configurable: true
589
+ });
590
+ Match.prototype.getViewMatchExpressionBuilder = function () {
591
+ return "gen" + this.expressionNameInView;
592
+ };
593
+ Match.prototype.getInViewMethod = function (state) {
594
+ var viewElement = this === null || this === void 0 ? void 0 : this.getAncestor('ViewElement');
595
+ var argsList = [];
596
+ var parent = viewElement === null || viewElement === void 0 ? void 0 : viewElement.parentNode;
597
+ var index = 0;
598
+ while (parent && parent.concept !== 'View') {
599
+ if (parent.slotScope) {
600
+ argsList.unshift(index === 0 ? 'current' : 'current' + index);
601
+ index++;
602
+ }
603
+ parent = parent.parentNode;
604
+ }
605
+ var code = '';
606
+ code += this.getViewMatchExpressionBuilder() + " (" + argsList.join(', ') + ") {\n";
607
+ code += "return " + this.toJS();
608
+ code += ";\n";
609
+ code += '}';
610
+ return code;
611
+ };
612
+ Match.prototype.toVue = function (state) {
613
+ if ((state === null || state === void 0 ? void 0 : state.finalCode) === false) {
614
+ return this.toUI();
615
+ }
616
+ else {
617
+ var viewElement = this === null || this === void 0 ? void 0 : this.getAncestor('ViewElement');
618
+ var argsList = [];
619
+ var parent = viewElement === null || viewElement === void 0 ? void 0 : viewElement.parentNode;
620
+ var index = 0;
621
+ while (parent && parent.concept !== 'View') {
622
+ if (parent.slotScope) {
623
+ argsList.unshift(index === 0 ? 'current' : 'current' + index);
624
+ index++;
625
+ }
626
+ parent = parent.parentNode;
627
+ }
628
+ return this.getViewMatchExpressionBuilder() + "(" + argsList.join(', ') + ")";
629
+ // let code = 'await (async () => {\n';
630
+ // if (this.expression && Array.isArray(this.cases)) {
631
+ // this.cases.forEach((item, index) => {
632
+ // code += item?.toJS?.(this.expression, index, this.cases.length);
633
+ // });
634
+ // }
635
+ // code += `})()`;
636
+ // return code;
637
+ }
638
+ };
639
+ Match.prototype.toUI = function (state) {
640
+ var _a, _b;
641
+ var code = '匹配 ';
642
+ if (this.expression) {
643
+ code += (_b = (_a = this.expression).toUI) === null || _b === void 0 ? void 0 : _b.call(_a);
644
+ }
645
+ if (Array.isArray(this.cases)) {
646
+ code += ' { ';
647
+ this.cases.forEach(function (item, index) {
648
+ var _a;
649
+ code += (_a = item === null || item === void 0 ? void 0 : item.toUI) === null || _a === void 0 ? void 0 : _a.call(item);
650
+ });
651
+ code += '}';
652
+ }
653
+ return code;
654
+ };
655
+ Match.prototype.toJS = function (state) {
656
+ //let code = 'await (async () => {\n';
657
+ //if (this.expression && Array.isArray(this.cases)) {
658
+ // this.cases.forEach((item, index) => {
659
+ // code += item?.toJS?.(this.expression, index, this.cases.length);
660
+ // });
661
+ //}
662
+ //code += `})()`;
663
+ //return code;
664
+ var _this = this;
665
+ var code = '';
666
+ // 祖先逻辑
667
+ var ancestorLogic = this.getAncestor('Logic');
668
+ if (this.isExpression || !ancestorLogic) {
669
+ if (ancestorLogic) {
670
+ code += 'await (async () => {\n';
671
+ }
672
+ else {
673
+ code += '(() => {\n';
674
+ }
675
+ }
676
+ if (this.expression && Array.isArray(this.cases)) {
677
+ this.cases.forEach(function (item, index) {
678
+ var _a;
679
+ code += (_a = item === null || item === void 0 ? void 0 : item.toJS) === null || _a === void 0 ? void 0 : _a.call(item, _this.expression, index, _this.cases.length);
680
+ });
681
+ }
682
+ if (this.isExpression || !ancestorLogic) {
683
+ code += '})()';
684
+ }
685
+ return code;
686
+ };
687
+ Match.prototype.toEmbeddedTS = function (state) {
688
+ var code = '';
689
+ if (this.parentNode.concept === 'Logic') {
690
+ code += '\n';
691
+ }
692
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0));
693
+ code += '(() => { \n';
694
+ var parentCode;
695
+ if (this.expression) {
696
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0));
697
+ // Identifier会使用自己本身的类型,来推导,因为右侧放的内容关系关系到内部类型推断
698
+ if ((this.expression instanceof Identifier__1["default"]) || (this.expression instanceof MemberExpression__1["default"])) {
699
+ code += parentCode = this.expression.toEmbeddedTS(translator_1.shiftState(state, code));
700
+ }
701
+ else {
702
+ parentCode = '__matchExpression';
703
+ code += "let " + parentCode + " = ";
704
+ code += this.expression.toEmbeddedTS(translator_1.shiftState(state, code));
705
+ }
706
+ code += ';\n';
707
+ }
708
+ else {
709
+ code += '__IDENTIFIER__;\n';
710
+ }
711
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) + 1 || 0));
712
+ code += ' function __MatchExpressionFuntion() {\n';
713
+ // 最后一项是else
714
+ this.cases.forEach(function (item, index) {
715
+ // 如果是最后一项
716
+ code += item.toEmbeddedTS(translator_1.shiftState(state, code, { tabSize: ((state === null || state === void 0 ? void 0 : state.tabSize) || 0) }), index, parentCode);
717
+ });
718
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0));
719
+ code += '};\n';
720
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0));
721
+ code += 'return __MatchExpressionFuntion();\n';
722
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0));
723
+ code += '})()';
724
+ if (this.parentNode.concept !== 'Argument'
725
+ && this.parentKey !== 'test'
726
+ && this.parentKey !== 'patterns'
727
+ && this.parentNode.concept !== 'Assignment'
728
+ && this.parentNode.concept !== 'ForEachStatement'
729
+ && this.parentNode.concept !== 'SelectMembers'
730
+ && this.parentNode.concept !== 'UnaryExpression'
731
+ && this.parentNode.concept !== 'BinaryExpression'
732
+ && this.parentNode.concept !== 'StringInterpolation'
733
+ && this.parentNode.concept !== 'MemberExpression'
734
+ && !['NewMap', 'NewList'].includes(this.parentNode.concept)
735
+ && this.parentKey !== 'returnExpression') {
736
+ code += ';\n';
737
+ }
738
+ return code;
739
+ };
740
+ var Match_1;
741
+ __decorate([
742
+ decorators_1.property()
743
+ ], Match.prototype, "concept");
744
+ __decorate([
745
+ decorators_1.property('LogicItem')
746
+ ], Match.prototype, "expression");
747
+ __decorate([
748
+ decorators_1.property()
749
+ ], Match.prototype, "isExpression");
750
+ __decorate([
751
+ decorators_1.property('MatchCase')
752
+ ], Match.prototype, "cases");
753
+ __decorate([
754
+ translator_1.withSourceMap()
755
+ ], Match.prototype, "toEmbeddedTS");
756
+ Match = Match_1 = __decorate([
757
+ decorators_1.concept('匹配')
758
+ ], Match);
759
+ return Match;
760
+ }(LogicItem__1["default"]));
761
+ exports.Match = Match;
762
+ classMap_1["default"].Match = Match;
763
+ exports["default"] = Match;
764
+ //================================================================================
765
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
766
+ // 自动生成的代码已结束。下面可以手动编写。
767
+ //================================================================================
768
+ // @ts-check