Skip to content

Commit

Permalink
feat(next): create basic package for using next.js framework
Browse files Browse the repository at this point in the history
  • Loading branch information
Frantz Kati committed Dec 4, 2020
1 parent ef3c86c commit a0c3e02
Show file tree
Hide file tree
Showing 26 changed files with 1,694 additions and 98 deletions.
7 changes: 7 additions & 0 deletions examples/next/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules/
.env
connect-session-knex.sqlite
blog.sqlite
storage/
mikrotensei
.next
13 changes: 13 additions & 0 deletions examples/next/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require('dotenv').config()
const { auth } = require('@tensei/auth')
const { next } = require('@tensei/next')
const { tensei } = require('@tensei/core')
const { graphql } = require('@tensei/graphql')

tensei()
.plugins([auth().plugin(), next().plugin(), graphql().plugin()])
.databaseConfig({
dbName: 'mikrotensei.sqlite',
type: 'sqlite'
})
.start()
Binary file added examples/next/mikrotensei.sqlite
Binary file not shown.
3 changes: 3 additions & 0 deletions examples/next/nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignoreRoot": [".git"]
}
21 changes: 21 additions & 0 deletions examples/next/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@examples/next",
"version": "0.4.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"@mikro-orm/sqlite": "^4.3.2",
"next": "^10.0.3",
"react": "^17.0.1",
"react-dom": "^17.0.1"
},
"devDependencies": {
"nodemon": "^2.0.4",
"prettier": "^2.0.5"
},
"scripts": {
"start": "nodemon --watch ../../node_modules app.js",
"prettier": "prettier --write './**/*.{js,json,css}'"
},
"private": true
}
3 changes: 3 additions & 0 deletions examples/next/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Home() {
return <h1>PAGE LOADED BY NEXT JS</h1>
}
9 changes: 5 additions & 4 deletions packages/core/Tensei.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,8 @@ export class Tensei implements TenseiContract {

this.server.listen(port, () => {
this.ctx.logger.success(
`🚀 Access your server on ${
this.ctx.serverUrl || `http://127.0.0.1:${port}`
}`
`🚀 Access your server on ${this.ctx.serverUrl ||
`http://127.0.0.1:${port}`}`
)
})
}
Expand Down Expand Up @@ -563,7 +562,9 @@ export class Tensei implements TenseiContract {
}

private mail(driverName: SupportedDrivers, mailConfig = {}) {
this.ctx.mailer = mail().connection(driverName).config(mailConfig)
this.ctx.mailer = mail()
.connection(driverName)
.config(mailConfig)

return this
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class Database {
}

private generateEntityClass(resource: ResourceContract) {
const entityClass = function () {}
const entityClass = function() {}

Object.defineProperty(entityClass, 'name', {
value: resource.data.pascalCaseName,
Expand Down
5 changes: 4 additions & 1 deletion packages/express-session-mikro-orm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ const StoreFactory = (Store: any) => {
this.options.tableName,
(table: any) => {
table.string('session_id').primary()
table.datetime('expires').nullable().index()
table
.datetime('expires')
.nullable()
.index()
table.text('data').notNullable()
}
)
Expand Down
3 changes: 3 additions & 0 deletions packages/media/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build
tensei.sqlite
.env
4 changes: 3 additions & 1 deletion packages/media/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ class MediaLibrary {

if (fileFields.length) {
MediaResource.fields([
belongsTo(resource.data.name).nullable().hidden()
belongsTo(resource.data.name)
.nullable()
.hidden()
])
}
})
Expand Down
12 changes: 9 additions & 3 deletions packages/media/src/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@ export const mediaResource = () =>
.searchable(),
integer('Width').nullable(),
integer('Height').nullable(),
text('Original Filename').nullable().searchable(),
text('Original Filename')
.nullable()
.searchable(),
text('Extension')
.description('The file extension, for example psd, pdf, png')
.searchable(),
text('Mime Type').nullable().searchable(),
text('Mime Type')
.nullable()
.searchable(),
text('Hash').searchable(),
text('Path').nullable().searchable(),
text('Path')
.nullable()
.searchable(),
text('Alt Text').nullable(),
text('Disk').nullable(),
json('Disk Meta').nullable(),
Expand Down
3 changes: 3 additions & 0 deletions packages/next/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build
tensei.sqlite
.env
58 changes: 58 additions & 0 deletions packages/next/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<div align="center">
<br />
<br />
<img src="https://res.cloudinary.com/bahdcoder/image/upload/v1604236130/Asset_1_4x_fhcfyg.png" width="450px">
</div>

<br />

<br />

<div align="center">
<h3>
<strong>
The fastest and easiest way to build powerful and secure APIs
</strong>
</h3>
<p>Open source Node.js Headless CMS 🚀. </p>
</div>

<br />

<div align="center">


[![github-actions-image]][github-actions-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url]

</div>

<div align="center">
<h3>
<a href="https://tenseijs.com">
Website
</a>
<span> | </span>
<a href="https://tenseijs.com/docs">
Guides
</a>
<span> | </span>
<a href="CONTRIBUTING.md">
Contributing
</a>
</h3>
</div>

<div align="center">
<sub>Built with ❤︎ by <a href="https://github.com/bahdcoder">Kati Frantz</a>
</div>

[github-actions-image]: https://img.shields.io/github/workflow/status/tenseijs/tensei/Tests?style=for-the-badge
[github-actions-url]: https://github.com/tenseijs/tensei/actions?query=workflow%3ATests "github-actions"

[npm-image]: https://img.shields.io/npm/v/@tensei/core.svg?style=for-the-badge&logo=npm
[npm-url]: https://www.npmjs.com/package/@tensei/core "npm"

[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript

[license-url]: LICENSE.md
[license-image]: https://img.shields.io/github/license/tenseijs/tensei?style=for-the-badge
33 changes: 33 additions & 0 deletions packages/next/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "@tensei/next",
"version": "0.4.1",
"main": "./build/index.js",
"license": "MIT",
"types": "./build/index.d.ts",
"files": [
"build/"
],
"devDependencies": {},
"scripts": {
"prettier": "prettier --write './**/*.{js,json,ts,css}'",
"build": "tsc --p tsconfig.json",
"dev": "tsc --watch --p tsconfig.json",
"test": "jest --verbose --runInBand --forceExit"
},
"dependencies": {
"next": "^10.0.3"
},
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"publishConfig": {
"access": "public"
}
}
20 changes: 20 additions & 0 deletions packages/next/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Next from 'next'
import { plugin } from '@tensei/common'

class NextJSPlugin {
plugin() {
return plugin('Next JS').boot(async ctx => {
const app = Next({
dev: process.env.NODE_ENV !== 'production'
})

await app.prepare()

ctx.app.all('*', (request, response) =>
app.getRequestHandler()(request, response)
)
})
}
}

export const next = () => new NextJSPlugin()
15 changes: 15 additions & 0 deletions packages/next/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "ES2017",
"module": "commonjs",
"declaration": true,
"outDir": "./build",
"strict": true,
"baseUrl": "./src",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"types": ["@types/jest"]
},
"exclude": ["__tests__", "build"]
}
4 changes: 3 additions & 1 deletion packages/tests/helpers/resources/Comment.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { text, resource, textarea, belongsTo } from '@tensei/common'

export default resource('Comment').fields([
text('Title').rules('required').searchable(),
text('Title')
.rules('required')
.searchable(),
textarea('Body').rules('required'),
belongsTo('Post')
])
4 changes: 3 additions & 1 deletion packages/tests/helpers/resources/Post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ export default resource('Post')
textarea('Content')
.rules('required', 'max:2000', 'min:12')
.hideOnIndex(),
integer('Av. CPC').rules('required').hideOnDetail(),
integer('Av. CPC')
.rules('required')
.hideOnDetail(),
select('Category')
.options([
{
Expand Down
9 changes: 7 additions & 2 deletions packages/tests/helpers/resources/Tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ import { text, resource, textarea, belongsToMany, number } from '@tensei/common'

export default resource('Tag')
.fields([
text('Name').rules('required').searchable(),
number('Priority').nullable().default(1).rules('integer', 'under:5'),
text('Name')
.rules('required')
.searchable(),
number('Priority')
.nullable()
.default(1)
.rules('integer', 'under:5'),
textarea('Description'),
belongsToMany('Post')
])
Expand Down
4 changes: 3 additions & 1 deletion packages/tests/helpers/resources/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { text, resource, hasMany } from '@tensei/common'

export default resource('User')
.fields([
text('Full name').searchable().rules('required'),
text('Full name')
.searchable()
.rules('required'),
text('Email')
.unique()
.searchable()
Expand Down
4 changes: 3 additions & 1 deletion packages/tests/helpers/resources/UserNoRel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { text, hasMany, resource } from '@tensei/common'

export default resource('User')
.fields([
text('Full name').searchable().rules('required'),
text('Full name')
.searchable()
.rules('required'),
text('Email')
.unique()
.searchable()
Expand Down
27 changes: 22 additions & 5 deletions packages/tests/packages/auth/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ test('Registers auth resources when plugin is registered', async () => {
test('Can customize the name of the authenticator user', async () => {
const {
ctx: { resources }
} = await setup([auth().user('Customer').plugin()])
} = await setup([
auth()
.user('Customer')
.plugin()
])

expect(
resources.find(resource => resource.data.name === 'Customer')
Expand All @@ -27,7 +31,11 @@ test('Can customize the name of the authenticator user', async () => {
test('Enabling roles and permissions registers Role and permission resources', async () => {
const {
ctx: { resources }
} = await setup([auth().rolesAndPermissions().plugin()])
} = await setup([
auth()
.rolesAndPermissions()
.plugin()
])

expect(
resources.filter(resource =>
Expand Down Expand Up @@ -205,7 +213,10 @@ test('Can request a password reset and reset password', async () => {
},
app
} = await setup([
auth().verifyEmails().user('Student').plugin(),
auth()
.verifyEmails()
.user('Student')
.plugin(),
graphql().plugin(),
setupFakeMailer(mailerMock)
])
Expand Down Expand Up @@ -298,7 +309,10 @@ test('Can login and stay authenticated with cookie based applications', async ()
},
app
} = await setup([
auth().verifyEmails().user('Student').plugin(),
auth()
.verifyEmails()
.user('Student')
.plugin(),
graphql().plugin()
])

Expand Down Expand Up @@ -621,7 +635,10 @@ test('if a refresh token is used twice (compromised), the user is automatically
},
app
} = await setup([
auth().user('Customer').noCookies().plugin(),
auth()
.user('Customer')
.noCookies()
.plugin(),
graphql().plugin()
])

Expand Down
Loading

0 comments on commit a0c3e02

Please sign in to comment.