@orpc/client 2.0.0-beta.49 → 2.0.0-beta.50

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 (75) hide show
  1. package/dist/adapters/fetch/index.d.ts +3 -2
  2. package/dist/adapters/fetch/index.js +2 -2
  3. package/dist/adapters/fetch/rpc-link.d.ts +8 -8
  4. package/dist/adapters/fetch/rpc-link.js +16 -13
  5. package/dist/adapters/fetch/transport.d.ts +29 -31
  6. package/dist/adapters/fetch/transport.js +49 -63
  7. package/dist/adapters/message-port/index.d.ts +4 -3
  8. package/dist/adapters/message-port/index.js +3 -3
  9. package/dist/adapters/message-port/message-port.d.ts +13 -13
  10. package/dist/adapters/message-port/message-port.js +35 -53
  11. package/dist/adapters/message-port/rpc-link.d.ts +8 -8
  12. package/dist/adapters/message-port/rpc-link.js +17 -14
  13. package/dist/adapters/message-port/transport.d.ts +31 -34
  14. package/dist/adapters/message-port/transport.js +38 -52
  15. package/dist/adapters/standard/codec.d.ts +10 -10
  16. package/dist/adapters/standard/index.d.ts +6 -5
  17. package/dist/adapters/standard/index.js +2 -4
  18. package/dist/adapters/standard/link.d.ts +31 -31
  19. package/dist/adapters/standard/link.js +101 -85
  20. package/dist/adapters/standard/plugin.d.ts +25 -31
  21. package/dist/adapters/standard/plugin.js +14 -16
  22. package/dist/adapters/standard/rpc-link-codec.d.ts +53 -60
  23. package/dist/adapters/standard/rpc-link-codec.js +98 -102
  24. package/dist/adapters/standard/transport.d.ts +7 -7
  25. package/dist/adapters/websocket/index.d.ts +3 -2
  26. package/dist/adapters/websocket/index.js +2 -2
  27. package/dist/adapters/websocket/rpc-link.d.ts +8 -8
  28. package/dist/adapters/websocket/rpc-link.js +16 -13
  29. package/dist/adapters/websocket/transport.d.ts +101 -100
  30. package/dist/adapters/websocket/transport.js +102 -130
  31. package/dist/async-iterator-object.d.ts +2 -2
  32. package/dist/async-iterator-object.js +27 -28
  33. package/dist/client-safe.d.ts +4 -6
  34. package/dist/client-safe.js +29 -34
  35. package/dist/client.d.ts +24 -26
  36. package/dist/client.js +35 -37
  37. package/dist/consts.d.ts +1 -1
  38. package/dist/consts.js +18 -41
  39. package/dist/dynamic-link.d.ts +6 -6
  40. package/dist/dynamic-link.js +16 -16
  41. package/dist/error-utils.d.ts +3 -4
  42. package/dist/error-utils.js +47 -51
  43. package/dist/error.d.ts +79 -79
  44. package/dist/error.js +154 -166
  45. package/dist/index.d.ts +14 -53
  46. package/dist/index.js +12 -40
  47. package/dist/plugins/batch.d.ts +122 -155
  48. package/dist/plugins/batch.js +320 -391
  49. package/dist/plugins/cookie-jar.d.ts +64 -61
  50. package/dist/plugins/cookie-jar.js +208 -245
  51. package/dist/plugins/dedupe.d.ts +49 -53
  52. package/dist/plugins/dedupe.js +168 -211
  53. package/dist/plugins/index.d.ts +9 -28
  54. package/dist/plugins/index.js +8 -23
  55. package/dist/plugins/request-compression.d.ts +38 -35
  56. package/dist/plugins/request-compression.js +131 -177
  57. package/dist/plugins/response-compression.d.ts +21 -18
  58. package/dist/plugins/response-compression.js +64 -88
  59. package/dist/plugins/retry-after.d.ts +31 -38
  60. package/dist/plugins/retry-after.js +60 -85
  61. package/dist/plugins/retry.d.ts +55 -55
  62. package/dist/plugins/retry.js +118 -137
  63. package/dist/plugins/timeout.d.ts +19 -17
  64. package/dist/plugins/timeout.js +41 -36
  65. package/dist/rpc-json-serializer.d.ts +84 -84
  66. package/dist/rpc-json-serializer.js +338 -383
  67. package/dist/rpc-serializer.d.ts +20 -21
  68. package/dist/rpc-serializer.js +97 -125
  69. package/dist/types.d.ts +19 -31
  70. package/dist/utils.d.ts +18 -29
  71. package/dist/utils.js +63 -47
  72. package/package.json +5 -5
  73. package/dist/adapters/standard/codec.js +0 -1
  74. package/dist/adapters/standard/transport.js +0 -1
  75. package/dist/types.js +0 -1
