@cocoar/signalarrr 4.0.0-beta.15

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/index.cjs ADDED
@@ -0,0 +1,375 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ HARRRConnection: () => HARRRConnection,
34
+ HARRRConnectionOptions: () => HARRRConnectionOptions,
35
+ isStreamReference: () => isStreamReference,
36
+ parseHARRRError: () => parseHARRRError,
37
+ resolveStreamReference: () => resolveStreamReference,
38
+ resolveStreamReferenceAsStream: () => resolveStreamReferenceAsStream
39
+ });
40
+ module.exports = __toCommonJS(index_exports);
41
+
42
+ // src/harrr-connection.ts
43
+ var signalR = __toESM(require("@microsoft/signalr"), 1);
44
+
45
+ // src/models/cancellation-token-reference.ts
46
+ function isCancellationTokenReference(v) {
47
+ return typeof v === "object" && v !== null && typeof v["Id"] === "string";
48
+ }
49
+
50
+ // src/models/stream-reference.ts
51
+ function isStreamReference(v) {
52
+ if (typeof v !== "object" || v === null) return false;
53
+ const obj = v;
54
+ return typeof obj["Uri"] === "string" && Object.keys(obj).length === 1;
55
+ }
56
+ async function resolveStreamReference(ref) {
57
+ const response = await fetchStreamReference(ref);
58
+ return response.arrayBuffer();
59
+ }
60
+ async function resolveStreamReferenceAsStream(ref) {
61
+ const response = await fetchStreamReference(ref);
62
+ if (!response.body) {
63
+ throw new Error("StreamReference: response has no body stream");
64
+ }
65
+ return response.body;
66
+ }
67
+ async function fetchStreamReference(ref) {
68
+ const url = ref.Uri;
69
+ const scheme = url.split(":")[0]?.toLowerCase();
70
+ if (scheme !== "http" && scheme !== "https") {
71
+ throw new Error(`StreamReference: unsupported URI scheme '${scheme}'`);
72
+ }
73
+ const response = await fetch(url);
74
+ if (!response.ok) {
75
+ throw new Error(`StreamReference: download failed (${response.status} ${response.statusText})`);
76
+ }
77
+ return response;
78
+ }
79
+
80
+ // src/models/harrr-error.ts
81
+ function parseHARRRError(error) {
82
+ const msg = error instanceof Error ? error.message : String(error);
83
+ const marker = "HARRRException: ";
84
+ const markerIndex = msg.indexOf(marker);
85
+ const jsonCandidate = markerIndex >= 0 ? msg.substring(markerIndex + marker.length) : msg;
86
+ try {
87
+ const parsed = JSON.parse(jsonCandidate);
88
+ if (typeof parsed === "object" && parsed !== null && typeof parsed.Type === "string" && typeof parsed.Message === "string") {
89
+ return parsed;
90
+ }
91
+ } catch {
92
+ }
93
+ const matches = /\[([\w.]+)\]\s*(.*)/m.exec(msg);
94
+ if (matches) {
95
+ return {
96
+ Type: matches[1] ?? "Error",
97
+ Message: matches[2] ?? msg
98
+ };
99
+ }
100
+ return {
101
+ Type: "Error",
102
+ Message: msg
103
+ };
104
+ }
105
+
106
+ // src/cancellation-manager.ts
107
+ var CancellationManager = class {
108
+ _controllers = /* @__PURE__ */ new Map();
109
+ create(id) {
110
+ const controller = new AbortController();
111
+ this._controllers.set(id, controller);
112
+ return controller.signal;
113
+ }
114
+ cancel(id) {
115
+ const controller = this._controllers.get(id);
116
+ if (controller) {
117
+ controller.abort();
118
+ this._controllers.delete(id);
119
+ }
120
+ }
121
+ remove(id) {
122
+ this._controllers.delete(id);
123
+ }
124
+ };
125
+
126
+ // src/harrr-connection.ts
127
+ var HARRRConnection = class _HARRRConnection {
128
+ _hubConnection;
129
+ _accessTokenFactory = () => "";
130
+ _serverRequestHandlers = /* @__PURE__ */ new Map();
131
+ _serverStreamHandlers = /* @__PURE__ */ new Map();
132
+ _cancellationManager = new CancellationManager();
133
+ get baseUrl() {
134
+ return this._hubConnection.baseUrl;
135
+ }
136
+ set baseUrl(value) {
137
+ this._hubConnection.baseUrl = value;
138
+ }
139
+ get connectionId() {
140
+ return this._hubConnection.connectionId;
141
+ }
142
+ get state() {
143
+ return this._hubConnection.state;
144
+ }
145
+ get serverTimeoutInMilliseconds() {
146
+ return this._hubConnection.serverTimeoutInMilliseconds;
147
+ }
148
+ set serverTimeoutInMilliseconds(value) {
149
+ this._hubConnection.serverTimeoutInMilliseconds = value;
150
+ }
151
+ get keepAliveIntervalInMilliseconds() {
152
+ return this._hubConnection.keepAliveIntervalInMilliseconds;
153
+ }
154
+ set keepAliveIntervalInMilliseconds(value) {
155
+ this._hubConnection.keepAliveIntervalInMilliseconds = value;
156
+ }
157
+ constructor(hubConnection, _options) {
158
+ this._hubConnection = hubConnection;
159
+ const conn = hubConnection["connection"];
160
+ const factory = conn?.["_options"]?.["accessTokenFactory"] ?? conn?.["_accessTokenFactory"];
161
+ if (typeof factory === "function") {
162
+ this._accessTokenFactory = factory;
163
+ }
164
+ this._hubConnection.on("ChallengeAuthentication", (req) => {
165
+ return this._accessTokenFactory();
166
+ });
167
+ this._hubConnection.on("InvokeServerRequest", async (req) => {
168
+ if (req.StreamId) {
169
+ await this._streamBackToServer(req, req.StreamId);
170
+ return void 0;
171
+ }
172
+ const result = await this._dispatchServerMethod(req);
173
+ if (result instanceof Blob || result instanceof ArrayBuffer || isNodeBuffer(result)) {
174
+ return await this._uploadAndReturnReference(result);
175
+ }
176
+ return result;
177
+ });
178
+ this._hubConnection.on("InvokeServerMessage", async (req) => {
179
+ try {
180
+ if (req.StreamId) {
181
+ await this._streamBackToServer(req, req.StreamId);
182
+ } else {
183
+ await this._dispatchServerMethod(req);
184
+ }
185
+ } catch {
186
+ }
187
+ });
188
+ this._hubConnection.on("CancelTokenFromServer", (req) => {
189
+ if (req.CancellationGuid) {
190
+ this._cancellationManager.cancel(req.CancellationGuid);
191
+ }
192
+ });
193
+ }
194
+ async _dispatchServerMethod(req) {
195
+ const handler = this._serverRequestHandlers.get(req.Method);
196
+ if (!handler) return void 0;
197
+ const args = await this._prepareArgs(req);
198
+ return await handler(...args);
199
+ }
200
+ async _prepareArgs(req) {
201
+ const args = [];
202
+ for (const arg of req.Arguments ?? []) {
203
+ if (isCancellationTokenReference(arg) && req.CancellationGuid) {
204
+ args.push(this._cancellationManager.create(req.CancellationGuid));
205
+ } else if (isStreamReference(arg)) {
206
+ args.push(await resolveStreamReference(arg));
207
+ } else {
208
+ args.push(arg);
209
+ }
210
+ }
211
+ return args;
212
+ }
213
+ async _streamBackToServer(req, streamId) {
214
+ const args = await this._prepareArgs(req);
215
+ try {
216
+ const streamHandler = this._serverStreamHandlers.get(req.Method);
217
+ if (streamHandler) {
218
+ const stream = streamHandler(...args);
219
+ for await (const item of stream) {
220
+ await this._hubConnection.send("StreamItemToServer", streamId, item);
221
+ }
222
+ await this._hubConnection.send("StreamCompleteToServer", streamId, null);
223
+ return;
224
+ }
225
+ const handler = this._serverRequestHandlers.get(req.Method);
226
+ if (handler) {
227
+ const result = await handler(...args);
228
+ if (result != null) {
229
+ if (typeof result === "object" && Symbol.asyncIterator in result) {
230
+ for await (const item of result) {
231
+ await this._hubConnection.send("StreamItemToServer", streamId, item);
232
+ }
233
+ } else {
234
+ await this._hubConnection.send("StreamItemToServer", streamId, result);
235
+ }
236
+ }
237
+ await this._hubConnection.send("StreamCompleteToServer", streamId, null);
238
+ } else {
239
+ await this._hubConnection.send("StreamCompleteToServer", streamId, null);
240
+ }
241
+ } catch (err) {
242
+ await this._hubConnection.send("StreamCompleteToServer", streamId, String(err));
243
+ }
244
+ }
245
+ async _uploadAndReturnReference(data) {
246
+ const uploadUrl = await this._hubConnection.invoke("RequestUploadSlot");
247
+ let body;
248
+ if (data instanceof Blob) {
249
+ body = data;
250
+ } else if (data instanceof ArrayBuffer || data instanceof Uint8Array) {
251
+ body = data;
252
+ } else {
253
+ body = String(data);
254
+ }
255
+ await fetch(uploadUrl, {
256
+ method: "POST",
257
+ headers: { "Content-Type": "application/octet-stream" },
258
+ body
259
+ });
260
+ return { Uri: uploadUrl };
261
+ }
262
+ /** Prepare outgoing arguments — upload binary data and replace with StreamReferences. */
263
+ async _prepareOutgoingArgs(args) {
264
+ let hasStream = false;
265
+ for (const arg of args) {
266
+ if (arg instanceof Blob || arg instanceof ArrayBuffer || isNodeBuffer(arg)) {
267
+ hasStream = true;
268
+ break;
269
+ }
270
+ }
271
+ if (!hasStream) return args;
272
+ const result = [];
273
+ for (const arg of args) {
274
+ if (arg instanceof Blob || arg instanceof ArrayBuffer || isNodeBuffer(arg)) {
275
+ result.push(await this._uploadAndReturnReference(arg));
276
+ } else {
277
+ result.push(arg);
278
+ }
279
+ }
280
+ return result;
281
+ }
282
+ start() {
283
+ return this._hubConnection.start();
284
+ }
285
+ stop() {
286
+ return this._hubConnection.stop();
287
+ }
288
+ onClose(callback) {
289
+ this._hubConnection.onclose(callback);
290
+ }
291
+ onReconnecting(callback) {
292
+ this._hubConnection.onreconnecting(callback);
293
+ }
294
+ onReconnected(callback) {
295
+ this._hubConnection.onreconnected(callback);
296
+ }
297
+ async invoke(methodName, ...args) {
298
+ const preparedArgs = await this._prepareOutgoingArgs(args);
299
+ const msg = {
300
+ Method: methodName,
301
+ Arguments: preparedArgs,
302
+ Authorization: this._accessTokenFactory()
303
+ };
304
+ return this._hubConnection.invoke("InvokeMessageResult", msg).catch((err) => Promise.reject(this._extractException(err)));
305
+ }
306
+ async send(methodName, ...args) {
307
+ const preparedArgs = await this._prepareOutgoingArgs(args);
308
+ const msg = {
309
+ Method: methodName,
310
+ Arguments: preparedArgs,
311
+ Authorization: this._accessTokenFactory()
312
+ };
313
+ return this._hubConnection.send("SendMessage", msg);
314
+ }
315
+ stream(methodName, ...args) {
316
+ const msg = {
317
+ Method: methodName,
318
+ Arguments: args,
319
+ Authorization: this._accessTokenFactory()
320
+ };
321
+ return this._hubConnection.stream("StreamMessage", msg);
322
+ }
323
+ on(methodName, newMethod) {
324
+ this._hubConnection.on(methodName, newMethod);
325
+ }
326
+ /** Register a handler for server-to-client method calls (single return value). */
327
+ onServerMethod(methodName, func) {
328
+ this._serverRequestHandlers.set(methodName, func);
329
+ return this;
330
+ }
331
+ /** Register a handler for server-to-client streaming calls (returns AsyncIterable). */
332
+ onServerStreamMethod(methodName, func) {
333
+ this._serverStreamHandlers.set(methodName, func);
334
+ return this;
335
+ }
336
+ off(methodName, method) {
337
+ if (!method) {
338
+ this._hubConnection.off(methodName);
339
+ } else {
340
+ this._hubConnection.off(methodName, method);
341
+ }
342
+ }
343
+ asSignalRHubConnection() {
344
+ return this._hubConnection;
345
+ }
346
+ static create(hubConnection, options) {
347
+ if (hubConnection instanceof Function) {
348
+ const builder = new signalR.HubConnectionBuilder();
349
+ hubConnection(builder);
350
+ return new _HARRRConnection(builder.build(), options);
351
+ }
352
+ return new _HARRRConnection(hubConnection, options);
353
+ }
354
+ _extractException(error) {
355
+ const parsed = parseHARRRError(error);
356
+ return { type: parsed.Type, message: parsed.Message };
357
+ }
358
+ };
359
+ function isNodeBuffer(value) {
360
+ return typeof globalThis !== "undefined" && typeof globalThis["Buffer"] === "function" && typeof globalThis["Buffer"]["isBuffer"] === "function" && globalThis["Buffer"].isBuffer(value);
361
+ }
362
+
363
+ // src/harrr-connection-options.ts
364
+ var HARRRConnectionOptions = class {
365
+ };
366
+ // Annotate the CommonJS export names for ESM import in node:
367
+ 0 && (module.exports = {
368
+ HARRRConnection,
369
+ HARRRConnectionOptions,
370
+ isStreamReference,
371
+ parseHARRRError,
372
+ resolveStreamReference,
373
+ resolveStreamReferenceAsStream
374
+ });
375
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/harrr-connection.ts","../src/models/cancellation-token-reference.ts","../src/models/stream-reference.ts","../src/models/harrr-error.ts","../src/cancellation-manager.ts","../src/harrr-connection-options.ts"],"sourcesContent":["export { HARRRConnection } from './harrr-connection.js';\nexport { HARRRConnectionOptions } from './harrr-connection-options.js';\nexport type { ClientRequestMessage } from './models/client-request-message.js';\nexport type { ServerRequestMessage } from './models/server-request-message.js';\nexport type { CancellationTokenReference } from './models/cancellation-token-reference.js';\nexport type { StreamReference } from './models/stream-reference.js';\nexport { isStreamReference, resolveStreamReference, resolveStreamReferenceAsStream } from './models/stream-reference.js';\nexport type { HARRRError } from './models/harrr-error.js';\nexport { parseHARRRError } from './models/harrr-error.js';\n","import * as signalR from '@microsoft/signalr';\nimport { ClientRequestMessage } from './models/client-request-message.js';\nimport { ServerRequestMessage } from './models/server-request-message.js';\nimport { isCancellationTokenReference } from './models/cancellation-token-reference.js';\nimport { isStreamReference, resolveStreamReference } from './models/stream-reference.js';\nimport { parseHARRRError } from './models/harrr-error.js';\nimport { HARRRConnectionOptions } from './harrr-connection-options.js';\nimport { CancellationManager } from './cancellation-manager.js';\n\nexport class HARRRConnection {\n private _hubConnection: signalR.HubConnection;\n private _accessTokenFactory: () => string = () => '';\n private _serverRequestHandlers = new Map<string, (...args: unknown[]) => unknown>();\n private _serverStreamHandlers = new Map<string, (...args: unknown[]) => AsyncIterable<unknown>>();\n private _cancellationManager = new CancellationManager();\n\n public get baseUrl(): string {\n return this._hubConnection.baseUrl;\n }\n\n public set baseUrl(value: string) {\n this._hubConnection.baseUrl = value;\n }\n\n public get connectionId(): string | null {\n return this._hubConnection.connectionId;\n }\n\n public get state(): signalR.HubConnectionState {\n return this._hubConnection.state;\n }\n\n public get serverTimeoutInMilliseconds(): number {\n return this._hubConnection.serverTimeoutInMilliseconds;\n }\n\n public set serverTimeoutInMilliseconds(value: number) {\n this._hubConnection.serverTimeoutInMilliseconds = value;\n }\n\n public get keepAliveIntervalInMilliseconds(): number {\n return this._hubConnection.keepAliveIntervalInMilliseconds;\n }\n\n public set keepAliveIntervalInMilliseconds(value: number) {\n this._hubConnection.keepAliveIntervalInMilliseconds = value;\n }\n\n constructor(hubConnection: signalR.HubConnection, _options?: HARRRConnectionOptions) {\n this._hubConnection = hubConnection;\n\n const conn = (hubConnection as unknown as Record<string, unknown>)['connection'] as Record<string, unknown> | undefined;\n const factory =\n (conn?.['_options'] as Record<string, unknown> | undefined)?.['accessTokenFactory'] ??\n conn?.['_accessTokenFactory'];\n if (typeof factory === 'function') {\n this._accessTokenFactory = factory as () => string;\n }\n\n // Native client results — return values are sent back to the server automatically by SignalR\n this._hubConnection.on('ChallengeAuthentication', (req: ServerRequestMessage) => {\n return this._accessTokenFactory();\n });\n\n this._hubConnection.on('InvokeServerRequest', async (req: ServerRequestMessage) => {\n // If StreamId is present, stream results back instead of returning a single value\n if (req.StreamId) {\n await this._streamBackToServer(req, req.StreamId);\n return undefined;\n }\n const result = await this._dispatchServerMethod(req);\n\n // If the result is binary data (Blob, ArrayBuffer, Buffer), upload via HTTP\n // and return a StreamReference instead\n if (result instanceof Blob || result instanceof ArrayBuffer ||\n isNodeBuffer(result)) {\n return await this._uploadAndReturnReference(result);\n }\n\n return result;\n });\n\n this._hubConnection.on('InvokeServerMessage', async (req: ServerRequestMessage) => {\n try {\n if (req.StreamId) {\n await this._streamBackToServer(req, req.StreamId);\n } else {\n await this._dispatchServerMethod(req);\n }\n } catch {\n // ignored — fire-and-forget\n }\n });\n\n this._hubConnection.on('CancelTokenFromServer', (req: ServerRequestMessage) => {\n if (req.CancellationGuid) {\n this._cancellationManager.cancel(req.CancellationGuid);\n }\n });\n }\n\n private async _dispatchServerMethod(req: ServerRequestMessage): Promise<unknown> {\n const handler = this._serverRequestHandlers.get(req.Method);\n if (!handler) return undefined;\n\n const args = await this._prepareArgs(req);\n return await handler(...args);\n }\n\n private async _prepareArgs(req: ServerRequestMessage): Promise<unknown[]> {\n const args: unknown[] = [];\n for (const arg of req.Arguments ?? []) {\n if (isCancellationTokenReference(arg) && req.CancellationGuid) {\n args.push(this._cancellationManager.create(req.CancellationGuid));\n } else if (isStreamReference(arg)) {\n // Download the stream data via HTTP and pass as ArrayBuffer\n args.push(await resolveStreamReference(arg));\n } else {\n args.push(arg);\n }\n }\n return args;\n }\n\n private async _streamBackToServer(req: ServerRequestMessage, streamId: string): Promise<void> {\n const args = await this._prepareArgs(req);\n\n try {\n // Try stream handler first\n const streamHandler = this._serverStreamHandlers.get(req.Method);\n if (streamHandler) {\n const stream = streamHandler(...args);\n for await (const item of stream) {\n await this._hubConnection.send('StreamItemToServer', streamId, item);\n }\n await this._hubConnection.send('StreamCompleteToServer', streamId, null);\n return;\n }\n\n // Fall back to regular handler — send single result as one item\n const handler = this._serverRequestHandlers.get(req.Method);\n if (handler) {\n const result = await handler(...args);\n if (result != null) {\n // Check if result is async iterable\n if (typeof result === 'object' && Symbol.asyncIterator in (result as object)) {\n for await (const item of result as AsyncIterable<unknown>) {\n await this._hubConnection.send('StreamItemToServer', streamId, item);\n }\n } else {\n await this._hubConnection.send('StreamItemToServer', streamId, result);\n }\n }\n await this._hubConnection.send('StreamCompleteToServer', streamId, null);\n } else {\n await this._hubConnection.send('StreamCompleteToServer', streamId, null);\n }\n } catch (err) {\n await this._hubConnection.send('StreamCompleteToServer', streamId, String(err));\n }\n }\n\n private async _uploadAndReturnReference(data: Blob | ArrayBuffer | Uint8Array | unknown): Promise<{ Uri: string }> {\n // Request an upload URL from the server\n const uploadUrl = await this._hubConnection.invoke<string>('RequestUploadSlot');\n\n // Upload the data via HTTP POST\n let body: BodyInit;\n if (data instanceof Blob) {\n body = data;\n } else if (data instanceof ArrayBuffer || data instanceof Uint8Array) {\n body = data as BodyInit;\n } else {\n body = String(data);\n }\n await fetch(uploadUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/octet-stream' },\n body,\n });\n\n return { Uri: uploadUrl };\n }\n\n /** Prepare outgoing arguments — upload binary data and replace with StreamReferences. */\n private async _prepareOutgoingArgs(args: unknown[]): Promise<unknown[]> {\n let hasStream = false;\n for (const arg of args) {\n if (arg instanceof Blob || arg instanceof ArrayBuffer ||\n isNodeBuffer(arg)) {\n hasStream = true;\n break;\n }\n }\n if (!hasStream) return args;\n\n const result: unknown[] = [];\n for (const arg of args) {\n if (arg instanceof Blob || arg instanceof ArrayBuffer ||\n isNodeBuffer(arg)) {\n result.push(await this._uploadAndReturnReference(arg));\n } else {\n result.push(arg);\n }\n }\n return result;\n }\n\n public start(): Promise<void> {\n return this._hubConnection.start();\n }\n\n public stop(): Promise<void> {\n return this._hubConnection.stop();\n }\n\n public onClose(callback: (error?: Error) => void): void {\n this._hubConnection.onclose(callback);\n }\n\n public onReconnecting(callback: (error?: Error) => void): void {\n this._hubConnection.onreconnecting(callback);\n }\n\n public onReconnected(callback: (connectionId?: string) => void): void {\n this._hubConnection.onreconnected(callback);\n }\n\n public async invoke<T>(methodName: string, ...args: unknown[]): Promise<T> {\n const preparedArgs = await this._prepareOutgoingArgs(args);\n const msg: ClientRequestMessage = {\n Method: methodName,\n Arguments: preparedArgs,\n Authorization: this._accessTokenFactory(),\n };\n return this._hubConnection\n .invoke<T>('InvokeMessageResult', msg)\n .catch(err => Promise.reject(this._extractException(err)));\n }\n\n public async send(methodName: string, ...args: unknown[]): Promise<void> {\n const preparedArgs = await this._prepareOutgoingArgs(args);\n const msg: ClientRequestMessage = {\n Method: methodName,\n Arguments: preparedArgs,\n Authorization: this._accessTokenFactory(),\n };\n return this._hubConnection.send('SendMessage', msg);\n }\n\n public stream<T>(methodName: string, ...args: unknown[]): signalR.IStreamResult<T> {\n const msg: ClientRequestMessage = {\n Method: methodName,\n Arguments: args,\n Authorization: this._accessTokenFactory(),\n };\n return this._hubConnection.stream<T>('StreamMessage', msg);\n }\n\n public on(methodName: string, newMethod: (...args: any[]) => void): void {\n this._hubConnection.on(methodName, newMethod);\n }\n\n /** Register a handler for server-to-client method calls (single return value). */\n public onServerMethod(methodName: string, func: (...args: unknown[]) => unknown): this {\n this._serverRequestHandlers.set(methodName, func);\n return this;\n }\n\n /** Register a handler for server-to-client streaming calls (returns AsyncIterable). */\n public onServerStreamMethod(methodName: string, func: (...args: unknown[]) => AsyncIterable<unknown>): this {\n this._serverStreamHandlers.set(methodName, func);\n return this;\n }\n\n public off(methodName: string): void;\n public off(methodName: string, method: (...args: any[]) => void): void;\n public off(methodName: string, method?: (...args: any[]) => void): void {\n if (!method) {\n this._hubConnection.off(methodName);\n } else {\n this._hubConnection.off(methodName, method);\n }\n }\n\n public asSignalRHubConnection(): signalR.HubConnection {\n return this._hubConnection;\n }\n\n public static create(\n hubConnection: signalR.HubConnection | ((builder: signalR.HubConnectionBuilder) => void),\n options?: HARRRConnectionOptions,\n ): HARRRConnection {\n if (hubConnection instanceof Function) {\n const builder = new signalR.HubConnectionBuilder();\n hubConnection(builder);\n return new HARRRConnection(builder.build(), options);\n }\n return new HARRRConnection(hubConnection, options);\n }\n\n private _extractException(error: unknown): { type: string; message: string } {\n const parsed = parseHARRRError(error);\n return { type: parsed.Type, message: parsed.Message };\n }\n}\n\n/** Runtime check for Node.js Buffer without importing @types/node */\nfunction isNodeBuffer(value: unknown): boolean {\n return typeof globalThis !== 'undefined' &&\n typeof (globalThis as Record<string, unknown>)['Buffer'] === 'function' &&\n typeof ((globalThis as Record<string, unknown>)['Buffer'] as Record<string, unknown>)['isBuffer'] === 'function' &&\n ((globalThis as Record<string, unknown>)['Buffer'] as { isBuffer: (v: unknown) => boolean }).isBuffer(value);\n}\n","export interface CancellationTokenReference {\n Id: string;\n}\n\nexport function isCancellationTokenReference(v: unknown): v is CancellationTokenReference {\n return typeof v === 'object' && v !== null && typeof (v as Record<string, unknown>)['Id'] === 'string';\n}\n","export interface StreamReference {\n Uri: string;\n}\n\nexport function isStreamReference(v: unknown): v is StreamReference {\n if (typeof v !== 'object' || v === null) return false;\n const obj = v as Record<string, unknown>;\n return typeof obj['Uri'] === 'string' && Object.keys(obj).length === 1;\n}\n\n/** Resolve a StreamReference by downloading the data — returns the full content buffered in memory. */\nexport async function resolveStreamReference(ref: StreamReference): Promise<ArrayBuffer> {\n const response = await fetchStreamReference(ref);\n return response.arrayBuffer();\n}\n\n/** Resolve a StreamReference as a ReadableStream — for large files, avoids buffering in memory. */\nexport async function resolveStreamReferenceAsStream(ref: StreamReference): Promise<ReadableStream<Uint8Array>> {\n const response = await fetchStreamReference(ref);\n if (!response.body) {\n throw new Error('StreamReference: response has no body stream');\n }\n return response.body;\n}\n\nasync function fetchStreamReference(ref: StreamReference): Promise<Response> {\n const url = ref.Uri;\n const scheme = url.split(':')[0]?.toLowerCase();\n if (scheme !== 'http' && scheme !== 'https') {\n throw new Error(`StreamReference: unsupported URI scheme '${scheme}'`);\n }\n const response = await fetch(url);\n if (!response.ok) {\n throw new Error(`StreamReference: download failed (${response.status} ${response.statusText})`);\n }\n return response;\n}\n","/**\n * Structured error envelope from SignalARRR server exceptions.\n * The server serializes exceptions as JSON in the HubException message string.\n */\nexport interface HARRRError {\n Type: string;\n Message: string;\n StackTrace?: string;\n}\n\n/**\n * Parse a HubException message into a structured HARRRError.\n * Supports both the new JSON format and the legacy `[Type] Message` format.\n *\n * SignalR wraps HubException messages with prefix text like:\n * \"An unexpected error occurred invoking '...' on the server. HARRRException: {json}\"\n */\nexport function parseHARRRError(error: unknown): HARRRError {\n const msg = error instanceof Error ? error.message : String(error);\n\n // Extract JSON after \"HARRRException: \" marker (SignalR wrapping)\n const marker = 'HARRRException: ';\n const markerIndex = msg.indexOf(marker);\n const jsonCandidate = markerIndex >= 0 ? msg.substring(markerIndex + marker.length) : msg;\n\n // Try JSON format\n try {\n const parsed = JSON.parse(jsonCandidate);\n if (typeof parsed === 'object' && parsed !== null && typeof parsed.Type === 'string' && typeof parsed.Message === 'string') {\n return parsed as HARRRError;\n }\n } catch {\n // Not JSON — try legacy format\n }\n\n // Legacy format: [Type] Message\n const matches = /\\[([\\w.]+)\\]\\s*(.*)/m.exec(msg);\n if (matches) {\n return {\n Type: matches[1] ?? 'Error',\n Message: matches[2] ?? msg,\n };\n }\n\n // Fallback\n return {\n Type: 'Error',\n Message: msg,\n };\n}\n","export class CancellationManager {\n private _controllers = new Map<string, AbortController>();\n\n create(id: string): AbortSignal {\n const controller = new AbortController();\n this._controllers.set(id, controller);\n return controller.signal;\n }\n\n cancel(id: string): void {\n const controller = this._controllers.get(id);\n if (controller) {\n controller.abort();\n this._controllers.delete(id);\n }\n }\n\n remove(id: string): void {\n this._controllers.delete(id);\n }\n}\n","export class HARRRConnectionOptions {}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,cAAyB;;;ACIlB,SAAS,6BAA6B,GAA6C;AACxF,SAAO,OAAO,MAAM,YAAY,MAAM,QAAQ,OAAQ,EAA8B,IAAI,MAAM;AAChG;;;ACFO,SAAS,kBAAkB,GAAkC;AAClE,MAAI,OAAO,MAAM,YAAY,MAAM,KAAM,QAAO;AAChD,QAAM,MAAM;AACZ,SAAO,OAAO,IAAI,KAAK,MAAM,YAAY,OAAO,KAAK,GAAG,EAAE,WAAW;AACvE;AAGA,eAAsB,uBAAuB,KAA4C;AACvF,QAAM,WAAW,MAAM,qBAAqB,GAAG;AAC/C,SAAO,SAAS,YAAY;AAC9B;AAGA,eAAsB,+B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aAAO,IAAI,iBAAgB,QAAQ,MAAM,GAAG,OAAO;AAAA,IACrD;AACA,WAAO,IAAI,iBAAgB,eAAe,OAAO;AAAA,EACnD;AAAA,EAEQ,kBAAkB,OAAmD;AAC3E,UAAM,SAAS,gBAAgB,KAAK;AACpC,WAAO,EAAE,MAAM,OAAO,MAAM,SAAS,OAAO,QAAQ;AAAA,EACtD;AACF;AAGA,SAAS,aAAa,OAAyB;AAC7C,SAAO,OAAO,eAAe,eAC3B,OAAQ,WAAuC,QAAQ,MAAM,cAC7D,OAAS,WAAuC,QAAQ,EAA8B,UAAU,MAAM,cACpG,WAAuC,QAAQ,EAA4C,SAAS,KAAK;AAC/G;;;AKzTO,IAAM,yBAAN,MAA6B;AAAC;","names":[]}
@@ -0,0 +1,94 @@
1
+ import * as signalR from '@microsoft/signalr';
2
+
3
+ declare class HARRRConnectionOptions {
4
+ }
5
+
6
+ declare class HARRRConnection {
7
+ private _hubConnection;
8
+ private _accessTokenFactory;
9
+ private _serverRequestHandlers;
10
+ private _serverStreamHandlers;
11
+ private _cancellationManager;
12
+ get baseUrl(): string;
13
+ set baseUrl(value: string);
14
+ get connectionId(): string | null;
15
+ get state(): signalR.HubConnectionState;
16
+ get serverTimeoutInMilliseconds(): number;
17
+ set serverTimeoutInMilliseconds(value: number);
18
+ get keepAliveIntervalInMilliseconds(): number;
19
+ set keepAliveIntervalInMilliseconds(value: number);
20
+ constructor(hubConnection: signalR.HubConnection, _options?: HARRRConnectionOptions);
21
+ private _dispatchServerMethod;
22
+ private _prepareArgs;
23
+ private _streamBackToServer;
24
+ private _uploadAndReturnReference;
25
+ /** Prepare outgoing arguments — upload binary data and replace with StreamReferences. */
26
+ private _prepareOutgoingArgs;
27
+ start(): Promise<void>;
28
+ stop(): Promise<void>;
29
+ onClose(callback: (error?: Error) => void): void;
30
+ onReconnecting(callback: (error?: Error) => void): void;
31
+ onReconnected(callback: (connectionId?: string) => void): void;
32
+ invoke<T>(methodName: string, ...args: unknown[]): Promise<T>;
33
+ send(methodName: string, ...args: unknown[]): Promise<void>;
34
+ stream<T>(methodName: string, ...args: unknown[]): signalR.IStreamResult<T>;
35
+ on(methodName: string, newMethod: (...args: any[]) => void): void;
36
+ /** Register a handler for server-to-client method calls (single return value). */
37
+ onServerMethod(methodName: string, func: (...args: unknown[]) => unknown): this;
38
+ /** Register a handler for server-to-client streaming calls (returns AsyncIterable). */
39
+ onServerStreamMethod(methodName: string, func: (...args: unknown[]) => AsyncIterable<unknown>): this;
40
+ off(methodName: string): void;
41
+ off(methodName: string, method: (...args: any[]) => void): void;
42
+ asSignalRHubConnection(): signalR.HubConnection;
43
+ static create(hubConnection: signalR.HubConnection | ((builder: signalR.HubConnectionBuilder) => void), options?: HARRRConnectionOptions): HARRRConnection;
44
+ private _extractException;
45
+ }
46
+
47
+ interface ClientRequestMessage {
48
+ Method: string;
49
+ Arguments: unknown[];
50
+ Authorization?: string;
51
+ GenericArguments?: string[];
52
+ }
53
+
54
+ interface ServerRequestMessage {
55
+ Id: string;
56
+ Method: string;
57
+ Arguments?: unknown[];
58
+ GenericArguments?: string[];
59
+ CancellationGuid?: string;
60
+ StreamId?: string;
61
+ }
62
+
63
+ interface CancellationTokenReference {
64
+ Id: string;
65
+ }
66
+
67
+ interface StreamReference {
68
+ Uri: string;
69
+ }
70
+ declare function isStreamReference(v: unknown): v is StreamReference;
71
+ /** Resolve a StreamReference by downloading the data — returns the full content buffered in memory. */
72
+ declare function resolveStreamReference(ref: StreamReference): Promise<ArrayBuffer>;
73
+ /** Resolve a StreamReference as a ReadableStream — for large files, avoids buffering in memory. */
74
+ declare function resolveStreamReferenceAsStream(ref: StreamReference): Promise<ReadableStream<Uint8Array>>;
75
+
76
+ /**
77
+ * Structured error envelope from SignalARRR server exceptions.
78
+ * The server serializes exceptions as JSON in the HubException message string.
79
+ */
80
+ interface HARRRError {
81
+ Type: string;
82
+ Message: string;
83
+ StackTrace?: string;
84
+ }
85
+ /**
86
+ * Parse a HubException message into a structured HARRRError.
87
+ * Supports both the new JSON format and the legacy `[Type] Message` format.
88
+ *
89
+ * SignalR wraps HubException messages with prefix text like:
90
+ * "An unexpected error occurred invoking '...' on the server. HARRRException: {json}"
91
+ */
92
+ declare function parseHARRRError(error: unknown): HARRRError;
93
+
94
+ export { type CancellationTokenReference, type ClientRequestMessage, HARRRConnection, HARRRConnectionOptions, type HARRRError, type ServerRequestMessage, type StreamReference, isStreamReference, parseHARRRError, resolveStreamReference, resolveStreamReferenceAsStream };
@@ -0,0 +1,94 @@
1
+ import * as signalR from '@microsoft/signalr';
2
+
3
+ declare class HARRRConnectionOptions {
4
+ }
5
+
6
+ declare class HARRRConnection {
7
+ private _hubConnection;
8
+ private _accessTokenFactory;
9
+ private _serverRequestHandlers;
10
+ private _serverStreamHandlers;
11
+ private _cancellationManager;
12
+ get baseUrl(): string;
13
+ set baseUrl(value: string);
14
+ get connectionId(): string | null;
15
+ get state(): signalR.HubConnectionState;
16
+ get serverTimeoutInMilliseconds(): number;
17
+ set serverTimeoutInMilliseconds(value: number);
18
+ get keepAliveIntervalInMilliseconds(): number;
19
+ set keepAliveIntervalInMilliseconds(value: number);
20
+ constructor(hubConnection: signalR.HubConnection, _options?: HARRRConnectionOptions);
21
+ private _dispatchServerMethod;
22
+ private _prepareArgs;
23
+ private _streamBackToServer;
24
+ private _uploadAndReturnReference;
25
+ /** Prepare outgoing arguments — upload binary data and replace with StreamReferences. */
26
+ private _prepareOutgoingArgs;
27
+ start(): Promise<void>;
28
+ stop(): Promise<void>;
29
+ onClose(callback: (error?: Error) => void): void;
30
+ onReconnecting(callback: (error?: Error) => void): void;
31
+ onReconnected(callback: (connectionId?: string) => void): void;
32
+ invoke<T>(methodName: string, ...args: unknown[]): Promise<T>;
33
+ send(methodName: string, ...args: unknown[]): Promise<void>;
34
+ stream<T>(methodName: string, ...args: unknown[]): signalR.IStreamResult<T>;
35
+ on(methodName: string, newMethod: (...args: any[]) => void): void;
36
+ /** Register a handler for server-to-client method calls (single return value). */
37
+ onServerMethod(methodName: string, func: (...args: unknown[]) => unknown): this;
38
+ /** Register a handler for server-to-client streaming calls (returns AsyncIterable). */
39
+ onServerStreamMethod(methodName: string, func: (...args: unknown[]) => AsyncIterable<unknown>): this;
40
+ off(methodName: string): void;
41
+ off(methodName: string, method: (...args: any[]) => void): void;
42
+ asSignalRHubConnection(): signalR.HubConnection;
43
+ static create(hubConnection: signalR.HubConnection | ((builder: signalR.HubConnectionBuilder) => void), options?: HARRRConnectionOptions): HARRRConnection;
44
+ private _extractException;
45
+ }
46
+
47
+ interface ClientRequestMessage {
48
+ Method: string;
49
+ Arguments: unknown[];
50
+ Authorization?: string;
51
+ GenericArguments?: string[];
52
+ }
53
+
54
+ interface ServerRequestMessage {
55
+ Id: string;
56
+ Method: string;
57
+ Arguments?: unknown[];
58
+ GenericArguments?: string[];
59
+ CancellationGuid?: string;
60
+ StreamId?: string;
61
+ }
62
+
63
+ interface CancellationTokenReference {
64
+ Id: string;
65
+ }
66
+
67
+ interface StreamReference {
68
+ Uri: string;
69
+ }
70
+ declare function isStreamReference(v: unknown): v is StreamReference;
71
+ /** Resolve a StreamReference by downloading the data — returns the full content buffered in memory. */
72
+ declare function resolveStreamReference(ref: StreamReference): Promise<ArrayBuffer>;
73
+ /** Resolve a StreamReference as a ReadableStream — for large files, avoids buffering in memory. */
74
+ declare function resolveStreamReferenceAsStream(ref: StreamReference): Promise<ReadableStream<Uint8Array>>;
75
+
76
+ /**
77
+ * Structured error envelope from SignalARRR server exceptions.
78
+ * The server serializes exceptions as JSON in the HubException message string.
79
+ */
80
+ interface HARRRError {
81
+ Type: string;
82
+ Message: string;
83
+ StackTrace?: string;
84
+ }
85
+ /**
86
+ * Parse a HubException message into a structured HARRRError.
87
+ * Supports both the new JSON format and the legacy `[Type] Message` format.
88
+ *
89
+ * SignalR wraps HubException messages with prefix text like:
90
+ * "An unexpected error occurred invoking '...' on the server. HARRRException: {json}"
91
+ */
92
+ declare function parseHARRRError(error: unknown): HARRRError;
93
+
94
+ export { type CancellationTokenReference, type ClientRequestMessage, HARRRConnection, HARRRConnectionOptions, type HARRRError, type ServerRequestMessage, type StreamReference, isStreamReference, parseHARRRError, resolveStreamReference, resolveStreamReferenceAsStream };