@xentobias/worker-rpc 1.0.8 → 1.0.11
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/broadcast.d.ts +106 -0
- package/dist/endpoint.d.ts +70 -14
- package/dist/id.d.ts +19 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -583
- package/dist/proxy.d.ts +3 -5
- package/dist/types.d.ts +36 -7
- package/package.json +2 -2
- package/dist/endpoint.d.ts.map +0 -1
- package/dist/id.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/proxy.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { type ResultMessage, type ErrorMessage, type MethodPath, type BroadcastMessageTarget, type BroadcastResult } from './types';
|
|
2
|
+
import { Endpoint, type EndpointOptions } from './endpoint';
|
|
3
|
+
/**
|
|
4
|
+
* Broadcast Endpoint - handles 1-to-many RPC communication
|
|
5
|
+
*
|
|
6
|
+
* Unlike the regular Endpoint which expects a single response per call,
|
|
7
|
+
* BroadcastEndpoint collects multiple responses from all subscribers and
|
|
8
|
+
* returns both successful results and errors.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const endpoint = createBroadcastEndpoint({
|
|
13
|
+
* async postMessage(message) {
|
|
14
|
+
* return await pubsub.publish('channel', message);
|
|
15
|
+
* },
|
|
16
|
+
* addEventListener(type, listener) {
|
|
17
|
+
* pubsub.subscribe('channel', (msg) => listener({ data: msg }));
|
|
18
|
+
* }
|
|
19
|
+
* }, { id: 'my-endpoint' });
|
|
20
|
+
*
|
|
21
|
+
* const { results, errors } = await endpoint.call(['ping'], []);
|
|
22
|
+
* console.log(`${results.length} succeeded, ${errors.length} failed`);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare class BroadcastEndpoint extends Endpoint {
|
|
26
|
+
/** Pending broadcast calls awaiting multiple responses */
|
|
27
|
+
private pendingBroadcastCalls;
|
|
28
|
+
/**
|
|
29
|
+
* Get the broadcast target with proper typing
|
|
30
|
+
*/
|
|
31
|
+
private get broadcastTarget();
|
|
32
|
+
/**
|
|
33
|
+
* Call a remote method and collect responses from all subscribers.
|
|
34
|
+
* @returns Promise that resolves with a BroadcastResult containing results and errors
|
|
35
|
+
*/
|
|
36
|
+
call(path: MethodPath, args: unknown[]): Promise<BroadcastResult>;
|
|
37
|
+
/**
|
|
38
|
+
* Send a broadcast message and set up multi-response handling
|
|
39
|
+
*/
|
|
40
|
+
private sendBroadcast;
|
|
41
|
+
/**
|
|
42
|
+
* Handle timeout for a broadcast call
|
|
43
|
+
*/
|
|
44
|
+
private handleTimeout;
|
|
45
|
+
/**
|
|
46
|
+
* Handle the subscriber count after postMessage resolves
|
|
47
|
+
*/
|
|
48
|
+
private handleSubscriberCount;
|
|
49
|
+
/**
|
|
50
|
+
* Check if all responses have been received and complete if so
|
|
51
|
+
*/
|
|
52
|
+
private checkCompletion;
|
|
53
|
+
/**
|
|
54
|
+
* Complete a broadcast call - cleanup and resolve with results and errors
|
|
55
|
+
*/
|
|
56
|
+
private completeBroadcast;
|
|
57
|
+
/**
|
|
58
|
+
* Handle a successful result - overrides base to support multi-response
|
|
59
|
+
*/
|
|
60
|
+
protected handleResult(message: ResultMessage): void;
|
|
61
|
+
/**
|
|
62
|
+
* Handle an error result - overrides base to support multi-response
|
|
63
|
+
*/
|
|
64
|
+
protected handleError(message: ErrorMessage): void;
|
|
65
|
+
/**
|
|
66
|
+
* Get the number of pending calls (including broadcast calls)
|
|
67
|
+
*/
|
|
68
|
+
getPendingCallCount(): number;
|
|
69
|
+
/**
|
|
70
|
+
* Check if there are any pending calls (including broadcast calls)
|
|
71
|
+
*/
|
|
72
|
+
hasPendingCalls(): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Release this endpoint and clean up resources
|
|
75
|
+
*/
|
|
76
|
+
release(options?: {
|
|
77
|
+
silent?: boolean;
|
|
78
|
+
}): void;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Create a broadcast endpoint for 1-to-many RPC communication
|
|
82
|
+
*
|
|
83
|
+
* @param target - A BroadcastMessageTarget where postMessage returns subscriber count
|
|
84
|
+
* @param options - Optional configuration
|
|
85
|
+
* @returns A BroadcastEndpoint instance
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const endpoint = createBroadcastEndpoint({
|
|
90
|
+
* async postMessage(message) {
|
|
91
|
+
* return await redis.publish('rpc-channel', JSON.stringify(message));
|
|
92
|
+
* },
|
|
93
|
+
* addEventListener(type, listener) {
|
|
94
|
+
* redis.subscribe('rpc-channel', (msg) => {
|
|
95
|
+
* listener({ data: JSON.parse(msg) });
|
|
96
|
+
* });
|
|
97
|
+
* }
|
|
98
|
+
* });
|
|
99
|
+
*
|
|
100
|
+
* const { results, errors } = await wrap(endpoint).ping();
|
|
101
|
+
* if (errors.length > 0) {
|
|
102
|
+
* console.warn(`${errors.length} subscribers failed`);
|
|
103
|
+
* }
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export declare function createBroadcastEndpoint(target: BroadcastMessageTarget, options?: EndpointOptions): BroadcastEndpoint;
|
package/dist/endpoint.d.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
import { type MethodPath, type MessageTarget } from './types';
|
|
1
|
+
import { type RpcMessage, type CallMessage, type ResultMessage, type ErrorMessage, type MethodPath, type PendingCall, type CallbackRegistration, type MessageTarget, type TransferableValue } from './types';
|
|
2
|
+
/** Unique identifier for tracking RPC calls */
|
|
3
|
+
export type CallId = `c:${string}`;
|
|
4
|
+
/** Unique identifier for callback functions */
|
|
5
|
+
export type CallbackId = `cb:${string}`;
|
|
2
6
|
/** Configuration options for the RPC endpoint */
|
|
3
7
|
export interface EndpointOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Unique identifier for this endpoint.
|
|
10
|
+
* Used in call IDs to identify the caller for response routing.
|
|
11
|
+
* If not provided, a random ID will be generated.
|
|
12
|
+
*/
|
|
13
|
+
id?: string;
|
|
4
14
|
/** Timeout for RPC calls in milliseconds (default: 30000) */
|
|
5
15
|
timeout?: number;
|
|
6
16
|
/** Enable debug logging */
|
|
@@ -31,21 +41,56 @@ export interface ShutdownResult {
|
|
|
31
41
|
* RPC Endpoint - handles bidirectional communication with a worker
|
|
32
42
|
*/
|
|
33
43
|
export declare class Endpoint {
|
|
34
|
-
|
|
35
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Generate a random ID string for use as a default endpoint ID.
|
|
46
|
+
* @returns A random 6-character alphanumeric string
|
|
47
|
+
*/
|
|
48
|
+
private static generateRandomId;
|
|
49
|
+
/**
|
|
50
|
+
* Extract the endpoint ID from a call ID.
|
|
51
|
+
* Call IDs have the format: "c:<endpointId>:<counter>"
|
|
52
|
+
*
|
|
53
|
+
* Useful for routing responses back to the caller in broadcast scenarios.
|
|
54
|
+
*
|
|
55
|
+
* @param callId - The call ID to extract from
|
|
56
|
+
* @returns The endpoint ID portion of the call ID
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* Endpoint.extractEndpointId('c:runner3:1') // returns 'runner3'
|
|
61
|
+
* Endpoint.extractEndpointId('c:abc123:42') // returns 'abc123'
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
static extractEndpointId(callId: CallId): string;
|
|
65
|
+
protected target: MessageTarget;
|
|
66
|
+
protected options: Required<EndpointOptions>;
|
|
36
67
|
private exposedApi;
|
|
37
68
|
private exposeOptions;
|
|
69
|
+
/** Unique identifier for this endpoint */
|
|
70
|
+
readonly id: string;
|
|
71
|
+
/** Counter for generating unique call IDs */
|
|
72
|
+
private callCounter;
|
|
73
|
+
/** Counter for generating unique callback IDs */
|
|
74
|
+
private callbackCounter;
|
|
38
75
|
/** Pending calls awaiting response */
|
|
39
|
-
|
|
76
|
+
protected pendingCalls: Map<`c:${string}`, PendingCall>;
|
|
40
77
|
/** Registered callbacks (functions passed as arguments) */
|
|
41
|
-
|
|
78
|
+
protected callbacks: Map<`cb:${string}`, CallbackRegistration>;
|
|
42
79
|
/** Remote callbacks (proxies for functions on the other side) */
|
|
43
|
-
|
|
80
|
+
protected remoteCallbacks: Map<`cb:${string}`, Function>;
|
|
44
81
|
/** Message handler bound to this instance */
|
|
45
82
|
private boundMessageHandler;
|
|
46
83
|
/** Whether this endpoint has been released */
|
|
47
|
-
|
|
84
|
+
protected released: boolean;
|
|
48
85
|
constructor(target: MessageTarget, options?: EndpointOptions);
|
|
86
|
+
/**
|
|
87
|
+
* Generate a unique call ID for this endpoint
|
|
88
|
+
*/
|
|
89
|
+
protected generateCallId(): CallId;
|
|
90
|
+
/**
|
|
91
|
+
* Generate a unique callback ID for this endpoint
|
|
92
|
+
*/
|
|
93
|
+
protected generateCallbackId(): CallbackId;
|
|
49
94
|
/**
|
|
50
95
|
* Attach the message listener to the target
|
|
51
96
|
*/
|
|
@@ -57,7 +102,7 @@ export declare class Endpoint {
|
|
|
57
102
|
/**
|
|
58
103
|
* Log a debug message
|
|
59
104
|
*/
|
|
60
|
-
|
|
105
|
+
protected debug(...args: unknown[]): void;
|
|
61
106
|
/**
|
|
62
107
|
* Expose an API object for remote invocation
|
|
63
108
|
*/
|
|
@@ -77,11 +122,11 @@ export declare class Endpoint {
|
|
|
77
122
|
/**
|
|
78
123
|
* Handle a successful result
|
|
79
124
|
*/
|
|
80
|
-
|
|
125
|
+
protected handleResult(message: ResultMessage): void;
|
|
81
126
|
/**
|
|
82
127
|
* Handle an error result
|
|
83
128
|
*/
|
|
84
|
-
|
|
129
|
+
protected handleError(message: ErrorMessage): void;
|
|
85
130
|
/**
|
|
86
131
|
* Handle a callback invocation
|
|
87
132
|
*/
|
|
@@ -97,15 +142,27 @@ export declare class Endpoint {
|
|
|
97
142
|
/**
|
|
98
143
|
* Register a local callback function
|
|
99
144
|
*/
|
|
100
|
-
|
|
145
|
+
protected registerCallback(fn: Function, remaining?: number): CallbackId;
|
|
101
146
|
/**
|
|
102
147
|
* Create a proxy function for a remote callback
|
|
103
148
|
*/
|
|
104
|
-
|
|
149
|
+
protected createRemoteCallback(callbackId: CallbackId): Function;
|
|
105
150
|
/**
|
|
106
151
|
* Invoke a remote callback
|
|
107
152
|
*/
|
|
108
153
|
private invokeCallback;
|
|
154
|
+
/**
|
|
155
|
+
* Process arguments for a call - separates functions into callbacks and collects transferables
|
|
156
|
+
*/
|
|
157
|
+
protected processArgs(args: unknown[]): {
|
|
158
|
+
rawArgs: unknown[];
|
|
159
|
+
callbackMap: Record<number, CallbackId>;
|
|
160
|
+
transferables: TransferableValue[];
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Build a call message
|
|
164
|
+
*/
|
|
165
|
+
protected buildCallMessage(id: CallId, path: MethodPath, rawArgs: unknown[], callbackMap: Record<number, CallbackId>): CallMessage;
|
|
109
166
|
/**
|
|
110
167
|
* Call a remote method
|
|
111
168
|
*/
|
|
@@ -113,7 +170,7 @@ export declare class Endpoint {
|
|
|
113
170
|
/**
|
|
114
171
|
* Send a message to the target
|
|
115
172
|
*/
|
|
116
|
-
|
|
173
|
+
protected send(message: RpcMessage, transferables?: TransferableValue[]): void;
|
|
117
174
|
/**
|
|
118
175
|
* Get the number of pending calls
|
|
119
176
|
*/
|
|
@@ -164,4 +221,3 @@ export declare function isMessagePort(value: unknown): value is MessagePort;
|
|
|
164
221
|
* Create an endpoint for a worker or message port
|
|
165
222
|
*/
|
|
166
223
|
export declare function createEndpoint(target: MessageTarget, options?: EndpointOptions): Endpoint;
|
|
167
|
-
//# sourceMappingURL=endpoint.d.ts.map
|
package/dist/id.d.ts
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
|
-
/** Generate a unique call ID */
|
|
2
|
-
export declare function generateId(): string;
|
|
3
1
|
/** Unique identifier for tracking RPC calls */
|
|
4
2
|
export type CallId = `c:${string}`;
|
|
5
|
-
export declare function generateCallId(): CallId;
|
|
6
3
|
/** Unique identifier for callback functions */
|
|
7
4
|
export type CallbackId = `cb:${string}`;
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Generate a random ID string for use as a default endpoint ID.
|
|
7
|
+
* @returns A random 6-character alphanumeric string
|
|
8
|
+
*/
|
|
9
|
+
export declare function generateRandomId(): string;
|
|
10
|
+
/**
|
|
11
|
+
* Extract the endpoint ID from a call ID.
|
|
12
|
+
* Call IDs have the format: "c:<endpointId>:<counter>"
|
|
13
|
+
*
|
|
14
|
+
* @param callId - The call ID to extract from
|
|
15
|
+
* @returns The endpoint ID portion of the call ID
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* extractEndpointId('c:runner3:1') // returns 'runner3'
|
|
20
|
+
* extractEndpointId('c:abc123:42') // returns 'abc123'
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function extractEndpointId(callId: CallId): string;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { type MessageTarget, type RemoteObject } from "./types";
|
|
|
3
3
|
export * from "./types";
|
|
4
4
|
export * from "./endpoint";
|
|
5
5
|
export * from "./proxy";
|
|
6
|
+
export * from "./broadcast";
|
|
6
7
|
/**
|
|
7
8
|
* Expose an API object for remote invocation
|
|
8
9
|
* Call this in the worker to expose methods to the parent
|
|
@@ -40,4 +41,3 @@ export declare function expose(api: object, options?: EndpointOptions): Endpoint
|
|
|
40
41
|
* ```
|
|
41
42
|
*/
|
|
42
43
|
export declare function remote<T extends object>(worker: MessageTarget, options?: EndpointOptions): RemoteObject<T>;
|
|
43
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,584 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
// src/types.ts
|
|
3
|
-
var MessageType;
|
|
4
|
-
((MessageType2) => {
|
|
5
|
-
MessageType2[MessageType2["Call"] = 0] = "Call";
|
|
6
|
-
MessageType2[MessageType2["Result"] = 1] = "Result";
|
|
7
|
-
MessageType2[MessageType2["Error"] = 2] = "Error";
|
|
8
|
-
MessageType2[MessageType2["Callback"] = 3] = "Callback";
|
|
9
|
-
MessageType2[MessageType2["CallbackRelease"] = 4] = "CallbackRelease";
|
|
10
|
-
MessageType2[MessageType2["EndpointRelease"] = 5] = "EndpointRelease";
|
|
11
|
-
})(MessageType ||= {});
|
|
12
|
-
|
|
13
|
-
// src/id.ts
|
|
14
|
-
var instanceId = Math.random().toString(36).slice(2, 8);
|
|
15
|
-
var counter = 0;
|
|
16
|
-
function generateId() {
|
|
17
|
-
return `${instanceId}:${++counter}`;
|
|
18
|
-
}
|
|
19
|
-
function generateCallId() {
|
|
20
|
-
return `c:${generateId()}`;
|
|
21
|
-
}
|
|
22
|
-
function generateCallbackId() {
|
|
23
|
-
return `cb:${generateId()}`;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// src/endpoint.ts
|
|
27
|
-
var DEFAULT_TIMEOUT = 30000;
|
|
28
|
-
|
|
29
|
-
class Endpoint {
|
|
30
|
-
target;
|
|
31
|
-
options;
|
|
32
|
-
exposedApi = null;
|
|
33
|
-
exposeOptions = {};
|
|
34
|
-
pendingCalls = new Map;
|
|
35
|
-
callbacks = new Map;
|
|
36
|
-
remoteCallbacks = new Map;
|
|
37
|
-
boundMessageHandler;
|
|
38
|
-
released = false;
|
|
39
|
-
constructor(target, options = {}) {
|
|
40
|
-
this.target = target;
|
|
41
|
-
this.options = {
|
|
42
|
-
timeout: options.timeout ?? DEFAULT_TIMEOUT,
|
|
43
|
-
onError: options.onError ?? console.error,
|
|
44
|
-
debug: options.debug ?? false,
|
|
45
|
-
onRelease: options.onRelease ?? (() => {})
|
|
46
|
-
};
|
|
47
|
-
this.boundMessageHandler = this.handleMessage.bind(this);
|
|
48
|
-
this.attachListener();
|
|
49
|
-
}
|
|
50
|
-
attachListener() {
|
|
51
|
-
if (this.target.addEventListener) {
|
|
52
|
-
this.target.addEventListener("message", this.boundMessageHandler);
|
|
53
|
-
} else if (this.target.onmessage !== undefined) {
|
|
54
|
-
this.target.onmessage = this.boundMessageHandler;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
detachListener() {
|
|
58
|
-
if (this.target.removeEventListener) {
|
|
59
|
-
this.target.removeEventListener("message", this.boundMessageHandler);
|
|
60
|
-
} else if (this.target.onmessage !== undefined) {
|
|
61
|
-
this.target.onmessage = null;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
debug(...args) {
|
|
65
|
-
if (this.options.debug) {
|
|
66
|
-
console.log("[worker-rpc]", ...args);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
expose(api, options = {}) {
|
|
70
|
-
this.exposedApi = api;
|
|
71
|
-
this.exposeOptions = {
|
|
72
|
-
maxDepth: options.maxDepth ?? 10
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
handleMessage(event) {
|
|
76
|
-
const message = event.data;
|
|
77
|
-
if (typeof message !== "object" || message === null || !("t" in message)) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
this.debug("received", MessageType[message.t], message);
|
|
81
|
-
switch (message.t) {
|
|
82
|
-
case 0 /* Call */:
|
|
83
|
-
this.handleCall(message);
|
|
84
|
-
break;
|
|
85
|
-
case 1 /* Result */:
|
|
86
|
-
this.handleResult(message);
|
|
87
|
-
break;
|
|
88
|
-
case 2 /* Error */:
|
|
89
|
-
this.handleError(message);
|
|
90
|
-
break;
|
|
91
|
-
case 3 /* Callback */:
|
|
92
|
-
this.handleCallback(message);
|
|
93
|
-
break;
|
|
94
|
-
case 4 /* CallbackRelease */:
|
|
95
|
-
this.handleCallbackRelease(message);
|
|
96
|
-
break;
|
|
97
|
-
case 5 /* EndpointRelease */:
|
|
98
|
-
this.handleEndpointRelease();
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
async handleCall(message) {
|
|
103
|
-
const { id, p: path, a: args, c: callbackMap } = message;
|
|
104
|
-
try {
|
|
105
|
-
const { method, thisArg } = this.resolveMethod(path);
|
|
106
|
-
if (typeof method !== "function") {
|
|
107
|
-
throw new Error(`Method not found: ${path.join(".")}`);
|
|
108
|
-
}
|
|
109
|
-
const resolvedArgs = args.map((arg, index) => {
|
|
110
|
-
const callbackId = callbackMap?.[index];
|
|
111
|
-
if (callbackId) {
|
|
112
|
-
return this.createRemoteCallback(callbackId);
|
|
113
|
-
}
|
|
114
|
-
return arg;
|
|
115
|
-
});
|
|
116
|
-
const result = await method.apply(thisArg, resolvedArgs);
|
|
117
|
-
if (isFunction(result)) {
|
|
118
|
-
const callbackId = this.registerCallback(result);
|
|
119
|
-
this.send({
|
|
120
|
-
t: 1 /* Result */,
|
|
121
|
-
id,
|
|
122
|
-
v: null,
|
|
123
|
-
c: callbackId
|
|
124
|
-
});
|
|
125
|
-
} else {
|
|
126
|
-
this.send({
|
|
127
|
-
t: 1 /* Result */,
|
|
128
|
-
id,
|
|
129
|
-
v: result
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
} catch (error) {
|
|
133
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
134
|
-
this.send({
|
|
135
|
-
t: 2 /* Error */,
|
|
136
|
-
id,
|
|
137
|
-
e: err.message,
|
|
138
|
-
n: err.name,
|
|
139
|
-
s: err.stack
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
resolveMethod(path) {
|
|
144
|
-
if (!this.exposedApi) {
|
|
145
|
-
throw new Error("No API exposed");
|
|
146
|
-
}
|
|
147
|
-
let current = this.exposedApi;
|
|
148
|
-
let parent = null;
|
|
149
|
-
for (let i = 0;i < path.length; i++) {
|
|
150
|
-
const key = path[i];
|
|
151
|
-
if (current === null || current === undefined) {
|
|
152
|
-
throw new Error(`Cannot access property '${key}' of ${current}`);
|
|
153
|
-
}
|
|
154
|
-
if (key === undefined) {
|
|
155
|
-
throw new Error(`Invalid path at index ${i}`);
|
|
156
|
-
}
|
|
157
|
-
parent = current;
|
|
158
|
-
current = current[key];
|
|
159
|
-
if (i >= (this.exposeOptions.maxDepth ?? 10)) {
|
|
160
|
-
throw new Error(`Maximum nesting depth exceeded`);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return { target: this.exposedApi, method: current, thisArg: parent };
|
|
164
|
-
}
|
|
165
|
-
handleResult(message) {
|
|
166
|
-
const pending = this.pendingCalls.get(message.id);
|
|
167
|
-
if (!pending) {
|
|
168
|
-
this.debug("Received result for unknown call:", message.id);
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
this.pendingCalls.delete(message.id);
|
|
172
|
-
if (pending.timer) {
|
|
173
|
-
clearTimeout(pending.timer);
|
|
174
|
-
}
|
|
175
|
-
if (message.c) {
|
|
176
|
-
pending.resolve(this.createRemoteCallback(message.c));
|
|
177
|
-
} else {
|
|
178
|
-
pending.resolve(message.v);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
handleError(message) {
|
|
182
|
-
const pending = this.pendingCalls.get(message.id);
|
|
183
|
-
if (!pending) {
|
|
184
|
-
this.debug("Received error for unknown call:", message.id);
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
this.pendingCalls.delete(message.id);
|
|
188
|
-
if (pending.timer) {
|
|
189
|
-
clearTimeout(pending.timer);
|
|
190
|
-
}
|
|
191
|
-
const error = new Error(message.e);
|
|
192
|
-
if (message.n) {
|
|
193
|
-
error.name = message.n;
|
|
194
|
-
}
|
|
195
|
-
if (message.s) {
|
|
196
|
-
error.stack = message.s;
|
|
197
|
-
}
|
|
198
|
-
pending.reject(error);
|
|
199
|
-
}
|
|
200
|
-
async handleCallback(message) {
|
|
201
|
-
const { id, c: callbackId, a: args, cb: callbackMap } = message;
|
|
202
|
-
const registration = this.callbacks.get(callbackId);
|
|
203
|
-
if (!registration) {
|
|
204
|
-
this.send({
|
|
205
|
-
t: 2 /* Error */,
|
|
206
|
-
id,
|
|
207
|
-
e: `Callback not found: ${callbackId}`
|
|
208
|
-
});
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
try {
|
|
212
|
-
const resolvedArgs = args.map((arg, index) => {
|
|
213
|
-
const cbId = callbackMap?.[index];
|
|
214
|
-
if (cbId) {
|
|
215
|
-
return this.createRemoteCallback(cbId);
|
|
216
|
-
}
|
|
217
|
-
return arg;
|
|
218
|
-
});
|
|
219
|
-
const result = await registration.fn(...resolvedArgs);
|
|
220
|
-
if (registration.remaining > 0) {
|
|
221
|
-
registration.remaining--;
|
|
222
|
-
if (registration.remaining === 0) {
|
|
223
|
-
this.callbacks.delete(callbackId);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
if (isFunction(result)) {
|
|
227
|
-
const cbId = this.registerCallback(result);
|
|
228
|
-
this.send({
|
|
229
|
-
t: 1 /* Result */,
|
|
230
|
-
id,
|
|
231
|
-
v: null,
|
|
232
|
-
c: cbId
|
|
233
|
-
});
|
|
234
|
-
} else {
|
|
235
|
-
this.send({
|
|
236
|
-
t: 1 /* Result */,
|
|
237
|
-
id,
|
|
238
|
-
v: result
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
} catch (error) {
|
|
242
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
243
|
-
this.send({
|
|
244
|
-
t: 2 /* Error */,
|
|
245
|
-
id,
|
|
246
|
-
e: err.message,
|
|
247
|
-
n: err.name,
|
|
248
|
-
s: err.stack
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
handleCallbackRelease(message) {
|
|
253
|
-
for (const callbackId of message.c) {
|
|
254
|
-
this.callbacks.delete(callbackId);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
handleEndpointRelease() {
|
|
258
|
-
this.debug("Remote endpoint released");
|
|
259
|
-
this.options.onRelease();
|
|
260
|
-
this.release({ silent: true });
|
|
261
|
-
}
|
|
262
|
-
registerCallback(fn, remaining = -1) {
|
|
263
|
-
const id = generateCallbackId();
|
|
264
|
-
this.callbacks.set(id, { fn, remaining });
|
|
265
|
-
return id;
|
|
266
|
-
}
|
|
267
|
-
createRemoteCallback(callbackId) {
|
|
268
|
-
let proxy = this.remoteCallbacks.get(callbackId);
|
|
269
|
-
if (proxy) {
|
|
270
|
-
return proxy;
|
|
271
|
-
}
|
|
272
|
-
proxy = async (...args) => {
|
|
273
|
-
return this.invokeCallback(callbackId, args);
|
|
274
|
-
};
|
|
275
|
-
this.remoteCallbacks.set(callbackId, proxy);
|
|
276
|
-
return proxy;
|
|
277
|
-
}
|
|
278
|
-
async invokeCallback(callbackId, args) {
|
|
279
|
-
const id = generateCallId();
|
|
280
|
-
const rawArgs = [];
|
|
281
|
-
const callbackMap = {};
|
|
282
|
-
const transferables = [];
|
|
283
|
-
for (let i = 0;i < args.length; i++) {
|
|
284
|
-
const arg = args[i];
|
|
285
|
-
if (isFunction(arg)) {
|
|
286
|
-
callbackMap[i] = this.registerCallback(arg);
|
|
287
|
-
rawArgs.push(null);
|
|
288
|
-
} else if (isMessagePort(arg)) {
|
|
289
|
-
transferables.push(arg);
|
|
290
|
-
rawArgs.push(arg);
|
|
291
|
-
} else {
|
|
292
|
-
rawArgs.push(arg);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
return new Promise((resolve, reject) => {
|
|
296
|
-
const timer = setTimeout(() => {
|
|
297
|
-
this.pendingCalls.delete(id);
|
|
298
|
-
reject(new Error(`Callback invocation timed out: ${callbackId}`));
|
|
299
|
-
}, this.options.timeout);
|
|
300
|
-
this.pendingCalls.set(id, { resolve, reject, timer });
|
|
301
|
-
const message = {
|
|
302
|
-
t: 3 /* Callback */,
|
|
303
|
-
id,
|
|
304
|
-
c: callbackId,
|
|
305
|
-
a: rawArgs,
|
|
306
|
-
...Object.keys(callbackMap).length > 0 && { cb: callbackMap }
|
|
307
|
-
};
|
|
308
|
-
this.send(message, transferables);
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
async call(path, args) {
|
|
312
|
-
if (this.released) {
|
|
313
|
-
throw new Error("Endpoint has been released");
|
|
314
|
-
}
|
|
315
|
-
const rawArgs = [];
|
|
316
|
-
const callbackMap = {};
|
|
317
|
-
const transferables = [];
|
|
318
|
-
for (let i = 0;i < args.length; i++) {
|
|
319
|
-
const arg = args[i];
|
|
320
|
-
switch (true) {
|
|
321
|
-
case isFunction(arg): {
|
|
322
|
-
callbackMap[i] = this.registerCallback(arg);
|
|
323
|
-
rawArgs.push(null);
|
|
324
|
-
break;
|
|
325
|
-
}
|
|
326
|
-
case isMessagePort(arg): {
|
|
327
|
-
transferables.push(arg);
|
|
328
|
-
rawArgs.push(arg);
|
|
329
|
-
break;
|
|
330
|
-
}
|
|
331
|
-
default: {
|
|
332
|
-
rawArgs.push(arg);
|
|
333
|
-
break;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
const id = generateCallId();
|
|
338
|
-
return new Promise((resolve, reject) => {
|
|
339
|
-
const timer = setTimeout(() => {
|
|
340
|
-
this.pendingCalls.delete(id);
|
|
341
|
-
reject(new Error(`Call timed out: ${path.join(".")}`));
|
|
342
|
-
}, this.options.timeout);
|
|
343
|
-
this.pendingCalls.set(id, { resolve, reject, timer });
|
|
344
|
-
const message = {
|
|
345
|
-
t: 0 /* Call */,
|
|
346
|
-
id,
|
|
347
|
-
p: path,
|
|
348
|
-
a: rawArgs,
|
|
349
|
-
...Object.keys(callbackMap).length > 0 && { c: callbackMap }
|
|
350
|
-
};
|
|
351
|
-
this.send(message, transferables);
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
send(message, transferables = []) {
|
|
355
|
-
this.debug("sending", MessageType[message.t], message);
|
|
356
|
-
this.target.postMessage(message, transferables);
|
|
357
|
-
}
|
|
358
|
-
getPendingCallCount() {
|
|
359
|
-
return this.pendingCalls.size;
|
|
360
|
-
}
|
|
361
|
-
hasPendingCalls() {
|
|
362
|
-
return this.pendingCalls.size > 0;
|
|
363
|
-
}
|
|
364
|
-
async shutdown(options = {}) {
|
|
365
|
-
const { timeout = DEFAULT_TIMEOUT } = options;
|
|
366
|
-
if (this.released) {
|
|
367
|
-
return {
|
|
368
|
-
success: true,
|
|
369
|
-
timeout: false
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
if (!this.hasPendingCalls()) {
|
|
373
|
-
this.release();
|
|
374
|
-
return {
|
|
375
|
-
success: true,
|
|
376
|
-
timeout: false
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
return new Promise((resolve) => {
|
|
380
|
-
let resolved = false;
|
|
381
|
-
const complete = (result) => {
|
|
382
|
-
if (resolved)
|
|
383
|
-
return;
|
|
384
|
-
resolved = true;
|
|
385
|
-
clearTimeout(timeoutId);
|
|
386
|
-
if (!this.released) {
|
|
387
|
-
this.release();
|
|
388
|
-
}
|
|
389
|
-
resolve(result);
|
|
390
|
-
};
|
|
391
|
-
const timeoutId = setTimeout(() => {
|
|
392
|
-
complete({
|
|
393
|
-
success: false,
|
|
394
|
-
timeout: true
|
|
395
|
-
});
|
|
396
|
-
}, timeout);
|
|
397
|
-
for (const [, pending] of this.pendingCalls) {
|
|
398
|
-
const originalResolve = pending.resolve;
|
|
399
|
-
const originalReject = pending.reject;
|
|
400
|
-
pending.resolve = (value) => {
|
|
401
|
-
originalResolve(value);
|
|
402
|
-
if (!this.hasPendingCalls()) {
|
|
403
|
-
complete({
|
|
404
|
-
success: true,
|
|
405
|
-
timeout: false
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
};
|
|
409
|
-
pending.reject = (error) => {
|
|
410
|
-
originalReject(error);
|
|
411
|
-
if (!this.hasPendingCalls()) {
|
|
412
|
-
complete({
|
|
413
|
-
success: true,
|
|
414
|
-
timeout: false
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
}
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
release(options = {}) {
|
|
422
|
-
if (this.released) {
|
|
423
|
-
return;
|
|
424
|
-
}
|
|
425
|
-
this.released = true;
|
|
426
|
-
for (const [, pending] of this.pendingCalls) {
|
|
427
|
-
if (pending.timer) {
|
|
428
|
-
clearTimeout(pending.timer);
|
|
429
|
-
}
|
|
430
|
-
pending.reject(new Error("Endpoint released"));
|
|
431
|
-
}
|
|
432
|
-
this.pendingCalls.clear();
|
|
433
|
-
const { silent = false } = options;
|
|
434
|
-
if (!silent) {
|
|
435
|
-
if (this.remoteCallbacks.size > 0) {
|
|
436
|
-
const callbackIds = [...this.remoteCallbacks.keys()];
|
|
437
|
-
this.send({
|
|
438
|
-
t: 4 /* CallbackRelease */,
|
|
439
|
-
id: generateCallId(),
|
|
440
|
-
c: callbackIds
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
this.send({
|
|
444
|
-
t: 5 /* EndpointRelease */,
|
|
445
|
-
id: generateCallId()
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
|
-
this.remoteCallbacks.clear();
|
|
449
|
-
this.callbacks.clear();
|
|
450
|
-
this.detachListener();
|
|
451
|
-
}
|
|
452
|
-
getTarget() {
|
|
453
|
-
return this.target;
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
function isFunction(value) {
|
|
457
|
-
return typeof value === "function";
|
|
458
|
-
}
|
|
459
|
-
function isMessagePort(value) {
|
|
460
|
-
return typeof MessagePort !== "undefined" && value instanceof MessagePort;
|
|
461
|
-
}
|
|
462
|
-
function createEndpoint(target, options) {
|
|
463
|
-
return new Endpoint(target, options);
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
// src/proxy.ts
|
|
467
|
-
var PATH = Symbol("rpc:path");
|
|
468
|
-
var PROXY_ENDPOINT = Symbol("rpc:proxy-endpoint");
|
|
469
|
-
var REMOTE_PROXY = Symbol.for("rpc:remote-proxy");
|
|
470
|
-
var ENDPOINT = Symbol.for("rpc:endpoint");
|
|
471
|
-
var RELEASE = Symbol.for("rpc:release");
|
|
472
|
-
var proxyHandler = {
|
|
473
|
-
get(target, prop) {
|
|
474
|
-
if (prop === REMOTE_PROXY) {
|
|
475
|
-
return true;
|
|
476
|
-
}
|
|
477
|
-
if (prop === ENDPOINT) {
|
|
478
|
-
return target[PROXY_ENDPOINT];
|
|
479
|
-
}
|
|
480
|
-
if (prop === RELEASE) {
|
|
481
|
-
return () => {
|
|
482
|
-
const endpoint = target[PROXY_ENDPOINT];
|
|
483
|
-
endpoint.release();
|
|
484
|
-
};
|
|
485
|
-
}
|
|
486
|
-
if (prop === "then") {
|
|
487
|
-
if (target[PATH].length === 0) {
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
|
-
const endpoint = target[PROXY_ENDPOINT];
|
|
491
|
-
const path = target[PATH];
|
|
492
|
-
const promise = endpoint.call(path, []);
|
|
493
|
-
return promise.then.bind(promise);
|
|
494
|
-
}
|
|
495
|
-
if (prop === "toJSON") {
|
|
496
|
-
return;
|
|
497
|
-
}
|
|
498
|
-
if (prop === Symbol.toStringTag || prop === Symbol.iterator || prop === Symbol.asyncIterator || prop === "constructor" || prop === "prototype") {
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
501
|
-
if (typeof prop === "string") {
|
|
502
|
-
const endpoint = target[PROXY_ENDPOINT];
|
|
503
|
-
const currentPath = target[PATH];
|
|
504
|
-
const newPath = [...currentPath, prop];
|
|
505
|
-
return createProxyInternal(endpoint, newPath);
|
|
506
|
-
}
|
|
507
|
-
},
|
|
508
|
-
apply(target, _thisArg, args) {
|
|
509
|
-
const endpoint = target[PROXY_ENDPOINT];
|
|
510
|
-
const path = target[PATH];
|
|
511
|
-
return endpoint.call(path, args);
|
|
512
|
-
},
|
|
513
|
-
set() {
|
|
514
|
-
throw new Error("Cannot set properties on a remote proxy");
|
|
515
|
-
},
|
|
516
|
-
deleteProperty() {
|
|
517
|
-
throw new Error("Cannot delete properties on a remote proxy");
|
|
518
|
-
},
|
|
519
|
-
getPrototypeOf() {
|
|
520
|
-
return Function.prototype;
|
|
521
|
-
},
|
|
522
|
-
has(_target, prop) {
|
|
523
|
-
return prop === REMOTE_PROXY || prop === ENDPOINT || prop === RELEASE;
|
|
524
|
-
}
|
|
525
|
-
};
|
|
526
|
-
function createProxyInternal(endpoint, path) {
|
|
527
|
-
const target = function() {};
|
|
528
|
-
target[PROXY_ENDPOINT] = endpoint;
|
|
529
|
-
target[PATH] = path;
|
|
530
|
-
return new Proxy(target, proxyHandler);
|
|
531
|
-
}
|
|
532
|
-
function wrap(endpoint) {
|
|
533
|
-
return createProxyInternal(endpoint, []);
|
|
534
|
-
}
|
|
535
|
-
function isProxy(value) {
|
|
536
|
-
if (value === null || value === undefined) {
|
|
537
|
-
return false;
|
|
538
|
-
}
|
|
539
|
-
try {
|
|
540
|
-
return value[REMOTE_PROXY] === true;
|
|
541
|
-
} catch {
|
|
542
|
-
return false;
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
function getEndpoint(proxy) {
|
|
546
|
-
if (isProxy(proxy)) {
|
|
547
|
-
return proxy[ENDPOINT];
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
function releaseProxy(proxy) {
|
|
551
|
-
if (isProxy(proxy)) {
|
|
552
|
-
proxy[RELEASE]();
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
// src/index.ts
|
|
557
|
-
function expose(api, options) {
|
|
558
|
-
const self = globalThis;
|
|
559
|
-
const endpoint2 = createEndpoint(self, options);
|
|
560
|
-
endpoint2.expose(api);
|
|
561
|
-
return endpoint2;
|
|
562
|
-
}
|
|
563
|
-
function remote(worker, options) {
|
|
564
|
-
const endpoint2 = createEndpoint(worker, options);
|
|
565
|
-
return wrap(endpoint2);
|
|
566
|
-
}
|
|
567
|
-
export {
|
|
568
|
-
wrap,
|
|
569
|
-
remote,
|
|
570
|
-
releaseProxy,
|
|
571
|
-
isProxy,
|
|
572
|
-
isMessagePort,
|
|
573
|
-
isFunction,
|
|
574
|
-
getEndpoint,
|
|
575
|
-
expose,
|
|
576
|
-
createEndpoint,
|
|
577
|
-
REMOTE_PROXY,
|
|
578
|
-
RELEASE,
|
|
579
|
-
PROXY_ENDPOINT,
|
|
580
|
-
PATH,
|
|
581
|
-
MessageType,
|
|
582
|
-
Endpoint,
|
|
583
|
-
ENDPOINT
|
|
584
|
-
};
|
|
2
|
+
var U;((K)=>{K[K.Call=0]="Call";K[K.Result=1]="Result";K[K.Error=2]="Error";K[K.Callback=3]="Callback";K[K.CallbackRelease=4]="CallbackRelease";K[K.EndpointRelease=5]="EndpointRelease"})(U||={});var _=30000;class S{static generateRandomId(){return Math.random().toString(36).slice(2,8)}static extractEndpointId(z){return z.split(":")[1]??""}target;options;exposedApi=null;exposeOptions={};id;callCounter=0;callbackCounter=0;pendingCalls=new Map;callbacks=new Map;remoteCallbacks=new Map;boundMessageHandler;released=!1;constructor(z,q={}){this.target=z,this.id=q.id??S.generateRandomId(),this.options={id:this.id,timeout:q.timeout??_,onError:q.onError??console.error,debug:q.debug??!1,onRelease:q.onRelease??(()=>{})},this.boundMessageHandler=this.handleMessage.bind(this),this.attachListener()}generateCallId(){return`c:${this.id}:${++this.callCounter}`}generateCallbackId(){return`cb:${this.id}:${++this.callbackCounter}`}attachListener(){if(this.target.addEventListener)this.target.addEventListener("message",this.boundMessageHandler);else if(this.target.onmessage!==void 0)this.target.onmessage=this.boundMessageHandler}detachListener(){if(this.target.removeEventListener)this.target.removeEventListener("message",this.boundMessageHandler);else if(this.target.onmessage!==void 0)this.target.onmessage=null}debug(...z){if(this.options.debug)console.log("[worker-rpc]",...z)}expose(z,q={}){this.exposedApi=z,this.exposeOptions={maxDepth:q.maxDepth??10}}handleMessage(z){let q=z.data;if(typeof q!=="object"||q===null||!("t"in q))return;switch(this.debug("received",U[q.t],q),q.t){case 0:this.handleCall(q);break;case 1:this.handleResult(q);break;case 2:this.handleError(q);break;case 3:this.handleCallback(q);break;case 4:this.handleCallbackRelease(q);break;case 5:this.handleEndpointRelease();break}}async handleCall(z){let{id:q,p:G,a:Q,c:V}=z;try{let{method:Z,thisArg:K}=this.resolveMethod(G);if(typeof Z!=="function")throw Error(`Method not found: ${G.join(".")}`);let $=Q.map((W,H)=>{let D=V?.[H];if(D)return this.createRemoteCallback(D);return W}),J=await Z.apply(K,$);if(L(J)){let W=this.registerCallback(J);this.send({t:1,id:q,v:null,c:W})}else this.send({t:1,id:q,v:J})}catch(Z){let K=Z instanceof Error?Z:Error(String(Z));this.send({t:2,id:q,e:K.message,n:K.name,s:K.stack})}}resolveMethod(z){if(!this.exposedApi)throw Error("No API exposed");let q=this.exposedApi,G=null;for(let Q=0;Q<z.length;Q++){let V=z[Q];if(q===null||q===void 0)throw Error(`Cannot access property '${V}' of ${q}`);if(V===void 0)throw Error(`Invalid path at index ${Q}`);if(G=q,q=q[V],Q>=(this.exposeOptions.maxDepth??10))throw Error("Maximum nesting depth exceeded")}return{target:this.exposedApi,method:q,thisArg:G}}handleResult(z){let q=this.pendingCalls.get(z.id);if(!q){this.debug("Received result for unknown call:",z.id);return}if(this.pendingCalls.delete(z.id),q.timer)clearTimeout(q.timer);if(z.c)q.resolve(this.createRemoteCallback(z.c));else q.resolve(z.v)}handleError(z){let q=this.pendingCalls.get(z.id);if(!q){this.debug("Received error for unknown call:",z.id);return}if(this.pendingCalls.delete(z.id),q.timer)clearTimeout(q.timer);let G=Error(z.e);if(z.n)G.name=z.n;if(z.s)G.stack=z.s;q.reject(G)}async handleCallback(z){let{id:q,c:G,a:Q,cb:V}=z,Z=this.callbacks.get(G);if(!Z){this.send({t:2,id:q,e:`Callback not found: ${G}`});return}try{let K=Q.map((J,W)=>{let H=V?.[W];if(H)return this.createRemoteCallback(H);return J}),$=await Z.fn(...K);if(Z.remaining>0){if(Z.remaining--,Z.remaining===0)this.callbacks.delete(G)}if(L($)){let J=this.registerCallback($);this.send({t:1,id:q,v:null,c:J})}else this.send({t:1,id:q,v:$})}catch(K){let $=K instanceof Error?K:Error(String(K));this.send({t:2,id:q,e:$.message,n:$.name,s:$.stack})}}handleCallbackRelease(z){for(let q of z.c)this.callbacks.delete(q)}handleEndpointRelease(){this.debug("Remote endpoint released"),this.options.onRelease(),this.release({silent:!0})}registerCallback(z,q=-1){let G=this.generateCallbackId();return this.callbacks.set(G,{fn:z,remaining:q}),G}createRemoteCallback(z){let q=this.remoteCallbacks.get(z);if(q)return q;return q=async(...G)=>{return this.invokeCallback(z,G)},this.remoteCallbacks.set(z,q),q}async invokeCallback(z,q){let G=this.generateCallId(),Q=[],V={},Z=[];for(let K=0;K<q.length;K++){let $=q[K];if(L($))V[K]=this.registerCallback($),Q.push(null);else if(R($))Z.push($),Q.push($);else Q.push($)}return new Promise((K,$)=>{let J=setTimeout(()=>{this.pendingCalls.delete(G),$(Error(`Callback invocation timed out: ${z}`))},this.options.timeout);this.pendingCalls.set(G,{resolve:K,reject:$,timer:J});let W={t:3,id:G,c:z,a:Q,...Object.keys(V).length>0&&{cb:V}};this.send(W,Z)})}processArgs(z){let q=[],G={},Q=[];for(let V=0;V<z.length;V++){let Z=z[V];if(L(Z))G[V]=this.registerCallback(Z),q.push(null);else if(R(Z))Q.push(Z),q.push(Z);else q.push(Z)}return{rawArgs:q,callbackMap:G,transferables:Q}}buildCallMessage(z,q,G,Q){return{t:0,id:z,p:q,a:G,...Object.keys(Q).length>0&&{c:Q}}}call(z,q){if(this.released)return Promise.reject(Error("Endpoint has been released"));let{rawArgs:G,callbackMap:Q,transferables:V}=this.processArgs(q),Z=this.generateCallId(),K=this.buildCallMessage(Z,z,G,Q);return new Promise(($,J)=>{let W=setTimeout(()=>{this.pendingCalls.delete(Z),J(Error(`Call timed out: ${z.join(".")}`))},this.options.timeout);this.pendingCalls.set(Z,{resolve:$,reject:J,timer:W}),this.send(K,V)})}send(z,q=[]){this.debug("sending",U[z.t],z),this.target.postMessage(z,q)}getPendingCallCount(){return this.pendingCalls.size}hasPendingCalls(){return this.pendingCalls.size>0}async shutdown(z={}){let{timeout:q=_}=z;if(this.released)return{success:!0,timeout:!1};if(!this.hasPendingCalls())return this.release(),{success:!0,timeout:!1};return new Promise((G)=>{let Q=!1,V=(K)=>{if(Q)return;if(Q=!0,clearTimeout(Z),!this.released)this.release();G(K)},Z=setTimeout(()=>{V({success:!1,timeout:!0})},q);for(let[,K]of this.pendingCalls){let{resolve:$,reject:J}=K;K.resolve=(W)=>{if($(W),!this.hasPendingCalls())V({success:!0,timeout:!1})},K.reject=(W)=>{if(J(W),!this.hasPendingCalls())V({success:!0,timeout:!1})}}})}release(z={}){if(this.released)return;this.released=!0;for(let[,G]of this.pendingCalls){if(G.timer)clearTimeout(G.timer);G.reject(Error("Endpoint released"))}this.pendingCalls.clear();let{silent:q=!1}=z;if(!q){if(this.remoteCallbacks.size>0){let G=[...this.remoteCallbacks.keys()];this.send({t:4,id:this.generateCallId(),c:G})}this.send({t:5,id:this.generateCallId()})}this.remoteCallbacks.clear(),this.callbacks.clear(),this.detachListener()}getTarget(){return this.target}}function L(z){return typeof z==="function"}function R(z){return typeof MessagePort<"u"&&z instanceof MessagePort}function C(z,q){return new S(z,q)}var F=Symbol("rpc:path"),B=Symbol("rpc:proxy-endpoint"),X=Symbol.for("rpc:remote-proxy"),Y=Symbol.for("rpc:endpoint"),j=Symbol.for("rpc:release"),v={get(z,q){if(q===X)return!0;if(q===Y)return z[B];if(q===j)return()=>{z[B].release()};if(q==="then"){if(z[F].length===0)return;let G=z[B],Q=z[F],V=G.call(Q,[]);return V.then.bind(V)}if(q==="toJSON")return;if(q===Symbol.toStringTag||q===Symbol.iterator||q===Symbol.asyncIterator||q==="constructor"||q==="prototype")return;if(typeof q==="string"){let G=z[B],V=[...z[F],q];return N(G,V)}},apply(z,q,G){let Q=z[B],V=z[F];return Q.call(V,G)},set(){throw Error("Cannot set properties on a remote proxy")},deleteProperty(){throw Error("Cannot delete properties on a remote proxy")},getPrototypeOf(){return Function.prototype},has(z,q){return q===X||q===Y||q===j}};function N(z,q){let G=function(){};return G[B]=z,G[F]=q,new Proxy(G,v)}function f(z){return N(z,[])}function O(z){if(z===null||z===void 0)return!1;try{return z[X]===!0}catch{return!1}}function I(z){if(O(z))return z[Y]}function h(z){if(O(z))z[j]()}class x extends S{pendingBroadcastCalls=new Map;get broadcastTarget(){return this.target}call(z,q){if(this.released)return Promise.reject(Error("Endpoint has been released"));let{rawArgs:G,callbackMap:Q,transferables:V}=this.processArgs(q),Z=this.generateCallId(),K=this.buildCallMessage(Z,z,G,Q);return this.sendBroadcast(Z,K,V,z)}sendBroadcast(z,q,G,Q){return this.debug("sending broadcast",U[q.t],q),new Promise((V,Z)=>{let K={resolve:V,reject:Z,timer:setTimeout(()=>this.handleTimeout(z,Q),this.options.timeout),expectedCount:1/0,results:[],errors:[]};this.pendingBroadcastCalls.set(z,K),Promise.resolve(this.broadcastTarget.postMessage(q,G)).then(($)=>this.handleSubscriberCount(z,$))})}handleTimeout(z,q){let G=this.pendingBroadcastCalls.get(z);if(!G)return;this.pendingBroadcastCalls.delete(z);let Q=G.results.length+G.errors.length,V=G.expectedCount===1/0?0:G.expectedCount-Q;if(V>0){let Z=Error(`Broadcast timed out: ${q.join(".")}`);Z.name="TimeoutError";for(let K=0;K<V;K++)G.errors.push(Z)}if(this.debug(`Broadcast timed out with ${G.results.length} results, ${G.errors.length} errors (${V} timed out)`),G.results.length>0||G.errors.length>0)G.resolve({results:G.results,errors:G.errors});else G.reject(Error(`Broadcast timed out: ${q.join(".")}`))}handleSubscriberCount(z,q){let G=this.pendingBroadcastCalls.get(z);if(!G)return;if(q===0){this.completeBroadcast(z,G);return}G.expectedCount=q,this.checkCompletion(z,G)}checkCompletion(z,q){if(q.results.length+q.errors.length>=q.expectedCount)this.completeBroadcast(z,q)}completeBroadcast(z,q){this.pendingBroadcastCalls.delete(z),clearTimeout(q.timer),q.resolve({results:q.results,errors:q.errors})}handleResult(z){let q=this.pendingBroadcastCalls.get(z.id);if(!q){super.handleResult(z);return}q.results.push(z.c?this.createRemoteCallback(z.c):z.v),this.debug(`Broadcast received ${q.results.length}/${q.expectedCount} responses`),this.checkCompletion(z.id,q)}handleError(z){let q=this.pendingBroadcastCalls.get(z.id);if(!q){super.handleError(z);return}let G=Error(z.e);if(z.n)G.name=z.n;if(z.s)G.stack=z.s;q.errors.push(G),this.debug(`Broadcast received error (${q.results.length} results, ${q.errors.length} errors / ${q.expectedCount} expected)`),this.checkCompletion(z.id,q)}getPendingCallCount(){return super.getPendingCallCount()+this.pendingBroadcastCalls.size}hasPendingCalls(){return super.hasPendingCalls()||this.pendingBroadcastCalls.size>0}release(z={}){for(let[,q]of this.pendingBroadcastCalls)clearTimeout(q.timer),q.reject(Error("Endpoint released"));this.pendingBroadcastCalls.clear(),super.release(z)}}function M(z,q){return new x(z,q)}function l(z,q){let Q=C(globalThis,q);return Q.expose(z),Q}function c(z,q){let G=C(z,q);return f(G)}export{f as wrap,c as remote,h as releaseProxy,O as isProxy,R as isMessagePort,L as isFunction,I as getEndpoint,l as expose,C as createEndpoint,M as createBroadcastEndpoint,X as REMOTE_PROXY,j as RELEASE,B as PROXY_ENDPOINT,F as PATH,U as MessageType,S as Endpoint,Y as ENDPOINT,x as BroadcastEndpoint};
|
package/dist/proxy.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { type BroadcastEndpoint } from "./broadcast";
|
|
1
2
|
import { Endpoint } from "./endpoint";
|
|
2
|
-
import { type RemoteObject } from "./types";
|
|
3
|
+
import { type RemoteBroadcastObject, type RemoteObject } from "./types";
|
|
3
4
|
/** Symbol to store the method path on a proxy */
|
|
4
5
|
export declare const PATH: unique symbol;
|
|
5
6
|
/** Symbol to store the endpoint on a proxy */
|
|
@@ -32,10 +33,8 @@ export declare const RELEASE: unique symbol;
|
|
|
32
33
|
* const user = await api.db.users.find("123");
|
|
33
34
|
* ```
|
|
34
35
|
*/
|
|
36
|
+
export declare function wrap<T extends object>(endpoint: BroadcastEndpoint): RemoteBroadcastObject<T>;
|
|
35
37
|
export declare function wrap<T extends object>(endpoint: Endpoint): RemoteObject<T>;
|
|
36
|
-
export declare function wrap<T extends object>(endpoint: Endpoint, options?: {
|
|
37
|
-
timeout?: number;
|
|
38
|
-
}): RemoteObject<T>;
|
|
39
38
|
/**
|
|
40
39
|
* Check if a value is a remote proxy
|
|
41
40
|
*/
|
|
@@ -48,4 +47,3 @@ export declare function getEndpoint(proxy: unknown): Endpoint | undefined;
|
|
|
48
47
|
* Release a proxy and its underlying endpoint
|
|
49
48
|
*/
|
|
50
49
|
export declare function releaseProxy(proxy: unknown): void;
|
|
51
|
-
//# sourceMappingURL=proxy.d.ts.map
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CallbackId, CallId } from './
|
|
1
|
+
import type { CallbackId, CallId } from './endpoint';
|
|
2
2
|
/** Path to a nested method (e.g., ['db', 'users', 'find']) */
|
|
3
3
|
export type MethodPath = string[];
|
|
4
4
|
/** Message types for the RPC protocol */
|
|
@@ -75,13 +75,17 @@ export interface EndpointReleaseMessage extends BaseMessage {
|
|
|
75
75
|
export type RpcMessage = CallMessage | ResultMessage | ErrorMessage | CallbackMessage | CallbackReleaseMessage | EndpointReleaseMessage;
|
|
76
76
|
/** Unwrap a Promise type */
|
|
77
77
|
export type Unpromise<T> = T extends Promise<infer U> ? U : T;
|
|
78
|
-
/**
|
|
79
|
-
export type
|
|
80
|
-
/** Convert a function type to its remote callable version */
|
|
81
|
-
export type RemoteFunction<T> = T extends (...args: infer A) => infer R ? (...args: A) => Promise<Unpromise<R>> : never;
|
|
78
|
+
/** Helper to convert a single property to its remote version */
|
|
79
|
+
export type RemoteProperty<T> = T extends (...args: infer A) => infer R ? (...args: A) => Promise<Unpromise<R>> : T extends object ? RemoteObject<T> : T;
|
|
82
80
|
/** Convert an object type to its remote callable version */
|
|
83
81
|
export type RemoteObject<T> = {
|
|
84
|
-
[K in keyof T]:
|
|
82
|
+
[K in keyof T]: RemoteProperty<T[K]>;
|
|
83
|
+
};
|
|
84
|
+
/** Helper to convert a single property to its broadcast remote version */
|
|
85
|
+
export type RemoteBroadcastProperty<T> = T extends (...args: infer A) => infer R ? (...args: A) => Promise<BroadcastResult<Unpromise<R>>> : T extends object ? RemoteBroadcastObject<T> : T;
|
|
86
|
+
/** Convert an object type to its broadcast remote version (all methods return arrays) */
|
|
87
|
+
export type RemoteBroadcastObject<T> = {
|
|
88
|
+
[K in keyof T]: RemoteBroadcastProperty<T[K]>;
|
|
85
89
|
};
|
|
86
90
|
/** Pending call information */
|
|
87
91
|
export interface PendingCall {
|
|
@@ -106,4 +110,29 @@ export interface MessageTarget {
|
|
|
106
110
|
start?(): void;
|
|
107
111
|
close?(): void;
|
|
108
112
|
}
|
|
109
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Extended message target that supports broadcasting to multiple receivers.
|
|
115
|
+
* The postMessage method returns the number of subscribers that received the message.
|
|
116
|
+
*/
|
|
117
|
+
export interface BroadcastMessageTarget extends Omit<MessageTarget, 'postMessage'> {
|
|
118
|
+
/**
|
|
119
|
+
* Send a message to all subscribers.
|
|
120
|
+
* @returns The number of subscribers that received the message
|
|
121
|
+
*/
|
|
122
|
+
postMessage(message: any, transfer?: any[]): number | Promise<number>;
|
|
123
|
+
addEventListener?(type: string, listener: (event: any) => void): void;
|
|
124
|
+
removeEventListener?(type: string, listener: (event: any) => void): void;
|
|
125
|
+
onmessage?: ((event: any) => void) | null;
|
|
126
|
+
start?(): void;
|
|
127
|
+
close?(): void;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Result of a broadcast call containing both successful results and errors.
|
|
131
|
+
* @template T - The type of successful results
|
|
132
|
+
*/
|
|
133
|
+
export interface BroadcastResult<T = unknown> {
|
|
134
|
+
/** Successful responses from subscribers */
|
|
135
|
+
results: T[];
|
|
136
|
+
/** Errors from subscribers that failed */
|
|
137
|
+
errors: Error[];
|
|
138
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xentobias/worker-rpc",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
4
4
|
"description": "High-performance, type-safe RPC for Workers",
|
|
5
5
|
"module": "src/index.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "bun build ./src/index.ts --outdir ./dist --target bun && tsc --declaration",
|
|
19
|
+
"build": "bun build ./src/index.ts --minify --outdir ./dist --target bun && tsc --declaration",
|
|
20
20
|
"typecheck": "tsc --noEmit",
|
|
21
21
|
"test": "bun test",
|
|
22
22
|
"prepublishOnly": "bun run build",
|
package/dist/endpoint.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../src/endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,UAAU,EAGf,KAAK,aAAa,EAEnB,MAAM,SAAS,CAAC;AAYjB,iDAAiD;AACjD,MAAM,WAAW,eAAe;IAC9B,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,2BAA2B;IAC3B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB;AAED,wCAAwC;AACxC,MAAM,WAAW,aAAa;IAC5B,qDAAqD;IACrD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,oCAAoC;AACpC,MAAM,WAAW,eAAe;IAC9B,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,8CAA8C;AAC9C,MAAM,WAAW,cAAc;IAC7B,uEAAuE;IACvE,OAAO,EAAE,OAAO,CAAC;IACjB,qCAAqC;IACrC,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;GA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;IACI,eAAe,IAAI,OAAO;IAIjC;;;;;;;;;;;;;;OAcG;IACU,QAAQ,CACnB,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,cAAc,CAAC;IAwE1B;;;;;OAKG;IACI,OAAO,CAAC,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAO,GAAG,IAAI;IA4CxD;;OAEG;IACI,SAAS,IAAI,aAAa;CAGlC;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAE5D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAElE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,aAAa,EACrB,OAAO,CAAC,EAAE,eAAe,GACxB,QAAQ,CAEV"}
|
package/dist/id.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../src/id.ts"],"names":[],"mappings":"AAMA,gCAAgC;AAChC,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAGD,+CAA+C;AAC/C,MAAM,MAAM,MAAM,GAAG,KAAK,MAAM,EAAE,CAAC;AAEnC,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,+CAA+C;AAC/C,MAAM,MAAM,UAAU,GAAG,MAAM,MAAM,EAAE,CAAC;AAExC,wBAAgB,kBAAkB,IAAI,UAAU,CAE/C"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAkB,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAE5E,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,SAAS,CAAC;AAEhE,cAAc,SAAS,CAA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