Skip to content

Commit c104cff

Browse files
chore: wip
1 parent 1f47f66 commit c104cff

File tree

4 files changed

+30
-23
lines changed

4 files changed

+30
-23
lines changed

app/Actions/SubscriberEmailAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Action } from '@stacksjs/actions'
22
// import { epmailSubscribeRequest } from '@stacksjs/validation'
33
import SubscriberEmail from '../../storage/framework/orm/src/models/SubscriberEmail'
4-
import { SubscriberEmailRequestType } from '../../storage/framework/requests/SubscriberEmailRequest'
4+
import { SubscriberEmailRequestType } from '../../storage/framework/types/requests'
55

66
export default new Action({
77
name: 'SubscriberEmailAction',

storage/framework/core/actions/src/action.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
import type { JobOptions, Nullable } from '@stacksjs/types'
22
import type { ValidationBoolean, ValidationNumber, ValidationString } from '@stacksjs/validation'
3+
import type { ModelRequests } from '../../../types/requests'
34

45
type ValidationKey = string
56
interface ValidationValue {
67
rule: ValidationString | ValidationNumber | ValidationBoolean | Date | Nullable<any>
78
message: string
89
}
910

10-
// TODO: this is temporary and will get auto generated based on ./app/Actions/*
11-
interface Request {
12-
message: string
13-
level: 'info' | 'warn' | 'error'
14-
}
15-
1611
interface ActionOptions {
1712
name?: string
1813
description?: string
@@ -24,7 +19,7 @@ interface ActionOptions {
2419
tries?: JobOptions['tries']
2520
backoff?: JobOptions['backoff']
2621
enabled?: JobOptions['enabled']
27-
handle: (request?: Request) => Promise<any> | object | string
22+
handle: (request?: ModelRequests) => Promise<any> | object | string
2823
}
2924

3025
export class Action {
@@ -37,7 +32,7 @@ export class Action {
3732
path?: ActionOptions['path']
3833
method?: ActionOptions['method']
3934
validations?: Record<ValidationKey, ValidationValue>
40-
handle: (request?: Request) => Promise<any> | object | string
35+
handle: (request?: ModelRequests) => Promise<any> | object | string
4136

4237
constructor({ name, description, validations, handle, rate, tries, backoff, enabled, path, method }: ActionOptions) {
4338
// log.debug(`Action ${name} created`) // TODO: this does not yet work because the cloud does not yet have proper file system (efs) access

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ async function writeModelNames() {
105105

106106
async function writeModelRequests() {
107107
const modelFiles = glob.sync(path.userModelsPath('*.ts'))
108+
109+
const requestD = Bun.file(path.frameworkPath('types/requests.d.ts'))
110+
let importTypes = ``
111+
let importTypesString = ``
108112
let typeString = ``
109113
for (let i = 0; i < modelFiles.length; i++) {
110114

@@ -159,13 +163,17 @@ async function writeModelRequests() {
159163

160164
const requestFile = Bun.file(path.projectStoragePath(`framework/requests/${modelName}Request.ts`))
161165

162-
const requestD = Bun.file(path.frameworkPath('types/requests.d.ts'))
166+
importTypes = `${modelName}RequestType`
167+
importTypesString += `${importTypes}`
168+
169+
if (i < modelFiles.length - 1)
170+
importTypesString += ` | `
163171

164-
fileString += `import { ${modelName}RequestType } from '../types/requests'\n\n`
172+
fileString += `import { ${importTypes} } from '../types/requests'\n\n`
165173

166174
const types = `export interface ${modelName}RequestType extends RequestInstance {
167175
validate(): void
168-
getParam(key: ${fieldStringType}): number | string | null
176+
get(key: ${fieldStringType}): string | number | undefined;
169177
${fieldString}
170178
}\n\n`
171179

@@ -180,14 +188,17 @@ async function writeModelRequests() {
180188
181189
export const ${modelLowerCase}Request = new ${modelName}Request()
182190
`
183-
const requestWrite = requestD.writer()
184191

185192
const writer = requestFile.writer()
186193

187194
writer.write(fileString)
188-
189-
requestWrite.write(typeString)
190195
}
196+
197+
typeString += `export type ModelRequests = ${importTypesString}`
198+
199+
const requestWrite = requestD.writer()
200+
201+
requestWrite.write(typeString)
191202
}
192203

193204
async function writeOrmActions(apiRoute: string, modelName: String): Promise<void> {

storage/framework/types/requests.d.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export interface ProjectRequestType extends RequestInstance {
22
validate(): void
3-
getParam(key: 'id' |'name' |'description' |'url' |'status'): number | string | null
3+
get(key: 'id' |'name' |'description' |'url' |'status'): string | number | undefined;
44
id: number
55
name: string
66
description: string
@@ -13,7 +13,7 @@ export interface ProjectRequestType extends RequestInstance {
1313

1414
export interface SubscriberEmailRequestType extends RequestInstance {
1515
validate(): void
16-
getParam(key: 'id' |'email'): number | string | null
16+
get(key: 'id' |'email'): string | number | undefined;
1717
id: number
1818
email: string
1919
created_at: Date
@@ -23,7 +23,7 @@ export interface SubscriberEmailRequestType extends RequestInstance {
2323

2424
export interface AccessTokenRequestType extends RequestInstance {
2525
validate(): void
26-
getParam(key: 'id' |'name' |'token' |'plainTextToken' |'abilities'): number | string | null
26+
get(key: 'id' |'name' |'token' |'plainTextToken' |'abilities'): string | number | undefined;
2727
id: number
2828
name: string
2929
token: string
@@ -36,7 +36,7 @@ export interface AccessTokenRequestType extends RequestInstance {
3636

3737
export interface TeamRequestType extends RequestInstance {
3838
validate(): void
39-
getParam(key: 'id' |'name' |'companyName' |'email' |'billingEmail' |'status' |'description' |'path' |'isPersonal'): number | string | null
39+
get(key: 'id' |'name' |'companyName' |'email' |'billingEmail' |'status' |'description' |'path' |'isPersonal'): string | number | undefined;
4040
id: number
4141
name: string
4242
companyName: string
@@ -53,7 +53,7 @@ export interface TeamRequestType extends RequestInstance {
5353

5454
export interface SubscriberRequestType extends RequestInstance {
5555
validate(): void
56-
getParam(key: 'id' |'subscribed'): number | string | null
56+
get(key: 'id' |'subscribed'): string | number | undefined;
5757
id: number
5858
subscribed: boolean
5959
created_at: Date
@@ -63,7 +63,7 @@ export interface SubscriberRequestType extends RequestInstance {
6363

6464
export interface DeploymentRequestType extends RequestInstance {
6565
validate(): void
66-
getParam(key: 'id' |'commitSha' |'commitMessage' |'branch' |'status' |'executionTime' |'deployScript' |'terminalOutput'): number | string | null
66+
get(key: 'id' |'commitSha' |'commitMessage' |'branch' |'status' |'executionTime' |'deployScript' |'terminalOutput'): string | number | undefined;
6767
id: number
6868
commitSha: string
6969
commitMessage: string
@@ -79,7 +79,7 @@ export interface DeploymentRequestType extends RequestInstance {
7979

8080
export interface UserRequestType extends RequestInstance {
8181
validate(): void
82-
getParam(key: 'id' |'name' |'email' |'jobTitle' |'password'): number | string | null
82+
get(key: 'id' |'name' |'email' |'jobTitle' |'password'): string | number | undefined;
8383
id: number
8484
name: string
8585
email: string
@@ -92,7 +92,7 @@ export interface UserRequestType extends RequestInstance {
9292

9393
export interface PostRequestType extends RequestInstance {
9494
validate(): void
95-
getParam(key: 'id' |'title' |'body'): number | string | null
95+
get(key: 'id' |'title' |'body'): string | number | undefined;
9696
id: number
9797
title: string
9898
body: string
@@ -101,3 +101,4 @@ export interface PostRequestType extends RequestInstance {
101101
deleted_at: Date
102102
}
103103

104+
export type ModelRequests = ProjectRequestType | SubscriberEmailRequestType | AccessTokenRequestType | TeamRequestType | SubscriberRequestType | DeploymentRequestType | UserRequestType | PostRequestTypequestType | UserRequestType | PostRequestType

0 commit comments

Comments
 (0)