@orpc/client 0.0.0-next.ccd4e42 → 0.0.0-next.d0e429d

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,76 @@
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-I4MCMTJ2.js";
4
+ import {
5
+ ORPCError,
6
+ createAutoRetryEventIterator
7
+ } from "./chunk-7F3XVLRJ.js";
8
+
9
+ // src/adapters/fetch/rpc-link.ts
10
+ import { isAsyncIteratorObject, stringifyJSON, 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;
25
+ toFetchBodyOptions;
15
26
  constructor(options) {
16
27
  this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
17
28
  this.rpcSerializer = options.rpcSerializer ?? new RPCSerializer();
18
- this.maxURLLength = options.maxURLLength ?? 2083;
29
+ this.maxUrlLength = options.maxUrlLength ?? 2083;
19
30
  this.fallbackMethod = options.fallbackMethod ?? "POST";
20
31
  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
- };
32
+ this.eventSourceMaxNumberOfRetries = options.eventSourceMaxNumberOfRetries ?? 5;
33
+ this.method = options.method ?? this.fallbackMethod;
34
+ this.headers = options.headers ?? {};
35
+ this.eventSourceRetry = options.eventSourceRetry ?? true;
36
+ this.eventSourceRetryDelay = options.eventSourceRetryDelay ?? (({ retryTimes, lastRetry }) => lastRetry ?? 1e3 * 2 ** retryTimes);
37
+ this.toFetchBodyOptions = options;
27
38
  }
28
39
  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"));
40
+ const output = await this.performCall(path, input, options);
41
+ if (!isAsyncIteratorObject(output)) {
42
+ return output;
43
+ }
44
+ return createAutoRetryEventIterator(output, async (reconnectOptions) => {
45
+ if (options.signal?.aborted || reconnectOptions.retryTimes > this.eventSourceMaxNumberOfRetries) {
46
+ return null;
47
+ }
48
+ if (!await value(this.eventSourceRetry, reconnectOptions, options, path, input)) {
49
+ return null;
50
+ }
51
+ const delay = await value(this.eventSourceRetryDelay, reconnectOptions, options, path, input);
52
+ await new Promise((resolve) => setTimeout(resolve, delay));
53
+ const updatedOptions = { ...options, lastEventId: reconnectOptions.lastEventId };
54
+ const maybeIterator = await this.performCall(path, input, updatedOptions);
55
+ if (!isAsyncIteratorObject(maybeIterator)) {
56
+ throw new InvalidEventSourceRetryResponse("Invalid EventSource retry response");
57
+ }
58
+ return maybeIterator;
59
+ }, void 0);
60
+ }
61
+ async performCall(path, input, options) {
62
+ const encoded = await this.encodeRequest(path, input, options);
63
+ const fetchBody = toFetchBody(encoded.body, encoded.headers, this.toFetchBodyOptions);
64
+ if (options.lastEventId !== void 0) {
65
+ encoded.headers.set("last-event-id", options.lastEventId);
33
66
  }
34
67
  const response = await this.fetch(encoded.url, {
35
68
  method: encoded.method,
36
69
  headers: encoded.headers,
37
- body: encoded.body,
70
+ body: fetchBody,
38
71
  signal: options.signal
39
- }, clientContext);
40
- const body = await fetchReToStandardBody(response);
72
+ }, options, path, input);
73
+ const body = await toStandardBody(response);
41
74
  const deserialized = (() => {
42
75
  try {
43
76
  return this.rpcSerializer.deserialize(body);
@@ -53,51 +86,44 @@ var RPCLink = class {
53
86
  });
54
87
  }
55
88
  })();
