@orpc/client 0.46.0 → 0.47.0

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,7 +1,7 @@
1
- import { C as ClientContext, a as ClientOptionsOut, b as ClientLink } from '../../shared/client.D_CzLDyB.mjs';
2
- import { StandardLinkClient, StandardLinkOptions, StandardRPCLinkCodecOptions, StandardRPCLinkCodec } from '../standard/index.mjs';
3
1
  import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
4
2
  import { ToFetchRequestOptions } from '@orpc/standard-server-fetch';
3
+ import { C as ClientContext, a as ClientOptionsOut, b as ClientLink } from '../../shared/client.D_CzLDyB.mjs';
4
+ import { StandardLinkClient, StandardLinkOptions, StandardRPCLinkCodecOptions } from '../standard/index.mjs';
5
5
  import '@orpc/shared';
6
6
 
7
7
  interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
@@ -15,8 +15,6 @@ declare class LinkFetchClient<T extends ClientContext> implements StandardLinkCl
15
15
  }
16
16
 
17
17
  interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, LinkFetchClientOptions<T> {
18
- linkCodec?: StandardRPCLinkCodec<T>;
19
- linkClient?: LinkFetchClient<T>;
20
18
  }
21
19
  declare class RPCLink<T extends ClientContext> implements ClientLink<T> {
22
20
  private readonly standardLink;
@@ -28,4 +26,4 @@ interface FetchWithContext<TClientContext extends ClientContext> {
28
26
  (url: URL, init: RequestInit, options: ClientOptionsOut<TClientContext>, path: readonly string[], input: unknown): Promise<Response>;
29
27
  }
30
28
 
31
- export { type FetchWithContext, RPCLink, type RPCLinkOptions };
29
+ export { type FetchWithContext, LinkFetchClient, type LinkFetchClientOptions, RPCLink, type RPCLinkOptions };
@@ -1,7 +1,7 @@
1
- import { C as ClientContext, a as ClientOptionsOut, b as ClientLink } from '../../shared/client.D_CzLDyB.js';
2
- import { StandardLinkClient, StandardLinkOptions, StandardRPCLinkCodecOptions, StandardRPCLinkCodec } from '../standard/index.js';
3
1
  import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
4
2
  import { ToFetchRequestOptions } from '@orpc/standard-server-fetch';
3
+ import { C as ClientContext, a as ClientOptionsOut, b as ClientLink } from '../../shared/client.D_CzLDyB.js';
4
+ import { StandardLinkClient, StandardLinkOptions, StandardRPCLinkCodecOptions } from '../standard/index.js';
5
5
  import '@orpc/shared';
6
6
 
7
7
  interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
@@ -15,8 +15,6 @@ declare class LinkFetchClient<T extends ClientContext> implements StandardLinkCl
15
15
  }
16
16
 
17
17
  interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, LinkFetchClientOptions<T> {
18
- linkCodec?: StandardRPCLinkCodec<T>;
19
- linkClient?: LinkFetchClient<T>;
20
18
  }
21
19
  declare class RPCLink<T extends ClientContext> implements ClientLink<T> {
22
20
  private readonly standardLink;
@@ -28,4 +26,4 @@ interface FetchWithContext<TClientContext extends ClientContext> {
28
26
  (url: URL, init: RequestInit, options: ClientOptionsOut<TClientContext>, path: readonly string[], input: unknown): Promise<Response>;
29
27
  }
30
28
 
31
- export { type FetchWithContext, RPCLink, type RPCLinkOptions };
29
+ export { type FetchWithContext, LinkFetchClient, type LinkFetchClientOptions, RPCLink, type RPCLinkOptions };
@@ -1,8 +1,8 @@
1
- import { a as StandardRPCLinkCodec, S as StandardLink } from '../../shared/client.Ch8Gzz9n.mjs';
2
- import '@orpc/shared';
3
- import '@orpc/standard-server';
4
1
  import { toFetchRequest, toStandardLazyResponse } from '@orpc/standard-server-fetch';
2
+ import { a as StandardRPCLinkCodec, b as RPCSerializer, S as StandardLink } from '../../shared/client.BMw2gtvr.mjs';
3
+ import '@orpc/shared';
5
4
  import '../../shared/client.DcaJQZfy.mjs';
5
+ import '@orpc/standard-server';
6
6
 
7
7
  class LinkFetchClient {
8
8
  fetch;
@@ -22,8 +22,9 @@ class LinkFetchClient {
22
22
  class RPCLink {
23
23
  standardLink;
24
24
  constructor(options) {
25
- const linkCodec = options.linkCodec ?? new StandardRPCLinkCodec(options);
26
- const linkClient = options.linkClient ?? new LinkFetchClient(options);
25
+ const serializer = new RPCSerializer();
26
+ const linkCodec = new StandardRPCLinkCodec(serializer, options);
27
+ const linkClient = new LinkFetchClient(options);
27
28
  this.standardLink = new StandardLink(linkCodec, linkClient, options);
28
29
  }
29
30
  async call(path, input, options) {
@@ -31,4 +32,4 @@ class RPCLink {
31
32
  }
32
33
  }
33
34
 
34
- export { RPCLink };
35
+ export { LinkFetchClient, RPCLink };
@@ -132,16 +132,15 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
132
132
  path: readonly string[],
133
133
  input: unknown
134
134
  ]>;
135
- rpcSerializer?: RPCSerializer;
136
135
  }
137
136
  declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
137
+ private readonly serializer;
138
138
  private readonly baseUrl;
139
139
  private readonly maxUrlLength;
140
140
  private readonly fallbackMethod;
141
141
  private readonly expectedMethod;
142
142
  private readonly headers;
143
- private readonly rpcSerializer;
144
- constructor(options: StandardRPCLinkCodecOptions<T>);
143
+ constructor(serializer: RPCSerializer, options: StandardRPCLinkCodecOptions<T>);
145
144
  encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
146
145
  decode(response: StandardLazyResponse): Promise<unknown>;
147
146
  }
@@ -132,16 +132,15 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
132
132
  path: readonly string[],
133
133
  input: unknown
134
134
  ]>;
