✨ types(hooks): LockPackage für context.lock
continuous-integration/drone/push Build is passing

acquire/release/isHeld/held/count/waiters inklusive LockHandle mit
reentrant-Kennzeichen. Gehört zu tibi-server #31.
This commit is contained in:
apairon committed 2026-11-09 16:40:05 +00:00
1 parent c91b377c40
commit 4e13d4ab9a
1 file changed
+55
Vendored
+55
View File
@@ -2307,6 +2307,60 @@ declare global {
count(): number
}
/**
* Project-scoped named claims for single-flight work.
*
* A claim exists once per key and is released when the hook/job ends
* (return, exception, panic, timeout) or via `release()`. No TTL, no LRU,
* no configuration.
*/
interface LockPackage {
/**
* Claim a named lock.
*
* @param key Lock key, e.g. `"ssr:render:" + url`
* @param options.waitMs Optional wait budget in milliseconds (default 0,
* capped at 30000). Waits for the current owner to release.
* @returns `{ acquired, key, reentrant? }`. `reentrant` is true when the
* same execution already holds the key (never granted twice).
*/
acquire(key: string, options?: { waitMs?: number }): LockHandle
/**
* Release this execution's claim.
*
* @returns `true` if this execution held and released the claim.
*/
release(key: string): boolean
/**
* Whether this execution holds the key.
*/
isHeld(key: string): boolean
/**
* Whether anybody holds the key.
*/
held(key: string): boolean
/**
* Number of held claims in this project.
*/
count(): number
/**
* Number of executions waiting for a claim.
*/
waiters(): number
}
interface LockHandle {
acquired: boolean
key: string
/** Set when the same execution tried to acquire its own claim. */
reentrant?: boolean
}
/**
* Project-scoped rate limiter with two strategies:
* - **Backoff**: Exponential back-off per key (e.g. login brute-force protection).
@@ -2478,6 +2532,7 @@ declare global {
base64: Base64Package
channel: ChannelPackage
cache: CachePackage
lock: LockPackage
ratelimit: RatelimitPackage
}