te.js 2.1.0 → 2.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.
- package/README.md +197 -196
- package/auto-docs/analysis/handler-analyzer.js +58 -58
- package/auto-docs/analysis/source-resolver.js +101 -101
- package/auto-docs/constants.js +37 -37
- package/auto-docs/docs-llm/index.js +7 -7
- package/auto-docs/docs-llm/prompts.js +222 -222
- package/auto-docs/docs-llm/provider.js +132 -132
- package/auto-docs/index.js +146 -146
- package/auto-docs/openapi/endpoint-processor.js +277 -277
- package/auto-docs/openapi/generator.js +107 -107
- package/auto-docs/openapi/level3.js +131 -131
- package/auto-docs/openapi/spec-builders.js +244 -244
- package/auto-docs/ui/docs-ui.js +186 -186
- package/auto-docs/utils/logger.js +17 -17
- package/auto-docs/utils/strip-usage.js +10 -10
- package/cli/docs-command.js +315 -315
- package/cli/fly-command.js +71 -71
- package/cli/index.js +56 -56
- package/cors/index.js +71 -0
- package/database/index.js +165 -165
- package/database/mongodb.js +146 -146
- package/database/redis.js +201 -201
- package/docs/README.md +36 -36
- package/docs/ammo.md +362 -362
- package/docs/api-reference.md +490 -490
- package/docs/auto-docs.md +216 -216
- package/docs/cli.md +152 -152
- package/docs/configuration.md +275 -275
- package/docs/database.md +390 -390
- package/docs/error-handling.md +438 -438
- package/docs/file-uploads.md +333 -333
- package/docs/getting-started.md +214 -214
- package/docs/middleware.md +355 -355
- package/docs/rate-limiting.md +393 -393
- package/docs/routing.md +302 -302
- package/lib/llm/client.js +73 -0
- package/lib/llm/index.js +7 -0
- package/lib/llm/parse.js +89 -0
- package/package.json +64 -62
- package/rate-limit/algorithms/fixed-window.js +141 -141
- package/rate-limit/algorithms/sliding-window.js +147 -147
- package/rate-limit/algorithms/token-bucket.js +115 -115
- package/rate-limit/base.js +165 -165
- package/rate-limit/index.js +147 -147
- package/rate-limit/storage/base.js +104 -104
- package/rate-limit/storage/memory.js +101 -101
- package/rate-limit/storage/redis.js +88 -88
- package/server/ammo/body-parser.js +220 -220
- package/server/ammo/dispatch-helper.js +103 -103
- package/server/ammo/enhancer.js +57 -57
- package/server/ammo.js +454 -415
- package/server/endpoint.js +97 -74
- package/server/error.js +9 -9
- package/server/errors/code-context.js +125 -125
- package/server/errors/llm-error-service.js +140 -140
- package/server/files/helper.js +33 -33
- package/server/files/uploader.js +143 -143
- package/server/handler.js +158 -119
- package/server/target.js +185 -175
- package/server/targets/middleware-validator.js +22 -22
- package/server/targets/path-validator.js +21 -21
- package/server/targets/registry.js +160 -160
- package/server/targets/shoot-validator.js +21 -21
- package/te.js +428 -402
- package/utils/auto-register.js +17 -17
- package/utils/configuration.js +64 -64
- package/utils/errors-llm-config.js +84 -84
- package/utils/request-logger.js +43 -43
- package/utils/status-codes.js +82 -82
- package/utils/tejas-entrypoint-html.js +18 -18
package/docs/getting-started.md
CHANGED
|
@@ -1,214 +1,214 @@
|
|
|
1
|
-
# Getting Started with Tejas
|
|
2
|
-
|
|
3
|
-
Tejas is a lightweight Node.js framework for building powerful backend services. It features an intuitive API with aviation-inspired naming conventions.
|
|
4
|
-
|
|
5
|
-
## Why Tejas?
|
|
6
|
-
|
|
7
|
-
- **AI-Native** — MCP server gives your AI assistant full framework knowledge for correct code generation
|
|
8
|
-
- **Zero-Config Error Handling** — No try-catch needed! Tejas catches all errors automatically
|
|
9
|
-
- **Clean, Readable Code** — Aviation-inspired naming makes code self-documenting
|
|
10
|
-
- **Express Compatible** — Use your existing Express middleware
|
|
11
|
-
- **Built-in Features** — Rate limiting, file uploads, database connections out of the box
|
|
12
|
-
|
|
13
|
-
## AI-Assisted Setup (MCP) — Recommended
|
|
14
|
-
|
|
15
|
-
The fastest way to start building with Tejas is through your AI assistant. The **Tejas MCP server** (`tejas-mcp`) gives AI tools full access to framework documentation, validated code examples, and purpose-built tools that scaffold projects and generate correct te.js code.
|
|
16
|
-
|
|
17
|
-
### Setup
|
|
18
|
-
|
|
19
|
-
**Cursor** — create or edit `.cursor/mcp.json` in your workspace:
|
|
20
|
-
|
|
21
|
-
```json
|
|
22
|
-
{
|
|
23
|
-
"mcpServers": {
|
|
24
|
-
"tejas": {
|
|
25
|
-
"command": "npx",
|
|
26
|
-
"args": ["-y", "tejas-mcp"]
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
**Other MCP-compatible IDEs** — run `npx tejas-mcp` as the stdio server command. No API keys required.
|
|
33
|
-
|
|
34
|
-
### What you can do
|
|
35
|
-
|
|
36
|
-
Once connected, prompt your assistant naturally:
|
|
37
|
-
|
|
38
|
-
- *"Scaffold a new te.js project called my-api on port 5000"*
|
|
39
|
-
- *"Create a REST API with user CRUD routes using te.js"*
|
|
40
|
-
- *"Add a /health endpoint that returns system uptime"*
|
|
41
|
-
|
|
42
|
-
The MCP server provides these tools: `scaffold_project`, `generate_target`, `generate_app_entry`, `generate_config`, `get_documentation`, and `search_docs`.
|
|
43
|
-
|
|
44
|
-
---
|
|
45
|
-
|
|
46
|
-
## Prerequisites
|
|
47
|
-
|
|
48
|
-
- Node.js 18.x or higher
|
|
49
|
-
- npm or yarn
|
|
50
|
-
|
|
51
|
-
## Installation
|
|
52
|
-
|
|
53
|
-
```bash
|
|
54
|
-
npm install te.js
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
## Quick Start
|
|
58
|
-
|
|
59
|
-
### 1. Create Your Application
|
|
60
|
-
|
|
61
|
-
Create an `index.js` file:
|
|
62
|
-
|
|
63
|
-
```javascript
|
|
64
|
-
import Tejas from 'te.js';
|
|
65
|
-
|
|
66
|
-
const app = new Tejas();
|
|
67
|
-
|
|
68
|
-
app.takeoff();
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### 2. Create Your First Route
|
|
72
|
-
|
|
73
|
-
Create a `targets` directory and add `hello.target.js`:
|
|
74
|
-
|
|
75
|
-
```javascript
|
|
76
|
-
import { Target } from 'te.js';
|
|
77
|
-
|
|
78
|
-
const target = new Target('/hello');
|
|
79
|
-
|
|
80
|
-
target.register('/', (ammo) => {
|
|
81
|
-
ammo.fire({ message: 'Hello, World!' });
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
target.register('/greet/:name', (ammo) => {
|
|
85
|
-
const { name } = ammo.payload;
|
|
86
|
-
ammo.fire({ message: `Hello, ${name}!` });
|
|
87
|
-
});
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
### 3. Run Your Application
|
|
91
|
-
|
|
92
|
-
```bash
|
|
93
|
-
node index.js
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
Your server is now running on `http://localhost:1403`
|
|
97
|
-
|
|
98
|
-
## Core Concepts
|
|
99
|
-
|
|
100
|
-
### Terminology
|
|
101
|
-
|
|
102
|
-
Tejas uses aviation-inspired naming:
|
|
103
|
-
|
|
104
|
-
| Term | Express Equivalent | Description |
|
|
105
|
-
|------|-------------------|-------------|
|
|
106
|
-
| `Tejas` | `express()` | Main application instance |
|
|
107
|
-
| `Target` | `Router` | Route grouping |
|
|
108
|
-
| `Ammo` | `req` + `res` | Request/response wrapper |
|
|
109
|
-
| `fire()` | `res.send()` | Send response |
|
|
110
|
-
| `throw()` | Error response | Send error |
|
|
111
|
-
| `midair()` | `use()` | Register middleware |
|
|
112
|
-
| `takeoff()` | `listen()` | Start server |
|
|
113
|
-
|
|
114
|
-
### Basic Structure
|
|
115
|
-
|
|
116
|
-
```
|
|
117
|
-
my-app/
|
|
118
|
-
├── index.js # Application entry point
|
|
119
|
-
├── tejas.config.json # Optional configuration
|
|
120
|
-
├── .env # Environment variables
|
|
121
|
-
├── targets/ # Route definitions (auto-discovered)
|
|
122
|
-
│ ├── user.target.js
|
|
123
|
-
│ ├── auth.target.js
|
|
124
|
-
│ └── api/
|
|
125
|
-
│ └── v1.target.js
|
|
126
|
-
├── services/ # Business logic
|
|
127
|
-
│ └── user.service.js
|
|
128
|
-
└── middleware/ # Custom middleware
|
|
129
|
-
└── auth.js
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
## Automatic Error Handling
|
|
133
|
-
|
|
134
|
-
One of Tejas's most powerful features is that **you don't need to write any error handling code**. The framework catches all errors automatically:
|
|
135
|
-
|
|
136
|
-
```javascript
|
|
137
|
-
// ✅ No try-catch needed — if anything throws, Tejas handles it
|
|
138
|
-
target.register('/data', async (ammo) => {
|
|
139
|
-
const data = await riskyDatabaseCall();
|
|
140
|
-
const processed = await anotherAsyncOperation(data);
|
|
141
|
-
ammo.fire(processed);
|
|
142
|
-
});
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
Your application never crashes from unhandled exceptions, and clients always receive proper error responses. Learn more in [Error Handling](./error-handling.md).
|
|
146
|
-
|
|
147
|
-
## Next Steps
|
|
148
|
-
|
|
149
|
-
- [Configuration](./configuration.md) — All configuration options and sources
|
|
150
|
-
- [Routing](./routing.md) — Deep dive into the Target-based routing system
|
|
151
|
-
- [Ammo](./ammo.md) — Master request/response handling
|
|
152
|
-
- [Middleware](./middleware.md) — Global, target, and route-level middleware
|
|
153
|
-
- [Database](./database.md) — Connect to MongoDB or Redis
|
|
154
|
-
- [Error Handling](./error-handling.md) — Zero-config error handling
|
|
155
|
-
- [CLI Reference](./cli.md) — `tejas fly` and doc generation commands
|
|
156
|
-
- [Auto-Documentation](./auto-docs.md) — Generate OpenAPI specs from your code
|
|
157
|
-
|
|
158
|
-
## Example Application
|
|
159
|
-
|
|
160
|
-
Here's a more complete example:
|
|
161
|
-
|
|
162
|
-
```javascript
|
|
163
|
-
import Tejas from 'te.js';
|
|
164
|
-
|
|
165
|
-
const app = new Tejas({
|
|
166
|
-
port: 3000,
|
|
167
|
-
log: {
|
|
168
|
-
http_requests: true,
|
|
169
|
-
exceptions: true
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
// Global middleware
|
|
174
|
-
app.midair((ammo, next) => {
|
|
175
|
-
console.log(`${ammo.method} ${ammo.path}`);
|
|
176
|
-
next();
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
// Rate limiting (in-memory)
|
|
180
|
-
app.withRateLimit({
|
|
181
|
-
maxRequests: 100,
|
|
182
|
-
timeWindowSeconds: 60
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
// Start with optional Redis
|
|
186
|
-
app.takeoff({
|
|
187
|
-
withRedis: { url: 'redis://localhost:6379' }
|
|
188
|
-
});
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
```javascript
|
|
192
|
-
// targets/api.target.js
|
|
193
|
-
import { Target } from 'te.js';
|
|
194
|
-
|
|
195
|
-
const api = new Target('/api');
|
|
196
|
-
|
|
197
|
-
// GET /api/status
|
|
198
|
-
api.register('/status', (ammo) => {
|
|
199
|
-
if (ammo.GET) {
|
|
200
|
-
ammo.fire({ status: 'operational', timestamp: Date.now() });
|
|
201
|
-
} else {
|
|
202
|
-
ammo.notAllowed();
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
// POST /api/echo
|
|
207
|
-
api.register('/echo', (ammo) => {
|
|
208
|
-
if (ammo.POST) {
|
|
209
|
-
ammo.fire(ammo.payload);
|
|
210
|
-
} else {
|
|
211
|
-
ammo.notAllowed();
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
```
|
|
1
|
+
# Getting Started with Tejas
|
|
2
|
+
|
|
3
|
+
Tejas is a lightweight Node.js framework for building powerful backend services. It features an intuitive API with aviation-inspired naming conventions.
|
|
4
|
+
|
|
5
|
+
## Why Tejas?
|
|
6
|
+
|
|
7
|
+
- **AI-Native** — MCP server gives your AI assistant full framework knowledge for correct code generation
|
|
8
|
+
- **Zero-Config Error Handling** — No try-catch needed! Tejas catches all errors automatically
|
|
9
|
+
- **Clean, Readable Code** — Aviation-inspired naming makes code self-documenting
|
|
10
|
+
- **Express Compatible** — Use your existing Express middleware
|
|
11
|
+
- **Built-in Features** — Rate limiting, file uploads, database connections out of the box
|
|
12
|
+
|
|
13
|
+
## AI-Assisted Setup (MCP) — Recommended
|
|
14
|
+
|
|
15
|
+
The fastest way to start building with Tejas is through your AI assistant. The **Tejas MCP server** (`tejas-mcp`) gives AI tools full access to framework documentation, validated code examples, and purpose-built tools that scaffold projects and generate correct te.js code.
|
|
16
|
+
|
|
17
|
+
### Setup
|
|
18
|
+
|
|
19
|
+
**Cursor** — create or edit `.cursor/mcp.json` in your workspace:
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"mcpServers": {
|
|
24
|
+
"tejas": {
|
|
25
|
+
"command": "npx",
|
|
26
|
+
"args": ["-y", "tejas-mcp"]
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Other MCP-compatible IDEs** — run `npx tejas-mcp` as the stdio server command. No API keys required.
|
|
33
|
+
|
|
34
|
+
### What you can do
|
|
35
|
+
|
|
36
|
+
Once connected, prompt your assistant naturally:
|
|
37
|
+
|
|
38
|
+
- *"Scaffold a new te.js project called my-api on port 5000"*
|
|
39
|
+
- *"Create a REST API with user CRUD routes using te.js"*
|
|
40
|
+
- *"Add a /health endpoint that returns system uptime"*
|
|
41
|
+
|
|
42
|
+
The MCP server provides these tools: `scaffold_project`, `generate_target`, `generate_app_entry`, `generate_config`, `get_documentation`, and `search_docs`.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Prerequisites
|
|
47
|
+
|
|
48
|
+
- Node.js 18.x or higher
|
|
49
|
+
- npm or yarn
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npm install te.js
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Quick Start
|
|
58
|
+
|
|
59
|
+
### 1. Create Your Application
|
|
60
|
+
|
|
61
|
+
Create an `index.js` file:
|
|
62
|
+
|
|
63
|
+
```javascript
|
|
64
|
+
import Tejas from 'te.js';
|
|
65
|
+
|
|
66
|
+
const app = new Tejas();
|
|
67
|
+
|
|
68
|
+
app.takeoff();
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 2. Create Your First Route
|
|
72
|
+
|
|
73
|
+
Create a `targets` directory and add `hello.target.js`:
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
import { Target } from 'te.js';
|
|
77
|
+
|
|
78
|
+
const target = new Target('/hello');
|
|
79
|
+
|
|
80
|
+
target.register('/', (ammo) => {
|
|
81
|
+
ammo.fire({ message: 'Hello, World!' });
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
target.register('/greet/:name', (ammo) => {
|
|
85
|
+
const { name } = ammo.payload;
|
|
86
|
+
ammo.fire({ message: `Hello, ${name}!` });
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 3. Run Your Application
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
node index.js
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Your server is now running on `http://localhost:1403`
|
|
97
|
+
|
|
98
|
+
## Core Concepts
|
|
99
|
+
|
|
100
|
+
### Terminology
|
|
101
|
+
|
|
102
|
+
Tejas uses aviation-inspired naming:
|
|
103
|
+
|
|
104
|
+
| Term | Express Equivalent | Description |
|
|
105
|
+
|------|-------------------|-------------|
|
|
106
|
+
| `Tejas` | `express()` | Main application instance |
|
|
107
|
+
| `Target` | `Router` | Route grouping |
|
|
108
|
+
| `Ammo` | `req` + `res` | Request/response wrapper |
|
|
109
|
+
| `fire()` | `res.send()` | Send response |
|
|
110
|
+
| `throw()` | Error response | Send error |
|
|
111
|
+
| `midair()` | `use()` | Register middleware |
|
|
112
|
+
| `takeoff()` | `listen()` | Start server |
|
|
113
|
+
|
|
114
|
+
### Basic Structure
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
my-app/
|
|
118
|
+
├── index.js # Application entry point
|
|
119
|
+
├── tejas.config.json # Optional configuration
|
|
120
|
+
├── .env # Environment variables
|
|
121
|
+
├── targets/ # Route definitions (auto-discovered)
|
|
122
|
+
│ ├── user.target.js
|
|
123
|
+
│ ├── auth.target.js
|
|
124
|
+
│ └── api/
|
|
125
|
+
│ └── v1.target.js
|
|
126
|
+
├── services/ # Business logic
|
|
127
|
+
│ └── user.service.js
|
|
128
|
+
└── middleware/ # Custom middleware
|
|
129
|
+
└── auth.js
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Automatic Error Handling
|
|
133
|
+
|
|
134
|
+
One of Tejas's most powerful features is that **you don't need to write any error handling code**. The framework catches all errors automatically:
|
|
135
|
+
|
|
136
|
+
```javascript
|
|
137
|
+
// ✅ No try-catch needed — if anything throws, Tejas handles it
|
|
138
|
+
target.register('/data', async (ammo) => {
|
|
139
|
+
const data = await riskyDatabaseCall();
|
|
140
|
+
const processed = await anotherAsyncOperation(data);
|
|
141
|
+
ammo.fire(processed);
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Your application never crashes from unhandled exceptions, and clients always receive proper error responses. Learn more in [Error Handling](./error-handling.md).
|
|
146
|
+
|
|
147
|
+
## Next Steps
|
|
148
|
+
|
|
149
|
+
- [Configuration](./configuration.md) — All configuration options and sources
|
|
150
|
+
- [Routing](./routing.md) — Deep dive into the Target-based routing system
|
|
151
|
+
- [Ammo](./ammo.md) — Master request/response handling
|
|
152
|
+
- [Middleware](./middleware.md) — Global, target, and route-level middleware
|
|
153
|
+
- [Database](./database.md) — Connect to MongoDB or Redis
|
|
154
|
+
- [Error Handling](./error-handling.md) — Zero-config error handling
|
|
155
|
+
- [CLI Reference](./cli.md) — `tejas fly` and doc generation commands
|
|
156
|
+
- [Auto-Documentation](./auto-docs.md) — Generate OpenAPI specs from your code
|
|
157
|
+
|
|
158
|
+
## Example Application
|
|
159
|
+
|
|
160
|
+
Here's a more complete example:
|
|
161
|
+
|
|
162
|
+
```javascript
|
|
163
|
+
import Tejas from 'te.js';
|
|
164
|
+
|
|
165
|
+
const app = new Tejas({
|
|
166
|
+
port: 3000,
|
|
167
|
+
log: {
|
|
168
|
+
http_requests: true,
|
|
169
|
+
exceptions: true
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// Global middleware
|
|
174
|
+
app.midair((ammo, next) => {
|
|
175
|
+
console.log(`${ammo.method} ${ammo.path}`);
|
|
176
|
+
next();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
// Rate limiting (in-memory)
|
|
180
|
+
app.withRateLimit({
|
|
181
|
+
maxRequests: 100,
|
|
182
|
+
timeWindowSeconds: 60
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// Start with optional Redis
|
|
186
|
+
app.takeoff({
|
|
187
|
+
withRedis: { url: 'redis://localhost:6379' }
|
|
188
|
+
});
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
```javascript
|
|
192
|
+
// targets/api.target.js
|
|
193
|
+
import { Target } from 'te.js';
|
|
194
|
+
|
|
195
|
+
const api = new Target('/api');
|
|
196
|
+
|
|
197
|
+
// GET /api/status
|
|
198
|
+
api.register('/status', (ammo) => {
|
|
199
|
+
if (ammo.GET) {
|
|
200
|
+
ammo.fire({ status: 'operational', timestamp: Date.now() });
|
|
201
|
+
} else {
|
|
202
|
+
ammo.notAllowed();
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
// POST /api/echo
|
|
207
|
+
api.register('/echo', (ammo) => {
|
|
208
|
+
if (ammo.POST) {
|
|
209
|
+
ammo.fire(ammo.payload);
|
|
210
|
+
} else {
|
|
211
|
+
ammo.notAllowed();
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
```
|