Skip to content

Commit

Permalink
Improve TypeScript error messages managing boolean values sources
Browse files Browse the repository at this point in the history
  • Loading branch information
juanluispaz committed Mar 17, 2024
1 parent 76b5507 commit b4a3475
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 188 deletions.
32 changes: 11 additions & 21 deletions src/expressions/delete.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AnyValueSource, IBooleanValueSource, IExecutableDeleteQuery, IIfValueSource, ValueSourceOf, ValueSourceValueTypeForResult } from "./values"
import type { AnyValueSource, IAnyBooleanValueSource, IExecutableDeleteQuery, ValueSourceOf, ValueSourceValueTypeForResult } from "./values"
import type { ForUseInLeftJoin, HasSource, IRawFragment, ITableOrView, OfDB, OfSameDB } from "../utils/ITableOrView"
import type { ResultObjectValues, ResultObjectValuesProjectedAsNullable } from "../utils/resultUtils"
import type { NNoTableOrViewRequiredFrom, NSource } from "../utils/sourceName"
Expand Down Expand Up @@ -28,16 +28,13 @@ export interface CustomizableExecutableDelete</*in|out*/ TABLE extends HasSource
}

export interface DynamicExecutableDeleteExpression</*in|out*/ TABLE extends HasSource<any>, /*in|out*/ USING extends HasSource<any>> extends ReturnableExecutableDelete<TABLE, USING> {
and(condition: IIfValueSource <USING[typeof source], any>): DynamicExecutableDeleteExpression<TABLE, USING>
and(condition: IBooleanValueSource <USING[typeof source], any>): DynamicExecutableDeleteExpression<TABLE, USING>
or(condition: IIfValueSource <USING[typeof source], any>): DynamicExecutableDeleteExpression<TABLE, USING>
or(condition: IBooleanValueSource <USING[typeof source], any>): DynamicExecutableDeleteExpression<TABLE, USING>
and(condition: IAnyBooleanValueSource<USING[typeof source], any>): DynamicExecutableDeleteExpression<TABLE, USING>
or(condition: IAnyBooleanValueSource<USING[typeof source], any>): DynamicExecutableDeleteExpression<TABLE, USING>
}

export interface DeleteWhereExpression</*in|out*/ TABLE extends HasSource<any>, /*in|out*/ USING extends HasSource<any>> extends DeleteExpressionBase<TABLE, USING> {
dynamicWhere() : DynamicExecutableDeleteExpression<TABLE, USING>
where(condition: IIfValueSource <USING[typeof source], any>): DynamicExecutableDeleteExpression<TABLE, USING>
where(condition: IBooleanValueSource <USING[typeof source], any>): DynamicExecutableDeleteExpression<TABLE, USING>
where(condition: IAnyBooleanValueSource<USING[typeof source], any>): DynamicExecutableDeleteExpression<TABLE, USING>
}

