owebjs 1.0.4 → 1.0.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.
@@ -0,0 +1 @@
1
+ import{a as d}from"./chunk-OR3GJT5E.js";import{d as u,e as m}from"./chunk-XR5MHIBF.js";import{a}from"./chunk-2HA4XQFN.js";import p from"node:path";import{dirname as R}from"node:path";import{fileURLToPath as E}from"node:url";var g=R(E(import.meta.url)),_=a(async l=>{let r=[];for(let s of l){let f=p.parse(s.rel),t=s.filePath.replaceAll("\\","/"),i=new URL(p.resolve(t),`file://${g}`).pathname.replaceAll("\\","/"),c=u(f),o=m(c),e=(await import(i)).default;r.push({url:o.url,method:o.method,fn:e,fileInfo:s})}return r},"generateRoutes"),w=a(async(l,r)=>{let s=await d(l),f=await _(s);for(let t of f)r[t.method](t.url,function(i,c){let o=new t.fn(...arguments),h=a(()=>{if(o.handle.constructor.name=="AsyncFunction")o.handle(...arguments).catch(e=>{let n=[...arguments,e];o?.handleError?o.handleError(...n):r._options.OWEB_INTERNAL_ERROR_HANDLER(...n)});else try{o.handle(...arguments)}catch(e){let n=[...arguments,e];o?.handleError?o.handleError(...n):r._options.OWEB_INTERNAL_ERROR_HANDLER(...n)}},"handle");if(t.fileInfo.hooks.length)for(let e=0;e<t.fileInfo.hooks.length;e++){let n=t.fileInfo.hooks[e];new n().handle(i,c,()=>{e+1==t.fileInfo.hooks.length&&h()})}else h()})},"assignRoutes");export{_ as a,w as b};
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { FastifyServerOptions, FastifyListenOptions, FastifyInstance } from 'fastify';
1
+ import { FastifyServerOptions, FastifyRequest, FastifyReply, FastifyListenOptions, FastifyInstance } from 'fastify';
2
2
 
3
3
  interface OwebOptions extends FastifyServerOptions {
4
4
  uWebSocketsEnabled?: boolean;
5
+ OWEB_INTERNAL_ERROR_HANDLER?: Function;
5
6
  }
