UNPKG

@lunora/cli

Version:

The Lunora CLI: init, dev, deploy, codegen, migrate, seed, doctor, insights, logs, registry, and the rest of the project commands

4 lines (3 loc) • 1.6 kB
import{LunoraError as r}from"@lunora/errors";import{E as y,c as N}from"./shared-CV7ESvuj.mjs";const g=async(l,f,h)=>{const n=await l.fetchImpl(`${l.baseUrl}${y}`,{body:JSON.stringify({tables:f}),headers:{authorization:`Bearer ${l.token}`,"content-type":"application/json"},method:"POST"});if(!n.ok)throw new r("INTERNAL",`reading the deployment's rows failed (HTTP ${String(n.status)})`);if(!n.body)throw new r("INTERNAL","reading the deployment's rows failed: the export response carried no body");const s=n.body.getReader(),w=new TextDecoder;let t="",i=0;const c=N(),p=o=>{if(i+=1,o.trim().length===0)return!0;const a=`reading the deployment's rows failed: export line ${String(i)} (${String(o.length)} characters) is not a { table, doc } row`;let e;try{e=JSON.parse(o)}catch{throw new r("INTERNAL",a)}try{if(!c.read(e))return!0}catch{throw new r("INTERNAL",`reading the deployment's rows failed: export line ${String(i)} follows the export's end marker`)}if(e===null||typeof e.table!="string"||e.doc===null||typeof e.doc!="object")throw new r("INTERNAL",a);return h({doc:e.doc,table:e.table})!==!1};try{for(;;){const{done:a,value:e}=await s.read();if(a)break;t+=w.decode(e,{stream:!0});let d=t.indexOf(` `);for(;d!==-1;){const m=t.slice(0,d);if(t=t.slice(d+1),!p(m)){await s.cancel().catch(()=>{});return}d=t.indexOf(` `)}}if(t.trim().length>0)throw new r("INTERNAL",`reading the deployment's rows failed: the export ended inside line ${String(i+1)}`);const o=c.problem();if(o!==void 0)throw new r("INTERNAL",`reading the deployment's rows failed: ${o}`)}finally{s.releaseLock()}};export{g as f};