export interface DeleteExpression</*in|out*/ TABLE extends HasSource<any>, /*in|out*/ USING extends HasSource<any>> extends DeleteWhereExpression<TABLE, USING> {
Expand All @@ -50,8 +47,7 @@ export interface DeleteExpression</*in|out*/ TABLE extends HasSource<any>, /*in|

export interface DeleteWhereExpressionAllowingNoWhere</*in|out*/ TABLE extends HasSource<any>, /*in|out*/ USING extends HasSource<any>> extends ReturnableExecutableDelete<TABLE, USING> {
dynamicWhere() : DynamicExecutableDeleteExpression<TABLE, USING>
where(condition: IIfValueSource <USING[typeof source], any>): DynamicExecutableDeleteExpression<TABLE, USING>
where(condition: IBooleanValueSource <USING[typeof source], any>): DynamicExecutableDeleteExpression<TABLE, USING>
where(condition: IAnyBooleanValueSource<USING[typeof source], any>): DynamicExecutableDeleteExpression<TABLE, USING>
}

export interface DeleteExpressionAllowingNoWhere</*in|out*/ TABLE extends HasSource<any>, /*in|out*/ USING extends HasSource<any>> extends DeleteWhereExpressionAllowingNoWhere<TABLE, USING> {
Expand All @@ -74,16 +70,13 @@ export interface DeleteWhereJoinExpression</*in|out*/ TABLE extends HasSource<an
}

export interface DynamicOnExpression</*in|out*/ TABLE extends HasSource<any>, /*in|out*/ USING extends HasSource<any>> extends DeleteWhereJoinExpression<TABLE, USING> {
and(condition: IIfValueSource <USING[typeof source], any>): DynamicOnExpression<TABLE, USING>
and(condition: IBooleanValueSource <USING[typeof source], any>): DynamicOnExpression<TABLE, USING>
or(condition: IIfValueSource <USING[typeof source], any>): DynamicOnExpression<TABLE, USING>
or(condition: IBooleanValueSource <USING[typeof source], any>): DynamicOnExpression<TABLE, USING>
and(condition: IAnyBooleanValueSource<USING[typeof source], any>): DynamicOnExpression<TABLE, USING>
or(condition: IAnyBooleanValueSource<USING[typeof source], any>): DynamicOnExpression<TABLE, USING>
}

export interface OnExpression</*in|out*/ TABLE extends HasSource<any>, /*in|out*/ USING extends HasSource<any>> extends DeleteWhereJoinExpression<TABLE, USING> {
dynamicOn(): DynamicOnExpression<TABLE, USING>
on(condition: IIfValueSource <USING[typeof source], any>): DynamicOnExpression<TABLE, USING>
on(condition: IBooleanValueSource <USING[typeof source], any>): DynamicOnExpression<TABLE, USING>
on(condition: IAnyBooleanValueSource<USING[typeof source], any>): DynamicOnExpression<TABLE, USING>
}

export interface DeleteExpressionWithoutJoin</*in|out*/ TABLE extends HasSource<any>, /*in|out*/ USING extends HasSource<any>> extends DeleteWhereExpression<TABLE, USING> {
Expand Down Expand Up @@ -121,16 +114,13 @@ export interface DeleteWhereJoinExpressionAllowingNoWhere</*in|out*/ TABLE exten
}

export interface DynamicOnExpressionAllowingNoWhere</*in|out*/ TABLE extends HasSource<any>, /*in|out*/ USING extends HasSource<any>> extends DeleteWhereJoinExpressionAllowingNoWhere<TABLE, USING> {
and(condition: IIfValueSource <USING[typeof source], any>): DynamicOnExpressionAllowingNoWhere<TABLE, USING>
and(condition: IBooleanValueSource <USING[typeof source], any>): DynamicOnExpressionAllowingNoWhere<TABLE, USING>
or(condition: IIfValueSource <USING[typeof source], any>): DynamicOnExpressionAllowingNoWhere<TABLE, USING>
or(condition: IBooleanValueSource <USING[typeof source], any>): DynamicOnExpressionAllowingNoWhere<TABLE, USING>
and(condition: IAnyBooleanValueSource<USING[typeof source], any>): DynamicOnExpressionAllowingNoWhere<TABLE, USING>
or(condition: IAnyBooleanValueSource<USING[typeof source], any>): DynamicOnExpressionAllowingNoWhere<TABLE, USING>
}

export interface OnExpressionAllowingNoWhere</*in|out*/ TABLE extends HasSource<any>, /*in|out*/ USING extends HasSource<any>> extends DeleteWhereJoinExpressionAllowingNoWhere<TABLE, USING> {
dynamicOn(): DynamicOnExpressionAllowingNoWhere<TABLE, USING>
on(condition: IIfValueSource <USING[typeof source], any>): DynamicOnExpressionAllowingNoWhere<TABLE, USING>
on(condition: IBooleanValueSource <USING[typeof source], any>): DynamicOnExpressionAllowingNoWhere<TABLE, USING>
on(condition: IAnyBooleanValueSource<USING[typeof source], any>): DynamicOnExpressionAllowingNoWhere<TABLE, USING>
}

export interface DeleteExpressionWithoutJoinAllowingNoWhere</*in|out*/ TABLE extends HasSource<any>, /*in|out*/ USING extends HasSource<any>> extends DeleteWhereExpressionAllowingNoWhere<TABLE, USING> {
Expand Down
14 changes: 7 additions & 7 deletions src/expressions/fragment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BooleanValueSource, NumberValueSource, StringValueSource, LocalDateValueSource, LocalTimeValueSource, LocalDateTimeValueSource, EqualableValueSource, ComparableValueSource, RemapValueSourceType, TypeOfArgument, MapArgumentToValueSource, ArgForFn, IfValueSource, ArgForBuilderIfValue, IBooleanValueSource, IIfValueSource, BigintValueSource, OptionalType, ValueSourceOf, UuidValueSource, CustomIntValueSource, CustomDoubleValueSource, CustomUuidValueSource, CustomLocalDateTimeValueSource, CustomLocalDateValueSource, CustomLocalTimeValueSource, IValueSource, RemapValueSourceTypeWithOptionalType, OptionalTypeOfValue, ArgBaseTypeForFn, MergeOptionalUnion } from "../expressions/values"
import type { BooleanValueSource, NumberValueSource, StringValueSource, LocalDateValueSource, LocalTimeValueSource, LocalDateTimeValueSource, EqualableValueSource, ComparableValueSource, RemapValueSourceType, TypeOfArgument, MapArgumentToValueSource, ArgForFn, IfValueSource, ArgForBuilderIfValue, IAnyBooleanValueSource, BigintValueSource, OptionalType, ValueSourceOf, UuidValueSource, CustomIntValueSource, CustomDoubleValueSource, CustomUuidValueSource, CustomLocalDateTimeValueSource, CustomLocalDateValueSource, CustomLocalTimeValueSource, IValueSource, RemapValueSourceTypeWithOptionalType, OptionalTypeOfValue, ArgBaseTypeForFn, MergeOptionalUnion } from "../expressions/values"
import type { optionalType, source } from "../utils/symbols"
import type { NSource } from "../utils/sourceName"

Expand Down Expand Up @@ -285,27 +285,27 @@ export interface FragmentFunction5</*in|out*/ NO_SOURCE extends NSource, A1, A2,
}

