Skip to content

Commit ddf5bf1

Browse files
chore: wip
1 parent a36135e commit ddf5bf1

File tree

10 files changed

+117
-18
lines changed

10 files changed

+117
-18
lines changed

storage/framework/actions/src/LogFetchStatsAction.ts renamed to app/Actions/Logs/LogFetchStatsAction.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Action } from '@stacksjs/actions'
2-
import { response } from '@stacksjs/router'
32
import { Log } from '@stacksjs/orm'
3+
import { response } from '@stacksjs/router'
44

55
export default new Action({
66
name: 'Log Stats',
@@ -24,27 +24,27 @@ export default new Action({
2424
const month = date.getMonth() + 1
2525
const year = date.getFullYear()
2626
const key = `${year}-${month}-${day} ${hour}:00`
27-
27+
2828
if (!acc[key]) {
2929
acc[key] = 0
3030
}
3131
acc[key]++
32-
32+
3333
return acc
3434
}, {})
3535

3636
// Format data for line graph
3737
const data = Object.entries(hourlyStats).map(([time, count]) => ({
3838
time,
39-
count
39+
count,
4040
}))
4141

4242
return response.json({
4343
data,
4444
timeRange: {
4545
start: twentyFourHoursAgo,
46-
end: now
47-
}
46+
end: now,
47+
},
4848
})
4949
},
5050
})

storage/framework/api/openapi.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import { Table } from 'dynamodb-toolbox/table'
2+
import { Entity } from 'dynamodb-toolbox/entity'
3+
import { item } from 'dynamodb-toolbox/schema/item'
4+
import { string } from 'dynamodb-toolbox/schema/string'
5+
6+
// Define the main table
7+
const AppTable: Table = new Table({
8+
name: 'app-table',
9+
partitionKey: {
10+
name: 'pk',
11+
type: 'string'
12+
},
13+
sortKey: {
14+
name: 'sk',
15+
type: 'string'
16+
},
17+
indexes: {
18+
GSI1: {
19+
type: 'global',
20+
partitionKey: {
21+
name: 'gsi1pk',
22+
type: 'string'
23+
},
24+
sortKey: {
25+
name: 'gsi1sk',
26+
type: 'string'
27+
}
28+
},
29+
GSI2: {
30+
type: 'global',
31+
partitionKey: {
32+
name: 'gsi2pk',
33+
type: 'string'
34+
},
35+
sortKey: {
36+
name: 'gsi2sk',
37+
type: 'string'
38+
}
39+
}
40+
}
41+
})
42+
43+
// User Entity
44+
const userSchema = item({
45+
id: string().required(),
46+
name: string().required(),
47+
email: string().required(),
48+
job_title: string(),
49+
password: string().required(),
50+
public_passkey: string(),
51+
stripe_id: string(),
52+
uuid: string(),
53+
created_at: string(),
54+
updated_at: string()
55+
})
56+
57+
const UserEntity: Entity = new Entity({
58+
name: 'User',
59+
table: AppTable,
60+
schema: userSchema,
61+
computeKey: (keyInput: any) => ({
62+
pk: `USER#${keyInput.id}`,
63+
sk: `USER#${keyInput.id}`
64+
})
65+
})
66+
67+
// Post Entity
68+
const postSchema = item({
69+
id: string().required(),
70+
user_id: string().required(),
71+
title: string().required(),
72+
body: string().required(),
73+
created_at: string(),
74+
updated_at: string()
75+
})
76+
77+
const PostEntity: Entity = new Entity({
78+
name: 'Post',
79+
table: AppTable,
80+
schema: postSchema,
81+
computeKey: (keyInput: any) => ({
82+
pk: `POST#${keyInput.id}`,
83+
sk: `POST#${keyInput.id}`
84+
})
85+
})
86+
87+
// Helper functions for key generation
88+
const generateKeys = {
89+
user: (id: string) => ({
90+
pk: `USER#${id}`,
91+
sk: `USER#${id}`,
92+
gsi1pk: `USER#EMAIL`,
93+
gsi1sk: `USER#${id}`,
94+
gsi2pk: `USER#NAME`,
95+
gsi2sk: `USER#${id}`
96+
}),
97+
post: (id: string, userId: string) => ({
98+
pk: `POST#${id}`,
99+
sk: `POST#${id}`,
100+
gsi1pk: `USER#${userId}`,
101+
gsi1sk: `POST#${id}`
102+
})
103+
}
104+
105+
export {
106+
AppTable,
107+
UserEntity,
108+
PostEntity,
109+
generateKeys,
110+
}

storage/framework/defaults/models/Log.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export default {
99

1010
traits: {
1111
useTimestamps: true,
12-
useApi: true,
1312
useSearch: {
1413
displayable: ['id', 'type', 'source', 'message', 'project', 'timestamp'],
1514
searchable: ['message', 'project', 'file'],

storage/framework/orm/routes.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,3 @@ route.post('requests', 'storage/framework/actions/src/RequestStoreOrmAction.ts')
1515
route.patch('requests/{id}', 'storage/framework/actions/src/RequestUpdateOrmAction.ts')
1616

1717
route.delete('requests/{id}', 'storage/framework/actions/src/RequestDestroyOrmAction.ts')
18-
19-
route.get('logs', 'storage/framework/actions/src/LogIndexOrmAction.ts')
20-
21-
route.get('logs/{id}', 'storage/framework/actions/src/LogShowOrmAction.ts')
22-
23-
route.post('logs', 'storage/framework/actions/src/LogStoreOrmAction.ts')
24-
25-
route.patch('logs/{id}', 'storage/framework/actions/src/LogUpdateOrmAction.ts')
26-
27-
route.delete('logs/{id}', 'storage/framework/actions/src/LogDestroyOrmAction.ts')

0 commit comments

Comments
 (0)