diff --git a/README.md b/README.md
index d7cb5cf..ec53cef 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
[](https://github.com/fastify/session/actions/workflows/ci.yml)
[](https://www.npmjs.com/package/@fastify/session)
-[](https://standardjs.com/)
+[](https://github.com/neostandard/neostandard)
A session plugin for [fastify](http://fastify.dev/).
Requires the [@fastify/cookie](https://github.com/fastify/fastify-cookie) plugin.
diff --git a/eslint.config.js b/eslint.config.js
new file mode 100644
index 0000000..89fd678
--- /dev/null
+++ b/eslint.config.js
@@ -0,0 +1,6 @@
+'use strict'
+
+module.exports = require('neostandard')({
+ ignores: require('neostandard').resolveIgnoresFromGitignore(),
+ ts: true
+})
diff --git a/package.json b/package.json
index 5b1cba1..80d1ac3 100644
--- a/package.json
+++ b/package.json
@@ -9,8 +9,8 @@
"test:unit": "c8 --100 node --test",
"test:typescript": "tsd",
"benchmark": "node benchmark/bench.js",
- "lint": "standard lib/* test/* benchmark/*.js",
- "lint:fix": "standard --fix"
+ "lint": "eslint",
+ "lint:fix": "eslint --fix"
},
"keywords": [
"session",
@@ -40,8 +40,8 @@
"cronometro": "^4.0.0",
"fastify": "^5.0.0",
"ioredis": "^5.3.2",
+ "neostandard": "^0.11.9",
"session-file-store": "^1.5.0",
- "standard": "^17.1.0",
"tsd": "^0.31.0"
},
"types": "types/types.d.ts",
diff --git a/types/types.d.ts b/types/types.d.ts
index 5d4a6ee..cead17e 100644
--- a/types/types.d.ts
+++ b/types/types.d.ts
@@ -1,8 +1,8 @@
///
-import type * as Fastify from 'fastify';
-import { FastifyPluginCallback } from 'fastify';
-import { CookieSerializeOptions } from "@fastify/cookie"
+import type * as Fastify from 'fastify'
+import { FastifyPluginCallback } from 'fastify'
+import { CookieSerializeOptions } from '@fastify/cookie'
declare module 'fastify' {
interface FastifyInstance {
@@ -26,8 +26,8 @@ type FastifySession = FastifyPluginCallback void;
-type CallbackSession = (err: any, result?: Fastify.Session | null) => void;
+type Callback = (err?: any) => void
+type CallbackSession = (err: any, result?: Fastify.Session | null) => void
interface ExpressSessionData {
/** The cookie properties as defined by express-session */
@@ -180,25 +180,24 @@ declare namespace fastifySession {
}
export class MemoryStore implements fastifySession.SessionStore {
- constructor(map?: Map);
- set(
+ constructor (map?: Map)
+ set (
sessionId: string,
session: Fastify.Session,
callback: Callback
- ): void;
- get(
+ ): void
+ get (
sessionId: string,
callback: CallbackSession
- ): void;
- destroy(sessionId: string, callback: Callback): void;
+ ): void
+ destroy (sessionId: string, callback: Callback): void
}
- export const Store: MemoryStore;
+ export const Store: MemoryStore
export const fastifySession: FastifySession
export { fastifySession as default }
}
-declare function fastifySession(...params: Parameters): ReturnType
+declare function fastifySession (...params: Parameters): ReturnType
export = fastifySession
-
diff --git a/types/types.test-d.ts b/types/types.test-d.ts
index d2e77c4..8f5e7ec 100644
--- a/types/types.test-d.ts
+++ b/types/types.test-d.ts
@@ -1,21 +1,21 @@
-import MongoStore from 'connect-mongo';
-import RedisStore from 'connect-redis';
+import MongoStore from 'connect-mongo'
+import RedisStore from 'connect-redis'
import fastify, {
FastifyInstance,
FastifyReply,
FastifyRequest,
Session
-} from 'fastify';
-import Redis from 'ioredis';
-import { expectAssignable, expectNotAssignable, expectDocCommentIncludes, expectError, expectType } from 'tsd';
-import { CookieOptions, MemoryStore, SessionStore, default as fastifySession, default as plugin } from '..';
+} from 'fastify'
+import Redis from 'ioredis'
+import { expectAssignable, expectNotAssignable, expectDocCommentIncludes, expectError, expectType } from 'tsd'
+import { CookieOptions, MemoryStore, SessionStore, default as fastifySession, default as plugin } from '..'
class EmptyStore {
- set(_sessionId: string, _session: any, _callback: Function) {}
+ set (_sessionId: string, _session: any, _callback: Function) {}
- get(_sessionId: string, _callback: Function) {}
+ get (_sessionId: string, _callback: Function) {}
- destroy(_sessionId: string, _callback: Function) {}
+ destroy (_sessionId: string, _callback: Function) {}
}
declare module 'fastify' {
@@ -30,104 +30,104 @@ declare module 'fastify' {
expectType(plugin.Store)
expectType(plugin.MemoryStore)
-const secret = 'ABCDEFGHIJKLNMOPQRSTUVWXYZ012345';
+const secret = 'ABCDEFGHIJKLNMOPQRSTUVWXYZ012345'
-const app: FastifyInstance = fastify();
-app.register(plugin);
-app.register(plugin, { secret: 'DizIzSecret' });
-app.register(plugin, { secret: 'DizIzSecret', rolling: true });
+const app: FastifyInstance = fastify()
+app.register(plugin, { secret: 'DizIzSecret' })
+app.register(plugin, { secret: 'DizIzSecret', rolling: true })
app.register(plugin, {
secret,
rolling: false,
cookie: {
secure: false
}
-});
+})
app.register(plugin, {
secret,
cookie: {
maxAge: 1000,
secure: 'auto'
}
-});
+})
-const cookieMaxAge: CookieOptions = {};
-expectDocCommentIncludes<"millisecond">(cookieMaxAge.maxAge);
+const cookieMaxAge: CookieOptions = {}
+expectDocCommentIncludes<'millisecond'>(cookieMaxAge.maxAge)
app.register(plugin, {
secret,
store: new EmptyStore()
-});
+})
app.register(plugin, {
secret,
store: new RedisStore({ client: new Redis() })
-});
+})
app.register(plugin, {
secret,
- store: MongoStore.create({ mongoUrl: 'mongodb://connection-string'})
-});
+ store: MongoStore.create({ mongoUrl: 'mongodb://connection-string' })
+})
app.register(plugin, {
secret,
store: new MemoryStore(new Map())
-});
+})
app.register(plugin, {
secret,
idGenerator: () => Date.now() + ''
-});
+})
app.register(plugin, {
secret,
-});
+})
app.register(plugin, {
secret,
- idGenerator: (request) => `${request == undefined ? 'null' : request.ip}-${Date.now()}`
-});
+ idGenerator: (request) => `${request === undefined ? 'null' : request.ip}-${Date.now()}`
+})
-expectError(app.register(plugin, {}));
+expectError(app.register(plugin))
+expectError(app.register(plugin, {}))
expectError(app.decryptSession('sessionId', {}, () => ({})))
-app.decryptSession<{hello: 'world'}>('sessionId', { hello: 'world' }, () => ({}))
-app.decryptSession<{hello: 'world'}>('sessionId', { hello: 'world' }, { domain: '/' }, () => ({}))
+app.decryptSession<{ hello: 'world' }>('sessionId', { hello: 'world' }, () => ({}))
+app.decryptSession<{ hello: 'world' }>('sessionId', { hello: 'world' }, { domain: '/' }, () => ({}))
app.decryptSession('sessionId', {}, () => ({}))
app.decryptSession('sessionId', {}, { domain: '/' }, () => ({}))
app.route({
method: 'GET',
url: '/',
- preHandler(req, _rep, next) {
- expectType(req.session.destroy(next));
- expectType>(req.session.destroy());
+ preHandler (req, _rep, next) {
+ expectType(req.session.destroy(next))
+ expectType>(req.session.destroy())
},
- async handler(request, reply) {
- expectType(request);
- expectType(reply);
- expectType>(request.sessionStore);
- expectError((request.sessionStore = null));
- expectError(request.session.doesNotExist());
- expectType<{ id: number } | undefined>(request.session.user);
- request.sessionStore.set('session-set-test', request.session, () => {});
+ async handler (request, reply) {
+ expectType(request)
+ expectType(reply)
+ expectType>(request.sessionStore)
+ expectError((request.sessionStore = null))
+ expectError(request.session.doesNotExist())
+ expectType<{ id: number } | undefined>(request.session.user)
+ request.sessionStore.set('session-set-test', request.session, () => {})
request.sessionStore.get('', (err, session) => {
- const store = new MemoryStore();
- if (session) store.set('session-set-test', session, () => {});
- expectType(err);
- expectType(session);
- expectType<{ id: number } | undefined>(session?.user);
- });
- expectType(request.session.set('foo', 'bar'));
- expectType(request.session.get('foo'));
- expectType(request.session.touch());
- expectType(request.session.isModified());
- expectType(request.session.reload(() => {}));
- expectType(request.session.destroy(() => {}));
- expectType(request.session.regenerate(() => {}));
- expectType(request.session.regenerate(['foo'], () => {}));
- expectType(request.session.save(() => {}));
- expectType>(request.session.reload());
- expectType>(request.session.destroy());
- expectType>(request.session.regenerate());
- expectType>(request.session.regenerate(['foo']));
- expectType>(request.session.save());
+ const store = new MemoryStore()
+ if (session) store.set('session-set-test', session, () => {})
+ expectType(err)
+ expectType(session)
+ expectType<{ id: number } | undefined>(session?.user)
+ })
+ expectType(request.session.set('foo', 'bar'))
+ expectType(request.session.get('foo'))
+ expectType(request.session.touch())
+ expectType(request.session.isModified())
+ expectType(request.session.reload(() => {}))
+ expectType(request.session.destroy(() => {}))
+ expectType(request.session.regenerate(() => {}))
+ expectType(request.session.regenerate(['foo'], () => {}))
+ expectType(request.session.save(() => {}))
+ expectType>(request.session.reload())
+ expectType>(request.session.destroy())
+ expectType>(request.session.regenerate())
+ expectType>(request.session.regenerate(['foo']))
+ expectType>(request.session.save())
}
-});
+})
const customSigner = {
sign: (value: string) => value,
@@ -136,19 +136,19 @@ const customSigner = {
renew: false,
value: null
})
-};
+}
-app.register(plugin, { secret: customSigner });
+app.register(plugin, { secret: customSigner })
const app2 = fastify()
-app2.register(fastifySession)
+app2.register(fastifySession, { secret: 'DizIzSecret' })
-app2.get('/', async function(request) {
- expectAssignable(request.session.get('foo'));
- expectNotAssignable(request.session.get('foo'));
+app2.get('/', async function (request) {
+ expectAssignable(request.session.get('foo'))
+ expectNotAssignable(request.session.get('foo'))
- expectType(request.session.set('foo', 'bar'));
- expectError(request.session.set('foo', 2));
+ expectType(request.session.set('foo', 'bar'))
+ expectError(request.session.set('foo', 2))
expectType(request.session.get('user'))
expectAssignable(request.session.set('user', { id: 2 }))