effect-qb 0.14.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mysql.js +61555 -4252
- package/dist/postgres/metadata.js +728 -104
- package/dist/postgres.js +6906 -4023
- package/package.json +15 -2
- package/src/internal/aggregation-validation.ts +3 -3
- package/src/internal/case-analysis.d.ts +18 -0
- package/src/internal/case-analysis.ts +4 -4
- package/src/internal/coercion/analysis.d.ts +7 -0
- package/src/internal/{coercion-analysis.ts → coercion/analysis.ts} +3 -3
- package/src/internal/coercion/errors.d.ts +17 -0
- package/src/internal/{coercion-errors.ts → coercion/errors.ts} +1 -1
- package/src/internal/coercion/kind.d.ts +4 -0
- package/src/internal/{coercion-kind.ts → coercion/kind.ts} +2 -2
- package/src/internal/{coercion-normalize.ts → coercion/normalize.ts} +1 -1
- package/src/internal/coercion/rules.d.ts +6 -0
- package/src/internal/{coercion-rules.ts → coercion/rules.ts} +2 -2
- package/src/internal/column-state.d.ts +190 -0
- package/src/internal/column-state.ts +43 -47
- package/src/internal/column.ts +43 -305
- package/src/internal/datatypes/define.d.ts +17 -0
- package/src/internal/datatypes/define.ts +18 -4
- package/src/internal/datatypes/lookup.d.ts +44 -0
- package/src/internal/datatypes/lookup.ts +61 -152
- package/src/internal/datatypes/shape.d.ts +16 -0
- package/src/internal/datatypes/shape.ts +1 -1
- package/src/internal/derived-table.d.ts +4 -0
- package/src/internal/derived-table.ts +21 -16
- package/src/internal/dialect.ts +12 -1
- package/src/internal/dsl-mutation-runtime.ts +378 -0
- package/src/internal/dsl-plan-runtime.ts +387 -0
- package/src/internal/dsl-query-runtime.ts +160 -0
- package/src/internal/dsl-transaction-ddl-runtime.ts +263 -0
- package/src/internal/executor.ts +146 -34
- package/src/internal/expression-ast.ts +15 -5
- package/src/internal/grouping-key.d.ts +3 -0
- package/src/internal/grouping-key.ts +1 -1
- package/src/internal/implication-runtime.d.ts +15 -0
- package/src/internal/implication-runtime.ts +4 -4
- package/src/internal/json/ast.d.ts +30 -0
- package/src/internal/json/ast.ts +1 -1
- package/src/internal/json/errors.d.ts +8 -0
- package/src/internal/json/path.d.ts +75 -0
- package/src/internal/json/path.ts +1 -1
- package/src/internal/json/types.d.ts +62 -0
- package/src/internal/predicate/analysis.d.ts +20 -0
- package/src/internal/predicate/analysis.ts +183 -0
- package/src/internal/predicate/atom.d.ts +28 -0
- package/src/internal/{predicate-atom.ts → predicate/atom.ts} +7 -0
- package/src/internal/{predicate-branches.ts → predicate/branches.ts} +2 -2
- package/src/internal/predicate/context.d.ts +67 -0
- package/src/internal/{predicate-context.ts → predicate/context.ts} +163 -20
- package/src/internal/predicate/formula.d.ts +35 -0
- package/src/internal/{predicate-formula.ts → predicate/formula.ts} +1 -1
- package/src/internal/predicate/key.d.ts +11 -0
- package/src/internal/predicate/key.ts +73 -0
- package/src/internal/{predicate-nnf.ts → predicate/nnf.ts} +2 -2
- package/src/internal/predicate/normalize.d.ts +53 -0
- package/src/internal/{predicate-normalize.ts → predicate/normalize.ts} +130 -49
- package/src/internal/predicate/runtime.d.ts +31 -0
- package/src/internal/{predicate-runtime.ts → predicate/runtime.ts} +127 -17
- package/src/internal/projection-alias.d.ts +13 -0
- package/src/internal/projections.d.ts +31 -0
- package/src/internal/projections.ts +1 -1
- package/src/internal/query-ast.d.ts +217 -0
- package/src/internal/query-ast.ts +1 -1
- package/src/internal/query-requirements.d.ts +20 -0
- package/src/internal/query.d.ts +775 -0
- package/src/internal/query.ts +683 -369
- package/src/internal/renderer.ts +11 -21
- package/src/internal/row-set.d.ts +53 -0
- package/src/internal/{plan.ts → row-set.ts} +11 -9
- package/src/internal/runtime/driver-value-mapping.ts +186 -0
- package/src/internal/{runtime-normalize.ts → runtime/normalize.ts} +9 -31
- package/src/internal/{runtime-schema.ts → runtime/schema.ts} +13 -38
- package/src/internal/runtime/value.d.ts +22 -0
- package/src/internal/{runtime-value.ts → runtime/value.ts} +2 -2
- package/src/internal/scalar.d.ts +107 -0
- package/src/internal/scalar.ts +202 -0
- package/src/internal/schema-derivation.d.ts +105 -0
- package/src/internal/schema-expression.d.ts +18 -0
- package/src/internal/schema-expression.ts +38 -7
- package/src/internal/table-options.d.ts +94 -0
- package/src/internal/table-options.ts +8 -2
- package/src/internal/table.d.ts +173 -0
- package/src/internal/table.ts +32 -14
- package/src/mysql/column.ts +95 -18
- package/src/mysql/datatypes/index.ts +47 -7
- package/src/mysql/errors/generated.ts +57336 -0
- package/src/mysql/errors/index.ts +1 -0
- package/src/mysql/errors/normalize.ts +55 -53
- package/src/mysql/errors/types.ts +74 -0
- package/src/mysql/executor.ts +88 -11
- package/src/mysql/function/aggregate.ts +1 -5
- package/src/mysql/function/core.ts +1 -4
- package/src/mysql/function/index.ts +0 -1
- package/src/mysql/function/string.ts +1 -5
- package/src/mysql/function/temporal.ts +12 -15
- package/src/mysql/function/window.ts +1 -6
- package/src/{internal/mysql-dialect.ts → mysql/internal/dialect.ts} +12 -6
- package/src/{internal/mysql-query.ts → mysql/internal/dsl.ts} +1299 -2143
- package/src/mysql/internal/renderer.ts +46 -0
- package/src/mysql/internal/sql-expression-renderer.ts +1501 -0
- package/src/mysql/json.ts +2 -0
- package/src/mysql/query.ts +111 -91
- package/src/mysql/renderer.ts +8 -3
- package/src/mysql/table.ts +1 -1
- package/src/mysql.ts +6 -4
- package/src/postgres/cast.ts +30 -16
- package/src/postgres/column.ts +179 -46
- package/src/postgres/datatypes/index.d.ts +515 -0
- package/src/postgres/datatypes/index.ts +22 -13
- package/src/postgres/datatypes/spec.d.ts +412 -0
- package/src/postgres/errors/generated.ts +2636 -0
- package/src/postgres/errors/index.ts +1 -0
- package/src/postgres/errors/normalize.ts +47 -62
- package/src/postgres/errors/types.ts +92 -34
- package/src/postgres/executor.ts +54 -7
- package/src/postgres/function/aggregate.ts +1 -5
- package/src/postgres/function/core.ts +12 -6
- package/src/postgres/function/index.ts +0 -1
- package/src/postgres/function/string.ts +1 -5
- package/src/postgres/function/temporal.ts +12 -15
- package/src/postgres/function/window.ts +1 -6
- package/src/{internal/postgres-dialect.ts → postgres/internal/dialect.ts} +12 -6
- package/src/{internal/postgres-query.ts → postgres/internal/dsl.ts} +1356 -2133
- package/src/{internal/postgres-renderer.ts → postgres/internal/renderer.ts} +17 -8
- package/src/postgres/internal/schema-ddl.ts +108 -0
- package/src/{internal/postgres-schema-model.ts → postgres/internal/schema-model.ts} +12 -6
- package/src/{internal → postgres/internal}/sql-expression-renderer.ts +79 -25
- package/src/postgres/{function/json.ts → json.ts} +77 -85
- package/src/postgres/metadata.ts +2 -2
- package/src/postgres/query.ts +113 -89
- package/src/postgres/renderer.ts +8 -13
- package/src/postgres/schema-expression.ts +2 -1
- package/src/postgres/schema-management.ts +1 -1
- package/src/postgres/table.ts +12 -4
- package/src/postgres/type.ts +33 -2
- package/src/postgres.ts +6 -4
- package/src/internal/expression.ts +0 -327
- package/src/internal/mysql-renderer.ts +0 -37
- package/src/internal/predicate-analysis.ts +0 -81
- package/src/internal/predicate-key.ts +0 -28
- package/src/internal/schema-ddl.ts +0 -55
- package/src/mysql/function/json.ts +0 -4
- package/src/mysql/private/query.ts +0 -1
- package/src/postgres/private/query.ts +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { EqColumnAtom, EqLiteralAtom, NeqLiteralAtom, NonNullAtom, NullAtom, PredicateAtom, UnknownAtom } from "./
|
|
2
|
-
import type { AllFormula, AnyFormula, AtomFormula, FalseFormula, NotFormula, PredicateFormula, TrueFormula } from "./
|
|
1
|
+
import type { EqColumnAtom, EqLiteralAtom, LiteralSetAtom, NeqLiteralAtom, NonNullAtom, NullAtom, PredicateAtom, UnknownAtom } from "./atom.js"
|
|
2
|
+
import type { AllFormula, AnyFormula, AtomFormula, FalseFormula, NotFormula, PredicateFormula, TrueFormula } from "./formula.js"
|
|
3
3
|
|
|
4
4
|
type Polarity = "positive" | "negative"
|
|
5
5
|
|
|
@@ -8,6 +8,8 @@ export interface Context<
|
|
|
8
8
|
NullKeys extends string = never,
|
|
9
9
|
EqLiterals = {},
|
|
10
10
|
NeqLiterals = {},
|
|
11
|
+
LiteralSets = {},
|
|
12
|
+
JsonLiteralSets = {},
|
|
11
13
|
SourceNames extends string = never,
|
|
12
14
|
Contradiction extends boolean = false,
|
|
13
15
|
Unknown extends boolean = false
|
|
@@ -16,6 +18,8 @@ export interface Context<
|
|
|
16
18
|
readonly nullKeys: NullKeys
|
|
17
19
|
readonly eqLiterals: EqLiterals
|
|
18
20
|
readonly neqLiterals: NeqLiterals
|
|
21
|
+
readonly literalSets: LiteralSets
|
|
22
|
+
readonly jsonLiteralSets: JsonLiteralSets
|
|
19
23
|
readonly sourceNames: SourceNames
|
|
20
24
|
readonly contradiction: Contradiction
|
|
21
25
|
readonly unknown: Unknown
|
|
@@ -27,6 +31,8 @@ type AnyContext = Context<
|
|
|
27
31
|
string,
|
|
28
32
|
Record<string, string>,
|
|
29
33
|
Record<string, string>,
|
|
34
|
+
Record<string, string>,
|
|
35
|
+
Record<string, Record<string, string>>,
|
|
30
36
|
string,
|
|
31
37
|
boolean,
|
|
32
38
|
boolean
|
|
@@ -84,15 +90,75 @@ type MergeNeqLiteralMaps<Left, Right> = {
|
|
|
84
90
|
: never
|
|
85
91
|
}
|
|
86
92
|
|
|
93
|
+
type MergeLiteralSetMaps<Left, Right> = {
|
|
94
|
+
readonly [K in Extract<keyof Left | keyof Right, string>]:
|
|
95
|
+
K extends keyof Left
|
|
96
|
+
? K extends keyof Right
|
|
97
|
+
? Extract<Left[K], Right[K]>
|
|
98
|
+
: Left[K]
|
|
99
|
+
: K extends keyof Right
|
|
100
|
+
? Right[K]
|
|
101
|
+
: never
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
type MergeJsonLiteralSetPathMaps<Left, Right> = {
|
|
105
|
+
readonly [K in Extract<keyof Left | keyof Right, string>]:
|
|
106
|
+
K extends keyof Left
|
|
107
|
+
? K extends keyof Right
|
|
108
|
+
? Extract<Left[K], Right[K]>
|
|
109
|
+
: Left[K]
|
|
110
|
+
: K extends keyof Right
|
|
111
|
+
? Right[K]
|
|
112
|
+
: never
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
type MergeJsonLiteralSetMaps<Left, Right> = {
|
|
116
|
+
readonly [K in Extract<keyof Left | keyof Right, string>]:
|
|
117
|
+
K extends keyof Left
|
|
118
|
+
? K extends keyof Right
|
|
119
|
+
? MergeJsonLiteralSetPathMaps<Left[K], Right[K]>
|
|
120
|
+
: Left[K]
|
|
121
|
+
: K extends keyof Right
|
|
122
|
+
? Right[K]
|
|
123
|
+
: never
|
|
124
|
+
}
|
|
125
|
+
|
|
87
126
|
type FilterNeverValues<Map> = {
|
|
88
127
|
readonly [K in keyof Map as Map[K] extends never ? never : K]: Map[K]
|
|
89
128
|
}
|
|
90
129
|
|
|
130
|
+
type JsonKeyParts<Key extends string> = string extends Key
|
|
131
|
+
? never
|
|
132
|
+
: Key extends `${infer ColumnKey}#json:${infer Path}`
|
|
133
|
+
? readonly [ColumnKey, Path]
|
|
134
|
+
: never
|
|
135
|
+
|
|
136
|
+
type LiteralSetMapAfterAdd<
|
|
137
|
+
LiteralSets,
|
|
138
|
+
Key extends string,
|
|
139
|
+
Values extends string
|
|
140
|
+
> = [JsonKeyParts<Key>] extends [never]
|
|
141
|
+
? FilterNeverValues<MergeLiteralSetMaps<LiteralSets, { readonly [K in Key]: Values }>>
|
|
142
|
+
: LiteralSets
|
|
143
|
+
|
|
144
|
+
type JsonLiteralSetMapAfterAdd<
|
|
145
|
+
JsonLiteralSets,
|
|
146
|
+
Key extends string,
|
|
147
|
+
Values extends string
|
|
148
|
+
> = JsonKeyParts<Key> extends readonly [infer ColumnKey extends string, infer Path extends string]
|
|
149
|
+
? MergeJsonLiteralSetMaps<
|
|
150
|
+
JsonLiteralSets,
|
|
151
|
+
{ readonly [C in ColumnKey]: { readonly [P in Path]: Values } }
|
|
152
|
+
>
|
|
153
|
+
: JsonLiteralSets
|
|
154
|
+
|
|
91
155
|
type MarkContradiction<Ctx extends AnyContext> = Context<
|
|
92
156
|
Ctx["nonNullKeys"],
|
|
93
157
|
Ctx["nullKeys"],
|
|
94
158
|
Ctx["eqLiterals"],
|
|
95
159
|
Ctx["neqLiterals"],
|
|
160
|
+
Ctx["literalSets"],
|
|
161
|
+
Ctx["jsonLiteralSets"],
|
|
96
162
|
Ctx["sourceNames"],
|
|
97
163
|
true,
|
|
98
164
|
Ctx["unknown"]
|
|
@@ -103,6 +169,8 @@ type MarkUnknown<Ctx extends AnyContext> = Context<
|
|
|
103
169
|
Ctx["nullKeys"],
|
|
104
170
|
Ctx["eqLiterals"],
|
|
105
171
|
Ctx["neqLiterals"],
|
|
172
|
+
Ctx["literalSets"],
|
|
173
|
+
Ctx["jsonLiteralSets"],
|
|
106
174
|
Ctx["sourceNames"],
|
|
107
175
|
Ctx["contradiction"],
|
|
108
176
|
true
|
|
@@ -116,6 +184,8 @@ type AddNonNull<
|
|
|
116
184
|
Ctx["nullKeys"],
|
|
117
185
|
Ctx["eqLiterals"],
|
|
118
186
|
Ctx["neqLiterals"],
|
|
187
|
+
Ctx["literalSets"],
|
|
188
|
+
Ctx["jsonLiteralSets"],
|
|
119
189
|
Ctx["sourceNames"] | SourceNameOfKey<Key>,
|
|
120
190
|
Key extends Ctx["nullKeys"] ? true : Ctx["contradiction"],
|
|
121
191
|
Ctx["unknown"]
|
|
@@ -129,11 +199,35 @@ type AddNull<
|
|
|
129
199
|
Ctx["nullKeys"] | Key,
|
|
130
200
|
Ctx["eqLiterals"],
|
|
131
201
|
Ctx["neqLiterals"],
|
|
202
|
+
Ctx["literalSets"],
|
|
203
|
+
Ctx["jsonLiteralSets"],
|
|
132
204
|
Ctx["sourceNames"] | SourceNameOfKey<Key>,
|
|
133
205
|
Key extends Ctx["nonNullKeys"] ? true : Ctx["contradiction"],
|
|
134
206
|
Ctx["unknown"]
|
|
135
207
|
>
|
|
136
208
|
|
|
209
|
+
type AddLiteralSet<
|
|
210
|
+
Ctx extends AnyContext,
|
|
211
|
+
Key extends string,
|
|
212
|
+
Values extends string
|
|
213
|
+
> = Context<
|
|
214
|
+
Ctx["nonNullKeys"] | Key,
|
|
215
|
+
Ctx["nullKeys"],
|
|
216
|
+
Ctx["eqLiterals"],
|
|
217
|
+
Ctx["neqLiterals"],
|
|
218
|
+
LiteralSetMapAfterAdd<Ctx["literalSets"], Key, Values>,
|
|
219
|
+
JsonLiteralSetMapAfterAdd<Ctx["jsonLiteralSets"], Key, Values>,
|
|
220
|
+
Ctx["sourceNames"] | SourceNameOfKey<Key>,
|
|
221
|
+
EqLiteralValueOf<Ctx["eqLiterals"], Key> extends infer EqValue
|
|
222
|
+
? [EqValue] extends [never]
|
|
223
|
+
? Key extends Ctx["nullKeys"] ? true : Ctx["contradiction"]
|
|
224
|
+
: EqValue extends Values
|
|
225
|
+
? Key extends Ctx["nullKeys"] ? true : Ctx["contradiction"]
|
|
226
|
+
: true
|
|
227
|
+
: true,
|
|
228
|
+
Ctx["unknown"]
|
|
229
|
+
>
|
|
230
|
+
|
|
137
231
|
type AddEqLiteral<
|
|
138
232
|
Ctx extends AnyContext,
|
|
139
233
|
Key extends string,
|
|
@@ -143,6 +237,8 @@ type AddEqLiteral<
|
|
|
143
237
|
Ctx["nullKeys"],
|
|
144
238
|
FilterNeverValues<MergeEqLiteralMaps<Ctx["eqLiterals"], { readonly [K in Key]: Value }>>,
|
|
145
239
|
Ctx["neqLiterals"],
|
|
240
|
+
LiteralSetMapAfterAdd<Ctx["literalSets"], Key, Value>,
|
|
241
|
+
JsonLiteralSetMapAfterAdd<Ctx["jsonLiteralSets"], Key, Value>,
|
|
146
242
|
Ctx["sourceNames"] | SourceNameOfKey<Key>,
|
|
147
243
|
EqLiteralValueOf<Ctx["eqLiterals"], Key> extends never
|
|
148
244
|
? NeqLiteralValuesOf<Ctx["neqLiterals"], Key> extends infer NeqValues
|
|
@@ -169,6 +265,8 @@ type AddNeqLiteral<
|
|
|
169
265
|
Ctx["nullKeys"],
|
|
170
266
|
Ctx["eqLiterals"],
|
|
171
267
|
FilterNeverValues<MergeNeqLiteralMaps<Ctx["neqLiterals"], { readonly [K in Key]: Value }>>,
|
|
268
|
+
Ctx["literalSets"],
|
|
269
|
+
Ctx["jsonLiteralSets"],
|
|
172
270
|
Ctx["sourceNames"] | SourceNameOfKey<Key>,
|
|
173
271
|
EqLiteralValueOf<Ctx["eqLiterals"], Key> extends infer EqValue
|
|
174
272
|
? [EqValue] extends [never]
|
|
@@ -219,11 +317,13 @@ type ApplyAtom<
|
|
|
219
317
|
? AddEqLiteral<Ctx, Key, Value>
|
|
220
318
|
: Atom extends NeqLiteralAtom<infer Key extends string, infer Value extends string>
|
|
221
319
|
? AddNeqLiteral<Ctx, Key, Value>
|
|
222
|
-
: Atom extends
|
|
223
|
-
?
|
|
224
|
-
: Atom extends
|
|
225
|
-
?
|
|
226
|
-
:
|
|
320
|
+
: Atom extends LiteralSetAtom<infer Key extends string, infer Values extends string>
|
|
321
|
+
? AddLiteralSet<Ctx, Key, Values>
|
|
322
|
+
: Atom extends EqColumnAtom<infer Left extends string, infer Right extends string>
|
|
323
|
+
? ApplyEqColumn<Ctx, Left, Right>
|
|
324
|
+
: Atom extends UnknownAtom<any>
|
|
325
|
+
? MarkUnknown<Ctx>
|
|
326
|
+
: Ctx
|
|
227
327
|
|
|
228
328
|
type ApplyNegativeAtom<
|
|
229
329
|
Ctx extends AnyContext,
|
|
@@ -237,18 +337,23 @@ type ApplyNegativeAtom<
|
|
|
237
337
|
? AddNeqLiteral<Ctx, Key, Value>
|
|
238
338
|
: Atom extends NeqLiteralAtom<infer Key extends string, infer Value extends string>
|
|
239
339
|
? AddEqLiteral<Ctx, Key, Value>
|
|
240
|
-
: Atom extends
|
|
241
|
-
? AddNonNull<
|
|
242
|
-
: Atom extends
|
|
243
|
-
?
|
|
244
|
-
:
|
|
340
|
+
: Atom extends LiteralSetAtom<infer Key extends string, any>
|
|
341
|
+
? AddNonNull<Ctx, Key>
|
|
342
|
+
: Atom extends EqColumnAtom<infer Left extends string, infer Right extends string>
|
|
343
|
+
? AddNonNull<AddNonNull<Ctx, Left>, Right>
|
|
344
|
+
: Atom extends UnknownAtom<any>
|
|
345
|
+
? MarkUnknown<Ctx>
|
|
346
|
+
: Ctx
|
|
245
347
|
|
|
246
348
|
type FramesFromItems<
|
|
247
349
|
Items extends readonly PredicateFormula[],
|
|
248
350
|
Direction extends Polarity
|
|
249
|
-
> =
|
|
250
|
-
|
|
251
|
-
|
|
351
|
+
> = Items extends readonly [
|
|
352
|
+
infer Head extends PredicateFormula,
|
|
353
|
+
...infer Tail extends readonly PredicateFormula[]
|
|
354
|
+
]
|
|
355
|
+
? readonly [Frame<Head, Direction>, ...FramesFromItems<Tail, Direction>]
|
|
356
|
+
: readonly []
|
|
252
357
|
|
|
253
358
|
type IntersectEqLiteralMaps<
|
|
254
359
|
Left,
|
|
@@ -265,6 +370,27 @@ type IntersectNeqLiteralMaps<
|
|
|
265
370
|
Extract<Left[K], Right[K]> extends never ? never : Extract<Left[K], Right[K]>
|
|
266
371
|
}>
|
|
267
372
|
|
|
373
|
+
type UnionLiteralSetMaps<
|
|
374
|
+
Left,
|
|
375
|
+
Right
|
|
376
|
+
> = FilterNeverValues<{
|
|
377
|
+
readonly [K in Extract<keyof Left, keyof Right>]: Left[K] | Right[K]
|
|
378
|
+
}>
|
|
379
|
+
|
|
380
|
+
type UnionJsonLiteralSetPathMaps<
|
|
381
|
+
Left,
|
|
382
|
+
Right
|
|
383
|
+
> = FilterNeverValues<{
|
|
384
|
+
readonly [K in Extract<keyof Left, keyof Right>]: Left[K] | Right[K]
|
|
385
|
+
}>
|
|
386
|
+
|
|
387
|
+
type UnionJsonLiteralSetMaps<
|
|
388
|
+
Left,
|
|
389
|
+
Right
|
|
390
|
+
> = {
|
|
391
|
+
readonly [K in Extract<keyof Left, keyof Right>]: UnionJsonLiteralSetPathMaps<Left[K], Right[K]>
|
|
392
|
+
}
|
|
393
|
+
|
|
268
394
|
type IntersectContexts<
|
|
269
395
|
Left extends AnyContext,
|
|
270
396
|
Right extends AnyContext
|
|
@@ -273,6 +399,8 @@ type IntersectContexts<
|
|
|
273
399
|
Extract<Left["nullKeys"], Right["nullKeys"]>,
|
|
274
400
|
IntersectEqLiteralMaps<Left["eqLiterals"], Right["eqLiterals"]>,
|
|
275
401
|
IntersectNeqLiteralMaps<Left["neqLiterals"], Right["neqLiterals"]>,
|
|
402
|
+
UnionLiteralSetMaps<Left["literalSets"], Right["literalSets"]>,
|
|
403
|
+
UnionJsonLiteralSetMaps<Left["jsonLiteralSets"], Right["jsonLiteralSets"]>,
|
|
276
404
|
Extract<Left["sourceNames"], Right["sourceNames"]>,
|
|
277
405
|
Left["contradiction"] extends true
|
|
278
406
|
? Right["contradiction"]
|
|
@@ -286,17 +414,20 @@ type AnalyzeAnyBranches<
|
|
|
286
414
|
Ctx extends AnyContext,
|
|
287
415
|
Items extends readonly PredicateFormula[],
|
|
288
416
|
Direction extends Polarity,
|
|
289
|
-
Current extends AnyContext | never = never
|
|
290
|
-
|
|
417
|
+
Current extends AnyContext | never = never,
|
|
418
|
+
Seen extends readonly unknown[] = []
|
|
419
|
+
> = Seen["length"] extends 20
|
|
420
|
+
? MarkUnknown<Ctx>
|
|
421
|
+
: Items extends readonly [
|
|
291
422
|
infer Head extends PredicateFormula,
|
|
292
423
|
...infer Tail extends readonly PredicateFormula[]
|
|
293
424
|
]
|
|
294
425
|
? AnalyzeBranch<Ctx, Head, Direction> extends infer Branch extends AnyContext
|
|
295
426
|
? Branch["contradiction"] extends true
|
|
296
|
-
? AnalyzeAnyBranches<Ctx, Tail, Direction, Current>
|
|
427
|
+
? AnalyzeAnyBranches<Ctx, Tail, Direction, Current, readonly [...Seen, unknown]>
|
|
297
428
|
: [Current] extends [never]
|
|
298
|
-
? AnalyzeAnyBranches<Ctx, Tail, Direction, Branch>
|
|
299
|
-
: AnalyzeAnyBranches<Ctx, Tail, Direction, IntersectContexts<Current, Branch
|
|
429
|
+
? AnalyzeAnyBranches<Ctx, Tail, Direction, Branch, readonly [...Seen, unknown]>
|
|
430
|
+
: AnalyzeAnyBranches<Ctx, Tail, Direction, IntersectContexts<Current, Branch>, readonly [...Seen, unknown]>
|
|
300
431
|
: never
|
|
301
432
|
: [Current] extends [never]
|
|
302
433
|
? MarkContradiction<Ctx>
|
|
@@ -353,3 +484,15 @@ export type AnalyzeStack<
|
|
|
353
484
|
|
|
354
485
|
export type AnalyzeFormula<Formula extends PredicateFormula> =
|
|
355
486
|
AnalyzeStack<EmptyContext, readonly [Frame<Formula, "positive">]>
|
|
487
|
+
|
|
488
|
+
export type PredicateContext = AnyContext
|
|
489
|
+
|
|
490
|
+
export type AssumeFactsTrue<
|
|
491
|
+
Ctx extends PredicateContext,
|
|
492
|
+
Formula extends PredicateFormula
|
|
493
|
+
> = AnalyzeStack<Ctx, readonly [Frame<Formula, "positive">]>
|
|
494
|
+
|
|
495
|
+
export type AssumeFactsFalse<
|
|
496
|
+
Ctx extends PredicateContext,
|
|
497
|
+
Formula extends PredicateFormula
|
|
498
|
+
> = AnalyzeStack<Ctx, readonly [Frame<Formula, "negative">]>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { PredicateAtom } from "./atom.js";
|
|
2
|
+
export interface TrueFormula {
|
|
3
|
+
readonly kind: "true";
|
|
4
|
+
}
|
|
5
|
+
export interface FalseFormula {
|
|
6
|
+
readonly kind: "false";
|
|
7
|
+
}
|
|
8
|
+
export interface AtomFormula<Atom extends PredicateAtom> {
|
|
9
|
+
readonly kind: "atom";
|
|
10
|
+
readonly atom: Atom;
|
|
11
|
+
}
|
|
12
|
+
export interface AllFormula<Items extends readonly PredicateFormula[]> {
|
|
13
|
+
readonly kind: "all";
|
|
14
|
+
readonly items: Items;
|
|
15
|
+
}
|
|
16
|
+
export interface AnyFormula<Items extends readonly PredicateFormula[]> {
|
|
17
|
+
readonly kind: "any";
|
|
18
|
+
readonly items: Items;
|
|
19
|
+
}
|
|
20
|
+
export interface NotFormula<Item extends PredicateFormula> {
|
|
21
|
+
readonly kind: "not";
|
|
22
|
+
readonly item: Item;
|
|
23
|
+
}
|
|
24
|
+
export type PredicateFormula = TrueFormula | FalseFormula | AtomFormula<PredicateAtom> | AllFormula<readonly PredicateFormula[]> | AnyFormula<readonly PredicateFormula[]> | NotFormula<PredicateFormula>;
|
|
25
|
+
type NormalizeAllItems<Items extends readonly PredicateFormula[], Current extends readonly PredicateFormula[] = []> = Items extends readonly [infer Head extends PredicateFormula, ...infer Tail extends readonly PredicateFormula[]] ? Head extends TrueFormula ? NormalizeAllItems<Tail, Current> : Head extends FalseFormula ? [FalseFormula] : Head extends AllFormula<infer Nested extends readonly PredicateFormula[]> ? NormalizeAllItems<[...Nested, ...Tail], Current> : NormalizeAllItems<Tail, [...Current, Head]> : Current;
|
|
26
|
+
type NormalizeAnyItems<Items extends readonly PredicateFormula[], Current extends readonly PredicateFormula[] = []> = Items extends readonly [infer Head extends PredicateFormula, ...infer Tail extends readonly PredicateFormula[]] ? Head extends FalseFormula ? NormalizeAnyItems<Tail, Current> : Head extends TrueFormula ? [TrueFormula] : Head extends AnyFormula<infer Nested extends readonly PredicateFormula[]> ? NormalizeAnyItems<[...Nested, ...Tail], Current> : NormalizeAnyItems<Tail, [...Current, Head]> : Current;
|
|
27
|
+
type CollapseNormalizedAll<Items extends readonly PredicateFormula[]> = NormalizeAllItems<Items> extends infer Normalized extends readonly PredicateFormula[] ? [Normalized] extends [readonly [FalseFormula]] ? FalseFormula : [Normalized] extends [readonly []] ? TrueFormula : [Normalized] extends [readonly [infer Only extends PredicateFormula]] ? Only : AllFormula<Normalized> : never;
|
|
28
|
+
type CollapseNormalizedAny<Items extends readonly PredicateFormula[]> = NormalizeAnyItems<Items> extends infer Normalized extends readonly PredicateFormula[] ? [Normalized] extends [readonly [TrueFormula]] ? TrueFormula : [Normalized] extends [readonly []] ? FalseFormula : [Normalized] extends [readonly [infer Only extends PredicateFormula]] ? Only : AnyFormula<Normalized> : never;
|
|
29
|
+
export type NormalizeBooleanConstants<Formula extends PredicateFormula> = [
|
|
30
|
+
Formula
|
|
31
|
+
] extends [AllFormula<infer Items extends readonly PredicateFormula[]>] ? CollapseNormalizedAll<Items> : [Formula] extends [AnyFormula<infer Items extends readonly PredicateFormula[]>] ? CollapseNormalizedAny<Items> : [Formula] extends [NotFormula<infer Item extends PredicateFormula>] ? [Item] extends [TrueFormula] ? FalseFormula : [Item] extends [FalseFormula] ? TrueFormula : Formula : Formula;
|
|
32
|
+
export type And<Left extends PredicateFormula, Right extends PredicateFormula> = NormalizeBooleanConstants<AllFormula<[Left, Right]>>;
|
|
33
|
+
export type Or<Left extends PredicateFormula, Right extends PredicateFormula> = NormalizeBooleanConstants<AnyFormula<[Left, Right]>>;
|
|
34
|
+
export type Not<Value extends PredicateFormula> = NormalizeBooleanConstants<NotFormula<Value>>;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type * as Expression from "../scalar.js";
|
|
2
|
+
import type * as ExpressionAst from "../expression-ast.js";
|
|
3
|
+
export type ColumnKey<TableName extends string, ColumnName extends string> = `${TableName}.${ColumnName}`;
|
|
4
|
+
export type ColumnKeyOfAst<Ast extends ExpressionAst.Any> = Ast extends ExpressionAst.ColumnNode<infer TableName extends string, infer ColumnName extends string> ? ColumnKey<TableName, ColumnName> : never;
|
|
5
|
+
type AstOf<Value extends Expression.Any> = Value extends {
|
|
6
|
+
readonly [ExpressionAst.TypeId]: infer Ast extends ExpressionAst.Any;
|
|
7
|
+
} ? Ast : never;
|
|
8
|
+
export type ColumnKeyOfExpression<Value extends Expression.Any> = ColumnKeyOfAst<AstOf<Value>>;
|
|
9
|
+
export type LiteralKey<Value> = Value extends string ? `string:${Value}` : Value extends number ? `number:${Value}` : Value extends boolean ? `boolean:${Value}` : Value extends null ? "null" : Value extends Date ? `date:${string}` : "unknown";
|
|
10
|
+
export type ValueKey<Value> = LiteralKey<Value>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type * as Expression from "../scalar.js"
|
|
2
|
+
import type * as ExpressionAst from "../expression-ast.js"
|
|
3
|
+
import type * as JsonPath from "../json/path.js"
|
|
4
|
+
|
|
5
|
+
export type ColumnKey<
|
|
6
|
+
TableName extends string,
|
|
7
|
+
ColumnName extends string
|
|
8
|
+
> = `${TableName}.${ColumnName}`
|
|
9
|
+
|
|
10
|
+
export type ColumnKeyOfAst<Ast extends ExpressionAst.Any> =
|
|
11
|
+
[Ast] extends [ExpressionAst.ColumnNode<infer TableName extends string, infer ColumnName extends string>]
|
|
12
|
+
? ColumnKey<TableName, ColumnName>
|
|
13
|
+
: never
|
|
14
|
+
|
|
15
|
+
type JsonPathKey<
|
|
16
|
+
Segments extends ExpressionAst.JsonSegmentTuple,
|
|
17
|
+
Current extends string = never,
|
|
18
|
+
Seen extends readonly unknown[] = []
|
|
19
|
+
> = Seen["length"] extends 8
|
|
20
|
+
? never
|
|
21
|
+
: Segments extends readonly [
|
|
22
|
+
infer Segment,
|
|
23
|
+
...infer Tail extends ExpressionAst.JsonSegmentTuple
|
|
24
|
+
]
|
|
25
|
+
? Segment extends JsonPath.KeySegment<infer Key extends string>
|
|
26
|
+
? JsonPathKey<
|
|
27
|
+
Tail,
|
|
28
|
+
[Current] extends [never] ? Key : `${Current}.${Key}`,
|
|
29
|
+
readonly [...Seen, unknown]
|
|
30
|
+
>
|
|
31
|
+
: never
|
|
32
|
+
: Current
|
|
33
|
+
|
|
34
|
+
export type JsonPathPredicateKey<
|
|
35
|
+
Base extends Expression.Any,
|
|
36
|
+
Segments extends ExpressionAst.JsonSegmentTuple
|
|
37
|
+
> = [ColumnKeyOfExpression<Base>] extends [never]
|
|
38
|
+
? never
|
|
39
|
+
: [JsonPathKey<Segments>] extends [never]
|
|
40
|
+
? never
|
|
41
|
+
: `${ColumnKeyOfExpression<Base>}#json:${JsonPathKey<Segments>}`
|
|
42
|
+
|
|
43
|
+
export type PredicateKeyOfAst<Ast extends ExpressionAst.Any> =
|
|
44
|
+
[Ast] extends [ExpressionAst.ColumnNode<infer TableName extends string, infer ColumnName extends string>]
|
|
45
|
+
? ColumnKey<TableName, ColumnName>
|
|
46
|
+
: [Ast] extends [ExpressionAst.CastNode<infer Value extends Expression.Any, infer Target extends Expression.DbType.Any>]
|
|
47
|
+
? [Target] extends [Expression.DbTypeOf<Value>]
|
|
48
|
+
? [Expression.DbTypeOf<Value>] extends [Target]
|
|
49
|
+
? PredicateKeyOfExpression<Value>
|
|
50
|
+
: never
|
|
51
|
+
: never
|
|
52
|
+
: [Ast] extends [ExpressionAst.JsonAccessNode<infer Kind, infer Base extends Expression.Any, infer Segments extends ExpressionAst.JsonSegmentTuple>]
|
|
53
|
+
? Kind extends "jsonGetText" | "jsonPathText" | "jsonAccessText" | "jsonTraverseText"
|
|
54
|
+
? JsonPathPredicateKey<Base, Segments>
|
|
55
|
+
: never
|
|
56
|
+
: never
|
|
57
|
+
|
|
58
|
+
type AstOf<Value extends Expression.Any> = Value extends {
|
|
59
|
+
readonly [ExpressionAst.TypeId]: infer Ast extends ExpressionAst.Any
|
|
60
|
+
} ? Ast : never
|
|
61
|
+
|
|
62
|
+
export type ColumnKeyOfExpression<Value extends Expression.Any> = ColumnKeyOfAst<AstOf<Value>>
|
|
63
|
+
export type PredicateKeyOfExpression<Value extends Expression.Any> = PredicateKeyOfAst<AstOf<Value>>
|
|
64
|
+
|
|
65
|
+
export type LiteralKey<Value> =
|
|
66
|
+
Value extends string ? `string:${Value}` :
|
|
67
|
+
Value extends number ? `number:${Value}` :
|
|
68
|
+
Value extends boolean ? `boolean:${Value}` :
|
|
69
|
+
Value extends null ? "null" :
|
|
70
|
+
Value extends Date ? `date:${string}` :
|
|
71
|
+
"unknown"
|
|
72
|
+
|
|
73
|
+
export type ValueKey<Value> = LiteralKey<Value>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { EqColumnAtom, EqLiteralAtom, NeqLiteralAtom, NonNullAtom, NullAtom, PredicateAtom, UnknownAtom } from "./
|
|
2
|
-
import type { PredicateFormula } from "./
|
|
1
|
+
import type { EqColumnAtom, EqLiteralAtom, NeqLiteralAtom, NonNullAtom, NullAtom, PredicateAtom, UnknownAtom } from "./atom.js"
|
|
2
|
+
import type { PredicateFormula } from "./formula.js"
|
|
3
3
|
|
|
4
4
|
export type NegateAtom<Atom extends PredicateAtom> =
|
|
5
5
|
Atom extends NullAtom<infer Key extends string> ? NonNullAtom<Key> :
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type * as Expression from "../scalar.js";
|
|
2
|
+
import type * as ExpressionAst from "../expression-ast.js";
|
|
3
|
+
import type { ColumnKeyOfExpression, ValueKey } from "./key.js";
|
|
4
|
+
import type { AllFormula, AnyFormula, AtomFormula, FalseFormula, PredicateFormula, TrueFormula } from "./formula.js";
|
|
5
|
+
import type { EqLiteralAtom, NeqLiteralAtom, NonNullAtom, NullAtom, UnknownAtom } from "./atom.js";
|
|
6
|
+
type AstOf<Value extends Expression.Any> = Value extends {
|
|
7
|
+
readonly [ExpressionAst.TypeId]: infer Ast extends ExpressionAst.Any;
|
|
8
|
+
} ? Ast : never;
|
|
9
|
+
type LiteralValueOfExpression<Value extends Expression.Any> = AstOf<Value> extends ExpressionAst.LiteralNode<infer Literal> ? Literal : never;
|
|
10
|
+
type True = TrueFormula;
|
|
11
|
+
type False = FalseFormula;
|
|
12
|
+
type UnknownTag<Tag extends string> = AtomFormula<UnknownAtom<Tag>>;
|
|
13
|
+
type AtomOf<Atom extends import("./atom.js").PredicateAtom> = AtomFormula<Atom>;
|
|
14
|
+
type FactOf<Atom extends import("./atom.js").PredicateAtom> = AtomFormula<Atom>;
|
|
15
|
+
type NonNullFactsOfExpression<Value extends Expression.Any> = [
|
|
16
|
+
ColumnKeyOfExpression<Value>
|
|
17
|
+
] extends [never] ? never : FactOf<NonNullAtom<ColumnKeyOfExpression<Value>>>;
|
|
18
|
+
type CombineFacts<Left extends PredicateFormula, Right extends PredicateFormula> = [Left] extends [never] ? Right : [Right] extends [never] ? Left : import("./formula.js").NormalizeBooleanConstants<AllFormula<[Left, Right]>>;
|
|
19
|
+
type FactsOfExpressions<Values extends readonly Expression.Any[]> = Values extends readonly [
|
|
20
|
+
infer Head extends Expression.Any,
|
|
21
|
+
...infer Tail extends readonly Expression.Any[]
|
|
22
|
+
] ? CombineFacts<FormulaOfExpression<Head>, FactsOfExpressions<Tail>> : never;
|
|
23
|
+
type FormulaOfEq<Left extends Expression.Any, Right extends Expression.Any> = [
|
|
24
|
+
ColumnKeyOfExpression<Left>
|
|
25
|
+
] extends [never] ? [ColumnKeyOfExpression<Right>] extends [never] ? LiteralValueOfExpression<Left> extends infer LeftLiteral ? LiteralValueOfExpression<Right> extends infer RightLiteral ? [LeftLiteral] extends [never] ? UnknownTag<"eq:unsupported"> : [RightLiteral] extends [never] ? UnknownTag<"eq:unsupported"> : LeftLiteral extends null ? False : RightLiteral extends null ? False : [LeftLiteral] extends [RightLiteral] ? True : False : UnknownTag<"eq:unsupported"> : UnknownTag<"eq:unsupported"> : LiteralValueOfExpression<Left> extends infer LeftLiteral ? [LeftLiteral] extends [never] ? UnknownTag<"eq:unsupported"> : LeftLiteral extends null ? False : AtomOf<EqLiteralAtom<ColumnKeyOfExpression<Right>, ValueKey<LeftLiteral>>> : UnknownTag<"eq:unsupported"> : [ColumnKeyOfExpression<Right>] extends [never] ? LiteralValueOfExpression<Right> extends infer RightLiteral ? [RightLiteral] extends [never] ? UnknownTag<"eq:unsupported"> : RightLiteral extends null ? False : AtomOf<EqLiteralAtom<ColumnKeyOfExpression<Left>, ValueKey<RightLiteral>>> : UnknownTag<"eq:unsupported"> : AtomOf<import("./atom.js").EqColumnAtom<ColumnKeyOfExpression<Left>, ColumnKeyOfExpression<Right>>>;
|
|
26
|
+
type FormulaOfNeq<Left extends Expression.Any, Right extends Expression.Any> = [
|
|
27
|
+
ColumnKeyOfExpression<Left>
|
|
28
|
+
] extends [never] ? [ColumnKeyOfExpression<Right>] extends [never] ? LiteralValueOfExpression<Left> extends infer LeftLiteral ? LiteralValueOfExpression<Right> extends infer RightLiteral ? [LeftLiteral] extends [never] ? UnknownTag<"neq:unsupported"> : [RightLiteral] extends [never] ? UnknownTag<"neq:unsupported"> : LeftLiteral extends null ? False : RightLiteral extends null ? False : [LeftLiteral] extends [RightLiteral] ? False : True : UnknownTag<"neq:unsupported"> : UnknownTag<"neq:unsupported"> : LiteralValueOfExpression<Left> extends infer LeftLiteral ? [LeftLiteral] extends [never] ? UnknownTag<"neq:unsupported"> : LeftLiteral extends null ? False : AtomOf<NeqLiteralAtom<ColumnKeyOfExpression<Right>, ValueKey<LeftLiteral>>> : UnknownTag<"neq:unsupported"> : [ColumnKeyOfExpression<Right>] extends [never] ? LiteralValueOfExpression<Right> extends infer RightLiteral ? [RightLiteral] extends [never] ? UnknownTag<"neq:unsupported"> : RightLiteral extends null ? False : AtomOf<NeqLiteralAtom<ColumnKeyOfExpression<Left>, ValueKey<RightLiteral>>> : UnknownTag<"neq:unsupported"> : CombineFacts<NonNullFactsOfExpression<Left>, NonNullFactsOfExpression<Right>>;
|
|
29
|
+
type FormulaOfIsNotDistinctFrom<Left extends Expression.Any, Right extends Expression.Any> = LiteralValueOfExpression<Left> extends infer LeftLiteral ? LiteralValueOfExpression<Right> extends infer RightLiteral ? [LeftLiteral] extends [never] ? [RightLiteral] extends [never] ? UnknownTag<"isNotDistinctFrom:unsupported"> : RightLiteral extends null ? [ColumnKeyOfExpression<Left>] extends [never] ? UnknownTag<"isNotDistinctFrom:unsupported"> : AtomOf<NullAtom<ColumnKeyOfExpression<Left>>> : UnknownTag<"isNotDistinctFrom:unsupported"> : LeftLiteral extends null ? [ColumnKeyOfExpression<Right>] extends [never] ? UnknownTag<"isNotDistinctFrom:unsupported"> : AtomOf<NullAtom<ColumnKeyOfExpression<Right>>> : RightLiteral extends null ? [ColumnKeyOfExpression<Left>] extends [never] ? UnknownTag<"isNotDistinctFrom:unsupported"> : AtomOf<NullAtom<ColumnKeyOfExpression<Left>>> : [ColumnKeyOfExpression<Left>] extends [never] ? [ColumnKeyOfExpression<Right>] extends [never] ? CombineFacts<NonNullFactsOfExpression<Left>, NonNullFactsOfExpression<Right>> : AtomOf<EqLiteralAtom<ColumnKeyOfExpression<Right>, ValueKey<LeftLiteral>>> : AtomOf<EqLiteralAtom<ColumnKeyOfExpression<Left>, ValueKey<RightLiteral>>> : UnknownTag<"isNotDistinctFrom:unsupported"> : UnknownTag<"isNotDistinctFrom:unsupported">;
|
|
30
|
+
type OrFormulas<Items extends readonly PredicateFormula[]> = import("./formula.js").NormalizeBooleanConstants<AnyFormula<Items>>;
|
|
31
|
+
type AndFormulas<Items extends readonly PredicateFormula[]> = import("./formula.js").NormalizeBooleanConstants<AllFormula<Items>>;
|
|
32
|
+
type FormulaTupleOf<Values extends readonly Expression.Any[]> = {
|
|
33
|
+
readonly [K in keyof Values]: Values[K] extends Expression.Any ? FormulaOfExpression<Values[K]> : never;
|
|
34
|
+
} & readonly PredicateFormula[];
|
|
35
|
+
type AllFormulaOfValues<Values extends readonly Expression.Any[]> = import("./formula.js").NormalizeBooleanConstants<AllFormula<FormulaTupleOf<Values>>>;
|
|
36
|
+
type AnyFormulaOfValues<Values extends readonly Expression.Any[]> = import("./formula.js").NormalizeBooleanConstants<AnyFormula<FormulaTupleOf<Values>>>;
|
|
37
|
+
type FormulaOfInValues<Left extends Expression.Any, Values extends readonly Expression.Any[], Current extends readonly PredicateFormula[] = []> = Values extends readonly [
|
|
38
|
+
infer Head extends Expression.Any,
|
|
39
|
+
...infer Tail extends readonly Expression.Any[]
|
|
40
|
+
] ? FormulaOfInValues<Left, Tail, [...Current, FormulaOfEq<Left, Head>]> : Current;
|
|
41
|
+
type FormulaOfNotInValues<Left extends Expression.Any, Values extends readonly Expression.Any[], Current extends readonly PredicateFormula[] = []> = Values extends readonly [
|
|
42
|
+
infer Head extends Expression.Any,
|
|
43
|
+
...infer Tail extends readonly Expression.Any[]
|
|
44
|
+
] ? FormulaOfNotInValues<Left, Tail, [...Current, FormulaOfNeq<Left, Head>]> : Current;
|
|
45
|
+
type FormulaOfVariadic<Kind extends ExpressionAst.VariadicKind, Values extends readonly Expression.Any[]> = Kind extends "and" ? AllFormulaOfValues<Values> : Kind extends "or" ? AnyFormulaOfValues<Values> : Kind extends "in" ? Values extends readonly [infer Left extends Expression.Any, ...infer Tail extends readonly Expression.Any[]] ? OrFormulas<FormulaOfInValues<Left, Tail>> : False : Kind extends "notIn" ? Values extends readonly [infer Left extends Expression.Any, ...infer Tail extends readonly Expression.Any[]] ? CombineFacts<NonNullFactsOfExpression<Left>, AndFormulas<FormulaOfNotInValues<Left, Tail>>> : True : Kind extends "between" ? FactsOfExpressions<Values> extends infer Facts extends PredicateFormula ? [Facts] extends [never] ? UnknownTag<"variadic:between"> : CombineFacts<Facts, UnknownTag<"variadic:between">> : UnknownTag<"variadic:between"> : UnknownTag<`variadic:${Kind}`>;
|
|
46
|
+
type FormulaOfUnary<Kind extends ExpressionAst.UnaryKind, Inner extends Expression.Any> = Kind extends "isNull" ? [ColumnKeyOfExpression<Inner>] extends [never] ? UnknownTag<"isNull:unsupported"> : AtomOf<NullAtom<ColumnKeyOfExpression<Inner>>> : Kind extends "isNotNull" ? [ColumnKeyOfExpression<Inner>] extends [never] ? UnknownTag<"isNotNull:unsupported"> : AtomOf<NonNullAtom<ColumnKeyOfExpression<Inner>>> : Kind extends "not" ? import("./formula.js").Not<FormulaOfExpression<Inner>> : UnknownTag<`unary:${Kind}`>;
|
|
47
|
+
type FormulaOfBinary<Kind extends ExpressionAst.BinaryKind, Left extends Expression.Any, Right extends Expression.Any> = Kind extends "eq" ? FormulaOfEq<Left, Right> : Kind extends "neq" ? FormulaOfNeq<Left, Right> : Kind extends "lt" | "lte" | "gt" | "gte" | "like" | "ilike" | "contains" | "containedBy" | "overlaps" ? CombineFacts<NonNullFactsOfExpression<Left>, NonNullFactsOfExpression<Right>> : Kind extends "isNotDistinctFrom" ? FormulaOfIsNotDistinctFrom<Left, Right> : Kind extends "isDistinctFrom" ? import("./formula.js").Not<FormulaOfIsNotDistinctFrom<Left, Right>> : CombineFacts<NonNullFactsOfExpression<Left>, NonNullFactsOfExpression<Right>>;
|
|
48
|
+
type FormulaOfAst<Ast extends ExpressionAst.Any> = [Ast] extends [ExpressionAst.LiteralNode<infer Literal>] ? Literal extends true ? True : Literal extends false ? False : UnknownTag<"literal:non-boolean"> : [Ast] extends [ExpressionAst.UnaryNode<infer Kind extends ExpressionAst.UnaryKind, infer Inner extends Expression.Any>] ? FormulaOfUnary<Kind, Inner> : [Ast] extends [ExpressionAst.VariadicNode<infer Kind extends ExpressionAst.VariadicKind, infer Values extends readonly Expression.Any[]>] ? FormulaOfVariadic<Kind, Values> : [Ast] extends [ExpressionAst.BinaryNode<infer Kind extends ExpressionAst.BinaryKind, infer Left extends Expression.Any, infer Right extends Expression.Any>] ? FormulaOfBinary<Kind, Left, Right> : UnknownTag<`expr:${Ast["kind"]}`>;
|
|
49
|
+
export type FormulaOfExpression<Value extends Expression.Any> = [
|
|
50
|
+
AstOf<Value>
|
|
51
|
+
] extends [infer Ast extends ExpressionAst.Any] ? FormulaOfAst<Ast> : UnknownTag<"missing-ast">;
|
|
52
|
+
export type FormulaOfPredicate<Value> = Value extends true ? True : Value extends false ? False : Value extends Expression.Any ? FormulaOfExpression<Value> : UnknownTag<"predicate:unsupported">;
|
|
53
|
+
export {};
|