complete
This commit is contained in:
+10
-14
@@ -25,7 +25,6 @@ function createBirpc($functions, options) {
|
||||
let $closed = false;
|
||||
const _rpcPromiseMap = /* @__PURE__ */ new Map();
|
||||
let _promiseInit;
|
||||
let rpc;
|
||||
async function _call(method, args, event, optional) {
|
||||
if ($closed)
|
||||
throw new Error(`[birpc] rpc is closed, cannot call "${method}"`);
|
||||
@@ -52,7 +51,7 @@ function createBirpc($functions, options) {
|
||||
if (timeout >= 0) {
|
||||
timeoutId = setTimeout(() => {
|
||||
try {
|
||||
const handleResult = options.onTimeoutError?.call(rpc, method, args);
|
||||
const handleResult = options.onTimeoutError?.(method, args);
|
||||
if (handleResult !== true)
|
||||
throw new Error(`[birpc] timeout on calling "${method}"`);
|
||||
} catch (e) {
|
||||
@@ -69,11 +68,11 @@ function createBirpc($functions, options) {
|
||||
}
|
||||
try {
|
||||
if (options.onRequest)
|
||||
await options.onRequest.call(rpc, req, handler, resolve);
|
||||
await options.onRequest(req, handler, resolve);
|
||||
else
|
||||
await handler();
|
||||
} catch (e) {
|
||||
if (options.onGeneralError?.call(rpc, e) !== true)
|
||||
if (options.onGeneralError?.(e) !== true)
|
||||
throw e;
|
||||
return;
|
||||
} finally {
|
||||
@@ -95,13 +94,10 @@ function createBirpc($functions, options) {
|
||||
get $closed() {
|
||||
return $closed;
|
||||
},
|
||||
get $meta() {
|
||||
return options.meta;
|
||||
},
|
||||
$close,
|
||||
$functions
|
||||
};
|
||||
rpc = new Proxy({}, {
|
||||
const rpc = new Proxy({}, {
|
||||
get(_, method) {
|
||||
if (Object.prototype.hasOwnProperty.call(builtinMethods, method))
|
||||
return builtinMethods[method];
|
||||
@@ -146,14 +142,14 @@ function createBirpc($functions, options) {
|
||||
try {
|
||||
msg = deserialize(data);
|
||||
} catch (e) {
|
||||
if (options.onGeneralError?.call(rpc, e) !== true)
|
||||
if (options.onGeneralError?.(e) !== true)
|
||||
throw e;
|
||||
return;
|
||||
}
|
||||
if (msg.t === TYPE_REQUEST) {
|
||||
const { m: method, a: args, o: optional } = msg;
|
||||
let result, error;
|
||||
let fn = await (resolver ? resolver.call(rpc, method, $functions[method]) : $functions[method]);
|
||||
let fn = await (resolver ? resolver(method, $functions[method]) : $functions[method]);
|
||||
if (optional)
|
||||
fn ||= () => void 0;
|
||||
if (!fn) {
|
||||
@@ -167,9 +163,9 @@ function createBirpc($functions, options) {
|
||||
}
|
||||
if (msg.i) {
|
||||
if (error && options.onError)
|
||||
options.onError.call(rpc, error, method, args);
|
||||
options.onError(error, method, args);
|
||||
if (error && options.onFunctionError) {
|
||||
if (options.onFunctionError.call(rpc, error, method, args) === true)
|
||||
if (options.onFunctionError(error, method, args) === true)
|
||||
return;
|
||||
}
|
||||
if (!error) {
|
||||
@@ -178,14 +174,14 @@ function createBirpc($functions, options) {
|
||||
return;
|
||||
} catch (e) {
|
||||
error = e;
|
||||
if (options.onGeneralError?.call(rpc, e, method, args) !== true)
|
||||
if (options.onGeneralError?.(e, method, args) !== true)
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
try {
|
||||
await post(serialize({ t: TYPE_RESPONSE, i: msg.i, e: error }), ...extra);
|
||||
} catch (e) {
|
||||
if (options.onGeneralError?.call(rpc, e, method, args) !== true)
|
||||
if (options.onGeneralError?.(e, method, args) !== true)
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
+11
-11
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "birpc",
|
||||
"type": "module",
|
||||
"version": "2.9.0",
|
||||
"version": "2.8.0",
|
||||
"description": "Message based Two-way remote procedure call",
|
||||
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
||||
"license": "MIT",
|
||||
@@ -33,17 +33,17 @@
|
||||
"dist"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@antfu/eslint-config": "^6.3.0",
|
||||
"@antfu/ni": "^28.0.0",
|
||||
"@types/node": "^24.10.1",
|
||||
"@antfu/eslint-config": "^4.11.0",
|
||||
"@antfu/ni": "^24.3.0",
|
||||
"@types/node": "^22.13.13",
|
||||
"@vitest/coverage-v8": "3.0.9",
|
||||
"bumpp": "^10.3.2",
|
||||
"eslint": "^9.39.1",
|
||||
"tsx": "^4.21.0",
|
||||
"typescript": "^5.9.3",
|
||||
"unbuild": "^3.6.1",
|
||||
"vite": "^7.2.6",
|
||||
"vitest": "^4.0.15"
|
||||
"bumpp": "^10.1.0",
|
||||
"eslint": "^9.23.0",
|
||||
"tsx": "^4.19.3",
|
||||
"typescript": "^5.8.2",
|
||||
"unbuild": "^3.5.0",
|
||||
"vite": "^6.2.3",
|
||||
"vitest": "^3.0.9"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
|
||||
Reference in New Issue
Block a user