@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.
Files changed (175) hide show
  1. package/.eslintrc.cjs +18 -0
  2. package/LICENSE +4 -21
  3. package/dist/alamos.d.ts +3 -0
  4. package/{build/module/lib → dist}/errors.d.ts +35 -40
  5. package/dist/freighter.cjs.js +11828 -0
  6. package/dist/freighter.cjs.js.map +1 -0
  7. package/dist/freighter.es.js +11828 -0
  8. package/dist/freighter.es.js.map +1 -0
  9. package/dist/http.d.ts +20 -0
  10. package/dist/index.d.ts +8 -0
  11. package/{build/module/lib → dist}/middleware.d.ts +11 -8
  12. package/{build/main/lib → dist}/stream.d.ts +11 -11
  13. package/{build/main/lib → dist}/transport.d.ts +2 -2
  14. package/dist/unary.d.ts +16 -0
  15. package/dist/websocket.d.ts +24 -0
  16. package/package.json +30 -98
  17. package/src/alamos.ts +40 -0
  18. package/src/errors.spec.ts +94 -0
  19. package/src/errors.ts +205 -0
  20. package/src/http.spec.ts +67 -0
  21. package/src/http.ts +115 -0
  22. package/src/index.ts +21 -20
  23. package/src/{lib/middleware.ts → middleware.ts} +29 -19
  24. package/src/{lib/stream.ts → stream.ts} +23 -14
  25. package/src/transport.ts +23 -0
  26. package/src/unary.ts +44 -0
  27. package/src/websocket.spec.ts +119 -0
  28. package/src/websocket.ts +203 -0
  29. package/tsconfig.json +5 -42
  30. package/tsconfig.vite.json +4 -0
  31. package/vite.config.ts +16 -0
  32. package/.editorconfig +0 -15
  33. package/.eslintrc.json +0 -33
  34. package/.gitignore +0 -9
  35. package/.nyc_output/3238f10e-9572-49ec-ab9d-28cbcaa6152a.json +0 -1
  36. package/.nyc_output/4e78a5c9-c0ca-4664-aa04-f478522608eb.json +0 -1
  37. package/.nyc_output/6a2244f2-5aea-45c7-8eeb-e14b454f0096.json +0 -1
  38. package/.nyc_output/dd1075a0-827b-4154-a75e-9bc90a4e16d0.json +0 -1
  39. package/.nyc_output/f829ad27-9bcd-4604-ae57-aae8c6f28d51.json +0 -1
  40. package/.nyc_output/fabc60f1-8fc5-4a1e-bea0-dc1fbcc31c9c.json +0 -1
  41. package/.nyc_output/processinfo/3238f10e-9572-49ec-ab9d-28cbcaa6152a.json +0 -1
  42. package/.nyc_output/processinfo/4e78a5c9-c0ca-4664-aa04-f478522608eb.json +0 -1
  43. package/.nyc_output/processinfo/6a2244f2-5aea-45c7-8eeb-e14b454f0096.json +0 -1
  44. package/.nyc_output/processinfo/dd1075a0-827b-4154-a75e-9bc90a4e16d0.json +0 -1
  45. package/.nyc_output/processinfo/f829ad27-9bcd-4604-ae57-aae8c6f28d51.json +0 -1
  46. package/.nyc_output/processinfo/fabc60f1-8fc5-4a1e-bea0-dc1fbcc31c9c.json +0 -1
  47. package/.nyc_output/processinfo/index.json +0 -1
  48. package/.prettierignore +0 -2
  49. package/.prettierrc +0 -3
  50. package/.vscode/settings.json +0 -4
  51. package/build/main/index.d.ts +0 -9
  52. package/build/main/index.js +0 -29
  53. package/build/main/lib/caseconv.d.ts +0 -2
  54. package/build/main/lib/caseconv.js +0 -14
  55. package/build/main/lib/encoder.d.ts +0 -59
  56. package/build/main/lib/encoder.js +0 -57
  57. package/build/main/lib/encoder.spec.d.ts +0 -1
  58. package/build/main/lib/encoder.spec.js +0 -26
  59. package/build/main/lib/errors.d.ts +0 -87
  60. package/build/main/lib/errors.js +0 -189
  61. package/build/main/lib/errors.spec.js +0 -88
  62. package/build/main/lib/http.d.ts +0 -50
  63. package/build/main/lib/http.js +0 -114
  64. package/build/main/lib/http.spec.js +0 -59
  65. package/build/main/lib/middleware.d.ts +0 -45
  66. package/build/main/lib/middleware.js +0 -38
  67. package/build/main/lib/runtime.d.ts +0 -5
  68. package/build/main/lib/runtime.js +0 -24
  69. package/build/main/lib/stream.js +0 -3
  70. package/build/main/lib/transport.js +0 -3
  71. package/build/main/lib/unary.d.ts +0 -15
  72. package/build/main/lib/unary.js +0 -3
  73. package/build/main/lib/url.d.ts +0 -38
  74. package/build/main/lib/url.js +0 -65
  75. package/build/main/lib/url.spec.d.ts +0 -1
  76. package/build/main/lib/url.spec.js +0 -41
  77. package/build/main/lib/util/log.d.ts +0 -2
  78. package/build/main/lib/util/log.js +0 -15
  79. package/build/main/lib/websocket.d.ts +0 -25
  80. package/build/main/lib/websocket.js +0 -172
  81. package/build/main/lib/websocket.spec.js +0 -86
  82. package/build/main/lib/ws.spec.d.ts +0 -1
  83. package/build/main/lib/ws.spec.js +0 -115
  84. package/build/module/index.d.ts +0 -9
  85. package/build/module/index.js +0 -7
  86. package/build/module/lib/caseconv.d.ts +0 -2
  87. package/build/module/lib/caseconv.js +0 -12
  88. package/build/module/lib/encoder.d.ts +0 -59
  89. package/build/module/lib/encoder.js +0 -47
  90. package/build/module/lib/encoder.spec.d.ts +0 -1
  91. package/build/module/lib/encoder.spec.js +0 -21
  92. package/build/module/lib/errors.js +0 -164
  93. package/build/module/lib/errors.spec.d.ts +0 -1
  94. package/build/module/lib/errors.spec.js +0 -85
  95. package/build/module/lib/http.d.ts +0 -50
  96. package/build/module/lib/http.js +0 -108
  97. package/build/module/lib/http.spec.d.ts +0 -1
  98. package/build/module/lib/http.spec.js +0 -54
  99. package/build/module/lib/middleware.js +0 -32
  100. package/build/module/lib/runtime.d.ts +0 -5
  101. package/build/module/lib/runtime.js +0 -21
  102. package/build/module/lib/stream.d.ts +0 -76
  103. package/build/module/lib/stream.js +0 -2
  104. package/build/module/lib/transport.d.ts +0 -13
  105. package/build/module/lib/transport.js +0 -2
  106. package/build/module/lib/unary.d.ts +0 -15
  107. package/build/module/lib/unary.js +0 -2
  108. package/build/module/lib/url.d.ts +0 -38
  109. package/build/module/lib/url.js +0 -65
  110. package/build/module/lib/url.spec.d.ts +0 -1
  111. package/build/module/lib/url.spec.js +0 -34
  112. package/build/module/lib/util/log.d.ts +0 -2
  113. package/build/module/lib/util/log.js +0 -11
  114. package/build/module/lib/websocket.d.ts +0 -25
  115. package/build/module/lib/websocket.js +0 -181
  116. package/build/module/lib/websocket.spec.d.ts +0 -1
  117. package/build/module/lib/websocket.spec.js +0 -82
  118. package/build/module/lib/ws.spec.d.ts +0 -1
  119. package/build/module/lib/ws.spec.js +0 -94
  120. package/build/tsconfig.module.tsbuildinfo +0 -1
  121. package/build/tsconfig.tsbuildinfo +0 -1
  122. package/coverage/base.css +0 -224
  123. package/coverage/block-navigation.js +0 -87
  124. package/coverage/caseconv.ts.html +0 -124
  125. package/coverage/encoder.ts.html +0 -403
  126. package/coverage/errors.ts.html +0 -727
  127. package/coverage/favicon.png +0 -0
  128. package/coverage/http.ts.html +0 -532
  129. package/coverage/index.html +0 -221
  130. package/coverage/lcov-report/base.css +0 -224
  131. package/coverage/lcov-report/block-navigation.js +0 -87
  132. package/coverage/lcov-report/caseconv.ts.html +0 -124
  133. package/coverage/lcov-report/encoder.ts.html +0 -403
  134. package/coverage/lcov-report/errors.ts.html +0 -727
  135. package/coverage/lcov-report/favicon.png +0 -0
  136. package/coverage/lcov-report/http.ts.html +0 -532
  137. package/coverage/lcov-report/index.html +0 -221
  138. package/coverage/lcov-report/middleware.ts.html +0 -286
  139. package/coverage/lcov-report/prettify.css +0 -1
  140. package/coverage/lcov-report/prettify.js +0 -2
  141. package/coverage/lcov-report/runtime.ts.html +0 -154
  142. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  143. package/coverage/lcov-report/sorter.js +0 -196
  144. package/coverage/lcov-report/url.ts.html +0 -322
  145. package/coverage/lcov-report/websocket.ts.html +0 -760
  146. package/coverage/lcov.info +0 -552
  147. package/coverage/middleware.ts.html +0 -286
  148. package/coverage/prettify.css +0 -1
  149. package/coverage/prettify.js +0 -2
  150. package/coverage/runtime.ts.html +0 -154
  151. package/coverage/sort-arrow-sprite.png +0 -0
  152. package/coverage/sorter.js +0 -196
  153. package/coverage/url.ts.html +0 -322
  154. package/coverage/websocket.ts.html +0 -760
  155. package/src/lib/caseconv.ts +0 -13
  156. package/src/lib/encoder.spec.ts +0 -23
  157. package/src/lib/encoder.ts +0 -105
  158. package/src/lib/errors.spec.ts +0 -98
  159. package/src/lib/errors.ts +0 -214
  160. package/src/lib/http.spec.ts +0 -85
  161. package/src/lib/http.ts +0 -149
  162. package/src/lib/runtime.ts +0 -23
  163. package/src/lib/transport.ts +0 -14
  164. package/src/lib/unary.ts +0 -21
  165. package/src/lib/url.spec.ts +0 -37
  166. package/src/lib/url.ts +0 -79
  167. package/src/lib/util/log.ts +0 -12
  168. package/src/lib/websocket.spec.ts +0 -106
  169. package/src/lib/websocket.ts +0 -225
  170. package/src/types/example.d.ts +0 -24
  171. package/tsconfig.module.json +0 -9
  172. package/yarn.lock +0 -5878
  173. /package/{build/main/lib → dist}/errors.spec.d.ts +0 -0
  174. /package/{build/main/lib → dist}/http.spec.d.ts +0 -0
  175. /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
