-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* move example into examples folder * move tests into test folder, configuration into .taprc * disable package-lock generation * add typings * remove husky in favor of pre-commit * remove new line
- Loading branch information
Showing
7 changed files
with
69 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
files: | ||
- test/**/*.test.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { FastifyPluginAsync, HTTPMethods } from "fastify"; | ||
|
||
interface Stats { | ||
mean: number; | ||
mode: number; | ||
median: number; | ||
max: number; | ||
min: number; | ||
sd: number; | ||
} | ||
|
||
declare module 'fastify' { | ||
interface FastifyInstance { | ||
stats(): Partial<Record<HTTPMethods, Record<string, Stats>>>; | ||
measurements(): Partial<Record<HTTPMethods, Record<string, Array<number>>>>; | ||
} | ||
} | ||
|
||
interface FastifyRoutesStatsOptions { | ||
/** | ||
* @default 30000 | ||
*/ | ||
printInterval?: number; | ||
} | ||
|
||
declare const fastifyRoutesStats: FastifyPluginAsync<FastifyRoutesStatsOptions> | ||
export default fastifyRoutesStats |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Fastify from 'fastify' | ||
import { expectAssignable, expectError, expectType } from 'tsd' | ||
import fastifyRoutesStats from '..' | ||
|
||
const fastify = Fastify(); | ||
|
||
fastify.register(fastifyRoutesStats, { printInterval: 1000 }) | ||
expectError(fastify.register(fastifyRoutesStats, { printInterval: 'a' })) | ||
|
||
expectAssignable<Function>(fastify.measurements) | ||
expectAssignable<Function>(fastify.stats) | ||
|
||
fastify.get('/stats', function (req, reply) { | ||
expectAssignable<Function>(this.measurements) | ||
expectAssignable<Function>(this.stats) | ||
}) | ||
|
||
expectType<Array<number>>(fastify.measurements().GET!['test']) | ||
expectAssignable<Record<string, {}> | undefined>(fastify.stats().GET) | ||
expectType<number>(fastify.stats().GET!['/'].max) | ||
expectType<number>(fastify.stats().GET!['/'].mean) | ||
expectType<number>(fastify.stats().GET!['/'].median) | ||
expectType<number>(fastify.stats().GET!['/'].min) | ||
expectType<number>(fastify.stats().GET!['/'].mode) | ||
expectType<number>(fastify.stats().GET!['/'].sd) |