@superblocksteam/sdk 1.7.0 → 1.8.0
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/dist/client.d.ts +3 -0
- package/dist/client.js +3 -0
- package/dist/socket/handlers.d.ts +4 -0
- package/dist/socket/socket.d.ts +1 -0
- package/dist/socket/socket.js +59 -57
- package/package.json +2 -2
- package/src/client.ts +6 -1
- package/src/socket/handlers.ts +4 -0
- package/src/socket/socket.ts +76 -79
package/dist/client.d.ts
CHANGED
|
@@ -19,10 +19,12 @@ export interface MultiPageApplicationWrapper {
|
|
|
19
19
|
export type PushApplicationWithCommitConfig = ApplicationWrapper & {
|
|
20
20
|
commitId: string;
|
|
21
21
|
commitMessage: string;
|
|
22
|
+
gitState: LocalGitRepoState;
|
|
22
23
|
};
|
|
23
24
|
export type PushMultiPageApplicationWithCommitConfig = MultiPageApplicationWrapper & {
|
|
24
25
|
commitId: string;
|
|
25
26
|
commitMessage: string;
|
|
27
|
+
gitState: LocalGitRepoState;
|
|
26
28
|
};
|
|
27
29
|
export interface ApiWrapper {
|
|
28
30
|
apiPb: Record<string, any>;
|
|
@@ -32,6 +34,7 @@ export type PushApiWithCommitConfig = {
|
|
|
32
34
|
apiPb: Record<string, any>;
|
|
33
35
|
commitId: string;
|
|
34
36
|
commitMessage: string;
|
|
37
|
+
gitState: LocalGitRepoState;
|
|
35
38
|
};
|
|
36
39
|
export type Branches = {
|
|
37
40
|
branches: Branch[];
|
package/dist/client.js
CHANGED
|
@@ -477,6 +477,7 @@ async function pushApplication({ cliVersion, applicationId, token, superblocksBa
|
|
|
477
477
|
commitId: applicationConfig.commitId,
|
|
478
478
|
commitMessage: applicationConfig.commitMessage,
|
|
479
479
|
pages: applicationConfig.pages,
|
|
480
|
+
gitState: applicationConfig.gitState,
|
|
480
481
|
})
|
|
481
482
|
: await socket.call.v1.public.application.pushCommit({
|
|
482
483
|
applicationId,
|
|
@@ -486,6 +487,7 @@ async function pushApplication({ cliVersion, applicationId, token, superblocksBa
|
|
|
486
487
|
commitId: applicationConfig.commitId,
|
|
487
488
|
commitMessage: applicationConfig.commitMessage,
|
|
488
489
|
page: applicationConfig.page,
|
|
490
|
+
gitState: applicationConfig.gitState,
|
|
489
491
|
});
|
|
490
492
|
socket.close();
|
|
491
493
|
handleHttpError(resp.responseMeta.status);
|
|
@@ -565,6 +567,7 @@ async function pushApi({ cliVersion, apiId, token, superblocksBaseUrl, apiConfig
|
|
|
565
567
|
branchName: branch,
|
|
566
568
|
commitId: apiConfig.commitId,
|
|
567
569
|
commitMessage: apiConfig.commitMessage,
|
|
570
|
+
gitState: apiConfig.gitState,
|
|
568
571
|
});
|
|
569
572
|
socket.close();
|
|
570
573
|
handleHttpError(resp.responseMeta.status);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LocalGitRepoState } from "@superblocksteam/util";
|
|
1
2
|
import { ApiToSign, ApiToVerify, AppToSign, AppToVerify, MethodHandlers, RemoteCommitDto, Signature } from "../types";
|
|
2
3
|
type MethodSchema<Params, Response> = (params: Params) => Promise<Response>;
|
|
3
4
|
export interface ClientMethods {
|
|
@@ -85,6 +86,7 @@ export interface ServerMethods {
|
|
|
85
86
|
application: Record<string, unknown>;
|
|
86
87
|
page: Record<string, unknown>;
|
|
87
88
|
apis: Record<string, unknown>[];
|
|
89
|
+
gitState: LocalGitRepoState;
|
|
88
90
|
}, RemoteCommitDto>;
|
|
89
91
|
};
|
|
90
92
|
api: {
|
|
@@ -94,6 +96,7 @@ export interface ServerMethods {
|
|
|
94
96
|
commitId: string;
|
|
95
97
|
commitMessage: string;
|
|
96
98
|
apiPb: Record<string, unknown>;
|
|
99
|
+
gitState: LocalGitRepoState;
|
|
97
100
|
}, RemoteCommitDto>;
|
|
98
101
|
};
|
|
99
102
|
};
|
|
@@ -109,6 +112,7 @@ export interface ServerMethods {
|
|
|
109
112
|
application: Record<string, unknown>;
|
|
110
113
|
pages: Record<string, unknown>[];
|
|
111
114
|
apis: Record<string, unknown>[];
|
|
115
|
+
gitState: LocalGitRepoState;
|
|
112
116
|
}, RemoteCommitDto>;
|
|
113
117
|
};
|
|
114
118
|
};
|
package/dist/socket/socket.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare class ISocket<ImplementedMethods, CallableMethods, RequestContext
|
|
|
8
8
|
private peerAuthorization?;
|
|
9
9
|
private nxtRequestId;
|
|
10
10
|
constructor(ws: WebSocket, requestHandlers: MethodHandlers<ImplementedMethods, CallableMethods, RequestContext>);
|
|
11
|
+
private handleEvent;
|
|
11
12
|
request<Params, Result>(method: string, params: Params, authorization?: string): Promise<Result>;
|
|
12
13
|
private respond;
|
|
13
14
|
private respondError;
|
package/dist/socket/socket.js
CHANGED
|
@@ -7,71 +7,73 @@ class ISocket {
|
|
|
7
7
|
this.ws = ws;
|
|
8
8
|
this.requestHandlers = requestHandlers;
|
|
9
9
|
this.nxtRequestId = 0;
|
|
10
|
-
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
this.ws.addEventListener("message", async (event) => {
|
|
10
|
+
this.ws.addEventListener("message", (event) => {
|
|
13
11
|
const eventData = JSON.parse(event.data.toString());
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (!Array.isArray(handlers)) {
|
|
29
|
-
return await this.respondError(eventData.request.id, {
|
|
12
|
+
void this.handleEvent(eventData);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
async handleEvent(eventData) {
|
|
16
|
+
if (eventData.request) {
|
|
17
|
+
// Split the method string into parts
|
|
18
|
+
const parts = eventData.request.method.split(".");
|
|
19
|
+
let handlers = this.requestHandlers;
|
|
20
|
+
for (const part of parts) {
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
handlers = handlers[part];
|
|
24
|
+
if (!handlers) {
|
|
25
|
+
return this.respondError(eventData.request.id, {
|
|
30
26
|
code: 2,
|
|
31
|
-
message:
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
if (eventData.request.setAuthorization) {
|
|
35
|
-
this.peerAuthorization = eventData.request.setAuthorization;
|
|
36
|
-
}
|
|
37
|
-
const middlewareHandlers = handlers.slice(0, -1);
|
|
38
|
-
const handler = handlers[handlers.length - 1];
|
|
39
|
-
const reqCtx = {};
|
|
40
|
-
let response;
|
|
41
|
-
// TODO(george): maybe we should not create a new client for each request
|
|
42
|
-
const client = createISocketClient(this);
|
|
43
|
-
try {
|
|
44
|
-
for (const middlewareHandler of middlewareHandlers) {
|
|
45
|
-
await middlewareHandler(eventData.request.payload, this.peerAuthorization, client, reqCtx);
|
|
46
|
-
}
|
|
47
|
-
response = await handler(eventData.request.payload, client, reqCtx);
|
|
48
|
-
}
|
|
49
|
-
catch (error) {
|
|
50
|
-
return await this.respondError(eventData.request.id, {
|
|
51
|
-
code: 3,
|
|
52
|
-
message: error.toString(),
|
|
27
|
+
message: `unknown method ${eventData.request.method}`,
|
|
53
28
|
});
|
|
54
29
|
}
|
|
55
|
-
await this.respond(eventData.request.id, response);
|
|
56
30
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
31
|
+
if (!Array.isArray(handlers)) {
|
|
32
|
+
return this.respondError(eventData.request.id, {
|
|
33
|
+
code: 2,
|
|
34
|
+
message: "unknown method",
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (eventData.request.setAuthorization) {
|
|
38
|
+
this.peerAuthorization = eventData.request.setAuthorization;
|
|
39
|
+
}
|
|
40
|
+
const middlewareHandlers = handlers.slice(0, -1);
|
|
41
|
+
const handler = handlers[handlers.length - 1];
|
|
42
|
+
const reqCtx = {};
|
|
43
|
+
let response;
|
|
44
|
+
// TODO(george): maybe we should not create a new client for each request
|
|
45
|
+
const client = createISocketClient(this);
|
|
46
|
+
try {
|
|
47
|
+
for (const middlewareHandler of middlewareHandlers) {
|
|
48
|
+
await middlewareHandler(eventData.request.payload, this.peerAuthorization, client, reqCtx);
|
|
63
49
|
}
|
|
64
|
-
|
|
65
|
-
this.responseHandler[eventData.response.id].resolve(eventData.response.payload);
|
|
66
|
-
delete this.responseHandler[eventData.response.id];
|
|
50
|
+
response = await handler(eventData.request.payload, client, reqCtx);
|
|
67
51
|
}
|
|
68
|
-
|
|
69
|
-
return
|
|
52
|
+
catch (error) {
|
|
53
|
+
return this.respondError(eventData.request.id, {
|
|
70
54
|
code: 3,
|
|
71
|
-
message:
|
|
55
|
+
message: error.toString(),
|
|
72
56
|
});
|
|
73
57
|
}
|
|
74
|
-
|
|
58
|
+
this.respond(eventData.request.id, response);
|
|
59
|
+
}
|
|
60
|
+
else if (eventData.response && eventData.response.id) {
|
|
61
|
+
if (!this.responseHandler[eventData.response.id]) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (eventData.response.error) {
|
|
65
|
+
this.responseHandler[eventData.response.id].reject(eventData.response.error);
|
|
66
|
+
}
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
68
|
+
this.responseHandler[eventData.response.id].resolve(eventData.response.payload);
|
|
69
|
+
delete this.responseHandler[eventData.response.id];
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
return this.respondError(-1, {
|
|
73
|
+
code: 3,
|
|
74
|
+
message: "unknown request id",
|
|
75
|
+
});
|
|
76
|
+
}
|
|
75
77
|
}
|
|
76
78
|
request(method, params, authorization) {
|
|
77
79
|
return new Promise((resolve, reject) => {
|
|
@@ -91,7 +93,7 @@ class ISocket {
|
|
|
91
93
|
this.ws.send(JSON.stringify(toSend));
|
|
92
94
|
});
|
|
93
95
|
}
|
|
94
|
-
|
|
96
|
+
respond(requestId, result) {
|
|
95
97
|
const toSend = {
|
|
96
98
|
response: {
|
|
97
99
|
payload: result,
|
|
@@ -101,7 +103,7 @@ class ISocket {
|
|
|
101
103
|
};
|
|
102
104
|
return this.ws.send(JSON.stringify(toSend));
|
|
103
105
|
}
|
|
104
|
-
|
|
106
|
+
respondError(requestId, error) {
|
|
105
107
|
const toSend = {
|
|
106
108
|
response: {
|
|
107
109
|
payload: null,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superblocksteam/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Superblocks JS SDK",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"typescript": "^5.1.3"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@superblocksteam/util": "1.
|
|
34
|
+
"@superblocksteam/util": "1.8.0",
|
|
35
35
|
"axios": "^1.3.5",
|
|
36
36
|
"isomorphic-ws": "^5.0.0"
|
|
37
37
|
},
|
package/src/client.ts
CHANGED
|
@@ -61,12 +61,14 @@ export interface MultiPageApplicationWrapper {
|
|
|
61
61
|
export type PushApplicationWithCommitConfig = ApplicationWrapper & {
|
|
62
62
|
commitId: string;
|
|
63
63
|
commitMessage: string;
|
|
64
|
+
gitState: LocalGitRepoState;
|
|
64
65
|
};
|
|
65
66
|
|
|
66
67
|
export type PushMultiPageApplicationWithCommitConfig =
|
|
67
68
|
MultiPageApplicationWrapper & {
|
|
68
69
|
commitId: string;
|
|
69
70
|
commitMessage: string;
|
|
71
|
+
gitState: LocalGitRepoState;
|
|
70
72
|
};
|
|
71
73
|
|
|
72
74
|
export interface ApiWrapper {
|
|
@@ -78,6 +80,7 @@ export type PushApiWithCommitConfig = {
|
|
|
78
80
|
apiPb: Record<string, any>;
|
|
79
81
|
commitId: string;
|
|
80
82
|
commitMessage: string;
|
|
83
|
+
gitState: LocalGitRepoState;
|
|
81
84
|
};
|
|
82
85
|
|
|
83
86
|
export type Branches = {
|
|
@@ -114,7 +117,6 @@ export async function fetchApplication({
|
|
|
114
117
|
const baseServerUrl = fetchSinglePageApplication
|
|
115
118
|
? BASE_SERVER_PUBLIC_API_URL_V1
|
|
116
119
|
: BASE_SERVER_PUBLIC_API_URL_v2;
|
|
117
|
-
|
|
118
120
|
const serverURL = branch
|
|
119
121
|
? new URL(
|
|
120
122
|
`${baseServerUrl}/applications/${applicationId}/branches/${encodeURIComponent(
|
|
@@ -765,6 +767,7 @@ export async function pushApplication({
|
|
|
765
767
|
pages: (
|
|
766
768
|
applicationConfig as unknown as PushMultiPageApplicationWithCommitConfig
|
|
767
769
|
).pages,
|
|
770
|
+
gitState: applicationConfig.gitState,
|
|
768
771
|
})
|
|
769
772
|
: await socket.call.v1.public.application.pushCommit({
|
|
770
773
|
applicationId,
|
|
@@ -776,6 +779,7 @@ export async function pushApplication({
|
|
|
776
779
|
page: (
|
|
777
780
|
applicationConfig as unknown as PushApplicationWithCommitConfig
|
|
778
781
|
).page,
|
|
782
|
+
gitState: applicationConfig.gitState,
|
|
779
783
|
});
|
|
780
784
|
socket.close();
|
|
781
785
|
handleHttpError(resp.responseMeta.status);
|
|
@@ -897,6 +901,7 @@ export async function pushApi({
|
|
|
897
901
|
branchName: branch,
|
|
898
902
|
commitId: apiConfig.commitId,
|
|
899
903
|
commitMessage: apiConfig.commitMessage,
|
|
904
|
+
gitState: apiConfig.gitState,
|
|
900
905
|
});
|
|
901
906
|
socket.close();
|
|
902
907
|
handleHttpError(resp.responseMeta.status);
|
package/src/socket/handlers.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LocalGitRepoState } from "@superblocksteam/util";
|
|
1
2
|
import {
|
|
2
3
|
ApiToSign,
|
|
3
4
|
ApiToVerify,
|
|
@@ -97,6 +98,7 @@ export interface ServerMethods {
|
|
|
97
98
|
application: Record<string, unknown>;
|
|
98
99
|
page: Record<string, unknown>;
|
|
99
100
|
apis: Record<string, unknown>[];
|
|
101
|
+
gitState: LocalGitRepoState;
|
|
100
102
|
},
|
|
101
103
|
RemoteCommitDto
|
|
102
104
|
>;
|
|
@@ -109,6 +111,7 @@ export interface ServerMethods {
|
|
|
109
111
|
commitId: string;
|
|
110
112
|
commitMessage: string;
|
|
111
113
|
apiPb: Record<string, unknown>;
|
|
114
|
+
gitState: LocalGitRepoState;
|
|
112
115
|
},
|
|
113
116
|
RemoteCommitDto
|
|
114
117
|
>;
|
|
@@ -127,6 +130,7 @@ export interface ServerMethods {
|
|
|
127
130
|
application: Record<string, unknown>;
|
|
128
131
|
pages: Record<string, unknown>[];
|
|
129
132
|
apis: Record<string, unknown>[];
|
|
133
|
+
gitState: LocalGitRepoState;
|
|
130
134
|
},
|
|
131
135
|
RemoteCommitDto
|
|
132
136
|
>;
|
package/src/socket/socket.ts
CHANGED
|
@@ -57,87 +57,90 @@ export class ISocket<ImplementedMethods, CallableMethods, RequestContext> {
|
|
|
57
57
|
this.requestHandlers = requestHandlers;
|
|
58
58
|
this.nxtRequestId = 0;
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
// @ts-ignore
|
|
62
|
-
this.ws.addEventListener("message", async (event: MessageEvent) => {
|
|
60
|
+
this.ws.addEventListener("message", (event: WebSocket.MessageEvent) => {
|
|
63
61
|
const eventData: SocketMessage = JSON.parse(event.data.toString());
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
let handlers = this.requestHandlers;
|
|
68
|
-
for (const part of parts) {
|
|
69
|
-
// @ts-ignore
|
|
70
|
-
handlers = handlers[part];
|
|
71
|
-
if (!handlers) {
|
|
72
|
-
return await this.respondError(eventData.request.id, {
|
|
73
|
-
code: 2,
|
|
74
|
-
message: `unknown method ${eventData.request.method}`,
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
}
|
|
62
|
+
void this.handleEvent(eventData);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
78
65
|
|
|
79
|
-
|
|
80
|
-
|
|
66
|
+
private async handleEvent(eventData: SocketMessage<unknown, unknown>) {
|
|
67
|
+
if (eventData.request) {
|
|
68
|
+
// Split the method string into parts
|
|
69
|
+
const parts = eventData.request.method.split(".");
|
|
70
|
+
let handlers = this.requestHandlers;
|
|
71
|
+
for (const part of parts) {
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
73
|
+
// @ts-ignore
|
|
74
|
+
handlers = handlers[part];
|
|
75
|
+
if (!handlers) {
|
|
76
|
+
return this.respondError(eventData.request.id, {
|
|
81
77
|
code: 2,
|
|
82
|
-
message:
|
|
78
|
+
message: `unknown method ${eventData.request.method}`,
|
|
83
79
|
});
|
|
84
80
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
await this.respond(eventData.request.id, response);
|
|
120
|
-
} else if (eventData.response && eventData.response.id) {
|
|
121
|
-
if (!this.responseHandler[eventData.response.id]) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
if (eventData.response.error) {
|
|
125
|
-
this.responseHandler[eventData.response.id].reject(
|
|
126
|
-
eventData.response.error
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!Array.isArray(handlers)) {
|
|
84
|
+
return this.respondError(eventData.request.id, {
|
|
85
|
+
code: 2,
|
|
86
|
+
message: "unknown method",
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (eventData.request.setAuthorization) {
|
|
90
|
+
this.peerAuthorization = eventData.request.setAuthorization;
|
|
91
|
+
}
|
|
92
|
+
const middlewareHandlers = handlers.slice(0, -1) as MiddlewareHandler<
|
|
93
|
+
unknown,
|
|
94
|
+
CallableMethods,
|
|
95
|
+
RequestContext
|
|
96
|
+
>[];
|
|
97
|
+
const handler = handlers[handlers.length - 1] as MethodHandler<
|
|
98
|
+
unknown,
|
|
99
|
+
unknown,
|
|
100
|
+
CallableMethods,
|
|
101
|
+
RequestContext
|
|
102
|
+
>;
|
|
103
|
+
const reqCtx = {} as RequestContext;
|
|
104
|
+
let response: unknown;
|
|
105
|
+
// TODO(george): maybe we should not create a new client for each request
|
|
106
|
+
const client = createISocketClient(this);
|
|
107
|
+
try {
|
|
108
|
+
for (const middlewareHandler of middlewareHandlers) {
|
|
109
|
+
await middlewareHandler(
|
|
110
|
+
eventData.request.payload,
|
|
111
|
+
this.peerAuthorization,
|
|
112
|
+
client,
|
|
113
|
+
reqCtx
|
|
127
114
|
);
|
|
128
115
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
);
|
|
133
|
-
delete this.responseHandler[eventData.response.id];
|
|
134
|
-
} else {
|
|
135
|
-
return await this.respondError(-1, {
|
|
116
|
+
response = await handler(eventData.request.payload, client, reqCtx);
|
|
117
|
+
} catch (error: any) {
|
|
118
|
+
return this.respondError(eventData.request.id, {
|
|
136
119
|
code: 3,
|
|
137
|
-
message:
|
|
120
|
+
message: error.toString(),
|
|
138
121
|
});
|
|
139
122
|
}
|
|
140
|
-
|
|
123
|
+
this.respond(eventData.request.id, response);
|
|
124
|
+
} else if (eventData.response && eventData.response.id) {
|
|
125
|
+
if (!this.responseHandler[eventData.response.id]) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (eventData.response.error) {
|
|
129
|
+
this.responseHandler[eventData.response.id].reject(
|
|
130
|
+
eventData.response.error
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
134
|
+
this.responseHandler[eventData.response.id].resolve(
|
|
135
|
+
eventData.response.payload as any
|
|
136
|
+
);
|
|
137
|
+
delete this.responseHandler[eventData.response.id];
|
|
138
|
+
} else {
|
|
139
|
+
return this.respondError(-1, {
|
|
140
|
+
code: 3,
|
|
141
|
+
message: "unknown request id",
|
|
142
|
+
});
|
|
143
|
+
}
|
|
141
144
|
}
|
|
142
145
|
|
|
143
146
|
public request<Params, Result>(
|
|
@@ -163,10 +166,7 @@ export class ISocket<ImplementedMethods, CallableMethods, RequestContext> {
|
|
|
163
166
|
});
|
|
164
167
|
}
|
|
165
168
|
|
|
166
|
-
private
|
|
167
|
-
requestId: number,
|
|
168
|
-
result: Result
|
|
169
|
-
): Promise<void> {
|
|
169
|
+
private respond<Result>(requestId: number, result: Result): void {
|
|
170
170
|
const toSend: SocketMessage = {
|
|
171
171
|
response: {
|
|
172
172
|
payload: result,
|
|
@@ -177,10 +177,7 @@ export class ISocket<ImplementedMethods, CallableMethods, RequestContext> {
|
|
|
177
177
|
return this.ws.send(JSON.stringify(toSend));
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
private
|
|
181
|
-
requestId: number,
|
|
182
|
-
error: SocketError
|
|
183
|
-
): Promise<void> {
|
|
180
|
+
private respondError(requestId: number, error: SocketError): void {
|
|
184
181
|
const toSend: SocketMessage = {
|
|
185
182
|
response: {
|
|
186
183
|
payload: null,
|