@orpc/client 0.0.0-next.85df466 → 0.0.0-next.8900489

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.
package/README.md CHANGED
@@ -32,7 +32,7 @@
32
32
  - **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
33
33
  - **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
34
34
  - **Multi-Runtime Support 🌍**: Run your code seamlessly on Cloudflare, Deno, Bun, Node.js, and more.
35
- - **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue), Pinia Colada, and more.
35
+ - **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
36
36
  - **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
37
37
  - **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
38
38
  - **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
@@ -55,9 +55,13 @@ You can find the full documentation [here](https://orpc.unnoq.com).
55
55
  - [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
56
56
  - [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
57
57
  - [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
58
+ - [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
59
+ - [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
58
60
  - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
59
61
  - [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
60
62
  - [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
63
+ - [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
64
+ - [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
61
65
 
62
66
  ## `@orpc/client`
63
67
 
@@ -1,103 +1,29 @@
1
- import { Value } from '@orpc/shared';
2
- import { ToFetchBodyOptions } from '@orpc/standard-server-fetch';
3
- import { C as ClientContext, a as ClientOptionsOut, E as EventIteratorReconnectOptions, b as ClientLink } from '../../shared/client.D_CzLDyB.mjs';
4
- import { RPCSerializer } from '../standard/index.mjs';
1
+ import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
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, StandardRPCLinkOptions } from '../standard/index.mjs';
5
+ import '@orpc/shared';
5
6
 
6
- interface FetchWithContext<TClientContext extends ClientContext> {
7
- (url: URL, init: RequestInit, options: ClientOptionsOut<TClientContext>, path: readonly string[], input: unknown): Promise<Response>;
7
+ interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
8
+ fetch?: (request: Request, init: Record<never, never>, options: ClientOptionsOut<T>, path: readonly string[], input: unknown) => Promise<Response>;
9
+ }
10
+ declare class LinkFetchClient<T extends ClientContext> implements StandardLinkClient<T> {
11
+ private readonly fetch;
12
+ private readonly toFetchRequestOptions;
13
+ constructor(options: LinkFetchClientOptions<T>);
14
+ call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
8
15
  }
9
16
 
10
- type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
11
- declare class InvalidEventSourceRetryResponse extends Error {
17
+ interface RPCLinkOptions<T extends ClientContext> extends StandardRPCLinkOptions<T>, LinkFetchClientOptions<T> {
12
18
  }
13
- interface RPCLinkOptions<TClientContext extends ClientContext> extends ToFetchBodyOptions {
14
- /**
15
- * Base url for all requests.
16
- */
17
- url: string;
18
- /**
19
- * The maximum length of the URL.
20
- *
21
- * @default 2083
22
- */
23
- maxUrlLength?: number;
24
- /**
25
- * The method used to make the request.
26
- *
27
- * @default 'POST'
28
- */
29
- method?: Value<HTTPMethod, [
30
- options: ClientOptionsOut<TClientContext>,
31
- path: readonly string[],
32
- input: unknown
33
- ]>;
34
- /**
35
- * The method to use when the payload cannot safely pass to the server with method return from method function.
36
- * GET is not allowed, it's very dangerous.
37
- *
38
- * @default 'POST'
39
- */
40
- fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
41
- /**
42
- * Inject headers to the request.
43
- */
44
- headers?: Value<[string, string][] | Record<string, string> | Headers, [
45
- options: ClientOptionsOut<TClientContext>,
46
- path: readonly string[],
47
- input: unknown
48
- ]>;
49
- /**
50
- * Custom fetch implementation.
51
- *
52
- * @default globalThis.fetch.bind(globalThis)
53
- */
54
- fetch?: FetchWithContext<TClientContext>;
55
- rpcSerializer?: RPCSerializer;
56
- /**
57
- * Maximum number of retry attempts for EventSource errors before throwing.
58
- *
59
- * @default 5
60
- */
61
- eventSourceMaxNumberOfRetries?: number;
62
- /**
63
- * Delay (in ms) before retrying an EventSource call.
64
- *
65
- * @default ({retryTimes, lastRetry}) => lastRetry ?? (1000 * 2 ** retryTimes)
66
- */
67
- eventSourceRetryDelay?: Value<number, [
68
- reconnectOptions: EventIteratorReconnectOptions,
69
- options: ClientOptionsOut<TClientContext>,
70
- path: readonly string[],
71
- input: unknown
72
- ]>;
73
- /**
74
- * Function to determine if an error is retryable.
75
- *
76
- * @default true
77
- */
78
- eventSourceRetry?: Value<boolean, [
79
- reconnectOptions: EventIteratorReconnectOptions,
80
- options: ClientOptionsOut<TClientContext>,
81
- path: readonly string[],
82
- input: unknown
83
- ]>;
19
+ declare class RPCLink<T extends ClientContext> implements ClientLink<T> {
20
+ private readonly standardLink;
21
+ constructor(options: RPCLinkOptions<T>);
22
+ call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
84
23
  }
85
- declare class RPCLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
86
- private readonly fetch;
87
- private readonly rpcSerializer;
88
- private readonly maxUrlLength;
89
- private readonly fallbackMethod;
90
- private readonly method;
91
- private readonly headers;
92
- private readonly url;
93
- private readonly eventSourceMaxNumberOfRetries;
94
- private readonly eventSourceRetryDelay;
95
- private readonly eventSourceRetry;
96
- private readonly toFetchBodyOptions;
97
- constructor(options: RPCLinkOptions<TClientContext>);
98
- call(path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>): Promise<unknown>;
99
- private performCall;
100
- private encodeRequest;
24
+
25
+ interface FetchWithContext<TClientContext extends ClientContext> {
26
+ (url: URL, init: RequestInit, options: ClientOptionsOut<TClientContext>, path: readonly string[], input: unknown): Promise<Response>;
101
27
  }
102
28
 
103
- export { type FetchWithContext, InvalidEventSourceRetryResponse, RPCLink, type RPCLinkOptions };
29
+ export { type FetchWithContext, LinkFetchClient, type LinkFetchClientOptions, RPCLink, type RPCLinkOptions };
@@ -1,103 +1,29 @@
1
- import { Value } from '@orpc/shared';
2
- import { ToFetchBodyOptions } from '@orpc/standard-server-fetch';
3
- import { C as ClientContext, a as ClientOptionsOut, E as EventIteratorReconnectOptions, b as ClientLink } from '../../shared/client.D_CzLDyB.js';
4
- import { RPCSerializer } from '../standard/index.js';
1
+ import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
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, StandardRPCLinkOptions } from '../standard/index.js';
5
+ import '@orpc/shared';
5
6
 
6
- interface FetchWithContext<TClientContext extends ClientContext> {
7
- (url: URL, init: RequestInit, options: ClientOptionsOut<TClientContext>, path: readonly string[], input: unknown): Promise<Response>;
7
+ interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
8
+ fetch?: (request: Request, init: Record<never, never>, options: ClientOptionsOut<T>, path: readonly string[], input: unknown) => Promise<Response>;
9
+ }
10
+ declare class LinkFetchClient<T extends ClientContext> implements StandardLinkClient<T> {
11
+ private readonly fetch;
12
+ private readonly toFetchRequestOptions;
13
+ constructor(options: LinkFetchClientOptions<T>);
14
+ call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
8
15
  }
9
16
 
10
- type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
11
- declare class InvalidEventSourceRetryResponse extends Error {
17
+ interface RPCLinkOptions<T extends ClientContext> extends StandardRPCLinkOptions<T>, LinkFetchClientOptions<T> {
12
18
  }
13
- interface RPCLinkOptions<TClientContext extends ClientContext> extends ToFetchBodyOptions {
14
- /**
15
- * Base url for all requests.
16
- */
17
- url: string;
18
- /**
19
- * The maximum length of the URL.
20
- *
21
- * @default 2083
22
- */
23
- maxUrlLength?: number;
24
- /**
25
- * The method used to make the request.
26
- *
27
- * @default 'POST'
28
- */
29
- method?: Value<HTTPMethod, [
30
- options: ClientOptionsOut<TClientContext>,
31
- path: readonly string[],
32
- input: unknown
33
- ]>;
34
- /**
35
- * The method to use when the payload cannot safely pass to the server with method return from method function.
36
- * GET is not allowed, it's very dangerous.
37
- *
38
- * @default 'POST'
39
- */
40
- fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
41
- /**
42
- * Inject headers to the request.
43
- */
44
- headers?: Value<[string, string][] | Record<string, string> | Headers, [
45
- options: ClientOptionsOut<TClientContext>,
46
- path: readonly string[],
47
- input: unknown
48
- ]>;
49
- /**
50
- * Custom fetch implementation.
51
- *
52
- * @default globalThis.fetch.bind(globalThis)
53
- */
54
- fetch?: FetchWithContext<TClientContext>;
55
- rpcSerializer?: RPCSerializer;
56
- /**
57
- * Maximum number of retry attempts for EventSource errors before throwing.
58
- *
59
- * @default 5
60
- */
61
- eventSourceMaxNumberOfRetries?: number;
62
- /**
63
- * Delay (in ms) before retrying an EventSource call.
64
- *
65
- * @default ({retryTimes, lastRetry}) => lastRetry ?? (1000 * 2 ** retryTimes)
66
- */
67
- eventSourceRetryDelay?: Value<number, [
68
- reconnectOptions: EventIteratorReconnectOptions,
69
- options: ClientOptionsOut<TClientContext>,
70
- path: readonly string[],
71
- input: unknown
72
- ]>;
73
- /**
74
- * Function to determine if an error is retryable.
75
- *
76
- * @default true
77
- */
78
- eventSourceRetry?: Value<boolean, [
79
- reconnectOptions: EventIteratorReconnectOptions,
80
- options: ClientOptionsOut<TClientContext>,
81
- path: readonly string[],
82
- input: unknown
83
- ]>;
19
+ declare class RPCLink<T extends ClientContext> implements ClientLink<T> {
20
+ private readonly standardLink;
21
+ constructor(options: RPCLinkOptions<T>);
22
+ call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
84
23
  }
85
- declare class RPCLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
86
- private readonly fetch;
87
- private readonly rpcSerializer;
88
- private readonly maxUrlLength;
89
- private readonly fallbackMethod;
90
- private readonly method;
91
- private readonly headers;
92
- private readonly url;
93
- private readonly eventSourceMaxNumberOfRetries;
94
- private readonly eventSourceRetryDelay;
95
- private readonly eventSourceRetry;
96
- private readonly toFetchBodyOptions;
97
- constructor(options: RPCLinkOptions<TClientContext>);
98
- call(path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>): Promise<unknown>;
99
- private performCall;
100
- private encodeRequest;
24
+
25
+ interface FetchWithContext<TClientContext extends ClientContext> {
26
+ (url: URL, init: RequestInit, options: ClientOptionsOut<TClientContext>, path: readonly string[], input: unknown): Promise<Response>;
101
27
  }
102
28
 
103
- export { type FetchWithContext, InvalidEventSourceRetryResponse, RPCLink, type RPCLinkOptions };
29
+ export { type FetchWithContext, LinkFetchClient, type LinkFetchClientOptions, RPCLink, type RPCLinkOptions };
@@ -1,121 +1,36 @@
1
- import { isAsyncIteratorObject, value, trim, stringifyJSON } from '@orpc/shared';
2
- import { toFetchBody, toStandardBody } from '@orpc/standard-server-fetch';
3
- import { c as createAutoRetryEventIterator, O as ORPCError } from '../../shared/client.Ly4zGQrc.mjs';
4
- import { a as RPCSerializer } from '../../shared/client.DHJ8vRIG.mjs';
1
+ import { toFetchRequest, toStandardLazyResponse } from '@orpc/standard-server-fetch';
2
+ import { b as StandardRPCJsonSerializer, c as StandardRPCLinkCodec, d as StandardRPCSerializer, S as StandardLink } from '../../shared/client.CPmBUYbj.mjs';
3
+ import '@orpc/shared';
4
+ import '../../shared/client.XAn8cDTM.mjs';
5
5
  import '@orpc/standard-server';
6
6
 
7
- class InvalidEventSourceRetryResponse extends Error {
8
- }
9
- class RPCLink {
7
+ class LinkFetchClient {
10
8
  fetch;
11
- rpcSerializer;
12
- maxUrlLength;
13
- fallbackMethod;
14
- method;
15
- headers;
16
- url;
17
- eventSourceMaxNumberOfRetries;
18
- eventSourceRetryDelay;
19
- eventSourceRetry;
20
- toFetchBodyOptions;
9
+ toFetchRequestOptions;
21
10
  constructor(options) {
22
- this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
23
- this.rpcSerializer = options.rpcSerializer ?? new RPCSerializer();
24
- this.maxUrlLength = options.maxUrlLength ?? 2083;
25
- this.fallbackMethod = options.fallbackMethod ?? "POST";
26
- this.url = options.url;
27
- this.eventSourceMaxNumberOfRetries = options.eventSourceMaxNumberOfRetries ?? 5;
28
- this.method = options.method ?? this.fallbackMethod;
29
- this.headers = options.headers ?? {};
30
- this.eventSourceRetry = options.eventSourceRetry ?? true;
31
- this.eventSourceRetryDelay = options.eventSourceRetryDelay ?? (({ retryTimes, lastRetry }) => lastRetry ?? 1e3 * 2 ** retryTimes);
32
- this.toFetchBodyOptions = options;
11
+ this.fetch = options?.fetch ?? globalThis.fetch.bind(globalThis);
12
+ this.toFetchRequestOptions = options;
33
13
  }
34
- async call(path, input, options) {
35
- const output = await this.performCall(path, input, options);
36
- if (!isAsyncIteratorObject(output)) {
37
- return output;
38
- }
39
- return createAutoRetryEventIterator(output, async (reconnectOptions) => {
40
- if (options.signal?.aborted || reconnectOptions.retryTimes > this.eventSourceMaxNumberOfRetries) {
41
- return null;
42
- }
43
- if (!await value(this.eventSourceRetry, reconnectOptions, options, path, input)) {
44
- return null;
45
- }
46
- const delay = await value(this.eventSourceRetryDelay, reconnectOptions, options, path, input);
47
- await new Promise((resolve) => setTimeout(resolve, delay));
48
- const updatedOptions = { ...options, lastEventId: reconnectOptions.lastEventId };
49
- const maybeIterator = await this.performCall(path, input, updatedOptions);
50
- if (!isAsyncIteratorObject(maybeIterator)) {
51
- throw new InvalidEventSourceRetryResponse("Invalid EventSource retry response");
52
- }
53
- return maybeIterator;
54
- }, void 0);
14
+ async call(request, options, path, input) {
15
+ const fetchRequest = toFetchRequest(request, this.toFetchRequestOptions);
16
+ const fetchResponse = await this.fetch(fetchRequest, {}, options, path, input);
17
+ const lazyResponse = toStandardLazyResponse(fetchResponse);
18
+ return lazyResponse;
55
19
  }
56
- async performCall(path, input, options) {
57
- const encoded = await this.encodeRequest(path, input, options);
58
- const fetchBody = toFetchBody(encoded.body, encoded.headers, this.toFetchBodyOptions);
59
- if (options.lastEventId !== void 0) {
60
- encoded.headers.set("last-event-id", options.lastEventId);
61
- }
62
- const response = await this.fetch(encoded.url, {
63
- method: encoded.method,
64
- headers: encoded.headers,
65
- body: fetchBody,
66
- signal: options.signal
67
- }, options, path, input);
68
- const body = await toStandardBody(response);
69
- const deserialized = (() => {
70
- try {
71
- return this.rpcSerializer.deserialize(body);
72
- } catch (error) {
73
- if (response.ok) {
74
- throw new ORPCError("INTERNAL_SERVER_ERROR", {
75
- message: "Invalid RPC response",
76
- cause: error
77
- });
78
- }
79
- throw new ORPCError(response.status.toString(), {
80
- message: response.statusText
81
- });
82
- }
83
- })();
84
- if (!response.ok) {
85
- if (ORPCError.isValidJSON(deserialized)) {
86
- throw ORPCError.fromJSON(deserialized);
87
- }
88
- throw new ORPCError("INTERNAL_SERVER_ERROR", {
89
- message: "Invalid RPC error response",
90
- cause: deserialized
91
- });
92
- }
93
- return deserialized;
20
+ }
21
+
22
+ class RPCLink {
23
+ standardLink;
24
+ constructor(options) {
25
+ const jsonSerializer = new StandardRPCJsonSerializer(options);
26
+ const serializer = new StandardRPCSerializer(jsonSerializer);
27
+ const linkCodec = new StandardRPCLinkCodec(serializer, options);
28
+ const linkClient = new LinkFetchClient(options);
29
+ this.standardLink = new StandardLink(linkCodec, linkClient, options);
94
30
  }
95
- async encodeRequest(path, input, options) {
96
- const expectedMethod = await value(this.method, options, path, input);
97
- const headers = new Headers(await value(this.headers, options, path, input));
98
- const url = new URL(`${trim(this.url, "/")}/${path.map(encodeURIComponent).join("/")}`);
99
- const serialized = this.rpcSerializer.serialize(input);
100
- if (expectedMethod === "GET" && !(serialized instanceof FormData) && !(serialized instanceof Blob) && !isAsyncIteratorObject(serialized)) {
101
- const getUrl = new URL(url);
102
- getUrl.searchParams.append("data", stringifyJSON(serialized) ?? "");
103
- if (getUrl.toString().length <= this.maxUrlLength) {
104
- return {
105
- body: void 0,
106
- method: expectedMethod,
107
- headers,
108
- url: getUrl
109
- };
110
- }
111
- }
112
- return {
113
- url,
114
- method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod,
115
- headers,
116
- body: serialized
117
- };
31
+ async call(path, input, options) {
32
+ return this.standardLink.call(path, input, options);
118
33
  }
119
34
  }
120
35
 
121
- export { InvalidEventSourceRetryResponse, RPCLink };
36
+ export { LinkFetchClient, RPCLink };
@@ -1,22 +1,169 @@
1
- import { Segment } from '@orpc/shared';
1
+ import { Value, Interceptor, Segment } from '@orpc/shared';
2
+ import { StandardRequest, StandardLazyResponse, StandardHeaders } from '@orpc/standard-server';
3
+ import { C as ClientContext, a as ClientOptionsOut, E as EventIteratorReconnectOptions, b as ClientLink } from '../../shared/client.D_CzLDyB.mjs';
2
4
 
3
- type RPCJsonSerializedMeta = [
4
- 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7,
5
- Segment[]
6
- ][];
7
- type RPCJsonSerialized = [json: unknown, meta: RPCJsonSerializedMeta, maps: Segment[][], blobs: Blob[]];
8
- declare class RPCJsonSerializer {
9
- serialize(data: unknown, segments?: Segment[], meta?: RPCJsonSerializedMeta, maps?: Segment[][], blobs?: Blob[]): RPCJsonSerialized;
10
- deserialize(json: unknown, meta: RPCJsonSerializedMeta): unknown;
11
- deserialize(json: unknown, meta: RPCJsonSerializedMeta, maps: Segment[][], getBlob: (index: number) => Blob): unknown;
5
+ interface StandardLinkCodec<T extends ClientContext> {
6
+ encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
7
+ decode(response: StandardLazyResponse, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<unknown>;
8
+ }
9
+ interface StandardLinkClient<T extends ClientContext> {
10
+ call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
12
11
  }
13
12
 
14
- declare class RPCSerializer {
13
+ declare class InvalidEventIteratorRetryResponse extends Error {
14
+ }
15
+ interface StandardLinkOptions<T extends ClientContext> {
16
+ /**
17
+ * Maximum retry attempts for **consecutive failures** before throwing
18
+ *
19
+ * @default 5
20
+ */
21
+ eventIteratorMaxRetries?: Value<number, [
22
+ reconnectOptions: EventIteratorReconnectOptions,
23
+ options: ClientOptionsOut<T>,
24
+ path: readonly string[],
25
+ input: unknown
26
+ ]>;
27
+ /**
28
+ * Delay (in ms) before retrying an event iterator call.
29
+ *
30
+ * @default (o) => o.lastRetry ?? (1000 * 2 ** o.retryTimes)
31
+ */
32
+ eventIteratorRetryDelay?: Value<number, [
33
+ reconnectOptions: EventIteratorReconnectOptions,
34
+ options: ClientOptionsOut<T>,
35
+ path: readonly string[],
36
+ input: unknown
37
+ ]>;
38
+ /**
39
+ * Function to determine if an error is retryable.
40
+ *
41
+ * @default true
42
+ */
43
+ eventIteratorShouldRetry?: Value<boolean, [
44
+ reconnectOptions: EventIteratorReconnectOptions,
45
+ options: ClientOptionsOut<T>,
46
+ path: readonly string[],
47
+ input: unknown
48
+ ]>;
49
+ interceptors?: Interceptor<{
50
+ path: readonly string[];
51
+ input: unknown;
52
+ options: ClientOptionsOut<T>;
53
+ }, unknown, unknown>[];
54
+ clientInterceptors?: Interceptor<{
55
+ request: StandardRequest;
56
+ }, StandardLazyResponse, unknown>[];
57
+ }
58
+ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
59
+ #private;
60
+ readonly codec: StandardLinkCodec<T>;
61
+ readonly sender: StandardLinkClient<T>;
62
+ private readonly eventIteratorMaxRetries;
63
+ private readonly eventIteratorRetryDelay;
64
+ private readonly eventIteratorShouldRetry;
65
+ private readonly interceptors;
66
+ private readonly clientInterceptors;
67
+ constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options: StandardLinkOptions<T>);
68
+ call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
69
+ }
70
+
71
+ declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
72
+ readonly BIGINT: 0;
73
+ readonly DATE: 1;
74
+ readonly NAN: 2;
75
+ readonly UNDEFINED: 3;
76
+ readonly URL: 4;
77
+ readonly REGEXP: 5;
78
+ readonly SET: 6;
79
+ readonly MAP: 7;
80
+ };
81
+ type StandardRPCJsonSerializedMetaItem = readonly [type: number, ...path: Segment[]];
82
+ type StandardRPCJsonSerialized = [json: unknown, meta: StandardRPCJsonSerializedMetaItem[], maps: Segment[][], blobs: Blob[]];
83
+ interface StandardRPCCustomJsonSerializer {
84
+ type: number;
85
+ condition(data: unknown): boolean;
86
+ serialize(data: any): unknown;
87
+ deserialize(serialized: any): unknown;
88
+ }
89
+ interface StandardRPCJsonSerializerOptions {
90
+ customJsonSerializers?: readonly StandardRPCCustomJsonSerializer[];
91
+ }
92
+ declare class StandardRPCJsonSerializer {
93
+ private readonly customSerializers;
94
+ constructor(options?: StandardRPCJsonSerializerOptions);
95
+ serialize(data: unknown, segments?: Segment[], meta?: StandardRPCJsonSerializedMetaItem[], maps?: Segment[][], blobs?: Blob[]): StandardRPCJsonSerialized;
96
+ deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[]): unknown;
97
+ deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[], maps: readonly Segment[][], getBlob: (index: number) => Blob): unknown;
98
+ }
99
+
100
+ declare class StandardRPCSerializer {
15
101
  #private;
16
102
  private readonly jsonSerializer;
17
- constructor(jsonSerializer?: RPCJsonSerializer);
103
+ constructor(jsonSerializer: StandardRPCJsonSerializer);
18
104
  serialize(data: unknown): unknown;
19
105
  deserialize(data: unknown): unknown;
20
106
  }
21
107
 
22
- export { type RPCJsonSerialized, type RPCJsonSerializedMeta, RPCJsonSerializer, RPCSerializer };
108
+ type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
109
+ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
110
+ /**
111
+ * Base url for all requests.
112
+ */
113
+ url: Value<string | URL, [
114
+ options: ClientOptionsOut<T>,
115
+ path: readonly string[],
116
+ input: unknown
117
+ ]>;
118
+ /**
119
+ * The maximum length of the URL.
120
+ *
121
+ * @default 2083
122
+ */
123
+ maxUrlLength?: Value<number, [
124
+ options: ClientOptionsOut<T>,
125
+ path: readonly string[],
126
+ input: unknown
127
+ ]>;
128
+ /**
129
+ * The method used to make the request.
130
+ *
131
+ * @default 'POST'
132
+ */
133
+ method?: Value<HTTPMethod, [
134
+ options: ClientOptionsOut<T>,
135
+ path: readonly string[],
136
+ input: unknown
137
+ ]>;
138
+ /**
139
+ * The method to use when the payload cannot safely pass to the server with method return from method function.
140
+ * GET is not allowed, it's very dangerous.
141
+ *
142
+ * @default 'POST'
143
+ */
144
+ fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
145
+ /**
146
+ * Inject headers to the request.
147
+ */
148
+ headers?: Value<StandardHeaders, [
149
+ options: ClientOptionsOut<T>,
150
+ path: readonly string[],
151
+ input: unknown
152
+ ]>;
153
+ }
154
+ declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
155
+ private readonly serializer;
156
+ private readonly baseUrl;
157
+ private readonly maxUrlLength;
158
+ private readonly fallbackMethod;
159
+ private readonly expectedMethod;
160
+ private readonly headers;
161
+ constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>);
162
+ encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
163
+ decode(response: StandardLazyResponse): Promise<unknown>;
164
+ }
165
+
166
+ interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions {
167
+ }
168
+
169
+ export { InvalidEventIteratorRetryResponse, STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, StandardLink, type StandardLinkClient, type StandardLinkCodec, type StandardLinkOptions, type StandardRPCCustomJsonSerializer, type StandardRPCJsonSerialized, type StandardRPCJsonSerializedMetaItem, StandardRPCJsonSerializer, type StandardRPCJsonSerializerOptions, StandardRPCLinkCodec, type StandardRPCLinkCodecOptions, type StandardRPCLinkOptions, StandardRPCSerializer };