effect-qb 4.0.0-beta.66 → 4.0.0-beta.98

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 (129) hide show
  1. package/README.md +5 -2
  2. package/dist/index.js +9376 -0
  3. package/dist/mysql.js +3921 -2573
  4. package/dist/postgres/metadata.js +2491 -1373
  5. package/dist/postgres.js +5453 -5155
  6. package/dist/sqlite.js +6895 -5529
  7. package/dist/standard.js +9330 -0
  8. package/package.json +9 -2
  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.ts +21 -15
  14. package/src/internal/column.ts +44 -7
  15. package/src/internal/datatypes/define.ts +7 -1
  16. package/src/internal/datatypes/enrich.ts +23 -0
  17. package/src/internal/datatypes/lookup.ts +81 -25
  18. package/src/internal/datatypes/matrix.ts +903 -0
  19. package/src/internal/datatypes/shape.ts +2 -0
  20. package/src/internal/derived-table.ts +4 -36
  21. package/src/{mysql/internal/sql-expression-renderer.ts → internal/dialect-renderers/mysql.ts} +552 -361
  22. package/src/{postgres/internal/sql-expression-renderer.ts → internal/dialect-renderers/postgres.ts} +657 -400
  23. package/src/{sqlite/internal/sql-expression-renderer.ts → internal/dialect-renderers/sqlite.ts} +505 -347
  24. package/src/internal/dialect.ts +35 -0
  25. package/src/internal/dsl-mutation-runtime.ts +12 -162
  26. package/src/internal/dsl-plan-runtime.ts +10 -138
  27. package/src/internal/dsl-query-runtime.ts +5 -79
  28. package/src/internal/dsl-transaction-ddl-runtime.ts +41 -65
  29. package/src/internal/executor.ts +14 -16
  30. package/src/internal/grouping-key.ts +87 -20
  31. package/src/internal/implication-runtime.ts +1 -1
  32. package/src/internal/json/path-access.ts +351 -0
  33. package/src/internal/predicate/runtime.ts +3 -0
  34. package/src/internal/query.d.ts +38 -11
  35. package/src/internal/query.ts +64 -25
  36. package/src/internal/renderer.ts +26 -14
  37. package/src/internal/runtime/normalize.ts +12 -5
  38. package/src/internal/scalar.ts +7 -1
  39. package/src/internal/schema-derivation.d.ts +7 -7
  40. package/src/internal/schema-derivation.ts +9 -9
  41. package/src/internal/schema-expression.ts +2 -2
  42. package/src/internal/sql-expression-renderer.ts +19 -0
  43. package/src/internal/standard-dsl.ts +6978 -0
  44. package/src/internal/table-options.ts +126 -66
  45. package/src/internal/table.ts +652 -219
  46. package/src/mysql/column-extension.ts +3 -0
  47. package/src/mysql/column.ts +8 -9
  48. package/src/mysql/datatypes/index.ts +4 -2
  49. package/src/mysql/datatypes/spec.ts +6 -176
  50. package/src/mysql/errors/normalize.ts +0 -1
  51. package/src/mysql/executor.ts +7 -7
  52. package/src/mysql/internal/dialect.ts +9 -4
  53. package/src/mysql/internal/dsl.ts +312 -154
  54. package/src/mysql/internal/renderer.ts +6 -2
  55. package/src/mysql/json.ts +7 -2
  56. package/src/mysql/query-extension.ts +16 -0
  57. package/src/mysql/renderer.ts +37 -3
  58. package/src/mysql/type.ts +60 -0
  59. package/src/mysql.ts +7 -13
  60. package/src/postgres/check.ts +1 -0
  61. package/src/postgres/column-extension.ts +28 -0
  62. package/src/postgres/column.ts +2 -8
  63. package/src/postgres/datatypes/index.d.ts +2 -1
  64. package/src/postgres/datatypes/index.ts +4 -2
  65. package/src/postgres/datatypes/spec.ts +6 -260
  66. package/src/postgres/errors/normalize.ts +0 -1
  67. package/src/postgres/executor.ts +7 -7
  68. package/src/postgres/foreign-key.ts +24 -0
  69. package/src/postgres/function/core.ts +1 -3
  70. package/src/postgres/function/index.ts +1 -17
  71. package/src/postgres/index.ts +1 -0
  72. package/src/postgres/internal/dialect.ts +9 -4
  73. package/src/postgres/internal/dsl.ts +306 -163
  74. package/src/postgres/internal/renderer.ts +6 -2
  75. package/src/postgres/internal/schema-ddl.ts +22 -10
  76. package/src/postgres/internal/schema-model.ts +238 -7
  77. package/src/postgres/json-extension.ts +7 -0
  78. package/src/postgres/json.ts +762 -173
  79. package/src/postgres/jsonb.ts +37 -0
  80. package/src/postgres/primary-key.ts +24 -0
  81. package/src/postgres/query-extension.ts +2 -0
  82. package/src/postgres/renderer.ts +37 -3
  83. package/src/postgres/schema-management.ts +12 -11
  84. package/src/postgres/schema.ts +106 -15
  85. package/src/postgres/table.ts +205 -530
  86. package/src/postgres/type.ts +93 -10
  87. package/src/postgres/unique.ts +32 -0
  88. package/src/postgres.ts +20 -16
  89. package/src/sqlite/column-extension.ts +3 -0
  90. package/src/sqlite/column.ts +8 -9
  91. package/src/sqlite/datatypes/index.ts +4 -2
  92. package/src/sqlite/datatypes/spec.ts +6 -94
  93. package/src/sqlite/errors/normalize.ts +0 -1
  94. package/src/sqlite/executor.ts +7 -7
  95. package/src/sqlite/internal/dialect.ts +9 -4
  96. package/src/sqlite/internal/dsl.ts +301 -154
  97. package/src/sqlite/internal/renderer.ts +6 -2
  98. package/src/sqlite/json.ts +8 -2
  99. package/src/sqlite/query-extension.ts +2 -0
  100. package/src/sqlite/renderer.ts +37 -3
  101. package/src/sqlite/type.ts +40 -0
  102. package/src/sqlite.ts +7 -13
  103. package/src/standard/cast.ts +113 -0
  104. package/src/standard/check.ts +17 -0
  105. package/src/standard/column.ts +163 -0
  106. package/src/standard/datatypes/index.ts +83 -0
  107. package/src/standard/datatypes/spec.ts +12 -0
  108. package/src/standard/dialect.ts +40 -0
  109. package/src/standard/foreign-key.ts +37 -0
  110. package/src/standard/function/aggregate.ts +2 -0
  111. package/src/standard/function/core.ts +2 -0
  112. package/src/standard/function/index.ts +18 -0
  113. package/src/standard/function/string.ts +2 -0
  114. package/src/standard/function/temporal.ts +78 -0
  115. package/src/standard/function/window.ts +2 -0
  116. package/src/standard/index.ts +17 -0
  117. package/src/standard/internal/renderer.ts +45 -0
  118. package/src/standard/json.ts +883 -0
  119. package/src/standard/primary-key.ts +17 -0
  120. package/src/standard/query.ts +152 -0
  121. package/src/standard/renderer.ts +49 -0
  122. package/src/standard/table.ts +151 -0
  123. package/src/standard/unique.ts +17 -0
  124. package/src/standard.ts +32 -0
  125. package/src/internal/aggregation-validation.ts +0 -57
  126. package/src/internal/table.d.ts +0 -180
  127. package/src/mysql/table.ts +0 -186
  128. package/src/postgres/cast.ts +0 -45
  129. package/src/sqlite/table.ts +0 -175
