@oxog/spark 1.1.1 → 1.2.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.
- package/CHANGELOG.md +632 -315
- package/LICENSE +20 -20
- package/README.md +288 -241
- package/package.json +83 -89
- package/src/core/application.js +1068 -956
- package/src/core/context.js +1098 -830
- package/src/core/middleware.js +303 -217
- package/src/index.js +183 -280
- package/src/middleware/body-parser.js +482 -526
- package/src/middleware/cache.js +177 -170
- package/src/middleware/compression.js +177 -182
- package/src/middleware/cors.js +176 -95
- package/src/middleware/health.js +219 -218
- package/src/middleware/logger.js +195 -194
- package/src/middleware/metrics.js +339 -327
- package/src/middleware/rate-limit.js +367 -319
- package/src/middleware/security.js +442 -332
- package/src/middleware/session.js +647 -529
- package/src/middleware/static.js +404 -299
- package/src/router/layer.js +197 -117
- package/src/router/route.js +149 -123
- package/src/router/router.js +703 -755
- package/src/utils/async-handler.js +145 -147
- package/src/utils/context-pool.js +83 -82
- package/src/utils/regex-validator.js +187 -163
- package/src/utils/safe-json.js +110 -0
- package/types/index.d.ts +536 -291
- package/dist/LICENSE +0 -21
- package/dist/README.md +0 -242
- package/dist/core/application.js +0 -959
- package/dist/core/context.js +0 -833
- package/dist/core/middleware.js +0 -220
- package/dist/core/request.js +0 -335
- package/dist/core/response.js +0 -377
- package/dist/index.js +0 -280
- package/dist/middleware/body-parser.js +0 -528
- package/dist/middleware/cache.js +0 -173
- package/dist/middleware/compression.js +0 -185
- package/dist/middleware/cors.js +0 -97
- package/dist/middleware/health.js +0 -221
- package/dist/middleware/index.js +0 -23
- package/dist/middleware/logger.js +0 -197
- package/dist/middleware/metrics.js +0 -330
- package/dist/middleware/rate-limit.js +0 -322
- package/dist/middleware/security.js +0 -335
- package/dist/middleware/session.js +0 -532
- package/dist/middleware/static.js +0 -301
- package/dist/package.json +0 -62
- package/dist/router/layer.js +0 -119
- package/dist/router/route.js +0 -125
- package/dist/router/router.js +0 -758
- package/dist/types/index.d.ts +0 -291
- package/dist/utils/async-handler.js +0 -150
- package/dist/utils/cache.js +0 -443
- package/dist/utils/context-pool.js +0 -85
- package/dist/utils/error-types.js +0 -134
- package/dist/utils/http.js +0 -415
- package/dist/utils/regex-validator.js +0 -166
- package/src/core/request.js +0 -335
- package/src/core/response.js +0 -377
- package/src/middleware/index.js +0 -23
- package/src/utils/cache.js +0 -443
- package/src/utils/error-types.js +0 -134
- package/src/utils/http.js +0 -415
package/dist/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Ersin Koç
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/dist/README.md
DELETED
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
# ⚡ Spark
|
|
2
|
-
|
|
3
|
-
A fast, lightweight, and zero-dependency Node.js web framework built for performance and simplicity.
|
|
4
|
-
|
|
5
|
-
[](https://badge.fury.io/js/@oxog/spark)
|
|
6
|
-
[](https://opensource.org/licenses/MIT)
|
|
7
|
-
[](https://nodejs.org/)
|
|
8
|
-
|
|
9
|
-
## 🚀 Features
|
|
10
|
-
|
|
11
|
-
- **Zero Dependencies** - No external dependencies, pure Node.js
|
|
12
|
-
- **High Performance** - Built for speed with optimized request handling
|
|
13
|
-
- **Middleware Support** - Express-like middleware system
|
|
14
|
-
- **Advanced Router** - Powerful routing with parameter support
|
|
15
|
-
- **Session Management** - Built-in session handling with auto-save
|
|
16
|
-
- **Security First** - CORS, CSRF, rate limiting, and security headers
|
|
17
|
-
- **TypeScript Support** - Full TypeScript definitions included
|
|
18
|
-
- **Memory Efficient** - Optimized for low memory usage
|
|
19
|
-
- **Easy to Use** - Simple, intuitive API
|
|
20
|
-
|
|
21
|
-
## 📦 Installation
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
npm install @oxog/spark
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## 🌟 Quick Start
|
|
28
|
-
|
|
29
|
-
```javascript
|
|
30
|
-
const { Spark } = require('@oxog/spark');
|
|
31
|
-
|
|
32
|
-
const app = new Spark();
|
|
33
|
-
|
|
34
|
-
app.get('/', (ctx) => {
|
|
35
|
-
ctx.json({ message: 'Hello World!' });
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
app.listen(3000, () => {
|
|
39
|
-
console.log('Server running on port 3000');
|
|
40
|
-
});
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
## 📚 Documentation
|
|
44
|
-
|
|
45
|
-
### 🎯 **Quick Links**
|
|
46
|
-
- **[📖 Complete Documentation](docs/README.md)** - Full documentation index
|
|
47
|
-
- **[🚀 Getting Started](docs/getting-started.md)** - Quick start guide
|
|
48
|
-
- **[📋 API Reference](docs/api-reference.md)** - Complete API documentation
|
|
49
|
-
- **[🔧 Middleware Guide](docs/middleware-guide.md)** - Comprehensive middleware guide
|
|
50
|
-
|
|
51
|
-
### 📈 **Learning Path**
|
|
52
|
-
- **[🟢 Beginner Level](docs/beginner/)** - Start here if you're new to Spark
|
|
53
|
-
- **[🟡 Intermediate Level](docs/intermediate/)** - Build sophisticated applications
|
|
54
|
-
- **[🔴 Expert Level](docs/expert/)** - Master advanced patterns and architecture
|
|
55
|
-
|
|
56
|
-
### 🛡️ **Production Ready**
|
|
57
|
-
- **[Security Best Practices](docs/security-best-practices.md)** - Security guidelines
|
|
58
|
-
- **[Deployment Guide](docs/deployment.md)** - Production deployment instructions
|
|
59
|
-
|
|
60
|
-
## 🔧 Core Components
|
|
61
|
-
|
|
62
|
-
### Application
|
|
63
|
-
The main Spark application class that handles server lifecycle, middleware, and routing.
|
|
64
|
-
|
|
65
|
-
### Router
|
|
66
|
-
Advanced routing system with support for parameters, middleware, and nested routes.
|
|
67
|
-
|
|
68
|
-
### Context
|
|
69
|
-
Request/response context object with helper methods for common operations.
|
|
70
|
-
|
|
71
|
-
### Middleware
|
|
72
|
-
Extensible middleware system with built-in middleware for common tasks.
|
|
73
|
-
|
|
74
|
-
## 🛠️ Built-in Middleware
|
|
75
|
-
|
|
76
|
-
- **Body Parser** - Parse JSON, form data, and text
|
|
77
|
-
- **CORS** - Cross-origin resource sharing
|
|
78
|
-
- **Session** - Session management with auto-save functionality
|
|
79
|
-
- **Security** - Security headers and protection
|
|
80
|
-
- **Rate Limiting** - Request rate limiting
|
|
81
|
-
- **Compression** - Response compression
|
|
82
|
-
- **Static Files** - Static file serving
|
|
83
|
-
- **Logger** - Request logging
|
|
84
|
-
- **Health Check** - Health monitoring endpoints
|
|
85
|
-
|
|
86
|
-
## 📊 Performance
|
|
87
|
-
|
|
88
|
-
Spark is designed for high performance with minimal overhead:
|
|
89
|
-
|
|
90
|
-
- **~4000 req/sec** on standard hardware
|
|
91
|
-
- **<1ms** average response time
|
|
92
|
-
- **<50MB** memory footprint
|
|
93
|
-
- **Zero** external dependencies
|
|
94
|
-
|
|
95
|
-
## 🏗️ Architecture
|
|
96
|
-
|
|
97
|
-
```
|
|
98
|
-
┌─────────────────┐
|
|
99
|
-
│ Application │
|
|
100
|
-
├─────────────────┤
|
|
101
|
-
│ Middleware │
|
|
102
|
-
├─────────────────┤
|
|
103
|
-
│ Router │
|
|
104
|
-
├─────────────────┤
|
|
105
|
-
│ Context │
|
|
106
|
-
├─────────────────┤
|
|
107
|
-
│ HTTP Server │
|
|
108
|
-
└─────────────────┘
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
## 🔒 Security
|
|
112
|
-
|
|
113
|
-
Spark includes built-in security features:
|
|
114
|
-
|
|
115
|
-
- CORS protection
|
|
116
|
-
- CSRF protection
|
|
117
|
-
- Rate limiting
|
|
118
|
-
- Security headers
|
|
119
|
-
- Input validation
|
|
120
|
-
- XSS protection
|
|
121
|
-
|
|
122
|
-
## 🧪 Testing
|
|
123
|
-
|
|
124
|
-
```bash
|
|
125
|
-
# Run all tests
|
|
126
|
-
npm test
|
|
127
|
-
|
|
128
|
-
# Run specific test suites
|
|
129
|
-
npm run test:unit
|
|
130
|
-
npm run test:integration
|
|
131
|
-
npm run test:examples
|
|
132
|
-
|
|
133
|
-
# Run performance benchmarks
|
|
134
|
-
npm run benchmark
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
## 📈 Examples
|
|
138
|
-
|
|
139
|
-
### Basic API
|
|
140
|
-
```javascript
|
|
141
|
-
const { Spark } = require('@oxog/spark');
|
|
142
|
-
|
|
143
|
-
const app = new Spark();
|
|
144
|
-
|
|
145
|
-
app.get('/users', (ctx) => {
|
|
146
|
-
ctx.json([
|
|
147
|
-
{ id: 1, name: 'John Doe' },
|
|
148
|
-
{ id: 2, name: 'Jane Smith' }
|
|
149
|
-
]);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
app.get('/users/:id', (ctx) => {
|
|
153
|
-
const { id } = ctx.params;
|
|
154
|
-
ctx.json({ id, name: 'User ' + id });
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
app.listen(3000);
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
### With Middleware
|
|
161
|
-
```javascript
|
|
162
|
-
const { Spark } = require('@oxog/spark');
|
|
163
|
-
|
|
164
|
-
const app = new Spark();
|
|
165
|
-
|
|
166
|
-
// Global middleware
|
|
167
|
-
app.use(require('@oxog/spark/middleware/logger')());
|
|
168
|
-
app.use(require('@oxog/spark/middleware/cors')());
|
|
169
|
-
|
|
170
|
-
// Route-specific middleware
|
|
171
|
-
app.get('/protected',
|
|
172
|
-
require('@oxog/spark/middleware/auth'),
|
|
173
|
-
(ctx) => {
|
|
174
|
-
ctx.json({ message: 'Protected route' });
|
|
175
|
-
}
|
|
176
|
-
);
|
|
177
|
-
|
|
178
|
-
app.listen(3000);
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
### E-commerce API with Sessions
|
|
182
|
-
```javascript
|
|
183
|
-
const { Spark, Router } = require('@oxog/spark');
|
|
184
|
-
|
|
185
|
-
const app = new Spark();
|
|
186
|
-
const api = new Router();
|
|
187
|
-
|
|
188
|
-
// Session middleware with auto-save
|
|
189
|
-
app.use(require('@oxog/spark/middleware/session')({
|
|
190
|
-
secret: 'your-secret-key',
|
|
191
|
-
saveUninitialized: true,
|
|
192
|
-
cookie: {
|
|
193
|
-
maxAge: 24 * 60 * 60 * 1000, // 24 hours
|
|
194
|
-
httpOnly: true,
|
|
195
|
-
secure: process.env.NODE_ENV === 'production'
|
|
196
|
-
}
|
|
197
|
-
}));
|
|
198
|
-
|
|
199
|
-
// Authentication
|
|
200
|
-
api.post('/auth/login', (ctx) => {
|
|
201
|
-
const { email, password } = ctx.body;
|
|
202
|
-
|
|
203
|
-
if (authenticate(email, password)) {
|
|
204
|
-
ctx.session.userId = user.id; // Auto-saved immediately
|
|
205
|
-
ctx.json({ success: true });
|
|
206
|
-
} else {
|
|
207
|
-
ctx.status(401).json({ error: 'Invalid credentials' });
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
// Protected routes
|
|
212
|
-
api.get('/orders', requireAuth, (ctx) => {
|
|
213
|
-
const orders = getOrdersByUser(ctx.session.userId);
|
|
214
|
-
ctx.json({ orders });
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
app.use('/api', api.routes());
|
|
218
|
-
app.listen(3000);
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
## 🤝 Contributing
|
|
222
|
-
|
|
223
|
-
Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
224
|
-
|
|
225
|
-
## 📄 License
|
|
226
|
-
|
|
227
|
-
MIT License - see the [LICENSE](LICENSE) file for details.
|
|
228
|
-
|
|
229
|
-
## 🔗 Links
|
|
230
|
-
|
|
231
|
-
- [Documentation](docs/)
|
|
232
|
-
- [Examples](examples/)
|
|
233
|
-
- [Issues](https://github.com/oxog/spark/issues)
|
|
234
|
-
- [Changelog](CHANGELOG.md)
|
|
235
|
-
|
|
236
|
-
## 🌟 Support
|
|
237
|
-
|
|
238
|
-
If you find Spark useful, please consider giving it a star on GitHub!
|
|
239
|
-
|
|
240
|
-
---
|
|
241
|
-
|
|
242
|
-
Built with ❤️ by the Spark team
|