// @bun
var o=Object.defineProperty;var s=(t)=>t;function n(t,i){this[t]=s.bind(null,i)}var m=(t,i)=>{for(var r in i)o(t,r,{get:i[r],enumerable:!0,configurable:!0,set:n.bind(i,r)})};var u=(t,i)=>()=>(t&&(i=t(t=0)),i);import{CodeBlock as c,InstallCommand as d}from"@contractspec/lib.design-system";import l from"@contractspec/lib.ui-link";import{ChevronRight as p}from"lucide-react";import{jsx as e,jsxs as a}from"react/jsx-runtime";function g(){return a("div",{className:"space-y-8",children:[a("div",{className:"space-y-4",children:[e("h1",{className:"font-bold text-4xl",children:"Resilience Library"}),a("p",{className:"text-lg text-muted-foreground",children:["The ",e("code",{children:"@contractspec/lib.resilience"})," library provides primitives to handle failures gracefully."]})]}),a("div",{className:"space-y-4",children:[e("h2",{className:"font-bold text-2xl",children:"Installation"}),e(d,{package:"@contractspec/lib.resilience"})]}),a("div",{className:"space-y-4",children:[e("h2",{className:"font-bold text-2xl",children:"Circuit Breaker"}),e("p",{className:"text-muted-foreground",children:"Prevent cascading failures by stopping calls to a failing dependency."}),e(c,{language:"typescript",code:`import { CircuitBreaker } from '@contractspec/lib.resilience/circuit-breaker';

const breaker = new CircuitBreaker({
  failureThreshold: 5,
  resetTimeoutMs: 30000,
});

const result = await breaker.execute(async () => {
  return await fetch('https://api.stripe.com/v1/charges');
});`})]}),a("div",{className:"space-y-4",children:[e("h2",{className:"font-bold text-2xl",children:"Retry"}),e("p",{className:"text-muted-foreground",children:"Automatically retry transient failures with exponential backoff."}),e(c,{language:"typescript",code:`import { retry } from '@contractspec/lib.resilience/retry';

const result = await retry(
  async () => fetchUser(id),
  3, // retries
  1000, // initial delay
  true // backoff
);`})]}),a("div",{className:"space-y-4",children:[e("h2",{className:"font-bold text-2xl",children:"Timeout & Fallback"}),e("p",{className:"text-muted-foreground",children:"Set hard limits on execution time and provide default values on failure."}),e(c,{language:"typescript",code:`import { timeout, fallback } from '@contractspec/lib.resilience';

const result = await fallback(
  () => timeout(slowOperation, 5000),
  defaultValue
);`})]}),a("div",{className:"flex items-center gap-4 pt-4",children:[e(l,{href:"/docs/libraries",className:"btn-ghost",children:"Back to Libraries"}),a(l,{href:"/docs/libraries/testing",className:"btn-primary",children:["Next: Testing ",e(p,{size:16})]})]})]})}export{g as LibrariesResiliencePage};
