@orpc/client 0.0.0-next.c0ca4c7 → 0.0.0-next.c112960
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/README.md +22 -22
- package/dist/adapters/fetch/index.d.mts +31 -11
- package/dist/adapters/fetch/index.d.ts +31 -11
- package/dist/adapters/fetch/index.mjs +26 -13
- package/dist/adapters/message-port/index.d.mts +59 -0
- package/dist/adapters/message-port/index.d.ts +59 -0
- package/dist/adapters/message-port/index.mjs +72 -0
- package/dist/adapters/standard/index.d.mts +6 -5
- package/dist/adapters/standard/index.d.ts +6 -5
- package/dist/adapters/standard/index.mjs +3 -2
- package/dist/adapters/websocket/index.d.mts +29 -0
- package/dist/adapters/websocket/index.d.ts +29 -0
- package/dist/adapters/websocket/index.mjs +46 -0
- package/dist/index.d.mts +104 -29
- package/dist/index.d.ts +104 -29
- package/dist/index.mjs +57 -11
- package/dist/plugins/index.d.mts +163 -25
- package/dist/plugins/index.d.ts +163 -25
- package/dist/plugins/index.mjs +332 -56
- package/dist/shared/{client.5813Ufvs.d.mts → client.BG98rYdO.d.ts} +21 -15
- package/dist/shared/{client.C0lT7w02.d.mts → client.BOYsZIRq.d.mts} +8 -9
- package/dist/shared/{client.C0lT7w02.d.ts → client.BOYsZIRq.d.ts} +8 -9
- package/dist/shared/{client.grRbC25r.d.ts → client.Bwgm6dgk.d.mts} +21 -15
- package/dist/shared/{client.DhAxdT4W.mjs → client.Bx-B_kf6.mjs} +90 -29
- package/dist/shared/{client.D-jrSuDb.d.ts → client.CVVVqf1Y.d.ts} +13 -25
- package/dist/shared/client.ZLgATkMs.mjs +208 -0
- package/dist/shared/{client.Bt94sjrK.d.mts → client._Y_enhib.d.mts} +13 -25
- package/package.json +16 -5
- package/dist/shared/client.jKEwIsRd.mjs +0 -175
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { isObject, isTypescriptObject } from '@orpc/shared';
|
|
2
|
-
import { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
|
3
|
-
|
|
4
|
-
const COMMON_ORPC_ERROR_DEFS = {
|
|
5
|
-
BAD_REQUEST: {
|
|
6
|
-
status: 400,
|
|
7
|
-
message: "Bad Request"
|
|
8
|
-
},
|
|
9
|
-
UNAUTHORIZED: {
|
|
10
|
-
status: 401,
|
|
11
|
-
message: "Unauthorized"
|
|
12
|
-
},
|
|
13
|
-
FORBIDDEN: {
|
|
14
|
-
status: 403,
|
|
15
|
-
message: "Forbidden"
|
|
16
|
-
},
|
|
17
|
-
NOT_FOUND: {
|
|
18
|
-
status: 404,
|
|
19
|
-
message: "Not Found"
|
|
20
|
-
},
|
|
21
|
-
METHOD_NOT_SUPPORTED: {
|
|
22
|
-
status: 405,
|
|
23
|
-
message: "Method Not Supported"
|
|
24
|
-
},
|
|
25
|
-
NOT_ACCEPTABLE: {
|
|
26
|
-
status: 406,
|
|
27
|
-
message: "Not Acceptable"
|
|
28
|
-
},
|
|
29
|
-
TIMEOUT: {
|
|
30
|
-
status: 408,
|
|
31
|
-
message: "Request Timeout"
|
|
32
|
-
},
|
|
33
|
-
CONFLICT: {
|
|
34
|
-
status: 409,
|
|
35
|
-
message: "Conflict"
|
|
36
|
-
},
|
|
37
|
-
PRECONDITION_FAILED: {
|
|
38
|
-
status: 412,
|
|
39
|
-
message: "Precondition Failed"
|
|
40
|
-
},
|
|
41
|
-
PAYLOAD_TOO_LARGE: {
|
|
42
|
-
status: 413,
|
|
43
|
-
message: "Payload Too Large"
|
|
44
|
-
},
|
|
45
|
-
UNSUPPORTED_MEDIA_TYPE: {
|
|
46
|
-
status: 415,
|
|
47
|
-
message: "Unsupported Media Type"
|
|
48
|
-
},
|
|
49
|
-
UNPROCESSABLE_CONTENT: {
|
|
50
|
-
status: 422,
|
|
51
|
-
message: "Unprocessable Content"
|
|
52
|
-
},
|
|
53
|
-
TOO_MANY_REQUESTS: {
|
|
54
|
-
status: 429,
|
|
55
|
-
message: "Too Many Requests"
|
|
56
|
-
},
|
|
57
|
-
CLIENT_CLOSED_REQUEST: {
|
|
58
|
-
status: 499,
|
|
59
|
-
message: "Client Closed Request"
|
|
60
|
-
},
|
|
61
|
-
INTERNAL_SERVER_ERROR: {
|
|
62
|
-
status: 500,
|
|
63
|
-
message: "Internal Server Error"
|
|
64
|
-
},
|
|
65
|
-
NOT_IMPLEMENTED: {
|
|
66
|
-
status: 501,
|
|
67
|
-
message: "Not Implemented"
|
|
68
|
-
},
|
|
69
|
-
BAD_GATEWAY: {
|
|
70
|
-
status: 502,
|
|
71
|
-
message: "Bad Gateway"
|
|
72
|
-
},
|
|
73
|
-
SERVICE_UNAVAILABLE: {
|
|
74
|
-
status: 503,
|
|
75
|
-
message: "Service Unavailable"
|
|
76
|
-
},
|
|
77
|
-
GATEWAY_TIMEOUT: {
|
|
78
|
-
status: 504,
|
|
79
|
-
message: "Gateway Timeout"
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
function fallbackORPCErrorStatus(code, status) {
|
|
83
|
-
return status ?? COMMON_ORPC_ERROR_DEFS[code]?.status ?? 500;
|
|
84
|
-
}
|
|
85
|
-
function fallbackORPCErrorMessage(code, message) {
|
|
86
|
-
return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
|
|
87
|
-
}
|
|
88
|
-
class ORPCError extends Error {
|
|
89
|
-
defined;
|
|
90
|
-
code;
|
|
91
|
-
status;
|
|
92
|
-
data;
|
|
93
|
-
constructor(code, ...[options]) {
|
|
94
|
-
if (options?.status && !isORPCErrorStatus(options.status)) {
|
|
95
|
-
throw new Error("[ORPCError] Invalid error status code.");
|
|
96
|
-
}
|
|
97
|
-
const message = fallbackORPCErrorMessage(code, options?.message);
|
|
98
|
-
super(message, options);
|
|
99
|
-
this.code = code;
|
|
100
|
-
this.status = fallbackORPCErrorStatus(code, options?.status);
|
|
101
|
-
this.defined = options?.defined ?? false;
|
|
102
|
-
this.data = options?.data;
|
|
103
|
-
}
|
|
104
|
-
toJSON() {
|
|
105
|
-
return {
|
|
106
|
-
defined: this.defined,
|
|
107
|
-
code: this.code,
|
|
108
|
-
status: this.status,
|
|
109
|
-
message: this.message,
|
|
110
|
-
data: this.data
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
static fromJSON(json, options) {
|
|
114
|
-
return new ORPCError(json.code, {
|
|
115
|
-
...options,
|
|
116
|
-
...json
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
static isValidJSON(json) {
|
|
120
|
-
if (!isObject(json)) {
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
const validKeys = ["defined", "code", "status", "message", "data"];
|
|
124
|
-
if (Object.keys(json).some((k) => !validKeys.includes(k))) {
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
return "defined" in json && typeof json.defined === "boolean" && "code" in json && typeof json.code === "string" && "status" in json && typeof json.status === "number" && "message" in json && typeof json.message === "string";
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
function isDefinedError(error) {
|
|
131
|
-
return error instanceof ORPCError && error.defined;
|
|
132
|
-
}
|
|
133
|
-
function toORPCError(error) {
|
|
134
|
-
return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", {
|
|
135
|
-
message: "Internal server error",
|
|
136
|
-
cause: error
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
function isORPCErrorStatus(status) {
|
|
140
|
-
return status < 200 || status >= 400;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function mapEventIterator(iterator, maps) {
|
|
144
|
-
return async function* () {
|
|
145
|
-
try {
|
|
146
|
-
while (true) {
|
|
147
|
-
const { done, value } = await iterator.next();
|
|
148
|
-
let mappedValue = await maps.value(value, done);
|
|
149
|
-
if (mappedValue !== value) {
|
|
150
|
-
const meta = getEventMeta(value);
|
|
151
|
-
if (meta && isTypescriptObject(mappedValue)) {
|
|
152
|
-
mappedValue = withEventMeta(mappedValue, meta);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
if (done) {
|
|
156
|
-
return mappedValue;
|
|
157
|
-
}
|
|
158
|
-
yield mappedValue;
|
|
159
|
-
}
|
|
160
|
-
} catch (error) {
|
|
161
|
-
let mappedError = await maps.error(error);
|
|
162
|
-
if (mappedError !== error) {
|
|
163
|
-
const meta = getEventMeta(error);
|
|
164
|
-
if (meta && isTypescriptObject(mappedError)) {
|
|
165
|
-
mappedError = withEventMeta(mappedError, meta);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
throw mappedError;
|
|
169
|
-
} finally {
|
|
170
|
-
await iterator.return?.();
|
|
171
|
-
}
|
|
172
|
-
}();
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
export { COMMON_ORPC_ERROR_DEFS as C, ORPCError as O, fallbackORPCErrorMessage as a, isORPCErrorStatus as b, fallbackORPCErrorStatus as f, isDefinedError as i, mapEventIterator as m, toORPCError as t };
|