@orpc/client 0.0.0-next.ef3ba82 → 0.0.0-next.f01f7b1
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 +101 -0
- package/dist/adapters/fetch/index.d.mts +46 -0
- package/dist/adapters/fetch/index.d.ts +46 -0
- package/dist/adapters/fetch/index.mjs +46 -0
- package/dist/adapters/message-port/index.d.mts +80 -0
- package/dist/adapters/message-port/index.d.ts +80 -0
- package/dist/adapters/message-port/index.mjs +87 -0
- package/dist/adapters/standard/index.d.mts +11 -0
- package/dist/adapters/standard/index.d.ts +11 -0
- package/dist/adapters/standard/index.mjs +6 -0
- package/dist/adapters/websocket/index.d.mts +29 -0
- package/dist/adapters/websocket/index.d.ts +29 -0
- package/dist/adapters/websocket/index.mjs +47 -0
- package/dist/index.d.mts +230 -0
- package/dist/index.d.ts +230 -0
- package/dist/index.mjs +112 -0
- package/dist/plugins/index.d.mts +249 -0
- package/dist/plugins/index.d.ts +249 -0
- package/dist/plugins/index.mjs +485 -0
- package/dist/shared/client.2jUAqzYU.d.ts +45 -0
- package/dist/shared/client.B3pNRBih.d.ts +91 -0
- package/dist/shared/client.BFAVy68H.d.mts +91 -0
- package/dist/shared/client.BLtwTQUg.mjs +40 -0
- package/dist/shared/client.Bbef3nb6.mjs +398 -0
- package/dist/shared/client.BlehYYCS.mjs +171 -0
- package/dist/shared/client.CpCa3si8.d.mts +45 -0
- package/dist/shared/client.i2uoJbEp.d.mts +83 -0
- package/dist/shared/client.i2uoJbEp.d.ts +83 -0
- package/package.json +35 -17
- package/dist/index.js +0 -82
- package/dist/src/index.d.ts +0 -6
- package/dist/src/procedure.d.ts +0 -26
- package/dist/src/router.d.ts +0 -33
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Interceptor } from '@orpc/shared';
|
|
2
|
+
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
3
|
+
import { b as ClientContext, c as ClientOptions, C as ClientLink } from './client.i2uoJbEp.mjs';
|
|
4
|
+
|
|
5
|
+
interface StandardLinkPlugin<T extends ClientContext> {
|
|
6
|
+
order?: number;
|
|
7
|
+
init?(options: StandardLinkOptions<T>): void;
|
|
8
|
+
}
|
|
9
|
+
declare class CompositeStandardLinkPlugin<T extends ClientContext, TPlugin extends StandardLinkPlugin<T>> implements StandardLinkPlugin<T> {
|
|
10
|
+
protected readonly plugins: TPlugin[];
|
|
11
|
+
constructor(plugins?: readonly TPlugin[]);
|
|
12
|
+
init(options: StandardLinkOptions<T>): void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface StandardLinkCodec<T extends ClientContext> {
|
|
16
|
+
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
|
|
17
|
+
decode(response: StandardLazyResponse, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<unknown>;
|
|
18
|
+
}
|
|
19
|
+
interface StandardLinkClient<T extends ClientContext> {
|
|
20
|
+
call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
|
|
24
|
+
path: readonly string[];
|
|
25
|
+
input: unknown;
|
|
26
|
+
}
|
|
27
|
+
interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> {
|
|
28
|
+
request: StandardRequest;
|
|
29
|
+
}
|
|
30
|
+
interface StandardLinkOptions<T extends ClientContext> {
|
|
31
|
+
interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>[];
|
|
32
|
+
clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, Promise<StandardLazyResponse>>[];
|
|
33
|
+
plugins?: StandardLinkPlugin<T>[];
|
|
34
|
+
}
|
|
35
|
+
declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
36
|
+
readonly codec: StandardLinkCodec<T>;
|
|
37
|
+
readonly sender: StandardLinkClient<T>;
|
|
38
|
+
private readonly interceptors;
|
|
39
|
+
private readonly clientInterceptors;
|
|
40
|
+
constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
|
|
41
|
+
call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { CompositeStandardLinkPlugin as C, StandardLink as d };
|
|
45
|
+
export type { StandardLinkClientInterceptorOptions as S, StandardLinkPlugin as a, StandardLinkOptions as b, StandardLinkInterceptorOptions as c, StandardLinkCodec as e, StandardLinkClient as f };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { PromiseWithError } from '@orpc/shared';
|
|
2
|
+
|
|
3
|
+
type HTTPPath = `/${string}`;
|
|
4
|
+
type HTTPMethod = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
5
|
+
type ClientContext = Record<PropertyKey, any>;
|
|
6
|
+
interface ClientOptions<T extends ClientContext> {
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
lastEventId?: string | undefined;
|
|
9
|
+
context: T;
|
|
10
|
+
}
|
|
11
|
+
type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
12
|
+
context?: T;
|
|
13
|
+
} : {
|
|
14
|
+
context: T;
|
|
15
|
+
});
|
|
16
|
+
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>];
|
|
17
|
+
type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
|
|
18
|
+
interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
19
|
+
(...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
|
|
20
|
+
}
|
|
21
|
+
type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
|
|
22
|
+
[k: string]: NestedClient<TClientContext>;
|
|
23
|
+
};
|
|
24
|
+
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
|
25
|
+
interface ClientLink<TClientContext extends ClientContext> {
|
|
26
|
+
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Recursively infers the **input types** from a client.
|
|
30
|
+
*
|
|
31
|
+
* Produces a nested map where each endpoint's input type is preserved.
|
|
32
|
+
*/
|
|
33
|
+
type InferClientInputs<T extends NestedClient<any>> = T extends Client<any, infer U, any, any> ? U : {
|
|
34
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientInputs<T[K]> : never;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Recursively infers the **body input types** from a client.
|
|
38
|
+
*
|
|
39
|
+
* If an endpoint's input includes `{ body: ... }`, only the `body` portion is extracted.
|
|
40
|
+
* Produces a nested map of body input types.
|
|
41
|
+
*/
|
|
42
|
+
type InferClientBodyInputs<T extends NestedClient<any>> = T extends Client<any, infer U, any, any> ? U extends {
|
|
43
|
+
body: infer UBody;
|
|
44
|
+
} ? UBody : U : {
|
|
45
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientBodyInputs<T[K]> : never;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Recursively infers the **output types** from a client.
|
|
49
|
+
*
|
|
50
|
+
* Produces a nested map where each endpoint's output type is preserved.
|
|
51
|
+
*/
|
|
52
|
+
type InferClientOutputs<T extends NestedClient<any>> = T extends Client<any, any, infer U, any> ? U : {
|
|
53
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientOutputs<T[K]> : never;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Recursively infers the **body output types** from a client.
|
|
57
|
+
*
|
|
58
|
+
* If an endpoint's output includes `{ body: ... }`, only the `body` portion is extracted.
|
|
59
|
+
* Produces a nested map of body output types.
|
|
60
|
+
*/
|
|
61
|
+
type InferClientBodyOutputs<T extends NestedClient<any>> = T extends Client<any, any, infer U, any> ? U extends {
|
|
62
|
+
body: infer UBody;
|
|
63
|
+
} ? UBody : U : {
|
|
64
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientBodyOutputs<T[K]> : never;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Recursively infers the **error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#type‐safe-error-handling).
|
|
68
|
+
*
|
|
69
|
+
* Produces a nested map where each endpoint's error type is preserved.
|
|
70
|
+
*/
|
|
71
|
+
type InferClientErrors<T extends NestedClient<any>> = T extends Client<any, any, any, infer U> ? U : {
|
|
72
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientErrors<T[K]> : never;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Recursively infers a **union of all error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#type‐safe-error-handling).
|
|
76
|
+
*
|
|
77
|
+
* Useful when you want to handle all possible errors from any endpoint at once.
|
|
78
|
+
*/
|
|
79
|
+
type InferClientErrorUnion<T extends NestedClient<any>> = T extends Client<any, any, any, infer U> ? U : {
|
|
80
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientErrorUnion<T[K]> : never;
|
|
81
|
+
}[keyof T];
|
|
82
|
+
|
|
83
|
+
export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientPromiseResult as a, ClientContext as b, ClientOptions as c, Client as d, ClientRest as e, HTTPMethod as f, InferClientInputs as g, InferClientBodyInputs as h, InferClientOutputs as i, InferClientBodyOutputs as j, InferClientErrors as k, InferClientErrorUnion as l };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { PromiseWithError } from '@orpc/shared';
|
|
2
|
+
|
|
3
|
+
type HTTPPath = `/${string}`;
|
|
4
|
+
type HTTPMethod = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
5
|
+
type ClientContext = Record<PropertyKey, any>;
|
|
6
|
+
interface ClientOptions<T extends ClientContext> {
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
lastEventId?: string | undefined;
|
|
9
|
+
context: T;
|
|
10
|
+
}
|
|
11
|
+
type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
12
|
+
context?: T;
|
|
13
|
+
} : {
|
|
14
|
+
context: T;
|
|
15
|
+
});
|
|
16
|
+
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>];
|
|
17
|
+
type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
|
|
18
|
+
interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
19
|
+
(...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
|
|
20
|
+
}
|
|
21
|
+
type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
|
|
22
|
+
[k: string]: NestedClient<TClientContext>;
|
|
23
|
+
};
|
|
24
|
+
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
|
25
|
+
interface ClientLink<TClientContext extends ClientContext> {
|
|
26
|
+
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Recursively infers the **input types** from a client.
|
|
30
|
+
*
|
|
31
|
+
* Produces a nested map where each endpoint's input type is preserved.
|
|
32
|
+
*/
|
|
33
|
+
type InferClientInputs<T extends NestedClient<any>> = T extends Client<any, infer U, any, any> ? U : {
|
|
34
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientInputs<T[K]> : never;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Recursively infers the **body input types** from a client.
|
|
38
|
+
*
|
|
39
|
+
* If an endpoint's input includes `{ body: ... }`, only the `body` portion is extracted.
|
|
40
|
+
* Produces a nested map of body input types.
|
|
41
|
+
*/
|
|
42
|
+
type InferClientBodyInputs<T extends NestedClient<any>> = T extends Client<any, infer U, any, any> ? U extends {
|
|
43
|
+
body: infer UBody;
|
|
44
|
+
} ? UBody : U : {
|
|
45
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientBodyInputs<T[K]> : never;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Recursively infers the **output types** from a client.
|
|
49
|
+
*
|
|
50
|
+
* Produces a nested map where each endpoint's output type is preserved.
|
|
51
|
+
*/
|
|
52
|
+
type InferClientOutputs<T extends NestedClient<any>> = T extends Client<any, any, infer U, any> ? U : {
|
|
53
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientOutputs<T[K]> : never;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Recursively infers the **body output types** from a client.
|
|
57
|
+
*
|
|
58
|
+
* If an endpoint's output includes `{ body: ... }`, only the `body` portion is extracted.
|
|
59
|
+
* Produces a nested map of body output types.
|
|
60
|
+
*/
|
|
61
|
+
type InferClientBodyOutputs<T extends NestedClient<any>> = T extends Client<any, any, infer U, any> ? U extends {
|
|
62
|
+
body: infer UBody;
|
|
63
|
+
} ? UBody : U : {
|
|
64
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientBodyOutputs<T[K]> : never;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Recursively infers the **error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#type‐safe-error-handling).
|
|
68
|
+
*
|
|
69
|
+
* Produces a nested map where each endpoint's error type is preserved.
|
|
70
|
+
*/
|
|
71
|
+
type InferClientErrors<T extends NestedClient<any>> = T extends Client<any, any, any, infer U> ? U : {
|
|
72
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientErrors<T[K]> : never;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Recursively infers a **union of all error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#type‐safe-error-handling).
|
|
76
|
+
*
|
|
77
|
+
* Useful when you want to handle all possible errors from any endpoint at once.
|
|
78
|
+
*/
|
|
79
|
+
type InferClientErrorUnion<T extends NestedClient<any>> = T extends Client<any, any, any, infer U> ? U : {
|
|
80
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientErrorUnion<T[K]> : never;
|
|
81
|
+
}[keyof T];
|
|
82
|
+
|
|
83
|
+
export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientPromiseResult as a, ClientContext as b, ClientOptions as c, Client as d, ClientRest as e, HTTPMethod as f, InferClientInputs as g, InferClientBodyInputs as h, InferClientOutputs as i, InferClientBodyOutputs as j, InferClientErrors as k, InferClientErrorUnion as l };
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/client",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.f01f7b1",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"homepage": "https://orpc.
|
|
6
|
+
"homepage": "https://orpc.dev",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git+https://github.com/unnoq/orpc.git",
|
|
@@ -15,32 +15,50 @@
|
|
|
15
15
|
],
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
|
-
"types": "./dist/
|
|
19
|
-
"import": "./dist/index.
|
|
20
|
-
"default": "./dist/index.
|
|
18
|
+
"types": "./dist/index.d.mts",
|
|
19
|
+
"import": "./dist/index.mjs",
|
|
20
|
+
"default": "./dist/index.mjs"
|
|
21
21
|
},
|
|
22
|
-
"
|
|
23
|
-
"types": "./dist/
|
|
22
|
+
"./plugins": {
|
|
23
|
+
"types": "./dist/plugins/index.d.mts",
|
|
24
|
+
"import": "./dist/plugins/index.mjs",
|
|
25
|
+
"default": "./dist/plugins/index.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./standard": {
|
|
28
|
+
"types": "./dist/adapters/standard/index.d.mts",
|
|
29
|
+
"import": "./dist/adapters/standard/index.mjs",
|
|
30
|
+
"default": "./dist/adapters/standard/index.mjs"
|
|
31
|
+
},
|
|
32
|
+
"./fetch": {
|
|
33
|
+
"types": "./dist/adapters/fetch/index.d.mts",
|
|
34
|
+
"import": "./dist/adapters/fetch/index.mjs",
|
|
35
|
+
"default": "./dist/adapters/fetch/index.mjs"
|
|
36
|
+
},
|
|
37
|
+
"./websocket": {
|
|
38
|
+
"types": "./dist/adapters/websocket/index.d.mts",
|
|
39
|
+
"import": "./dist/adapters/websocket/index.mjs",
|
|
40
|
+
"default": "./dist/adapters/websocket/index.mjs"
|
|
41
|
+
},
|
|
42
|
+
"./message-port": {
|
|
43
|
+
"types": "./dist/adapters/message-port/index.d.mts",
|
|
44
|
+
"import": "./dist/adapters/message-port/index.mjs",
|
|
45
|
+
"default": "./dist/adapters/message-port/index.mjs"
|
|
24
46
|
}
|
|
25
47
|
},
|
|
26
48
|
"files": [
|
|
27
|
-
"!dist/*.tsbuildinfo",
|
|
28
49
|
"dist"
|
|
29
50
|
],
|
|
30
|
-
"peerDependencies": {
|
|
31
|
-
"@orpc/contract": "0.0.0-next.ef3ba82",
|
|
32
|
-
"@orpc/server": "0.0.0-next.ef3ba82"
|
|
33
|
-
},
|
|
34
51
|
"dependencies": {
|
|
35
|
-
"@orpc/shared": "0.0.0-next.
|
|
36
|
-
"@orpc/
|
|
52
|
+
"@orpc/shared": "0.0.0-next.f01f7b1",
|
|
53
|
+
"@orpc/standard-server": "0.0.0-next.f01f7b1",
|
|
54
|
+
"@orpc/standard-server-fetch": "0.0.0-next.f01f7b1",
|
|
55
|
+
"@orpc/standard-server-peer": "0.0.0-next.f01f7b1"
|
|
37
56
|
},
|
|
38
57
|
"devDependencies": {
|
|
39
|
-
"zod": "^
|
|
40
|
-
"@orpc/openapi": "0.0.0-next.ef3ba82"
|
|
58
|
+
"zod": "^4.1.12"
|
|
41
59
|
},
|
|
42
60
|
"scripts": {
|
|
43
|
-
"build": "
|
|
61
|
+
"build": "unbuild",
|
|
44
62
|
"build:watch": "pnpm run build --watch",
|
|
45
63
|
"type:check": "tsc -b"
|
|
46
64
|
}
|
package/dist/index.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
// src/procedure.ts
|
|
2
|
-
import {
|
|
3
|
-
ORPC_HEADER,
|
|
4
|
-
ORPC_HEADER_VALUE
|
|
5
|
-
} from "@orpc/contract";
|
|
6
|
-
import { trim } from "@orpc/shared";
|
|
7
|
-
import { ORPCError } from "@orpc/shared/error";
|
|
8
|
-
import { ORPCDeserializer, ORPCSerializer } from "@orpc/transformer";
|
|
9
|
-
function createProcedureClient(options) {
|
|
10
|
-
const serializer = new ORPCSerializer();
|
|
11
|
-
const deserializer = new ORPCDeserializer();
|
|
12
|
-
const client = async (input) => {
|
|
13
|
-
const fetch_ = options.fetch ?? fetch;
|
|
14
|
-
const url = `${trim(options.baseURL, "/")}/${options.path.map(encodeURIComponent).join("/")}`;
|
|
15
|
-
let headers = await options.headers?.(input);
|
|
16
|
-
headers = headers instanceof Headers ? headers : new Headers(headers);
|
|
17
|
-
const { body, headers: headers_ } = serializer.serialize(input);
|
|
18
|
-
for (const [key, value] of headers_.entries()) {
|
|
19
|
-
headers.set(key, value);
|
|
20
|
-
}
|
|
21
|
-
headers.set(ORPC_HEADER, ORPC_HEADER_VALUE);
|
|
22
|
-
const response = await fetch_(url, {
|
|
23
|
-
method: "POST",
|
|
24
|
-
headers,
|
|
25
|
-
body
|
|
26
|
-
});
|
|
27
|
-
const json = await (async () => {
|
|
28
|
-
try {
|
|
29
|
-
return await deserializer.deserialize(response);
|
|
30
|
-
} catch (e) {
|
|
31
|
-
throw new ORPCError({
|
|
32
|
-
code: "INTERNAL_SERVER_ERROR",
|
|
33
|
-
message: "Cannot parse response.",
|
|
34
|
-
cause: e
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
})();
|
|
38
|
-
if (!response.ok) {
|
|
39
|
-
throw ORPCError.fromJSON(json) ?? new ORPCError({
|
|
40
|
-
status: response.status,
|
|
41
|
-
code: "INTERNAL_SERVER_ERROR",
|
|
42
|
-
message: "Internal server error"
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
return json;
|
|
46
|
-
};
|
|
47
|
-
return client;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// src/router.ts
|
|
51
|
-
function createRouterClient(options) {
|
|
52
|
-
const path = options?.path ?? [];
|
|
53
|
-
const client = new Proxy(
|
|
54
|
-
createProcedureClient({
|
|
55
|
-
baseURL: options.baseURL,
|
|
56
|
-
fetch: options.fetch,
|
|
57
|
-
headers: options.headers,
|
|
58
|
-
path
|
|
59
|
-
}),
|
|
60
|
-
{
|
|
61
|
-
get(target, key) {
|
|
62
|
-
if (typeof key !== "string") {
|
|
63
|
-
return Reflect.get(target, key);
|
|
64
|
-
}
|
|
65
|
-
return createRouterClient({
|
|
66
|
-
...options,
|
|
67
|
-
path: [...path, key]
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
);
|
|
72
|
-
return client;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// src/index.ts
|
|
76
|
-
export * from "@orpc/shared/error";
|
|
77
|
-
var createORPCClient = createRouterClient;
|
|
78
|
-
export {
|
|
79
|
-
createORPCClient,
|
|
80
|
-
createProcedureClient,
|
|
81
|
-
createRouterClient
|
|
82
|
-
};
|
package/dist/src/index.d.ts
DELETED
package/dist/src/procedure.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { Promisable } from '@orpc/shared';
|
|
2
|
-
import { type Schema, type SchemaInput, type SchemaOutput } from '@orpc/contract';
|
|
3
|
-
export interface ProcedureClient<TInputSchema extends Schema, TOutputSchema extends Schema, TFuncOutput extends SchemaOutput<TOutputSchema>> {
|
|
4
|
-
(input: SchemaInput<TInputSchema>): Promise<SchemaOutput<TOutputSchema, TFuncOutput>>;
|
|
5
|
-
}
|
|
6
|
-
export interface CreateProcedureClientOptions {
|
|
7
|
-
/**
|
|
8
|
-
* The base url of the server.
|
|
9
|
-
*/
|
|
10
|
-
baseURL: string;
|
|
11
|
-
/**
|
|
12
|
-
* The fetch function used to make the request.
|
|
13
|
-
* @default global fetch
|
|
14
|
-
*/
|
|
15
|
-
fetch?: typeof fetch;
|
|
16
|
-
/**
|
|
17
|
-
* The headers used to make the request.
|
|
18
|
-
* Invoked before the request is made.
|
|
19
|
-
*/
|
|
20
|
-
headers?: (input: unknown) => Promisable<Headers | Record<string, string>>;
|
|
21
|
-
/**
|
|
22
|
-
* The path of the procedure on server.
|
|
23
|
-
*/
|
|
24
|
-
path: string[];
|
|
25
|
-
}
|
|
26
|
-
export declare function createProcedureClient<TInputSchema extends Schema, TOutputSchema extends Schema, TFuncOutput extends SchemaOutput<TOutputSchema>>(options: CreateProcedureClientOptions): ProcedureClient<TInputSchema, TOutputSchema, TFuncOutput>;
|
package/dist/src/router.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { ContractProcedure, ContractRouter, SchemaOutput } from '@orpc/contract';
|
|
2
|
-
import type { Procedure, Router } from '@orpc/server';
|
|
3
|
-
import type { Promisable } from '@orpc/shared';
|
|
4
|
-
import { type ProcedureClient } from './procedure';
|
|
5
|
-
export type RouterClientWithContractRouter<TRouter extends ContractRouter> = {
|
|
6
|
-
[K in keyof TRouter]: TRouter[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? ProcedureClient<UInputSchema, UOutputSchema, SchemaOutput<UOutputSchema>> : TRouter[K] extends ContractRouter ? RouterClientWithContractRouter<TRouter[K]> : never;
|
|
7
|
-
};
|
|
8
|
-
export type RouterClientWithRouter<TRouter extends Router<any>> = {
|
|
9
|
-
[K in keyof TRouter]: TRouter[K] extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> ? ProcedureClient<UInputSchema, UOutputSchema, UFuncOutput> : TRouter[K] extends Router<any> ? RouterClientWithRouter<TRouter[K]> : never;
|
|
10
|
-
};
|
|
11
|
-
export interface CreateRouterClientOptions {
|
|
12
|
-
/**
|
|
13
|
-
* The base url of the server.
|
|
14
|
-
*/
|
|
15
|
-
baseURL: string;
|
|
16
|
-
/**
|
|
17
|
-
* The fetch function used to make the request.
|
|
18
|
-
* @default global fetch
|
|
19
|
-
*/
|
|
20
|
-
fetch?: typeof fetch;
|
|
21
|
-
/**
|
|
22
|
-
* The headers used to make the request.
|
|
23
|
-
* Invoked before the request is made.
|
|
24
|
-
*/
|
|
25
|
-
headers?: (input: unknown) => Promisable<Headers | Record<string, string>>;
|
|
26
|
-
/**
|
|
27
|
-
* This used for internal purpose only.
|
|
28
|
-
*
|
|
29
|
-
* @internal
|
|
30
|
-
*/
|
|
31
|
-
path?: string[];
|
|
32
|
-
}
|
|
33
|
-
export declare function createRouterClient<TRouter extends Router<any> | ContractRouter>(options: CreateRouterClientOptions): TRouter extends Router<any> ? RouterClientWithRouter<TRouter> : TRouter extends ContractRouter ? RouterClientWithContractRouter<TRouter> : never;
|