@orpc/client 0.46.0 → 1.0.0-beta.1
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 +3 -1
- package/dist/adapters/fetch/index.d.mts +4 -6
- package/dist/adapters/fetch/index.d.ts +4 -6
- package/dist/adapters/fetch/index.mjs +8 -6
- package/dist/adapters/standard/index.d.mts +35 -15
- package/dist/adapters/standard/index.d.ts +35 -15
- package/dist/adapters/standard/index.mjs +2 -2
- package/dist/index.d.mts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.mjs +3 -3
- package/dist/shared/{client.Ch8Gzz9n.mjs → client.CPmBUYbj.mjs} +130 -100
- package/dist/shared/{client.DcaJQZfy.mjs → client.XAn8cDTM.mjs} +2 -1
- package/package.json +5 -5
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,6 +55,8 @@ 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.
|
@@ -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, StandardRPCLinkOptions } from '../standard/index.mjs';
|
5
5
|
import '@orpc/shared';
|
6
6
|
|
7
7
|
interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
|
@@ -14,9 +14,7 @@ declare class LinkFetchClient<T extends ClientContext> implements StandardLinkCl
|
|
14
14
|
call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
15
15
|
}
|
16
16
|
|
17
|
-
interface RPCLinkOptions<T extends ClientContext> extends
|
18
|
-
linkCodec?: StandardRPCLinkCodec<T>;
|
19
|
-
linkClient?: LinkFetchClient<T>;
|
17
|
+
interface RPCLinkOptions<T extends ClientContext> extends StandardRPCLinkOptions<T>, LinkFetchClientOptions<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, StandardRPCLinkOptions } from '../standard/index.js';
|
5
5
|
import '@orpc/shared';
|
6
6
|
|
7
7
|
interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
|
@@ -14,9 +14,7 @@ declare class LinkFetchClient<T extends ClientContext> implements StandardLinkCl
|
|
14
14
|
call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
15
15
|
}
|
16
16
|
|
17
|
-
interface RPCLinkOptions<T extends ClientContext> extends
|
18
|
-
linkCodec?: StandardRPCLinkCodec<T>;
|
19
|
-
linkClient?: LinkFetchClient<T>;
|
17
|
+
interface RPCLinkOptions<T extends ClientContext> extends StandardRPCLinkOptions<T>, LinkFetchClientOptions<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 {
|
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';
|
2
3
|
import '@orpc/shared';
|
4
|
+
import '../../shared/client.XAn8cDTM.mjs';
|
3
5
|
import '@orpc/standard-server';
|
4
|
-
import { toFetchRequest, toStandardLazyResponse } from '@orpc/standard-server-fetch';
|
5
|
-
import '../../shared/client.DcaJQZfy.mjs';
|
6
6
|
|
7
7
|
class LinkFetchClient {
|
8
8
|
fetch;
|
@@ -22,8 +22,10 @@ class LinkFetchClient {
|
|
22
22
|
class RPCLink {
|
23
23
|
standardLink;
|
24
24
|
constructor(options) {
|
25
|
-
const
|
26
|
-
const
|
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);
|
27
29
|
this.standardLink = new StandardLink(linkCodec, linkClient, options);
|
28
30
|
}
|
29
31
|
async call(path, input, options) {
|
@@ -31,4 +33,4 @@ class RPCLink {
|
|
31
33
|
}
|
32
34
|
}
|
33
35
|
|
34
|
-
export { RPCLink };
|
36
|
+
export { LinkFetchClient, RPCLink };
|
@@ -68,21 +68,39 @@ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
68
68
|
call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
|
69
69
|
}
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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;
|
80
98
|
}
|
81
99
|
|
82
|
-
declare class
|
100
|
+
declare class StandardRPCSerializer {
|
83
101
|
#private;
|
84
102
|
private readonly jsonSerializer;
|
85
|
-
constructor(jsonSerializer
|
103
|
+
constructor(jsonSerializer: StandardRPCJsonSerializer);
|
86
104
|
serialize(data: unknown): unknown;
|
87
105
|
deserialize(data: unknown): unknown;
|
88
106
|
}
|
@@ -132,18 +150,20 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
132
150
|
path: readonly string[],
|
133
151
|
input: unknown
|
134
152
|
]>;
|
135
|
-
rpcSerializer?: RPCSerializer;
|
136
153
|
}
|
137
154
|
declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
155
|
+
private readonly serializer;
|
138
156
|
private readonly baseUrl;
|
139
157
|
private readonly maxUrlLength;
|
140
158
|
private readonly fallbackMethod;
|
141
159
|
private readonly expectedMethod;
|
142
160
|
private readonly headers;
|
143
|
-
|
144
|
-
constructor(options: StandardRPCLinkCodecOptions<T>);
|
161
|
+
constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>);
|
145
162
|
encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
|
146
163
|
decode(response: StandardLazyResponse): Promise<unknown>;
|
147
164
|
}
|
148
165
|
|
149
|
-
|
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 };
|
@@ -68,21 +68,39 @@ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
68
68
|
call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
|
69
69
|
}
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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;
|
80
98
|
}
|
81
99
|
|
82
|
-
declare class
|
100
|
+
declare class StandardRPCSerializer {
|
83
101
|
#private;
|
84
102
|
private readonly jsonSerializer;
|
85
|
-
constructor(jsonSerializer
|
103
|
+
constructor(jsonSerializer: StandardRPCJsonSerializer);
|
86
104
|
serialize(data: unknown): unknown;
|
87
105
|
deserialize(data: unknown): unknown;
|
88
106
|
}
|
@@ -132,18 +150,20 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
132
150
|
path: readonly string[],
|
133
151
|
input: unknown
|
134
152
|
]>;
|
135
|
-
rpcSerializer?: RPCSerializer;
|
136
153
|
}
|
137
154
|
declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
155
|
+
private readonly serializer;
|
138
156
|
private readonly baseUrl;
|
139
157
|
private readonly maxUrlLength;
|
140
158
|
private readonly fallbackMethod;
|
141
159
|
private readonly expectedMethod;
|
142
160
|
private readonly headers;
|
143
|
-
|
144
|
-
constructor(options: StandardRPCLinkCodecOptions<T>);
|
161
|
+
constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>);
|
145
162
|
encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
|
146
163
|
decode(response: StandardLazyResponse): Promise<unknown>;
|
147
164
|
}
|
148
165
|
|
149
|
-
|
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 };
|
@@ -1,4 +1,4 @@
|
|
1
|
-
export { I as InvalidEventIteratorRetryResponse,
|
1
|
+
export { I as InvalidEventIteratorRetryResponse, a as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, S as StandardLink, b as StandardRPCJsonSerializer, c as StandardRPCLinkCodec, d as StandardRPCSerializer } from '../../shared/client.CPmBUYbj.mjs';
|
2
2
|
import '@orpc/shared';
|
3
|
-
import '../../shared/client.
|
3
|
+
import '../../shared/client.XAn8cDTM.mjs';
|
4
4
|
import '@orpc/standard-server';
|
package/dist/index.d.mts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import { N as NestedClient, b as ClientLink, I as InferClientContext, C as ClientContext, a as ClientOptionsOut, c as ClientPromiseResult } from './shared/client.D_CzLDyB.mjs';
|
2
2
|
export { g as Client, e as ClientOptions, f as ClientRest, E as EventIteratorReconnectOptions, d as createAutoRetryEventIterator, m as mapEventIterator } from './shared/client.D_CzLDyB.mjs';
|
3
3
|
import { Promisable, MaybeOptionalOptions } from '@orpc/shared';
|
4
|
+
export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
4
5
|
export { ErrorEvent } from '@orpc/standard-server';
|
5
6
|
|
6
7
|
interface createORPCClientOptions {
|
@@ -133,7 +134,9 @@ interface EventIteratorState {
|
|
133
134
|
}
|
134
135
|
declare function registerEventIteratorState(iterator: AsyncIteratorObject<unknown, unknown, void>, state: EventIteratorState): void;
|
135
136
|
declare function updateEventIteratorStatus(state: EventIteratorState, status: ConnectionStatus): void;
|
136
|
-
declare function onEventIteratorStatusChange(iterator: AsyncIteratorObject<unknown, unknown, void>, callback: (status: ConnectionStatus) => void,
|
137
|
+
declare function onEventIteratorStatusChange(iterator: AsyncIteratorObject<unknown, unknown, void>, callback: (status: ConnectionStatus) => void, options?: {
|
138
|
+
notifyImmediately?: boolean;
|
139
|
+
}): () => void;
|
137
140
|
|
138
141
|
type SafeResult<TOutput, TError extends Error> = [error: null, data: TOutput, isDefined: false] & {
|
139
142
|
error: null;
|
package/dist/index.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import { N as NestedClient, b as ClientLink, I as InferClientContext, C as ClientContext, a as ClientOptionsOut, c as ClientPromiseResult } from './shared/client.D_CzLDyB.js';
|
2
2
|
export { g as Client, e as ClientOptions, f as ClientRest, E as EventIteratorReconnectOptions, d as createAutoRetryEventIterator, m as mapEventIterator } from './shared/client.D_CzLDyB.js';
|
3
3
|
import { Promisable, MaybeOptionalOptions } from '@orpc/shared';
|
4
|
+
export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
4
5
|
export { ErrorEvent } from '@orpc/standard-server';
|
5
6
|
|
6
7
|
interface createORPCClientOptions {
|
@@ -133,7 +134,9 @@ interface EventIteratorState {
|
|
133
134
|
}
|
134
135
|
declare function registerEventIteratorState(iterator: AsyncIteratorObject<unknown, unknown, void>, state: EventIteratorState): void;
|
135
136
|
declare function updateEventIteratorStatus(state: EventIteratorState, status: ConnectionStatus): void;
|
136
|
-
declare function onEventIteratorStatusChange(iterator: AsyncIteratorObject<unknown, unknown, void>, callback: (status: ConnectionStatus) => void,
|
137
|
+
declare function onEventIteratorStatusChange(iterator: AsyncIteratorObject<unknown, unknown, void>, callback: (status: ConnectionStatus) => void, options?: {
|
138
|
+
notifyImmediately?: boolean;
|
139
|
+
}): () => void;
|
137
140
|
|
138
141
|
type SafeResult<TOutput, TError extends Error> = [error: null, data: TOutput, isDefined: false] & {
|
139
142
|
error: null;
|
package/dist/index.mjs
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import { i as isDefinedError } from './shared/client.
|
2
|
-
export { C as COMMON_ORPC_ERROR_DEFS, O as ORPCError, c as createAutoRetryEventIterator, a as fallbackORPCErrorMessage, f as fallbackORPCErrorStatus, m as mapEventIterator, o as onEventIteratorStatusChange, r as registerEventIteratorState, t as toORPCError, u as updateEventIteratorStatus } from './shared/client.
|
1
|
+
import { i as isDefinedError } from './shared/client.XAn8cDTM.mjs';
|
2
|
+
export { C as COMMON_ORPC_ERROR_DEFS, O as ORPCError, c as createAutoRetryEventIterator, a as fallbackORPCErrorMessage, f as fallbackORPCErrorStatus, m as mapEventIterator, o as onEventIteratorStatusChange, r as registerEventIteratorState, t as toORPCError, u as updateEventIteratorStatus } from './shared/client.XAn8cDTM.mjs';
|
3
|
+
export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
3
4
|
export { ErrorEvent } from '@orpc/standard-server';
|
4
|
-
import '@orpc/shared';
|
5
5
|
|
6
6
|
function createORPCClient(link, options) {
|
7
7
|
const path = options?.path ?? [];
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { intercept, isAsyncIteratorObject, value, isObject,
|
2
|
-
import { c as createAutoRetryEventIterator,
|
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.XAn8cDTM.mjs';
|
3
3
|
import { ErrorEvent } from '@orpc/standard-server';
|
4
4
|
|
5
5
|
class InvalidEventIteratorRetryResponse extends Error {
|
@@ -57,50 +57,74 @@ class StandardLink {
|
|
57
57
|
}
|
58
58
|
}
|
59
59
|
|
60
|
-
|
60
|
+
const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES = {
|
61
|
+
BIGINT: 0,
|
62
|
+
DATE: 1,
|
63
|
+
NAN: 2,
|
64
|
+
UNDEFINED: 3,
|
65
|
+
URL: 4,
|
66
|
+
REGEXP: 5,
|
67
|
+
SET: 6,
|
68
|
+
MAP: 7
|
69
|
+
};
|
70
|
+
class StandardRPCJsonSerializer {
|
71
|
+
customSerializers;
|
72
|
+
constructor(options = {}) {
|
73
|
+
this.customSerializers = options.customJsonSerializers ?? [];
|
74
|
+
if (this.customSerializers.length !== new Set(this.customSerializers.map((custom) => custom.type)).size) {
|
75
|
+
throw new Error("Custom serializer type must be unique.");
|
76
|
+
}
|
77
|
+
}
|
61
78
|
serialize(data, segments = [], meta = [], maps = [], blobs = []) {
|
79
|
+
for (const custom of this.customSerializers) {
|
80
|
+
if (custom.condition(data)) {
|
81
|
+
const result = this.serialize(custom.serialize(data), segments, meta, maps, blobs);
|
82
|
+
meta.push([custom.type, ...segments]);
|
83
|
+
return result;
|
84
|
+
}
|
85
|
+
}
|
62
86
|
if (data instanceof Blob) {
|
63
87
|
maps.push(segments);
|
64
88
|
blobs.push(data);
|
65
89
|
return [data, meta, maps, blobs];
|
66
90
|
}
|
67
91
|
if (typeof data === "bigint") {
|
68
|
-
meta.push([
|
92
|
+
meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.BIGINT, ...segments]);
|
69
93
|
return [data.toString(), meta, maps, blobs];
|
70
94
|
}
|
71
95
|
if (data instanceof Date) {
|
72
|
-
meta.push([
|
96
|
+
meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.DATE, ...segments]);
|
73
97
|
if (Number.isNaN(data.getTime())) {
|
74
98
|
return [null, meta, maps, blobs];
|
75
99
|
}
|
76
100
|
return [data.toISOString(), meta, maps, blobs];
|
77
101
|
}
|
78
102
|
if (Number.isNaN(data)) {
|
79
|
-
meta.push([
|
103
|
+
meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.NAN, ...segments]);
|
80
104
|
return [null, meta, maps, blobs];
|
81
105
|
}
|
82
106
|
if (data instanceof URL) {
|
83
|
-
meta.push([
|
107
|
+
meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.URL, ...segments]);
|
84
108
|
return [data.toString(), meta, maps, blobs];
|
85
109
|
}
|
86
110
|
if (data instanceof RegExp) {
|
87
|
-
meta.push([
|
111
|
+
meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.REGEXP, ...segments]);
|
88
112
|
return [data.toString(), meta, maps, blobs];
|
89
113
|
}
|
90
114
|
if (data instanceof Set) {
|
91
115
|
const result = this.serialize(Array.from(data), segments, meta, maps, blobs);
|
92
|
-
meta.push([
|
116
|
+
meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.SET, ...segments]);
|
93
117
|
return result;
|
94
118
|
}
|
95
119
|
if (data instanceof Map) {
|
96
120
|
const result = this.serialize(Array.from(data.entries()), segments, meta, maps, blobs);
|
97
|
-
meta.push([
|
121
|
+
meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.MAP, ...segments]);
|
98
122
|
return result;
|
99
123
|
}
|
100
124
|
if (Array.isArray(data)) {
|
101
125
|
const json = data.map((v, i) => {
|
102
126
|
if (v === void 0) {
|
103
|
-
meta.push([
|
127
|
+
meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.UNDEFINED, ...segments, i]);
|
104
128
|
return v;
|
105
129
|
}
|
106
130
|
return this.serialize(v, [...segments, i], meta, maps, blobs)[0];
|
@@ -129,38 +153,45 @@ class RPCJsonSerializer {
|
|
129
153
|
currentRef[preSegment] = getBlob(i);
|
130
154
|
});
|
131
155
|
}
|
132
|
-
for (const
|
156
|
+
for (const item of meta) {
|
157
|
+
const type = item[0];
|
133
158
|
let currentRef = ref;
|
134
159
|
let preSegment = "data";
|
135
|
-
|
160
|
+
for (let i = 1; i < item.length; i++) {
|
136
161
|
currentRef = currentRef[preSegment];
|
137
|
-
preSegment =
|
138
|
-
}
|
162
|
+
preSegment = item[i];
|
163
|
+
}
|
164
|
+
for (const custom of this.customSerializers) {
|
165
|
+
if (custom.type === type) {
|
166
|
+
currentRef[preSegment] = custom.deserialize(currentRef[preSegment]);
|
167
|
+
break;
|
168
|
+
}
|
169
|
+
}
|
139
170
|
switch (type) {
|
140
|
-
case
|
171
|
+
case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.BIGINT:
|
141
172
|
currentRef[preSegment] = BigInt(currentRef[preSegment]);
|
142
173
|
break;
|
143
|
-
case
|
174
|
+
case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.DATE:
|
144
175
|
currentRef[preSegment] = new Date(currentRef[preSegment] ?? "Invalid Date");
|
145
176
|
break;
|
146
|
-
case
|
177
|
+
case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.NAN:
|
147
178
|
currentRef[preSegment] = Number.NaN;
|
148
179
|
break;
|
149
|
-
case
|
180
|
+
case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.UNDEFINED:
|
150
181
|
currentRef[preSegment] = void 0;
|
151
182
|
break;
|
152
|
-
case
|
183
|
+
case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.URL:
|
153
184
|
currentRef[preSegment] = new URL(currentRef[preSegment]);
|
154
185
|
break;
|
155
|
-
case
|
186
|
+
case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.REGEXP: {
|
156
187
|
const [, pattern, flags] = currentRef[preSegment].match(/^\/(.*)\/([a-z]*)$/);
|
157
188
|
currentRef[preSegment] = new RegExp(pattern, flags);
|
158
189
|
break;
|
159
190
|
}
|
160
|
-
case
|
191
|
+
case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.SET:
|
161
192
|
currentRef[preSegment] = new Set(currentRef[preSegment]);
|
162
193
|
break;
|
163
|
-
case
|
194
|
+
case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.MAP:
|
164
195
|
currentRef[preSegment] = new Map(currentRef[preSegment]);
|
165
196
|
break;
|
166
197
|
}
|
@@ -169,8 +200,81 @@ class RPCJsonSerializer {
|
|
169
200
|
}
|
170
201
|
}
|
171
202
|
|
172
|
-
class
|
173
|
-
constructor(
|
203
|
+
class StandardRPCLinkCodec {
|
204
|
+
constructor(serializer, options) {
|
205
|
+
this.serializer = serializer;
|
206
|
+
this.baseUrl = options.url;
|
207
|
+
this.maxUrlLength = options.maxUrlLength ?? 2083;
|
208
|
+
this.fallbackMethod = options.fallbackMethod ?? "POST";
|
209
|
+
this.expectedMethod = options.method ?? this.fallbackMethod;
|
210
|
+
this.headers = options.headers ?? {};
|
211
|
+
}
|
212
|
+
baseUrl;
|
213
|
+
maxUrlLength;
|
214
|
+
fallbackMethod;
|
215
|
+
expectedMethod;
|
216
|
+
headers;
|
217
|
+
async encode(path, input, options) {
|
218
|
+
const expectedMethod = await value(this.expectedMethod, options, path, input);
|
219
|
+
const headers = await value(this.headers, options, path, input);
|
220
|
+
const baseUrl = await value(this.baseUrl, options, path, input);
|
221
|
+
const url = new URL(`${trim(baseUrl.toString(), "/")}/${path.map(encodeURIComponent).join("/")}`);
|
222
|
+
const serialized = this.serializer.serialize(input);
|
223
|
+
if (expectedMethod === "GET" && !(serialized instanceof FormData) && !(serialized instanceof Blob) && !isAsyncIteratorObject(serialized)) {
|
224
|
+
const maxUrlLength = await value(this.maxUrlLength, options, path, input);
|
225
|
+
const getUrl = new URL(url);
|
226
|
+
getUrl.searchParams.append("data", stringifyJSON(serialized) ?? "");
|
227
|
+
if (getUrl.toString().length <= maxUrlLength) {
|
228
|
+
return {
|
229
|
+
body: void 0,
|
230
|
+
method: expectedMethod,
|
231
|
+
headers,
|
232
|
+
url: getUrl,
|
233
|
+
signal: options.signal
|
234
|
+
};
|
235
|
+
}
|
236
|
+
}
|
237
|
+
return {
|
238
|
+
url,
|
239
|
+
method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod,
|
240
|
+
headers,
|
241
|
+
body: serialized,
|
242
|
+
signal: options.signal
|
243
|
+
};
|
244
|
+
}
|
245
|
+
async decode(response) {
|
246
|
+
const isOk = response.status >= 200 && response.status < 300;
|
247
|
+
const deserialized = await (async () => {
|
248
|
+
let isBodyOk = false;
|
249
|
+
try {
|
250
|
+
const body = await response.body();
|
251
|
+
isBodyOk = true;
|
252
|
+
return this.serializer.deserialize(body);
|
253
|
+
} catch (error) {
|
254
|
+
if (!isBodyOk) {
|
255
|
+
throw new Error("Cannot parse response body, please check the response body and content-type.", {
|
256
|
+
cause: error
|
257
|
+
});
|
258
|
+
}
|
259
|
+
throw new Error("Invalid RPC response format.", {
|
260
|
+
cause: error
|
261
|
+
});
|
262
|
+
}
|
263
|
+
})();
|
264
|
+
if (!isOk) {
|
265
|
+
if (ORPCError.isValidJSON(deserialized)) {
|
266
|
+
throw ORPCError.fromJSON(deserialized);
|
267
|
+
}
|
268
|
+
throw new Error("Invalid RPC error response format.", {
|
269
|
+
cause: deserialized
|
270
|
+
});
|
271
|
+
}
|
272
|
+
return deserialized;
|
273
|
+
}
|
274
|
+
}
|
275
|
+
|
276
|
+
class StandardRPCSerializer {
|
277
|
+
constructor(jsonSerializer) {
|
174
278
|
this.jsonSerializer = jsonSerializer;
|
175
279
|
}
|
176
280
|
serialize(data) {
|
@@ -244,78 +348,4 @@ class RPCSerializer {
|
|
244
348
|
}
|
245
349
|
}
|
246
350
|
|
247
|
-
|
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
|
-
export { InvalidEventIteratorRetryResponse as I, RPCJsonSerializer as R, StandardLink as S, StandardRPCLinkCodec as a, RPCSerializer as b };
|
351
|
+
export { InvalidEventIteratorRetryResponse as I, StandardLink as S, STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as a, StandardRPCJsonSerializer as b, StandardRPCLinkCodec as c, StandardRPCSerializer as d };
|
@@ -147,7 +147,8 @@ function updateEventIteratorStatus(state, status) {
|
|
147
147
|
state.listeners.forEach((cb) => cb(status));
|
148
148
|
}
|
149
149
|
}
|
150
|
-
function onEventIteratorStatusChange(iterator, callback,
|
150
|
+
function onEventIteratorStatusChange(iterator, callback, options = {}) {
|
151
|
+
const notifyImmediately = options.notifyImmediately ?? true;
|
151
152
|
const state = iteratorStates.get(iterator);
|
152
153
|
if (!state) {
|
153
154
|
throw new Error("Iterator is not registered.");
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/client",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "1.0.0-beta.1",
|
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.
|
38
|
-
"@orpc/standard-server
|
39
|
-
"@orpc/standard-server": "0.
|
37
|
+
"@orpc/shared": "1.0.0-beta.1",
|
38
|
+
"@orpc/standard-server": "1.0.0-beta.1",
|
39
|
+
"@orpc/standard-server-fetch": "1.0.0-beta.1"
|
40
40
|
},
|
41
41
|
"devDependencies": {
|
42
|
-
"zod": "^3.24.
|
42
|
+
"zod": "^3.24.2"
|
43
43
|
},
|
44
44
|
"scripts": {
|
45
45
|
"build": "unbuild",
|