@orpc/client 0.0.0-next.a419c18 → 0.0.0-next.a45fc95
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 +145 -34
- package/dist/adapters/fetch/index.d.mts +31 -15
- package/dist/adapters/fetch/index.d.ts +31 -15
- package/dist/adapters/fetch/index.mjs +27 -17
- package/dist/adapters/message-port/index.d.mts +80 -0
- package/dist/adapters/message-port/index.d.ts +80 -0
- package/dist/adapters/message-port/index.mjs +87 -0
- package/dist/adapters/standard/index.d.mts +9 -103
- package/dist/adapters/standard/index.d.ts +9 -103
- package/dist/adapters/standard/index.mjs +4 -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 +47 -0
- package/dist/index.d.mts +106 -27
- package/dist/index.d.ts +106 -27
- package/dist/index.mjs +61 -14
- package/dist/plugins/index.d.mts +209 -21
- package/dist/plugins/index.d.ts +209 -21
- package/dist/plugins/index.mjs +412 -53
- package/dist/shared/{client.Bt40CWA-.d.ts → client.2jUAqzYU.d.ts} +20 -14
- package/dist/shared/client.B3pNRBih.d.ts +91 -0
- package/dist/shared/client.BFAVy68H.d.mts +91 -0
- package/dist/shared/client.BLtwTQUg.mjs +40 -0
- package/dist/shared/{client.CAwgYDwB.mjs → client.CO7ppLAC.mjs} +109 -39
- package/dist/shared/{client.CKw2tbcl.d.mts → client.CpCa3si8.d.mts} +20 -14
- package/dist/shared/client.i2uoJbEp.d.mts +83 -0
- package/dist/shared/client.i2uoJbEp.d.ts +83 -0
- package/dist/shared/client.mvr4CV9V.mjs +171 -0
- package/package.json +18 -8
- package/dist/shared/client.BacCdg3F.mjs +0 -172
- package/dist/shared/client.RZs5Myak.d.mts +0 -30
- package/dist/shared/client.RZs5Myak.d.ts +0 -30
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { resolveMaybeOptionalOptions, getConstructor, isObject } from '@orpc/shared';
|
|
2
|
+
|
|
3
|
+
const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client";
|
|
4
|
+
const ORPC_CLIENT_PACKAGE_VERSION = "0.0.0-next.a45fc95";
|
|
5
|
+
|
|
6
|
+
const COMMON_ORPC_ERROR_DEFS = {
|
|
7
|
+
BAD_REQUEST: {
|
|
8
|
+
status: 400,
|
|
9
|
+
message: "Bad Request"
|
|
10
|
+
},
|
|
11
|
+
UNAUTHORIZED: {
|
|
12
|
+
status: 401,
|
|
13
|
+
message: "Unauthorized"
|
|
14
|
+
},
|
|
15
|
+
FORBIDDEN: {
|
|
16
|
+
status: 403,
|
|
17
|
+
message: "Forbidden"
|
|
18
|
+
},
|
|
19
|
+
NOT_FOUND: {
|
|
20
|
+
status: 404,
|
|
21
|
+
message: "Not Found"
|
|
22
|
+
},
|
|
23
|
+
METHOD_NOT_SUPPORTED: {
|
|
24
|
+
status: 405,
|
|
25
|
+
message: "Method Not Supported"
|
|
26
|
+
},
|
|
27
|
+
NOT_ACCEPTABLE: {
|
|
28
|
+
status: 406,
|
|
29
|
+
message: "Not Acceptable"
|
|
30
|
+
},
|
|
31
|
+
TIMEOUT: {
|
|
32
|
+
status: 408,
|
|
33
|
+
message: "Request Timeout"
|
|
34
|
+
},
|
|
35
|
+
CONFLICT: {
|
|
36
|
+
status: 409,
|
|
37
|
+
message: "Conflict"
|
|
38
|
+
},
|
|
39
|
+
PRECONDITION_FAILED: {
|
|
40
|
+
status: 412,
|
|
41
|
+
message: "Precondition Failed"
|
|
42
|
+
},
|
|
43
|
+
PAYLOAD_TOO_LARGE: {
|
|
44
|
+
status: 413,
|
|
45
|
+
message: "Payload Too Large"
|
|
46
|
+
},
|
|
47
|
+
UNSUPPORTED_MEDIA_TYPE: {
|
|
48
|
+
status: 415,
|
|
49
|
+
message: "Unsupported Media Type"
|
|
50
|
+
},
|
|
51
|
+
UNPROCESSABLE_CONTENT: {
|
|
52
|
+
status: 422,
|
|
53
|
+
message: "Unprocessable Content"
|
|
54
|
+
},
|
|
55
|
+
TOO_MANY_REQUESTS: {
|
|
56
|
+
status: 429,
|
|
57
|
+
message: "Too Many Requests"
|
|
58
|
+
},
|
|
59
|
+
CLIENT_CLOSED_REQUEST: {
|
|
60
|
+
status: 499,
|
|
61
|
+
message: "Client Closed Request"
|
|
62
|
+
},
|
|
63
|
+
INTERNAL_SERVER_ERROR: {
|
|
64
|
+
status: 500,
|
|
65
|
+
message: "Internal Server Error"
|
|
66
|
+
},
|
|
67
|
+
NOT_IMPLEMENTED: {
|
|
68
|
+
status: 501,
|
|
69
|
+
message: "Not Implemented"
|
|
70
|
+
},
|
|
71
|
+
BAD_GATEWAY: {
|
|
72
|
+
status: 502,
|
|
73
|
+
message: "Bad Gateway"
|
|
74
|
+
},
|
|
75
|
+
SERVICE_UNAVAILABLE: {
|
|
76
|
+
status: 503,
|
|
77
|
+
message: "Service Unavailable"
|
|
78
|
+
},
|
|
79
|
+
GATEWAY_TIMEOUT: {
|
|
80
|
+
status: 504,
|
|
81
|
+
message: "Gateway Timeout"
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
function fallbackORPCErrorStatus(code, status) {
|
|
85
|
+
return status ?? COMMON_ORPC_ERROR_DEFS[code]?.status ?? 500;
|
|
86
|
+
}
|
|
87
|
+
function fallbackORPCErrorMessage(code, message) {
|
|
88
|
+
return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
|
|
89
|
+
}
|
|
90
|
+
const GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL = Symbol.for(`__${ORPC_CLIENT_PACKAGE_NAME}@${ORPC_CLIENT_PACKAGE_VERSION}/error/ORPC_ERROR_CONSTRUCTORS__`);
|
|
91
|
+
void (globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL] ??= /* @__PURE__ */ new WeakSet());
|
|
92
|
+
const globalORPCErrorConstructors = globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL];
|
|
93
|
+
class ORPCError extends Error {
|
|
94
|
+
defined;
|
|
95
|
+
code;
|
|
96
|
+
status;
|
|
97
|
+
data;
|
|
98
|
+
constructor(code, ...rest) {
|
|
99
|
+
const options = resolveMaybeOptionalOptions(rest);
|
|
100
|
+
if (options.status !== void 0 && !isORPCErrorStatus(options.status)) {
|
|
101
|
+
throw new Error("[ORPCError] Invalid error status code.");
|
|
102
|
+
}
|
|
103
|
+
const message = fallbackORPCErrorMessage(code, options.message);
|
|
104
|
+
super(message, options);
|
|
105
|
+
this.code = code;
|
|
106
|
+
this.status = fallbackORPCErrorStatus(code, options.status);
|
|
107
|
+
this.defined = options.defined ?? false;
|
|
108
|
+
this.data = options.data;
|
|
109
|
+
}
|
|
110
|
+
toJSON() {
|
|
111
|
+
return {
|
|
112
|
+
defined: this.defined,
|
|
113
|
+
code: this.code,
|
|
114
|
+
status: this.status,
|
|
115
|
+
message: this.message,
|
|
116
|
+
data: this.data
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Workaround for Next.js where different contexts use separate
|
|
121
|
+
* dependency graphs, causing multiple ORPCError constructors existing and breaking
|
|
122
|
+
* `instanceof` checks across contexts.
|
|
123
|
+
*
|
|
124
|
+
* This is particularly problematic with "Optimized SSR", where orpc-client
|
|
125
|
+
* executes in one context but is invoked from another. When an error is thrown
|
|
126
|
+
* in the execution context, `instanceof ORPCError` checks fail in the
|
|
127
|
+
* invocation context due to separate class constructors.
|
|
128
|
+
*
|
|
129
|
+
* @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
|
|
130
|
+
*/
|
|
131
|
+
static [Symbol.hasInstance](instance) {
|
|
132
|
+
if (globalORPCErrorConstructors.has(this)) {
|
|
133
|
+
const constructor = getConstructor(instance);
|
|
134
|
+
if (constructor && globalORPCErrorConstructors.has(constructor)) {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return super[Symbol.hasInstance](instance);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
globalORPCErrorConstructors.add(ORPCError);
|
|
142
|
+
function isDefinedError(error) {
|
|
143
|
+
return error instanceof ORPCError && error.defined;
|
|
144
|
+
}
|
|
145
|
+
function toORPCError(error) {
|
|
146
|
+
return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", {
|
|
147
|
+
message: "Internal server error",
|
|
148
|
+
cause: error
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function isORPCErrorStatus(status) {
|
|
152
|
+
return status < 200 || status >= 400;
|
|
153
|
+
}
|
|
154
|
+
function isORPCErrorJson(json) {
|
|
155
|
+
if (!isObject(json)) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
const validKeys = ["defined", "code", "status", "message", "data"];
|
|
159
|
+
if (Object.keys(json).some((k) => !validKeys.includes(k))) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
return "defined" in json && typeof json.defined === "boolean" && "code" in json && typeof json.code === "string" && "status" in json && typeof json.status === "number" && isORPCErrorStatus(json.status) && "message" in json && typeof json.message === "string";
|
|
163
|
+
}
|
|
164
|
+
function createORPCErrorFromJson(json, options = {}) {
|
|
165
|
+
return new ORPCError(json.code, {
|
|
166
|
+
...options,
|
|
167
|
+
...json
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export { COMMON_ORPC_ERROR_DEFS as C, ORPC_CLIENT_PACKAGE_NAME as O, ORPC_CLIENT_PACKAGE_VERSION as a, fallbackORPCErrorMessage as b, ORPCError as c, isORPCErrorStatus as d, isORPCErrorJson as e, fallbackORPCErrorStatus as f, createORPCErrorFromJson as g, isDefinedError as i, toORPCError as t };
|
package/package.json
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/client",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.a45fc95",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"homepage": "https://orpc.
|
|
6
|
+
"homepage": "https://orpc.dev",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/
|
|
9
|
+
"url": "git+https://github.com/middleapi/orpc.git",
|
|
10
10
|
"directory": "packages/client"
|
|
11
11
|
},
|
|
12
12
|
"keywords": [
|
|
13
|
-
"unnoq",
|
|
14
13
|
"orpc"
|
|
15
14
|
],
|
|
16
15
|
"exports": {
|
|
@@ -33,18 +32,29 @@
|
|
|
33
32
|
"types": "./dist/adapters/fetch/index.d.mts",
|
|
34
33
|
"import": "./dist/adapters/fetch/index.mjs",
|
|
35
34
|
"default": "./dist/adapters/fetch/index.mjs"
|
|
35
|
+
},
|
|
36
|
+
"./websocket": {
|
|
37
|
+
"types": "./dist/adapters/websocket/index.d.mts",
|
|
38
|
+
"import": "./dist/adapters/websocket/index.mjs",
|
|
39
|
+
"default": "./dist/adapters/websocket/index.mjs"
|
|
40
|
+
},
|
|
41
|
+
"./message-port": {
|
|
42
|
+
"types": "./dist/adapters/message-port/index.d.mts",
|
|
43
|
+
"import": "./dist/adapters/message-port/index.mjs",
|
|
44
|
+
"default": "./dist/adapters/message-port/index.mjs"
|
|
36
45
|
}
|
|
37
46
|
},
|
|
38
47
|
"files": [
|
|
39
48
|
"dist"
|
|
40
49
|
],
|
|
41
50
|
"dependencies": {
|
|
42
|
-
"@orpc/standard-server": "0.0.0-next.
|
|
43
|
-
"@orpc/standard-server-fetch": "0.0.0-next.
|
|
44
|
-
"@orpc/shared": "0.0.0-next.
|
|
51
|
+
"@orpc/standard-server": "0.0.0-next.a45fc95",
|
|
52
|
+
"@orpc/standard-server-fetch": "0.0.0-next.a45fc95",
|
|
53
|
+
"@orpc/shared": "0.0.0-next.a45fc95",
|
|
54
|
+
"@orpc/standard-server-peer": "0.0.0-next.a45fc95"
|
|
45
55
|
},
|
|
46
56
|
"devDependencies": {
|
|
47
|
-
"zod": "^3.
|
|
57
|
+
"zod": "^4.3.6"
|
|
48
58
|
},
|
|
49
59
|
"scripts": {
|
|
50
60
|
"build": "unbuild",
|
|
@@ -1,172 +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 && (options.status < 400 || options.status >= 600)) {
|
|
95
|
-
throw new Error("[ORPCError] The error status code must be in the 400-599 range.");
|
|
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
|
-
|
|
140
|
-
function mapEventIterator(iterator, maps) {
|
|
141
|
-
return async function* () {
|
|
142
|
-
try {
|
|
143
|
-
while (true) {
|
|
144
|
-
const { done, value } = await iterator.next();
|
|
145
|
-
let mappedValue = await maps.value(value, done);
|
|
146
|
-
if (mappedValue !== value) {
|
|
147
|
-
const meta = getEventMeta(value);
|
|
148
|
-
if (meta && isTypescriptObject(mappedValue)) {
|
|
149
|
-
mappedValue = withEventMeta(mappedValue, meta);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
if (done) {
|
|
153
|
-
return mappedValue;
|
|
154
|
-
}
|
|
155
|
-
yield mappedValue;
|
|
156
|
-
}
|
|
157
|
-
} catch (error) {
|
|
158
|
-
let mappedError = await maps.error(error);
|
|
159
|
-
if (mappedError !== error) {
|
|
160
|
-
const meta = getEventMeta(error);
|
|
161
|
-
if (meta && isTypescriptObject(mappedError)) {
|
|
162
|
-
mappedError = withEventMeta(mappedError, meta);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
throw mappedError;
|
|
166
|
-
} finally {
|
|
167
|
-
await iterator.return?.();
|
|
168
|
-
}
|
|
169
|
-
}();
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export { COMMON_ORPC_ERROR_DEFS as C, ORPCError as O, fallbackORPCErrorMessage as a, fallbackORPCErrorStatus as f, isDefinedError as i, mapEventIterator as m, toORPCError as t };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
type ClientContext = Record<string, any>;
|
|
2
|
-
type FriendlyClientOptions<TClientContext extends ClientContext> = {
|
|
3
|
-
signal?: AbortSignal;
|
|
4
|
-
lastEventId?: string | undefined;
|
|
5
|
-
} & (Record<never, never> extends TClientContext ? {
|
|
6
|
-
context?: TClientContext;
|
|
7
|
-
} : {
|
|
8
|
-
context: TClientContext;
|
|
9
|
-
});
|
|
10
|
-
type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
|
|
11
|
-
type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
|
|
12
|
-
__error?: {
|
|
13
|
-
type: TError;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
interface Client<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
|
|
17
|
-
(...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
|
|
18
|
-
}
|
|
19
|
-
type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
|
|
20
|
-
[k: string]: NestedClient<TClientContext>;
|
|
21
|
-
};
|
|
22
|
-
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
|
23
|
-
type ClientOptions<TClientContext extends ClientContext> = FriendlyClientOptions<TClientContext> & {
|
|
24
|
-
context: TClientContext;
|
|
25
|
-
};
|
|
26
|
-
interface ClientLink<TClientContext extends ClientContext> {
|
|
27
|
-
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export type { ClientOptions as C, FriendlyClientOptions as F, InferClientContext as I, NestedClient as N, ClientContext as a, ClientLink as b, ClientPromiseResult as c, ClientRest as d, Client as e };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
type ClientContext = Record<string, any>;
|
|
2
|
-
type FriendlyClientOptions<TClientContext extends ClientContext> = {
|
|
3
|
-
signal?: AbortSignal;
|
|
4
|
-
lastEventId?: string | undefined;
|
|
5
|
-
} & (Record<never, never> extends TClientContext ? {
|
|
6
|
-
context?: TClientContext;
|
|
7
|
-
} : {
|
|
8
|
-
context: TClientContext;
|
|
9
|
-
});
|
|
10
|
-
type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
|
|
11
|
-
type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
|
|
12
|
-
__error?: {
|
|
13
|
-
type: TError;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
interface Client<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
|
|
17
|
-
(...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
|
|
18
|
-
}
|
|
19
|
-
type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
|
|
20
|
-
[k: string]: NestedClient<TClientContext>;
|
|
21
|
-
};
|
|
22
|
-
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
|
23
|
-
type ClientOptions<TClientContext extends ClientContext> = FriendlyClientOptions<TClientContext> & {
|
|
24
|
-
context: TClientContext;
|
|
25
|
-
};
|
|
26
|
-
interface ClientLink<TClientContext extends ClientContext> {
|
|
27
|
-
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export type { ClientOptions as C, FriendlyClientOptions as F, InferClientContext as I, NestedClient as N, ClientContext as a, ClientLink as b, ClientPromiseResult as c, ClientRest as d, Client as e };
|