@stackframe/stack-shared 2.3.3 → 2.3.5

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.
@@ -89,7 +89,9 @@ class AsyncValueCache {
89
89
  this._store.set(value);
90
90
  }
91
91
  _setAsync(value) {
92
- return pending(this._store.setAsync(value));
92
+ const promise = pending(value);
93
+ this._pendingPromise = promise;
94
+ return pending(this._store.setAsync(promise));
93
95
  }
94
96
  _refetch(cacheStrategy) {
95
97
  if (cacheStrategy === "read-write" && this._pendingPromise) {
@@ -99,7 +101,6 @@ class AsyncValueCache {
99
101
  if (cacheStrategy === "never") {
100
102
  return promise;
101
103
  }
102
- this._pendingPromise = promise;
103
104
  return pending(this._setAsync(promise).then(() => promise));
104
105
  }
105
106
  forceSetCachedValue(value) {
@@ -0,0 +1,3 @@
1
+ declare const globalVar: any;
2
+ export { globalVar, };
3
+ export declare function createGlobal<T>(key: string, init: () => T): T;
@@ -0,0 +1,14 @@
1
+ const globalVar = typeof globalThis !== 'undefined' ? globalThis :
2
+ typeof window !== 'undefined' ? window :
3
+ typeof global !== 'undefined' ? global :
4
+ typeof self !== 'undefined' ? self :
5
+ {};
6
+ export { globalVar, };
7
+ const stackGlobalsSymbol = Symbol.for('__stack-globals');
8
+ globalVar[stackGlobalsSymbol] ??= {};
9
+ export function createGlobal(key, init) {
10
+ if (!globalVar[stackGlobalsSymbol][key]) {
11
+ globalVar[stackGlobalsSymbol][key] = init();
12
+ }
13
+ return globalVar[stackGlobalsSymbol][key];
14
+ }
@@ -8,7 +8,7 @@ export type DeepPartial<T> = T extends object ? {
8
8
  */
9
9
  export declare function deepPlainEquals<T>(obj1: T, obj2: unknown): obj2 is T;
10
10
  export declare function typedEntries<T extends {}>(obj: T): [keyof T, T[keyof T]][];
11
- export declare function typedFromEntries<T extends {}>(entries: [keyof T, T[keyof T]][]): Partial<T>;
11
+ export declare function typedFromEntries<K extends PropertyKey, V>(entries: [K, V][]): Record<K, V>;
12
12
  export declare function typedKeys<T extends {}>(obj: T): (keyof T)[];
13
13
  export declare function typedValues<T extends {}>(obj: T): T[keyof T][];
14
14
  export declare function typedAssign<T extends {}, U extends {}>(target: T, source: U): asserts target is T & U;
@@ -11,9 +11,7 @@ export declare function resolved<T>(value: T): ReactPromise<T>;
11
11
  /**
12
12
  * Like Promise.resolve(...), but also adds the status and value properties for use with React's `use` hook.
13
13
  */
14
- export declare function rejected<T>(reason: unknown, options?: {
15
- disableErrorWrapping?: boolean;
16
- }): ReactPromise<T>;
14
+ export declare function rejected<T>(reason: unknown): ReactPromise<T>;
17
15
  export declare function neverResolve(): ReactPromise<never>;
18
16
  export declare function pending<T>(promise: Promise<T>, options?: {
19
17
  disableErrorWrapping?: boolean;
@@ -41,11 +41,10 @@ export function resolved(value) {
41
41
  /**
42
42
  * Like Promise.resolve(...), but also adds the status and value properties for use with React's `use` hook.
43
43
  */
44
- export function rejected(reason, options = {}) {
45
- const actualReason = options.disableErrorWrapping ? reason : createReactPromiseErrorWrapper(reason);
46
- return Object.assign(Promise.reject(actualReason), {
44
+ export function rejected(reason) {
45
+ return Object.assign(Promise.reject(reason), {
47
46
  status: "rejected",
48
- reason: actualReason,
47
+ reason: reason,
49
48
  });
50
49
  }
51
50
  export function neverResolve() {
@@ -58,27 +57,12 @@ export function pending(promise, options = {}) {
58
57
  return value;
59
58
  }, actualReason => {
60
59
  res.status = "rejected";
61
- const reason = options.disableErrorWrapping ? actualReason : createReactPromiseErrorWrapper(actualReason);
62
- res.reason = reason;
63
- throw reason;
60
+ res.reason = actualReason;
61
+ throw actualReason;
64
62
  });
65
63
  res.status = "pending";
66
64
  return res;
67
65
  }
68
- function createReactPromiseErrorWrapper(error) {
69
- return new ReactPromiseErrorWrapper(error);
70
- }
71
- class ReactPromiseErrorWrapper extends StackAssertionError {
72
- error;
73
- wrappedErrorMessage;
74
- constructor(error) {
75
- const wrappedErrorMessage = error instanceof ReactPromiseErrorWrapper ? error.wrappedErrorMessage : `${error}`;
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
- this.error = error;
78
- this.wrappedErrorMessage = wrappedErrorMessage;
79
- this.name = "ReactPromiseErrorWrapper";
80
- }
81
- }
82
66
  export async function wait(ms) {
83
67
  return await new Promise(resolve => setTimeout(resolve, ms));
84
68
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackframe/stack-shared",
3
- "version": "2.3.3",
3
+ "version": "2.3.5",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "files": [