Initial commit
This commit is contained in:
commit
5917935505
7
.env
Normal file
7
.env
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
DATON_LOGGING_LEVEL=6
|
||||||
|
APP_NAME="My First Daton App!"
|
||||||
|
|
||||||
|
DB_USERNAME=garrettmills
|
||||||
|
DB_PASSWORD=garrettmills
|
||||||
|
DB_DATABASE=garrettmills
|
||||||
|
|
5
.idea/.gitignore
vendored
Normal file
5
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
12
.idea/daton-app.iml
Normal file
12
.idea/daton-app.iml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
6
.idea/deno.xml
Normal file
6
.idea/deno.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="DenoSettings">
|
||||||
|
<option name="useDeno" value="true" />
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/misc.xml
Normal file
6
.idea/misc.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="JavaScriptSettings">
|
||||||
|
<option name="languageLevel" value="ES6" />
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/daton-app.iml" filepath="$PROJECT_DIR$/.idea/daton-app.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
2
app/assets/.gitkeep
Normal file
2
app/assets/.gitkeep
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
27
app/configs/app.config.ts
Normal file
27
app/configs/app.config.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import { Daton } from '../../bundle/daton.ts'
|
||||||
|
const { env, ViewEngine } = Daton
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: env('APP_NAME', 'Daton'),
|
||||||
|
|
||||||
|
views: {
|
||||||
|
/*
|
||||||
|
* View engine that should be used to render templates.
|
||||||
|
* Options are Handlebars, Ejs, or Denjuck.
|
||||||
|
*/
|
||||||
|
engine: ViewEngine.Handlebars,
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Relative path from the app directory to the base directory where
|
||||||
|
* view files should be looked up.
|
||||||
|
*/
|
||||||
|
base_dir: 'http/views',
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If using Handlebars, optionally, the path to the directory within the
|
||||||
|
* base_dir that contains the partials. They will be automatically registered
|
||||||
|
* with Handlebars.
|
||||||
|
*/
|
||||||
|
partials_dir: 'partials',
|
||||||
|
},
|
||||||
|
}
|
17
app/configs/db.config.ts
Normal file
17
app/configs/db.config.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { Daton } from '../../bundle/daton.ts'
|
||||||
|
const { env } = Daton
|
||||||
|
|
||||||
|
export default {
|
||||||
|
|
||||||
|
connections: {
|
||||||
|
default: {
|
||||||
|
type: env('DB_TYPE', 'postgres'),
|
||||||
|
user: env('DB_USERNAME', 'daton'),
|
||||||
|
password: env('DB_PASSWORD'),
|
||||||
|
database: env('DB_DATABASE', 'daton'),
|
||||||
|
hostname: env('DB_HOSTNAME', 'localhost'),
|
||||||
|
port: env('DB_PORT', 5432),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
18
app/configs/server.config.ts
Normal file
18
app/configs/server.config.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
export default {
|
||||||
|
port: 8080,
|
||||||
|
use_ssl: false,
|
||||||
|
prefix: '/',
|
||||||
|
allow_mount_without_prefix: false,
|
||||||
|
|
||||||
|
request_timeout: 15000, // 15 seconds
|
||||||
|
|
||||||
|
powered_by: {
|
||||||
|
enable: true,
|
||||||
|
text: 'Daton',
|
||||||
|
},
|
||||||
|
|
||||||
|
session: {
|
||||||
|
driver: 'database', // memory | database
|
||||||
|
model: 'http:Session', // required for database
|
||||||
|
},
|
||||||
|
}
|
10
app/http/controllers/Home.controller.ts
Normal file
10
app/http/controllers/Home.controller.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import {Controller, Request, view, Injectable} from '../../../bundle/daton.ts'
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export default class HomeController extends Controller {
|
||||||
|
|
||||||
|
async get_home(request: Request) {
|
||||||
|
return view('home', { greeting: 'Hello' })
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
9
app/http/middleware/Test.middleware.ts
Normal file
9
app/http/middleware/Test.middleware.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { Middleware, Request, http, HTTPStatus } from '../../../bundle/daton.ts'
|
||||||
|
|
||||||
|
export default class TestMiddleware extends Middleware {
|
||||||
|
public async handleRequest(request: Request) {
|
||||||
|
if ( Math.random() >= 0.5 ) {
|
||||||
|
return http(HTTPStatus.FORBIDDEN, 'Well, you were unlucky.')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
app/http/routes/home.routes.ts
Normal file
11
app/http/routes/home.routes.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { RouterDefinition } from '../../../bundle/daton.ts'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
prefix: '/',
|
||||||
|
middleware: [],
|
||||||
|
get: {
|
||||||
|
'/': 'controller::Home.get_home',
|
||||||
|
'/maybe': ['middleware::Test', 'controller::Home.get_home'],
|
||||||
|
'/statics/**': { handler: 'daton::static', arg: 'assets' },
|
||||||
|
},
|
||||||
|
} as RouterDefinition
|
9
app/http/views/home.hbs
Normal file
9
app/http/views/home.hbs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<html>
|
||||||
|
{{> header }}
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>Welcome to Daton</h1>
|
||||||
|
<h2>Daton is an opinionated application framework for Deno</h2>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
37
app/http/views/partials/header.hbs
Normal file
37
app/http/views/partials/header.hbs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
|
||||||
|
<title>Daton</title>
|
||||||
|
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Quicksand:300,500" rel="stylesheet">
|
||||||
|
|
||||||
|
<style>
|
||||||
|
html, body {
|
||||||
|
background-color: #F2F4FF;
|
||||||
|
color: #36453B;
|
||||||
|
font-family: 'Quicksand', sans-serif;
|
||||||
|
font-weight: 500;
|
||||||
|
height: 100vh;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
height: 100vh;
|
||||||
|
margin: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container h1 {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container h2 {
|
||||||
|
font-weight: 300;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
24
app/models/LoginAttempt.model.ts
Normal file
24
app/models/LoginAttempt.model.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import { Model, Type, Field, Relation } from '../../bundle/daton_orm.ts'
|
||||||
|
import User from "./User.model.ts";
|
||||||
|
|
||||||
|
export default class LoginAttempt extends Model<LoginAttempt> {
|
||||||
|
protected static table = 'daton_login_attempts'
|
||||||
|
protected static key = 'daton_login_attempt_id'
|
||||||
|
|
||||||
|
protected static readonly CREATED_AT = 'attempt_date'
|
||||||
|
protected static readonly UPDATED_AT = null
|
||||||
|
|
||||||
|
@Field(Type.int)
|
||||||
|
protected daton_login_attempt_id?: number
|
||||||
|
|
||||||
|
@Field(Type.int)
|
||||||
|
protected user_id!: number
|
||||||
|
|
||||||
|
@Field(Type.timestamp)
|
||||||
|
protected attempt_date!: Date
|
||||||
|
|
||||||
|
@Relation()
|
||||||
|
public user() {
|
||||||
|
return this.belongs_to_one(User, 'login_attempts')
|
||||||
|
}
|
||||||
|
}
|
27
app/models/User.model.ts
Normal file
27
app/models/User.model.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import { Model, Type, Field, Relation } from '../../bundle/daton_orm.ts'
|
||||||
|
import LoginAttemptModel from './LoginAttempt.model.ts'
|
||||||
|
|
||||||
|
export default class User extends Model<User> {
|
||||||
|
protected static table = 'daton_users'
|
||||||
|
protected static key = 'user_id'
|
||||||
|
|
||||||
|
protected static readonly CREATED_AT = 'created_at'
|
||||||
|
protected static readonly UPDATED_AT = 'updated_at'
|
||||||
|
|
||||||
|
@Field(Type.int)
|
||||||
|
protected user_id?: number
|
||||||
|
|
||||||
|
@Field(Type.varchar)
|
||||||
|
protected first_name!: String
|
||||||
|
|
||||||
|
@Field(Type.varchar)
|
||||||
|
protected last_name!: String
|
||||||
|
|
||||||
|
@Field(Type.bool)
|
||||||
|
protected active!: Boolean
|
||||||
|
|
||||||
|
@Relation()
|
||||||
|
public login_attempts() {
|
||||||
|
return this.has_many(LoginAttemptModel)
|
||||||
|
}
|
||||||
|
}
|
19
app/models/http/Session.model.ts
Normal file
19
app/models/http/Session.model.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { SessionModel } from '../../../bundle/daton.ts'
|
||||||
|
import { Field, Type } from '../../../bundle/daton_orm.ts'
|
||||||
|
|
||||||
|
export default class Session extends SessionModel {
|
||||||
|
protected static table = 'sessions'
|
||||||
|
protected static key = 'session_key'
|
||||||
|
|
||||||
|
protected static readonly CREATED_AT = 'start_time'
|
||||||
|
protected static readonly UPDATED_AT = null // No updated at
|
||||||
|
|
||||||
|
@Field(Type.varchar)
|
||||||
|
protected session_key!: string
|
||||||
|
|
||||||
|
@Field(Type.int)
|
||||||
|
protected user_id?: number
|
||||||
|
|
||||||
|
@Field(Type.timestamp)
|
||||||
|
protected start_time!: Date
|
||||||
|
}
|
0
app/services/.gitkeep
Normal file
0
app/services/.gitkeep
Normal file
25
build.sh
Executable file
25
build.sh
Executable file
@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
### CONFIGURATION ###
|
||||||
|
BUILD_ENTRY_POINT="index.ts"
|
||||||
|
BUILD_DENO_PATH="$(which deno)"
|
||||||
|
BUILD_DENO_FLAGS="--unstable --allow-read --allow-env --allow-net"
|
||||||
|
BUILD_DENO_BINARY="application.bin"
|
||||||
|
|
||||||
|
|
||||||
|
### BUILD SCRIPT ###
|
||||||
|
rm -rf build "$BUILD_DENO_BINARY"
|
||||||
|
mkdir build
|
||||||
|
|
||||||
|
cp "$BUILD_DENO_PATH" build
|
||||||
|
deno bundle -c ./tsconfig.json --unstable --importmap=./import-map.json "./${BUILD_ENTRY_POINT}" build/bundle.js
|
||||||
|
cp ./tsconfig.json build/tsconfig.json
|
||||||
|
|
||||||
|
echo "#!/bin/sh" > build/launch
|
||||||
|
echo 'DIR="$(cd "$(dirname "$0")" ; pwd -P)"' >> build/launch
|
||||||
|
echo "exec \$DIR/deno run $BUILD_DENO_FLAGS \$DIR/bundle.js \$@" >> build/launch
|
||||||
|
|
||||||
|
chmod +x build/launch
|
||||||
|
warp-packer -a linux-x64 -i build -e launch -o "$BUILD_DENO_BINARY"
|
||||||
|
|
||||||
|
rm -rf build
|
7
bundle/daton.ts
Normal file
7
bundle/daton.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
export * from 'daton-lib/module.ts'
|
||||||
|
export * from '../../daton/di/module.ts'
|
||||||
|
|
||||||
|
import * as std from 'daton-external/std.ts'
|
||||||
|
export { std }
|
||||||
|
|
||||||
|
export * as Daton from 'daton-lib/mod.ts'
|
1
bundle/daton_orm.ts
Normal file
1
bundle/daton_orm.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from 'daton-orm/module.ts'
|
14
bundle/daton_units.ts
Normal file
14
bundle/daton_units.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
export { default as ConfigUnit } from 'daton-lib/unit/Config.ts'
|
||||||
|
export { DatabaseUnit } from 'daton-orm/DatabaseUnit.ts'
|
||||||
|
export { default as ControllerUnit } from 'daton-lib/unit/Controllers.ts'
|
||||||
|
export { default as MiddlewareUnit } from 'daton-lib/unit/Middlewares.ts'
|
||||||
|
export { default as RoutesUnit } from 'daton-lib/unit/Routes.ts'
|
||||||
|
export { default as HttpKernelUnit } from 'daton-lib/unit/HttpKernel.ts'
|
||||||
|
export { default as ModelsUnit } from 'daton-orm/ModelsUnit.ts'
|
||||||
|
export { default as HttpServerUnit } from 'daton-lib/unit/HttpServer.ts'
|
||||||
|
export { default as RoutingUnit } from 'daton-lib/unit/Routing.ts'
|
||||||
|
export { default as ServicesUnit } from 'daton-lib/unit/Services.ts'
|
||||||
|
export { default as ViewEngineUnit } from 'daton-lib/unit/ViewEngine.ts'
|
||||||
|
export { default as DatonMiddlewareUnit } from 'daton-lib/unit/DatonMiddleware.ts'
|
||||||
|
// export { default as CLIAppUnit } from 'daton-cli/CLIAppUnit.ts'
|
||||||
|
// export { default as CLIUnit } from 'daton-cli/CLIUnit.ts'
|
9
import-map.bak.json
Normal file
9
import-map.bak.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"imports": {
|
||||||
|
"daton/": "https://code.garrettmills.dev/garrettmills/daton/raw/branch/master/",
|
||||||
|
"daton-lib/": "https://code.garrettmills.dev/garrettmills/daton/raw/branch/master/lib/src/",
|
||||||
|
"daton-di/": "https://code.garrettmills.dev/garrettmills/daton/raw/branch/master/di/src/",
|
||||||
|
"daton-orm/": "https://code.garrettmills.dev/garrettmills/daton/raw/branch/master/orm/src/",
|
||||||
|
"daton-external/": "https://code.garrettmills.dev/garrettmills/daton/raw/branch/master/lib/src/external/"
|
||||||
|
}
|
||||||
|
}
|
9
import-map.json
Normal file
9
import-map.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"imports": {
|
||||||
|
"daton/": "https://code.garrettmills.dev/garrettmills/daton/raw/branch/master/",
|
||||||
|
"daton-lib/": "https://code.garrettmills.dev/garrettmills/daton/raw/branch/master/lib/src/",
|
||||||
|
"daton-di/": "https://code.garrettmills.dev/garrettmills/daton/raw/branch/master/di/src/",
|
||||||
|
"daton-orm/": "https://code.garrettmills.dev/garrettmills/daton/raw/branch/master/orm/src/",
|
||||||
|
"daton-external/": "https://code.garrettmills.dev/garrettmills/daton/raw/branch/master/lib/src/external/"
|
||||||
|
}
|
||||||
|
}
|
25
index.ts
Executable file
25
index.ts
Executable file
@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/env -S deno run -c ./tsconfig.json --unstable --allow-read --allow-env --allow-net --importmap=./import-map.json
|
||||||
|
/* Main executable for the Daton app. */
|
||||||
|
|
||||||
|
import { make, Scaffolding, Application } from './bundle/daton.ts'
|
||||||
|
import units from './units.ts'
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Let's get up and running. The scaffolding provides the bare minimum
|
||||||
|
* amount of support required to get Daton up and running. The app handles
|
||||||
|
* the rest.
|
||||||
|
*
|
||||||
|
* Daton will automatically load and process application resources, which is
|
||||||
|
* why we need to pass in the base path of this script.
|
||||||
|
*/
|
||||||
|
console.log('Import URL')
|
||||||
|
console.log(import.meta.url)
|
||||||
|
const scaffolding = make(Scaffolding, import.meta.url)
|
||||||
|
await scaffolding.up()
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Now, import the units and start the application. The units define each
|
||||||
|
* modular piece of functionality that is managed by the Daton app.
|
||||||
|
*/
|
||||||
|
const app = make(Application, units)
|
||||||
|
await app.run()
|
6
tsconfig.json
Normal file
6
tsconfig.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"emitDecoratorMetadata": true
|
||||||
|
}
|
||||||
|
}
|
29
units.ts
Normal file
29
units.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import {
|
||||||
|
ConfigUnit,
|
||||||
|
DatabaseUnit,
|
||||||
|
ControllerUnit,
|
||||||
|
MiddlewareUnit,
|
||||||
|
RoutesUnit,
|
||||||
|
HttpKernelUnit,
|
||||||
|
ModelsUnit,
|
||||||
|
HttpServerUnit,
|
||||||
|
RoutingUnit,
|
||||||
|
ServicesUnit,
|
||||||
|
ViewEngineUnit,
|
||||||
|
DatonMiddlewareUnit,
|
||||||
|
} from './bundle/daton_units.ts'
|
||||||
|
|
||||||
|
export default [
|
||||||
|
ServicesUnit,
|
||||||
|
ConfigUnit,
|
||||||
|
DatabaseUnit,
|
||||||
|
ModelsUnit,
|
||||||
|
ViewEngineUnit,
|
||||||
|
HttpKernelUnit,
|
||||||
|
DatonMiddlewareUnit,
|
||||||
|
MiddlewareUnit,
|
||||||
|
ControllerUnit,
|
||||||
|
RoutesUnit,
|
||||||
|
RoutingUnit,
|
||||||
|
HttpServerUnit,
|
||||||
|
]
|
Loading…
Reference in New Issue
Block a user