135
- rpcSerializer?: RPCSerializer;
136
135
  }
137
136
  declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
137
+ private readonly serializer;
138
138
  private readonly baseUrl;
139
139
  private readonly maxUrlLength;
140
140
  private readonly fallbackMethod;
141
141
  private readonly expectedMethod;
142
142
  private readonly headers;
143
- private readonly rpcSerializer;
144
- constructor(options: StandardRPCLinkCodecOptions<T>);
143
+ constructor(serializer: RPCSerializer, options: StandardRPCLinkCodecOptions<T>);
145
144
  encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
146
145
  decode(response: StandardLazyResponse): Promise<unknown>;
147
146
  }
@@ -1,4 +1,4 @@
1
- export { I as InvalidEventIteratorRetryResponse, R as RPCJsonSerializer, b as RPCSerializer, S as StandardLink, a as StandardRPCLinkCodec } from '../../shared/client.Ch8Gzz9n.mjs';
1
+ export { I as InvalidEventIteratorRetryResponse, R as RPCJsonSerializer, b as RPCSerializer, S as StandardLink, a as StandardRPCLinkCodec } from '../../shared/client.BMw2gtvr.mjs';
2
2
  import '@orpc/shared';
3
3
  import '../../shared/client.DcaJQZfy.mjs';
4
4
  import '@orpc/standard-server';
@@ -1,5 +1,5 @@
1
- import { intercept, isAsyncIteratorObject, value, isObject, stringifyJSON, trim } from '@orpc/shared';
2
- import { c as createAutoRetryEventIterator, m as mapEventIterator, t as toORPCError, O as ORPCError } from './client.DcaJQZfy.mjs';
1
+ import { intercept, isAsyncIteratorObject, value, isObject, trim, stringifyJSON } from '@orpc/shared';
2
+ import { c as createAutoRetryEventIterator, O as ORPCError, m as mapEventIterator, t as toORPCError } from './client.DcaJQZfy.mjs';
3
3
  import { ErrorEvent } from '@orpc/standard-server';
4
4
 
5
5
  class InvalidEventIteratorRetryResponse extends Error {
@@ -169,6 +169,79 @@ class RPCJsonSerializer {
169
169
  }
170
170
  }
171
171
 
