/** * CSV Data Connector for bulk property imports * * Allows importing property data from CSV files and mapping * to IFC entities. */ import type { EntityTable } from '@ifc-lite/data'; import { PropertyValueType } from '@ifc-lite/data'; import type { MutablePropertyView } from './mutable-property-view.js'; import type { Mutation, PropertyValue } from './types.js'; import { type MutationGuard } from './mutation-guard.js'; /** * A parsed CSV row */ export interface CsvRow { [column: string]: string; } /** * Match strategy for linking CSV rows to IFC entities */ export type MatchStrategy = { type: 'globalId'; column: string; } | { type: 'expressId'; column: string; } | { type: 'name'; column: string; } | { type: 'property'; psetName: string; propName: string; column: string; }; /** * Mapping from CSV column to IFC property */ export interface PropertyMapping { /** CSV column name */ sourceColumn: string; /** Target property set name */ targetPset: string; /** Target property name */ targetProperty: string; /** Value type */ valueType: PropertyValueType; /** Optional value transformation */ transform?: (value: string) => PropertyValue; } /** * Complete data mapping configuration */ export interface DataMapping { /** How to match CSV rows to IFC entities */ matchStrategy: MatchStrategy; /** Property mappings */ propertyMappings: PropertyMapping[]; } /** * Result of matching a CSV row to entities */ export interface MatchResult { row: CsvRow; rowIndex: number; matchedEntityIds: number[]; confidence: number; warnings?: string[]; } /** * Statistics from CSV import */ export interface ImportStats { totalRows: number; matchedRows: number; unmatchedRows: number; mutationsCreated: number; errors: string[]; warnings: string[]; } /** * Progress update during async import */ export interface ImportProgress { /** Current phase of the import */ phase: 'parsing' | 'matching' | 'applying'; /** Unified progress 0–1 across all phases */ percent: number; /** Running count of mutations created */ mutationsCreated: number; /** Running count of matched rows */ matchedRows: number; /** Total rows being processed */ totalRows: number; } /** * CSV parsing options */ export interface CsvParseOptions { /** Delimiter character (default: ',') */ delimiter?: string; /** Has header row (default: true) */ hasHeader?: boolean; /** Skip empty rows (default: true) */ skipEmpty?: boolean; } /** * CSV Data Connector */ export declare class CsvConnector { private entities; private mutationView; private strings; /** See mutation-guard.ts: consulted once by `generateMutations`, opt-in. */ private canEdit; constructor(entities: EntityTable, mutationView: MutablePropertyView, strings?: { get(idx: number): string; } | null, canEdit?: MutationGuard); /** * Parse CSV content into rows */ parse(content: string, options?: CsvParseOptions): CsvRow[]; /** * Match CSV rows to IFC entities */ match(rows: CsvRow[], mapping: DataMapping): MatchResult[]; /** * Match a single row to entities */ private matchRow; /** * Generate mutations from matched data */ generateMutations(matches: MatchResult[], mapping: DataMapping): Mutation[]; /** * Import CSV data and apply to entities * * Computed name on purpose: Vite 8's dev-time import-analysis rewrites a * literal `import(` method head as a dynamic import (injecting * `__vite__injectQuery` into the parameter list), which breaks the whole * viewer dev server with a SyntaxError. The computed form is the same * public method, invisible to that rewrite. */ ['import'](content: string, mapping: DataMapping, options?: CsvParseOptions): ImportStats; /** * Async batched import that yields to the main thread between batches. * Provides live progress updates via onProgress callback. */ importAsync(content: string, mapping: DataMapping, onProgress: (progress: ImportProgress) => void, options?: CsvParseOptions & { batchSize?: number; }): Promise; /** * Preview import without applying changes */ preview(content: string, mapping: DataMapping, options?: CsvParseOptions): { rows: CsvRow[]; matches: MatchResult[]; estimatedMutations: number; }; /** * Parse a single CSV line respecting quoted values */ private parseCsvLine; /** * Parse a string value to the appropriate type */ private parseValue; /** * Auto-detect column mappings based on column names */ autoDetectMappings(headers: string[]): PropertyMapping[]; /** * Clean a string to be a valid property name */ private cleanPropertyName; } //# sourceMappingURL=csv-connector.d.ts.map