uql-orm 0.104.1 → 0.105.1

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 (161) hide show
  1. package/README.md +24 -10
  2. package/dist/browser/querier/httpQuerier.d.ts +3 -3
  3. package/dist/browser/type/clientQuerier.d.ts +1 -1
  4. package/dist/browser/uql-browser.min.js +2 -2
  5. package/dist/browser/uql-browser.min.js.map +9 -9
  6. package/dist/cockroachdb/cockroachDialect.d.ts +2 -2
  7. package/dist/dialect/abstractDialect.d.ts +3 -3
  8. package/dist/dialect/abstractSqlDialect.d.ts +39 -37
  9. package/dist/dialect/abstractSqlDialect.js +35 -32
  10. package/dist/dialect/aliases.d.ts +2 -0
  11. package/dist/dialect/aliases.js +2 -0
  12. package/dist/dialect/jsonSql.js +2 -2
  13. package/dist/dialect/mergeSqlDialect.d.ts +2 -2
  14. package/dist/dialect/mysqlLikeSqlDialect.d.ts +7 -7
  15. package/dist/dialect/mysqlLikeSqlDialect.js +1 -1
  16. package/dist/dialect/operators.js +2 -4
  17. package/dist/dialect/queryJoins.d.ts +4 -2
  18. package/dist/dialect/vectorSqlDialect.d.ts +1 -1
  19. package/dist/dialect/vectorSqlDialect.js +1 -1
  20. package/dist/entity/column.d.ts +3 -0
  21. package/dist/entity/column.js +3 -0
  22. package/dist/entity/columnOptionsBuilder.d.ts +54 -0
  23. package/dist/entity/columnOptionsBuilder.js +108 -0
  24. package/dist/entity/decorator/bag.d.ts +5 -5
  25. package/dist/entity/decorator/entity.d.ts +3 -20
  26. package/dist/entity/decorator/entity.js +3 -37
  27. package/dist/entity/decorator/members.d.ts +46 -76
  28. package/dist/entity/decorator/members.js +18 -7
  29. package/dist/entity/index.d.ts +2 -1
  30. package/dist/entity/index.js +2 -1
  31. package/dist/entity/metadata/definition.d.ts +15 -26
  32. package/dist/entity/metadata/definition.js +344 -148
  33. package/dist/entity/metadata/schemaFixture/animal.d.ts +54 -0
  34. package/dist/entity/metadata/schemaFixture/animal.js +7 -0
  35. package/dist/entity/metadata/schemaFixture/author.d.ts +140 -0
  36. package/dist/entity/metadata/schemaFixture/author.js +25 -0
  37. package/dist/entity/metadata/schemaFixture/book.d.ts +192 -0
  38. package/dist/entity/metadata/schemaFixture/book.js +23 -0
  39. package/dist/http/contract.d.ts +2 -2
  40. package/dist/http/handler.d.ts +2 -2
  41. package/dist/http/query.js +12 -13
  42. package/dist/index.d.ts +2 -2
  43. package/dist/index.js +2 -1
  44. package/dist/mariadb/mariaDialect.d.ts +2 -2
  45. package/dist/mariadb/mariaDialect.js +1 -1
  46. package/dist/mariadb/mariadbQuerier.js +1 -3
  47. package/dist/migrate/builder/columnBuilder.d.ts +20 -68
  48. package/dist/migrate/builder/columnBuilder.js +104 -110
  49. package/dist/migrate/builder/migrationBuilder.d.ts +3 -3
  50. package/dist/migrate/builder/migrationBuilder.js +7 -6
  51. package/dist/migrate/builder/tableBuilder.d.ts +3 -55
  52. package/dist/migrate/builder/tableBuilder.js +88 -204
  53. package/dist/migrate/builder/types.d.ts +52 -151
  54. package/dist/migrate/builder/types.js +0 -6
  55. package/dist/migrate/codegen/entityCodeGenerator.d.ts +2 -2
  56. package/dist/migrate/codegen/entityCodeGenerator.js +24 -24
  57. package/dist/migrate/codegen/entityTypes.d.ts +2 -2
  58. package/dist/migrate/codegen/fieldOptionsSource.d.ts +3 -1
  59. package/dist/migrate/codegen/fieldOptionsSource.js +35 -34
  60. package/dist/migrate/codegen/indexEntrySource.d.ts +16 -0
  61. package/dist/migrate/codegen/{indexDecoratorSource.js → indexEntrySource.js} +54 -27
  62. package/dist/migrate/ddl/defaultSql.js +7 -6
  63. package/dist/migrate/ddl/indexCapabilities.d.ts +8 -7
  64. package/dist/migrate/ddl/indexCapabilities.js +26 -13
  65. package/dist/migrate/ddl/indexDdl.d.ts +13 -13
  66. package/dist/migrate/ddl/indexDdl.js +33 -30
  67. package/dist/migrate/ddl/mysqlIndexDdl.d.ts +6 -11
  68. package/dist/migrate/ddl/mysqlIndexDdl.js +17 -28
  69. package/dist/migrate/ddl/pgIndexDdl.d.ts +2 -2
  70. package/dist/migrate/ddl/sqliteIndexDdl.d.ts +2 -2
  71. package/dist/migrate/drift/driftDetector.js +2 -2
  72. package/dist/migrate/generator/definitionToNode.d.ts +8 -2
  73. package/dist/migrate/generator/definitionToNode.js +4 -5
  74. package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +11 -2
  75. package/dist/migrate/introspection/jsonIndexEntry.d.ts +6 -0
  76. package/dist/migrate/introspection/jsonIndexEntry.js +120 -0
  77. package/dist/migrate/introspection/mysqlIntrospector.d.ts +4 -4
  78. package/dist/migrate/introspection/mysqlIntrospector.js +25 -21
  79. package/dist/migrate/introspection/postgresIntrospector.d.ts +1 -1
  80. package/dist/migrate/introspection/postgresIntrospector.js +3 -4
  81. package/dist/migrate/introspection/sqliteIntrospector.js +24 -9
  82. package/dist/migrate/introspection/tableSchemaAST.js +5 -1
  83. package/dist/migrate/migrator.d.ts +2 -2
  84. package/dist/migrate/schemaChange.d.ts +3 -3
  85. package/dist/migrate/schemaChange.js +3 -2
  86. package/dist/migrate/schemaGenerator.d.ts +5 -5
  87. package/dist/migrate/schemaGenerator.js +1 -1
  88. package/dist/migrate/storage/databaseStorage.js +4 -4
  89. package/dist/mongodb/mongoDialect.d.ts +41 -44
  90. package/dist/mongodb/mongoDialect.js +118 -32
  91. package/dist/mongodb/mongoIntrospector.d.ts +3 -1
  92. package/dist/mongodb/mongoIntrospector.js +11 -5
  93. package/dist/mongodb/mongoSchemaGenerator.d.ts +4 -4
  94. package/dist/mongodb/mongoSchemaGenerator.js +35 -27
  95. package/dist/mongodb/mongodbQuerier.d.ts +1 -11
  96. package/dist/mongodb/mongodbQuerier.js +9 -43
  97. package/dist/mssql/mssqlDialect.d.ts +4 -4
  98. package/dist/postgres/postgresDialect.d.ts +2 -2
  99. package/dist/querier/abstractQuerier.d.ts +0 -1
  100. package/dist/querier/abstractQuerier.js +1 -20
  101. package/dist/querier/abstractSqlQuerier.d.ts +1 -1
  102. package/dist/querier/keyset.js +3 -3
  103. package/dist/schema/declaredColumn.d.ts +11 -0
  104. package/dist/schema/declaredColumn.js +21 -0
  105. package/dist/schema/indexColumns.d.ts +0 -3
  106. package/dist/schema/indexColumns.js +11 -7
  107. package/dist/schema/indexDifferences.d.ts +10 -5
  108. package/dist/schema/indexDifferences.js +42 -28
  109. package/dist/schema/schemaASTBuilder.d.ts +4 -4
  110. package/dist/schema/schemaASTBuilder.js +28 -36
  111. package/dist/schema/schemaASTDiffer.js +8 -4
  112. package/dist/schema/sqlExpression.d.ts +21 -17
  113. package/dist/schema/sqlExpression.js +11 -23
  114. package/dist/type/column.d.ts +328 -0
  115. package/dist/type/column.js +2 -0
  116. package/dist/type/config.d.ts +3 -3
  117. package/dist/type/dialect.d.ts +15 -14
  118. package/dist/type/dialect.js +1 -0
  119. package/dist/type/entity.d.ts +292 -281
  120. package/dist/type/entity.js +6 -1
  121. package/dist/type/index.d.ts +2 -0
  122. package/dist/type/index.js +2 -0
  123. package/dist/type/migration.d.ts +11 -11
  124. package/dist/type/querier.d.ts +2 -2
  125. package/dist/type/query.d.ts +44 -40
  126. package/dist/type/query.js +2 -3
  127. package/dist/type/queryAggregate.d.ts +22 -12
  128. package/dist/type/querySql.d.ts +22 -6
  129. package/dist/type/querySql.js +27 -9
  130. package/dist/type/schemaEntity.d.ts +194 -0
  131. package/dist/type/schemaEntity.js +1 -0
  132. package/dist/type/utility.d.ts +4 -7
  133. package/dist/type/vector.d.ts +1 -1
  134. package/dist/util/ddlExpression.util.d.ts +12 -13
  135. package/dist/util/ddlExpression.util.js +12 -21
  136. package/dist/util/dialect.util.d.ts +11 -5
  137. package/dist/util/dialect.util.js +31 -37
  138. package/dist/util/field.util.d.ts +10 -9
  139. package/dist/util/field.util.js +14 -10
  140. package/dist/util/fieldOption.util.d.ts +11 -95
  141. package/dist/util/fieldOption.util.js +49 -16
  142. package/dist/util/hook.util.d.ts +3 -15
  143. package/dist/util/hook.util.js +3 -16
  144. package/dist/util/index.d.ts +1 -0
  145. package/dist/util/index.js +1 -0
  146. package/dist/util/indexEntry.util.d.ts +45 -0
  147. package/dist/util/indexEntry.util.js +138 -0
  148. package/dist/util/relationQuery.util.d.ts +0 -1
  149. package/dist/util/relationQuery.util.js +0 -5
  150. package/dist/util/sql.d.ts +13 -10
  151. package/dist/util/sql.js +34 -16
  152. package/dist/util/sql.util.d.ts +4 -5
  153. package/dist/util/sql.util.js +7 -16
  154. package/dist/util/string.util.d.ts +2 -0
  155. package/dist/util/string.util.js +4 -0
  156. package/dist/util/triggerWrite.d.ts +5 -5
  157. package/dist/util/uqlError.d.ts +1 -1
  158. package/dist/util/uqlError.js +1 -1
  159. package/package.json +1 -1
  160. package/skills/uql-orm/SKILL.md +76 -25
  161. package/dist/migrate/codegen/indexDecoratorSource.d.ts +0 -16
