@orpc/client 0.0.0-next.d16a1b6 → 0.0.0-next.d177d36

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,389 @@
1
+ import { isAsyncIteratorObject, defer, value, splitInHalf, toArray, stringifyJSON } from '@orpc/shared';
2
+ import { toBatchRequest, parseBatchResponse, toBatchAbortSignal } from '@orpc/standard-server/batch';
3
+ import { replicateStandardLazyResponse, getEventMeta } from '@orpc/standard-server';
4
+
5
+ class BatchLinkPlugin {
6
+ groups;
7
+ maxSize;
8
+ batchUrl;
9
+ maxUrlLength;
10
+ batchHeaders;
11
+ mapRequestItem;
12
+ exclude;
13
+ mode;
14
+ pending;
15
+ order = 5e6;
16
+ constructor(options) {
17
+ this.groups = options.groups;
18
+ this.pending = /* @__PURE__ */ new Map();
19
+ this.maxSize = options.maxSize ?? 10;
20
+ this.maxUrlLength = options.maxUrlLength ?? 2083;
21
+ this.mode = options.mode ?? "streaming";
22
+ this.batchUrl = options.url ?? (([options2]) => `${options2.request.url.origin}${options2.request.url.pathname}/__batch__`);
23
+ this.batchHeaders = options.headers ?? (([options2, ...rest]) => {
24
+ const headers = {};
25
+ for (const [key, value2] of Object.entries(options2.request.headers)) {
26
+ if (rest.every((item) => item.request.headers[key] === value2)) {
27
+ headers[key] = value2;
28
+ }
29
+ }
30
+ return headers;
31
+ });
32
+ this.mapRequestItem = options.mapRequestItem ?? (({ request, batchHeaders }) => {
33
+ const headers = {};
34
+ for (const [key, value2] of Object.entries(request.headers)) {
35
+ if (batchHeaders[key] !== value2) {
36
+ headers[key] = value2;
37
+ }
38
+ }
39
+ return {
40
+ method: request.method,
41
+ url: request.url,
42
+ headers,
43
+ body: request.body,
44
+ signal: request.signal
45
+ };
46
+ });
47
+ this.exclude = options.exclude ?? (() => false);
48
+ }
49
+ init(options) {
50
+ options.clientInterceptors ??= [];
51
+ options.clientInterceptors.push((options2) => {
52
+ if (options2.request.headers["x-orpc-batch"] !== "1") {
53
+ return options2.next();
54
+ }
55
+ return options2.next({
56
+ ...options2,
57
+ request: {
58
+ ...options2.request,
59
+ headers: {
60
+ ...options2.request.headers,
61
+ "x-orpc-batch": void 0
62
+ }
63
+ }
64
+ });
65
+ });
66
+ options.clientInterceptors.push((options2) => {
67
+ if (this.exclude(options2) || options2.request.body instanceof Blob || options2.request.body instanceof FormData || isAsyncIteratorObject(options2.request.body)) {
68
+ return options2.next();
69
+ }
70
+ const group = this.groups.find((group2) => group2.condition(options2));
71
+ if (!group) {
72
+ return options2.next();
73
+ }
74
+ return new Promise((resolve, reject) => {
75
+ this.#enqueueRequest(group, options2, resolve, reject);
76
+ defer(() => this.#processPendingBatches());
77
+ });
78
+ });
79
+ }
80
+ #enqueueRequest(group, options, resolve, reject) {
81
+ const items = this.pending.get(group);
82
+ if (items) {
83
+ items.push([options, resolve, reject]);
84
+ } else {
85
+ this.pending.set(group, [[options, resolve, reject]]);
86
+ }
87
+ }
88
+ async #processPendingBatches() {
89
+ const pending = this.pending;
90
+ this.pending = /* @__PURE__ */ new Map();
91
+ for (const [group, items] of pending) {
92
+ const getItems = items.filter(([options]) => options.request.method === "GET");
93
+ const restItems = items.filter(([options]) => options.request.method !== "GET");
94
+ this.#executeBatch("GET", group, getItems);
95
+ this.#executeBatch("POST", group, restItems);
96
+ }
97
+ }
98
+ async #executeBatch(method, group, groupItems) {
99
+ if (!groupItems.length) {
100
+ return;
101
+ }
102
+ const batchItems = groupItems;
103
+ if (batchItems.length === 1) {
104
+ batchItems[0][0].next().then(batchItems[0][1]).catch(batchItems[0][2]);
105
+ return;
106
+ }
107
+ try {
108
+ const options = batchItems.map(([options2]) => options2);
109
+ const maxSize = await value(this.maxSize, options);
110
+ if (batchItems.length > maxSize) {
111
+ const [first, second] = splitInHalf(batchItems);
112
+ this.#executeBatch(method, group, first);
113
+ this.#executeBatch(method, group, second);
114
+ return;
115
+ }
116
+ const batchUrl = new URL(await value(this.batchUrl, options));
117
+ const batchHeaders = await value(this.batchHeaders, options);
118
+ const mappedItems = batchItems.map(([options2]) => this.mapRequestItem({ ...options2, batchUrl, batchHeaders }));
119
+ const batchRequest = toBatchRequest({
120
+ method,
121
+ url: batchUrl,
122
+ headers: batchHeaders,
123
+ requests: mappedItems
124
+ });
125
+ const maxUrlLength = await value(this.maxUrlLength, options);
126
+ if (batchRequest.url.toString().length > maxUrlLength) {
127
+ const [first, second] = splitInHalf(batchItems);
128
+ this.#executeBatch(method, group, first);
129
+ this.#executeBatch(method, group, second);
130
+ return;
131
+ }
132
+ const mode = value(this.mode, options);
133
+ const lazyResponse = await options[0].next({
134
+ request: { ...batchRequest, headers: { ...batchRequest.headers, "x-orpc-batch": mode } },
135
+ signal: batchRequest.signal,
136
+ context: group.context,
137
+ input: group.input,
138
+ path: toArray(group.path)
139
+ });
140
+ const parsed = parseBatchResponse({ ...lazyResponse, body: await lazyResponse.body() });
141
+ for await (const item of parsed) {
142
+ batchItems[item.index]?.[1]({ ...item, body: () => Promise.resolve(item.body) });
143
+ }
144
+ throw new Error("Something went wrong make batch response not contains enough responses. This can be a bug please report it.");
145
+ } catch (error) {
146
+ for (const [, , reject] of batchItems) {
147
+ reject(error);
148
+ }
149
+ }
150
+ }
151
+ }
152
+
153
+ class DedupeRequestsPlugin {
154
+ #groups;
155
+ #filter;
156
+ order = 4e6;
157
+ // make sure execute before batch plugin
158
+ #queue = /* @__PURE__ */ new Map();
159
+ constructor(options) {
160
+ this.#groups = options.groups;
161
+ this.#filter = options.filter ?? (({ request }) => request.method === "GET");
162
+ }
163
+ init(options) {
164
+ options.clientInterceptors ??= [];
165
+ options.clientInterceptors.push((options2) => {
166
+ if (options2.request.body instanceof Blob || options2.request.body instanceof FormData || options2.request.body instanceof URLSearchParams || isAsyncIteratorObject(options2.request.body) || !this.#filter(options2)) {
167
+ return options2.next();
168
+ }
169
+ const group = this.#groups.find((group2) => group2.condition(options2));
170
+ if (!group) {
171
+ return options2.next();
172
+ }
173
+ return new Promise((resolve, reject) => {
174
+ this.#enqueue(group, options2, resolve, reject);
175
+ defer(() => this.#dequeue());
176
+ });
177
+ });
178
+ }
179
+ #enqueue(group, options, resolve, reject) {
180
+ let queue = this.#queue.get(group);
181
+ if (!queue) {
182
+ this.#queue.set(group, queue = []);
183
+ }
184
+ const matched = queue.find((item) => {
185
+ const requestString1 = stringifyJSON({
186
+ body: item.options.request.body,
187
+ headers: item.options.request.headers,
188
+ method: item.options.request.method,
189
+ url: item.options.request.url
190
+ });
191
+ const requestString2 = stringifyJSON({
192
+ body: options.request.body,
193
+ headers: options.request.headers,
194
+ method: options.request.method,
195
+ url: options.request.url
196
+ });
197
+ return requestString1 === requestString2;
198
+ });
199
+ if (matched) {
200
+ matched.signals.push(options.request.signal);
201
+ matched.resolves.push(resolve);
202
+ matched.rejects.push(reject);
203
+ } else {
204
+ queue.push({
205
+ options,
206
+ signals: [options.request.signal],
207
+ resolves: [resolve],
208
+ rejects: [reject]
209
+ });
210
+ }
211
+ }
212
+ async #dequeue() {
213
+ const promises = [];
214
+ for (const [group, items] of this.#queue) {
215
+ for (const { options, signals, resolves, rejects } of items) {
216
+ promises.push(
217
+ this.#execute(group, options, signals, resolves, rejects)
218
+ );
219
+ }
220
+ }
221
+ this.#queue.clear();
222
+ await Promise.all(promises);
223
+ }
224
+ async #execute(group, options, signals, resolves, rejects) {
225
+ try {
226
+ const dedupedRequest = {
227
+ ...options.request,
228
+ signal: toBatchAbortSignal(signals)
229
+ };
230
+ const response = await options.next({
231
+ ...options,
232
+ request: dedupedRequest,
233
+ signal: dedupedRequest.signal,
234
+ context: group.context
235
+ });
236
+ const replicatedResponses = replicateStandardLazyResponse(response, resolves.length);
237
+ for (const resolve of resolves) {
238
+ resolve(replicatedResponses.shift());
239
+ }
240
+ } catch (error) {
241
+ for (const reject of rejects) {
242
+ reject(error);
243
+ }
244
+ }
245
+ }
246
+ }
247
+
248
+ class ClientRetryPluginInvalidEventIteratorRetryResponse extends Error {
249
+ }
250
+ class ClientRetryPlugin {
251
+ defaultRetry;
252
+ defaultRetryDelay;
253
+ defaultShouldRetry;
254
+ defaultOnRetry;
255
+ constructor(options = {}) {
256
+ this.defaultRetry = options.default?.retry ?? 0;
257
+ this.defaultRetryDelay = options.default?.retryDelay ?? ((o) => o.lastEventRetry ?? 2e3);
258
+ this.defaultShouldRetry = options.default?.shouldRetry ?? true;
259
+ this.defaultOnRetry = options.default?.onRetry;
260
+ }
261
+ init(options) {
262
+ options.interceptors ??= [];
263
+ options.interceptors.push(async (interceptorOptions) => {
264
+ const maxAttempts = await value(
265
+ interceptorOptions.context.retry ?? this.defaultRetry,
266
+ interceptorOptions
267
+ );
268
+ const retryDelay = interceptorOptions.context.retryDelay ?? this.defaultRetryDelay;
269
+ const shouldRetry = interceptorOptions.context.shouldRetry ?? this.defaultShouldRetry;
270
+ const onRetry = interceptorOptions.context.onRetry ?? this.defaultOnRetry;
271
+ if (maxAttempts <= 0) {
272
+ return interceptorOptions.next();
273
+ }
274
+ let lastEventId = interceptorOptions.lastEventId;
275
+ let lastEventRetry;
276
+ let callback;
277
+ let attemptIndex = 0;
278
+ const next = async (initialError) => {
279
+ let currentError = initialError;
280
+ while (true) {
281
+ const updatedInterceptorOptions = { ...interceptorOptions, lastEventId };
282
+ if (currentError) {
283
+ if (attemptIndex >= maxAttempts) {
284
+ throw currentError.error;
285
+ }
286
+ const attemptOptions = {
287
+ ...updatedInterceptorOptions,
288
+ attemptIndex,
289
+ error: currentError.error,
290
+ lastEventRetry
291
+ };
292
+ const shouldRetryBool = await value(
293
+ shouldRetry,
294
+ attemptOptions
295
+ );
296
+ if (!shouldRetryBool) {
297
+ throw currentError.error;
298
+ }
299
+ callback = onRetry?.(attemptOptions);
300
+ const retryDelayMs = await value(retryDelay, attemptOptions);
301
+ await new Promise((resolve) => setTimeout(resolve, retryDelayMs));
302
+ attemptIndex++;
303
+ }
304
+ try {
305
+ currentError = void 0;
306
+ return await interceptorOptions.next(updatedInterceptorOptions);
307
+ } catch (error) {
308
+ currentError = { error };
309
+ if (updatedInterceptorOptions.signal?.aborted === true) {
310
+ throw error;
311
+ }
312
+ } finally {
313
+ callback?.(!currentError);
314
+ callback = void 0;
315
+ }
316
+ }
317
+ };
318
+ const output = await next();
319
+ if (!isAsyncIteratorObject(output)) {
320
+ return output;
321
+ }
322
+ return async function* () {
323
+ let current = output;
324
+ try {
325
+ while (true) {
326
+ try {
327
+ const item = await current.next();
328
+ const meta = getEventMeta(item.value);
329
+ lastEventId = meta?.id ?? lastEventId;
330
+ lastEventRetry = meta?.retry ?? lastEventRetry;
331
+ if (item.done) {
332
+ return item.value;
333
+ }
334
+ yield item.value;
335
+ } catch (error) {
336
+ const meta = getEventMeta(error);
337
+ lastEventId = meta?.id ?? lastEventId;
338
+ lastEventRetry = meta?.retry ?? lastEventRetry;
339
+ const maybeEventIterator = await next({ error });
340
+ if (!isAsyncIteratorObject(maybeEventIterator)) {
341
+ throw new ClientRetryPluginInvalidEventIteratorRetryResponse(
342
+ "RetryPlugin: Expected an Event Iterator, got a non-Event Iterator"
343
+ );
344
+ }
345
+ current = maybeEventIterator;
346
+ }
347
+ }
348
+ } finally {
349
+ await current.return?.();
350
+ }
351
+ }();
352
+ });
353
+ }
354
+ }
355
+
356
+ class SimpleCsrfProtectionLinkPlugin {
357
+ headerName;
358
+ headerValue;
359
+ exclude;
360
+ constructor(options = {}) {
361
+ this.headerName = options.headerName ?? "x-csrf-token";
362
+ this.headerValue = options.headerValue ?? "orpc";
363
+ this.exclude = options.exclude ?? false;
364
+ }
365
+ order = 8e6;
366
+ init(options) {
367
+ options.clientInterceptors ??= [];
368
+ options.clientInterceptors.push(async (options2) => {
369
+ const excluded = await value(this.exclude, options2);
370
+ if (excluded) {
371
+ return options2.next();
372
+ }
373
+ const headerName = await value(this.headerName, options2);
374
+ const headerValue = await value(this.headerValue, options2);
375
+ return options2.next({
376
+ ...options2,
377
+ request: {
378
+ ...options2.request,
379
+ headers: {
380
+ ...options2.request.headers,
381
+ [headerName]: headerValue
382
+ }
383
+ }
384
+ });
385
+ });
386
+ }
387
+ }
388
+
389
+ export { BatchLinkPlugin, ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse, DedupeRequestsPlugin, SimpleCsrfProtectionLinkPlugin };
@@ -0,0 +1,29 @@
1
+ import { PromiseWithError } from '@orpc/shared';
2
+
3
+ type HTTPPath = `/${string}`;
4
+ type HTTPMethod = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
5
+ type ClientContext = Record<PropertyKey, any>;
6
+ interface ClientOptions<T extends ClientContext> {
7
+ signal?: AbortSignal;
8
+ lastEventId?: string | undefined;
9
+ context: T;
10
+ }
11
+ type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? {
12
+ context?: T;
13
+ } : {
14
+ context: T;
15
+ });
16
+ type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
17
+ type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
18
+ interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
19
+ (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
20
+ }
21
+ type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
22
+ [k: string]: NestedClient<TClientContext>;
23
+ };
24
+ type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
25
+ interface ClientLink<TClientContext extends ClientContext> {
26
+ call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
27
+ }
28
+
29
+ export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientContext as a, ClientOptions as b, ClientPromiseResult as c, HTTPMethod as d, ClientRest as e, Client as f };
@@ -0,0 +1,29 @@
1
+ import { PromiseWithError } from '@orpc/shared';
2
+
3
+ type HTTPPath = `/${string}`;
4
+ type HTTPMethod = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
5
+ type ClientContext = Record<PropertyKey, any>;
6
+ interface ClientOptions<T extends ClientContext> {
7
+ signal?: AbortSignal;
8
+ lastEventId?: string | undefined;
9
+ context: T;
10
+ }
11
+ type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? {
12
+ context?: T;
13
+ } : {
14
+ context: T;
15
+ });
16
+ type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
17
+ type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
18
+ interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
19
+ (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
20
+ }
21
+ type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
22
+ [k: string]: NestedClient<TClientContext>;
23
+ };
24
+ type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
25
+ interface ClientLink<TClientContext extends ClientContext> {
26
+ call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
27
+ }
28
+
29
+ export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientContext as a, ClientOptions as b, ClientPromiseResult as c, HTTPMethod as d, ClientRest as e, Client as f };
@@ -0,0 +1,91 @@
1
+ import { a as ClientContext, b as ClientOptions, d as HTTPMethod } from './client.4TS_0JaO.js';
2
+ import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.C0KbSWlC.js';
3
+ import { Segment, Value, Promisable } from '@orpc/shared';
4
+ import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
5
+
6
+ declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
7
+ readonly BIGINT: 0;
8
+ readonly DATE: 1;
9
+ readonly NAN: 2;
10
+ readonly UNDEFINED: 3;
11
+ readonly URL: 4;
12
+ readonly REGEXP: 5;
13
+ readonly SET: 6;
14
+ readonly MAP: 7;
15
+ };
16
+ type StandardRPCJsonSerializedMetaItem = readonly [type: number, ...path: Segment[]];
17
+ type StandardRPCJsonSerialized = [json: unknown, meta: StandardRPCJsonSerializedMetaItem[], maps: Segment[][], blobs: Blob[]];
18
+ interface StandardRPCCustomJsonSerializer {
19
+ type: number;
20
+ condition(data: unknown): boolean;
21
+ serialize(data: any): unknown;
22
+ deserialize(serialized: any): unknown;
23
+ }
24
+ interface StandardRPCJsonSerializerOptions {
25
+ customJsonSerializers?: readonly StandardRPCCustomJsonSerializer[];
26
+ }
27
+ declare class StandardRPCJsonSerializer {
28
+ private readonly customSerializers;
29
+ constructor(options?: StandardRPCJsonSerializerOptions);
30
+ serialize(data: unknown, segments?: Segment[], meta?: StandardRPCJsonSerializedMetaItem[], maps?: Segment[][], blobs?: Blob[]): StandardRPCJsonSerialized;
31
+ deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[]): unknown;
32
+ deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[], maps: readonly Segment[][], getBlob: (index: number) => Blob): unknown;
33
+ }
34
+
35
+ declare class StandardRPCSerializer {
36
+ #private;
37
+ private readonly jsonSerializer;
38
+ constructor(jsonSerializer: StandardRPCJsonSerializer);
39
+ serialize(data: unknown): object;
40
+ deserialize(data: unknown): unknown;
41
+ }
42
+
43
+ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
44
+ /**
45
+ * Base url for all requests.
46
+ */
47
+ url: Value<Promisable<string | URL>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
48
+ /**
49
+ * The maximum length of the URL.
50
+ *
51
+ * @default 2083
52
+ */
53
+ maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
54
+ /**
55
+ * The method used to make the request.
56
+ *
57
+ * @default 'POST'
58
+ */
59
+ method?: Value<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
60
+ /**
61
+ * The method to use when the payload cannot safely pass to the server with method return from method function.
62
+ * GET is not allowed, it's very dangerous.
63
+ *
64
+ * @default 'POST'
65
+ */
66
+ fallbackMethod?: Exclude<HTTPMethod, 'HEAD' | 'GET'>;
67
+ /**
68
+ * Inject headers to the request.
69
+ */
70
+ headers?: Value<Promisable<StandardHeaders>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
71
+ }
72
+ declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
73
+ private readonly serializer;
74
+ private readonly baseUrl;
75
+ private readonly maxUrlLength;
76
+ private readonly fallbackMethod;
77
+ private readonly expectedMethod;
78
+ private readonly headers;
79
+ constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>);
80
+ encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
81
+ decode(response: StandardLazyResponse): Promise<unknown>;
82
+ }
83
+
84
+ interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions {
85
+ }
86
+ declare class StandardRPCLink<T extends ClientContext> extends StandardLink<T> {
87
+ constructor(linkClient: StandardLinkClient<T>, options: StandardRPCLinkOptions<T>);
88
+ }
89
+
90
+ export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, StandardRPCJsonSerializer as e, StandardRPCLink as g, StandardRPCLinkCodec as i, StandardRPCSerializer as j };
91
+ export type { StandardRPCJsonSerializedMetaItem as a, StandardRPCJsonSerialized as b, StandardRPCCustomJsonSerializer as c, StandardRPCJsonSerializerOptions as d, StandardRPCLinkOptions as f, StandardRPCLinkCodecOptions as h };
@@ -0,0 +1,46 @@
1
+ import { Interceptor } from '@orpc/shared';
2
+ import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
3
+ import { a as ClientContext, b as ClientOptions, C as ClientLink } from './client.4TS_0JaO.mjs';
4
+
5
+ interface StandardLinkPlugin<T extends ClientContext> {
6
+ order?: number;
7
+ init?(options: StandardLinkOptions<T>): void;
8
+ }
9
+ declare class CompositeStandardLinkPlugin<T extends ClientContext, TPlugin extends StandardLinkPlugin<T>> implements StandardLinkPlugin<T> {
10
+ protected readonly plugins: TPlugin[];
11
+ constructor(plugins?: readonly TPlugin[]);
12
+ init(options: StandardLinkOptions<T>): void;
13
+ }
14
+
15
+ interface StandardLinkCodec<T extends ClientContext> {
16
+ encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
17
+ decode(response: StandardLazyResponse, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<unknown>;
18
+ }
19
+ interface StandardLinkClient<T extends ClientContext> {
20
+ call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
21
+ }
22
+
23
+ interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
24
+ path: readonly string[];
25
+ input: unknown;
26
+ }
27
+ interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> {
28
+ request: StandardRequest;
29
+ }
30
+ interface StandardLinkOptions<T extends ClientContext> {
31
+ interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>[];
32
+ clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, Promise<StandardLazyResponse>>[];
33
+ plugins?: StandardLinkPlugin<T>[];
34
+ }
35
+ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
36
+ #private;
37
+ readonly codec: StandardLinkCodec<T>;
38
+ readonly sender: StandardLinkClient<T>;
39
+ private readonly interceptors;
40
+ private readonly clientInterceptors;
41
+ constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
42
+ call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
43
+ }
44
+
45
+ export { CompositeStandardLinkPlugin as C, StandardLink as d };
46
+ export type { StandardLinkClientInterceptorOptions as S, StandardLinkPlugin as a, StandardLinkOptions as b, StandardLinkInterceptorOptions as c, StandardLinkCodec as e, StandardLinkClient as f };
@@ -0,0 +1,91 @@
1
+ import { a as ClientContext, b as ClientOptions, d as HTTPMethod } from './client.4TS_0JaO.mjs';
2
+ import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.BMoG_EdN.mjs';
3
+ import { Segment, Value, Promisable } from '@orpc/shared';
4
+ import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
5
+
6
+ declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
7
+ readonly BIGINT: 0;
8
+ readonly DATE: 1;
9
+ readonly NAN: 2;
10
+ readonly UNDEFINED: 3;
11
+ readonly URL: 4;
12
+ readonly REGEXP: 5;
13
+ readonly SET: 6;
14
+ readonly MAP: 7;
15
+ };
16
+ type StandardRPCJsonSerializedMetaItem = readonly [type: number, ...path: Segment[]];
17
+ type StandardRPCJsonSerialized = [json: unknown, meta: StandardRPCJsonSerializedMetaItem[], maps: Segment[][], blobs: Blob[]];
18
+ interface StandardRPCCustomJsonSerializer {
19
+ type: number;
20
+ condition(data: unknown): boolean;
21
+ serialize(data: any): unknown;
22
+ deserialize(serialized: any): unknown;
23
+ }
24
+ interface StandardRPCJsonSerializerOptions {
25
+ customJsonSerializers?: readonly StandardRPCCustomJsonSerializer[];
26
+ }
27
+ declare class StandardRPCJsonSerializer {
28
+ private readonly customSerializers;
29
+ constructor(options?: StandardRPCJsonSerializerOptions);
30
+ serialize(data: unknown, segments?: Segment[], meta?: StandardRPCJsonSerializedMetaItem[], maps?: Segment[][], blobs?: Blob[]): StandardRPCJsonSerialized;
31
+ deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[]): unknown;
32
+ deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[], maps: readonly Segment[][], getBlob: (index: number) => Blob): unknown;
33
+ }
34
+
35
+ declare class StandardRPCSerializer {
36
+ #private;
37
+ private readonly jsonSerializer;
38
+ constructor(jsonSerializer: StandardRPCJsonSerializer);
39
+ serialize(data: unknown): object;
40
+ deserialize(data: unknown): unknown;
41
+ }
42
+
43
+ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
44
+ /**
45
+ * Base url for all requests.
46
+ */
47
+ url: Value<Promisable<string | URL>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
48
+ /**
49
+ * The maximum length of the URL.
50
+ *
51
+ * @default 2083
52
+ */
53
+ maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
54
+ /**
55
+ * The method used to make the request.
56
+ *
57
+ * @default 'POST'
58
+ */
59
+ method?: Value<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
60
+ /**
61
+ * The method to use when the payload cannot safely pass to the server with method return from method function.
62
+ * GET is not allowed, it's very dangerous.
63
+ *
64
+ * @default 'POST'
65
+ */
66
+ fallbackMethod?: Exclude<HTTPMethod, 'HEAD' | 'GET'>;
67
+ /**
68
+ * Inject headers to the request.
69
+ */
70
+ headers?: Value<Promisable<StandardHeaders>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
71
+ }
72
+ declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
73
+ private readonly serializer;
74
+ private readonly baseUrl;
75
+ private readonly maxUrlLength;
76
+ private readonly fallbackMethod;
77
+ private readonly expectedMethod;
78
+ private readonly headers;
79
+ constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>);
80
+ encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
81
+ decode(response: StandardLazyResponse): Promise<unknown>;
82
+ }
83
+
84
+ interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions {
85
+ }
86
+ declare class StandardRPCLink<T extends ClientContext> extends StandardLink<T> {
87
+ constructor(linkClient: StandardLinkClient<T>, options: StandardRPCLinkOptions<T>);
88
+ }
89
+
90
+ export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, StandardRPCJsonSerializer as e, StandardRPCLink as g, StandardRPCLinkCodec as i, StandardRPCSerializer as j };
91
+ export type { StandardRPCJsonSerializedMetaItem as a, StandardRPCJsonSerialized as b, StandardRPCCustomJsonSerializer as c, StandardRPCJsonSerializerOptions as d, StandardRPCLinkOptions as f, StandardRPCLinkCodecOptions as h };