56
- if (response.ok) {
57
- return deserialized;
89
+ if (!response.ok) {
90
+ if (ORPCError.isValidJSON(deserialized)) {
91
+ throw ORPCError.fromJSON(deserialized);
92
+ }
93
+ throw new ORPCError("INTERNAL_SERVER_ERROR", {
94
+ message: "Invalid RPC error response",
95
+ cause: deserialized
96
+ });
58
97
  }
59
- throw ORPCError.fromJSON(deserialized);
98
+ return deserialized;
60
99
  }
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);
100
+ async encodeRequest(path, input, options) {
101
+ const expectedMethod = await value(this.method, options, path, input);
102
+ const headers = new Headers(await value(this.headers, options, path, input));
65
103
  const url = new URL(`${trim(this.url, "/")}/${path.map(encodeURIComponent).join("/")}`);
66
- headers.append("x-orpc-handler", "rpc");
67
104
  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) {
105
+ if (expectedMethod === "GET" && !(serialized instanceof FormData) && !(serialized instanceof Blob) && !isAsyncIteratorObject(serialized)) {
106
+ const getUrl = new URL(url);
107
+ getUrl.searchParams.append("data", stringifyJSON(serialized) ?? "");
108
+ if (getUrl.toString().length <= this.maxUrlLength) {
72
109
  return {
73
110
  body: void 0,
74
- method: expectMethod,
111
+ method: expectedMethod,
75
112
  headers,
76
- url: tryURL
113
+ url: getUrl
77
114
  };
78
115
  }
79
116
  }
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
117
  return {
93
- body: serialized,
94
- method,
118
+ url,
119
+ method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod,
95
120
  headers,
96
- url
121
+ body: serialized
97
122
  };
98
123
  }
99
124
  };
100
125
  export {
126
+ InvalidEventSourceRetryResponse,
101
127
  RPCLink
102
128
  };
103
129
  //# 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,52 @@ 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
 
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
+ }
74
+
33
75
  // src/index.ts
34
- import { isDefinedError, ORPCError, safe } from "@orpc/contract";
76
+ import { ErrorEvent } from "@orpc/standard-server";
35
77
  export {
78
+ COMMON_ORPC_ERROR_DEFS,
36
79
  DynamicLink,
80
+ ErrorEvent,
37
81
  ORPCError,
82
+ createAutoRetryEventIterator,
38
83
  createORPCClient,
84
+ fallbackORPCErrorMessage,
85
+ fallbackORPCErrorStatus,
39
86
  isDefinedError,
40
- safe
87
+ mapEventIterator,
88
+ onEventIteratorStatusChange,
89
+ registerEventIteratorState,
90
+ safe,
91
+ toORPCError,
92
+ updateEventIteratorStatus
41
93
  };
