@orpc/client 0.0.0-next.caefe3a → 0.0.0-next.cc4cb21

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/dist/fetch.js CHANGED
@@ -1,43 +1,74 @@
1
- // src/adapters/fetch/orpc-link.ts
2
- import { ORPCError } from "@orpc/contract";
3
- import { fetchReToStandardBody } from "@orpc/server/fetch";
4
- import { RPCSerializer } from "@orpc/server/standard";
5
- import { isPlainObject, trim } from "@orpc/shared";
6
- import cd from "content-disposition";
1
+ import {
2
+ RPCSerializer
3
+ } from "./chunk-PGCPKPL5.js";
4
+ import {
5
+ ORPCError,
6
+ createAutoRetryEventIterator
7
+ } from "./chunk-7F3XVLRJ.js";
8
+
9
+ // src/adapters/fetch/rpc-link.ts
10
+ import { isAsyncIteratorObject, trim, value } from "@orpc/shared";
11
+ import { toFetchBody, toStandardBody } from "@orpc/standard-server-fetch";
12
+ var InvalidEventSourceRetryResponse = class extends Error {
13
+ };
7
14
  var RPCLink = class {
8
15
  fetch;
9
16
  rpcSerializer;
10
- maxURLLength;
17
+ maxUrlLength;
11
18
  fallbackMethod;
12
- getMethod;
13
- getHeaders;
19
+ method;
20
+ headers;
14
21
  url;
22
+ eventSourceMaxNumberOfRetries;
23
+ eventSourceRetryDelay;
24
+ eventSourceRetry;
15
25
  constructor(options) {
16
26
  this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
17
27
  this.rpcSerializer = options.rpcSerializer ?? new RPCSerializer();
18
- this.maxURLLength = options.maxURLLength ?? 2083;
28
+ this.maxUrlLength = options.maxUrlLength ?? 2083;
19
29
  this.fallbackMethod = options.fallbackMethod ?? "POST";
20
30
  this.url = options.url;
21
- this.getMethod = async (path, input, context) => {
22
- return await options.method?.(path, input, context) ?? this.fallbackMethod;
23
- };
24
- this.getHeaders = async (path, input, context) => {
25
- return new Headers(await options.headers?.(path, input, context));
26
- };
31
+ this.eventSourceMaxNumberOfRetries = options.eventSourceMaxNumberOfRetries ?? 5;
32
+ this.method = options.method ?? this.fallbackMethod;
33
+ this.headers = options.headers ?? {};
34
+ this.eventSourceRetry = options.eventSourceRetry ?? true;
35
+ this.eventSourceRetryDelay = options.eventSourceRetryDelay ?? (({ retryTimes, lastRetry }) => lastRetry ?? 1e3 * 2 ** retryTimes);
27
36
  }
28
37
  async call(path, input, options) {
29
- const clientContext = options.context;
30
- const encoded = await this.encode(path, input, options);
31
- if (encoded.body instanceof Blob && !encoded.headers.has("content-disposition")) {
32
- encoded.headers.set("content-disposition", cd(encoded.body instanceof File ? encoded.body.name : "blob"));
38
+ const output = await this.performCall(path, input, options);
39
+ if (!isAsyncIteratorObject(output)) {
40
+ return output;
41
+ }
42
+ return createAutoRetryEventIterator(output, async (reconnectOptions) => {
43
+ if (options.signal?.aborted || reconnectOptions.retryTimes > this.eventSourceMaxNumberOfRetries) {
44
+ return null;
45
+ }
46
+ if (!await value(this.eventSourceRetry, reconnectOptions, options, path, input)) {
47
+ return null;
48
+ }
49
+ const delay = await value(this.eventSourceRetryDelay, reconnectOptions, options, path, input);
50
+ await new Promise((resolve) => setTimeout(resolve, delay));
51
+ const updatedOptions = { ...options, lastEventId: reconnectOptions.lastEventId };
52
+ const maybeIterator = await this.performCall(path, input, updatedOptions);
53
+ if (!isAsyncIteratorObject(maybeIterator)) {
54
+ throw new InvalidEventSourceRetryResponse("Invalid EventSource retry response");
55
+ }
56
+ return maybeIterator;
57
+ }, void 0);
58
+ }
59
+ async performCall(path, input, options) {
60
+ const encoded = await this.encodeRequest(path, input, options);
61
+ const fetchBody = toFetchBody(encoded.body, encoded.headers);
62
+ if (options.lastEventId !== void 0) {
63
+ encoded.headers.set("last-event-id", options.lastEventId);
33
64
  }
34
65
  const response = await this.fetch(encoded.url, {
35
66
  method: encoded.method,
36
67
  headers: encoded.headers,
37
- body: encoded.body,
68
+ body: fetchBody,
38
69
  signal: options.signal
39
- }, clientContext);
40
- const body = await fetchReToStandardBody(response);
70
+ }, options, path, input);
71
+ const body = await toStandardBody(response);
41
72
  const deserialized = (() => {
42
73
  try {
43
74
  return this.rpcSerializer.deserialize(body);
@@ -53,51 +84,44 @@ var RPCLink = class {
53
84
  });
54
85
  }
55
86
  })();