- MIT License
2
-
3
- Copyright (c) 2019 emiliano bonilla
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.
@@ -0,0 +1,3 @@
1
+ import { type Instrumentation } from "@synnaxlabs/alamos";
2
+ import { type Middleware } from './middleware';
3
+ export declare const middleware: (instrumentation: Instrumentation) => Middleware;
@@ -1,41 +1,36 @@
1
- import { z } from 'zod';
1
+ import { URL } from "@synnaxlabs/x";
2
+ import { z } from "zod";
2
3
  export interface TypedError extends Error {
3
- discriminator: 'FreighterError';
4
- /**
5
- * @description Returns a unique type identifier for the error. Freighter uses this to
6
- * determine the correct decoder to use on the other end of the freighter.
7
- */
8
- type: string;
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
- discriminator: 'FreighterError';
12
- type: string;
13
- constructor(message: string, type: string);
12
+ discriminator: "FreighterError";
13
+ type: string;
14
+ constructor(message: string, type: string);
14
15
  }
15
- declare type ErrorDecoder = (encoded: string) => Error | undefined;
16
- declare type ErrorEncoder = (error: TypedError) => string;
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 = 'unknown';
20
- export declare const NONE = 'nil';
21
- export declare const FREIGHTER = 'freighter';
22
- export declare const ErrorPayloadSchema: z.ZodObject<
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
- type,
49
- encode,
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 | undefined;
61
+ export declare const decodeError: (payload: ErrorPayload) => Error | null;
72
62
  export declare class UnknownError extends BaseTypedError implements TypedError {
73
- constructor(message: string);
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
- constructor();
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
- constructor();
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
- constructor();
79
+ url: URL;
80
+ constructor(args?: UnreachableArgs);
86
81
  }
87
82
  export {};