UNPKG

@codenameryuu/adonis-datatable

Version:
32 lines (31 loc) 1.06 kB
import { Exception } from "@adonisjs/core/exceptions"; import LucidDataTable from "./engines/lucid_datatable.js"; import DatabaseDataTable from "./engines/database_datatable.js"; import ObjectDataTable from "./engines/object_datatable.js"; export class Datatables { engines; constructor(engines) { this.engines = engines; } of(...source) { for (const engine of Object.values(this.engines)) { const canCreate = engine.canCreate; if (typeof canCreate === "function" && canCreate.apply(engine, source)) { const create = engine.create; if (typeof create === "function") { return create.apply(engine, source); } } } throw new Exception("No available engine run"); } static lucid(source) { return LucidDataTable.create(source); } static database(source) { return DatabaseDataTable.create(source); } static object(source) { return ObjectDataTable.create(source); } }