gemi 0.65.0 → 0.67.0

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.
Files changed (51) hide show
  1. package/dist/ai/Agent.d.ts +55 -1
  2. package/dist/ai/Agent.d.ts.map +1 -1
  3. package/dist/ai/AgentProvider.d.ts +8 -44
  4. package/dist/ai/AgentProvider.d.ts.map +1 -1
  5. package/dist/ai/ImageModel.d.ts +127 -0
  6. package/dist/ai/ImageModel.d.ts.map +1 -0
  7. package/dist/ai/ImageProvider.d.ts +94 -0
  8. package/dist/ai/ImageProvider.d.ts.map +1 -0
  9. package/dist/ai/index.d.ts +5 -0
  10. package/dist/ai/index.d.ts.map +1 -1
  11. package/dist/ai/index.js +12 -12
  12. package/dist/ai/index.js.map +12 -8
  13. package/dist/ai/providers/call.d.ts +12 -0
  14. package/dist/ai/providers/call.d.ts.map +1 -1
  15. package/dist/ai/providers/endpoints.d.ts +153 -0
  16. package/dist/ai/providers/endpoints.d.ts.map +1 -0
  17. package/dist/ai/providers/fakeProvider.d.ts +54 -0
  18. package/dist/ai/providers/fakeProvider.d.ts.map +1 -1
  19. package/dist/ai/providers/http.d.ts +28 -0
  20. package/dist/ai/providers/http.d.ts.map +1 -1
  21. package/dist/ai/providers/images.d.ts +126 -0
  22. package/dist/ai/providers/images.d.ts.map +1 -0
  23. package/dist/ai/store/Attachments.d.ts +52 -0
  24. package/dist/ai/store/Attachments.d.ts.map +1 -1
  25. package/dist/ai/types.d.ts +26 -0
  26. package/dist/ai/types.d.ts.map +1 -1
  27. package/dist/{chunk-se5ekvgb.js → chunk-43asnfa8.js} +1 -1
  28. package/dist/{chunk-nxg51m0q.js → chunk-j3p8c0xp.js} +1 -1
  29. package/dist/{chunk-fk127cwf.js → chunk-ka2qqsys.js} +2 -2
  30. package/dist/{chunk-fk127cwf.js.map → chunk-ka2qqsys.js.map} +1 -1
  31. package/dist/{chunk-x917yccy.js → chunk-rnztqasa.js} +1 -1
  32. package/dist/{chunk-j3b3qerv.js → chunk-sksks0tz.js} +1 -1
  33. package/dist/chunk-z7vmrf00.js +5 -0
  34. package/dist/{chunk-a85fn4zf.js.map → chunk-z7vmrf00.js.map} +4 -4
  35. package/dist/client/ProgressManager.d.ts +1 -1
  36. package/dist/facades/index.js +1 -1
  37. package/dist/http/HttpRequest.d.ts +18 -3
  38. package/dist/http/HttpRequest.d.ts.map +1 -1
  39. package/dist/http/index.js +1 -1
  40. package/dist/i18n/index.js +1 -1
  41. package/dist/kernel/index.js +1 -1
  42. package/dist/server/index.js +1 -1
  43. package/dist/services/file-storage/drivers/FileSystemDriver.d.ts +23 -1
  44. package/dist/services/file-storage/drivers/FileSystemDriver.d.ts.map +1 -1
  45. package/dist/services/index.js +1 -1
  46. package/package.json +1 -1
  47. package/dist/chunk-a85fn4zf.js +0 -5
  48. /package/dist/{chunk-se5ekvgb.js.map → chunk-43asnfa8.js.map} +0 -0
  49. /package/dist/{chunk-nxg51m0q.js.map → chunk-j3p8c0xp.js.map} +0 -0
  50. /package/dist/{chunk-x917yccy.js.map → chunk-rnztqasa.js.map} +0 -0
  51. /package/dist/{chunk-j3b3qerv.js.map → chunk-sksks0tz.js.map} +0 -0
@@ -1,4 +1,4 @@
1
1
  // @bun
2
- import{aa as R}from"../chunk-q1nq7n6y.js";import"../chunk-9a8qz3s7.js";import{Wa as L}from"../chunk-adj6dnvj.js";import{hc as E,ic as V}from"../chunk-p0m3qgs5.js";import"../chunk-z4k18gnp.js";import{Cc as j}from"../chunk-se5ekvgb.js";import"../chunk-7438nrkm.js";import"../chunk-r77f1482.js";import"../chunk-a85fn4zf.js";import"../chunk-g2ywq30n.js";import"../chunk-87c0cy5v.js";import"../chunk-ftaxfq7p.js";import"../chunk-7xc64j6p.js";import"../chunk-70y8wajy.js";import{ag as X}from"../chunk-tn71d46d.js";import"../chunk-pcxxnnad.js";import"../chunk-p5m0da00.js";import"../chunk-5g1j29p2.js";import"../chunk-2dvjj3ad.js";import"../chunk-9ch1q7nd.js";import"../chunk-r6v21jn6.js";import{createElement as J,Fragment as M,isValidElement as U}from"react";function $(q,B){let G=Object.values(B).some((z)=>typeof z==="function"&&U(z(""))),Q=/{{([^{}]+?)(?::([^{}\[\]]+?))?(?:\[(.*?)\])?}}/g;if(!G)return q.replace(Q,(W,O,_,Z)=>{let C=O.includes(":")?O.split(":")[0]:O,H=B[C];if(H===void 0)return W;if(typeof H==="function"){let K=H(Z!==void 0?Z:"");if(U(K))throw Error("JSX returned in string context");return String(K)}if(_)switch(_.toLowerCase()){case"number":return Number(H).toString();case"string":return String(H);case"boolean":return Boolean(H).toString();default:return String(H)}return String(H)});else{let z=[],W=0,O=null;while((O=Q.exec(q))!==null){let[_,Z,C,H]=O,F=O.index,K=Z.includes(":")?Z.split(":")[0]:Z;if(F>W)z.push(q.substring(W,F));let Y=B[K];if(Y===void 0)z.push(_);else if(typeof Y==="function"){let A=Y(H!==void 0?H:"");z.push(A)}else if(C)switch(C.toLowerCase()){case"number":z.push(Number(Y).toString());break;case"string":z.push(String(Y));break;case"boolean":z.push(Boolean(Y).toString());break;default:z.push(String(Y))}else z.push(String(Y));W=F+_.length}if(W<q.length)z.push(q.substring(W));return J(M,{},...z)}}class P{name;dictionary;constructor(q,B){this.name=q;this.dictionary=B}reference(q){if(typeof window<"u")throw Error("Cannot use reference in the browser");if(!this.dictionary?.[q])throw Error(`Translation not found for ${String(q)}`);return this.dictionary[q]}render(q,...B){let{locale:G=j.locale(),params:Q}={params:{},...B[0]};if(typeof window<"u")throw Error("Cannot use render in the browser");if(!this.dictionary?.[q]?.[G])throw Error(`Translation not found for ${String(q)} in ${String(G)}`);return $(this.dictionary[q][G],Q??{})}static create(q,B){return new P(q,B)}static text(q,...B){let{locale:G=j.locale(),params:Q}={params:{},...B?.[0]};if(!q?.[G])throw Error(`Translation not found for ${String(G)}`);return $(q[G],Q??{})}}async function N(q,B,...G){let{locale:Q=j.locale(),params:z}={params:{},...G[0]},O=(await q.load(String(Q)))[B];if(typeof O!=="string")throw Error(`Translation not found for "${B}" in "${String(Q)}" (dictionary ${q.id})`);return $(O,z??{})}export{V as translationConfigDefaults,N as translate,E as defineTranslationConfig,R as defineDictionary,X as Translator,L as TranslationServiceProvider,P as Dictionary};
2
+ import{aa as R}from"../chunk-q1nq7n6y.js";import"../chunk-9a8qz3s7.js";import{Wa as L}from"../chunk-adj6dnvj.js";import{hc as E,ic as V}from"../chunk-p0m3qgs5.js";import"../chunk-z4k18gnp.js";import{Cc as j}from"../chunk-43asnfa8.js";import"../chunk-7438nrkm.js";import"../chunk-r77f1482.js";import"../chunk-z7vmrf00.js";import"../chunk-g2ywq30n.js";import"../chunk-87c0cy5v.js";import"../chunk-ftaxfq7p.js";import"../chunk-7xc64j6p.js";import"../chunk-70y8wajy.js";import{ag as X}from"../chunk-tn71d46d.js";import"../chunk-pcxxnnad.js";import"../chunk-p5m0da00.js";import"../chunk-5g1j29p2.js";import"../chunk-2dvjj3ad.js";import"../chunk-9ch1q7nd.js";import"../chunk-r6v21jn6.js";import{createElement as J,Fragment as M,isValidElement as U}from"react";function $(q,B){let G=Object.values(B).some((z)=>typeof z==="function"&&U(z(""))),Q=/{{([^{}]+?)(?::([^{}\[\]]+?))?(?:\[(.*?)\])?}}/g;if(!G)return q.replace(Q,(W,O,_,Z)=>{let C=O.includes(":")?O.split(":")[0]:O,H=B[C];if(H===void 0)return W;if(typeof H==="function"){let K=H(Z!==void 0?Z:"");if(U(K))throw Error("JSX returned in string context");return String(K)}if(_)switch(_.toLowerCase()){case"number":return Number(H).toString();case"string":return String(H);case"boolean":return Boolean(H).toString();default:return String(H)}return String(H)});else{let z=[],W=0,O=null;while((O=Q.exec(q))!==null){let[_,Z,C,H]=O,F=O.index,K=Z.includes(":")?Z.split(":")[0]:Z;if(F>W)z.push(q.substring(W,F));let Y=B[K];if(Y===void 0)z.push(_);else if(typeof Y==="function"){let A=Y(H!==void 0?H:"");z.push(A)}else if(C)switch(C.toLowerCase()){case"number":z.push(Number(Y).toString());break;case"string":z.push(String(Y));break;case"boolean":z.push(Boolean(Y).toString());break;default:z.push(String(Y))}else z.push(String(Y));W=F+_.length}if(W<q.length)z.push(q.substring(W));return J(M,{},...z)}}class P{name;dictionary;constructor(q,B){this.name=q;this.dictionary=B}reference(q){if(typeof window<"u")throw Error("Cannot use reference in the browser");if(!this.dictionary?.[q])throw Error(`Translation not found for ${String(q)}`);return this.dictionary[q]}render(q,...B){let{locale:G=j.locale(),params:Q}={params:{},...B[0]};if(typeof window<"u")throw Error("Cannot use render in the browser");if(!this.dictionary?.[q]?.[G])throw Error(`Translation not found for ${String(q)} in ${String(G)}`);return $(this.dictionary[q][G],Q??{})}static create(q,B){return new P(q,B)}static text(q,...B){let{locale:G=j.locale(),params:Q}={params:{},...B?.[0]};if(!q?.[G])throw Error(`Translation not found for ${String(G)}`);return $(q[G],Q??{})}}async function N(q,B,...G){let{locale:Q=j.locale(),params:z}={params:{},...G[0]},O=(await q.load(String(Q)))[B];if(typeof O!=="string")throw Error(`Translation not found for "${B}" in "${String(Q)}" (dictionary ${q.id})`);return $(O,z??{})}export{V as translationConfigDefaults,N as translate,E as defineTranslationConfig,R as defineDictionary,X as Translator,L as TranslationServiceProvider,P as Dictionary};
3
3
 