export interface FragmentBuilder0IfValue</*in|out*/ NO_SOURCE extends NSource> {
as<RESULT extends IBooleanValueSource<NO_SOURCE, any> | IIfValueSource<NO_SOURCE, any>>(impl: () => RESULT): () => IfValueSource<NO_SOURCE, RESULT[typeof optionalType]>
as<RESULT extends IAnyBooleanValueSource<NO_SOURCE, any>>(impl: () => RESULT): () => IfValueSource<NO_SOURCE, RESULT[typeof optionalType]>
}

export interface FragmentBuilder1IfValue</*in|out*/ NO_SOURCE extends NSource, A1> {
as<RESULT extends IBooleanValueSource<NO_SOURCE, any> | IIfValueSource<NO_SOURCE, any>>(impl: (a1: ArgForBuilderIfValue<NO_SOURCE, A1>) => RESULT): FragmentFunctionIfValue1<NO_SOURCE, A1, RESULT[typeof optionalType]>
as<RESULT extends IAnyBooleanValueSource<NO_SOURCE, any>>(impl: (a1: ArgForBuilderIfValue<NO_SOURCE, A1>) => RESULT): FragmentFunctionIfValue1<NO_SOURCE, A1, RESULT[typeof optionalType]>
}

export interface FragmentBuilder2IfValue</*in|out*/ NO_SOURCE extends NSource, A1, A2> {
as<RESULT extends IBooleanValueSource<NO_SOURCE, any> | IIfValueSource<NO_SOURCE, any>>(impl: (a1: ArgForBuilderIfValue<NO_SOURCE, A1>, a2: ArgForBuilderIfValue<NO_SOURCE, A2>) => RESULT): FragmentFunctionIfValue2<NO_SOURCE, A1, A2, RESULT[typeof optionalType]>
as<RESULT extends IAnyBooleanValueSource<NO_SOURCE, any>>(impl: (a1: ArgForBuilderIfValue<NO_SOURCE, A1>, a2: ArgForBuilderIfValue<NO_SOURCE, A2>) => RESULT): FragmentFunctionIfValue2<NO_SOURCE, A1, A2, RESULT[typeof optionalType]>
}

