31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
import { SeguimientoTablaResponse, SeguimientoValor } from '../seguimiento-tabla.service';
|
|
|
|
/** Largest number of rows each format accepts. A query above the limit is refused, never truncated. */
|
|
export const EXPORT_LIMITS = { xlsx: 5000, pdf: 1000 } as const;
|
|
export type ExportFormat = keyof typeof EXPORT_LIMITS;
|
|
|
|
export type TrackingRow = Record<string, SeguimientoValor>;
|
|
|
|
/** Everything one export needs: the first answer (columns, filters, window) and all the rows it announced. */
|
|
export interface TrackingSnapshot {
|
|
corte: string;
|
|
ventana: SeguimientoTablaResponse['ventana'];
|
|
filtros: SeguimientoTablaResponse['filtros'];
|
|
filtros_disponibles: SeguimientoTablaResponse['filtros_disponibles'];
|
|
columnas: SeguimientoTablaResponse['columnas'];
|
|
items: TrackingRow[];
|
|
}
|
|
|
|
export type TrackingExportEvent =
|
|
| { kind: 'progress'; fetched: number; total: number }
|
|
| { kind: 'done'; snapshot: TrackingSnapshot };
|
|
|
|
export class ExportLimitExceeded extends Error {
|
|
constructor(readonly total: number, readonly limit: number) {
|
|
super(`The query has ${total} rows and the limit is ${limit}`);
|
|
}
|
|
}
|
|
|
|
/** The pages did not describe one stable list (the total changed, a page repeated or a row was lost). */
|
|
export class ExportInconsistent extends Error {}
|