# @types/schwifty

> TypeScript definitions for schwifty

Latest version **5.0.7** (published 2025-10-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @types/schwifty
pnpm add @types/schwifty
yarn add @types/schwifty
bun add @types/schwifty
```

## Health

**Score 65/100 (B)** — status: stable.

Positive: has types; no vulnerabilities; high maintenance score; popular repo; extremely popular.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 5.0.7 |
| Published | 2025-10-24 |
| First published | 2018-05-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 7.2 KB |
| Known vulnerabilities | 0 (+3 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 51439 |
| Maintainers | types |

## Links

- npm: https://www.npmjs.com/package/@types/schwifty
- Repository: https://github.com/DefinitelyTyped/DefinitelyTyped
- Homepage: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/schwifty
- npm.io page: https://npm.io/package/@types/schwifty

## Dependencies (5)

- [joi](https://npm.io/package/joi.md) ^17.7.0
- [knex](https://npm.io/package/knex.md) ^0.16.1
- [objection](https://npm.io/package/objection.md) ^1.1.9
- [@hapi/hapi](https://npm.io/package/@hapi/hapi.md) ^21.1.0
- [@types/node](https://npm.io/package/@types/node.md) *

## Recent versions

- 5.0.7 (latest) — 2025-10-24
- 5.0.6 (ts5.0) — 2023-11-22
- 5.0.3 (ts4.8) — 2023-09-25
- 5.0.2 (ts4.3) — 2022-12-21
- 5.0.1 (ts3.6) — 2021-07-06
- 5.0.0 (ts3.5) — 2021-02-13
- 4.0.3 (ts3.0) — 2019-11-05
- 4.0.2 (ts2.9) — 2019-03-19
- 4.0.0 (ts2.4) — 2018-05-27
- 5.0.5 — 2023-11-07
- 5.0.4 — 2023-10-18
- 4.0.4 — 2021-01-14
- 4.0.1 — 2018-07-14

## README

# 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](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/schwifty/index.d.ts)
````ts
// 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 { Plugin, Request, ResponseToolkit, Server } from "@hapi/hapi";
import * as Joi from "joi";
import Knex = require("knex");
import * as Objection from "objection";

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,
    // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
): 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
 * Last updated: Fri, 24 Oct 2025 04:02:41 GMT
 * Dependencies: [@hapi/hapi](https://npmjs.com/package/@hapi/hapi), [@types/node](https://npmjs.com/package/@types/node), [joi](https://npmjs.com/package/joi), [knex](https://npmjs.com/package/knex), [objection](https://npmjs.com/package/objection)

# Credits
These definitions were written by [ozum](https://github.com/ozum), and [timcosta](https://github.com/timcosta).

---
_Source: https://npm.io/package/@types/schwifty · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
