kaelum 1.8.1 → 1.8.3

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/README.md CHANGED
@@ -84,11 +84,14 @@ app.start();
84
84
  ## ⚡ Quick Start
85
85
 
86
86
  ```bash
87
- # Scaffold a new project
88
- npx kaelum create my-app --template web
87
+ # Scaffold a new project (interactive — picks language + template)
88
+ npx kaelum create my-app
89
89
 
90
- # Or an API project
91
- npx kaelum create my-api --template api
90
+ # Or non-interactive with a specific template
91
+ npx kaelum create my-app --template js-web
92
+ npx kaelum create my-api --template js-api
93
+ npx kaelum create my-app --template ts-web
94
+ npx kaelum create my-api --template ts-api
92
95
 
93
96
  # Run it
94
97
  cd my-app && npm install && npm start
@@ -96,21 +99,35 @@ cd my-app && npm install && npm start
96
99
 
97
100
  > No global install needed — `npx` handles everything.
98
101
 
102
+ ### Available Templates
103
+
104
+ | Template | Language | Description |
105
+ | -------- | ---------- | ----------------------------------------- |
106
+ | `js-web` | JavaScript | MVC with views & static files |
107
+ | `js-api` | JavaScript | REST API ready |
108
+ | `ts-web` | TypeScript | MVC with views & static files (tsx + tsc) |
109
+ | `ts-api` | TypeScript | REST API ready (tsx + tsc) |
110
+
111
+ > Legacy aliases `web` and `api` map to `js-web` and `js-api`.
112
+
99
113
  ---
100
114
 
101
115
  ## ✨ Features
102
116
 
103
- | Feature | Description |
104
- |---------|-------------|
105
- | 🚀 **Zero-Config Start** | JSON parsing, static files, EJS views — all pre-configured |
106
- | 🌳 **Tree Routing** | Recursive nested routes with `addRoute` and `apiRoute` |
107
- | 🔒 **Security Built-in** | One-toggle CORS, Helmet, and XSS protection |
108
- | 🛠️ **CLI Scaffolding** | `npx kaelum create` with Web and API templates |
109
- | 📦 **Dual Module** | Works with both `require()` and `import` |
110
- | 🏥 **Health Checks** | Built-in `/health` endpoint with readiness probes |
111
- | ⚡ **Middleware Manager** | Track, add, and remove middleware programmatically |
112
- | 🔄 **Redirects** | Declarative redirect maps with single, array, or object syntax |
113
- | 🛡️ **Error Handler** | Standardized JSON/HTML error responses with hooks |
117
+ | Feature | Description |
118
+ | ------------------------ | -------------------------------------------------------------- |
119
+ | 🚀 **Zero-Config Start** | JSON parsing, static files, EJS views — all pre-configured |
120
+ | 🌳 **Tree Routing** | Recursive nested routes with `addRoute` and `apiRoute` |
121
+ | 🔒 **Security Built-in** | One-toggle CORS, Helmet, and XSS protection |
122
+ | 🛠️ **CLI Scaffolding** | `npx kaelum create` with JS and TS templates (web + API) |
123
+ | 📦 **Dual Module** | Works with both `require()` and `import` |
124
+ | 🏥 **Health Checks** | Built-in `/health` endpoint with readiness probes |
125
+ | ⚡ **Middleware Manager** | Track, add, and remove middleware programmatically |
126
+ | 🔄 **Redirects** | Declarative redirect maps with single, array, or object syntax |
127
+ | 🛡️ **Error Handler** | Standardized JSON/HTML error responses with hooks |
128
+ | ⏱️ **Rate Limiting** | Built-in zero-dependency in-memory rate limiter |
129
+ | 🧩 **Plugin System** | Register and manage plugins with dedup guard |
130
+ | 🔌 **Graceful Shutdown** | Signal handling, connection draining, and cleanup hooks |
114
131
 
115
132
  ---
116
133
 
@@ -145,6 +162,8 @@ app.setConfig({
145
162
  bodyParser: true, // JSON + urlencoded (default: on)
146
163
  port: 3000, // preferred port
147
164
  views: { engine: "ejs", path: "./views" },
165
+ rateLimit: true, // enable rate limiting (default: 100 req/15 min)
166
+ gracefulShutdown: { timeout: 10000 }, // signal handling + cleanup
148
167
  });
149
168
  ```
150
169
 
