@orpc/client 0.0.0-next.4fc998d → 0.0.0-next.50b03b7

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 (32) hide show
  1. package/README.md +39 -30
  2. package/dist/adapters/fetch/index.d.mts +31 -14
  3. package/dist/adapters/fetch/index.d.ts +31 -14
  4. package/dist/adapters/fetch/index.mjs +27 -17
  5. package/dist/adapters/message-port/index.d.mts +80 -0
  6. package/dist/adapters/message-port/index.d.ts +80 -0
  7. package/dist/adapters/message-port/index.mjs +87 -0
  8. package/dist/adapters/standard/index.d.mts +9 -167
  9. package/dist/adapters/standard/index.d.ts +9 -167
  10. package/dist/adapters/standard/index.mjs +4 -2
  11. package/dist/adapters/websocket/index.d.mts +29 -0
  12. package/dist/adapters/websocket/index.d.ts +29 -0
  13. package/dist/adapters/websocket/index.mjs +47 -0
  14. package/dist/index.d.mts +107 -33
  15. package/dist/index.d.ts +107 -33
  16. package/dist/index.mjs +85 -36
  17. package/dist/plugins/index.d.mts +249 -0
  18. package/dist/plugins/index.d.ts +249 -0
  19. package/dist/plugins/index.mjs +485 -0
  20. package/dist/shared/client.2jUAqzYU.d.ts +45 -0
  21. package/dist/shared/client.B3pNRBih.d.ts +91 -0
  22. package/dist/shared/client.BFAVy68H.d.mts +91 -0
  23. package/dist/shared/client.BLtwTQUg.mjs +40 -0
  24. package/dist/shared/client.B_sF8lzC.mjs +171 -0
  25. package/dist/shared/{client.CPmBUYbj.mjs → client.Blkj2isF.mjs} +109 -62
  26. package/dist/shared/client.CpCa3si8.d.mts +45 -0
  27. package/dist/shared/client.i2uoJbEp.d.mts +83 -0
  28. package/dist/shared/client.i2uoJbEp.d.ts +83 -0
  29. package/package.json +23 -8
  30. package/dist/shared/client.D_CzLDyB.d.mts +0 -42
  31. package/dist/shared/client.D_CzLDyB.d.ts +0 -42
  32. package/dist/shared/client.XAn8cDTM.mjs +0 -266
