Skip to content

Commit 7e2171f

Browse files
committed
chore: wip
1 parent 16038fd commit 7e2171f

File tree

9 files changed

+37
-26
lines changed

9 files changed

+37
-26
lines changed

storage/framework/core/actions/src/orm/generate-model.ts

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,8 @@ async function generateApiRoutes(modelFiles: string[]) {
9595
}
9696

9797
async function lookupFile(fileName: string): Promise<string | null> {
98-
const ormDirectory = path.projectStoragePath('framework/orm/Actions')
99-
98+
const ormDirectory = path.builtUserActionsPath()
10099
const filePath = path.join(ormDirectory, fileName)
101-
102100
const pathExists = await fs.existsSync(filePath)
103101

104102
// Check if the directory exists
@@ -107,9 +105,7 @@ async function lookupFile(fileName: string): Promise<string | null> {
107105
}
108106

109107
const actionDirectory = path.userActionsPath()
110-
111108
const actionFilePath = path.join(actionDirectory, fileName)
112-
113109
const fileExists = await fs.existsSync(actionFilePath)
114110

115111
if (fileExists) {
@@ -121,15 +117,12 @@ async function lookupFile(fileName: string): Promise<string | null> {
121117

122118
async function writeModelNames() {
123119
const modelFiles = glob.sync(path.userModelsPath('*.ts'))
124-
125120
let fileString = `export type ModelNames = `
126121

127122
for (let i = 0; i < modelFiles.length; i++) {
128123
const modeFileElement = modelFiles[i] as string
129-
130124
const model = (await import(modeFileElement)).default as Model
131125
const modelName = getModelName(model, modeFileElement)
132-
133126
const typeFile = Bun.file(path.corePath(`types/src/model-names.ts`))
134127

135128
fileString += `'${modelName}'`
@@ -146,8 +139,8 @@ async function writeModelNames() {
146139

147140
async function writeModelRequest() {
148141
const modelFiles = glob.sync(path.userModelsPath('*.ts'))
149-
150142
const requestD = Bun.file(path.frameworkPath('types/requests.d.ts'))
143+
151144
let importTypes = ``
152145
let importTypesString = ``
153146
let typeString = `import { Request } from '../core/router/src/request'\n\n`
@@ -173,14 +166,10 @@ async function writeModelRequest() {
173166
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`
174167

175168
const modeFileElement = modelFiles[i] as string
176-
177169
const model = (await import(modeFileElement)).default as Model
178170
const modelName = getModelName(model, modeFileElement)
179-
180171
const useTimestamps = model?.traits?.useTimestamps ?? model?.traits?.timestampable ?? true
181-
182172
const useSoftDeletes = model?.traits?.useSoftDeletes ?? model?.traits?.softDeletable ?? false
183-
184173
const attributes = await extractFields(model, modeFileElement)
185174

186175
fieldString += ` id?: number\n`
@@ -192,20 +181,18 @@ async function writeModelRequest() {
192181
const otherModelRelations = await fetchOtherModelRelations(model, modelName)
193182

194183
for (const attribute of attributes) {
195-
let defaultValue: any = `''`
196184
const entity = attribute.fieldArray?.entity === 'enum' ? 'string[]' : attribute.fieldArray?.entity
185+
let defaultValue: any = `''`
197186

198187
if (attribute.fieldArray?.entity === 'boolean') defaultValue = false
199-
200188
if (attribute.fieldArray?.entity === 'number') defaultValue = 0
201189

202190
fieldString += ` ${attribute.field}: ${entity}\n `
203-
204191
fieldStringType += `'${attribute.field}'`
192+
205193
if (keyCounter < attributes.length - 1) fieldStringType += ' |'
206194

207195
fieldStringInt += `public ${attribute.field} = ${defaultValue}\n`
208-
209196
keyCounter++
210197
}
211198

@@ -220,7 +207,6 @@ async function writeModelRequest() {
220207
// fieldStringType += ' |'
221208

222209
fieldStringInt += `public ${otherModel.foreignKey} = 0\n`
223-
224210
keyCounterForeign++
225211
}
226212

@@ -379,7 +365,7 @@ async function writeOrmActions(apiRoute: string, modelName: String): Promise<voi
379365
})
380366
`
381367

382-
const file = Bun.file(path.frameworkPath(`orm/Actions/${modelName}${formattedApiRoute}OrmAction.ts`))
368+
const file = Bun.file(path.builtUserActionsPath(`${modelName}${formattedApiRoute}OrmAction.ts`))
383369

384370
const writer = file.writer()
385371

@@ -502,14 +488,14 @@ async function deleteExistingOrmActions(modelStringFile?: string) {
502488
if (fs.existsSync(routes)) await Bun.$`rm ${routes}`
503489

504490
if (modelStringFile) {
505-
const ormPath = path.frameworkPath(`orm/Actions/${modelStringFile}.ts`)
491+
const ormPath = path.builtUserActionsPath(`${modelStringFile}.ts`)
506492

507493
if (fs.existsSync(ormPath)) await Bun.$`rm ${ormPath}`
508494

509495
return
510496
}
511497

512-
const ormPaths = glob.sync(path.frameworkPath(`orm/Actions/*.ts`))
498+
const ormPaths = glob.sync(path.builtUserActionsPath(`*.ts`))
513499

514500
for (const ormPath of ormPaths) {
515501
if (fs.existsSync(ormPath)) await Bun.$`rm ${ormPath}`

storage/framework/core/cloud/src/cloud/queue.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class QueueStack {
2525
async init() {
2626
const jobsDir = path.jobsPath()
2727
const actionsDir = path.appPath('Actions')
28-
const ormActionDir = path.projectStoragePath('framework/orm/Actions')
28+
const ormActionDir = path.builtUserActionsPath()
2929

3030
const jobFiles = await fs.readdir(jobsDir)
3131
const actionFiles = await fs.readdir(actionsDir)
@@ -47,7 +47,7 @@ export class QueueStack {
4747
for (const ormFile of ormActionFiles) {
4848
if (!ormFile.endsWith('.ts')) continue
4949

50-
const ormActionPath = path.frameworkPath(`orm/Actions/${ormFile}`)
50+
const ormActionPath = path.builtUserActionsPath(ormFile)
5151

5252
// Await the loading of the job module
5353
const ormAction = await this.loadModule(ormActionPath)

storage/framework/core/path/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export function userActionsPath(path?: string) {
4242
return appPath(`Actions/${path || ''}`)
4343
}
4444

45+
export function builtUserActionsPath(path?: string) {
46+
return frameworkPath(`actions/${path || ''}`)
47+
}
48+
4549
export function userComponentsPath(path?: string) {
4650
return libsPath(`components/${path || ''}`)
4751
}
@@ -1267,6 +1271,7 @@ export function homeDir(path?: string) {
12671271
export const path = {
12681272
actionsPath,
12691273
userActionsPath,
1274+
builtUserActionsPath,
12701275
userComponentsPath,
12711276
userViewsPath,
12721277
userFunctionsPath,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { projectStoragePath, routesPath } from '@stacksjs/path'
2+
import { intro, outro } from '../build/src'
3+
4+
const { startTime } = await intro({
5+
dir: import.meta.dir,
6+
})
7+
8+
const result = await Bun.build({
9+
entrypoints: [routesPath('api.ts'), projectStoragePath('framework/orm/routes.ts')],
10+
outdir: './dist',
11+
format: 'esm',
12+
target: 'bun',
13+
sourcemap: 'linked',
14+
})
15+
16+
await outro({
17+
dir: import.meta.dir,
18+
startTime,
19+
result,
20+
})

storage/framework/orm/routes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { route } from '@stacksjs/router'
22

3-
await route.get('users', '/Users/chrisbreuer/Code/stacks/storage/framework/orm/Actions/UserIndexOrmAction.ts')
3+
await route.get('users', '/Users/chrisbreuer/Code/stacks/storage/framework/actions/UserIndexOrmAction.ts')
44

5-
await route.get('users/{id}', '/Users/chrisbreuer/Code/stacks/storage/framework/orm/Actions/UserShowOrmAction.ts')
5+
await route.get('users/{id}', '/Users/chrisbreuer/Code/stacks/storage/framework/actions/UserShowOrmAction.ts')
66

77
await route.post('users', '/Users/chrisbreuer/Code/stacks/app/Actions/UserStoreAction.ts')
88

9-
await route.delete('users/{id}', '/Users/chrisbreuer/Code/stacks/storage/framework/orm/Actions/UserDestroyOrmAction.ts')
9+
await route.delete('users/{id}', '/Users/chrisbreuer/Code/stacks/storage/framework/actions/UserDestroyOrmAction.ts')

0 commit comments

Comments
 (0)