effect-qb 0.13.0 → 0.15.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 (146) hide show
  1. package/README.md +6 -1431
  2. package/dist/mysql.js +61945 -3611
  3. package/dist/postgres/metadata.js +2818 -0
  4. package/dist/postgres.js +9942 -5591
  5. package/package.json +21 -10
  6. package/src/internal/aggregation-validation.ts +3 -3
  7. package/src/internal/case-analysis.d.ts +18 -0
  8. package/src/internal/case-analysis.ts +4 -4
  9. package/src/internal/coercion/analysis.d.ts +7 -0
  10. package/src/internal/{coercion-analysis.ts → coercion/analysis.ts} +3 -3
  11. package/src/internal/coercion/errors.d.ts +17 -0
  12. package/src/internal/{coercion-errors.ts → coercion/errors.ts} +1 -1
  13. package/src/internal/coercion/kind.d.ts +4 -0
  14. package/src/internal/{coercion-kind.ts → coercion/kind.ts} +2 -2
  15. package/src/internal/{coercion-normalize.ts → coercion/normalize.ts} +1 -1
  16. package/src/internal/coercion/rules.d.ts +6 -0
  17. package/src/internal/{coercion-rules.ts → coercion/rules.ts} +2 -2
  18. package/src/internal/column-state.d.ts +190 -0
  19. package/src/internal/column-state.ts +119 -56
  20. package/src/internal/column.ts +387 -149
  21. package/src/internal/datatypes/define.d.ts +17 -0
  22. package/src/internal/datatypes/define.ts +18 -34
  23. package/src/internal/datatypes/lookup.d.ts +44 -0
  24. package/src/internal/datatypes/lookup.ts +61 -152
  25. package/src/internal/datatypes/shape.d.ts +16 -0
  26. package/src/internal/datatypes/shape.ts +1 -1
  27. package/src/internal/derived-table.d.ts +4 -0
  28. package/src/internal/derived-table.ts +21 -16
  29. package/src/internal/dsl-mutation-runtime.ts +378 -0
  30. package/src/internal/dsl-plan-runtime.ts +387 -0
  31. package/src/internal/dsl-query-runtime.ts +160 -0
  32. package/src/internal/dsl-transaction-ddl-runtime.ts +263 -0
  33. package/src/internal/executor.ts +173 -38
  34. package/src/internal/expression-ast.ts +19 -5
  35. package/src/internal/grouping-key.d.ts +3 -0
  36. package/src/internal/grouping-key.ts +1 -1
  37. package/src/internal/implication-runtime.d.ts +15 -0
  38. package/src/internal/implication-runtime.ts +171 -0
  39. package/src/internal/json/ast.d.ts +30 -0
  40. package/src/internal/json/ast.ts +1 -1
  41. package/src/internal/json/errors.d.ts +8 -0
  42. package/src/internal/json/path.d.ts +75 -0
  43. package/src/internal/json/path.ts +1 -1
  44. package/src/internal/json/types.d.ts +62 -0
  45. package/src/internal/predicate/analysis.d.ts +20 -0
  46. package/src/internal/{predicate-analysis.ts → predicate/analysis.ts} +13 -3
  47. package/src/internal/predicate/atom.d.ts +28 -0
  48. package/src/internal/{predicate-branches.ts → predicate/branches.ts} +2 -2
  49. package/src/internal/predicate/context.d.ts +67 -0
  50. package/src/internal/{predicate-context.ts → predicate/context.ts} +111 -32
  51. package/src/internal/predicate/formula.d.ts +35 -0
  52. package/src/internal/{predicate-formula.ts → predicate/formula.ts} +32 -20
  53. package/src/internal/predicate/key.d.ts +11 -0
  54. package/src/internal/{predicate-key.ts → predicate/key.ts} +2 -2
  55. package/src/internal/{predicate-nnf.ts → predicate/nnf.ts} +2 -2
  56. package/src/internal/predicate/normalize.d.ts +53 -0
  57. package/src/internal/predicate/normalize.ts +273 -0
  58. package/src/internal/predicate/runtime.d.ts +31 -0
  59. package/src/internal/predicate/runtime.ts +679 -0
  60. package/src/internal/projection-alias.d.ts +13 -0
  61. package/src/internal/projections.d.ts +31 -0
  62. package/src/internal/projections.ts +1 -1
  63. package/src/internal/query-ast.d.ts +217 -0
  64. package/src/internal/query-ast.ts +1 -1
  65. package/src/internal/query-requirements.d.ts +20 -0
  66. package/src/internal/query.d.ts +775 -0
  67. package/src/internal/query.ts +767 -275
  68. package/src/internal/renderer.ts +7 -21
  69. package/src/internal/row-set.d.ts +53 -0
  70. package/src/internal/{plan.ts → row-set.ts} +23 -11
  71. package/src/internal/{runtime-normalize.ts → runtime/normalize.ts} +9 -31
  72. package/src/internal/{runtime-schema.ts → runtime/schema.ts} +84 -55
  73. package/src/internal/runtime/value.d.ts +22 -0
  74. package/src/internal/{runtime-value.ts → runtime/value.ts} +2 -2
  75. package/src/internal/scalar.d.ts +107 -0
  76. package/src/internal/scalar.ts +191 -0
  77. package/src/internal/schema-derivation.d.ts +105 -0
  78. package/src/internal/schema-derivation.ts +93 -21
  79. package/src/internal/schema-expression.d.ts +18 -0
  80. package/src/internal/schema-expression.ts +75 -0
  81. package/src/internal/table-options.d.ts +94 -0
  82. package/src/internal/table-options.ts +94 -8
  83. package/src/internal/table.d.ts +173 -0
  84. package/src/internal/table.ts +135 -54
  85. package/src/mysql/column.ts +95 -18
  86. package/src/mysql/datatypes/index.ts +58 -3
  87. package/src/mysql/errors/generated.ts +57336 -0
  88. package/src/mysql/errors/index.ts +1 -0
  89. package/src/mysql/errors/normalize.ts +55 -53
  90. package/src/mysql/errors/types.ts +74 -0
  91. package/src/mysql/executor.ts +69 -7
  92. package/src/mysql/function/aggregate.ts +1 -5
  93. package/src/mysql/function/core.ts +1 -3
  94. package/src/mysql/function/index.ts +1 -1
  95. package/src/mysql/function/string.ts +1 -5
  96. package/src/mysql/function/temporal.ts +12 -15
  97. package/src/mysql/function/window.ts +1 -6
  98. package/src/{internal/mysql-dialect.ts → mysql/internal/dialect.ts} +1 -1
  99. package/src/mysql/internal/dsl.ts +6115 -0
  100. package/src/{internal/mysql-renderer.ts → mysql/internal/renderer.ts} +6 -6
  101. package/src/mysql/internal/sql-expression-renderer.ts +1455 -0
  102. package/src/mysql/json.ts +2 -0
  103. package/src/mysql/query.ts +111 -86
  104. package/src/mysql/renderer.ts +1 -1
  105. package/src/mysql/table.ts +1 -1
  106. package/src/mysql.ts +6 -4
  107. package/src/postgres/cast.ts +30 -0
  108. package/src/postgres/column.ts +178 -20
  109. package/src/postgres/datatypes/index.d.ts +515 -0
  110. package/src/postgres/datatypes/index.ts +49 -5
  111. package/src/postgres/datatypes/spec.d.ts +412 -0
  112. package/src/postgres/errors/generated.ts +2636 -0
  113. package/src/postgres/errors/index.ts +1 -0
  114. package/src/postgres/errors/normalize.ts +47 -62
  115. package/src/postgres/errors/types.ts +92 -34
  116. package/src/postgres/executor.ts +37 -5
  117. package/src/postgres/function/aggregate.ts +1 -5
  118. package/src/postgres/function/core.ts +20 -2
  119. package/src/postgres/function/index.ts +1 -1
  120. package/src/postgres/function/string.ts +1 -5
  121. package/src/postgres/function/temporal.ts +12 -15
  122. package/src/postgres/function/window.ts +1 -6
  123. package/src/{internal/postgres-dialect.ts → postgres/internal/dialect.ts} +1 -1
  124. package/src/{internal/query-factory.ts → postgres/internal/dsl.ts} +1568 -2120
  125. package/src/{internal/postgres-renderer.ts → postgres/internal/renderer.ts} +6 -6
  126. package/src/postgres/internal/schema-ddl.ts +108 -0
  127. package/src/postgres/internal/schema-model.ts +150 -0
  128. package/src/{internal → postgres/internal}/sql-expression-renderer.ts +112 -46
  129. package/src/postgres/json.ts +493 -0
  130. package/src/postgres/metadata.ts +31 -0
  131. package/src/postgres/query.ts +113 -86
  132. package/src/postgres/renderer.ts +3 -13
  133. package/src/postgres/schema-expression.ts +17 -0
  134. package/src/postgres/schema-management.ts +204 -0
  135. package/src/postgres/schema.ts +35 -0
  136. package/src/postgres/table.ts +316 -42
  137. package/src/postgres/type.ts +31 -0
  138. package/src/postgres.ts +20 -4
  139. package/CHANGELOG.md +0 -134
  140. package/src/internal/expression.ts +0 -327
  141. package/src/internal/predicate-normalize.ts +0 -202
  142. package/src/mysql/function/json.ts +0 -4
  143. package/src/mysql/private/query.ts +0 -13
  144. package/src/postgres/function/json.ts +0 -4
  145. package/src/postgres/private/query.ts +0 -13
  146. /package/src/internal/{predicate-atom.ts → predicate/atom.ts} +0 -0
