@synnaxlabs/freighter 0.2.0 → 0.4.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/.eslintrc.cjs +18 -0
- package/LICENSE +4 -21
- package/dist/alamos.d.ts +3 -0
- package/{build/module/lib → dist}/errors.d.ts +35 -40
- package/dist/freighter.cjs.js +11828 -0
- package/dist/freighter.cjs.js.map +1 -0
- package/dist/freighter.es.js +11828 -0
- package/dist/freighter.es.js.map +1 -0
- package/dist/http.d.ts +20 -0
- package/dist/index.d.ts +8 -0
- package/{build/module/lib → dist}/middleware.d.ts +11 -8
- package/{build/main/lib → dist}/stream.d.ts +11 -11
- package/{build/main/lib → dist}/transport.d.ts +2 -2
- package/dist/unary.d.ts +16 -0
- package/dist/websocket.d.ts +24 -0
- package/package.json +30 -98
- package/src/alamos.ts +40 -0
- package/src/errors.spec.ts +94 -0
- package/src/errors.ts +205 -0
- package/src/http.spec.ts +67 -0
- package/src/http.ts +115 -0
- package/src/index.ts +21 -20
- package/src/{lib/middleware.ts → middleware.ts} +29 -19
- package/src/{lib/stream.ts → stream.ts} +23 -14
- package/src/transport.ts +23 -0
- package/src/unary.ts +44 -0
- package/src/websocket.spec.ts +119 -0
- package/src/websocket.ts +203 -0
- package/tsconfig.json +5 -42
- package/tsconfig.vite.json +4 -0
- package/vite.config.ts +16 -0
- package/.editorconfig +0 -15
- package/.eslintrc.json +0 -33
- package/.gitignore +0 -9
- package/.nyc_output/3238f10e-9572-49ec-ab9d-28cbcaa6152a.json +0 -1
- package/.nyc_output/4e78a5c9-c0ca-4664-aa04-f478522608eb.json +0 -1
- package/.nyc_output/6a2244f2-5aea-45c7-8eeb-e14b454f0096.json +0 -1
- package/.nyc_output/dd1075a0-827b-4154-a75e-9bc90a4e16d0.json +0 -1
- package/.nyc_output/f829ad27-9bcd-4604-ae57-aae8c6f28d51.json +0 -1
- package/.nyc_output/fabc60f1-8fc5-4a1e-bea0-dc1fbcc31c9c.json +0 -1
- package/.nyc_output/processinfo/3238f10e-9572-49ec-ab9d-28cbcaa6152a.json +0 -1
- package/.nyc_output/processinfo/4e78a5c9-c0ca-4664-aa04-f478522608eb.json +0 -1
- package/.nyc_output/processinfo/6a2244f2-5aea-45c7-8eeb-e14b454f0096.json +0 -1
- package/.nyc_output/processinfo/dd1075a0-827b-4154-a75e-9bc90a4e16d0.json +0 -1
- package/.nyc_output/processinfo/f829ad27-9bcd-4604-ae57-aae8c6f28d51.json +0 -1
- package/.nyc_output/processinfo/fabc60f1-8fc5-4a1e-bea0-dc1fbcc31c9c.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/.prettierignore +0 -2
- package/.prettierrc +0 -3
- package/.vscode/settings.json +0 -4
- package/build/main/index.d.ts +0 -9
- package/build/main/index.js +0 -29
- package/build/main/lib/caseconv.d.ts +0 -2
- package/build/main/lib/caseconv.js +0 -14
- package/build/main/lib/encoder.d.ts +0 -59
- package/build/main/lib/encoder.js +0 -57
- package/build/main/lib/encoder.spec.d.ts +0 -1
- package/build/main/lib/encoder.spec.js +0 -26
- package/build/main/lib/errors.d.ts +0 -87
- package/build/main/lib/errors.js +0 -189
- package/build/main/lib/errors.spec.js +0 -88
- package/build/main/lib/http.d.ts +0 -50
- package/build/main/lib/http.js +0 -114
- package/build/main/lib/http.spec.js +0 -59
- package/build/main/lib/middleware.d.ts +0 -45
- package/build/main/lib/middleware.js +0 -38
- package/build/main/lib/runtime.d.ts +0 -5
- package/build/main/lib/runtime.js +0 -24
- package/build/main/lib/stream.js +0 -3
- package/build/main/lib/transport.js +0 -3
- package/build/main/lib/unary.d.ts +0 -15
- package/build/main/lib/unary.js +0 -3
- package/build/main/lib/url.d.ts +0 -38
- package/build/main/lib/url.js +0 -65
- package/build/main/lib/url.spec.d.ts +0 -1
- package/build/main/lib/url.spec.js +0 -41
- package/build/main/lib/util/log.d.ts +0 -2
- package/build/main/lib/util/log.js +0 -15
- package/build/main/lib/websocket.d.ts +0 -25
- package/build/main/lib/websocket.js +0 -172
- package/build/main/lib/websocket.spec.js +0 -86
- package/build/main/lib/ws.spec.d.ts +0 -1
- package/build/main/lib/ws.spec.js +0 -115
- package/build/module/index.d.ts +0 -9
- package/build/module/index.js +0 -7
- package/build/module/lib/caseconv.d.ts +0 -2
- package/build/module/lib/caseconv.js +0 -12
- package/build/module/lib/encoder.d.ts +0 -59
- package/build/module/lib/encoder.js +0 -47
- package/build/module/lib/encoder.spec.d.ts +0 -1
- package/build/module/lib/encoder.spec.js +0 -21
- package/build/module/lib/errors.js +0 -164
- package/build/module/lib/errors.spec.d.ts +0 -1
- package/build/module/lib/errors.spec.js +0 -85
- package/build/module/lib/http.d.ts +0 -50
- package/build/module/lib/http.js +0 -108
- package/build/module/lib/http.spec.d.ts +0 -1
- package/build/module/lib/http.spec.js +0 -54
- package/build/module/lib/middleware.js +0 -32
- package/build/module/lib/runtime.d.ts +0 -5
- package/build/module/lib/runtime.js +0 -21
- package/build/module/lib/stream.d.ts +0 -76
- package/build/module/lib/stream.js +0 -2
- package/build/module/lib/transport.d.ts +0 -13
- package/build/module/lib/transport.js +0 -2
- package/build/module/lib/unary.d.ts +0 -15
- package/build/module/lib/unary.js +0 -2
- package/build/module/lib/url.d.ts +0 -38
- package/build/module/lib/url.js +0 -65
- package/build/module/lib/url.spec.d.ts +0 -1
- package/build/module/lib/url.spec.js +0 -34
- package/build/module/lib/util/log.d.ts +0 -2
- package/build/module/lib/util/log.js +0 -11
- package/build/module/lib/websocket.d.ts +0 -25
- package/build/module/lib/websocket.js +0 -181
- package/build/module/lib/websocket.spec.d.ts +0 -1
- package/build/module/lib/websocket.spec.js +0 -82
- package/build/module/lib/ws.spec.d.ts +0 -1
- package/build/module/lib/ws.spec.js +0 -94
- package/build/tsconfig.module.tsbuildinfo +0 -1
- package/build/tsconfig.tsbuildinfo +0 -1
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/caseconv.ts.html +0 -124
- package/coverage/encoder.ts.html +0 -403
- package/coverage/errors.ts.html +0 -727
- package/coverage/favicon.png +0 -0
- package/coverage/http.ts.html +0 -532
- package/coverage/index.html +0 -221
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/caseconv.ts.html +0 -124
- package/coverage/lcov-report/encoder.ts.html +0 -403
- package/coverage/lcov-report/errors.ts.html +0 -727
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/http.ts.html +0 -532
- package/coverage/lcov-report/index.html +0 -221
- package/coverage/lcov-report/middleware.ts.html +0 -286
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/runtime.ts.html +0 -154
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/url.ts.html +0 -322
- package/coverage/lcov-report/websocket.ts.html +0 -760
- package/coverage/lcov.info +0 -552
- package/coverage/middleware.ts.html +0 -286
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/runtime.ts.html +0 -154
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -196
- package/coverage/url.ts.html +0 -322
- package/coverage/websocket.ts.html +0 -760
- package/src/lib/caseconv.ts +0 -13
- package/src/lib/encoder.spec.ts +0 -23
- package/src/lib/encoder.ts +0 -105
- package/src/lib/errors.spec.ts +0 -98
- package/src/lib/errors.ts +0 -214
- package/src/lib/http.spec.ts +0 -85
- package/src/lib/http.ts +0 -149
- package/src/lib/runtime.ts +0 -23
- package/src/lib/transport.ts +0 -14
- package/src/lib/unary.ts +0 -21
- package/src/lib/url.spec.ts +0 -37
- package/src/lib/url.ts +0 -79
- package/src/lib/util/log.ts +0 -12
- package/src/lib/websocket.spec.ts +0 -106
- package/src/lib/websocket.ts +0 -225
- package/src/types/example.d.ts +0 -24
- package/tsconfig.module.json +0 -9
- package/yarn.lock +0 -5878
- /package/{build/main/lib → dist}/errors.spec.d.ts +0 -0
- /package/{build/main/lib → dist}/http.spec.d.ts +0 -0
- /package/{build/main/lib → dist}/websocket.spec.d.ts +0 -0
package/.eslintrc.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2023 Synnax Labs, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this software is governed by the Business Source License included in the file
|
|
5
|
+
* licenses/BSL.txt.
|
|
6
|
+
*
|
|
7
|
+
* As of the Change Date specified in that file, in accordance with the Business Source
|
|
8
|
+
* License, use of this software will be governed by the Apache License, Version 2.0,
|
|
9
|
+
* included in the file licenses/APL.txt.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
module.exports = {
|
|
13
|
+
root: true,
|
|
14
|
+
extends: ["synnaxlabs"],
|
|
15
|
+
parserOptions: {
|
|
16
|
+
project: "./tsconfig.json",
|
|
17
|
+
},
|
|
18
|
+
};
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
Source code in this repository is licensed under the Business Source License 1.1 (BSL).
|
|
2
|
+
A copy of the license can be found in the licenses/BSL.txt file. Source code in a given
|
|
3
|
+
file is licensed under the BSL and the copyright belongs to Synnax Labs, Inc. unless
|
|
4
|
+
otherwise noted at the beginning of the file.
|
package/dist/alamos.d.ts
ADDED
|
@@ -1,41 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { URL } from "@synnaxlabs/x";
|
|
2
|
+
import { z } from "zod";
|
|
2
3
|
export interface TypedError extends Error {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
discriminator: "FreighterError";
|
|
5
|
+
/**
|
|
6
|
+
* @description Returns a unique type identifier for the error. Freighter uses this to
|
|
7
|
+
* determine the correct decoder to use on the other end of the freighter.
|
|
8
|
+
*/
|
|
9
|
+
type: string;
|
|
9
10
|
}
|
|
10
11
|
export declare class BaseTypedError extends Error implements TypedError {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
discriminator: "FreighterError";
|
|
13
|
+
type: string;
|
|
14
|
+
constructor(message: string, type: string);
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
type ErrorDecoder = (encoded: ErrorPayload) => Error | null;
|
|
17
|
+
type ErrorEncoder = (error: TypedError) => ErrorPayload | null;
|
|
17
18
|
export declare const isTypedError: (error: unknown) => error is TypedError;
|
|
18
|
-
export declare const assertErrorType: <T>(type: string, error?: Error) => T;
|
|
19
|
-
export declare const UNKNOWN =
|
|
20
|
-
export declare const NONE =
|
|
21
|
-
export declare const FREIGHTER =
|
|
22
|
-
export declare const
|
|
23
|
-
{
|
|
19
|
+
export declare const assertErrorType: <T>(type: string, error?: Error | null) => T;
|
|
20
|
+
export declare const UNKNOWN = "unknown";
|
|
21
|
+
export declare const NONE = "nil";
|
|
22
|
+
export declare const FREIGHTER = "freighter";
|
|
23
|
+
export declare const errorZ: z.ZodObject<{
|
|
24
24
|
type: z.ZodString;
|
|
25
25
|
data: z.ZodString;
|
|
26
|
-
|
|
27
|
-
'strip',
|
|
28
|
-
z.ZodTypeAny,
|
|
29
|
-
{
|
|
26
|
+
}, "strip", z.ZodTypeAny, {
|
|
30
27
|
type: string;
|
|
31
28
|
data: string;
|
|
32
|
-
|
|
33
|
-
{
|
|
29
|
+
}, {
|
|
34
30
|
type: string;
|
|
35
31
|
data: string;
|
|
36
|
-
|
|
37
|
-
>;
|
|
38
|
-
export declare type ErrorPayload = z.infer<typeof ErrorPayloadSchema>;
|
|
32
|
+
}>;
|
|
33
|
+
export type ErrorPayload = z.infer<typeof errorZ>;
|
|
39
34
|
/**
|
|
40
35
|
* Registers a custom error type with the error registry, which allows it to be
|
|
41
36
|
* encoded/decoded and sent over the network.
|
|
@@ -44,14 +39,9 @@ export declare type ErrorPayload = z.infer<typeof ErrorPayloadSchema>;
|
|
|
44
39
|
* @param encode - A function that encodes the error into a string.
|
|
45
40
|
* @param decode - A function that decodes the error from a string.
|
|
46
41
|
*/
|
|
47
|
-
export declare const registerError: ({
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
decode,
|
|
51
|
-
}: {
|
|
52
|
-
type: string;
|
|
53
|
-
encode: ErrorEncoder;
|
|
54
|
-
decode: ErrorDecoder;
|
|
42
|
+
export declare const registerError: ({ encode, decode, }: {
|
|
43
|
+
encode: ErrorEncoder;
|
|
44
|
+
decode: ErrorDecoder;
|
|
55
45
|
}) => void;
|
|
56
46
|
/**
|
|
57
47
|
* Encodes an error into a payload that can be sent between a freighter server
|
|
@@ -68,20 +58,25 @@ export declare const encodeError: (error: unknown) => ErrorPayload;
|
|
|
68
58
|
* @param payload - The encoded error payload.
|
|
69
59
|
* @returns The decoded error.
|
|
70
60
|
*/
|
|
71
|
-
export declare const decodeError: (payload: ErrorPayload) => Error |
|
|
61
|
+
export declare const decodeError: (payload: ErrorPayload) => Error | null;
|
|
72
62
|
export declare class UnknownError extends BaseTypedError implements TypedError {
|
|
73
|
-
|
|
63
|
+
constructor(message: string);
|
|
74
64
|
}
|
|
75
65
|
/** Thrown/returned when a stream closed normally. */
|
|
76
66
|
export declare class EOF extends BaseTypedError implements TypedError {
|
|
77
|
-
|
|
67
|
+
constructor();
|
|
78
68
|
}
|
|
79
69
|
/** Thrown/returned when a stream is closed abnormally. */
|
|
80
70
|
export declare class StreamClosed extends BaseTypedError implements TypedError {
|
|
81
|
-
|
|
71
|
+
constructor();
|
|
72
|
+
}
|
|
73
|
+
export interface UnreachableArgs {
|
|
74
|
+
message?: string;
|
|
75
|
+
url?: URL;
|
|
82
76
|
}
|
|
83
77
|
/** Thrown when a target is unreachable. */
|
|
84
78
|
export declare class Unreachable extends BaseTypedError implements TypedError {
|
|
85
|
-
|
|
79
|
+
url: URL;
|
|
80
|
+
constructor(args?: UnreachableArgs);
|
|
86
81
|
}
|
|
87
82
|
export {};
|