/**
 * Collections handler
 */ import { ManyItems , OneItem , PartialItem , QueryOne } from '../items' ; import { ITransport } from '../transport' ; import { CollectionType , DefaultType } from '../types' ; export type CollectionItem < T = DefaultType > = CollectionType & T ; export class CollectionsHandler < T = CollectionItem > { transport : ITransport ; constructor ( transport ) { this . transport = transport ; } async readOne ( collection ) { const response = await this . transport . get ( `/collections/${ collection }` ) ; return response . data as T ; } async readAll ( ) { const { data , meta } = await this . transport . get ( `/collections` ) ; return { data , meta , } ; } async createOne ( collection ) { return ( await this . transport . post < T > ( `/collections` , collection ) ) . data ; } async createMany ( collections ) { const { data , meta } = await this . transport . post ( `/collections` , collections ) ; return { data , meta , } ; } async updateOne ( collection , item , query ? ) { return ( await this . transport . patch < PartialItem < T > > ( `/collections/${ collection }` , item , { params : query , } ) ) . data ; } async deleteOne ( collection ) { await this . transport . delete ( `/collections/${ collection }` ) ; } }