@orpc/client 0.0.0-next.f81b4a2 → 0.0.0-next.f9e0a4c

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.
@@ -1,6 +1,6 @@
1
- import { Interceptor, ThrowableError } from '@orpc/shared';
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.CipPQkhk.js';
3
+ import { b as ClientContext, c as ClientOptions, C as ClientLink } from './client.BOYsZIRq.js';
4
4
 
5
5
  interface StandardLinkPlugin<T extends ClientContext> {
6
6
  order?: number;
@@ -28,12 +28,11 @@ interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends
28
28
  request: StandardRequest;
29
29
  }
30
30
  interface StandardLinkOptions<T extends ClientContext> {
31
- interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, unknown, ThrowableError>[];
32
- clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, StandardLazyResponse, ThrowableError>[];
31
+ interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>[];
32
+ clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, Promise<StandardLazyResponse>>[];
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,7 +1,7 @@
1
1
  import { PromiseWithError } from '@orpc/shared';
2
2
 
3
3
  type HTTPPath = `/${string}`;
4
- type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
4
+ type HTTPMethod = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
5
5
  type ClientContext = Record<PropertyKey, any>;
6
6
  interface ClientOptions<T extends ClientContext> {
7
7
  signal?: AbortSignal;
@@ -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,7 +1,7 @@
1
1
  import { PromiseWithError } from '@orpc/shared';
2
2
 
3
3
  type HTTPPath = `/${string}`;
4
- type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
4
+ type HTTPMethod = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
5
5
  type ClientContext = Record<PropertyKey, any>;
6
6
  interface ClientOptions<T extends ClientContext> {
7
7
  signal?: AbortSignal;
@@ -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,6 @@
1
- import { Interceptor, ThrowableError } from '@orpc/shared';
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.CipPQkhk.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;
@@ -28,12 +28,11 @@ interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends
28
28
  request: StandardRequest;
29
29
  }
30
30
  interface StandardLinkOptions<T extends ClientContext> {
31
- interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, unknown, ThrowableError>[];
32
- clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, StandardLazyResponse, ThrowableError>[];
31
+ interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>[];
32
+ clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, Promise<StandardLazyResponse>>[];
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,6 +1,6 @@
1
- import { a as ClientContext, b as ClientOptions, d as HTTPMethod } from './client.CipPQkhk.js';
2
- import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.C9U9n1f3.js';
3
- import { Segment, Value } from '@orpc/shared';
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
+ import { Segment, Value, Promisable } from '@orpc/shared';
4
4
  import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
5
5
 
6
6
  declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
@@ -44,30 +44,30 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
44
44
  /**
45
45
  * Base url for all requests.
46
46
  */
47
- url: Value<string | URL, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
47
+ url: Value<Promisable<string | URL>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
48
48
  /**
49
49
  * The maximum length of the URL.
50
50
  *
51
51
  * @default 2083
52
52
  */
53
- maxUrlLength?: Value<number, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
53
+ maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
54
54
  /**
55
55
  * The method used to make the request.
56
56
  *
57
57
  * @default 'POST'
58
58
  */
59
- method?: Value<HTTPMethod, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
59
+ method?: Value<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
60
60
  /**
61
61
  * The method to use when the payload cannot safely pass to the server with method return from method function.
62
62
  * GET is not allowed, it's very dangerous.
63
63
  *
64
64
  * @default 'POST'
65
65
  */
66
- fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
66
+ fallbackMethod?: Exclude<HTTPMethod, 'HEAD' | 'GET'>;
67
67
  /**
68
68
  * Inject headers to the request.
69
69
  */
70
- headers?: Value<StandardHeaders, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
70
+ headers?: Value<Promisable<StandardHeaders>, [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,6 +1,6 @@
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.CRWEpqLB.mjs';
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.txdq_i5V.mjs';
4
4
 
5
5
  class CompositeStandardLinkPlugin {
6
6
  plugins;
@@ -26,20 +26,52 @@ class StandardLink {
26
26
  interceptors;
27
27
  clientInterceptors;
28
28
  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)
29
+ return runWithSpan(
30
+ { name: `${ORPC_NAME}.${path.join("/")}`, signal: options.signal },
31
+ (span) => {
32
+ span?.setAttribute("rpc.system", ORPC_NAME);
33
+ span?.setAttribute("rpc.method", path.join("."));
34
+ if (isAsyncIteratorObject(input)) {
35
+ input = asyncIteratorWithSpan(
36
+ { name: "consume_event_iterator_input", signal: options.signal },
37
+ input
38
+ );
39
+ }
40
+ return intercept(this.interceptors, { ...options, path, input }, async ({ path: path2, input: input2, ...options2 }) => {
41
+ const otelConfig = getGlobalOtelConfig();
42
+ let otelContext;
43
+ const currentSpan = otelConfig?.trace.getActiveSpan() ?? span;
44
+ if (currentSpan && otelConfig) {
45
+ otelContext = otelConfig?.trace.setSpan(otelConfig.context.active(), currentSpan);
46
+ }
47
+ const request = await runWithSpan(
48
+ { name: "encode_request", context: otelContext },
49
+ () => this.codec.encode(path2, input2, options2)
50
+ );
51
+ const response = await intercept(
52
+ this.clientInterceptors,
53
+ { ...options2, input: input2, path: path2, request },
54
+ ({ input: input3, path: path3, request: request2, ...options3 }) => {
55
+ return runWithSpan(
56
+ { name: "send_request", signal: options3.signal, context: otelContext },
57
+ () => this.sender.call(request2, options3, path3, input3)
58
+ );
59
+ }
60
+ );
61
+ const output = await runWithSpan(
62
+ { name: "decode_response", context: otelContext },
63
+ () => this.codec.decode(response, options2, path2, input2)
64
+ );
65
+ if (isAsyncIteratorObject(output)) {
66
+ return asyncIteratorWithSpan(
67
+ { name: "consume_event_iterator_output", signal: options2.signal },
68
+ output
69
+ );
70
+ }
71
+ return output;
72
+ });
73
+ }
40
74
  );
41
- const output = await this.codec.decode(response, options, path, input);
42
- return output;
43
75
  }
44
76
  }
45
77
 
@@ -330,6 +362,9 @@ class StandardRPCSerializer {
330
362
  return this.#deserialize(data);
331
363
  }
332
364
  #deserialize(data) {
365
+ if (data === void 0) {
366
+ return void 0;
367
+ }
333
368
  if (!(data instanceof FormData)) {
334
369
  return this.jsonSerializer.deserialize(data.json, data.meta ?? []);
335
370
  }
@@ -1,6 +1,6 @@
1
- import { a as ClientContext, b as ClientOptions, d as HTTPMethod } from './client.CipPQkhk.mjs';
2
- import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.FXep-a3a.mjs';
3
- import { Segment, Value } from '@orpc/shared';
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
+ import { Segment, Value, Promisable } from '@orpc/shared';
4
4
  import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
5
5
 
6
6
  declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
@@ -44,30 +44,30 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
44
44
  /**
45
45
  * Base url for all requests.
46
46
  */
47
- url: Value<string | URL, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
47
+ url: Value<Promisable<string | URL>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
48
48
  /**
49
49
  * The maximum length of the URL.
50
50
  *
51
51
  * @default 2083
52
52
  */
53
- maxUrlLength?: Value<number, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
53
+ maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
54
54
  /**
55
55
  * The method used to make the request.
56
56
  *
57
57
  * @default 'POST'
58
58
  */
59
- method?: Value<HTTPMethod, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
59
+ method?: Value<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
60
60
  /**
61
61
  * The method to use when the payload cannot safely pass to the server with method return from method function.
62
62
  * GET is not allowed, it's very dangerous.
63
63
  *
64
64
  * @default 'POST'
65
65
  */
66
- fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
66
+ fallbackMethod?: Exclude<HTTPMethod, 'HEAD' | 'GET'>;
67
67
  /**
68
68
  * Inject headers to the request.
69
69
  */
70
- headers?: Value<StandardHeaders, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
70
+ headers?: Value<Promisable<StandardHeaders>, [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,4 +1,4 @@
1
- import { isObject, isTypescriptObject } from '@orpc/shared';
1
+ import { resolveMaybeOptionalOptions, isObject, AsyncIteratorClass, isTypescriptObject } from '@orpc/shared';
2
2
  import { getEventMeta, withEventMeta } from '@orpc/standard-server';
3
3
 
4
4
  const COMMON_ORPC_ERROR_DEFS = {
@@ -90,16 +90,17 @@ class ORPCError extends Error {
90
90
  code;
91
91
  status;
92
92
  data;
93
- constructor(code, ...[options]) {
94
- if (options?.status && !isORPCErrorStatus(options.status)) {
93
+ constructor(code, ...rest) {
94
+ const options = resolveMaybeOptionalOptions(rest);
95
+ if (options.status !== void 0 && !isORPCErrorStatus(options.status)) {
95
96
  throw new Error("[ORPCError] Invalid error status code.");
96
97
  }
97
- const message = fallbackORPCErrorMessage(code, options?.message);
98
+ const message = fallbackORPCErrorMessage(code, options.message);
98
99
  super(message, options);
99
100
  this.code = code;
100
- this.status = fallbackORPCErrorStatus(code, options?.status);
101
- this.defined = options?.defined ?? false;
102
- this.data = options?.data;
101
+ this.status = fallbackORPCErrorStatus(code, options.status);
102
+ this.defined = options.defined ?? false;
103
+ this.data = options.data;
103
104
  }
104
105
  toJSON() {
105
106
  return {
@@ -141,35 +142,39 @@ function createORPCErrorFromJson(json, options = {}) {
141
142
  }
142
143
 
143
144
  function mapEventIterator(iterator, maps) {
144
- return async function* () {
145
- try {
146
- while (true) {
147
- const { done, value } = await iterator.next();
148
- let mappedValue = await maps.value(value, done);
149
- if (mappedValue !== value) {
150
- const meta = getEventMeta(value);
151
- if (meta && isTypescriptObject(mappedValue)) {
152
- mappedValue = withEventMeta(mappedValue, meta);
153
- }
154
- }
155
- if (done) {
156
- return mappedValue;
157
- }
158
- yield mappedValue;
145
+ const mapError = async (error) => {
146
+ let mappedError = await maps.error(error);
147
+ if (mappedError !== error) {
148
+ const meta = getEventMeta(error);
149
+ if (meta && isTypescriptObject(mappedError)) {
150
+ mappedError = withEventMeta(mappedError, meta);
159
151
  }
160
- } catch (error) {
161
- let mappedError = await maps.error(error);
162
- if (mappedError !== error) {
163
- const meta = getEventMeta(error);
164
- if (meta && isTypescriptObject(mappedError)) {
165
- mappedError = withEventMeta(mappedError, meta);
166
- }
152
+ }
153
+ return mappedError;
154
+ };
155
+ return new AsyncIteratorClass(async () => {
156
+ const { done, value } = await (async () => {
157
+ try {
158
+ return await iterator.next();
159
+ } catch (error) {
160
+ throw await mapError(error);
161
+ }
162
+ })();
163
+ let mappedValue = await maps.value(value, done);
164
+ if (mappedValue !== value) {
165
+ const meta = getEventMeta(value);
166
+ if (meta && isTypescriptObject(mappedValue)) {
167
+ mappedValue = withEventMeta(mappedValue, meta);
167
168
  }
168
- throw mappedError;
169
- } finally {
169
+ }
170
+ return { done, value: mappedValue };
171
+ }, async () => {
172
+ try {
170
173
  await iterator.return?.();
174
+ } catch (error) {
175
+ throw await mapError(error);
171
176
  }
172
- }();
177
+ });
173
178
  }
174
179
 
175
180
  export { COMMON_ORPC_ERROR_DEFS as C, ORPCError as O, fallbackORPCErrorMessage as a, isORPCErrorStatus as b, isORPCErrorJson as c, createORPCErrorFromJson as d, fallbackORPCErrorStatus as f, isDefinedError as i, mapEventIterator as m, toORPCError as t };
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.f81b4a2",
4
+ "version": "0.0.0-next.f9e0a4c",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -33,18 +33,29 @@
33
33
  "types": "./dist/adapters/fetch/index.d.mts",
34
34
  "import": "./dist/adapters/fetch/index.mjs",
35
35
  "default": "./dist/adapters/fetch/index.mjs"
36
+ },
37
+ "./websocket": {
38
+ "types": "./dist/adapters/websocket/index.d.mts",
39
+ "import": "./dist/adapters/websocket/index.mjs",
40
+ "default": "./dist/adapters/websocket/index.mjs"
41
+ },
42
+ "./message-port": {
43
+ "types": "./dist/adapters/message-port/index.d.mts",
44
+ "import": "./dist/adapters/message-port/index.mjs",
45
+ "default": "./dist/adapters/message-port/index.mjs"
36
46
  }
37
47
  },
38
48
  "files": [
39
49
  "dist"
40
50
  ],
41
51
  "dependencies": {
42
- "@orpc/standard-server": "0.0.0-next.f81b4a2",
43
- "@orpc/shared": "0.0.0-next.f81b4a2",
44
- "@orpc/standard-server-fetch": "0.0.0-next.f81b4a2"
52
+ "@orpc/standard-server-fetch": "0.0.0-next.f9e0a4c",
53
+ "@orpc/standard-server-peer": "0.0.0-next.f9e0a4c",
54
+ "@orpc/standard-server": "0.0.0-next.f9e0a4c",
55
+ "@orpc/shared": "0.0.0-next.f9e0a4c"
45
56
  },
46
57
  "devDependencies": {
47
- "zod": "^3.24.2"
58
+ "zod": "^4.0.17"
48
59
  },
49
60
  "scripts": {
50
61
  "build": "unbuild",