effect-qb 0.17.0 → 0.20.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.
Files changed (137) hide show
  1. package/README.md +11 -1
  2. package/dist/index.js +9376 -0
  3. package/dist/mysql.js +4092 -2671
  4. package/dist/postgres/metadata.js +2589 -1402
  5. package/dist/postgres.js +3953 -3583
  6. package/dist/sqlite.js +5527 -4088
  7. package/dist/standard.js +9330 -0
  8. package/package.json +9 -4
  9. package/src/casing.ts +71 -0
  10. package/src/index.ts +2 -0
  11. package/src/internal/casing.ts +89 -0
  12. package/src/internal/coercion/rules.ts +13 -1
  13. package/src/internal/column-state.d.ts +3 -3
  14. package/src/internal/column-state.ts +24 -18
  15. package/src/internal/column.ts +52 -15
  16. package/src/internal/datatypes/define.ts +7 -1
  17. package/src/internal/datatypes/enrich.ts +23 -0
  18. package/src/internal/datatypes/lookup.ts +81 -25
  19. package/src/internal/datatypes/matrix.ts +903 -0
  20. package/src/internal/datatypes/shape.ts +2 -0
  21. package/src/internal/derived-table.ts +4 -36
  22. package/src/{mysql/internal/sql-expression-renderer.ts → internal/dialect-renderers/mysql.ts} +552 -361
  23. package/src/{postgres/internal/sql-expression-renderer.ts → internal/dialect-renderers/postgres.ts} +657 -400
  24. package/src/{sqlite/internal/sql-expression-renderer.ts → internal/dialect-renderers/sqlite.ts} +505 -347
  25. package/src/internal/dialect.ts +36 -1
  26. package/src/internal/dsl-mutation-runtime.ts +12 -162
  27. package/src/internal/dsl-plan-runtime.ts +10 -138
  28. package/src/internal/dsl-query-runtime.ts +5 -79
  29. package/src/internal/dsl-transaction-ddl-runtime.ts +41 -65
  30. package/src/internal/executor.ts +66 -49
  31. package/src/internal/grouping-key.ts +87 -20
  32. package/src/internal/implication-runtime.ts +1 -1
  33. package/src/internal/json/path-access.ts +351 -0
  34. package/src/internal/predicate/runtime.ts +3 -0
  35. package/src/internal/query.d.ts +39 -12
  36. package/src/internal/query.ts +65 -26
  37. package/src/internal/renderer.ts +26 -14
  38. package/src/internal/runtime/driver-value-mapping.ts +3 -3
  39. package/src/internal/runtime/normalize.ts +12 -5
  40. package/src/internal/runtime/schema.ts +28 -38
  41. package/src/internal/runtime/value.ts +20 -23
  42. package/src/internal/scalar.d.ts +1 -1
  43. package/src/internal/scalar.ts +8 -2
  44. package/src/internal/schema-derivation.d.ts +12 -61
  45. package/src/internal/schema-derivation.ts +95 -43
  46. package/src/internal/schema-expression.ts +2 -2
  47. package/src/internal/sql-expression-renderer.ts +19 -0
  48. package/src/internal/standard-dsl.ts +6978 -0
  49. package/src/internal/table-options.ts +126 -66
  50. package/src/internal/table.ts +819 -237
  51. package/src/mysql/column-extension.ts +3 -0
  52. package/src/mysql/column.ts +14 -15
  53. package/src/mysql/datatypes/index.ts +4 -2
  54. package/src/mysql/datatypes/spec.ts +6 -176
  55. package/src/mysql/errors/normalize.ts +0 -1
  56. package/src/mysql/executor.ts +11 -11
  57. package/src/mysql/function/temporal.ts +1 -1
  58. package/src/mysql/internal/dialect.ts +9 -4
  59. package/src/mysql/internal/dsl.ts +334 -170
  60. package/src/mysql/internal/renderer.ts +6 -2
  61. package/src/mysql/json.ts +7 -2
  62. package/src/mysql/query-extension.ts +16 -0
  63. package/src/mysql/renderer.ts +37 -3
  64. package/src/mysql/type.ts +60 -0
  65. package/src/mysql.ts +7 -13
  66. package/src/postgres/check.ts +1 -0
  67. package/src/postgres/column-extension.ts +28 -0
  68. package/src/postgres/column.ts +13 -19
  69. package/src/postgres/datatypes/index.d.ts +2 -1
  70. package/src/postgres/datatypes/index.ts +4 -2
  71. package/src/postgres/datatypes/spec.ts +6 -260
  72. package/src/postgres/errors/normalize.ts +0 -1
  73. package/src/postgres/executor.ts +11 -11
  74. package/src/postgres/foreign-key.ts +24 -0
  75. package/src/postgres/function/core.ts +1 -3
  76. package/src/postgres/function/index.ts +1 -17
  77. package/src/postgres/function/temporal.ts +1 -1
  78. package/src/postgres/index.ts +1 -0
  79. package/src/postgres/internal/dialect.ts +9 -4
  80. package/src/postgres/internal/dsl.ts +328 -179
  81. package/src/postgres/internal/renderer.ts +6 -2
  82. package/src/postgres/internal/schema-ddl.ts +22 -10
  83. package/src/postgres/internal/schema-model.ts +238 -7
  84. package/src/postgres/json-extension.ts +7 -0
  85. package/src/postgres/json.ts +762 -173
  86. package/src/postgres/jsonb.ts +37 -0
  87. package/src/postgres/primary-key.ts +24 -0
  88. package/src/postgres/query-extension.ts +2 -0
  89. package/src/postgres/renderer.ts +37 -3
  90. package/src/postgres/schema-management.ts +13 -13
  91. package/src/postgres/schema.ts +106 -15
  92. package/src/postgres/table.ts +205 -538
  93. package/src/postgres/type.ts +93 -10
  94. package/src/postgres/unique.ts +32 -0
  95. package/src/postgres.ts +20 -16
  96. package/src/sqlite/column-extension.ts +3 -0
  97. package/src/sqlite/column.ts +14 -15
  98. package/src/sqlite/datatypes/index.ts +4 -2
  99. package/src/sqlite/datatypes/spec.ts +6 -94
  100. package/src/sqlite/errors/normalize.ts +0 -1
  101. package/src/sqlite/executor.ts +11 -11
  102. package/src/sqlite/function/temporal.ts +1 -1
  103. package/src/sqlite/internal/dialect.ts +9 -4
  104. package/src/sqlite/internal/dsl.ts +307 -159
  105. package/src/sqlite/internal/renderer.ts +6 -2
  106. package/src/sqlite/json.ts +8 -2
  107. package/src/sqlite/query-extension.ts +2 -0
  108. package/src/sqlite/renderer.ts +37 -3
  109. package/src/sqlite/type.ts +40 -0
  110. package/src/sqlite.ts +7 -13
  111. package/src/standard/cast.ts +113 -0
  112. package/src/standard/check.ts +17 -0
  113. package/src/standard/column.ts +163 -0
  114. package/src/standard/datatypes/index.ts +83 -0
  115. package/src/standard/datatypes/spec.ts +12 -0
  116. package/src/standard/dialect.ts +40 -0
  117. package/src/standard/foreign-key.ts +37 -0
  118. package/src/standard/function/aggregate.ts +2 -0
  119. package/src/standard/function/core.ts +2 -0
  120. package/src/standard/function/index.ts +18 -0
  121. package/src/standard/function/string.ts +2 -0
  122. package/src/standard/function/temporal.ts +78 -0
  123. package/src/standard/function/window.ts +2 -0
  124. package/src/standard/index.ts +17 -0
  125. package/src/standard/internal/renderer.ts +45 -0
  126. package/src/standard/json.ts +883 -0
  127. package/src/standard/primary-key.ts +17 -0
  128. package/src/standard/query.ts +152 -0
  129. package/src/standard/renderer.ts +49 -0
  130. package/src/standard/table.ts +151 -0
  131. package/src/standard/unique.ts +17 -0
  132. package/src/standard.ts +32 -0
  133. package/src/internal/aggregation-validation.ts +0 -57
  134. package/src/internal/table.d.ts +0 -173
  135. package/src/mysql/table.ts +0 -183
  136. package/src/postgres/cast.ts +0 -45
  137. package/src/sqlite/table.ts +0 -183
