effect-qb 0.15.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -40,6 +40,7 @@ import {
40
40
  type ExpressionInput,
41
41
  type ExtractDialect,
42
42
  type ExtractRequired,
43
+ type FactsOfPlan,
43
44
  type GroupByInput,
44
45
  type GroupedOfPlan,
45
46
  type GroupedKeysFromValues,
@@ -55,6 +56,7 @@ import {
55
56
  type PlanDialectOf,
56
57
  type PresenceWitnessKeysOfSource,
57
58
  type PredicateInput,
59
+ type PredicateStateOfPlan,
58
60
  type KindOf,
59
61
  type QueryPlan,
60
62
  type OutputOfSelection,
@@ -117,7 +119,7 @@ import type {
117
119
  JsonValueAtPath,
118
120
  NormalizeJsonLiteral
119
121
  } from "../../internal/json/types.js"
120
- import type { AssumeTrue } from "../../internal/predicate/analysis.js"
122
+ import type { AssumePredicateStateTrue, EmptyFacts, PredicateStateFacts, PredicateStateFormula } from "../../internal/predicate/analysis.js"
121
123
  import type { FormulaOfPredicate } from "../../internal/predicate/normalize.js"
122
124
  import type { TrueFormula } from "../../internal/predicate/formula.js"
123
125
  import { assumeFormulaTrue, formulaOfExpression as formulaOfExpressionRuntime, trueFormula } from "../../internal/predicate/runtime.js"
@@ -762,6 +764,18 @@ type DialectExpressionTuple<
762
764
  readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
763
765
  }
764
766
 
767
+ type DialectExpressionArray<
768
+ Values extends readonly ExpressionInput[],
769
+ Dialect extends string,
770
+ TextDb extends Expression.DbType.Any,
771
+ NumericDb extends Expression.DbType.Any,
772
+ BoolDb extends Expression.DbType.Any,
773
+ TimestampDb extends Expression.DbType.Any,
774
+ NullDb extends Expression.DbType.Any
775
+ > = DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> extends infer Tuple extends readonly Expression.Any[]
776
+ ? Tuple
777
+ : never
778
+
765
779
  /** Normalized expression tuple for generic string operator inputs. */
766
780
  type DialectStringExpressionTuple<
767
781
  Values extends readonly ExpressionInput[],
@@ -778,7 +792,7 @@ type DialectStringExpressionTuple<
778
792
  /** Names of sources already available to a plan. */
779
793
  type AvailableNames<Available extends Record<string, Plan.AnySource>> = Extract<keyof Available, string>
780
794
 
781
- type PlanAssumptionsAfterWhere<
795
+ type PlanPredicateStateAfterWhere<
782
796
  PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
783
797
  Predicate extends PredicateInput,
784
798
  Dialect extends string,
@@ -787,12 +801,34 @@ type PlanAssumptionsAfterWhere<
787
801
  BoolDb extends Expression.DbType.Any,
788
802
  TimestampDb extends Expression.DbType.Any,
789
803
  NullDb extends Expression.DbType.Any
790
- > = AssumeTrue<
791
- AssumptionsOfPlan<PlanValue>,
804
+ > = AssumePredicateStateTrue<
805
+ PredicateStateOfPlan<PlanValue>,
792
806
  DialectAsExpression<Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
793
807
  >
794
808
 
795
- type PlanAssumptionsAfterHaving<
809
+ type PlanAssumptionsAfterWhere<
810
+ PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
811
+ Predicate extends PredicateInput,
812
+ Dialect extends string,
813
+ TextDb extends Expression.DbType.Any,
814
+ NumericDb extends Expression.DbType.Any,
815
+ BoolDb extends Expression.DbType.Any,
816
+ TimestampDb extends Expression.DbType.Any,
817
+ NullDb extends Expression.DbType.Any
818
+ > = PredicateStateFormula<PlanPredicateStateAfterWhere<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
819
+
820
+ type PlanFactsAfterWhere<
821
+ PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
822
+ Predicate extends PredicateInput,
823
+ Dialect extends string,
824
+ TextDb extends Expression.DbType.Any,
825
+ NumericDb extends Expression.DbType.Any,
826
+ BoolDb extends Expression.DbType.Any,
827
+ TimestampDb extends Expression.DbType.Any,
828
+ NullDb extends Expression.DbType.Any
829
+ > = PredicateStateFacts<PlanPredicateStateAfterWhere<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
830
+
831
+ type PlanPredicateStateAfterHaving<
796
832
  PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
797
833
  Predicate extends HavingPredicateInput,
798
834
  Dialect extends string,
@@ -801,12 +837,34 @@ type PlanAssumptionsAfterHaving<
801
837
  BoolDb extends Expression.DbType.Any,
802
838
  TimestampDb extends Expression.DbType.Any,
803
839
  NullDb extends Expression.DbType.Any
804
- > = AssumeTrue<
805
- AssumptionsOfPlan<PlanValue>,
840
+ > = AssumePredicateStateTrue<
841
+ PredicateStateOfPlan<PlanValue>,
806
842
  DialectAsExpression<Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
807
843
  >
808
844
 
809
- type PlanAssumptionsAfterJoin<
845
+ type PlanAssumptionsAfterHaving<
846
+ PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
847
+ Predicate extends HavingPredicateInput,
848
+ Dialect extends string,
849
+ TextDb extends Expression.DbType.Any,
850
+ NumericDb extends Expression.DbType.Any,
851
+ BoolDb extends Expression.DbType.Any,
852
+ TimestampDb extends Expression.DbType.Any,
853
+ NullDb extends Expression.DbType.Any
854
+ > = PredicateStateFormula<PlanPredicateStateAfterHaving<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
855
+
856
+ type PlanFactsAfterHaving<
857
+ PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
858
+ Predicate extends HavingPredicateInput,
859
+ Dialect extends string,
860
+ TextDb extends Expression.DbType.Any,
861
+ NumericDb extends Expression.DbType.Any,
862
+ BoolDb extends Expression.DbType.Any,
863
+ TimestampDb extends Expression.DbType.Any,
864
+ NullDb extends Expression.DbType.Any
865
+ > = PredicateStateFacts<PlanPredicateStateAfterHaving<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
866
+
867
+ type PlanPredicateStateAfterJoin<
810
868
  PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
811
869
  Predicate extends PredicateInput,
812
870
  Kind extends QueryAst.JoinKind,
@@ -817,11 +875,35 @@ type PlanAssumptionsAfterJoin<
817
875
  TimestampDb extends Expression.DbType.Any,
818
876
  NullDb extends Expression.DbType.Any
819
877
  > = Kind extends "inner"
820
- ? AssumeTrue<
821
- AssumptionsOfPlan<PlanValue>,
878
+ ? AssumePredicateStateTrue<
879
+ PredicateStateOfPlan<PlanValue>,
822
880
  DialectAsExpression<Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
823
881
  >
824
- : AssumptionsOfPlan<PlanValue>
882
+ : PredicateStateOfPlan<PlanValue>
883
+
884
+ type PlanAssumptionsAfterJoin<
885
+ PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
886
+ Predicate extends PredicateInput,
887
+ Kind extends QueryAst.JoinKind,
888
+ Dialect extends string,
889
+ TextDb extends Expression.DbType.Any,
890
+ NumericDb extends Expression.DbType.Any,
891
+ BoolDb extends Expression.DbType.Any,
892
+ TimestampDb extends Expression.DbType.Any,
893
+ NullDb extends Expression.DbType.Any
894
+ > = PredicateStateFormula<PlanPredicateStateAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
895
+
896
+ type PlanFactsAfterJoin<
897
+ PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
898
+ Predicate extends PredicateInput,
899
+ Kind extends QueryAst.JoinKind,
900
+ Dialect extends string,
901
+ TextDb extends Expression.DbType.Any,
902
+ NumericDb extends Expression.DbType.Any,
903
+ BoolDb extends Expression.DbType.Any,
904
+ TimestampDb extends Expression.DbType.Any,
905
+ NullDb extends Expression.DbType.Any
906
+ > = PredicateStateFacts<PlanPredicateStateAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
825
907
 
826
908
  type ScalarSubqueryInput<
827
909
  PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
@@ -1480,6 +1562,42 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1480
1562
  >
1481
1563
  }
