@orpc/client 0.0.0-next.b45a533 → 0.0.0-next.b47b94e

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
@@ -21,28 +21,24 @@
21
21
 
22
22
  <h3 align="center">Typesafe APIs Made Simple 🪄</h3>
23
23
 
24
- **oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards, ensuring a smooth and enjoyable developer experience.
24
+ **oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
25
25
 
26
26
  ---
27
27
 
28
28
  ## Highlights
29
29
 
30
- - **End-to-End Type Safety 🔒**: Ensure complete type safety from inputs to outputs and errors, bridging server and client seamlessly.
31
- - **First-Class OpenAPI 📄**: Adheres to the OpenAPI standard out of the box, ensuring seamless integration and comprehensive API documentation.
32
- - **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
33
- - **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
34
- - **Multi-Runtime Support 🌍**: Run your code seamlessly on Cloudflare, Deno, Bun, Node.js, and more.
35
- - **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
36
- - **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
37
- - **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
38
- - **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
39
- - **Native Types 📦**: Enjoy built-in support for Date, File, Blob, BigInt, URL and more with no extra setup.
40
- - **Lazy Router ⏱️**: Improve cold start times with our lazy routing feature.
41
- - **SSE & Streaming 📡**: Provides SSE and streaming features – perfect for real-time notifications and AI-powered streaming responses.
42
- - **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
43
- - **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
44
- - **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
45
- - **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
30
+ - **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
31
+ - **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
32
+ - **📝 Contract-First Development**: Optionally define your API contract before implementation.
33
+ - **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
34
+ - **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
35
+ - **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
36
+ - **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
37
+ - **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
38
+ - **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
39
+ - **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
40
+ - **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
41
+ - **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
46
42
 
47
43
  ## Documentation
48
44
 
