shelving 1.188.1 → 1.188.2
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/error/ResponseError.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ interface ResponseErrorOptions extends BaseErrorOptions {
|
|
|
7
7
|
export declare class ResponseError extends Error implements BaseError {
|
|
8
8
|
/** Provide additional named contextual data that is relevant to the `Error` instance. */
|
|
9
9
|
readonly [key: string]: unknown;
|
|
10
|
-
|
|
10
|
+
/** HTTP status code for the response. */
|
|
11
|
+
readonly code: number;
|
|
12
|
+
constructor(message?: string, { code, ...options }?: ResponseErrorOptions);
|
|
11
13
|
}
|
|
12
14
|
export {};
|
package/error/ResponseError.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { setBaseErrorOptions } from "./BaseError.js";
|
|
2
2
|
/** Error thrown when a received HTTP response isn't OK. */
|
|
3
3
|
export class ResponseError extends Error {
|
|
4
|
-
|
|
4
|
+
/** HTTP status code for the response. */
|
|
5
|
+
code;
|
|
6
|
+
constructor(message, { code = 400, ...options } = {}) {
|
|
5
7
|
super(message, options);
|
|
8
|
+
this.code = code;
|
|
6
9
|
setBaseErrorOptions(ResponseError, this, options);
|
|
7
10
|
}
|
|
8
11
|
}
|
package/package.json
CHANGED
package/store/FetchStore.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type NONE } from "../util/constants.js";
|
|
|
2
2
|
import { BooleanStore } from "./BooleanStore.js";
|
|
3
3
|
import { Store } from "./Store.js";
|
|
4
4
|
/** Callback for a callback fetch store. */
|
|
5
|
-
export type FetchCallback<T> = () => PromiseLike<T>;
|
|
5
|
+
export type FetchCallback<T> = () => T | PromiseLike<T>;
|
|
6
6
|
/**
|
|
7
7
|
* Store that fetches its values from a remote source.
|
|
8
8
|
*
|
|
@@ -24,16 +24,17 @@ export declare class FetchStore<T> extends Store<T> {
|
|
|
24
24
|
* - Triggered automatically when someone reads `value` or `loading`
|
|
25
25
|
* - Multiple requests to `fetch()` while one is inflight will return the same promise.
|
|
26
26
|
*
|
|
27
|
+
* @returns {Promise} that resolves when the fetch is done.
|
|
28
|
+
* @returns {void} if this store returned a synchronous value.
|
|
27
29
|
* @throws {never} Never throws so safe to call unhandled.
|
|
28
30
|
*/
|
|
29
|
-
refresh(): Promise<void
|
|
31
|
+
refresh(): Promise<void> | void;
|
|
30
32
|
/** An in-flight refresh, so we don't de-duplicate these. */
|
|
31
33
|
private _inflight;
|
|
32
|
-
private _refresh;
|
|
33
34
|
await(value: PromiseLike<T>): Promise<void>;
|
|
34
35
|
private _awaits;
|
|
35
36
|
/** Call the callback with the current payload. */
|
|
36
|
-
protected _fetch(): PromiseLike<T>;
|
|
37
|
+
protected _fetch(): T | PromiseLike<T>;
|
|
37
38
|
private _callback;
|
|
38
39
|
/** Invalidate this endpoint, so a new fetch is triggered next time `this.value` is called. */
|
|
39
40
|
invalidate(): void;
|
package/store/FetchStore.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RequiredError } from "../error/RequiredError.js";
|
|
2
|
+
import { isAsync } from "../util/async.js";
|
|
2
3
|
import { ABORTED } from "../util/constants.js";
|
|
3
4
|
import { awaitDispose } from "../util/dispose.js";
|
|
4
5
|
import { BooleanStore } from "./BooleanStore.js";
|
|
@@ -45,22 +46,25 @@ export class FetchStore extends Store {
|
|
|
45
46
|
* - Triggered automatically when someone reads `value` or `loading`
|
|
46
47
|
* - Multiple requests to `fetch()` while one is inflight will return the same promise.
|
|
47
48
|
*
|
|
49
|
+
* @returns {Promise} that resolves when the fetch is done.
|
|
50
|
+
* @returns {void} if this store returned a synchronous value.
|
|
48
51
|
* @throws {never} Never throws so safe to call unhandled.
|
|
49
52
|
*/
|
|
50
53
|
refresh() {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
/** An in-flight refresh, so we don't de-duplicate these. */
|
|
54
|
-
_inflight = undefined;
|
|
55
|
-
/** Kick off a refresh. */
|
|
56
|
-
async _refresh() {
|
|
54
|
+
if (this._inflight)
|
|
55
|
+
return this._inflight;
|
|
57
56
|
try {
|
|
58
|
-
|
|
57
|
+
const value = this._fetch();
|
|
58
|
+
if (isAsync(value))
|
|
59
|
+
return (this._inflight = this.await(value));
|
|
60
|
+
this.value = value;
|
|
59
61
|
}
|
|
60
|
-
|
|
61
|
-
this.
|
|
62
|
+
catch (thrown) {
|
|
63
|
+
this.reason = thrown;
|
|
62
64
|
}
|
|
63
65
|
}
|
|
66
|
+
/** An in-flight refresh, so we don't de-duplicate these. */
|
|
67
|
+
_inflight = undefined;
|
|
64
68
|
// Override to start/stop `this.busy` when awaiting values, and handle aborts correctly.
|
|
65
69
|
async await(value) {
|
|
66
70
|
this.busy.value = true;
|
|
@@ -81,8 +85,10 @@ export class FetchStore extends Store {
|
|
|
81
85
|
}
|
|
82
86
|
finally {
|
|
83
87
|
this._awaits.delete(value);
|
|
84
|
-
if (!this._awaits.size)
|
|
88
|
+
if (!this._awaits.size) {
|
|
85
89
|
this.busy.value = false;
|
|
90
|
+
this._inflight = undefined; // Clear any inflight refresh if this was the last await.
|
|
91
|
+
}
|
|
86
92
|
this._controller = undefined;
|
|
87
93
|
}
|
|
88
94
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { NONE } from "../util/constants.js";
|
|
2
2
|
import { FetchStore } from "./FetchStore.js";
|
|
3
3
|
import { Store } from "./Store.js";
|
|
4
|
-
export type PayloadFetchCallback<P, R> = (payload: P) => PromiseLike<R>;
|
|
4
|
+
export type PayloadFetchCallback<P, R> = (payload: P) => R | PromiseLike<R>;
|
|
5
5
|
/**
|
|
6
6
|
* Store that fetches its values from a remote source by sending a payload to them.
|
|
7
7
|
*
|