@orpc/client 1.14.11 → 1.14.12
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 +68 -52
- package/dist/adapters/fetch/index.d.mts +35 -54
- package/dist/adapters/fetch/index.d.ts +35 -54
- package/dist/adapters/fetch/index.mjs +27 -74
- package/dist/adapters/message-port/index.d.mts +30 -25
- package/dist/adapters/message-port/index.d.ts +30 -25
- package/dist/adapters/message-port/index.mjs +30 -39
- package/dist/adapters/standard/index.d.mts +9 -59
- package/dist/adapters/standard/index.d.ts +9 -59
- package/dist/adapters/standard/index.mjs +5 -5
- package/dist/adapters/websocket/index.d.mts +21 -113
- package/dist/adapters/websocket/index.d.ts +21 -113
- package/dist/adapters/websocket/index.mjs +37 -95
- package/dist/index.d.mts +184 -75
- package/dist/index.d.ts +184 -75
- package/dist/index.mjs +63 -74
- package/dist/plugins/index.d.mts +122 -191
- package/dist/plugins/index.d.ts +122 -191
- package/dist/plugins/index.mjs +281 -627
- package/dist/shared/client.2jUAqzYU.d.ts +45 -0
- 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.C1VUaWTu.mjs +404 -0
- package/dist/shared/client.CpCa3si8.d.mts +45 -0
- package/dist/shared/client.DrCRv_sG.mjs +174 -0
- package/dist/shared/client.i2uoJbEp.d.mts +83 -0
- package/dist/shared/client.i2uoJbEp.d.ts +83 -0
- package/package.json +7 -7
- package/dist/shared/client.8f4DNmdE.d.mts +0 -96
- package/dist/shared/client.BBZBQID8.d.mts +0 -167
- package/dist/shared/client.BBZBQID8.d.ts +0 -167
- package/dist/shared/client.BMKYqpdy.d.ts +0 -96
- package/dist/shared/client.BRJnOJ0R.mjs +0 -174
- package/dist/shared/client.BdItY5DT.d.mts +0 -111
- package/dist/shared/client.BdItY5DT.d.ts +0 -111
- package/dist/shared/client.Dnfj8jnT.mjs +0 -92
- package/dist/shared/client.DqYwRDUO.mjs +0 -343
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { PromiseWithError, Registry, MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
-
|
|
3
|
-
interface ClientContext {
|
|
4
|
-
[key: PropertyKey]: any;
|
|
5
|
-
}
|
|
6
|
-
interface ClientOptions<T extends ClientContext> {
|
|
7
|
-
signal?: AbortSignal | undefined;
|
|
8
|
-
lastEventId?: string | undefined;
|
|
9
|
-
context: T;
|
|
10
|
-
}
|
|
11
|
-
type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (object extends T ? {
|
|
12
|
-
context?: T;
|
|
13
|
-
} : {
|
|
14
|
-
context: T;
|
|
15
|
-
});
|
|
16
|
-
type ClientRest<TClientContext extends ClientContext, TInput> = object extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
|
|
17
|
-
interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
18
|
-
(...rest: ClientRest<TClientContext, TInput>): PromiseWithError<TOutput, TError>;
|
|
19
|
-
}
|
|
20
|
-
type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
|
|
21
|
-
[k: string]: NestedClient<TClientContext>;
|
|
22
|
-
};
|
|
23
|
-
type AnyNestedClient = NestedClient<any>;
|
|
24
|
-
type InferClientContext<T extends AnyNestedClient> = T extends NestedClient<infer U> ? U : never;
|
|
25
|
-
interface ClientLink<TClientContext extends ClientContext> {
|
|
26
|
-
call: (path: string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Recursively infers the **input types** from a client.
|
|
30
|
-
*
|
|
31
|
-
* Produces a nested map where each endpoint's input type is preserved.
|
|
32
|
-
*/
|
|
33
|
-
type InferClientInputs<T extends AnyNestedClient> = T extends Client<any, infer U, any, any> ? U : {
|
|
34
|
-
[K in keyof T]: T[K] extends AnyNestedClient ? InferClientInputs<T[K]> : never;
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Recursively infers the **body input types** from a client.
|
|
38
|
-
*
|
|
39
|
-
* If an endpoint's input includes `{ body: ... }`, only the `body` portion is extracted.
|
|
40
|
-
* Produces a nested map of body input types.
|
|
41
|
-
*/
|
|
42
|
-
type InferClientBodyInputs<T extends AnyNestedClient> = T extends Client<any, infer U, any, any> ? U extends {
|
|
43
|
-
body: infer UBody;
|
|
44
|
-
} ? UBody : U : {
|
|
45
|
-
[K in keyof T]: T[K] extends AnyNestedClient ? InferClientBodyInputs<T[K]> : never;
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* Recursively infers the **output types** from a client.
|
|
49
|
-
*
|
|
50
|
-
* Produces a nested map where each endpoint's output type is preserved.
|
|
51
|
-
*/
|
|
52
|
-
type InferClientOutputs<T extends AnyNestedClient> = T extends Client<any, any, infer U, any> ? U : {
|
|
53
|
-
[K in keyof T]: T[K] extends AnyNestedClient ? InferClientOutputs<T[K]> : never;
|
|
54
|
-
};
|
|
55
|
-
/**
|
|
56
|
-
* Recursively infers the **body output types** from a client.
|
|
57
|
-
*
|
|
58
|
-
* If an endpoint's output includes `{ body: ... }`, only the `body` portion is extracted.
|
|
59
|
-
* Produces a nested map of body output types.
|
|
60
|
-
*/
|
|
61
|
-
type InferClientBodyOutputs<T extends AnyNestedClient> = T extends Client<any, any, infer U, any> ? U extends {
|
|
62
|
-
body: infer UBody;
|
|
63
|
-
} ? UBody : U : {
|
|
64
|
-
[K in keyof T]: T[K] extends AnyNestedClient ? InferClientBodyOutputs<T[K]> : never;
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* Recursively infers the **error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#type‐safe-error-handling).
|
|
68
|
-
*
|
|
69
|
-
* Produces a nested map where each endpoint's error type is preserved.
|
|
70
|
-
*/
|
|
71
|
-
type InferClientErrors<T extends AnyNestedClient> = T extends Client<any, any, any, infer U> ? U : {
|
|
72
|
-
[K in keyof T]: T[K] extends AnyNestedClient ? InferClientErrors<T[K]> : never;
|
|
73
|
-
};
|
|
74
|
-
/**
|
|
75
|
-
* Recursively infers a **union of all error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#type‐safe-error-handling).
|
|
76
|
-
*
|
|
77
|
-
* Useful when you want to handle all possible errors from any endpoint at once.
|
|
78
|
-
*/
|
|
79
|
-
type InferClientError<T extends AnyNestedClient> = T extends Client<any, any, any, infer U> ? U : {
|
|
80
|
-
[K in keyof T]: T[K] extends AnyNestedClient ? InferClientError<T[K]> : never;
|
|
81
|
-
}[keyof T];
|
|
82
|
-
|
|
83
|
-
declare const COMMON_ERROR_STATUS_MAP: {
|
|
84
|
-
BAD_REQUEST: number;
|
|
85
|
-
UNAUTHORIZED: number;
|
|
86
|
-
PAYMENT_REQUIRED: number;
|
|
87
|
-
FORBIDDEN: number;
|
|
88
|
-
NOT_FOUND: number;
|
|
89
|
-
METHOD_NOT_SUPPORTED: number;
|
|
90
|
-
NOT_ACCEPTABLE: number;
|
|
91
|
-
TIMEOUT: number;
|
|
92
|
-
CONFLICT: number;
|
|
93
|
-
GONE: number;
|
|
94
|
-
PRECONDITION_FAILED: number;
|
|
95
|
-
PAYLOAD_TOO_LARGE: number;
|
|
96
|
-
UNSUPPORTED_MEDIA_TYPE: number;
|
|
97
|
-
UNPROCESSABLE_CONTENT: number;
|
|
98
|
-
PRECONDITION_REQUIRED: number;
|
|
99
|
-
TOO_MANY_REQUESTS: number;
|
|
100
|
-
CLIENT_CLOSED_REQUEST: number;
|
|
101
|
-
INTERNAL_SERVER_ERROR: number;
|
|
102
|
-
NOT_IMPLEMENTED: number;
|
|
103
|
-
BAD_GATEWAY: number;
|
|
104
|
-
SERVICE_UNAVAILABLE: number;
|
|
105
|
-
GATEWAY_TIMEOUT: number;
|
|
106
|
-
};
|
|
107
|
-
type ORPCErrorCode = Registry extends {
|
|
108
|
-
ORPCErrorCode: infer T extends string;
|
|
109
|
-
} ? T : (keyof typeof COMMON_ERROR_STATUS_MAP) | (string & {});
|
|
110
|
-
type ORPCErrorOptions<TData> = ErrorOptions & {
|
|
111
|
-
message?: string;
|
|
112
|
-
} & (undefined extends TData ? {
|
|
113
|
-
data?: TData;
|
|
114
|
-
} : {
|
|
115
|
-
data: TData;
|
|
116
|
-
});
|
|
117
|
-
declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
|
|
118
|
-
/**
|
|
119
|
-
* @info
|
|
120
|
-
* The `__branch` property is used for type branding, helping TypeScript distinguish
|
|
121
|
-
* an `ORPCError` instance from plain objects with a similar structure.
|
|
122
|
-
*/
|
|
123
|
-
readonly name: "ORPCError" & {
|
|
124
|
-
__branch: "ORPCError";
|
|
125
|
-
};
|
|
126
|
-
/**
|
|
127
|
-
* Indicates whether the error matches a definition in the procedure's `.errors` map.
|
|
128
|
-
*/
|
|
129
|
-
readonly defined: boolean;
|
|
130
|
-
/**
|
|
131
|
-
* Indicates whether the error's type is inferable at the TypeScript level.
|
|
132
|
-
* This is typically true when the error is explicitly defined or returned within a handler.
|
|
133
|
-
*/
|
|
134
|
-
readonly inferable: boolean;
|
|
135
|
-
code: TCode;
|
|
136
|
-
data: TData;
|
|
137
|
-
constructor(code: TCode, ...rest: MaybeOptionalOptions<ORPCErrorOptions<TData>>);
|
|
138
|
-
toJSON(): ORPCErrorJSON<TCode, TData>;
|
|
139
|
-
/**
|
|
140
|
-
* Workaround for Next.js where different contexts use separate
|
|
141
|
-
* dependency graphs, causing multiple ORPCError constructors existing and breaking
|
|
142
|
-
* `instanceof` checks across contexts.
|
|
143
|
-
*
|
|
144
|
-
* This is particularly problematic with "Optimized SSR", where orpc-client
|
|
145
|
-
* executes in one context but is invoked from another. When an error is thrown
|
|
146
|
-
* in the execution context, `instanceof ORPCError` checks fail in the
|
|
147
|
-
* invocation context due to separate class constructors.
|
|
148
|
-
*
|
|
149
|
-
* @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
|
|
150
|
-
*/
|
|
151
|
-
static [Symbol.hasInstance](instance: unknown): boolean;
|
|
152
|
-
}
|
|
153
|
-
interface ORPCErrorJSON<TCode extends string, TData> extends Pick<ORPCError<TCode, TData>, 'code' | 'message' | 'data'> {
|
|
154
|
-
/**
|
|
155
|
-
* remove readonly
|
|
156
|
-
*/
|
|
157
|
-
defined: boolean;
|
|
158
|
-
/**
|
|
159
|
-
* remove readonly
|
|
160
|
-
*/
|
|
161
|
-
inferable: boolean;
|
|
162
|
-
}
|
|
163
|
-
type AnyORPCError = ORPCError<any, any>;
|
|
164
|
-
type AnyORPCErrorJSON = ORPCErrorJSON<any, any>;
|
|
165
|
-
|
|
166
|
-
export { ORPCError as g, COMMON_ERROR_STATUS_MAP as j };
|
|
167
|
-
export type { AnyORPCError as A, ClientContext as C, FriendlyClientOptions as F, InferClientContext as I, NestedClient as N, ORPCErrorCode as O, ClientOptions as a, ClientLink as b, AnyNestedClient as c, InferClientError as d, Client as e, ClientRest as f, ORPCErrorJSON as h, AnyORPCErrorJSON as i, InferClientBodyInputs as k, InferClientBodyOutputs as l, InferClientErrors as m, InferClientInputs as n, InferClientOutputs as o, ORPCErrorOptions as p };
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { PromiseWithError, Registry, MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
-
|
|
3
|
-
interface ClientContext {
|
|
4
|
-
[key: PropertyKey]: any;
|
|
5
|
-
}
|
|
6
|
-
interface ClientOptions<T extends ClientContext> {
|
|
7
|
-
signal?: AbortSignal | undefined;
|
|
8
|
-
lastEventId?: string | undefined;
|
|
9
|
-
context: T;
|
|
10
|
-
}
|
|
11
|
-
type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (object extends T ? {
|
|
12
|
-
context?: T;
|
|
13
|
-
} : {
|
|
14
|
-
context: T;
|
|
15
|
-
});
|
|
16
|
-
type ClientRest<TClientContext extends ClientContext, TInput> = object extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
|
|
17
|
-
interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
18
|
-
(...rest: ClientRest<TClientContext, TInput>): PromiseWithError<TOutput, TError>;
|
|
19
|
-
}
|
|
20
|
-
type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
|
|
21
|
-
[k: string]: NestedClient<TClientContext>;
|
|
22
|
-
};
|
|
23
|
-
type AnyNestedClient = NestedClient<any>;
|
|
24
|
-
type InferClientContext<T extends AnyNestedClient> = T extends NestedClient<infer U> ? U : never;
|
|
25
|
-
interface ClientLink<TClientContext extends ClientContext> {
|
|
26
|
-
call: (path: string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Recursively infers the **input types** from a client.
|
|
30
|
-
*
|
|
31
|
-
* Produces a nested map where each endpoint's input type is preserved.
|
|
32
|
-
*/
|
|
33
|
-
type InferClientInputs<T extends AnyNestedClient> = T extends Client<any, infer U, any, any> ? U : {
|
|
34
|
-
[K in keyof T]: T[K] extends AnyNestedClient ? InferClientInputs<T[K]> : never;
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Recursively infers the **body input types** from a client.
|
|
38
|
-
*
|
|
39
|
-
* If an endpoint's input includes `{ body: ... }`, only the `body` portion is extracted.
|
|
40
|
-
* Produces a nested map of body input types.
|
|
41
|
-
*/
|
|
42
|
-
type InferClientBodyInputs<T extends AnyNestedClient> = T extends Client<any, infer U, any, any> ? U extends {
|
|
43
|
-
body: infer UBody;
|
|
44
|
-
} ? UBody : U : {
|
|
45
|
-
[K in keyof T]: T[K] extends AnyNestedClient ? InferClientBodyInputs<T[K]> : never;
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* Recursively infers the **output types** from a client.
|
|
49
|
-
*
|
|
50
|
-
* Produces a nested map where each endpoint's output type is preserved.
|
|
51
|
-
*/
|
|
52
|
-
type InferClientOutputs<T extends AnyNestedClient> = T extends Client<any, any, infer U, any> ? U : {
|
|
53
|
-
[K in keyof T]: T[K] extends AnyNestedClient ? InferClientOutputs<T[K]> : never;
|
|
54
|
-
};
|
|
55
|
-
/**
|
|
56
|
-
* Recursively infers the **body output types** from a client.
|
|
57
|
-
*
|
|
58
|
-
* If an endpoint's output includes `{ body: ... }`, only the `body` portion is extracted.
|
|
59
|
-
* Produces a nested map of body output types.
|
|
60
|
-
*/
|
|
61
|
-
type InferClientBodyOutputs<T extends AnyNestedClient> = T extends Client<any, any, infer U, any> ? U extends {
|
|
62
|
-
body: infer UBody;
|
|
63
|
-
} ? UBody : U : {
|
|
64
|
-
[K in keyof T]: T[K] extends AnyNestedClient ? InferClientBodyOutputs<T[K]> : never;
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* Recursively infers the **error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#type‐safe-error-handling).
|
|
68
|
-
*
|
|
69
|
-
* Produces a nested map where each endpoint's error type is preserved.
|
|
70
|
-
*/
|
|
71
|
-
type InferClientErrors<T extends AnyNestedClient> = T extends Client<any, any, any, infer U> ? U : {
|
|
72
|
-
[K in keyof T]: T[K] extends AnyNestedClient ? InferClientErrors<T[K]> : never;
|
|
73
|
-
};
|
|
74
|
-
/**
|
|
75
|
-
* Recursively infers a **union of all error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#type‐safe-error-handling).
|
|
76
|
-
*
|
|
77
|
-
* Useful when you want to handle all possible errors from any endpoint at once.
|
|
78
|
-
*/
|
|
79
|
-
type InferClientError<T extends AnyNestedClient> = T extends Client<any, any, any, infer U> ? U : {
|
|
80
|
-
[K in keyof T]: T[K] extends AnyNestedClient ? InferClientError<T[K]> : never;
|
|
81
|
-
}[keyof T];
|
|
82
|
-
|
|
83
|
-
declare const COMMON_ERROR_STATUS_MAP: {
|
|
84
|
-
BAD_REQUEST: number;
|
|
85
|
-
UNAUTHORIZED: number;
|
|
86
|
-
PAYMENT_REQUIRED: number;
|
|
87
|
-
FORBIDDEN: number;
|
|
88
|
-
NOT_FOUND: number;
|
|
89
|
-
METHOD_NOT_SUPPORTED: number;
|
|
90
|
-
NOT_ACCEPTABLE: number;
|
|
91
|
-
TIMEOUT: number;
|
|
92
|
-
CONFLICT: number;
|
|
93
|
-
GONE: number;
|
|
94
|
-
PRECONDITION_FAILED: number;
|
|
95
|
-
PAYLOAD_TOO_LARGE: number;
|
|
96
|
-
UNSUPPORTED_MEDIA_TYPE: number;
|
|
97
|
-
UNPROCESSABLE_CONTENT: number;
|
|
98
|
-
PRECONDITION_REQUIRED: number;
|
|
99
|
-
TOO_MANY_REQUESTS: number;
|
|
100
|
-
CLIENT_CLOSED_REQUEST: number;
|
|
101
|
-
INTERNAL_SERVER_ERROR: number;
|
|
102
|
-
NOT_IMPLEMENTED: number;
|
|
103
|
-
BAD_GATEWAY: number;
|
|
104
|
-
SERVICE_UNAVAILABLE: number;
|
|
105
|
-
GATEWAY_TIMEOUT: number;
|
|
106
|
-
};
|
|
107
|
-
type ORPCErrorCode = Registry extends {
|
|
108
|
-
ORPCErrorCode: infer T extends string;
|
|
109
|
-
} ? T : (keyof typeof COMMON_ERROR_STATUS_MAP) | (string & {});
|
|
110
|
-
type ORPCErrorOptions<TData> = ErrorOptions & {
|
|
111
|
-
message?: string;
|
|
112
|
-
} & (undefined extends TData ? {
|
|
113
|
-
data?: TData;
|
|
114
|
-
} : {
|
|
115
|
-
data: TData;
|
|
116
|
-
});
|
|
117
|
-
declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
|
|
118
|
-
/**
|
|
119
|
-
* @info
|
|
120
|
-
* The `__branch` property is used for type branding, helping TypeScript distinguish
|
|
121
|
-
* an `ORPCError` instance from plain objects with a similar structure.
|
|
122
|
-
*/
|
|
123
|
-
readonly name: "ORPCError" & {
|
|
124
|
-
__branch: "ORPCError";
|
|
125
|
-
};
|
|
126
|
-
/**
|
|
127
|
-
* Indicates whether the error matches a definition in the procedure's `.errors` map.
|
|
128
|
-
*/
|
|
129
|
-
readonly defined: boolean;
|
|
130
|
-
/**
|
|
131
|
-
* Indicates whether the error's type is inferable at the TypeScript level.
|
|
132
|
-
* This is typically true when the error is explicitly defined or returned within a handler.
|
|
133
|
-
*/
|
|
134
|
-
readonly inferable: boolean;
|
|
135
|
-
code: TCode;
|
|
136
|
-
data: TData;
|
|
137
|
-
constructor(code: TCode, ...rest: MaybeOptionalOptions<ORPCErrorOptions<TData>>);
|
|
138
|
-
toJSON(): ORPCErrorJSON<TCode, TData>;
|
|
139
|
-
/**
|
|
140
|
-
* Workaround for Next.js where different contexts use separate
|
|
141
|
-
* dependency graphs, causing multiple ORPCError constructors existing and breaking
|
|
142
|
-
* `instanceof` checks across contexts.
|
|
143
|
-
*
|
|
144
|
-
* This is particularly problematic with "Optimized SSR", where orpc-client
|
|
145
|
-
* executes in one context but is invoked from another. When an error is thrown
|
|
146
|
-
* in the execution context, `instanceof ORPCError` checks fail in the
|
|
147
|
-
* invocation context due to separate class constructors.
|
|
148
|
-
*
|
|
149
|
-
* @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
|
|
150
|
-
*/
|
|
151
|
-
static [Symbol.hasInstance](instance: unknown): boolean;
|
|
152
|
-
}
|
|
153
|
-
interface ORPCErrorJSON<TCode extends string, TData> extends Pick<ORPCError<TCode, TData>, 'code' | 'message' | 'data'> {
|
|
154
|
-
/**
|
|
155
|
-
* remove readonly
|
|
156
|
-
*/
|
|
157
|
-
defined: boolean;
|
|
158
|
-
/**
|
|
159
|
-
* remove readonly
|
|
160
|
-
*/
|
|
161
|
-
inferable: boolean;
|
|
162
|
-
}
|
|
163
|
-
type AnyORPCError = ORPCError<any, any>;
|
|
164
|
-
type AnyORPCErrorJSON = ORPCErrorJSON<any, any>;
|
|
165
|
-
|
|
166
|
-
export { ORPCError as g, COMMON_ERROR_STATUS_MAP as j };
|
|
167
|
-
export type { AnyORPCError as A, ClientContext as C, FriendlyClientOptions as F, InferClientContext as I, NestedClient as N, ORPCErrorCode as O, ClientOptions as a, ClientLink as b, AnyNestedClient as c, InferClientError as d, Client as e, ClientRest as f, ORPCErrorJSON as h, AnyORPCErrorJSON as i, InferClientBodyInputs as k, InferClientBodyOutputs as l, InferClientErrors as m, InferClientInputs as n, InferClientOutputs as o, ORPCErrorOptions as p };
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { Promisable, OrderablePlugin, Interceptor } from '@orpc/shared';
|
|
2
|
-
import { StandardRequest, StandardLazyResponse } from '@standardserver/core';
|
|
3
|
-
import { C as ClientContext, a as ClientOptions, A as AnyORPCError, b as ClientLink } from './client.BBZBQID8.js';
|
|
4
|
-
|
|
5
|
-
type StandardLinkCodecDecodedResponse = {
|
|
6
|
-
kind: 'output';
|
|
7
|
-
output: unknown;
|
|
8
|
-
} | {
|
|
9
|
-
kind: 'error';
|
|
10
|
-
error: AnyORPCError;
|
|
11
|
-
};
|
|
12
|
-
interface StandardLinkCodec<T extends ClientContext> {
|
|
13
|
-
encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promisable<StandardRequest>;
|
|
14
|
-
decodeResponse(response: StandardLazyResponse, path: string[], options: ClientOptions<T>): Promisable<StandardLinkCodecDecodedResponse>;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface StandardLinkPlugin<T extends ClientContext> extends OrderablePlugin {
|
|
18
|
-
/**
|
|
19
|
-
* Initializes the plugin and returns new link options.
|
|
20
|
-
* Called once per plugin instance during composition.
|
|
21
|
-
*
|
|
22
|
-
* This method allows plugins to wrap, extend, or transform link options
|
|
23
|
-
* such as interceptors, or configuration.
|
|
24
|
-
*
|
|
25
|
-
* @param options - The current link options from previous plugins or base configuration
|
|
26
|
-
* @returns Transformed link options with plugin's modifications applied
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* init(options) {
|
|
31
|
-
* return {
|
|
32
|
-
* ...options,
|
|
33
|
-
* interceptors: [...(options.interceptors || []), myInterceptor]
|
|
34
|
-
* }
|
|
35
|
-
* }
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
init?(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
39
|
-
}
|
|
40
|
-
declare class CompositeStandardLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
41
|
-
name: string;
|
|
42
|
-
protected readonly plugins: StandardLinkPlugin<T>[];
|
|
43
|
-
constructor(plugins?: StandardLinkPlugin<T>[]);
|
|
44
|
-
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Handles the transport layer for sending requests and receiving responses.
|
|
49
|
-
*
|
|
50
|
-
* Implementations are responsible for the actual network communication,
|
|
51
|
-
* such as HTTP fetch, WebSocket, or other transport mechanisms.
|
|
52
|
-
*/
|
|
53
|
-
interface StandardLinkTransport<T extends ClientContext> {
|
|
54
|
-
/**
|
|
55
|
-
* @throws Transport-level errors (network failures, timeouts, etc.)
|
|
56
|
-
*/
|
|
57
|
-
send(request: StandardRequest, path: string[], options: ClientOptions<T>): Promise<StandardLazyResponse>;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
|
|
61
|
-
path: string[];
|
|
62
|
-
input: unknown;
|
|
63
|
-
}
|
|
64
|
-
type StandardLinkInterceptor<T extends ClientContext> = Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>;
|
|
65
|
-
interface StandardLinkTransportInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
|
|
66
|
-
path: string[];
|
|
67
|
-
request: StandardRequest;
|
|
68
|
-
}
|
|
69
|
-
type StandardLinkTransportInterceptor<T extends ClientContext> = Interceptor<StandardLinkTransportInterceptorOptions<T>, Promise<StandardLazyResponse>>;
|
|
70
|
-
interface StandardLinkOptions<T extends ClientContext> {
|
|
71
|
-
/**
|
|
72
|
-
* Interceptors that execute around the entire call, including transport and codec.
|
|
73
|
-
* Useful for error handling, logging, metrics, ...
|
|
74
|
-
*/
|
|
75
|
-
interceptors?: StandardLinkInterceptor<T>[];
|
|
76
|
-
/**
|
|
77
|
-
* Interceptors that execute around the transport layer, after encoding and before decoding.
|
|
78
|
-
* Useful for modifying the request or response, adding transport-level logging, ...
|
|
79
|
-
*/
|
|
80
|
-
transportInterceptors?: StandardLinkTransportInterceptor<T>[];
|
|
81
|
-
plugins?: StandardLinkPlugin<T>[];
|
|
82
|
-
}
|
|
83
|
-
declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
84
|
-
private readonly codec;
|
|
85
|
-
private readonly transport;
|
|
86
|
-
private readonly interceptors;
|
|
87
|
-
private readonly transportInterceptors;
|
|
88
|
-
constructor(codec: StandardLinkCodec<T>, transport: StandardLinkTransport<T>, options?: StandardLinkOptions<T>);
|
|
89
|
-
/**
|
|
90
|
-
* @throws ORPCError, transport-level errors (network failures, timeouts, etc.)
|
|
91
|
-
*/
|
|
92
|
-
call(path: string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export { CompositeStandardLinkPlugin as C, StandardLink as a };
|
|
96
|
-
export type { StandardLinkTransport as S, StandardLinkOptions as b, StandardLinkPlugin as c, StandardLinkTransportInterceptorOptions as d, StandardLinkInterceptorOptions as e, StandardLinkCodec as f, StandardLinkCodecDecodedResponse as g, StandardLinkInterceptor as h, StandardLinkTransportInterceptor as i };
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { sortPlugins, runWithSpan, ORPC_NAME, isAsyncIteratorObject, override, traceAsyncIterator, intercept, getOpenTelemetryConfig, value, pathToHttpPath, stringifyJSON } from '@orpc/shared';
|
|
2
|
-
import { mergeStandardHeaders, parseStandardUrl } from '@standardserver/core';
|
|
3
|
-
import { toStandardHeaders } from '@standardserver/fetch';
|
|
4
|
-
import { O as ORPCError } from './client.Dnfj8jnT.mjs';
|
|
5
|
-
import { R as RPCSerializer, i as isORPCErrorJson, c as createORPCErrorFromJson } from './client.DqYwRDUO.mjs';
|
|
6
|
-
|
|
7
|
-
class CompositeStandardLinkPlugin {
|
|
8
|
-
name = "~composite";
|
|
9
|
-
plugins;
|
|
10
|
-
constructor(plugins = []) {
|
|
11
|
-
this.plugins = sortPlugins(plugins);
|
|
12
|
-
}
|
|
13
|
-
init(options) {
|
|
14
|
-
for (const plugin of this.plugins) {
|
|
15
|
-
if (plugin.init) {
|
|
16
|
-
options = plugin.init(options);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return options;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
class StandardLink {
|
|
24
|
-
constructor(codec, transport, options = {}) {
|
|
25
|
-
this.codec = codec;
|
|
26
|
-
this.transport = transport;
|
|
27
|
-
options = new CompositeStandardLinkPlugin(options.plugins).init(options);
|
|
28
|
-
this.interceptors = options.interceptors;
|
|
29
|
-
this.transportInterceptors = options.transportInterceptors;
|
|
30
|
-
}
|
|
31
|
-
interceptors;
|
|
32
|
-
transportInterceptors;
|
|
33
|
-
/**
|
|
34
|
-
* @throws ORPCError, transport-level errors (network failures, timeouts, etc.)
|
|
35
|
-
*/
|
|
36
|
-
call(path, input, options) {
|
|
37
|
-
return runWithSpan(`${ORPC_NAME}.${path.join("/")}`, (span) => {
|
|
38
|
-
span?.setAttribute("rpc.system", ORPC_NAME);
|
|
39
|
-
span?.setAttribute("rpc.method", path.join("."));
|
|
40
|
-
if (isAsyncIteratorObject(input)) {
|
|
41
|
-
input = override(input, traceAsyncIterator("consume_async_iterator_object_input", input));
|
|
42
|
-
}
|
|
43
|
-
return intercept(this.interceptors, { ...options, path, input }, async ({ path: path2, input: input2, ...options2 }) => {
|
|
44
|
-
const otel = getOpenTelemetryConfig();
|
|
45
|
-
let activeContext;
|
|
46
|
-
const activeSpan = otel?.trace.getActiveSpan() ?? span;
|
|
47
|
-
if (activeSpan && otel) {
|
|
48
|
-
activeContext = otel.trace.setSpan(otel.context.active(), activeSpan);
|
|
49
|
-
}
|
|
50
|
-
let request = await runWithSpan(
|
|
51
|
-
{ name: "encode_input", context: activeContext },
|
|
52
|
-
() => this.codec.encodeInput(input2, path2, options2)
|
|
53
|
-
);
|
|
54
|
-
if (activeContext && otel?.propagation) {
|
|
55
|
-
const headers = { ...request.headers };
|
|
56
|
-
otel.propagation.inject(activeContext, headers);
|
|
57
|
-
request = { ...request, headers };
|
|
58
|
-
}
|
|
59
|
-
const response = await intercept(
|
|
60
|
-
this.transportInterceptors,
|
|
61
|
-
{ ...options2, path: path2, request },
|
|
62
|
-
({ path: path3, request: request2, ...options3 }) => {
|
|
63
|
-
let activeTransportContext;
|
|
64
|
-
const activeTransportSpan = otel?.trace.getActiveSpan() ?? activeSpan;
|
|
65
|
-
if (activeTransportSpan && otel) {
|
|
66
|
-
activeTransportContext = otel.trace.setSpan(otel.context.active(), activeTransportSpan);
|
|
67
|
-
}
|
|
68
|
-
return runWithSpan(
|
|
69
|
-
{ name: "send_request", context: activeTransportContext },
|
|
70
|
-
() => this.transport.send(request2, path3, options3)
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
);
|
|
74
|
-
const decodedResult = await runWithSpan(
|
|
75
|
-
{ name: "decode_response", context: activeContext },
|
|
76
|
-
() => this.codec.decodeResponse(response, path2, options2)
|
|
77
|
-
);
|
|
78
|
-
if (decodedResult.kind === "error") {
|
|
79
|
-
throw decodedResult.error;
|
|
80
|
-
}
|
|
81
|
-
const output = decodedResult.output;
|
|
82
|
-
if (isAsyncIteratorObject(output)) {
|
|
83
|
-
return override(output, traceAsyncIterator("consume_async_iterator_object_output", output));
|
|
84
|
-
}
|
|
85
|
-
return output;
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const END_SLASH_REGEX = /\/$/;
|
|
92
|
-
class RPCLinkCodec {
|
|
93
|
-
baseUrl;
|
|
94
|
-
maxUrlLength;
|
|
95
|
-
fallbackMethod;
|
|
96
|
-
expectedMethod;
|
|
97
|
-
headers;
|
|
98
|
-
serializer;
|
|
99
|
-
constructor(options) {
|
|
100
|
-
this.baseUrl = options.url ?? "/";
|
|
101
|
-
this.maxUrlLength = options.maxUrlLength ?? 2083;
|
|
102
|
-
this.fallbackMethod = options.fallbackMethod ?? "POST";
|
|
103
|
-
this.expectedMethod = options.method ?? this.fallbackMethod;
|
|
104
|
-
this.headers = options.headers ?? {};
|
|
105
|
-
this.serializer = options.serializer ?? new RPCSerializer();
|
|
106
|
-
}
|
|
107
|
-
async encodeInput(input, path, options) {
|
|
108
|
-
let headers = toResolvedStandardHeaders(await value(this.headers, options, path, input));
|
|
109
|
-
if (options.lastEventId !== void 0) {
|
|
110
|
-
headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
|
|
111
|
-
}
|
|
112
|
-
const expectedMethod = await value(this.expectedMethod, options, path, input);
|
|
113
|
-
const baseUrl = await value(this.baseUrl, options, path, input);
|
|
114
|
-
const [pathname, search, hash] = parseStandardUrl(baseUrl);
|
|
115
|
-
const newPathname = `${pathname.replace(END_SLASH_REGEX, "")}${pathToHttpPath(path)}`;
|
|
116
|
-
const serialized = this.serializer.serialize(input);
|
|
117
|
-
if (expectedMethod === "GET" && !(serialized instanceof Blob) && !(serialized instanceof ReadableStream) && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) {
|
|
118
|
-
const maxUrlLength = await value(this.maxUrlLength, options, path, input);
|
|
119
|
-
const mergedSearch = new URLSearchParams(search);
|
|
120
|
-
mergedSearch.append("data", stringifyJSON(serialized) ?? "");
|
|
121
|
-
const url2 = `${newPathname}?${mergedSearch}${hash ?? ""}`;
|
|
122
|
-
if (url2.length <= maxUrlLength) {
|
|
123
|
-
return {
|
|
124
|
-
body: void 0,
|
|
125
|
-
method: expectedMethod,
|
|
126
|
-
headers,
|
|
127
|
-
url: url2,
|
|
128
|
-
signal: options.signal
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
const url = `${newPathname}${search ?? ""}${hash ?? ""}`;
|
|
133
|
-
return {
|
|
134
|
-
url,
|
|
135
|
-
method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod,
|
|
136
|
-
headers,
|
|
137
|
-
body: serialized,
|
|
138
|
-
signal: options.signal
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
async decodeResponse(response) {
|
|
142
|
-
const isOk = response.status < 400;
|
|
143
|
-
const body = await response.resolveBody();
|
|
144
|
-
const deserialized = await (async () => {
|
|
145
|
-
try {
|
|
146
|
-
return this.serializer.deserialize(body);
|
|
147
|
-
} catch (cause) {
|
|
148
|
-
throw new Error("Invalid RPC response format.", {
|
|
149
|
-
cause
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
})();
|
|
153
|
-
if (!isOk) {
|
|
154
|
-
if (isORPCErrorJson(deserialized)) {
|
|
155
|
-
return { kind: "error", error: createORPCErrorFromJson(deserialized) };
|
|
156
|
-
}
|
|
157
|
-
return {
|
|
158
|
-
kind: "error",
|
|
159
|
-
error: new ORPCError("MALFORMED_ORPC_ERROR_RESPONSE", {
|
|
160
|
-
data: { headers: response.headers, status: response.status, body: deserialized }
|
|
161
|
-
})
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
return { kind: "output", output: deserialized };
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
function toResolvedStandardHeaders(headers) {
|
|
168
|
-
if (typeof headers.forEach === "function") {
|
|
169
|
-
return toStandardHeaders(headers);
|
|
170
|
-
}
|
|
171
|
-
return headers;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export { CompositeStandardLinkPlugin as C, RPCLinkCodec as R, StandardLink as S };
|