export class ResourceTracker {
    resources = new Map();
    track(id, type) {
        if (this.resources.has(id)) {
            throw new Error(`Resource already tracked: ${id}`);
        }
        this.resources.set(id, { id, type, disposed: false });
    }
    dispose(id) {
        const resource = this.resources.get(id);
        if (!resource) {
            throw new Error(`Unknown resource: ${id}`);
        }
        this.resources.set(id, { ...resource, disposed: true });
    }
    report() {
        const resources = [...this.resources.values()].sort((a, b) => a.id.localeCompare(b.id));
        const leaks = resources.filter((resource) => !resource.disposed);
        return {
            total: resources.length,
            leaked: leaks.length,
            resources,
            leaks
        };
    }
    assertNoLeaks() {
        const report = this.report();
        if (report.leaked > 0) {
            throw new ResourceLeakError("Resource leaks detected", report);
        }
    }
}
export class ResourceLeakError extends Error {
    report;
    constructor(message, report) {
        super(message);
        this.report = report;
        this.name = "ResourceLeakError";
    }
}
//# sourceMappingURL=ResourceTracker.js.map