@lcap/nasl 3.3.0-alpha.2 → 3.3.0-alpha.3
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/automate/upgrader/2.20.js.map +1 -1
- package/out/bak/translator.js +52 -1
- package/out/bak/translator.js.map +1 -1
- package/out/breakpoint/shared/utils.js +0 -2
- package/out/breakpoint/shared/utils.js.map +1 -1
- package/out/common/Command.d.ts +1 -0
- package/out/common/Command.js +9 -1
- package/out/common/Command.js.map +1 -1
- package/out/concepts/BindAttribute__.d.ts +2 -0
- package/out/concepts/BindAttribute__.js +77 -2
- package/out/concepts/BindAttribute__.js.map +1 -1
- package/out/concepts/BindEvent__.d.ts +2 -1
- package/out/concepts/BindEvent__.js +43 -36
- package/out/concepts/BindEvent__.js.map +1 -1
- package/out/concepts/CallLogic__.js +67 -10
- package/out/concepts/CallLogic__.js.map +1 -1
- package/out/concepts/CallQueryComponent__.d.ts +1 -1
- package/out/concepts/Connection__.js +9 -10
- package/out/concepts/Connection__.js.map +1 -1
- package/out/concepts/ForEachStatement__.js +25 -35
- package/out/concepts/ForEachStatement__.js.map +1 -1
- package/out/concepts/Logic__.js +1 -0
- package/out/concepts/Logic__.js.map +1 -1
- package/out/concepts/MemberExpression__.d.ts +1 -0
- package/out/concepts/MemberExpression__.js +115 -0
- package/out/concepts/MemberExpression__.js.map +1 -1
- package/out/concepts/Module__.d.ts +1 -1
- package/out/concepts/Module__.js +34 -35
- package/out/concepts/Module__.js.map +1 -1
- package/out/concepts/TypeAnnotation__.d.ts +4 -3
- package/out/concepts/TypeAnnotation__.js +114 -73
- package/out/concepts/TypeAnnotation__.js.map +1 -1
- package/out/concepts/ValidationRule__.d.ts +14 -14
- package/out/concepts/ValidationRule__.js +29 -25
- package/out/concepts/ValidationRule__.js.map +1 -1
- package/out/concepts/ViewElement__.d.ts +88 -87
- package/out/concepts/ViewElement__.js +268 -204
- package/out/concepts/ViewElement__.js.map +1 -1
- package/out/concepts/View__.d.ts +6 -0
- package/out/concepts/View__.js +252 -9
- package/out/concepts/View__.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.browser.js +1 -0
- package/out/concepts/basics/stdlib/nasl.browser.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.event.js +2 -0
- package/out/concepts/basics/stdlib/nasl.event.js.map +1 -1
- package/out/generator/genBundleFiles.js +90 -1
- package/out/generator/genBundleFiles.js.map +1 -1
- package/out/generator/genReleaseBody.js +1 -1
- package/out/generator/genReleaseBody.js.map +1 -1
- package/out/generator/permission.js +3 -3
- package/out/generator/permission.js.map +1 -1
- package/out/natural/genNaturalTS.js +7 -3
- package/out/natural/genNaturalTS.js.map +1 -1
- package/out/natural/transformTSCode.d.ts +1 -1
- package/out/natural/transformTSCode.js +115 -141
- package/out/natural/transformTSCode.js.map +1 -1
- package/out/server/extendBaseNode.js +69 -44
- package/out/server/extendBaseNode.js.map +1 -1
- package/out/server/formatTsUtils.js +72 -63
- package/out/server/formatTsUtils.js.map +1 -1
- package/out/server/getLogics.js +20 -23
- package/out/server/getLogics.js.map +1 -1
- package/out/server/getMemberIdentifier.d.ts +1 -0
- package/out/server/getMemberIdentifier.js +149 -1
- package/out/server/getMemberIdentifier.js.map +1 -1
- package/out/server/naslServer.d.ts +3 -3
- package/out/server/naslServer.js +182 -132
- package/out/server/naslServer.js.map +1 -1
- package/out/server/translator.js +43 -33
- package/out/server/translator.js.map +1 -1
- package/out/service/defaultErrorMessage.json +6 -6
- package/out/service/storage/init.js +16 -0
- package/out/service/storage/init.js.map +1 -1
- package/out/templator/genCreateBlock.js +5 -3
- package/out/templator/genCreateBlock.js.map +1 -1
- package/out/templator/genCurdEditMultipleKeyBlock.js +12 -8
- package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
- package/out/templator/genCurdMultipleKeyBlock.js +8 -7
- package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
- package/out/templator/genEditTableBlock.d.ts +1 -1
- package/out/templator/genEditTableBlock.js +12 -6
- package/out/templator/genEditTableBlock.js.map +1 -1
- package/out/templator/genEnumSelectBlock.js +2 -2
- package/out/templator/genEnumSelectBlock.js.map +1 -1
- package/out/templator/genGetBlock.js +1 -1
- package/out/templator/genGetBlock.js.map +1 -1
- package/out/templator/genGridViewBlock.d.ts +2 -2
- package/out/templator/genGridViewBlock.js +20 -7
- package/out/templator/genGridViewBlock.js.map +1 -1
- package/out/templator/genListViewBlock.d.ts +2 -2
- package/out/templator/genListViewBlock.js +13 -5
- package/out/templator/genListViewBlock.js.map +1 -1
- package/out/templator/genSelectBlock.d.ts +2 -2
- package/out/templator/genSelectBlock.js +8 -6
- package/out/templator/genSelectBlock.js.map +1 -1
- package/out/templator/genTableBlock.d.ts +1 -1
- package/out/templator/genTableBlock.js +10 -5
- package/out/templator/genTableBlock.js.map +1 -1
- package/out/templator/genUpdateBlock.js +5 -3
- package/out/templator/genUpdateBlock.js.map +1 -1
- package/package.json +2 -1
- package/sandbox/stdlib/nasl.auth.ts +40 -44
- package/sandbox/stdlib/nasl.core.ts +8 -1
- package/sandbox/stdlib/nasl.http.ts +22 -22
- package/sandbox-natural/stdlib/nasl.util.ts +74 -15
- package/src/automate/upgrader/2.20.js +17 -13
- package/src/bak/translator.js +50 -1
- package/src/breakpoint/shared/utils.ts +0 -2
- package/src/common/Command.ts +8 -0
- package/src/concepts/BindAttribute__.ts +67 -2
- package/src/concepts/BindEvent__.ts +43 -63
- package/src/concepts/CallLogic__.ts +66 -10
- package/src/concepts/Connection__.ts +14 -20
- package/src/concepts/ForEachStatement__.ts +32 -43
- package/src/concepts/Logic__.ts +1 -0
- package/src/concepts/MemberExpression__.ts +109 -1
- package/src/concepts/Module__.ts +41 -58
- package/src/concepts/TypeAnnotation__.ts +142 -122
- package/src/concepts/ValidationRule__.ts +553 -523
- package/src/concepts/ViewElement__.ts +2445 -2498
- package/src/concepts/View__.ts +256 -8
- package/src/concepts/basics/stdlib/nasl.browser.ts +1 -0
- package/src/concepts/basics/stdlib/nasl.event.ts +2 -0
- package/src/generator/genBundleFiles.ts +91 -1
- package/src/generator/genReleaseBody.ts +1 -1
- package/src/generator/permission.ts +3 -3
- package/src/natural/genNaturalTS.ts +8 -4
- package/src/natural/transformTSCode.ts +139 -151
- package/src/server/extendBaseNode.ts +71 -45
- package/src/server/formatTsUtils.ts +64 -64
- package/src/server/getLogics.ts +23 -30
- package/src/server/getMemberIdentifier.ts +143 -0
- package/src/server/naslServer.ts +174 -148
- package/src/server/translator.ts +40 -39
- package/src/service/defaultErrorMessage.json +6 -6
- package/src/service/storage/init.ts +17 -0
- package/src/templator/genCreateBlock.ts +5 -3
- package/src/templator/genCurdEditMultipleKeyBlock.ts +12 -8
- package/src/templator/genCurdMultipleKeyBlock.ts +8 -7
- package/src/templator/genEditTableBlock.ts +12 -7
- package/src/templator/genEnumSelectBlock.ts +2 -2
- package/src/templator/genGetBlock.ts +6 -6
- package/src/templator/genGridViewBlock.ts +22 -9
- package/src/templator/genListViewBlock.ts +14 -5
- package/src/templator/genSelectBlock.ts +8 -6
- package/src/templator/genTableBlock.ts +10 -9
- package/src/templator/genUpdateBlock.ts +5 -3
- package/test/concepts/validation-rule/__snapshots__/toEmbeddedTS.spec.ts.snap +11 -0
- package/test/concepts/validation-rule/__snapshots__/toJS.spec.ts.snap +10 -0
- package/test/concepts/validation-rule/fixtures/argument-without-keyword.json +34 -0
- package/test/concepts/validation-rule/fixtures/empty-rule.json +9 -0
- package/test/concepts/validation-rule/validation-rule.spec.ts +15 -0
|
@@ -3,13 +3,13 @@ import { TranslatorState, shiftState, withSourceMap, indent, createCompilerState
|
|
|
3
3
|
import Function from './Function__';
|
|
4
4
|
import { ElementToVueOptions } from './ViewElement__';
|
|
5
5
|
import { getValidationInFunction } from '../server/getFunctions';
|
|
6
|
-
import defaultErrorMessage
|
|
6
|
+
import defaultErrorMessage = require('../service/defaultErrorMessage.json');
|
|
7
7
|
import BindAttribute from './BindAttribute__';
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
//================================================================================
|
|
10
10
|
// 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
|
|
11
11
|
// ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
|
|
12
|
-
|
|
12
|
+
//================================================================================
|
|
13
13
|
import { EventPayload, Params } from '../common/EventEmitter';
|
|
14
14
|
import { concept, excludedInJSON, property } from '../decorators';
|
|
15
15
|
|
|
@@ -24,548 +24,578 @@ import LogicItem from './LogicItem__';
|
|
|
24
24
|
*/
|
|
25
25
|
@concept('验证规则')
|
|
26
26
|
export class ValidationRule extends LogicItem {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
getClassName() {
|
|
87
|
-
return 'ValidationRule';
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
static from(source: any, parentNode?: any, parentKey?: string): ValidationRule {
|
|
91
|
-
return super.from(source, parentNode, parentKey) as ValidationRule;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* 设置错误信息
|
|
96
|
-
*/
|
|
97
|
-
setErrorMessage(errorMessage: LogicItem) {
|
|
98
|
-
errorMessage._delete();
|
|
99
|
-
const relationOptions = { parentNode: this, parentKey: 'errorMessage' };
|
|
100
|
-
Object.assign(errorMessage, relationOptions);
|
|
101
|
-
const object = {
|
|
102
|
-
errorMessage,
|
|
103
|
-
};
|
|
104
|
-
this.update({
|
|
105
|
-
...object,
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* 设置验证对象
|
|
111
|
-
*/
|
|
112
|
-
setTarget(target: LogicItem) {
|
|
113
|
-
target._delete();
|
|
114
|
-
const relationOptions = { parentNode: this, parentKey: 'target' };
|
|
115
|
-
Object.assign(target, relationOptions);
|
|
116
|
-
const object = {
|
|
117
|
-
target,
|
|
118
|
-
};
|
|
119
|
-
this.update({
|
|
120
|
-
...object,
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* 设置是否启用服务端验证
|
|
126
|
-
*/
|
|
127
|
-
setEnableServerValidation(enableServerValidation: boolean) {
|
|
128
|
-
const object = {
|
|
129
|
-
enableServerValidation,
|
|
130
|
-
};
|
|
131
|
-
this.update({
|
|
132
|
-
...object,
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* 插入实际参数
|
|
138
|
-
* @internal
|
|
139
|
-
* @param argumentOptions 实际参数参数
|
|
140
|
-
*/
|
|
141
|
-
_insertArgumentAt(argumentOptions: Partial<Argument>, index: number): Argument;
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* 插入实际参数
|
|
145
|
-
* @internal
|
|
146
|
-
* @param argument 已有的实际参数实例
|
|
147
|
-
*/
|
|
148
|
-
_insertArgumentAt(argument: Argument, index: number): Argument;
|
|
149
|
-
|
|
150
|
-
_insertArgumentAt(options: Partial<Argument> | Argument, index: number) {
|
|
151
|
-
const argumentOptions: any = {};
|
|
152
|
-
const relationOptions = { parentNode: this, parentKey: 'arguments' };
|
|
153
|
-
let argument: Argument;
|
|
154
|
-
if (options instanceof Argument) {
|
|
155
|
-
options.ensureDelete(); // 同一实例不支持多处存在
|
|
156
|
-
argument = options;
|
|
157
|
-
Object.assign(argument, relationOptions);
|
|
158
|
-
} else {
|
|
159
|
-
argument = Argument.from(
|
|
160
|
-
{
|
|
161
|
-
...argumentOptions,
|
|
162
|
-
...options,
|
|
163
|
-
},
|
|
164
|
-
this,
|
|
165
|
-
'arguments'
|
|
166
|
-
);
|
|
27
|
+
/**
|
|
28
|
+
* 产品概念
|
|
29
|
+
*/
|
|
30
|
+
@property()
|
|
31
|
+
concept: 'ValidationRule' = 'ValidationRule';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 验证规则标题
|
|
35
|
+
*/
|
|
36
|
+
@property()
|
|
37
|
+
label: string = '验证规则';
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* calleeNamespace
|
|
41
|
+
*/
|
|
42
|
+
@property()
|
|
43
|
+
calleeNamespace: string = undefined;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* calleeName
|
|
47
|
+
*/
|
|
48
|
+
@property()
|
|
49
|
+
calleeName: string = undefined;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 实际参数
|
|
53
|
+
*/
|
|
54
|
+
@property('Argument')
|
|
55
|
+
arguments: Array<Argument> = [];
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 错误信息
|
|
59
|
+
*/
|
|
60
|
+
@property('LogicItem')
|
|
61
|
+
errorMessage: LogicItem = undefined;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 验证对象
|
|
65
|
+
*/
|
|
66
|
+
@property('LogicItem')
|
|
67
|
+
target: LogicItem = undefined;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 是否启用服务端验证
|
|
71
|
+
*/
|
|
72
|
+
@property()
|
|
73
|
+
enableServerValidation: boolean = true;
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @param source 需要合并的部分参数
|
|
79
|
+
*/
|
|
80
|
+
constructor(source?: Partial<ValidationRule>) {
|
|
81
|
+
source = Object.assign({}, ValidationRule.getDefaultOptions(), source);
|
|
82
|
+
super(source);
|
|
83
|
+
super.subConstructor(source);
|
|
167
84
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* 插入实际参数
|
|
174
|
-
* @param argumentOptions 实际参数参数
|
|
175
|
-
*/
|
|
176
|
-
insertArgumentAt(argumentOptions: Partial<Argument>, index: number): Argument;
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* 插入实际参数
|
|
180
|
-
* @param argument 已有的实际参数实例
|
|
181
|
-
*/
|
|
182
|
-
insertArgumentAt(argument: Argument, index: number): Argument;
|
|
183
|
-
|
|
184
|
-
insertArgumentAt(options: Partial<Argument> | Argument, index: number) {
|
|
185
|
-
const node = this._insertArgumentAt(options as any, index);
|
|
186
|
-
node.create({
|
|
187
|
-
index,
|
|
188
|
-
parentNode: this,
|
|
189
|
-
parentKey: 'arguments',
|
|
190
|
-
});
|
|
191
|
-
return node;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* 添加实际参数
|
|
196
|
-
* @internal
|
|
197
|
-
* @param argumentOptions 实际参数参数
|
|
198
|
-
*/
|
|
199
|
-
_addArgument(argumentOptions: Partial<Argument>): Argument;
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* 添加实际参数
|
|
203
|
-
* @internal
|
|
204
|
-
* @param argument 已有的实际参数实例
|
|
205
|
-
*/
|
|
206
|
-
_addArgument(argument: Argument): Argument;
|
|
207
|
-
|
|
208
|
-
_addArgument(options?: Partial<Argument> | Argument) {
|
|
209
|
-
const index = this.arguments.length;
|
|
210
|
-
return this._insertArgumentAt(options as any, index);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* 添加实际参数
|
|
215
|
-
* @param argumentOptions 实际参数参数
|
|
216
|
-
*/
|
|
217
|
-
addArgument(argumentOptions: Partial<Argument>): Argument;
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* 添加实际参数
|
|
221
|
-
* @param argument 已有的实际参数实例
|
|
222
|
-
*/
|
|
223
|
-
addArgument(argument: Argument): Argument;
|
|
224
|
-
|
|
225
|
-
addArgument(options?: Partial<Argument> | Argument) {
|
|
226
|
-
const node = this._addArgument(options as any);
|
|
227
|
-
const index = this.arguments.indexOf(node);
|
|
228
|
-
node.create({
|
|
229
|
-
index,
|
|
230
|
-
parentNode: this,
|
|
231
|
-
parentKey: 'arguments',
|
|
232
|
-
});
|
|
233
|
-
return node;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* 删除实际参数
|
|
238
|
-
* @param argument 已有的实际参数实例
|
|
239
|
-
*/
|
|
240
|
-
removeArgumentInArguments(argument: Argument): void;
|
|
241
|
-
|
|
242
|
-
removeArgumentInArguments(options: Argument) {
|
|
243
|
-
const argument: Argument = options;
|
|
244
|
-
return argument.delete();
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* 删除逻辑项
|
|
249
|
-
* @param name 逻辑项名称
|
|
250
|
-
*/
|
|
251
|
-
removeErrorMessage(name: string): void;
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* 删除逻辑项
|
|
255
|
-
* @param errorMessage 已有的逻辑项实例
|
|
256
|
-
*/
|
|
257
|
-
removeErrorMessage(errorMessage: LogicItem): void;
|
|
258
|
-
|
|
259
|
-
removeErrorMessage(options: string | LogicItem) {
|
|
260
|
-
let errorMessage: LogicItem;
|
|
261
|
-
if (typeof options === 'string') {
|
|
262
|
-
errorMessage = this.errorMessage;
|
|
263
|
-
if (!errorMessage) {
|
|
264
|
-
throw new Error(`找不到逻辑项 ${options}`);
|
|
265
|
-
}
|
|
266
|
-
} else {
|
|
267
|
-
errorMessage = options;
|
|
85
|
+
getClassName() {
|
|
86
|
+
return 'ValidationRule';
|
|
268
87
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* 删除逻辑项
|
|
274
|
-
* @param name 逻辑项名称
|
|
275
|
-
*/
|
|
276
|
-
removeTarget(name: string): void;
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* 删除逻辑项
|
|
280
|
-
* @param target 已有的逻辑项实例
|
|
281
|
-
*/
|
|
282
|
-
removeTarget(target: LogicItem): void;
|
|
283
|
-
|
|
284
|
-
removeTarget(options: string | LogicItem) {
|
|
285
|
-
let target: LogicItem;
|
|
286
|
-
if (typeof options === 'string') {
|
|
287
|
-
target = this.target;
|
|
288
|
-
if (!target) {
|
|
289
|
-
throw new Error(`找不到逻辑项 ${options}`);
|
|
290
|
-
}
|
|
291
|
-
} else {
|
|
292
|
-
target = options;
|
|
88
|
+
|
|
89
|
+
static from(source: any, parentNode?: any, parentKey?: string): ValidationRule {
|
|
90
|
+
return super.from(source, parentNode, parentKey) as ValidationRule;
|
|
293
91
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
const index = (this as any)[parentKey].indexOf(logicItem);
|
|
310
|
-
~index && (this as any)[parentKey].splice(index, 1);
|
|
311
|
-
params.index = index;
|
|
312
|
-
} else if ((this as any)[parentKey] === logicItem) {
|
|
313
|
-
params.index = 0;
|
|
314
|
-
(this as any)[parentKey] = undefined;
|
|
315
|
-
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 设置错误信息
|
|
96
|
+
*/
|
|
97
|
+
setErrorMessage(errorMessage: LogicItem) {
|
|
98
|
+
errorMessage._delete();
|
|
99
|
+
const relationOptions = { parentNode: this, parentKey: 'errorMessage' };
|
|
100
|
+
Object.assign(errorMessage, relationOptions);
|
|
101
|
+
const object = {
|
|
102
|
+
errorMessage,
|
|
103
|
+
};
|
|
104
|
+
this.update({
|
|
105
|
+
...object,
|
|
106
|
+
});
|
|
316
107
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
toInViewMethod() {
|
|
335
|
-
let code = '{';
|
|
336
|
-
// 兼容就得简写模式
|
|
337
|
-
if (this.calleeName && this.calleeName.includes('(')) {
|
|
338
|
-
return `'${this.calleeName}'`;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* 设置验证对象
|
|
111
|
+
*/
|
|
112
|
+
setTarget(target: LogicItem) {
|
|
113
|
+
target._delete();
|
|
114
|
+
const relationOptions = { parentNode: this, parentKey: 'target' };
|
|
115
|
+
Object.assign(target, relationOptions);
|
|
116
|
+
const object = {
|
|
117
|
+
target,
|
|
118
|
+
};
|
|
119
|
+
this.update({
|
|
120
|
+
...object,
|
|
121
|
+
});
|
|
339
122
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 设置是否启用服务端验证
|
|
126
|
+
*/
|
|
127
|
+
setEnableServerValidation(enableServerValidation: boolean) {
|
|
128
|
+
const object = {
|
|
129
|
+
enableServerValidation,
|
|
130
|
+
};
|
|
131
|
+
this.update({
|
|
132
|
+
...object,
|
|
133
|
+
});
|
|
346
134
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* 插入实际参数
|
|
142
|
+
* @internal
|
|
143
|
+
* @param argumentOptions 实际参数参数
|
|
144
|
+
*/
|
|
145
|
+
_insertArgumentAt(argumentOptions: Partial<Argument>, index: number): Argument;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 插入实际参数
|
|
149
|
+
* @internal
|
|
150
|
+
* @param argument 已有的实际参数实例
|
|
151
|
+
*/
|
|
152
|
+
_insertArgumentAt(argument: Argument, index: number): Argument;
|
|
153
|
+
|
|
154
|
+
_insertArgumentAt(options: Partial<Argument> | Argument, index: number) {
|
|
155
|
+
const argumentOptions: any = {};
|
|
156
|
+
const relationOptions = { parentNode: this, parentKey: 'arguments' };
|
|
157
|
+
let argument: Argument;
|
|
158
|
+
if (options instanceof Argument) {
|
|
159
|
+
options.ensureDelete(); // 同一实例不支持多处存在
|
|
160
|
+
argument = options;
|
|
161
|
+
Object.assign(argument, relationOptions);
|
|
162
|
+
} else {
|
|
163
|
+
argument = Argument.from({
|
|
164
|
+
...argumentOptions,
|
|
165
|
+
...options,
|
|
166
|
+
}, this, 'arguments');
|
|
167
|
+
}
|
|
168
|
+
this.arguments.splice(index, 0, argument);
|
|
169
|
+
return argument;
|
|
355
170
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* 插入实际参数
|
|
176
|
+
* @param argumentOptions 实际参数参数
|
|
177
|
+
*/
|
|
178
|
+
insertArgumentAt(argumentOptions: Partial<Argument>, index: number): Argument;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* 插入实际参数
|
|
182
|
+
* @param argument 已有的实际参数实例
|
|
183
|
+
*/
|
|
184
|
+
insertArgumentAt(argument: Argument, index: number): Argument;
|
|
185
|
+
|
|
186
|
+
insertArgumentAt(options: Partial<Argument> | Argument, index: number) {
|
|
187
|
+
const node = this._insertArgumentAt(options as any, index);
|
|
188
|
+
node.create({
|
|
189
|
+
index,
|
|
190
|
+
parentNode: this,
|
|
191
|
+
parentKey: 'arguments',
|
|
192
|
+
});
|
|
193
|
+
return node;
|
|
374
194
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* 添加实际参数
|
|
200
|
+
* @internal
|
|
201
|
+
* @param argumentOptions 实际参数参数
|
|
202
|
+
*/
|
|
203
|
+
_addArgument(argumentOptions: Partial<Argument>): Argument;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* 添加实际参数
|
|
207
|
+
* @internal
|
|
208
|
+
* @param argument 已有的实际参数实例
|
|
209
|
+
*/
|
|
210
|
+
_addArgument(argument: Argument): Argument;
|
|
211
|
+
|
|
212
|
+
_addArgument(options?: Partial<Argument> | Argument) {
|
|
213
|
+
const index = this.arguments.length;
|
|
214
|
+
return this._insertArgumentAt(options as any, index);
|
|
378
215
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* 添加实际参数
|
|
221
|
+
* @param argumentOptions 实际参数参数
|
|
222
|
+
*/
|
|
223
|
+
addArgument(argumentOptions: Partial<Argument>): Argument;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* 添加实际参数
|
|
227
|
+
* @param argument 已有的实际参数实例
|
|
228
|
+
*/
|
|
229
|
+
addArgument(argument: Argument): Argument;
|
|
230
|
+
|
|
231
|
+
addArgument(options?: Partial<Argument> | Argument) {
|
|
232
|
+
const node = this._addArgument(options as any);
|
|
233
|
+
const index = this.arguments.indexOf(node);
|
|
234
|
+
node.create({
|
|
235
|
+
index,
|
|
236
|
+
parentNode: this,
|
|
237
|
+
parentKey: 'arguments',
|
|
238
|
+
});
|
|
239
|
+
return node;
|
|
388
240
|
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* 删除实际参数
|
|
247
|
+
* @param argument 已有的实际参数实例
|
|
248
|
+
*/
|
|
249
|
+
removeArgumentInArguments(argument: Argument): void;
|
|
250
|
+
|
|
251
|
+
removeArgumentInArguments(options: Argument) {
|
|
252
|
+
let argument: Argument = options;
|
|
253
|
+
return argument.delete();
|
|
395
254
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* 删除逻辑项
|
|
260
|
+
* @param name 逻辑项名称
|
|
261
|
+
*/
|
|
262
|
+
removeErrorMessage(name: string): void;
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* 删除逻辑项
|
|
266
|
+
* @param errorMessage 已有的逻辑项实例
|
|
267
|
+
*/
|
|
268
|
+
removeErrorMessage(errorMessage: LogicItem): void;
|
|
269
|
+
|
|
270
|
+
removeErrorMessage(options: string | LogicItem) {
|
|
271
|
+
let errorMessage: LogicItem;
|
|
272
|
+
if (typeof options === 'string') {
|
|
273
|
+
errorMessage = this.errorMessage;
|
|
274
|
+
if (!errorMessage) {
|
|
275
|
+
throw new Error('找不到逻辑项 ' + options);
|
|
276
|
+
}
|
|
277
|
+
} else {
|
|
278
|
+
errorMessage = options;
|
|
279
|
+
}
|
|
280
|
+
return errorMessage.delete();
|
|
404
281
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* 删除逻辑项
|
|
287
|
+
* @param name 逻辑项名称
|
|
288
|
+
*/
|
|
289
|
+
removeTarget(name: string): void;
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* 删除逻辑项
|
|
293
|
+
* @param target 已有的逻辑项实例
|
|
294
|
+
*/
|
|
295
|
+
removeTarget(target: LogicItem): void;
|
|
296
|
+
|
|
297
|
+
removeTarget(options: string | LogicItem) {
|
|
298
|
+
let target: LogicItem;
|
|
299
|
+
if (typeof options === 'string') {
|
|
300
|
+
target = this.target;
|
|
301
|
+
if (!target) {
|
|
302
|
+
throw new Error('找不到逻辑项 ' + options);
|
|
303
|
+
}
|
|
304
|
+
} else {
|
|
305
|
+
target = options;
|
|
306
|
+
}
|
|
307
|
+
return target.delete();
|
|
423
308
|
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
309
|
+
|
|
310
|
+
__removeLogicItem(logicItem: LogicItem) {
|
|
311
|
+
const parentKey = logicItem.parentKey;
|
|
312
|
+
const params: Params = {
|
|
313
|
+
parentNode: this,
|
|
314
|
+
parentKey,
|
|
315
|
+
index: -1,
|
|
316
|
+
object: null,
|
|
317
|
+
oldObject: logicItem,
|
|
318
|
+
};
|
|
319
|
+
if (parentKey) {
|
|
320
|
+
params.parentKey = parentKey;
|
|
321
|
+
if (Array.isArray((this as any)[parentKey])) {
|
|
322
|
+
const index = (this as any)[parentKey].indexOf(logicItem);
|
|
323
|
+
~index && (this as any)[parentKey].splice(index, 1);
|
|
324
|
+
params.index = index;
|
|
325
|
+
} else if ((this as any)[parentKey] === logicItem) {
|
|
326
|
+
params.index = 0;
|
|
327
|
+
(this as any)[parentKey] = undefined;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return params;
|
|
427
331
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
332
|
+
|
|
333
|
+
//================================================================================
|
|
334
|
+
// ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
|
|
335
|
+
// 自动生成的代码已结束。下面可以手动编写。
|
|
336
|
+
//================================================================================
|
|
337
|
+
|
|
338
|
+
public static getDefaultOptions() {
|
|
339
|
+
return {
|
|
340
|
+
target: {
|
|
341
|
+
concept: 'Identifier',
|
|
342
|
+
name: '',
|
|
343
|
+
},
|
|
344
|
+
};
|
|
441
345
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
346
|
+
|
|
347
|
+
toInViewMethod() {
|
|
348
|
+
let code = '{';
|
|
349
|
+
// 兼容就得简写模式
|
|
350
|
+
if (this.calleeName && this.calleeName.includes('(')) {
|
|
351
|
+
return `'${this.calleeName}'`;
|
|
352
|
+
} else if (this.calleeName === 'unique') {
|
|
353
|
+
code += `validate: 'excluded',`;
|
|
354
|
+
} else if (this.calleeName === 'confirmed') {
|
|
355
|
+
code += `validate: 'is',`;
|
|
356
|
+
} else {
|
|
357
|
+
code += `validate: '${this.calleeName}',`;
|
|
358
|
+
}
|
|
359
|
+
if (this.arguments.length) {
|
|
360
|
+
let args = '[';
|
|
361
|
+
this.arguments?.forEach((arg, index) => {
|
|
362
|
+
args += arg?.toJS();
|
|
363
|
+
if (index !== this.arguments?.length - 1)
|
|
364
|
+
args += ', ';
|
|
365
|
+
});
|
|
366
|
+
args += ']';
|
|
367
|
+
code += `args: ${args} ,`;
|
|
368
|
+
}
|
|
369
|
+
if (this.errorMessage) {
|
|
370
|
+
code += `message: ${this.errorMessage?.toJS()},`;
|
|
371
|
+
} else {
|
|
372
|
+
let defaultError = (defaultErrorMessage as Record<string, string>)[this.calleeName];
|
|
373
|
+
let index = 0;
|
|
374
|
+
while (defaultError && defaultError.indexOf(`{args}`) !== -1) {
|
|
375
|
+
defaultError = defaultError.replace(`{args}`, `\${${this.arguments[index]?.toJS()}}`);
|
|
376
|
+
index++;
|
|
377
|
+
}
|
|
378
|
+
const itemTitle = (this?.parentNode as any)?.parentNode?.bindAttrs?.find((item: BindAttribute) => item.name === 'label');
|
|
379
|
+
let labelName;
|
|
380
|
+
if (itemTitle?.expression?.toJS()) {
|
|
381
|
+
labelName = `\${${itemTitle?.expression?.toJS()}}`;
|
|
382
|
+
} else {
|
|
383
|
+
labelName = itemTitle?.value || '表单项';
|
|
384
|
+
}
|
|
385
|
+
defaultError = defaultError && defaultError.replace(`{label}`, labelName);
|
|
386
|
+
code += `message: \`${defaultError}\`,`;
|
|
387
|
+
}
|
|
388
|
+
code += `trigger: 'input+blur'`;
|
|
389
|
+
if (['required', 'filled', 'notEmpty'].includes(this.calleeName)) {
|
|
390
|
+
code += ',required: true';
|
|
391
|
+
}
|
|
392
|
+
code += '}';
|
|
393
|
+
return code;
|
|
456
394
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
395
|
+
|
|
396
|
+
toVue(options?: ElementToVueOptions) {
|
|
397
|
+
let code = '{';
|
|
398
|
+
// 兼容就得简写模式
|
|
399
|
+
if (this.calleeName && this.calleeName.includes('(')) {
|
|
400
|
+
return `'${this.calleeName}'`;
|
|
401
|
+
} else if (this.calleeName === 'unique') {
|
|
402
|
+
code += `validate: 'excluded',`;
|
|
403
|
+
} else if (this.calleeName === 'confirmed') {
|
|
404
|
+
code += `validate: 'is',`;
|
|
405
|
+
} else {
|
|
406
|
+
code += `validate: '${this.calleeName}',`;
|
|
407
|
+
}
|
|
408
|
+
if (this.arguments.length) {
|
|
409
|
+
let args = '[';
|
|
410
|
+
this.arguments?.forEach((arg, index) => {
|
|
411
|
+
args += arg?.toVue(options);
|
|
412
|
+
if (index !== this.arguments?.length - 1)
|
|
413
|
+
args += ', ';
|
|
414
|
+
});
|
|
415
|
+
args += ']';
|
|
416
|
+
code += `args: ${args} ,`;
|
|
417
|
+
}
|
|
418
|
+
if (this.errorMessage) {
|
|
419
|
+
code += `message: ${this.errorMessage?.toVue(options)},`;
|
|
420
|
+
} else {
|
|
421
|
+
let defaultError = (defaultErrorMessage as Record<string, string>)[this.calleeName];
|
|
422
|
+
let index = 0;
|
|
423
|
+
while (defaultError && defaultError.indexOf(`{args}`) !== -1) {
|
|
424
|
+
defaultError = defaultError.replace(`{args}`, `\${${this.arguments[index]?.toVue(options)}}`);
|
|
425
|
+
index++;
|
|
426
|
+
}
|
|
427
|
+
const itemTitle = (this?.parentNode as any)?.parentNode?.bindAttrs?.find((item: BindAttribute) => item.name === 'label');
|
|
428
|
+
let labelName;
|
|
429
|
+
if (itemTitle?.expression?.toVue()) {
|
|
430
|
+
labelName = `\${${itemTitle?.expression?.toVue()}}`;
|
|
431
|
+
} else {
|
|
432
|
+
labelName = itemTitle?.value || '表单项';
|
|
433
|
+
}
|
|
434
|
+
defaultError = defaultError && defaultError.replace(`{label}`, labelName);
|
|
435
|
+
code += `message: \`${defaultError}\`,`;
|
|
436
|
+
}
|
|
437
|
+
code += `trigger: 'input+blur'`;
|
|
438
|
+
if (['required', 'filled', 'notEmpty'].includes(this.calleeName)) {
|
|
439
|
+
code += ',required: true';
|
|
440
|
+
}
|
|
441
|
+
code += '}';
|
|
442
|
+
return code;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
toUI(state?: TranslatorState): string {
|
|
446
|
+
let code = this.calleeName;
|
|
447
|
+
if (this.arguments?.length) {
|
|
448
|
+
code += '(';
|
|
449
|
+
this.arguments?.forEach((arg, index) => {
|
|
450
|
+
code += arg?.toUI(shiftState(state, code));
|
|
451
|
+
if (index !== this.arguments?.length - 1)
|
|
452
|
+
code += ', ';
|
|
453
|
+
});
|
|
454
|
+
code += ')';
|
|
455
|
+
}
|
|
456
|
+
return code;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
toJS(state?: TranslatorState): string {
|
|
460
|
+
let code = '{';
|
|
461
|
+
code += `validate: '${this.calleeName}',`;
|
|
462
|
+
if (this.arguments.length) {
|
|
463
|
+
let args = '[';
|
|
464
|
+
this.arguments?.forEach((arg, index) => {
|
|
465
|
+
args += arg?.toJS(shiftState(state, code));
|
|
466
|
+
if (index !== this.arguments?.length - 1)
|
|
467
|
+
args += ', ';
|
|
468
|
+
});
|
|
469
|
+
args += ']';
|
|
470
|
+
code += `args: ${args},`;
|
|
471
|
+
}
|
|
472
|
+
code += `trigger: 'input+blur',`;
|
|
473
|
+
code += `message: ${this.errorMessage?.toJS(shiftState(state, code))}`;
|
|
474
|
+
code += '}';
|
|
475
|
+
return code;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
@withSourceMap()
|
|
479
|
+
toEmbeddedTS(state?: TranslatorState): string {
|
|
480
|
+
let code = '';
|
|
481
|
+
|
|
482
|
+
const {
|
|
483
|
+
calleeName,
|
|
484
|
+
target,
|
|
485
|
+
calleeKey,
|
|
486
|
+
arguments: args,
|
|
487
|
+
errorMessage,
|
|
488
|
+
view,
|
|
489
|
+
} = this;
|
|
490
|
+
|
|
491
|
+
if (calleeName) {
|
|
492
|
+
// 调用逻辑时绑定的验证器
|
|
493
|
+
if (this.getAncestor('CallLogic') || !view) {
|
|
494
|
+
code += target.toEmbeddedTS(shiftState(state, code));
|
|
495
|
+
code += ';\n';
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
if (args.length > 0) {
|
|
499
|
+
const validationInFunction = getValidationInFunction(calleeName);
|
|
500
|
+
code += calleeKey;
|
|
501
|
+
code += '(';
|
|
502
|
+
args.forEach((arg, index) => {
|
|
503
|
+
const param = validationInFunction?.params?.[index];
|
|
504
|
+
|
|
505
|
+
// 当前参数缺失 keyword,且原始形参中有名称,则补充参数
|
|
506
|
+
if (!arg.keyword && param.name) {
|
|
507
|
+
arg.keyword = param.name;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// 如果找到函数而且有参数,就用参数的必填非必填
|
|
511
|
+
if (validationInFunction && param) {
|
|
512
|
+
code += arg.toEmbeddedTS(shiftState(state, code), param.required, false);
|
|
513
|
+
}
|
|
514
|
+
// 如果没有就默认不必填
|
|
515
|
+
else {
|
|
516
|
+
code += arg.toEmbeddedTS(shiftState(state, code), false, false);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
if (index !== args.length - 1) {
|
|
520
|
+
code += ', ';
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
code += ');';
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
if (errorMessage) {
|
|
527
|
+
code += 'nasl.validation.errorMessage(';
|
|
528
|
+
code += errorMessage.toEmbeddedTS(shiftState(state, code));
|
|
529
|
+
code += ')';
|
|
530
|
+
}
|
|
531
|
+
} else {
|
|
532
|
+
code += '__ValidationRule__';
|
|
533
|
+
}
|
|
534
|
+
return code;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
toBrief(): string {
|
|
538
|
+
return this.arguments.map((a) => a.toBrief()).join('<br />');
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
get calleeKey(): string {
|
|
542
|
+
return `${this.calleeNamespace}.${this.calleeName}`;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
_setCallee(func: Function) {
|
|
546
|
+
this.calleeNamespace = func.getNamespace();
|
|
547
|
+
this.calleeName = func.name;
|
|
548
|
+
this.arguments = [];
|
|
549
|
+
func.params.forEach((param) => {
|
|
550
|
+
this._addArgument(undefined);
|
|
489
551
|
});
|
|
490
|
-
code += ');';
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
if (errorMessage) {
|
|
494
|
-
code += 'nasl.validation.errorMessage(';
|
|
495
|
-
code += errorMessage.toEmbeddedTS(shiftState(state, code));
|
|
496
|
-
code += ')';
|
|
497
|
-
}
|
|
498
|
-
} else {
|
|
499
|
-
code += '__IDENTIFIER__';
|
|
500
552
|
}
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
actionMsg: `切换调用逻辑`,
|
|
538
|
-
});
|
|
539
|
-
const { parentNode } = this;
|
|
540
|
-
this.update({
|
|
541
|
-
calleeNamespace,
|
|
542
|
-
calleeName,
|
|
543
|
-
arguments: params,
|
|
544
|
-
folded: false,
|
|
545
|
-
});
|
|
546
|
-
if (parentNode.concept === 'MemberExpression' && 'firstMemberExpressionNode' in parentNode) {
|
|
547
|
-
const topNode = parentNode.firstMemberExpressionNode();
|
|
548
|
-
topNode.replaceNode(this);
|
|
549
|
-
}
|
|
550
|
-
this.app.emit('collect:end');
|
|
551
|
-
} else {
|
|
552
|
-
this.update({
|
|
553
|
-
calleeNamespace,
|
|
554
|
-
calleeName,
|
|
555
|
-
arguments: params,
|
|
556
|
-
folded: false,
|
|
557
|
-
});
|
|
553
|
+
|
|
554
|
+
setCallee(func: Function) {
|
|
555
|
+
const calleeNamespace = func.getNamespace();
|
|
556
|
+
const calleeName = func.name;
|
|
557
|
+
const params = func.params.map((param) => {
|
|
558
|
+
const relationOptions = { parentNode: this, parentKey: 'arguments' };
|
|
559
|
+
const argument = Argument.from({
|
|
560
|
+
keyword: param.name,
|
|
561
|
+
}, this);
|
|
562
|
+
Object.assign(argument, relationOptions);
|
|
563
|
+
return argument;
|
|
564
|
+
});
|
|
565
|
+
if (this.app) {
|
|
566
|
+
this.app.emit('collect:start', {
|
|
567
|
+
actionMsg: `切换调用逻辑`,
|
|
568
|
+
});
|
|
569
|
+
const parentNode: any = this.parentNode;
|
|
570
|
+
this.update({
|
|
571
|
+
calleeNamespace,
|
|
572
|
+
calleeName,
|
|
573
|
+
arguments: params,
|
|
574
|
+
folded: false,
|
|
575
|
+
});
|
|
576
|
+
if (parentNode.concept === 'MemberExpression') {
|
|
577
|
+
const topNode = parentNode.firstMemberExpressionNode();
|
|
578
|
+
topNode.replaceNode(this);
|
|
579
|
+
}
|
|
580
|
+
this.app.emit('collect:end');
|
|
581
|
+
} else {
|
|
582
|
+
this.update({
|
|
583
|
+
calleeNamespace,
|
|
584
|
+
calleeName,
|
|
585
|
+
arguments: params,
|
|
586
|
+
folded: false,
|
|
587
|
+
});
|
|
588
|
+
}
|
|
558
589
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
//= ===============================================================================
|
|
590
|
+
//================================================================================
|
|
591
|
+
// 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
|
|
592
|
+
// ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
|
|
593
|
+
//================================================================================
|
|
564
594
|
}
|
|
565
595
|
|
|
566
596
|
classMap.ValidationRule = ValidationRule;
|
|
567
597
|
export default ValidationRule;
|
|
568
|
-
|
|
598
|
+
//================================================================================
|
|
569
599
|
// ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
|
|
570
600
|
// 自动生成的代码已结束。下面可以手动编写。
|
|
571
|
-
|
|
601
|
+
//================================================================================
|