qubu 0.4.0 → 0.4.2
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.
- package/dist/{canonical-BbnqavJm.mjs → canonical-BXUguqfo.mjs} +23 -23
- package/dist/codegen.d.mts +25 -33
- package/dist/codegen.mjs +38 -45
- package/dist/column-hqKr7-1I.mjs +620 -0
- package/dist/{complete-D5Djh-zo.mjs → complete-WYyVozgK.mjs} +50 -50
- package/dist/{complete-types-BavBtv8J.d.mts → complete-types-IjEn5VPN.d.mts} +56 -56
- package/dist/core.d.mts +2 -2
- package/dist/core.mjs +4 -4
- package/dist/ddl.d.mts +12 -12
- package/dist/ddl.mjs +13 -14
- package/dist/{dialect-b2-Z6uBF.mjs → dialect-wUKrnPMB.mjs} +2 -2
- package/dist/diff.d.mts +1 -1
- package/dist/diff.mjs +6 -7
- package/dist/{index-DH0qV6aS.d.mts → index-1DpA3mUh.d.mts} +20 -20
- package/dist/{index-D3ZOwPT-.d.mts → index-CPvfEheG.d.mts} +13 -15
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +94 -95
- package/dist/introspection.d.mts +8 -8
- package/dist/introspection.mjs +29 -30
- package/dist/{json-CUZlv4HT.mjs → json-Db7XRD91.mjs} +2 -2
- package/dist/migration.d.mts +20 -21
- package/dist/migration.mjs +5 -6
- package/dist/{mysql-CKEKGnj4.mjs → mysql-B_cYzzX2.mjs} +237 -7
- package/dist/mysql.d.mts +2 -2
- package/dist/mysql.mjs +3 -3
- package/dist/{on-conflict-4MOBl51J.mjs → on-conflict-hfPW0KmQ.mjs} +3 -4
- package/dist/postgres.d.mts +5 -5
- package/dist/postgres.mjs +6 -6
- package/dist/{registry-CXV8u7Pt.mjs → registry-BRMLYwDp.mjs} +26 -29
- package/dist/{relational-DuQ9IHSb.mjs → relational-BZ3WDPzC.mjs} +2 -2
- package/dist/schema.d.mts +1 -1
- package/dist/schema.mjs +5 -6
- package/dist/{snapshot-DJpfmxhQ.mjs → snapshot-C-W65HEd.mjs} +5 -5
- package/dist/snapshot.d.mts +3 -3
- package/dist/snapshot.mjs +5 -7
- package/dist/{source-DGO3DRgg.mjs → source-BcS2AsIg.mjs} +6 -8
- package/dist/{serialize-CFtYYAdk.mjs → sqlite-Cg0nwYEH.mjs} +326 -12
- package/dist/sqlite.d.mts +1 -1
- package/dist/sqlite.mjs +2 -2
- package/dist/{standard-BTVYKh_F.mjs → standard-DfcZEVOj.mjs} +1 -1
- package/dist/{table-D6rcs8SB.mjs → table-Bp5irMSj.mjs} +2 -3
- package/dist/{types-Deo_q43Y.d.mts → types-BK1COGZe.d.mts} +1113 -1128
- package/dist/{types-g-vVvj1B.mjs → types-JM3FcAnX.mjs} +7 -8
- package/dist/{types-CSNJTYaM.d.mts → types-JSZHpUEj.d.mts} +83 -84
- package/dist/{value-b6OFZXVS.mjs → value-Bi71Agyf.mjs} +1 -1
- package/dist/vite/ambient.d.ts +309 -340
- package/dist/vite.d.mts +5 -6
- package/dist/vite.mjs +3 -4
- package/docs/dialects-and-execution.md +45 -55
- package/docs/getting-started.md +4 -4
- package/docs/guides/better-auth.md +57 -0
- package/docs/guides/compose-queries.md +24 -67
- package/docs/guides/drizzle.md +23 -23
- package/docs/guides/extensions/dialects.md +4 -4
- package/docs/guides/extensions/sources-and-clauses.md +15 -15
- package/docs/guides/extensions/typed-expressions.md +13 -17
- package/docs/guides/extensions/unsafe-syntax.md +3 -3
- package/docs/guides/json.md +7 -7
- package/docs/guides/mutations.md +14 -21
- package/docs/guides/select/conditions.md +6 -8
- package/docs/guides/select/grouping-and-windows.md +4 -15
- package/docs/guides/select/ordering-and-pagination.md +6 -19
- package/docs/guides/select/overview.md +12 -26
- package/docs/guides/sql-templates.md +20 -24
- package/docs/guides/vite-plugin.md +9 -13
- package/docs/index.md +5 -7
- package/docs/query-model/fragments.md +4 -15
- package/docs/query-model/result-shapes.md +11 -14
- package/docs/query-model/source-scope.md +31 -49
- package/docs/reference/mysql-snapshot.md +2 -5
- package/docs/reference/postgres-snapshot.md +3 -3
- package/docs/reference/sqlite-snapshot.md +2 -5
- package/docs/reference/supported-surface.md +26 -26
- package/docs/schema/catalog-model.md +2 -5
- package/docs/schema/code-generation.md +18 -18
- package/docs/schema/columns-and-writes.md +17 -25
- package/docs/schema/constraints-and-indexes.md +36 -52
- package/docs/schema/ddl-emission.md +6 -6
- package/docs/schema/diff.md +5 -5
- package/docs/schema/introspection.md +7 -7
- package/docs/schema/migration-plans.md +9 -9
- package/docs/schema/snapshots.md +3 -3
- package/docs/schema/storage-and-schema-sql.md +11 -11
- package/docs/schema/tables-and-names.md +11 -14
- package/docs/sql-semantic-types.md +10 -10
- package/docs/troubleshooting.md +10 -10
- package/package.json +21 -33
- package/skills/qubu/agents/openai.yaml +3 -3
- package/dist/column-D-8OqGuV.mjs +0 -328
- package/dist/column-LV7oGQde.mjs +0 -296
- package/dist/drizzle-mysql.d.mts +0 -24
- package/dist/drizzle-mysql.mjs +0 -72
- package/dist/drizzle-postgres.d.mts +0 -24
- package/dist/drizzle-postgres.mjs +0 -73
- package/dist/drizzle-sqlite.d.mts +0 -57
- package/dist/drizzle-sqlite.mjs +0 -108
- package/dist/drizzle.d.mts +0 -13
- package/dist/drizzle.mjs +0 -2
- package/dist/errors-BGCoLe_r.mjs +0 -14
- package/dist/postgres-BK2APkKP.mjs +0 -236
- package/dist/runtime-Cn_Xgzta.mjs +0 -193
- package/dist/sqlite-CrsK0Fza.mjs +0 -320
- package/dist/types-DZsueVoI.d.mts +0 -45
|
@@ -4,11 +4,11 @@ interface SqlSemanticType<TName extends string = string> {
|
|
|
4
4
|
readonly sqlType: TName;
|
|
5
5
|
}
|
|
6
6
|
/** Marker for extensions whose SQL domain has not been declared. */
|
|
7
|
-
type SqlUnknown = SqlSemanticType<
|
|
7
|
+
type SqlUnknown = SqlSemanticType<"unknown"> & {
|
|
8
8
|
readonly sqlUnknown: true;
|
|
9
9
|
};
|
|
10
10
|
/** SQL domains accepted by text operations and the text equality group. */
|
|
11
|
-
interface SqlTextLike extends SqlEqualityComparable<
|
|
11
|
+
interface SqlTextLike extends SqlEqualityComparable<"text"> {
|
|
12
12
|
readonly sqlTextLike: true;
|
|
13
13
|
}
|
|
14
14
|
/** SQL domains accepted by numeric operations. */
|
|
@@ -20,37 +20,37 @@ interface SqlOrderable<TGroup = unknown> {
|
|
|
20
20
|
readonly sqlOrderGroup: TGroup;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
* SQL domains that can be compared for equality with the same compatibility
|
|
24
|
-
*
|
|
23
|
+
* SQL domains that can be compared for equality with the same compatibility group. Dialect
|
|
24
|
+
* extensions can share a group with a portable domain.
|
|
25
25
|
*/
|
|
26
26
|
interface SqlEqualityComparable<TGroup = unknown> {
|
|
27
27
|
readonly sqlEqualityGroup: TGroup;
|
|
28
28
|
}
|
|
29
29
|
/** Portable text domain with text, ordering, and equality capabilities. */
|
|
30
|
-
type SqlText = SqlSemanticType<
|
|
30
|
+
type SqlText = SqlSemanticType<"text"> & SqlTextLike & SqlOrderable<"text"> & SqlEqualityComparable<"text">;
|
|
31
31
|
/** Portable UUID domain; equality-capable but deliberately not text-like. */
|
|
32
|
-
type SqlUuid = SqlSemanticType<
|
|
32
|
+
type SqlUuid = SqlSemanticType<"uuid"> & SqlEqualityComparable<"uuid">;
|
|
33
33
|
/** Portable integer domain in the shared numeric compatibility groups. */
|
|
34
|
-
type SqlInteger = SqlSemanticType<
|
|
34
|
+
type SqlInteger = SqlSemanticType<"integer"> & SqlNumericLike & SqlOrderable<"numeric"> & SqlEqualityComparable<"numeric">;
|
|
35
35
|
/** Portable decimal domain in the shared numeric compatibility groups. */
|
|
36
|
-
type SqlDecimal = SqlSemanticType<
|
|
36
|
+
type SqlDecimal = SqlSemanticType<"decimal"> & SqlNumericLike & SqlOrderable<"numeric"> & SqlEqualityComparable<"numeric">;
|
|
37
37
|
/** Portable boolean domain with equality comparison. */
|
|
38
|
-
type SqlBoolean = SqlSemanticType<
|
|
38
|
+
type SqlBoolean = SqlSemanticType<"boolean"> & SqlEqualityComparable<"boolean">;
|
|
39
39
|
/** Portable date domain with date-specific equality and ordering groups. */
|
|
40
|
-
type SqlDate = SqlSemanticType<
|
|
40
|
+
type SqlDate = SqlSemanticType<"date"> & SqlOrderable<"date"> & SqlEqualityComparable<"date">;
|
|
41
41
|
/** Portable timestamp domain with timestamp-specific comparison groups. */
|
|
42
|
-
type SqlTimestamp = SqlSemanticType<
|
|
42
|
+
type SqlTimestamp = SqlSemanticType<"timestamp"> & SqlOrderable<"timestamp"> & SqlEqualityComparable<"timestamp">;
|
|
43
43
|
/** Portable JSON domain retaining its decoded application value type. */
|
|
44
|
-
type SqlJson<TValue = unknown> = SqlSemanticType<
|
|
44
|
+
type SqlJson<TValue = unknown> = SqlSemanticType<"json"> & {
|
|
45
45
|
readonly sqlJsonValue?: TValue;
|
|
46
46
|
};
|
|
47
47
|
/** Portable bigint domain in the shared numeric compatibility groups. */
|
|
48
|
-
type SqlBigInt = SqlSemanticType<
|
|
48
|
+
type SqlBigInt = SqlSemanticType<"bigint"> & SqlNumericLike & SqlOrderable<"numeric"> & SqlEqualityComparable<"numeric">;
|
|
49
49
|
/** Portable binary domain with equality comparison. */
|
|
50
|
-
type SqlBinary = SqlSemanticType<
|
|
50
|
+
type SqlBinary = SqlSemanticType<"binary"> & SqlEqualityComparable<"binary">;
|
|
51
51
|
/** Any declared SQL semantic type, including user and dialect extensions. */
|
|
52
52
|
type AnySqlType = SqlSemanticType<string>;
|
|
53
|
-
type IsUnresolvedSqlType<T> = T extends SqlUnknown ? true : T extends AnySqlType ? string extends T[
|
|
53
|
+
type IsUnresolvedSqlType<T> = T extends SqlUnknown ? true : T extends AnySqlType ? string extends T["sqlType"] ? true : false : false;
|
|
54
54
|
/** Whether a declared SQL domain satisfies a semantic capability constraint. */
|
|
55
55
|
type SqlTypeSatisfies<TActual, TConstraint> = true extends IsUnresolvedSqlType<TActual> ? true : TActual extends TConstraint ? true : false;
|
|
56
56
|
type EqualityGroup<T> = T extends SqlEqualityComparable<infer TGroup> ? TGroup : never;
|
|
@@ -64,90 +64,90 @@ type SqlOrderCompatible<TLeft, TRight> = true extends IsUnresolvedSqlType<TLeft>
|
|
|
64
64
|
declare const fragmentMetadata: unique symbol;
|
|
65
65
|
/** Result value metadata, including nullability provenance and its SQL domain. */
|
|
66
66
|
type ResultMeta<TOutput, TNullableFrom = never, TSqlType extends AnySqlType = SqlUnknown> = {
|
|
67
|
-
readonly kind:
|
|
67
|
+
readonly kind: "result";
|
|
68
68
|
readonly output: TOutput;
|
|
69
69
|
readonly nullableFrom: TNullableFrom;
|
|
70
70
|
readonly sqlType: TSqlType;
|
|
71
71
|
};
|
|
72
72
|
type RequiresSourceMeta<TSource> = {
|
|
73
|
-
readonly kind:
|
|
73
|
+
readonly kind: "requires-source";
|
|
74
74
|
readonly source: TSource;
|
|
75
75
|
};
|
|
76
76
|
/** A source that must be provided by the enclosing query scope. */
|
|
77
77
|
type RequiresOuterSourceMeta<TSource> = {
|
|
78
|
-
readonly kind:
|
|
78
|
+
readonly kind: "requires-outer-source";
|
|
79
79
|
readonly source: TSource;
|
|
80
80
|
};
|
|
81
81
|
/** A correlated query clause that provisions sources from its enclosing scope. */
|
|
82
82
|
type ProvidesOuterSourceMeta<TSource> = {
|
|
83
|
-
readonly kind:
|
|
83
|
+
readonly kind: "provides-outer-source";
|
|
84
84
|
readonly source: TSource;
|
|
85
85
|
};
|
|
86
86
|
type NullableSourceMeta<TSource> = {
|
|
87
|
-
readonly kind:
|
|
87
|
+
readonly kind: "nullable-source";
|
|
88
88
|
readonly source: TSource;
|
|
89
89
|
};
|
|
90
90
|
/** A fragment that introduces a typed relational source to FROM/JOIN. */
|
|
91
91
|
type ProvidesSourceMeta<TSource, TRow = unknown> = {
|
|
92
|
-
readonly kind:
|
|
92
|
+
readonly kind: "provides-source";
|
|
93
93
|
readonly source: TSource;
|
|
94
94
|
readonly row: TRow;
|
|
95
95
|
};
|
|
96
96
|
/** Dependencies read by an expression at the current query level. */
|
|
97
97
|
type ExpressionMeta<TDependencies = unknown> = {
|
|
98
|
-
readonly kind:
|
|
98
|
+
readonly kind: "expression";
|
|
99
99
|
readonly dependencies: TDependencies;
|
|
100
100
|
};
|
|
101
101
|
/** Dependencies consumed inside an aggregate expression. */
|
|
102
102
|
type AggregateMeta<TDependencies = unknown> = {
|
|
103
|
-
readonly kind:
|
|
103
|
+
readonly kind: "aggregate";
|
|
104
104
|
readonly dependencies: TDependencies;
|
|
105
105
|
};
|
|
106
106
|
/** Marks an expression that contains a window function. */
|
|
107
107
|
type WindowMeta = {
|
|
108
|
-
readonly kind:
|
|
108
|
+
readonly kind: "window";
|
|
109
109
|
};
|
|
110
110
|
/** Marks an expression that contains a scalar or predicate subquery. */
|
|
111
111
|
type SubqueryMeta = {
|
|
112
|
-
readonly kind:
|
|
112
|
+
readonly kind: "subquery";
|
|
113
113
|
};
|
|
114
114
|
/** Grouping keys and column dependencies made available by a GROUP BY clause. */
|
|
115
115
|
type GroupingMeta<TKeys = unknown, TDependencies = unknown> = {
|
|
116
|
-
readonly kind:
|
|
116
|
+
readonly kind: "grouping";
|
|
117
117
|
readonly keys: TKeys;
|
|
118
118
|
readonly dependencies: TDependencies;
|
|
119
119
|
};
|
|
120
|
-
type QueryCardinality =
|
|
120
|
+
type QueryCardinality = "many" | "zero-or-one" | "exactly-one";
|
|
121
121
|
type CardinalityMeta<TCardinality extends QueryCardinality = QueryCardinality> = {
|
|
122
|
-
readonly kind:
|
|
122
|
+
readonly kind: "cardinality";
|
|
123
123
|
readonly cardinality: TCardinality;
|
|
124
124
|
};
|
|
125
125
|
/** A fragment whose syntax must be rendered by a dialect with this capability. */
|
|
126
126
|
type RequiresCapabilityMeta<TCapability extends DialectCapability = DialectCapability> = {
|
|
127
|
-
readonly kind:
|
|
127
|
+
readonly kind: "requires-capability";
|
|
128
128
|
readonly capability: TCapability;
|
|
129
129
|
};
|
|
130
130
|
type FragmentMeta = ResultMeta<unknown, unknown, AnySqlType> | RequiresSourceMeta<unknown> | RequiresOuterSourceMeta<unknown> | ProvidesOuterSourceMeta<unknown> | NullableSourceMeta<unknown> | ProvidesSourceMeta<unknown, unknown> | ExpressionMeta | AggregateMeta | WindowMeta | SubqueryMeta | GroupingMeta | CardinalityMeta | RequiresCapabilityMeta;
|
|
131
131
|
interface RenderContext {
|
|
132
132
|
readonly dialect: Dialect;
|
|
133
133
|
/** Whether selected fields name an application result or a SQL relation. */
|
|
134
|
-
readonly projectionMode:
|
|
134
|
+
readonly projectionMode: "result" | "relation";
|
|
135
135
|
append(text: string): void;
|
|
136
136
|
parameter(value: unknown): void;
|
|
137
137
|
render(part: Fragment<any>): void;
|
|
138
138
|
/** Render an embedded query with SQL-facing projection names. */
|
|
139
139
|
renderRelation(part: Fragment<any>): void;
|
|
140
140
|
/**
|
|
141
|
-
* Optional schema-rendering hook used to emit a bare physical column name.
|
|
142
|
-
*
|
|
141
|
+
* Optional schema-rendering hook used to emit a bare physical column name. Ordinary query
|
|
142
|
+
* rendering leaves this undefined and retains qualification.
|
|
143
143
|
*/
|
|
144
144
|
readonly renderColumnReference?: (columnName: string) => void;
|
|
145
145
|
}
|
|
146
146
|
type RenderFunction = (context: RenderContext) => void;
|
|
147
147
|
/**
|
|
148
|
-
* The smallest composable unit in qubu. Runtime rendering is deliberately
|
|
149
|
-
*
|
|
150
|
-
*
|
|
148
|
+
* The smallest composable unit in qubu. Runtime rendering is deliberately just a function; the
|
|
149
|
+
* metadata type carries semantic information for TypeScript consumers without imposing an AST on
|
|
150
|
+
* extensions.
|
|
151
151
|
*/
|
|
152
152
|
interface Fragment<TMetadata = any> {
|
|
153
153
|
readonly [fragmentMetadata]?: TMetadata;
|
|
@@ -156,10 +156,10 @@ interface Fragment<TMetadata = any> {
|
|
|
156
156
|
type AnyFragment = Fragment<any>;
|
|
157
157
|
type MetadataOf<T> = T extends Fragment<infer TMetadata> ? TMetadata : never;
|
|
158
158
|
type WithoutResult<TMetadata> = TMetadata extends {
|
|
159
|
-
readonly kind:
|
|
159
|
+
readonly kind: "result" | "cardinality";
|
|
160
160
|
} ? never : TMetadata;
|
|
161
161
|
type ResultMetadata<TMetadata> = TMetadata extends {
|
|
162
|
-
readonly kind:
|
|
162
|
+
readonly kind: "result";
|
|
163
163
|
} ? TMetadata : never;
|
|
164
164
|
type ResultOutput<TMetadata> = TMetadata extends {
|
|
165
165
|
readonly output: infer TOutput;
|
|
@@ -171,43 +171,43 @@ type ResultSqlType<TMetadata> = TMetadata extends {
|
|
|
171
171
|
readonly sqlType: infer TSqlType extends AnySqlType;
|
|
172
172
|
} ? TSqlType : SqlUnknown;
|
|
173
173
|
type RequiredSource<TMetadata> = TMetadata extends {
|
|
174
|
-
readonly kind:
|
|
174
|
+
readonly kind: "requires-source";
|
|
175
175
|
readonly source: infer TSource;
|
|
176
176
|
} ? TSource : never;
|
|
177
177
|
type RequiredOuterSource<TMetadata> = TMetadata extends {
|
|
178
|
-
readonly kind:
|
|
178
|
+
readonly kind: "requires-outer-source";
|
|
179
179
|
readonly source: infer TSource;
|
|
180
180
|
} ? TSource : never;
|
|
181
181
|
type ProvidedOuterSource<TMetadata> = TMetadata extends {
|
|
182
|
-
readonly kind:
|
|
182
|
+
readonly kind: "provides-outer-source";
|
|
183
183
|
readonly source: infer TSource;
|
|
184
184
|
} ? TSource : never;
|
|
185
185
|
type NullableSource<TMetadata> = TMetadata extends {
|
|
186
|
-
readonly kind:
|
|
186
|
+
readonly kind: "nullable-source";
|
|
187
187
|
readonly source: infer TSource;
|
|
188
188
|
} ? TSource : never;
|
|
189
189
|
type ExpressionDependencies<TMetadata> = TMetadata extends {
|
|
190
|
-
readonly kind:
|
|
190
|
+
readonly kind: "expression";
|
|
191
191
|
readonly dependencies: infer TDependencies;
|
|
192
192
|
} ? TDependencies : never;
|
|
193
193
|
type AggregateDependencies<TMetadata> = TMetadata extends {
|
|
194
|
-
readonly kind:
|
|
194
|
+
readonly kind: "aggregate";
|
|
195
195
|
readonly dependencies: infer TDependencies;
|
|
196
196
|
} ? TDependencies : never;
|
|
197
197
|
type GroupingKeys<TMetadata> = TMetadata extends {
|
|
198
|
-
readonly kind:
|
|
198
|
+
readonly kind: "grouping";
|
|
199
199
|
readonly keys: infer TKeys;
|
|
200
200
|
} ? TKeys : never;
|
|
201
201
|
type GroupingDependencies<TMetadata> = TMetadata extends {
|
|
202
|
-
readonly kind:
|
|
202
|
+
readonly kind: "grouping";
|
|
203
203
|
readonly dependencies: infer TDependencies;
|
|
204
204
|
} ? TDependencies : never;
|
|
205
205
|
type Cardinality<TMetadata> = TMetadata extends {
|
|
206
|
-
readonly kind:
|
|
206
|
+
readonly kind: "cardinality";
|
|
207
207
|
readonly cardinality: infer TCardinality;
|
|
208
208
|
} ? TCardinality : never;
|
|
209
209
|
type RequiredCapabilities<TMetadata> = TMetadata extends {
|
|
210
|
-
readonly kind:
|
|
210
|
+
readonly kind: "requires-capability";
|
|
211
211
|
readonly capability: infer TCapability extends DialectCapability;
|
|
212
212
|
} ? TCapability : never;
|
|
213
213
|
type InheritedMetadataOf<TMetadata> = WithoutResult<TMetadata>;
|
|
@@ -219,7 +219,7 @@ type RequiresOf<T> = RequiredSource<MetadataOf<T>>;
|
|
|
219
219
|
type RequiresOuterOf<T> = RequiredOuterSource<MetadataOf<T>>;
|
|
220
220
|
type ProvidesOuterOf<T> = ProvidedOuterSource<MetadataOf<T>>;
|
|
221
221
|
type RequiresOuterMetadataOf<T> = Extract<MetadataOf<T>, {
|
|
222
|
-
readonly kind:
|
|
222
|
+
readonly kind: "requires-outer-source";
|
|
223
223
|
}>;
|
|
224
224
|
type NullabilityOf<T> = ResultNullableFrom<ResultMetadata<MetadataOf<T>>>;
|
|
225
225
|
type NullableSourcesOf<T> = NullableSource<MetadataOf<T>>;
|
|
@@ -230,13 +230,13 @@ type VisibleDependenciesOf<T> = Exclude<DependenciesOf<T>, AggregateDependencies
|
|
|
230
230
|
type GroupingKeysOf<T> = GroupingKeys<MetadataOf<T>>;
|
|
231
231
|
type GroupingDependenciesOf<T> = GroupingDependencies<MetadataOf<T>>;
|
|
232
232
|
type HasAggregate<T> = [Extract<MetadataOf<T>, {
|
|
233
|
-
readonly kind:
|
|
233
|
+
readonly kind: "aggregate";
|
|
234
234
|
}>] extends [never] ? false : true;
|
|
235
235
|
type HasWindow<T> = [Extract<MetadataOf<T>, {
|
|
236
|
-
readonly kind:
|
|
236
|
+
readonly kind: "window";
|
|
237
237
|
}>] extends [never] ? false : true;
|
|
238
238
|
type HasSubquery<T> = [Extract<MetadataOf<T>, {
|
|
239
|
-
readonly kind:
|
|
239
|
+
readonly kind: "subquery";
|
|
240
240
|
}>] extends [never] ? false : true;
|
|
241
241
|
type CardinalityOf<T> = Cardinality<MetadataOf<T>>;
|
|
242
242
|
type CapabilitiesOf<T> = RequiredCapabilities<MetadataOf<T>>;
|
|
@@ -248,7 +248,7 @@ declare function isFragment(value: unknown): value is AnyFragment;
|
|
|
248
248
|
//#endregion
|
|
249
249
|
//#region src/result.d.ts
|
|
250
250
|
/** Portable result domains that can require driver-specific normalization. */
|
|
251
|
-
type DecodableResultType =
|
|
251
|
+
type DecodableResultType = "boolean" | "date" | "timestamp" | "json";
|
|
252
252
|
/** Context supplied while decoding one projected field. */
|
|
253
253
|
interface ResultDecodeContext {
|
|
254
254
|
readonly dialect: Dialect;
|
|
@@ -295,7 +295,7 @@ declare class ResultDecodingError extends TypeError {
|
|
|
295
295
|
}
|
|
296
296
|
//#endregion
|
|
297
297
|
//#region src/expressions/types.d.ts
|
|
298
|
-
type ExpressionKind =
|
|
298
|
+
type ExpressionKind = "value" | "column" | "function" | "operator" | "sql" | "subquery" | "unsafe";
|
|
299
299
|
/** Runtime/type-level proof that an expression is safe to use in schema SQL. */
|
|
300
300
|
declare const schemaExpressionBrand: unique symbol;
|
|
301
301
|
interface SchemaExpressionBrand {
|
|
@@ -304,12 +304,11 @@ interface SchemaExpressionBrand {
|
|
|
304
304
|
interface Expression<TMetadata = any, TKind extends ExpressionKind = ExpressionKind> extends Fragment<TMetadata>, ResultValueCarrier {
|
|
305
305
|
readonly expressionKind: TKind;
|
|
306
306
|
/** Internal runtime marker for query constructs rejected by schema SQL. */
|
|
307
|
-
readonly expressionCategory?:
|
|
307
|
+
readonly expressionCategory?: "aggregate" | "window" | "subquery";
|
|
308
308
|
}
|
|
309
309
|
/**
|
|
310
|
-
* An expression whose renderer is deterministic and may be used by schema
|
|
311
|
-
*
|
|
312
|
-
* they explicitly opt into this contract.
|
|
310
|
+
* An expression whose renderer is deterministic and may be used by schema metadata. Query
|
|
311
|
+
* extensions remain ordinary {@link Expression} values until they explicitly opt into this contract.
|
|
313
312
|
*/
|
|
314
313
|
type SchemaExpression<TMetadata = any, TKind extends ExpressionKind = ExpressionKind> = Expression<TMetadata, TKind> & SchemaExpressionBrand;
|
|
315
314
|
type AnyExpression = Expression<any, any>;
|
|
@@ -320,7 +319,7 @@ type ExpressionNullability<T> = NullabilityOf<T>;
|
|
|
320
319
|
/** Extract the SQL semantic domain produced by an expression. */
|
|
321
320
|
type ExpressionSqlType<T> = SqlTypeOf<T>;
|
|
322
321
|
/** Add a concrete dialect requirement without dropping expression metadata. */
|
|
323
|
-
declare function withDialectCapability<const TCapability extends DialectCapability, TExpression extends AnyExpression>(expression: TExpression, capability: TCapability): TExpression extends SchemaExpression<any, any> ? SchemaExpression<MetadataOf<TExpression> | RequiresCapabilityMeta<TCapability>, TExpression[
|
|
322
|
+
declare function withDialectCapability<const TCapability extends DialectCapability, TExpression extends AnyExpression>(expression: TExpression, capability: TCapability): TExpression extends SchemaExpression<any, any> ? SchemaExpression<MetadataOf<TExpression> | RequiresCapabilityMeta<TCapability>, TExpression["expressionKind"]> : Expression<MetadataOf<TExpression> | RequiresCapabilityMeta<TCapability>, TExpression["expressionKind"]>;
|
|
324
323
|
/** An expression whose result is known to be assignable to `TOutput`. */
|
|
325
324
|
type ExpressionWithOutput<TOutput, TKind extends ExpressionKind = ExpressionKind> = Expression<ResultMeta<TOutput, unknown, AnySqlType> | RequiresSourceMeta<unknown> | NullableSourceMeta<unknown> | ExpressionMeta<unknown> | AggregateMeta<unknown> | RequiresCapabilityMeta | WindowMeta | SubqueryMeta, TKind>;
|
|
326
325
|
/** Sparse type-level configuration for a result-producing expression. */
|
|
@@ -332,31 +331,31 @@ interface ResultExpressionConfig {
|
|
|
332
331
|
readonly sqlType?: AnySqlType;
|
|
333
332
|
}
|
|
334
333
|
type ResultConfigValue<TConfig, TKey extends PropertyKey, TFallback> = TKey extends keyof TConfig ? TConfig[TKey] : TFallback;
|
|
335
|
-
type ResultConfigOutput<TConfig> = ResultConfigValue<TConfig,
|
|
336
|
-
type ResultConfigChildren<TConfig> = ResultConfigValue<TConfig,
|
|
337
|
-
type ResultConfigKind<TConfig> = Extract<ResultConfigValue<TConfig,
|
|
338
|
-
type ResultConfigNullableFrom<TConfig> = ResultConfigValue<TConfig,
|
|
339
|
-
type ResultConfigSqlType<TConfig> = Extract<ResultConfigValue<TConfig,
|
|
334
|
+
type ResultConfigOutput<TConfig> = ResultConfigValue<TConfig, "output", unknown>;
|
|
335
|
+
type ResultConfigChildren<TConfig> = ResultConfigValue<TConfig, "children", never>;
|
|
336
|
+
type ResultConfigKind<TConfig> = Extract<ResultConfigValue<TConfig, "kind", ExpressionKind>, ExpressionKind>;
|
|
337
|
+
type ResultConfigNullableFrom<TConfig> = ResultConfigValue<TConfig, "nullableFrom", NullabilityOf<ResultConfigChildren<TConfig>>>;
|
|
338
|
+
type ResultConfigSqlType<TConfig> = Extract<ResultConfigValue<TConfig, "sqlType", SqlUnknown>, AnySqlType>;
|
|
340
339
|
/** Build an expression result while inheriting non-result metadata from children. */
|
|
341
340
|
type ResultExpression<TConfig extends ResultExpressionConfig = {}> = SchemaExpression<ResultMeta<ResultConfigOutput<TConfig>, ResultConfigNullableFrom<TConfig>, ResultConfigSqlType<TConfig>> | ExpressionMeta<DependenciesOf<ResultConfigChildren<TConfig>>> | InheritedMetadata<ResultConfigChildren<TConfig>>, ResultConfigKind<TConfig>>;
|
|
342
341
|
/** Build an aggregate result while recording which dependencies it consumes. */
|
|
343
342
|
type AggregateResultExpression<TConfig extends ResultExpressionConfig = {}> = Expression<ResultMeta<ResultConfigOutput<TConfig>, ResultConfigNullableFrom<TConfig>, ResultConfigSqlType<TConfig>> | ExpressionMeta<DependenciesOf<ResultConfigChildren<TConfig>>> | AggregateMeta<DependenciesOf<ResultConfigChildren<TConfig>>> | InheritedMetadata<ResultConfigChildren<TConfig>>, ResultConfigKind<TConfig>>;
|
|
344
343
|
/** A result expression that contains a query boundary. */
|
|
345
|
-
type SubqueryResultExpression<TConfig extends Omit<ResultExpressionConfig,
|
|
346
|
-
declare function makeExpression<TMetadata = never, TKind extends ExpressionKind = ExpressionKind>(expressionKind: TKind, render: (context: RenderContext) => void, expressionCategory?:
|
|
344
|
+
type SubqueryResultExpression<TConfig extends Omit<ResultExpressionConfig, "kind"> = {}> = Expression<ResultMeta<ResultConfigOutput<TConfig>, ResultConfigNullableFrom<TConfig>, ResultConfigSqlType<TConfig>> | ExpressionMeta<DependenciesOf<ResultConfigChildren<TConfig>>> | InheritedMetadata<ResultConfigChildren<TConfig>> | SubqueryMeta, "subquery">;
|
|
345
|
+
declare function makeExpression<TMetadata = never, TKind extends ExpressionKind = ExpressionKind>(expressionKind: TKind, render: (context: RenderContext) => void, expressionCategory?: "aggregate" | "window" | "subquery", result?: ResultValueMetadata): Expression<TMetadata, TKind>;
|
|
347
346
|
/** Mark a query-only expression category without changing its SQL renderer. */
|
|
348
|
-
declare function markExpressionCategory<TMetadata, TKind extends ExpressionKind>(expression: Expression<TMetadata, TKind>, category:
|
|
347
|
+
declare function markExpressionCategory<TMetadata, TKind extends ExpressionKind>(expression: Expression<TMetadata, TKind>, category: "aggregate" | "window" | "subquery"): Expression<TMetadata, TKind>;
|
|
349
348
|
declare function isExpression(value: unknown): value is AnyExpression;
|
|
350
349
|
//#endregion
|
|
351
350
|
//#region src/expressions/column.d.ts
|
|
352
|
-
interface ColumnReference<TFieldName extends string = string, TMetadata = never> extends SchemaExpression<TMetadata,
|
|
351
|
+
interface ColumnReference<TFieldName extends string = string, TMetadata = never> extends SchemaExpression<TMetadata, "column"> {
|
|
353
352
|
/** Application-facing key used by typed rows and dependency metadata. */
|
|
354
353
|
readonly fieldName: TFieldName;
|
|
355
354
|
/** Physical SQL identifier rendered for this column. */
|
|
356
355
|
readonly columnName: string;
|
|
357
356
|
}
|
|
358
357
|
type ColumnDependency<TSource, TName extends string> = {
|
|
359
|
-
readonly kind:
|
|
358
|
+
readonly kind: "column";
|
|
360
359
|
readonly source: TSource;
|
|
361
360
|
readonly name: TName;
|
|
362
361
|
};
|
|
@@ -364,9 +363,254 @@ type ColumnGroupingDependencies<T> = T extends ColumnReference<any, any> ? Depen
|
|
|
364
363
|
/** Turn an expression into a fragment that renders it without changing it. */
|
|
365
364
|
declare function expressionFragment<TExpression extends Expression>(expression: TExpression): Fragment<MetadataOf<TExpression>>;
|
|
366
365
|
//#endregion
|
|
366
|
+
//#region src/query/errors.d.ts
|
|
367
|
+
/** Stable diagnostics shared by type-level and runtime query validation. */
|
|
368
|
+
type QueryValidationErrorCode = "invalid-selection" | "duplicate-clause" | "invalid-mutation" | "unsafe-mutation" | "invalid-update" | "invalid-insert" | "invalid-comparison" | "invalid-boolean-expression" | "invalid-pagination" | "invalid-row-lock" | "invalid-json-path" | "missing-source" | "invalid-grouping" | "incompatible-sql-domain" | "incompatible-sql-equality" | "incompatible-sql-order" | "incompatible-set-domain" | "invalid-subquery" | "invalid-omission" | "invalid-stream-query" | "invalid-explain-query" | "invalid-explain-options" | "unsupported-explain-option" | "unsupported-explain-dialect" | "missing-dialect-capability";
|
|
369
|
+
interface QueryValidationIssue {
|
|
370
|
+
readonly code: QueryValidationErrorCode;
|
|
371
|
+
readonly context: string;
|
|
372
|
+
readonly path: readonly (string | number)[];
|
|
373
|
+
readonly message: string;
|
|
374
|
+
readonly hint: string;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* A type-level query failure that names the failing rule and the repair path. The legacy detail
|
|
378
|
+
* field is optional so each validator can retain the useful source or clause type in the compiler
|
|
379
|
+
* diagnostic.
|
|
380
|
+
*/
|
|
381
|
+
type QueryTypeValidation<TCode extends QueryValidationErrorCode, TContext extends string, THint extends string, TDetail = never> = {
|
|
382
|
+
readonly __qubu_error_code__: TCode;
|
|
383
|
+
readonly __qubu_error_context__: TContext;
|
|
384
|
+
readonly __qubu_error_hint__: THint;
|
|
385
|
+
} & ([TDetail] extends [never] ? unknown : {
|
|
386
|
+
readonly __qubu_error_detail__: TDetail;
|
|
387
|
+
});
|
|
388
|
+
/** Raised when a query cannot satisfy Qubu's runtime authoring rules. */
|
|
389
|
+
declare class QueryValidationError extends TypeError {
|
|
390
|
+
readonly name = "QueryValidationError";
|
|
391
|
+
readonly code: QueryValidationErrorCode;
|
|
392
|
+
readonly context: string;
|
|
393
|
+
readonly path: readonly (string | number)[];
|
|
394
|
+
readonly hint: string;
|
|
395
|
+
readonly issue: QueryValidationIssue;
|
|
396
|
+
constructor(issue: QueryValidationIssue);
|
|
397
|
+
}
|
|
398
|
+
//#endregion
|
|
399
|
+
//#region src/core/render.d.ts
|
|
400
|
+
type DefaultDialectCapability = "json";
|
|
401
|
+
interface RenderedQuery {
|
|
402
|
+
readonly text: string;
|
|
403
|
+
readonly parameters: readonly unknown[];
|
|
404
|
+
}
|
|
405
|
+
interface RenderOptions<TCapabilities extends DialectCapability = DialectCapability> {
|
|
406
|
+
readonly dialect?: Dialect<TCapabilities>;
|
|
407
|
+
}
|
|
408
|
+
type IsAny$1<T> = 0 extends 1 & T ? true : false;
|
|
409
|
+
type MissingCapabilities<TQuery, TCapabilities extends DialectCapability> = IsAny$1<CapabilitiesOf<TQuery>> extends true ? never : Exclude<CapabilitiesOf<TQuery>, TCapabilities>;
|
|
410
|
+
type RenderCapabilityValidation<TQuery, TCapabilities extends DialectCapability> = [MissingCapabilities<TQuery, TCapabilities>] extends [never] ? unknown : QueryTypeValidation<"missing-dialect-capability", "render.dialect", "Provide a dialect that supports every capability required by the query.", MissingCapabilities<TQuery, TCapabilities>>;
|
|
411
|
+
declare function render<TQuery extends AnyFragment>(query: TQuery & RenderCapabilityValidation<TQuery, DefaultDialectCapability>): RenderedQuery;
|
|
412
|
+
declare function render<TQuery extends AnyFragment, TCapabilities extends DialectCapability>(query: TQuery & RenderCapabilityValidation<TQuery, TCapabilities>, options: RenderOptions<TCapabilities> | Dialect<TCapabilities>): RenderedQuery;
|
|
413
|
+
//#endregion
|
|
414
|
+
//#region src/execution.d.ts
|
|
415
|
+
type StreamableQuery<TRow extends object = Record<string, unknown>> = QueryWithRow<TRow> & {
|
|
416
|
+
readonly queryKind: "select" | "set";
|
|
417
|
+
};
|
|
418
|
+
/** Rendering policy and cancellation input accepted by query execution. */
|
|
419
|
+
interface ExecutionOptions extends RenderOptions {
|
|
420
|
+
/** Passed to the application adapter for drivers that support cancellation. */
|
|
421
|
+
readonly signal?: AbortSignal;
|
|
422
|
+
}
|
|
423
|
+
/** Rendering, EXPLAIN, and cancellation options for plan requests. */
|
|
424
|
+
interface ExplainOptions extends RenderOptions, ExplainRenderOptions {
|
|
425
|
+
/** Passed to the application adapter for drivers that support cancellation. */
|
|
426
|
+
readonly signal?: AbortSignal;
|
|
427
|
+
}
|
|
428
|
+
/** EXPLAIN options accepted for SELECT and set-operation queries. */
|
|
429
|
+
type ExplainReadOptions = ExplainOptions;
|
|
430
|
+
/** EXPLAIN options for mutations, which never run with analysis enabled. */
|
|
431
|
+
type ExplainMutationOptions = Omit<ExplainOptions, "analyze"> & {
|
|
432
|
+
readonly analyze?: never;
|
|
433
|
+
};
|
|
434
|
+
/** Select read-only or plan-only EXPLAIN options from the query kind. */
|
|
435
|
+
type ExplainOptionsFor<TQuery extends AnyQuery> = TQuery["queryKind"] extends "select" | "set" ? ExplainReadOptions : ExplainMutationOptions;
|
|
436
|
+
/** Controls the lifecycle of one adapter-owned transaction. */
|
|
437
|
+
interface TransactionOptions {
|
|
438
|
+
/** Passed to the adapter for transaction begin, commit, and rollback. */
|
|
439
|
+
readonly signal?: AbortSignal;
|
|
440
|
+
}
|
|
441
|
+
/** One rendered statement and the controls passed to an application adapter. */
|
|
442
|
+
interface ExecutionRequest {
|
|
443
|
+
/** SQL text and raw application parameters produced by Qubu's renderer. */
|
|
444
|
+
readonly statement: RenderedQuery;
|
|
445
|
+
/** The source query kind, available without parsing rendered SQL. */
|
|
446
|
+
readonly queryKind: QueryKind;
|
|
447
|
+
/** Named logical fields used by Qubu after the adapter returns raw rows. */
|
|
448
|
+
readonly resultShape: ResultShape;
|
|
449
|
+
/** Present when the caller supplied an abort signal to {@link execute} or {@link stream}. */
|
|
450
|
+
readonly signal?: AbortSignal;
|
|
451
|
+
}
|
|
452
|
+
/** One rendered EXPLAIN statement and the controls passed to an adapter. */
|
|
453
|
+
interface ExplainRequest extends ExecutionRequest {}
|
|
454
|
+
/**
|
|
455
|
+
* Driver-neutral rows and optional mutation facts returned by an adapter.
|
|
456
|
+
*
|
|
457
|
+
* Adapters normalize driver result fields into this shape. They should omit a mutation fact when
|
|
458
|
+
* the driver cannot report it accurately.
|
|
459
|
+
*/
|
|
460
|
+
interface ExecutionResult<TRow extends object = Record<string, unknown>> {
|
|
461
|
+
/** Decoded result rows. Mutations without `RETURNING` use an empty array. */
|
|
462
|
+
readonly rows: readonly TRow[];
|
|
463
|
+
/** Rows inserted, updated, or deleted when the driver reports that count. */
|
|
464
|
+
readonly affectedRows?: number | bigint;
|
|
465
|
+
/** Rows whose stored values changed when distinct from affected rows. */
|
|
466
|
+
readonly changedRows?: number | bigint;
|
|
467
|
+
/** An insert identifier reported by the driver, including generated IDs. */
|
|
468
|
+
readonly insertId?: string | number | bigint;
|
|
469
|
+
}
|
|
470
|
+
/** Driver-normalized rows and mutation facts returned to Qubu by an adapter. */
|
|
471
|
+
interface AdapterExecutionResult {
|
|
472
|
+
/** Object rows keyed by the query's rendered result aliases. */
|
|
473
|
+
readonly rows: readonly Readonly<Record<string, unknown>>[];
|
|
474
|
+
readonly affectedRows?: number | bigint;
|
|
475
|
+
readonly changedRows?: number | bigint;
|
|
476
|
+
readonly insertId?: string | number | bigint;
|
|
477
|
+
}
|
|
478
|
+
/** Adapter-decoded vendor plan rows returned by an EXPLAIN request. */
|
|
479
|
+
interface ExplainResult<TPlanRow extends object = Record<string, unknown>> {
|
|
480
|
+
/** Opaque plan rows in the shape selected by the application adapter. */
|
|
481
|
+
readonly rows: readonly TPlanRow[];
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* The driver-facing boundary. `request.statement.parameters` contains raw application values in
|
|
485
|
+
* placeholder order; the adapter binds and encodes them for its driver. Connection pooling,
|
|
486
|
+
* transactions, retries, and proprietary driver-row normalization remain adapter concerns. Qubu
|
|
487
|
+
* applies the adapter's registered logical result decoders afterward.
|
|
488
|
+
*/
|
|
489
|
+
interface QueryAdapter {
|
|
490
|
+
/** Default rendering policy for queries sent through this adapter. */
|
|
491
|
+
readonly dialect: Dialect;
|
|
492
|
+
/** Driver-specific conversions for portable logical result domains. */
|
|
493
|
+
readonly decoders?: ResultDecoders;
|
|
494
|
+
/** Execute one request and normalize the driver's result fields. */
|
|
495
|
+
execute(request: ExecutionRequest): Promise<AdapterExecutionResult>;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* An opt-in adapter capability for typed, adapter-decoded EXPLAIN results.
|
|
499
|
+
*
|
|
500
|
+
* Qubu renders and validates the statement. The adapter binds parameters, executes the plan
|
|
501
|
+
* request, owns cancellation and connection lifecycle, and decodes vendor-specific plan rows
|
|
502
|
+
* without a cross-dialect Qubu plan tree.
|
|
503
|
+
*/
|
|
504
|
+
interface ExplainableQueryAdapter<TPlanRow extends object = Record<string, unknown>> extends QueryAdapter {
|
|
505
|
+
explain(request: ExplainRequest): Promise<ExplainResult<TPlanRow>>;
|
|
506
|
+
}
|
|
507
|
+
/** Extract the plan-row type owned by an explainable adapter. */
|
|
508
|
+
type ExplainPlanRow<TAdapter extends ExplainableQueryAdapter> = TAdapter extends ExplainableQueryAdapter<infer TPlanRow> ? TPlanRow : never;
|
|
509
|
+
/**
|
|
510
|
+
* An opt-in adapter capability for streaming rows from read queries.
|
|
511
|
+
*
|
|
512
|
+
* The adapter owns the returned iterator and every resource behind it. The iterator must release
|
|
513
|
+
* those resources when it completes, is closed early, fails, or observes an aborted request
|
|
514
|
+
* signal.
|
|
515
|
+
*/
|
|
516
|
+
interface StreamingQueryAdapter extends QueryAdapter {
|
|
517
|
+
/** Return an adapter-owned object-row stream for one SELECT or set query. */
|
|
518
|
+
stream(request: ExecutionRequest): AsyncIterable<Readonly<Record<string, unknown>>>;
|
|
519
|
+
}
|
|
520
|
+
type QueryExecutor = QueryAdapter;
|
|
521
|
+
/**
|
|
522
|
+
* An adapter that can pin one driver connection for a callback transaction. The callback receives
|
|
523
|
+
* an adapter scoped to that transaction. Qubu does not issue transaction SQL or manage the driver's
|
|
524
|
+
* connection lifecycle.
|
|
525
|
+
*/
|
|
526
|
+
interface TransactionalQueryAdapter<TTransactionAdapter extends QueryAdapter = QueryAdapter> extends QueryAdapter {
|
|
527
|
+
transaction<T>(callback: (adapter: TTransactionAdapter) => Promise<T>, options?: TransactionOptions): Promise<T>;
|
|
528
|
+
}
|
|
529
|
+
type TransactionAdapterOf<TAdapter extends TransactionalQueryAdapter> = TAdapter extends TransactionalQueryAdapter<infer TTransactionAdapter> ? TTransactionAdapter : never;
|
|
530
|
+
/** A transaction-capable streaming adapter whose scoped client can stream. */
|
|
531
|
+
type StreamingTransactionalQueryAdapter = StreamingQueryAdapter & TransactionalQueryAdapter<StreamingQueryAdapter>;
|
|
532
|
+
/** A query client with one application-owned adapter bound to every call. */
|
|
533
|
+
interface QubuClient<TAdapter extends QueryAdapter = QueryAdapter> {
|
|
534
|
+
/** The adapter supplied to {@link qubu}. */
|
|
535
|
+
readonly adapter: TAdapter;
|
|
536
|
+
/** Execute a query and keep the adapter's structured mutation facts. */
|
|
537
|
+
execute<TRow extends object>(query: QueryWithRow<TRow>, options?: ExecutionOptions): Promise<ExecutionResult<TRow>>;
|
|
538
|
+
/** Execute a query and return only its decoded rows. */
|
|
539
|
+
rows<TRow extends object>(query: QueryWithRow<TRow>, options?: ExecutionOptions): Promise<readonly TRow[]>;
|
|
540
|
+
}
|
|
541
|
+
/** A bound client whose adapter also decodes vendor-specific EXPLAIN rows. */
|
|
542
|
+
interface QubuExplainableClient<TAdapter extends ExplainableQueryAdapter = ExplainableQueryAdapter> extends QubuClient<TAdapter> {
|
|
543
|
+
/** Explain a query without executing it and return adapter-owned plan rows. */
|
|
544
|
+
explain<TQuery extends AnyQuery>(query: TQuery, options?: ExplainOptionsFor<TQuery>): Promise<ExplainResult<ExplainPlanRow<TAdapter>>>;
|
|
545
|
+
}
|
|
546
|
+
/** A bound client whose adapter also supports typed read-query streams. */
|
|
547
|
+
interface QubuStreamingClient<TAdapter extends StreamingQueryAdapter = StreamingQueryAdapter> extends QubuClient<TAdapter> {
|
|
548
|
+
/** Stream decoded rows without materializing the complete result. */
|
|
549
|
+
stream<TRow extends object>(query: StreamableQuery<TRow>, options?: ExecutionOptions): AsyncIterable<TRow>;
|
|
550
|
+
}
|
|
551
|
+
/** A bound client that supports both streaming and typed EXPLAIN plans. */
|
|
552
|
+
interface QubuStreamingExplainableClient<TAdapter extends StreamingQueryAdapter & ExplainableQueryAdapter = StreamingQueryAdapter & ExplainableQueryAdapter> extends QubuStreamingClient<TAdapter>, QubuExplainableClient<TAdapter> {}
|
|
553
|
+
type QubuClientFor<TAdapter extends QueryAdapter> = TAdapter extends StreamingQueryAdapter ? TAdapter extends ExplainableQueryAdapter ? QubuStreamingExplainableClient<TAdapter> : QubuStreamingClient<TAdapter> : TAdapter extends ExplainableQueryAdapter ? QubuExplainableClient<TAdapter> : QubuClient<TAdapter>;
|
|
554
|
+
/** The client available inside a transaction callback. */
|
|
555
|
+
type QubuTransaction = QubuClient<QueryAdapter>;
|
|
556
|
+
/** The streaming client available inside a streaming transaction callback. */
|
|
557
|
+
type QubuStreamingTransaction = QubuStreamingClient<StreamingQueryAdapter>;
|
|
558
|
+
/** A bound client whose adapter supports transaction-scoped execution. */
|
|
559
|
+
interface QubuTransactionalClient<TAdapter extends TransactionalQueryAdapter = TransactionalQueryAdapter, TTransactionAdapter extends QueryAdapter = QueryAdapter> extends QubuClient<TAdapter> {
|
|
560
|
+
/** Run several queries on one adapter-owned transaction. */
|
|
561
|
+
transaction<T>(callback: (transaction: QubuClientFor<TTransactionAdapter>) => Promise<T>, options?: TransactionOptions): Promise<T>;
|
|
562
|
+
}
|
|
563
|
+
/** A bound EXPLAIN client with an adapter-owned transaction callback. */
|
|
564
|
+
type QubuExplainableTransactionalClient<TAdapter extends ExplainableQueryAdapter & TransactionalQueryAdapter = ExplainableQueryAdapter & TransactionalQueryAdapter, TTransactionAdapter extends QueryAdapter = QueryAdapter> = QubuExplainableClient<TAdapter> & QubuTransactionalClient<TAdapter, TTransactionAdapter>;
|
|
565
|
+
/** A bound streaming and EXPLAIN client with an adapter-owned transaction. */
|
|
566
|
+
type QubuExplainableStreamingTransactionalClient<TAdapter extends ExplainableQueryAdapter & StreamingTransactionalQueryAdapter = ExplainableQueryAdapter & StreamingTransactionalQueryAdapter> = QubuStreamingExplainableClient<TAdapter> & QubuTransactionalClient<TAdapter, StreamingQueryAdapter>;
|
|
567
|
+
/** A bound streaming client whose transaction callback can also stream. */
|
|
568
|
+
interface QubuStreamingTransactionalClient<TAdapter extends StreamingTransactionalQueryAdapter = StreamingTransactionalQueryAdapter> extends QubuStreamingClient<TAdapter> {
|
|
569
|
+
/** Run a callback whose streams must be consumed or closed before it resolves. */
|
|
570
|
+
transaction<T>(callback: (transaction: QubuStreamingTransaction) => Promise<T>, options?: TransactionOptions): Promise<T>;
|
|
571
|
+
}
|
|
572
|
+
/** Bind an application-owned adapter once for repeated query execution. */
|
|
573
|
+
declare function qubu<TAdapter extends ExplainableQueryAdapter & StreamingTransactionalQueryAdapter>(adapter: TAdapter): QubuExplainableStreamingTransactionalClient<TAdapter>;
|
|
574
|
+
declare function qubu<TAdapter extends ExplainableQueryAdapter & TransactionalQueryAdapter & StreamingQueryAdapter>(adapter: TAdapter): QubuExplainableTransactionalClient<TAdapter> & QubuStreamingExplainableClient<TAdapter>;
|
|
575
|
+
declare function qubu<TAdapter extends ExplainableQueryAdapter & TransactionalQueryAdapter>(adapter: TAdapter): QubuExplainableTransactionalClient<TAdapter, TransactionAdapterOf<TAdapter>>;
|
|
576
|
+
declare function qubu<TAdapter extends ExplainableQueryAdapter & StreamingQueryAdapter>(adapter: TAdapter): QubuStreamingExplainableClient<TAdapter>;
|
|
577
|
+
declare function qubu<TAdapter extends ExplainableQueryAdapter>(adapter: TAdapter): QubuExplainableClient<TAdapter>;
|
|
578
|
+
declare function qubu<TAdapter extends StreamingTransactionalQueryAdapter>(adapter: TAdapter): QubuStreamingTransactionalClient<TAdapter>;
|
|
579
|
+
declare function qubu<TAdapter extends TransactionalQueryAdapter & StreamingQueryAdapter>(adapter: TAdapter): QubuTransactionalClient<TAdapter> & QubuStreamingClient<TAdapter>;
|
|
580
|
+
declare function qubu<TAdapter extends TransactionalQueryAdapter>(adapter: TAdapter): QubuTransactionalClient<TAdapter, TransactionAdapterOf<TAdapter>>;
|
|
581
|
+
declare function qubu<TAdapter extends StreamingQueryAdapter>(adapter: TAdapter): QubuStreamingClient<TAdapter>;
|
|
582
|
+
declare function qubu<TAdapter extends QueryAdapter>(adapter: TAdapter): QubuClient<TAdapter>;
|
|
583
|
+
interface DriverValueEncoder<TDriverValue = unknown> {
|
|
584
|
+
/** Convert one Qubu parameter into the driver's bindable representation. */
|
|
585
|
+
encode(value: unknown): TDriverValue;
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Render a typed query, pass it to an application adapter, and return the adapter's structured
|
|
589
|
+
* result unchanged.
|
|
590
|
+
*
|
|
591
|
+
* Driver errors are not caught or translated.
|
|
592
|
+
*/
|
|
593
|
+
declare function execute<TRow extends object>(query: QueryWithRow<TRow>, adapter: QueryAdapter, options?: ExecutionOptions): Promise<ExecutionResult<TRow>>;
|
|
594
|
+
declare function execute<TRow extends object>(adapter: QueryAdapter, query: QueryWithRow<TRow>, options?: ExecutionOptions): Promise<ExecutionResult<TRow>>;
|
|
595
|
+
/** Execute a query and return its decoded rows without mutation facts. */
|
|
596
|
+
declare function executeRows<TRow extends object>(query: QueryWithRow<TRow>, adapter: QueryAdapter, options?: ExecutionOptions): Promise<readonly TRow[]>;
|
|
597
|
+
declare function executeRows<TRow extends object>(adapter: QueryAdapter, query: QueryWithRow<TRow>, options?: ExecutionOptions): Promise<readonly TRow[]>;
|
|
598
|
+
/**
|
|
599
|
+
* Render a query as a dialect-specific EXPLAIN request and return the adapter-decoded vendor plan
|
|
600
|
+
* rows. EXPLAIN never calls QueryAdapter.execute.
|
|
601
|
+
*/
|
|
602
|
+
declare function explain<TQuery extends AnyQuery, TAdapter extends ExplainableQueryAdapter>(query: TQuery, adapter: TAdapter, options?: ExplainOptionsFor<TQuery>): Promise<ExplainResult<ExplainPlanRow<TAdapter>>>;
|
|
603
|
+
declare function explain<TQuery extends AnyQuery, TAdapter extends ExplainableQueryAdapter>(adapter: TAdapter, query: TQuery, options?: ExplainOptionsFor<TQuery>): Promise<ExplainResult<ExplainPlanRow<TAdapter>>>;
|
|
604
|
+
/**
|
|
605
|
+
* Render a SELECT or set-operation query and return the adapter-owned row stream. Mutations,
|
|
606
|
+
* including mutations with RETURNING, must use execute().
|
|
607
|
+
*/
|
|
608
|
+
declare function stream<TRow extends object>(query: StreamableQuery<TRow>, adapter: StreamingQueryAdapter, options?: ExecutionOptions): AsyncIterable<TRow>;
|
|
609
|
+
declare function stream<TRow extends object>(adapter: StreamingQueryAdapter, query: StreamableQuery<TRow>, options?: ExecutionOptions): AsyncIterable<TRow>;
|
|
610
|
+
//#endregion
|
|
367
611
|
//#region src/schema/metadata.d.ts
|
|
368
612
|
/** Dialect identities with first-party schema metadata adapters. */
|
|
369
|
-
type SchemaDialectName =
|
|
613
|
+
type SchemaDialectName = "postgresql" | "sqlite" | "mysql";
|
|
370
614
|
/** A dialect-owned extension attached to serializable schema metadata. */
|
|
371
615
|
interface SchemaDialectExtension<TDialect extends string = string> {
|
|
372
616
|
readonly dialect: TDialect;
|
|
@@ -385,7 +629,7 @@ interface SchemaObjectIdentity {
|
|
|
385
629
|
}
|
|
386
630
|
/** Structured diagnostics produced while resolving relational metadata. */
|
|
387
631
|
interface SchemaMetadataDiagnostic {
|
|
388
|
-
readonly code:
|
|
632
|
+
readonly code: "invalid-physical-name" | "duplicate-physical-name" | "dialect-mismatch" | "unsupported-dialect-option";
|
|
389
633
|
readonly message: string;
|
|
390
634
|
readonly path: readonly (string | number)[];
|
|
391
635
|
readonly relatedPaths?: readonly (readonly (string | number)[])[];
|
|
@@ -405,20 +649,19 @@ declare function freezeSchemaMetadata<T>(value: T): T;
|
|
|
405
649
|
/** Check the portable identifier subset used for generated metadata names. */
|
|
406
650
|
declare function isValidSchemaObjectName(name: string): boolean;
|
|
407
651
|
/**
|
|
408
|
-
* Attach a record key and resolved physical name without changing the
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
* traversals.
|
|
652
|
+
* Attach a record key and resolved physical name without changing the enumerable shape of legacy
|
|
653
|
+
* constraint/index values. The properties are still ordinary read-only runtime metadata and are
|
|
654
|
+
* available to snapshot traversals.
|
|
412
655
|
*/
|
|
413
656
|
declare function materializeSchemaObjectIdentity<TValue extends object>(value: TValue, id: string, physicalName?: string): TValue & SchemaObjectIdentity;
|
|
414
657
|
type NamedMetadataValue = object & {
|
|
415
658
|
readonly physicalName?: string;
|
|
416
659
|
};
|
|
417
660
|
/**
|
|
418
|
-
* Resolve and validate names for one metadata record. The caller decides
|
|
419
|
-
*
|
|
661
|
+
* Resolve and validate names for one metadata record. The caller decides whether constraint and
|
|
662
|
+
* index names share a database namespace.
|
|
420
663
|
*/
|
|
421
|
-
declare function materializeSchemaObjectRecord<TValue extends NamedMetadataValue>(record: Readonly<Record<string, TValue>>, kind:
|
|
664
|
+
declare function materializeSchemaObjectRecord<TValue extends NamedMetadataValue>(record: Readonly<Record<string, TValue>>, kind: "constraint" | "index"): Readonly<Record<string, TValue & SchemaObjectIdentity>>;
|
|
422
665
|
/** Return a diagnostic when a dialect extension is used by another adapter. */
|
|
423
666
|
declare function dialectMismatchDiagnostic(extension: SchemaDialectExtension, dialect: string, path: readonly (string | number)[]): SchemaMetadataDiagnostic | undefined;
|
|
424
667
|
/** Throw a structured error for one or more dialect capability findings. */
|
|
@@ -430,70 +673,70 @@ type SchemaLiteralValue = null | boolean | string | number | bigint;
|
|
|
430
673
|
/**
|
|
431
674
|
* Public input accepted by a column's `default` option.
|
|
432
675
|
*
|
|
433
|
-
* Primitive values are always literals. Branded schema expressions are
|
|
434
|
-
*
|
|
435
|
-
*
|
|
676
|
+
* Primitive values are always literals. Branded schema expressions are rendered as SQL expressions,
|
|
677
|
+
* and an external descriptor records a default whose definition belongs to another schema
|
|
678
|
+
* authority.
|
|
436
679
|
*/
|
|
437
680
|
type ColumnDefaultInput = SchemaLiteralValue | AnySchemaExpression | ExternalDefaultDescriptor;
|
|
438
681
|
/** A canonical, dialect-neutral literal node retained by default metadata. */
|
|
439
682
|
type CanonicalLiteral = {
|
|
440
|
-
readonly kind:
|
|
683
|
+
readonly kind: "null";
|
|
441
684
|
} | {
|
|
442
|
-
readonly kind:
|
|
685
|
+
readonly kind: "boolean";
|
|
443
686
|
readonly value: boolean;
|
|
444
687
|
} | {
|
|
445
|
-
readonly kind:
|
|
688
|
+
readonly kind: "string";
|
|
446
689
|
readonly value: string;
|
|
447
690
|
} | {
|
|
448
|
-
readonly kind:
|
|
691
|
+
readonly kind: "number";
|
|
449
692
|
readonly value: string;
|
|
450
693
|
} | {
|
|
451
|
-
readonly kind:
|
|
694
|
+
readonly kind: "bigint";
|
|
452
695
|
readonly value: string;
|
|
453
696
|
};
|
|
454
697
|
/** A default represented by a canonical literal node. */
|
|
455
698
|
interface LiteralDefaultDescriptor<TLiteral extends CanonicalLiteral = CanonicalLiteral> {
|
|
456
|
-
readonly kind:
|
|
699
|
+
readonly kind: "literal";
|
|
457
700
|
readonly value: TLiteral;
|
|
458
701
|
}
|
|
459
702
|
/** A default whose SQL is retained as a deterministic schema expression. */
|
|
460
703
|
interface ExpressionDefaultDescriptor<TExpression extends AnySchemaExpression = AnySchemaExpression> {
|
|
461
|
-
readonly kind:
|
|
704
|
+
readonly kind: "expression";
|
|
462
705
|
readonly expression: TExpression;
|
|
463
706
|
}
|
|
464
707
|
/** A default supplied by the database or another external schema authority. */
|
|
465
708
|
interface ExternalDefaultDescriptor {
|
|
466
|
-
readonly kind:
|
|
709
|
+
readonly kind: "external";
|
|
467
710
|
}
|
|
468
711
|
/** Complete default metadata carried by a column definition. */
|
|
469
712
|
type ColumnDefault = LiteralDefaultDescriptor | ExpressionDefaultDescriptor | ExternalDefaultDescriptor;
|
|
470
713
|
/** Alias used by snapshot and schema tooling consumers. */
|
|
471
714
|
type DefaultDescriptor = ColumnDefault;
|
|
472
715
|
/** Storage mode for a generated-column expression. */
|
|
473
|
-
type GeneratedColumnMode =
|
|
716
|
+
type GeneratedColumnMode = "stored" | "virtual";
|
|
474
717
|
/** A generated column with an expression that can be rendered later. */
|
|
475
718
|
interface ExpressionGeneratedColumnDescriptor<TExpression extends AnySchemaExpression = AnySchemaExpression> {
|
|
476
|
-
readonly kind:
|
|
719
|
+
readonly kind: "expression";
|
|
477
720
|
readonly expression: TExpression;
|
|
478
721
|
readonly mode: GeneratedColumnMode;
|
|
479
722
|
}
|
|
480
723
|
/** A generated-column behavior known to exist but owned externally. */
|
|
481
724
|
interface ExternalGeneratedColumnDescriptor {
|
|
482
|
-
readonly kind:
|
|
725
|
+
readonly kind: "external";
|
|
483
726
|
}
|
|
484
727
|
/** Complete generated-column metadata, separate from identity metadata. */
|
|
485
728
|
type GeneratedColumnDescriptor = ExpressionGeneratedColumnDescriptor | ExternalGeneratedColumnDescriptor;
|
|
486
729
|
/** Alias used by snapshot and schema tooling consumers. */
|
|
487
730
|
type GeneratedDescriptor = GeneratedColumnDescriptor;
|
|
488
731
|
/** Identity generation policy. Identity is not an ordinary SQL expression. */
|
|
489
|
-
type IdentityGeneration =
|
|
732
|
+
type IdentityGeneration = "always" | "by-default";
|
|
490
733
|
/** SQLite's opt-in AUTOINCREMENT behavior for an INTEGER rowid alias. */
|
|
491
|
-
interface SqliteIdentityExtension extends SchemaDialectExtension<
|
|
734
|
+
interface SqliteIdentityExtension extends SchemaDialectExtension<"sqlite"> {
|
|
492
735
|
/** Preserve deleted rowids instead of allowing SQLite to reuse them. */
|
|
493
736
|
readonly autoIncrement?: boolean;
|
|
494
737
|
}
|
|
495
738
|
/** MySQL's column-level AUTO_INCREMENT identity detail. */
|
|
496
|
-
interface MysqlIdentityExtension extends SchemaDialectExtension<
|
|
739
|
+
interface MysqlIdentityExtension extends SchemaDialectExtension<"mysql"> {
|
|
497
740
|
/** Emit MySQL's AUTO_INCREMENT behavior for this identity column. */
|
|
498
741
|
readonly autoIncrement?: boolean;
|
|
499
742
|
}
|
|
@@ -501,13 +744,13 @@ interface MysqlIdentityExtension extends SchemaDialectExtension<'mysql'> {
|
|
|
501
744
|
type IdentityDialectExtension = SqliteIdentityExtension | MysqlIdentityExtension | (SchemaDialectExtension<string> & Readonly<Record<string, unknown>>);
|
|
502
745
|
/** Complete identity metadata for a database-generated column value. */
|
|
503
746
|
interface IdentityDescriptor {
|
|
504
|
-
readonly kind:
|
|
747
|
+
readonly kind: "identity";
|
|
505
748
|
readonly generation: IdentityGeneration;
|
|
506
749
|
/** Optional dialect-owned identity semantics such as SQLite AUTOINCREMENT. */
|
|
507
750
|
readonly dialect?: IdentityDialectExtension;
|
|
508
751
|
}
|
|
509
752
|
/** Structured failures raised while resolving column behavior metadata. */
|
|
510
|
-
type ColumnBehaviorErrorCode =
|
|
753
|
+
type ColumnBehaviorErrorCode = "invalid-default" | "invalid-generated-column" | "invalid-identity" | "invalid-on-update" | "default-flag-conflict" | "generated-flag-conflict" | "default-generated-conflict" | "identity-generated-conflict";
|
|
511
754
|
/** A column behavior error with a stable code and optional property path. */
|
|
512
755
|
declare class ColumnBehaviorError extends TypeError {
|
|
513
756
|
readonly code: ColumnBehaviorErrorCode;
|
|
@@ -549,16 +792,16 @@ declare function resolveColumnBehavior(options: {
|
|
|
549
792
|
//#endregion
|
|
550
793
|
//#region src/schema/column.d.ts
|
|
551
794
|
/** Portable physical storage spellings understood by every schema dialect. */
|
|
552
|
-
type PortableStorageType =
|
|
795
|
+
type PortableStorageType = "integer" | "numeric" | "text" | "boolean" | "date" | "timestamp" | "uuid" | "json" | "bigint" | "binary";
|
|
553
796
|
/** A dialect-neutral physical storage descriptor. */
|
|
554
797
|
interface PortableColumnStorage<TType extends PortableStorageType = PortableStorageType> {
|
|
555
|
-
readonly kind:
|
|
798
|
+
readonly kind: "portable";
|
|
556
799
|
/** Stable physical storage category, independent of the SQL domain. */
|
|
557
800
|
readonly type: TType;
|
|
558
801
|
}
|
|
559
802
|
/** A physical storage declaration owned by one SQL dialect. */
|
|
560
803
|
interface NativeColumnStorage<TDialect extends string = string, TDeclaration extends string = string> {
|
|
561
|
-
readonly kind:
|
|
804
|
+
readonly kind: "native";
|
|
562
805
|
/** Adapter name that owns the declaration. */
|
|
563
806
|
readonly dialect: TDialect;
|
|
564
807
|
/** Exact dialect declaration, preserved without normalization. */
|
|
@@ -605,7 +848,7 @@ type ColumnStorageDialectOf<T> = Extract<ColumnStorageOf<T>, NativeColumnStorage
|
|
|
605
848
|
/** Extract the exact native declaration from a column definition. */
|
|
606
849
|
type ColumnStorageDeclarationOf<T> = Extract<ColumnStorageOf<T>, NativeColumnStorage> extends NativeColumnStorage<any, infer TDeclaration> ? TDeclaration : never;
|
|
607
850
|
/** Extract the descriptor discriminant from a column definition. */
|
|
608
|
-
type ColumnStorageKindOf<T> = Extract<ColumnStorageOf<T>, ColumnStorage>[
|
|
851
|
+
type ColumnStorageKindOf<T> = Extract<ColumnStorageOf<T>, ColumnStorage>["kind"];
|
|
609
852
|
/** Short alias for {@link ColumnStorageOf}. */
|
|
610
853
|
type StorageOf<T> = ColumnStorageOf<T>;
|
|
611
854
|
/** Alias matching the existing `ColumnSqlType` extraction naming. */
|
|
@@ -635,12 +878,12 @@ interface ColumnOptions {
|
|
|
635
878
|
/** Override adapter decoding for values selected from this column. */
|
|
636
879
|
readonly decode?: ResultDecoder;
|
|
637
880
|
/**
|
|
638
|
-
* Raw SQL target that makes a custom definition reusable with cast().
|
|
639
|
-
*
|
|
881
|
+
* Raw SQL target that makes a custom definition reusable with cast(). The value is emitted
|
|
882
|
+
* verbatim and must come from trusted source code.
|
|
640
883
|
*/
|
|
641
884
|
readonly castType?: string;
|
|
642
885
|
}
|
|
643
|
-
type BuiltInColumnOptions = Omit<ColumnOptions,
|
|
886
|
+
type BuiltInColumnOptions = Omit<ColumnOptions, "castType" | "storage"> & {
|
|
644
887
|
readonly castType?: never;
|
|
645
888
|
readonly storage?: never;
|
|
646
889
|
};
|
|
@@ -672,20 +915,20 @@ interface ColumnDefinitionConfig {
|
|
|
672
915
|
readonly onUpdate?: AnySchemaExpression;
|
|
673
916
|
}
|
|
674
917
|
type ConfigValue<TConfig, TKey extends PropertyKey, TFallback> = TKey extends keyof TConfig ? TConfig[TKey] : TFallback;
|
|
675
|
-
type ColumnConfigOutput<TConfig> = ConfigValue<TConfig,
|
|
918
|
+
type ColumnConfigOutput<TConfig> = ConfigValue<TConfig, "output", unknown>;
|
|
676
919
|
type ConfigBoolean<TConfig, TKey extends PropertyKey> = Extract<ConfigValue<TConfig, TKey, false>, boolean> extends (infer TValue) ? [TValue] extends [never] ? false : TValue : false;
|
|
677
|
-
type ColumnConfigNullable<TConfig> = ConfigBoolean<TConfig,
|
|
678
|
-
type ColumnConfigInsert<TConfig> = ConfigValue<TConfig,
|
|
679
|
-
type ColumnConfigUpdate<TConfig> = ConfigValue<TConfig,
|
|
680
|
-
type ColumnConfigHasDefault<TConfig> = ConfigBoolean<TConfig,
|
|
681
|
-
type ColumnConfigGenerated<TConfig> = ConfigBoolean<TConfig,
|
|
682
|
-
type ColumnConfigSqlType<TConfig> = Extract<ConfigValue<TConfig,
|
|
683
|
-
type ColumnConfigStorage<TConfig> = ConfigValue<TConfig,
|
|
684
|
-
type ColumnConfigDefault<TConfig> = ConfigValue<TConfig,
|
|
685
|
-
type ColumnConfigGeneratedColumn<TConfig> = ConfigValue<TConfig,
|
|
686
|
-
type ColumnConfigIdentity<TConfig> = ConfigValue<TConfig,
|
|
687
|
-
type ColumnConfigOnUpdate<TConfig> = ConfigValue<TConfig,
|
|
688
|
-
type SetColumnOutput<TConfig, TOutput> = Omit<TConfig,
|
|
920
|
+
type ColumnConfigNullable<TConfig> = ConfigBoolean<TConfig, "nullable">;
|
|
921
|
+
type ColumnConfigInsert<TConfig> = ConfigValue<TConfig, "insert", ColumnConfigOutput<TConfig>>;
|
|
922
|
+
type ColumnConfigUpdate<TConfig> = ConfigValue<TConfig, "update", ColumnConfigInsert<TConfig>>;
|
|
923
|
+
type ColumnConfigHasDefault<TConfig> = ConfigBoolean<TConfig, "hasDefault">;
|
|
924
|
+
type ColumnConfigGenerated<TConfig> = ConfigBoolean<TConfig, "generated">;
|
|
925
|
+
type ColumnConfigSqlType<TConfig> = Extract<ConfigValue<TConfig, "sqlType", SqlUnknown>, AnySqlType> extends (infer TValue) ? [TValue] extends [never] ? SqlUnknown : TValue : SqlUnknown;
|
|
926
|
+
type ColumnConfigStorage<TConfig> = ConfigValue<TConfig, "storage", undefined>;
|
|
927
|
+
type ColumnConfigDefault<TConfig> = ConfigValue<TConfig, "default", undefined>;
|
|
928
|
+
type ColumnConfigGeneratedColumn<TConfig> = ConfigValue<TConfig, "generatedColumn", undefined>;
|
|
929
|
+
type ColumnConfigIdentity<TConfig> = ConfigValue<TConfig, "identity", undefined>;
|
|
930
|
+
type ColumnConfigOnUpdate<TConfig> = ConfigValue<TConfig, "onUpdate", undefined>;
|
|
931
|
+
type SetColumnOutput<TConfig, TOutput> = Omit<TConfig, "output" | "insert" | "update"> & {
|
|
689
932
|
readonly output: TOutput;
|
|
690
933
|
readonly insert: SameType<ColumnConfigInsert<TConfig>, ColumnConfigOutput<TConfig>> extends true ? TOutput : ColumnConfigInsert<TConfig>;
|
|
691
934
|
readonly update: SameType<ColumnConfigUpdate<TConfig>, ColumnConfigOutput<TConfig>> extends true ? TOutput : ColumnConfigUpdate<TConfig>;
|
|
@@ -693,7 +936,7 @@ type SetColumnOutput<TConfig, TOutput> = Omit<TConfig, 'output' | 'insert' | 'up
|
|
|
693
936
|
interface ColumnDefinition<TConfig extends ColumnDefinitionConfig = {}> {
|
|
694
937
|
/** @internal Type-level configuration retained for inference. */
|
|
695
938
|
readonly __config?: TConfig;
|
|
696
|
-
readonly definitionKind:
|
|
939
|
+
readonly definitionKind: "column";
|
|
697
940
|
readonly nullable: ColumnConfigNullable<TConfig>;
|
|
698
941
|
readonly hasDefault: ColumnConfigHasDefault<TConfig>;
|
|
699
942
|
readonly generated: ColumnConfigGenerated<TConfig>;
|
|
@@ -716,11 +959,11 @@ interface ColumnDefinition<TConfig extends ColumnDefinitionConfig = {}> {
|
|
|
716
959
|
readonly __insert?: ColumnConfigInsert<TConfig>;
|
|
717
960
|
readonly __update?: ColumnConfigUpdate<TConfig>;
|
|
718
961
|
/**
|
|
719
|
-
* Narrow the column's application type without changing its runtime
|
|
720
|
-
* definition.
|
|
962
|
+
* Narrow the column's application type without changing its runtime definition.
|
|
721
963
|
*
|
|
722
|
-
* @remarks
|
|
723
|
-
* not validate values or add a
|
|
964
|
+
* @remarks
|
|
965
|
+
* Distinct insert or update types are preserved. This method does not validate values or add a
|
|
966
|
+
* database constraint.
|
|
724
967
|
*/
|
|
725
968
|
readonly $type: <const TType extends ColumnConfigOutput<TConfig>>() => ColumnDefinition<SetColumnOutput<TConfig, TType>> & (this extends {
|
|
726
969
|
readonly castTarget: infer TCastTarget extends CastTarget;
|
|
@@ -731,26 +974,26 @@ interface ColumnDefinition<TConfig extends ColumnDefinitionConfig = {}> {
|
|
|
731
974
|
}
|
|
732
975
|
type Flag<T extends boolean | undefined> = T extends true ? true : false;
|
|
733
976
|
type HasExplicitOption<TOptions, TKey extends PropertyKey> = TKey extends keyof TOptions ? {} extends Pick<TOptions, TKey> ? false : true : false;
|
|
734
|
-
type ColumnHasDefaultOption<TOptions extends ColumnOptions> = HasExplicitOption<TOptions,
|
|
977
|
+
type ColumnHasDefaultOption<TOptions extends ColumnOptions> = HasExplicitOption<TOptions, "default"> extends true ? true : Flag<TOptions["hasDefault"]>;
|
|
735
978
|
type ColumnIsGeneratedOption<TOptions extends ColumnOptions> = TOptions extends {
|
|
736
979
|
readonly generatedColumn: GeneratedColumnDescriptor;
|
|
737
980
|
} ? true : TOptions extends {
|
|
738
981
|
readonly identity: IdentityDescriptor;
|
|
739
|
-
} ? true : Flag<TOptions[
|
|
740
|
-
type ColumnDefaultOption<TOptions extends ColumnOptions> = HasExplicitOption<TOptions,
|
|
982
|
+
} ? true : Flag<TOptions["generated"]>;
|
|
983
|
+
type ColumnDefaultOption<TOptions extends ColumnOptions> = HasExplicitOption<TOptions, "default"> extends true ? TOptions extends {
|
|
741
984
|
readonly default: infer TDefault;
|
|
742
|
-
} ? TDefault extends AnySchemaExpression ? ExpressionDefaultDescriptor<TDefault> : TDefault extends ExternalDefaultDescriptor ? TDefault : TDefault extends SchemaLiteralValue ? LiteralDefaultDescriptor : never : never : TOptions[
|
|
985
|
+
} ? TDefault extends AnySchemaExpression ? ExpressionDefaultDescriptor<TDefault> : TDefault extends ExternalDefaultDescriptor ? TDefault : TDefault extends SchemaLiteralValue ? LiteralDefaultDescriptor : never : never : TOptions["hasDefault"] extends true ? ExternalDefaultDescriptor : undefined;
|
|
743
986
|
type ColumnGeneratedOption<TOptions extends ColumnOptions> = TOptions extends {
|
|
744
987
|
readonly generatedColumn: infer TGenerated extends GeneratedColumnDescriptor;
|
|
745
|
-
} ? TGenerated : TOptions[
|
|
988
|
+
} ? TGenerated : TOptions["generated"] extends true ? ExternalGeneratedColumnDescriptor : undefined;
|
|
746
989
|
type ColumnIdentityOption<TOptions extends ColumnOptions> = TOptions extends {
|
|
747
990
|
readonly identity: infer TIdentity extends IdentityDescriptor;
|
|
748
991
|
} ? TIdentity : undefined;
|
|
749
992
|
type ColumnOnUpdateOption<TOptions extends ColumnOptions> = TOptions extends {
|
|
750
993
|
readonly onUpdate: infer TOnUpdate extends AnySchemaExpression;
|
|
751
994
|
} ? TOnUpdate : undefined;
|
|
752
|
-
type IsAny
|
|
753
|
-
type SameType<TLeft, TRight> = IsAny
|
|
995
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
996
|
+
type SameType<TLeft, TRight> = IsAny<TLeft> extends true ? IsAny<TRight> : IsAny<TRight> extends true ? false : [TLeft] extends [TRight] ? [TRight] extends [TLeft] ? true : false : false;
|
|
754
997
|
type Simplify$1<T> = { readonly [TKey in keyof T]: T[TKey]; };
|
|
755
998
|
type ColumnValueConfig<TOutput, TInsert, TUpdate> = {
|
|
756
999
|
readonly output: TOutput;
|
|
@@ -761,7 +1004,7 @@ type ColumnValueConfig<TOutput, TInsert, TUpdate> = {
|
|
|
761
1004
|
});
|
|
762
1005
|
type TrueConfig<TKey extends PropertyKey, TValue> = TValue extends true ? { readonly [TField in TKey]: true; } : {};
|
|
763
1006
|
type DefinedConfig<TKey extends PropertyKey, TValue> = [TValue] extends [undefined] ? {} : { readonly [TField in TKey]: TValue; };
|
|
764
|
-
type ColumnOptionConfig<TOptions extends ColumnOptions> = Simplify$1<TrueConfig<
|
|
1007
|
+
type ColumnOptionConfig<TOptions extends ColumnOptions> = Simplify$1<TrueConfig<"nullable", Flag<TOptions["nullable"]>> & TrueConfig<"hasDefault", ColumnHasDefaultOption<TOptions>> & TrueConfig<"generated", ColumnIsGeneratedOption<TOptions>> & DefinedConfig<"default", ColumnDefaultOption<TOptions>> & DefinedConfig<"generatedColumn", ColumnGeneratedOption<TOptions>> & DefinedConfig<"identity", ColumnIdentityOption<TOptions>> & DefinedConfig<"onUpdate", ColumnOnUpdateOption<TOptions>> & (TOptions extends {
|
|
765
1008
|
readonly storage: infer TStorage extends ColumnStorage;
|
|
766
1009
|
} ? {
|
|
767
1010
|
readonly storage: TStorage;
|
|
@@ -833,7 +1076,7 @@ type AnyColumnDefinition = ColumnDefinition<any>;
|
|
|
833
1076
|
type NamedCastColumn<TDefinition extends AnyColumnDefinition> = TDefinition & {
|
|
834
1077
|
readonly castTarget: NamedCastTarget;
|
|
835
1078
|
};
|
|
836
|
-
declare function column<TOutput = unknown, TInsert = TOutput, TUpdate = TInsert, TSqlType extends AnySqlType = SqlUnknown, const TStorage extends ColumnStorage = ColumnStorage, const TOptions extends Omit<ColumnOptions,
|
|
1079
|
+
declare function column<TOutput = unknown, TInsert = TOutput, TUpdate = TInsert, TSqlType extends AnySqlType = SqlUnknown, const TStorage extends ColumnStorage = ColumnStorage, const TOptions extends Omit<ColumnOptions, "storage"> = Omit<ColumnOptions, "storage">>(options: TOptions & {
|
|
837
1080
|
readonly storage: TStorage;
|
|
838
1081
|
}): ColumnFromOptions<TOutput, TInsert, TUpdate, TOptions & {
|
|
839
1082
|
readonly storage: TStorage;
|
|
@@ -929,7 +1172,7 @@ declare function columnResultValue(definition: {
|
|
|
929
1172
|
readonly storage?: ColumnStorage;
|
|
930
1173
|
readonly resultDecoder?: ResultDecoder;
|
|
931
1174
|
}): ResultValueMetadata | undefined;
|
|
932
|
-
type NativeColumnOptions = Omit<ColumnOptions,
|
|
1175
|
+
type NativeColumnOptions = Omit<ColumnOptions, "storage"> & {
|
|
933
1176
|
readonly storage?: never;
|
|
934
1177
|
};
|
|
935
1178
|
type NativeColumnFromOptions<TOutput, TInsert, TUpdate, TOptions extends NativeColumnOptions, TSqlType extends AnySqlType, TDialect extends string, TDeclaration extends string> = ColumnDefinition<Simplify$1<ColumnValueConfig<TOutput, TInsert, TUpdate> & {
|
|
@@ -948,527 +1191,30 @@ declare function nativeColumn<const TDialect extends string, const TDeclaration
|
|
|
948
1191
|
declare function nullable<TConfig extends ColumnDefinitionConfig>(definition: ColumnDefinition<TConfig>): ColumnDefinition<Simplify$1<Omit<TConfig, "nullable"> & {
|
|
949
1192
|
readonly nullable: true;
|
|
950
1193
|
}>>;
|
|
951
|
-
declare function integer<const TOptions extends BuiltInColumnOptions = {}>(options?: TOptions): BuiltInColumnDefinition<number, SqlInteger,
|
|
952
|
-
declare function numeric<const TOptions extends BuiltInColumnOptions = {}>(options?: TOptions): BuiltInColumnDefinition<number, SqlDecimal,
|
|
953
|
-
declare function text<const TOptions extends BuiltInColumnOptions = {}>(options?: TOptions): BuiltInColumnDefinition<string, SqlText,
|
|
954
|
-
declare function boolean<const TOptions extends BuiltInColumnOptions = {}>(options?: TOptions): BuiltInColumnDefinition<boolean, SqlBoolean,
|
|
955
|
-
declare function date<const TOptions extends BuiltInColumnOptions = {}>(options?: TOptions): BuiltInColumnDefinition<Date, SqlDate,
|
|
956
|
-
declare function timestamp<const TOptions extends BuiltInColumnOptions = {}>(options?: TOptions): BuiltInColumnDefinition<Date, SqlTimestamp,
|
|
957
|
-
declare function uuid<const TOptions extends BuiltInColumnOptions = {}>(options?: TOptions): BuiltInColumnDefinition<string, SqlUuid,
|
|
958
|
-
declare function json<TOutput = unknown, const TOptions extends BuiltInColumnOptions = {}>(options?: TOptions): BuiltInColumnDefinition<TOutput, SqlJson<TOutput>,
|
|
959
|
-
declare function bigint<const TOptions extends BuiltInColumnOptions = {}>(options?: TOptions): BuiltInColumnDefinition<bigint, SqlBigInt,
|
|
960
|
-
declare function binary<const TOptions extends BuiltInColumnOptions = {}>(options?: TOptions): BuiltInColumnDefinition<Uint8Array, SqlBinary,
|
|
1194
|
+
declare function integer<const TOptions extends BuiltInColumnOptions = {}>(options?: TOptions): BuiltInColumnDefinition<number, SqlInteger, "integer", "integer", TOptions>;
|
|
1195
|
+
declare function numeric<const TOptions extends BuiltInColumnOptions = {}>(options?: TOptions): BuiltInColumnDefinition<number, SqlDecimal, "numeric", "decimal", TOptions>;
|
|
1196
|
+
declare function text<const TOptions extends BuiltInColumnOptions = {}>(options?: TOptions): BuiltInColumnDefinition<string, SqlText, "text", "text", TOptions>;
|
|
1197
|
+
declare function boolean<const TOptions extends BuiltInColumnOptions = {}>(options?: TOptions): BuiltInColumnDefinition<boolean, SqlBoolean, "boolean", "boolean", TOptions>;
|
|
1198
|
+
declare function date<const TOptions extends BuiltInColumnOptions = {}>(options?: TOptions): BuiltInColumnDefinition<Date, SqlDate, "date", "date", TOptions>;
|
|
1199
|
+
declare function timestamp<const TOptions extends BuiltInColumnOptions = {}>(options?: TOptions): BuiltInColumnDefinition<Date, SqlTimestamp, "timestamp", "timestamp", TOptions>;
|
|
1200
|
+
declare function uuid<const TOptions extends BuiltInColumnOptions = {}>(options?: TOptions): BuiltInColumnDefinition<string, SqlUuid, "uuid", "uuid", TOptions>;
|
|
1201
|
+
declare function json<TOutput = unknown, const TOptions extends BuiltInColumnOptions = {}>(options?: TOptions): BuiltInColumnDefinition<TOutput, SqlJson<TOutput>, "json", "json", TOptions>;
|
|
1202
|
+
declare function bigint<const TOptions extends BuiltInColumnOptions = {}>(options?: TOptions): BuiltInColumnDefinition<bigint, SqlBigInt, "bigint", "bigint", TOptions>;
|
|
1203
|
+
declare function binary<const TOptions extends BuiltInColumnOptions = {}>(options?: TOptions): BuiltInColumnDefinition<Uint8Array, SqlBinary, "binary", "binary", TOptions>;
|
|
961
1204
|
//#endregion
|
|
962
|
-
//#region src/
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
readonly [declaredColumnNullability]: TNullable;
|
|
1205
|
+
//#region src/expressions/cast.d.ts
|
|
1206
|
+
type CastDefinition = ColumnDefinition<any> & {
|
|
1207
|
+
readonly nullable: false;
|
|
1208
|
+
readonly castTarget: CastTarget;
|
|
967
1209
|
};
|
|
968
|
-
/** @internal */
|
|
969
|
-
type DeclaredColumnNullabilityOf<TColumn> = TColumn extends DeclaredColumnNullability<infer TNullable> ? TNullable : never;
|
|
970
|
-
//#endregion
|
|
971
|
-
//#region src/schema/constraints.d.ts
|
|
972
|
-
declare const fieldConstraint: unique symbol;
|
|
973
|
-
/** Application and SQL facts that a reusable source field may require. */
|
|
974
|
-
interface FieldLikeOptions {
|
|
975
|
-
readonly output?: unknown;
|
|
976
|
-
readonly sqlType?: object;
|
|
977
|
-
readonly nullable?: boolean;
|
|
978
|
-
}
|
|
979
1210
|
/**
|
|
980
|
-
*
|
|
981
|
-
*
|
|
982
|
-
* selected value.
|
|
983
|
-
*/
|
|
984
|
-
interface FieldLike<TOptions extends FieldLikeOptions = FieldLikeOptions> {
|
|
985
|
-
readonly [fieldConstraint]: TOptions;
|
|
986
|
-
}
|
|
987
|
-
type FieldOptions<T> = T extends FieldLike<infer TOptions> ? TOptions : never;
|
|
988
|
-
type RequiredOutput<T> = T extends FieldLike<any> ? FieldOptions<T> extends {
|
|
989
|
-
readonly output: infer TOutput;
|
|
990
|
-
} ? FieldOptions<T> extends {
|
|
991
|
-
readonly nullable: false;
|
|
992
|
-
} ? NonNullable<TOutput> : TOutput : FieldOptions<T> extends {
|
|
993
|
-
readonly nullable: false;
|
|
994
|
-
} ? {} : unknown : T;
|
|
995
|
-
type RequiredSqlType<T> = T extends FieldLike<any> ? FieldOptions<T> extends {
|
|
996
|
-
readonly sqlType: infer TSqlType;
|
|
997
|
-
} ? (AnySqlType & TSqlType) | SqlUnknown : AnySqlType : AnySqlType;
|
|
998
|
-
type RequiredColumn<TField extends string, TRequirement, TIdentity> = ColumnReference<TField, ResultMeta<RequiredOutput<TRequirement>, TIdentity, RequiredSqlType<TRequirement>> | RequiresSourceMeta<TIdentity> | ExpressionMeta<ColumnDependency<TIdentity, TField>>>;
|
|
999
|
-
type RequiredColumns<TShape extends object, TIdentity> = { readonly [K in keyof TShape]-?: K extends string ? RequiredColumn<K, TShape[K], TIdentity> : never; };
|
|
1000
|
-
/**
|
|
1001
|
-
* A source containing at least the requested application and SQL fields.
|
|
1002
|
-
* Additional fields and the concrete source identity are preserved by generic
|
|
1003
|
-
* functions that accept this lower-bound constraint.
|
|
1004
|
-
*/
|
|
1005
|
-
interface SourceLike<TShape extends object> extends Fragment<any> {
|
|
1006
|
-
readonly sourceKind: SourceKind;
|
|
1007
|
-
readonly [sourceIdentity]: unknown;
|
|
1008
|
-
readonly reference: Fragment<never>;
|
|
1009
|
-
readonly columns: RequiredColumns<TShape, this[typeof sourceIdentity]>;
|
|
1010
|
-
}
|
|
1011
|
-
/** The physical-table form of the lower-bound {@link SourceLike} constraint. */
|
|
1012
|
-
interface TableLike<TShape extends object> extends SourceLike<TShape> {
|
|
1013
|
-
readonly tableName: string;
|
|
1014
|
-
readonly definitions: object;
|
|
1015
|
-
readonly sqlNames: Readonly<Record<string, string>>;
|
|
1016
|
-
}
|
|
1017
|
-
/** Standard SQL referential action retained on a foreign-key constraint. */
|
|
1018
|
-
type ReferentialAction = 'no-action' | 'restrict' | 'cascade' | 'set-null' | 'set-default';
|
|
1019
|
-
/** Standard SQL match mode for a composite foreign key. */
|
|
1020
|
-
type ForeignKeyMatch = 'simple' | 'full' | 'partial';
|
|
1021
|
-
/** Deferrability timing for a foreign-key or key constraint. */
|
|
1022
|
-
type ConstraintTiming = 'immediate' | 'deferred';
|
|
1023
|
-
/** PostgreSQL-only constraint options retained for a schema adapter. */
|
|
1024
|
-
interface PostgresConstraintExtension extends SchemaDialectExtension<'postgresql'> {
|
|
1025
|
-
/** PostgreSQL `NOT VALID` validation state for a constraint. */
|
|
1026
|
-
readonly notValid?: boolean;
|
|
1027
|
-
}
|
|
1028
|
-
/** SQLite-only table-constraint options. */
|
|
1029
|
-
interface SqliteConstraintExtension extends SchemaDialectExtension<'sqlite'> {
|
|
1030
|
-
/** SQLite conflict policy attached to a table constraint. */
|
|
1031
|
-
readonly onConflict?: 'rollback' | 'abort' | 'fail' | 'ignore' | 'replace';
|
|
1032
|
-
}
|
|
1033
|
-
/** MySQL-only constraint options. */
|
|
1034
|
-
interface MysqlConstraintExtension extends SchemaDialectExtension<'mysql'> {
|
|
1035
|
-
/** MySQL 8 constraint enforcement state. */
|
|
1036
|
-
readonly enforced?: boolean;
|
|
1037
|
-
}
|
|
1038
|
-
/** First-party and user-defined dialect extensions for constraints. */
|
|
1039
|
-
type ConstraintDialectExtension = PostgresConstraintExtension | SqliteConstraintExtension | MysqlConstraintExtension | (SchemaDialectExtension<string> & Readonly<Record<string, unknown>>);
|
|
1040
|
-
/** Shared physical-name and dialect-extension options for constraints. */
|
|
1041
|
-
interface ConstraintOptions<TExtension extends ConstraintDialectExtension | undefined = ConstraintDialectExtension | undefined> extends SchemaObjectNameOptions {
|
|
1042
|
-
/** Engine-specific metadata owned by a future schema adapter. */
|
|
1043
|
-
readonly dialect?: TExtension;
|
|
1044
|
-
}
|
|
1045
|
-
/** Options for primary-key and candidate-key declarations. */
|
|
1046
|
-
interface KeyConstraintOptions<TExtension extends ConstraintDialectExtension | undefined = ConstraintDialectExtension | undefined> extends ConstraintOptions<TExtension> {
|
|
1047
|
-
/** Whether the key can be deferred by a supporting dialect. */
|
|
1048
|
-
readonly deferrable?: boolean;
|
|
1049
|
-
/** Initial enforcement timing for a deferrable key. */
|
|
1050
|
-
readonly initially?: ConstraintTiming;
|
|
1051
|
-
}
|
|
1052
|
-
/** Options for a database unique constraint, including nullable columns. */
|
|
1053
|
-
interface UniqueConstraintOptions<TExtension extends ConstraintDialectExtension | undefined = ConstraintDialectExtension | undefined> extends ConstraintOptions<TExtension> {
|
|
1054
|
-
/**
|
|
1055
|
-
* SQL NULL comparison semantics. `distinct` is the common default in which
|
|
1056
|
-
* multiple NULL values do not conflict; `not-distinct` permits at most one.
|
|
1057
|
-
*/
|
|
1058
|
-
readonly nulls?: UniqueNullSemantics;
|
|
1059
|
-
/** Whether the constraint can be deferred by a supporting dialect. */
|
|
1060
|
-
readonly deferrable?: boolean;
|
|
1061
|
-
/** Initial enforcement timing for a deferrable constraint. */
|
|
1062
|
-
readonly initially?: ConstraintTiming;
|
|
1063
|
-
}
|
|
1064
|
-
/** Explicit NULL behavior for a database uniqueness rule. */
|
|
1065
|
-
type UniqueNullSemantics = 'distinct' | 'not-distinct';
|
|
1066
|
-
/** Options for a table check constraint. */
|
|
1067
|
-
interface CheckConstraintOptions<TExtension extends ConstraintDialectExtension | undefined = ConstraintDialectExtension | undefined> extends ConstraintOptions<TExtension> {
|
|
1068
|
-
/** Whether the check can be deferred by a supporting dialect. */
|
|
1069
|
-
readonly deferrable?: boolean;
|
|
1070
|
-
/** Initial enforcement timing for a deferrable check. */
|
|
1071
|
-
readonly initially?: ConstraintTiming;
|
|
1072
|
-
}
|
|
1073
|
-
/** Dialect tag and parameter-free SQL needed to reconstruct a catalog check. */
|
|
1074
|
-
interface CatalogCheckSql<TDialect extends SchemaDialectName = SchemaDialectName> {
|
|
1075
|
-
/** Catalog dialect that supplied the check expression. */
|
|
1076
|
-
readonly dialect: TDialect;
|
|
1077
|
-
/** Opaque SQL text recovered from the catalog. */
|
|
1078
|
-
readonly sql: string;
|
|
1079
|
-
}
|
|
1080
|
-
/** Options for a foreign-key declaration. */
|
|
1081
|
-
interface ForeignKeyOptions<TExtension extends ConstraintDialectExtension | undefined = ConstraintDialectExtension | undefined> extends ConstraintOptions<TExtension> {
|
|
1082
|
-
readonly onUpdate?: ReferentialAction;
|
|
1083
|
-
readonly onDelete?: ReferentialAction;
|
|
1084
|
-
readonly match?: ForeignKeyMatch;
|
|
1085
|
-
readonly deferrable?: boolean;
|
|
1086
|
-
readonly initially?: ConstraintTiming;
|
|
1087
|
-
}
|
|
1088
|
-
/** A schema constraint whose columns form a relational key. */
|
|
1089
|
-
interface KeyConstraint<TKind extends 'primary-key' | 'unique' = 'primary-key' | 'unique', TColumns extends readonly ColumnReference<string, any>[] = readonly ColumnReference<string, any>[]> extends SchemaObjectIdentity {
|
|
1090
|
-
readonly kind: TKind;
|
|
1091
|
-
readonly columns: TColumns;
|
|
1092
|
-
readonly physicalName?: string;
|
|
1093
|
-
readonly dialect?: ConstraintDialectExtension;
|
|
1094
|
-
readonly deferrable?: boolean;
|
|
1095
|
-
readonly initially?: ConstraintTiming;
|
|
1096
|
-
}
|
|
1097
|
-
/** A referenced table and exact candidate-key column tuple. */
|
|
1098
|
-
interface ForeignKeyTarget<TTable extends TableLike<any> = TableLike<any>, TColumns extends readonly AnyKeyColumn[] = readonly AnyKeyColumn[]> {
|
|
1099
|
-
readonly table: TTable;
|
|
1100
|
-
readonly columns: TColumns;
|
|
1101
|
-
}
|
|
1102
|
-
type ForeignKeyTargetInput<TTarget extends ForeignKeyTarget = ForeignKeyTarget> = TTarget | (() => TTarget);
|
|
1103
|
-
/** A foreign key from local columns to a direct or lazily resolved target. */
|
|
1104
|
-
interface ForeignKeyConstraint<TColumns extends readonly AnyKeyColumn[] = readonly AnyKeyColumn[], TTarget extends ForeignKeyTargetInput = ForeignKeyTargetInput> extends SchemaObjectIdentity {
|
|
1105
|
-
readonly kind: 'foreign-key';
|
|
1106
|
-
readonly columns: TColumns;
|
|
1107
|
-
readonly target: TTarget;
|
|
1108
|
-
readonly physicalName?: string;
|
|
1109
|
-
readonly dialect?: ConstraintDialectExtension;
|
|
1110
|
-
readonly onUpdate?: ReferentialAction;
|
|
1111
|
-
readonly onDelete?: ReferentialAction;
|
|
1112
|
-
readonly match?: ForeignKeyMatch;
|
|
1113
|
-
readonly deferrable?: boolean;
|
|
1114
|
-
readonly initially?: ConstraintTiming;
|
|
1115
|
-
}
|
|
1116
|
-
/** Database uniqueness that deliberately does not prove a candidate key. */
|
|
1117
|
-
interface UniqueConstraint<TColumns extends readonly AnyKeyColumn[] = readonly AnyKeyColumn[], TNulls extends UniqueNullSemantics = UniqueNullSemantics> extends SchemaObjectIdentity {
|
|
1118
|
-
readonly kind: 'unique-constraint';
|
|
1119
|
-
readonly columns: TColumns;
|
|
1120
|
-
readonly nulls: TNulls;
|
|
1121
|
-
readonly physicalName?: string;
|
|
1122
|
-
readonly dialect?: ConstraintDialectExtension;
|
|
1123
|
-
readonly deferrable?: boolean;
|
|
1124
|
-
readonly initially?: ConstraintTiming;
|
|
1125
|
-
}
|
|
1126
|
-
/** A table-scoped boolean invariant. */
|
|
1127
|
-
interface CheckConstraint<TExpression extends AnyExpression = AnyExpression> extends SchemaObjectIdentity {
|
|
1128
|
-
readonly kind: 'check';
|
|
1129
|
-
readonly expression: TExpression;
|
|
1130
|
-
readonly physicalName?: string;
|
|
1131
|
-
readonly dialect?: ConstraintDialectExtension;
|
|
1132
|
-
readonly deferrable?: boolean;
|
|
1133
|
-
readonly initially?: ConstraintTiming;
|
|
1134
|
-
}
|
|
1135
|
-
/**
|
|
1136
|
-
* Opaque catalog SQL whose check-constraint origin proves a boolean SQL
|
|
1137
|
-
* semantic type. The expression remains dialect-tagged and parameter-free.
|
|
1138
|
-
*/
|
|
1139
|
-
interface CatalogCheckExpression<TDialect extends SchemaDialectName = SchemaDialectName> extends SchemaExpression<ResultMeta<boolean, never, SqlBoolean> | ExpressionMeta<never>, 'unsafe'> {
|
|
1140
|
-
readonly schemaSqlDialect: TDialect;
|
|
1141
|
-
readonly schemaSql: string;
|
|
1142
|
-
}
|
|
1143
|
-
/** Structured schema metadata carried by sources that declare constraints. */
|
|
1144
|
-
type SourceConstraint = KeyConstraint | UniqueConstraint | ForeignKeyConstraint | CheckConstraint;
|
|
1145
|
-
/** Named schema constraints attached to a source. */
|
|
1146
|
-
type SourceConstraintsRecord = Readonly<Record<string, SourceConstraint>>;
|
|
1147
|
-
/**
|
|
1148
|
-
* Validate one constraint against a schema adapter dialect. This is kept
|
|
1149
|
-
* separate from construction because the same declaration can be inspected
|
|
1150
|
-
* for more than one target dialect before a serializer is selected.
|
|
1151
|
-
*/
|
|
1152
|
-
declare function validateConstraintDialect(constraint: SourceConstraint, dialect: string, path?: readonly (string | number)[]): readonly SchemaMetadataDiagnostic[];
|
|
1153
|
-
type AnyKeyColumn = ColumnReference<string, any>;
|
|
1154
|
-
type ColumnSource<TColumn> = DependenciesOf<TColumn> extends ColumnDependency<infer TSource, string> ? TSource : never;
|
|
1155
|
-
type IsNullableKeyColumn<TColumn> = [DeclaredColumnNullabilityOf<TColumn>] extends [never] ? null extends OutputOf<TColumn> ? true : false : true extends DeclaredColumnNullabilityOf<TColumn> ? true : false;
|
|
1156
|
-
type InvalidKeyColumn<TColumn, TSource> = TColumn extends AnyKeyColumn ? IsNullableKeyColumn<TColumn> extends true ? TColumn : DependenciesOf<TColumn> extends ColumnDependency<TSource, string> ? never : TColumn : TColumn;
|
|
1157
|
-
type KeyColumnsValidation<TColumns extends readonly AnyKeyColumn[]> = [{ [K in keyof TColumns]: InvalidKeyColumn<TColumns[K], ColumnSource<TColumns[0]>>; }[number]] extends [never] ? unknown : never;
|
|
1158
|
-
type SameSourceColumnsValidation<TColumns extends readonly AnyKeyColumn[]> = [{ [K in keyof TColumns]: TColumns[K] extends AnyKeyColumn ? DependenciesOf<TColumns[K]> extends ColumnDependency<ColumnSource<TColumns[0]>, string> ? never : TColumns[K] : TColumns[K]; }[number]] extends [never] ? unknown : never;
|
|
1159
|
-
type SameSqlDomain<TLeft, TRight> = SqlTypeOf<TLeft> extends (infer TLeftSql) ? SqlTypeOf<TRight> extends (infer TRightSql) ? TLeftSql extends SqlUnknown ? false : TRightSql extends SqlUnknown ? false : TLeftSql extends AnySqlType ? TRightSql extends AnySqlType ? string extends TLeftSql['sqlType'] ? false : string extends TRightSql['sqlType'] ? false : [TLeftSql['sqlType']] extends [TRightSql['sqlType']] ? [TRightSql['sqlType']] extends [TLeftSql['sqlType']] ? true : false : false : false : false : false : false;
|
|
1160
|
-
type ForeignKeyColumnsValidation<TLocal extends readonly AnyKeyColumn[], TTarget extends readonly AnyKeyColumn[]> = TLocal extends readonly [infer TLocalHead, ...infer TLocalTail] ? TTarget extends readonly [infer TTargetHead, ...infer TTargetTail] ? TLocalHead extends AnyKeyColumn ? TTargetHead extends AnyKeyColumn ? SameSqlDomain<TLocalHead, TTargetHead> extends true ? ForeignKeyColumnsValidation<Extract<TLocalTail, readonly AnyKeyColumn[]>, Extract<TTargetTail, readonly AnyKeyColumn[]>> : never : never : never : never : TTarget extends readonly [] ? unknown : never;
|
|
1161
|
-
type IsUnresolvedSqlDomain<TSqlType> = TSqlType extends SqlUnknown ? true : TSqlType extends AnySqlType ? string extends TSqlType['sqlType'] ? true : false : true;
|
|
1162
|
-
type CatalogSqlDomainCompatible<TLeft, TRight> = true extends IsUnresolvedSqlDomain<SqlTypeOf<TLeft>> | IsUnresolvedSqlDomain<SqlTypeOf<TRight>> ? true : SameSqlDomain<TLeft, TRight>;
|
|
1163
|
-
type CatalogForeignKeyColumnsValidation<TLocal extends readonly AnyKeyColumn[], TTarget extends readonly AnyKeyColumn[]> = TLocal extends readonly [infer TLocalHead, ...infer TLocalTail] ? TTarget extends readonly [infer TTargetHead, ...infer TTargetTail] ? TLocalHead extends AnyKeyColumn ? TTargetHead extends AnyKeyColumn ? CatalogSqlDomainCompatible<TLocalHead, TTargetHead> extends true ? CatalogForeignKeyColumnsValidation<Extract<TLocalTail, readonly AnyKeyColumn[]>, Extract<TTargetTail, readonly AnyKeyColumn[]>> : never : never : never : never : TTarget extends readonly [] ? unknown : never;
|
|
1164
|
-
type CheckExpressionValidation<TExpression> = [SqlTypeOf<TExpression>] extends [never] ? never : SqlTypeOf<TExpression> extends SqlBoolean ? unknown : never;
|
|
1165
|
-
/** Declare a primary key, including a composite primary key. */
|
|
1166
|
-
declare function primaryKey<const TColumns extends readonly [AnyKeyColumn, ...AnyKeyColumn[]]>(...columns: TColumns & KeyColumnsValidation<NoInfer<TColumns>>): KeyConstraint<'primary-key', TColumns>;
|
|
1167
|
-
declare function primaryKey<const TColumns extends readonly [AnyKeyColumn, ...AnyKeyColumn[]], const TOptions extends KeyConstraintOptions>(...columnsAndOptions: [...TColumns, TOptions] & KeyColumnsValidation<NoInfer<TColumns>>): KeyConstraint<'primary-key', TColumns>;
|
|
1168
|
-
/** Declare a non-null unique key, including a composite unique key. */
|
|
1169
|
-
declare function unique<const TColumns extends readonly [AnyKeyColumn, ...AnyKeyColumn[]]>(...columns: TColumns & KeyColumnsValidation<NoInfer<TColumns>>): KeyConstraint<'unique', TColumns>;
|
|
1170
|
-
declare function unique<const TColumns extends readonly [AnyKeyColumn, ...AnyKeyColumn[]], const TOptions extends KeyConstraintOptions>(...columnsAndOptions: [...TColumns, TOptions] & KeyColumnsValidation<NoInfer<TColumns>>): KeyConstraint<'unique', TColumns>;
|
|
1171
|
-
/**
|
|
1172
|
-
* Describe database uniqueness without claiming that the columns determine a
|
|
1173
|
-
* row. Nullable columns are accepted, and the NULL behavior is explicit in
|
|
1174
|
-
* the returned metadata. Use {@link unique} when a type-level key proof is
|
|
1175
|
-
* intended.
|
|
1176
|
-
*/
|
|
1177
|
-
declare function uniqueConstraint<const TColumns extends readonly [AnyKeyColumn, ...AnyKeyColumn[]]>(...columns: TColumns & SameSourceColumnsValidation<NoInfer<TColumns>>): UniqueConstraint<TColumns, 'distinct'>;
|
|
1178
|
-
declare function uniqueConstraint<const TColumns extends readonly [AnyKeyColumn, ...AnyKeyColumn[]], const TOptions extends UniqueConstraintOptions>(...columnsAndOptions: [...TColumns, TOptions] & SameSourceColumnsValidation<NoInfer<TColumns>>): UniqueConstraint<TColumns, TOptions extends {
|
|
1179
|
-
readonly nulls: infer TNulls extends UniqueNullSemantics;
|
|
1180
|
-
} ? TNulls : 'distinct'>;
|
|
1181
|
-
/** Pair a table with the exact columns targeted by a foreign key. */
|
|
1182
|
-
declare function references<TTable extends TableLike<any>, const TColumns extends readonly [AnyKeyColumn, ...AnyKeyColumn[]]>(table: TTable, ...columns: TColumns): ForeignKeyTarget<TTable, TColumns>;
|
|
1183
|
-
type ResolvedTarget$1<T> = T extends (() => infer TResolved) ? TResolved : T;
|
|
1184
|
-
/** Declare a single-column or composite foreign key. */
|
|
1185
|
-
declare function foreignKey<const TColumns extends readonly [AnyKeyColumn, ...AnyKeyColumn[]], const TTarget extends ForeignKeyTargetInput, const TOptions extends ForeignKeyOptions = {}>(columns: TColumns & SameSourceColumnsValidation<NoInfer<TColumns>>, target: TTarget & (ResolvedTarget$1<TTarget> extends ForeignKeyTarget<any, infer TTargetColumns> ? ForeignKeyColumnsValidation<TColumns, TTargetColumns> : never), options?: TOptions): ForeignKeyConstraint<TColumns, TTarget>;
|
|
1186
|
-
/**
|
|
1187
|
-
* Reconstruct a foreign key proved by database catalog metadata.
|
|
1188
|
-
*
|
|
1189
|
-
* @remarks
|
|
1190
|
-
* Use this helper for generated or introspection-owned declarations when one
|
|
1191
|
-
* or both native SQL domains are unresolved. It accepts unresolved domains,
|
|
1192
|
-
* but still rejects known domain mismatches, unequal tuple arity, and local
|
|
1193
|
-
* columns from different sources. The enclosing `table()` declaration
|
|
1194
|
-
* continues to verify target-column ownership and candidate-key metadata.
|
|
1195
|
-
* Resolved targets also receive runtime shape, ownership, and arity checks.
|
|
1196
|
-
* The returned value serializes as an ordinary foreign-key constraint.
|
|
1197
|
-
*/
|
|
1198
|
-
declare function catalogForeignKey<const TColumns extends readonly [AnyKeyColumn, ...AnyKeyColumn[]], const TTarget extends ForeignKeyTargetInput, const TOptions extends ForeignKeyOptions = {}>(columns: TColumns & SameSourceColumnsValidation<NoInfer<TColumns>>, target: TTarget & (ResolvedTarget$1<TTarget> extends ForeignKeyTarget<any, infer TTargetColumns> ? CatalogForeignKeyColumnsValidation<TColumns, TTargetColumns> : never), options?: TOptions): ForeignKeyConstraint<TColumns, TTarget>;
|
|
1199
|
-
/** Declare a boolean table invariant. */
|
|
1200
|
-
declare function check<const TExpression extends Expression<any, any>, const TOptions extends CheckConstraintOptions = {}>(expression: TExpression & CheckExpressionValidation<TExpression>, options?: TOptions): CheckConstraint<TExpression>;
|
|
1201
|
-
/**
|
|
1202
|
-
* Reconstruct a boolean check from opaque SQL recovered from a database
|
|
1203
|
-
* catalog.
|
|
1204
|
-
*
|
|
1205
|
-
* @remarks
|
|
1206
|
-
* This helper records catalog origin as a narrow type-level proof. It
|
|
1207
|
-
* gives the opaque expression the {@link SqlBoolean} semantic type without
|
|
1208
|
-
* changing the ordinary {@link check} contract. Qubu does not parse or infer
|
|
1209
|
-
* dependencies from the SQL. It preserves the text apart from normalizing
|
|
1210
|
-
* line endings and retains the dialect tag in serialized schema metadata.
|
|
1211
|
-
*/
|
|
1212
|
-
declare function catalogCheck<const TDialect extends SchemaDialectName, const TOptions extends CheckConstraintOptions = {}>(input: CatalogCheckSql<TDialect>, options?: TOptions): CheckConstraint<CatalogCheckExpression<TDialect>>;
|
|
1213
|
-
//#endregion
|
|
1214
|
-
//#region src/query/errors.d.ts
|
|
1215
|
-
/** Stable diagnostics shared by type-level and runtime query validation. */
|
|
1216
|
-
type QueryValidationErrorCode = 'invalid-selection' | 'duplicate-clause' | 'invalid-mutation' | 'unsafe-mutation' | 'invalid-update' | 'invalid-insert' | 'invalid-comparison' | 'invalid-boolean-expression' | 'invalid-pagination' | 'invalid-row-lock' | 'invalid-json-path' | 'missing-source' | 'invalid-grouping' | 'incompatible-sql-domain' | 'incompatible-sql-equality' | 'incompatible-sql-order' | 'incompatible-set-domain' | 'invalid-subquery' | 'invalid-omission' | 'invalid-stream-query' | 'invalid-explain-query' | 'invalid-explain-options' | 'unsupported-explain-option' | 'unsupported-explain-dialect' | 'missing-dialect-capability';
|
|
1217
|
-
interface QueryValidationIssue {
|
|
1218
|
-
readonly code: QueryValidationErrorCode;
|
|
1219
|
-
readonly context: string;
|
|
1220
|
-
readonly path: readonly (string | number)[];
|
|
1221
|
-
readonly message: string;
|
|
1222
|
-
readonly hint: string;
|
|
1223
|
-
}
|
|
1224
|
-
/**
|
|
1225
|
-
* A type-level query failure that names the failing rule and the repair path.
|
|
1226
|
-
* The legacy detail field is optional so each validator can retain the useful
|
|
1227
|
-
* source or clause type in the compiler diagnostic.
|
|
1228
|
-
*/
|
|
1229
|
-
type QueryTypeValidation<TCode extends QueryValidationErrorCode, TContext extends string, THint extends string, TDetail = never> = {
|
|
1230
|
-
readonly __qubu_error_code__: TCode;
|
|
1231
|
-
readonly __qubu_error_context__: TContext;
|
|
1232
|
-
readonly __qubu_error_hint__: THint;
|
|
1233
|
-
} & ([TDetail] extends [never] ? unknown : {
|
|
1234
|
-
readonly __qubu_error_detail__: TDetail;
|
|
1235
|
-
});
|
|
1236
|
-
/** Raised when a query cannot satisfy Qubu's runtime authoring rules. */
|
|
1237
|
-
declare class QueryValidationError extends TypeError {
|
|
1238
|
-
readonly name = "QueryValidationError";
|
|
1239
|
-
readonly code: QueryValidationErrorCode;
|
|
1240
|
-
readonly context: string;
|
|
1241
|
-
readonly path: readonly (string | number)[];
|
|
1242
|
-
readonly hint: string;
|
|
1243
|
-
readonly issue: QueryValidationIssue;
|
|
1244
|
-
constructor(issue: QueryValidationIssue);
|
|
1245
|
-
}
|
|
1246
|
-
//#endregion
|
|
1247
|
-
//#region src/core/render.d.ts
|
|
1248
|
-
type DefaultDialectCapability = 'json';
|
|
1249
|
-
interface RenderedQuery {
|
|
1250
|
-
readonly text: string;
|
|
1251
|
-
readonly parameters: readonly unknown[];
|
|
1252
|
-
}
|
|
1253
|
-
interface RenderOptions<TCapabilities extends DialectCapability = DialectCapability> {
|
|
1254
|
-
readonly dialect?: Dialect<TCapabilities>;
|
|
1255
|
-
}
|
|
1256
|
-
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
1257
|
-
type MissingCapabilities<TQuery, TCapabilities extends DialectCapability> = IsAny<CapabilitiesOf<TQuery>> extends true ? never : Exclude<CapabilitiesOf<TQuery>, TCapabilities>;
|
|
1258
|
-
type RenderCapabilityValidation<TQuery, TCapabilities extends DialectCapability> = [MissingCapabilities<TQuery, TCapabilities>] extends [never] ? unknown : QueryTypeValidation<'missing-dialect-capability', 'render.dialect', 'Provide a dialect that supports every capability required by the query.', MissingCapabilities<TQuery, TCapabilities>>;
|
|
1259
|
-
declare function render<TQuery extends AnyFragment>(query: TQuery & RenderCapabilityValidation<TQuery, DefaultDialectCapability>): RenderedQuery;
|
|
1260
|
-
declare function render<TQuery extends AnyFragment, TCapabilities extends DialectCapability>(query: TQuery & RenderCapabilityValidation<TQuery, TCapabilities>, options: RenderOptions<TCapabilities> | Dialect<TCapabilities>): RenderedQuery;
|
|
1261
|
-
//#endregion
|
|
1262
|
-
//#region src/execution.d.ts
|
|
1263
|
-
type StreamableQuery<TRow extends object = Record<string, unknown>> = QueryWithRow<TRow> & {
|
|
1264
|
-
readonly queryKind: 'select' | 'set';
|
|
1265
|
-
};
|
|
1266
|
-
/** Rendering policy and cancellation input accepted by query execution. */
|
|
1267
|
-
interface ExecutionOptions extends RenderOptions {
|
|
1268
|
-
/** Passed to the application adapter for drivers that support cancellation. */
|
|
1269
|
-
readonly signal?: AbortSignal;
|
|
1270
|
-
}
|
|
1271
|
-
/** Rendering, EXPLAIN, and cancellation options for plan requests. */
|
|
1272
|
-
interface ExplainOptions extends RenderOptions, ExplainRenderOptions {
|
|
1273
|
-
/** Passed to the application adapter for drivers that support cancellation. */
|
|
1274
|
-
readonly signal?: AbortSignal;
|
|
1275
|
-
}
|
|
1276
|
-
/** EXPLAIN options accepted for SELECT and set-operation queries. */
|
|
1277
|
-
type ExplainReadOptions = ExplainOptions;
|
|
1278
|
-
/** EXPLAIN options for mutations, which never run with analysis enabled. */
|
|
1279
|
-
type ExplainMutationOptions = Omit<ExplainOptions, 'analyze'> & {
|
|
1280
|
-
readonly analyze?: never;
|
|
1281
|
-
};
|
|
1282
|
-
/** Select read-only or plan-only EXPLAIN options from the query kind. */
|
|
1283
|
-
type ExplainOptionsFor<TQuery extends AnyQuery> = TQuery['queryKind'] extends 'select' | 'set' ? ExplainReadOptions : ExplainMutationOptions;
|
|
1284
|
-
/** Controls the lifecycle of one adapter-owned transaction. */
|
|
1285
|
-
interface TransactionOptions {
|
|
1286
|
-
/** Passed to the adapter for transaction begin, commit, and rollback. */
|
|
1287
|
-
readonly signal?: AbortSignal;
|
|
1288
|
-
}
|
|
1289
|
-
/** One rendered statement and the controls passed to an application adapter. */
|
|
1290
|
-
interface ExecutionRequest {
|
|
1291
|
-
/** SQL text and raw application parameters produced by Qubu's renderer. */
|
|
1292
|
-
readonly statement: RenderedQuery;
|
|
1293
|
-
/** The source query kind, available without parsing rendered SQL. */
|
|
1294
|
-
readonly queryKind: QueryKind;
|
|
1295
|
-
/** Named logical fields used by Qubu after the adapter returns raw rows. */
|
|
1296
|
-
readonly resultShape: ResultShape;
|
|
1297
|
-
/** Present when the caller supplied an abort signal to {@link execute} or {@link stream}. */
|
|
1298
|
-
readonly signal?: AbortSignal;
|
|
1299
|
-
}
|
|
1300
|
-
/** One rendered EXPLAIN statement and the controls passed to an adapter. */
|
|
1301
|
-
interface ExplainRequest extends ExecutionRequest {}
|
|
1302
|
-
/**
|
|
1303
|
-
* Driver-neutral rows and optional mutation facts returned by an adapter.
|
|
1304
|
-
*
|
|
1305
|
-
* Adapters normalize driver result fields into this shape. They should omit a
|
|
1306
|
-
* mutation fact when the driver cannot report it accurately.
|
|
1307
|
-
*/
|
|
1308
|
-
interface ExecutionResult<TRow extends object = Record<string, unknown>> {
|
|
1309
|
-
/** Decoded result rows. Mutations without `RETURNING` use an empty array. */
|
|
1310
|
-
readonly rows: readonly TRow[];
|
|
1311
|
-
/** Rows inserted, updated, or deleted when the driver reports that count. */
|
|
1312
|
-
readonly affectedRows?: number | bigint;
|
|
1313
|
-
/** Rows whose stored values changed when distinct from affected rows. */
|
|
1314
|
-
readonly changedRows?: number | bigint;
|
|
1315
|
-
/** An insert identifier reported by the driver, including generated IDs. */
|
|
1316
|
-
readonly insertId?: string | number | bigint;
|
|
1317
|
-
}
|
|
1318
|
-
/** Driver-normalized rows and mutation facts returned to Qubu by an adapter. */
|
|
1319
|
-
interface AdapterExecutionResult {
|
|
1320
|
-
/** Object rows keyed by the query's rendered result aliases. */
|
|
1321
|
-
readonly rows: readonly Readonly<Record<string, unknown>>[];
|
|
1322
|
-
readonly affectedRows?: number | bigint;
|
|
1323
|
-
readonly changedRows?: number | bigint;
|
|
1324
|
-
readonly insertId?: string | number | bigint;
|
|
1325
|
-
}
|
|
1326
|
-
/** Adapter-decoded vendor plan rows returned by an EXPLAIN request. */
|
|
1327
|
-
interface ExplainResult<TPlanRow extends object = Record<string, unknown>> {
|
|
1328
|
-
/** Opaque plan rows in the shape selected by the application adapter. */
|
|
1329
|
-
readonly rows: readonly TPlanRow[];
|
|
1330
|
-
}
|
|
1331
|
-
/**
|
|
1332
|
-
* The driver-facing boundary. `request.statement.parameters` contains raw
|
|
1333
|
-
* application values in placeholder order; the adapter binds and encodes them
|
|
1334
|
-
* for its driver. Connection pooling, transactions, retries, and proprietary
|
|
1335
|
-
* driver-row normalization remain adapter concerns. Qubu applies the adapter's
|
|
1336
|
-
* registered logical result decoders afterward.
|
|
1337
|
-
*/
|
|
1338
|
-
interface QueryAdapter {
|
|
1339
|
-
/** Default rendering policy for queries sent through this adapter. */
|
|
1340
|
-
readonly dialect: Dialect;
|
|
1341
|
-
/** Driver-specific conversions for portable logical result domains. */
|
|
1342
|
-
readonly decoders?: ResultDecoders;
|
|
1343
|
-
/** Execute one request and normalize the driver's result fields. */
|
|
1344
|
-
execute(request: ExecutionRequest): Promise<AdapterExecutionResult>;
|
|
1345
|
-
}
|
|
1346
|
-
/**
|
|
1347
|
-
* An opt-in adapter capability for typed, adapter-decoded EXPLAIN results.
|
|
1348
|
-
*
|
|
1349
|
-
* Qubu renders and validates the statement. The adapter binds parameters,
|
|
1350
|
-
* executes the plan request, owns cancellation and connection lifecycle, and
|
|
1351
|
-
* decodes vendor-specific plan rows without a cross-dialect Qubu plan tree.
|
|
1352
|
-
*/
|
|
1353
|
-
interface ExplainableQueryAdapter<TPlanRow extends object = Record<string, unknown>> extends QueryAdapter {
|
|
1354
|
-
explain(request: ExplainRequest): Promise<ExplainResult<TPlanRow>>;
|
|
1355
|
-
}
|
|
1356
|
-
/** Extract the plan-row type owned by an explainable adapter. */
|
|
1357
|
-
type ExplainPlanRow<TAdapter extends ExplainableQueryAdapter> = TAdapter extends ExplainableQueryAdapter<infer TPlanRow> ? TPlanRow : never;
|
|
1358
|
-
/**
|
|
1359
|
-
* An opt-in adapter capability for streaming rows from read queries.
|
|
1360
|
-
*
|
|
1361
|
-
* The adapter owns the returned iterator and every resource behind it. The
|
|
1362
|
-
* iterator must release those resources when it completes, is closed early,
|
|
1363
|
-
* fails, or observes an aborted request signal.
|
|
1364
|
-
*/
|
|
1365
|
-
interface StreamingQueryAdapter extends QueryAdapter {
|
|
1366
|
-
/** Return an adapter-owned object-row stream for one SELECT or set query. */
|
|
1367
|
-
stream(request: ExecutionRequest): AsyncIterable<Readonly<Record<string, unknown>>>;
|
|
1368
|
-
}
|
|
1369
|
-
type QueryExecutor = QueryAdapter;
|
|
1370
|
-
/**
|
|
1371
|
-
* An adapter that can pin one driver connection for a callback transaction.
|
|
1372
|
-
* The callback receives an adapter scoped to that transaction. Qubu does not
|
|
1373
|
-
* issue transaction SQL or manage the driver's connection lifecycle.
|
|
1374
|
-
*/
|
|
1375
|
-
interface TransactionalQueryAdapter<TTransactionAdapter extends QueryAdapter = QueryAdapter> extends QueryAdapter {
|
|
1376
|
-
transaction<T>(callback: (adapter: TTransactionAdapter) => Promise<T>, options?: TransactionOptions): Promise<T>;
|
|
1377
|
-
}
|
|
1378
|
-
/** A transaction-capable streaming adapter whose scoped client can stream. */
|
|
1379
|
-
type StreamingTransactionalQueryAdapter = StreamingQueryAdapter & TransactionalQueryAdapter<StreamingQueryAdapter>;
|
|
1380
|
-
/** A query client with one application-owned adapter bound to every call. */
|
|
1381
|
-
interface QubuClient<TAdapter extends QueryAdapter = QueryAdapter> {
|
|
1382
|
-
/** The adapter supplied to {@link qubu}. */
|
|
1383
|
-
readonly adapter: TAdapter;
|
|
1384
|
-
/** Execute a query and keep the adapter's structured mutation facts. */
|
|
1385
|
-
execute<TRow extends object>(query: QueryWithRow<TRow>, options?: ExecutionOptions): Promise<ExecutionResult<TRow>>;
|
|
1386
|
-
/** Execute a query and return only its decoded rows. */
|
|
1387
|
-
rows<TRow extends object>(query: QueryWithRow<TRow>, options?: ExecutionOptions): Promise<readonly TRow[]>;
|
|
1388
|
-
}
|
|
1389
|
-
/** A bound client whose adapter also decodes vendor-specific EXPLAIN rows. */
|
|
1390
|
-
interface QubuExplainableClient<TAdapter extends ExplainableQueryAdapter = ExplainableQueryAdapter> extends QubuClient<TAdapter> {
|
|
1391
|
-
/** Explain a query without executing it and return adapter-owned plan rows. */
|
|
1392
|
-
explain<TQuery extends AnyQuery>(query: TQuery, options?: ExplainOptionsFor<TQuery>): Promise<ExplainResult<ExplainPlanRow<TAdapter>>>;
|
|
1393
|
-
}
|
|
1394
|
-
/** A bound client whose adapter also supports typed read-query streams. */
|
|
1395
|
-
interface QubuStreamingClient<TAdapter extends StreamingQueryAdapter = StreamingQueryAdapter> extends QubuClient<TAdapter> {
|
|
1396
|
-
/** Stream decoded rows without materializing the complete result. */
|
|
1397
|
-
stream<TRow extends object>(query: StreamableQuery<TRow>, options?: ExecutionOptions): AsyncIterable<TRow>;
|
|
1398
|
-
}
|
|
1399
|
-
/** A bound client that supports both streaming and typed EXPLAIN plans. */
|
|
1400
|
-
interface QubuStreamingExplainableClient<TAdapter extends StreamingQueryAdapter & ExplainableQueryAdapter = StreamingQueryAdapter & ExplainableQueryAdapter> extends QubuStreamingClient<TAdapter>, QubuExplainableClient<TAdapter> {}
|
|
1401
|
-
type QubuClientFor<TAdapter extends QueryAdapter> = TAdapter extends StreamingQueryAdapter ? TAdapter extends ExplainableQueryAdapter ? QubuStreamingExplainableClient<TAdapter> : QubuStreamingClient<TAdapter> : TAdapter extends ExplainableQueryAdapter ? QubuExplainableClient<TAdapter> : QubuClient<TAdapter>;
|
|
1402
|
-
/** The client available inside a transaction callback. */
|
|
1403
|
-
type QubuTransaction = QubuClient<QueryAdapter>;
|
|
1404
|
-
/** The streaming client available inside a streaming transaction callback. */
|
|
1405
|
-
type QubuStreamingTransaction = QubuStreamingClient<StreamingQueryAdapter>;
|
|
1406
|
-
/** A bound client whose adapter supports transaction-scoped execution. */
|
|
1407
|
-
interface QubuTransactionalClient<TAdapter extends TransactionalQueryAdapter = TransactionalQueryAdapter, TTransactionAdapter extends QueryAdapter = QueryAdapter> extends QubuClient<TAdapter> {
|
|
1408
|
-
/** Run several queries on one adapter-owned transaction. */
|
|
1409
|
-
transaction<T>(callback: (transaction: QubuClientFor<TTransactionAdapter>) => Promise<T>, options?: TransactionOptions): Promise<T>;
|
|
1410
|
-
}
|
|
1411
|
-
/** A bound EXPLAIN client with an adapter-owned transaction callback. */
|
|
1412
|
-
type QubuExplainableTransactionalClient<TAdapter extends ExplainableQueryAdapter & TransactionalQueryAdapter = ExplainableQueryAdapter & TransactionalQueryAdapter, TTransactionAdapter extends QueryAdapter = QueryAdapter> = QubuExplainableClient<TAdapter> & QubuTransactionalClient<TAdapter, TTransactionAdapter>;
|
|
1413
|
-
/** A bound streaming and EXPLAIN client with an adapter-owned transaction. */
|
|
1414
|
-
type QubuExplainableStreamingTransactionalClient<TAdapter extends ExplainableQueryAdapter & StreamingTransactionalQueryAdapter = ExplainableQueryAdapter & StreamingTransactionalQueryAdapter> = QubuStreamingExplainableClient<TAdapter> & QubuTransactionalClient<TAdapter, StreamingQueryAdapter>;
|
|
1415
|
-
/** A bound streaming client whose transaction callback can also stream. */
|
|
1416
|
-
interface QubuStreamingTransactionalClient<TAdapter extends StreamingTransactionalQueryAdapter = StreamingTransactionalQueryAdapter> extends QubuStreamingClient<TAdapter> {
|
|
1417
|
-
/** Run a callback whose streams must be consumed or closed before it resolves. */
|
|
1418
|
-
transaction<T>(callback: (transaction: QubuStreamingTransaction) => Promise<T>, options?: TransactionOptions): Promise<T>;
|
|
1419
|
-
}
|
|
1420
|
-
/** Bind an application-owned adapter once for repeated query execution. */
|
|
1421
|
-
declare function qubu<TAdapter extends ExplainableQueryAdapter & StreamingTransactionalQueryAdapter>(adapter: TAdapter): QubuExplainableStreamingTransactionalClient<TAdapter>;
|
|
1422
|
-
declare function qubu<TAdapter extends ExplainableQueryAdapter & TransactionalQueryAdapter & StreamingQueryAdapter>(adapter: TAdapter): QubuExplainableTransactionalClient<TAdapter> & QubuStreamingExplainableClient<TAdapter>;
|
|
1423
|
-
declare function qubu<TAdapter extends ExplainableQueryAdapter & TransactionalQueryAdapter>(adapter: TAdapter): QubuExplainableTransactionalClient<TAdapter>;
|
|
1424
|
-
declare function qubu<TAdapter extends ExplainableQueryAdapter & StreamingQueryAdapter>(adapter: TAdapter): QubuStreamingExplainableClient<TAdapter>;
|
|
1425
|
-
declare function qubu<TAdapter extends ExplainableQueryAdapter>(adapter: TAdapter): QubuExplainableClient<TAdapter>;
|
|
1426
|
-
declare function qubu<TAdapter extends StreamingTransactionalQueryAdapter>(adapter: TAdapter): QubuStreamingTransactionalClient<TAdapter>;
|
|
1427
|
-
declare function qubu<TAdapter extends TransactionalQueryAdapter & StreamingQueryAdapter>(adapter: TAdapter): QubuTransactionalClient<TAdapter> & QubuStreamingClient<TAdapter>;
|
|
1428
|
-
declare function qubu<TAdapter extends TransactionalQueryAdapter>(adapter: TAdapter): QubuTransactionalClient<TAdapter>;
|
|
1429
|
-
declare function qubu<TAdapter extends StreamingQueryAdapter>(adapter: TAdapter): QubuStreamingClient<TAdapter>;
|
|
1430
|
-
declare function qubu<TAdapter extends QueryAdapter>(adapter: TAdapter): QubuClient<TAdapter>;
|
|
1431
|
-
interface DriverValueEncoder<TDriverValue = unknown> {
|
|
1432
|
-
/** Convert one Qubu parameter into the driver's bindable representation. */
|
|
1433
|
-
encode(value: unknown): TDriverValue;
|
|
1434
|
-
}
|
|
1435
|
-
/**
|
|
1436
|
-
* Render a typed query, pass it to an application adapter, and return the
|
|
1437
|
-
* adapter's structured result unchanged.
|
|
1438
|
-
*
|
|
1439
|
-
* Driver errors are not caught or translated.
|
|
1440
|
-
*/
|
|
1441
|
-
declare function execute<TRow extends object>(query: QueryWithRow<TRow>, adapter: QueryAdapter, options?: ExecutionOptions): Promise<ExecutionResult<TRow>>;
|
|
1442
|
-
declare function execute<TRow extends object>(adapter: QueryAdapter, query: QueryWithRow<TRow>, options?: ExecutionOptions): Promise<ExecutionResult<TRow>>;
|
|
1443
|
-
/** Execute a query and return its decoded rows without mutation facts. */
|
|
1444
|
-
declare function executeRows<TRow extends object>(query: QueryWithRow<TRow>, adapter: QueryAdapter, options?: ExecutionOptions): Promise<readonly TRow[]>;
|
|
1445
|
-
declare function executeRows<TRow extends object>(adapter: QueryAdapter, query: QueryWithRow<TRow>, options?: ExecutionOptions): Promise<readonly TRow[]>;
|
|
1446
|
-
/**
|
|
1447
|
-
* Render a query as a dialect-specific EXPLAIN request and return the
|
|
1448
|
-
* adapter-decoded vendor plan rows. EXPLAIN never calls QueryAdapter.execute.
|
|
1449
|
-
*/
|
|
1450
|
-
declare function explain<TQuery extends AnyQuery, TAdapter extends ExplainableQueryAdapter>(query: TQuery, adapter: TAdapter, options?: ExplainOptionsFor<TQuery>): Promise<ExplainResult<ExplainPlanRow<TAdapter>>>;
|
|
1451
|
-
declare function explain<TQuery extends AnyQuery, TAdapter extends ExplainableQueryAdapter>(adapter: TAdapter, query: TQuery, options?: ExplainOptionsFor<TQuery>): Promise<ExplainResult<ExplainPlanRow<TAdapter>>>;
|
|
1452
|
-
/**
|
|
1453
|
-
* Render a SELECT or set-operation query and return the adapter-owned row
|
|
1454
|
-
* stream. Mutations, including mutations with RETURNING, must use execute().
|
|
1455
|
-
*/
|
|
1456
|
-
declare function stream<TRow extends object>(query: StreamableQuery<TRow>, adapter: StreamingQueryAdapter, options?: ExecutionOptions): AsyncIterable<TRow>;
|
|
1457
|
-
declare function stream<TRow extends object>(adapter: StreamingQueryAdapter, query: StreamableQuery<TRow>, options?: ExecutionOptions): AsyncIterable<TRow>;
|
|
1458
|
-
//#endregion
|
|
1459
|
-
//#region src/expressions/cast.d.ts
|
|
1460
|
-
type CastDefinition = ColumnDefinition<any> & {
|
|
1461
|
-
readonly nullable: false;
|
|
1462
|
-
readonly castTarget: CastTarget;
|
|
1463
|
-
};
|
|
1464
|
-
/**
|
|
1465
|
-
* Cast to a built-in or custom column definition while deriving both result
|
|
1466
|
-
* types from that definition. Operand nullability and source facts survive.
|
|
1211
|
+
* Cast to a built-in or custom column definition while deriving both result types from that
|
|
1212
|
+
* definition. Operand nullability and source facts survive.
|
|
1467
1213
|
*/
|
|
1468
1214
|
declare function cast<TDefinition extends CastDefinition, TExpression extends AnyExpression>(expression: TExpression, definition: TDefinition): ResultExpression<{
|
|
1469
1215
|
readonly output: ColumnOutput<TDefinition>;
|
|
1470
1216
|
readonly children: TExpression;
|
|
1471
|
-
readonly kind:
|
|
1217
|
+
readonly kind: "operator";
|
|
1472
1218
|
readonly nullableFrom: NullabilityOf<TExpression>;
|
|
1473
1219
|
readonly sqlType: ColumnSqlType<TDefinition>;
|
|
1474
1220
|
}>;
|
|
@@ -1476,7 +1222,7 @@ declare function cast<TDefinition extends CastDefinition, TExpression extends An
|
|
|
1476
1222
|
declare function cast<T, TSqlType extends AnySqlType = SqlUnknown, TExpression extends AnyExpression = AnyExpression, const TType extends string = string>(expression: TExpression, typeName: TType): ResultExpression<{
|
|
1477
1223
|
readonly output: T;
|
|
1478
1224
|
readonly children: TExpression;
|
|
1479
|
-
readonly kind:
|
|
1225
|
+
readonly kind: "operator";
|
|
1480
1226
|
readonly nullableFrom: NullabilityOf<TExpression>;
|
|
1481
1227
|
readonly sqlType: TSqlType;
|
|
1482
1228
|
}>;
|
|
@@ -1499,10 +1245,10 @@ declare function typedCast<T, TSqlType extends AnySqlType>(): <TExpression exten
|
|
|
1499
1245
|
type MappedOutput<TOutput, TExpression> = TOutput | Extract<ExpressionOutput<TExpression>, null>;
|
|
1500
1246
|
type MappedResultMetadata<TOutput, TExpression> = ResultMeta<MappedOutput<TOutput, TExpression>, NullabilityOf<TExpression>, SqlTypeOf<TExpression>> | ExpressionMeta<DependenciesOf<TExpression>> | InheritedMetadata<TExpression>;
|
|
1501
1247
|
/** Attach an application decoder to an expression without changing its SQL. */
|
|
1502
|
-
declare function mapResult<TOutput, TExpression extends AnyExpression>(expression: TExpression, decoder: ResultDecoder<TOutput>): TExpression extends AnySchemaExpression ? SchemaExpression<MappedResultMetadata<TOutput, TExpression>, TExpression[
|
|
1248
|
+
declare function mapResult<TOutput, TExpression extends AnyExpression>(expression: TExpression, decoder: ResultDecoder<TOutput>): TExpression extends AnySchemaExpression ? SchemaExpression<MappedResultMetadata<TOutput, TExpression>, TExpression["expressionKind"]> : Expression<MappedResultMetadata<TOutput, TExpression>, TExpression["expressionKind"]>;
|
|
1503
1249
|
//#endregion
|
|
1504
1250
|
//#region src/expressions/value.d.ts
|
|
1505
|
-
interface ValueExpression<T = unknown, TSqlType extends AnySqlType = SqlUnknown> extends SchemaExpression<ResultMeta<T, never, TSqlType> | ExpressionMeta<never>,
|
|
1251
|
+
interface ValueExpression<T = unknown, TSqlType extends AnySqlType = SqlUnknown> extends SchemaExpression<ResultMeta<T, never, TSqlType> | ExpressionMeta<never>, "value"> {
|
|
1506
1252
|
readonly value: T;
|
|
1507
1253
|
}
|
|
1508
1254
|
declare function value<T>(input: T): ValueExpression<T>;
|
|
@@ -1515,11 +1261,11 @@ type Operand<T> = T | ExpressionWithOutput<T>;
|
|
|
1515
1261
|
/** Plain values are contextually typed by the expression beside them. */
|
|
1516
1262
|
type OperandSqlType<T, TContext extends AnySqlType> = T extends Fragment<any> ? SqlTypeOf<T> : TContext;
|
|
1517
1263
|
/** Type-level validation that a known SQL domain provides a capability. */
|
|
1518
|
-
type SqlCapabilityValidation<TActual, TCapability> = SqlTypeSatisfies<TActual, TCapability> extends true ? unknown : QueryTypeValidation<
|
|
1264
|
+
type SqlCapabilityValidation<TActual, TCapability> = SqlTypeSatisfies<TActual, TCapability> extends true ? unknown : QueryTypeValidation<"incompatible-sql-domain", "expression.sql-domain", "Use an expression with the required SQL domain.", TActual>;
|
|
1519
1265
|
/** Type-level validation that two known SQL domains can test equality. */
|
|
1520
|
-
type SqlEqualityValidation<TLeft, TRight> = SqlEqualityCompatible<TLeft, TRight> extends true ? unknown : QueryTypeValidation<
|
|
1266
|
+
type SqlEqualityValidation<TLeft, TRight> = SqlEqualityCompatible<TLeft, TRight> extends true ? unknown : QueryTypeValidation<"incompatible-sql-equality", "comparison.operands", "Use operands from the same SQL equality group.", readonly [TLeft, TRight]>;
|
|
1521
1267
|
/** Type-level validation that two known SQL domains share an ordering group. */
|
|
1522
|
-
type SqlOrderValidation<TLeft, TRight> = SqlOrderCompatible<TLeft, TRight> extends true ? unknown : QueryTypeValidation<
|
|
1268
|
+
type SqlOrderValidation<TLeft, TRight> = SqlOrderCompatible<TLeft, TRight> extends true ? unknown : QueryTypeValidation<"incompatible-sql-order", "comparison.operands", "Use operands from the same SQL ordering group.", readonly [TLeft, TRight]>;
|
|
1523
1269
|
type OperandNullability<T> = T extends Fragment<any> ? NullabilityOf<T> : never;
|
|
1524
1270
|
type IsNullOperand<T> = T extends null ? true : T extends ValueExpression<infer TValue> ? [TValue] extends [null] ? true : false : false;
|
|
1525
1271
|
//#endregion
|
|
@@ -1527,7 +1273,7 @@ type IsNullOperand<T> = T extends null ? true : T extends ValueExpression<infer
|
|
|
1527
1273
|
type NonNullBooleanResult<TExpression> = ResultExpression<{
|
|
1528
1274
|
readonly output: boolean;
|
|
1529
1275
|
readonly children: TExpression;
|
|
1530
|
-
readonly kind:
|
|
1276
|
+
readonly kind: "operator";
|
|
1531
1277
|
readonly nullableFrom: never;
|
|
1532
1278
|
readonly sqlType: SqlBoolean;
|
|
1533
1279
|
}>;
|
|
@@ -1564,13 +1310,13 @@ declare function notIn<T, TExpression extends ExpressionWithOutput<T>, const TVa
|
|
|
1564
1310
|
type ComparisonResult<TLeft, R, TOperator extends string> = ResultExpression<{
|
|
1565
1311
|
readonly output: boolean;
|
|
1566
1312
|
readonly children: TLeft | R;
|
|
1567
|
-
readonly kind:
|
|
1568
|
-
readonly nullableFrom: TOperator extends
|
|
1313
|
+
readonly kind: "operator";
|
|
1314
|
+
readonly nullableFrom: TOperator extends "IS DISTINCT FROM" | "IS NOT DISTINCT FROM" ? never : TOperator extends "=" | "<>" ? IsNullOperand<R> extends true ? never : NullabilityOf<TLeft> | OperandNullability<R> : NullabilityOf<TLeft> | OperandNullability<R>;
|
|
1569
1315
|
readonly sqlType: SqlBoolean;
|
|
1570
1316
|
}>;
|
|
1571
1317
|
/** SQL-domain validation selected by a comparison operator family. */
|
|
1572
|
-
type ComparisonValidation<TLeft, TRight, TOperator extends string> = TOperator extends
|
|
1573
|
-
declare function eq<T, TLeft extends ExpressionWithOutput<T>, R extends Operand<NoInfer<T>>>(left: TLeft & ComparisonValidation<TLeft, R,
|
|
1318
|
+
type ComparisonValidation<TLeft, TRight, TOperator extends string> = TOperator extends "LIKE" | "NOT LIKE" | "ILIKE" ? SqlCapabilityValidation<ExpressionSqlType<TLeft>, SqlTextLike> & SqlCapabilityValidation<OperandSqlType<TRight, ExpressionSqlType<TLeft>>, SqlTextLike> : TOperator extends "<" | "<=" | ">" | ">=" ? SqlOrderValidation<ExpressionSqlType<TLeft>, OperandSqlType<TRight, ExpressionSqlType<TLeft>>> : SqlEqualityValidation<ExpressionSqlType<TLeft>, OperandSqlType<TRight, ExpressionSqlType<TLeft>>>;
|
|
1319
|
+
declare function eq<T, TLeft extends ExpressionWithOutput<T>, R extends Operand<NoInfer<T>>>(left: TLeft & ComparisonValidation<TLeft, R, "=">, right: R): ComparisonResult<TLeft & SqlEqualityValidation<(MetadataOf<TLeft> extends (infer T_1) ? T_1 extends MetadataOf<TLeft> ? T_1 extends {
|
|
1574
1320
|
readonly kind: "result";
|
|
1575
1321
|
} ? T_1 : never : never : never) extends (infer T_2) ? T_2 extends (MetadataOf<TLeft> extends (infer T_3) ? T_3 extends MetadataOf<TLeft> ? T_3 extends {
|
|
1576
1322
|
readonly kind: "result";
|
|
@@ -1583,7 +1329,7 @@ declare function eq<T, TLeft extends ExpressionWithOutput<T>, R extends Operand<
|
|
|
1583
1329
|
} ? T_6 : never : never : never) ? T_5 extends {
|
|
1584
1330
|
readonly sqlType: infer TSqlType extends AnySqlType;
|
|
1585
1331
|
} ? TSqlType : SqlUnknown : never : never>>, R, "=">;
|
|
1586
|
-
declare function ne<T, TLeft extends ExpressionWithOutput<T>, R extends Operand<NoInfer<T>>>(left: TLeft & ComparisonValidation<TLeft, R,
|
|
1332
|
+
declare function ne<T, TLeft extends ExpressionWithOutput<T>, R extends Operand<NoInfer<T>>>(left: TLeft & ComparisonValidation<TLeft, R, "<>">, right: R): ComparisonResult<TLeft & SqlEqualityValidation<(MetadataOf<TLeft> extends (infer T_1) ? T_1 extends MetadataOf<TLeft> ? T_1 extends {
|
|
1587
1333
|
readonly kind: "result";
|
|
1588
1334
|
} ? T_1 : never : never : never) extends (infer T_2) ? T_2 extends (MetadataOf<TLeft> extends (infer T_3) ? T_3 extends MetadataOf<TLeft> ? T_3 extends {
|
|
1589
1335
|
readonly kind: "result";
|
|
@@ -1596,7 +1342,7 @@ declare function ne<T, TLeft extends ExpressionWithOutput<T>, R extends Operand<
|
|
|
1596
1342
|
} ? T_6 : never : never : never) ? T_5 extends {
|
|
1597
1343
|
readonly sqlType: infer TSqlType extends AnySqlType;
|
|
1598
1344
|
} ? TSqlType : SqlUnknown : never : never>>, R, "<>">;
|
|
1599
|
-
declare function lt<TLeft extends AnyExpression, R extends Operand<Exclude<ExpressionOutput<TLeft>, null>>>(left: TLeft & ComparisonValidation<TLeft, R,
|
|
1345
|
+
declare function lt<TLeft extends AnyExpression, R extends Operand<Exclude<ExpressionOutput<TLeft>, null>>>(left: TLeft & ComparisonValidation<TLeft, R, "<">, right: R): ComparisonResult<TLeft & SqlOrderValidation<(MetadataOf<TLeft> extends (infer T) ? T extends MetadataOf<TLeft> ? T extends {
|
|
1600
1346
|
readonly kind: "result";
|
|
1601
1347
|
} ? T : never : never : never) extends (infer T_1) ? T_1 extends (MetadataOf<TLeft> extends (infer T_2) ? T_2 extends MetadataOf<TLeft> ? T_2 extends {
|
|
1602
1348
|
readonly kind: "result";
|
|
@@ -1609,7 +1355,7 @@ declare function lt<TLeft extends AnyExpression, R extends Operand<Exclude<Expre
|
|
|
1609
1355
|
} ? T_5 : never : never : never) ? T_4 extends {
|
|
1610
1356
|
readonly sqlType: infer TSqlType extends AnySqlType;
|
|
1611
1357
|
} ? TSqlType : SqlUnknown : never : never>>, R, "<">;
|
|
1612
|
-
declare function lte<TLeft extends AnyExpression, R extends Operand<Exclude<ExpressionOutput<TLeft>, null>>>(left: TLeft & ComparisonValidation<TLeft, R,
|
|
1358
|
+
declare function lte<TLeft extends AnyExpression, R extends Operand<Exclude<ExpressionOutput<TLeft>, null>>>(left: TLeft & ComparisonValidation<TLeft, R, "<=">, right: R): ComparisonResult<TLeft & SqlOrderValidation<(MetadataOf<TLeft> extends (infer T) ? T extends MetadataOf<TLeft> ? T extends {
|
|
1613
1359
|
readonly kind: "result";
|
|
1614
1360
|
} ? T : never : never : never) extends (infer T_1) ? T_1 extends (MetadataOf<TLeft> extends (infer T_2) ? T_2 extends MetadataOf<TLeft> ? T_2 extends {
|
|
1615
1361
|
readonly kind: "result";
|
|
@@ -1622,7 +1368,7 @@ declare function lte<TLeft extends AnyExpression, R extends Operand<Exclude<Expr
|
|
|
1622
1368
|
} ? T_5 : never : never : never) ? T_4 extends {
|
|
1623
1369
|
readonly sqlType: infer TSqlType extends AnySqlType;
|
|
1624
1370
|
} ? TSqlType : SqlUnknown : never : never>>, R, "<=">;
|
|
1625
|
-
declare function gt<TLeft extends AnyExpression, R extends Operand<Exclude<ExpressionOutput<TLeft>, null>>>(left: TLeft & ComparisonValidation<TLeft, R,
|
|
1371
|
+
declare function gt<TLeft extends AnyExpression, R extends Operand<Exclude<ExpressionOutput<TLeft>, null>>>(left: TLeft & ComparisonValidation<TLeft, R, ">">, right: R): ComparisonResult<TLeft & SqlOrderValidation<(MetadataOf<TLeft> extends (infer T) ? T extends MetadataOf<TLeft> ? T extends {
|
|
1626
1372
|
readonly kind: "result";
|
|
1627
1373
|
} ? T : never : never : never) extends (infer T_1) ? T_1 extends (MetadataOf<TLeft> extends (infer T_2) ? T_2 extends MetadataOf<TLeft> ? T_2 extends {
|
|
1628
1374
|
readonly kind: "result";
|
|
@@ -1635,7 +1381,7 @@ declare function gt<TLeft extends AnyExpression, R extends Operand<Exclude<Expre
|
|
|
1635
1381
|
} ? T_5 : never : never : never) ? T_4 extends {
|
|
1636
1382
|
readonly sqlType: infer TSqlType extends AnySqlType;
|
|
1637
1383
|
} ? TSqlType : SqlUnknown : never : never>>, R, ">">;
|
|
1638
|
-
declare function gte<TLeft extends AnyExpression, R extends Operand<Exclude<ExpressionOutput<TLeft>, null>>>(left: TLeft & ComparisonValidation<TLeft, R,
|
|
1384
|
+
declare function gte<TLeft extends AnyExpression, R extends Operand<Exclude<ExpressionOutput<TLeft>, null>>>(left: TLeft & ComparisonValidation<TLeft, R, ">=">, right: R): ComparisonResult<TLeft & SqlOrderValidation<(MetadataOf<TLeft> extends (infer T) ? T extends MetadataOf<TLeft> ? T extends {
|
|
1639
1385
|
readonly kind: "result";
|
|
1640
1386
|
} ? T : never : never : never) extends (infer T_1) ? T_1 extends (MetadataOf<TLeft> extends (infer T_2) ? T_2 extends MetadataOf<TLeft> ? T_2 extends {
|
|
1641
1387
|
readonly kind: "result";
|
|
@@ -1648,7 +1394,7 @@ declare function gte<TLeft extends AnyExpression, R extends Operand<Exclude<Expr
|
|
|
1648
1394
|
} ? T_5 : never : never : never) ? T_4 extends {
|
|
1649
1395
|
readonly sqlType: infer TSqlType extends AnySqlType;
|
|
1650
1396
|
} ? TSqlType : SqlUnknown : never : never>>, R, ">=">;
|
|
1651
|
-
declare function like<TLeft extends ExpressionWithOutput<string>, R extends Operand<string>>(left: TLeft & ComparisonValidation<TLeft, R,
|
|
1397
|
+
declare function like<TLeft extends ExpressionWithOutput<string>, R extends Operand<string>>(left: TLeft & ComparisonValidation<TLeft, R, "LIKE">, pattern: R): ComparisonResult<TLeft & SqlCapabilityValidation<(MetadataOf<TLeft> extends (infer T) ? T extends MetadataOf<TLeft> ? T extends {
|
|
1652
1398
|
readonly kind: "result";
|
|
1653
1399
|
} ? T : never : never : never) extends (infer T_1) ? T_1 extends (MetadataOf<TLeft> extends (infer T_2) ? T_2 extends MetadataOf<TLeft> ? T_2 extends {
|
|
1654
1400
|
readonly kind: "result";
|
|
@@ -1661,7 +1407,7 @@ declare function like<TLeft extends ExpressionWithOutput<string>, R extends Oper
|
|
|
1661
1407
|
} ? T_5 : never : never : never) ? T_4 extends {
|
|
1662
1408
|
readonly sqlType: infer TSqlType extends AnySqlType;
|
|
1663
1409
|
} ? TSqlType : SqlUnknown : never : never>, SqlTextLike>, R, "LIKE">;
|
|
1664
|
-
declare function notLike<TLeft extends ExpressionWithOutput<string>, R extends Operand<string>>(left: TLeft & ComparisonValidation<TLeft, R,
|
|
1410
|
+
declare function notLike<TLeft extends ExpressionWithOutput<string>, R extends Operand<string>>(left: TLeft & ComparisonValidation<TLeft, R, "NOT LIKE">, pattern: R): ComparisonResult<TLeft & SqlCapabilityValidation<(MetadataOf<TLeft> extends (infer T) ? T extends MetadataOf<TLeft> ? T extends {
|
|
1665
1411
|
readonly kind: "result";
|
|
1666
1412
|
} ? T : never : never : never) extends (infer T_1) ? T_1 extends (MetadataOf<TLeft> extends (infer T_2) ? T_2 extends MetadataOf<TLeft> ? T_2 extends {
|
|
1667
1413
|
readonly kind: "result";
|
|
@@ -1674,7 +1420,7 @@ declare function notLike<TLeft extends ExpressionWithOutput<string>, R extends O
|
|
|
1674
1420
|
} ? T_5 : never : never : never) ? T_4 extends {
|
|
1675
1421
|
readonly sqlType: infer TSqlType extends AnySqlType;
|
|
1676
1422
|
} ? TSqlType : SqlUnknown : never : never>, SqlTextLike>, R, "NOT LIKE">;
|
|
1677
|
-
declare function isDistinctFrom<T, TLeft extends ExpressionWithOutput<T>, R extends Operand<NoInfer<T>>>(left: TLeft & ComparisonValidation<TLeft, R,
|
|
1423
|
+
declare function isDistinctFrom<T, TLeft extends ExpressionWithOutput<T>, R extends Operand<NoInfer<T>>>(left: TLeft & ComparisonValidation<TLeft, R, "IS DISTINCT FROM">, right: R): ComparisonResult<TLeft & SqlEqualityValidation<(MetadataOf<TLeft> extends (infer T_1) ? T_1 extends MetadataOf<TLeft> ? T_1 extends {
|
|
1678
1424
|
readonly kind: "result";
|
|
1679
1425
|
} ? T_1 : never : never : never) extends (infer T_2) ? T_2 extends (MetadataOf<TLeft> extends (infer T_3) ? T_3 extends MetadataOf<TLeft> ? T_3 extends {
|
|
1680
1426
|
readonly kind: "result";
|
|
@@ -1687,7 +1433,7 @@ declare function isDistinctFrom<T, TLeft extends ExpressionWithOutput<T>, R exte
|
|
|
1687
1433
|
} ? T_6 : never : never : never) ? T_5 extends {
|
|
1688
1434
|
readonly sqlType: infer TSqlType extends AnySqlType;
|
|
1689
1435
|
} ? TSqlType : SqlUnknown : never : never>>, R, "IS DISTINCT FROM">;
|
|
1690
|
-
declare function isNotDistinctFrom<T, TLeft extends ExpressionWithOutput<T>, R extends Operand<NoInfer<T>>>(left: TLeft & ComparisonValidation<TLeft, R,
|
|
1436
|
+
declare function isNotDistinctFrom<T, TLeft extends ExpressionWithOutput<T>, R extends Operand<NoInfer<T>>>(left: TLeft & ComparisonValidation<TLeft, R, "IS NOT DISTINCT FROM">, right: R): ComparisonResult<TLeft & SqlEqualityValidation<(MetadataOf<TLeft> extends (infer T_1) ? T_1 extends MetadataOf<TLeft> ? T_1 extends {
|
|
1691
1437
|
readonly kind: "result";
|
|
1692
1438
|
} ? T_1 : never : never : never) extends (infer T_2) ? T_2 extends (MetadataOf<TLeft> extends (infer T_3) ? T_3 extends MetadataOf<TLeft> ? T_3 extends {
|
|
1693
1439
|
readonly kind: "result";
|
|
@@ -1703,13 +1449,13 @@ declare function isNotDistinctFrom<T, TLeft extends ExpressionWithOutput<T>, R e
|
|
|
1703
1449
|
//#endregion
|
|
1704
1450
|
//#region src/expressions/subquery.d.ts
|
|
1705
1451
|
type SingleColumn<Row extends object> = keyof Row extends (infer TKey) ? TKey extends keyof Row ? [keyof Row] extends [TKey] ? Row[TKey] : never : never : never;
|
|
1706
|
-
type ScalarOutput<TQuery extends AnyQuery> = SingleColumn<QueryRow<TQuery>> | ([CardinalityOf<TQuery>] extends [
|
|
1452
|
+
type ScalarOutput<TQuery extends AnyQuery> = SingleColumn<QueryRow<TQuery>> | ([CardinalityOf<TQuery>] extends ["exactly-one"] ? never : null);
|
|
1707
1453
|
type SingleColumnSqlType<TQuery extends AnyQuery> = SingleColumn<QuerySqlTypeMap<TQuery>>;
|
|
1708
|
-
declare function scalar<TQuery extends AnyQuery>(query: TQuery): Expression<ResultMeta<ScalarOutput<TQuery>, never, SingleColumnSqlType<TQuery>> | InheritedMetadata<TQuery> | SubqueryMeta,
|
|
1454
|
+
declare function scalar<TQuery extends AnyQuery>(query: TQuery): Expression<ResultMeta<ScalarOutput<TQuery>, never, SingleColumnSqlType<TQuery>> | InheritedMetadata<TQuery> | SubqueryMeta, "subquery">;
|
|
1709
1455
|
//#endregion
|
|
1710
1456
|
//#region src/expressions/operators/comparison/subquery.d.ts
|
|
1711
|
-
type IsUnion<T, TWhole = T> = T extends unknown ? [TWhole] extends [T] ? false : true : never;
|
|
1712
|
-
type InQueryValidation<TExpression, TQuery> = [keyof QueryRow<TQuery>] extends [never] ? QueryTypeValidation<
|
|
1457
|
+
type IsUnion<T, TWhole = T> = T extends unknown ? ([TWhole] extends [T] ? false : true) : never;
|
|
1458
|
+
type InQueryValidation<TExpression, TQuery> = [keyof QueryRow<TQuery>] extends [never] ? QueryTypeValidation<"invalid-subquery", "in-query.projection", "Select exactly one field in the IN subquery."> : true extends IsUnion<keyof QueryRow<TQuery>> ? QueryTypeValidation<"invalid-subquery", "in-query.projection", "Select exactly one field in the IN subquery."> : SingleColumn<QueryRow<TQuery>> extends ExpressionOutput<TExpression> ? SqlEqualityValidation<ExpressionSqlType<TExpression>, SingleColumn<QuerySqlTypeMap<TQuery>>> : QueryTypeValidation<"incompatible-sql-equality", "in-query.operands", "Select a subquery field from the same SQL equality group as the expression.", SingleColumn<QueryRow<TQuery>>>;
|
|
1713
1459
|
declare function inQuery<TExpression extends AnyExpression, TQuery extends AnyQuery>(expression: TExpression & InQueryValidation<TExpression, TQuery>, query: TQuery): SubqueryResultExpression<{
|
|
1714
1460
|
readonly output: boolean;
|
|
1715
1461
|
readonly children: TExpression | TQuery;
|
|
@@ -1746,10 +1492,10 @@ declare function caseWhen<T, TCondition extends BooleanExpression<any>, TThen ex
|
|
|
1746
1492
|
type SqlChild<TValues extends readonly unknown[]> = Extract<TValues[number], AnyFragment>;
|
|
1747
1493
|
type EmbeddedQueryMetadata<TChild> = TChild extends AnyQuery ? SubqueryMeta : never;
|
|
1748
1494
|
/**
|
|
1749
|
-
* A parameterized SQL template that composes with Qubu expressions and
|
|
1750
|
-
*
|
|
1495
|
+
* A parameterized SQL template that composes with Qubu expressions and queries through the normal
|
|
1496
|
+
* renderer.
|
|
1751
1497
|
*/
|
|
1752
|
-
type SqlFragment<TOutput = unknown, TSqlType extends AnySqlType = SqlUnknown, TChild extends AnyFragment = never> = Expression<ResultMeta<TOutput, NullabilityOf<TChild>, TSqlType> | ExpressionMeta<DependenciesOf<TChild>> | InheritedMetadata<TChild> | EmbeddedQueryMetadata<TChild>,
|
|
1498
|
+
type SqlFragment<TOutput = unknown, TSqlType extends AnySqlType = SqlUnknown, TChild extends AnyFragment = never> = Expression<ResultMeta<TOutput, NullabilityOf<TChild>, TSqlType> | ExpressionMeta<DependenciesOf<TChild>> | InheritedMetadata<TChild> | EmbeddedQueryMetadata<TChild>, "sql">;
|
|
1753
1499
|
/** A SQL template tag with an explicitly declared output and SQL domain. */
|
|
1754
1500
|
interface TypedSqlTag<TOutput, TSqlType extends AnySqlType = SqlUnknown> {
|
|
1755
1501
|
<const TValues extends readonly unknown[]>(strings: TemplateStringsArray, ...values: TValues): SqlFragment<TOutput, TSqlType, SqlChild<TValues>>;
|
|
@@ -1757,33 +1503,33 @@ interface TypedSqlTag<TOutput, TSqlType extends AnySqlType = SqlUnknown> {
|
|
|
1757
1503
|
/** Public call contract for {@link sql}. */
|
|
1758
1504
|
interface SqlTag extends TypedSqlTag<unknown, SqlUnknown> {
|
|
1759
1505
|
/**
|
|
1760
|
-
* Declare the application output and SQL semantic domain without changing
|
|
1761
|
-
*
|
|
1506
|
+
* Declare the application output and SQL semantic domain without changing how template
|
|
1507
|
+
* substitutions render.
|
|
1762
1508
|
*/
|
|
1763
1509
|
type<TOutput, TSqlType extends AnySqlType = SqlUnknown>(): TypedSqlTag<TOutput, TSqlType>;
|
|
1764
1510
|
}
|
|
1765
1511
|
/**
|
|
1766
|
-
* Build trusted SQL syntax while binding every ordinary substitution as a
|
|
1767
|
-
*
|
|
1512
|
+
* Build trusted SQL syntax while binding every ordinary substitution as a parameter. Qubu fragments
|
|
1513
|
+
* remain composable substitutions.
|
|
1768
1514
|
*
|
|
1769
|
-
* @remarks
|
|
1770
|
-
*
|
|
1771
|
-
* dynamic syntax. Use `sql.type<Output,
|
|
1772
|
-
* is known.
|
|
1515
|
+
* @remarks
|
|
1516
|
+
* Template text is trusted and is not parsed. Use `identifier()` from `qubu/core` for runtime
|
|
1517
|
+
* identifiers and `unsafeExpression()` for deliberately dynamic syntax. Use `sql.type<Output,
|
|
1518
|
+
* SqlType>()` when the fragment's result is known.
|
|
1773
1519
|
*/
|
|
1774
1520
|
declare const sql: SqlTag;
|
|
1775
1521
|
//#endregion
|
|
1776
1522
|
//#region src/expressions/functions/aggregate.d.ts
|
|
1777
1523
|
declare function count(): AggregateResultExpression<{
|
|
1778
1524
|
readonly output: number;
|
|
1779
|
-
readonly kind:
|
|
1525
|
+
readonly kind: "function";
|
|
1780
1526
|
readonly nullableFrom: never;
|
|
1781
1527
|
readonly sqlType: SqlInteger;
|
|
1782
1528
|
}>;
|
|
1783
1529
|
declare function count<TExpression extends AnyExpression>(expression: TExpression): AggregateResultExpression<{
|
|
1784
1530
|
readonly output: number;
|
|
1785
1531
|
readonly children: TExpression;
|
|
1786
|
-
readonly kind:
|
|
1532
|
+
readonly kind: "function";
|
|
1787
1533
|
readonly nullableFrom: never;
|
|
1788
1534
|
readonly sqlType: SqlInteger;
|
|
1789
1535
|
}>;
|
|
@@ -1826,9 +1572,9 @@ declare function max<T, TExpression extends ExpressionWithOutput<T>>(expression:
|
|
|
1826
1572
|
//#region src/expressions/functions/call.d.ts
|
|
1827
1573
|
declare function call<TOutput = unknown, const TName extends string = string, const TArguments extends readonly unknown[] = readonly unknown[], TNullableFrom = NullabilityOf<TArguments[number]>, TSqlType extends AnySqlType = SqlUnknown>(name: TName, ...args: TArguments): Expression<ResultMeta<TOutput, TNullableFrom, TSqlType> | ExpressionMeta<DependenciesOf<TArguments[number]>> | InheritedMetadata<TArguments[number]>, "function">;
|
|
1828
1574
|
/**
|
|
1829
|
-
* Internal built-in function constructor for deterministic schema functions.
|
|
1830
|
-
*
|
|
1831
|
-
*
|
|
1575
|
+
* Internal built-in function constructor for deterministic schema functions. Arbitrary calls stay
|
|
1576
|
+
* on {@link call} and require an explicit schema extension contract before they can be used in
|
|
1577
|
+
* schema metadata.
|
|
1832
1578
|
*/
|
|
1833
1579
|
declare function schemaCall<TOutput = unknown, const TName extends string = string, const TArguments extends readonly unknown[] = readonly unknown[], TNullableFrom = NullabilityOf<TArguments[number]>, TSqlType extends AnySqlType = SqlUnknown>(name: TName, ...args: TArguments): SchemaExpression<ResultMeta<TOutput, TNullableFrom, TSqlType> | ExpressionMeta<DependenciesOf<TArguments[number]>> | InheritedMetadata<TArguments[number]>, "function">;
|
|
1834
1580
|
/** Declare the SQL result domain of a custom function call. */
|
|
@@ -1888,16 +1634,16 @@ declare function concat<const TArguments extends readonly Operand<string>[]>(...
|
|
|
1888
1634
|
//#region src/expressions/functions/window.d.ts
|
|
1889
1635
|
type WindowOrder = AnyExpression | OrderTerm<any>;
|
|
1890
1636
|
/**
|
|
1891
|
-
* The initial inline window scope. Named windows and frame clauses can be
|
|
1892
|
-
*
|
|
1637
|
+
* The initial inline window scope. Named windows and frame clauses can be added at a later
|
|
1638
|
+
* dialect-aware boundary without changing expression types.
|
|
1893
1639
|
*/
|
|
1894
1640
|
interface WindowSpec {
|
|
1895
1641
|
readonly partitionBy?: readonly AnyExpression[];
|
|
1896
1642
|
readonly orderBy?: readonly WindowOrder[];
|
|
1897
1643
|
}
|
|
1898
1644
|
type FragmentItems<T> = T extends readonly unknown[] ? T[number] : never;
|
|
1899
|
-
type WindowSpecParts<TWindow> = TWindow extends WindowSpec ? FragmentItems<TWindow[
|
|
1900
|
-
type WindowedExpression<TExpression extends AnyExpression, TWindow extends WindowSpec | undefined> = Expression<ResultMeta<OutputOf<TExpression>, NullabilityOf<TExpression>, SqlTypeOf<TExpression>> | ExpressionMeta<DependenciesOf<TExpression | WindowSpecParts<TWindow>>> | InheritedMetadata<TExpression | WindowSpecParts<TWindow>> | WindowMeta,
|
|
1645
|
+
type WindowSpecParts<TWindow> = TWindow extends WindowSpec ? FragmentItems<TWindow["partitionBy"]> | FragmentItems<TWindow["orderBy"]> : never;
|
|
1646
|
+
type WindowedExpression<TExpression extends AnyExpression, TWindow extends WindowSpec | undefined> = Expression<ResultMeta<OutputOf<TExpression>, NullabilityOf<TExpression>, SqlTypeOf<TExpression>> | ExpressionMeta<DependenciesOf<TExpression | WindowSpecParts<TWindow>>> | InheritedMetadata<TExpression | WindowSpecParts<TWindow>> | WindowMeta, "function">;
|
|
1901
1647
|
declare function over<TExpression extends AnyExpression, const TWindow extends WindowSpec | undefined = undefined>(expression: TExpression, window?: TWindow): WindowedExpression<TExpression, TWindow>;
|
|
1902
1648
|
declare function rowNumber(): Expression<ExpressionMeta<never> | ResultMeta<number, never, SqlInteger>, "function">;
|
|
1903
1649
|
declare function rank(): Expression<ExpressionMeta<never> | ResultMeta<number, never, SqlInteger>, "function">;
|
|
@@ -1910,7 +1656,7 @@ declare const jsonPathBrand: unique symbol;
|
|
|
1910
1656
|
/** An opaque root-relative JSON path whose literal segments remain available to TypeScript. */
|
|
1911
1657
|
interface JsonPath<TSegments extends readonly JsonPathSegment[] = readonly JsonPathSegment[]> {
|
|
1912
1658
|
readonly [jsonPathBrand]: true;
|
|
1913
|
-
readonly pathKind:
|
|
1659
|
+
readonly pathKind: "json";
|
|
1914
1660
|
readonly segments: TSegments;
|
|
1915
1661
|
}
|
|
1916
1662
|
/**
|
|
@@ -1919,7 +1665,7 @@ interface JsonPath<TSegments extends readonly JsonPathSegment[] = readonly JsonP
|
|
|
1919
1665
|
* @throws {TypeError} When an index is negative, fractional, or unsafe.
|
|
1920
1666
|
*/
|
|
1921
1667
|
declare function jsonPath<const TSegments extends readonly JsonPathSegment[]>(...segments: TSegments): JsonPath<TSegments>;
|
|
1922
|
-
type JsonExpressionMetadata<TOutput, TDocument> = ResultMeta<TOutput> | ExpressionMeta<DependenciesOf<TDocument>> | InheritedMetadata<TDocument> | RequiresCapabilityMeta<
|
|
1668
|
+
type JsonExpressionMetadata<TOutput, TDocument> = ResultMeta<TOutput> | ExpressionMeta<DependenciesOf<TDocument>> | InheritedMetadata<TDocument> | RequiresCapabilityMeta<"json">;
|
|
1923
1669
|
/** Extract a JSON string, returning SQL NULL for missing, null, or non-string values. */
|
|
1924
1670
|
declare function jsonText<TDocument extends AnyExpression, TPath extends JsonPath>(document: TDocument, path: TPath): SchemaExpression<JsonExpressionMetadata<string | null, TDocument>, "function">;
|
|
1925
1671
|
/** Extract a JSON number, returning SQL NULL for missing, null, or non-number values. */
|
|
@@ -2717,160 +2463,487 @@ declare const modulo: <T, TLeft extends ExpressionWithOutput<T>, R extends Opera
|
|
|
2717
2463
|
} ? TSqlType : SqlUnknown : never : never;
|
|
2718
2464
|
}>;
|
|
2719
2465
|
//#endregion
|
|
2720
|
-
//#region src/query/clauses/types.d.ts
|
|
2721
|
-
type ClausePlacement =
|
|
2722
|
-
interface SelectClause<TMetadata = any> extends Fragment<TMetadata> {
|
|
2723
|
-
readonly clauseKind: string;
|
|
2724
|
-
readonly placement: ClausePlacement;
|
|
2725
|
-
readonly order: number;
|
|
2466
|
+
//#region src/query/clauses/types.d.ts
|
|
2467
|
+
type ClausePlacement = "before-select" | "after-select";
|
|
2468
|
+
interface SelectClause<TMetadata = any> extends Fragment<TMetadata> {
|
|
2469
|
+
readonly clauseKind: string;
|
|
2470
|
+
readonly placement: ClausePlacement;
|
|
2471
|
+
readonly order: number;
|
|
2472
|
+
}
|
|
2473
|
+
type AnySelectClause = SelectClause<any>;
|
|
2474
|
+
//#endregion
|
|
2475
|
+
//#region src/query/clauses/distinct.d.ts
|
|
2476
|
+
interface DistinctClause extends SelectClause<never> {
|
|
2477
|
+
readonly clauseKind: "distinct";
|
|
2478
|
+
}
|
|
2479
|
+
declare function distinct(): DistinctClause;
|
|
2480
|
+
//#endregion
|
|
2481
|
+
//#region src/query/clauses/having.d.ts
|
|
2482
|
+
interface HavingClause<TMetadata = never> extends SelectClause<TMetadata> {
|
|
2483
|
+
readonly clauseKind: "having";
|
|
2484
|
+
readonly condition: BooleanExpression<any>;
|
|
2485
|
+
}
|
|
2486
|
+
type HavingComposition<TCondition extends BooleanExpression<any> | Omit$1> = TCondition extends Omit$1 ? Omit$1 : TCondition extends BooleanExpression<any> ? HavingClause<InheritedMetadata<TCondition>> : never;
|
|
2487
|
+
type HavingValidation<TCondition> = TCondition extends Omit$1 ? unknown : SqlCapabilityValidation<ExpressionSqlType<TCondition>, SqlBoolean>;
|
|
2488
|
+
declare function having<TCondition extends BooleanExpression<any> | Omit$1>(condition: TCondition & HavingValidation<TCondition>): HavingComposition<TCondition>;
|
|
2489
|
+
//#endregion
|
|
2490
|
+
//#region src/query/clauses/pagination.d.ts
|
|
2491
|
+
interface OffsetClause extends SelectClause<never> {
|
|
2492
|
+
readonly clauseKind: "offset";
|
|
2493
|
+
readonly rows: number;
|
|
2494
|
+
}
|
|
2495
|
+
type AnyPaginationClause = OffsetClause | FetchClause;
|
|
2496
|
+
declare function offset(rows: number): OffsetClause;
|
|
2497
|
+
interface FetchClause<TRows extends number = number> extends SelectClause<never> {
|
|
2498
|
+
readonly clauseKind: "fetch";
|
|
2499
|
+
readonly direction: "FIRST" | "NEXT";
|
|
2500
|
+
readonly rows: TRows;
|
|
2501
|
+
}
|
|
2502
|
+
declare function fetchFirst<const TRows extends number>(rows: TRows): FetchClause<TRows>;
|
|
2503
|
+
declare function fetchNext<const TRows extends number>(rows: TRows): FetchClause<TRows>;
|
|
2504
|
+
//#endregion
|
|
2505
|
+
//#region src/query/clauses/row-lock.d.ts
|
|
2506
|
+
interface RowLockOptions<TMode extends RowLockMode = RowLockMode, TWait extends RowLockWaitPolicy = RowLockWaitPolicy> {
|
|
2507
|
+
readonly mode?: TMode;
|
|
2508
|
+
readonly wait?: TWait;
|
|
2509
|
+
readonly waitPolicy?: TWait;
|
|
2510
|
+
}
|
|
2511
|
+
interface RowLockClause<TMode extends RowLockMode = RowLockMode, TWait extends RowLockWaitPolicy = RowLockWaitPolicy> extends SelectClause<RequiresCapabilityMeta<"row-locking">> {
|
|
2512
|
+
readonly clauseKind: "row-lock";
|
|
2513
|
+
readonly mode: TMode;
|
|
2514
|
+
readonly wait: TWait;
|
|
2515
|
+
}
|
|
2516
|
+
declare function rowLock(): RowLockClause<"update", "default">;
|
|
2517
|
+
declare function rowLock<TMode extends RowLockMode>(mode: TMode): RowLockClause<TMode, "default">;
|
|
2518
|
+
declare function rowLock<TMode extends RowLockMode, TWait extends RowLockWaitPolicy>(mode: TMode, wait: TWait): RowLockClause<TMode, TWait>;
|
|
2519
|
+
declare function rowLock(options: RowLockOptions): RowLockClause;
|
|
2520
|
+
//#endregion
|
|
2521
|
+
//#region src/query/clauses/where.d.ts
|
|
2522
|
+
interface WhereClause<TMetadata = never> extends SelectClause<TMetadata> {
|
|
2523
|
+
readonly clauseKind: "where";
|
|
2524
|
+
readonly condition: BooleanExpression<any>;
|
|
2525
|
+
}
|
|
2526
|
+
type WhereComposition<TCondition extends BooleanExpression<any> | Omit$1> = TCondition extends Omit$1 ? Omit$1 : TCondition extends BooleanExpression<any> ? WhereClause<InheritedMetadata<TCondition>> : never;
|
|
2527
|
+
type WhereValidation<TCondition> = TCondition extends Omit$1 ? unknown : SqlCapabilityValidation<ExpressionSqlType<TCondition>, SqlBoolean>;
|
|
2528
|
+
declare function where<TCondition extends BooleanExpression<any> | Omit$1>(condition: TCondition & WhereValidation<TCondition>): WhereComposition<TCondition>;
|
|
2529
|
+
//#endregion
|
|
2530
|
+
//#region src/query/omit.d.ts
|
|
2531
|
+
/** An explicit placeholder for a safely omitted SELECT clause or projection field. */
|
|
2532
|
+
declare const omit: unique symbol;
|
|
2533
|
+
type Omit$1 = typeof omit;
|
|
2534
|
+
type OmittableSelectClause = DistinctClause | HavingClause<any> | OrderByClause<any> | OffsetClause | FetchClause | RowLockClause | WhereClause<any>;
|
|
2535
|
+
type SelectPart = AnySelectClause | Omit$1;
|
|
2536
|
+
type PresentClauses<TParts extends readonly SelectPart[]> = { readonly [TIndex in keyof TParts]: Exclude<TParts[TIndex], Omit$1>; };
|
|
2537
|
+
type InvalidOmittedClauses<TParts extends readonly SelectPart[]> = { [TIndex in keyof TParts]: Omit$1 extends TParts[TIndex] ? Exclude<TParts[TIndex], Omit$1> extends OmittableSelectClause ? never : Exclude<TParts[TIndex], Omit$1> : never; }[number];
|
|
2538
|
+
type OmissionValidation<TParts extends readonly SelectPart[]> = [InvalidOmittedClauses<TParts>] extends [never] ? unknown : QueryTypeValidation<"invalid-omission", "select.omit", "Use omit only for a conditional SELECT clause or projection field.", InvalidOmittedClauses<TParts>>;
|
|
2539
|
+
//#endregion
|
|
2540
|
+
//#region src/expressions/operators/logic.d.ts
|
|
2541
|
+
type BooleanOperand = BooleanExpression<any> | Omit$1;
|
|
2542
|
+
type PresentConditions<TConditions extends readonly BooleanOperand[]> = Exclude<TConditions[number], Omit$1>;
|
|
2543
|
+
type BooleanComposition<TConditions extends readonly BooleanOperand[]> = [PresentConditions<TConditions>] extends [never] ? Omit$1 : ResultExpression<{
|
|
2544
|
+
readonly output: boolean;
|
|
2545
|
+
readonly children: PresentConditions<TConditions>;
|
|
2546
|
+
readonly kind: "operator";
|
|
2547
|
+
readonly nullableFrom: NullabilityOf<PresentConditions<TConditions>>;
|
|
2548
|
+
readonly sqlType: SqlBoolean;
|
|
2549
|
+
}> | (Omit$1 extends TConditions[number] ? Omit$1 : never);
|
|
2550
|
+
type BooleanConditionsValidation<TConditions extends readonly unknown[]> = TConditions extends readonly [infer THead, ...infer TTail] ? (THead extends Omit$1 ? unknown : SqlCapabilityValidation<ExpressionSqlType<THead>, SqlBoolean>) & BooleanConditionsValidation<TTail> : unknown;
|
|
2551
|
+
declare function and<const TConditions extends readonly BooleanOperand[]>(...conditions: TConditions & BooleanConditionsValidation<TConditions>): BooleanComposition<TConditions>;
|
|
2552
|
+
declare function or<const TConditions extends readonly BooleanOperand[]>(...conditions: TConditions & BooleanConditionsValidation<TConditions>): BooleanComposition<TConditions>;
|
|
2553
|
+
declare function not<TCondition extends BooleanExpression<any>>(condition: TCondition & SqlCapabilityValidation<ExpressionSqlType<TCondition>, SqlBoolean>): ResultExpression<{
|
|
2554
|
+
readonly output: boolean;
|
|
2555
|
+
readonly children: TCondition;
|
|
2556
|
+
readonly kind: "operator";
|
|
2557
|
+
readonly nullableFrom: NullabilityOf<TCondition>;
|
|
2558
|
+
readonly sqlType: SqlBoolean;
|
|
2559
|
+
}>;
|
|
2560
|
+
//#endregion
|
|
2561
|
+
//#region src/schema/column-nullability.d.ts
|
|
2562
|
+
declare const declaredColumnNullability: unique symbol;
|
|
2563
|
+
/** Compile-time nullability retained by a column from its table declaration. */
|
|
2564
|
+
type DeclaredColumnNullability<TNullable extends boolean> = {
|
|
2565
|
+
readonly [declaredColumnNullability]: TNullable;
|
|
2566
|
+
};
|
|
2567
|
+
/** @internal */
|
|
2568
|
+
type DeclaredColumnNullabilityOf<TColumn> = TColumn extends DeclaredColumnNullability<infer TNullable> ? TNullable : never;
|
|
2569
|
+
//#endregion
|
|
2570
|
+
//#region src/schema/indexes.d.ts
|
|
2571
|
+
type IndexTerm = AnyExpression | OrderTerm<any>;
|
|
2572
|
+
/** PostgreSQL-specific index method and storage metadata. */
|
|
2573
|
+
interface PostgresIndexExtension extends SchemaDialectExtension<"postgresql"> {
|
|
2574
|
+
readonly method?: "btree" | "hash" | "gist" | "spgist" | "gin" | "brin";
|
|
2575
|
+
readonly concurrently?: boolean;
|
|
2576
|
+
readonly operatorClasses?: Readonly<Record<string, string>>;
|
|
2577
|
+
readonly storageParameters?: Readonly<Record<string, string | number | boolean>>;
|
|
2726
2578
|
}
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
interface DistinctClause extends SelectClause<never> {
|
|
2731
|
-
readonly clauseKind: 'distinct';
|
|
2579
|
+
/** SQLite-specific index metadata retained for a future adapter. */
|
|
2580
|
+
interface SqliteIndexExtension extends SchemaDialectExtension<"sqlite"> {
|
|
2581
|
+
readonly auto?: boolean;
|
|
2732
2582
|
}
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
readonly
|
|
2738
|
-
readonly
|
|
2583
|
+
/** MySQL-specific index algorithm, locking, and parser metadata. */
|
|
2584
|
+
interface MysqlIndexExtension extends SchemaDialectExtension<"mysql"> {
|
|
2585
|
+
readonly algorithm?: "default" | "inplace" | "copy";
|
|
2586
|
+
readonly lock?: "default" | "none" | "shared" | "exclusive";
|
|
2587
|
+
readonly using?: "btree" | "hash" | "rtree";
|
|
2588
|
+
readonly parser?: string;
|
|
2589
|
+
readonly keyBlockSize?: number;
|
|
2739
2590
|
}
|
|
2740
|
-
|
|
2741
|
-
type
|
|
2742
|
-
|
|
2591
|
+
/** First-party and user-defined dialect extensions for indexes. */
|
|
2592
|
+
type IndexDialectExtension = PostgresIndexExtension | SqliteIndexExtension | MysqlIndexExtension | (SchemaDialectExtension<string> & Readonly<Record<string, unknown>>);
|
|
2593
|
+
interface IndexOptions<TPredicate extends AnyExpression | undefined = AnyExpression | undefined, TExtension extends IndexDialectExtension | undefined = IndexDialectExtension | undefined> extends SchemaObjectNameOptions {
|
|
2594
|
+
readonly unique?: boolean;
|
|
2595
|
+
readonly where?: TPredicate;
|
|
2596
|
+
/** Columns stored in the index payload but not used as key terms. */
|
|
2597
|
+
readonly include?: readonly ColumnReference<string, any>[];
|
|
2598
|
+
/** Typed engine-specific index options. */
|
|
2599
|
+
readonly dialect?: TExtension;
|
|
2600
|
+
}
|
|
2601
|
+
type IndexTermExpression$2<TTerm> = TTerm extends OrderTerm<any> ? TTerm["expression"] : TTerm;
|
|
2602
|
+
type IsNullableIndexColumn<TColumn> = [DeclaredColumnNullabilityOf<TColumn>] extends [never] ? null extends OutputOf<TColumn> ? true : false : true extends DeclaredColumnNullabilityOf<TColumn> ? true : false;
|
|
2603
|
+
type IsEligibleColumn<TTerm> = IndexTermExpression$2<TTerm> extends (infer TExpression) ? TExpression extends ColumnReference<string, any> ? IsNullableIndexColumn<TExpression> extends true ? false : true : false : false;
|
|
2604
|
+
type AllEligibleColumns<TTerms extends readonly IndexTerm[]> = { [K in keyof TTerms]: IsEligibleColumn<TTerms[K]>; }[number] extends (infer TEligibility) ? false extends TEligibility ? true extends TEligibility ? boolean : false : true : false;
|
|
2605
|
+
type BooleanOption<TValue> = [Extract<TValue, true>] extends [never] ? false : [Exclude<TValue, true>] extends [never] ? true : boolean;
|
|
2606
|
+
type UniqueOption<TOptions> = "unique" extends keyof TOptions ? BooleanOption<TOptions["unique"]> : false;
|
|
2607
|
+
type PredicateOption<TOptions> = "where" extends keyof TOptions ? TOptions["where"] : undefined;
|
|
2608
|
+
type DialectOption<TOptions> = TOptions extends {
|
|
2609
|
+
readonly dialect?: infer TDialect;
|
|
2610
|
+
} ? unknown extends TDialect ? IndexDialectExtension | undefined : TDialect : undefined;
|
|
2611
|
+
type PredicatePresence<TOptions> = [Exclude<PredicateOption<TOptions>, undefined>] extends [never] ? false : undefined extends PredicateOption<TOptions> ? boolean : true;
|
|
2612
|
+
type IsCandidateKey<TTerms extends readonly IndexTerm[], TOptions extends IndexOptions<any>> = UniqueOption<TOptions> extends (infer TUnique) ? PredicatePresence<TOptions> extends (infer THasPredicate) ? AllEligibleColumns<TTerms> extends (infer TEligible) ? TUnique extends false ? false : THasPredicate extends true ? false : TEligible extends false ? false : TUnique extends true ? THasPredicate extends false ? TEligible extends true ? true : boolean : boolean : boolean : false : false : false;
|
|
2613
|
+
/** Portable index metadata retained by a table and its aliases. */
|
|
2614
|
+
interface TableIndex<TTerms extends readonly IndexTerm[] = any, TOptions extends IndexOptions<any> = any> extends SchemaObjectIdentity {
|
|
2615
|
+
readonly kind: "index";
|
|
2616
|
+
readonly terms: TTerms;
|
|
2617
|
+
readonly unique: UniqueOption<TOptions>;
|
|
2618
|
+
readonly predicate: PredicateOption<TOptions>;
|
|
2619
|
+
readonly includedColumns?: TOptions extends {
|
|
2620
|
+
readonly include: infer TIncluded;
|
|
2621
|
+
} ? TIncluded : undefined;
|
|
2622
|
+
readonly dialect?: DialectOption<TOptions>;
|
|
2623
|
+
readonly candidateKey: IsCandidateKey<TTerms, TOptions>;
|
|
2624
|
+
}
|
|
2625
|
+
/** The widened index shape accepted by source metadata records. */
|
|
2626
|
+
interface SourceIndex {
|
|
2627
|
+
readonly kind: "index";
|
|
2628
|
+
readonly terms: readonly IndexTerm[];
|
|
2629
|
+
readonly unique: boolean;
|
|
2630
|
+
readonly predicate: AnyExpression | undefined;
|
|
2631
|
+
readonly includedColumns?: readonly ColumnReference<string, any>[];
|
|
2632
|
+
readonly dialect?: IndexDialectExtension;
|
|
2633
|
+
readonly candidateKey: boolean;
|
|
2634
|
+
}
|
|
2635
|
+
type SourceIndexesRecord = Readonly<Record<string, SourceIndex>>;
|
|
2636
|
+
/**
|
|
2637
|
+
* Validate portable and dialect-owned index facts for one target adapter. Unsupported features are
|
|
2638
|
+
* reported as data so a serializer can aggregate diagnostics instead of failing during traversal
|
|
2639
|
+
* with an opaque exception.
|
|
2640
|
+
*/
|
|
2641
|
+
declare function validateIndexDialect(indexMetadata: SourceIndex, dialect: string, path?: readonly (string | number)[]): readonly SchemaMetadataDiagnostic[];
|
|
2642
|
+
type ValidIndexExpression<T> = T extends AnyExpression ? HasAggregate<T> extends true ? never : HasWindow<T> extends true ? never : HasSubquery<T> extends true ? never : unknown : never;
|
|
2643
|
+
type InvalidIndexTerms<TTerms extends readonly IndexTerm[]> = { [K in keyof TTerms]: TTerms[K] extends OrderTerm<any> ? TTerms[K] extends {
|
|
2644
|
+
readonly nulls: "FIRST" | "LAST";
|
|
2645
|
+
} ? TTerms[K] : ValidIndexExpression<TTerms[K]["expression"]> extends never ? TTerms[K] : never : ValidIndexExpression<TTerms[K]> extends never ? TTerms[K] : never; }[number];
|
|
2646
|
+
type IndexTermsValidation<TTerms extends readonly IndexTerm[]> = [InvalidIndexTerms<TTerms>] extends [never] ? unknown : never;
|
|
2647
|
+
/** Declare a portable column or expression index. */
|
|
2648
|
+
declare function index<const TTerms extends readonly [IndexTerm, ...IndexTerm[]], const TOptions extends IndexOptions<any> = {}>(terms: TTerms & IndexTermsValidation<NoInfer<TTerms>>, options?: TOptions): TableIndex<TTerms, TOptions>;
|
|
2743
2649
|
//#endregion
|
|
2744
|
-
//#region src/
|
|
2745
|
-
|
|
2746
|
-
readonly
|
|
2747
|
-
|
|
2650
|
+
//#region src/schema/alias.d.ts
|
|
2651
|
+
type SourceIndexes$1<T> = T extends {
|
|
2652
|
+
readonly indexes: infer TIndexes extends SourceIndexesRecord;
|
|
2653
|
+
} ? TIndexes : {};
|
|
2654
|
+
type AliasIdentity<TBase, TAlias extends string> = {
|
|
2655
|
+
readonly sourceKind: "alias";
|
|
2656
|
+
readonly alias: TAlias;
|
|
2657
|
+
readonly base: TBase;
|
|
2658
|
+
};
|
|
2659
|
+
type AliasedSource<TBase extends Source<any>, TAlias extends string> = Source<{
|
|
2660
|
+
readonly identity: AliasIdentity<SourceIdentity<TBase>, TAlias>;
|
|
2661
|
+
readonly row: SourceRow<TBase>;
|
|
2662
|
+
readonly metadata: RequiresOuterMetadataOf<TBase> | CapabilityMetadataOf<TBase>;
|
|
2663
|
+
readonly sqlTypes: SourceSqlTypeMap<TBase>;
|
|
2664
|
+
readonly constraints: SourceConstraints<TBase>;
|
|
2665
|
+
}> & {
|
|
2666
|
+
readonly alias: TAlias;
|
|
2667
|
+
readonly base: TBase;
|
|
2668
|
+
readonly columns: SourceColumns<SourceRow<TBase>, AliasIdentity<SourceIdentity<TBase>, TAlias>, SourceSqlTypeMap<TBase>>;
|
|
2669
|
+
readonly constraints: SourceConstraints<TBase>;
|
|
2670
|
+
readonly indexes: SourceIndexes$1<TBase>;
|
|
2671
|
+
} & SourceColumns<SourceRow<TBase>, AliasIdentity<SourceIdentity<TBase>, TAlias>, SourceSqlTypeMap<TBase>>;
|
|
2672
|
+
type QueryAliasIdentity<TAlias extends string> = {
|
|
2673
|
+
readonly sourceKind: "query-alias";
|
|
2674
|
+
readonly alias: TAlias;
|
|
2675
|
+
};
|
|
2676
|
+
type QuerySource<TRow extends object, TAlias extends string, TMetadata = never, TSqlTypes extends SourceSqlTypes<TRow> = UnknownSourceSqlTypes<TRow>> = Source<{
|
|
2677
|
+
readonly identity: QueryAliasIdentity<TAlias>;
|
|
2678
|
+
readonly row: TRow;
|
|
2679
|
+
readonly metadata: TMetadata;
|
|
2680
|
+
readonly sqlTypes: TSqlTypes;
|
|
2681
|
+
}> & {
|
|
2682
|
+
readonly alias: TAlias;
|
|
2683
|
+
readonly query: Query<{
|
|
2684
|
+
readonly row: TRow;
|
|
2685
|
+
readonly cardinality: any;
|
|
2686
|
+
readonly metadata: TMetadata;
|
|
2687
|
+
readonly sqlTypes: TSqlTypes;
|
|
2688
|
+
}>;
|
|
2689
|
+
readonly columns: SourceColumns<TRow, QueryAliasIdentity<TAlias>, TSqlTypes>;
|
|
2690
|
+
} & SourceColumns<TRow, QueryAliasIdentity<TAlias>, TSqlTypes>;
|
|
2691
|
+
declare function alias<TBase extends Source<any>, const TAlias extends string>(source: TBase, name: TAlias): AliasedSource<TBase, TAlias>;
|
|
2692
|
+
declare function alias<TQuery extends AnyQuery, const TAlias extends string>(query: TQuery, name: TAlias): QuerySource<QueryRow<TQuery>, TAlias, RequiresOuterMetadataOf<TQuery> | CapabilityMetadataOf<TQuery>, QuerySqlTypeMap<TQuery>>;
|
|
2693
|
+
type LateralIdentity<TAlias extends string> = {
|
|
2694
|
+
readonly sourceKind: "lateral";
|
|
2695
|
+
readonly alias: TAlias;
|
|
2696
|
+
};
|
|
2697
|
+
type LateralSource<TQuery extends AnyQuery, TAlias extends string> = Source<{
|
|
2698
|
+
readonly identity: LateralIdentity<TAlias>;
|
|
2699
|
+
readonly row: QueryRow<TQuery>;
|
|
2700
|
+
readonly metadata: RequiresOuterMetadataOf<TQuery> | CapabilityMetadataOf<TQuery>;
|
|
2701
|
+
readonly sqlTypes: QuerySqlTypeMap<TQuery>;
|
|
2702
|
+
}> & {
|
|
2703
|
+
readonly alias: TAlias;
|
|
2704
|
+
readonly query: TQuery;
|
|
2705
|
+
readonly columns: SourceColumns<QueryRow<TQuery>, LateralIdentity<TAlias>, QuerySqlTypeMap<TQuery>>;
|
|
2706
|
+
} & SourceColumns<QueryRow<TQuery>, LateralIdentity<TAlias>, QuerySqlTypeMap<TQuery>>;
|
|
2707
|
+
/** Render a query as a LATERAL source whose outer requirements stay visible. */
|
|
2708
|
+
declare function lateral<TQuery extends AnyQuery, const TAlias extends string>(query: TQuery, name: TAlias): LateralSource<TQuery, TAlias>;
|
|
2709
|
+
//#endregion
|
|
2710
|
+
//#region src/schema/constraints.d.ts
|
|
2711
|
+
declare const fieldConstraint: unique symbol;
|
|
2712
|
+
/** Application and SQL facts that a reusable source field may require. */
|
|
2713
|
+
interface FieldLikeOptions {
|
|
2714
|
+
readonly output?: unknown;
|
|
2715
|
+
readonly sqlType?: object;
|
|
2716
|
+
readonly nullable?: boolean;
|
|
2748
2717
|
}
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
readonly
|
|
2718
|
+
/**
|
|
2719
|
+
* A reusable source-field requirement combining application and SQL facts. Omitted facts impose no
|
|
2720
|
+
* constraint; `nullable: false` requires a non-null selected value.
|
|
2721
|
+
*/
|
|
2722
|
+
interface FieldLike<TOptions extends FieldLikeOptions = FieldLikeOptions> {
|
|
2723
|
+
readonly [fieldConstraint]: TOptions;
|
|
2724
|
+
}
|
|
2725
|
+
type FieldOptions<T> = T extends FieldLike<infer TOptions> ? TOptions : never;
|
|
2726
|
+
type RequiredOutput<T> = T extends FieldLike<any> ? FieldOptions<T> extends {
|
|
2727
|
+
readonly output: infer TOutput;
|
|
2728
|
+
} ? FieldOptions<T> extends {
|
|
2729
|
+
readonly nullable: false;
|
|
2730
|
+
} ? NonNullable<TOutput> : TOutput : FieldOptions<T> extends {
|
|
2731
|
+
readonly nullable: false;
|
|
2732
|
+
} ? {} : unknown : T;
|
|
2733
|
+
type RequiredSqlType<T> = T extends FieldLike<any> ? FieldOptions<T> extends {
|
|
2734
|
+
readonly sqlType: infer TSqlType;
|
|
2735
|
+
} ? (AnySqlType & TSqlType) | SqlUnknown : AnySqlType : AnySqlType;
|
|
2736
|
+
type RequiredColumn<TField extends string, TRequirement, TIdentity> = ColumnReference<TField, ResultMeta<RequiredOutput<TRequirement>, TIdentity, RequiredSqlType<TRequirement>> | RequiresSourceMeta<TIdentity> | ExpressionMeta<ColumnDependency<TIdentity, TField>>>;
|
|
2737
|
+
type RequiredColumns<TShape extends object, TIdentity> = { readonly [K in keyof TShape]-?: K extends string ? RequiredColumn<K, TShape[K], TIdentity> : never; };
|
|
2738
|
+
/**
|
|
2739
|
+
* A source containing at least the requested application and SQL fields. Additional fields and the
|
|
2740
|
+
* concrete source identity are preserved by generic functions that accept this lower-bound
|
|
2741
|
+
* constraint.
|
|
2742
|
+
*/
|
|
2743
|
+
interface SourceLike<TShape extends object> extends Fragment<any> {
|
|
2744
|
+
readonly sourceKind: SourceKind;
|
|
2745
|
+
readonly [sourceIdentity]: unknown;
|
|
2746
|
+
readonly reference: Fragment<never>;
|
|
2747
|
+
readonly columns: RequiredColumns<TShape, this[typeof sourceIdentity]>;
|
|
2748
|
+
}
|
|
2749
|
+
/** The physical-table form of the lower-bound {@link SourceLike} constraint. */
|
|
2750
|
+
interface TableLike<TShape extends object> extends SourceLike<TShape> {
|
|
2751
|
+
readonly tableName: string;
|
|
2752
|
+
readonly definitions: object;
|
|
2753
|
+
readonly sqlNames: Readonly<Record<string, string>>;
|
|
2754
|
+
}
|
|
2755
|
+
/** Standard SQL referential action retained on a foreign-key constraint. */
|
|
2756
|
+
type ReferentialAction = "no-action" | "restrict" | "cascade" | "set-null" | "set-default";
|
|
2757
|
+
/** Standard SQL match mode for a composite foreign key. */
|
|
2758
|
+
type ForeignKeyMatch = "simple" | "full" | "partial";
|
|
2759
|
+
/** Deferrability timing for a foreign-key or key constraint. */
|
|
2760
|
+
type ConstraintTiming = "immediate" | "deferred";
|
|
2761
|
+
/** PostgreSQL-only constraint options retained for a schema adapter. */
|
|
2762
|
+
interface PostgresConstraintExtension extends SchemaDialectExtension<"postgresql"> {
|
|
2763
|
+
/** PostgreSQL `NOT VALID` validation state for a constraint. */
|
|
2764
|
+
readonly notValid?: boolean;
|
|
2765
|
+
}
|
|
2766
|
+
/** SQLite-only table-constraint options. */
|
|
2767
|
+
interface SqliteConstraintExtension extends SchemaDialectExtension<"sqlite"> {
|
|
2768
|
+
/** SQLite conflict policy attached to a table constraint. */
|
|
2769
|
+
readonly onConflict?: "rollback" | "abort" | "fail" | "ignore" | "replace";
|
|
2770
|
+
}
|
|
2771
|
+
/** MySQL-only constraint options. */
|
|
2772
|
+
interface MysqlConstraintExtension extends SchemaDialectExtension<"mysql"> {
|
|
2773
|
+
/** MySQL 8 constraint enforcement state. */
|
|
2774
|
+
readonly enforced?: boolean;
|
|
2775
|
+
}
|
|
2776
|
+
/** First-party and user-defined dialect extensions for constraints. */
|
|
2777
|
+
type ConstraintDialectExtension = PostgresConstraintExtension | SqliteConstraintExtension | MysqlConstraintExtension | (SchemaDialectExtension<string> & Readonly<Record<string, unknown>>);
|
|
2778
|
+
/** Shared physical-name and dialect-extension options for constraints. */
|
|
2779
|
+
interface ConstraintOptions<TExtension extends ConstraintDialectExtension | undefined = ConstraintDialectExtension | undefined> extends SchemaObjectNameOptions {
|
|
2780
|
+
/** Engine-specific metadata owned by a future schema adapter. */
|
|
2781
|
+
readonly dialect?: TExtension;
|
|
2782
|
+
}
|
|
2783
|
+
/** Options for primary-key and candidate-key declarations. */
|
|
2784
|
+
interface KeyConstraintOptions<TExtension extends ConstraintDialectExtension | undefined = ConstraintDialectExtension | undefined> extends ConstraintOptions<TExtension> {
|
|
2785
|
+
/** Whether the key can be deferred by a supporting dialect. */
|
|
2786
|
+
readonly deferrable?: boolean;
|
|
2787
|
+
/** Initial enforcement timing for a deferrable key. */
|
|
2788
|
+
readonly initially?: ConstraintTiming;
|
|
2789
|
+
}
|
|
2790
|
+
/** Options for a database unique constraint, including nullable columns. */
|
|
2791
|
+
interface UniqueConstraintOptions<TExtension extends ConstraintDialectExtension | undefined = ConstraintDialectExtension | undefined> extends ConstraintOptions<TExtension> {
|
|
2792
|
+
/**
|
|
2793
|
+
* SQL NULL comparison semantics. `distinct` is the common default in which multiple NULL values
|
|
2794
|
+
* do not conflict; `not-distinct` permits at most one.
|
|
2795
|
+
*/
|
|
2796
|
+
readonly nulls?: UniqueNullSemantics;
|
|
2797
|
+
/** Whether the constraint can be deferred by a supporting dialect. */
|
|
2798
|
+
readonly deferrable?: boolean;
|
|
2799
|
+
/** Initial enforcement timing for a deferrable constraint. */
|
|
2800
|
+
readonly initially?: ConstraintTiming;
|
|
2801
|
+
}
|
|
2802
|
+
/** Explicit NULL behavior for a database uniqueness rule. */
|
|
2803
|
+
type UniqueNullSemantics = "distinct" | "not-distinct";
|
|
2804
|
+
/** Options for a table check constraint. */
|
|
2805
|
+
interface CheckConstraintOptions<TExtension extends ConstraintDialectExtension | undefined = ConstraintDialectExtension | undefined> extends ConstraintOptions<TExtension> {
|
|
2806
|
+
/** Whether the check can be deferred by a supporting dialect. */
|
|
2807
|
+
readonly deferrable?: boolean;
|
|
2808
|
+
/** Initial enforcement timing for a deferrable check. */
|
|
2809
|
+
readonly initially?: ConstraintTiming;
|
|
2810
|
+
}
|
|
2811
|
+
/** Dialect tag and parameter-free SQL needed to reconstruct a catalog check. */
|
|
2812
|
+
interface CatalogCheckSql<TDialect extends SchemaDialectName = SchemaDialectName> {
|
|
2813
|
+
/** Catalog dialect that supplied the check expression. */
|
|
2814
|
+
readonly dialect: TDialect;
|
|
2815
|
+
/** Opaque SQL text recovered from the catalog. */
|
|
2816
|
+
readonly sql: string;
|
|
2817
|
+
}
|
|
2818
|
+
/** Options for a foreign-key declaration. */
|
|
2819
|
+
interface ForeignKeyOptions<TExtension extends ConstraintDialectExtension | undefined = ConstraintDialectExtension | undefined> extends ConstraintOptions<TExtension> {
|
|
2820
|
+
readonly onUpdate?: ReferentialAction;
|
|
2821
|
+
readonly onDelete?: ReferentialAction;
|
|
2822
|
+
readonly match?: ForeignKeyMatch;
|
|
2823
|
+
readonly deferrable?: boolean;
|
|
2824
|
+
readonly initially?: ConstraintTiming;
|
|
2825
|
+
}
|
|
2826
|
+
/** A schema constraint whose columns form a relational key. */
|
|
2827
|
+
interface KeyConstraint<TKind extends "primary-key" | "unique" = "primary-key" | "unique", TColumns extends readonly ColumnReference<string, any>[] = readonly ColumnReference<string, any>[]> extends SchemaObjectIdentity {
|
|
2828
|
+
readonly kind: TKind;
|
|
2829
|
+
readonly columns: TColumns;
|
|
2830
|
+
readonly physicalName?: string;
|
|
2831
|
+
readonly dialect?: ConstraintDialectExtension;
|
|
2832
|
+
readonly deferrable?: boolean;
|
|
2833
|
+
readonly initially?: ConstraintTiming;
|
|
2834
|
+
}
|
|
2835
|
+
/** A referenced table and exact candidate-key column tuple. */
|
|
2836
|
+
interface ForeignKeyTarget<TTable extends TableLike<any> = TableLike<any>, TColumns extends readonly AnyKeyColumn[] = readonly AnyKeyColumn[]> {
|
|
2837
|
+
readonly table: TTable;
|
|
2838
|
+
readonly columns: TColumns;
|
|
2839
|
+
}
|
|
2840
|
+
type ForeignKeyTargetInput<TTarget extends ForeignKeyTarget = ForeignKeyTarget> = TTarget | (() => TTarget);
|
|
2841
|
+
/** A foreign key from local columns to a direct or lazily resolved target. */
|
|
2842
|
+
interface ForeignKeyConstraint<TColumns extends readonly AnyKeyColumn[] = readonly AnyKeyColumn[], TTarget extends ForeignKeyTargetInput = ForeignKeyTargetInput> extends SchemaObjectIdentity {
|
|
2843
|
+
readonly kind: "foreign-key";
|
|
2844
|
+
readonly columns: TColumns;
|
|
2845
|
+
readonly target: TTarget;
|
|
2846
|
+
readonly physicalName?: string;
|
|
2847
|
+
readonly dialect?: ConstraintDialectExtension;
|
|
2848
|
+
readonly onUpdate?: ReferentialAction;
|
|
2849
|
+
readonly onDelete?: ReferentialAction;
|
|
2850
|
+
readonly match?: ForeignKeyMatch;
|
|
2851
|
+
readonly deferrable?: boolean;
|
|
2852
|
+
readonly initially?: ConstraintTiming;
|
|
2755
2853
|
}
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
readonly
|
|
2762
|
-
readonly
|
|
2763
|
-
readonly
|
|
2854
|
+
/** Database uniqueness that deliberately does not prove a candidate key. */
|
|
2855
|
+
interface UniqueConstraint<TColumns extends readonly AnyKeyColumn[] = readonly AnyKeyColumn[], TNulls extends UniqueNullSemantics = UniqueNullSemantics> extends SchemaObjectIdentity {
|
|
2856
|
+
readonly kind: "unique-constraint";
|
|
2857
|
+
readonly columns: TColumns;
|
|
2858
|
+
readonly nulls: TNulls;
|
|
2859
|
+
readonly physicalName?: string;
|
|
2860
|
+
readonly dialect?: ConstraintDialectExtension;
|
|
2861
|
+
readonly deferrable?: boolean;
|
|
2862
|
+
readonly initially?: ConstraintTiming;
|
|
2764
2863
|
}
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
readonly
|
|
2768
|
-
readonly
|
|
2864
|
+
/** A table-scoped boolean invariant. */
|
|
2865
|
+
interface CheckConstraint<TExpression extends AnyExpression = AnyExpression> extends SchemaObjectIdentity {
|
|
2866
|
+
readonly kind: "check";
|
|
2867
|
+
readonly expression: TExpression;
|
|
2868
|
+
readonly physicalName?: string;
|
|
2869
|
+
readonly dialect?: ConstraintDialectExtension;
|
|
2870
|
+
readonly deferrable?: boolean;
|
|
2871
|
+
readonly initially?: ConstraintTiming;
|
|
2769
2872
|
}
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
readonly clauseKind: 'where';
|
|
2778
|
-
readonly condition: BooleanExpression<any>;
|
|
2873
|
+
/**
|
|
2874
|
+
* Opaque catalog SQL whose check-constraint origin proves a boolean SQL semantic type. The
|
|
2875
|
+
* expression remains dialect-tagged and parameter-free.
|
|
2876
|
+
*/
|
|
2877
|
+
interface CatalogCheckExpression<TDialect extends SchemaDialectName = SchemaDialectName> extends SchemaExpression<ResultMeta<boolean, never, SqlBoolean> | ExpressionMeta<never>, "unsafe"> {
|
|
2878
|
+
readonly schemaSqlDialect: TDialect;
|
|
2879
|
+
readonly schemaSql: string;
|
|
2779
2880
|
}
|
|
2780
|
-
|
|
2781
|
-
type
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
type
|
|
2791
|
-
type
|
|
2792
|
-
type
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
type
|
|
2796
|
-
type
|
|
2797
|
-
type
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
declare function
|
|
2807
|
-
declare function
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
type
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
}> & {
|
|
2847
|
-
readonly alias: TAlias;
|
|
2848
|
-
readonly query: Query$1<{
|
|
2849
|
-
readonly row: TRow;
|
|
2850
|
-
readonly cardinality: any;
|
|
2851
|
-
readonly metadata: TMetadata;
|
|
2852
|
-
readonly sqlTypes: TSqlTypes;
|
|
2853
|
-
}>;
|
|
2854
|
-
readonly columns: SourceColumns<TRow, QueryAliasIdentity<TAlias>, TSqlTypes>;
|
|
2855
|
-
} & SourceColumns<TRow, QueryAliasIdentity<TAlias>, TSqlTypes>;
|
|
2856
|
-
declare function alias<TBase extends Source<any>, const TAlias extends string>(source: TBase, name: TAlias): AliasedSource<TBase, TAlias>;
|
|
2857
|
-
declare function alias<TQuery extends AnyQuery, const TAlias extends string>(query: TQuery, name: TAlias): QuerySource<QueryRow<TQuery>, TAlias, RequiresOuterMetadataOf<TQuery> | CapabilityMetadataOf<TQuery>, QuerySqlTypeMap<TQuery>>;
|
|
2858
|
-
type LateralIdentity<TAlias extends string> = {
|
|
2859
|
-
readonly sourceKind: 'lateral';
|
|
2860
|
-
readonly alias: TAlias;
|
|
2861
|
-
};
|
|
2862
|
-
type LateralSource<TQuery extends AnyQuery, TAlias extends string> = Source<{
|
|
2863
|
-
readonly identity: LateralIdentity<TAlias>;
|
|
2864
|
-
readonly row: QueryRow<TQuery>;
|
|
2865
|
-
readonly metadata: RequiresOuterMetadataOf<TQuery> | CapabilityMetadataOf<TQuery>;
|
|
2866
|
-
readonly sqlTypes: QuerySqlTypeMap<TQuery>;
|
|
2867
|
-
}> & {
|
|
2868
|
-
readonly alias: TAlias;
|
|
2869
|
-
readonly query: TQuery;
|
|
2870
|
-
readonly columns: SourceColumns<QueryRow<TQuery>, LateralIdentity<TAlias>, QuerySqlTypeMap<TQuery>>;
|
|
2871
|
-
} & SourceColumns<QueryRow<TQuery>, LateralIdentity<TAlias>, QuerySqlTypeMap<TQuery>>;
|
|
2872
|
-
/** Render a query as a LATERAL source whose outer requirements stay visible. */
|
|
2873
|
-
declare function lateral<TQuery extends AnyQuery, const TAlias extends string>(query: TQuery, name: TAlias): LateralSource<TQuery, TAlias>;
|
|
2881
|
+
/** Structured schema metadata carried by sources that declare constraints. */
|
|
2882
|
+
type SourceConstraint = KeyConstraint | UniqueConstraint | ForeignKeyConstraint | CheckConstraint;
|
|
2883
|
+
/** Named schema constraints attached to a source. */
|
|
2884
|
+
type SourceConstraintsRecord = Readonly<Record<string, SourceConstraint>>;
|
|
2885
|
+
/**
|
|
2886
|
+
* Validate one constraint against a schema adapter dialect. This is kept separate from construction
|
|
2887
|
+
* because the same declaration can be inspected for more than one target dialect before a
|
|
2888
|
+
* serializer is selected.
|
|
2889
|
+
*/
|
|
2890
|
+
declare function validateConstraintDialect(constraint: SourceConstraint, dialect: string, path?: readonly (string | number)[]): readonly SchemaMetadataDiagnostic[];
|
|
2891
|
+
type AnyKeyColumn = ColumnReference<string, any>;
|
|
2892
|
+
type ColumnSource<TColumn> = DependenciesOf<TColumn> extends ColumnDependency<infer TSource, string> ? TSource : never;
|
|
2893
|
+
type IsNullableKeyColumn<TColumn> = [DeclaredColumnNullabilityOf<TColumn>] extends [never] ? null extends OutputOf<TColumn> ? true : false : true extends DeclaredColumnNullabilityOf<TColumn> ? true : false;
|
|
2894
|
+
type InvalidKeyColumn<TColumn, TSource> = TColumn extends AnyKeyColumn ? IsNullableKeyColumn<TColumn> extends true ? TColumn : DependenciesOf<TColumn> extends ColumnDependency<TSource, string> ? never : TColumn : TColumn;
|
|
2895
|
+
type KeyColumnsValidation<TColumns extends readonly AnyKeyColumn[]> = [{ [K in keyof TColumns]: InvalidKeyColumn<TColumns[K], ColumnSource<TColumns[0]>>; }[number]] extends [never] ? unknown : never;
|
|
2896
|
+
type SameSourceColumnsValidation<TColumns extends readonly AnyKeyColumn[]> = [{ [K in keyof TColumns]: TColumns[K] extends AnyKeyColumn ? DependenciesOf<TColumns[K]> extends ColumnDependency<ColumnSource<TColumns[0]>, string> ? never : TColumns[K] : TColumns[K]; }[number]] extends [never] ? unknown : never;
|
|
2897
|
+
type SameSqlDomain<TLeft, TRight> = SqlTypeOf<TLeft> extends (infer TLeftSql) ? SqlTypeOf<TRight> extends (infer TRightSql) ? TLeftSql extends SqlUnknown ? false : TRightSql extends SqlUnknown ? false : TLeftSql extends AnySqlType ? TRightSql extends AnySqlType ? string extends TLeftSql["sqlType"] ? false : string extends TRightSql["sqlType"] ? false : [TLeftSql["sqlType"]] extends [TRightSql["sqlType"]] ? [TRightSql["sqlType"]] extends [TLeftSql["sqlType"]] ? true : false : false : false : false : false : false;
|
|
2898
|
+
type ForeignKeyColumnsValidation<TLocal extends readonly AnyKeyColumn[], TTarget extends readonly AnyKeyColumn[]> = TLocal extends readonly [infer TLocalHead, ...infer TLocalTail] ? TTarget extends readonly [infer TTargetHead, ...infer TTargetTail] ? TLocalHead extends AnyKeyColumn ? TTargetHead extends AnyKeyColumn ? SameSqlDomain<TLocalHead, TTargetHead> extends true ? ForeignKeyColumnsValidation<Extract<TLocalTail, readonly AnyKeyColumn[]>, Extract<TTargetTail, readonly AnyKeyColumn[]>> : never : never : never : never : TTarget extends readonly [] ? unknown : never;
|
|
2899
|
+
type IsUnresolvedSqlDomain<TSqlType> = TSqlType extends SqlUnknown ? true : TSqlType extends AnySqlType ? string extends TSqlType["sqlType"] ? true : false : true;
|
|
2900
|
+
type CatalogSqlDomainCompatible<TLeft, TRight> = true extends IsUnresolvedSqlDomain<SqlTypeOf<TLeft>> | IsUnresolvedSqlDomain<SqlTypeOf<TRight>> ? true : SameSqlDomain<TLeft, TRight>;
|
|
2901
|
+
type CatalogForeignKeyColumnsValidation<TLocal extends readonly AnyKeyColumn[], TTarget extends readonly AnyKeyColumn[]> = TLocal extends readonly [infer TLocalHead, ...infer TLocalTail] ? TTarget extends readonly [infer TTargetHead, ...infer TTargetTail] ? TLocalHead extends AnyKeyColumn ? TTargetHead extends AnyKeyColumn ? CatalogSqlDomainCompatible<TLocalHead, TTargetHead> extends true ? CatalogForeignKeyColumnsValidation<Extract<TLocalTail, readonly AnyKeyColumn[]>, Extract<TTargetTail, readonly AnyKeyColumn[]>> : never : never : never : never : TTarget extends readonly [] ? unknown : never;
|
|
2902
|
+
type CheckExpressionValidation<TExpression> = [SqlTypeOf<TExpression>] extends [never] ? never : SqlTypeOf<TExpression> extends SqlBoolean ? unknown : never;
|
|
2903
|
+
/** Declare a primary key, including a composite primary key. */
|
|
2904
|
+
declare function primaryKey<const TColumns extends readonly [AnyKeyColumn, ...AnyKeyColumn[]]>(...columns: TColumns & KeyColumnsValidation<NoInfer<TColumns>>): KeyConstraint<"primary-key", TColumns>;
|
|
2905
|
+
declare function primaryKey<const TColumns extends readonly [AnyKeyColumn, ...AnyKeyColumn[]], const TOptions extends KeyConstraintOptions>(...columnsAndOptions: [...TColumns, TOptions] & KeyColumnsValidation<NoInfer<TColumns>>): KeyConstraint<"primary-key", TColumns>;
|
|
2906
|
+
/** Declare a non-null unique key, including a composite unique key. */
|
|
2907
|
+
declare function unique<const TColumns extends readonly [AnyKeyColumn, ...AnyKeyColumn[]]>(...columns: TColumns & KeyColumnsValidation<NoInfer<TColumns>>): KeyConstraint<"unique", TColumns>;
|
|
2908
|
+
declare function unique<const TColumns extends readonly [AnyKeyColumn, ...AnyKeyColumn[]], const TOptions extends KeyConstraintOptions>(...columnsAndOptions: [...TColumns, TOptions] & KeyColumnsValidation<NoInfer<TColumns>>): KeyConstraint<"unique", TColumns>;
|
|
2909
|
+
/**
|
|
2910
|
+
* Describe database uniqueness without claiming that the columns determine a row. Nullable columns
|
|
2911
|
+
* are accepted, and the NULL behavior is explicit in the returned metadata. Use {@link unique} when
|
|
2912
|
+
* a type-level key proof is intended.
|
|
2913
|
+
*/
|
|
2914
|
+
declare function uniqueConstraint<const TColumns extends readonly [AnyKeyColumn, ...AnyKeyColumn[]]>(...columns: TColumns & SameSourceColumnsValidation<NoInfer<TColumns>>): UniqueConstraint<TColumns, "distinct">;
|
|
2915
|
+
declare function uniqueConstraint<const TColumns extends readonly [AnyKeyColumn, ...AnyKeyColumn[]], const TOptions extends UniqueConstraintOptions>(...columnsAndOptions: [...TColumns, TOptions] & SameSourceColumnsValidation<NoInfer<TColumns>>): UniqueConstraint<TColumns, TOptions extends {
|
|
2916
|
+
readonly nulls: infer TNulls extends UniqueNullSemantics;
|
|
2917
|
+
} ? TNulls : "distinct">;
|
|
2918
|
+
/** Pair a table with the exact columns targeted by a foreign key. */
|
|
2919
|
+
declare function references<TTable extends TableLike<any>, const TColumns extends readonly [AnyKeyColumn, ...AnyKeyColumn[]]>(table: TTable, ...columns: TColumns): ForeignKeyTarget<TTable, TColumns>;
|
|
2920
|
+
type ResolvedTarget$1<T> = T extends (() => infer TResolved) ? TResolved : T;
|
|
2921
|
+
/** Declare a single-column or composite foreign key. */
|
|
2922
|
+
declare function foreignKey<const TColumns extends readonly [AnyKeyColumn, ...AnyKeyColumn[]], const TTarget extends ForeignKeyTargetInput, const TOptions extends ForeignKeyOptions = {}>(columns: TColumns & SameSourceColumnsValidation<NoInfer<TColumns>>, target: TTarget & (ResolvedTarget$1<TTarget> extends ForeignKeyTarget<any, infer TTargetColumns> ? ForeignKeyColumnsValidation<TColumns, TTargetColumns> : never), options?: TOptions): ForeignKeyConstraint<TColumns, TTarget>;
|
|
2923
|
+
/**
|
|
2924
|
+
* Reconstruct a foreign key proved by database catalog metadata.
|
|
2925
|
+
*
|
|
2926
|
+
* @remarks
|
|
2927
|
+
* Use this helper for generated or introspection-owned declarations when one or both native SQL
|
|
2928
|
+
* domains are unresolved. It accepts unresolved domains, but still rejects known domain
|
|
2929
|
+
* mismatches, unequal tuple arity, and local columns from different sources. The enclosing
|
|
2930
|
+
* `table()` declaration continues to verify target-column ownership and candidate-key metadata.
|
|
2931
|
+
* Resolved targets also receive runtime shape, ownership, and arity checks. The returned value
|
|
2932
|
+
* serializes as an ordinary foreign-key constraint.
|
|
2933
|
+
*/
|
|
2934
|
+
declare function catalogForeignKey<const TColumns extends readonly [AnyKeyColumn, ...AnyKeyColumn[]], const TTarget extends ForeignKeyTargetInput, const TOptions extends ForeignKeyOptions = {}>(columns: TColumns & SameSourceColumnsValidation<NoInfer<TColumns>>, target: TTarget & (ResolvedTarget$1<TTarget> extends ForeignKeyTarget<any, infer TTargetColumns> ? CatalogForeignKeyColumnsValidation<TColumns, TTargetColumns> : never), options?: TOptions): ForeignKeyConstraint<TColumns, TTarget>;
|
|
2935
|
+
/** Declare a boolean table invariant. */
|
|
2936
|
+
declare function check<const TExpression extends Expression<any, any>, const TOptions extends CheckConstraintOptions = {}>(expression: TExpression & CheckExpressionValidation<TExpression>, options?: TOptions): CheckConstraint<TExpression>;
|
|
2937
|
+
/**
|
|
2938
|
+
* Reconstruct a boolean check from opaque SQL recovered from a database catalog.
|
|
2939
|
+
*
|
|
2940
|
+
* @remarks
|
|
2941
|
+
* This helper records catalog origin as a narrow type-level proof. It gives the opaque expression
|
|
2942
|
+
* the {@link SqlBoolean} semantic type without changing the ordinary {@link check} contract. Qubu
|
|
2943
|
+
* does not parse or infer dependencies from the SQL. It preserves the text apart from normalizing
|
|
2944
|
+
* line endings and retains the dialect tag in serialized schema metadata.
|
|
2945
|
+
*/
|
|
2946
|
+
declare function catalogCheck<const TDialect extends SchemaDialectName, const TOptions extends CheckConstraintOptions = {}>(input: CatalogCheckSql<TDialect>, options?: TOptions): CheckConstraint<CatalogCheckExpression<TDialect>>;
|
|
2874
2947
|
//#endregion
|
|
2875
2948
|
//#region src/schema/registry.d.ts
|
|
2876
2949
|
/** The first naming-policy version used by schema metadata. */
|
|
@@ -2885,8 +2958,8 @@ interface SchemaNamingPolicy {
|
|
|
2885
2958
|
/**
|
|
2886
2959
|
* The built-in naming policy for schema-generated physical names.
|
|
2887
2960
|
*
|
|
2888
|
-
* Explicit names supplied to `table()` remain unchanged. The policy is used
|
|
2889
|
-
*
|
|
2961
|
+
* Explicit names supplied to `table()` remain unchanged. The policy is used by tooling when it
|
|
2962
|
+
* needs a physical name for a logical table ID.
|
|
2890
2963
|
*/
|
|
2891
2964
|
declare const defaultSchemaNamingPolicy: SchemaNamingPolicy;
|
|
2892
2965
|
/** A table record accepted by {@link schema}. */
|
|
@@ -2913,7 +2986,7 @@ type SchemaTableRegistry<TTables extends SchemaTableRecord> = { readonly [K in k
|
|
|
2913
2986
|
type SchemaTableNames<TTables extends SchemaTableRecord> = Readonly<{ [K in keyof TTables & string]: string; }>;
|
|
2914
2987
|
/** The root model returned by {@link schema}. */
|
|
2915
2988
|
interface Schema<TTables extends SchemaTableRecord = SchemaTableRecord> {
|
|
2916
|
-
readonly schemaKind:
|
|
2989
|
+
readonly schemaKind: "schema";
|
|
2917
2990
|
/** Tables keyed by stable logical ID. */
|
|
2918
2991
|
readonly tables: Readonly<TTables>;
|
|
2919
2992
|
/** Explicit registry entries with logical and physical identity separated. */
|
|
@@ -2927,7 +3000,7 @@ interface Schema<TTables extends SchemaTableRecord = SchemaTableRecord> {
|
|
|
2927
3000
|
}
|
|
2928
3001
|
/** A structured validation finding produced while constructing a schema. */
|
|
2929
3002
|
interface SchemaDiagnostic {
|
|
2930
|
-
readonly code:
|
|
3003
|
+
readonly code: "invalid-table-id" | "duplicate-table-id" | "duplicate-physical-name" | "invalid-namespace" | "generated-name-collision";
|
|
2931
3004
|
readonly message: string;
|
|
2932
3005
|
/** Location of the invalid or conflicting declaration. */
|
|
2933
3006
|
readonly path: readonly (string | number)[];
|
|
@@ -2946,18 +3019,18 @@ type EntriesToTables<TEntries extends readonly SchemaTableInput[]> = { readonly
|
|
|
2946
3019
|
/**
|
|
2947
3020
|
* Create an immutable root registry keyed by stable logical table IDs.
|
|
2948
3021
|
*
|
|
2949
|
-
* The input keys are logical IDs. Each table keeps the physical name already
|
|
2950
|
-
*
|
|
2951
|
-
*
|
|
2952
|
-
*
|
|
3022
|
+
* The input keys are logical IDs. Each table keeps the physical name already used by query
|
|
3023
|
+
* rendering, so registering a table does not change its row inference, source identity, or
|
|
3024
|
+
* generated SQL. The optional namespace is metadata for schema tooling and is not added to ordinary
|
|
3025
|
+
* query rendering.
|
|
2953
3026
|
*
|
|
2954
|
-
* @throws {@link SchemaValidationError}
|
|
2955
|
-
*
|
|
3027
|
+
* @throws {@link SchemaValidationError} When IDs, physical names, namespaces, or generated names
|
|
3028
|
+
* collide or are invalid.
|
|
2956
3029
|
*/
|
|
2957
3030
|
declare function schema<const TTables extends SchemaTableRecord>(tables: TTables, options?: SchemaOptions): Schema<TTables>;
|
|
2958
3031
|
/**
|
|
2959
|
-
* Tuple input is useful for integrations that need duplicate-ID diagnostics
|
|
2960
|
-
*
|
|
3032
|
+
* Tuple input is useful for integrations that need duplicate-ID diagnostics before converting
|
|
3033
|
+
* declarations into an object record.
|
|
2961
3034
|
*/
|
|
2962
3035
|
declare function schema<const TEntries extends readonly SchemaTableInput[]>(tables: TEntries, options?: SchemaOptions): Schema<EntriesToTables<TEntries>>;
|
|
2963
3036
|
/** Generate a v1 physical name for a logical table ID. */
|
|
@@ -2965,9 +3038,9 @@ declare function generatedTableName(logicalId: string, namingPolicy?: SchemaNami
|
|
|
2965
3038
|
//#endregion
|
|
2966
3039
|
//#region src/schema/expressions.d.ts
|
|
2967
3040
|
/** SQL declaration context in which a schema expression will be emitted. */
|
|
2968
|
-
type SchemaExpressionMode =
|
|
3041
|
+
type SchemaExpressionMode = "default" | "generated" | "check" | "index";
|
|
2969
3042
|
/** Stable error categories for schema-expression validation failures. */
|
|
2970
|
-
type SchemaExpressionErrorCode =
|
|
3043
|
+
type SchemaExpressionErrorCode = "not-deterministic" | "unsupported-expression" | "parameter" | "unsupported-value" | "column-not-allowed" | "dialect-mismatch" | "invalid-literal";
|
|
2971
3044
|
/** Error raised before a schema expression can become persisted SQL. */
|
|
2972
3045
|
declare class SchemaExpressionError extends TypeError {
|
|
2973
3046
|
readonly code: SchemaExpressionErrorCode;
|
|
@@ -2975,9 +3048,9 @@ declare class SchemaExpressionError extends TypeError {
|
|
|
2975
3048
|
constructor(code: SchemaExpressionErrorCode, message: string, mode?: SchemaExpressionMode);
|
|
2976
3049
|
}
|
|
2977
3050
|
/**
|
|
2978
|
-
* Restricted rendering surface made available to explicit schema extensions.
|
|
2979
|
-
*
|
|
2980
|
-
*
|
|
3051
|
+
* Restricted rendering surface made available to explicit schema extensions. `parameter()` is
|
|
3052
|
+
* retained for structural compatibility with query renderers, but always throws; use `literal()`
|
|
3053
|
+
* for deterministic values.
|
|
2981
3054
|
*/
|
|
2982
3055
|
interface SchemaRenderContext extends RenderContext {
|
|
2983
3056
|
readonly schemaMode: SchemaExpressionMode;
|
|
@@ -2999,30 +3072,29 @@ type SchemaExpressionInput<TExpression extends AnyExpression> = TExpression exte
|
|
|
2999
3072
|
readonly __requires_deterministic_schema_expression__: never;
|
|
3000
3073
|
};
|
|
3001
3074
|
/** A dialect-tagged raw SQL expression for syntax Qubu does not model. */
|
|
3002
|
-
interface UnsafeSchemaSqlExpression extends SchemaExpression<never,
|
|
3075
|
+
interface UnsafeSchemaSqlExpression extends SchemaExpression<never, "unsafe"> {
|
|
3003
3076
|
readonly schemaSqlDialect: string;
|
|
3004
3077
|
readonly schemaSql: string;
|
|
3005
3078
|
}
|
|
3006
3079
|
/**
|
|
3007
|
-
* Normalize only line endings. Whitespace, quoting, and every other byte of
|
|
3008
|
-
*
|
|
3080
|
+
* Normalize only line endings. Whitespace, quoting, and every other byte of a raw schema expression
|
|
3081
|
+
* remain under the extension author's control.
|
|
3009
3082
|
*/
|
|
3010
3083
|
declare function normalizeSchemaSql(sql: string): string;
|
|
3011
3084
|
/**
|
|
3012
|
-
* Explicitly opt an audited expression into deterministic schema rendering.
|
|
3013
|
-
*
|
|
3014
|
-
*
|
|
3085
|
+
* Explicitly opt an audited expression into deterministic schema rendering. The wrapper does not
|
|
3086
|
+
* rewrite the renderer; it records the author's promise so schema consumers can reject ordinary
|
|
3087
|
+
* query extensions by default.
|
|
3015
3088
|
*/
|
|
3016
|
-
declare function schemaExpression<TExpression extends AnyExpression>(expression: TExpression): SchemaExpression<MetadataOf<TExpression>, TExpression[
|
|
3089
|
+
declare function schemaExpression<TExpression extends AnyExpression>(expression: TExpression): SchemaExpression<MetadataOf<TExpression>, TExpression["expressionKind"]>;
|
|
3017
3090
|
/**
|
|
3018
|
-
* Define an extension with the restricted schema context. This is the typed
|
|
3019
|
-
*
|
|
3091
|
+
* Define an extension with the restricted schema context. This is the typed alternative to
|
|
3092
|
+
* {@link unsafeSchemaSql} for deterministic custom syntax.
|
|
3020
3093
|
*/
|
|
3021
|
-
declare function defineSchemaExpression<TMetadata = never, TKind extends ExpressionKind =
|
|
3094
|
+
declare function defineSchemaExpression<TMetadata = never, TKind extends ExpressionKind = "function">(kind: TKind, render: (context: SchemaRenderContext) => void): SchemaExpression<TMetadata, TKind>;
|
|
3022
3095
|
/**
|
|
3023
|
-
* Create a dialect-specific raw schema expression. The SQL is parameter-free
|
|
3024
|
-
*
|
|
3025
|
-
* normalization.
|
|
3096
|
+
* Create a dialect-specific raw schema expression. The SQL is parameter-free by contract and is
|
|
3097
|
+
* preserved exactly apart from CRLF/CR line-ending normalization.
|
|
3026
3098
|
*/
|
|
3027
3099
|
declare function unsafeSchemaSql(dialect: string, sql: string): UnsafeSchemaSqlExpression;
|
|
3028
3100
|
declare function unsafeSchemaSql(options: {
|
|
@@ -3041,9 +3113,8 @@ declare function renderSchemaSql<TExpression extends AnyExpression>(expression:
|
|
|
3041
3113
|
/**
|
|
3042
3114
|
* Schema-only behavior layered onto a query dialect.
|
|
3043
3115
|
*
|
|
3044
|
-
* The query policy is deliberately not repeated here: identifier quoting,
|
|
3045
|
-
*
|
|
3046
|
-
* enclosing {@link SchemaDialect}.
|
|
3116
|
+
* The query policy is deliberately not repeated here: identifier quoting, placeholders, JSON,
|
|
3117
|
+
* casts, and capability identity all come from the enclosing {@link SchemaDialect}.
|
|
3047
3118
|
*/
|
|
3048
3119
|
interface SchemaDialectHooks {
|
|
3049
3120
|
/** Version of this dialect's schema metadata extension contract. */
|
|
@@ -3062,16 +3133,15 @@ interface SchemaDialectHooks {
|
|
|
3062
3133
|
/**
|
|
3063
3134
|
* A schema dialect is a strict capability superset of a query dialect.
|
|
3064
3135
|
*
|
|
3065
|
-
* A schema dialect must be created with {@link createSchemaDialect}; that
|
|
3066
|
-
*
|
|
3067
|
-
* behavior and snapshot metadata.
|
|
3136
|
+
* A schema dialect must be created with {@link createSchemaDialect}; that helper preserves the exact
|
|
3137
|
+
* query rendering object and adds only schema behavior and snapshot metadata.
|
|
3068
3138
|
*/
|
|
3069
3139
|
interface SchemaDialect<TCapabilities extends DialectCapability = DialectCapability> extends Dialect<TCapabilities> {
|
|
3070
3140
|
readonly schema: SchemaDialectHooks;
|
|
3071
3141
|
}
|
|
3072
3142
|
/**
|
|
3073
|
-
* Add schema behavior to an existing query dialect without rebuilding any of
|
|
3074
|
-
*
|
|
3143
|
+
* Add schema behavior to an existing query dialect without rebuilding any of its identifier,
|
|
3144
|
+
* literal, placeholder, JSON, cast, or capability policies.
|
|
3075
3145
|
*/
|
|
3076
3146
|
declare function createSchemaDialect<const TCapabilities extends DialectCapability = DialectCapability>(queryDialect: Dialect<TCapabilities>, schema: SchemaDialectHooks): SchemaDialect<TCapabilities>;
|
|
3077
3147
|
//#endregion
|
|
@@ -3079,8 +3149,8 @@ declare function createSchemaDialect<const TCapabilities extends DialectCapabili
|
|
|
3079
3149
|
/**
|
|
3080
3150
|
* Return every known source column as a named projection object.
|
|
3081
3151
|
*
|
|
3082
|
-
* The result can be passed directly to `select()` or spread into a larger
|
|
3083
|
-
*
|
|
3152
|
+
* The result can be passed directly to `select()` or spread into a larger projection, such as `{
|
|
3153
|
+
* ...all(users), displayName: upper(users.name) }`.
|
|
3084
3154
|
*/
|
|
3085
3155
|
declare function all<TSource extends AnySource>(source: TSource): SourceColumns<SourceRow<TSource>, SourceIdentity<TSource>, SourceSqlTypeMap<TSource>>;
|
|
3086
3156
|
type SelectionObject = Record<string, AnyExpression | Omit$1>;
|
|
@@ -3098,17 +3168,26 @@ type SelectionMetadata<TSelection> = InheritedMetadata<SelectionItems<TSelection
|
|
|
3098
3168
|
/** SQL result domains retained for each named projection field. */
|
|
3099
3169
|
type SelectionSqlTypes<TSelection, TRow extends object = SelectionOutput<TSelection>> = { readonly [K in keyof TRow]: K extends keyof TSelection ? SqlTypeOf<TSelection[K]> : SqlUnknown; };
|
|
3100
3170
|
//#endregion
|
|
3171
|
+
//#region src/query/clauses/from.d.ts
|
|
3172
|
+
interface FromClause<TSources extends readonly AnySource[] = readonly AnySource[], TMetadata = RequiresOuterMetadataOf<TSources[number]> | CapabilityMetadataOf<TSources[number]>> extends SelectClause<TMetadata> {
|
|
3173
|
+
readonly clauseKind: "from";
|
|
3174
|
+
readonly sources: TSources;
|
|
3175
|
+
}
|
|
3176
|
+
declare function from<const TSources extends readonly [AnySource, ...AnySource[]]>(...sources: TSources): FromClause<TSources, RequiresOuterMetadataOf<TSources[number]> | CapabilityMetadataOf<TSources[number]>>;
|
|
3177
|
+
type FromSource<T> = T extends FromClause<infer TSources> ? TSources[number] extends (infer TSource) ? TSource extends Source<any> ? [SourceProvision<TSource>] extends [never] ? never : TSource : never : never : never;
|
|
3178
|
+
type FromScope<T> = T extends FromClause<infer TSources> ? ProvidedSourceIdentity<TSources[number]> : never;
|
|
3179
|
+
//#endregion
|
|
3101
3180
|
//#region src/query/clauses/group-by.d.ts
|
|
3102
3181
|
interface GroupByClause<TMetadata = never> extends SelectClause<TMetadata> {
|
|
3103
|
-
readonly clauseKind:
|
|
3182
|
+
readonly clauseKind: "group-by";
|
|
3104
3183
|
readonly expressions: readonly AnyExpression[];
|
|
3105
3184
|
}
|
|
3106
3185
|
declare function groupBy<const TExpressions extends readonly AnyExpression[]>(...expressions: TExpressions): GroupByClause<GroupingMeta<TExpressions[number], ColumnGroupingDependencies<TExpressions[number]>> | InheritedMetadata<TExpressions[number]>>;
|
|
3107
3186
|
//#endregion
|
|
3108
3187
|
//#region src/query/clauses/joins.d.ts
|
|
3109
|
-
type JoinType =
|
|
3188
|
+
type JoinType = "INNER" | "LEFT" | "RIGHT" | "FULL" | "CROSS" | "NATURAL";
|
|
3110
3189
|
interface JoinClause<TSource extends AnySource = AnySource, TMetadata = never> extends SelectClause<TMetadata> {
|
|
3111
|
-
readonly clauseKind:
|
|
3190
|
+
readonly clauseKind: "join";
|
|
3112
3191
|
readonly joinType: JoinType;
|
|
3113
3192
|
readonly source: TSource;
|
|
3114
3193
|
readonly condition?: BooleanExpression<any>;
|
|
@@ -3136,22 +3215,13 @@ declare function fullJoin<TSource extends AnySource, TCondition extends BooleanE
|
|
|
3136
3215
|
declare function crossJoin<TSource extends AnySource>(source: TSource): JoinClause<TSource, RequiresOuterMetadataOf<TSource> | CapabilityMetadataOf<TSource>>;
|
|
3137
3216
|
declare function naturalJoin<TSource extends AnySource>(source: TSource): JoinClause<TSource, RequiresOuterMetadataOf<TSource> | CapabilityMetadataOf<TSource>>;
|
|
3138
3217
|
//#endregion
|
|
3139
|
-
//#region src/query/clauses/from.d.ts
|
|
3140
|
-
interface FromClause<TSources extends readonly AnySource[] = readonly AnySource[], TMetadata = RequiresOuterMetadataOf<TSources[number]> | CapabilityMetadataOf<TSources[number]>> extends SelectClause<TMetadata> {
|
|
3141
|
-
readonly clauseKind: 'from';
|
|
3142
|
-
readonly sources: TSources;
|
|
3143
|
-
}
|
|
3144
|
-
declare function from<const TSources extends readonly [AnySource, ...AnySource[]]>(...sources: TSources): FromClause<TSources, RequiresOuterMetadataOf<TSources[number]> | CapabilityMetadataOf<TSources[number]>>;
|
|
3145
|
-
type FromSource<T> = T extends FromClause<infer TSources> ? TSources[number] extends (infer TSource) ? TSource extends Source<any> ? [SourceProvision<TSource>] extends [never] ? never : TSource : never : never : never;
|
|
3146
|
-
type FromScope<T> = T extends FromClause<infer TSources> ? ProvidedSourceIdentity<TSources[number]> : never;
|
|
3147
|
-
//#endregion
|
|
3148
3218
|
//#region src/query/set.d.ts
|
|
3149
|
-
type SetOperator =
|
|
3219
|
+
type SetOperator = "UNION" | "UNION ALL" | "INTERSECT" | "EXCEPT";
|
|
3150
3220
|
interface SetQuery<TConfig extends QueryConfig = {}> extends Query<TConfig> {
|
|
3151
|
-
readonly queryKind:
|
|
3221
|
+
readonly queryKind: "set";
|
|
3152
3222
|
}
|
|
3153
3223
|
type SetSqlCompatibilityFailures<TLeft, TRight> = { [K in keyof QuerySqlTypeMap<TLeft>]: K extends keyof QuerySqlTypeMap<TRight> ? SqlEqualityCompatible<QuerySqlTypeMap<TLeft>[K], QuerySqlTypeMap<TRight>[K]> extends true ? never : K : K; }[keyof QuerySqlTypeMap<TLeft>];
|
|
3154
|
-
type SetSqlValidation<TLeft, TRight> = [SetSqlCompatibilityFailures<TLeft, TRight>] extends [never] ? unknown : QueryTypeValidation<
|
|
3224
|
+
type SetSqlValidation<TLeft, TRight> = [SetSqlCompatibilityFailures<TLeft, TRight>] extends [never] ? unknown : QueryTypeValidation<"incompatible-set-domain", "set-operation.columns", "Make corresponding set-operation fields use compatible SQL domains.", SetSqlCompatibilityFailures<TLeft, TRight>>;
|
|
3155
3225
|
declare function union<TLeft extends AnyQuery, TRight extends QueryWithRow<QueryRow<TLeft>>>(left: TLeft & SetSqlValidation<TLeft, TRight>, right: TRight): SetQuery<{
|
|
3156
3226
|
readonly row: QueryRow<TLeft & SetSqlValidation<TLeft, TRight>>;
|
|
3157
3227
|
readonly cardinality: any;
|
|
@@ -3179,7 +3249,7 @@ declare function except<TLeft extends AnyQuery, TRight extends QueryWithRow<Quer
|
|
|
3179
3249
|
//#endregion
|
|
3180
3250
|
//#region src/query/clauses/with.d.ts
|
|
3181
3251
|
type CteIdentity<TName extends string> = {
|
|
3182
|
-
readonly sourceKind:
|
|
3252
|
+
readonly sourceKind: "cte";
|
|
3183
3253
|
readonly name: TName;
|
|
3184
3254
|
};
|
|
3185
3255
|
type CteSource<TName extends string, TRow extends object, TMetadata = never, TSqlTypes extends SourceSqlTypes<TRow> = UnknownSourceSqlTypes<TRow>> = Source<{
|
|
@@ -3189,7 +3259,7 @@ type CteSource<TName extends string, TRow extends object, TMetadata = never, TSq
|
|
|
3189
3259
|
readonly sqlTypes: TSqlTypes;
|
|
3190
3260
|
}> & {
|
|
3191
3261
|
readonly cteName: TName;
|
|
3192
|
-
readonly query: Query
|
|
3262
|
+
readonly query: Query<{
|
|
3193
3263
|
readonly row: TRow;
|
|
3194
3264
|
readonly cardinality: any;
|
|
3195
3265
|
readonly metadata: TMetadata;
|
|
@@ -3198,9 +3268,9 @@ type CteSource<TName extends string, TRow extends object, TMetadata = never, TSq
|
|
|
3198
3268
|
readonly columns: SourceColumns<TRow, CteIdentity<TName>, TSqlTypes>;
|
|
3199
3269
|
} & SourceColumns<TRow, CteIdentity<TName>, TSqlTypes>;
|
|
3200
3270
|
type CteMetadata<TQuery extends AnyQuery> = RequiresOuterMetadataOf<TQuery> | CapabilityMetadataOf<TQuery>;
|
|
3201
|
-
type IsUnknown<T> = unknown extends T ? [keyof T] extends [never] ? true : false : false;
|
|
3271
|
+
type IsUnknown<T> = unknown extends T ? ([keyof T] extends [never] ? true : false) : false;
|
|
3202
3272
|
type RecursiveMemberFieldFailures<TAnchor, TMember> = Exclude<keyof QueryRow<TAnchor>, keyof QueryRow<TMember>> | Exclude<keyof QueryRow<TMember>, keyof QueryRow<TAnchor>> | { [K in keyof QueryRow<TAnchor> & keyof QueryRow<TMember>]: [IsUnknown<QueryRow<TMember>[K]>] extends [true] ? never : [IsUnknown<QueryRow<TAnchor>[K]>] extends [true] ? never : [QueryRow<TMember>[K]] extends [QueryRow<TAnchor>[K]] ? never : K; }[keyof QueryRow<TAnchor> & keyof QueryRow<TMember>];
|
|
3203
|
-
type RecursiveMemberShapeValidation<TAnchor, TMember> = [RecursiveMemberFieldFailures<TAnchor, TMember>] extends [never] ? unknown : QueryTypeValidation<
|
|
3273
|
+
type RecursiveMemberShapeValidation<TAnchor, TMember> = [RecursiveMemberFieldFailures<TAnchor, TMember>] extends [never] ? unknown : QueryTypeValidation<"incompatible-set-domain", "recursive-cte.member", "The recursive member must expose the anchor fields with compatible application types.", RecursiveMemberFieldFailures<TAnchor, TMember>>;
|
|
3204
3274
|
type RecursiveMemberValidation<TAnchor, TMember> = RecursiveMemberShapeValidation<TAnchor, TMember> & SetSqlValidation<TAnchor, TMember>;
|
|
3205
3275
|
type RecursiveCteSelf<TName extends string, TAnchor extends SelectQuery<any>> = CteSource<TName, QueryRow<TAnchor>, CteMetadata<TAnchor>, QuerySqlTypeMap<TAnchor>>;
|
|
3206
3276
|
/** The typed source returned by {@link recursiveCte}. */
|
|
@@ -3214,33 +3284,32 @@ type AnyCteSource = Source<any> & {
|
|
|
3214
3284
|
};
|
|
3215
3285
|
declare function cte<const TName extends string, TQuery extends AnyQuery>(name: TName, query: TQuery): CteSource<TName, QueryRow<TQuery>, RequiresOuterMetadataOf<TQuery> | CapabilityMetadataOf<TQuery>, QuerySqlTypeMap<TQuery>>;
|
|
3216
3286
|
/**
|
|
3217
|
-
* Define a typed recursive `WITH` source from an anchor and one recursive
|
|
3218
|
-
*
|
|
3219
|
-
*
|
|
3287
|
+
* Define a typed recursive `WITH` source from an anchor and one recursive member. The callback
|
|
3288
|
+
* receives a forward reference that must be introduced through the member query's normal FROM or
|
|
3289
|
+
* JOIN scope.
|
|
3220
3290
|
*/
|
|
3221
3291
|
declare function recursiveCte<const TName extends string, TAnchor extends SelectQuery<any>, TMember extends SelectQuery<any>>(name: TName, anchor: TAnchor, member: ((self: RecursiveCteSelf<TName, TAnchor>) => TMember) & ((self: RecursiveCteSelf<TName, TAnchor>) => TMember & RecursiveMemberValidation<NoInfer<TAnchor>, NoInfer<TMember>>)): RecursiveCteSource<TName, TAnchor, TMember>;
|
|
3222
3292
|
interface WithClause<TMetadata = never> extends SelectClause<TMetadata> {
|
|
3223
|
-
readonly clauseKind:
|
|
3293
|
+
readonly clauseKind: "with";
|
|
3224
3294
|
readonly ctes: readonly AnyCteSource[];
|
|
3225
3295
|
}
|
|
3226
3296
|
declare function withCte<const TCtes extends readonly AnyCteSource[]>(...ctes: TCtes): WithClause<RequiresOuterMetadataOf<TCtes[number]> | CapabilityMetadataOf<TCtes[number]>>;
|
|
3227
3297
|
//#endregion
|
|
3228
3298
|
//#region src/query/select/types.d.ts
|
|
3229
|
-
interface SelectQuery<TConfig extends QueryConfig = {}> extends Query
|
|
3230
|
-
readonly queryKind:
|
|
3299
|
+
interface SelectQuery<TConfig extends QueryConfig = {}> extends Query<TConfig> {
|
|
3300
|
+
readonly queryKind: "select";
|
|
3231
3301
|
}
|
|
3232
3302
|
type ExactlyOneSafeClause = DistinctClause | OrderByClause<any> | RowLockClause | WithClause;
|
|
3233
3303
|
type AtMostOneClause = FetchClause<0 | 1>;
|
|
3234
3304
|
type UnconditionalAtMostOneClause<TParts extends readonly SelectPart[]> = { [TIndex in keyof TParts]: Omit$1 extends TParts[TIndex] ? never : Extract<TParts[TIndex], AtMostOneClause>; }[number];
|
|
3235
3305
|
type ConditionalPaginationClause<TParts extends readonly SelectPart[]> = { [TIndex in keyof TParts]: Omit$1 extends TParts[TIndex] ? Extract<TParts[TIndex], AnyPaginationClause> : never; }[number];
|
|
3236
3306
|
/**
|
|
3237
|
-
* SELECT cardinality is intentionally conservative. A literal FETCH/LIMIT
|
|
3238
|
-
*
|
|
3239
|
-
*
|
|
3240
|
-
*
|
|
3241
|
-
* do not prove exactness.
|
|
3307
|
+
* SELECT cardinality is intentionally conservative. A literal FETCH/LIMIT bound of zero or one
|
|
3308
|
+
* proves an upper bound only when it is unconditional; an otherwise source-free query has one row
|
|
3309
|
+
* unless a known row-reducing clause is present. Conditional pagination, predicates, and arbitrary
|
|
3310
|
+
* clauses do not prove exactness.
|
|
3242
3311
|
*/
|
|
3243
|
-
type SelectCardinality<TParts extends readonly SelectPart[]> = UnconditionalAtMostOneClause<TParts> extends never ? ConditionalPaginationClause<TParts> extends never ? Exclude<TParts[number], ExactlyOneSafeClause | Omit$1> extends never ?
|
|
3312
|
+
type SelectCardinality<TParts extends readonly SelectPart[]> = UnconditionalAtMostOneClause<TParts> extends never ? ConditionalPaginationClause<TParts> extends never ? Exclude<TParts[number], ExactlyOneSafeClause | Omit$1> extends never ? "exactly-one" : "many" : "many" : "zero-or-one";
|
|
3244
3313
|
type ClauseScope<TClause> = TClause extends FromClause ? FromScope<TClause> : TClause extends JoinClause<infer TSource, any> ? ProvidedSourceIdentity<TSource> : never;
|
|
3245
3314
|
type AvailableScope<TClauses extends readonly AnySelectClause[]> = ClauseScope<TClauses[number]>;
|
|
3246
3315
|
type AvailableOuterScope<TClauses extends readonly AnySelectClause[]> = ProvidesOuterOf<TClauses[number]>;
|
|
@@ -3248,7 +3317,7 @@ type NullableSources<TClauses extends readonly AnySelectClause[]> = NullableSour
|
|
|
3248
3317
|
type RequiredScope<TSelection, TClauses extends readonly AnySelectClause[]> = SelectionRequires<TSelection> | RequiresOuterOf<SelectionItems<TSelection>> | RequiresOf<TClauses[number]> | RequiresOuterOf<TClauses[number]>;
|
|
3249
3318
|
type MissingScope<TSelection, TClauses extends readonly AnySelectClause[]> = Exclude<RequiredScope<TSelection, TClauses>, AvailableScope<TClauses> | AvailableOuterScope<TClauses>>;
|
|
3250
3319
|
type RequiredOuterScope<TSelection, TClauses extends readonly AnySelectClause[]> = Extract<Exclude<RequiredScope<TSelection, TClauses>, AvailableScope<TClauses>>, AvailableOuterScope<TClauses>>;
|
|
3251
|
-
type ScopeValidation<TSelection, TClauses extends readonly AnySelectClause[]> = [MissingScope<TSelection, TClauses>] extends [never] ? unknown : QueryTypeValidation<
|
|
3320
|
+
type ScopeValidation<TSelection, TClauses extends readonly AnySelectClause[]> = [MissingScope<TSelection, TClauses>] extends [never] ? unknown : QueryTypeValidation<"missing-source", "select.scope", "Add a FROM, JOIN, or correlate() clause that provides the referenced source.", MissingScope<TSelection, TClauses>>;
|
|
3252
3321
|
type GroupingRuleClause = HavingClause<any> | OrderByClause<any>;
|
|
3253
3322
|
type HasGroupByClause<TClauses extends readonly AnySelectClause[]> = Extract<TClauses[number], GroupByClause<any>> extends never ? false : true;
|
|
3254
3323
|
type HasHavingClause<TClauses extends readonly AnySelectClause[]> = Extract<TClauses[number], HavingClause<any>> extends never ? false : true;
|
|
@@ -3256,14 +3325,14 @@ type GroupingRuleClauses<TClauses extends readonly AnySelectClause[]> = Extract<
|
|
|
3256
3325
|
type RequiresGrouping<TSelection, TClauses extends readonly AnySelectClause[]> = HasGroupByClause<TClauses> extends true ? true : HasHavingClause<TClauses> extends true ? true : HasAggregate<SelectionItems<TSelection> | GroupingRuleClauses<TClauses>>;
|
|
3257
3326
|
type ClauseSource<TClause> = TClause extends FromClause ? FromSource<TClause> : TClause extends JoinClause<infer TSource, any> ? TSource : never;
|
|
3258
3327
|
type ConstraintDeterminesSource<TConstraint, TSource extends AnySource, TGroupedDependencies> = TConstraint extends {
|
|
3259
|
-
readonly kind:
|
|
3328
|
+
readonly kind: "primary-key" | "unique";
|
|
3260
3329
|
readonly columns: infer TColumns;
|
|
3261
3330
|
} ? TColumns extends readonly ColumnReference<string, any>[] ? [DependenciesOf<TColumns[number]>] extends [ColumnDependency<any, any>] ? [ColumnDependency<SourceIdentity<TSource>, DependenciesOf<TColumns[number]> extends ColumnDependency<any, infer TName extends string> ? TName : never>] extends [TGroupedDependencies] ? true : false : false : false : false;
|
|
3262
|
-
type IndexTermExpression$
|
|
3331
|
+
type IndexTermExpression$1<T> = T extends OrderTerm<any> ? T["expression"] : T;
|
|
3263
3332
|
type IndexDeterminesSource<TIndex, TSource extends AnySource, TGroupedDependencies> = TIndex extends {
|
|
3264
3333
|
readonly candidateKey: true;
|
|
3265
3334
|
readonly terms: infer TTerms extends readonly unknown[];
|
|
3266
|
-
} ? [DependenciesOf<IndexTermExpression$
|
|
3335
|
+
} ? [DependenciesOf<IndexTermExpression$1<TTerms[number]>>] extends [ColumnDependency<any, any>] ? [ColumnDependency<SourceIdentity<TSource>, DependenciesOf<IndexTermExpression$1<TTerms[number]>> extends ColumnDependency<any, infer TName extends string> ? TName : never>] extends [TGroupedDependencies] ? true : false : false : false;
|
|
3267
3336
|
type SourceIndexes<T> = T extends {
|
|
3268
3337
|
readonly indexes: infer TIndexes extends SourceIndexesRecord;
|
|
3269
3338
|
} ? TIndexes : {};
|
|
@@ -3275,12 +3344,11 @@ type ClauseGroupingFailures<TClauses extends readonly AnySelectClause[]> = TClau
|
|
|
3275
3344
|
type GroupByAggregateFailures<TClauses extends readonly AnySelectClause[]> = TClauses[number] extends (infer TClause) ? TClause extends GroupByClause<any> ? HasAggregate<TClause> extends true ? TClause : never : never : never;
|
|
3276
3345
|
type GroupingFailures<TSelection, TClauses extends readonly AnySelectClause[]> = SelectionGroupingFailures<TSelection, TClauses> | ClauseGroupingFailures<TClauses> | GroupByAggregateFailures<TClauses>;
|
|
3277
3346
|
/**
|
|
3278
|
-
* Enforce the grouped-query rule: visible column dependencies must be grouped
|
|
3279
|
-
*
|
|
3280
|
-
*
|
|
3281
|
-
* expressions are accepted as exact grouping keys only.
|
|
3347
|
+
* Enforce the grouped-query rule: visible column dependencies must be grouped or functionally
|
|
3348
|
+
* determined by a grouped, declared key from the same source. Aggregate arguments are consumed by
|
|
3349
|
+
* the aggregate. Non-column GROUP BY expressions are accepted as exact grouping keys only.
|
|
3282
3350
|
*/
|
|
3283
|
-
type GroupingValidation<TSelection, TClauses extends readonly AnySelectClause[]> = RequiresGrouping<TSelection, TClauses> extends true ? [GroupingFailures<TSelection, TClauses>] extends [never] ? unknown : QueryTypeValidation<
|
|
3351
|
+
type GroupingValidation<TSelection, TClauses extends readonly AnySelectClause[]> = RequiresGrouping<TSelection, TClauses> extends true ? [GroupingFailures<TSelection, TClauses>] extends [never] ? unknown : QueryTypeValidation<"invalid-grouping", "select.grouping", "Group every visible dependency or project it through an aggregate.", GroupingFailures<TSelection, TClauses>> : unknown;
|
|
3284
3352
|
//#endregion
|
|
3285
3353
|
//#region src/query/select.d.ts
|
|
3286
3354
|
type SelectMetadata<TSelection, TClauses extends readonly AnySelectClause[]> = ([RequiredOuterScope<TSelection, TClauses>] extends [never] ? never : RequiresOuterSourceMeta<RequiredOuterScope<TSelection, TClauses>>) | CapabilityMetadataOf<SelectionItems<TSelection> | TClauses[number]>;
|
|
@@ -3293,19 +3361,18 @@ declare function select<const TSelection extends Selection, const TParts extends
|
|
|
3293
3361
|
//#endregion
|
|
3294
3362
|
//#region src/query/clauses/correlate.d.ts
|
|
3295
3363
|
/**
|
|
3296
|
-
* Provision an enclosing source to a correlated SELECT. The clause emits no
|
|
3297
|
-
*
|
|
3298
|
-
* as a requirement on the resulting query.
|
|
3364
|
+
* Provision an enclosing source to a correlated SELECT. The clause emits no SQL; select() consumes
|
|
3365
|
+
* the provision and records any actually used source as a requirement on the resulting query.
|
|
3299
3366
|
*/
|
|
3300
3367
|
interface CorrelateClause<TSources extends readonly AnySource[] = readonly AnySource[]> extends SelectClause<ProvidesOuterSourceMeta<SourceIdentity<TSources[number]>>> {
|
|
3301
|
-
readonly clauseKind:
|
|
3368
|
+
readonly clauseKind: "correlate";
|
|
3302
3369
|
readonly sources: TSources;
|
|
3303
3370
|
}
|
|
3304
3371
|
declare function correlate<const TSources extends readonly [AnySource, ...AnySource[]]>(...sources: TSources): CorrelateClause<TSources>;
|
|
3305
3372
|
//#endregion
|
|
3306
3373
|
//#region src/query/mutation/returning.d.ts
|
|
3307
3374
|
interface ReturningClause<TSelection extends Selection = Selection> extends Fragment<SelectionMetadata<TSelection>> {
|
|
3308
|
-
readonly clauseKind:
|
|
3375
|
+
readonly clauseKind: "returning";
|
|
3309
3376
|
readonly selection: TSelection;
|
|
3310
3377
|
readonly row: SelectionOutput<TSelection>;
|
|
3311
3378
|
readonly resultShape: ResultShape;
|
|
@@ -3316,52 +3383,52 @@ type ReturningSqlTypes<T> = [T] extends [ReturningClause<infer TSelection>] ? Se
|
|
|
3316
3383
|
declare function returning<const TSelection extends Selection>(selection: TSelection): ReturningClause<TSelection>;
|
|
3317
3384
|
//#endregion
|
|
3318
3385
|
//#region src/query/mutation/types.d.ts
|
|
3319
|
-
type MutationKind =
|
|
3320
|
-
interface MutationQueryConfig extends Omit<QueryConfig,
|
|
3386
|
+
type MutationKind = "insert" | "update" | "delete";
|
|
3387
|
+
interface MutationQueryConfig extends Omit<QueryConfig, "cardinality"> {
|
|
3321
3388
|
readonly kind?: MutationKind;
|
|
3322
3389
|
}
|
|
3323
3390
|
type MutationConfigValue<TConfig, TKey extends PropertyKey, TFallback> = TKey extends keyof TConfig ? TConfig[TKey] : TFallback;
|
|
3324
|
-
type MutationConfigRow<TConfig> = Extract<MutationConfigValue<TConfig,
|
|
3325
|
-
type MutationConfigKind<TConfig> = Extract<MutationConfigValue<TConfig,
|
|
3326
|
-
interface MutationQuery<TConfig extends MutationQueryConfig = {}> extends Query
|
|
3391
|
+
type MutationConfigRow<TConfig> = Extract<MutationConfigValue<TConfig, "row", Record<string, unknown>>, object>;
|
|
3392
|
+
type MutationConfigKind<TConfig> = Extract<MutationConfigValue<TConfig, "kind", MutationKind>, MutationKind>;
|
|
3393
|
+
interface MutationQuery<TConfig extends MutationQueryConfig = {}> extends Query<{
|
|
3327
3394
|
readonly row: MutationConfigRow<TConfig>;
|
|
3328
|
-
readonly cardinality:
|
|
3329
|
-
readonly metadata: MutationConfigValue<TConfig,
|
|
3330
|
-
readonly sqlTypes: MutationConfigValue<TConfig,
|
|
3395
|
+
readonly cardinality: "many";
|
|
3396
|
+
readonly metadata: MutationConfigValue<TConfig, "metadata", never>;
|
|
3397
|
+
readonly sqlTypes: MutationConfigValue<TConfig, "sqlTypes", UnknownSourceSqlTypes<MutationConfigRow<TConfig>>>;
|
|
3331
3398
|
}> {
|
|
3332
3399
|
readonly queryKind: MutationConfigKind<TConfig>;
|
|
3333
3400
|
}
|
|
3334
3401
|
type MutationCapabilityMetadata<T> = CapabilityMetadataOf<T>;
|
|
3335
3402
|
interface AllowAllClause extends Fragment<never> {
|
|
3336
|
-
readonly clauseKind:
|
|
3403
|
+
readonly clauseKind: "allow-all";
|
|
3337
3404
|
}
|
|
3338
3405
|
declare function allowAll(): AllowAllClause;
|
|
3339
3406
|
type MutationConditionClause = WhereClause<any>;
|
|
3340
3407
|
type MutationClause = MutationConditionClause | AllowAllClause | MutationReturningClause;
|
|
3341
|
-
type MutationSafetyValidation<TClauses extends readonly unknown[]> = Extract<TClauses[number], MutationConditionClause | AllowAllClause> extends never ? QueryTypeValidation<
|
|
3408
|
+
type MutationSafetyValidation<TClauses extends readonly unknown[]> = Extract<TClauses[number], MutationConditionClause | AllowAllClause> extends never ? QueryTypeValidation<"unsafe-mutation", "mutation.safety", "Add where(...) or allowAll() explicitly."> : unknown;
|
|
3342
3409
|
type MutationReturningClause = ReturningClause<any>;
|
|
3343
3410
|
type MutationReturning<TClauses extends readonly unknown[]> = Extract<TClauses[number], MutationReturningClause>;
|
|
3344
3411
|
type MutationRow<TClauses extends readonly unknown[]> = ReturningRow<MutationReturning<TClauses>>;
|
|
3345
3412
|
type MutationSqlTypes<TClauses extends readonly unknown[]> = ReturningSqlTypes<MutationReturning<TClauses>>;
|
|
3346
|
-
type MutationScopeValidation<TSource, TClauses extends readonly unknown[]> = [Exclude<RequiresOf<TClauses[number]>, SourceIdentity<TSource>>] extends [never] ? unknown : QueryTypeValidation<
|
|
3413
|
+
type MutationScopeValidation<TSource, TClauses extends readonly unknown[]> = [Exclude<RequiresOf<TClauses[number]>, SourceIdentity<TSource>>] extends [never] ? unknown : QueryTypeValidation<"missing-source", "mutation.scope", "Use clauses that reference the mutation table or an explicitly correlated source.", Exclude<RequiresOf<TClauses[number]>, SourceIdentity<TSource>>>;
|
|
3347
3414
|
//#endregion
|
|
3348
3415
|
//#region src/query/mutation/update.d.ts
|
|
3349
3416
|
/** A value, target-compatible expression, or explicitly omitted update field. */
|
|
3350
3417
|
type UpdateAssignmentValue<T> = T | ExpressionWithOutput<T> | Omit$1;
|
|
3351
3418
|
/** Writable table fields accepted by {@link update}. */
|
|
3352
|
-
type UpdateAssignments<TTable extends AnyTable> = { -readonly [K in keyof TableUpdateInput<TTable[
|
|
3353
|
-
type InvalidUpdateAssignments<TTable extends AnyTable, TAssignments> = TAssignments extends UpdateAssignments<TTable> ? Exclude<keyof TAssignments, keyof UpdateAssignments<TTable>> extends never ? unknown : QueryTypeValidation<
|
|
3354
|
-
type AssignmentScopeValidation<TTable extends AnyTable, TAssignments> = [Exclude<RequiresOf<TAssignments extends object ? TAssignments[keyof TAssignments] : never>, SourceIdentity<TTable>>] extends [never] ? unknown : QueryTypeValidation<
|
|
3419
|
+
type UpdateAssignments<TTable extends AnyTable> = { -readonly [K in keyof TableUpdateInput<TTable["definitions"]>]?: UpdateAssignmentValue<TableUpdateInput<TTable["definitions"]>[K]>; };
|
|
3420
|
+
type InvalidUpdateAssignments<TTable extends AnyTable, TAssignments> = TAssignments extends UpdateAssignments<TTable> ? Exclude<keyof TAssignments, keyof UpdateAssignments<TTable>> extends never ? unknown : QueryTypeValidation<"invalid-update", "update.assignments", "Use only columns declared by the update table.", Exclude<keyof TAssignments, keyof UpdateAssignments<TTable>>> : QueryTypeValidation<"invalid-update", "update.assignments", "Provide values or expressions matching the update table columns.", TAssignments>;
|
|
3421
|
+
type AssignmentScopeValidation<TTable extends AnyTable, TAssignments> = [Exclude<RequiresOf<TAssignments extends object ? TAssignments[keyof TAssignments] : never>, SourceIdentity<TTable>>] extends [never] ? unknown : QueryTypeValidation<"missing-source", "update.assignments", "Use expressions scoped to the update table.", Exclude<RequiresOf<TAssignments extends object ? TAssignments[keyof TAssignments] : never>, SourceIdentity<TTable>>>;
|
|
3355
3422
|
declare function update<const TTable extends AnyTable, const TAssignments extends object, const TClauses extends readonly MutationClause[]>(table: TTable, assignments: TAssignments & InvalidUpdateAssignments<TTable, TAssignments> & AssignmentScopeValidation<TTable, TAssignments>, ...clauses: TClauses & MutationScopeValidation<TTable, TClauses> & MutationSafetyValidation<TClauses>): MutationQuery<{
|
|
3356
3423
|
readonly row: MutationRow<TClauses>;
|
|
3357
|
-
readonly kind:
|
|
3424
|
+
readonly kind: "update";
|
|
3358
3425
|
readonly metadata: MutationCapabilityMetadata<TClauses[number] | (TAssignments extends object ? TAssignments[keyof TAssignments] : never)>;
|
|
3359
3426
|
readonly sqlTypes: MutationSqlTypes<TClauses>;
|
|
3360
3427
|
}>;
|
|
3361
3428
|
//#endregion
|
|
3362
3429
|
//#region src/query/mutation/on-conflict.d.ts
|
|
3363
3430
|
type ExcludedIdentity<TTableIdentity> = {
|
|
3364
|
-
readonly sourceKind:
|
|
3431
|
+
readonly sourceKind: "excluded";
|
|
3365
3432
|
readonly table: TTableIdentity;
|
|
3366
3433
|
};
|
|
3367
3434
|
type ExcludedSource<TTable extends AnyTable> = Source<{
|
|
@@ -3373,10 +3440,10 @@ type ExcludedSqlTypes<TTable extends AnyTable> = SourceSqlTypeMap<TTable> & Sour
|
|
|
3373
3440
|
/** Columns from the proposed INSERT row, available inside DO UPDATE. */
|
|
3374
3441
|
declare function excluded<const TTable extends AnyTable>(table: TTable): ExcludedSource<TTable>;
|
|
3375
3442
|
interface DoNothingAction {
|
|
3376
|
-
readonly actionKind:
|
|
3443
|
+
readonly actionKind: "do-nothing";
|
|
3377
3444
|
}
|
|
3378
3445
|
interface DoUpdateAction<TAssignments extends object = object, TWhere extends WhereClause<any> | undefined = WhereClause<any> | undefined> {
|
|
3379
|
-
readonly actionKind:
|
|
3446
|
+
readonly actionKind: "do-update";
|
|
3380
3447
|
readonly assignments: TAssignments;
|
|
3381
3448
|
readonly where: TWhere;
|
|
3382
3449
|
}
|
|
@@ -3391,12 +3458,12 @@ type TableKeyConstraint<TTable extends AnyTable> = Extract<TableConstraints<TTab
|
|
|
3391
3458
|
/** A declared primary or non-null unique key used as an upsert target. */
|
|
3392
3459
|
type ConflictTarget<TTable extends AnyTable = AnyTable> = TableKeyConstraint<TTable>;
|
|
3393
3460
|
type ConflictSources<TTable extends AnyTable> = SourceIdentity<TTable> | ExcludedIdentity<SourceIdentity<TTable>>;
|
|
3394
|
-
type ConflictAssignmentValidation<TTable extends AnyTable, TAssignments> = TAssignments extends UpdateAssignments<TTable> ? Exclude<keyof TAssignments, keyof UpdateAssignments<TTable>> extends never ? [Exclude<RequiresOf<TAssignments[keyof TAssignments]>, ConflictSources<TTable>>] extends [never] ? unknown : QueryTypeValidation<
|
|
3395
|
-
type ConflictWhereValidation<TTable extends AnyTable, TWhere> = TWhere extends undefined ? unknown : [Exclude<RequiresOf<TWhere>, ConflictSources<TTable>>] extends [never] ? unknown : QueryTypeValidation<
|
|
3461
|
+
type ConflictAssignmentValidation<TTable extends AnyTable, TAssignments> = TAssignments extends UpdateAssignments<TTable> ? Exclude<keyof TAssignments, keyof UpdateAssignments<TTable>> extends never ? [Exclude<RequiresOf<TAssignments[keyof TAssignments]>, ConflictSources<TTable>>] extends [never] ? unknown : QueryTypeValidation<"missing-source", "upsert.update.assignments", "Use expressions scoped to the target table or excluded row.", Exclude<RequiresOf<TAssignments[keyof TAssignments]>, ConflictSources<TTable>>> : QueryTypeValidation<"invalid-update", "upsert.update.assignments", "Use only writable columns declared by the target table.", Exclude<keyof TAssignments, keyof UpdateAssignments<TTable>>> : QueryTypeValidation<"invalid-update", "upsert.update.assignments", "Provide values or expressions matching the target table update columns.", TAssignments>;
|
|
3462
|
+
type ConflictWhereValidation<TTable extends AnyTable, TWhere> = TWhere extends undefined ? unknown : [Exclude<RequiresOf<TWhere>, ConflictSources<TTable>>] extends [never] ? unknown : QueryTypeValidation<"missing-source", "upsert.update.where", "Use expressions scoped to the target table or excluded row.", Exclude<RequiresOf<TWhere>, ConflictSources<TTable>>>;
|
|
3396
3463
|
type ConflictActionValidation<TTable extends AnyTable, TAction extends ConflictAction> = TAction extends DoUpdateAction<infer TAssignments, infer TWhere> ? ConflictAssignmentValidation<TTable, TAssignments> & ConflictWhereValidation<TTable, TWhere> : unknown;
|
|
3397
3464
|
type ConflictActionCapabilities<TAction extends ConflictAction> = TAction extends DoUpdateAction<infer TAssignments, infer TWhere> ? CapabilityMetadataOf<TAssignments[keyof TAssignments] | Exclude<TWhere, undefined>> : never;
|
|
3398
|
-
interface OnConflictClause<TAction extends ConflictAction = ConflictAction> extends Fragment<RequiresCapabilityMeta<
|
|
3399
|
-
readonly clauseKind:
|
|
3465
|
+
interface OnConflictClause<TAction extends ConflictAction = ConflictAction> extends Fragment<RequiresCapabilityMeta<"on-conflict"> | ConflictActionCapabilities<TAction>> {
|
|
3466
|
+
readonly clauseKind: "on-conflict";
|
|
3400
3467
|
readonly target: KeyConstraint | undefined;
|
|
3401
3468
|
readonly action: TAction;
|
|
3402
3469
|
}
|
|
@@ -3406,32 +3473,32 @@ declare function onConflict<const TTable extends AnyTable, const TTarget extends
|
|
|
3406
3473
|
//#endregion
|
|
3407
3474
|
//#region src/query/mutation/insert.d.ts
|
|
3408
3475
|
interface ValuesSource<TRows extends readonly object[] = readonly object[]> {
|
|
3409
|
-
readonly insertKind:
|
|
3476
|
+
readonly insertKind: "values";
|
|
3410
3477
|
readonly rows: TRows;
|
|
3411
3478
|
}
|
|
3412
3479
|
declare function values<const TRows extends readonly [object, ...object[]]>(...rows: TRows): ValuesSource<TRows>;
|
|
3413
3480
|
interface DefaultValuesSource {
|
|
3414
|
-
readonly insertKind:
|
|
3481
|
+
readonly insertKind: "default-values";
|
|
3415
3482
|
}
|
|
3416
3483
|
declare function defaultValues(): DefaultValuesSource;
|
|
3417
3484
|
interface InsertSelectSource<TQuery extends AnyQuery = AnyQuery, TColumns extends readonly string[] = readonly string[]> {
|
|
3418
|
-
readonly insertKind:
|
|
3485
|
+
readonly insertKind: "select";
|
|
3419
3486
|
readonly query: TQuery;
|
|
3420
3487
|
readonly columns: TColumns;
|
|
3421
3488
|
}
|
|
3422
3489
|
declare function insertSelect<TQuery extends AnyQuery, const TColumns extends readonly [string, ...string[]]>(query: TQuery, columns: TColumns): InsertSelectSource<TQuery, TColumns>;
|
|
3423
3490
|
type InsertSource = ValuesSource<any> | DefaultValuesSource | InsertSelectSource<any, any>;
|
|
3424
3491
|
type InsertSourceCapabilityMetadata<TSource extends InsertSource> = TSource extends InsertSelectSource<infer TQuery, any> ? CapabilityMetadataOf<TQuery> : never;
|
|
3425
|
-
type InsertRow<TTable extends AnyTable> = TableInsertInput<TTable[
|
|
3426
|
-
type InvalidInsertRow<TTable extends AnyTable, TRow> = TRow extends InsertRow<TTable> ? Exclude<keyof TRow, keyof InsertRow<TTable>> extends never ? unknown : QueryTypeValidation<
|
|
3427
|
-
type ValidInsertSource<TTable extends AnyTable, TSource extends InsertSource> = TSource extends ValuesSource<infer TRows> ? TRows[number] extends (infer TRow) ? InvalidInsertRow<TTable, TRow> : never : TSource extends DefaultValuesSource ? Exclude<keyof TTable[
|
|
3492
|
+
type InsertRow<TTable extends AnyTable> = TableInsertInput<TTable["definitions"]>;
|
|
3493
|
+
type InvalidInsertRow<TTable extends AnyTable, TRow> = TRow extends InsertRow<TTable> ? Exclude<keyof TRow, keyof InsertRow<TTable>> extends never ? unknown : QueryTypeValidation<"invalid-insert", "insert.values.columns", "Use only columns declared by the insert table.", Exclude<keyof TRow, keyof InsertRow<TTable>>> : QueryTypeValidation<"invalid-insert", "insert.values.row", "Provide values matching the insert table columns.", TRow>;
|
|
3494
|
+
type ValidInsertSource<TTable extends AnyTable, TSource extends InsertSource> = TSource extends ValuesSource<infer TRows> ? TRows[number] extends (infer TRow) ? InvalidInsertRow<TTable, TRow> : never : TSource extends DefaultValuesSource ? Exclude<keyof TTable["definitions"], { [K in keyof TTable["definitions"]]-?: ColumnIsGenerated<TTable["definitions"][K]> extends true ? K : TTable["definitions"][K] extends {
|
|
3428
3495
|
hasDefault: true;
|
|
3429
|
-
} ? K : never; }[keyof TTable[
|
|
3496
|
+
} ? K : never; }[keyof TTable["definitions"]]> extends never ? unknown : QueryTypeValidation<"invalid-insert", "insert.default-values", "Provide values for required columns or define defaults for them.", Exclude<keyof TTable["definitions"], { [K in keyof TTable["definitions"]]-?: ColumnIsGenerated<TTable["definitions"][K]> extends true ? K : TTable["definitions"][K] extends {
|
|
3430
3497
|
hasDefault: true;
|
|
3431
|
-
} ? K : never; }[keyof TTable[
|
|
3498
|
+
} ? K : never; }[keyof TTable["definitions"]]>> : TSource extends InsertSelectSource<any, infer TColumns> ? Exclude<TColumns[number], keyof TTable["definitions"]> extends never ? Exclude<{ [K in keyof TTable["definitions"]]-?: ColumnIsGenerated<TTable["definitions"][K]> extends true ? never : ColumnHasDefault<TTable["definitions"][K]> extends true ? never : K; }[keyof TTable["definitions"]], TColumns[number]> extends never ? unknown : QueryTypeValidation<"invalid-insert", "insert.select.columns", "Include every required insert column in the target list.", Exclude<{ [K in keyof TTable["definitions"]]-?: ColumnIsGenerated<TTable["definitions"][K]> extends true ? never : ColumnHasDefault<TTable["definitions"][K]> extends true ? never : K; }[keyof TTable["definitions"]], TColumns[number]>> : QueryTypeValidation<"invalid-insert", "insert.select.columns", "Use only columns declared by the insert table.", Exclude<TColumns[number], keyof TTable["definitions"]>> : never;
|
|
3432
3499
|
declare function insertInto<const TTable extends AnyTable, const TSource extends InsertSource, const TClauses extends readonly InsertClause[]>(table: TTable, source: TSource & ValidInsertSource<TTable, TSource>, ...clauses: TClauses & MutationScopeValidation<TTable, TClauses>): MutationQuery<{
|
|
3433
3500
|
readonly row: MutationRow<TClauses>;
|
|
3434
|
-
readonly kind:
|
|
3501
|
+
readonly kind: "insert";
|
|
3435
3502
|
readonly metadata: MutationCapabilityMetadata<TClauses[number]> | InsertSourceCapabilityMetadata<TSource>;
|
|
3436
3503
|
readonly sqlTypes: MutationSqlTypes<TClauses>;
|
|
3437
3504
|
}>;
|
|
@@ -3439,16 +3506,16 @@ declare function insertInto<const TTable extends AnyTable, const TSource extends
|
|
|
3439
3506
|
//#region src/query/mutation/delete.d.ts
|
|
3440
3507
|
declare function deleteFrom<const TTable extends AnyTable, const TClauses extends readonly MutationClause[]>(table: TTable, ...clauses: TClauses & MutationScopeValidation<TTable, TClauses> & MutationSafetyValidation<TClauses>): MutationQuery<{
|
|
3441
3508
|
readonly row: MutationRow<TClauses>;
|
|
3442
|
-
readonly kind:
|
|
3509
|
+
readonly kind: "delete";
|
|
3443
3510
|
readonly metadata: MutationCapabilityMetadata<TClauses[number]>;
|
|
3444
3511
|
readonly sqlTypes: MutationSqlTypes<TClauses>;
|
|
3445
3512
|
}>;
|
|
3446
3513
|
//#endregion
|
|
3447
3514
|
//#region src/query/clauses/order-by.d.ts
|
|
3448
|
-
type OrderDirection =
|
|
3449
|
-
type NullsOrder =
|
|
3515
|
+
type OrderDirection = "ASC" | "DESC";
|
|
3516
|
+
type NullsOrder = "FIRST" | "LAST";
|
|
3450
3517
|
interface OrderTerm<TMetadata = never, TExpression extends AnyExpression = AnyExpression> extends Fragment<TMetadata> {
|
|
3451
|
-
readonly orderKind:
|
|
3518
|
+
readonly orderKind: "term";
|
|
3452
3519
|
readonly expression: TExpression;
|
|
3453
3520
|
readonly direction?: OrderDirection;
|
|
3454
3521
|
readonly nulls?: NullsOrder;
|
|
@@ -3469,7 +3536,7 @@ declare function nullsLast<TExpression extends AnyExpression>(expression: TExpre
|
|
|
3469
3536
|
readonly kind: "result" | "cardinality";
|
|
3470
3537
|
} ? never : T : never : never, TExpression & SqlCapabilityValidation<ExpressionSqlType<TExpression>, SqlOrderable<unknown>>>;
|
|
3471
3538
|
interface OrderByClause<TMetadata = never> extends SelectClause<TMetadata> {
|
|
3472
|
-
readonly clauseKind:
|
|
3539
|
+
readonly clauseKind: "order-by";
|
|
3473
3540
|
readonly terms: readonly OrderTerm<any>[];
|
|
3474
3541
|
}
|
|
3475
3542
|
type OrderByPart = AnyExpression | OrderTerm<any> | Omit$1;
|
|
@@ -3478,86 +3545,6 @@ type OrderByComposition<TParts extends readonly OrderByPart[]> = [PresentOrderPa
|
|
|
3478
3545
|
type OrderPartsValidation<TParts extends readonly unknown[]> = TParts extends readonly [infer THead, ...infer TTail] ? (THead extends Omit$1 ? unknown : THead extends AnyExpression ? SqlCapabilityValidation<ExpressionSqlType<THead>, SqlOrderable> : unknown) & OrderPartsValidation<TTail> : unknown;
|
|
3479
3546
|
declare function orderBy<const TParts extends readonly OrderByPart[]>(...parts: TParts & OrderPartsValidation<TParts>): OrderByComposition<TParts>;
|
|
3480
3547
|
//#endregion
|
|
3481
|
-
//#region src/schema/indexes.d.ts
|
|
3482
|
-
type IndexTerm = AnyExpression | OrderTerm<any>;
|
|
3483
|
-
/** PostgreSQL-specific index method and storage metadata. */
|
|
3484
|
-
interface PostgresIndexExtension extends SchemaDialectExtension<'postgresql'> {
|
|
3485
|
-
readonly method?: 'btree' | 'hash' | 'gist' | 'spgist' | 'gin' | 'brin';
|
|
3486
|
-
readonly concurrently?: boolean;
|
|
3487
|
-
readonly operatorClasses?: Readonly<Record<string, string>>;
|
|
3488
|
-
readonly storageParameters?: Readonly<Record<string, string | number | boolean>>;
|
|
3489
|
-
}
|
|
3490
|
-
/** SQLite-specific index metadata retained for a future adapter. */
|
|
3491
|
-
interface SqliteIndexExtension extends SchemaDialectExtension<'sqlite'> {
|
|
3492
|
-
readonly auto?: boolean;
|
|
3493
|
-
}
|
|
3494
|
-
/** MySQL-specific index algorithm, locking, and parser metadata. */
|
|
3495
|
-
interface MysqlIndexExtension extends SchemaDialectExtension<'mysql'> {
|
|
3496
|
-
readonly algorithm?: 'default' | 'inplace' | 'copy';
|
|
3497
|
-
readonly lock?: 'default' | 'none' | 'shared' | 'exclusive';
|
|
3498
|
-
readonly using?: 'btree' | 'hash' | 'rtree';
|
|
3499
|
-
readonly parser?: string;
|
|
3500
|
-
readonly keyBlockSize?: number;
|
|
3501
|
-
}
|
|
3502
|
-
/** First-party and user-defined dialect extensions for indexes. */
|
|
3503
|
-
type IndexDialectExtension = PostgresIndexExtension | SqliteIndexExtension | MysqlIndexExtension | (SchemaDialectExtension<string> & Readonly<Record<string, unknown>>);
|
|
3504
|
-
interface IndexOptions<TPredicate extends AnyExpression | undefined = AnyExpression | undefined, TExtension extends IndexDialectExtension | undefined = IndexDialectExtension | undefined> extends SchemaObjectNameOptions {
|
|
3505
|
-
readonly unique?: boolean;
|
|
3506
|
-
readonly where?: TPredicate;
|
|
3507
|
-
/** Columns stored in the index payload but not used as key terms. */
|
|
3508
|
-
readonly include?: readonly ColumnReference<string, any>[];
|
|
3509
|
-
/** Typed engine-specific index options. */
|
|
3510
|
-
readonly dialect?: TExtension;
|
|
3511
|
-
}
|
|
3512
|
-
type IndexTermExpression$1<TTerm> = TTerm extends OrderTerm<any> ? TTerm['expression'] : TTerm;
|
|
3513
|
-
type IsNullableIndexColumn<TColumn> = [DeclaredColumnNullabilityOf<TColumn>] extends [never] ? null extends OutputOf<TColumn> ? true : false : true extends DeclaredColumnNullabilityOf<TColumn> ? true : false;
|
|
3514
|
-
type IsEligibleColumn<TTerm> = IndexTermExpression$1<TTerm> extends (infer TExpression) ? TExpression extends ColumnReference<string, any> ? IsNullableIndexColumn<TExpression> extends true ? false : true : false : false;
|
|
3515
|
-
type AllEligibleColumns<TTerms extends readonly IndexTerm[]> = { [K in keyof TTerms]: IsEligibleColumn<TTerms[K]>; }[number] extends (infer TEligibility) ? false extends TEligibility ? true extends TEligibility ? boolean : false : true : false;
|
|
3516
|
-
type BooleanOption<TValue> = [Extract<TValue, true>] extends [never] ? false : [Exclude<TValue, true>] extends [never] ? true : boolean;
|
|
3517
|
-
type UniqueOption<TOptions> = 'unique' extends keyof TOptions ? BooleanOption<TOptions['unique']> : false;
|
|
3518
|
-
type PredicateOption<TOptions> = 'where' extends keyof TOptions ? TOptions['where'] : undefined;
|
|
3519
|
-
type DialectOption<TOptions> = TOptions extends {
|
|
3520
|
-
readonly dialect?: infer TDialect;
|
|
3521
|
-
} ? unknown extends TDialect ? IndexDialectExtension | undefined : TDialect : undefined;
|
|
3522
|
-
type PredicatePresence<TOptions> = [Exclude<PredicateOption<TOptions>, undefined>] extends [never] ? false : undefined extends PredicateOption<TOptions> ? boolean : true;
|
|
3523
|
-
type IsCandidateKey<TTerms extends readonly IndexTerm[], TOptions extends IndexOptions<any>> = UniqueOption<TOptions> extends (infer TUnique) ? PredicatePresence<TOptions> extends (infer THasPredicate) ? AllEligibleColumns<TTerms> extends (infer TEligible) ? TUnique extends false ? false : THasPredicate extends true ? false : TEligible extends false ? false : TUnique extends true ? THasPredicate extends false ? TEligible extends true ? true : boolean : boolean : boolean : false : false : false;
|
|
3524
|
-
/** Portable index metadata retained by a table and its aliases. */
|
|
3525
|
-
interface TableIndex<TTerms extends readonly IndexTerm[] = any, TOptions extends IndexOptions<any> = any> extends SchemaObjectIdentity {
|
|
3526
|
-
readonly kind: 'index';
|
|
3527
|
-
readonly terms: TTerms;
|
|
3528
|
-
readonly unique: UniqueOption<TOptions>;
|
|
3529
|
-
readonly predicate: PredicateOption<TOptions>;
|
|
3530
|
-
readonly includedColumns?: TOptions extends {
|
|
3531
|
-
readonly include: infer TIncluded;
|
|
3532
|
-
} ? TIncluded : undefined;
|
|
3533
|
-
readonly dialect?: DialectOption<TOptions>;
|
|
3534
|
-
readonly candidateKey: IsCandidateKey<TTerms, TOptions>;
|
|
3535
|
-
}
|
|
3536
|
-
/** The widened index shape accepted by source metadata records. */
|
|
3537
|
-
interface SourceIndex {
|
|
3538
|
-
readonly kind: 'index';
|
|
3539
|
-
readonly terms: readonly IndexTerm[];
|
|
3540
|
-
readonly unique: boolean;
|
|
3541
|
-
readonly predicate: AnyExpression | undefined;
|
|
3542
|
-
readonly includedColumns?: readonly ColumnReference<string, any>[];
|
|
3543
|
-
readonly dialect?: IndexDialectExtension;
|
|
3544
|
-
readonly candidateKey: boolean;
|
|
3545
|
-
}
|
|
3546
|
-
type SourceIndexesRecord = Readonly<Record<string, SourceIndex>>;
|
|
3547
|
-
/**
|
|
3548
|
-
* Validate portable and dialect-owned index facts for one target adapter.
|
|
3549
|
-
* Unsupported features are reported as data so a serializer can aggregate
|
|
3550
|
-
* diagnostics instead of failing during traversal with an opaque exception.
|
|
3551
|
-
*/
|
|
3552
|
-
declare function validateIndexDialect(indexMetadata: SourceIndex, dialect: string, path?: readonly (string | number)[]): readonly SchemaMetadataDiagnostic[];
|
|
3553
|
-
type ValidIndexExpression<T> = T extends AnyExpression ? HasAggregate<T> extends true ? never : HasWindow<T> extends true ? never : HasSubquery<T> extends true ? never : unknown : never;
|
|
3554
|
-
type InvalidIndexTerms<TTerms extends readonly IndexTerm[]> = { [K in keyof TTerms]: TTerms[K] extends OrderTerm<any> ? TTerms[K] extends {
|
|
3555
|
-
readonly nulls: 'FIRST' | 'LAST';
|
|
3556
|
-
} ? TTerms[K] : ValidIndexExpression<TTerms[K]['expression']> extends never ? TTerms[K] : never : ValidIndexExpression<TTerms[K]> extends never ? TTerms[K] : never; }[number];
|
|
3557
|
-
type IndexTermsValidation<TTerms extends readonly IndexTerm[]> = [InvalidIndexTerms<TTerms>] extends [never] ? unknown : never;
|
|
3558
|
-
/** Declare a portable column or expression index. */
|
|
3559
|
-
declare function index<const TTerms extends readonly [IndexTerm, ...IndexTerm[]], const TOptions extends IndexOptions<any> = {}>(terms: TTerms & IndexTermsValidation<NoInfer<TTerms>>, options?: TOptions): TableIndex<TTerms, TOptions>;
|
|
3560
|
-
//#endregion
|
|
3561
3548
|
//#region src/schema/table.d.ts
|
|
3562
3549
|
type TableDefinitions = Record<string, ColumnDefinition<any>>;
|
|
3563
3550
|
type AnyTable = Source<any> & {
|
|
@@ -3574,7 +3561,7 @@ type OptionalInsertKeys<TDefinitions extends TableDefinitions> = Exclude<keyof T
|
|
|
3574
3561
|
type TableInsertInput<TDefinitions extends TableDefinitions> = { -readonly [K in RequiredInsertKeys<TDefinitions>]: ColumnInsertInput<TDefinitions[K]>; } & { -readonly [K in OptionalInsertKeys<TDefinitions>]?: ColumnInsertInput<TDefinitions[K]>; };
|
|
3575
3562
|
type TableUpdateInput<TDefinitions extends TableDefinitions> = { -readonly [K in keyof TDefinitions as ColumnIsGenerated<TDefinitions[K]> extends true ? never : K]?: ColumnUpdateInput<TDefinitions[K]>; };
|
|
3576
3563
|
type TableIdentity<TName extends string> = {
|
|
3577
|
-
readonly sourceKind:
|
|
3564
|
+
readonly sourceKind: "table";
|
|
3578
3565
|
readonly tableName: TName;
|
|
3579
3566
|
};
|
|
3580
3567
|
type TableColumns<TDefinitions extends TableDefinitions, TIdentity> = { readonly [K in keyof TDefinitions]: SourceColumns<TableRow<TDefinitions>, TIdentity, TableSqlTypes<TDefinitions>>[K] & DeclaredColumnNullability<ColumnIsNullable<TDefinitions[K]>>; };
|
|
@@ -3602,7 +3589,7 @@ type InvalidConstraintDependencies<TName extends string, TConstraints extends So
|
|
|
3602
3589
|
type InvalidExpression<TExpression, TName extends string> = TExpression extends AnyExpression ? Exclude<DependenciesOf<TExpression>, ColumnDependency<TableIdentity<TName>, string>> extends never ? HasAggregate<TExpression> extends true ? TExpression : HasWindow<TExpression> extends true ? TExpression : HasSubquery<TExpression> extends true ? TExpression : never : TExpression : TExpression;
|
|
3603
3590
|
type ResolvedTarget<T> = T extends (() => infer TResolved) ? TResolved : T;
|
|
3604
3591
|
type SameColumnTuple<TLeft extends readonly unknown[], TRight extends readonly unknown[]> = TLeft extends readonly [infer TLeftHead, ...infer TLeftTail] ? TRight extends readonly [infer TRightHead, ...infer TRightTail] ? [DependenciesOf<TLeftHead>] extends [DependenciesOf<TRightHead>] ? [DependenciesOf<TRightHead>] extends [DependenciesOf<TLeftHead>] ? SameColumnTuple<TLeftTail, TRightTail> : false : false : false : TRight extends readonly [] ? true : false;
|
|
3605
|
-
type IndexTermExpression<T> = T extends OrderTerm<any> ? T[
|
|
3592
|
+
type IndexTermExpression<T> = T extends OrderTerm<any> ? T["expression"] : T;
|
|
3606
3593
|
type IndexColumns<TTerms extends readonly IndexTerm[]> = { [K in keyof TTerms]: IndexTermExpression<TTerms[K]>; };
|
|
3607
3594
|
type IndexIncludedColumns<TIndex> = TIndex extends {
|
|
3608
3595
|
readonly includedColumns?: infer TIncluded;
|
|
@@ -3615,15 +3602,15 @@ type IndexesOf<T> = T extends {
|
|
|
3615
3602
|
readonly indexes: infer TIndexes extends SourceIndexesRecord;
|
|
3616
3603
|
} ? TIndexes : {};
|
|
3617
3604
|
type HasMatchingConstraint<TColumns, TConstraints> = TConstraints extends SourceConstraintsRecord ? true extends { [K in keyof TConstraints]: TConstraints[K] extends (infer TConstraint) ? TConstraint extends {
|
|
3618
|
-
readonly kind:
|
|
3605
|
+
readonly kind: "primary-key" | "unique";
|
|
3619
3606
|
readonly columns: infer TCandidate extends readonly unknown[];
|
|
3620
3607
|
} ? TColumns extends readonly unknown[] ? SameColumnTuple<TColumns, TCandidate> : false : false : false; }[keyof TConstraints] ? true : false : false;
|
|
3621
3608
|
type HasMatchingIndex<TColumns, TIndexes> = TIndexes extends SourceIndexesRecord ? true extends { [K in keyof TIndexes]: TIndexes[K] extends (infer TIndex) ? TIndex extends {
|
|
3622
3609
|
readonly terms: infer TTerms extends readonly IndexTerm[];
|
|
3623
3610
|
readonly candidateKey: infer TCandidateKey;
|
|
3624
3611
|
} ? [TCandidateKey] extends [true] ? TColumns extends readonly unknown[] ? SameColumnTuple<TColumns, IndexColumns<TTerms>> : false : false : false : false; }[keyof TIndexes] ? true : false : false;
|
|
3625
|
-
type TargetMetadata<TTarget extends ForeignKeyTarget, TName extends string, TConstraints extends SourceConstraintsRecord, TIndexes extends SourceIndexesRecord> = [SourceIdentity<TTarget[
|
|
3626
|
-
type InvalidForeignKey<TConstraint extends ForeignKeyConstraint, TName extends string, TConstraints extends SourceConstraintsRecord, TIndexes extends SourceIndexesRecord> = ResolvedTarget<TConstraint[
|
|
3612
|
+
type TargetMetadata<TTarget extends ForeignKeyTarget, TName extends string, TConstraints extends SourceConstraintsRecord, TIndexes extends SourceIndexesRecord> = [SourceIdentity<TTarget["table"]>] extends [TableIdentity<TName>] ? [TableIdentity<TName>] extends [SourceIdentity<TTarget["table"]>] ? readonly [TConstraints, TIndexes] : readonly [ConstraintsOf<TTarget["table"]>, IndexesOf<TTarget["table"]>] : readonly [ConstraintsOf<TTarget["table"]>, IndexesOf<TTarget["table"]>];
|
|
3613
|
+
type InvalidForeignKey<TConstraint extends ForeignKeyConstraint, TName extends string, TConstraints extends SourceConstraintsRecord, TIndexes extends SourceIndexesRecord> = ResolvedTarget<TConstraint["target"]> extends (infer TTarget) ? TTarget extends ForeignKeyTarget ? Exclude<DependenciesOf<TTarget["columns"][number]>, ColumnDependency<SourceIdentity<TTarget["table"]>, string>> extends never ? TargetMetadata<TTarget, TName, TConstraints, TIndexes> extends readonly [infer TTargetConstraints, infer TTargetIndexes] ? HasMatchingConstraint<TTarget["columns"], TTargetConstraints> extends true ? never : HasMatchingIndex<TTarget["columns"], TTargetIndexes> extends true ? never : TConstraint : TConstraint : TConstraint : TConstraint : TConstraint;
|
|
3627
3614
|
type InvalidConstraint<TConstraint, TName extends string, TConstraints extends SourceConstraintsRecord, TIndexes extends SourceIndexesRecord> = TConstraint extends ForeignKeyConstraint ? InvalidForeignKey<TConstraint, TName, TConstraints, TIndexes> : TConstraint extends CheckConstraint<infer TExpression> ? InvalidExpression<TExpression, TName> : never;
|
|
3628
3615
|
type InvalidConstraints<TName extends string, TConstraints extends SourceConstraintsRecord, TIndexes extends SourceIndexesRecord> = TConstraints[keyof TConstraints] extends (infer TConstraint) ? InvalidConstraint<TConstraint, TName, TConstraints, TIndexes> : never;
|
|
3629
3616
|
type InvalidIndex<TIndex, TName extends string> = TIndex extends {
|
|
@@ -3644,7 +3631,7 @@ declare function table<const TName extends string, const TDefinitions extends Ta
|
|
|
3644
3631
|
//#endregion
|
|
3645
3632
|
//#region src/schema/source.d.ts
|
|
3646
3633
|
declare const sourceIdentity: unique symbol;
|
|
3647
|
-
type SourceKind =
|
|
3634
|
+
type SourceKind = "table" | "table-alias" | "query-alias" | "lateral" | "cte" | "excluded" | "custom" | "table-function";
|
|
3648
3635
|
/** SQL semantic domains keyed by the application fields of a source row. */
|
|
3649
3636
|
type SourceSqlTypes<TRow extends object> = { readonly [K in keyof TRow]: AnySqlType; };
|
|
3650
3637
|
/** A source SQL-domain map used when no stronger metadata was declared. */
|
|
@@ -3659,11 +3646,11 @@ interface SourceConfig {
|
|
|
3659
3646
|
readonly constraints?: SourceConstraintsRecord;
|
|
3660
3647
|
}
|
|
3661
3648
|
type SourceConfigValue<TConfig, TKey extends PropertyKey, TFallback> = TKey extends keyof TConfig ? TConfig[TKey] : TFallback;
|
|
3662
|
-
type SourceConfigIdentity<TConfig> = SourceConfigValue<TConfig,
|
|
3663
|
-
type SourceConfigRow<TConfig> = Extract<SourceConfigValue<TConfig,
|
|
3664
|
-
type SourceConfigMetadata<TConfig> = SourceConfigValue<TConfig,
|
|
3665
|
-
type SourceConfigSqlTypes<TConfig> = Extract<SourceConfigValue<TConfig,
|
|
3666
|
-
type SourceConfigConstraints<TConfig> = Extract<SourceConfigValue<TConfig,
|
|
3649
|
+
type SourceConfigIdentity<TConfig> = SourceConfigValue<TConfig, "identity", unknown>;
|
|
3650
|
+
type SourceConfigRow<TConfig> = Extract<SourceConfigValue<TConfig, "row", Record<string, unknown>>, object>;
|
|
3651
|
+
type SourceConfigMetadata<TConfig> = SourceConfigValue<TConfig, "metadata", never>;
|
|
3652
|
+
type SourceConfigSqlTypes<TConfig> = Extract<SourceConfigValue<TConfig, "sqlTypes", UnknownSourceSqlTypes<SourceConfigRow<TConfig>>>, SourceSqlTypes<SourceConfigRow<TConfig>>>;
|
|
3653
|
+
type SourceConfigConstraints<TConfig> = Extract<SourceConfigValue<TConfig, "constraints", {}>, SourceConstraintsRecord>;
|
|
3667
3654
|
interface Source<TConfig extends SourceConfig = {}> extends Fragment<ResultMeta<readonly SourceConfigRow<TConfig>[]> | ProvidesSourceMeta<SourceConfigIdentity<TConfig>, SourceConfigRow<TConfig>> | SourceConfigMetadata<TConfig>> {
|
|
3668
3655
|
/** @internal Type-level configuration retained for inference. */
|
|
3669
3656
|
readonly __sourceConfig?: TConfig;
|
|
@@ -3678,7 +3665,7 @@ interface Source<TConfig extends SourceConfig = {}> extends Fragment<ResultMeta<
|
|
|
3678
3665
|
type AnySource = Source<any>;
|
|
3679
3666
|
/** The source-provision fact carried by a source-producing fragment. */
|
|
3680
3667
|
type SourceProvision<T> = Extract<MetadataOf<T>, {
|
|
3681
|
-
readonly kind:
|
|
3668
|
+
readonly kind: "provides-source";
|
|
3682
3669
|
}>;
|
|
3683
3670
|
type ProvidedSourceIdentity<T> = SourceProvision<T> extends ProvidesSourceMeta<infer TIdentity, any> ? TIdentity : never;
|
|
3684
3671
|
type ProvidedSourceRow<T> = SourceProvision<T> extends ProvidesSourceMeta<any, infer TRow> ? TRow : never;
|
|
@@ -3723,21 +3710,20 @@ declare function createSource<TIdentity, TRow extends object, TMetadata = never,
|
|
|
3723
3710
|
readonly constraints: TConstraints;
|
|
3724
3711
|
}>;
|
|
3725
3712
|
/**
|
|
3726
|
-
* Create a typed source-producing fragment for a custom FROM relation such as
|
|
3727
|
-
*
|
|
3728
|
-
*
|
|
3729
|
-
* remain available to the normal FROM/JOIN scope checks.
|
|
3713
|
+
* Create a typed source-producing fragment for a custom FROM relation such as a table-valued
|
|
3714
|
+
* function. The renderer owns the relation syntax and may bind values through context.parameter();
|
|
3715
|
+
* the source identity and output columns remain available to the normal FROM/JOIN scope checks.
|
|
3730
3716
|
*/
|
|
3731
3717
|
declare function customSource<const TIdentity, const TDefinitions extends TableDefinitions>(options: CustomSourceOptions<TIdentity, TDefinitions>): CustomSource<TIdentity, TDefinitions>;
|
|
3732
3718
|
/**
|
|
3733
|
-
* Add convenient direct column properties without allowing a column name to
|
|
3734
|
-
*
|
|
3719
|
+
* Add convenient direct column properties without allowing a column name to overwrite the source's
|
|
3720
|
+
* rendering or metadata primitives.
|
|
3735
3721
|
*/
|
|
3736
3722
|
declare function exposeColumns(target: object, columns: Record<string, unknown>): void;
|
|
3737
3723
|
//#endregion
|
|
3738
3724
|
//#region src/query/types.d.ts
|
|
3739
3725
|
type Row = Record<string, unknown>;
|
|
3740
|
-
type QueryKind =
|
|
3726
|
+
type QueryKind = "select" | "set" | "insert" | "update" | "delete";
|
|
3741
3727
|
/** Sparse type-level configuration carried by a query. */
|
|
3742
3728
|
interface QueryConfig {
|
|
3743
3729
|
readonly row?: object;
|
|
@@ -3746,11 +3732,11 @@ interface QueryConfig {
|
|
|
3746
3732
|
readonly sqlTypes?: unknown;
|
|
3747
3733
|
}
|
|
3748
3734
|
type QueryConfigValue<TConfig, TKey extends PropertyKey, TFallback> = TKey extends keyof TConfig ? TConfig[TKey] : TFallback;
|
|
3749
|
-
type QueryConfigRow<TConfig> = Extract<QueryConfigValue<TConfig,
|
|
3750
|
-
type QueryConfigCardinality<TConfig> = Extract<QueryConfigValue<TConfig,
|
|
3751
|
-
type QueryConfigMetadata<TConfig> = QueryConfigValue<TConfig,
|
|
3752
|
-
type QueryConfigSqlTypes<TConfig> = QueryConfigValue<TConfig,
|
|
3753
|
-
interface Query
|
|
3735
|
+
type QueryConfigRow<TConfig> = Extract<QueryConfigValue<TConfig, "row", Row>, object>;
|
|
3736
|
+
type QueryConfigCardinality<TConfig> = Extract<QueryConfigValue<TConfig, "cardinality", QueryCardinality>, QueryCardinality>;
|
|
3737
|
+
type QueryConfigMetadata<TConfig> = QueryConfigValue<TConfig, "metadata", never>;
|
|
3738
|
+
type QueryConfigSqlTypes<TConfig> = QueryConfigValue<TConfig, "sqlTypes", SourceSqlTypes<QueryConfigRow<TConfig>>>;
|
|
3739
|
+
interface Query<TConfig extends QueryConfig = {}> extends Fragment<ResultMeta<readonly QueryConfigRow<TConfig>[]> | CardinalityMeta<QueryConfigCardinality<TConfig>> | QueryConfigMetadata<TConfig>> {
|
|
3754
3740
|
/** @internal Type-level configuration retained for inference. */
|
|
3755
3741
|
readonly __queryConfig?: TConfig;
|
|
3756
3742
|
readonly queryKind: QueryKind;
|
|
@@ -3760,8 +3746,8 @@ interface Query$1<TConfig extends QueryConfig = {}> extends Fragment<ResultMeta<
|
|
|
3760
3746
|
/** Type-only SQL domains of the named query projection. */
|
|
3761
3747
|
readonly sqlTypes?: QueryConfigSqlTypes<TConfig>;
|
|
3762
3748
|
}
|
|
3763
|
-
type AnyQuery = Query
|
|
3764
|
-
type QueryWithRow<TRow extends object> = Query
|
|
3749
|
+
type AnyQuery = Query<any>;
|
|
3750
|
+
type QueryWithRow<TRow extends object> = Query<{
|
|
3765
3751
|
readonly row: TRow;
|
|
3766
3752
|
readonly cardinality: any;
|
|
3767
3753
|
readonly metadata: any;
|
|
@@ -3778,33 +3764,33 @@ type QuerySqlTypeMap<T> = T extends {
|
|
|
3778
3764
|
//#endregion
|
|
3779
3765
|
//#region src/core/dialect.d.ts
|
|
3780
3766
|
/** Capabilities whose syntax must be explicitly supported by a dialect. */
|
|
3781
|
-
type DialectCapability =
|
|
3767
|
+
type DialectCapability = "ilike" | "json" | "on-conflict" | "row-locking";
|
|
3782
3768
|
/**
|
|
3783
|
-
* Optional dialect hook used by schema expressions when a JavaScript value
|
|
3784
|
-
*
|
|
3769
|
+
* Optional dialect hook used by schema expressions when a JavaScript value must become SQL text
|
|
3770
|
+
* instead of a query parameter.
|
|
3785
3771
|
*
|
|
3786
|
-
* The hook is deliberately separate from {@link Dialect.placeholder}: schema
|
|
3787
|
-
*
|
|
3772
|
+
* The hook is deliberately separate from {@link Dialect.placeholder}: schema metadata is
|
|
3773
|
+
* parameter-free and must never render a query placeholder.
|
|
3788
3774
|
*/
|
|
3789
3775
|
type SchemaLiteralRenderer = (value: unknown) => string;
|
|
3790
3776
|
/** Scalar application types supported by the portable JSON renderer. */
|
|
3791
|
-
type JsonScalarKind =
|
|
3777
|
+
type JsonScalarKind = "text" | "number" | "boolean";
|
|
3792
3778
|
/** Dialect policy for portable scalar JSON reads and path existence checks. */
|
|
3793
3779
|
interface DialectJson {
|
|
3794
3780
|
renderScalar(context: RenderContext, document: AnyFragment, path: readonly (string | number)[], kind: JsonScalarKind): void;
|
|
3795
3781
|
renderExists(context: RenderContext, document: AnyFragment, path: readonly (string | number)[]): void;
|
|
3796
3782
|
}
|
|
3797
|
-
type PaginationKind =
|
|
3783
|
+
type PaginationKind = "offset" | "fetch";
|
|
3798
3784
|
/** Logical built-in targets that a dialect can spell in CAST expressions. */
|
|
3799
|
-
type PortableCastType =
|
|
3785
|
+
type PortableCastType = "integer" | "decimal" | "text" | "boolean" | "date" | "timestamp" | "uuid" | "json" | "bigint" | "binary";
|
|
3800
3786
|
/** A logical cast target whose concrete spelling is selected by a dialect. */
|
|
3801
3787
|
interface PortableCastTarget<TType extends PortableCastType = PortableCastType> {
|
|
3802
|
-
readonly kind:
|
|
3788
|
+
readonly kind: "portable-cast";
|
|
3803
3789
|
readonly type: TType;
|
|
3804
3790
|
}
|
|
3805
3791
|
/** A trusted raw cast target supplied by a custom definition. */
|
|
3806
3792
|
interface NamedCastTarget<TTypeName extends string = string> {
|
|
3807
|
-
readonly kind:
|
|
3793
|
+
readonly kind: "named-cast";
|
|
3808
3794
|
readonly typeName: TTypeName;
|
|
3809
3795
|
}
|
|
3810
3796
|
/** Runtime target carried by a definition that can be used with cast(). */
|
|
@@ -3814,20 +3800,20 @@ type DialectCastTypes = Readonly<Partial<Record<PortableCastType, string>>>;
|
|
|
3814
3800
|
interface PaginationPart {
|
|
3815
3801
|
readonly kind: PaginationKind;
|
|
3816
3802
|
readonly rows: number;
|
|
3817
|
-
readonly direction?:
|
|
3803
|
+
readonly direction?: "FIRST" | "NEXT";
|
|
3818
3804
|
}
|
|
3819
3805
|
interface DialectPagination {
|
|
3820
3806
|
/** Render a complete pagination group in dialect-specific syntax. */
|
|
3821
3807
|
readonly render: (context: RenderContext, parts: readonly PaginationPart[]) => void;
|
|
3822
3808
|
}
|
|
3823
|
-
type RowLockMode =
|
|
3824
|
-
type RowLockWaitPolicy =
|
|
3809
|
+
type RowLockMode = "update" | "no-key-update" | "share" | "key-share";
|
|
3810
|
+
type RowLockWaitPolicy = "default" | "nowait" | "skip-locked";
|
|
3825
3811
|
interface DialectRowLocking {
|
|
3826
3812
|
/** Render a dialect-supported row-locking clause. */
|
|
3827
3813
|
readonly render: (context: RenderContext, mode: RowLockMode, wait: RowLockWaitPolicy) => void;
|
|
3828
3814
|
}
|
|
3829
3815
|
/** Output modes accepted by first-party EXPLAIN policies. */
|
|
3830
|
-
type ExplainFormat =
|
|
3816
|
+
type ExplainFormat = "text" | "json" | "xml" | "yaml" | "tree" | "traditional" | "query-plan" | "bytecode";
|
|
3831
3817
|
/** Dialect-independent EXPLAIN switches passed to a dialect policy. */
|
|
3832
3818
|
interface ExplainRenderOptions {
|
|
3833
3819
|
readonly analyze?: boolean;
|
|
@@ -3859,7 +3845,7 @@ interface Dialect<TCapabilities extends DialectCapability = DialectCapability> {
|
|
|
3859
3845
|
/** Capabilities advertised by this dialect at the rendering boundary. */
|
|
3860
3846
|
readonly capabilities?: readonly TCapabilities[];
|
|
3861
3847
|
}
|
|
3862
|
-
interface DialectOptions<TCapabilities extends Exclude<DialectCapability,
|
|
3848
|
+
interface DialectOptions<TCapabilities extends Exclude<DialectCapability, "json"> = never, TJson extends DialectJson | undefined = DialectJson | undefined> {
|
|
3863
3849
|
readonly name: string;
|
|
3864
3850
|
readonly quoteIdentifier?: (identifier: string) => string;
|
|
3865
3851
|
readonly placeholder: (position: number) => string;
|
|
@@ -3878,16 +3864,16 @@ interface DialectOptions<TCapabilities extends Exclude<DialectCapability, 'json'
|
|
|
3878
3864
|
/** Resolve a logical or explicitly named CAST target for a dialect. */
|
|
3879
3865
|
declare function resolveCastTarget(dialect: Dialect, target: CastTarget): string;
|
|
3880
3866
|
/**
|
|
3881
|
-
* Create a dialect from the few rendering decisions that SQL builders need
|
|
3882
|
-
*
|
|
3867
|
+
* Create a dialect from the few rendering decisions that SQL builders need to leave open. More
|
|
3868
|
+
* involved syntax can be supplied as a custom fragment.
|
|
3883
3869
|
*/
|
|
3884
|
-
declare function createDialect<const TCapabilities extends Exclude<DialectCapability,
|
|
3870
|
+
declare function createDialect<const TCapabilities extends Exclude<DialectCapability, "json"> = never>(options: DialectOptions<TCapabilities, DialectJson> & {
|
|
3885
3871
|
readonly json: DialectJson;
|
|
3886
|
-
}): Dialect<TCapabilities |
|
|
3887
|
-
declare function createDialect<const TCapabilities extends Exclude<DialectCapability,
|
|
3872
|
+
}): Dialect<TCapabilities | "json">;
|
|
3873
|
+
declare function createDialect<const TCapabilities extends Exclude<DialectCapability, "json"> = never>(options: DialectOptions<TCapabilities, undefined>): Dialect<TCapabilities>;
|
|
3888
3874
|
/**
|
|
3889
|
-
* Check a capability at runtime for callers that intentionally bypass the
|
|
3890
|
-
*
|
|
3875
|
+
* Check a capability at runtime for callers that intentionally bypass the typed render boundary or
|
|
3876
|
+
* use a dialect supplied by an older integration.
|
|
3891
3877
|
*/
|
|
3892
3878
|
declare function assertDialectCapability(dialect: Dialect, capability: DialectCapability): void;
|
|
3893
3879
|
//#endregion
|
|
@@ -3914,7 +3900,7 @@ interface SnapshotNamingPolicy {
|
|
|
3914
3900
|
}
|
|
3915
3901
|
/** A JSON-safe representation of a non-finite JavaScript number. */
|
|
3916
3902
|
interface SnapshotSpecialNumber {
|
|
3917
|
-
readonly $number:
|
|
3903
|
+
readonly $number: "NaN" | "Infinity" | "-Infinity";
|
|
3918
3904
|
}
|
|
3919
3905
|
/** A JSON-safe representation of a JavaScript bigint. */
|
|
3920
3906
|
interface SnapshotBigInt {
|
|
@@ -3932,18 +3918,18 @@ interface SnapshotDialectExtension {
|
|
|
3932
3918
|
}
|
|
3933
3919
|
/** A portable or dialect-owned physical column declaration. */
|
|
3934
3920
|
type SnapshotStorage = {
|
|
3935
|
-
readonly kind:
|
|
3921
|
+
readonly kind: "portable";
|
|
3936
3922
|
readonly type: string;
|
|
3937
3923
|
} | {
|
|
3938
|
-
readonly kind:
|
|
3924
|
+
readonly kind: "native";
|
|
3939
3925
|
readonly dialect: string;
|
|
3940
3926
|
readonly type: string;
|
|
3941
3927
|
/** SQLite's derived type affinity, when the selected adapter records it. */
|
|
3942
|
-
readonly affinity?:
|
|
3928
|
+
readonly affinity?: "blob" | "integer" | "numeric" | "real" | "text";
|
|
3943
3929
|
};
|
|
3944
3930
|
/** A deterministic expression after it crosses the snapshot data boundary. */
|
|
3945
3931
|
interface SnapshotExpression {
|
|
3946
|
-
readonly kind:
|
|
3932
|
+
readonly kind: "expression";
|
|
3947
3933
|
readonly expressionKind: string;
|
|
3948
3934
|
/** Canonical parameter-free text for the selected schema expression dialect. */
|
|
3949
3935
|
readonly sql: string;
|
|
@@ -3952,42 +3938,42 @@ interface SnapshotExpression {
|
|
|
3952
3938
|
}
|
|
3953
3939
|
/** A default value retained independently from insert-write behavior. */
|
|
3954
3940
|
type SnapshotDefault = {
|
|
3955
|
-
readonly kind:
|
|
3941
|
+
readonly kind: "literal";
|
|
3956
3942
|
readonly value: SnapshotLiteral;
|
|
3957
3943
|
} | {
|
|
3958
|
-
readonly kind:
|
|
3944
|
+
readonly kind: "expression";
|
|
3959
3945
|
readonly expression: SnapshotExpression;
|
|
3960
3946
|
} | {
|
|
3961
|
-
readonly kind:
|
|
3947
|
+
readonly kind: "external";
|
|
3962
3948
|
};
|
|
3963
3949
|
/** Canonical literal values accepted by neutral schema metadata. */
|
|
3964
3950
|
type SnapshotLiteral = {
|
|
3965
|
-
readonly kind:
|
|
3951
|
+
readonly kind: "null";
|
|
3966
3952
|
} | {
|
|
3967
|
-
readonly kind:
|
|
3953
|
+
readonly kind: "boolean";
|
|
3968
3954
|
readonly value: boolean;
|
|
3969
3955
|
} | {
|
|
3970
|
-
readonly kind:
|
|
3956
|
+
readonly kind: "string";
|
|
3971
3957
|
readonly value: string;
|
|
3972
3958
|
} | {
|
|
3973
|
-
readonly kind:
|
|
3959
|
+
readonly kind: "number";
|
|
3974
3960
|
readonly value: string;
|
|
3975
3961
|
} | {
|
|
3976
|
-
readonly kind:
|
|
3962
|
+
readonly kind: "bigint";
|
|
3977
3963
|
readonly value: string;
|
|
3978
3964
|
};
|
|
3979
3965
|
/** A generated-column expression and its storage mode. */
|
|
3980
3966
|
type SnapshotGeneratedColumn = {
|
|
3981
|
-
readonly kind:
|
|
3967
|
+
readonly kind: "expression";
|
|
3982
3968
|
readonly expression: SnapshotExpression;
|
|
3983
|
-
readonly mode:
|
|
3969
|
+
readonly mode: "stored" | "virtual";
|
|
3984
3970
|
} | {
|
|
3985
|
-
readonly kind:
|
|
3971
|
+
readonly kind: "external";
|
|
3986
3972
|
};
|
|
3987
3973
|
/** Identity behavior is deliberately separate from generated expressions. */
|
|
3988
3974
|
interface SnapshotIdentity {
|
|
3989
|
-
readonly kind:
|
|
3990
|
-
readonly generation:
|
|
3975
|
+
readonly kind: "identity";
|
|
3976
|
+
readonly generation: "always" | "by-default";
|
|
3991
3977
|
readonly dialect?: SnapshotDialectExtension;
|
|
3992
3978
|
}
|
|
3993
3979
|
/** A canonical column record keyed by its stable logical field ID. */
|
|
@@ -4006,65 +3992,65 @@ interface SnapshotColumn {
|
|
|
4006
3992
|
}
|
|
4007
3993
|
/** An expression or bare column used by an index. */
|
|
4008
3994
|
type SnapshotIndexTermExpression = {
|
|
4009
|
-
readonly kind:
|
|
3995
|
+
readonly kind: "column";
|
|
4010
3996
|
readonly column: string;
|
|
4011
3997
|
} | {
|
|
4012
|
-
readonly kind:
|
|
3998
|
+
readonly kind: "expression";
|
|
4013
3999
|
readonly expression: SnapshotExpression;
|
|
4014
4000
|
};
|
|
4015
4001
|
/** One ordered index term. */
|
|
4016
4002
|
type SnapshotIndexTerm = SnapshotIndexTermExpression | {
|
|
4017
|
-
readonly kind:
|
|
4003
|
+
readonly kind: "order";
|
|
4018
4004
|
readonly expression: SnapshotIndexTermExpression;
|
|
4019
|
-
readonly direction?:
|
|
4020
|
-
readonly nulls?:
|
|
4005
|
+
readonly direction?: "ASC" | "DESC";
|
|
4006
|
+
readonly nulls?: "FIRST" | "LAST";
|
|
4021
4007
|
};
|
|
4022
4008
|
/** Common key metadata shared by primary and strict unique constraints. */
|
|
4023
4009
|
interface SnapshotKeyConstraint {
|
|
4024
4010
|
readonly id: string;
|
|
4025
|
-
readonly kind:
|
|
4011
|
+
readonly kind: "primary-key" | "unique";
|
|
4026
4012
|
readonly physicalName: string;
|
|
4027
4013
|
readonly columns: readonly string[];
|
|
4028
4014
|
readonly deferrable?: boolean;
|
|
4029
|
-
readonly initially?:
|
|
4015
|
+
readonly initially?: "immediate" | "deferred";
|
|
4030
4016
|
readonly dialect?: SnapshotDialectExtension;
|
|
4031
4017
|
}
|
|
4032
4018
|
/** Nullable database uniqueness, intentionally not a candidate-key proof. */
|
|
4033
4019
|
interface SnapshotUniqueConstraint {
|
|
4034
4020
|
readonly id: string;
|
|
4035
|
-
readonly kind:
|
|
4021
|
+
readonly kind: "unique-constraint";
|
|
4036
4022
|
readonly physicalName: string;
|
|
4037
4023
|
readonly columns: readonly string[];
|
|
4038
|
-
readonly nulls:
|
|
4024
|
+
readonly nulls: "distinct" | "not-distinct";
|
|
4039
4025
|
readonly deferrable?: boolean;
|
|
4040
|
-
readonly initially?:
|
|
4026
|
+
readonly initially?: "immediate" | "deferred";
|
|
4041
4027
|
readonly dialect?: SnapshotDialectExtension;
|
|
4042
4028
|
}
|
|
4043
4029
|
/** A foreign key whose target is represented only by logical IDs. */
|
|
4044
4030
|
interface SnapshotForeignKey {
|
|
4045
4031
|
readonly id: string;
|
|
4046
|
-
readonly kind:
|
|
4032
|
+
readonly kind: "foreign-key";
|
|
4047
4033
|
readonly physicalName: string;
|
|
4048
4034
|
readonly columns: readonly string[];
|
|
4049
4035
|
readonly target: {
|
|
4050
4036
|
readonly table: string;
|
|
4051
4037
|
readonly columns: readonly string[];
|
|
4052
4038
|
};
|
|
4053
|
-
readonly onUpdate?:
|
|
4054
|
-
readonly onDelete?:
|
|
4055
|
-
readonly match?:
|
|
4039
|
+
readonly onUpdate?: "no-action" | "restrict" | "cascade" | "set-null" | "set-default";
|
|
4040
|
+
readonly onDelete?: "no-action" | "restrict" | "cascade" | "set-null" | "set-default";
|
|
4041
|
+
readonly match?: "simple" | "full" | "partial";
|
|
4056
4042
|
readonly deferrable?: boolean;
|
|
4057
|
-
readonly initially?:
|
|
4043
|
+
readonly initially?: "immediate" | "deferred";
|
|
4058
4044
|
readonly dialect?: SnapshotDialectExtension;
|
|
4059
4045
|
}
|
|
4060
4046
|
/** A table check constraint with a detached expression value. */
|
|
4061
4047
|
interface SnapshotCheckConstraint {
|
|
4062
4048
|
readonly id: string;
|
|
4063
|
-
readonly kind:
|
|
4049
|
+
readonly kind: "check";
|
|
4064
4050
|
readonly physicalName: string;
|
|
4065
4051
|
readonly expression: SnapshotExpression;
|
|
4066
4052
|
readonly deferrable?: boolean;
|
|
4067
|
-
readonly initially?:
|
|
4053
|
+
readonly initially?: "immediate" | "deferred";
|
|
4068
4054
|
readonly dialect?: SnapshotDialectExtension;
|
|
4069
4055
|
}
|
|
4070
4056
|
/** Every constraint represented by the v1 neutral model. */
|
|
@@ -4072,7 +4058,7 @@ type SnapshotConstraint = SnapshotKeyConstraint | SnapshotUniqueConstraint | Sna
|
|
|
4072
4058
|
/** A canonical index record keyed by its stable logical ID. */
|
|
4073
4059
|
interface SnapshotIndex {
|
|
4074
4060
|
readonly id: string;
|
|
4075
|
-
readonly kind:
|
|
4061
|
+
readonly kind: "index";
|
|
4076
4062
|
readonly physicalName: string;
|
|
4077
4063
|
readonly terms: readonly SnapshotIndexTerm[];
|
|
4078
4064
|
readonly unique: boolean;
|
|
@@ -4100,7 +4086,7 @@ interface SchemaSnapshot {
|
|
|
4100
4086
|
}
|
|
4101
4087
|
/** Schema-expression context supplied to a dialect adapter. */
|
|
4102
4088
|
interface SnapshotExpressionContext {
|
|
4103
|
-
readonly mode:
|
|
4089
|
+
readonly mode: "default" | "generated" | "check" | "index";
|
|
4104
4090
|
readonly path: readonly (string | number)[];
|
|
4105
4091
|
readonly dialect: SchemaDialect;
|
|
4106
4092
|
}
|
|
@@ -4120,17 +4106,16 @@ interface SnapshotValidationContext {
|
|
|
4120
4106
|
readonly dialect: SchemaDialect;
|
|
4121
4107
|
}
|
|
4122
4108
|
/**
|
|
4123
|
-
* Adapter boundary for the common traversal. Schema hooks live on
|
|
4124
|
-
*
|
|
4125
|
-
*
|
|
4126
|
-
* taking ownership of canonical ordering or cross-reference validation.
|
|
4109
|
+
* Adapter boundary for the common traversal. Schema hooks live on `dialect.schema`; the adapter
|
|
4110
|
+
* only selects that schema dialect, so PostgreSQL, SQLite, and MySQL can share the query rendering
|
|
4111
|
+
* policy without taking ownership of canonical ordering or cross-reference validation.
|
|
4127
4112
|
*/
|
|
4128
4113
|
interface SchemaSnapshotAdapter<TCapabilities extends DialectCapability = DialectCapability> {
|
|
4129
4114
|
/** The query dialect plus its schema hooks and metadata. */
|
|
4130
4115
|
readonly dialect: SchemaDialect<TCapabilities>;
|
|
4131
4116
|
}
|
|
4132
4117
|
/** Structured diagnostic categories emitted by snapshot tooling. */
|
|
4133
|
-
type SnapshotDiagnosticCode =
|
|
4118
|
+
type SnapshotDiagnosticCode = "invalid-schema" | "invalid-value" | "unsupported-expression" | "dialect-mismatch" | "unresolved-reference" | "invalid-snapshot" | "unknown-field" | "future-version" | "invalid-cross-reference" | "non-canonical" | "unsupported-dialect-option";
|
|
4134
4119
|
/** A path-addressed snapshot diagnostic suitable for CLI or editor output. */
|
|
4135
4120
|
interface SnapshotDiagnostic {
|
|
4136
4121
|
readonly code: SnapshotDiagnosticCode;
|
|
@@ -4159,4 +4144,4 @@ type SchemaSnapshotInput = SchemaSnapshot | Readonly<Record<string, unknown>>;
|
|
|
4159
4144
|
/** Expose the schema generic in tooling declarations without widening APIs. */
|
|
4160
4145
|
type AnySchema = Schema<any>;
|
|
4161
4146
|
//#endregion
|
|
4162
|
-
export { PaginationKind as $, ExecutionRequest as $a, SchemaObjectNameOptions as $c, rank as $i, InheritedMetadata as $l, AvailableScope as $n, ForeignKeyTargetInput as $o, unsafeSchemaSql as $r, PortableStorageType as $s, PostgresIndexExtension as $t, SnapshotStorage as A, lt as Aa, ExternalGeneratedColumnDescriptor as Ac, RowLockOptions as Ai, ResultField as Al, excluded as An, stream as Ao, groupBy as Ar, ColumnInsertInput as As, SourceSqlTypeMap as At, SqlBoolean as Au, CastTarget as B, Operand as Ba, SchemaLiteralValue as Bc, add as Bi, CapabilityMetadataOf as Bl, MutationReturning as Bn, CatalogCheckExpression as Bo, SchemaExpressionError as Br, ColumnStorageDialectOf as Bs, TableDefinitions as Bt, SqlSemanticType as Bu, SnapshotIndexTerm as C, ComparisonValidation as Ca, ColumnBehaviorErrorCode as Cc, or as Ci, markExpressionCategory as Cl, ConflictTarget as Cn, StreamingTransactionalQueryAdapter as Co, from as Cr, ColumnDefaultOf as Cs, SourceColumns as Ct, fragment as Cu, SnapshotLiteral as D, isDistinctFrom as Da, ExpressionDefaultDescriptor as Dc, omit as Di, ResultDecoder as Dl, OnConflictClause as Dn, executeRows as Do, leftJoin as Dr, ColumnGeneratedOf as Ds, SourceKind as Dt, AnySqlType as Du, SnapshotKeyConstraint as E, gte as Ea, DefaultDescriptor as Ec, SelectPart as Ei, ResultDecodeContext as El, ExcludedSource as En, execute as Eo, innerJoin as Er, ColumnFromOptions as Es, SourceIdentity as Et, sequence as Eu, neutralSnapshotDialect as F, inList as Fa, IdentityDialectExtension as Fc, having as Fi, timestampResultDecoder as Fl, AllowAllClause as Fn, QueryTypeValidation as Fo, all as Fr, ColumnOutput as Fs, exposeColumns as Ft, SqlInteger as Fu, DialectJson as G, typedValue as Ga, generatedColumn as Gc, JsonPath as Gi, Fragment as Gl, allowAll as Gn, ConstraintOptions as Go, SchemaRenderOptions as Gr, ColumnUpdateInput as Gs, TableRow as Gt, SqlUnknown as Gu, DialectCapability as H, OperandSqlType as Ha, canonicalLiteral as Hc, modulo as Hi, CardinalityOf as Hl, MutationRow as Hn, CheckConstraint as Ho, SchemaExpressionInput as Hr, ColumnStorageOf as Hs, TableInsertInput as Ht, SqlTextLike as Hu, schemaSnapshotDialectVersion as I, notIn as Ia, IdentityGeneration as Ic, distinct as Ii, AggregateDependenciesOf as Il, MutationClause as In, QueryValidationError as Io, SchemaDialect as Ir, ColumnSqlType as Is, sourceIdentity as It, SqlJson as Iu, DialectRowLocking as J, cast as Ja, SchemaDialectExtension as Jc, jsonNumber as Ji, GroupingKeysOf as Jl, ReturningSqlTypes as Jn, FieldLikeOptions as Jo, isUnsafeSchemaSql as Jr, NativeStorage as Js, table as Jt, DialectOptions as K, value as Ka, identityColumn as Kc, jsonBoolean as Ki, FragmentMeta as Kl, ReturningClause as Kn, ConstraintTiming as Ko, UnsafeSchemaSqlExpression as Kr, DialectNativeStorage as Ks, TableSqlTypes as Kt, SqlUuid as Ku, schemaSnapshotFormat as L, isNotNull as La, LiteralDefaultDescriptor as Lc, AnySelectClause as Li, AggregateMeta as Ll, MutationKind as Ln, QueryValidationErrorCode as Lo, SchemaDialectHooks as Lr, ColumnStorage as Ls, AnyTable as Lt, SqlNumericLike as Lu, SnapshotTable as M, ne as Ma, GeneratedColumnMode as Mc, fetchFirst as Mi, booleanResultDecoder as Ml, UpdateAssignmentValue as Mn, RenderOptions as Mo, SelectionObject as Mr, ColumnIsNullable as Ms, UnknownSourceSqlTypes as Mt, SqlDecimal as Mu, SnapshotUniqueConstraint as N, notLike as Na, GeneratedDescriptor as Nc, fetchNext as Ni, dateResultDecoder as Nl, UpdateAssignments as Nn, RenderedQuery as No, SelectionOutput as Nr, ColumnOnUpdateOf as Ns, createSource as Nt, SqlEqualityComparable as Nu, SnapshotNamingPolicy as O, isNotDistinctFrom as Oa, ExpressionGeneratedColumnDescriptor as Oc, where as Oi, ResultDecoders as Ol, doNothing as On, explain as Oo, naturalJoin as Or, ColumnHasDefault as Os, SourceProvision as Ot, SqlBigInt as Ou, SnapshotValidationContext as P, between as Pa, IdentityDescriptor as Pc, offset as Pi, jsonTextResultDecoder as Pl, update as Pn, render as Po, SelectionSqlTypes as Pr, ColumnOptions as Ps, customSource as Pt, SqlEqualityCompatible as Pu, NamedCastTarget as Q, ExecutionOptions as Qa, SchemaObjectIdentity as Qc, over as Qi, HasWindow as Ql, AvailableOuterScope as Qn, ForeignKeyTarget as Qo, schemaExpression as Qr, PortableStorageDescriptor as Qs, MysqlIndexExtension as Qt, schemaSnapshotNamingPolicyVersion as R, isNull as Ra, MysqlIdentityExtension as Rc, ClausePlacement as Ri, AnyFragment as Rl, MutationQuery as Rn, QueryValidationIssue as Ro, createSchemaDialect as Rr, ColumnStorageDeclarationOf as Rs, Table as Rt, SqlOrderCompatible as Ru, SnapshotIndex as S, scalar as Sa, ColumnBehaviorError as Sc, not as Si, makeExpression as Sl, ConflictAction as Sn, StreamingQueryAdapter as So, FromSource as Sr, DeclaredColumnNullability as Ss, Source as St, WindowMeta as Su, SnapshotJsonValue as T, gt as Ta, ColumnDefaultInput as Tc, OmittableSelectClause as Ti, DecodableResultType as Tl, DoUpdateAction as Tn, TransactionalQueryAdapter as To, fullJoin as Tr, ColumnDefinitionConfig as Ts, SourceConstraints as Tt, parenthesize as Tu, DialectCastTypes as U, SqlCapabilityValidation as Ua, externalDefault as Uc, multiply as Ui, DependenciesOf as Ul, MutationScopeValidation as Un, CheckConstraintOptions as Uo, SchemaExpressionMode as Ur, ColumnStorageType as Us, TableMetadataCallback as Ut, SqlTimestamp as Uu, Dialect as V, OperandNullability as Va, SqliteIdentityExtension as Vc, divide as Vi, CardinalityMeta as Vl, MutationReturningClause as Vn, CatalogCheckSql as Vo, SchemaExpressionErrorCode as Vr, ColumnStorageKindOf as Vs, TableIdentity as Vt, SqlText as Vu, DialectExplain as W, asValue as Wa, externalGeneratedColumn as Wc, subtract as Wi, ExpressionMeta as Wl, MutationSqlTypes as Wn, ConstraintDialectExtension as Wo, SchemaRenderContext as Wr, ColumnStorageTypeOf as Ws, TableOptions as Wt, SqlTypeSatisfies as Wu, ExplainRenderOptions as X, AdapterExecutionResult as Xa, SchemaMetadataDiagnostic as Xc, jsonText as Xi, HasAggregate as Xl, correlate as Xn, ForeignKeyMatch as Xo, renderSchemaExpression as Xr, PortableColumnStorage as Xs, IndexOptions as Xt, ExplainFormat as Y, typedCast as Ya, SchemaDialectName as Yc, jsonPath as Yi, GroupingMeta as Yl, returning as Yn, ForeignKeyConstraint as Yo, normalizeSchemaSql as Yr, NativeStorageDescriptor as Ys, IndexDialectExtension as Yt, JsonScalarKind as Z, DriverValueEncoder as Za, SchemaMetadataValidationError as Zc, denseRank as Zi, HasSubquery as Zl, select as Zn, ForeignKeyOptions as Zo, renderSchemaSql as Zr, PortableStorage as Zs, IndexTerm as Zt, SnapshotExpressionContext as _, sql as _a, portableStorage as _c, QueryAliasIdentity as _i, ExpressionSqlType as _l, ValuesSource as _n, QubuTransaction as _o, intersect as _r, primaryKey as _s, AnySource as _t, RequiresSourceMeta as _u, SnapshotBigInt as a, call as aa, bigint as ac, SchemaTableNames as ai, materializeSchemaObjectIdentity as al, validateIndexDialect as an, ExplainReadOptions as ao, ScopeValidation as ar, SourceConstraint as as, SchemaLiteralRenderer as at, OutputOf as au, SnapshotGeneratedColumn as b, inQuery as ba, uuid as bc, lateral as bi, SchemaExpressionBrand as bl, insertSelect as bn, QueryExecutor as bo, FromClause as br, uniqueConstraint as bs, ProvidedSourceIdentity as bt, SubqueryMeta as bu, SnapshotConstraint as c, avg as ca, column as cc, SchemaValidationError as ci, ColumnReference as cl, desc as cn, ExplainableQueryAdapter as co, CteSource as cr, SqliteConstraintExtension as cs, resolveCastTarget as ct, ProvidesSourceMeta as cu, SnapshotDefault as d, max as da, integer as dc, schema as di, AnySchemaExpression as dl, order as dn, QubuExplainableStreamingTransactionalClient as do, cte as dr, UniqueConstraintOptions as ds, QueryConfig as dt, RenderFunction as du, rowNumber as ea, StorageDeclarationOf as ec, Schema as ei, assertSchemaDialectSupport as el, SourceIndex as en, ExecutionResult as eo, ClauseScope as er, KeyConstraint as es, PaginationPart as et, InheritedMetadataOf as eu, SnapshotDiagnostic as f, min as fa, json as fc, schemaNamingPolicyVersion as fi, Expression as fl, orderBy as fn, QubuExplainableTransactionalClient as fo, recursiveCte as fr, UniqueNullSemantics as fs, QueryKind as ft, RequiresCapabilityMeta as fu, SnapshotExpression as g, TypedSqlTag as ga, numeric as gc, LateralSource as gi, ExpressionRequires as gl, InsertSource as gn, QubuStreamingTransactionalClient as go, except as gr, foreignKey as gs, Row as gt, RequiresOuterSourceMeta as gu, SnapshotDialectExtension as h, SqlTag as ha, nullable as hc, LateralIdentity as hi, ExpressionOutput as hl, InsertSelectSource as hn, QubuStreamingTransaction as ho, SetQuery as hr, check as hs, QueryWithRow as ht, RequiresOuterOf as hu, SchemaSnapshotInput as i, upper as ia, StorageTypeOf as ic, SchemaTableEntry as ii, isValidSchemaObjectName as il, index as in, ExplainPlanRow as io, RequiredScope as ir, ReferentialAction as is, RowLockWaitPolicy as it, NullableSourcesOf as iu, SnapshotStorageContext as j, lte as ja, GeneratedColumnDescriptor as jc, rowLock as ji, ResultShape as jl, onConflict as jn, RenderCapabilityValidation as jo, Selection as jr, ColumnIsGenerated as js, SourceSqlTypes as jt, SqlDate as ju, SnapshotSpecialNumber as k, like as ka, ExternalDefaultDescriptor as kc, RowLockClause as ki, ResultDecodingError as kl, doUpdate as kn, qubu as ko, rightJoin as kr, ColumnIdentityOf as ks, SourceRow as kt, SqlBinary as ku, SnapshotCreateResult as l, count as la, columnResultValue as lc, defaultSchemaNamingPolicy as li, expressionFragment as ll, nullsFirst as ln, QubuClient as lo, RecursiveCteSource as lr, TableLike as ls, AnyQuery as lt, QueryCardinality as lu, SnapshotDialect as m, SqlFragment as ma, nativeStorage as mc, AliasedSource as mi, ExpressionNullability as ml, DefaultValuesSource as mn, QubuStreamingExplainableClient as mo, SetOperator as mr, catalogForeignKey as ms, QuerySqlTypeMap as mt, RequiresOuterMetadataOf as mu, SchemaSnapshot as n, concat as na, StorageDialectOf as nc, SchemaNamingPolicy as ni, freezeSchemaMetadata as nl, SqliteIndexExtension as nn, ExplainOptions as no, MissingScope as nr, MysqlConstraintExtension as ns, PortableCastType as nt, NullabilityOf as nu, SnapshotCheckConstraint as o, schemaCall as oa, binary as oc, SchemaTableRecord as oi, materializeSchemaObjectRecord as ol, OrderTerm as on, ExplainRequest as oo, SelectCardinality as or, SourceConstraintsRecord as os, assertDialectCapability as ot, ProvidesOuterOf as ou, SnapshotDiagnosticCode as p, sum as pa, nativeColumn as pc, AliasIdentity as pi, ExpressionKind as pl, deleteFrom as pn, QubuStreamingClient as po, withCte as pr, catalogCheck as ps, QueryRow as pt, RequiresOf as pu, DialectPagination as q, mapResult as qa, resolveColumnBehavior as qc, jsonExists as qi, GroupingDependenciesOf as ql, ReturningRow as qn, FieldLike as qo, defineSchemaExpression as qr, NativeColumnStorage as qs, TableUpdateInput as qt, SchemaSnapshotAdapter as r, lower as ra, StorageOf as rc, SchemaOptions as ri, generatedSchemaObjectName as rl, TableIndex as rn, ExplainOptionsFor as ro, RequiredOuterScope as rr, PostgresConstraintExtension as rs, RowLockMode as rt, NullableSourceMeta as ru, SnapshotColumn as s, typedCall as sa, boolean as sc, SchemaTableRegistry as si, ColumnDependency as sl, asc as sn, ExplainResult as so, SelectQuery as sr, SourceLike as ss, createDialect as st, ProvidesOuterSourceMeta as su, AnySchema as t, coalesce as ta, StorageDescriptor as tc, SchemaDiagnostic as ti, dialectMismatchDiagnostic as tl, SourceIndexesRecord as tn, ExplainMutationOptions as to, GroupingValidation as tr, KeyConstraintOptions as ts, PortableCastTarget as tt, MetadataOf as tu, SnapshotDecodeResult as u, countDistinct as ua, date as uc, generatedTableName as ui, AnyExpression as ul, nullsLast as un, QubuExplainableClient as uo, WithClause as ur, UniqueConstraint as us, Query$1 as ut, RenderContext as uu, SnapshotExtensionContext as v, caseWhen as va, text as vc, QuerySource as vi, ExpressionWithOutput as vl, defaultValues as vn, QubuTransactionalClient as vo, union as vr, references as vs, CustomSource as vt, ResultMeta as vu, SnapshotIndexTermExpression as w, eq as wa, ColumnDefault as wc, Omit$1 as wi, withDialectCapability as wl, DoNothingAction as wn, TransactionOptions as wo, crossJoin as wr, ColumnDefinition as ws, SourceConfig as wt, isFragment as wu, SnapshotIdentity as x, notExists as xa, CanonicalLiteral as xc, and as xi, isExpression as xl, values as xn, StreamableQuery as xo, FromScope as xr, validateConstraintDialect as xs, ProvidedSourceRow as xt, VisibleDependenciesOf as xu, SnapshotForeignKey as y, exists as ya, timestamp as yc, alias as yi, SchemaExpression as yl, insertInto as yn, QueryAdapter as yo, unionAll as yr, unique as ys, CustomSourceOptions as yt, SqlTypeOf as yu, schemaSnapshotVersion as z, isTrue as za, ResolvedColumnBehavior as zc, SelectClause as zi, CapabilitiesOf as zl, MutationQueryConfig as zn, AnyKeyColumn as zo, RenderedSchemaExpression as zr, ColumnStorageDescriptor as zs, TableColumns as zt, SqlOrderable as zu };
|
|
4147
|
+
export { PaginationKind as $, SqlTag as $a, RenderCapabilityValidation as $c, SourceIndexesRecord as $i, InheritedMetadata as $l, WithClause as $n, ColumnStorageOf as $o, generatedTableName as $r, canonicalLiteral as $s, nullsLast as $t, SnapshotStorage as A, jsonBoolean as Aa, ExplainableQueryAdapter as Ac, catalogCheck as Ai, ResultField as Al, MutationReturningClause as An, value as Ao, SchemaExpressionErrorCode as Ar, timestamp as As, SourceSqlTypeMap as At, SqlBoolean as Au, CastTarget as B, concat as Ba, QubuTransactionalClient as Bc, AliasedSource as Bi, CapabilityMetadataOf as Bl, select as Bn, ColumnIdentityOf as Bo, renderSchemaSql as Br, ExternalDefaultDescriptor as Bs, TableDefinitions as Bt, SqlSemanticType as Bu, SnapshotIndexTerm as C, SelectClause as Ca, ExplainMutationOptions as Cc, SourceConstraintsRecord as Ci, markExpressionCategory as Cl, update as Cn, isTrue as Co, SelectionSqlTypes as Cr, json as Cs, SourceColumns as Ct, fragment as Cu, SnapshotLiteral as D, multiply as Da, ExplainReadOptions as Dc, UniqueConstraint as Di, ResultDecoder as Dl, MutationQuery as Dn, SqlCapabilityValidation as Do, createSchemaDialect as Dr, numeric as Ds, SourceKind as Dt, AnySqlType as Du, SnapshotKeyConstraint as E, modulo as Ea, ExplainPlanRow as Ec, TableLike as Ei, ResultDecodeContext as El, MutationKind as En, OperandSqlType as Eo, SchemaDialectHooks as Er, nullable as Es, SourceIdentity as Et, sequence as Eu, neutralSnapshotDialect as F, denseRank as Fa, QubuStreamingClient as Fc, references as Fi, timestampResultDecoder as Fl, ReturningClause as Fn, ColumnDefinition as Fo, UnsafeSchemaSqlExpression as Fr, ColumnDefault as Fs, exposeColumns as Ft, SqlInteger as Fu, DialectJson as G, typedCall as Ga, StreamingTransactionalQueryAdapter as Gc, alias as Gi, Fragment as Gl, MissingScope as Gn, ColumnOptions as Go, SchemaNamingPolicy as Gr, IdentityDescriptor as Gs, TableRow as Gt, SqlUnknown as Gu, DialectCapability as H, upper as Ha, QueryExecutor as Hc, LateralSource as Hi, CardinalityOf as Hl, AvailableScope as Hn, ColumnIsGenerated as Ho, unsafeSchemaSql as Hr, GeneratedColumnDescriptor as Hs, TableInsertInput as Ht, SqlTextLike as Hu, schemaSnapshotDialectVersion as I, over as Ia, QubuStreamingExplainableClient as Ic, unique as Ii, AggregateDependenciesOf as Il, ReturningRow as In, ColumnDefinitionConfig as Io, defineSchemaExpression as Ir, ColumnDefaultInput as Is, sourceIdentity as It, SqlJson as Iu, DialectRowLocking as J, countDistinct as Ja, execute as Jc, IndexOptions as Ji, GroupingKeysOf as Jl, ScopeValidation as Jn, ColumnStorage as Jo, SchemaTableNames as Jr, LiteralDefaultDescriptor as Js, table as Jt, DialectOptions as K, avg as Ka, TransactionOptions as Kc, lateral as Ki, FragmentMeta as Kl, RequiredOuterScope as Kn, ColumnOutput as Ko, SchemaOptions as Kr, IdentityDialectExtension as Ks, TableSqlTypes as Kt, SqlUuid as Ku, schemaSnapshotFormat as L, rank as La, QubuStreamingTransaction as Lc, uniqueConstraint as Li, AggregateMeta as Ll, ReturningSqlTypes as Ln, ColumnFromOptions as Lo, isUnsafeSchemaSql as Lr, DefaultDescriptor as Ls, AnyTable as Lt, SqlNumericLike as Lu, SnapshotTable as M, jsonNumber as Ma, QubuExplainableClient as Mc, check as Mi, booleanResultDecoder as Ml, MutationScopeValidation as Mn, cast as Mo, SchemaExpressionMode as Mr, CanonicalLiteral as Ms, UnknownSourceSqlTypes as Mt, SqlDecimal as Mu, SnapshotUniqueConstraint as N, jsonPath as Na, QubuExplainableStreamingTransactionalClient as Nc, foreignKey as Ni, dateResultDecoder as Nl, MutationSqlTypes as Nn, typedCast as No, SchemaRenderContext as Nr, ColumnBehaviorError as Ns, createSource as Nt, SqlEqualityComparable as Nu, SnapshotNamingPolicy as O, subtract as Oa, ExplainRequest as Oc, UniqueConstraintOptions as Oi, ResultDecoders as Ol, MutationQueryConfig as On, asValue as Oo, RenderedSchemaExpression as Or, portableStorage as Os, SourceProvision as Ot, SqlBigInt as Ou, SnapshotValidationContext as P, jsonText as Pa, QubuExplainableTransactionalClient as Pc, primaryKey as Pi, jsonTextResultDecoder as Pl, allowAll as Pn, ColumnDefaultOf as Po, SchemaRenderOptions as Pr, ColumnBehaviorErrorCode as Ps, customSource as Pt, SqlEqualityCompatible as Pu, NamedCastTarget as Q, SqlFragment as Qa, stream as Qc, SourceIndex as Qi, HasWindow as Ql, RecursiveCteSource as Qn, ColumnStorageKindOf as Qo, defaultSchemaNamingPolicy as Qr, SqliteIdentityExtension as Qs, nullsFirst as Qt, schemaSnapshotNamingPolicyVersion as R, rowNumber as Ra, QubuStreamingTransactionalClient as Rc, validateConstraintDialect as Ri, AnyFragment as Rl, returning as Rn, ColumnGeneratedOf as Ro, normalizeSchemaSql as Rr, ExpressionDefaultDescriptor as Rs, Table as Rt, SqlOrderCompatible as Ru, SnapshotIndex as S, ClausePlacement as Sa, ExecutionResult as Sc, SourceConstraint as Si, makeExpression as Sl, UpdateAssignments as Sn, isNull as So, SelectionOutput as Sr, integer as Ss, Source as St, WindowMeta as Su, SnapshotJsonValue as T, divide as Ta, ExplainOptionsFor as Tc, SqliteConstraintExtension as Ti, DecodableResultType as Tl, MutationClause as Tn, OperandNullability as To, SchemaDialect as Tr, nativeStorage as Ts, SourceConstraints as Tt, parenthesize as Tu, DialectCastTypes as U, call as Ua, StreamableQuery as Uc, QueryAliasIdentity as Ui, DependenciesOf as Ul, ClauseScope as Un, ColumnIsNullable as Uo, Schema as Ur, GeneratedColumnMode as Us, TableMetadataCallback as Ut, SqlTimestamp as Uu, Dialect as V, lower as Va, QueryAdapter as Vc, LateralIdentity as Vi, CardinalityMeta as Vl, AvailableOuterScope as Vn, ColumnInsertInput as Vo, schemaExpression as Vr, ExternalGeneratedColumnDescriptor as Vs, TableIdentity as Vt, SqlText as Vu, DialectExplain as W, schemaCall as Wa, StreamingQueryAdapter as Wc, QuerySource as Wi, ExpressionMeta as Wl, GroupingValidation as Wn, ColumnOnUpdateOf as Wo, SchemaDiagnostic as Wr, GeneratedDescriptor as Ws, TableOptions as Wt, SqlTypeSatisfies as Wu, ExplainRenderOptions as X, min as Xa, explain as Xc, MysqlIndexExtension as Xi, HasAggregate as Xl, SelectQuery as Xn, ColumnStorageDescriptor as Xo, SchemaTableRegistry as Xr, ResolvedColumnBehavior as Xs, asc as Xt, ExplainFormat as Y, max as Ya, executeRows as Yc, IndexTerm as Yi, GroupingMeta as Yl, SelectCardinality as Yn, ColumnStorageDeclarationOf as Yo, SchemaTableRecord as Yr, MysqlIdentityExtension as Ys, OrderTerm as Yt, JsonScalarKind as Z, sum as Za, qubu as Zc, PostgresIndexExtension as Zi, HasSubquery as Zl, CteSource as Zn, ColumnStorageDialectOf as Zo, SchemaValidationError as Zr, SchemaLiteralValue as Zs, desc as Zt, SnapshotExpressionContext as _, fetchNext as _a, materializeSchemaObjectRecord as _c, KeyConstraint as _i, ExpressionSqlType as _l, doNothing as _n, notLike as _o, FromScope as _r, binary as _s, AnySource as _t, RequiresSourceMeta as _u, SnapshotBigInt as a, and as aa, SchemaDialectExtension as ac, CheckConstraint as ai, QueryValidationErrorCode as al, InsertSource as an, notExists as ao, except as ar, NativeStorage as as, SchemaLiteralRenderer as at, OutputOf as au, SnapshotGeneratedColumn as b, distinct as ba, ExecutionOptions as bc, PostgresConstraintExtension as bi, SchemaExpressionBrand as bl, onConflict as bn, notIn as bo, Selection as br, columnResultValue as bs, ProvidedSourceIdentity as bt, SubqueryMeta as bu, SnapshotConstraint as c, Omit$1 as ca, SchemaMetadataValidationError as cc, ConstraintOptions as ci, ColumnReference as cl, insertInto as cn, eq as co, unionAll as cr, PortableStorage as cs, resolveCastTarget as ct, ProvidesSourceMeta as cu, SnapshotDefault as d, omit as da, assertSchemaDialectSupport as dc, FieldLikeOptions as di, AnySchemaExpression as dl, ConflictAction as dn, isDistinctFrom as do, innerJoin as dr, StorageDeclarationOf as ds, QueryConfig as dt, RenderFunction as du, SqliteIndexExtension as ea, externalDefault as ec, schema as ei, RenderOptions as el, order as en, TypedSqlTag as eo, cte as er, ColumnStorageType as es, PaginationPart as et, InheritedMetadataOf as eu, SnapshotDiagnostic as f, where as fa, dialectMismatchDiagnostic as fc, ForeignKeyConstraint as fi, Expression as fl, ConflictTarget as fn, isNotDistinctFrom as fo, leftJoin as fr, StorageDescriptor as fs, QueryKind as ft, RequiresCapabilityMeta as fu, SnapshotExpression as g, fetchFirst as ga, materializeSchemaObjectIdentity as gc, ForeignKeyTargetInput as gi, ExpressionRequires as gl, OnConflictClause as gn, ne as go, FromClause as gr, bigint as gs, Row as gt, RequiresOuterSourceMeta as gu, SnapshotDialectExtension as h, rowLock as ha, isValidSchemaObjectName as hc, ForeignKeyTarget as hi, ExpressionOutput as hl, ExcludedSource as hn, lte as ho, groupBy as hr, StorageTypeOf as hs, QueryWithRow as ht, RequiresOuterOf as hu, SchemaSnapshotInput as i, DeclaredColumnNullability as ia, resolveColumnBehavior as ic, CatalogCheckSql as ii, QueryValidationError as il, InsertSelectSource as in, inQuery as io, SetQuery as ir, NativeColumnStorage as is, RowLockWaitPolicy as it, NullableSourcesOf as iu, SnapshotStorageContext as j, jsonExists as ja, QubuClient as jc, catalogForeignKey as ji, ResultShape as jl, MutationRow as jn, mapResult as jo, SchemaExpressionInput as jr, uuid as js, SourceSqlTypes as jt, SqlDate as ju, SnapshotSpecialNumber as k, JsonPath as ka, ExplainResult as kc, UniqueNullSemantics as ki, ResultDecodingError as kl, MutationReturning as kn, typedValue as ko, SchemaExpressionError as kr, text as ks, SourceRow as kt, SqlBinary as ku, SnapshotCreateResult as l, OmittableSelectClause as la, SchemaObjectIdentity as lc, ConstraintTiming as li, expressionFragment as ll, insertSelect as ln, gt as lo, crossJoin as lr, PortableStorageDescriptor as ls, AnyQuery as lt, QueryCardinality as lu, SnapshotDialect as m, RowLockOptions as ma, generatedSchemaObjectName as mc, ForeignKeyOptions as mi, ExpressionNullability as ml, DoUpdateAction as mn, lt as mo, rightJoin as mr, StorageOf as ms, QuerySqlTypeMap as mt, RequiresOuterMetadataOf as mu, SchemaSnapshot as n, index as na, generatedColumn as nc, AnyKeyColumn as ni, render as nl, deleteFrom as nn, caseWhen as no, withCte as nr, ColumnUpdateInput as ns, PortableCastType as nt, NullabilityOf as nu, SnapshotCheckConstraint as o, not as oa, SchemaDialectName as oc, CheckConstraintOptions as oi, QueryValidationIssue as ol, ValuesSource as on, scalar as oo, intersect as or, NativeStorageDescriptor as os, assertDialectCapability as ot, ProvidesOuterOf as ou, SnapshotDiagnosticCode as p, RowLockClause as pa, freezeSchemaMetadata as pc, ForeignKeyMatch as pi, ExpressionKind as pl, DoNothingAction as pn, like as po, naturalJoin as pr, StorageDialectOf as ps, QueryRow as pt, RequiresOf as pu, DialectPagination as q, count as qa, TransactionalQueryAdapter as qc, IndexDialectExtension as qi, GroupingDependenciesOf as ql, RequiredScope as qn, ColumnSqlType as qo, SchemaTableEntry as qr, IdentityGeneration as qs, TableUpdateInput as qt, SchemaSnapshotAdapter as r, validateIndexDialect as ra, identityColumn as rc, CatalogCheckExpression as ri, QueryTypeValidation as rl, DefaultValuesSource as rn, exists as ro, SetOperator as rr, DialectNativeStorage as rs, RowLockMode as rt, NullableSourceMeta as ru, SnapshotColumn as s, or as sa, SchemaMetadataDiagnostic as sc, ConstraintDialectExtension as si, ColumnDependency as sl, defaultValues as sn, ComparisonValidation as so, union as sr, PortableColumnStorage as ss, createDialect as st, ProvidesOuterSourceMeta as su, AnySchema as t, TableIndex as ta, externalGeneratedColumn as tc, schemaNamingPolicyVersion as ti, RenderedQuery as tl, orderBy as tn, sql as to, recursiveCte as tr, ColumnStorageTypeOf as ts, PortableCastTarget as tt, MetadataOf as tu, SnapshotDecodeResult as u, SelectPart as ua, SchemaObjectNameOptions as uc, FieldLike as ui, AnyExpression as ul, values as un, gte as uo, fullJoin as ur, PortableStorageType as us, Query as ut, RenderContext as uu, SnapshotExtensionContext as v, offset as va, AdapterExecutionResult as vc, KeyConstraintOptions as vi, ExpressionWithOutput as vl, doUpdate as vn, between as vo, FromSource as vr, boolean as vs, CustomSource as vt, ResultMeta as vu, SnapshotIndexTermExpression as w, add as wa, ExplainOptions as wc, SourceLike as wi, withDialectCapability as wl, AllowAllClause as wn, Operand as wo, all as wr, nativeColumn as ws, SourceConfig as wt, isFragment as wu, SnapshotIdentity as x, AnySelectClause as xa, ExecutionRequest as xc, ReferentialAction as xi, isExpression as xl, UpdateAssignmentValue as xn, isNotNull as xo, SelectionObject as xr, date as xs, ProvidedSourceRow as xt, VisibleDependenciesOf as xu, SnapshotForeignKey as y, having as ya, DriverValueEncoder as yc, MysqlConstraintExtension as yi, SchemaExpression as yl, excluded as yn, inList as yo, from as yr, column as ys, CustomSourceOptions as yt, SqlTypeOf as yu, schemaSnapshotVersion as z, coalesce as za, QubuTransaction as zc, AliasIdentity as zi, CapabilitiesOf as zl, correlate as zn, ColumnHasDefault as zo, renderSchemaExpression as zr, ExpressionGeneratedColumnDescriptor as zs, TableColumns as zt, SqlOrderable as zu };
|