From 5fea048dc5c45b5bb2592e386e012be22f54d6e6 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 5 Jan 2025 12:00:48 +0000 Subject: [PATCH] types: merge duplicate `FastifyCookieOptions` interface exports --- types/plugin.d.ts | 10 ++-------- types/plugin.test-d.ts | 17 ++++++++--------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/types/plugin.d.ts b/types/plugin.d.ts index fdba3fb..cb928b6 100644 --- a/types/plugin.d.ts +++ b/types/plugin.d.ts @@ -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 @@ -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; } diff --git a/types/plugin.test-d.ts b/types/plugin.test-d.ts index 2532f75..f610b3e 100644 --- a/types/plugin.test-d.ts +++ b/types/plugin.test-d.ts @@ -1,15 +1,14 @@ -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) @@ -17,7 +16,7 @@ app.register(fastifyCookieStar.default) app.register(fastifyCookieStar.fastifyCookie) expectType(fastifyCookieNamed) -expectType(fastifyCookieDefault) +expectType(cookie) expectType(fastifyCookieCjsImport.default) expectType(fastifyCookieCjsImport.fastifyCookie) expectType(fastifyCookieStar.default) @@ -26,9 +25,9 @@ expectType( ) expectType(fastifyCookieCjs) -expectType(fastifyCookieDefault.sign) -expectType(fastifyCookieDefault.unsign) -expectType(fastifyCookieDefault.signerFactory) +expectType(cookie.sign) +expectType(cookie.unsign) +expectType(cookie.signerFactory) expectType(fastifyCookieNamed.sign) expectType(fastifyCookieNamed.unsign) @@ -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)