@orpc/client 0.0.0-next.c4a591c → 0.0.0-next.c58d6c4
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 +96 -0
- package/dist/adapters/fetch/index.d.mts +33 -0
- package/dist/adapters/fetch/index.d.ts +33 -0
- package/dist/adapters/fetch/index.mjs +29 -0
- 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 +71 -0
- package/dist/adapters/standard/index.d.mts +10 -0
- package/dist/adapters/standard/index.d.ts +10 -0
- package/dist/adapters/standard/index.mjs +4 -0
- package/dist/adapters/websocket/index.d.mts +29 -0
- package/dist/adapters/websocket/index.d.ts +29 -0
- package/dist/adapters/websocket/index.mjs +31 -0
- package/dist/index.d.mts +169 -0
- package/dist/index.d.ts +169 -0
- package/dist/index.mjs +65 -0
- package/dist/plugins/index.d.mts +202 -0
- package/dist/plugins/index.d.ts +202 -0
- package/dist/plugins/index.mjs +389 -0
- package/dist/shared/client.4TS_0JaO.d.mts +29 -0
- package/dist/shared/client.4TS_0JaO.d.ts +29 -0
- package/dist/shared/client.7UM0t5o-.d.ts +91 -0
- package/dist/shared/client.BMoG_EdN.d.mts +46 -0
- package/dist/shared/client.BdD8cpjs.d.mts +91 -0
- package/dist/shared/client.C0KbSWlC.d.ts +46 -0
- package/dist/shared/client.CRWEpqLB.mjs +175 -0
- package/dist/shared/client.DpICn1BD.mjs +355 -0
- package/package.json +32 -17
- package/dist/fetch.js +0 -89
- package/dist/index.js +0 -42
- package/dist/src/adapters/fetch/index.d.ts +0 -3
- package/dist/src/adapters/fetch/orpc-link.d.ts +0 -46
- package/dist/src/adapters/fetch/types.d.ts +0 -4
- package/dist/src/client.d.ts +0 -11
- package/dist/src/dynamic-link.d.ts +0 -13
- package/dist/src/index.d.ts +0 -6
- package/dist/src/types.d.ts +0 -5
package/dist/index.d.mts
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
import { N as NestedClient, C as ClientLink, I as InferClientContext, a as ClientContext, b as ClientOptions, c as ClientPromiseResult, F as FriendlyClientOptions } from './shared/client.4TS_0JaO.mjs';
|
2
|
+
export { f as Client, e as ClientRest, d as HTTPMethod, H as HTTPPath } from './shared/client.4TS_0JaO.mjs';
|
3
|
+
import { Promisable, MaybeOptionalOptions, ThrowableError } from '@orpc/shared';
|
4
|
+
export { EventPublisher, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, Registry, ThrowableError, onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
5
|
+
export { ErrorEvent } from '@orpc/standard-server';
|
6
|
+
|
7
|
+
interface createORPCClientOptions {
|
8
|
+
/**
|
9
|
+
* Use as base path for all procedure, useful when you only want to call a subset of the procedure.
|
10
|
+
*/
|
11
|
+
path?: string[];
|
12
|
+
}
|
13
|
+
/**
|
14
|
+
* Create a oRPC client-side client from a link.
|
15
|
+
*
|
16
|
+
* @see {@link https://orpc.unnoq.com/docs/client/client-side Client-side Client Docs}
|
17
|
+
*/
|
18
|
+
declare function createORPCClient<T extends NestedClient<any>>(link: ClientLink<InferClientContext<T>>, options?: createORPCClientOptions): T;
|
19
|
+
|
20
|
+
/**
|
21
|
+
* DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
|
22
|
+
* based on the request path, input, and context.
|
23
|
+
*
|
24
|
+
* @see {@link https://orpc.unnoq.com/docs/client/dynamic-link Dynamic Link Docs}
|
25
|
+
*/
|
26
|
+
declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
|
27
|
+
private readonly linkResolver;
|
28
|
+
constructor(linkResolver: (options: ClientOptions<TClientContext>, path: readonly string[], input: unknown) => Promisable<ClientLink<TClientContext>>);
|
29
|
+
call(path: readonly string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
|
30
|
+
}
|
31
|
+
|
32
|
+
declare const COMMON_ORPC_ERROR_DEFS: {
|
33
|
+
readonly BAD_REQUEST: {
|
34
|
+
readonly status: 400;
|
35
|
+
readonly message: "Bad Request";
|
36
|
+
};
|
37
|
+
readonly UNAUTHORIZED: {
|
38
|
+
readonly status: 401;
|
39
|
+
readonly message: "Unauthorized";
|
40
|
+
};
|
41
|
+
readonly FORBIDDEN: {
|
42
|
+
readonly status: 403;
|
43
|
+
readonly message: "Forbidden";
|
44
|
+
};
|
45
|
+
readonly NOT_FOUND: {
|
46
|
+
readonly status: 404;
|
47
|
+
readonly message: "Not Found";
|
48
|
+
};
|
49
|
+
readonly METHOD_NOT_SUPPORTED: {
|
50
|
+
readonly status: 405;
|
51
|
+
readonly message: "Method Not Supported";
|
52
|
+
};
|
53
|
+
readonly NOT_ACCEPTABLE: {
|
54
|
+
readonly status: 406;
|
55
|
+
readonly message: "Not Acceptable";
|
56
|
+
};
|
57
|
+
readonly TIMEOUT: {
|
58
|
+
readonly status: 408;
|
59
|
+
readonly message: "Request Timeout";
|
60
|
+
};
|
61
|
+
readonly CONFLICT: {
|
62
|
+
readonly status: 409;
|
63
|
+
readonly message: "Conflict";
|
64
|
+
};
|
65
|
+
readonly PRECONDITION_FAILED: {
|
66
|
+
readonly status: 412;
|
67
|
+
readonly message: "Precondition Failed";
|
68
|
+
};
|
69
|
+
readonly PAYLOAD_TOO_LARGE: {
|
70
|
+
readonly status: 413;
|
71
|
+
readonly message: "Payload Too Large";
|
72
|
+
};
|
73
|
+
readonly UNSUPPORTED_MEDIA_TYPE: {
|
74
|
+
readonly status: 415;
|
75
|
+
readonly message: "Unsupported Media Type";
|
76
|
+
};
|
77
|
+
readonly UNPROCESSABLE_CONTENT: {
|
78
|
+
readonly status: 422;
|
79
|
+
readonly message: "Unprocessable Content";
|
80
|
+
};
|
81
|
+
readonly TOO_MANY_REQUESTS: {
|
82
|
+
readonly status: 429;
|
83
|
+
readonly message: "Too Many Requests";
|
84
|
+
};
|
85
|
+
readonly CLIENT_CLOSED_REQUEST: {
|
86
|
+
readonly status: 499;
|
87
|
+
readonly message: "Client Closed Request";
|
88
|
+
};
|
89
|
+
readonly INTERNAL_SERVER_ERROR: {
|
90
|
+
readonly status: 500;
|
91
|
+
readonly message: "Internal Server Error";
|
92
|
+
};
|
93
|
+
readonly NOT_IMPLEMENTED: {
|
94
|
+
readonly status: 501;
|
95
|
+
readonly message: "Not Implemented";
|
96
|
+
};
|
97
|
+
readonly BAD_GATEWAY: {
|
98
|
+
readonly status: 502;
|
99
|
+
readonly message: "Bad Gateway";
|
100
|
+
};
|
101
|
+
readonly SERVICE_UNAVAILABLE: {
|
102
|
+
readonly status: 503;
|
103
|
+
readonly message: "Service Unavailable";
|
104
|
+
};
|
105
|
+
readonly GATEWAY_TIMEOUT: {
|
106
|
+
readonly status: 504;
|
107
|
+
readonly message: "Gateway Timeout";
|
108
|
+
};
|
109
|
+
};
|
110
|
+
type CommonORPCErrorCode = keyof typeof COMMON_ORPC_ERROR_DEFS;
|
111
|
+
type ORPCErrorCode = CommonORPCErrorCode | (string & {});
|
112
|
+
declare function fallbackORPCErrorStatus(code: ORPCErrorCode, status: number | undefined): number;
|
113
|
+
declare function fallbackORPCErrorMessage(code: ORPCErrorCode, message: string | undefined): string;
|
114
|
+
type ORPCErrorOptions<TData> = ErrorOptions & {
|
115
|
+
defined?: boolean;
|
116
|
+
status?: number;
|
117
|
+
message?: string;
|
118
|
+
} & (undefined extends TData ? {
|
119
|
+
data?: TData;
|
120
|
+
} : {
|
121
|
+
data: TData;
|
122
|
+
});
|
123
|
+
declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
|
124
|
+
readonly defined: boolean;
|
125
|
+
readonly code: TCode;
|
126
|
+
readonly status: number;
|
127
|
+
readonly data: TData;
|
128
|
+
constructor(code: TCode, ...[options]: MaybeOptionalOptions<ORPCErrorOptions<TData>>);
|
129
|
+
toJSON(): ORPCErrorJSON<TCode, TData>;
|
130
|
+
}
|
131
|
+
type ORPCErrorJSON<TCode extends string, TData> = Pick<ORPCError<TCode, TData>, 'defined' | 'code' | 'status' | 'message' | 'data'>;
|
132
|
+
declare function isDefinedError<T>(error: T): error is Extract<T, ORPCError<any, any>>;
|
133
|
+
declare function toORPCError(error: unknown): ORPCError<any, any>;
|
134
|
+
declare function isORPCErrorStatus(status: number): boolean;
|
135
|
+
declare function isORPCErrorJson(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
|
136
|
+
declare function createORPCErrorFromJson<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>;
|
137
|
+
|
138
|
+
declare function mapEventIterator<TYield, TReturn, TNext, TMap = TYield | TReturn>(iterator: AsyncIterator<TYield, TReturn, TNext>, maps: {
|
139
|
+
value: (value: NoInfer<TYield | TReturn>, done: boolean | undefined) => Promise<TMap>;
|
140
|
+
error: (error: unknown) => Promise<unknown>;
|
141
|
+
}): AsyncGenerator<TMap, TMap, TNext>;
|
142
|
+
|
143
|
+
type SafeResult<TOutput, TError> = [error: null, data: TOutput, isDefined: false, isSuccess: true] & {
|
144
|
+
error: null;
|
145
|
+
data: TOutput;
|
146
|
+
isDefined: false;
|
147
|
+
isSuccess: true;
|
148
|
+
} | [error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false, isSuccess: false] & {
|
149
|
+
error: Exclude<TError, ORPCError<any, any>>;
|
150
|
+
data: undefined;
|
151
|
+
isDefined: false;
|
152
|
+
isSuccess: false;
|
153
|
+
} | [error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true, isSuccess: false] & {
|
154
|
+
error: Extract<TError, ORPCError<any, any>>;
|
155
|
+
data: undefined;
|
156
|
+
isDefined: true;
|
157
|
+
isSuccess: false;
|
158
|
+
};
|
159
|
+
/**
|
160
|
+
* Works like try/catch, but can infer error types.
|
161
|
+
*
|
162
|
+
* @info support both tuple `[error, data, isDefined, isSuccess]` and object `{ error, data, isDefined, isSuccess }` styles.
|
163
|
+
* @see {@link https://orpc.unnoq.com/docs/client/error-handling Client Error Handling Docs}
|
164
|
+
*/
|
165
|
+
declare function safe<TOutput, TError = ThrowableError>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
|
166
|
+
declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
|
167
|
+
|
168
|
+
export { COMMON_ORPC_ERROR_DEFS, ClientContext, ClientLink, ClientOptions, ClientPromiseResult, DynamicLink, FriendlyClientOptions, InferClientContext, NestedClient, ORPCError, createORPCClient, createORPCErrorFromJson, fallbackORPCErrorMessage, fallbackORPCErrorStatus, isDefinedError, isORPCErrorJson, isORPCErrorStatus, mapEventIterator, resolveFriendlyClientOptions, safe, toORPCError };
|
169
|
+
export type { CommonORPCErrorCode, ORPCErrorCode, ORPCErrorJSON, ORPCErrorOptions, SafeResult, createORPCClientOptions };
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
import { N as NestedClient, C as ClientLink, I as InferClientContext, a as ClientContext, b as ClientOptions, c as ClientPromiseResult, F as FriendlyClientOptions } from './shared/client.4TS_0JaO.js';
|
2
|
+
export { f as Client, e as ClientRest, d as HTTPMethod, H as HTTPPath } from './shared/client.4TS_0JaO.js';
|
3
|
+
import { Promisable, MaybeOptionalOptions, ThrowableError } from '@orpc/shared';
|
4
|
+
export { EventPublisher, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, Registry, ThrowableError, onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
5
|
+
export { ErrorEvent } from '@orpc/standard-server';
|
6
|
+
|
7
|
+
interface createORPCClientOptions {
|
8
|
+
/**
|
9
|
+
* Use as base path for all procedure, useful when you only want to call a subset of the procedure.
|
10
|
+
*/
|
11
|
+
path?: string[];
|
12
|
+
}
|
13
|
+
/**
|
14
|
+
* Create a oRPC client-side client from a link.
|
15
|
+
*
|
16
|
+
* @see {@link https://orpc.unnoq.com/docs/client/client-side Client-side Client Docs}
|
17
|
+
*/
|
18
|
+
declare function createORPCClient<T extends NestedClient<any>>(link: ClientLink<InferClientContext<T>>, options?: createORPCClientOptions): T;
|
19
|
+
|
20
|
+
/**
|
21
|
+
* DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
|
22
|
+
* based on the request path, input, and context.
|
23
|
+
*
|
24
|
+
* @see {@link https://orpc.unnoq.com/docs/client/dynamic-link Dynamic Link Docs}
|
25
|
+
*/
|
26
|
+
declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
|
27
|
+
private readonly linkResolver;
|
28
|
+
constructor(linkResolver: (options: ClientOptions<TClientContext>, path: readonly string[], input: unknown) => Promisable<ClientLink<TClientContext>>);
|
29
|
+
call(path: readonly string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
|
30
|
+
}
|
31
|
+
|
32
|
+
declare const COMMON_ORPC_ERROR_DEFS: {
|
33
|
+
readonly BAD_REQUEST: {
|
34
|
+
readonly status: 400;
|
35
|
+
readonly message: "Bad Request";
|
36
|
+
};
|
37
|
+
readonly UNAUTHORIZED: {
|
38
|
+
readonly status: 401;
|
39
|
+
readonly message: "Unauthorized";
|
40
|
+
};
|
41
|
+
readonly FORBIDDEN: {
|
42
|
+
readonly status: 403;
|
43
|
+
readonly message: "Forbidden";
|
44
|
+
};
|
45
|
+
readonly NOT_FOUND: {
|
46
|
+
readonly status: 404;
|
47
|
+
readonly message: "Not Found";
|
48
|
+
};
|
49
|
+
readonly METHOD_NOT_SUPPORTED: {
|
50
|
+
readonly status: 405;
|
51
|
+
readonly message: "Method Not Supported";
|
52
|
+
};
|
53
|
+
readonly NOT_ACCEPTABLE: {
|
54
|
+
readonly status: 406;
|
55
|
+
readonly message: "Not Acceptable";
|
56
|
+
};
|
57
|
+
readonly TIMEOUT: {
|
58
|
+
readonly status: 408;
|
59
|
+
readonly message: "Request Timeout";
|
60
|
+
};
|
61
|
+
readonly CONFLICT: {
|
62
|
+
readonly status: 409;
|
63
|
+
readonly message: "Conflict";
|
64
|
+
};
|
65
|
+
readonly PRECONDITION_FAILED: {
|
66
|
+
readonly status: 412;
|
67
|
+
readonly message: "Precondition Failed";
|
68
|
+
};
|
69
|
+
readonly PAYLOAD_TOO_LARGE: {
|
70
|
+
readonly status: 413;
|
71
|
+
readonly message: "Payload Too Large";
|
72
|
+
};
|
73
|
+
readonly UNSUPPORTED_MEDIA_TYPE: {
|
74
|
+
readonly status: 415;
|
75
|
+
readonly message: "Unsupported Media Type";
|
76
|
+
};
|
77
|
+
readonly UNPROCESSABLE_CONTENT: {
|
78
|
+
readonly status: 422;
|
79
|
+
readonly message: "Unprocessable Content";
|
80
|
+
};
|
81
|
+
readonly TOO_MANY_REQUESTS: {
|
82
|
+
readonly status: 429;
|
83
|
+
readonly message: "Too Many Requests";
|
84
|
+
};
|
85
|
+
readonly CLIENT_CLOSED_REQUEST: {
|
86
|
+
readonly status: 499;
|
87
|
+
readonly message: "Client Closed Request";
|
88
|
+
};
|
89
|
+
readonly INTERNAL_SERVER_ERROR: {
|
90
|
+
readonly status: 500;
|
91
|
+
readonly message: "Internal Server Error";
|
92
|
+
};
|
93
|
+
readonly NOT_IMPLEMENTED: {
|
94
|
+
readonly status: 501;
|
95
|
+
readonly message: "Not Implemented";
|
96
|
+
};
|
97
|
+
readonly BAD_GATEWAY: {
|
98
|
+
readonly status: 502;
|
99
|
+
readonly message: "Bad Gateway";
|
100
|
+
};
|
101
|
+
readonly SERVICE_UNAVAILABLE: {
|
102
|
+
readonly status: 503;
|
103
|
+
readonly message: "Service Unavailable";
|
104
|
+
};
|
105
|
+
readonly GATEWAY_TIMEOUT: {
|
106
|
+
readonly status: 504;
|
107
|
+
readonly message: "Gateway Timeout";
|
108
|
+
};
|
109
|
+
};
|
110
|
+
type CommonORPCErrorCode = keyof typeof COMMON_ORPC_ERROR_DEFS;
|
111
|
+
type ORPCErrorCode = CommonORPCErrorCode | (string & {});
|
112
|
+
declare function fallbackORPCErrorStatus(code: ORPCErrorCode, status: number | undefined): number;
|
113
|
+
declare function fallbackORPCErrorMessage(code: ORPCErrorCode, message: string | undefined): string;
|
114
|
+
type ORPCErrorOptions<TData> = ErrorOptions & {
|
115
|
+
defined?: boolean;
|
116
|
+
status?: number;
|
117
|
+
message?: string;
|
118
|
+
} & (undefined extends TData ? {
|
119
|
+
data?: TData;
|
120
|
+
} : {
|
121
|
+
data: TData;
|
122
|
+
});
|
123
|
+
declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
|
124
|
+
readonly defined: boolean;
|
125
|
+
readonly code: TCode;
|
126
|
+
readonly status: number;
|
127
|
+
readonly data: TData;
|
128
|
+
constructor(code: TCode, ...[options]: MaybeOptionalOptions<ORPCErrorOptions<TData>>);
|
129
|
+
toJSON(): ORPCErrorJSON<TCode, TData>;
|
130
|
+
}
|
131
|
+
type ORPCErrorJSON<TCode extends string, TData> = Pick<ORPCError<TCode, TData>, 'defined' | 'code' | 'status' | 'message' | 'data'>;
|
132
|
+
declare function isDefinedError<T>(error: T): error is Extract<T, ORPCError<any, any>>;
|
133
|
+
declare function toORPCError(error: unknown): ORPCError<any, any>;
|
134
|
+
declare function isORPCErrorStatus(status: number): boolean;
|
135
|
+
declare function isORPCErrorJson(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
|
136
|
+
declare function createORPCErrorFromJson<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>;
|
137
|
+
|
138
|
+
declare function mapEventIterator<TYield, TReturn, TNext, TMap = TYield | TReturn>(iterator: AsyncIterator<TYield, TReturn, TNext>, maps: {
|
139
|
+
value: (value: NoInfer<TYield | TReturn>, done: boolean | undefined) => Promise<TMap>;
|
140
|
+
error: (error: unknown) => Promise<unknown>;
|
141
|
+
}): AsyncGenerator<TMap, TMap, TNext>;
|
142
|
+
|
143
|
+
type SafeResult<TOutput, TError> = [error: null, data: TOutput, isDefined: false, isSuccess: true] & {
|
144
|
+
error: null;
|
145
|
+
data: TOutput;
|
146
|
+
isDefined: false;
|
147
|
+
isSuccess: true;
|
148
|
+
} | [error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false, isSuccess: false] & {
|
149
|
+
error: Exclude<TError, ORPCError<any, any>>;
|
150
|
+
data: undefined;
|
151
|
+
isDefined: false;
|
152
|
+
isSuccess: false;
|
153
|
+
} | [error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true, isSuccess: false] & {
|
154
|
+
error: Extract<TError, ORPCError<any, any>>;
|
155
|
+
data: undefined;
|
156
|
+
isDefined: true;
|
157
|
+
isSuccess: false;
|
158
|
+
};
|
159
|
+
/**
|
160
|
+
* Works like try/catch, but can infer error types.
|
161
|
+
*
|
162
|
+
* @info support both tuple `[error, data, isDefined, isSuccess]` and object `{ error, data, isDefined, isSuccess }` styles.
|
163
|
+
* @see {@link https://orpc.unnoq.com/docs/client/error-handling Client Error Handling Docs}
|
164
|
+
*/
|
165
|
+
declare function safe<TOutput, TError = ThrowableError>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
|
166
|
+
declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
|
167
|
+
|
168
|
+
export { COMMON_ORPC_ERROR_DEFS, ClientContext, ClientLink, ClientOptions, ClientPromiseResult, DynamicLink, FriendlyClientOptions, InferClientContext, NestedClient, ORPCError, createORPCClient, createORPCErrorFromJson, fallbackORPCErrorMessage, fallbackORPCErrorStatus, isDefinedError, isORPCErrorJson, isORPCErrorStatus, mapEventIterator, resolveFriendlyClientOptions, safe, toORPCError };
|
169
|
+
export type { CommonORPCErrorCode, ORPCErrorCode, ORPCErrorJSON, ORPCErrorOptions, SafeResult, createORPCClientOptions };
|
package/dist/index.mjs
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
import { i as isDefinedError } from './shared/client.CRWEpqLB.mjs';
|
2
|
+
export { C as COMMON_ORPC_ERROR_DEFS, O as ORPCError, d as createORPCErrorFromJson, a as fallbackORPCErrorMessage, f as fallbackORPCErrorStatus, c as isORPCErrorJson, b as isORPCErrorStatus, m as mapEventIterator, t as toORPCError } from './shared/client.CRWEpqLB.mjs';
|
3
|
+
export { EventPublisher, onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
4
|
+
export { ErrorEvent } from '@orpc/standard-server';
|
5
|
+
|
6
|
+
async function safe(promise) {
|
7
|
+
try {
|
8
|
+
const output = await promise;
|
9
|
+
return Object.assign(
|
10
|
+
[null, output, false, true],
|
11
|
+
{ error: null, data: output, isDefined: false, isSuccess: true }
|
12
|
+
);
|
13
|
+
} catch (e) {
|
14
|
+
const error = e;
|
15
|
+
if (isDefinedError(error)) {
|
16
|
+
return Object.assign(
|
17
|
+
[error, void 0, true, false],
|
18
|
+
{ error, data: void 0, isDefined: true, isSuccess: false }
|
19
|
+
);
|
20
|
+
}
|
21
|
+
return Object.assign(
|
22
|
+
[error, void 0, false, false],
|
23
|
+
{ error, data: void 0, isDefined: false, isSuccess: false }
|
24
|
+
);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
function resolveFriendlyClientOptions(options) {
|
28
|
+
return {
|
29
|
+
...options,
|
30
|
+
context: options.context ?? {}
|
31
|
+
// Context only optional if all fields are optional
|
32
|
+
};
|
33
|
+
}
|
34
|
+
|
35
|
+
function createORPCClient(link, options) {
|
36
|
+
const path = options?.path ?? [];
|
37
|
+
const procedureClient = async (...[input, options2 = {}]) => {
|
38
|
+
return await link.call(path, input, resolveFriendlyClientOptions(options2));
|
39
|
+
};
|
40
|
+
const recursive = new Proxy(procedureClient, {
|
41
|
+
get(target, key) {
|
42
|
+
if (typeof key !== "string") {
|
43
|
+
return Reflect.get(target, key);
|
44
|
+
}
|
45
|
+
return createORPCClient(link, {
|
46
|
+
...options,
|
47
|
+
path: [...path, key]
|
48
|
+
});
|
49
|
+
}
|
50
|
+
});
|
51
|
+
return recursive;
|
52
|
+
}
|
53
|
+
|
54
|
+
class DynamicLink {
|
55
|
+
constructor(linkResolver) {
|
56
|
+
this.linkResolver = linkResolver;
|
57
|
+
}
|
58
|
+
async call(path, input, options) {
|
59
|
+
const resolvedLink = await this.linkResolver(options, path, input);
|
60
|
+
const output = await resolvedLink.call(path, input, options);
|
61
|
+
return output;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
export { DynamicLink, createORPCClient, isDefinedError, resolveFriendlyClientOptions, safe };
|
@@ -0,0 +1,202 @@
|
|
1
|
+
import { Value, Promisable } from '@orpc/shared';
|
2
|
+
import { StandardHeaders, StandardRequest } from '@orpc/standard-server';
|
3
|
+
import { BatchResponseMode } from '@orpc/standard-server/batch';
|
4
|
+
import { S as StandardLinkClientInterceptorOptions, a as StandardLinkPlugin, b as StandardLinkOptions, c as StandardLinkInterceptorOptions } from '../shared/client.BMoG_EdN.mjs';
|
5
|
+
import { a as ClientContext } from '../shared/client.4TS_0JaO.mjs';
|
6
|
+
|
7
|
+
interface BatchLinkPluginGroup<T extends ClientContext> {
|
8
|
+
condition(options: StandardLinkClientInterceptorOptions<T>): boolean;
|
9
|
+
context: T;
|
10
|
+
path?: readonly string[];
|
11
|
+
input?: unknown;
|
12
|
+
}
|
13
|
+
interface BatchLinkPluginOptions<T extends ClientContext> {
|
14
|
+
groups: readonly [BatchLinkPluginGroup<T>, ...BatchLinkPluginGroup<T>[]];
|
15
|
+
/**
|
16
|
+
* The maximum number of requests in the batch.
|
17
|
+
*
|
18
|
+
* @default 10
|
19
|
+
*/
|
20
|
+
maxSize?: Value<Promisable<number>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
21
|
+
/**
|
22
|
+
* The batch response mode.
|
23
|
+
*
|
24
|
+
* @default 'streaming'
|
25
|
+
*/
|
26
|
+
mode?: Value<BatchResponseMode, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
27
|
+
/**
|
28
|
+
* Defines the URL to use for the batch request.
|
29
|
+
*
|
30
|
+
* @default the URL of the first request in the batch + '/__batch__'
|
31
|
+
*/
|
32
|
+
url?: Value<Promisable<string | URL>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
33
|
+
/**
|
34
|
+
* The maximum length of the URL.
|
35
|
+
*
|
36
|
+
* @default 2083
|
37
|
+
*/
|
38
|
+
maxUrlLength?: Value<Promisable<number>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
39
|
+
/**
|
40
|
+
* Defines the HTTP headers to use for the batch request.
|
41
|
+
*
|
42
|
+
* @default The same headers of all requests in the batch
|
43
|
+
*/
|
44
|
+
headers?: Value<Promisable<StandardHeaders>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
45
|
+
/**
|
46
|
+
* Map the batch request items before sending them.
|
47
|
+
*
|
48
|
+
* @default Removes headers that are duplicated in the batch headers.
|
49
|
+
*/
|
50
|
+
mapRequestItem?: (options: StandardLinkClientInterceptorOptions<T> & {
|
51
|
+
batchUrl: URL;
|
52
|
+
batchHeaders: StandardHeaders;
|
53
|
+
}) => StandardRequest;
|
54
|
+
/**
|
55
|
+
* Exclude a request from the batch.
|
56
|
+
*
|
57
|
+
* @default () => false
|
58
|
+
*/
|
59
|
+
exclude?: (options: StandardLinkClientInterceptorOptions<T>) => boolean;
|
60
|
+
}
|
61
|
+
/**
|
62
|
+
* The Batch Requests Plugin allows you to combine multiple requests and responses into a single batch,
|
63
|
+
* reducing the overhead of sending each one separately.
|
64
|
+
*
|
65
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/batch-requests Batch Requests Plugin Docs}
|
66
|
+
*/
|
67
|
+
declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
68
|
+
#private;
|
69
|
+
private readonly groups;
|
70
|
+
private readonly maxSize;
|
71
|
+
private readonly batchUrl;
|
72
|
+
private readonly maxUrlLength;
|
73
|
+
private readonly batchHeaders;
|
74
|
+
private readonly mapRequestItem;
|
75
|
+
private readonly exclude;
|
76
|
+
private readonly mode;
|
77
|
+
private pending;
|
78
|
+
order: number;
|
79
|
+
constructor(options: NoInfer<BatchLinkPluginOptions<T>>);
|
80
|
+
init(options: StandardLinkOptions<T>): void;
|
81
|
+
}
|
82
|
+
|
83
|
+
interface DedupeRequestsPluginGroup<T extends ClientContext> {
|
84
|
+
condition(options: StandardLinkClientInterceptorOptions<T>): boolean;
|
85
|
+
/**
|
86
|
+
* The context used for the rest of the request lifecycle.
|
87
|
+
*/
|
88
|
+
context: T;
|
89
|
+
}
|
90
|
+
interface DedupeRequestsPluginOptions<T extends ClientContext> {
|
91
|
+
/**
|
92
|
+
* To enable deduplication, a request must match at least one defined group.
|
93
|
+
* Requests that fall into the same group are considered for deduplication together.
|
94
|
+
*/
|
95
|
+
groups: readonly [DedupeRequestsPluginGroup<T>, ...DedupeRequestsPluginGroup<T>[]];
|
96
|
+
/**
|
97
|
+
* Filters requests to dedupe
|
98
|
+
*
|
99
|
+
* @default (({ request }) => request.method === 'GET')
|
100
|
+
*/
|
101
|
+
filter?: (options: StandardLinkClientInterceptorOptions<T>) => boolean;
|
102
|
+
}
|
103
|
+
/**
|
104
|
+
* Prevents duplicate requests by deduplicating similar ones to reduce server load.
|
105
|
+
*
|
106
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/dedupe-requests Dedupe Requests Plugin}
|
107
|
+
*/
|
108
|
+
declare class DedupeRequestsPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
109
|
+
#private;
|
110
|
+
order: number;
|
111
|
+
constructor(options: NoInfer<DedupeRequestsPluginOptions<T>>);
|
112
|
+
init(options: StandardLinkOptions<T>): void;
|
113
|
+
}
|
114
|
+
|
115
|
+
interface ClientRetryPluginAttemptOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> {
|
116
|
+
lastEventRetry: number | undefined;
|
117
|
+
attemptIndex: number;
|
118
|
+
error: unknown;
|
119
|
+
}
|
120
|
+
interface ClientRetryPluginContext {
|
121
|
+
/**
|
122
|
+
* Maximum retry attempts before throwing
|
123
|
+
* Use `Number.POSITIVE_INFINITY` for infinite retries (e.g., when handling Server-Sent Events).
|
124
|
+
*
|
125
|
+
* @default 0
|
126
|
+
*/
|
127
|
+
retry?: Value<Promisable<number>, [StandardLinkInterceptorOptions<ClientRetryPluginContext>]>;
|
128
|
+
/**
|
129
|
+
* Delay (in ms) before retrying.
|
130
|
+
*
|
131
|
+
* @default (o) => o.lastEventRetry ?? 2000
|
132
|
+
*/
|
133
|
+
retryDelay?: Value<Promisable<number>, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
|
134
|
+
/**
|
135
|
+
* Determine should retry or not.
|
136
|
+
*
|
137
|
+
* @default true
|
138
|
+
*/
|
139
|
+
shouldRetry?: Value<Promisable<boolean>, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
|
140
|
+
/**
|
141
|
+
* The hook called when retrying, and return the unsubscribe function.
|
142
|
+
*/
|
143
|
+
onRetry?: (options: ClientRetryPluginAttemptOptions<ClientRetryPluginContext>) => void | ((isSuccess: boolean) => void);
|
144
|
+
}
|
145
|
+
declare class ClientRetryPluginInvalidEventIteratorRetryResponse extends Error {
|
146
|
+
}
|
147
|
+
interface ClientRetryPluginOptions {
|
148
|
+
default?: ClientRetryPluginContext;
|
149
|
+
}
|
150
|
+
/**
|
151
|
+
* The Client Retry Plugin enables retrying client calls when errors occur.
|
152
|
+
*
|
153
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/client-retry Client Retry Plugin Docs}
|
154
|
+
*/
|
155
|
+
declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements StandardLinkPlugin<T> {
|
156
|
+
private readonly defaultRetry;
|
157
|
+
private readonly defaultRetryDelay;
|
158
|
+
private readonly defaultShouldRetry;
|
159
|
+
private readonly defaultOnRetry;
|
160
|
+
constructor(options?: ClientRetryPluginOptions);
|
161
|
+
init(options: StandardLinkOptions<T>): void;
|
162
|
+
}
|
163
|
+
|
164
|
+
interface SimpleCsrfProtectionLinkPluginOptions<T extends ClientContext> {
|
165
|
+
/**
|
166
|
+
* The name of the header to check.
|
167
|
+
*
|
168
|
+
* @default 'x-csrf-token'
|
169
|
+
*/
|
170
|
+
headerName?: Value<Promisable<string>, [options: StandardLinkClientInterceptorOptions<T>]>;
|
171
|
+
/**
|
172
|
+
* The value of the header to check.
|
173
|
+
*
|
174
|
+
* @default 'orpc'
|
175
|
+
*
|
176
|
+
*/
|
177
|
+
headerValue?: Value<Promisable<string>, [options: StandardLinkClientInterceptorOptions<T>]>;
|
178
|
+
/**
|
179
|
+
* Exclude a procedure from the plugin.
|
180
|
+
*
|
181
|
+
* @default false
|
182
|
+
*/
|
183
|
+
exclude?: Value<Promisable<boolean>, [options: StandardLinkClientInterceptorOptions<T>]>;
|
184
|
+
}
|
185
|
+
/**
|
186
|
+
* This plugin adds basic Cross-Site Request Forgery (CSRF) protection to your oRPC application.
|
187
|
+
* It helps ensure that requests to your procedures originate from JavaScript code,
|
188
|
+
* not from other sources like standard HTML forms or direct browser navigation.
|
189
|
+
*
|
190
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
|
191
|
+
*/
|
192
|
+
declare class SimpleCsrfProtectionLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
193
|
+
private readonly headerName;
|
194
|
+
private readonly headerValue;
|
195
|
+
private readonly exclude;
|
196
|
+
constructor(options?: SimpleCsrfProtectionLinkPluginOptions<T>);
|
197
|
+
order: number;
|
198
|
+
init(options: StandardLinkOptions<T>): void;
|
199
|
+
}
|
200
|
+
|
201
|
+
export { BatchLinkPlugin, ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse, DedupeRequestsPlugin, SimpleCsrfProtectionLinkPlugin };
|
202
|
+
export type { BatchLinkPluginGroup, BatchLinkPluginOptions, ClientRetryPluginAttemptOptions, ClientRetryPluginContext, ClientRetryPluginOptions, DedupeRequestsPluginGroup, DedupeRequestsPluginOptions, SimpleCsrfProtectionLinkPluginOptions };
|