Skip to content

Commit d28b9b9

Browse files
committed
Clarify naming
1 parent 123f51b commit d28b9b9

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

‎packages/clerk-js/src/core/tokenCache.ts‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ interface TokenCacheEntry extends TokenCacheKeyJSON {
3434

3535
type Seconds = number;
3636

37-
interface CachedToken {
37+
interface TokenWithExpiry {
3838
expiresAt: Seconds;
3939
token: TokenResource;
4040
}
@@ -52,7 +52,7 @@ interface TokenCacheValue {
5252
* await its resolver. Folded into resolvedToken when the live entry resolves,
5353
* which is what keeps a staler resolve from overwriting a fresher token.
5454
*/
55-
freshest?: CachedToken;
55+
freshestKnown?: TokenWithExpiry;
5656
cachedAt: Seconds;
5757
entry: TokenCacheEntry;
5858
/** Timer for automatic cache cleanup when token expires */
@@ -137,7 +137,7 @@ const generateTabId = (): string => {
137137
return Math.random().toString(36).slice(2);
138138
};
139139

140-
const pickFreshestCachedToken = (existing: CachedToken | undefined, incoming: CachedToken): CachedToken => {
140+
const pickFreshest = (existing: TokenWithExpiry | undefined, incoming: TokenWithExpiry): TokenWithExpiry => {
141141
if (!existing) {
142142
return incoming;
143143
}
@@ -201,7 +201,7 @@ const MemoryTokenCache = (prefix?: string): TokenCache => {
201201
}
202202

203203
const hasResolvedToken = value.entry.resolvedToken !== undefined;
204-
const expiresAt = hasResolvedToken && value.freshest ? value.freshest.expiresAt : Infinity;
204+
const expiresAt = hasResolvedToken && value.freshestKnown ? value.freshestKnown.expiresAt : Infinity;
205205
const remainingTtl = expiresAt - Math.floor(Date.now() / 1000);
206206

207207
// Token expired or dangerously close to expiration - force synchronous refresh
@@ -339,7 +339,7 @@ const MemoryTokenCache = (prefix?: string): TokenCache => {
339339

340340
// Chain the freshest known token across replacements. This never touches
341341
// entry.resolvedToken: a pending entry reads as pending and callers await.
342-
value.freshest = existing?.freshest;
342+
value.freshestKnown = existing?.freshestKnown;
343343

344344
// Clears both timers and drops the slot, but only if it still holds `target`
345345
// (a newer set() may have replaced it while a promise/timer was pending).
@@ -380,16 +380,16 @@ const MemoryTokenCache = (prefix?: string): TokenCache => {
380380
// `exp` is server time, so reading it on the device clock is late by the
381381
// device's lag. A full lifetime from cache insert is late by the token's age
382382
// on arrival. The earlier of the two is late only by the smaller error.
383-
const candidate: CachedToken = {
383+
const candidate: TokenWithExpiry = {
384384
expiresAt: Math.min(claims.exp, value.cachedAt + claims.exp - claims.iat),
385385
token: newToken,
386386
};
387387

388388
// Track the freshest token seen for this key, even when this resolver was
389389
// replaced by a newer set() while it was pending.
390-
const previous = live.freshest;
391-
const winner = pickFreshestCachedToken(previous, candidate);
392-
live.freshest = winner;
390+
const previous = live.freshestKnown;
391+
const winner = pickFreshest(previous, candidate);
392+
live.freshestKnown = winner;
393393

394394
// resolvedToken is only written once the live slot itself resolves. While
395395
// the live slot is pending, readers must keep awaiting its resolver, so a

0 commit comments

Comments
 (0)