Skip to content

Commit 865c37e

Browse files
committed
chore: wip
1 parent f71572b commit 865c37e

File tree

4 files changed

+33
-78
lines changed

4 files changed

+33
-78
lines changed

.stacks/core/types/src/model.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ export interface Fields {
5050
unique?: boolean
5151
required?: boolean
5252
factory?: () => any
53-
validation?: String | Number | Boolean | Date
53+
validator?: {
54+
rule: String | Number | Boolean | Date
55+
message: string
56+
}
57+
// validation?: String | Number | Boolean | Date
5458
}
5559
}

.stacks/core/validation/src/validate.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,12 @@ declare module '@stacksjs/validation' {
1515
}
1616

1717
const validate = validator.validate
18-
export { validate, validator, Validator }
18+
const string = validator.string
19+
const number = validator.number
20+
const boolean = validator.boolean
21+
const array = validator.array
22+
const object = validator.object
23+
const any = validator.any
24+
const email = () => validator.string().email()
25+
26+
export { validate, validator, Validator, string, number, boolean, array, object, any, email }

.stacks/vcs/github/workflows/export-size.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,3 @@ jobs:
3030
with:
3131
github_token: ${{ secrets.GITHUB_TOKEN }}
3232
paths: .stacks/core/actions,.stacks/core/arrays,.stacks/core/auth,.stacks/core/build,.stacks/core/cache,.stacks/core/cli,.stacks/core/cloud,.stacks/core/config,.stacks/core/collections,.stacks/core/database,.stacks/core/datetime,.stacks/core/docs,.stacks/core/error-handling,.stacks/core/git,.stacks/core/lint,.stacks/core/modules,.stacks/core/notifications,.stacks/core/objects,.stacks/core/path,.stacks/core/realtime,.stacks/core/router,.stacks/core/security,.stacks/core/server,.stacks/core/storage,.stacks/core/strings,.stacks/core/testing,.stacks/core/types,.stacks/core/ui,.stacks/core/utils,.stacks/core/x-ray
33-
commands

app/models/User.ts

Lines changed: 19 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,37 @@
11
import { faker } from 'stacks/core/faker/src'
2-
import { validate } from 'stacks/core/validation/src'
3-
import type { Model } from 'stacks/core/types/src'
2+
import { email, string } from 'stacks/core/validation/src'
3+
import { defineModel } from 'stacks/core/utils/src'
44

5-
export default <Model> {
6-
name: 'User',
5+
export default defineModel({
6+
name: 'User', // defaults to the sanitized file name
77
table: 'users',
8-
authenticatable: true, // boolean | AuthSettings (including TokenSettings),
8+
authenticatable: true, // boolean | AuthSettings (including TokenSettings)
99
searchable: true, // boolean | IndexSettings,
1010
seedable: { // boolean | SeedSettings,
1111
count: 10,
1212
},
1313
fields: {
1414
name: {
15-
validation: validate.string().min(3).max(255),
16-
factory: () => faker.person.firstName(),
15+
validator: {
16+
rule: string().minLength(3).maxLength(255),
17+
message: 'Name must be between 3 and 255 characters',
18+
},
19+
factory: () => faker.person.fullName(),
1720
},
1821
email: {
19-
validation: validate.string().min(1).max(255),
2022
unique: true,
23+
validator: {
24+
rule: email(),
25+
message: 'Email must be a valid email address',
26+
},
2127
factory: () => faker.internet.email(),
2228
},
2329
password: {
24-
validation: validate.string().min(6).max(255),
30+
validator: {
31+
rule: string().minLength(6).maxLength(255),
32+
message: 'Password must be between 6 and 255 characters',
33+
},
2534
factory: () => faker.internet.password(),
2635
},
2736
},
28-
// dashboard: {
29-
// cards: [
30-
// {
31-
// title: 'Users',
32-
// icon: 'heroicon-o-user',
33-
// color: 'primary',
34-
// value: 'users',
35-
// query: {
36-
// model: 'User',
37-
// count: true,
38-
39-
// or
40-
41-
// model: 'User',
42-
// count: true,
43-
// where: {
44-
// id: 1,
45-
// },
46-
47-
// or
48-
49-
// model: 'User',
50-
// count: true,
51-
// where: {
52-
// id: {
53-
// $gt: 1,
54-
// },
55-
// },
56-
57-
// or
58-
59-
// model: 'User',
60-
// count: true,
61-
// where: {
62-
// id: {
63-
// $in: [1, 2, 3],
64-
// },
65-
// },
66-
67-
// or
68-
69-
// model: 'User',
70-
// count: true,
71-
// where: {
72-
// id: {
73-
// $notIn: [1, 2, 3],
74-
// },
75-
// },
76-
77-
// or
78-
79-
// model: 'User',
80-
// count: true,
81-
// where: {
82-
// id: {
83-
// // $notIn: [1, 2, 3],
84-
// $not: {
85-
// $in: [1, 2, 3],
86-
// },
87-
// },
88-
// },
89-
// }
90-
// }
91-
// ]
92-
// }
93-
}
37+
})

0 commit comments

Comments
 (0)