@synnaxlabs/freighter 0.56.0 → 0.56.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/.turbo/turbo-build.log +4 -4
- package/dist/freighter.cjs +7 -7
- package/dist/freighter.js +300 -283
- package/dist/src/alamos.d.ts.map +1 -1
- package/dist/src/errors.d.ts +3 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/http.d.ts.map +1 -1
- package/dist/src/unary.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/alamos.ts +5 -7
- package/src/errors.ts +5 -2
- package/src/http.ts +15 -6
- package/src/unary.ts +5 -4
- package/src/websocket.ts +2 -2
package/dist/src/alamos.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alamos.d.ts","sourceRoot":"","sources":["../../src/alamos.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"alamos.d.ts","sourceRoot":"","sources":["../../src/alamos.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAG1D,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAE7D,eAAO,MAAM,UAAU,GACpB,iBAAiB,eAAe,KAAG,UAuBnC,CAAC"}
|
package/dist/src/errors.d.ts
CHANGED
|
@@ -25,6 +25,9 @@ export declare class StreamClosed extends StreamClosed_base {
|
|
|
25
25
|
export interface UnreachableArgs {
|
|
26
26
|
message?: string;
|
|
27
27
|
url?: URL;
|
|
28
|
+
/** Underlying error that caused the target to be unreachable (e.g. the original fetch
|
|
29
|
+
* failure). Preserved on Error.cause for stack-trace continuity. */
|
|
30
|
+
cause?: unknown;
|
|
28
31
|
}
|
|
29
32
|
declare const Unreachable_base: errors.TypedClass;
|
|
30
33
|
/** Thrown when a network target is unreachable. */
|
package/dist/src/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;;AAE5C;;GAEG;AACH,qBAAa,cAAe,SAAQ,mBAA+B;CAAG;;AAEtE;;GAEG;AACH,qBAAa,GAAI,SAAQ,QAAyB;;CAIjD;;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,iBAAmC;;CAIpE;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;;AAE5C;;GAEG;AACH,qBAAa,cAAe,SAAQ,mBAA+B;CAAG;;AAEtE;;GAEG;AACH,qBAAa,GAAI,SAAQ,QAAyB;;CAIjD;;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,iBAAmC;;CAIpE;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,GAAG,CAAC;IACV;wEACoE;IACpE,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;;AAED,mDAAmD;AACnD,qBAAa,WAAY,SAAQ,gBAAiC;IAChE,GAAG,EAAE,GAAG,CAAC;gBAEG,IAAI,GAAE,eAAoB;CAKvC"}
|
package/dist/src/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/http.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,MAAM,EAAU,KAAK,GAAG,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,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O,MAAM,uBAAuB,GAAI,KAAK,KAAK,KAAG,OAsBpD,CAAC;AAIF;;;;;;GAMG;AACH,qBAAa,UAAW,SAAQ,mBAAoB,YAAW,WAAW;IACxE,QAAQ,EAAE,GAAG,CAAC;IACd,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC;gBAEV,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,GAAE,OAAe;IAazE,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAIpC;IAEK,IAAI,CAAC,EAAE,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAC,OAAO,GAAG,EAAE,EACxD,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,EAC9B,SAAS,EAAE,EAAE,EACb,SAAS,EAAE,EAAE,GACZ,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;CA2DxB"}
|
package/dist/src/unary.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unary.d.ts","sourceRoot":"","sources":["../../src/unary.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"unary.d.ts","sourceRoot":"","sources":["../../src/unary.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,OAAO,EAAU,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,CAAC;AAI7B,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;;GAGG;AACH,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C;;;;;;;OAOG;IACH,IAAI,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAC,OAAO,GAAG,EAAE,EACpD,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,EAC9B,SAAS,EAAE,EAAE,EACb,SAAS,EAAE,EAAE,KACV,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;CAC3B;AAED,eAAO,MAAM,gBAAgB,GAC3B,MAAM,WAAW,EACjB,KAAK,OAAO,CAAC,MAAM,KAClB,WAgCF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synnaxlabs/freighter",
|
|
3
|
-
"version": "0.56.
|
|
3
|
+
"version": "0.56.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "a modular transport abstraction",
|
|
6
6
|
"repository": "https://github.com/synnaxlabs/synnax/tree/main/freighter/ts",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"zod": "^4.4.3",
|
|
18
18
|
"@synnaxlabs/alamos": "^0.56.0",
|
|
19
|
-
"@synnaxlabs/x": "^0.56.
|
|
19
|
+
"@synnaxlabs/x": "^0.56.1"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/node": "^25.9.0",
|
package/src/alamos.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// included in the file licenses/APL.txt.
|
|
9
9
|
|
|
10
10
|
import { type Instrumentation } from "@synnaxlabs/alamos";
|
|
11
|
+
import { errors } from "@synnaxlabs/x";
|
|
11
12
|
|
|
12
13
|
import { type Context, type Middleware } from "@/middleware";
|
|
13
14
|
|
|
@@ -24,19 +25,16 @@ export const middleware =
|
|
|
24
25
|
return await next(context);
|
|
25
26
|
} catch (err) {
|
|
26
27
|
if (err instanceof Error) span.recordError(err);
|
|
27
|
-
throw err;
|
|
28
|
+
throw errors.fromUnknown(err);
|
|
28
29
|
}
|
|
29
30
|
},
|
|
30
31
|
);
|
|
31
32
|
log(context, instrumentation, null);
|
|
32
33
|
return res;
|
|
33
34
|
} catch (err) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
err instanceof Error ? err : new Error(String(err)),
|
|
38
|
-
);
|
|
39
|
-
throw err;
|
|
35
|
+
const e = errors.fromUnknown(err);
|
|
36
|
+
log(context, instrumentation, e);
|
|
37
|
+
throw e;
|
|
40
38
|
}
|
|
41
39
|
};
|
|
42
40
|
|
package/src/errors.ts
CHANGED
|
@@ -38,6 +38,9 @@ export class StreamClosed extends FreighterError.sub("stream_closed") {
|
|
|
38
38
|
export interface UnreachableArgs {
|
|
39
39
|
message?: string;
|
|
40
40
|
url?: URL;
|
|
41
|
+
/** Underlying error that caused the target to be unreachable (e.g. the original fetch
|
|
42
|
+
* failure). Preserved on Error.cause for stack-trace continuity. */
|
|
43
|
+
cause?: unknown;
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
/** Thrown when a network target is unreachable. */
|
|
@@ -45,8 +48,8 @@ export class Unreachable extends FreighterError.sub("unreachable") {
|
|
|
45
48
|
url: URL;
|
|
46
49
|
|
|
47
50
|
constructor(args: UnreachableArgs = {}) {
|
|
48
|
-
const { message = "Unreachable", url = URL.UNKNOWN } = args;
|
|
49
|
-
super(message);
|
|
51
|
+
const { message = "Unreachable", url = URL.UNKNOWN, cause } = args;
|
|
52
|
+
super(message, cause !== undefined ? { cause } : undefined);
|
|
50
53
|
this.url = url;
|
|
51
54
|
}
|
|
52
55
|
}
|
package/src/http.ts
CHANGED
|
@@ -109,8 +109,10 @@ export class HTTPClient extends MiddlewareCollector implements UnaryClient {
|
|
|
109
109
|
try {
|
|
110
110
|
httpRes = await fetch(ctx.target, request);
|
|
111
111
|
} catch (e) {
|
|
112
|
-
|
|
113
|
-
throw shouldCastToUnreachable(
|
|
112
|
+
const err = errors.fromUnknown(e);
|
|
113
|
+
throw shouldCastToUnreachable(err)
|
|
114
|
+
? new Unreachable({ url, cause: err })
|
|
115
|
+
: err;
|
|
114
116
|
}
|
|
115
117
|
const data = await httpRes.arrayBuffer();
|
|
116
118
|
if (httpRes?.ok) {
|
|
@@ -118,18 +120,25 @@ export class HTTPClient extends MiddlewareCollector implements UnaryClient {
|
|
|
118
120
|
return outCtx;
|
|
119
121
|
}
|
|
120
122
|
if (httpRes.status !== HTTP_STATUS_BAD_REQUEST)
|
|
121
|
-
throw new Error(
|
|
123
|
+
throw new Error(
|
|
124
|
+
`[freighter] HTTP ${httpRes.status} from ${ctx.target}: ${httpRes.statusText}`,
|
|
125
|
+
);
|
|
122
126
|
let decoded: Error | null;
|
|
123
127
|
try {
|
|
124
128
|
decoded = errors.decode(this.encoder.decode(data, errors.payloadZ));
|
|
125
129
|
} catch (e) {
|
|
126
|
-
|
|
130
|
+
const err = errors.fromUnknown(e);
|
|
127
131
|
throw new Error(
|
|
128
|
-
`[freighter] - failed to decode error: ${httpRes.statusText}: ${
|
|
132
|
+
`[freighter] - failed to decode error: ${httpRes.statusText}: ${err.message}`,
|
|
129
133
|
{ cause: e },
|
|
130
134
|
);
|
|
131
135
|
}
|
|
132
|
-
throw
|
|
136
|
+
throw (
|
|
137
|
+
decoded ??
|
|
138
|
+
new Error(
|
|
139
|
+
`[freighter] HTTP ${httpRes.status} from ${ctx.target}: ${httpRes.statusText}`,
|
|
140
|
+
)
|
|
141
|
+
);
|
|
133
142
|
},
|
|
134
143
|
);
|
|
135
144
|
|
package/src/unary.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// License, use of this software will be governed by the Apache License, Version 2.0,
|
|
8
8
|
// included in the file licenses/APL.txt.
|
|
9
9
|
|
|
10
|
-
import { breaker } from "@synnaxlabs/x";
|
|
10
|
+
import { breaker, errors } from "@synnaxlabs/x";
|
|
11
11
|
import { type z } from "zod";
|
|
12
12
|
|
|
13
13
|
import { Unreachable } from "@/errors";
|
|
@@ -61,9 +61,10 @@ export const unaryWithBreaker = (
|
|
|
61
61
|
try {
|
|
62
62
|
return await this.wrapped.send(target, req, reqSchema, resSchema);
|
|
63
63
|
} catch (err) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
const e = errors.fromUnknown(err);
|
|
65
|
+
if (!Unreachable.matches(e)) throw e;
|
|
66
|
+
console.warn(`[freighter] ${brk.retryMessage}`, e);
|
|
67
|
+
if (!(await brk.wait())) throw e;
|
|
67
68
|
}
|
|
68
69
|
while (true);
|
|
69
70
|
}
|
package/src/websocket.ts
CHANGED
|
@@ -210,11 +210,11 @@ export class WebSocketClient extends MiddlewareCollector implements StreamClient
|
|
|
210
210
|
oWs
|
|
211
211
|
.receiveOpenAck()
|
|
212
212
|
.then(() => resolve(oWs))
|
|
213
|
-
.catch((err:
|
|
213
|
+
.catch((err: unknown) => reject(errors.fromUnknown(err)));
|
|
214
214
|
};
|
|
215
215
|
ws.onerror = (ev: Event) => {
|
|
216
216
|
const ev_ = ev as ErrorEvent;
|
|
217
|
-
reject(new Error(ev_.message));
|
|
217
|
+
reject(new Error(ev_.message ?? "websocket error", { cause: ev_.error ?? ev }));
|
|
218
218
|
};
|
|
219
219
|
});
|
|
220
220
|
}
|