UNPKG

miniflare

Version:

Fun, full-featured, fully-local simulator for Cloudflare Workers

1 lines 5.38 kB
import{c as e,s as t,z as n}from"./useRouterState-DkU0JPAO.js";import{$ as r,Ht as i,Pt as a,Vt as o,a as s,r as c}from"./button-cdxnqcgzwko8ooha-DW4HgSd6.js";import{t as l}from"./label-latndvb1ngem7we8-M6HmFWt4.js";import{t as u}from"./table-inweecadl3her7pd-BRHbXqg_.js";import{t as d}from"./Breadcrumbs-D11-yw8F.js";import{Rt as f,a as p,ct as m,dt as h}from"./index-CkemaNd1.js";var g=e(),_=n(t(),1),v=e=>(0,g.jsxs)(`svg`,{width:`1em`,height:`1em`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,className:`link-external-icon`,...e,children:[(0,g.jsx)(`path`,{d:`M9 4H8.8C7.11984 4 6.27976 4 5.63803 4.32698C5.07354 4.6146 4.6146 5.07354 4.32698 5.63803C4 6.27976 4 7.11984 4 8.8V15.2C4 16.8802 4 17.7202 4.32698 18.362C4.6146 18.9265 5.07354 19.3854 5.63803 19.673C6.27976 20 7.11984 20 8.8 20H15.2C16.8802 20 17.7202 20 18.362 19.673C18.9265 19.3854 19.3854 18.9265 19.673 18.362C20 17.7202 20 16.8802 20 15.2V15`}),(0,g.jsx)(`path`,{d:`M14 4H20M20 4V10M20 4L11 13`})]});v.displayName=`Link.ExternalIcon`;var y={variant:{inline:{classes:`text-kumo-link underline underline-offset-[0.15em] decoration-[0.0625em] link-current transition-colors`,description:`Inline text link that flows with content`},current:{classes:`text-current underline underline-offset-[0.15em] decoration-[0.0625em] link-current transition-colors`,description:`Link that inherits color from parent text`},plain:{classes:`text-kumo-link hover:text-kumo-link/70 transition-colors`,description:`Link without underline decoration`}}},b={variant:`inline`};function x({variant:e=b.variant}={}){return o(y.variant[e].classes)}var S=(0,_.forwardRef)(function({className:e,variant:t=`inline`,render:n,...i},c){let l=s(),u={className:o(x({variant:t}),`group/link inline-flex items-center gap-[0.1875em]`)};return a({render:n??(0,g.jsx)(l,{}),ref:c,props:r(u,i,{className:e})})});S.displayName=`Link`;var C=Object.assign(S,{ExternalIcon:v});function w(){let e=p.useParams(),t=p.useLoaderData(),{namespaceId:n}=t,r=f(),[a,o]=(0,_.useState)(t.cursor),[s,v]=(0,_.useState)(null),[y,b]=(0,_.useState)(t.hasMore),[x,S]=(0,_.useState)(!1),[w,T]=(0,_.useState)(!1),[E,D]=(0,_.useState)(t.objects),[O,k]=(0,_.useState)(``);(0,_.useEffect)(()=>{D(t.objects),o(t.cursor),b(t.hasMore),v(null),S(!1),T(!1)},[t]);let A=(0,_.useCallback)(async e=>{try{e?T(!0):(S(!0),D([])),v(null);let t=await h({path:{id:n},query:{cursor:e,limit:50}}),r=t.data?.result??[];D(e?e=>[...e,...r]:r);let i=t.data?.result_info?.cursor;o(i??null),b(!!i)}catch(e){v(e instanceof Error?e.message:`Failed to fetch objects`)}finally{S(!1),T(!1)}},[n]);function j(){a&&!w&&A(a)}function M(t){t.preventDefault();let n=O.trim();n&&r({params:{className:e.className,objectId:n},search:{table:void 0},to:`/do/$className/$objectId`})}return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(d,{icon:m,items:[(0,g.jsx)(`span`,{className:`flex items-center gap-1.5`,children:e.className},`class-name`)],title:`Durable Objects`}),(0,g.jsxs)(`div`,{className:`px-6 py-6`,children:[(0,g.jsxs)(`form`,{className:`mb-6 flex items-end gap-2`,onSubmit:M,children:[(0,g.jsxs)(`div`,{className:`max-w-100 flex-1`,children:[(0,g.jsx)(l,{htmlFor:`open-instance`,tooltip:`Get an instance by its name (i.e. idFromName) or by its ID (Cloudflare-generated 64 digit hex ID)`,children:`View specific DO instance`}),(0,g.jsx)(`input`,{id:`open-instance`,className:`bg-bg text-text focus:ring-kumo-ring mt-1.5 h-9 w-full rounded-lg border border-kumo-line px-3 font-mono text-sm focus:ring focus:outline-none`,placeholder:`Enter instance name or hex ID...`,value:O,onChange:e=>k(e.target.value)})]}),(0,g.jsx)(c,{type:`submit`,variant:`secondary`,disabled:!O.trim(),children:`Open Studio`})]}),s&&(0,g.jsx)(`div`,{className:`mb-4 rounded-md border border-kumo-danger/20 bg-kumo-danger/8 p-4 text-kumo-danger`,children:s}),x?(0,g.jsx)(`div`,{className:`p-12 text-center text-kumo-subtle`,children:`Loading...`}):E.length===0?(0,g.jsxs)(`div`,{className:`flex flex-col items-center justify-center space-y-2 p-12 text-center text-kumo-subtle`,children:[(0,g.jsx)(`h2`,{className:`text-2xl font-medium`,children:`No Durable Objects with stored data`}),(0,g.jsx)(`p`,{className:`text-sm font-light`,children:`Create a Durable Object with SQLite storage to see it here.`})]}):(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`div`,{className:`overflow-hidden rounded-lg border border-kumo-fill`,children:(0,g.jsxs)(u,{children:[(0,g.jsx)(u.Header,{children:(0,g.jsxs)(u.Row,{children:[(0,g.jsx)(u.Head,{children:`Name`}),(0,g.jsx)(u.Head,{children:`Object ID`}),(0,g.jsx)(u.Head,{})]})}),(0,g.jsx)(u.Body,{children:E.map(t=>(0,g.jsxs)(u.Row,{children:[(0,g.jsx)(u.Cell,{className:`font-mono text-xs`,children:t.name??`—`}),(0,g.jsx)(u.Cell,{className:`text-text-secondary font-mono text-xs`,children:t.id}),(0,g.jsx)(u.Cell,{className:`text-right`,children:(0,g.jsxs)(i,{className:`inline-flex h-6.5 items-center gap-1 rounded-md px-2 text-xs hover:bg-kumo-fill`,params:{className:e.className,objectId:t.id},search:{table:void 0},to:`/do/$className/$objectId`,children:[`Open Studio`,(0,g.jsx)(C.ExternalIcon,{})]})})]},t.id))})]})}),y&&(0,g.jsx)(`div`,{className:`py-4 text-center`,children:(0,g.jsx)(c,{variant:`secondary`,disabled:w,loading:w,onClick:j,children:w?`Loading...`:`Load More`})})]})]})]})}export{w as component};