@orpc/client 1.0.0-beta.3 → 1.0.0-beta.4
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 +6 -6
- package/dist/adapters/fetch/index.d.ts +6 -6
- package/dist/adapters/fetch/index.mjs +2 -3
- package/dist/adapters/standard/index.d.mts +8 -8
- package/dist/adapters/standard/index.d.ts +8 -8
- package/dist/adapters/standard/index.mjs +2 -3
- package/dist/index.d.mts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.mjs +32 -30
- package/dist/plugins/index.d.mts +7 -8
- package/dist/plugins/index.d.ts +7 -8
- package/dist/plugins/index.mjs +0 -1
- package/dist/shared/{client.aGal-uGY.d.ts → client.Bt40CWA-.d.ts} +11 -17
- package/dist/shared/{client.3Q53fveR.mjs → client.CAwgYDwB.mjs} +8 -8
- package/dist/shared/{client.DrOAzyMB.d.mts → client.CKw2tbcl.d.mts} +11 -17
- package/dist/shared/{client.CupM8eRP.d.mts → client.RZs5Myak.d.mts} +5 -5
- package/dist/shared/{client.CupM8eRP.d.ts → client.RZs5Myak.d.ts} +5 -5
- package/package.json +4 -4
- package/dist/shared/client.CvnV7_uV.mjs +0 -12
package/README.md
CHANGED
@@ -87,6 +87,14 @@ const client: RouterClient<typeof router> = createORPCClient(link)
|
|
87
87
|
const client: ContractRouterClient<typeof contract> = createORPCClient(link)
|
88
88
|
```
|
89
89
|
|
90
|
+
## Sponsors
|
91
|
+
|
92
|
+
<p align="center">
|
93
|
+
<a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
|
94
|
+
<img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
|
95
|
+
</a>
|
96
|
+
</p>
|
97
|
+
|
90
98
|
## License
|
91
99
|
|
92
100
|
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
@@ -1,18 +1,18 @@
|
|
1
1
|
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
2
2
|
import { ToFetchRequestOptions } from '@orpc/standard-server-fetch';
|
3
|
-
import { a as ClientContext, C as
|
4
|
-
import { b as StandardLinkClient } from '../../shared/client.
|
3
|
+
import { a as ClientContext, C as ClientOptions, b as ClientLink } from '../../shared/client.RZs5Myak.mjs';
|
4
|
+
import { b as StandardLinkClient } from '../../shared/client.CKw2tbcl.mjs';
|
5
5
|
import { StandardRPCLinkOptions } from '../standard/index.mjs';
|
6
6
|
import '@orpc/shared';
|
7
7
|
|
8
8
|
interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
|
9
|
-
fetch?: (request: Request, init: Record<never, never>, options:
|
9
|
+
fetch?: (request: Request, init: Record<never, never>, options: ClientOptions<T>, path: readonly string[], input: unknown) => Promise<Response>;
|
10
10
|
}
|
11
11
|
declare class LinkFetchClient<T extends ClientContext> implements StandardLinkClient<T> {
|
12
12
|
private readonly fetch;
|
13
13
|
private readonly toFetchRequestOptions;
|
14
14
|
constructor(options: LinkFetchClientOptions<T>);
|
15
|
-
call(request: StandardRequest, options:
|
15
|
+
call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
16
16
|
}
|
17
17
|
|
18
18
|
interface RPCLinkOptions<T extends ClientContext> extends StandardRPCLinkOptions<T>, LinkFetchClientOptions<T> {
|
@@ -20,11 +20,11 @@ interface RPCLinkOptions<T extends ClientContext> extends StandardRPCLinkOptions
|
|
20
20
|
declare class RPCLink<T extends ClientContext> implements ClientLink<T> {
|
21
21
|
private readonly standardLink;
|
22
22
|
constructor(options: RPCLinkOptions<T>);
|
23
|
-
call(path: readonly string[], input: unknown, options:
|
23
|
+
call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
|
24
24
|
}
|
25
25
|
|
26
26
|
interface FetchWithContext<TClientContext extends ClientContext> {
|
27
|
-
(url: URL, init: RequestInit, options:
|
27
|
+
(url: URL, init: RequestInit, options: ClientOptions<TClientContext>, path: readonly string[], input: unknown): Promise<Response>;
|
28
28
|
}
|
29
29
|
|
30
30
|
export { type FetchWithContext, LinkFetchClient, type LinkFetchClientOptions, RPCLink, type RPCLinkOptions };
|
@@ -1,18 +1,18 @@
|
|
1
1
|
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
2
2
|
import { ToFetchRequestOptions } from '@orpc/standard-server-fetch';
|
3
|
-
import { a as ClientContext, C as
|
4
|
-
import { b as StandardLinkClient } from '../../shared/client.
|
3
|
+
import { a as ClientContext, C as ClientOptions, b as ClientLink } from '../../shared/client.RZs5Myak.js';
|
4
|
+
import { b as StandardLinkClient } from '../../shared/client.Bt40CWA-.js';
|
5
5
|
import { StandardRPCLinkOptions } from '../standard/index.js';
|
6
6
|
import '@orpc/shared';
|
7
7
|
|
8
8
|
interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
|
9
|
-
fetch?: (request: Request, init: Record<never, never>, options:
|
9
|
+
fetch?: (request: Request, init: Record<never, never>, options: ClientOptions<T>, path: readonly string[], input: unknown) => Promise<Response>;
|
10
10
|
}
|
11
11
|
declare class LinkFetchClient<T extends ClientContext> implements StandardLinkClient<T> {
|
12
12
|
private readonly fetch;
|
13
13
|
private readonly toFetchRequestOptions;
|
14
14
|
constructor(options: LinkFetchClientOptions<T>);
|
15
|
-
call(request: StandardRequest, options:
|
15
|
+
call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
16
16
|
}
|
17
17
|
|
18
18
|
interface RPCLinkOptions<T extends ClientContext> extends StandardRPCLinkOptions<T>, LinkFetchClientOptions<T> {
|
@@ -20,11 +20,11 @@ interface RPCLinkOptions<T extends ClientContext> extends StandardRPCLinkOptions
|
|
20
20
|
declare class RPCLink<T extends ClientContext> implements ClientLink<T> {
|
21
21
|
private readonly standardLink;
|
22
22
|
constructor(options: RPCLinkOptions<T>);
|
23
|
-
call(path: readonly string[], input: unknown, options:
|
23
|
+
call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
|
24
24
|
}
|
25
25
|
|
26
26
|
interface FetchWithContext<TClientContext extends ClientContext> {
|
27
|
-
(url: URL, init: RequestInit, options:
|
27
|
+
(url: URL, init: RequestInit, options: ClientOptions<TClientContext>, path: readonly string[], input: unknown): Promise<Response>;
|
28
28
|
}
|
29
29
|
|
30
30
|
export { type FetchWithContext, LinkFetchClient, type LinkFetchClientOptions, RPCLink, type RPCLinkOptions };
|
@@ -1,9 +1,8 @@
|
|
1
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.
|
2
|
+
import { b as StandardRPCJsonSerializer, c as StandardRPCLinkCodec, d as StandardRPCSerializer, S as StandardLink } from '../../shared/client.CAwgYDwB.mjs';
|
3
3
|
import '@orpc/shared';
|
4
|
-
import '../../shared/client.CvnV7_uV.mjs';
|
5
|
-
import '@orpc/standard-server';
|
6
4
|
import '../../shared/client.BacCdg3F.mjs';
|
5
|
+
import '@orpc/standard-server';
|
7
6
|
|
8
7
|
class LinkFetchClient {
|
9
8
|
fetch;
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import { c as StandardLinkCodec,
|
2
|
-
export { I as InvalidEventIteratorRetryResponse, d as StandardLink, b as StandardLinkClient } from '../../shared/client.
|
1
|
+
import { c as StandardLinkCodec, a as StandardLinkOptions } from '../../shared/client.CKw2tbcl.mjs';
|
2
|
+
export { I as InvalidEventIteratorRetryResponse, d as StandardLink, b as StandardLinkClient, S as StandardLinkPlugin } from '../../shared/client.CKw2tbcl.mjs';
|
3
3
|
import { Segment, Value } from '@orpc/shared';
|
4
|
-
import { a as ClientContext, C as
|
4
|
+
import { a as ClientContext, C as ClientOptions } from '../../shared/client.RZs5Myak.mjs';
|
5
5
|
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
6
6
|
|
7
7
|
declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
|
@@ -47,7 +47,7 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
47
47
|
* Base url for all requests.
|
48
48
|
*/
|
49
49
|
url: Value<string | URL, [
|
50
|
-
options:
|
50
|
+
options: ClientOptions<T>,
|
51
51
|
path: readonly string[],
|
52
52
|
input: unknown
|
53
53
|
]>;
|
@@ -57,7 +57,7 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
57
57
|
* @default 2083
|
58
58
|
*/
|
59
59
|
maxUrlLength?: Value<number, [
|
60
|
-
options:
|
60
|
+
options: ClientOptions<T>,
|
61
61
|
path: readonly string[],
|
62
62
|
input: unknown
|
63
63
|
]>;
|
@@ -67,7 +67,7 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
67
67
|
* @default 'POST'
|
68
68
|
*/
|
69
69
|
method?: Value<HTTPMethod, [
|
70
|
-
options:
|
70
|
+
options: ClientOptions<T>,
|
71
71
|
path: readonly string[],
|
72
72
|
input: unknown
|
73
73
|
]>;
|
@@ -82,7 +82,7 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
82
82
|
* Inject headers to the request.
|
83
83
|
*/
|
84
84
|
headers?: Value<StandardHeaders, [
|
85
|
-
options:
|
85
|
+
options: ClientOptions<T>,
|
86
86
|
path: readonly string[],
|
87
87
|
input: unknown
|
88
88
|
]>;
|
@@ -95,7 +95,7 @@ declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardL
|
|
95
95
|
private readonly expectedMethod;
|
96
96
|
private readonly headers;
|
97
97
|
constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>);
|
98
|
-
encode(path: readonly string[], input: unknown, options:
|
98
|
+
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
|
99
99
|
decode(response: StandardLazyResponse): Promise<unknown>;
|
100
100
|
}
|
101
101
|
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import { c as StandardLinkCodec,
|
2
|
-
export { I as InvalidEventIteratorRetryResponse, d as StandardLink, b as StandardLinkClient } from '../../shared/client.
|
1
|
+
import { c as StandardLinkCodec, a as StandardLinkOptions } from '../../shared/client.Bt40CWA-.js';
|
2
|
+
export { I as InvalidEventIteratorRetryResponse, d as StandardLink, b as StandardLinkClient, S as StandardLinkPlugin } from '../../shared/client.Bt40CWA-.js';
|
3
3
|
import { Segment, Value } from '@orpc/shared';
|
4
|
-
import { a as ClientContext, C as
|
4
|
+
import { a as ClientContext, C as ClientOptions } from '../../shared/client.RZs5Myak.js';
|
5
5
|
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
6
6
|
|
7
7
|
declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
|
@@ -47,7 +47,7 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
47
47
|
* Base url for all requests.
|
48
48
|
*/
|
49
49
|
url: Value<string | URL, [
|
50
|
-
options:
|
50
|
+
options: ClientOptions<T>,
|
51
51
|
path: readonly string[],
|
52
52
|
input: unknown
|
53
53
|
]>;
|
@@ -57,7 +57,7 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
57
57
|
* @default 2083
|
58
58
|
*/
|
59
59
|
maxUrlLength?: Value<number, [
|
60
|
-
options:
|
60
|
+
options: ClientOptions<T>,
|
61
61
|
path: readonly string[],
|
62
62
|
input: unknown
|
63
63
|
]>;
|
@@ -67,7 +67,7 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
67
67
|
* @default 'POST'
|
68
68
|
*/
|
69
69
|
method?: Value<HTTPMethod, [
|
70
|
-
options:
|
70
|
+
options: ClientOptions<T>,
|
71
71
|
path: readonly string[],
|
72
72
|
input: unknown
|
73
73
|
]>;
|
@@ -82,7 +82,7 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
82
82
|
* Inject headers to the request.
|
83
83
|
*/
|
84
84
|
headers?: Value<StandardHeaders, [
|
85
|
-
options:
|
85
|
+
options: ClientOptions<T>,
|
86
86
|
path: readonly string[],
|
87
87
|
input: unknown
|
88
88
|
]>;
|
@@ -95,7 +95,7 @@ declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardL
|
|
95
95
|
private readonly expectedMethod;
|
96
96
|
private readonly headers;
|
97
97
|
constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>);
|
98
|
-
encode(path: readonly string[], input: unknown, options:
|
98
|
+
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
|
99
99
|
decode(response: StandardLazyResponse): Promise<unknown>;
|
100
100
|
}
|
101
101
|
|
@@ -1,5 +1,4 @@
|
|
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.
|
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.CAwgYDwB.mjs';
|
2
2
|
import '@orpc/shared';
|
3
|
-
import '../../shared/client.CvnV7_uV.mjs';
|
4
|
-
import '@orpc/standard-server';
|
5
3
|
import '../../shared/client.BacCdg3F.mjs';
|
4
|
+
import '@orpc/standard-server';
|
package/dist/index.d.mts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { N as NestedClient, b as ClientLink, I as InferClientContext, a as ClientContext, C as
|
2
|
-
export {
|
1
|
+
import { N as NestedClient, b as ClientLink, I as InferClientContext, a as ClientContext, C as ClientOptions, c as ClientPromiseResult, F as FriendlyClientOptions } from './shared/client.RZs5Myak.mjs';
|
2
|
+
export { e as Client, d as ClientRest } from './shared/client.RZs5Myak.mjs';
|
3
3
|
import { Promisable, MaybeOptionalOptions } from '@orpc/shared';
|
4
4
|
export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
5
5
|
export { ErrorEvent } from '@orpc/standard-server';
|
@@ -18,8 +18,8 @@ declare function createORPCClient<T extends NestedClient<any>>(link: ClientLink<
|
|
18
18
|
*/
|
19
19
|
declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
|
20
20
|
private readonly linkResolver;
|
21
|
-
constructor(linkResolver: (options:
|
22
|
-
call(path: readonly string[], input: unknown, options:
|
21
|
+
constructor(linkResolver: (options: ClientOptions<TClientContext>, path: readonly string[], input: unknown) => Promisable<ClientLink<TClientContext>>);
|
22
|
+
call(path: readonly string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
|
23
23
|
}
|
24
24
|
|
25
25
|
declare const COMMON_ORPC_ERROR_DEFS: {
|
@@ -146,5 +146,6 @@ type SafeResult<TOutput, TError extends Error> = [error: null, data: TOutput, is
|
|
146
146
|
isDefined: true;
|
147
147
|
};
|
148
148
|
declare function safe<TOutput, TError extends Error>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
|
149
|
+
declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
|
149
150
|
|
150
|
-
export { COMMON_ORPC_ERROR_DEFS, ClientContext, ClientLink,
|
151
|
+
export { COMMON_ORPC_ERROR_DEFS, ClientContext, ClientLink, ClientOptions, ClientPromiseResult, type CommonORPCErrorCode, DynamicLink, FriendlyClientOptions, InferClientContext, NestedClient, ORPCError, type ORPCErrorCode, type ORPCErrorJSON, type ORPCErrorOptions, type SafeResult, createORPCClient, type createORPCClientOptions, fallbackORPCErrorMessage, fallbackORPCErrorStatus, isDefinedError, mapEventIterator, resolveFriendlyClientOptions, safe, toORPCError };
|
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { N as NestedClient, b as ClientLink, I as InferClientContext, a as ClientContext, C as
|
2
|
-
export {
|
1
|
+
import { N as NestedClient, b as ClientLink, I as InferClientContext, a as ClientContext, C as ClientOptions, c as ClientPromiseResult, F as FriendlyClientOptions } from './shared/client.RZs5Myak.js';
|
2
|
+
export { e as Client, d as ClientRest } from './shared/client.RZs5Myak.js';
|
3
3
|
import { Promisable, MaybeOptionalOptions } from '@orpc/shared';
|
4
4
|
export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
5
5
|
export { ErrorEvent } from '@orpc/standard-server';
|
@@ -18,8 +18,8 @@ declare function createORPCClient<T extends NestedClient<any>>(link: ClientLink<
|
|
18
18
|
*/
|
19
19
|
declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
|
20
20
|
private readonly linkResolver;
|
21
|
-
constructor(linkResolver: (options:
|
22
|
-
call(path: readonly string[], input: unknown, options:
|
21
|
+
constructor(linkResolver: (options: ClientOptions<TClientContext>, path: readonly string[], input: unknown) => Promisable<ClientLink<TClientContext>>);
|
22
|
+
call(path: readonly string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
|
23
23
|
}
|
24
24
|
|
25
25
|
declare const COMMON_ORPC_ERROR_DEFS: {
|
@@ -146,5 +146,6 @@ type SafeResult<TOutput, TError extends Error> = [error: null, data: TOutput, is
|
|
146
146
|
isDefined: true;
|
147
147
|
};
|
148
148
|
declare function safe<TOutput, TError extends Error>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
|
149
|
+
declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
|
149
150
|
|
150
|
-
export { COMMON_ORPC_ERROR_DEFS, ClientContext, ClientLink,
|
151
|
+
export { COMMON_ORPC_ERROR_DEFS, ClientContext, ClientLink, ClientOptions, ClientPromiseResult, type CommonORPCErrorCode, DynamicLink, FriendlyClientOptions, InferClientContext, NestedClient, ORPCError, type ORPCErrorCode, type ORPCErrorJSON, type ORPCErrorOptions, type SafeResult, createORPCClient, type createORPCClientOptions, fallbackORPCErrorMessage, fallbackORPCErrorStatus, isDefinedError, mapEventIterator, resolveFriendlyClientOptions, safe, toORPCError };
|
package/dist/index.mjs
CHANGED
@@ -3,15 +3,39 @@ export { C as COMMON_ORPC_ERROR_DEFS, O as ORPCError, a as fallbackORPCErrorMess
|
|
3
3
|
export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
4
4
|
export { ErrorEvent } from '@orpc/standard-server';
|
5
5
|
|
6
|
+
async function safe(promise) {
|
7
|
+
try {
|
8
|
+
const output = await promise;
|
9
|
+
return Object.assign(
|
10
|
+
[null, output, false],
|
11
|
+
{ error: null, data: output, isDefined: false }
|
12
|
+
);
|
13
|
+
} catch (e) {
|
14
|
+
const error = e;
|
15
|
+
if (isDefinedError(error)) {
|
16
|
+
return Object.assign(
|
17
|
+
[error, void 0, true],
|
18
|
+
{ error, data: void 0, isDefined: true }
|
19
|
+
);
|
20
|
+
}
|
21
|
+
return Object.assign(
|
22
|
+
[error, void 0, false],
|
23
|
+
{ error, data: void 0, isDefined: false }
|
24
|
+
);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
function resolveFriendlyClientOptions(options) {
|
28
|
+
return {
|
29
|
+
...options,
|
30
|
+
context: options?.context ?? {}
|
31
|
+
// Context only optional if all fields are optional
|
32
|
+
};
|
33
|
+
}
|
34
|
+
|
6
35
|
function createORPCClient(link, options) {
|
7
36
|
const path = options?.path ?? [];
|
8
|
-
const procedureClient = async (...[input, options2]) => {
|
9
|
-
|
10
|
-
...options2,
|
11
|
-
context: options2?.context ?? {}
|
12
|
-
// options.context can be undefined when all field is optional
|
13
|
-
};
|
14
|
-
return await link.call(path, input, optionsOut);
|
37
|
+
const procedureClient = async (...[input, options2 = {}]) => {
|
38
|
+
return await link.call(path, input, resolveFriendlyClientOptions(options2));
|
15
39
|
};
|
16
40
|
const recursive = new Proxy(procedureClient, {
|
17
41
|
get(target, key) {
|
@@ -38,26 +62,4 @@ class DynamicLink {
|
|
38
62
|
}
|
39
63
|
}
|
40
64
|
|
41
|
-
|
42
|
-
try {
|
43
|
-
const output = await promise;
|
44
|
-
return Object.assign(
|
45
|
-
[null, output, false],
|
46
|
-
{ error: null, data: output, isDefined: false }
|
47
|
-
);
|
48
|
-
} catch (e) {
|
49
|
-
const error = e;
|
50
|
-
if (isDefinedError(error)) {
|
51
|
-
return Object.assign(
|
52
|
-
[error, void 0, true],
|
53
|
-
{ error, data: void 0, isDefined: true }
|
54
|
-
);
|
55
|
-
}
|
56
|
-
return Object.assign(
|
57
|
-
[error, void 0, false],
|
58
|
-
{ error, data: void 0, isDefined: false }
|
59
|
-
);
|
60
|
-
}
|
61
|
-
}
|
62
|
-
|
63
|
-
export { DynamicLink, createORPCClient, isDefinedError, safe };
|
65
|
+
export { DynamicLink, createORPCClient, isDefinedError, resolveFriendlyClientOptions, safe };
|
package/dist/plugins/index.d.mts
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
import { C as ClientPlugin, S as StandardLinkOptions } from '../shared/client.DrOAzyMB.mjs';
|
2
|
-
export { a as CompositeClientPlugin } from '../shared/client.DrOAzyMB.mjs';
|
3
1
|
import { Value } from '@orpc/shared';
|
4
|
-
import {
|
2
|
+
import { S as StandardLinkPlugin, a as StandardLinkOptions } from '../shared/client.CKw2tbcl.mjs';
|
3
|
+
import { C as ClientOptions } from '../shared/client.RZs5Myak.mjs';
|
5
4
|
import '@orpc/standard-server';
|
6
5
|
|
7
6
|
interface ClientRetryPluginAttemptOptions {
|
@@ -25,7 +24,7 @@ interface ClientRetryPluginContext {
|
|
25
24
|
*/
|
26
25
|
retryDelay?: Value<number, [
|
27
26
|
attemptOptions: ClientRetryPluginAttemptOptions,
|
28
|
-
clientOptions:
|
27
|
+
clientOptions: ClientOptions<ClientRetryPluginContext>,
|
29
28
|
path: readonly string[],
|
30
29
|
input: unknown
|
31
30
|
]>;
|
@@ -36,21 +35,21 @@ interface ClientRetryPluginContext {
|
|
36
35
|
*/
|
37
36
|
shouldRetry?: Value<boolean, [
|
38
37
|
attemptOptions: ClientRetryPluginAttemptOptions,
|
39
|
-
clientOptions:
|
38
|
+
clientOptions: ClientOptions<ClientRetryPluginContext>,
|
40
39
|
path: readonly string[],
|
41
40
|
input: unknown
|
42
41
|
]>;
|
43
42
|
/**
|
44
43
|
* The hook called when retrying, and return the unsubscribe function.
|
45
44
|
*/
|
46
|
-
onRetry?: (options: ClientRetryPluginAttemptOptions, clientOptions:
|
45
|
+
onRetry?: (options: ClientRetryPluginAttemptOptions, clientOptions: ClientOptions<ClientRetryPluginContext>, path: readonly string[], input: unknown) => void | (() => void);
|
47
46
|
}
|
48
47
|
declare class ClientRetryPluginInvalidEventIteratorRetryResponse extends Error {
|
49
48
|
}
|
50
49
|
interface ClientRetryPluginOptions {
|
51
50
|
default?: ClientRetryPluginContext;
|
52
51
|
}
|
53
|
-
declare class ClientRetryPlugin<T extends
|
52
|
+
declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements StandardLinkPlugin<T> {
|
54
53
|
private readonly defaultRetry;
|
55
54
|
private readonly defaultRetryDelay;
|
56
55
|
private readonly defaultShouldRetry;
|
@@ -59,4 +58,4 @@ declare class ClientRetryPlugin<T extends ClientContext & ClientRetryPluginConte
|
|
59
58
|
init(options: StandardLinkOptions<T>): void;
|
60
59
|
}
|
61
60
|
|
62
|
-
export {
|
61
|
+
export { ClientRetryPlugin, type ClientRetryPluginAttemptOptions, type ClientRetryPluginContext, ClientRetryPluginInvalidEventIteratorRetryResponse, type ClientRetryPluginOptions };
|
package/dist/plugins/index.d.ts
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
import { C as ClientPlugin, S as StandardLinkOptions } from '../shared/client.aGal-uGY.js';
|
2
|
-
export { a as CompositeClientPlugin } from '../shared/client.aGal-uGY.js';
|
3
1
|
import { Value } from '@orpc/shared';
|
4
|
-
import {
|
2
|
+
import { S as StandardLinkPlugin, a as StandardLinkOptions } from '../shared/client.Bt40CWA-.js';
|
3
|
+
import { C as ClientOptions } from '../shared/client.RZs5Myak.js';
|
5
4
|
import '@orpc/standard-server';
|
6
5
|
|
7
6
|
interface ClientRetryPluginAttemptOptions {
|
@@ -25,7 +24,7 @@ interface ClientRetryPluginContext {
|
|
25
24
|
*/
|
26
25
|
retryDelay?: Value<number, [
|
27
26
|
attemptOptions: ClientRetryPluginAttemptOptions,
|
28
|
-
clientOptions:
|
27
|
+
clientOptions: ClientOptions<ClientRetryPluginContext>,
|
29
28
|
path: readonly string[],
|
30
29
|
input: unknown
|
31
30
|
]>;
|
@@ -36,21 +35,21 @@ interface ClientRetryPluginContext {
|
|
36
35
|
*/
|
37
36
|
shouldRetry?: Value<boolean, [
|
38
37
|
attemptOptions: ClientRetryPluginAttemptOptions,
|
39
|
-
clientOptions:
|
38
|
+
clientOptions: ClientOptions<ClientRetryPluginContext>,
|
40
39
|
path: readonly string[],
|
41
40
|
input: unknown
|
42
41
|
]>;
|
43
42
|
/**
|
44
43
|
* The hook called when retrying, and return the unsubscribe function.
|
45
44
|
*/
|
46
|
-
onRetry?: (options: ClientRetryPluginAttemptOptions, clientOptions:
|
45
|
+
onRetry?: (options: ClientRetryPluginAttemptOptions, clientOptions: ClientOptions<ClientRetryPluginContext>, path: readonly string[], input: unknown) => void | (() => void);
|
47
46
|
}
|
48
47
|
declare class ClientRetryPluginInvalidEventIteratorRetryResponse extends Error {
|
49
48
|
}
|
50
49
|
interface ClientRetryPluginOptions {
|
51
50
|
default?: ClientRetryPluginContext;
|
52
51
|
}
|
53
|
-
declare class ClientRetryPlugin<T extends
|
52
|
+
declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements StandardLinkPlugin<T> {
|
54
53
|
private readonly defaultRetry;
|
55
54
|
private readonly defaultRetryDelay;
|
56
55
|
private readonly defaultShouldRetry;
|
@@ -59,4 +58,4 @@ declare class ClientRetryPlugin<T extends ClientContext & ClientRetryPluginConte
|
|
59
58
|
init(options: StandardLinkOptions<T>): void;
|
60
59
|
}
|
61
60
|
|
62
|
-
export {
|
61
|
+
export { ClientRetryPlugin, type ClientRetryPluginAttemptOptions, type ClientRetryPluginContext, ClientRetryPluginInvalidEventIteratorRetryResponse, type ClientRetryPluginOptions };
|
package/dist/plugins/index.mjs
CHANGED
@@ -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, C as
|
3
|
+
import { a as ClientContext, C as ClientOptions, b as ClientLink } from './client.RZs5Myak.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, type StandardLinkClient as b, type StandardLinkCodec as c, StandardLink as d };
|
@@ -1,7 +1,6 @@
|
|
1
|
-
import { intercept, isObject, value,
|
2
|
-
import { C as CompositeClientPlugin } from './client.CvnV7_uV.mjs';
|
3
|
-
import { ErrorEvent } from '@orpc/standard-server';
|
1
|
+
import { toArray, intercept, isObject, value, isAsyncIteratorObject, stringifyJSON } from '@orpc/shared';
|
4
2
|
import { O as ORPCError, m as mapEventIterator, t as toORPCError } from './client.BacCdg3F.mjs';
|
3
|
+
import { ErrorEvent } from '@orpc/standard-server';
|
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;
|
@@ -198,7 +198,7 @@ class StandardRPCLinkCodec {
|
|
198
198
|
const expectedMethod = await value(this.expectedMethod, options, path, input);
|
199
199
|
const headers = { ...await value(this.headers, options, path, input) };
|
200
200
|
const baseUrl = await value(this.baseUrl, options, path, input);
|
201
|
-
const url = new URL(`${
|
201
|
+
const url = new URL(`${baseUrl.toString().replace(/\/$/, "")}/${path.map(encodeURIComponent).join("/")}`);
|
202
202
|
if (options.lastEventId !== void 0) {
|
203
203
|
if (Array.isArray(headers["last-event-id"])) {
|
204
204
|
headers["last-event-id"] = [...headers["last-event-id"], options.lastEventId];
|
@@ -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, C as
|
3
|
+
import { a as ClientContext, C as ClientOptions, b as ClientLink } from './client.RZs5Myak.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, type StandardLinkClient as b, type StandardLinkCodec as c, StandardLink as d };
|
@@ -1,5 +1,5 @@
|
|
1
1
|
type ClientContext = Record<string, any>;
|
2
|
-
type
|
2
|
+
type FriendlyClientOptions<TClientContext extends ClientContext> = {
|
3
3
|
signal?: AbortSignal;
|
4
4
|
lastEventId?: string | undefined;
|
5
5
|
} & (Record<never, never> extends TClientContext ? {
|
@@ -7,7 +7,7 @@ type ClientOptions<TClientContext extends ClientContext> = {
|
|
7
7
|
} : {
|
8
8
|
context: TClientContext;
|
9
9
|
});
|
10
|
-
type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?:
|
10
|
+
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
11
|
type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
|
12
12
|
__error?: {
|
13
13
|
type: TError;
|
@@ -20,11 +20,11 @@ type NestedClient<TClientContext extends ClientContext> = Client<TClientContext,
|
|
20
20
|
[k: string]: NestedClient<TClientContext>;
|
21
21
|
};
|
22
22
|
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
23
|
-
type
|
23
|
+
type ClientOptions<TClientContext extends ClientContext> = FriendlyClientOptions<TClientContext> & {
|
24
24
|
context: TClientContext;
|
25
25
|
};
|
26
26
|
interface ClientLink<TClientContext extends ClientContext> {
|
27
|
-
call: (path: readonly string[], input: unknown, options:
|
27
|
+
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
28
28
|
}
|
29
29
|
|
30
|
-
export type {
|
30
|
+
export type { ClientOptions as C, FriendlyClientOptions as F, InferClientContext as I, NestedClient as N, ClientContext as a, ClientLink as b, ClientPromiseResult as c, ClientRest as d, Client as e };
|
@@ -1,5 +1,5 @@
|
|
1
1
|
type ClientContext = Record<string, any>;
|
2
|
-
type
|
2
|
+
type FriendlyClientOptions<TClientContext extends ClientContext> = {
|
3
3
|
signal?: AbortSignal;
|
4
4
|
lastEventId?: string | undefined;
|
5
5
|
} & (Record<never, never> extends TClientContext ? {
|
@@ -7,7 +7,7 @@ type ClientOptions<TClientContext extends ClientContext> = {
|
|
7
7
|
} : {
|
8
8
|
context: TClientContext;
|
9
9
|
});
|
10
|
-
type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?:
|
10
|
+
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
11
|
type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
|
12
12
|
__error?: {
|
13
13
|
type: TError;
|
@@ -20,11 +20,11 @@ type NestedClient<TClientContext extends ClientContext> = Client<TClientContext,
|
|
20
20
|
[k: string]: NestedClient<TClientContext>;
|
21
21
|
};
|
22
22
|
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
23
|
-
type
|
23
|
+
type ClientOptions<TClientContext extends ClientContext> = FriendlyClientOptions<TClientContext> & {
|
24
24
|
context: TClientContext;
|
25
25
|
};
|
26
26
|
interface ClientLink<TClientContext extends ClientContext> {
|
27
|
-
call: (path: readonly string[], input: unknown, options:
|
27
|
+
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
28
28
|
}
|
29
29
|
|
30
|
-
export type {
|
30
|
+
export type { ClientOptions as C, FriendlyClientOptions as F, InferClientContext as I, NestedClient as N, ClientContext as a, ClientLink as b, ClientPromiseResult as c, ClientRest as d, Client as e };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/client",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.0.0-beta.
|
4
|
+
"version": "1.0.0-beta.4",
|
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": "1.0.0-beta.
|
43
|
-
"@orpc/standard-server": "1.0.0-beta.
|
44
|
-
"@orpc/standard-server-fetch": "1.0.0-beta.
|
42
|
+
"@orpc/shared": "1.0.0-beta.4",
|
43
|
+
"@orpc/standard-server": "1.0.0-beta.4",
|
44
|
+
"@orpc/standard-server-fetch": "1.0.0-beta.4"
|
45
45
|
},
|
46
46
|
"devDependencies": {
|
47
47
|
"zod": "^3.24.2"
|