arkormx 2.0.0-next.15 → 2.0.0-next.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -149,10 +149,13 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
149
149
  resolveSchemaForeignKeyName(table, foreignKey) {
150
150
  return `${table}_${foreignKey.column}_fkey`;
151
151
  }
152
- resolveSchemaColumnType(column) {
152
+ resolveSchemaEnumName(table, column) {
153
+ return column.enumName ?? `${table}_${column.name}_enum`;
154
+ }
155
+ resolveSchemaColumnType(table, column) {
153
156
  if (column.type === "id") return "integer";
154
157
  if (column.type === "uuid") return "uuid";
155
- if (column.type === "enum") return this.quoteIdentifier(column.enumName ?? `${column.name}_enum`);
158
+ if (column.type === "enum") return this.quoteIdentifier(this.resolveSchemaEnumName(table, column));
156
159
  if (column.type === "string") return "varchar(255)";
157
160
  if (column.type === "text") return "text";
158
161
  if (column.type === "integer") return "integer";
@@ -175,8 +178,8 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
175
178
  if (column.type === "id") return column.default === void 0;
176
179
  return column.autoIncrement === true;
177
180
  }
178
- buildSchemaColumnDefinition(column) {
179
- const parts = [this.quoteIdentifier(column.map ?? column.name), this.resolveSchemaColumnType(column)];
181
+ buildSchemaColumnDefinition(table, column) {
182
+ const parts = [this.quoteIdentifier(column.map ?? column.name), this.resolveSchemaColumnType(table, column)];
180
183
  if (this.shouldUseIdentity(column)) parts.push("generated by default as identity");
181
184
  const defaultValue = this.resolveSchemaColumnDefault(column);
182
185
  if (defaultValue && !this.shouldUseIdentity(column)) parts.push(`default ${defaultValue}`);
@@ -195,10 +198,10 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
195
198
  const mappedColumns = index.columns.map((column) => this.quoteIdentifier(this.resolveSchemaColumnName(column, columns))).join(", ");
196
199
  return `create index if not exists ${this.quoteIdentifier(this.resolveSchemaIndexName(table, index))} on ${this.quoteIdentifier(table)} (${mappedColumns})`;
197
200
  }
198
- async ensureEnumTypes(columns, executor = this.db) {
201
+ async ensureEnumTypes(table, columns, executor = this.db) {
199
202
  for (const column of columns) {
200
203
  if (column.type !== "enum") continue;
201
- const enumName = column.enumName ?? `${column.name}_enum`;
204
+ const enumName = this.resolveSchemaEnumName(table, column);
202
205
  if ((await kysely.sql`
203
206
  select exists(
204
207
  select 1
@@ -213,8 +216,8 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
213
216
  }
214
217
  async executeCreateTableOperation(operation, executor) {
215
218
  const table = this.resolveMappedTable(operation.table);
216
- await this.ensureEnumTypes(operation.columns, executor);
217
- const columnDefinitions = operation.columns.map((column) => this.buildSchemaColumnDefinition(column));
219
+ await this.ensureEnumTypes(table, operation.columns, executor);
220
+ const columnDefinitions = operation.columns.map((column) => this.buildSchemaColumnDefinition(table, column));
218
221
  const foreignKeys = (operation.foreignKeys ?? []).map((foreignKey) => this.buildSchemaForeignKeyConstraint(table, foreignKey, operation.columns));
219
222
  const definitions = [...columnDefinitions, ...foreignKeys].join(", ");
220
223
  await this.executeRawStatement(`create table if not exists ${this.quoteIdentifier(table)} (${definitions})`, executor);
@@ -222,8 +225,8 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
222
225
  }
223
226
  async executeAlterTableOperation(operation, executor) {
224
227
  const table = this.resolveMappedTable(operation.table);
225
- await this.ensureEnumTypes(operation.addColumns, executor);
226
- for (const column of operation.addColumns) await this.executeRawStatement(`alter table ${this.quoteIdentifier(table)} add column if not exists ${this.buildSchemaColumnDefinition(column)}`, executor);
228
+ await this.ensureEnumTypes(table, operation.addColumns, executor);
229
+ for (const column of operation.addColumns) await this.executeRawStatement(`alter table ${this.quoteIdentifier(table)} add column if not exists ${this.buildSchemaColumnDefinition(table, column)}`, executor);
227
230
  for (const column of operation.dropColumns) await this.executeRawStatement(`alter table ${this.quoteIdentifier(table)} drop column if exists ${this.quoteIdentifier(column)}`, executor);
228
231
  for (const foreignKey of operation.addForeignKeys ?? []) await this.executeRawStatement(`alter table ${this.quoteIdentifier(table)} add ${this.buildSchemaForeignKeyConstraint(table, foreignKey, operation.addColumns)}`, executor);
229
232
  for (const index of operation.addIndexes ?? []) await this.executeRawStatement(this.buildSchemaIndexStatement(table, index, operation.addColumns), executor);
package/dist/index.d.cts CHANGED
@@ -2849,6 +2849,7 @@ declare class KyselyDatabaseAdapter implements DatabaseAdapter {
2849
2849
  private resolveSchemaColumnName;
2850
2850
  private resolveSchemaIndexName;
2851
2851
  private resolveSchemaForeignKeyName;
2852
+ private resolveSchemaEnumName;
2852
2853
  private resolveSchemaColumnType;
2853
2854
  private resolveSchemaColumnDefault;
2854
2855
  private shouldUseIdentity;
package/dist/index.d.mts CHANGED
@@ -2849,6 +2849,7 @@ declare class KyselyDatabaseAdapter implements DatabaseAdapter {
2849
2849
  private resolveSchemaColumnName;
2850
2850
  private resolveSchemaIndexName;
2851
2851
  private resolveSchemaForeignKeyName;
2852
+ private resolveSchemaEnumName;
2852
2853
  private resolveSchemaColumnType;
2853
2854
  private resolveSchemaColumnDefault;
2854
2855
  private shouldUseIdentity;
package/dist/index.mjs CHANGED
@@ -120,10 +120,13 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
120
120
  resolveSchemaForeignKeyName(table, foreignKey) {
121
121
  return `${table}_${foreignKey.column}_fkey`;
122
122
  }
123
- resolveSchemaColumnType(column) {
123
+ resolveSchemaEnumName(table, column) {
124
+ return column.enumName ?? `${table}_${column.name}_enum`;
125
+ }
126
+ resolveSchemaColumnType(table, column) {
124
127
  if (column.type === "id") return "integer";
125
128
  if (column.type === "uuid") return "uuid";
126
- if (column.type === "enum") return this.quoteIdentifier(column.enumName ?? `${column.name}_enum`);
129
+ if (column.type === "enum") return this.quoteIdentifier(this.resolveSchemaEnumName(table, column));
127
130
  if (column.type === "string") return "varchar(255)";
128
131
  if (column.type === "text") return "text";
129
132
  if (column.type === "integer") return "integer";
@@ -146,8 +149,8 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
146
149
  if (column.type === "id") return column.default === void 0;
147
150
  return column.autoIncrement === true;
148
151
  }
149
- buildSchemaColumnDefinition(column) {
150
- const parts = [this.quoteIdentifier(column.map ?? column.name), this.resolveSchemaColumnType(column)];
152
+ buildSchemaColumnDefinition(table, column) {
153
+ const parts = [this.quoteIdentifier(column.map ?? column.name), this.resolveSchemaColumnType(table, column)];
151
154
  if (this.shouldUseIdentity(column)) parts.push("generated by default as identity");
152
155
  const defaultValue = this.resolveSchemaColumnDefault(column);
153
156
  if (defaultValue && !this.shouldUseIdentity(column)) parts.push(`default ${defaultValue}`);
@@ -166,10 +169,10 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
166
169
  const mappedColumns = index.columns.map((column) => this.quoteIdentifier(this.resolveSchemaColumnName(column, columns))).join(", ");
167
170
  return `create index if not exists ${this.quoteIdentifier(this.resolveSchemaIndexName(table, index))} on ${this.quoteIdentifier(table)} (${mappedColumns})`;
168
171
  }
169
- async ensureEnumTypes(columns, executor = this.db) {
172
+ async ensureEnumTypes(table, columns, executor = this.db) {
170
173
  for (const column of columns) {
171
174
  if (column.type !== "enum") continue;
172
- const enumName = column.enumName ?? `${column.name}_enum`;
175
+ const enumName = this.resolveSchemaEnumName(table, column);
173
176
  if ((await sql`
174
177
  select exists(
175
178
  select 1
@@ -184,8 +187,8 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
184
187
  }
185
188
  async executeCreateTableOperation(operation, executor) {
186
189
  const table = this.resolveMappedTable(operation.table);
187
- await this.ensureEnumTypes(operation.columns, executor);
188
- const columnDefinitions = operation.columns.map((column) => this.buildSchemaColumnDefinition(column));
190
+ await this.ensureEnumTypes(table, operation.columns, executor);
191
+ const columnDefinitions = operation.columns.map((column) => this.buildSchemaColumnDefinition(table, column));
189
192
  const foreignKeys = (operation.foreignKeys ?? []).map((foreignKey) => this.buildSchemaForeignKeyConstraint(table, foreignKey, operation.columns));
190
193
  const definitions = [...columnDefinitions, ...foreignKeys].join(", ");
191
194
  await this.executeRawStatement(`create table if not exists ${this.quoteIdentifier(table)} (${definitions})`, executor);
@@ -193,8 +196,8 @@ var KyselyDatabaseAdapter = class KyselyDatabaseAdapter {
193
196
  }
194
197
  async executeAlterTableOperation(operation, executor) {
195
198
  const table = this.resolveMappedTable(operation.table);
196
- await this.ensureEnumTypes(operation.addColumns, executor);
197
- for (const column of operation.addColumns) await this.executeRawStatement(`alter table ${this.quoteIdentifier(table)} add column if not exists ${this.buildSchemaColumnDefinition(column)}`, executor);
199
+ await this.ensureEnumTypes(table, operation.addColumns, executor);
200
+ for (const column of operation.addColumns) await this.executeRawStatement(`alter table ${this.quoteIdentifier(table)} add column if not exists ${this.buildSchemaColumnDefinition(table, column)}`, executor);
198
201
  for (const column of operation.dropColumns) await this.executeRawStatement(`alter table ${this.quoteIdentifier(table)} drop column if exists ${this.quoteIdentifier(column)}`, executor);
199
202
  for (const foreignKey of operation.addForeignKeys ?? []) await this.executeRawStatement(`alter table ${this.quoteIdentifier(table)} add ${this.buildSchemaForeignKeyConstraint(table, foreignKey, operation.addColumns)}`, executor);
200
203
  for (const index of operation.addIndexes ?? []) await this.executeRawStatement(this.buildSchemaIndexStatement(table, index, operation.addColumns), executor);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arkormx",
3
- "version": "2.0.0-next.15",
3
+ "version": "2.0.0-next.16",
4
4
  "description": "Modern TypeScript-first ORM for Node.js.",
5
5
  "keywords": [
6
6
  "orm",