@@ -27,10 +27,31 @@ type BaseCompareGroupOf<Db extends Expression.DbType.Base<any, any>> =
27
27
  : BaseFamilyOf<Db>
28
28
 
29
29
  type BaseCastTargetsOf<Db extends Expression.DbType.Base<any, any>> =
30
- Db extends { readonly castTargets?: readonly (infer Target extends string)[] }
31
- ? Target
30
+ Db extends { readonly castTargets: infer Targets extends readonly string[] }
31
+ ? Targets[number]
32
32
  : never
33
33
 
34
+ type BaseImplicitTargetsOf<Db extends Expression.DbType.Base<any, any>> =
35
+ Db extends { readonly implicitTargets: infer Targets extends readonly string[] }
36
+ ? Targets[number]
37
+ : never
38
+
39
+ type IsCustomBaseDbType<Db extends Expression.DbType.Any> =
40
+ Db extends Expression.DbType.Json<any, any>
41
+ ? false
42
+ : Db extends Expression.DbType.Base<any, any>
43
+ ? Db extends { readonly family: string }
44
+ ? false
45
+ : true
46
+ : false
47
+
48
+ type DbTypeCompatibleWithDialect<
49
+ Db extends Expression.DbType.Any,
50
+ Dialect extends string
51
+ > = Dialect extends "standard"
52
+ ? Db extends { readonly dialect: string } ? true : false
53
+ : Db extends { readonly dialect: Dialect | "standard" } ? true : false
54
+
34
55
  type BaseHasTextualTrait<Db extends Expression.DbType.Base<any, any>> =