172
+ class StandardRPCLinkCodec {
173
+ constructor(serializer, options) {
174
+ this.serializer = serializer;
175
+ this.baseUrl = options.url;
176
+ this.maxUrlLength = options.maxUrlLength ?? 2083;
177
+ this.fallbackMethod = options.fallbackMethod ?? "POST";
178
+ this.expectedMethod = options.method ?? this.fallbackMethod;
179
+ this.headers = options.headers ?? {};
180
+ }
181
+ baseUrl;
182
+ maxUrlLength;
183
+ fallbackMethod;
184
+ expectedMethod;
185
+ headers;
186
+ async encode(path, input, options) {
187
+ const expectedMethod = await value(this.expectedMethod, options, path, input);
188
+ const headers = await value(this.headers, options, path, input);
189
+ const baseUrl = await value(this.baseUrl, options, path, input);
190
+ const url = new URL(`${trim(baseUrl.toString(), "/")}/${path.map(encodeURIComponent).join("/")}`);
191
+ const serialized = this.serializer.serialize(input);
192
+ if (expectedMethod === "GET" && !(serialized instanceof FormData) && !(serialized instanceof Blob) && !isAsyncIteratorObject(serialized)) {
193
+ const maxUrlLength = await value(this.maxUrlLength, options, path, input);
194
+ const getUrl = new URL(url);
195
+ getUrl.searchParams.append("data", stringifyJSON(serialized) ?? "");
196
+ if (getUrl.toString().length <= maxUrlLength) {
197
+ return {
198
+ body: void 0,
199
+ method: expectedMethod,
200
+ headers,
201
+ url: getUrl,
202
+ signal: options.signal
203
+ };
204
+ }
205
+ }
206
+ return {
207
+ url,
208
+ method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod,
209
+ headers,
210
+ body: serialized,
211
+ signal: options.signal
212
+ };
213
+ }
214
+ async decode(response) {
215
+ const isOk = response.status >= 200 && response.status < 300;
216
+ const deserialized = await (async () => {
217
+ let isBodyOk = false;
218
+ try {
219
+ const body = await response.body();
220
+ isBodyOk = true;
221
+ return this.serializer.deserialize(body);
222
+ } catch (error) {
223
+ if (!isBodyOk) {
224
+ throw new Error("Cannot parse response body, please check the response body and content-type.", {
225
+ cause: error
226
+ });
227
+ }
228
+ throw new Error("Invalid RPC response format.", {
229
+ cause: error
230
+ });
231
+ }
232
+ })();
233
+ if (!isOk) {
234
+ if (ORPCError.isValidJSON(deserialized)) {
235
+ throw ORPCError.fromJSON(deserialized);
236
+ }
237
+ throw new Error("Invalid RPC error response format.", {
238
+ cause: deserialized
239
+ });
240
+ }
241
+ return deserialized;
242
+ }
243
+ }
244
+
172
245
  class RPCSerializer {
173
246
  constructor(jsonSerializer = new RPCJsonSerializer()) {
174
247
  this.jsonSerializer = jsonSerializer;
@@ -244,78 +317,4 @@ class RPCSerializer {
244
317
  }
245
318
  }
246
319
 
247
- class StandardRPCLinkCodec {
248
- baseUrl;
249
- maxUrlLength;
250
- fallbackMethod;
251
- expectedMethod;
252
- headers;
253
- rpcSerializer;
254
- constructor(options) {
255
- this.baseUrl = options.url;
256
- this.maxUrlLength = options.maxUrlLength ?? 2083;
257
- this.fallbackMethod = options.fallbackMethod ?? "POST";
258
- this.expectedMethod = options.method ?? this.fallbackMethod;
259
- this.headers = options.headers ?? {};
260
- this.rpcSerializer = options.rpcSerializer ?? new RPCSerializer();
261
- }
262
- async encode(path, input, options) {
263
- const expectedMethod = await value(this.expectedMethod, options, path, input);
264
- const headers = await value(this.headers, options, path, input);
265
- const baseUrl = await value(this.baseUrl, options, path, input);
266
- const url = new URL(`${trim(baseUrl.toString(), "/")}/${path.map(encodeURIComponent).join("/")}`);
267
- const serialized = this.rpcSerializer.serialize(input);
268
- if (expectedMethod === "GET" && !(serialized instanceof FormData) && !(serialized instanceof Blob) && !isAsyncIteratorObject(serialized)) {
269
- const maxUrlLength = await value(this.maxUrlLength, options, path, input);
270
- const getUrl = new URL(url);
271
- getUrl.searchParams.append("data", stringifyJSON(serialized) ?? "");
272
- if (getUrl.toString().length <= maxUrlLength) {
273
- return {
274
- body: void 0,
275
- method: expectedMethod,
276
- headers,
277
- url: getUrl,
278
- signal: options.signal
279
- };
280
- }
281
- }
282
- return {
283
- url,
284
- method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod,
285
- headers,
286
- body: serialized,
287
- signal: options.signal
288
- };
289
- }
290
- async decode(response) {
291
- const isOk = response.status >= 200 && response.status < 300;
292
- const deserialized = await (async () => {
293
- let isBodyOk = false;
294
- try {
295
- const body = await response.body();
296
- isBodyOk = true;
297
- return this.rpcSerializer.deserialize(body);
298
- } catch (error) {
299
- if (!isBodyOk) {
300
- throw new Error("Cannot parse response body, please check the response body and content-type.", {
301
- cause: error
302
- });
303
- }
304
- throw new Error("Invalid RPC response format.", {
305
- cause: error
306
- });
307
- }
308
- })();
309
- if (!isOk) {
310
- if (ORPCError.isValidJSON(deserialized)) {
311
- throw ORPCError.fromJSON(deserialized);
312
- }
313
- throw new Error("Invalid RPC error response format.", {
314
- cause: deserialized
315
- });
316
- }
317
- return deserialized;
318
- }
319
- }
320
-
321
320
  export { InvalidEventIteratorRetryResponse as I, RPCJsonSerializer as R, StandardLink as S, StandardRPCLinkCodec as a, RPCSerializer as b };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/client",
3
3
  "type": "module",
4
- "version": "0.46.0",
4
+ "version": "0.47.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -34,12 +34,12 @@
34
34
  "dist"
35
35
  ],
36
36
  "dependencies": {
37
- "@orpc/shared": "0.46.0",
38
- "@orpc/standard-server-fetch": "0.46.0",
39
- "@orpc/standard-server": "0.46.0"
37
+ "@orpc/standard-server": "0.47.0",
38
+ "@orpc/shared": "0.47.0",
39
+ "@orpc/standard-server-fetch": "0.47.0"
40
40
  },
41
41
  "devDependencies": {
42
- "zod": "^3.24.1"
42
+ "zod": "^3.24.2"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "unbuild",