shelving 1.195.0 → 1.195.1
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.
|
@@ -2,7 +2,9 @@ import type { AnyCaller } from "../../util/function.js";
|
|
|
2
2
|
import type { RequestOptions } from "../../util/http.js";
|
|
3
3
|
import type { Endpoint } from "../endpoint/Endpoint.js";
|
|
4
4
|
import { ThroughAPIProvider } from "./ThroughAPIProvider.js";
|
|
5
|
-
/** Provider that logs
|
|
5
|
+
/** Provider that logs operations to the console. */
|
|
6
6
|
export declare class DebugAPIProvider<P, R> extends ThroughAPIProvider<P, R> {
|
|
7
|
-
|
|
7
|
+
getRequest<PP extends P, RR extends R>(endpoint: Endpoint<PP, RR>, payload: PP, options?: RequestOptions, caller?: AnyCaller): Request;
|
|
8
|
+
fetch(request: Request): Promise<Response>;
|
|
9
|
+
parseResponse<PP extends P, RR extends R>(endpoint: Endpoint<PP, RR>, response: Response, caller?: AnyCaller): Promise<RR>;
|
|
8
10
|
}
|
|
@@ -1,37 +1,43 @@
|
|
|
1
1
|
import { debugFullRequest, debugFullResponse } from "../../util/debug.js";
|
|
2
2
|
import { ThroughAPIProvider } from "./ThroughAPIProvider.js";
|
|
3
|
-
/** Provider that logs
|
|
3
|
+
/** Provider that logs operations to the console. */
|
|
4
4
|
export class DebugAPIProvider extends ThroughAPIProvider {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
getRequest(endpoint, payload, options, caller = this.getRequest) {
|
|
6
|
+
const url = this.url.toString();
|
|
7
|
+
const ep = endpoint.toString();
|
|
8
8
|
try {
|
|
9
|
-
request =
|
|
9
|
+
const request = super.getRequest(endpoint, payload, options, caller);
|
|
10
|
+
console.debug("✔ REQUEST", url, ep, payload);
|
|
11
|
+
return request;
|
|
10
12
|
}
|
|
11
13
|
catch (reason) {
|
|
12
|
-
console.error("✘
|
|
14
|
+
console.error("✘ REQUEST", url, ep, payload, reason);
|
|
13
15
|
throw reason;
|
|
14
16
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
let response;
|
|
17
|
+
}
|
|
18
|
+
async fetch(request) {
|
|
19
|
+
const url = this.url.toString();
|
|
19
20
|
try {
|
|
20
|
-
|
|
21
|
+
console.error("→ FETCH", url, await debugFullRequest(request));
|
|
22
|
+
const response = await super.fetch(request);
|
|
23
|
+
console.error("← FETCH", url, await debugFullResponse(response));
|
|
24
|
+
return response;
|
|
21
25
|
}
|
|
22
26
|
catch (reason) {
|
|
23
|
-
console.error("✘ FETCH",
|
|
27
|
+
console.error("✘ FETCH", url, reason);
|
|
24
28
|
throw reason;
|
|
25
29
|
}
|
|
26
|
-
|
|
27
|
-
|
|
30
|
+
}
|
|
31
|
+
async parseResponse(endpoint, response, caller = this.parseResponse) {
|
|
32
|
+
const url = this.url.toString();
|
|
33
|
+
const ep = endpoint.toString();
|
|
28
34
|
try {
|
|
29
|
-
const result = await
|
|
30
|
-
console.debug("✔
|
|
35
|
+
const result = await super.parseResponse(endpoint, response, caller);
|
|
36
|
+
console.debug("✔ RESPONSE", url, ep, result);
|
|
31
37
|
return result;
|
|
32
38
|
}
|
|
33
39
|
catch (reason) {
|
|
34
|
-
console.error("✘
|
|
40
|
+
console.error("✘ RESPONSE", url, ep, reason);
|
|
35
41
|
throw reason;
|
|
36
42
|
}
|
|
37
43
|
}
|
package/package.json
CHANGED
package/util/sequence.js
CHANGED
|
@@ -2,8 +2,12 @@ import { UnexpectedError } from "../error/UnexpectedError.js";
|
|
|
2
2
|
import { getDeferred, getDelay } from "./async.js";
|
|
3
3
|
import { ABORT } from "./constants.js";
|
|
4
4
|
/** Turn a `Promise<R>` into an `IteratorAbortResult<R>` */
|
|
5
|
-
|
|
6
|
-
return
|
|
5
|
+
function _awaitAbortResult(value) {
|
|
6
|
+
return value.then(_getAbortResult);
|
|
7
|
+
}
|
|
8
|
+
/** Turn a result `R` into an `IteratorAbortResult<R>` */
|
|
9
|
+
function _getAbortResult(value) {
|
|
10
|
+
return { done: ABORT, value };
|
|
7
11
|
}
|
|
8
12
|
/** Call an iterator's `return()` method (if it exists) with an initial value, and return the `value` it returns. */
|
|
9
13
|
async function _iteratorReturn(iterator, initial, caller) {
|
|
@@ -26,13 +30,12 @@ export function isSequence(value) {
|
|
|
26
30
|
/** Infinite sequence that yields until a `SIGNAL` is received. */
|
|
27
31
|
export async function* repeatUntil(source, ...signals) {
|
|
28
32
|
const iterator = source[Symbol.asyncIterator]();
|
|
33
|
+
const aborts = signals.map(_awaitAbortResult);
|
|
29
34
|
let n;
|
|
30
35
|
while (true) {
|
|
31
36
|
try {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
...signals.map(_awaitAbort),
|
|
35
|
-
]);
|
|
37
|
+
const next = iterator.next(n);
|
|
38
|
+
const { done, value } = await (aborts.length ? Promise.race([next, ...aborts]) : next);
|
|
36
39
|
if (done) {
|
|
37
40
|
// For aborts, tell the iterator we're no longer using it.
|
|
38
41
|
if (done === ABORT)
|
|
@@ -81,7 +84,7 @@ export async function* callSequence(sequence, callback) {
|
|
|
81
84
|
export function runSequence(sequence, onNext, onError, onReturn) {
|
|
82
85
|
const { promise, resolve } = getDeferred();
|
|
83
86
|
void _runSequenceIterator(sequence[Symbol.asyncIterator](), promise, onNext, onError, onReturn);
|
|
84
|
-
return (value) => resolve(
|
|
87
|
+
return (value) => resolve(_getAbortResult(value));
|
|
85
88
|
}
|
|
86
89
|
async function _runSequenceIterator(iterator, stopped, onNext, onError, onReturn) {
|
|
87
90
|
let n;
|