@@ -95,10 +95,8 @@ async function generateApiRoutes(modelFiles: string[]) {
95
95
}
96
96
97
97
async function lookupFile ( fileName : string ) : Promise < string | null > {
98
- const ormDirectory = path . projectStoragePath ( 'framework/orm/Actions' )
99
-
98
+ const ormDirectory = path . builtUserActionsPath ( )
100
99
const filePath = path . join ( ormDirectory , fileName )
101
-
102
100
const pathExists = await fs . existsSync ( filePath )
103
101
104
102
// Check if the directory exists
@@ -107,9 +105,7 @@ async function lookupFile(fileName: string): Promise<string | null> {
107
105
}
108
106
109
107
const actionDirectory = path . userActionsPath ( )
110
-
111
108
const actionFilePath = path . join ( actionDirectory , fileName )
112
-
113
109
const fileExists = await fs . existsSync ( actionFilePath )
114
110
115
111
if ( fileExists ) {
@@ -121,15 +117,12 @@ async function lookupFile(fileName: string): Promise<string | null> {
121
117
122
118
async function writeModelNames ( ) {
123
119
const modelFiles = glob . sync ( path . userModelsPath ( '*.ts' ) )
124
-
125
120
let fileString = `export type ModelNames = `
126
121
127
122
for ( let i = 0 ; i < modelFiles . length ; i ++ ) {
128
123
const modeFileElement = modelFiles [ i ] as string
129
-
130
124
const model = ( await import ( modeFileElement ) ) . default as Model
131
125
const modelName = getModelName ( model , modeFileElement )
132
-
133
126
const typeFile = Bun . file ( path . corePath ( `types/src/model-names.ts` ) )
134
127
135
128
fileString += `'${ modelName } '`
@@ -146,8 +139,8 @@ async function writeModelNames() {
146
139
147
140
async function writeModelRequest ( ) {
148
141
const modelFiles = glob . sync ( path . userModelsPath ( '*.ts' ) )
149
-
150
142
const requestD = Bun . file ( path . frameworkPath ( 'types/requests.d.ts' ) )
143
+
151
144
let importTypes = ``
152
145
let importTypesString = ``
153
146
let typeString = `import { Request } from '../core/router/src/request'\n\n`
@@ -173,14 +166,10 @@ async function writeModelRequest() {
173
166
let fileString = `import { Request } from '@stacksjs/router'\nimport type { VineType } from '@stacksjs/types'\nimport { validateField } from '@stacksjs/validation'\nimport { customValidate } from '@stacksjs/validation'\n\n`
174
167
175
168
const modeFileElement = modelFiles [ i ] as string
176
-
177
169
const model = ( await import ( modeFileElement ) ) . default as Model
178
170
const modelName = getModelName ( model , modeFileElement )
179
-
180
171
const useTimestamps = model ?. traits ?. useTimestamps ?? model ?. traits ?. timestampable ?? true
181
-
182
172
const useSoftDeletes = model ?. traits ?. useSoftDeletes ?? model ?. traits ?. softDeletable ?? false
183
-
184
173
const attributes = await extractFields ( model , modeFileElement )
185
174
186
175
fieldString += ` id?: number\n`
@@ -192,20 +181,18 @@ async function writeModelRequest() {
192
181
const otherModelRelations = await fetchOtherModelRelations ( model , modelName )
193
182
194
183
for ( const attribute of attributes ) {
195
- let defaultValue : any = `''`
196
184
const entity = attribute . fieldArray ?. entity === 'enum' ? 'string[]' : attribute . fieldArray ?. entity
185
+ let defaultValue : any = `''`
197
186
198
187
if ( attribute . fieldArray ?. entity === 'boolean' ) defaultValue = false
199
-
200
188
if ( attribute . fieldArray ?. entity === 'number' ) defaultValue = 0
201
189
202
190
fieldString += ` ${ attribute . field } : ${ entity } \n `
203
-
204
191
fieldStringType += `'${ attribute . field } '`
192
+
205
193
if ( keyCounter < attributes . length - 1 ) fieldStringType += ' |'
206
194
207
195
fieldStringInt += `public ${ attribute . field } = ${ defaultValue } \n`
208
-
209
196
keyCounter ++
210
197
}
211
198
@@ -220,7 +207,6 @@ async function writeModelRequest() {
220
207
// fieldStringType += ' |'
221
208
222
209
fieldStringInt += `public ${ otherModel . foreignKey } = 0\n`
223
-
224
210
keyCounterForeign ++
225
211
}
226
212
@@ -379,7 +365,7 @@ async function writeOrmActions(apiRoute: string, modelName: String): Promise<voi
379
365
})
380
366
`
381
367
382
- const file = Bun . file ( path . frameworkPath ( `orm/Actions/ ${ modelName } ${ formattedApiRoute } OrmAction.ts`) )
368
+ const file = Bun . file ( path . builtUserActionsPath ( ` ${ modelName } ${ formattedApiRoute } OrmAction.ts`) )
383
369
384
370
const writer = file . writer ( )
385
371
@@ -502,14 +488,14 @@ async function deleteExistingOrmActions(modelStringFile?: string) {
502
488
if ( fs . existsSync ( routes ) ) await Bun . $ `rm ${ routes } `
503
489
504
490
if ( modelStringFile ) {
505
- const ormPath = path . frameworkPath ( `orm/Actions/ ${ modelStringFile } .ts`)
491
+ const ormPath = path . builtUserActionsPath ( ` ${ modelStringFile } .ts`)
506
492
507
493
if ( fs . existsSync ( ormPath ) ) await Bun . $ `rm ${ ormPath } `
508
494
509
495
return
510
496
}
511
497
512
- const ormPaths = glob . sync ( path . frameworkPath ( `orm/Actions/ *.ts`) )
498
+ const ormPaths = glob . sync ( path . builtUserActionsPath ( ` *.ts`) )
513
499
514
500
for ( const ormPath of ormPaths ) {
515
501
if ( fs . existsSync ( ormPath ) ) await Bun . $ `rm ${ ormPath } `
0 commit comments