6
7
  interface LoadRoutesOptions {
7
8
  directory: string;
@@ -11,12 +12,15 @@ interface _FastifyInstance extends FastifyInstance {
11
12
  declare class _FastifyInstance {
12
13
  }
13
14
  declare class Oweb extends _FastifyInstance {
15
+ _options: OwebOptions;
14
16
  constructor(options?: OwebOptions);
17
+ setup(): Promise<unknown>;
15
18
  loadRoutes({ directory }: LoadRoutesOptions): Promise<void>;
19
+ setInternalErrorHandler(errorHandlerCallback: (request: FastifyRequest, reply: FastifyReply, error: Error) => void): void;
16
20
  start(listenOptions?: FastifyListenOptions): Promise<{
17
21
  err: Error;
18
22
  address: string;
19
23
  }>;
20
24
  }
21
25
 
22
- export { LoadRoutesOptions, OwebOptions, Oweb as default };
26
+ export { LoadRoutesOptions, Oweb, OwebOptions, Oweb as default };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as i}from"./chunk-VLHAZXJ6.js";import{b as n}from"./chunk-JSRKSHP6.js";import"./chunk-OR3GJT5E.js";import"./chunk-XR5MHIBF.js";import"./chunk-2WXLF7QU.js";import"./chunk-2D3NDWTU.js";import"./chunk-Z23QA6PX.js";import"./chunk-7JAXN5IF.js";import"./chunk-ARAMBVQ3.js";import{a as r}from"./chunk-2HA4XQFN.js";import u from"fastify";var a=i({}),f=r((e,t)=>(a.on("request",e),a),"serverFactory"),m=class{static{r(this,"_FastifyInstance")}},o=class extends m{static{r(this,"Oweb")}constructor(t={}){super();let s=t??{};s.uWebSocketsEnabled&&(s.serverFactory=f),Object.assign(this,u(s))}loadRoutes({directory:t}){return n(t,this)}start(t={port:3e3,host:"127.0.0.1"}){return new Promise(s=>{this.listen({port:+t.port},(c,p)=>s({err:c,address:p}))})}};export{o as default};
1
+ import{b as a}from"./chunk-FRG47WHC.js";import"./chunk-OR3GJT5E.js";import"./chunk-XR5MHIBF.js";import{a as r}from"./chunk-2HA4XQFN.js";import p from"fastify";var _=class{static{r(this,"_FastifyInstance")}},n=class extends _{static{r(this,"Oweb")}_options={};constructor(t={}){super();let s=t??{};this._options=s,this._options.OWEB_INTERNAL_ERROR_HANDLER=(e,o,i)=>o.status(500).send({error:i.message})}async setup(){return new Promise(async t=>{if(this._options.uWebSocketsEnabled){let s=(await import("./uwebsocket/server.js")).default,e=await s({});this._options.serverFactory=(o,i)=>(e.on("request",o),e),Object.assign(this,p(this._options)),t(!0)}else Object.assign(this,p(this._options)),t(!0)})}loadRoutes({directory:t}){return a(t,this)}setInternalErrorHandler(t){this._options.OWEB_INTERNAL_ERROR_HANDLER=t}start(t={port:3e3,host:"127.0.0.1"}){return new Promise(s=>{this.listen({port:+t.port},(e,o)=>s({err:e,address:o}))})}};export{n as Oweb,n as default};
@@ -1 +1 @@
1
- import{a,b}from"../chunk-JSRKSHP6.js";import"../chunk-OR3GJT5E.js";import"../chunk-XR5MHIBF.js";import"../chunk-2HA4XQFN.js";export{b as assignRoutes,a as generateRoutes};
1
+ import{a,b}from"../chunk-FRG47WHC.js";import"../chunk-OR3GJT5E.js";import"../chunk-XR5MHIBF.js";import"../chunk-2HA4XQFN.js";export{b as assignRoutes,a as generateRoutes};
@@ -1 +1 @@
1
- import{a}from"../chunk-VLHAZXJ6.js";import"../chunk-2WXLF7QU.js";import"../chunk-2D3NDWTU.js";import"../chunk-Z23QA6PX.js";import"../chunk-7JAXN5IF.js";import"../chunk-ARAMBVQ3.js";import"../chunk-2HA4XQFN.js";export{a as default};
1
+ import{a as p}from"../chunk-2WXLF7QU.js";import"../chunk-2D3NDWTU.js";import{a as d}from"../chunk-Z23QA6PX.js";import"../chunk-7JAXN5IF.js";import"../chunk-ARAMBVQ3.js";import{a as u}from"../chunk-2HA4XQFN.js";import{EventEmitter as k}from"node:events";var q="request";async function v({cert_file_name:h,key_file_name:m}){let c;c=(await import("uWebSockets.js")).default;let S="App";h&&m&&(S="SSLApp");let l=u((i,n)=>{n.statusCode=404,n.statusMessage="Not Found",n.end()},"handler"),E={cert_file_name:h,key_file_name:m},o=c[S](E).any("/*",(i,n)=>{i.finished=!1;let e=new p(n),t=new d(i,o);e.res=t,t.req=e,e.socket=t.socket,e.method!=="HEAD"?i.onData((r,f)=>{let y=Buffer.from(r);return f?(e.push(y),e.push(null),i.finished?void 0:l(e,t)):e.push(y)}):i.finished||l(e,t)}),g=class extends k{static{u(this,"uServerClass")}constructor(){super();let n=this.on.bind(this),e=this.once.bind(this);this.once=function(t,s){return e(t,s)},this.on=function(t,s){if(t===q){l=s;return}return n(t,s)}}close(n){if(c.us_listen_socket_close(o._socket),!!n)return n()}start(n,e,t){let s,r=u(function(f){o._socket=f,t&&t(f)},"callbackFunction");return n&&e&&t&&(s=[n,e,r]),!t&&(!e||typeof e=="function")&&(t=e,e=n,s=[e,r]),o.listen(...s)}listen(n,e,t){if(typeof n=="object"){let s=n;return e=s.port,t=s.cb,n=s.host,this.start(n,e,r=>{o._socket=r,t&&t(r)})}else return(!e||typeof e=="function")&&!t?(t=e,e=n,this.start(e,t)):this.start(n,e,t)}get uwsApp(){return o}},a=new g;return a[Symbol("IncomingMessage")]=p,a[Symbol("ServerResponse")]=d,a}u(v,"default");export{v as default};
package/package.json CHANGED
@@ -1,32 +1,32 @@
1
- {
2
- "name": "owebjs",
3
- "version": "1.0.4",
4
- "description": "",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "scripts": {
8
- "start": "node .",
9
- "build": "tsup",
10
- "dev": "tsup && node .",
11
- "test": "tsup && node scripts/copyBinaries && node test/index.js",
12
- "format": "prettier --write . --ignore-path .gitignore"
13
- },
14
- "keywords": [],
15
- "author": "owebjs",
16
- "license": "MIT",
17
- "dependencies": {
18
- "fastify": "^4.23.2",
19
- "jsonwebtoken": "^9.0.2"
20
- },
21
- "devDependencies": {
22
- "@swc/core": "^1.3.85",
23
- "@types/jsonwebtoken": "^9.0.3",
24
- "@types/node": "^20.6.2",
25
- "prettier": "^3.0.3",
26
- "tslib": "^2.6.2",
27
- "tsup": "^7.2.0",
28
- "typescript": "^5.2.2",
29
- "uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.10.0"
30
- },
31
- "type": "module"
32
- }
1
+ {
2
+ "name": "owebjs",
3
+ "version": "1.0.6",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "start": "node .",
9
+ "build": "tsup",
10
+ "dev": "tsup && node .",
11
+ "test": "tsup && node scripts/copyBinaries && node test/index.js",
12
+ "format": "prettier --write . --ignore-path .gitignore"
13
+ },
14
+ "keywords": [],
15
+ "author": "owebjs",
16
+ "license": "MIT",
17
+ "dependencies": {
18
+ "fastify": "^4.23.2",
19
+ "jsonwebtoken": "^9.0.2"
20
+ },
21
+ "devDependencies": {
22
+ "@swc/core": "^1.3.85",
23
+ "@types/jsonwebtoken": "^9.0.3",
24
+ "@types/node": "^20.6.2",
25
+ "prettier": "^3.0.3",
26
+ "tslib": "^2.6.2",
27
+ "tsup": "^7.2.0",
28
+ "typescript": "^5.2.2",
29
+ "uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.10.0"
30
+ },
31
+ "type": "module"
32
+ }
@@ -1 +0,0 @@
1
- import{a as h}from"./chunk-OR3GJT5E.js";import{d as u,e as m}from"./chunk-XR5MHIBF.js";import{a as i}from"./chunk-2HA4XQFN.js";import c from"node:path";import{dirname as p}from"node:path";import{fileURLToPath as d}from"node:url";var g=p(d(import.meta.url)),w=i(async r=>{let n=[];for(let t of r){let s=c.parse(t.rel),e=t.filePath.replaceAll("\\","/"),a=new URL(c.resolve(e),`file://${g}`).pathname.replaceAll("\\","/"),l=u(s),o=m(l),f=await import(a);n.push({url:o.url,method:o.method,fn:f?.default,fileInfo:t})}return n},"generateRoutes"),U=i(async(r,n)=>{let t=await h(r),s=await w(t);for(let e of s)n[e.method](e.url,function(a,l){if(e.fileInfo.hooks.length)for(let o=0;o<e.fileInfo.hooks.length;o++){let f=e.fileInfo.hooks[o];new f().handle(a,l,()=>{o+1==e.fileInfo.hooks.length&&new e.fn(...arguments).handle(...arguments)})}else new e.fn(...arguments).handle(...arguments)})},"assignRoutes");export{w as a,U as b};
@@ -1 +0,0 @@
1
- import{a}from"./chunk-2WXLF7QU.js";import{a as p}from"./chunk-Z23QA6PX.js";import{a as u}from"./chunk-2HA4XQFN.js";import E from"uWebSockets.js";import{EventEmitter as k}from"node:events";var q="request";function v({cert_file_name:d,key_file_name:h}){let m="App";d&&h&&(m="SSLApp");let c=u((i,n)=>{n.statusCode=404,n.statusMessage="Not Found",n.end()},"handler"),g={cert_file_name:d,key_file_name:h},o=E[m](g).any("/*",(i,n)=>{i.finished=!1;let e=new a(n),t=new p(i,o);e.res=t,t.req=e,e.socket=t.socket,e.method!=="HEAD"?i.onData((r,f)=>{let S=Buffer.from(r);return f?(e.push(S),e.push(null),i.finished?void 0:c(e,t)):e.push(S)}):i.finished||c(e,t)}),y=class extends k{static{u(this,"uServerClass")}constructor(){super();let n=this.on.bind(this),e=this.once.bind(this);this.once=function(t,s){return e(t,s)},this.on=function(t,s){if(t===q){c=s;return}return n(t,s)}}close(n){if(E.us_listen_socket_close(o._socket),!!n)return n()}start(n,e,t){let s,r=u(function(f){o._socket=f,t&&t(f)},"callbackFunction");return n&&e&&t&&(s=[n,e,r]),!t&&(!e||typeof e=="function")&&(t=e,e=n,s=[e,r]),o.listen(...s)}listen(n,e,t){if(typeof n=="object"){let s=n;return e=s.port,t=s.cb,n=s.host,this.start(n,e,r=>{o._socket=r,t&&t(r)})}else return(!e||typeof e=="function")&&!t?(t=e,e=n,this.start(e,t)):this.start(n,e,t)}get uwsApp(){return o}},l=new y;return l[Symbol("IncomingMessage")]=a,l[Symbol("ServerResponse")]=p,l}u(v,"default");export{v as a};