@shumai-one/shumai 0.4.4 → 0.4.6
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.
- package/bin/{chunk-snhsjs4x.js → chunk-07jszkhj.js} +62 -62
- package/bin/chunk-0c67210c.js +1 -0
- package/bin/{chunk-kswvyqq1.js → chunk-0wvhahzh.js} +2 -2
- package/bin/chunk-161rxeq2.js +2 -0
- package/bin/{chunk-trveq4wg.js → chunk-1bgsphyz.js} +2 -2
- package/bin/{chunk-vap4k11j.js → chunk-1dqsf5qj.js} +6 -6
- package/bin/{chunk-zxk7q0zk.js → chunk-1jybg56e.js} +1 -1
- package/bin/chunk-1kt5dzjv.js +2 -0
- package/bin/{chunk-drepsbb4.js → chunk-1t51fp6n.js} +1 -1
- package/bin/{chunk-cbgq517y.js → chunk-2jrjwaqr.js} +2 -2
- package/bin/chunk-2qjfpmcf.js +2 -0
- package/bin/{chunk-wjyaezs7.js → chunk-2vzzd0q6.js} +1 -1
- package/bin/chunk-2yr5k567.js +2 -0
- package/bin/chunk-2z1pnt7h.js +2 -0
- package/bin/{chunk-0zv3bks2.js → chunk-3d5rm1d1.js} +1 -1
- package/bin/{chunk-w4ghe71n.js → chunk-3d9tfxp4.js} +1 -1
- package/bin/{chunk-0qjfahk9.js → chunk-3dgahs95.js} +1 -1
- package/bin/{chunk-dqxeztfa.js → chunk-3j5njrpr.js} +2 -2
- package/bin/{chunk-ryzz5fht.js → chunk-3n4224c0.js} +1 -1
- package/bin/{chunk-914bp49r.js → chunk-3tg39jx7.js} +3 -3
- package/bin/chunk-3vmapyk9.js +1 -0
- package/bin/{chunk-g3fpmyyn.js → chunk-46wfxyd7.js} +2 -2
- package/bin/{chunk-4hkkdm2q.js → chunk-47tn3vtg.js} +1 -1
- package/bin/{chunk-1zwajpwf.js → chunk-4syt6rn0.js} +3 -3
- package/bin/chunk-5kvc1gp2.js +1 -0
- package/bin/{chunk-xa18z1py.js → chunk-5vvvgjvz.js} +2 -2
- package/bin/{chunk-5nm2jvg5.js → chunk-6vxzkrsj.js} +11 -11
- package/bin/{chunk-ytdwk2fq.js → chunk-6y4xkcte.js} +2 -2
- package/bin/{chunk-fpc4p0j8.js → chunk-7e5z637e.js} +2 -2
- package/bin/chunk-7nvk7waw.js +1 -0
- package/bin/{chunk-rq0n0vcc.js → chunk-80qz30dc.js} +2 -2
- package/bin/chunk-886pnknh.js +3 -0
- package/bin/{chunk-6ghcj4a9.js → chunk-8cn7fx40.js} +1 -1
- package/bin/chunk-908pypkr.js +1 -0
- package/bin/chunk-952qwf17.js +2 -0
- package/bin/chunk-988casfy.js +1 -0
- package/bin/chunk-9a2tf0mh.js +2 -0
- package/bin/{chunk-nkdk229f.js → chunk-9d0thqcy.js} +1 -1
- package/bin/{chunk-s2k4qntr.js → chunk-9nvymwqj.js} +2 -2
- package/bin/{chunk-mz0yjra0.js → chunk-9trnkbtr.js} +4 -4
- package/bin/{chunk-t2hy6tj9.js → chunk-a4056d0r.js} +1 -1
- package/bin/{chunk-ze20rm02.js → chunk-a796sgcw.js} +4 -4
- package/bin/{chunk-kpgfqkp0.js → chunk-afnzb9ne.js} +2 -2
- package/bin/chunk-apfrw0wd.js +3 -0
- package/bin/{chunk-wndm3px3.js → chunk-axmd242s.js} +1 -1
- package/bin/{chunk-nr20tvnw.js → chunk-b3aqmcps.js} +2 -2
- package/bin/chunk-b6q287d1.js +2 -0
- package/bin/{chunk-j1tkmcae.js → chunk-b9hyc0a1.js} +2 -2
- package/bin/chunk-ba33nf0q.js +4 -0
- package/bin/chunk-batadmvr.js +2 -0
- package/bin/{chunk-1t167cvj.js → chunk-brwbhbmc.js} +7 -7
- package/bin/chunk-bvdvp192.js +1 -0
- package/bin/{chunk-fahk9h62.js → chunk-crja7whq.js} +2 -2
- package/bin/{chunk-98715kc3.js → chunk-d7fwggt6.js} +2 -2
- package/bin/chunk-db1msmdh.js +2 -0
- package/bin/{chunk-97f2af6d.js → chunk-dbw8c1jj.js} +5 -5
- package/bin/{chunk-7gmdnsdg.js → chunk-dj5a6kkh.js} +1 -1
- package/bin/chunk-dkx3pmdz.js +1 -0
- package/bin/{chunk-071x515q.js → chunk-dmvvt8va.js} +2 -2
- package/bin/{chunk-3tedzb2j.js → chunk-dpc11hpd.js} +9 -9
- package/bin/{chunk-ks8xzc95.js → chunk-dscq4a4k.js} +2 -2
- package/bin/{chunk-jmpb5633.js → chunk-dz076sh7.js} +1 -1
- package/bin/chunk-edqd8evk.js +2 -0
- package/bin/{chunk-0qaq0sp8.js → chunk-ehpfg3km.js} +2 -2
- package/bin/chunk-ey3h4sct.js +2 -0
- package/bin/{chunk-vm5fx7td.js → chunk-ga3pahzf.js} +1 -1
- package/bin/chunk-gc6m7agb.js +3 -0
- package/bin/{chunk-7bcxj1jd.js → chunk-gcjsw9yp.js} +1 -1
- package/bin/chunk-gqr5hxhj.js +2 -0
- package/bin/{chunk-jrjnqx78.js → chunk-gsfcpcye.js} +1 -1
- package/bin/chunk-h9mka9br.js +2 -0
- package/bin/chunk-hacyjx1s.js +1 -0
- package/bin/chunk-hd6dnnyg.js +2 -0
- package/bin/chunk-he5nvmqw.js +1 -0
- package/bin/{chunk-reyxk4bw.js → chunk-hnhdq2wd.js} +1 -1
- package/bin/{chunk-gt4csat6.js → chunk-hs2r9qaw.js} +2 -2
- package/bin/{chunk-fb40xxz3.js → chunk-hxyg5q2a.js} +2 -2
- package/bin/chunk-hyr1vtfp.js +1 -0
- package/bin/{chunk-zw86wnwe.js → chunk-j9ks8bd7.js} +2 -2
- package/bin/{chunk-1gvscz88.js → chunk-jg2v25d2.js} +2 -2
- package/bin/chunk-jh8q3885.js +211 -0
- package/bin/chunk-jzbrt2vk.js +1 -0
- package/bin/chunk-k6avge95.js +10 -0
- package/bin/{chunk-msfw3jmc.js → chunk-kg8eg9z3.js} +2 -2
- package/bin/chunk-kk42xhgz.js +1 -0
- package/bin/{chunk-3ttrhqy3.js → chunk-kmbjp5kp.js} +2 -2
- package/bin/{chunk-jgs8an3h.js → chunk-md5pcq46.js} +8 -8
- package/bin/{chunk-xarsrs08.js → chunk-mtb9fpj2.js} +1 -1
- package/bin/chunk-n3xjwszr.js +2 -0
- package/bin/chunk-nqym3zbs.js +1 -0
- package/bin/{chunk-579e4wv4.js → chunk-p75f5pgq.js} +2 -2
- package/bin/{chunk-hm0dkzed.js → chunk-pdh9bnyj.js} +2 -2
- package/bin/{chunk-rhvv1vvk.js → chunk-pgj2kjnn.js} +2 -2
- package/bin/{chunk-hmpwg5za.js → chunk-pvg3msgw.js} +8 -8
- package/bin/{chunk-4991gz3y.js → chunk-pwkby9h7.js} +6 -6
- package/bin/{chunk-fnmwksnb.js → chunk-qbqym9m6.js} +2 -2
- package/bin/{chunk-4wy87hwd.js → chunk-qgkbxw1k.js} +2 -2
- package/bin/{chunk-1j27fzy1.js → chunk-qs7855cz.js} +2 -2
- package/bin/{chunk-7jtmwt5a.js → chunk-radcwage.js} +2 -2
- package/bin/{chunk-gk2q9a3f.js → chunk-rmzcarv9.js} +2 -2
- package/bin/{chunk-s2fnfyn9.js → chunk-rp4pc6kz.js} +1 -1
- package/bin/{chunk-5adsx8x4.js → chunk-rsd164d9.js} +2 -2
- package/bin/{chunk-hk5rc6cd.js → chunk-s05cdax2.js} +4 -4
- package/bin/{chunk-pazjhrnf.js → chunk-sab7tjxw.js} +5 -5
- package/bin/chunk-sebbjvgv.css +1 -0
- package/bin/{chunk-bkr5zm4h.js → chunk-t350k3s1.js} +1 -1
- package/bin/{chunk-4v41a1r9.js → chunk-t7bvde99.js} +3 -3
- package/bin/chunk-t8gv2ekj.js +14 -0
- package/bin/chunk-teqprbd8.js +2 -0
- package/bin/chunk-tgr86ac4.js +2 -0
- package/bin/{chunk-5hg6kcfz.js → chunk-v8v8vdf7.js} +9 -9
- package/bin/chunk-vm5tn0zm.js +2 -0
- package/bin/chunk-vzj2j11x.js +2 -0
- package/bin/chunk-w1wxzqqb.js +2 -0
- package/bin/chunk-wmjp8dcm.js +1 -0
- package/bin/chunk-wy8dkyxj.js +1 -0
- package/bin/{chunk-a6gx7f5q.js → chunk-y1b3ck7m.js} +1 -1
- package/bin/{chunk-1xh34aew.js → chunk-y20sbaz5.js} +2 -2
- package/bin/{chunk-qsr1a0rp.js → chunk-y56yvezn.js} +1 -1
- package/bin/{chunk-9t8n2des.js → chunk-yfr0hzb7.js} +2 -2
- package/bin/chunk-ysv80zyb.js +5 -0
- package/bin/chunk-z08bqvkc.js +42 -0
- package/bin/{chunk-5tcdwep5.js → chunk-z6jpt0h6.js} +4 -4
- package/bin/shumai-app.html +1 -1
- package/bin/shumai-app.js +605 -370
- package/package.json +7 -7
- package/prisma/migrations/20260913130237_add_asset_comment_asset_id_idx/migration.sql +2 -0
- package/prisma/migrations/20260914024424_add_asset_comment_reactions/migration.sql +22 -0
- package/prisma/migrations/20260914064432_limit_reaction_code_length/migration.sql +8 -0
- package/prisma/migrations/20260914092940_add_jpeg_preview_flags/migration.sql +5 -0
- package/prisma/schema.prisma +22 -0
- package/bin/chunk-0cmx7k4c.js +0 -1
- package/bin/chunk-16xax8kk.js +0 -1
- package/bin/chunk-2w5xqhjm.js +0 -1
- package/bin/chunk-3zkasqb8.js +0 -1
- package/bin/chunk-453ykvaw.js +0 -2
- package/bin/chunk-4mjywsj8.js +0 -3
- package/bin/chunk-5vzrpz50.js +0 -2
- package/bin/chunk-77fmkpdz.js +0 -10
- package/bin/chunk-7kjgvxqa.js +0 -2
- package/bin/chunk-7pw1550a.js +0 -2
- package/bin/chunk-7rhz2gze.js +0 -211
- package/bin/chunk-837fky18.js +0 -3
- package/bin/chunk-84as6x83.js +0 -1
- package/bin/chunk-8e28hcny.js +0 -2
- package/bin/chunk-9ccw540k.js +0 -2
- package/bin/chunk-9ybt6vbm.js +0 -1
- package/bin/chunk-avwgktxb.js +0 -2
- package/bin/chunk-d27mm390.js +0 -1
- package/bin/chunk-dj92fss9.js +0 -2
- package/bin/chunk-f6svp4dp.js +0 -2
- package/bin/chunk-fsyzs0tf.js +0 -1
- package/bin/chunk-fxecgp5k.js +0 -1
- package/bin/chunk-gc5sbfa5.js +0 -2
- package/bin/chunk-gdm6yfqq.js +0 -2
- package/bin/chunk-gye8gabk.js +0 -2
- package/bin/chunk-j2bvj2yn.js +0 -2
- package/bin/chunk-jffktpqg.js +0 -1
- package/bin/chunk-k2k9vjq6.js +0 -1
- package/bin/chunk-m9pr03kn.js +0 -2
- package/bin/chunk-mfn9qjm4.js +0 -2
- package/bin/chunk-nbdw8fen.js +0 -1
- package/bin/chunk-q806pqeh.js +0 -1
- package/bin/chunk-qka4mkmj.js +0 -2
- package/bin/chunk-rchsme43.js +0 -3
- package/bin/chunk-rqf7999q.js +0 -42
- package/bin/chunk-rssgmj7x.js +0 -2
- package/bin/chunk-t7nsgg5k.js +0 -4
- package/bin/chunk-tm7f32c7.js +0 -14
- package/bin/chunk-vy8gntez.js +0 -1
- package/bin/chunk-vyzptrea.js +0 -2
- package/bin/chunk-wdsf44hs.js +0 -2
- package/bin/chunk-x5jwwvs0.js +0 -1
- package/bin/chunk-x92cq59c.js +0 -1
- package/bin/chunk-xtf3c29c.css +0 -1
- package/bin/chunk-xx337zcw.js +0 -2
- package/bin/chunk-xz6713tj.js +0 -2
- package/bin/chunk-yfnem6se.js +0 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Jt,
|
|
2
|
+
import{Jt,qt}from"./chunk-md5pcq46.js";import{w,G}from"./chunk-qbqym9m6.js";var Go=w(function(he){var{hasOwn:V}=Jt(),{streamCollector:te}=Jt();he.streamCollector=te;var{buildQueryString:K,HttpResponse:Q}=qt(),H=G("https"),{Readable:oe}=G("stream"),N=G("http2");function I(e){let t=e&&typeof e==="object"&&"reason"in e?e.reason:void 0;if(t){if(t instanceof Error){let s=Error("Request aborted");return s.name="AbortError",s.cause=t,s}let n=Error(String(t));return n.name="AbortError",n}let o=Error("Request aborted");return o.name="AbortError",o}var ne=["ECONNRESET","EPIPE","ETIMEDOUT"],J=(e)=>{let t={};for(let o in e){if(!V(e,o))continue;let n=e[o];t[o]=Array.isArray(n)?n.join(","):n}return t},h={setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:(e)=>clearTimeout(e)},F=1000,se=(e,t,o=0)=>{if(!o)return-1;let n=(s)=>{let i=h.setTimeout(()=>{e.destroy(),t(Object.assign(Error(`@smithy/node-http-handler - the request socket did not establish a connection with the server within the configured timeout of ${o} ms.`),{name:"TimeoutError"}))},o-s),c=(a)=>{if(a?.connecting)a.on("connect",()=>{h.clearTimeout(i)});else h.clearTimeout(i)};if(e.socket)c(e.socket);else e.on("socket",c)};if(o<2000)return n(0),0;return h.setTimeout(n.bind(null,F),F)},re=(e,t,o=0,n,s)=>{if(o)return h.setTimeout(()=>{let i=`@smithy/node-http-handler - [${n?"ERROR":"WARN"}] a request has exceeded the configured ${o} ms requestTimeout.`;if(n){let c=Object.assign(Error(i),{name:"TimeoutError",code:"ETIMEDOUT"});e.destroy(c),t(c)}else i+=" Init client requestHandler with throwOnRequestTimeout=true to turn this into an error.",s?.warn?.(i)},o);return-1},ie=3000,ce=(e,{keepAlive:t,keepAliveMsecs:o},n=ie)=>{if(t!==!0)return-1;let s=()=>{if(e.socket)e.socket.setKeepAlive(t,o||0);else e.on("socket",(i)=>{i.setKeepAlive(t,o||0)})};if(n===0)return s(),0;return h.setTimeout(s,n)},j=3000,ae=(e,t,o=0)=>{let n=(s)=>{let i=o-s,c=()=>{e.destroy(),t(Object.assign(Error(`@smithy/node-http-handler - the request socket timed out after ${o} ms of inactivity (configured by client requestHandler).`),{name:"TimeoutError"}))};if(e.socket)e.socket.setTimeout(i,c),e.on("close",()=>e.socket?.removeListener("timeout",c));else e.setTimeout(i,c)};if(0<o&&o<6000)return n(0),0;return h.setTimeout(n.bind(null,o===0?0:j),j)},B=6000;async function X(e,t,o=B,n=!1){let s=t.headers,i=s?s.Expect||s.expect:void 0,c=-1,a=!0;if(!n&&i==="100-continue")a=await Promise.race([new Promise((u)=>{c=Number(h.setTimeout(()=>u(!0),Math.max(B,o)))}),new Promise((u)=>{e.on("continue",()=>{h.clearTimeout(c),u(!0)}),e.on("response",()=>{h.clearTimeout(c),u(!1)}),e.on("error",()=>{h.clearTimeout(c),u(!1)})})]);if(a)ue(e,t.body)}function ue(e,t){if(t instanceof oe){t.pipe(e);return}if(t){let o=Buffer.isBuffer(t);if(o||typeof t==="string"){if(o&&t.byteLength===0)e.end();else e.end(t);return}let s=t;if(typeof s==="object"&&s.buffer&&typeof s.byteOffset==="number"&&typeof s.byteLength==="number"){e.end(Buffer.from(s.buffer,s.byteOffset,s.byteLength));return}e.end(Buffer.from(t));return}e.end()}var fe=0,O=void 0,W=void 0;class L{config;configProvider;socketWarningTimestamp=0;externalAgent=!1;metadata={handlerProtocol:"http/1.1"};static create(e){if(typeof e?.handle==="function")return e;return new L(e)}static checkSocketUsage(e,t,o=console){let{sockets:n,requests:s,maxSockets:i}=e;if(typeof i!=="number"||i===1/0)return t;let c=15000;if(Date.now()-c<t)return t;if(n&&s)for(let a in n){if(!V(n,a))continue;let u=n[a]?.length??0,l=s[a]?.length??0;if(u>=i&&l>=2*i)return o?.warn?.(`@smithy/node-http-handler:WARN - socket usage at capacity=${u} and ${l} additional requests are enqueued.
|
|
3
3
|
See https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/node-configuring-maxsockets.html
|
|
4
|
-
or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler config.`),Date.now()}return t}constructor(e){this.configProvider=new Promise((t,o)=>{if(typeof e==="function")e().then((n)=>{t(this.resolveDefaultConfig(n))}).catch(o);else t(this.resolveDefaultConfig(e))})}destroy(){this.config?.httpAgent?.destroy(),this.config?.httpsAgent?.destroy()}async handle(e,{abortSignal:t,requestTimeout:o}={}){if(!this.config)this.config=await this.configProvider;let n=this.config,s=n.logger,i=e.protocol==="https:";if(!i&&!this.config.httpAgent)this.config.httpAgent=await this.config.httpAgentProvider();return new Promise((c,a)=>{let u=void 0,l=-1,m=-1,T=-1,
|
|
4
|
+
or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler config.`),Date.now()}return t}constructor(e){this.configProvider=new Promise((t,o)=>{if(typeof e==="function")e().then((n)=>{t(this.resolveDefaultConfig(n))}).catch(o);else t(this.resolveDefaultConfig(e))})}destroy(){this.config?.httpAgent?.destroy(),this.config?.httpsAgent?.destroy()}async handle(e,{abortSignal:t,requestTimeout:o}={}){if(!this.config)this.config=await this.configProvider;let n=this.config,s=n.logger,i=e.protocol==="https:";if(!i&&!this.config.httpAgent)this.config.httpAgent=await this.config.httpAgentProvider();return new Promise((c,a)=>{let u=void 0,l=-1,m=-1,T=-1,C=-1,E=-1,k=()=>{h.clearTimeout(l),h.clearTimeout(m),h.clearTimeout(T),h.clearTimeout(C),h.clearTimeout(E)},U=async(r)=>{await u,k(),c(r)},p=async(r)=>{await u,k(),a(r)};if(t?.aborted){let r=I(t);p(r);return}let S=e.headers,R=S?(S.Expect??S.expect)==="100-continue":!1,x=i?n.httpsAgent:n.httpAgent;if(R&&!this.externalAgent)x=new(i?H.Agent:O)({keepAlive:!1,maxSockets:1/0});l=h.setTimeout(()=>{this.socketWarningTimestamp=L.checkSocketUsage(x,this.socketWarningTimestamp,s)},n.socketAcquisitionWarningTimeout??(n.requestTimeout??2000)+(n.connectionTimeout??1000));let D=e.query?K(e.query):"",v=void 0;if(e.username!=null||e.password!=null){let r=e.username??"",f=e.password??"";v=`${r}:${f}`}let P=e.path;if(D)P+=`?${D}`;if(e.fragment)P+=`#${e.fragment}`;let y=e.hostname??"";if(y[0]==="["&&y.endsWith("]"))y=e.hostname.slice(1,-1);else y=e.hostname;let _={headers:e.headers,host:y,method:e.method,path:P,port:e.port,agent:x,auth:v},g=(i?H.request:W)(_,(r)=>{let f=new Q({statusCode:r.statusCode||-1,reason:r.statusMessage,headers:J(r.headers),body:r});U({response:f})});if(g.on("error",(r)=>{if(ne.includes(r.code))p(Object.assign(r,{name:"TimeoutError"}));else p(r)}),t){let r=()=>{g.destroy();let f=I(t);p(f)};if(typeof t.addEventListener==="function"){let f=t;f.addEventListener("abort",r,{once:!0}),g.once("close",()=>f.removeEventListener("abort",r))}else t.onabort=r}let b=o??n.requestTimeout;m=se(g,p,n.connectionTimeout),T=re(g,p,b,n.throwOnRequestTimeout,s??console),C=ae(g,p,n.socketTimeout);let d=_.agent;if(typeof d==="object"&&"keepAlive"in d)E=ce(g,{keepAlive:d.keepAlive,keepAliveMsecs:d.keepAliveMsecs});u=X(g,e,b,this.externalAgent).catch((r)=>(k(),a(r)))})}updateHttpClientConfig(e,t){this.config=void 0,this.configProvider=this.configProvider.then((o)=>{if(e===Symbol.for("logger"))return{...o,logger:o.logger??t};return{...o,[e]:t}})}httpHandlerConfigs(){return this.config??{}}resolveDefaultConfig(e){let{requestTimeout:t,connectionTimeout:o,socketTimeout:n,socketAcquisitionWarningTimeout:s,httpAgent:i,httpsAgent:c,throwOnRequestTimeout:a,logger:u}=e||{},l=!0,m=50;return{connectionTimeout:o,requestTimeout:t,socketTimeout:n,socketAcquisitionWarningTimeout:s,throwOnRequestTimeout:a,httpAgentProvider:async()=>{let T=G("http"),{Agent:C,request:E}=T.default??T;if(W=E,O=C,i instanceof O||typeof i?.destroy==="function")return this.externalAgent=!0,i;return new O({keepAlive:!0,maxSockets:50,...i})},httpsAgent:(()=>{if(c instanceof H.Agent||typeof c?.destroy==="function")return this.externalAgent=!0,c;return new H.Agent({keepAlive:!0,maxSockets:50,...c})})(),logger:u}}}var de=new Uint16Array(1);class M{id=de[0]++;total=0;max=0;session;refs=0;constructor(e){e.unref(),this.session=e}retain(){if(this.session.destroyed)throw Error("@smithy/node-http-handler - cannot acquire reference to destroyed session.");this.refs+=1,this.total+=1,this.max=Math.max(this.refs,this.max),this.session.ref()}free(){if(this.session.destroyed)return;if(this.refs-=1,this.refs===0)this.session.unref();if(this.refs<0)throw Error("@smithy/node-http-handler - ClientHttp2Session refcount at zero, cannot decrement.")}deref(){return this.session}close(){if(!this.session.closed)this.session.close()}destroy(){if(this.refs=0,!this.session.destroyed)this.session.destroy()}useCount(){return this.refs}}class Y{sessions=[];maxConcurrency=0;constructor(e){this.sessions=(e??[]).map((t)=>new M(t))}poll(){let e=!1;for(let t of this.sessions){if(t.deref().destroyed){e=!0;continue}if(!this.maxConcurrency||t.useCount()<this.maxConcurrency)return t}if(e){for(let t of this.sessions)if(t.deref().destroyed)this.remove(t)}}offerLast(e){this.sessions.push(e)}remove(e){let t=this.sessions.indexOf(e);if(t>-1)this.sessions.splice(t,1)}[Symbol.iterator](){return this.sessions[Symbol.iterator]()}setMaxConcurrency(e){this.maxConcurrency=e}destroy(e){this.remove(e),e.destroy()}}class Z{config;connectOptions;connectionPools=new Map;constructor(e){if(this.config=e,this.config.maxConcurrency&&this.config.maxConcurrency<=0)throw RangeError("maxConcurrency must be greater than zero.")}lease(e,t){let o=this.getUrlString(e),n=this.getPool(o);if(!this.config.disableConcurrency&&!t.isEventStream){let u=n.poll();if(u)return u.retain(),u}let s=new M(this.connect(o)),i=s.deref();if(this.config.maxConcurrency)i.settings({maxConcurrentStreams:this.config.maxConcurrency},(u)=>{if(u)throw Error("Fail to set maxConcurrentStreams to "+this.config.maxConcurrency+"when creating new session for "+e.destination.toString())});let c=()=>{this.removeFromPoolAndClose(o,s)},a=()=>{this.removeFromPoolAndCheckedDestroy(o,s)};if(i.on("goaway",c),i.on("error",a),i.on("frameError",a),i.on("close",a),t.requestTimeout)i.setTimeout(t.requestTimeout,a);return n.offerLast(s),s.retain(),s}release(e,t){t.free()}createIsolatedSession(e,t){let o=this.getUrlString(e),n=new M(this.connect(o)),s=n.deref();s.settings({maxConcurrentStreams:1});let i=()=>{n.destroy()};if(s.on("error",i),s.on("frameError",i),s.on("close",i),t.requestTimeout)s.setTimeout(t.requestTimeout,i);return n.retain(),n}destroy(){for(let[e,t]of this.connectionPools){for(let o of[...t])o.destroy();this.connectionPools.delete(e)}}setMaxConcurrentStreams(e){if(e&&e<=0)throw RangeError("maxConcurrentStreams must be greater than zero.");this.config.maxConcurrency=e;for(let t of this.connectionPools.values())t.setMaxConcurrency(e)}setDisableConcurrentStreams(e){this.config.disableConcurrency=e}setNodeHttp2ConnectOptions(e){this.connectOptions=e}debug(){let e={};for(let[t,o]of this.connectionPools){let n=[];for(let s of o)n.push({id:s.id,active:s.useCount(),maxConcurrent:s.max,totalRequests:s.total});e[t]={sessions:n}}return e}removeFromPoolAndClose(e,t){this.connectionPools.get(e)?.remove(t),t.close()}removeFromPoolAndCheckedDestroy(e,t){this.connectionPools.get(e)?.remove(t),t.destroy()}getPool(e){if(!this.connectionPools.has(e)){let t=new Y;if(this.config.maxConcurrency)t.setMaxConcurrency(this.config.maxConcurrency);this.connectionPools.set(e,t)}return this.connectionPools.get(e)}getUrlString(e){return e.destination.toString()}connect(e){return this.connectOptions===void 0?N.connect(e):N.connect(e,this.connectOptions)}}var{constants:z}=N;class q{config;configProvider;metadata={handlerProtocol:"h2"};connectionManager=new Z({});static create(e){if(typeof e?.handle==="function")return e;return new q(e)}constructor(e){this.configProvider=new Promise((t,o)=>{if(typeof e==="function")e().then((n)=>{t(n||{})}).catch(o);else t(e||{})})}destroy(){this.connectionManager.destroy()}async handle(e,{abortSignal:t,requestTimeout:o,isEventStream:n}={}){if(!this.config){this.config=await this.configProvider;let{disableConcurrentStreams:u,maxConcurrentStreams:l,nodeHttp2ConnectOptions:m}=this.config;if(this.connectionManager.setDisableConcurrentStreams(u??!1),l)this.connectionManager.setMaxConcurrentStreams(l);if(m)this.connectionManager.setNodeHttp2ConnectOptions(m)}let{requestTimeout:s,disableConcurrentStreams:i}=this.config,c=i||n,a=o??s;return new Promise((u,l)=>{let m=!1,T=void 0,C=async(r)=>{await T,u(r)},E=async(r)=>{await T,l(r)};if(t?.aborted){m=!0;let r=I(t);E(r);return}let{hostname:k,method:U,port:p,protocol:S,query:R}=e,x="";if(e.username!=null||e.password!=null){let r=e.username??"",f=e.password??"";x=`${r}:${f}@`}let D=`${S}//${x}${k}${p?`:${p}`:""}`,v={destination:new URL(D)},P={requestTimeout:this.config?.sessionTimeout,isEventStream:n},y=c?this.connectionManager.createIsolatedSession(v,P):this.connectionManager.lease(v,P),_=y.deref(),A=(r)=>{if(c)y.destroy();m=!0,E(r)},g=R?K(R):"",b=e.path;if(g)b+=`?${g}`;if(e.fragment)b+=`#${e.fragment}`;let d=_.request({...e.headers,[z.HTTP2_HEADER_PATH]:b,[z.HTTP2_HEADER_METHOD]:U});if(a)d.setTimeout(a,()=>{d.close();let r=Error(`Stream timed out because of no activity for ${a} ms`);r.name="TimeoutError",A(r)});if(t){let r=()=>{d.close();let f=I(t);A(f)};if(typeof t.addEventListener==="function"){let f=t;f.addEventListener("abort",r,{once:!0}),d.once("close",()=>f.removeEventListener("abort",r))}else t.onabort=r}d.on("frameError",(r,f,ee)=>{A(Error(`Frame type id ${r} in stream id ${ee} has failed with code ${f}.`))}),d.on("error",A),d.on("aborted",()=>{A(Error(`HTTP/2 stream is abnormally aborted in mid-communication with result code ${d.rstCode}.`))}),d.on("response",(r)=>{let f=new Q({statusCode:r[":status"]??-1,headers:J(r),body:d});if(m=!0,C({response:f}),c)_.close()}),d.on("close",()=>{if(c)y.destroy();else this.connectionManager.release(v,y);if(!m)A(Error("Unexpected error: http2 request did not get a response"))}),T=X(d,e,a)})}updateHttpClientConfig(e,t){this.config=void 0,this.configProvider=this.configProvider.then((o)=>({...o,[e]:t}))}httpHandlerConfigs(){return this.config??{}}}he.DEFAULT_REQUEST_TIMEOUT=fe;he.NodeHttp2Handler=q;he.NodeHttpHandler=L});
|
|
5
5
|
export{Go};
|