Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type FastifySession = FastifyPluginCallback<fastifySession.FastifySessionOptions
}

type Callback = (err?: any) => void
type CallbackSession = (err: any, result?: Fastify.Session | null) => void
type CallbackSession = (err?: any, result?: Fastify.Session | null) => void

interface ExpressSessionData {
/** The cookie properties as defined by express-session */
Expand Down
30 changes: 30 additions & 0 deletions types/index.tst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,32 @@ class EmptyStore {
destroy (_sessionId: string, _callback: Function) {}
}

const customTypedStore: SessionStore = {
set (_sessionStoreId, _session, callback) {
callback()
},
get (_sessionStoreId, callback) {
callback()
callback(null)
callback(null, null)
callback(null, undefined)
callback(new Error('failed'))
callback(new Error('failed'), null)
callback(null, {
cookie: {
originalMaxAge: null
},
foo: 'bar'
})
},
compareAndSet (_sessionStoreId, _expectedGeneration, _session, callback) {
callback()
},
destroy (_sessionStoreId, callback) {
callback()
}
}

declare module 'fastify' {
interface Session {
user?: {
Expand Down Expand Up @@ -68,6 +94,10 @@ app.register(plugin, {
secret,
store: new EmptyStore() as any
})
app.register(plugin, {
secret,
store: customTypedStore
})
expect(app.register).type.not.toBeCallableWith(plugin, {
secret,
store: new RedisStore({ client: createClient() })
Expand Down
Loading