Skip to content

Commit 20c3e7f

Browse files
author
Frantz Kati
committed
integrate schema generator
1 parent 9232007 commit 20c3e7f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1174
-406
lines changed

examples/blog/app.js

+38-51
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const Comment = require('./resources/Comment')
1414
module.exports = tensei()
1515
.dashboardPath('tensei')
1616
.resources([Tag, Post, User, Comment])
17-
.database('mongodb')
1817
.serverUrl('http://localhost:5000')
1918
.clientUrl('https://google.com')
2019
.defaultStorageDriver('local')
@@ -67,31 +66,31 @@ module.exports = tensei()
6766
]),
6867
])
6968
.plugins([
70-
auth()
71-
.name('Customer')
72-
.twoFactorAuth()
73-
.verifyEmails()
74-
.teams()
75-
.apiPath('auth')
76-
.rolesAndPermissions()
77-
.social('github', {
78-
key: process.env.GITHUB_KEY,
79-
secret: process.env.GITHUB_SECRET,
80-
scope: ['user', 'user:email'],
81-
})
82-
.social('gitlab', {
83-
key: process.env.GITLAB_KEY,
84-
secret: process.env.GITLAB_SECRET,
85-
})
86-
.social('google', {
87-
key: process.env.GOOGLE_KEY,
88-
secret: process.env.GOOGLE_SECRET,
89-
})
90-
.social('linkedin', {
91-
key: process.env.LINKEDIN_KEY,
92-
secret: process.env.LINKEDIN_SECRET,
93-
})
94-
.plugin(),
69+
// auth()
70+
// .name('Customer')
71+
// .twoFactorAuth()
72+
// .verifyEmails()
73+
// .teams()
74+
// .apiPath('auth')
75+
// .rolesAndPermissions()
76+
// .social('github', {
77+
// key: process.env.GITHUB_KEY,
78+
// secret: process.env.GITHUB_SECRET,
79+
// scope: ['user', 'user:email'],
80+
// })
81+
// .social('gitlab', {
82+
// key: process.env.GITLAB_KEY,
83+
// secret: process.env.GITLAB_SECRET,
84+
// })
85+
// .social('google', {
86+
// key: process.env.GOOGLE_KEY,
87+
// secret: process.env.GOOGLE_SECRET,
88+
// })
89+
// .social('linkedin', {
90+
// key: process.env.LINKEDIN_KEY,
91+
// secret: process.env.LINKEDIN_SECRET,
92+
// })
93+
// .plugin(),
9594
trix(),
9695
// cashier()
9796
// .customerResourceName('Customer')
@@ -102,30 +101,18 @@ module.exports = tensei()
102101
// ])
103102
// .plugin(),
104103
graphql().plugin(),
105-
plugin('Custom Slug Validation').setup(
106-
({ indicative }) => {
107-
indicative.validator.extend('slug', {
108-
async: false,
109-
validate(data, field, args, config) {
110-
return data.original[field].match(
111-
/^[a-z0-9]+(?:-[a-z0-9]+)*$/
112-
)
113-
},
114-
})
115-
}
116-
),
104+
plugin('Custom Slug Validation').setup(({ indicative }) => {
105+
indicative.validator.extend('slug', {
106+
async: false,
107+
validate(data, field, args, config) {
108+
return data.original[field].match(
109+
/^[a-z0-9]+(?:-[a-z0-9]+)*$/
110+
)
111+
},
112+
})
113+
}),
117114
])
118-
.databaseConfig('mongodb://localhost/tensei-y', {
119-
useUnifiedTopology: true,
120-
useNewUrlParser: true,
115+
.databaseConfig({
116+
type: 'mysql',
117+
dbName: 'mikrotensei',
121118
})
122-
// .databaseConfig({
123-
// client: 'mysql',
124-
// connection: {
125-
// host: '127.0.0.1',
126-
// user: 'root',
127-
// pass: '',
128-
// database: 'flmg',
129-
// },
130-
// debug: true,
131-
// })

examples/blog/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"license": "MIT",
66
"dependencies": {
77
"@jackfranklin/test-data-bot": "^1.3.0",
8+
"@mikro-orm/mysql": "^4.2.1",
89
"@slynova/flydrive-s3": "^1.0.3",
910
"dotenv": "^8.2.0",
1011
"faker": "^4.1.0",

examples/blog/resources/Comment.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ const { text, textarea, resource, belongsTo } = require('@tensei/core')
33
module.exports = resource('Comment').fields([
44
text('Title').rules('required').searchable(),
55
textarea('Body').rules('required').hideOnIndex(),
6+
textarea('Reply').rules('required', 'max:255').hideOnIndex(),
67
belongsTo('Post'),
78
])

examples/blog/resources/Post.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ module.exports = resource('Post')
6262
.falseLabel('Pending')
6363
.default(false)
6464
.hideOnIndex(),
65-
text('Slug').rules('required', 'slug'),
65+
text('Slug').rules('required', 'slug').unique(),
6666
text('Description').rules('required').hideOnIndex(),
6767
trix('Content').rules('required', 'max:2000', 'min:12').hideOnIndex(),
6868
integer('Av. CPC').rules('required').hideOnDetail(),
@@ -88,6 +88,10 @@ module.exports = resource('Post')
8888
label: 'Sequelize',
8989
value: 'sequelize',
9090
},
91+
{
92+
label: 'Mangojs',
93+
value: 'mangojs'
94+
}
9195
])
9296
.rules('required')
9397
.searchable()

