@oxog/spark 1.2.0 → 1.3.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 +24 -0
- package/README.md +2 -2
- package/package.json +15 -8
- package/src/core/application.js +1 -1
- package/src/core/context.js +2 -2
- package/src/core/middleware.js +2 -2
- package/src/middleware/compression.js +1 -1
- package/src/middleware/logger.js +2 -2
- package/src/middleware/session.js +1 -1
- package/src/router/router.js +3 -1
- package/src/utils/regex-validator.js +1 -1
- package/src/utils/safe-json.js +2 -2
- package/types/index.d.ts +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,30 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [1.3.0] - 2026-12-02
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
- `engines.node` is now `>=18` (was `>=14.0.0`); CI already tested Node 18 and later only.
|
|
14
|
+
- `"sideEffects": false` is declared, so bundlers can drop unused exports.
|
|
15
|
+
- Errors rethrown from a caught error now carry it as `cause` (`Failed to parse URL`,
|
|
16
|
+
`Invalid redirect URL`, `Invalid regex pattern`, `Invalid JSON`, `Cannot stringify circular
|
|
17
|
+
JSON structure`); messages are unchanged.
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
- Types: `Route` is exported as a type only. It was declared as an exported class, so
|
|
21
|
+
`import { Route } from '@oxog/spark'` type-checked but failed at runtime (the class is not
|
|
22
|
+
a runtime export). Found by Are The Types Wrong.
|
|
23
|
+
|
|
24
|
+
### Internal
|
|
25
|
+
- Tooling: adopted oxog-standard (ESLint 10 with the shared typescript-eslint config, shared
|
|
26
|
+
tsconfig base, managed CI for Node 18 to 26 and Trusted Publishing release workflow,
|
|
27
|
+
packed-archive checks with publint and Are The Types Wrong). Spark stays published as its
|
|
28
|
+
CommonJS sources without a build step.
|
|
29
|
+
- Lint fixes in `src` without runtime effect: unused callback parameters renamed with a `_`
|
|
30
|
+
prefix, two dead initial values removed.
|
|
31
|
+
|
|
8
32
|
## [1.2.0] - 2026-11-30
|
|
9
33
|
|
|
10
34
|
This release includes the changes listed under 1.1.2, which was never published
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ A fast, lightweight, and zero-dependency Node.js web framework built for perform
|
|
|
4
4
|
|
|
5
5
|
[](https://badge.fury.io/js/@oxog/spark)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
|
-
[](https://nodejs.org/)
|
|
8
8
|
|
|
9
9
|
## 🚀 Features
|
|
10
10
|
|
|
@@ -22,7 +22,7 @@ A fast, lightweight, and zero-dependency Node.js web framework built for perform
|
|
|
22
22
|
|
|
23
23
|
### Prerequisites
|
|
24
24
|
|
|
25
|
-
- Node.js >=
|
|
25
|
+
- Node.js >= 18
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
28
|
npm install @oxog/spark
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxog/spark",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Zero-dependency Node.js web framework with routing, middleware, body parsing, sessions, CORS, CSRF, rate limiting and security headers",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -19,14 +19,15 @@
|
|
|
19
19
|
"LICENSE",
|
|
20
20
|
"CHANGELOG.md"
|
|
21
21
|
],
|
|
22
|
+
"sideEffects": false,
|
|
22
23
|
"engines": {
|
|
23
|
-
"node": ">=
|
|
24
|
+
"node": ">=18"
|
|
24
25
|
},
|
|
25
26
|
"scripts": {
|
|
26
27
|
"test": "vitest run",
|
|
27
28
|
"test:watch": "vitest",
|
|
28
29
|
"test:coverage": "vitest run --coverage",
|
|
29
|
-
"lint": "eslint src tests
|
|
30
|
+
"lint": "eslint src tests --max-warnings=0",
|
|
30
31
|
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
|
|
31
32
|
"build": "node -e \"require('./src/index.js')\"",
|
|
32
33
|
"test:package": "node scripts/check-package.mjs",
|
|
@@ -71,13 +72,19 @@
|
|
|
71
72
|
},
|
|
72
73
|
"homepage": "https://github.com/ersinkoc/Spark#readme",
|
|
73
74
|
"devDependencies": {
|
|
74
|
-
"@
|
|
75
|
+
"@arethetypeswrong/cli": "^0.18.5",
|
|
76
|
+
"@eslint/js": "^10.0.0",
|
|
75
77
|
"@types/node": "^20.19.43",
|
|
76
|
-
"@vitest/coverage-v8": "^
|
|
77
|
-
"eslint": "^
|
|
78
|
-
"globals": "^
|
|
78
|
+
"@vitest/coverage-v8": "^4.1.12",
|
|
79
|
+
"eslint": "^10.0.0",
|
|
80
|
+
"globals": "^17.0.0",
|
|
81
|
+
"publint": "^0.3.25",
|
|
79
82
|
"typescript": "^5.9.3",
|
|
83
|
+
"typescript-eslint": "^8.74.0",
|
|
80
84
|
"vite": "^6.4.6",
|
|
81
|
-
"vitest": "^
|
|
85
|
+
"vitest": "^4.1.12"
|
|
86
|
+
},
|
|
87
|
+
"oxog": {
|
|
88
|
+
"sourcePublishedReason": "Spark is published as its CommonJS sources (src/*.js, no build step) with hand-written types/index.d.ts; ESM consumers use Node's CommonJS named-export detection. A tsup ESM+CJS build would need the sources rewritten as ESM (esbuild cannot derive named ESM exports from CommonJS)."
|
|
82
89
|
}
|
|
83
90
|
}
|
package/src/core/application.js
CHANGED
package/src/core/context.js
CHANGED
|
@@ -171,7 +171,7 @@ class Context {
|
|
|
171
171
|
this.path = '/';
|
|
172
172
|
this.statusCode = 400;
|
|
173
173
|
this.body = { error: 'Invalid URL format' };
|
|
174
|
-
throw new Error(`Failed to parse URL: ${error.message}
|
|
174
|
+
throw new Error(`Failed to parse URL: ${error.message}`, { cause: error });
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
/**
|
|
@@ -501,7 +501,7 @@ class Context {
|
|
|
501
501
|
try {
|
|
502
502
|
target = new URL(url, `http://${placeholderHost}`);
|
|
503
503
|
} catch (error) {
|
|
504
|
-
throw new Error(`Invalid redirect URL: ${error.message}
|
|
504
|
+
throw new Error(`Invalid redirect URL: ${error.message}`, { cause: error });
|
|
505
505
|
}
|
|
506
506
|
|
|
507
507
|
if (target.hostname !== placeholderHost) {
|
package/src/core/middleware.js
CHANGED
|
@@ -10,7 +10,7 @@ const rateLimit = require('../middleware/rate-limit');
|
|
|
10
10
|
const security = require('../middleware/security');
|
|
11
11
|
const logger = require('../middleware/logger');
|
|
12
12
|
|
|
13
|
-
function createMiddleware(
|
|
13
|
+
function createMiddleware(_app) {
|
|
14
14
|
return {
|
|
15
15
|
bodyParser: (options) => bodyParser(options),
|
|
16
16
|
cors: (options) => cors(options),
|
|
@@ -190,7 +190,7 @@ function createMiddleware(app) {
|
|
|
190
190
|
};
|
|
191
191
|
},
|
|
192
192
|
|
|
193
|
-
etag: (
|
|
193
|
+
etag: (_options = {}) => {
|
|
194
194
|
const crypto = require('crypto');
|
|
195
195
|
|
|
196
196
|
return async (ctx, next) => {
|
|
@@ -79,7 +79,7 @@ async function compressResponse(body, opts, originalSend) {
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
function shouldCompress(ctx,
|
|
82
|
+
function shouldCompress(ctx, _body) {
|
|
83
83
|
// The response Content-Type (not the request's) decides compressibility
|
|
84
84
|
const contentType = ctx.getHeader('content-type');
|
|
85
85
|
|
package/src/middleware/logger.js
CHANGED
|
@@ -133,7 +133,7 @@ function devLogger(options = {}) {
|
|
|
133
133
|
};
|
|
134
134
|
|
|
135
135
|
return logger({
|
|
136
|
-
format: (tokens,
|
|
136
|
+
format: (tokens, _ctx) => {
|
|
137
137
|
const method = colorMethod(tokens.method);
|
|
138
138
|
const status = colorStatus(tokens.status);
|
|
139
139
|
const url = tokens.url;
|
|
@@ -167,7 +167,7 @@ function requestLogger(options = {}) {
|
|
|
167
167
|
|
|
168
168
|
function structuredLogger(options = {}) {
|
|
169
169
|
const opts = {
|
|
170
|
-
format: (tokens,
|
|
170
|
+
format: (tokens, _ctx) => {
|
|
171
171
|
const logData = {
|
|
172
172
|
timestamp: new Date().toISOString(),
|
|
173
173
|
method: tokens.method,
|
|
@@ -129,7 +129,7 @@ function session(options = {}) {
|
|
|
129
129
|
const sessionId = getSessionId(ctx, opts);
|
|
130
130
|
let session = null;
|
|
131
131
|
let isNew = false;
|
|
132
|
-
let finalSessionId
|
|
132
|
+
let finalSessionId;
|
|
133
133
|
|
|
134
134
|
if (sessionId) {
|
|
135
135
|
session = await opts.store.get(sessionId);
|
package/src/router/router.js
CHANGED
|
@@ -141,7 +141,7 @@ class Router {
|
|
|
141
141
|
*/
|
|
142
142
|
use(pathOrMiddleware, ...middlewares) {
|
|
143
143
|
let path = '/';
|
|
144
|
-
let handlers
|
|
144
|
+
let handlers;
|
|
145
145
|
|
|
146
146
|
if (typeof pathOrMiddleware === 'string') {
|
|
147
147
|
path = pathOrMiddleware;
|
|
@@ -648,6 +648,7 @@ class Router {
|
|
|
648
648
|
* app.use('/api', router.routes());
|
|
649
649
|
*/
|
|
650
650
|
routes() {
|
|
651
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias -- the returned middleware is a plain named function, as in 1.x
|
|
651
652
|
const router = this;
|
|
652
653
|
return function routerMiddleware(ctx, next) {
|
|
653
654
|
return router.handle(ctx, next);
|
|
@@ -659,6 +660,7 @@ class Router {
|
|
|
659
660
|
* @returns {Function} Middleware function
|
|
660
661
|
*/
|
|
661
662
|
middleware(prefix) {
|
|
663
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias -- the returned middleware is a plain named function, as in 1.x
|
|
662
664
|
const router = this;
|
|
663
665
|
let normalized = prefix ? (prefix.startsWith('/') ? prefix : `/${prefix}`) : '';
|
|
664
666
|
while (normalized.length > 1 && normalized.endsWith('/')) {
|
package/src/utils/safe-json.js
CHANGED
|
@@ -72,7 +72,7 @@ function safeJSONParse(text, options = {}) {
|
|
|
72
72
|
try {
|
|
73
73
|
return options.reviver ? JSON.parse(text, options.reviver) : JSON.parse(text);
|
|
74
74
|
} catch (error) {
|
|
75
|
-
throw new Error(`Invalid JSON: ${error.message}
|
|
75
|
+
throw new Error(`Invalid JSON: ${error.message}`, { cause: error });
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
@@ -98,7 +98,7 @@ function safeJSONStringify(value, options = {}) {
|
|
|
98
98
|
} catch (error) {
|
|
99
99
|
// Handle circular references
|
|
100
100
|
if (error.message && error.message.includes('circular')) {
|
|
101
|
-
throw new Error('Cannot stringify circular JSON structure');
|
|
101
|
+
throw new Error('Cannot stringify circular JSON structure', { cause: error });
|
|
102
102
|
}
|
|
103
103
|
throw error;
|
|
104
104
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -184,7 +184,8 @@ export interface RouterOptions {
|
|
|
184
184
|
strict?: boolean;
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
|
|
187
|
+
/** Returned by `Router#route()`. The class is not exported at runtime, so it is exported as a type only. */
|
|
188
|
+
declare class Route {
|
|
188
189
|
constructor(path: string);
|
|
189
190
|
path: string;
|
|
190
191
|
get(...handlers: Middleware[]): this;
|
|
@@ -196,6 +197,7 @@ export declare class Route {
|
|
|
196
197
|
options(...handlers: Middleware[]): this;
|
|
197
198
|
all(...handlers: Middleware[]): this;
|
|
198
199
|
}
|
|
200
|
+
export type { Route };
|
|
199
201
|
|
|
200
202
|
type RouteRegistrar<T> = (path: string | RegExp | Array<string | RegExp>, ...handlers: Middleware[]) => T;
|
|
201
203
|
|