@north-light/crouter 0.3.350 → 0.3.351
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
var T=Object.defineProperty;var a=(r,e)=>T(r,"name",{value:e,configurable:!0});import{request as g}from"node:http";import{homedir as A}from"node:os";import{join as p}from"node:path";import{CrtrClient as S}from"./client.js";
|
|
1
|
+
var T=Object.defineProperty;var a=(r,e)=>T(r,"name",{value:e,configurable:!0});import{request as g}from"node:http";import{homedir as A}from"node:os";import{join as p}from"node:path";import{CrtrClient as S}from"./client.js";const O=".crouter",_="api.sock",v=Symbol.for("@north-light/crouter-api/local-socket-fetch");function k(){const r=process.env.CRTR_API_SOCKET;if(r)return r;const e=process.env.CRTR_HOME,t=e!==void 0&&e!==""?e:p(A(),O);return p(process.platform==="linux"?"/run/crtr":p(t,"runtime"),_)}a(k,"defaultSocketPath");function x(r){const e=a(function(t,s={}){const m=t instanceof URL?t:new URL(typeof t=="string"?t:t.url),w=s.method??"GET",l={};if(s.headers!==void 0)for(const[h,u]of new Headers(s.headers).entries())l[h]=u;const f=typeof s.body=="string"?s.body:void 0;return f!==void 0&&(l["content-length"]=String(Buffer.byteLength(f))),new Promise((h,u)=>{const i=g({socketPath:r,path:m.pathname+m.search,method:w,headers:l},o=>{const C=new ReadableStream({start(d){o.on("data",n=>d.enqueue(new Uint8Array(n))),o.on("end",()=>d.close()),o.on("error",n=>d.error(n))},cancel(){o.destroy()}}),b=new Headers;for(const[d,n]of Object.entries(o.headers))if(n!==void 0)for(const R of Array.isArray(n)?n:[n])b.append(d,R);const E=o.statusCode??0;h(new Response(E===204?null:C,{status:E,statusText:o.statusMessage,headers:b}))});i.on("error",o=>u(new TypeError("fetch failed",{cause:o})));const c=s.signal,y=a(()=>{i.destroy(),u(c?.reason??new DOMException("The operation was aborted.","AbortError"))},"abort");if(c!=null){if(c.aborted){y();return}c.addEventListener("abort",y,{once:!0})}f!==void 0&&i.write(f),i.end()})},"fetchOverSocket");return e[v]=!0,e}a(x,"socketFetch");function U(r={}){const{socketPath:e,...t}=r;return new S({baseUrl:"http://localhost",fetch:x(e??k()),autostart:!0,...t})}a(U,"localClient");export{k as defaultSocketPath,U as localClient,x as socketFetch};
|