diff --git a/src/PostgrestTransformBuilder.ts b/src/PostgrestTransformBuilder.ts index 624a47f8..8926f112 100644 --- a/src/PostgrestTransformBuilder.ts +++ b/src/PostgrestTransformBuilder.ts @@ -7,6 +7,10 @@ import { PostgrestSingleResponse, } from './types' +/* Extract the column name from a potential JSON accessor expression. */ +type ColumnName = + T extends `${infer TName}->${infer _TRest}` ? TName : T + export default class PostgrestTransformBuilder< Schema extends GenericSchema, Row extends Record, @@ -46,13 +50,11 @@ export default class PostgrestTransformBuilder< return this as unknown as PostgrestTransformBuilder } - order( - column: ColumnName, - options?: { ascending?: boolean; nullsFirst?: boolean; foreignTable?: undefined } - ): this - order( - column: string, - options?: { ascending?: boolean; nullsFirst?: boolean; foreignTable: string } + order>( + column: ColExpr, + options?: ColName extends keyof Row ? + { ascending?: boolean; nullsFirst?: boolean; foreignTable?: string } : + { ascending?: boolean; nullsFirst?: boolean; foreignTable: string } ): this /** * Order the query result by `column`.