import { Flow, FlowResponse } from '@/models' import { FlowsFilter, FlowsPaginationFilter } from '@/models/Filters' import { Paginated } from '@/models/pagination' import { BatchProcessor } from '@/services/BatchProcessor' import { mapper } from '@/services/Mapper' import { WorkspaceApi } from '@/services/WorkspaceApi' import { toMap } from '@/utilities' export class WorkspaceFlowsApi extends WorkspaceApi { protected override routePrefix = '/flows' private readonly batcher = new BatchProcessor(async ids => { if (ids.length === 1) { const [id] = ids const { data } = await this.get(`${id}`) return () => mapper.map('FlowResponse', data, 'Flow') } const flows = await this.getFlows({ flows: { id: ids, }, }) return toMap(flows, 'id') }, { maxBatchSize: 200 }) public getFlow(flowId: string): Promise { return this.batcher.batch(flowId) } public async getFlows(filter: FlowsFilter = {}): Promise { const request = mapper.map('FlowsFilter', filter, 'FlowsFilterRequest') const { data } = await this.post('filter', request) return mapper.map('FlowResponse', data, 'Flow') } public async getFlowsPaginated(filter: FlowsPaginationFilter = {}): Promise> { const request = mapper.map('FlowsPaginationFilter', filter, 'FlowsPaginationFilterRequest') const { data } = await this.post>('/paginate', request) return mapper.map('FlowsPaginationResponse', data, 'FlowsPagination') } public async getFlowsCount(filter: FlowsFilter = {}): Promise { const request = mapper.map('FlowsFilter', filter, 'FlowsFilterRequest') const { data } = await this.post('count', request) return data } public deleteFlow(flowId: string): Promise { return this.delete(`/${flowId}`) } }