veko-framework 1.0.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.
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Veko v1 – Higher-order route wrapper for consistent error handling
3
+ * Keeps generated route handlers lean: one try/catch, VekoError normalization.
4
+ */
5
+
6
+ import { toVekoError } from './errors.js';
7
+
8
+ /**
9
+ * Wrap an async route handler so all errors are caught and returned as JSON.
10
+ * Uses VekoError status when present; otherwise normalizes DB/other errors.
11
+ * @param {(req: import('express').Request, res: import('express').Response) => Promise<void>} handler
12
+ * @returns {(req: import('express').Request, res: import('express').Response) => void}
13
+ */
14
+ export function wrapAction(handler) {
15
+ return (req, res) => {
16
+ Promise.resolve(handler(req, res)).catch((err) => {
17
+ if (res.headersSent) return;
18
+ const veko = toVekoError(err);
19
+ res.status(veko.status).json({ error: veko.message, message: veko.message });
20
+ });
21
+ };
22
+ }
23
+
24
+ export default wrapAction;
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "allowJs": true,
10
+ "checkJs": false,
11
+ "outDir": "dist",
12
+ "rootDir": ".",
13
+ "types": ["node"]
14
+ },
15
+ "include": ["src/cli/**/*.ts", "src/compiler/**/*.d.ts", "src/config/**/*.d.ts"],
16
+ "exclude": ["node_modules", "generated", "dist"]
17
+ }