@synnaxlabs/freighter 0.32.0 → 0.34.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,KAAK,MAAM,EAAW,KAAK,GAAG,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,CAAC;AAG7B,OAAO,EAAgB,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,eAAO,MAAM,uBAAuB,iBAAiB,CAAC;AAYtD;;;;;;GAMG;AACH,qBAAa,UAAW,SAAQ,mBAAoB,YAAW,WAAW;IACxE,QAAQ,EAAE,GAAG,CAAC;IACd,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC;IACtB,KAAK,EAAE,OAAO,KAAK,CAAC;gBAER,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,GAAE,OAAe;IAczE,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAIpC;IAEK,IAAI,CAAC,EAAE,SAAS,CAAC,CAAC,UAAU,EAAE,EAAE,SAAS,CAAC,CAAC,UAAU,GAAG,EAAE,EAC9D,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,EAC/B,SAAS,EAAE,EAAE,EACb,SAAS,EAAE,EAAE,GACZ,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC,CAAC;CAuDhD"}
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],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AAiB;IAE7C;;;;OAIG;gBACS,YAAY,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,UAAQ;IAMpE,6CAA6C;IACvC,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC,UAAU,EAAE,EAAE,SAAS,CAAC,CAAC,UAAU,GAAG,EAAE,EAChE,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,EAAE,EACb,SAAS,EAAE,EAAE,GACZ,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAmB1B,OAAO,CAAC,QAAQ;YAWF,UAAU;CAezB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synnaxlabs/freighter",
3
- "version": "0.32.0",
3
+ "version": "0.34.0",
4
4
  "type": "module",
5
5
  "description": "a modular transport abstraction",
6
6
  "repository": "https://github.com/synnaxlabs/synnax/tree/main/freighter/ts",
@@ -14,24 +14,22 @@
14
14
  "control systems"
15
15
  ],
16
16
  "dependencies": {
17
- "node-fetch": "2.6.11",
17
+ "node-fetch": "^2.7.0",
18
18
  "ws": "^8.18.0",
19
- "zod": "3.23.8",
20
- "@synnaxlabs/alamos": "0.32.0",
21
- "@synnaxlabs/x": "0.32.0"
19
+ "zod": "^3.23.8",
20
+ "@synnaxlabs/alamos": "0.34.0",
21
+ "@synnaxlabs/x": "0.34.0"
22
22
  },
23
23
  "devDependencies": {
24
- "@types/node": "^22.5.4",
25
- "@vitest/coverage-v8": "^2.1.0",
26
- "typescript": "^5.6.2",
27
- "vite": "5.4.4",
28
- "vitest": "^2.1.0",
29
- "@synnaxlabs/tsconfig": "0.0.2",
24
+ "@types/node": "^22.7.5",
25
+ "@vitest/coverage-v8": "^2.1.4",
26
+ "eslint": "^9.12.0",
27
+ "typescript": "^5.6.3",
28
+ "vite": "^5.4.10",
29
+ "vitest": "^2.1.4",
30
30
  "@synnaxlabs/vite-plugin": "0.0.1",
31
- "eslint-config-synnaxlabs": "0.0.1"
32
- },
33
- "peerDependencies": {
34
- "zod": "3.23.8"
31
+ "eslint-config-synnaxlabs": "0.0.1",
32
+ "@synnaxlabs/tsconfig": "0.0.2"
35
33
  },
36
34
  "main": "dist/freighter.cjs",
37
35
  "module": "dist/freighter.js",
@@ -41,7 +39,7 @@
41
39
  "watch": "tsc --noEmit && vite build --watch",
42
40
  "test": "vitest",
43
41
  "cov": "vitest --coverage",
44
- "lint": "eslint \"src/**/*.ts*\"",
45
- "fix": "eslint \"src/**/*.ts*\" --fix"
42
+ "lint": "eslint --cache",
43
+ "fix": "eslint --cache --fix"
46
44
  }
47
45
  }
