@orpc/client 0.0.0-next.fd13879 → 0.0.0-next.fd1ee2a

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,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,32 @@ 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);
145
+ return new AsyncIteratorClass(async () => {
146
+ const { done, value } = await (async () => {
147
+ try {
148
+ return await iterator.next();
149
+ } catch (error) {
150
+ let mappedError = await maps.error(error);
151
+ if (mappedError !== error) {
152
+ const meta = getEventMeta(error);
153
+ if (meta && isTypescriptObject(mappedError)) {
154
+ mappedError = withEventMeta(mappedError, meta);
153
155
  }
154
156
  }
155
- if (done) {
156
- return mappedValue;
157
- }
158
- yield mappedValue;
157
+ throw mappedError;
159
158
  }
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
- }
159
+ })();
160
+ let mappedValue = await maps.value(value, done);
161
+ if (mappedValue !== value) {
162
+ const meta = getEventMeta(value);
163
+ if (meta && isTypescriptObject(mappedValue)) {
164
+ mappedValue = withEventMeta(mappedValue, meta);
167
165
  }
168
- throw mappedError;
169
- } finally {
170
- await iterator.return?.();
171
166
  }
172
- }();
167
+ return { done, value: mappedValue };
168
+ }, async () => {
169
+ await iterator.return?.();
170
+ });
173
171
  }
174
172
 
175
173
  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 };
@@ -1,6 +1,6 @@
1
1
  import { toArray, intercept, isObject, value, isAsyncIteratorObject, 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.BngOL3Ai.mjs';
4
4
 
5
5
  class CompositeStandardLinkPlugin {
6
6
  plugins;
@@ -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.4TS_0JaO.js';
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,8 +28,8 @@ 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> {
@@ -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.4TS_0JaO.mjs';
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,8 +28,8 @@ 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> {
@@ -1,6 +1,6 @@
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.7ZYxJok_.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.CXXEPIbK.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,19 +44,19 @@ 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<Exclude<HTTPMethod, 'HEAD'>, [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.
@@ -67,7 +67,7 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
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 { 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.ds1abV85.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.C4VxIexA.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,19 +44,19 @@ 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<Exclude<HTTPMethod, 'HEAD'>, [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.
@@ -67,7 +67,7 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
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;
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.fd13879",
4
+ "version": "0.0.0-next.fd1ee2a",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -38,19 +38,24 @@
38
38
  "types": "./dist/adapters/websocket/index.d.mts",
39
39
  "import": "./dist/adapters/websocket/index.mjs",
40
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"
41
46
  }
42
47
  },
43
48
  "files": [
44
49
  "dist"
45
50
  ],
46
51
  "dependencies": {
47
- "@orpc/shared": "0.0.0-next.fd13879",
48
- "@orpc/standard-server-peer": "0.0.0-next.fd13879",
49
- "@orpc/standard-server-fetch": "0.0.0-next.fd13879",
50
- "@orpc/standard-server": "0.0.0-next.fd13879"
52
+ "@orpc/standard-server": "0.0.0-next.fd1ee2a",
53
+ "@orpc/standard-server-fetch": "0.0.0-next.fd1ee2a",
54
+ "@orpc/shared": "0.0.0-next.fd1ee2a",
55
+ "@orpc/standard-server-peer": "0.0.0-next.fd1ee2a"
51
56
  },
52
57
  "devDependencies": {
53
- "zod": "3.25.0-beta.20250516T005923"
58
+ "zod": "^4.0.5"
54
59
  },
55
60
  "scripts": {
56
61
  "build": "unbuild",