Skip to content

Commit d1a51a3

Browse files
authored
fix (types): update typescript definitions, typescript tests and harmonize directory structure (#226)
1 parent b4575de commit d1a51a3

File tree

5 files changed

+56
-41
lines changed

5 files changed

+56
-41
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Notice that in this case it is important to use the `prefix` option to tell the
7070

7171
Also notice paths in `upstream` are ignored, so you need to use `rewritePrefix` to specify the target base path.
7272

73-
For other examples, see [`example.js`](example.js).
73+
For other examples, see [`example.js`](examples/example.js).
7474

7575
## Request tracking
7676

example.js renamed to examples/example.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
const Fastify = require('fastify')
4-
const proxy = require('.')
4+
const proxy = require('..')
55

66
async function startOrigin () {
77
const origin = Fastify()

index.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
/// <reference types="node" />
1+
/// <reference types='node' />
22

3-
import { FastifyPlugin, preHandlerHookHandler } from "fastify";
3+
import { FastifyPluginCallback, preHandlerHookHandler } from 'fastify';
44

55
import {
66
FastifyReplyFromOptions,
77
FastifyReplyFromHooks,
8-
} from "fastify-reply-from";
8+
} from 'fastify-reply-from';
99

10-
import { ClientOptions, ServerOptions } from "ws";
10+
import { ClientOptions, ServerOptions } from 'ws';
1111

1212
export interface FastifyHttpProxyOptions extends FastifyReplyFromOptions {
1313
upstream: string;
@@ -25,5 +25,5 @@ export interface FastifyHttpProxyOptions extends FastifyReplyFromOptions {
2525
constraints?: { [name: string]: any };
2626
}
2727

28-
declare const fastifyHttpProxy: FastifyPlugin<FastifyHttpProxyOptions>;
28+
export const fastifyHttpProxy: FastifyPluginCallback<FastifyHttpProxyOptions>;
2929
export default fastifyHttpProxy;

package.json

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
"version": "6.2.1",
44
"description": "proxy http requests, for Fastify",
55
"main": "index.js",
6+
"types": "index.d.ts",
67
"scripts": {
7-
"lint:fix": "standard --fix",
8-
"lint:typescript": "standard --fix --parser @typescript-eslint/parser --plugin typescript test/types/*.ts",
9-
"test": "standard | snazzy && tap test/*.js && npm run typescript",
8+
"lint": "standard | snazzy",
9+
"lint:fix": "standard --fix | snazzy",
10+
"lint:typescript": "npm run lint:fix - --parser @typescript-eslint/parser --plugin typescript \"test/types/*.ts\"",
11+
"test": "npm run lint && tap \"test/*.js\" && npm run typescript",
1012
"typescript": "tsd"
1113
},
1214
"repository": {
@@ -26,33 +28,33 @@
2628
"homepage": "https://github.com/fastify/fastify-http-proxy#readme",
2729
"devDependencies": {
2830
"@fastify/pre-commit": "^2.0.2",
29-
"@types/node": "^16.0.0",
30-
"@types/ws": "^8.2.0",
31-
"@typescript-eslint/parser": "^4.0.0",
32-
"eslint-plugin-typescript": "^0.14.0",
33-
"express": "^4.16.4",
34-
"express-http-proxy": "^1.6.2",
35-
"fast-proxy": "^2.0.0",
36-
"fastify": "^3.12.0",
31+
"@types/node": "^16.11.19",
32+
"@types/ws": "^8.2.2",
33+
"@typescript-eslint/eslint-plugin": "^5.9.1",
34+
"@typescript-eslint/parser": "^5.9.1",
35+
"express": "^4.17.2",
36+
"express-http-proxy": "^1.6.3",
37+
"fast-proxy": "^2.1.0",
38+
"fastify": "^3.25.3",
3739
"fastify-websocket": "^4.0.0",
38-
"got": "^11.5.1",
39-
"http-errors": "^1.8.0",
40-
"http-proxy": "^1.17.0",
41-
"make-promises-safe": "^5.0.0",
40+
"got": "^11.8.3",
41+
"http-errors": "^2.0.0",
42+
"http-proxy": "^1.18.1",
43+
"make-promises-safe": "^5.1.0",
4244
"simple-get": "^4.0.0",
4345
"snazzy": "^9.0.0",
44-
"socket.io": "^4.0.0",
45-
"socket.io-client": "^4.0.0",
46-
"standard": "^16.0.3",
47-
"tap": "^15.0.1",
48-
"tsd": "^0.17.0",
49-
"typescript": "^4.0.2"
46+
"socket.io": "^4.4.1",
47+
"socket.io-client": "^4.4.1",
48+
"standard": "^16.0.4",
49+
"tap": "^15.1.6",
50+
"tsd": "^0.19.1",
51+
"typescript": "^4.5.4"
5052
},
5153
"dependencies": {
52-
"fastify-reply-from": "^6.0.0",
53-
"ws": "^8.0.0"
54+
"fastify-reply-from": "^6.4.1",
55+
"ws": "^8.4.2"
5456
},
5557
"tsd": {
56-
"directory": "test"
58+
"directory": "test/types"
5759
}
5860
}

test/index.test-d.ts renamed to test/types/index.test-d.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import fastify, { RawReplyDefaultExpression, RawRequestDefaultExpression } from "fastify";
2-
import fastifyHttpProxy from "..";
3-
import { expectType } from "tsd";
1+
import fastify, { RawReplyDefaultExpression, RawRequestDefaultExpression } from 'fastify';
2+
import { expectError, expectType } from 'tsd';
3+
import fastifyHttpProxy from '../..';
44

55
const app = fastify();
66

77
app.register(fastifyHttpProxy, {
8-
upstream: "http://origin.asd"
8+
upstream: 'http://origin.asd'
99
});
1010

1111
app.register(fastifyHttpProxy, {
12-
upstream: "http://origin.asd",
13-
prefix: "/auth",
14-
rewritePrefix: "/u",
12+
upstream: 'http://origin.asd',
13+
prefix: '/auth',
14+
rewritePrefix: '/u',
1515
http2: false,
1616
config: { key: 1 },
17-
replyOptions: { contentType: "application/json" },
18-
httpMethods: ["DELETE", "GET", "HEAD", "PATCH", "POST", "PUT", "OPTIONS"],
17+
replyOptions: { contentType: 'application/json' },
18+
httpMethods: ['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT', 'OPTIONS'],
1919
preHandler: (request, reply) => {
2020
expectType<RawRequestDefaultExpression>(request.raw);
2121
expectType<RawReplyDefaultExpression>(reply.raw);
@@ -26,7 +26,14 @@ app.register(fastifyHttpProxy, {
2626
},
2727
base: 'whatever',
2828
cacheURLs: 10,
29-
undici: { dummy: true }, // undici has no TS declarations yet
29+
undici: {
30+
connections: 128,
31+
pipelining: 1,
32+
keepAliveTimeout: 60 * 1000,
33+
tls: {
34+
rejectUnauthorized: false
35+
}
36+
},
3037
http: {
3138
agentOptions: {
3239
keepAliveMsecs: 10 * 60 * 1000
@@ -42,3 +49,9 @@ app.register(fastifyHttpProxy, {
4249
sessionTimeout: 30000,
4350
constraints: { version: '1.0.2' }
4451
});
52+
53+
expectError(
54+
app.register(fastifyHttpProxy, {
55+
thisOptionDoesNotExist: 'triggers a typescript error'
56+
})
57+
);

0 commit comments

Comments
 (0)