5.0.6 • Published 6 months ago

@types/schwifty v5.0.6

Weekly downloads
314
License
MIT
Repository
github
Last release
6 months ago

Installation

npm install --save @types/schwifty

Summary

This package contains type definitions for schwifty (https://github.com/hapipal/schwifty).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/schwifty.

index.d.ts

// Type definitions for schwifty 5.0
// Project: https://github.com/hapipal/schwifty
// Definitions by: ozum <https://github.com/ozum>
//                 timcosta <https://github.com/timcosta>
// 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/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;
    static field(name: string): Joi.Schema;
    static joiSchema: Joi.Schema;
}

export interface RegistrationOptions {
    knex?: Knex | Knex.Config | undefined;
    models?: ModelClass[] | string | undefined;
    migrationsDir?: string | undefined;
    teardownOnStop?: boolean | undefined;
    migrateOnStart?: boolean | "latest" | "rollback" | undefined;
}

export function assertCompatible(
    ModelA: typeof Model,
    ModelB: typeof Model,
    message?: string
): void | Error;

export const plugin: Plugin<RegistrationOptions>;

export interface RegisteredModels {
    [key: string]: ModelClass;
}

/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 +                      Hapi Decorations                                     +
 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */

/**
 * Merge decorations into hapi objects.
 */
declare module "@hapi/hapi" {
    interface Server {
        schwifty: (
            config:
                | ModelClass
                | ModelClass[]
                | {
                      knex: Knex | Knex.Config;
                      models: ModelClass[];
                      migrationsDir: string;
                  }
        ) => void;
        knex: () => Knex;
        models: (all?: boolean) => RegisteredModels;
    }

    interface Request {
        knex: () => Knex;
        models: (all?: boolean) => RegisteredModels;
    }

    interface ResponseToolkit {
        knex: () => Knex;
        models: (all?: boolean) => RegisteredModels;
    }
}

Additional Details

Credits

These definitions were written by ozum, and timcosta.

5.0.6

6 months ago

5.0.5

6 months ago

5.0.4

7 months ago

5.0.3

8 months ago

5.0.2

1 year ago

5.0.1

3 years ago

5.0.0

3 years ago

4.0.4

3 years ago

4.0.3

5 years ago

4.0.2

5 years ago

4.0.1

6 years ago

4.0.0

6 years ago