@lunora/cli
Version:
The Lunora CLI: init, dev, deploy, codegen, run, reset, and migrate commands
2 lines (1 loc) • 1.46 kB
JavaScript
import{LunoraError as d}from"@lunora/errors";import{i as g}from"../packem_shared/command-Bjv4VmYA.mjs";import{t as l}from"../packem_shared/resolve-target-vxaXHmvg.mjs";const h=r=>{if(r===void 0||r.length===0)return{};try{return JSON.parse(r)}catch(o){const t=o instanceof Error?o.message:String(o);throw new d("INTERNAL",`failed to parse --args as JSON: ${t}`,{cause:o})}},f=/\/$/u,p=async r=>{const o=`${(l({cwd:r.cwd??process.cwd(),url:r.url})??"http://localhost:8787").replace(f,"")}/_lunora/rpc`,t=r.fetchImpl??globalThis.fetch;if(typeof t!="function")throw new TypeError("no fetch implementation available — pass --fetch via dependency injection or run on Node >= 18");let e;try{e=h(r.args)}catch(s){const u=s instanceof Error?s.message:String(s);return r.logger.error(u),{body:void 0,code:1,requestUrl:o}}const a={args:e,functionPath:r.functionPath};r.shard!==void 0&&(a.shardKey=r.shard),r.logger.info(`POST ${o} -> ${r.functionPath}`);const c=await t(o,{body:JSON.stringify(a),headers:{"content-type":"application/json"},method:"POST"}),i=await c.text();let n;try{n=JSON.parse(i)}catch{n=i}return r.logger.info(JSON.stringify(n,void 0,2)),{body:n,code:c.ok?0:1,requestUrl:o}},S=g(({argument:r,cwd:o,logger:t,options:e})=>{const a=r[0];return a?p({args:e.args,cwd:o,functionPath:a,logger:t,shard:e.shard,url:e.url}):(t.error("missing function path. Usage: lunora run <functionPath> [--args <json>]"),{code:1})});export{S as execute,p as runRpcCommand};