export interface FragmentBuilder3IfValue</*in|out*/ NO_SOURCE extends NSource, A1, A2, A3> {
as<RESULT extends IBooleanValueSource<NO_SOURCE, any> | IIfValueSource<NO_SOURCE, any>>(impl: (a1: ArgForBuilderIfValue<NO_SOURCE, A1>, a2: ArgForBuilderIfValue<NO_SOURCE, A2>, a3: ArgForBuilderIfValue<NO_SOURCE, A3>) => RESULT): FragmentFunctionIfValue3<NO_SOURCE, A1, A2, A3, RESULT[typeof optionalType]>
as<RESULT extends IAnyBooleanValueSource<NO_SOURCE, any>>(impl: (a1: ArgForBuilderIfValue<NO_SOURCE, A1>, a2: ArgForBuilderIfValue<NO_SOURCE, A2>, a3: ArgForBuilderIfValue<NO_SOURCE, A3>) => RESULT): FragmentFunctionIfValue3<NO_SOURCE, A1, A2, A3, RESULT[typeof optionalType]>
}

export interface FragmentBuilder4IfValue</*in|out*/ NO_SOURCE extends NSource, A1, A2, A3, A4> {
as<RESULT extends IBooleanValueSource<NO_SOURCE, any> | IIfValueSource<NO_SOURCE, any>>(impl: (a1: ArgForBuilderIfValue<NO_SOURCE, A1>, a2: ArgForBuilderIfValue<NO_SOURCE, A2>, a3: ArgForBuilderIfValue<NO_SOURCE, A3>, a4: ArgForBuilderIfValue<NO_SOURCE, A4>) => RESULT): FragmentFunctionIfValue4<NO_SOURCE, A1, A2, A3, A4, RESULT[typeof optionalType]>
as<RESULT extends IAnyBooleanValueSource<NO_SOURCE, any>>(impl: (a1: ArgForBuilderIfValue<NO_SOURCE, A1>, a2: ArgForBuilderIfValue<NO_SOURCE, A2>, a3: ArgForBuilderIfValue<NO_SOURCE, A3>, a4: ArgForBuilderIfValue<NO_SOURCE, A4>) => RESULT): FragmentFunctionIfValue4<NO_SOURCE, A1, A2, A3, A4, RESULT[typeof optionalType]>
}

export interface FragmentBuilder5IfValue</*in|out*/ NO_SOURCE extends NSource, A1, A2, A3, A4, A5> {
as<RESULT extends BooleanValueSource<NO_SOURCE, any> | IIfValueSource<NO_SOURCE, any>>(impl: (a1: ArgForBuilderIfValue<NO_SOURCE, A1>, a2: ArgForBuilderIfValue<NO_SOURCE, A2>, a3: ArgForBuilderIfValue<NO_SOURCE, A3>, a4: ArgForBuilderIfValue<NO_SOURCE, A4>, a5: ArgForBuilderIfValue<NO_SOURCE, A5>) => RESULT): FragmentFunctionIfValue5<NO_SOURCE, A1, A2, A3, A4, A5, RESULT[typeof optionalType]>
as<RESULT extends IAnyBooleanValueSource<NO_SOURCE, any>>(impl: (a1: ArgForBuilderIfValue<NO_SOURCE, A1>, a2: ArgForBuilderIfValue<NO_SOURCE, A2>, a3: ArgForBuilderIfValue<NO_SOURCE, A3>, a4: ArgForBuilderIfValue<NO_SOURCE, A4>, a5: ArgForBuilderIfValue<NO_SOURCE, A5>) => RESULT): FragmentFunctionIfValue5<NO_SOURCE, A1, A2, A3, A4, A5, RESULT[typeof optionalType]>
}

