uql-orm 0.65.1 → 0.67.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 (193) hide show
  1. package/dist/browser/querier/httpQuerier.js +1 -8
  2. package/dist/browser/uql-browser.min.js.map +5 -5
  3. package/dist/bunSql/bunSql.util.d.ts +2 -6
  4. package/dist/bunSql/bunSql.util.js +2 -6
  5. package/dist/bunSql/bunSqlQuerier.d.ts +2 -5
  6. package/dist/bunSql/bunSqlQuerier.js +2 -5
  7. package/dist/cockroachdb/cockroachDialect.d.ts +4 -13
  8. package/dist/cockroachdb/cockroachDialect.js +4 -13
  9. package/dist/context/context.browser.js +2 -10
  10. package/dist/context/context.d.ts +4 -17
  11. package/dist/context/context.js +4 -17
  12. package/dist/dialect/abstractDialect.d.ts +4 -19
  13. package/dist/dialect/abstractDialect.js +2 -20
  14. package/dist/dialect/abstractSqlDialect.d.ts +47 -212
  15. package/dist/dialect/abstractSqlDialect.js +68 -222
  16. package/dist/dialect/aliases.d.ts +2 -12
  17. package/dist/dialect/aliases.js +4 -12
  18. package/dist/dialect/hydrateColumn.d.ts +2 -6
  19. package/dist/dialect/hydrateColumn.js +3 -13
  20. package/dist/dialect/jsonArrayElemMatchUtils.d.ts +1 -7
  21. package/dist/dialect/jsonArrayElemMatchUtils.js +1 -7
  22. package/dist/dialect/jsonSql.d.ts +6 -27
  23. package/dist/dialect/jsonSql.js +6 -27
  24. package/dist/dialect/mergeSqlDialect.d.ts +4 -22
  25. package/dist/dialect/mergeSqlDialect.js +4 -22
  26. package/dist/dialect/mysqlLikeSqlDialect.d.ts +11 -37
  27. package/dist/dialect/mysqlLikeSqlDialect.js +35 -51
  28. package/dist/dialect/pgLikeSqlDialect.d.ts +8 -22
  29. package/dist/dialect/pgLikeSqlDialect.js +36 -39
  30. package/dist/dialect/queryContext.d.ts +4 -22
  31. package/dist/dialect/queryContext.js +4 -22
  32. package/dist/dialect/queryJoins.d.ts +3 -12
  33. package/dist/dialect/queryJoins.js +3 -12
  34. package/dist/dialect/vectorCast.d.ts +2 -12
  35. package/dist/dialect/vectorCast.js +3 -19
  36. package/dist/dialect/vectorSqlDialect.d.ts +8 -38
  37. package/dist/dialect/vectorSqlDialect.js +7 -38
  38. package/dist/entity/decorator/bag.d.ts +6 -19
  39. package/dist/entity/decorator/bag.js +6 -22
  40. package/dist/entity/decorator/entity.d.ts +5 -10
  41. package/dist/entity/decorator/entity.js +2 -7
  42. package/dist/entity/decorator/members.d.ts +10 -31
  43. package/dist/entity/decorator/members.js +3 -12
  44. package/dist/entity/metadata/definition.d.ts +5 -21
  45. package/dist/entity/metadata/definition.js +69 -91
  46. package/dist/http/handler.d.ts +2 -14
  47. package/dist/index.d.ts +3 -1
  48. package/dist/index.js +3 -1
  49. package/dist/libsql/libsqlDialect.d.ts +1 -8
  50. package/dist/libsql/libsqlDialect.js +1 -8
  51. package/dist/maria/mariaDialect.d.ts +3 -5
  52. package/dist/maria/mariaDialect.js +5 -5
  53. package/dist/maria/mariadbQuerier.js +2 -2
  54. package/dist/maria/mariadbQuerierPool.js +1 -6
  55. package/dist/migrate/builder/migrationBuilder.js +3 -19
  56. package/dist/migrate/builder/splitSqlStatements.d.ts +1 -14
  57. package/dist/migrate/builder/splitSqlStatements.js +2 -22
  58. package/dist/migrate/builder/types.d.ts +2 -15
  59. package/dist/migrate/cli-config.js +2 -11
  60. package/dist/migrate/cli.js +2 -7
  61. package/dist/migrate/codegen/entityCodeGenerator.d.ts +0 -15
  62. package/dist/migrate/codegen/entityCodeGenerator.js +15 -44
  63. package/dist/migrate/codegen/fieldOptionsSource.d.ts +1 -8
  64. package/dist/migrate/codegen/fieldOptionsSource.js +3 -22
  65. package/dist/migrate/ddl/indexDdl.d.ts +2 -5
  66. package/dist/migrate/ddl/indexDdl.js +2 -5
  67. package/dist/migrate/ddl/pgIndexDdl.d.ts +3 -13
  68. package/dist/migrate/ddl/pgIndexDdl.js +3 -13
  69. package/dist/migrate/generator/definitionToNode.d.ts +2 -9
  70. package/dist/migrate/generator/definitionToNode.js +3 -17
  71. package/dist/migrate/generator/indexNodeToSchema.d.ts +2 -3
  72. package/dist/migrate/generator/indexNodeToSchema.js +2 -3
  73. package/dist/migrate/generator/mongoCommand.d.ts +1 -8
  74. package/dist/migrate/generator/mongoSchemaGenerator.d.ts +1 -8
  75. package/dist/migrate/generator/mongoSchemaGenerator.js +1 -8
  76. package/dist/migrate/introspection/abstractSqlSchemaIntrospector.d.ts +6 -26
  77. package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +9 -41
  78. package/dist/migrate/introspection/baseSqlIntrospector.js +0 -1
  79. package/dist/migrate/introspection/mongoIntrospector.d.ts +3 -1
  80. package/dist/migrate/introspection/mongoIntrospector.js +48 -46
  81. package/dist/migrate/introspection/mssqlIntrospector.d.ts +4 -4
  82. package/dist/migrate/introspection/mssqlIntrospector.js +18 -27
  83. package/dist/migrate/introspection/mysqlIntrospector.d.ts +7 -2
  84. package/dist/migrate/introspection/mysqlIntrospector.js +16 -14
  85. package/dist/migrate/introspection/postgresIntrospector.d.ts +24 -9
  86. package/dist/migrate/introspection/postgresIntrospector.js +68 -59
  87. package/dist/migrate/introspection/sqliteIntrospector.d.ts +1 -1
  88. package/dist/migrate/introspection/sqliteIntrospector.js +8 -10
  89. package/dist/migrate/migrator.d.ts +9 -53
  90. package/dist/migrate/migrator.js +32 -65
  91. package/dist/migrate/schemaGenerator.d.ts +20 -66
  92. package/dist/migrate/schemaGenerator.js +32 -93
  93. package/dist/mongo/mongoDialect.d.ts +21 -53
  94. package/dist/mongo/mongoDialect.js +25 -70
  95. package/dist/mongo/mongodbQuerier.d.ts +5 -8
  96. package/dist/mongo/mongodbQuerier.js +31 -65
  97. package/dist/mssql/mssqlDialect.d.ts +8 -34
  98. package/dist/mssql/mssqlDialect.js +37 -51
  99. package/dist/mssql/mssqlQuerier.d.ts +37 -4
  100. package/dist/mssql/mssqlQuerier.js +2 -2
  101. package/dist/mssql/mssqlWireTypes.d.ts +2 -14
  102. package/dist/mssql/mssqlWireTypes.js +2 -14
  103. package/dist/nestjs/uqlModule.js +2 -7
  104. package/dist/pglite/pgliteQuerier.d.ts +1 -9
  105. package/dist/pglite/pgliteQuerierPool.d.ts +4 -26
  106. package/dist/pglite/pgliteQuerierPool.js +3 -18
  107. package/dist/postgres/abstractPgQuerierPool.d.ts +1 -8
  108. package/dist/postgres/abstractPgQuerierPool.js +1 -8
  109. package/dist/postgres/pgNumericTypes.d.ts +3 -26
  110. package/dist/postgres/pgNumericTypes.js +3 -26
  111. package/dist/postgres/postgresDialect.d.ts +4 -10
  112. package/dist/postgres/postgresDialect.js +4 -10
  113. package/dist/querier/abstractQuerier.d.ts +35 -103
  114. package/dist/querier/abstractQuerier.js +105 -201
  115. package/dist/querier/abstractSharedHandleQuerierPool.d.ts +3 -17
  116. package/dist/querier/abstractSharedHandleQuerierPool.js +3 -17
  117. package/dist/querier/abstractSqlQuerier.d.ts +15 -36
  118. package/dist/querier/abstractSqlQuerier.js +49 -131
  119. package/dist/schema/canonicalType.d.ts +3 -21
  120. package/dist/schema/canonicalType.js +22 -67
  121. package/dist/schema/dependencyGraph.d.ts +2 -8
  122. package/dist/schema/dependencyGraph.js +2 -32
  123. package/dist/schema/index.d.ts +1 -25
  124. package/dist/schema/index.js +0 -26
  125. package/dist/schema/indexColumns.d.ts +1 -8
  126. package/dist/schema/indexColumns.js +1 -8
  127. package/dist/schema/indexDifferences.d.ts +7 -40
  128. package/dist/schema/indexDifferences.js +6 -31
  129. package/dist/schema/schemaAST.d.ts +8 -175
  130. package/dist/schema/schemaAST.js +13 -365
  131. package/dist/schema/schemaASTBuilder.d.ts +2 -24
  132. package/dist/schema/schemaASTBuilder.js +6 -41
  133. package/dist/schema/schemaASTDiffer.d.ts +6 -46
  134. package/dist/schema/schemaASTDiffer.js +8 -56
  135. package/dist/schema/types.d.ts +5 -61
  136. package/dist/schema/types.js +3 -6
  137. package/dist/sqlite/abstractSqliteQuerier.d.ts +1 -8
  138. package/dist/sqlite/localSqliteQuerierPool.d.ts +1 -7
  139. package/dist/sqlite/localSqliteQuerierPool.js +1 -7
  140. package/dist/sqlite/nodeSqliteQuerierPool.d.ts +2 -7
  141. package/dist/sqlite/nodeSqliteQuerierPool.js +2 -7
  142. package/dist/sqlite/sqliteDialect.d.ts +5 -20
  143. package/dist/sqlite/sqliteDialect.js +29 -35
  144. package/dist/turso/tursoDialect.d.ts +4 -6
  145. package/dist/turso/tursoDialect.js +4 -6
  146. package/dist/turso/tursoLocalQuerierPool.d.ts +1 -7
  147. package/dist/turso/tursoLocalQuerierPool.js +1 -7
  148. package/dist/turso/tursoQuerierPool.d.ts +2 -6
  149. package/dist/turso/tursoQuerierPool.js +2 -6
  150. package/dist/turso/tursoSessionQuerier.d.ts +1 -7
  151. package/dist/turso/tursoSessionQuerier.js +1 -7
  152. package/dist/type/dialect.d.ts +42 -94
  153. package/dist/type/dialect.js +3 -13
  154. package/dist/type/entity.d.ts +189 -551
  155. package/dist/type/entity.js +26 -9
  156. package/dist/type/logger.d.ts +2 -14
  157. package/dist/type/migration.d.ts +9 -38
  158. package/dist/type/querier.d.ts +9 -28
  159. package/dist/type/querierPool.d.ts +4 -26
  160. package/dist/type/query.d.ts +28 -78
  161. package/dist/type/query.js +2 -7
  162. package/dist/type/queryAggregate.d.ts +18 -98
  163. package/dist/type/queryRaw.d.ts +1 -8
  164. package/dist/type/queryRaw.js +1 -8
  165. package/dist/type/queryWhere.d.ts +13 -61
  166. package/dist/type/universalQuerier.d.ts +18 -105
  167. package/dist/type/utility.d.ts +12 -24
  168. package/dist/type/vector.d.ts +8 -38
  169. package/dist/type/vector.js +1 -1
  170. package/dist/type/wire.d.ts +2 -5
  171. package/dist/util/dialect.util.d.ts +9 -27
  172. package/dist/util/dialect.util.js +10 -27
  173. package/dist/util/field.util.d.ts +5 -37
  174. package/dist/util/field.util.js +7 -50
  175. package/dist/util/fieldOption.util.d.ts +7 -15
  176. package/dist/util/fieldOption.util.js +1 -1
  177. package/dist/util/filters.util.d.ts +2 -5
  178. package/dist/util/filters.util.js +2 -5
  179. package/dist/util/logger.d.ts +2 -6
  180. package/dist/util/logger.js +2 -6
  181. package/dist/util/object.util.d.ts +2 -6
  182. package/dist/util/object.util.js +1 -5
  183. package/dist/util/raw.d.ts +3 -23
  184. package/dist/util/relationQuery.util.d.ts +3 -14
  185. package/dist/util/relationQuery.util.js +3 -14
  186. package/dist/util/rowKey.util.d.ts +2 -10
  187. package/dist/util/rowKey.util.js +2 -10
  188. package/dist/util/sql.util.d.ts +6 -37
  189. package/dist/util/sql.util.js +13 -73
  190. package/dist/util/sqlLiteral.d.ts +2 -13
  191. package/dist/util/sqlLiteral.js +8 -13
  192. package/dist/util/string.util.js +0 -2
  193. package/package.json +4 -4
