@orpc/client 0.0.0-next.ee46dab → 0.0.0-next.ee89076

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.
Files changed (28) hide show
  1. package/README.md +19 -22
  2. package/dist/adapters/fetch/index.d.mts +31 -11
  3. package/dist/adapters/fetch/index.d.ts +31 -11
  4. package/dist/adapters/fetch/index.mjs +26 -13
  5. package/dist/adapters/message-port/index.d.mts +59 -0
  6. package/dist/adapters/message-port/index.d.ts +59 -0
  7. package/dist/adapters/message-port/index.mjs +72 -0
  8. package/dist/adapters/standard/index.d.mts +6 -5
  9. package/dist/adapters/standard/index.d.ts +6 -5
  10. package/dist/adapters/standard/index.mjs +3 -2
  11. package/dist/adapters/websocket/index.d.mts +29 -0
  12. package/dist/adapters/websocket/index.d.ts +29 -0
  13. package/dist/adapters/websocket/index.mjs +46 -0
  14. package/dist/index.d.mts +53 -23
  15. package/dist/index.d.ts +53 -23
  16. package/dist/index.mjs +25 -8
  17. package/dist/plugins/index.d.mts +162 -25
  18. package/dist/plugins/index.d.ts +162 -25
  19. package/dist/plugins/index.mjs +331 -56
  20. package/dist/shared/{client.5813Ufvs.d.mts → client.BG98rYdO.d.ts} +21 -15
  21. package/dist/shared/{client.C0lT7w02.d.mts → client.BOYsZIRq.d.mts} +8 -9
  22. package/dist/shared/{client.C0lT7w02.d.ts → client.BOYsZIRq.d.ts} +8 -9
  23. package/dist/shared/{client.DSPm2IGZ.mjs → client.Bp1jlnBk.mjs} +89 -29
  24. package/dist/shared/{client.grRbC25r.d.ts → client.Bwgm6dgk.d.mts} +21 -15
  25. package/dist/shared/{client.D-jrSuDb.d.ts → client.CVVVqf1Y.d.ts} +13 -25
  26. package/dist/shared/{client.Bt94sjrK.d.mts → client._Y_enhib.d.mts} +13 -25
  27. package/dist/shared/{client.jKEwIsRd.mjs → client.txdq_i5V.mjs} +54 -49
  28. package/package.json +16 -5