@@ -0,0 +1,31 @@
1
+ import * as Expression from "./scalar.js";
2
+ /**
3
+ * Flat projection metadata shared by renderers and executors.
4
+ *
5
+ * `path` identifies where a value should be decoded in the nested result row,
6
+ * while `alias` is the flat SQL column alias used by the rendered query.
7
+ */
8
+ export interface Projection {
9
+ readonly path: readonly string[];
10
+ readonly alias: string;
11
+ }
12
+ /** Selection leaf paired with its resolved projection alias. */
13
+ export interface FlattenedProjection {
14
+ readonly path: readonly string[];
15
+ readonly expression: Expression.Any;
16
+ readonly alias: string;
17
+ }
18
+ /**
19
+ * Flattens a nested selection object into leaf expressions with decode paths
20
+ * and resolved SQL aliases.
21
+ */
22
+ export declare const flattenSelection: (selection: Record<string, unknown>, path?: readonly string[]) => readonly FlattenedProjection[];
23
+ /**
24
+ * Validates the flattened projection set shared by renderer and executor code.
25
+ *
26
+ * This rejects:
27
+ * - duplicate SQL aliases
28
+ * - duplicate decode paths
29
+ * - conflicting prefix paths like `profile` and `profile.id`
30
+ */
31
+ export declare const validateProjections: (projections: readonly Projection[]) => void;
@@ -1,4 +1,4 @@
1
- import * as Expression from "./expression.js"
1
+ import * as Expression from "./scalar.js"
2
2
  import * as ProjectionAlias from "./projection-alias.js"