4
4
  //# debugId=05D26B4E06225F6C64756E2164756E21
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{ya as D}from"../chunk-3pwn2r6s.js";import{Va as i}from"../chunk-sqc6fkqt.js";import{Wa as y}from"../chunk-adj6dnvj.js";import{$a as e,Bb as d,Eb as p,Hb as c,Za as U,_a as m,ab as k,bb as A,hb as w,ib as g,kb as P,lb as S,mb as h,nb as R,qb as u,rb as l,ub as v}from"../chunk-nxg51m0q.js";import"../chunk-hq496pa4.js";import"../chunk-fmcq21hg.js";import{cc as r}from"../chunk-7wgk7q33.js";import"../chunk-p0m3qgs5.js";import"../chunk-z4k18gnp.js";import{cd as x,id as B,jd as I,md as L,nd as E,od as s,sd as C,td as K,ud as t,vd as o,yc as Yj,zc as a}from"../chunk-se5ekvgb.js";import{Gd as n}from"../chunk-7438nrkm.js";import{Xd as b}from"../chunk-r77f1482.js";import{Qe as _,Te as V}from"../chunk-a85fn4zf.js";import{hf as F}from"../chunk-g2ywq30n.js";import"../chunk-87c0cy5v.js";import"../chunk-ftaxfq7p.js";import"../chunk-7xc64j6p.js";import"../chunk-70y8wajy.js";import"../chunk-2bb3rdqq.js";import"../chunk-tn71d46d.js";import{cg as H,dg as f}from"../chunk-pcxxnnad.js";import{eg as T}from"../chunk-p5m0da00.js";import"../chunk-5g1j29p2.js";import"../chunk-731etrh2.js";import"../chunk-2dvjj3ad.js";import{rg as q}from"../chunk-9ch1q7nd.js";import"../chunk-r6v21jn6.js";function Jj(j){let W=j.headers.get("Cache-Control")?.toLowerCase()??"";return/(^|[\s,])(public|s-maxage)\b/.test(W)}var Nj=new Set,Wj={refusal:null,apply:(j)=>j,carried:null};async function M(j){let W=f(x);if(W.config.global.length===0)return Wj;let{pathname:X}=new URL(j.url),N=q(X),z=new V(j,{},N?"api":"view","");return await F.run(z,async()=>{let Y=F.getStore(),{headers:Z,cookies:zj}=Y,$=(J)=>{if(!Jj(J))return K(J,Z,zj);let G=new Headers(Z);return G.delete("Set-Cookie"),K(J,G,Nj)};try{return await W.runGlobalMiddleware(),{refusal:null,apply:$,carried:{user:Y.user}}}catch(J){let G=!N&&X.endsWith(".json");if(J?.kind===_){let O=N?C(J.payload.api):G?E(J.payload.viewData??J.payload.api):L(J.payload.view);return{refusal:$(O),apply:$,carried:null}}if(b(J)){console.error(J);let O=N||G?B():L(I());return{refusal:$(O),apply:$,carried:null}}throw J}finally{Y.destroy()}})}var Q=[R,l,D,w,c,k,g,u,S,m,P,p,v,h,y,d,A];class jj{config={};providers=[];services=[];serviceInstances=[];serviceTokens=new Set;servicesBooted=!1;models=[];app=new H;boot(){if(this.models.length>0)i(...this.models);else Xj();this.app.config.merge(this.config),H.setInstance(this.app),this.app.registerMany([...Q,...this.providers]),this.registerServices()}registerServices(){let j=this.serviceTokens;this.serviceInstances=[],this.serviceTokens=new Set,this.servicesBooted=!1;let W=new Map;for(let X of this.services){let N=typeof X==="function"?new X:X,z=N.constructor;if(!z.token)throw Error(`Service [${z.name}] is listed in \`services\` but does not declare a \`static token\`.`);let Y=W.get(z.token);if(Y)throw Error(`Services [${Y}] and [${z.name}] both declare the token "${z.token}". Tokens are the container's keys, so they must be unique.`);W.set(z.token,z.name);let Z=z;if(!j.has(z.token)&&this.app.bound(Z))throw Error(`Service [${z.name}] declares the token "${z.token}", which is already bound in the container by the framework or a provider. Binding it would replace that service everywhere, so pick a token nothing else owns.`);this.app.instance(Z,N),this.serviceInstances.push(N),this.serviceTokens.add(z.token)}}async waitForBoot(){await this.app.boot(),await this.bootServices(),e(this.app)}async bootServices(){if(this.servicesBooted)return;for(let j of this.serviceInstances)await j.boot();this.servicesBooted=!0}shutdown(j){return this.run(()=>this.app.shutdown(j))}run(j){return T.run(this.app,j)}resolve(j){return this.app.make(j)}apiRoutes(){return this.app.make(t)}viewRoutes(){return this.app.make(s)}domains(){return this.app.make(o)}broadcast(){return this.app.make(a)}queue(){return this.app.make(r)}globalMiddleware(j){return M(j)}destroy(){if(this.app.resolved(U))this.app.make(U).stop();if(this.app.flush(),H.getInstance()===this.app)H.setInstance(void 0);T.disable()}}function Xj(){if(Bun.env.NODE_ENV==="production")return;let j=n();if(j.length===0)return;console.warn(`[gemi] ${j.length} model${j.length===1?" is":"s are"} registered, but Kernel.models is empty.
2
+ import{ya as D}from"../chunk-3pwn2r6s.js";import{Va as i}from"../chunk-sqc6fkqt.js";import{Wa as y}from"../chunk-adj6dnvj.js";import{$a as e,Bb as d,Eb as p,Hb as c,Za as U,_a as m,ab as k,bb as A,hb as w,ib as g,kb as P,lb as S,mb as h,nb as R,qb as u,rb as l,ub as v}from"../chunk-j3p8c0xp.js";import"../chunk-hq496pa4.js";import"../chunk-fmcq21hg.js";import{cc as r}from"../chunk-7wgk7q33.js";import"../chunk-p0m3qgs5.js";import"../chunk-z4k18gnp.js";import{cd as x,id as B,jd as I,md as L,nd as E,od as s,sd as C,td as K,ud as t,vd as o,yc as Yj,zc as a}from"../chunk-43asnfa8.js";import{Gd as n}from"../chunk-7438nrkm.js";import{Xd as b}from"../chunk-r77f1482.js";import{Qe as _,Te as V}from"../chunk-z7vmrf00.js";import{hf as F}from"../chunk-g2ywq30n.js";import"../chunk-87c0cy5v.js";import"../chunk-ftaxfq7p.js";import"../chunk-7xc64j6p.js";import"../chunk-70y8wajy.js";import"../chunk-2bb3rdqq.js";import"../chunk-tn71d46d.js";import{cg as H,dg as f}from"../chunk-pcxxnnad.js";import{eg as T}from"../chunk-p5m0da00.js";import"../chunk-5g1j29p2.js";import"../chunk-731etrh2.js";import"../chunk-2dvjj3ad.js";import{rg as q}from"../chunk-9ch1q7nd.js";import"../chunk-r6v21jn6.js";function Jj(j){let W=j.headers.get("Cache-Control")?.toLowerCase()??"";return/(^|[\s,])(public|s-maxage)\b/.test(W)}var Nj=new Set,Wj={refusal:null,apply:(j)=>j,carried:null};async function M(j){let W=f(x);if(W.config.global.length===0)return Wj;let{pathname:X}=new URL(j.url),N=q(X),z=new V(j,{},N?"api":"view","");return await F.run(z,async()=>{let Y=F.getStore(),{headers:Z,cookies:zj}=Y,$=(J)=>{if(!Jj(J))return K(J,Z,zj);let G=new Headers(Z);return G.delete("Set-Cookie"),K(J,G,Nj)};try{return await W.runGlobalMiddleware(),{refusal:null,apply:$,carried:{user:Y.user}}}catch(J){let G=!N&&X.endsWith(".json");if(J?.kind===_){let O=N?C(J.payload.api):G?E(J.payload.viewData??J.payload.api):L(J.payload.view);return{refusal:$(O),apply:$,carried:null}}if(b(J)){console.error(J);let O=N||G?B():L(I());return{refusal:$(O),apply:$,carried:null}}throw J}finally{Y.destroy()}})}var Q=[R,l,D,w,c,k,g,u,S,m,P,p,v,h,y,d,A];class jj{config={};providers=[];services=[];serviceInstances=[];serviceTokens=new Set;servicesBooted=!1;models=[];app=new H;boot(){if(this.models.length>0)i(...this.models);else Xj();this.app.config.merge(this.config),H.setInstance(this.app),this.app.registerMany([...Q,...this.providers]),this.registerServices()}registerServices(){let j=this.serviceTokens;this.serviceInstances=[],this.serviceTokens=new Set,this.servicesBooted=!1;let W=new Map;for(let X of this.services){let N=typeof X==="function"?new X:X,z=N.constructor;if(!z.token)throw Error(`Service [${z.name}] is listed in \`services\` but does not declare a \`static token\`.`);let Y=W.get(z.token);if(Y)throw Error(`Services [${Y}] and [${z.name}] both declare the token "${z.token}". Tokens are the container's keys, so they must be unique.`);W.set(z.token,z.name);let Z=z;if(!j.has(z.token)&&this.app.bound(Z))throw Error(`Service [${z.name}] declares the token "${z.token}", which is already bound in the container by the framework or a provider. Binding it would replace that service everywhere, so pick a token nothing else owns.`);this.app.instance(Z,N),this.serviceInstances.push(N),this.serviceTokens.add(z.token)}}async waitForBoot(){await this.app.boot(),await this.bootServices(),e(this.app)}async bootServices(){if(this.servicesBooted)return;for(let j of this.serviceInstances)await j.boot();this.servicesBooted=!0}shutdown(j){return this.run(()=>this.app.shutdown(j))}run(j){return T.run(this.app,j)}resolve(j){return this.app.make(j)}apiRoutes(){return this.app.make(t)}viewRoutes(){return this.app.make(s)}domains(){return this.app.make(o)}broadcast(){return this.app.make(a)}queue(){return this.app.make(r)}globalMiddleware(j){return M(j)}destroy(){if(this.app.resolved(U))this.app.make(U).stop();if(this.app.flush(),H.getInstance()===this.app)H.setInstance(void 0);T.disable()}}function Xj(){if(Bun.env.NODE_ENV==="production")return;let j=n();if(j.length===0)return;console.warn(`[gemi] ${j.length} model${j.length===1?" is":"s are"} registered, but Kernel.models is empty.
3
3
  Nested relation reads resolve a model by name, so a policy on a subclass that does not own its
4
4
  `+" name is skipped inside every include \u2014 scoped at the root, "+`unscoped in an include, with nothing
5
5
  to notice it. Declaring the modules registers each class under its own name and audits the set:
@@ -1,4 +1,4 @@
1
1
  // @bun
2
- import{wa as Y}from"../chunk-8z37k28d.js";import{xa as L}from"../chunk-wzqxtrpt.js";import{hg as b,jg as C,kg as Q,lg as V,mg as X}from"../chunk-731etrh2.js";import{qg as K}from"../chunk-2dvjj3ad.js";import"../chunk-9ch1q7nd.js";import{xg as J}from"../chunk-r6v21jn6.js";class Z{app;instrumentation;handleSignals;server;stopping;settings;constructor(z){this.app=new L({kernel:z.kernel}),this.handleSignals=z.handleSignals??!0,this.instrumentation=V(z.instrumentation??((B,$)=>$(B)))}async start(){process.env.ROOT_DIR=K();let z=Bun.env.NODE_ENV==="production";if(z){if(this.handleSignals)X(()=>this.stop());this.settings=C()}if(await this.app.waitForBoot(),z){let{httpProd:B}=await import("../chunk-x917yccy.js");this.server=await B(this.app,this.instrumentation.bind(this))}else{Y();let{httpDev:B}=await import("../chunk-j3b3qerv.js");this.server=await B(this.app,this.instrumentation.bind(this))}return this.server}stop(z={}){return this.stopping??=Q({server:this.server,shutdownProviders:(B)=>this.app.shutdown(B),settings:{...this.settings??C(),...z}}),this.stopping}}export{b as isShuttingDown,Z as Server};
2
+ import{wa as Y}from"../chunk-8z37k28d.js";import{xa as L}from"../chunk-wzqxtrpt.js";import{hg as b,jg as C,kg as Q,lg as V,mg as X}from"../chunk-731etrh2.js";import{qg as K}from"../chunk-2dvjj3ad.js";import"../chunk-9ch1q7nd.js";import{xg as J}from"../chunk-r6v21jn6.js";class Z{app;instrumentation;handleSignals;server;stopping;settings;constructor(z){this.app=new L({kernel:z.kernel}),this.handleSignals=z.handleSignals??!0,this.instrumentation=V(z.instrumentation??((B,$)=>$(B)))}async start(){process.env.ROOT_DIR=K();let z=Bun.env.NODE_ENV==="production";if(z){if(this.handleSignals)X(()=>this.stop());this.settings=C()}if(await this.app.waitForBoot(),z){let{httpProd:B}=await import("../chunk-rnztqasa.js");this.server=await B(this.app,this.instrumentation.bind(this))}else{Y();let{httpDev:B}=await import("../chunk-sksks0tz.js");this.server=await B(this.app,this.instrumentation.bind(this))}return this.server}stop(z={}){return this.stopping??=Q({server:this.server,shutdownProviders:(B)=>this.app.shutdown(B),settings:{...this.settings??C(),...z}}),this.stopping}}export{b as isShuttingDown,Z as Server};
3
3
 
4
4
  //# debugId=58E7CE0DE71CEE0464756E2164756E21
@@ -1,8 +1,30 @@
1
1
  import type { PutFileOptions, PutFileParams, ReadFileParams, ReadResult } from "./types";
2
2
  import { FileStorageDriver } from "./FileStorageDriver";
3
3
  export declare class FileSystemDriver extends FileStorageDriver {
4
- private folderPath;
4
+ private readonly configured?;
5
5
  constructor(folderPath?: string);
6
+ /**
7
+ * Computed per read, not baked into a constructor default.
8
+ *
9
+ * This is the second time this exact bug has been written in this repository,
10
+ * and `LogManager.logsDirPath` carries the first one's post-mortem: a driver
11
+ * is constructed when `app/config/filesystem.ts` is evaluated, and that
12
+ * happens *before* the http layer sets `ROOT_DIR`. So the old default,
13
+ * `` `${process.env.ROOT_DIR}/storage` ``, interpolated `undefined` and froze
14
+ * it — measured, `new FileSystemDriver().folderPath` was `"undefined/storage"`
15
+ * with `ROOT_DIR` unset, and stayed `"undefined/storage"` after the server set
16
+ * it a moment later.
17
+ *
18
+ * It fails quietly, which is what makes it worth a comment rather than a
19
+ * one-line fix: reads and writes both used the same wrong folder, so nothing
20
+ * threw and nothing 404'd. Files simply accumulated in a stray `undefined/`
21
+ * directory beside the project, and the only way to notice was to look.
22
+ *
23
+ * `projectRoot()` is the same rule `httpProd` computes `ROOT_DIR` from, so an
24
+ * explicit folder still wins and an app that configured nothing now gets the
25
+ * directory it always meant.
26
+ */
27
+ private get folderPath();
6
28
  put(params: PutFileParams | Blob, { signal }?: PutFileOptions): Promise<string>;
7
29
  fetch(params: ReadFileParams | string): Promise<Response>;
8
30
  read(input: ReadFileParams | string): Promise<ReadResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"FileSystemDriver.d.ts","sourceRoot":"","sources":["../../../../services/file-storage/drivers/FileSystemDriver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,cAAc,EACd,UAAU,EACX,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAQxD,qBAAa,gBAAiB,SAAQ,iBAAiB;IACzC,OAAO,CAAC,UAAU;gBAAV,UAAU,GAAE,MAA0C;IAIpE,GAAG,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,EAAE,EAAE,MAAM,EAAE,GAAE,cAAmB;IA+BjE,KAAK,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM;IA+BrC,IAAI,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAyCzD,IAAI,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM;IASpC,IAAI;CAKX"}
1
+ {"version":3,"file":"FileSystemDriver.d.ts","sourceRoot":"","sources":["../../../../services/file-storage/drivers/FileSystemDriver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAMxD,qBAAa,gBAAiB,SAAQ,iBAAiB;IACrD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAS;gBAEzB,UAAU,CAAC,EAAE,MAAM;IAK/B;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,OAAO,KAAK,UAAU,GAErB;IAEK,GAAG,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,EAAE,EAAE,MAAM,EAAE,GAAE,cAAmB;IA+BjE,KAAK,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM;IA+BrC,IAAI,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAyCzD,IAAI,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM;IASpC,IAAI;CAKX"}
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{Ya as AW}from"../chunk-zytmxty5.js";import{Ab as vW,Bb as IW,Cb as TW,Db as hW,Eb as qW,Fb as PW,Gb as wW,Hb as yW,Za as A6,_a as GW,ab as $W,bb as XW,cb as m4,db as zW,eb as BW,fb as xW,gb as MW,hb as jW,ib as NW,jb as U,kb as LW,lb as DW,mb as FW,nb as OW,ob as HW,pb as UW,qb as SW,rb as fW,sb as RW,tb as kW,ub as _W,vb as i4,wb as o4,xb as A1,yb as CW,zb as bW}from"../chunk-nxg51m0q.js";import"../chunk-hq496pa4.js";import{Kb as u6,Lb as d6,Mb as p6,Nb as l6,Ob as n6,Pb as i6,Qb as o6,Rb as s6,Sb as a6,Tb as t6,Ub as r6,Vb as e6,Wb as WW,Xb as YW,Yb as JW,Zb as ZW}from"../chunk-fmcq21hg.js";import{$b as g6,_b as V6,ac as c6,bc as E6,cc as m6}from"../chunk-7wgk7q33.js";import{hc as QW,ic as KW}from"../chunk-p0m3qgs5.js";import"../chunk-z4k18gnp.js";import{$c as U6,Fc as K6,Jc as N1,Lc as X6,Nc as z6,Oc as B6,Pc as x6,Qc as M6,Rc as j6,Sc as N6,Tc as L6,Uc as D6,Vc as F6,Zc as O6,_c as H6,ad as S6,bd as f6,cd as R6,dd as k6,ed as _6,fd as C6,hd as b6,od as v6,qc as C0,uc as r0,ud as I6,vc as e0,wc as W6,wd as T6,xc as Y6,zc as J6}from"../chunk-se5ekvgb.js";import"../chunk-7438nrkm.js";import"../chunk-r77f1482.js";import{$e as Y1,Je as y1,Ke as P1,Le as W1,We as V,Xe as v,af as Z6,bf as G6,cf as $6,df as Q6}from"../chunk-a85fn4zf.js";import"../chunk-g2ywq30n.js";import"../chunk-87c0cy5v.js";import"../chunk-ftaxfq7p.js";import"../chunk-7xc64j6p.js";import"../chunk-70y8wajy.js";import{Wf as h6,Xf as q6,Yf as P6,Zf as w6,_f as y6}from"../chunk-2bb3rdqq.js";import"../chunk-tn71d46d.js";import{dg as g}from"../chunk-pcxxnnad.js";import"../chunk-p5m0da00.js";import"../chunk-5g1j29p2.js";import"../chunk-731etrh2.js";import"../chunk-2dvjj3ad.js";import"../chunk-9ch1q7nd.js";import{xg as d4}from"../chunk-r6v21jn6.js";import{Buffer as u4}from"buffer";class p4 extends Y1{client;config;constructor(...W){super();this.config=W}async connect(){let W=await import("../chunk-ex9ns7pf.js");return this.client??=new W.S3Client(...this.config),{sdk:W,client:this.client}}async put(W,{signal:Y}={}){Y?.throwIfAborted();let J,Z,G,$=process.env.BUCKET_NAME;if(W instanceof Blob)J=W,G=`${Bun.randomUUIDv7()}.${W.type.split("/")[1].split(";")[0]}`,Z=W.type;else J=W.body,G=W.name,$=W.bucket??$,Z=W.contentType||(J instanceof Blob||J instanceof File?J.type:void 0);Z=Z||void 0;let Q=J instanceof u4?J:J instanceof Blob||J instanceof File?u4.from(await J.arrayBuffer()):"",{sdk:K,client:z}=await this.connect();return Y?.throwIfAborted(),await z.send(new K.PutObjectCommand({Bucket:$,Key:G,Body:Q,ContentType:Z}),{abortSignal:Y}),G}async list(W){let{sdk:Y,client:J}=await this.connect();return await J.send(new Y.ListObjectsV2Command({Bucket:process.env.BUCKET_NAME,Prefix:W}))}async fetch(W){let Y=process.env.BUCKET_NAME,J;if(typeof W==="string")J=W;else Y=W.bucket??Y,J=W.name;if(!J)throw Error("Object name has to be specified");let{sdk:Z,client:G}=await this.connect(),$=await G.send(new Z.GetObjectCommand({Bucket:Y,Key:J}));return new Response($.Body.transformToWebStream(),{headers:{"Content-Type":$.ContentType,"Content-Length":$.ContentLength.toString(),"Cache-Control":"private, max-age=12000, must-revalidate","Last-Modified":$.LastModified?.toUTCString()||"",ETag:$.ETag||""}})}async read(W){let Y=typeof W==="string"?{name:W}:W,J=Y.bucket??process.env.BUCKET_NAME,{name:Z,range:G=null}=Y;if(!Z)throw Error("Object name has to be specified");let{sdk:$,client:Q}=await this.connect(),K;try{K=await Q.send(new $.GetObjectCommand({Bucket:J,Key:Z,Range:G?P1(G):void 0}))}catch(M){if(M?.name==="InvalidRange"||M?.$metadata?.httpStatusCode===416)throw new V(await this.size({name:Z,bucket:J}));if(M?.name==="NoSuchKey"||M?.$metadata?.httpStatusCode===404)throw new v(Z);throw M}let z=W1(K.ContentRange),X=Boolean(z)&&K.$metadata?.httpStatusCode===206,x=z?.total??K.ContentLength??0;return{body:K.Body.transformToWebStream(),start:z?.start??0,end:z?.end??x-1,total:x,partial:X,type:K.ContentType??"application/octet-stream",etag:K.ETag||void 0,lastModified:K.LastModified,name:Z}}async size(W){let Y=typeof W==="string"?W:W.name,J=(typeof W==="string"?void 0:W.bucket)??process.env.BUCKET_NAME,{sdk:Z,client:G}=await this.connect();try{return(await G.send(new Z.HeadObjectCommand({Bucket:J,Key:Y}))).ContentLength??0}catch($){if($?.name==="NotFound"||$?.$metadata?.httpStatusCode===404)throw new v(Y);throw $}}}import{Buffer as l4}from"buffer";import{Readable as T0}from"stream";function w1(W){return W?.statusCode===404||W?.details?.errorCode==="BlobNotFound"||W?.code==="BlobNotFound"}function h0(W){return W?.statusCode===416||W?.details?.errorCode==="InvalidRange"||W?.code==="InvalidRange"}class n4 extends Y1{config;serviceClientPromise=null;constructor(W={}){super();this.config=W}async serviceClient(){if(this.config.serviceClient)return this.config.serviceClient;return this.serviceClientPromise??=(async()=>{let W;try{W=await import("@azure/storage-blob")}catch{throw Error("AzureBlobDriver requires the '@azure/storage-blob' package. Install it with `bun add @azure/storage-blob`, or pass a pre-built `serviceClient`.")}let Y=this.config.connectionString??process.env.AZURE_STORAGE_CONNECTION_STRING;if(this.config.url)return new W.BlobServiceClient(this.config.url,this.config.credential);if(Y)return W.BlobServiceClient.fromConnectionString(Y);throw Error("AzureBlobDriver needs a connection string (AZURE_STORAGE_CONNECTION_STRING), a `url`, or a `serviceClient`.")})(),this.serviceClientPromise}async blob(W,Y){if(!W)throw Error("Object name has to be specified");let J=Y??this.config.container??process.env.BUCKET_NAME;if(!J)throw Error("AzureBlobDriver needs a container name, from `bucket`, the `container` config, or BUCKET_NAME.");return(await this.serviceClient()).getContainerClient(J).getBlockBlobClient(W)}async put(W,{signal:Y}={}){Y?.throwIfAborted();let J,Z,G,$;if(W instanceof Blob)J=W,G=`${Bun.randomUUIDv7()}.${W.type.split("/")[1].split(";")[0]}`,Z=W.type;else J=W.body,G=W.name,$=W.bucket,Z=W.contentType??(J instanceof Blob||J instanceof File?J.type:void 0);let Q=J instanceof l4?J:l4.from(await J.arrayBuffer()),K=await this.blob(G,$);return Y?.throwIfAborted(),await K.uploadData(Q,{blobHTTPHeaders:Z?{blobContentType:Z}:void 0,abortSignal:Y}),G}async list(W){let Y=this.config.container??process.env.BUCKET_NAME,Z=(await this.serviceClient()).getContainerClient(Y),G=[];for await(let $ of Z.listBlobsFlat({prefix:W}))G.push($.name);return G}async fetch(W){let Y=await this.read(typeof W==="string"?{name:W}:{name:W.name,bucket:W.bucket});return new Response(Y.body,{headers:{"Content-Type":Y.type,"Content-Length":String(Y.total),"Cache-Control":"private, max-age=12000, must-revalidate","Last-Modified":Y.lastModified?.toUTCString()??"",ETag:Y.etag??""}})}async read(W){let Y=typeof W==="string"?{name:W}:W,{name:J,bucket:Z,range:G=null}=Y,$=await this.blob(J,Z),Q,K,z=G?.kind==="suffix"||G?.kind==="offset"&&G.end===null&&G.start===0;if(G&&z){let k=await this.size({name:J,bucket:Z}),e=y1(G,k);if(!e)throw new V(k);Q=e.start,K=e.length}else if(G?.kind==="offset")Q=G.start,K=G.end===null?void 0:G.end-G.start+1;let X;try{X=await $.download(Q,K)}catch(k){if(h0(k))throw new V(await this.size({name:J,bucket:Z}));if(w1(k))throw new v(J);throw k}let x=W1(X.contentRange),M=Boolean(x),R=x?.total??X.contentLength??0;return{body:await q0(X),start:x?.start??0,end:x?.end??R-1,total:R,partial:M,type:X.contentType??"application/octet-stream",etag:X.etag||void 0,lastModified:X.lastModified,name:J}}async size(W){let Y=typeof W==="string"?W:W.name,J=typeof W==="string"?void 0:W.bucket,Z=await this.blob(Y,J);try{return(await Z.getProperties()).contentLength??0}catch(G){if(w1(G))throw new v(Y);throw G}}async delete(W){let Y=typeof W==="string"?W:W.name,J=typeof W==="string"?void 0:W.bucket,Z=await this.blob(Y,J);try{await Z.delete()}catch(G){if(w1(G))throw new v(Y);throw G}}}async function q0(W){if(W.blobBody)return await W.blobBody;if(W.readableStreamBody)return T0.toWeb(W.readableStreamBody);return null}var P0=`
2
+ import{Ya as AW}from"../chunk-zytmxty5.js";import{Ab as vW,Bb as IW,Cb as TW,Db as hW,Eb as qW,Fb as PW,Gb as wW,Hb as yW,Za as A6,_a as GW,ab as $W,bb as XW,cb as m4,db as zW,eb as BW,fb as xW,gb as MW,hb as jW,ib as NW,jb as U,kb as LW,lb as DW,mb as FW,nb as OW,ob as HW,pb as UW,qb as SW,rb as fW,sb as RW,tb as kW,ub as _W,vb as i4,wb as o4,xb as A1,yb as CW,zb as bW}from"../chunk-j3p8c0xp.js";import"../chunk-hq496pa4.js";import{Kb as u6,Lb as d6,Mb as p6,Nb as l6,Ob as n6,Pb as i6,Qb as o6,Rb as s6,Sb as a6,Tb as t6,Ub as r6,Vb as e6,Wb as WW,Xb as YW,Yb as JW,Zb as ZW}from"../chunk-fmcq21hg.js";import{$b as g6,_b as V6,ac as c6,bc as E6,cc as m6}from"../chunk-7wgk7q33.js";import{hc as QW,ic as KW}from"../chunk-p0m3qgs5.js";import"../chunk-z4k18gnp.js";import{$c as U6,Fc as K6,Jc as N1,Lc as X6,Nc as z6,Oc as B6,Pc as x6,Qc as M6,Rc as j6,Sc as N6,Tc as L6,Uc as D6,Vc as F6,Zc as O6,_c as H6,ad as S6,bd as f6,cd as R6,dd as k6,ed as _6,fd as C6,hd as b6,od as v6,qc as C0,uc as r0,ud as I6,vc as e0,wc as W6,wd as T6,xc as Y6,zc as J6}from"../chunk-43asnfa8.js";import"../chunk-7438nrkm.js";import"../chunk-r77f1482.js";import{$e as Y1,Je as y1,Ke as P1,Le as W1,We as V,Xe as v,af as Z6,bf as G6,cf as $6,df as Q6}from"../chunk-z7vmrf00.js";import"../chunk-g2ywq30n.js";import"../chunk-87c0cy5v.js";import"../chunk-ftaxfq7p.js";import"../chunk-7xc64j6p.js";import"../chunk-70y8wajy.js";import{Wf as h6,Xf as q6,Yf as P6,Zf as w6,_f as y6}from"../chunk-2bb3rdqq.js";import"../chunk-tn71d46d.js";import{dg as g}from"../chunk-pcxxnnad.js";import"../chunk-p5m0da00.js";import"../chunk-5g1j29p2.js";import"../chunk-731etrh2.js";import"../chunk-2dvjj3ad.js";import"../chunk-9ch1q7nd.js";import{xg as d4}from"../chunk-r6v21jn6.js";import{Buffer as u4}from"buffer";class p4 extends Y1{client;config;constructor(...W){super();this.config=W}async connect(){let W=await import("../chunk-ex9ns7pf.js");return this.client??=new W.S3Client(...this.config),{sdk:W,client:this.client}}async put(W,{signal:Y}={}){Y?.throwIfAborted();let J,Z,G,$=process.env.BUCKET_NAME;if(W instanceof Blob)J=W,G=`${Bun.randomUUIDv7()}.${W.type.split("/")[1].split(";")[0]}`,Z=W.type;else J=W.body,G=W.name,$=W.bucket??$,Z=W.contentType||(J instanceof Blob||J instanceof File?J.type:void 0);Z=Z||void 0;let Q=J instanceof u4?J:J instanceof Blob||J instanceof File?u4.from(await J.arrayBuffer()):"",{sdk:K,client:z}=await this.connect();return Y?.throwIfAborted(),await z.send(new K.PutObjectCommand({Bucket:$,Key:G,Body:Q,ContentType:Z}),{abortSignal:Y}),G}async list(W){let{sdk:Y,client:J}=await this.connect();return await J.send(new Y.ListObjectsV2Command({Bucket:process.env.BUCKET_NAME,Prefix:W}))}async fetch(W){let Y=process.env.BUCKET_NAME,J;if(typeof W==="string")J=W;else Y=W.bucket??Y,J=W.name;if(!J)throw Error("Object name has to be specified");let{sdk:Z,client:G}=await this.connect(),$=await G.send(new Z.GetObjectCommand({Bucket:Y,Key:J}));return new Response($.Body.transformToWebStream(),{headers:{"Content-Type":$.ContentType,"Content-Length":$.ContentLength.toString(),"Cache-Control":"private, max-age=12000, must-revalidate","Last-Modified":$.LastModified?.toUTCString()||"",ETag:$.ETag||""}})}async read(W){let Y=typeof W==="string"?{name:W}:W,J=Y.bucket??process.env.BUCKET_NAME,{name:Z,range:G=null}=Y;if(!Z)throw Error("Object name has to be specified");let{sdk:$,client:Q}=await this.connect(),K;try{K=await Q.send(new $.GetObjectCommand({Bucket:J,Key:Z,Range:G?P1(G):void 0}))}catch(M){if(M?.name==="InvalidRange"||M?.$metadata?.httpStatusCode===416)throw new V(await this.size({name:Z,bucket:J}));if(M?.name==="NoSuchKey"||M?.$metadata?.httpStatusCode===404)throw new v(Z);throw M}let z=W1(K.ContentRange),X=Boolean(z)&&K.$metadata?.httpStatusCode===206,x=z?.total??K.ContentLength??0;return{body:K.Body.transformToWebStream(),start:z?.start??0,end:z?.end??x-1,total:x,partial:X,type:K.ContentType??"application/octet-stream",etag:K.ETag||void 0,lastModified:K.LastModified,name:Z}}async size(W){let Y=typeof W==="string"?W:W.name,J=(typeof W==="string"?void 0:W.bucket)??process.env.BUCKET_NAME,{sdk:Z,client:G}=await this.connect();try{return(await G.send(new Z.HeadObjectCommand({Bucket:J,Key:Y}))).ContentLength??0}catch($){if($?.name==="NotFound"||$?.$metadata?.httpStatusCode===404)throw new v(Y);throw $}}}import{Buffer as l4}from"buffer";import{Readable as T0}from"stream";function w1(W){return W?.statusCode===404||W?.details?.errorCode==="BlobNotFound"||W?.code==="BlobNotFound"}function h0(W){return W?.statusCode===416||W?.details?.errorCode==="InvalidRange"||W?.code==="InvalidRange"}class n4 extends Y1{config;serviceClientPromise=null;constructor(W={}){super();this.config=W}async serviceClient(){if(this.config.serviceClient)return this.config.serviceClient;return this.serviceClientPromise??=(async()=>{let W;try{W=await import("@azure/storage-blob")}catch{throw Error("AzureBlobDriver requires the '@azure/storage-blob' package. Install it with `bun add @azure/storage-blob`, or pass a pre-built `serviceClient`.")}let Y=this.config.connectionString??process.env.AZURE_STORAGE_CONNECTION_STRING;if(this.config.url)return new W.BlobServiceClient(this.config.url,this.config.credential);if(Y)return W.BlobServiceClient.fromConnectionString(Y);throw Error("AzureBlobDriver needs a connection string (AZURE_STORAGE_CONNECTION_STRING), a `url`, or a `serviceClient`.")})(),this.serviceClientPromise}async blob(W,Y){if(!W)throw Error("Object name has to be specified");let J=Y??this.config.container??process.env.BUCKET_NAME;if(!J)throw Error("AzureBlobDriver needs a container name, from `bucket`, the `container` config, or BUCKET_NAME.");return(await this.serviceClient()).getContainerClient(J).getBlockBlobClient(W)}async put(W,{signal:Y}={}){Y?.throwIfAborted();let J,Z,G,$;if(W instanceof Blob)J=W,G=`${Bun.randomUUIDv7()}.${W.type.split("/")[1].split(";")[0]}`,Z=W.type;else J=W.body,G=W.name,$=W.bucket,Z=W.contentType??(J instanceof Blob||J instanceof File?J.type:void 0);let Q=J instanceof l4?J:l4.from(await J.arrayBuffer()),K=await this.blob(G,$);return Y?.throwIfAborted(),await K.uploadData(Q,{blobHTTPHeaders:Z?{blobContentType:Z}:void 0,abortSignal:Y}),G}async list(W){let Y=this.config.container??process.env.BUCKET_NAME,Z=(await this.serviceClient()).getContainerClient(Y),G=[];for await(let $ of Z.listBlobsFlat({prefix:W}))G.push($.name);return G}async fetch(W){let Y=await this.read(typeof W==="string"?{name:W}:{name:W.name,bucket:W.bucket});return new Response(Y.body,{headers:{"Content-Type":Y.type,"Content-Length":String(Y.total),"Cache-Control":"private, max-age=12000, must-revalidate","Last-Modified":Y.lastModified?.toUTCString()??"",ETag:Y.etag??""}})}async read(W){let Y=typeof W==="string"?{name:W}:W,{name:J,bucket:Z,range:G=null}=Y,$=await this.blob(J,Z),Q,K,z=G?.kind==="suffix"||G?.kind==="offset"&&G.end===null&&G.start===0;if(G&&z){let k=await this.size({name:J,bucket:Z}),e=y1(G,k);if(!e)throw new V(k);Q=e.start,K=e.length}else if(G?.kind==="offset")Q=G.start,K=G.end===null?void 0:G.end-G.start+1;let X;try{X=await $.download(Q,K)}catch(k){if(h0(k))throw new V(await this.size({name:J,bucket:Z}));if(w1(k))throw new v(J);throw k}let x=W1(X.contentRange),M=Boolean(x),R=x?.total??X.contentLength??0;return{body:await q0(X),start:x?.start??0,end:x?.end??R-1,total:R,partial:M,type:X.contentType??"application/octet-stream",etag:X.etag||void 0,lastModified:X.lastModified,name:J}}async size(W){let Y=typeof W==="string"?W:W.name,J=typeof W==="string"?void 0:W.bucket,Z=await this.blob(Y,J);try{return(await Z.getProperties()).contentLength??0}catch(G){if(w1(G))throw new v(Y);throw G}}async delete(W){let Y=typeof W==="string"?W:W.name,J=typeof W==="string"?void 0:W.bucket,Z=await this.blob(Y,J);try{await Z.delete()}catch(G){if(w1(G))throw new v(Y);throw G}}}async function q0(W){if(W.blobBody)return await W.blobBody;if(W.readableStreamBody)return T0.toWeb(W.readableStreamBody);return null}var P0=`
3
3
  local currentKey = KEYS[1]
4
4
  local previousKey = KEYS[2]
5
5
  local limit = tonumber(ARGV[1])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemi",
3
- "version": "0.65.0",
3
+ "version": "0.67.0",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "author": "Enes Tufekci <enes@gemijs.dev>",
@@ -1,5 +0,0 @@
1
- // @bun
2
- import{hf as C}from"./chunk-g2ywq30n.js";import{dg as w}from"./chunk-pcxxnnad.js";import{xg as u}from"./chunk-r6v21jn6.js";class V{static kind="controller";constructor(){}}class b extends V{}function j(H){let K=new Map;if(!H)return K;for(let R of H.split(";")){let P=R.indexOf("=");if(P===-1)continue;let J=R.slice(0,P).trim();if(!J)continue;K.set(J,R.slice(P+1).trim())}return K}function o(H){return j(H.headers.get("cookie"))}function Z(H){if(!/^\d+$/.test(H))return null;let K=Number(H);return Number.isSafeInteger(K)?K:null}function z(H){if(!H)return null;let K=H.trim();if(!/^bytes=/i.test(K))return null;let P=K.slice(6).split(",").map((W)=>W.trim()).filter((W)=>W!=="");if(P.length!==1)return null;let J=P[0],T=J.indexOf("-");if(T===-1)return null;let G=J.slice(0,T),O=J.slice(T+1);if(G===""){let W=Z(O);if(W===null)return null;return{kind:"suffix",suffixLength:W}}let D=Z(G);if(D===null)return null;if(O==="")return{kind:"offset",start:D,end:null};let Q=Z(O);if(Q===null||Q<D)return null;return{kind:"offset",start:D,end:Q}}function E(H,K){if(!Number.isFinite(K)||K<=0)return null;let R,P;if(H.kind==="suffix"){if(H.suffixLength<=0)return null;R=Math.max(0,K-H.suffixLength),P=K-1}else{if(H.start>=K)return null;if(R=H.start,P=H.end===null?K-1:Math.min(H.end,K-1),P<R)return null}return{start:R,end:P,length:P-R+1}}function s(H){if(H.kind==="suffix")return`bytes=-${H.suffixLength}`;return H.end===null?`bytes=${H.start}-`:`bytes=${H.start}-${H.end}`}function t(H){if(!H)return null;let K=/^bytes\s+(\d+)-(\d+)\/(\d+)$/i.exec(H.trim());if(!K)return null;let R=Z(K[1]),P=Z(K[2]),J=Z(K[3]);if(R===null||P===null||J===null||P<R)return null;return{start:R,end:P,total:J}}function r(H,K,R){return`bytes ${H}-${K}/${R}`}function q(H){return`bytes */${H}`}var e="GEMI_REQUEST_BREAKER_ERROR";class X extends Error{kind="GEMI_REQUEST_BREAKER_ERROR";payload={api:{},view:{}}}class U extends X{errors={};constructor(H){super("Validation error");this.name="ValidationError",this.errors=H,this.payload={api:{status:400,data:{error:{kind:"validation_error",messages:H}},headers:{"Content-Type":"application/json"}},view:{status:400}}}}var x=new WeakMap;function PH(H,K){x.set(H,{clientAddress:K})}function I(H){return x.has(H)}function JH(H){return x.get(H)?.clientAddress}var S=new WeakMap;function DH(H,K){S.set(H,K)}function _(H){return S.get(H)??null}class ${data;constructor(H){this.data=H}get(H){return this.data[H]}has(H){return this.data[H]!==void 0}toJSON(){return this.data}}function c(H){let[K,R]=H.match(/\d+|\D+/g)??[];if(!K||!R)return 0;let P=Number.parseInt(K);switch(R){case"B":return P;case"KB":return P*1024;case"MB":return P*1024*1024;case"GB":return P*1024*1024*1024;case"TB":return P*1024*1024*1024*1024;default:return 0}}function f(H){switch(H){case"image":return"image";case"png":return"image/png";case"jpg":return"image/jpeg";case"jpeg":return"image/jpeg";case"ttf":return"font/ttf";case"excel":return"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";case"csv":return"text/csv";case"word":return"application/vnd.openxmlformats-officedocument.wordprocessingml.document";case"pdf":return"application/pdf";case"json":return"application/json";default:return H}}function v(H){let[K,R]=H.split(":");switch(K){case"required":return(P)=>{if(P instanceof Blob)return P.size>0;return P!==null&&P!==void 0&&P?.length>0};case"password":return(P)=>{return/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9]).{8,}$/.test(P)};case"number":return(P)=>{if(typeof P!=="number")return!1;return!Number.isNaN(P)};case"min":return(P)=>{return P?.length>=Number.parseInt(R)};case"max":return(P)=>{return P?.length<=Number.parseInt(R)};case"email":return(P)=>{return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(P)};case"file":return(P)=>{return P instanceof Blob};case"fileType":return(P)=>{if(P instanceof Blob){let J=f(R);return P.type.startsWith(J)}};case"fileSize":return(P)=>{if(P instanceof Blob){let J=c(R);return P.size<=J}};default:return()=>!0}}class g{kind;rawRequest;headers;cookies;search;schema={};routePath;params;domain;constructor(H,K,R,P){if(!H){let D=C.getStore().req;this.params=D.params,this.rawRequest=D.rawRequest,this.kind=D.kind,this.routePath=D.routePath,this.domain=D.domain??null}else this.params=K,this.rawRequest=H,this.routePath=P,this.kind=R??"api",this.domain=_(H);this.headers=this.rawRequest.headers;let J=j(this.rawRequest.headers.get("Cookie")),T=new URL(this.rawRequest.url),G=new Map;for(let[D,Q]of T.searchParams)if(G.has(D)){let W=G.get(D);if(Array.isArray(W))W.push(Q),G.set(D,W);else G.set(D,[W,Q])}else G.set(D,Q);let O=Object.fromEntries(G.entries());this.search=new $(O),this.cookies=J}locale(){return C.getStore().locale}ctx(){return C.getStore()}isModelOriginated(){return I(this.rawRequest)}range(){return z(this.rawRequest.headers.get("Range"))}refine(H){return{}}async parseBody(){let H=new $({});if(this.rawRequest.headers.get("Content-Type")==="application/json"){let K=await this.rawRequest.json();H=new $(K)}if(this.rawRequest.headers.get("Content-Type")==="application/x-www-form-urlencoded"){let K=await this.rawRequest.formData();H=new $(K)}if(this.rawRequest.headers.get("Content-Type")?.startsWith("multipart/form-data")){let K=await this.rawRequest.formData(),R=new Map;for(let[P,J]of K.entries())if(R.has(P)){let T=R.get(P);if(Array.isArray(T))T.push(J),R.set(P,T);else R.set(P,[T,J])}else R.set(P,J);H=new $(Object.fromEntries(R.entries()))}return H}validateInput(H){let K={};for(let[R,P]of Object.entries(this.schema))for(let[J,T]of Object.entries(P)){let G=v(J),O=T,D=!1;if(typeof T==="function")O=T(H.get(R)),D=typeof O>"u";else D=G(H.get(R));if(D)continue;if(!H.get(R)&&!Object.keys(P).includes("required"))continue;if(!K[R])K[R]=[];if(J==="required"){K[R]=[String(O)];continue}K[R].push(String(O))}for(let[R,P]of Object.entries(this.refine(H.toJSON())??{})){if(!K[R])K[R]=[];K[R]=[...K[R]??[],P]}if(Object.keys(K).length>0)throw new U(K);return H}async input(){return this.validateInput(await this.parseBody())}async safeInput(){let H=await this.parseBody();try{return this.validateInput(H),{isValid:!0,errors:{},input:H}}catch(K){if(!(K instanceof U))throw K;return{isValid:!1,errors:K.errors,input:H}}}}class h extends X{error;constructor(H="Not authorized"){super(H);this.name="AuthorizationError",this.error=H,this.payload={api:{status:401,data:{error:this.error}},view:{}}}}class F extends X{static apiStatus=403;error;constructor(H="Insufficient permissions"){super(H);this.name="InsufficientPermissionsError",this.error=H,this.payload={api:{status:F.apiStatus,data:{error:this.error}},view:{status:403}}}}class A extends X{total;constructor(H){super("Range not satisfiable");this.total=H;this.name="RangeNotSatisfiableError",this.payload={api:{status:416,data:{error:{message:"Range not satisfiable"}},headers:{"Content-Range":q(H),"Accept-Ranges":"bytes","Cache-Control":"no-store"}},view:{}}}}class Y extends X{fileName;constructor(H){super("File not found");this.fileName=H;this.name="FileNotFoundError",this.payload={api:{status:404,data:{error:{message:"Not found"}},headers:{"Cache-Control":"no-store"}},view:{}}}}class m extends X{constructor(H={}){super("Authentication error");this.name="AuthenticationError";let K=H.redirectTo??"/auth/sign-in";this.payload={api:{status:401,data:{error:"Authentication error"}},viewData:{status:200,data:{},headers:{"Cache-Control":"private, no-cache, no-store, max-age=0, must-revalidate"},directive:{kind:"Redirect",path:K}},view:{status:302,headers:{"Cache-Control":"private, no-cache, no-store, max-age=0, must-revalidate",Location:K}}}}}class L{static getFacadeAccessor(){throw Error(`Facade [${this.name}] does not implement getFacadeAccessor().`)}static getFacadeRoot(){return w(this.getFacadeAccessor())}}class B{async read(H){let K=typeof H==="string"?{name:H}:H,R=await this.fetch({name:K.name,bucket:K.bucket});if(!R.ok)throw new Y(K.name);let P=R.headers.get("Content-Type")??"application/octet-stream",J=R.headers.get("ETag")??void 0,T=R.headers.get("Last-Modified"),G=T?new Date(T):void 0;if(K.range){let Q=await R.blob();return{body:Q,start:0,end:Q.size-1,total:Q.size,partial:!1,type:P,etag:J,lastModified:G,name:K.name}}let O=Number(R.headers.get("Content-Length")),D=Number.isFinite(O)?O:0;return{body:R.body,start:0,end:D-1,total:D,partial:!1,type:P,etag:J,lastModified:G,name:K.name}}async size(H){let K=typeof H==="string"?H:H.name,R=typeof H==="string"?void 0:H.bucket,P=await this.fetch({name:K,bucket:R});if(!P.ok)throw new Y(K);let J=Number(P.headers.get("Content-Length"));if(Number.isFinite(J))return await P.body?.cancel(),J;return(await P.blob()).size}}import{readdir as d}from"fs/promises";class M extends B{folderPath;constructor(H=`${process.env.ROOT_DIR}/storage`){super();this.folderPath=H}async put(H,{signal:K}={}){K?.throwIfAborted();let R,P;if(H instanceof Blob)R=H,P=`${Bun.randomUUIDv7()}.${H.type.split("/")[1].split(";")[0]}`;else R=H.body,P=H.name;let J=R instanceof Buffer?R:R instanceof Blob||R instanceof File?Buffer.from(await R.arrayBuffer()):"",T=`${this.folderPath}/${P}`;return K?.throwIfAborted(),await Bun.write(T,J),P}async fetch(H){let K=process.env.BUCKET_NAME,R;if(typeof H==="string")R=H;else K=H.bucket??K,R=H.name;if(!R)throw Error("Object name has to be specified");let P=`${this.folderPath}/${R}`,J=Bun.file(P),T=Bun.file(P).stream(),G=new Date(J.lastModified).toUTCString();return new Response(T,{headers:{"Content-Type":J.type,"Content-Length":String(J.size),"Cache-Control":"private, max-age=12000, must-revalidate","Last-Modified":G}})}async read(H){let K=typeof H==="string"?{name:H}:H,{name:R,range:P=null}=K;if(!R)throw Error("Object name has to be specified");let J=Bun.file(`${this.folderPath}/${R}`);if(!await J.exists())throw new Y(R);let T=J.size,G=P?E(P,T):null;if(P&&!G)throw new A(T);let O=G?.start??0,D=G?G.end:T-1;return{body:G?J.slice(O,D+1):J,start:O,end:D,total:T,partial:Boolean(G),type:J.type||"application/octet-stream",lastModified:new Date(J.lastModified),name:R}}async size(H){let K=typeof H==="string"?H:H.name,R=Bun.file(`${this.folderPath}/${K}`);if(!await R.exists())throw new Y(K);return R.size}async list(){return await d(this.folderPath)}}function IH(H){return H}function k(){return{driver:new M}}class N{static token="filesystem";driver;constructor(H={}){this.driver=H.driver??k().driver}}import{Buffer as i}from"buffer";async function y(H){try{return(await import("sharp")).default}catch(K){throw Error(`${H} requires the 'sharp' package. Install it with \`bun add sharp\`.`,{cause:K})}}class p extends L{static getFacadeAccessor(){return N}static async put(H,K={}){return this.getFacadeRoot().driver.put(H,K)}static async metadata(H){let K=i.from(await H.arrayBuffer()),R=await y("Storage.metadata()");try{return await R(K).metadata()}catch{return{}}}static async fetch(H){return this.getFacadeRoot().driver.fetch(H)}static async read(H,K={}){let R=typeof H==="string"?{name:H}:{...H},P="range"in K?K.range??null:R.range!==void 0?R.range:C.getStore()?.rangeRequest??null;return this.getFacadeRoot().driver.read({...R,range:P})}static list(H){return this.getFacadeRoot().driver.list(H)}static delete(){}}
3
- export{V as Ce,b as De,j as Ee,o as Fe,PH as Ge,JH as He,z as Ie,E as Je,s as Ke,t as Le,r as Me,q as Ne,DH as Oe,_ as Pe,e as Qe,X as Re,U as Se,g as Te,h as Ue,F as Ve,A as We,Y as Xe,m as Ye,L as Ze,y as _e,B as $e,M as af,IH as bf,k as cf,N as df,p as ef};
4
-
5
- //# debugId=7B77BADDECDA05E464756E2164756E21