@orpc/client 0.0.0-next.ec7d801 → 0.0.0-next.eccbaa4

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 (31) hide show
  1. package/README.md +7 -2
  2. package/dist/adapters/fetch/index.d.mts +23 -10
  3. package/dist/adapters/fetch/index.d.ts +23 -10
  4. package/dist/adapters/fetch/index.mjs +25 -8
  5. package/dist/adapters/message-port/index.d.mts +36 -15
  6. package/dist/adapters/message-port/index.d.ts +36 -15
  7. package/dist/adapters/message-port/index.mjs +30 -14
  8. package/dist/adapters/standard/index.d.mts +6 -5
  9. package/dist/adapters/standard/index.d.ts +6 -5
  10. package/dist/adapters/standard/index.mjs +4 -2
  11. package/dist/adapters/websocket/index.d.mts +11 -11
  12. package/dist/adapters/websocket/index.d.ts +11 -11
  13. package/dist/adapters/websocket/index.mjs +13 -10
  14. package/dist/index.d.mts +86 -25
  15. package/dist/index.d.ts +86 -25
  16. package/dist/index.mjs +54 -7
  17. package/dist/plugins/index.d.mts +52 -5
  18. package/dist/plugins/index.d.ts +52 -5
  19. package/dist/plugins/index.mjs +121 -25
  20. package/dist/shared/client.BH1AYT_p.d.mts +83 -0
  21. package/dist/shared/client.BH1AYT_p.d.ts +83 -0
  22. package/dist/shared/client.BLtwTQUg.mjs +40 -0
  23. package/dist/shared/{client.BX0_8bnM.mjs → client.BngW4e9E.mjs} +37 -38
  24. package/dist/shared/{client.7UM0t5o-.d.ts → client.BxV-mzeR.d.ts} +3 -3
  25. package/dist/shared/{client.C0KbSWlC.d.ts → client.CPgZaUox.d.mts} +1 -2
  26. package/dist/shared/{client.BdD8cpjs.d.mts → client.D8lMmWVC.d.mts} +3 -3
  27. package/dist/shared/{client.CQCGVpTM.mjs → client.DE877kpy.mjs} +63 -20
  28. package/dist/shared/{client.BMoG_EdN.d.mts → client.De8SW4Kw.d.ts} +1 -2
  29. package/package.json +6 -6
  30. package/dist/shared/client.4TS_0JaO.d.mts +0 -29
  31. package/dist/shared/client.4TS_0JaO.d.ts +0 -29
@@ -1,6 +1,8 @@
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.BX0_8bnM.mjs';
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.BngW4e9E.mjs';
4
+ import { toStandardHeaders as toStandardHeaders$1 } from '@orpc/standard-server-fetch';
5
+ import { m as mapEventIterator } from './client.BLtwTQUg.mjs';
4
6
 
5
7
  class CompositeStandardLinkPlugin {
6
8
  plugins;
@@ -26,20 +28,52 @@ class StandardLink {
26
28
  interceptors;
27
29
  clientInterceptors;
28
30
  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)
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
+ );
41
+ }
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
+ }
40
76
  );
41
- const output = await this.codec.decode(response, options, path, input);
42
- return output;
43
77
  }
44
78
  }
45
79
 
