UNPKG

@lunora/cli

Version:

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

2 lines (1 loc) 1.67 kB
const i=e=>e.endsWith("S")?e.slice(0,-1):e,d=e=>e.replaceAll(/([a-z\d])([A-Z])/gu,"$1_$2").toUpperCase().split(/[_-]+/u).filter(t=>t.length>0),l=new Set(["CREDENTIAL","DSN","PASSPHRASE","PASSWD","PASSWORD","SECRET","TOKEN"]),S=["ACCESS_KEY","API_KEY","ENCRYPTION_KEY","PRIVATE_KEY","SIGNING_KEY"],m=new RegExp(`(?:${[...l,...S.map(e=>e.replaceAll("_",""))].join("|")})S?$`,"iu"),g=e=>d(e).some(t=>t==="PUBLIC"||t==="PUBLISHABLE"),h=e=>{if(g(e))return!1;const t=d(e);if(t.some(s=>l.has(i(s))))return!0;const r=i(t.join("_"));return S.some(s=>r===s||r.endsWith(`_${s}`))||m.test(e)},x=e=>{switch(e){case"boolean":return"boolean";case"date":case"number":case"timestamp":return"number";case"id":case"literal":case"string":return"string";default:return}},A=/already (?:exists|indexed)|duplicate/iu,u=e=>["vectorize","create-metadata-index",e.index,`--property-name=${e.property}`,`--type=${e.type}`],_=async(e,t)=>{try{return await e(t)}catch(r){return{code:1,stderr:r instanceof Error?r.message:String(r)}}},I=async e=>{const{cwd:t,entries:r,exec:s,logger:E,spawner:p}=e,a=[];for(const n of r){const o=await _(p,{args:[...s.args,...u(n)],captureStderr:!0,command:s.command,cwd:t,stdoutToStderr:!0});if(o.code===0){a.push({entry:n,status:"created"});continue}const c=`${o.stderr??""}${o.stdout??""}`;if(A.test(c)){a.push({entry:n,status:"exists"});continue}a.push({entry:n,error:c.trim()||`exit code ${String(o.code)}`,status:"failed"}),E.warn(`could not create the Vectorize metadata index for "${n.property}" on "${n.index}" — filters on that property will match nothing until it exists. Run: wrangler ${u(n).join(" ")}`)}return a};export{u as c,I as e,h as i,x as m};