@orpc/client 0.0.0-next.c0dd7cd → 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 +31 -22
- package/dist/adapters/fetch/index.d.mts +31 -15
- package/dist/adapters/fetch/index.d.ts +31 -15
- package/dist/adapters/fetch/index.mjs +26 -18
- 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 +9 -103
- package/dist/adapters/standard/index.d.ts +9 -103
- package/dist/adapters/standard/index.mjs +3 -3
- 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 +107 -27
- package/dist/index.d.ts +107 -27
- package/dist/index.mjs +84 -36
- package/dist/plugins/index.d.mts +166 -25
- package/dist/plugins/index.d.ts +166 -25
- package/dist/plugins/index.mjs +341 -61
- package/dist/shared/client.BG98rYdO.d.ts +45 -0
- package/dist/shared/client.BOYsZIRq.d.mts +29 -0
- package/dist/shared/client.BOYsZIRq.d.ts +29 -0
- package/dist/shared/client.Bwgm6dgk.d.mts +45 -0
- package/dist/shared/{client.Be-O_tdu.mjs → client.Bx-B_kf6.mjs} +106 -40
- package/dist/shared/client.CVVVqf1Y.d.ts +91 -0
- package/dist/shared/client.ZLgATkMs.mjs +208 -0
- package/dist/shared/client._Y_enhib.d.mts +91 -0
- package/package.json +16 -5
- package/dist/shared/client.BacCdg3F.mjs +0 -172
- package/dist/shared/client.CupM8eRP.d.mts +0 -30
- package/dist/shared/client.CupM8eRP.d.ts +0 -30
- package/dist/shared/client.CvnV7_uV.mjs +0 -12
- package/dist/shared/client.DrOAzyMB.d.mts +0 -45
- package/dist/shared/client.aGal-uGY.d.ts +0 -45
|
@@ -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 ClientOptions<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?: ClientOptions<TClientContext>] : [input: TInput, options?: ClientOptions<TClientContext>] : [input: TInput, options: ClientOptions<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 ClientOptionsOut<TClientContext extends ClientContext> = ClientOptions<TClientContext> & {
|
|
24
|
-
context: TClientContext;
|
|
25
|
-
};
|
|
26
|
-
interface ClientLink<TClientContext extends ClientContext> {
|
|
27
|
-
call: (path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>) => Promise<unknown>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export type { ClientOptionsOut as C, InferClientContext as I, NestedClient as N, ClientContext as a, ClientLink as b, ClientPromiseResult as c, ClientOptions as d, ClientRest as e, Client as f };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
type ClientContext = Record<string, any>;
|
|
2
|
-
type ClientOptions<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?: ClientOptions<TClientContext>] : [input: TInput, options?: ClientOptions<TClientContext>] : [input: TInput, options: ClientOptions<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 ClientOptionsOut<TClientContext extends ClientContext> = ClientOptions<TClientContext> & {
|
|
24
|
-
context: TClientContext;
|
|
25
|
-
};
|
|
26
|
-
interface ClientLink<TClientContext extends ClientContext> {
|
|
27
|
-
call: (path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>) => Promise<unknown>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export type { ClientOptionsOut as C, InferClientContext as I, NestedClient as N, ClientContext as a, ClientLink as b, ClientPromiseResult as c, ClientOptions as d, ClientRest as e, Client as f };
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Interceptor } from '@orpc/shared';
|
|
2
|
-
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
3
|
-
import { a as ClientContext, C as ClientOptionsOut, b as ClientLink } from './client.CupM8eRP.mjs';
|
|
4
|
-
|
|
5
|
-
interface StandardLinkCodec<T extends ClientContext> {
|
|
6
|
-
encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
|
|
7
|
-
decode(response: StandardLazyResponse, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<unknown>;
|
|
8
|
-
}
|
|
9
|
-
interface StandardLinkClient<T extends ClientContext> {
|
|
10
|
-
call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
declare class InvalidEventIteratorRetryResponse extends Error {
|
|
14
|
-
}
|
|
15
|
-
interface StandardLinkOptions<T extends ClientContext> {
|
|
16
|
-
interceptors?: Interceptor<{
|
|
17
|
-
path: readonly string[];
|
|
18
|
-
input: unknown;
|
|
19
|
-
options: ClientOptionsOut<T>;
|
|
20
|
-
}, unknown, unknown>[];
|
|
21
|
-
clientInterceptors?: Interceptor<{
|
|
22
|
-
request: StandardRequest;
|
|
23
|
-
}, StandardLazyResponse, unknown>[];
|
|
24
|
-
plugins?: ClientPlugin<T>[];
|
|
25
|
-
}
|
|
26
|
-
declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
27
|
-
#private;
|
|
28
|
-
readonly codec: StandardLinkCodec<T>;
|
|
29
|
-
readonly sender: StandardLinkClient<T>;
|
|
30
|
-
private readonly interceptors;
|
|
31
|
-
private readonly clientInterceptors;
|
|
32
|
-
constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
|
|
33
|
-
call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
interface ClientPlugin<T extends ClientContext> {
|
|
37
|
-
init?(options: StandardLinkOptions<T>): void;
|
|
38
|
-
}
|
|
39
|
-
declare class CompositeClientPlugin<T extends ClientContext> implements ClientPlugin<T> {
|
|
40
|
-
private readonly plugins;
|
|
41
|
-
constructor(plugins?: ClientPlugin<T>[]);
|
|
42
|
-
init(options: StandardLinkOptions<T>): void;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export { type ClientPlugin as C, InvalidEventIteratorRetryResponse as I, type StandardLinkOptions as S, CompositeClientPlugin as a, type StandardLinkClient as b, type StandardLinkCodec as c, StandardLink as d };
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Interceptor } from '@orpc/shared';
|
|
2
|
-
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
3
|
-
import { a as ClientContext, C as ClientOptionsOut, b as ClientLink } from './client.CupM8eRP.js';
|
|
4
|
-
|
|
5
|
-
interface StandardLinkCodec<T extends ClientContext> {
|
|
6
|
-
encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
|
|
7
|
-
decode(response: StandardLazyResponse, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<unknown>;
|
|
8
|
-
}
|
|
9
|
-
interface StandardLinkClient<T extends ClientContext> {
|
|
10
|
-
call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
declare class InvalidEventIteratorRetryResponse extends Error {
|
|
14
|
-
}
|
|
15
|
-
interface StandardLinkOptions<T extends ClientContext> {
|
|
16
|
-
interceptors?: Interceptor<{
|
|
17
|
-
path: readonly string[];
|
|
18
|
-
input: unknown;
|
|
19
|
-
options: ClientOptionsOut<T>;
|
|
20
|
-
}, unknown, unknown>[];
|
|
21
|
-
clientInterceptors?: Interceptor<{
|
|
22
|
-
request: StandardRequest;
|
|
23
|
-
}, StandardLazyResponse, unknown>[];
|
|
24
|
-
plugins?: ClientPlugin<T>[];
|
|
25
|
-
}
|
|
26
|
-
declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
27
|
-
#private;
|
|
28
|
-
readonly codec: StandardLinkCodec<T>;
|
|
29
|
-
readonly sender: StandardLinkClient<T>;
|
|
30
|
-
private readonly interceptors;
|
|
31
|
-
private readonly clientInterceptors;
|
|
32
|
-
constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
|
|
33
|
-
call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
interface ClientPlugin<T extends ClientContext> {
|
|
37
|
-
init?(options: StandardLinkOptions<T>): void;
|
|
38
|
-
}
|
|
39
|
-
declare class CompositeClientPlugin<T extends ClientContext> implements ClientPlugin<T> {
|
|
40
|
-
private readonly plugins;
|
|
41
|
-
constructor(plugins?: ClientPlugin<T>[]);
|
|
42
|
-
init(options: StandardLinkOptions<T>): void;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export { type ClientPlugin as C, InvalidEventIteratorRetryResponse as I, type StandardLinkOptions as S, CompositeClientPlugin as a, type StandardLinkClient as b, type StandardLinkCodec as c, StandardLink as d };
|