3
3
 
4
4
  /**
@@ -0,0 +1,217 @@
1
+ import type * as Expression from "./scalar.js";
2
+ /** Symbol used to attach query-clause AST metadata to query-plan values. */
3
+ export declare const TypeId: unique symbol;
4
+ export type TypeId = typeof TypeId;
5
+ /** Statement kinds supported by the current query AST. */
6
+ export type QueryStatement = "select" | "set" | "insert" | "update" | "delete" | "truncate" | "merge" | "transaction" | "commit" | "rollback" | "savepoint" | "rollbackTo" | "releaseSavepoint" | "createTable" | "createIndex" | "dropIndex" | "alterTable" | "dropTable";
7
+ /** Base `FROM` clause recorded by the query AST. */
8
+ export interface FromClause<TableName extends string = string> {
9
+ readonly kind: "from";
10
+ readonly tableName: TableName;
11
+ readonly baseTableName: string;
12
+ readonly source: unknown;
13
+ }
14
+ /** Boolean predicate recorded in a `WHERE` clause. */
15
+ export interface WhereClause<Predicate extends Expression.Any = Expression.Any> {
16
+ readonly kind: "where";
17
+ readonly predicate: Predicate;
18
+ }
19
+ /** Boolean predicate recorded in a `HAVING` clause. */
20
+ export interface HavingClause<Predicate extends Expression.Any = Expression.Any> {
21
+ readonly kind: "having";
22
+ readonly predicate: Predicate;
23
+ }
24
+ /** Assignment recorded in a mutation statement. */
25
+ export interface AssignmentClause<Value extends Expression.Any = Expression.Any> {
26
+ readonly tableName?: string;
27
+ readonly columnName: string;
28
+ readonly value: Value;
29
+ }
30
+ /** One row in a multi-row `values (...)` insert source. */
31
+ export interface InsertValuesRowClause<Values extends readonly AssignmentClause[] = readonly AssignmentClause[]> {
32
+ readonly values: Values;
33
+ }
34
+ /** Additional insert source kinds beyond a single literal row. */
35
+ export type InsertSourceClause = {
36
+ readonly kind: "values";
37
+ readonly columns: readonly [string, ...string[]];
38
+ readonly rows: readonly [InsertValuesRowClause, ...InsertValuesRowClause[]];
39
+ } | {
40
+ readonly kind: "query";
41
+ readonly columns: readonly [string, ...string[]];
42
+ readonly query: unknown;
43
+ } | {
44
+ readonly kind: "unnest";
45
+ readonly columns: readonly [string, ...string[]];
46
+ readonly values: readonly {
47
+ readonly columnName: string;
48
+ readonly values: readonly unknown[];
49
+ }[];
50
+ };
51
+ /** One branch inside a `merge` statement. */
52
+ export type MergeMatchedClause<Predicate extends Expression.Any | undefined = Expression.Any | undefined> = {
53
+ readonly kind: "update";
54
+ readonly values: readonly AssignmentClause[];
55
+ readonly predicate?: Predicate;
56
+ } | {
57
+ readonly kind: "delete";
58
+ readonly predicate?: Predicate;
59
+ };
60
+ /** Insert branch inside a `merge` statement. */
61
+ export interface MergeNotMatchedClause<Predicate extends Expression.Any | undefined = Expression.Any | undefined> {
62
+ readonly kind: "insert";
63
+ readonly values: readonly AssignmentClause[];
64
+ readonly predicate?: Predicate;
65
+ }
66
+ /** Payload recorded by a `merge` statement. */
67
+ export interface MergeClause<On extends Expression.Any = Expression.Any, Predicate extends Expression.Any | undefined = Expression.Any | undefined> {
68
+ readonly kind: "merge";
69
+ readonly on: On;
70
+ readonly whenMatched?: MergeMatchedClause<Predicate>;
71
+ readonly whenNotMatched?: MergeNotMatchedClause<Predicate>;
72
+ }
73
+ /** DDL payload recorded by schema-manipulation statements. */
74
+ export type DdlClause = {
75
+ readonly kind: "createTable";
76
+ readonly ifNotExists: boolean;
77
+ } | {
78
+ readonly kind: "dropTable";
79
+ readonly ifExists: boolean;
80
+ } | {
81
+ readonly kind: "createIndex";
82
+ readonly name: string;
83
+ readonly columns: readonly [string, ...string[]];
84
+ readonly unique: boolean;
85
+ readonly ifNotExists: boolean;
86
+ } | {
87
+ readonly kind: "dropIndex";
88
+ readonly name: string;
89
+ readonly ifExists: boolean;
90
+ };
91
+ /** Truncate payload recorded by a truncate statement. */
92
+ export interface TruncateClause {
93
+ readonly kind: "truncate";
94
+ readonly restartIdentity: boolean;
95
+ readonly cascade: boolean;
96
+ }
97
+ /** Transaction-control payload recorded by transactional statements. */
98
+ export type TransactionClause = {
99
+ readonly kind: "transaction";
100
+ readonly isolationLevel?: "read committed" | "repeatable read" | "serializable";
101
+ readonly readOnly?: boolean;
102
+ } | {
103
+ readonly kind: "commit";
104
+ } | {
105
+ readonly kind: "rollback";
106
+ } | {
107
+ readonly kind: "savepoint";
108
+ readonly name: string;
109
+ } | {
110
+ readonly kind: "rollbackTo";
111
+ readonly name: string;
112
+ } | {
113
+ readonly kind: "releaseSavepoint";
114
+ readonly name: string;
115
+ } | {
116
+ readonly kind: "dropTable";
117
+ readonly ifExists: boolean;
118
+ } | {
119
+ readonly kind: "createIndex";
120
+ readonly name: string;
121
+ readonly columns: readonly [string, ...string[]];
122
+ readonly unique: boolean;
123
+ readonly ifNotExists: boolean;
124
+ } | {
125
+ readonly kind: "dropIndex";
126
+ readonly name: string;
127
+ readonly ifExists: boolean;
128
+ };
129
+ /** Locking mode attached to a select statement. */
130
+ export interface LockClause {
131
+ readonly kind: "lock";
132
+ readonly mode: "update" | "share" | "lowPriority" | "ignore" | "quick";
133
+ readonly nowait?: boolean;
134
+ readonly skipLocked?: boolean;
135
+ }
136
+ /** Conflict target attached to a Postgres insert statement. */
137
+ export type ConflictTargetClause = {
138
+ readonly kind: "columns";
139
+ readonly columns: readonly [string, ...string[]];
140
+ readonly where?: Expression.Any;
141
+ } | {
142
+ readonly kind: "constraint";
143
+ readonly name: string;
144
+ };
145
+ /** Conflict clause attached to an insert statement. */
146
+ export interface ConflictClause {
147
+ readonly kind: "conflict";
148
+ readonly target?: ConflictTargetClause;
149
+ readonly action: "doNothing" | "doUpdate";
150
+ readonly values?: readonly AssignmentClause[];
151
+ readonly where?: Expression.Any;
152
+ }
153
+ /** Join kinds supported by the current query layer. */
154
+ export type JoinKind = "inner" | "left" | "right" | "full" | "cross";
155
+ /** Join clause recorded by the query AST. */
156
+ export interface JoinClause<TableName extends string = string, Kind extends JoinKind = JoinKind, On extends Expression.Any | undefined = Expression.Any | undefined> {
157
+ readonly kind: Kind;
158
+ readonly tableName: TableName;
159
+ readonly baseTableName: string;
160
+ readonly source: unknown;
161
+ readonly on?: On;
162
+ }
163
+ /** Sort direction recorded by an `ORDER BY` clause. */
164
+ export type OrderDirection = "asc" | "desc";
165
+ /** Ordering clause recorded by the query AST. */
166
+ export interface OrderByClause<Value extends Expression.Any = Expression.Any> {
167
+ readonly kind: "orderBy";
168
+ readonly value: Value;
169
+ readonly direction: OrderDirection;
170
+ }
171
+ /** Set-operator kinds supported by compound queries. */
172
+ export type SetOperatorKind = "union" | "intersect" | "except";
173
+ /** Compound-query clause recorded by the query AST. */
174
+ export interface SetOperationClause {
175
+ readonly kind: SetOperatorKind;
176
+ readonly all?: boolean;
177
+ readonly query: unknown;
178
+ }
179
+ /**
180
+ * Internal query AST stored alongside public `Plan` metadata.
181
+ *
182
+ * The public plan state tracks selection, required sources, available sources,
183
+ * and dialect. This AST captures the clause ordering needed to eventually
184
+ * render or optimize a SQL query.
185
+ */
186
+ export interface Ast<Selection = unknown, Grouped extends string = never, Statement extends QueryStatement = "select"> {
187
+ readonly kind: Statement;
188
+ readonly select: Selection;
189
+ readonly distinct?: boolean;
190
+ readonly distinctOn?: readonly Expression.Any[];
191
+ readonly setBase?: unknown;
192
+ readonly recursive?: boolean;
193
+ readonly from?: FromClause;
194
+ readonly fromSources?: readonly FromClause[];
195
+ readonly into?: FromClause;
196
+ readonly target?: FromClause;
197
+ readonly targets?: readonly FromClause[];
198
+ readonly using?: FromClause;
199
+ readonly values?: readonly AssignmentClause[];
200
+ readonly insertSource?: InsertSourceClause;
201
+ readonly set?: readonly AssignmentClause[];
202
+ readonly ddl?: DdlClause;
203
+ readonly truncate?: TruncateClause;
204
+ readonly merge?: MergeClause;
205
+ readonly transaction?: TransactionClause;
206
+ readonly lock?: LockClause;
207
+ readonly conflict?: ConflictClause;
208
+ readonly where: readonly WhereClause[];
209
+ readonly having: readonly HavingClause[];
210
+ readonly joins: readonly JoinClause[];
211
+ readonly groupBy: readonly Expression.Any[];
212
+ readonly orderBy: readonly OrderByClause[];
213
+ readonly limit?: Expression.Any;
214
+ readonly offset?: Expression.Any;
215
+ readonly setOperations?: readonly SetOperationClause[];
216
+ readonly groupedSources?: Grouped;
217
+ }
@@ -1,4 +1,4 @@
1
- import type * as Expression from "./expression.js"
1
+ import type * as Expression from "./scalar.js"
2
2
 
