diff --git a/types/schwifty/index.d.1.ts b/types/schwifty/index.d.1.ts deleted file mode 100644 index 0580e5e1fb..0000000000 --- a/types/schwifty/index.d.1.ts +++ /dev/null @@ -1,83 +0,0 @@ -// Type definitions for schwifty 4.0. -// Project: https://github.com/hapipal/schwifty -// Definitions by: ozum -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.4 - -// HELP WANTED: If possible, find a better way to define Server.models, Request.models and ResponseToolkit.models -// They are dynamic types extended from SchwiftyModel. - -import * as Objection from "objection"; -import * as Joi from "joi"; -import { - Server, - Request, - ResponseToolkit, - Plugin, - ServerRegisterPluginObject -} from "hapi"; -import * as Knex from "knex"; - -type Model = typeof SchwiftyModel | typeof Objection.Model; - -declare class SchwiftyModel extends Objection.Model { - static getJoiSchema(patch?: boolean): Joi.Schema; - joiSchema: Joi.Schema; -} - -interface RegistrationOptions { - knex?: Knex | Knex.Config; - models?: Array | string; - migrationsDir?: string; - teardownOnStop?: boolean; - migrateOnStart?: boolean | "latest" | "rollback"; -} - -interface SchwiftyExtras { - assertCompatible: ( - ModelA: typeof SchwiftyModel, - ModelB: typeof SchwiftyModel, - message?: string - ) => void | Error; - Model: typeof SchwiftyModel; -} - -declare const Schwifty: Plugin & SchwiftyExtras; - -export const plugin: Plugin; - -//export = Schwifty; - -/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + Hapi Decorations + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */ - -/** - * Merge decorations into hapi objects. - */ -declare module "hapi" { - interface Server { - schwifty: ( - config: - | Model - | Array - | { - knex: Knex | Knex.Config; - models: Array; - migrationsDir: string; - } - ) => void; - knex: () => Knex; - models: (all?: boolean) => { [key: string]: typeof SchwiftyModel }; - } - - interface Request { - knex: () => Knex; - models: (all?: boolean) => { [key: string]: typeof SchwiftyModel }; - } - - interface ResponseToolkit { - knex: () => Knex; - models: (all?: boolean) => { [key: string]: typeof SchwiftyModel }; - } -} diff --git a/types/schwifty/package.json b/types/schwifty/package.json deleted file mode 100644 index 37b2fc1558..0000000000 --- a/types/schwifty/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "private": true, - "dependencies": { - "objection": "^1.1.8" - } -} diff --git a/types/schwifty/schwifty-tests.ts b/types/schwifty/schwifty-tests.ts index afdcda5441..39d06c6f09 100644 --- a/types/schwifty/schwifty-tests.ts +++ b/types/schwifty/schwifty-tests.ts @@ -1,7 +1,7 @@ import * as Hapi from "hapi"; import * as Joi from "joi"; import * as Schwifty from "schwifty"; -import DogClass from "./test/dog"; +import DogModel from "./test/dog"; (async () => { const server = new Hapi.Server({ port: 3000 }); @@ -20,13 +20,13 @@ import DogClass from "./test/dog"; } }); - Schwifty.assertCompatible(DogClass, DogClass); + Schwifty.assertCompatible(DogModel, DogModel); // Register a model with schwifty... - server.schwifty(DogClass); + server.schwifty(DogModel); await server.initialize(); - const Dog: typeof DogClass = server.models().Dog; + const Dog: typeof DogModel = server.models().Dog; await Dog.query().insert({ name: "Guinness" }); diff --git a/types/schwifty/test/plugin.ts b/types/schwifty/test/plugin.ts index 0b3e9b189b..e2523f7161 100644 --- a/types/schwifty/test/plugin.ts +++ b/types/schwifty/test/plugin.ts @@ -5,7 +5,7 @@ import DogModel from "./dog"; exports.plugin = { register: async ( server: Hapi.Server, - options: { Model: Schwifty.Model } + options: { Model: typeof Schwifty.Model } ) => { await server.register(Schwifty); diff --git a/types/schwifty/tsconfig.json b/types/schwifty/tsconfig.json index ff73409893..d7117c5fd2 100644 --- a/types/schwifty/tsconfig.json +++ b/types/schwifty/tsconfig.json @@ -13,5 +13,10 @@ "target": "es6", "strictFunctionTypes": true }, - "files": ["index.d.ts", "schwifty-tests.ts"] + "files": [ + "index.d.ts", + "schwifty-tests.ts", + "test/dog.ts", + "test/plugin.ts" + ] }