effect-qb 0.15.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 +362 -70
- package/dist/postgres/metadata.js +557 -27
- package/dist/postgres.js +5028 -4732
- package/package.json +2 -2
- package/src/internal/column-state.ts +7 -0
- package/src/internal/column.ts +22 -0
- package/src/internal/dialect.ts +12 -1
- package/src/internal/executor.ts +15 -4
- package/src/internal/predicate/analysis.ts +103 -1
- package/src/internal/predicate/atom.ts +7 -0
- package/src/internal/predicate/context.ts +156 -16
- package/src/internal/predicate/key.ts +46 -1
- package/src/internal/predicate/normalize.ts +115 -34
- package/src/internal/predicate/runtime.ts +118 -11
- package/src/internal/query.ts +328 -90
- package/src/internal/renderer.ts +4 -0
- package/src/internal/runtime/driver-value-mapping.ts +186 -0
- package/src/internal/scalar.ts +11 -0
- package/src/mysql/column.ts +1 -0
- package/src/mysql/executor.ts +20 -5
- package/src/mysql/internal/dialect.ts +12 -6
- package/src/mysql/internal/dsl.ts +268 -54
- package/src/mysql/internal/renderer.ts +11 -2
- package/src/mysql/internal/sql-expression-renderer.ts +54 -8
- package/src/mysql/renderer.ts +7 -2
- package/src/postgres/cast.ts +22 -7
- package/src/postgres/column.ts +1 -0
- package/src/postgres/executor.ts +20 -5
- package/src/postgres/internal/dialect.ts +12 -6
- package/src/postgres/internal/dsl.ts +285 -58
- package/src/postgres/internal/renderer.ts +11 -2
- package/src/postgres/internal/sql-expression-renderer.ts +60 -8
- package/src/postgres/renderer.ts +7 -2
- package/src/postgres/type.ts +4 -0
package/src/internal/query.ts
CHANGED
|
@@ -10,8 +10,21 @@ import type { JsonNode } from "./json/ast.js"
|
|
|
10
10
|
import type * as JsonPath from "./json/path.js"
|
|
11
11
|
import type { QueryCapability } from "./query-requirements.js"
|
|
12
12
|
import type { CaseBranchAssumeFalse, CaseBranchAssumeTrue, CaseBranchDecision } from "./case-analysis.js"
|
|
13
|
-
import type {
|
|
14
|
-
|
|
13
|
+
import type {
|
|
14
|
+
ContradictsFormula,
|
|
15
|
+
EmptyFacts,
|
|
16
|
+
FactsOfFormula,
|
|
17
|
+
GuaranteedLiteralSetInFacts,
|
|
18
|
+
GuaranteedNeqLiteralInFacts,
|
|
19
|
+
GuaranteedJsonLiteralSetInFacts,
|
|
20
|
+
GuaranteedNonNullKeysInFacts,
|
|
21
|
+
GuaranteedNullKeysInFacts,
|
|
22
|
+
GuaranteedSourceNamesInFacts,
|
|
23
|
+
PredicateState
|
|
24
|
+
} from "./predicate/analysis.js"
|
|
25
|
+
import type { AssumeFactsFalse, AssumeFactsTrue, PredicateContext } from "./predicate/context.js"
|
|
26
|
+
import type { FormulaOfPredicate } from "./predicate/normalize.js"
|
|
27
|
+
import type { ColumnKeyOfAst, ColumnKeyOfExpression, PredicateKeyOfAst } from "./predicate/key.js"
|
|
15
28
|
import type { PredicateFormula, TrueFormula } from "./predicate/formula.js"
|
|
16
29
|
import { trueFormula } from "./predicate/runtime.js"
|
|
17
30
|
|
|
@@ -113,12 +126,14 @@ export interface QueryState<
|
|
|
113
126
|
Capabilities extends QueryCapability,
|
|
114
127
|
Statement extends QueryAst.QueryStatement,
|
|
115
128
|
Target,
|
|
116
|
-
InsertState extends InsertSourceState
|
|
129
|
+
InsertState extends InsertSourceState,
|
|
130
|
+
Facts extends PredicateContext
|
|
117
131
|
> {
|
|
118
132
|
readonly required: Outstanding
|
|
119
133
|
readonly availableNames: AvailableNames
|
|
120
134
|
readonly grouped: Grouped
|
|
121
135
|
readonly assumptions: Assumptions
|
|
136
|
+
readonly facts: Facts
|
|
122
137
|
readonly capabilities: Capabilities
|
|
123
138
|
readonly statement: Statement
|
|
124
139
|
readonly target: Target
|
|
@@ -1067,6 +1082,12 @@ export type OutstandingOfPlan<
|
|
|
1067
1082
|
export type AssumptionsOfPlan<
|
|
1068
1083
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any, any, any>
|
|
1069
1084
|
> = QueryPlanState<PlanValue>["assumptions"]
|
|
1085
|
+
export type FactsOfPlan<
|
|
1086
|
+
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any, any, any>
|
|
1087
|
+
> = QueryPlanState<PlanValue>["facts"]
|
|
1088
|
+
export type PredicateStateOfPlan<
|
|
1089
|
+
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any, any, any>
|
|
1090
|
+
> = PredicateState<AssumptionsOfPlan<PlanValue>, FactsOfPlan<PlanValue>>
|
|
1070
1091
|
export type CapabilitiesOfPlan<
|
|
1071
1092
|
PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any, any, any>
|
|
1072
1093
|
> = QueryPlanState<PlanValue>["capabilities"]
|
|
@@ -1324,12 +1345,13 @@ type MergeNullabilityStates<
|
|
|
1324
1345
|
type FoldEffectiveNullability<
|
|
1325
1346
|
Values extends readonly Expression.Any[],
|
|
1326
1347
|
Available extends Record<string, RowSet.AnySource>,
|
|
1327
|
-
Assumptions extends PredicateFormula
|
|
1348
|
+
Assumptions extends PredicateFormula,
|
|
1349
|
+
Facts extends PredicateContext
|
|
1328
1350
|
> = Extract<{
|
|
1329
|
-
[K in keyof Values]: Values[K] extends Expression.Any ? EffectiveNullability<Values[K], Available, Assumptions> : never
|
|
1351
|
+
[K in keyof Values]: Values[K] extends Expression.Any ? EffectiveNullability<Values[K], Available, Assumptions, Facts> : never
|
|
1330
1352
|
}[number], "always"> extends never
|
|
1331
1353
|
? Extract<{
|
|
1332
|
-
[K in keyof Values]: Values[K] extends Expression.Any ? EffectiveNullability<Values[K], Available, Assumptions> : never
|
|
1354
|
+
[K in keyof Values]: Values[K] extends Expression.Any ? EffectiveNullability<Values[K], Available, Assumptions, Facts> : never
|
|
1333
1355
|
}[number], "maybe"> extends never
|
|
1334
1356
|
? "never"
|
|
1335
1357
|
: "maybe"
|
|
@@ -1338,12 +1360,13 @@ type FoldEffectiveNullability<
|
|
|
1338
1360
|
type CoalesceEffectiveNullability<
|
|
1339
1361
|
Values extends readonly Expression.Any[],
|
|
1340
1362
|
Available extends Record<string, RowSet.AnySource>,
|
|
1341
|
-
Assumptions extends PredicateFormula
|
|
1363
|
+
Assumptions extends PredicateFormula,
|
|
1364
|
+
Facts extends PredicateContext
|
|
1342
1365
|
> = Extract<{
|
|
1343
|
-
[K in keyof Values]: Values[K] extends Expression.Any ? EffectiveNullability<Values[K], Available, Assumptions> : never
|
|
1366
|
+
[K in keyof Values]: Values[K] extends Expression.Any ? EffectiveNullability<Values[K], Available, Assumptions, Facts> : never
|
|
1344
1367
|
}[number], "never"> extends never
|
|
1345
1368
|
? Extract<{
|
|
1346
|
-
[K in keyof Values]: Values[K] extends Expression.Any ? EffectiveNullability<Values[K], Available, Assumptions> : never
|
|
1369
|
+
[K in keyof Values]: Values[K] extends Expression.Any ? EffectiveNullability<Values[K], Available, Assumptions, Facts> : never
|
|
1347
1370
|
}[number], "maybe"> extends never
|
|
1348
1371
|
? "always"
|
|
1349
1372
|
: "maybe"
|
|
@@ -1357,16 +1380,16 @@ type NullabilityOfOutput<Output> =
|
|
|
1357
1380
|
type PreciseFactSet<Value extends string> = string extends Value ? never : Value
|
|
1358
1381
|
|
|
1359
1382
|
type KnownGuaranteedNullKeys<
|
|
1360
|
-
|
|
1361
|
-
> = PreciseFactSet<
|
|
1383
|
+
Facts extends PredicateContext
|
|
1384
|
+
> = PreciseFactSet<GuaranteedNullKeysInFacts<Facts>>
|
|
1362
1385
|
|
|
1363
1386
|
type KnownGuaranteedNonNullKeys<
|
|
1364
|
-
|
|
1365
|
-
> = PreciseFactSet<
|
|
1387
|
+
Facts extends PredicateContext
|
|
1388
|
+
> = PreciseFactSet<GuaranteedNonNullKeysInFacts<Facts>>
|
|
1366
1389
|
|
|
1367
1390
|
type KnownGuaranteedSourceNames<
|
|
1368
|
-
|
|
1369
|
-
> = PreciseFactSet<
|
|
1391
|
+
Facts extends PredicateContext
|
|
1392
|
+
> = PreciseFactSet<GuaranteedSourceNamesInFacts<Facts>>
|
|
1370
1393
|
|
|
1371
1394
|
type ExplicitlyRequiredSourceNames<
|
|
1372
1395
|
Available extends Record<string, RowSet.AnySource>
|
|
@@ -1393,7 +1416,7 @@ type ImpliedSourceNamesFromRequired<
|
|
|
1393
1416
|
> = Extract<{
|
|
1394
1417
|
readonly [K in Extract<keyof Available, string>]:
|
|
1395
1418
|
K extends Required
|
|
1396
|
-
? PreciseFactSet<
|
|
1419
|
+
? PreciseFactSet<GuaranteedSourceNamesInFacts<FactsOfFormula<PresentFormulaOfSource<Available[K]>>>>
|
|
1397
1420
|
: never
|
|
1398
1421
|
}[Extract<keyof Available, string>], string>
|
|
1399
1422
|
|
|
@@ -1416,17 +1439,20 @@ type ExpandRequiredSourceNamesStep<
|
|
|
1416
1439
|
|
|
1417
1440
|
type DirectlyAbsentSourceNames<
|
|
1418
1441
|
Available extends Record<string, RowSet.AnySource>,
|
|
1419
|
-
Assumptions extends PredicateFormula
|
|
1442
|
+
Assumptions extends PredicateFormula,
|
|
1443
|
+
Facts extends PredicateContext
|
|
1420
1444
|
> = Extract<{
|
|
1421
1445
|
readonly [K in Extract<keyof Available, string>]:
|
|
1422
|
-
K extends
|
|
1423
|
-
?
|
|
1424
|
-
?
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1446
|
+
Available[K] extends RowSet.Source<any, infer Mode extends RowSet.SourceMode, any, any>
|
|
1447
|
+
? Mode extends "required"
|
|
1448
|
+
? never
|
|
1449
|
+
: PresenceWitnessesOfSource<Available[K]> extends infer Witnesses extends string
|
|
1450
|
+
? Extract<Witnesses, KnownGuaranteedNullKeys<Facts>> extends never
|
|
1451
|
+
? ContradictsFormula<Assumptions, PresentFormulaOfSource<Available[K]>> extends true
|
|
1452
|
+
? K
|
|
1453
|
+
: never
|
|
1454
|
+
: K
|
|
1455
|
+
: never
|
|
1430
1456
|
: never
|
|
1431
1457
|
}[Extract<keyof Available, string>], string>
|
|
1432
1458
|
|
|
@@ -1435,7 +1461,7 @@ type ImpliedAbsentSourceNames<
|
|
|
1435
1461
|
Absent extends string
|
|
1436
1462
|
> = Extract<{
|
|
1437
1463
|
readonly [K in Extract<keyof Available, string>]:
|
|
1438
|
-
Extract<PreciseFactSet<
|
|
1464
|
+
Extract<PreciseFactSet<GuaranteedSourceNamesInFacts<FactsOfFormula<PresentFormulaOfSource<Available[K]>>>>, Absent> extends never
|
|
1439
1465
|
? never
|
|
1440
1466
|
: K
|
|
1441
1467
|
}[Extract<keyof Available, string>], string>
|
|
@@ -1459,23 +1485,26 @@ type ExpandAbsentSourceNamesStep<
|
|
|
1459
1485
|
|
|
1460
1486
|
type AbsentSourceNamesInScope<
|
|
1461
1487
|
Available extends Record<string, RowSet.AnySource>,
|
|
1462
|
-
Assumptions extends PredicateFormula
|
|
1463
|
-
|
|
1488
|
+
Assumptions extends PredicateFormula,
|
|
1489
|
+
Facts extends PredicateContext
|
|
1490
|
+
> = ExpandAbsentSourceNames<Available, DirectlyAbsentSourceNames<Available, Assumptions, Facts>>
|
|
1464
1491
|
|
|
1465
1492
|
type RequiredSourceNamesInScope<
|
|
1466
1493
|
Available extends Record<string, RowSet.AnySource>,
|
|
1467
|
-
Assumptions extends PredicateFormula
|
|
1494
|
+
Assumptions extends PredicateFormula,
|
|
1495
|
+
Facts extends PredicateContext
|
|
1468
1496
|
> = Exclude<
|
|
1469
1497
|
ExpandRequiredSourceNames<
|
|
1470
1498
|
Available,
|
|
1471
|
-
ExplicitlyRequiredSourceNames<Available> | KnownGuaranteedSourceNames<
|
|
1499
|
+
ExplicitlyRequiredSourceNames<Available> | KnownGuaranteedSourceNames<Facts>
|
|
1472
1500
|
>,
|
|
1473
|
-
AbsentSourceNamesInScope<Available, Assumptions>
|
|
1501
|
+
AbsentSourceNamesInScope<Available, Assumptions, Facts>
|
|
1474
1502
|
>
|
|
1475
1503
|
|
|
1476
1504
|
type EffectiveAvailable<
|
|
1477
1505
|
Available extends Record<string, RowSet.AnySource>,
|
|
1478
|
-
Assumptions extends PredicateFormula
|
|
1506
|
+
Assumptions extends PredicateFormula,
|
|
1507
|
+
Facts extends PredicateContext
|
|
1479
1508
|
> = {
|
|
1480
1509
|
readonly [K in keyof Available]:
|
|
1481
1510
|
Available[K] extends RowSet.Source<
|
|
@@ -1486,7 +1515,7 @@ type EffectiveAvailable<
|
|
|
1486
1515
|
>
|
|
1487
1516
|
? RowSet.Source<
|
|
1488
1517
|
Name,
|
|
1489
|
-
K extends RequiredSourceNamesInScope<Available, Assumptions> ? "required" : Mode,
|
|
1518
|
+
K extends RequiredSourceNamesInScope<Available, Assumptions, Facts> ? "required" : Mode,
|
|
1490
1519
|
PresentFormula,
|
|
1491
1520
|
PresenceWitness
|
|
1492
1521
|
> & {
|
|
@@ -1498,8 +1527,9 @@ type EffectiveAvailable<
|
|
|
1498
1527
|
type HasAbsentSource<
|
|
1499
1528
|
Dependencies extends Expression.BindingId,
|
|
1500
1529
|
Available extends Record<string, RowSet.AnySource>,
|
|
1501
|
-
Assumptions extends PredicateFormula
|
|
1502
|
-
|
|
1530
|
+
Assumptions extends PredicateFormula,
|
|
1531
|
+
Facts extends PredicateContext
|
|
1532
|
+
> = Extract<Dependencies, AbsentSourceNamesInScope<Available, Assumptions, Facts>> extends never ? false : true
|
|
1503
1533
|
|
|
1504
1534
|
type OptionalSourceNamesInScope<
|
|
1505
1535
|
Available extends Record<string, RowSet.AnySource>
|
|
@@ -1507,102 +1537,298 @@ type OptionalSourceNamesInScope<
|
|
|
1507
1537
|
[K in keyof Available & string]: SourceModeOf<Available, K> extends "optional" ? K : never
|
|
1508
1538
|
}[keyof Available & string], string>
|
|
1509
1539
|
|
|
1540
|
+
type EffectiveNullabilityFromBase<
|
|
1541
|
+
Value extends Expression.Any,
|
|
1542
|
+
Available extends Record<string, RowSet.AnySource>,
|
|
1543
|
+
Assumptions extends PredicateFormula,
|
|
1544
|
+
Facts extends PredicateContext
|
|
1545
|
+
> = Expression.NullabilityOf<Value> extends "always" ? "always"
|
|
1546
|
+
: PredicateKeyOfAst<AstOf<Value>> extends infer Key extends string
|
|
1547
|
+
? IsUnion<Key> extends true
|
|
1548
|
+
? EffectiveNullabilityFromSources<Value, Available, Assumptions, Facts>
|
|
1549
|
+
: string extends Key
|
|
1550
|
+
? EffectiveNullabilityFromSources<Value, Available, Assumptions, Facts>
|
|
1551
|
+
: Key extends KnownGuaranteedNullKeys<Facts>
|
|
1552
|
+
? "always"
|
|
1553
|
+
: Key extends KnownGuaranteedNonNullKeys<Facts>
|
|
1554
|
+
? "never"
|
|
1555
|
+
: EffectiveNullabilityFromSources<Value, Available, Assumptions, Facts>
|
|
1556
|
+
: EffectiveNullabilityFromSources<Value, Available, Assumptions, Facts>
|
|
1557
|
+
|
|
1558
|
+
type EffectiveNullabilityFromSources<
|
|
1559
|
+
Value extends Expression.Any,
|
|
1560
|
+
Available extends Record<string, RowSet.AnySource>,
|
|
1561
|
+
Assumptions extends PredicateFormula,
|
|
1562
|
+
Facts extends PredicateContext
|
|
1563
|
+
> = HasAbsentSource<DependenciesOf<Value>, Available, Assumptions, Facts> extends true ? "always"
|
|
1564
|
+
: HasOptionalSource<DependenciesOf<Value>, Available> extends true ? "maybe"
|
|
1565
|
+
: Expression.NullabilityOf<Value>
|
|
1566
|
+
|
|
1510
1567
|
type BaseEffectiveNullability<
|
|
1511
1568
|
Value extends Expression.Any,
|
|
1512
1569
|
Available extends Record<string, RowSet.AnySource>,
|
|
1513
|
-
Assumptions extends PredicateFormula
|
|
1570
|
+
Assumptions extends PredicateFormula,
|
|
1571
|
+
Facts extends PredicateContext
|
|
1514
1572
|
> = AstOf<Value> extends ExpressionAst.ColumnNode<infer TableName extends string, infer ColumnName extends string>
|
|
1515
|
-
? TableName extends AbsentSourceNamesInScope<Available, Assumptions>
|
|
1573
|
+
? TableName extends AbsentSourceNamesInScope<Available, Assumptions, Facts>
|
|
1516
1574
|
? "always"
|
|
1517
|
-
: `${TableName}.${ColumnName}` extends KnownGuaranteedNullKeys<
|
|
1575
|
+
: `${TableName}.${ColumnName}` extends KnownGuaranteedNullKeys<Facts>
|
|
1518
1576
|
? "always"
|
|
1519
|
-
: `${TableName}.${ColumnName}` extends KnownGuaranteedNonNullKeys<
|
|
1577
|
+
: `${TableName}.${ColumnName}` extends KnownGuaranteedNonNullKeys<Facts>
|
|
1520
1578
|
? "never"
|
|
1521
|
-
:
|
|
1522
|
-
|
|
1523
|
-
: HasOptionalSource<DependenciesOf<Value>, Available> extends true ? "maybe"
|
|
1524
|
-
: Expression.NullabilityOf<Value>
|
|
1525
|
-
: Expression.NullabilityOf<Value> extends "always" ? "always"
|
|
1526
|
-
: HasAbsentSource<DependenciesOf<Value>, Available, Assumptions> extends true ? "always"
|
|
1527
|
-
: HasOptionalSource<DependenciesOf<Value>, Available> extends true ? "maybe"
|
|
1528
|
-
: Expression.NullabilityOf<Value>
|
|
1579
|
+
: EffectiveNullabilityFromBase<Value, Available, Assumptions, Facts>
|
|
1580
|
+
: EffectiveNullabilityFromBase<Value, Available, Assumptions, Facts>
|
|
1529
1581
|
|
|
1530
1582
|
type CaseOutputOf<
|
|
1531
1583
|
Branches extends readonly ExpressionAst.CaseBranchNode[],
|
|
1532
1584
|
Else extends Expression.Any,
|
|
1533
1585
|
Available extends Record<string, RowSet.AnySource>,
|
|
1534
|
-
Assumptions extends PredicateFormula
|
|
1586
|
+
Assumptions extends PredicateFormula,
|
|
1587
|
+
Facts extends PredicateContext
|
|
1535
1588
|
> = Branches extends readonly [
|
|
1536
1589
|
infer Head extends ExpressionAst.CaseBranchNode,
|
|
1537
1590
|
...infer Tail extends readonly ExpressionAst.CaseBranchNode[]
|
|
1538
1591
|
]
|
|
1539
1592
|
? Head extends ExpressionAst.CaseBranchNode<infer Predicate extends Expression.Any, infer Then extends Expression.Any>
|
|
1540
1593
|
? CaseBranchDecision<Assumptions, Predicate> extends "skip"
|
|
1541
|
-
? CaseOutputOf<Tail, Else, Available, Assumptions>
|
|
1594
|
+
? CaseOutputOf<Tail, Else, Available, Assumptions, Facts>
|
|
1542
1595
|
: CaseBranchDecision<Assumptions, Predicate> extends "take"
|
|
1543
|
-
?
|
|
1544
|
-
|
|
1545
|
-
|
|
1596
|
+
? FormulaOfPredicate<Predicate> extends infer BranchFormula extends PredicateFormula
|
|
1597
|
+
? ExpressionOutput<
|
|
1598
|
+
Then,
|
|
1599
|
+
EffectiveAvailable<
|
|
1600
|
+
Available,
|
|
1601
|
+
CaseBranchAssumeTrue<Assumptions, Predicate>,
|
|
1602
|
+
AssumeFactsTrue<Facts, BranchFormula>
|
|
1603
|
+
>,
|
|
1604
|
+
CaseBranchAssumeTrue<Assumptions, Predicate>,
|
|
1605
|
+
AssumeFactsTrue<Facts, BranchFormula>
|
|
1606
|
+
>
|
|
1607
|
+
: never
|
|
1608
|
+
: FormulaOfPredicate<Predicate> extends infer BranchFormula extends PredicateFormula
|
|
1609
|
+
? ExpressionOutput<
|
|
1610
|
+
Then,
|
|
1611
|
+
EffectiveAvailable<
|
|
1612
|
+
Available,
|
|
1613
|
+
CaseBranchAssumeTrue<Assumptions, Predicate>,
|
|
1614
|
+
AssumeFactsTrue<Facts, BranchFormula>
|
|
1615
|
+
>,
|
|
1616
|
+
CaseBranchAssumeTrue<Assumptions, Predicate>,
|
|
1617
|
+
AssumeFactsTrue<Facts, BranchFormula>
|
|
1618
|
+
> |
|
|
1619
|
+
CaseOutputOf<
|
|
1620
|
+
Tail,
|
|
1621
|
+
Else,
|
|
1622
|
+
Available,
|
|
1623
|
+
CaseBranchAssumeFalse<Assumptions, Predicate>,
|
|
1624
|
+
AssumeFactsFalse<Facts, BranchFormula>
|
|
1625
|
+
>
|
|
1626
|
+
: never
|
|
1546
1627
|
: never
|
|
1547
|
-
: ExpressionOutput<Else, EffectiveAvailable<Available, Assumptions>, Assumptions>
|
|
1628
|
+
: ExpressionOutput<Else, EffectiveAvailable<Available, Assumptions, Facts>, Assumptions, Facts>
|
|
1548
1629
|
|
|
1549
1630
|
/** Effective nullability of an expression after source-scope nullability is applied. */
|
|
1550
1631
|
type EffectiveNullabilityOfAst<
|
|
1551
1632
|
Value extends Expression.Any,
|
|
1552
1633
|
Ast extends ExpressionAst.Any,
|
|
1553
1634
|
Available extends Record<string, RowSet.AnySource>,
|
|
1554
|
-
Assumptions extends PredicateFormula = TrueAssumptions
|
|
1635
|
+
Assumptions extends PredicateFormula = TrueAssumptions,
|
|
1636
|
+
Facts extends PredicateContext = EmptyFacts
|
|
1555
1637
|
> = Ast extends ExpressionAst.ColumnNode<any, any>
|
|
1556
|
-
? BaseEffectiveNullability<Value, Available, Assumptions>
|
|
1638
|
+
? BaseEffectiveNullability<Value, Available, Assumptions, Facts>
|
|
1557
1639
|
: Ast extends ExpressionAst.LiteralNode<any>
|
|
1558
1640
|
? Expression.NullabilityOf<Value>
|
|
1559
1641
|
: Ast extends ExpressionAst.UnaryNode<infer Kind, infer UnaryValue extends Expression.Any>
|
|
1560
1642
|
? Kind extends "upper" | "lower" | "not"
|
|
1561
|
-
? EffectiveNullability<UnaryValue, Available, Assumptions>
|
|
1643
|
+
? EffectiveNullability<UnaryValue, Available, Assumptions, Facts>
|
|
1562
1644
|
: Kind extends "isNull" | "isNotNull" | "count"
|
|
1563
1645
|
? "never"
|
|
1564
1646
|
: Expression.NullabilityOf<Value>
|
|
1565
1647
|
: Ast extends ExpressionAst.BinaryNode<"eq", infer Left extends Expression.Any, infer Right extends Expression.Any>
|
|
1566
|
-
? EffectiveNullability<Left, Available, Assumptions> extends "never"
|
|
1567
|
-
? EffectiveNullability<Right, Available, Assumptions> extends "never" ? "never" : "maybe"
|
|
1648
|
+
? EffectiveNullability<Left, Available, Assumptions, Facts> extends "never"
|
|
1649
|
+
? EffectiveNullability<Right, Available, Assumptions, Facts> extends "never" ? "never" : "maybe"
|
|
1568
1650
|
: "maybe"
|
|
1569
1651
|
: Ast extends ExpressionAst.VariadicNode<infer Kind, infer Values extends readonly Expression.Any[]>
|
|
1570
1652
|
? Kind extends "coalesce"
|
|
1571
|
-
? CoalesceEffectiveNullability<Values, Available, Assumptions>
|
|
1653
|
+
? CoalesceEffectiveNullability<Values, Available, Assumptions, Facts>
|
|
1572
1654
|
: Kind extends "and" | "or" | "concat"
|
|
1573
|
-
? FoldEffectiveNullability<Values, Available, Assumptions>
|
|
1574
|
-
: BaseEffectiveNullability<Value, Available, Assumptions>
|
|
1655
|
+
? FoldEffectiveNullability<Values, Available, Assumptions, Facts>
|
|
1656
|
+
: BaseEffectiveNullability<Value, Available, Assumptions, Facts>
|
|
1575
1657
|
: Ast extends ExpressionAst.CaseNode<infer Branches extends readonly ExpressionAst.CaseBranchNode[], infer Else extends Expression.Any>
|
|
1576
|
-
? NullabilityOfOutput<CaseOutputOf<Branches, Else, Available, Assumptions>>
|
|
1577
|
-
: BaseEffectiveNullability<Value, Available, Assumptions>
|
|
1658
|
+
? NullabilityOfOutput<CaseOutputOf<Branches, Else, Available, Assumptions, Facts>>
|
|
1659
|
+
: BaseEffectiveNullability<Value, Available, Assumptions, Facts>
|
|
1578
1660
|
|
|
1579
1661
|
export type EffectiveNullability<
|
|
1580
1662
|
Value extends Expression.Any,
|
|
1581
1663
|
Available extends Record<string, RowSet.AnySource>,
|
|
1582
|
-
Assumptions extends PredicateFormula = TrueAssumptions
|
|
1664
|
+
Assumptions extends PredicateFormula = TrueAssumptions,
|
|
1665
|
+
Facts extends PredicateContext = EmptyFacts
|
|
1583
1666
|
> =
|
|
1584
1667
|
AstOf<Value> extends infer Ast extends ExpressionAst.Any
|
|
1585
|
-
? EffectiveNullabilityOfAst<Value, Ast, Available, Assumptions>
|
|
1586
|
-
: BaseEffectiveNullability<Value, Available, Assumptions>
|
|
1668
|
+
? EffectiveNullabilityOfAst<Value, Ast, Available, Assumptions, Facts>
|
|
1669
|
+
: BaseEffectiveNullability<Value, Available, Assumptions, Facts>
|
|
1670
|
+
|
|
1671
|
+
type LiteralKeyValue<Value extends string> =
|
|
1672
|
+
Value extends `string:${infer Literal}` ? Literal :
|
|
1673
|
+
Value extends `number:${infer Literal extends number}` ? Literal :
|
|
1674
|
+
Value extends "boolean:true" ? true :
|
|
1675
|
+
Value extends "boolean:false" ? false :
|
|
1676
|
+
never
|
|
1677
|
+
|
|
1678
|
+
type LiteralSetRuntime<Values> =
|
|
1679
|
+
Values extends readonly (infer Value)[] ? LiteralSetRuntime<Value> :
|
|
1680
|
+
Values extends string ? LiteralKeyValue<Values> :
|
|
1681
|
+
never
|
|
1682
|
+
|
|
1683
|
+
type NarrowRuntimeToAllowed<
|
|
1684
|
+
Runtime,
|
|
1685
|
+
Allowed
|
|
1686
|
+
> = Runtime extends unknown
|
|
1687
|
+
? Extract<Runtime, Allowed> extends infer Extracted
|
|
1688
|
+
? [Extracted] extends [never]
|
|
1689
|
+
? Allowed extends Runtime ? Allowed : never
|
|
1690
|
+
: Extracted
|
|
1691
|
+
: never
|
|
1692
|
+
: never
|
|
1693
|
+
|
|
1694
|
+
type RefineRuntimeByAllowedLiterals<
|
|
1695
|
+
Runtime,
|
|
1696
|
+
Values
|
|
1697
|
+
> = [Values] extends [never]
|
|
1698
|
+
? Runtime
|
|
1699
|
+
: string extends Values
|
|
1700
|
+
? Runtime
|
|
1701
|
+
: NarrowRuntimeToAllowed<Runtime, LiteralSetRuntime<Values>>
|
|
1702
|
+
|
|
1703
|
+
type RefineRuntimeByExcludedLiterals<
|
|
1704
|
+
Runtime,
|
|
1705
|
+
Values
|
|
1706
|
+
> = [Values] extends [never]
|
|
1707
|
+
? Runtime
|
|
1708
|
+
: string extends Values
|
|
1709
|
+
? Runtime
|
|
1710
|
+
: Exclude<Runtime, LiteralSetRuntime<Values>>
|
|
1711
|
+
|
|
1712
|
+
type JsonKeyParts<Key extends string> = string extends Key
|
|
1713
|
+
? never
|
|
1714
|
+
: Key extends `${infer ColumnKey}#json:${infer Path}`
|
|
1715
|
+
? readonly [ColumnKey, Path]
|
|
1716
|
+
: never
|
|
1717
|
+
|
|
1718
|
+
type LiteralSetForPredicateKey<
|
|
1719
|
+
Facts extends PredicateContext,
|
|
1720
|
+
Key extends string
|
|
1721
|
+
> = [JsonKeyParts<Key>] extends [never]
|
|
1722
|
+
? GuaranteedLiteralSetInFacts<Facts, Key>
|
|
1723
|
+
: JsonKeyParts<Key> extends readonly [infer ColumnKey extends string, infer Path extends string]
|
|
1724
|
+
? GuaranteedJsonLiteralSetInFacts<Facts, ColumnKey, Path>
|
|
1725
|
+
: never
|
|
1726
|
+
|
|
1727
|
+
type RefineRuntimeForPredicateKey<
|
|
1728
|
+
Runtime,
|
|
1729
|
+
Facts extends PredicateContext,
|
|
1730
|
+
Key extends string
|
|
1731
|
+
> = IsUnion<Key> extends true
|
|
1732
|
+
? Runtime
|
|
1733
|
+
: string extends Key
|
|
1734
|
+
? Runtime
|
|
1735
|
+
: RefineRuntimeByExcludedLiterals<
|
|
1736
|
+
RefineRuntimeByAllowedLiterals<Runtime, LiteralSetForPredicateKey<Facts, Key>>,
|
|
1737
|
+
GuaranteedNeqLiteralInFacts<Facts, Key>
|
|
1738
|
+
>
|
|
1739
|
+
|
|
1740
|
+
type JsonLiteralSetsForColumn<
|
|
1741
|
+
Facts extends PredicateContext,
|
|
1742
|
+
ColumnKey extends string
|
|
1743
|
+
> = [Facts["jsonLiteralSets"]] extends [{ readonly [C in ColumnKey]: infer Paths }]
|
|
1744
|
+
? Paths
|
|
1745
|
+
: {}
|
|
1746
|
+
|
|
1747
|
+
type RefineJsonRuntimeAtPath<
|
|
1748
|
+
Runtime,
|
|
1749
|
+
Path extends string,
|
|
1750
|
+
Values
|
|
1751
|
+
> = Runtime extends unknown
|
|
1752
|
+
? Path extends `${infer Head}.${infer Tail}`
|
|
1753
|
+
? Runtime extends object
|
|
1754
|
+
? Head extends keyof Runtime
|
|
1755
|
+
? RefineJsonRuntimeAtPath<NonNullable<Runtime[Head]>, Tail, Values> extends infer Refined
|
|
1756
|
+
? [Refined] extends [never]
|
|
1757
|
+
? never
|
|
1758
|
+
: Omit<Runtime, Head> & { readonly [K in Head]: Refined }
|
|
1759
|
+
: never
|
|
1760
|
+
: never
|
|
1761
|
+
: never
|
|
1762
|
+
: Runtime extends object
|
|
1763
|
+
? Path extends keyof Runtime
|
|
1764
|
+
? RefineRuntimeByAllowedLiterals<NonNullable<Runtime[Path]>, Values> extends infer Refined
|
|
1765
|
+
? [Refined] extends [never]
|
|
1766
|
+
? never
|
|
1767
|
+
: Omit<Runtime, Path> & { readonly [K in Path]: Refined }
|
|
1768
|
+
: never
|
|
1769
|
+
: never
|
|
1770
|
+
: RefineRuntimeByAllowedLiterals<NonNullable<Runtime>, Values>
|
|
1771
|
+
: never
|
|
1772
|
+
|
|
1773
|
+
type RefineJsonRuntimeWithConstraints<
|
|
1774
|
+
Runtime,
|
|
1775
|
+
Constraints
|
|
1776
|
+
> = [keyof Constraints & string] extends [never]
|
|
1777
|
+
? Runtime
|
|
1778
|
+
: {
|
|
1779
|
+
readonly [Path in keyof Constraints & string]:
|
|
1780
|
+
[RefineJsonRuntimeAtPath<Runtime, Path, Constraints[Path]>] extends [never] ? Path : never
|
|
1781
|
+
}[keyof Constraints & string] extends never
|
|
1782
|
+
? UnionToIntersection<{
|
|
1783
|
+
readonly [Path in keyof Constraints & string]: RefineJsonRuntimeAtPath<Runtime, Path, Constraints[Path]>
|
|
1784
|
+
}[keyof Constraints & string]>
|
|
1785
|
+
: never
|
|
1786
|
+
|
|
1787
|
+
type RefineJsonRuntimeForColumn<
|
|
1788
|
+
Runtime,
|
|
1789
|
+
ColumnKey extends string,
|
|
1790
|
+
Facts extends PredicateContext
|
|
1791
|
+
> = Runtime extends object
|
|
1792
|
+
? Runtime extends unknown
|
|
1793
|
+
? RefineJsonRuntimeWithConstraints<Runtime, JsonLiteralSetsForColumn<Facts, ColumnKey>>
|
|
1794
|
+
: never
|
|
1795
|
+
: Runtime
|
|
1796
|
+
|
|
1797
|
+
type AssumptionRefinedRuntime<
|
|
1798
|
+
Ast extends ExpressionAst.Any,
|
|
1799
|
+
Runtime,
|
|
1800
|
+
Facts extends PredicateContext
|
|
1801
|
+
> = [PredicateKeyOfAst<Ast>] extends [never]
|
|
1802
|
+
? Runtime
|
|
1803
|
+
: PredicateKeyOfAst<Ast> extends infer PredicateKey extends string
|
|
1804
|
+
? [ColumnKeyOfAst<Ast>] extends [never]
|
|
1805
|
+
? RefineRuntimeForPredicateKey<Runtime, Facts, PredicateKey>
|
|
1806
|
+
: ColumnKeyOfAst<Ast> extends infer ColumnKey extends string
|
|
1807
|
+
? RefineRuntimeForPredicateKey<RefineJsonRuntimeForColumn<Runtime, ColumnKey, Facts>, Facts, PredicateKey>
|
|
1808
|
+
: Runtime
|
|
1809
|
+
: Runtime
|
|
1587
1810
|
|
|
1588
1811
|
/** Result runtime type of an expression after effective nullability is resolved. */
|
|
1589
1812
|
export type ExpressionOutput<
|
|
1590
1813
|
Value extends Expression.Any,
|
|
1591
1814
|
Available extends Record<string, RowSet.AnySource>,
|
|
1592
|
-
Assumptions extends PredicateFormula = TrueAssumptions
|
|
1815
|
+
Assumptions extends PredicateFormula = TrueAssumptions,
|
|
1816
|
+
Facts extends PredicateContext = EmptyFacts
|
|
1593
1817
|
> = AstOf<Value> extends infer Ast extends ExpressionAst.Any
|
|
1594
1818
|
? Ast extends ExpressionAst.CaseNode<infer Branches extends readonly ExpressionAst.CaseBranchNode[], infer Else extends Expression.Any>
|
|
1595
|
-
? CaseOutputOf<Branches, Else, Available, Assumptions>
|
|
1596
|
-
: EffectiveNullabilityOfAst<Value, Ast, Available, Assumptions> extends infer Nullability
|
|
1819
|
+
? CaseOutputOf<Branches, Else, Available, Assumptions, Facts>
|
|
1820
|
+
: EffectiveNullabilityOfAst<Value, Ast, Available, Assumptions, Facts> extends infer Nullability
|
|
1597
1821
|
? Expression.NullabilityOf<Value> extends infer BaseNullability
|
|
1598
1822
|
? Expression.RuntimeOf<Value> extends infer Runtime
|
|
1599
|
-
?
|
|
1600
|
-
?
|
|
1601
|
-
?
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1823
|
+
? AssumptionRefinedRuntime<Ast, Runtime, Facts> extends infer RefinedRuntime
|
|
1824
|
+
? Nullability extends "never"
|
|
1825
|
+
? BaseNullability extends "never"
|
|
1826
|
+
? RefinedRuntime
|
|
1827
|
+
: NonNullable<RefinedRuntime>
|
|
1828
|
+
: Nullability extends "always"
|
|
1829
|
+
? null
|
|
1830
|
+
: RefinedRuntime | null
|
|
1831
|
+
: never
|
|
1606
1832
|
: never
|
|
1607
1833
|
: never
|
|
1608
1834
|
: never
|
|
@@ -1612,23 +1838,26 @@ export type ExpressionOutput<
|
|
|
1612
1838
|
export type OutputOfSelection<
|
|
1613
1839
|
Selection,
|
|
1614
1840
|
Available extends Record<string, RowSet.AnySource>,
|
|
1615
|
-
Assumptions extends PredicateFormula = TrueAssumptions
|
|
1841
|
+
Assumptions extends PredicateFormula = TrueAssumptions,
|
|
1842
|
+
Facts extends PredicateContext = EmptyFacts
|
|
1616
1843
|
> = Selection extends Expression.Any
|
|
1617
|
-
? ExpressionOutput<Selection, Available, Assumptions>
|
|
1844
|
+
? ExpressionOutput<Selection, Available, Assumptions, Facts>
|
|
1618
1845
|
: Selection extends Record<string, any>
|
|
1619
1846
|
? {
|
|
1620
|
-
readonly [K in keyof Selection]: OutputOfSelection<Selection[K], Available, Assumptions>
|
|
1847
|
+
readonly [K in keyof Selection]: OutputOfSelection<Selection[K], Available, Assumptions, Facts>
|
|
1621
1848
|
}
|
|
1622
1849
|
: never
|
|
1623
1850
|
|
|
1624
1851
|
type ResolvedSelectionOutput<
|
|
1625
1852
|
Selection,
|
|
1626
1853
|
Available extends Record<string, RowSet.AnySource>,
|
|
1627
|
-
Assumptions extends PredicateFormula
|
|
1854
|
+
Assumptions extends PredicateFormula,
|
|
1855
|
+
Facts extends PredicateContext
|
|
1628
1856
|
> = OutputOfSelection<
|
|
1629
1857
|
Selection,
|
|
1630
|
-
EffectiveAvailable<Available, Assumptions>,
|
|
1631
|
-
Assumptions
|
|
1858
|
+
EffectiveAvailable<Available, Assumptions, Facts>,
|
|
1859
|
+
Assumptions,
|
|
1860
|
+
Facts
|
|
1632
1861
|
>
|
|
1633
1862
|
|
|
1634
1863
|
/** Resolved row type produced by a concrete query plan. */
|
|
@@ -1636,7 +1865,9 @@ export type ResultRow<PlanValue extends QueryPlan<any, any, any, any, any, any,
|
|
|
1636
1865
|
SelectionOfPlan<PlanValue> extends infer Selection
|
|
1637
1866
|
? AvailableOfPlan<PlanValue> extends infer Available extends Record<string, RowSet.AnySource>
|
|
1638
1867
|
? AssumptionsOfPlan<PlanValue> extends infer Assumptions extends PredicateFormula
|
|
1639
|
-
?
|
|
1868
|
+
? FactsOfPlan<PlanValue> extends infer Facts extends PredicateContext
|
|
1869
|
+
? ResolvedSelectionOutput<Selection, Available, Assumptions, Facts>
|
|
1870
|
+
: never
|
|
1640
1871
|
: never
|
|
1641
1872
|
: never
|
|
1642
1873
|
: never
|
|
@@ -1648,7 +1879,7 @@ export type ResultRows<PlanValue extends QueryPlan<any, any, any, any, any, any,
|
|
|
1648
1879
|
export type RuntimeResultRow<PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>> =
|
|
1649
1880
|
SelectionOfPlan<PlanValue> extends infer Selection
|
|
1650
1881
|
? AvailableOfPlan<PlanValue> extends infer Available extends Record<string, RowSet.AnySource>
|
|
1651
|
-
? OutputOfSelection<Selection, Available, TrueAssumptions>
|
|
1882
|
+
? OutputOfSelection<Selection, Available, TrueAssumptions, EmptyFacts>
|
|
1652
1883
|
: never
|
|
1653
1884
|
: never
|
|
1654
1885
|
|
|
@@ -1858,7 +2089,8 @@ export type QueryPlan<
|
|
|
1858
2089
|
Capabilities extends QueryCapability = "read",
|
|
1859
2090
|
Statement extends QueryAst.QueryStatement = "select",
|
|
1860
2091
|
Target = any,
|
|
1861
|
-
InsertState extends InsertSourceState = InsertSourceState
|
|
2092
|
+
InsertState extends InsertSourceState = InsertSourceState,
|
|
2093
|
+
Facts extends PredicateContext = PredicateContext
|
|
1862
2094
|
> = RowSet.RowSet<Selection, Required, Available, Dialect> & {
|
|
1863
2095
|
readonly [QueryTypeId]: QueryState<
|
|
1864
2096
|
Outstanding,
|
|
@@ -1868,7 +2100,8 @@ export type QueryPlan<
|
|
|
1868
2100
|
Capabilities,
|
|
1869
2101
|
Statement,
|
|
1870
2102
|
Target,
|
|
1871
|
-
InsertState
|
|
2103
|
+
InsertState,
|
|
2104
|
+
Facts
|
|
1872
2105
|
>
|
|
1873
2106
|
readonly [QueryAst.TypeId]: QueryAst.Ast<Selection, Grouped, Statement>
|
|
1874
2107
|
}
|
|
@@ -1958,6 +2191,7 @@ export const makeExpression = <
|
|
|
1958
2191
|
readonly runtime: Runtime
|
|
1959
2192
|
readonly dbType: Db
|
|
1960
2193
|
readonly runtimeSchema?: Schema.Schema.Any
|
|
2194
|
+
readonly driverValueMapping?: Expression.DriverValueMapping
|
|
1961
2195
|
readonly nullability: Nullable
|
|
1962
2196
|
readonly dialect: Dialect
|
|
1963
2197
|
readonly kind?: Kind
|
|
@@ -1979,6 +2213,7 @@ export const makeExpression = <
|
|
|
1979
2213
|
runtime: state.runtime,
|
|
1980
2214
|
dbType: state.dbType,
|
|
1981
2215
|
runtimeSchema: state.runtimeSchema,
|
|
2216
|
+
driverValueMapping: state.driverValueMapping,
|
|
1982
2217
|
nullability: state.nullability,
|
|
1983
2218
|
dialect: state.dialect,
|
|
1984
2219
|
kind: state.kind ?? ("scalar" as Kind),
|
|
@@ -2004,7 +2239,8 @@ export const makePlan = <
|
|
|
2004
2239
|
Capabilities extends QueryCapability = "read",
|
|
2005
2240
|
Statement extends QueryAst.QueryStatement = "select",
|
|
2006
2241
|
Target = any,
|
|
2007
|
-
InsertState extends InsertSourceState = InsertSourceState
|
|
2242
|
+
InsertState extends InsertSourceState = InsertSourceState,
|
|
2243
|
+
Facts extends PredicateContext = PredicateContext
|
|
2008
2244
|
>(
|
|
2009
2245
|
state: RowSet.State<Selection, Required, Available, Dialect>,
|
|
2010
2246
|
ast: QueryAst.Ast<Selection, Grouped, Statement>,
|
|
@@ -2012,8 +2248,9 @@ export const makePlan = <
|
|
|
2012
2248
|
_capabilities?: Capabilities,
|
|
2013
2249
|
_statement?: Statement,
|
|
2014
2250
|
_target?: Target,
|
|
2015
|
-
_insertState?: InsertState
|
|
2016
|
-
|
|
2251
|
+
_insertState?: InsertState,
|
|
2252
|
+
_facts?: Facts
|
|
2253
|
+
): QueryPlan<Selection, Required, Available, Dialect, Grouped, ScopedNames, Outstanding, Assumptions, Capabilities, Statement, Target, InsertState, Facts> => {
|
|
2017
2254
|
const plan = Object.create(PlanProto)
|
|
2018
2255
|
Object.defineProperty(plan, "pipe", {
|
|
2019
2256
|
configurable: true,
|
|
@@ -2029,6 +2266,7 @@ export const makePlan = <
|
|
|
2029
2266
|
availableNames: undefined as unknown as ScopedNames,
|
|
2030
2267
|
grouped: undefined as unknown as Grouped,
|
|
2031
2268
|
assumptions: ((_assumptions ?? trueFormula()) as Assumptions),
|
|
2269
|
+
facts: ((_facts ?? undefined) as unknown as Facts),
|
|
2032
2270
|
capabilities: undefined as unknown as Capabilities,
|
|
2033
2271
|
statement: (_statement ?? ("select" as Statement)) as Statement,
|
|
2034
2272
|
target: (_target ?? (undefined as unknown as Target)) as Target,
|
|
@@ -2049,7 +2287,7 @@ export const getAst = <
|
|
|
2049
2287
|
/** Returns the internal phantom query state carried by a query plan. */
|
|
2050
2288
|
export const getQueryState = (
|
|
2051
2289
|
plan: QueryPlan<any, any, any, any, any, any, any, any, any, any>
|
|
2052
|
-
): QueryState<any, any, any, any, any, any, any, any> => plan[QueryTypeId]
|
|
2290
|
+
): QueryState<any, any, any, any, any, any, any, any, any> => plan[QueryTypeId]
|
|
2053
2291
|
|
|
2054
2292
|
/**
|
|
2055
2293
|
* Collects the required table names referenced by a runtime selection object.
|