effect-qb 0.14.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/dist/mysql.js +61270 -4259
- package/dist/postgres/metadata.js +176 -82
- package/dist/postgres.js +5903 -3316
- package/package.json +14 -1
- 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 +36 -47
- package/src/internal/column.ts +21 -305
- package/src/internal/datatypes/define.d.ts +17 -0
- package/src/internal/datatypes/define.ts +18 -4
- package/src/internal/datatypes/lookup.d.ts +44 -0
- package/src/internal/datatypes/lookup.ts +61 -152
- package/src/internal/datatypes/shape.d.ts +16 -0
- package/src/internal/datatypes/shape.ts +1 -1
- package/src/internal/derived-table.d.ts +4 -0
- package/src/internal/derived-table.ts +21 -16
- package/src/internal/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 +132 -31
- package/src/internal/expression-ast.ts +15 -5
- package/src/internal/grouping-key.d.ts +3 -0
- package/src/internal/grouping-key.ts +1 -1
- package/src/internal/implication-runtime.d.ts +15 -0
- package/src/internal/implication-runtime.ts +4 -4
- package/src/internal/json/ast.d.ts +30 -0
- package/src/internal/json/ast.ts +1 -1
- package/src/internal/json/errors.d.ts +8 -0
- package/src/internal/json/path.d.ts +75 -0
- package/src/internal/json/path.ts +1 -1
- package/src/internal/json/types.d.ts +62 -0
- package/src/internal/predicate/analysis.d.ts +20 -0
- package/src/internal/{predicate-analysis.ts → predicate/analysis.ts} +3 -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} +8 -5
- package/src/internal/predicate/formula.d.ts +35 -0
- package/src/internal/{predicate-formula.ts → predicate/formula.ts} +1 -1
- package/src/internal/predicate/key.d.ts +11 -0
- package/src/internal/{predicate-key.ts → 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 → predicate/normalize.ts} +19 -19
- package/src/internal/predicate/runtime.d.ts +31 -0
- package/src/internal/{predicate-runtime.ts → predicate/runtime.ts} +9 -6
- 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 +389 -313
- package/src/internal/renderer.ts +7 -21
- package/src/internal/row-set.d.ts +53 -0
- package/src/internal/{plan.ts → row-set.ts} +11 -9
- package/src/internal/{runtime-normalize.ts → runtime/normalize.ts} +9 -31
- package/src/internal/{runtime-schema.ts → runtime/schema.ts} +13 -38
- package/src/internal/runtime/value.d.ts +22 -0
- package/src/internal/{runtime-value.ts → runtime/value.ts} +2 -2
- package/src/internal/scalar.d.ts +107 -0
- package/src/internal/scalar.ts +191 -0
- package/src/internal/schema-derivation.d.ts +105 -0
- package/src/internal/schema-expression.d.ts +18 -0
- package/src/internal/schema-expression.ts +38 -7
- package/src/internal/table-options.d.ts +94 -0
- package/src/internal/table-options.ts +8 -2
- package/src/internal/table.d.ts +173 -0
- package/src/internal/table.ts +32 -14
- package/src/mysql/column.ts +94 -18
- package/src/mysql/datatypes/index.ts +47 -7
- package/src/mysql/errors/generated.ts +57336 -0
- package/src/mysql/errors/index.ts +1 -0
- package/src/mysql/errors/normalize.ts +55 -53
- package/src/mysql/errors/types.ts +74 -0
- package/src/mysql/executor.ts +69 -7
- package/src/mysql/function/aggregate.ts +1 -5
- package/src/mysql/function/core.ts +1 -4
- package/src/mysql/function/index.ts +0 -1
- package/src/mysql/function/string.ts +1 -5
- package/src/mysql/function/temporal.ts +12 -15
- package/src/mysql/function/window.ts +1 -6
- package/src/{internal/mysql-dialect.ts → mysql/internal/dialect.ts} +1 -1
- package/src/{internal/mysql-query.ts → mysql/internal/dsl.ts} +1024 -2082
- 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 -91
- 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 +11 -12
- package/src/postgres/column.ts +178 -46
- package/src/postgres/datatypes/index.d.ts +515 -0
- package/src/postgres/datatypes/index.ts +22 -13
- package/src/postgres/datatypes/spec.d.ts +412 -0
- package/src/postgres/errors/generated.ts +2636 -0
- package/src/postgres/errors/index.ts +1 -0
- package/src/postgres/errors/normalize.ts +47 -62
- package/src/postgres/errors/types.ts +92 -34
- package/src/postgres/executor.ts +37 -5
- package/src/postgres/function/aggregate.ts +1 -5
- package/src/postgres/function/core.ts +12 -6
- package/src/postgres/function/index.ts +0 -1
- package/src/postgres/function/string.ts +1 -5
- package/src/postgres/function/temporal.ts +12 -15
- package/src/postgres/function/window.ts +1 -6
- package/src/{internal/postgres-dialect.ts → postgres/internal/dialect.ts} +1 -1
- package/src/{internal/postgres-query.ts → postgres/internal/dsl.ts} +1085 -2089
- package/src/{internal/postgres-renderer.ts → postgres/internal/renderer.ts} +6 -6
- package/src/postgres/internal/schema-ddl.ts +108 -0
- package/src/{internal/postgres-schema-model.ts → postgres/internal/schema-model.ts} +12 -6
- package/src/{internal → postgres/internal}/sql-expression-renderer.ts +19 -17
- package/src/postgres/{function/json.ts → json.ts} +77 -85
- package/src/postgres/metadata.ts +2 -2
- package/src/postgres/query.ts +113 -89
- package/src/postgres/renderer.ts +3 -13
- package/src/postgres/schema-expression.ts +2 -1
- package/src/postgres/schema-management.ts +1 -1
- package/src/postgres/table.ts +12 -4
- package/src/postgres/type.ts +29 -2
- package/src/postgres.ts +6 -4
- package/src/internal/expression.ts +0 -327
- package/src/internal/schema-ddl.ts +0 -55
- package/src/mysql/function/json.ts +0 -4
- package/src/mysql/private/query.ts +0 -1
- package/src/postgres/private/query.ts +0 -1
- /package/src/internal/{predicate-atom.ts → predicate/atom.ts} +0 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type * as Expression from "../scalar.js";
|
|
2
|
+
import type * as JsonPath from "./path.js";
|
|
3
|
+
export type JsonKind = "jsonGet" | "jsonPath" | "jsonAccess" | "jsonTraverse" | "jsonGetText" | "jsonPathText" | "jsonAccessText" | "jsonTraverseText" | "jsonHasKey" | "jsonKeyExists" | "jsonHasAnyKeys" | "jsonHasAllKeys" | "jsonConcat" | "jsonMerge" | "jsonDelete" | "jsonDeletePath" | "jsonRemove" | "jsonSet" | "jsonInsert" | "jsonPathExists" | "jsonPathMatch" | "jsonBuildObject" | "jsonBuildArray" | "jsonToJson" | "jsonToJsonb" | "jsonTypeOf" | "jsonLength" | "jsonKeys" | "jsonStripNulls";
|
|
4
|
+
/**
|
|
5
|
+
* Broad JSON AST node accepted by the renderer.
|
|
6
|
+
*
|
|
7
|
+
* The JSON subsystem is intentionally shaped as a small grammar rather than a
|
|
8
|
+
* collection of bespoke node interfaces. The renderer uses the `kind` plus the
|
|
9
|
+
* common field names below to lower the nodes into dialect SQL.
|
|
10
|
+
*/
|
|
11
|
+
export interface JsonNode<Kind extends JsonKind = JsonKind> {
|
|
12
|
+
readonly kind: Kind;
|
|
13
|
+
readonly value?: Expression.Any;
|
|
14
|
+
readonly base?: Expression.Any;
|
|
15
|
+
readonly left?: Expression.Any;
|
|
16
|
+
readonly right?: Expression.Any;
|
|
17
|
+
readonly path?: JsonPath.Path<any> | readonly any[];
|
|
18
|
+
readonly segments?: readonly any[];
|
|
19
|
+
readonly keys?: readonly string[];
|
|
20
|
+
readonly query?: string | Expression.Any;
|
|
21
|
+
readonly newValue?: Expression.Any;
|
|
22
|
+
readonly insert?: Expression.Any;
|
|
23
|
+
readonly createMissing?: boolean;
|
|
24
|
+
readonly insertAfter?: boolean;
|
|
25
|
+
readonly entries?: readonly {
|
|
26
|
+
readonly key: string;
|
|
27
|
+
readonly value: Expression.Any;
|
|
28
|
+
}[];
|
|
29
|
+
readonly values?: readonly Expression.Any[];
|
|
30
|
+
}
|
package/src/internal/json/ast.ts
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type JsonPathUsageError<Operation extends string, Root, Path, Reason extends string> = {
|
|
2
|
+
readonly __effect_qb_error__: "effect-qb: invalid json path usage";
|
|
3
|
+
readonly __effect_qb_json_operation__: Operation;
|
|
4
|
+
readonly __effect_qb_json_reason__: Reason;
|
|
5
|
+
readonly __effect_qb_json_root__: Root;
|
|
6
|
+
readonly __effect_qb_json_path__: Path;
|
|
7
|
+
readonly __effect_qb_hint__: "Use key(...) on objects, index(...) on arrays, and prefer exact key/index paths when you want precise output typing";
|
|
8
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type * as Expression from "../scalar.js";
|
|
2
|
+
import type { JsonPathUsageError } from "./errors.js";
|
|
3
|
+
import type { JsonBuildArray as JsonBuildArrayResult, JsonBuildObject as JsonBuildObjectResult, JsonConcatResult, JsonDeleteAtPath, JsonLiteralInput, JsonStripNullsResult as JsonStripNullsResultValue, JsonValueAtPath, JsonSetAtPath } from "./types.js";
|
|
4
|
+
import type { JsonKeysResult as JsonKeysResultValue, JsonLengthResult as JsonLengthResultValue, JsonTextResult as JsonTextResultValue, JsonTypeName as JsonTypeNameValue } from "./types.js";
|
|
5
|
+
export declare const SegmentTypeId: unique symbol;
|
|
6
|
+
export type SegmentTypeId = typeof SegmentTypeId;
|
|
7
|
+
export declare const TypeId: unique symbol;
|
|
8
|
+
export type TypeId = typeof TypeId;
|
|
9
|
+
type SegmentState<Kind extends string> = {
|
|
10
|
+
readonly kind: Kind;
|
|
11
|
+
};
|
|
12
|
+
export interface KeySegment<Key extends string = string> {
|
|
13
|
+
readonly [SegmentTypeId]: SegmentState<"key">;
|
|
14
|
+
readonly kind: "key";
|
|
15
|
+
readonly key: Key;
|
|
16
|
+
}
|
|
17
|
+
export interface IndexSegment<Index extends number = number> {
|
|
18
|
+
readonly [SegmentTypeId]: SegmentState<"index">;
|
|
19
|
+
readonly kind: "index";
|
|
20
|
+
readonly index: Index;
|
|
21
|
+
}
|
|
22
|
+
export interface WildcardSegment {
|
|
23
|
+
readonly [SegmentTypeId]: SegmentState<"wildcard">;
|
|
24
|
+
readonly kind: "wildcard";
|
|
25
|
+
}
|
|
26
|
+
export interface SliceSegment<Start extends number | undefined = number | undefined, End extends number | undefined = number | undefined> {
|
|
27
|
+
readonly [SegmentTypeId]: SegmentState<"slice">;
|
|
28
|
+
readonly kind: "slice";
|
|
29
|
+
readonly start: Start;
|
|
30
|
+
readonly end: End;
|
|
31
|
+
}
|
|
32
|
+
export interface DescendSegment {
|
|
33
|
+
readonly [SegmentTypeId]: SegmentState<"descend">;
|
|
34
|
+
readonly kind: "descend";
|
|
35
|
+
}
|
|
36
|
+
export type CanonicalSegment = KeySegment | IndexSegment | WildcardSegment | SliceSegment | DescendSegment;
|
|
37
|
+
export type AnySegment = any;
|
|
38
|
+
export type ExactSegment = KeySegment | IndexSegment;
|
|
39
|
+
type PathState<Segments extends readonly CanonicalSegment[]> = {
|
|
40
|
+
readonly segments: Segments;
|
|
41
|
+
};
|
|
42
|
+
export interface Path<Segments extends readonly CanonicalSegment[] = readonly CanonicalSegment[]> {
|
|
43
|
+
readonly [TypeId]: PathState<Segments>;
|
|
44
|
+
readonly segments: Segments;
|
|
45
|
+
}
|
|
46
|
+
export type JsonPath<Segments extends readonly CanonicalSegment[] = readonly CanonicalSegment[]> = Path<Segments>;
|
|
47
|
+
export type JsonPathSegments = readonly CanonicalSegment[];
|
|
48
|
+
export type JsonPrimitive = JsonLiteralInput;
|
|
49
|
+
export type JsonLiteral = JsonLiteralInput;
|
|
50
|
+
export type JsonInput = Expression.Any | JsonLiteral;
|
|
51
|
+
export declare const key: <Key extends string>(value: Key) => KeySegment<Key>;
|
|
52
|
+
export declare const index: <Index extends number>(value: Index) => IndexSegment<Index>;
|
|
53
|
+
export declare const wildcard: () => WildcardSegment;
|
|
54
|
+
export declare const slice: <Start extends number | undefined = undefined, End extends number | undefined = undefined>(start?: Start | undefined, end?: End | undefined) => SliceSegment<Start, End>;
|
|
55
|
+
export declare const descend: () => DescendSegment;
|
|
56
|
+
export declare const path: <Segments extends readonly CanonicalSegment[]>(...segments: Segments) => Path<Segments>;
|
|
57
|
+
export declare const makeJsonPath: <Segments extends readonly CanonicalSegment[]>(...segments: Segments) => Path<Segments>;
|
|
58
|
+
export type SegmentsOf<Value extends Path<any>> = Value[typeof TypeId]["segments"];
|
|
59
|
+
export type IsExactSegment<Segment extends CanonicalSegment> = Segment extends ExactSegment ? true : false;
|
|
60
|
+
export type IsExactPath<PathValue extends Path<any>> = SegmentsOf<PathValue> extends readonly [infer Head extends CanonicalSegment, ...infer Tail extends readonly CanonicalSegment[]] ? IsExactSegment<Head> extends true ? Tail extends readonly [] ? true : IsExactPath<Path<Tail>> : false : true;
|
|
61
|
+
export type JsonPathValue<Root, PathValue extends Path<any>, Operation extends string = "json.get"> = JsonValueAtPath<Root, PathValue, Operation>;
|
|
62
|
+
export type JsonPathOutput<Root, PathValue extends Path<any>, Operation extends string = "json.get"> = JsonValueAtPath<Root, PathValue, Operation>;
|
|
63
|
+
export type JsonPathCompatible<Root, PathValue extends Path<any>, Operation extends string = "json.get"> = JsonValueAtPath<Root, PathValue, Operation> extends JsonPathUsageError<any, any, any, any> ? JsonValueAtPath<Root, PathValue, Operation> : PathValue;
|
|
64
|
+
export type JsonPathUpdate<Root, PathValue extends Path<any>, Next, Operation extends string = "json.set"> = JsonSetAtPath<Root, PathValue, Next, Operation>;
|
|
65
|
+
export type JsonPathDelete<Root, PathValue extends Path<any>, Operation extends string = "json.delete"> = JsonDeleteAtPath<Root, PathValue, Operation>;
|
|
66
|
+
export type JsonConcat<Left, Right> = JsonConcatResult<Left, Right>;
|
|
67
|
+
export type JsonBuildObject<Shape extends Record<string, JsonInput>> = JsonBuildObjectResult<Shape>;
|
|
68
|
+
export type JsonBuildArray<Values extends readonly JsonInput[]> = JsonBuildArrayResult<Values>;
|
|
69
|
+
export type JsonTextResult<Value> = JsonTextResultValue<Value>;
|
|
70
|
+
export type JsonTypeName<Value> = JsonTypeNameValue<Value>;
|
|
71
|
+
export type JsonLengthResult<Value> = JsonLengthResultValue<Value>;
|
|
72
|
+
export type JsonKeysResult<Value> = JsonKeysResultValue<Value>;
|
|
73
|
+
export type JsonStripNullsResult<Value> = JsonStripNullsResultValue<Value>;
|
|
74
|
+
export type JsonValueOfInput<Input> = Input extends Expression.Any ? Expression.RuntimeOf<Input> : Input extends JsonLiteral ? Input : never;
|
|
75
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type * as JsonPath from "./path.js";
|
|
2
|
+
import type { JsonPathUsageError } from "./errors.js";
|
|
3
|
+
export type JsonPrimitive = string | number | boolean | null;
|
|
4
|
+
export type JsonValue = JsonPrimitive | readonly JsonValue[] | {
|
|
5
|
+
readonly [key: string]: JsonValue;
|
|
6
|
+
};
|
|
7
|
+
type OptionalKeyOf<ObjectType extends object, Key extends PropertyKey> = Key extends keyof ObjectType ? {} extends Pick<ObjectType, Key> ? true : false : true;
|
|
8
|
+
type NormalizeJsonTuple<Values extends readonly unknown[]> = Values extends readonly [] ? readonly [] : Values extends readonly [infer Head, ...infer Tail] ? readonly [NormalizeJsonLiteral<Head>, ...NormalizeJsonTuple<Tail>] : readonly NormalizeJsonLiteral<Values[number]>[];
|
|
9
|
+
type NormalizeJsonObject<ObjectType extends object> = {
|
|
10
|
+
readonly [Key in keyof ObjectType as Key extends string ? Key : never]: NormalizeJsonLiteral<Exclude<ObjectType[Key], undefined>>;
|
|
11
|
+
};
|
|
12
|
+
export type NormalizeJsonLiteral<Value> = [
|
|
13
|
+
Value
|
|
14
|
+
] extends [never] ? never : Value extends JsonPrimitive ? Value : Value extends undefined | bigint | symbol | Date | ((...args: readonly any[]) => any) ? never : Value extends readonly unknown[] ? NormalizeJsonTuple<Value> : Value extends object ? NormalizeJsonObject<Value> : never;
|
|
15
|
+
export type JsonLiteralInput = JsonPrimitive | readonly JsonLiteralInput[] | {
|
|
16
|
+
readonly [key: string]: JsonLiteralInput;
|
|
17
|
+
};
|
|
18
|
+
type StripNull<Value> = Exclude<Value, null>;
|
|
19
|
+
type KeyStep<Root, Key extends string, Operation extends string> = Root extends readonly unknown[] ? JsonPathUsageError<Operation, Root, JsonPath.KeySegment<Key>, "key segments cannot be applied to arrays"> : Root extends object ? Key extends keyof Root ? NormalizeJsonLiteral<Exclude<Root[Key], undefined>> | (OptionalKeyOf<Root, Key> extends true ? null : never) : Root extends Record<string, infer Value> ? NormalizeJsonLiteral<Value> | null : null : JsonPathUsageError<Operation, Root, JsonPath.KeySegment<Key>, "key segments require an object-like json value">;
|
|
20
|
+
type TupleIndex<Values extends readonly unknown[], Index extends number, Count extends readonly unknown[] = []> = Values extends readonly [infer Head, ...infer Tail] ? Count["length"] extends Index ? Head : TupleIndex<Tail, Index, [...Count, unknown]> : never;
|
|
21
|
+
type DropTupleIndex<Values extends readonly unknown[], Index extends number, Count extends readonly unknown[] = []> = Values extends readonly [infer Head, ...infer Tail] ? Count["length"] extends Index ? readonly [...Tail] : readonly [Head, ...DropTupleIndex<Tail, Index, [...Count, unknown]>] : readonly [];
|
|
22
|
+
type SetTupleIndex<Values extends readonly unknown[], Index extends number, Next, Count extends readonly unknown[] = []> = Values extends readonly [infer Head, ...infer Tail] ? Count["length"] extends Index ? readonly [Next, ...Tail] : readonly [Head, ...SetTupleIndex<Tail, Index, Next, [...Count, unknown]>] : readonly NormalizeJsonLiteral<Next>[];
|
|
23
|
+
type InsertTupleIndex<Values extends readonly unknown[], Index extends number, Next, After extends boolean, Count extends readonly unknown[] = []> = Values extends readonly [infer Head, ...infer Tail] ? Count["length"] extends Index ? After extends true ? readonly [Head, NormalizeJsonLiteral<Next>, ...Tail] : readonly [NormalizeJsonLiteral<Next>, Head, ...Tail] : readonly [Head, ...InsertTupleIndex<Tail, Index, Next, After, [...Count, unknown]>] : readonly NormalizeJsonLiteral<Next>[];
|
|
24
|
+
type IndexStep<Root, Index extends number, Operation extends string> = Root extends readonly unknown[] ? number extends Root["length"] ? NormalizeJsonLiteral<Root[number]> | null : NormalizeJsonLiteral<TupleIndex<Root, Index>> | (TupleIndex<Root, Index> extends never ? null : never) : JsonPathUsageError<Operation, Root, JsonPath.IndexSegment<Index>, "index segments require an array-like json value">;
|
|
25
|
+
type NonExactStep<Root, Segment extends JsonPath.CanonicalSegment> = Segment extends JsonPath.WildcardSegment ? NormalizeJsonLiteral<Root> | null : Segment extends JsonPath.SliceSegment<any, any> ? NormalizeJsonLiteral<Root> | null : Segment extends JsonPath.DescendSegment ? NormalizeJsonLiteral<Root> | null : never;
|
|
26
|
+
type StepValue<Root, Segment extends JsonPath.CanonicalSegment, Operation extends string> = Segment extends JsonPath.KeySegment<infer Key extends string> ? KeyStep<Root, Key, Operation> : Segment extends JsonPath.IndexSegment<infer Index extends number> ? IndexStep<Root, Index, Operation> : NonExactStep<Root, Segment>;
|
|
27
|
+
type StepSet<Root, Segment extends JsonPath.CanonicalSegment, Next, Operation extends string> = Segment extends JsonPath.KeySegment<infer Key extends string> ? Root extends readonly unknown[] ? JsonPathUsageError<Operation, Root, Segment, "key segments cannot update arrays"> : Root extends object ? Omit<Root, Key> & {
|
|
28
|
+
readonly [K in Key]: NormalizeJsonLiteral<Next>;
|
|
29
|
+
} : JsonPathUsageError<Operation, Root, Segment, "key segments require an object-like json value"> : Segment extends JsonPath.IndexSegment<infer Index extends number> ? Root extends readonly unknown[] ? number extends Root["length"] ? readonly (NormalizeJsonLiteral<Root[number]> | NormalizeJsonLiteral<Next>)[] : SetTupleIndex<Root, Index, Next> : JsonPathUsageError<Operation, Root, Segment, "index segments require an array-like json value"> : NormalizeJsonLiteral<Root>;
|
|
30
|
+
type StepDelete<Root, Segment extends JsonPath.CanonicalSegment, Operation extends string> = Segment extends JsonPath.KeySegment<infer Key extends string> ? Root extends readonly unknown[] ? JsonPathUsageError<Operation, Root, Segment, "key segments cannot delete from arrays"> : Root extends object ? Omit<Root, Key> : JsonPathUsageError<Operation, Root, Segment, "key segments require an object-like json value"> : Segment extends JsonPath.IndexSegment<infer Index extends number> ? Root extends readonly unknown[] ? number extends Root["length"] ? Root : DropTupleIndex<Root, Index> : JsonPathUsageError<Operation, Root, Segment, "index segments require an array-like json value"> : NormalizeJsonLiteral<Root>;
|
|
31
|
+
type StepInsert<Root, Segment extends JsonPath.CanonicalSegment, Next, After extends boolean, Operation extends string> = Segment extends JsonPath.IndexSegment<infer Index extends number> ? Root extends readonly unknown[] ? number extends Root["length"] ? readonly (NormalizeJsonLiteral<Root[number]> | NormalizeJsonLiteral<Next>)[] : InsertTupleIndex<Root, Index, Next, After> : JsonPathUsageError<Operation, Root, Segment, "index segments require an array-like json value"> : Segment extends JsonPath.KeySegment<infer Key extends string> ? Root extends readonly unknown[] ? JsonPathUsageError<Operation, Root, Segment, "key segments cannot insert into arrays"> : Root extends object ? Key extends keyof Root ? Root : Root & {
|
|
32
|
+
readonly [K in Key]: NormalizeJsonLiteral<Next>;
|
|
33
|
+
} : JsonPathUsageError<Operation, Root, Segment, "key segments require an object-like json value"> : NormalizeJsonLiteral<Root>;
|
|
34
|
+
type RecurseValue<Current, Segments extends readonly JsonPath.CanonicalSegment[], Operation extends string> = Segments extends readonly [infer Head extends JsonPath.CanonicalSegment, ...infer Tail extends readonly JsonPath.CanonicalSegment[]] ? StepValue<Current, Head, Operation> extends infer Next ? Next extends JsonPathUsageError<any, any, any, any> ? Next : Tail extends readonly [] ? Next : null extends Next ? RecurseValue<StripNull<Next>, Tail, Operation> | null : RecurseValue<Next, Tail, Operation> : never : NormalizeJsonLiteral<Current>;
|
|
35
|
+
type RecurseSet<Current, Segments extends readonly JsonPath.CanonicalSegment[], Next, Operation extends string> = Segments extends readonly [infer Head extends JsonPath.CanonicalSegment, ...infer Tail extends readonly JsonPath.CanonicalSegment[]] ? Tail extends readonly [] ? StepSet<Current, Head, Next, Operation> : StepValue<Current, Head, Operation> extends infer Child ? Child extends JsonPathUsageError<any, any, any, any> ? Child : StepSet<Current, Head, RecurseSet<StripNull<Child>, Tail, Next, Operation>, Operation> : never : NormalizeJsonLiteral<Next>;
|
|
36
|
+
type RecurseDelete<Current, Segments extends readonly JsonPath.CanonicalSegment[], Operation extends string> = Segments extends readonly [infer Head extends JsonPath.CanonicalSegment, ...infer Tail extends readonly JsonPath.CanonicalSegment[]] ? Tail extends readonly [] ? StepDelete<Current, Head, Operation> : StepValue<Current, Head, Operation> extends infer Child ? Child extends JsonPathUsageError<any, any, any, any> ? Child : StepSet<Current, Head, RecurseDelete<StripNull<Child>, Tail, Operation>, Operation> : never : NormalizeJsonLiteral<Current>;
|
|
37
|
+
type RecurseInsert<Current, Segments extends readonly JsonPath.CanonicalSegment[], Next, After extends boolean, Operation extends string> = Segments extends readonly [infer Head extends JsonPath.CanonicalSegment, ...infer Tail extends readonly JsonPath.CanonicalSegment[]] ? Tail extends readonly [] ? StepInsert<Current, Head, Next, After, Operation> : StepValue<Current, Head, Operation> extends infer Child ? Child extends JsonPathUsageError<any, any, any, any> ? Child : StepSet<Current, Head, RecurseInsert<StripNull<Child>, Tail, Next, After, Operation>, Operation> : never : NormalizeJsonLiteral<Current>;
|
|
38
|
+
export type JsonValueAtPath<Root, PathValue extends JsonPath.Path<any>, Operation extends string = "json.get"> = RecurseValue<NormalizeJsonLiteral<Root>, JsonPath.SegmentsOf<PathValue>, Operation>;
|
|
39
|
+
export type JsonSetAtPath<Root, PathValue extends JsonPath.Path<any>, Next, Operation extends string = "json.set"> = RecurseSet<NormalizeJsonLiteral<Root>, JsonPath.SegmentsOf<PathValue>, Next, Operation>;
|
|
40
|
+
export type JsonInsertAtPath<Root, PathValue extends JsonPath.Path<any>, Next, After extends boolean = false, Operation extends string = "json.insert"> = RecurseInsert<NormalizeJsonLiteral<Root>, JsonPath.SegmentsOf<PathValue>, Next, After, Operation>;
|
|
41
|
+
export type JsonDeleteAtPath<Root, PathValue extends JsonPath.Path<any>, Operation extends string = "json.delete"> = RecurseDelete<NormalizeJsonLiteral<Root>, JsonPath.SegmentsOf<PathValue>, Operation>;
|
|
42
|
+
type ArrayElement<Value> = Value extends readonly (infer Element)[] ? Element : never;
|
|
43
|
+
type MergeJsonObjects<Left extends object, Right extends object> = Omit<Left, keyof Right> & Right;
|
|
44
|
+
type StripNullsTuple<Values extends readonly unknown[]> = Values extends readonly [] ? readonly [] : Values extends readonly [infer Head, ...infer Tail] ? readonly [JsonStripNullsResult<Head>, ...StripNullsTuple<Tail>] : readonly JsonStripNullsResult<Values[number]>[];
|
|
45
|
+
type StripNullsObject<ObjectType extends object> = ({
|
|
46
|
+
readonly [Key in keyof ObjectType as Key extends string ? null extends NormalizeJsonLiteral<Exclude<ObjectType[Key], undefined>> ? never : Key : never]-?: JsonStripNullsResult<Exclude<ObjectType[Key], null>>;
|
|
47
|
+
} & {
|
|
48
|
+
readonly [Key in keyof ObjectType as Key extends string ? null extends NormalizeJsonLiteral<Exclude<ObjectType[Key], undefined>> ? Key : never : never]?: JsonStripNullsResult<Exclude<ObjectType[Key], null>>;
|
|
49
|
+
});
|
|
50
|
+
export type JsonStripNullsResult<Value> = Value extends null ? null : Value extends readonly unknown[] ? StripNullsTuple<Value> : Value extends object ? StripNullsObject<Value> : Value;
|
|
51
|
+
export type JsonConcatResult<Left, Right> = NormalizeJsonLiteral<Left> extends infer NormalizedLeft ? NormalizeJsonLiteral<Right> extends infer NormalizedRight ? NormalizedLeft extends readonly unknown[] ? NormalizedRight extends readonly unknown[] ? number extends NormalizedLeft["length"] | NormalizedRight["length"] ? readonly (ArrayElement<NormalizedLeft> | ArrayElement<NormalizedRight>)[] : readonly [...NormalizedLeft, ...NormalizedRight] : unknown : NormalizedLeft extends object ? NormalizedRight extends object ? MergeJsonObjects<NormalizedLeft, NormalizedRight> : unknown : unknown : never : never;
|
|
52
|
+
export type JsonBuildObject<Shape extends Record<string, unknown>> = {
|
|
53
|
+
readonly [K in keyof Shape]: NormalizeJsonLiteral<Shape[K]>;
|
|
54
|
+
};
|
|
55
|
+
export type JsonBuildArray<Values extends readonly unknown[]> = {
|
|
56
|
+
readonly [K in keyof Values]: NormalizeJsonLiteral<Values[K]>;
|
|
57
|
+
} & readonly unknown[];
|
|
58
|
+
export type JsonTextResult<Value> = Value extends JsonPrimitive ? `${Value}` : string;
|
|
59
|
+
export type JsonTypeName<Value> = NormalizeJsonLiteral<Value> extends null ? "null" : NormalizeJsonLiteral<Value> extends string ? "string" : NormalizeJsonLiteral<Value> extends number ? "number" : NormalizeJsonLiteral<Value> extends boolean ? "boolean" : NormalizeJsonLiteral<Value> extends readonly unknown[] ? "array" : NormalizeJsonLiteral<Value> extends object ? "object" : "unknown";
|
|
60
|
+
export type JsonLengthResult<Value> = NormalizeJsonLiteral<Value> extends readonly unknown[] ? number : NormalizeJsonLiteral<Value> extends object ? number : null;
|
|
61
|
+
export type JsonKeysResult<Value> = NormalizeJsonLiteral<Value> extends object ? NormalizeJsonLiteral<Value> extends readonly unknown[] ? readonly [] : readonly Extract<keyof NormalizeJsonLiteral<Value>, string>[] : null;
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AnalyzeFormula } from "./context.js";
|
|
2
|
+
import type { FormulaOfPredicate } from "./normalize.js";
|
|
3
|
+
import type { And, Not, PredicateFormula, TrueFormula } from "./formula.js";
|
|
4
|
+
type ContextOf<Formula extends PredicateFormula> = AnalyzeFormula<Formula>;
|
|
5
|
+
export type GuaranteedNonNullKeys<Assumptions extends PredicateFormula> = ContextOf<Assumptions>["nonNullKeys"];
|
|
6
|
+
export type GuaranteedNullKeys<Assumptions extends PredicateFormula> = ContextOf<Assumptions>["nullKeys"];
|
|
7
|
+
export type GuaranteedSourceNames<Assumptions extends PredicateFormula> = ContextOf<Assumptions>["sourceNames"];
|
|
8
|
+
export type GuaranteedEqLiteral<Assumptions extends PredicateFormula, Key extends string> = Key extends keyof ContextOf<Assumptions>["eqLiterals"] ? ContextOf<Assumptions>["eqLiterals"][Key] : never;
|
|
9
|
+
type IsContradiction<Formula extends PredicateFormula> = ContextOf<Formula>["contradiction"] extends true ? true : false;
|
|
10
|
+
type ContradictoryAssumption<Assumptions extends PredicateFormula, Formula extends PredicateFormula> = IsContradiction<And<Assumptions, Formula>>;
|
|
11
|
+
type ContradictionFromNegation<Assumptions extends PredicateFormula, Formula extends PredicateFormula> = IsContradiction<And<Assumptions, Not<Formula>>>;
|
|
12
|
+
export type ContradictsFormula<Assumptions extends PredicateFormula, Formula extends PredicateFormula> = ContradictoryAssumption<Assumptions, Formula>;
|
|
13
|
+
export type ImpliesFormula<Assumptions extends PredicateFormula, Formula extends PredicateFormula> = ContradictionFromNegation<Assumptions, Formula>;
|
|
14
|
+
export type AssumeFormulaTrue<Assumptions extends PredicateFormula, Formula extends PredicateFormula> = Assumptions extends TrueFormula ? Formula : And<Assumptions, Formula>;
|
|
15
|
+
export type AssumeFormulaFalse<Assumptions extends PredicateFormula, Formula extends PredicateFormula> = Assumptions extends TrueFormula ? Not<Formula> : And<Assumptions, Not<Formula>>;
|
|
16
|
+
export type AssumeTrue<Assumptions extends PredicateFormula, Predicate> = AssumeFormulaTrue<Assumptions, FormulaOfPredicate<Predicate>>;
|
|
17
|
+
export type AssumeFalse<Assumptions extends PredicateFormula, Predicate> = AssumeFormulaFalse<Assumptions, FormulaOfPredicate<Predicate>>;
|
|
18
|
+
export type Contradicts<Assumptions extends PredicateFormula, Predicate> = ContradictoryAssumption<Assumptions, FormulaOfPredicate<Predicate>>;
|
|
19
|
+
export type Implies<Assumptions extends PredicateFormula, Predicate> = ContradictionFromNegation<Assumptions, FormulaOfPredicate<Predicate>>;
|
|
20
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { AnalyzeFormula } from "./
|
|
2
|
-
import type { FormulaOfPredicate } from "./
|
|
3
|
-
import type { And, Not, PredicateFormula, TrueFormula } from "./
|
|
1
|
+
import type { AnalyzeFormula } from "./context.js"
|
|
2
|
+
import type { FormulaOfPredicate } from "./normalize.js"
|
|
3
|
+
import type { And, Not, PredicateFormula, TrueFormula } from "./formula.js"
|
|
4
4
|
|
|
5
5
|
type ContextOf<Formula extends PredicateFormula> = AnalyzeFormula<Formula>
|
|
6
6
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface NullAtom<Key extends string> {
|
|
2
|
+
readonly kind: "is-null";
|
|
3
|
+
readonly key: Key;
|
|
4
|
+
}
|
|
5
|
+
export interface NonNullAtom<Key extends string> {
|
|
6
|
+
readonly kind: "is-not-null";
|
|
7
|
+
readonly key: Key;
|
|
8
|
+
}
|
|
9
|
+
export interface EqLiteralAtom<Key extends string, Value extends string> {
|
|
10
|
+
readonly kind: "eq-literal";
|
|
11
|
+
readonly key: Key;
|
|
12
|
+
readonly value: Value;
|
|
13
|
+
}
|
|
14
|
+
export interface NeqLiteralAtom<Key extends string, Value extends string> {
|
|
15
|
+
readonly kind: "neq-literal";
|
|
16
|
+
readonly key: Key;
|
|
17
|
+
readonly value: Value;
|
|
18
|
+
}
|
|
19
|
+
export interface EqColumnAtom<LeftKey extends string, RightKey extends string> {
|
|
20
|
+
readonly kind: "eq-column";
|
|
21
|
+
readonly left: LeftKey;
|
|
22
|
+
readonly right: RightKey;
|
|
23
|
+
}
|
|
24
|
+
export interface UnknownAtom<Tag extends string> {
|
|
25
|
+
readonly kind: "unknown";
|
|
26
|
+
readonly tag: Tag;
|
|
27
|
+
}
|
|
28
|
+
export type PredicateAtom = NullAtom<string> | NonNullAtom<string> | EqLiteralAtom<string, string> | NeqLiteralAtom<string, string> | EqColumnAtom<string, string> | UnknownAtom<string>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PredicateAtom } from "./
|
|
2
|
-
import type { AtomFormula, FalseFormula, PredicateFormula, TrueFormula } from "./
|
|
1
|
+
import type { PredicateAtom } from "./atom.js"
|
|
2
|
+
import type { AtomFormula, FalseFormula, PredicateFormula, TrueFormula } from "./formula.js"
|
|
3
3
|
|
|
4
4
|
export interface BranchLimitExceeded {
|
|
5
5
|
readonly kind: "branch-limit-exceeded"
|
|
@@ -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
|
|
|
@@ -246,9 +246,12 @@ type ApplyNegativeAtom<
|
|
|
246
246
|
type FramesFromItems<
|
|
247
247
|
Items extends readonly PredicateFormula[],
|
|
248
248
|
Direction extends Polarity
|
|
249
|
-
> =
|
|
250
|
-
|
|
251
|
-
|
|
249
|
+
> = Items extends readonly [
|
|
250
|
+
infer Head extends PredicateFormula,
|
|
251
|
+
...infer Tail extends readonly PredicateFormula[]
|
|
252
|
+
]
|
|
253
|
+
? readonly [Frame<Head, Direction>, ...FramesFromItems<Tail, Direction>]
|
|
254
|
+
: readonly []
|
|
252
255
|
|
|
253
256
|
type IntersectEqLiteralMaps<
|
|
254
257
|
Left,
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { PredicateAtom } from "./atom.js";
|
|
2
|
+
export interface TrueFormula {
|
|
3
|
+
readonly kind: "true";
|
|
4
|
+
}
|
|
5
|
+
export interface FalseFormula {
|
|
6
|
+
readonly kind: "false";
|
|
7
|
+
}
|
|
8
|
+
export interface AtomFormula<Atom extends PredicateAtom> {
|
|
9
|
+
readonly kind: "atom";
|
|
10
|
+
readonly atom: Atom;
|
|
11
|
+
}
|
|
12
|
+
export interface AllFormula<Items extends readonly PredicateFormula[]> {
|
|
13
|
+
readonly kind: "all";
|
|
14
|
+
readonly items: Items;
|
|
15
|
+
}
|
|
16
|
+
export interface AnyFormula<Items extends readonly PredicateFormula[]> {
|
|
17
|
+
readonly kind: "any";
|
|
18
|
+
readonly items: Items;
|
|
19
|
+
}
|
|
20
|
+
export interface NotFormula<Item extends PredicateFormula> {
|
|
21
|
+
readonly kind: "not";
|
|
22
|
+
readonly item: Item;
|
|
23
|
+
}
|
|
24
|
+
export type PredicateFormula = TrueFormula | FalseFormula | AtomFormula<PredicateAtom> | AllFormula<readonly PredicateFormula[]> | AnyFormula<readonly PredicateFormula[]> | NotFormula<PredicateFormula>;
|
|
25
|
+
type NormalizeAllItems<Items extends readonly PredicateFormula[], Current extends readonly PredicateFormula[] = []> = Items extends readonly [infer Head extends PredicateFormula, ...infer Tail extends readonly PredicateFormula[]] ? Head extends TrueFormula ? NormalizeAllItems<Tail, Current> : Head extends FalseFormula ? [FalseFormula] : Head extends AllFormula<infer Nested extends readonly PredicateFormula[]> ? NormalizeAllItems<[...Nested, ...Tail], Current> : NormalizeAllItems<Tail, [...Current, Head]> : Current;
|
|
26
|
+
type NormalizeAnyItems<Items extends readonly PredicateFormula[], Current extends readonly PredicateFormula[] = []> = Items extends readonly [infer Head extends PredicateFormula, ...infer Tail extends readonly PredicateFormula[]] ? Head extends FalseFormula ? NormalizeAnyItems<Tail, Current> : Head extends TrueFormula ? [TrueFormula] : Head extends AnyFormula<infer Nested extends readonly PredicateFormula[]> ? NormalizeAnyItems<[...Nested, ...Tail], Current> : NormalizeAnyItems<Tail, [...Current, Head]> : Current;
|
|
27
|
+
type CollapseNormalizedAll<Items extends readonly PredicateFormula[]> = NormalizeAllItems<Items> extends infer Normalized extends readonly PredicateFormula[] ? [Normalized] extends [readonly [FalseFormula]] ? FalseFormula : [Normalized] extends [readonly []] ? TrueFormula : [Normalized] extends [readonly [infer Only extends PredicateFormula]] ? Only : AllFormula<Normalized> : never;
|
|
28
|
+
type CollapseNormalizedAny<Items extends readonly PredicateFormula[]> = NormalizeAnyItems<Items> extends infer Normalized extends readonly PredicateFormula[] ? [Normalized] extends [readonly [TrueFormula]] ? TrueFormula : [Normalized] extends [readonly []] ? FalseFormula : [Normalized] extends [readonly [infer Only extends PredicateFormula]] ? Only : AnyFormula<Normalized> : never;
|
|
29
|
+
export type NormalizeBooleanConstants<Formula extends PredicateFormula> = [
|
|
30
|
+
Formula
|
|
31
|
+
] extends [AllFormula<infer Items extends readonly PredicateFormula[]>] ? CollapseNormalizedAll<Items> : [Formula] extends [AnyFormula<infer Items extends readonly PredicateFormula[]>] ? CollapseNormalizedAny<Items> : [Formula] extends [NotFormula<infer Item extends PredicateFormula>] ? [Item] extends [TrueFormula] ? FalseFormula : [Item] extends [FalseFormula] ? TrueFormula : Formula : Formula;
|
|
32
|
+
export type And<Left extends PredicateFormula, Right extends PredicateFormula> = NormalizeBooleanConstants<AllFormula<[Left, Right]>>;
|
|
33
|
+
export type Or<Left extends PredicateFormula, Right extends PredicateFormula> = NormalizeBooleanConstants<AnyFormula<[Left, Right]>>;
|
|
34
|
+
export type Not<Value extends PredicateFormula> = NormalizeBooleanConstants<NotFormula<Value>>;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type * as Expression from "../scalar.js";
|
|
2
|
+
import type * as ExpressionAst from "../expression-ast.js";
|
|
3
|
+
export type ColumnKey<TableName extends string, ColumnName extends string> = `${TableName}.${ColumnName}`;
|
|
4
|
+
export type ColumnKeyOfAst<Ast extends ExpressionAst.Any> = Ast extends ExpressionAst.ColumnNode<infer TableName extends string, infer ColumnName extends string> ? ColumnKey<TableName, ColumnName> : never;
|
|
5
|
+
type AstOf<Value extends Expression.Any> = Value extends {
|
|
6
|
+
readonly [ExpressionAst.TypeId]: infer Ast extends ExpressionAst.Any;
|
|
7
|
+
} ? Ast : never;
|
|
8
|
+
export type ColumnKeyOfExpression<Value extends Expression.Any> = ColumnKeyOfAst<AstOf<Value>>;
|
|
9
|
+
export type LiteralKey<Value> = Value extends string ? `string:${Value}` : Value extends number ? `number:${Value}` : Value extends boolean ? `boolean:${Value}` : Value extends null ? "null" : Value extends Date ? `date:${string}` : "unknown";
|
|
10
|
+
export type ValueKey<Value> = LiteralKey<Value>;
|
|
11
|
+
export {};
|
|
@@ -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 {};
|