mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-02 06:29:40 +08:00
delete package.json
This commit is contained in:
@@ -1,83 +0,0 @@
|
||||
// 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: 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<Model> | 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<RegistrationOptions> & SchwiftyExtras;
|
||||
|
||||
export const plugin: Plugin<RegistrationOptions>;
|
||||
|
||||
//export = Schwifty;
|
||||
|
||||
/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
|
||||
+ Hapi Decorations +
|
||||
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
|
||||
|
||||
/**
|
||||
* Merge decorations into hapi objects.
|
||||
*/
|
||||
declare module "hapi" {
|
||||
interface Server {
|
||||
schwifty: (
|
||||
config:
|
||||
| Model
|
||||
| Array<Model>
|
||||
| {
|
||||
knex: Knex | Knex.Config;
|
||||
models: Array<Model>;
|
||||
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 };
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"objection": "^1.1.8"
|
||||
}
|
||||
}
|
||||
@@ -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" });
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user