@@ -2,7 +2,6 @@ import { path } from '@stacksjs/path'
22import { fs } from '@stacksjs/storage'
33import { plural , snakeCase } from '@stacksjs/strings'
44import type { Model } from '@stacksjs/types'
5- import { globSync } from 'tinyglobby'
65
76export function getModelName ( model : Model , modelPath : string ) : string {
87 if ( model . name )
@@ -22,26 +21,26 @@ export function getTableName(model: Model, modelPath: string): string {
2221
2322function extractHiddenFields ( model : Model ) : string [ ] {
2423 if ( ! model . attributes ) return [ ]
25-
26- return Object . keys ( model . attributes ) . filter ( key =>
24+
25+ return Object . keys ( model . attributes ) . filter ( key =>
2726 model . attributes ?. [ key ] ?. hidden === true
2827 ) . map ( field => snakeCase ( field ) )
2928}
3029
3130function extractFillableFields ( model : Model ) : string [ ] {
3231 if ( ! model . attributes ) return [ ]
33-
34- const fillable = Object . keys ( model . attributes ) . filter ( key =>
32+
33+ const fillable = Object . keys ( model . attributes ) . filter ( key =>
3534 model . attributes ?. [ key ] ?. fillable === true
3635 ) . map ( field => snakeCase ( field ) )
3736
3837 // Add trait-specific fillable fields
3938 const additionalFields : string [ ] = [ ]
40-
39+
4140 if ( model . traits ?. useUuid ) {
4241 additionalFields . push ( 'uuid' )
4342 }
44-
43+
4544 if ( model . traits ?. useAuth ) {
4645 const useAuth = model . traits . useAuth
4746 if ( typeof useAuth === 'object' && useAuth . usePasskey ) {
@@ -54,8 +53,8 @@ function extractFillableFields(model: Model): string[] {
5453
5554function extractGuardedFields ( model : Model ) : string [ ] {
5655 if ( ! model . attributes ) return [ ]
57-
58- return Object . keys ( model . attributes ) . filter ( key =>
56+
57+ return Object . keys ( model . attributes ) . filter ( key =>
5958 model . attributes ?. [ key ] ?. guarded === true
6059 ) . map ( field => snakeCase ( field ) )
6160}
@@ -145,7 +144,7 @@ class ${modelName}Model {
145144 // Create a new record
146145 static async create(data: Record<string, any>) {
147146 const instance = new ${ modelName } Model()
148-
147+
149148 // Filter based on fillable and guarded
150149 const filteredData = Object.fromEntries(
151150 Object.entries(data).filter(([key]) =>
@@ -211,11 +210,11 @@ class ${modelName}Model {
211210 // Convert to JSON (excluding hidden fields)
212211 toJSON() {
213212 const json = { ...this.attributes }
214-
213+
215214 for (const field of this.hidden) {
216215 delete json[field]
217216 }
218-
217+
219218 return json
220219 }
221220}
@@ -236,15 +235,15 @@ export async function generateOrmModels(): Promise<void> {
236235 const tableName = getTableName ( model , userModelFile )
237236
238237 const modelString = generateOrmModelString ( modelName , tableName , model )
239-
238+
240239 // Ensure the directory exists
241240 const ormModelsDir = path . storagePath ( 'framework/core/db/src/orm/Models' )
242241 await fs . promises . mkdir ( ormModelsDir , { recursive : true } )
243242
244243 // Write the generated model file
245244 const outputPath = path . join ( ormModelsDir , `${ modelName } .ts` )
246245 await fs . promises . writeFile ( outputPath , modelString , 'utf8' )
247-
246+
248247 console . log ( `Generated ORM model: ${ modelName } -> ${ outputPath } ` )
249248 }
250249}
@@ -255,15 +254,15 @@ export async function generateOrmModel(modelPath: string): Promise<void> {
255254 const tableName = getTableName ( model , modelPath )
256255
257256 const modelString = generateOrmModelString ( modelName , tableName , model )
258-
257+
259258 // Ensure the directory exists
260259 const ormModelsDir = path . storagePath ( 'framework/core/db/src/orm/Models' )
261260 await fs . promises . mkdir ( ormModelsDir , { recursive : true } )
262261
263262 // Write the generated model file
264263 const outputPath = path . join ( ormModelsDir , `${ modelName } .ts` )
265264 await fs . promises . writeFile ( outputPath , modelString , 'utf8' )
266-
265+
267266 console . log ( `Generated ORM model: ${ modelName } -> ${ outputPath } ` )
268267}
269268
0 commit comments