import { Context } from '@nuxt/types/app' import { hooks } from '~/services/dataProvider/provider/hook/_import' import { DataProviderArgs } from '~/types/interfaces' class BaseProvider { protected arguments!: DataProviderArgs; protected ctx!: Context; constructor (ctx: Context, args: DataProviderArgs) { this.arguments = args this.ctx = ctx this.sortHook() } static support (args:DataProviderArgs): boolean { throw new Error('Need to be implement into static method') } async postHook () { for (const hook of hooks) { if (hook.support(this.arguments)) { await new hook().invoke(this.arguments) } } } sortHook () { hooks.sort(function (a, b) { if (a.priority > b.priority) { return 1 } if (a.priority < b.priority) { return -1 } return 0 }) } } export default BaseProvider