Skip to content

Commit 05f1920

Browse files
committed
fix: enforce MongoStore constructor asserts (plan#runtime)
1 parent 81c301d commit 05f1920

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

docs/PLANS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
- Type safety is paper-thin: option hooks (serialize, transformId, crypto) stay typed as any and defaultSerializeFunction is littered with @ts-ignore (src/lib/MongoStore.ts:61-124). Once you enable the stricter compiler flags below, refactor this class into generics (MongoStore<T extends SessionData>) so public
3030
types match reality.
3131
- [done 2025-11-16] Improve type safety with generics/typed hooks (agent: Codex)
32+
- Replace console.assert with real assertions: current guards in the constructor use import { assert } from 'console', which only logs and does not throw, so bad options still proceed and fail later. Switch to node:assert/strict to enforce required inputs. src/lib/MongoStore.ts:1,200-214
33+
- [done 2025-11-19] Replace console.assert with node:assert/strict and add tests for missing mongoUrl/client options (agent: Codex)
3234

3335
- Tooling & CI
3436
- Tighten the compiler and target modern runtimes: tsconfig.json still emits ES2018/CommonJS, disables strictFunctionTypes, noImplicitAny, and noUnused*, and forces inline source maps that bloat npm tarballs (tsconfig.json:2-44). Move to target: es2022, enable the strict diagnostics, emit external .map files, and

src/lib/MongoStore.spec.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,33 @@ test.afterEach.always(async () => {
2727

2828
test.serial('create store w/o provide required options', (t) => {
2929
t.throws(() => MongoStore.create({}), {
30-
message: /Cannot init client/,
30+
message: /You must provide either mongoUrl\|clientPromise\|client/,
3131
})
3232
})
3333

34+
test.serial(
35+
'create store with explicit undefined clientPromise still errors',
36+
(t) => {
37+
t.throws(
38+
() =>
39+
MongoStore.create({
40+
clientPromise: undefined as unknown as Promise<MongoClient>,
41+
}),
42+
{ message: /You must provide either mongoUrl\|clientPromise\|client/ }
43+
)
44+
}
45+
)
46+
47+
test.serial('create store with explicit undefined client still errors', (t) => {
48+
t.throws(
49+
() =>
50+
MongoStore.create({
51+
client: undefined as unknown as MongoClient,
52+
}),
53+
{ message: /You must provide either mongoUrl\|clientPromise\|client/ }
54+
)
55+
})
56+
3457
test.serial('create store with clientPromise', async (t) => {
3558
const clientP = MongoClient.connect('mongodb://root:example@127.0.0.1:27017')
3659
const store = MongoStore.create({ clientPromise: clientP })

src/lib/MongoStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assert } from 'console'
1+
import assert from 'node:assert/strict'
22
import util from 'util'
33
import * as session from 'express-session'
44
import {

0 commit comments

Comments
 (0)