Skip to content

Commit

Permalink
Touch up on generics
Browse files Browse the repository at this point in the history
  • Loading branch information
daogrady committed Jan 22, 2024
1 parent 186325e commit 401feda
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions apis/ql.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export type Awaitable<T, I> = T & Promise<I>
// all the functionality of an instance of SELECT, but directly callable:
// new SELECT(...).(...) == SELECT(...)
export type StaticSELECT<T> = typeof SELECT
& ((...columns: (T extends ArrayConstructable<any> ? keyof SingularInstanceType<T> : keyof T)[]) => SELECT<T>)
& ((...columns: (T extends ArrayConstructable ? keyof SingularInstanceType<T> : keyof T)[]) => SELECT<T>)
& ((...columns: string[]) => SELECT<T>)
& ((columns: string[]) => SELECT<T>)
& (TaggedTemplateQueryPart<SELECT<T>>)
Expand Down Expand Up @@ -155,7 +155,7 @@ declare class QL<T> {
type TaggedTemplateQueryPart<T> = (strings: TemplateStringsArray, ...params: unknown[]) => T

interface SELECT extends Columns, Where, And, Having, GroupBy, OrderBy, Limit {}
export class SELECT<T> extends ConstructedQuery {
export class SELECT<T> extends ConstructedQuery<T> {

static one: SELECT_one<T> & { from: SELECT_one<T> }

Expand Down Expand Up @@ -200,11 +200,11 @@ type SELECT_one =
TaggedTemplateQueryPart<Awaitable<SELECT<unknown>, InstanceType<any>>>
&
// calling with class
(<T extends ArrayConstructable<any>>
(<T extends ArrayConstructable>
(entityType: T, projection?: Projection<QLExtensions<SingularInstanceType<T>>>)
=> Awaitable<SELECT<SingularInstanceType<T>>, SingularInstanceType<T>>)
&
(<T extends ArrayConstructable<any>>
(<T extends ArrayConstructable>
(entityType: T, primaryKey: PK, projection?: Projection<QLExtensions<SingularInstanceType<T>>>)
=> Awaitable<SELECT<SingularInstanceType<T>>, SingularInstanceType<T>>)

Expand All @@ -221,11 +221,11 @@ type SELECT_from<T> =
TaggedTemplateQueryPart<Awaitable<SELECT<unknown>, InstanceType<any>>>
&
// calling with class
(<T extends ArrayConstructable<any>>
(<T extends ArrayConstructable>
(entityType: T, projection?: Projection<QLExtensions<SingularInstanceType<T>>>)
=> Awaitable<SELECT<T>, InstanceType<T>>)
&
(<T extends ArrayConstructable<any>>
(<T extends ArrayConstructable>
(entityType: T, primaryKey: PK, projection?: Projection<SingularInstanceType<T>>)
=> Awaitable<SELECT<SingularInstanceType<T>>, InstanceType<SingularInstanceType<T>>>) // when specifying a key, we expect a single element as result
// calling with definition
Expand Down Expand Up @@ -267,7 +267,7 @@ export class INSERT<T> extends ConstructedQuery<T> {
interface UPSERT extends Columns {}
export class UPSERT<T> extends ConstructedQuery<T> {

static into: (<T extends ArrayConstructable<any>> (entity: T, entries?: object | object[]) => UPSERT<SingularInstanceType<T>>)
static into: (<T extends ArrayConstructable> (entity: T, entries?: object | object[]) => UPSERT<SingularInstanceType<T>>)
& (TaggedTemplateQueryPart<UPSERT<unknown>>)
& ((entity: Definition | string, entries?: object | object[]) => UPSERT<any>)
& ((entity: LinkedEntity | string, entries?: object | object[]) => UPSERT<any>)
Expand Down Expand Up @@ -306,8 +306,6 @@ export class DELETE<T> extends ConstructedQuery<T> {

}



export interface UPDATE extends Whereable, Andable {}
export class UPDATE<T> extends ConstructedQuery<T> {
// cds-typer plural, singular
Expand Down Expand Up @@ -347,7 +345,7 @@ interface And {

interface Columns {
columns (projection: Projection<T>): this
columns (...col: (T extends ArrayConstructable<any> ? keyof SingularInstanceType<T> : keyof T)[]): this
columns (...col: (T extends ArrayConstructable ? keyof SingularInstanceType<T> : keyof T)[]): this
columns (...col: (string | column_expr)[]): this
columns (col: (string | column_expr)[]): this
columns: TaggedTemplateQueryPart<this>
Expand Down

0 comments on commit 401feda

Please sign in to comment.