@oxog/spark 1.1.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.
Files changed (63) hide show
  1. package/CHANGELOG.md +294 -0
  2. package/LICENSE +21 -0
  3. package/README.md +242 -0
  4. package/dist/LICENSE +21 -0
  5. package/dist/README.md +242 -0
  6. package/dist/core/application.js +957 -0
  7. package/dist/core/context.js +831 -0
  8. package/dist/core/middleware.js +218 -0
  9. package/dist/core/request.js +333 -0
  10. package/dist/core/response.js +375 -0
  11. package/dist/index.js +278 -0
  12. package/dist/middleware/body-parser.js +526 -0
  13. package/dist/middleware/cache.js +171 -0
  14. package/dist/middleware/compression.js +183 -0
  15. package/dist/middleware/cors.js +95 -0
  16. package/dist/middleware/health.js +219 -0
  17. package/dist/middleware/index.js +21 -0
  18. package/dist/middleware/logger.js +195 -0
  19. package/dist/middleware/metrics.js +328 -0
  20. package/dist/middleware/rate-limit.js +320 -0
  21. package/dist/middleware/security.js +333 -0
  22. package/dist/middleware/session.js +530 -0
  23. package/dist/middleware/static.js +299 -0
  24. package/dist/package.json +62 -0
  25. package/dist/router/layer.js +117 -0
  26. package/dist/router/route.js +123 -0
  27. package/dist/router/router.js +756 -0
  28. package/dist/types/index.d.ts +291 -0
  29. package/dist/utils/async-handler.js +145 -0
  30. package/dist/utils/cache.js +441 -0
  31. package/dist/utils/context-pool.js +83 -0
  32. package/dist/utils/error-types.js +132 -0
  33. package/dist/utils/http.js +413 -0
  34. package/dist/utils/regex-validator.js +177 -0
  35. package/package.json +89 -0
  36. package/src/core/application.js +957 -0
  37. package/src/core/context.js +831 -0
  38. package/src/core/middleware.js +218 -0
  39. package/src/core/request.js +333 -0
  40. package/src/core/response.js +375 -0
  41. package/src/index.js +278 -0
  42. package/src/middleware/body-parser.js +526 -0
  43. package/src/middleware/cache.js +171 -0
  44. package/src/middleware/compression.js +183 -0
  45. package/src/middleware/cors.js +95 -0
  46. package/src/middleware/health.js +219 -0
  47. package/src/middleware/index.js +21 -0
  48. package/src/middleware/logger.js +195 -0
  49. package/src/middleware/metrics.js +328 -0
  50. package/src/middleware/rate-limit.js +320 -0
  51. package/src/middleware/security.js +333 -0
  52. package/src/middleware/session.js +530 -0
  53. package/src/middleware/static.js +299 -0
  54. package/src/router/layer.js +117 -0
  55. package/src/router/route.js +123 -0
  56. package/src/router/router.js +756 -0
  57. package/src/utils/async-handler.js +145 -0
  58. package/src/utils/cache.js +441 -0
  59. package/src/utils/context-pool.js +83 -0
  60. package/src/utils/error-types.js +132 -0
  61. package/src/utils/http.js +413 -0
  62. package/src/utils/regex-validator.js +177 -0
  63. package/types/index.d.ts +291 -0
package/dist/README.md ADDED
@@ -0,0 +1,242 @@
1
+ # โšก Spark
2
+
3
+ A fast, lightweight, and zero-dependency Node.js web framework built for performance and simplicity.
4
+
5
+ [![npm version](https://badge.fury.io/js/@oxog/spark.svg)](https://badge.fury.io/js/@oxog/spark)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+ [![Node.js Version](https://img.shields.io/badge/node-%3E%3D14.0.0-brightgreen)](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