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