From b1bd5c341ee378b281aa2770c3d7a28b81a80c32 Mon Sep 17 00:00:00 2001 From: thomashii Date: Tue, 15 Mar 2022 13:25:51 +0800 Subject: [PATCH] Update to support v6.0.0 --- .dockerignore | 9 +- AUTHORS.md | 12 --- CHANGELOG.md | 6 +- CONTRIBUTING.md | 24 ----- Dockerfile | 24 +++-- README.md | 8 +- bin/dev.dart | 4 +- bin/prod.dart | 2 +- config/default.yaml | 1 + lib/src/config/plugins/orm.dart | 17 ++-- lib/src/models/greeting.dart | 1 - lib/src/routes/routes.dart | 6 +- pubspec.yaml | 164 ++++++++++++++++++++++++++++---- views/layout.jael | 4 +- 14 files changed, 190 insertions(+), 92 deletions(-) delete mode 100644 AUTHORS.md delete mode 100644 CONTRIBUTING.md diff --git a/.dockerignore b/.dockerignore index faf23bd..003c2d9 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,10 +1,11 @@ .dart_tool .idea -.pub .vscode +.metals +.git +.github +.packages logs/ test/ build/ -.analysis-options -.packages -*.g.dart \ No newline at end of file +pubspec.lock \ No newline at end of file diff --git a/AUTHORS.md b/AUTHORS.md deleted file mode 100644 index ac95ab5..0000000 --- a/AUTHORS.md +++ /dev/null @@ -1,12 +0,0 @@ -Primary Authors -=============== - -* __[Thomas Hii](dukefirehawk.apps@gmail.com)__ - - Thomas is the current maintainer of the code base. He has refactored and migrated the - code base to support NNBD. - -* __[Tobe O](thosakwe@gmail.com)__ - - Tobe has written much of the original code prior to NNBD migration. He has moved on and - is no longer involved with the project. diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c9985b..74a3368 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,4 @@ ## 1.0.0 -* Changed to use `angel3` packages -* Updated to support NNBD -* Updated README -* Updated default `postgresql` setup -* Updated linter to `package:lints` +* Initial version diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index b34fbca..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,24 +0,0 @@ -# Contribution - -Any help from the open-source community is always welcome and needed: - -1. Found an issue? - - Please [fill a bug report][tracker] with error message and steps to reproduce it. -2. Wish a feature? - - Open a feature request with use cases. -3. Are you using and liking the project? - - Create an article about your use case - - Do a post on your likes and dislikes - - Make a donation. -4. Are you a developer? - - Fix a bug and send a [pull request][pull_request] - - Implement a new feature - - Improve the Unit Tests - - Improve the [User Guide][doc] and send a [document pull request][doc_repo] -5. Have you already helped in any way? - - **Many thanks to the contributors and everybody that uses this project!** - -[tracker]: https://github.com/dukefirehawk/angel/issues -[pull_request]: https://github.com/dukefirehawk/angel/pulls -[doc]: https://angel3-docs.dukefirehawk.com -[doc_repo]: https://github.com/dukefirehawk/angel3-guide/pulls \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index c84bc87..91ac9d2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,24 @@ -FROM google/dart:latest +FROM dart:latest -COPY ./ ./ +# Copy all the source code +COPY ./config /app/config +COPY ./lib /app/lib +COPY ./bin /app/bin +COPY ./views /app/views +COPY ./web /app/web +COPY ./*.yaml /app/ -# Install dependencies, pre-build -RUN pub get +WORKDIR /app +RUN dart pub upgrade -# Optionally build generaed sources. +# Optionally build generated sources. # RUN pub run build_runner build -# Set environment, start server +# Set environment, start server in JIT mode ENV ANGEL_ENV=production EXPOSE 3000 -CMD dart bin/prod.dart +CMD dart ./bin/prod.dart -p 3000 -a 0.0.0.0 + +# Use -j flag to set higher number of isolates +#CMD dart ./bin/prod.dart -p 3000 -a 0.0.0.0 -j 50 + diff --git a/README.md b/README.md index 6da72da..751f212 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ This is an ORM starter application for [Angel3 framework](https://angel3-framewo ## Installation & Setup 1. Download and install [Dart](https://dart.dev/get-dart). -2. Install `postgresql` version 9, 10, 11 or 12. **postgresql 13 is not working as the driver do not support SCRAM** +2. Install `postgresql` version 10, 11, 12 and 13 3. Create a new user and database in postgres using `psql` cli. For example: ```sql @@ -46,13 +46,13 @@ This is an ORM starter application for [Angel3 framework](https://angel3-framewo 3. Insert a message into DB: - ``` + ```bash curl -H "Content-Type: application/json" -X POST -d '{"message":"OK_Message" }' "http://localhost:3000/greetings/" ``` or - ``` + ```bash curl -X POST -d 'message=OK_Message2' "http://localhost:3000/greetings/" ``` @@ -61,7 +61,7 @@ This is an ORM starter application for [Angel3 framework](https://angel3-framewo ``` http://localhost:3000/greetings/ ``` - + ### Production 1. Run the following command: diff --git a/bin/dev.dart b/bin/dev.dart index 926466c..d845458 100644 --- a/bin/dev.dart +++ b/bin/dev.dart @@ -11,7 +11,7 @@ void main() async { hierarchicalLoggingEnabled = true; var hot = HotReloader(() async { - var logger = Logger.detached('{{angel}}') + var logger = Logger.detached('[Angel3]') ..level = Level.ALL ..onRecord.listen(prettyLog); var app = Angel(logger: logger, reflector: MirrorsReflector()); @@ -24,5 +24,5 @@ void main() async { var server = await hot.startServer('127.0.0.1', 3000); print( - '{{angel}} server listening at http://${server.address.address}:${server.port}'); + '[angel] server listening at http://${server.address.address}:${server.port}'); } diff --git a/bin/prod.dart b/bin/prod.dart index efd1e5e..cb647ce 100644 --- a/bin/prod.dart +++ b/bin/prod.dart @@ -26,5 +26,5 @@ import 'package:angel3_production/angel3_production.dart'; // // https://gitter.im/angel_dart/discussion void main(List args) => - Runner('{{angel}}', configureServer, reflector: MirrorsReflector()) + Runner('[Angel3]', configureServer, reflector: MirrorsReflector()) .run(args); diff --git a/config/default.yaml b/config/default.yaml index df1451a..9129586 100644 --- a/config/default.yaml +++ b/config/default.yaml @@ -10,3 +10,4 @@ postgres: password: App1970# useSSL: false time_zone: UTC + diff --git a/lib/src/config/plugins/orm.dart b/lib/src/config/plugins/orm.dart index be286f8..66d66d5 100644 --- a/lib/src/config/plugins/orm.dart +++ b/lib/src/config/plugins/orm.dart @@ -6,15 +6,18 @@ import 'package:angel3_orm_postgres/angel3_orm_postgres.dart'; import 'package:postgres/postgres.dart'; Future configureServer(Angel app) async { - var connection = await connectToPostgres(app.configuration); - await connection.open(); + try { + var connection = await connectToPostgres(app.configuration); + await connection.open(); - var logger = app.environment.isProduction ? null : app.logger; - var executor = PostgreSqlExecutor(connection, logger: logger); + var executor = PostgreSqlExecutor(connection, logger: app.logger); - app - ..container!.registerSingleton(executor) - ..shutdownHooks.add((_) => connection.close()); + app + ..container.registerSingleton(executor) + ..shutdownHooks.add((_) => connection.close()); + } catch (e) { + app.logger.severe("Failed to connect to PostgreSQL. ORM disabled.", e); + } } Future connectToPostgres(Map configuration) async { diff --git a/lib/src/models/greeting.dart b/lib/src/models/greeting.dart index b07c747..89eb1f2 100644 --- a/lib/src/models/greeting.dart +++ b/lib/src/models/greeting.dart @@ -1,5 +1,4 @@ import 'package:angel3_migration/angel3_migration.dart'; -import 'package:angel3_model/angel3_model.dart'; import 'package:angel3_serialize/angel3_serialize.dart'; import 'package:angel3_orm/angel3_orm.dart'; import 'package:optional/optional.dart'; diff --git a/lib/src/routes/routes.dart b/lib/src/routes/routes.dart index 25d82ff..cd0bbf1 100644 --- a/lib/src/routes/routes.dart +++ b/lib/src/routes/routes.dart @@ -19,7 +19,7 @@ AngelConfigurer configureServer(FileSystem fileSystem) { app.get('/', (req, res) => res.render('hello')); app.get('/greetings', (req, res) { - var executor = req.container!.make()!; + var executor = req.container!.make(); var query = GreetingQuery(); return query.get(executor); }); @@ -30,7 +30,7 @@ AngelConfigurer configureServer(FileSystem fileSystem) { if (!req.bodyAsMap.containsKey('message')) { throw AngelHttpException.badRequest(message: 'Missing "message".'); } else { - var executor = req.container!.make()!; + var executor = req.container!.make(); var message = req.bodyAsMap['message'].toString(); var query = GreetingQuery()..values.message = message; var optional = await query.insert(executor); @@ -40,7 +40,7 @@ AngelConfigurer configureServer(FileSystem fileSystem) { app.get('/greetings/:message', (req, res) { var message = req.params['message'] as String; - var executor = req.container!.make()!; + var executor = req.container!.make(); var query = GreetingQuery()..where!.message.equals(message); return query.get(executor); }); diff --git a/pubspec.yaml b/pubspec.yaml index 0cda9fb..8b55243 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,32 +3,156 @@ version: 1.0.0 description: An ORM starter application for Angel3 framework publish_to: none environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.15.0 <3.0.0' dependencies: - angel3_auth: ^4.0.0 - angel3_configuration: ^4.1.0 - angel3_framework: ^4.2.0 - angel3_jael: ^4.2.0 - angel3_migration: ^4.0.0 - angel3_orm: ^4.0.0 - angel3_orm_postgres: ^3.0.0 - angel3_serialize: ^4.1.0 - angel3_production: ^3.1.0 - angel3_static: ^4.1.0 - angel3_validate: ^4.0.0 + angel3_auth: ^6.0.0 + angel3_configuration: ^6.0.0 + angel3_framework: ^6.0.0 + angel3_jael: ^6.0.0 + angel3_migration: ^6.0.0 + angel3_orm: ^6.0.0 + angel3_orm_postgres: ^6.0.0 + angel3_serialize: ^6.0.0 + angel3_production: ^6.0.0 + angel3_static: ^6.0.0 + angel3_validate: ^6.0.0 belatuk_pretty_logging: ^4.0.0 optional: ^6.0.0 logging: ^1.0.0 dev_dependencies: - angel3_hot: ^4.2.0 - angel3_migration_runner: ^4.0.0 - angel3_orm_generator: ^4.1.0 - angel3_serialize_generator: ^4.2.0 - angel3_test: ^4.0.0 + angel3_hot: ^6.0.0 + angel3_migration_runner: ^6.0.0 + angel3_orm_generator: ^6.0.0 + angel3_serialize_generator: ^6.0.0 + angel3_test: ^6.0.0 build_runner: ^2.0.3 io: ^1.0.0 test: ^1.17.5 lints: ^1.0.0 - - - +dependency_overrides: + angel3_container: + git: + url: https://github.com/dukefirehawk/angel.git + ref: release/6.0.0 + path: packages/container/angel_container + angel3_framework: + git: + url: https://github.com/dukefirehawk/angel.git + ref: release/6.0.0 + path: packages/framework + angel3_http_exception: + git: + url: https://github.com/dukefirehawk/angel.git + ref: release/6.0.0 + path: packages/http_exception + angel3_model: + git: + url: https://github.com/dukefirehawk/angel.git + ref: release/6.0.0 + path: packages/model + angel3_route: + git: + url: https://github.com/dukefirehawk/angel.git + ref: release/6.0.0 + path: packages/route + angel3_mock_request: + git: + url: https://github.com/dukefirehawk/angel.git + ref: release/6.0.0 + path: packages/mock_request + angel3_auth: + git: + url: https://github.com/dukefirehawk/angel.git + ref: release/6.0.0 + path: packages/auth + angel3_client: + git: + url: https://github.com/dukefirehawk/angel.git + ref: release/6.0.0 + path: packages/client + angel3_websocket: + git: + url: https://github.com/dukefirehawk/angel.git + ref: release/6.0.0 + path: packages/websocket + angel3_validate: + git: + url: https://github.com/dukefirehawk/angel.git + ref: release/6.0.0 + path: packages/validate + angel3_configuration: + git: + url: https://github.com/dukefirehawk/angel.git + ref: release/6.0.0 + path: packages/configuration + angel3_test: + git: + url: https://github.com/dukefirehawk/angel.git + ref: release/6.0.0 + path: packages/test + jael3: + git: + url: https://github.com/dukefirehawk/angel.git + ref: release/6.0.0 + path: packages/jael/jael + angel3_jael: + git: + url: https://github.com/dukefirehawk/angel.git + ref: release/6.0.0 + path: packages/jael/angel_jael + jael3_preprocessor: + git: + url: https://github.com/dukefirehawk/angel.git + ref: release/6.0.0 + path: packages/jael/jael_preprocessor + angel3_serialize: + git: + url: https://github.com/dukefirehawk/angel.git + ref: release/6.0.0 + path: packages/serialize/angel_serialize + angel3_serialize_generator: + git: + url: https://github.com/dukefirehawk/angel.git + ref: release/6.0.0 + path: packages/serialize/angel_serialize_generator + angel3_hot: + git: + url: https://github.com/dukefirehawk/angel.git + ref: release/6.0.0 + path: packages/hot + angel3_static: + git: + url: https://github.com/dukefirehawk/angel.git + ref: release/6.0.0 + path: packages/static + angel3_production: + path: ../belatuk/packages/production +# git: +# url: https://github.com/dukefirehawk/angel.git +# ref: release/6.0.0 +# path: packages/production + angel3_orm: + git: + url: https://github.com/dukefirehawk/angel.git + ref: release/6.0.0 + path: packages/orm/angel_orm + angel3_orm_generator: + git: + url: https://github.com/dukefirehawk/angel.git + ref: release/6.0.0 + path: packages/orm/angel_orm_generator + angel3_orm_postgres: + git: + url: https://github.com/dukefirehawk/angel.git + ref: release/6.0.0 + path: packages/orm/angel_orm_postgres + angel3_migration: + git: + url: https://github.com/dukefirehawk/angel.git + ref: release/6.0.0 + path: packages/orm/angel_migration + angel3_migration_runner: + git: + url: https://github.com/dukefirehawk/angel.git + ref: release/6.0.0 + path: packages/orm/angel_migration_runner diff --git a/views/layout.jael b/views/layout.jael index ea0714b..7a2c5cd 100644 --- a/views/layout.jael +++ b/views/layout.jael @@ -3,8 +3,8 @@ {{ title ?? 'Angel' }} - - + +