Skip to content

Commit 5f6e7c6

Browse files
chore: wip
1 parent c4e368a commit 5f6e7c6

28 files changed

+285
-128
lines changed

app/Models/Request.ts

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import type { Model } from '@stacksjs/types'
2+
import { faker } from '@stacksjs/faker'
3+
import { schema } from '@stacksjs/validation'
4+
5+
export default {
6+
name: 'Request',
7+
table: 'requests',
8+
primaryKey: 'id',
9+
autoIncrement: true,
10+
11+
traits: {
12+
useTimestamps: true,
13+
useSoftDeletes: true,
14+
useSeeder: {
15+
count: 50,
16+
},
17+
useApi: true,
18+
},
19+
20+
attributes: {
21+
method: {
22+
fillable: true,
23+
validation: {
24+
rule: schema.enum(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD']),
25+
message: {
26+
enum: 'method must be a valid HTTP method',
27+
required: 'method is required',
28+
},
29+
},
30+
factory: () => faker.helpers.arrayElement(['GET', 'POST', 'PUT', 'DELETE']),
31+
},
32+
33+
path: {
34+
fillable: true,
35+
validation: {
36+
rule: schema.string(),
37+
message: {
38+
string: 'path must be a string',
39+
required: 'path is required',
40+
},
41+
},
42+
factory: () => faker.internet.url(),
43+
},
44+
45+
status_code: {
46+
fillable: true,
47+
validation: {
48+
rule: schema.number(),
49+
message: {
50+
number: 'status_code must be a number',
51+
required: 'status_code is required',
52+
},
53+
},
54+
factory: () => faker.helpers.arrayElement([200, 201, 400, 401, 403, 404, 500]),
55+
},
56+
57+
duration_ms: {
58+
fillable: true,
59+
validation: {
60+
rule: schema.number(),
61+
message: {
62+
number: 'duration_ms must be a number',
63+
required: 'duration_ms is required',
64+
},
65+
},
66+
factory: () => faker.number.int({ min: 50, max: 1000 }),
67+
},
68+
69+
ip_address: {
70+
fillable: true,
71+
validation: {
72+
rule: schema.string(),
73+
message: {
74+
string: 'ip_address must be a string',
75+
required: 'ip_address is required',
76+
},
77+
},
78+
factory: () => faker.internet.ip(),
79+
},
80+
81+
memory_usage: {
82+
fillable: true,
83+
validation: {
84+
rule: schema.number(),
85+
message: {
86+
number: 'memory_usage must be a number in MB',
87+
required: 'memory_usage is required',
88+
},
89+
},
90+
factory: () => faker.number.int({ min: 50, max: 512 }),
91+
},
92+
93+
user_agent: {
94+
fillable: true,
95+
validation: {
96+
rule: schema.string(),
97+
message: {
98+
string: 'user_agent must be a string',
99+
},
100+
},
101+
factory: () => faker.internet.userAgent(),
102+
},
103+
104+
error_message: {
105+
fillable: true,
106+
validation: {
107+
rule: schema.string(),
108+
message: {
109+
string: 'error_message must be a string',
110+
},
111+
},
112+
factory: () => faker.helpers.maybe(() => faker.lorem.sentence(), { probability: 0.2 }),
113+
},
114+
},
115+
} satisfies Model

storage/framework/core/orm/src/generate.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,15 +1829,15 @@ export async function generateModelString(
18291829
18301830
whereNotNull(column: keyof ${formattedTableName}Table): ${modelName}Model {
18311831
this.selectFromQuery = this.selectFromQuery.where((eb: any) =>
1832-
eb(column, '=', '').or(column, 'not', null)
1832+
eb(column, '=', '').or(column, 'is not', null)
18331833
)
18341834
18351835
this.updateFromQuery = this.updateFromQuery.where((eb: any) =>
1836-
eb(column, '=', '').or(column, 'not', null)
1836+
eb(column, '=', '').or(column, 'is not', null)
18371837
)
18381838
18391839
this.deleteFromQuery = this.deleteFromQuery.where((eb: any) =>
1840-
eb(column, '=', '').or(column, 'not', null)
1840+
eb(column, '=', '').or(column, 'is not', null)
18411841
)
18421842
18431843
return this
@@ -1847,15 +1847,15 @@ export async function generateModelString(
18471847
const instance = new ${modelName}Model(null)
18481848
18491849
instance.selectFromQuery = instance.selectFromQuery.where((eb: any) =>
1850-
eb(column, '=', '').or(column, 'not', null)
1850+
eb(column, '=', '').or(column, 'is not', null)
18511851
)
18521852
18531853
instance.updateFromQuery = instance.updateFromQuery.where((eb: any) =>
1854-
eb(column, '=', '').or(column, 'not', null)
1854+
eb(column, '=', '').or(column, 'is not', null)
18551855
)
18561856
18571857
instance.deleteFromQuery = instance.deleteFromQuery.where((eb: any) =>
1858-
eb(column, '=', '').or(column, 'not', null)
1858+
eb(column, '=', '').or(column, 'is not', null)
18591859
)
18601860
18611861
return instance

storage/framework/core/orm/src/subquery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
type Operator = '=' | '<' | '>' | '<=' | '>=' | '<>' | '!=' | 'like' | 'not like' | 'in' | 'not in' | 'between' | 'not between' | 'is' | 'is not'
1+
export type Operator = '=' | '<' | '>' | '<=' | '>=' | '<>' | '!=' | 'like' | 'not like' | 'in' | 'not in' | 'between' | 'not between' | 'is' | 'is not'
22

33
interface WhereCondition<T = any, V = any> {
44
type: 'and' | 'or'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export type ModelNames = 'Project' | 'SubscriberEmail' | 'AccessToken' | 'Team' | 'Activity' | 'Subscriber' | 'Deployment' | 'Release' | 'User' | 'Post' | 'FailedJob' | 'Product' | 'PaymentMethod' | 'Request' | 'Transaction' | 'Job' | 'Subscription' | 'Error'
1+
export type ModelNames = 'Project' | 'SubscriberEmail' | 'AccessToken' | 'Team' | 'Request' | 'Activity' | 'Subscriber' | 'Deployment' | 'Release' | 'User' | 'Post' | 'FailedJob' | 'Product' | 'PaymentMethod' | 'Request' | 'Transaction' | 'Job' | 'Subscription' | 'Error'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export type TableNames = 'projects' | 'subscriber_emails' | 'personal_access_tokens' | 'team_users' | 'teams' | 'activities' | 'subscribers' | 'deployments' | 'releases' | 'team_users' | 'users' | 'posts' | 'failed_jobs' | 'products' | 'payment_methods' | 'requests' | 'transactions' | 'jobs' | 'subscriptions' | 'errors'
1+
export type TableNames = 'projects' | 'subscriber_emails' | 'personal_access_tokens' | 'team_users' | 'teams' | 'requests' | 'activities' | 'subscribers' | 'deployments' | 'releases' | 'team_users' | 'users' | 'posts' | 'failed_jobs' | 'products' | 'payment_methods' | 'requests' | 'transactions' | 'jobs' | 'subscriptions' | 'errors'

storage/framework/orm/routes.ts

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

3-
43
route.get('requests', 'storage/framework/actions/src/RequestIndexOrmAction.ts')
54

65
route.get('requests/{id}', 'storage/framework/actions/src/RequestShowOrmAction.ts')
@@ -11,11 +10,18 @@ route.patch('requests/{id}', 'storage/framework/actions/src/RequestUpdateOrmActi
1110

1211
route.delete('requests/{id}', 'storage/framework/actions/src/RequestDestroyOrmAction.ts')
1312

14-
rmAction.ts')
13+
route.get('activities', 'storage/framework/actions/src/ActivityIndexOrmAction.ts')
14+
15+
route.get('activities/{id}', 'storage/framework/actions/src/ActivityShowOrmAction.ts')
16+
17+
route.post('activities', 'storage/framework/actions/src/ActivityStoreOrmAction.ts')
18+
19+
route.patch('activities/{id}', 'storage/framework/actions/src/ActivityUpdateOrmAction.ts')
20+
21+
route.delete('activities/{id}', 'storage/framework/actions/src/ActivityDestroyOrmAction.ts')
1522

1623
route.get('users', 'UserIndexOrmAction')
1724

1825
route.post('users', 'UserStoreOrmAction')
1926

2027
route.get('users/{id}', 'UserShowOrmAction')
21-

storage/framework/orm/src/models/AccessToken.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,15 +1034,15 @@ export class AccessTokenModel {
10341034

10351035
whereNotNull(column: keyof PersonalAccessTokensTable): AccessTokenModel {
10361036
this.selectFromQuery = this.selectFromQuery.where((eb: any) =>
1037-
eb(column, '=', '').or(column, 'not', null),
1037+
eb(column, '=', '').or(column, 'is not', null),
10381038
)
10391039

10401040
this.updateFromQuery = this.updateFromQuery.where((eb: any) =>
1041-
eb(column, '=', '').or(column, 'not', null),
1041+
eb(column, '=', '').or(column, 'is not', null),
10421042
)
10431043

10441044
this.deleteFromQuery = this.deleteFromQuery.where((eb: any) =>
1045-
eb(column, '=', '').or(column, 'not', null),
1045+
eb(column, '=', '').or(column, 'is not', null),
10461046
)
10471047

10481048
return this
@@ -1052,15 +1052,15 @@ export class AccessTokenModel {
10521052
const instance = new AccessTokenModel(null)
10531053

10541054
instance.selectFromQuery = instance.selectFromQuery.where((eb: any) =>
1055-
eb(column, '=', '').or(column, 'not', null),
1055+
eb(column, '=', '').or(column, 'is not', null),
10561056
)
10571057

10581058
instance.updateFromQuery = instance.updateFromQuery.where((eb: any) =>
1059-
eb(column, '=', '').or(column, 'not', null),
1059+
eb(column, '=', '').or(column, 'is not', null),
10601060
)
10611061

10621062
instance.deleteFromQuery = instance.deleteFromQuery.where((eb: any) =>
1063-
eb(column, '=', '').or(column, 'not', null),
1063+
eb(column, '=', '').or(column, 'is not', null),
10641064
)
10651065

10661066
return instance

storage/framework/orm/src/models/Activity.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,15 +1068,15 @@ export class ActivityModel {
10681068

10691069
whereNotNull(column: keyof ActivitiesTable): ActivityModel {
10701070
this.selectFromQuery = this.selectFromQuery.where((eb: any) =>
1071-
eb(column, '=', '').or(column, 'not', null),
1071+
eb(column, '=', '').or(column, 'is not', null),
10721072
)
10731073

10741074
this.updateFromQuery = this.updateFromQuery.where((eb: any) =>
1075-
eb(column, '=', '').or(column, 'not', null),
1075+
eb(column, '=', '').or(column, 'is not', null),
10761076
)
10771077

10781078
this.deleteFromQuery = this.deleteFromQuery.where((eb: any) =>
1079-
eb(column, '=', '').or(column, 'not', null),
1079+
eb(column, '=', '').or(column, 'is not', null),
10801080
)
10811081

10821082
return this
@@ -1086,15 +1086,15 @@ export class ActivityModel {
10861086
const instance = new ActivityModel(null)
10871087

10881088
instance.selectFromQuery = instance.selectFromQuery.where((eb: any) =>
1089-
eb(column, '=', '').or(column, 'not', null),
1089+
eb(column, '=', '').or(column, 'is not', null),
10901090
)
10911091

10921092
instance.updateFromQuery = instance.updateFromQuery.where((eb: any) =>
1093-
eb(column, '=', '').or(column, 'not', null),
1093+
eb(column, '=', '').or(column, 'is not', null),
10941094
)
10951095

10961096
instance.deleteFromQuery = instance.deleteFromQuery.where((eb: any) =>
1097-
eb(column, '=', '').or(column, 'not', null),
1097+
eb(column, '=', '').or(column, 'is not', null),
10981098
)
10991099

11001100
return instance

storage/framework/orm/src/models/Deployment.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,15 +1075,15 @@ export class DeploymentModel {
10751075

10761076
whereNotNull(column: keyof DeploymentsTable): DeploymentModel {
10771077
this.selectFromQuery = this.selectFromQuery.where((eb: any) =>
1078-
eb(column, '=', '').or(column, 'not', null),
1078+
eb(column, '=', '').or(column, 'is not', null),
10791079
)
10801080

10811081
this.updateFromQuery = this.updateFromQuery.where((eb: any) =>
1082-
eb(column, '=', '').or(column, 'not', null),
1082+
eb(column, '=', '').or(column, 'is not', null),
10831083
)
10841084

10851085
this.deleteFromQuery = this.deleteFromQuery.where((eb: any) =>
1086-
eb(column, '=', '').or(column, 'not', null),
1086+
eb(column, '=', '').or(column, 'is not', null),
10871087
)
10881088

10891089
return this
@@ -1093,15 +1093,15 @@ export class DeploymentModel {
10931093
const instance = new DeploymentModel(null)
10941094

10951095
instance.selectFromQuery = instance.selectFromQuery.where((eb: any) =>
1096-
eb(column, '=', '').or(column, 'not', null),
1096+
eb(column, '=', '').or(column, 'is not', null),
10971097
)
10981098

10991099
instance.updateFromQuery = instance.updateFromQuery.where((eb: any) =>
1100-
eb(column, '=', '').or(column, 'not', null),
1100+
eb(column, '=', '').or(column, 'is not', null),
11011101
)
11021102

11031103
instance.deleteFromQuery = instance.deleteFromQuery.where((eb: any) =>
1104-
eb(column, '=', '').or(column, 'not', null),
1104+
eb(column, '=', '').or(column, 'is not', null),
11051105
)
11061106

11071107
return instance

storage/framework/orm/src/models/Error.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,15 +1030,15 @@ export class ErrorModel {
10301030

10311031
whereNotNull(column: keyof ErrorsTable): ErrorModel {
10321032
this.selectFromQuery = this.selectFromQuery.where((eb: any) =>
1033-
eb(column, '=', '').or(column, 'not', null),
1033+
eb(column, '=', '').or(column, 'is not', null),
10341034
)
10351035

10361036
this.updateFromQuery = this.updateFromQuery.where((eb: any) =>
1037-
eb(column, '=', '').or(column, 'not', null),
1037+
eb(column, '=', '').or(column, 'is not', null),
10381038
)
10391039

10401040
this.deleteFromQuery = this.deleteFromQuery.where((eb: any) =>
1041-
eb(column, '=', '').or(column, 'not', null),
1041+
eb(column, '=', '').or(column, 'is not', null),
10421042
)
10431043

10441044
return this
@@ -1048,15 +1048,15 @@ export class ErrorModel {
10481048
const instance = new ErrorModel(null)
10491049

10501050
instance.selectFromQuery = instance.selectFromQuery.where((eb: any) =>
1051-
eb(column, '=', '').or(column, 'not', null),
1051+
eb(column, '=', '').or(column, 'is not', null),
10521052
)
10531053

10541054
instance.updateFromQuery = instance.updateFromQuery.where((eb: any) =>
1055-
eb(column, '=', '').or(column, 'not', null),
1055+
eb(column, '=', '').or(column, 'is not', null),
10561056
)
10571057

10581058
instance.deleteFromQuery = instance.deleteFromQuery.where((eb: any) =>
1059-
eb(column, '=', '').or(column, 'not', null),
1059+
eb(column, '=', '').or(column, 'is not', null),
10601060
)
10611061

10621062
return instance

0 commit comments

Comments
 (0)