@truxie/nitro 0.1.1 → 0.1.2

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 (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +6 -4
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import {BaseExecutionContext,getRouteParams,applyJsonBody}from'truxie';import {eventHandler}from'h3';var w=Object.defineProperty;var a=(e,t)=>w(e,"name",{value:t,configurable:true});var l=class extends BaseExecutionContext{static{a(this,"NitroExecutionContext");}constructor(t,o,r){let n=b(t),i=t.context.params??{},d=g(t);super(t,o,r,n,i,d),t.context.auth&&this.setAuth(t.context.auth);}};function g(e){let t=new AbortController,o=e.node?.req,r=e.node?.res;if(o&&r){let n=false;r.on("finish",()=>{n=true;}),o.on("close",()=>{n||t.abort("Client disconnected");});}return t}a(g,"createRequestAbortController");function b(e){try{let t=e.node?.req?.url??"",o=t.indexOf("?");if(o===-1)return {};let r=new URLSearchParams(t.slice(o)),n={};return r.forEach((i,d)=>{n[d]=i;}),n}catch{return {}}}a(b,"getQuerySafe");function y(e,t,o){let r=e.getContainer(),n;return async i=>{n||(n=e.createHandler({middlewares:t.middlewares,guards:t.guards,interceptors:t.interceptors,pipes:t.pipes,filters:t.filters,handler:o}));let d=new l(i,o,r);if(t.parseBody!==false)try{let{readBody:p}=await import('h3'),f=await p(i);f!=null&&d.setBody(f);}catch{}return n(d)}}a(y,"nitroHandler");function C(e,t,o){return y(e,typeof t=="function"?{}:t,typeof t=="function"?t:o)}a(C,"defineHandler");function q(e){let{app:t}=e,o=eventHandler(async r=>{let n=r.method.toUpperCase(),d=(r.path??r.node?.req?.url??"").split("?")[0]??"",p=t.matchRoute(n,d);if(!p){let{createError:m}=await import('h3');throw m({statusCode:404,statusMessage:"Not Found"})}let{route:f,params:c}=p;r.context.params={...r.context.params,...c};let s=new l(r,()=>{},t.getContainer());await D(r,s,f.controllerClass,f.methodName);let u=await t.handleRequest(f,s);if(u.isRedirect){let{sendRedirect:m}=await import('h3');return m(r,u.redirectUrl,u.redirectStatus)}if(u.value instanceof Response)return u.value;let h=s.getData("__statusCode");if(h!==void 0){let{setResponseStatus:m}=await import('h3');m(r,h);}return u.value});return t.hasGateways()&&t.createWebSocketHooks({adaptPeer:E,adaptMessage:N,getUrl:a(r=>r.request?.url??r.context._url??"/","getUrl"),getPeers:a(r=>r.peers,"getPeers")}).then(r=>{o.__websocket__=r;}),o}a(q,"createControllerDispatcher");async function D(e,t,o,r){if(e.method.toUpperCase()==="GET")return;let n=getRouteParams(o,r),i=e.node?.req?.headers?.["content-type"]??"",d=n?.some(c=>c.type==="rawBody")??false,p=n?.some(c=>c.type==="formData")??false,f=n?.some(c=>c.type==="body")??false;try{if(p&&i.includes("multipart/")){let{readMultipartFormData:c}=await import('h3'),s=await c(e);s&&t.setFormData(s.map(u=>({name:u.name??"",filename:u.filename,type:u.type,data:Buffer.from(u.data)})));}else if(d){let{readRawBody:c}=await import('h3'),s=await c(e);s!=null&&(t.setRawBody(s),f&&typeof s=="string"&&applyJsonBody(t,s,i));}else if(!i.includes("multipart/")){let{readBody:c}=await import('h3');try{let s=await c(e);s!=null&&t.setBody(s);}catch(s){t.setBodyParseError(s instanceof Error?s:new Error(String(s)));}}}catch{}}a(D,"parseBody");function E(e){return {get id(){return e.id},get remoteAddress(){return e.remoteAddress},get context(){return e.context},send(t,o){e.send(typeof t=="string"?t:JSON.stringify(t),o);},publish(t,o,r){e.publish(t,typeof o=="string"?o:JSON.stringify(o),r);},subscribe:a(t=>e.subscribe(t),"subscribe"),unsubscribe:a(t=>e.unsubscribe(t),"unsubscribe"),close:a((t,o)=>e.close(t,o),"close"),terminate:a(()=>e.terminate?.()??e.close(),"terminate"),get peers(){return e.peers??new Set},get topics(){return e.topics??new Set}}}a(E,"adaptCrosswsPeer");function N(e){return {get rawData(){return e.rawData??e},text(){return typeof e.text=="function"?e.text():typeof e=="string"?e:String(e)},json(){if(typeof e.json=="function")return e.json();let t=typeof e.text=="function"?e.text():String(e);return JSON.parse(t)}}}a(N,"adaptCrosswsMessage");export{l as NitroExecutionContext,q as createControllerDispatcher,C as defineHandler,y as nitro,y as nitroHandler};
1
+ import {BaseExecutionContext,getRouteParams,applyJsonBody}from'truxie';import {eventHandler}from'h3';var w=Object.defineProperty;var n=(e,t)=>w(e,"name",{value:t,configurable:true});var l=class extends BaseExecutionContext{static{n(this,"NitroExecutionContext");}constructor(t,o,r){let a=b(t),i=t.context.params??{},d=g(t);super(t,o,r,a,i,d),t.context.auth&&this.setAuth(t.context.auth);}};function g(e){let t=new AbortController,o=e.node?.res;if(o){let r=false;o.on("finish",()=>{r=true;}),o.on("close",()=>{r||t.abort("Client disconnected");});}return t}n(g,"createRequestAbortController");function b(e){try{let t=e.node?.req?.url??"",o=t.indexOf("?");if(o===-1)return {};let r=new URLSearchParams(t.slice(o)),a={};return r.forEach((i,d)=>{a[d]=i;}),a}catch{return {}}}n(b,"getQuerySafe");function y(e,t,o){let r=e.getContainer(),a;return async i=>{a||(a=e.createHandler({middlewares:t.middlewares,guards:t.guards,interceptors:t.interceptors,pipes:t.pipes,filters:t.filters,handler:o}));let d=new l(i,o,r);if(t.parseBody!==false)try{let{readBody:p}=await import('h3'),f=await p(i);f!=null&&d.setBody(f);}catch{}return a(d)}}n(y,"nitroHandler");function C(e,t,o){return y(e,typeof t=="function"?{}:t,typeof t=="function"?t:o)}n(C,"defineHandler");function D(e){let{app:t}=e,o=eventHandler(async r=>{let a=r.method.toUpperCase(),d=(r.path??r.node?.req?.url??"").split("?")[0]??"",p=t.matchRoute(a,d);if(!p){let{createError:m}=await import('h3');throw m({statusCode:404,statusMessage:"Not Found"})}let{route:f,params:c}=p;r.context.params={...r.context.params,...c};let s=new l(r,()=>{},t.getContainer());await E(r,s,f.controllerClass,f.methodName);let u=await t.handleRequest(f,s);if(u.isRedirect){let{sendRedirect:m}=await import('h3');return m(r,u.redirectUrl,u.redirectStatus)}if(u.value instanceof Response)return u.value;let h=s.getData("__statusCode");if(h!==void 0){let{setResponseStatus:m}=await import('h3');m(r,h);}return u.value});return t.hasGateways()&&t.createWebSocketHooks({adaptPeer:q,adaptMessage:N,getUrl:n(r=>r.request?.url??r.context._url??"/","getUrl"),getPeers:n(r=>r.peers,"getPeers")}).then(r=>{o.__websocket__=r;}),o}n(D,"createControllerDispatcher");async function E(e,t,o,r){if(e.method.toUpperCase()==="GET")return;let a=getRouteParams(o,r),i=e.node?.req?.headers?.["content-type"]??"",d=a?.some(c=>c.type==="rawBody")??false,p=a?.some(c=>c.type==="formData")??false,f=a?.some(c=>c.type==="body")??false;try{if(p&&i.includes("multipart/")){let{readMultipartFormData:c}=await import('h3'),s=await c(e);s&&t.setFormData(s.map(u=>({name:u.name??"",filename:u.filename,type:u.type,data:Buffer.from(u.data)})));}else if(d){let{readRawBody:c}=await import('h3'),s=await c(e);s!=null&&(t.setRawBody(s),f&&typeof s=="string"&&applyJsonBody(t,s,i));}else if(!i.includes("multipart/")){let{readBody:c}=await import('h3');try{let s=await c(e);s!=null&&t.setBody(s);}catch(s){t.setBodyParseError(s instanceof Error?s:new Error(String(s)));}}}catch{}}n(E,"parseBody");function q(e){return {get id(){return e.id},get remoteAddress(){return e.remoteAddress},get context(){return e.context},send(t,o){e.send(typeof t=="string"?t:JSON.stringify(t),o);},publish(t,o,r){e.publish(t,typeof o=="string"?o:JSON.stringify(o),r);},subscribe:n(t=>e.subscribe(t),"subscribe"),unsubscribe:n(t=>e.unsubscribe(t),"unsubscribe"),close:n((t,o)=>e.close(t,o),"close"),terminate:n(()=>e.terminate?.()??e.close(),"terminate"),get peers(){return e.peers??new Set},get topics(){return e.topics??new Set}}}n(q,"adaptCrosswsPeer");function N(e){return {get rawData(){return e.rawData??e},text(){return typeof e.text=="function"?e.text():typeof e=="string"?e:String(e)},json(){if(typeof e.json=="function")return e.json();let t=typeof e.text=="function"?e.text():String(e);return JSON.parse(t)}}}n(N,"adaptCrosswsMessage");export{l as NitroExecutionContext,D as createControllerDispatcher,C as defineHandler,y as nitro,y as nitroHandler};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@truxie/nitro",
3
- "version": "0.1.1",
4
- "description": "Nitro adapter for truxie \u2014 controller dispatcher and handler utilities",
3
+ "version": "0.1.2",
4
+ "description": "Nitro adapter for truxie — controller dispatcher and handler utilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -23,7 +23,8 @@
23
23
  "dev": "tsup --watch",
24
24
  "typecheck": "tsc --noEmit",
25
25
  "clean": "rm -rf dist",
26
- "prepublishOnly": "npm run build"
26
+ "prepublishOnly": "npm run build",
27
+ "test": "vitest run"
27
28
  },
28
29
  "peerDependencies": {
29
30
  "truxie": "^0.1.1",
@@ -34,7 +35,8 @@
34
35
  "@types/node": "^22.10.5",
35
36
  "h3": "^1.13.0",
36
37
  "tsup": "^8.0.0",
37
- "typescript": "^5.0.0"
38
+ "typescript": "^5.0.0",
39
+ "vitest": "^3.2.7"
38
40
  },
39
41
  "license": "MIT",
40
42
  "engines": {