@orpc/client 0.47.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 +2 -2
- package/dist/adapters/fetch/index.d.ts +2 -2
- package/dist/adapters/fetch/index.mjs +4 -3
- package/dist/adapters/standard/index.d.mts +34 -13
- package/dist/adapters/standard/index.d.ts +34 -13
- 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.BMw2gtvr.mjs → client.CPmBUYbj.mjs} +56 -25
- package/dist/shared/{client.DcaJQZfy.mjs → client.XAn8cDTM.mjs} +2 -1
- package/package.json +4 -4
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
1
|
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
2
2
|
import { ToFetchRequestOptions } from '@orpc/standard-server-fetch';
|
3
3
|
import { C as ClientContext, a as ClientOptionsOut, b as ClientLink } from '../../shared/client.D_CzLDyB.mjs';
|
4
|
-
import { StandardLinkClient,
|
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,7 +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
|
17
|
+
interface RPCLinkOptions<T extends ClientContext> extends StandardRPCLinkOptions<T>, LinkFetchClientOptions<T> {
|
18
18
|
}
|
19
19
|
declare class RPCLink<T extends ClientContext> implements ClientLink<T> {
|
20
20
|
private readonly standardLink;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
2
2
|
import { ToFetchRequestOptions } from '@orpc/standard-server-fetch';
|
3
3
|
import { C as ClientContext, a as ClientOptionsOut, b as ClientLink } from '../../shared/client.D_CzLDyB.js';
|
4
|
-
import { StandardLinkClient,
|
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,7 +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
|
17
|
+
interface RPCLinkOptions<T extends ClientContext> extends StandardRPCLinkOptions<T>, LinkFetchClientOptions<T> {
|
18
18
|
}
|
19
19
|
declare class RPCLink<T extends ClientContext> implements ClientLink<T> {
|
20
20
|
private readonly standardLink;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { toFetchRequest, toStandardLazyResponse } from '@orpc/standard-server-fetch';
|
2
|
-
import {
|
2
|
+
import { b as StandardRPCJsonSerializer, c as StandardRPCLinkCodec, d as StandardRPCSerializer, S as StandardLink } from '../../shared/client.CPmBUYbj.mjs';
|
3
3
|
import '@orpc/shared';
|
4
|
-
import '../../shared/client.
|
4
|
+
import '../../shared/client.XAn8cDTM.mjs';
|
5
5
|
import '@orpc/standard-server';
|
6
6
|
|
7
7
|
class LinkFetchClient {
|
@@ -22,7 +22,8 @@ class LinkFetchClient {
|
|
22
22
|
class RPCLink {
|
23
23
|
standardLink;
|
24
24
|
constructor(options) {
|
25
|
-
const
|
25
|
+
const jsonSerializer = new StandardRPCJsonSerializer(options);
|
26
|
+
const serializer = new StandardRPCSerializer(jsonSerializer);
|
26
27
|
const linkCodec = new StandardRPCLinkCodec(serializer, options);
|
27
28
|
const linkClient = new LinkFetchClient(options);
|
28
29
|
this.standardLink = new StandardLink(linkCodec, linkClient, options);
|
@@ -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
|
}
|
@@ -140,9 +158,12 @@ declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardL
|
|
140
158
|
private readonly fallbackMethod;
|
141
159
|
private readonly expectedMethod;
|
142
160
|
private readonly headers;
|
143
|
-
constructor(serializer:
|
161
|
+
constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>);
|
144
162
|
encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
|
145
163
|
decode(response: StandardLazyResponse): Promise<unknown>;
|
146
164
|
}
|
147
165
|
|
148
|
-
|
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
|
}
|
@@ -140,9 +158,12 @@ declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardL
|
|
140
158
|
private readonly fallbackMethod;
|
141
159
|
private readonly expectedMethod;
|
142
160
|
private readonly headers;
|
143
|
-
constructor(serializer:
|
161
|
+
constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>);
|
144
162
|
encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
|
145
163
|
decode(response: StandardLazyResponse): Promise<unknown>;
|
146
164
|
}
|
147
165
|
|
148
|
-
|
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
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.
|
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
|
}
|
@@ -242,8 +273,8 @@ class StandardRPCLinkCodec {
|
|
242
273
|
}
|
243
274
|
}
|
244
275
|
|
245
|
-
class
|
246
|
-
constructor(jsonSerializer
|
276
|
+
class StandardRPCSerializer {
|
277
|
+
constructor(jsonSerializer) {
|
247
278
|
this.jsonSerializer = jsonSerializer;
|
248
279
|
}
|
249
280
|
serialize(data) {
|
@@ -317,4 +348,4 @@ class RPCSerializer {
|
|
317
348
|
}
|
318
349
|
}
|
319
350
|
|
320
|
-
export { InvalidEventIteratorRetryResponse as I,
|
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,9 +34,9 @@
|
|
34
34
|
"dist"
|
35
35
|
],
|
36
36
|
"dependencies": {
|
37
|
-
"@orpc/
|
38
|
-
"@orpc/
|
39
|
-
"@orpc/standard-server-fetch": "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
42
|
"zod": "^3.24.2"
|