import type { Schema } from 'mongoose'; import type { GetModelTypeFromClass, GetModelTypeLiteFromSchema } from '../modules/BaseModel.ts'; import { BaseModel } from '../modules/BaseModel.ts'; export type TLock = GetModelTypeFromClass; declare class Lock extends BaseModel { static initHooks(schema: Schema): void; static get modelSchema(): { readonly _id: { readonly type: StringConstructor; readonly required: true; }; readonly expiredAt: { readonly type: DateConstructor; }; }; static get modelStatics(): { /** * Acquire an advisory lock by name. Locks have NO ownership token: any * caller may release any lock, so only release from the flow that * acquired it. Steal-if-expired is atomic — an expired lock is reclaimed * immediately rather than waiting on Mongo's TTL reaper (which lags up to * ~60s). The TTL index stays as garbage collection. * @param {string} name * @param {number} [ttlSeconds=30] */ readonly acquireLock: (this: GetModelTypeLiteFromSchema<{ readonly _id: { readonly type: StringConstructor; readonly required: true; }; readonly expiredAt: { readonly type: DateConstructor; }; }, {}>, name: string, ttlSeconds?: number) => Promise; /** * Release an advisory lock by name. Unconditional: this does NOT verify * the caller still holds the lock (no ownership token), so a lock that * expired and was re-acquired by another worker can be released by the * original holder. Release only from the flow that acquired it. * @param {string} name */ readonly releaseLock: (this: GetModelTypeLiteFromSchema<{ readonly _id: { readonly type: StringConstructor; readonly required: true; }; readonly expiredAt: { readonly type: DateConstructor; }; }, {}>, name: string) => Promise; /** * Resolve once the named lock is gone or expires. Optionally reject after * `timeoutMs` so callers can bound the wait. * @param {string} name * @param {number} [timeoutMs] reject after this many ms if still locked */ readonly waitForUnlock: (this: GetModelTypeLiteFromSchema<{ readonly _id: { readonly type: StringConstructor; readonly required: true; }; readonly expiredAt: { readonly type: DateConstructor; }; }, {}>, name: string, timeoutMs?: number) => Promise; /** * get lock remaining time based on lock name * @param {string} name */ readonly getLockData: (this: GetModelTypeLiteFromSchema<{ readonly _id: { readonly type: StringConstructor; readonly required: true; }; readonly expiredAt: { readonly type: DateConstructor; }; }, {}>, name: string) => Promise<{ ttl: number; }>; /** * get lock remaining time based on lock name * @param {string[]} names */ readonly getLocksData: (this: GetModelTypeLiteFromSchema<{ readonly _id: { readonly type: StringConstructor; readonly required: true; }; readonly expiredAt: { readonly type: DateConstructor; }; }, {}>, names: string[]) => Promise<{ name: string; ttl: number; }[]>; }; } export default Lock;