js-rpc2 1.0.4 → 1.0.5
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/package.json +2 -2
- package/src/lib.js +7 -5
- package/src/server.js +6 -2
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "js-rpc2",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.5",
|
4
4
|
"description": "js web websocket http rpc",
|
5
5
|
"main": "index.js",
|
6
6
|
"type": "module",
|
@@ -26,7 +26,7 @@
|
|
26
26
|
"author": "yuanliwei",
|
27
27
|
"license": "MIT",
|
28
28
|
"devDependencies": {
|
29
|
-
"@types/node": "^22.
|
29
|
+
"@types/node": "^22.13.14",
|
30
30
|
"koa": "^2.15.3",
|
31
31
|
"koa-router": "^13.0.1",
|
32
32
|
"ws": "^8.18.0"
|
package/src/lib.js
CHANGED
@@ -88,11 +88,11 @@ export async function buildBufferData(queue, key, iv) {
|
|
88
88
|
/**
|
89
89
|
* @param {Uint8Array<ArrayBuffer>} buffer
|
90
90
|
* @param {CryptoKey} key
|
91
|
-
* @param {Uint8Array} iv
|
92
|
-
* @returns {Promise<[Uint8Array[],Uint8Array<ArrayBuffer>]>}
|
91
|
+
* @param {Uint8Array<ArrayBuffer>} iv
|
92
|
+
* @returns {Promise<[Uint8Array<ArrayBuffer>[],Uint8Array<ArrayBuffer>]>}
|
93
93
|
*/
|
94
94
|
export async function parseBufferData(buffer, key, iv) {
|
95
|
-
/** @type{Uint8Array[]} */
|
95
|
+
/** @type{Uint8Array<ArrayBuffer>[]} */
|
96
96
|
let queue = []
|
97
97
|
let offset = 0
|
98
98
|
let remain = new Uint8Array(0)
|
@@ -310,7 +310,7 @@ export async function encrypt(data, key, iv) {
|
|
310
310
|
}
|
311
311
|
|
312
312
|
/**
|
313
|
-
* @param {Uint8Array} data
|
313
|
+
* @param {Uint8Array<ArrayBuffer>} data
|
314
314
|
* @param {CryptoKey} key
|
315
315
|
* @param {Uint8Array} iv
|
316
316
|
* @returns
|
@@ -632,7 +632,9 @@ export function createRpcServerHelper(param) {
|
|
632
632
|
async close() {
|
633
633
|
await writer.close()
|
634
634
|
}
|
635
|
-
}))
|
635
|
+
})).catch(e => {
|
636
|
+
console.error(e)
|
637
|
+
})
|
636
638
|
|
637
639
|
/** @type{RPC_HELPER_SERVER} */
|
638
640
|
let ret = { writable: decode.writable, readable: encode.readable }
|
package/src/server.js
CHANGED
@@ -64,13 +64,17 @@ export function createRpcServerWebSocket(param) {
|
|
64
64
|
export function createRpcServerKoaRouter(param) {
|
65
65
|
param.router.post(param.path, async (ctx) => {
|
66
66
|
let helper = createRpcServerHelper({ rpcKey: param.rpcKey, extension: param.extension })
|
67
|
-
|
67
|
+
/** @type{ReadableStream} */
|
68
|
+
let a = Readable.toWeb(ctx.req)
|
69
|
+
await a.pipeTo(helper.writable)
|
68
70
|
ctx.status = 200
|
69
71
|
ctx.response.set({
|
70
72
|
'Connection': 'keep-alive',
|
71
73
|
'Cache-Control': 'no-cache',
|
72
74
|
'Content-Type': 'application/octet-stream'
|
73
75
|
})
|
74
|
-
|
76
|
+
/** @type{object} */
|
77
|
+
let b = helper.readable
|
78
|
+
ctx.body = Readable.fromWeb(b)
|
75
79
|
})
|
76
80
|
}
|