@synnaxlabs/freighter 0.9.3 → 0.10.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.
- package/.vscode/settings.json +3 -0
- package/dist/alamos.d.ts +4 -2
- package/dist/alamos.d.ts.map +1 -0
- package/dist/errors.d.ts +7 -2
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.spec.d.ts +1 -0
- package/dist/errors.spec.d.ts.map +1 -0
- package/dist/freighter.cjs +1 -1
- package/dist/freighter.cjs.map +1 -1
- package/dist/freighter.js +2620 -3650
- package/dist/freighter.js.map +1 -1
- package/dist/http.d.ts +5 -3
- package/dist/http.d.ts.map +1 -0
- package/dist/http.spec.d.ts +1 -0
- package/dist/http.spec.d.ts.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/middleware.d.ts +1 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/stream.d.ts +4 -2
- package/dist/stream.d.ts.map +1 -0
- package/dist/transport.d.ts +3 -1
- package/dist/transport.d.ts.map +1 -0
- package/dist/unary.d.ts +4 -2
- package/dist/unary.d.ts.map +1 -0
- package/dist/websocket.d.ts +5 -3
- package/dist/websocket.d.ts.map +1 -0
- package/dist/websocket.spec.d.ts +1 -0
- package/dist/websocket.spec.d.ts.map +1 -0
- package/package.json +10 -10
- package/src/errors.spec.ts +1 -1
- package/src/errors.ts +15 -10
- package/src/index.ts +2 -2
- package/src/unary.ts +1 -1
package/dist/http.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type z } from "zod";
|
|
1
|
+
import { UnaryClient } from './unary';
|
|
3
2
|
import { MiddlewareCollector } from './middleware';
|
|
4
|
-
import {
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { URL, binary } from '@synnaxlabs/x';
|
|
5
|
+
|
|
5
6
|
export declare const CONTENT_TYPE_HEADER_KEY = "Content-Type";
|
|
6
7
|
/**
|
|
7
8
|
* HTTPClientFactory provides a POST and GET implementation of the Unary
|
|
@@ -18,3 +19,4 @@ export declare class HTTPClient extends MiddlewareCollector implements UnaryClie
|
|
|
18
19
|
get headers(): Record<string, string>;
|
|
19
20
|
send<RQ extends z.ZodTypeAny, RS extends z.ZodTypeAny = RQ>(target: string, req: z.input<RQ> | z.output<RQ>, reqSchema: RQ, resSchema: RS): Promise<[z.output<RS> | null, Error | null]>;
|
|
20
21
|
}
|
|
22
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAW,KAAK,GAAG,EAAE,KAAK,MAAM,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,cAAc,CAAC;IAC/B,KAAK,EAAE,OAAO,KAAK,CAAC;gBAER,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,cAAc,EAAE,MAAM,GAAE,OAAe;IAclF,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"}
|
package/dist/http.spec.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.spec.d.ts","sourceRoot":"","sources":["../src/http.spec.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { BaseTypedError, decodeError, encodeError, EOF, errorZ, registerError, StreamClosed, Unreachable, } from './errors';
|
|
2
|
-
export type { ErrorPayload
|
|
2
|
+
export type { ErrorPayload, TypedError } from './errors';
|
|
3
3
|
export { HTTPClient } from './http';
|
|
4
|
-
export type { Context
|
|
4
|
+
export type { Context, Middleware, Next } from './middleware';
|
|
5
5
|
export type { Stream, StreamClient } from './stream';
|
|
6
6
|
export type { UnaryClient } from './unary';
|
|
7
7
|
export { sendRequired } from './unary';
|
|
8
8
|
export { WebSocketClient } from './websocket';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EACL,cAAc,EACd,WAAW,EACX,WAAW,EACX,GAAG,EACH,MAAM,EACN,aAAa,EACb,YAAY,EACZ,WAAW,GACZ,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAC9D,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACrD,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/middleware.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AASA;;;;;;;GAOG;AACH,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC;AAED,eAAO,MAAM,KAAK,+BAAgC,CAAC;AACnD,MAAM,MAAM,IAAI,GAAG,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC;AAE1C,sDAAsD;AACtD,MAAM,MAAM,IAAI,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC,OAAO,EAAE,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC;AAEtE;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,OAAO,EAAE,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC;AAExF;;;GAGG;AACH,KAAK,SAAS,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC,OAAO,EAAE,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC;AAEpE;;;GAGG;AACH,qBAAa,mBAAmB;IAC9B,UAAU,EAAE,UAAU,EAAE,CAAM;IAE9B,yCAAyC;IACzC,GAAG,CAAC,GAAG,EAAE,EAAE,UAAU,EAAE,GAAG,IAAI;IAI9B;;;;;;;;OAQG;IACG,iBAAiB,CACrB,GAAG,EAAE,OAAO,EACZ,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,CAAC,OAAO,EAAE,KAAK,GAAG,IAAI,CAAC,CAAC;CAUpC"}
|
package/dist/stream.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Transport } from './transport';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* Interface for an entity that receives a stream of responses.
|
|
5
6
|
*/
|
|
@@ -74,3 +75,4 @@ export interface StreamClient extends Transport {
|
|
|
74
75
|
*/
|
|
75
76
|
stream: <RQ extends z.ZodTypeAny, RS extends z.ZodTypeAny = RQ>(target: string, reqSchema: RQ, resSchema: RS) => Promise<Stream<RQ, RS>>;
|
|
76
77
|
}
|
|
78
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,EAAE,SAAS,CAAC,CAAC,UAAU;IACrD;;;;;;;;OAQG;IACH,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IAE7D;;OAEG;IACH,QAAQ,EAAE,MAAM,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY,CAAC,EAAE,SAAS,CAAC,CAAC,UAAU;IACnD;;;;;;;;;;MAUE;IACF,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,KAAK,GAAG,IAAI,CAAC;CACzD;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB,CAAC,EAAE,SAAS,CAAC,CAAC,UAAU,CAAE,SAAQ,YAAY,CAAC,EAAE,CAAC;IACnF;;;;;;;;OAQG;IACH,SAAS,EAAE,MAAM,IAAI,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC,UAAU,EAAE,EAAE,SAAS,CAAC,CAAC,UAAU,GAAG,EAAE,CAC3E,SAAQ,kBAAkB,CAAC,EAAE,CAAC,EAC5B,cAAc,CAAC,EAAE,CAAC;CAAG;AAEzB;;GAEG;AACH,MAAM,WAAW,YAAa,SAAQ,SAAS;IAC7C;;;;;;;;;;OAUG;IACH,MAAM,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC,UAAU,EAAE,EAAE,SAAS,CAAC,CAAC,UAAU,GAAG,EAAE,EAC5D,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,EAAE,EACb,SAAS,EAAE,EAAE,KACV,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;CAC9B"}
|
package/dist/transport.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Middleware } from './middleware';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Transport is a based interface that represents a general transport for
|
|
4
5
|
* exchanging messages between a client and a server.
|
|
@@ -11,3 +12,4 @@ export interface Transport {
|
|
|
11
12
|
*/
|
|
12
13
|
use: (...mw: Middleware[]) => void;
|
|
13
14
|
}
|
|
15
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB;;;;OAIG;IACH,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE,UAAU,EAAE,KAAK,IAAI,CAAC;CACpC"}
|
package/dist/unary.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Transport } from './transport';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* An interface for an entity that implements a simple request-response
|
|
5
6
|
* transport between two entities.
|
|
@@ -14,3 +15,4 @@ export interface UnaryClient extends Transport {
|
|
|
14
15
|
send: <RQ extends z.ZodTypeAny, RS extends z.ZodTypeAny = RQ>(target: string, req: z.input<RQ> | z.output<RQ>, reqSchema: RQ, resSchema: RS) => Promise<[z.output<RS>, null] | [null, Error]>;
|
|
15
16
|
}
|
|
16
17
|
export declare const sendRequired: <RQ extends z.ZodTypeAny, RS extends z.ZodTypeAny = RQ>(client: UnaryClient, target: string, req: z.input<RQ> | z.output<RQ>, reqSchema: RQ, resSchema: RS) => Promise<z.output<RS>>;
|
|
18
|
+
//# sourceMappingURL=unary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unary.d.ts","sourceRoot":"","sources":["../src/unary.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;;GAGG;AACH,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C;;;;;OAKG;IACH,IAAI,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC,UAAU,EAAE,EAAE,SAAS,CAAC,CAAC,UAAU,GAAG,EAAE,EAC1D,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,KACV,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;CACpD;AAED,eAAO,MAAM,YAAY,kEAIf,WAAW,UACX,MAAM,OACT,EAAE,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,CAAC,aACpB,EAAE,aACF,EAAE,KACZ,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC,CAItB,CAAC"}
|
package/dist/websocket.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { z } from "zod";
|
|
1
|
+
import { Stream, StreamClient } from './stream';
|
|
3
2
|
import { MiddlewareCollector } from './middleware';
|
|
4
|
-
import
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { URL, binary } from '@synnaxlabs/x';
|
|
5
|
+
|
|
5
6
|
export declare const FREIGHTER_METADATA_PREFIX = "freighterctx";
|
|
6
7
|
/**
|
|
7
8
|
* WebSocketClient is an implementation of StreamClient that is backed by
|
|
@@ -22,3 +23,4 @@ export declare class WebSocketClient extends MiddlewareCollector implements Stre
|
|
|
22
23
|
private buildURL;
|
|
23
24
|
private wrapSocket;
|
|
24
25
|
}
|
|
26
|
+
//# sourceMappingURL=websocket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../src/websocket.ts"],"names":[],"mappings":"AASA,OAAO,EAAW,KAAK,GAAG,EAAoB,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EAAE,mBAAmB,EAAgB,MAAM,cAAc,CAAC;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AA4GrD,eAAO,MAAM,yBAAyB,iBAAiB,CAAC;AAQxD;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,mBAAoB,YAAW,YAAY;IAC9E,OAAO,EAAE,GAAG,CAAC;IACb,OAAO,EAAE,MAAM,CAAC,cAAc,CAAC;IAE/B,MAAM,CAAC,QAAQ,CAAC,YAAY,iBAAiB;IAE7C;;;;OAIG;gBACS,YAAY,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,cAAc,EAAE,MAAM,UAAQ;IAM7E,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/dist/websocket.spec.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket.spec.d.ts","sourceRoot":"","sources":["../src/websocket.spec.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synnaxlabs/freighter",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.10.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "a modular transport abstraction",
|
|
7
7
|
"repository": "https://github.com/synnaxlabs/synnax/tree/main/freighter/ts",
|
|
@@ -20,18 +20,18 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"js-convert-case": "^4.2.0",
|
|
23
|
-
"node-fetch": "
|
|
24
|
-
"ws": "^8.
|
|
23
|
+
"node-fetch": "3.3.2",
|
|
24
|
+
"ws": "^8.16.0",
|
|
25
25
|
"zod": "3.22.4",
|
|
26
|
-
"@synnaxlabs/
|
|
27
|
-
"@synnaxlabs/
|
|
26
|
+
"@synnaxlabs/alamos": "0.3.0",
|
|
27
|
+
"@synnaxlabs/x": "0.16.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@types/node": "^20.
|
|
31
|
-
"@vitest/coverage-v8": "^1.
|
|
32
|
-
"typescript": "^5.
|
|
33
|
-
"vite": "
|
|
34
|
-
"vitest": "^1.
|
|
30
|
+
"@types/node": "^20.12.7",
|
|
31
|
+
"@vitest/coverage-v8": "^1.5.0",
|
|
32
|
+
"typescript": "^5.4.5",
|
|
33
|
+
"vite": "5.2.8",
|
|
34
|
+
"vitest": "^1.5.0",
|
|
35
35
|
"@synnaxlabs/tsconfig": "0.0.2",
|
|
36
36
|
"@synnaxlabs/vite-plugin": "0.0.1",
|
|
37
37
|
"eslint-config-synnaxlabs": "0.0.1"
|
package/src/errors.spec.ts
CHANGED
|
@@ -85,7 +85,7 @@ describe("errors", () => {
|
|
|
85
85
|
test("encoding and decoding freighter errors", () => {
|
|
86
86
|
[new EOF(), new StreamClosed(), new Unreachable()].forEach((error) => {
|
|
87
87
|
const encoded = encodeError(error);
|
|
88
|
-
expect(encoded.type
|
|
88
|
+
expect(encoded.type.startsWith(FREIGHTER)).toBeTruthy();
|
|
89
89
|
expect(encoded.data).toEqual(error.message);
|
|
90
90
|
const decoded = decodeError(encoded);
|
|
91
91
|
expect(decoded).toEqual(error);
|
package/src/errors.ts
CHANGED
|
@@ -143,8 +143,12 @@ export class UnknownError extends BaseTypedError implements TypedError {
|
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
+
const FREIGHTER_ERROR_TYPE = "freighter.";
|
|
147
|
+
|
|
146
148
|
/** Thrown/returned when a stream closed normally. */
|
|
147
149
|
export class EOF extends BaseTypedError implements TypedError {
|
|
150
|
+
static readonly TYPE = FREIGHTER_ERROR_TYPE + "eof";
|
|
151
|
+
|
|
148
152
|
constructor() {
|
|
149
153
|
super("EOF", FREIGHTER);
|
|
150
154
|
}
|
|
@@ -152,6 +156,8 @@ export class EOF extends BaseTypedError implements TypedError {
|
|
|
152
156
|
|
|
153
157
|
/** Thrown/returned when a stream is closed abnormally. */
|
|
154
158
|
export class StreamClosed extends BaseTypedError implements TypedError {
|
|
159
|
+
static readonly TYPE = FREIGHTER_ERROR_TYPE + "stream_closed";
|
|
160
|
+
|
|
155
161
|
constructor() {
|
|
156
162
|
super("StreamClosed", FREIGHTER);
|
|
157
163
|
}
|
|
@@ -164,6 +170,7 @@ export interface UnreachableArgs {
|
|
|
164
170
|
|
|
165
171
|
/** Thrown when a target is unreachable. */
|
|
166
172
|
export class Unreachable extends BaseTypedError implements TypedError {
|
|
173
|
+
static readonly TYPE = FREIGHTER_ERROR_TYPE + "unreachable";
|
|
167
174
|
url: URL;
|
|
168
175
|
|
|
169
176
|
constructor(args: UnreachableArgs = {}) {
|
|
@@ -173,26 +180,24 @@ export class Unreachable extends BaseTypedError implements TypedError {
|
|
|
173
180
|
}
|
|
174
181
|
}
|
|
175
182
|
|
|
176
|
-
const FREIGHTER_ERROR_TYPE = "freighter";
|
|
177
|
-
|
|
178
183
|
const freighterErrorEncoder: ErrorEncoder = (error: TypedError) => {
|
|
179
184
|
if (error.type !== FREIGHTER) return null;
|
|
180
|
-
if (error instanceof EOF) return { type:
|
|
185
|
+
if (error instanceof EOF) return { type: EOF.TYPE, data: "EOF" };
|
|
181
186
|
if (error instanceof StreamClosed)
|
|
182
|
-
return { type:
|
|
187
|
+
return { type: StreamClosed.TYPE, data: "StreamClosed" };
|
|
183
188
|
if (error instanceof Unreachable)
|
|
184
|
-
return { type:
|
|
189
|
+
return { type: Unreachable.TYPE, data: "Unreachable" };
|
|
185
190
|
throw new Error(`Unknown error type: ${error.type}: ${error.message}`);
|
|
186
191
|
};
|
|
187
192
|
|
|
188
193
|
const freighterErrorDecoder: ErrorDecoder = (encoded: ErrorPayload) => {
|
|
189
|
-
if (encoded.type
|
|
190
|
-
switch (encoded.
|
|
191
|
-
case
|
|
194
|
+
if (!encoded.type.startsWith(FREIGHTER_ERROR_TYPE)) return null;
|
|
195
|
+
switch (encoded.type) {
|
|
196
|
+
case EOF.TYPE:
|
|
192
197
|
return new EOF();
|
|
193
|
-
case
|
|
198
|
+
case StreamClosed.TYPE:
|
|
194
199
|
return new StreamClosed();
|
|
195
|
-
case
|
|
200
|
+
case Unreachable.TYPE:
|
|
196
201
|
return new Unreachable();
|
|
197
202
|
default:
|
|
198
203
|
throw new Error(`Unknown error type: ${encoded.data}`);
|
package/src/index.ts
CHANGED
|
@@ -17,9 +17,9 @@ export {
|
|
|
17
17
|
StreamClosed,
|
|
18
18
|
Unreachable,
|
|
19
19
|
} from "@/errors";
|
|
20
|
-
export type { ErrorPayload
|
|
20
|
+
export type { ErrorPayload, TypedError } from "@/errors";
|
|
21
21
|
export { HTTPClient } from "@/http";
|
|
22
|
-
export type { Context
|
|
22
|
+
export type { Context, Middleware, Next } from "@/middleware";
|
|
23
23
|
export type { Stream, StreamClient } from "@/stream";
|
|
24
24
|
export type { UnaryClient } from "@/unary";
|
|
25
25
|
export { sendRequired } from "@/unary";
|
package/src/unary.ts
CHANGED
|
@@ -25,7 +25,7 @@ export interface UnaryClient extends Transport {
|
|
|
25
25
|
send: <RQ extends z.ZodTypeAny, RS extends z.ZodTypeAny = RQ>(
|
|
26
26
|
target: string,
|
|
27
27
|
req: z.input<RQ> | z.output<RQ>,
|
|
28
|
-
reqSchema: RQ
|
|
28
|
+
reqSchema: RQ,
|
|
29
29
|
resSchema: RS,
|
|
30
30
|
) => Promise<[z.output<RS>, null] | [null, Error]>;
|
|
31
31
|
}
|