export interface FragmentFunctionIfValue1</*in|out*/ NO_SOURCE extends NSource, A1, /*in|out*/ OPTIONAL_TYPE extends OptionalType> {
Expand Down
14 changes: 5 additions & 9 deletions src/expressions/insert.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IExecutableSelectQuery, RemapIValueSourceType, ValueSourceValueType, AnyValueSource, ValueSourceOf, ValueSourceValueTypeForResult, RemapIValueSourceTypeWithOptionalType, IExecutableInsertQuery, IIfValueSource, IBooleanValueSource, IStringValueSource } from "./values"
import type { IExecutableSelectQuery, RemapIValueSourceType, ValueSourceValueType, AnyValueSource, ValueSourceOf, ValueSourceValueTypeForResult, RemapIValueSourceTypeWithOptionalType, IExecutableInsertQuery, IAnyBooleanValueSource, IStringValueSource } from "./values"
import type { HasSource, IRawFragment, OfDB, ResolvedShape } from "../utils/ITableOrView"
import type { from, source, using } from "../utils/symbols"
import type { ColumnWithDefaultValue } from "../utils/Column"
Expand Down Expand Up @@ -882,16 +882,13 @@ export interface ShapedInsertOnConflictSetsExpression</*in|out*/ TABLE extends H
}

export interface DynamicOnConflictWhereExpression</*in|out*/ TABLE extends HasSource<any>, /*in|out*/ USING extends HasSource<any>, NEXT> {
and(condition: IIfValueSource<USING[typeof source], any>): DynamicOnConflictWhereExpression<TABLE, USING, NEXT> & NEXT
and(condition: IBooleanValueSource<USING[typeof source], any>): DynamicOnConflictWhereExpression<TABLE, USING, NEXT> & NEXT
or(condition: IIfValueSource<USING[typeof source], any>): DynamicOnConflictWhereExpression<TABLE, USING, NEXT> & NEXT
or(condition: IBooleanValueSource<USING[typeof source], any>): DynamicOnConflictWhereExpression<TABLE, USING, NEXT> & NEXT
and(condition: IAnyBooleanValueSource<USING[typeof source], any>): DynamicOnConflictWhereExpression<TABLE, USING, NEXT> & NEXT
or(condition: IAnyBooleanValueSource<USING[typeof source], any>): DynamicOnConflictWhereExpression<TABLE, USING, NEXT> & NEXT
}

export interface OnConflictOnColumnWhere</*in|out*/ TABLE extends HasSource<any>, /*in|out*/ USING extends HasSource<any>, NEXT> {
dynamicWhere() : DynamicOnConflictWhereExpression<TABLE, USING, NEXT> & NEXT
where(condition: IIfValueSource<USING[typeof source], any>): DynamicOnConflictWhereExpression<TABLE, USING, NEXT> & NEXT
where(condition: IBooleanValueSource<USING[typeof source], any>): DynamicOnConflictWhereExpression<TABLE, USING, NEXT> & NEXT
where(condition: IAnyBooleanValueSource<USING[typeof source], any>): DynamicOnConflictWhereExpression<TABLE, USING, NEXT> & NEXT
}

type OnConflictDoNothingFnType<TABLE extends HasSource<any>, _USING extends HasSource<any>, NEXT> =
Expand Down Expand Up @@ -934,8 +931,7 @@ type OnConflictDoUpdateWhereFnType<TABLE extends HasSource<any>, USING extends H
: never

interface OnConflictDoUpdateWhereFnTypeInterface</*in|out*/ TABLE extends HasSource<any>, /*in|out*/ USING extends HasSource<any>, /*in|out*/ NEXT> {
(condition: IIfValueSource<USING[typeof source], any>): DynamicOnConflictWhereExpression<TABLE, USING, NEXT> & NEXT
(condition: IBooleanValueSource<USING[typeof source], any>): DynamicOnConflictWhereExpression<TABLE, USING, NEXT> & NEXT
(condition: IAnyBooleanValueSource<USING[typeof source], any>): DynamicOnConflictWhereExpression<TABLE, USING, NEXT> & NEXT
}

type OnConflictOnColumnFnType<TABLE extends HasSource<any>, USING extends HasSource<any>, NEXT> =
Expand Down
Loading

0 comments on commit b4a3475

Please sign in to comment.