@orpc/client 0.0.0-next.da92bc0 → 0.0.0-next.dbce934

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.
@@ -26,4 +26,4 @@ interface ClientLink<TClientContext extends ClientContext> {
26
26
  call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
27
27
  }
28
28
 
29
- export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientContext as a, ClientOptions as b, ClientPromiseResult as c, HTTPMethod as d, ClientRest as e, Client as f };
29
+ export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientPromiseResult as a, ClientContext as b, ClientOptions as c, Client as d, ClientRest as e, HTTPMethod as f };
@@ -1,6 +1,7 @@
1
- import { toArray, intercept, isObject, value, isAsyncIteratorObject, stringifyJSON } from '@orpc/shared';
1
+ import { toArray, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, intercept, getGlobalOtelConfig, isObject, value, stringifyJSON } from '@orpc/shared';
2
2
  import { mergeStandardHeaders, ErrorEvent } from '@orpc/standard-server';
3
- import { C as COMMON_ORPC_ERROR_DEFS, b as isORPCErrorStatus, c as isORPCErrorJson, d as createORPCErrorFromJson, O as ORPCError, m as mapEventIterator, t as toORPCError } from './client.DHOfWE0c.mjs';
3
+ import { C as COMMON_ORPC_ERROR_DEFS, d as isORPCErrorStatus, e as isORPCErrorJson, g as createORPCErrorFromJson, c as ORPCError, m as mapEventIterator, t as toORPCError } from './client.B0xwt6NP.mjs';
4
+ import { toStandardHeaders as toStandardHeaders$1 } from '@orpc/standard-server-fetch';
4
5
 
