Skip to content

Added TypeScript declarations, fix README #11

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -21,7 +21,7 @@ npm i fastify-http-context
Next, set up the plugin:

```js
const { fastifyHttpContextPlugin } = fastify-http-context
const { fastifyHttpContextPlugin } = require('fastify-http-context');
const fastify = require('fastify');

fastify.register(fastifyHttpContextPlugin, { defaults: user: { id: 'system' } };
Expand Down
33 changes: 33 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { FastifyRequest, FastifyReply, Plugin } from "fastify";
import { IncomingMessage, Server, ServerResponse } from "http";

export type HttpContext = {
get: <T>(key: string) => T | undefined;
set: <T>(key: string, value: T) => void;
};

export type Hook =
| "onRequest"
| "preParsing"
| "preValidation"
| "preHandler"
| "preSerialization"
| "onError"
| "onSend"
| "onResponse";

export type HttpContextOptions = {
defaults?: Record<string, any>;
hook?: Hook;
};

declare const fastifyHttpContextPlugin: Plugin<
Server,
IncomingMessage,
ServerResponse,
HttpContextOptions
>;

declare const httpContext: HttpContext;

export { fastifyHttpContextPlugin, httpContext };
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
"version": "2.0.0",
"description": "Simulates a thread of execution to allow for true session context to take place per api call within the fastify lifecycle of calls.",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"test": "nyc mocha test/**/*.js",
"benchmark": "concurrently -k -s first \"node ./examples/baseline.js\" \"sleep 10 && autocannon -c 100 -d 5 -p 10 localhost:3000/\""
},
"files": [
"index.js",
"index.d.ts",
"async-local-storage.js"
],
"repository": {
Expand Down