Skip to content

Commit 5dda494

Browse files
committed
fix(tables): keep TTL import coercion lightweight
1 parent 3adfbb6 commit 5dda494

3 files changed

Lines changed: 9 additions & 16 deletions

File tree

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@ export const ttlColumnType: ColumnTypeDefinition = {
8383
return seconds === null ? { ok: false } : { ok: true, value: seconds }
8484
},
8585

86-
coerceForImport(value, context) {
87-
return parseTtlEpochSeconds(value, context) ?? String(value)
88-
},
89-
9086
valueForConversion(value, target: ColumnDefinition) {
9187
if (target.type !== 'date') return value
9288
return epochSecondsToIso(value) ?? value

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,6 @@ export interface ColumnTypeDefinition {
167167
context?: NormalizeDateCellOptions
168168
): CoerceResult
169169

170-
/** Import-only normalization when invalid raw text must survive for row-level validation. */
171-
coerceForImport?(value: unknown, context?: NormalizeDateCellOptions): Exclude<JsonValue, Date>
172-
173170
/** Source-owned normalization applied before checking or rewriting a type conversion. */
174171
valueForConversion?(value: JsonValue, target: ColumnDefinition): JsonValue
175172

apps/sim/lib/table/import.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
import type { Options as CsvParseOptions } from 'csv-parse'
1515
import { OrchestrationError } from '@/lib/core/orchestration/types'
1616
import { getColumnId } from '@/lib/table/column-keys'
17-
import { type ColumnType, columnTypeById } from '@/lib/table/column-types'
17+
import type { ColumnType } from '@/lib/table/column-types'
18+
import { parseTtlEpochSeconds } from '@/lib/table/column-types/ttl'
1819
import { parseCurrencyInput } from '@/lib/table/currency'
1920
import { type NormalizeDateCellOptions, normalizeDateCellValue } from '@/lib/table/dates'
2021
import type { ColumnDefinition, RowData, TableSchema } from '@/lib/table/types'
@@ -468,11 +469,10 @@ export function inferSchemaFromCsv(
468469
* back to the original string when unparseable so that schema validation can
469470
* reject it with context rather than silently inserting `null`.
470471
*
471-
* Deliberately not routed through the registry's ordinary `coerce`: that
472-
* contract is "coerced or rejected", while an import needs invalid raw text to
473-
* survive so row-level validation can name it. Types with special import
474-
* behavior own it through `coerceForImport`; the remaining legacy import
475-
* semantics stay here until they can move without changing error behavior.
472+
* Deliberately not routed through the column-type registry: its contract is
473+
* "coerced or rejected", while an import needs invalid raw text to survive so
474+
* row-level validation can name it. A registry value import here would also
475+
* pull every column-type implementation into each client that previews CSVs.
476476
*/
477477
export function coerceValue(
478478
value: unknown,
@@ -481,9 +481,6 @@ export function coerceValue(
481481
): string | number | boolean | null | Record<string, unknown> | unknown[] {
482482
if (value === null || value === undefined || value === '') return null
483483

484-
const importValue = columnTypeById(colType).coerceForImport?.(value, options)
485-
if (importValue !== undefined) return importValue
486-
487484
switch (colType) {
488485
case 'number': {
489486
const n = Number(value)
@@ -504,6 +501,9 @@ export function coerceValue(
504501
case 'date': {
505502
return normalizeDateCellValue(String(value), options) ?? String(value)
506503
}
504+
case 'ttl': {
505+
return parseTtlEpochSeconds(value, options) ?? String(value)
506+
}
507507
case 'json': {
508508
if (typeof value === 'object') return value as Record<string, unknown> | unknown[]
509509
try {

0 commit comments

Comments
 (0)