@stacksjs/orm 0.75.635 → 0.75.636
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.
|
@@ -25,6 +25,6 @@ export interface FrameworkSchema {
|
|
|
25
25
|
`;const FRAMEWORK_FOOTER=`}
|
|
26
26
|
`;function headerFor(target){return target==="framework"?FRAMEWORK_HEADER:APP_HEADER}function footerFor(target){return target==="framework"?FRAMEWORK_FOOTER:APP_FOOTER}async function loadModelsFrom(dir,recursive,failures=[]){const out=[];if(!fs.existsSync(dir))return out;const entries=fs.readdirSync(dir,{withFileTypes:true});for(const entry of entries){const fullPath=path.join(dir,entry.name);if(entry.isDirectory()){if(recursive){const sub=await loadModelsFrom(fullPath,true,failures);out.push(...sub)}continue}if(!entry.name.endsWith(".ts"))continue;if(entry.name.startsWith("_")||entry.name.startsWith("index"))continue;try{const module=await(path.isAbsolute(fullPath)?import(fullPath):import(path.resolve(fullPath)));const def=module.default||module;if(def?.name&&(def.attributes||def.table)){out.push({filePath:fullPath,model:def})}}catch(err){failures.push({file:fullPath,error:err.message})}}return out}export async function buildDatabaseSchema(options={}){const dialect=resolveDialect(options.dialect);const modelsDir=options.modelsDir??path.userModelsPath();const defaultsDir=options.defaultsDir??path.frameworkPath("defaults/app/Models");const outFile=options.outFile??path.projectPath("database/types.d.ts");const errors=[];const allModels=[];for(const[dir,recursive]of[[modelsDir,false],[defaultsDir,true]]){try{const found=await loadModelsFrom(dir,recursive,errors);allModels.push(...found)}catch(err){errors.push({file:dir,error:err.message})}}const byName=new Map;for(const item of allModels){byName.set(item.model.name??path.basename(item.filePath).replace(/\.ts$/,""),item)}for(const item of allModels){if(item.filePath.startsWith(modelsDir)){byName.set(item.model.name??path.basename(item.filePath).replace(/\.ts$/,""),item)}}const tables=[];for(const[name,{model}]of byName){const tableName=model.table??`${snakeCase(name)}s`;const columns={...deriveSystemColumns(model,dialect),...deriveAttributeColumns(model,dialect),...deriveFkColumns(model)};tables.push({table:tableName,model:name,columns})}const pivotByTable=new Map;for(const[name,{model}]of byName){for(const pivot of derivePivotTables(name,model,dialect)){if(pivotByTable.has(pivot.table))continue;pivotByTable.set(pivot.table,{table:pivot.table,model:`(${pivot.table} pivot)`,columns:pivot.columns})}}tables.push(...pivotByTable.values());if(options.migrationsDir!==false){const migrationsDir=options.migrationsDir??path.resolve(path.dirname(outFile),"migrations");const owned=new Set(tables.map((entry)=>entry.table));const derived=deriveMigrationTables(migrationsDir,dialect);for(const entry of derived.tables){if(owned.has(entry.table))continue;owned.add(entry.table);tables.push({table:entry.table,model:`(${entry.table} migration)`,columns:entry.columns})}errors.push(...derived.errors)}tables.sort((a,b)=>a.table.localeCompare(b.table));const target=options.target??"app";const indent=target==="framework"?1:2;const body=tables.map((t)=>renderTableEntry(t.table,t.columns,indent)).join(`
|
|
27
27
|
`);const content=`${headerFor(target)}${body}
|
|
28
|
-
${footerFor(target)}`;if(!options.dryRun){const dir=path.dirname(outFile);if(!fs.existsSync(dir))fs.mkdirSync(dir,{recursive:true});fs.writeFileSync(outFile,content,"utf-8");log.success(`[generate:db-types] wrote ${tables.length} table(s) to ${outFile}`)}return{outFile,tables,errors,content}}export function renderDatabaseTypeFile(tables,target="app"){const body=[...tables].sort((a,b)=>a.table.localeCompare(b.table)).map((t)=>renderTableEntry(t.table,t.columns,target==="framework"?1:2)).join(`
|
|
28
|
+
${footerFor(target)}`;if(!options.dryRun&&(!options.strict||errors.length===0)&&await Bun.file(outFile).text().catch(()=>{return})!==content){const dir=path.dirname(outFile);if(!fs.existsSync(dir))fs.mkdirSync(dir,{recursive:true});fs.writeFileSync(outFile,content,"utf-8");log.success(`[generate:db-types] wrote ${tables.length} table(s) to ${outFile}`)}return{outFile,tables,errors,content}}export function renderDatabaseTypeFile(tables,target="app"){const body=[...tables].sort((a,b)=>a.table.localeCompare(b.table)).map((t)=>renderTableEntry(t.table,t.columns,target==="framework"?1:2)).join(`
|
|
29
29
|
`);return`${headerFor(target)}${body}
|
|
30
30
|
${footerFor(target)}`}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/orm",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.636",
|
|
6
6
|
"description": "The Stacks ORM integration",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -63,32 +63,32 @@
|
|
|
63
63
|
"prepublishOnly": "bun run build"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@stacksjs/cache": "0.75.
|
|
67
|
-
"@stacksjs/cli": "0.75.
|
|
68
|
-
"@stacksjs/config": "0.75.
|
|
69
|
-
"@stacksjs/database": "0.75.
|
|
70
|
-
"@stacksjs/env": "0.75.
|
|
71
|
-
"@stacksjs/error-handling": "0.75.
|
|
72
|
-
"@stacksjs/events": "0.75.
|
|
73
|
-
"@stacksjs/logging": "0.75.
|
|
74
|
-
"@stacksjs/model-meta": "0.75.
|
|
75
|
-
"@stacksjs/pagination": "0.75.
|
|
76
|
-
"@stacksjs/path": "0.75.
|
|
77
|
-
"@stacksjs/query-builder": "0.75.
|
|
78
|
-
"@stacksjs/realtime": "0.75.
|
|
79
|
-
"@stacksjs/router": "0.75.
|
|
80
|
-
"@stacksjs/storage": "0.75.
|
|
81
|
-
"@stacksjs/strings": "0.75.
|
|
66
|
+
"@stacksjs/cache": "0.75.636",
|
|
67
|
+
"@stacksjs/cli": "0.75.636",
|
|
68
|
+
"@stacksjs/config": "0.75.636",
|
|
69
|
+
"@stacksjs/database": "0.75.636",
|
|
70
|
+
"@stacksjs/env": "0.75.636",
|
|
71
|
+
"@stacksjs/error-handling": "0.75.636",
|
|
72
|
+
"@stacksjs/events": "0.75.636",
|
|
73
|
+
"@stacksjs/logging": "0.75.636",
|
|
74
|
+
"@stacksjs/model-meta": "0.75.636",
|
|
75
|
+
"@stacksjs/pagination": "0.75.636",
|
|
76
|
+
"@stacksjs/path": "0.75.636",
|
|
77
|
+
"@stacksjs/query-builder": "0.75.636",
|
|
78
|
+
"@stacksjs/realtime": "0.75.636",
|
|
79
|
+
"@stacksjs/router": "0.75.636",
|
|
80
|
+
"@stacksjs/storage": "0.75.636",
|
|
81
|
+
"@stacksjs/strings": "0.75.636",
|
|
82
82
|
"@stacksjs/ts-validation": "^0.5.7",
|
|
83
|
-
"@stacksjs/validation": "0.75.
|
|
83
|
+
"@stacksjs/validation": "0.75.636",
|
|
84
84
|
"bun-query-builder": "^0.6.4",
|
|
85
85
|
"stripe": "23.0.0"
|
|
86
86
|
},
|
|
87
87
|
"peerDependencies": {
|
|
88
|
-
"@stacksjs/auth": "0.75.
|
|
89
|
-
"@stacksjs/payments": "0.75.
|
|
90
|
-
"@stacksjs/queue": "0.75.
|
|
91
|
-
"@stacksjs/search-engine": "0.75.
|
|
88
|
+
"@stacksjs/auth": "0.75.636",
|
|
89
|
+
"@stacksjs/payments": "0.75.636",
|
|
90
|
+
"@stacksjs/queue": "0.75.636",
|
|
91
|
+
"@stacksjs/search-engine": "0.75.636"
|
|
92
92
|
},
|
|
93
93
|
"peerDependenciesMeta": {
|
|
94
94
|
"@stacksjs/auth": {
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
}
|
|
103
103
|
},
|
|
104
104
|
"devDependencies": {
|
|
105
|
-
"@stacksjs/types": "0.75.
|
|
105
|
+
"@stacksjs/types": "0.75.636",
|
|
106
106
|
"better-dx": "^0.2.39"
|
|
107
107
|
}
|
|
108
108
|
}
|