@orpc/client 0.16.0 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js
CHANGED
@@ -1,26 +1,29 @@
|
|
1
|
-
// src/procedure.ts
|
2
|
-
import {
|
3
|
-
import { trim } from "@orpc/shared";
|
1
|
+
// src/procedure-fetch-client.ts
|
2
|
+
import { ORPC_PROTOCOL_HEADER, ORPC_PROTOCOL_VALUE, trim } from "@orpc/shared";
|
4
3
|
import { ORPCError } from "@orpc/shared/error";
|
5
4
|
import { ORPCDeserializer, ORPCSerializer } from "@orpc/transformer";
|
6
5
|
var serializer = new ORPCSerializer();
|
7
6
|
var deserializer = new ORPCDeserializer();
|
8
|
-
function
|
9
|
-
const client = async (...
|
10
|
-
const
|
11
|
-
const fetch_ = options.fetch ?? fetch;
|
7
|
+
function createProcedureFetchClient(options) {
|
8
|
+
const client = async (...[input, callerOptions]) => {
|
9
|
+
const fetchClient = options.fetch ?? fetch;
|
12
10
|
const url = `${trim(options.baseURL, "/")}/${options.path.map(encodeURIComponent).join("/")}`;
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
const headers = new Headers({
|
12
|
+
[ORPC_PROTOCOL_HEADER]: ORPC_PROTOCOL_VALUE
|
13
|
+
});
|
14
|
+
let customHeaders = await options.headers?.(input);
|
15
|
+
customHeaders = customHeaders instanceof Headers ? customHeaders : new Headers(customHeaders);
|
16
|
+
for (const [key, value] of customHeaders.entries()) {
|
17
|
+
headers.append(key, value);
|
18
|
+
}
|
19
|
+
const serialized = serializer.serialize(input);
|
20
|
+
for (const [key, value] of serialized.headers.entries()) {
|
17
21
|
headers.append(key, value);
|
18
22
|
}
|
19
|
-
|
20
|
-
const response = await fetch_(url, {
|
23
|
+
const response = await fetchClient(url, {
|
21
24
|
method: "POST",
|
22
25
|
headers,
|
23
|
-
body,
|
26
|
+
body: serialized.body,
|
24
27
|
signal: callerOptions?.signal
|
25
28
|
});
|
26
29
|
const json = await (async () => {
|
@@ -46,14 +49,12 @@ function createProcedureClient(options) {
|
|
46
49
|
return client;
|
47
50
|
}
|
48
51
|
|
49
|
-
// src/router.ts
|
50
|
-
function
|
52
|
+
// src/router-fetch-client.ts
|
53
|
+
function createRouterFetchClient(options) {
|
51
54
|
const path = options?.path ?? [];
|
52
55
|
const client = new Proxy(
|
53
|
-
|
54
|
-
|
55
|
-
fetch: options.fetch,
|
56
|
-
headers: options.headers,
|
56
|
+
createProcedureFetchClient({
|
57
|
+
...options,
|
57
58
|
path
|
58
59
|
}),
|
59
60
|
{
|
@@ -61,7 +62,7 @@ function createRouterClient(options) {
|
|
61
62
|
if (typeof key !== "string") {
|
62
63
|
return Reflect.get(target, key);
|
63
64
|
}
|
64
|
-
return
|
65
|
+
return createRouterFetchClient({
|
65
66
|
...options,
|
66
67
|
path: [...path, key]
|
67
68
|
});
|
@@ -73,10 +74,10 @@ function createRouterClient(options) {
|
|
73
74
|
|
74
75
|
// src/index.ts
|
75
76
|
export * from "@orpc/shared/error";
|
76
|
-
var
|
77
|
+
var createORPCFetchClient = createRouterFetchClient;
|
77
78
|
export {
|
78
|
-
|
79
|
-
|
80
|
-
|
79
|
+
createORPCFetchClient,
|
80
|
+
createProcedureFetchClient,
|
81
|
+
createRouterFetchClient
|
81
82
|
};
|
82
83
|
//# 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
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type {
|
1
|
+
import type { ProcedureClient } from '@orpc/server';
|
2
2
|
import type { Promisable } from '@orpc/shared';
|
3
3
|
export interface CreateProcedureClientOptions {
|
4
4
|
/**
|
@@ -20,5 +20,5 @@ export interface CreateProcedureClientOptions {
|
|
20
20
|
*/
|
21
21
|
path: string[];
|
22
22
|
}
|
23
|
-
export declare function
|
24
|
-
//# sourceMappingURL=procedure.d.ts.map
|
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.
|
4
|
+
"version": "0.17.0",
|
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.
|
33
|
-
"@orpc/server": "0.
|
32
|
+
"@orpc/contract": "0.17.0",
|
33
|
+
"@orpc/server": "0.17.0"
|
34
34
|
},
|
35
35
|
"dependencies": {
|
36
|
-
"@orpc/
|
37
|
-
"@orpc/
|
36
|
+
"@orpc/shared": "0.17.0",
|
37
|
+
"@orpc/transformer": "0.17.0"
|
38
38
|
},
|
39
39
|
"devDependencies": {
|
40
40
|
"zod": "^3.24.1",
|
41
|
-
"@orpc/openapi": "0.
|
41
|
+
"@orpc/openapi": "0.17.0"
|
42
42
|
},
|
43
43
|
"scripts": {
|
44
44
|
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|
package/dist/src/router.d.ts
DELETED
@@ -1,9 +0,0 @@
|
|
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
|
-
};
|
8
|
-
export declare function createRouterClient<T extends Router<any> | ContractRouter>(options: SetOptional<CreateProcedureClientOptions, 'path'>): RouterClient<T>;
|
9
|
-
//# sourceMappingURL=router.d.ts.map
|