diff --git a/src/stores/file.ts b/src/stores/file.ts index e085c70..1364398 100644 --- a/src/stores/file.ts +++ b/src/stores/file.ts @@ -19,11 +19,16 @@ import type { FileStoreConfig, SessionData, SessionStoreContract } from '../type /** * File store writes the session data on the file system as. Each session * id gets its own file. + * */ export class FileStore implements SessionStoreContract { #config: FileStoreConfig #age: string | number + /** + * @param {FileStoreConfig} config + * @param {string|number} The age must be in seconds or a time expression + */ constructor(config: FileStoreConfig, age: string | number) { this.#config = config this.#age = age @@ -95,7 +100,7 @@ export class FileStore implements SessionStoreContract { /** * Check if the file has been expired and return null (if expired) */ - const sessionWillExpireAt = stats.mtimeMs + string.milliseconds.parse(this.#age) + const sessionWillExpireAt = stats.mtimeMs + (string.seconds.parse(this.#age) * 1000) if (Date.now() > sessionWillExpireAt) { debug('file store: expired session data %s', sessionId) return null diff --git a/tests/stores/file_store.spec.ts b/tests/stores/file_store.spec.ts index e9a44ca..7a1dc8b 100644 --- a/tests/stores/file_store.spec.ts +++ b/tests/stores/file_store.spec.ts @@ -76,7 +76,7 @@ test.group('File store', () => { test('return null when session data is expired', async ({ assert, fs }) => { const sessionId = '1234' - const session = new FileStore({ location: fs.basePath }, 1000) + const session = new FileStore({ location: fs.basePath }, 1) await session.write(sessionId, { message: 'hello-world' }) await setTimeout(2000)