From daec5e35ca50922d2d613a094e14aad5f07e3757 Mon Sep 17 00:00:00 2001 From: thomashii Date: Tue, 16 Feb 2021 10:10:09 +0800 Subject: [PATCH] Cleared static analytics errors --- README.md | 6 ++ packages/cli/README.md | 6 +- packages/cli/lib/src/commands/deploy.dart | 4 +- packages/cli/lib/src/commands/doctor.dart | 2 +- packages/cli/lib/src/commands/init.dart | 19 +++--- packages/cli/lib/src/commands/install.dart | 19 +++--- packages/cli/lib/src/commands/key.dart | 6 +- packages/cli/lib/src/commands/make.dart | 12 ++-- packages/cli/lib/src/commands/pub.dart | 4 +- packages/cli/lib/src/commands/rename.dart | 18 +++--- .../commands/service_generators/custom.dart | 2 +- .../commands/service_generators/rethink.dart | 2 +- packages/cli/lib/src/random_string.dart | 4 +- packages/cli/pubspec.yaml | 2 +- .../bin/jael_language_server.dart | 3 +- .../jael_language_server/lib/src/server.dart | 6 +- .../jael/jael_language_server/pubspec.yaml | 2 +- packages/mongo/lib/mongo_service.dart | 15 ++--- packages/relations/lib/src/belongs_to.dart | 12 ++-- .../relations/lib/src/belongs_to_many.dart | 12 ++-- packages/relations/lib/src/has_many.dart | 13 ++-- .../relations/lib/src/has_many_through.dart | 15 +++-- packages/relations/lib/src/has_one.dart | 14 +++-- packages/relations/pubspec.yaml | 3 +- packages/relations/test/belongs_to_test.dart | 9 +-- packages/relations/test/common.dart | 5 +- packages/relations/test/has_many_test.dart | 13 ++-- packages/relations/test/has_one_test.dart | 9 +-- .../static/lib/src/virtual_directory.dart | 62 +++++++++++++------ .../bin/jael_language_server.dart | 7 ++- .../jael_language_server/lib/src/server.dart | 16 +++-- .../vscode/jael_language_server/pubspec.yaml | 10 +-- 32 files changed, 196 insertions(+), 136 deletions(-) diff --git a/README.md b/README.md index 7af0dc2f..c6d0d45f 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,12 @@ dart --observe bin/dev.dart Next, check out the [detailed documentation](https://docs.angel-dart.dev/v/2.x) to learn to flesh out your project. +## Development + +* Install development version of Angel CLI +`dart pub global activate --source path ./packages/cli` +`dart pub global activate --source git https://github.com/dukefirehawk/angel/packages/cli` + ## Examples and Documentation Visit the [documentation](https://docs.angel-dart.dev/v/2.x) for dozens of guides and resources, including video tutorials, diff --git a/packages/cli/README.md b/packages/cli/README.md index 3b96938f..1aaea509 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -9,12 +9,16 @@ Includes functionality such as: * Renaming projects * Much more... -To install: +* To install: ```bash $ pub global activate angel_cli ``` +* Install development version +`dart pub global activate --source path ./packages/cli` +`dart pub global activate --source git https://github.com/dukefirehawk/angel/packages/cli` + And then, for information on each command: ```bash diff --git a/packages/cli/lib/src/commands/deploy.dart b/packages/cli/lib/src/commands/deploy.dart index 92b5f82e..9c95ea50 100644 --- a/packages/cli/lib/src/commands/deploy.dart +++ b/packages/cli/lib/src/commands/deploy.dart @@ -11,7 +11,7 @@ class DeployCommand extends Command { 'Generates scaffolding + helper functionality for deploying servers. Run this in your project root.'; DeployCommand() { - addSubcommand(new NginxCommand()); - addSubcommand(new SystemdCommand()); + addSubcommand(NginxCommand()); + addSubcommand(SystemdCommand()); } } diff --git a/packages/cli/lib/src/commands/doctor.dart b/packages/cli/lib/src/commands/doctor.dart index b435b6f0..fc70af3f 100644 --- a/packages/cli/lib/src/commands/doctor.dart +++ b/packages/cli/lib/src/commands/doctor.dart @@ -26,7 +26,7 @@ class DoctorCommand extends Command { print(green.wrap( "$checkmark Git executable found: v${version.replaceAll('git version', '').trim()}")); } else - throw new Exception("Git executable exit code not 0"); + throw Exception("Git executable exit code not 0"); } catch (exc) { print(red.wrap("$ballot Git executable not found")); } diff --git a/packages/cli/lib/src/commands/init.dart b/packages/cli/lib/src/commands/init.dart index 7dafb866..3c5ff157 100644 --- a/packages/cli/lib/src/commands/init.dart +++ b/packages/cli/lib/src/commands/init.dart @@ -263,41 +263,44 @@ Future preBuild(Directory projectDir) async { if (buildCode != 0) throw new Exception('Failed to pre-build resources.'); } +const RepoArchiveLocation = "https://github.com/angel-dart"; +const RepoLocation = "https://github.com/dukefirehawk"; + const BoilerplateInfo graphQLBoilerplate = const BoilerplateInfo( 'GraphQL', "A starting point for GraphQL API servers.", - 'https://github.com/angel-dart/angel.git', + '${RepoLocation}/boilerplates.git', ref: 'graphql', ); const BoilerplateInfo ormBoilerplate = const BoilerplateInfo( 'ORM', "A starting point for applications that use Angel's ORM.", - 'https://github.com/angel-dart/angel.git', + '${RepoLocation}/boilerplates.git', ref: 'orm', ); const BoilerplateInfo basicBoilerplate = const BoilerplateInfo( 'Basic', 'Minimal starting point for Angel 2.x - A simple server with only a few additional packages.', - 'https://github.com/angel-dart/angel.git'); + '${RepoLocation}/boilerplates.git'); const BoilerplateInfo legacyBoilerplate = const BoilerplateInfo( 'Legacy', 'Minimal starting point for applications running Angel 1.1.x.', - 'https://github.com/angel-dart/angel.git', + '${RepoArchiveLocation}/angel.git', ref: '1.1.x', ); const BoilerplateInfo sharedBoilerplate = const BoilerplateInfo( 'Shared', 'Holds common models and files shared across multiple Dart projects.', - 'https://github.com/angel-dart/boilerplate_shared.git'); + '${RepoLocation}/boilerplate_shared.git'); const BoilerplateInfo sharedOrmBoilerplate = const BoilerplateInfo( 'Shared (ORM)', 'Holds common models and files shared across multiple Dart projects.', - 'https://github.com/angel-dart/boilerplate_shared.git', + '${RepoLocation}/boilerplate_shared.git', ref: 'orm', ); @@ -306,8 +309,8 @@ const List boilerplates = const [ //legacyBoilerplate, ormBoilerplate, graphQLBoilerplate, - sharedBoilerplate, - sharedOrmBoilerplate, + //sharedBoilerplate, + //sharedOrmBoilerplate, ]; class BoilerplateInfo { diff --git a/packages/cli/lib/src/commands/install.dart b/packages/cli/lib/src/commands/install.dart index d7a9ec37..3cc7ad66 100644 --- a/packages/cli/lib/src/commands/install.dart +++ b/packages/cli/lib/src/commands/install.dart @@ -14,7 +14,7 @@ import 'make/maker.dart'; class InstallCommand extends Command { static const String repo = 'https://github.com/angel-dart/install.git'; static final Directory installRepo = - new Directory.fromUri(homeDir.uri.resolve('./.angel/addons')); + Directory.fromUri(homeDir.uri.resolve('./.angel/addons')); @override String get name => 'install'; @@ -72,7 +72,7 @@ class InstallCommand extends Command { for (var packageName in argResults.rest) { var packageDir = - new Directory.fromUri(installRepo.uri.resolve(packageName)); + Directory.fromUri(installRepo.uri.resolve(packageName)); if (!await packageDir.exists()) throw 'No add-on named "$packageName" is installed. You might need to run `angel install --update`.'; @@ -90,7 +90,7 @@ class InstallCommand extends Command { .map((k) { var dep = projectPubspec.dependencies[k]; if (dep is HostedDependency) - return new MakerDependency(k, dep.version.toString()); + return MakerDependency(k, dep.version.toString()); return null; }) .where((d) => d != null) @@ -99,14 +99,13 @@ class InstallCommand extends Command { deps.addAll(projectPubspec.devDependencies.keys.map((k) { var dep = projectPubspec.devDependencies[k]; if (dep is HostedDependency) - return new MakerDependency(k, dep.version.toString(), dev: true); + return MakerDependency(k, dep.version.toString(), dev: true); return null; }).where((d) => d != null)); await depend(deps); - var promptFile = - new File.fromUri(packageDir.uri.resolve('angel_cli.yaml')); + var promptFile = File.fromUri(packageDir.uri.resolve('angel_cli.yaml')); if (await promptFile.exists()) { var contents = await promptFile.readAsString(); @@ -116,7 +115,7 @@ class InstallCommand extends Command { // Loads globs if (cfg['templates'] is List) { globs.addAll( - (cfg['templates'] as List).map((p) => new Glob(p.toString()))); + (cfg['templates'] as List).map((p) => Glob(p.toString()))); } if (cfg['values'] is Map) { @@ -144,14 +143,14 @@ class InstallCommand extends Command { await for (var entity in src.list()) { if (entity is Directory) { var name = p.basename(entity.path); - var newDir = new Directory.fromUri(dst.uri.resolve(name)); + var newDir = Directory.fromUri(dst.uri.resolve(name)); await merge( entity, newDir, prefix.isEmpty ? name : '$prefix/$name'); } else if (entity is File && !entity.path.endsWith('angel_cli.yaml')) { var name = p.basename(entity.path); var target = dst.uri.resolve(name); - var targetFile = new File.fromUri(target); + var targetFile = File.fromUri(target); bool allClear = !await targetFile.exists(); if (!allClear) { @@ -187,7 +186,7 @@ class InstallCommand extends Command { } } - await merge(new Directory.fromUri(packageDir.uri.resolve('files')), + await merge(Directory.fromUri(packageDir.uri.resolve('files')), Directory.current, ''); print('Successfully installed $packageName@${projectPubspec.version}.'); } diff --git a/packages/cli/lib/src/commands/key.dart b/packages/cli/lib/src/commands/key.dart index cab986f8..92e10456 100644 --- a/packages/cli/lib/src/commands/key.dart +++ b/packages/cli/lib/src/commands/key.dart @@ -13,17 +13,17 @@ class KeyCommand extends Command { run() async { var secret = rs.randomAlphaNumeric(32); print('Generated new development JWT secret: $secret'); - await changeSecret(new File('config/default.yaml'), secret); + await changeSecret(File('config/default.yaml'), secret); secret = rs.randomAlphaNumeric(32); print('Generated new production JWT secret: $secret'); - await changeSecret(new File('config/production.yaml'), secret); + await changeSecret(File('config/production.yaml'), secret); } changeSecret(File file, String secret) async { if (await file.exists()) { var contents = await file.readAsString(); - contents = contents.replaceAll(new RegExp(r'jwt_secret:[^\n]+\n?'), ''); + contents = contents.replaceAll(RegExp(r'jwt_secret:[^\n]+\n?'), ''); await file.writeAsString(contents.trim() + '\njwt_secret: "$secret"'); } } diff --git a/packages/cli/lib/src/commands/make.dart b/packages/cli/lib/src/commands/make.dart index 219fedf1..012cb9f9 100644 --- a/packages/cli/lib/src/commands/make.dart +++ b/packages/cli/lib/src/commands/make.dart @@ -15,11 +15,11 @@ class MakeCommand extends Command { 'Generates common code for your project, such as projects and controllers.'; MakeCommand() { - addSubcommand(new ControllerCommand()); - addSubcommand(new MigrationCommand()); - addSubcommand(new ModelCommand()); - addSubcommand(new PluginCommand()); - addSubcommand(new TestCommand()); - addSubcommand(new ServiceCommand()); + addSubcommand(ControllerCommand()); + addSubcommand(MigrationCommand()); + addSubcommand(ModelCommand()); + addSubcommand(PluginCommand()); + addSubcommand(TestCommand()); + addSubcommand(ServiceCommand()); } } diff --git a/packages/cli/lib/src/commands/pub.dart b/packages/cli/lib/src/commands/pub.dart index 1f3a74ce..1b582ebc 100644 --- a/packages/cli/lib/src/commands/pub.dart +++ b/packages/cli/lib/src/commands/pub.dart @@ -1,9 +1,9 @@ import 'dart:io'; -final RegExp _leadingSlashes = new RegExp(r'^/+'); +final RegExp _leadingSlashes = RegExp(r'^/+'); String resolvePub() { - var exec = new File(Platform.resolvedExecutable); + var exec = File(Platform.resolvedExecutable); var pubPath = exec.parent.uri.resolve('pub').path; if (Platform.isWindows) pubPath = pubPath.replaceAll(_leadingSlashes, '') + '.bat'; diff --git a/packages/cli/lib/src/commands/rename.dart b/packages/cli/lib/src/commands/rename.dart index ae11b5e5..9a051ebe 100644 --- a/packages/cli/lib/src/commands/rename.dart +++ b/packages/cli/lib/src/commands/rename.dart @@ -29,17 +29,17 @@ class RenameCommand extends Command { newName = prompts.get('Rename project to'); } - newName = new ReCase(newName).snakeCase; + newName = ReCase(newName).snakeCase; var choice = prompts.getBool('Rename the project to `$newName`?'); if (choice) { print('Renaming project to `$newName`...'); var pubspecFile = - new File.fromUri(Directory.current.uri.resolve('pubspec.yaml')); + File.fromUri(Directory.current.uri.resolve('pubspec.yaml')); if (!await pubspecFile.exists()) { - throw new Exception('No pubspec.yaml found in current directory.'); + throw Exception('No pubspec.yaml found in current directory.'); } else { var pubspec = await loadPubspec(); var oldName = pubspec.name; @@ -66,7 +66,7 @@ renamePubspec(Directory dir, String oldName, String newName) async { if (await pubspecFile.exists()) { var contents = await pubspecFile.readAsString(), oldContents = contents; contents = - contents.replaceAll(new RegExp('name:\\s*$oldName'), 'name: $newName'); + contents.replaceAll(RegExp('name:\\s*$oldName'), 'name: $newName'); if (contents != oldContents) { await pubspecFile.writeAsString(contents); @@ -76,7 +76,7 @@ renamePubspec(Directory dir, String oldName, String newName) async { // print(cyan // .wrap('Note that this does not actually modify your `pubspec.yaml`.')); // TODO: https://github.com/dart-lang/pubspec_parse/issues/17 -// var newPubspec = new Pubspec.fromJson(pubspec.toJson()..['name'] = newName); +// var newPubspec = Pubspec.fromJson(pubspec.toJson()..['name'] = newName); // await newPubspec.save(dir); } @@ -84,7 +84,7 @@ renameDartFiles(Directory dir, String oldName, String newName) async { if (!await dir.exists()) return; // Try to replace MongoDB URL - var configGlob = new Glob('config/**/*.yaml'); + var configGlob = Glob('config/**/*.yaml'); try { await for (var yamlFile in configGlob.list(root: dir.absolute.path)) { @@ -98,19 +98,19 @@ renameDartFiles(Directory dir, String oldName, String newName) async { } } catch (_) {} - var entry = new File.fromUri(dir.uri.resolve('lib/$oldName.dart')); + var entry = File.fromUri(dir.uri.resolve('lib/$oldName.dart')); if (await entry.exists()) { await entry.rename(dir.uri.resolve('lib/$newName.dart').toFilePath()); print('Renaming library file `${entry.absolute.path}`...'); } - var fmt = new DartFormatter(); + var fmt = DartFormatter(); await for (FileSystemEntity file in dir.list(recursive: true)) { if (file is File && file.path.endsWith('.dart')) { var contents = await file.readAsString(); var ast = parseCompilationUnit(contents); - var visitor = new RenamingVisitor(oldName, newName) + var visitor = RenamingVisitor(oldName, newName) ..visitCompilationUnit(ast); if (visitor.replace.isNotEmpty) { diff --git a/packages/cli/lib/src/commands/service_generators/custom.dart b/packages/cli/lib/src/commands/service_generators/custom.dart index d4134602..9008b695 100644 --- a/packages/cli/lib/src/commands/service_generators/custom.dart +++ b/packages/cli/lib/src/commands/service_generators/custom.dart @@ -12,7 +12,7 @@ class CustomServiceGenerator extends ServiceGenerator { @override void applyToLibrary(LibraryBuilder library, String name, String lower) { - library.body.add(new Class((clazz) { + library.body.add(Class((clazz) { clazz ..name = '${name}Service' ..extend = refer('Service'); diff --git a/packages/cli/lib/src/commands/service_generators/rethink.dart b/packages/cli/lib/src/commands/service_generators/rethink.dart index 57059844..49cc78c1 100644 --- a/packages/cli/lib/src/commands/service_generators/rethink.dart +++ b/packages/cli/lib/src/commands/service_generators/rethink.dart @@ -34,7 +34,7 @@ class RethinkServiceGenerator extends ServiceGenerator { void applyToLibrary(LibraryBuilder library, String name, String lower) { library.directives.addAll([ 'package:angel_rethink/angel_rethink.dart', - 'package:rethinkdb_driver/rethinkdb_driver.dart' + 'package:rethinkdb_dart/rethinkdb_dart.dart' ].map((str) => new Directive.import(str))); } diff --git a/packages/cli/lib/src/random_string.dart b/packages/cli/lib/src/random_string.dart index c089e870..9f539aaf 100644 --- a/packages/cli/lib/src/random_string.dart +++ b/packages/cli/lib/src/random_string.dart @@ -2,10 +2,10 @@ import 'dart:math'; const String _valid = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; -final Random _rnd = new Random.secure(); +final Random _rnd = Random.secure(); String randomAlphaNumeric(int length) { - var b = new StringBuffer(); + var b = StringBuffer(); for (int i = 0; i < length; i++) { b.writeCharCode(_valid.codeUnitAt(_rnd.nextInt(_valid.length))); diff --git a/packages/cli/pubspec.yaml b/packages/cli/pubspec.yaml index 35e0ab95..54dba432 100644 --- a/packages/cli/pubspec.yaml +++ b/packages/cli/pubspec.yaml @@ -2,7 +2,7 @@ author: Tobe O description: Command-line tools for the Angel framework, including scaffolding. homepage: https://github.com/angel-dart/angel_cli name: angel_cli -version: 2.1.7+1 +version: 2.2.0 environment: sdk: ">=2.10.0 <2.12.0" dependencies: diff --git a/packages/jael/jael_language_server/bin/jael_language_server.dart b/packages/jael/jael_language_server/bin/jael_language_server.dart index f90548a2..77e9ef58 100644 --- a/packages/jael/jael_language_server/bin/jael_language_server.dart +++ b/packages/jael/jael_language_server/bin/jael_language_server.dart @@ -3,8 +3,9 @@ import 'dart:io'; import 'package:args/args.dart'; import 'package:io/ansi.dart'; import 'package:io/io.dart'; -import 'package:dart_language_server/dart_language_server.dart'; +//import 'package:dart_language_server/dart_language_server.dart'; import 'package:jael_language_server/jael_language_server.dart'; +import 'package:jael_language_server/src/protocol/language_server/server.dart'; main(List args) async { var argParser = new ArgParser() diff --git a/packages/jael/jael_language_server/lib/src/server.dart b/packages/jael/jael_language_server/lib/src/server.dart index 41de486a..864d9d57 100644 --- a/packages/jael/jael_language_server/lib/src/server.dart +++ b/packages/jael/jael_language_server/lib/src/server.dart @@ -1,6 +1,6 @@ import 'dart:async'; -import 'package:dart_language_server/src/protocol/language_server/interface.dart'; -import 'package:dart_language_server/src/protocol/language_server/messages.dart'; +//import 'package:dart_language_server/src/protocol/language_server/interface.dart'; +//import 'package:dart_language_server/src/protocol/language_server/messages.dart'; import 'package:file/file.dart'; import 'package:file/local.dart'; import 'package:file/memory.dart'; @@ -13,6 +13,8 @@ import 'package:string_scanner/string_scanner.dart'; import 'package:symbol_table/symbol_table.dart'; import 'analyzer.dart'; import 'object.dart'; +import 'protocol/language_server/interface.dart'; +import 'protocol/language_server/messages.dart'; class JaelLanguageServer extends LanguageServer { var _diagnostics = new StreamController(); diff --git a/packages/jael/jael_language_server/pubspec.yaml b/packages/jael/jael_language_server/pubspec.yaml index 9bc9644d..782edf81 100644 --- a/packages/jael/jael_language_server/pubspec.yaml +++ b/packages/jael/jael_language_server/pubspec.yaml @@ -7,7 +7,7 @@ environment: sdk: '>=2.10.0 <2.12.0' dependencies: args: ^1.0.0 - dart_language_server: ^0.1.3 +# dart_language_server: ^0.1.16 file: ^5.0.0 io: ^0.3.2 jael: #^2.0.0 diff --git a/packages/mongo/lib/mongo_service.dart b/packages/mongo/lib/mongo_service.dart index 0669221e..9367e8c2 100644 --- a/packages/mongo/lib/mongo_service.dart +++ b/packages/mongo/lib/mongo_service.dart @@ -16,14 +16,14 @@ class MongoService extends Service> { @deprecated final bool debug; - MongoService(DbCollection this.collection, + MongoService(this.collection, {this.allowRemoveAll = false, this.allowQuery = true, this.debug = true}) : super(); SelectorBuilder _makeQuery([Map params_]) { - Map params = Map.from(params_ ?? {}); + var params = Map.from(params_ ?? {}); params = params..remove('provider'); - SelectorBuilder result = where.exists('_id'); + var result = where.exists('_id'); // You can pass a SelectorBuilder as 'query'; if (params['query'] is SelectorBuilder) { @@ -36,12 +36,13 @@ class MongoService extends Service> { (allowQuery == true || !params.containsKey('provider'))) { if (params[key] is Map) { // If they send a map, then we'll sort by every key in the map - for (String fieldName in params[key].keys.where((x) => x is String)) { + + for (var fieldName in params[key].keys.where((x) => x is String)) { var sorter = params[key][fieldName]; - if (sorter is num) { + if (sorter is num && fieldName is String) { result = result.sortBy(fieldName, descending: sorter == -1); - } else if (sorter is String) { - result = result.sortBy(fieldName, descending: sorter == "-1"); + } else if (sorter is String && fieldName is String) { + result = result.sortBy(fieldName, descending: sorter == '-1'); } else if (sorter is SelectorBuilder) { result = result.and(sorter); } diff --git a/packages/relations/lib/src/belongs_to.dart b/packages/relations/lib/src/belongs_to.dart index 68ae9c38..25b06c0e 100644 --- a/packages/relations/lib/src/belongs_to.dart +++ b/packages/relations/lib/src/belongs_to.dart @@ -27,7 +27,7 @@ HookedServiceEventListener belongsTo(Pattern servicePath, } return (HookedServiceEvent e) async { - var ref = e.service.app.service(servicePath); + var ref = e.getService(servicePath); if (ref == null) throw noService(servicePath); _getForeignKey(obj) { @@ -35,8 +35,9 @@ HookedServiceEventListener belongsTo(Pattern servicePath, return getForeignKey(obj); else if (obj is Map) return obj[localId]; - else if (obj is Extensible) - return obj.properties[localId]; + //TODO: Undefined class + //else if (obj is Extensible) + // return obj.properties[localId]; else if (localId == null || localId == 'userId') return obj.userId; else @@ -48,8 +49,9 @@ HookedServiceEventListener belongsTo(Pattern servicePath, return assignForeignObject(foreign, obj); else if (obj is Map) obj[foreignName] = foreign; - else if (obj is Extensible) - obj.properties[foreignName] = foreign; + //TODO: Undefined class + //else if (obj is Extensible) + // obj.properties[foreignName] = foreign; else reflect(obj).setField(new Symbol(foreignName), foreign); } diff --git a/packages/relations/lib/src/belongs_to_many.dart b/packages/relations/lib/src/belongs_to_many.dart index 2b3a508a..e0f078bf 100644 --- a/packages/relations/lib/src/belongs_to_many.dart +++ b/packages/relations/lib/src/belongs_to_many.dart @@ -27,7 +27,7 @@ HookedServiceEventListener belongsToMany(Pattern servicePath, } return (HookedServiceEvent e) async { - var ref = e.service.app.service(servicePath); + var ref = e.getService(servicePath); if (ref == null) throw noService(servicePath); _getForeignKey(obj) { @@ -35,8 +35,9 @@ HookedServiceEventListener belongsToMany(Pattern servicePath, return getForeignKey(obj); else if (obj is Map) return obj[localId]; - else if (obj is Extensible) - return obj.properties[localId]; + //TODO: Undefined class + //else if (obj is Extensible) + // return obj.properties[localId]; else if (localId == null || localId == 'userId') return obj.userId; else @@ -48,8 +49,9 @@ HookedServiceEventListener belongsToMany(Pattern servicePath, return assignForeignObject(foreign, obj); else if (obj is Map) obj[foreignName] = foreign; - else if (obj is Extensible) - obj.properties[foreignName] = foreign; + //TODO: Undefined class + //else if (obj is Extensible) + // obj.properties[foreignName] = foreign; else reflect(obj).setField(new Symbol(foreignName), foreign); } diff --git a/packages/relations/lib/src/has_many.dart b/packages/relations/lib/src/has_many.dart index 34cffcff..1ab1d745 100644 --- a/packages/relations/lib/src/has_many.dart +++ b/packages/relations/lib/src/has_many.dart @@ -17,9 +17,8 @@ HookedServiceEventListener hasMany(Pattern servicePath, String localKey, getLocalKey(obj), assignForeignObjects(foreign, obj)}) { - return (HookedServiceEvent e) async { - var ref = e.service.app.service(servicePath); + var ref = e.getService(servicePath); var foreignName = as?.isNotEmpty == true ? as : pluralize.plural(servicePath.toString()); if (ref == null) throw noService(servicePath); @@ -29,8 +28,9 @@ HookedServiceEventListener hasMany(Pattern servicePath, return getLocalKey(obj); else if (obj is Map) return obj[localKey ?? 'id']; - else if (obj is Extensible) - return obj.properties[localKey ?? 'id']; + //TODO: Undefined class + //else if (obj is Extensible) + // return obj.properties[localKey ?? 'id']; else if (localKey == null || localKey == 'id') return obj.id; else @@ -42,8 +42,9 @@ HookedServiceEventListener hasMany(Pattern servicePath, return assignForeignObjects(foreign, obj); else if (obj is Map) obj[foreignName] = foreign; - else if (obj is Extensible) - obj.properties[foreignName] = foreign; + //TODO: Undefined class + //else if (obj is Extensible) + // obj.properties[foreignName] = foreign; else reflect(obj).setField(new Symbol(foreignName), foreign); } diff --git a/packages/relations/lib/src/has_many_through.dart b/packages/relations/lib/src/has_many_through.dart index 9539519e..c2028b30 100644 --- a/packages/relations/lib/src/has_many_through.dart +++ b/packages/relations/lib/src/has_many_through.dart @@ -29,8 +29,9 @@ HookedServiceEventListener hasManyThrough(String servicePath, String pivotPath, return assignForeignObjects(foreign, obj); else if (obj is Map) obj[foreignName] = foreign; - else if (obj is Extensible) - obj.properties[foreignName] = foreign; + //TODO: Undefined class + //else if (obj is Extensible) + // obj.properties[foreignName] = foreign; else reflect(obj).setField(new Symbol(foreignName), foreign); } @@ -40,8 +41,9 @@ HookedServiceEventListener hasManyThrough(String servicePath, String pivotPath, return getLocalKey(obj); else if (obj is Map) return obj[localKey ?? 'id']; - else if (obj is Extensible) - return obj.properties[localKey ?? 'id']; + //TODO: Undefined class + //else if (obj is Extensible) + // return obj.properties[localKey ?? 'id']; else if (localKey == null || localKey == 'id') return obj.id; else @@ -53,8 +55,9 @@ HookedServiceEventListener hasManyThrough(String servicePath, String pivotPath, return getPivotKey(obj); else if (obj is Map) return obj[pivotKey ?? 'id']; - else if (obj is Extensible) - return obj.properties[pivotKey ?? 'id']; + //TODO: Undefined class + //else if (obj is Extensible) + // return obj.properties[pivotKey ?? 'id']; else if (pivotKey == null || pivotKey == 'id') return obj.id; else diff --git a/packages/relations/lib/src/has_one.dart b/packages/relations/lib/src/has_one.dart index 8578081b..0556bf1a 100644 --- a/packages/relations/lib/src/has_one.dart +++ b/packages/relations/lib/src/has_one.dart @@ -17,9 +17,8 @@ HookedServiceEventListener hasOne(Pattern servicePath, String localKey, getLocalKey(obj), assignForeignObject(foreign, obj)}) { - return (HookedServiceEvent e) async { - var ref = e.service.app.service(servicePath); + var ref = e.getService(servicePath); var foreignName = as?.isNotEmpty == true ? as : pluralize.singular(servicePath.toString()); @@ -30,8 +29,10 @@ HookedServiceEventListener hasOne(Pattern servicePath, return getLocalKey(obj); else if (obj is Map) return obj[localKey ?? 'id']; - else if (obj is Extensible) - return obj.properties[localKey ?? 'id']; + + //TODO: Undefined class + //else if (obj is Extensible) + // return obj.properties[localKey ?? 'id']; else if (localKey == null || localKey == 'id') return obj.id; else @@ -43,8 +44,9 @@ HookedServiceEventListener hasOne(Pattern servicePath, return assignForeignObject(foreign, obj); else if (obj is Map) obj[foreignName] = foreign; - else if (obj is Extensible) - obj.properties[foreignName] = foreign; + //TODO: Undefined class + //else if (obj is Extensible) + // obj.properties[foreignName] = foreign; else reflect(obj).setField(new Symbol(foreignName), foreign); } diff --git a/packages/relations/pubspec.yaml b/packages/relations/pubspec.yaml index 4288b0d2..7198f434 100644 --- a/packages/relations/pubspec.yaml +++ b/packages/relations/pubspec.yaml @@ -9,5 +9,6 @@ dependencies: angel_framework: #^1.0.0-dev path: ../framework dev_dependencies: - #angel_seeder: ^1.0.0 + angel_seeder: #^1.0.0 + path: ../seeder test: ^1.15.7 diff --git a/packages/relations/test/belongs_to_test.dart b/packages/relations/test/belongs_to_test.dart index d398e923..119732e0 100644 --- a/packages/relations/test/belongs_to_test.dart +++ b/packages/relations/test/belongs_to_test.dart @@ -27,11 +27,12 @@ main() { })); }))); - app.service('books').afterAll(relations.belongsTo('authors')); + // TODO: Missing method afterAll + //app.findService ('books').afterAll(relations.belongsTo('authors')); }); test('index', () async { - var books = await app.service('books').index(); + var books = await app.findService('books').index(); print(books); expect(books, allOf(isList, isNotEmpty)); @@ -46,8 +47,8 @@ main() { test('create', () async { var warAndPeace = await app - .service('books') - .create(new Book(title: 'War and Peace').toJson()); + .findService('books') + .create(Book(title: 'War and Peace').toJson()); print(warAndPeace); expect(warAndPeace.keys, contains('author')); diff --git a/packages/relations/test/common.dart b/packages/relations/test/common.dart index f8adf3dd..478fa683 100644 --- a/packages/relations/test/common.dart +++ b/packages/relations/test/common.dart @@ -1,5 +1,6 @@ +import 'dart:convert'; import 'package:angel_framework/angel_framework.dart'; -import 'package:json_god/json_god.dart' as god; +//import 'package:json_god/json_god.dart' as god; @deprecated class CustomMapService extends Service { @@ -32,7 +33,7 @@ class CustomMapService extends Service { @override create(data, [params]) async { - Map d = data is Map ? data : god.serializeObject(data); + Map d = data is Map ? data : jsonDecode(data); d['id'] = _items.length.toString(); _items.add(d); return d; diff --git a/packages/relations/test/has_many_test.dart b/packages/relations/test/has_many_test.dart index e27b19e4..4f83fa71 100644 --- a/packages/relations/test/has_many_test.dart +++ b/packages/relations/test/has_many_test.dart @@ -1,5 +1,5 @@ import 'package:angel_framework/angel_framework.dart'; -import 'package:angel_relations/angel_relations.dart' as relations; +//import 'package:angel_relations/angel_relations.dart' as relations; import 'package:angel_seeder/angel_seeder.dart'; import 'package:test/test.dart'; import 'common.dart'; @@ -27,13 +27,14 @@ main() { })); }))); - app - .service('authors') - .afterAll(relations.hasMany('books', foreignKey: 'authorId')); + // TODO: Missing afterAll method + // app + // .findService('authors') + // .afterAll(relations.hasMany('books', foreignKey: 'authorId')); }); test('index', () async { - var authors = await app.service('authors').index(); + var authors = await app.findService('authors').index(); print(authors); expect(authors, allOf(isList, isNotEmpty)); @@ -51,7 +52,7 @@ main() { test('create', () async { var tolstoy = await app - .service('authors') + .findService('authors') .create(new Author(name: 'Leo Tolstoy').toJson()); print(tolstoy); diff --git a/packages/relations/test/has_one_test.dart b/packages/relations/test/has_one_test.dart index 7169f545..e6687521 100644 --- a/packages/relations/test/has_one_test.dart +++ b/packages/relations/test/has_one_test.dart @@ -27,12 +27,13 @@ main() { })); }))); - app.service('authors').afterAll( - relations.hasOne('books', as: 'book', foreignKey: 'authorId')); + // TODO: Missing afterAll method + // app.findService('authors').afterAll( + // relations.hasOne('books', as: 'book', foreignKey: 'authorId')); }); test('index', () async { - var authors = await app.service('authors').index(); + var authors = await app.findService('authors').index(); print(authors); expect(authors, allOf(isList, isNotEmpty)); @@ -49,7 +50,7 @@ main() { test('create', () async { var tolstoy = await app - .service('authors') + .findService('authors') .create(new Author(name: 'Leo Tolstoy').toJson()); print(tolstoy); diff --git a/packages/static/lib/src/virtual_directory.dart b/packages/static/lib/src/virtual_directory.dart index c36a5659..7daa243e 100644 --- a/packages/static/lib/src/virtual_directory.dart +++ b/packages/static/lib/src/virtual_directory.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:typed_data'; import 'package:angel_framework/angel_framework.dart'; import 'package:file/file.dart'; import 'package:http_parser/http_parser.dart'; @@ -12,14 +11,16 @@ final RegExp _straySlashes = RegExp(r'(^/+)|(/+$)'); String _pathify(String path) { var p = path.replaceAll(_straySlashes, ''); - Map replace = {}; + var replace = {}; for (Match match in _param.allMatches(p)) { if (match[3] != null) replace[match[0]] = ':${match[1]}'; } replace.forEach((k, v) { - p = p.replaceAll(k, v); + if (k is String && v is String) { + p = p.replaceAll(k, v); + } }); return p; @@ -64,7 +65,7 @@ class VirtualDirectory { if (source != null) { _source = source; } else { - String dirPath = app.environment.isProduction ? './build/web' : './web'; + var dirPath = app.environment.isProduction ? './build/web' : './web'; _source = fileSystem.directory(dirPath); } } @@ -148,7 +149,7 @@ class VirtualDirectory { /// Serves the index file of a [directory], if it exists. Future serveDirectory(Directory directory, String relative, FileStat stat, RequestContext req, ResponseContext res) async { - for (String indexFileName in indexFileNames) { + for (var indexFileName in indexFileNames) { final index = fileSystem.file(directory.absolute.uri.resolve(indexFileName)); if (await index.exists()) { @@ -168,34 +169,53 @@ class VirtualDirectory { res.write('
  • ..
  • '); - List entities = await directory + var entities = await directory .list(followLinks: false) .toList() .then((l) => List.from(l)); entities.sort((a, b) { if (a is Directory) { - if (b is Directory) return a.path.compareTo(b.path); + if (b is Directory) { + return a.path.compareTo(b.path); + } return -1; } else if (a is File) { if (b is Directory) { return 1; - } else if (b is File) return a.path.compareTo(b.path); + } else if (b is File) { + return a.path.compareTo(b.path); + } return -1; - } else if (b is Link) return a.path.compareTo(b.path); + } else if (a is Link) { + if (b is Directory) { + return 1; + } else if (b is Link) { + return a.path.compareTo(b.path); + } + return -1; + } return 1; }); for (var entity in entities) { - var stub = p.basename(entity.path); - var href = stub; + String stub; String type; if (entity is File) { type = '[File]'; + stub = p.basename(entity.path); } else if (entity is Directory) { type = '[Directory]'; - } else if (entity is Link) type = '[Link]'; + stub = p.basename(entity.path); + } else if (entity is Link) { + type = '[Link]'; + stub = p.basename(entity.path); + } else { + //TODO: Handle unknown type + + } + var href = stub; if (relative.isNotEmpty) href = '/' + relative + '/' + stub; @@ -214,7 +234,7 @@ class VirtualDirectory { void _ensureContentTypeAllowed(String mimeType, RequestContext req) { var value = req.headers.value('accept'); - bool acceptable = value == null || + var acceptable = value == null || value?.isNotEmpty != true || (mimeType?.isNotEmpty == true && value?.contains(mimeType) == true) || value?.contains('*/*') == true; @@ -256,7 +276,7 @@ class VirtualDirectory { header = RangeHeader(items); for (var item in header.items) { - bool invalid = false; + var invalid = false; if (item.start != -1) { invalid = item.end != -1 && item.end < item.start; @@ -266,17 +286,17 @@ class VirtualDirectory { if (invalid) { throw AngelHttpException( - Exception("Semantically invalid, or unbounded range."), + Exception('Semantically invalid, or unbounded range.'), statusCode: 416, - message: "Semantically invalid, or unbounded range."); + message: 'Semantically invalid, or unbounded range.'); } // Ensure it's within range. if (item.start >= totalFileSize || item.end >= totalFileSize) { throw AngelHttpException( - Exception("Given range $item is out of bounds."), + Exception('Given range $item is out of bounds.'), statusCode: 416, - message: "Given range $item is out of bounds."); + message: 'Given range $item is out of bounds.'); } } @@ -285,8 +305,10 @@ class VirtualDirectory { statusCode: 416, message: '`Range` header may not be empty.'); } else if (header.items.length == 1) { var item = header.items[0]; - Stream stream; - int len = 0, total = totalFileSize; + Stream> stream; + var len = 0; + + var total = totalFileSize; if (item.start == -1) { if (item.end == -1) { diff --git a/packages/vscode/jael_language_server/bin/jael_language_server.dart b/packages/vscode/jael_language_server/bin/jael_language_server.dart index f90548a2..e0249970 100644 --- a/packages/vscode/jael_language_server/bin/jael_language_server.dart +++ b/packages/vscode/jael_language_server/bin/jael_language_server.dart @@ -3,8 +3,9 @@ import 'dart:io'; import 'package:args/args.dart'; import 'package:io/ansi.dart'; import 'package:io/io.dart'; -import 'package:dart_language_server/dart_language_server.dart'; -import 'package:jael_language_server/jael_language_server.dart'; +//import 'package:dart_language_server/dart_language_server.dart'; +import 'package:vs_jael_language_server/jael_language_server.dart'; +import 'package:vs_jael_language_server/src/protocol/language_server/server.dart'; main(List args) async { var argParser = new ArgParser() @@ -56,7 +57,7 @@ main(List args) async { ); var zone = Zone.current.fork(specification: spec); await zone.run(() async { - var stdio = new StdIOLanguageServer.start(jaelServer); + var stdio = StdIOLanguageServer.start(jaelServer); await stdio.onDone; }); } diff --git a/packages/vscode/jael_language_server/lib/src/server.dart b/packages/vscode/jael_language_server/lib/src/server.dart index e31fd23a..729ae02a 100644 --- a/packages/vscode/jael_language_server/lib/src/server.dart +++ b/packages/vscode/jael_language_server/lib/src/server.dart @@ -1,6 +1,6 @@ import 'dart:async'; -import 'package:dart_language_server/src/protocol/language_server/interface.dart'; -import 'package:dart_language_server/src/protocol/language_server/messages.dart'; +//import 'package:dart_language_server/src/protocol/language_server/interface.dart'; +//import 'package:dart_language_server/src/protocol/language_server/messages.dart'; import 'package:file/file.dart'; import 'package:file/local.dart'; import 'package:file/memory.dart'; @@ -11,9 +11,13 @@ import 'package:path/path.dart' as p; import 'package:source_span/source_span.dart'; import 'package:string_scanner/string_scanner.dart'; import 'package:symbol_table/symbol_table.dart'; -import 'analyzer.dart'; -import 'formatter.dart'; -import 'object.dart'; + +import 'protocol/language_server/interface.dart'; +import 'protocol/language_server/messages.dart'; + +import './analyzer.dart'; +import './formatter.dart' as fmt; +import './object.dart'; class JaelLanguageServer extends LanguageServer { var _diagnostics = new StreamController(); @@ -502,7 +506,7 @@ class JaelLanguageServer extends LanguageServer { var document = parseDocument(contents, sourceUrl: file.uri, onError: errors.add); if (errors.isNotEmpty) return null; - var formatter = new JaelFormatter( + var formatter = fmt.JaelFormatter( formattingOptions.tabSize, formattingOptions.insertSpaces); var formatted = formatter.apply(document); logger.info('Original:${contents}\nFormatted:\n$formatted'); diff --git a/packages/vscode/jael_language_server/pubspec.yaml b/packages/vscode/jael_language_server/pubspec.yaml index 7432cc56..137ee3f4 100644 --- a/packages/vscode/jael_language_server/pubspec.yaml +++ b/packages/vscode/jael_language_server/pubspec.yaml @@ -1,4 +1,4 @@ -name: jael_language_server +name: vs_jael_language_server version: 0.0.0 description: Language Server Protocol implementation for the Jael templating engine. author: Tobe Osakwe @@ -7,11 +7,13 @@ environment: sdk: ">=2.10.0 <2.12.0" dependencies: args: ^1.0.0 - dart_language_server: ^0.1.16 +# dart_language_server: ^0.1.16 file: ^5.0.0 io: ^0.3.2 - jael: ^2.0.0 - jael_preprocessor: ^2.0.0 + jael: #^2.0.0 + path: ../../jael/jael + jael_preprocessor: #^2.0.0 + path: ../../jael/jael_preprocessor json_rpc_2: ^2.0.0 logging: ^0.11.3 path: ^1.0.0