@orpc/client 0.0.0-next.df486d6 → 0.0.0-next.df70448

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 { 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 | 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,6 +1,9 @@
1
- import { isObject, isTypescriptObject } from '@orpc/shared';
1
+ import { resolveMaybeOptionalOptions, getConstructor, isObject, AsyncIteratorClass, isTypescriptObject } from '@orpc/shared';
2
2
  import { getEventMeta, withEventMeta } from '@orpc/standard-server';
3
3
 
4
+ const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client";
5
+ const ORPC_CLIENT_PACKAGE_VERSION = "0.0.0-next.df70448";
6
+
4
7
  const COMMON_ORPC_ERROR_DEFS = {
5
8
  BAD_REQUEST: {
6
9
  status: 400,
@@ -85,21 +88,25 @@ function fallbackORPCErrorStatus(code, status) {
85
88
  function fallbackORPCErrorMessage(code, message) {
86
89
  return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
87
90
  }
91
+ const GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL = Symbol.for(`__${ORPC_CLIENT_PACKAGE_NAME}@${ORPC_CLIENT_PACKAGE_VERSION}/error/ORPC_ERROR_CONSTRUCTORS__`);
92
+ void (globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL] ??= /* @__PURE__ */ new WeakSet());
93
+ const globalORPCErrorConstructors = globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL];
88
94
  class ORPCError extends Error {
89
95
  defined;
90
96
  code;
91
97
  status;
92
98
  data;
93
- constructor(code, ...[options]) {
94
- if (options?.status && !isORPCErrorStatus(options.status)) {
99
+ constructor(code, ...rest) {
100
+ const options = resolveMaybeOptionalOptions(rest);
101
+ if (options.status !== void 0 && !isORPCErrorStatus(options.status)) {
95
102
  throw new Error("[ORPCError] Invalid error status code.");
96
103
  }
97
- const message = fallbackORPCErrorMessage(code, options?.message);
104
+ const message = fallbackORPCErrorMessage(code, options.message);
98
105
  super(message, options);
99
106
  this.code = code;
100
- this.status = fallbackORPCErrorStatus(code, options?.status);
101
- this.defined = options?.defined ?? false;
102
- this.data = options?.data;
107
+ this.status = fallbackORPCErrorStatus(code, options.status);
108
+ this.defined = options.defined ?? false;
109
+ this.data = options.data;
103
110
  }
104
111
  toJSON() {
105
112
  return {
@@ -110,7 +117,29 @@ class ORPCError extends Error {
110
117
  data: this.data
111
118
  };
112
119
  }
120
+ /**
121
+ * Workaround for Next.js where different contexts use separate
122
+ * dependency graphs, causing multiple ORPCError constructors existing and breaking
123
+ * `instanceof` checks across contexts.
124
+ *
125
+ * This is particularly problematic with "Optimized SSR", where orpc-client
126
+ * executes in one context but is invoked from another. When an error is thrown
127
+ * in the execution context, `instanceof ORPCError` checks fail in the
128
+ * invocation context due to separate class constructors.
129
+ *
130
+ * @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
131
+ */
132
+ static [Symbol.hasInstance](instance) {
133
+ if (globalORPCErrorConstructors.has(this)) {
134
+ const constructor = getConstructor(instance);
135
+ if (constructor && globalORPCErrorConstructors.has(constructor)) {
136
+ return true;
137
+ }
138
+ }
139
+ return super[Symbol.hasInstance](instance);
140
+ }
113
141
  }
142
+ globalORPCErrorConstructors.add(ORPCError);
114
143
  function isDefinedError(error) {
115
144
  return error instanceof ORPCError && error.defined;
116
145
  }
@@ -141,35 +170,39 @@ function createORPCErrorFromJson(json, options = {}) {
141
170
  }
142
171
 
143
172
  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;
173
+ const mapError = async (error) => {
174
+ let mappedError = await maps.error(error);
175
+ if (mappedError !== error) {
176
+ const meta = getEventMeta(error);
177
+ if (meta && isTypescriptObject(mappedError)) {
178
+ mappedError = withEventMeta(mappedError, meta);
159
179
  }
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
- }
180
+ }
181
+ return mappedError;
182
+ };
183
+ return new AsyncIteratorClass(async () => {
184
+ const { done, value } = await (async () => {
185
+ try {
186
+ return await iterator.next();
187
+ } catch (error) {
188
+ throw await mapError(error);
189
+ }
190
+ })();
191
+ let mappedValue = await maps.value(value, done);
192
+ if (mappedValue !== value) {
193
+ const meta = getEventMeta(value);
194
+ if (meta && isTypescriptObject(mappedValue)) {
195
+ mappedValue = withEventMeta(mappedValue, meta);
167
196
  }
168
- throw mappedError;
169
- } finally {
197
+ }
198
+ return { done, value: mappedValue };
199
+ }, async () => {
200
+ try {
170
201
  await iterator.return?.();
202
+ } catch (error) {
203
+ throw await mapError(error);
171
204
  }
172
- }();
205
+ });
173
206
  }
174
207
 
175
- 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 };
208
+ 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, mapEventIterator as m, toORPCError as t };
@@ -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 | 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.df486d6",
4
+ "version": "0.0.0-next.df70448",
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/shared": "0.0.0-next.df486d6",
43
- "@orpc/standard-server-fetch": "0.0.0-next.df486d6",
44
- "@orpc/standard-server": "0.0.0-next.df486d6"
52
+ "@orpc/shared": "0.0.0-next.df70448",
53
+ "@orpc/standard-server-fetch": "0.0.0-next.df70448",
54
+ "@orpc/standard-server": "0.0.0-next.df70448",
55
+ "@orpc/standard-server-peer": "0.0.0-next.df70448"
45
56
  },
46
57
  "devDependencies": {
47
- "zod": "^3.24.2"
58
+ "zod": "^4.1.12"
48
59
  },
49
60
  "scripts": {
50
61
  "build": "unbuild",