@orpc/client 0.0.0-next.48a5661 → 0.0.0-next.4c9dd72
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/dist/adapters/fetch/index.d.mts +3 -3
- package/dist/adapters/fetch/index.d.ts +3 -3
- package/dist/adapters/fetch/index.mjs +1 -1
- package/dist/adapters/standard/index.d.mts +3 -3
- package/dist/adapters/standard/index.d.ts +3 -3
- package/dist/adapters/standard/index.mjs +1 -1
- package/dist/index.d.mts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.mjs +3 -3
- package/dist/plugins/index.d.mts +71 -20
- package/dist/plugins/index.d.ts +71 -20
- package/dist/plugins/index.mjs +162 -32
- package/dist/shared/{client.grRbC25r.d.ts → client.C7z5zk4v.d.mts} +11 -10
- package/dist/shared/{client.D-jrSuDb.d.ts → client.CDvsX60w.d.ts} +6 -22
- package/dist/shared/{client.Bt94sjrK.d.mts → client.CUq1_W_X.d.mts} +6 -22
- package/dist/shared/{client.C0lT7w02.d.mts → client.CipPQkhk.d.mts} +6 -7
- package/dist/shared/{client.C0lT7w02.d.ts → client.CipPQkhk.d.ts} +6 -7
- package/dist/shared/{client.DhAxdT4W.mjs → client.WoNjJX5a.mjs} +5 -4
- package/dist/shared/{client.5813Ufvs.d.mts → client.p3ON_yzu.d.ts} +11 -10
- package/package.json +4 -4
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
2
2
|
import { ToFetchRequestOptions } from '@orpc/standard-server-fetch';
|
|
3
|
-
import { a as ClientContext, b as ClientOptions } from '../../shared/client.
|
|
4
|
-
import {
|
|
5
|
-
import { f as StandardRPCLinkOptions } from '../../shared/client.
|
|
3
|
+
import { a as ClientContext, b as ClientOptions } from '../../shared/client.CipPQkhk.mjs';
|
|
4
|
+
import { f as StandardLinkClient, d as StandardLink } from '../../shared/client.C7z5zk4v.mjs';
|
|
5
|
+
import { f as StandardRPCLinkOptions } from '../../shared/client.CUq1_W_X.mjs';
|
|
6
6
|
import '@orpc/shared';
|
|
7
7
|
|
|
8
8
|
interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
2
2
|
import { ToFetchRequestOptions } from '@orpc/standard-server-fetch';
|
|
3
|
-
import { a as ClientContext, b as ClientOptions } from '../../shared/client.
|
|
4
|
-
import {
|
|
5
|
-
import { f as StandardRPCLinkOptions } from '../../shared/client.
|
|
3
|
+
import { a as ClientContext, b as ClientOptions } from '../../shared/client.CipPQkhk.js';
|
|
4
|
+
import { f as StandardLinkClient, d as StandardLink } from '../../shared/client.p3ON_yzu.js';
|
|
5
|
+
import { f as StandardRPCLinkOptions } from '../../shared/client.CDvsX60w.js';
|
|
6
6
|
import '@orpc/shared';
|
|
7
7
|
|
|
8
8
|
interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { toFetchRequest, toStandardLazyResponse } from '@orpc/standard-server-fetch';
|
|
2
|
-
import { S as StandardLink, b as StandardRPCJsonSerializer, c as StandardRPCLinkCodec, d as StandardRPCSerializer } from '../../shared/client.
|
|
2
|
+
import { S as StandardLink, b as StandardRPCJsonSerializer, c as StandardRPCLinkCodec, d as StandardRPCSerializer } from '../../shared/client.WoNjJX5a.mjs';
|
|
3
3
|
import '@orpc/shared';
|
|
4
4
|
import '@orpc/standard-server';
|
|
5
5
|
import '../../shared/client.jKEwIsRd.mjs';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { I as InvalidEventIteratorRetryResponse,
|
|
2
|
-
export { S as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, c as StandardRPCCustomJsonSerializer, b as StandardRPCJsonSerialized, a as StandardRPCJsonSerializedMetaItem, e as StandardRPCJsonSerializer, d as StandardRPCJsonSerializerOptions, h as StandardRPCLinkCodec, g as StandardRPCLinkCodecOptions, f as StandardRPCLinkOptions, i as StandardRPCSerializer } from '../../shared/client.
|
|
3
|
-
import { H as HTTPPath } from '../../shared/client.
|
|
1
|
+
export { I as InvalidEventIteratorRetryResponse, d as StandardLink, f as StandardLinkClient, S as StandardLinkClientInterceptorOptions, e as StandardLinkCodec, c as StandardLinkInterceptorOptions, b as StandardLinkOptions, a as StandardLinkPlugin } from '../../shared/client.C7z5zk4v.mjs';
|
|
2
|
+
export { S as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, c as StandardRPCCustomJsonSerializer, b as StandardRPCJsonSerialized, a as StandardRPCJsonSerializedMetaItem, e as StandardRPCJsonSerializer, d as StandardRPCJsonSerializerOptions, h as StandardRPCLinkCodec, g as StandardRPCLinkCodecOptions, f as StandardRPCLinkOptions, i as StandardRPCSerializer } from '../../shared/client.CUq1_W_X.mjs';
|
|
3
|
+
import { H as HTTPPath } from '../../shared/client.CipPQkhk.mjs';
|
|
4
4
|
import '@orpc/shared';
|
|
5
5
|
import '@orpc/standard-server';
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { I as InvalidEventIteratorRetryResponse,
|
|
2
|
-
export { S as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, c as StandardRPCCustomJsonSerializer, b as StandardRPCJsonSerialized, a as StandardRPCJsonSerializedMetaItem, e as StandardRPCJsonSerializer, d as StandardRPCJsonSerializerOptions, h as StandardRPCLinkCodec, g as StandardRPCLinkCodecOptions, f as StandardRPCLinkOptions, i as StandardRPCSerializer } from '../../shared/client.
|
|
3
|
-
import { H as HTTPPath } from '../../shared/client.
|
|
1
|
+
export { I as InvalidEventIteratorRetryResponse, d as StandardLink, f as StandardLinkClient, S as StandardLinkClientInterceptorOptions, e as StandardLinkCodec, c as StandardLinkInterceptorOptions, b as StandardLinkOptions, a as StandardLinkPlugin } from '../../shared/client.p3ON_yzu.js';
|
|
2
|
+
export { S as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, c as StandardRPCCustomJsonSerializer, b as StandardRPCJsonSerialized, a as StandardRPCJsonSerializedMetaItem, e as StandardRPCJsonSerializer, d as StandardRPCJsonSerializerOptions, h as StandardRPCLinkCodec, g as StandardRPCLinkCodecOptions, f as StandardRPCLinkOptions, i as StandardRPCSerializer } from '../../shared/client.CDvsX60w.js';
|
|
3
|
+
import { H as HTTPPath } from '../../shared/client.CipPQkhk.js';
|
|
4
4
|
import '@orpc/shared';
|
|
5
5
|
import '@orpc/standard-server';
|
|
6
6
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { I as InvalidEventIteratorRetryResponse, a as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, S as StandardLink, b as StandardRPCJsonSerializer, c as StandardRPCLinkCodec, d as StandardRPCSerializer, g as getMalformedResponseErrorCode, t as toHttpPath } from '../../shared/client.
|
|
1
|
+
export { I as InvalidEventIteratorRetryResponse, a as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, S as StandardLink, b as StandardRPCJsonSerializer, c as StandardRPCLinkCodec, d as StandardRPCSerializer, g as getMalformedResponseErrorCode, t as toHttpPath } from '../../shared/client.WoNjJX5a.mjs';
|
|
2
2
|
import '@orpc/shared';
|
|
3
3
|
import '@orpc/standard-server';
|
|
4
4
|
import '../../shared/client.jKEwIsRd.mjs';
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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.
|
|
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.CipPQkhk.mjs';
|
|
2
|
+
export { f as Client, e as ClientRest, d as HTTPMethod, H as HTTPPath } from './shared/client.CipPQkhk.mjs';
|
|
3
3
|
import { Promisable, MaybeOptionalOptions, ThrowableError } from '@orpc/shared';
|
|
4
4
|
export { Registry, ThrowableError, onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
|
5
5
|
export { ErrorEvent } from '@orpc/standard-server';
|
|
@@ -133,21 +133,21 @@ declare function mapEventIterator<TYield, TReturn, TNext, TMap = TYield | TRetur
|
|
|
133
133
|
error: (error: unknown) => Promise<unknown>;
|
|
134
134
|
}): AsyncGenerator<TMap, TMap, TNext>;
|
|
135
135
|
|
|
136
|
-
type SafeResult<TOutput, TError> = [error: null, data: TOutput, isDefined: false,
|
|
136
|
+
type SafeResult<TOutput, TError> = [error: null, data: TOutput, isDefined: false, isSuccess: true] & {
|
|
137
137
|
error: null;
|
|
138
138
|
data: TOutput;
|
|
139
139
|
isDefined: false;
|
|
140
|
-
|
|
141
|
-
} | [error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false,
|
|
140
|
+
isSuccess: true;
|
|
141
|
+
} | [error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false, isSuccess: false] & {
|
|
142
142
|
error: Exclude<TError, ORPCError<any, any>>;
|
|
143
143
|
data: undefined;
|
|
144
144
|
isDefined: false;
|
|
145
|
-
|
|
146
|
-
} | [error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true,
|
|
145
|
+
isSuccess: false;
|
|
146
|
+
} | [error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true, isSuccess: false] & {
|
|
147
147
|
error: Extract<TError, ORPCError<any, any>>;
|
|
148
148
|
data: undefined;
|
|
149
149
|
isDefined: true;
|
|
150
|
-
|
|
150
|
+
isSuccess: false;
|
|
151
151
|
};
|
|
152
152
|
declare function safe<TOutput, TError = ThrowableError>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
|
|
153
153
|
declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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.
|
|
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.CipPQkhk.js';
|
|
2
|
+
export { f as Client, e as ClientRest, d as HTTPMethod, H as HTTPPath } from './shared/client.CipPQkhk.js';
|
|
3
3
|
import { Promisable, MaybeOptionalOptions, ThrowableError } from '@orpc/shared';
|
|
4
4
|
export { Registry, ThrowableError, onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
|
5
5
|
export { ErrorEvent } from '@orpc/standard-server';
|
|
@@ -133,21 +133,21 @@ declare function mapEventIterator<TYield, TReturn, TNext, TMap = TYield | TRetur
|
|
|
133
133
|
error: (error: unknown) => Promise<unknown>;
|
|
134
134
|
}): AsyncGenerator<TMap, TMap, TNext>;
|
|
135
135
|
|
|
136
|
-
type SafeResult<TOutput, TError> = [error: null, data: TOutput, isDefined: false,
|
|
136
|
+
type SafeResult<TOutput, TError> = [error: null, data: TOutput, isDefined: false, isSuccess: true] & {
|
|
137
137
|
error: null;
|
|
138
138
|
data: TOutput;
|
|
139
139
|
isDefined: false;
|
|
140
|
-
|
|
141
|
-
} | [error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false,
|
|
140
|
+
isSuccess: true;
|
|
141
|
+
} | [error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false, isSuccess: false] & {
|
|
142
142
|
error: Exclude<TError, ORPCError<any, any>>;
|
|
143
143
|
data: undefined;
|
|
144
144
|
isDefined: false;
|
|
145
|
-
|
|
146
|
-
} | [error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true,
|
|
145
|
+
isSuccess: false;
|
|
146
|
+
} | [error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true, isSuccess: false] & {
|
|
147
147
|
error: Extract<TError, ORPCError<any, any>>;
|
|
148
148
|
data: undefined;
|
|
149
149
|
isDefined: true;
|
|
150
|
-
|
|
150
|
+
isSuccess: false;
|
|
151
151
|
};
|
|
152
152
|
declare function safe<TOutput, TError = ThrowableError>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
|
|
153
153
|
declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
|
package/dist/index.mjs
CHANGED
|
@@ -8,19 +8,19 @@ async function safe(promise) {
|
|
|
8
8
|
const output = await promise;
|
|
9
9
|
return Object.assign(
|
|
10
10
|
[null, output, false, true],
|
|
11
|
-
{ error: null, data: output, isDefined: false,
|
|
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
17
|
[error, void 0, true, false],
|
|
18
|
-
{ error, data: void 0, isDefined: true,
|
|
18
|
+
{ error, data: void 0, isDefined: true, isSuccess: false }
|
|
19
19
|
);
|
|
20
20
|
}
|
|
21
21
|
return Object.assign(
|
|
22
22
|
[error, void 0, false, false],
|
|
23
|
-
{ error, data: void 0, isDefined: false,
|
|
23
|
+
{ error, data: void 0, isDefined: false, isSuccess: false }
|
|
24
24
|
);
|
|
25
25
|
}
|
|
26
26
|
}
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,11 +1,72 @@
|
|
|
1
1
|
import { Value } from '@orpc/shared';
|
|
2
|
-
import {
|
|
3
|
-
import { b as
|
|
4
|
-
import '
|
|
2
|
+
import { StandardHeaders, StandardRequest } from '@orpc/standard-server';
|
|
3
|
+
import { S as StandardLinkClientInterceptorOptions, a as StandardLinkPlugin, b as StandardLinkOptions, c as StandardLinkInterceptorOptions } from '../shared/client.C7z5zk4v.mjs';
|
|
4
|
+
import { a as ClientContext } from '../shared/client.CipPQkhk.mjs';
|
|
5
5
|
|
|
6
|
-
interface
|
|
6
|
+
interface BatchLinkPluginGroup<T extends ClientContext> {
|
|
7
|
+
condition(options: StandardLinkClientInterceptorOptions<T>): boolean;
|
|
8
|
+
context: T;
|
|
9
|
+
path?: readonly string[];
|
|
10
|
+
input?: unknown;
|
|
11
|
+
}
|
|
12
|
+
interface BatchLinkPluginOptions<T extends ClientContext> {
|
|
13
|
+
groups: readonly [BatchLinkPluginGroup<T>, ...BatchLinkPluginGroup<T>[]];
|
|
14
|
+
/**
|
|
15
|
+
* The maximum number of requests in the batch.
|
|
16
|
+
*
|
|
17
|
+
* @default 10
|
|
18
|
+
*/
|
|
19
|
+
maxSize?: Value<number, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
20
|
+
/**
|
|
21
|
+
* Defines the URL to use for the batch request.
|
|
22
|
+
*
|
|
23
|
+
* @default the URL of the first request in the batch + '/__batch__'
|
|
24
|
+
*/
|
|
25
|
+
url?: Value<string | URL, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
26
|
+
/**
|
|
27
|
+
* The maximum length of the URL.
|
|
28
|
+
*
|
|
29
|
+
* @default 2083
|
|
30
|
+
*/
|
|
31
|
+
maxUrlLength?: Value<number, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
32
|
+
/**
|
|
33
|
+
* Defines the HTTP headers to use for the batch request.
|
|
34
|
+
*
|
|
35
|
+
* @default The same headers of all requests in the batch
|
|
36
|
+
*/
|
|
37
|
+
headers?: Value<StandardHeaders, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
38
|
+
/**
|
|
39
|
+
* Map the batch request items before sending them.
|
|
40
|
+
*
|
|
41
|
+
* @default Removes headers that are duplicated in the batch headers.
|
|
42
|
+
*/
|
|
43
|
+
mapRequestItem?: (options: StandardLinkClientInterceptorOptions<T> & {
|
|
44
|
+
batchUrl: URL;
|
|
45
|
+
batchHeaders: StandardHeaders;
|
|
46
|
+
}) => StandardRequest;
|
|
47
|
+
/**
|
|
48
|
+
* Exclude a request from the batch.
|
|
49
|
+
*
|
|
50
|
+
* @default () => false
|
|
51
|
+
*/
|
|
52
|
+
exclude?: (options: StandardLinkClientInterceptorOptions<T>) => boolean;
|
|
53
|
+
}
|
|
54
|
+
declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
55
|
+
#private;
|
|
56
|
+
private readonly groups;
|
|
57
|
+
private readonly maxSize;
|
|
58
|
+
private readonly batchUrl;
|
|
59
|
+
private readonly maxUrlLength;
|
|
60
|
+
private readonly batchHeaders;
|
|
61
|
+
private readonly mapRequestItem;
|
|
62
|
+
private readonly exclude;
|
|
63
|
+
private pending;
|
|
64
|
+
constructor(options: BatchLinkPluginOptions<T>);
|
|
65
|
+
init(options: StandardLinkOptions<T>): void;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface ClientRetryPluginAttemptOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> {
|
|
7
69
|
lastEventRetry: number | undefined;
|
|
8
|
-
lastEventId: string | undefined;
|
|
9
70
|
attemptIndex: number;
|
|
10
71
|
error: unknown;
|
|
11
72
|
}
|
|
@@ -16,33 +77,23 @@ interface ClientRetryPluginContext {
|
|
|
16
77
|
*
|
|
17
78
|
* @default 0
|
|
18
79
|
*/
|
|
19
|
-
retry?: number
|
|
80
|
+
retry?: Value<number, [StandardLinkInterceptorOptions<ClientRetryPluginContext>]>;
|
|
20
81
|
/**
|
|
21
82
|
* Delay (in ms) before retrying.
|
|
22
83
|
*
|
|
23
84
|
* @default (o) => o.lastEventRetry ?? 2000
|
|
24
85
|
*/
|
|
25
|
-
retryDelay?: Value<number, [
|
|
26
|
-
attemptOptions: ClientRetryPluginAttemptOptions,
|
|
27
|
-
clientOptions: ClientOptions<ClientRetryPluginContext>,
|
|
28
|
-
path: readonly string[],
|
|
29
|
-
input: unknown
|
|
30
|
-
]>;
|
|
86
|
+
retryDelay?: Value<number, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
|
|
31
87
|
/**
|
|
32
88
|
* Determine should retry or not.
|
|
33
89
|
*
|
|
34
90
|
* @default true
|
|
35
91
|
*/
|
|
36
|
-
shouldRetry?: Value<boolean, [
|
|
37
|
-
attemptOptions: ClientRetryPluginAttemptOptions,
|
|
38
|
-
clientOptions: ClientOptions<ClientRetryPluginContext>,
|
|
39
|
-
path: readonly string[],
|
|
40
|
-
input: unknown
|
|
41
|
-
]>;
|
|
92
|
+
shouldRetry?: Value<boolean, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
|
|
42
93
|
/**
|
|
43
94
|
* The hook called when retrying, and return the unsubscribe function.
|
|
44
95
|
*/
|
|
45
|
-
onRetry?: (options: ClientRetryPluginAttemptOptions
|
|
96
|
+
onRetry?: (options: ClientRetryPluginAttemptOptions<ClientRetryPluginContext>) => void | (() => void);
|
|
46
97
|
}
|
|
47
98
|
declare class ClientRetryPluginInvalidEventIteratorRetryResponse extends Error {
|
|
48
99
|
}
|
|
@@ -58,4 +109,4 @@ declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements S
|
|
|
58
109
|
init(options: StandardLinkOptions<T>): void;
|
|
59
110
|
}
|
|
60
111
|
|
|
61
|
-
export { ClientRetryPlugin, type ClientRetryPluginAttemptOptions, type ClientRetryPluginContext, ClientRetryPluginInvalidEventIteratorRetryResponse, type ClientRetryPluginOptions };
|
|
112
|
+
export { BatchLinkPlugin, type BatchLinkPluginGroup, type BatchLinkPluginOptions, ClientRetryPlugin, type ClientRetryPluginAttemptOptions, type ClientRetryPluginContext, ClientRetryPluginInvalidEventIteratorRetryResponse, type ClientRetryPluginOptions };
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,11 +1,72 @@
|
|
|
1
1
|
import { Value } from '@orpc/shared';
|
|
2
|
-
import {
|
|
3
|
-
import { b as
|
|
4
|
-
import '
|
|
2
|
+
import { StandardHeaders, StandardRequest } from '@orpc/standard-server';
|
|
3
|
+
import { S as StandardLinkClientInterceptorOptions, a as StandardLinkPlugin, b as StandardLinkOptions, c as StandardLinkInterceptorOptions } from '../shared/client.p3ON_yzu.js';
|
|
4
|
+
import { a as ClientContext } from '../shared/client.CipPQkhk.js';
|
|
5
5
|
|
|
6
|
-
interface
|
|
6
|
+
interface BatchLinkPluginGroup<T extends ClientContext> {
|
|
7
|
+
condition(options: StandardLinkClientInterceptorOptions<T>): boolean;
|
|
8
|
+
context: T;
|
|
9
|
+
path?: readonly string[];
|
|
10
|
+
input?: unknown;
|
|
11
|
+
}
|
|
12
|
+
interface BatchLinkPluginOptions<T extends ClientContext> {
|
|
13
|
+
groups: readonly [BatchLinkPluginGroup<T>, ...BatchLinkPluginGroup<T>[]];
|
|
14
|
+
/**
|
|
15
|
+
* The maximum number of requests in the batch.
|
|
16
|
+
*
|
|
17
|
+
* @default 10
|
|
18
|
+
*/
|
|
19
|
+
maxSize?: Value<number, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
20
|
+
/**
|
|
21
|
+
* Defines the URL to use for the batch request.
|
|
22
|
+
*
|
|
23
|
+
* @default the URL of the first request in the batch + '/__batch__'
|
|
24
|
+
*/
|
|
25
|
+
url?: Value<string | URL, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
26
|
+
/**
|
|
27
|
+
* The maximum length of the URL.
|
|
28
|
+
*
|
|
29
|
+
* @default 2083
|
|
30
|
+
*/
|
|
31
|
+
maxUrlLength?: Value<number, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
32
|
+
/**
|
|
33
|
+
* Defines the HTTP headers to use for the batch request.
|
|
34
|
+
*
|
|
35
|
+
* @default The same headers of all requests in the batch
|
|
36
|
+
*/
|
|
37
|
+
headers?: Value<StandardHeaders, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
38
|
+
/**
|
|
39
|
+
* Map the batch request items before sending them.
|
|
40
|
+
*
|
|
41
|
+
* @default Removes headers that are duplicated in the batch headers.
|
|
42
|
+
*/
|
|
43
|
+
mapRequestItem?: (options: StandardLinkClientInterceptorOptions<T> & {
|
|
44
|
+
batchUrl: URL;
|
|
45
|
+
batchHeaders: StandardHeaders;
|
|
46
|
+
}) => StandardRequest;
|
|
47
|
+
/**
|
|
48
|
+
* Exclude a request from the batch.
|
|
49
|
+
*
|
|
50
|
+
* @default () => false
|
|
51
|
+
*/
|
|
52
|
+
exclude?: (options: StandardLinkClientInterceptorOptions<T>) => boolean;
|
|
53
|
+
}
|
|
54
|
+
declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
55
|
+
#private;
|
|
56
|
+
private readonly groups;
|
|
57
|
+
private readonly maxSize;
|
|
58
|
+
private readonly batchUrl;
|
|
59
|
+
private readonly maxUrlLength;
|
|
60
|
+
private readonly batchHeaders;
|
|
61
|
+
private readonly mapRequestItem;
|
|
62
|
+
private readonly exclude;
|
|
63
|
+
private pending;
|
|
64
|
+
constructor(options: BatchLinkPluginOptions<T>);
|
|
65
|
+
init(options: StandardLinkOptions<T>): void;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface ClientRetryPluginAttemptOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> {
|
|
7
69
|
lastEventRetry: number | undefined;
|
|
8
|
-
lastEventId: string | undefined;
|
|
9
70
|
attemptIndex: number;
|
|
10
71
|
error: unknown;
|
|
11
72
|
}
|
|
@@ -16,33 +77,23 @@ interface ClientRetryPluginContext {
|
|
|
16
77
|
*
|
|
17
78
|
* @default 0
|
|
18
79
|
*/
|
|
19
|
-
retry?: number
|
|
80
|
+
retry?: Value<number, [StandardLinkInterceptorOptions<ClientRetryPluginContext>]>;
|
|
20
81
|
/**
|
|
21
82
|
* Delay (in ms) before retrying.
|
|
22
83
|
*
|
|
23
84
|
* @default (o) => o.lastEventRetry ?? 2000
|
|
24
85
|
*/
|
|
25
|
-
retryDelay?: Value<number, [
|
|
26
|
-
attemptOptions: ClientRetryPluginAttemptOptions,
|
|
27
|
-
clientOptions: ClientOptions<ClientRetryPluginContext>,
|
|
28
|
-
path: readonly string[],
|
|
29
|
-
input: unknown
|
|
30
|
-
]>;
|
|
86
|
+
retryDelay?: Value<number, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
|
|
31
87
|
/**
|
|
32
88
|
* Determine should retry or not.
|
|
33
89
|
*
|
|
34
90
|
* @default true
|
|
35
91
|
*/
|
|
36
|
-
shouldRetry?: Value<boolean, [
|
|
37
|
-
attemptOptions: ClientRetryPluginAttemptOptions,
|
|
38
|
-
clientOptions: ClientOptions<ClientRetryPluginContext>,
|
|
39
|
-
path: readonly string[],
|
|
40
|
-
input: unknown
|
|
41
|
-
]>;
|
|
92
|
+
shouldRetry?: Value<boolean, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
|
|
42
93
|
/**
|
|
43
94
|
* The hook called when retrying, and return the unsubscribe function.
|
|
44
95
|
*/
|
|
45
|
-
onRetry?: (options: ClientRetryPluginAttemptOptions
|
|
96
|
+
onRetry?: (options: ClientRetryPluginAttemptOptions<ClientRetryPluginContext>) => void | (() => void);
|
|
46
97
|
}
|
|
47
98
|
declare class ClientRetryPluginInvalidEventIteratorRetryResponse extends Error {
|
|
48
99
|
}
|
|
@@ -58,4 +109,4 @@ declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements S
|
|
|
58
109
|
init(options: StandardLinkOptions<T>): void;
|
|
59
110
|
}
|
|
60
111
|
|
|
61
|
-
export { ClientRetryPlugin, type ClientRetryPluginAttemptOptions, type ClientRetryPluginContext, ClientRetryPluginInvalidEventIteratorRetryResponse, type ClientRetryPluginOptions };
|
|
112
|
+
export { BatchLinkPlugin, type BatchLinkPluginGroup, type BatchLinkPluginOptions, ClientRetryPlugin, type ClientRetryPluginAttemptOptions, type ClientRetryPluginContext, ClientRetryPluginInvalidEventIteratorRetryResponse, type ClientRetryPluginOptions };
|
package/dist/plugins/index.mjs
CHANGED
|
@@ -1,6 +1,151 @@
|
|
|
1
|
-
import { isAsyncIteratorObject, value } from '@orpc/shared';
|
|
1
|
+
import { isAsyncIteratorObject, value, splitInHalf, toArray } from '@orpc/shared';
|
|
2
|
+
import { toBatchRequest, parseBatchResponse } from '@orpc/standard-server/batch';
|
|
2
3
|
import { getEventMeta } from '@orpc/standard-server';
|
|
3
4
|
|
|
5
|
+
class BatchLinkPlugin {
|
|
6
|
+
groups;
|
|
7
|
+
maxSize;
|
|
8
|
+
batchUrl;
|
|
9
|
+
maxUrlLength;
|
|
10
|
+
batchHeaders;
|
|
11
|
+
mapRequestItem;
|
|
12
|
+
exclude;
|
|
13
|
+
pending;
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.groups = options.groups;
|
|
16
|
+
this.pending = /* @__PURE__ */ new Map();
|
|
17
|
+
this.maxSize = options.maxSize ?? 10;
|
|
18
|
+
this.maxUrlLength = options.maxUrlLength ?? 2083;
|
|
19
|
+
this.batchUrl = options.url ?? (([options2]) => `${options2.request.url.origin}${options2.request.url.pathname}/__batch__`);
|
|
20
|
+
this.batchHeaders = options.headers ?? (([options2, ...rest]) => {
|
|
21
|
+
const headers = {};
|
|
22
|
+
for (const [key, value2] of Object.entries(options2.request.headers)) {
|
|
23
|
+
if (rest.every((item) => item.request.headers[key] === value2)) {
|
|
24
|
+
headers[key] = value2;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return headers;
|
|
28
|
+
});
|
|
29
|
+
this.mapRequestItem = options.mapRequestItem ?? (({ request, batchHeaders }) => {
|
|
30
|
+
const headers = {};
|
|
31
|
+
for (const [key, value2] of Object.entries(request.headers)) {
|
|
32
|
+
if (batchHeaders[key] !== value2) {
|
|
33
|
+
headers[key] = value2;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
method: request.method,
|
|
38
|
+
url: request.url,
|
|
39
|
+
headers,
|
|
40
|
+
body: request.body,
|
|
41
|
+
signal: request.signal
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
this.exclude = options.exclude ?? (() => false);
|
|
45
|
+
}
|
|
46
|
+
init(options) {
|
|
47
|
+
options.clientInterceptors ??= [];
|
|
48
|
+
options.clientInterceptors.push((options2) => {
|
|
49
|
+
if (options2.request.headers["x-orpc-batch"] !== "1") {
|
|
50
|
+
return options2.next();
|
|
51
|
+
}
|
|
52
|
+
return options2.next({
|
|
53
|
+
...options2,
|
|
54
|
+
request: {
|
|
55
|
+
...options2.request,
|
|
56
|
+
headers: {
|
|
57
|
+
...options2.request.headers,
|
|
58
|
+
"x-orpc-batch": void 0
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
options.clientInterceptors.push((options2) => {
|
|
64
|
+
if (this.exclude(options2) || options2.request.body instanceof Blob || options2.request.body instanceof FormData || isAsyncIteratorObject(options2.request.body)) {
|
|
65
|
+
return options2.next();
|
|
66
|
+
}
|
|
67
|
+
const group = this.groups.find((group2) => group2.condition(options2));
|
|
68
|
+
if (!group) {
|
|
69
|
+
return options2.next();
|
|
70
|
+
}
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
this.#enqueueRequest(group, options2, resolve, reject);
|
|
73
|
+
setTimeout(() => this.#processPendingBatches());
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
#enqueueRequest(group, options, resolve, reject) {
|
|
78
|
+
const items = this.pending.get(group);
|
|
79
|
+
if (items) {
|
|
80
|
+
items.push([options, resolve, reject]);
|
|
81
|
+
} else {
|
|
82
|
+
this.pending.set(group, [[options, resolve, reject]]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async #processPendingBatches() {
|
|
86
|
+
const pending = this.pending;
|
|
87
|
+
this.pending = /* @__PURE__ */ new Map();
|
|
88
|
+
for (const [group, items] of pending) {
|
|
89
|
+
const getItems = items.filter(([options]) => options.request.method === "GET");
|
|
90
|
+
const restItems = items.filter(([options]) => options.request.method !== "GET");
|
|
91
|
+
this.#executeBatch("GET", group, getItems);
|
|
92
|
+
this.#executeBatch("POST", group, restItems);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async #executeBatch(method, group, groupItems) {
|
|
96
|
+
if (!groupItems.length) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const batchItems = groupItems;
|
|
100
|
+
if (batchItems.length === 1) {
|
|
101
|
+
batchItems[0][0].next().then(batchItems[0][1]).catch(batchItems[0][2]);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
const options = batchItems.map(([options2]) => options2);
|
|
106
|
+
const maxSize = await value(this.maxSize, options);
|
|
107
|
+
if (batchItems.length > maxSize) {
|
|
108
|
+
const [first, second] = splitInHalf(batchItems);
|
|
109
|
+
this.#executeBatch(method, group, first);
|
|
110
|
+
this.#executeBatch(method, group, second);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const batchUrl = new URL(await value(this.batchUrl, options));
|
|
114
|
+
const batchHeaders = await value(this.batchHeaders, options);
|
|
115
|
+
const mappedItems = batchItems.map(([options2]) => this.mapRequestItem({ ...options2, batchUrl, batchHeaders }));
|
|
116
|
+
const batchRequest = toBatchRequest({
|
|
117
|
+
method,
|
|
118
|
+
url: batchUrl,
|
|
119
|
+
headers: batchHeaders,
|
|
120
|
+
requests: mappedItems
|
|
121
|
+
});
|
|
122
|
+
const maxUrlLength = await value(this.maxUrlLength, options);
|
|
123
|
+
if (batchRequest.url.toString().length > maxUrlLength) {
|
|
124
|
+
const [first, second] = splitInHalf(batchItems);
|
|
125
|
+
this.#executeBatch(method, group, first);
|
|
126
|
+
this.#executeBatch(method, group, second);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const lazyResponse = await options[0].next({
|
|
130
|
+
request: { ...batchRequest, headers: { ...batchRequest.headers, "x-orpc-batch": "1" } },
|
|
131
|
+
signal: batchRequest.signal,
|
|
132
|
+
context: group.context,
|
|
133
|
+
input: group.input,
|
|
134
|
+
path: toArray(group.path)
|
|
135
|
+
});
|
|
136
|
+
const parsed = parseBatchResponse({ ...lazyResponse, body: await lazyResponse.body() });
|
|
137
|
+
for await (const item of parsed) {
|
|
138
|
+
batchItems[item.index]?.[1]({ ...item, body: () => Promise.resolve(item.body) });
|
|
139
|
+
}
|
|
140
|
+
throw new Error("Something went wrong make batch response not contains enough responses. This can be a bug please report it.");
|
|
141
|
+
} catch (error) {
|
|
142
|
+
for (const [, , reject] of batchItems) {
|
|
143
|
+
reject(error);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
4
149
|
class ClientRetryPluginInvalidEventIteratorRetryResponse extends Error {
|
|
5
150
|
}
|
|
6
151
|
class ClientRetryPlugin {
|
|
@@ -17,65 +162,50 @@ class ClientRetryPlugin {
|
|
|
17
162
|
init(options) {
|
|
18
163
|
options.interceptors ??= [];
|
|
19
164
|
options.interceptors.push(async (interceptorOptions) => {
|
|
20
|
-
const maxAttempts =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
165
|
+
const maxAttempts = await value(
|
|
166
|
+
interceptorOptions.context.retry ?? this.defaultRetry,
|
|
167
|
+
interceptorOptions
|
|
168
|
+
);
|
|
169
|
+
const retryDelay = interceptorOptions.context.retryDelay ?? this.defaultRetryDelay;
|
|
170
|
+
const shouldRetry = interceptorOptions.context.shouldRetry ?? this.defaultShouldRetry;
|
|
171
|
+
const onRetry = interceptorOptions.context.onRetry ?? this.defaultOnRetry;
|
|
24
172
|
if (maxAttempts <= 0) {
|
|
25
173
|
return interceptorOptions.next();
|
|
26
174
|
}
|
|
27
|
-
let lastEventId = interceptorOptions.
|
|
175
|
+
let lastEventId = interceptorOptions.lastEventId;
|
|
28
176
|
let lastEventRetry;
|
|
29
177
|
let unsubscribe;
|
|
30
178
|
let attemptIndex = 0;
|
|
31
179
|
const next = async (initial) => {
|
|
32
180
|
let current = initial;
|
|
33
181
|
while (true) {
|
|
34
|
-
const
|
|
182
|
+
const updatedInterceptorOptions = { ...interceptorOptions, lastEventId };
|
|
35
183
|
if (current) {
|
|
36
184
|
if (attemptIndex >= maxAttempts) {
|
|
37
185
|
throw current.error;
|
|
38
186
|
}
|
|
39
187
|
const attemptOptions = {
|
|
188
|
+
...updatedInterceptorOptions,
|
|
40
189
|
attemptIndex,
|
|
41
190
|
error: current.error,
|
|
42
|
-
lastEventId,
|
|
43
191
|
lastEventRetry
|
|
44
192
|
};
|
|
45
193
|
const shouldRetryBool = await value(
|
|
46
194
|
shouldRetry,
|
|
47
|
-
attemptOptions
|
|
48
|
-
newClientOptions,
|
|
49
|
-
interceptorOptions.path,
|
|
50
|
-
interceptorOptions.input
|
|
195
|
+
attemptOptions
|
|
51
196
|
);
|
|
52
197
|
if (!shouldRetryBool) {
|
|
53
198
|
throw current.error;
|
|
54
199
|
}
|
|
55
|
-
unsubscribe = onRetry?.(
|
|
56
|
-
|
|
57
|
-
newClientOptions,
|
|
58
|
-
interceptorOptions.path,
|
|
59
|
-
interceptorOptions.input
|
|
60
|
-
);
|
|
61
|
-
const retryDelayMs = await value(
|
|
62
|
-
retryDelay,
|
|
63
|
-
attemptOptions,
|
|
64
|
-
newClientOptions,
|
|
65
|
-
interceptorOptions.path,
|
|
66
|
-
interceptorOptions.input
|
|
67
|
-
);
|
|
200
|
+
unsubscribe = onRetry?.(attemptOptions);
|
|
201
|
+
const retryDelayMs = await value(retryDelay, attemptOptions);
|
|
68
202
|
await new Promise((resolve) => setTimeout(resolve, retryDelayMs));
|
|
69
203
|
attemptIndex++;
|
|
70
204
|
}
|
|
71
205
|
try {
|
|
72
|
-
|
|
73
|
-
...interceptorOptions,
|
|
74
|
-
options: newClientOptions
|
|
75
|
-
});
|
|
76
|
-
return output2;
|
|
206
|
+
return await interceptorOptions.next(updatedInterceptorOptions);
|
|
77
207
|
} catch (error) {
|
|
78
|
-
if (
|
|
208
|
+
if (updatedInterceptorOptions.signal?.aborted === true) {
|
|
79
209
|
throw error;
|
|
80
210
|
}
|
|
81
211
|
current = { error };
|
|
@@ -123,4 +253,4 @@ class ClientRetryPlugin {
|
|
|
123
253
|
}
|
|
124
254
|
}
|
|
125
255
|
|
|
126
|
-
export { ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse };
|
|
256
|
+
export { BatchLinkPlugin, ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Interceptor, ThrowableError } from '@orpc/shared';
|
|
2
2
|
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
3
|
-
import { a as ClientContext, b as ClientOptions, C as ClientLink } from './client.
|
|
3
|
+
import { a as ClientContext, b as ClientOptions, C as ClientLink } from './client.CipPQkhk.mjs';
|
|
4
4
|
|
|
5
5
|
interface StandardLinkCodec<T extends ClientContext> {
|
|
6
6
|
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
|
|
@@ -15,15 +15,16 @@ declare class InvalidEventIteratorRetryResponse extends Error {
|
|
|
15
15
|
interface StandardLinkPlugin<T extends ClientContext> {
|
|
16
16
|
init?(options: StandardLinkOptions<T>): void;
|
|
17
17
|
}
|
|
18
|
+
interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
|
|
19
|
+
path: readonly string[];
|
|
20
|
+
input: unknown;
|
|
21
|
+
}
|
|
22
|
+
interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> {
|
|
23
|
+
request: StandardRequest;
|
|
24
|
+
}
|
|
18
25
|
interface StandardLinkOptions<T extends ClientContext> {
|
|
19
|
-
interceptors?: Interceptor<
|
|
20
|
-
|
|
21
|
-
input: unknown;
|
|
22
|
-
options: ClientOptions<T>;
|
|
23
|
-
}, unknown, ThrowableError>[];
|
|
24
|
-
clientInterceptors?: Interceptor<{
|
|
25
|
-
request: StandardRequest;
|
|
26
|
-
}, StandardLazyResponse, ThrowableError>[];
|
|
26
|
+
interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, unknown, ThrowableError>[];
|
|
27
|
+
clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, StandardLazyResponse, ThrowableError>[];
|
|
27
28
|
plugins?: StandardLinkPlugin<T>[];
|
|
28
29
|
}
|
|
29
30
|
declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
@@ -36,4 +37,4 @@ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
|
36
37
|
call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
export { InvalidEventIteratorRetryResponse as I, type
|
|
40
|
+
export { InvalidEventIteratorRetryResponse as I, type StandardLinkClientInterceptorOptions as S, type StandardLinkPlugin as a, type StandardLinkOptions as b, type StandardLinkInterceptorOptions as c, StandardLink as d, type StandardLinkCodec as e, type StandardLinkClient as f };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as ClientContext, b as ClientOptions, d as HTTPMethod } from './client.
|
|
2
|
-
import {
|
|
1
|
+
import { a as ClientContext, b as ClientOptions, d as HTTPMethod } from './client.CipPQkhk.js';
|
|
2
|
+
import { e as StandardLinkCodec, b as StandardLinkOptions } from './client.p3ON_yzu.js';
|
|
3
3
|
import { Segment, Value } from '@orpc/shared';
|
|
4
4
|
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
5
5
|
|
|
@@ -44,31 +44,19 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
|
44
44
|
/**
|
|
45
45
|
* Base url for all requests.
|
|
46
46
|
*/
|
|
47
|
-
url: Value<string | URL, [
|
|
48
|
-
options: ClientOptions<T>,
|
|
49
|
-
path: readonly string[],
|
|
50
|
-
input: unknown
|
|
51
|
-
]>;
|
|
47
|
+
url: Value<string | URL, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
52
48
|
/**
|
|
53
49
|
* The maximum length of the URL.
|
|
54
50
|
*
|
|
55
51
|
* @default 2083
|
|
56
52
|
*/
|
|
57
|
-
maxUrlLength?: Value<number, [
|
|
58
|
-
options: ClientOptions<T>,
|
|
59
|
-
path: readonly string[],
|
|
60
|
-
input: unknown
|
|
61
|
-
]>;
|
|
53
|
+
maxUrlLength?: Value<number, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
62
54
|
/**
|
|
63
55
|
* The method used to make the request.
|
|
64
56
|
*
|
|
65
57
|
* @default 'POST'
|
|
66
58
|
*/
|
|
67
|
-
method?: Value<HTTPMethod, [
|
|
68
|
-
options: ClientOptions<T>,
|
|
69
|
-
path: readonly string[],
|
|
70
|
-
input: unknown
|
|
71
|
-
]>;
|
|
59
|
+
method?: Value<HTTPMethod, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
72
60
|
/**
|
|
73
61
|
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
|
74
62
|
* GET is not allowed, it's very dangerous.
|
|
@@ -79,11 +67,7 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
|
79
67
|
/**
|
|
80
68
|
* Inject headers to the request.
|
|
81
69
|
*/
|
|
82
|
-
headers?: Value<StandardHeaders, [
|
|
83
|
-
options: ClientOptions<T>,
|
|
84
|
-
path: readonly string[],
|
|
85
|
-
input: unknown
|
|
86
|
-
]>;
|
|
70
|
+
headers?: Value<StandardHeaders, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
87
71
|
}
|
|
88
72
|
declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
89
73
|
private readonly serializer;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as ClientContext, b as ClientOptions, d as HTTPMethod } from './client.
|
|
2
|
-
import {
|
|
1
|
+
import { a as ClientContext, b as ClientOptions, d as HTTPMethod } from './client.CipPQkhk.mjs';
|
|
2
|
+
import { e as StandardLinkCodec, b as StandardLinkOptions } from './client.C7z5zk4v.mjs';
|
|
3
3
|
import { Segment, Value } from '@orpc/shared';
|
|
4
4
|
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
5
5
|
|
|
@@ -44,31 +44,19 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
|
44
44
|
/**
|
|
45
45
|
* Base url for all requests.
|
|
46
46
|
*/
|
|
47
|
-
url: Value<string | URL, [
|
|
48
|
-
options: ClientOptions<T>,
|
|
49
|
-
path: readonly string[],
|
|
50
|
-
input: unknown
|
|
51
|
-
]>;
|
|
47
|
+
url: Value<string | URL, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
52
48
|
/**
|
|
53
49
|
* The maximum length of the URL.
|
|
54
50
|
*
|
|
55
51
|
* @default 2083
|
|
56
52
|
*/
|
|
57
|
-
maxUrlLength?: Value<number, [
|
|
58
|
-
options: ClientOptions<T>,
|
|
59
|
-
path: readonly string[],
|
|
60
|
-
input: unknown
|
|
61
|
-
]>;
|
|
53
|
+
maxUrlLength?: Value<number, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
62
54
|
/**
|
|
63
55
|
* The method used to make the request.
|
|
64
56
|
*
|
|
65
57
|
* @default 'POST'
|
|
66
58
|
*/
|
|
67
|
-
method?: Value<HTTPMethod, [
|
|
68
|
-
options: ClientOptions<T>,
|
|
69
|
-
path: readonly string[],
|
|
70
|
-
input: unknown
|
|
71
|
-
]>;
|
|
59
|
+
method?: Value<HTTPMethod, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
72
60
|
/**
|
|
73
61
|
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
|
74
62
|
* GET is not allowed, it's very dangerous.
|
|
@@ -79,11 +67,7 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
|
79
67
|
/**
|
|
80
68
|
* Inject headers to the request.
|
|
81
69
|
*/
|
|
82
|
-
headers?: Value<StandardHeaders, [
|
|
83
|
-
options: ClientOptions<T>,
|
|
84
|
-
path: readonly string[],
|
|
85
|
-
input: unknown
|
|
86
|
-
]>;
|
|
70
|
+
headers?: Value<StandardHeaders, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
87
71
|
}
|
|
88
72
|
declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
89
73
|
private readonly serializer;
|
|
@@ -3,13 +3,15 @@ import { PromiseWithError } from '@orpc/shared';
|
|
|
3
3
|
type HTTPPath = `/${string}`;
|
|
4
4
|
type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
5
5
|
type ClientContext = Record<PropertyKey, any>;
|
|
6
|
-
|
|
6
|
+
interface ClientOptions<T extends ClientContext> {
|
|
7
7
|
signal?: AbortSignal;
|
|
8
8
|
lastEventId?: string | undefined;
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
context: T;
|
|
10
|
+
}
|
|
11
|
+
type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
12
|
+
context?: T;
|
|
11
13
|
} : {
|
|
12
|
-
context:
|
|
14
|
+
context: T;
|
|
13
15
|
});
|
|
14
16
|
type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
|
|
15
17
|
type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
|
|
@@ -20,9 +22,6 @@ type NestedClient<TClientContext extends ClientContext> = Client<TClientContext,
|
|
|
20
22
|
[k: string]: NestedClient<TClientContext>;
|
|
21
23
|
};
|
|
22
24
|
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
|
23
|
-
type ClientOptions<TClientContext extends ClientContext> = FriendlyClientOptions<TClientContext> & {
|
|
24
|
-
context: TClientContext;
|
|
25
|
-
};
|
|
26
25
|
interface ClientLink<TClientContext extends ClientContext> {
|
|
27
26
|
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
|
28
27
|
}
|
|
@@ -3,13 +3,15 @@ import { PromiseWithError } from '@orpc/shared';
|
|
|
3
3
|
type HTTPPath = `/${string}`;
|
|
4
4
|
type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
5
5
|
type ClientContext = Record<PropertyKey, any>;
|
|
6
|
-
|
|
6
|
+
interface ClientOptions<T extends ClientContext> {
|
|
7
7
|
signal?: AbortSignal;
|
|
8
8
|
lastEventId?: string | undefined;
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
context: T;
|
|
10
|
+
}
|
|
11
|
+
type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
12
|
+
context?: T;
|
|
11
13
|
} : {
|
|
12
|
-
context:
|
|
14
|
+
context: T;
|
|
13
15
|
});
|
|
14
16
|
type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
|
|
15
17
|
type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
|
|
@@ -20,9 +22,6 @@ type NestedClient<TClientContext extends ClientContext> = Client<TClientContext,
|
|
|
20
22
|
[k: string]: NestedClient<TClientContext>;
|
|
21
23
|
};
|
|
22
24
|
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
|
23
|
-
type ClientOptions<TClientContext extends ClientContext> = FriendlyClientOptions<TClientContext> & {
|
|
24
|
-
context: TClientContext;
|
|
25
|
-
};
|
|
26
25
|
interface ClientLink<TClientContext extends ClientContext> {
|
|
27
26
|
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
|
28
27
|
}
|
|
@@ -17,7 +17,7 @@ class StandardLink {
|
|
|
17
17
|
interceptors;
|
|
18
18
|
clientInterceptors;
|
|
19
19
|
call(path, input, options) {
|
|
20
|
-
return intercept(this.interceptors, { path, input
|
|
20
|
+
return intercept(this.interceptors, { ...options, path, input }, async ({ path: path2, input: input2, ...options2 }) => {
|
|
21
21
|
const output = await this.#call(path2, input2, options2);
|
|
22
22
|
return output;
|
|
23
23
|
});
|
|
@@ -26,8 +26,8 @@ class StandardLink {
|
|
|
26
26
|
const request = await this.codec.encode(path, input, options);
|
|
27
27
|
const response = await intercept(
|
|
28
28
|
this.clientInterceptors,
|
|
29
|
-
{ request },
|
|
30
|
-
({ request: request2 }) => this.sender.call(request2,
|
|
29
|
+
{ ...options, input, path, request },
|
|
30
|
+
({ input: input2, path: path2, request: request2, ...options2 }) => this.sender.call(request2, options2, path2, input2)
|
|
31
31
|
);
|
|
32
32
|
const output = await this.codec.decode(response, options, path, input);
|
|
33
33
|
return output;
|
|
@@ -205,7 +205,8 @@ class StandardRPCLinkCodec {
|
|
|
205
205
|
const expectedMethod = await value(this.expectedMethod, options, path, input);
|
|
206
206
|
let headers = await value(this.headers, options, path, input);
|
|
207
207
|
const baseUrl = await value(this.baseUrl, options, path, input);
|
|
208
|
-
const url = new URL(
|
|
208
|
+
const url = new URL(baseUrl);
|
|
209
|
+
url.pathname = `${url.pathname.replace(/\/$/, "")}${toHttpPath(path)}`;
|
|
209
210
|
if (options.lastEventId !== void 0) {
|
|
210
211
|
headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
|
|
211
212
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Interceptor, ThrowableError } from '@orpc/shared';
|
|
2
2
|
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
3
|
-
import { a as ClientContext, b as ClientOptions, C as ClientLink } from './client.
|
|
3
|
+
import { a as ClientContext, b as ClientOptions, C as ClientLink } from './client.CipPQkhk.js';
|
|
4
4
|
|
|
5
5
|
interface StandardLinkCodec<T extends ClientContext> {
|
|
6
6
|
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
|
|
@@ -15,15 +15,16 @@ declare class InvalidEventIteratorRetryResponse extends Error {
|
|
|
15
15
|
interface StandardLinkPlugin<T extends ClientContext> {
|
|
16
16
|
init?(options: StandardLinkOptions<T>): void;
|
|
17
17
|
}
|
|
18
|
+
interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
|
|
19
|
+
path: readonly string[];
|
|
20
|
+
input: unknown;
|
|
21
|
+
}
|
|
22
|
+
interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> {
|
|
23
|
+
request: StandardRequest;
|
|
24
|
+
}
|
|
18
25
|
interface StandardLinkOptions<T extends ClientContext> {
|
|
19
|
-
interceptors?: Interceptor<
|
|
20
|
-
|
|
21
|
-
input: unknown;
|
|
22
|
-
options: ClientOptions<T>;
|
|
23
|
-
}, unknown, ThrowableError>[];
|
|
24
|
-
clientInterceptors?: Interceptor<{
|
|
25
|
-
request: StandardRequest;
|
|
26
|
-
}, StandardLazyResponse, ThrowableError>[];
|
|
26
|
+
interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, unknown, ThrowableError>[];
|
|
27
|
+
clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, StandardLazyResponse, ThrowableError>[];
|
|
27
28
|
plugins?: StandardLinkPlugin<T>[];
|
|
28
29
|
}
|
|
29
30
|
declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
@@ -36,4 +37,4 @@ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
|
36
37
|
call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
export { InvalidEventIteratorRetryResponse as I, type
|
|
40
|
+
export { InvalidEventIteratorRetryResponse as I, type StandardLinkClientInterceptorOptions as S, type StandardLinkPlugin as a, type StandardLinkOptions as b, type StandardLinkInterceptorOptions as c, StandardLink as d, type StandardLinkCodec as e, type StandardLinkClient as f };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/client",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.4c9dd72",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"dist"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@orpc/
|
|
43
|
-
"@orpc/standard-server
|
|
44
|
-
"@orpc/
|
|
42
|
+
"@orpc/shared": "0.0.0-next.4c9dd72",
|
|
43
|
+
"@orpc/standard-server": "0.0.0-next.4c9dd72",
|
|
44
|
+
"@orpc/standard-server-fetch": "0.0.0-next.4c9dd72"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"zod": "^3.24.2"
|