@orpc/client 2.0.0-beta.49 → 2.0.0-beta.50
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.ts +3 -2
- package/dist/adapters/fetch/index.js +2 -2
- package/dist/adapters/fetch/rpc-link.d.ts +8 -8
- package/dist/adapters/fetch/rpc-link.js +16 -13
- package/dist/adapters/fetch/transport.d.ts +29 -31
- package/dist/adapters/fetch/transport.js +49 -63
- package/dist/adapters/message-port/index.d.ts +4 -3
- package/dist/adapters/message-port/index.js +3 -3
- package/dist/adapters/message-port/message-port.d.ts +13 -13
- package/dist/adapters/message-port/message-port.js +35 -53
- package/dist/adapters/message-port/rpc-link.d.ts +8 -8
- package/dist/adapters/message-port/rpc-link.js +17 -14
- package/dist/adapters/message-port/transport.d.ts +31 -34
- package/dist/adapters/message-port/transport.js +38 -52
- package/dist/adapters/standard/codec.d.ts +10 -10
- package/dist/adapters/standard/index.d.ts +6 -5
- package/dist/adapters/standard/index.js +2 -4
- package/dist/adapters/standard/link.d.ts +31 -31
- package/dist/adapters/standard/link.js +101 -85
- package/dist/adapters/standard/plugin.d.ts +25 -31
- package/dist/adapters/standard/plugin.js +14 -16
- package/dist/adapters/standard/rpc-link-codec.d.ts +53 -60
- package/dist/adapters/standard/rpc-link-codec.js +98 -102
- package/dist/adapters/standard/transport.d.ts +7 -7
- package/dist/adapters/websocket/index.d.ts +3 -2
- package/dist/adapters/websocket/index.js +2 -2
- package/dist/adapters/websocket/rpc-link.d.ts +8 -8
- package/dist/adapters/websocket/rpc-link.js +16 -13
- package/dist/adapters/websocket/transport.d.ts +101 -100
- package/dist/adapters/websocket/transport.js +102 -130
- package/dist/async-iterator-object.d.ts +2 -2
- package/dist/async-iterator-object.js +27 -28
- package/dist/client-safe.d.ts +4 -6
- package/dist/client-safe.js +29 -34
- package/dist/client.d.ts +24 -26
- package/dist/client.js +35 -37
- package/dist/consts.d.ts +1 -1
- package/dist/consts.js +18 -41
- package/dist/dynamic-link.d.ts +6 -6
- package/dist/dynamic-link.js +16 -16
- package/dist/error-utils.d.ts +3 -4
- package/dist/error-utils.js +47 -51
- package/dist/error.d.ts +79 -79
- package/dist/error.js +154 -166
- package/dist/index.d.ts +14 -53
- package/dist/index.js +12 -40
- package/dist/plugins/batch.d.ts +122 -155
- package/dist/plugins/batch.js +320 -391
- package/dist/plugins/cookie-jar.d.ts +64 -61
- package/dist/plugins/cookie-jar.js +208 -245
- package/dist/plugins/dedupe.d.ts +49 -53
- package/dist/plugins/dedupe.js +168 -211
- package/dist/plugins/index.d.ts +9 -28
- package/dist/plugins/index.js +8 -23
- package/dist/plugins/request-compression.d.ts +38 -35
- package/dist/plugins/request-compression.js +131 -177
- package/dist/plugins/response-compression.d.ts +21 -18
- package/dist/plugins/response-compression.js +64 -88
- package/dist/plugins/retry-after.d.ts +31 -38
- package/dist/plugins/retry-after.js +60 -85
- package/dist/plugins/retry.d.ts +55 -55
- package/dist/plugins/retry.js +118 -137
- package/dist/plugins/timeout.d.ts +19 -17
- package/dist/plugins/timeout.js +41 -36
- package/dist/rpc-json-serializer.d.ts +84 -84
- package/dist/rpc-json-serializer.js +338 -383
- package/dist/rpc-serializer.d.ts +20 -21
- package/dist/rpc-serializer.js +97 -125
- package/dist/types.d.ts +19 -31
- package/dist/utils.d.ts +18 -29
- package/dist/utils.js +63 -47
- package/package.json +5 -5
- package/dist/adapters/standard/codec.js +0 -1
- package/dist/adapters/standard/transport.js +0 -1
- package/dist/types.js +0 -1
|
@@ -1,52 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
*/
|
|
40
|
-
await this.peer.message(peerMessage);
|
|
41
|
-
return { matched: true };
|
|
42
|
-
});
|
|
43
|
-
onMessagePortClose(port, async () => {
|
|
44
|
-
closeReason = new AbortError('MessagePort closed');
|
|
45
|
-
await this.peer.close(closeReason);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
async send(standardRequest, _path, _options) {
|
|
49
|
-
const standardResponse = await this.peer.request(standardRequest);
|
|
50
|
-
return standardResponse;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
1
|
+
import { onMessagePortClose, onMessagePortMessage, postMessagePortMessage } from "./message-port.js";
|
|
2
|
+
import { AbortError, value } from "@orpc/shared";
|
|
3
|
+
import { ClientPeer, decodePeerMessage, encodePeerMessage, isPeerMessage, isServerPeerSendMessage } from "@standard-server/peer";
|
|
4
|
+
// src/adapters/message-port/transport.ts
|
|
5
|
+
var MessagePortLinkTransport = class {
|
|
6
|
+
peer;
|
|
7
|
+
constructor({ port, experimental_transfer, encodePeerMessage: encodePeerMessageOptions, decodePeerMessage: decodePeerMessageOptions }) {
|
|
8
|
+
let closeReason;
|
|
9
|
+
this.peer = new ClientPeer(async (message) => {
|
|
10
|
+
if (closeReason) throw closeReason;
|
|
11
|
+
const transfer = await value(experimental_transfer, message, port);
|
|
12
|
+
if (transfer) postMessagePortMessage(port, message, transfer);
|
|
13
|
+
else postMessagePortMessage(port, await encodePeerMessage(message, encodePeerMessageOptions));
|
|
14
|
+
});
|
|
15
|
+
onMessagePortMessage(port, async (data) => {
|
|
16
|
+
let peerMessage;
|
|
17
|
+
if (typeof data === "string" || data instanceof Uint8Array) {
|
|
18
|
+
const result = decodePeerMessage(data, decodePeerMessageOptions);
|
|
19
|
+
if (result.matched && isServerPeerSendMessage(result.message)) peerMessage = result.message;
|
|
20
|
+
} else if (isPeerMessage(data) && isServerPeerSendMessage(data)) peerMessage = data;
|
|
21
|
+
if (peerMessage === void 0) return { matched: false };
|
|
22
|
+
/**
|
|
23
|
+
* Message order is important: loading -> decode -> .message.
|
|
24
|
+
* This flow must stay synchronous, or we need to use `sequential` helper
|
|
25
|
+
*/
|
|
26
|
+
await this.peer.message(peerMessage);
|
|
27
|
+
return { matched: true };
|
|
28
|
+
});
|
|
29
|
+
onMessagePortClose(port, async () => {
|
|
30
|
+
closeReason = new AbortError("MessagePort closed");
|
|
31
|
+
await this.peer.close(closeReason);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async send(standardRequest, _path, _options) {
|
|
35
|
+
return await this.peer.request(standardRequest);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
export { MessagePortLinkTransport };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { ClientContext, ClientOptions } from "../../types.js";
|
|
2
|
+
import { Promisable } from "@orpc/shared";
|
|
3
|
+
import { StandardLazyResponse, StandardRequest } from "@standard-server/core";
|
|
4
4
|
export type StandardLinkCodecDecodedResponse = {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
kind: "output";
|
|
6
|
+
output: unknown;
|
|
7
7
|
} | {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
kind: "error";
|
|
9
|
+
error: Error;
|
|
10
10
|
};
|
|
11
11
|
export interface StandardLinkCodec<T extends ClientContext> {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
12
|
+
encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promisable<StandardRequest>;
|
|
13
|
+
decodeResponse(response: StandardLazyResponse, path: string[], options: ClientOptions<T>): Promisable<StandardLinkCodecDecodedResponse>;
|
|
14
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { StandardLinkCodec, StandardLinkCodecDecodedResponse } from "./codec.js";
|
|
2
|
+
import { StandardLink, StandardLinkInterceptor, StandardLinkInterceptorOptions, StandardLinkOptions, StandardLinkTransportInterceptor, StandardLinkTransportInterceptorOptions } from "./link.js";
|
|
3
|
+
import { StandardLinkPlugin } from "./plugin.js";
|
|
4
|
+
import { RPCLinkCodec, RPCLinkCodecOptions } from "./rpc-link-codec.js";
|
|
5
|
+
import { StandardLinkTransport } from "./transport.js";
|
|
6
|
+
export { RPCLinkCodec, RPCLinkCodecOptions, StandardLink, StandardLinkCodec, StandardLinkCodecDecodedResponse, StandardLinkInterceptor, StandardLinkInterceptorOptions, StandardLinkOptions, type StandardLinkPlugin, StandardLinkTransport, StandardLinkTransportInterceptor, StandardLinkTransportInterceptorOptions };
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
1
|
+
import { ClientContext, ClientLink, ClientOptions } from "../../types.js";
|
|
2
|
+
import { StandardLinkCodec } from "./codec.js";
|
|
3
|
+
import { StandardLinkPlugin } from "./plugin.js";
|
|
4
|
+
import { StandardLinkTransport } from "./transport.js";
|
|
5
|
+
import { Interceptor } from "@orpc/shared";
|
|
6
|
+
import { StandardLazyResponse, StandardRequest } from "@standard-server/core";
|
|
7
7
|
export interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
path: string[];
|
|
9
|
+
input: unknown;
|
|
10
10
|
}
|
|
11
11
|
export type StandardLinkInterceptor<T extends ClientContext> = Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>;
|
|
12
12
|
export interface StandardLinkTransportInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
path: string[];
|
|
14
|
+
request: StandardRequest;
|
|
15
15
|
}
|
|
16
16
|
export type StandardLinkTransportInterceptor<T extends ClientContext> = Interceptor<StandardLinkTransportInterceptorOptions<T>, Promise<StandardLazyResponse>>;
|
|
17
17
|
export interface StandardLinkOptions<T extends ClientContext> {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Interceptors that execute around the entire call, including transport and codec.
|
|
20
|
+
* Useful for error handling, logging, metrics, ...
|
|
21
|
+
*/
|
|
22
|
+
interceptors?: StandardLinkInterceptor<T>[] | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Interceptors that execute around the transport layer, after encoding and before decoding.
|
|
25
|
+
* Useful for modifying the request or response, adding transport-level logging, ...
|
|
26
|
+
*/
|
|
27
|
+
transportInterceptors?: StandardLinkTransportInterceptor<T>[] | undefined;
|
|
28
|
+
plugins?: StandardLinkPlugin<T>[] | undefined;
|
|
29
29
|
}
|
|
30
30
|
export declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
31
|
+
private readonly codec;
|
|
32
|
+
private readonly transport;
|
|
33
|
+
private readonly interceptors;
|
|
34
|
+
private readonly transportInterceptors;
|
|
35
|
+
constructor(codec: StandardLinkCodec<T>, transport: StandardLinkTransport<T>, options?: StandardLinkOptions<T>);
|
|
36
|
+
/**
|
|
37
|
+
* @throws ORPCError, MalformedResponseError, transport-level errors (network failures, timeouts, etc.)
|
|
38
|
+
*/
|
|
39
|
+
call(path: string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
|
|
40
|
+
}
|
|
@@ -1,85 +1,101 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
1
|
+
import { CompositeStandardLinkPlugin } from "./plugin.js";
|
|
2
|
+
import { ORPC_NAME, getTracer, intercept, isAsyncIteratorObject, override, runWithSpan, traceAsyncIterator, traceReadableStream } from "@orpc/shared";
|
|
3
|
+
// src/adapters/standard/link.ts
|
|
4
|
+
var StandardLink = class {
|
|
5
|
+
codec;
|
|
6
|
+
transport;
|
|
7
|
+
interceptors;
|
|
8
|
+
transportInterceptors;
|
|
9
|
+
constructor(codec, transport, options = {}) {
|
|
10
|
+
this.codec = codec;
|
|
11
|
+
this.transport = transport;
|
|
12
|
+
options = new CompositeStandardLinkPlugin(options.plugins).init(options);
|
|
13
|
+
this.interceptors = options.interceptors;
|
|
14
|
+
this.transportInterceptors = options.transportInterceptors;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @throws ORPCError, MalformedResponseError, transport-level errors (network failures, timeouts, etc.)
|
|
18
|
+
*/
|
|
19
|
+
call(path, input, options) {
|
|
20
|
+
return runWithSpan(`${ORPC_NAME}.${path.join("/")}`, (span) => {
|
|
21
|
+
/**
|
|
22
|
+
* [Semantic conventions for RPC spans](https://opentelemetry.io/docs/specs/semconv/rpc/rpc-spans/)
|
|
23
|
+
*/
|
|
24
|
+
span?.setAttribute("rpc.system", ORPC_NAME);
|
|
25
|
+
span?.setAttribute("rpc.method", path.join("."));
|
|
26
|
+
if (getTracer() && isAsyncIteratorObject(input))
|
|
27
|
+
/**
|
|
28
|
+
* @warning
|
|
29
|
+
* Remember use `override` for AsyncIteratorObject to remain other special properties
|
|
30
|
+
*/
|
|
31
|
+
input = override(input, traceAsyncIterator("consume_async_iterator_object_input", input));
|
|
32
|
+
else if (getTracer() && input instanceof ReadableStream)
|
|
33
|
+
/**
|
|
34
|
+
* @warning
|
|
35
|
+
* Remember use `override` for ReadableStream to remain other special properties
|
|
36
|
+
*/
|
|
37
|
+
input = override(input, traceReadableStream("consume_octet_stream_input", input));
|
|
38
|
+
return intercept(this.interceptors, {
|
|
39
|
+
...options,
|
|
40
|
+
path,
|
|
41
|
+
input
|
|
42
|
+
}, async ({ path, input, ...options }) => {
|
|
43
|
+
/**
|
|
44
|
+
* In browsers, the OpenTelemetry context manager may not work reliably with async functions,
|
|
45
|
+
* so we should manually pass the parent span here.
|
|
46
|
+
*/
|
|
47
|
+
const tracer = getTracer();
|
|
48
|
+
const activeSpan = tracer?.getActiveSpan() ?? span;
|
|
49
|
+
let request = await runWithSpan({
|
|
50
|
+
name: "encode_input",
|
|
51
|
+
parent: activeSpan
|
|
52
|
+
}, () => this.codec.encodeInput(input, path, options));
|
|
53
|
+
if (activeSpan && tracer?.inject) {
|
|
54
|
+
const headers = { ...request.headers };
|
|
55
|
+
tracer.inject(activeSpan, headers);
|
|
56
|
+
request = {
|
|
57
|
+
...request,
|
|
58
|
+
headers
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const response = await intercept(this.transportInterceptors, {
|
|
62
|
+
...options,
|
|
63
|
+
path,
|
|
64
|
+
request
|
|
65
|
+
}, ({ path, request, ...options }) => {
|
|
66
|
+
/**
|
|
67
|
+
* In browsers, the OpenTelemetry context manager may not work reliably with async functions,
|
|
68
|
+
* so we should manually pass the parent span here.
|
|
69
|
+
*/
|
|
70
|
+
const activeTransportSpan = tracer?.getActiveSpan() ?? activeSpan;
|
|
71
|
+
return runWithSpan({
|
|
72
|
+
name: "send_request",
|
|
73
|
+
parent: activeTransportSpan
|
|
74
|
+
}, () => this.transport.send(request, path, options));
|
|
75
|
+
});
|
|
76
|
+
const decodedResult = await runWithSpan({
|
|
77
|
+
name: "decode_response",
|
|
78
|
+
parent: activeSpan
|
|
79
|
+
}, () => this.codec.decodeResponse(response, path, options));
|
|
80
|
+
if (decodedResult.kind === "error") throw decodedResult.error;
|
|
81
|
+
const output = decodedResult.output;
|
|
82
|
+
if (getTracer() && isAsyncIteratorObject(output))
|
|
83
|
+
/**
|
|
84
|
+
* Do not pass the active span as parent here, as it is a lazy span.
|
|
85
|
+
*
|
|
86
|
+
* @warning
|
|
87
|
+
* Remember use `override` for AsyncIteratorObject to remain other special properties
|
|
88
|
+
*/
|
|
89
|
+
return override(output, traceAsyncIterator("consume_async_iterator_object_output", output));
|
|
90
|
+
else if (getTracer() && output instanceof ReadableStream)
|
|
91
|
+
/**
|
|
92
|
+
* @warning
|
|
93
|
+
* Remember use `override` for ReadableStream to remain other special properties
|
|
94
|
+
*/
|
|
95
|
+
return override(output, traceReadableStream("consume_octet_stream_output", output));
|
|
96
|
+
return output;
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
export { StandardLink };
|
|
@@ -1,32 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { ClientContext } from "../../types.js";
|
|
2
|
+
import { StandardLinkOptions } from "./link.js";
|
|
3
|
+
import { OrderablePlugin } from "@orpc/shared";
|
|
4
4
|
export interface StandardLinkPlugin<T extends ClientContext> extends OrderablePlugin {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
export declare class CompositeStandardLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
28
|
-
name: string;
|
|
29
|
-
protected readonly plugins: StandardLinkPlugin<T>[];
|
|
30
|
-
constructor(plugins?: StandardLinkPlugin<T>[]);
|
|
31
|
-
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
32
|
-
}
|
|
5
|
+
/**
|
|
6
|
+
* Initializes the plugin and returns new link options.
|
|
7
|
+
* Called once per plugin instance during composition.
|
|
8
|
+
*
|
|
9
|
+
* This method allows plugins to wrap, extend, or transform link options
|
|
10
|
+
* such as interceptors, or configuration.
|
|
11
|
+
*
|
|
12
|
+
* @param options - The current link options from previous plugins or base configuration
|
|
13
|
+
* @returns Transformed link options with plugin's modifications applied
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* init(options) {
|
|
18
|
+
* return {
|
|
19
|
+
* ...options,
|
|
20
|
+
* interceptors: [...(options.interceptors || []), myInterceptor]
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
init?(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
26
|
+
}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import { sortPlugins } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
}
|
|
1
|
+
import { sortPlugins } from "@orpc/shared";
|
|
2
|
+
// src/adapters/standard/plugin.ts
|
|
3
|
+
var CompositeStandardLinkPlugin = class {
|
|
4
|
+
name = "~composite";
|
|
5
|
+
plugins;
|
|
6
|
+
constructor(plugins = []) {
|
|
7
|
+
this.plugins = sortPlugins(plugins);
|
|
8
|
+
}
|
|
9
|
+
init(options) {
|
|
10
|
+
for (const plugin of this.plugins) if (plugin.init) options = plugin.init(options);
|
|
11
|
+
return options;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
export { CompositeStandardLinkPlugin };
|
|
@@ -1,63 +1,56 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import { RPCSerializer } from "../../rpc-serializer.js";
|
|
2
|
+
import { StandardLinkCodec, StandardLinkCodecDecodedResponse } from "./codec.js";
|
|
3
|
+
import { ClientContext, ClientOptions } from "../../types.js";
|
|
4
|
+
import "./index.js";
|
|
5
|
+
import { Promisable, Public, Value } from "@orpc/shared";
|
|
6
|
+
import { StandardHeaders, StandardLazyResponse, StandardRequest, StandardUrl } from "@standard-server/core";
|
|
6
7
|
export interface RPCLinkCodecOptions<T extends ClientContext> {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
options: ClientOptions<T>,
|
|
45
|
-
path: string[],
|
|
46
|
-
input: unknown
|
|
47
|
-
]> | undefined;
|
|
48
|
-
/**
|
|
49
|
-
* Override the default RPC serializer.
|
|
50
|
-
*/
|
|
51
|
-
serializer?: Public<RPCSerializer> | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Base url for all requests (without origin). Should match with handler's prefix.
|
|
10
|
+
*
|
|
11
|
+
* @example '/rpc?base=1'
|
|
12
|
+
*
|
|
13
|
+
* @default '/'
|
|
14
|
+
*/
|
|
15
|
+
url?: Value<Promisable<StandardUrl>, [options: ClientOptions<T>, path: string[], input: unknown]> | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* The maximum length of the URL.
|
|
18
|
+
*
|
|
19
|
+
* If the URL exceeds this length, the codec should use the `fallbackMethod` to send the request with the payload in the body instead of the URL.
|
|
20
|
+
*
|
|
21
|
+
* @default 2083
|
|
22
|
+
*/
|
|
23
|
+
maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: string[], input: unknown]> | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* The method used to make the request.
|
|
26
|
+
*
|
|
27
|
+
* @default 'POST'
|
|
28
|
+
*/
|
|
29
|
+
method?: Value<Promisable<"GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "QUERY">, [options: ClientOptions<T>, path: string[], input: unknown]> | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
|
32
|
+
* GET is not allowed, it's very dangerous.
|
|
33
|
+
*
|
|
34
|
+
* @default 'POST'
|
|
35
|
+
*/
|
|
36
|
+
fallbackMethod?: "POST" | "PUT" | "PATCH" | "DELETE" | "QUERY" | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Inject headers to the request.
|
|
39
|
+
*/
|
|
40
|
+
headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: string[], input: unknown]> | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Override the default RPC serializer.
|
|
43
|
+
*/
|
|
44
|
+
serializer?: Public<RPCSerializer> | undefined;
|
|
52
45
|
}
|
|
53
46
|
export declare class RPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
47
|
+
private readonly baseUrl;
|
|
48
|
+
private readonly maxUrlLength;
|
|
49
|
+
private readonly fallbackMethod;
|
|
50
|
+
private readonly expectedMethod;
|
|
51
|
+
private readonly headers;
|
|
52
|
+
private readonly serializer;
|
|
53
|
+
constructor(options: RPCLinkCodecOptions<T>);
|
|
54
|
+
encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promise<StandardRequest>;
|
|
55
|
+
decodeResponse(response: StandardLazyResponse): Promise<StandardLinkCodecDecodedResponse>;
|
|
56
|
+
}
|