@@ -1,4 +1,4 @@
1
- import { pipeArguments } from "effect/Pipeable"
1
+ import { pipeArguments, type Pipeable } from "effect/Pipeable"
2
2
  import * as Schema from "effect/Schema"
3
3
 
4
4
  import { sqliteDatatypes } from "../datatypes/index.js"
@@ -6,6 +6,12 @@ import { sqliteDatatypes } from "../datatypes/index.js"
6
6
  import * as Expression from "../../internal/scalar.js"
7
7
  import * as Plan from "../../internal/row-set.js"
8
8
  import * as Table from "../../internal/table.js"
9
+ import type {
10
+ LiteralStringInput,
11
+ NonEmptyStringInput,
12
+ SafeSqlIdentifierInput,
13
+ SafeSqlIdentifierPathInput
14
+ } from "../../internal/table-options.js"
9
15
  import type { CastTargetError, OperandCompatibilityError } from "../../internal/coercion/errors.js"
10
16
  import type { RuntimeOfDbType } from "../../internal/coercion/analysis.js"
11
17
  import type { CanCastDbType, CanCompareDbTypes, CanContainDbTypes, CanTextuallyCoerceDbType } from "../../internal/coercion/rules.js"
@@ -71,6 +77,7 @@ import {
71
77
  type ScopedNamesOfPlan,
72
78
  type SelectionOfPlan,
73
79
  type SelectionShape,
80
+ type SelectionProjectionAliasCollisionConstraint,
74
81
  type SetCompatiblePlan,
75
82
  type SetCompatibleRightPlan,
76
83
  type SchemaTableLike,
@@ -80,10 +87,8 @@ import {
80
87
  type TableDialectOf,
81
88
  type StatementOfPlan,
82
89
  type MutationInputOf,
83
- type MutationTargetLike,
84
90
  type MutationTargetOfPlan,
85
91
  type MergeCapabilities,
86
- type MutationTargetInput,
87
92
  type MutationValuesInput,
88
93
  type SourceDialectOf,
89
94
  type SourceLike,
@@ -100,7 +105,6 @@ import {
100
105
  type TableLike,
101
106
  type UpdateInputOfTarget,
102
107
  type MutationTargetNamesOf,
103
- type MutationTargetTuple,
104
108
  type TupleDependencies,
105
109
  type TupleDialect,
106
110
  type ResultRow
@@ -138,6 +142,10 @@ import * as ProjectionAlias from "../../internal/projection-alias.js"
138
142
  import * as QueryAst from "../../internal/query-ast.js"
139
143
  import { normalizeColumnList } from "../../internal/table-options.js"
140
144
 
145
+ type MutationTargetLike = Table.AnyTable<Dialect | "standard">
146
+ type MutationTargetTuple = readonly [MutationTargetLike, MutationTargetLike, ...MutationTargetLike[]]
147
+ type MutationTargetInput = MutationTargetLike | MutationTargetTuple
148
+
141
149
  /**
142
150
  * Dialect-specific DB type profile used to specialize the shared query
143
151
  * operator surface.
@@ -710,7 +718,7 @@ type NumericExpressionDialectInput<
710
718
  BoolDb extends Expression.DbType.Any,
711
719
  TimestampDb extends Expression.DbType.Any,
712
720
  NullDb extends Expression.DbType.Any
713
- > = Exclude<DialectOfDialectNumericInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect> extends never
721
+ > = Exclude<DialectOfDialectNumericInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect | "standard"> extends never
714
722
  ? unknown
715
723
  : {
716
724
  readonly __effect_qb_error__: "effect-qb: numeric expressions cannot mix dialects"
@@ -803,6 +811,35 @@ type DialectExpressionArray<
803
811
  ? Tuple
804
812
  : never
805
813
 
814
+ type ExtractFunctionFieldInput<
815
+ Value extends ExpressionInput
816
+ > = Value extends string
817
+ ? SafeSqlIdentifierInput<Value>
818
+ : Value extends { readonly [ExpressionAst.TypeId]: ExpressionAst.LiteralNode<infer Field extends string> }
819
+ ? SafeSqlIdentifierInput<Field> extends never ? never : Value
820
+ : never
821
+
822
+ type GenericFunctionNameInput<Name extends string> =
823
+ Name extends "current_date" | "extract" ? never : SafeSqlIdentifierPathInput<Name>
824
+
825
+ type FunctionCallApi = {
826
+ (name: "current_date"): Expression.Any
827
+ <Field extends string, Source extends ExpressionInput>(
828
+ name: "extract",
829
+ field: SafeSqlIdentifierInput<Field>,
830
+ source: Source
831
+ ): Expression.Any
832
+ <Field extends Expression.Any, Source extends ExpressionInput>(
833
+ name: "extract",
834
+ field: Field & ExtractFunctionFieldInput<Field>,
835
+ source: Source
836
+ ): Expression.Any
837
+ <Name extends string, Args extends readonly ExpressionInput[]>(
838
+ name: GenericFunctionNameInput<Name>,
839
+ ...args: Args
840
+ ): Expression.Any
841
+ }
842
+
806
843
  /** Normalized expression tuple for generic string operator inputs. */
807
844
  type DialectStringExpressionTuple<
808
845
  Values extends readonly ExpressionInput[],
@@ -1069,6 +1106,9 @@ type JsonPathInput = JsonPath.Path<any> | JsonPath.CanonicalSegment
1069
1106
 
1070
1107
  type JsonQueryInput = JsonPath.Path<any> | StringExpressionInput
1071
1108
 
1109
+ type JsonQueryValue<Query extends JsonQueryInput> =
1110
+ Query extends string ? LiteralStringInput<Query> : Query
1111
+
1072
1112
  type JsonPathOutputOf<
1073
1113
  Root,
1074
1114
  Target extends JsonPathInput,
@@ -1543,18 +1583,21 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1543
1583
  type: sqliteDatatypes
1544
1584
  }
1545
1585
  const ValuesInputProto = {
1546
- pipe(this: unknown) {
1586
+ pipe(this: Pipeable) {
1547
1587
  return pipeArguments(this, arguments)
1548
1588
  }
1549
1589
  }
1550
1590
 
1551
1591
  const literalSchemaOf = <Value extends LiteralValue>(
1552
1592
  value: Value
1553
- ): Schema.Schema.Any | undefined => {
1593
+ ): Schema.Top | undefined => {
1554
1594
  if (value === null || value instanceof Date) {
1555
1595
  return undefined
1556
1596
  }
1557
- return Schema.Literal(value) as unknown as Schema.Schema.Any
1597
+ if (typeof value === "number" && !Number.isFinite(value)) {
1598
+ return undefined
1599
+ }
1600
+ return Schema.Literal(value) as unknown as Schema.Top
1558
1601
  }
1559
1602
 
1560
1603
  const literal = <const Value extends LiteralValue>(
@@ -1641,7 +1684,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1641
1684
  value: Expression.Any,
1642
1685
  target: Expression.Any
1643
1686
  ): Expression.Any => {
1644
- const ast = (value as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1687
+ const ast = (value as Expression.Any & { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1645
1688
  if (ast.kind !== "literal") {
1646
1689
  return value
1647
1690
  }
@@ -1662,8 +1705,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1662
1705
  left: Expression.Any,
1663
1706
  right: Expression.Any
1664
1707
  ): readonly [Expression.Any, Expression.Any] => {
1665
- const leftAst = (left as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1666
- const rightAst = (right as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1708
+ const leftAst = (left as Expression.Any & { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1709
+ const rightAst = (right as Expression.Any & { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1667
1710
  if (leftAst.kind === "literal" && rightAst.kind !== "literal") {
1668
1711
  return [retargetLiteralExpression(left, right), right]
1669
1712
  }
@@ -1696,7 +1739,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1696
1739
  ): readonly Expression.Any[] => {
1697
1740
  const flattened: Array<Expression.Any> = []
1698
1741
  for (const value of values) {
1699
- const ast = (value as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1742
+ const ast = (value as Expression.Any & { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
1700
1743
  if (ast.kind === kind) {
1701
1744
  flattened.push(...ast.values)
1702
1745
  } else {
@@ -1742,7 +1785,33 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1742
1785
  if (operations.every((operation) => typeof operation === "function")) {
1743
1786
  return pipeArguments(this, arguments)
1744
1787
  }
1745
- throw new TypeError(`Cannot mix query expressions and pipe functions inside ${kind}(...).pipe(...)`)
1788
+ const valuesForMixedPipe = (value: unknown): readonly Expression.Any[] => {
1789
+ if (typeof value !== "object" || value === null || !(Expression.TypeId in value)) {
1790
+ return []
1791
+ }
1792
+ const expression = value as Expression.Any & {
1793
+ readonly [ExpressionAst.TypeId]: ExpressionAst.Any
1794
+ }
1795
+ const ast = expression[ExpressionAst.TypeId]
1796
+ if (ast.kind === kind) {
1797
+ return (ast as {
1798
+ readonly values: readonly Expression.Any[]
1799
+ }).values
1800
+ }
1801
+ return [expression]
1802
+ }
1803
+ let current: unknown = this
1804
+ for (const operation of operations) {
1805
+ if (typeof operation === "function") {
1806
+ current = (operation as (value: unknown) => unknown)(current)
1807
+ continue
1808
+ }
1809
+ current = makeVariadicBooleanExpression(
1810
+ kind,
1811
+ [...valuesForMixedPipe(current), toDialectExpression(operation as ExpressionInput)] as const
1812
+ )
1813
+ }
1814
+ return current
1746
1815
  }
1747
1816
  })
1748
1817
 
@@ -1763,9 +1832,6 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
1763
1832
  const partitionBy = [...(spec?.partitionBy ?? [])] as unknown as PartitionBy
1764
1833
  const orderBy = (spec?.orderBy ?? []).map((term) => {
1765
1834
  const direction = term.direction ?? "asc"
1766
- if (direction !== "asc" && direction !== "desc") {
1767
- throw new Error("window order direction must be asc or desc")
1768
- }
1769
1835
  return {
1770
1836
  value: term.value,
1771
1837
  direction
@@ -1906,7 +1972,8 @@ type BinaryPredicateExpression<
1906
1972
  >(
1907
1973
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "eq">
1908
1974
  ): BinaryPredicateExpression<Left, Right, "eq"> => {
1909
- const [left, right] = args as unknown as [Left, Right]
1975
+ const left = args[0] as Left
1976
+ const right = args[1] as Right
1910
1977
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "eq")
1911
1978
  }
1912
1979
 
@@ -1916,7 +1983,8 @@ type BinaryPredicateExpression<
1916
1983
  >(
1917
1984
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "neq">
1918
1985
  ): BinaryPredicateExpression<Left, Right, "neq"> => {
1919
- const [left, right] = args as unknown as [Left, Right]
1986
+ const left = args[0] as Left
1987
+ const right = args[1] as Right
1920
1988
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "neq")
1921
1989
  }
1922
1990
 
@@ -1926,7 +1994,8 @@ type BinaryPredicateExpression<
1926
1994
  >(
1927
1995
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "lt">
1928
1996
  ): BinaryPredicateExpression<Left, Right, "lt"> => {
1929
- const [left, right] = args as unknown as [Left, Right]
1997
+ const left = args[0] as Left
1998
+ const right = args[1] as Right
1930
1999
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "lt")
1931
2000
  }
1932
2001
 
@@ -1936,7 +2005,8 @@ type BinaryPredicateExpression<
1936
2005
  >(
1937
2006
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "lte">
1938
2007
  ): BinaryPredicateExpression<Left, Right, "lte"> => {
1939
- const [left, right] = args as unknown as [Left, Right]
2008
+ const left = args[0] as Left
2009
+ const right = args[1] as Right
1940
2010
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "lte")
1941
2011
  }
1942
2012
 
@@ -1946,7 +2016,8 @@ type BinaryPredicateExpression<
1946
2016
  >(
1947
2017
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "gt">
1948
2018
  ): BinaryPredicateExpression<Left, Right, "gt"> => {
1949
- const [left, right] = args as unknown as [Left, Right]
2019
+ const left = args[0] as Left
2020
+ const right = args[1] as Right
1950
2021
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "gt")
1951
2022
  }
1952
2023
 
@@ -1956,7 +2027,8 @@ type BinaryPredicateExpression<
1956
2027
  >(
1957
2028
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "gte">
1958
2029
  ): BinaryPredicateExpression<Left, Right, "gte"> => {
1959
- const [left, right] = args as unknown as [Left, Right]
2030
+ const left = args[0] as Left
2031
+ const right = args[1] as Right
1960
2032
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "gte")
1961
2033
  }
1962
2034
 
@@ -1966,7 +2038,8 @@ type BinaryPredicateExpression<
1966
2038
  >(
1967
2039
  ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "like">
1968
2040
  ): BinaryPredicateExpression<Left, Right, "like"> => {
1969
- const [left, right] = args as unknown as [Left, Right]
2041
+ const left = args[0] as Left
2042
+ const right = args[1] as Right
1970
2043
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "like")
1971
2044
  }
1972
2045
 
@@ -1976,7 +2049,8 @@ type BinaryPredicateExpression<
1976
2049
  >(
1977
2050
  ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "ilike">
1978
2051
  ): BinaryPredicateExpression<Left, Right, "ilike"> => {
1979
- const [left, right] = args as unknown as [Left, Right]
2052
+ const left = args[0] as Left
2053
+ const right = args[1] as Right
1980
2054
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "ilike")
1981
2055
  }
1982
2056
 
@@ -1986,7 +2060,8 @@ type BinaryPredicateExpression<
1986
2060
  >(
1987
2061
  ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "regexMatch">
1988
2062
  ): BinaryPredicateExpression<Left, Right, "regexMatch"> => {
1989
- const [left, right] = args as unknown as [Left, Right]
2063
+ const left = args[0] as Left
2064
+ const right = args[1] as Right
1990
2065
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "regexMatch")
1991
2066
  }
1992
2067
 
@@ -1996,7 +2071,8 @@ type BinaryPredicateExpression<
1996
2071
  >(
1997
2072
  ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "regexIMatch">
1998
2073
  ): BinaryPredicateExpression<Left, Right, "regexIMatch"> => {
1999
- const [left, right] = args as unknown as [Left, Right]
2074
+ const left = args[0] as Left
2075
+ const right = args[1] as Right
2000
2076
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "regexIMatch")
2001
2077
  }
2002
2078
 
@@ -2006,7 +2082,8 @@ type BinaryPredicateExpression<
2006
2082
  >(
2007
2083
  ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "regexNotMatch">
2008
2084
  ): BinaryPredicateExpression<Left, Right, "regexNotMatch"> => {
2009
- const [left, right] = args as unknown as [Left, Right]
2085
+ const left = args[0] as Left
2086
+ const right = args[1] as Right
2010
2087
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "regexNotMatch")
2011
2088
  }
2012
2089
 
@@ -2016,7 +2093,8 @@ type BinaryPredicateExpression<
2016
2093
  >(
2017
2094
  ...args: TextArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "regexNotIMatch">
2018
2095
  ): BinaryPredicateExpression<Left, Right, "regexNotIMatch"> => {
2019
- const [left, right] = args as unknown as [Left, Right]
2096
+ const left = args[0] as Left
2097
+ const right = args[1] as Right
2020
2098
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "regexNotIMatch")
2021
2099
  }
2022
2100
 
@@ -2026,7 +2104,8 @@ type BinaryPredicateExpression<
2026
2104
  >(
2027
2105
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "isDistinctFrom">
2028
2106
  ): BinaryPredicateExpression<Left, Right, "isDistinctFrom", "never"> => {
2029
- const [left, right] = args as unknown as [Left, Right]
2107
+ const left = args[0] as Left
2108
+ const right = args[1] as Right
2030
2109
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "isDistinctFrom", "never")
2031
2110
  }
2032
2111
 
@@ -2036,7 +2115,8 @@ type BinaryPredicateExpression<
2036
2115
  >(
2037
2116
  ...args: ComparableArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "isNotDistinctFrom">
2038
2117
  ): BinaryPredicateExpression<Left, Right, "isNotDistinctFrom", "never"> => {
2039
- const [left, right] = args as unknown as [Left, Right]
2118
+ const left = args[0] as Left
2119
+ const right = args[1] as Right
2040
2120
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "isNotDistinctFrom", "never")
2041
2121
  }
2042
2122
 
@@ -2187,62 +2267,62 @@ type BinaryPredicateExpression<
2187
2267
  })
2188
2268
 
2189
2269
  const range = <Kind extends string, Subtype extends Expression.DbType.Any>(
2190
- kind: Kind,
2270
+ kind: NonEmptyStringInput<Kind>,
2191
2271
  subtype: Subtype
2192
2272
  ): Expression.DbType.Range<Dialect, Subtype, Kind> => ({
2193
2273
  dialect: profile.dialect,
2194
- kind,
2274
+ kind: kind as Kind,
2195
2275
  subtype
2196
2276
  })
2197
2277
 
2198
2278
  const multirange = <Kind extends string, Subtype extends Expression.DbType.Any>(
2199
- kind: Kind,
2279
+ kind: NonEmptyStringInput<Kind>,
2200
2280
  subtype: Subtype
2201
2281
  ): Expression.DbType.Multirange<Dialect, Subtype, Kind> => ({
2202
2282
  dialect: profile.dialect,
2203
- kind,
2283
+ kind: kind as Kind,
2204
2284
  subtype
2205
2285
  })
2206
2286
 
2207
2287
  const record = <Kind extends string, Fields extends Record<string, Expression.DbType.Any>>(
2208
- kind: Kind,
2288
+ kind: NonEmptyStringInput<Kind>,
2209
2289
  fields: Fields
2210
2290
  ): Expression.DbType.Composite<Dialect, Fields, Kind> => ({
2211
2291
  dialect: profile.dialect,
2212
- kind,
2292
+ kind: kind as Kind,
2213
2293
  fields
2214
2294
  })
2215
2295
 
2216
2296
  const domain = <Kind extends string, Base extends Expression.DbType.Any>(
2217
- kind: Kind,
2297
+ kind: NonEmptyStringInput<Kind>,
2218
2298
  base: Base
2219
2299
  ): Expression.DbType.Domain<Dialect, Base, Kind> => ({
2220
2300
  dialect: profile.dialect,
2221
- kind,
2301
+ kind: kind as Kind,
2222
2302
  base
2223
2303
  })
2224
2304
 
2225
2305
  const enum_ = <Kind extends string>(
2226
- kind: Kind
2306
+ kind: NonEmptyStringInput<Kind>
2227
2307
  ): Expression.DbType.Enum<Dialect, Kind> => ({
2228
2308
  dialect: profile.dialect,
2229
- kind,
2309
+ kind: kind as Kind,
2230
2310
  variant: "enum"
2231
2311
  })
2232
2312
 
2233
2313
  const set = <Kind extends string>(
2234
- kind: Kind
2314
+ kind: NonEmptyStringInput<Kind>
2235
2315
  ): Expression.DbType.Set<Dialect, Kind> => ({
2236
2316
  dialect: profile.dialect,
2237
- kind,
2317
+ kind: kind as Kind,
2238
2318
  variant: "set"
2239
2319
  })
2240
2320
 
2241
2321
  const custom = <Kind extends string>(
2242
- kind: Kind
2322
+ kind: NonEmptyStringInput<Kind>
2243
2323
  ): Expression.DbType.Base<Dialect, Kind> => ({
2244
2324
  dialect: profile.dialect,
2245
- kind
2325
+ kind: kind as Kind
2246
2326
  })
2247
2327
 
2248
2328
  const driverValueMapping = <Db extends Expression.DbType.Any>(
@@ -3050,9 +3130,12 @@ type BinaryPredicateExpression<
3050
3130
  }
3051
3131
  )
3052
3132
 
3053
- const jsonPathExists = <Base extends JsonExpressionLike<any>>(
3133
+ const jsonPathExists = <
3134
+ Base extends JsonExpressionLike<any>,
3135
+ Query extends JsonQueryInput
3136
+ >(
3054
3137
  base: Base,
3055
- query: JsonQueryInput
3138
+ query: JsonQueryValue<Query>
3056
3139
  ) => {
3057
3140
  if (isJsonPathValue(query)) {
3058
3141
  return buildJsonNodeExpression(
@@ -3100,9 +3183,12 @@ type BinaryPredicateExpression<
3100
3183
  }
3101
3184
  )
3102
3185
 
3103
- const jsonPathMatch = <Base extends JsonExpressionLike<any>>(
3186
+ const jsonPathMatch = <
3187
+ Base extends JsonExpressionLike<any>,
3188
+ Query extends JsonQueryInput
3189
+ >(
3104
3190
  base: Base,
3105
- query: JsonQueryInput
3191
+ query: JsonQueryValue<Query>
3106
3192
  ) => {
3107
3193
  if (isJsonPathValue(query)) {
3108
3194
  return buildJsonNodeExpression(
@@ -3329,7 +3415,8 @@ type BinaryPredicateExpression<
3329
3415
  >(
3330
3416
  ...args: ContainmentArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "contains">
3331
3417
  ): BinaryPredicateExpression<Left, Right, "contains"> => {
3332
- const [left, right] = args as unknown as [Left, Right]
3418
+ const left = args[0] as Left
3419
+ const right = args[1] as Right
3333
3420
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "contains")
3334
3421
  }
3335
3422
 
@@ -3339,7 +3426,8 @@ type BinaryPredicateExpression<
3339
3426
  >(
3340
3427
  ...args: ContainmentArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "containedBy">
3341
3428
  ): BinaryPredicateExpression<Left, Right, "containedBy"> => {
3342
- const [left, right] = args as unknown as [Left, Right]
3429
+ const left = args[0] as Left
3430
+ const right = args[1] as Right
3343
3431
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "containedBy")
3344
3432
  }
3345
3433
 
@@ -3349,7 +3437,8 @@ type BinaryPredicateExpression<
3349
3437
  >(
3350
3438
  ...args: ContainmentArgs<Left, Right, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb, "overlaps">
3351
3439
  ): BinaryPredicateExpression<Left, Right, "overlaps"> => {
3352
- const [left, right] = args as unknown as [Left, Right]
3440
+ const left = args[0] as Left
3441
+ const right = args[1] as Right
3353
3442
  return buildBinaryPredicate(left as ExpressionInput, right as ExpressionInput, "overlaps")
3354
3443
  }
3355
3444
 
@@ -3776,12 +3865,9 @@ type BinaryPredicateExpression<
3776
3865
  >
3777
3866
  }
3778
3867
 
3779
- const call = <
3780
- Name extends string,
3781
- Args extends readonly ExpressionInput[]
3782
- >(
3783
- name: Name,
3784
- ...args: Args
3868
+ const call: FunctionCallApi = (
3869
+ name: string,
3870
+ ...args: readonly ExpressionInput[]
3785
3871
  ): Expression.Any => {
3786
3872
  const expressions = args.map((value) => toDialectExpression(value)) as readonly Expression.Any[]
3787
3873
  return makeExpression({
@@ -4017,9 +4103,6 @@ type BinaryPredicateExpression<
4017
4103
  ExpressionAst.ExcludedNode<AstOf<Value> extends ExpressionAst.ColumnNode<any, infer ColumnName extends string> ? ColumnName : string>
4018
4104
  > => {
4019
4105
  const ast = ((value as unknown) as Expression.Any & { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
4020
- if (ast.kind !== "column") {
4021
- throw new Error("excluded(...) only accepts bound table columns")
4022
- }
4023
4106
  return makeExpression({
4024
4107
  runtime: undefined as Expression.RuntimeOf<Value>,
4025
4108
  dbType: value[Expression.TypeId].dbType as Expression.DbTypeOf<Value>,
@@ -4032,7 +4115,7 @@ type BinaryPredicateExpression<
4032
4115
  dependencies: {}
4033
4116
  }, {
4034
4117
  kind: "excluded",
4035
- columnName: ast.columnName
4118
+ columnName: (ast as ExpressionAst.ColumnNode<any, string>).columnName
4036
4119
  }) as unknown as AstBackedExpression<
4037
4120
  Expression.RuntimeOf<Value>,
4038
4121
  Expression.DbTypeOf<Value>,
@@ -4065,7 +4148,7 @@ type BinaryPredicateExpression<
4065
4148
  }
4066
4149
  if (value !== null && typeof value === "object" && Expression.TypeId in value) {
4067
4150
  const expression = value as unknown as Expression.Any
4068
- const ast = (expression as unknown as { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
4151
+ const ast = (expression as Expression.Any & { readonly [ExpressionAst.TypeId]: ExpressionAst.Any })[ExpressionAst.TypeId]
4069
4152
  if (ast.kind === "literal") {
4070
4153
  const normalizedValue = normalizeMutationValue(ast.value)
4071
4154
  return makeExpression({
@@ -4134,8 +4217,8 @@ type BinaryPredicateExpression<
4134
4217
  : ">="
4135
4218
 
4136
4219
  const targetSourceDetails = (table: MutationTargetLike | SchemaTableLike) => {
4137
- const sourceName = (table as unknown as TableLike)[Table.TypeId].name
4138
- const sourceBaseName = (table as unknown as TableLike)[Table.TypeId].baseName
4220
+ const sourceName = (table as TableLike)[Table.TypeId].name
4221
+ const sourceBaseName = (table as TableLike)[Table.TypeId].baseName
4139
4222
  return {
4140
4223
  sourceName,
4141
4224
  sourceBaseName
@@ -4225,12 +4308,7 @@ type BinaryPredicateExpression<
4225
4308
 
4226
4309
  const normalizeUnnestColumns = (columns: UnnestColumnsInput): Record<string, readonly Expression.Any[]> =>
4227
4310
  Object.fromEntries(
4228
- Object.entries(columns).map(([key, values]) => {
4229
- if (!Array.isArray(values)) {
4230
- throw new Error("unnest(...) expects every value to be an array")
4231
- }
4232
- return [key, values.map((value) => toDialectExpression(value))]
4233
- })
4311
+ Object.entries(columns).map(([key, values]) => [key, values.map((value) => toDialectExpression(value))])
4234
4312
  ) as Record<string, readonly Expression.Any[]>
4235
4313
 
4236
4314
  const normalizeMutationTargets = (
@@ -4276,13 +4354,7 @@ type BinaryPredicateExpression<
4276
4354
  const getMutationColumn = (
4277
4355
  columns: Record<string, unknown>,
4278
4356
  columnName: string
4279
- ): Expression.Any => {
4280
- const column = columns[columnName]
4281
- if (column === undefined || column === null || typeof column !== "object" || !(Expression.TypeId in column)) {
4282
- throw new Error("effect-qb: unknown mutation column")
4283
- }
4284
- return column as Expression.Any
4285
- }
4357
+ ): Expression.Any => columns[columnName] as Expression.Any
4286
4358
 
4287
4359
  const buildMutationAssignments = <Target extends MutationTargetInput, Values>(
4288
4360
  target: Target,
@@ -4298,7 +4370,7 @@ type BinaryPredicateExpression<
4298
4370
  }
4299
4371
  const valueMap = values as Record<string, Record<string, unknown> | undefined>
4300
4372
  return targets.flatMap((table) => {
4301
- const targetName = (table as unknown as TableLike)[Table.TypeId].name
4373
+ const targetName = (table as TableLike)[Table.TypeId].name
4302
4374
  const scopedValues = valueMap[targetName] ?? {}
4303
4375
  const columns = table as unknown as Record<string, Expression.Any>
4304
4376
  return Object.entries(scopedValues).map(([columnName, value]) => ({
@@ -4319,20 +4391,17 @@ type BinaryPredicateExpression<
4319
4391
  } => {
4320
4392
  const firstRow = rows[0]
4321
4393
  const firstColumns = Object.keys(firstRow)
4322
- if (firstColumns.length === 0) {
4323
- throw new Error("values(...) rows must specify at least one column; use insert(target) for default-only inserts instead")
4324
- }
4325
4394
  const columns = firstColumns as [string, ...string[]]
4326
- const normalizedRows = rows.map((row) => {
4327
- const rowKeys = Object.keys(row)
4328
- if (rowKeys.length !== columns.length || columns.some((column) => !(column in row))) {
4329
- throw new Error("All values(...) rows must project the same columns in the same shape")
4330
- }
4395
+ const normalizeRow = (row: InsertRowInput<Target>) => {
4331
4396
  const assignments = buildMutationAssignments(target, row) as readonly QueryAst.AssignmentClause[]
4332
4397
  return {
4333
4398
  values: columns.map((columnName) => assignments.find((assignment) => assignment.columnName === columnName)!)
4334
4399
  } satisfies QueryAst.InsertValuesRowClause
4335
- }) as unknown as [QueryAst.InsertValuesRowClause, ...QueryAst.InsertValuesRowClause[]]
4400
+ }
4401
+ const normalizedRows: readonly [QueryAst.InsertValuesRowClause, ...QueryAst.InsertValuesRowClause[]] = [
4402
+ normalizeRow(rows[0]),
4403
+ ...rows.slice(1).map(normalizeRow)
4404
+ ]
4336
4405
  const required = normalizedRows.flatMap((row) =>
4337
4406
  row.values.flatMap((entry) => Object.keys(entry.value[Expression.TypeId].dependencies))
4338
4407
  )
@@ -4347,9 +4416,6 @@ type BinaryPredicateExpression<
4347
4416
  selection: Record<string, Expression.Any>
4348
4417
  ): readonly [string, ...string[]] => {
4349
4418
  const columns = Object.keys(selection)
4350
- if (columns.length === 0) {
4351
- throw new Error("insert(...).pipe(from(subquery)) requires at least one projected column")
4352
- }
4353
4419
  return columns as [string, ...string[]]
4354
4420
  }
4355
4421
 
@@ -4364,27 +4430,11 @@ type BinaryPredicateExpression<
4364
4430
  }[]
4365
4431
  } => {
4366
4432
  const entries = Object.entries(values)
4367
- if (entries.length === 0) {
4368
- throw new Error("unnest(...) requires at least one column array")
4369
- }
4370
4433
  const columns = entries.map(([columnName]) => columnName) as [string, ...string[]]
4371
- const normalized = entries.map(([columnName, items]) => {
4372
- if (!Array.isArray(items)) {
4373
- throw new Error("unnest(...) expects every value to be an array")
4374
- }
4375
- return {
4376
- columnName,
4377
- values: items
4378
- }
4379
- })
4380
- const expectedLength = normalized[0]!.values.length
4381
- if (normalized.some((entry) => entry.values.length !== expectedLength)) {
4382
- throw new Error("unnest(...) expects every column array to have the same length")
4383
- }
4384
- const knownColumns = new Set(Object.keys(target[Table.TypeId].fields))
4385
- if (columns.some((columnName) => !knownColumns.has(columnName))) {
4386
- throw new Error("unnest(...) received a column that does not exist on the target table")
4387
- }
4434
+ const normalized = entries.map(([columnName, items]) => ({
4435
+ columnName,
4436
+ values: items
4437
+ }))
4388
4438
  return {
4389
4439
  columns,
4390
4440
  values: normalized
@@ -4396,10 +4446,6 @@ type BinaryPredicateExpression<
4396
4446
  columnsInput: string | readonly string[]
4397
4447
  ): readonly [string, ...string[]] => {
4398
4448
  const columns = normalizeColumnList(columnsInput) as readonly [string, ...string[]]
4399
- const knownColumns = new Set(Object.keys(target[Table.TypeId].fields))
4400
- if (columns.some((columnName) => !knownColumns.has(columnName))) {
4401
- throw new Error("effect-qb: unknown conflict target column")
4402
- }
4403
4449
  return columns
4404
4450
  }
4405
4451
 
@@ -4414,7 +4460,10 @@ type BinaryPredicateExpression<
4414
4460
  }
4415
4461
  }
4416
4462
  if (!Array.isArray(input) && "constraint" in input) {
4417
- throw new Error("Unsupported sqlite named conflict constraint")
4463
+ return {
4464
+ kind: "constraint",
4465
+ name: input.constraint
4466
+ }
4418
4467
  }
4419
4468
  const columnTarget = input as {
4420
4469
  readonly columns: string | readonly string[]
@@ -4475,14 +4524,91 @@ type ValidateTargetColumnInput<
4475
4524
  Columns extends DdlColumnInput
4476
4525
  > = ValidateTargetColumns<Target, NormalizeDdlColumns<Columns>> extends never ? never : Columns
4477
4526
 
4478
- type CreateIndexOptions = {
4479
- readonly name?: string
4527
+ type SameColumnSet<
4528
+ Left extends readonly string[],
4529
+ Right extends readonly string[]
4530
+ > = string extends Left[number] | Right[number]
4531
+ ? false
4532
+ : Exclude<Left[number], Right[number]> extends never
4533
+ ? Exclude<Right[number], Left[number]> extends never
4534
+ ? true
4535
+ : false
4536
+ : false
4537
+
4538
+ type ConflictArbitersOf<Target extends MutationTargetLike> =
4539
+ Target[typeof Table.TypeId]["conflictArbiters"][number]
4540
+
4541
+ type MatchingConflictArbiter<
4542
+ Target extends MutationTargetLike,
4543
+ Columns extends readonly string[],
4544
+ AllowPartial extends boolean
4545
+ > = ConflictArbitersOf<Target> extends infer Arbiter extends Table.ConflictArbiter
4546
+ ? Arbiter extends Table.ConflictArbiter
4547
+ ? SameColumnSet<Arbiter["columns"], Columns> extends true
4548
+ ? Arbiter["scope"] extends "unconditional"
4549
+ ? true
4550
+ : AllowPartial extends true ? true : never
4551
+ : never
4552
+ : never
4553
+ : never
4554
+
4555
+ type HasInlineConflictArbiter<
4556
+ Target extends MutationTargetLike,
4557
+ Columns extends readonly string[]
4558
+ > = Columns extends readonly [infer Column extends Extract<keyof Target[typeof Table.TypeId]["fields"], string>]
4559
+ ? Target[typeof Table.TypeId]["fields"][Column] extends { readonly metadata: { readonly primaryKey: true } | { readonly unique: true } }
4560
+ ? true
4561
+ : false
4562
+ : false
4563
+
4564
+ type HasConflictArbiter<
4565
+ Target extends MutationTargetLike,
4566
+ Columns extends readonly string[],
4567
+ AllowPartial extends boolean
4568
+ > = string extends Extract<keyof Target[typeof Table.TypeId]["fields"], string>
4569
+ ? true
4570
+ : HasInlineConflictArbiter<Target, Columns> extends true
4571
+ ? true
4572
+ : true extends MatchingConflictArbiter<Target, Columns, AllowPartial> ? true : false
4573
+
4574
+ type ConflictTargetArbiterError<
4575
+ Columns,
4576
+ AllowPartial extends boolean
4577
+ > = {
4578
+ readonly __effect_qb_error__: "effect-qb: conflict target columns must match a primary key, unique constraint, or unique index"
4579
+ readonly __effect_qb_conflict_columns__: Columns
4580
+ readonly __effect_qb_partial_target__: AllowPartial
4581
+ readonly __effect_qb_hint__: "Declare the target columns as primaryKey/unique, add a table-level Unique.make(...), or use a simple Pg.Index.uniqueIndex(...)"
4582
+ }
4583
+
4584
+ type ValidateConflictColumnInput<
4585
+ Target extends MutationTargetLike,
4586
+ Columns extends DdlColumnInput,
4587
+ AllowPartial extends boolean
4588
+ > = ValidateTargetColumnInput<Target, Columns> extends never
4589
+ ? never
4590
+ : HasConflictArbiter<Target, NormalizeDdlColumns<Columns>, AllowPartial> extends true
4591
+ ? Columns
4592
+ : ConflictTargetArbiterError<NormalizeDdlColumns<Columns>, AllowPartial>
4593
+
4594
+ type ConflictColumnPlanConstraint<
4595
+ Target extends MutationTargetLike,
4596
+ Columns extends DdlColumnInput,
4597
+ AllowPartial extends boolean
4598
+ > = ValidateTargetColumnInput<Target, Columns> extends never
4599
+ ? never
4600
+ : HasConflictArbiter<Target, NormalizeDdlColumns<Columns>, AllowPartial> extends true
4601
+ ? unknown
4602
+ : ConflictTargetArbiterError<NormalizeDdlColumns<Columns>, AllowPartial>
4603
+
4604
+ type CreateIndexOptions<Name extends string = string> = {
4605
+ readonly name?: NonEmptyStringInput<Name>
4480
4606
  readonly unique?: boolean
4481
4607
  readonly ifNotExists?: boolean
4482
4608
  }
4483
4609
 
4484
- type DropIndexOptions = {
4485
- readonly name?: string
4610
+ type DropIndexOptions<Name extends string = string> = {
4611
+ readonly name?: NonEmptyStringInput<Name>
4486
4612
  readonly ifExists?: boolean
4487
4613
  }
4488
4614
 
@@ -4581,7 +4707,7 @@ type ValuesRowsDialectInput<
4581
4707
  BoolDb extends Expression.DbType.Any,
4582
4708
  TimestampDb extends Expression.DbType.Any,
4583
4709
  NullDb extends Expression.DbType.Any
4584
- > = Exclude<ValuesRowsDialect<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect> extends never
4710
+ > = Exclude<ValuesRowsDialect<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect | "standard"> extends never
4585
4711
  ? unknown
4586
4712
  : {
4587
4713
  readonly __effect_qb_error__: "effect-qb: values rows cannot mix dialects"
@@ -4636,7 +4762,7 @@ type UnnestColumnsDialectInput<
4636
4762
  BoolDb extends Expression.DbType.Any,
4637
4763
  TimestampDb extends Expression.DbType.Any,
4638
4764
  NullDb extends Expression.DbType.Any
4639
- > = Exclude<UnnestColumnsDialect<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect> extends never
4765
+ > = Exclude<UnnestColumnsDialect<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect | "standard"> extends never
4640
4766
  ? unknown
4641
4767
  : {
4642
4768
  readonly __effect_qb_error__: "effect-qb: unnest columns cannot mix dialects"
@@ -4971,6 +5097,26 @@ type ConflictTargetInput<
4971
5097
  readonly constraint?: string
4972
5098
  }>)
4973
5099
 
5100
+ type ConflictConstraintNameConstraint<Target> =
5101
+ Target extends { readonly constraint: infer Constraint extends string }
5102
+ ? { readonly constraint: NonEmptyStringInput<Constraint> }
5103
+ : unknown
5104
+
5105
+ type ConflictTargetHasPredicate<Target> =
5106
+ Target extends { readonly where: PredicateInput } ? true : false
5107
+
5108
+ type ConflictTargetPlanConstraint<
5109
+ Target extends MutationTargetLike,
5110
+ ConflictTarget
5111
+ > =
5112
+ ConflictTarget extends { readonly constraint: string }
5113
+ ? unknown
5114
+ : ConflictTarget extends { readonly columns: infer Columns extends DdlColumnInput }
5115
+ ? ConflictColumnPlanConstraint<Target, Columns, ConflictTargetHasPredicate<ConflictTarget>>
5116
+ : ConflictTarget extends DdlColumnInput
5117
+ ? ConflictColumnPlanConstraint<Target, ConflictTarget, false>
5118
+ : unknown
5119
+
4974
5120
  type ConflictActionInput<
4975
5121
  Target extends MutationTargetLike,
4976
5122
  Dialect extends string,
@@ -5122,7 +5268,7 @@ type MutationOrderLimitSupported<PlanValue extends QueryPlan<any, any, any, any,
5122
5268
  type MutationTargetTupleDialectConstraint<
5123
5269
  Targets extends MutationTargetTuple,
5124
5270
  Dialect extends string
5125
- > = Exclude<TableDialectOf<Targets[number]>, Dialect> extends never ? unknown : never
5271
+ > = Exclude<TableDialectOf<Targets[number]>, Dialect | "standard"> extends never ? unknown : never
5126
5272
 
5127
5273
  type MutationRequiredFromValues<Values extends Record<string, unknown>> = {
5128
5274
  [K in keyof Values]: Values[K] extends Expression.Any ? RequiredFromDependencies<DependenciesOf<Values[K]>> : never
@@ -5176,7 +5322,7 @@ type KnownIncompatibleMutationDialectFromValues<
5176
5322
  BoolDb extends Expression.DbType.Any,
5177
5323
  TimestampDb extends Expression.DbType.Any,
5178
5324
  NullDb extends Expression.DbType.Any
5179
- > = Exclude<KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect>
5325
+ > = Exclude<KnownMutationDialectFromValues<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect | "standard">
5180
5326
 
5181
5327
  type MutationValuesDialectConstraint<
5182
5328
  Values,
@@ -5228,9 +5374,11 @@ type SourceDialectConstraint<
5228
5374
  Dialect extends string
5229
5375
  > = [SourceDialectOf<CurrentSource>] extends [never]
5230
5376
  ? unknown
5231
- : Extract<SourceDialectOf<CurrentSource>, Dialect> extends never
5232
- ? never
5233
- : unknown
5377
+ : Exclude<SourceDialectOf<CurrentSource>, Dialect | "standard"> extends never
5378
+ ? unknown
5379
+ : Dialect extends "standard"
5380
+ ? unknown
5381
+ : never
5234
5382
 
5235
5383
  type SourceRequirementConstraint<
5236
5384
  PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>,
@@ -5494,7 +5642,7 @@ type AsCurriedResult<
5494
5642
  function as<
5495
5643
  Alias extends string
5496
5644
  >(
5497
- alias: Alias
5645
+ alias: LiteralStringInput<Alias>
5498
5646
  ): <Value extends AsCurriedInput<Dialect>>(
5499
5647
  value: Value
5500
5648
  ) => AsCurriedResult<Value, Alias, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
@@ -5503,7 +5651,7 @@ type AsCurriedResult<
5503
5651
  Alias extends string
5504
5652
  >(
5505
5653
  value: Value,
5506
- alias: Alias
5654
+ alias: LiteralStringInput<Alias>
5507
5655
  ): ProjectionAliasedExpression<DialectAsExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Alias>
5508
5656
  function as<
5509
5657
  Rows extends ValuesRowsInput,
@@ -5514,7 +5662,7 @@ type AsCurriedResult<
5514
5662
  ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5515
5663
  Dialect
5516
5664
  >,
5517
- alias: Alias
5665
+ alias: LiteralStringInput<Alias>
5518
5666
  ): ValuesSource<
5519
5667
  Rows,
5520
5668
  ValuesOutputShape<Rows, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
@@ -5526,11 +5674,11 @@ type AsCurriedResult<
5526
5674
  Alias extends string
5527
5675
  >(
5528
5676
  value: DerivedTableCompatiblePlan<PlanValue>,
5529
- alias: Alias
5677
+ alias: LiteralStringInput<Alias>
5530
5678
  ): DerivedSource<PlanValue, Alias>
5531
5679
  function as(valueOrAlias: unknown, alias?: string): unknown {
5532
5680
  if (alias === undefined) {
5533
- return (value: unknown) => as(value as any, valueOrAlias as string)
5681
+ return (value: unknown) => as(value as any, valueOrAlias as never)
5534
5682
  }
5535
5683
  const resolvedAlias = alias
5536
5684
  const value = valueOrAlias
@@ -5570,7 +5718,7 @@ type AsCurriedResult<
5570
5718
  function with_<
5571
5719
  Alias extends string
5572
5720
  >(
5573
- alias: Alias
5721
+ alias: LiteralStringInput<Alias>
5574
5722
  ): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
5575
5723
  value: SqliteCteCompatiblePlan<PlanValue>
5576
5724
  ) => import("../../internal/query.js").CteSource<PlanValue, Alias>
@@ -5579,11 +5727,11 @@ type AsCurriedResult<
5579
5727
  Alias extends string
5580
5728
  >(
5581
5729
  value: SqliteCteCompatiblePlan<PlanValue>,
5582
- alias: Alias
5730
+ alias: LiteralStringInput<Alias>
5583
5731
  ): import("../../internal/query.js").CteSource<PlanValue, Alias>
5584
5732
  function with_(valueOrAlias: unknown, alias?: string): unknown {
5585
5733
  if (alias === undefined) {
5586
- return (value: unknown) => with_(value as any, valueOrAlias as string)
5734
+ return (value: unknown) => with_(value as any, valueOrAlias as never)
5587
5735
  }
5588
5736
  return makeCteSource(
5589
5737
  valueOrAlias as CompletePlan<QueryPlan<any, any, any, any, any, any, any, any, any, any>>,
@@ -5594,7 +5742,7 @@ type AsCurriedResult<
5594
5742
  function withRecursive_<
5595
5743
  Alias extends string
5596
5744
  >(
5597
- alias: Alias
5745
+ alias: LiteralStringInput<Alias>
5598
5746
  ): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
5599
5747
  value: SqliteCteCompatiblePlan<PlanValue>
5600
5748
  ) => import("../../internal/query.js").CteSource<PlanValue, Alias>
@@ -5603,11 +5751,11 @@ type AsCurriedResult<
5603
5751
  Alias extends string
5604
5752
  >(
5605
5753
  value: SqliteCteCompatiblePlan<PlanValue>,
5606
- alias: Alias
5754
+ alias: LiteralStringInput<Alias>
5607
5755
  ): import("../../internal/query.js").CteSource<PlanValue, Alias>
5608
5756
  function withRecursive_(valueOrAlias: unknown, alias?: string): unknown {
5609
5757
  if (alias === undefined) {
5610
- return (value: unknown) => withRecursive_(value as any, valueOrAlias as string)
5758
+ return (value: unknown) => withRecursive_(value as any, valueOrAlias as never)
5611
5759
  }
5612
5760
  return makeCteSource(
5613
5761
  valueOrAlias as CompletePlan<QueryPlan<any, any, any, any, any, any, any, any, any, any>>,
@@ -5619,7 +5767,7 @@ type AsCurriedResult<
5619
5767
  function lateral<
5620
5768
  Alias extends string
5621
5769
  >(
5622
- alias: Alias
5770
+ alias: LiteralStringInput<Alias>
5623
5771
  ): <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
5624
5772
  value: LateralSourceCompatiblePlan<PlanValue>
5625
5773
  ) => import("../../internal/query.js").LateralSource<PlanValue, Alias>
@@ -5628,11 +5776,11 @@ type AsCurriedResult<
5628
5776
  Alias extends string
5629
5777
  >(
5630
5778
  value: LateralSourceCompatiblePlan<PlanValue>,
5631
- alias: Alias
5779
+ alias: LiteralStringInput<Alias>
5632
5780
  ): import("../../internal/query.js").LateralSource<PlanValue, Alias>
5633
5781
  function lateral(valueOrAlias: unknown, alias?: string): unknown {
5634
5782
  if (alias === undefined) {
5635
- return (value: unknown) => lateral(value as any, valueOrAlias as string)
5783
+ return (value: unknown) => lateral(value as any, valueOrAlias as never)
5636
5784
  }
5637
5785
  return makeLateralSource(
5638
5786
  valueOrAlias as QueryPlan<any, any, any, any, any, any, any, any, any, any>,
@@ -5659,7 +5807,7 @@ type AsCurriedResult<
5659
5807
  columns: Columns
5660
5808
  & UnnestColumnsShapeInput<Columns>
5661
5809
  & UnnestColumnsDialectInput<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5662
- alias: Alias
5810
+ alias: LiteralStringInput<Alias>
5663
5811
  ) => UnnestSource<
5664
5812
  UnnestOutputShape<Columns, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5665
5813
  Alias,
@@ -5675,7 +5823,7 @@ type AsCurriedResult<
5675
5823
  start: Start & NumericExpressionDialectInput<Start, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5676
5824
  stop: Stop & NumericExpressionDialectInput<Stop, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
5677
5825
  step?: Step & (Step extends NumericExpressionInput ? NumericExpressionDialectInput<Step, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb> : unknown),
5678
- alias?: Alias
5826
+ alias?: LiteralStringInput<Alias>
5679
5827
  ) => Dialect extends "postgres"
5680
5828
  ? TableFunctionSource<
5681
5829
  GenerateSeriesOutputShape<Start, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
@@ -5722,8 +5870,8 @@ type AsCurriedResult<
5722
5870
  ? SelectSelectionNonEmptyError<Selection>
5723
5871
  : unknown
5724
5872
 
5725
- export type SelectApi = <Selection extends SelectionShape>(
5726
- selection: Selection & SelectionRootObjectConstraint<Selection> & SelectionNestedNonEmptyConstraint<Selection> & SelectSelectionNonEmptyConstraint<Selection>
5873
+ export type SelectApi = <const Selection extends SelectionShape>(
5874
+ selection: Selection & SelectionRootObjectConstraint<Selection> & SelectionNestedNonEmptyConstraint<Selection> & SelectSelectionNonEmptyConstraint<Selection> & SelectionProjectionAliasCollisionConstraint<Selection>
5727
5875
  ) => QueryPlan<
5728
5876
  Selection,
5729
5877
  ExtractRequired<Selection>,
@@ -6188,8 +6336,8 @@ type AsCurriedResult<
6188
6336
  : unknown
6189
6337
 
6190
6338
  type ReturningApi = Dialect extends "postgres" | "sqlite"
6191
- ? <Selection extends SelectionShape>(
6192
- selection: Selection & SelectionRootObjectConstraint<Selection> & SelectionNestedNonEmptyConstraint<Selection> & ReturningSelectionNonEmptyConstraint<Selection>
6339
+ ? <const Selection extends SelectionShape>(
6340
+ selection: Selection & SelectionRootObjectConstraint<Selection> & SelectionNestedNonEmptyConstraint<Selection> & ReturningSelectionNonEmptyConstraint<Selection> & SelectionProjectionAliasCollisionConstraint<Selection>
6193
6341
  ) =>
6194
6342
  <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
6195
6343
  plan: PlanValue & RequireMutationStatement<PlanValue>
@@ -6258,13 +6406,13 @@ type AsCurriedResult<
6258
6406
  const Columns extends DdlColumnInput,
6259
6407
  UpdateValues extends MutationInputOf<Table.UpdateOf<Target>> | undefined = MutationInputOf<Table.UpdateOf<Target>> | undefined,
6260
6408
  Options extends ConflictActionInput<Target, Dialect, UpdateValues> = ConflictActionInput<Target, Dialect, UpdateValues>,
6261
- ConflictTarget extends ConflictTargetInput<Target, Dialect, Columns> = ConflictTargetInput<Target, Dialect, Columns>
6409
+ const ConflictTarget extends ConflictTargetInput<Target, Dialect, Columns> = ConflictTargetInput<Target, Dialect, Columns>
6262
6410
  >(
6263
- target: ConflictTarget,
6411
+ target: ConflictTarget & ConflictConstraintNameConstraint<ConflictTarget>,
6264
6412
  options?: Options & ConflictActionUpdateNonEmptyConstraint<Options>
6265
- ) =>
6413
+ ) =>
6266
6414
  <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
6267
- plan: PlanValue & RequireInsertStatement<PlanValue>
6415
+ plan: PlanValue & RequireInsertStatement<PlanValue> & ConflictTargetPlanConstraint<MutationTargetOfPlan<PlanValue>, ConflictTarget>
6268
6416
  ) => QueryPlan<
6269
6417
  SelectionOfPlan<PlanValue>,
6270
6418
  Exclude<RequiredOfPlan<PlanValue> | ConflictRequired<UpdateValues, Options, ConflictTarget>, AvailableNames<AvailableOfPlan<PlanValue>>>,
@@ -6328,7 +6476,7 @@ type AsCurriedResult<
6328
6476
  >(
6329
6477
  target: Target,
6330
6478
  values: Values & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
6331
- conflictColumns: ValidateTargetColumnInput<Target, Columns>,
6479
+ conflictColumns: ValidateConflictColumnInput<Target, Columns, false>,
6332
6480
  updateValues?: UpdateValues & UpdateValuesNonEmptyConstraint<Exclude<UpdateValues, undefined>> & MutationValuesDialectConstraint<Exclude<UpdateValues, undefined>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
6333
6481
  ) => QueryPlan<
6334
6482
  {},
@@ -6422,7 +6570,7 @@ type AsCurriedResult<
6422
6570
  target: Target,
6423
6571
  source: Source & (
6424
6572
  SourceRequiredOf<Source> extends never ? unknown : SourceRequirementError<Source>
6425
- ),
6573
+ ) & SourceDialectConstraint<Source, Dialect>,
6426
6574
  on: On,
6427
6575
  options: MergeOptions<Target, MatchedValues, InsertValues, MatchedPredicate, NotMatchedPredicate>
6428
6576
  ) => QueryPlan<
@@ -6636,7 +6784,7 @@ type AsCurriedResult<
6636
6784
  "rollback"
6637
6785
  >
6638
6786
 
6639
- type SavepointApi = <Name extends string>(name: Name) => QueryPlan<
6787
+ type SavepointApi = <Name extends string>(name: NonEmptyStringInput<Name>) => QueryPlan<
6640
6788
  {},
6641
6789
  never,
6642
6790
  {},
@@ -6649,7 +6797,7 @@ type AsCurriedResult<
6649
6797
  "savepoint"
6650
6798
  >
6651
6799
 
6652
- type RollbackToApi = <Name extends string>(name: Name) => QueryPlan<
6800
+ type RollbackToApi = <Name extends string>(name: NonEmptyStringInput<Name>) => QueryPlan<
6653
6801
  {},
6654
6802
  never,
6655
6803
  {},
@@ -6662,7 +6810,7 @@ type AsCurriedResult<
6662
6810
  "rollbackTo"
6663
6811
  >
6664
6812
 
6665
- type ReleaseSavepointApi = <Name extends string>(name: Name) => QueryPlan<
6813
+ type ReleaseSavepointApi = <Name extends string>(name: NonEmptyStringInput<Name>) => QueryPlan<
6666
6814
  {},
6667
6815
  never,
6668
6816
  {},
@@ -6707,10 +6855,10 @@ type AsCurriedResult<
6707
6855
  "dropTable"
6708
6856
  >
6709
6857
 
6710
- type CreateIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput>(
6858
+ type CreateIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput, Name extends string = string>(
6711
6859
  target: Target,
6712
6860
  columns: Columns & ValidateDdlColumnInput<Target, Columns>,
6713
- options?: CreateIndexOptions
6861
+ options?: CreateIndexOptions<Name>
6714
6862
  ) => QueryPlan<
6715
6863
  {},
6716
6864
  never,
@@ -6724,10 +6872,10 @@ type AsCurriedResult<
6724
6872
  "createIndex"
6725
6873
  >
6726
6874
 
6727
- type DropIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput>(
6875
+ type DropIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput, Name extends string = string>(
6728
6876
  target: Target,
6729
6877
  columns: Columns & ValidateDdlColumnInput<Target, Columns>,
6730
- options?: DropIndexOptions
6878
+ options?: DropIndexOptions<Name>
6731
6879
  ) => QueryPlan<
6732
6880
  {},
6733
6881
  never,