@orpc/client 0.0.0-next.ea0903c → 0.0.0-next.eaf61c7
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 +18 -22
- package/dist/adapters/fetch/index.d.mts +15 -12
- package/dist/adapters/fetch/index.d.ts +15 -12
- package/dist/adapters/fetch/index.mjs +5 -12
- 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 +5 -4
- package/dist/adapters/standard/index.d.ts +5 -4
- package/dist/adapters/standard/index.mjs +2 -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 +44 -0
- package/dist/index.d.mts +30 -12
- package/dist/index.d.ts +30 -12
- package/dist/index.mjs +10 -10
- package/dist/plugins/index.d.mts +162 -21
- package/dist/plugins/index.d.ts +162 -21
- package/dist/plugins/index.mjs +306 -43
- package/dist/shared/{client.87WXDX8t.d.mts → client.4TS_0JaO.d.mts} +12 -15
- package/dist/shared/{client.87WXDX8t.d.ts → client.4TS_0JaO.d.ts} +12 -15
- package/dist/shared/{client.CZFIVTQj.d.ts → client.7UM0t5o-.d.ts} +13 -25
- package/dist/shared/{client.D9lmRwGB.d.mts → client.BMoG_EdN.d.mts} +20 -13
- package/dist/shared/{client.BacCdg3F.mjs → client.BX0_8bnM.mjs} +35 -35
- package/dist/shared/{client.BC0T26HA.d.mts → client.BdD8cpjs.d.mts} +13 -25
- package/dist/shared/{client.BaocqKnn.d.ts → client.C0KbSWlC.d.ts} +20 -13
- package/dist/shared/{client.F0iTxiCl.mjs → client.CQCGVpTM.mjs} +43 -26
- package/package.json +16 -5
package/dist/index.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
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.
|
2
|
-
export { f as Client, e as ClientRest, d as HTTPMethod, H as HTTPPath } from './shared/client.
|
3
|
-
import { Promisable, MaybeOptionalOptions } from '@orpc/shared';
|
4
|
-
export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
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, AsyncIteratorClass, ThrowableError } from '@orpc/shared';
|
4
|
+
export { EventPublisher, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, Registry, ThrowableError, onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
5
5
|
export { ErrorEvent } from '@orpc/standard-server';
|
6
6
|
|
7
7
|
interface createORPCClientOptions {
|
@@ -10,11 +10,18 @@ interface createORPCClientOptions {
|
|
10
10
|
*/
|
11
11
|
path?: string[];
|
12
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
|
+
*/
|
13
18
|
declare function createORPCClient<T extends NestedClient<any>>(link: ClientLink<InferClientContext<T>>, options?: createORPCClientOptions): T;
|
14
19
|
|
15
20
|
/**
|
16
21
|
* DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
|
17
22
|
* based on the request path, input, and context.
|
23
|
+
*
|
24
|
+
* @see {@link https://orpc.unnoq.com/docs/client/dynamic-link Dynamic Link Docs}
|
18
25
|
*/
|
19
26
|
declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
|
20
27
|
private readonly linkResolver;
|
@@ -120,32 +127,43 @@ declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
|
|
120
127
|
readonly data: TData;
|
121
128
|
constructor(code: TCode, ...[options]: MaybeOptionalOptions<ORPCErrorOptions<TData>>);
|
122
129
|
toJSON(): ORPCErrorJSON<TCode, TData>;
|
123
|
-
static fromJSON<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>;
|
124
|
-
static isValidJSON(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
|
125
130
|
}
|
126
131
|
type ORPCErrorJSON<TCode extends string, TData> = Pick<ORPCError<TCode, TData>, 'defined' | 'code' | 'status' | 'message' | 'data'>;
|
127
132
|
declare function isDefinedError<T>(error: T): error is Extract<T, ORPCError<any, any>>;
|
128
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>;
|
129
137
|
|
130
138
|
declare function mapEventIterator<TYield, TReturn, TNext, TMap = TYield | TReturn>(iterator: AsyncIterator<TYield, TReturn, TNext>, maps: {
|
131
139
|
value: (value: NoInfer<TYield | TReturn>, done: boolean | undefined) => Promise<TMap>;
|
132
140
|
error: (error: unknown) => Promise<unknown>;
|
133
|
-
}):
|
141
|
+
}): AsyncIteratorClass<TMap, TMap, TNext>;
|
134
142
|
|
135
|
-
type SafeResult<TOutput, TError
|
143
|
+
type SafeResult<TOutput, TError> = [error: null, data: TOutput, isDefined: false, isSuccess: true] & {
|
136
144
|
error: null;
|
137
145
|
data: TOutput;
|
138
146
|
isDefined: false;
|
139
|
-
|
147
|
+
isSuccess: true;
|
148
|
+
} | [error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false, isSuccess: false] & {
|
140
149
|
error: Exclude<TError, ORPCError<any, any>>;
|
141
150
|
data: undefined;
|
142
151
|
isDefined: false;
|
143
|
-
|
152
|
+
isSuccess: false;
|
153
|
+
} | [error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true, isSuccess: false] & {
|
144
154
|
error: Extract<TError, ORPCError<any, any>>;
|
145
155
|
data: undefined;
|
146
156
|
isDefined: true;
|
157
|
+
isSuccess: false;
|
147
158
|
};
|
148
|
-
|
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>>;
|
149
166
|
declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
|
150
167
|
|
151
|
-
export { COMMON_ORPC_ERROR_DEFS, ClientContext, ClientLink, ClientOptions, ClientPromiseResult,
|
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
CHANGED
@@ -1,33 +1,33 @@
|
|
1
|
-
import { i as isDefinedError } from './shared/client.
|
2
|
-
export { C as COMMON_ORPC_ERROR_DEFS, O as ORPCError, a as fallbackORPCErrorMessage, f as fallbackORPCErrorStatus, m as mapEventIterator, t as toORPCError } from './shared/client.
|
3
|
-
export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
1
|
+
import { i as isDefinedError } from './shared/client.BX0_8bnM.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.BX0_8bnM.mjs';
|
3
|
+
export { EventPublisher, onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
4
4
|
export { ErrorEvent } from '@orpc/standard-server';
|
5
5
|
|
6
6
|
async function safe(promise) {
|
7
7
|
try {
|
8
8
|
const output = await promise;
|
9
9
|
return Object.assign(
|
10
|
-
[null, output, false],
|
11
|
-
{ error: null, data: output, isDefined: false }
|
10
|
+
[null, output, false, true],
|
11
|
+
{ error: null, data: output, isDefined: false, isSuccess: true }
|
12
12
|
);
|
13
13
|
} catch (e) {
|
14
14
|
const error = e;
|
15
15
|
if (isDefinedError(error)) {
|
16
16
|
return Object.assign(
|
17
|
-
[error, void 0, true],
|
18
|
-
{ error, data: void 0, isDefined: true }
|
17
|
+
[error, void 0, true, false],
|
18
|
+
{ error, data: void 0, isDefined: true, isSuccess: false }
|
19
19
|
);
|
20
20
|
}
|
21
21
|
return Object.assign(
|
22
|
-
[error, void 0, false],
|
23
|
-
{ error, data: void 0, isDefined: false }
|
22
|
+
[error, void 0, false, false],
|
23
|
+
{ error, data: void 0, isDefined: false, isSuccess: false }
|
24
24
|
);
|
25
25
|
}
|
26
26
|
}
|
27
27
|
function resolveFriendlyClientOptions(options) {
|
28
28
|
return {
|
29
29
|
...options,
|
30
|
-
context: options
|
30
|
+
context: options.context ?? {}
|
31
31
|
// Context only optional if all fields are optional
|
32
32
|
};
|
33
33
|
}
|
package/dist/plugins/index.d.mts
CHANGED
@@ -1,11 +1,119 @@
|
|
1
|
-
import { Value } from '@orpc/shared';
|
2
|
-
import {
|
3
|
-
import {
|
4
|
-
import '
|
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';
|
5
6
|
|
6
|
-
interface
|
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> {
|
7
116
|
lastEventRetry: number | undefined;
|
8
|
-
lastEventId: string | undefined;
|
9
117
|
attemptIndex: number;
|
10
118
|
error: unknown;
|
11
119
|
}
|
@@ -16,39 +124,34 @@ interface ClientRetryPluginContext {
|
|
16
124
|
*
|
17
125
|
* @default 0
|
18
126
|
*/
|
19
|
-
retry?: number
|
127
|
+
retry?: Value<Promisable<number>, [StandardLinkInterceptorOptions<ClientRetryPluginContext>]>;
|
20
128
|
/**
|
21
129
|
* Delay (in ms) before retrying.
|
22
130
|
*
|
23
131
|
* @default (o) => o.lastEventRetry ?? 2000
|
24
132
|
*/
|
25
|
-
retryDelay?: Value<number
|
26
|
-
attemptOptions: ClientRetryPluginAttemptOptions,
|
27
|
-
clientOptions: ClientOptions<ClientRetryPluginContext>,
|
28
|
-
path: readonly string[],
|
29
|
-
input: unknown
|
30
|
-
]>;
|
133
|
+
retryDelay?: Value<Promisable<number>, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
|
31
134
|
/**
|
32
135
|
* Determine should retry or not.
|
33
136
|
*
|
34
137
|
* @default true
|
35
138
|
*/
|
36
|
-
shouldRetry?: Value<boolean
|
37
|
-
attemptOptions: ClientRetryPluginAttemptOptions,
|
38
|
-
clientOptions: ClientOptions<ClientRetryPluginContext>,
|
39
|
-
path: readonly string[],
|
40
|
-
input: unknown
|
41
|
-
]>;
|
139
|
+
shouldRetry?: Value<Promisable<boolean>, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
|
42
140
|
/**
|
43
141
|
* The hook called when retrying, and return the unsubscribe function.
|
44
142
|
*/
|
45
|
-
onRetry?: (options: ClientRetryPluginAttemptOptions
|
143
|
+
onRetry?: (options: ClientRetryPluginAttemptOptions<ClientRetryPluginContext>) => void | ((isSuccess: boolean) => void);
|
46
144
|
}
|
47
145
|
declare class ClientRetryPluginInvalidEventIteratorRetryResponse extends Error {
|
48
146
|
}
|
49
147
|
interface ClientRetryPluginOptions {
|
50
148
|
default?: ClientRetryPluginContext;
|
51
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
|
+
*/
|
52
155
|
declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements StandardLinkPlugin<T> {
|
53
156
|
private readonly defaultRetry;
|
54
157
|
private readonly defaultRetryDelay;
|
@@ -58,4 +161,42 @@ declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements S
|
|
58
161
|
init(options: StandardLinkOptions<T>): void;
|
59
162
|
}
|
60
163
|
|
61
|
-
|
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 };
|
package/dist/plugins/index.d.ts
CHANGED
@@ -1,11 +1,119 @@
|
|
1
|
-
import { Value } from '@orpc/shared';
|
2
|
-
import {
|
3
|
-
import {
|
4
|
-
import '
|
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.C0KbSWlC.js';
|
5
|
+
import { a as ClientContext } from '../shared/client.4TS_0JaO.js';
|
5
6
|
|
6
|
-
interface
|
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> {
|
7
116
|
lastEventRetry: number | undefined;
|
8
|
-
lastEventId: string | undefined;
|
9
117
|
attemptIndex: number;
|
10
118
|
error: unknown;
|
11
119
|
}
|
@@ -16,39 +124,34 @@ interface ClientRetryPluginContext {
|
|
16
124
|
*
|
17
125
|
* @default 0
|
18
126
|
*/
|
19
|
-
retry?: number
|
127
|
+
retry?: Value<Promisable<number>, [StandardLinkInterceptorOptions<ClientRetryPluginContext>]>;
|
20
128
|
/**
|
21
129
|
* Delay (in ms) before retrying.
|
22
130
|
*
|
23
131
|
* @default (o) => o.lastEventRetry ?? 2000
|
24
132
|
*/
|
25
|
-
retryDelay?: Value<number
|
26
|
-
attemptOptions: ClientRetryPluginAttemptOptions,
|
27
|
-
clientOptions: ClientOptions<ClientRetryPluginContext>,
|
28
|
-
path: readonly string[],
|
29
|
-
input: unknown
|
30
|
-
]>;
|
133
|
+
retryDelay?: Value<Promisable<number>, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
|
31
134
|
/**
|
32
135
|
* Determine should retry or not.
|
33
136
|
*
|
34
137
|
* @default true
|
35
138
|
*/
|
36
|
-
shouldRetry?: Value<boolean
|
37
|
-
attemptOptions: ClientRetryPluginAttemptOptions,
|
38
|
-
clientOptions: ClientOptions<ClientRetryPluginContext>,
|
39
|
-
path: readonly string[],
|
40
|
-
input: unknown
|
41
|
-
]>;
|
139
|
+
shouldRetry?: Value<Promisable<boolean>, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
|
42
140
|
/**
|
43
141
|
* The hook called when retrying, and return the unsubscribe function.
|
44
142
|
*/
|
45
|
-
onRetry?: (options: ClientRetryPluginAttemptOptions
|
143
|
+
onRetry?: (options: ClientRetryPluginAttemptOptions<ClientRetryPluginContext>) => void | ((isSuccess: boolean) => void);
|
46
144
|
}
|
47
145
|
declare class ClientRetryPluginInvalidEventIteratorRetryResponse extends Error {
|
48
146
|
}
|
49
147
|
interface ClientRetryPluginOptions {
|
50
148
|
default?: ClientRetryPluginContext;
|
51
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
|
+
*/
|
52
155
|
declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements StandardLinkPlugin<T> {
|
53
156
|
private readonly defaultRetry;
|
54
157
|
private readonly defaultRetryDelay;
|
@@ -58,4 +161,42 @@ declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements S
|
|
58
161
|
init(options: StandardLinkOptions<T>): void;
|
59
162
|
}
|
60
163
|
|
61
|
-
|
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 };
|