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