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

types: merge duplicate FastifyCookieOptions interface exports #318

Merged
merged 2 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 2 additions & 8 deletions types/plugin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,6 @@ declare namespace fastifyCookie {

type HookType = 'onRequest' | 'preParsing' | 'preValidation' | 'preHandler' | 'preSerialization'

export interface FastifyCookieOptions {
secret?: string | string[] | Buffer | Buffer[] | Signer;
hook?: HookType | false;
parseOptions?: fastifyCookie.CookieSerializeOptions;
}

export type Sign = (value: string, secret: string | Buffer, algorithm?: string) => string
export type Unsign = (input: string, secret: string | Buffer, algorithm?: string) => UnsignResult
export type SignerFactory = (secrets: string | string[] | Buffer | Buffer[], algorithm?: string) => SignerBase
Expand Down Expand Up @@ -179,10 +173,10 @@ declare namespace fastifyCookie {
}

export const fastifyCookie: FastifyCookie

export interface FastifyCookieOptions {
Fdawgs marked this conversation as resolved.
Show resolved Hide resolved
secret?: string | string[] | Buffer | Buffer[] | SignerBase;
secret?: string | string[] | Buffer | Buffer[] | Signer | SignerBase;
algorithm?: string;
hook?: HookType | false;
parseOptions?: CookieSerializeOptions;
}

Expand Down
17 changes: 8 additions & 9 deletions types/plugin.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import cookie from '..'
import { expectError, expectType } from 'tsd'
import * as fastifyCookieStar from '..'
import fastifyCookieCjsImport = require('..')
import fastifyCookieDefault, { fastifyCookie as fastifyCookieNamed, Signer } from '..'
import cookie, { fastifyCookie as fastifyCookieNamed, Signer } from '..'
import fastify, { FastifyInstance, FastifyReply, setCookieWrapper } from 'fastify'

const fastifyCookieCjs = require('..')

const app: FastifyInstance = fastify()
app.register(fastifyCookieNamed)
app.register(fastifyCookieDefault)
app.register(cookie)
app.register(fastifyCookieCjs)
app.register(fastifyCookieCjsImport.default)
app.register(fastifyCookieCjsImport.fastifyCookie)
app.register(fastifyCookieStar.default)
app.register(fastifyCookieStar.fastifyCookie)

expectType<fastifyCookieStar.FastifyCookie>(fastifyCookieNamed)
expectType<fastifyCookieStar.FastifyCookie>(fastifyCookieDefault)
expectType<fastifyCookieStar.FastifyCookie>(cookie)
expectType<fastifyCookieStar.FastifyCookie>(fastifyCookieCjsImport.default)
expectType<fastifyCookieStar.FastifyCookie>(fastifyCookieCjsImport.fastifyCookie)
expectType<fastifyCookieStar.FastifyCookie>(fastifyCookieStar.default)
Expand All @@ -26,9 +25,9 @@ expectType<fastifyCookieStar.FastifyCookie>(
)
expectType<any>(fastifyCookieCjs)

expectType<fastifyCookieStar.Sign>(fastifyCookieDefault.sign)
expectType<fastifyCookieStar.Unsign>(fastifyCookieDefault.unsign)
expectType<fastifyCookieStar.SignerFactory >(fastifyCookieDefault.signerFactory)
expectType<fastifyCookieStar.Sign>(cookie.sign)
expectType<fastifyCookieStar.Unsign>(cookie.unsign)
expectType<fastifyCookieStar.SignerFactory >(cookie.signerFactory)

expectType<fastifyCookieStar.Sign>(fastifyCookieNamed.sign)
expectType<fastifyCookieStar.Unsign>(fastifyCookieNamed.unsign)
Expand Down Expand Up @@ -246,5 +245,5 @@ appWithHook.register(cookie, { hook: 'preValidation' })
expectError(appWithHook.register(cookie, { hook: true }))
expectError(appWithHook.register(cookie, { hook: 'false' }))

expectType<(cookieHeader: string, opts?: fastifyCookieStar.ParseOptions) => { [key: string]: string }>(fastifyCookieDefault.parse)
expectType<(name: string, value: string, opts?: fastifyCookieStar.SerializeOptions) => string>(fastifyCookieDefault.serialize)
expectType<(cookieHeader: string, opts?: fastifyCookieStar.ParseOptions) => { [key: string]: string }>(cookie.parse)
expectType<(name: string, value: string, opts?: fastifyCookieStar.SerializeOptions) => string>(cookie.serialize)
Loading