3
3
  /** Symbol used to attach query-clause AST metadata to query-plan values. */
4
4
  export const TypeId: unique symbol = Symbol.for("effect-qb/QueryAst")
@@ -0,0 +1,20 @@
1
+ /** Query capabilities directly modeled by the current plan AST. */
2
+ export type QueryCapability = "read" | "write" | "ddl" | "transaction" | "locking";
3
+ /**
4
+ * Capability or query-mode requirement associated with a dialect error.
5
+ *
6
+ * Not every requirement is currently expressible by query plans. The extra
7
+ * vocabulary exists so dialect maps can stay stable as the plan surface grows.
8
+ */
9
+ export type QueryRequirement = QueryCapability | "ddl" | "transaction" | "locking";
10
+ /** Runtime capability list for the current read-only query plans. */
11
+ export declare const read_query_capabilities: readonly ["read"];
12
+ /** Type-level union of two capability sets. */
13
+ export type MergeCapabilities<Left extends QueryCapability, Right extends QueryCapability> = Left | Right;
14
+ /** Type-level union of capability sets across a readonly tuple. */
15
+ export type MergeCapabilityTuple<Values extends readonly QueryCapability[], Current extends QueryCapability = never> = Values extends readonly [
16
+ infer Head extends QueryCapability,
17
+ ...infer Tail extends readonly QueryCapability[]
18
+ ] ? MergeCapabilityTuple<Tail, Current | Head> : Current;
19
+ /** Dedupes and normalizes capability lists at runtime. */
20
+ export declare const union_query_capabilities: (...values: readonly (readonly QueryCapability[])[]) => readonly QueryCapability[];