diff --git a/src/PostgrestFilterBuilder.ts b/src/PostgrestFilterBuilder.ts index 8fe560bb..c0de7d33 100644 --- a/src/PostgrestFilterBuilder.ts +++ b/src/PostgrestFilterBuilder.ts @@ -26,6 +26,10 @@ type FilterOperator = | 'phfts' | 'wfts' +export type IsStringOperator = Path extends `${string}->>${string}` + ? true + : false + // Match relationship filters with `table.column` syntax and resolve underlying // column value. If not matched, fallback to generic type. // TODO: Validate the relationship itself ala select-query-parser. Currently we @@ -41,9 +45,11 @@ type ResolveFilterValue< : ResolveFilterRelationshipValue : ColumnName extends keyof Row ? Row[ColumnName] - : // If the column selection is a jsonpath like `data->value` we attempt to match + : // If the column selection is a jsonpath like `data->value` or `data->>value` we attempt to match // the expected type with the parsed custom json type - JsonPathToType> extends infer JsonPathValue + IsStringOperator extends true + ? string + : JsonPathToType> extends infer JsonPathValue ? JsonPathValue extends never ? never : JsonPathValue diff --git a/test/issue-1354-d.ts b/test/issue-1354-d.ts index 704f0ae7..247efa43 100644 --- a/test/issue-1354-d.ts +++ b/test/issue-1354-d.ts @@ -280,7 +280,13 @@ const postgrestOverrideTypes = new PostgrestClient('http://loc const resIn = await postgrestOverrideTypes .from('foo') .select('id, bar, baz') - .in('bar->version', [1, 32]) + .in('bar->version', [31]) + .single() + await postgrestOverrideTypes + .from('foo') + .select('id, bar, baz') + // the type become a string when using the string json accessor operator + .in('bar->>version', ['something']) .single() if (resIn.error) {