@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 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
  [![npm version](https://badge.fury.io/js/@oxog/spark.svg)](https://badge.fury.io/js/@oxog/spark)
6
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/)
7
+ [![Node.js Version](https://img.shields.io/badge/node-%3E%3D18-brightgreen)](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 >= 14.0.0
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.2.0",
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": ">=14.0.0"
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 scripts eslint.config.js vitest.config.mjs --max-warnings=0",
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
- "@eslint/js": "^9.39.5",
75
+ "@arethetypeswrong/cli": "^0.18.5",
76
+ "@eslint/js": "^10.0.0",
75
77
  "@types/node": "^20.19.43",
76
- "@vitest/coverage-v8": "^3.2.7",
77
- "eslint": "^9.39.5",
78
- "globals": "^15.15.0",
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": "^3.2.7"
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
  }
@@ -803,7 +803,7 @@ class Application extends EventEmitter {
803
803
  cluster.fork();
804
804
  }
805
805
 
806
- cluster.on('exit', (worker, code, signal) => {
806
+ cluster.on('exit', (_worker, _code, _signal) => {
807
807
  // Console.log removed for production
808
808
  cluster.fork();
809
809
  });
@@ -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) {
@@ -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(app) {
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: (options = {}) => {
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, body) {
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
 
@@ -133,7 +133,7 @@ function devLogger(options = {}) {
133
133
  };
134
134
 
135
135
  return logger({
136
- format: (tokens, ctx) => {
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, ctx) => {
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 = null;
132
+ let finalSessionId;
133
133
 
134
134
  if (sessionId) {
135
135
  session = await opts.store.get(sessionId);
@@ -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('/')) {
@@ -155,7 +155,7 @@ class SafeRegexCache {
155
155
 
156
156
  return regex;
157
157
  } catch (error) {
158
- throw new Error(`Invalid regex pattern: ${error.message}`);
158
+ throw new Error(`Invalid regex pattern: ${error.message}`, { cause: error });
159
159
  }
160
160
  }
161
161
 
@@ -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
- export declare class Route {
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