56
- if (response.ok) {
57
- return deserialized;
87
+ if (!response.ok) {
88
+ if (ORPCError.isValidJSON(deserialized)) {
89
+ throw ORPCError.fromJSON(deserialized);
90
+ }
91
+ throw new ORPCError("INTERNAL_SERVER_ERROR", {
92
+ message: "Invalid RPC error response",
93
+ cause: deserialized
94
+ });
58
95
  }
59
- throw ORPCError.fromJSON(deserialized);
96
+ return deserialized;
60
97
  }
61
- async encode(path, input, options) {
62
- const clientContext = options.context;
63
- const expectMethod = await this.getMethod(path, input, clientContext);
64
- const headers = await this.getHeaders(path, input, clientContext);
98
+ async encodeRequest(path, input, options) {
99
+ const expectedMethod = await value(this.method, options, path, input);
100
+ const headers = new Headers(await value(this.headers, options, path, input));
65
101
  const url = new URL(`${trim(this.url, "/")}/${path.map(encodeURIComponent).join("/")}`);
66
- headers.append("x-orpc-handler", "rpc");
67
102
  const serialized = this.rpcSerializer.serialize(input);
68
- if (expectMethod === "GET" && isPlainObject(serialized)) {
69
- const tryURL = new URL(url);
70
- tryURL.searchParams.append("data", JSON.stringify(serialized));
71
- if (tryURL.toString().length <= this.maxURLLength) {
103
+ if (expectedMethod === "GET" && !(serialized instanceof FormData) && !(serialized instanceof Blob) && !isAsyncIteratorObject(serialized)) {
104
+ const getUrl = new URL(url);
105
+ getUrl.searchParams.append("data", JSON.stringify(serialized) ?? "");
106
+ if (getUrl.toString().length <= this.maxUrlLength) {
72
107
  return {
73
108
  body: void 0,
74
- method: expectMethod,
109
+ method: expectedMethod,
75
110
  headers,
76
- url: tryURL
111
+ url: getUrl
77
112
  };
78
113
  }
79
114
  }
80
- const method = expectMethod === "GET" ? this.fallbackMethod : expectMethod;
81
- if (isPlainObject(serialized)) {
82
- if (!headers.has("content-type")) {
83
- headers.set("content-type", "application/json");
84
- }
85
- return {
86
- body: JSON.stringify(serialized),
87
- method,
88
- headers,
89
- url
90
- };
91
- }
92
115
  return {
93
- body: serialized,
94
- method,
116
+ url,
117
+ method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod,
95
118
  headers,
96
- url
119
+ body: serialized
97
120
  };
98
121
  }
99
122
  };
100
123
  export {
124
+ InvalidEventSourceRetryResponse,
101
125
  RPCLink
102
126
  };
103
127
  //# sourceMappingURL=fetch.js.map
package/dist/index.js CHANGED
@@ -1,8 +1,27 @@
1
+ import {
2
+ COMMON_ORPC_ERROR_DEFS,
3
+ ORPCError,
4
+ createAutoRetryEventIterator,
5
+ fallbackORPCErrorMessage,
6
+ fallbackORPCErrorStatus,
7
+ isDefinedError,
8
+ mapEventIterator,
9
+ onEventIteratorStatusChange,
10
+ registerEventIteratorState,
11
+ toORPCError,
12
+ updateEventIteratorStatus
13
+ } from "./chunk-7F3XVLRJ.js";
14
+
1
15
  // src/client.ts
2
16
  function createORPCClient(link, options) {
3
17
  const path = options?.path ?? [];
4
18
  const procedureClient = async (...[input, options2]) => {
5
- return await link.call(path, input, options2 ?? {});
19
+ const optionsOut = {
20
+ ...options2,
21
+ context: options2?.context ?? {}
22
+ // options.context can be undefined when all field is optional
23
+ };
24
+ return await link.call(path, input, optionsOut);
6
25
  };
7
26
  const recursive = new Proxy(procedureClient, {
8
27
  get(target, key) {
@@ -24,19 +43,48 @@ var DynamicLink = class {
24
43
  this.linkResolver = linkResolver;
25
44
  }
26
45
  async call(path, input, options) {
27
- const resolvedLink = await this.linkResolver(path, input, options.context);
46
+ const resolvedLink = await this.linkResolver(options, path, input);
28
47
  const output = await resolvedLink.call(path, input, options);
29
48
  return output;
30
49
  }
31
50
  };
32
51
 
33
- // src/index.ts
34
- import { isDefinedError, ORPCError, safe } from "@orpc/contract";
52
+ // src/utils.ts
53
+ async function safe(promise) {
54
+ try {
55
+ const output = await promise;
56
+ return Object.assign(
57
+ [null, output, false],
58
+ { error: null, data: output, isDefined: false }
59
+ );
60
+ } catch (e) {
61
+ const error = e;
62
+ if (isDefinedError(error)) {
63
+ return Object.assign(
64
+ [error, void 0, true],
65
+ { error, data: void 0, isDefined: true }
66
+ );
67
+ }
68
+ return Object.assign(
69
+ [error, void 0, false],
70
+ { error, data: void 0, isDefined: false }
71
+ );
72
+ }
73
+ }
35
74
  export {
75
+ COMMON_ORPC_ERROR_DEFS,
36
76
  DynamicLink,
37
77
  ORPCError,
78
+ createAutoRetryEventIterator,
38
79
  createORPCClient,
80
+ fallbackORPCErrorMessage,
81
+ fallbackORPCErrorStatus,
39
82
  isDefinedError,
40
- safe
83
+ mapEventIterator,
84
+ onEventIteratorStatusChange,
85
+ registerEventIteratorState,
86
+ safe,
87
+ toORPCError,
88
+ updateEventIteratorStatus
41
89
  };
42
90
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,232 @@
1
+ import {
2
+ ORPCError,
3
+ mapEventIterator,
4
+ toORPCError
5
+ } from "./chunk-7F3XVLRJ.js";
6
+
7
+ // src/openapi/bracket-notation.ts
8
+ import { isObject } from "@orpc/shared";
9
+ var BracketNotationSerializer = class {
10
+ serialize(data, segments = [], result = []) {
11
+ if (Array.isArray(data)) {
12
+ data.forEach((item, i) => {
13
+ this.serialize(item, [...segments, i], result);
14
+ });
15
+ } else if (isObject(data)) {
16
+ for (const key in data) {
17
+ this.serialize(data[key], [...segments, key], result);
18
+ }
19
+ } else {
20
+ result.push([this.stringifyPath(segments), data]);
21
+ }
22
+ return result;
23
+ }
24
+ deserialize(serialized) {
25
+ const arrayPushStyles = /* @__PURE__ */ new WeakSet();
26
+ const ref = { value: [] };
27
+ for (const [path, value] of serialized) {
28
+ const segments = this.parsePath(path);
29
+ let currentRef = ref;
30
+ let nextSegment = "value";
31
+ segments.forEach((segment, i) => {
32
+ if (!Array.isArray(currentRef[nextSegment]) && !isObject(currentRef[nextSegment])) {
33
+ currentRef[nextSegment] = [];
34
+ }
35
+ if (i !== segments.length - 1) {
36
+ if (Array.isArray(currentRef[nextSegment]) && !isValidArrayIndex(segment)) {
37
+ currentRef[nextSegment] = { ...currentRef[nextSegment] };
38
+ }
39
+ } else {
40
+ if (Array.isArray(currentRef[nextSegment])) {
41
+ if (segment === "") {
42
+ if (currentRef[nextSegment].length && !arrayPushStyles.has(currentRef[nextSegment])) {
43
+ currentRef[nextSegment] = { ...currentRef[nextSegment] };
44
+ }
45
+ } else {
46
+ if (arrayPushStyles.has(currentRef[nextSegment])) {
47
+ currentRef[nextSegment] = { "": currentRef[nextSegment].at(-1) };
48
+ } else if (!isValidArrayIndex(segment)) {
49
+ currentRef[nextSegment] = { ...currentRef[nextSegment] };
50
+ }
51
+ }
52
+ }
53
+ }
54
+ currentRef = currentRef[nextSegment];
55
+ nextSegment = segment;
56
+ });
57
+ if (Array.isArray(currentRef)) {
58
+ if (nextSegment === "") {
59
+ arrayPushStyles.add(currentRef);
60
+ currentRef.push(value);
61
+ } else {
62
+ currentRef[Number(nextSegment)] = value;
63
+ }
64
+ } else {
65
+ currentRef[nextSegment] = value;
66
+ }
67
+ }
68
+ return ref.value;
69
+ }
70
+ stringifyPath(segments) {
71
+ return segments.map((segment) => {
72
+ return segment.toString().replace(/[\\[\]]/g, (match) => {
73
+ switch (match) {
74
+ case "\\":
75
+ return "\\\\";
76
+ case "[":
77
+ return "\\[";
78
+ case "]":
79
+ return "\\]";
80
+ /* v8 ignore next 2 */
81
+ default:
82
+ return match;
83
+ }
84
+ });
85
+ }).reduce((result, segment, i) => {
86
+ if (i === 0) {
87
+ return segment;
88
+ }
89
+ return `${result}[${segment}]`;
90
+ }, "");
91
+ }
92
+ parsePath(path) {
93
+ const segments = [];
94
+ let inBrackets = false;
95
+ let currentSegment = "";
96
+ let backslashCount = 0;
97
+ for (let i = 0; i < path.length; i++) {
98
+ const char = path[i];
99
+ const nextChar = path[i + 1];
100
+ if (inBrackets && char === "]" && (nextChar === void 0 || nextChar === "[") && backslashCount % 2 === 0) {
101
+ if (nextChar === void 0) {
102
+ inBrackets = false;
103
+ }
104
+ segments.push(currentSegment);
105
+ currentSegment = "";
106
+ i++;
107
+ } else if (segments.length === 0 && char === "[" && backslashCount % 2 === 0) {
108
+ inBrackets = true;
109
+ segments.push(currentSegment);
110
+ currentSegment = "";
111
+ } else if (char === "\\") {
112
+ backslashCount++;
113
+ } else {
114
+ currentSegment += "\\".repeat(backslashCount / 2) + char;
115
+ backslashCount = 0;
116
+ }
117
+ }
118
+ return inBrackets || segments.length === 0 ? [path] : segments;
119
+ }
120
+ };
121
+ function isValidArrayIndex(value) {
122
+ return /^0$|^[1-9]\d*$/.test(value);
123
+ }
124
+
125
+ // src/openapi/json-serializer.ts
126
+ import { isObject as isObject2 } from "@orpc/shared";
127
+ var OpenAPIJsonSerializer = class {
128
+ serialize(data, hasBlobRef = { value: false }) {
129
+ if (data instanceof Blob) {
130
+ hasBlobRef.value = true;
131
+ return [data, hasBlobRef.value];
132
+ }
133
+ if (data instanceof Set) {
134
+ return this.serialize(Array.from(data), hasBlobRef);
135
+ }
136
+ if (data instanceof Map) {
137
+ return this.serialize(Array.from(data.entries()), hasBlobRef);
138
+ }
139
+ if (Array.isArray(data)) {
140
+ const json = data.map((v) => v === void 0 ? null : this.serialize(v, hasBlobRef)[0]);
141
+ return [json, hasBlobRef.value];
142
+ }
143
+ if (isObject2(data)) {
144
+ const json = {};
145
+ for (const k in data) {
146
+ json[k] = this.serialize(data[k], hasBlobRef)[0];
147
+ }
148
+ return [json, hasBlobRef.value];
149
+ }
150
+ if (typeof data === "bigint" || data instanceof RegExp || data instanceof URL) {
151
+ return [data.toString(), hasBlobRef.value];
152
+ }
153
+ if (data instanceof Date) {
154
+ return [Number.isNaN(data.getTime()) ? null : data.toISOString(), hasBlobRef.value];
155
+ }
156
+ if (Number.isNaN(data)) {
157
+ return [null, hasBlobRef.value];
158
+ }
159
+ return [data, hasBlobRef.value];
160
+ }
161
+ };
162
+
163
+ // src/openapi/serializer.ts
164
+ import { isAsyncIteratorObject } from "@orpc/shared";
165
+ import { ErrorEvent } from "@orpc/standard-server";
166
+ var OpenAPISerializer = class {
167
+ constructor(jsonSerializer = new OpenAPIJsonSerializer(), bracketNotation = new BracketNotationSerializer()) {
168
+ this.jsonSerializer = jsonSerializer;
169
+ this.bracketNotation = bracketNotation;
170
+ }
171
+ serialize(data) {
172
+ if (isAsyncIteratorObject(data)) {
173
+ return mapEventIterator(data, {
174
+ value: async (value) => this.#serialize(value, false),
175
+ error: async (e) => {
176
+ if (e instanceof ErrorEvent) {
177
+ return new ErrorEvent({
178
+ data: this.#serialize(e.data, false),
179
+ cause: e
180
+ });
181
+ }
182
+ return new ErrorEvent({
183
+ data: this.#serialize(toORPCError(e).toJSON(), false),
184
+ cause: e
185
+ });
186
+ }
187
+ });
188
+ }
189
+ return this.#serialize(data, true);
190
+ }
191
+ #serialize(data, enableFormData) {
192
+ if (data instanceof Blob || data === void 0) {
193
+ return data;
194
+ }
195
+ const [json, hasBlob] = this.jsonSerializer.serialize(data);
196
+ if (!enableFormData || !hasBlob) {
197
+ return json;
198
+ }
199
+ const form = new FormData();
200
+ for (const [path, value] of this.bracketNotation.serialize(json)) {
201
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
202
+ form.append(path, value.toString());
203
+ } else if (value instanceof Blob) {
204
+ form.append(path, value);
205
+ }
206
+ }
207
+ return form;
208
+ }
209
+ deserialize(data) {
210
+ if (data instanceof URLSearchParams || data instanceof FormData) {
211
+ return this.bracketNotation.deserialize(Array.from(data.entries()));
212
+ }
213
+ if (isAsyncIteratorObject(data)) {
214
+ return mapEventIterator(data, {
215
+ value: async (value) => value,
216
+ error: async (e) => {
217
+ if (e instanceof ErrorEvent && ORPCError.isValidJSON(e.data)) {
218
+ return ORPCError.fromJSON(e.data, { cause: e });
219
+ }
220
+ return e;
221
+ }
222
+ });
223
+ }
224
+ return data;
225
+ }
226
+ };
227
+ export {
228
+ BracketNotationSerializer,
229
+ OpenAPIJsonSerializer,
230
+ OpenAPISerializer
231
+ };
232
+ //# sourceMappingURL=openapi.js.map
package/dist/rpc.js ADDED
@@ -0,0 +1,10 @@
1
+ import {
2
+ RPCJsonSerializer,
3
+ RPCSerializer
4
+ } from "./chunk-PGCPKPL5.js";
5
+ import "./chunk-7F3XVLRJ.js";
6
+ export {
7
+ RPCJsonSerializer,
8
+ RPCSerializer
9
+ };
10
+ //# sourceMappingURL=rpc.js.map
@@ -1,3 +1,3 @@
1
- export * from './orpc-link';
1
+ export * from './rpc-link';
2
2
  export * from './types';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,98 @@
1
+ import type { Value } from '@orpc/shared';
2
+ import type { ClientContext, ClientLink, ClientOptionsOut } from '../../types';
3
+ import type { FetchWithContext } from './types';
4
+ import { type EventIteratorReconnectOptions } from '../../event-iterator';
5
+ import { RPCSerializer } from '../../rpc';
6
+ type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
7
+ export declare class InvalidEventSourceRetryResponse extends Error {
8
+ }
9
+ export interface RPCLinkOptions<TClientContext extends ClientContext> {
10
+ /**
11
+ * Base url for all requests.
12
+ */
13
+ url: string;
14
+ /**
15
+ * The maximum length of the URL.
16
+ *
17
+ * @default 2083
18
+ */
19
+ maxUrlLength?: number;
20
+ /**
21
+ * The method used to make the request.
22
+ *
23
+ * @default 'POST'
24
+ */
25
+ method?: Value<HTTPMethod, [
26
+ options: ClientOptionsOut<TClientContext>,
27
+ path: readonly string[],
28
+ input: unknown
29
+ ]>;
30
+ /**
31
+ * The method to use when the payload cannot safely pass to the server with method return from method function.
32
+ * GET is not allowed, it's very dangerous.
33
+ *
34
+ * @default 'POST'
35
+ */
36
+ fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
37
+ /**
38
+ * Inject headers to the request.
39
+ */
40
+ headers?: Value<[string, string][] | Record<string, string> | Headers, [
41
+ options: ClientOptionsOut<TClientContext>,
42
+ path: readonly string[],
43
+ input: unknown
44
+ ]>;
45
+ /**
46
+ * Custom fetch implementation.
47
+ *
48
+ * @default globalThis.fetch.bind(globalThis)
49
+ */
50
+ fetch?: FetchWithContext<TClientContext>;
51
+ rpcSerializer?: RPCSerializer;
52
+ /**
53
+ * Maximum number of retry attempts for EventSource errors before throwing.
54
+ *
55
+ * @default 5
56
+ */
57
+ eventSourceMaxNumberOfRetries?: number;
58
+ /**
59
+ * Delay (in ms) before retrying an EventSource call.
60
+ *
61
+ * @default ({retryTimes, lastRetry}) => lastRetry ?? (1000 * 2 ** retryTimes)
62
+ */
63
+ eventSourceRetryDelay?: Value<number, [
64
+ reconnectOptions: EventIteratorReconnectOptions,
65
+ options: ClientOptionsOut<TClientContext>,
66
+ path: readonly string[],
67
+ input: unknown
68
+ ]>;
69
+ /**
70
+ * Function to determine if an error is retryable.
71
+ *
72
+ * @default true
73
+ */
74
+ eventSourceRetry?: Value<boolean, [
75
+ reconnectOptions: EventIteratorReconnectOptions,
76
+ options: ClientOptionsOut<TClientContext>,
77
+ path: readonly string[],
78
+ input: unknown
79
+ ]>;
80
+ }
81
+ export declare class RPCLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
82
+ private readonly fetch;
83
+ private readonly rpcSerializer;
84
+ private readonly maxUrlLength;
85
+ private readonly fallbackMethod;
86
+ private readonly method;
87
+ private readonly headers;
88
+ private readonly url;
89
+ private readonly eventSourceMaxNumberOfRetries;
90
+ private readonly eventSourceRetryDelay;
91
+ private readonly eventSourceRetry;
92
+ constructor(options: RPCLinkOptions<TClientContext>);
93
+ call(path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>): Promise<unknown>;
94
+ private performCall;
95
+ private encodeRequest;
96
+ }
97
+ export {};
98
+ //# sourceMappingURL=rpc-link.d.ts.map
@@ -1,4 +1,5 @@
1
- export interface FetchWithContext<TClientContext> {
2
- (input: RequestInfo | URL, init: RequestInit | undefined, context: TClientContext): Promise<Response>;
1
+ import type { ClientContext, ClientOptionsOut } from '../../types';
2
+ export interface FetchWithContext<TClientContext extends ClientContext> {
3
+ (url: URL, init: RequestInit, options: ClientOptionsOut<TClientContext>, path: readonly string[], input: unknown): Promise<Response>;
3
4
  }
4
5
  //# sourceMappingURL=types.d.ts.map
@@ -1,11 +1,9 @@
1
- import type { AnyContractRouter, ContractRouterClient } from '@orpc/contract';
2
- import type { AnyRouter, RouterClient } from '@orpc/server';
3
- import type { ClientLink } from './types';
1
+ import type { ClientLink, InferClientContext, NestedClient } from './types';
4
2
  export interface createORPCClientOptions {
5
3
  /**
6
4
  * Use as base path for all procedure, useful when you only want to call a subset of the procedure.
7
5
  */
8
6
  path?: string[];
9
7
  }
10
- export declare function createORPCClient<TRouter extends AnyRouter | AnyContractRouter, TClientContext = unknown>(link: ClientLink<TClientContext>, options?: createORPCClientOptions): TRouter extends AnyRouter ? RouterClient<TRouter, TClientContext> : TRouter extends AnyContractRouter ? ContractRouterClient<TRouter, TClientContext> : never;
8
+ export declare function createORPCClient<T extends NestedClient<any>>(link: ClientLink<InferClientContext<T>>, options?: createORPCClientOptions): T;
11
9
  //# sourceMappingURL=client.d.ts.map
@@ -1,13 +1,12 @@
1
- import type { ClientOptions } from '@orpc/contract';
2
1
  import type { Promisable } from '@orpc/shared';
3
- import type { ClientLink } from './types';
2
+ import type { ClientContext, ClientLink, ClientOptionsOut } from './types';
4
3
  /**
5
4
  * DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
6
5
  * based on the request path, input, and context.
7
6
  */
8
- export declare class DynamicLink<TClientContext> implements ClientLink<TClientContext> {
7
+ export declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
9
8
  private readonly linkResolver;
10
- constructor(linkResolver: (path: readonly string[], input: unknown, context: TClientContext) => Promisable<ClientLink<TClientContext>>);
11
- call(path: readonly string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
9
+ constructor(linkResolver: (options: ClientOptionsOut<TClientContext>, path: readonly string[], input: unknown) => Promisable<ClientLink<TClientContext>>);
10
+ call(path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>): Promise<unknown>;
12
11
  }
13
12
  //# sourceMappingURL=dynamic-link.d.ts.map