@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,326 @@
|
|
|
1
|
+
import io, { Socket } from 'socket.io-client';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
EVENT_DISCONNECT,
|
|
5
|
+
EVENT_RECONNECT,
|
|
6
|
+
TARGET_BACKEND,
|
|
7
|
+
TARGET_FRONTEND,
|
|
8
|
+
EVENT_TYPE_BREAKPOINT,
|
|
9
|
+
EVENT_TYPE_PAGE_INFO,
|
|
10
|
+
EVENT_TYPE_OBJECT_INFO,
|
|
11
|
+
RESPONSE_TYPE_FRONTEND_INFO,
|
|
12
|
+
RESPONSE_TYPE_OBJECT_INFO,
|
|
13
|
+
RESPONSE_TYPE_PAGE_INFO,
|
|
14
|
+
} from './constants';
|
|
15
|
+
|
|
16
|
+
type RequestData = {
|
|
17
|
+
target?: string,
|
|
18
|
+
operation?: {
|
|
19
|
+
eventType?: string,
|
|
20
|
+
path?: string,
|
|
21
|
+
threadId?: number,
|
|
22
|
+
breakpointStatus?: string,
|
|
23
|
+
frontendInfo?: any,
|
|
24
|
+
breakpoint?: {
|
|
25
|
+
path?: string,
|
|
26
|
+
breakpointStatus?: string,
|
|
27
|
+
},
|
|
28
|
+
[key: string]: any,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
type ResponseData = {
|
|
33
|
+
type?: string,
|
|
34
|
+
data?: {
|
|
35
|
+
path?: string,
|
|
36
|
+
eventType?: string,
|
|
37
|
+
pageNum?: number,
|
|
38
|
+
pageSize?: number,
|
|
39
|
+
uniqueId?: number,
|
|
40
|
+
threadId?: number,
|
|
41
|
+
requestId?: number,
|
|
42
|
+
connectionName?: string,
|
|
43
|
+
connectionStatus?: string,
|
|
44
|
+
exceptionMsg?: string,
|
|
45
|
+
variables?: any,
|
|
46
|
+
variable?: any,
|
|
47
|
+
beacon?: any,
|
|
48
|
+
result?: any,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
type Getter = () => Record<string, any>;
|
|
53
|
+
type Listner = (source: ResponseData['data']) => void;
|
|
54
|
+
|
|
55
|
+
let socket: Socket;
|
|
56
|
+
const store: Record<string, Listner[]> = {};
|
|
57
|
+
|
|
58
|
+
const socketType = 'debug';
|
|
59
|
+
|
|
60
|
+
const namespace = '/debug/ide';
|
|
61
|
+
const path = '/debug/context';
|
|
62
|
+
|
|
63
|
+
const nativeTypes = [EVENT_DISCONNECT, EVENT_RECONNECT];
|
|
64
|
+
|
|
65
|
+
const callback = (result: ResponseData = {}) => {
|
|
66
|
+
const { type, data = {} } = result;
|
|
67
|
+
const { eventType } = data;
|
|
68
|
+
|
|
69
|
+
if (!type) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const key = type === RESPONSE_TYPE_FRONTEND_INFO ? eventType : type;
|
|
74
|
+
|
|
75
|
+
if (!key) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const { [key]: listeners = [] } = store;
|
|
80
|
+
|
|
81
|
+
listeners.forEach((listener) => listener(data));
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const register = (socket: Socket) => {
|
|
85
|
+
socket && nativeTypes.forEach((type) => {
|
|
86
|
+
socket.on(type, () => callback({ type }));
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const isConnected = () => socket && socket.connected;
|
|
91
|
+
|
|
92
|
+
export const connect = (appId = '') => {
|
|
93
|
+
if (socket) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (!appId) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const query = { appId };
|
|
102
|
+
const extraHeaders = query;
|
|
103
|
+
|
|
104
|
+
const transportOptions = {
|
|
105
|
+
polling: { extraHeaders },
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
socket = io(namespace, {
|
|
109
|
+
transports: ['websocket'],
|
|
110
|
+
reconnectionAttempts: 5,
|
|
111
|
+
transportOptions,
|
|
112
|
+
path,
|
|
113
|
+
query,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
socket.on(socketType, callback);
|
|
117
|
+
register(socket);
|
|
118
|
+
|
|
119
|
+
return new Promise((resolve, reject) => {
|
|
120
|
+
socket.on('connect', () => resolve(socket));
|
|
121
|
+
|
|
122
|
+
socket.on('error', reject);
|
|
123
|
+
socket.on('connect_error', reject);
|
|
124
|
+
socket.on('connect_timeout', reject);
|
|
125
|
+
socket.on(EVENT_DISCONNECT, reject);
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
export const disconnect = () => {
|
|
130
|
+
socket && socket.disconnect();
|
|
131
|
+
socket = null;
|
|
132
|
+
|
|
133
|
+
callback({ type: EVENT_DISCONNECT });
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export const off = (type: string, listener: Listner) => {
|
|
137
|
+
const { [type]: listeners = [] } = store;
|
|
138
|
+
store[type] = listeners.filter((item) => item !== listener);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export const on = (type: string, listener: Listner) => {
|
|
142
|
+
const { [type]: listeners = [] } = store;
|
|
143
|
+
store[type] = listeners.concat(listener);
|
|
144
|
+
|
|
145
|
+
return () => off(type, listener);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export const emit = (data: RequestData = {}) => {
|
|
149
|
+
if (!socket) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
socket.emit(socketType, data);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
let getter: Getter = () => ({});
|
|
157
|
+
|
|
158
|
+
const getBackenPolyfill = () => getter && getter();
|
|
159
|
+
|
|
160
|
+
export const setBackendPolyfillGetter = (rookie: Getter) => {
|
|
161
|
+
getter = rookie || getter;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const isUsefulArray = (array: any[] = []) => array.every((item) => item !== undefined);
|
|
165
|
+
const isDifferentArray = (a: any[] = [], b: any[] = []) => {
|
|
166
|
+
const length = Math.max(a.length, b.length);
|
|
167
|
+
|
|
168
|
+
for (let i = 0; i < length; i += 1) {
|
|
169
|
+
if (a[i] !== b[i]) {
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return false;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const tick = (time = 5000) => (...args: Parameters<typeof on>) => new Promise((resolve) => {
|
|
178
|
+
// eslint-disable-next-line
|
|
179
|
+
let un: ReturnType<typeof on>;
|
|
180
|
+
// eslint-disable-next-line
|
|
181
|
+
let timer: ReturnType<typeof setTimeout>;
|
|
182
|
+
const [type, listener] = args;
|
|
183
|
+
|
|
184
|
+
const callback: typeof listener = async (...rest) => {
|
|
185
|
+
const result = listener && await listener(...rest);
|
|
186
|
+
|
|
187
|
+
if (result === undefined) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
un();
|
|
192
|
+
resolve(result);
|
|
193
|
+
timer && clearTimeout(timer);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
un = on(type, callback);
|
|
197
|
+
timer = setTimeout(un, time);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
const tickers = [
|
|
201
|
+
(data: RequestData = {}) => {
|
|
202
|
+
const { operation = {} } = data;
|
|
203
|
+
const {
|
|
204
|
+
eventType,
|
|
205
|
+
pageNum: requestPageNum,
|
|
206
|
+
pageSize: requestPageSize,
|
|
207
|
+
uniqueId: requestUniqueId,
|
|
208
|
+
} = operation;
|
|
209
|
+
|
|
210
|
+
if (eventType !== EVENT_TYPE_PAGE_INFO) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const requestValues = [requestPageNum, requestPageSize, requestUniqueId];
|
|
215
|
+
const useful = isUsefulArray(requestValues);
|
|
216
|
+
|
|
217
|
+
if (!useful) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return tick()(RESPONSE_TYPE_PAGE_INFO, (data = {}) => {
|
|
222
|
+
const {
|
|
223
|
+
variable,
|
|
224
|
+
pageNum: responsePageNum,
|
|
225
|
+
pageSize: responsePageSize,
|
|
226
|
+
uniqueId: responseUniqueId,
|
|
227
|
+
} = data;
|
|
228
|
+
|
|
229
|
+
if (!variable) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const responseValues = [responsePageNum, responsePageSize, responseUniqueId];
|
|
234
|
+
const different = isDifferentArray(responseValues, requestValues);
|
|
235
|
+
|
|
236
|
+
return different ? undefined : variable;
|
|
237
|
+
});
|
|
238
|
+
},
|
|
239
|
+
(data: RequestData = {}) => {
|
|
240
|
+
const { operation = {} } = data;
|
|
241
|
+
const { eventType, uniqueId: requestUniqueId } = operation;
|
|
242
|
+
|
|
243
|
+
if (eventType !== EVENT_TYPE_OBJECT_INFO) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const requestValues = [requestUniqueId];
|
|
248
|
+
const useful = isUsefulArray(requestValues);
|
|
249
|
+
|
|
250
|
+
if (!useful) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return tick()(RESPONSE_TYPE_OBJECT_INFO, (data = {}) => {
|
|
255
|
+
const {
|
|
256
|
+
variable,
|
|
257
|
+
uniqueId: responseUniqueId,
|
|
258
|
+
} = data;
|
|
259
|
+
|
|
260
|
+
if (!variable) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const responseValues = [responseUniqueId];
|
|
265
|
+
const different = isDifferentArray(responseValues, requestValues);
|
|
266
|
+
|
|
267
|
+
return different ? undefined : variable;
|
|
268
|
+
});
|
|
269
|
+
},
|
|
270
|
+
];
|
|
271
|
+
|
|
272
|
+
export const emitToBackend = (operation: RequestData['operation'] = {}) => {
|
|
273
|
+
const backendPolyfill = getBackenPolyfill() || {};
|
|
274
|
+
operation = { ...backendPolyfill, ...operation };
|
|
275
|
+
|
|
276
|
+
const { threadId, eventType } = operation;
|
|
277
|
+
const data = { target: TARGET_BACKEND, operation };
|
|
278
|
+
|
|
279
|
+
if (!threadId && eventType !== EVENT_TYPE_BREAKPOINT) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
emit(data);
|
|
284
|
+
|
|
285
|
+
return tickers.reduce((result, ticker) => result || ticker(data), undefined);
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
let uId = 0;
|
|
289
|
+
|
|
290
|
+
export const getBeacon = () => uId++;
|
|
291
|
+
|
|
292
|
+
export const emitToFrontend = (operation: RequestData['operation'] = {}) => {
|
|
293
|
+
const beacon = getBeacon();
|
|
294
|
+
|
|
295
|
+
const data = {
|
|
296
|
+
target: TARGET_FRONTEND,
|
|
297
|
+
operation: { beacon, ...operation },
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
emit(data);
|
|
301
|
+
|
|
302
|
+
const { eventType } = operation;
|
|
303
|
+
|
|
304
|
+
if (!eventType) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return tick()(eventType, (data = {}) => {
|
|
309
|
+
const { beacon: responseBeacon, result = 'null' } = data;
|
|
310
|
+
|
|
311
|
+
if (responseBeacon !== beacon) {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
let value;
|
|
316
|
+
|
|
317
|
+
try {
|
|
318
|
+
value = JSON.parse(result);
|
|
319
|
+
} catch (error) {
|
|
320
|
+
value = 'null';
|
|
321
|
+
console.error(error);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return value;
|
|
325
|
+
});
|
|
326
|
+
};
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { App, View, ViewElement, BaseNode } from '../../concepts';
|
|
2
|
+
|
|
3
|
+
import { TRAVERSE_NODE_KEYS, BREAKPOINT_CONCEPTS } from './constants';
|
|
4
|
+
|
|
5
|
+
type Callback = (node: BaseNode) => void;
|
|
6
|
+
|
|
7
|
+
type HistoryInApp = {
|
|
8
|
+
_historyIndex?: number,
|
|
9
|
+
_historyList?: Array<{
|
|
10
|
+
list?: Array<{
|
|
11
|
+
action?: 'delete' | 'create' | 'update',
|
|
12
|
+
object?: null | Record<string, any>,
|
|
13
|
+
oldObject?: null | Record<string, any>,
|
|
14
|
+
}>,
|
|
15
|
+
}>,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const neatKeys = [
|
|
19
|
+
'breakpoint',
|
|
20
|
+
'offsetX',
|
|
21
|
+
'offsetY',
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
export const isAppDirty = (app: HistoryInApp = {}) => {
|
|
25
|
+
if (!app) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const {
|
|
30
|
+
_historyIndex = 0,
|
|
31
|
+
_historyList = [],
|
|
32
|
+
} = app;
|
|
33
|
+
|
|
34
|
+
const historyList = _historyList.slice(0, _historyIndex);
|
|
35
|
+
|
|
36
|
+
return historyList.some((item = {}) => {
|
|
37
|
+
const { list = [] } = item;
|
|
38
|
+
|
|
39
|
+
return list.some((current = {}) => {
|
|
40
|
+
const { action, oldObject } = current;
|
|
41
|
+
|
|
42
|
+
if (action !== 'update') {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!oldObject) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const keys = Object.keys(oldObject);
|
|
51
|
+
const filter = (key: string) => !neatKeys.includes(key);
|
|
52
|
+
const dirtyKeys = keys.filter(filter);
|
|
53
|
+
|
|
54
|
+
return dirtyKeys.length > 0;
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const getRealNode = (node: BaseNode): BaseNode => {
|
|
60
|
+
if (!node) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const { concept, object } = (node as any);
|
|
65
|
+
|
|
66
|
+
if (concept === 'MemberExpression') {
|
|
67
|
+
return getRealNode(object as BaseNode);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return node;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const unbrakableAncestors = [
|
|
74
|
+
'BindAttribute',
|
|
75
|
+
'CallAuthInterface',
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
export const isBreakable = (node: BaseNode): Boolean => {
|
|
79
|
+
node = getRealNode(node);
|
|
80
|
+
|
|
81
|
+
if (!node) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const { concept } = node;
|
|
86
|
+
|
|
87
|
+
const ancestor = unbrakableAncestors.some((ancestor) => node.getAncestor(ancestor));
|
|
88
|
+
|
|
89
|
+
if (ancestor) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return BREAKPOINT_CONCEPTS.includes(concept);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const getUniqueIdFromNode = (node: BaseNode) => node && node.nodePath;
|
|
97
|
+
|
|
98
|
+
export const getLogics = (app: App) => {
|
|
99
|
+
if (!app) {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const { logics = [], frontends = [] } = app;
|
|
104
|
+
|
|
105
|
+
let result = logics;
|
|
106
|
+
|
|
107
|
+
const forViewElement = (viewElement: ViewElement) => {
|
|
108
|
+
if (!viewElement) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const {
|
|
113
|
+
children: viewElementChildren = [],
|
|
114
|
+
bindEvents: viewElementBindEvents = [],
|
|
115
|
+
} = viewElement;
|
|
116
|
+
|
|
117
|
+
viewElementBindEvents.forEach((bindEvent) => {
|
|
118
|
+
const { logics: bindEventLogics = [] } = bindEvent;
|
|
119
|
+
|
|
120
|
+
result = result.concat(bindEventLogics);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
viewElementChildren.forEach(forViewElement);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const forView = (view: View) => {
|
|
127
|
+
if (!view) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const {
|
|
132
|
+
logics: viewLogics = [],
|
|
133
|
+
elements: viewElements = [],
|
|
134
|
+
children: viewChildren = [],
|
|
135
|
+
bindEvents: viewBindEvents = [],
|
|
136
|
+
} = view;
|
|
137
|
+
|
|
138
|
+
result = result.concat(viewLogics);
|
|
139
|
+
|
|
140
|
+
viewBindEvents.forEach((bindEvent) => {
|
|
141
|
+
const { logics: bindEventLogics = [] } = bindEvent;
|
|
142
|
+
|
|
143
|
+
result = result.concat(bindEventLogics);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
viewElements.forEach(forViewElement);
|
|
147
|
+
viewChildren.forEach(forView);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
frontends.forEach((frontend) => {
|
|
151
|
+
const { views = [] } = frontend;
|
|
152
|
+
|
|
153
|
+
views.forEach(forView);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
return result;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const hadBreakpoint = (node: BaseNode) => {
|
|
160
|
+
if (node instanceof BaseNode) {
|
|
161
|
+
return node.breakpoint;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return false;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
export const traverseBreakpointOnNode = (node: (BaseNode | any), callback: Callback) => {
|
|
168
|
+
if (!node) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const operate = (item: BaseNode) => hadBreakpoint(item) && callback(item);
|
|
173
|
+
const forEach = (item: BaseNode) => {
|
|
174
|
+
operate(item);
|
|
175
|
+
traverseBreakpointOnNode(item, callback);
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
operate(node);
|
|
179
|
+
TRAVERSE_NODE_KEYS.forEach((key) => {
|
|
180
|
+
const { [key]: value } = node;
|
|
181
|
+
const array = Array.isArray(value) ? value : [value];
|
|
182
|
+
|
|
183
|
+
array.forEach(forEach);
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
export const traverseBreakpointOnApp = (app: App, callback: Callback) => {
|
|
188
|
+
if (!app) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const logics = getLogics(app);
|
|
193
|
+
|
|
194
|
+
logics.forEach((logic) => traverseBreakpointOnNode(logic, callback));
|
|
195
|
+
};
|