42
94
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,226 @@
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
+ return new ErrorEvent({
177
+ data: this.#serialize(toORPCError(e).toJSON(), false),
178
+ cause: e
179
+ });
180
+ }
181
+ });
182
+ }
183
+ return this.#serialize(data, true);
184
+ }
185
+ #serialize(data, enableFormData) {
186
+ if (data instanceof Blob || data === void 0) {
187
+ return data;
188
+ }
189
+ const [json, hasBlob] = this.jsonSerializer.serialize(data);
190
+ if (!enableFormData || !hasBlob) {
191
+ return json;
192
+ }
193
+ const form = new FormData();
194
+ for (const [path, value] of this.bracketNotation.serialize(json)) {
195
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
196
+ form.append(path, value.toString());
197
+ } else if (value instanceof Blob) {
198
+ form.append(path, value);
199
+ }
200
+ }
201
+ return form;
202
+ }
203
+ deserialize(data) {
204
+ if (data instanceof URLSearchParams || data instanceof FormData) {
205
+ return this.bracketNotation.deserialize(Array.from(data.entries()));
206
+ }
207
+ if (isAsyncIteratorObject(data)) {
208
+ return mapEventIterator(data, {
209
+ value: async (value) => value,
210
+ error: async (e) => {
211
+ if (e instanceof ErrorEvent && ORPCError.isValidJSON(e.data)) {
212
+ return ORPCError.fromJSON(e.data, { cause: e });
213
+ }
214
+ return e;
215
+ }
216
+ });
217
+ }
218
+ return data;
219
+ }
220
+ };
221
+ export {
222
+ BracketNotationSerializer,
223
+ OpenAPIJsonSerializer,
224
+ OpenAPISerializer
225
+ };
226
+ //# sourceMappingURL=openapi.js.map
package/dist/rpc.js ADDED
@@ -0,0 +1,10 @@
1
+ import {
2
+ RPCJsonSerializer,
3
+ RPCSerializer
4
+ } from "./chunk-I4MCMTJ2.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,100 @@
1
+ import type { Value } from '@orpc/shared';
2
+ import type { ToFetchBodyOptions } from '@orpc/standard-server-fetch';
3
+ import type { ClientContext, ClientLink, ClientOptionsOut } from '../../types';
4
+ import type { FetchWithContext } from './types';
5
+ import { type EventIteratorReconnectOptions } from '../../event-iterator';
6
+ import { RPCSerializer } from '../../rpc';
7
+ type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
8
+ export declare class InvalidEventSourceRetryResponse extends Error {
9
+ }
10
+ export interface RPCLinkOptions<TClientContext extends ClientContext> extends ToFetchBodyOptions {
11
+ /**
12
+ * Base url for all requests.
13
+ */
14
+ url: string;
15
+ /**
16
+ * The maximum length of the URL.
17
+ *
18
+ * @default 2083
19
+ */
20
+ maxUrlLength?: number;
21
+ /**
22
+ * The method used to make the request.
23
+ *
24
+ * @default 'POST'
25
+ */
26
+ method?: Value<HTTPMethod, [
27
+ options: ClientOptionsOut<TClientContext>,
28
+ path: readonly string[],
29
+ input: unknown
30
+ ]>;
31
+ /**
32
+ * The method to use when the payload cannot safely pass to the server with method return from method function.
33
+ * GET is not allowed, it's very dangerous.
34
+ *
35
+ * @default 'POST'
36
+ */
37
+ fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
38
+ /**
39
+ * Inject headers to the request.
40
+ */
41
+ headers?: Value<[string, string][] | Record<string, string> | Headers, [
42
+ options: ClientOptionsOut<TClientContext>,
43
+ path: readonly string[],
44
+ input: unknown
45
+ ]>;
46
+ /**
47
+ * Custom fetch implementation.
48
+ *
49
+ * @default globalThis.fetch.bind(globalThis)
50
+ */
51
+ fetch?: FetchWithContext<TClientContext>;
52
+ rpcSerializer?: RPCSerializer;
53
+ /**
54
+ * Maximum number of retry attempts for EventSource errors before throwing.
55
+ *
56
+ * @default 5
57
+ */
58
+ eventSourceMaxNumberOfRetries?: number;
59
+ /**
60
+ * Delay (in ms) before retrying an EventSource call.
61
+ *
62
+ * @default ({retryTimes, lastRetry}) => lastRetry ?? (1000 * 2 ** retryTimes)
63
+ */
64
+ eventSourceRetryDelay?: Value<number, [
65
+ reconnectOptions: EventIteratorReconnectOptions,
66
+ options: ClientOptionsOut<TClientContext>,
67
+ path: readonly string[],
68
+ input: unknown
69
+ ]>;
70
+ /**
71
+ * Function to determine if an error is retryable.
72
+ *
73
+ * @default true
74
+ */
75
+ eventSourceRetry?: Value<boolean, [
76
+ reconnectOptions: EventIteratorReconnectOptions,
77
+ options: ClientOptionsOut<TClientContext>,
78
+ path: readonly string[],
79
+ input: unknown
80
+ ]>;
81
+ }
82
+ export declare class RPCLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
83
+ private readonly fetch;
84
+ private readonly rpcSerializer;
85
+ private readonly maxUrlLength;
86
+ private readonly fallbackMethod;
87
+ private readonly method;
88
+ private readonly headers;
89
+ private readonly url;
90
+ private readonly eventSourceMaxNumberOfRetries;
91
+ private readonly eventSourceRetryDelay;
92
+ private readonly eventSourceRetry;
93
+ private readonly toFetchBodyOptions;
94
+ constructor(options: RPCLinkOptions<TClientContext>);
95
+ call(path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>): Promise<unknown>;
96
+ private performCall;
97
+ private encodeRequest;
98
+ }
99
+ export {};
100
+ //# 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