import type { OrganizationSourceRecordList, OrganizationSourceRecord, OrganizationSourceRecordListResponse, V2OrganizationSourceRecordsListOrdering, } from './generated/schemas'; export function recordLabel(record: OrganizationSourceRecordList): string { if (record.source_group === 'stock_exchange_activity') { const type: 'exchange_instrument' = record.record_type; const duration: string | null | undefined = record.payload.duration?.value; const yieldValue: string | null | undefined = record.payload.yield?.value; return type + record.payload.exchange + (duration || '') + (yieldValue || ''); } if (record.source_group === 'budget_process_registry') { const type: 'budget_registry_organization' = record.record_type; return type + record.payload.registry.code; } if (record.source_group === 'government_support') { const type: 'sme_support_measure' = record.record_type; return type + record.payload.support_sizes.map((size) => size.value).join(','); } if (record.source_group === 'sro_membership') { const type: 'sro_membership' = record.record_type; return type + record.payload.sro_name; } return record.title || ''; } export function detailCount(record: OrganizationSourceRecord): number { if (record.source_group === 'budget_process_registry') return record.payload.heads.length; if (record.source_group === 'government_support') return record.payload.regulatory_documents.length; if (record.source_group === 'sro_membership') return record.payload.lineage.lookup_value.length; return 0; } export function total(response: OrganizationSourceRecordListResponse): number { return response.meta.pagination.total_count; } export const existingOrder: V2OrganizationSourceRecordsListOrdering = '-payload__united_states'; import { v2OrganizationSourceRecordsExportTicket } from './generated/client'; import type { SourceExportFileTicketRequest, SourceExportArchiveTicketRequest, OrganizationSourceRecordExportRequest } from './generated/schemas'; // All three selectors must remain callable through the actual generated function. export async function exportSelection(selector: SourceExportFileTicketRequest | SourceExportArchiveTicketRequest | OrganizationSourceRecordExportRequest): Promise { const response = await v2OrganizationSourceRecordsExportTicket(selector); if (response.status === 201) { const ticket: string = response.data.ticket; if ('selection_kind' in response.data) { const format: 'xlsx' | 'csv' | 'json' = response.data.format; const size: number | null = response.data.size_bytes; return `${ticket}:${format}:${size}`; } return ticket; } return ''; } import type { SourceExportPart, SourceExportSourceSummary } from './generated/schemas'; export function sourceExportYear(part: SourceExportPart, source: SourceExportSourceSummary): string { const year: number | null = part.year; const partitioning: 'year' | 'none' = source.partitioning; const projections: number | null = source.exported_records_count; return `${partitioning}:${year ?? 'undated'}:${projections}`; }