Skip to content

Commit c2112d4

Browse files
committed
fix: jsonpath filter string operator accessor
1 parent b49c660 commit c2112d4

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/PostgrestFilterBuilder.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ type FilterOperator =
2626
| 'phfts'
2727
| 'wfts'
2828

29+
export type IsStringOperator<Path extends string> = Path extends `${string}->>${string}`
30+
? true
31+
: false
32+
2933
// Match relationship filters with `table.column` syntax and resolve underlying
3034
// column value. If not matched, fallback to generic type.
3135
// TODO: Validate the relationship itself ala select-query-parser. Currently we
@@ -41,9 +45,11 @@ type ResolveFilterValue<
4145
: ResolveFilterRelationshipValue<Schema, RelationshipTable, Remainder>
4246
: ColumnName extends keyof Row
4347
? Row[ColumnName]
44-
: // If the column selection is a jsonpath like `data->value` we attempt to match
48+
: // If the column selection is a jsonpath like `data->value` or `data->>value` we attempt to match
4549
// the expected type with the parsed custom json type
46-
JsonPathToType<Row, JsonPathToAccessor<ColumnName>> extends infer JsonPathValue
50+
IsStringOperator<ColumnName> extends true
51+
? string
52+
: JsonPathToType<Row, JsonPathToAccessor<ColumnName>> extends infer JsonPathValue
4753
? JsonPathValue extends never
4854
? never
4955
: JsonPathValue

test/issue-1354-d.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,13 @@ const postgrestOverrideTypes = new PostgrestClient<DatabaseOverride>('http://loc
280280
const resIn = await postgrestOverrideTypes
281281
.from('foo')
282282
.select('id, bar, baz')
283-
.in('bar->version', [1, 32])
283+
.in('bar->version', [31])
284+
.single()
285+
await postgrestOverrideTypes
286+
.from('foo')
287+
.select('id, bar, baz')
288+
// the type become a string when using the string json accessor operator
289+
.in('bar->>version', ['something'])
284290
.single()
285291

286292
if (resIn.error) {

0 commit comments

Comments
 (0)