@@ -0,0 +1,91 @@
1
+ import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.i2uoJbEp.mjs';
2
+ import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.CpCa3si8.mjs';
3
+ import { Segment, Value, Promisable } from '@orpc/shared';
4
+ import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
5
+
6
+ declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
7
+ readonly BIGINT: 0;
8
+ readonly DATE: 1;
9
+ readonly NAN: 2;
10
+ readonly UNDEFINED: 3;
11
+ readonly URL: 4;
12
+ readonly REGEXP: 5;
13
+ readonly SET: 6;
14
+ readonly MAP: 7;
15
+ };
16
+ type StandardRPCJsonSerializedMetaItem = readonly [type: number, ...path: Segment[]];
17
+ type StandardRPCJsonSerialized = [json: unknown, meta: StandardRPCJsonSerializedMetaItem[], maps: Segment[][], blobs: Blob[]];
18
+ interface StandardRPCCustomJsonSerializer {
19
+ type: number;
20
+ condition(data: unknown): boolean;
21
+ serialize(data: any): unknown;
22
+ deserialize(serialized: any): unknown;
23
+ }
24
+ interface StandardRPCJsonSerializerOptions {
25
+ customJsonSerializers?: readonly StandardRPCCustomJsonSerializer[];
26
+ }
27
+ declare class StandardRPCJsonSerializer {
28
+ private readonly customSerializers;
29
+ constructor(options?: StandardRPCJsonSerializerOptions);
30
+ serialize(data: unknown, segments?: Segment[], meta?: StandardRPCJsonSerializedMetaItem[], maps?: Segment[][], blobs?: Blob[]): StandardRPCJsonSerialized;
31
+ deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[]): unknown;
32
+ deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[], maps: readonly Segment[][], getBlob: (index: number) => Blob): unknown;
33
+ }
34
+
35
+ declare class StandardRPCSerializer {
36
+ #private;
37
+ private readonly jsonSerializer;
38
+ constructor(jsonSerializer: StandardRPCJsonSerializer);
39
+ serialize(data: unknown): object;
40
+ deserialize(data: unknown): unknown;
41
+ }
42
+
43
+ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
44
+ /**
45
+ * Base url for all requests.
46
+ */
47
+ url: Value<Promisable<string | URL>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
48
+ /**
49
+ * The maximum length of the URL.
50
+ *
51
+ * @default 2083
52
+ */
53
+ maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
54
+ /**
55
+ * The method used to make the request.
56
+ *
57
+ * @default 'POST'
58
+ */
59
+ method?: Value<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
60
+ /**
61
+ * The method to use when the payload cannot safely pass to the server with method return from method function.
62
+ * GET is not allowed, it's very dangerous.
63
+ *
64
+ * @default 'POST'
65
+ */
66
+ fallbackMethod?: Exclude<HTTPMethod, 'HEAD' | 'GET'>;
67
+ /**
68
+ * Inject headers to the request.
69
+ */
70
+ headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
71
+ }
72
+ declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
73
+ private readonly serializer;
74
+ private readonly baseUrl;
75
+ private readonly maxUrlLength;
76
+ private readonly fallbackMethod;
77
+ private readonly expectedMethod;
78
+ private readonly headers;
79
+ constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>);
80
+ encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
81
+ decode(response: StandardLazyResponse): Promise<unknown>;
82
+ }
83
+
84
+ interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions {
85
+ }
86
+ declare class StandardRPCLink<T extends ClientContext> extends StandardLink<T> {
87
+ constructor(linkClient: StandardLinkClient<T>, options: StandardRPCLinkOptions<T>);
88
+ }
89
+
90
+ export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, StandardRPCJsonSerializer as e, StandardRPCLink as g, StandardRPCLinkCodec as i, StandardRPCSerializer as j };
91
+ export type { StandardRPCJsonSerializedMetaItem as a, StandardRPCJsonSerialized as b, StandardRPCCustomJsonSerializer as c, StandardRPCJsonSerializerOptions as d, StandardRPCLinkOptions as f, StandardRPCLinkCodecOptions as h };
@@ -0,0 +1,40 @@
1
+ import { AsyncIteratorClass, isTypescriptObject } from '@orpc/shared';
2
+ import { getEventMeta, withEventMeta } from '@orpc/standard-server';
3
+
4
+ function mapEventIterator(iterator, maps) {
5
+ const mapError = async (error) => {
6
+ let mappedError = await maps.error(error);
7
+ if (mappedError !== error) {
8
+ const meta = getEventMeta(error);
9
+ if (meta && isTypescriptObject(mappedError)) {
10
+ mappedError = withEventMeta(mappedError, meta);
11
+ }
12
+ }
13
+ return mappedError;
14
+ };
15
+ return new AsyncIteratorClass(async () => {
16
+ const { done, value } = await (async () => {
17
+ try {
18
+ return await iterator.next();
19
+ } catch (error) {
20
+ throw await mapError(error);
21
+ }
22
+ })();
23
+ let mappedValue = await maps.value(value, done);
24
+ if (mappedValue !== value) {
25
+ const meta = getEventMeta(value);
26
+ if (meta && isTypescriptObject(mappedValue)) {
27
+ mappedValue = withEventMeta(mappedValue, meta);
28
+ }
29
+ }
30
+ return { done, value: mappedValue };
31
+ }, async () => {
32
+ try {
33
+ await iterator.return?.();
34
+ } catch (error) {
35
+ throw await mapError(error);
36
+ }
37
+ });
38
+ }
39
+
40
+ export { mapEventIterator as m };
@@ -0,0 +1,171 @@
1
+ import { resolveMaybeOptionalOptions, getConstructor, isObject } from '@orpc/shared';
2
+
3
+ const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client";
4
+ const ORPC_CLIENT_PACKAGE_VERSION = "0.0.0-next.50b03b7";
5
+
6
+ const COMMON_ORPC_ERROR_DEFS = {
7
+ BAD_REQUEST: {
8
+ status: 400,
9
+ message: "Bad Request"
10
+ },
11
+ UNAUTHORIZED: {
12
+ status: 401,
13
+ message: "Unauthorized"
14
+ },
15
+ FORBIDDEN: {
16
+ status: 403,
17
+ message: "Forbidden"
18
+ },
19
+ NOT_FOUND: {
20
+ status: 404,
21
+ message: "Not Found"
22
+ },
23
+ METHOD_NOT_SUPPORTED: {
24
+ status: 405,
25
+ message: "Method Not Supported"
26
+ },
27
+ NOT_ACCEPTABLE: {
28
+ status: 406,
29
+ message: "Not Acceptable"
30
+ },
31
+ TIMEOUT: {
32
+ status: 408,
33
+ message: "Request Timeout"
34
+ },
35
+ CONFLICT: {
36
+ status: 409,
37
+ message: "Conflict"
38
+ },
39
+ PRECONDITION_FAILED: {
40
+ status: 412,
41
+ message: "Precondition Failed"
42
+ },
43
+ PAYLOAD_TOO_LARGE: {
44
+ status: 413,
45
+ message: "Payload Too Large"
46
+ },
47
+ UNSUPPORTED_MEDIA_TYPE: {
48
+ status: 415,
49
+ message: "Unsupported Media Type"
50
+ },
51
+ UNPROCESSABLE_CONTENT: {
52
+ status: 422,
53
+ message: "Unprocessable Content"
54
+ },
55
+ TOO_MANY_REQUESTS: {
56
+ status: 429,
57
+ message: "Too Many Requests"
58
+ },
59
+ CLIENT_CLOSED_REQUEST: {
60
+ status: 499,
61
+ message: "Client Closed Request"
62
+ },
63
+ INTERNAL_SERVER_ERROR: {
64
+ status: 500,
65
+ message: "Internal Server Error"
66
+ },
67
+ NOT_IMPLEMENTED: {
68
+ status: 501,
69
+ message: "Not Implemented"
70
+ },
71
+ BAD_GATEWAY: {
72
+ status: 502,
73
+ message: "Bad Gateway"
74
+ },
75
+ SERVICE_UNAVAILABLE: {
76
+ status: 503,
77
+ message: "Service Unavailable"
78
+ },
79
+ GATEWAY_TIMEOUT: {
80
+ status: 504,
81
+ message: "Gateway Timeout"
82
+ }
83
+ };
84
+ function fallbackORPCErrorStatus(code, status) {
85
+ return status ?? COMMON_ORPC_ERROR_DEFS[code]?.status ?? 500;
86
+ }
87
+ function fallbackORPCErrorMessage(code, message) {
88
+ return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
89
+ }
90
+ const GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL = Symbol.for(`__${ORPC_CLIENT_PACKAGE_NAME}@${ORPC_CLIENT_PACKAGE_VERSION}/error/ORPC_ERROR_CONSTRUCTORS__`);
91
+ void (globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL] ??= /* @__PURE__ */ new WeakSet());
92
+ const globalORPCErrorConstructors = globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL];
93
+ class ORPCError extends Error {
94
+ defined;
95
+ code;
96
+ status;
97
+ data;
98
+ constructor(code, ...rest) {
99
+ const options = resolveMaybeOptionalOptions(rest);
100
+ if (options.status !== void 0 && !isORPCErrorStatus(options.status)) {
101
+ throw new Error("[ORPCError] Invalid error status code.");
102
+ }
103
+ const message = fallbackORPCErrorMessage(code, options.message);
104
+ super(message, options);
105
+ this.code = code;
106
+ this.status = fallbackORPCErrorStatus(code, options.status);
107
+ this.defined = options.defined ?? false;
108
+ this.data = options.data;
109
+ }
110
+ toJSON() {
111
+ return {
112
+ defined: this.defined,
113
+ code: this.code,
114
+ status: this.status,
115
+ message: this.message,
116
+ data: this.data
117
+ };
118
+ }
119
+ /**
120
+ * Workaround for Next.js where different contexts use separate
121
+ * dependency graphs, causing multiple ORPCError constructors existing and breaking
122
+ * `instanceof` checks across contexts.
123
+ *
124
+ * This is particularly problematic with "Optimized SSR", where orpc-client
125
+ * executes in one context but is invoked from another. When an error is thrown
126
+ * in the execution context, `instanceof ORPCError` checks fail in the
127
+ * invocation context due to separate class constructors.
128
+ *
129
+ * @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
130
+ */
131
+ static [Symbol.hasInstance](instance) {
132
+ if (globalORPCErrorConstructors.has(this)) {
133
+ const constructor = getConstructor(instance);
134
+ if (constructor && globalORPCErrorConstructors.has(constructor)) {
135
+ return true;
136
+ }
137
+ }
138
+ return super[Symbol.hasInstance](instance);
139
+ }
140
+ }
141
+ globalORPCErrorConstructors.add(ORPCError);
142
+ function isDefinedError(error) {
143
+ return error instanceof ORPCError && error.defined;
144
+ }
145
+ function toORPCError(error) {
146
+ return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", {
147
+ message: "Internal server error",
148
+ cause: error
149
+ });
150
+ }
151
+ function isORPCErrorStatus(status) {
152
+ return status < 200 || status >= 400;
153
+ }
154
+ function isORPCErrorJson(json) {
155
+ if (!isObject(json)) {
156
+ return false;
157
+ }
158
+ const validKeys = ["defined", "code", "status", "message", "data"];
159
+ if (Object.keys(json).some((k) => !validKeys.includes(k))) {
160
+ return false;
161
+ }
162
+ return "defined" in json && typeof json.defined === "boolean" && "code" in json && typeof json.code === "string" && "status" in json && typeof json.status === "number" && isORPCErrorStatus(json.status) && "message" in json && typeof json.message === "string";
163
+ }
164
+ function createORPCErrorFromJson(json, options = {}) {
165
+ return new ORPCError(json.code, {
166
+ ...options,
167
+ ...json
168
+ });
169
+ }
170
+
171
+ export { COMMON_ORPC_ERROR_DEFS as C, ORPC_CLIENT_PACKAGE_NAME as O, ORPC_CLIENT_PACKAGE_VERSION as a, fallbackORPCErrorMessage as b, ORPCError as c, isORPCErrorStatus as d, isORPCErrorJson as e, fallbackORPCErrorStatus as f, createORPCErrorFromJson as g, isDefinedError as i, toORPCError as t };
@@ -1,59 +1,79 @@
1
- import { intercept, isAsyncIteratorObject, value, isObject, trim, stringifyJSON } from '@orpc/shared';
2
- import { c as createAutoRetryEventIterator, O as ORPCError, m as mapEventIterator, t as toORPCError } from './client.XAn8cDTM.mjs';
3
- import { ErrorEvent } from '@orpc/standard-server';
1
+ import { toArray, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, intercept, getGlobalOtelConfig, isObject, value, stringifyJSON } from '@orpc/shared';
2
+ import { mergeStandardHeaders, ErrorEvent } from '@orpc/standard-server';
3
+ import { C as COMMON_ORPC_ERROR_DEFS, d as isORPCErrorStatus, e as isORPCErrorJson, g as createORPCErrorFromJson, c as ORPCError, t as toORPCError } from './client.B_sF8lzC.mjs';
4
+ import { toStandardHeaders as toStandardHeaders$1 } from '@orpc/standard-server-fetch';
5
+ import { m as mapEventIterator } from './client.BLtwTQUg.mjs';
4
6
 