@@ -185,20 +204,32 @@ app.apiRoute("products", {
185
204
  app.start(3000); // start server
186
205
  app.setMiddleware("/admin", authMiddleware); // scoped middleware
187
206
  app.redirect("/old", "/new", 301); // redirects
188
- app.healthCheck("/health"); // health endpoint
189
- app.useErrorHandler({ exposeStack: false }); // error handling
207
+ app.healthCheck("/health"); // health endpoint
208
+ app.useErrorHandler({ exposeStack: false }); // error handling
209
+ app.plugin(myPlugin, { key: "value" }); // register plugin
210
+ app.onShutdown(() => cleanup()); // shutdown hook
211
+ app.close(); // graceful close
212
+ ```
213
+
214
+ ### CLI Commands
215
+
216
+ ```bash
217
+ kaelum create # interactive project scaffolding
218
+ kaelum --version # show installed version
219
+ kaelum info # show environment details
220
+ kaelum help # show all commands
190
221
  ```
191
222
 
192
223
  ---
193
224
 
194
225
  ## 📁 Project Templates
195
226
 
196
- ### Web Template
227
+ ### JavaScript Web (`js-web`)
197
228
 
198
229
  ```
199
230
  my-web-app/
200
231
  ├── public/ # Static assets
201
- ├── views/ # EJS templates
232
+ ├── views/ # HTML templates
202
233
  ├── controllers/ # Route logic (MVC)
203
234
  ├── middlewares/ # Custom middleware
204
235
  ├── routes.js # Route definitions
@@ -206,7 +237,7 @@ my-web-app/
206
237
  └── package.json
207
238
  ```
208
239
 
209
- ### API Template
240
+ ### JavaScript API (`js-api`)
210
241
 
211
242
  ```
212
243
  my-api/
@@ -217,6 +248,34 @@ my-api/
217
248
  └── package.json
218
249
  ```
219
250
 
251
+ ### TypeScript Web (`ts-web`)
252
+
253
+ ```
254
+ my-web-app/
255
+ ├── public/ # Static assets
256
+ ├── views/ # HTML templates
257
+ ├── src/
258
+ │ ├── controllers/ # Route logic (MVC)
259
+ │ ├── middlewares/ # Custom middleware
260
+ │ ├── routes.ts # Route definitions
261
+ │ └── app.ts # Entry point
262
+ ├── tsconfig.json
263
+ └── package.json
264
+ ```
265
+
266
+ ### TypeScript API (`ts-api`)
267
+
268
+ ```
269
+ my-api/
270
+ ├── src/
271
+ │ ├── controllers/ # Business logic
272
+ │ ├── middlewares/ # Auth, validation
273
+ │ ├── routes.ts # API routes
274
+ │ └── app.ts # Entry point
275
+ ├── tsconfig.json
276
+ └── package.json
277
+ ```
278
+
220
279
  ---
221
280
 
222
281
  ## 🧪 Testing
@@ -239,10 +298,10 @@ See also: [Code of Conduct](https://github.com/kaelumjs/.github/blob/main/CODE_O
239
298
 
240
299
  ## 🌐 Ecosystem
241
300
 
242
- | Package | Description |
243
- |---------|-------------|
244
- | [kaelum](https://www.npmjs.com/package/kaelum) | Core framework |
245
- | [kaelumjs/docs](https://github.com/kaelumjs/docs) | Documentation site |
301
+ | Package | Description |
302
+ | ------------------------------------------------------- | -------------------------- |
303
+ | [kaelum](https://www.npmjs.com/package/kaelum) | Core framework |
304
+ | [kaelumjs/docs](https://github.com/kaelumjs/docs) | Documentation site |
246
305
  | [kaelumjs/.github](https://github.com/kaelumjs/.github) | Shared community standards |
247
306
 
248
307
  ---
@@ -2,8 +2,8 @@
2
2
  // Simple in-memory controller for Kaelum API demonstration
3
3
 
4
4
  const users = [
5
- { id: 1, name: "Maria", role: "admin" },
6
- { id: 2, name: "Joao", role: "user" },
5
+ { id: 1, name: "Alice", role: "admin" },
6
+ { id: 2, name: "Bob", role: "user" },
7
7
  ];
8
8
 
9
9
  exports.list = (req, res) => res.json(users);
@@ -15,7 +15,7 @@ exports.create = (req, res) => {
15
15
  };
16
16
 
17
17
  exports.get = (req, res) => {
18
- const user = users.find((u) => u.id == req.params.id);
18
+ const user = users.find((u) => u.id === Number(req.params.id));
19
19
  return user ? res.json(user) : res.status(404).json({ error: "User not found" });
20
20
  };
21
21
 
@@ -1,6 +1,7 @@
1
1
  // routes.js
2
2
  const users = require("./controllers/usersController");
3
3
  const auth = require("./middlewares/authMock");
4
+ const { version } = require("./package.json");
4
5
 
5
6
  module.exports = (app) => {
6
7
  // Global middleware for /users path
@@ -28,6 +29,6 @@ module.exports = (app) => {
28
29
 
29
30
  // Metadata endpoint
30
31
  app.addRoute("/meta", {
31
- get: (req, res) => res.json({ version: "1.8.0", framework: "Kaelum" }),
32
+ get: (req, res) => res.json({ version, framework: "Kaelum" }),
32
33
  });
33
34
  };
@@ -1,49 +1,52 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width,initial-scale=1" />
6
- <title>Kaelum — Hello</title>
7
- <link rel="stylesheet" href="/style.css" />
8
- </head>
9
- <body>
10
- <main class="container">
11
- <header>
12
- <h1>Kaelum.js</h1>
13
- <p class="subtitle">
14
- Minimalist framework for Web Apps &amp; APIs — Demo Template
15
- </p>
16
- </header>
17
3
 
18
- <section class="content">
19
- <h2>Welcome 👋</h2>
20
- <p>
21
- This template was automatically generated by the
22
- <strong>Kaelum</strong> CLI.
23
- </p>
4
+ <head>
5
+ <meta charset="utf-8" />
6
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
7
+ <title>Kaelum Hello</title>
8
+ <link rel="stylesheet" href="/style.css" />
9
+ </head>
24
10
 
25
- <div class="cards">
26
- <div class="card">
27
- <h3>Routes</h3>
28
- <p>
29
- Available routes: <code>/</code>, <code>/about</code>, <code>/about/team</code>,
30
- <code>/dashboard</code>, <code>/dashboard/settings</code>.
31
- </p>
32
- </div>
33
- <div class="card">
34
- <h3>Security</h3>
35
- <p>CORS and Helmet are enabled via <code>app.setConfig</code>.</p>
36
- </div>
37
- <div class="card">
38
- <h3>Health Check</h3>
39
- <p>Built-in health endpoint at <code>/health</code>.</p>
40
- </div>
11
+ <body>
12
+ <main class="container">
13
+ <header>
14
+ <h1>Kaelum.js</h1>
15
+ <p class="subtitle">
16
+ Minimalist framework for Web Apps &amp; APIs — Demo Template
17
+ </p>
18
+ </header>
19
+
20
+ <section class="content">
21
+ <h2>Welcome 👋</h2>
22
+ <p>
23
+ This template was automatically generated by the
24
+ <strong>Kaelum</strong> CLI.
25
+ </p>
26
+
27
+ <div class="cards">
28
+ <div class="card">
29
+ <h3>Routes</h3>
30
+ <p>
31
+ Available routes: <code>/</code>, <code>/about</code>, <code>/about/team</code>,
32
+ <code>/dashboard</code>, <code>/dashboard/settings</code>.
33
+ </p>
34
+ </div>
35
+ <div class="card">
36
+ <h3>Security</h3>
37
+ <p>CORS and Helmet are enabled via <code>app.setConfig</code>.</p>
41
38
  </div>
39
+ <div class="card">
40
+ <h3>Health Check</h3>
41
+ <p>Built-in health endpoint at <code>/health</code>.</p>
42
+ </div>
43
+ </div>
44
+
45
+ <p class="small">
46
+ Generated by Kaelum CLI
47
+ </p>
48
+ </section>
49
+ </main>
50
+ </body>
42
51
 
43
- <p class="small">
44
- Generated by Kaelum CLI &bull; Kaelum v1.8.0
45
- </p>
46
- </section>
47
- </main>
48
- </body>
49
- </html>
52
+ </html>
@@ -8,8 +8,8 @@ interface User {
8
8
  }
9
9
 
10
10
  const users: User[] = [
11
- { id: 1, name: "Maria", role: "admin" },
12
- { id: 2, name: "Joao", role: "user" },
11
+ { id: 1, name: "Alice", role: "admin" },
12
+ { id: 2, name: "Bob", role: "user" },
13
13
  ];
14
14
 
15
15
  const list = (req: any, res: any): void => {
@@ -1,5 +1,6 @@
1
1
  const users = require("./controllers/usersController");
2
2
  const { authMock } = require("./middlewares/authMock");
3
+ const { version } = require("../../package.json");
3
4
 
4
5
  const routes = (app: any): void => {
5
6
  // Global middleware for /users path
@@ -28,7 +29,7 @@ const routes = (app: any): void => {
28
29
  // Metadata endpoint
29
30
  app.addRoute("/meta", {
30
31
  get: (req: any, res: any) =>
31
- res.json({ version: "1.8.0", framework: "Kaelum" }),
32
+ res.json({ version, framework: "Kaelum" }),
32
33
  });
33
34
  };
34
35
 
@@ -1,6 +1,9 @@
1
1
  // controllers/pagesController.ts
2
2
  const path = require("path");
3
3
 
4
+ // Uses process.cwd() so it resolves from the project root in both
5
+ // development (tsx) and production (compiled dist/), since views/
6
+ // lives at the project root alongside src/.
4
7
  const view = (file: string): string => path.join(process.cwd(), "views", file);
5
8
 
6
9
  const home = (req: any, res: any): void => {
@@ -1,49 +1,52 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width,initial-scale=1" />
6
- <title>Kaelum — Hello</title>
7
- <link rel="stylesheet" href="/style.css" />
8
- </head>
9
- <body>
10
- <main class="container">
11
- <header>
12
- <h1>Kaelum.js</h1>
13
- <p class="subtitle">
14
- Minimalist framework for Web Apps &amp; APIs — TypeScript Template
15
- </p>
16
- </header>
17
3
 
18
- <section class="content">
19
- <h2>Welcome 👋</h2>
20
- <p>
21
- This TypeScript template was automatically generated by the
22
- <strong>Kaelum</strong> CLI.
23
- </p>
4
+ <head>
5
+ <meta charset="utf-8" />
6
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
7
+ <title>Kaelum Hello</title>
8
+ <link rel="stylesheet" href="/style.css" />
9
+ </head>
24
10
 
25
- <div class="cards">
26
- <div class="card">
27
- <h3>Routes</h3>
28
- <p>
29
- Available routes: <code>/</code>, <code>/about</code>, <code>/about/team</code>,
30
- <code>/dashboard</code>, <code>/dashboard/settings</code>.
31
- </p>
32
- </div>
33
- <div class="card">
34
- <h3>TypeScript</h3>
35
- <p>Run <code>npm run dev</code> for hot-reload via <code>tsx</code>.</p>
36
- </div>
37
- <div class="card">
38
- <h3>Health Check</h3>
39
- <p>Built-in health endpoint at <code>/health</code>.</p>
40
- </div>
11
+ <body>
12
+ <main class="container">
13
+ <header>
14
+ <h1>Kaelum.js</h1>
15
+ <p class="subtitle">
16
+ Minimalist framework for Web Apps &amp; APIs — TypeScript Template
17
+ </p>
18
+ </header>
19
+
20
+ <section class="content">
21
+ <h2>Welcome 👋</h2>
22
+ <p>
23
+ This TypeScript template was automatically generated by the
24
+ <strong>Kaelum</strong> CLI.
25
+ </p>
26
+
27
+ <div class="cards">
28
+ <div class="card">
29
+ <h3>Routes</h3>
30
+ <p>
31
+ Available routes: <code>/</code>, <code>/about</code>, <code>/about/team</code>,
32
+ <code>/dashboard</code>, <code>/dashboard/settings</code>.
33
+ </p>
34
+ </div>
35
+ <div class="card">
36
+ <h3>TypeScript</h3>
37
+ <p>Run <code>npm run dev</code> for hot-reload via <code>tsx</code>.</p>
41
38
  </div>
39
+ <div class="card">
40
+ <h3>Health Check</h3>
41
+ <p>Built-in health endpoint at <code>/health</code>.</p>
42
+ </div>
43
+ </div>
44
+
45
+ <p class="small">
46
+ Generated by Kaelum CLI
47
+ </p>
48
+ </section>
49
+ </main>
50
+ </body>
42
51
 
43
- <p class="small">
44
- Generated by Kaelum CLI &bull; Kaelum v1.8.0
45
- </p>
46
- </section>
47
- </main>
48
- </body>
49
- </html>
52
+ </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kaelum",
3
- "version": "1.8.1",
3
+ "version": "1.8.3",
4
4
  "description": "A minimalist Node.js framework for building web pages and APIs with simplicity and speed.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",