Refactor apriori.ts