@@ -1,12 +1,14 @@
1
- import type { Value } from '@orpc/shared';
2
- import type { StandardLinkInterceptorOptions, StandardLinkOptions, StandardLinkPlugin } from '../adapters/standard/index.ts';
3
- import type { ClientContext } from '../types.ts';
1
+ import "../adapters/standard/index.js";
2
+ import { StandardLinkPlugin } from "../adapters/standard/plugin.js";
3
+ import { StandardLinkInterceptorOptions, StandardLinkOptions } from "../adapters/standard/link.js";
4
+ import { ClientContext } from "../types.js";
5
+ import { Value } from "@orpc/shared";
4
6
  export interface TimeoutLinkPluginOptions<T extends ClientContext> {
5
- /**
6
- * Timeout in milliseconds before the request is aborted.
7
- * Use `null` or `undefined` to disable the timeout.
8
- */
9
- timeout: Value<number | null | undefined, [options: StandardLinkInterceptorOptions<T>]>;
7
+ /**
8
+ * Timeout in milliseconds before the request is aborted.
9
+ * Use `null` or `undefined` to disable the timeout.
10
+ */
11
+ timeout: Value<number | null | undefined, [options: StandardLinkInterceptorOptions<T>]>;
10
12
  }
11
13
  /**
12
14
  * The Timeout Link Plugin aborts requests that exceed a configured timeout with an `AbortError`.
@@ -14,12 +16,12 @@ export interface TimeoutLinkPluginOptions<T extends ClientContext> {
14
16
  * @see {@link https://orpc.dev/docs/plugins/timeout | Timeout Plugin}
15
17
  */
16
18
  export declare class TimeoutLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