35
56
  Db extends { readonly traits?: infer Traits }
36
57
  ? Traits extends { readonly textual: true }
@@ -99,25 +120,56 @@ export type RuntimeOfDbType<Db extends Expression.DbType.Any> =
99
120
  : unknown
100
121
  : unknown
101
122
 
102
- export type CanCompareDbTypes<
123
+ type HaveSameComparableGroup<
103
124
  Left extends Expression.DbType.Any,
104
- Right extends Expression.DbType.Any,
105
- Dialect extends string
106
- > = Left extends { readonly dialect: Dialect }
107
- ? Right extends { readonly dialect: Dialect }
108
- ? CompareGroupOfDbType<Left> extends never
125
+ Right extends Expression.DbType.Any
126
+ > = CompareGroupOfDbType<Left> extends never
127
+ ? false
128
+ : CompareGroupOfDbType<Right> extends never
129
+ ? false
130
+ : CompareGroupOfDbType<Left> extends "null"
109
131
  ? false
110
- : CompareGroupOfDbType<Right> extends never
132
+ : CompareGroupOfDbType<Right> extends "null"
111
133
  ? false
112
- : CompareGroupOfDbType<Left> extends "null"
113
- ? false
114
- : CompareGroupOfDbType<Right> extends "null"
115
- ? false
116
- : [CompareGroupOfDbType<Left>] extends [CompareGroupOfDbType<Right>]
117
- ? [CompareGroupOfDbType<Right>] extends [CompareGroupOfDbType<Left>]
118
- ? true
119
- : false
134
+ : [CompareGroupOfDbType<Left>] extends [CompareGroupOfDbType<Right>]
135
+ ? [CompareGroupOfDbType<Right>] extends [CompareGroupOfDbType<Left>]
136
+ ? true
137
+ : false
138
+ : false
139
+
140
+ export type CanImplicitlyConvertDbType<
141
+ Source extends Expression.DbType.Any,
142
+ Target extends Expression.DbType.Any,
143
+ Dialect extends string
144
+ > = DbTypeCompatibleWithDialect<Source, Dialect> extends true
145
+ ? DbTypeCompatibleWithDialect<Target, Dialect> extends true
146
+ ? Source extends Expression.DbType.Domain<any, infer Base extends Expression.DbType.Any, any>
147
+ ? CanImplicitlyConvertDbType<Base, Target, Dialect>
148
+ : Target extends Expression.DbType.Domain<any, infer TargetBase extends Expression.DbType.Any, any>
149
+ ? CanImplicitlyConvertDbType<Source, TargetBase, Dialect>
150
+ : HaveSameComparableGroup<Source, Target> extends true
151
+ ? true
152
+ : Source extends Expression.DbType.Base<any, any>
153
+ ? FamilyOfDbType<Target> extends BaseImplicitTargetsOf<Source>
154
+ ? true
120
155
  : false
