@orpc/client 1.8.2 → 1.8.3
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.
@@ -1,23 +1,36 @@
|
|
1
|
+
import { Interceptor } from '@orpc/shared';
|
1
2
|
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
2
3
|
import { ToFetchRequestOptions } from '@orpc/standard-server-fetch';
|
3
4
|
import { b as ClientContext, c as ClientOptions } from '../../shared/client.BOYsZIRq.mjs';
|
4
|
-
import { f as StandardLinkClient } from '../../shared/client.Bwgm6dgk.mjs';
|
5
|
+
import { a as StandardLinkPlugin, f as StandardLinkClient } from '../../shared/client.Bwgm6dgk.mjs';
|
5
6
|
import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.Ycwr4Tuo.mjs';
|
6
|
-
import '@orpc/shared';
|
7
7
|
|
8
|
-
interface
|
9
|
-
|
8
|
+
interface LinkFetchPlugin<T extends ClientContext> extends StandardLinkPlugin<T> {
|
9
|
+
initRuntimeAdapter?(options: LinkFetchClientOptions<T>): void;
|
10
|
+
}
|
11
|
+
|
12
|
+
interface LinkFetchInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
|
13
|
+
request: Request;
|
14
|
+
init: {
|
10
15
|
redirect?: Request['redirect'];
|
11
|
-
}
|
16
|
+
};
|
17
|
+
path: readonly string[];
|
18
|
+
input: unknown;
|
19
|
+
}
|
20
|
+
interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
|
21
|
+
fetch?: (request: Request, init: LinkFetchInterceptorOptions<T>['init'], options: ClientOptions<T>, path: readonly string[], input: unknown) => Promise<Response>;
|
22
|
+
adapterInterceptors?: Interceptor<LinkFetchInterceptorOptions<T>, Promise<Response>>[];
|
23
|
+
plugins?: LinkFetchPlugin<T>[];
|
12
24
|
}
|
13
25
|
declare class LinkFetchClient<T extends ClientContext> implements StandardLinkClient<T> {
|
14
26
|
private readonly fetch;
|
15
27
|
private readonly toFetchRequestOptions;
|
28
|
+
private readonly adapterInterceptors;
|
16
29
|
constructor(options: LinkFetchClientOptions<T>);
|
17
|
-
call(
|
30
|
+
call(standardRequest: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
18
31
|
}
|
19
32
|
|
20
|
-
interface RPCLinkOptions<T extends ClientContext> extends
|
33
|
+
interface RPCLinkOptions<T extends ClientContext> extends LinkFetchClientOptions<T>, Omit<StandardRPCLinkOptions<T>, 'plugins'> {
|
21
34
|
}
|
22
35
|
/**
|
23
36
|
* The RPC Link communicates with the server using the RPC protocol.
|
@@ -30,4 +43,4 @@ declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
|
|
30
43
|
}
|
31
44
|
|
32
45
|
export { LinkFetchClient, RPCLink };
|
33
|
-
export type { LinkFetchClientOptions, RPCLinkOptions };
|
46
|
+
export type { LinkFetchClientOptions, LinkFetchInterceptorOptions, RPCLinkOptions };
|
@@ -1,23 +1,36 @@
|
|
1
|
+
import { Interceptor } from '@orpc/shared';
|
1
2
|
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
2
3
|
import { ToFetchRequestOptions } from '@orpc/standard-server-fetch';
|
3
4
|
import { b as ClientContext, c as ClientOptions } from '../../shared/client.BOYsZIRq.js';
|
4
|
-
import { f as StandardLinkClient } from '../../shared/client.BG98rYdO.js';
|
5
|
+
import { a as StandardLinkPlugin, f as StandardLinkClient } from '../../shared/client.BG98rYdO.js';
|
5
6
|
import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.C176log5.js';
|
6
|
-
import '@orpc/shared';
|
7
7
|
|
8
|
-
interface
|
9
|
-
|
8
|
+
interface LinkFetchPlugin<T extends ClientContext> extends StandardLinkPlugin<T> {
|
9
|
+
initRuntimeAdapter?(options: LinkFetchClientOptions<T>): void;
|
10
|
+
}
|
11
|
+
|
12
|
+
interface LinkFetchInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
|
13
|
+
request: Request;
|
14
|
+
init: {
|
10
15
|
redirect?: Request['redirect'];
|
11
|
-
}
|
16
|
+
};
|
17
|
+
path: readonly string[];
|
18
|
+
input: unknown;
|
19
|
+
}
|
20
|
+
interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
|
21
|
+
fetch?: (request: Request, init: LinkFetchInterceptorOptions<T>['init'], options: ClientOptions<T>, path: readonly string[], input: unknown) => Promise<Response>;
|
22
|
+
adapterInterceptors?: Interceptor<LinkFetchInterceptorOptions<T>, Promise<Response>>[];
|
23
|
+
plugins?: LinkFetchPlugin<T>[];
|
12
24
|
}
|
13
25
|
declare class LinkFetchClient<T extends ClientContext> implements StandardLinkClient<T> {
|
14
26
|
private readonly fetch;
|
15
27
|
private readonly toFetchRequestOptions;
|
28
|
+
private readonly adapterInterceptors;
|
16
29
|
constructor(options: LinkFetchClientOptions<T>);
|
17
|
-
call(
|
30
|
+
call(standardRequest: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
18
31
|
}
|
19
32
|
|
20
|
-
interface RPCLinkOptions<T extends ClientContext> extends
|
33
|
+
interface RPCLinkOptions<T extends ClientContext> extends LinkFetchClientOptions<T>, Omit<StandardRPCLinkOptions<T>, 'plugins'> {
|
21
34
|
}
|
22
35
|
/**
|
23
36
|
* The RPC Link communicates with the server using the RPC protocol.
|
@@ -30,4 +43,4 @@ declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
|
|
30
43
|
}
|
31
44
|
|
32
45
|
export { LinkFetchClient, RPCLink };
|
33
|
-
export type { LinkFetchClientOptions, RPCLinkOptions };
|
46
|
+
export type { LinkFetchClientOptions, LinkFetchInterceptorOptions, RPCLinkOptions };
|
@@ -1,20 +1,36 @@
|
|
1
|
+
import { toArray, intercept } from '@orpc/shared';
|
1
2
|
import { toFetchRequest, toStandardLazyResponse } from '@orpc/standard-server-fetch';
|
2
|
-
import '
|
3
|
-
import { c as StandardRPCLink } from '../../shared/client.DKmRtVO2.mjs';
|
3
|
+
import { C as CompositeStandardLinkPlugin, c as StandardRPCLink } from '../../shared/client.DKmRtVO2.mjs';
|
4
4
|
import '@orpc/standard-server';
|
5
5
|
import '../../shared/client.txdq_i5V.mjs';
|
6
6
|
|
7
|
+
class CompositeLinkFetchPlugin extends CompositeStandardLinkPlugin {
|
8
|
+
initRuntimeAdapter(options) {
|
9
|
+
for (const plugin of this.plugins) {
|
10
|
+
plugin.initRuntimeAdapter?.(options);
|
11
|
+
}
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
7
15
|
class LinkFetchClient {
|
8
16
|
fetch;
|
9
17
|
toFetchRequestOptions;
|
18
|
+
adapterInterceptors;
|
10
19
|
constructor(options) {
|
11
|
-
|
20
|
+
const plugin = new CompositeLinkFetchPlugin(options.plugins);
|
21
|
+
plugin.initRuntimeAdapter(options);
|
22
|
+
this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
|
12
23
|
this.toFetchRequestOptions = options;
|
24
|
+
this.adapterInterceptors = toArray(options.adapterInterceptors);
|
13
25
|
}
|
14
|
-
async call(
|
15
|
-
const
|
16
|
-
const fetchResponse = await
|
17
|
-
|
26
|
+
async call(standardRequest, options, path, input) {
|
27
|
+
const request = toFetchRequest(standardRequest, this.toFetchRequestOptions);
|
28
|
+
const fetchResponse = await intercept(
|
29
|
+
this.adapterInterceptors,
|
30
|
+
{ ...options, request, path, input, init: { redirect: "manual" } },
|
31
|
+
({ request: request2, path: path2, input: input2, init, ...options2 }) => this.fetch(request2, init, options2, path2, input2)
|
32
|
+
);
|
33
|
+
const lazyResponse = toStandardLazyResponse(fetchResponse, { signal: request.signal });
|
18
34
|
return lazyResponse;
|
19
35
|
}
|
20
36
|
}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/client",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.8.
|
4
|
+
"version": "1.8.3",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -49,10 +49,10 @@
|
|
49
49
|
"dist"
|
50
50
|
],
|
51
51
|
"dependencies": {
|
52
|
-
"@orpc/
|
53
|
-
"@orpc/
|
54
|
-
"@orpc/standard-server": "1.8.
|
55
|
-
"@orpc/standard-server-peer": "1.8.
|
52
|
+
"@orpc/standard-server": "1.8.3",
|
53
|
+
"@orpc/shared": "1.8.3",
|
54
|
+
"@orpc/standard-server-fetch": "1.8.3",
|
55
|
+
"@orpc/standard-server-peer": "1.8.3"
|
56
56
|
},
|
57
57
|
"devDependencies": {
|
58
58
|
"zod": "^4.0.17"
|