17
- private readonly timeout;
18
- name: string;
19
- /**
20
- * Should abort if the total retry time exceeds the configured timeout
21
- */
22
- after: string[];
23
- constructor(options: NoInfer<TimeoutLinkPluginOptions<T>>);
24
- init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
25
- }
19
+ private readonly timeout;
20
+ name: string;
21
+ /**
22
+ * Should abort if the total retry time exceeds the configured timeout
23
+ */
24
+ after: string[];
25
+ constructor(options: NoInfer<TimeoutLinkPluginOptions<T>>);
26
+ init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
27
+ }
@@ -1,37 +1,42 @@
1
- import { AbortError, anyAbortSignal, toArray, value } from '@orpc/shared';
1
+ import { AbortError, anyAbortSignal, toArray, value } from "@orpc/shared";
2
+ // src/plugins/timeout.ts
2
3
  /**
3
- * The Timeout Link Plugin aborts requests that exceed a configured timeout with an `AbortError`.
4
- *
5
- * @see {@link https://orpc.dev/docs/plugins/timeout | Timeout Plugin}
6
- */
7
- export class TimeoutLinkPlugin {
8
- timeout;
9
- name = '~timeout';
10
- /**
11
- * Should abort if the total retry time exceeds the configured timeout
12
- */
13
- after = ['~retry'];
14
- constructor(options) {
15
- this.timeout = options.timeout;
16
- }
17
- init(options) {
18
- const interceptor = async (interceptorOptions) => {
19
- const timeoutMs = value(this.timeout, interceptorOptions);
20
- if (timeoutMs === null || timeoutMs === undefined) {
21
- return interceptorOptions.next();
22
- }
23
- const controller = new AbortController();
24
- const timeoutId = setTimeout(() => {
25
- controller.abort(new AbortError(`Request timed out after ${timeoutMs}ms`));
26
- }, timeoutMs);
27
- const signal = anyAbortSignal([interceptorOptions.signal, controller.signal]);
28
- try {
29
- return await interceptorOptions.next({ ...interceptorOptions, signal });
30
- }
31
- finally {
32
- clearTimeout(timeoutId);
33
- }
34
- };
35
- return { ...options, interceptors: [interceptor, ...toArray(options.interceptors)] };
36
- }
37
- }
4
+ * The Timeout Link Plugin aborts requests that exceed a configured timeout with an `AbortError`.
5
+ *
6
+ * @see {@link https://orpc.dev/docs/plugins/timeout | Timeout Plugin}
7
+ */
8
+ var TimeoutLinkPlugin = class {
9
+ timeout;
10
+ name = "~timeout";
11
+ /**
12
+ * Should abort if the total retry time exceeds the configured timeout
13
+ */
14
+ after = ["~retry"];
15
+ constructor(options) {
16
+ this.timeout = options.timeout;
17
+ }
18
+ init(options) {
19
+ const interceptor = async (interceptorOptions) => {
20
+ const timeoutMs = value(this.timeout, interceptorOptions);
21
+ if (timeoutMs === null || timeoutMs === void 0) return interceptorOptions.next();
22
+ const controller = new AbortController();
23
+ const timeoutId = setTimeout(() => {
24
+ controller.abort(new AbortError(`Request timed out after ${timeoutMs}ms`));
25
+ }, timeoutMs);
26
+ const signal = anyAbortSignal([interceptorOptions.signal, controller.signal]);
27
+ try {
28
+ return await interceptorOptions.next({
29
+ ...interceptorOptions,
30
+ signal
31
+ });
32
+ } finally {
33
+ clearTimeout(timeoutId);
34
+ }
35
+ };
36
+ return {
37
+ ...options,
38
+ interceptors: [interceptor, ...toArray(options.interceptors)]
39
+ };
40
+ }
41
+ };
42
+ export { TimeoutLinkPlugin };
@@ -1,81 +1,81 @@
1
- import type { Segment } from '@orpc/shared';
1
+ import { Segment } from "@orpc/shared";
2
2
  export type RPCJsonSerializationMeta = [type: string, ...path: Segment[]];
3
3
  export type RPCJsonSerialization = {
4
- json: unknown;
5
- meta?: RPCJsonSerializationMeta[] | undefined;
6
- maps?: undefined;
7
- blobs?: undefined;
4
+ json: unknown;
5
+ meta?: RPCJsonSerializationMeta[] | undefined;
6
+ maps?: undefined;
7
+ blobs?: undefined;
8
8
  } | {
9
- json: unknown;
10
- meta?: RPCJsonSerializationMeta[] | undefined;
11
- maps: Segment[][];
12
- blobs: Blob[];
9
+ json: unknown;
10
+ meta?: RPCJsonSerializationMeta[] | undefined;
11
+ maps: Segment[][];
12
+ blobs: Blob[];
13
13
  };
14
14
  export interface RPCJsonSerializerHandler {
15
- condition(value: unknown): boolean;
16
- serialize(value: any): unknown;
17
- /**
18
- * `serialized` comes from the wire, so validate its type and throw on mismatch.
19
- */
20
- deserialize(serialized: unknown): unknown;
21
- /**
22
- * If false, the result of this serializer will not be further processed by other serializers,
23
- * even if it matches their conditions and treat it as final serialized value.
24
- * This can be useful for serializers that return primitive values, which should not be further processed.
25
- * to improve performance and avoid potential issues with other serializers.
26
- *
27
- * @default false
28
- */
29
- isTerminal?: boolean | undefined;
15
+ condition(value: unknown): boolean;
16
+ serialize(value: any): unknown;
17
+ /**
18
+ * `serialized` comes from the wire, so validate its type and throw on mismatch.
19
+ */
20
+ deserialize(serialized: unknown): unknown;
21
+ /**
22
+ * If false, the result of this serializer will not be further processed by other serializers,
23
+ * even if it matches their conditions and treat it as final serialized value.
24
+ * This can be useful for serializers that return primitive values, which should not be further processed.
25
+ * to improve performance and avoid potential issues with other serializers.
26
+ *
27
+ * @default false
28
+ */
29
+ isTerminal?: boolean | undefined;
30
30
  }
31
31
  export interface RPCJsonSerializerOptions {
32
- /**
33
- * Extend or override the built-in type handlers used during serialization and deserialization.
34
- *
35
- * Each key is a unique type identifier (e.g. `"date"`, `"bigint"`) and maps to a handler
36
- * that defines how to detect, serialize, and deserialize values of that type.
37
- *
38
- * **Extending:** Add new keys to support custom types:
39
- * ```ts
40
- * handlers: {
41
- * buffer: {
42
- * condition: (v) => v instanceof Buffer,
43
- * serialize: (v: Buffer) => v.toString('base64'),
44
- * deserialize: (s: string) => Buffer.from(s, 'base64'),
45
- * isTerminal: true,
46
- * }
47
- * }
48
- * ```
49
- *
50
- * **Overriding:** Use an existing key to replace a built-in handler:
51
- * ```ts
52
- * handlers: {
53
- * date: {
54
- * condition: (v) => v instanceof Date,
55
- * serialize: (v: Date) => v.getTime(),
56
- * deserialize: (n: number) => new Date(n),
57
- * isTerminal: true,
58
- * }
59
- * }
60
- * ```
61
- *
62
- * **Disabling:** Set a key to `undefined` to remove a built-in handler:
63
- * ```ts
64
- * handlers: { url: undefined }
65
- * ```
66
- *
67
- * During deserialization, values whose type has no handler are left in their serialized form,
68
- * so a client and server with different handlers can still communicate.
69
- *
70
- * Built-in type keys: `undefined`, `bigint`, `date`, `nan`, `infinity`, `url`, `set`, `map`.
71
- */
72
- handlers?: Record<string, undefined | RPCJsonSerializerHandler> | undefined;
73
- /**
74
- * If true, properties with undefined values will be omitted during serialization.
75
- *
76
- * @default true
77
- */
78
- omitUndefinedProperties?: boolean | undefined;
32
+ /**
33
+ * Extend or override the built-in type handlers used during serialization and deserialization.
34
+ *
35
+ * Each key is a unique type identifier (e.g. `"date"`, `"bigint"`) and maps to a handler
36
+ * that defines how to detect, serialize, and deserialize values of that type.
37
+ *
38
+ * **Extending:** Add new keys to support custom types:
39
+ * ```ts
40
+ * handlers: {
41
+ * buffer: {
42
+ * condition: (v) => v instanceof Buffer,
43
+ * serialize: (v: Buffer) => v.toString('base64'),
44
+ * deserialize: (s: string) => Buffer.from(s, 'base64'),
45
+ * isTerminal: true,
46
+ * }
47
+ * }
48
+ * ```
49
+ *
50
+ * **Overriding:** Use an existing key to replace a built-in handler:
51
+ * ```ts
52
+ * handlers: {
53
+ * date: {
54
+ * condition: (v) => v instanceof Date,
55
+ * serialize: (v: Date) => v.getTime(),
56
+ * deserialize: (n: number) => new Date(n),
57
+ * isTerminal: true,
58
+ * }
59
+ * }
60
+ * ```
61
+ *
62
+ * **Disabling:** Set a key to `undefined` to remove a built-in handler:
63
+ * ```ts
64
+ * handlers: { url: undefined }
65
+ * ```
66
+ *
67
+ * During deserialization, values whose type has no handler are left in their serialized form,
68
+ * so a client and server with different handlers can still communicate.
69
+ *
70
+ * Built-in type keys: `undefined`, `bigint`, `date`, `nan`, `infinity`, `url`, `set`, `map`.
71
+ */
72
+ handlers?: Record<string, undefined | RPCJsonSerializerHandler> | undefined;
73
+ /**
74
+ * If true, properties with undefined values will be omitted during serialization.
75
+ *
76
+ * @default true
77
+ */
78
+ omitUndefinedProperties?: boolean | undefined;
79
79
  }
80
80
  /**
81
81
  * Serializes and deserializes native types like Date, BigInt, Set, and Map
@@ -84,16 +84,16 @@ export interface RPCJsonSerializerOptions {
84
84
  * @see {@link https://orpc.dev/docs/rpc/serializer#rpc-json-serializer | RPC Serializer - RPC JSON Serializer}
85
85
  */
86
86
  export declare class RPCJsonSerializer {
87
- private readonly handlers;
88
- private readonly inlineBuiltInHandlers;
89
- private readonly handlerEntries;
90
- private readonly omitUndefinedProperties;
91
- constructor(options?: RPCJsonSerializerOptions);
92
- serializeJson(data: unknown): RPCJsonSerialization;
93
- /**
94
- * `segments` is a shared mutable stack (push/pop while walking),
95
- * so it must be copied before being stored in `meta` or `maps`.
96
- */
97
- private serializeValue;
98
- deserializeJson(serialized: RPCJsonSerialization): unknown;
99
- }
87
+ private readonly handlers;
88
+ private readonly inlineBuiltInHandlers;
89
+ private readonly handlerEntries;
90
+ private readonly omitUndefinedProperties;
91
+ constructor(options?: RPCJsonSerializerOptions);
92
+ serializeJson(data: unknown): RPCJsonSerialization;
93
+ /**
94
+ * `segments` is a shared mutable stack (push/pop while walking),
95
+ * so it must be copied before being stored in `meta` or `maps`.
96
+ */
97
+ private serializeValue;
98
+ deserializeJson(serialized: RPCJsonSerialization): unknown;
99
+ }