nucleus-core-ts 0.9.130 → 0.9.131
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/package.json +1 -1
- package/scripts/generate-schema.ts +10 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nucleus-core-ts",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.131",
|
|
4
4
|
"description": "Production-ready, enterprise-grade TypeScript framework for building multi-tenant APIs",
|
|
5
5
|
"author": "Hidayet Can Özcan <hidayetcan@gmail.com>",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -223,7 +223,7 @@ function generateColumnCode(col: Column, allTables: string[], currentTable?: str
|
|
|
223
223
|
return code
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
function generateTableCode(table: TableDef, allTables: string[]): string {
|
|
226
|
+
function generateTableCode(table: TableDef, allTables: string[], allTableDefs: TableDef[]): string {
|
|
227
227
|
const tableName = toCamelCase(table.table_name)
|
|
228
228
|
const TableName = tableName.charAt(0).toUpperCase() + tableName.slice(1)
|
|
229
229
|
const columns = table.add_base_columns
|
|
@@ -297,7 +297,14 @@ function generateTableCode(table: TableDef, allTables: string[]): string {
|
|
|
297
297
|
const uniqueRefTables = [...new Set(externalRefs.map((r) => r.refTable))]
|
|
298
298
|
for (const refTable of uniqueRefTables) {
|
|
299
299
|
const refTableName = toCamelCase(refTable)
|
|
300
|
-
|
|
300
|
+
const refTableDef = allTableDefs.find((t) => t.table_name === refTable)
|
|
301
|
+
const refVectorCols = new Set((refTableDef?.columns || []).filter((c) => c.type === 'vector').map((c) => c.name))
|
|
302
|
+
const refHasIndexes = (refTableDef?.indexes || []).some((idx) => !idx.columns.some((c) => refVectorCols.has(c)))
|
|
303
|
+
if (refHasIndexes) {
|
|
304
|
+
code += `\tconst ${refTableName}Table = schema.table('${refTable}', ${refTableName}Columns, (t) => ${refTableName}Indexes(t));\n`
|
|
305
|
+
} else {
|
|
306
|
+
code += `\tconst ${refTableName}Table = schema.table('${refTable}', ${refTableName}Columns);\n`
|
|
307
|
+
}
|
|
301
308
|
}
|
|
302
309
|
}
|
|
303
310
|
|
|
@@ -375,7 +382,7 @@ function generateSchemaFile(tables: TableDef[]): string {
|
|
|
375
382
|
code += `import { sql } from 'drizzle-orm';\n\n`
|
|
376
383
|
|
|
377
384
|
for (const table of tables) {
|
|
378
|
-
code += generateTableCode(table, allTableNames)
|
|
385
|
+
code += generateTableCode(table, allTableNames, tables)
|
|
379
386
|
code += '\n'
|
|
380
387
|
}
|
|
381
388
|
|