From 4e13d4ab9a388d1ec47bf26ad6c94f2051aac03f Mon Sep 17 00:00:00 2001 From: Sebastian Frank Date: Mon, 9 Nov 2026 16:40:05 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20types(hooks):=20LockPackage=20f?= =?UTF-8?q?=C3=BCr=20context.lock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit acquire/release/isHeld/held/count/waiters inklusive LockHandle mit reentrant-Kennzeichen. Gehört zu tibi-server #31. --- index.d.ts | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/index.d.ts b/index.d.ts index 6b0df18..67d3320 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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 }