@seam-rpc/core 4.3.18 → 4.3.20

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/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type Result<Data, Error = undefined> = {
1
+ export type Result<Data, Error extends RpcError> = {
2
2
  ok: true;
3
3
  data: Data;
4
4
  } | {
@@ -14,13 +14,21 @@ export type ResError = {
14
14
  data: unknown;
15
15
  };
16
16
  };
17
- export declare class RpcError<Code extends string = any, Data = unknown> {
17
+ export declare class RpcError<ErrorMap extends Record<Code, any> = any, Code extends keyof ErrorMap = keyof ErrorMap> {
18
18
  private _code;
19
- private _data;
20
- constructor(code: Code, data: Data);
19
+ private _data?;
20
+ constructor(code: Code, data?: ErrorMap[Code]);
21
21
  get code(): Code;
22
- get data(): Data;
22
+ get data(): ErrorMap[Code] | undefined;
23
23
  toString(): string;
24
+ toJSON(): {
25
+ code: Code;
26
+ data: ErrorMap[Code] | undefined;
27
+ };
28
+ static fromJSON(json: {
29
+ code: any;
30
+ data: any;
31
+ }): RpcError<any, any>;
24
32
  }
25
33
  export declare function extractFiles(input: unknown): {
26
34
  json: any;
package/dist/index.js CHANGED
@@ -6,7 +6,13 @@ export class RpcError {
6
6
  get code() { return this._code; }
7
7
  get data() { return this._data; }
8
8
  toString() {
9
- return this._code + ": " + JSON.stringify(this._data);
9
+ return this._code.toString() + (this._data !== undefined ? ": " + JSON.stringify(this._data) : "");
10
+ }
11
+ toJSON() {
12
+ return { code: this._code, data: this._data };
13
+ }
14
+ static fromJSON(json) {
15
+ return new RpcError(json.code, json.data);
10
16
  }
11
17
  }
12
18
  export function extractFiles(input) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seam-rpc/core",
3
- "version": "4.3.18",
3
+ "version": "4.3.20",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",