@orpc/client 0.16.0 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js
CHANGED
@@ -1,31 +1,29 @@
|
|
1
|
-
// src/procedure.ts
|
2
|
-
import {
|
3
|
-
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";
|
4
4
|
import { ORPCError } from "@orpc/shared/error";
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
const client = async (...args) => {
|
10
|
-
const [input, callerOptions] = args;
|
11
|
-
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;
|
12
9
|
const url = `${trim(options.baseURL, "/")}/${options.path.map(encodeURIComponent).join("/")}`;
|
13
|
-
|
14
|
-
headers =
|
15
|
-
|
16
|
-
|
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()) {
|
17
16
|
headers.append(key, value);
|
18
17
|
}
|
19
|
-
|
20
|
-
const response = await fetch_(url, {
|
18
|
+
const response = await fetchClient(url, {
|
21
19
|
method: "POST",
|
22
20
|
headers,
|
23
|
-
body,
|
21
|
+
body: encoded.body,
|
24
22
|
signal: callerOptions?.signal
|
25
23
|
});
|
26
24
|
const json = await (async () => {
|
27
25
|
try {
|
28
|
-
return await
|
26
|
+
return await payloadCodec.decode(response);
|
29
27
|
} catch (e) {
|
30
28
|
throw new ORPCError({
|
31
29
|
code: "INTERNAL_SERVER_ERROR",
|
@@ -46,14 +44,12 @@ function createProcedureClient(options) {
|
|
46
44
|
return client;
|
47
45
|
}
|
48
46
|
|
49
|
-
// src/router.ts
|
50
|
-
function
|
47
|
+
// src/router-fetch-client.ts
|
48
|
+
function createRouterFetchClient(options) {
|
51
49
|
const path = options?.path ?? [];
|
52
50
|
const client = new Proxy(
|
53
|
-
|
54
|
-
|
55
|
-
fetch: options.fetch,
|
56
|
-
headers: options.headers,
|
51
|
+
createProcedureFetchClient({
|
52
|
+
...options,
|
57
53
|
path
|
58
54
|
}),
|
59
55
|
{
|
@@ -61,7 +57,7 @@ function createRouterClient(options) {
|
|
61
57
|
if (typeof key !== "string") {
|
62
58
|
return Reflect.get(target, key);
|
63
59
|
}
|
64
|
-
return
|
60
|
+
return createRouterFetchClient({
|
65
61
|
...options,
|
66
62
|
path: [...path, key]
|
67
63
|
});
|
@@ -73,10 +69,10 @@ function createRouterClient(options) {
|
|
73
69
|
|
74
70
|
// src/index.ts
|
75
71
|
export * from "@orpc/shared/error";
|
76
|
-
var
|
72
|
+
var createORPCFetchClient = createRouterFetchClient;
|
77
73
|
export {
|
78
|
-
|
79
|
-
|
80
|
-
|
74
|
+
createORPCFetchClient,
|
75
|
+
createProcedureFetchClient,
|
76
|
+
createRouterFetchClient
|
81
77
|
};
|
82
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
|
@@ -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.18.0",
|
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.
|
33
|
-
"@orpc/server": "0.16.0"
|
32
|
+
"@orpc/contract": "0.18.0"
|
34
33
|
},
|
35
34
|
"dependencies": {
|
36
|
-
"@orpc/
|
37
|
-
"@orpc/shared": "0.
|
35
|
+
"@orpc/server": "0.18.0",
|
36
|
+
"@orpc/shared": "0.18.0"
|
38
37
|
},
|
39
38
|
"devDependencies": {
|
40
39
|
"zod": "^3.24.1",
|
41
|
-
"@orpc/openapi": "0.
|
40
|
+
"@orpc/openapi": "0.18.0"
|
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/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
|