Skip to content

Commit

Permalink
add typings for decryptSession (fastify#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak authored Sep 7, 2022
1 parent 8155c63 commit 6324dc8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { FastifyPluginCallback } from 'fastify';
import type * as Fastify from 'fastify';

declare module 'fastify' {
interface FastifyInstance {
decryptSession<Request extends Record<string, any> = FastifyRequest>(sessionId: string, request: Request, cookieOpts: FastifySessionPlugin.CookieOptions, callback: Callback): void;
decryptSession<Request extends Record<string, any> = FastifyRequest>(sessionId: string, request: Request, callback: Callback): void;
}

interface FastifyRequest {
/** Allows to access or modify the session data. */
session: Fastify.Session;
Expand Down
6 changes: 6 additions & 0 deletions types/types.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ app.register(plugin, {

expectError(app.register(plugin, {}));

expectError(app.decryptSession<string>('sessionId', {}, () => ({})))
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: '/',
Expand Down

0 comments on commit 6324dc8

Please sign in to comment.