@@ -53,6 +49,8 @@ You can find the full documentation [here](https://orpc.unnoq.com).
53
49
  - [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
54
50
  - [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
55
51
  - [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
52
+ - [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with NestJS.
53
+ - [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
56
54
  - [@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
55
  - [@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
56
  - [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
@@ -60,6 +58,8 @@ You can find the full documentation [here](https://orpc.unnoq.com).
60
58
  - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
61
59
  - [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
62
60
  - [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
61
+ - [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
62
+ - [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
63
63
 
64
64
  ## `@orpc/client`
65
65
 
@@ -85,6 +85,14 @@ const client: RouterClient<typeof router> = createORPCClient(link)
85
85
  const client: ContractRouterClient<typeof contract> = createORPCClient(link)
86
86
  ```
87
87
 
88
+ ## Sponsors
89
+
90
+ <p align="center">
91
+ <a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
92
+ <img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
93
+ </a>
94
+ </p>
95
+
88
96
  ## License
89
97
 
90
98
  Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
@@ -1,29 +1,33 @@
1
1
  import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
2
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';
3
+ import { a as ClientContext, b as ClientOptions } from '../../shared/client.4TS_0JaO.mjs';
4
+ import { f as StandardLinkClient } from '../../shared/client.ds1abV85.mjs';
5
+ import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.ClwIM_ku.mjs';
5
6
  import '@orpc/shared';
6
7
 
7
8
  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
+ fetch?: (request: Request, init: {
10
+ redirect?: Request['redirect'];
11
+ }, options: ClientOptions<T>, path: readonly string[], input: unknown) => Promise<Response>;
9
12
  }
10
13
  declare class LinkFetchClient<T extends ClientContext> implements StandardLinkClient<T> {
11
14
  private readonly fetch;
12
15
  private readonly toFetchRequestOptions;
13
16
  constructor(options: LinkFetchClientOptions<T>);
14
- call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
17
+ call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
15
18
  }
16
19
 
17
- interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, LinkFetchClientOptions<T> {
20
+ interface RPCLinkOptions<T extends ClientContext> extends StandardRPCLinkOptions<T>, LinkFetchClientOptions<T> {
18
21
  }
19
- declare class RPCLink<T extends ClientContext> implements ClientLink<T> {
20
- private readonly standardLink;
22
+ /**
23
+ * The RPC Link communicates with the server using the RPC protocol.
24
+ *
25
+ * @see {@link https://orpc.unnoq.com/docs/client/rpc-link RPC Link Docs}
26
+ * @see {@link https://orpc.unnoq.com/docs/advanced/rpc-protocol RPC Protocol Docs}
27
+ */
28
+ declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
21
29
  constructor(options: RPCLinkOptions<T>);
22
- call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
23
30
  }
24
31
 
25
- interface FetchWithContext<TClientContext extends ClientContext> {
26
- (url: URL, init: RequestInit, options: ClientOptionsOut<TClientContext>, path: readonly string[], input: unknown): Promise<Response>;
27
- }
28
-
29
- export { type FetchWithContext, LinkFetchClient, type LinkFetchClientOptions, RPCLink, type RPCLinkOptions };
32
+ export { LinkFetchClient, RPCLink };
33
+ export type { LinkFetchClientOptions, RPCLinkOptions };
@@ -1,29 +1,33 @@
1
1
  import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
2
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';
3
+ import { a as ClientContext, b as ClientOptions } from '../../shared/client.4TS_0JaO.js';
4
+ import { f as StandardLinkClient } from '../../shared/client.7ZYxJok_.js';
5
+ import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.B2432-Lu.js';
5
6
  import '@orpc/shared';
6
7
 
7
8
  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
+ fetch?: (request: Request, init: {
10
+ redirect?: Request['redirect'];
11
+ }, options: ClientOptions<T>, path: readonly string[], input: unknown) => Promise<Response>;
9
12
  }
10
13
  declare class LinkFetchClient<T extends ClientContext> implements StandardLinkClient<T> {
11
14
  private readonly fetch;
12
15
  private readonly toFetchRequestOptions;
13
16
  constructor(options: LinkFetchClientOptions<T>);
14
- call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
17
+ call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
15
18
  }
16
19
 
17
- interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, LinkFetchClientOptions<T> {
20
+ interface RPCLinkOptions<T extends ClientContext> extends StandardRPCLinkOptions<T>, LinkFetchClientOptions<T> {
18
21
  }
19
- declare class RPCLink<T extends ClientContext> implements ClientLink<T> {
20
- private readonly standardLink;
22
+ /**
23
+ * The RPC Link communicates with the server using the RPC protocol.
24
+ *
25
+ * @see {@link https://orpc.unnoq.com/docs/client/rpc-link RPC Link Docs}
26
+ * @see {@link https://orpc.unnoq.com/docs/advanced/rpc-protocol RPC Protocol Docs}
27
+ */
28
+ declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
21
29
  constructor(options: RPCLinkOptions<T>);
22
- call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
23
30
  }
24
31
 
25
- interface FetchWithContext<TClientContext extends ClientContext> {
26
- (url: URL, init: RequestInit, options: ClientOptionsOut<TClientContext>, path: readonly string[], input: unknown): Promise<Response>;
27
- }
28
-
29
- export { type FetchWithContext, LinkFetchClient, type LinkFetchClientOptions, RPCLink, type RPCLinkOptions };
32
+ export { LinkFetchClient, RPCLink };
33
+ export type { LinkFetchClientOptions, RPCLinkOptions };
@@ -1,8 +1,8 @@
1
1
  import { toFetchRequest, toStandardLazyResponse } from '@orpc/standard-server-fetch';
2
- import { a as StandardRPCLinkCodec, b as RPCSerializer, S as StandardLink } from '../../shared/client.Df5pd75N.mjs';
3
2
  import '@orpc/shared';
4
- import '../../shared/client.XAn8cDTM.mjs';
3
+ import { c as StandardRPCLink } from '../../shared/client.DpICn1BD.mjs';
5
4
  import '@orpc/standard-server';
5
+ import '../../shared/client.CRWEpqLB.mjs';
6
6
 
7
7
  class LinkFetchClient {
8
8
  fetch;
@@ -13,22 +13,16 @@ class LinkFetchClient {
13
13
  }
14
14
  async call(request, options, path, input) {
15
15
  const fetchRequest = toFetchRequest(request, this.toFetchRequestOptions);
16
- const fetchResponse = await this.fetch(fetchRequest, {}, options, path, input);
16
+ const fetchResponse = await this.fetch(fetchRequest, { redirect: "manual" }, options, path, input);
17
17
  const lazyResponse = toStandardLazyResponse(fetchResponse);
18
18
  return lazyResponse;
19
19
  }
20
20
  }
21
21
 
22
- class RPCLink {
23
- standardLink;
22
+ class RPCLink extends StandardRPCLink {
24
23
  constructor(options) {
25
- const serializer = new RPCSerializer();
26
- const linkCodec = new StandardRPCLinkCodec(serializer, options);
27
24
  const linkClient = new LinkFetchClient(options);
28
- this.standardLink = new StandardLink(linkCodec, linkClient, options);
29
- }
30
- async call(path, input, options) {
31
- return this.standardLink.call(path, input, options);
25
+ super(linkClient, options);
32
26
  }
33
27
  }
34
28
 
@@ -1,148 +1,10 @@
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';
1
+ export { C as CompositeStandardLinkPlugin, d as StandardLink, f as StandardLinkClient, S as StandardLinkClientInterceptorOptions, e as StandardLinkCodec, c as StandardLinkInterceptorOptions, b as StandardLinkOptions, a as StandardLinkPlugin } from '../../shared/client.ds1abV85.mjs';
2
+ export { S as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, c as StandardRPCCustomJsonSerializer, b as StandardRPCJsonSerialized, a as StandardRPCJsonSerializedMetaItem, e as StandardRPCJsonSerializer, d as StandardRPCJsonSerializerOptions, g as StandardRPCLink, i as StandardRPCLinkCodec, h as StandardRPCLinkCodecOptions, f as StandardRPCLinkOptions, j as StandardRPCSerializer } from '../../shared/client.ClwIM_ku.mjs';
3
+ import { H as HTTPPath } from '../../shared/client.4TS_0JaO.mjs';
4
+ import '@orpc/shared';
5
+ import '@orpc/standard-server';
4
6
 
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>;
11
- }
7
+ declare function toHttpPath(path: readonly string[]): HTTPPath;
8
+ declare function getMalformedResponseErrorCode(status: number): string;
12
9
 
13
- declare class InvalidEventIteratorRetryResponse extends Error {
14
- }
15
- interface StandardLinkOptions<T extends ClientContext> {
16
- /**
17
- * Maximum number of retry attempts for event iterator errors 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
- type RPCJsonSerializedMeta = [
72
- 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7,
73
- Segment[]
74
- ][];
75
- type RPCJsonSerialized = [json: unknown, meta: RPCJsonSerializedMeta, maps: Segment[][], blobs: Blob[]];
76
- declare class RPCJsonSerializer {
77
- serialize(data: unknown, segments?: Segment[], meta?: RPCJsonSerializedMeta, maps?: Segment[][], blobs?: Blob[]): RPCJsonSerialized;
78
- deserialize(json: unknown, meta: RPCJsonSerializedMeta): unknown;
79
- deserialize(json: unknown, meta: RPCJsonSerializedMeta, maps: Segment[][], getBlob: (index: number) => Blob): unknown;
80
- }
81
-
82
- declare class RPCSerializer {
83
- #private;
84
- private readonly jsonSerializer;
85
- constructor(jsonSerializer?: RPCJsonSerializer);
86
- serialize(data: unknown): unknown;
87
- deserialize(data: unknown): unknown;
88
- }
89
-
90
- type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
91
- interface StandardRPCLinkCodecOptions<T extends ClientContext> {
92
- /**
93
- * Base url for all requests.
94
- */
95
- url: Value<string | URL, [
96
- options: ClientOptionsOut<T>,
97
- path: readonly string[],
98
- input: unknown
99
- ]>;
100
- /**
101
- * The maximum length of the URL.
102
- *
103
- * @default 2083
104
- */
105
- maxUrlLength?: Value<number, [
106
- options: ClientOptionsOut<T>,
107
- path: readonly string[],
108
- input: unknown
109
- ]>;
110
- /**
111
- * The method used to make the request.
112
- *
113
- * @default 'POST'
114
- */
115
- method?: Value<HTTPMethod, [
116
- options: ClientOptionsOut<T>,
117
- path: readonly string[],
118
- input: unknown
119
- ]>;
120
- /**
121
- * The method to use when the payload cannot safely pass to the server with method return from method function.
122
- * GET is not allowed, it's very dangerous.
123
- *
124
- * @default 'POST'
125
- */
126
- fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
127
- /**
128
- * Inject headers to the request.
129
- */
130
- headers?: Value<StandardHeaders, [
131
- options: ClientOptionsOut<T>,
132
- path: readonly string[],
133
- input: unknown
134
- ]>;
135
- }
136
- declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
137
- private readonly serializer;
138
- private readonly baseUrl;
139
- private readonly maxUrlLength;
140
- private readonly fallbackMethod;
141
- private readonly expectedMethod;
142
- private readonly headers;
143
- constructor(serializer: RPCSerializer, options: StandardRPCLinkCodecOptions<T>);
144
- encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
145
- decode(response: StandardLazyResponse): Promise<unknown>;
146
- }
147
-
148
- export { InvalidEventIteratorRetryResponse, type RPCJsonSerialized, type RPCJsonSerializedMeta, RPCJsonSerializer, RPCSerializer, StandardLink, type StandardLinkClient, type StandardLinkCodec, type StandardLinkOptions, StandardRPCLinkCodec, type StandardRPCLinkCodecOptions };
10
+ export { getMalformedResponseErrorCode, toHttpPath };
@@ -1,148 +1,10 @@
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.js';
1
+ export { C as CompositeStandardLinkPlugin, d as StandardLink, f as StandardLinkClient, S as StandardLinkClientInterceptorOptions, e as StandardLinkCodec, c as StandardLinkInterceptorOptions, b as StandardLinkOptions, a as StandardLinkPlugin } from '../../shared/client.7ZYxJok_.js';
2
+ export { S as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, c as StandardRPCCustomJsonSerializer, b as StandardRPCJsonSerialized, a as StandardRPCJsonSerializedMetaItem, e as StandardRPCJsonSerializer, d as StandardRPCJsonSerializerOptions, g as StandardRPCLink, i as StandardRPCLinkCodec, h as StandardRPCLinkCodecOptions, f as StandardRPCLinkOptions, j as StandardRPCSerializer } from '../../shared/client.B2432-Lu.js';
3
+ import { H as HTTPPath } from '../../shared/client.4TS_0JaO.js';
4
+ import '@orpc/shared';
5
+ import '@orpc/standard-server';
4
6
 
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>;
11
- }
7
+ declare function toHttpPath(path: readonly string[]): HTTPPath;
8
+ declare function getMalformedResponseErrorCode(status: number): string;
12
9
 
13
- declare class InvalidEventIteratorRetryResponse extends Error {
14
- }
15
- interface StandardLinkOptions<T extends ClientContext> {
16
- /**
17
- * Maximum number of retry attempts for event iterator errors 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
- type RPCJsonSerializedMeta = [
72
- 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7,
73
- Segment[]
74
- ][];
75
- type RPCJsonSerialized = [json: unknown, meta: RPCJsonSerializedMeta, maps: Segment[][], blobs: Blob[]];
76
- declare class RPCJsonSerializer {
77
- serialize(data: unknown, segments?: Segment[], meta?: RPCJsonSerializedMeta, maps?: Segment[][], blobs?: Blob[]): RPCJsonSerialized;
78
- deserialize(json: unknown, meta: RPCJsonSerializedMeta): unknown;
79
- deserialize(json: unknown, meta: RPCJsonSerializedMeta, maps: Segment[][], getBlob: (index: number) => Blob): unknown;
80
- }
81
-
82
- declare class RPCSerializer {
83
- #private;
84
- private readonly jsonSerializer;
85
- constructor(jsonSerializer?: RPCJsonSerializer);
86
- serialize(data: unknown): unknown;
87
- deserialize(data: unknown): unknown;
88
- }
89
-
90
- type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
91
- interface StandardRPCLinkCodecOptions<T extends ClientContext> {
92
- /**
93
- * Base url for all requests.
94
- */
95
- url: Value<string | URL, [
96
- options: ClientOptionsOut<T>,
97
- path: readonly string[],
98
- input: unknown
99
- ]>;
100
- /**
101
- * The maximum length of the URL.
102
- *
103
- * @default 2083
104
- */
105
- maxUrlLength?: Value<number, [
106
- options: ClientOptionsOut<T>,
107
- path: readonly string[],
108
- input: unknown
109
- ]>;
110
- /**
111
- * The method used to make the request.
112
- *
113
- * @default 'POST'
114
- */
115
- method?: Value<HTTPMethod, [
116
- options: ClientOptionsOut<T>,
117
- path: readonly string[],
118
- input: unknown
119
- ]>;
120
- /**
121
- * The method to use when the payload cannot safely pass to the server with method return from method function.
122
- * GET is not allowed, it's very dangerous.
123
- *
124
- * @default 'POST'
125
- */
126
- fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
127
- /**
128
- * Inject headers to the request.
129
- */
130
- headers?: Value<StandardHeaders, [
131
- options: ClientOptionsOut<T>,
132
- path: readonly string[],
133
- input: unknown
134
- ]>;
135
- }
136
- declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
137
- private readonly serializer;
138
- private readonly baseUrl;
139
- private readonly maxUrlLength;
140
- private readonly fallbackMethod;
141
- private readonly expectedMethod;
142
- private readonly headers;
143
- constructor(serializer: RPCSerializer, options: StandardRPCLinkCodecOptions<T>);
144
- encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
145
- decode(response: StandardLazyResponse): Promise<unknown>;
146
- }
147
-
148
- export { InvalidEventIteratorRetryResponse, type RPCJsonSerialized, type RPCJsonSerializedMeta, RPCJsonSerializer, RPCSerializer, StandardLink, type StandardLinkClient, type StandardLinkCodec, type StandardLinkOptions, StandardRPCLinkCodec, type StandardRPCLinkCodecOptions };
10
+ export { getMalformedResponseErrorCode, toHttpPath };
@@ -1,4 +1,4 @@
1
- export { I as InvalidEventIteratorRetryResponse, R as RPCJsonSerializer, b as RPCSerializer, S as StandardLink, a as StandardRPCLinkCodec } from '../../shared/client.Df5pd75N.mjs';
1
+ export { C as CompositeStandardLinkPlugin, a as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, S as StandardLink, b as StandardRPCJsonSerializer, c as StandardRPCLink, d as StandardRPCLinkCodec, e as StandardRPCSerializer, g as getMalformedResponseErrorCode, t as toHttpPath } from '../../shared/client.DpICn1BD.mjs';
2
2
  import '@orpc/shared';
3
- import '../../shared/client.XAn8cDTM.mjs';
4
3
  import '@orpc/standard-server';
4
+ import '../../shared/client.CRWEpqLB.mjs';
@@ -0,0 +1,29 @@
1
+ import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
2
+ import { a as ClientContext, b as ClientOptions } from '../../shared/client.4TS_0JaO.mjs';
3
+ import { f as StandardLinkClient } from '../../shared/client.ds1abV85.mjs';
4
+ import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.ClwIM_ku.mjs';
5
+ import '@orpc/shared';
6
+
7
+ interface experimental_LinkWebsocketClientOptions {
8
+ websocket: Pick<WebSocket, 'addEventListener' | 'send'>;
9
+ }
10
+ declare class experimental_LinkWebsocketClient<T extends ClientContext> implements StandardLinkClient<T> {
11
+ private readonly peer;
12
+ constructor(options: experimental_LinkWebsocketClientOptions);
13
+ call(request: StandardRequest, _options: ClientOptions<T>, _path: readonly string[], _input: unknown): Promise<StandardLazyResponse>;
14
+ }
15
+
16
+ interface experimental_RPCLinkOptions<T extends ClientContext> extends Omit<StandardRPCLinkOptions<T>, 'url' | 'headers' | 'method' | 'fallbackMethod' | 'maxUrlLength'>, experimental_LinkWebsocketClientOptions {
17
+ }
18
+ /**
19
+ * The RPC Link communicates with the server using the RPC protocol over WebSocket.
20
+ *
21
+ * @see {@link https://orpc.unnoq.com/docs/client/rpc-link RPC Link Docs}
22
+ * @see {@link https://orpc.unnoq.com/docs/adapters/websocket WebSocket Adapter Docs}
23
+ */
24
+ declare class experimental_RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
25
+ constructor(options: experimental_RPCLinkOptions<T>);
26
+ }
27
+
28
+ export { experimental_LinkWebsocketClient, experimental_RPCLink };
29
+ export type { experimental_LinkWebsocketClientOptions, experimental_RPCLinkOptions };
@@ -0,0 +1,29 @@
1
+ import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
2
+ import { a as ClientContext, b as ClientOptions } from '../../shared/client.4TS_0JaO.js';
3
+ import { f as StandardLinkClient } from '../../shared/client.7ZYxJok_.js';
4
+ import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.B2432-Lu.js';
5
+ import '@orpc/shared';
6
+
7
+ interface experimental_LinkWebsocketClientOptions {
8
+ websocket: Pick<WebSocket, 'addEventListener' | 'send'>;
9
+ }
10
+ declare class experimental_LinkWebsocketClient<T extends ClientContext> implements StandardLinkClient<T> {
11
+ private readonly peer;
12
+ constructor(options: experimental_LinkWebsocketClientOptions);
13
+ call(request: StandardRequest, _options: ClientOptions<T>, _path: readonly string[], _input: unknown): Promise<StandardLazyResponse>;
14
+ }
15
+
16
+ interface experimental_RPCLinkOptions<T extends ClientContext> extends Omit<StandardRPCLinkOptions<T>, 'url' | 'headers' | 'method' | 'fallbackMethod' | 'maxUrlLength'>, experimental_LinkWebsocketClientOptions {
17
+ }
18
+ /**
19
+ * The RPC Link communicates with the server using the RPC protocol over WebSocket.
20
+ *
21
+ * @see {@link https://orpc.unnoq.com/docs/client/rpc-link RPC Link Docs}
22
+ * @see {@link https://orpc.unnoq.com/docs/adapters/websocket WebSocket Adapter Docs}
23
+ */
24
+ declare class experimental_RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
25
+ constructor(options: experimental_RPCLinkOptions<T>);
26
+ }
27
+
28
+ export { experimental_LinkWebsocketClient, experimental_RPCLink };
29
+ export type { experimental_LinkWebsocketClientOptions, experimental_RPCLinkOptions };
@@ -0,0 +1,31 @@
1
+ import { ClientPeer } from '@orpc/standard-server-peer';
2
+ import '@orpc/shared';
3
+ import { c as StandardRPCLink } from '../../shared/client.DpICn1BD.mjs';
4
+ import '@orpc/standard-server';
5
+ import '../../shared/client.CRWEpqLB.mjs';
6
+
7
+ class experimental_LinkWebsocketClient {
8
+ peer;
9
+ constructor(options) {
10
+ this.peer = new ClientPeer(options.websocket.send.bind(options.websocket));
11
+ options.websocket.addEventListener("message", (event) => {
12
+ this.peer.message(event.data);
13
+ });
14
+ options.websocket.addEventListener("close", () => {
15
+ this.peer.close();
16
+ });
17
+ }
18
+ async call(request, _options, _path, _input) {
19
+ const response = await this.peer.request(request);
20
+ return { ...response, body: () => Promise.resolve(response.body) };
21
+ }
22
+ }
23
+
24
+ class experimental_RPCLink extends StandardRPCLink {
25
+ constructor(options) {
26
+ const linkClient = new experimental_LinkWebsocketClient(options);
27
+ super(linkClient, { ...options, url: "orpc:/" });
28
+ }
29
+ }
30
+
31
+ export { experimental_LinkWebsocketClient, experimental_RPCLink };