Skip to content

Commit ad4666d

Browse files
chore: wip
1 parent 45c3558 commit ad4666d

File tree

12 files changed

+34
-40
lines changed

12 files changed

+34
-40
lines changed

app/Actions/SubscriberEmailAction.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Action } from '@stacksjs/actions'
2-
import { schema } from '@stacksjs/validation'
2+
// import { schema } from '@stacksjs/validation'
33
// import { epmailSubscribeRequest } from '@stacksjs/validation'
44
import SubscriberEmail from '../../storage/framework/orm/src/models/SubscriberEmail'
55
import type { SubscriberEmailRequestType } from '../../storage/framework/types/requests'
@@ -8,15 +8,15 @@ export default new Action({
88
name: 'SubscriberEmailAction',
99
description: 'Save emails from subscribe page',
1010
method: 'POST',
11-
validations: {
12-
status: {
13-
rule: schema.string().minLength(5).maxLength(255),
14-
message: {
15-
minLength: 'Name must have a minimum of 3 characters',
16-
maxLength: 'Name must have a maximum of 255 characters',
17-
},
18-
},
19-
},
11+
// validations: {
12+
// status: {
13+
// rule: schema.string().minLength(5).maxLength(255),
14+
// message: {
15+
// minLength: 'Name must have a minimum of 3 characters',
16+
// maxLength: 'Name must have a maximum of 255 characters',
17+
// },
18+
// },
19+
// },
2020
async handle(request: SubscriberEmailRequestType) {
2121
const email = request.get('email')
2222

app/Models/User.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ export default {
3333
useApi: {
3434
uri: 'users', // your-url.com/api/users
3535
middleware: ['Api'], // defaults to `[]`
36+
3637
routes: {
3738
index: 'UserIndexOrmAction',
3839
show: 'UserShowOrmAction',
39-
store: 'UserStoreAction',
4040
destroy: 'UserDestroyOrmAction',
4141
},
4242
},

storage/framework/actions/src/UserDestroyOrmAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Action } from '@stacksjs/actions'
2+
import User from '../../orm/src/models/User'
23
import type { UserRequestType } from '../../types/requests'
3-
import User from '../src/models/User'
44

55
export default new Action({
66
name: 'User Destroy',

storage/framework/actions/src/UserIndexOrmAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Action } from '@stacksjs/actions'
2+
import User from '../../orm/src/models/User'
23
import type { UserRequestType } from '../../types/requests'
3-
import User from '../src/models/User'
44

55
export default new Action({
66
name: 'User Index',

storage/framework/actions/src/UserShowOrmAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Action } from '@stacksjs/actions'
2+
import User from '../../orm/src/models/User'
23
import type { UserRequestType } from '../../types/requests'
3-
import User from '../src/models/User'
44

55
export default new Action({
66
name: 'User Show',

storage/framework/actions/src/UserStoreOrmAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Action } from '@stacksjs/actions'
2+
import User from '../../orm/src/models/User'
23
import type { UserRequestType } from '../../types/requests'
3-
import User from '../src/models/User'
44

55
export default new Action({
66
name: 'User Store',

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ async function generateApiRoutes(modelFiles: string[]) {
5858
const apiRoutes = model.traits.useApi.routes
5959
for (const apiRoute in apiRoutes) {
6060
if (Object.prototype.hasOwnProperty.call(apiRoutes, apiRoute)) {
61-
// console.log(`Route: ${apiRoute}, Path: ${apiRoutes[apiRoute]}`);
62-
// }
63-
6461
let path: string | null = ''
6562

6663
await writeOrmActions(apiRoute as string, modelName)
@@ -101,7 +98,7 @@ async function generateApiRoutes(modelFiles: string[]) {
10198
}
10299

103100
async function lookupFile(fileName: string): Promise<string | null> {
104-
const ormDirectory = path.builtUserActionsPath('src')
101+
const ormDirectory = path.builtUserActionsPath('src', { relative: true })
105102
const filePath = path.join(ormDirectory, fileName)
106103
const pathExists = await fs.existsSync(filePath)
107104

@@ -287,9 +284,10 @@ async function writeModelRequest() {
287284

288285
async function writeOrmActions(apiRoute: string, modelName: String): Promise<void> {
289286
const formattedApiRoute = apiRoute.charAt(0).toUpperCase() + apiRoute.slice(1)
287+
290288
let method = 'GET'
291289
let actionString = `import { Action } from '@stacksjs/actions'\n`
292-
actionString += `import ${modelName} from '../src/models/${modelName}'\n`
290+
actionString += `import ${modelName} from '../../orm/src/models/${modelName}'\n`
293291

294292
let handleString = ``
295293

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@ export function relativeActionsPath(path?: string) {
3838
return relative(projectPath(), actionsPath(path))
3939
}
4040

41-
export function userActionsPath(path?: string) {
41+
export function userActionsPath(path?: string, options?: { relative: true }) {
4242
return appPath(`Actions/${path || ''}`)
4343
}
4444

45-
export function builtUserActionsPath(path?: string) {
46-
return frameworkPath(`actions/${path || ''}`)
45+
export function builtUserActionsPath(path?: string, options?: { relative: boolean }) {
46+
const absolutePath = frameworkPath(`actions/${path || ''}`)
47+
48+
if (options?.relative) return relative(process.cwd(), absolutePath)
49+
50+
return absolutePath
4751
}
4852

4953
export function userComponentsPath(path?: string) {

storage/framework/core/router/src/router.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,11 @@ export class Router implements RouterInterface {
282282

283283
let actionModule = null
284284

285-
if (modulePath.includes('storage/framework/orm')) actionModule = await import(`${modulePath}.ts`)
286-
else if (modulePath.includes('app/Actions')) actionModule = await import(`${modulePath}.ts`)
285+
if (modulePath.includes('storage/framework/orm')) actionModule = await import(modulePath)
286+
else if (modulePath.includes('app/Actions')) actionModule = await import(modulePath)
287287
else if (modulePath.includes('OrmAction'))
288-
actionModule = await import(importPathFunction(`/framework/orm/${modulePath}.ts`))
289-
else actionModule = await import(importPathFunction(`${modulePath}.ts`))
288+
actionModule = await import(p.storagePath(`/framework/orm/${modulePath}`))
289+
else actionModule = await import(importPathFunction(modulePath))
290290

291291
// Use custom path from action module if available
292292
const newPath = actionModule.default.path ?? originalPath

storage/framework/core/types/src/model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export interface ModelOptions extends Base {
9292
useSearch?: boolean | SearchOptions // defaults to false
9393
searchable?: boolean | SearchOptions // useSearch alias
9494
useApi?: ApiOptions | boolean
95+
openApi?: boolean
9596
observe?: string[] | boolean
9697
useActivityLog?: boolean | ActivityLogOption
9798
}

0 commit comments

Comments
 (0)