@camera.ui/rpc 1.0.1
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/README.md +3 -0
- package/dist/channel.d.ts +106 -0
- package/dist/channel.js +347 -0
- package/dist/channel.js.map +1 -0
- package/dist/chunking.d.ts +77 -0
- package/dist/chunking.js +151 -0
- package/dist/chunking.js.map +1 -0
- package/dist/client.d.ts +245 -0
- package/dist/client.js +1863 -0
- package/dist/client.js.map +1 -0
- package/dist/codec.d.ts +12 -0
- package/dist/codec.js +31 -0
- package/dist/codec.js.map +1 -0
- package/dist/decorators.d.ts +7 -0
- package/dist/decorators.js +192 -0
- package/dist/decorators.js.map +1 -0
- package/dist/errors.d.ts +30 -0
- package/dist/errors.js +54 -0
- package/dist/errors.js.map +1 -0
- package/dist/handler.d.ts +35 -0
- package/dist/handler.js +399 -0
- package/dist/handler.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/service.d.ts +60 -0
- package/dist/service.js +286 -0
- package/dist/service.js.map +1 -0
- package/dist/types.d.ts +300 -0
- package/dist/types.js +14 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +83 -0
- package/dist/utils.js +273 -0
- package/dist/utils.js.map +1 -0
- package/dist/wrapper.d.ts +1 -0
- package/dist/wrapper.js +2 -0
- package/dist/wrapper.js.map +1 -0
- package/package.json +49 -0
package/dist/chunking.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { decode } from './codec.js';
|
|
2
|
+
/**
|
|
3
|
+
* Split data into chunks
|
|
4
|
+
*/
|
|
5
|
+
export function* createChunks(encoded, chunkId, maxChunkSize) {
|
|
6
|
+
const totalSize = encoded.length;
|
|
7
|
+
const totalChunks = Math.ceil(totalSize / maxChunkSize);
|
|
8
|
+
for (let i = 0; i < totalChunks; i++) {
|
|
9
|
+
const start = i * maxChunkSize;
|
|
10
|
+
const end = Math.min(start + maxChunkSize, totalSize);
|
|
11
|
+
const chunk = encoded.subarray(start, end);
|
|
12
|
+
yield {
|
|
13
|
+
id: chunkId,
|
|
14
|
+
chunkIndex: i,
|
|
15
|
+
data: chunk,
|
|
16
|
+
isLast: i === totalChunks - 1,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Reassemble chunks back into original data using a pre-allocated buffer.
|
|
22
|
+
* Chunks are written directly to the buffer - no intermediate Map storage.
|
|
23
|
+
*/
|
|
24
|
+
export class ChunkAssembler {
|
|
25
|
+
id;
|
|
26
|
+
buffer;
|
|
27
|
+
receivedChunks = new Set();
|
|
28
|
+
totalChunks = 0;
|
|
29
|
+
chunkSize = 0;
|
|
30
|
+
constructor(id, totalSize, totalChunks, chunkSize) {
|
|
31
|
+
this.id = id;
|
|
32
|
+
this.totalChunks = totalChunks;
|
|
33
|
+
// Use provided chunkSize or calculate from totalSize/totalChunks
|
|
34
|
+
this.chunkSize = chunkSize ?? Math.ceil(totalSize / totalChunks);
|
|
35
|
+
this.buffer = new Uint8Array(totalSize);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Add a chunk to the assembler.
|
|
39
|
+
* Writes directly to the pre-allocated buffer.
|
|
40
|
+
* @returns true if all chunks are received
|
|
41
|
+
*/
|
|
42
|
+
addChunk(chunk) {
|
|
43
|
+
if (chunk.id !== this.id) {
|
|
44
|
+
throw new Error(`Chunk ID mismatch: expected ${this.id}, got ${chunk.id}`);
|
|
45
|
+
}
|
|
46
|
+
// Write chunk directly to pre-allocated buffer
|
|
47
|
+
const offset = chunk.chunkIndex * this.chunkSize;
|
|
48
|
+
this.buffer.set(chunk.data, offset);
|
|
49
|
+
this.receivedChunks.add(chunk.chunkIndex);
|
|
50
|
+
return this.isComplete();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Check if all chunks have been received
|
|
54
|
+
*/
|
|
55
|
+
isComplete() {
|
|
56
|
+
return this.receivedChunks.size === this.totalChunks;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get the reassembled data.
|
|
60
|
+
* Buffer is already complete, just decode - no copy needed.
|
|
61
|
+
*/
|
|
62
|
+
getData() {
|
|
63
|
+
if (!this.isComplete()) {
|
|
64
|
+
throw new Error('Not all chunks received');
|
|
65
|
+
}
|
|
66
|
+
return decode(this.buffer);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get progress information
|
|
70
|
+
*/
|
|
71
|
+
getProgress() {
|
|
72
|
+
const received = this.receivedChunks.size;
|
|
73
|
+
const total = this.totalChunks;
|
|
74
|
+
const percentage = total > 0 ? (received / total) * 100 : 0;
|
|
75
|
+
return { received, total, percentage };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Manager for handling multiple chunk transfers
|
|
80
|
+
*/
|
|
81
|
+
export class ChunkingManager {
|
|
82
|
+
assemblers = new Map();
|
|
83
|
+
completedCallbacks = new Map();
|
|
84
|
+
errorCallbacks = new Map();
|
|
85
|
+
/**
|
|
86
|
+
* Start receiving chunks for a transfer.
|
|
87
|
+
* Pre-allocates buffer for direct chunk writing.
|
|
88
|
+
*/
|
|
89
|
+
startReceiving(id, totalChunks, onComplete, onError, totalSize, chunkSize) {
|
|
90
|
+
const assembler = new ChunkAssembler(id, totalSize, totalChunks, chunkSize);
|
|
91
|
+
this.assemblers.set(id, assembler);
|
|
92
|
+
this.completedCallbacks.set(id, onComplete);
|
|
93
|
+
this.errorCallbacks.set(id, onError);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Process an incoming chunk
|
|
97
|
+
*/
|
|
98
|
+
processChunk(chunk) {
|
|
99
|
+
const assembler = this.assemblers.get(chunk.id);
|
|
100
|
+
if (!assembler) {
|
|
101
|
+
console.warn(`Received chunk for unknown transfer: ${chunk.id}`);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
const isComplete = assembler.addChunk(chunk);
|
|
106
|
+
if (isComplete) {
|
|
107
|
+
const data = assembler.getData();
|
|
108
|
+
const callback = this.completedCallbacks.get(chunk.id);
|
|
109
|
+
// Cleanup
|
|
110
|
+
this.assemblers.delete(chunk.id);
|
|
111
|
+
this.completedCallbacks.delete(chunk.id);
|
|
112
|
+
this.errorCallbacks.delete(chunk.id);
|
|
113
|
+
// Notify completion
|
|
114
|
+
if (callback) {
|
|
115
|
+
callback(data);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
const errorCallback = this.errorCallbacks.get(chunk.id);
|
|
121
|
+
// Cleanup
|
|
122
|
+
this.assemblers.delete(chunk.id);
|
|
123
|
+
this.completedCallbacks.delete(chunk.id);
|
|
124
|
+
this.errorCallbacks.delete(chunk.id);
|
|
125
|
+
// Notify error
|
|
126
|
+
if (errorCallback) {
|
|
127
|
+
errorCallback(error);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Cancel a transfer
|
|
133
|
+
*/
|
|
134
|
+
cancel(id) {
|
|
135
|
+
const errorCallback = this.errorCallbacks.get(id);
|
|
136
|
+
this.assemblers.delete(id);
|
|
137
|
+
this.completedCallbacks.delete(id);
|
|
138
|
+
this.errorCallbacks.delete(id);
|
|
139
|
+
if (errorCallback) {
|
|
140
|
+
errorCallback(new Error('Transfer cancelled'));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Get progress for a transfer
|
|
145
|
+
*/
|
|
146
|
+
getProgress(id) {
|
|
147
|
+
const assembler = this.assemblers.get(id);
|
|
148
|
+
return assembler ? assembler.getProgress() : null;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=chunking.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunking.js","sourceRoot":"","sources":["../src/chunking.ts"],"names":[],"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AC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACpD,CAAC;CACF"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { Channel, PrivateChannel } from './channel.js';
|
|
2
|
+
import { ChunkingManager } from './chunking.js';
|
|
3
|
+
import { RPCService } from './service.js';
|
|
4
|
+
import type { MsgHdrs, NatsConnection, Status } from '@nats-io/nats-core';
|
|
5
|
+
import type { Promisify, RPCAuthOptions, RPCClient as RPCClientImpl, RPCClientOptions } from './types.js';
|
|
6
|
+
export declare function createRPCClient(options: RPCClientOptions): RPCClientImpl;
|
|
7
|
+
export declare class RPCClient implements RPCClientImpl {
|
|
8
|
+
options: RPCClientOptions;
|
|
9
|
+
readonly service: RPCService;
|
|
10
|
+
chunkingManager: ChunkingManager;
|
|
11
|
+
private pullIteratorCleanups;
|
|
12
|
+
private callbackCleanups;
|
|
13
|
+
private nc?;
|
|
14
|
+
private subscriptions;
|
|
15
|
+
private _subscriptionMeta;
|
|
16
|
+
private _maxPayloadSize;
|
|
17
|
+
private connectionPromise?;
|
|
18
|
+
private closed;
|
|
19
|
+
private isolatedClients;
|
|
20
|
+
private pendingRequests;
|
|
21
|
+
private streamHandlers;
|
|
22
|
+
/**
|
|
23
|
+
* Check connection status
|
|
24
|
+
*/
|
|
25
|
+
get isConnected(): boolean;
|
|
26
|
+
get isClosed(): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Get the maximum payload size
|
|
29
|
+
*/
|
|
30
|
+
get maxPayloadSize(): number;
|
|
31
|
+
/**
|
|
32
|
+
* Access the underlying NATS connection status events.
|
|
33
|
+
* Yields events like 'reconnect', 'disconnect', 'reconnecting'.
|
|
34
|
+
*/
|
|
35
|
+
status(): AsyncIterable<Status> | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Active liveness probe via NATS PING/PONG round-trip. Resolves when a PONG
|
|
38
|
+
* arrives, rejects on timeout. Caller treats timeout as "connection is dead"
|
|
39
|
+
* — the underlying socket may still report OPEN in that case (silent-dead
|
|
40
|
+
* TCP). Use a tight timeout (a few seconds) so a stale connection is
|
|
41
|
+
* detected promptly.
|
|
42
|
+
*/
|
|
43
|
+
flush(timeoutMs?: number): Promise<void>;
|
|
44
|
+
constructor(options: RPCClientOptions);
|
|
45
|
+
/**
|
|
46
|
+
* Create a new isolated RPC client
|
|
47
|
+
* @param options - Options for the isolated client
|
|
48
|
+
*/
|
|
49
|
+
createIsolatedClient(options: RPCClientOptions): RPCClient;
|
|
50
|
+
/**
|
|
51
|
+
* Connect to NATS server. Accepts an AbortSignal so callers can cancel
|
|
52
|
+
* an in-flight handshake when another candidate has won.
|
|
53
|
+
* The underlying nats-js connect() does not itself accept a signal,
|
|
54
|
+
* so we wrap it: on abort we synchronously close any late-arriving connection
|
|
55
|
+
* via the fork's abortClose() and reject with AbortError.
|
|
56
|
+
*/
|
|
57
|
+
connect(options?: {
|
|
58
|
+
signal?: AbortSignal;
|
|
59
|
+
}): Promise<NatsConnection>;
|
|
60
|
+
/**
|
|
61
|
+
* Disconnect from NATS server
|
|
62
|
+
* Cleans up resources without rejecting pending operations
|
|
63
|
+
*/
|
|
64
|
+
disconnect(): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Update connection options between suspend() and connect(). Used for token
|
|
67
|
+
* rotation / endpoint switching: subscription metadata is preserved by
|
|
68
|
+
* suspend(), reconfigure() points the next connect() at the new server, and
|
|
69
|
+
* connect() re-subscribes everything on the fresh transport.
|
|
70
|
+
*/
|
|
71
|
+
reconfigure(overrides: {
|
|
72
|
+
servers?: string[];
|
|
73
|
+
auth?: RPCAuthOptions;
|
|
74
|
+
}): void;
|
|
75
|
+
/**
|
|
76
|
+
* Hot-swap the server pool without dropping the live connection.
|
|
77
|
+
* Use this when only the URL needs to change but the existing connection
|
|
78
|
+
* is still authenticated and serving traffic. The new pool kicks in on the next auto-reconnect.
|
|
79
|
+
*
|
|
80
|
+
* For a forced switch (e.g. endpoint host changed), use suspend() +
|
|
81
|
+
* reconfigure() + connect() instead.
|
|
82
|
+
*/
|
|
83
|
+
setServers(servers: string[]): void;
|
|
84
|
+
/**
|
|
85
|
+
* Force the current dial loop (if any) to immediately retry with the latest
|
|
86
|
+
* server pool — including from a stuck mid-handshake or sleeping-on-delay
|
|
87
|
+
* state. Falls back to standard `reconnect()` on transports that don't ship
|
|
88
|
+
* the fork's `forceReconnect()` (e.g. server-side TCP via npm `@nats-io/nats-core`).
|
|
89
|
+
*/
|
|
90
|
+
forceReconnect(): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Synchronous force-tear-down without awaiting the transport's close
|
|
93
|
+
* handshake. Use during network changes when the WS is half-open and a
|
|
94
|
+
* normal `close()` would hang for 2s+ on the dead socket. Falls back to
|
|
95
|
+
* fire-and-forget `close()` on transports without the fork patch.
|
|
96
|
+
*/
|
|
97
|
+
abortClose(err?: Error): void;
|
|
98
|
+
/**
|
|
99
|
+
* Suspend the connection without clearing subscription metadata.
|
|
100
|
+
* After calling suspend(), connect() will restore previous subscriptions.
|
|
101
|
+
*/
|
|
102
|
+
suspend(): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Public publish method
|
|
105
|
+
*/
|
|
106
|
+
publish<TMessage = any>(subject: string, data: TMessage, opts?: {
|
|
107
|
+
headers?: MsgHdrs;
|
|
108
|
+
reply?: string;
|
|
109
|
+
}): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Public subscribe method
|
|
112
|
+
*/
|
|
113
|
+
subscribe<TResponse = any>(pattern: string, handler: (data: TResponse) => void | Promise<void>, options?: {
|
|
114
|
+
queue?: string;
|
|
115
|
+
}): Promise<() => void>;
|
|
116
|
+
/**
|
|
117
|
+
* Native NATS request/reply
|
|
118
|
+
* @param subject - The subject to send the request to
|
|
119
|
+
* @param data - The request data
|
|
120
|
+
* @param options - Request options including timeout and per-call retry override
|
|
121
|
+
*/
|
|
122
|
+
request<TRequest = any, TResponse = any>(subject: string, data: TRequest, options?: {
|
|
123
|
+
timeout?: number;
|
|
124
|
+
headers?: MsgHdrs;
|
|
125
|
+
noResponderRetry?: {
|
|
126
|
+
maxRetries?: number;
|
|
127
|
+
delays?: number[];
|
|
128
|
+
};
|
|
129
|
+
}): Promise<TResponse>;
|
|
130
|
+
private _requestOnce;
|
|
131
|
+
/**
|
|
132
|
+
* Retry helper for 503 / no-responder errors. The per-call `override`
|
|
133
|
+
* lets a request that targets a known-flaky responder (e.g. a child
|
|
134
|
+
* process that may be restarting) extend the wait window without
|
|
135
|
+
* affecting the client-wide default.
|
|
136
|
+
*/
|
|
137
|
+
private withNoResponderRetry;
|
|
138
|
+
/**
|
|
139
|
+
* Make an RPC call
|
|
140
|
+
*/
|
|
141
|
+
call<TResponse = any>(subject: string, ...args: any[]): Promise<TResponse>;
|
|
142
|
+
/**
|
|
143
|
+
* Make an RPC call (single attempt)
|
|
144
|
+
*/
|
|
145
|
+
private _callOnce;
|
|
146
|
+
/**
|
|
147
|
+
* Make a streaming RPC call
|
|
148
|
+
*/
|
|
149
|
+
callStream<TResponse = any>(subject: string, ...args: any[]): AsyncGenerator<TResponse>;
|
|
150
|
+
/**
|
|
151
|
+
* Make a streaming RPC call (single attempt).
|
|
152
|
+
*
|
|
153
|
+
* Manual iterator — see callPullIteratorWithCallback for rationale.
|
|
154
|
+
* The push-based stream still parks the client at `await resolver`
|
|
155
|
+
* while waiting for the next stream message; if the server stops
|
|
156
|
+
* sending without an `end` frame, the generator would hang on
|
|
157
|
+
* iter.return(). Force-settling the pending resolver lets return()
|
|
158
|
+
* run cleanup cleanly.
|
|
159
|
+
*/
|
|
160
|
+
private _callStreamOnce;
|
|
161
|
+
/**
|
|
162
|
+
* Make a pull-based iterator RPC call
|
|
163
|
+
*/
|
|
164
|
+
callPullIterator<TResponse = any>(subject: string, ...args: any[]): AsyncGenerator<TResponse>;
|
|
165
|
+
/**
|
|
166
|
+
* Pull-iterator-with-callbacks call.
|
|
167
|
+
*
|
|
168
|
+
* Combines a client-driven pull iterator (1 RTT per batch) with a oneway
|
|
169
|
+
* callback channel (fire-and-forget server → client) for low-latency
|
|
170
|
+
* frame-level data delivery with coarse-grained backpressure.
|
|
171
|
+
*
|
|
172
|
+
* The returned async generator yields `undefined` for each batch boundary
|
|
173
|
+
* the server produces. Meaningful data is dispatched through the provided
|
|
174
|
+
* callback object.
|
|
175
|
+
*/
|
|
176
|
+
callPullIteratorWithCallback(subject: string, callbacks: Record<string, (...a: any[]) => any>, onewayMethods: string[], ...args: any[]): AsyncGenerator<void>;
|
|
177
|
+
/**
|
|
178
|
+
* Make an RPC call with a callback subscription.
|
|
179
|
+
* Returns an unsubscribe function.
|
|
180
|
+
*/
|
|
181
|
+
callWithCallback<TResponse = any>(subject: string, args: any[], callback: (value: TResponse) => void | Promise<void>): Promise<() => void>;
|
|
182
|
+
/**
|
|
183
|
+
* Register RPC handlers
|
|
184
|
+
*/
|
|
185
|
+
registerHandler(namespace: string, handlers: object, options?: {
|
|
186
|
+
isolatedConnection?: boolean;
|
|
187
|
+
withoutDecorators?: boolean;
|
|
188
|
+
queue?: string;
|
|
189
|
+
}): Promise<() => Promise<void>>;
|
|
190
|
+
/**
|
|
191
|
+
* Setup a request handler (responder)
|
|
192
|
+
* @param pattern - The subject pattern to listen for requests
|
|
193
|
+
* @param handler - The handler function that receives data and subject
|
|
194
|
+
*/
|
|
195
|
+
onRequest<TRequest = any, TResponse = any>(pattern: string, handler: (data: TRequest) => Promise<TResponse> | TResponse): Promise<() => void>;
|
|
196
|
+
/**
|
|
197
|
+
* Create or join a bidirectional channel
|
|
198
|
+
* @param channelId - Unique channel identifier
|
|
199
|
+
* @param options - Optional configuration
|
|
200
|
+
*/
|
|
201
|
+
channel(channelId: string, options?: {
|
|
202
|
+
isolatedConnection?: boolean;
|
|
203
|
+
}): Promise<Channel>;
|
|
204
|
+
/**
|
|
205
|
+
* Create a private 1:1 channel
|
|
206
|
+
* @param channelId - Unique channel identifier
|
|
207
|
+
* @param targetClientId - Target client to connect to
|
|
208
|
+
* @param options - Optional configuration
|
|
209
|
+
*/
|
|
210
|
+
privateChannel(channelId: string, targetClientId: string, options?: {
|
|
211
|
+
isolatedConnection?: boolean;
|
|
212
|
+
}): Promise<PrivateChannel>;
|
|
213
|
+
/**
|
|
214
|
+
* Create proxy for type-safe RPC calls
|
|
215
|
+
* @param namespace - The namespace for RPC calls
|
|
216
|
+
* @param options - Optional configuration
|
|
217
|
+
*/
|
|
218
|
+
createProxy<T extends object>(namespace: string): Promisify<T>;
|
|
219
|
+
createProxy<T extends object>(namespace: string, options: {
|
|
220
|
+
isolatedConnection: false;
|
|
221
|
+
}): Promisify<T>;
|
|
222
|
+
createProxy<T extends object>(namespace: string, options: {
|
|
223
|
+
isolatedConnection: true;
|
|
224
|
+
}): {
|
|
225
|
+
proxy: Promisify<T>;
|
|
226
|
+
close: () => Promise<void>;
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* Create a service client proxy with automatic service discovery
|
|
230
|
+
*/
|
|
231
|
+
createServiceProxy<T extends object>(serviceName: string): Promise<Promisify<T>>;
|
|
232
|
+
createServiceProxy<T extends object>(serviceName: string, options: {
|
|
233
|
+
preferredId?: string;
|
|
234
|
+
timeout?: number;
|
|
235
|
+
isolatedConnection?: false;
|
|
236
|
+
}): Promise<Promisify<T>>;
|
|
237
|
+
createServiceProxy<T extends object>(serviceName: string, options: {
|
|
238
|
+
preferredId?: string;
|
|
239
|
+
timeout?: number;
|
|
240
|
+
isolatedConnection?: true;
|
|
241
|
+
}): Promise<{
|
|
242
|
+
proxy: Promisify<T>;
|
|
243
|
+
close: () => Promise<void>;
|
|
244
|
+
}>;
|
|
245
|
+
}
|