Store.tryClaim
Claim replay keys atomically
Records the first use of a replay key until its expiration time.
Usage
import { } from 'mppx'
const = .()
const = .() + 60_000
const = await .(, 'request:abc123', )
.()
true const = await .(, 'request:abc123', )
.()
falseStore.tryClaim uses the store's optional optimized tryClaim operation when present. Otherwise, it falls back to AtomicStore.update. Expired replay markers can be claimed again; legacy non-marker values remain claimed.
Support replay claims in a custom store
AtomicStore accepts an optional tryClaim fast path. The fallback stores a ReplayMarker, so include that type in a custom store's item map when you don't provide the fast path.
type TryClaim<itemMap extends StoreItemMap = StoreItemMap> = <
key extends keyof itemMap & string,
>(key: key, expires: number) => boolean | Promise<boolean>
type ReplayMarker = {
expires: number
type: 'mppx:replay'
}Return type
type ReturnType = boolean | Promise<boolean>Returns true when this call records the key and false when an unexpired claim already exists.
Parameters
expires
- Type:
number
Unix timestamp in milliseconds when the replay claim expires.
key
- Type:
string
Store key to claim. Typed stores constrain this value to their item-map keys.
store
- Type:
Store.AtomicStore
Atomic store used to persist the replay marker. Implement store.tryClaim as a single insert-if-absent-with-expiry operation when your backend supports it.