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.
Files changed (141) hide show
  1. package/dist/mysql.js +61270 -4259
  2. package/dist/postgres/metadata.js +176 -82
  3. package/dist/postgres.js +5903 -3316
  4. package/package.json +14 -1
  5. package/src/internal/aggregation-validation.ts +3 -3
  6. package/src/internal/case-analysis.d.ts +18 -0
  7. package/src/internal/case-analysis.ts +4 -4
  8. package/src/internal/coercion/analysis.d.ts +7 -0
  9. package/src/internal/{coercion-analysis.ts → coercion/analysis.ts} +3 -3
  10. package/src/internal/coercion/errors.d.ts +17 -0
  11. package/src/internal/{coercion-errors.ts → coercion/errors.ts} +1 -1
  12. package/src/internal/coercion/kind.d.ts +4 -0
  13. package/src/internal/{coercion-kind.ts → coercion/kind.ts} +2 -2
  14. package/src/internal/{coercion-normalize.ts → coercion/normalize.ts} +1 -1
  15. package/src/internal/coercion/rules.d.ts +6 -0
  16. package/src/internal/{coercion-rules.ts → coercion/rules.ts} +2 -2
  17. package/src/internal/column-state.d.ts +190 -0
  18. package/src/internal/column-state.ts +36 -47
  19. package/src/internal/column.ts +21 -305
  20. package/src/internal/datatypes/define.d.ts +17 -0
  21. package/src/internal/datatypes/define.ts +18 -4
  22. package/src/internal/datatypes/lookup.d.ts +44 -0
  23. package/src/internal/datatypes/lookup.ts +61 -152
  24. package/src/internal/datatypes/shape.d.ts +16 -0
  25. package/src/internal/datatypes/shape.ts +1 -1
  26. package/src/internal/derived-table.d.ts +4 -0
  27. package/src/internal/derived-table.ts +21 -16
  28. package/src/internal/dsl-mutation-runtime.ts +378 -0
  29. package/src/internal/dsl-plan-runtime.ts +387 -0
  30. package/src/internal/dsl-query-runtime.ts +160 -0
  31. package/src/internal/dsl-transaction-ddl-runtime.ts +263 -0
  32. package/src/internal/executor.ts +132 -31
  33. package/src/internal/expression-ast.ts +15 -5
  34. package/src/internal/grouping-key.d.ts +3 -0
  35. package/src/internal/grouping-key.ts +1 -1
  36. package/src/internal/implication-runtime.d.ts +15 -0
  37. package/src/internal/implication-runtime.ts +4 -4
  38. package/src/internal/json/ast.d.ts +30 -0
  39. package/src/internal/json/ast.ts +1 -1
  40. package/src/internal/json/errors.d.ts +8 -0
  41. package/src/internal/json/path.d.ts +75 -0
  42. package/src/internal/json/path.ts +1 -1
  43. package/src/internal/json/types.d.ts +62 -0
  44. package/src/internal/predicate/analysis.d.ts +20 -0
  45. package/src/internal/{predicate-analysis.ts → predicate/analysis.ts} +3 -3
  46. package/src/internal/predicate/atom.d.ts +28 -0
  47. package/src/internal/{predicate-branches.ts → predicate/branches.ts} +2 -2
  48. package/src/internal/predicate/context.d.ts +67 -0
  49. package/src/internal/{predicate-context.ts → predicate/context.ts} +8 -5
  50. package/src/internal/predicate/formula.d.ts +35 -0
  51. package/src/internal/{predicate-formula.ts → predicate/formula.ts} +1 -1
  52. package/src/internal/predicate/key.d.ts +11 -0
  53. package/src/internal/{predicate-key.ts → predicate/key.ts} +2 -2
  54. package/src/internal/{predicate-nnf.ts → predicate/nnf.ts} +2 -2
  55. package/src/internal/predicate/normalize.d.ts +53 -0
  56. package/src/internal/{predicate-normalize.ts → predicate/normalize.ts} +19 -19
  57. package/src/internal/predicate/runtime.d.ts +31 -0
  58. package/src/internal/{predicate-runtime.ts → predicate/runtime.ts} +9 -6
  59. package/src/internal/projection-alias.d.ts +13 -0
  60. package/src/internal/projections.d.ts +31 -0
  61. package/src/internal/projections.ts +1 -1
  62. package/src/internal/query-ast.d.ts +217 -0
  63. package/src/internal/query-ast.ts +1 -1
  64. package/src/internal/query-requirements.d.ts +20 -0
  65. package/src/internal/query.d.ts +775 -0
  66. package/src/internal/query.ts +389 -313
  67. package/src/internal/renderer.ts +7 -21
  68. package/src/internal/row-set.d.ts +53 -0
  69. package/src/internal/{plan.ts → row-set.ts} +11 -9
  70. package/src/internal/{runtime-normalize.ts → runtime/normalize.ts} +9 -31
  71. package/src/internal/{runtime-schema.ts → runtime/schema.ts} +13 -38
  72. package/src/internal/runtime/value.d.ts +22 -0
  73. package/src/internal/{runtime-value.ts → runtime/value.ts} +2 -2
  74. package/src/internal/scalar.d.ts +107 -0
  75. package/src/internal/scalar.ts +191 -0
  76. package/src/internal/schema-derivation.d.ts +105 -0
  77. package/src/internal/schema-expression.d.ts +18 -0
  78. package/src/internal/schema-expression.ts +38 -7
  79. package/src/internal/table-options.d.ts +94 -0
  80. package/src/internal/table-options.ts +8 -2
  81. package/src/internal/table.d.ts +173 -0
  82. package/src/internal/table.ts +32 -14
  83. package/src/mysql/column.ts +94 -18
  84. package/src/mysql/datatypes/index.ts +47 -7
  85. package/src/mysql/errors/generated.ts +57336 -0
  86. package/src/mysql/errors/index.ts +1 -0
  87. package/src/mysql/errors/normalize.ts +55 -53
  88. package/src/mysql/errors/types.ts +74 -0
  89. package/src/mysql/executor.ts +69 -7
  90. package/src/mysql/function/aggregate.ts +1 -5
  91. package/src/mysql/function/core.ts +1 -4
  92. package/src/mysql/function/index.ts +0 -1
  93. package/src/mysql/function/string.ts +1 -5
  94. package/src/mysql/function/temporal.ts +12 -15
  95. package/src/mysql/function/window.ts +1 -6
  96. package/src/{internal/mysql-dialect.ts → mysql/internal/dialect.ts} +1 -1
  97. package/src/{internal/mysql-query.ts → mysql/internal/dsl.ts} +1024 -2082
  98. package/src/{internal/mysql-renderer.ts → mysql/internal/renderer.ts} +6 -6
  99. package/src/mysql/internal/sql-expression-renderer.ts +1455 -0
  100. package/src/mysql/json.ts +2 -0
  101. package/src/mysql/query.ts +111 -91
  102. package/src/mysql/renderer.ts +1 -1
  103. package/src/mysql/table.ts +1 -1
  104. package/src/mysql.ts +6 -4
  105. package/src/postgres/cast.ts +11 -12
  106. package/src/postgres/column.ts +178 -46
  107. package/src/postgres/datatypes/index.d.ts +515 -0
  108. package/src/postgres/datatypes/index.ts +22 -13
  109. package/src/postgres/datatypes/spec.d.ts +412 -0
  110. package/src/postgres/errors/generated.ts +2636 -0
  111. package/src/postgres/errors/index.ts +1 -0
  112. package/src/postgres/errors/normalize.ts +47 -62
  113. package/src/postgres/errors/types.ts +92 -34
  114. package/src/postgres/executor.ts +37 -5
  115. package/src/postgres/function/aggregate.ts +1 -5
  116. package/src/postgres/function/core.ts +12 -6
  117. package/src/postgres/function/index.ts +0 -1
  118. package/src/postgres/function/string.ts +1 -5
  119. package/src/postgres/function/temporal.ts +12 -15
  120. package/src/postgres/function/window.ts +1 -6
  121. package/src/{internal/postgres-dialect.ts → postgres/internal/dialect.ts} +1 -1
  122. package/src/{internal/postgres-query.ts → postgres/internal/dsl.ts} +1085 -2089
  123. package/src/{internal/postgres-renderer.ts → postgres/internal/renderer.ts} +6 -6
  124. package/src/postgres/internal/schema-ddl.ts +108 -0
  125. package/src/{internal/postgres-schema-model.ts → postgres/internal/schema-model.ts} +12 -6
  126. package/src/{internal → postgres/internal}/sql-expression-renderer.ts +19 -17
  127. package/src/postgres/{function/json.ts → json.ts} +77 -85
  128. package/src/postgres/metadata.ts +2 -2
  129. package/src/postgres/query.ts +113 -89
  130. package/src/postgres/renderer.ts +3 -13
  131. package/src/postgres/schema-expression.ts +2 -1
  132. package/src/postgres/schema-management.ts +1 -1
  133. package/src/postgres/table.ts +12 -4
  134. package/src/postgres/type.ts +29 -2
  135. package/src/postgres.ts +6 -4
  136. package/src/internal/expression.ts +0 -327
  137. package/src/internal/schema-ddl.ts +0 -55
  138. package/src/mysql/function/json.ts +0 -4
  139. package/src/mysql/private/query.ts +0 -1
  140. package/src/postgres/private/query.ts +0 -1
  141. /package/src/internal/{predicate-atom.ts → predicate/atom.ts} +0 -0
