diff --git a/types/hapi-auth-basic/hapi-auth-basic-tests.ts b/types/hapi-auth-basic/hapi-auth-basic-tests.ts index 1a7192af6f..875a53c104 100644 --- a/types/hapi-auth-basic/hapi-auth-basic-tests.ts +++ b/types/hapi-auth-basic/hapi-auth-basic-tests.ts @@ -2,9 +2,9 @@ import Bcrypt = require('bcrypt'); import Basic = require('hapi-auth-basic'); -import * as Hapi from 'hapi'; +import { Server } from 'hapi'; -const server = new Hapi.Server(); +const server = new Server(); interface User { username: string; diff --git a/types/hapi-auth-basic/index.d.ts b/types/hapi-auth-basic/index.d.ts index ddf05c348a..b738935862 100644 --- a/types/hapi-auth-basic/index.d.ts +++ b/types/hapi-auth-basic/index.d.ts @@ -5,7 +5,7 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.4 -import * as Hapi from 'hapi'; +import { Plugin, Request, ResponseToolkit } from 'hapi'; declare namespace Basic { interface ValidateCustomResponse { @@ -18,10 +18,10 @@ declare namespace Basic { } interface Validate { - (request: Hapi.Request, username: string, password: string, h: object): Promise; + (request: Request, username: string, password: string, h: ResponseToolkit): Promise; } } -declare var Basic: Hapi.PluginFunction<{}>; +declare var Basic: Plugin<{}>; export = Basic; diff --git a/types/hapi-auth-basic/tsconfig.json b/types/hapi-auth-basic/tsconfig.json index 9d6132482f..191d992f70 100644 --- a/types/hapi-auth-basic/tsconfig.json +++ b/types/hapi-auth-basic/tsconfig.json @@ -16,9 +16,6 @@ "paths": { "boom": [ "boom/v4" - ], - "hapi": [ - "hapi/v16" ] }, "noEmit": true, @@ -28,4 +25,4 @@ "index.d.ts", "hapi-auth-basic-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/nes/index.d.ts b/types/nes/index.d.ts index c4d26ecda0..27b9d84dd1 100644 --- a/types/nes/index.d.ts +++ b/types/nes/index.d.ts @@ -23,17 +23,19 @@ * failing test demonstrating use if so. */ -import * as Hapi from 'hapi'; +import { Plugin } from 'hapi'; import NesClient = require('nes/client'); -declare module 'hapi' { +declare module 'hapi/definitions/server/server' { interface Server { broadcast(message: any, options?: nes.ServerBroadcastOptions): void; subscription(path: string, options?: nes.ServerSubscriptionOptions): void; publish(path: string, message: any, options?: nes.ServerPublishOptions): void; eachSocket(each: (socket: nes.Socket) => void, options?: nes.ServerEachSocketOptions): void; } +} +declare module 'hapi/definitions/request/request' { interface Request { socket: nes.Socket; } @@ -129,8 +131,6 @@ interface NesClassExports { }; } -interface NesAllExports extends NesClassExports, Hapi.PluginFunction<{}> {} - -declare var nes: NesAllExports; +declare var nes: NesClassExports & Plugin<{}>; export = nes; diff --git a/types/nes/test/broadcast-server.ts b/types/nes/test/broadcast-server.ts index 6ef8f7aafa..8af469f645 100644 --- a/types/nes/test/broadcast-server.ts +++ b/types/nes/test/broadcast-server.ts @@ -1,9 +1,9 @@ // from https://github.com/hapijs/nes#broadcast -import Hapi = require('hapi'); +import { Server } from 'hapi'; import Nes = require('nes'); -var server = new Hapi.Server(); +const server = new Server(); server.register(Nes).then(() => { diff --git a/types/nes/test/client-require.ts b/types/nes/test/client-require.ts index f5a07ea1d3..5bbc8f8370 100644 --- a/types/nes/test/client-require.ts +++ b/types/nes/test/client-require.ts @@ -5,8 +5,8 @@ import Client = require('nes/client'); -var options: Client.ClientConnectOptions = { +const options: Client.ClientConnectOptions = { delay: 3 } -var client: Client = new Client('ws://localhost', options); +const client: Client = new Client('ws://localhost', options); diff --git a/types/nes/test/nes-tests.ts b/types/nes/test/nes-tests.ts index 85cff1e208..b5557adfb9 100644 --- a/types/nes/test/nes-tests.ts +++ b/types/nes/test/nes-tests.ts @@ -1,18 +1,18 @@ -import Hapi = require('hapi'); +import { Request, ResponseToolkit, Server } from 'hapi'; import Nes = require('nes'); -var server: Hapi.Server = new Hapi.Server(); +const server = new Server(); server.register(Nes).then(() => { // No longer need to cast to Nes.Server as Hapi.Server has been modified directly. // let wsServer: Nes.Server = server as Nes.Server; - let wsServer: Hapi.Server = server; + let wsServer = server; wsServer.subscription('/item/{id}'); - wsServer.route( { + wsServer.route({ method: 'GET', path: '/test', config: { - handler: (request, h) => { + handler: (request: Request, h: ResponseToolkit) => { return {test: 'passes ' + request.socket.id}; } } diff --git a/types/nes/test/route-authentication-server.ts b/types/nes/test/route-authentication-server.ts index 2080f04ef4..6aab8cf53e 100644 --- a/types/nes/test/route-authentication-server.ts +++ b/types/nes/test/route-authentication-server.ts @@ -1,12 +1,18 @@ // from https://github.com/hapijs/nes#route-authentication -import Hapi = require('hapi'); +import { AuthCredentials, Request, ResponseToolkit, Server } from 'hapi'; import Basic = require('hapi-auth-basic'); import Bcrypt = require('bcrypt'); import Nes = require('nes'); -var server = new Hapi.Server(); -server.connection(); +const server = new Server(); + +declare module 'hapi/definitions/request/request-auth' { + interface AuthCredentials { + id: string; + name: string; + } +} server.register([Basic, Nes]).then(() => { @@ -19,7 +25,7 @@ server.register([Basic, Nes]).then(() => { id: string; } - var users: {[index: string]: User} = { + const users: { [index: string]: User } = { john: { username: 'john', password: '$2a$10$iqJSHD.BGr0E2IxQwYgJmeP3NvhPrXAeLSaGCj6IR/XU5QtjVu5Tm', // 'secret' @@ -28,9 +34,9 @@ server.register([Basic, Nes]).then(() => { } }; - var validate: Basic.Validate = async (request, username, password, h) => { + const validate: Basic.Validate = async (request, username, password, h) => { - var user = users[username]; + const user = users[username]; if (!user) { return { credentials: null, isValid: false }; } @@ -40,7 +46,7 @@ server.register([Basic, Nes]).then(() => { return { isValid, credentials: { id: user.id, name: user.name } }; }; - server.auth.strategy('simple', 'basic', { validateFunc: validate }); + server.auth.strategy('simple', 'basic', {validateFunc: validate}); server.auth.default('simple'); // Configure route with authentication @@ -50,7 +56,7 @@ server.register([Basic, Nes]).then(() => { path: '/h', config: { id: 'hello', - handler: function (request, h) { + handler: function (request: Request, h: ResponseToolkit) { return 'Hello ' + request.auth.credentials.name; } diff --git a/types/nes/test/route-invocation-server.ts b/types/nes/test/route-invocation-server.ts index d6893495c9..eb0ec4bf87 100644 --- a/types/nes/test/route-invocation-server.ts +++ b/types/nes/test/route-invocation-server.ts @@ -1,9 +1,9 @@ // from https://github.com/hapijs/nes#route-invocation -import Hapi = require('hapi'); +import { Request, ResponseToolkit, Server } from 'hapi'; import Nes = require('nes'); -var server = new Hapi.Server(); +const server = new Server(); server.register(Nes).then(() => { @@ -12,7 +12,7 @@ server.register(Nes).then(() => { path: '/h', config: { id: 'hello', - handler: (request, h) => { + handler: (request: Request, h: ResponseToolkit) => { return 'world!'; } diff --git a/types/nes/test/subscription-filter-client.ts b/types/nes/test/subscription-filter-client.ts index 05253539a4..95193be6c8 100644 --- a/types/nes/test/subscription-filter-client.ts +++ b/types/nes/test/subscription-filter-client.ts @@ -8,7 +8,7 @@ var client = new Nes.Client('ws://localhost'); client.connect({ auth: { headers: { authorization: 'Basic am9objpzZWNyZXQ=' } } }).then(() => { - var handler: Nes.Handler = (update) => { + const handler: Nes.Handler = (update) => { // First publish is not received (filtered due to updater key) // update -> { id: 6, status: 'initial', updater: 'steve' } @@ -27,7 +27,7 @@ var client = new NesClient('ws://localhost'); client.connect({ auth: { headers: { authorization: 'Basic am9objpzZWNyZXQ=' } } }).then(() => { - var handler: NesClient.Handler = (update) => { + const handler: NesClient.Handler = (update) => { // First publish is not received (filtered due to updater key) // update -> { id: 6, status: 'initial', updater: 'steve' } diff --git a/types/nes/test/subscription-filter-server.ts b/types/nes/test/subscription-filter-server.ts index 7a63abf151..acc124227e 100644 --- a/types/nes/test/subscription-filter-server.ts +++ b/types/nes/test/subscription-filter-server.ts @@ -1,11 +1,11 @@ // from https://github.com/hapijs/nes#subscription-filter -import Hapi = require('hapi'); +import {Server} from 'hapi'; import Basic = require('hapi-auth-basic'); import Bcrypt = require('bcrypt'); import Nes = require('nes'); -var server = new Hapi.Server(); +var server = new Server(); server.register([Basic, Nes]).then(() => { @@ -18,7 +18,7 @@ server.register([Basic, Nes]).then(() => { id: string; } - var users: {[index: string]: User} = { + const users: {[index: string]: User} = { john: { username: 'john', password: '$2a$10$iqJSHD.BGr0E2IxQwYgJmeP3NvhPrXAeLSaGCj6IR/XU5QtjVu5Tm', // 'secret' @@ -27,9 +27,9 @@ server.register([Basic, Nes]).then(() => { } }; - var validate: Basic.Validate = async (request, username, password, h) => { + const validate: Basic.Validate = async (request, username, password, h) => { - var user = users[username]; + const user = users[username]; if (!user) { return { credentials: null, isValid: false }; } diff --git a/types/nes/test/subscriptions-client.ts b/types/nes/test/subscriptions-client.ts index 9f6150f90c..0203d44ad8 100644 --- a/types/nes/test/subscriptions-client.ts +++ b/types/nes/test/subscriptions-client.ts @@ -3,9 +3,9 @@ import Nes = require('nes'); var client = new Nes.Client('ws://localhost'); - client.connect().then(() => {; +client.connect().then(() => { - var handler: Nes.Handler = (update, flags) => { + const handler: Nes.Handler = (update, flags) => { // update -> { id: 5, status: 'complete' } // Second publish is not received (doesn't match) @@ -21,7 +21,7 @@ import NesClient = require('nes/client'); var client = new NesClient('ws://localhost'); client.connect().then(() => { - var handler: NesClient.Handler = (update, flags) => { + const handler: NesClient.Handler = (update, flags) => { // update -> { id: 5, status: 'complete' } // Second publish is not received (doesn't match) diff --git a/types/nes/test/subscriptions-server.ts b/types/nes/test/subscriptions-server.ts index 1280f2afd1..390bd50c63 100644 --- a/types/nes/test/subscriptions-server.ts +++ b/types/nes/test/subscriptions-server.ts @@ -1,11 +1,11 @@ // from https://github.com/hapijs/nes#subscriptions -import Hapi = require('hapi'); +import { Server } from 'hapi'; import Nes = require('nes'); -var server = new Hapi.Server(); +var server = new Server(); -server.register(Nes).then(() =>{; +server.register(Nes).then(() => { server.subscription('/item/{id}'); diff --git a/types/nes/tsconfig.json b/types/nes/tsconfig.json index dc39b99fed..05fc49c647 100644 --- a/types/nes/tsconfig.json +++ b/types/nes/tsconfig.json @@ -16,9 +16,6 @@ "paths": { "boom": [ "boom/v4" - ], - "hapi": [ - "hapi/v16" ] }, "noEmit": true, @@ -41,4 +38,4 @@ "test/subscriptions-client.ts", "test/subscriptions-server.ts" ] -} \ No newline at end of file +}