@lcap/nasl 2.22.0-beta.5 → 3.0.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/README.md +13 -0
- package/docs/classes/Module.html +15 -15
- package/docs/classes/Namespace.html +15 -15
- package/docs/classes/ViewComponent.html +19 -19
- package/out/automate/engine/utils.js +4 -0
- package/out/automate/engine/utils.js.map +1 -1
- package/out/breakpoint/generator/AfterStartNode.d.ts +7 -0
- package/out/breakpoint/generator/AfterStartNode.js +27 -0
- package/out/breakpoint/generator/AfterStartNode.js.map +1 -0
- package/out/breakpoint/generator/BeforeEndNode.d.ts +7 -0
- package/out/breakpoint/generator/BeforeEndNode.js +27 -0
- package/out/breakpoint/generator/BeforeEndNode.js.map +1 -0
- package/out/breakpoint/generator/BreakpointNode.d.ts +14 -0
- package/out/breakpoint/generator/BreakpointNode.js +166 -0
- package/out/breakpoint/generator/BreakpointNode.js.map +1 -0
- package/out/breakpoint/generator/index.d.ts +4 -0
- package/out/breakpoint/generator/index.js +98 -0
- package/out/breakpoint/generator/index.js.map +1 -0
- package/out/breakpoint/index.d.ts +3 -0
- package/out/breakpoint/index.js +20 -0
- package/out/breakpoint/index.js.map +1 -0
- package/out/breakpoint/shared/constants.d.ts +30 -0
- package/out/breakpoint/shared/constants.js +87 -0
- package/out/breakpoint/shared/constants.js.map +1 -0
- package/out/breakpoint/shared/index.d.ts +3 -0
- package/out/breakpoint/shared/index.js +33 -0
- package/out/breakpoint/shared/index.js.map +1 -0
- package/out/breakpoint/shared/operations.d.ts +10 -0
- package/out/breakpoint/shared/operations.js +25 -0
- package/out/breakpoint/shared/operations.js.map +1 -0
- package/out/breakpoint/shared/socket.d.ts +47 -0
- package/out/breakpoint/shared/socket.js +210 -0
- package/out/breakpoint/shared/socket.js.map +1 -0
- package/out/breakpoint/shared/utils.d.ts +20 -0
- package/out/breakpoint/shared/utils.js +133 -0
- package/out/breakpoint/shared/utils.js.map +1 -0
- package/out/breakpoint/store/core.d.ts +30 -0
- package/out/breakpoint/store/core.js +341 -0
- package/out/breakpoint/store/core.js.map +1 -0
- package/out/breakpoint/store/dock.d.ts +1 -0
- package/out/breakpoint/store/dock.js +127 -0
- package/out/breakpoint/store/dock.js.map +1 -0
- package/out/breakpoint/store/index.d.ts +2 -0
- package/out/breakpoint/store/index.js +19 -0
- package/out/breakpoint/store/index.js.map +1 -0
- package/out/common/BaseNode.d.ts +8 -0
- package/out/common/BaseNode.js +19 -0
- package/out/common/BaseNode.js.map +1 -1
- package/out/concepts/App__.d.ts +365 -16
- package/out/concepts/App__.js +431 -10
- package/out/concepts/App__.js.map +1 -1
- package/out/concepts/Assignment__.js +1 -1
- package/out/concepts/Assignment__.js.map +1 -1
- package/out/concepts/AuthInterface__.d.ts +37 -0
- package/out/concepts/AuthInterface__.js +141 -0
- package/out/concepts/AuthInterface__.js.map +1 -0
- package/out/concepts/AuthLogicForCallInterface__.d.ts +138 -0
- package/out/concepts/AuthLogicForCallInterface__.js +493 -0
- package/out/concepts/AuthLogicForCallInterface__.js.map +1 -0
- package/out/concepts/AuthLogic__.d.ts +66 -0
- package/out/concepts/AuthLogic__.js +206 -0
- package/out/concepts/AuthLogic__.js.map +1 -0
- package/out/concepts/BackendVariable__.d.ts +137 -0
- package/out/concepts/BackendVariable__.js +422 -0
- package/out/concepts/BackendVariable__.js.map +1 -0
- package/out/concepts/Backend__.d.ts +134 -0
- package/out/concepts/Backend__.js +274 -0
- package/out/concepts/Backend__.js.map +1 -0
- package/out/concepts/BindAttribute__.d.ts +1 -1
- package/out/concepts/BindAttribute__.js +3 -1
- package/out/concepts/BindAttribute__.js.map +1 -1
- package/out/concepts/BindEvent__.d.ts +12 -0
- package/out/concepts/BindEvent__.js +68 -0
- package/out/concepts/BindEvent__.js.map +1 -1
- package/out/concepts/CallAuthInterface__.d.ts +126 -0
- package/out/concepts/CallAuthInterface__.js +408 -0
- package/out/concepts/CallAuthInterface__.js.map +1 -0
- package/out/concepts/CallInterface__.d.ts +6 -1
- package/out/concepts/CallInterface__.js +9 -1
- package/out/concepts/CallInterface__.js.map +1 -1
- package/out/concepts/CallLogic__.js +3 -1
- package/out/concepts/CallLogic__.js.map +1 -1
- package/out/concepts/CallQueryComponent__.js +9 -7
- package/out/concepts/CallQueryComponent__.js.map +1 -1
- package/out/concepts/Destination__.js +1 -1
- package/out/concepts/Destination__.js.map +1 -1
- package/out/concepts/End__.js +29 -2
- package/out/concepts/End__.js.map +1 -1
- package/out/concepts/EntityProperty__.js.map +1 -1
- package/out/concepts/Entity__.d.ts +1 -2
- package/out/concepts/Entity__.js +1 -31
- package/out/concepts/Entity__.js.map +1 -1
- package/out/concepts/ForEachStatement__.js +9 -4
- package/out/concepts/ForEachStatement__.js.map +1 -1
- package/out/concepts/FrontendLibrary__.d.ts +29 -29
- package/out/concepts/FrontendLibrary__.js +2 -2
- package/out/concepts/FrontendVariable__.d.ts +21 -0
- package/out/concepts/FrontendVariable__.js +64 -0
- package/out/concepts/FrontendVariable__.js.map +1 -0
- package/out/concepts/Frontend__.d.ts +151 -47
- package/out/concepts/Frontend__.js +188 -32
- package/out/concepts/Frontend__.js.map +1 -1
- package/out/concepts/Function__.js +1 -1
- package/out/concepts/Function__.js.map +1 -1
- package/out/concepts/Identifier__.js +1 -1
- package/out/concepts/Identifier__.js.map +1 -1
- package/out/concepts/Interface__.d.ts +1 -1
- package/out/concepts/Interface__.js.map +1 -1
- package/out/concepts/LogicItem__.d.ts +18 -3
- package/out/concepts/LogicItem__.js +22 -4
- package/out/concepts/LogicItem__.js.map +1 -1
- package/out/concepts/Logic__.d.ts +14 -9
- package/out/concepts/Logic__.js +43 -5
- package/out/concepts/Logic__.js.map +1 -1
- package/out/concepts/Module__.js.map +1 -1
- package/out/concepts/Namespace__.d.ts +29 -29
- package/out/concepts/Namespace__.js +2 -2
- package/out/concepts/NewComposite__.js +2 -2
- package/out/concepts/NewComposite__.js.map +1 -1
- package/out/concepts/OverriddenLogic__.d.ts +643 -0
- package/out/concepts/OverriddenLogic__.js +1602 -0
- package/out/concepts/OverriddenLogic__.js.map +1 -0
- package/out/concepts/Param__.d.ts +6 -0
- package/out/concepts/Param__.js +10 -0
- package/out/concepts/Param__.js.map +1 -1
- package/out/concepts/QueryFieldExpression__.d.ts +2 -0
- package/out/concepts/QueryFieldExpression__.js +9 -0
- package/out/concepts/QueryFieldExpression__.js.map +1 -1
- package/out/concepts/QuerySelectExpression__.d.ts +2 -2
- package/out/concepts/QuerySelectExpression__.js +2 -2
- package/out/concepts/QuerySelectExpression__.js.map +1 -1
- package/out/concepts/TypeAnnotation__.js +6 -6
- package/out/concepts/TypeAnnotation__.js.map +1 -1
- package/out/concepts/Variable__.d.ts +10 -0
- package/out/concepts/Variable__.js +12 -0
- package/out/concepts/Variable__.js.map +1 -1
- package/out/concepts/ViewComponent__.d.ts +33 -33
- package/out/concepts/ViewComponent__.js +7 -7
- package/out/concepts/ViewElement__.d.ts +6 -0
- package/out/concepts/ViewElement__.js +104 -1
- package/out/concepts/ViewElement__.js.map +1 -1
- package/out/concepts/View__.js +2 -2
- package/out/concepts/View__.js.map +1 -1
- package/out/concepts/basics/stdlib/index.js +2 -1
- package/out/concepts/basics/stdlib/index.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.auth.js +24 -0
- package/out/concepts/basics/stdlib/nasl.auth.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.http.d.ts +7 -0
- package/out/concepts/basics/stdlib/nasl.http.js +167 -0
- package/out/concepts/basics/stdlib/nasl.http.js.map +1 -0
- package/out/concepts/basics/stdlib/nasl.process.js +68 -0
- package/out/concepts/basics/stdlib/nasl.process.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.ui.js +4 -19
- package/out/concepts/basics/stdlib/nasl.ui.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.util.js +83 -17
- package/out/concepts/basics/stdlib/nasl.util.js.map +1 -1
- package/out/concepts/basics/types/index.d.ts +1 -0
- package/out/concepts/basics/types/index.js +4 -1
- package/out/concepts/basics/types/index.js.map +1 -1
- package/out/concepts/index__.d.ts +8 -0
- package/out/concepts/index__.js +8 -0
- package/out/concepts/index__.js.map +1 -1
- package/out/enums/KEYWORDS.js +0 -1
- package/out/enums/KEYWORDS.js.map +1 -1
- package/out/generator/genBundleFiles.d.ts +1 -0
- package/out/generator/genBundleFiles.js +27 -0
- package/out/generator/genBundleFiles.js.map +1 -1
- package/out/generator/genMetaData.d.ts +4 -1
- package/out/generator/genMetaData.js +14 -0
- package/out/generator/genMetaData.js.map +1 -1
- package/out/generator/genReleaseBody.d.ts +2 -1
- package/out/generator/genReleaseBody.js +2 -1
- package/out/generator/genReleaseBody.js.map +1 -1
- package/out/index.d.ts +2 -1
- package/out/index.js +3 -1
- package/out/index.js.map +1 -1
- package/out/server/extendBaseNode.js +16 -4
- package/out/server/extendBaseNode.js.map +1 -1
- package/out/server/formatTsUtils.d.ts +2 -1
- package/out/server/formatTsUtils.js +39 -4
- package/out/server/formatTsUtils.js.map +1 -1
- package/out/server/getExtensionModules.d.ts +2 -2
- package/out/server/getExtensionModules.js +16 -2
- package/out/server/getExtensionModules.js.map +1 -1
- package/out/server/getLogics.js +5 -5
- package/out/server/getLogics.js.map +1 -1
- package/out/server/getMemberIdentifier.d.ts +1 -0
- package/out/server/getMemberIdentifier.js +34 -7
- package/out/server/getMemberIdentifier.js.map +1 -1
- package/out/server/naslServer.d.ts +64 -64
- package/out/server/naslServer.js +249 -121
- package/out/server/naslServer.js.map +1 -1
- package/out/server/naslStdlibMap.js +2 -0
- package/out/server/naslStdlibMap.js.map +1 -1
- package/out/server/translator.d.ts +1 -0
- package/out/server/translator.js +67 -2
- package/out/server/translator.js.map +1 -1
- package/out/service/defaultErrorMessage.json +1 -0
- package/out/service/storage/api.d.ts +10 -1
- package/out/service/storage/api.js +6 -0
- package/out/service/storage/api.js.map +1 -1
- package/out/service/storage/init.d.ts +4 -0
- package/out/service/storage/init.js +55 -35
- package/out/service/storage/init.js.map +1 -1
- package/out/service/storage/service.d.ts +3 -0
- package/out/service/storage/service.js +14 -0
- package/out/service/storage/service.js.map +1 -1
- package/out/utils/sortTsString.d.ts +1 -0
- package/out/utils/sortTsString.js +36 -0
- package/out/utils/sortTsString.js.map +1 -0
- package/out/utils/traverse.js +2 -2
- package/out/utils/traverse.js.map +1 -1
- package/package.json +7 -2
- package/sandbox/stdlib/nasl.auth.ts +8 -4
- package/sandbox/stdlib/nasl.core.d.ts +206 -0
- package/sandbox/stdlib/nasl.core.js +1 -0
- package/sandbox/stdlib/nasl.core.js.map +1 -0
- package/sandbox/stdlib/nasl.http.ts +35 -0
- package/sandbox/stdlib/nasl.process.ts +13 -0
- package/sandbox/stdlib/nasl.ui.ts +0 -5
- package/src/automate/engine/utils.js +4 -1
- package/src/breakpoint/generator/AfterStartNode.ts +27 -0
- package/src/breakpoint/generator/BeforeEndNode.ts +27 -0
- package/src/breakpoint/generator/BreakpointNode.ts +228 -0
- package/src/breakpoint/generator/index.ts +114 -0
- package/src/breakpoint/index.ts +3 -0
- package/src/breakpoint/shared/constants.ts +95 -0
- package/src/breakpoint/shared/index.ts +3 -0
- package/src/breakpoint/shared/operations.ts +25 -0
- package/src/breakpoint/shared/socket.ts +326 -0
- package/src/breakpoint/shared/utils.ts +195 -0
- package/src/breakpoint/store/core.ts +411 -0
- package/src/breakpoint/store/dock.ts +166 -0
- package/src/breakpoint/store/index.ts +2 -0
- package/src/breakpoint/types/index.d.ts +19 -0
- package/src/common/BaseNode.ts +19 -1
- package/src/concepts/App__.ts +828 -26
- package/src/concepts/Assignment__.ts +1 -1
- package/src/concepts/AuthInterface__.ts +148 -0
- package/src/concepts/AuthLogicForCallInterface__.ts +573 -0
- package/src/concepts/AuthLogic__.ts +225 -0
- package/src/concepts/BackendVariable__.ts +466 -0
- package/src/concepts/Backend__.ts +347 -0
- package/src/concepts/BindAttribute__.ts +4 -3
- package/src/concepts/BindEvent__.ts +71 -2
- package/src/concepts/CallAuthInterface__.ts +490 -0
- package/src/concepts/CallInterface__.ts +10 -2
- package/src/concepts/CallLogic__.ts +3 -1
- package/src/concepts/CallQueryComponent__.ts +67 -7
- package/src/concepts/Destination__.ts +19 -1
- package/src/concepts/End__.ts +31 -3
- package/src/concepts/EntityProperty__.ts +6 -0
- package/src/concepts/Entity__.ts +8 -31
- package/src/concepts/ForEachStatement__.ts +9 -4
- package/src/concepts/FrontendLibrary__.ts +30 -30
- package/src/concepts/FrontendVariable__.ts +76 -0
- package/src/concepts/Frontend__.ts +352 -89
- package/src/concepts/Function__.ts +1 -1
- package/src/concepts/Identifier__.ts +5 -5
- package/src/concepts/Interface__.ts +1 -1
- package/src/concepts/LogicItem__.ts +26 -6
- package/src/concepts/Logic__.ts +86 -8
- package/src/concepts/Module__.ts +32 -2
- package/src/concepts/Namespace__.ts +30 -30
- package/src/concepts/NewComposite__.ts +2 -3
- package/src/concepts/OverriddenLogic__.ts +2165 -0
- package/src/concepts/Param__.ts +13 -3
- package/src/concepts/QueryFieldExpression__.ts +18 -0
- package/src/concepts/QuerySelectExpression__.ts +11 -3
- package/src/concepts/TypeAnnotation__.ts +45 -6
- package/src/concepts/Variable__.ts +14 -0
- package/src/concepts/ViewComponent__.ts +35 -35
- package/src/concepts/ViewElement__.ts +104 -1
- package/src/concepts/View__.ts +24 -2
- package/src/concepts/basics/stdlib/index.ts +2 -1
- package/src/concepts/basics/stdlib/nasl.auth.ts +24 -0
- package/src/concepts/basics/stdlib/nasl.http.ts +166 -0
- package/src/concepts/basics/stdlib/nasl.process.ts +68 -0
- package/src/concepts/basics/stdlib/nasl.ui.ts +4 -19
- package/src/concepts/basics/stdlib/nasl.util.ts +83 -17
- package/src/concepts/basics/types/index.ts +5 -4
- package/src/concepts/index__.ts +8 -0
- package/src/enums/KEYWORDS.ts +0 -1
- package/src/generator/genBundleFiles.ts +36 -2
- package/src/generator/genMetaData.ts +16 -1
- package/src/generator/genReleaseBody.ts +4 -1
- package/src/index.ts +2 -1
- package/src/server/extendBaseNode.ts +18 -7
- package/src/server/formatTsUtils.ts +37 -5
- package/src/server/getExtensionModules.ts +18 -3
- package/src/server/getLogics.ts +6 -6
- package/src/server/getMemberIdentifier.ts +35 -9
- package/src/server/naslServer.ts +250 -124
- package/src/server/naslStdlibMap.ts +2 -0
- package/src/server/translator.ts +67 -1
- package/src/service/defaultErrorMessage.json +1 -0
- package/src/service/storage/api.js +7 -1
- package/src/service/storage/init.ts +66 -35
- package/src/service/storage/service.ts +18 -2
- package/src/utils/sortTsString.ts +32 -0
- package/src/utils/traverse.ts +2 -2
- package/test/examples/app-simple.json +73635 -0
- package/ts-worker/lib/tsserver.js +3 -3
- package/ts-worker/package.json +1 -1
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
import debounce from 'lodash/debounce';
|
|
2
|
+
|
|
3
|
+
import { BaseNode, App } from '../../concepts';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
STATUS_ENABLED,
|
|
7
|
+
STATUS_DELETED,
|
|
8
|
+
TARGET_BACKEND,
|
|
9
|
+
TARGET_FRONTEND,
|
|
10
|
+
EVENT_TYPE_OBJECT_INFO,
|
|
11
|
+
EVENT_TYPE_PAGE_INFO,
|
|
12
|
+
EVENT_TYPE_PARSE,
|
|
13
|
+
EVENT_TYPE_RESOLVE,
|
|
14
|
+
EVENT_TYPE_STEP_OVER,
|
|
15
|
+
EVENT_TYPE_BREAKPOINT,
|
|
16
|
+
EVENT_TYPE_SYNC_BREAKPOINTS,
|
|
17
|
+
} from '../shared/constants';
|
|
18
|
+
|
|
19
|
+
import * as socket from '../shared/socket';
|
|
20
|
+
|
|
21
|
+
import { setCreate, setUpdate, setDelete } from '../shared/operations';
|
|
22
|
+
import { getRealNode, traverseBreakpointOnNode, traverseBreakpointOnApp } from '../shared/utils';
|
|
23
|
+
|
|
24
|
+
type Store = {
|
|
25
|
+
enable?: Boolean,
|
|
26
|
+
activePath?: string;
|
|
27
|
+
activeStackItem?: any;
|
|
28
|
+
echoStackItem?: any,
|
|
29
|
+
nodes?: BaseNode[];
|
|
30
|
+
stack?: any[],
|
|
31
|
+
connections?: string[];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
type StepOverData = Parameters<typeof socket.emitToFrontend>[0];
|
|
35
|
+
|
|
36
|
+
export const store: Store = {
|
|
37
|
+
enable: true,
|
|
38
|
+
nodes: [],
|
|
39
|
+
stack: [],
|
|
40
|
+
connections: [],
|
|
41
|
+
activePath: '',
|
|
42
|
+
activeStackItem: {},
|
|
43
|
+
echoStackItem: {},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
Object.defineProperty(store, 'activePath', {
|
|
47
|
+
get: () => {
|
|
48
|
+
const { activeStackItem = {} } = store;
|
|
49
|
+
const { operation = {} } = activeStackItem;
|
|
50
|
+
const { path = '' } = operation;
|
|
51
|
+
|
|
52
|
+
return path;
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const isUseful = (node: BaseNode) => {
|
|
57
|
+
if (!node) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const { app, nodePath } = (node as any);
|
|
62
|
+
|
|
63
|
+
if (!app || !nodePath) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return app.findNodeByPath(nodePath);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const clean = debounce(() => {
|
|
71
|
+
const set = new Set();
|
|
72
|
+
|
|
73
|
+
for (let i = 0; i < store.nodes.length; i += 1) {
|
|
74
|
+
const current = store.nodes[i];
|
|
75
|
+
const { id } = current;
|
|
76
|
+
|
|
77
|
+
const repeated = set.has(id);
|
|
78
|
+
const useless = !isUseful(current);
|
|
79
|
+
|
|
80
|
+
if (useless || repeated) {
|
|
81
|
+
store.nodes.splice(i, 1);
|
|
82
|
+
i -= 1;
|
|
83
|
+
} else {
|
|
84
|
+
set.add(id);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}, 300);
|
|
88
|
+
|
|
89
|
+
export const syncBreakpointsToFrontend = () => {
|
|
90
|
+
const { nodes = [] } = store;
|
|
91
|
+
|
|
92
|
+
const paths = nodes.map((item) => item.nodePath);
|
|
93
|
+
|
|
94
|
+
socket.emitToFrontend({
|
|
95
|
+
eventType: EVENT_TYPE_SYNC_BREAKPOINTS,
|
|
96
|
+
paths,
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const creater = (node: BaseNode) => {
|
|
101
|
+
if (!node?.breakpoint) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
store.nodes.push(node);
|
|
106
|
+
clean();
|
|
107
|
+
|
|
108
|
+
syncBreakpointsToFrontend();
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const deleter = (node: BaseNode) => {
|
|
112
|
+
const index = store.nodes.indexOf(node);
|
|
113
|
+
index > -1 && store.nodes.splice(index, 1);
|
|
114
|
+
|
|
115
|
+
syncBreakpointsToFrontend();
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const updater = (node: BaseNode) => {
|
|
119
|
+
if (!node) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const { breakpoint } = node;
|
|
124
|
+
const { nodes = [] } = store;
|
|
125
|
+
|
|
126
|
+
const included = nodes.includes(node);
|
|
127
|
+
|
|
128
|
+
if (breakpoint) {
|
|
129
|
+
!included && creater(node);
|
|
130
|
+
} else {
|
|
131
|
+
included && deleter(node);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
setCreate(creater);
|
|
136
|
+
setUpdate(updater);
|
|
137
|
+
setDelete(deleter);
|
|
138
|
+
|
|
139
|
+
export const addBreakpointNode = (node: BaseNode) => {
|
|
140
|
+
node = getRealNode(node);
|
|
141
|
+
|
|
142
|
+
if (!node) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
node.update({ breakpoint: STATUS_ENABLED });
|
|
147
|
+
socket.emitToBackend({
|
|
148
|
+
eventType: EVENT_TYPE_BREAKPOINT,
|
|
149
|
+
breakpoint: {
|
|
150
|
+
path: node.nodePath,
|
|
151
|
+
breakpointStatus: STATUS_ENABLED,
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
creater(node);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export const removeBreakpointNode = (node: BaseNode) => {
|
|
159
|
+
node = getRealNode(node);
|
|
160
|
+
|
|
161
|
+
if (!node) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
node.update({ breakpoint: null });
|
|
166
|
+
socket.emitToBackend({
|
|
167
|
+
eventType: EVENT_TYPE_BREAKPOINT,
|
|
168
|
+
breakpoint: {
|
|
169
|
+
path: node.nodePath,
|
|
170
|
+
breakpointStatus: STATUS_DELETED,
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
deleter(node);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
export const addBreakpointNodesFromNode = (source: BaseNode) => {
|
|
178
|
+
traverseBreakpointOnNode(source, creater);
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
export const addBreakpointNodesFromApp = (source: App) => {
|
|
182
|
+
store.nodes = [];
|
|
183
|
+
traverseBreakpointOnApp(source, creater);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
let temporaryNodes: BaseNode[] = [];
|
|
187
|
+
|
|
188
|
+
export const recoverBreakpointAfterTemporary = () => {
|
|
189
|
+
temporaryNodes.forEach((node) => {
|
|
190
|
+
if (node) {
|
|
191
|
+
node.breakpoint = STATUS_ENABLED;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
export const removeBreakpointForTemporary = async () => {
|
|
197
|
+
temporaryNodes = store.nodes || [];
|
|
198
|
+
temporaryNodes.forEach((node) => {
|
|
199
|
+
if (node && 'breakpoint' in node) {
|
|
200
|
+
delete node.breakpoint;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
await Promise.resolve(temporaryNodes);
|
|
205
|
+
recoverBreakpointAfterTemporary();
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
export const findFromStack = (targetPath = store.activePath) => {
|
|
209
|
+
const { stack = [], activeStackItem = {} } = store;
|
|
210
|
+
const { operation: { path: activeStackItemPath = '' } = {} } = activeStackItem;
|
|
211
|
+
|
|
212
|
+
if (activeStackItemPath === targetPath) {
|
|
213
|
+
return activeStackItem;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return stack.find((item = {}) => {
|
|
217
|
+
const { operation: { path = '' } = {} } = item;
|
|
218
|
+
|
|
219
|
+
return targetPath === path;
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
export const resolveBreakpointToBackend = (path = store.activePath) => {
|
|
224
|
+
const eventType = EVENT_TYPE_RESOLVE;
|
|
225
|
+
const data = { eventType, path };
|
|
226
|
+
|
|
227
|
+
path && socket.emitToBackend(data);
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
export const resolveBreakpointToFrontend = (path = store.activePath) => {
|
|
231
|
+
const eventType = EVENT_TYPE_RESOLVE;
|
|
232
|
+
const data = { eventType, path };
|
|
233
|
+
|
|
234
|
+
path && socket.emitToFrontend(data);
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
export const resolveByPath = (path = store.activePath) => {
|
|
238
|
+
const { activePath, stack = [] } = store;
|
|
239
|
+
|
|
240
|
+
const found = findFromStack(path);
|
|
241
|
+
const nextStack = stack.filter((item) => item !== found);
|
|
242
|
+
|
|
243
|
+
if (activePath === path) {
|
|
244
|
+
store.activeStackItem = nextStack[0];
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
store.stack = nextStack;
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
export const resolveBreakpoint = (path = store.activePath) => {
|
|
251
|
+
const found = findFromStack();
|
|
252
|
+
|
|
253
|
+
if (!found) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const { target } = found;
|
|
258
|
+
|
|
259
|
+
switch (target) {
|
|
260
|
+
case TARGET_BACKEND: {
|
|
261
|
+
resolveBreakpointToBackend(path);
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
case TARGET_FRONTEND: {
|
|
265
|
+
resolveBreakpointToFrontend(path);
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
store.echoStackItem = found;
|
|
271
|
+
resolveByPath();
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const stepOverBreakpointToBackend = () => {
|
|
275
|
+
const { activePath } = store;
|
|
276
|
+
|
|
277
|
+
activePath && socket.emitToBackend({
|
|
278
|
+
eventType: EVENT_TYPE_STEP_OVER,
|
|
279
|
+
path: store.activePath,
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
const stepOverBreakpointToFrontend = (data: StepOverData = {}) => {
|
|
284
|
+
const { activePath } = store;
|
|
285
|
+
|
|
286
|
+
activePath && socket.emitToFrontend({
|
|
287
|
+
eventType: EVENT_TYPE_STEP_OVER,
|
|
288
|
+
path: store.activePath,
|
|
289
|
+
...data,
|
|
290
|
+
});
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
export const stepOverBreakpoint = (data: StepOverData = {}) => {
|
|
294
|
+
const found = findFromStack();
|
|
295
|
+
|
|
296
|
+
if (!found) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const { target } = found;
|
|
301
|
+
|
|
302
|
+
switch (target) {
|
|
303
|
+
case TARGET_BACKEND: {
|
|
304
|
+
stepOverBreakpointToBackend();
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
case TARGET_FRONTEND: {
|
|
308
|
+
stepOverBreakpointToFrontend(data);
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
store.echoStackItem = found;
|
|
314
|
+
resolveByPath();
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
const CACHE_KEY = 'activePath';
|
|
318
|
+
const cacher = new Map();
|
|
319
|
+
|
|
320
|
+
const clearBeforeEmit = () => {
|
|
321
|
+
const { activePath: storeActivePath } = store;
|
|
322
|
+
const cacheActivePath = cacher.get(CACHE_KEY);
|
|
323
|
+
|
|
324
|
+
const empty = !cacheActivePath;
|
|
325
|
+
const different = storeActivePath !== cacheActivePath;
|
|
326
|
+
|
|
327
|
+
empty && cacher.clear();
|
|
328
|
+
different && cacher.clear();
|
|
329
|
+
|
|
330
|
+
cacher.set(CACHE_KEY, storeActivePath);
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
const emitToBackendWithCache = (source: Record<string, any> = {}) => {
|
|
334
|
+
clearBeforeEmit();
|
|
335
|
+
|
|
336
|
+
const key = JSON.stringify(source);
|
|
337
|
+
const cache = cacher.get(key) || socket.emitToBackend(source);
|
|
338
|
+
|
|
339
|
+
cacher.set(key, cache);
|
|
340
|
+
return cache;
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
export const fetchBackendPage = (source: Record<string, any> = {}) => emitToBackendWithCache({
|
|
344
|
+
eventType: EVENT_TYPE_PAGE_INFO,
|
|
345
|
+
...source,
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
export const fetchBackendObject = (source: Record<string, any> = {}) => emitToBackendWithCache({
|
|
349
|
+
eventType: EVENT_TYPE_OBJECT_INFO,
|
|
350
|
+
...source,
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
let variableNodes: BaseNode[] = [];
|
|
354
|
+
let variablesPromise: Promise<any>;
|
|
355
|
+
let resolveVariablesPromise: (arg: any) => void;
|
|
356
|
+
|
|
357
|
+
const nodeToCode = (node: BaseNode) => {
|
|
358
|
+
let code;
|
|
359
|
+
|
|
360
|
+
try {
|
|
361
|
+
if ('toJS' in node) {
|
|
362
|
+
code = (node as any).toJS();
|
|
363
|
+
}
|
|
364
|
+
} catch (e) {
|
|
365
|
+
console.error(e);
|
|
366
|
+
code = '';
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
return code;
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
const fetchVariables = debounce(async () => {
|
|
373
|
+
const { activePath } = store;
|
|
374
|
+
|
|
375
|
+
const resolve = resolveVariablesPromise;
|
|
376
|
+
const codes = variableNodes.map(nodeToCode);
|
|
377
|
+
|
|
378
|
+
variableNodes = [];
|
|
379
|
+
variablesPromise = undefined;
|
|
380
|
+
resolveVariablesPromise = undefined;
|
|
381
|
+
|
|
382
|
+
const result = await socket.emitToFrontend({
|
|
383
|
+
eventType: EVENT_TYPE_PARSE,
|
|
384
|
+
path: activePath,
|
|
385
|
+
codes,
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
resolve && resolve(result);
|
|
389
|
+
}, 0, { leading: false, trailing: true });
|
|
390
|
+
|
|
391
|
+
const getVariablesPromise = () => {
|
|
392
|
+
variablesPromise = variablesPromise || new Promise((resolve) => {
|
|
393
|
+
resolveVariablesPromise = resolve;
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
fetchVariables();
|
|
397
|
+
return variablesPromise;
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
export const fetchFrontendVariable = async (node: BaseNode) => {
|
|
401
|
+
const { length } = variableNodes;
|
|
402
|
+
|
|
403
|
+
variableNodes = variableNodes.concat(node);
|
|
404
|
+
|
|
405
|
+
const promise = getVariablesPromise();
|
|
406
|
+
const result = await promise;
|
|
407
|
+
|
|
408
|
+
return result && result[length];
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
export default store;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EVENT_DISCONNECT,
|
|
3
|
+
EVENT_RECONNECT,
|
|
4
|
+
TARGET_BACKEND,
|
|
5
|
+
TARGET_FRONTEND,
|
|
6
|
+
EVENT_TYPE_RESOLVE,
|
|
7
|
+
EVENT_TYPE_BREAKPOINT,
|
|
8
|
+
RESPONSE_TYPE_DEBUG_INFO,
|
|
9
|
+
RESPONSE_TYPE_CONNECTION_INFO,
|
|
10
|
+
CONNECTION_NAME_BACKEND,
|
|
11
|
+
CONNECTION_NAME_FRONTEND,
|
|
12
|
+
CONNECTION_STATUS_CONNECTED,
|
|
13
|
+
CONNECTION_STATUS_DISCONNECTED,
|
|
14
|
+
} from '../shared/constants';
|
|
15
|
+
|
|
16
|
+
import * as socket from '../shared/socket';
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
store,
|
|
20
|
+
findFromStack,
|
|
21
|
+
resolveByPath,
|
|
22
|
+
resolveBreakpoint,
|
|
23
|
+
syncBreakpointsToFrontend,
|
|
24
|
+
} from './core';
|
|
25
|
+
|
|
26
|
+
type Source = {
|
|
27
|
+
target?: string,
|
|
28
|
+
operation?: {
|
|
29
|
+
threadId?: number,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type ForBreakpoint = (target: string) => Parameters<typeof socket.on>[1];
|
|
34
|
+
|
|
35
|
+
const isMatchStepOver = (source: Source = {}) => {
|
|
36
|
+
const { echoStackItem = {} } = store;
|
|
37
|
+
const {
|
|
38
|
+
target,
|
|
39
|
+
operation: { threadId = 0 } = {},
|
|
40
|
+
} = echoStackItem;
|
|
41
|
+
const {
|
|
42
|
+
target: sourceTarget,
|
|
43
|
+
operation: { threadId: sourceThreadId = 0 } = {},
|
|
44
|
+
} = source;
|
|
45
|
+
|
|
46
|
+
const a = [target, threadId];
|
|
47
|
+
const b = [sourceTarget, sourceThreadId];
|
|
48
|
+
|
|
49
|
+
return a.every((x, i) => a[i] === b[i]);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const forBreakpoint: ForBreakpoint = (target) => (data = {}) => {
|
|
53
|
+
const { enable, activePath, activeStackItem } = store;
|
|
54
|
+
const { path } = data;
|
|
55
|
+
|
|
56
|
+
const current = { target, operation: data };
|
|
57
|
+
const matched = isMatchStepOver(current);
|
|
58
|
+
|
|
59
|
+
if (matched) {
|
|
60
|
+
store.stack.unshift(current);
|
|
61
|
+
store.activeStackItem = current;
|
|
62
|
+
store.echoStackItem = undefined;
|
|
63
|
+
} else {
|
|
64
|
+
store.stack.push(current);
|
|
65
|
+
store.activeStackItem = activePath ? activeStackItem : current;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
!enable && path && resolveBreakpoint(path);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// 前端代码执行到断点发送过来
|
|
72
|
+
socket.on(EVENT_TYPE_BREAKPOINT, forBreakpoint(TARGET_FRONTEND));
|
|
73
|
+
|
|
74
|
+
// 后端代码执行到断点发送过来
|
|
75
|
+
socket.on(RESPONSE_TYPE_DEBUG_INFO, forBreakpoint(TARGET_BACKEND));
|
|
76
|
+
|
|
77
|
+
// 建立连接时
|
|
78
|
+
socket.on(RESPONSE_TYPE_CONNECTION_INFO, (data = {}) => {
|
|
79
|
+
const { connectionName, connectionStatus } = data;
|
|
80
|
+
|
|
81
|
+
const isFrontend = connectionName === CONNECTION_NAME_FRONTEND;
|
|
82
|
+
const isConnected = connectionStatus === CONNECTION_STATUS_CONNECTED;
|
|
83
|
+
|
|
84
|
+
if (isFrontend && isConnected) {
|
|
85
|
+
syncBreakpointsToFrontend();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const cleanStackWhenDisconnect = (target: string) => {
|
|
90
|
+
if (!target) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const found = findFromStack();
|
|
95
|
+
|
|
96
|
+
const { stack = [] } = store;
|
|
97
|
+
const filter = (item: any = {}) => item.target !== target;
|
|
98
|
+
|
|
99
|
+
store.stack = stack.filter(filter);
|
|
100
|
+
|
|
101
|
+
const useful = store.stack.includes(found);
|
|
102
|
+
|
|
103
|
+
if (useful) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
store.activeStackItem = store.stack[0];
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// 连接发生变化时
|
|
111
|
+
socket.on(RESPONSE_TYPE_CONNECTION_INFO, (data = {}) => {
|
|
112
|
+
const { connections = [] } = store;
|
|
113
|
+
const { connectionName, connectionStatus } = data;
|
|
114
|
+
|
|
115
|
+
switch (connectionStatus) {
|
|
116
|
+
case CONNECTION_STATUS_CONNECTED: {
|
|
117
|
+
store.connections.push(connectionName);
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
case CONNECTION_STATUS_DISCONNECTED: {
|
|
121
|
+
const filter = (item: string) => item !== connectionName;
|
|
122
|
+
store.connections = connections.filter(filter);
|
|
123
|
+
|
|
124
|
+
switch (connectionName) {
|
|
125
|
+
case CONNECTION_NAME_BACKEND: {
|
|
126
|
+
cleanStackWhenDisconnect(TARGET_BACKEND);
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
case CONNECTION_NAME_FRONTEND: {
|
|
130
|
+
cleanStackWhenDisconnect(TARGET_FRONTEND);
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// 前端手动释放断点
|
|
140
|
+
socket.on(EVENT_TYPE_RESOLVE, (data = {}) => {
|
|
141
|
+
const { path } = data;
|
|
142
|
+
|
|
143
|
+
path && resolveByPath(path);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
const cleanStore = () => {
|
|
147
|
+
store.stack = [];
|
|
148
|
+
store.connections = [];
|
|
149
|
+
store.activeStackItem = {};
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
socket.on(EVENT_DISCONNECT, cleanStore);
|
|
153
|
+
socket.on(EVENT_RECONNECT, cleanStore);
|
|
154
|
+
|
|
155
|
+
socket.setBackendPolyfillGetter(() => {
|
|
156
|
+
const found = findFromStack();
|
|
157
|
+
|
|
158
|
+
if (!found) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const { operation = {} } = found;
|
|
163
|
+
const { variables, ...rest } = operation;
|
|
164
|
+
|
|
165
|
+
return rest;
|
|
166
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare module 'socket.io-client' {
|
|
2
|
+
export interface Socket {
|
|
3
|
+
connected: boolean;
|
|
4
|
+
on: (...args: any[]) => void;
|
|
5
|
+
emit: (...args: any[]) => void;
|
|
6
|
+
close: (...args: any[]) => void;
|
|
7
|
+
disconnect: (...args: any[]) => void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type IO = (...args: any[]) => any;
|
|
11
|
+
|
|
12
|
+
const io: IO = () => ({});
|
|
13
|
+
|
|
14
|
+
export default io;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare module 'lodash/debounce' {
|
|
18
|
+
export default (...args: any[]) => any;
|
|
19
|
+
}
|
package/src/common/BaseNode.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { ViewElement, App, TypeAnnotation } from '..';
|
|
|
16
16
|
import * as jsoner from '../service/storage/jsoner';
|
|
17
17
|
|
|
18
18
|
import { sentryMonitorNaslNode } from '../sentry';
|
|
19
|
+
import operations from '../breakpoint/shared/operations';
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* 顶点类
|
|
@@ -59,6 +60,15 @@ export class BaseNode extends EventEmitter {
|
|
|
59
60
|
workingCopy: object = undefined;
|
|
60
61
|
@property()
|
|
61
62
|
branch: object = undefined;
|
|
63
|
+
/**
|
|
64
|
+
* 断点状态
|
|
65
|
+
* undefined ==> 未设置
|
|
66
|
+
* null ==> 已删除
|
|
67
|
+
* 'ENABLED' ==> 启用断点
|
|
68
|
+
* 'DISABLED' ==> 禁用断点
|
|
69
|
+
*/
|
|
70
|
+
@property()
|
|
71
|
+
breakpoint: 'ENABLED' | 'DISABLED' | null | undefined = undefined;
|
|
62
72
|
/**
|
|
63
73
|
* 父节点
|
|
64
74
|
*/
|
|
@@ -170,6 +180,13 @@ export class BaseNode extends EventEmitter {
|
|
|
170
180
|
this.on('create', this.genActionListener);
|
|
171
181
|
this.on('delete', this.genActionListener);
|
|
172
182
|
this.on('update', this.genActionListener);
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* 监听action,delete,update事件
|
|
186
|
+
*/
|
|
187
|
+
this.on('create', () => operations.create(this));
|
|
188
|
+
this.on('delete', () => operations.delete(this));
|
|
189
|
+
this.on('update', () => operations.update(this));
|
|
173
190
|
}
|
|
174
191
|
|
|
175
192
|
// static constructorName = 'BaseNode'
|
|
@@ -203,6 +220,7 @@ export class BaseNode extends EventEmitter {
|
|
|
203
220
|
throw e;
|
|
204
221
|
}
|
|
205
222
|
});
|
|
223
|
+
operations.create(this);
|
|
206
224
|
// if (config.storage.protocol === 'http' && loadThen[source.concept as 'App' | 'View']) {
|
|
207
225
|
// const { childNodes } = loadThen[source.concept as 'App' | 'View'] || {};
|
|
208
226
|
// const queryList = childNodes.map(({ field, concept }) => {
|
|
@@ -1045,7 +1063,7 @@ export class BaseNode extends EventEmitter {
|
|
|
1045
1063
|
}
|
|
1046
1064
|
get isTreeLeaf() {
|
|
1047
1065
|
if (this.concept === 'EntityProperty' || this.concept === 'InterfaceParam' || this.concept === 'Param'
|
|
1048
|
-
|
|
1066
|
+
|| this.concept === 'Return' || this.concept === 'StructureProperty' || this.concept === 'Variable') {
|
|
1049
1067
|
if ((this as any).typeAnnotation || (this.__TypeAnnotation && this.parentKey === 'virtualParams')) {
|
|
1050
1068
|
return !this.hasChildren;
|
|
1051
1069
|
} else {
|