@orpc/client 0.0.0-next.aa72097 → 0.0.0-next.aac73c2

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.
@@ -0,0 +1,103 @@
1
+ import { a as ClientContext, b as ClientOptions, d as HTTPMethod } from './client.Bnaxb-CE.js';
2
+ import { c as StandardLinkCodec, a as StandardLinkOptions } from './client.BZZMKcrk.js';
3
+ import { Segment, Value } 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<string | URL, [
48
+ options: ClientOptions<T>,
49
+ path: readonly string[],
50
+ input: unknown
51
+ ]>;
52
+ /**
53
+ * The maximum length of the URL.
54
+ *
55
+ * @default 2083
56
+ */
57
+ maxUrlLength?: Value<number, [
58
+ options: ClientOptions<T>,
59
+ path: readonly string[],
60
+ input: unknown
61
+ ]>;
62
+ /**
63
+ * The method used to make the request.
64
+ *
65
+ * @default 'POST'
66
+ */
67
+ method?: Value<HTTPMethod, [
68
+ options: ClientOptions<T>,
69
+ path: readonly string[],
70
+ input: unknown
71
+ ]>;
72
+ /**
73
+ * The method to use when the payload cannot safely pass to the server with method return from method function.
74
+ * GET is not allowed, it's very dangerous.
75
+ *
76
+ * @default 'POST'
77
+ */
78
+ fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
79
+ /**
80
+ * Inject headers to the request.
81
+ */
82
+ headers?: Value<StandardHeaders, [
83
+ options: ClientOptions<T>,
84
+ path: readonly string[],
85
+ input: unknown
86
+ ]>;
87
+ }
88
+ declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
89
+ private readonly serializer;
90
+ private readonly baseUrl;
91
+ private readonly maxUrlLength;
92
+ private readonly fallbackMethod;
93
+ private readonly expectedMethod;
94
+ private readonly headers;
95
+ constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>);
96
+ encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
97
+ decode(response: StandardLazyResponse): Promise<unknown>;
98
+ }
99
+
100
+ interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions {
101
+ }
102
+
103
+ export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, type StandardRPCJsonSerializedMetaItem as a, type StandardRPCJsonSerialized as b, type StandardRPCCustomJsonSerializer as c, type StandardRPCJsonSerializerOptions as d, StandardRPCJsonSerializer as e, type StandardRPCLinkOptions as f, type StandardRPCLinkCodecOptions as g, StandardRPCLinkCodec as h, StandardRPCSerializer as i };
@@ -0,0 +1,103 @@
1
+ import { a as ClientContext, b as ClientOptions, d as HTTPMethod } from './client.Bnaxb-CE.mjs';
2
+ import { c as StandardLinkCodec, a as StandardLinkOptions } from './client.D_TnaeH1.mjs';
3
+ import { Segment, Value } 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<string | URL, [
48
+ options: ClientOptions<T>,
49
+ path: readonly string[],
50
+ input: unknown
51
+ ]>;
52
+ /**
53
+ * The maximum length of the URL.
54
+ *
55
+ * @default 2083
56
+ */
57
+ maxUrlLength?: Value<number, [
58
+ options: ClientOptions<T>,
59
+ path: readonly string[],
60
+ input: unknown
61
+ ]>;
62
+ /**
63
+ * The method used to make the request.
64
+ *
65
+ * @default 'POST'
66
+ */
67
+ method?: Value<HTTPMethod, [
68
+ options: ClientOptions<T>,
69
+ path: readonly string[],
70
+ input: unknown
71
+ ]>;
72
+ /**
73
+ * The method to use when the payload cannot safely pass to the server with method return from method function.
74
+ * GET is not allowed, it's very dangerous.
75
+ *
76
+ * @default 'POST'
77
+ */
78
+ fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
79
+ /**
80
+ * Inject headers to the request.
81
+ */
82
+ headers?: Value<StandardHeaders, [
83
+ options: ClientOptions<T>,
84
+ path: readonly string[],
85
+ input: unknown
86
+ ]>;
87
+ }
88
+ declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
89
+ private readonly serializer;
90
+ private readonly baseUrl;
91
+ private readonly maxUrlLength;
92
+ private readonly fallbackMethod;
93
+ private readonly expectedMethod;
94
+ private readonly headers;
95
+ constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>);
96
+ encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
97
+ decode(response: StandardLazyResponse): Promise<unknown>;
98
+ }
99
+
100
+ interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions {
101
+ }
102
+
103
+ export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, type StandardRPCJsonSerializedMetaItem as a, type StandardRPCJsonSerialized as b, type StandardRPCCustomJsonSerializer as c, type StandardRPCJsonSerializerOptions as d, StandardRPCJsonSerializer as e, type StandardRPCLinkOptions as f, type StandardRPCLinkCodecOptions as g, StandardRPCLinkCodec as h, StandardRPCSerializer as i };
@@ -0,0 +1,175 @@
1
+ import { isObject, isTypescriptObject } from '@orpc/shared';
2
+ import { getEventMeta, withEventMeta } from '@orpc/standard-server';
3
+
4
+ const COMMON_ORPC_ERROR_DEFS = {
5
+ BAD_REQUEST: {
6
+ status: 400,
7
+ message: "Bad Request"
8
+ },
9
+ UNAUTHORIZED: {
10
+ status: 401,
11
+ message: "Unauthorized"
12
+ },
13
+ FORBIDDEN: {
14
+ status: 403,
15
+ message: "Forbidden"
16
+ },
17
+ NOT_FOUND: {
18
+ status: 404,
19
+ message: "Not Found"
20
+ },
21
+ METHOD_NOT_SUPPORTED: {
22
+ status: 405,
23
+ message: "Method Not Supported"
24
+ },
25
+ NOT_ACCEPTABLE: {
26
+ status: 406,
27
+ message: "Not Acceptable"
28
+ },
29
+ TIMEOUT: {
30
+ status: 408,
31
+ message: "Request Timeout"
32
+ },
33
+ CONFLICT: {
34
+ status: 409,
35
+ message: "Conflict"
36
+ },
37
+ PRECONDITION_FAILED: {
38
+ status: 412,
39
+ message: "Precondition Failed"
40
+ },
41
+ PAYLOAD_TOO_LARGE: {
42
+ status: 413,
43
+ message: "Payload Too Large"
44
+ },
45
+ UNSUPPORTED_MEDIA_TYPE: {
46
+ status: 415,
47
+ message: "Unsupported Media Type"
48
+ },
49
+ UNPROCESSABLE_CONTENT: {
50
+ status: 422,
51
+ message: "Unprocessable Content"
52
+ },
53
+ TOO_MANY_REQUESTS: {
54
+ status: 429,
55
+ message: "Too Many Requests"
56
+ },
57
+ CLIENT_CLOSED_REQUEST: {
58
+ status: 499,
59
+ message: "Client Closed Request"
60
+ },
61
+ INTERNAL_SERVER_ERROR: {
62
+ status: 500,
63
+ message: "Internal Server Error"
64
+ },
65
+ NOT_IMPLEMENTED: {
66
+ status: 501,
67
+ message: "Not Implemented"
68
+ },
69
+ BAD_GATEWAY: {
70
+ status: 502,
71
+ message: "Bad Gateway"
72
+ },
73
+ SERVICE_UNAVAILABLE: {
74
+ status: 503,
75
+ message: "Service Unavailable"
76
+ },
77
+ GATEWAY_TIMEOUT: {
78
+ status: 504,
79
+ message: "Gateway Timeout"
80
+ }
81
+ };
82
+ function fallbackORPCErrorStatus(code, status) {
83
+ return status ?? COMMON_ORPC_ERROR_DEFS[code]?.status ?? 500;
84
+ }
85
+ function fallbackORPCErrorMessage(code, message) {
86
+ return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
87
+ }
88
+ class ORPCError extends Error {
89
+ defined;
90
+ code;
91
+ status;
92
+ data;
93
+ constructor(code, ...[options]) {
94
+ if (options?.status && !isORPCErrorStatus(options.status)) {
95
+ throw new Error("[ORPCError] Invalid error status code.");
96
+ }
97
+ const message = fallbackORPCErrorMessage(code, options?.message);
98
+ super(message, options);
99
+ this.code = code;
100
+ this.status = fallbackORPCErrorStatus(code, options?.status);
101
+ this.defined = options?.defined ?? false;
102
+ this.data = options?.data;
103
+ }
104
+ toJSON() {
105
+ return {
106
+ defined: this.defined,
107
+ code: this.code,
108
+ status: this.status,
109
+ message: this.message,
110
+ data: this.data
111
+ };
112
+ }
113
+ static fromJSON(json, options) {
114
+ return new ORPCError(json.code, {
115
+ ...options,
116
+ ...json
117
+ });
118
+ }
119
+ static isValidJSON(json) {
120
+ if (!isObject(json)) {
121
+ return false;
122
+ }
123
+ const validKeys = ["defined", "code", "status", "message", "data"];
124
+ if (Object.keys(json).some((k) => !validKeys.includes(k))) {
125
+ return false;
126
+ }
127
+ return "defined" in json && typeof json.defined === "boolean" && "code" in json && typeof json.code === "string" && "status" in json && typeof json.status === "number" && "message" in json && typeof json.message === "string";
128
+ }
129
+ }
130
+ function isDefinedError(error) {
131
+ return error instanceof ORPCError && error.defined;
132
+ }
133
+ function toORPCError(error) {
134
+ return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", {
135
+ message: "Internal server error",
136
+ cause: error
137
+ });
138
+ }
139
+ function isORPCErrorStatus(status) {
140
+ return status < 200 || status >= 400;
141
+ }
142
+
143
+ function mapEventIterator(iterator, maps) {
144
+ return async function* () {
145
+ try {
146
+ while (true) {
147
+ const { done, value } = await iterator.next();
148
+ let mappedValue = await maps.value(value, done);
149
+ if (mappedValue !== value) {
150
+ const meta = getEventMeta(value);
151
+ if (meta && isTypescriptObject(mappedValue)) {
152
+ mappedValue = withEventMeta(mappedValue, meta);
153
+ }
154
+ }
155
+ if (done) {
156
+ return mappedValue;
157
+ }
158
+ yield mappedValue;
159
+ }
160
+ } catch (error) {
161
+ let mappedError = await maps.error(error);
162
+ if (mappedError !== error) {
163
+ const meta = getEventMeta(error);
164
+ if (meta && isTypescriptObject(mappedError)) {
165
+ mappedError = withEventMeta(mappedError, meta);
166
+ }
167
+ }
168
+ throw mappedError;
169
+ } finally {
170
+ await iterator.return?.();
171
+ }
172
+ }();
173
+ }
174
+
175
+ export { COMMON_ORPC_ERROR_DEFS as C, ORPCError as O, fallbackORPCErrorMessage as a, isORPCErrorStatus as b, fallbackORPCErrorStatus as f, isDefinedError as i, mapEventIterator as m, toORPCError as t };
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.aa72097",
4
+ "version": "0.0.0-next.aac73c2",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -15,37 +15,39 @@
15
15
  ],
