Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript support? #216

Open
devuxer opened this issue Jul 9, 2017 · 4 comments
Open

Typescript support? #216

devuxer opened this issue Jul 9, 2017 · 4 comments

Comments

@devuxer
Copy link

devuxer commented Jul 9, 2017

Just wondering if anyone has created typescript typings for this project. I was surprised such a popular library didn't have a @types/epilogue package on npm.

@devuxer
Copy link
Author

devuxer commented Aug 1, 2017

I had a little time today to create a typescript declaration (d.ts file) for epilogue. I'm not savvy enough yet to know how to turn this into a proper @types/epilogue NPM package, but I thought I'd post what I have for the moment in case it helps others:

declare module "epilogue" {
    import { Express } from "express";
    import { Sequelize } from "sequelize-typescript";

    function initialize(options: initializeOptions): void;
    function resource(options: resourceOptions): void;

    interface initializeOptions {
        app: Express;
        sequelize: Sequelize;
        base?: string;
        updateMethod?: "POST" | "PUT" | "PATCH";
    }

    interface resourceOptions {
        app?: Express;
        sequelize?: Sequelize;
        model: any;
        endpoints?: string[];
        actions?: Array<"create" | "read" | "update" | "delete" | "list">;
        include?: any[];
        pagination?: boolean;
        updateMethod?: "POST" | "PUT" | "PATCH";
        search?: searchOptions | searchOptions[];
        sort?: sortOptions;
        reloadInstances?: boolean;
        associations?: boolean;
        excludeAttributes?: string[];
        readOnlyAttributes?: string[];
    }

    interface searchOptions {
        operator: "$like" | "$ilike" | "$iLike" | "$notLike" | "$notILike" | "$ne" | "$eq" | "$not" | "$gte" | "$gt" | "$lte" | "$lt";
        param: string;
        attributes: string[];
    }

    interface sortOptions {
        param: string;
        attributes: string[];
        default: string;
    }
}

@linktohack
Copy link

I have copied @devuxer's work and create a more sophisticated version here:
https://gist.github.com/linktohack/e4178333565b70f6e0c18581a6b0a063
If it's okay I'd like to contribute back to epilogue (create a typing section) rather than create a new @typespackage.

@devuxer
Copy link
Author

devuxer commented Sep 25, 2017

@linktohack , Looks great! Thanks!

@linktohack
Copy link

Pull request added, please discuss the rest there #218

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants