effect-qb 0.13.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1431
- package/dist/mysql.js +61945 -3611
- package/dist/postgres/metadata.js +2818 -0
- package/dist/postgres.js +9942 -5591
- package/package.json +21 -10
- 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 +119 -56
- package/src/internal/column.ts +387 -149
- package/src/internal/datatypes/define.d.ts +17 -0
- package/src/internal/datatypes/define.ts +18 -34
- 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/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 +173 -38
- package/src/internal/expression-ast.ts +19 -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 +171 -0
- 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 → predicate/analysis.ts} +13 -3
- package/src/internal/predicate/atom.d.ts +28 -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} +111 -32
- package/src/internal/predicate/formula.d.ts +35 -0
- package/src/internal/{predicate-formula.ts → predicate/formula.ts} +32 -20
- package/src/internal/predicate/key.d.ts +11 -0
- package/src/internal/{predicate-key.ts → predicate/key.ts} +2 -2
- 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 +273 -0
- package/src/internal/predicate/runtime.d.ts +31 -0
- package/src/internal/predicate/runtime.ts +679 -0
- 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 +767 -275
- package/src/internal/renderer.ts +7 -21
- package/src/internal/row-set.d.ts +53 -0
- package/src/internal/{plan.ts → row-set.ts} +23 -11
- package/src/internal/{runtime-normalize.ts → runtime/normalize.ts} +9 -31
- package/src/internal/{runtime-schema.ts → runtime/schema.ts} +84 -55
- 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 +191 -0
- package/src/internal/schema-derivation.d.ts +105 -0
- package/src/internal/schema-derivation.ts +93 -21
- package/src/internal/schema-expression.d.ts +18 -0
- package/src/internal/schema-expression.ts +75 -0
- package/src/internal/table-options.d.ts +94 -0
- package/src/internal/table-options.ts +94 -8
- package/src/internal/table.d.ts +173 -0
- package/src/internal/table.ts +135 -54
- package/src/mysql/column.ts +95 -18
- package/src/mysql/datatypes/index.ts +58 -3
- 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 +69 -7
- package/src/mysql/function/aggregate.ts +1 -5
- package/src/mysql/function/core.ts +1 -3
- package/src/mysql/function/index.ts +1 -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} +1 -1
- package/src/mysql/internal/dsl.ts +6115 -0
- package/src/{internal/mysql-renderer.ts → mysql/internal/renderer.ts} +6 -6
- package/src/mysql/internal/sql-expression-renderer.ts +1455 -0
- package/src/mysql/json.ts +2 -0
- package/src/mysql/query.ts +111 -86
- package/src/mysql/renderer.ts +1 -1
- package/src/mysql/table.ts +1 -1
- package/src/mysql.ts +6 -4
- package/src/postgres/cast.ts +30 -0
- package/src/postgres/column.ts +178 -20
- package/src/postgres/datatypes/index.d.ts +515 -0
- package/src/postgres/datatypes/index.ts +49 -5
- 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 +37 -5
- package/src/postgres/function/aggregate.ts +1 -5
- package/src/postgres/function/core.ts +20 -2
- package/src/postgres/function/index.ts +1 -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} +1 -1
- package/src/{internal/query-factory.ts → postgres/internal/dsl.ts} +1568 -2120
- package/src/{internal/postgres-renderer.ts → postgres/internal/renderer.ts} +6 -6
- package/src/postgres/internal/schema-ddl.ts +108 -0
- package/src/postgres/internal/schema-model.ts +150 -0
- package/src/{internal → postgres/internal}/sql-expression-renderer.ts +112 -46
- package/src/postgres/json.ts +493 -0
- package/src/postgres/metadata.ts +31 -0
- package/src/postgres/query.ts +113 -86
- package/src/postgres/renderer.ts +3 -13
- package/src/postgres/schema-expression.ts +17 -0
- package/src/postgres/schema-management.ts +204 -0
- package/src/postgres/schema.ts +35 -0
- package/src/postgres/table.ts +316 -42
- package/src/postgres/type.ts +31 -0
- package/src/postgres.ts +20 -4
- package/CHANGELOG.md +0 -134
- package/src/internal/expression.ts +0 -327
- package/src/internal/predicate-normalize.ts +0 -202
- package/src/mysql/function/json.ts +0 -4
- package/src/mysql/private/query.ts +0 -13
- package/src/postgres/function/json.ts +0 -4
- package/src/postgres/private/query.ts +0 -13
- /package/src/internal/{predicate-atom.ts → predicate/atom.ts} +0 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { EqColumnAtom, EqLiteralAtom, NeqLiteralAtom, NonNullAtom, NullAtom, PredicateAtom, UnknownAtom } from "./atom.js";
|
|
2
|
+
import type { AllFormula, AnyFormula, AtomFormula, FalseFormula, NotFormula, PredicateFormula, TrueFormula } from "./formula.js";
|
|
3
|
+
type Polarity = "positive" | "negative";
|
|
4
|
+
export interface Context<NonNullKeys extends string = never, NullKeys extends string = never, EqLiterals = {}, NeqLiterals = {}, SourceNames extends string = never, Contradiction extends boolean = false, Unknown extends boolean = false> {
|
|
5
|
+
readonly nonNullKeys: NonNullKeys;
|
|
6
|
+
readonly nullKeys: NullKeys;
|
|
7
|
+
readonly eqLiterals: EqLiterals;
|
|
8
|
+
readonly neqLiterals: NeqLiterals;
|
|
9
|
+
readonly sourceNames: SourceNames;
|
|
10
|
+
readonly contradiction: Contradiction;
|
|
11
|
+
readonly unknown: Unknown;
|
|
12
|
+
}
|
|
13
|
+
export type EmptyContext = Context;
|
|
14
|
+
type AnyContext = Context<string, string, Record<string, string>, Record<string, string>, string, boolean, boolean>;
|
|
15
|
+
type Frame<Formula extends PredicateFormula = PredicateFormula, Direction extends Polarity = Polarity> = {
|
|
16
|
+
readonly formula: Formula;
|
|
17
|
+
readonly polarity: Direction;
|
|
18
|
+
};
|
|
19
|
+
type SourceNameOfKey<Key extends string> = Key extends `${infer SourceName}.${string}` ? SourceName : never;
|
|
20
|
+
type EqLiteralValueOf<EqLiterals, Key extends string> = EqLiterals extends Record<string, string> ? Key extends keyof EqLiterals ? EqLiterals[Key] : never : never;
|
|
21
|
+
type NeqLiteralValuesOf<NeqLiterals, Key extends string> = NeqLiterals extends Record<string, string> ? Key extends keyof NeqLiterals ? NeqLiterals[Key] : never : never;
|
|
22
|
+
type MergeEqLiteralMaps<Left, Right> = {
|
|
23
|
+
readonly [K in Extract<keyof Left | keyof Right, string>]: K extends keyof Left ? K extends keyof Right ? Left[K] extends Right[K] ? Left[K] : never : Left[K] : K extends keyof Right ? Right[K] : never;
|
|
24
|
+
};
|
|
25
|
+
type MergeNeqLiteralMaps<Left, Right> = {
|
|
26
|
+
readonly [K in Extract<keyof Left | keyof Right, string>]: K extends keyof Left ? K extends keyof Right ? Left[K] | Right[K] : Left[K] : K extends keyof Right ? Right[K] : never;
|
|
27
|
+
};
|
|
28
|
+
type FilterNeverValues<Map> = {
|
|
29
|
+
readonly [K in keyof Map as Map[K] extends never ? never : K]: Map[K];
|
|
30
|
+
};
|
|
31
|
+
type MarkContradiction<Ctx extends AnyContext> = Context<Ctx["nonNullKeys"], Ctx["nullKeys"], Ctx["eqLiterals"], Ctx["neqLiterals"], Ctx["sourceNames"], true, Ctx["unknown"]>;
|
|
32
|
+
type MarkUnknown<Ctx extends AnyContext> = Context<Ctx["nonNullKeys"], Ctx["nullKeys"], Ctx["eqLiterals"], Ctx["neqLiterals"], Ctx["sourceNames"], Ctx["contradiction"], true>;
|
|
33
|
+
type AddNonNull<Ctx extends AnyContext, Key extends string> = Context<Ctx["nonNullKeys"] | Key, Ctx["nullKeys"], Ctx["eqLiterals"], Ctx["neqLiterals"], Ctx["sourceNames"] | SourceNameOfKey<Key>, Key extends Ctx["nullKeys"] ? true : Ctx["contradiction"], Ctx["unknown"]>;
|
|
34
|
+
type AddNull<Ctx extends AnyContext, Key extends string> = Context<Ctx["nonNullKeys"], Ctx["nullKeys"] | Key, Ctx["eqLiterals"], Ctx["neqLiterals"], Ctx["sourceNames"] | SourceNameOfKey<Key>, Key extends Ctx["nonNullKeys"] ? true : Ctx["contradiction"], Ctx["unknown"]>;
|
|
35
|
+
type AddEqLiteral<Ctx extends AnyContext, Key extends string, Value extends string> = Context<Ctx["nonNullKeys"] | Key, Ctx["nullKeys"], FilterNeverValues<MergeEqLiteralMaps<Ctx["eqLiterals"], {
|
|
36
|
+
readonly [K in Key]: Value;
|
|
37
|
+
}>>, Ctx["neqLiterals"], Ctx["sourceNames"] | SourceNameOfKey<Key>, EqLiteralValueOf<Ctx["eqLiterals"], Key> extends never ? NeqLiteralValuesOf<Ctx["neqLiterals"], Key> extends infer NeqValues ? Value extends NeqValues ? true : Key extends Ctx["nullKeys"] ? true : Ctx["contradiction"] : true : EqLiteralValueOf<Ctx["eqLiterals"], Key> extends Value ? NeqLiteralValuesOf<Ctx["neqLiterals"], Key> extends infer NeqValues ? Value extends NeqValues ? true : Key extends Ctx["nullKeys"] ? true : Ctx["contradiction"] : true : true, Ctx["unknown"]>;
|
|
38
|
+
type AddNeqLiteral<Ctx extends AnyContext, Key extends string, Value extends string> = Context<Ctx["nonNullKeys"] | Key, Ctx["nullKeys"], Ctx["eqLiterals"], FilterNeverValues<MergeNeqLiteralMaps<Ctx["neqLiterals"], {
|
|
39
|
+
readonly [K in Key]: Value;
|
|
40
|
+
}>>, Ctx["sourceNames"] | SourceNameOfKey<Key>, EqLiteralValueOf<Ctx["eqLiterals"], Key> extends infer EqValue ? [EqValue] extends [never] ? Key extends Ctx["nullKeys"] ? true : Ctx["contradiction"] : EqValue extends Value ? true : Key extends Ctx["nullKeys"] ? true : Ctx["contradiction"] : true, Ctx["unknown"]>;
|
|
41
|
+
type ApplyEqColumn<Ctx extends AnyContext, Left extends string, Right extends string> = EqLiteralValueOf<Ctx["eqLiterals"], Left> extends infer LeftValue ? EqLiteralValueOf<Ctx["eqLiterals"], Right> extends infer RightValue ? [LeftValue] extends [never] ? [RightValue] extends [never] ? AddNonNull<AddNonNull<Ctx, Left>, Right> : RightValue extends string ? AddEqLiteral<AddNonNull<AddNonNull<Ctx, Left>, Right>, Left, RightValue> : MarkContradiction<Ctx> : [RightValue] extends [never] ? LeftValue extends string ? AddEqLiteral<AddNonNull<AddNonNull<Ctx, Left>, Right>, Right, LeftValue> : MarkContradiction<Ctx> : LeftValue extends RightValue ? LeftValue extends string ? RightValue extends string ? AddEqLiteral<AddEqLiteral<AddNonNull<AddNonNull<Ctx, Left>, Right>, Left, LeftValue>, Right, RightValue> : MarkContradiction<Ctx> : MarkContradiction<Ctx> : MarkContradiction<Ctx> : never : never;
|
|
42
|
+
type ApplyAtom<Ctx extends AnyContext, Atom extends PredicateAtom> = Atom extends NullAtom<infer Key extends string> ? AddNull<Ctx, Key> : Atom extends NonNullAtom<infer Key extends string> ? AddNonNull<Ctx, Key> : Atom extends EqLiteralAtom<infer Key extends string, infer Value extends string> ? AddEqLiteral<Ctx, Key, Value> : Atom extends NeqLiteralAtom<infer Key extends string, infer Value extends string> ? AddNeqLiteral<Ctx, Key, Value> : Atom extends EqColumnAtom<infer Left extends string, infer Right extends string> ? ApplyEqColumn<Ctx, Left, Right> : Atom extends UnknownAtom<any> ? MarkUnknown<Ctx> : Ctx;
|
|
43
|
+
type ApplyNegativeAtom<Ctx extends AnyContext, Atom extends PredicateAtom> = Atom extends NullAtom<infer Key extends string> ? AddNonNull<Ctx, Key> : Atom extends NonNullAtom<infer Key extends string> ? AddNull<Ctx, Key> : Atom extends EqLiteralAtom<infer Key extends string, infer Value extends string> ? AddNeqLiteral<Ctx, Key, Value> : Atom extends NeqLiteralAtom<infer Key extends string, infer Value extends string> ? AddEqLiteral<Ctx, Key, Value> : Atom extends EqColumnAtom<infer Left extends string, infer Right extends string> ? AddNonNull<AddNonNull<Ctx, Left>, Right> : Atom extends UnknownAtom<any> ? MarkUnknown<Ctx> : Ctx;
|
|
44
|
+
type FramesFromItems<Items extends readonly PredicateFormula[], Direction extends Polarity> = Items extends readonly [
|
|
45
|
+
infer Head extends PredicateFormula,
|
|
46
|
+
...infer Tail extends readonly PredicateFormula[]
|
|
47
|
+
] ? readonly [Frame<Head, Direction>, ...FramesFromItems<Tail, Direction>] : readonly [];
|
|
48
|
+
type IntersectEqLiteralMaps<Left, Right> = FilterNeverValues<{
|
|
49
|
+
readonly [K in Extract<keyof Left, keyof Right>]: Left[K] extends Right[K] ? Left[K] : never;
|
|
50
|
+
}>;
|
|
51
|
+
type IntersectNeqLiteralMaps<Left, Right> = FilterNeverValues<{
|
|
52
|
+
readonly [K in Extract<keyof Left, keyof Right>]: Extract<Left[K], Right[K]> extends never ? never : Extract<Left[K], Right[K]>;
|
|
53
|
+
}>;
|
|
54
|
+
type IntersectContexts<Left extends AnyContext, Right extends AnyContext> = Context<Extract<Left["nonNullKeys"], Right["nonNullKeys"]>, Extract<Left["nullKeys"], Right["nullKeys"]>, IntersectEqLiteralMaps<Left["eqLiterals"], Right["eqLiterals"]>, IntersectNeqLiteralMaps<Left["neqLiterals"], Right["neqLiterals"]>, Extract<Left["sourceNames"], Right["sourceNames"]>, Left["contradiction"] extends true ? Right["contradiction"] : Right["contradiction"] extends true ? Left["contradiction"] : false, Left["unknown"] extends true ? true : Right["unknown"] extends true ? true : false>;
|
|
55
|
+
type AnalyzeAnyBranches<Ctx extends AnyContext, Items extends readonly PredicateFormula[], Direction extends Polarity, Current extends AnyContext | never = never> = Items extends readonly [
|
|
56
|
+
infer Head extends PredicateFormula,
|
|
57
|
+
...infer Tail extends readonly PredicateFormula[]
|
|
58
|
+
] ? AnalyzeBranch<Ctx, Head, Direction> extends infer Branch extends AnyContext ? Branch["contradiction"] extends true ? AnalyzeAnyBranches<Ctx, Tail, Direction, Current> : [Current] extends [never] ? AnalyzeAnyBranches<Ctx, Tail, Direction, Branch> : AnalyzeAnyBranches<Ctx, Tail, Direction, IntersectContexts<Current, Branch>> : never : [Current] extends [never] ? MarkContradiction<Ctx> : Current;
|
|
59
|
+
type Flip<Direction extends Polarity> = Direction extends "positive" ? "negative" : "positive";
|
|
60
|
+
type AnalyzeBranch<Ctx extends AnyContext, Formula extends PredicateFormula, Direction extends Polarity> = AnalyzeStack<Ctx, readonly [Frame<Formula, Direction>]>;
|
|
61
|
+
type AnalyzeFrame<Ctx extends AnyContext, Formula extends PredicateFormula, Direction extends Polarity, Tail extends readonly Frame[]> = [Formula] extends [TrueFormula] ? Direction extends "positive" ? AnalyzeStack<Ctx, Tail> : MarkContradiction<Ctx> : [Formula] extends [FalseFormula] ? Direction extends "positive" ? MarkContradiction<Ctx> : AnalyzeStack<Ctx, Tail> : [Formula] extends [AtomFormula<infer Atom extends PredicateAtom>] ? Direction extends "positive" ? AnalyzeStack<ApplyAtom<Ctx, Atom>, Tail> : AnalyzeStack<ApplyNegativeAtom<Ctx, Atom>, Tail> : [Formula] extends [NotFormula<infer Item extends PredicateFormula>] ? AnalyzeStack<Ctx, readonly [Frame<Item, Flip<Direction>>, ...Tail]> : [Formula] extends [AllFormula<infer Items extends readonly PredicateFormula[]>] ? Direction extends "positive" ? AnalyzeStack<Ctx, readonly [...FramesFromItems<Items, "positive">, ...Tail]> : AnalyzeStack<AnalyzeAnyBranches<Ctx, Items, "negative">, Tail> : [Formula] extends [AnyFormula<infer Items extends readonly PredicateFormula[]>] ? Direction extends "positive" ? AnalyzeStack<AnalyzeAnyBranches<Ctx, Items, "positive">, Tail> : AnalyzeStack<Ctx, readonly [...FramesFromItems<Items, "negative">, ...Tail]> : AnalyzeStack<MarkUnknown<Ctx>, Tail>;
|
|
62
|
+
export type AnalyzeStack<Ctx extends AnyContext, Stack extends readonly Frame[]> = Ctx["contradiction"] extends true ? Ctx : Stack extends readonly [
|
|
63
|
+
infer Head extends Frame,
|
|
64
|
+
...infer Tail extends readonly Frame[]
|
|
65
|
+
] ? AnalyzeFrame<Ctx, Head["formula"], Head["polarity"], Tail> : Ctx;
|
|
66
|
+
export type AnalyzeFormula<Formula extends PredicateFormula> = AnalyzeStack<EmptyContext, readonly [Frame<Formula, "positive">]>;
|
|
67
|
+
export {};
|
|
@@ -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, 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
|
|
|
@@ -7,6 +7,7 @@ export interface Context<
|
|
|
7
7
|
NonNullKeys extends string = never,
|
|
8
8
|
NullKeys extends string = never,
|
|
9
9
|
EqLiterals = {},
|
|
10
|
+
NeqLiterals = {},
|
|
10
11
|
SourceNames extends string = never,
|
|
11
12
|
Contradiction extends boolean = false,
|
|
12
13
|
Unknown extends boolean = false
|
|
@@ -14,13 +15,22 @@ export interface Context<
|
|
|
14
15
|
readonly nonNullKeys: NonNullKeys
|
|
15
16
|
readonly nullKeys: NullKeys
|
|
16
17
|
readonly eqLiterals: EqLiterals
|
|
18
|
+
readonly neqLiterals: NeqLiterals
|
|
17
19
|
readonly sourceNames: SourceNames
|
|
18
20
|
readonly contradiction: Contradiction
|
|
19
21
|
readonly unknown: Unknown
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
export type EmptyContext = Context
|
|
23
|
-
type AnyContext = Context<
|
|
25
|
+
type AnyContext = Context<
|
|
26
|
+
string,
|
|
27
|
+
string,
|
|
28
|
+
Record<string, string>,
|
|
29
|
+
Record<string, string>,
|
|
30
|
+
string,
|
|
31
|
+
boolean,
|
|
32
|
+
boolean
|
|
33
|
+
>
|
|
24
34
|
|
|
25
35
|
type Frame<
|
|
26
36
|
Formula extends PredicateFormula = PredicateFormula,
|
|
@@ -41,6 +51,15 @@ type EqLiteralValueOf<
|
|
|
41
51
|
: never
|
|
42
52
|
: never
|
|
43
53
|
|
|
54
|
+
type NeqLiteralValuesOf<
|
|
55
|
+
NeqLiterals,
|
|
56
|
+
Key extends string
|
|
57
|
+
> = NeqLiterals extends Record<string, string>
|
|
58
|
+
? Key extends keyof NeqLiterals
|
|
59
|
+
? NeqLiterals[Key]
|
|
60
|
+
: never
|
|
61
|
+
: never
|
|
62
|
+
|
|
44
63
|
type MergeEqLiteralMaps<Left, Right> = {
|
|
45
64
|
readonly [K in Extract<keyof Left | keyof Right, string>]:
|
|
46
65
|
K extends keyof Left
|
|
@@ -54,6 +73,17 @@ type MergeEqLiteralMaps<Left, Right> = {
|
|
|
54
73
|
: never
|
|
55
74
|
}
|
|
56
75
|
|
|
76
|
+
type MergeNeqLiteralMaps<Left, Right> = {
|
|
77
|
+
readonly [K in Extract<keyof Left | keyof Right, string>]:
|
|
78
|
+
K extends keyof Left
|
|
79
|
+
? K extends keyof Right
|
|
80
|
+
? Left[K] | Right[K]
|
|
81
|
+
: Left[K]
|
|
82
|
+
: K extends keyof Right
|
|
83
|
+
? Right[K]
|
|
84
|
+
: never
|
|
85
|
+
}
|
|
86
|
+
|
|
57
87
|
type FilterNeverValues<Map> = {
|
|
58
88
|
readonly [K in keyof Map as Map[K] extends never ? never : K]: Map[K]
|
|
59
89
|
}
|
|
@@ -62,6 +92,7 @@ type MarkContradiction<Ctx extends AnyContext> = Context<
|
|
|
62
92
|
Ctx["nonNullKeys"],
|
|
63
93
|
Ctx["nullKeys"],
|
|
64
94
|
Ctx["eqLiterals"],
|
|
95
|
+
Ctx["neqLiterals"],
|
|
65
96
|
Ctx["sourceNames"],
|
|
66
97
|
true,
|
|
67
98
|
Ctx["unknown"]
|
|
@@ -71,6 +102,7 @@ type MarkUnknown<Ctx extends AnyContext> = Context<
|
|
|
71
102
|
Ctx["nonNullKeys"],
|
|
72
103
|
Ctx["nullKeys"],
|
|
73
104
|
Ctx["eqLiterals"],
|
|
105
|
+
Ctx["neqLiterals"],
|
|
74
106
|
Ctx["sourceNames"],
|
|
75
107
|
Ctx["contradiction"],
|
|
76
108
|
true
|
|
@@ -83,6 +115,7 @@ type AddNonNull<
|
|
|
83
115
|
Ctx["nonNullKeys"] | Key,
|
|
84
116
|
Ctx["nullKeys"],
|
|
85
117
|
Ctx["eqLiterals"],
|
|
118
|
+
Ctx["neqLiterals"],
|
|
86
119
|
Ctx["sourceNames"] | SourceNameOfKey<Key>,
|
|
87
120
|
Key extends Ctx["nullKeys"] ? true : Ctx["contradiction"],
|
|
88
121
|
Ctx["unknown"]
|
|
@@ -95,6 +128,7 @@ type AddNull<
|
|
|
95
128
|
Ctx["nonNullKeys"],
|
|
96
129
|
Ctx["nullKeys"] | Key,
|
|
97
130
|
Ctx["eqLiterals"],
|
|
131
|
+
Ctx["neqLiterals"],
|
|
98
132
|
Ctx["sourceNames"] | SourceNameOfKey<Key>,
|
|
99
133
|
Key extends Ctx["nonNullKeys"] ? true : Ctx["contradiction"],
|
|
100
134
|
Ctx["unknown"]
|
|
@@ -108,11 +142,20 @@ type AddEqLiteral<
|
|
|
108
142
|
Ctx["nonNullKeys"] | Key,
|
|
109
143
|
Ctx["nullKeys"],
|
|
110
144
|
FilterNeverValues<MergeEqLiteralMaps<Ctx["eqLiterals"], { readonly [K in Key]: Value }>>,
|
|
145
|
+
Ctx["neqLiterals"],
|
|
111
146
|
Ctx["sourceNames"] | SourceNameOfKey<Key>,
|
|
112
147
|
EqLiteralValueOf<Ctx["eqLiterals"], Key> extends never
|
|
113
|
-
?
|
|
148
|
+
? NeqLiteralValuesOf<Ctx["neqLiterals"], Key> extends infer NeqValues
|
|
149
|
+
? Value extends NeqValues
|
|
150
|
+
? true
|
|
151
|
+
: Key extends Ctx["nullKeys"] ? true : Ctx["contradiction"]
|
|
152
|
+
: true
|
|
114
153
|
: EqLiteralValueOf<Ctx["eqLiterals"], Key> extends Value
|
|
115
|
-
?
|
|
154
|
+
? NeqLiteralValuesOf<Ctx["neqLiterals"], Key> extends infer NeqValues
|
|
155
|
+
? Value extends NeqValues
|
|
156
|
+
? true
|
|
157
|
+
: Key extends Ctx["nullKeys"] ? true : Ctx["contradiction"]
|
|
158
|
+
: true
|
|
116
159
|
: true,
|
|
117
160
|
Ctx["unknown"]
|
|
118
161
|
>
|
|
@@ -120,8 +163,22 @@ type AddEqLiteral<
|
|
|
120
163
|
type AddNeqLiteral<
|
|
121
164
|
Ctx extends AnyContext,
|
|
122
165
|
Key extends string,
|
|
123
|
-
|
|
124
|
-
> =
|
|
166
|
+
Value extends string
|
|
167
|
+
> = Context<
|
|
168
|
+
Ctx["nonNullKeys"] | Key,
|
|
169
|
+
Ctx["nullKeys"],
|
|
170
|
+
Ctx["eqLiterals"],
|
|
171
|
+
FilterNeverValues<MergeNeqLiteralMaps<Ctx["neqLiterals"], { readonly [K in Key]: Value }>>,
|
|
172
|
+
Ctx["sourceNames"] | SourceNameOfKey<Key>,
|
|
173
|
+
EqLiteralValueOf<Ctx["eqLiterals"], Key> extends infer EqValue
|
|
174
|
+
? [EqValue] extends [never]
|
|
175
|
+
? Key extends Ctx["nullKeys"] ? true : Ctx["contradiction"]
|
|
176
|
+
: EqValue extends Value
|
|
177
|
+
? true
|
|
178
|
+
: Key extends Ctx["nullKeys"] ? true : Ctx["contradiction"]
|
|
179
|
+
: true,
|
|
180
|
+
Ctx["unknown"]
|
|
181
|
+
>
|
|
125
182
|
|
|
126
183
|
type ApplyEqColumn<
|
|
127
184
|
Ctx extends AnyContext,
|
|
@@ -177,7 +234,7 @@ type ApplyNegativeAtom<
|
|
|
177
234
|
: Atom extends NonNullAtom<infer Key extends string>
|
|
178
235
|
? AddNull<Ctx, Key>
|
|
179
236
|
: Atom extends EqLiteralAtom<infer Key extends string, infer Value extends string>
|
|
180
|
-
?
|
|
237
|
+
? AddNeqLiteral<Ctx, Key, Value>
|
|
181
238
|
: Atom extends NeqLiteralAtom<infer Key extends string, infer Value extends string>
|
|
182
239
|
? AddEqLiteral<Ctx, Key, Value>
|
|
183
240
|
: Atom extends EqColumnAtom<infer Left extends string, infer Right extends string>
|
|
@@ -203,6 +260,14 @@ type IntersectEqLiteralMaps<
|
|
|
203
260
|
readonly [K in Extract<keyof Left, keyof Right>]: Left[K] extends Right[K] ? Left[K] : never
|
|
204
261
|
}>
|
|
205
262
|
|
|
263
|
+
type IntersectNeqLiteralMaps<
|
|
264
|
+
Left,
|
|
265
|
+
Right
|
|
266
|
+
> = FilterNeverValues<{
|
|
267
|
+
readonly [K in Extract<keyof Left, keyof Right>]:
|
|
268
|
+
Extract<Left[K], Right[K]> extends never ? never : Extract<Left[K], Right[K]>
|
|
269
|
+
}>
|
|
270
|
+
|
|
206
271
|
type IntersectContexts<
|
|
207
272
|
Left extends AnyContext,
|
|
208
273
|
Right extends AnyContext
|
|
@@ -210,6 +275,7 @@ type IntersectContexts<
|
|
|
210
275
|
Extract<Left["nonNullKeys"], Right["nonNullKeys"]>,
|
|
211
276
|
Extract<Left["nullKeys"], Right["nullKeys"]>,
|
|
212
277
|
IntersectEqLiteralMaps<Left["eqLiterals"], Right["eqLiterals"]>,
|
|
278
|
+
IntersectNeqLiteralMaps<Left["neqLiterals"], Right["neqLiterals"]>,
|
|
213
279
|
Extract<Left["sourceNames"], Right["sourceNames"]>,
|
|
214
280
|
Left["contradiction"] extends true
|
|
215
281
|
? Right["contradiction"]
|
|
@@ -228,7 +294,7 @@ type AnalyzeAnyBranches<
|
|
|
228
294
|
infer Head extends PredicateFormula,
|
|
229
295
|
...infer Tail extends readonly PredicateFormula[]
|
|
230
296
|
]
|
|
231
|
-
?
|
|
297
|
+
? AnalyzeBranch<Ctx, Head, Direction> extends infer Branch extends AnyContext
|
|
232
298
|
? Branch["contradiction"] extends true
|
|
233
299
|
? AnalyzeAnyBranches<Ctx, Tail, Direction, Current>
|
|
234
300
|
: [Current] extends [never]
|
|
@@ -241,6 +307,41 @@ type AnalyzeAnyBranches<
|
|
|
241
307
|
|
|
242
308
|
type Flip<Direction extends Polarity> = Direction extends "positive" ? "negative" : "positive"
|
|
243
309
|
|
|
310
|
+
type AnalyzeBranch<
|
|
311
|
+
Ctx extends AnyContext,
|
|
312
|
+
Formula extends PredicateFormula,
|
|
313
|
+
Direction extends Polarity
|
|
314
|
+
> = AnalyzeStack<Ctx, readonly [Frame<Formula, Direction>]>
|
|
315
|
+
|
|
316
|
+
type AnalyzeFrame<
|
|
317
|
+
Ctx extends AnyContext,
|
|
318
|
+
Formula extends PredicateFormula,
|
|
319
|
+
Direction extends Polarity,
|
|
320
|
+
Tail extends readonly Frame[]
|
|
321
|
+
> = [Formula] extends [TrueFormula]
|
|
322
|
+
? Direction extends "positive"
|
|
323
|
+
? AnalyzeStack<Ctx, Tail>
|
|
324
|
+
: MarkContradiction<Ctx>
|
|
325
|
+
: [Formula] extends [FalseFormula]
|
|
326
|
+
? Direction extends "positive"
|
|
327
|
+
? MarkContradiction<Ctx>
|
|
328
|
+
: AnalyzeStack<Ctx, Tail>
|
|
329
|
+
: [Formula] extends [AtomFormula<infer Atom extends PredicateAtom>]
|
|
330
|
+
? Direction extends "positive"
|
|
331
|
+
? AnalyzeStack<ApplyAtom<Ctx, Atom>, Tail>
|
|
332
|
+
: AnalyzeStack<ApplyNegativeAtom<Ctx, Atom>, Tail>
|
|
333
|
+
: [Formula] extends [NotFormula<infer Item extends PredicateFormula>]
|
|
334
|
+
? AnalyzeStack<Ctx, readonly [Frame<Item, Flip<Direction>>, ...Tail]>
|
|
335
|
+
: [Formula] extends [AllFormula<infer Items extends readonly PredicateFormula[]>]
|
|
336
|
+
? Direction extends "positive"
|
|
337
|
+
? AnalyzeStack<Ctx, readonly [...FramesFromItems<Items, "positive">, ...Tail]>
|
|
338
|
+
: AnalyzeStack<AnalyzeAnyBranches<Ctx, Items, "negative">, Tail>
|
|
339
|
+
: [Formula] extends [AnyFormula<infer Items extends readonly PredicateFormula[]>]
|
|
340
|
+
? Direction extends "positive"
|
|
341
|
+
? AnalyzeStack<AnalyzeAnyBranches<Ctx, Items, "positive">, Tail>
|
|
342
|
+
: AnalyzeStack<Ctx, readonly [...FramesFromItems<Items, "negative">, ...Tail]>
|
|
343
|
+
: AnalyzeStack<MarkUnknown<Ctx>, Tail>
|
|
344
|
+
|
|
244
345
|
export type AnalyzeStack<
|
|
245
346
|
Ctx extends AnyContext,
|
|
246
347
|
Stack extends readonly Frame[]
|
|
@@ -250,29 +351,7 @@ export type AnalyzeStack<
|
|
|
250
351
|
infer Head extends Frame,
|
|
251
352
|
...infer Tail extends readonly Frame[]
|
|
252
353
|
]
|
|
253
|
-
? Head["formula"]
|
|
254
|
-
? Head["polarity"] extends "positive"
|
|
255
|
-
? AnalyzeStack<Ctx, Tail>
|
|
256
|
-
: MarkContradiction<Ctx>
|
|
257
|
-
: Head["formula"] extends FalseFormula
|
|
258
|
-
? Head["polarity"] extends "positive"
|
|
259
|
-
? MarkContradiction<Ctx>
|
|
260
|
-
: AnalyzeStack<Ctx, Tail>
|
|
261
|
-
: Head["formula"] extends AtomFormula<infer Atom extends PredicateAtom>
|
|
262
|
-
? Head["polarity"] extends "positive"
|
|
263
|
-
? AnalyzeStack<ApplyAtom<Ctx, Atom>, Tail>
|
|
264
|
-
: AnalyzeStack<ApplyNegativeAtom<Ctx, Atom>, Tail>
|
|
265
|
-
: Head["formula"] extends NotFormula<infer Item extends PredicateFormula>
|
|
266
|
-
? AnalyzeStack<Ctx, readonly [Frame<Item, Flip<Head["polarity"]>>, ...Tail]>
|
|
267
|
-
: Head["formula"] extends AllFormula<infer Items extends readonly PredicateFormula[]>
|
|
268
|
-
? Head["polarity"] extends "positive"
|
|
269
|
-
? AnalyzeStack<Ctx, readonly [...FramesFromItems<Items, "positive">, ...Tail]>
|
|
270
|
-
: AnalyzeStack<AnalyzeAnyBranches<Ctx, Items, "negative">, Tail>
|
|
271
|
-
: Head["formula"] extends AnyFormula<infer Items extends readonly PredicateFormula[]>
|
|
272
|
-
? Head["polarity"] extends "positive"
|
|
273
|
-
? AnalyzeStack<AnalyzeAnyBranches<Ctx, Items, "positive">, Tail>
|
|
274
|
-
: AnalyzeStack<Ctx, readonly [...FramesFromItems<Items, "negative">, ...Tail]>
|
|
275
|
-
: AnalyzeStack<MarkUnknown<Ctx>, Tail>
|
|
354
|
+
? AnalyzeFrame<Ctx, Head["formula"], Head["polarity"], Tail>
|
|
276
355
|
: Ctx
|
|
277
356
|
|
|
278
357
|
export type AnalyzeFormula<Formula extends PredicateFormula> =
|
|
@@ -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 {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PredicateAtom } from "./
|
|
1
|
+
import type { PredicateAtom } from "./atom.js"
|
|
2
2
|
|
|
3
3
|
export interface TrueFormula {
|
|
4
4
|
readonly kind: "true"
|
|
@@ -62,27 +62,39 @@ type NormalizeAnyItems<
|
|
|
62
62
|
: NormalizeAnyItems<Tail, [...Current, Head]>
|
|
63
63
|
: Current
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
type CollapseNormalizedAll<
|
|
66
|
+
Items extends readonly PredicateFormula[]
|
|
67
|
+
> = NormalizeAllItems<Items> extends infer Normalized extends readonly PredicateFormula[]
|
|
68
|
+
? [Normalized] extends [readonly [FalseFormula]]
|
|
69
|
+
? FalseFormula
|
|
70
|
+
: [Normalized] extends [readonly []]
|
|
71
|
+
? TrueFormula
|
|
72
|
+
: [Normalized] extends [readonly [infer Only extends PredicateFormula]]
|
|
73
|
+
? Only
|
|
74
|
+
: AllFormula<Normalized>
|
|
75
|
+
: never
|
|
76
|
+
|
|
77
|
+
type CollapseNormalizedAny<
|
|
78
|
+
Items extends readonly PredicateFormula[]
|
|
79
|
+
> = NormalizeAnyItems<Items> extends infer Normalized extends readonly PredicateFormula[]
|
|
80
|
+
? [Normalized] extends [readonly [TrueFormula]]
|
|
81
|
+
? TrueFormula
|
|
82
|
+
: [Normalized] extends [readonly []]
|
|
68
83
|
? FalseFormula
|
|
69
|
-
:
|
|
70
|
-
?
|
|
71
|
-
:
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
: AnyFormula<NormalizeAnyItems<Items>>
|
|
82
|
-
: Formula extends NotFormula<infer Item extends PredicateFormula>
|
|
83
|
-
? Item extends TrueFormula
|
|
84
|
+
: [Normalized] extends [readonly [infer Only extends PredicateFormula]]
|
|
85
|
+
? Only
|
|
86
|
+
: AnyFormula<Normalized>
|
|
87
|
+
: never
|
|
88
|
+
|
|
89
|
+
export type NormalizeBooleanConstants<Formula extends PredicateFormula> =
|
|
90
|
+
[Formula] extends [AllFormula<infer Items extends readonly PredicateFormula[]>]
|
|
91
|
+
? CollapseNormalizedAll<Items>
|
|
92
|
+
: [Formula] extends [AnyFormula<infer Items extends readonly PredicateFormula[]>]
|
|
93
|
+
? CollapseNormalizedAny<Items>
|
|
94
|
+
: [Formula] extends [NotFormula<infer Item extends PredicateFormula>]
|
|
95
|
+
? [Item] extends [TrueFormula]
|
|
84
96
|
? FalseFormula
|
|
85
|
-
: Item extends FalseFormula
|
|
97
|
+
: [Item] extends [FalseFormula]
|
|
86
98
|
? TrueFormula
|
|
87
99
|
: Formula
|
|
88
100
|
: Formula
|
|
@@ -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 {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type * as Expression from "
|
|
2
|
-
import type * as ExpressionAst from "
|
|
1
|
+
import type * as Expression from "../scalar.js"
|
|
2
|
+
import type * as ExpressionAst from "../expression-ast.js"
|
|
3
3
|
|
|
4
4
|
export type ColumnKey<
|
|
5
5
|
TableName extends string,
|
|
@@ -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 {};
|