16
16
  "exports": {
17
17
  ".": {
18
- "types": "./dist/src/index.d.ts",
19
- "import": "./dist/index.js",
20
- "default": "./dist/index.js"
18
+ "types": "./dist/index.d.mts",
19
+ "import": "./dist/index.mjs",
20
+ "default": "./dist/index.mjs"
21
21
  },
22
- "./fetch": {
23
- "types": "./dist/src/adapters/fetch/index.d.ts",
24
- "import": "./dist/fetch.js",
25
- "default": "./dist/fetch.js"
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"
26
31
  },
27
- "./🔒/*": {
28
- "types": "./dist/src/*.d.ts"
32
+ "./fetch": {
33
+ "types": "./dist/adapters/fetch/index.d.mts",
34
+ "import": "./dist/adapters/fetch/index.mjs",
35
+ "default": "./dist/adapters/fetch/index.mjs"
29
36
  }
30
37
  },
31
38
  "files": [
32
- "!**/*.map",
33
- "!**/*.tsbuildinfo",
34
39
  "dist"
35
40
  ],
36
- "peerDependencies": {
37
- "@orpc/contract": "0.0.0-next.aa72097"
38
- },
39
41
  "dependencies": {
40
- "@orpc/server": "0.0.0-next.aa72097",
41
- "@orpc/shared": "0.0.0-next.aa72097"
42
+ "@orpc/shared": "0.0.0-next.aac73c2",
43
+ "@orpc/standard-server": "0.0.0-next.aac73c2",
44
+ "@orpc/standard-server-fetch": "0.0.0-next.aac73c2"
42
45
  },
43
46
  "devDependencies": {
44
- "zod": "^3.24.1",
45
- "@orpc/openapi": "0.0.0-next.aa72097"
47
+ "zod": "^3.24.2"
46
48
  },
47
49
  "scripts": {
48
- "build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.fetch=src/adapters/fetch/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
50
+ "build": "unbuild",
49
51
  "build:watch": "pnpm run build --watch",
50
52
  "type:check": "tsc -b"
51
53
  }
package/dist/fetch.js DELETED
@@ -1,87 +0,0 @@
1
- // src/adapters/fetch/orpc-link.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 ORPCLink = class {
6
- fetch;
7
- payloadCodec;
8
- maxURLLength;
9
- fallbackMethod;
10
- getMethod;
11
- getHeaders;
12
- url;
13
- constructor(options) {
14
- this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
15
- this.payloadCodec = options.payloadCodec ?? new ORPCPayloadCodec();
16
- this.maxURLLength = options.maxURLLength ?? 2083;
17
- this.fallbackMethod = options.fallbackMethod ?? "POST";
18
- this.url = options.url;
19
- this.getMethod = async (path, input, context) => {
20
- return await options.method?.(path, input, context) ?? this.fallbackMethod;
21
- };
22
- this.getHeaders = async (path, input, context) => {
23
- return new Headers(await options.headers?.(path, input, context));
24
- };
25
- }
26
- async call(path, input, options) {
27
- const clientContext = options.context;
28
- const encoded = await this.encode(path, input, options);
29
- const response = await this.fetch(encoded.url, {
30
- method: encoded.method,
31
- headers: encoded.headers,
32
- body: encoded.body,
33
- signal: options.signal
34
- }, clientContext);
35
- const decoded = await this.payloadCodec.decode(response);
36
- if (!response.ok) {
37
- const error = ORPCError.fromJSON(decoded) ?? new ORPCError({
38
- status: response.status,
39
- code: "INTERNAL_SERVER_ERROR",
40
- message: "Internal server error",
41
- cause: decoded
42
- });
43
- throw error;
44
- }
45
- return decoded;
46
- }
47
- async encode(path, input, options) {
48
- const clientContext = options.context;
49
- const expectMethod = await this.getMethod(path, input, clientContext);
50
- const methods = /* @__PURE__ */ new Set([expectMethod, this.fallbackMethod]);
51
- const baseHeaders = await this.getHeaders(path, input, clientContext);
52
- const baseUrl = new URL(`${trim(this.url, "/")}/${path.map(encodeURIComponent).join("/")}`);
53
- baseHeaders.append(ORPC_HANDLER_HEADER, ORPC_HANDLER_VALUE);
54
- for (const method of methods) {
55
- const url = new URL(baseUrl);
56
- const headers = new Headers(baseHeaders);
57
- const encoded = this.payloadCodec.encode(input, method, this.fallbackMethod);
58
- if (encoded.query) {
59
- for (const [key, value] of encoded.query.entries()) {
60
- url.searchParams.append(key, value);
61
- }
62
- }
63
- if (url.toString().length > this.maxURLLength) {
64
- continue;
65
- }
66
- if (encoded.headers) {
67
- for (const [key, value] of encoded.headers.entries()) {
68
- headers.append(key, value);
69
- }
70
- }
71
- return {
72
- url,
73
- headers,
74
- method: encoded.method,
75
- body: encoded.body
76
- };
77
- }
78
- throw new ORPCError({
79
- code: "BAD_REQUEST",
80
- message: "Cannot encode the request, please check the url length or payload."
81
- });
82
- }
83
- };
84
- export {
85
- ORPCLink
86
- };
87
- //# sourceMappingURL=fetch.js.map
package/dist/index.js DELETED
@@ -1,39 +0,0 @@
1
- // src/client.ts
2
- function createORPCClient(link, options) {
3
- const path = options?.path ?? [];
4
- const procedureClient = async (...[input, options2]) => {
5
- return await link.call(path, input, options2 ?? {});
6
- };
7
- const recursive = new Proxy(procedureClient, {
8
- get(target, key) {
9
- if (typeof key !== "string") {
10
- return Reflect.get(target, key);
11
- }
12
- return createORPCClient(link, {
13
- ...options,
14
- path: [...path, key]
15
- });
16
- }
17
- });
18
- return recursive;
19
- }
20
-
21
- // src/dynamic-link.ts
22
- var DynamicLink = class {
23
- constructor(linkResolver) {
24
- this.linkResolver = linkResolver;
25
- }
26
- async call(path, input, options) {
27
- const resolvedLink = await this.linkResolver(path, input, options.context);
28
- const output = await resolvedLink.call(path, input, options);
29
- return output;
30
- }
31
- };
32
-
33
- // src/index.ts
34
- export * from "@orpc/shared/error";
35
- export {
36
- DynamicLink,
37
- createORPCClient
38
- };
39
- //# sourceMappingURL=index.js.map
@@ -1,3 +0,0 @@
1
- export * from './orpc-link';
2
- export * from './types';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1,47 +0,0 @@
1
- import type { HTTPMethod } from '@orpc/contract';
2
- import type { ProcedureClientOptions } from '@orpc/server';
3
- import type { Promisable } from '@orpc/shared';
4
- import type { ClientLink } from '../../types';
5
- import type { FetchWithContext } from './types';
6
- import { type PublicORPCPayloadCodec } from '@orpc/server/fetch';
7
- export interface ORPCLinkOptions<TClientContext> {
8
- /**
9
- * Base url for all requests.
10
- */
11
- url: string;
12
- /**
13
- * The maximum length of the URL.
14
- *
15
- * @default 2083
16
- */
17
- maxURLLength?: number;
18
- /**
19
- * The method used to make the request.
20
- *
21
- * @default 'POST'
22
- */
23
- method?: (path: readonly string[], input: unknown, context: TClientContext) => Promisable<HTTPMethod | undefined>;
24
- /**
25
- * The method to use when the payload cannot safely pass to the server with method return from method function.
26
- * Do not use GET as fallback method, it's very dangerous.
27
- *
28
- * @default 'POST'
29
- */
30
- fallbackMethod?: HTTPMethod;
31
- headers?: (path: readonly string[], input: unknown, context: TClientContext) => Promisable<Headers | Record<string, string>>;
32
- fetch?: FetchWithContext<TClientContext>;
33
- payloadCodec?: PublicORPCPayloadCodec;
34
- }
35
- export declare class ORPCLink<TClientContext> implements ClientLink<TClientContext> {
36
- private readonly fetch;
37
- private readonly payloadCodec;
38
- private readonly maxURLLength;
39
- private readonly fallbackMethod;
40
- private readonly getMethod;
41
- private readonly getHeaders;
42
- private readonly url;
43
- constructor(options: ORPCLinkOptions<TClientContext>);
44
- call(path: readonly string[], input: unknown, options: ProcedureClientOptions<TClientContext>): Promise<unknown>;
45
- private encode;
46
- }
47
- //# sourceMappingURL=orpc-link.d.ts.map
@@ -1,4 +0,0 @@
1
- export interface FetchWithContext<TClientContext> {
2
- (input: RequestInfo | URL, init: RequestInit | undefined, context: TClientContext): Promise<Response>;
3
- }
4
- //# sourceMappingURL=types.d.ts.map
@@ -1,11 +0,0 @@
1
- import type { ContractRouter } from '@orpc/contract';
2
- import type { ANY_ROUTER, RouterClient } from '@orpc/server';
3
- import type { ClientLink } from './types';
4
- export interface createORPCClientOptions {
5
- /**
6
- * Use as base path for all procedure, useful when you only want to call a subset of the procedure.
7
- */
8
- path?: string[];
9
- }
10
- export declare function createORPCClient<TRouter extends ANY_ROUTER | ContractRouter, TClientContext = unknown>(link: ClientLink<TClientContext>, options?: createORPCClientOptions): RouterClient<TRouter, TClientContext>;
11
- //# sourceMappingURL=client.d.ts.map
@@ -1,13 +0,0 @@
1
- import type { ProcedureClientOptions } from '@orpc/server';
2
- import type { Promisable } from '@orpc/shared';
3
- import type { ClientLink } from './types';
4
- /**
5
- * DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
6
- * based on the request path, input, and context.
7
- */
8
- export declare class DynamicLink<TClientContext> implements ClientLink<TClientContext> {
9
- private readonly linkResolver;
10
- constructor(linkResolver: (path: readonly string[], input: unknown, context: TClientContext) => Promisable<ClientLink<TClientContext>>);
11
- call(path: readonly string[], input: unknown, options: ProcedureClientOptions<TClientContext>): Promise<unknown>;
12
- }
13
- //# sourceMappingURL=dynamic-link.d.ts.map
@@ -1,6 +0,0 @@
1
- /** unnoq */
2
- export * from './client';
3
- export * from './dynamic-link';
4
- export * from './types';
5
- export * from '@orpc/shared/error';
6
- //# sourceMappingURL=index.d.ts.map
@@ -1,5 +0,0 @@
1
- import type { ProcedureClientOptions } from '@orpc/server';
2
- export interface ClientLink<TClientContext> {
3
- call: (path: readonly string[], input: unknown, options: ProcedureClientOptions<TClientContext>) => Promise<unknown>;
4
- }
5
- //# sourceMappingURL=types.d.ts.map