@orpc/client 2.0.0-beta.49 → 2.0.0-beta.50
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/adapters/fetch/index.d.ts +3 -2
- package/dist/adapters/fetch/index.js +2 -2
- package/dist/adapters/fetch/rpc-link.d.ts +8 -8
- package/dist/adapters/fetch/rpc-link.js +16 -13
- package/dist/adapters/fetch/transport.d.ts +29 -31
- package/dist/adapters/fetch/transport.js +49 -63
- package/dist/adapters/message-port/index.d.ts +4 -3
- package/dist/adapters/message-port/index.js +3 -3
- package/dist/adapters/message-port/message-port.d.ts +13 -13
- package/dist/adapters/message-port/message-port.js +35 -53
- package/dist/adapters/message-port/rpc-link.d.ts +8 -8
- package/dist/adapters/message-port/rpc-link.js +17 -14
- package/dist/adapters/message-port/transport.d.ts +31 -34
- package/dist/adapters/message-port/transport.js +38 -52
- package/dist/adapters/standard/codec.d.ts +10 -10
- package/dist/adapters/standard/index.d.ts +6 -5
- package/dist/adapters/standard/index.js +2 -4
- package/dist/adapters/standard/link.d.ts +31 -31
- package/dist/adapters/standard/link.js +101 -85
- package/dist/adapters/standard/plugin.d.ts +25 -31
- package/dist/adapters/standard/plugin.js +14 -16
- package/dist/adapters/standard/rpc-link-codec.d.ts +53 -60
- package/dist/adapters/standard/rpc-link-codec.js +98 -102
- package/dist/adapters/standard/transport.d.ts +7 -7
- package/dist/adapters/websocket/index.d.ts +3 -2
- package/dist/adapters/websocket/index.js +2 -2
- package/dist/adapters/websocket/rpc-link.d.ts +8 -8
- package/dist/adapters/websocket/rpc-link.js +16 -13
- package/dist/adapters/websocket/transport.d.ts +101 -100
- package/dist/adapters/websocket/transport.js +102 -130
- package/dist/async-iterator-object.d.ts +2 -2
- package/dist/async-iterator-object.js +27 -28
- package/dist/client-safe.d.ts +4 -6
- package/dist/client-safe.js +29 -34
- package/dist/client.d.ts +24 -26
- package/dist/client.js +35 -37
- package/dist/consts.d.ts +1 -1
- package/dist/consts.js +18 -41
- package/dist/dynamic-link.d.ts +6 -6
- package/dist/dynamic-link.js +16 -16
- package/dist/error-utils.d.ts +3 -4
- package/dist/error-utils.js +47 -51
- package/dist/error.d.ts +79 -79
- package/dist/error.js +154 -166
- package/dist/index.d.ts +14 -53
- package/dist/index.js +12 -40
- package/dist/plugins/batch.d.ts +122 -155
- package/dist/plugins/batch.js +320 -391
- package/dist/plugins/cookie-jar.d.ts +64 -61
- package/dist/plugins/cookie-jar.js +208 -245
- package/dist/plugins/dedupe.d.ts +49 -53
- package/dist/plugins/dedupe.js +168 -211
- package/dist/plugins/index.d.ts +9 -28
- package/dist/plugins/index.js +8 -23
- package/dist/plugins/request-compression.d.ts +38 -35
- package/dist/plugins/request-compression.js +131 -177
- package/dist/plugins/response-compression.d.ts +21 -18
- package/dist/plugins/response-compression.js +64 -88
- package/dist/plugins/retry-after.d.ts +31 -38
- package/dist/plugins/retry-after.js +60 -85
- package/dist/plugins/retry.d.ts +55 -55
- package/dist/plugins/retry.js +118 -137
- package/dist/plugins/timeout.d.ts +19 -17
- package/dist/plugins/timeout.js +41 -36
- package/dist/rpc-json-serializer.d.ts +84 -84
- package/dist/rpc-json-serializer.js +338 -383
- package/dist/rpc-serializer.d.ts +20 -21
- package/dist/rpc-serializer.js +97 -125
- package/dist/types.d.ts +19 -31
- package/dist/utils.d.ts +18 -29
- package/dist/utils.js +63 -47
- package/package.json +5 -5
- package/dist/adapters/standard/codec.js +0 -1
- package/dist/adapters/standard/transport.js +0 -1
- package/dist/types.js +0 -1
package/dist/plugins/dedupe.d.ts
CHANGED
|
@@ -1,46 +1,42 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import "../adapters/standard/index.js";
|
|
2
|
+
import { StandardLinkPlugin } from "../adapters/standard/plugin.js";
|
|
3
|
+
import { StandardLinkOptions, StandardLinkTransportInterceptorOptions } from "../adapters/standard/link.js";
|
|
4
|
+
import { ClientContext } from "../types.js";
|
|
5
|
+
import { Value } from "@orpc/shared";
|
|
4
6
|
export interface DedupeLinkPluginGroup<T extends ClientContext> {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
items: [
|
|
11
|
-
StandardLinkTransportInterceptorOptions<T>,
|
|
12
|
-
StandardLinkTransportInterceptorOptions<T>,
|
|
13
|
-
...StandardLinkTransportInterceptorOptions<T>[]
|
|
14
|
-
]
|
|
15
|
-
]>;
|
|
7
|
+
condition: Value<boolean, [options: StandardLinkTransportInterceptorOptions<T>]>;
|
|
8
|
+
/**
|
|
9
|
+
* The context used for the rest of the request lifecycle.
|
|
10
|
+
*/
|
|
11
|
+
context: Value<T, [items: [StandardLinkTransportInterceptorOptions<T>, StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]>;
|
|
16
12
|
}
|
|
17
13
|
export interface DedupeLinkPluginOptions<T extends ClientContext> {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
14
|
+
/**
|
|
15
|
+
* To enable deduplication, a request must match at least one defined group.
|
|
16
|
+
* Requests that fall into the same group are considered for deduplication together.
|
|
17
|
+
*/
|
|
18
|
+
groups: [DedupeLinkPluginGroup<T>, ...DedupeLinkPluginGroup<T>[]];
|
|
19
|
+
/**
|
|
20
|
+
* Filters requests to dedupe.
|
|
21
|
+
*
|
|
22
|
+
* @default ({ request }) => request.method === 'GET' || request.method === 'QUERY'
|
|
23
|
+
*/
|
|
24
|
+
filter?: Value<boolean, [options: StandardLinkTransportInterceptorOptions<T>]> | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Only requests with the same scope are deduplicated together.
|
|
27
|
+
* On the server, return a value unique to the incoming request so different users never share a response.
|
|
28
|
+
*
|
|
29
|
+
* @default () => undefined
|
|
30
|
+
*/
|
|
31
|
+
scope?: ((options: StandardLinkTransportInterceptorOptions<T>) => unknown) | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* How long (in ms) to wait for more identical requests before sending,
|
|
34
|
+
* counted from the first queued request.
|
|
35
|
+
* With `0`, only requests made in the same event loop tick are deduplicated.
|
|
36
|
+
*
|
|
37
|
+
* @default 0
|
|
38
|
+
*/
|
|
39
|
+
wait?: number | undefined;
|
|
44
40
|
}
|
|
45
41
|
/**
|
|
46
42
|
* Prevents redundant requests by deduplicating similar in-flight requests,
|
|
@@ -49,16 +45,16 @@ export interface DedupeLinkPluginOptions<T extends ClientContext> {
|
|
|
49
45
|
* @see {@link https://orpc.dev/docs/plugins/dedupe | Dedupe Plugin}
|
|
50
46
|
*/
|
|
51
47
|
export declare class DedupeLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
48
|
+
name: string;
|
|
49
|
+
before: string[];
|
|
50
|
+
private readonly groups;
|
|
51
|
+
private readonly filter;
|
|
52
|
+
private readonly scope;
|
|
53
|
+
private readonly wait;
|
|
54
|
+
private readonly queue;
|
|
55
|
+
constructor(options: NoInfer<DedupeLinkPluginOptions<T>>);
|
|
56
|
+
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
57
|
+
private enqueue;
|
|
58
|
+
private processPendingRequests;
|
|
59
|
+
private execute;
|
|
60
|
+
}
|
package/dist/plugins/dedupe.js
CHANGED
|
@@ -1,226 +1,183 @@
|
|
|
1
|
-
import { captureAsyncContext, defer, disposableAllAbortSignal, isAsyncIteratorObject, replicateAsyncIterator, replicateReadableStream, runWithSignal, stringifyJSON, throwIfAborted, toArray, value, wrapAsyncIterator
|
|
1
|
+
import { captureAsyncContext, defer, disposableAllAbortSignal, isAsyncIteratorObject, listenAbort, replicateAsyncIterator, replicateReadableStream, runWithSignal, stringifyJSON, throwIfAborted, toArray, value, wrapAsyncIterator } from "@orpc/shared";
|
|
2
|
+
// src/plugins/dedupe.ts
|
|
2
3
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
request,
|
|
109
|
-
signal: request.signal,
|
|
110
|
-
context,
|
|
111
|
-
});
|
|
112
|
-
const { dispose } = sharedSignal;
|
|
113
|
-
const replicatedResponses = replicateLazyResponse({ ...response, resolveBody: (hint) => response.resolveBody(hint).finally(dispose) }, signals);
|
|
114
|
-
activeCallers.forEach((caller, index) => caller.resolve(replicatedResponses[index]));
|
|
115
|
-
}
|
|
116
|
-
catch (error) {
|
|
117
|
-
sharedSignal?.dispose();
|
|
118
|
-
for (const caller of activeCallers) {
|
|
119
|
-
caller.reject(error);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
4
|
+
* Prevents redundant requests by deduplicating similar in-flight requests,
|
|
5
|
+
* reducing the number of requests sent to the server.
|
|
6
|
+
*
|
|
7
|
+
* @see {@link https://orpc.dev/docs/plugins/dedupe | Dedupe Plugin}
|
|
8
|
+
*/
|
|
9
|
+
var DedupeLinkPlugin = class {
|
|
10
|
+
name = "~dedupe";
|
|
11
|
+
before = ["~batch"];
|
|
12
|
+
groups;
|
|
13
|
+
filter;
|
|
14
|
+
scope;
|
|
15
|
+
wait;
|
|
16
|
+
queue = /* @__PURE__ */ new Map();
|
|
17
|
+
constructor(options) {
|
|
18
|
+
this.groups = options.groups;
|
|
19
|
+
this.filter = options.filter ?? (({ request }) => request.method === "GET" || request.method === "QUERY");
|
|
20
|
+
this.scope = options.scope ?? (() => void 0);
|
|
21
|
+
this.wait = options.wait ?? 0;
|
|
22
|
+
}
|
|
23
|
+
init(options) {
|
|
24
|
+
const transportInterceptor = (interceptorOptions) => {
|
|
25
|
+
if (!canDedupeRequest(interceptorOptions.request) || !value(this.filter, interceptorOptions)) return interceptorOptions.next();
|
|
26
|
+
const group = this.groups.find((group) => value(group.condition, interceptorOptions));
|
|
27
|
+
if (!group) return interceptorOptions.next();
|
|
28
|
+
const scope = this.scope(interceptorOptions);
|
|
29
|
+
return runWithSignal(interceptorOptions.request.signal, () => new Promise((resolve, reject) => {
|
|
30
|
+
if (!this.queue.size) defer(() => this.processPendingRequests(), this.wait);
|
|
31
|
+
this.enqueue(scope, group, {
|
|
32
|
+
options: interceptorOptions,
|
|
33
|
+
resolve,
|
|
34
|
+
reject,
|
|
35
|
+
runInOwnContext: captureAsyncContext()
|
|
36
|
+
});
|
|
37
|
+
}));
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
...options,
|
|
41
|
+
transportInterceptors: [...toArray(options.transportInterceptors), transportInterceptor]
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
enqueue(scope, group, caller) {
|
|
45
|
+
let groups = this.queue.get(scope);
|
|
46
|
+
if (!groups) {
|
|
47
|
+
groups = /* @__PURE__ */ new Map();
|
|
48
|
+
this.queue.set(scope, groups);
|
|
49
|
+
}
|
|
50
|
+
let queue = groups.get(group);
|
|
51
|
+
if (!queue) {
|
|
52
|
+
queue = /* @__PURE__ */ new Map();
|
|
53
|
+
groups.set(group, queue);
|
|
54
|
+
}
|
|
55
|
+
const requestKey = createRequestKey(caller.options.path, caller.options.request);
|
|
56
|
+
const matched = queue.get(requestKey);
|
|
57
|
+
if (matched) {
|
|
58
|
+
matched.push(caller);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
queue.set(requestKey, [caller]);
|
|
62
|
+
}
|
|
63
|
+
async processPendingRequests() {
|
|
64
|
+
const pending = [...this.queue.values()];
|
|
65
|
+
this.queue.clear();
|
|
66
|
+
const executions = [];
|
|
67
|
+
for (const groups of pending) for (const [group, items] of groups) for (const callers of items.values()) {
|
|
68
|
+
const activeCallers = callers.filter((caller) => !caller.options.request.signal?.aborted);
|
|
69
|
+
const [first] = activeCallers;
|
|
70
|
+
if (first) executions.push(first.runInOwnContext(() => this.execute(group, activeCallers)));
|
|
71
|
+
}
|
|
72
|
+
await Promise.all(executions);
|
|
73
|
+
}
|
|
74
|
+
async execute(group, activeCallers) {
|
|
75
|
+
const first = activeCallers[0];
|
|
76
|
+
const matchedOptions = activeCallers.map((caller) => caller.options);
|
|
77
|
+
let sharedSignal;
|
|
78
|
+
try {
|
|
79
|
+
if (!shouldDedupe(matchedOptions)) {
|
|
80
|
+
const response = await first.options.next(first.options);
|
|
81
|
+
first.resolve(response);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const context = value(group.context, matchedOptions);
|
|
85
|
+
const signals = matchedOptions.map((options) => options.request.signal);
|
|
86
|
+
sharedSignal = disposableAllAbortSignal(signals);
|
|
87
|
+
const request = {
|
|
88
|
+
...first.options.request,
|
|
89
|
+
signal: sharedSignal.signal
|
|
90
|
+
};
|
|
91
|
+
const response = await first.options.next({
|
|
92
|
+
...first.options,
|
|
93
|
+
request,
|
|
94
|
+
signal: request.signal,
|
|
95
|
+
context
|
|
96
|
+
});
|
|
97
|
+
const { dispose } = sharedSignal;
|
|
98
|
+
const replicatedResponses = replicateLazyResponse({
|
|
99
|
+
...response,
|
|
100
|
+
resolveBody: (hint) => response.resolveBody(hint).finally(dispose)
|
|
101
|
+
}, signals);
|
|
102
|
+
activeCallers.forEach((caller, index) => caller.resolve(replicatedResponses[index]));
|
|
103
|
+
} catch (error) {
|
|
104
|
+
sharedSignal?.dispose();
|
|
105
|
+
for (const caller of activeCallers) caller.reject(error);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
124
109
|
function canDedupeRequest(request) {
|
|
125
|
-
|
|
126
|
-
request.body instanceof FormData ||
|
|
127
|
-
request.body instanceof URLSearchParams ||
|
|
128
|
-
request.body instanceof ReadableStream ||
|
|
129
|
-
isAsyncIteratorObject(request.body) ||
|
|
130
|
-
request.signal?.aborted);
|
|
110
|
+
return !(request.body instanceof Blob || request.body instanceof FormData || request.body instanceof URLSearchParams || request.body instanceof ReadableStream || isAsyncIteratorObject(request.body) || request.signal?.aborted);
|
|
131
111
|
}
|
|
132
112
|
function createRequestKey(path, request) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
113
|
+
return stringifyJSON({
|
|
114
|
+
path,
|
|
115
|
+
body: request.body,
|
|
116
|
+
headers: request.headers,
|
|
117
|
+
method: request.method,
|
|
118
|
+
url: request.url
|
|
119
|
+
});
|
|
140
120
|
}
|
|
141
121
|
/**
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
122
|
+
* Replicates the response once per signal. Like an unshared response, each replica's body
|
|
123
|
+
* fails and stops streaming once its own signal aborts, without affecting the other replicas.
|
|
124
|
+
*/
|
|
145
125
|
function replicateLazyResponse(response, signals) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
});
|
|
159
|
-
return (await bodiesPromise)[i];
|
|
160
|
-
}),
|
|
161
|
-
}));
|
|
126
|
+
let bodiesPromise;
|
|
127
|
+
return signals.map((signal, i) => ({
|
|
128
|
+
...response,
|
|
129
|
+
resolveBody: (hint) => runWithSignal(signal, async () => {
|
|
130
|
+
bodiesPromise ??= response.resolveBody(hint).then((body) => {
|
|
131
|
+
if (isAsyncIteratorObject(body)) return replicateAsyncIterator(body, signals.length).map((replica, index) => closeAsyncIteratorOnAbort(replica, signals[index]));
|
|
132
|
+
if (body instanceof ReadableStream) return replicateReadableStream(body, signals.length).map((replica, index) => closeReadableStreamOnAbort(replica, signals[index]));
|
|
133
|
+
return signals.map(() => body);
|
|
134
|
+
});
|
|
135
|
+
return (await bodiesPromise)[i];
|
|
136
|
+
})
|
|
137
|
+
}));
|
|
162
138
|
}
|
|
163
139
|
function closeAsyncIteratorOnAbort(replica, signal) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
return wrapAsyncIterator(replica, {
|
|
175
|
-
mapResult(result) {
|
|
176
|
-
// Ending the replica reports its reads as done rather than failed.
|
|
177
|
-
throwIfAborted(signal);
|
|
178
|
-
return result;
|
|
179
|
-
},
|
|
180
|
-
onFinish: () => signal.removeEventListener('abort', abort),
|
|
181
|
-
});
|
|
140
|
+
if (!signal) return replica;
|
|
141
|
+
const removeAbortListener = listenAbort(signal, () => void replica.return().catch(() => {}));
|
|
142
|
+
return wrapAsyncIterator(replica, {
|
|
143
|
+
mapResult(result) {
|
|
144
|
+
throwIfAborted(signal);
|
|
145
|
+
return result;
|
|
146
|
+
},
|
|
147
|
+
onFinish: removeAbortListener
|
|
148
|
+
});
|
|
182
149
|
}
|
|
183
150
|
/**
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
151
|
+
* Cancels the replica on abort even when nothing is reading it, which an aborted
|
|
152
|
+
* `pipeThrough` would not do until the in-flight chunk is read.
|
|
153
|
+
*/
|
|
187
154
|
function closeReadableStreamOnAbort(replica, signal) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
catch (error) {
|
|
214
|
-
signal.removeEventListener('abort', abort);
|
|
215
|
-
throw error;
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
async cancel(reason) {
|
|
219
|
-
signal.removeEventListener('abort', abort);
|
|
220
|
-
await reader.cancel(reason);
|
|
221
|
-
},
|
|
222
|
-
}, { highWaterMark: 0 });
|
|
155
|
+
if (!signal) return replica;
|
|
156
|
+
const reader = replica.getReader();
|
|
157
|
+
const removeAbortListener = listenAbort(signal, (reason) => {
|
|
158
|
+
reader.cancel(reason).catch(() => {});
|
|
159
|
+
});
|
|
160
|
+
return new ReadableStream({
|
|
161
|
+
async pull(controller) {
|
|
162
|
+
try {
|
|
163
|
+
const result = await reader.read();
|
|
164
|
+
throwIfAborted(signal);
|
|
165
|
+
if (result.done) {
|
|
166
|
+
removeAbortListener();
|
|
167
|
+
controller.close();
|
|
168
|
+
} else controller.enqueue(result.value);
|
|
169
|
+
} catch (error) {
|
|
170
|
+
removeAbortListener();
|
|
171
|
+
throw error;
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
async cancel(reason) {
|
|
175
|
+
removeAbortListener();
|
|
176
|
+
await reader.cancel(reason);
|
|
177
|
+
}
|
|
178
|
+
}, { highWaterMark: 0 });
|
|
223
179
|
}
|
|
224
180
|
function shouldDedupe(items) {
|
|
225
|
-
|
|
181
|
+
return items.length >= 2;
|
|
226
182
|
}
|
|
183
|
+
export { DedupeLinkPlugin };
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,28 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export
|
|
10
|
-
export * from './response-compression.ts';
|
|
11
|
-
export * from './retry.ts';
|
|
12
|
-
export {
|
|
13
|
-
/**
|
|
14
|
-
* @deprecated Use `RetryLinkPlugin` instead.
|
|
15
|
-
*/
|
|
16
|
-
RetryLinkPlugin as ClientRetryPlugin, } from './retry.ts';
|
|
17
|
-
export type {
|
|
18
|
-
/**
|
|
19
|
-
* @deprecated Use `RetryLinkPluginContext` instead.
|
|
20
|
-
*/
|
|
21
|
-
RetryLinkPluginContext as ClientRetryPluginContext, } from './retry.ts';
|
|
22
|
-
export * from './retry-after.ts';
|
|
23
|
-
export {
|
|
24
|
-
/**
|
|
25
|
-
* @deprecated Use `RetryAfterLinkPlugin` instead.
|
|
26
|
-
*/
|
|
27
|
-
RetryAfterLinkPlugin as RetryAfterPlugin, } from './retry-after.ts';
|
|
28
|
-
export * from './timeout.ts';
|
|
1
|
+
import { BATCH_HEADER, BatchLinkPlugin, BatchLinkPluginGroup, BatchLinkPluginMode, BatchLinkPluginOptions, DEFAULT_BATCH_MAX_SIZE } from "./batch.js";
|
|
2
|
+
import { CookieJar, CookieJarLinkPlugin, CookieJarLinkPluginOptions, StoredCookie } from "./cookie-jar.js";
|
|
3
|
+
import { DedupeLinkPlugin, DedupeLinkPluginGroup, DedupeLinkPluginOptions } from "./dedupe.js";
|
|
4
|
+
import { RequestCompressionLinkPlugin, RequestCompressionLinkPluginOptions } from "./request-compression.js";
|
|
5
|
+
import { ResponseCompressionLinkPlugin, ResponseCompressionLinkPluginOptions } from "./response-compression.js";
|
|
6
|
+
import { RetryLinkPlugin, RetryLinkPluginAttemptOptions, RetryLinkPluginContext, RetryLinkPluginOptions, isRetryableError } from "./retry.js";
|
|
7
|
+
import { RetryAfterLinkPlugin, RetryAfterLinkPluginOptions } from "./retry-after.js";
|
|
8
|
+
import { TimeoutLinkPlugin, TimeoutLinkPluginOptions } from "./timeout.js";
|
|
9
|
+
export { BATCH_HEADER, BatchLinkPlugin, BatchLinkPluginGroup, BatchLinkPluginMode, BatchLinkPluginOptions, RetryLinkPlugin as ClientRetryPlugin, type RetryLinkPluginContext as ClientRetryPluginContext, CookieJar, CookieJarLinkPlugin, CookieJarLinkPluginOptions, DEFAULT_BATCH_MAX_SIZE, DedupeLinkPlugin, DedupeLinkPluginGroup, DedupeLinkPluginOptions, DedupeLinkPlugin as DedupeRequestsPlugin, RequestCompressionLinkPlugin, RequestCompressionLinkPluginOptions, ResponseCompressionLinkPlugin, ResponseCompressionLinkPluginOptions, RetryAfterLinkPlugin, RetryAfterLinkPluginOptions, RetryAfterLinkPlugin as RetryAfterPlugin, RetryLinkPlugin, RetryLinkPluginAttemptOptions, RetryLinkPluginContext, RetryLinkPluginOptions, StoredCookie, TimeoutLinkPlugin, TimeoutLinkPluginOptions, isRetryableError };
|
package/dist/plugins/index.js
CHANGED
|
@@ -1,23 +1,8 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export * from './request-compression.js';
|
|
10
|
-
export * from './response-compression.js';
|
|
11
|
-
export * from './retry.js';
|
|
12
|
-
export {
|
|
13
|
-
/**
|
|
14
|
-
* @deprecated Use `RetryLinkPlugin` instead.
|
|
15
|
-
*/
|
|
16
|
-
RetryLinkPlugin as ClientRetryPlugin, } from './retry.js';
|
|
17
|
-
export * from './retry-after.js';
|
|
18
|
-
export {
|
|
19
|
-
/**
|
|
20
|
-
* @deprecated Use `RetryAfterLinkPlugin` instead.
|
|
21
|
-
*/
|
|
22
|
-
RetryAfterLinkPlugin as RetryAfterPlugin, } from './retry-after.js';
|
|
23
|
-
export * from './timeout.js';
|
|
1
|
+
export { BATCH_HEADER, BatchLinkPlugin, DEFAULT_BATCH_MAX_SIZE } from "./batch.js";
|
|
2
|
+
export { CookieJar, CookieJarLinkPlugin } from "./cookie-jar.js";
|
|
3
|
+
export { DedupeLinkPlugin, DedupeLinkPlugin as DedupeRequestsPlugin } from "./dedupe.js";
|
|
4
|
+
export { RequestCompressionLinkPlugin } from "./request-compression.js";
|
|
5
|
+
export { ResponseCompressionLinkPlugin } from "./response-compression.js";
|
|
6
|
+
export { RetryLinkPlugin as ClientRetryPlugin, RetryLinkPlugin, isRetryableError } from "./retry.js";
|
|
7
|
+
export { RetryAfterLinkPlugin, RetryAfterLinkPlugin as RetryAfterPlugin } from "./retry-after.js";
|
|
8
|
+
export { TimeoutLinkPlugin } from "./timeout.js";
|