package/dist/index.d.mts CHANGED
@@ -1,26 +1,21 @@
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.C0lT7w02.mjs';
2
- export { f as Client, e as ClientRest, d as HTTPMethod, H as HTTPPath } from './shared/client.C0lT7w02.mjs';
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 ClientPromiseResult, b as ClientContext, F as FriendlyClientOptions, c as ClientOptions, d as Client, e as ClientRest } from './shared/client.BOYsZIRq.mjs';
2
+ export { f as HTTPMethod, H as HTTPPath } from './shared/client.BOYsZIRq.mjs';
3
+ import { MaybeOptionalOptions, ThrowableError, Promisable, AsyncIteratorClass } from '@orpc/shared';
4
+ export { AsyncIteratorClass, EventPublisher, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, Registry, ThrowableError, asyncIteratorToStream as eventIteratorToStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared';
5
5
  export { ErrorEvent } from '@orpc/standard-server';
6
6
 
7
7
  interface createORPCClientOptions {
8
8
  /**
9
9
  * Use as base path for all procedure, useful when you only want to call a subset of the procedure.
10
10
  */
11
- path?: string[];
11
+ path?: readonly string[];
12
12
  }
13
- declare function createORPCClient<T extends NestedClient<any>>(link: ClientLink<InferClientContext<T>>, options?: createORPCClientOptions): T;
14
-
15
13
  /**
16
- * DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
17
- * based on the request path, input, and context.
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}
18
17
  */
19
- declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
20
- private readonly linkResolver;
21
- constructor(linkResolver: (options: ClientOptions<TClientContext>, path: readonly string[], input: unknown) => Promisable<ClientLink<TClientContext>>);
22
- call(path: readonly string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
23
- }
18
+ declare function createORPCClient<T extends NestedClient<any>>(link: ClientLink<InferClientContext<T>>, options?: createORPCClientOptions): T;
24
19
 
25
20
  declare const COMMON_ORPC_ERROR_DEFS: {
26
21
  readonly BAD_REQUEST: {
@@ -118,20 +113,15 @@ declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
118
113
  readonly code: TCode;
119
114
  readonly status: number;
120
115
  readonly data: TData;
121
- constructor(code: TCode, ...[options]: MaybeOptionalOptions<ORPCErrorOptions<TData>>);
116
+ constructor(code: TCode, ...rest: MaybeOptionalOptions<ORPCErrorOptions<TData>>);
122
117
  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
118
  }
126
119
  type ORPCErrorJSON<TCode extends string, TData> = Pick<ORPCError<TCode, TData>, 'defined' | 'code' | 'status' | 'message' | 'data'>;
127
120
  declare function isDefinedError<T>(error: T): error is Extract<T, ORPCError<any, any>>;
128
121
  declare function toORPCError(error: unknown): ORPCError<any, any>;
129
122
  declare function isORPCErrorStatus(status: number): boolean;
130
-
131
- declare function mapEventIterator<TYield, TReturn, TNext, TMap = TYield | TReturn>(iterator: AsyncIterator<TYield, TReturn, TNext>, maps: {
132
- value: (value: NoInfer<TYield | TReturn>, done: boolean | undefined) => Promise<TMap>;
133
- error: (error: unknown) => Promise<unknown>;
134
- }): AsyncGenerator<TMap, TMap, TNext>;
123
+ declare function isORPCErrorJson(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
124
+ declare function createORPCErrorFromJson<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>;
135
125
 
136
126
  type SafeResult<TOutput, TError> = [error: null, data: TOutput, isDefined: false, isSuccess: true] & {
137
127
  error: null;
@@ -149,7 +139,47 @@ type SafeResult<TOutput, TError> = [error: null, data: TOutput, isDefined: false
149
139
  isDefined: true;
150
140
  isSuccess: false;
151
141
  };
142
+ /**
143
+ * Works like try/catch, but can infer error types.
144
+ *
145
+ * @info support both tuple `[error, data, isDefined, isSuccess]` and object `{ error, data, isDefined, isSuccess }` styles.
146
+ * @see {@link https://orpc.unnoq.com/docs/client/error-handling Client Error Handling Docs}
147
+ */
152
148
  declare function safe<TOutput, TError = ThrowableError>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
153
149
  declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
154
150
 
155
- export { COMMON_ORPC_ERROR_DEFS, ClientContext, ClientLink, ClientOptions, ClientPromiseResult, type CommonORPCErrorCode, DynamicLink, FriendlyClientOptions, InferClientContext, NestedClient, ORPCError, type ORPCErrorCode, type ORPCErrorJSON, type ORPCErrorOptions, type SafeResult, createORPCClient, type createORPCClientOptions, fallbackORPCErrorMessage, fallbackORPCErrorStatus, isDefinedError, isORPCErrorStatus, mapEventIterator, resolveFriendlyClientOptions, safe, toORPCError };
151
+ type SafeClient<T extends NestedClient<any>> = T extends Client<infer UContext, infer UInput, infer UOutput, infer UError> ? (...rest: ClientRest<UContext, UInput>) => Promise<SafeResult<UOutput, UError>> : {
152
+ [K in keyof T]: T[K] extends NestedClient<any> ? SafeClient<T[K]> : never;
153
+ };
154
+ /**
155
+ * Create a safe client that automatically wraps all procedure calls with the `safe` util.
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * const safeClient = createSafeClient(client)
160
+ * const { error, data, isDefined } = await safeClient.doSomething({ id: '123' })
161
+ * ```
162
+ *
163
+ * @see {@link https://orpc.unnoq.com/docs/client/error-handling#using-createsafeclient Safe Client Docs}
164
+ */
165
+ declare function createSafeClient<T extends NestedClient<any>>(client: T): SafeClient<T>;
166
+
167
+ /**
168
+ * DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
169
+ * based on the request path, input, and context.
170
+ *
171
+ * @see {@link https://orpc.unnoq.com/docs/client/dynamic-link Dynamic Link Docs}
172
+ */
173
+ declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
174
+ private readonly linkResolver;
175
+ constructor(linkResolver: (options: ClientOptions<TClientContext>, path: readonly string[], input: unknown) => Promisable<ClientLink<TClientContext>>);
176
+ call(path: readonly string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
177
+ }
178
+
179
+ declare function mapEventIterator<TYield, TReturn, TNext, TMap = TYield | TReturn>(iterator: AsyncIterator<TYield, TReturn, TNext>, maps: {
180
+ value: (value: NoInfer<TYield | TReturn>, done: boolean | undefined) => Promise<TMap>;
181
+ error: (error: unknown) => Promise<unknown>;
182
+ }): AsyncIteratorClass<TMap, TMap, TNext>;
183
+
184
+ export { COMMON_ORPC_ERROR_DEFS, Client, ClientContext, ClientLink, ClientOptions, ClientPromiseResult, ClientRest, DynamicLink, FriendlyClientOptions, InferClientContext, NestedClient, ORPCError, createORPCClient, createORPCErrorFromJson, createSafeClient, fallbackORPCErrorMessage, fallbackORPCErrorStatus, isDefinedError, isORPCErrorJson, isORPCErrorStatus, mapEventIterator, resolveFriendlyClientOptions, safe, toORPCError };
185
+ export type { CommonORPCErrorCode, ORPCErrorCode, ORPCErrorJSON, ORPCErrorOptions, SafeClient, SafeResult, createORPCClientOptions };
package/dist/index.d.ts CHANGED
@@ -1,26 +1,21 @@
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.C0lT7w02.js';
2
- export { f as Client, e as ClientRest, d as HTTPMethod, H as HTTPPath } from './shared/client.C0lT7w02.js';
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 ClientPromiseResult, b as ClientContext, F as FriendlyClientOptions, c as ClientOptions, d as Client, e as ClientRest } from './shared/client.BOYsZIRq.js';
2
+ export { f as HTTPMethod, H as HTTPPath } from './shared/client.BOYsZIRq.js';
3
+ import { MaybeOptionalOptions, ThrowableError, Promisable, AsyncIteratorClass } from '@orpc/shared';
4
+ export { AsyncIteratorClass, EventPublisher, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, Registry, ThrowableError, asyncIteratorToStream as eventIteratorToStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared';
5
5
  export { ErrorEvent } from '@orpc/standard-server';
6
6
 
7
7
  interface createORPCClientOptions {
8
8
  /**
9
9
  * Use as base path for all procedure, useful when you only want to call a subset of the procedure.
10
10
  */
11
- path?: string[];
11
+ path?: readonly string[];
12
12
  }
13
- declare function createORPCClient<T extends NestedClient<any>>(link: ClientLink<InferClientContext<T>>, options?: createORPCClientOptions): T;
14
-
15
13
  /**
16
- * DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
17
- * based on the request path, input, and context.
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}
18
17
  */
19
- declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
20
- private readonly linkResolver;
21
- constructor(linkResolver: (options: ClientOptions<TClientContext>, path: readonly string[], input: unknown) => Promisable<ClientLink<TClientContext>>);
22
- call(path: readonly string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
23
- }
18
+ declare function createORPCClient<T extends NestedClient<any>>(link: ClientLink<InferClientContext<T>>, options?: createORPCClientOptions): T;
24
19
 
25
20
  declare const COMMON_ORPC_ERROR_DEFS: {
26
21
  readonly BAD_REQUEST: {
@@ -118,20 +113,15 @@ declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
118
113
  readonly code: TCode;
119
114
  readonly status: number;
120
115
  readonly data: TData;
121
- constructor(code: TCode, ...[options]: MaybeOptionalOptions<ORPCErrorOptions<TData>>);
116
+ constructor(code: TCode, ...rest: MaybeOptionalOptions<ORPCErrorOptions<TData>>);
122
117
  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
118
  }
126
119
  type ORPCErrorJSON<TCode extends string, TData> = Pick<ORPCError<TCode, TData>, 'defined' | 'code' | 'status' | 'message' | 'data'>;
127
120
  declare function isDefinedError<T>(error: T): error is Extract<T, ORPCError<any, any>>;
128
121
  declare function toORPCError(error: unknown): ORPCError<any, any>;
129
122
  declare function isORPCErrorStatus(status: number): boolean;
130
-
131
- declare function mapEventIterator<TYield, TReturn, TNext, TMap = TYield | TReturn>(iterator: AsyncIterator<TYield, TReturn, TNext>, maps: {
132
- value: (value: NoInfer<TYield | TReturn>, done: boolean | undefined) => Promise<TMap>;
133
- error: (error: unknown) => Promise<unknown>;
134
- }): AsyncGenerator<TMap, TMap, TNext>;
123
+ declare function isORPCErrorJson(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
124
+ declare function createORPCErrorFromJson<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>;
135
125
 
136
126
  type SafeResult<TOutput, TError> = [error: null, data: TOutput, isDefined: false, isSuccess: true] & {
137
127
  error: null;
@@ -149,7 +139,47 @@ type SafeResult<TOutput, TError> = [error: null, data: TOutput, isDefined: false
149
139
  isDefined: true;
150
140
  isSuccess: false;
151
141
  };
142
+ /**
143
+ * Works like try/catch, but can infer error types.
144
+ *
145
+ * @info support both tuple `[error, data, isDefined, isSuccess]` and object `{ error, data, isDefined, isSuccess }` styles.
146
+ * @see {@link https://orpc.unnoq.com/docs/client/error-handling Client Error Handling Docs}
147
+ */
152
148
  declare function safe<TOutput, TError = ThrowableError>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
153
149
  declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
154
150
 
155
- export { COMMON_ORPC_ERROR_DEFS, ClientContext, ClientLink, ClientOptions, ClientPromiseResult, type CommonORPCErrorCode, DynamicLink, FriendlyClientOptions, InferClientContext, NestedClient, ORPCError, type ORPCErrorCode, type ORPCErrorJSON, type ORPCErrorOptions, type SafeResult, createORPCClient, type createORPCClientOptions, fallbackORPCErrorMessage, fallbackORPCErrorStatus, isDefinedError, isORPCErrorStatus, mapEventIterator, resolveFriendlyClientOptions, safe, toORPCError };
151
+ type SafeClient<T extends NestedClient<any>> = T extends Client<infer UContext, infer UInput, infer UOutput, infer UError> ? (...rest: ClientRest<UContext, UInput>) => Promise<SafeResult<UOutput, UError>> : {
152
+ [K in keyof T]: T[K] extends NestedClient<any> ? SafeClient<T[K]> : never;
153
+ };
154
+ /**
155
+ * Create a safe client that automatically wraps all procedure calls with the `safe` util.
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * const safeClient = createSafeClient(client)
160
+ * const { error, data, isDefined } = await safeClient.doSomething({ id: '123' })
161
+ * ```
162
+ *
163
+ * @see {@link https://orpc.unnoq.com/docs/client/error-handling#using-createsafeclient Safe Client Docs}
164
+ */
165
+ declare function createSafeClient<T extends NestedClient<any>>(client: T): SafeClient<T>;
166
+
167
+ /**
168
+ * DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
169
+ * based on the request path, input, and context.
170
+ *
171
+ * @see {@link https://orpc.unnoq.com/docs/client/dynamic-link Dynamic Link Docs}
172
+ */
173
+ declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
174
+ private readonly linkResolver;
175
+ constructor(linkResolver: (options: ClientOptions<TClientContext>, path: readonly string[], input: unknown) => Promisable<ClientLink<TClientContext>>);
176
+ call(path: readonly string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
177
+ }
178
+
179
+ declare function mapEventIterator<TYield, TReturn, TNext, TMap = TYield | TReturn>(iterator: AsyncIterator<TYield, TReturn, TNext>, maps: {
180
+ value: (value: NoInfer<TYield | TReturn>, done: boolean | undefined) => Promise<TMap>;
181
+ error: (error: unknown) => Promise<unknown>;
182
+ }): AsyncIteratorClass<TMap, TMap, TNext>;
183
+
184
+ export { COMMON_ORPC_ERROR_DEFS, Client, ClientContext, ClientLink, ClientOptions, ClientPromiseResult, ClientRest, DynamicLink, FriendlyClientOptions, InferClientContext, NestedClient, ORPCError, createORPCClient, createORPCErrorFromJson, createSafeClient, fallbackORPCErrorMessage, fallbackORPCErrorStatus, isDefinedError, isORPCErrorJson, isORPCErrorStatus, mapEventIterator, resolveFriendlyClientOptions, safe, toORPCError };
185
+ export type { CommonORPCErrorCode, ORPCErrorCode, ORPCErrorJSON, ORPCErrorOptions, SafeClient, SafeResult, createORPCClientOptions };
package/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
- import { i as isDefinedError } from './shared/client.jKEwIsRd.mjs';
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.jKEwIsRd.mjs';
3
- export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
1
+ import { preventNativeAwait, isTypescriptObject } from '@orpc/shared';
2
+ export { AsyncIteratorClass, EventPublisher, asyncIteratorToStream as eventIteratorToStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared';
3
+ import { i as isDefinedError } from './shared/client.txdq_i5V.mjs';
4
+ 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.txdq_i5V.mjs';
4
5
  export { ErrorEvent } from '@orpc/standard-server';
5
6
 
6
7
  async function safe(promise) {
@@ -27,13 +28,13 @@ async function safe(promise) {
27
28
  function resolveFriendlyClientOptions(options) {
28
29
  return {
29
30
  ...options,
30
- context: options?.context ?? {}
31
+ context: options.context ?? {}
31
32
  // Context only optional if all fields are optional
32
33
  };
33
34
  }
34
35
 
35
- function createORPCClient(link, options) {
36
- const path = options?.path ?? [];
36
+ function createORPCClient(link, options = {}) {
37
+ const path = options.path ?? [];
37
38
  const procedureClient = async (...[input, options2 = {}]) => {
38
39
  return await link.call(path, input, resolveFriendlyClientOptions(options2));
39
40
  };
@@ -48,7 +49,23 @@ function createORPCClient(link, options) {
48
49
  });
49
50
  }
50
51
  });
51
- return recursive;
52
+ return preventNativeAwait(recursive);
53
+ }
54
+
55
+ function createSafeClient(client) {
56
+ const proxy = new Proxy((...args) => safe(client(...args)), {
57
+ get(_, prop, receiver) {
58
+ const value = Reflect.get(client, prop, receiver);
59
+ if (typeof prop !== "string") {
60
+ return value;
61
+ }
62
+ if (!isTypescriptObject(value)) {
63
+ return value;
64
+ }
65
+ return createSafeClient(value);
66
+ }
67
+ });
68
+ return proxy;
52
69
  }
53
70
 
54
71
  class DynamicLink {
@@ -62,4 +79,4 @@ class DynamicLink {
62
79
  }
63
80
  }
64
81
 
65
- export { DynamicLink, createORPCClient, isDefinedError, resolveFriendlyClientOptions, safe };
82
+ export { DynamicLink, createORPCClient, createSafeClient, isDefinedError, resolveFriendlyClientOptions, safe };
@@ -1,11 +1,119 @@
1
- import { Value } from '@orpc/shared';
2
- import { S as StandardLinkPlugin, a as StandardLinkOptions } from '../shared/client.5813Ufvs.mjs';
3
- import { b as ClientOptions } from '../shared/client.C0lT7w02.mjs';
4
- import '@orpc/standard-server';
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.Bwgm6dgk.mjs';
5
+ import { b as ClientContext } from '../shared/client.BOYsZIRq.mjs';
5
6
 
6
- interface ClientRetryPluginAttemptOptions {
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,43 +124,34 @@ interface ClientRetryPluginContext {
16
124
  *
17
125
  * @default 0
18
126
  */
19
- retry?: Value<number, [
20
- clientOptions: ClientOptions<ClientRetryPluginContext>,
21
- path: readonly string[],
22
- input: unknown
23
- ]>;
127
+ retry?: Value<Promisable<number>, [StandardLinkInterceptorOptions<ClientRetryPluginContext>]>;
24
128
  /**
25
129
  * Delay (in ms) before retrying.
26
130
  *
27
131
  * @default (o) => o.lastEventRetry ?? 2000
28
132
  */
29
- retryDelay?: Value<number, [
30
- attemptOptions: ClientRetryPluginAttemptOptions,
31
- clientOptions: ClientOptions<ClientRetryPluginContext>,
32
- path: readonly string[],
33
- input: unknown
34
- ]>;
133
+ retryDelay?: Value<Promisable<number>, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
35
134
  /**
36
135
  * Determine should retry or not.
37
136
  *
38
137
  * @default true
39
138
  */
40
- shouldRetry?: Value<boolean, [
41
- attemptOptions: ClientRetryPluginAttemptOptions,
42
- clientOptions: ClientOptions<ClientRetryPluginContext>,
43
- path: readonly string[],
44
- input: unknown
45
- ]>;
139
+ shouldRetry?: Value<Promisable<boolean>, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
46
140
  /**
47
141
  * The hook called when retrying, and return the unsubscribe function.
48
142
  */
49
- onRetry?: (options: ClientRetryPluginAttemptOptions, clientOptions: ClientOptions<ClientRetryPluginContext>, path: readonly string[], input: unknown) => void | (() => void);
143
+ onRetry?: (options: ClientRetryPluginAttemptOptions<ClientRetryPluginContext>) => void | ((isSuccess: boolean) => void);
50
144
  }
51
145
  declare class ClientRetryPluginInvalidEventIteratorRetryResponse extends Error {
52
146
  }
53
147
  interface ClientRetryPluginOptions {
54
148
  default?: ClientRetryPluginContext;
55
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
+ */
56
155
  declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements StandardLinkPlugin<T> {
57
156
  private readonly defaultRetry;
58
157
  private readonly defaultRetryDelay;
@@ -62,4 +161,42 @@ declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements S
62
161
  init(options: StandardLinkOptions<T>): void;
63
162
  }
64
163
 
65
- export { ClientRetryPlugin, type ClientRetryPluginAttemptOptions, type ClientRetryPluginContext, ClientRetryPluginInvalidEventIteratorRetryResponse, type ClientRetryPluginOptions };
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 };