156
+ : false
157
+ : false
158
+ : false
159
+
160
+ export type CanCompareDbTypes<
161
+ Left extends Expression.DbType.Any,
162
+ Right extends Expression.DbType.Any,
163
+ Dialect extends string
164
+ > = DbTypeCompatibleWithDialect<Left, Dialect> extends true
165
+ ? DbTypeCompatibleWithDialect<Right, Dialect> extends true
166
+ ? HaveSameComparableGroup<Left, Right> extends true
167
+ ? true
168
+ : CanImplicitlyConvertDbType<Left, Right, Dialect> extends true
169
+ ? true
170
+ : CanImplicitlyConvertDbType<Right, Left, Dialect> extends true
171
+ ? true
172
+ : false
121
173
  : false
122
174
  : false
123
175
 
@@ -125,8 +177,8 @@ export type CanContainDbTypes<
125
177
  Left extends Expression.DbType.Any,
126
178
  Right extends Expression.DbType.Any,
127
179
  Dialect extends string
128
- > = Left extends { readonly dialect: Dialect }
129
- ? Right extends { readonly dialect: Dialect }
180
+ > = DbTypeCompatibleWithDialect<Left, Dialect> extends true
181
+ ? DbTypeCompatibleWithDialect<Right, Dialect> extends true
130
182
  ? FamilyOfDbType<Left> extends "array" | "range" | "multirange"
131
183
  ? FamilyOfDbType<Right> extends "array" | "range" | "multirange"
132
184
  ? [CompareGroupOfDbType<Left>] extends [CompareGroupOfDbType<Right>]
@@ -142,7 +194,7 @@ export type CanContainDbTypes<
142
194
  export type CanTextuallyCoerceDbType<
143
195
  Db extends Expression.DbType.Any,
144
196
  Dialect extends string
145
- > = Db extends { readonly dialect: Dialect }
197
+ > = DbTypeCompatibleWithDialect<Db, Dialect> extends true
146
198
  ? Db extends Expression.DbType.Domain<any, infer Base extends Expression.DbType.Any, any>
147
199
  ? CanTextuallyCoerceDbType<Base, Dialect>
148
200
  : Db extends Expression.DbType.Enum<any, any> | Expression.DbType.Set<any, any>
@@ -158,13 +210,17 @@ export type CanCastDbType<
158
210
  Source extends Expression.DbType.Any,
159
211
  Target extends Expression.DbType.Any,
160
212
  Dialect extends string
161
- > = Source extends { readonly dialect: Dialect }
162
- ? Target extends { readonly dialect: Dialect }
213
+ > = DbTypeCompatibleWithDialect<Source, Dialect> extends true
214
+ ? DbTypeCompatibleWithDialect<Target, Dialect> extends true
163
215
  ? Source extends Expression.DbType.Domain<any, infer Base extends Expression.DbType.Any, any>
164
216
  ? CanCastDbType<Base, Target, Dialect>
165
217
  : Target extends Expression.DbType.Domain<any, infer TargetBase extends Expression.DbType.Any, any>
166
218
  ? CanCastDbType<Source, TargetBase, Dialect>
167
- : [CompareGroupOfDbType<Source>] extends [CompareGroupOfDbType<Target>]
219
+ : IsCustomBaseDbType<Source> extends true
220
+ ? true
221
+ : IsCustomBaseDbType<Target> extends true
222
+ ? true
223
+ : [CompareGroupOfDbType<Source>] extends [CompareGroupOfDbType<Target>]
168
224
  ? [CompareGroupOfDbType<Target>] extends [CompareGroupOfDbType<Source>]
169
225
  ? true
170
226
  : false
@@ -178,9 +234,9 @@ export type CanCastDbType<
178
234
  ? true
179
235
  : Source extends Expression.DbType.Base<any, any>
180
236
  ? Target extends Expression.DbType.Base<any, any>
181
- ? BaseFamilyOf<Target> extends ExactKindFamily
237
+ ? FamilyOfDbType<Target> extends ExactKindFamily
182
238
  ? false
183
- : BaseFamilyOf<Target> extends BaseCastTargetsOf<Source>
239
+ : FamilyOfDbType<Target> extends BaseCastTargetsOf<Source>
184
240
  ? true
185
241
  : false
186
242
  : false