@lcap/nasl 2.22.1 → 2.22.2-beta.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.
- package/out/breakpoint/generator/AfterStartNode.d.ts +7 -0
- package/out/breakpoint/generator/AfterStartNode.js +27 -0
- package/out/breakpoint/generator/AfterStartNode.js.map +1 -0
- package/out/breakpoint/generator/BeforeEndNode.d.ts +7 -0
- package/out/breakpoint/generator/BeforeEndNode.js +27 -0
- package/out/breakpoint/generator/BeforeEndNode.js.map +1 -0
- package/out/breakpoint/generator/BreakpointNode.d.ts +14 -0
- package/out/breakpoint/generator/BreakpointNode.js +200 -0
- package/out/breakpoint/generator/BreakpointNode.js.map +1 -0
- package/out/breakpoint/generator/index.d.ts +4 -0
- package/out/breakpoint/generator/index.js +98 -0
- package/out/breakpoint/generator/index.js.map +1 -0
- package/out/breakpoint/index.d.ts +3 -0
- package/out/breakpoint/index.js +20 -0
- package/out/breakpoint/index.js.map +1 -0
- package/out/breakpoint/shared/constants.d.ts +31 -0
- package/out/breakpoint/shared/constants.js +91 -0
- package/out/breakpoint/shared/constants.js.map +1 -0
- package/out/breakpoint/shared/index.d.ts +3 -0
- package/out/breakpoint/shared/index.js +33 -0
- package/out/breakpoint/shared/index.js.map +1 -0
- package/out/breakpoint/shared/operations.d.ts +10 -0
- package/out/breakpoint/shared/operations.js +25 -0
- package/out/breakpoint/shared/operations.js.map +1 -0
- package/out/breakpoint/shared/socket.d.ts +47 -0
- package/out/breakpoint/shared/socket.js +210 -0
- package/out/breakpoint/shared/socket.js.map +1 -0
- package/out/breakpoint/shared/utils.d.ts +23 -0
- package/out/breakpoint/shared/utils.js +165 -0
- package/out/breakpoint/shared/utils.js.map +1 -0
- package/out/breakpoint/store/core.d.ts +32 -0
- package/out/breakpoint/store/core.js +388 -0
- package/out/breakpoint/store/core.js.map +1 -0
- package/out/breakpoint/store/dock.d.ts +1 -0
- package/out/breakpoint/store/dock.js +127 -0
- package/out/breakpoint/store/dock.js.map +1 -0
- package/out/breakpoint/store/index.d.ts +2 -0
- package/out/breakpoint/store/index.js +19 -0
- package/out/breakpoint/store/index.js.map +1 -0
- package/out/common/Command.js +1 -1
- package/out/common/Command.js.map +1 -1
- package/out/common/asyncFuncMap.d.ts +2 -0
- package/out/common/asyncFuncMap.js +16 -0
- package/out/common/asyncFuncMap.js.map +1 -0
- package/out/concepts/AnonymousFunction__.js +11 -9
- package/out/concepts/AnonymousFunction__.js.map +1 -1
- package/out/concepts/AuthInterface__.d.ts +37 -0
- package/out/concepts/AuthInterface__.js +141 -0
- package/out/concepts/AuthInterface__.js.map +1 -0
- package/out/concepts/AuthLogicForCallInterface__.d.ts +138 -0
- package/out/concepts/AuthLogicForCallInterface__.js +493 -0
- package/out/concepts/AuthLogicForCallInterface__.js.map +1 -0
- package/out/concepts/AuthLogic__.d.ts +66 -0
- package/out/concepts/AuthLogic__.js +206 -0
- package/out/concepts/AuthLogic__.js.map +1 -0
- package/out/concepts/BackendVariable__.d.ts +137 -0
- package/out/concepts/BackendVariable__.js +422 -0
- package/out/concepts/BackendVariable__.js.map +1 -0
- package/out/concepts/Backend__.d.ts +134 -0
- package/out/concepts/Backend__.js +274 -0
- package/out/concepts/Backend__.js.map +1 -0
- package/out/concepts/CallAuthInterface__.d.ts +126 -0
- package/out/concepts/CallAuthInterface__.js +408 -0
- package/out/concepts/CallAuthInterface__.js.map +1 -0
- package/out/concepts/CallConnector__.d.ts +42 -0
- package/out/concepts/CallConnector__.js +198 -0
- package/out/concepts/CallConnector__.js.map +1 -0
- package/out/concepts/ConnectorTrigger__.d.ts +78 -0
- package/out/concepts/ConnectorTrigger__.js +155 -0
- package/out/concepts/ConnectorTrigger__.js.map +1 -0
- package/out/concepts/Connector__.d.ts +464 -0
- package/out/concepts/Connector__.js +698 -0
- package/out/concepts/Connector__.js.map +1 -0
- package/out/concepts/Destination__.js +6 -4
- package/out/concepts/Destination__.js.map +1 -1
- package/out/concepts/FrontendVariable__.d.ts +21 -0
- package/out/concepts/FrontendVariable__.js +64 -0
- package/out/concepts/FrontendVariable__.js.map +1 -0
- package/out/concepts/Match__.js +25 -6
- package/out/concepts/Match__.js.map +1 -1
- package/out/concepts/MsgTriggerEvent__.d.ts +137 -0
- package/out/concepts/MsgTriggerEvent__.js +228 -0
- package/out/concepts/MsgTriggerEvent__.js.map +1 -0
- package/out/concepts/MsgTriggerLauncher__.d.ts +118 -0
- package/out/concepts/MsgTriggerLauncher__.js +204 -0
- package/out/concepts/MsgTriggerLauncher__.js.map +1 -0
- package/out/concepts/OverriddenLogic__.d.ts +643 -0
- package/out/concepts/OverriddenLogic__.js +1602 -0
- package/out/concepts/OverriddenLogic__.js.map +1 -0
- package/out/concepts/Param__.js +1 -1
- package/out/concepts/Param__.js.map +1 -1
- package/out/concepts/StringLiteral__.js +5 -1
- package/out/concepts/StringLiteral__.js.map +1 -1
- package/out/concepts/TriggerEvent__.d.ts +120 -0
- package/out/concepts/TriggerEvent__.js +222 -0
- package/out/concepts/TriggerEvent__.js.map +1 -0
- package/out/concepts/TriggerLauncher__.d.ts +88 -0
- package/out/concepts/TriggerLauncher__.js +235 -0
- package/out/concepts/TriggerLauncher__.js.map +1 -0
- package/out/concepts/basics/stdlib/nasl.http.d.ts +7 -0
- package/out/concepts/basics/stdlib/nasl.http.js +167 -0
- package/out/concepts/basics/stdlib/nasl.http.js.map +1 -0
- package/out/concepts/types__.d.ts +124 -0
- package/out/concepts/types__.js +3 -0
- package/out/concepts/types__.js.map +1 -0
- package/out/server/getConnector.d.ts +11 -0
- package/out/server/getConnector.js +42 -0
- package/out/server/getConnector.js.map +1 -0
- package/out/server/naslServer.js +55 -0
- package/out/server/naslServer.js.map +1 -1
- package/out/service/creator/errHandles.js +5 -0
- package/out/service/creator/errHandles.js.map +1 -1
- package/out/templator/genCreateBlock.js +2 -1
- package/out/templator/genCreateBlock.js.map +1 -1
- package/out/templator/genCurdEditMultipleKeyBlock.js +6 -3
- package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
- package/out/templator/genCurdMultipleKeyBlock.js +4 -2
- package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
- package/out/templator/genEditTableBlock.js +2 -1
- package/out/templator/genEditTableBlock.js.map +1 -1
- package/out/templator/genUpdateBlock.js +2 -1
- package/out/templator/genUpdateBlock.js.map +1 -1
- package/package.json +2 -2
- package/src/common/Command.ts +1 -1
- package/src/common/dist/Command.js +39 -0
- package/src/concepts/AnonymousFunction__.ts +13 -11
- package/src/concepts/Destination__.ts +7 -5
- package/src/concepts/Match__.ts +24 -6
- package/src/concepts/Param__.ts +1 -1
- package/src/concepts/StringLiteral__.ts +5 -1
- package/src/concepts/dist/App__.js +2204 -0
- package/src/concepts/dist/CallLogic__.js +1149 -0
- package/src/concepts/dist/Destination__.js +756 -0
- package/src/concepts/dist/Entity__.js +729 -0
- package/src/concepts/dist/Logic__.js +1612 -0
- package/src/concepts/dist/Match__.js +768 -0
- package/src/concepts/dist/MsgTriggerEvent__.js +245 -0
- package/src/concepts/dist/OqlQueryComponent__.js +377 -0
- package/src/concepts/dist/Param__.js +1 -1
- package/src/concepts/dist/StringLiteral__.js +158 -0
- package/src/generator/dist/genBundleFiles.js +15 -4
- package/src/generator/dist/genReleaseBody.js +501 -0
- package/src/server/dist/naslServer.js +76 -6
- package/src/server/naslServer.ts +54 -0
- package/src/service/creator/errHandles.js +8 -3
- package/src/service/storage/dist/init.js +34 -32
- package/src/templator/genCreateBlock.ts +2 -1
- package/src/templator/genCurdEditMultipleKeyBlock.ts +6 -3
- package/src/templator/genCurdMultipleKeyBlock.ts +4 -2
- package/src/templator/genEditTableBlock.ts +2 -1
- package/src/templator/genUpdateBlock.ts +2 -1
- package/test/examples/qzbusiness.json +1 -98265
|
@@ -0,0 +1,1602 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
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;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
+
if (mod && mod.__esModule) return mod;
|
|
26
|
+
var result = {};
|
|
27
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
+
__setModuleDefault(result, mod);
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
32
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
33
|
+
};
|
|
34
|
+
var OverriddenLogic_1;
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.OverriddenLogic = void 0;
|
|
37
|
+
const FrontendLibrary__1 = require("./FrontendLibrary__");
|
|
38
|
+
const translator_1 = require("../translator");
|
|
39
|
+
const Namespace__1 = __importDefault(require("./Namespace__"));
|
|
40
|
+
const CallQueryComponent__1 = __importDefault(require("./CallQueryComponent__"));
|
|
41
|
+
const Assignment__1 = __importDefault(require("./Assignment__"));
|
|
42
|
+
const Identifier__1 = __importDefault(require("./Identifier__"));
|
|
43
|
+
const BindEvent__1 = __importDefault(require("./BindEvent__"));
|
|
44
|
+
const BatchAssignment__1 = __importDefault(require("./BatchAssignment__"));
|
|
45
|
+
const OqlQueryComponent__1 = __importDefault(require("./OqlQueryComponent__"));
|
|
46
|
+
const TypeAnnotation__1 = __importDefault(require("./TypeAnnotation__"));
|
|
47
|
+
const CallInterface__1 = __importDefault(require("./CallInterface__"));
|
|
48
|
+
const CallLogic__1 = __importDefault(require("./CallLogic__"));
|
|
49
|
+
const decorators_1 = require("../decorators");
|
|
50
|
+
const utils = __importStar(require("../utils"));
|
|
51
|
+
const BaseNode_1 = __importDefault(require("../common/BaseNode"));
|
|
52
|
+
const classMap_1 = __importDefault(require("../common/classMap"));
|
|
53
|
+
const Transactional__1 = __importDefault(require("./Transactional__"));
|
|
54
|
+
const TypeParam__1 = __importDefault(require("./TypeParam__"));
|
|
55
|
+
const Param__1 = __importDefault(require("./Param__"));
|
|
56
|
+
const Return__1 = __importDefault(require("./Return__"));
|
|
57
|
+
const Variable__1 = __importDefault(require("./Variable__"));
|
|
58
|
+
const LogicItem__1 = __importDefault(require("./LogicItem__"));
|
|
59
|
+
const Process__1 = __importDefault(require("./Process__"));
|
|
60
|
+
/**
|
|
61
|
+
* 逻辑
|
|
62
|
+
*/
|
|
63
|
+
let OverriddenLogic = OverriddenLogic_1 = class OverriddenLogic extends BaseNode_1.default {
|
|
64
|
+
/**
|
|
65
|
+
* 产品概念
|
|
66
|
+
*/
|
|
67
|
+
concept = 'OverriddenLogic';
|
|
68
|
+
/**
|
|
69
|
+
* overriddenModule
|
|
70
|
+
*/
|
|
71
|
+
overriddenModule = undefined;
|
|
72
|
+
/**
|
|
73
|
+
* 逻辑名称
|
|
74
|
+
*/
|
|
75
|
+
name = undefined;
|
|
76
|
+
/**
|
|
77
|
+
* 逻辑描述
|
|
78
|
+
*/
|
|
79
|
+
description = undefined;
|
|
80
|
+
/**
|
|
81
|
+
* triggerType
|
|
82
|
+
*/
|
|
83
|
+
triggerType = undefined;
|
|
84
|
+
/**
|
|
85
|
+
* cron
|
|
86
|
+
*/
|
|
87
|
+
cron = undefined;
|
|
88
|
+
/**
|
|
89
|
+
* 事务
|
|
90
|
+
*/
|
|
91
|
+
transactional = undefined;
|
|
92
|
+
/**
|
|
93
|
+
* 编译器信息
|
|
94
|
+
*/
|
|
95
|
+
compilerInfoMap = undefined;
|
|
96
|
+
/**
|
|
97
|
+
* 类型参数列表
|
|
98
|
+
*/
|
|
99
|
+
typeParams = null;
|
|
100
|
+
/**
|
|
101
|
+
* 输入参数列表
|
|
102
|
+
*/
|
|
103
|
+
params = [];
|
|
104
|
+
/**
|
|
105
|
+
* 输出参数列表
|
|
106
|
+
*/
|
|
107
|
+
returns = [];
|
|
108
|
+
/**
|
|
109
|
+
* 变量列表
|
|
110
|
+
*/
|
|
111
|
+
variables = [];
|
|
112
|
+
/**
|
|
113
|
+
* 逻辑项列表
|
|
114
|
+
*/
|
|
115
|
+
body = [];
|
|
116
|
+
/**
|
|
117
|
+
* 逻辑项列表
|
|
118
|
+
*/
|
|
119
|
+
playground = [];
|
|
120
|
+
/**
|
|
121
|
+
* 祖先 Module
|
|
122
|
+
*/
|
|
123
|
+
get module() {
|
|
124
|
+
return this.getAncestor('Module');
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* 祖先 App
|
|
128
|
+
*/
|
|
129
|
+
get app() {
|
|
130
|
+
return this.getAncestor('App');
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* 祖先 View
|
|
134
|
+
*/
|
|
135
|
+
get view() {
|
|
136
|
+
return this.getAncestor('View');
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* 祖先 Frontend
|
|
140
|
+
*/
|
|
141
|
+
get frontend() {
|
|
142
|
+
return this.getAncestor('Frontend');
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* 祖先 ProcessElement
|
|
146
|
+
*/
|
|
147
|
+
get processElement() {
|
|
148
|
+
return this.getAncestor('ProcessElement');
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* 祖先 Process
|
|
152
|
+
*/
|
|
153
|
+
get process() {
|
|
154
|
+
return this.getAncestor('Process');
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* @param source 需要合并的部分参数
|
|
158
|
+
*/
|
|
159
|
+
constructor(source) {
|
|
160
|
+
source = Object.assign({}, OverriddenLogic_1.getDefaultOptions(), source);
|
|
161
|
+
super(source);
|
|
162
|
+
super.subConstructor(source);
|
|
163
|
+
}
|
|
164
|
+
getClassName() {
|
|
165
|
+
return 'OverriddenLogic';
|
|
166
|
+
}
|
|
167
|
+
static from(source, parentNode, parentKey) {
|
|
168
|
+
return super.from(source, parentNode, parentKey);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* 从父级删除该节点
|
|
172
|
+
* @internal
|
|
173
|
+
*/
|
|
174
|
+
_delete() {
|
|
175
|
+
let params = null;
|
|
176
|
+
if (this.parentNode) {
|
|
177
|
+
params = this.parentNode?.__removeOverriddenLogic?.(this);
|
|
178
|
+
}
|
|
179
|
+
return params;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* 设置overriddenModule
|
|
183
|
+
*/
|
|
184
|
+
setOverriddenModule(overriddenModule) {
|
|
185
|
+
const object = {
|
|
186
|
+
overriddenModule,
|
|
187
|
+
};
|
|
188
|
+
this.update({
|
|
189
|
+
...object,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* 设置逻辑名称
|
|
194
|
+
*/
|
|
195
|
+
setName(name) {
|
|
196
|
+
const object = {
|
|
197
|
+
name,
|
|
198
|
+
};
|
|
199
|
+
this.update({
|
|
200
|
+
...object,
|
|
201
|
+
field: 'name',
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* 设置逻辑描述
|
|
206
|
+
*/
|
|
207
|
+
setDescription(description) {
|
|
208
|
+
const object = {
|
|
209
|
+
description,
|
|
210
|
+
};
|
|
211
|
+
this.update({
|
|
212
|
+
...object,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* 设置triggerType
|
|
217
|
+
*/
|
|
218
|
+
setTriggerType(triggerType) {
|
|
219
|
+
const object = {
|
|
220
|
+
triggerType,
|
|
221
|
+
};
|
|
222
|
+
this.update({
|
|
223
|
+
...object,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* 设置cron
|
|
228
|
+
*/
|
|
229
|
+
setCron(cron) {
|
|
230
|
+
const object = {
|
|
231
|
+
cron,
|
|
232
|
+
};
|
|
233
|
+
this.update({
|
|
234
|
+
...object,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* 设置事务
|
|
239
|
+
*/
|
|
240
|
+
setTransactional(transactional) {
|
|
241
|
+
transactional._delete();
|
|
242
|
+
const relationOptions = { parentNode: this, parentKey: 'transactional' };
|
|
243
|
+
Object.assign(transactional, relationOptions);
|
|
244
|
+
const object = {
|
|
245
|
+
transactional,
|
|
246
|
+
};
|
|
247
|
+
this.update({
|
|
248
|
+
...object,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
getTypeParamExistingNames(excludedList = []) {
|
|
252
|
+
const excludedSet = new Set(excludedList);
|
|
253
|
+
return (this.typeParams || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
|
|
254
|
+
}
|
|
255
|
+
getTypeParamUniqueName(name = 'typeParam1') {
|
|
256
|
+
return utils.unique(name, this.getTypeParamExistingNames(), undefined, false);
|
|
257
|
+
}
|
|
258
|
+
_insertTypeParamAt(options, index) {
|
|
259
|
+
const typeParamOptions = {};
|
|
260
|
+
const relationOptions = { parentNode: this, parentKey: 'typeParams' };
|
|
261
|
+
let typeParam;
|
|
262
|
+
if (!options) {
|
|
263
|
+
typeParam = TypeParam__1.default.from({
|
|
264
|
+
...typeParamOptions,
|
|
265
|
+
name: this.getTypeParamUniqueName(),
|
|
266
|
+
}, this, 'typeParams');
|
|
267
|
+
}
|
|
268
|
+
else if (typeof options === 'string') {
|
|
269
|
+
typeParam = TypeParam__1.default.from({
|
|
270
|
+
...typeParamOptions,
|
|
271
|
+
name: options,
|
|
272
|
+
}, this, 'typeParams');
|
|
273
|
+
}
|
|
274
|
+
else if (options instanceof TypeParam__1.default) {
|
|
275
|
+
options.ensureDelete(); // 同一实例不支持多处存在
|
|
276
|
+
typeParam = options;
|
|
277
|
+
Object.assign(typeParam, relationOptions);
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
typeParam = TypeParam__1.default.from({
|
|
281
|
+
...typeParamOptions,
|
|
282
|
+
...options,
|
|
283
|
+
}, this, 'typeParams');
|
|
284
|
+
}
|
|
285
|
+
this.typeParams.splice(index, 0, typeParam);
|
|
286
|
+
return typeParam;
|
|
287
|
+
}
|
|
288
|
+
insertTypeParamAt(options, index) {
|
|
289
|
+
const node = this._insertTypeParamAt(options, index);
|
|
290
|
+
node.create({
|
|
291
|
+
index,
|
|
292
|
+
parentNode: this,
|
|
293
|
+
parentKey: 'typeParams',
|
|
294
|
+
});
|
|
295
|
+
return node;
|
|
296
|
+
}
|
|
297
|
+
_addTypeParam(options) {
|
|
298
|
+
const index = this.typeParams.length;
|
|
299
|
+
return this._insertTypeParamAt(options, index);
|
|
300
|
+
}
|
|
301
|
+
addTypeParam(options) {
|
|
302
|
+
const node = this._addTypeParam(options);
|
|
303
|
+
const index = this.typeParams.indexOf(node);
|
|
304
|
+
node.create({
|
|
305
|
+
index,
|
|
306
|
+
parentNode: this,
|
|
307
|
+
parentKey: 'typeParams',
|
|
308
|
+
});
|
|
309
|
+
return node;
|
|
310
|
+
}
|
|
311
|
+
getParamUniqueName(name = 'param1') {
|
|
312
|
+
return utils.unique(name, this.getVarExistingNames(), undefined, false);
|
|
313
|
+
}
|
|
314
|
+
_insertParamAt(options, index) {
|
|
315
|
+
const paramOptions = {};
|
|
316
|
+
const relationOptions = { parentNode: this, parentKey: 'params' };
|
|
317
|
+
let param;
|
|
318
|
+
if (!options) {
|
|
319
|
+
param = Param__1.default.from({
|
|
320
|
+
...paramOptions,
|
|
321
|
+
name: this.getParamUniqueName(),
|
|
322
|
+
}, this, 'params');
|
|
323
|
+
}
|
|
324
|
+
else if (typeof options === 'string') {
|
|
325
|
+
param = Param__1.default.from({
|
|
326
|
+
...paramOptions,
|
|
327
|
+
name: options,
|
|
328
|
+
}, this, 'params');
|
|
329
|
+
}
|
|
330
|
+
else if (options instanceof Param__1.default) {
|
|
331
|
+
options.ensureDelete(); // 同一实例不支持多处存在
|
|
332
|
+
param = options;
|
|
333
|
+
Object.assign(param, relationOptions);
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
param = Param__1.default.from({
|
|
337
|
+
...paramOptions,
|
|
338
|
+
...options,
|
|
339
|
+
}, this, 'params');
|
|
340
|
+
}
|
|
341
|
+
this.params.splice(index, 0, param);
|
|
342
|
+
return param;
|
|
343
|
+
}
|
|
344
|
+
insertParamAt(options, index) {
|
|
345
|
+
const node = this._insertParamAt(options, index);
|
|
346
|
+
node.create({
|
|
347
|
+
index,
|
|
348
|
+
parentNode: this,
|
|
349
|
+
parentKey: 'params',
|
|
350
|
+
});
|
|
351
|
+
return node;
|
|
352
|
+
}
|
|
353
|
+
_addParam(options) {
|
|
354
|
+
const index = this.params.length;
|
|
355
|
+
return this._insertParamAt(options, index);
|
|
356
|
+
}
|
|
357
|
+
addParam(options) {
|
|
358
|
+
const node = this._addParam(options);
|
|
359
|
+
const index = this.params.indexOf(node);
|
|
360
|
+
node.create({
|
|
361
|
+
index,
|
|
362
|
+
parentNode: this,
|
|
363
|
+
parentKey: 'params',
|
|
364
|
+
});
|
|
365
|
+
return node;
|
|
366
|
+
}
|
|
367
|
+
getReturnUniqueName(name = 'result') {
|
|
368
|
+
return utils.unique(name, this.getVarExistingNames(), undefined, false);
|
|
369
|
+
}
|
|
370
|
+
_insertReturnAt(options, index) {
|
|
371
|
+
const retOptions = {};
|
|
372
|
+
const relationOptions = { parentNode: this, parentKey: 'returns' };
|
|
373
|
+
let ret;
|
|
374
|
+
if (!options) {
|
|
375
|
+
ret = Return__1.default.from({
|
|
376
|
+
...retOptions,
|
|
377
|
+
name: this.getReturnUniqueName(),
|
|
378
|
+
}, this, 'returns');
|
|
379
|
+
}
|
|
380
|
+
else if (typeof options === 'string') {
|
|
381
|
+
ret = Return__1.default.from({
|
|
382
|
+
...retOptions,
|
|
383
|
+
name: options,
|
|
384
|
+
}, this, 'returns');
|
|
385
|
+
}
|
|
386
|
+
else if (options instanceof Return__1.default) {
|
|
387
|
+
options.ensureDelete(); // 同一实例不支持多处存在
|
|
388
|
+
ret = options;
|
|
389
|
+
Object.assign(ret, relationOptions);
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
ret = Return__1.default.from({
|
|
393
|
+
...retOptions,
|
|
394
|
+
...options,
|
|
395
|
+
}, this, 'returns');
|
|
396
|
+
}
|
|
397
|
+
this.returns.splice(index, 0, ret);
|
|
398
|
+
return ret;
|
|
399
|
+
}
|
|
400
|
+
insertReturnAt(options, index) {
|
|
401
|
+
const node = this._insertReturnAt(options, index);
|
|
402
|
+
node.create({
|
|
403
|
+
index,
|
|
404
|
+
parentNode: this,
|
|
405
|
+
parentKey: 'returns',
|
|
406
|
+
});
|
|
407
|
+
return node;
|
|
408
|
+
}
|
|
409
|
+
_addReturn(options) {
|
|
410
|
+
const index = this.returns.length;
|
|
411
|
+
return this._insertReturnAt(options, index);
|
|
412
|
+
}
|
|
413
|
+
addReturn(options) {
|
|
414
|
+
const node = this._addReturn(options);
|
|
415
|
+
const index = this.returns.indexOf(node);
|
|
416
|
+
node.create({
|
|
417
|
+
index,
|
|
418
|
+
parentNode: this,
|
|
419
|
+
parentKey: 'returns',
|
|
420
|
+
});
|
|
421
|
+
return node;
|
|
422
|
+
}
|
|
423
|
+
getVariableUniqueName(name = 'variable1') {
|
|
424
|
+
return utils.unique(name, this.getVarExistingNames(), undefined, false);
|
|
425
|
+
}
|
|
426
|
+
_insertVariableAt(options, index) {
|
|
427
|
+
const variableOptions = {};
|
|
428
|
+
const relationOptions = { parentNode: this, parentKey: 'variables' };
|
|
429
|
+
let variable;
|
|
430
|
+
if (!options) {
|
|
431
|
+
variable = Variable__1.default.from({
|
|
432
|
+
...variableOptions,
|
|
433
|
+
name: this.getVariableUniqueName(),
|
|
434
|
+
}, this, 'variables');
|
|
435
|
+
}
|
|
436
|
+
else if (typeof options === 'string') {
|
|
437
|
+
variable = Variable__1.default.from({
|
|
438
|
+
...variableOptions,
|
|
439
|
+
name: options,
|
|
440
|
+
}, this, 'variables');
|
|
441
|
+
}
|
|
442
|
+
else if (options instanceof Variable__1.default) {
|
|
443
|
+
options.ensureDelete(); // 同一实例不支持多处存在
|
|
444
|
+
variable = options;
|
|
445
|
+
Object.assign(variable, relationOptions);
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
variable = Variable__1.default.from({
|
|
449
|
+
...variableOptions,
|
|
450
|
+
...options,
|
|
451
|
+
}, this, 'variables');
|
|
452
|
+
}
|
|
453
|
+
this.variables.splice(index, 0, variable);
|
|
454
|
+
return variable;
|
|
455
|
+
}
|
|
456
|
+
insertVariableAt(options, index) {
|
|
457
|
+
const node = this._insertVariableAt(options, index);
|
|
458
|
+
node.create({
|
|
459
|
+
index,
|
|
460
|
+
parentNode: this,
|
|
461
|
+
parentKey: 'variables',
|
|
462
|
+
});
|
|
463
|
+
return node;
|
|
464
|
+
}
|
|
465
|
+
_addVariable(options) {
|
|
466
|
+
const index = this.variables.length;
|
|
467
|
+
return this._insertVariableAt(options, index);
|
|
468
|
+
}
|
|
469
|
+
addVariable(options) {
|
|
470
|
+
const node = this._addVariable(options);
|
|
471
|
+
const index = this.variables.indexOf(node);
|
|
472
|
+
node.create({
|
|
473
|
+
index,
|
|
474
|
+
parentNode: this,
|
|
475
|
+
parentKey: 'variables',
|
|
476
|
+
});
|
|
477
|
+
return node;
|
|
478
|
+
}
|
|
479
|
+
_insertItemInBodyAt(options, index) {
|
|
480
|
+
const logicItemOptions = {};
|
|
481
|
+
const relationOptions = { parentNode: this, parentKey: 'body' };
|
|
482
|
+
let logicItem;
|
|
483
|
+
if (options instanceof LogicItem__1.default) {
|
|
484
|
+
options.ensureDelete(); // 同一实例不支持多处存在
|
|
485
|
+
logicItem = options;
|
|
486
|
+
Object.assign(logicItem, relationOptions);
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
logicItem = LogicItem__1.default.from({
|
|
490
|
+
...logicItemOptions,
|
|
491
|
+
...options,
|
|
492
|
+
}, this, 'body');
|
|
493
|
+
}
|
|
494
|
+
this.body.splice(index, 0, logicItem);
|
|
495
|
+
return logicItem;
|
|
496
|
+
}
|
|
497
|
+
insertItemInBodyAt(options, index) {
|
|
498
|
+
const node = this._insertItemInBodyAt(options, index);
|
|
499
|
+
node.create({
|
|
500
|
+
index,
|
|
501
|
+
parentNode: this,
|
|
502
|
+
parentKey: 'body',
|
|
503
|
+
});
|
|
504
|
+
return node;
|
|
505
|
+
}
|
|
506
|
+
_addItemInBody(options) {
|
|
507
|
+
const index = this.body.length;
|
|
508
|
+
return this._insertItemInBodyAt(options, index);
|
|
509
|
+
}
|
|
510
|
+
addItemInBody(options) {
|
|
511
|
+
const node = this._addItemInBody(options);
|
|
512
|
+
const index = this.body.indexOf(node);
|
|
513
|
+
node.create({
|
|
514
|
+
index,
|
|
515
|
+
parentNode: this,
|
|
516
|
+
parentKey: 'body',
|
|
517
|
+
});
|
|
518
|
+
return node;
|
|
519
|
+
}
|
|
520
|
+
_insertItemInPlaygroundAt(options, index) {
|
|
521
|
+
const logicItemOptions = {};
|
|
522
|
+
const relationOptions = { parentNode: this, parentKey: 'playground' };
|
|
523
|
+
let logicItem;
|
|
524
|
+
if (options instanceof LogicItem__1.default) {
|
|
525
|
+
options.ensureDelete(); // 同一实例不支持多处存在
|
|
526
|
+
logicItem = options;
|
|
527
|
+
Object.assign(logicItem, relationOptions);
|
|
528
|
+
}
|
|
529
|
+
else {
|
|
530
|
+
logicItem = LogicItem__1.default.from({
|
|
531
|
+
...logicItemOptions,
|
|
532
|
+
...options,
|
|
533
|
+
}, this, 'playground');
|
|
534
|
+
}
|
|
535
|
+
this.playground.splice(index, 0, logicItem);
|
|
536
|
+
return logicItem;
|
|
537
|
+
}
|
|
538
|
+
insertItemInPlaygroundAt(options, index) {
|
|
539
|
+
const node = this._insertItemInPlaygroundAt(options, index);
|
|
540
|
+
node.create({
|
|
541
|
+
index,
|
|
542
|
+
parentNode: this,
|
|
543
|
+
parentKey: 'playground',
|
|
544
|
+
});
|
|
545
|
+
return node;
|
|
546
|
+
}
|
|
547
|
+
_addItemInPlayground(options) {
|
|
548
|
+
const index = this.playground.length;
|
|
549
|
+
return this._insertItemInPlaygroundAt(options, index);
|
|
550
|
+
}
|
|
551
|
+
addItemInPlayground(options) {
|
|
552
|
+
const node = this._addItemInPlayground(options);
|
|
553
|
+
const index = this.playground.indexOf(node);
|
|
554
|
+
node.create({
|
|
555
|
+
index,
|
|
556
|
+
parentNode: this,
|
|
557
|
+
parentKey: 'playground',
|
|
558
|
+
});
|
|
559
|
+
return node;
|
|
560
|
+
}
|
|
561
|
+
removeTransactional(options) {
|
|
562
|
+
let transactional;
|
|
563
|
+
if (typeof options === 'string') {
|
|
564
|
+
transactional = this.transactional;
|
|
565
|
+
if (!transactional) {
|
|
566
|
+
throw new Error('找不到事务 ' + options);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
else {
|
|
570
|
+
transactional = options;
|
|
571
|
+
}
|
|
572
|
+
return transactional.delete();
|
|
573
|
+
}
|
|
574
|
+
__removeTransactional(transactional) {
|
|
575
|
+
const parentKey = transactional.parentKey;
|
|
576
|
+
const params = {
|
|
577
|
+
parentNode: this,
|
|
578
|
+
parentKey,
|
|
579
|
+
index: -1,
|
|
580
|
+
object: null,
|
|
581
|
+
oldObject: transactional,
|
|
582
|
+
};
|
|
583
|
+
if (parentKey) {
|
|
584
|
+
params.parentKey = parentKey;
|
|
585
|
+
if (Array.isArray(this[parentKey])) {
|
|
586
|
+
const index = this[parentKey].indexOf(transactional);
|
|
587
|
+
~index && this[parentKey].splice(index, 1);
|
|
588
|
+
params.index = index;
|
|
589
|
+
}
|
|
590
|
+
else if (this[parentKey] === transactional) {
|
|
591
|
+
params.index = 0;
|
|
592
|
+
this[parentKey] = undefined;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
return params;
|
|
596
|
+
}
|
|
597
|
+
removeTypeParam(options) {
|
|
598
|
+
let typeParam;
|
|
599
|
+
if (typeof options === 'string') {
|
|
600
|
+
typeParam = this.typeParams.find((item) => item.name === options);
|
|
601
|
+
if (!typeParam) {
|
|
602
|
+
throw new Error('找不到类型参数 ' + options);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
else {
|
|
606
|
+
typeParam = options;
|
|
607
|
+
}
|
|
608
|
+
return typeParam.delete();
|
|
609
|
+
}
|
|
610
|
+
__removeTypeParam(typeParam) {
|
|
611
|
+
const parentKey = typeParam.parentKey;
|
|
612
|
+
const params = {
|
|
613
|
+
parentNode: this,
|
|
614
|
+
parentKey,
|
|
615
|
+
index: -1,
|
|
616
|
+
object: null,
|
|
617
|
+
oldObject: typeParam,
|
|
618
|
+
};
|
|
619
|
+
if (parentKey) {
|
|
620
|
+
params.parentKey = parentKey;
|
|
621
|
+
if (Array.isArray(this[parentKey])) {
|
|
622
|
+
const index = this[parentKey].indexOf(typeParam);
|
|
623
|
+
~index && this[parentKey].splice(index, 1);
|
|
624
|
+
params.index = index;
|
|
625
|
+
}
|
|
626
|
+
else if (this[parentKey] === typeParam) {
|
|
627
|
+
params.index = 0;
|
|
628
|
+
this[parentKey] = undefined;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
return params;
|
|
632
|
+
}
|
|
633
|
+
removeParam(options) {
|
|
634
|
+
let param;
|
|
635
|
+
if (typeof options === 'string') {
|
|
636
|
+
param = this.params.find((item) => item.name === options);
|
|
637
|
+
if (!param) {
|
|
638
|
+
throw new Error('找不到输入参数 ' + options);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
else {
|
|
642
|
+
param = options;
|
|
643
|
+
}
|
|
644
|
+
return param.delete();
|
|
645
|
+
}
|
|
646
|
+
__removeParam(param) {
|
|
647
|
+
const parentKey = param.parentKey;
|
|
648
|
+
const params = {
|
|
649
|
+
parentNode: this,
|
|
650
|
+
parentKey,
|
|
651
|
+
index: -1,
|
|
652
|
+
object: null,
|
|
653
|
+
oldObject: param,
|
|
654
|
+
};
|
|
655
|
+
if (parentKey) {
|
|
656
|
+
params.parentKey = parentKey;
|
|
657
|
+
if (Array.isArray(this[parentKey])) {
|
|
658
|
+
const index = this[parentKey].indexOf(param);
|
|
659
|
+
~index && this[parentKey].splice(index, 1);
|
|
660
|
+
params.index = index;
|
|
661
|
+
}
|
|
662
|
+
else if (this[parentKey] === param) {
|
|
663
|
+
params.index = 0;
|
|
664
|
+
this[parentKey] = undefined;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
return params;
|
|
668
|
+
}
|
|
669
|
+
removeReturn(options) {
|
|
670
|
+
let ret;
|
|
671
|
+
if (typeof options === 'string') {
|
|
672
|
+
ret = this.returns.find((item) => item.name === options);
|
|
673
|
+
if (!ret) {
|
|
674
|
+
throw new Error('找不到输出参数 ' + options);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
else {
|
|
678
|
+
ret = options;
|
|
679
|
+
}
|
|
680
|
+
return ret.delete();
|
|
681
|
+
}
|
|
682
|
+
__removeReturn(ret) {
|
|
683
|
+
const parentKey = ret.parentKey;
|
|
684
|
+
const params = {
|
|
685
|
+
parentNode: this,
|
|
686
|
+
parentKey,
|
|
687
|
+
index: -1,
|
|
688
|
+
object: null,
|
|
689
|
+
oldObject: ret,
|
|
690
|
+
};
|
|
691
|
+
if (parentKey) {
|
|
692
|
+
params.parentKey = parentKey;
|
|
693
|
+
if (Array.isArray(this[parentKey])) {
|
|
694
|
+
const index = this[parentKey].indexOf(ret);
|
|
695
|
+
~index && this[parentKey].splice(index, 1);
|
|
696
|
+
params.index = index;
|
|
697
|
+
}
|
|
698
|
+
else if (this[parentKey] === ret) {
|
|
699
|
+
params.index = 0;
|
|
700
|
+
this[parentKey] = undefined;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
return params;
|
|
704
|
+
}
|
|
705
|
+
removeVariable(options) {
|
|
706
|
+
let variable;
|
|
707
|
+
if (typeof options === 'string') {
|
|
708
|
+
variable = this.variables.find((item) => item.name === options);
|
|
709
|
+
if (!variable) {
|
|
710
|
+
throw new Error('找不到变量 ' + options);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
else {
|
|
714
|
+
variable = options;
|
|
715
|
+
}
|
|
716
|
+
return variable.delete();
|
|
717
|
+
}
|
|
718
|
+
__removeVariable(variable) {
|
|
719
|
+
const parentKey = variable.parentKey;
|
|
720
|
+
const params = {
|
|
721
|
+
parentNode: this,
|
|
722
|
+
parentKey,
|
|
723
|
+
index: -1,
|
|
724
|
+
object: null,
|
|
725
|
+
oldObject: variable,
|
|
726
|
+
};
|
|
727
|
+
if (parentKey) {
|
|
728
|
+
params.parentKey = parentKey;
|
|
729
|
+
if (Array.isArray(this[parentKey])) {
|
|
730
|
+
const index = this[parentKey].indexOf(variable);
|
|
731
|
+
~index && this[parentKey].splice(index, 1);
|
|
732
|
+
params.index = index;
|
|
733
|
+
}
|
|
734
|
+
else if (this[parentKey] === variable) {
|
|
735
|
+
params.index = 0;
|
|
736
|
+
this[parentKey] = undefined;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
return params;
|
|
740
|
+
}
|
|
741
|
+
removeItemInBody(options) {
|
|
742
|
+
let logicItem = options;
|
|
743
|
+
return logicItem.delete();
|
|
744
|
+
}
|
|
745
|
+
removeItemInPlayground(options) {
|
|
746
|
+
let logicItem = options;
|
|
747
|
+
return logicItem.delete();
|
|
748
|
+
}
|
|
749
|
+
__removeLogicItem(logicItem) {
|
|
750
|
+
const parentKey = logicItem.parentKey;
|
|
751
|
+
const params = {
|
|
752
|
+
parentNode: this,
|
|
753
|
+
parentKey,
|
|
754
|
+
index: -1,
|
|
755
|
+
object: null,
|
|
756
|
+
oldObject: logicItem,
|
|
757
|
+
};
|
|
758
|
+
if (parentKey) {
|
|
759
|
+
params.parentKey = parentKey;
|
|
760
|
+
if (Array.isArray(this[parentKey])) {
|
|
761
|
+
const index = this[parentKey].indexOf(logicItem);
|
|
762
|
+
~index && this[parentKey].splice(index, 1);
|
|
763
|
+
params.index = index;
|
|
764
|
+
}
|
|
765
|
+
else if (this[parentKey] === logicItem) {
|
|
766
|
+
params.index = 0;
|
|
767
|
+
this[parentKey] = undefined;
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
return params;
|
|
771
|
+
}
|
|
772
|
+
//================================================================================
|
|
773
|
+
// ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
|
|
774
|
+
// 自动生成的代码已结束。下面可以手动编写。
|
|
775
|
+
//================================================================================
|
|
776
|
+
// 用于calllogic树中定位是那个logic,回显
|
|
777
|
+
get calleewholeKey() {
|
|
778
|
+
return this.getNamespace() + '.' + this.name;
|
|
779
|
+
}
|
|
780
|
+
// 设置定时任务
|
|
781
|
+
setCronAndTriggerType(cron, triggerType) {
|
|
782
|
+
const object = {
|
|
783
|
+
cron,
|
|
784
|
+
triggerType,
|
|
785
|
+
};
|
|
786
|
+
this.update({
|
|
787
|
+
...object,
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
/**
|
|
791
|
+
* 创建的时候 打开事务 通过开关设置数据库事务
|
|
792
|
+
*/
|
|
793
|
+
openTransactional(flag) {
|
|
794
|
+
if (flag) {
|
|
795
|
+
const transactional = new Transactional__1.default({
|
|
796
|
+
enabled: flag,
|
|
797
|
+
});
|
|
798
|
+
transactional._delete();
|
|
799
|
+
const relationOptions = { parentNode: this, parentKey: 'transactional' };
|
|
800
|
+
Object.assign(transactional, relationOptions);
|
|
801
|
+
this.transactional = transactional;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
findLogicItemByConcept(concept) {
|
|
805
|
+
let result;
|
|
806
|
+
utils.traverse((current) => {
|
|
807
|
+
if (current.node.concept === concept)
|
|
808
|
+
return (result = current.node);
|
|
809
|
+
}, { node: this }, {
|
|
810
|
+
mode: 'anyObject',
|
|
811
|
+
excludedKeySet: this.JSON_EXCLUDED_KEYS,
|
|
812
|
+
});
|
|
813
|
+
return result;
|
|
814
|
+
}
|
|
815
|
+
onChange($event) {
|
|
816
|
+
this.emit('change', $event);
|
|
817
|
+
}
|
|
818
|
+
getVarExistingNames(excludedList = []) {
|
|
819
|
+
const excludedSet = new Set(excludedList);
|
|
820
|
+
const varList = [];
|
|
821
|
+
if (Array.isArray(this.params)) {
|
|
822
|
+
varList.push(...this.params);
|
|
823
|
+
}
|
|
824
|
+
if (Array.isArray(this.returns)) {
|
|
825
|
+
varList.push(...this.returns);
|
|
826
|
+
}
|
|
827
|
+
if (Array.isArray(this.variables)) {
|
|
828
|
+
varList.push(...this.variables);
|
|
829
|
+
}
|
|
830
|
+
if (this.view) {
|
|
831
|
+
if (Array.isArray(this.view.params)) {
|
|
832
|
+
varList.push(...this.view.params);
|
|
833
|
+
}
|
|
834
|
+
if (Array.isArray(this.view.variables)) {
|
|
835
|
+
varList.push(...this.view.variables);
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
this.traverseChildren((el) => {
|
|
839
|
+
if (el?.concept === 'ForEachStatement') {
|
|
840
|
+
if (el?.item) {
|
|
841
|
+
varList.push(el?.item);
|
|
842
|
+
}
|
|
843
|
+
if (el?.index) {
|
|
844
|
+
varList.push(el?.index);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
});
|
|
848
|
+
return varList.filter((item) => !excludedSet.has(item)).map((item) => item?.name);
|
|
849
|
+
}
|
|
850
|
+
toJSContent(code, state) {
|
|
851
|
+
// params
|
|
852
|
+
if (Array.isArray(this.params)) {
|
|
853
|
+
this.params.forEach((param) => {
|
|
854
|
+
code += (0, translator_1.indent)((state?.tabSize || 0) + 1) + '';
|
|
855
|
+
code += param.toJS((0, translator_1.shiftState)(state, code, { inline: true }));
|
|
856
|
+
code += ';\n';
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
// variables
|
|
860
|
+
if (Array.isArray(this.variables)) {
|
|
861
|
+
this.variables.forEach((variable) => {
|
|
862
|
+
code += (0, translator_1.indent)((state?.tabSize || 0) + 1) + 'let ';
|
|
863
|
+
code += variable.toJS((0, translator_1.shiftState)(state, code, { inline: true }));
|
|
864
|
+
code += ';\n';
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
// returns
|
|
868
|
+
if (Array.isArray(this.returns)) {
|
|
869
|
+
this.returns.forEach((ret) => {
|
|
870
|
+
code += (0, translator_1.indent)((state?.tabSize || 0) + 1) + 'let ';
|
|
871
|
+
code += ret.toJS((0, translator_1.shiftState)(state, code, { inline: true }));
|
|
872
|
+
code += ';\n';
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
if (Array.isArray(this.body)) {
|
|
876
|
+
this.body.forEach((item) => {
|
|
877
|
+
code += item.toJS && item.toJS((0, translator_1.shiftState)(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
|
|
878
|
+
code += '\n';
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
return code;
|
|
882
|
+
}
|
|
883
|
+
toJS(state, type) {
|
|
884
|
+
let code = '';
|
|
885
|
+
if (type === 'IIFE') {
|
|
886
|
+
code += `await (async () => {\n`;
|
|
887
|
+
code = this.toJSContent(code, state);
|
|
888
|
+
code += (0, translator_1.indent)(state?.tabSize || 0) + '})();\n';
|
|
889
|
+
return code;
|
|
890
|
+
}
|
|
891
|
+
code += `async ${this.name} (`;
|
|
892
|
+
if (this.params?.length) {
|
|
893
|
+
this.params.forEach((param, index) => {
|
|
894
|
+
code += param.name;
|
|
895
|
+
if (index !== this.params.length - 1)
|
|
896
|
+
code += ', ';
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
code += ') {\n';
|
|
900
|
+
code = this.toJSContent(code, state);
|
|
901
|
+
code += (0, translator_1.indent)(state?.tabSize || 0) + '}\n';
|
|
902
|
+
return code;
|
|
903
|
+
}
|
|
904
|
+
toProcessService() {
|
|
905
|
+
return {
|
|
906
|
+
config: {
|
|
907
|
+
serviceType: 'micro',
|
|
908
|
+
},
|
|
909
|
+
url: {
|
|
910
|
+
method: 'POST',
|
|
911
|
+
path: this.getPath(),
|
|
912
|
+
},
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
toService() {
|
|
916
|
+
const parentNode = this.parentNode;
|
|
917
|
+
const { concept, name: entityName } = parentNode || {};
|
|
918
|
+
const logicName = this.name;
|
|
919
|
+
let serviceType = 'micro';
|
|
920
|
+
let method = 'POST';
|
|
921
|
+
// let path = `/api/${logicName}`;
|
|
922
|
+
const map = {
|
|
923
|
+
GetUser: 'LCAPAuth',
|
|
924
|
+
Logout: 'LCAPAuth',
|
|
925
|
+
CheckPermission: 'LCAPPermission',
|
|
926
|
+
GetUserResources: 'LCAPPermission',
|
|
927
|
+
UploadPermission: 'LCAPPermission',
|
|
928
|
+
GetUserList: 'LCAPUserManage',
|
|
929
|
+
GetRoleList: 'LCAPUserManage',
|
|
930
|
+
};
|
|
931
|
+
let path = `/api/${map[logicName]}/overridden/${logicName}`;
|
|
932
|
+
if (concept === 'Module') {
|
|
933
|
+
path = `/api/${entityName.replace('-', '_')}/${logicName}`;
|
|
934
|
+
}
|
|
935
|
+
else if (concept === 'Namespace') {
|
|
936
|
+
serviceType = 'entity';
|
|
937
|
+
let entityPath = entityName.replace(/[A-Z]/g, (char, index) => {
|
|
938
|
+
const lowerChar = char.toLowerCase();
|
|
939
|
+
return index === 0 ? lowerChar : `-${lowerChar}`;
|
|
940
|
+
});
|
|
941
|
+
const dataSource = parentNode.getAncestor('DataSource');
|
|
942
|
+
// 默认数据源不动,其他数据源需要拼接数据源信息
|
|
943
|
+
if (dataSource && dataSource.name !== 'defaultDS') {
|
|
944
|
+
entityPath = dataSource.name + '/' + entityPath;
|
|
945
|
+
}
|
|
946
|
+
path = `/api/${entityPath}`;
|
|
947
|
+
switch (this.name) {
|
|
948
|
+
case 'get':
|
|
949
|
+
method = 'GET';
|
|
950
|
+
path = `/api/${entityPath}`;
|
|
951
|
+
break;
|
|
952
|
+
case 'create':
|
|
953
|
+
method = 'POST';
|
|
954
|
+
break;
|
|
955
|
+
case 'update':
|
|
956
|
+
method = 'PUT';
|
|
957
|
+
break;
|
|
958
|
+
case 'delete':
|
|
959
|
+
method = 'DELETE';
|
|
960
|
+
path = `/api/${entityPath}`;
|
|
961
|
+
break;
|
|
962
|
+
case 'createOrUpdate':
|
|
963
|
+
method = 'POST';
|
|
964
|
+
path = `/api/${entityPath}/createOrUpdate`;
|
|
965
|
+
break;
|
|
966
|
+
case 'updateBy':
|
|
967
|
+
method = 'PUT';
|
|
968
|
+
path = `/api/${entityPath}/by`;
|
|
969
|
+
break;
|
|
970
|
+
case 'deleteBy':
|
|
971
|
+
method = 'DELETE';
|
|
972
|
+
path = `/api/${entityPath}/by`;
|
|
973
|
+
break;
|
|
974
|
+
case 'batchCreate':
|
|
975
|
+
method = 'POST';
|
|
976
|
+
path = `/api/${entityPath}/batch`;
|
|
977
|
+
break;
|
|
978
|
+
case 'batchUpdate':
|
|
979
|
+
method = 'PUT';
|
|
980
|
+
path = `/api/${entityPath}/batch`;
|
|
981
|
+
break;
|
|
982
|
+
case 'batchDelete':
|
|
983
|
+
method = 'DELETE';
|
|
984
|
+
path = `/api/${entityPath}/batch`;
|
|
985
|
+
break;
|
|
986
|
+
case 'import':
|
|
987
|
+
method = 'POST';
|
|
988
|
+
path = `/api/${entityPath}/import`;
|
|
989
|
+
break;
|
|
990
|
+
default:
|
|
991
|
+
break;
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
return {
|
|
995
|
+
config: {
|
|
996
|
+
serviceType,
|
|
997
|
+
},
|
|
998
|
+
url: {
|
|
999
|
+
method,
|
|
1000
|
+
path,
|
|
1001
|
+
},
|
|
1002
|
+
};
|
|
1003
|
+
}
|
|
1004
|
+
toEmbeddedTSInProcess(state, prependCode, noName, prefix) {
|
|
1005
|
+
let code = '';
|
|
1006
|
+
if (!prefix)
|
|
1007
|
+
code += `${noName ? '' : `${this.name}:`} function(`;
|
|
1008
|
+
else
|
|
1009
|
+
code += `function ${this.name}(`; //加空格会导致无法查询到引用
|
|
1010
|
+
this.params.forEach((param, index) => {
|
|
1011
|
+
code += param.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
|
|
1012
|
+
if (index !== this.params.length - 1)
|
|
1013
|
+
code += ', ';
|
|
1014
|
+
});
|
|
1015
|
+
code += `) {\n`;
|
|
1016
|
+
code += prependCode || '';
|
|
1017
|
+
code += '\n';
|
|
1018
|
+
this.variables.forEach((variable) => {
|
|
1019
|
+
code += (0, translator_1.indent)((state?.tabSize || 0) + 1) + 'let ';
|
|
1020
|
+
code += variable.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
|
|
1021
|
+
code += ';\n';
|
|
1022
|
+
});
|
|
1023
|
+
this.returns.forEach((ret) => {
|
|
1024
|
+
code += (0, translator_1.indent)((state?.tabSize || 0) + 1) + 'let ';
|
|
1025
|
+
code += ret.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
|
|
1026
|
+
code += ';\n';
|
|
1027
|
+
});
|
|
1028
|
+
if (!this.body.length && this.returns.length) {
|
|
1029
|
+
code += (0, translator_1.indent)((state?.tabSize || 0) + 1) + `return ${this.returns[0].name};\n`;
|
|
1030
|
+
}
|
|
1031
|
+
else {
|
|
1032
|
+
if (this.parentNode.type === 'ExclusiveGateway') {
|
|
1033
|
+
if (this.body.length <= 1) {
|
|
1034
|
+
code += (0, translator_1.indent)((state?.tabSize || 0) + 1);
|
|
1035
|
+
code += 'const __LogicEmpty: any = null;';
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
else if (this.body.length <= 2 && !(this.parentNode instanceof Namespace__1.default) && !(this.parentNode instanceof Process__1.default)) {
|
|
1039
|
+
code += (0, translator_1.indent)((state?.tabSize || 0) + 1);
|
|
1040
|
+
code += (0, translator_1.indent)(state?.tabSize || 0 + 4) + 'const __LogicEmpty: any = null;';
|
|
1041
|
+
}
|
|
1042
|
+
this.body.forEach((item) => {
|
|
1043
|
+
code += item.toEmbeddedTS && item.toEmbeddedTS((0, translator_1.shiftState)(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
|
|
1044
|
+
code += ';\n';
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
// 在body渲染完成之后把其余的节点放到下面
|
|
1048
|
+
this.playground.forEach((item) => {
|
|
1049
|
+
code += item.toEmbeddedTS((0, translator_1.shiftState)(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
|
|
1050
|
+
code += '\n';
|
|
1051
|
+
});
|
|
1052
|
+
code += (0, translator_1.indent)(state?.tabSize || 0 + 4) + '}';
|
|
1053
|
+
code += '\n';
|
|
1054
|
+
return code;
|
|
1055
|
+
}
|
|
1056
|
+
toEmbeddedTSNoExport(state) {
|
|
1057
|
+
return this.toEmbeddedTS(state, 'noExport');
|
|
1058
|
+
}
|
|
1059
|
+
toEmbeddedTS(state, prefix) {
|
|
1060
|
+
// 如果传了不要前缀那就为空, 要不用传进来的,要是都没有就默认导出
|
|
1061
|
+
let code = '';
|
|
1062
|
+
if (!prefix) {
|
|
1063
|
+
code += `export function ${this.name}`;
|
|
1064
|
+
}
|
|
1065
|
+
else if (prefix === 'noExport') {
|
|
1066
|
+
code += `function ${this.name}`;
|
|
1067
|
+
}
|
|
1068
|
+
else if (prefix === 'inObject') {
|
|
1069
|
+
code += `${this.name}`;
|
|
1070
|
+
}
|
|
1071
|
+
if (this.typeParams?.length) {
|
|
1072
|
+
code += '<';
|
|
1073
|
+
this.typeParams.forEach((typeParam, typeParamIndex) => {
|
|
1074
|
+
code += typeParam.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
|
|
1075
|
+
if (typeParamIndex !== this.typeParams.length - 1)
|
|
1076
|
+
code += ', ';
|
|
1077
|
+
});
|
|
1078
|
+
code += '>';
|
|
1079
|
+
}
|
|
1080
|
+
// 有参数长度
|
|
1081
|
+
if (this.params.length) {
|
|
1082
|
+
code += '(';
|
|
1083
|
+
this.params.forEach((param, index) => {
|
|
1084
|
+
code += param.toEmbeddedTS((0, translator_1.shiftState)(state, code));
|
|
1085
|
+
if (index !== this.params.length - 1)
|
|
1086
|
+
code += ', ';
|
|
1087
|
+
});
|
|
1088
|
+
code += ')';
|
|
1089
|
+
}
|
|
1090
|
+
else {
|
|
1091
|
+
// 没有参数的
|
|
1092
|
+
code += '()';
|
|
1093
|
+
}
|
|
1094
|
+
// 需要类型推导的局部变量/返回值需要调整申明顺序
|
|
1095
|
+
const advanceMap = new Map();
|
|
1096
|
+
const needGetSourceMapOqlList = [];
|
|
1097
|
+
this.traverseChildren((el) => {
|
|
1098
|
+
if (el && (el instanceof BatchAssignment__1.default || (el instanceof Assignment__1.default && el.left?.name))) {
|
|
1099
|
+
if (el instanceof Assignment__1.default) {
|
|
1100
|
+
const advanceVar = this.variables?.find((variable) => !variable.typeAnnotation && (el.left?.name === variable.name));
|
|
1101
|
+
if (advanceVar && !advanceMap.get(advanceVar)) {
|
|
1102
|
+
advanceMap.set(advanceVar, el);
|
|
1103
|
+
}
|
|
1104
|
+
const advanceRn = this.returns?.find((ret) => !ret.typeAnnotation && el.left?.name === ret.name);
|
|
1105
|
+
if (advanceRn && !advanceMap.get(advanceRn)) {
|
|
1106
|
+
advanceMap.set(advanceRn, el);
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
else if (el instanceof BatchAssignment__1.default) {
|
|
1110
|
+
el.assignmentLines.forEach(({ leftIndex }) => {
|
|
1111
|
+
const leftCode = leftIndex.length === 1 ? el.left.expression.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true })) : el.left.members[leftIndex[1]]?.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
|
|
1112
|
+
const advanceVar = this.variables?.find((variable) => !variable.typeAnnotation && (leftCode === variable.name));
|
|
1113
|
+
if (advanceVar && !advanceMap.get(advanceVar)) {
|
|
1114
|
+
advanceMap.set(advanceVar, el);
|
|
1115
|
+
}
|
|
1116
|
+
const advanceRn = this.returns?.find((ret) => !ret.typeAnnotation && leftCode === ret.name);
|
|
1117
|
+
if (advanceRn && !advanceMap.get(advanceRn)) {
|
|
1118
|
+
advanceMap.set(advanceRn, el);
|
|
1119
|
+
}
|
|
1120
|
+
});
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
// 如果有sql查询组件就需要把他们存起来
|
|
1124
|
+
if (el instanceof OqlQueryComponent__1.default) {
|
|
1125
|
+
if (!el.codeSourceMap) {
|
|
1126
|
+
needGetSourceMapOqlList.push(el.requestEmbeddedTS());
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
});
|
|
1130
|
+
if (needGetSourceMapOqlList.length) {
|
|
1131
|
+
Promise.all(needGetSourceMapOqlList).then(() => {
|
|
1132
|
+
// 触发一下更新重新生成代码
|
|
1133
|
+
this.app?.naslServer?.embeddedTSEmitter.emit('change', {
|
|
1134
|
+
value: [
|
|
1135
|
+
{
|
|
1136
|
+
originEvent: {
|
|
1137
|
+
action: 'update',
|
|
1138
|
+
target: this,
|
|
1139
|
+
},
|
|
1140
|
+
},
|
|
1141
|
+
],
|
|
1142
|
+
});
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
// 兼容 return 没有类型情况
|
|
1146
|
+
if (this.returns.length && this.returns[0].typeAnnotation) {
|
|
1147
|
+
code += ': ';
|
|
1148
|
+
code += this.returns[0].typeAnnotation?.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
|
|
1149
|
+
}
|
|
1150
|
+
code += '{\n';
|
|
1151
|
+
// 用于虚拟节点的查找引用
|
|
1152
|
+
this.virtualParams
|
|
1153
|
+
&& Array.isArray(this.virtualParams)
|
|
1154
|
+
&& this.virtualParams.forEach((param) => {
|
|
1155
|
+
code += (0, translator_1.indent)((state?.tabSize || 0) + 1);
|
|
1156
|
+
code += param.toEmbeddedNameTS((0, translator_1.shiftState)(state, code, { inline: true }));
|
|
1157
|
+
code += '\n';
|
|
1158
|
+
});
|
|
1159
|
+
this.variables.forEach((variable) => {
|
|
1160
|
+
if (!advanceMap.get(variable)) {
|
|
1161
|
+
code += (0, translator_1.indent)((state?.tabSize || 0) + 1) + 'let ';
|
|
1162
|
+
code += variable.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
|
|
1163
|
+
code += ';\n';
|
|
1164
|
+
}
|
|
1165
|
+
});
|
|
1166
|
+
this.returns.forEach((ret) => {
|
|
1167
|
+
if (!advanceMap.get(ret)) {
|
|
1168
|
+
code += (0, translator_1.indent)((state?.tabSize || 0) + 1) + 'let ';
|
|
1169
|
+
code += ret.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
|
|
1170
|
+
code += ';\n';
|
|
1171
|
+
}
|
|
1172
|
+
});
|
|
1173
|
+
advanceMap.forEach((assignment, node) => {
|
|
1174
|
+
code += (0, translator_1.indent)((state?.tabSize || 0) + 1) + '// @ts-ignore\n';
|
|
1175
|
+
code += (0, translator_1.indent)((state?.tabSize || 0) + 1) + 'let ';
|
|
1176
|
+
code += node.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
|
|
1177
|
+
if (assignment instanceof BatchAssignment__1.default) {
|
|
1178
|
+
assignment.assignmentLines.forEach(({ leftIndex, rightIndex }) => {
|
|
1179
|
+
const leftCode = leftIndex.length === 1 ? assignment.left.expression.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true })) : assignment.left.members[leftIndex[1]]?.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
|
|
1180
|
+
if (leftCode === node.name) {
|
|
1181
|
+
const rightNode = rightIndex.length === 1 ? assignment.rights[rightIndex[0]]?.expression : assignment.rights[rightIndex[0]]?.members[rightIndex[1]];
|
|
1182
|
+
// 当右边有明确类型时,直接使用其类型。旧版本数据查询不能直接使用其 typeAnnotation
|
|
1183
|
+
if (rightNode?.typeAnnotation && !(rightNode instanceof CallQueryComponent__1.default && rightNode.ideVersion !== '2.11')) {
|
|
1184
|
+
code += ': ';
|
|
1185
|
+
code += rightNode.typeAnnotation?.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true })) || 'null';
|
|
1186
|
+
}
|
|
1187
|
+
else {
|
|
1188
|
+
code += ' = ';
|
|
1189
|
+
const rightCode = rightNode?.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
|
|
1190
|
+
code += this.getRightCode(rightCode, assignment, rightNode);
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
else if (['NewList', 'NewMap'].includes(assignment.right?.concept) && !assignment.right?.typeAnnotation) {
|
|
1196
|
+
const rightNode = assignment.right;
|
|
1197
|
+
code += ' = ';
|
|
1198
|
+
code += rightNode.getInitCode((0, translator_1.shiftState)(state, code, { inline: true }));
|
|
1199
|
+
}
|
|
1200
|
+
else if (assignment.right?.concept === 'NewComposite' && assignment.right?.typeAnnotation?.typeKind === 'anonymousStructure') {
|
|
1201
|
+
const rightNode = assignment.right;
|
|
1202
|
+
code += ' = ';
|
|
1203
|
+
code += rightNode.getInitCode((0, translator_1.shiftState)(state, code, { inline: true }));
|
|
1204
|
+
}
|
|
1205
|
+
else {
|
|
1206
|
+
const rightNode = assignment.right;
|
|
1207
|
+
// 当右边有明确类型时,直接使用其类型。旧版本数据查询不能直接使用其 typeAnnotation
|
|
1208
|
+
if (rightNode?.typeAnnotation && !(rightNode instanceof CallQueryComponent__1.default && rightNode.ideVersion !== '2.11')) {
|
|
1209
|
+
code += ': ';
|
|
1210
|
+
code += rightNode.typeAnnotation?.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true })) || 'null';
|
|
1211
|
+
}
|
|
1212
|
+
else {
|
|
1213
|
+
code += ' = ';
|
|
1214
|
+
let rightCode = '';
|
|
1215
|
+
// 因为右侧枚举要赋值就得new 一下;
|
|
1216
|
+
if (rightNode && rightNode instanceof Identifier__1.default && rightNode.namespace && rightNode.namespace.endsWith('enums')) {
|
|
1217
|
+
rightCode += 'new ';
|
|
1218
|
+
}
|
|
1219
|
+
rightCode += rightNode && rightNode.toEmbeddedTS ? rightNode.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true })) : '__RIGHT__';
|
|
1220
|
+
code += this.getRightCode(rightCode, assignment, rightNode);
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
code += ';\n';
|
|
1224
|
+
});
|
|
1225
|
+
if (!this.body.length && this.returns.length) {
|
|
1226
|
+
code += (0, translator_1.indent)((state?.tabSize || 0) + 1) + `return ${this.returns[0].name};\n`;
|
|
1227
|
+
}
|
|
1228
|
+
else {
|
|
1229
|
+
// 如果长度小于2 并且不是虚拟节点就 加 报错,
|
|
1230
|
+
if (this.body.length <= 2 && !(this.parentNode instanceof Namespace__1.default)) {
|
|
1231
|
+
code += (0, translator_1.indent)((state?.tabSize || 0) + 1);
|
|
1232
|
+
code += 'const __LogicEmpty: any = null;';
|
|
1233
|
+
}
|
|
1234
|
+
this.body.forEach((item) => {
|
|
1235
|
+
code += item.toEmbeddedTS && item.toEmbeddedTS((0, translator_1.shiftState)(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
|
|
1236
|
+
code += ';\n';
|
|
1237
|
+
});
|
|
1238
|
+
}
|
|
1239
|
+
// 在body渲染完成之后把其余的节点放到下面
|
|
1240
|
+
this.playground.forEach((item) => {
|
|
1241
|
+
code += item.toEmbeddedTS((0, translator_1.shiftState)(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
|
|
1242
|
+
code += ';\n';
|
|
1243
|
+
});
|
|
1244
|
+
code += (0, translator_1.indent)(state?.tabSize || 0) + '}';
|
|
1245
|
+
if (prefix === 'inObject') {
|
|
1246
|
+
code += `,`;
|
|
1247
|
+
}
|
|
1248
|
+
code += '\n';
|
|
1249
|
+
return code;
|
|
1250
|
+
}
|
|
1251
|
+
getRightCode(code, assignment, rightNode) {
|
|
1252
|
+
code = code.replaceAll('\n', ' ');
|
|
1253
|
+
if (assignment instanceof Assignment__1.default && !assignment.right)
|
|
1254
|
+
return code;
|
|
1255
|
+
// 调用接口,参数替换成 null
|
|
1256
|
+
if (rightNode instanceof CallInterface__1.default) {
|
|
1257
|
+
const { _interface } = rightNode.getModuleInterface();
|
|
1258
|
+
return _interface ? `${rightNode.tsCalleeKey}(${_interface.params.map(() => 'null').join(',')})` : null;
|
|
1259
|
+
}
|
|
1260
|
+
// 调用服务端逻辑,参数替换成 null
|
|
1261
|
+
if (rightNode instanceof CallLogic__1.default && rightNode.calleeNamespace === 'app.logics') {
|
|
1262
|
+
const calleeName = rightNode?.calleeName;
|
|
1263
|
+
const calleeLogic = this.app.logics.find((l) => l.name === calleeName);
|
|
1264
|
+
return calleeLogic ? `app.logics.${calleeName}(${calleeLogic.params.map(() => 'null').join(',')})` : null;
|
|
1265
|
+
}
|
|
1266
|
+
// ForEachStatement 内部变量需要替换处理,如 item、index
|
|
1267
|
+
const forEachStatement = assignment.getAncestor('ForEachStatement');
|
|
1268
|
+
if (forEachStatement) {
|
|
1269
|
+
code = this.handleForEachCode(code, forEachStatement);
|
|
1270
|
+
}
|
|
1271
|
+
// Match 需要针对分支缩小类型范围
|
|
1272
|
+
const matchCase = assignment.getAncestor('MatchCase');
|
|
1273
|
+
if (matchCase) {
|
|
1274
|
+
code = this.handleMatchCaseCode(code, matchCase);
|
|
1275
|
+
}
|
|
1276
|
+
return code;
|
|
1277
|
+
}
|
|
1278
|
+
handleReplaceCode(code, variable, replaceCode) {
|
|
1279
|
+
return code.replace(/\S+/g, ($1) => {
|
|
1280
|
+
if ($1 === `${variable},`)
|
|
1281
|
+
return `${replaceCode},`;
|
|
1282
|
+
if ($1 === variable)
|
|
1283
|
+
return replaceCode;
|
|
1284
|
+
let fnCode = $1;
|
|
1285
|
+
if ($1.startsWith(`${variable}.`))
|
|
1286
|
+
fnCode = $1.replaceAll(`${variable}.`, `${replaceCode}.`);
|
|
1287
|
+
if ($1.startsWith(`${variable},`))
|
|
1288
|
+
fnCode = $1.replaceAll(`${variable},`, `${replaceCode},`);
|
|
1289
|
+
if ($1.includes(`(${variable},`))
|
|
1290
|
+
fnCode = $1.replaceAll(`(${variable},`, `(${replaceCode},`);
|
|
1291
|
+
if ($1.includes(`(${variable}.`))
|
|
1292
|
+
fnCode = $1.replaceAll(`(${variable}.`, `(${replaceCode}.`);
|
|
1293
|
+
if ($1.includes(`(${variable})`))
|
|
1294
|
+
fnCode = $1.replaceAll(`(${variable})`, `(${replaceCode})`);
|
|
1295
|
+
if ($1.includes(`,${variable},`))
|
|
1296
|
+
fnCode = $1.replaceAll(`,${variable},`, `,${replaceCode},`);
|
|
1297
|
+
if ($1.includes(`,${variable}.`))
|
|
1298
|
+
fnCode = $1.replaceAll(`,${variable}.`, `,${replaceCode}.`);
|
|
1299
|
+
if ($1.includes(`,${variable})`))
|
|
1300
|
+
fnCode = $1.replaceAll(`,${variable})`, `,${replaceCode})`);
|
|
1301
|
+
return fnCode;
|
|
1302
|
+
});
|
|
1303
|
+
}
|
|
1304
|
+
handleForEachCode(code, forEachStatement) {
|
|
1305
|
+
const { item, index, each } = forEachStatement;
|
|
1306
|
+
if (code.includes(item.name)) {
|
|
1307
|
+
const eachTSCode = each.toEmbeddedTS();
|
|
1308
|
+
code = this.handleReplaceCode(code, item.name, eachTSCode === '__IDENTIFIER__' ? eachTSCode : `${eachTSCode}.__get(0)`);
|
|
1309
|
+
}
|
|
1310
|
+
if (code.includes(index.name))
|
|
1311
|
+
code = this.handleReplaceCode(code, index.name, 'new nasl.core.Integer(0)');
|
|
1312
|
+
const parentForEachStatement = forEachStatement.getAncestor('ForEachStatement');
|
|
1313
|
+
if (parentForEachStatement) {
|
|
1314
|
+
this.handleForEachCode(code, parentForEachStatement);
|
|
1315
|
+
}
|
|
1316
|
+
return code;
|
|
1317
|
+
}
|
|
1318
|
+
handleMatchCaseCode(code, matchCase) {
|
|
1319
|
+
const match = matchCase.getAncestor('Match');
|
|
1320
|
+
const expressionTsCode = match.expression.toEmbeddedTS();
|
|
1321
|
+
if (code.includes(expressionTsCode)) {
|
|
1322
|
+
let typeCode = '';
|
|
1323
|
+
matchCase.patterns.forEach((pattern, index) => {
|
|
1324
|
+
if (pattern instanceof TypeAnnotation__1.default) {
|
|
1325
|
+
if (index === 0) {
|
|
1326
|
+
typeCode += pattern.toEmbeddedTS();
|
|
1327
|
+
}
|
|
1328
|
+
else {
|
|
1329
|
+
typeCode += '|';
|
|
1330
|
+
typeCode += pattern.toEmbeddedTS();
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
});
|
|
1334
|
+
if (typeCode) {
|
|
1335
|
+
code = this.handleReplaceCode(code, expressionTsCode, `(${expressionTsCode} as ${typeCode})`);
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
const parentMatchCase = match.getAncestor('MatchCase');
|
|
1339
|
+
if (parentMatchCase) {
|
|
1340
|
+
code = this.handleMatchCaseCode(code, parentMatchCase);
|
|
1341
|
+
}
|
|
1342
|
+
return code;
|
|
1343
|
+
}
|
|
1344
|
+
getNamespace() {
|
|
1345
|
+
if (this.parentNode) {
|
|
1346
|
+
const parentNamespace = this.parentNode?.getNamespace();
|
|
1347
|
+
const parentName = this.parentNode.name;
|
|
1348
|
+
const arr = [parentNamespace];
|
|
1349
|
+
if (this.parentNode.concept !== 'App' && parentName) {
|
|
1350
|
+
arr.push(parentName);
|
|
1351
|
+
}
|
|
1352
|
+
let namespace = arr.join('.');
|
|
1353
|
+
if (!['nasl.ui', 'nasl.utils', 'nasl.util', 'nasl.browser', 'nasl.auth', 'nasl.configuration', 'nasl.process', 'nasl.logging', 'nasl.io'].includes(namespace)
|
|
1354
|
+
&& !namespace.includes('.overriddenLogics')) {
|
|
1355
|
+
namespace = `${namespace}.overriddenLogics`;
|
|
1356
|
+
}
|
|
1357
|
+
if (this.concept === 'OverriddenLogic') {
|
|
1358
|
+
namespace = `extensions.${this.overriddenModule}.logics`;
|
|
1359
|
+
}
|
|
1360
|
+
return namespace;
|
|
1361
|
+
}
|
|
1362
|
+
else
|
|
1363
|
+
throw new Error('无法获取命名空间,请设置 parentNode!');
|
|
1364
|
+
}
|
|
1365
|
+
getTsNamespace() {
|
|
1366
|
+
if (this.parentNode) {
|
|
1367
|
+
const parentNamespace = this.parentNode?.getTsNamespace();
|
|
1368
|
+
const parentName = this.parentNode.tsName || this.parentNode.name;
|
|
1369
|
+
const arr = [parentNamespace];
|
|
1370
|
+
if (this.parentNode.concept !== 'App' && parentName) {
|
|
1371
|
+
arr.push(parentName);
|
|
1372
|
+
}
|
|
1373
|
+
let namespace = arr.join('.');
|
|
1374
|
+
if (!['nasl.ui', 'nasl.utils', 'nasl.util', 'nasl.browser', 'nasl.auth', 'nasl.configuration', 'nasl.process', 'nasl.logging', 'nasl.io'].includes(namespace)
|
|
1375
|
+
&& !namespace.includes('.overriddenLogics')) {
|
|
1376
|
+
namespace = `${namespace}.overriddenLogics`;
|
|
1377
|
+
}
|
|
1378
|
+
return namespace;
|
|
1379
|
+
}
|
|
1380
|
+
else
|
|
1381
|
+
throw new Error('无法获取命名空间,请设置 parentNode!');
|
|
1382
|
+
}
|
|
1383
|
+
/**
|
|
1384
|
+
* 生成宿主语言的文件路径
|
|
1385
|
+
* @param name 一般不用传,用于 rename
|
|
1386
|
+
*/
|
|
1387
|
+
getEmbeddedFilePath(name = this.name) {
|
|
1388
|
+
let _path = this.module ? `/${this.module.parentKey}/${this.module.name}` : '';
|
|
1389
|
+
if (this.parentNode instanceof FrontendLibrary__1.FrontendLibrary) {
|
|
1390
|
+
_path += `/frontends/${this.parentNode.type}`;
|
|
1391
|
+
}
|
|
1392
|
+
return `/embedded/${this.app.name}${_path}/overriddenLogics/${name}.ts`;
|
|
1393
|
+
}
|
|
1394
|
+
toEmbeddedTSFile() {
|
|
1395
|
+
let code = `namespace ${this.getTsNamespace()} {\n`;
|
|
1396
|
+
const state = (0, translator_1.createCompilerState)(code, { tabSize: 1 });
|
|
1397
|
+
try {
|
|
1398
|
+
code += this.toEmbeddedTS(state);
|
|
1399
|
+
}
|
|
1400
|
+
catch (err) {
|
|
1401
|
+
console.log(err, '有问题翻译失败');
|
|
1402
|
+
code += '';
|
|
1403
|
+
console.log(err);
|
|
1404
|
+
}
|
|
1405
|
+
code += '}\n';
|
|
1406
|
+
return {
|
|
1407
|
+
code,
|
|
1408
|
+
filePath: this.getEmbeddedFilePath(),
|
|
1409
|
+
sourceMap: state.sourceMap,
|
|
1410
|
+
};
|
|
1411
|
+
}
|
|
1412
|
+
static getDefaultOptions() {
|
|
1413
|
+
return {
|
|
1414
|
+
body: [
|
|
1415
|
+
{
|
|
1416
|
+
concept: 'Start',
|
|
1417
|
+
label: '开始',
|
|
1418
|
+
kind: 'Statement',
|
|
1419
|
+
type: 'Start',
|
|
1420
|
+
},
|
|
1421
|
+
{
|
|
1422
|
+
concept: 'End',
|
|
1423
|
+
label: '结束',
|
|
1424
|
+
kind: 'Statement',
|
|
1425
|
+
type: 'End',
|
|
1426
|
+
},
|
|
1427
|
+
],
|
|
1428
|
+
};
|
|
1429
|
+
}
|
|
1430
|
+
async saveStructureOfCallQueryComponents(root) {
|
|
1431
|
+
if (!root)
|
|
1432
|
+
root = this;
|
|
1433
|
+
const set = new Set();
|
|
1434
|
+
utils.traverse(({ node }) => {
|
|
1435
|
+
if (node instanceof CallQueryComponent__1.default) {
|
|
1436
|
+
set.add(node);
|
|
1437
|
+
}
|
|
1438
|
+
}, { node: root }, {
|
|
1439
|
+
mode: 'anyObject',
|
|
1440
|
+
excludedKeySet: new Set(['parentNode', '__assignment__']),
|
|
1441
|
+
});
|
|
1442
|
+
for (const node of set) {
|
|
1443
|
+
node.saveStructure();
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
// 通过开关设置数据库事务
|
|
1447
|
+
setTransactionEnabled(flag) {
|
|
1448
|
+
this.setTransactional(new Transactional__1.default({
|
|
1449
|
+
enabled: flag,
|
|
1450
|
+
}));
|
|
1451
|
+
}
|
|
1452
|
+
fake;
|
|
1453
|
+
getPath;
|
|
1454
|
+
delete() {
|
|
1455
|
+
let actionMsg = '删除逻辑项';
|
|
1456
|
+
if (this.name)
|
|
1457
|
+
actionMsg += `“${this.name}”`;
|
|
1458
|
+
this.app?.emit('collect:start', {
|
|
1459
|
+
actionMsg,
|
|
1460
|
+
});
|
|
1461
|
+
super.delete();
|
|
1462
|
+
this.traverseChildren((el) => {
|
|
1463
|
+
if (el?.concept === 'CallQueryComponent')
|
|
1464
|
+
el.removeStructure();
|
|
1465
|
+
});
|
|
1466
|
+
this.app?.emit('collect:end');
|
|
1467
|
+
}
|
|
1468
|
+
// 是不是内部有错误
|
|
1469
|
+
haveError = false;
|
|
1470
|
+
// 是否body为空
|
|
1471
|
+
isSmpty = false;
|
|
1472
|
+
get pathName() {
|
|
1473
|
+
if (this.view) {
|
|
1474
|
+
return this.getEventLogicName('chinese');
|
|
1475
|
+
}
|
|
1476
|
+
const nameMap = {
|
|
1477
|
+
OnProcessStart: '流程开始时',
|
|
1478
|
+
OnTasksCreate: '任务创建时',
|
|
1479
|
+
OnTasksOpen: '任务打开时',
|
|
1480
|
+
OnTasksClose: '任务关闭时',
|
|
1481
|
+
OnCreate: '用户任务创建时',
|
|
1482
|
+
OnOpen: '用户任务打开时',
|
|
1483
|
+
OnClose: '用户任务关闭时',
|
|
1484
|
+
};
|
|
1485
|
+
const pathName = [this.name];
|
|
1486
|
+
let parentNode = this.parentNode;
|
|
1487
|
+
while (parentNode && parentNode.concept !== 'Process') {
|
|
1488
|
+
const name = nameMap[parentNode.name] || parentNode.name;
|
|
1489
|
+
pathName.unshift(name);
|
|
1490
|
+
parentNode = parentNode.parentNode;
|
|
1491
|
+
}
|
|
1492
|
+
return pathName.join('-');
|
|
1493
|
+
}
|
|
1494
|
+
// 获取bindEvent下的logic的名称
|
|
1495
|
+
getEventLogicName(type) {
|
|
1496
|
+
if (this.parentNode instanceof BindEvent__1.default) {
|
|
1497
|
+
if (type === 'chinese') {
|
|
1498
|
+
const bindEvent = this.parentNode;
|
|
1499
|
+
const bindChineseName = bindEvent.getPageViewEventChineseName();
|
|
1500
|
+
return `${bindChineseName}-${this.name}`;
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
return this.name;
|
|
1504
|
+
}
|
|
1505
|
+
// 虚拟输入参数列表
|
|
1506
|
+
virtualParams = [];
|
|
1507
|
+
get getLogicBelongTo() {
|
|
1508
|
+
const [, belongTo] = this.calleewholeKey.split('.');
|
|
1509
|
+
return belongTo;
|
|
1510
|
+
}
|
|
1511
|
+
// 校验logic的返回值是不是有error类型
|
|
1512
|
+
static checkLogicReturnTypeHasError(logic) {
|
|
1513
|
+
let findHasError = false;
|
|
1514
|
+
if (!logic) {
|
|
1515
|
+
return findHasError;
|
|
1516
|
+
}
|
|
1517
|
+
if (logic.returns?.length && logic.returns[0]?.typeAnnotation) {
|
|
1518
|
+
// 如果新导入的logic还有Error类型
|
|
1519
|
+
const logicType = logic.returns[0].typeAnnotation;
|
|
1520
|
+
if (logicType.typeNamespace === 'nasl.ui' && logicType.typeName === 'Error') {
|
|
1521
|
+
findHasError = true;
|
|
1522
|
+
}
|
|
1523
|
+
else if (logicType.typeNamespace === 'nasl.core' && logicType.typeKind === 'union') {
|
|
1524
|
+
// 如果 logic 有 returns 而且,也有typeArguments的长度
|
|
1525
|
+
findHasError = Boolean(logicType.typeArguments?.find((item) => (item?.typeNamespace === 'nasl.ui' && item?.typeName === 'Error')));
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
return findHasError;
|
|
1529
|
+
}
|
|
1530
|
+
get getIsEmptyLogic() {
|
|
1531
|
+
return this.body?.filter((node) => !['Start', 'End'].includes(node?.concept))?.length <= 0;
|
|
1532
|
+
}
|
|
1533
|
+
getOverriddenDepLogic() {
|
|
1534
|
+
const dep = this.app.dependencies?.find((dep) => dep.name === this.overriddenModule);
|
|
1535
|
+
if (dep) {
|
|
1536
|
+
const depLogic = dep?.logics?.find((l) => l.name === this.name);
|
|
1537
|
+
return depLogic || null;
|
|
1538
|
+
}
|
|
1539
|
+
else {
|
|
1540
|
+
return null;
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
};
|
|
1544
|
+
__decorate([
|
|
1545
|
+
(0, decorators_1.property)()
|
|
1546
|
+
], OverriddenLogic.prototype, "concept", void 0);
|
|
1547
|
+
__decorate([
|
|
1548
|
+
(0, decorators_1.property)()
|
|
1549
|
+
], OverriddenLogic.prototype, "overriddenModule", void 0);
|
|
1550
|
+
__decorate([
|
|
1551
|
+
(0, decorators_1.property)()
|
|
1552
|
+
], OverriddenLogic.prototype, "name", void 0);
|
|
1553
|
+
__decorate([
|
|
1554
|
+
(0, decorators_1.property)()
|
|
1555
|
+
], OverriddenLogic.prototype, "description", void 0);
|
|
1556
|
+
__decorate([
|
|
1557
|
+
(0, decorators_1.property)()
|
|
1558
|
+
], OverriddenLogic.prototype, "triggerType", void 0);
|
|
1559
|
+
__decorate([
|
|
1560
|
+
(0, decorators_1.property)()
|
|
1561
|
+
], OverriddenLogic.prototype, "cron", void 0);
|
|
1562
|
+
__decorate([
|
|
1563
|
+
(0, decorators_1.property)('Transactional')
|
|
1564
|
+
], OverriddenLogic.prototype, "transactional", void 0);
|
|
1565
|
+
__decorate([
|
|
1566
|
+
(0, decorators_1.property)()
|
|
1567
|
+
], OverriddenLogic.prototype, "compilerInfoMap", void 0);
|
|
1568
|
+
__decorate([
|
|
1569
|
+
(0, decorators_1.property)('TypeParam')
|
|
1570
|
+
], OverriddenLogic.prototype, "typeParams", void 0);
|
|
1571
|
+
__decorate([
|
|
1572
|
+
(0, decorators_1.property)('Param')
|
|
1573
|
+
], OverriddenLogic.prototype, "params", void 0);
|
|
1574
|
+
__decorate([
|
|
1575
|
+
(0, decorators_1.property)('Return')
|
|
1576
|
+
], OverriddenLogic.prototype, "returns", void 0);
|
|
1577
|
+
__decorate([
|
|
1578
|
+
(0, decorators_1.property)('Variable')
|
|
1579
|
+
], OverriddenLogic.prototype, "variables", void 0);
|
|
1580
|
+
__decorate([
|
|
1581
|
+
(0, decorators_1.property)('LogicItem')
|
|
1582
|
+
], OverriddenLogic.prototype, "body", void 0);
|
|
1583
|
+
__decorate([
|
|
1584
|
+
(0, decorators_1.property)('LogicItem')
|
|
1585
|
+
], OverriddenLogic.prototype, "playground", void 0);
|
|
1586
|
+
__decorate([
|
|
1587
|
+
(0, translator_1.withSourceMap)()
|
|
1588
|
+
], OverriddenLogic.prototype, "toEmbeddedTSInProcess", null);
|
|
1589
|
+
__decorate([
|
|
1590
|
+
(0, translator_1.withSourceMap)()
|
|
1591
|
+
], OverriddenLogic.prototype, "toEmbeddedTS", null);
|
|
1592
|
+
OverriddenLogic = OverriddenLogic_1 = __decorate([
|
|
1593
|
+
(0, decorators_1.concept)('逻辑')
|
|
1594
|
+
], OverriddenLogic);
|
|
1595
|
+
exports.OverriddenLogic = OverriddenLogic;
|
|
1596
|
+
classMap_1.default.OverriddenLogic = OverriddenLogic;
|
|
1597
|
+
exports.default = OverriddenLogic;
|
|
1598
|
+
//================================================================================
|
|
1599
|
+
// ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
|
|
1600
|
+
// 自动生成的代码已结束。下面可以手动编写。
|
|
1601
|
+
//================================================================================
|
|
1602
|
+
//# sourceMappingURL=OverriddenLogic__.js.map
|