@@ -192,6 +226,12 @@ class StandardRPCJsonSerializer {
192
226
  function toHttpPath(path) {
193
227
  return `/${path.map(encodeURIComponent).join("/")}`;
194
228
  }
229
+ function toStandardHeaders(headers) {
230
+ if (typeof headers.forEach === "function") {
231
+ return toStandardHeaders$1(headers);
232
+ }
233
+ return headers;
234
+ }
195
235
  function getMalformedResponseErrorCode(status) {
196
236
  return Object.entries(COMMON_ORPC_ERROR_DEFS).find(([, def]) => def.status === status)?.[0] ?? "MALFORMED_ORPC_ERROR_RESPONSE";
197
237
  }
@@ -211,14 +251,14 @@ class StandardRPCLinkCodec {
211
251
  expectedMethod;
212
252
  headers;
213
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
+ }
214
258
  const expectedMethod = await value(this.expectedMethod, options, path, input);
215
- let headers = await value(this.headers, options, path, input);
216
259
  const baseUrl = await value(this.baseUrl, options, path, input);
217
260
  const url = new URL(baseUrl);
218
261
  url.pathname = `${url.pathname.replace(/\/$/, "")}${toHttpPath(path)}`;
219
- if (options.lastEventId !== void 0) {
220
- headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
221
- }
222
262
  const serialized = this.serializer.serialize(input);
223
263
  if (expectedMethod === "GET" && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) {
224
264
  const maxUrlLength = await value(this.maxUrlLength, options, path, input);
@@ -330,6 +370,9 @@ class StandardRPCSerializer {
330
370
  return this.#deserialize(data);
331
371
  }
332
372
  #deserialize(data) {
373
+ if (data === void 0) {
374
+ return void 0;
375
+ }
333
376
  if (!(data instanceof FormData)) {
334
377
  return this.jsonSerializer.deserialize(data.json, data.meta ?? []);
335
378
  }
@@ -352,4 +395,4 @@ class StandardRPCLink extends StandardLink {
352
395
  }
353
396
  }
354
397
 
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 };
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 };
@@ -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.BH1AYT_p.js';
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;
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.ec7d801",
4
+ "version": "0.0.0-next.eccbaa4",
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.ec7d801",
53
- "@orpc/standard-server": "0.0.0-next.ec7d801",
54
- "@orpc/standard-server-fetch": "0.0.0-next.ec7d801",
55
- "@orpc/standard-server-peer": "0.0.0-next.ec7d801"
52
+ "@orpc/shared": "0.0.0-next.eccbaa4",
53
+ "@orpc/standard-server": "0.0.0-next.eccbaa4",
54
+ "@orpc/standard-server-peer": "0.0.0-next.eccbaa4",
55
+ "@orpc/standard-server-fetch": "0.0.0-next.eccbaa4"
56
56
  },
57
57
  "devDependencies": {
58
- "zod": "^3.25.57"
58
+ "zod": "^4.1.12"
59
59
  },
60
60
  "scripts": {
61
61
  "build": "unbuild",
@@ -1,29 +0,0 @@
1
- import { PromiseWithError } from '@orpc/shared';
2
-
3
- type HTTPPath = `/${string}`;
4
- type HTTPMethod = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
5
- type ClientContext = Record<PropertyKey, any>;
6
- interface ClientOptions<T extends ClientContext> {
7
- signal?: AbortSignal;
8
- lastEventId?: string | undefined;
9
- context: T;
10
- }
11
- type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? {
12
- context?: T;
13
- } : {
14
- context: T;
15
- });
16
- type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
17
- type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
18
- interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
19
- (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
20
- }
21
- type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
22
- [k: string]: NestedClient<TClientContext>;
23
- };
24
- type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
25
- interface ClientLink<TClientContext extends ClientContext> {
26
- call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
27
- }
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 };
@@ -1,29 +0,0 @@
1
- import { PromiseWithError } from '@orpc/shared';
2
-
3
- type HTTPPath = `/${string}`;
4
- type HTTPMethod = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
5
- type ClientContext = Record<PropertyKey, any>;
6
- interface ClientOptions<T extends ClientContext> {
7
- signal?: AbortSignal;
8
- lastEventId?: string | undefined;
9
- context: T;
10
- }
11
- type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? {
12
- context?: T;
13
- } : {
14
- context: T;
15
- });
16
- type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
17
- type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
18
- interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
19
- (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
20
- }
21
- type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
22
- [k: string]: NestedClient<TClientContext>;
23
- };
24
- type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
25
- interface ClientLink<TClientContext extends ClientContext> {
26
- call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
27
- }
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 };