5
6
  class CompositeStandardLinkPlugin {
6
7
  plugins;
@@ -26,20 +27,52 @@ class StandardLink {
26
27
  interceptors;
27
28
  clientInterceptors;
28
29
  call(path, input, options) {
29
- return intercept(this.interceptors, { ...options, path, input }, async ({ path: path2, input: input2, ...options2 }) => {
30
- const output = await this.#call(path2, input2, options2);
31
- return output;
32
- });
33
- }
34
- async #call(path, input, options) {
35
- const request = await this.codec.encode(path, input, options);
36
- const response = await intercept(
37
- this.clientInterceptors,
38
- { ...options, input, path, request },
39
- ({ input: input2, path: path2, request: request2, ...options2 }) => this.sender.call(request2, options2, path2, input2)
30
+ return runWithSpan(
31
+ { name: `${ORPC_NAME}.${path.join("/")}`, signal: options.signal },
32
+ (span) => {
33
+ span?.setAttribute("rpc.system", ORPC_NAME);
34
+ span?.setAttribute("rpc.method", path.join("."));
35
+ if (isAsyncIteratorObject(input)) {
36
+ input = asyncIteratorWithSpan(
37
+ { name: "consume_event_iterator_input", signal: options.signal },
38
+ input
39
+ );
40
+ }
41
+ return intercept(this.interceptors, { ...options, path, input }, async ({ path: path2, input: input2, ...options2 }) => {
42
+ const otelConfig = getGlobalOtelConfig();
43
+ let otelContext;
44
+ const currentSpan = otelConfig?.trace.getActiveSpan() ?? span;
45
+ if (currentSpan && otelConfig) {
46
+ otelContext = otelConfig?.trace.setSpan(otelConfig.context.active(), currentSpan);
47
+ }
48
+ const request = await runWithSpan(
49
+ { name: "encode_request", context: otelContext },
50
+ () => this.codec.encode(path2, input2, options2)
51
+ );
52
+ const response = await intercept(
53
+ this.clientInterceptors,
54
+ { ...options2, input: input2, path: path2, request },
55
+ ({ input: input3, path: path3, request: request2, ...options3 }) => {
56
+ return runWithSpan(
57
+ { name: "send_request", signal: options3.signal, context: otelContext },
58
+ () => this.sender.call(request2, options3, path3, input3)
59
+ );
60
+ }
61
+ );
62
+ const output = await runWithSpan(
63
+ { name: "decode_response", context: otelContext },
64
+ () => this.codec.decode(response, options2, path2, input2)
65
+ );
66
+ if (isAsyncIteratorObject(output)) {
67
+ return asyncIteratorWithSpan(
68
+ { name: "consume_event_iterator_output", signal: options2.signal },
69
+ output
70
+ );
71
+ }
72
+ return output;
73
+ });
74
+ }
40
75
  );
41
- const output = await this.codec.decode(response, options, path, input);
42
- return output;
43
76
  }
44
77
  }
45
78
 
@@ -192,6 +225,12 @@ class StandardRPCJsonSerializer {
192
225
  function toHttpPath(path) {
193
226
  return `/${path.map(encodeURIComponent).join("/")}`;
194
227
  }
228
+ function toStandardHeaders(headers) {
229
+ if (typeof headers.forEach === "function") {
230
+ return toStandardHeaders$1(headers);
231
+ }
232
+ return headers;
233
+ }
195
234
  function getMalformedResponseErrorCode(status) {
196
235
  return Object.entries(COMMON_ORPC_ERROR_DEFS).find(([, def]) => def.status === status)?.[0] ?? "MALFORMED_ORPC_ERROR_RESPONSE";
197
236
  }
@@ -211,14 +250,14 @@ class StandardRPCLinkCodec {
211
250
  expectedMethod;
212
251
  headers;
213
252
  async encode(path, input, options) {
253
+ let headers = toStandardHeaders(await value(this.headers, options, path, input));
254
+ if (options.lastEventId !== void 0) {
255
+ headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
256
+ }
214
257
  const expectedMethod = await value(this.expectedMethod, options, path, input);
215
- let headers = await value(this.headers, options, path, input);
216
258
  const baseUrl = await value(this.baseUrl, options, path, input);
217
259
  const url = new URL(baseUrl);
218
260
  url.pathname = `${url.pathname.replace(/\/$/, "")}${toHttpPath(path)}`;
219
- if (options.lastEventId !== void 0) {
220
- headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
221
- }
222
261
  const serialized = this.serializer.serialize(input);
223
262
  if (expectedMethod === "GET" && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) {
224
263
  const maxUrlLength = await value(this.maxUrlLength, options, path, input);
@@ -330,6 +369,9 @@ class StandardRPCSerializer {
330
369
  return this.#deserialize(data);
331
370
  }
332
371
  #deserialize(data) {
372
+ if (data === void 0) {
373
+ return void 0;
374
+ }
333
375
  if (!(data instanceof FormData)) {
334
376
  return this.jsonSerializer.deserialize(data.json, data.meta ?? []);
335
377
  }
@@ -352,4 +394,4 @@ class StandardRPCLink extends StandardLink {
352
394
  }
353
395
  }
354
396
 
355
- 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, getMalformedResponseErrorCode as g, toHttpPath as t };
397
+ 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 };
@@ -1,6 +1,6 @@
1
1
  import { Interceptor } 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.4TS_0JaO.mjs';
3
+ import { b as ClientContext, c as ClientOptions, C as ClientLink } from './client.BOYsZIRq.mjs';
4
4
 
5
5
  interface StandardLinkPlugin<T extends ClientContext> {
6
6
  order?: number;
@@ -33,7 +33,6 @@ interface StandardLinkOptions<T extends ClientContext> {
33
33
  plugins?: StandardLinkPlugin<T>[];
34
34
  }
35
35
  declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
36
- #private;
37
36
  readonly codec: StandardLinkCodec<T>;
38
37
  readonly sender: StandardLinkClient<T>;
39
38
  private readonly interceptors;
@@ -1,5 +1,5 @@
1
- import { a as ClientContext, b as ClientOptions, d as HTTPMethod } from './client.4TS_0JaO.js';
2
- import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.C0KbSWlC.js';
1
+ import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.BOYsZIRq.js';
2
+ import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.BG98rYdO.js';
3
3
  import { Segment, Value, Promisable } from '@orpc/shared';
4
4
  import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
5
5
 
@@ -67,7 +67,7 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
67
67
  /**
68
68
  * Inject headers to the request.
69
69
  */
70
- headers?: Value<Promisable<StandardHeaders>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
70
+ headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
71
71
  }
72
72
  declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
73
73
  private readonly serializer;
@@ -1,5 +1,5 @@
1
- import { a as ClientContext, b as ClientOptions, d as HTTPMethod } from './client.4TS_0JaO.mjs';
2
- import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.BMoG_EdN.mjs';
1
+ import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.BOYsZIRq.mjs';
2
+ import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.Bwgm6dgk.mjs';
3
3
  import { Segment, Value, Promisable } from '@orpc/shared';
4
4
  import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
5
5
 
@@ -67,7 +67,7 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
67
67
  /**
68
68
  * Inject headers to the request.
69
69
  */
70
- headers?: Value<Promisable<StandardHeaders>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
70
+ headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
71
71
  }
72
72
  declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
73
73
  private readonly serializer;
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.da92bc0",
4
+ "version": "0.0.0-next.dbce934",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -49,13 +49,13 @@
49
49
  "dist"
50
50
  ],
51
51
  "dependencies": {
52
- "@orpc/shared": "0.0.0-next.da92bc0",
53
- "@orpc/standard-server": "0.0.0-next.da92bc0",
54
- "@orpc/standard-server-peer": "0.0.0-next.da92bc0",
55
- "@orpc/standard-server-fetch": "0.0.0-next.da92bc0"
52
+ "@orpc/standard-server": "0.0.0-next.dbce934",
53
+ "@orpc/shared": "0.0.0-next.dbce934",
54
+ "@orpc/standard-server-peer": "0.0.0-next.dbce934",
55
+ "@orpc/standard-server-fetch": "0.0.0-next.dbce934"
56
56
  },
57
57
  "devDependencies": {
58
- "zod": "^3.25.76"
58
+ "zod": "^4.1.5"
59
59
  },
60
60
  "scripts": {
61
61
  "build": "unbuild",