@orpc/client 0.0.0-next.db1f26d → 0.0.0-next.ee0aeaf
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +18 -15
- package/dist/src/procedure.d.ts +2 -5
- package/dist/src/router.d.ts +7 -32
- package/package.json +7 -7
package/dist/index.js
CHANGED
@@ -1,28 +1,31 @@
|
|
1
1
|
// src/procedure.ts
|
2
|
-
import {
|
3
|
-
ORPC_HEADER,
|
4
|
-
ORPC_HEADER_VALUE
|
5
|
-
} from "@orpc/contract";
|
6
|
-
import { trim } from "@orpc/shared";
|
2
|
+
import { ORPC_PROTOCOL_HEADER, ORPC_PROTOCOL_VALUE, trim } from "@orpc/shared";
|
7
3
|
import { ORPCError } from "@orpc/shared/error";
|
8
4
|
import { ORPCDeserializer, ORPCSerializer } from "@orpc/transformer";
|
5
|
+
var serializer = new ORPCSerializer();
|
6
|
+
var deserializer = new ORPCDeserializer();
|
9
7
|
function createProcedureClient(options) {
|
10
|
-
const
|
11
|
-
|
12
|
-
const client = async (input) => {
|
8
|
+
const client = async (...args) => {
|
9
|
+
const [input, callerOptions] = args;
|
13
10
|
const fetch_ = options.fetch ?? fetch;
|
14
11
|
const url = `${trim(options.baseURL, "/")}/${options.path.map(encodeURIComponent).join("/")}`;
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
const headers = new Headers({
|
13
|
+
[ORPC_PROTOCOL_HEADER]: ORPC_PROTOCOL_VALUE
|
14
|
+
});
|
15
|
+
let customHeaders = await options.headers?.(input);
|
16
|
+
customHeaders = customHeaders instanceof Headers ? customHeaders : new Headers(customHeaders);
|
17
|
+
for (const [key, value] of customHeaders.entries()) {
|
18
|
+
headers.append(key, value);
|
19
|
+
}
|
20
|
+
const serialized = serializer.serialize(input);
|
21
|
+
for (const [key, value] of serialized.headers.entries()) {
|
22
|
+
headers.append(key, value);
|
20
23
|
}
|
21
|
-
headers.set(ORPC_HEADER, ORPC_HEADER_VALUE);
|
22
24
|
const response = await fetch_(url, {
|
23
25
|
method: "POST",
|
24
26
|
headers,
|
25
|
-
body
|
27
|
+
body: serialized.body,
|
28
|
+
signal: callerOptions?.signal
|
26
29
|
});
|
27
30
|
const json = await (async () => {
|
28
31
|
try {
|
package/dist/src/procedure.d.ts
CHANGED
@@ -1,8 +1,5 @@
|
|
1
|
+
import type { Caller } from '@orpc/server';
|
1
2
|
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
3
|
export interface CreateProcedureClientOptions {
|
7
4
|
/**
|
8
5
|
* The base url of the server.
|
@@ -23,5 +20,5 @@ export interface CreateProcedureClientOptions {
|
|
23
20
|
*/
|
24
21
|
path: string[];
|
25
22
|
}
|
26
|
-
export declare function createProcedureClient<
|
23
|
+
export declare function createProcedureClient<TInput, TOutput>(options: CreateProcedureClientOptions): Caller<TInput, TOutput>;
|
27
24
|
//# sourceMappingURL=procedure.d.ts.map
|
package/dist/src/router.d.ts
CHANGED
@@ -1,34 +1,9 @@
|
|
1
|
-
import type { ContractProcedure, ContractRouter, SchemaOutput } from '@orpc/contract';
|
2
|
-
import type { Lazy, Procedure, Router } from '@orpc/server';
|
3
|
-
import type {
|
4
|
-
import {
|
5
|
-
export type
|
6
|
-
[K in keyof
|
1
|
+
import type { ContractProcedure, ContractRouter, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { Caller, Lazy, Procedure, Router } from '@orpc/server';
|
3
|
+
import type { SetOptional } from '@orpc/shared';
|
4
|
+
import type { CreateProcedureClientOptions } from './procedure';
|
5
|
+
export type RouterClient<T extends Router<any> | ContractRouter> = {
|
6
|
+
[K in keyof T]: T[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema> | Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> | Lazy<Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput>> ? Caller<SchemaInput<UInputSchema>, SchemaOutput<UOutputSchema, UFuncOutput>> : T[K] extends Router<any> | ContractRouter ? RouterClient<T[K]> : never;
|
7
7
|
};
|
8
|
-
export
|
9
|
-
[K in keyof TRouter]: TRouter[K] extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> | Lazy<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;
|
8
|
+
export declare function createRouterClient<T extends Router<any> | ContractRouter>(options: SetOptional<CreateProcedureClientOptions, 'path'>): RouterClient<T>;
|
34
9
|
//# sourceMappingURL=router.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.ee0aeaf",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -29,16 +29,16 @@
|
|
29
29
|
"dist"
|
30
30
|
],
|
31
31
|
"peerDependencies": {
|
32
|
-
"@orpc/contract": "0.0.0-next.
|
33
|
-
"@orpc/server": "0.0.0-next.
|
32
|
+
"@orpc/contract": "0.0.0-next.ee0aeaf",
|
33
|
+
"@orpc/server": "0.0.0-next.ee0aeaf"
|
34
34
|
},
|
35
35
|
"dependencies": {
|
36
|
-
"@orpc/shared": "0.0.0-next.
|
37
|
-
"@orpc/transformer": "0.0.0-next.
|
36
|
+
"@orpc/shared": "0.0.0-next.ee0aeaf",
|
37
|
+
"@orpc/transformer": "0.0.0-next.ee0aeaf"
|
38
38
|
},
|
39
39
|
"devDependencies": {
|
40
|
-
"zod": "^3.
|
41
|
-
"@orpc/openapi": "0.0.0-next.
|
40
|
+
"zod": "^3.24.1",
|
41
|
+
"@orpc/openapi": "0.0.0-next.ee0aeaf"
|
42
42
|
},
|
43
43
|
"scripts": {
|
44
44
|
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|