@@ -1,51 +1,18 @@
1
1
  import type { IndexNode } from './types.js';
2
- /**
3
- * What an introspector can report about an index, and so all that diffing may compare. Anything it
4
- * cannot report is skipped: the entity declares it, the database never mentions it, and no migration
5
- * could ever make the two agree.
6
- *
7
- * Deliberately separate from the dialect's `IndexFeature`, which says what an engine can *emit* and
8
- * rejects outright. The two look alike and are not: Postgres emits an expression index and reads one
9
- * back, MySQL emits one it cannot describe afterwards.
10
- */
2
+ /** What an introspector reports about an index, and so all a diff may compare; apart from `IndexFeature`, what an engine emits. */
11
3
  export type IndexFacet = 'order' | 'nulls' | 'opsClass' | 'accessMethod' | 'include';
12
4
  /**
13
- * Whether the table already has this index, for the additive sync that only ever *creates* one.
14
- *
15
- * Its shape, never its name: the table's indexes were named by whoever created them, so an index
16
- * that is already there must not be created a second time under a name we happen to prefer. A
17
- * derived name is no handle at all - the convention can change, an engine silently truncates one
18
- * past its identifier limit, and SQLite reports names it made up.
19
- *
20
- * Uniqueness counts, because a unique index and a plain one over the same columns enforce different
21
- * things and no engine can alter one into the other. An index over an expression or a JSON path has
22
- * no comparable columns - engines reprint SQL text from their parse tree, the same reason
23
- * {@link describeIndexDifferences} leaves those entries alone - so it falls back to its name.
5
+ * Whether the table has this index already, by shape rather than name, uniqueness included. An index
6
+ * over an expression, whose text the engine reprints, falls back to its name.
24
7
  */