packages/auth/src/index.ts

+16-7
Original file line numberDiff line numberDiff line change
@@ -827,15 +827,22 @@ class Auth {
827827
}
828828
}
829829

830-
const user = await manager(this.userResource(config.database)).database().findOneById(
830+
const user = await manager(this.userResource(config.database))
831+
.database()
832+
.findOneById(
831833
userWithPassword.id,
832834
[],
833835
this.config.rolesAndPermissions
834-
? config.database === 'mongodb' ? [] : [
835-
`${this.roleResource(config.database).data.slug}.${
836-
this.permissionResource(config.database).data.slug
837-
}`
838-
]
836+
? config.database === 'mongodb'
837+
? []
838+
: [
839+
`${
840+
this.roleResource(config.database).data.slug
841+
}.${
842+
this.permissionResource(config.database).data
843+
.slug
844+
}`
845+
]
839846
: []
840847
)
841848

@@ -945,7 +952,9 @@ class Auth {
945952

946953
const user = {
947954
...model,
948-
two_factor_enabled: ['1', 'true'].includes(model.two_factor_enabled)
955+
two_factor_enabled: ['1', 'true'].includes(
956+
model.two_factor_enabled
957+
)
949958
}
950959

951960
if (this.config.rolesAndPermissions) {

packages/common/src/fields/Array.ts

+7
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ export class ArrayField extends Field {
77

88
public databaseFieldType = 'array'
99

10+
constructor(name: string, databaseField?: string) {
11+
super(name, databaseField)
12+
13+
this.property.type = 'string[]'
14+
}
15+
1016
public of(arrayOf: ArrayTypes) {
1117
this.arrayOf = arrayOf
18+
this.property.type = `${arrayOf}[]`
1219

1320
return this
1421
}

packages/common/src/fields/BelongsTo.ts

-69
This file was deleted.

packages/common/src/fields/BelongsToMany.ts

-43
This file was deleted.

packages/common/src/fields/BigInteger.ts

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ export class BigInteger extends Integer {
88
*/
99
public databaseFieldType: string = 'bigInteger'
1010

11-
protected isRelationshipField: boolean = true
12-
1311
/**
1412
*
1513
* This is a short name for the frontend component that

packages/common/src/fields/Boolean.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Field from './Field'
2+
import { BooleanFieldContract } from '@tensei/core'
23

3-
export class BooleanField extends Field {
4+
export class BooleanField extends Field implements BooleanFieldContract {
45
public databaseFieldType: string = 'boolean'
56

67
public component = 'BooleanField'
@@ -21,6 +22,8 @@ export class BooleanField extends Field {
2122
super(name, databaseField)
2223

2324
this.rules('boolean')
25+
26+
this.property.type = 'boolean'
2427
}
2528

2629
public trueLabel(value: string) {

packages/common/src/fields/Date.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ export class DateField extends Field {
5757
constructor(name: string, databaseField?: string) {
5858
super(name, databaseField)
5959

60-
this.default(format(new Date(), this.dateFormat))
60+
this.property.type = 'Date'
61+
62+
// this.default(format(new Date(), this.dateFormat))
6163
}
6264

6365
/**

packages/common/src/fields/DateTime.ts

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ export class DateTime extends DateField {
88
*/
99
public databaseFieldType: string = 'datetime'
1010

11+
public constructor(name: string, databaseField?: string) {
12+
super(name, databaseField)
13+
14+
this.property.type = 'date'
15+
}
16+
1117
/**
1218
*
1319
* This is a short name for the frontend component that

0 commit comments

Comments
 (0)