effect-qb 0.12.3
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 +1294 -0
- package/dist/mysql.js +57575 -0
- package/dist/postgres.js +6303 -0
- package/package.json +42 -0
- package/src/internal/aggregation-validation.ts +57 -0
- package/src/internal/case-analysis.ts +50 -0
- package/src/internal/coercion-analysis.ts +30 -0
- package/src/internal/coercion-errors.ts +29 -0
- package/src/internal/coercion-kind.ts +32 -0
- package/src/internal/coercion-normalize.ts +7 -0
- package/src/internal/coercion-rules.ts +25 -0
- package/src/internal/column-state.ts +453 -0
- package/src/internal/column.ts +417 -0
- package/src/internal/datatypes/define.ts +44 -0
- package/src/internal/datatypes/lookup.ts +280 -0
- package/src/internal/datatypes/shape.ts +72 -0
- package/src/internal/derived-table.ts +149 -0
- package/src/internal/dialect.ts +30 -0
- package/src/internal/executor.ts +390 -0
- package/src/internal/expression-ast.ts +349 -0
- package/src/internal/expression.ts +325 -0
- package/src/internal/grouping-key.ts +82 -0
- package/src/internal/json/ast.ts +63 -0
- package/src/internal/json/errors.ts +13 -0
- package/src/internal/json/path.ts +227 -0
- package/src/internal/json/shape.ts +1 -0
- package/src/internal/json/types.ts +386 -0
- package/src/internal/mysql-dialect.ts +39 -0
- package/src/internal/mysql-renderer.ts +37 -0
- package/src/internal/plan.ts +64 -0
- package/src/internal/postgres-dialect.ts +34 -0
- package/src/internal/postgres-renderer.ts +40 -0
- package/src/internal/predicate-analysis.ts +71 -0
- package/src/internal/predicate-atom.ts +43 -0
- package/src/internal/predicate-branches.ts +40 -0
- package/src/internal/predicate-context.ts +279 -0
- package/src/internal/predicate-formula.ts +100 -0
- package/src/internal/predicate-key.ts +28 -0
- package/src/internal/predicate-nnf.ts +12 -0
- package/src/internal/predicate-normalize.ts +202 -0
- package/src/internal/projection-alias.ts +15 -0
- package/src/internal/projections.ts +101 -0
- package/src/internal/query-ast.ts +297 -0
- package/src/internal/query-factory.ts +6757 -0
- package/src/internal/query-requirements.ts +40 -0
- package/src/internal/query.ts +1590 -0
- package/src/internal/renderer.ts +102 -0
- package/src/internal/runtime-normalize.ts +344 -0
- package/src/internal/runtime-schema.ts +428 -0
- package/src/internal/runtime-value.ts +85 -0
- package/src/internal/schema-derivation.ts +131 -0
- package/src/internal/sql-expression-renderer.ts +1353 -0
- package/src/internal/table-options.ts +225 -0
- package/src/internal/table.ts +674 -0
- package/src/mysql/column.ts +30 -0
- package/src/mysql/datatypes/index.ts +6 -0
- package/src/mysql/datatypes/spec.ts +180 -0
- package/src/mysql/errors/catalog.ts +51662 -0
- package/src/mysql/errors/fields.ts +21 -0
- package/src/mysql/errors/index.ts +18 -0
- package/src/mysql/errors/normalize.ts +232 -0
- package/src/mysql/errors/requirements.ts +73 -0
- package/src/mysql/executor.ts +134 -0
- package/src/mysql/query.ts +189 -0
- package/src/mysql/renderer.ts +19 -0
- package/src/mysql/table.ts +157 -0
- package/src/mysql.ts +18 -0
- package/src/postgres/column.ts +20 -0
- package/src/postgres/datatypes/index.ts +8 -0
- package/src/postgres/datatypes/spec.ts +264 -0
- package/src/postgres/errors/catalog.ts +452 -0
- package/src/postgres/errors/fields.ts +48 -0
- package/src/postgres/errors/index.ts +4 -0
- package/src/postgres/errors/normalize.ts +209 -0
- package/src/postgres/errors/requirements.ts +65 -0
- package/src/postgres/errors/types.ts +38 -0
- package/src/postgres/executor.ts +131 -0
- package/src/postgres/query.ts +189 -0
- package/src/postgres/renderer.ts +29 -0
- package/src/postgres/table.ts +157 -0
- package/src/postgres.ts +18 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export interface NullAtom<Key extends string> {
|
|
2
|
+
readonly kind: "is-null"
|
|
3
|
+
readonly key: Key
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface NonNullAtom<Key extends string> {
|
|
7
|
+
readonly kind: "is-not-null"
|
|
8
|
+
readonly key: Key
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface EqLiteralAtom<Key extends string, Value extends string> {
|
|
12
|
+
readonly kind: "eq-literal"
|
|
13
|
+
readonly key: Key
|
|
14
|
+
readonly value: Value
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface NeqLiteralAtom<Key extends string, Value extends string> {
|
|
18
|
+
readonly kind: "neq-literal"
|
|
19
|
+
readonly key: Key
|
|
20
|
+
readonly value: Value
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface EqColumnAtom<
|
|
24
|
+
LeftKey extends string,
|
|
25
|
+
RightKey extends string
|
|
26
|
+
> {
|
|
27
|
+
readonly kind: "eq-column"
|
|
28
|
+
readonly left: LeftKey
|
|
29
|
+
readonly right: RightKey
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface UnknownAtom<Tag extends string> {
|
|
33
|
+
readonly kind: "unknown"
|
|
34
|
+
readonly tag: Tag
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type PredicateAtom =
|
|
38
|
+
| NullAtom<string>
|
|
39
|
+
| NonNullAtom<string>
|
|
40
|
+
| EqLiteralAtom<string, string>
|
|
41
|
+
| NeqLiteralAtom<string, string>
|
|
42
|
+
| EqColumnAtom<string, string>
|
|
43
|
+
| UnknownAtom<string>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { PredicateAtom } from "./predicate-atom.js"
|
|
2
|
+
import type { AtomFormula, FalseFormula, PredicateFormula, TrueFormula } from "./predicate-formula.js"
|
|
3
|
+
|
|
4
|
+
export interface BranchLimitExceeded {
|
|
5
|
+
readonly kind: "branch-limit-exceeded"
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
type Branch = readonly PredicateAtom[]
|
|
9
|
+
type Branches = readonly Branch[]
|
|
10
|
+
|
|
11
|
+
export type AppendBranch<
|
|
12
|
+
Left extends Branches | BranchLimitExceeded,
|
|
13
|
+
Right extends Branches | BranchLimitExceeded,
|
|
14
|
+
_RemainingBudget extends readonly unknown[]
|
|
15
|
+
> = Left extends BranchLimitExceeded
|
|
16
|
+
? BranchLimitExceeded
|
|
17
|
+
: Right extends BranchLimitExceeded
|
|
18
|
+
? BranchLimitExceeded
|
|
19
|
+
: Left extends Branches
|
|
20
|
+
? Right extends Branches
|
|
21
|
+
? Left | Right
|
|
22
|
+
: BranchLimitExceeded
|
|
23
|
+
: BranchLimitExceeded
|
|
24
|
+
|
|
25
|
+
export type CrossProductBranches<
|
|
26
|
+
Left extends Branches | BranchLimitExceeded,
|
|
27
|
+
Right extends Branches | BranchLimitExceeded,
|
|
28
|
+
_RemainingBudget extends readonly unknown[]
|
|
29
|
+
> = AppendBranch<Left, Right, []>
|
|
30
|
+
|
|
31
|
+
export type BranchesOf<
|
|
32
|
+
Formula extends PredicateFormula,
|
|
33
|
+
_RemainingBudget extends readonly unknown[] = readonly [1]
|
|
34
|
+
> = Formula extends TrueFormula
|
|
35
|
+
? [[]]
|
|
36
|
+
: Formula extends FalseFormula
|
|
37
|
+
? []
|
|
38
|
+
: Formula extends AtomFormula<infer Atom extends PredicateAtom>
|
|
39
|
+
? [[Atom]]
|
|
40
|
+
: BranchLimitExceeded
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import type { EqColumnAtom, EqLiteralAtom, NeqLiteralAtom, NonNullAtom, NullAtom, PredicateAtom, UnknownAtom } from "./predicate-atom.js"
|
|
2
|
+
import type { AllFormula, AnyFormula, AtomFormula, FalseFormula, NotFormula, PredicateFormula, TrueFormula } from "./predicate-formula.js"
|
|
3
|
+
|
|
4
|
+
type Polarity = "positive" | "negative"
|
|
5
|
+
|
|
6
|
+
export interface Context<
|
|
7
|
+
NonNullKeys extends string = never,
|
|
8
|
+
NullKeys extends string = never,
|
|
9
|
+
EqLiterals = {},
|
|
10
|
+
SourceNames extends string = never,
|
|
11
|
+
Contradiction extends boolean = false,
|
|
12
|
+
Unknown extends boolean = false
|
|
13
|
+
> {
|
|
14
|
+
readonly nonNullKeys: NonNullKeys
|
|
15
|
+
readonly nullKeys: NullKeys
|
|
16
|
+
readonly eqLiterals: EqLiterals
|
|
17
|
+
readonly sourceNames: SourceNames
|
|
18
|
+
readonly contradiction: Contradiction
|
|
19
|
+
readonly unknown: Unknown
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type EmptyContext = Context
|
|
23
|
+
type AnyContext = Context<string, string, Record<string, string>, string, boolean, boolean>
|
|
24
|
+
|
|
25
|
+
type Frame<
|
|
26
|
+
Formula extends PredicateFormula = PredicateFormula,
|
|
27
|
+
Direction extends Polarity = Polarity
|
|
28
|
+
> = {
|
|
29
|
+
readonly formula: Formula
|
|
30
|
+
readonly polarity: Direction
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type SourceNameOfKey<Key extends string> = Key extends `${infer SourceName}.${string}` ? SourceName : never
|
|
34
|
+
|
|
35
|
+
type EqLiteralValueOf<
|
|
36
|
+
EqLiterals,
|
|
37
|
+
Key extends string
|
|
38
|
+
> = EqLiterals extends Record<string, string>
|
|
39
|
+
? Key extends keyof EqLiterals
|
|
40
|
+
? EqLiterals[Key]
|
|
41
|
+
: never
|
|
42
|
+
: never
|
|
43
|
+
|
|
44
|
+
type MergeEqLiteralMaps<Left, Right> = {
|
|
45
|
+
readonly [K in Extract<keyof Left | keyof Right, string>]:
|
|
46
|
+
K extends keyof Left
|
|
47
|
+
? K extends keyof Right
|
|
48
|
+
? Left[K] extends Right[K]
|
|
49
|
+
? Left[K]
|
|
50
|
+
: never
|
|
51
|
+
: Left[K]
|
|
52
|
+
: K extends keyof Right
|
|
53
|
+
? Right[K]
|
|
54
|
+
: never
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
type FilterNeverValues<Map> = {
|
|
58
|
+
readonly [K in keyof Map as Map[K] extends never ? never : K]: Map[K]
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
type MarkContradiction<Ctx extends AnyContext> = Context<
|
|
62
|
+
Ctx["nonNullKeys"],
|
|
63
|
+
Ctx["nullKeys"],
|
|
64
|
+
Ctx["eqLiterals"],
|
|
65
|
+
Ctx["sourceNames"],
|
|
66
|
+
true,
|
|
67
|
+
Ctx["unknown"]
|
|
68
|
+
>
|
|
69
|
+
|
|
70
|
+
type MarkUnknown<Ctx extends AnyContext> = Context<
|
|
71
|
+
Ctx["nonNullKeys"],
|
|
72
|
+
Ctx["nullKeys"],
|
|
73
|
+
Ctx["eqLiterals"],
|
|
74
|
+
Ctx["sourceNames"],
|
|
75
|
+
Ctx["contradiction"],
|
|
76
|
+
true
|
|
77
|
+
>
|
|
78
|
+
|
|
79
|
+
type AddNonNull<
|
|
80
|
+
Ctx extends AnyContext,
|
|
81
|
+
Key extends string
|
|
82
|
+
> = Context<
|
|
83
|
+
Ctx["nonNullKeys"] | Key,
|
|
84
|
+
Ctx["nullKeys"],
|
|
85
|
+
Ctx["eqLiterals"],
|
|
86
|
+
Ctx["sourceNames"] | SourceNameOfKey<Key>,
|
|
87
|
+
Key extends Ctx["nullKeys"] ? true : Ctx["contradiction"],
|
|
88
|
+
Ctx["unknown"]
|
|
89
|
+
>
|
|
90
|
+
|
|
91
|
+
type AddNull<
|
|
92
|
+
Ctx extends AnyContext,
|
|
93
|
+
Key extends string
|
|
94
|
+
> = Context<
|
|
95
|
+
Ctx["nonNullKeys"],
|
|
96
|
+
Ctx["nullKeys"] | Key,
|
|
97
|
+
Ctx["eqLiterals"],
|
|
98
|
+
Ctx["sourceNames"] | SourceNameOfKey<Key>,
|
|
99
|
+
Key extends Ctx["nonNullKeys"] ? true : Ctx["contradiction"],
|
|
100
|
+
Ctx["unknown"]
|
|
101
|
+
>
|
|
102
|
+
|
|
103
|
+
type AddEqLiteral<
|
|
104
|
+
Ctx extends AnyContext,
|
|
105
|
+
Key extends string,
|
|
106
|
+
Value extends string
|
|
107
|
+
> = Context<
|
|
108
|
+
Ctx["nonNullKeys"] | Key,
|
|
109
|
+
Ctx["nullKeys"],
|
|
110
|
+
FilterNeverValues<MergeEqLiteralMaps<Ctx["eqLiterals"], { readonly [K in Key]: Value }>>,
|
|
111
|
+
Ctx["sourceNames"] | SourceNameOfKey<Key>,
|
|
112
|
+
EqLiteralValueOf<Ctx["eqLiterals"], Key> extends never
|
|
113
|
+
? Key extends Ctx["nullKeys"] ? true : Ctx["contradiction"]
|
|
114
|
+
: EqLiteralValueOf<Ctx["eqLiterals"], Key> extends Value
|
|
115
|
+
? Key extends Ctx["nullKeys"] ? true : Ctx["contradiction"]
|
|
116
|
+
: true,
|
|
117
|
+
Ctx["unknown"]
|
|
118
|
+
>
|
|
119
|
+
|
|
120
|
+
type AddNeqLiteral<
|
|
121
|
+
Ctx extends AnyContext,
|
|
122
|
+
Key extends string,
|
|
123
|
+
_Value extends string
|
|
124
|
+
> = AddNonNull<Ctx, Key>
|
|
125
|
+
|
|
126
|
+
type ApplyEqColumn<
|
|
127
|
+
Ctx extends AnyContext,
|
|
128
|
+
Left extends string,
|
|
129
|
+
Right extends string
|
|
130
|
+
> =
|
|
131
|
+
EqLiteralValueOf<Ctx["eqLiterals"], Left> extends infer LeftValue
|
|
132
|
+
? EqLiteralValueOf<Ctx["eqLiterals"], Right> extends infer RightValue
|
|
133
|
+
? [LeftValue] extends [never]
|
|
134
|
+
? [RightValue] extends [never]
|
|
135
|
+
? AddNonNull<AddNonNull<Ctx, Left>, Right>
|
|
136
|
+
: RightValue extends string
|
|
137
|
+
? AddEqLiteral<AddNonNull<AddNonNull<Ctx, Left>, Right>, Left, RightValue>
|
|
138
|
+
: MarkContradiction<Ctx>
|
|
139
|
+
: [RightValue] extends [never]
|
|
140
|
+
? LeftValue extends string
|
|
141
|
+
? AddEqLiteral<AddNonNull<AddNonNull<Ctx, Left>, Right>, Right, LeftValue>
|
|
142
|
+
: MarkContradiction<Ctx>
|
|
143
|
+
: LeftValue extends RightValue
|
|
144
|
+
? LeftValue extends string
|
|
145
|
+
? RightValue extends string
|
|
146
|
+
? AddEqLiteral<AddEqLiteral<AddNonNull<AddNonNull<Ctx, Left>, Right>, Left, LeftValue>, Right, RightValue>
|
|
147
|
+
: MarkContradiction<Ctx>
|
|
148
|
+
: MarkContradiction<Ctx>
|
|
149
|
+
: MarkContradiction<Ctx>
|
|
150
|
+
: never
|
|
151
|
+
: never
|
|
152
|
+
|
|
153
|
+
type ApplyAtom<
|
|
154
|
+
Ctx extends AnyContext,
|
|
155
|
+
Atom extends PredicateAtom
|
|
156
|
+
> =
|
|
157
|
+
Atom extends NullAtom<infer Key extends string>
|
|
158
|
+
? AddNull<Ctx, Key>
|
|
159
|
+
: Atom extends NonNullAtom<infer Key extends string>
|
|
160
|
+
? AddNonNull<Ctx, Key>
|
|
161
|
+
: Atom extends EqLiteralAtom<infer Key extends string, infer Value extends string>
|
|
162
|
+
? AddEqLiteral<Ctx, Key, Value>
|
|
163
|
+
: Atom extends NeqLiteralAtom<infer Key extends string, infer Value extends string>
|
|
164
|
+
? AddNeqLiteral<Ctx, Key, Value>
|
|
165
|
+
: Atom extends EqColumnAtom<infer Left extends string, infer Right extends string>
|
|
166
|
+
? ApplyEqColumn<Ctx, Left, Right>
|
|
167
|
+
: Atom extends UnknownAtom<any>
|
|
168
|
+
? MarkUnknown<Ctx>
|
|
169
|
+
: Ctx
|
|
170
|
+
|
|
171
|
+
type ApplyNegativeAtom<
|
|
172
|
+
Ctx extends AnyContext,
|
|
173
|
+
Atom extends PredicateAtom
|
|
174
|
+
> =
|
|
175
|
+
Atom extends NullAtom<infer Key extends string>
|
|
176
|
+
? AddNonNull<Ctx, Key>
|
|
177
|
+
: Atom extends NonNullAtom<infer Key extends string>
|
|
178
|
+
? AddNull<Ctx, Key>
|
|
179
|
+
: Atom extends EqLiteralAtom<infer Key extends string, infer Value extends string>
|
|
180
|
+
? AddNonNull<Ctx, Key>
|
|
181
|
+
: Atom extends NeqLiteralAtom<infer Key extends string, infer Value extends string>
|
|
182
|
+
? AddEqLiteral<Ctx, Key, Value>
|
|
183
|
+
: Atom extends EqColumnAtom<infer Left extends string, infer Right extends string>
|
|
184
|
+
? AddNonNull<AddNonNull<Ctx, Left>, Right>
|
|
185
|
+
: Atom extends UnknownAtom<any>
|
|
186
|
+
? MarkUnknown<Ctx>
|
|
187
|
+
: Ctx
|
|
188
|
+
|
|
189
|
+
type FramesFromItems<
|
|
190
|
+
Items extends readonly PredicateFormula[],
|
|
191
|
+
Direction extends Polarity
|
|
192
|
+
> = Items extends readonly [
|
|
193
|
+
infer Head extends PredicateFormula,
|
|
194
|
+
...infer Tail extends readonly PredicateFormula[]
|
|
195
|
+
]
|
|
196
|
+
? readonly [Frame<Head, Direction>, ...FramesFromItems<Tail, Direction>]
|
|
197
|
+
: readonly []
|
|
198
|
+
|
|
199
|
+
type IntersectEqLiteralMaps<
|
|
200
|
+
Left,
|
|
201
|
+
Right
|
|
202
|
+
> = FilterNeverValues<{
|
|
203
|
+
readonly [K in Extract<keyof Left, keyof Right>]: Left[K] extends Right[K] ? Left[K] : never
|
|
204
|
+
}>
|
|
205
|
+
|
|
206
|
+
type IntersectContexts<
|
|
207
|
+
Left extends AnyContext,
|
|
208
|
+
Right extends AnyContext
|
|
209
|
+
> = Context<
|
|
210
|
+
Extract<Left["nonNullKeys"], Right["nonNullKeys"]>,
|
|
211
|
+
Extract<Left["nullKeys"], Right["nullKeys"]>,
|
|
212
|
+
IntersectEqLiteralMaps<Left["eqLiterals"], Right["eqLiterals"]>,
|
|
213
|
+
Extract<Left["sourceNames"], Right["sourceNames"]>,
|
|
214
|
+
Left["contradiction"] extends true
|
|
215
|
+
? Right["contradiction"]
|
|
216
|
+
: Right["contradiction"] extends true
|
|
217
|
+
? Left["contradiction"]
|
|
218
|
+
: false,
|
|
219
|
+
Left["unknown"] extends true ? true : Right["unknown"] extends true ? true : false
|
|
220
|
+
>
|
|
221
|
+
|
|
222
|
+
type AnalyzeAnyBranches<
|
|
223
|
+
Ctx extends AnyContext,
|
|
224
|
+
Items extends readonly PredicateFormula[],
|
|
225
|
+
Direction extends Polarity,
|
|
226
|
+
Current extends AnyContext | never = never
|
|
227
|
+
> = Items extends readonly [
|
|
228
|
+
infer Head extends PredicateFormula,
|
|
229
|
+
...infer Tail extends readonly PredicateFormula[]
|
|
230
|
+
]
|
|
231
|
+
? AnalyzeStack<Ctx, readonly [Frame<Head, Direction>]> extends infer Branch extends AnyContext
|
|
232
|
+
? Branch["contradiction"] extends true
|
|
233
|
+
? AnalyzeAnyBranches<Ctx, Tail, Direction, Current>
|
|
234
|
+
: [Current] extends [never]
|
|
235
|
+
? AnalyzeAnyBranches<Ctx, Tail, Direction, Branch>
|
|
236
|
+
: AnalyzeAnyBranches<Ctx, Tail, Direction, IntersectContexts<Current, Branch>>
|
|
237
|
+
: never
|
|
238
|
+
: [Current] extends [never]
|
|
239
|
+
? MarkContradiction<Ctx>
|
|
240
|
+
: Current
|
|
241
|
+
|
|
242
|
+
type Flip<Direction extends Polarity> = Direction extends "positive" ? "negative" : "positive"
|
|
243
|
+
|
|
244
|
+
export type AnalyzeStack<
|
|
245
|
+
Ctx extends AnyContext,
|
|
246
|
+
Stack extends readonly Frame[]
|
|
247
|
+
> = Ctx["contradiction"] extends true
|
|
248
|
+
? Ctx
|
|
249
|
+
: Stack extends readonly [
|
|
250
|
+
infer Head extends Frame,
|
|
251
|
+
...infer Tail extends readonly Frame[]
|
|
252
|
+
]
|
|
253
|
+
? Head["formula"] extends TrueFormula
|
|
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>
|
|
276
|
+
: Ctx
|
|
277
|
+
|
|
278
|
+
export type AnalyzeFormula<Formula extends PredicateFormula> =
|
|
279
|
+
AnalyzeStack<EmptyContext, readonly [Frame<Formula, "positive">]>
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { PredicateAtom } from "./predicate-atom.js"
|
|
2
|
+
|
|
3
|
+
export interface TrueFormula {
|
|
4
|
+
readonly kind: "true"
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface FalseFormula {
|
|
8
|
+
readonly kind: "false"
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface AtomFormula<Atom extends PredicateAtom> {
|
|
12
|
+
readonly kind: "atom"
|
|
13
|
+
readonly atom: Atom
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface AllFormula<Items extends readonly PredicateFormula[]> {
|
|
17
|
+
readonly kind: "all"
|
|
18
|
+
readonly items: Items
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface AnyFormula<Items extends readonly PredicateFormula[]> {
|
|
22
|
+
readonly kind: "any"
|
|
23
|
+
readonly items: Items
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface NotFormula<Item extends PredicateFormula> {
|
|
27
|
+
readonly kind: "not"
|
|
28
|
+
readonly item: Item
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type PredicateFormula =
|
|
32
|
+
| TrueFormula
|
|
33
|
+
| FalseFormula
|
|
34
|
+
| AtomFormula<PredicateAtom>
|
|
35
|
+
| AllFormula<readonly PredicateFormula[]>
|
|
36
|
+
| AnyFormula<readonly PredicateFormula[]>
|
|
37
|
+
| NotFormula<PredicateFormula>
|
|
38
|
+
|
|
39
|
+
type NormalizeAllItems<
|
|
40
|
+
Items extends readonly PredicateFormula[],
|
|
41
|
+
Current extends readonly PredicateFormula[] = []
|
|
42
|
+
> = Items extends readonly [infer Head extends PredicateFormula, ...infer Tail extends readonly PredicateFormula[]]
|
|
43
|
+
? Head extends TrueFormula
|
|
44
|
+
? NormalizeAllItems<Tail, Current>
|
|
45
|
+
: Head extends FalseFormula
|
|
46
|
+
? [FalseFormula]
|
|
47
|
+
: Head extends AllFormula<infer Nested extends readonly PredicateFormula[]>
|
|
48
|
+
? NormalizeAllItems<[...Nested, ...Tail], Current>
|
|
49
|
+
: NormalizeAllItems<Tail, [...Current, Head]>
|
|
50
|
+
: Current
|
|
51
|
+
|
|
52
|
+
type NormalizeAnyItems<
|
|
53
|
+
Items extends readonly PredicateFormula[],
|
|
54
|
+
Current extends readonly PredicateFormula[] = []
|
|
55
|
+
> = Items extends readonly [infer Head extends PredicateFormula, ...infer Tail extends readonly PredicateFormula[]]
|
|
56
|
+
? Head extends FalseFormula
|
|
57
|
+
? NormalizeAnyItems<Tail, Current>
|
|
58
|
+
: Head extends TrueFormula
|
|
59
|
+
? [TrueFormula]
|
|
60
|
+
: Head extends AnyFormula<infer Nested extends readonly PredicateFormula[]>
|
|
61
|
+
? NormalizeAnyItems<[...Nested, ...Tail], Current>
|
|
62
|
+
: NormalizeAnyItems<Tail, [...Current, Head]>
|
|
63
|
+
: Current
|
|
64
|
+
|
|
65
|
+
export type NormalizeBooleanConstants<Formula extends PredicateFormula> =
|
|
66
|
+
Formula extends AllFormula<infer Items extends readonly PredicateFormula[]>
|
|
67
|
+
? NormalizeAllItems<Items> extends [FalseFormula]
|
|
68
|
+
? FalseFormula
|
|
69
|
+
: NormalizeAllItems<Items> extends readonly []
|
|
70
|
+
? TrueFormula
|
|
71
|
+
: NormalizeAllItems<Items> extends readonly [infer Only extends PredicateFormula]
|
|
72
|
+
? Only
|
|
73
|
+
: AllFormula<NormalizeAllItems<Items>>
|
|
74
|
+
: Formula extends AnyFormula<infer Items extends readonly PredicateFormula[]>
|
|
75
|
+
? NormalizeAnyItems<Items> extends [TrueFormula]
|
|
76
|
+
? TrueFormula
|
|
77
|
+
: NormalizeAnyItems<Items> extends readonly []
|
|
78
|
+
? FalseFormula
|
|
79
|
+
: NormalizeAnyItems<Items> extends readonly [infer Only extends PredicateFormula]
|
|
80
|
+
? Only
|
|
81
|
+
: AnyFormula<NormalizeAnyItems<Items>>
|
|
82
|
+
: Formula extends NotFormula<infer Item extends PredicateFormula>
|
|
83
|
+
? Item extends TrueFormula
|
|
84
|
+
? FalseFormula
|
|
85
|
+
: Item extends FalseFormula
|
|
86
|
+
? TrueFormula
|
|
87
|
+
: Formula
|
|
88
|
+
: Formula
|
|
89
|
+
|
|
90
|
+
export type And<
|
|
91
|
+
Left extends PredicateFormula,
|
|
92
|
+
Right extends PredicateFormula
|
|
93
|
+
> = NormalizeBooleanConstants<AllFormula<[Left, Right]>>
|
|
94
|
+
|
|
95
|
+
export type Or<
|
|
96
|
+
Left extends PredicateFormula,
|
|
97
|
+
Right extends PredicateFormula
|
|
98
|
+
> = NormalizeBooleanConstants<AnyFormula<[Left, Right]>>
|
|
99
|
+
|
|
100
|
+
export type Not<Value extends PredicateFormula> = NormalizeBooleanConstants<NotFormula<Value>>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type * as Expression from "./expression.js"
|
|
2
|
+
import type * as ExpressionAst from "./expression-ast.js"
|
|
3
|
+
|
|
4
|
+
export type ColumnKey<
|
|
5
|
+
TableName extends string,
|
|
6
|
+
ColumnName extends string
|
|
7
|
+
> = `${TableName}.${ColumnName}`
|
|
8
|
+
|
|
9
|
+
export type ColumnKeyOfAst<Ast extends ExpressionAst.Any> =
|
|
10
|
+
Ast extends ExpressionAst.ColumnNode<infer TableName extends string, infer ColumnName extends string>
|
|
11
|
+
? ColumnKey<TableName, ColumnName>
|
|
12
|
+
: never
|
|
13
|
+
|
|
14
|
+
type AstOf<Value extends Expression.Any> = Value extends {
|
|
15
|
+
readonly [ExpressionAst.TypeId]: infer Ast extends ExpressionAst.Any
|
|
16
|
+
} ? Ast : never
|
|
17
|
+
|
|
18
|
+
export type ColumnKeyOfExpression<Value extends Expression.Any> = ColumnKeyOfAst<AstOf<Value>>
|
|
19
|
+
|
|
20
|
+
export type LiteralKey<Value> =
|
|
21
|
+
Value extends string ? `string:${Value}` :
|
|
22
|
+
Value extends number ? `number:${Value}` :
|
|
23
|
+
Value extends boolean ? `boolean:${Value}` :
|
|
24
|
+
Value extends null ? "null" :
|
|
25
|
+
Value extends Date ? `date:${string}` :
|
|
26
|
+
"unknown"
|
|
27
|
+
|
|
28
|
+
export type ValueKey<Value> = LiteralKey<Value>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EqColumnAtom, EqLiteralAtom, NeqLiteralAtom, NonNullAtom, NullAtom, PredicateAtom, UnknownAtom } from "./predicate-atom.js"
|
|
2
|
+
import type { PredicateFormula } from "./predicate-formula.js"
|
|
3
|
+
|
|
4
|
+
export type NegateAtom<Atom extends PredicateAtom> =
|
|
5
|
+
Atom extends NullAtom<infer Key extends string> ? NonNullAtom<Key> :
|
|
6
|
+
Atom extends NonNullAtom<infer Key extends string> ? NullAtom<Key> :
|
|
7
|
+
Atom extends EqLiteralAtom<infer Key extends string, infer Value extends string> ? NeqLiteralAtom<Key, Value> :
|
|
8
|
+
Atom extends NeqLiteralAtom<infer Key extends string, infer Value extends string> ? EqLiteralAtom<Key, Value> :
|
|
9
|
+
Atom extends EqColumnAtom<any, any> ? UnknownAtom<"not:eq-column"> :
|
|
10
|
+
UnknownAtom<"not:unknown">
|
|
11
|
+
|
|
12
|
+
export type ToNnf<Formula extends PredicateFormula> = Formula
|