/** * Internal contract-registry ownership and active-use lifecycle. * * Public registry operations intentionally remain synchronous and preserve * their existing signatures. Loader-owned registrations additionally carry * an opaque generation identity so teardown can stop admission, drain active * users, and remove only the exact entries that generation published. * * @internal */ type ContractGenerationStatus = "staging" | "active" | "retiring" | "retired" | "failed"; interface ContractEntry { readonly implementation: T; readonly generation: ContractGeneration | undefined; } interface ContractLeaseRecord { released: boolean; quarantined: boolean; quarantineFailure: Error | undefined; retirementNotified: boolean; retirementHandler: ((reason: unknown) => void) | undefined; } /** Opaque ownership state for one loader generation. */ export interface ContractGeneration { /** Registry epoch that owns every global side effect of this generation. */ readonly resetToken: object; status: ContractGenerationStatus; readonly entries: Map; /** Candidate entries hidden by explicit rollback-time register/unregister. */ readonly entryOverlayShadows: Set; readonly leases: Set; readonly retirementHandlerFailures: unknown[]; retirementNotificationDepth: number; retirementReason: unknown; hasRetirementReason: boolean; retirementNotificationStarted: boolean; settleLeaseDrain: (() => void) | undefined; rejectLeaseDrain: ((reason: unknown) => void) | undefined; retirementDrainQuarantined: boolean; retirementPromise: Promise | undefined; } /** A stable reference captured with a resolved contract implementation. */ export interface ContractReference { readonly name: string; readonly entry: ContractEntry; } /** One active-use lease. Release is idempotent. */ export interface ContractLease { /** * Register the synchronous cancellation control for this use. When * retirement already started, registration invokes it immediately. */ setRetirementHandler(handler: (reason: unknown) => void): void; /** * Close generation admission after this use outlives its cancellation grace. * The lease remains active until the provider reports terminal settlement. */ quarantine(): void; /** Release this generation use. Safe to call more than once. */ release(): void; } /** A contract implementation and the identity required to lease it. */ export interface ContractSnapshot { readonly implementation: T; readonly reference: ContractReference; } /** * Reject candidate preparation before extension-controlled materialization or * transition hooks can run inside a current or inherited teardown scope. */ export declare function assertContractGenerationAdmissionAllowed(): void; /** Read one raw public registration. */ export declare function tryResolveRegisteredContract(name: string): T | undefined; /** * Bind raw contract resolution to a failed candidate during rollback. * * Failed candidates retain their unpublished staged dependencies. Reset and * hook settlement still revoke inherited descendants. */ export declare function runWithContractGenerationResolution(generation: ContractGeneration, operation: () => T | Promise): Promise; /** * Bind teardown to one registry epoch without overriding current raw entries. * * Successful teardown keeps the registry's public overwrite semantics while * stale or detached work remains unable to cross a reset boundary. */ export declare function runWithContractGenerationEpoch(generation: ContractGeneration, operation: () => T | Promise): Promise; /** Install one unmanaged public registration. */ export declare function registerUnmanagedContract(name: string, implementation: T): void; /** Remove the current public registration without lifecycle coordination. */ export declare function unregisterContract(name: string): void; /** * Force-clear the public registry and lifecycle state. * * This preserves the historical synchronous reset primitive used by tests and * composition roots. Normal loader shutdown must use generation retirement. */ export declare function resetContractRegistry(): void; /** Start staging one candidate generation without publishing partial entries. */ export declare function beginContractGeneration(): ContractGeneration; /** Stage or replace one loader-owned entry inside a candidate generation. */ export declare function stageContract(generation: ContractGeneration, name: string, implementation: T): void; /** Resolve candidate-local dependencies without publishing the candidate. */ export declare function tryResolveContractForGeneration(generation: ContractGeneration, name: string): T | undefined; /** Atomically publish every staged entry and open active-use admission. */ export declare function commitContractGeneration(generation: ContractGeneration): void; /** * Capture a contract for lifecycle-aware use. * * Missing is distinct from an unavailable transition: callers may apply their * documented fallback only for a stable, genuinely absent registration. */ export declare function trySnapshotContractForUse(name: string): Readonly> | undefined; /** * Capture only a loader-generation-owned contract for security-sensitive use. * * Ownerless registrations remain available to compatibility consumers through * `trySnapshotContractForUse`, but cannot satisfy a contract whose safety * depends on retirement fencing and active-use lease drainage. */ export declare function trySnapshotGenerationOwnedContractForUse(name: string): Readonly> | undefined; /** Acquire active-use ownership immediately before invoking a contract. */ export declare function acquireContractLease(reference: Readonly>): Readonly; /** * Close admission synchronously before contexts or other generation-owned * resources begin revocation. */ export declare function sealContractGeneration(generation: ContractGeneration, reason?: unknown): void; /** * Notify active uses synchronously, then await release or reject if an active * lease has quarantined the generation. A drain may be retried after release. */ export declare function drainContractGeneration(generation: ContractGeneration): Promise; /** Whether every admitted use has released before extension teardown begins. */ export declare function isContractGenerationDrained(generation: ContractGeneration): boolean; /** Complete a successful teardown and remove only this generation's entries. */ export declare function completeContractGenerationRetirement(generation: ContractGeneration): void; /** * Finish a failed candidate. Absence remains fail-closed until a later * generation commits successfully or the low-level registry is reset. */ export declare function failContractGeneration(generation: ContractGeneration): void; export {}; //# sourceMappingURL=contract-registry-internal.d.ts.map