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>,
@@ -960,6 +1042,16 @@ type JsonPathInput = JsonPath.Path<any> | JsonPath.CanonicalSegment
960
1042
 
961
1043
  type JsonQueryInput = JsonPath.Path<any> | StringExpressionInput
962
1044
 
1045
+ type JsonPathSegmentsOf<Target extends JsonPathInput> =
1046
+ Target extends JsonPath.Path<any>
1047
+ ? JsonPath.SegmentsOf<Target>
1048
+ : readonly [Target]
1049
+
1050
+ type JsonTextAccessKind<Target extends JsonPathInput> =
1051
+ Target extends JsonPath.Path<any>
1052
+ ? JsonPath.IsExactPath<Target> extends true ? "jsonPathText" : "jsonTraverseText"
1053
+ : Target extends JsonPath.ExactSegment ? "jsonGetText" : "jsonAccessText"
1054
+
963
1055
  type JsonPathOutputOf<
964
1056
  Root,
965
1057
  Target extends JsonPathInput,
@@ -1480,6 +1572,42 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1480
1572
  >
1481
1573
  }
1482
1574
 
1575
+ const retargetLiteralExpression = (
1576
+ value: Expression.Any,
1577
+ target: Expression.Any
1578
+ ): Expression.Any => {
1579
+ const ast = (value as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1580
+ if (ast.kind !== "literal") {
1581
+ return value
1582
+ }
1583
+ const targetState = target[Expression.TypeId]
1584
+ return makeExpression({
1585
+ runtime: value[Expression.TypeId].runtime,
1586
+ dbType: targetState.dbType,
1587
+ runtimeSchema: targetState.runtimeSchema,
1588
+ driverValueMapping: targetState.driverValueMapping,
1589
+ nullability: value[Expression.TypeId].nullability,
1590
+ dialect: targetState.dialect,
1591
+ kind: "scalar",
1592
+ dependencies: {}
1593
+ }, ast)
1594
+ }
1595
+
1596
+ const alignBinaryPredicateExpressions = (
1597
+ left: Expression.Any,
1598
+ right: Expression.Any
1599
+ ): readonly [Expression.Any, Expression.Any] => {
1600
+ const leftAst = (left as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1601
+ const rightAst = (right as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1602
+ if (leftAst.kind === "literal" && rightAst.kind !== "literal") {
1603
+ return [retargetLiteralExpression(left, right), right]
1604
+ }
1605
+ if (rightAst.kind === "literal" && leftAst.kind !== "literal") {
1606
+ return [left, retargetLiteralExpression(right, left)]
1607
+ }
1608
+ return [left, right]
1609
+ }
1610
+
1483
1611
  const toDialectStringExpression = <Value extends StringExpressionInput>(
1484
1612
  value: Value
1485
1613
  ): DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> =>
@@ -1657,8 +1785,10 @@ type BinaryPredicateExpression<
1657
1785
  kind: Kind,
1658
1786
  nullability: Nullability = "maybe" as Nullability,
1659
1787
  ): any => {
1660
- const leftExpression = toDialectExpression(left)
1661
- const rightExpression = toDialectExpression(right)
1788
+ const [leftExpression, rightExpression] = alignBinaryPredicateExpressions(
1789
+ toDialectExpression(left),
1790
+ toDialectExpression(right)
1791
+ )
1662
1792
  return (makeExpression as any)({
1663
1793
  runtime: true as boolean,
1664
1794
  dbType: profile.boolDb as BoolDb,
@@ -1681,17 +1811,21 @@ type BinaryPredicateExpression<
1681
1811
  kind: ExpressionAst.VariadicKind
1682
1812
  ): Expression.Any => {
1683
1813
  const expressions = values.map((value) => toDialectExpression(value as any)) as readonly Expression.Any[]
1814
+ const [head, ...tail] = expressions
1815
+ const alignedExpressions = (head !== undefined && (kind === "in" || kind === "notIn" || kind === "between"))
1816
+ ? [head, ...tail.map((value) => retargetLiteralExpression(value, head))]
1817
+ : expressions
1684
1818
  return makeExpression({
1685
1819
  runtime: true as boolean,
1686
1820
  dbType: profile.boolDb as BoolDb,
1687
1821
  nullability: "maybe",
1688
- dialect: (expressions.find((value) => value[Expression.TypeId].dialect !== undefined)?.[Expression.TypeId].dialect ?? profile.dialect) as Dialect,
1822
+ dialect: (alignedExpressions.find((value) => value[Expression.TypeId].dialect !== undefined)?.[Expression.TypeId].dialect ?? profile.dialect) as Dialect,
1689
1823
  kind: "scalar",
1690
1824
 
1691
- dependencies: mergeManyDependencies(expressions)
1825
+ dependencies: mergeManyDependencies(alignedExpressions)
1692
1826
  }, {
1693
1827
  kind,
1694
- values: expressions
1828
+ values: alignedExpressions
1695
1829
  })
1696
1830
  }
1697
1831
 
@@ -1997,6 +2131,7 @@ type BinaryPredicateExpression<
1997
2131
  runtime: undefined as unknown as RuntimeOfDbType<Target>,
1998
2132
  dbType: target as Target,
1999
2133
  runtimeSchema: undefined,
2134
+ driverValueMapping: (target as Expression.DbType.Any).driverValueMapping,
2000
2135
  nullability: expression[Expression.TypeId].nullability,
2001
2136
  dialect: expression[Expression.TypeId].dialect,
2002
2137
  kind: expression[Expression.TypeId].kind,
@@ -2076,6 +2211,14 @@ type BinaryPredicateExpression<
2076
2211
  kind
2077
2212
  })
2078
2213
 
2214
+ const driverValueMapping = <Db extends Expression.DbType.Any>(
2215
+ dbType: Db,
2216
+ mapping: Expression.DriverValueMapping
2217
+ ): Db => ({
2218
+ ...dbType,
2219
+ driverValueMapping: mapping
2220
+ })
2221
+
2079
2222
  const type = {
2080
2223
  ...profile.type,
2081
2224
  array,
@@ -2085,7 +2228,8 @@ type BinaryPredicateExpression<
2085
2228
  domain,
2086
2229
  enum: enum_,
2087
2230
  set,
2088
- custom
2231
+ custom,
2232
+ driverValueMapping
2089
2233
  }
2090
2234
 
2091
2235
  const makeJsonDb = <Kind extends string>(
@@ -2273,7 +2417,7 @@ type BinaryPredicateExpression<
2273
2417
  DialectOf<Base>,
2274
2418
  KindOf<Base>,
2275
2419
  DependenciesOf<Base>,
2276
- JsonNode
2420
+ ExpressionAst.JsonAccessNode<JsonTextAccessKind<Target>, Base, JsonPathSegmentsOf<Target>>
2277
2421
  > => {
2278
2422
  const segments = normalizeJsonPathInput(target)
2279
2423
  const kind = isJsonPathValue(target)
@@ -2300,7 +2444,7 @@ type BinaryPredicateExpression<
2300
2444
  DialectOf<Base>,
2301
2445
  KindOf<Base>,
2302
2446
  DependenciesOf<Base>,
2303
- JsonNode
2447
+ ExpressionAst.JsonAccessNode<JsonTextAccessKind<Target>, Base, JsonPathSegmentsOf<Target>>
2304
2448
  >
2305
2449
  }
2306
2450
 
@@ -3027,12 +3171,12 @@ type BinaryPredicateExpression<
3027
3171
  }
3028
3172
 
3029
3173
  const and = <
3030
- Values extends readonly [ExpressionInput, ...ExpressionInput[]]
3174
+ const Values extends readonly [ExpressionInput, ...ExpressionInput[]]
3031
3175
  >(
3032
3176
  ...values: Values
3033
3177
  ): VariadicBooleanExpression<
3034
3178
  "and",
3035
- { readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[],
3179
+ DialectExpressionArray<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
3036
3180
  Dialect,
3037
3181
  TextDb,
3038
3182
  NumericDb,
@@ -3042,16 +3186,16 @@ type BinaryPredicateExpression<
3042
3186
  > =>
3043
3187
  makeVariadicBooleanExpression(
3044
3188
  "and",
3045
- values.map((value) => toDialectExpression(value)) as { readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]
3189
+ values.map((value) => toDialectExpression(value)) as unknown as DialectExpressionArray<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
3046
3190
  )
3047
3191
 
3048
3192
  const or = <
3049
- Values extends readonly [ExpressionInput, ...ExpressionInput[]]
3193
+ const Values extends readonly [ExpressionInput, ...ExpressionInput[]]
3050
3194
  >(
3051
3195
  ...values: Values
3052
3196
  ): VariadicBooleanExpression<
3053
3197
  "or",
3054
- { readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[],
3198
+ DialectExpressionArray<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
3055
3199
  Dialect,
3056
3200
  TextDb,
3057
3201
  NumericDb,
@@ -3061,7 +3205,7 @@ type BinaryPredicateExpression<
3061
3205
  > =>
3062
3206
  makeVariadicBooleanExpression(
3063
3207
  "or",
3064
- values.map((value) => toDialectExpression(value)) as { readonly [K in keyof Values]: DialectAsExpression<Values[K], Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> } & readonly Expression.Any[]
3208
+ values.map((value) => toDialectExpression(value)) as unknown as DialectExpressionArray<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
3065
3209
  )
3066
3210
 
3067
3211
  const not = <Value extends ExpressionInput>(
@@ -3295,6 +3439,8 @@ type BinaryPredicateExpression<
3295
3439
  return makeExpression({
3296
3440
  runtime: undefined as Expression.RuntimeOf<ScalarOutputOfPlan<PlanValue>> | null,
3297
3441
  dbType: expression[Expression.TypeId].dbType as Expression.DbTypeOf<ScalarOutputOfPlan<PlanValue>>,
3442
+ runtimeSchema: expression[Expression.TypeId].runtimeSchema,
3443
+ driverValueMapping: expression[Expression.TypeId].driverValueMapping,
3298
3444
  nullability: "maybe",
3299
3445
  dialect: profile.dialect as Dialect,
3300
3446
  kind: "scalar",
@@ -3838,6 +3984,7 @@ type BinaryPredicateExpression<
3838
3984
  runtime: undefined as Expression.RuntimeOf<Value>,
3839
3985
  dbType: value[Expression.TypeId].dbType as Expression.DbTypeOf<Value>,
3840
3986
  runtimeSchema: value[Expression.TypeId].runtimeSchema,
3987
+ driverValueMapping: value[Expression.TypeId].driverValueMapping,
3841
3988
  nullability: value[Expression.TypeId].nullability as Expression.NullabilityOf<Value>,
3842
3989
  dialect: profile.dialect as Dialect,
3843
3990
  kind: "scalar",
@@ -3862,11 +4009,13 @@ type BinaryPredicateExpression<
3862
4009
  column: Expression.Any
3863
4010
  ): Expression.Any => {
3864
4011
  if (value !== null && typeof value === "object" && Expression.TypeId in value) {
3865
- return value as unknown as Expression.Any
4012
+ return retargetLiteralExpression(value as unknown as Expression.Any, column)
3866
4013
  }
3867
4014
  return makeExpression({
3868
4015
  runtime: value as Value,
3869
4016
  dbType: column[Expression.TypeId].dbType,
4017
+ runtimeSchema: column[Expression.TypeId].runtimeSchema,
4018
+ driverValueMapping: column[Expression.TypeId].driverValueMapping,
3870
4019
  nullability: value === null ? "always" : "never",
3871
4020
  dialect: column[Expression.TypeId].dialect,
3872
4021
  kind: "scalar",
@@ -3941,6 +4090,7 @@ type BinaryPredicateExpression<
3941
4090
  runtime: undefined as never,
3942
4091
  dbType: state.dbType,
3943
4092
  runtimeSchema: state.runtimeSchema,
4093
+ driverValueMapping: state.driverValueMapping,
3944
4094
  nullability: state.nullability,
3945
4095
  dialect: state.dialect,
3946
4096
  kind: "scalar",
@@ -4332,7 +4482,10 @@ type DistinctOnApi<Dialect extends string> = Dialect extends "postgres"
4332
4482
  OutstandingOfPlan<PlanValue>,
4333
4483
  AssumptionsOfPlan<PlanValue>,
4334
4484
  CapabilitiesOfPlan<PlanValue>,
4335
- StatementOfPlan<PlanValue>
4485
+ StatementOfPlan<PlanValue>,
4486
+ MutationTargetOfPlan<PlanValue>,
4487
+ InsertSourceStateOfPlan<PlanValue>,
4488
+ FactsOfPlan<PlanValue>
4336
4489
  >
4337
4490
  : DistinctOnUnsupportedError<Dialect>
4338
4491
 
@@ -4641,7 +4794,10 @@ type SelectFromResult<
4641
4794
  Exclude<OutstandingOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
4642
4795
  AssumptionsOfPlan<PlanValue>,
4643
4796
  MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentSource>>,
4644
- StatementOfPlan<PlanValue>
4797
+ StatementOfPlan<PlanValue>,
4798
+ MutationTargetOfPlan<PlanValue>,
4799
+ InsertSourceStateOfPlan<PlanValue>,
4800
+ FactsOfPlan<PlanValue>
4645
4801
  >
4646
4802
 
4647
4803
  type UpdateFromResult<
@@ -4663,7 +4819,10 @@ type UpdateFromResult<
4663
4819
  Exclude<OutstandingOfPlan<PlanValue>, SourceNameOf<CurrentSource>>,
4664
4820
  AssumptionsOfPlan<PlanValue>,
4665
4821
  MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentSource>>,
4666
- StatementOfPlan<PlanValue>
4822
+ StatementOfPlan<PlanValue>,
4823
+ MutationTargetOfPlan<PlanValue>,
4824
+ InsertSourceStateOfPlan<PlanValue>,
4825
+ FactsOfPlan<PlanValue>
4667
4826
  >
4668
4827
 
4669
4828
  type InsertFromResult<
@@ -4684,7 +4843,8 @@ type InsertFromResult<
4684
4843
  : CapabilitiesOfPlan<PlanValue>,
4685
4844
  StatementOfPlan<PlanValue>,
4686
4845
  MutationTargetOfPlan<PlanValue>,
4687
- "ready"
4846
+ "ready",
4847
+ FactsOfPlan<PlanValue>
4688
4848
  >
4689
4849
 
4690
4850
  type FromPlanConstraint<
@@ -5046,7 +5206,10 @@ type AsCurriedResult<
5046
5206
  ExtractRequired<Selection>,
5047
5207
  TrueFormula,
5048
5208
  "read",
5049
- "select"
5209
+ "select",
5210
+ any,
5211
+ "ready",
5212
+ EmptyFacts
5050
5213
  >
5051
5214
 
5052
5215
  const {
@@ -5117,7 +5280,10 @@ type AsCurriedResult<
5117
5280
  AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Predicate>,
5118
5281
  PlanAssumptionsAfterWhere<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5119
5282
  CapabilitiesOfPlan<PlanValue>,
5120
- StatementOfPlan<PlanValue>
5283
+ StatementOfPlan<PlanValue>,
5284
+ MutationTargetOfPlan<PlanValue>,
5285
+ InsertSourceStateOfPlan<PlanValue>,
5286
+ PlanFactsAfterWhere<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
5121
5287
  >
5122
5288
 
5123
5289
  export type FromApi = <CurrentSource extends FromInput>(
@@ -5142,7 +5308,10 @@ type AsCurriedResult<
5142
5308
  AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Predicate>,
5143
5309
  PlanAssumptionsAfterHaving<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5144
5310
  CapabilitiesOfPlan<PlanValue>,
5145
- StatementOfPlan<PlanValue>
5311
+ StatementOfPlan<PlanValue>,
5312
+ MutationTargetOfPlan<PlanValue>,
5313
+ InsertSourceStateOfPlan<PlanValue>,
5314
+ PlanFactsAfterHaving<PlanValue, Predicate, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
5146
5315
  >
5147
5316
 
5148
5317
  type CrossJoinApi = <CurrentTable extends SourceLike>(
@@ -5204,7 +5373,10 @@ type AsCurriedResult<
5204
5373
  AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind>,
5205
5374
  PlanAssumptionsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5206
5375
  MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>,
5207
- StatementOfPlan<PlanValue>
5376
+ StatementOfPlan<PlanValue>,
5377
+ MutationTargetOfPlan<PlanValue>,
5378
+ InsertSourceStateOfPlan<PlanValue>,
5379
+ PlanFactsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
5208
5380
  >
5209
5381
 
5210
5382
  type BinaryJoinApi<Kind extends QueryAst.JoinKind> = <
@@ -5236,7 +5408,10 @@ type AsCurriedResult<
5236
5408
  AddJoinRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, SourceNameOf<CurrentTable>, Predicate, Kind>,
5237
5409
  PlanAssumptionsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5238
5410
  MergeCapabilities<CapabilitiesOfPlan<PlanValue>, SourceCapabilitiesOf<CurrentTable>>,
5239
- StatementOfPlan<PlanValue>
5411
+ StatementOfPlan<PlanValue>,
5412
+ MutationTargetOfPlan<PlanValue>,
5413
+ InsertSourceStateOfPlan<PlanValue>,
5414
+ PlanFactsAfterJoin<PlanValue, Predicate, Kind, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
5240
5415
  >
5241
5416
 
5242
5417
  type OrderByApi = <Value extends ExpressionInput>(
@@ -5255,7 +5430,10 @@ type AsCurriedResult<
5255
5430
  AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, Value>,
5256
5431
  AssumptionsOfPlan<PlanValue>,
5257
5432
  CapabilitiesOfPlan<PlanValue>,
5258
- StatementOfPlan<PlanValue>
5433
+ StatementOfPlan<PlanValue>,
5434
+ MutationTargetOfPlan<PlanValue>,
5435
+ InsertSourceStateOfPlan<PlanValue>,
5436
+ FactsOfPlan<PlanValue>
5259
5437
  >
5260
5438
 
5261
5439
  interface LockApi {
@@ -5271,7 +5449,10 @@ type AsCurriedResult<
5271
5449
  OutstandingOfPlan<PlanValue>,
5272
5450
  AssumptionsOfPlan<PlanValue>,
5273
5451
  MergeCapabilities<CapabilitiesOfPlan<PlanValue>, "transaction">,
5274
- StatementOfPlan<PlanValue>
5452
+ StatementOfPlan<PlanValue>,
5453
+ MutationTargetOfPlan<PlanValue>,
5454
+ InsertSourceStateOfPlan<PlanValue>,
5455
+ FactsOfPlan<PlanValue>
5275
5456
  >
5276
5457
  <Mode extends Dialect extends "mysql" ? "lowPriority" | "ignore" | "quick" : never>(
5277
5458
  mode: Mode,
@@ -5296,7 +5477,10 @@ type AsCurriedResult<
5296
5477
  OutstandingOfPlan<PlanValue>,
5297
5478
  AssumptionsOfPlan<PlanValue>,
5298
5479
  MergeCapabilities<CapabilitiesOfPlan<PlanValue>, "transaction">,
5299
- StatementOfPlan<PlanValue>
5480
+ StatementOfPlan<PlanValue>,
5481
+ MutationTargetOfPlan<PlanValue>,
5482
+ InsertSourceStateOfPlan<PlanValue>,
5483
+ FactsOfPlan<PlanValue>
5300
5484
  >
5301
5485
  }
5302
5486
 
@@ -5313,7 +5497,10 @@ type AsCurriedResult<
5313
5497
  OutstandingOfPlan<PlanValue>,
5314
5498
  AssumptionsOfPlan<PlanValue>,
5315
5499
  CapabilitiesOfPlan<PlanValue>,
5316
- StatementOfPlan<PlanValue>
5500
+ StatementOfPlan<PlanValue>,
5501
+ MutationTargetOfPlan<PlanValue>,
5502
+ InsertSourceStateOfPlan<PlanValue>,
5503
+ FactsOfPlan<PlanValue>
5317
5504
  >
5318
5505
 
5319
5506
  type LimitApi = <Value extends NumericExpressionInput>(
@@ -5331,7 +5518,10 @@ type AsCurriedResult<
5331
5518
  AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, DialectAsNumericExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
5332
5519
  AssumptionsOfPlan<PlanValue>,
5333
5520
  CapabilitiesOfPlan<PlanValue>,
5334
- StatementOfPlan<PlanValue>
5521
+ StatementOfPlan<PlanValue>,
5522
+ MutationTargetOfPlan<PlanValue>,
5523
+ InsertSourceStateOfPlan<PlanValue>,
5524
+ FactsOfPlan<PlanValue>
5335
5525
  >
5336
5526
 
5337
5527
  type OffsetApi = <Value extends NumericExpressionInput>(
@@ -5349,7 +5539,10 @@ type AsCurriedResult<
5349
5539
  AddExpressionRequired<OutstandingOfPlan<PlanValue>, AvailableOfPlan<PlanValue>, DialectAsNumericExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
5350
5540
  AssumptionsOfPlan<PlanValue>,
5351
5541
  CapabilitiesOfPlan<PlanValue>,
5352
- StatementOfPlan<PlanValue>
5542
+ StatementOfPlan<PlanValue>,
5543
+ MutationTargetOfPlan<PlanValue>,
5544
+ InsertSourceStateOfPlan<PlanValue>,
5545
+ FactsOfPlan<PlanValue>
5353
5546
  >
5354
5547
 
5355
5548
  const {
@@ -5448,7 +5641,7 @@ type AsCurriedResult<
5448
5641
  ...currentAst,
5449
5642
  distinct: true,
5450
5643
  distinctOn: expressions
5451
- }, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement as StatementOfPlan<PlanValue>)
5644
+ }, currentQuery.assumptions, currentQuery.capabilities, currentQuery.statement as StatementOfPlan<PlanValue>, currentQuery.target, currentQuery.insertSource, currentQuery.facts)
5452
5645
  }
5453
5646
  }) as DistinctOnApi<Dialect>
5454
5647
 
@@ -5467,7 +5660,10 @@ type AsCurriedResult<
5467
5660
  Exclude<OutstandingOfPlan<PlanValue> | RequiredFromDependencies<TupleDependencies<Values>>, AvailableNames<AvailableOfPlan<PlanValue>>>,
5468
5661
  AssumptionsOfPlan<PlanValue>,
5469
5662
  CapabilitiesOfPlan<PlanValue>,
5470
- StatementOfPlan<PlanValue>
5663
+ StatementOfPlan<PlanValue>,
5664
+ MutationTargetOfPlan<PlanValue>,
5665
+ InsertSourceStateOfPlan<PlanValue>,
5666
+ FactsOfPlan<PlanValue>
5471
5667
  >
5472
5668
 
5473
5669
  type ReturningApi = <Selection extends SelectionShape>(
@@ -5487,7 +5683,8 @@ type AsCurriedResult<
5487
5683
  CapabilitiesOfPlan<PlanValue>,
5488
5684
  StatementOfPlan<PlanValue>,
5489
5685
  MutationTargetOfPlan<PlanValue>,
5490
- InsertSourceStateOfPlan<PlanValue>
5686
+ InsertSourceStateOfPlan<PlanValue>,
5687
+ FactsOfPlan<PlanValue>
5491
5688
  >
5492
5689
 
5493
5690
  export interface InsertApi {
@@ -5505,7 +5702,8 @@ type AsCurriedResult<
5505
5702
  "write",
5506
5703
  "insert",
5507
5704
  Target,
5508
- "missing"
5705
+ "missing",
5706
+ EmptyFacts
5509
5707
  >
5510
5708
  <Target extends MutationTargetLike, Values extends Record<string, unknown>>(
5511
5709
  target: Target,
@@ -5522,7 +5720,8 @@ type AsCurriedResult<
5522
5720
  "write",
5523
5721
  "insert",
5524
5722
  Target,
5525
- "ready"
5723
+ "ready",
5724
+ EmptyFacts
5526
5725
  >
5527
5726
  }
5528
5727
 
@@ -5554,7 +5753,8 @@ type AsCurriedResult<
5554
5753
  CapabilitiesOfPlan<PlanValue>,
5555
5754
  StatementOfPlan<PlanValue>,
5556
5755
  MutationTargetOfPlan<PlanValue>,
5557
- InsertSourceStateOfPlan<PlanValue>
5756
+ InsertSourceStateOfPlan<PlanValue>,
5757
+ FactsOfPlan<PlanValue>
5558
5758
  >
5559
5759
 
5560
5760
  interface UpdateApi {
@@ -5571,7 +5771,10 @@ type AsCurriedResult<
5571
5771
  Exclude<NestedMutationRequiredFromValues<Values>, MutationTargetNamesOf<Targets>>,
5572
5772
  TrueFormula,
5573
5773
  "write",
5574
- "update"
5774
+ "update",
5775
+ any,
5776
+ "ready",
5777
+ EmptyFacts
5575
5778
  >
5576
5779
  <Target extends MutationTargetLike, Values extends Record<string, unknown>>(
5577
5780
  target: Target,
@@ -5586,7 +5789,10 @@ type AsCurriedResult<
5586
5789
  Exclude<MutationRequiredFromValues<Values>, SourceNameOf<Target>>,
5587
5790
  TrueFormula,
5588
5791
  "write",
5589
- "update"
5792
+ "update",
5793
+ any,
5794
+ "ready",
5795
+ EmptyFacts
5590
5796
  >
5591
5797
  }
5592
5798
 
@@ -5612,7 +5818,8 @@ type AsCurriedResult<
5612
5818
  "write",
5613
5819
  "insert",
5614
5820
  Target,
5615
- "ready"
5821
+ "ready",
5822
+ EmptyFacts
5616
5823
  >
5617
5824
 
5618
5825
  interface DeleteApi {
@@ -5628,7 +5835,10 @@ type AsCurriedResult<
5628
5835
  never,
5629
5836
  TrueFormula,
5630
5837
  "write",
5631
- "delete"
5838
+ "delete",
5839
+ any,
5840
+ "ready",
5841
+ EmptyFacts
5632
5842
  >
5633
5843
  <Targets extends MutationTargetTuple>(
5634
5844
  target: Dialect extends "mysql" ? Targets : never
@@ -5642,7 +5852,10 @@ type AsCurriedResult<
5642
5852
  never,
5643
5853
  TrueFormula,
5644
5854
  "write",
5645
- "delete"
5855
+ "delete",
5856
+ any,
5857
+ "ready",
5858
+ EmptyFacts
5646
5859
  >
5647
5860
  }
5648
5861
 
@@ -5659,7 +5872,10 @@ type AsCurriedResult<
5659
5872
  never,
5660
5873
  TrueFormula,
5661
5874
  "write",
5662
- "truncate"
5875
+ "truncate",
5876
+ any,
5877
+ "ready",
5878
+ EmptyFacts
5663
5879
  >
5664
5880
 
5665
5881
  type MergeApi = <
@@ -5713,7 +5929,10 @@ type AsCurriedResult<
5713
5929
  >,
5714
5930
  TrueFormula,
5715
5931
  MergeCapabilities<"write", SourceCapabilitiesOf<Source>>,
5716
- "merge"
5932
+ "merge",
5933
+ any,
5934
+ "ready",
5935
+ EmptyFacts
5717
5936
  >
5718
5937
 
5719
5938
  const mutationRuntime = makeDslMutationRuntime({
@@ -5768,7 +5987,8 @@ type AsCurriedResult<
5768
5987
  CapabilitiesOfPlan<PlanValue>,
5769
5988
  StatementOfPlan<PlanValue>,
5770
5989
  MutationTargetOfPlan<PlanValue>,
5771
- InsertSourceStateOfPlan<PlanValue>
5990
+ InsertSourceStateOfPlan<PlanValue>,
5991
+ FactsOfPlan<PlanValue>
5772
5992
  > => mutationRuntime.onConflict(target, options)(plan)
5773
5993
 
5774
5994
  const update: UpdateApi = ((
@@ -5798,7 +6018,8 @@ type AsCurriedResult<
5798
6018
  "write",
5799
6019
  "insert",
5800
6020
  Target,
5801
- "ready"
6021
+ "ready",
6022
+ EmptyFacts
5802
6023
  > => mutationRuntime.upsert(target, values, conflictColumns as string | readonly string[], updateValues)
5803
6024
 
5804
6025
  const delete_: DeleteApi = ((
@@ -5820,7 +6041,10 @@ type AsCurriedResult<
5820
6041
  never,
5821
6042
  TrueFormula,
5822
6043
  "write",
5823
- "truncate"
6044
+ "truncate",
6045
+ any,
6046
+ "ready",
6047
+ EmptyFacts
5824
6048
  > => mutationRuntime.truncate(target, options)
5825
6049
 
5826
6050
  const merge: MergeApi = <
@@ -5874,7 +6098,10 @@ type AsCurriedResult<
5874
6098
  >,
5875
6099
  TrueFormula,
5876
6100
  MergeCapabilities<"write", SourceCapabilitiesOf<Source>>,
5877
- "merge"
6101
+ "merge",
6102
+ any,
6103
+ "ready",
6104
+ EmptyFacts
5878
6105
  > => mutationRuntime.merge(target, source, on, options)
5879
6106
 
5880
6107
  type TransactionApi = (options?: TransactionOptions) => QueryPlan<