@stackframe/stack-shared 2.7.3 → 2.7.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @stackframe/stack-shared
2
2
 
3
+ ## 2.7.5
4
+
5
+ ### Patch Changes
6
+
7
+ - Various changes
8
+ - @stackframe/stack-sc@2.7.5
9
+
10
+ ## 2.7.4
11
+
12
+ ### Patch Changes
13
+
14
+ - @stackframe/stack-sc@2.7.4
15
+
3
16
  ## 2.7.3
4
17
 
5
18
  ### Patch Changes
@@ -50,6 +50,7 @@ declare class AsyncValueCache<T> {
50
50
  private readonly _rateLimitOptions;
51
51
  private _subscriptionsCount;
52
52
  private _unsubscribers;
53
+ private _mostRecentRefreshPromiseIndex;
53
54
  constructor(fetcher: () => Promise<T>, _options?: {
54
55
  onSubscribe?: (refresh: () => void) => (() => void);
55
56
  rateLimiter?: Omit<RateLimitOptions, "batchCalls">;
@@ -63,6 +63,7 @@ class AsyncValueCache {
63
63
  this._options = _options;
64
64
  this._subscriptionsCount = 0;
65
65
  this._unsubscribers = [];
66
+ this._mostRecentRefreshPromiseIndex = 0;
66
67
  this._store = new AsyncStore();
67
68
  this._rateLimitOptions = {
68
69
  concurrency: 1,
@@ -132,17 +133,8 @@ class AsyncValueCache {
132
133
  const storeObj = this._store.onChange(callback);
133
134
  runAsynchronously(this.getOrWait("read-write"));
134
135
  if (this._subscriptionsCount++ === 0 && this._options.onSubscribe) {
135
- let mostRecentRefreshPromiseIndex = 0;
136
136
  const unsubscribe = this._options.onSubscribe(() => {
137
- const currentRefreshPromiseIndex = mostRecentRefreshPromiseIndex++;
138
- runAsynchronously(async () => {
139
- // wait a few seconds; if anything changes during that time, we don't want to refresh
140
- // else we do unnecessary requests if we unsubscribe and then subscribe again immediately
141
- await wait(5000);
142
- if (this._subscriptionsCount === 0 && currentRefreshPromiseIndex === mostRecentRefreshPromiseIndex) {
143
- this.invalidate();
144
- }
145
- });
137
+ runAsynchronously(this.refresh());
146
138
  });
147
139
  this._unsubscribers.push(unsubscribe);
148
140
  }
@@ -154,6 +146,15 @@ class AsyncValueCache {
154
146
  hasUnsubscribed = true;
155
147
  storeObj.unsubscribe();
156
148
  if (--this._subscriptionsCount === 0) {
149
+ const currentRefreshPromiseIndex = ++this._mostRecentRefreshPromiseIndex;
150
+ runAsynchronously(async () => {
151
+ // wait a few seconds; if anything changes during that time, we don't want to refresh
152
+ // else we do unnecessary requests if we unsubscribe and then subscribe again immediately
153
+ await wait(5000);
154
+ if (this._subscriptionsCount === 0 && currentRefreshPromiseIndex === this._mostRecentRefreshPromiseIndex) {
155
+ this.invalidate();
156
+ }
157
+ });
157
158
  for (const unsubscribe of this._unsubscribers) {
158
159
  unsubscribe();
159
160
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackframe/stack-shared",
3
- "version": "2.7.3",
3
+ "version": "2.7.5",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "files": [
@@ -51,7 +51,7 @@
51
51
  "oauth4webapi": "^2.10.3",
52
52
  "semver": "^7.6.3",
53
53
  "uuid": "^9.0.1",
54
- "@stackframe/stack-sc": "2.7.3"
54
+ "@stackframe/stack-sc": "2.7.5"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@sentry/nextjs": "^8.40.0",