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

build(deps-dev): replace standard with neostandard #157

Merged
merged 2 commits into from
Dec 8, 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
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![CI](https://github.com/fastify/fastify-caching/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/fastify-caching/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/@fastify/caching.svg?style=flat)](https://www.npmjs.com/package/@fastify/caching)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)

*@fastify/caching* is a plugin for the [Fastify](http://fastify.dev/) framework
that provides server-side caching and mechanisms for manipulating HTTP cache headers according to
Expand Down
6 changes: 6 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict'

module.exports = require('neostandard')({
ignores: require('neostandard').resolveIgnoresFromGitignore(),
ts: true
})
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"type": "commonjs",
"types": "types/index.d.ts",
"scripts": {
"lint": "standard --verbose | snazzy",
"lint:fix": "standard --verbose --fix | snazzy",
"lint": "eslint",
"lint:fix": "eslint --fix",
"test": "npm run test:unit && npm run test:typescript",
"test:typescript": "tsd",
"test:unit": "c8 --100 node --test",
Expand Down Expand Up @@ -38,8 +38,7 @@
"@types/node": "^22.0.0",
"c8": "^10.1.2",
"fastify": "^5.0.0",
"snazzy": "^9.0.0",
"standard": "^17.1.0",
"neostandard": "^0.11.9",
"tsd": "^0.31.0"
},
"dependencies": {
Expand Down
14 changes: 7 additions & 7 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types='node' />

import { FastifyPluginCallback } from 'fastify';
import { FastifyPluginCallback } from 'fastify'

declare module 'fastify' {
interface FastifyInstance {
Expand Down Expand Up @@ -33,13 +33,13 @@ declare module 'fastify' {

type FastifyCaching = FastifyPluginCallback<fastifyCaching.FastifyCachingPluginOptions> & {
privacy: fastifyCaching.Privacy;
};
}

type CacheResult<T> = {
item: T,
stored: number,
ttl: number,
} | null;
} | null

declare namespace fastifyCaching {
/**
Expand Down Expand Up @@ -130,11 +130,11 @@ declare namespace fastifyCaching {
serverExpiresIn?: number;
}

export const privacy: Privacy;
export const privacy: Privacy

export const fastifyCaching: FastifyCaching;
export { fastifyCaching as default };
export const fastifyCaching: FastifyCaching
export { fastifyCaching as default }
}

declare function fastifyCaching(...params: Parameters<FastifyCaching>): ReturnType<FastifyCaching>
declare function fastifyCaching (...params: Parameters<FastifyCaching>): ReturnType<FastifyCaching>
export = fastifyCaching
60 changes: 30 additions & 30 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
import Fastify, { FastifyReply } from 'fastify';
import { expectAssignable, expectError, expectType } from 'tsd';
import Fastify, { FastifyReply } from 'fastify'
import { expectAssignable, expectError, expectType } from 'tsd'
import fastifyCaching, {
AbstractCacheCompliantObject,
FastifyCachingPluginOptions,
} from '..';
} from '..'

const fastify = Fastify({ logger: true });
const fastify = Fastify({ logger: true })

const cachingOptions: FastifyCachingPluginOptions = {
privacy: fastifyCaching.privacy.PUBLIC,
expiresIn: 300,
cacheSegment: 'fastify-caching',
};
expectAssignable<FastifyCachingPluginOptions>(cachingOptions);
}
expectAssignable<FastifyCachingPluginOptions>(cachingOptions)

fastify.register(fastifyCaching, cachingOptions);
fastify.register(fastifyCaching, cachingOptions)

expectType<AbstractCacheCompliantObject>(fastify.cache);
expectType<AbstractCacheCompliantObject['get']>(fastify.cache.get);
expectType<AbstractCacheCompliantObject['set']>(fastify.cache.set);
expectType<string>(fastify.cacheSegment);
expectType<AbstractCacheCompliantObject>(fastify.cache)
expectType<AbstractCacheCompliantObject['get']>(fastify.cache.get)
expectType<AbstractCacheCompliantObject['set']>(fastify.cache.set)
expectType<string>(fastify.cacheSegment)
// expectType<number>(fastify.etagMaxLife);

fastify.get('/one', async (request, reply) => {
expectType<(tag?: string, timeToLive?: number) => FastifyReply>(reply.etag);
expectType<(date?: Date) => FastifyReply>(reply.expires);
expectType<(tag?: string, timeToLive?: number) => FastifyReply>(reply.etag)
expectType<(date?: Date) => FastifyReply>(reply.expires)

expectType<FastifyReply>(reply.etag('hello', 6000));
expectType<FastifyReply>(reply.expires(new Date(Date.now() + 6000)));
expectType<FastifyReply>(reply.etag('hello', 6000))
expectType<FastifyReply>(reply.expires(new Date(Date.now() + 6000)))

return { message: 'one' };
});
return { message: 'one' }
})

fastify.get('/two', async (request, reply) => {
expectType<FastifyReply>(
reply.etag('hello', 6000).expires(new Date(Date.now() + 6000))
);
)

return { message: 'two' };
});
return { message: 'two' }
})

// We register a new instance that should trigger a typescript error.
const shouldErrorApp = Fastify({ logger: true });
const shouldErrorApp = Fastify({ logger: true })

const badCachingOptions = {
privacy: fastifyCaching.privacy.PRIVATE,
expiresIn: 'a string instead of a number of second',
cacheSegment: 'fastify-caching',
};
}

expectError(shouldErrorApp.register(fastifyCaching, badCachingOptions));
expectError(shouldErrorApp.register(fastifyCaching, badCachingOptions))

fastify.get('/three', async (request, reply) => {
expectAssignable<Promise<unknown>>(
fastify.cache.get('well-known')
);
)
expectAssignable<Promise<{ item: string; stored: number; ttl: number; } | null>>(
fastify.cache.get<string>('well-known')
);
)
expectType<void>(
fastify.cache.get<string>('well-known', (err, value) => {
expectType<unknown>(err);
expectAssignable<{ item: string; stored: number; ttl: number; } | null>(value);
expectType<unknown>(err)
expectAssignable<{ item: string; stored: number; ttl: number; } | null>(value)
})
);
)

return { message: 'two' };
});
return { message: 'two' }
})
Loading