diff --git a/.gitattributes b/.gitattributes index 18aaf6d1a..b1baa584a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,3 @@ **/pubspec.lock linguist-generated=true -pkgs/dart_services/lib/src/shared/** linguist-generated=true pkgs/dartpad_ui/lib/samples.g.dart linguist-generated=true pkgs/dartpad_ui/web/codemirror/** linguist-generated=true diff --git a/pkgs/dart_services/README.md b/pkgs/dart_services/README.md index 2b3325ec7..41704822f 100644 --- a/pkgs/dart_services/README.md +++ b/pkgs/dart_services/README.md @@ -35,15 +35,8 @@ To run tests: `dart test` -### Re-generating source - -To rebuild the shelf router, run: - -``` -dart run build_runner build --delete-conflicting-outputs -``` - ### Building storage artifacts + Dart services pre-compiles `.dill` files for the Dart SDK and Flutter Web SDK, which are uploaded to Cloud Storage automatically. These files are located in the `artifacts/` directory. diff --git a/pkgs/dart_services/lib/src/common_server.dart b/pkgs/dart_services/lib/src/common_server.dart index 963ab5373..0dfc136f4 100644 --- a/pkgs/dart_services/lib/src/common_server.dart +++ b/pkgs/dart_services/lib/src/common_server.dart @@ -21,8 +21,6 @@ import 'sdk.dart'; import 'shelf_cors.dart' as shelf_cors; import 'utils.dart'; -part 'common_server.g.dart'; - const jsonContentType = 'application/json; charset=utf-8'; const apiPrefix = '/api/'; @@ -68,8 +66,24 @@ class CommonServerApi { final CommonServerImpl impl; final TaskScheduler scheduler = TaskScheduler(); - /// The (lazily-constructed) router. - late final Router router = _$CommonServerApiRouter(this); + /// The shelf router. + late final Router router = () { + final router = Router(); + + // general requests (GET) + router.get(r'/api//version', handleVersion); + + // general requests (POST) + router.post(r'/api//analyze', handleAnalyze); + router.post(r'/api//compile', handleCompile); + router.post(r'/api//compileDDC', handleCompileDDC); + router.post(r'/api//complete', handleComplete); + router.post(r'/api//fixes', handleFixes); + router.post(r'/api//format', handleFormat); + router.post(r'/api//document', handleDocument); + router.post(r'/api//openInIDX', handleOpenInIdx); + return router; + }(); CommonServerApi(this.impl); @@ -77,8 +91,13 @@ class CommonServerApi { Future shutdown() => impl.shutdown(); - @Route.post('$apiPrefix/analyze') - Future analyze(Request request, String apiVersion) async { + Future handleVersion(Request request, String apiVersion) async { + if (apiVersion != api3) return unhandledVersion(apiVersion); + + return ok(version().toJson()); + } + + Future handleAnalyze(Request request, String apiVersion) async { if (apiVersion != api3) return unhandledVersion(apiVersion); final sourceRequest = @@ -91,8 +110,7 @@ class CommonServerApi { return ok(result.toJson()); } - @Route.post('$apiPrefix/compile') - Future compile(Request request, String apiVersion) async { + Future handleCompile(Request request, String apiVersion) async { if (apiVersion != api3) return unhandledVersion(apiVersion); final sourceRequest = @@ -109,8 +127,7 @@ class CommonServerApi { } } - @Route.post('$apiPrefix/compileDDC') - Future compileDDC(Request request, String apiVersion) async { + Future handleCompileDDC(Request request, String apiVersion) async { if (apiVersion != api3) return unhandledVersion(apiVersion); final sourceRequest = @@ -134,8 +151,7 @@ class CommonServerApi { } } - @Route.post('$apiPrefix/complete') - Future complete(Request request, String apiVersion) async { + Future handleComplete(Request request, String apiVersion) async { if (apiVersion != api3) return unhandledVersion(apiVersion); final sourceRequest = @@ -147,8 +163,7 @@ class CommonServerApi { return ok(result.toJson()); } - @Route.post('$apiPrefix/fixes') - Future fixes(Request request, String apiVersion) async { + Future handleFixes(Request request, String apiVersion) async { if (apiVersion != api3) return unhandledVersion(apiVersion); final sourceRequest = @@ -160,8 +175,7 @@ class CommonServerApi { return ok(result.toJson()); } - @Route.post('$apiPrefix/format') - Future format(Request request, String apiVersion) async { + Future handleFormat(Request request, String apiVersion) async { if (apiVersion != api3) return unhandledVersion(apiVersion); final sourceRequest = @@ -177,8 +191,7 @@ class CommonServerApi { return ok(result.toJson()); } - @Route.post('$apiPrefix/document') - Future document(Request request, String apiVersion) async { + Future handleDocument(Request request, String apiVersion) async { if (apiVersion != api3) return unhandledVersion(apiVersion); final sourceRequest = @@ -194,15 +207,7 @@ class CommonServerApi { return ok(result.toJson()); } - @Route.get('$apiPrefix/version') - Future versionGet(Request request, String apiVersion) async { - if (apiVersion != api3) return unhandledVersion(apiVersion); - - return ok(version().toJson()); - } - - @Route.post('$apiPrefix/openInIDX') - Future openInIdx(Request request, String apiVersion) async { + Future handleOpenInIdx(Request request, String apiVersion) async { final code = api.OpenInIdxRequest.fromJson(await request.readAsJson()).code; final idxUrl = Uri.parse('https://idx.google.com/run.api'); diff --git a/pkgs/dart_services/lib/src/common_server.g.dart b/pkgs/dart_services/lib/src/common_server.g.dart deleted file mode 100644 index f01227bf0..000000000 --- a/pkgs/dart_services/lib/src/common_server.g.dart +++ /dev/null @@ -1,57 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'common_server.dart'; - -// ************************************************************************** -// ShelfRouterGenerator -// ************************************************************************** - -Router _$CommonServerApiRouter(CommonServerApi service) { - final router = Router(); - router.add( - 'POST', - r'/api//analyze', - service.analyze, - ); - router.add( - 'POST', - r'/api//compile', - service.compile, - ); - router.add( - 'POST', - r'/api//compileDDC', - service.compileDDC, - ); - router.add( - 'POST', - r'/api//complete', - service.complete, - ); - router.add( - 'POST', - r'/api//fixes', - service.fixes, - ); - router.add( - 'POST', - r'/api//format', - service.format, - ); - router.add( - 'POST', - r'/api//document', - service.document, - ); - router.add( - 'GET', - r'/api//version', - service.versionGet, - ); - router.add( - 'POST', - r'/api//openInIDX', - service.openInIdx, - ); - return router; -} diff --git a/pkgs/dart_services/pubspec.yaml b/pkgs/dart_services/pubspec.yaml index 15fef7871..d890d0357 100644 --- a/pkgs/dart_services/pubspec.yaml +++ b/pkgs/dart_services/pubspec.yaml @@ -3,7 +3,7 @@ description: The backend service for DartPad. publish_to: none environment: - sdk: ^3.5.0 + sdk: ^3.6.0 dependencies: analysis_server_lib: ^0.2.5 @@ -24,16 +24,14 @@ dependencies: yaml: ^3.1.2 dev_dependencies: - build_runner: ^2.4.11 - collection: ^1.18.0 + collection: ^1.19.0 # TODO: Unpin once stable is updated to Dart 3.7. dart_flutter_team_lints: 3.2.1 grinder: ^0.9.5 - json_serializable: ^6.9.0 + json_serializable: ^6.9.2 package_config: ^2.1.0 - shelf_router_generator: ^1.1.1 synchronized: ^3.1.0+1 - test: ^1.25.7 + test: ^1.25.9 test_descriptor: ^2.0.1 dependency_overrides: