Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure maxAge type has milliseconds as the unit #245

Merged
merged 1 commit into from
Apr 15, 2024
Merged
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
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