dchester / epilogue

Create flexible REST endpoints and controllers from Sequelize models in your Express app
846 stars 116 forks source link

Typescript support? #216

Open devuxer opened 7 years ago

devuxer commented 7 years ago

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 commented 7 years ago

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 commented 6 years ago

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 commented 6 years ago

@linktohack , Looks great! Thanks!

linktohack commented 6 years ago

Pull request added, please discuss the rest there https://github.com/dchester/epilogue/pull/218