@synnaxlabs/freighter 0.1.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 (89) 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 +17 -12
  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/dist/middleware.d.ts +48 -0
  12. package/{build/module/lib → dist}/stream.d.ts +12 -11
  13. package/dist/transport.d.ts +13 -0
  14. package/dist/unary.d.ts +16 -0
  15. package/dist/websocket.d.ts +24 -0
  16. package/package.json +30 -97
  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 +26 -0
  23. package/src/middleware.ts +77 -0
  24. package/src/stream.ts +97 -0
  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 +10 -0
  30. package/tsconfig.vite.json +4 -0
  31. package/vite.config.ts +16 -0
  32. package/build/main/index.d.ts +0 -7
  33. package/build/main/index.js +0 -27
  34. package/build/main/lib/caseconv.d.ts +0 -2
  35. package/build/main/lib/caseconv.js +0 -14
  36. package/build/main/lib/encoder.d.ts +0 -60
  37. package/build/main/lib/encoder.js +0 -61
  38. package/build/main/lib/encoder.spec.js +0 -26
  39. package/build/main/lib/errors.d.ts +0 -77
  40. package/build/main/lib/errors.js +0 -171
  41. package/build/main/lib/errors.spec.js +0 -76
  42. package/build/main/lib/http.d.ts +0 -46
  43. package/build/main/lib/http.js +0 -99
  44. package/build/main/lib/http.spec.js +0 -49
  45. package/build/main/lib/runtime.d.ts +0 -5
  46. package/build/main/lib/runtime.js +0 -22
  47. package/build/main/lib/stream.d.ts +0 -75
  48. package/build/main/lib/stream.js +0 -3
  49. package/build/main/lib/unary.d.ts +0 -14
  50. package/build/main/lib/unary.js +0 -3
  51. package/build/main/lib/url.d.ts +0 -37
  52. package/build/main/lib/url.js +0 -57
  53. package/build/main/lib/url.spec.d.ts +0 -1
  54. package/build/main/lib/url.spec.js +0 -36
  55. package/build/main/lib/websocket.d.ts +0 -21
  56. package/build/main/lib/websocket.js +0 -154
  57. package/build/main/lib/ws.spec.d.ts +0 -1
  58. package/build/main/lib/ws.spec.js +0 -73
  59. package/build/module/index.d.ts +0 -7
  60. package/build/module/index.js +0 -6
  61. package/build/module/lib/caseconv.d.ts +0 -2
  62. package/build/module/lib/caseconv.js +0 -9
  63. package/build/module/lib/encoder.d.ts +0 -60
  64. package/build/module/lib/encoder.js +0 -51
  65. package/build/module/lib/encoder.spec.d.ts +0 -1
  66. package/build/module/lib/encoder.spec.js +0 -21
  67. package/build/module/lib/errors.js +0 -160
  68. package/build/module/lib/errors.spec.d.ts +0 -1
  69. package/build/module/lib/errors.spec.js +0 -71
  70. package/build/module/lib/http.d.ts +0 -46
  71. package/build/module/lib/http.js +0 -94
  72. package/build/module/lib/http.spec.d.ts +0 -1
  73. package/build/module/lib/http.spec.js +0 -44
  74. package/build/module/lib/runtime.d.ts +0 -5
  75. package/build/module/lib/runtime.js +0 -19
  76. package/build/module/lib/stream.js +0 -2
  77. package/build/module/lib/unary.d.ts +0 -14
  78. package/build/module/lib/unary.js +0 -2
  79. package/build/module/lib/url.d.ts +0 -37
  80. package/build/module/lib/url.js +0 -61
  81. package/build/module/lib/url.spec.d.ts +0 -1
  82. package/build/module/lib/url.spec.js +0 -31
  83. package/build/module/lib/websocket.d.ts +0 -21
  84. package/build/module/lib/websocket.js +0 -160
  85. package/build/module/lib/ws.spec.d.ts +0 -1
  86. package/build/module/lib/ws.spec.js +0 -69
  87. /package/{build/main/lib → dist}/errors.spec.d.ts +0 -0
  88. /package/{build/main/lib → dist}/http.spec.d.ts +0 -0
  89. /package/{build/main/lib/encoder.spec.d.ts → 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,6 +1,7 @@
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
+ discriminator: "FreighterError";
4
5
  /**
5
6
  * @description Returns a unique type identifier for the error. Freighter uses this to
6
7
  * determine the correct decoder to use on the other end of the freighter.
@@ -8,18 +9,18 @@ export interface TypedError extends Error {
8
9
  type: string;
9
10
  }
10
11
  export declare class BaseTypedError extends Error implements TypedError {
11
- discriminator: 'FreighterError';
12
+ discriminator: "FreighterError";
12
13
  type: string;
13
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 assertErrorType: <T>(type: string, error?: Error | null) => T;
19
20
  export declare const UNKNOWN = "unknown";
20
21
  export declare const NONE = "nil";
21
22
  export declare const FREIGHTER = "freighter";
22
- export declare const ErrorPayloadSchema: z.ZodObject<{
23
+ export declare const errorZ: z.ZodObject<{
23
24
  type: z.ZodString;
24
25
  data: z.ZodString;
25
26
  }, "strip", z.ZodTypeAny, {
@@ -29,7 +30,7 @@ export declare const ErrorPayloadSchema: z.ZodObject<{
29
30
  type: string;
30
31
  data: string;
31
32
  }>;
32
- export declare type ErrorPayload = z.infer<typeof ErrorPayloadSchema>;
33
+ export type ErrorPayload = z.infer<typeof errorZ>;
33
34
  /**
34
35
  * Registers a custom error type with the error registry, which allows it to be
35
36
  * encoded/decoded and sent over the network.
@@ -38,8 +39,7 @@ export declare type ErrorPayload = z.infer<typeof ErrorPayloadSchema>;
38
39
  * @param encode - A function that encodes the error into a string.
39
40
  * @param decode - A function that decodes the error from a string.
40
41
  */
41
- export declare const registerError: ({ type, encode, decode, }: {
42
- type: string;
42
+ export declare const registerError: ({ encode, decode, }: {
43
43
  encode: ErrorEncoder;
44
44
  decode: ErrorDecoder;
45
45
  }) => void;
@@ -58,7 +58,7 @@ export declare const encodeError: (error: unknown) => ErrorPayload;
58
58
  * @param payload - The encoded error payload.
59
59
  * @returns The decoded error.
60
60
  */
61
- export declare const decodeError: (payload: ErrorPayload) => Error | undefined;
61
+ export declare const decodeError: (payload: ErrorPayload) => Error | null;
62
62
  export declare class UnknownError extends BaseTypedError implements TypedError {
63
63
  constructor(message: string);
64
64
  }
@@ -70,8 +70,13 @@ export declare class EOF extends BaseTypedError implements TypedError {
70
70
  export declare class StreamClosed extends BaseTypedError implements TypedError {
71
71
  constructor();
72
72
  }
73
+ export interface UnreachableArgs {
74
+ message?: string;
75
+ url?: URL;
76
+ }
73
77
  /** Thrown when a target is unreachable. */
74
78
  export declare class Unreachable extends BaseTypedError implements TypedError {
75
- constructor();
79
+ url: URL;
80
+ constructor(args?: UnreachableArgs);
76
81
  }
77
82
  export {};