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 h=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}},m=/already (?:exists|indexed)|duplicate/iu,i=e=>["vectorize","create-metadata-index",e.index,`--property-name=${e.property}`,`--type=${e.type}`],g=async(e,t)=>{try{return await e(t)}catch(r){return{code:1,stderr:r instanceof Error?r.message:String(r)}}},x=async e=>{const{cwd:t,entries:r,exec:s,logger:E,spawner:p}=e,a=[];for(const n of r){const o=await g(p,{args:[...s.args,...i(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(m.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 ${i(n).join(" ")}`)}return a},u=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"],A=new RegExp(`(?:${[...l,...S.map(e=>e.replaceAll("_",""))].join("|")})S?$`,"iu"),_=e=>d(e).some(t=>t==="PUBLIC"||t==="PUBLISHABLE"),I=e=>{if(_(e))return!1;const t=d(e);if(t.some(s=>l.has(u(s))))return!0;const r=u(t.join("_"));return S.some(s=>r===s||r.endsWith(`_${s}`))||A.test(e)};export{i as c,x as e,I as i,h as m};