@stackframe/stack-shared 2.3.1 → 2.3.3
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/utils/caches.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export declare class AsyncCache<D extends any[], T> {
|
|
|
34
34
|
});
|
|
35
35
|
readonly getOrWait: (key: D, cacheStrategy: CacheStrategy) => ReactPromise<T>;
|
|
36
36
|
readonly forceSetCachedValue: (key: D, value: T) => void;
|
|
37
|
+
readonly forceSetCachedValueAsync: (key: D, value: Promise<T>) => ReactPromise<boolean>;
|
|
37
38
|
readonly refresh: (key: D) => Promise<T>;
|
|
38
39
|
readonly invalidate: (key: D) => Promise<T>;
|
|
39
40
|
readonly onChange: (key: D, callback: (value: T, oldValue: T | undefined) => void) => {
|
|
@@ -75,6 +76,7 @@ declare class AsyncValueCache<T> {
|
|
|
75
76
|
private _setAsync;
|
|
76
77
|
private _refetch;
|
|
77
78
|
forceSetCachedValue(value: T): void;
|
|
79
|
+
forceSetCachedValueAsync(value: Promise<T>): ReactPromise<boolean>;
|
|
78
80
|
refresh(): Promise<T>;
|
|
79
81
|
invalidate(): Promise<T>;
|
|
80
82
|
onChange(callback: (value: T, oldValue: T | undefined) => void): {
|
package/dist/utils/caches.js
CHANGED
|
@@ -46,6 +46,7 @@ export class AsyncCache {
|
|
|
46
46
|
getIfCached = this._createKeyed("getIfCached");
|
|
47
47
|
getOrWait = this._createKeyed("getOrWait");
|
|
48
48
|
forceSetCachedValue = this._createKeyed("forceSetCachedValue");
|
|
49
|
+
forceSetCachedValueAsync = this._createKeyed("forceSetCachedValueAsync");
|
|
49
50
|
refresh = this._createKeyed("refresh");
|
|
50
51
|
invalidate = this._createKeyed("invalidate");
|
|
51
52
|
onChange = this._createKeyed("onChange");
|
|
@@ -104,6 +105,9 @@ class AsyncValueCache {
|
|
|
104
105
|
forceSetCachedValue(value) {
|
|
105
106
|
this._set(value);
|
|
106
107
|
}
|
|
108
|
+
forceSetCachedValueAsync(value) {
|
|
109
|
+
return this._setAsync(value);
|
|
110
|
+
}
|
|
107
111
|
async refresh() {
|
|
108
112
|
return await this.getOrWait("write-only");
|
|
109
113
|
}
|
package/dist/utils/promises.js
CHANGED
|
@@ -73,7 +73,7 @@ class ReactPromiseErrorWrapper extends StackAssertionError {
|
|
|
73
73
|
wrappedErrorMessage;
|
|
74
74
|
constructor(error) {
|
|
75
75
|
const wrappedErrorMessage = error instanceof ReactPromiseErrorWrapper ? error.wrappedErrorMessage : `${error}`;
|
|
76
|
-
super(`Error occured
|
|
76
|
+
super(`Error occured in a ReactPromise: ${wrappedErrorMessage}\n\nSee the \`cause\` property for the original error. This error is a wrapper around the original error to preserve the stack trace (which would go lost when using Stack's pending(...) or rejected(...) functions).`, { cause: error });
|
|
77
77
|
this.error = error;
|
|
78
78
|
this.wrappedErrorMessage = wrappedErrorMessage;
|
|
79
79
|
this.name = "ReactPromiseErrorWrapper";
|
package/dist/utils/results.d.ts
CHANGED
|
@@ -58,7 +58,7 @@ declare function pending(): AsyncResult<never, never, void> & {
|
|
|
58
58
|
declare function pending<P>(progress: P): AsyncResult<never, never, P> & {
|
|
59
59
|
status: "pending";
|
|
60
60
|
};
|
|
61
|
-
declare function promiseToResult<T
|
|
61
|
+
declare function promiseToResult<T>(promise: Promise<T>): Promise<Result<T>>;
|
|
62
62
|
declare function fromThrowing<T>(fn: () => T): Result<T, unknown>;
|
|
63
63
|
declare function mapResult<T, U, E = unknown, P = unknown>(result: Result<T, E>, fn: (data: T) => U): Result<U, E>;
|
|
64
64
|
declare function mapResult<T, U, E = unknown, P = unknown>(result: AsyncResult<T, E, P>, fn: (data: T) => U): AsyncResult<U, E, P>;
|
package/dist/utils/results.js
CHANGED
|
@@ -53,14 +53,14 @@ function pending(progress) {
|
|
|
53
53
|
progress: progress,
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
-
function promiseToResult(promise) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
error
|
|
63
|
-
}
|
|
56
|
+
async function promiseToResult(promise) {
|
|
57
|
+
try {
|
|
58
|
+
const value = await promise;
|
|
59
|
+
return Result.ok(value);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
return Result.error(error);
|
|
63
|
+
}
|
|
64
64
|
}
|
|
65
65
|
function fromThrowing(fn) {
|
|
66
66
|
try {
|