@orpc/client 0.0.0-next.c59d67c → 0.0.0-next.d42488d
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/dist/index.js +27 -32
- package/dist/src/index.d.ts +4 -4
- package/dist/src/procedure-fetch-client.d.ts +24 -0
- package/dist/src/router-fetch-client.d.ts +6 -0
- package/package.json +6 -7
- package/dist/src/procedure.d.ts +0 -27
- package/dist/src/router.d.ts +0 -34
package/dist/index.js
CHANGED
@@ -1,32 +1,29 @@
|
|
1
|
-
// src/procedure.ts
|
2
|
-
import {
|
3
|
-
|
4
|
-
ORPC_HEADER_VALUE
|
5
|
-
} from "@orpc/contract";
|
6
|
-
import { trim } from "@orpc/shared";
|
1
|
+
// src/procedure-fetch-client.ts
|
2
|
+
import { ORPCPayloadCodec } from "@orpc/server/fetch";
|
3
|
+
import { ORPC_HANDLER_HEADER, ORPC_HANDLER_VALUE, trim } from "@orpc/shared";
|
7
4
|
import { ORPCError } from "@orpc/shared/error";
|
8
|
-
|
9
|
-
function
|
10
|
-
const
|
11
|
-
|
12
|
-
const client = async (input) => {
|
13
|
-
const fetch_ = options.fetch ?? fetch;
|
5
|
+
var payloadCodec = new ORPCPayloadCodec();
|
6
|
+
function createProcedureFetchClient(options) {
|
7
|
+
const client = async (...[input, callerOptions]) => {
|
8
|
+
const fetchClient = options.fetch ?? fetch;
|
14
9
|
const url = `${trim(options.baseURL, "/")}/${options.path.map(encodeURIComponent).join("/")}`;
|
15
|
-
|
16
|
-
headers =
|
17
|
-
|
18
|
-
|
19
|
-
|
10
|
+
const encoded = payloadCodec.encode(input);
|
11
|
+
const headers = new Headers(encoded.headers);
|
12
|
+
headers.append(ORPC_HANDLER_HEADER, ORPC_HANDLER_VALUE);
|
13
|
+
let customHeaders = await options.headers?.(input);
|
14
|
+
customHeaders = customHeaders instanceof Headers ? customHeaders : new Headers(customHeaders);
|
15
|
+
for (const [key, value] of customHeaders.entries()) {
|
16
|
+
headers.append(key, value);
|
20
17
|
}
|
21
|
-
|
22
|
-
const response = await fetch_(url, {
|
18
|
+
const response = await fetchClient(url, {
|
23
19
|
method: "POST",
|
24
20
|
headers,
|
25
|
-
body
|
21
|
+
body: encoded.body,
|
22
|
+
signal: callerOptions?.signal
|
26
23
|
});
|
27
24
|
const json = await (async () => {
|
28
25
|
try {
|
29
|
-
return await
|
26
|
+
return await payloadCodec.decode(response);
|
30
27
|
} catch (e) {
|
31
28
|
throw new ORPCError({
|
32
29
|
code: "INTERNAL_SERVER_ERROR",
|
@@ -47,14 +44,12 @@ function createProcedureClient(options) {
|
|
47
44
|
return client;
|
48
45
|
}
|
49
46
|
|
50
|
-
// src/router.ts
|
51
|
-
function
|
47
|
+
// src/router-fetch-client.ts
|
48
|
+
function createRouterFetchClient(options) {
|
52
49
|
const path = options?.path ?? [];
|
53
50
|
const client = new Proxy(
|
54
|
-
|
55
|
-
|
56
|
-
fetch: options.fetch,
|
57
|
-
headers: options.headers,
|
51
|
+
createProcedureFetchClient({
|
52
|
+
...options,
|
58
53
|
path
|
59
54
|
}),
|
60
55
|
{
|
@@ -62,7 +57,7 @@ function createRouterClient(options) {
|
|
62
57
|
if (typeof key !== "string") {
|
63
58
|
return Reflect.get(target, key);
|
64
59
|
}
|
65
|
-
return
|
60
|
+
return createRouterFetchClient({
|
66
61
|
...options,
|
67
62
|
path: [...path, key]
|
68
63
|
});
|
@@ -74,10 +69,10 @@ function createRouterClient(options) {
|
|
74
69
|
|
75
70
|
// src/index.ts
|
76
71
|
export * from "@orpc/shared/error";
|
77
|
-
var
|
72
|
+
var createORPCFetchClient = createRouterFetchClient;
|
78
73
|
export {
|
79
|
-
|
80
|
-
|
81
|
-
|
74
|
+
createORPCFetchClient,
|
75
|
+
createProcedureFetchClient,
|
76
|
+
createRouterFetchClient
|
82
77
|
};
|
83
78
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/** unnoq */
|
2
|
-
import {
|
3
|
-
export * from './procedure';
|
4
|
-
export * from './router';
|
2
|
+
import { createRouterFetchClient } from './router-fetch-client';
|
3
|
+
export * from './procedure-fetch-client';
|
4
|
+
export * from './router-fetch-client';
|
5
5
|
export * from '@orpc/shared/error';
|
6
|
-
export declare const
|
6
|
+
export declare const createORPCFetchClient: typeof createRouterFetchClient;
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import type { ProcedureClient } from '@orpc/server';
|
2
|
+
import type { Promisable } from '@orpc/shared';
|
3
|
+
export interface CreateProcedureClientOptions {
|
4
|
+
/**
|
5
|
+
* The base url of the server.
|
6
|
+
*/
|
7
|
+
baseURL: string;
|
8
|
+
/**
|
9
|
+
* The fetch function used to make the request.
|
10
|
+
* @default global fetch
|
11
|
+
*/
|
12
|
+
fetch?: typeof fetch;
|
13
|
+
/**
|
14
|
+
* The headers used to make the request.
|
15
|
+
* Invoked before the request is made.
|
16
|
+
*/
|
17
|
+
headers?: (input: unknown) => Promisable<Headers | Record<string, string>>;
|
18
|
+
/**
|
19
|
+
* The path of the procedure on server.
|
20
|
+
*/
|
21
|
+
path: string[];
|
22
|
+
}
|
23
|
+
export declare function createProcedureFetchClient<TInput, TOutput>(options: CreateProcedureClientOptions): ProcedureClient<TInput, TOutput>;
|
24
|
+
//# sourceMappingURL=procedure-fetch-client.d.ts.map
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import type { ContractRouter } from '@orpc/contract';
|
2
|
+
import type { ANY_ROUTER, RouterClient } from '@orpc/server';
|
3
|
+
import type { SetOptional } from '@orpc/shared';
|
4
|
+
import type { CreateProcedureClientOptions } from './procedure-fetch-client';
|
5
|
+
export declare function createRouterFetchClient<T extends ANY_ROUTER | ContractRouter>(options: SetOptional<CreateProcedureClientOptions, 'path'>): RouterClient<T>;
|
6
|
+
//# sourceMappingURL=router-fetch-client.d.ts.map
|
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.d42488d",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -29,16 +29,15 @@
|
|
29
29
|
"dist"
|
30
30
|
],
|
31
31
|
"peerDependencies": {
|
32
|
-
"@orpc/contract": "0.0.0-next.
|
33
|
-
"@orpc/server": "0.0.0-next.c59d67c"
|
32
|
+
"@orpc/contract": "0.0.0-next.d42488d"
|
34
33
|
},
|
35
34
|
"dependencies": {
|
36
|
-
"@orpc/shared": "0.0.0-next.
|
37
|
-
"@orpc/
|
35
|
+
"@orpc/shared": "0.0.0-next.d42488d",
|
36
|
+
"@orpc/server": "0.0.0-next.d42488d"
|
38
37
|
},
|
39
38
|
"devDependencies": {
|
40
|
-
"zod": "^3.
|
41
|
-
"@orpc/openapi": "0.0.0-next.
|
39
|
+
"zod": "^3.24.1",
|
40
|
+
"@orpc/openapi": "0.0.0-next.d42488d"
|
42
41
|
},
|
43
42
|
"scripts": {
|
44
43
|
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|
package/dist/src/procedure.d.ts
DELETED
@@ -1,27 +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>;
|
27
|
-
//# sourceMappingURL=procedure.d.ts.map
|
package/dist/src/router.d.ts
DELETED
@@ -1,34 +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;
|
34
|
-
//# sourceMappingURL=router.d.ts.map
|