@pathscale/wss-adapter 1.0.4 → 1.0.7
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/types/index.d.ts +50 -55
- package/dist/wssAdapter.js +25 -17
- package/package.json +1 -1
- package/types/index.ts +4 -1
- package/wssAdapter.ts +29 -29
package/dist/types/index.d.ts
CHANGED
|
@@ -1,77 +1,72 @@
|
|
|
1
1
|
interface IService {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
remote: string;
|
|
3
|
+
methods: {
|
|
4
|
+
[methodCode: string]: {
|
|
5
|
+
name: string;
|
|
6
|
+
parameters: string[];
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
9
|
}
|
|
10
10
|
interface IServiceConfig extends IService {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
onDisconnect: (event: {
|
|
12
|
+
code: number;
|
|
13
|
+
reason: string;
|
|
14
|
+
wasClean: boolean;
|
|
15
|
+
}) => void | null;
|
|
16
16
|
}
|
|
17
17
|
interface IServices {
|
|
18
|
-
|
|
18
|
+
[serviceName: string]: IServiceConfig;
|
|
19
19
|
}
|
|
20
20
|
interface IErrors {
|
|
21
|
-
|
|
21
|
+
[errorCode: number]: string;
|
|
22
22
|
}
|
|
23
23
|
interface IConfiguration {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
timeout: number;
|
|
25
|
+
services: IServices;
|
|
26
|
+
errors: IErrors;
|
|
27
|
+
onError: (error: {
|
|
28
|
+
error: number;
|
|
29
|
+
message: string;
|
|
30
|
+
}) => void;
|
|
28
31
|
}
|
|
29
32
|
interface IServiceConnect {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
remote?: string
|
|
33
|
-
): Promise<T>
|
|
34
|
-
disconnect: () => void
|
|
33
|
+
connect<T>(payload: string | string[] | undefined, remote?: string): Promise<T>;
|
|
34
|
+
disconnect: () => void;
|
|
35
35
|
}
|
|
36
36
|
interface IWssAdapter {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
services: {
|
|
38
|
+
[serviceName: string]: IServiceConnect;
|
|
39
|
+
};
|
|
40
|
+
sessions: {
|
|
41
|
+
[serviceName: string]: Record<string, <Response, Params = {}>(payload?: Params) => Promise<Response>>;
|
|
42
|
+
};
|
|
43
|
+
configure: (configuration: IConfiguration) => void;
|
|
44
44
|
}
|
|
45
45
|
interface ISequence {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
value: number;
|
|
47
|
+
getSeq: () => number;
|
|
48
|
+
decreaseSeq: () => void;
|
|
49
49
|
}
|
|
50
50
|
interface ISessions {
|
|
51
|
-
|
|
51
|
+
[serviceName: string]: WebSocket;
|
|
52
52
|
}
|
|
53
53
|
interface IPendingPromises {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
[seq: number]: {
|
|
55
|
+
resolve: (payload: unknown) => void;
|
|
56
|
+
reject: (error: Error) => void;
|
|
57
|
+
toHandler: ReturnType<typeof setTimeout>;
|
|
58
|
+
};
|
|
59
59
|
}
|
|
60
60
|
interface IStore {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
IWssAdapter,
|
|
72
|
-
IServiceConfig,
|
|
73
|
-
IConfiguration,
|
|
74
|
-
IErrors,
|
|
75
|
-
IServices,
|
|
76
|
-
IService,
|
|
61
|
+
timeout: number;
|
|
62
|
+
errors: IErrors;
|
|
63
|
+
services: IServices;
|
|
64
|
+
sequence: ISequence;
|
|
65
|
+
sessions: ISessions;
|
|
66
|
+
pendingPromises: IPendingPromises;
|
|
67
|
+
onError: (error: {
|
|
68
|
+
error: number;
|
|
69
|
+
message: string;
|
|
70
|
+
}) => void;
|
|
77
71
|
}
|
|
72
|
+
export { IStore, IWssAdapter, IServiceConfig, IConfiguration, IErrors, IServices, IService, };
|
package/dist/wssAdapter.js
CHANGED
|
@@ -94,25 +94,33 @@ var sendHandler = function (serviceName, serviceConfig, methodName, params) {
|
|
|
94
94
|
if (!methodCode) {
|
|
95
95
|
throw new Error("method ".concat(methodName, " not available in ").concat(serviceName, " service"));
|
|
96
96
|
}
|
|
97
|
-
|
|
98
|
-
if (params) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
97
|
+
// const purgedParams: Record<string, unknown> = {}
|
|
98
|
+
// if (params) {
|
|
99
|
+
// if (
|
|
100
|
+
// !Object.keys(params).every((param) =>
|
|
101
|
+
// serviceConfig.methods[methodCode].parameters.includes(param)
|
|
102
|
+
// )
|
|
103
|
+
// ) {
|
|
104
|
+
// throw new Error(
|
|
105
|
+
// `method ${methodCode} is being called with missing parameters`
|
|
106
|
+
// )
|
|
107
|
+
// }
|
|
108
|
+
// serviceConfig.methods[methodCode].parameters.forEach((k) => {
|
|
109
|
+
// purgedParams[k] = params[k]
|
|
110
|
+
// })
|
|
111
|
+
// const difference = Object.keys(params).filter(
|
|
112
|
+
// (x) => !serviceConfig.methods[methodCode].parameters.includes(x)
|
|
113
|
+
// )
|
|
114
|
+
// if (difference.length) {
|
|
115
|
+
// throw new Error(
|
|
116
|
+
// `method ${methodCode} is being called with unknow parameters, ${difference}`
|
|
117
|
+
// )
|
|
118
|
+
// }
|
|
119
|
+
// }
|
|
112
120
|
var payload = {
|
|
113
121
|
method: Number.parseInt(methodCode),
|
|
114
122
|
seq: store.sequence.getSeq(),
|
|
115
|
-
params:
|
|
123
|
+
params: params,
|
|
116
124
|
};
|
|
117
125
|
console.log("".concat(serviceName, "::").concat(methodName, " sends:"), payload);
|
|
118
126
|
return new Promise(function (resolve, reject) {
|
|
@@ -151,7 +159,7 @@ var receiveHandler = function (event) {
|
|
|
151
159
|
function onError(response) {
|
|
152
160
|
var _a, _b;
|
|
153
161
|
var errorCode = response.params.error;
|
|
154
|
-
var errorMsg = (_a = store.errors[errorCode]) !== null && _a !== void 0 ? _a :
|
|
162
|
+
var errorMsg = (_a = store.errors[errorCode]) !== null && _a !== void 0 ? _a : errorCode;
|
|
155
163
|
if ([45349638, 45349637].includes(errorCode)) {
|
|
156
164
|
store.sequence.decreaseSeq();
|
|
157
165
|
console.log('seq has been decreased because of error');
|
package/package.json
CHANGED
package/types/index.ts
CHANGED
|
@@ -38,7 +38,10 @@ interface IWssAdapter {
|
|
|
38
38
|
[serviceName: string]: IServiceConnect
|
|
39
39
|
}
|
|
40
40
|
sessions: {
|
|
41
|
-
[serviceName: string]:
|
|
41
|
+
[serviceName: string]: Record<
|
|
42
|
+
string,
|
|
43
|
+
<Response, Params = {}>(payload?: Params) => Promise<Response>
|
|
44
|
+
>
|
|
42
45
|
}
|
|
43
46
|
configure: (configuration: IConfiguration) => void
|
|
44
47
|
}
|
package/wssAdapter.ts
CHANGED
|
@@ -123,38 +123,38 @@ const sendHandler = (
|
|
|
123
123
|
)
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
const purgedParams: Record<string, unknown> = {}
|
|
127
|
-
|
|
128
|
-
if (params) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
126
|
+
// const purgedParams: Record<string, unknown> = {}
|
|
127
|
+
|
|
128
|
+
// if (params) {
|
|
129
|
+
// if (
|
|
130
|
+
// !Object.keys(params).every((param) =>
|
|
131
|
+
// serviceConfig.methods[methodCode].parameters.includes(param)
|
|
132
|
+
// )
|
|
133
|
+
// ) {
|
|
134
|
+
// throw new Error(
|
|
135
|
+
// `method ${methodCode} is being called with missing parameters`
|
|
136
|
+
// )
|
|
137
|
+
// }
|
|
138
|
+
|
|
139
|
+
// serviceConfig.methods[methodCode].parameters.forEach((k) => {
|
|
140
|
+
// purgedParams[k] = params[k]
|
|
141
|
+
// })
|
|
142
|
+
|
|
143
|
+
// const difference = Object.keys(params).filter(
|
|
144
|
+
// (x) => !serviceConfig.methods[methodCode].parameters.includes(x)
|
|
145
|
+
// )
|
|
146
|
+
|
|
147
|
+
// if (difference.length) {
|
|
148
|
+
// throw new Error(
|
|
149
|
+
// `method ${methodCode} is being called with unknow parameters, ${difference}`
|
|
150
|
+
// )
|
|
151
|
+
// }
|
|
152
|
+
// }
|
|
153
153
|
|
|
154
154
|
const payload = {
|
|
155
155
|
method: Number.parseInt(methodCode),
|
|
156
156
|
seq: store.sequence.getSeq(),
|
|
157
|
-
params:
|
|
157
|
+
params: params,
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
console.log(`${serviceName}::${methodName} sends:`, payload)
|
|
@@ -210,7 +210,7 @@ interface IResponse {
|
|
|
210
210
|
|
|
211
211
|
function onError(response: IResponse) {
|
|
212
212
|
const { error: errorCode } = response.params
|
|
213
|
-
const errorMsg = store.errors[errorCode] ??
|
|
213
|
+
const errorMsg = store.errors[errorCode] ?? errorCode
|
|
214
214
|
|
|
215
215
|
if ([45349638, 45349637].includes(errorCode)) {
|
|
216
216
|
store.sequence.decreaseSeq()
|