@pathscale/wss-adapter 1.0.5 → 1.0.8
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 +1 -1
- package/dist/wssAdapter.js +25 -16
- package/package.json +1 -1
- package/types/index.ts +4 -1
- package/wssAdapter.ts +29 -29
package/dist/types/index.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ interface IWssAdapter {
|
|
|
38
38
|
[serviceName: string]: IServiceConnect;
|
|
39
39
|
};
|
|
40
40
|
sessions: {
|
|
41
|
-
[serviceName: string]:
|
|
41
|
+
[serviceName: string]: Record<string, <Response, Params = {}>(payload?: Params) => Promise<Response>>;
|
|
42
42
|
};
|
|
43
43
|
configure: (configuration: IConfiguration) => void;
|
|
44
44
|
}
|
package/dist/wssAdapter.js
CHANGED
|
@@ -82,6 +82,7 @@ var disconnectHandler = function (serviceName) {
|
|
|
82
82
|
};
|
|
83
83
|
var sendHandler = function (serviceName, serviceConfig, methodName, params) {
|
|
84
84
|
var _a;
|
|
85
|
+
if (params === void 0) { params = {}; }
|
|
85
86
|
var methodCode = (_a = Object.entries(serviceConfig.methods)
|
|
86
87
|
.map(function (_a) {
|
|
87
88
|
var code = _a[0], info = _a[1];
|
|
@@ -94,25 +95,33 @@ var sendHandler = function (serviceName, serviceConfig, methodName, params) {
|
|
|
94
95
|
if (!methodCode) {
|
|
95
96
|
throw new Error("method ".concat(methodName, " not available in ").concat(serviceName, " service"));
|
|
96
97
|
}
|
|
97
|
-
|
|
98
|
-
if (params) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
98
|
+
// const purgedParams: Record<string, unknown> = {}
|
|
99
|
+
// if (params) {
|
|
100
|
+
// if (
|
|
101
|
+
// !Object.keys(params).every((param) =>
|
|
102
|
+
// serviceConfig.methods[methodCode].parameters.includes(param)
|
|
103
|
+
// )
|
|
104
|
+
// ) {
|
|
105
|
+
// throw new Error(
|
|
106
|
+
// `method ${methodCode} is being called with missing parameters`
|
|
107
|
+
// )
|
|
108
|
+
// }
|
|
109
|
+
// serviceConfig.methods[methodCode].parameters.forEach((k) => {
|
|
110
|
+
// purgedParams[k] = params[k]
|
|
111
|
+
// })
|
|
112
|
+
// const difference = Object.keys(params).filter(
|
|
113
|
+
// (x) => !serviceConfig.methods[methodCode].parameters.includes(x)
|
|
114
|
+
// )
|
|
115
|
+
// if (difference.length) {
|
|
116
|
+
// throw new Error(
|
|
117
|
+
// `method ${methodCode} is being called with unknow parameters, ${difference}`
|
|
118
|
+
// )
|
|
119
|
+
// }
|
|
120
|
+
// }
|
|
112
121
|
var payload = {
|
|
113
122
|
method: Number.parseInt(methodCode),
|
|
114
123
|
seq: store.sequence.getSeq(),
|
|
115
|
-
params:
|
|
124
|
+
params: params,
|
|
116
125
|
};
|
|
117
126
|
console.log("".concat(serviceName, "::").concat(methodName, " sends:"), payload);
|
|
118
127
|
return new Promise(function (resolve, reject) {
|
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
|
@@ -111,7 +111,7 @@ const sendHandler = (
|
|
|
111
111
|
serviceName: string,
|
|
112
112
|
serviceConfig: IServiceConfig,
|
|
113
113
|
methodName: string,
|
|
114
|
-
params: Record<string, unknown>
|
|
114
|
+
params: Record<string, unknown> = {}
|
|
115
115
|
) => {
|
|
116
116
|
const methodCode = Object.entries(serviceConfig.methods)
|
|
117
117
|
.map(([code, info]) => ({ code, info }))
|
|
@@ -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)
|