5
- class InvalidEventIteratorRetryResponse extends Error {
7
+ class CompositeStandardLinkPlugin {
8
+ plugins;
9
+ constructor(plugins = []) {
10
+ this.plugins = [...plugins].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
11
+ }
12
+ init(options) {
13
+ for (const plugin of this.plugins) {
14
+ plugin.init?.(options);
15
+ }
16
+ }
6
17
  }
18
+
7
19
  class StandardLink {
8
- constructor(codec, sender, options) {
20
+ constructor(codec, sender, options = {}) {
9
21
  this.codec = codec;
10
22
  this.sender = sender;
11
- this.eventIteratorMaxRetries = options.eventIteratorMaxRetries ?? 5;
12
- this.eventIteratorRetryDelay = options.eventIteratorRetryDelay ?? ((o) => o.lastRetry ?? 1e3 * 2 ** o.retryTimes);
13
- this.eventIteratorShouldRetry = options.eventIteratorShouldRetry ?? true;
14
- this.interceptors = options.interceptors ?? [];
15
- this.clientInterceptors = options.clientInterceptors ?? [];
23
+ const plugin = new CompositeStandardLinkPlugin(options.plugins);
24
+ plugin.init(options);
25
+ this.interceptors = toArray(options.interceptors);
26
+ this.clientInterceptors = toArray(options.clientInterceptors);
16
27
  }
17
- eventIteratorMaxRetries;
18
- eventIteratorRetryDelay;
19
- eventIteratorShouldRetry;
20
28
  interceptors;
21
29
  clientInterceptors;
22
30
  call(path, input, options) {
23
- return intercept(this.interceptors, { path, input, options }, async ({ path: path2, input: input2, options: options2 }) => {
24
- const output = await this.#call(path2, input2, options2);
25
- if (!isAsyncIteratorObject(output)) {
26
- return output;
27
- }
28
- return createAutoRetryEventIterator(output, async (reconnectOptions) => {
29
- const maxRetries = await value(this.eventIteratorMaxRetries, reconnectOptions, options2, path2, input2);
30
- if (options2.signal?.aborted || reconnectOptions.retryTimes > maxRetries) {
31
- return null;
32
- }
33
- const shouldRetry = await value(this.eventIteratorShouldRetry, reconnectOptions, options2, path2, input2);
34
- if (!shouldRetry) {
35
- return null;
31
+ return runWithSpan(
32
+ { name: `${ORPC_NAME}.${path.join("/")}`, signal: options.signal },
33
+ (span) => {
34
+ span?.setAttribute("rpc.system", ORPC_NAME);
35
+ span?.setAttribute("rpc.method", path.join("."));
36
+ if (isAsyncIteratorObject(input)) {
37
+ input = asyncIteratorWithSpan(
38
+ { name: "consume_event_iterator_input", signal: options.signal },
39
+ input
40
+ );
36
41
  }
37
- const retryDelay = await value(this.eventIteratorRetryDelay, reconnectOptions, options2, path2, input2);
38
- await new Promise((resolve) => setTimeout(resolve, retryDelay));
39
- const updatedOptions = { ...options2, lastEventId: reconnectOptions.lastEventId };
40
- const maybeIterator = await this.#call(path2, input2, updatedOptions);
41
- if (!isAsyncIteratorObject(maybeIterator)) {
42
- throw new InvalidEventIteratorRetryResponse("Invalid Event Iterator retry response");
43
- }
44
- return maybeIterator;
45
- }, options2.lastEventId);
46
- });
47
- }
48
- async #call(path, input, options) {
49
- const request = await this.codec.encode(path, input, options);
50
- const response = await intercept(
51
- this.clientInterceptors,
52
- { request },
53
- ({ request: request2 }) => this.sender.call(request2, options, path, input)
42
+ return intercept(this.interceptors, { ...options, path, input }, async ({ path: path2, input: input2, ...options2 }) => {
43
+ const otelConfig = getGlobalOtelConfig();
44
+ let otelContext;
45
+ const currentSpan = otelConfig?.trace.getActiveSpan() ?? span;
46
+ if (currentSpan && otelConfig) {
47
+ otelContext = otelConfig?.trace.setSpan(otelConfig.context.active(), currentSpan);
48
+ }
49
+ const request = await runWithSpan(
50
+ { name: "encode_request", context: otelContext },
51
+ () => this.codec.encode(path2, input2, options2)
52
+ );
53
+ const response = await intercept(
54
+ this.clientInterceptors,
55
+ { ...options2, input: input2, path: path2, request },
56
+ ({ input: input3, path: path3, request: request2, ...options3 }) => {
57
+ return runWithSpan(
58
+ { name: "send_request", signal: options3.signal, context: otelContext },
59
+ () => this.sender.call(request2, options3, path3, input3)
60
+ );
61
+ }
62
+ );
63
+ const output = await runWithSpan(
64
+ { name: "decode_response", context: otelContext },
65
+ () => this.codec.decode(response, options2, path2, input2)
66
+ );
67
+ if (isAsyncIteratorObject(output)) {
68
+ return asyncIteratorWithSpan(
69
+ { name: "consume_event_iterator_output", signal: options2.signal },
70
+ output
71
+ );
72
+ }
73
+ return output;
74
+ });
75
+ }
54
76
  );
55
- const output = await this.codec.decode(response, options, path, input);
56
- return output;
57
77
  }
58
78
  }
59
79
 
@@ -134,6 +154,9 @@ class StandardRPCJsonSerializer {
134
154
  if (isObject(data)) {
135
155
  const json = {};
136
156
  for (const k in data) {
157
+ if (k === "toJSON" && typeof data[k] === "function") {
158
+ continue;
159
+ }
137
160
  json[k] = this.serialize(data[k], [...segments, k], meta, maps, blobs)[0];
138
161
  }
139
162
  return [json, meta, maps, blobs];
@@ -200,6 +223,19 @@ class StandardRPCJsonSerializer {
200
223
  }
201
224
  }
202
225
 
226
+ function toHttpPath(path) {
227
+ return `/${path.map(encodeURIComponent).join("/")}`;
228
+ }
229
+ function toStandardHeaders(headers) {
230
+ if (typeof headers.forEach === "function") {
231
+ return toStandardHeaders$1(headers);
232
+ }
233
+ return headers;
234
+ }
235
+ function getMalformedResponseErrorCode(status) {
236
+ return Object.entries(COMMON_ORPC_ERROR_DEFS).find(([, def]) => def.status === status)?.[0] ?? "MALFORMED_ORPC_ERROR_RESPONSE";
237
+ }
238
+
203
239
  class StandardRPCLinkCodec {
204
240
  constructor(serializer, options) {
205
241
  this.serializer = serializer;
@@ -215,15 +251,19 @@ class StandardRPCLinkCodec {
215
251
  expectedMethod;
216
252
  headers;
217
253
  async encode(path, input, options) {
254
+ let headers = toStandardHeaders(await value(this.headers, options, path, input));
255
+ if (options.lastEventId !== void 0) {
256
+ headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
257
+ }
218
258
  const expectedMethod = await value(this.expectedMethod, options, path, input);
219
- const headers = await value(this.headers, options, path, input);
220
259
  const baseUrl = await value(this.baseUrl, options, path, input);
221
- const url = new URL(`${trim(baseUrl.toString(), "/")}/${path.map(encodeURIComponent).join("/")}`);
260
+ const url = new URL(baseUrl);
261
+ url.pathname = `${url.pathname.replace(/\/$/, "")}${toHttpPath(path)}`;
222
262
  const serialized = this.serializer.serialize(input);
223
- if (expectedMethod === "GET" && !(serialized instanceof FormData) && !(serialized instanceof Blob) && !isAsyncIteratorObject(serialized)) {
263
+ if (expectedMethod === "GET" && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) {
224
264
  const maxUrlLength = await value(this.maxUrlLength, options, path, input);
225
265
  const getUrl = new URL(url);
226
- getUrl.searchParams.append("data", stringifyJSON(serialized) ?? "");
266
+ getUrl.searchParams.append("data", stringifyJSON(serialized));
227
267
  if (getUrl.toString().length <= maxUrlLength) {
228
268
  return {
229
269
  body: void 0,
@@ -243,7 +283,7 @@ class StandardRPCLinkCodec {
243
283
  };
244
284
  }
245
285
  async decode(response) {
246
- const isOk = response.status >= 200 && response.status < 300;
286
+ const isOk = !isORPCErrorStatus(response.status);
247
287
  const deserialized = await (async () => {
248
288
  let isBodyOk = false;
249
289
  try {
@@ -262,11 +302,12 @@ class StandardRPCLinkCodec {
262
302
  }
263
303
  })();
264
304
  if (!isOk) {
265
- if (ORPCError.isValidJSON(deserialized)) {
266
- throw ORPCError.fromJSON(deserialized);
305
+ if (isORPCErrorJson(deserialized)) {
306
+ throw createORPCErrorFromJson(deserialized);
267
307
  }
268
- throw new Error("Invalid RPC error response format.", {
269
- cause: deserialized
308
+ throw new ORPCError(getMalformedResponseErrorCode(response.status), {
309
+ status: response.status,
310
+ data: { ...response, body: deserialized }
270
311
  });
271
312
  }
272
313
  return deserialized;
@@ -292,9 +333,6 @@ class StandardRPCSerializer {
292
333
  return this.#serialize(data, true);
293
334
  }
294
335
  #serialize(data, enableFormData) {
295
- if (data === void 0 || data instanceof Blob) {
296
- return data;
297
- }
298
336
  const [json, meta_, maps, blobs] = this.jsonSerializer.serialize(data);
299
337
  const meta = meta_.length === 0 ? void 0 : meta_;
300
338
  if (!enableFormData || blobs.length === 0) {
@@ -319,8 +357,8 @@ class StandardRPCSerializer {
319
357
  return e;
320
358
  }
321
359
  const deserialized = this.#deserialize(e.data);
322
- if (ORPCError.isValidJSON(deserialized)) {
323
- return ORPCError.fromJSON(deserialized, { cause: e });
360
+ if (isORPCErrorJson(deserialized)) {
361
+ return createORPCErrorFromJson(deserialized, { cause: e });
324
362
  }
325
363
  return new ErrorEvent({
326
364
  data: deserialized,
@@ -332,8 +370,8 @@ class StandardRPCSerializer {
332
370
  return this.#deserialize(data);
333
371
  }
334
372
  #deserialize(data) {
335
- if (data === void 0 || data instanceof Blob) {
336
- return data;
373
+ if (data === void 0) {
374
+ return void 0;
337
375
  }
338
376
  if (!(data instanceof FormData)) {
339
377
  return this.jsonSerializer.deserialize(data.json, data.meta ?? []);
@@ -348,4 +386,13 @@ class StandardRPCSerializer {
348
386
  }
349
387
  }
350
388
 
351
- export { InvalidEventIteratorRetryResponse as I, StandardLink as S, STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as a, StandardRPCJsonSerializer as b, StandardRPCLinkCodec as c, StandardRPCSerializer as d };
389
+ class StandardRPCLink extends StandardLink {
390
+ constructor(linkClient, options) {
391
+ const jsonSerializer = new StandardRPCJsonSerializer(options);
392
+ const serializer = new StandardRPCSerializer(jsonSerializer);
393
+ const linkCodec = new StandardRPCLinkCodec(serializer, options);
394
+ super(linkCodec, linkClient, options);
395
+ }
396
+ }
397
+
398
+ export { CompositeStandardLinkPlugin as C, StandardLink as S, STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as a, StandardRPCJsonSerializer as b, StandardRPCLink as c, StandardRPCLinkCodec as d, StandardRPCSerializer as e, toStandardHeaders as f, getMalformedResponseErrorCode as g, toHttpPath as t };
@@ -0,0 +1,45 @@
1
+ import { Interceptor } from '@orpc/shared';
2
+ import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
3
+ import { b as ClientContext, c as ClientOptions, C as ClientLink } from './client.i2uoJbEp.mjs';
4
+
5
+ interface StandardLinkPlugin<T extends ClientContext> {
6
+ order?: number;
7
+ init?(options: StandardLinkOptions<T>): void;
8
+ }
9
+ declare class CompositeStandardLinkPlugin<T extends ClientContext, TPlugin extends StandardLinkPlugin<T>> implements StandardLinkPlugin<T> {
10
+ protected readonly plugins: TPlugin[];
11
+ constructor(plugins?: readonly TPlugin[]);
12
+ init(options: StandardLinkOptions<T>): void;
13
+ }
14
+
15
+ interface StandardLinkCodec<T extends ClientContext> {
16
+ encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
17
+ decode(response: StandardLazyResponse, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<unknown>;
18
+ }
19
+ interface StandardLinkClient<T extends ClientContext> {
20
+ call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
21
+ }
22
+
23
+ interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
24
+ path: readonly string[];
25
+ input: unknown;
26
+ }
27
+ interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> {
28
+ request: StandardRequest;
29
+ }
30
+ interface StandardLinkOptions<T extends ClientContext> {
31
+ interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>[];
32
+ clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, Promise<StandardLazyResponse>>[];
33
+ plugins?: StandardLinkPlugin<T>[];
34
+ }
35
+ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
36
+ readonly codec: StandardLinkCodec<T>;
37
+ readonly sender: StandardLinkClient<T>;
38
+ private readonly interceptors;
39
+ private readonly clientInterceptors;
40
+ constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
41
+ call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
42
+ }
43
+
44
+ export { CompositeStandardLinkPlugin as C, StandardLink as d };
45
+ export type { StandardLinkClientInterceptorOptions as S, StandardLinkPlugin as a, StandardLinkOptions as b, StandardLinkInterceptorOptions as c, StandardLinkCodec as e, StandardLinkClient as f };