UNPKG

sequelize-dm

Version:

Sequelize is a promise-based Node.js ORM tool for Postgres, MySQL, MariaDB, SQLite, Microsoft SQL Server, Amazon Redshift and Snowflake’s Data Cloud. It features solid transaction support, relations, eager and lazy loading, read replication and more.

29 lines (27 loc) 813 B
/** * Utility type for a class which can be called in addion to being used as a constructor. */ interface Invokeable<Args extends any[], Instance> { (...args: Args): Instance; new (...args: Args): Instance; } /** * Wraps a constructor to not need the `new` keyword using a proxy. * Only used for data types. * * @param Class The class instance to wrap as invocable. * @returns Wrapped class instance. * @private */ export function classToInvokable<Args extends any[], Instance extends object>( Class: new (...args: Args) => Instance, ): Invokeable<Args, Instance> { return new Proxy<Invokeable<Args, Instance>>(Class as any, { apply(_target, _thisArg, args: Args) { return new Class(...args); }, construct(_target, args: Args) { return new Class(...args); }, }); }