DefinitelyTyped/types/schwifty/index.d.ts
Ozum Eldogan 3a19d3f7c9 update TypeScript version (#40093)
knex which is a dependency of this module, requires TypeScript 3 and above.
2019-11-05 09:04:43 -08:00

71 lines
2.1 KiB
TypeScript

// Type definitions for schwifty 4.0
// Project: https://github.com/hapipal/schwifty
// Definitions by: ozum <https://github.com/ozum>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
// HELP NEEDED: 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 } from "hapi";
import * as Knex from "knex";
export type ModelClass = typeof Model | typeof Objection.Model;
export class Model extends Objection.Model {
static getJoiSchema(patch?: boolean): Joi.Schema;
joiSchema: Joi.Schema;
}
export interface RegistrationOptions {
knex?: Knex | Knex.Config;
models?: ModelClass[] | string;
migrationsDir?: string;
teardownOnStop?: boolean;
migrateOnStart?: boolean | "latest" | "rollback";
}
export function assertCompatible(
ModelA: typeof Model,
ModelB: typeof Model,
message?: string
): void | Error;
export const plugin: Plugin<RegistrationOptions>;
/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Hapi Decorations +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
/**
* Merge decorations into hapi objects.
*/
declare module "hapi" {
interface Server {
schwifty: (
config:
| ModelClass
| ModelClass[]
| {
knex: Knex | Knex.Config;
models: ModelClass[];
migrationsDir: string;
}
) => void;
knex: () => Knex;
models: (all?: boolean) => { [key: string]: typeof Model };
}
interface Request {
knex: () => Knex;
models: (all?: boolean) => { [key: string]: typeof Model };
}
interface ResponseToolkit {
knex: () => Knex;
models: (all?: boolean) => { [key: string]: typeof Model };
}
}