js-rpc2 1.0.6 → 1.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-rpc2",
3
- "version": "1.0.6",
3
+ "version": "1.1.0",
4
4
  "description": "js web websocket http rpc",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/src/lib.js CHANGED
@@ -744,6 +744,14 @@ export function createRpcClientHelper(param) {
744
744
  argArray.push(fnName)
745
745
  for (const arg of args) {
746
746
  if (arg instanceof Function) {
747
+ const isAsyncFunction = arg.constructor?.name === 'AsyncFunction'
748
+ if (!isAsyncFunction) {
749
+ const receivedType = arg.constructor?.name || 'regular function'
750
+ throw new Error(
751
+ `Expected an AsyncFunction as the callback, but received a ${receivedType}. ` +
752
+ 'Ensure the callback is declared with "async function" or an arrow function using "async".'
753
+ )
754
+ }
747
755
  const key = uniqueKeyID++
748
756
  keys.push(key)
749
757
  callbackFunctionMap.set(key, { id: key, type: RPC_TYPE_CALLBACK, callback: arg })
package/src/server.js CHANGED
@@ -17,6 +17,7 @@ export { createRpcServerHelper }
17
17
  * wss: WebSocketServer;
18
18
  * rpcKey:string;
19
19
  * extension: Object;
20
+ * logger?:(msg:string)=>void;
20
21
  * }} param
21
22
  */
22
23
  export function createRpcServerWebSocket(param) {
@@ -25,7 +26,7 @@ export function createRpcServerWebSocket(param) {
25
26
  if (url != param.path) {
26
27
  return
27
28
  }
28
- let helper = createRpcServerHelper({ rpcKey: param.rpcKey, extension: param.extension, async: true, })
29
+ let helper = createRpcServerHelper({ rpcKey: param.rpcKey, extension: param.extension, async: true, logger: param.logger })
29
30
  let writer = helper.writable.getWriter()
30
31
  helper.readable.pipeTo(new WritableStream({
31
32
  async write(chunk) {