@lcap/nasl 2.18.0 → 2.19.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/automate/template/myProcess.js +1 -1
- package/out/automate/template/myProcess.js.map +1 -1
- package/out/bak/translator.js +2 -1
- package/out/bak/translator.js.map +1 -1
- package/out/common/BaseNode.js +1 -0
- package/out/common/BaseNode.js.map +1 -1
- package/out/common/Command.d.ts +1 -0
- package/out/common/Command.js +5 -1
- package/out/common/Command.js.map +1 -1
- package/out/concepts/AnonymousFunction__.d.ts +1 -0
- package/out/concepts/AnonymousFunction__.js +40 -2
- package/out/concepts/AnonymousFunction__.js.map +1 -1
- package/out/concepts/App__.d.ts +10 -0
- package/out/concepts/App__.js +132 -0
- package/out/concepts/App__.js.map +1 -1
- package/out/concepts/Assignee__.js +4 -3
- package/out/concepts/Assignee__.js.map +1 -1
- package/out/concepts/BatchAssignment__.d.ts +2 -0
- package/out/concepts/BatchAssignment__.js +108 -47
- package/out/concepts/BatchAssignment__.js.map +1 -1
- package/out/concepts/BindAttribute__.js +8 -1
- package/out/concepts/BindAttribute__.js.map +1 -1
- package/out/concepts/CallFunction__.js +51 -18
- package/out/concepts/CallFunction__.js.map +1 -1
- package/out/concepts/CallInterface__.js +6 -4
- package/out/concepts/CallInterface__.js.map +1 -1
- package/out/concepts/CallLogic__.d.ts +2 -1
- package/out/concepts/CallLogic__.js +113 -26
- package/out/concepts/CallLogic__.js.map +1 -1
- package/out/concepts/CallQueryComponent__.js +4 -1
- package/out/concepts/CallQueryComponent__.js.map +1 -1
- package/out/concepts/DataSource__.d.ts +2 -0
- package/out/concepts/DataSource__.js +55 -1
- package/out/concepts/DataSource__.js.map +1 -1
- package/out/concepts/Destination__.d.ts +2 -1
- package/out/concepts/Destination__.js +90 -22
- package/out/concepts/Destination__.js.map +1 -1
- package/out/concepts/ForEachStatement__.js +2 -0
- package/out/concepts/ForEachStatement__.js.map +1 -1
- package/out/concepts/Identifier__.d.ts +1 -0
- package/out/concepts/Identifier__.js +18 -7
- package/out/concepts/Identifier__.js.map +1 -1
- package/out/concepts/LogicItem__.d.ts +1 -1
- package/out/concepts/LogicItem__.js.map +1 -1
- package/out/concepts/Logic__.d.ts +1 -0
- package/out/concepts/Logic__.js +33 -21
- package/out/concepts/Logic__.js.map +1 -1
- package/out/concepts/Match__.js +13 -8
- package/out/concepts/Match__.js.map +1 -1
- package/out/concepts/NewComposite__.d.ts +345 -0
- package/out/concepts/NewComposite__.js +1067 -0
- package/out/concepts/NewComposite__.js.map +1 -0
- package/out/concepts/NewList__.d.ts +130 -0
- package/out/concepts/NewList__.js +353 -0
- package/out/concepts/NewList__.js.map +1 -0
- package/out/concepts/NewMap__.d.ts +221 -0
- package/out/concepts/NewMap__.js +492 -0
- package/out/concepts/NewMap__.js.map +1 -0
- package/out/concepts/New__.d.ts +19 -0
- package/out/concepts/New__.js +66 -0
- package/out/concepts/New__.js.map +1 -0
- package/out/concepts/Param__.d.ts +2 -0
- package/out/concepts/Param__.js +40 -3
- package/out/concepts/Param__.js.map +1 -1
- package/out/concepts/ProcessElement__.js +31 -10
- package/out/concepts/ProcessElement__.js.map +1 -1
- package/out/concepts/ProcessOutcome__.js +1 -1
- package/out/concepts/ProcessOutcome__.js.map +1 -1
- package/out/concepts/ProcessOutcomes__.d.ts +30 -0
- package/out/concepts/{ConstructArgument__.js → ProcessOutcomes__.js} +27 -48
- package/out/concepts/ProcessOutcomes__.js.map +1 -0
- package/out/concepts/Return__.js +2 -1
- package/out/concepts/Return__.js.map +1 -1
- package/out/concepts/SelectMembers__.js +3 -3
- package/out/concepts/SelectMembers__.js.map +1 -1
- package/out/concepts/StringInterpolation__.js +12 -2
- package/out/concepts/StringInterpolation__.js.map +1 -1
- package/out/concepts/TypeAnnotation__.d.ts +4 -0
- package/out/concepts/TypeAnnotation__.js +66 -12
- package/out/concepts/TypeAnnotation__.js.map +1 -1
- package/out/concepts/ValidationRule__.js +1 -1
- package/out/concepts/ValidationRule__.js.map +1 -1
- package/out/concepts/Variable__.js +2 -1
- package/out/concepts/Variable__.js.map +1 -1
- package/out/concepts/ViewElement__.js +13 -1
- package/out/concepts/ViewElement__.js.map +1 -1
- package/out/concepts/View__.d.ts +1 -0
- package/out/concepts/View__.js +13 -0
- package/out/concepts/View__.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.auth.js +1 -1
- package/out/concepts/basics/stdlib/nasl.auth.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.logging.js +5 -0
- package/out/concepts/basics/stdlib/nasl.logging.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.ui.js +2 -0
- package/out/concepts/basics/stdlib/nasl.ui.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.util.js +151 -19
- package/out/concepts/basics/stdlib/nasl.util.js.map +1 -1
- package/out/concepts/index__.d.ts +5 -0
- package/out/concepts/index__.js +5 -0
- package/out/concepts/index__.js.map +1 -1
- package/out/enums/KEYWORDS.js +1 -0
- package/out/enums/KEYWORDS.js.map +1 -1
- package/out/generator/genBundleFiles.js +32 -182
- package/out/generator/genBundleFiles.js.map +1 -1
- package/out/generator/genMetaData.d.ts +1 -10
- package/out/generator/genMetaData.js +184 -50
- package/out/generator/genMetaData.js.map +1 -1
- package/out/generator/genReleaseBody.d.ts +2 -0
- package/out/generator/genReleaseBody.js +29 -3
- package/out/generator/genReleaseBody.js.map +1 -1
- package/out/generator/index.d.ts +1 -0
- package/out/generator/index.js +1 -0
- package/out/generator/index.js.map +1 -1
- package/out/generator/permission.d.ts +9 -0
- package/out/generator/permission.js +235 -0
- package/out/generator/permission.js.map +1 -0
- package/out/index.d.ts +1 -1
- package/out/index.js +2 -1
- package/out/index.js.map +1 -1
- package/out/server/entity2LogicNamespace.js +69 -9
- package/out/server/entity2LogicNamespace.js.map +1 -1
- package/out/server/extendBaseNode.js +10 -20
- package/out/server/extendBaseNode.js.map +1 -1
- package/out/server/formatTsUtils.d.ts +1 -2
- package/out/server/formatTsUtils.js +36 -47
- package/out/server/formatTsUtils.js.map +1 -1
- package/out/server/getLogics.d.ts +2 -1
- package/out/server/getLogics.js +11 -0
- package/out/server/getLogics.js.map +1 -1
- package/out/server/getMemberIdentifier.js +1 -1
- package/out/server/getMemberIdentifier.js.map +1 -1
- package/out/server/getProcesses.js +1 -1
- package/out/server/getProcesses.js.map +1 -1
- package/out/server/naslServer.d.ts +1 -1
- package/out/server/naslServer.js +181 -35
- package/out/server/naslServer.js.map +1 -1
- package/out/server/process2LogicNamespace.js +8 -0
- package/out/server/process2LogicNamespace.js.map +1 -1
- package/out/server/translator.js +66 -6
- package/out/server/translator.js.map +1 -1
- package/out/service/creator/add.configs.js +4 -0
- package/out/service/creator/add.configs.js.map +1 -1
- package/out/service/datasource/api.d.ts +12 -0
- package/out/service/datasource/api.js +14 -0
- package/out/service/datasource/api.js.map +1 -0
- package/out/service/datasource/index.d.ts +2 -0
- package/out/service/datasource/index.js +10 -0
- package/out/service/datasource/index.js.map +1 -0
- package/out/service/storage/init.js +8 -1
- package/out/service/storage/init.js.map +1 -1
- package/out/templator/genEditTableBlock.js +4 -5
- package/out/templator/genEditTableBlock.js.map +1 -1
- package/out/templator/genGetBlock.js +4 -3
- package/out/templator/genGetBlock.js.map +1 -1
- package/out/templator/genGridViewBlock.js +16 -14
- package/out/templator/genGridViewBlock.js.map +1 -1
- package/out/templator/genListViewBlock.js +5 -5
- package/out/templator/genListViewBlock.js.map +1 -1
- package/out/templator/genTableBlock.js +6 -10
- package/out/templator/genTableBlock.js.map +1 -1
- package/package.json +1 -1
- package/sandbox/stdlib/dist/nasl.logging.js +0 -0
- package/sandbox/stdlib/dist/nasl.util.js +0 -0
- package/sandbox/stdlib/nasl.auth.ts +1 -1
- package/sandbox/stdlib/nasl.core.ts +4 -0
- package/sandbox/stdlib/nasl.logging.ts +4 -4
- package/sandbox/stdlib/nasl.util.ts +14 -5
- package/src/automate/template/myProcess.js +1 -1
- package/src/bak/translator.js +4 -1
- package/src/common/BaseNode.ts +1 -0
- package/src/common/Command.ts +4 -0
- package/src/concepts/AnonymousFunction__.ts +48 -2
- package/src/concepts/App__.ts +140 -41
- package/src/concepts/Assignee__.ts +4 -3
- package/src/concepts/BatchAssignment__.ts +111 -51
- package/src/concepts/BindAttribute__.ts +9 -2
- package/src/concepts/CallFunction__.ts +65 -31
- package/src/concepts/CallInterface__.ts +6 -22
- package/src/concepts/CallLogic__.ts +88 -24
- package/src/concepts/CallQueryComponent__.ts +4 -1
- package/src/concepts/DataSource__.ts +56 -1
- package/src/concepts/Destination__.ts +92 -22
- package/src/concepts/ForEachStatement__.ts +2 -0
- package/src/concepts/Identifier__.ts +18 -7
- package/src/concepts/LogicItem__.ts +1 -1
- package/src/concepts/Logic__.ts +54 -39
- package/src/concepts/Match__.ts +12 -8
- package/src/concepts/NewComposite__.ts +1356 -0
- package/src/concepts/NewList__.ts +444 -0
- package/src/concepts/NewMap__.ts +678 -0
- package/src/concepts/New__.ts +73 -0
- package/src/concepts/Param__.ts +238 -199
- package/src/concepts/ProcessElement__.ts +32 -10
- package/src/concepts/ProcessOutcome__.ts +1 -1
- package/src/concepts/ProcessOutcomes__.ts +90 -0
- package/src/concepts/Return__.ts +4 -1
- package/src/concepts/SelectMembers__.ts +3 -3
- package/src/concepts/StringInterpolation__.ts +21 -11
- package/src/concepts/TypeAnnotation__.ts +71 -50
- package/src/concepts/ValidationRule__.ts +19 -1
- package/src/concepts/Variable__.ts +4 -1
- package/src/concepts/ViewElement__.ts +23 -7
- package/src/concepts/View__.ts +16 -2
- package/src/concepts/basics/stdlib/dist/nasl.util.js +1602 -0
- package/src/concepts/basics/stdlib/nasl.auth.ts +1 -1
- package/src/concepts/basics/stdlib/nasl.logging.ts +5 -0
- package/src/concepts/basics/stdlib/nasl.ui.ts +2 -0
- package/src/concepts/basics/stdlib/nasl.util.ts +153 -19
- package/src/concepts/dist/BindAttribute__.js +760 -0
- package/src/concepts/dist/BindEvent__.js +732 -0
- package/src/concepts/dist/CallFunction__.js +82 -28
- package/src/concepts/dist/CallLogic__.js +95 -27
- package/src/concepts/dist/Identifier__.js +311 -0
- package/src/concepts/dist/StringInterpolation__.js +231 -0
- package/src/concepts/dist/TypeAnnotation__.js +834 -0
- package/src/concepts/dist/ViewElement__.js +1692 -0
- package/src/concepts/dist/View__.js +1601 -0
- package/src/concepts/index__.ts +5 -0
- package/src/enums/KEYWORDS.ts +1 -0
- package/src/generator/dist/genBundleFiles.js +23 -176
- package/src/generator/dist/genMetaData.js +245 -0
- package/src/generator/dist/permission.js +392 -0
- package/src/generator/genBundleFiles.ts +34 -219
- package/src/generator/genMetaData.ts +177 -77
- package/src/generator/genReleaseBody.ts +30 -5
- package/src/generator/index.ts +1 -0
- package/src/generator/permission.ts +271 -0
- package/src/index.ts +1 -1
- package/src/server/dist/naslServer.js +443 -249
- package/src/server/entity2LogicNamespace.ts +70 -10
- package/src/server/extendBaseNode.ts +10 -21
- package/src/server/formatTsUtils.ts +36 -46
- package/src/server/getLogics.ts +13 -1
- package/src/server/getMemberIdentifier.ts +1 -1
- package/src/server/getProcesses.ts +1 -1
- package/src/server/naslServer.ts +181 -42
- package/src/server/process2LogicNamespace.ts +8 -0
- package/src/server/translator.ts +64 -7
- package/src/service/creator/add.configs.js +4 -0
- package/src/service/dataSource/api.js +11 -0
- package/src/service/dataSource/index.js +6 -0
- package/src/service/storage/dist/init.js +48 -10
- package/src/service/storage/init.ts +9 -2
- package/src/service/video/VideoTranscribe.js +1 -0
- package/src/templator/dist/genEditTableBlock.js +204 -0
- package/src/templator/dist/genGridViewBlock.js +265 -0
- package/src/templator/dist/genListViewBlock.js +84 -0
- package/src/templator/dist/genTableBlock.js +209 -0
- package/src/templator/dist/utils.js +527 -0
- package/src/templator/genEditTableBlock.ts +8 -16
- package/src/templator/genGetBlock.ts +18 -19
- package/src/templator/genGridViewBlock.ts +18 -18
- package/src/templator/genListViewBlock.ts +8 -11
- package/src/templator/genTableBlock.ts +6 -10
- package/ts-worker/dist/webpack.config.dev.js +3 -1
- package/ts-worker/lib/tsserver.js +8 -1
- package/out/automate/engine/2.14-components.d.ts +0 -1115
- package/out/automate/engine/2.14-components.js +0 -1087
- package/out/automate/engine/2.14-components.js.map +0 -1
- package/out/concepts/ConstructArgument__.d.ts +0 -40
- package/out/concepts/ConstructArgument__.js.map +0 -1
- package/out/concepts/Construct__.d.ts +0 -189
- package/out/concepts/Construct__.js +0 -340
- package/out/concepts/Construct__.js.map +0 -1
- package/out/concepts/MatchExpression__.d.ts +0 -97
- package/out/concepts/MatchExpression__.js +0 -281
- package/out/concepts/MatchExpression__.js.map +0 -1
- package/out/templator/sql-parser/index.d.ts +0 -1
- package/out/templator/sql-parser/index.js +0 -228
- package/out/templator/sql-parser/index.js.map +0 -1
- package/out/templator/sql-parser/parser.js +0 -26664
- package/out/templator/sql-parser/parser.js.map +0 -1
- package/src/concepts/dist/Anchor__.js +0 -179
- package/src/concepts/dist/Assignment__.js +0 -301
- package/src/concepts/dist/CallInterface__.js +0 -533
- package/src/concepts/dist/ForEachStatement__.js +0 -426
- package/src/concepts/dist/MatchCase__.js +0 -587
- package/src/concepts/dist/MemberExpression__.js +0 -348
- package/src/concepts/dist/Param__.js +0 -537
- package/src/concepts/dist/Return__.js +0 -493
- package/src/server/dist/formatTsUtils.js +0 -683
- package/ts-worker/lib/dist/tsserver.dev.js +0 -22953
- package/ts-worker/sources/lib/dist/tsserver.dev.js +0 -22912
|
@@ -0,0 +1,1356 @@
|
|
|
1
|
+
import { TranslatorState, shiftState, withSourceMap} from '../translator';
|
|
2
|
+
import { ElementToVueOptions } from './ViewElement__';
|
|
3
|
+
import MemberExpression from './MemberExpression__';
|
|
4
|
+
import StructureProperty from './StructureProperty__';
|
|
5
|
+
import App from './App__';
|
|
6
|
+
//================================================================================
|
|
7
|
+
// 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
|
|
8
|
+
// ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
|
|
9
|
+
//================================================================================
|
|
10
|
+
import { EventPayload, Params } from '../common/EventEmitter';
|
|
11
|
+
import { concept, excludedInJSON, property } from '../decorators';
|
|
12
|
+
|
|
13
|
+
import * as utils from '../utils';
|
|
14
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
15
|
+
import BaseNode from '../common/BaseNode';
|
|
16
|
+
import classMap from '../common/classMap';
|
|
17
|
+
import TypeAnnotation from './TypeAnnotation__';
|
|
18
|
+
import Identifier from './Identifier__';
|
|
19
|
+
import SelectMembers from './SelectMembers__';
|
|
20
|
+
import AssignmentLine from './AssignmentLine__';
|
|
21
|
+
import LogicItem from './LogicItem__';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 实体/(匿名)数据结构构造器
|
|
25
|
+
*/
|
|
26
|
+
@concept('实体/(匿名)数据结构构造器')
|
|
27
|
+
export class NewComposite extends LogicItem {
|
|
28
|
+
/**
|
|
29
|
+
* 产品概念
|
|
30
|
+
*/
|
|
31
|
+
@property()
|
|
32
|
+
concept: 'NewComposite' = 'NewComposite';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 类型
|
|
36
|
+
*/
|
|
37
|
+
@property('TypeAnnotation')
|
|
38
|
+
typeAnnotation: TypeAnnotation = undefined;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 左边项
|
|
42
|
+
*/
|
|
43
|
+
@property('Identifier')
|
|
44
|
+
properties: Array<Identifier> = [];
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 右边项
|
|
48
|
+
*/
|
|
49
|
+
@property('SelectMembers')
|
|
50
|
+
rights: Array<SelectMembers> = [];
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 赋值线
|
|
54
|
+
*/
|
|
55
|
+
@property('AssignmentLine')
|
|
56
|
+
assignmentLines: Array<AssignmentLine> = [];
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* hideProperties
|
|
60
|
+
*/
|
|
61
|
+
@property()
|
|
62
|
+
hideProperties: boolean = false;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* hideDefaults
|
|
66
|
+
*/
|
|
67
|
+
@property()
|
|
68
|
+
hideDefaults: boolean = false;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 自动连线
|
|
72
|
+
*/
|
|
73
|
+
@property()
|
|
74
|
+
autoConnection: boolean = true;
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @param source 需要合并的部分参数
|
|
80
|
+
*/
|
|
81
|
+
constructor(source?: Partial<NewComposite>) {
|
|
82
|
+
source = Object.assign({}, NewComposite.getDefaultOptions(), source);
|
|
83
|
+
super(source);
|
|
84
|
+
super.subConstructor(source);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
static from(source: any, parentNode?: any, parentKey?: string): NewComposite {
|
|
88
|
+
return super.from(source, parentNode, parentKey) as NewComposite;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 设置类型
|
|
94
|
+
*/
|
|
95
|
+
setTypeAnnotation(typeAnnotation: TypeAnnotation) {
|
|
96
|
+
typeAnnotation._delete();
|
|
97
|
+
const relationOptions = { parentNode: this, parentKey: 'typeAnnotation' };
|
|
98
|
+
Object.assign(typeAnnotation, relationOptions);
|
|
99
|
+
const object = {
|
|
100
|
+
typeAnnotation,
|
|
101
|
+
};
|
|
102
|
+
this.update({
|
|
103
|
+
...object,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 设置左边项
|
|
109
|
+
*/
|
|
110
|
+
setProperties(properties: Array<Identifier>) {
|
|
111
|
+
const object = {
|
|
112
|
+
properties,
|
|
113
|
+
};
|
|
114
|
+
this.update({
|
|
115
|
+
...object,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* 设置右边项
|
|
121
|
+
*/
|
|
122
|
+
setRights(rights: Array<SelectMembers>) {
|
|
123
|
+
const object = {
|
|
124
|
+
rights,
|
|
125
|
+
};
|
|
126
|
+
this.update({
|
|
127
|
+
...object,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 设置赋值线
|
|
133
|
+
*/
|
|
134
|
+
setAssignmentLines(assignmentLines: Array<AssignmentLine>) {
|
|
135
|
+
const object = {
|
|
136
|
+
assignmentLines,
|
|
137
|
+
};
|
|
138
|
+
this.update({
|
|
139
|
+
...object,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 设置hideProperties
|
|
145
|
+
*/
|
|
146
|
+
setHideProperties(hideProperties: boolean) {
|
|
147
|
+
const object = {
|
|
148
|
+
hideProperties,
|
|
149
|
+
};
|
|
150
|
+
this.update({
|
|
151
|
+
...object,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* 设置hideDefaults
|
|
157
|
+
*/
|
|
158
|
+
setHideDefaults(hideDefaults: boolean) {
|
|
159
|
+
const object = {
|
|
160
|
+
hideDefaults,
|
|
161
|
+
};
|
|
162
|
+
this.update({
|
|
163
|
+
...object,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* 设置自动连线
|
|
169
|
+
*/
|
|
170
|
+
setAutoConnection(autoConnection: boolean) {
|
|
171
|
+
const object = {
|
|
172
|
+
autoConnection,
|
|
173
|
+
};
|
|
174
|
+
this.update({
|
|
175
|
+
...object,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
getIdentifierExistingNames(excludedList: Array<Identifier> = []) {
|
|
180
|
+
const excludedSet = new Set(excludedList);
|
|
181
|
+
return ((this.properties as Identifier[]) || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
|
|
182
|
+
}
|
|
183
|
+
getIdentifierUniqueName(name = 'identifier1') {
|
|
184
|
+
return utils.unique(name, this.getIdentifierExistingNames(), undefined, false);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* 插入标识符
|
|
189
|
+
* @internal
|
|
190
|
+
* @param name 标识符名称,如果不填会自动生成一个唯一名称
|
|
191
|
+
*/
|
|
192
|
+
_insertIdentifierAt(name: string, index: number): Identifier;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* 插入标识符
|
|
196
|
+
* @internal
|
|
197
|
+
* @param identifierOptions 标识符参数
|
|
198
|
+
*/
|
|
199
|
+
_insertIdentifierAt(identifierOptions: Partial<Identifier>, index: number): Identifier;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* 插入标识符
|
|
203
|
+
* @internal
|
|
204
|
+
* @param identifier 已有的标识符实例
|
|
205
|
+
*/
|
|
206
|
+
_insertIdentifierAt(identifier: Identifier, index: number): Identifier;
|
|
207
|
+
|
|
208
|
+
_insertIdentifierAt(options: string | Partial<Identifier> | Identifier, index: number) {
|
|
209
|
+
const identifierOptions: any = {};
|
|
210
|
+
const relationOptions = { parentNode: this, parentKey: 'properties' };
|
|
211
|
+
let identifier: Identifier;
|
|
212
|
+
if (!options) {
|
|
213
|
+
identifier = Identifier.from({
|
|
214
|
+
...identifierOptions,
|
|
215
|
+
name: this.getIdentifierUniqueName(),
|
|
216
|
+
}, this, 'properties');
|
|
217
|
+
} else if (typeof options === 'string') {
|
|
218
|
+
identifier = Identifier.from({
|
|
219
|
+
...identifierOptions,
|
|
220
|
+
name: options,
|
|
221
|
+
}, this, 'properties');
|
|
222
|
+
} else if (options instanceof Identifier) {
|
|
223
|
+
options.ensureDelete(); // 同一实例不支持多处存在
|
|
224
|
+
identifier = options;
|
|
225
|
+
Object.assign(identifier, relationOptions);
|
|
226
|
+
} else {
|
|
227
|
+
identifier = Identifier.from({
|
|
228
|
+
...identifierOptions,
|
|
229
|
+
...options,
|
|
230
|
+
}, this, 'properties');
|
|
231
|
+
}
|
|
232
|
+
this.properties.splice(index, 0, identifier);
|
|
233
|
+
return identifier;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* 插入标识符
|
|
238
|
+
* @param name 标识符名称,如果不填会自动生成一个唯一名称
|
|
239
|
+
*/
|
|
240
|
+
insertIdentifierAt(name: string, index: number): Identifier;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* 插入标识符
|
|
244
|
+
* @param identifierOptions 标识符参数
|
|
245
|
+
*/
|
|
246
|
+
insertIdentifierAt(identifierOptions: Partial<Identifier>, index: number): Identifier;
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* 插入标识符
|
|
250
|
+
* @param identifier 已有的标识符实例
|
|
251
|
+
*/
|
|
252
|
+
insertIdentifierAt(identifier: Identifier, index: number): Identifier;
|
|
253
|
+
|
|
254
|
+
insertIdentifierAt(options: string | Partial<Identifier> | Identifier, index: number) {
|
|
255
|
+
const node = this._insertIdentifierAt(options as any, index);
|
|
256
|
+
node.create({
|
|
257
|
+
index,
|
|
258
|
+
parentNode: this,
|
|
259
|
+
parentKey: 'properties',
|
|
260
|
+
});
|
|
261
|
+
return node;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* 添加标识符
|
|
266
|
+
* @internal
|
|
267
|
+
* @param name 标识符名称,如果不填会自动生成一个唯一名称
|
|
268
|
+
*/
|
|
269
|
+
_addIdentifier(name?: string): Identifier;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* 添加标识符
|
|
273
|
+
* @internal
|
|
274
|
+
* @param identifierOptions 标识符参数
|
|
275
|
+
*/
|
|
276
|
+
_addIdentifier(identifierOptions: Partial<Identifier>): Identifier;
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* 添加标识符
|
|
280
|
+
* @internal
|
|
281
|
+
* @param identifier 已有的标识符实例
|
|
282
|
+
*/
|
|
283
|
+
_addIdentifier(identifier: Identifier): Identifier;
|
|
284
|
+
|
|
285
|
+
_addIdentifier(options?: string | Partial<Identifier> | Identifier) {
|
|
286
|
+
const index = this.properties.length;
|
|
287
|
+
return this._insertIdentifierAt(options as any, index);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* 添加标识符
|
|
292
|
+
* @internal
|
|
293
|
+
* @param name 标识符名称,如果不填会自动生成一个唯一名称
|
|
294
|
+
*/
|
|
295
|
+
addIdentifier(name?: string): Identifier;
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* 添加标识符
|
|
299
|
+
* @param identifierOptions 标识符参数
|
|
300
|
+
*/
|
|
301
|
+
addIdentifier(identifierOptions: Partial<Identifier>): Identifier;
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* 添加标识符
|
|
305
|
+
* @param identifier 已有的标识符实例
|
|
306
|
+
*/
|
|
307
|
+
addIdentifier(identifier: Identifier): Identifier;
|
|
308
|
+
|
|
309
|
+
addIdentifier(options?: string | Partial<Identifier> | Identifier) {
|
|
310
|
+
const node = this._addIdentifier(options as any);
|
|
311
|
+
const index = this.properties.indexOf(node);
|
|
312
|
+
node.create({
|
|
313
|
+
index,
|
|
314
|
+
parentNode: this,
|
|
315
|
+
parentKey: 'properties',
|
|
316
|
+
});
|
|
317
|
+
return node;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
getSelectMembersExistingNames(excludedList: Array<SelectMembers> = []) {
|
|
322
|
+
const excludedSet = new Set(excludedList);
|
|
323
|
+
return ((this.rights as SelectMembers[]) || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
|
|
324
|
+
}
|
|
325
|
+
getSelectMembersUniqueName(name = 'selectMembers1') {
|
|
326
|
+
return utils.unique(name, this.getSelectMembersExistingNames(), undefined, false);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* 插入选择成员
|
|
331
|
+
* @internal
|
|
332
|
+
* @param name 选择成员名称,如果不填会自动生成一个唯一名称
|
|
333
|
+
*/
|
|
334
|
+
_insertSelectMembersAt(name: string, index: number): SelectMembers;
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* 插入选择成员
|
|
338
|
+
* @internal
|
|
339
|
+
* @param selectMembersOptions 选择成员参数
|
|
340
|
+
*/
|
|
341
|
+
_insertSelectMembersAt(selectMembersOptions: Partial<SelectMembers>, index: number): SelectMembers;
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* 插入选择成员
|
|
345
|
+
* @internal
|
|
346
|
+
* @param selectMembers 已有的选择成员实例
|
|
347
|
+
*/
|
|
348
|
+
_insertSelectMembersAt(selectMembers: SelectMembers, index: number): SelectMembers;
|
|
349
|
+
|
|
350
|
+
_insertSelectMembersAt(options: string | Partial<SelectMembers> | SelectMembers, index: number) {
|
|
351
|
+
const selectMembersOptions: any = {};
|
|
352
|
+
const relationOptions = { parentNode: this, parentKey: 'rights' };
|
|
353
|
+
let selectMembers: SelectMembers;
|
|
354
|
+
if (!options) {
|
|
355
|
+
selectMembers = SelectMembers.from({
|
|
356
|
+
...selectMembersOptions,
|
|
357
|
+
name: this.getSelectMembersUniqueName(),
|
|
358
|
+
}, this, 'rights');
|
|
359
|
+
} else if (typeof options === 'string') {
|
|
360
|
+
selectMembers = SelectMembers.from({
|
|
361
|
+
...selectMembersOptions,
|
|
362
|
+
name: options,
|
|
363
|
+
}, this, 'rights');
|
|
364
|
+
} else if (options instanceof SelectMembers) {
|
|
365
|
+
options.ensureDelete(); // 同一实例不支持多处存在
|
|
366
|
+
selectMembers = options;
|
|
367
|
+
Object.assign(selectMembers, relationOptions);
|
|
368
|
+
} else {
|
|
369
|
+
selectMembers = SelectMembers.from({
|
|
370
|
+
...selectMembersOptions,
|
|
371
|
+
...options,
|
|
372
|
+
}, this, 'rights');
|
|
373
|
+
}
|
|
374
|
+
this.rights.splice(index, 0, selectMembers);
|
|
375
|
+
return selectMembers;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* 插入选择成员
|
|
380
|
+
* @param name 选择成员名称,如果不填会自动生成一个唯一名称
|
|
381
|
+
*/
|
|
382
|
+
insertSelectMembersAt(name: string, index: number): SelectMembers;
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* 插入选择成员
|
|
386
|
+
* @param selectMembersOptions 选择成员参数
|
|
387
|
+
*/
|
|
388
|
+
insertSelectMembersAt(selectMembersOptions: Partial<SelectMembers>, index: number): SelectMembers;
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* 插入选择成员
|
|
392
|
+
* @param selectMembers 已有的选择成员实例
|
|
393
|
+
*/
|
|
394
|
+
insertSelectMembersAt(selectMembers: SelectMembers, index: number): SelectMembers;
|
|
395
|
+
|
|
396
|
+
insertSelectMembersAt(options: string | Partial<SelectMembers> | SelectMembers, index: number) {
|
|
397
|
+
const node = this._insertSelectMembersAt(options as any, index);
|
|
398
|
+
node.create({
|
|
399
|
+
index,
|
|
400
|
+
parentNode: this,
|
|
401
|
+
parentKey: 'rights',
|
|
402
|
+
});
|
|
403
|
+
return node;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* 添加选择成员
|
|
408
|
+
* @internal
|
|
409
|
+
* @param name 选择成员名称,如果不填会自动生成一个唯一名称
|
|
410
|
+
*/
|
|
411
|
+
_addSelectMembers(name?: string): SelectMembers;
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* 添加选择成员
|
|
415
|
+
* @internal
|
|
416
|
+
* @param selectMembersOptions 选择成员参数
|
|
417
|
+
*/
|
|
418
|
+
_addSelectMembers(selectMembersOptions: Partial<SelectMembers>): SelectMembers;
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* 添加选择成员
|
|
422
|
+
* @internal
|
|
423
|
+
* @param selectMembers 已有的选择成员实例
|
|
424
|
+
*/
|
|
425
|
+
_addSelectMembers(selectMembers: SelectMembers): SelectMembers;
|
|
426
|
+
|
|
427
|
+
_addSelectMembers(options?: string | Partial<SelectMembers> | SelectMembers) {
|
|
428
|
+
const index = this.rights.length;
|
|
429
|
+
return this._insertSelectMembersAt(options as any, index);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* 添加选择成员
|
|
434
|
+
* @internal
|
|
435
|
+
* @param name 选择成员名称,如果不填会自动生成一个唯一名称
|
|
436
|
+
*/
|
|
437
|
+
addSelectMembers(name?: string): SelectMembers;
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* 添加选择成员
|
|
441
|
+
* @param selectMembersOptions 选择成员参数
|
|
442
|
+
*/
|
|
443
|
+
addSelectMembers(selectMembersOptions: Partial<SelectMembers>): SelectMembers;
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* 添加选择成员
|
|
447
|
+
* @param selectMembers 已有的选择成员实例
|
|
448
|
+
*/
|
|
449
|
+
addSelectMembers(selectMembers: SelectMembers): SelectMembers;
|
|
450
|
+
|
|
451
|
+
addSelectMembers(options?: string | Partial<SelectMembers> | SelectMembers) {
|
|
452
|
+
const node = this._addSelectMembers(options as any);
|
|
453
|
+
const index = this.rights.indexOf(node);
|
|
454
|
+
node.create({
|
|
455
|
+
index,
|
|
456
|
+
parentNode: this,
|
|
457
|
+
parentKey: 'rights',
|
|
458
|
+
});
|
|
459
|
+
return node;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
getAssignmentLineExistingNames(excludedList: Array<AssignmentLine> = []) {
|
|
464
|
+
const excludedSet = new Set(excludedList);
|
|
465
|
+
return ((this.assignmentLines as AssignmentLine[]) || []).filter((item) => !excludedSet.has(item)).map((item) => item.name);
|
|
466
|
+
}
|
|
467
|
+
getAssignmentLineUniqueName(name = 'assignmentLine1') {
|
|
468
|
+
return utils.unique(name, this.getAssignmentLineExistingNames(), undefined, false);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* 插入赋值连线
|
|
473
|
+
* @internal
|
|
474
|
+
* @param name 赋值连线名称,如果不填会自动生成一个唯一名称
|
|
475
|
+
*/
|
|
476
|
+
_insertAssignmentLineAt(name: string, index: number): AssignmentLine;
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* 插入赋值连线
|
|
480
|
+
* @internal
|
|
481
|
+
* @param assignmentLineOptions 赋值连线参数
|
|
482
|
+
*/
|
|
483
|
+
_insertAssignmentLineAt(assignmentLineOptions: Partial<AssignmentLine>, index: number): AssignmentLine;
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* 插入赋值连线
|
|
487
|
+
* @internal
|
|
488
|
+
* @param assignmentLine 已有的赋值连线实例
|
|
489
|
+
*/
|
|
490
|
+
_insertAssignmentLineAt(assignmentLine: AssignmentLine, index: number): AssignmentLine;
|
|
491
|
+
|
|
492
|
+
_insertAssignmentLineAt(options: string | Partial<AssignmentLine> | AssignmentLine, index: number) {
|
|
493
|
+
const assignmentLineOptions: any = {};
|
|
494
|
+
const relationOptions = { parentNode: this, parentKey: 'assignmentLines' };
|
|
495
|
+
let assignmentLine: AssignmentLine;
|
|
496
|
+
if (!options) {
|
|
497
|
+
assignmentLine = AssignmentLine.from({
|
|
498
|
+
...assignmentLineOptions,
|
|
499
|
+
name: this.getAssignmentLineUniqueName(),
|
|
500
|
+
}, this, 'assignmentLines');
|
|
501
|
+
} else if (typeof options === 'string') {
|
|
502
|
+
assignmentLine = AssignmentLine.from({
|
|
503
|
+
...assignmentLineOptions,
|
|
504
|
+
name: options,
|
|
505
|
+
}, this, 'assignmentLines');
|
|
506
|
+
} else if (options instanceof AssignmentLine) {
|
|
507
|
+
options.ensureDelete(); // 同一实例不支持多处存在
|
|
508
|
+
assignmentLine = options;
|
|
509
|
+
Object.assign(assignmentLine, relationOptions);
|
|
510
|
+
} else {
|
|
511
|
+
assignmentLine = AssignmentLine.from({
|
|
512
|
+
...assignmentLineOptions,
|
|
513
|
+
...options,
|
|
514
|
+
}, this, 'assignmentLines');
|
|
515
|
+
}
|
|
516
|
+
this.assignmentLines.splice(index, 0, assignmentLine);
|
|
517
|
+
return assignmentLine;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* 插入赋值连线
|
|
522
|
+
* @param name 赋值连线名称,如果不填会自动生成一个唯一名称
|
|
523
|
+
*/
|
|
524
|
+
insertAssignmentLineAt(name: string, index: number): AssignmentLine;
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* 插入赋值连线
|
|
528
|
+
* @param assignmentLineOptions 赋值连线参数
|
|
529
|
+
*/
|
|
530
|
+
insertAssignmentLineAt(assignmentLineOptions: Partial<AssignmentLine>, index: number): AssignmentLine;
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* 插入赋值连线
|
|
534
|
+
* @param assignmentLine 已有的赋值连线实例
|
|
535
|
+
*/
|
|
536
|
+
insertAssignmentLineAt(assignmentLine: AssignmentLine, index: number): AssignmentLine;
|
|
537
|
+
|
|
538
|
+
insertAssignmentLineAt(options: string | Partial<AssignmentLine> | AssignmentLine, index: number) {
|
|
539
|
+
const node = this._insertAssignmentLineAt(options as any, index);
|
|
540
|
+
node.create({
|
|
541
|
+
index,
|
|
542
|
+
parentNode: this,
|
|
543
|
+
parentKey: 'assignmentLines',
|
|
544
|
+
});
|
|
545
|
+
return node;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* 添加赋值连线
|
|
550
|
+
* @internal
|
|
551
|
+
* @param name 赋值连线名称,如果不填会自动生成一个唯一名称
|
|
552
|
+
*/
|
|
553
|
+
_addAssignmentLine(name?: string): AssignmentLine;
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* 添加赋值连线
|
|
557
|
+
* @internal
|
|
558
|
+
* @param assignmentLineOptions 赋值连线参数
|
|
559
|
+
*/
|
|
560
|
+
_addAssignmentLine(assignmentLineOptions: Partial<AssignmentLine>): AssignmentLine;
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* 添加赋值连线
|
|
564
|
+
* @internal
|
|
565
|
+
* @param assignmentLine 已有的赋值连线实例
|
|
566
|
+
*/
|
|
567
|
+
_addAssignmentLine(assignmentLine: AssignmentLine): AssignmentLine;
|
|
568
|
+
|
|
569
|
+
_addAssignmentLine(options?: string | Partial<AssignmentLine> | AssignmentLine) {
|
|
570
|
+
const index = this.assignmentLines.length;
|
|
571
|
+
return this._insertAssignmentLineAt(options as any, index);
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* 添加赋值连线
|
|
576
|
+
* @internal
|
|
577
|
+
* @param name 赋值连线名称,如果不填会自动生成一个唯一名称
|
|
578
|
+
*/
|
|
579
|
+
addAssignmentLine(name?: string): AssignmentLine;
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* 添加赋值连线
|
|
583
|
+
* @param assignmentLineOptions 赋值连线参数
|
|
584
|
+
*/
|
|
585
|
+
addAssignmentLine(assignmentLineOptions: Partial<AssignmentLine>): AssignmentLine;
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* 添加赋值连线
|
|
589
|
+
* @param assignmentLine 已有的赋值连线实例
|
|
590
|
+
*/
|
|
591
|
+
addAssignmentLine(assignmentLine: AssignmentLine): AssignmentLine;
|
|
592
|
+
|
|
593
|
+
addAssignmentLine(options?: string | Partial<AssignmentLine> | AssignmentLine) {
|
|
594
|
+
const node = this._addAssignmentLine(options as any);
|
|
595
|
+
const index = this.assignmentLines.indexOf(node);
|
|
596
|
+
node.create({
|
|
597
|
+
index,
|
|
598
|
+
parentNode: this,
|
|
599
|
+
parentKey: 'assignmentLines',
|
|
600
|
+
});
|
|
601
|
+
return node;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* 删除类型标注
|
|
609
|
+
* @param name 类型标注名称
|
|
610
|
+
*/
|
|
611
|
+
removeTypeAnnotation(name: string): void;
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* 删除类型标注
|
|
615
|
+
* @param typeAnnotation 已有的类型标注实例
|
|
616
|
+
*/
|
|
617
|
+
removeTypeAnnotation(typeAnnotation: TypeAnnotation): void;
|
|
618
|
+
|
|
619
|
+
removeTypeAnnotation(options: string | TypeAnnotation) {
|
|
620
|
+
let typeAnnotation: TypeAnnotation;
|
|
621
|
+
if (typeof options === 'string') {
|
|
622
|
+
typeAnnotation = this.typeAnnotation;
|
|
623
|
+
if (!typeAnnotation) {
|
|
624
|
+
throw new Error('找不到类型标注 ' + options);
|
|
625
|
+
}
|
|
626
|
+
} else {
|
|
627
|
+
typeAnnotation = options;
|
|
628
|
+
}
|
|
629
|
+
return typeAnnotation.delete();
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
__removeTypeAnnotation(typeAnnotation: TypeAnnotation) {
|
|
633
|
+
const parentKey = typeAnnotation.parentKey;
|
|
634
|
+
const params: Params = {
|
|
635
|
+
parentNode: this,
|
|
636
|
+
parentKey,
|
|
637
|
+
index: -1,
|
|
638
|
+
object: null,
|
|
639
|
+
oldObject: typeAnnotation,
|
|
640
|
+
};
|
|
641
|
+
if (parentKey) {
|
|
642
|
+
params.parentKey = parentKey;
|
|
643
|
+
if (Array.isArray((this as any)[parentKey])) {
|
|
644
|
+
const index = (this as any)[parentKey].indexOf(typeAnnotation);
|
|
645
|
+
~index && (this as any)[parentKey].splice(index, 1);
|
|
646
|
+
params.index = index;
|
|
647
|
+
} else if ((this as any)[parentKey] === typeAnnotation) {
|
|
648
|
+
params.index = 0;
|
|
649
|
+
(this as any)[parentKey] = undefined;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
return params;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* 删除标识符
|
|
659
|
+
* @param name 标识符名称
|
|
660
|
+
*/
|
|
661
|
+
removeIdentifier(name: string): void;
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* 删除标识符
|
|
665
|
+
* @param identifier 已有的标识符实例
|
|
666
|
+
*/
|
|
667
|
+
removeIdentifier(identifier: Identifier): void;
|
|
668
|
+
|
|
669
|
+
removeIdentifier(options: string | Identifier) {
|
|
670
|
+
let identifier: Identifier;
|
|
671
|
+
if (typeof options === 'string') {
|
|
672
|
+
identifier = (this.properties as Identifier[]).find((item) => item.name === options);
|
|
673
|
+
if (!identifier) {
|
|
674
|
+
throw new Error('找不到标识符 ' + options);
|
|
675
|
+
}
|
|
676
|
+
} else {
|
|
677
|
+
identifier = options;
|
|
678
|
+
}
|
|
679
|
+
return identifier.delete();
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
__removeLogicItem(logicItem: LogicItem) {
|
|
683
|
+
const parentKey = logicItem.parentKey;
|
|
684
|
+
const params: Params = {
|
|
685
|
+
parentNode: this,
|
|
686
|
+
parentKey,
|
|
687
|
+
index: -1,
|
|
688
|
+
object: null,
|
|
689
|
+
oldObject: logicItem,
|
|
690
|
+
};
|
|
691
|
+
if (parentKey) {
|
|
692
|
+
params.parentKey = parentKey;
|
|
693
|
+
if (Array.isArray((this as any)[parentKey])) {
|
|
694
|
+
const index = (this as any)[parentKey].indexOf(logicItem);
|
|
695
|
+
~index && (this as any)[parentKey].splice(index, 1);
|
|
696
|
+
params.index = index;
|
|
697
|
+
} else if ((this as any)[parentKey] === logicItem) {
|
|
698
|
+
params.index = 0;
|
|
699
|
+
(this as any)[parentKey] = undefined;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
return params;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* 删除选择成员
|
|
709
|
+
* @param name 选择成员名称
|
|
710
|
+
*/
|
|
711
|
+
removeSelectMembers(name: string): void;
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* 删除选择成员
|
|
715
|
+
* @param selectMembers 已有的选择成员实例
|
|
716
|
+
*/
|
|
717
|
+
removeSelectMembers(selectMembers: SelectMembers): void;
|
|
718
|
+
|
|
719
|
+
removeSelectMembers(options: string | SelectMembers) {
|
|
720
|
+
let selectMembers: SelectMembers;
|
|
721
|
+
if (typeof options === 'string') {
|
|
722
|
+
selectMembers = (this.rights as SelectMembers[]).find((item) => item.name === options);
|
|
723
|
+
if (!selectMembers) {
|
|
724
|
+
throw new Error('找不到选择成员 ' + options);
|
|
725
|
+
}
|
|
726
|
+
} else {
|
|
727
|
+
selectMembers = options;
|
|
728
|
+
}
|
|
729
|
+
return selectMembers.delete();
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
__removeSelectMembers(selectMembers: SelectMembers) {
|
|
733
|
+
const parentKey = selectMembers.parentKey;
|
|
734
|
+
const params: Params = {
|
|
735
|
+
parentNode: this,
|
|
736
|
+
parentKey,
|
|
737
|
+
index: -1,
|
|
738
|
+
object: null,
|
|
739
|
+
oldObject: selectMembers,
|
|
740
|
+
};
|
|
741
|
+
if (parentKey) {
|
|
742
|
+
params.parentKey = parentKey;
|
|
743
|
+
if (Array.isArray((this as any)[parentKey])) {
|
|
744
|
+
const index = (this as any)[parentKey].indexOf(selectMembers);
|
|
745
|
+
~index && (this as any)[parentKey].splice(index, 1);
|
|
746
|
+
params.index = index;
|
|
747
|
+
} else if ((this as any)[parentKey] === selectMembers) {
|
|
748
|
+
params.index = 0;
|
|
749
|
+
(this as any)[parentKey] = undefined;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
return params;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
/**
|
|
758
|
+
* 删除赋值连线
|
|
759
|
+
* @param name 赋值连线名称
|
|
760
|
+
*/
|
|
761
|
+
removeAssignmentLine(name: string): void;
|
|
762
|
+
|
|
763
|
+
/**
|
|
764
|
+
* 删除赋值连线
|
|
765
|
+
* @param assignmentLine 已有的赋值连线实例
|
|
766
|
+
*/
|
|
767
|
+
removeAssignmentLine(assignmentLine: AssignmentLine): void;
|
|
768
|
+
|
|
769
|
+
removeAssignmentLine(options: string | AssignmentLine) {
|
|
770
|
+
let assignmentLine: AssignmentLine;
|
|
771
|
+
if (typeof options === 'string') {
|
|
772
|
+
assignmentLine = (this.assignmentLines as AssignmentLine[]).find((item) => item.name === options);
|
|
773
|
+
if (!assignmentLine) {
|
|
774
|
+
throw new Error('找不到赋值连线 ' + options);
|
|
775
|
+
}
|
|
776
|
+
} else {
|
|
777
|
+
assignmentLine = options;
|
|
778
|
+
}
|
|
779
|
+
return assignmentLine.delete();
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
__removeAssignmentLine(assignmentLine: AssignmentLine) {
|
|
783
|
+
const parentKey = assignmentLine.parentKey;
|
|
784
|
+
const params: Params = {
|
|
785
|
+
parentNode: this,
|
|
786
|
+
parentKey,
|
|
787
|
+
index: -1,
|
|
788
|
+
object: null,
|
|
789
|
+
oldObject: assignmentLine,
|
|
790
|
+
};
|
|
791
|
+
if (parentKey) {
|
|
792
|
+
params.parentKey = parentKey;
|
|
793
|
+
if (Array.isArray((this as any)[parentKey])) {
|
|
794
|
+
const index = (this as any)[parentKey].indexOf(assignmentLine);
|
|
795
|
+
~index && (this as any)[parentKey].splice(index, 1);
|
|
796
|
+
params.index = index;
|
|
797
|
+
} else if ((this as any)[parentKey] === assignmentLine) {
|
|
798
|
+
params.index = 0;
|
|
799
|
+
(this as any)[parentKey] = undefined;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
return params;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
//================================================================================
|
|
806
|
+
// ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
|
|
807
|
+
// 自动生成的代码已结束。下面可以手动编写。
|
|
808
|
+
//================================================================================
|
|
809
|
+
get lines() {
|
|
810
|
+
return this.assignmentLines.length;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
async newConnection(addRightIndex?: number) {
|
|
814
|
+
const leftLineSet = new Set();
|
|
815
|
+
const lineArr: Array<AssignmentLine> = [];
|
|
816
|
+
const connectionArr: any = [];
|
|
817
|
+
// 系统属性不可自动连线
|
|
818
|
+
['id', 'createdTime', 'updatedTime', 'createdBy', 'updatedBy'].forEach((name) => leftLineSet.add(name));
|
|
819
|
+
// 左边已连线的下标
|
|
820
|
+
this.assignmentLines.forEach((line) => {
|
|
821
|
+
if (line.leftIndex.length > 1)
|
|
822
|
+
leftLineSet.add(Number(line.leftIndex[1]));
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
const autoConnection = () => {
|
|
826
|
+
let structure: any;
|
|
827
|
+
const isAnnotation = this.typeAnnotation.typeKind === 'anonymousStructure';
|
|
828
|
+
if (!isAnnotation)
|
|
829
|
+
structure = this.app.findNodeByCompleteName(this.typeAnnotation.typeNamespace + '.' + this.typeAnnotation.typeName);
|
|
830
|
+
this.app.emit('collect:start', {
|
|
831
|
+
actionMsg: '自动连线',
|
|
832
|
+
});
|
|
833
|
+
this.properties.forEach((property: Identifier, leftSecondIndex: number) => {
|
|
834
|
+
const leftName = property.name;
|
|
835
|
+
const leftTypeAnnotation = !isAnnotation && structure.properties.find((p: StructureProperty) => p.name === property.name).typeAnnotation;
|
|
836
|
+
const typeStruct = isAnnotation && this.typeAnnotation.properties[leftSecondIndex]; // 获取匿名数据结构typeAnnotation的具体property
|
|
837
|
+
if (leftLineSet.has(leftSecondIndex) || leftLineSet.has(leftName))
|
|
838
|
+
return;
|
|
839
|
+
|
|
840
|
+
this.rights.forEach((selectMember, rightFirstIndex) => {
|
|
841
|
+
const { members, expression } = selectMember;
|
|
842
|
+
if (leftLineSet.has(leftSecondIndex))
|
|
843
|
+
return;
|
|
844
|
+
if (addRightIndex !== -1 && addRightIndex !== rightFirstIndex)
|
|
845
|
+
return;
|
|
846
|
+
// 右侧父节点也不允许自动连线
|
|
847
|
+
const rightLineSet = new Set();
|
|
848
|
+
for (let i = 0; i < members.length - 1; i++) {
|
|
849
|
+
const completeName = members[i].completeName;
|
|
850
|
+
const preCompleteName = members[i + 1].completeName;
|
|
851
|
+
if (preCompleteName.includes(completeName) && completeName.split('.').length !== preCompleteName.split('.').length)
|
|
852
|
+
rightLineSet.add(i);
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
if (leftName === expression.name && (isAnnotation || expression.__TypeAnnotation.typeKind === leftTypeAnnotation.typeKind)) {
|
|
856
|
+
const Line: AssignmentLine = new AssignmentLine({
|
|
857
|
+
leftIndex: [0, leftSecondIndex],
|
|
858
|
+
rightIndex: [rightFirstIndex],
|
|
859
|
+
});
|
|
860
|
+
lineArr.push(Line);
|
|
861
|
+
connectionArr.push({
|
|
862
|
+
leftItem: typeStruct,
|
|
863
|
+
rightItem: expression,
|
|
864
|
+
});
|
|
865
|
+
leftLineSet.add(leftSecondIndex);
|
|
866
|
+
return;
|
|
867
|
+
}
|
|
868
|
+
members.forEach((rightMember: any, rightSecondIndex: number) => {
|
|
869
|
+
const rightName = rightMember.property.name;
|
|
870
|
+
if (rightLineSet.has(rightSecondIndex))
|
|
871
|
+
return;
|
|
872
|
+
|
|
873
|
+
if (leftName === rightName) {
|
|
874
|
+
const rightTypeAnnotation = rightMember.__TypeAnnotation;
|
|
875
|
+
if (!isAnnotation && leftTypeAnnotation.typeKind !== rightTypeAnnotation.typeKind)
|
|
876
|
+
return;
|
|
877
|
+
const leftIndex = [0, leftSecondIndex];
|
|
878
|
+
const rightIndex = [rightFirstIndex, rightSecondIndex];
|
|
879
|
+
const Line: AssignmentLine = new AssignmentLine({ leftIndex, rightIndex });
|
|
880
|
+
lineArr.push(Line);
|
|
881
|
+
connectionArr.push({
|
|
882
|
+
leftItem: typeStruct,
|
|
883
|
+
rightItem: rightMember,
|
|
884
|
+
});
|
|
885
|
+
leftLineSet.add(leftSecondIndex);
|
|
886
|
+
}
|
|
887
|
+
});
|
|
888
|
+
});
|
|
889
|
+
});
|
|
890
|
+
lineArr.length && this.setAssignmentLines([...this.assignmentLines, ...lineArr]);
|
|
891
|
+
if (this.typeAnnotation.typeKind === 'anonymousStructure') {
|
|
892
|
+
connectionArr.forEach(({ leftItem, rightItem }: any) => {
|
|
893
|
+
if (rightItem.__TypeAnnotation) {
|
|
894
|
+
leftItem.update({
|
|
895
|
+
typeAnnotation: TypeAnnotation.from({ ...rightItem.__TypeAnnotation.toJSON() }),
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
this.app.emit('collect:end');
|
|
901
|
+
};
|
|
902
|
+
|
|
903
|
+
let count = 0;
|
|
904
|
+
const typeAnnotationEnd = () => {
|
|
905
|
+
const r = this.rights.every((right) => right.members.every((item) => item.__isCorrectTypeAnnotation));
|
|
906
|
+
count++;
|
|
907
|
+
if (r) {
|
|
908
|
+
autoConnection();
|
|
909
|
+
} else if (count <= 10) {
|
|
910
|
+
setTimeout(() => {
|
|
911
|
+
typeAnnotationEnd();
|
|
912
|
+
}, 100);
|
|
913
|
+
}
|
|
914
|
+
};
|
|
915
|
+
typeAnnotationEnd();
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
connection(leftItem: Identifier | TypeAnnotation, rightItem: LogicItem | SelectMembers, rightToLeft: boolean) {
|
|
919
|
+
let newLeftIndex = [0];
|
|
920
|
+
let newRightIndex = [];
|
|
921
|
+
let newLines: Array<AssignmentLine> = [...this.assignmentLines];
|
|
922
|
+
let newProperties = this.properties;
|
|
923
|
+
if (leftItem.concept === 'Identifier') {
|
|
924
|
+
const members = this.properties;
|
|
925
|
+
const secondIndex = members.findIndex((ident: any) => ident === leftItem);
|
|
926
|
+
// 连线左边的坐标。
|
|
927
|
+
newLeftIndex = [0, secondIndex];
|
|
928
|
+
} else {
|
|
929
|
+
newLines = [];
|
|
930
|
+
newProperties = [];
|
|
931
|
+
}
|
|
932
|
+
if (rightItem.concept === 'SelectMembers') {
|
|
933
|
+
newRightIndex = [this.rights.findIndex((right) => right === rightItem)];
|
|
934
|
+
} else {
|
|
935
|
+
const selectMember = rightItem.getAncestor('SelectMembers');
|
|
936
|
+
const firstIndex = this.rights.findIndex((right) => right === selectMember);
|
|
937
|
+
const secondIndex = this.rights[firstIndex].members.findIndex((exp: any) => exp === rightItem);
|
|
938
|
+
newRightIndex = [firstIndex, secondIndex];
|
|
939
|
+
}
|
|
940
|
+
// 左边同一个属性只能有一个连线
|
|
941
|
+
if (rightToLeft) {
|
|
942
|
+
newLines = newLines.filter(({ leftIndex: index }) => !(newLeftIndex[0] === index[0] && newLeftIndex[1] === index[1]));
|
|
943
|
+
}
|
|
944
|
+
const Line: AssignmentLine = new AssignmentLine({
|
|
945
|
+
leftIndex: newLeftIndex,
|
|
946
|
+
rightIndex: newRightIndex,
|
|
947
|
+
});
|
|
948
|
+
newLines.push(Line);
|
|
949
|
+
|
|
950
|
+
if (this.typeAnnotation.typeKind !== 'anonymousStructure') {
|
|
951
|
+
this.update({
|
|
952
|
+
assignmentLines: newLines,
|
|
953
|
+
properties: newProperties,
|
|
954
|
+
});
|
|
955
|
+
} else {
|
|
956
|
+
this.app.emit('collect:start', {
|
|
957
|
+
actionMsg: '匿名数据结构连线',
|
|
958
|
+
});
|
|
959
|
+
// 匿名数据结构typeAnnotation变化
|
|
960
|
+
const structureProperty = this.typeAnnotation.properties.find(({ name }) => name === leftItem.name);
|
|
961
|
+
const exp = rightItem.concept === 'SelectMembers' ? rightItem.expression : rightItem;
|
|
962
|
+
// 场景:右侧连接是非匿名数据
|
|
963
|
+
if (exp.__TypeAnnotation && exp.__TypeAnnotation.typeKey !== 'nasl.core.Null') {
|
|
964
|
+
structureProperty.update({
|
|
965
|
+
typeAnnotation: TypeAnnotation.from({ ...exp.__TypeAnnotation.toJSON() }),
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
this.update({
|
|
969
|
+
assignmentLines: newLines,
|
|
970
|
+
properties: newProperties,
|
|
971
|
+
});
|
|
972
|
+
this.app.emit('collect:end');
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
deleteAssignmentLine(assignmentLine: AssignmentLine) {
|
|
977
|
+
const newLine = this.assignmentLines.filter((line) => line !== assignmentLine);
|
|
978
|
+
this.app.emit('collect:start', {
|
|
979
|
+
actionMsg: '删除连线',
|
|
980
|
+
});
|
|
981
|
+
if (this.typeAnnotation.typeKind === 'anonymousStructure') {
|
|
982
|
+
const typeStructureProperty = this.findMember(assignmentLine.leftIndex, 'left', true);
|
|
983
|
+
typeStructureProperty.update({
|
|
984
|
+
typeAnnotation: null,
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
this.update({
|
|
988
|
+
assignmentLines: newLine,
|
|
989
|
+
});
|
|
990
|
+
this.app.emit('collect:end');
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
changeLinesLocation(selectMember: any) {
|
|
994
|
+
if (selectMember.concept !== 'SelectMembers')
|
|
995
|
+
return;
|
|
996
|
+
|
|
997
|
+
if (this.rights.findIndex((member) => selectMember === member) !== -1) {
|
|
998
|
+
const index = this.rights.findIndex((member) => selectMember === member);
|
|
999
|
+
const newRights = this.rights.filter((member) => selectMember !== member);
|
|
1000
|
+
const filterLine = this.assignmentLines.filter((line) => line.rightIndex[0] !== index);
|
|
1001
|
+
const newLines: Array<AssignmentLine> = [];
|
|
1002
|
+
const oldLines: AssignmentLine[] = this.assignmentLines.filter(({ rightIndex }) => rightIndex[0] === index);
|
|
1003
|
+
filterLine.forEach((line) => {
|
|
1004
|
+
if (line.rightIndex[0] > index) {
|
|
1005
|
+
if (line.rightIndex[1] === undefined) {
|
|
1006
|
+
const newLine = Object.assign({}, line, { rightIndex: [line.rightIndex[0] - 1] });
|
|
1007
|
+
newLines.push(newLine);
|
|
1008
|
+
} else {
|
|
1009
|
+
const newLine = Object.assign({}, line, { rightIndex: [line.rightIndex[0] - 1, line.rightIndex[1]] });
|
|
1010
|
+
newLines.push(newLine);
|
|
1011
|
+
}
|
|
1012
|
+
} else {
|
|
1013
|
+
newLines.push(line);
|
|
1014
|
+
}
|
|
1015
|
+
});
|
|
1016
|
+
this.app.emit('collect:start', {
|
|
1017
|
+
actionMsg: '匿名数据结构删除右侧变量',
|
|
1018
|
+
});
|
|
1019
|
+
if (this.typeAnnotation.typeKind === 'anonymousStructure') {
|
|
1020
|
+
oldLines.forEach(({ leftIndex }) => {
|
|
1021
|
+
const leftItem = this.typeAnnotation.properties[leftIndex[1]];
|
|
1022
|
+
leftItem.update({
|
|
1023
|
+
typeAnnotation: null,
|
|
1024
|
+
});
|
|
1025
|
+
});
|
|
1026
|
+
}
|
|
1027
|
+
this.update({
|
|
1028
|
+
rights: newRights,
|
|
1029
|
+
assignmentLines: newLines,
|
|
1030
|
+
});
|
|
1031
|
+
this.app.emit('collect:end');
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
changeMembers(oldNode:any, members: MemberExpression[], keepMembers: any, expression: LogicItem) {
|
|
1036
|
+
this.app.emit('collect:start', {
|
|
1037
|
+
actionMsg: 'New初始赋值修改变量',
|
|
1038
|
+
});
|
|
1039
|
+
const selectMember = oldNode.parentNode;
|
|
1040
|
+
const autoConnectionIndex = this.rights.findIndex((right) => right === selectMember);
|
|
1041
|
+
const newSelectMember = Object.assign({}, selectMember, { expression, members });
|
|
1042
|
+
const splitIndex = this.rights.findIndex((right) => selectMember === right);
|
|
1043
|
+
const newLines: AssignmentLine[] = this.assignmentLines.filter(({ rightIndex }) => rightIndex[0] !== splitIndex);
|
|
1044
|
+
let oldLines: AssignmentLine[] = this.assignmentLines.filter(({ rightIndex }) => rightIndex[0] === splitIndex);
|
|
1045
|
+
// 右侧变量改变后,修改连线
|
|
1046
|
+
members.forEach((item, index) => {
|
|
1047
|
+
if (keepMembers.has(item.completeName)) {
|
|
1048
|
+
const lines = this.findlines(item, selectMember);
|
|
1049
|
+
lines.forEach((line) => {
|
|
1050
|
+
const newLine = Object.assign({}, line, { rightIndex: [line.rightIndex[0], index] });
|
|
1051
|
+
newLines.push(newLine);
|
|
1052
|
+
oldLines = oldLines.filter(({ leftIndex }) => leftIndex[1] !== line.leftIndex[1]);
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
});
|
|
1056
|
+
|
|
1057
|
+
if (this.typeAnnotation.typeKind === 'anonymousStructure') {
|
|
1058
|
+
oldLines.forEach(({ leftIndex }) => {
|
|
1059
|
+
const leftItem = this.typeAnnotation.properties[leftIndex[1]];
|
|
1060
|
+
leftItem.update({
|
|
1061
|
+
typeAnnotation: null,
|
|
1062
|
+
});
|
|
1063
|
+
});
|
|
1064
|
+
}
|
|
1065
|
+
this.update({
|
|
1066
|
+
assignmentLines: newLines,
|
|
1067
|
+
rights: [...this.rights.slice(0, splitIndex), newSelectMember, ...this.rights.slice(splitIndex + 1, this.rights.length)],
|
|
1068
|
+
});
|
|
1069
|
+
this.autoConnection && this.newConnection(autoConnectionIndex);
|
|
1070
|
+
this.app.emit('collect:end');
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
findlines(member: any, selectMember: any) {
|
|
1074
|
+
const lines: Array<AssignmentLine> = [];
|
|
1075
|
+
// 根节点的情况
|
|
1076
|
+
if (selectMember === this) {
|
|
1077
|
+
if (member === this.typeAnnotation)
|
|
1078
|
+
return this.assignmentLines;
|
|
1079
|
+
else {
|
|
1080
|
+
const index2 = this.properties.findIndex((item: Identifier) => item.completeName === member.completeName);
|
|
1081
|
+
this.assignmentLines.forEach((line) => {
|
|
1082
|
+
if (line.leftIndex[1] === index2)
|
|
1083
|
+
lines.push(line);
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
} else {
|
|
1087
|
+
const index1 = this.rights.findIndex((right) => right === selectMember);
|
|
1088
|
+
const index2 = selectMember.members.findIndex((item: MemberExpression) => item.completeName === member.completeName);
|
|
1089
|
+
this.assignmentLines.forEach((line) => {
|
|
1090
|
+
if (line.rightIndex[0] === index1 && line.rightIndex[1] === index2)
|
|
1091
|
+
lines.push(line);
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
return lines;
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
findMember(arrIndex: Array<number>, place: string, isAnnotation?: boolean) {
|
|
1098
|
+
const [firstIndex, secondIndex] = [arrIndex[0], arrIndex[1]];
|
|
1099
|
+
if (isAnnotation) {
|
|
1100
|
+
return this.typeAnnotation.properties[secondIndex];
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
if (place === 'left') {
|
|
1104
|
+
if (secondIndex === undefined) {
|
|
1105
|
+
return this.typeAnnotation;
|
|
1106
|
+
}
|
|
1107
|
+
return this.properties[secondIndex];
|
|
1108
|
+
} else {
|
|
1109
|
+
if (secondIndex === undefined) {
|
|
1110
|
+
return this.rights[firstIndex].expression;
|
|
1111
|
+
}
|
|
1112
|
+
return this.rights[firstIndex].members[secondIndex];
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
toUI(state?: TranslatorState): string {
|
|
1117
|
+
let code = '';
|
|
1118
|
+
const typeAnnotation = this.typeAnnotation;
|
|
1119
|
+
const leftTopIndex = this.assignmentLines.findIndex(({ leftIndex }) => leftIndex[1] === undefined);
|
|
1120
|
+
if (!this.typeAnnotation)
|
|
1121
|
+
return null;
|
|
1122
|
+
|
|
1123
|
+
code += 'await (async () => { \n';
|
|
1124
|
+
if (leftTopIndex !== -1) {
|
|
1125
|
+
const rightIndex = this.assignmentLines[leftTopIndex].rightIndex;
|
|
1126
|
+
const obj = rightIndex[1] !== undefined ? this.rights[rightIndex[0]].members[rightIndex[1]] : this.rights[rightIndex[0]].expression;
|
|
1127
|
+
code += `return ${obj};\n`;
|
|
1128
|
+
} else if (typeAnnotation.typeKind !== 'anonymousStructure') {
|
|
1129
|
+
code += `const obj = this.$genInitFromSchema('${typeAnnotation.sortedTypeKey}', this.$utils['New'](${typeAnnotation.toUI(shiftState(state, code, { inline: true }))}));\n`;
|
|
1130
|
+
this.assignmentLines.forEach(({ leftIndex, rightIndex }, index) => {
|
|
1131
|
+
const leftSecondIndex = leftIndex[1];
|
|
1132
|
+
const [rightFirst, rightSecond] = [rightIndex[0], rightIndex[1]];
|
|
1133
|
+
const leftItem = this.properties[leftSecondIndex];
|
|
1134
|
+
const rightItem = rightSecond !== undefined ? this.rights[rightFirst].members[rightSecond] : this.rights[rightFirst].expression;
|
|
1135
|
+
code += `obj.${leftItem.name} = ${rightItem.toUI(shiftState(state, code, { inline: true }))}`;
|
|
1136
|
+
code += ';\n';
|
|
1137
|
+
});
|
|
1138
|
+
code += 'return obj;\n';
|
|
1139
|
+
} else {
|
|
1140
|
+
code += `const obj = {};\n`;
|
|
1141
|
+
this.properties.forEach((property) => {
|
|
1142
|
+
code += `obj.${property.name} = null;\n`;
|
|
1143
|
+
});
|
|
1144
|
+
this.assignmentLines.forEach(({ leftIndex, rightIndex }, index) => {
|
|
1145
|
+
const leftSecondIndex = leftIndex[1];
|
|
1146
|
+
const [rightFirst, rightSecond] = [rightIndex[0], rightIndex[1]];
|
|
1147
|
+
const leftItem = this.properties[leftSecondIndex];
|
|
1148
|
+
const rightItem = rightSecond !== undefined ? this.rights[rightFirst].members[rightSecond] : this.rights[rightFirst].expression;
|
|
1149
|
+
code += `obj.${leftItem.name} = ${rightItem.toUI(shiftState(state, code, { inline: true }))}`;
|
|
1150
|
+
code += ';\n';
|
|
1151
|
+
});
|
|
1152
|
+
code += 'return obj;\n';
|
|
1153
|
+
}
|
|
1154
|
+
code += '})()';
|
|
1155
|
+
return code;
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
toJS(state?: TranslatorState): string {
|
|
1159
|
+
let code = '';
|
|
1160
|
+
const typeAnnotation = this.typeAnnotation;
|
|
1161
|
+
const leftTopIndex = this.assignmentLines.findIndex(({ leftIndex }) => leftIndex[1] === undefined);
|
|
1162
|
+
if (!this.typeAnnotation)
|
|
1163
|
+
return null;
|
|
1164
|
+
|
|
1165
|
+
code += 'await (async () => { \n';
|
|
1166
|
+
if (leftTopIndex !== -1) {
|
|
1167
|
+
const rightIndex = this.assignmentLines[leftTopIndex].rightIndex;
|
|
1168
|
+
const obj = rightIndex[1] !== undefined ? this.rights[rightIndex[0]].members[rightIndex[1]] : this.rights[rightIndex[0]].expression;
|
|
1169
|
+
code += `return ${obj.toJS(shiftState(state, code, { inline: true }))};\n`;
|
|
1170
|
+
} else if (typeAnnotation.typeKind !== 'anonymousStructure') {
|
|
1171
|
+
code += `const obj = this.$genInitFromSchema('${typeAnnotation.sortedTypeKey}', this.$utils['New'](${typeAnnotation.toJS(shiftState(state, code, { inline: true }))}));\n`;
|
|
1172
|
+
this.assignmentLines.forEach(({ leftIndex, rightIndex }, index) => {
|
|
1173
|
+
const leftSecondIndex = leftIndex[1];
|
|
1174
|
+
const [rightFirst, rightSecond] = [rightIndex[0], rightIndex[1]];
|
|
1175
|
+
const leftItem = this.properties[leftSecondIndex];
|
|
1176
|
+
const rightItem = rightSecond !== undefined ? this.rights[rightFirst].members[rightSecond] : this.rights[rightFirst].expression;
|
|
1177
|
+
code += `obj.${leftItem.name} = ${rightItem.toJS(shiftState(state, code, { inline: true }))}`;
|
|
1178
|
+
code += ';\n';
|
|
1179
|
+
});
|
|
1180
|
+
code += 'return obj;\n';
|
|
1181
|
+
} else {
|
|
1182
|
+
code += `const obj = {};\n`;
|
|
1183
|
+
this.properties.forEach((property) => {
|
|
1184
|
+
code += `obj.${property.name} = null;\n`;
|
|
1185
|
+
});
|
|
1186
|
+
this.assignmentLines.forEach(({ leftIndex, rightIndex }, index) => {
|
|
1187
|
+
const leftSecondIndex = leftIndex[1];
|
|
1188
|
+
const [rightFirst, rightSecond] = [rightIndex[0], rightIndex[1]];
|
|
1189
|
+
const leftItem = this.properties[leftSecondIndex];
|
|
1190
|
+
const rightItem = rightSecond !== undefined ? this.rights[rightFirst].members[rightSecond] : this.rights[rightFirst].expression;
|
|
1191
|
+
code += `obj.${leftItem.name} = ${rightItem.toJS(shiftState(state, code, { inline: true }))}`;
|
|
1192
|
+
code += ';\n';
|
|
1193
|
+
});
|
|
1194
|
+
code += 'return obj;\n';
|
|
1195
|
+
}
|
|
1196
|
+
code += '})()';
|
|
1197
|
+
return code;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
@withSourceMap()
|
|
1201
|
+
toEmbeddedTS(state?: TranslatorState): string {
|
|
1202
|
+
let code = '';
|
|
1203
|
+
if (!this.typeAnnotation) {
|
|
1204
|
+
code += '__IDENTIFIER__';
|
|
1205
|
+
} else if (this.typeAnnotation.typeKind !== 'anonymousStructure') {
|
|
1206
|
+
const rightMap = new Map();
|
|
1207
|
+
code += '(() => { \n';
|
|
1208
|
+
// 提供sourcemap,获取类型标注和上下文可选变量
|
|
1209
|
+
this.rights.forEach((right) => {
|
|
1210
|
+
rightMap.set(right.expression, right.expression.toEmbeddedTS(shiftState(state, code, { inline: true })));
|
|
1211
|
+
code += rightMap.get(right.expression);
|
|
1212
|
+
code += ';\n';
|
|
1213
|
+
right.members.forEach((member) => {
|
|
1214
|
+
rightMap.set(member, member.toEmbeddedTS(shiftState(state, code, { inline: true })));
|
|
1215
|
+
code += rightMap.get(member);
|
|
1216
|
+
code += '; ';
|
|
1217
|
+
});
|
|
1218
|
+
code += right.members.length ? '\n' : '';
|
|
1219
|
+
});
|
|
1220
|
+
// 方便ts报错检查
|
|
1221
|
+
code += 'function __newComposite() {\n';
|
|
1222
|
+
code += `let __obj = nasl.util.New<${this.typeAnnotation.sortedTypeKey}>();`;
|
|
1223
|
+
code += '\n';
|
|
1224
|
+
// 是否是左边的顶层连线
|
|
1225
|
+
const leftTopIndex = this.assignmentLines.findIndex(({ leftIndex }) => leftIndex[1] === undefined);
|
|
1226
|
+
if (leftTopIndex !== -1) {
|
|
1227
|
+
const rightIndex = this.assignmentLines[leftTopIndex].rightIndex;
|
|
1228
|
+
const rightExpression = rightIndex[1] !== undefined ? this.rights[rightIndex[0]].members[rightIndex[1]] : this.rights[rightIndex[0]].expression;
|
|
1229
|
+
code += `__obj = ${rightExpression.toEmbeddedTS(shiftState(state, code, { inline: true }))};`;
|
|
1230
|
+
code += '\n';
|
|
1231
|
+
} else {
|
|
1232
|
+
// 左侧properties的identifier的类型标注
|
|
1233
|
+
this.properties.forEach((item) => {
|
|
1234
|
+
code += `const `;
|
|
1235
|
+
code += `${item.toEmbeddedTS(shiftState(state, code, { inline: true }))} = __obj.${item.name};\n`;
|
|
1236
|
+
});
|
|
1237
|
+
this.assignmentLines.forEach(({ leftIndex, rightIndex }) => {
|
|
1238
|
+
const leftSecondIndex = leftIndex[1];
|
|
1239
|
+
const [rightFirst, rightSecond] = [rightIndex[0], rightIndex[1]];
|
|
1240
|
+
const leftItem = this.properties[leftSecondIndex];
|
|
1241
|
+
const rightItem = rightSecond !== undefined ? this.rights[rightFirst].members[rightSecond] : this.rights[rightFirst].expression;
|
|
1242
|
+
const rightTs = rightMap.get(rightItem);
|
|
1243
|
+
code += `nasl.core.compare2(`;
|
|
1244
|
+
code += `${['__IDENTIFIER__', '__IDENTIFIER__()'].includes(rightTs) ? 'null' : rightMap.get(rightItem)}, `;
|
|
1245
|
+
code += `${leftItem.toEmbeddedTS(shiftState(state, code, { inline: true }))});\n`;
|
|
1246
|
+
});
|
|
1247
|
+
}
|
|
1248
|
+
code += 'return __obj;\n';
|
|
1249
|
+
code += '};\n';
|
|
1250
|
+
|
|
1251
|
+
code += 'return __newComposite();\n';
|
|
1252
|
+
code += '})()';
|
|
1253
|
+
} else {
|
|
1254
|
+
const nameMap = new Map();
|
|
1255
|
+
const rightMap = new Map();
|
|
1256
|
+
this.assignmentLines.forEach(({ leftIndex, rightIndex }) => {
|
|
1257
|
+
const leftSecondIndex = leftIndex[1];
|
|
1258
|
+
const [rightFirst, rightSecond] = [rightIndex[0], rightIndex[1]];
|
|
1259
|
+
const leftItem = this.properties[leftSecondIndex];
|
|
1260
|
+
const rightItem = rightSecond !== undefined ? this.rights[rightFirst].members[rightSecond] : this.rights[rightFirst].expression;
|
|
1261
|
+
nameMap.set(leftItem.name, rightItem);
|
|
1262
|
+
rightMap.set(rightItem, null);
|
|
1263
|
+
});
|
|
1264
|
+
code += '(() => { \n';
|
|
1265
|
+
// 提供sourcemap,获取类型标注和上下文可选变量
|
|
1266
|
+
this.rights.forEach((right) => {
|
|
1267
|
+
let ts = right.expression.toEmbeddedTS(shiftState(state, code, { inline: true }));
|
|
1268
|
+
if (rightMap.has(right.expression))
|
|
1269
|
+
rightMap.set(right.expression, ts);
|
|
1270
|
+
code += ts;
|
|
1271
|
+
code += ';\n';
|
|
1272
|
+
right.members.forEach((member) => {
|
|
1273
|
+
ts = member.toEmbeddedTS(shiftState(state, code, { inline: true }));
|
|
1274
|
+
if (rightMap.has(member))
|
|
1275
|
+
rightMap.set(member, ts);
|
|
1276
|
+
code += ts;
|
|
1277
|
+
code += '; ';
|
|
1278
|
+
});
|
|
1279
|
+
code += right.members.length ? '\n' : '';
|
|
1280
|
+
});
|
|
1281
|
+
// 方便ts报错检查
|
|
1282
|
+
code += 'function __newComposite(): ';
|
|
1283
|
+
code += this.typeAnnotation.toEmbeddedTS(shiftState(state, code, { inline: true }));
|
|
1284
|
+
code += '{\n';
|
|
1285
|
+
this.properties.forEach((property) => {
|
|
1286
|
+
const name = property.name;
|
|
1287
|
+
const rightItem = nameMap.get(name);
|
|
1288
|
+
if (rightMap.get(rightItem) !== undefined) {
|
|
1289
|
+
code += `{ const x = ${rightMap.get(rightItem)}; const `;
|
|
1290
|
+
code += property.toEmbeddedTS(shiftState(state, code, { inline: true }));
|
|
1291
|
+
code += `: nasl.core.Incompatible<typeof x, void> = x`;
|
|
1292
|
+
code += '; }\n';
|
|
1293
|
+
} else {
|
|
1294
|
+
code += '{ const ';
|
|
1295
|
+
code += property.toEmbeddedTS(shiftState(state, code, { inline: true }));
|
|
1296
|
+
code += '; }\n';
|
|
1297
|
+
}
|
|
1298
|
+
});
|
|
1299
|
+
code += 'return;\n';
|
|
1300
|
+
code += '};\n';
|
|
1301
|
+
|
|
1302
|
+
code += 'return __newComposite();\n';
|
|
1303
|
+
code += '})()';
|
|
1304
|
+
}
|
|
1305
|
+
return code;
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
__addIdentifier(App: App) {
|
|
1309
|
+
const app = this.app || App;
|
|
1310
|
+
app.emit('collect:start', {
|
|
1311
|
+
actionMsg: '添加匿名数据结构属性',
|
|
1312
|
+
});
|
|
1313
|
+
const node = this.addIdentifier({ name: this.getIdentifierUniqueName('property1') });
|
|
1314
|
+
const struct = StructureProperty.from({
|
|
1315
|
+
name: node.name,
|
|
1316
|
+
typeAnnotation: null,
|
|
1317
|
+
});
|
|
1318
|
+
this.typeAnnotation.addStructureProperty(struct);
|
|
1319
|
+
app.emit('collect:end');
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
__deleteIdentifier(property: Identifier) {
|
|
1323
|
+
const index = this.properties.findIndex((p) => p === property);
|
|
1324
|
+
const newLines: AssignmentLine[] = [];
|
|
1325
|
+
const newProperties = [...this.typeAnnotation.properties.slice(0, index), ...this.typeAnnotation.properties.slice(index + 1, this.properties.length)];
|
|
1326
|
+
this.assignmentLines.forEach((line) => {
|
|
1327
|
+
const { leftIndex } = line;
|
|
1328
|
+
if (leftIndex[1] < index) {
|
|
1329
|
+
newLines.push(line);
|
|
1330
|
+
} else if (leftIndex[1] > index) {
|
|
1331
|
+
const newLine = Object.assign({}, line, { leftIndex: [leftIndex[0], leftIndex[1] - 1] });
|
|
1332
|
+
newLines.push(newLine);
|
|
1333
|
+
}
|
|
1334
|
+
});
|
|
1335
|
+
this.app.emit('collect:start', {
|
|
1336
|
+
actionMsg: '删除匿名数据结属性',
|
|
1337
|
+
});
|
|
1338
|
+
this.setAssignmentLines(newLines);
|
|
1339
|
+
this.typeAnnotation.update({
|
|
1340
|
+
properties: newProperties,
|
|
1341
|
+
});
|
|
1342
|
+
property.delete();
|
|
1343
|
+
this.app.emit('collect:end');
|
|
1344
|
+
}
|
|
1345
|
+
//================================================================================
|
|
1346
|
+
// 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
|
|
1347
|
+
// ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
|
|
1348
|
+
//================================================================================
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
classMap.NewComposite = NewComposite;
|
|
1352
|
+
export default NewComposite;
|
|
1353
|
+
//================================================================================
|
|
1354
|
+
// ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
|
|
1355
|
+
// 自动生成的代码已结束。下面可以手动编写。
|
|
1356
|
+
//================================================================================
|