@@ -1,215 +1,99 @@
1
- /**
2
- * Table Builder
3
- *
4
- * Fluent API for defining tables in migrations.
5
- */
6
- import { DATE_PRECISION } from '../../util/date.js';
7
1
  import { declaredIndexName } from '../../util/ddlExpression.util.js';
8
2
  import { currentTimestamp } from '../../util/sql.js';
9
3
  import { columnForeignKey, columnIndex, indexDefinition } from '../generator/definitionToNode.js';
10
- import { ColumnDefinitionBuilder } from './columnBuilder.js';
4
+ import { tableColumns } from './columnBuilder.js';
11
5
  /** Normalizes `table.index` options, where a bare string is the index name. */
12
6
  function namedOptions(options) {
13
7
  return typeof options === 'string' ? { name: options } : (options ?? {});
14
8
  }
15
- /**
16
- * Builder for table-level foreign keys.
17
- */
18
- class TableForeignKeyDefinitionBuilder {
19
- _columns;
20
- _referencedTable;
21
- _referencedColumns = [];
22
- _onDelete;
23
- _onUpdate;
24
- _name;
25
- constructor(_columns) {
26
- this._columns = _columns;
27
- }
28
- references(table, columns) {
29
- this._referencedTable = table;
30
- this._referencedColumns = columns;
31
- return this;
32
- }
33
- onDelete(action) {
34
- this._onDelete = action;
35
- return this;
36
- }
37
- onUpdate(action) {
38
- this._onUpdate = action;
39
- return this;
40
- }
41
- name(name) {
42
- this._name = name;
43
- return this;
44
- }
45
- /**
46
- * Build the foreign key definition.
47
- */
48
- build() {
49
- if (!this._referencedTable)
50
- return undefined;
51
- return {
52
- name: this._name,
53
- columns: this._columns,
54
- references: { table: this._referencedTable, columns: this._referencedColumns },
55
- onDelete: this._onDelete,
56
- onUpdate: this._onUpdate,
57
- };
58
- }
9
+ function foreignKeyDefinition(columns) {
10
+ let references;
11
+ let onDelete;
12
+ let onUpdate;
13
+ let name;
14
+ return {
15
+ references(table, referenced) {
16
+ references = { table, columns: referenced };
17
+ return this;
18
+ },
19
+ onDelete(action) {
20
+ onDelete = action;
21
+ return this;
22
+ },
23
+ onUpdate(action) {
24
+ onUpdate = action;
25
+ return this;
26
+ },
27
+ name(constraint) {
28
+ name = constraint;
29
+ return this;
30
+ },
31
+ build() {
32
+ if (!references)
33
+ return undefined;
34
+ return { name, columns, references, onDelete, onUpdate };
35
+ },
36
+ };
59
37
  }
60
- /**
61
- * Builder for table definitions with a fluent API.
62
- */
63
- export class TableDefinitionBuilder {
64
- _name;
65
- _columnBuilders = [];
66
- _primaryKey;
67
- _indexes = [];
68
- _foreignKeyBuilders = [];
69
- _comment;
70
- constructor(name) {
71
- this._name = name;
72
- }
73
- /** Big, matching an entity's `@Id`: a key is spelled from this type, so it has to state the real one. */
74
- id(name = 'id', options = {}) {
75
- return this.add(name, { category: 'integer', size: 'big' }, { ...options, primaryKey: true, autoIncrement: true });
76
- }
77
- integer(name, options) {
78
- return this.add(name, { category: 'integer' }, options);
79
- }
80
- smallint(name, options) {
81
- return this.add(name, { category: 'integer', size: 'small' }, options);
82
- }
83
- bigint(name, options) {
84
- return this.add(name, { category: 'integer', size: 'big' }, options);
85
- }
86
- float(name, options) {
87
- return this.add(name, { category: 'float' }, options);
88
- }
89
- double(name, options) {
90
- return this.add(name, { category: 'float', size: 'big' }, options);
91
- }
92
- decimal(name, options = {}) {
93
- const { precision, scale, ...rest } = options;
94
- return this.add(name, { category: 'decimal', precision, scale }, rest);
95
- }
96
- string(name, options = {}) {
97
- const { length = 255, ...rest } = options;
98
- return this.add(name, { category: 'string', length }, rest);
99
- }
100
- char(name, options = {}) {
101
- const { length = 1, ...rest } = options;
102
- return this.add(name, { category: 'string', length }, rest);
103
- }
104
- text(name, options) {
105
- return this.add(name, { category: 'string' }, options);
106
- }
107
- boolean(name, options) {
108
- return this.add(name, { category: 'boolean' }, options);
109
- }
110
- date(name, options) {
111
- return this.add(name, { category: 'date' }, options);
112
- }
113
- time(name, options) {
114
- return this.add(name, { category: 'time' }, options);
115
- }
116
- timestamp(name, options) {
117
- return this.add(name, { category: 'timestamp', precision: DATE_PRECISION }, options);
118
- }
119
- timestamptz(name, options) {
120
- return this.add(name, { category: 'timestamp', withTimezone: true, precision: DATE_PRECISION }, options);
121
- }
122
- json(name, options) {
123
- return this.add(name, { category: 'json' }, options);
124
- }
125
- /** One canonical json category; the dialect decides between `JSON` and `JSONB`. */
126
- jsonb(name, options) {
127
- return this.add(name, { category: 'json' }, options);
128
- }
129
- uuid(name, options) {
130
- return this.add(name, { category: 'uuid' }, options);
131
- }
132
- blob(name, options) {
133
- return this.add(name, { category: 'blob' }, options);
134
- }
135
- vector(name, options = {}) {
136
- const { dimensions, ...rest } = options;
137
- return this.add(name, { category: 'vector', length: dimensions }, rest);
138
- }
139
- add(name, type, options = {}) {
140
- const column = new ColumnDefinitionBuilder(name, type, options);
141
- this._columnBuilders.push(column);
38
+ /** A table as `createTable`'s callback declares it: its columns in `f`'s vocabulary, then what spans several. */
39
+ export function tableBuilder(name) {
40
+ const columns = [];
41
+ const indexes = [];
42
+ const foreignKeyBuilders = [];
43
+ let primaryKey;
44
+ let comment;
45
+ const factory = tableColumns((column) => {
46
+ columns.push(column);
142
47
  return column;
143
- }
144
- createdAt() {
145
- return this.timestampNow('createdAt');
146
- }
147
- updatedAt() {
148
- return this.timestampNow('updatedAt');
149
- }
150
- timestampNow(name) {
151
- return this.timestamptz(name, { defaultValue: currentTimestamp });
152
- }
153
- timestamps() {
154
- this.createdAt();
155
- this.updatedAt();
156
- }
157
- primaryKey(columns) {
158
- this._primaryKey = columns;
159
- return this;
160
- }
161
- unique(columns, options) {
162
- this._indexes.push(indexDefinition(columns, { ...namedOptions(options), unique: true }, true));
163
- return this;
164
- }
165
- index(columns, options) {
166
- this._indexes.push(indexDefinition(columns, namedOptions(options)));
167
- return this;
168
- }
169
- foreignKey(columns) {
170
- const fk = new TableForeignKeyDefinitionBuilder(columns);
171
- this._foreignKeyBuilders.push(fk);
172
- return fk;
173
- }
174
- comment(text) {
175
- this._comment = text;
176
- return this;
177
- }
178
- /**
179
- * Build the table definition.
180
- */
181
- build() {
182
- // Build all columns from builders
183
- const columns = this._columnBuilders.map((cb) => cb.build());
184
- // Collect column-level indexes, skipping one a table-level index already names.
185
- const taken = new Set(this._indexes
186
- .filter((idx) => idx.where === undefined)
187
- .map((idx) => declaredIndexName(idx.name, this._name, idx.entries, { unique: idx.uniqueName })));
188
- for (const col of columns) {
189
- const index = columnIndex(this._name, col);
190
- if (index && !taken.has(index.name)) {
191
- this._indexes.push(index);
48
+ });
49
+ const timestampNow = (column) => factory.timestamptz(column).default(currentTimestamp);
50
+ return {
51
+ ...factory,
52
+ createdAt: () => timestampNow('createdAt'),
53
+ updatedAt: () => timestampNow('updatedAt'),
54
+ timestamps() {
55
+ timestampNow('createdAt');
56
+ timestampNow('updatedAt');
57
+ },
58
+ primaryKey(keyColumns) {
59
+ primaryKey = keyColumns;
60
+ return this;
61
+ },
62
+ unique(entries, options) {
63
+ indexes.push(indexDefinition(entries, { ...namedOptions(options), unique: true }, true));
64
+ return this;
65
+ },
66
+ index(entries, options) {
67
+ indexes.push(indexDefinition(entries, namedOptions(options)));
68
+ return this;
69
+ },
70
+ foreignKey(keyColumns) {
71
+ const foreignKey = foreignKeyDefinition(keyColumns);
72
+ foreignKeyBuilders.push(foreignKey);
73
+ return foreignKey;
74
+ },
75
+ comment(text) {
76
+ comment = text;
77
+ return this;
78
+ },
79
+ build() {
80
+ const built = columns.map((column) => column.build());
81
+ // Column-level indexes, skipping one a table-level index already names.
82
+ const taken = new Set(indexes
83
+ .filter((index) => index.where === undefined)
84
+ .map((index) => declaredIndexName(index.name, name, index.entries, { unique: index.uniqueName })));
85
+ const columnIndexes = built.flatMap((column) => {
86
+ const index = columnIndex(name, column);
87
+ if (!index || taken.has(index.name))
88
+ return [];
192
89
  taken.add(index.name);
193
- }
194
- }
195
- // Build foreign keys
196
- const foreignKeys = this._foreignKeyBuilders
197
- .map((fk) => fk.build())
198
- .filter((fk) => fk !== undefined);
199
- // Collect column-level foreign keys
200
- for (const col of columns) {
201
- const foreignKey = columnForeignKey(col);
202
- if (foreignKey) {
203
- foreignKeys.push(foreignKey);
204
- }
205
- }
206
- return {
207
- name: this._name,
208
- columns,
209
- primaryKey: this._primaryKey,
210
- indexes: this._indexes,
211
- foreignKeys,
212
- comment: this._comment,
213
- };
214
- }
90
+ return [index];
91
+ });
92
+ const foreignKeys = [
93
+ ...foreignKeyBuilders.map((foreignKey) => foreignKey.build()),
94
+ ...built.map(columnForeignKey),
95
+ ].filter((foreignKey) => foreignKey !== undefined);
96
+ return { name, columns: built, primaryKey, indexes: [...indexes, ...columnIndexes], foreignKeys, comment };
97
+ },
98
+ };
215
99
  }
@@ -1,73 +1,6 @@
1
- /**
2
- * Migration Builder Types
3
- *
4
- * Type definitions for the fluent migration builder API.
5
- * Enables type-safe migrations without raw SQL.
6
- */
7
1
  import type { ColumnNode, EnumValues, ForeignKeyAction } from '../../schema/types.js';
8
- import type { EntityIndexColumn, Except, IndexColumnInput, IndexOptions, IndexSchema, QuerySql } from '../../type/index.js';
2
+ import type { IndexEntry, Except, FieldOptions, IndexColumnInput, IndexOptions, IndexSchema, QuerySql } from '../../type/index.js';
9
3
  import type { ForeignKeySchema } from '../../type/migration.js';
10
- /**
11
- * Foreign key reference options.
12
- */
13
- export interface ReferenceOptions {
14
- /** Referenced table */
15
- table: string;
16
- /** Referenced column (default: 'id') */
17
- column?: string;
18
- /** Action on delete */
19
- onDelete?: ForeignKeyAction;
20
- /** Action on update */
21
- onUpdate?: ForeignKeyAction;
22
- }
23
- /**
24
- * Base options for all column types.
25
- * Columns are NOT NULL by default (safer).
26
- */
27
- export interface BaseColumnOptions {
28
- /** Whether the column is nullable (default: false) */
29
- nullable?: boolean;
30
- /** Whether this column has a unique constraint */
31
- unique?: boolean;
32
- /** Set as primary key */
33
- primaryKey?: boolean;
34
- /** Enable auto-increment (for integer types) */
35
- autoIncrement?: boolean;
36
- /** Default value or expression */
37
- defaultValue?: unknown;
38
- /** Add an index (true = auto-name, string = custom name) */
39
- index?: boolean | string;
40
- /** Column comment */
41
- comment?: string;
42
- /** Whether the numeric type is unsigned (MySQL/MariaDB) */
43
- unsigned?: boolean;
44
- /** Foreign key reference */
45
- references?: ReferenceOptions;
46
- }
47
- /**
48
- * Options for string/char columns.
49
- */
50
- export interface StringColumnOptions extends BaseColumnOptions {
51
- /** Maximum length (default: 255 for string, 1 for char) */
52
- length?: number;
53
- }
54
- /**
55
- * Options for decimal columns.
56
- */
57
- export interface DecimalColumnOptions extends BaseColumnOptions {
58
- /** Total digits */
59
- precision?: number;
60
- /** Digits after decimal point */
61
- scale?: number;
62
- }
63
- /**
64
- * Options for vector columns (AI embeddings).
65
- */
66
- export interface VectorColumnOptions extends BaseColumnOptions {
67
- /** Number of dimensions */
68
- dimensions?: number;
69
- }
70
- /** A column as the builder describes one: a {@link ColumnNode} without its graph links. */
71
4
  export type ColumnDefinition = Except<ColumnNode, 'table'>;
72
5
  /**
73
6
  * The foreign key a single column declares: {@link ForeignKeySchema} without the local columns, which
@@ -87,13 +20,13 @@ export interface FullColumnDefinition extends ColumnDefinition {
87
20
  index?: string | boolean;
88
21
  }
89
22
  /**
90
- * An index as the builder records it, with the entries and options `@Index` takes: its SQL kept as `raw`
23
+ * An index as the builder records it, with the entries and options an entity's `indexes` entry takes: its SQL kept as `raw`
91
24
  * until a generator renders it for the engine the migration runs on.
92
25
  */
93
26
  export type IndexDefinition = Except<IndexSchema, 'name' | 'entries' | 'where'> & {
94
27
  /** As declared; an unnamed index is named when it is rendered, from its predicate as written. */
95
28
  readonly name?: string;
96
- readonly entries: readonly EntityIndexColumn[];
29
+ readonly entries: readonly IndexEntry[];
97
30
  readonly where?: QuerySql;
98
31
  /** Whether an unnamed index takes the `_uk` kind. Only `table.unique` sets it: earlier migrations installed `_uk` there, so `index` keeps `_idx`. */
99
32
  readonly uniqueName?: boolean;
@@ -169,104 +102,72 @@ export type AnyMigrationOperation = {
169
102
  export type ForeignKeyTarget = ForeignKeySchema['references'];
170
103
  /** A foreign key's constraint name and actions, each the engine's default where unstated. */
171
104
  export type ForeignKeyOptions = Pick<ForeignKeySchema, 'name' | 'onDelete' | 'onUpdate'>;
172
- /**
173
- * Interface for column builder (fluent API).
174
- */
175
- export interface ColumnBuilder {
176
- /** Make column nullable */
177
- nullable(value?: boolean): this;
178
- /** Make column NOT NULL (convenience method) */
179
- notNullable(): this;
180
- /** Set default value */
181
- defaultValue(value: unknown): this;
182
- /** Set as primary key */
183
- primaryKey(): this;
184
- /** Enable auto-increment */
105
+ /** A table's column, in an entity column's vocabulary: `table.string('email').length(80).nullable()`. */
106
+ export interface TableColumnBuilder {
107
+ /** Lets the column hold `null`: a column is `NOT NULL` otherwise, as an entity's is. */
108
+ nullable(): this;
109
+ /** The column's DDL default: a value, or SQL the database evaluates per row (`currentTimestamp`, `sql`). */
110
+ default(value: FieldOptions['defaultValue']): this;
111
+ /** Makes it the primary key. */
112
+ id(): this;
185
113
  autoIncrement(): this;
186
- /** Add unique constraint */
187
114
  unique(): this;
188
- /** Constrain the column to these values, as a `CHECK (col IN (...))`. */
115
+ /** A string column's length. */
116
+ length(length: number): this;
117
+ /** A decimal's digits, or a timestamp's fractional-second digits. */
118
+ precision(digits: number): this;
119
+ scale(digits: number): this;
189
120
  enum(values: EnumValues): this;
190
- /** Make the column one the database computes, as `GENERATED ALWAYS AS (<sql>) STORED`. */
191
- computed(sql: string): this;
192
- /** Add comment */
121
+ /** A column the database computes, `GENERATED ALWAYS AS (<sql>) STORED`, its SQL as text. */
122
+ as(sql: string): this;
193
123
  comment(text: string): this;
194
- /** Add index */
195
124
  index(name?: string): this;
196
- /** Set as unsigned (MySQL/MariaDB) */
197
125
  unsigned(): this;
198
- /** Add foreign key reference */
199
126
  references(table: string, column?: string): ForeignKeyBuilder;
200
- /** Get the built column definition */
201
127
  build(): FullColumnDefinition;
202
128
  }
203
- /**
204
- * Interface for foreign key builder.
205
- */
206
- export interface ForeignKeyBuilder extends ColumnBuilder {
129
+ export interface ForeignKeyBuilder extends TableColumnBuilder {
207
130
  /** Set ON DELETE action */
208
131
  onDelete(action: ForeignKeyAction): this;
209
132
  /** Set ON UPDATE action */
210
133
  onUpdate(action: ForeignKeyAction): this;
211
134
  }
212
- /** Every column type the builder can declare, name first, handed to `addColumn`/`alterColumn` callbacks too. */
213
- export interface ColumnFactory {
214
- /** Add an auto-incrementing primary key */
215
- id(name?: string, options?: BaseColumnOptions): ColumnBuilder;
216
- /** Add an integer column */
217
- integer(name: string, options?: BaseColumnOptions): ColumnBuilder;
218
- /** Add a smallint column */
219
- smallint(name: string, options?: BaseColumnOptions): ColumnBuilder;
220
- /** Add a bigint column */
221
- bigint(name: string, options?: BaseColumnOptions): ColumnBuilder;
222
- /** Add a float column */
223
- float(name: string, options?: BaseColumnOptions): ColumnBuilder;
224
- /** Add a double column */
225
- double(name: string, options?: BaseColumnOptions): ColumnBuilder;
226
- /** Add a decimal column */
227
- decimal(name: string, options?: DecimalColumnOptions): ColumnBuilder;
228
- /** Add a varchar column */
229
- string(name: string, options?: StringColumnOptions): ColumnBuilder;
230
- /** Add a char column */
231
- char(name: string, options?: StringColumnOptions): ColumnBuilder;
232
- /** Add a text column */
233
- text(name: string, options?: BaseColumnOptions): ColumnBuilder;
234
- /** Add a boolean column */
235
- boolean(name: string, options?: BaseColumnOptions): ColumnBuilder;
236
- /** Add a date column */
237
- date(name: string, options?: BaseColumnOptions): ColumnBuilder;
238
- /** Add a time column */
239
- time(name: string, options?: BaseColumnOptions): ColumnBuilder;
240
- /** Add a timestamp column */
241
- timestamp(name: string, options?: BaseColumnOptions): ColumnBuilder;
242
- /** Add a timestamptz column */
243
- timestamptz(name: string, options?: BaseColumnOptions): ColumnBuilder;
244
- /** Add a JSON column */
245
- json(name: string, options?: BaseColumnOptions): ColumnBuilder;
246
- /** Add a JSONB column (Postgres) */
247
- jsonb(name: string, options?: BaseColumnOptions): ColumnBuilder;
248
- /** Add a UUID column */
249
- uuid(name: string, options?: BaseColumnOptions): ColumnBuilder;
250
- /** Add a blob/bytea column */
251
- blob(name: string, options?: BaseColumnOptions): ColumnBuilder;
252
- /** Add a vector column (for embeddings) */
253
- vector(name: string, options?: VectorColumnOptions): ColumnBuilder;
135
+ /** Every column type a table declares, name first, handed to `addColumn`/`alterColumn` callbacks too. */
136
+ export interface TableColumnFactory {
137
+ id(name?: string): TableColumnBuilder;
138
+ integer(name: string): TableColumnBuilder;
139
+ smallint(name: string): TableColumnBuilder;
140
+ bigint(name: string): TableColumnBuilder;
141
+ float(name: string): TableColumnBuilder;
142
+ double(name: string): TableColumnBuilder;
143
+ decimal(name: string, precision?: number, scale?: number): TableColumnBuilder;
144
+ /** A `VARCHAR`, 255 long unless `length()` says otherwise. */
145
+ string(name: string): TableColumnBuilder;
146
+ char(name: string): TableColumnBuilder;
147
+ text(name: string): TableColumnBuilder;
148
+ boolean(name: string): TableColumnBuilder;
149
+ date(name: string): TableColumnBuilder;
150
+ time(name: string): TableColumnBuilder;
151
+ timestamp(name: string): TableColumnBuilder;
152
+ timestamptz(name: string): TableColumnBuilder;
153
+ json(name: string): TableColumnBuilder;
154
+ jsonb(name: string): TableColumnBuilder;
155
+ uuid(name: string): TableColumnBuilder;
156
+ blob(name: string): TableColumnBuilder;
157
+ vector(name: string, dimensions?: number): TableColumnBuilder;
254
158
  }
255
- /**
256
- * Interface for table builder (fluent API).
257
- */
258
- export interface TableBuilder extends ColumnFactory {
159
+ export interface TableBuilder extends TableColumnFactory {
259
160
  /** Add createdAt timestamp column */
260
- createdAt(): ColumnBuilder;
161
+ createdAt(): TableColumnBuilder;
261
162
  /** Add updatedAt timestamp column */
262
- updatedAt(): ColumnBuilder;
163
+ updatedAt(): TableColumnBuilder;
263
164
  /** Add both createdAt and updatedAt columns */
264
165
  timestamps(): void;
265
166
  /** Add composite primary key */
266
167
  primaryKey(columns: string[]): this;
267
- /** Add a composite unique index; takes the same options as `@Index`, or just its name. */
168
+ /** Add a composite unique index; takes the same options as an `indexes` entry, or just its name. */
268
169
  unique(columns: readonly IndexColumnInput[], options?: string | IndexOptions): this;
269
- /** Add a composite index; takes the same options as `@Index`, or just its name. */
170
+ /** Add a composite index; takes the same options as an `indexes` entry, or just its name. */
270
171
  index(columns: readonly IndexColumnInput[], options?: string | IndexOptions): this;
271
172
  /** Add table-level foreign key */
272
173
  foreignKey(columns: string[]): TableForeignKeyBuilder;
@@ -293,13 +194,13 @@ export interface TableForeignKeyBuilder {
293
194
  */
294
195
  export interface AlterTableBuilder {
295
196
  /** Add a column, declared exactly as in `createTable`: `addColumn((c) => c.timestamp('createdAt'))`. */
296
- addColumn(callback: (columns: ColumnFactory) => ColumnBuilder): this;
197
+ addColumn(callback: (columns: TableColumnFactory) => TableColumnBuilder): this;
297
198
  /** Drop a column from the table */
298
199
  dropColumn(name: string): this;
299
200
  /** Rename a column */
300
201
  renameColumn(oldName: string, newName: string): this;
301
202
  /** Redeclare a column, named and typed as it should end up. */
302
- alterColumn(callback: (columns: ColumnFactory) => ColumnBuilder): this;
203
+ alterColumn(callback: (columns: TableColumnFactory) => TableColumnBuilder): this;
303
204
  /** Add an index to the table */
304
205
  addIndex(columns: readonly IndexColumnInput[], options?: IndexOptions): this;
305
206
  /** Drop an index from the table */
@@ -325,14 +226,14 @@ export interface MigrationBuilder {
325
226
  /** Alter an existing table */
326
227
  alterTable(name: string, callback: (table: AlterTableBuilder) => void): Promise<void>;
327
228
  /** Add a column, declared exactly as in `createTable`: `addColumn('t', (c) => c.timestamp('at'))`. */
328
- addColumn(tableName: string, callback: (columns: ColumnFactory) => ColumnBuilder): Promise<void>;
229
+ addColumn(tableName: string, callback: (columns: TableColumnFactory) => TableColumnBuilder): Promise<void>;
329
230
  /** Drop a column from a table */
330
231
  dropColumn(tableName: string, columnName: string): Promise<void>;
331
232
  /** Redeclare a column, named and typed as it should end up. */
332
- alterColumn(tableName: string, callback: (columns: ColumnFactory) => ColumnBuilder): Promise<void>;
233
+ alterColumn(tableName: string, callback: (columns: TableColumnFactory) => TableColumnBuilder): Promise<void>;
333
234
  /** Rename a column */
334
235
  renameColumn(tableName: string, oldName: string, newName: string): Promise<void>;
335
- /** Create an index; takes the same options as `@Index`, so a generated migration can restate them. */
236
+ /** Create an index; takes the same options as an `indexes` entry, so a generated migration can restate them. */
336
237
  createIndex(tableName: string, columns: readonly IndexColumnInput[], options?: IndexOptions): Promise<void>;
337
238
  /** Drop an index */
338
239
  dropIndex(tableName: string, indexName: string): Promise<void>;
@@ -1,7 +1 @@
1
- /**
2
- * Migration Builder Types
3
- *
4
- * Type definitions for the fluent migration builder API.
5
- * Enables type-safe migrations without raw SQL.
6
- */
7
1
  export {};
@@ -44,7 +44,7 @@ export declare class EntityCodeGenerator {
44
44
  generateForTable(tableName: string): GeneratedEntity | undefined;
45
45
  private generateEntity;
46
46
  private buildImports;
47
- private buildEntityDecorators;
47
+ private buildEntityDecorator;
48
48
  private buildFields;
49
49
  /** The `@sync-added` JSDoc a generated member opens with, saying `what` it is, where asked for. */
50
50
  private syncDoc;
@@ -56,7 +56,7 @@ export declare class EntityCodeGenerator {
56
56
  private buildField;
57
57
  private buildFieldOptions;
58
58
  /**
59
- * The indexes this table needs an `@Index` for, which is every one a `@Field({ index })` cannot
59
+ * The indexes this table lists under `indexes`, which is every one a `.index()` cannot
60
60
  * carry on its own.
61
61
  */
62
62
  private declaredIndexes;