@orpc/client 0.0.0-next.32a6de9 → 0.0.0-next.32e1281
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 +17 -22
- package/dist/adapters/fetch/index.d.mts +13 -6
- package/dist/adapters/fetch/index.d.ts +13 -6
- package/dist/adapters/fetch/index.mjs +5 -8
- 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 +3 -3
- package/dist/adapters/standard/index.d.ts +3 -3
- 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 +22 -8
- package/dist/index.d.ts +22 -8
- package/dist/index.mjs +4 -4
- package/dist/plugins/index.d.mts +103 -13
- package/dist/plugins/index.d.ts +103 -13
- package/dist/plugins/index.mjs +150 -17
- package/dist/shared/{client.CipPQkhk.d.ts → client.4TS_0JaO.d.mts} +1 -1
- package/dist/shared/{client.CipPQkhk.d.mts → client.4TS_0JaO.d.ts} +1 -1
- package/dist/shared/{client.cs2A0fEV.d.ts → client.7UM0t5o-.d.ts} +13 -9
- package/dist/shared/{client.p3ON_yzu.d.ts → client.BMoG_EdN.d.mts} +16 -10
- package/dist/shared/{client.jKEwIsRd.mjs → client.BX0_8bnM.mjs} +30 -33
- package/dist/shared/{client.Cev5VIeo.d.mts → client.BdD8cpjs.d.mts} +13 -9
- package/dist/shared/{client.C7z5zk4v.d.mts → client.C0KbSWlC.d.ts} +16 -10
- package/dist/shared/{client.BQuFq0Vi.mjs → client.CQCGVpTM.mjs} +33 -16
- 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, ThrowableError } from '@orpc/shared';
|
|
4
|
-
export { Registry, ThrowableError, 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,18 +127,18 @@ 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>;
|
|
129
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>;
|
|
130
137
|
|
|
131
138
|
declare function mapEventIterator<TYield, TReturn, TNext, TMap = TYield | TReturn>(iterator: AsyncIterator<TYield, TReturn, TNext>, maps: {
|
|
132
139
|
value: (value: NoInfer<TYield | TReturn>, done: boolean | undefined) => Promise<TMap>;
|
|
133
140
|
error: (error: unknown) => Promise<unknown>;
|
|
134
|
-
}):
|
|
141
|
+
}): AsyncIteratorClass<TMap, TMap, TNext>;
|
|
135
142
|
|
|
136
143
|
type SafeResult<TOutput, TError> = [error: null, data: TOutput, isDefined: false, isSuccess: true] & {
|
|
137
144
|
error: null;
|
|
@@ -149,7 +156,14 @@ type SafeResult<TOutput, TError> = [error: null, data: TOutput, isDefined: false
|
|
|
149
156
|
isDefined: true;
|
|
150
157
|
isSuccess: false;
|
|
151
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
|
+
*/
|
|
152
165
|
declare function safe<TOutput, TError = ThrowableError>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
|
|
153
166
|
declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
|
|
154
167
|
|
|
155
|
-
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,6 +1,6 @@
|
|
|
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, b as isORPCErrorStatus, 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) {
|
|
@@ -27,7 +27,7 @@ async function safe(promise) {
|
|
|
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,7 +1,8 @@
|
|
|
1
|
-
import { Value } from '@orpc/shared';
|
|
1
|
+
import { Value, Promisable } from '@orpc/shared';
|
|
2
2
|
import { StandardHeaders, StandardRequest } from '@orpc/standard-server';
|
|
3
|
-
import {
|
|
4
|
-
import { a as
|
|
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
7
|
interface BatchLinkPluginGroup<T extends ClientContext> {
|
|
7
8
|
condition(options: StandardLinkClientInterceptorOptions<T>): boolean;
|
|
@@ -16,25 +17,31 @@ interface BatchLinkPluginOptions<T extends ClientContext> {
|
|
|
16
17
|
*
|
|
17
18
|
* @default 10
|
|
18
19
|
*/
|
|
19
|
-
maxSize?: Value<number
|
|
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>[]]]>;
|
|
20
27
|
/**
|
|
21
28
|
* Defines the URL to use for the batch request.
|
|
22
29
|
*
|
|
23
30
|
* @default the URL of the first request in the batch + '/__batch__'
|
|
24
31
|
*/
|
|
25
|
-
url?: Value<string | URL
|
|
32
|
+
url?: Value<Promisable<string | URL>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
26
33
|
/**
|
|
27
34
|
* The maximum length of the URL.
|
|
28
35
|
*
|
|
29
36
|
* @default 2083
|
|
30
37
|
*/
|
|
31
|
-
maxUrlLength?: Value<number
|
|
38
|
+
maxUrlLength?: Value<Promisable<number>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
32
39
|
/**
|
|
33
40
|
* Defines the HTTP headers to use for the batch request.
|
|
34
41
|
*
|
|
35
42
|
* @default The same headers of all requests in the batch
|
|
36
43
|
*/
|
|
37
|
-
headers?: Value<StandardHeaders
|
|
44
|
+
headers?: Value<Promisable<StandardHeaders>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
38
45
|
/**
|
|
39
46
|
* Map the batch request items before sending them.
|
|
40
47
|
*
|
|
@@ -51,6 +58,12 @@ interface BatchLinkPluginOptions<T extends ClientContext> {
|
|
|
51
58
|
*/
|
|
52
59
|
exclude?: (options: StandardLinkClientInterceptorOptions<T>) => boolean;
|
|
53
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
|
+
*/
|
|
54
67
|
declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
55
68
|
#private;
|
|
56
69
|
private readonly groups;
|
|
@@ -60,8 +73,42 @@ declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPl
|
|
|
60
73
|
private readonly batchHeaders;
|
|
61
74
|
private readonly mapRequestItem;
|
|
62
75
|
private readonly exclude;
|
|
76
|
+
private readonly mode;
|
|
63
77
|
private pending;
|
|
64
|
-
|
|
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>>);
|
|
65
112
|
init(options: StandardLinkOptions<T>): void;
|
|
66
113
|
}
|
|
67
114
|
|
|
@@ -77,29 +124,34 @@ interface ClientRetryPluginContext {
|
|
|
77
124
|
*
|
|
78
125
|
* @default 0
|
|
79
126
|
*/
|
|
80
|
-
retry?: Value<number
|
|
127
|
+
retry?: Value<Promisable<number>, [StandardLinkInterceptorOptions<ClientRetryPluginContext>]>;
|
|
81
128
|
/**
|
|
82
129
|
* Delay (in ms) before retrying.
|
|
83
130
|
*
|
|
84
131
|
* @default (o) => o.lastEventRetry ?? 2000
|
|
85
132
|
*/
|
|
86
|
-
retryDelay?: Value<number
|
|
133
|
+
retryDelay?: Value<Promisable<number>, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
|
|
87
134
|
/**
|
|
88
135
|
* Determine should retry or not.
|
|
89
136
|
*
|
|
90
137
|
* @default true
|
|
91
138
|
*/
|
|
92
|
-
shouldRetry?: Value<boolean
|
|
139
|
+
shouldRetry?: Value<Promisable<boolean>, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
|
|
93
140
|
/**
|
|
94
141
|
* The hook called when retrying, and return the unsubscribe function.
|
|
95
142
|
*/
|
|
96
|
-
onRetry?: (options: ClientRetryPluginAttemptOptions<ClientRetryPluginContext>) => void | (() => void);
|
|
143
|
+
onRetry?: (options: ClientRetryPluginAttemptOptions<ClientRetryPluginContext>) => void | ((isSuccess: boolean) => void);
|
|
97
144
|
}
|
|
98
145
|
declare class ClientRetryPluginInvalidEventIteratorRetryResponse extends Error {
|
|
99
146
|
}
|
|
100
147
|
interface ClientRetryPluginOptions {
|
|
101
148
|
default?: ClientRetryPluginContext;
|
|
102
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
|
+
*/
|
|
103
155
|
declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements StandardLinkPlugin<T> {
|
|
104
156
|
private readonly defaultRetry;
|
|
105
157
|
private readonly defaultRetryDelay;
|
|
@@ -109,4 +161,42 @@ declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements S
|
|
|
109
161
|
init(options: StandardLinkOptions<T>): void;
|
|
110
162
|
}
|
|
111
163
|
|
|
112
|
-
|
|
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,7 +1,8 @@
|
|
|
1
|
-
import { Value } from '@orpc/shared';
|
|
1
|
+
import { Value, Promisable } from '@orpc/shared';
|
|
2
2
|
import { StandardHeaders, StandardRequest } from '@orpc/standard-server';
|
|
3
|
-
import {
|
|
4
|
-
import { a as
|
|
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
7
|
interface BatchLinkPluginGroup<T extends ClientContext> {
|
|
7
8
|
condition(options: StandardLinkClientInterceptorOptions<T>): boolean;
|
|
@@ -16,25 +17,31 @@ interface BatchLinkPluginOptions<T extends ClientContext> {
|
|
|
16
17
|
*
|
|
17
18
|
* @default 10
|
|
18
19
|
*/
|
|
19
|
-
maxSize?: Value<number
|
|
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>[]]]>;
|
|
20
27
|
/**
|
|
21
28
|
* Defines the URL to use for the batch request.
|
|
22
29
|
*
|
|
23
30
|
* @default the URL of the first request in the batch + '/__batch__'
|
|
24
31
|
*/
|
|
25
|
-
url?: Value<string | URL
|
|
32
|
+
url?: Value<Promisable<string | URL>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
26
33
|
/**
|
|
27
34
|
* The maximum length of the URL.
|
|
28
35
|
*
|
|
29
36
|
* @default 2083
|
|
30
37
|
*/
|
|
31
|
-
maxUrlLength?: Value<number
|
|
38
|
+
maxUrlLength?: Value<Promisable<number>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
32
39
|
/**
|
|
33
40
|
* Defines the HTTP headers to use for the batch request.
|
|
34
41
|
*
|
|
35
42
|
* @default The same headers of all requests in the batch
|
|
36
43
|
*/
|
|
37
|
-
headers?: Value<StandardHeaders
|
|
44
|
+
headers?: Value<Promisable<StandardHeaders>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
38
45
|
/**
|
|
39
46
|
* Map the batch request items before sending them.
|
|
40
47
|
*
|
|
@@ -51,6 +58,12 @@ interface BatchLinkPluginOptions<T extends ClientContext> {
|
|
|
51
58
|
*/
|
|
52
59
|
exclude?: (options: StandardLinkClientInterceptorOptions<T>) => boolean;
|
|
53
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
|
+
*/
|
|
54
67
|
declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
55
68
|
#private;
|
|
56
69
|
private readonly groups;
|
|
@@ -60,8 +73,42 @@ declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPl
|
|
|
60
73
|
private readonly batchHeaders;
|
|
61
74
|
private readonly mapRequestItem;
|
|
62
75
|
private readonly exclude;
|
|
76
|
+
private readonly mode;
|
|
63
77
|
private pending;
|
|
64
|
-
|
|
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>>);
|
|
65
112
|
init(options: StandardLinkOptions<T>): void;
|
|
66
113
|
}
|
|
67
114
|
|
|
@@ -77,29 +124,34 @@ interface ClientRetryPluginContext {
|
|
|
77
124
|
*
|
|
78
125
|
* @default 0
|
|
79
126
|
*/
|
|
80
|
-
retry?: Value<number
|
|
127
|
+
retry?: Value<Promisable<number>, [StandardLinkInterceptorOptions<ClientRetryPluginContext>]>;
|
|
81
128
|
/**
|
|
82
129
|
* Delay (in ms) before retrying.
|
|
83
130
|
*
|
|
84
131
|
* @default (o) => o.lastEventRetry ?? 2000
|
|
85
132
|
*/
|
|
86
|
-
retryDelay?: Value<number
|
|
133
|
+
retryDelay?: Value<Promisable<number>, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
|
|
87
134
|
/**
|
|
88
135
|
* Determine should retry or not.
|
|
89
136
|
*
|
|
90
137
|
* @default true
|
|
91
138
|
*/
|
|
92
|
-
shouldRetry?: Value<boolean
|
|
139
|
+
shouldRetry?: Value<Promisable<boolean>, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
|
|
93
140
|
/**
|
|
94
141
|
* The hook called when retrying, and return the unsubscribe function.
|
|
95
142
|
*/
|
|
96
|
-
onRetry?: (options: ClientRetryPluginAttemptOptions<ClientRetryPluginContext>) => void | (() => void);
|
|
143
|
+
onRetry?: (options: ClientRetryPluginAttemptOptions<ClientRetryPluginContext>) => void | ((isSuccess: boolean) => void);
|
|
97
144
|
}
|
|
98
145
|
declare class ClientRetryPluginInvalidEventIteratorRetryResponse extends Error {
|
|
99
146
|
}
|
|
100
147
|
interface ClientRetryPluginOptions {
|
|
101
148
|
default?: ClientRetryPluginContext;
|
|
102
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
|
+
*/
|
|
103
155
|
declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements StandardLinkPlugin<T> {
|
|
104
156
|
private readonly defaultRetry;
|
|
105
157
|
private readonly defaultRetryDelay;
|
|
@@ -109,4 +161,42 @@ declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements S
|
|
|
109
161
|
init(options: StandardLinkOptions<T>): void;
|
|
110
162
|
}
|
|
111
163
|
|
|
112
|
-
|
|
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 };
|