25
8
  export declare function indexSignature(index: Pick<IndexNode, 'name' | 'entries' | 'unique'>): string;
26
9
  /**
27
- * A constraint name without its kind marker.
28
- *
29
- * What pairs two sides of a *report*: an index whose uniqueness or columns changed is one index that
30
- * differs, not one dropped and another created, and only a handle independent of its shape can say
31
- * so. Stripping the marker is what lets `idx_User_email`, named before the convention moved it to
32
- * the end, recognise the `User__email_idx` derived for it now, so upgrading reports no drift.
33
- *
34
- * Exactly one marker, and the trailing one first. Stripping both ends would eat a leading marker
35
- * that belongs to the *table* - an index over `pk_registry` is not a primary key - leaving it unable
36
- * to pair with its own older name. The separator is levelled last, since only one convention doubles
37
- * it.
10
+ * A constraint name without its kind marker, pairing an index with its older spelling
11
+ * (`idx_User_email` with `User__email_idx`). Only one marker, the trailing one first.
38
12
  */
39
13
  export declare function indexNameStem(name: string): string;
40
14
  /**
41
- * Everything an index differs by, named, or nothing when the two match.
42
- *
43
- * Only what both sides can state *structurally* is compared. SQL text is not: a database reprints an
44
- * expression and a predicate from its parse tree, so `status IN ('a','b')` reads back as
45
- * `status = ANY (ARRAY['a'::text, 'b'::text])`, `LIKE` as `~~`, and a date literal with its time zone
46
- * spelled out. Folding that back needs a SQL parser, and every near-miss reports drift that no
47
- * migration can settle. So a partial index's predicate is never compared, and an index over an
48
- * expression - a `raw()` one, or a JSON path, which the engines report as an expression too - has
49
- * its entries left alone while the rest of it still compares.
15
+ * What two indexes differ by, comparing only what both sides state structurally: an expression, a JSON
16
+ * path or a predicate is reprinted by the engine, so never compared.
50
17
  */
