@orpc/client 0.0.0-next.8f622a0 → 0.0.0-next.904b0c2
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 +8 -0
- package/dist/adapters/fetch/index.d.mts +9 -13
- package/dist/adapters/fetch/index.d.ts +9 -13
- package/dist/adapters/fetch/index.mjs +5 -10
- package/dist/adapters/standard/index.d.mts +7 -103
- package/dist/adapters/standard/index.d.ts +7 -103
- package/dist/adapters/standard/index.mjs +2 -3
- package/dist/index.d.mts +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.mjs +34 -32
- package/dist/plugins/index.d.mts +10 -11
- package/dist/plugins/index.d.ts +10 -11
- package/dist/plugins/index.mjs +14 -15
- package/dist/shared/{client.CupM8eRP.d.mts → client.87WXDX8t.d.mts} +7 -5
- package/dist/shared/{client.CupM8eRP.d.ts → client.87WXDX8t.d.ts} +7 -5
- package/dist/shared/client.BC0T26HA.d.mts +103 -0
- package/dist/shared/{client.aGal-uGY.d.ts → client.BaocqKnn.d.ts} +11 -17
- package/dist/shared/client.CZFIVTQj.d.ts +103 -0
- package/dist/shared/{client.Be-O_tdu.mjs → client.D77bw0hs.mjs} +23 -21
- package/dist/shared/{client.DrOAzyMB.d.mts → client.D9lmRwGB.d.mts} +11 -17
- package/dist/shared/{client.BacCdg3F.mjs → client.jKEwIsRd.mjs} +6 -3
- package/package.json +4 -4
- package/dist/shared/client.CvnV7_uV.mjs +0 -12
package/dist/plugins/index.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { C as CompositeClientPlugin } from '../shared/client.CvnV7_uV.mjs';
|
|
2
1
|
import { isAsyncIteratorObject, value } from '@orpc/shared';
|
|
3
2
|
import { getEventMeta } from '@orpc/standard-server';
|
|
4
3
|
|
|
@@ -11,7 +10,7 @@ class ClientRetryPlugin {
|
|
|
11
10
|
defaultOnRetry;
|
|
12
11
|
constructor(options = {}) {
|
|
13
12
|
this.defaultRetry = options.default?.retry ?? 0;
|
|
14
|
-
this.defaultRetryDelay = options.default?.retryDelay ?? ((o) => o.
|
|
13
|
+
this.defaultRetryDelay = options.default?.retryDelay ?? ((o) => o.lastEventRetry ?? 2e3);
|
|
15
14
|
this.defaultShouldRetry = options.default?.shouldRetry ?? true;
|
|
16
15
|
this.defaultOnRetry = options.default?.onRetry;
|
|
17
16
|
}
|
|
@@ -25,13 +24,14 @@ class ClientRetryPlugin {
|
|
|
25
24
|
if (maxAttempts <= 0) {
|
|
26
25
|
return interceptorOptions.next();
|
|
27
26
|
}
|
|
28
|
-
let
|
|
29
|
-
let
|
|
27
|
+
let lastEventId = interceptorOptions.options.lastEventId;
|
|
28
|
+
let lastEventRetry;
|
|
30
29
|
let unsubscribe;
|
|
31
30
|
let attemptIndex = 0;
|
|
32
31
|
const next = async (initial) => {
|
|
33
32
|
let current = initial;
|
|
34
33
|
while (true) {
|
|
34
|
+
const newClientOptions = { ...interceptorOptions.options, lastEventId };
|
|
35
35
|
if (current) {
|
|
36
36
|
if (attemptIndex >= maxAttempts) {
|
|
37
37
|
throw current.error;
|
|
@@ -39,13 +39,13 @@ class ClientRetryPlugin {
|
|
|
39
39
|
const attemptOptions = {
|
|
40
40
|
attemptIndex,
|
|
41
41
|
error: current.error,
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
lastEventId,
|
|
43
|
+
lastEventRetry
|
|
44
44
|
};
|
|
45
45
|
const shouldRetryBool = await value(
|
|
46
46
|
shouldRetry,
|
|
47
47
|
attemptOptions,
|
|
48
|
-
|
|
48
|
+
newClientOptions,
|
|
49
49
|
interceptorOptions.path,
|
|
50
50
|
interceptorOptions.input
|
|
51
51
|
);
|
|
@@ -54,14 +54,14 @@ class ClientRetryPlugin {
|
|
|
54
54
|
}
|
|
55
55
|
unsubscribe = onRetry?.(
|
|
56
56
|
attemptOptions,
|
|
57
|
-
|
|
57
|
+
newClientOptions,
|
|
58
58
|
interceptorOptions.path,
|
|
59
59
|
interceptorOptions.input
|
|
60
60
|
);
|
|
61
61
|
const retryDelayMs = await value(
|
|
62
62
|
retryDelay,
|
|
63
63
|
attemptOptions,
|
|
64
|
-
|
|
64
|
+
newClientOptions,
|
|
65
65
|
interceptorOptions.path,
|
|
66
66
|
interceptorOptions.input
|
|
67
67
|
);
|
|
@@ -69,14 +69,13 @@ class ClientRetryPlugin {
|
|
|
69
69
|
attemptIndex++;
|
|
70
70
|
}
|
|
71
71
|
try {
|
|
72
|
-
const newClientOptions = { ...interceptorOptions.options, lastEventId: eventIteratorLastEventId };
|
|
73
72
|
const output2 = await interceptorOptions.next({
|
|
74
73
|
...interceptorOptions,
|
|
75
74
|
options: newClientOptions
|
|
76
75
|
});
|
|
77
76
|
return output2;
|
|
78
77
|
} catch (error) {
|
|
79
|
-
if (
|
|
78
|
+
if (newClientOptions.signal?.aborted === true) {
|
|
80
79
|
throw error;
|
|
81
80
|
}
|
|
82
81
|
current = { error };
|
|
@@ -97,16 +96,16 @@ class ClientRetryPlugin {
|
|
|
97
96
|
try {
|
|
98
97
|
const item = await current.next();
|
|
99
98
|
const meta = getEventMeta(item.value);
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
lastEventId = meta?.id ?? lastEventId;
|
|
100
|
+
lastEventRetry = meta?.retry ?? lastEventRetry;
|
|
102
101
|
if (item.done) {
|
|
103
102
|
return item.value;
|
|
104
103
|
}
|
|
105
104
|
yield item.value;
|
|
106
105
|
} catch (error) {
|
|
107
106
|
const meta = getEventMeta(error);
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
lastEventId = meta?.id ?? lastEventId;
|
|
108
|
+
lastEventRetry = meta?.retry ?? lastEventRetry;
|
|
110
109
|
const maybeEventIterator = await next({ error });
|
|
111
110
|
if (!isAsyncIteratorObject(maybeEventIterator)) {
|
|
112
111
|
throw new ClientRetryPluginInvalidEventIteratorRetryResponse(
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
type HTTPPath = `/${string}`;
|
|
2
|
+
type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
1
3
|
type ClientContext = Record<string, any>;
|
|
2
|
-
type
|
|
4
|
+
type FriendlyClientOptions<TClientContext extends ClientContext> = {
|
|
3
5
|
signal?: AbortSignal;
|
|
4
6
|
lastEventId?: string | undefined;
|
|
5
7
|
} & (Record<never, never> extends TClientContext ? {
|
|
@@ -7,7 +9,7 @@ type ClientOptions<TClientContext extends ClientContext> = {
|
|
|
7
9
|
} : {
|
|
8
10
|
context: TClientContext;
|
|
9
11
|
});
|
|
10
|
-
type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?:
|
|
12
|
+
type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
|
|
11
13
|
type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
|
|
12
14
|
__error?: {
|
|
13
15
|
type: TError;
|
|
@@ -20,11 +22,11 @@ type NestedClient<TClientContext extends ClientContext> = Client<TClientContext,
|
|
|
20
22
|
[k: string]: NestedClient<TClientContext>;
|
|
21
23
|
};
|
|
22
24
|
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
|
23
|
-
type
|
|
25
|
+
type ClientOptions<TClientContext extends ClientContext> = FriendlyClientOptions<TClientContext> & {
|
|
24
26
|
context: TClientContext;
|
|
25
27
|
};
|
|
26
28
|
interface ClientLink<TClientContext extends ClientContext> {
|
|
27
|
-
call: (path: readonly string[], input: unknown, options:
|
|
29
|
+
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
export type {
|
|
32
|
+
export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientContext as a, ClientOptions as b, ClientPromiseResult as c, HTTPMethod as d, ClientRest as e, Client as f };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
type HTTPPath = `/${string}`;
|
|
2
|
+
type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
1
3
|
type ClientContext = Record<string, any>;
|
|
2
|
-
type
|
|
4
|
+
type FriendlyClientOptions<TClientContext extends ClientContext> = {
|
|
3
5
|
signal?: AbortSignal;
|
|
4
6
|
lastEventId?: string | undefined;
|
|
5
7
|
} & (Record<never, never> extends TClientContext ? {
|
|
@@ -7,7 +9,7 @@ type ClientOptions<TClientContext extends ClientContext> = {
|
|
|
7
9
|
} : {
|
|
8
10
|
context: TClientContext;
|
|
9
11
|
});
|
|
10
|
-
type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?:
|
|
12
|
+
type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
|
|
11
13
|
type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
|
|
12
14
|
__error?: {
|
|
13
15
|
type: TError;
|
|
@@ -20,11 +22,11 @@ type NestedClient<TClientContext extends ClientContext> = Client<TClientContext,
|
|
|
20
22
|
[k: string]: NestedClient<TClientContext>;
|
|
21
23
|
};
|
|
22
24
|
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
|
23
|
-
type
|
|
25
|
+
type ClientOptions<TClientContext extends ClientContext> = FriendlyClientOptions<TClientContext> & {
|
|
24
26
|
context: TClientContext;
|
|
25
27
|
};
|
|
26
28
|
interface ClientLink<TClientContext extends ClientContext> {
|
|
27
|
-
call: (path: readonly string[], input: unknown, options:
|
|
29
|
+
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
export type {
|
|
32
|
+
export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientContext as a, ClientOptions as b, ClientPromiseResult as c, HTTPMethod as d, ClientRest as e, Client as f };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { a as ClientContext, b as ClientOptions, d as HTTPMethod } from './client.87WXDX8t.mjs';
|
|
2
|
+
import { c as StandardLinkCodec, a as StandardLinkOptions } from './client.D9lmRwGB.mjs';
|
|
3
|
+
import { Segment, Value } from '@orpc/shared';
|
|
4
|
+
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
5
|
+
|
|
6
|
+
declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
|
|
7
|
+
readonly BIGINT: 0;
|
|
8
|
+
readonly DATE: 1;
|
|
9
|
+
readonly NAN: 2;
|
|
10
|
+
readonly UNDEFINED: 3;
|
|
11
|
+
readonly URL: 4;
|
|
12
|
+
readonly REGEXP: 5;
|
|
13
|
+
readonly SET: 6;
|
|
14
|
+
readonly MAP: 7;
|
|
15
|
+
};
|
|
16
|
+
type StandardRPCJsonSerializedMetaItem = readonly [type: number, ...path: Segment[]];
|
|
17
|
+
type StandardRPCJsonSerialized = [json: unknown, meta: StandardRPCJsonSerializedMetaItem[], maps: Segment[][], blobs: Blob[]];
|
|
18
|
+
interface StandardRPCCustomJsonSerializer {
|
|
19
|
+
type: number;
|
|
20
|
+
condition(data: unknown): boolean;
|
|
21
|
+
serialize(data: any): unknown;
|
|
22
|
+
deserialize(serialized: any): unknown;
|
|
23
|
+
}
|
|
24
|
+
interface StandardRPCJsonSerializerOptions {
|
|
25
|
+
customJsonSerializers?: readonly StandardRPCCustomJsonSerializer[];
|
|
26
|
+
}
|
|
27
|
+
declare class StandardRPCJsonSerializer {
|
|
28
|
+
private readonly customSerializers;
|
|
29
|
+
constructor(options?: StandardRPCJsonSerializerOptions);
|
|
30
|
+
serialize(data: unknown, segments?: Segment[], meta?: StandardRPCJsonSerializedMetaItem[], maps?: Segment[][], blobs?: Blob[]): StandardRPCJsonSerialized;
|
|
31
|
+
deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[]): unknown;
|
|
32
|
+
deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[], maps: readonly Segment[][], getBlob: (index: number) => Blob): unknown;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
declare class StandardRPCSerializer {
|
|
36
|
+
#private;
|
|
37
|
+
private readonly jsonSerializer;
|
|
38
|
+
constructor(jsonSerializer: StandardRPCJsonSerializer);
|
|
39
|
+
serialize(data: unknown): object;
|
|
40
|
+
deserialize(data: unknown): unknown;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
44
|
+
/**
|
|
45
|
+
* Base url for all requests.
|
|
46
|
+
*/
|
|
47
|
+
url: Value<string | URL, [
|
|
48
|
+
options: ClientOptions<T>,
|
|
49
|
+
path: readonly string[],
|
|
50
|
+
input: unknown
|
|
51
|
+
]>;
|
|
52
|
+
/**
|
|
53
|
+
* The maximum length of the URL.
|
|
54
|
+
*
|
|
55
|
+
* @default 2083
|
|
56
|
+
*/
|
|
57
|
+
maxUrlLength?: Value<number, [
|
|
58
|
+
options: ClientOptions<T>,
|
|
59
|
+
path: readonly string[],
|
|
60
|
+
input: unknown
|
|
61
|
+
]>;
|
|
62
|
+
/**
|
|
63
|
+
* The method used to make the request.
|
|
64
|
+
*
|
|
65
|
+
* @default 'POST'
|
|
66
|
+
*/
|
|
67
|
+
method?: Value<HTTPMethod, [
|
|
68
|
+
options: ClientOptions<T>,
|
|
69
|
+
path: readonly string[],
|
|
70
|
+
input: unknown
|
|
71
|
+
]>;
|
|
72
|
+
/**
|
|
73
|
+
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
|
74
|
+
* GET is not allowed, it's very dangerous.
|
|
75
|
+
*
|
|
76
|
+
* @default 'POST'
|
|
77
|
+
*/
|
|
78
|
+
fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
|
|
79
|
+
/**
|
|
80
|
+
* Inject headers to the request.
|
|
81
|
+
*/
|
|
82
|
+
headers?: Value<StandardHeaders, [
|
|
83
|
+
options: ClientOptions<T>,
|
|
84
|
+
path: readonly string[],
|
|
85
|
+
input: unknown
|
|
86
|
+
]>;
|
|
87
|
+
}
|
|
88
|
+
declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
89
|
+
private readonly serializer;
|
|
90
|
+
private readonly baseUrl;
|
|
91
|
+
private readonly maxUrlLength;
|
|
92
|
+
private readonly fallbackMethod;
|
|
93
|
+
private readonly expectedMethod;
|
|
94
|
+
private readonly headers;
|
|
95
|
+
constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>);
|
|
96
|
+
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
|
|
97
|
+
decode(response: StandardLazyResponse): Promise<unknown>;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions {
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, type StandardRPCJsonSerializedMetaItem as a, type StandardRPCJsonSerialized as b, type StandardRPCCustomJsonSerializer as c, type StandardRPCJsonSerializerOptions as d, StandardRPCJsonSerializer as e, type StandardRPCLinkOptions as f, type StandardRPCLinkCodecOptions as g, StandardRPCLinkCodec as h, StandardRPCSerializer as i };
|
|
@@ -1,27 +1,30 @@
|
|
|
1
1
|
import { Interceptor } from '@orpc/shared';
|
|
2
2
|
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
3
|
-
import { a as ClientContext,
|
|
3
|
+
import { a as ClientContext, b as ClientOptions, C as ClientLink } from './client.87WXDX8t.js';
|
|
4
4
|
|
|
5
5
|
interface StandardLinkCodec<T extends ClientContext> {
|
|
6
|
-
encode(path: readonly string[], input: unknown, options:
|
|
7
|
-
decode(response: StandardLazyResponse, options:
|
|
6
|
+
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
|
|
7
|
+
decode(response: StandardLazyResponse, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<unknown>;
|
|
8
8
|
}
|
|
9
9
|
interface StandardLinkClient<T extends ClientContext> {
|
|
10
|
-
call(request: StandardRequest, options:
|
|
10
|
+
call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
declare class InvalidEventIteratorRetryResponse extends Error {
|
|
14
14
|
}
|
|
15
|
+
interface StandardLinkPlugin<T extends ClientContext> {
|
|
16
|
+
init?(options: StandardLinkOptions<T>): void;
|
|
17
|
+
}
|
|
15
18
|
interface StandardLinkOptions<T extends ClientContext> {
|
|
16
19
|
interceptors?: Interceptor<{
|
|
17
20
|
path: readonly string[];
|
|
18
21
|
input: unknown;
|
|
19
|
-
options:
|
|
22
|
+
options: ClientOptions<T>;
|
|
20
23
|
}, unknown, unknown>[];
|
|
21
24
|
clientInterceptors?: Interceptor<{
|
|
22
25
|
request: StandardRequest;
|
|
23
26
|
}, StandardLazyResponse, unknown>[];
|
|
24
|
-
plugins?:
|
|
27
|
+
plugins?: StandardLinkPlugin<T>[];
|
|
25
28
|
}
|
|
26
29
|
declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
27
30
|
#private;
|
|
@@ -30,16 +33,7 @@ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
|
30
33
|
private readonly interceptors;
|
|
31
34
|
private readonly clientInterceptors;
|
|
32
35
|
constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
|
|
33
|
-
call(path: readonly string[], input: unknown, options:
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
interface ClientPlugin<T extends ClientContext> {
|
|
37
|
-
init?(options: StandardLinkOptions<T>): void;
|
|
38
|
-
}
|
|
39
|
-
declare class CompositeClientPlugin<T extends ClientContext> implements ClientPlugin<T> {
|
|
40
|
-
private readonly plugins;
|
|
41
|
-
constructor(plugins?: ClientPlugin<T>[]);
|
|
42
|
-
init(options: StandardLinkOptions<T>): void;
|
|
36
|
+
call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
|
|
43
37
|
}
|
|
44
38
|
|
|
45
|
-
export {
|
|
39
|
+
export { InvalidEventIteratorRetryResponse as I, type StandardLinkPlugin as S, type StandardLinkOptions as a, StandardLink as b, type StandardLinkCodec as c, type StandardLinkClient as d };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { a as ClientContext, b as ClientOptions, d as HTTPMethod } from './client.87WXDX8t.js';
|
|
2
|
+
import { c as StandardLinkCodec, a as StandardLinkOptions } from './client.BaocqKnn.js';
|
|
3
|
+
import { Segment, Value } from '@orpc/shared';
|
|
4
|
+
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
5
|
+
|
|
6
|
+
declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
|
|
7
|
+
readonly BIGINT: 0;
|
|
8
|
+
readonly DATE: 1;
|
|
9
|
+
readonly NAN: 2;
|
|
10
|
+
readonly UNDEFINED: 3;
|
|
11
|
+
readonly URL: 4;
|
|
12
|
+
readonly REGEXP: 5;
|
|
13
|
+
readonly SET: 6;
|
|
14
|
+
readonly MAP: 7;
|
|
15
|
+
};
|
|
16
|
+
type StandardRPCJsonSerializedMetaItem = readonly [type: number, ...path: Segment[]];
|
|
17
|
+
type StandardRPCJsonSerialized = [json: unknown, meta: StandardRPCJsonSerializedMetaItem[], maps: Segment[][], blobs: Blob[]];
|
|
18
|
+
interface StandardRPCCustomJsonSerializer {
|
|
19
|
+
type: number;
|
|
20
|
+
condition(data: unknown): boolean;
|
|
21
|
+
serialize(data: any): unknown;
|
|
22
|
+
deserialize(serialized: any): unknown;
|
|
23
|
+
}
|
|
24
|
+
interface StandardRPCJsonSerializerOptions {
|
|
25
|
+
customJsonSerializers?: readonly StandardRPCCustomJsonSerializer[];
|
|
26
|
+
}
|
|
27
|
+
declare class StandardRPCJsonSerializer {
|
|
28
|
+
private readonly customSerializers;
|
|
29
|
+
constructor(options?: StandardRPCJsonSerializerOptions);
|
|
30
|
+
serialize(data: unknown, segments?: Segment[], meta?: StandardRPCJsonSerializedMetaItem[], maps?: Segment[][], blobs?: Blob[]): StandardRPCJsonSerialized;
|
|
31
|
+
deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[]): unknown;
|
|
32
|
+
deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[], maps: readonly Segment[][], getBlob: (index: number) => Blob): unknown;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
declare class StandardRPCSerializer {
|
|
36
|
+
#private;
|
|
37
|
+
private readonly jsonSerializer;
|
|
38
|
+
constructor(jsonSerializer: StandardRPCJsonSerializer);
|
|
39
|
+
serialize(data: unknown): object;
|
|
40
|
+
deserialize(data: unknown): unknown;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
44
|
+
/**
|
|
45
|
+
* Base url for all requests.
|
|
46
|
+
*/
|
|
47
|
+
url: Value<string | URL, [
|
|
48
|
+
options: ClientOptions<T>,
|
|
49
|
+
path: readonly string[],
|
|
50
|
+
input: unknown
|
|
51
|
+
]>;
|
|
52
|
+
/**
|
|
53
|
+
* The maximum length of the URL.
|
|
54
|
+
*
|
|
55
|
+
* @default 2083
|
|
56
|
+
*/
|
|
57
|
+
maxUrlLength?: Value<number, [
|
|
58
|
+
options: ClientOptions<T>,
|
|
59
|
+
path: readonly string[],
|
|
60
|
+
input: unknown
|
|
61
|
+
]>;
|
|
62
|
+
/**
|
|
63
|
+
* The method used to make the request.
|
|
64
|
+
*
|
|
65
|
+
* @default 'POST'
|
|
66
|
+
*/
|
|
67
|
+
method?: Value<HTTPMethod, [
|
|
68
|
+
options: ClientOptions<T>,
|
|
69
|
+
path: readonly string[],
|
|
70
|
+
input: unknown
|
|
71
|
+
]>;
|
|
72
|
+
/**
|
|
73
|
+
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
|
74
|
+
* GET is not allowed, it's very dangerous.
|
|
75
|
+
*
|
|
76
|
+
* @default 'POST'
|
|
77
|
+
*/
|
|
78
|
+
fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
|
|
79
|
+
/**
|
|
80
|
+
* Inject headers to the request.
|
|
81
|
+
*/
|
|
82
|
+
headers?: Value<StandardHeaders, [
|
|
83
|
+
options: ClientOptions<T>,
|
|
84
|
+
path: readonly string[],
|
|
85
|
+
input: unknown
|
|
86
|
+
]>;
|
|
87
|
+
}
|
|
88
|
+
declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
89
|
+
private readonly serializer;
|
|
90
|
+
private readonly baseUrl;
|
|
91
|
+
private readonly maxUrlLength;
|
|
92
|
+
private readonly fallbackMethod;
|
|
93
|
+
private readonly expectedMethod;
|
|
94
|
+
private readonly headers;
|
|
95
|
+
constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>);
|
|
96
|
+
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
|
|
97
|
+
decode(response: StandardLazyResponse): Promise<unknown>;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions {
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, type StandardRPCJsonSerializedMetaItem as a, type StandardRPCJsonSerialized as b, type StandardRPCCustomJsonSerializer as c, type StandardRPCJsonSerializerOptions as d, StandardRPCJsonSerializer as e, type StandardRPCLinkOptions as f, type StandardRPCLinkCodecOptions as g, StandardRPCLinkCodec as h, StandardRPCSerializer as i };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { intercept, isObject, value,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { O as ORPCError, m as mapEventIterator, t as toORPCError } from './client.BacCdg3F.mjs';
|
|
1
|
+
import { toArray, intercept, isObject, value, isAsyncIteratorObject, stringifyJSON } from '@orpc/shared';
|
|
2
|
+
import { mergeStandardHeaders, ErrorEvent } from '@orpc/standard-server';
|
|
3
|
+
import { b as isORPCErrorStatus, O as ORPCError, m as mapEventIterator, t as toORPCError } from './client.jKEwIsRd.mjs';
|
|
5
4
|
|
|
6
5
|
class InvalidEventIteratorRetryResponse extends Error {
|
|
7
6
|
}
|
|
@@ -9,10 +8,11 @@ class StandardLink {
|
|
|
9
8
|
constructor(codec, sender, options = {}) {
|
|
10
9
|
this.codec = codec;
|
|
11
10
|
this.sender = sender;
|
|
12
|
-
const plugin
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
this.
|
|
11
|
+
for (const plugin of toArray(options.plugins)) {
|
|
12
|
+
plugin.init?.(options);
|
|
13
|
+
}
|
|
14
|
+
this.interceptors = toArray(options.interceptors);
|
|
15
|
+
this.clientInterceptors = toArray(options.clientInterceptors);
|
|
16
16
|
}
|
|
17
17
|
interceptors;
|
|
18
18
|
clientInterceptors;
|
|
@@ -111,6 +111,9 @@ class StandardRPCJsonSerializer {
|
|
|
111
111
|
if (isObject(data)) {
|
|
112
112
|
const json = {};
|
|
113
113
|
for (const k in data) {
|
|
114
|
+
if (k === "toJSON" && typeof data[k] === "function") {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
114
117
|
json[k] = this.serialize(data[k], [...segments, k], meta, maps, blobs)[0];
|
|
115
118
|
}
|
|
116
119
|
return [json, meta, maps, blobs];
|
|
@@ -177,6 +180,10 @@ class StandardRPCJsonSerializer {
|
|
|
177
180
|
}
|
|
178
181
|
}
|
|
179
182
|
|
|
183
|
+
function toHttpPath(path) {
|
|
184
|
+
return `/${path.map(encodeURIComponent).join("/")}`;
|
|
185
|
+
}
|
|
186
|
+
|
|
180
187
|
class StandardRPCLinkCodec {
|
|
181
188
|
constructor(serializer, options) {
|
|
182
189
|
this.serializer = serializer;
|
|
@@ -193,17 +200,11 @@ class StandardRPCLinkCodec {
|
|
|
193
200
|
headers;
|
|
194
201
|
async encode(path, input, options) {
|
|
195
202
|
const expectedMethod = await value(this.expectedMethod, options, path, input);
|
|
196
|
-
|
|
203
|
+
let headers = await value(this.headers, options, path, input);
|
|
197
204
|
const baseUrl = await value(this.baseUrl, options, path, input);
|
|
198
|
-
const url = new URL(`${
|
|
205
|
+
const url = new URL(`${baseUrl.toString().replace(/\/$/, "")}${toHttpPath(path)}`);
|
|
199
206
|
if (options.lastEventId !== void 0) {
|
|
200
|
-
|
|
201
|
-
headers["last-event-id"] = [...headers["last-event-id"], options.lastEventId];
|
|
202
|
-
} else if (headers["last-event-id"] !== void 0) {
|
|
203
|
-
headers["last-event-id"] = [headers["last-event-id"], options.lastEventId];
|
|
204
|
-
} else {
|
|
205
|
-
headers["last-event-id"] = options.lastEventId;
|
|
206
|
-
}
|
|
207
|
+
headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
|
|
207
208
|
}
|
|
208
209
|
const serialized = this.serializer.serialize(input);
|
|
209
210
|
if (expectedMethod === "GET" && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) {
|
|
@@ -229,7 +230,7 @@ class StandardRPCLinkCodec {
|
|
|
229
230
|
};
|
|
230
231
|
}
|
|
231
232
|
async decode(response) {
|
|
232
|
-
const isOk = response.status
|
|
233
|
+
const isOk = !isORPCErrorStatus(response.status);
|
|
233
234
|
const deserialized = await (async () => {
|
|
234
235
|
let isBodyOk = false;
|
|
235
236
|
try {
|
|
@@ -251,8 +252,9 @@ class StandardRPCLinkCodec {
|
|
|
251
252
|
if (ORPCError.isValidJSON(deserialized)) {
|
|
252
253
|
throw ORPCError.fromJSON(deserialized);
|
|
253
254
|
}
|
|
254
|
-
throw new
|
|
255
|
-
|
|
255
|
+
throw new ORPCError("MALFORMED_ORPC_ERROR_RESPONSE", {
|
|
256
|
+
status: response.status,
|
|
257
|
+
data: deserialized
|
|
256
258
|
});
|
|
257
259
|
}
|
|
258
260
|
return deserialized;
|
|
@@ -328,4 +330,4 @@ class StandardRPCSerializer {
|
|
|
328
330
|
}
|
|
329
331
|
}
|
|
330
332
|
|
|
331
|
-
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 };
|
|
333
|
+
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, toHttpPath as t };
|
|
@@ -1,27 +1,30 @@
|
|
|
1
1
|
import { Interceptor } from '@orpc/shared';
|
|
2
2
|
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
3
|
-
import { a as ClientContext,
|
|
3
|
+
import { a as ClientContext, b as ClientOptions, C as ClientLink } from './client.87WXDX8t.mjs';
|
|
4
4
|
|
|
5
5
|
interface StandardLinkCodec<T extends ClientContext> {
|
|
6
|
-
encode(path: readonly string[], input: unknown, options:
|
|
7
|
-
decode(response: StandardLazyResponse, options:
|
|
6
|
+
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
|
|
7
|
+
decode(response: StandardLazyResponse, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<unknown>;
|
|
8
8
|
}
|
|
9
9
|
interface StandardLinkClient<T extends ClientContext> {
|
|
10
|
-
call(request: StandardRequest, options:
|
|
10
|
+
call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
declare class InvalidEventIteratorRetryResponse extends Error {
|
|
14
14
|
}
|
|
15
|
+
interface StandardLinkPlugin<T extends ClientContext> {
|
|
16
|
+
init?(options: StandardLinkOptions<T>): void;
|
|
17
|
+
}
|
|
15
18
|
interface StandardLinkOptions<T extends ClientContext> {
|
|
16
19
|
interceptors?: Interceptor<{
|
|
17
20
|
path: readonly string[];
|
|
18
21
|
input: unknown;
|
|
19
|
-
options:
|
|
22
|
+
options: ClientOptions<T>;
|
|
20
23
|
}, unknown, unknown>[];
|
|
21
24
|
clientInterceptors?: Interceptor<{
|
|
22
25
|
request: StandardRequest;
|
|
23
26
|
}, StandardLazyResponse, unknown>[];
|
|
24
|
-
plugins?:
|
|
27
|
+
plugins?: StandardLinkPlugin<T>[];
|
|
25
28
|
}
|
|
26
29
|
declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
27
30
|
#private;
|
|
@@ -30,16 +33,7 @@ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
|
30
33
|
private readonly interceptors;
|
|
31
34
|
private readonly clientInterceptors;
|
|
32
35
|
constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
|
|
33
|
-
call(path: readonly string[], input: unknown, options:
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
interface ClientPlugin<T extends ClientContext> {
|
|
37
|
-
init?(options: StandardLinkOptions<T>): void;
|
|
38
|
-
}
|
|
39
|
-
declare class CompositeClientPlugin<T extends ClientContext> implements ClientPlugin<T> {
|
|
40
|
-
private readonly plugins;
|
|
41
|
-
constructor(plugins?: ClientPlugin<T>[]);
|
|
42
|
-
init(options: StandardLinkOptions<T>): void;
|
|
36
|
+
call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
|
|
43
37
|
}
|
|
44
38
|
|
|
45
|
-
export {
|
|
39
|
+
export { InvalidEventIteratorRetryResponse as I, type StandardLinkPlugin as S, type StandardLinkOptions as a, StandardLink as b, type StandardLinkCodec as c, type StandardLinkClient as d };
|
|
@@ -91,8 +91,8 @@ class ORPCError extends Error {
|
|
|
91
91
|
status;
|
|
92
92
|
data;
|
|
93
93
|
constructor(code, ...[options]) {
|
|
94
|
-
if (options?.status && (options.status
|
|
95
|
-
throw new Error("[ORPCError]
|
|
94
|
+
if (options?.status && !isORPCErrorStatus(options.status)) {
|
|
95
|
+
throw new Error("[ORPCError] Invalid error status code.");
|
|
96
96
|
}
|
|
97
97
|
const message = fallbackORPCErrorMessage(code, options?.message);
|
|
98
98
|
super(message, options);
|
|
@@ -136,6 +136,9 @@ function toORPCError(error) {
|
|
|
136
136
|
cause: error
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
|
+
function isORPCErrorStatus(status) {
|
|
140
|
+
return status < 200 || status >= 400;
|
|
141
|
+
}
|
|
139
142
|
|
|
140
143
|
function mapEventIterator(iterator, maps) {
|
|
141
144
|
return async function* () {
|
|
@@ -169,4 +172,4 @@ function mapEventIterator(iterator, maps) {
|
|
|
169
172
|
}();
|
|
170
173
|
}
|
|
171
174
|
|
|
172
|
-
export { COMMON_ORPC_ERROR_DEFS as C, ORPCError as O, fallbackORPCErrorMessage as a, fallbackORPCErrorStatus as f, isDefinedError as i, mapEventIterator as m, toORPCError as t };
|
|
175
|
+
export { COMMON_ORPC_ERROR_DEFS as C, ORPCError as O, fallbackORPCErrorMessage as a, isORPCErrorStatus as b, fallbackORPCErrorStatus as f, isDefinedError as i, mapEventIterator as m, toORPCError as t };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/client",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.904b0c2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"dist"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@orpc/shared": "0.0.0-next.
|
|
43
|
-
"@orpc/standard-server-fetch": "0.0.0-next.
|
|
44
|
-
"@orpc/standard-server": "0.0.0-next.
|
|
42
|
+
"@orpc/shared": "0.0.0-next.904b0c2",
|
|
43
|
+
"@orpc/standard-server-fetch": "0.0.0-next.904b0c2",
|
|
44
|
+
"@orpc/standard-server": "0.0.0-next.904b0c2"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"zod": "^3.24.2"
|