import{CodeBlock as a,InstallCommand as r}from"@contractspec/lib.design-system";import i from"@contractspec/lib.ui-link";import{ChevronRight as c}from"lucide-react";import{jsx as e,jsxs as t}from"react/jsx-runtime";function n(){return t("div",{className:"space-y-8",children:[t("div",{className:"space-y-4",children:[e("h1",{className:"font-bold text-4xl",children:"Resilience Library"}),t("p",{className:"text-lg text-muted-foreground",children:["The ",e("code",{children:"@contractspec/lib.resilience"})," library provides primitives to handle failures gracefully."]})]}),t("div",{className:"space-y-4",children:[e("h2",{className:"font-bold text-2xl",children:"Installation"}),e(r,{package:"@contractspec/lib.resilience"})]}),t("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(a,{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');
});`})]}),t("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(a,{language:"typescript",code:`import { retry } from '@contractspec/lib.resilience/retry';

const result = await retry(
  async () => fetchUser(id),
  3, // retries
  1000, // initial delay
  true // backoff
);`})]}),t("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(a,{language:"typescript",code:`import { timeout, fallback } from '@contractspec/lib.resilience';

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