kuwan-expresspack-core 0.1.2 → 0.1.4
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/dist/index.mjs
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import { a } from './chunk-VSPZT4K6.mjs';
|
|
2
2
|
import { c } from './chunk-CRIPGIHI.mjs';
|
|
3
|
-
import
|
|
3
|
+
import y from 'consola';
|
|
4
4
|
import { Router } from 'express';
|
|
5
|
-
import
|
|
5
|
+
import u, { relative, join } from 'path';
|
|
6
6
|
import { glob } from 'tinyglobby';
|
|
7
|
-
import
|
|
8
|
-
import
|
|
7
|
+
import x, { existsSync } from 'fs';
|
|
8
|
+
import { fileURLToPath } from 'url';
|
|
9
|
+
import 'module';
|
|
9
10
|
|
|
10
|
-
var j=process.env.EXPRESSPACK_LOG_LEVEL,
|
|
11
|
+
var j=process.env.EXPRESSPACK_LOG_LEVEL,F=y.create({level:Number.isNaN(Number(j))?3:Number(j)}),i=F;function K(e,o,r){return e.listen(o,async()=>{r&&(i.debug("Executing onStart hook..."),await r().catch(t=>{i.error("Error during onStart hook:",t);})),i.box({message:`Server is running at http://localhost:${o}`,style:{borderColor:"cyan"},level:"info"}),c.emit("app:mounted");})}function $(e,o){process.on("SIGINT",async()=>{i.info("Received SIGINT. Shutting down gracefully..."),await new Promise(r=>{e.close(async s=>s instanceof Error?(i.error("Error shutting down server:",s),r()):(o&&await o().catch(t=>{i.error("Error during shutdown hook:",t);}),i.info("Server has been shut down."),r()));}),process.exit(0);});}function D(e){return e}async function _({app:e},{kernel:o,listener:r,appBootstrap:s}){i.debug("Loading kernel...");try{let t=await o();await(t?.default||t)({app:e});}catch(t){throw i.error("Error loading kernel:",t),t}if(r&&typeof r=="function")try{let t=await r(),p=t?.default||t;p===void 0||typeof p!="function"?i.warn("No listener setup function found"):await p();}catch(t){throw i.error("Error loading listener:",t),t}if(s&&typeof s=="function")try{await s({app:e});}catch(t){throw i.error("Error during boot process:",t),t}i.debug("Kernel loaded.");}function h(){return Router()}function G(e){let o=h();return e(o),o}function k(e){let o=join(e,"expresspack.config"),r=join(e,"app"),s=join(e,"config"),t=join(s,"app"),p=join(s,"body-parser"),n=join(r,"controllers"),c=join(r,"services"),m=join(r,"errors"),l=join(r,"middlewares"),g=join(r,"routes");return {rc:o,root:e,app:r,middlewareFilePath:l,routesFilePath:g,config:{base:s,bodyParserFile:p,appConfigFile:t},controllers:{base:n},services:{base:c},errors:{base:m}}}var S=e=>{let o=["ts","mts","js","mjs","cjs","cts"];for(let r of o){let s=`${e}.${r}`;if(existsSync(s))return s}return null},C=e=>existsSync(e)?e:null;function N(e){if(!e)return "";let o=u.sep;return e.endsWith(o)?e:e+o}var z=u.dirname(fileURLToPath(import.meta.url)),B=u.resolve(z,"..","package.json"),A=u.dirname(B);function b(e,o){let s=`
|
|
11
12
|
declare module 'kuwan-expresspack-core/config' {
|
|
12
13
|
const config: AppConfig;
|
|
13
14
|
export default config;
|
|
14
15
|
export function getAppConfig<K extends keyof AppConfig>(key: K): AppConfig[K];
|
|
15
16
|
|
|
16
17
|
export interface AppConfig {
|
|
17
|
-
${o.map(
|
|
18
|
+
${o.map(c=>`${c.topic}: typeof import('${c.configPath}').default;`).join(`
|
|
18
19
|
`)}
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
|
-
`.trim(),
|
|
22
|
-
${
|
|
23
|
-
`)}`);let p=new Set;for(let
|
|
22
|
+
`.trim(),p=A,n=u.join(p,".types");y.debug({modulesPath:A,generatedTypesDir:n});try{x.existsSync(p)&&(x.existsSync(n)||(x.mkdirSync(n,{recursive:!1}),y.debug("Created directory:",n)),x.writeFileSync(u.join(n,"config.d.ts"),s),y.debug("Generated types at:",u.join(n,"config.d.ts")));}catch(c){y.debug("Failed to generate config types. This warning can be ignored.",c);}}var W="*.{js,ts,mjs,cjs,mts,cts}",q=["!*.d.{ts,mts,mjs,cts}","!*.map"];async function X(e){let o=await glob([W,...q],{cwd:e}),r=new Set;return o.forEach(s=>{let t=s.replace(/\.(js|ts|mjs|cjs|mts|cts)$/,"");r.add(t);}),Array.from(r)}async function Q(e){let{config:o}=k(e),r=o.base;if(i.debug("Loading all configurations from: "+N(relative(e,o.base))),!C(r)){i.debug("No config directory found. Looked for:",r);return}let t=await X(r);i.debug(`Found ${t.length} config files: %s`,`
|
|
23
|
+
${t.join(`
|
|
24
|
+
`)}`);let p=new Set;for(let n of t){let c=S(join(r,n));if(!c){i.warn(`No config file found for topic: ${n}`);continue}try{let m=await import(c),l=m.default||m;typeof l=="function"&&(l=await l());let g=n.replace(/[-_](\w)/g,(Y,v)=>v?v.toUpperCase():"");a[g]=l;let T=c.split("/").pop();i.debug(`Loaded config: ${g} from ${T}`),process.env.NODE_ENV!=="production"&&p.add({topic:g,configPath:c});}catch(m){i.error(`Failed to load config ${n}:`,m);}}process.env.NODE_ENV!=="production"&&(i.debug("Generating type definitions for config files..."),b(e,Array.from(p)));}
|
|
24
25
|
|
|
25
|
-
export {
|
|
26
|
+
export { Q as configLoader, h as createRouter, D as defineKernel, G as defineRouterMiddleware, K as gracefulHTTPStart, $ as gracefulShutdown, _ as loadKernel };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { ErrorRequestHandler } from 'express';
|
|
1
|
+
import { RequestHandler, ErrorRequestHandler } from 'express';
|
|
2
|
+
|
|
3
|
+
declare function notFoundErrorHandler(): RequestHandler;
|
|
2
4
|
|
|
3
5
|
declare function errorHandler(): ErrorRequestHandler;
|
|
4
6
|
|
|
5
|
-
export { errorHandler };
|
|
7
|
+
export { errorHandler, notFoundErrorHandler };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { b } from '../../chunk-OXS52JE5.mjs';
|
|
2
2
|
|
|
3
|
-
function
|
|
3
|
+
function d(){return (r,t,o)=>{t.status(404).json({error:"Not Found"});}}function m(){return (r,t,o,n)=>{if(b.isCustomError(r))return o.status(r.statusCode).json(r.toJSON());if(r instanceof Error){let s=r.statusCode||500;return o.status(s).json({error:"Internal Server Error"})}n(r);}}
|
|
4
4
|
|
|
5
|
-
export {
|
|
5
|
+
export { m as errorHandler, d as notFoundErrorHandler };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kuwan-expresspack-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"./services/*": {
|
|
49
49
|
"types": "./dist/services/*/index.d.ts",
|
|
50
|
-
"import": "./dist/services/*/index.
|
|
50
|
+
"import": "./dist/services/*/index.mjs"
|
|
51
51
|
},
|
|
52
52
|
"./services/event": {
|
|
53
53
|
"types": "./dist/services/event/index.d.ts",
|