Browse Source

Updated libraries (#7007)

Thomas Hii 3 years ago
parent
commit
8f0e27e066

+ 4 - 0
frameworks/Dart/angel3/.gitignore

@@ -0,0 +1,4 @@
+.factorypath
+.packages
+.dart_tool
+.metals

+ 1 - 1
frameworks/Dart/angel3/README.md

@@ -44,7 +44,7 @@ http://localhost:8080/query?queries=
 
 ### UPDATE
 
-http://localhost:8080/update?queries=
+http://localhost:8080/updates?queries=
 
 ### FORTUNES
 

+ 1 - 1
frameworks/Dart/angel3/angel3.dockerfile

@@ -18,4 +18,4 @@ RUN dart pub get
 # Set environment, start server
 ENV ANGEL_ENV=production
 EXPOSE 8080
-CMD dart ./run/prod.dart -p 8080 -a 0.0.0.0
+CMD dart ./run/prod.dart -p 8080 -a 0.0.0.0 -j 20

+ 1 - 0
frameworks/Dart/angel3/orm/config/default.yaml

@@ -3,6 +3,7 @@ jwt_secret: INSECURE_DEFAULT_SECRET
 host: 127.0.0.1
 port: 8080
 postgres:
+  #host: localhost
   host: tfb-database
   port: 5432
   database_name: hello_world

+ 2 - 0
frameworks/Dart/angel3/orm/config/development.yaml

@@ -0,0 +1,2 @@
+# Development-only server configuration.
+debug: true

+ 5 - 1
frameworks/Dart/angel3/orm/lib/src/config/config.dart

@@ -2,6 +2,7 @@
 import 'package:angel3_configuration/angel3_configuration.dart';
 import 'package:angel3_framework/angel3_framework.dart';
 import 'package:angel3_jael/angel3_jael.dart';
+import 'package:jael3/jael3.dart';
 import 'package:file/file.dart';
 import 'plugins/plugins.dart' as plugins;
 
@@ -16,7 +17,10 @@ AngelConfigurer configureServer(FileSystem fileSystem) {
     // Configure our application to render Jael templates from the `views/` directory.
     //
     // See: https://github.com/angel-dart/jael
-    await app.configure(jael(fileSystem.directory('views'), minified: true));
+    var viewsDirectory = fileSystem.directory('views');
+    var viewCache = <String, Document>{};
+    jaelTemplatePreload(viewsDirectory, viewCache);
+    await app.configure(jael(viewsDirectory, cache: viewCache));
 
     // Apply another plug-ins, i.e. ones that *you* have written.
     //

+ 34 - 2
frameworks/Dart/angel3/orm/lib/src/config/plugins/orm.dart

@@ -4,17 +4,21 @@ import 'package:angel3_framework/angel3_framework.dart';
 import 'package:angel3_orm/angel3_orm.dart';
 import 'package:angel3_orm_postgres/angel3_orm_postgres.dart';
 import 'package:postgres/postgres.dart';
+import 'package:postgres_pool/postgres_pool.dart';
 
 Future<void> configureServer(Angel app) async {
+  var logger = app.environment.isProduction ? null : app.logger;
+
   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 = await connectToPostgresPool(app.configuration, logger);
+
   app
     ..container!.registerSingleton<QueryExecutor>(executor)
     ..shutdownHooks.add((_) => connection.close());
+//    ..shutdownHooks.add((_) => executor.close());
 }
 
 Future<PostgreSQLConnection> connectToPostgres(Map configuration) async {
@@ -33,3 +37,31 @@ Future<PostgreSQLConnection> connectToPostgres(Map configuration) async {
       useSSL: postgresConfig['use_ssl'] as bool? ?? false);
   return connection;
 }
+
+Future<PostgreSqlPoolExecutor> connectToPostgresPool(
+    Map configuration, dynamic logger) async {
+  var postgresConfig = configuration['postgres'] as Map? ?? {};
+  var _pool = PgPool(
+    PgEndpoint(
+        host: postgresConfig['host'] as String? ?? 'localhost',
+        port: postgresConfig['port'] as int? ?? 5432,
+        database: postgresConfig['database_name'] as String? ??
+            Platform.environment['USER'] ??
+            Platform.environment['USERNAME'] ??
+            '',
+        username: postgresConfig['username'] as String?,
+        password: postgresConfig['password'] as String?),
+    settings: PgPoolSettings()
+      ..maxConnectionAge = Duration(hours: 1)
+      ..concurrency = 10,
+  );
+
+  // Run sql to create the tables in a transaction
+  //await _pool.runTx((conn) async {
+  //  for (var s in schemas) {
+  //    await conn.execute(await File('test/migrations/$s.sql').readAsString());
+  //  }
+  //});
+
+  return PostgreSqlPoolExecutor(_pool, logger: logger);
+}

+ 14 - 5
frameworks/Dart/angel3/orm/lib/src/routes/controllers/controllers.dart

@@ -2,7 +2,6 @@ import 'dart:async';
 import 'dart:math';
 import 'package:angel3_framework/angel3_framework.dart';
 import 'package:angel3_orm/angel3_orm.dart';
-import 'package:optional/optional.dart';
 import '../../models/fortune.dart';
 import '../../models/world.dart';
 
@@ -44,9 +43,7 @@ Future configureServer(Angel app) async {
   }
 
   // Return data in json
-  app.get('/json', (req, res) async {
-    res.json({'message': 'Hello, World!'});
-  });
+  app.get('/json', (req, res) => res.json({'message': 'Hello, World!'}));
 
   // Return data in plaintext
   app.get('/plaintext', (req, res) async {
@@ -56,14 +53,21 @@ Future configureServer(Angel app) async {
 
   // Add an entry and sort a list of fortune
   app.get('/fortunes', (req, res) async {
+    //var stopwatch = Stopwatch()..start();
+
     var list = await FortuneQuery().get(executor);
 
+    //print('Query Time: ${stopwatch.elapsed.inMilliseconds}ms');
+
     list.add(
         Fortune(id: 0, message: 'Additional fortune added at request time.'));
     list.sort((a, b) => a.message?.compareTo(b.message ?? '') ?? 0);
 
+    //print('Process Time: ${stopwatch.elapsed.inMilliseconds}ms');
+    //stopwatch.stop();
+
     //res.json(list);
-    await res.render('listing', {'fortunes': list});
+    res.render('listing', {'fortunes': list});
   });
 
   // Find a random World
@@ -98,6 +102,8 @@ Future configureServer(Angel app) async {
 
   // Update a list of worlds
   app.get('/updates', (req, res) async {
+    //var stopwatch = Stopwatch()..start();
+
     var params = req.queryParameters;
     var queryLimit = _parseQueryCount(params['queries'] as String?);
     var listOfIds = _generateIds(queryLimit);
@@ -115,6 +121,9 @@ Future configureServer(Angel app) async {
       result.add(updatedRec.value);
     }
 
+    //rint('Process Time: ${stopwatch.elapsed.inMilliseconds}ms');
+    //stopwatch.stop();
+
     res.json(result);
   });
 }

+ 53 - 25
frameworks/Dart/angel3/orm/pubspec.lock

@@ -7,14 +7,14 @@ packages:
       name: _fe_analyzer_shared
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "30.0.0"
+    version: "31.0.0"
   analyzer:
     dependency: transitive
     description:
       name: analyzer
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "2.7.0"
+    version: "2.8.0"
   angel3_auth:
     dependency: "direct main"
     description:
@@ -49,7 +49,7 @@ packages:
       name: angel3_framework
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "4.2.2"
+    version: "4.2.3"
   angel3_hot:
     dependency: "direct dev"
     description:
@@ -70,21 +70,21 @@ packages:
       name: angel3_jael
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "4.2.1"
+    version: "4.3.1"
   angel3_migration:
     dependency: "direct main"
     description:
       name: angel3_migration
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "4.0.0"
+    version: "4.0.2"
   angel3_migration_runner:
     dependency: "direct dev"
     description:
       name: angel3_migration_runner
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "4.0.0"
+    version: "4.1.0"
   angel3_mock_request:
     dependency: transitive
     description:
@@ -98,35 +98,35 @@ packages:
       name: angel3_model
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "3.1.0"
+    version: "3.1.1"
   angel3_orm:
     dependency: "direct main"
     description:
       name: angel3_orm
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "4.0.1"
+    version: "4.0.4"
   angel3_orm_generator:
     dependency: "direct dev"
     description:
       name: angel3_orm_generator
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "4.1.1"
+    version: "4.1.3"
   angel3_orm_postgres:
     dependency: "direct main"
     description:
       name: angel3_orm_postgres
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "3.1.0"
+    version: "3.2.1"
   angel3_production:
     dependency: "direct main"
     description:
       name: angel3_production
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "3.1.1"
+    version: "3.1.2"
   angel3_route:
     dependency: transitive
     description:
@@ -280,7 +280,7 @@ packages:
       name: build
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "2.1.1"
+    version: "2.2.1"
   build_config:
     dependency: transitive
     description:
@@ -301,21 +301,21 @@ packages:
       name: build_resolvers
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "2.0.5"
+    version: "2.0.6"
   build_runner:
     dependency: "direct dev"
     description:
       name: build_runner
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "2.1.5"
+    version: "2.1.7"
   build_runner_core:
     dependency: transitive
     description:
       name: build_runner_core
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "7.2.2"
+    version: "7.2.3"
   built_collection:
     dependency: transitive
     description:
@@ -399,7 +399,7 @@ packages:
       name: dart_style
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "2.2.0"
+    version: "2.2.1"
   dotenv:
     dependency: transitive
     description:
@@ -407,6 +407,13 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "3.0.0"
+  executor:
+    dependency: transitive
+    description:
+      name: executor
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "2.2.2"
   file:
     dependency: transitive
     description:
@@ -492,7 +499,7 @@ packages:
     source: hosted
     version: "1.0.3"
   jael3:
-    dependency: transitive
+    dependency: "direct main"
     description:
       name: jael3
       url: "https://pub.dartlang.org"
@@ -518,7 +525,7 @@ packages:
       name: json_annotation
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "4.3.0"
+    version: "4.4.0"
   json_rpc_2:
     dependency: transitive
     description:
@@ -561,6 +568,13 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "1.0.1"
+  mysql1:
+    dependency: transitive
+    description:
+      name: mysql1
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "0.19.2"
   node_preamble:
     dependency: transitive
     description:
@@ -588,7 +602,7 @@ packages:
       name: path
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "1.8.0"
+    version: "1.8.1"
   pedantic:
     dependency: transitive
     description:
@@ -609,7 +623,14 @@ packages:
       name: postgres
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "2.4.2"
+    version: "2.4.3"
+  postgres_pool:
+    dependency: transitive
+    description:
+      name: postgres_pool
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "2.1.3"
   pub_semver:
     dependency: transitive
     description:
@@ -623,7 +644,7 @@ packages:
       name: pubspec_parse
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "1.1.0"
+    version: "1.2.0"
   quiver:
     dependency: transitive
     description:
@@ -638,6 +659,13 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "4.0.0"
+  retry:
+    dependency: transitive
+    description:
+      name: retry
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "3.1.0"
   sasl_scram:
     dependency: transitive
     description:
@@ -686,7 +714,7 @@ packages:
       name: source_gen
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "1.1.1"
+    version: "1.2.1"
   source_map_stack_trace:
     dependency: transitive
     description:
@@ -749,21 +777,21 @@ packages:
       name: test
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "1.19.4"
+    version: "1.20.1"
   test_api:
     dependency: transitive
     description:
       name: test_api
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "0.4.8"
+    version: "0.4.9"
   test_core:
     dependency: transitive
     description:
       name: test_core
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "0.4.9"
+    version: "0.4.11"
   timing:
     dependency: transitive
     description:

+ 11 - 2
frameworks/Dart/angel3/orm/pubspec.yaml

@@ -16,16 +16,25 @@ dependencies:
   angel3_production: ^3.1.0
   angel3_static: ^4.1.0
   angel3_validate: ^4.0.0
+  jael3: ^4.2.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_migration_runner: ^4.1.0
   angel3_orm_generator: ^4.1.0
   angel3_serialize_generator: ^4.2.0
   angel3_test: ^4.0.0
   build_runner: ^2.0.3
   io: ^1.0.0
   test: ^1.17.5
-  lints: ^1.0.0
+  lints: ^1.0.0
+#dependency_overrides:
+#  angel3_orm:
+#    path: ../../../../../belatuk/packages/orm/angel_orm
+#  angel3_orm_postgres:
+#    path: ../../../../../belatuk/packages/orm/angel_orm_postgres
+#  angel3_jael:
+#    path: ../../../../../belatuk/packages/jael/angel_jael
+     

+ 28 - 0
frameworks/Dart/angel3/orm/run/dev.dart

@@ -0,0 +1,28 @@
+import 'dart:io';
+import 'package:logging/logging.dart';
+import 'package:belatuk_pretty_logging/belatuk_pretty_logging.dart';
+import 'package:angel3_container/mirrors.dart';
+import 'package:angel3_framework/angel3_framework.dart';
+import 'package:angel3_hot/angel3_hot.dart';
+import 'package:benchmark_app/benchmark_app.dart';
+
+void main() async {
+  // Watch the config/ and web/ directories for changes, and hot-reload the server.
+  hierarchicalLoggingEnabled = true;
+
+  var hot = HotReloader(() async {
+    var logger = Logger.detached('Angel3')
+      ..level = Level.ALL
+      ..onRecord.listen(prettyLog);
+    var app = Angel(logger: logger, reflector: MirrorsReflector());
+    await app.configure(configureServer);
+    return app;
+  }, [
+    Directory('config'),
+    Directory('lib'),
+  ]);
+
+  var server = await hot.startServer('127.0.0.1', 8080);
+  print(
+      'Angel3 server listening at http://${server.address.address}:${server.port}');
+}

+ 20 - 0
frameworks/Dart/angel3/orm/templates/fortunes.mustache

@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>Fortunes</title>
+</head>
+<body>
+<table>
+  <tr>
+    <th>id</th>
+    <th>message</th>
+  </tr>
+  {{#fortunes}}
+  <tr>
+    <td>{{id}}</td>
+    <td>{{message}}</td>
+  </tr>
+  {{/fortunes}}
+</table>
+</body>
+</html>

+ 43 - 0
frameworks/Dart/angel3/orm/test/all_test.dart

@@ -0,0 +1,43 @@
+import 'package:angel3_framework/angel3_framework.dart';
+import 'package:angel3_test/angel3_test.dart';
+import 'package:test/test.dart';
+import 'package:benchmark_app/benchmark_app.dart';
+
+// Angel also includes facilities to make testing easier.
+//
+// `package:angel_test` ships a client that can test
+// both plain HTTP and WebSockets.
+//
+// Tests do not require your server to actually be mounted on a port,
+// so they will run faster than they would in other frameworks, where you
+// would have to first bind a socket, and then account for network latency.
+//
+// See the documentation here:
+// https://github.com/angel-dart/test
+//
+// If you are unfamiliar with Dart's advanced testing library, you can read up
+// here:
+// https://github.com/dart-lang/test
+
+void main() async {
+  late TestClient client;
+
+  setUp(() async {
+    var app = Angel();
+    await app.configure(configureServer);
+
+    client = await connectTo(app);
+  });
+
+  tearDown(() async {
+    await client.close();
+  });
+
+  test('index returns 200', () async {
+    // Request a resource at the given path.
+    var response = await client.get(Uri.parse('/'));
+
+    // Expect a 200 response.
+    expect(response, hasStatus(200));
+  });
+}