Skip to content

Commit

Permalink
types: merge duplicate FastifyCookieOptions interface exports
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs committed Jan 5, 2025
1 parent b9fcf13 commit 5fea048
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
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 {
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)

0 comments on commit 5fea048

Please sign in to comment.