1482
1564
 
1565
+ const retargetLiteralExpression = (
1566
+ value: Expression.Any,
1567
+ target: Expression.Any
1568
+ ): Expression.Any => {
1569
+ const ast = (value as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1570
+ if (ast.kind !== "literal") {
1571
+ return value
1572
+ }
1573
+ const targetState = target[Expression.TypeId]
1574
+ return makeExpression({
1575
+ runtime: value[Expression.TypeId].runtime,
1576
+ dbType: targetState.dbType,
1577
+ runtimeSchema: targetState.runtimeSchema,
1578
+ driverValueMapping: targetState.driverValueMapping,
1579
+ nullability: value[Expression.TypeId].nullability,
1580
+ dialect: targetState.dialect,
1581
+ kind: "scalar",
1582
+ dependencies: {}
1583
+ }, ast)
1584
+ }
1585
+
1586
+ const alignBinaryPredicateExpressions = (
1587
+ left: Expression.Any,
1588
+ right: Expression.Any
1589
+ ): readonly [Expression.Any, Expression.Any] => {
1590
+ const leftAst = (left as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1591
+ const rightAst = (right as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1592
+ if (leftAst.kind === "literal" && rightAst.kind !== "literal") {
1593
+ return [retargetLiteralExpression(left, right), right]
1594
+ }
1595
+ if (rightAst.kind === "literal" && leftAst.kind !== "literal") {
1596
+ return [left, retargetLiteralExpression(right, left)]
1597
+ }
1598
+ return [left, right]
1599
+ }
1600
+
1483
1601
  const toDialectStringExpression = <Value extends StringExpressionInput>(
1484
1602
  value: Value
1485
1603
  ): DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> =>
@@ -1657,8 +1775,10 @@ type BinaryPredicateExpression<
1657
1775
  kind: Kind,
1658
1776
  nullability: Nullability = "maybe" as Nullability,
1659
1777
  ): any => {
1660
- const leftExpression = toDialectExpression(left)
1661
- const rightExpression = toDialectExpression(right)
1778
+ const [leftExpression, rightExpression] = alignBinaryPredicateExpressions(
1779
+ toDialectExpression(left),
1780
+ toDialectExpression(right)
1781
+ )
1662
1782
  return (makeExpression as any)({
1663
1783
  runtime: true as boolean,
1664
1784
  dbType: profile.boolDb as BoolDb,
@@ -1681,17 +1801,21 @@ type BinaryPredicateExpression<
1681
1801
  kind: ExpressionAst.VariadicKind
1682
1802
  ): Expression.Any => {
1683
1803
  const expressions = values.map((value) => toDialectExpression(value as any)) as readonly Expression.Any[]
1804
+ const [head, ...tail] = expressions
1805
+ const alignedExpressions = (head !== undefined && (kind === "in" || kind === "notIn" || kind === "between"))
1806
+ ? [head, ...tail.map((value) => retargetLiteralExpression(value, head))]
1807
+ : expressions
1684
1808
  return makeExpression({
1685
1809
  runtime: true as boolean,
1686
1810
  dbType: profile.boolDb as BoolDb,
1687
1811
  nullability: "maybe",
1688
- dialect: (expressions.find((value) => value[Expression.TypeId].dialect !== undefined)?.[Expression.TypeId].dialect ?? profile.dialect) as Dialect,
1812
+ dialect: (alignedExpressions.find((value) => value[Expression.TypeId].dialect !== undefined)?.[Expression.TypeId].dialect ?? profile.dialect) as Dialect,
1689
1813
  kind: "scalar",
1690
1814
 
1691
- dependencies: mergeManyDependencies(expressions)
1815
+ dependencies: mergeManyDependencies(alignedExpressions)
1692
1816
  }, {
1693
1817
  kind,
1694
- values: expressions
1818
+ values: alignedExpressions
1695
1819
  })
1696
1820
  }
1697
1821
 
@@ -1960,6 +2084,7 @@ type BinaryPredicateExpression<
1960
2084
  runtime: undefined as unknown as RuntimeOfDbType<Target>,
1961
2085
  dbType: target as Target,
1962
2086
  runtimeSchema: undefined,
2087
+ driverValueMapping: (target as Expression.DbType.Any).driverValueMapping,
1963
2088
  nullability: expression[Expression.TypeId].nullability,
1964
2089
  dialect: expression[Expression.TypeId].dialect,
1965
2090
  kind: expression[Expression.TypeId].kind,
@@ -2039,6 +2164,14 @@ type BinaryPredicateExpression<
2039
2164
  kind
2040
2165
  })
2041
2166
 
2167
+ const driverValueMapping = <Db extends Expression.DbType.Any>(
2168
+ dbType: Db,
2169
+ mapping: Expression.DriverValueMapping
2170
+ ): Db => ({
2171
+ ...dbType,
2172
+ driverValueMapping: mapping
2173
+ })
2174
+
2042
2175
  const type = {
2043
2176
  ...profile.type,
2044
2177
  array,
@@ -2048,7 +2181,8 @@ type BinaryPredicateExpression<
2048
2181
  domain,
2049
2182
  enum: enum_,
2050
2183
  set,
2051
- custom
2184
+ custom,
2185
+ driverValueMapping
2052
2186
  }
2053
2187
 
2054
2188
  const makeJsonDb = <Kind extends string>(
@@ -2993,12 +3127,12 @@ type BinaryPredicateExpression<
2993
3127
  }
2994
3128
 
2995
3129
  const and = <
2996
- Values extends readonly [ExpressionInput, ...ExpressionInput[]]
3130
+ const Values extends readonly [ExpressionInput, ...ExpressionInput[]]
2997
3131
  >(
2998
3132
  ...values: Values
2999
3133
  ): VariadicBooleanExpression<
3000
3134
  "and",
3001
- { readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[],
3135
+ DialectExpressionArray<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
3002
3136
  Dialect,
3003
3137
  TextDb,
3004
3138
  NumericDb,
@@ -3008,16 +3142,16 @@ type BinaryPredicateExpression<
3008
3142
  > =>
3009
3143
  makeVariadicBooleanExpression(
3010
3144
  "and",
3011
- values.map((value) => toDialectExpression(value)) as { readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]
3145
+ values.map((value) => toDialectExpression(value)) as unknown as DialectExpressionArray<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
3012
3146
  )
3013
3147
 
3014
3148
  const or = <
3015
- Values extends readonly [ExpressionInput, ...ExpressionInput[]]
3149
+ const Values extends readonly [ExpressionInput, ...ExpressionInput[]]
3016
3150
  >(
3017
3151
  ...values: Values
3018
3152
  ): VariadicBooleanExpression<
3019
3153
  "or",
3020
- { readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[],
3154
+ DialectExpressionArray<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
3021
3155
  Dialect,
3022
3156
  TextDb,
3023
3157
  NumericDb,
@@ -3027,7 +3161,7 @@ type BinaryPredicateExpression<
3027
3161
  > =>
3028
3162
  makeVariadicBooleanExpression(
3029
3163
  "or",
3030
- values.map((value) => toDialectExpression(value)) as { readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]
3164
+ values.map((value) => toDialectExpression(value)) as unknown as DialectExpressionArray<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
3031
3165
  )
3032
3166
 
3033
3167
  const not = <Value extends ExpressionInput>(
@@ -3261,6 +3395,8 @@ type BinaryPredicateExpression<
3261
3395
  return makeExpression({
3262
3396
  runtime: undefined as Expression.RuntimeOf<ScalarOutputOfPlan<PlanValue>> | null,
3263
3397
  dbType: expression[Expression.TypeId].dbType as Expression.DbTypeOf<ScalarOutputOfPlan<PlanValue>>,
3398
+ runtimeSchema: expression[Expression.TypeId].runtimeSchema,
3399
+ driverValueMapping: expression[Expression.TypeId].driverValueMapping,
3264
3400
  nullability: "maybe",
3265
3401
  dialect: profile.dialect as Dialect,
3266
3402
  kind: "scalar",
@@ -3804,6 +3940,7 @@ type BinaryPredicateExpression<
3804
3940
  runtime: undefined as Expression.RuntimeOf<Value>,
3805
3941
  dbType: value[Expression.TypeId].dbType as Expression.DbTypeOf<Value>,
3806
3942
  runtimeSchema: value[Expression.TypeId].runtimeSchema,
3943
+ driverValueMapping: value[Expression.TypeId].driverValueMapping,
3807
3944
  nullability: value[Expression.TypeId].nullability as Expression.NullabilityOf<Value>,
3808
3945
  dialect: profile.dialect as Dialect,
3809
3946
  kind: "scalar",
@@ -3828,11 +3965,13 @@ type BinaryPredicateExpression<
3828
3965
  column: Expression.Any
3829
3966
  ): Expression.Any => {
3830
3967
  if (value !== null && typeof value === "object" && Expression.TypeId in value) {
3831
- return value as unknown as Expression.Any
3968
+ return retargetLiteralExpression(value as unknown as Expression.Any, column)
3832
3969
  }
3833
3970
  return makeExpression({
3834
3971
  runtime: value as Value,
3835
3972
  dbType: column[Expression.TypeId].dbType,
3973
+ runtimeSchema: column[Expression.TypeId].runtimeSchema,
3974
+ driverValueMapping: column[Expression.TypeId].driverValueMapping,
3836
3975
  nullability: value === null ? "always" : "never",
3837
3976
  dialect: column[Expression.TypeId].dialect,
3838
3977
  kind: "scalar",
@@ -3907,6 +4046,7 @@ type BinaryPredicateExpression<
3907
4046
  runtime: undefined as never,
3908
4047
  dbType: state.dbType,
3909
4048
  runtimeSchema: state.runtimeSchema,
4049
+ driverValueMapping: state.driverValueMapping,
3910
4050
  nullability: state.nullability,
3911
4051
  dialect: state.dialect,
3912
4052
  kind: "scalar",
@@ -4607,7 +4747,10 @@ type SelectFromResult<
4607
4747
  Exclude<OutstandingOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
4608
4748
  AssumptionsOfPlan<PlanValue>,
4609
4749
  MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentSource>>,
4610
- StatementOfPlan<PlanValue>
4750
+ StatementOfPlan<PlanValue>,
4751
+ MutationTargetOfPlan<PlanValue>,
4752
+ InsertSourceStateOfPlan<PlanValue>,
4753
+ FactsOfPlan<PlanValue>
4611
4754
  >
4612
4755
 
4613
4756
  type UpdateFromResult<
@@ -4629,7 +4772,10 @@ type UpdateFromResult<
4629
4772
  Exclude<OutstandingOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
4630
4773
  AssumptionsOfPlan<PlanValue>,
4631
4774
  MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentSource>>,
4632
- StatementOfPlan<PlanValue>
4775
+ StatementOfPlan<PlanValue>,
4776
+ MutationTargetOfPlan<PlanValue>,
4777
+ InsertSourceStateOfPlan<PlanValue>,
4778
+ FactsOfPlan<PlanValue>
4633
4779
  >
4634
4780
 
4635
4781
  type InsertFromResult<
@@ -4650,7 +4796,8 @@ type InsertFromResult<
4650
4796
  : CapabilitiesOfPlan<PlanValue>,
4651
4797
  StatementOfPlan<PlanValue>,
4652
4798
  MutationTargetOfPlan<PlanValue>,
4653
- "ready"
4799
+ "ready",
4800
+ FactsOfPlan<PlanValue>
4654
4801
  >
4655
4802
 
4656
4803
  type FromPlanConstraint<
@@ -4996,7 +5143,10 @@ type AsCurriedResult<
4996
5143
  ExtractRequired<Selection>,
4997
5144
  TrueFormula,
4998
5145
  "read",
4999
- "select"
5146
+ "select",
5147
+ any,
5148
+ "ready",
5149
+ EmptyFacts
5000
5150
  >
5001
5151
 
5002
5152
  const {
@@ -5067,7 +5217,10 @@ type AsCurriedResult<
5067
5217
  AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Predicate>,
5068
5218
  PlanAssumptionsAfterWhere<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5069
5219
  CapabilitiesOfPlan<PlanValue>,
5070
- StatementOfPlan<PlanValue>
5220
+ StatementOfPlan<PlanValue>,
5221
+ MutationTargetOfPlan<PlanValue>,
5222
+ InsertSourceStateOfPlan<PlanValue>,
5223
+ PlanFactsAfterWhere<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
5071
5224
  >
5072
5225
 
5073
5226
  export type FromApi = <CurrentSource extends FromInput>(
@@ -5092,7 +5245,10 @@ type AsCurriedResult<
5092
5245
  AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Predicate>,
5093
5246
  PlanAssumptionsAfterHaving<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5094
5247
  CapabilitiesOfPlan<PlanValue>,
5095
- StatementOfPlan<PlanValue>
5248
+ StatementOfPlan<PlanValue>,
5249
+ MutationTargetOfPlan<PlanValue>,
5250
+ InsertSourceStateOfPlan<PlanValue>,
5251
+ PlanFactsAfterHaving<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
5096
5252
  >
5097
5253
 
5098
5254
  type CrossJoinApi = <CurrentTable extends SourceLike>(
@@ -5154,7 +5310,10 @@ type AsCurriedResult<
5154
5310
  AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind>,
5155
5311
  PlanAssumptionsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5156
5312
  MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>,
5157
- StatementOfPlan<PlanValue>
5313
+ StatementOfPlan<PlanValue>,
5314
+ MutationTargetOfPlan<PlanValue>,
5315
+ InsertSourceStateOfPlan<PlanValue>,
5316
+ PlanFactsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
5158
5317
  >
5159
5318
 
5160
5319
  type BinaryJoinApi<Kind extends QueryAst.JoinKind> = <
@@ -5186,7 +5345,10 @@ type AsCurriedResult<
5186
5345
  AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind>,
5187
5346
  PlanAssumptionsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5188
5347
  MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>,
5189
- StatementOfPlan<PlanValue>
5348
+ StatementOfPlan<PlanValue>,
5349
+ MutationTargetOfPlan<PlanValue>,
5350
+ InsertSourceStateOfPlan<PlanValue>,
5351
+ PlanFactsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
5190
5352
  >
5191
5353
 
5192
5354
  type OrderByApi = <Value extends ExpressionInput>(
@@ -5205,7 +5367,10 @@ type AsCurriedResult<
5205
5367
  AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Value>,
5206
5368
  AssumptionsOfPlan<PlanValue>,
5207
5369
  CapabilitiesOfPlan<PlanValue>,
5208
- StatementOfPlan<PlanValue>
5370
+ StatementOfPlan<PlanValue>,
5371
+ MutationTargetOfPlan<PlanValue>,
5372
+ InsertSourceStateOfPlan<PlanValue>,
5373
+ FactsOfPlan<PlanValue>
5209
5374
  >
5210
5375
 
5211
5376
  interface LockApi {
@@ -5221,7 +5386,10 @@ type AsCurriedResult<
5221
5386
  OutstandingOfPlan<PlanValue>,
5222
5387
  AssumptionsOfPlan<PlanValue>,
5223
5388
  MergeCapabilities<CapabilitiesOfPlan<PlanValue>, "transaction">,
5224
- StatementOfPlan<PlanValue>
5389
+ StatementOfPlan<PlanValue>,
5390
+ MutationTargetOfPlan<PlanValue>,
5391
+ InsertSourceStateOfPlan<PlanValue>,
5392
+ FactsOfPlan<PlanValue>
5225
5393
  >
5226
5394
  <Mode extends Dialect extends "mysql" ? "lowPriority" | "ignore" | "quick" : never>(
5227
5395
  mode: Mode,
@@ -5246,7 +5414,10 @@ type AsCurriedResult<
5246
5414
  OutstandingOfPlan<PlanValue>,
5247
5415
  AssumptionsOfPlan<PlanValue>,
5248
5416
  MergeCapabilities<CapabilitiesOfPlan<PlanValue>, "transaction">,
5249
- StatementOfPlan<PlanValue>
5417
+ StatementOfPlan<PlanValue>,
5418
+ MutationTargetOfPlan<PlanValue>,
5419
+ InsertSourceStateOfPlan<PlanValue>,
5420
+ FactsOfPlan<PlanValue>
5250
5421
  >
5251
5422
  }
5252
5423
 
@@ -5263,7 +5434,10 @@ type AsCurriedResult<
5263
5434
  OutstandingOfPlan<PlanValue>,
5264
5435
  AssumptionsOfPlan<PlanValue>,
5265
5436
  CapabilitiesOfPlan<PlanValue>,
5266
- StatementOfPlan<PlanValue>
5437
+ StatementOfPlan<PlanValue>,
5438
+ MutationTargetOfPlan<PlanValue>,
5439
+ InsertSourceStateOfPlan<PlanValue>,
5440
+ FactsOfPlan<PlanValue>
5267
5441
  >
5268
5442
 
5269
5443
  type LimitApi = <Value extends NumericExpressionInput>(
@@ -5281,7 +5455,10 @@ type AsCurriedResult<
5281
5455
  AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, DialectAsNumericExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
5282
5456
  AssumptionsOfPlan<PlanValue>,
5283
5457
  CapabilitiesOfPlan<PlanValue>,
5284
- StatementOfPlan<PlanValue>
5458
+ StatementOfPlan<PlanValue>,
5459
+ MutationTargetOfPlan<PlanValue>,
5460
+ InsertSourceStateOfPlan<PlanValue>,
5461
+ FactsOfPlan<PlanValue>
5285
5462
  >
5286
5463
 
5287
5464
  type OffsetApi = <Value extends NumericExpressionInput>(
@@ -5299,7 +5476,10 @@ type AsCurriedResult<
5299
5476
  AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, DialectAsNumericExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
5300
5477
  AssumptionsOfPlan<PlanValue>,
5301
5478
  CapabilitiesOfPlan<PlanValue>,
5302
- StatementOfPlan<PlanValue>
5479
+ StatementOfPlan<PlanValue>,
5480
+ MutationTargetOfPlan<PlanValue>,
5481
+ InsertSourceStateOfPlan<PlanValue>,
5482
+ FactsOfPlan<PlanValue>
5303
5483
  >
5304
5484
 
5305
5485
  const {
@@ -5391,7 +5571,10 @@ type AsCurriedResult<
5391
5571
  Exclude<OutstandingOfPlan<PlanValue> | RequiredFromDependencies<TupleDependencies<Values>>, AvailableNames<AvailableOfPlan<PlanValue>>>,
5392
5572
  AssumptionsOfPlan<PlanValue>,
5393
5573
  CapabilitiesOfPlan<PlanValue>,
5394
- StatementOfPlan<PlanValue>
5574
+ StatementOfPlan<PlanValue>,
5575
+ MutationTargetOfPlan<PlanValue>,
5576
+ InsertSourceStateOfPlan<PlanValue>,
5577
+ FactsOfPlan<PlanValue>
5395
5578
  >
5396
5579
 
5397
5580
  type ReturningApi = <Selection extends SelectionShape>(
@@ -5411,7 +5594,8 @@ type AsCurriedResult<
5411
5594
  CapabilitiesOfPlan<PlanValue>,
5412
5595
  StatementOfPlan<PlanValue>,
5413
5596
  MutationTargetOfPlan<PlanValue>,
5414
- InsertSourceStateOfPlan<PlanValue>
5597
+ InsertSourceStateOfPlan<PlanValue>,
5598
+ FactsOfPlan<PlanValue>
5415
5599
  >
5416
5600
 
5417
5601
  export interface InsertApi {
@@ -5429,7 +5613,8 @@ type AsCurriedResult<
5429
5613
  "write",
5430
5614
  "insert",
5431
5615
  Target,
5432
- "missing"
5616
+ "missing",
5617
+ EmptyFacts
5433
5618
  >
5434
5619
  <Target extends MutationTargetLike, Values extends Record<string, unknown>>(
5435
5620
  target: Target,
@@ -5446,7 +5631,8 @@ type AsCurriedResult<
5446
5631
  "write",
5447
5632
  "insert",
5448
5633
  Target,
5449
- "ready"
5634
+ "ready",
5635
+ EmptyFacts
5450
5636
  >
5451
5637
  }
5452
5638
 
@@ -5478,7 +5664,8 @@ type AsCurriedResult<
5478
5664
  CapabilitiesOfPlan<PlanValue>,
5479
5665
  StatementOfPlan<PlanValue>,
5480
5666
  MutationTargetOfPlan<PlanValue>,
5481
- InsertSourceStateOfPlan<PlanValue>
5667
+ InsertSourceStateOfPlan<PlanValue>,
5668
+ FactsOfPlan<PlanValue>
5482
5669
  >
5483
5670
 
5484
5671
  interface UpdateApi {
@@ -5495,7 +5682,10 @@ type AsCurriedResult<
5495
5682
  Exclude<NestedMutationRequiredFromValues<Values>, MutationTargetNamesOf<Targets>>,
5496
5683
  TrueFormula,
5497
5684
  "write",
5498
- "update"
5685
+ "update",
5686
+ any,
5687
+ "ready",
5688
+ EmptyFacts
5499
5689
  >
5500
5690
  <Target extends MutationTargetLike, Values extends Record<string, unknown>>(
5501
5691
  target: Target,
@@ -5510,7 +5700,10 @@ type AsCurriedResult<
5510
5700
  Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
5511
5701
  TrueFormula,
5512
5702
  "write",
5513
- "update"
5703
+ "update",
5704
+ any,
5705
+ "ready",
5706
+ EmptyFacts
5514
5707
  >
5515
5708
  }
5516
5709
 
@@ -5536,7 +5729,8 @@ type AsCurriedResult<
5536
5729
  "write",
5537
5730
  "insert",
5538
5731
  Target,
5539
- "ready"
5732
+ "ready",
5733
+ EmptyFacts
5540
5734
  >
5541
5735
 
5542
5736
  interface DeleteApi {
@@ -5552,7 +5746,10 @@ type AsCurriedResult<
5552
5746
  never,
5553
5747
  TrueFormula,
5554
5748
  "write",
5555
- "delete"
5749
+ "delete",
5750
+ any,
5751
+ "ready",
5752
+ EmptyFacts
5556
5753
  >
5557
5754
  <Targets extends MutationTargetTuple>(
5558
5755
  target: Dialect extends "mysql" ? Targets : never
@@ -5566,7 +5763,10 @@ type AsCurriedResult<
5566
5763
  never,
5567
5764
  TrueFormula,
5568
5765
  "write",
5569
- "delete"
5766
+ "delete",
5767
+ any,
5768
+ "ready",
5769
+ EmptyFacts
5570
5770
  >
5571
5771
  }
5572
5772
 
@@ -5583,7 +5783,10 @@ type AsCurriedResult<
5583
5783
  never,
5584
5784
  TrueFormula,
5585
5785
  "write",
5586
- "truncate"
5786
+ "truncate",
5787
+ any,
5788
+ "ready",
5789
+ EmptyFacts
5587
5790
  >
5588
5791
 
5589
5792
  type MergeApi = <
@@ -5637,7 +5840,10 @@ type AsCurriedResult<
5637
5840
  >,
5638
5841
  TrueFormula,
5639
5842
  MergeCapabilities<"write", SourceCapabilitiesOf<Source>>,
5640
- "merge"
5843
+ "merge",
5844
+ any,
5845
+ "ready",
5846
+ EmptyFacts
5641
5847
  >
5642
5848
 
5643
5849
  const mutationRuntime = makeDslMutationRuntime({
@@ -5692,7 +5898,8 @@ type AsCurriedResult<
5692
5898
  CapabilitiesOfPlan<PlanValue>,
5693
5899
  StatementOfPlan<PlanValue>,
5694
5900
  MutationTargetOfPlan<PlanValue>,
5695
- InsertSourceStateOfPlan<PlanValue>
5901
+ InsertSourceStateOfPlan<PlanValue>,
5902
+ FactsOfPlan<PlanValue>
5696
5903
  > => mutationRuntime.onConflict(target, options)(plan)
5697
5904
 
5698
5905
  const update: UpdateApi = ((
@@ -5722,7 +5929,8 @@ type AsCurriedResult<
5722
5929
  "write",
5723
5930
  "insert",
5724
5931
  Target,
5725
- "ready"
5932
+ "ready",
5933
+ EmptyFacts
5726
5934
  > => mutationRuntime.upsert(target, values, conflictColumns as string | readonly string[], updateValues)
5727
5935
 
5728
5936
  const delete_: DeleteApi = ((
@@ -5744,7 +5952,10 @@ type AsCurriedResult<
5744
5952
  never,
5745
5953
  TrueFormula,
5746
5954
  "write",
5747
- "truncate"
5955
+ "truncate",
5956
+ any,
5957
+ "ready",
5958
+ EmptyFacts
5748
5959
  > => mutationRuntime.truncate(target, options)
5749
5960
 
5750
5961
  const merge: MergeApi = <
@@ -5798,7 +6009,10 @@ type AsCurriedResult<
5798
6009
  >,
5799
6010
  TrueFormula,
5800
6011
  MergeCapabilities<"write", SourceCapabilitiesOf<Source>>,
5801
- "merge"
6012
+ "merge",
6013
+ any,
6014
+ "ready",
6015
+ EmptyFacts
5802
6016
  > => mutationRuntime.merge(target, source, on, options)
5803
6017
 
5804
6018
  type TransactionApi = (options?: TransactionOptions) => QueryPlan<