package/package.json CHANGED
@@ -1,7 +1,20 @@
1
1
  {
2
2
  "name": "effect-qb",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "type": "module",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/relsunkaev/effect-qb.git"
9
+ },
10
+ "bugs": {
11
+ "url": "https://github.com/relsunkaev/effect-qb/issues"
12
+ },
13
+ "homepage": "https://github.com/relsunkaev/effect-qb#readme",
14
+ "engines": {
15
+ "node": ">=22",
16
+ "bun": ">=1.3.5"
17
+ },
5
18
  "files": [
6
19
  "dist",
7
20
  "src",
@@ -1,4 +1,4 @@
1
- import * as Expression from "./expression.js"
1
+ import * as Expression from "./scalar.js"
2
2
  import { groupingKeyOfExpression } from "./grouping-key.js"
3
3
 
4
4
  /** Recursive selection value accepted by aggregate-shape validation. */
@@ -13,7 +13,7 @@ const isExpression = (value: unknown): value is Expression.Any =>
13
13
 
14
14
  const selectionHasAggregate = (selection: SelectionValue): boolean => {
15
15
  if (isExpression(selection)) {
16
- return selection[Expression.TypeId].aggregation === "aggregate"
16
+ return selection[Expression.TypeId].kind === "aggregate"
17
17
  }
18
18
  return Object.values(selection).some((value) => selectionHasAggregate(value))
19
19
  }
@@ -23,7 +23,7 @@ const isGroupedSelectionValid = (
23
23
  groupedExpressions: ReadonlySet<string>
24
24
  ): boolean => {
25
25
  if (isExpression(selection)) {
26
- const aggregation = selection[Expression.TypeId].aggregation
26
+ const aggregation = selection[Expression.TypeId].kind
27
27
  if (aggregation === "aggregate") {
28
28
  return true
29
29
  }
@@ -0,0 +1,18 @@
1
+ import type * as Expression from "./scalar.js";
2
+ import type * as ExpressionAst from "./expression-ast.js";
3
+ import type { PredicateFormula } from "./predicate/formula.js";
4
+ import type { AssumeFormulaFalse, AssumeFormulaTrue, Contradicts, Implies } from "./predicate/analysis.js";
5
+ import type { FormulaOfExpression } from "./predicate/normalize.js";
6
+ export interface CasePath<Assumptions extends PredicateFormula, Value extends Expression.Any> {
7
+ readonly assumptions: Assumptions;
8
+ readonly value: Value;
9
+ }
10
+ type PredicateFormulaOf<Predicate extends Expression.Any> = FormulaOfExpression<Predicate>;
11
+ export type CaseBranchAssumeTrue<Assumptions extends PredicateFormula, Predicate extends Expression.Any> = AssumeFormulaTrue<Assumptions, PredicateFormulaOf<Predicate>>;
12
+ export type CaseBranchAssumeFalse<Assumptions extends PredicateFormula, Predicate extends Expression.Any> = AssumeFormulaFalse<Assumptions, PredicateFormulaOf<Predicate>>;
13
+ export type CaseBranchDecision<Assumptions extends PredicateFormula, Predicate extends Expression.Any> = Contradicts<Assumptions, Predicate> extends true ? "skip" : Implies<Assumptions, Predicate> extends true ? "take" : "branch";
14
+ export type ReachableCasePaths<Assumptions extends PredicateFormula, Branches extends readonly ExpressionAst.CaseBranchNode[], Else extends Expression.Any> = Branches extends readonly [
15
+ infer Head extends ExpressionAst.CaseBranchNode,
16
+ ...infer Tail extends readonly ExpressionAst.CaseBranchNode[]
17
+ ] ? CaseBranchDecision<Assumptions, Head["when"]> extends "skip" ? ReachableCasePaths<Assumptions, Tail, Else> : CaseBranchDecision<Assumptions, Head["when"]> extends "take" ? CasePath<CaseBranchAssumeTrue<Assumptions, Head["when"]>, Head["then"]> : CasePath<CaseBranchAssumeTrue<Assumptions, Head["when"]>, Head["then"]> | ReachableCasePaths<CaseBranchAssumeFalse<Assumptions, Head["when"]>, Tail, Else> : CasePath<Assumptions, Else>;
18
+ export {};
@@ -1,8 +1,8 @@
1
- import type * as Expression from "./expression.js"
1
+ import type * as Expression from "./scalar.js"
2
2
  import type * as ExpressionAst from "./expression-ast.js"
3
- import type { PredicateFormula } from "./predicate-formula.js"
4
- import type { AssumeFormulaFalse, AssumeFormulaTrue, Contradicts, Implies } from "./predicate-analysis.js"
5
- import type { FormulaOfExpression } from "./predicate-normalize.js"
3
+ import type { PredicateFormula } from "./predicate/formula.js"
4
+ import type { AssumeFormulaFalse, AssumeFormulaTrue, Contradicts, Implies } from "./predicate/analysis.js"
5
+ import type { FormulaOfExpression } from "./predicate/normalize.js"
6
6
 
7
7
  export interface CasePath<
8
8
  Assumptions extends PredicateFormula,
@@ -0,0 +1,7 @@
1
+ import type * as Expression from "../scalar.js";
2
+ import type { CastTargetError, OperandCompatibilityError } from "./errors.js";
3
+ import type { CanCastDbType, CanCompareDbTypes, CanTextuallyCoerceDbType } from "./rules.js";
4
+ export type ComparableDbType<Left extends Expression.DbType.Any, Right extends Expression.DbType.Any, Dialect extends string, Operator extends string = "comparison"> = CanCompareDbTypes<Left, Right, Dialect> extends true ? Right : OperandCompatibilityError<Operator, Left, Right, Dialect, "the same db type family">;
5
+ export type TextCompatibleDbType<Db extends Expression.DbType.Any, Dialect extends string, Operator extends string = "text operator"> = CanTextuallyCoerceDbType<Db, Dialect> extends true ? Db : OperandCompatibilityError<Operator, Db, Db, Dialect, "a text-compatible db type">;
6
+ export type CastableDbType<Source extends Expression.DbType.Any, Target extends Expression.DbType.Any, Dialect extends string> = CanCastDbType<Source, Target, Dialect> extends true ? Target : CastTargetError<Source, Target, Dialect>;
7
+ export type RuntimeOfDbType<Db extends Expression.DbType.Any> = Expression.RuntimeOfDbType<Db>;
@@ -1,6 +1,6 @@
1
- import type * as Expression from "./expression.js"
2
- import type { CastTargetError, OperandCompatibilityError } from "./coercion-errors.js"
3
- import type { CanCastDbType, CanCompareDbTypes, CanTextuallyCoerceDbType } from "./coercion-rules.js"
1
+ import type * as Expression from "../scalar.js"
2
+ import type { CastTargetError, OperandCompatibilityError } from "./errors.js"
3
+ import type { CanCastDbType, CanCompareDbTypes, CanTextuallyCoerceDbType } from "./rules.js"
4
4
 
5
5
  export type ComparableDbType<
6
6
  Left extends Expression.DbType.Any,
@@ -0,0 +1,17 @@
1
+ import type * as Expression from "../scalar.js";
2
+ export type OperandCompatibilityError<Operator extends string, Left extends Expression.DbType.Any, Right extends Expression.DbType.Any, Dialect extends string, Expected extends string> = {
3
+ readonly __effect_qb_error__: "effect-qb: incompatible operand types";
4
+ readonly __effect_qb_operator__: Operator;
5
+ readonly __effect_qb_left_db_type__: Left;
6
+ readonly __effect_qb_right_db_type__: Right;
7
+ readonly __effect_qb_dialect__: Dialect;
8
+ readonly __effect_qb_expected__: Expected;
9
+ readonly __effect_qb_hint__: "Use cast(...) or pick values from the same db type family";
10
+ };
11
+ export type CastTargetError<Source extends Expression.DbType.Any, Target extends Expression.DbType.Any, Dialect extends string> = {
12
+ readonly __effect_qb_error__: "effect-qb: unsupported cast target";
13
+ readonly __effect_qb_source_db_type__: Source;
14
+ readonly __effect_qb_target_db_type__: Target;
15
+ readonly __effect_qb_dialect__: Dialect;
16
+ readonly __effect_qb_hint__: "Use one of the supported Q.type.<kind>() witnesses";
17
+ };
@@ -1,4 +1,4 @@
1
- import type * as Expression from "./expression.js"
1
+ import type * as Expression from "../scalar.js"
2
2
 
3
3
  export type OperandCompatibilityError<
4
4
  Operator extends string,
@@ -0,0 +1,4 @@
1
+ import type * as Expression from "../scalar.js";
2
+ import type { FamilyOfDbType } from "../datatypes/lookup.js";
3
+ export type CoercionKind = "text" | "numeric" | "boolean" | "date" | "time" | "timestamp" | "binary" | "interval" | "uuid" | "json" | "xml" | "bit" | "identifier" | "network" | "spatial" | "textsearch" | "range" | "multirange" | "array" | "record" | "domain" | "enum" | "set" | "money" | "null" | `other:${string}`;
4
+ export type CoercionKindOf<Db extends Expression.DbType.Any> = FamilyOfDbType<Db>;
@@ -1,5 +1,5 @@
1
- import type * as Expression from "./expression.js"
2
- import type { FamilyOfDbType } from "./datatypes/lookup.js"
1
+ import type * as Expression from "../scalar.js"
2
+ import type { FamilyOfDbType } from "../datatypes/lookup.js"
3
3
 
4
4
  export type CoercionKind =
5
5
  | "text"
@@ -1,4 +1,4 @@
1
- import type * as Expression from "./expression.js"
1
+ import type * as Expression from "../scalar.js"
2
2
 
3
3
  /** Extracts the database type carried by an expression. */
4
4
  export type DbTypeOfExpression<Value extends Expression.Any> = Expression.DbTypeOf<Value>
@@ -0,0 +1,6 @@
1
+ import type * as Expression from "../scalar.js";
2
+ import type { CanCastDbType as LookupCanCastDbType, CanCompareDbTypes as LookupCanCompareDbTypes, CanContainDbTypes as LookupCanContainDbTypes, CanTextuallyCoerceDbType as LookupCanTextuallyCoerceDbType } from "../datatypes/lookup.js";
3
+ export type CanCompareDbTypes<Left extends Expression.DbType.Any, Right extends Expression.DbType.Any, Dialect extends string> = LookupCanCompareDbTypes<Left, Right, Dialect>;
4
+ export type CanContainDbTypes<Left extends Expression.DbType.Any, Right extends Expression.DbType.Any, Dialect extends string> = LookupCanContainDbTypes<Left, Right, Dialect>;
5
+ export type CanTextuallyCoerceDbType<Db extends Expression.DbType.Any, Dialect extends string> = LookupCanTextuallyCoerceDbType<Db, Dialect>;
6
+ export type CanCastDbType<Source extends Expression.DbType.Any, Target extends Expression.DbType.Any, Dialect extends string> = LookupCanCastDbType<Source, Target, Dialect>;
@@ -1,5 +1,5 @@
1
- import type * as Expression from "./expression.js"
2
- import type { CanCastDbType as LookupCanCastDbType, CanCompareDbTypes as LookupCanCompareDbTypes, CanContainDbTypes as LookupCanContainDbTypes, CanTextuallyCoerceDbType as LookupCanTextuallyCoerceDbType } from "./datatypes/lookup.js"
1
+ import type * as Expression from "../scalar.js"
2
+ import type { CanCastDbType as LookupCanCastDbType, CanCompareDbTypes as LookupCanCompareDbTypes, CanContainDbTypes as LookupCanContainDbTypes, CanTextuallyCoerceDbType as LookupCanTextuallyCoerceDbType } from "../datatypes/lookup.js"
3
3
 
4
4
  export type CanCompareDbTypes<
5
5
  Left extends Expression.DbType.Any,
@@ -0,0 +1,190 @@
1
+ import type * as Brand from "effect/Brand";
2
+ import { type Pipeable } from "effect/Pipeable";
3
+ import * as Schema from "effect/Schema";
4
+ import * as Expression from "./scalar.js";
5
+ import * as ExpressionAst from "./expression-ast.js";
6
+ import type * as SchemaExpression from "./schema-expression.js";
7
+ /** Symbol used to attach column-definition metadata. */
8
+ export declare const ColumnTypeId: unique symbol;
9
+ /** Symbol used to attach bound-column provenance. */
10
+ export declare const BoundColumnTypeId: unique symbol;
11
+ export type ColumnTypeId = typeof ColumnTypeId;
12
+ export type BoundColumnTypeId = typeof BoundColumnTypeId;
13
+ export type DdlExpression = Expression.Any | SchemaExpression.Any;
14
+ /** Lazy reference to another bound column. */
15
+ export interface ColumnReference<Target = unknown> {
16
+ readonly target: () => Target;
17
+ readonly name?: string;
18
+ readonly onUpdate?: "noAction" | "restrict" | "cascade" | "setNull" | "setDefault";
19
+ readonly onDelete?: "noAction" | "restrict" | "cascade" | "setNull" | "setDefault";
20
+ readonly deferrable?: boolean;
21
+ readonly initiallyDeferred?: boolean;
22
+ }
23
+ /** Inline single-column index metadata. */
24
+ export interface ColumnIndexOptions {
25
+ readonly name?: string;
26
+ readonly method?: string;
27
+ readonly include?: readonly string[];
28
+ readonly predicate?: DdlExpression;
29
+ readonly order?: "asc" | "desc";
30
+ readonly nulls?: "first" | "last";
31
+ readonly operatorClass?: string;
32
+ readonly collation?: string;
33
+ }
34
+ /** Inline single-column unique-constraint metadata. */
35
+ export interface ColumnUniqueOptions {
36
+ readonly name?: string;
37
+ readonly nullsNotDistinct?: boolean;
38
+ readonly deferrable?: boolean;
39
+ readonly initiallyDeferred?: boolean;
40
+ }
41
+ /** Complete static state tracked for a column definition. */
42
+ export interface ColumnState<Select, Insert, Update, Db extends Expression.DbType.Any, Nullable extends boolean, HasDefault extends boolean, Generated extends boolean, PrimaryKey extends boolean, Unique extends boolean, Ref, Dependencies extends Expression.BindingId = never> {
43
+ readonly select: Select;
44
+ readonly insert: Insert;
45
+ readonly update: Update;
46
+ readonly dbType: Db;
47
+ readonly nullable: Nullable;
48
+ readonly hasDefault: HasDefault;
49
+ readonly generated: Generated;
50
+ readonly primaryKey: PrimaryKey;
51
+ readonly unique: Unique;
52
+ readonly references: Ref;
53
+ readonly brand?: true;
54
+ readonly index?: ColumnIndexOptions;
55
+ readonly uniqueConstraint?: ColumnUniqueOptions;
56
+ readonly defaultValue?: DdlExpression;
57
+ readonly generatedValue?: DdlExpression;
58
+ readonly ddlType?: string;
59
+ readonly identity?: {
60
+ readonly generation: "always" | "byDefault";
61
+ };
62
+ readonly enum?: {
63
+ readonly name: string;
64
+ readonly schemaName?: string;
65
+ readonly values: readonly [string, ...string[]];
66
+ };
67
+ readonly dependencies?: Dependencies;
68
+ }
69
+ /** Unbound column definition produced by the `Column` DSL. */
70
+ export interface ColumnDefinition<Select, Insert, Update, Db extends Expression.DbType.Any, Nullable extends boolean, HasDefault extends boolean, Generated extends boolean, PrimaryKey extends boolean, Unique extends boolean, Ref, Dependencies extends Expression.BindingId = never> extends Pipeable, Expression.Scalar<Select, Db, Nullable extends true ? "maybe" : "never", Db["dialect"], "scalar", Dependencies> {
71
+ readonly pipe: Pipeable["pipe"];
72
+ readonly [ColumnTypeId]: ColumnState<Select, Insert, Update, Db, Nullable, HasDefault, Generated, PrimaryKey, Unique, Ref, Dependencies>;
73
+ readonly schema: Schema.Schema<NonNullable<Select>, any, any>;
74
+ readonly metadata: {
75
+ readonly dbType: Db;
76
+ readonly nullable: Nullable;
77
+ readonly hasDefault: HasDefault;
78
+ readonly generated: Generated;
79
+ readonly primaryKey: PrimaryKey;
80
+ readonly unique: Unique;
81
+ readonly references: Ref;
82
+ readonly brand?: true;
83
+ readonly index?: ColumnIndexOptions;
84
+ readonly uniqueConstraint?: ColumnUniqueOptions;
85
+ readonly defaultValue?: DdlExpression;
86
+ readonly generatedValue?: DdlExpression;
87
+ readonly ddlType?: string;
88
+ readonly identity?: {
89
+ readonly generation: "always" | "byDefault";
90
+ };
91
+ readonly enum?: {
92
+ readonly name: string;
93
+ readonly schemaName?: string;
94
+ readonly values: readonly [string, ...string[]];
95
+ };
96
+ };
97
+ }
98
+ /** Column definition bound to a concrete table and column name. */
99
+ export interface BoundColumn<Select, Insert, Update, Db extends Expression.DbType.Any, Nullable extends boolean, HasDefault extends boolean, Generated extends boolean, PrimaryKey extends boolean, Unique extends boolean, Ref, TableName extends string, ColumnName extends string, BaseTableName extends string = TableName> extends ColumnDefinition<Select, Insert, Update, Db, Nullable, HasDefault, Generated, PrimaryKey, Unique, Ref, TableName> {
100
+ readonly [BoundColumnTypeId]: {
101
+ readonly tableName: TableName;
102
+ readonly columnName: ColumnName;
103
+ readonly baseTableName: BaseTableName;
104
+ readonly schemaName?: string;
105
+ };
106
+ readonly [Expression.TypeId]: Expression.State<Select, Db, Nullable extends true ? "maybe" : "never", Db["dialect"], "scalar", TableName>;
107
+ readonly [ExpressionAst.TypeId]: ExpressionAst.ColumnNode<TableName, ColumnName>;
108
+ }
109
+ /** Convenience alias for any column definition. */
110
+ export type AnyColumnDefinition = ColumnDefinition<any, any, any, Expression.DbType.Any, boolean, boolean, boolean, boolean, boolean, any, any>;
111
+ /** Convenience alias for any bound column. */
112
+ export type AnyBoundColumn = BoundColumn<any, any, any, Expression.DbType.Any, boolean, boolean, boolean, boolean, boolean, any, string, string, string>;
113
+ /** Constructs a runtime column-definition object from schema and metadata. */
114
+ export declare const makeColumnDefinition: <Select, Insert, Update, Db extends Expression.DbType.Any, Nullable extends boolean, HasDefault extends boolean, Generated extends boolean, PrimaryKey extends boolean, Unique extends boolean, Ref, Dependencies extends string = never>(schema: Schema.Schema<NonNullable<Select>, any, any>, metadata: {
115
+ readonly dbType: Db;
116
+ readonly nullable: Nullable;
117
+ readonly hasDefault: HasDefault;
118
+ readonly generated: Generated;
119
+ readonly primaryKey: PrimaryKey;
120
+ readonly unique: Unique;
121
+ readonly references: Ref;
122
+ readonly brand?: true | undefined;
123
+ readonly index?: ColumnIndexOptions | undefined;
124
+ readonly uniqueConstraint?: ColumnUniqueOptions | undefined;
125
+ readonly defaultValue?: DdlExpression | undefined;
126
+ readonly generatedValue?: DdlExpression | undefined;
127
+ readonly ddlType?: string | undefined;
128
+ readonly identity?: {
129
+ readonly generation: "always" | "byDefault";
130
+ } | undefined;
131
+ readonly enum?: {
132
+ readonly name: string;
133
+ readonly schemaName?: string | undefined;
134
+ readonly values: readonly [string, ...string[]];
135
+ } | undefined;
136
+ }) => ColumnDefinition<Select, Insert, Update, Db, Nullable, HasDefault, Generated, PrimaryKey, Unique, Ref, Dependencies>;
137
+ export declare const remapColumnDefinition: <Select, Insert, Update, Db extends Expression.DbType.Any, Nullable extends boolean, HasDefault extends boolean, Generated extends boolean, PrimaryKey extends boolean, Unique extends boolean, Ref, Dependencies extends string = never>(column: ColumnDefinition<Select, Insert, Update, Db, Nullable, HasDefault, Generated, PrimaryKey, Unique, Ref, Dependencies>, options?: {
138
+ readonly schema?: Schema.Schema.Any | undefined;
139
+ readonly metadata?: {
140
+ readonly dbType: Db;
141
+ readonly nullable: Nullable;
142
+ readonly hasDefault: HasDefault;
143
+ readonly generated: Generated;
144
+ readonly primaryKey: PrimaryKey;
145
+ readonly unique: Unique;
146
+ readonly references: Ref;
147
+ readonly brand?: true | undefined;
148
+ readonly index?: ColumnIndexOptions | undefined;
149
+ readonly uniqueConstraint?: ColumnUniqueOptions | undefined;
150
+ readonly defaultValue?: DdlExpression | undefined;
151
+ readonly generatedValue?: DdlExpression | undefined;
152
+ readonly ddlType?: string | undefined;
153
+ readonly identity?: {
154
+ readonly generation: "always" | "byDefault";
155
+ } | undefined;
156
+ readonly enum?: {
157
+ readonly name: string;
158
+ readonly schemaName?: string | undefined;
159
+ readonly values: readonly [string, ...string[]];
160
+ } | undefined;
161
+ } | undefined;
162
+ }) => ColumnDefinition<Select, Insert, Update, Db, Nullable, HasDefault, Generated, PrimaryKey, Unique, Ref, Dependencies>;
163
+ /** Attaches table/column provenance to an existing column definition. */
164
+ export declare const bindColumn: <TableName extends string, ColumnName extends string, BaseTableName extends string, SchemaName extends string | undefined, Column extends AnyColumnDefinition>(tableName: TableName, columnName: ColumnName, column: Column, baseTableName: BaseTableName, schemaName?: SchemaName | undefined) => BoundColumnFrom<Column, TableName, ColumnName, BaseTableName>;
165
+ /** Extracts the internal state record for a column. */
166
+ export type ColumnStateOf<Column extends AnyColumnDefinition> = Column[typeof ColumnTypeId];
167
+ /** Extracts the read/select type of a column. */
168
+ export type SelectType<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["select"];
169
+ /** Extracts the insert type of a column. */
170
+ export type InsertType<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["insert"];
171
+ /** Extracts the update type of a column. */
172
+ export type UpdateType<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["update"];
173
+ /** Extracts whether a column is nullable. */
174
+ export type IsNullable<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["nullable"];
175
+ /** Extracts whether a column has a server-side default. */
176
+ export type HasDefault<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["hasDefault"];
177
+ /** Extracts whether a column is generated by the database. */
178
+ export type IsGenerated<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["generated"];
179
+ /** Extracts whether a column is part of a primary key. */
180
+ export type IsPrimaryKey<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["primaryKey"];
181
+ /** Extracts whether a column is unique. */
182
+ export type IsUnique<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["unique"];
183
+ /** Extracts a column's foreign-key reference metadata. */
184
+ export type ReferencesOf<Column extends AnyColumnDefinition> = ColumnStateOf<Column>["references"];
185
+ /** Extracts the non-null select type of a column. */
186
+ export type BaseSelectType<Column extends AnyColumnDefinition> = NonNullable<SelectType<Column>>;
187
+ type BrandedValue<Value, BrandName extends string> = [Extract<Value, null | undefined>] extends [never] ? Value & Brand.Brand<BrandName> : (Exclude<Value, null | undefined> & Brand.Brand<BrandName>) | Extract<Value, null | undefined>;
188
+ /** Rebinds a generic column definition to a specific table and key. */
189
+ export type BoundColumnFrom<Column extends AnyColumnDefinition, TableName extends string, ColumnName extends string, BaseTableName extends string = TableName> = BoundColumn<Column["metadata"]["brand"] extends true ? BrandedValue<SelectType<Column>, `${TableName}.${ColumnName}`> : SelectType<Column>, Column["metadata"]["brand"] extends true ? BrandedValue<InsertType<Column>, `${TableName}.${ColumnName}`> : InsertType<Column>, Column["metadata"]["brand"] extends true ? BrandedValue<UpdateType<Column>, `${TableName}.${ColumnName}`> : UpdateType<Column>, ColumnStateOf<Column>["dbType"], IsNullable<Column>, HasDefault<Column>, IsGenerated<Column>, IsPrimaryKey<Column>, IsUnique<Column>, ReferencesOf<Column>, TableName, ColumnName, BaseTableName>;
190
+ export {};
@@ -2,7 +2,7 @@ import type * as Brand from "effect/Brand"
2
2
  import { pipeArguments, type Pipeable } from "effect/Pipeable"
3
3
  import * as Schema from "effect/Schema"
4
4
 
5
- import * as Expression from "./expression.js"
5
+ import * as Expression from "./scalar.js"
6
6
  import * as ExpressionAst from "./expression-ast.js"
7
7
  import type * as SchemaExpression from "./schema-expression.js"
8
8
 
@@ -34,6 +34,8 @@ export interface ColumnIndexOptions {
34
34
  readonly predicate?: DdlExpression
35
35
  readonly order?: "asc" | "desc"
36
36
  readonly nulls?: "first" | "last"
37
+ readonly operatorClass?: string
38
+ readonly collation?: string
37
39
  }
38
40
 
39
41
  /** Inline single-column unique-constraint metadata. */
@@ -56,8 +58,7 @@ export interface ColumnState<
56
58
  PrimaryKey extends boolean,
57
59
  Unique extends boolean,
58
60
  Ref,
59
- Source = never,
60
- Dependencies extends Expression.SourceDependencies = {}
61
+ Dependencies extends Expression.BindingId = never
61
62
  > {
62
63
  readonly select: Select
63
64
  readonly insert: Insert
@@ -83,8 +84,7 @@ export interface ColumnState<
83
84
  readonly schemaName?: string
84
85
  readonly values: readonly [string, ...string[]]
85
86
  }
86
- readonly source: Source
87
- readonly dependencies: Dependencies
87
+ readonly dependencies?: Dependencies
88
88
  }
89
89
 
90
90
  /** Unbound column definition produced by the `Column` DSL. */
@@ -99,15 +99,13 @@ export interface ColumnDefinition<
99
99
  PrimaryKey extends boolean,
100
100
  Unique extends boolean,
101
101
  Ref,
102
- Source = never,
103
- Dependencies extends Expression.SourceDependencies = {}
104
- > extends Pipeable, Expression.Expression<
102
+ Dependencies extends Expression.BindingId = never
103
+ > extends Pipeable, Expression.Scalar<
105
104
  Select,
106
105
  Db,
107
106
  Nullable extends true ? "maybe" : "never",
108
107
  Db["dialect"],
109
108
  "scalar",
110
- Source,
111
109
  Dependencies
112
110
  > {
113
111
  readonly pipe: Pipeable["pipe"]
@@ -122,7 +120,6 @@ export interface ColumnDefinition<
122
120
  PrimaryKey,
123
121
  Unique,
124
122
  Ref,
125
- Source,
126
123
  Dependencies
127
124
  >
128
125
  readonly schema: Schema.Schema<NonNullable<Select>, any, any>
@@ -161,11 +158,11 @@ export interface BoundColumn<
161
158
  HasDefault extends boolean,
162
159
  Generated extends boolean,
163
160
  PrimaryKey extends boolean,
164
- Unique extends boolean,
165
- Ref,
166
- TableName extends string,
167
- ColumnName extends string,
168
- BaseTableName extends string = TableName
161
+ Unique extends boolean,
162
+ Ref,
163
+ TableName extends string,
164
+ ColumnName extends string,
165
+ BaseTableName extends string = TableName
169
166
  > extends ColumnDefinition<
170
167
  Select,
171
168
  Insert,
@@ -177,8 +174,7 @@ export interface BoundColumn<
177
174
  PrimaryKey,
178
175
  Unique,
179
176
  Ref,
180
- Expression.ColumnSource<TableName, ColumnName, BaseTableName>,
181
- Record<TableName, true>
177
+ TableName
182
178
  > {
183
179
  readonly [BoundColumnTypeId]: {
184
180
  readonly tableName: TableName
@@ -192,9 +188,7 @@ export interface BoundColumn<
192
188
  Nullable extends true ? "maybe" : "never",
193
189
  Db["dialect"],
194
190
  "scalar",
195
- Expression.ColumnSource<TableName, ColumnName, BaseTableName>,
196
- Record<TableName, true>,
197
- "propagate"
191
+ TableName
198
192
  >
199
193
  readonly [ExpressionAst.TypeId]: ExpressionAst.ColumnNode<TableName, ColumnName>
200
194
  }
@@ -226,6 +220,7 @@ export type AnyBoundColumn = BoundColumn<
226
220
  boolean,
227
221
  any,
228
222
  string,
223
+ string,
229
224
  string
230
225
  >
231
226
 
@@ -235,6 +230,17 @@ const ColumnProto = {
235
230
  }
236
231
  }
237
232
 
233
+ const attachPipe = <Value extends object>(value: Value): Value => {
234
+ Object.defineProperty(value, "pipe", {
235
+ configurable: true,
236
+ writable: true,
237
+ value: function(this: unknown) {
238
+ return pipeArguments(value, arguments)
239
+ }
240
+ })
241
+ return value
242
+ }
243
+
238
244
  /** Constructs a runtime column-definition object from schema and metadata. */
239
245
  export const makeColumnDefinition = <
240
246
  Select,
@@ -247,8 +253,7 @@ export const makeColumnDefinition = <
247
253
  PrimaryKey extends boolean,
248
254
  Unique extends boolean,
249
255
  Ref,
250
- Source = never,
251
- Dependencies extends Expression.SourceDependencies = {}
256
+ Dependencies extends Expression.BindingId = never
252
257
  >(
253
258
  schema: Schema.Schema<NonNullable<Select>, any, any>,
254
259
  metadata: ColumnDefinition<
@@ -262,7 +267,6 @@ export const makeColumnDefinition = <
262
267
  PrimaryKey,
263
268
  Unique,
264
269
  Ref,
265
- Source,
266
270
  Dependencies
267
271
  >["metadata"]
268
272
  ): ColumnDefinition<
@@ -276,10 +280,9 @@ export const makeColumnDefinition = <
276
280
  PrimaryKey,
277
281
  Unique,
278
282
  Ref,
279
- Source,
280
283
  Dependencies
281
284
  > => {
282
- const column = Object.create(ColumnProto)
285
+ const column = attachPipe(Object.create(ColumnProto))
283
286
  column.schema = schema
284
287
  column.metadata = metadata
285
288
  column[Expression.TypeId] = {
@@ -288,10 +291,8 @@ export const makeColumnDefinition = <
288
291
  runtimeSchema: schema,
289
292
  nullability: (metadata.nullable ? "maybe" : "never") as Nullable extends true ? "maybe" : "never",
290
293
  dialect: metadata.dbType.dialect,
291
- aggregation: "scalar",
292
- source: undefined as Source,
293
- sourceNullability: "propagate" as const,
294
- dependencies: {} as Dependencies
294
+ kind: "scalar",
295
+ dependencies: {}
295
296
  }
296
297
  column[ColumnTypeId] = {
297
298
  select: undefined as Select,
@@ -308,9 +309,7 @@ export const makeColumnDefinition = <
308
309
  generatedValue: metadata.generatedValue,
309
310
  ddlType: metadata.ddlType,
310
311
  identity: metadata.identity,
311
- enum: metadata.enum,
312
- source: undefined as Source,
313
- dependencies: {} as Dependencies
312
+ enum: metadata.enum
314
313
  }
315
314
  return column
316
315
  }
@@ -326,8 +325,7 @@ export const remapColumnDefinition = <
326
325
  PrimaryKey extends boolean,
327
326
  Unique extends boolean,
328
327
  Ref,
329
- Source = never,
330
- Dependencies extends Expression.SourceDependencies = {}
328
+ Dependencies extends Expression.BindingId = never
331
329
  >(
332
330
  column: ColumnDefinition<
333
331
  Select,
@@ -340,7 +338,6 @@ export const remapColumnDefinition = <
340
338
  PrimaryKey,
341
339
  Unique,
342
340
  Ref,
343
- Source,
344
341
  Dependencies
345
342
  >,
346
343
  options: {
@@ -356,7 +353,6 @@ export const remapColumnDefinition = <
356
353
  PrimaryKey,
357
354
  Unique,
358
355
  Ref,
359
- Source,
360
356
  Dependencies
361
357
  >["metadata"]
362
358
  } = {}
@@ -371,12 +367,11 @@ export const remapColumnDefinition = <
371
367
  PrimaryKey,
372
368
  Unique,
373
369
  Ref,
374
- Source,
375
370
  Dependencies
376
371
  > => {
377
372
  const schema = options.schema ?? column.schema
378
373
  const metadata = options.metadata ?? column.metadata
379
- const next = Object.create(ColumnProto)
374
+ const next = attachPipe(Object.create(ColumnProto))
380
375
  next.schema = schema
381
376
  next.metadata = metadata
382
377
  next[Expression.TypeId] = {
@@ -441,7 +436,7 @@ export const bindColumn = <
441
436
  const schema = column.metadata.brand === true
442
437
  ? Schema.brand(brandName)(column.schema)
443
438
  : column.schema
444
- const bound = Object.create(ColumnProto)
439
+ const bound = attachPipe(Object.create(ColumnProto))
445
440
  bound.schema = schema
446
441
  bound.metadata = column.metadata
447
442
  bound[Expression.TypeId] = {
@@ -450,16 +445,10 @@ export const bindColumn = <
450
445
  runtimeSchema: schema,
451
446
  nullability: (column.metadata.nullable ? "maybe" : "never") as IsNullable<Column> extends true ? "maybe" : "never",
452
447
  dialect: column.metadata.dbType.dialect,
453
- aggregation: "scalar",
454
- source: {
455
- tableName,
456
- columnName,
457
- baseTableName
458
- },
459
- sourceNullability: "propagate" as const,
448
+ kind: "scalar",
460
449
  dependencies: {
461
450
  [tableName]: true
462
- } as Record<TableName, true>
451
+ }
463
452
  }
464
453
  bound[ExpressionAst.TypeId] = {
465
454
  kind: "column",