@pl4dr/rpc-core 1001.0.0
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/LICENSE +21 -0
- package/dist/index.cjs +127 -0
- package/dist/index.d.cts +138 -0
- package/dist/index.d.ts +138 -0
- package/dist/index.js +98 -0
- package/package.json +37 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Chan Nyein Thaw
|
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.
|
package/dist/index.cjs
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
|
20
|
+
// src/index.ts
|
21
|
+
var index_exports = {};
|
22
|
+
__export(index_exports, {
|
23
|
+
JSON_RPC_ERROR_CODES_BY_KEY: () => JSON_RPC_ERROR_CODES_BY_KEY,
|
24
|
+
RPC_ERROR_CODE: () => RPC_ERROR_CODE,
|
25
|
+
RPC_ERROR_KEY: () => RPC_ERROR_KEY
|
26
|
+
});
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
28
|
+
|
29
|
+
// src/error.ts
|
30
|
+
var RPC_ERROR_CODE = {
|
31
|
+
PARSE_ERROR: 400,
|
32
|
+
BAD_REQUEST: 400,
|
33
|
+
UNAUTHORIZED: 401,
|
34
|
+
FORBIDDEN: 403,
|
35
|
+
NOT_FOUND: 404,
|
36
|
+
METHOD_NOT_SUPPORTED: 405,
|
37
|
+
TIMEOUT: 408,
|
38
|
+
CONFLICT: 409,
|
39
|
+
PRECONDITION_FAILED: 412,
|
40
|
+
PAYLOAD_TOO_LARGE: 413,
|
41
|
+
UNSUPPORTED_MEDIA_TYPE: 415,
|
42
|
+
UNPROCESSABLE_CONTENT: 422,
|
43
|
+
TOO_MANY_REQUESTS: 429,
|
44
|
+
CLIENT_CLOSED_REQUEST: 499,
|
45
|
+
INTERNAL_SERVER_ERROR: 500,
|
46
|
+
NOT_IMPLEMENTED: 501,
|
47
|
+
BAD_GATEWAY: 502,
|
48
|
+
SERVICE_UNAVAILABLE: 503,
|
49
|
+
GATEWAY_TIMEOUT: 504
|
50
|
+
};
|
51
|
+
var RPC_ERROR_KEY = {
|
52
|
+
400: "PARSE_ERROR",
|
53
|
+
401: "UNAUTHORIZED",
|
54
|
+
403: "FORBIDDEN",
|
55
|
+
404: "NOT_FOUND",
|
56
|
+
405: "METHOD_NOT_SUPPORTED",
|
57
|
+
408: "TIMEOUT",
|
58
|
+
409: "CONFLICT",
|
59
|
+
412: "PRECONDITION_FAILED",
|
60
|
+
413: "PAYLOAD_TOO_LARGE",
|
61
|
+
415: "UNSUPPORTED_MEDIA_TYPE",
|
62
|
+
422: "UNPROCESSABLE_CONTENT",
|
63
|
+
429: "TOO_MANY_REQUESTS",
|
64
|
+
499: "CLIENT_CLOSED_REQUEST",
|
65
|
+
500: "INTERNAL_SERVER_ERROR",
|
66
|
+
501: "NOT_IMPLEMENTED",
|
67
|
+
502: "BAD_GATEWAY",
|
68
|
+
503: "SERVICE_UNAVAILABLE",
|
69
|
+
504: "GATEWAY_TIMEOUT"
|
70
|
+
};
|
71
|
+
var JSON_RPC_ERROR_CODES_BY_KEY = {
|
72
|
+
/**
|
73
|
+
* Invalid JSON was received by the server.
|
74
|
+
* An error occurred on the server while parsing the JSON text.
|
75
|
+
*/
|
76
|
+
PARSE_ERROR: -32700,
|
77
|
+
/**
|
78
|
+
* The JSON sent is not a valid Request object.
|
79
|
+
*/
|
80
|
+
BAD_REQUEST: -32600,
|
81
|
+
// 400
|
82
|
+
// Internal JSON-RPC error
|
83
|
+
INTERNAL_SERVER_ERROR: -32603,
|
84
|
+
// 500
|
85
|
+
NOT_IMPLEMENTED: -32603,
|
86
|
+
// 501
|
87
|
+
BAD_GATEWAY: -32603,
|
88
|
+
// 502
|
89
|
+
SERVICE_UNAVAILABLE: -32603,
|
90
|
+
// 503
|
91
|
+
GATEWAY_TIMEOUT: -32603,
|
92
|
+
// 504
|
93
|
+
// Implementation specific errors
|
94
|
+
UNAUTHORIZED: -32001,
|
95
|
+
// 401
|
96
|
+
FORBIDDEN: -32003,
|
97
|
+
// 403
|
98
|
+
NOT_FOUND: -32004,
|
99
|
+
// 404
|
100
|
+
METHOD_NOT_SUPPORTED: -32005,
|
101
|
+
// 405
|
102
|
+
TIMEOUT: -32008,
|
103
|
+
// 408
|
104
|
+
CONFLICT: -32009,
|
105
|
+
// 409
|
106
|
+
PRECONDITION_FAILED: -32012,
|
107
|
+
// 412
|
108
|
+
PAYLOAD_TOO_LARGE: -32013,
|
109
|
+
// 413
|
110
|
+
UNSUPPORTED_MEDIA_TYPE: -32015,
|
111
|
+
// 415
|
112
|
+
UNPROCESSABLE_CONTENT: -32022,
|
113
|
+
// 422
|
114
|
+
TOO_MANY_REQUESTS: -32029,
|
115
|
+
// 429
|
116
|
+
CLIENT_CLOSED_REQUEST: -32099
|
117
|
+
// 499
|
118
|
+
};
|
119
|
+
|
120
|
+
// src/router/types.ts
|
121
|
+
var import_zod = require("zod");
|
122
|
+
// Annotate the CommonJS export names for ESM import in node:
|
123
|
+
0 && (module.exports = {
|
124
|
+
JSON_RPC_ERROR_CODES_BY_KEY,
|
125
|
+
RPC_ERROR_CODE,
|
126
|
+
RPC_ERROR_KEY
|
127
|
+
});
|
package/dist/index.d.cts
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
import { ZodIssue, Schema } from 'zod';
|
2
|
+
import { ResultAsync } from 'neverthrow';
|
3
|
+
|
4
|
+
declare const RPC_ERROR_CODE: {
|
5
|
+
readonly PARSE_ERROR: 400;
|
6
|
+
readonly BAD_REQUEST: 400;
|
7
|
+
readonly UNAUTHORIZED: 401;
|
8
|
+
readonly FORBIDDEN: 403;
|
9
|
+
readonly NOT_FOUND: 404;
|
10
|
+
readonly METHOD_NOT_SUPPORTED: 405;
|
11
|
+
readonly TIMEOUT: 408;
|
12
|
+
readonly CONFLICT: 409;
|
13
|
+
readonly PRECONDITION_FAILED: 412;
|
14
|
+
readonly PAYLOAD_TOO_LARGE: 413;
|
15
|
+
readonly UNSUPPORTED_MEDIA_TYPE: 415;
|
16
|
+
readonly UNPROCESSABLE_CONTENT: 422;
|
17
|
+
readonly TOO_MANY_REQUESTS: 429;
|
18
|
+
readonly CLIENT_CLOSED_REQUEST: 499;
|
19
|
+
readonly INTERNAL_SERVER_ERROR: 500;
|
20
|
+
readonly NOT_IMPLEMENTED: 501;
|
21
|
+
readonly BAD_GATEWAY: 502;
|
22
|
+
readonly SERVICE_UNAVAILABLE: 503;
|
23
|
+
readonly GATEWAY_TIMEOUT: 504;
|
24
|
+
};
|
25
|
+
declare const RPC_ERROR_KEY: {
|
26
|
+
readonly 400: "PARSE_ERROR";
|
27
|
+
readonly 401: "UNAUTHORIZED";
|
28
|
+
readonly 403: "FORBIDDEN";
|
29
|
+
readonly 404: "NOT_FOUND";
|
30
|
+
readonly 405: "METHOD_NOT_SUPPORTED";
|
31
|
+
readonly 408: "TIMEOUT";
|
32
|
+
readonly 409: "CONFLICT";
|
33
|
+
readonly 412: "PRECONDITION_FAILED";
|
34
|
+
readonly 413: "PAYLOAD_TOO_LARGE";
|
35
|
+
readonly 415: "UNSUPPORTED_MEDIA_TYPE";
|
36
|
+
readonly 422: "UNPROCESSABLE_CONTENT";
|
37
|
+
readonly 429: "TOO_MANY_REQUESTS";
|
38
|
+
readonly 499: "CLIENT_CLOSED_REQUEST";
|
39
|
+
readonly 500: "INTERNAL_SERVER_ERROR";
|
40
|
+
readonly 501: "NOT_IMPLEMENTED";
|
41
|
+
readonly 502: "BAD_GATEWAY";
|
42
|
+
readonly 503: "SERVICE_UNAVAILABLE";
|
43
|
+
readonly 504: "GATEWAY_TIMEOUT";
|
44
|
+
};
|
45
|
+
/**
|
46
|
+
* JSON-RPC 2.0 Error codes
|
47
|
+
*
|
48
|
+
* `-32000` to `-32099` are reserved for implementation-defined server-errors.
|
49
|
+
* For tRPC we're copying the last digits of HTTP 4XX errors.
|
50
|
+
*/
|
51
|
+
declare const JSON_RPC_ERROR_CODES_BY_KEY: {
|
52
|
+
/**
|
53
|
+
* Invalid JSON was received by the server.
|
54
|
+
* An error occurred on the server while parsing the JSON text.
|
55
|
+
*/
|
56
|
+
readonly PARSE_ERROR: -32700;
|
57
|
+
/**
|
58
|
+
* The JSON sent is not a valid Request object.
|
59
|
+
*/
|
60
|
+
readonly BAD_REQUEST: -32600;
|
61
|
+
readonly INTERNAL_SERVER_ERROR: -32603;
|
62
|
+
readonly NOT_IMPLEMENTED: -32603;
|
63
|
+
readonly BAD_GATEWAY: -32603;
|
64
|
+
readonly SERVICE_UNAVAILABLE: -32603;
|
65
|
+
readonly GATEWAY_TIMEOUT: -32603;
|
66
|
+
readonly UNAUTHORIZED: -32001;
|
67
|
+
readonly FORBIDDEN: -32003;
|
68
|
+
readonly NOT_FOUND: -32004;
|
69
|
+
readonly METHOD_NOT_SUPPORTED: -32005;
|
70
|
+
readonly TIMEOUT: -32008;
|
71
|
+
readonly CONFLICT: -32009;
|
72
|
+
readonly PRECONDITION_FAILED: -32012;
|
73
|
+
readonly PAYLOAD_TOO_LARGE: -32013;
|
74
|
+
readonly UNSUPPORTED_MEDIA_TYPE: -32015;
|
75
|
+
readonly UNPROCESSABLE_CONTENT: -32022;
|
76
|
+
readonly TOO_MANY_REQUESTS: -32029;
|
77
|
+
readonly CLIENT_CLOSED_REQUEST: -32099;
|
78
|
+
};
|
79
|
+
interface RPCErrorContract {
|
80
|
+
procedure: string | undefined;
|
81
|
+
input: unknown | undefined;
|
82
|
+
issues: ZodIssue[] | undefined;
|
83
|
+
code: keyof typeof RPC_ERROR_CODE;
|
84
|
+
message: string;
|
85
|
+
stack?: string | undefined;
|
86
|
+
cause?: unknown;
|
87
|
+
}
|
88
|
+
|
89
|
+
type MockHandler<I, O> = (input: I) => Promise<O>;
|
90
|
+
type ProcedureHandler<Context, I, O> = (options: {
|
91
|
+
ctx: Context;
|
92
|
+
input: I;
|
93
|
+
}) => Promise<O>;
|
94
|
+
type MiddlewareHandler<ContextIn, ContextOut> = (options: {
|
95
|
+
ctx: ContextIn;
|
96
|
+
}) => Promise<ContextOut>;
|
97
|
+
interface ProcedureMeta<I, O, _Context = unknown> {
|
98
|
+
readonly name: string;
|
99
|
+
readonly method: 'GET' | 'POST';
|
100
|
+
readonly inputSchema: Schema<I>;
|
101
|
+
readonly outputSchema: Schema<O>;
|
102
|
+
}
|
103
|
+
interface Procedure<I, O, _Context = unknown> extends ProcedureMeta<I, O, _Context> {
|
104
|
+
callable: {
|
105
|
+
call(context: unknown, input: I): Promise<O>;
|
106
|
+
try(context: unknown, input: I): ResultAsync<O, RPCErrorContract>;
|
107
|
+
};
|
108
|
+
readonly mocked: boolean;
|
109
|
+
}
|
110
|
+
type InferProcedureInput<P> = P extends Procedure<infer I, any, any> ? I : never;
|
111
|
+
type InferProcedureOutput<P> = P extends Procedure<any, infer O, any> ? O : never;
|
112
|
+
|
113
|
+
type RouterResponse<Data = unknown, Input = unknown> = {
|
114
|
+
result: {
|
115
|
+
data: Data;
|
116
|
+
};
|
117
|
+
} | {
|
118
|
+
message: string;
|
119
|
+
code: number;
|
120
|
+
data: RouterErrorDetails<Input>;
|
121
|
+
};
|
122
|
+
type RouterErrorDetails<Input = unknown> = {
|
123
|
+
code: string;
|
124
|
+
httpStatus: number;
|
125
|
+
message: string;
|
126
|
+
procedure?: string;
|
127
|
+
issues?: ZodIssue[];
|
128
|
+
stack?: string;
|
129
|
+
input?: Input;
|
130
|
+
};
|
131
|
+
|
132
|
+
type Constructor<T> = new (...args: any[]) => T;
|
133
|
+
type AbstractConstructor<T> = abstract new (...args: any[]) => T;
|
134
|
+
type Prettify<T> = {
|
135
|
+
[K in keyof T]: T[K];
|
136
|
+
} & {};
|
137
|
+
|
138
|
+
export { type AbstractConstructor, type Constructor, type InferProcedureInput, type InferProcedureOutput, JSON_RPC_ERROR_CODES_BY_KEY, type MiddlewareHandler, type MockHandler, type Prettify, type Procedure, type ProcedureHandler, type ProcedureMeta, type RPCErrorContract, RPC_ERROR_CODE, RPC_ERROR_KEY, type RouterErrorDetails, type RouterResponse };
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
import { ZodIssue, Schema } from 'zod';
|
2
|
+
import { ResultAsync } from 'neverthrow';
|
3
|
+
|
4
|
+
declare const RPC_ERROR_CODE: {
|
5
|
+
readonly PARSE_ERROR: 400;
|
6
|
+
readonly BAD_REQUEST: 400;
|
7
|
+
readonly UNAUTHORIZED: 401;
|
8
|
+
readonly FORBIDDEN: 403;
|
9
|
+
readonly NOT_FOUND: 404;
|
10
|
+
readonly METHOD_NOT_SUPPORTED: 405;
|
11
|
+
readonly TIMEOUT: 408;
|
12
|
+
readonly CONFLICT: 409;
|
13
|
+
readonly PRECONDITION_FAILED: 412;
|
14
|
+
readonly PAYLOAD_TOO_LARGE: 413;
|
15
|
+
readonly UNSUPPORTED_MEDIA_TYPE: 415;
|
16
|
+
readonly UNPROCESSABLE_CONTENT: 422;
|
17
|
+
readonly TOO_MANY_REQUESTS: 429;
|
18
|
+
readonly CLIENT_CLOSED_REQUEST: 499;
|
19
|
+
readonly INTERNAL_SERVER_ERROR: 500;
|
20
|
+
readonly NOT_IMPLEMENTED: 501;
|
21
|
+
readonly BAD_GATEWAY: 502;
|
22
|
+
readonly SERVICE_UNAVAILABLE: 503;
|
23
|
+
readonly GATEWAY_TIMEOUT: 504;
|
24
|
+
};
|
25
|
+
declare const RPC_ERROR_KEY: {
|
26
|
+
readonly 400: "PARSE_ERROR";
|
27
|
+
readonly 401: "UNAUTHORIZED";
|
28
|
+
readonly 403: "FORBIDDEN";
|
29
|
+
readonly 404: "NOT_FOUND";
|
30
|
+
readonly 405: "METHOD_NOT_SUPPORTED";
|
31
|
+
readonly 408: "TIMEOUT";
|
32
|
+
readonly 409: "CONFLICT";
|
33
|
+
readonly 412: "PRECONDITION_FAILED";
|
34
|
+
readonly 413: "PAYLOAD_TOO_LARGE";
|
35
|
+
readonly 415: "UNSUPPORTED_MEDIA_TYPE";
|
36
|
+
readonly 422: "UNPROCESSABLE_CONTENT";
|
37
|
+
readonly 429: "TOO_MANY_REQUESTS";
|
38
|
+
readonly 499: "CLIENT_CLOSED_REQUEST";
|
39
|
+
readonly 500: "INTERNAL_SERVER_ERROR";
|
40
|
+
readonly 501: "NOT_IMPLEMENTED";
|
41
|
+
readonly 502: "BAD_GATEWAY";
|
42
|
+
readonly 503: "SERVICE_UNAVAILABLE";
|
43
|
+
readonly 504: "GATEWAY_TIMEOUT";
|
44
|
+
};
|
45
|
+
/**
|
46
|
+
* JSON-RPC 2.0 Error codes
|
47
|
+
*
|
48
|
+
* `-32000` to `-32099` are reserved for implementation-defined server-errors.
|
49
|
+
* For tRPC we're copying the last digits of HTTP 4XX errors.
|
50
|
+
*/
|
51
|
+
declare const JSON_RPC_ERROR_CODES_BY_KEY: {
|
52
|
+
/**
|
53
|
+
* Invalid JSON was received by the server.
|
54
|
+
* An error occurred on the server while parsing the JSON text.
|
55
|
+
*/
|
56
|
+
readonly PARSE_ERROR: -32700;
|
57
|
+
/**
|
58
|
+
* The JSON sent is not a valid Request object.
|
59
|
+
*/
|
60
|
+
readonly BAD_REQUEST: -32600;
|
61
|
+
readonly INTERNAL_SERVER_ERROR: -32603;
|
62
|
+
readonly NOT_IMPLEMENTED: -32603;
|
63
|
+
readonly BAD_GATEWAY: -32603;
|
64
|
+
readonly SERVICE_UNAVAILABLE: -32603;
|
65
|
+
readonly GATEWAY_TIMEOUT: -32603;
|
66
|
+
readonly UNAUTHORIZED: -32001;
|
67
|
+
readonly FORBIDDEN: -32003;
|
68
|
+
readonly NOT_FOUND: -32004;
|
69
|
+
readonly METHOD_NOT_SUPPORTED: -32005;
|
70
|
+
readonly TIMEOUT: -32008;
|
71
|
+
readonly CONFLICT: -32009;
|
72
|
+
readonly PRECONDITION_FAILED: -32012;
|
73
|
+
readonly PAYLOAD_TOO_LARGE: -32013;
|
74
|
+
readonly UNSUPPORTED_MEDIA_TYPE: -32015;
|
75
|
+
readonly UNPROCESSABLE_CONTENT: -32022;
|
76
|
+
readonly TOO_MANY_REQUESTS: -32029;
|
77
|
+
readonly CLIENT_CLOSED_REQUEST: -32099;
|
78
|
+
};
|
79
|
+
interface RPCErrorContract {
|
80
|
+
procedure: string | undefined;
|
81
|
+
input: unknown | undefined;
|
82
|
+
issues: ZodIssue[] | undefined;
|
83
|
+
code: keyof typeof RPC_ERROR_CODE;
|
84
|
+
message: string;
|
85
|
+
stack?: string | undefined;
|
86
|
+
cause?: unknown;
|
87
|
+
}
|
88
|
+
|
89
|
+
type MockHandler<I, O> = (input: I) => Promise<O>;
|
90
|
+
type ProcedureHandler<Context, I, O> = (options: {
|
91
|
+
ctx: Context;
|
92
|
+
input: I;
|
93
|
+
}) => Promise<O>;
|
94
|
+
type MiddlewareHandler<ContextIn, ContextOut> = (options: {
|
95
|
+
ctx: ContextIn;
|
96
|
+
}) => Promise<ContextOut>;
|
97
|
+
interface ProcedureMeta<I, O, _Context = unknown> {
|
98
|
+
readonly name: string;
|
99
|
+
readonly method: 'GET' | 'POST';
|
100
|
+
readonly inputSchema: Schema<I>;
|
101
|
+
readonly outputSchema: Schema<O>;
|
102
|
+
}
|
103
|
+
interface Procedure<I, O, _Context = unknown> extends ProcedureMeta<I, O, _Context> {
|
104
|
+
callable: {
|
105
|
+
call(context: unknown, input: I): Promise<O>;
|
106
|
+
try(context: unknown, input: I): ResultAsync<O, RPCErrorContract>;
|
107
|
+
};
|
108
|
+
readonly mocked: boolean;
|
109
|
+
}
|
110
|
+
type InferProcedureInput<P> = P extends Procedure<infer I, any, any> ? I : never;
|
111
|
+
type InferProcedureOutput<P> = P extends Procedure<any, infer O, any> ? O : never;
|
112
|
+
|
113
|
+
type RouterResponse<Data = unknown, Input = unknown> = {
|
114
|
+
result: {
|
115
|
+
data: Data;
|
116
|
+
};
|
117
|
+
} | {
|
118
|
+
message: string;
|
119
|
+
code: number;
|
120
|
+
data: RouterErrorDetails<Input>;
|
121
|
+
};
|
122
|
+
type RouterErrorDetails<Input = unknown> = {
|
123
|
+
code: string;
|
124
|
+
httpStatus: number;
|
125
|
+
message: string;
|
126
|
+
procedure?: string;
|
127
|
+
issues?: ZodIssue[];
|
128
|
+
stack?: string;
|
129
|
+
input?: Input;
|
130
|
+
};
|
131
|
+
|
132
|
+
type Constructor<T> = new (...args: any[]) => T;
|
133
|
+
type AbstractConstructor<T> = abstract new (...args: any[]) => T;
|
134
|
+
type Prettify<T> = {
|
135
|
+
[K in keyof T]: T[K];
|
136
|
+
} & {};
|
137
|
+
|
138
|
+
export { type AbstractConstructor, type Constructor, type InferProcedureInput, type InferProcedureOutput, JSON_RPC_ERROR_CODES_BY_KEY, type MiddlewareHandler, type MockHandler, type Prettify, type Procedure, type ProcedureHandler, type ProcedureMeta, type RPCErrorContract, RPC_ERROR_CODE, RPC_ERROR_KEY, type RouterErrorDetails, type RouterResponse };
|
package/dist/index.js
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
// src/error.ts
|
2
|
+
var RPC_ERROR_CODE = {
|
3
|
+
PARSE_ERROR: 400,
|
4
|
+
BAD_REQUEST: 400,
|
5
|
+
UNAUTHORIZED: 401,
|
6
|
+
FORBIDDEN: 403,
|
7
|
+
NOT_FOUND: 404,
|
8
|
+
METHOD_NOT_SUPPORTED: 405,
|
9
|
+
TIMEOUT: 408,
|
10
|
+
CONFLICT: 409,
|
11
|
+
PRECONDITION_FAILED: 412,
|
12
|
+
PAYLOAD_TOO_LARGE: 413,
|
13
|
+
UNSUPPORTED_MEDIA_TYPE: 415,
|
14
|
+
UNPROCESSABLE_CONTENT: 422,
|
15
|
+
TOO_MANY_REQUESTS: 429,
|
16
|
+
CLIENT_CLOSED_REQUEST: 499,
|
17
|
+
INTERNAL_SERVER_ERROR: 500,
|
18
|
+
NOT_IMPLEMENTED: 501,
|
19
|
+
BAD_GATEWAY: 502,
|
20
|
+
SERVICE_UNAVAILABLE: 503,
|
21
|
+
GATEWAY_TIMEOUT: 504
|
22
|
+
};
|
23
|
+
var RPC_ERROR_KEY = {
|
24
|
+
400: "PARSE_ERROR",
|
25
|
+
401: "UNAUTHORIZED",
|
26
|
+
403: "FORBIDDEN",
|
27
|
+
404: "NOT_FOUND",
|
28
|
+
405: "METHOD_NOT_SUPPORTED",
|
29
|
+
408: "TIMEOUT",
|
30
|
+
409: "CONFLICT",
|
31
|
+
412: "PRECONDITION_FAILED",
|
32
|
+
413: "PAYLOAD_TOO_LARGE",
|
33
|
+
415: "UNSUPPORTED_MEDIA_TYPE",
|
34
|
+
422: "UNPROCESSABLE_CONTENT",
|
35
|
+
429: "TOO_MANY_REQUESTS",
|
36
|
+
499: "CLIENT_CLOSED_REQUEST",
|
37
|
+
500: "INTERNAL_SERVER_ERROR",
|
38
|
+
501: "NOT_IMPLEMENTED",
|
39
|
+
502: "BAD_GATEWAY",
|
40
|
+
503: "SERVICE_UNAVAILABLE",
|
41
|
+
504: "GATEWAY_TIMEOUT"
|
42
|
+
};
|
43
|
+
var JSON_RPC_ERROR_CODES_BY_KEY = {
|
44
|
+
/**
|
45
|
+
* Invalid JSON was received by the server.
|
46
|
+
* An error occurred on the server while parsing the JSON text.
|
47
|
+
*/
|
48
|
+
PARSE_ERROR: -32700,
|
49
|
+
/**
|
50
|
+
* The JSON sent is not a valid Request object.
|
51
|
+
*/
|
52
|
+
BAD_REQUEST: -32600,
|
53
|
+
// 400
|
54
|
+
// Internal JSON-RPC error
|
55
|
+
INTERNAL_SERVER_ERROR: -32603,
|
56
|
+
// 500
|
57
|
+
NOT_IMPLEMENTED: -32603,
|
58
|
+
// 501
|
59
|
+
BAD_GATEWAY: -32603,
|
60
|
+
// 502
|
61
|
+
SERVICE_UNAVAILABLE: -32603,
|
62
|
+
// 503
|
63
|
+
GATEWAY_TIMEOUT: -32603,
|
64
|
+
// 504
|
65
|
+
// Implementation specific errors
|
66
|
+
UNAUTHORIZED: -32001,
|
67
|
+
// 401
|
68
|
+
FORBIDDEN: -32003,
|
69
|
+
// 403
|
70
|
+
NOT_FOUND: -32004,
|
71
|
+
// 404
|
72
|
+
METHOD_NOT_SUPPORTED: -32005,
|
73
|
+
// 405
|
74
|
+
TIMEOUT: -32008,
|
75
|
+
// 408
|
76
|
+
CONFLICT: -32009,
|
77
|
+
// 409
|
78
|
+
PRECONDITION_FAILED: -32012,
|
79
|
+
// 412
|
80
|
+
PAYLOAD_TOO_LARGE: -32013,
|
81
|
+
// 413
|
82
|
+
UNSUPPORTED_MEDIA_TYPE: -32015,
|
83
|
+
// 415
|
84
|
+
UNPROCESSABLE_CONTENT: -32022,
|
85
|
+
// 422
|
86
|
+
TOO_MANY_REQUESTS: -32029,
|
87
|
+
// 429
|
88
|
+
CLIENT_CLOSED_REQUEST: -32099
|
89
|
+
// 499
|
90
|
+
};
|
91
|
+
|
92
|
+
// src/router/types.ts
|
93
|
+
import "zod";
|
94
|
+
export {
|
95
|
+
JSON_RPC_ERROR_CODES_BY_KEY,
|
96
|
+
RPC_ERROR_CODE,
|
97
|
+
RPC_ERROR_KEY
|
98
|
+
};
|
package/package.json
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
{
|
2
|
+
"name": "@pl4dr/rpc-core",
|
3
|
+
"version": "1001.0.0",
|
4
|
+
"description": "RPC Core",
|
5
|
+
"author": "Chan Nyein Thaw<me@chanyeinthaw.com>",
|
6
|
+
"type": "module",
|
7
|
+
"main": "dist/index.js",
|
8
|
+
"files": [
|
9
|
+
"dist"
|
10
|
+
],
|
11
|
+
"repository": {
|
12
|
+
"type": "git",
|
13
|
+
"url": "git+https://github.com/pl4dr/rpc"
|
14
|
+
},
|
15
|
+
"exports": {
|
16
|
+
"./package.json": "./package.json",
|
17
|
+
".": {
|
18
|
+
"import": "./dist/index.js",
|
19
|
+
"default": "./dist/index.cjs"
|
20
|
+
}
|
21
|
+
},
|
22
|
+
"devDependencies": {
|
23
|
+
"typescript": "*"
|
24
|
+
},
|
25
|
+
"dependencies": {
|
26
|
+
"neverthrow": "*",
|
27
|
+
"superjson": "*",
|
28
|
+
"zod": "*"
|
29
|
+
},
|
30
|
+
"scripts": {
|
31
|
+
"lint": "tsc",
|
32
|
+
"build": "tsup",
|
33
|
+
"format": "prettier --write .",
|
34
|
+
"check:format": "prettier --check .",
|
35
|
+
"check:exports": "attw --pack . --ignore-rules=cjs-resolves-to-esm"
|
36
|
+
}
|
37
|
+
}
|