Skip to content

Commit

Permalink
ensure maxAge type has milliseconds as the unit (#245)
Browse files Browse the repository at this point in the history
Co-authored-by: Chuanqi <[email protected]>
  • Loading branch information
chuanqisun and Chuanqi authored Apr 15, 2024
1 parent 8554dca commit e1a1d93
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ declare namespace fastifySession {
cookiePrefix?: string;
}

export interface CookieOptions extends Omit<CookieSerializeOptions, 'signed'> {}
export interface CookieOptions extends Omit<CookieSerializeOptions, 'signed' | 'maxAge'> {
/** A `number` in milliseconds that specifies the `Expires` attribute by adding the specified milliseconds to the current date. If both `expires` and `maxAge` are set, then `expires` is used. */
maxAge?: number;
}

export class MemoryStore implements fastifySession.SessionStore {
constructor(map?: Map<string, Fastify.Session>);
Expand Down
9 changes: 7 additions & 2 deletions types/types.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import fastify, {
Session
} from 'fastify';
import Redis from 'ioredis';
import { expectAssignable, expectError, expectType } from 'tsd';
import { MemoryStore, SessionStore, default as fastifySession, default as plugin } from '..';
import { expectAssignable, 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) {}
Expand Down Expand Up @@ -46,9 +46,14 @@ app.register(plugin, {
app.register(plugin, {
secret,
cookie: {
maxAge: 1000,
secure: 'auto'
}
});

const cookieMaxAge: CookieOptions = {};
expectDocCommentIncludes<"millisecond">(cookieMaxAge.maxAge);

app.register(plugin, {
secret,
store: new EmptyStore()
Expand Down

0 comments on commit e1a1d93

Please sign in to comment.