Skip to content

Commit 1132bae

Browse files
mbalabashmcollina
authored andcommitted
Add types definition for TS integration (#55)
* Add typescript definition for plugin * Move @types/node to devDependencies * Add test for types * Add typescript check to test stage
1 parent 12b974c commit 1132bae

File tree

5 files changed

+52
-3
lines changed

5 files changed

+52
-3
lines changed

index.d.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Plugin } from 'fastify'
2+
import { Server, IncomingMessage, ServerResponse } from 'http'
3+
4+
declare const fastifyCompress: Plugin<
5+
Server,
6+
IncomingMessage,
7+
ServerResponse,
8+
{
9+
global?: boolean
10+
threshold?: number
11+
customTypes?: RegExp
12+
brotli?: NodeModule
13+
zlib?: NodeModule
14+
inflateIfDeflated?: boolean
15+
}
16+
>
17+
18+
export = fastifyCompress

package.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,22 @@
1919
"unzipper": "^0.9.11"
2020
},
2121
"devDependencies": {
22+
"@types/node": "^11.13.9",
23+
"@typescript-eslint/parser": "^1.7.0",
24+
"eslint-plugin-typescript": "^0.14.0",
2225
"fastify": "^2.0.0",
2326
"iltorb": "^2.3.0",
2427
"jsonstream": "^1.0.3",
2528
"pre-commit": "^1.2.2",
2629
"standard": "^12.0.0",
30+
"typescript": "^3.4.5",
2731
"tap": "^12.6.6"
2832
},
2933
"scripts": {
30-
"unit": "tap test.js",
31-
"test": "standard && npm run unit",
34+
"unit": "tap test/test.js",
35+
"test": "standard && npm run unit && npm run typescript",
36+
"lint:typescript": "standard --fix --parser @typescript-eslint/parser --plugin typescript test/types/*.ts",
37+
"typescript": "tsc --project ./test/types/tsconfig.json",
3238
"coverage": "npm run unit -- --cov",
3339
"coverage-report": "npm run coverage && tap --coverage-report=lcov"
3440
},

test.js renamed to test/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const JSONStream = require('jsonstream')
99
const createReadStream = fs.createReadStream
1010
const readFileSync = fs.readFileSync
1111
const Fastify = require('fastify')
12-
const compressPlugin = require('./index')
12+
const compressPlugin = require('../index')
1313

1414
test('should send a deflated data', t => {
1515
t.plan(4)

test/types/index.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as fastify from 'fastify'
2+
import * as fastifyCompress from '../..'
3+
4+
const zlib = require('zlib')
5+
const iltorb = require('iltorb')
6+
7+
const app = fastify()
8+
9+
app.register(fastifyCompress, {
10+
global: true,
11+
threshold: 10,
12+
brotli: iltorb,
13+
zlib: zlib,
14+
inflateIfDeflated: true,
15+
customTypes: /x-protobuf$/
16+
})

test/types/tsconfig.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es6",
4+
"module": "commonjs",
5+
"noEmit": true,
6+
"strict": true
7+
},
8+
"files": ["./index.ts"]
9+
}

0 commit comments

Comments
 (0)