@orpc/client 0.0.0-next.d137cdf → 0.0.0-next.d17ef5e
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 +100 -0
- package/dist/adapters/fetch/index.d.mts +30 -0
- package/dist/adapters/fetch/index.d.ts +30 -0
- package/dist/adapters/fetch/index.mjs +36 -0
- package/dist/adapters/standard/index.d.mts +105 -0
- package/dist/adapters/standard/index.d.ts +105 -0
- package/dist/adapters/standard/index.mjs +4 -0
- package/dist/index.d.mts +151 -0
- package/dist/index.d.ts +151 -0
- package/dist/index.mjs +65 -0
- package/dist/plugins/index.d.mts +61 -0
- package/dist/plugins/index.d.ts +61 -0
- package/dist/plugins/index.mjs +126 -0
- package/dist/shared/client.B1XjLWRe.mjs +334 -0
- package/dist/shared/client.BacCdg3F.mjs +172 -0
- package/dist/shared/client.Bt40CWA-.d.ts +39 -0
- package/dist/shared/client.CKw2tbcl.d.mts +39 -0
- package/dist/shared/client.RZs5Myak.d.mts +30 -0
- package/dist/shared/client.RZs5Myak.d.ts +30 -0
- package/package.json +23 -17
- package/dist/index.js +0 -83
- package/dist/src/index.d.ts +0 -7
- package/dist/src/procedure.d.ts +0 -27
- package/dist/src/router.d.ts +0 -34
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.d17ef5e",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -15,33 +15,39 @@
|
|
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"
|
24
36
|
}
|
25
37
|
},
|
26
38
|
"files": [
|
27
|
-
"!**/*.map",
|
28
|
-
"!**/*.tsbuildinfo",
|
29
39
|
"dist"
|
30
40
|
],
|
31
|
-
"peerDependencies": {
|
32
|
-
"@orpc/server": "0.0.0-next.d137cdf",
|
33
|
-
"@orpc/contract": "0.0.0-next.d137cdf"
|
34
|
-
},
|
35
41
|
"dependencies": {
|
36
|
-
"@orpc/shared": "0.0.0-next.
|
37
|
-
"@orpc/
|
42
|
+
"@orpc/shared": "0.0.0-next.d17ef5e",
|
43
|
+
"@orpc/standard-server": "0.0.0-next.d17ef5e",
|
44
|
+
"@orpc/standard-server-fetch": "0.0.0-next.d17ef5e"
|
38
45
|
},
|
39
46
|
"devDependencies": {
|
40
|
-
"zod": "^3.
|
41
|
-
"@orpc/openapi": "0.0.0-next.d137cdf"
|
47
|
+
"zod": "^3.24.2"
|
42
48
|
},
|
43
49
|
"scripts": {
|
44
|
-
"build": "
|
50
|
+
"build": "unbuild",
|
45
51
|
"build:watch": "pnpm run build --watch",
|
46
52
|
"type:check": "tsc -b"
|
47
53
|
}
|
package/dist/index.js
DELETED
@@ -1,83 +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
|
-
};
|
83
|
-
//# sourceMappingURL=index.js.map
|
package/dist/src/index.d.ts
DELETED
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 { Lazy, 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> | 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;
|
34
|
-
//# sourceMappingURL=router.d.ts.map
|