Skip to content

Commit d652f34

Browse files
committed
refactor(tables): keep CSV coercion in import switch
1 parent afa07f8 commit d652f34

4 files changed

Lines changed: 1 addition & 26 deletions

File tree

apps/sim/lib/table/column-types/extension-points.test.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,13 @@ import {
88
valueForTypeConversion,
99
wouldExceedColumnTypeLimit,
1010
} from '@/lib/table/column-types'
11-
import { coerceValue } from '@/lib/table/import'
1211
import type { ColumnDefinition } from '@/lib/table/types'
1312

1413
const definition = COLUMN_TYPE_REGISTRY.string
1514
const originalMaxPerTable = definition.maxPerTable
16-
const originalCoerceImport = definition.coerceImport
1715
const originalValueForConversion = definition.valueForConversion
1816

19-
function restoreOptionalProperty(
20-
key: 'maxPerTable' | 'coerceImport' | 'valueForConversion',
21-
value: unknown
22-
) {
17+
function restoreOptionalProperty(key: 'maxPerTable' | 'valueForConversion', value: unknown) {
2318
if (value === undefined) {
2419
Reflect.deleteProperty(definition, key)
2520
return
@@ -29,7 +24,6 @@ function restoreOptionalProperty(
2924

3025
afterEach(() => {
3126
restoreOptionalProperty('maxPerTable', originalMaxPerTable)
32-
restoreOptionalProperty('coerceImport', originalCoerceImport)
3327
restoreOptionalProperty('valueForConversion', originalValueForConversion)
3428
})
3529

@@ -82,12 +76,4 @@ describe('column type extension points', () => {
8276
)
8377
).toBeNull()
8478
})
85-
86-
it('lets a type own CSV import coercion', () => {
87-
Object.assign(definition, {
88-
coerceImport: (value: unknown) => `imported:${String(value)}`,
89-
})
90-
91-
expect(coerceValue('raw', 'string')).toBe('imported:raw')
92-
})
9379
})

apps/sim/lib/table/column-types/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export * from '@/lib/table/column-types/registry'
1414
export type {
1515
CoerceResult,
1616
ColumnCellEditor,
17-
ColumnImportCoerceOptions,
1817
ColumnType,
1918
ColumnTypeDefinition,
2019
TypeSpecificColumnKey,

apps/sim/lib/table/column-types/types.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ export type TypeSpecificColumnKey = (typeof TYPE_SPECIFIC_COLUMN_KEYS)[number]
6868
/** Result of coercing a raw value toward a column's declared type. */
6969
export type CoerceResult = { ok: true; value: JsonValue } | { ok: false }
7070

71-
export interface ColumnImportCoerceOptions extends NormalizeDateCellOptions {
72-
currencyCode?: string
73-
}
74-
7571
export interface ColumnTypeDefinition {
7672
readonly id: ColumnType
7773

@@ -170,9 +166,6 @@ export interface ColumnTypeDefinition {
170166
context?: NormalizeDateCellOptions
171167
): CoerceResult
172168

173-
/** CSV-specific coercion when invalid input must survive for row-level validation. */
174-
coerceImport?(value: unknown, options?: ColumnImportCoerceOptions): Exclude<JsonValue, Date>
175-
176169
/** Source-owned normalization applied before checking or rewriting a type conversion. */
177170
valueForConversion?(value: JsonValue, target: ColumnDefinition): JsonValue
178171

apps/sim/lib/table/import.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import type { Options as CsvParseOptions } from 'csv-parse'
1515
import { OrchestrationError } from '@/lib/core/orchestration/types'
1616
import { getColumnId } from '@/lib/table/column-keys'
1717
import type { ColumnType } from '@/lib/table/column-types'
18-
import { columnTypeById } from '@/lib/table/column-types'
1918
import { parseCurrencyInput } from '@/lib/table/currency'
2019
import { type NormalizeDateCellOptions, normalizeDateCellValue } from '@/lib/table/dates'
2120
import type { ColumnDefinition, RowData, TableSchema } from '@/lib/table/types'
@@ -482,8 +481,6 @@ export function coerceValue(
482481
options?: NormalizeDateCellOptions & { currencyCode?: string }
483482
): string | number | boolean | null | Record<string, unknown> | unknown[] {
484483
if (value === null || value === undefined || value === '') return null
485-
const definition = columnTypeById(colType)
486-
if (definition.coerceImport) return definition.coerceImport(value, options)
487484

488485
switch (colType) {
489486
case 'number': {

0 commit comments

Comments
 (0)