@@ -29,9 +29,6 @@ import {
29
29
 
30
30
  class MyCustomError extends BaseTypedError {
31
31
  type = "MyCustomError";
32
- constructor(message: string) {
33
- super(message);
34
- }
35
32
  }
36
33
 
37
34
  const myCustomErrorEncoder = (error: MyCustomError): ErrorPayload | null => {
@@ -39,9 +36,8 @@ const myCustomErrorEncoder = (error: MyCustomError): ErrorPayload | null => {
39
36
  return { type: "MyCustomError", data: error.message };
40
37
  };
41
38
 
42
- const myCustomErrorDecoder = (encoded: ErrorPayload): TypedError => {
43
- return new MyCustomError(encoded.data);
44
- };
39
+ const myCustomErrorDecoder = (encoded: ErrorPayload): TypedError =>
40
+ new MyCustomError(encoded.data);
45
41
 
46
42
  describe("errors", () => {
47
43
  test("isTypedError", () => {
package/src/errors.ts CHANGED
@@ -46,10 +46,6 @@ export const errorMatcher =
46
46
  export class BaseTypedError extends Error implements TypedError {
47
47
  readonly discriminator = "FreighterError";
48
48
  type: string = "";
49
-
50
- constructor(message?: string) {
51
- super(message);
52
- }
53
49
  }
54
50
 
55
51
  type ErrorDecoder = (encoded: ErrorPayload) => Error | null;
@@ -100,12 +96,11 @@ class Registry {
100
96
 
101
97
  encode(error: unknown): ErrorPayload {
102
98
  if (error == null) return { type: NONE, data: "" };
103
- if (isTypedError(error)) {
99
+ if (isTypedError(error))
104
100
  for (const provider of this.providers) {
105
101
  const payload = provider.encode(error);
106
102
  if (payload != null) return payload;
107
103
  }
108
- }
109
104
  return { type: UNKNOWN, data: JSON.stringify(error) };
110
105
  }
111
106
 
@@ -144,9 +139,7 @@ export const registerError = ({
144
139
  * @param error - The error to encode.
145
140
  * @returns The encoded error.
146
141
  */
147
- export const encodeError = (error: unknown): ErrorPayload => {
148
- return REGISTRY.encode(error);
149
- };
142
+ export const encodeError = (error: unknown): ErrorPayload => REGISTRY.encode(error);
150
143
 
151
144
  /**
152
145
  * Decodes an error payload into an exception. If a custom decoder can be found
@@ -156,22 +149,18 @@ export const encodeError = (error: unknown): ErrorPayload => {
156
149
  * @param payload - The encoded error payload.
157
150
  * @returns The decoded error.
158
151
  */
159
- export const decodeError = (payload: ErrorPayload): Error | null => {
160
- return REGISTRY.decode(payload);
161
- };
152
+ export const decodeError = (payload: ErrorPayload): Error | null =>
153
+ REGISTRY.decode(payload);
162
154
 
163
155
  export class UnknownError extends BaseTypedError implements TypedError {
164
156
  type = "unknown";
165
- constructor(message: string) {
166
- super(message);
167
- }
168
157
  }
169
158
 
170
159
  const FREIGHTER_ERROR_TYPE = "freighter.";
171
160
 
172
161
  /** Thrown/returned when a stream closed normally. */
173
162
  export class EOF extends BaseTypedError implements TypedError {
174
- static readonly TYPE = FREIGHTER_ERROR_TYPE + "eof";
163
+ static readonly TYPE = `${FREIGHTER_ERROR_TYPE}eof`;
175
164
  type = EOF.TYPE;
176
165
  static readonly matches = errorMatcher(EOF.TYPE);
177
166
 
@@ -182,7 +171,7 @@ export class EOF extends BaseTypedError implements TypedError {
182
171
 
183
172
  /** Thrown/returned when a stream is closed abnormally. */
184
173
  export class StreamClosed extends BaseTypedError implements TypedError {
185
- static readonly TYPE = FREIGHTER_ERROR_TYPE + "stream_closed";
174
+ static readonly TYPE = `${FREIGHTER_ERROR_TYPE}stream_closed`;
186
175
  static readonly matches = errorMatcher(StreamClosed.TYPE);
187
176
  type = StreamClosed.TYPE;
188
177
 
@@ -198,7 +187,7 @@ export interface UnreachableArgs {
198
187
 
199
188
  /** Thrown when a target is unreachable. */
200
189
  export class Unreachable extends BaseTypedError implements TypedError {
201
- static readonly TYPE = FREIGHTER_ERROR_TYPE + "unreachable";
190
+ static readonly TYPE = `${FREIGHTER_ERROR_TYPE}unreachable`;
202
191
  type = Unreachable.TYPE;
203
192
  static readonly matches = errorMatcher(Unreachable.TYPE);
204
193
  url: URL;
package/src/http.ts CHANGED
@@ -7,8 +7,6 @@
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
- /* eslint-disable @typescript-eslint/no-var-requires */
11
-
12
10
  import { type binary, runtime, type URL } from "@synnaxlabs/x";
13
11
  import { type z } from "zod";
14
12
 
@@ -20,8 +18,10 @@ export const CONTENT_TYPE_HEADER_KEY = "Content-Type";
20
18
 
21
19
  const resolveFetchAPI = (protocol: "http" | "https"): typeof fetch => {
22
20
  if (runtime.RUNTIME !== "node") return fetch;
21
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
23
22
  const _fetch: typeof fetch = require("node-fetch");
24
23
  if (protocol === "http") return _fetch;
24
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
25
25
  const https = require("https");
26
26
  const agent = new https.Agent({ rejectUnauthorized: false });
27
27
  // @ts-expect-error - TS doesn't know about qhis option
@@ -44,16 +44,15 @@ class MyCustomError extends BaseTypedError {
44
44
  }
45
45
 
46
46
  const encodeTestError = (err: TypedError): ErrorPayload => {
47
- if (!(err instanceof MyCustomError)) {
48
- throw new Error("Unexpected error type");
49
- }
47
+ if (!(err instanceof MyCustomError)) throw new Error("Unexpected error type");
48
+
50
49
  return { type: "integration.error", data: `${err.code},${err.message}` };
51
50
  };
52
51
 
53
52
  const decodeTestError = (encoded: ErrorPayload): TypedError | null => {
54
53
  if (encoded.type !== "integration.error") return null;
55
54
  const [code, message] = encoded.data.split(",");
56
- return new MyCustomError(message, parseInt(code, 10));
55
+ return new MyCustomError(message, parseInt(code));
57
56
  };
58
57
 
59
58
  registerError({
package/src/websocket.ts CHANGED
@@ -13,11 +13,11 @@ import { z } from "zod";
13
13
  import { decodeError, EOF, errorZ, StreamClosed } from "@/errors";
14
14
  import { CONTENT_TYPE_HEADER_KEY } from "@/http";
15
15
  import { type Context, MiddlewareCollector } from "@/middleware";
16
- import type { Stream, StreamClient } from "@/stream";
16
+ import { type Stream, type StreamClient } from "@/stream";
17
17
 
18
18
  const resolveWebSocketConstructor = (): ((target: string) => WebSocket) => {
19
19
  if (runtime.RUNTIME !== "node") return (t) => new WebSocket(t);
20
- // eslint-disable-next-line @typescript-eslint/no-var-requires
20
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
21
21
  return (t) => new (require("ws").WebSocket)(t, { rejectUnauthorized: false });
22
22
  };
23
23