@orpc/client 0.0.0-next.cba521d → 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,89 +1,127 @@
1
- // src/adapters/fetch/orpc-link.ts
2
- import { ORPCError } from "@orpc/contract";
3
- import { ORPCPayloadCodec } from "@orpc/server/fetch";
4
- import { ORPC_HANDLER_HEADER, ORPC_HANDLER_VALUE, trim } from "@orpc/shared";
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
+ };
5
14
  var RPCLink = class {
6
15
  fetch;
7
- payloadCodec;
8
- maxURLLength;
16
+ rpcSerializer;
17
+ maxUrlLength;
9
18
  fallbackMethod;
10
- getMethod;
11
- getHeaders;
19
+ method;
20
+ headers;
12
21
  url;
22
+ eventSourceMaxNumberOfRetries;
23
+ eventSourceRetryDelay;
24
+ eventSourceRetry;
13
25
  constructor(options) {
14
26
  this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
15
- this.payloadCodec = options.payloadCodec ?? new ORPCPayloadCodec();
16
- this.maxURLLength = options.maxURLLength ?? 2083;
27
+ this.rpcSerializer = options.rpcSerializer ?? new RPCSerializer();
28
+ this.maxUrlLength = options.maxUrlLength ?? 2083;
17
29
  this.fallbackMethod = options.fallbackMethod ?? "POST";
18
30
  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
- };
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);
25
36
  }
26
37
  async call(path, input, options) {
27
- const clientContext = options.context;
28
- const encoded = await this.encode(path, input, options);
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);
64
+ }
29
65
  const response = await this.fetch(encoded.url, {
30
66
  method: encoded.method,
31
67
  headers: encoded.headers,
32
- body: encoded.body,
68
+ body: fetchBody,
33
69
  signal: options.signal
34
- }, clientContext);
35
- const decoded = await this.payloadCodec.decode(response);
70
+ }, options, path, input);
71
+ const body = await toStandardBody(response);
72
+ const deserialized = (() => {
73
+ try {
74
+ return this.rpcSerializer.deserialize(body);
75
+ } catch (error) {
76
+ if (response.ok) {
77
+ throw new ORPCError("INTERNAL_SERVER_ERROR", {
78
+ message: "Invalid RPC response",
79
+ cause: error
80
+ });
81
+ }
82
+ throw new ORPCError(response.status.toString(), {
83
+ message: response.statusText
84
+ });
85
+ }
86
+ })();
36
87
  if (!response.ok) {
37
- if (ORPCError.isValidJSON(decoded)) {
38
- throw new ORPCError(decoded);
88
+ if (ORPCError.isValidJSON(deserialized)) {
89
+ throw ORPCError.fromJSON(deserialized);
39
90
  }
40
- throw new ORPCError({
41
- status: response.status,
42
- code: "INTERNAL_SERVER_ERROR",
43
- message: "Internal server error",
44
- cause: decoded
91
+ throw new ORPCError("INTERNAL_SERVER_ERROR", {
92
+ message: "Invalid RPC error response",
93
+ cause: deserialized
45
94
  });
46
95
  }
47
- return decoded;
96
+ return deserialized;
48
97
  }
49
- async encode(path, input, options) {
50
- const clientContext = options.context;
51
- const expectMethod = await this.getMethod(path, input, clientContext);
52
- const methods = /* @__PURE__ */ new Set([expectMethod, this.fallbackMethod]);
53
- const baseHeaders = await this.getHeaders(path, input, clientContext);
54
- const baseUrl = new URL(`${trim(this.url, "/")}/${path.map(encodeURIComponent).join("/")}`);
55
- baseHeaders.append(ORPC_HANDLER_HEADER, ORPC_HANDLER_VALUE);
56
- for (const method of methods) {
57
- const url = new URL(baseUrl);
58
- const headers = new Headers(baseHeaders);
59
- const encoded = this.payloadCodec.encode(input, method, this.fallbackMethod);
60
- if (encoded.query) {
61
- for (const [key, value] of encoded.query.entries()) {
62
- url.searchParams.append(key, value);
63
- }
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));
101
+ const url = new URL(`${trim(this.url, "/")}/${path.map(encodeURIComponent).join("/")}`);
102
+ const serialized = this.rpcSerializer.serialize(input);
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) {
107
+ return {
108
+ body: void 0,
109
+ method: expectedMethod,
110
+ headers,
111
+ url: getUrl
112
+ };
64
113
  }
65
- if (url.toString().length > this.maxURLLength) {
66
- continue;
67
- }
68
- if (encoded.headers) {
69
- for (const [key, value] of encoded.headers.entries()) {
70
- headers.append(key, value);
71
- }
72
- }
73
- return {
74
- url,
75
- headers,
76
- method: encoded.method,
77
- body: encoded.body
78
- };
79
114
  }
80
- throw new ORPCError({
81
- code: "BAD_REQUEST",
82
- message: "Cannot encode the request, please check the url length or payload."
83
- });
115
+ return {
116
+ url,
117
+ method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod,
118
+ headers,
119
+ body: serialized
120
+ };
84
121
  }
85
122
  };
86
123
  export {
124
+ InvalidEventSourceRetryResponse,
87
125
  RPCLink
88
126
  };
89
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 { ContractRouter, ContractRouterClient } from '@orpc/contract';
2
- import type { ANY_ROUTER, 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 ANY_ROUTER | ContractRouter, TClientContext = unknown>(link: ClientLink<TClientContext>, options?: createORPCClientOptions): TRouter extends ContractRouter ? ContractRouterClient<TRouter, TClientContext> : TRouter extends ANY_ROUTER ? RouterClient<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