Skip to content

Commit

Permalink
build(deps-dev): replace standard with neostandard (#179)
Browse files Browse the repository at this point in the history
* build(deps-dev): replace standard with neostandard

* chore: add eslint.config.js

* chore:rebase

* Update package.json

Signed-off-by: Frazer Smith <frazer.dev@icloud.com>

* Update lib/httpError.d.ts

Co-authored-by: Arthur Fiorette <47537704+arthurfiorette@users.noreply.github.com>
Signed-off-by: Frazer Smith <frazer.dev@icloud.com>

* Update lib/httpError.d.ts

Co-authored-by: Arthur Fiorette <47537704+arthurfiorette@users.noreply.github.com>
Signed-off-by: Frazer Smith <frazer.dev@icloud.com>

* chore: ignore

---------

Signed-off-by: Frazer Smith <frazer.dev@icloud.com>
Co-authored-by: Arthur Fiorette <47537704+arthurfiorette@users.noreply.github.com>
  • Loading branch information
Fdawgs and arthurfiorette authored Dec 17, 2024
1 parent 72c6863 commit 8329e91
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 30 deletions.
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-sensible/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/fastify-sensible/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/@fastify/sensible.svg?style=flat)](https://www.npmjs.com/package/@fastify/sensible)
[![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)

Defaults for Fastify that everyone can agree on™.<br>
This plugin adds some useful utilities to your Fastify instance, see the API section to learn more.
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
})
16 changes: 9 additions & 7 deletions lib/httpError.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
export declare class HttpError<N extends number = number> extends Error {
status: N;
statusCode: N;
expose: boolean;
status: N
statusCode: N
expose: boolean
headers?: {
[key: string]: string;
};

[key: string]: any;
}

type UnknownError = Error | string | number | { [key: string]: any };
type UnknownError = Error | string | number | { [key: string]: any }

export type HttpErrorCodes = 400 | '400' // BadRequest
| 401 | '401' // Unauthorized
Expand Down Expand Up @@ -92,13 +93,14 @@ export type HttpErrorNames = 'badRequest'
| 'loopDetected'
| 'bandwidthLimitExceeded'
| 'notExtended'
| 'networkAuthenticationRequired';
| 'networkAuthenticationRequired'

export type HttpErrors = {
HttpError: typeof HttpError;
getHttpError: (code: HttpErrorCodes, message?: string) => HttpError;
createError: (...args: UnknownError[]) => HttpError;
} & Record<HttpErrorNames, (msg?: string) => HttpError>;
} & Record<HttpErrorNames, (msg?: string) => HttpError>

// eslint-disable-next-line @typescript-eslint/no-redeclare
declare const HttpErrors: HttpErrors
export default HttpErrors;
export default HttpErrors
7 changes: 4 additions & 3 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",
"lint:fix": "standard --fix",
"lint": "eslint",
"lint:fix": "eslint --fix",
"test": "npm run test:unit && npm run test:typescript",
"test:typescript": "tsd",
"test:unit": "tap"
Expand All @@ -31,8 +31,9 @@
"devDependencies": {
"@fastify/pre-commit": "^2.1.0",
"@types/node": "^22.0.0",
"eslint": "^9.17.0",
"fastify": "^5.0.0",
"standard": "^17.1.0",
"neostandard": "^0.12.0",
"tap": "^18.7.1",
"tsd": "^0.31.0"
},
Expand Down
16 changes: 8 additions & 8 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FastifyPluginCallback, FastifyReply } from 'fastify'
import { HttpErrors, HttpError } from "../lib/httpError"
import { FastifyPluginCallback, FastifyReply } from 'fastify'
import { HttpErrors, HttpError } from '../lib/httpError'
import * as Errors from '../lib/httpError'

type FastifySensible = FastifyPluginCallback<fastifySensible.FastifySensibleOptions>
Expand All @@ -24,7 +24,7 @@ type staleTypes = 'while-revalidate' | 'if-error'

declare module 'fastify' {
namespace SensibleTypes {
type ToType<T> = [Error, T];
type ToType<T> = [Error, T]
}

interface Assert {
Expand Down Expand Up @@ -89,11 +89,11 @@ declare namespace fastifySensible {
sharedSchemaId?: string;
}

export { HttpError };
export { HttpError }

export type HttpErrors = Errors.HttpErrors;
export type HttpErrorCodes = Errors.HttpErrorCodes;
export type HttpErrorNames = Errors.HttpErrorNames;
export type HttpErrors = Errors.HttpErrors
export type HttpErrorCodes = Errors.HttpErrorCodes
export type HttpErrorNames = Errors.HttpErrorNames

export const httpErrors: typeof Errors.default

Expand All @@ -105,5 +105,5 @@ declare namespace fastifySensible {
export { fastifySensible as default }
}

declare function fastifySensible(...params: Parameters<FastifySensible>): ReturnType<FastifySensible>
declare function fastifySensible (...params: Parameters<FastifySensible>): ReturnType<FastifySensible>
export = fastifySensible
21 changes: 10 additions & 11 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const app = fastify()

app.register(fastifySensible)

expectAssignable<FastifySensibleOptions>({});
expectAssignable<FastifySensibleOptions>({ sharedSchemaId: 'HttpError' });
expectNotAssignable<FastifySensibleOptions>({ notSharedSchemaId: 'HttpError' });
expectAssignable<FastifySensibleOptions>({})
expectAssignable<FastifySensibleOptions>({ sharedSchemaId: 'HttpError' })
expectNotAssignable<FastifySensibleOptions>({ notSharedSchemaId: 'HttpError' })

app.get('/', (req, reply) => {
expectAssignable<typeof reply>(reply.badRequest())
Expand Down Expand Up @@ -60,13 +60,12 @@ app.get('/', (req, reply) => {
expectAssignable<HttpError>(app.httpErrors.createError(405, 'Method Not Allowed'))
})

app.get("/", (req, reply) => {
app.get('/', (req, reply) => {
expectAssignable<HttpError>(
app.httpErrors.createError(405, "Method Not Allowed"),
);
expectAssignable<HttpError>(app.httpErrors.badRequest());
});

app.httpErrors.createError(405, 'Method Not Allowed')
)
expectAssignable<HttpError>(app.httpErrors.badRequest())
})

app.get('/', async (req, reply) => {
expectAssignable<HttpError>(app.httpErrors.badRequest())
Expand Down Expand Up @@ -158,5 +157,5 @@ app.get('/', async (req, reply) => {
expectType<string | false | null>(req.is('foo', 'bar'))
})

httpErrors.forbidden('This type should be also available');
httpErrors.createError('MyError');
httpErrors.forbidden('This type should be also available')
httpErrors.createError('MyError')

0 comments on commit 8329e91

Please sign in to comment.