weifuwu 0.16.1 → 0.16.2
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/iii/ws.d.ts +1 -0
- package/dist/index.js +21 -0
- package/dist/server.d.ts +1 -0
- package/package.json +1 -1
package/dist/iii/ws.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ interface WsHandlerDeps {
|
|
|
18
18
|
removeStreamSubscriber: (ws: WebSocket) => void;
|
|
19
19
|
handleInvokeResult: (invocationId: string, result: unknown) => void;
|
|
20
20
|
handleInvokeError: (invocationId: string, error: string) => void;
|
|
21
|
+
handleInvoke: (ws: WebSocket, invocationId: string, functionId: string, payload: unknown) => void;
|
|
21
22
|
}
|
|
22
23
|
export declare function createWsHandler(deps: WsHandlerDeps): {
|
|
23
24
|
open(_ws: WebSocket, _ctx: Context): void;
|
package/dist/index.js
CHANGED
|
@@ -7428,6 +7428,10 @@ function createWsHandler(deps) {
|
|
|
7428
7428
|
if (workerId) deps.unregisterRemoteTrigger(workerId, msg.function_id);
|
|
7429
7429
|
break;
|
|
7430
7430
|
}
|
|
7431
|
+
case "invoke": {
|
|
7432
|
+
deps.handleInvoke(ws, msg.invocation_id, msg.function_id, msg.payload);
|
|
7433
|
+
break;
|
|
7434
|
+
}
|
|
7431
7435
|
case "invoke_result": {
|
|
7432
7436
|
deps.handleInvokeResult(msg.invocation_id, msg.result);
|
|
7433
7437
|
break;
|
|
@@ -7667,6 +7671,23 @@ function iii(opts = {}) {
|
|
|
7667
7671
|
p.reject(new Error(error));
|
|
7668
7672
|
pending.delete(invocationId);
|
|
7669
7673
|
}
|
|
7674
|
+
},
|
|
7675
|
+
handleInvoke(ws, invocationId, functionId, payload) {
|
|
7676
|
+
const fn = functions.get(functionId);
|
|
7677
|
+
if (!fn) {
|
|
7678
|
+
ws.send(JSON.stringify({
|
|
7679
|
+
type: "invoke_error",
|
|
7680
|
+
invocation_id: invocationId,
|
|
7681
|
+
error: `Function "${functionId}" not found`
|
|
7682
|
+
}));
|
|
7683
|
+
return;
|
|
7684
|
+
}
|
|
7685
|
+
const ctx = { engine: module, functionId, workerName: fn.workerName };
|
|
7686
|
+
Promise.resolve(fn.handler(payload, ctx)).then((result) => {
|
|
7687
|
+
ws.send(JSON.stringify({ type: "invoke_result", invocation_id: invocationId, result }));
|
|
7688
|
+
}).catch((err) => {
|
|
7689
|
+
ws.send(JSON.stringify({ type: "invoke_error", invocation_id: invocationId, error: err.message }));
|
|
7690
|
+
});
|
|
7670
7691
|
}
|
|
7671
7692
|
});
|
|
7672
7693
|
function doTrigger(request) {
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|