51
18
  export declare function describeIndexDifferences(source: IndexNode, target: IndexNode, facets: ReadonlySet<IndexFacet>): string[];
@@ -1,15 +1,6 @@
1
1
  /**
2
- * Whether the table already has this index, for the additive sync that only ever *creates* one.
3
- *
4
- * Its shape, never its name: the table's indexes were named by whoever created them, so an index
5
- * that is already there must not be created a second time under a name we happen to prefer. A
6
- * derived name is no handle at all - the convention can change, an engine silently truncates one
7
- * past its identifier limit, and SQLite reports names it made up.
8
- *
9
- * Uniqueness counts, because a unique index and a plain one over the same columns enforce different
10
- * things and no engine can alter one into the other. An index over an expression or a JSON path has
11
- * no comparable columns - engines reprint SQL text from their parse tree, the same reason
12
- * {@link describeIndexDifferences} leaves those entries alone - so it falls back to its name.
2
+ * Whether the table has this index already, by shape rather than name, uniqueness included. An index
3
+ * over an expression, whose text the engine reprints, falls back to its name.
13
4
  */
14
5
  export function indexSignature(index) {
15
6
  const comparable = !index.entries.some((entry) => entry.expression || entry.jsonPath || entry.jsonArray);
@@ -19,17 +10,8 @@ export function indexSignature(index) {
19
10
  return `${index.unique ? 'unique' : 'plain'}(${identity})`;
20
11
  }
21
12
  /**
22
- * A constraint name without its kind marker.
23
- *
24
- * What pairs two sides of a *report*: an index whose uniqueness or columns changed is one index that
25
- * differs, not one dropped and another created, and only a handle independent of its shape can say
26
- * so. Stripping the marker is what lets `idx_User_email`, named before the convention moved it to
27
- * the end, recognise the `User__email_idx` derived for it now, so upgrading reports no drift.
28
- *
29
- * Exactly one marker, and the trailing one first. Stripping both ends would eat a leading marker
30
- * that belongs to the *table* - an index over `pk_registry` is not a primary key - leaving it unable
31
- * to pair with its own older name. The separator is levelled last, since only one convention doubles
32
- * it.
13
+ * A constraint name without its kind marker, pairing an index with its older spelling
14
+ * (`idx_User_email` with `User__email_idx`). Only one marker, the trailing one first.
33
15
  */
34
16
  export function indexNameStem(name) {
35
17
  const withoutSuffix = name.replace(KIND_SUFFIX, '');
@@ -45,15 +27,8 @@ const KIND_SUFFIX = /_(?:idx|fk|ck|pk|uk|uq)$/i;
45
27
  */
46
28
  const KIND_PREFIX = /^(?:idx|fk|ck|pk|uk|uq)_/i;
47
29
  /**
48
- * Everything an index differs by, named, or nothing when the two match.
49
- *
50
- * Only what both sides can state *structurally* is compared. SQL text is not: a database reprints an
51
- * expression and a predicate from its parse tree, so `status IN ('a','b')` reads back as
52
- * `status = ANY (ARRAY['a'::text, 'b'::text])`, `LIKE` as `~~`, and a date literal with its time zone
53
- * spelled out. Folding that back needs a SQL parser, and every near-miss reports drift that no
54
- * migration can settle. So a partial index's predicate is never compared, and an index over an
55
- * expression - a `raw()` one, or a JSON path, which the engines report as an expression too - has
56
- * its entries left alone while the rest of it still compares.
30
+ * What two indexes differ by, comparing only what both sides state structurally: an expression, a JSON
31
+ * path or a predicate is reprinted by the engine, so never compared.
57
32
  */
58
33
  export function describeIndexDifferences(source, target, facets) {
59
34
  const differences = [];
@@ -1,187 +1,20 @@
1
- /**
2
- * SchemaAST Class
3
- *
4
- * The main class for working with schema graphs.
5
- * Provides graph operations like navigation, validation, and topological sorting.
6
- */
7
- import type { ColumnNode, IndexNode, SchemaAST as ISchemaAST, RelationshipNode, RelationshipType, TableNode, ValidationError } from './types.js';
8
- /**
9
- * A table node with its collections empty, ready to be filled. Six places build one, and the fields
10
- * that are pure boilerplate are exactly the ones a new field gets forgotten in: {@link TableNode.schema}
11
- * was added and `SchemaAST.clone` kept rebuilding nodes without it.
12
- */
1
+ import type { IndexNode, RelationshipNode, TableNode } from './types.js';
2
+ /** A table node with its collections empty, ready to be filled. */
13
3
  export declare function createTableNode(name: string, schema?: string, comment?: string): TableNode;
14
- /**
15
- * Schema AST - A graph representation of a database schema.
16
- *
17
- * Enables:
18
- * - Graph navigation (dependencies, dependents)
19
- * - Circular dependency detection
20
- * - Topological sorting for correct DDL order
21
- * - Smart relation inference
22
- * - Schema validation
23
- */
24
- export declare class SchemaAST implements ISchemaAST {
4
+ /** A database schema as a graph: tables, the foreign keys between them, and their indexes. */
5
+ export declare class SchemaAST {
25
6
  readonly tables: Map<string, TableNode>;
26
7
  readonly relationships: RelationshipNode[];
27
8
  readonly indexes: IndexNode[];
28
- /**
29
- * Get a table by the name it is keyed under: schema-qualified where it has one, so two tables of
30
- * the same name in different schemas stay distinct. Build the key with `qualifyName`.
31
- */
9
+ /** A table by the key it is stored under: schema-qualified where it has one (see `qualifyName`). */
32
10
  getTable(name: string): TableNode | undefined;
33
- /**
34
- * Add a table to the schema.
35
- */
36
11
  addTable(table: TableNode): void;
37
- /**
38
- * Remove a table from the schema.
39
- */
40
- removeTable(name: string): boolean;
41
- /**
42
- * Get all table nodes.
43
- */
44
12
  getTables(): TableNode[];
45
- /**
46
- * Get all table names.
47
- */
48
- getTableNames(): string[];
49
- /**
50
- * Get all tables that depend on this table (have FKs pointing to it).
51
- * These are tables that reference this table's primary key.
52
- */
53
- getDependentTables(table: TableNode): TableNode[];
54
- /**
55
- * Get all tables this table depends on (has FKs to).
56
- * These are tables that this table references.
57
- */
58
- getDependencies(table: TableNode): TableNode[];
59
- /**
60
- * Get the relationship between two tables (if any).
61
- */
62
- getRelationship(from: TableNode, to: TableNode): RelationshipNode | undefined;
63
- /**
64
- * Get all relationships for a table.
65
- */
66
- getTableRelationships(table: TableNode): RelationshipNode[];
67
- /**
68
- * Get the column that a foreign key column references.
69
- */
70
- getReferencedColumn(fkColumn: ColumnNode): ColumnNode | undefined;
71
- /**
72
- * Detect circular foreign key dependencies.
73
- * Returns arrays of tables that form cycles.
74
- */
75
- detectCircularDependencies(): TableNode[][];
76
- /**
77
- * Check if there are any circular dependencies.
78
- */
79
- hasCircularDependencies(): boolean;
80
- /**
81
- * Get tables in correct order for CREATE (dependencies first).
82
- * Tables with no dependencies come first, then tables that depend on them, etc.
83
- */
13
+ /** Tables in `CREATE` order, each after the tables it references. */
84
14
  getCreateOrder(): TableNode[];
85
- /**
86
- * Get tables in correct order for DROP (dependents first).
87
- * Tables that depend on others come first, then the tables they depend on.
88
- */
15
+ /** Tables in `DROP` order, each before the tables it references. */
89
16
  getDropOrder(): TableNode[];
90
- /**
91
- * Validate schema integrity.
92
- * Checks for:
93
- * - Missing FK targets
94
- * - Circular dependencies
95
- * - Orphan columns
96
- * - Duplicate indexes
97
- */
98
- validate(): ValidationError[];
99
- /**
100
- * Check if the schema is valid (no validation errors).
101
- */
102
- isValid(): boolean;
103
- /**
104
- * Check if a table looks like a junction table (ManyToMany through).
105
- * Junction tables typically have:
106
- * - Exactly 2 foreign keys
107
- * - Few other columns (id, maybe timestamps)
108
- * - Primary key might be composite of the FKs
109
- */
110
- isJunctionTable(table: TableNode): boolean;
111
- /**
112
- * Infer relation type from schema structure.
113
- */
114
- inferRelationType(rel: RelationshipNode): RelationshipType;
115
- /**
116
- * Get the inverse relation type.
117
- */
118
- getInverseRelationType(type: RelationshipType): RelationshipType;
119
- /**
120
- * Add an index to the schema.
121
- */
122
17
  addIndex(index: IndexNode): void;
123
- /**
124
- * Get all indexes for a table.
125
- */
126
- getTableIndexes(tableName: string): IndexNode[];
127
- /**
128
- * Find an index by name.
129
- */
130
- getIndex(name: string): IndexNode | undefined;
131
- /**
132
- * Add a relationship to the schema.
133
- */
18
+ /** Adds a foreign key, linking it from both tables and both column sets. */
134
19
  addRelationship(rel: RelationshipNode): void;
135
- /**
136
- * Remove a relationship from the schema.
137
- */
138
- removeRelationship(name: string): boolean;
139
- /**
140
- * Create a deep clone of this schema.
141
- */
142
- clone(): SchemaAST;
143
- /**
144
- * Get statistics about the schema.
145
- */
146
- getStats(): {
147
- tableCount: number;
148
- columnCount: number;
149
- relationshipCount: number;
150
- indexCount: number;
151
- };
152
- /**
153
- * The schema as a plain object, for serialization and debugging. The graph links are what is left
154
- * out - they are cycles, and nothing else is: listing the fields to keep instead dropped every
155
- * option a column had gained since, `defaultValue` and `enum` included.
156
- */
157
- toJSON(): {
158
- tables: {
159
- name: string;
160
- columns: {
161
- name: string;
162
- type: import("./types.js").CanonicalType;
163
- nullable: boolean;
164
- defaultValue?: unknown;
165
- isPrimaryKey: boolean;
166
- isAutoIncrement: boolean;
167
- isUnique: boolean;
168
- enum?: import("./types.js").EnumValues;
169
- generatedAs?: string;
170
- comment?: string;
171
- }[];
172
- indexes: {
173
- name: string;
174
- columns: string[];
175
- unique: boolean;
176
- }[];
177
- }[];
178
- relationships: {
179
- name: string;
180
- type: RelationshipType;
181
- from: string;
182
- to: string;
183
- onDelete: import("./types.js").ForeignKeyAction | undefined;
184
- onUpdate: import("./types.js").ForeignKeyAction | undefined;
185
- }[];
186
- };
187
20
  }