@orpc/client 0.0.0-next.964aca5 → 0.0.0-next.9686570
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/README.md +17 -22
- package/dist/adapters/fetch/index.d.mts +11 -4
- package/dist/adapters/fetch/index.d.ts +11 -4
- package/dist/adapters/fetch/index.mjs +2 -2
- package/dist/adapters/message-port/index.d.mts +59 -0
- package/dist/adapters/message-port/index.d.ts +59 -0
- package/dist/adapters/message-port/index.mjs +71 -0
- package/dist/adapters/standard/index.d.mts +3 -3
- package/dist/adapters/standard/index.d.ts +3 -3
- package/dist/adapters/standard/index.mjs +2 -2
- package/dist/adapters/websocket/index.d.mts +29 -0
- package/dist/adapters/websocket/index.d.ts +29 -0
- package/dist/adapters/websocket/index.mjs +44 -0
- package/dist/index.d.mts +50 -20
- package/dist/index.d.ts +50 -20
- package/dist/index.mjs +24 -7
- package/dist/plugins/index.d.mts +75 -16
- package/dist/plugins/index.d.ts +75 -16
- package/dist/plugins/index.mjs +116 -17
- package/dist/shared/{client.CipPQkhk.d.mts → client.BOYsZIRq.d.mts} +2 -2
- package/dist/shared/{client.CipPQkhk.d.ts → client.BOYsZIRq.d.ts} +2 -2
- package/dist/shared/{client.FvDtk0Vr.d.ts → client.C4VxIexA.d.mts} +14 -13
- package/dist/shared/{client.Bt2hFtM_.d.mts → client.CXXEPIbK.d.ts} +14 -13
- package/dist/shared/{client.CRWEpqLB.mjs → client.DHOfWE0c.mjs} +22 -25
- package/dist/shared/{client.DpICn1BD.mjs → client.DwfV9Oyl.mjs} +1 -1
- package/dist/shared/{client.Dc8eXpCj.d.ts → client.WCinBImJ.d.ts} +10 -9
- package/dist/shared/{client.DXvQo1nS.d.mts → client.aTp4sII-.d.mts} +10 -9
- package/package.json +16 -5
package/dist/plugins/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { isAsyncIteratorObject, value, splitInHalf, toArray } from '@orpc/shared';
|
|
2
|
-
import { toBatchRequest, parseBatchResponse } from '@orpc/standard-server/batch';
|
|
3
|
-
import { getEventMeta } from '@orpc/standard-server';
|
|
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
4
|
|
|
5
5
|
class BatchLinkPlugin {
|
|
6
6
|
groups;
|
|
@@ -10,6 +10,7 @@ class BatchLinkPlugin {
|
|
|
10
10
|
batchHeaders;
|
|
11
11
|
mapRequestItem;
|
|
12
12
|
exclude;
|
|
13
|
+
mode;
|
|
13
14
|
pending;
|
|
14
15
|
order = 5e6;
|
|
15
16
|
constructor(options) {
|
|
@@ -17,6 +18,7 @@ class BatchLinkPlugin {
|
|
|
17
18
|
this.pending = /* @__PURE__ */ new Map();
|
|
18
19
|
this.maxSize = options.maxSize ?? 10;
|
|
19
20
|
this.maxUrlLength = options.maxUrlLength ?? 2083;
|
|
21
|
+
this.mode = options.mode ?? "streaming";
|
|
20
22
|
this.batchUrl = options.url ?? (([options2]) => `${options2.request.url.origin}${options2.request.url.pathname}/__batch__`);
|
|
21
23
|
this.batchHeaders = options.headers ?? (([options2, ...rest]) => {
|
|
22
24
|
const headers = {};
|
|
@@ -71,7 +73,7 @@ class BatchLinkPlugin {
|
|
|
71
73
|
}
|
|
72
74
|
return new Promise((resolve, reject) => {
|
|
73
75
|
this.#enqueueRequest(group, options2, resolve, reject);
|
|
74
|
-
|
|
76
|
+
defer(() => this.#processPendingBatches());
|
|
75
77
|
});
|
|
76
78
|
});
|
|
77
79
|
}
|
|
@@ -127,8 +129,9 @@ class BatchLinkPlugin {
|
|
|
127
129
|
this.#executeBatch(method, group, second);
|
|
128
130
|
return;
|
|
129
131
|
}
|
|
132
|
+
const mode = value(this.mode, options);
|
|
130
133
|
const lazyResponse = await options[0].next({
|
|
131
|
-
request: { ...batchRequest, headers: { ...batchRequest.headers, "x-orpc-batch":
|
|
134
|
+
request: { ...batchRequest, headers: { ...batchRequest.headers, "x-orpc-batch": mode } },
|
|
132
135
|
signal: batchRequest.signal,
|
|
133
136
|
context: group.context,
|
|
134
137
|
input: group.input,
|
|
@@ -147,6 +150,101 @@ class BatchLinkPlugin {
|
|
|
147
150
|
}
|
|
148
151
|
}
|
|
149
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
|
+
|
|
150
248
|
class ClientRetryPluginInvalidEventIteratorRetryResponse extends Error {
|
|
151
249
|
}
|
|
152
250
|
class ClientRetryPlugin {
|
|
@@ -175,20 +273,20 @@ class ClientRetryPlugin {
|
|
|
175
273
|
}
|
|
176
274
|
let lastEventId = interceptorOptions.lastEventId;
|
|
177
275
|
let lastEventRetry;
|
|
178
|
-
let
|
|
276
|
+
let callback;
|
|
179
277
|
let attemptIndex = 0;
|
|
180
|
-
const next = async (
|
|
181
|
-
let
|
|
278
|
+
const next = async (initialError) => {
|
|
279
|
+
let currentError = initialError;
|
|
182
280
|
while (true) {
|
|
183
281
|
const updatedInterceptorOptions = { ...interceptorOptions, lastEventId };
|
|
184
|
-
if (
|
|
282
|
+
if (currentError) {
|
|
185
283
|
if (attemptIndex >= maxAttempts) {
|
|
186
|
-
throw
|
|
284
|
+
throw currentError.error;
|
|
187
285
|
}
|
|
188
286
|
const attemptOptions = {
|
|
189
287
|
...updatedInterceptorOptions,
|
|
190
288
|
attemptIndex,
|
|
191
|
-
error:
|
|
289
|
+
error: currentError.error,
|
|
192
290
|
lastEventRetry
|
|
193
291
|
};
|
|
194
292
|
const shouldRetryBool = await value(
|
|
@@ -196,23 +294,24 @@ class ClientRetryPlugin {
|
|
|
196
294
|
attemptOptions
|
|
197
295
|
);
|
|
198
296
|
if (!shouldRetryBool) {
|
|
199
|
-
throw
|
|
297
|
+
throw currentError.error;
|
|
200
298
|
}
|
|
201
|
-
|
|
299
|
+
callback = onRetry?.(attemptOptions);
|
|
202
300
|
const retryDelayMs = await value(retryDelay, attemptOptions);
|
|
203
301
|
await new Promise((resolve) => setTimeout(resolve, retryDelayMs));
|
|
204
302
|
attemptIndex++;
|
|
205
303
|
}
|
|
206
304
|
try {
|
|
305
|
+
currentError = void 0;
|
|
207
306
|
return await interceptorOptions.next(updatedInterceptorOptions);
|
|
208
307
|
} catch (error) {
|
|
308
|
+
currentError = { error };
|
|
209
309
|
if (updatedInterceptorOptions.signal?.aborted === true) {
|
|
210
310
|
throw error;
|
|
211
311
|
}
|
|
212
|
-
current = { error };
|
|
213
312
|
} finally {
|
|
214
|
-
|
|
215
|
-
|
|
313
|
+
callback?.(!currentError);
|
|
314
|
+
callback = void 0;
|
|
216
315
|
}
|
|
217
316
|
}
|
|
218
317
|
};
|
|
@@ -287,4 +386,4 @@ class SimpleCsrfProtectionLinkPlugin {
|
|
|
287
386
|
}
|
|
288
387
|
}
|
|
289
388
|
|
|
290
|
-
export { BatchLinkPlugin, ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse, SimpleCsrfProtectionLinkPlugin };
|
|
389
|
+
export { BatchLinkPlugin, ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse, DedupeRequestsPlugin, SimpleCsrfProtectionLinkPlugin };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PromiseWithError } from '@orpc/shared';
|
|
2
2
|
|
|
3
3
|
type HTTPPath = `/${string}`;
|
|
4
|
-
type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
4
|
+
type HTTPMethod = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
5
5
|
type ClientContext = Record<PropertyKey, any>;
|
|
6
6
|
interface ClientOptions<T extends ClientContext> {
|
|
7
7
|
signal?: AbortSignal;
|
|
@@ -26,4 +26,4 @@ interface ClientLink<TClientContext extends ClientContext> {
|
|
|
26
26
|
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N,
|
|
29
|
+
export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientPromiseResult as a, ClientContext as b, ClientOptions as c, Client as d, ClientRest as e, HTTPMethod as f };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PromiseWithError } from '@orpc/shared';
|
|
2
2
|
|
|
3
3
|
type HTTPPath = `/${string}`;
|
|
4
|
-
type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
4
|
+
type HTTPMethod = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
5
5
|
type ClientContext = Record<PropertyKey, any>;
|
|
6
6
|
interface ClientOptions<T extends ClientContext> {
|
|
7
7
|
signal?: AbortSignal;
|
|
@@ -26,4 +26,4 @@ interface ClientLink<TClientContext extends ClientContext> {
|
|
|
26
26
|
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N,
|
|
29
|
+
export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientPromiseResult as a, ClientContext as b, ClientOptions as c, Client as d, ClientRest as e, HTTPMethod as f };
|
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
import { Interceptor
|
|
1
|
+
import { Interceptor } from '@orpc/shared';
|
|
2
2
|
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
interface StandardLinkCodec<T extends ClientContext> {
|
|
6
|
-
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
|
|
7
|
-
decode(response: StandardLazyResponse, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<unknown>;
|
|
8
|
-
}
|
|
9
|
-
interface StandardLinkClient<T extends ClientContext> {
|
|
10
|
-
call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
|
11
|
-
}
|
|
3
|
+
import { b as ClientContext, c as ClientOptions, C as ClientLink } from './client.BOYsZIRq.mjs';
|
|
12
4
|
|
|
13
5
|
interface StandardLinkPlugin<T extends ClientContext> {
|
|
14
6
|
order?: number;
|
|
@@ -20,6 +12,14 @@ declare class CompositeStandardLinkPlugin<T extends ClientContext, TPlugin exten
|
|
|
20
12
|
init(options: StandardLinkOptions<T>): void;
|
|
21
13
|
}
|
|
22
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
23
|
interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
|
|
24
24
|
path: readonly string[];
|
|
25
25
|
input: unknown;
|
|
@@ -28,8 +28,8 @@ interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends
|
|
|
28
28
|
request: StandardRequest;
|
|
29
29
|
}
|
|
30
30
|
interface StandardLinkOptions<T extends ClientContext> {
|
|
31
|
-
interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, unknown
|
|
32
|
-
clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, StandardLazyResponse
|
|
31
|
+
interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>[];
|
|
32
|
+
clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, Promise<StandardLazyResponse>>[];
|
|
33
33
|
plugins?: StandardLinkPlugin<T>[];
|
|
34
34
|
}
|
|
35
35
|
declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
@@ -42,4 +42,5 @@ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
|
42
42
|
call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
export { CompositeStandardLinkPlugin as C,
|
|
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 };
|
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
import { Interceptor
|
|
1
|
+
import { Interceptor } from '@orpc/shared';
|
|
2
2
|
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
interface StandardLinkCodec<T extends ClientContext> {
|
|
6
|
-
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
|
|
7
|
-
decode(response: StandardLazyResponse, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<unknown>;
|
|
8
|
-
}
|
|
9
|
-
interface StandardLinkClient<T extends ClientContext> {
|
|
10
|
-
call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
|
11
|
-
}
|
|
3
|
+
import { b as ClientContext, c as ClientOptions, C as ClientLink } from './client.BOYsZIRq.js';
|
|
12
4
|
|
|
13
5
|
interface StandardLinkPlugin<T extends ClientContext> {
|
|
14
6
|
order?: number;
|
|
@@ -20,6 +12,14 @@ declare class CompositeStandardLinkPlugin<T extends ClientContext, TPlugin exten
|
|
|
20
12
|
init(options: StandardLinkOptions<T>): void;
|
|
21
13
|
}
|
|
22
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
23
|
interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
|
|
24
24
|
path: readonly string[];
|
|
25
25
|
input: unknown;
|
|
@@ -28,8 +28,8 @@ interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends
|
|
|
28
28
|
request: StandardRequest;
|
|
29
29
|
}
|
|
30
30
|
interface StandardLinkOptions<T extends ClientContext> {
|
|
31
|
-
interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, unknown
|
|
32
|
-
clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, StandardLazyResponse
|
|
31
|
+
interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>[];
|
|
32
|
+
clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, Promise<StandardLazyResponse>>[];
|
|
33
33
|
plugins?: StandardLinkPlugin<T>[];
|
|
34
34
|
}
|
|
35
35
|
declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
@@ -42,4 +42,5 @@ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
|
42
42
|
call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
export { CompositeStandardLinkPlugin as C,
|
|
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 };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isObject, isTypescriptObject } from '@orpc/shared';
|
|
1
|
+
import { isObject, AsyncIteratorClass, isTypescriptObject } from '@orpc/shared';
|
|
2
2
|
import { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
|
3
3
|
|
|
4
4
|
const COMMON_ORPC_ERROR_DEFS = {
|
|
@@ -141,35 +141,32 @@ function createORPCErrorFromJson(json, options = {}) {
|
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
function mapEventIterator(iterator, maps) {
|
|
144
|
-
return async
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
144
|
+
return new AsyncIteratorClass(async () => {
|
|
145
|
+
const { done, value } = await (async () => {
|
|
146
|
+
try {
|
|
147
|
+
return await iterator.next();
|
|
148
|
+
} catch (error) {
|
|
149
|
+
let mappedError = await maps.error(error);
|
|
150
|
+
if (mappedError !== error) {
|
|
151
|
+
const meta = getEventMeta(error);
|
|
152
|
+
if (meta && isTypescriptObject(mappedError)) {
|
|
153
|
+
mappedError = withEventMeta(mappedError, meta);
|
|
153
154
|
}
|
|
154
155
|
}
|
|
155
|
-
|
|
156
|
-
return mappedValue;
|
|
157
|
-
}
|
|
158
|
-
yield mappedValue;
|
|
156
|
+
throw mappedError;
|
|
159
157
|
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
158
|
+
})();
|
|
159
|
+
let mappedValue = await maps.value(value, done);
|
|
160
|
+
if (mappedValue !== value) {
|
|
161
|
+
const meta = getEventMeta(value);
|
|
162
|
+
if (meta && isTypescriptObject(mappedValue)) {
|
|
163
|
+
mappedValue = withEventMeta(mappedValue, meta);
|
|
167
164
|
}
|
|
168
|
-
throw mappedError;
|
|
169
|
-
} finally {
|
|
170
|
-
await iterator.return?.();
|
|
171
165
|
}
|
|
172
|
-
|
|
166
|
+
return { done, value: mappedValue };
|
|
167
|
+
}, async () => {
|
|
168
|
+
await iterator.return?.();
|
|
169
|
+
});
|
|
173
170
|
}
|
|
174
171
|
|
|
175
172
|
export { COMMON_ORPC_ERROR_DEFS as C, ORPCError as O, fallbackORPCErrorMessage as a, isORPCErrorStatus as b, isORPCErrorJson as c, createORPCErrorFromJson as d, fallbackORPCErrorStatus as f, isDefinedError as i, mapEventIterator as m, toORPCError as t };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { toArray, intercept, isObject, value, isAsyncIteratorObject, stringifyJSON } from '@orpc/shared';
|
|
2
2
|
import { mergeStandardHeaders, ErrorEvent } from '@orpc/standard-server';
|
|
3
|
-
import { C as COMMON_ORPC_ERROR_DEFS, b as isORPCErrorStatus, c as isORPCErrorJson, d as createORPCErrorFromJson, O as ORPCError, m as mapEventIterator, t as toORPCError } from './client.
|
|
3
|
+
import { C as COMMON_ORPC_ERROR_DEFS, b as isORPCErrorStatus, c as isORPCErrorJson, d as createORPCErrorFromJson, O as ORPCError, m as mapEventIterator, t as toORPCError } from './client.DHOfWE0c.mjs';
|
|
4
4
|
|
|
5
5
|
class CompositeStandardLinkPlugin {
|
|
6
6
|
plugins;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.
|
|
3
|
-
import { Segment, Value } from '@orpc/shared';
|
|
1
|
+
import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.BOYsZIRq.js';
|
|
2
|
+
import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.CXXEPIbK.js';
|
|
3
|
+
import { Segment, Value, Promisable } from '@orpc/shared';
|
|
4
4
|
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
5
5
|
|
|
6
6
|
declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
|
|
@@ -44,30 +44,30 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
|
44
44
|
/**
|
|
45
45
|
* Base url for all requests.
|
|
46
46
|
*/
|
|
47
|
-
url: Value<string | URL
|
|
47
|
+
url: Value<Promisable<string | URL>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
48
48
|
/**
|
|
49
49
|
* The maximum length of the URL.
|
|
50
50
|
*
|
|
51
51
|
* @default 2083
|
|
52
52
|
*/
|
|
53
|
-
maxUrlLength?: Value<number
|
|
53
|
+
maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
54
54
|
/**
|
|
55
55
|
* The method used to make the request.
|
|
56
56
|
*
|
|
57
57
|
* @default 'POST'
|
|
58
58
|
*/
|
|
59
|
-
method?: Value<HTTPMethod, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
59
|
+
method?: Value<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
60
60
|
/**
|
|
61
61
|
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
|
62
62
|
* GET is not allowed, it's very dangerous.
|
|
63
63
|
*
|
|
64
64
|
* @default 'POST'
|
|
65
65
|
*/
|
|
66
|
-
fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
|
|
66
|
+
fallbackMethod?: Exclude<HTTPMethod, 'HEAD' | 'GET'>;
|
|
67
67
|
/**
|
|
68
68
|
* Inject headers to the request.
|
|
69
69
|
*/
|
|
70
|
-
headers?: Value<StandardHeaders
|
|
70
|
+
headers?: Value<Promisable<StandardHeaders>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
71
71
|
}
|
|
72
72
|
declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
73
73
|
private readonly serializer;
|
|
@@ -87,4 +87,5 @@ declare class StandardRPCLink<T extends ClientContext> extends StandardLink<T> {
|
|
|
87
87
|
constructor(linkClient: StandardLinkClient<T>, options: StandardRPCLinkOptions<T>);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S,
|
|
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 };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.
|
|
3
|
-
import { Segment, Value } from '@orpc/shared';
|
|
1
|
+
import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.BOYsZIRq.mjs';
|
|
2
|
+
import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.C4VxIexA.mjs';
|
|
3
|
+
import { Segment, Value, Promisable } from '@orpc/shared';
|
|
4
4
|
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
5
5
|
|
|
6
6
|
declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
|
|
@@ -44,30 +44,30 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
|
44
44
|
/**
|
|
45
45
|
* Base url for all requests.
|
|
46
46
|
*/
|
|
47
|
-
url: Value<string | URL
|
|
47
|
+
url: Value<Promisable<string | URL>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
48
48
|
/**
|
|
49
49
|
* The maximum length of the URL.
|
|
50
50
|
*
|
|
51
51
|
* @default 2083
|
|
52
52
|
*/
|
|
53
|
-
maxUrlLength?: Value<number
|
|
53
|
+
maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
54
54
|
/**
|
|
55
55
|
* The method used to make the request.
|
|
56
56
|
*
|
|
57
57
|
* @default 'POST'
|
|
58
58
|
*/
|
|
59
|
-
method?: Value<HTTPMethod, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
59
|
+
method?: Value<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
60
60
|
/**
|
|
61
61
|
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
|
62
62
|
* GET is not allowed, it's very dangerous.
|
|
63
63
|
*
|
|
64
64
|
* @default 'POST'
|
|
65
65
|
*/
|
|
66
|
-
fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
|
|
66
|
+
fallbackMethod?: Exclude<HTTPMethod, 'HEAD' | 'GET'>;
|
|
67
67
|
/**
|
|
68
68
|
* Inject headers to the request.
|
|
69
69
|
*/
|
|
70
|
-
headers?: Value<StandardHeaders
|
|
70
|
+
headers?: Value<Promisable<StandardHeaders>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
71
71
|
}
|
|
72
72
|
declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
73
73
|
private readonly serializer;
|
|
@@ -87,4 +87,5 @@ declare class StandardRPCLink<T extends ClientContext> extends StandardLink<T> {
|
|
|
87
87
|
constructor(linkClient: StandardLinkClient<T>, options: StandardRPCLinkOptions<T>);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S,
|
|
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 };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/client",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.9686570",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -33,18 +33,29 @@
|
|
|
33
33
|
"types": "./dist/adapters/fetch/index.d.mts",
|
|
34
34
|
"import": "./dist/adapters/fetch/index.mjs",
|
|
35
35
|
"default": "./dist/adapters/fetch/index.mjs"
|
|
36
|
+
},
|
|
37
|
+
"./websocket": {
|
|
38
|
+
"types": "./dist/adapters/websocket/index.d.mts",
|
|
39
|
+
"import": "./dist/adapters/websocket/index.mjs",
|
|
40
|
+
"default": "./dist/adapters/websocket/index.mjs"
|
|
41
|
+
},
|
|
42
|
+
"./message-port": {
|
|
43
|
+
"types": "./dist/adapters/message-port/index.d.mts",
|
|
44
|
+
"import": "./dist/adapters/message-port/index.mjs",
|
|
45
|
+
"default": "./dist/adapters/message-port/index.mjs"
|
|
36
46
|
}
|
|
37
47
|
},
|
|
38
48
|
"files": [
|
|
39
49
|
"dist"
|
|
40
50
|
],
|
|
41
51
|
"dependencies": {
|
|
42
|
-
"@orpc/shared": "0.0.0-next.
|
|
43
|
-
"@orpc/standard-server": "0.0.0-next.
|
|
44
|
-
"@orpc/standard-server-fetch": "0.0.0-next.
|
|
52
|
+
"@orpc/shared": "0.0.0-next.9686570",
|
|
53
|
+
"@orpc/standard-server": "0.0.0-next.9686570",
|
|
54
|
+
"@orpc/standard-server-fetch": "0.0.0-next.9686570",
|
|
55
|
+
"@orpc/standard-server-peer": "0.0.0-next.9686570"
|
|
45
56
|
},
|
|
46
57
|
"devDependencies": {
|
|
47
|
-
"zod": "^
|
|
58
|
+
"zod": "^4.0.5"
|
|
48
59
|
},
|
|
49
60
|
"scripts": {
|
|
50
61
|
"build": "unbuild",
|