Skip to content

Commit

Permalink
lint: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuuki-Sakura authored and Ruben committed Nov 18, 2024
1 parent a2c40a5 commit 8c69ef6
Showing 1 changed file with 53 additions and 41 deletions.
94 changes: 53 additions & 41 deletions src/find-options/FindReturnType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,18 @@ type ExtractNil<T> = Exclude<T, Exclude<T, undefined | null>>

type ArrayType<I, E> = Array<I> | ExtractNil<E>

export type FindReturnType<
type PickSelect<
Entity extends ObjectLiteral,
Select extends
| FindOptionsSelect<Entity>
| FindOptionsSelectByString<Entity>
| undefined,
Relation extends
| FindOptionsRelations<Entity>
| FindOptionsRelationByString
| undefined,
> = keyof Select extends never
? keyof Relation extends never
? Entity
: Entity & {
[R in Relation extends FindOptionsRelationByString
? never
: TruthyKeys<Relation>]: Relation extends FindOptionsRelations<Entity>
? Relation[R] extends FindOptionsRelations<Entity[R]>
? FindReturnType<Entity[R], undefined, Relation[R]>
: Entity[R]
: Entity[R]
}
> = Select extends FindOptionsSelectByString<Entity>
? {
[R in Select extends FindOptionsSelectByString<Entity>
? Select[number]
: never]: Entity[R]
}
: {
[R in Select extends FindOptionsSelectByString<Entity>
? never
Expand All @@ -58,28 +48,50 @@ export type FindReturnType<
? FindReturnType<Entity[R], Select[R], undefined>
: Entity[R]
: Entity[R]
} & {
[R in Relation extends FindOptionsRelationByString
? never
: TruthyKeys<Relation>]: Exclude<
Entity[R],
undefined | null
> extends Array<infer U>
? U extends object
? Relation[R] extends FindOptionsRelations<U>
? ArrayType<
FindReturnType<U, undefined, Relation[R]>,
Entity[R]
>
: ArrayType<U, Entity[R]>
: ArrayType<U, Entity[R]>
: Entity[R] extends object
? Relation[R] extends FindOptionsRelations<Entity[R]>
? FindReturnType<Entity[R], undefined, Relation[R]>
: Entity[R]
: Entity[R]
} & {
[R in Select extends FindOptionsSelectByString<Entity>
? Select[number]
: never]: Entity[R]
}

type PickRelations<
Entity extends ObjectLiteral,
Relation extends
| FindOptionsRelations<Entity>
| FindOptionsRelationByString
| undefined,
> = {
[R in Relation extends FindOptionsRelationByString
? never
: TruthyKeys<Relation>]: Exclude<
Entity[R],
undefined | null
> extends Array<infer U>
? U extends object
? Relation[R] extends FindOptionsRelations<U>
? ArrayType<
FindReturnType<U, undefined, Relation[R]>,
Entity[R]
>
: ArrayType<U, Entity[R]>
: ArrayType<U, Entity[R]>
: Entity[R] extends object
? Relation[R] extends FindOptionsRelations<Entity[R]>
? FindReturnType<Entity[R], undefined, Relation[R]>
: Entity[R]
: Entity[R]
}

export type FindReturnType<
Entity extends ObjectLiteral,
Select extends
| FindOptionsSelect<Entity>
| FindOptionsSelectByString<Entity>
| undefined,
Relation extends
| FindOptionsRelations<Entity>
| FindOptionsRelationByString
| undefined,
> = keyof Select extends never
? keyof Relation extends never
? Entity
: Entity & PickRelations<Entity, Relation>
: keyof Relation extends never
? PickSelect<Entity, Select>
: PickSelect<Entity, Select> & PickRelations<Entity, Relation>

0 comments on commit 8c69ef6

Please sign in to comment.