Skip to content

Commit

Permalink
Improve type signature of encodeRow and encodeRows
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-dp committed Jun 24, 2024
1 parent 9eb0b14 commit e614240
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
9 changes: 5 additions & 4 deletions clients/typescript/src/client/conversions/converter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Row } from '../../util'
import { AnyTableSchema } from '../model'
import { PgType } from './types'

Expand All @@ -13,19 +14,19 @@ export interface Converter {
* @param row The row to encode
* @param tableSchema The schema of the table for this row.
*/
encodeRow<T extends Record<string, any> = Record<string, any>>(
encodeRow(
row: Record<string, unknown>,
tableSchema: Pick<AnyTableSchema, 'fields'>
): T
): Row
/**
* Encodes the provided rows for storing in the database.
* @param rows The rows to encode
* @param tableSchema The schema of the table for these rows.
*/
encodeRows<T extends Record<string, any> = Record<string, any>>(
encodeRows(
rows: Array<Record<string, unknown>>,
tableSchema: Pick<AnyTableSchema, 'fields'>
): Array<T>
): Array<Row>
/**
* Decodes the provided value from the database.
* @param v The value to decode.
Expand Down
9 changes: 3 additions & 6 deletions clients/typescript/src/client/model/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,9 @@ export function transformTableRecord<T extends Row>(
schema !== undefined
? validate(transformedParsedRow, schema)
: transformedParsedRow
const transformedRecord = converter.encodeRow<DataRecord>(
validatedTransformedParsedRow,
{
fields,
}
)
const transformedRecord = converter.encodeRow(validatedTransformedParsedRow, {
fields,
})

// check if any of the immutable fields were modified
const validatedTransformedRecord = validateRecordTransformation(
Expand Down

0 comments on commit e614240

Please sign in to comment.