Skip to content

Commit

Permalink
Add entry fields to inferred types
Browse files Browse the repository at this point in the history
  • Loading branch information
benmerckx committed Nov 12, 2024
1 parent e2d35ad commit d1f59c9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
4 changes: 1 addition & 3 deletions src/core/Graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ type InferResult<Selection, Types, Include> = Selection extends Expr<
: Selection extends undefined
? Types extends undefined
? EntryFields & (Include extends undefined ? {} : InferSelection<Include>)
: Infer<Types> &
EntryFields &
(Include extends undefined ? {} : InferSelection<Include>)
: Infer<Types> & (Include extends undefined ? {} : InferSelection<Include>)
: InferSelection<Selection>

type QueryResult<Selection, Types, Include> = Expand<
Expand Down
11 changes: 3 additions & 8 deletions src/core/Infer.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import {Expand, UnionOfValues} from 'alinea/core/util/Types'
import {EntryFields} from './EntryFields.js'
import {Expr} from './Expr.js'
import {Field} from './Field.js'
import {Type} from './Type.js'

type QueryList<T> = Expand<
UnionOfValues<{
[K in keyof T]: {_type: K} & QueryRow<T[K]>
[K in keyof T]: {_type: K} & Type.Infer<T[K]>
}>
>

export type QueryRow<Definition> = {
[K in keyof Definition as Definition[K] extends Expr<any>
? K
: never]: Definition[K] extends Expr<infer T> ? T : never
}

export type InferQueryValue<T> = T extends Array<Type<infer X>>
? InferQueryValue<X>
: T extends Type<infer Fields>
? QueryRow<Fields>
? Type.Infer<Fields> & EntryFields
: T extends Expr<infer QueryValue>
? QueryValue
: T extends Record<string, Type>
Expand Down

0 comments on commit d1f59c9

Please sign in to comment.