@orpc/client 0.0.0-next.d42488d → 0.0.0-next.d4f9056
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 +101 -0
- package/dist/adapters/fetch/index.d.mts +46 -0
- package/dist/adapters/fetch/index.d.ts +46 -0
- package/dist/adapters/fetch/index.mjs +45 -0
- package/dist/adapters/message-port/index.d.mts +59 -0
- package/dist/adapters/message-port/index.d.ts +59 -0
- package/dist/adapters/message-port/index.mjs +72 -0
- package/dist/adapters/standard/index.d.mts +11 -0
- package/dist/adapters/standard/index.d.ts +11 -0
- package/dist/adapters/standard/index.mjs +5 -0
- package/dist/adapters/websocket/index.d.mts +29 -0
- package/dist/adapters/websocket/index.d.ts +29 -0
- package/dist/adapters/websocket/index.mjs +46 -0
- package/dist/index.d.mts +230 -0
- package/dist/index.d.ts +230 -0
- package/dist/index.mjs +111 -0
- package/dist/plugins/index.d.mts +203 -0
- package/dist/plugins/index.d.ts +203 -0
- package/dist/plugins/index.mjs +407 -0
- package/dist/shared/client.B7f1cdI2.mjs +208 -0
- package/dist/shared/client.BDTnZdQC.mjs +397 -0
- package/dist/shared/client.BG98rYdO.d.ts +45 -0
- package/dist/shared/client.BOYsZIRq.d.mts +29 -0
- package/dist/shared/client.BOYsZIRq.d.ts +29 -0
- package/dist/shared/client.Bwgm6dgk.d.mts +45 -0
- package/dist/shared/client.CVVVqf1Y.d.ts +91 -0
- package/dist/shared/client._Y_enhib.d.mts +91 -0
- package/package.json +34 -16
- package/dist/index.js +0 -78
- package/dist/src/index.d.ts +0 -7
- package/dist/src/procedure-fetch-client.d.ts +0 -24
- package/dist/src/router-fetch-client.d.ts +0 -6
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.BOYsZIRq.mjs';
|
|
2
|
+
import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.Bwgm6dgk.mjs';
|
|
3
|
+
import { Segment, Value, Promisable } from '@orpc/shared';
|
|
4
|
+
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
5
|
+
|
|
6
|
+
declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
|
|
7
|
+
readonly BIGINT: 0;
|
|
8
|
+
readonly DATE: 1;
|
|
9
|
+
readonly NAN: 2;
|
|
10
|
+
readonly UNDEFINED: 3;
|
|
11
|
+
readonly URL: 4;
|
|
12
|
+
readonly REGEXP: 5;
|
|
13
|
+
readonly SET: 6;
|
|
14
|
+
readonly MAP: 7;
|
|
15
|
+
};
|
|
16
|
+
type StandardRPCJsonSerializedMetaItem = readonly [type: number, ...path: Segment[]];
|
|
17
|
+
type StandardRPCJsonSerialized = [json: unknown, meta: StandardRPCJsonSerializedMetaItem[], maps: Segment[][], blobs: Blob[]];
|
|
18
|
+
interface StandardRPCCustomJsonSerializer {
|
|
19
|
+
type: number;
|
|
20
|
+
condition(data: unknown): boolean;
|
|
21
|
+
serialize(data: any): unknown;
|
|
22
|
+
deserialize(serialized: any): unknown;
|
|
23
|
+
}
|
|
24
|
+
interface StandardRPCJsonSerializerOptions {
|
|
25
|
+
customJsonSerializers?: readonly StandardRPCCustomJsonSerializer[];
|
|
26
|
+
}
|
|
27
|
+
declare class StandardRPCJsonSerializer {
|
|
28
|
+
private readonly customSerializers;
|
|
29
|
+
constructor(options?: StandardRPCJsonSerializerOptions);
|
|
30
|
+
serialize(data: unknown, segments?: Segment[], meta?: StandardRPCJsonSerializedMetaItem[], maps?: Segment[][], blobs?: Blob[]): StandardRPCJsonSerialized;
|
|
31
|
+
deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[]): unknown;
|
|
32
|
+
deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[], maps: readonly Segment[][], getBlob: (index: number) => Blob): unknown;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
declare class StandardRPCSerializer {
|
|
36
|
+
#private;
|
|
37
|
+
private readonly jsonSerializer;
|
|
38
|
+
constructor(jsonSerializer: StandardRPCJsonSerializer);
|
|
39
|
+
serialize(data: unknown): object;
|
|
40
|
+
deserialize(data: unknown): unknown;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
44
|
+
/**
|
|
45
|
+
* Base url for all requests.
|
|
46
|
+
*/
|
|
47
|
+
url: Value<Promisable<string | URL>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
48
|
+
/**
|
|
49
|
+
* The maximum length of the URL.
|
|
50
|
+
*
|
|
51
|
+
* @default 2083
|
|
52
|
+
*/
|
|
53
|
+
maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
54
|
+
/**
|
|
55
|
+
* The method used to make the request.
|
|
56
|
+
*
|
|
57
|
+
* @default 'POST'
|
|
58
|
+
*/
|
|
59
|
+
method?: Value<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
60
|
+
/**
|
|
61
|
+
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
|
62
|
+
* GET is not allowed, it's very dangerous.
|
|
63
|
+
*
|
|
64
|
+
* @default 'POST'
|
|
65
|
+
*/
|
|
66
|
+
fallbackMethod?: Exclude<HTTPMethod, 'HEAD' | 'GET'>;
|
|
67
|
+
/**
|
|
68
|
+
* Inject headers to the request.
|
|
69
|
+
*/
|
|
70
|
+
headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
71
|
+
}
|
|
72
|
+
declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
73
|
+
private readonly serializer;
|
|
74
|
+
private readonly baseUrl;
|
|
75
|
+
private readonly maxUrlLength;
|
|
76
|
+
private readonly fallbackMethod;
|
|
77
|
+
private readonly expectedMethod;
|
|
78
|
+
private readonly headers;
|
|
79
|
+
constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>);
|
|
80
|
+
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
|
|
81
|
+
decode(response: StandardLazyResponse): Promise<unknown>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions {
|
|
85
|
+
}
|
|
86
|
+
declare class StandardRPCLink<T extends ClientContext> extends StandardLink<T> {
|
|
87
|
+
constructor(linkClient: StandardLinkClient<T>, options: StandardRPCLinkOptions<T>);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, StandardRPCJsonSerializer as e, StandardRPCLink as g, StandardRPCLinkCodec as i, StandardRPCSerializer as j };
|
|
91
|
+
export type { StandardRPCJsonSerializedMetaItem as a, StandardRPCJsonSerialized as b, StandardRPCCustomJsonSerializer as c, StandardRPCJsonSerializerOptions as d, StandardRPCLinkOptions as f, StandardRPCLinkCodecOptions as h };
|
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.d4f9056",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -15,32 +15,50 @@
|
|
|
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"
|
|
36
|
+
},
|
|
37
|
+
"./websocket": {
|
|
38
|
+
"types": "./dist/adapters/websocket/index.d.mts",
|
|
39
|
+
"import": "./dist/adapters/websocket/index.mjs",
|
|
40
|
+
"default": "./dist/adapters/websocket/index.mjs"
|
|
41
|
+
},
|
|
42
|
+
"./message-port": {
|
|
43
|
+
"types": "./dist/adapters/message-port/index.d.mts",
|
|
44
|
+
"import": "./dist/adapters/message-port/index.mjs",
|
|
45
|
+
"default": "./dist/adapters/message-port/index.mjs"
|
|
24
46
|
}
|
|
25
47
|
},
|
|
26
48
|
"files": [
|
|
27
|
-
"!**/*.map",
|
|
28
|
-
"!**/*.tsbuildinfo",
|
|
29
49
|
"dist"
|
|
30
50
|
],
|
|
31
|
-
"peerDependencies": {
|
|
32
|
-
"@orpc/contract": "0.0.0-next.d42488d"
|
|
33
|
-
},
|
|
34
51
|
"dependencies": {
|
|
35
|
-
"@orpc/shared": "0.0.0-next.
|
|
36
|
-
"@orpc/server": "0.0.0-next.
|
|
52
|
+
"@orpc/shared": "0.0.0-next.d4f9056",
|
|
53
|
+
"@orpc/standard-server": "0.0.0-next.d4f9056",
|
|
54
|
+
"@orpc/standard-server-fetch": "0.0.0-next.d4f9056",
|
|
55
|
+
"@orpc/standard-server-peer": "0.0.0-next.d4f9056"
|
|
37
56
|
},
|
|
38
57
|
"devDependencies": {
|
|
39
|
-
"zod": "^
|
|
40
|
-
"@orpc/openapi": "0.0.0-next.d42488d"
|
|
58
|
+
"zod": "^4.1.11"
|
|
41
59
|
},
|
|
42
60
|
"scripts": {
|
|
43
|
-
"build": "
|
|
61
|
+
"build": "unbuild",
|
|
44
62
|
"build:watch": "pnpm run build --watch",
|
|
45
63
|
"type:check": "tsc -b"
|
|
46
64
|
}
|
package/dist/index.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
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
|
-
import { ORPCError } from "@orpc/shared/error";
|
|
5
|
-
var payloadCodec = new ORPCPayloadCodec();
|
|
6
|
-
function createProcedureFetchClient(options) {
|
|
7
|
-
const client = async (...[input, callerOptions]) => {
|
|
8
|
-
const fetchClient = options.fetch ?? fetch;
|
|
9
|
-
const url = `${trim(options.baseURL, "/")}/${options.path.map(encodeURIComponent).join("/")}`;
|
|
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);
|
|
17
|
-
}
|
|
18
|
-
const response = await fetchClient(url, {
|
|
19
|
-
method: "POST",
|
|
20
|
-
headers,
|
|
21
|
-
body: encoded.body,
|
|
22
|
-
signal: callerOptions?.signal
|
|
23
|
-
});
|
|
24
|
-
const json = await (async () => {
|
|
25
|
-
try {
|
|
26
|
-
return await payloadCodec.decode(response);
|
|
27
|
-
} catch (e) {
|
|
28
|
-
throw new ORPCError({
|
|
29
|
-
code: "INTERNAL_SERVER_ERROR",
|
|
30
|
-
message: "Cannot parse response.",
|
|
31
|
-
cause: e
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
})();
|
|
35
|
-
if (!response.ok) {
|
|
36
|
-
throw ORPCError.fromJSON(json) ?? new ORPCError({
|
|
37
|
-
status: response.status,
|
|
38
|
-
code: "INTERNAL_SERVER_ERROR",
|
|
39
|
-
message: "Internal server error"
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
return json;
|
|
43
|
-
};
|
|
44
|
-
return client;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// src/router-fetch-client.ts
|
|
48
|
-
function createRouterFetchClient(options) {
|
|
49
|
-
const path = options?.path ?? [];
|
|
50
|
-
const client = new Proxy(
|
|
51
|
-
createProcedureFetchClient({
|
|
52
|
-
...options,
|
|
53
|
-
path
|
|
54
|
-
}),
|
|
55
|
-
{
|
|
56
|
-
get(target, key) {
|
|
57
|
-
if (typeof key !== "string") {
|
|
58
|
-
return Reflect.get(target, key);
|
|
59
|
-
}
|
|
60
|
-
return createRouterFetchClient({
|
|
61
|
-
...options,
|
|
62
|
-
path: [...path, key]
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
);
|
|
67
|
-
return client;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// src/index.ts
|
|
71
|
-
export * from "@orpc/shared/error";
|
|
72
|
-
var createORPCFetchClient = createRouterFetchClient;
|
|
73
|
-
export {
|
|
74
|
-
createORPCFetchClient,
|
|
75
|
-
createProcedureFetchClient,
|
|
76
|
-
createRouterFetchClient
|
|
77
|
-
};
|
|
78
|
-
//# sourceMappingURL=index.js.map
|
package/dist/src/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/** unnoq */
|
|
2
|
-
import { createRouterFetchClient } from './router-fetch-client';
|
|
3
|
-
export * from './procedure-fetch-client';
|
|
4
|
-
export * from './router-fetch-client';
|
|
5
|
-
export * from '@orpc/shared/error';
|
|
6
|
-
export declare const createORPCFetchClient: typeof createRouterFetchClient;
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,24 +0,0 @@
|
|
|
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
|
|
@@ -1,6 +0,0 @@
|
|
|
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
|