Dropping unused _dartpadsupportservicesApi (#478)
diff --git a/doc/generated/_dartpadsupportservices.dart b/doc/generated/_dartpadsupportservices.dart
deleted file mode 100644
index 38c4385..0000000
--- a/doc/generated/_dartpadsupportservices.dart
+++ /dev/null
@@ -1,286 +0,0 @@
-// This is a generated file (see the discoveryapis_generator project).
-
-// ignore_for_file: unnecessary_cast
-
-library dart_services.P_dartpadsupportservices.v1;
-
-import 'dart:core' as core;
-import 'dart:async' as async;
-import 'dart:convert' as convert;
-
-import 'package:_discoveryapis_commons/_discoveryapis_commons.dart' as commons;
-import 'package:http/http.dart' as http;
-
-export 'package:_discoveryapis_commons/_discoveryapis_commons.dart'
- show ApiRequestError, DetailedApiRequestError;
-
-const core.String USER_AGENT = 'dart-api-client _dartpadsupportservices/v1';
-
-class P_dartpadsupportservicesApi {
- final commons.ApiRequester _requester;
-
- P_dartpadsupportservicesApi(http.Client client,
- {core.String rootUrl: "/",
- core.String servicePath: "api/_dartpadsupportservices/v1/"})
- : _requester =
- new commons.ApiRequester(client, rootUrl, servicePath, USER_AGENT);
-
- /// Store a gist dataset to be retrieved.
- ///
- /// [request] - The metadata request object.
- ///
- /// Request parameters:
- ///
- /// Completes with a [UuidContainer].
- ///
- /// Completes with a [commons.ApiRequestError] if the API endpoint returned an
- /// error.
- ///
- /// If the used [http.Client] completes with an error when making a REST call,
- /// this method will complete with the same error.
- async.Future<UuidContainer> export(PadSaveObject request) {
- var _url = null;
- var _queryParams = new core.Map<core.String, core.List<core.String>>();
- var _uploadMedia = null;
- var _uploadOptions = null;
- var _downloadOptions = commons.DownloadOptions.Metadata;
- var _body = null;
-
- if (request != null) {
- _body = convert.json.encode((request).toJson());
- }
-
- _url = 'export';
-
- var _response = _requester.request(_url, "POST",
- body: _body,
- queryParams: _queryParams,
- uploadOptions: _uploadOptions,
- uploadMedia: _uploadMedia,
- downloadOptions: _downloadOptions);
- return _response.then((data) => new UuidContainer.fromJson(data));
- }
-
- /// Request parameters:
- ///
- /// Completes with a [UuidContainer].
- ///
- /// Completes with a [commons.ApiRequestError] if the API endpoint returned an
- /// error.
- ///
- /// If the used [http.Client] completes with an error when making a REST call,
- /// this method will complete with the same error.
- async.Future<UuidContainer> getUnusedMappingId() {
- var _url = null;
- var _queryParams = new core.Map<core.String, core.List<core.String>>();
- var _uploadMedia = null;
- var _uploadOptions = null;
- var _downloadOptions = commons.DownloadOptions.Metadata;
- var _body = null;
-
- _url = 'getUnusedMappingId';
-
- var _response = _requester.request(_url, "GET",
- body: _body,
- queryParams: _queryParams,
- uploadOptions: _uploadOptions,
- uploadMedia: _uploadMedia,
- downloadOptions: _downloadOptions);
- return _response.then((data) => new UuidContainer.fromJson(data));
- }
-
- /// Retrieve a stored gist data set.
- ///
- /// [request] - The metadata request object.
- ///
- /// Request parameters:
- ///
- /// Completes with a [PadSaveObject].
- ///
- /// Completes with a [commons.ApiRequestError] if the API endpoint returned an
- /// error.
- ///
- /// If the used [http.Client] completes with an error when making a REST call,
- /// this method will complete with the same error.
- async.Future<PadSaveObject> pullExportContent(UuidContainer request) {
- var _url = null;
- var _queryParams = new core.Map<core.String, core.List<core.String>>();
- var _uploadMedia = null;
- var _uploadOptions = null;
- var _downloadOptions = commons.DownloadOptions.Metadata;
- var _body = null;
-
- if (request != null) {
- _body = convert.json.encode((request).toJson());
- }
-
- _url = 'pullExportData';
-
- var _response = _requester.request(_url, "POST",
- body: _body,
- queryParams: _queryParams,
- uploadOptions: _uploadOptions,
- uploadMedia: _uploadMedia,
- downloadOptions: _downloadOptions);
- return _response.then((data) => new PadSaveObject.fromJson(data));
- }
-
- /// Request parameters:
- ///
- /// [id] - Query parameter: 'id'.
- ///
- /// Completes with a [UuidContainer].
- ///
- /// Completes with a [commons.ApiRequestError] if the API endpoint returned an
- /// error.
- ///
- /// If the used [http.Client] completes with an error when making a REST call,
- /// this method will complete with the same error.
- async.Future<UuidContainer> retrieveGist({core.String id}) {
- var _url = null;
- var _queryParams = new core.Map<core.String, core.List<core.String>>();
- var _uploadMedia = null;
- var _uploadOptions = null;
- var _downloadOptions = commons.DownloadOptions.Metadata;
- var _body = null;
-
- if (id != null) {
- _queryParams["id"] = [id];
- }
-
- _url = 'retrieveGist';
-
- var _response = _requester.request(_url, "GET",
- body: _body,
- queryParams: _queryParams,
- uploadOptions: _uploadOptions,
- uploadMedia: _uploadMedia,
- downloadOptions: _downloadOptions);
- return _response.then((data) => new UuidContainer.fromJson(data));
- }
-
- /// [request] - The metadata request object.
- ///
- /// Request parameters:
- ///
- /// Completes with a [UuidContainer].
- ///
- /// Completes with a [commons.ApiRequestError] if the API endpoint returned an
- /// error.
- ///
- /// If the used [http.Client] completes with an error when making a REST call,
- /// this method will complete with the same error.
- async.Future<UuidContainer> storeGist(GistToInternalIdMapping request) {
- var _url = null;
- var _queryParams = new core.Map<core.String, core.List<core.String>>();
- var _uploadMedia = null;
- var _uploadOptions = null;
- var _downloadOptions = commons.DownloadOptions.Metadata;
- var _body = null;
-
- if (request != null) {
- _body = convert.json.encode((request).toJson());
- }
-
- _url = 'storeGist';
-
- var _response = _requester.request(_url, "POST",
- body: _body,
- queryParams: _queryParams,
- uploadOptions: _uploadOptions,
- uploadMedia: _uploadMedia,
- downloadOptions: _downloadOptions);
- return _response.then((data) => new UuidContainer.fromJson(data));
- }
-}
-
-class GistToInternalIdMapping {
- core.String gistId;
- core.String internalId;
-
- GistToInternalIdMapping();
-
- GistToInternalIdMapping.fromJson(core.Map _json) {
- if (_json.containsKey("gistId")) {
- gistId = _json["gistId"];
- }
- if (_json.containsKey("internalId")) {
- internalId = _json["internalId"];
- }
- }
-
- core.Map<core.String, core.Object> toJson() {
- final core.Map<core.String, core.Object> _json =
- new core.Map<core.String, core.Object>();
- if (gistId != null) {
- _json["gistId"] = gistId;
- }
- if (internalId != null) {
- _json["internalId"] = internalId;
- }
- return _json;
- }
-}
-
-class PadSaveObject {
- core.String css;
- core.String dart;
- core.String html;
- core.String uuid;
-
- PadSaveObject();
-
- PadSaveObject.fromJson(core.Map _json) {
- if (_json.containsKey("css")) {
- css = _json["css"];
- }
- if (_json.containsKey("dart")) {
- dart = _json["dart"];
- }
- if (_json.containsKey("html")) {
- html = _json["html"];
- }
- if (_json.containsKey("uuid")) {
- uuid = _json["uuid"];
- }
- }
-
- core.Map<core.String, core.Object> toJson() {
- final core.Map<core.String, core.Object> _json =
- new core.Map<core.String, core.Object>();
- if (css != null) {
- _json["css"] = css;
- }
- if (dart != null) {
- _json["dart"] = dart;
- }
- if (html != null) {
- _json["html"] = html;
- }
- if (uuid != null) {
- _json["uuid"] = uuid;
- }
- return _json;
- }
-}
-
-class UuidContainer {
- core.String uuid;
-
- UuidContainer();
-
- UuidContainer.fromJson(core.Map _json) {
- if (_json.containsKey("uuid")) {
- uuid = _json["uuid"];
- }
- }
-
- core.Map<core.String, core.Object> toJson() {
- final core.Map<core.String, core.Object> _json =
- new core.Map<core.String, core.Object>();
- if (uuid != null) {
- _json["uuid"] = uuid;
- }
- return _json;
- }
-}
diff --git a/doc/generated/_dartpadsupportservices.json b/doc/generated/_dartpadsupportservices.json
deleted file mode 100644
index 08656c0..0000000
--- a/doc/generated/_dartpadsupportservices.json
+++ /dev/null
@@ -1,127 +0,0 @@
-{
- "kind": "discovery#restDescription",
- "etag": "c910828f54f3058a3a0c7ed72989a5003e08c5a0",
- "discoveryVersion": "v1",
- "id": "_dartpadsupportservices:v1",
- "name": "_dartpadsupportservices",
- "version": "v1",
- "revision": "0",
- "protocol": "rest",
- "baseUrl": "/api/_dartpadsupportservices/v1/",
- "basePath": "/api/_dartpadsupportservices/v1/",
- "rootUrl": "/",
- "servicePath": "api/_dartpadsupportservices/v1/",
- "parameters": {},
- "schemas": {
- "PadSaveObject": {
- "id": "PadSaveObject",
- "type": "object",
- "properties": {
- "dart": {
- "type": "string"
- },
- "html": {
- "type": "string"
- },
- "css": {
- "type": "string"
- },
- "uuid": {
- "type": "string"
- }
- }
- },
- "UuidContainer": {
- "id": "UuidContainer",
- "type": "object",
- "properties": {
- "uuid": {
- "type": "string"
- }
- }
- },
- "GistToInternalIdMapping": {
- "id": "GistToInternalIdMapping",
- "type": "object",
- "properties": {
- "gistId": {
- "type": "string"
- },
- "internalId": {
- "type": "string"
- }
- }
- }
- },
- "methods": {
- "export": {
- "id": "FileRelayServer.export",
- "path": "export",
- "httpMethod": "POST",
- "description": "Store a gist dataset to be retrieved.",
- "parameters": {},
- "parameterOrder": [],
- "request": {
- "$ref": "PadSaveObject"
- },
- "response": {
- "$ref": "UuidContainer"
- }
- },
- "pullExportContent": {
- "id": "FileRelayServer.pullExportContent",
- "path": "pullExportData",
- "httpMethod": "POST",
- "description": "Retrieve a stored gist data set.",
- "parameters": {},
- "parameterOrder": [],
- "request": {
- "$ref": "UuidContainer"
- },
- "response": {
- "$ref": "PadSaveObject"
- }
- },
- "getUnusedMappingId": {
- "id": "FileRelayServer.getUnusedMappingId",
- "path": "getUnusedMappingId",
- "httpMethod": "GET",
- "parameters": {},
- "parameterOrder": [],
- "response": {
- "$ref": "UuidContainer"
- }
- },
- "storeGist": {
- "id": "FileRelayServer.storeGist",
- "path": "storeGist",
- "httpMethod": "POST",
- "parameters": {},
- "parameterOrder": [],
- "request": {
- "$ref": "GistToInternalIdMapping"
- },
- "response": {
- "$ref": "UuidContainer"
- }
- },
- "retrieveGist": {
- "id": "FileRelayServer.retrieveGist",
- "path": "retrieveGist",
- "httpMethod": "GET",
- "parameters": {
- "id": {
- "type": "string",
- "description": "Query parameter: 'id'.",
- "required": false,
- "location": "query"
- }
- },
- "parameterOrder": [],
- "response": {
- "$ref": "UuidContainer"
- }
- }
- },
- "resources": {}
-}
diff --git a/example/apitest.dart b/example/apitest.dart
index 6584b9d..72e02a8 100644
--- a/example/apitest.dart
+++ b/example/apitest.dart
@@ -8,13 +8,11 @@
import 'package:codemirror/codemirror.dart';
-import '../doc/generated/_dartpadsupportservices.dart' as support;
import '../doc/generated/dartservices.dart' as services;
import 'services_utils.dart' as utils;
utils.SanitizingBrowserClient client;
services.DartservicesApi servicesApi;
-support.P_dartpadsupportservicesApi _dartpadSupportApi;
void main() {
setupAnalyze();
@@ -23,64 +21,12 @@
setupDocument();
setupFixes();
setupVersion();
- setupDartpadServices();
}
-void setupDartpadServices() {
- setupExport();
- setupRetrieve();
- setupIdRetrieval();
- setupGistStore();
- setupGistRetrieval();
-}
void _setupClients() {
client = utils.SanitizingBrowserClient();
servicesApi = services.DartservicesApi(client, rootUrl: _uriBase);
- _dartpadSupportApi =
- support.P_dartpadsupportservicesApi(client, rootUrl: _uriBase);
-}
-
-void setupIdRetrieval() {
- final output = querySelector('#idSection .output');
- final button = querySelector('#idSection button') as ButtonElement;
- button.onClick.listen((e) {
- final sw = Stopwatch()..start();
- _dartpadSupportApi.getUnusedMappingId().then((results) {
- output.text = '${_formatTiming(sw)}${results.toJson()}';
- });
- });
-}
-
-void setupGistStore() {
- final editor = createEditor(querySelector('#storeSection .editor'),
- defaultText: 'Internal ID');
- final output = querySelector('#storeSection .output');
- final button = querySelector('#storeSection button') as ButtonElement;
- button.onClick.listen((e) {
- final editorText = editor.getDoc().getValue();
- final saveObject = support.GistToInternalIdMapping();
- saveObject.internalId = editorText;
- saveObject.gistId = '72d83fe97bfc8e735607'; //Solar
- final sw = Stopwatch()..start();
- _dartpadSupportApi.storeGist(saveObject).then((results) {
- output.text = '${_formatTiming(sw)}${results.toJson()}';
- });
- });
-}
-
-void setupGistRetrieval() {
- final editor = createEditor(querySelector('#gistSection .editor'),
- defaultText: 'Internal ID');
- final output = querySelector('#gistSection .output');
- final button = querySelector('#gistSection button') as ButtonElement;
- button.onClick.listen((e) {
- final editorText = editor.getDoc().getValue();
- final sw = Stopwatch()..start();
- _dartpadSupportApi.retrieveGist(id: editorText).then((results) {
- output.text = '${_formatTiming(sw)}${results.toJson()}';
- });
- });
}
void setupAnalyze() {
@@ -182,36 +128,6 @@
});
}
-void setupExport() {
- final editor = createEditor(querySelector('#exportSection .editor'));
- final output = querySelector('#exportSection .output');
- final button = querySelector('#exportSection button') as ButtonElement;
- button.onClick.listen((e) {
- final saveObject = support.PadSaveObject();
- saveObject.dart = editor.getDoc().getValue();
- final sw = Stopwatch()..start();
- _dartpadSupportApi.export(saveObject).then((results) {
- output.text = '${_formatTiming(sw)}${results.toJson()}';
- });
- });
-}
-
-void setupRetrieve() {
- final output = querySelector('#retrieveSection .output');
- final editor =
- createEditor(querySelector('#retrieveSection .editor'), defaultText: '');
- final button = querySelector('#retrieveSection button') as ButtonElement;
- button.onClick.listen((e) {
- final uuid = editor.getDoc().getValue();
- final sw = Stopwatch()..start();
- final uuidContainer = support.UuidContainer()..uuid = uuid;
-
- _dartpadSupportApi.pullExportContent(uuidContainer).then((results) {
- output.text = '${_formatTiming(sw)}${results.toJson()}';
- });
- });
-}
-
CodeMirror createEditor(Element element, {String defaultText}) {
final options = {
'tabSize': 2,
diff --git a/lib/services_dev.dart b/lib/services_dev.dart
index 8f7df7f..463df6c 100644
--- a/lib/services_dev.dart
+++ b/lib/services_dev.dart
@@ -18,7 +18,6 @@
import 'src/common.dart';
import 'src/common_server.dart';
-import 'src/dartpad_support_server.dart';
import 'src/flutter_web.dart';
import 'src/shelf_cors.dart' as shelf_cors;
@@ -48,12 +47,9 @@
if (result['discovery'] as bool) {
final serverUrl = result['server-url'] as String;
- if (result['relay'] as bool) {
- EndpointsServer.generateRelayDiscovery(sdk, serverUrl).then(printExit);
- } else {
- EndpointsServer.generateDiscovery(SdkManager.flutterSdk, serverUrl)
- .then(printExit);
- }
+ EndpointsServer.generateDiscovery(SdkManager.flutterSdk, serverUrl)
+ .then(printExit);
+
return;
}
@@ -97,21 +93,6 @@
return utf8.decode(await response.body.first);
}
- static Future<String> generateRelayDiscovery(
- String sdkPath, String serverUrl) async {
- final databaseServer = FileRelayServer();
- final apiServer = ApiServer(apiPrefix: '/api', prettyPrint: true)
- ..addApi(databaseServer);
- apiServer.enableDiscoveryApi();
-
- final uri =
- Uri.parse('/api/discovery/v1/apis/_dartpadsupportservices/v1/rest');
- final request = HttpApiRequest('GET', uri, <String, dynamic>{},
- Stream<List<int>>.fromIterable(<List<int>>[]));
- final response = await apiServer.handleHttpApiRequest(request);
- return utf8.decode(await response.body.first);
- }
-
final int port;
HttpServer server;
diff --git a/lib/services_gae.dart b/lib/services_gae.dart
index 7159f23..e486271 100644
--- a/lib/services_gae.dart
+++ b/lib/services_gae.dart
@@ -14,7 +14,6 @@
import 'src/common.dart';
import 'src/common_server.dart';
-import 'src/dartpad_support_server.dart';
import 'src/flutter_web.dart';
const String _API = '/api';
@@ -62,14 +61,12 @@
rpc.ApiServer apiServer;
FlutterWebManager flutterWebManager;
CommonServer commonServer;
- FileRelayServer fileRelayServer;
GaeServer(this.sdkPath, this.redisServerUri) {
hierarchicalLoggingEnabled = true;
_logger.level = Level.ALL;
discoveryEnabled = false;
- fileRelayServer = FileRelayServer();
flutterWebManager = FlutterWebManager(SdkManager.flutterSdk);
commonServer = CommonServer(
sdkPath,
@@ -81,8 +78,7 @@
redisServerUri, io.Platform.environment['GAE_VERSION']));
// Enabled pretty printing of returned json for debuggability.
apiServer = rpc.ApiServer(apiPrefix: _API, prettyPrint: true)
- ..addApi(commonServer)
- ..addApi(fileRelayServer);
+ ..addApi(commonServer);
}
Future<dynamic> start([int gaePort = 8080]) async {
diff --git a/lib/src/dartpad_support_server.dart b/lib/src/dartpad_support_server.dart
deleted file mode 100644
index 5617faa..0000000
--- a/lib/src/dartpad_support_server.dart
+++ /dev/null
@@ -1,300 +0,0 @@
-// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-library services.database;
-
-import 'dart:async';
-import 'dart:convert' as convert;
-import 'dart:io' as io;
-import 'dart:mirrors' as mirrors;
-
-import 'package:appengine/appengine.dart' as ae;
-import 'package:crypto/crypto.dart' as crypto;
-import 'package:gcloud/db.dart' as db;
-import 'package:logging/logging.dart';
-import 'package:pedantic/pedantic.dart';
-import 'package:rpc/rpc.dart';
-import 'package:uuid/uuid.dart' as uuid_tools;
-
-final Logger _logger = Logger('dartpad_support_server');
-
-// This class defines the interface that the server provides.
-@ApiClass(name: '_dartpadsupportservices', version: 'v1')
-class FileRelayServer {
- Map<String, List<dynamic>> database;
- bool test;
-
- String getTypeName(dynamic obj) =>
- mirrors.reflect(obj).type.reflectedType.toString();
-
- String getClass(dynamic obj) => mirrors.MirrorSystem.getName(
- mirrors.reflectClass(obj as Type).simpleName);
-
- FileRelayServer({this.test = false}) {
- hierarchicalLoggingEnabled = true;
- _logger.level = Level.ALL;
- if (test) {
- database = <String, List<dynamic>>{};
- }
- }
-
- Future<List<dynamic>> _databaseQuery<T extends db.Model>(
- String attribute, dynamic value) async {
- var result = <dynamic>[];
- if (test) {
- final dataList = database[getClass(T)];
- if (dataList != null) {
- for (final dataObject in dataList) {
- final dataObjectMirror = mirrors.reflect(dataObject);
- final futureValue =
- dataObjectMirror.getField(Symbol(attribute.split(' ')[0]));
- if (futureValue.hasReflectee && futureValue.reflectee == value) {
- result.add(dataObject);
- }
- }
- }
- } else {
- final query = ae.context.services.db.query<T>()..filter(attribute, value);
- result = await query.run().toList();
- }
- return Future<List<dynamic>>.value(result);
- }
-
- Future<void> _databaseCommit({List<db.Model> inserts, List<db.Key> deletes}) {
- if (test) {
- if (inserts != null) {
- for (final insertObject in inserts) {
- if (!database.containsKey(getTypeName(insertObject))) {
- database[getTypeName(insertObject)] = <dynamic>[];
- }
- database[getTypeName(insertObject)].add(insertObject);
- }
- }
- if (deletes != null) {
- // TODO: Implement delete
- }
- } else {
- ae.context.services.db.commit(inserts: inserts, deletes: deletes);
- }
- return Future<void>.value(null);
- }
-
- @ApiMethod(
- method: 'POST',
- path: 'export',
- description: 'Store a gist dataset to be retrieved.')
- Future<UuidContainer> export(PadSaveObject data) {
- final record = _GaePadSaveObject.fromDSO(data);
- final randomUuid = uuid_tools.Uuid().v4();
- record.uuid = '${_computeSHA1(record)}-$randomUuid';
- _databaseCommit(inserts: <db.Model>[record]).catchError((dynamic e) {
- _logger.severe('Error while recording export $e');
- throw e;
- });
- _logger.info('Recorded Export with ID ${record.uuid}');
- return Future<UuidContainer>.value(UuidContainer.fromUuid(record.uuid));
- }
-
- @ApiMethod(
- method: 'POST',
- path: 'pullExportData',
- description: 'Retrieve a stored gist data set.')
- Future<PadSaveObject> pullExportContent(UuidContainer uuidContainer) async {
- final result =
- await _databaseQuery<_GaePadSaveObject>('uuid =', uuidContainer.uuid);
- if (result.isEmpty) {
- _logger
- .severe('Export with UUID ${uuidContainer.uuid} could not be found.');
- throw BadRequestError('Nothing of correct uuid could be found.');
- }
- final record = result.first as _GaePadSaveObject;
- if (!test) {
- unawaited(_databaseCommit(deletes: <db.Key>[record.key])
- .catchError((dynamic e) {
- _logger.severe('Error while deleting export $e');
- throw (e);
- }));
- _logger.info('Deleted Export with ID ${record.uuid}');
- }
- return Future<PadSaveObject>.value(PadSaveObject.fromRecordSource(record));
- }
-
- @ApiMethod(method: 'GET', path: 'getUnusedMappingId')
- Future<UuidContainer> getUnusedMappingId() async {
- final limit = 4;
- var attemptCount = 0;
- String randomUuid;
- List<dynamic> result;
- do {
- randomUuid = uuid_tools.Uuid().v4();
- result = await _databaseQuery<_GistMapping>('internalId =', randomUuid);
- attemptCount++;
- if (result.isNotEmpty) {
- _logger.info('Collision in retrieving mapping id $randomUuid.');
- }
- } while (result.isNotEmpty && attemptCount < limit);
- if (result.isNotEmpty) {
- _logger.severe('Could not generate valid ID.');
- throw InternalServerError('Could not generate ID.');
- }
- _logger.info('Valid ID $randomUuid retrieved.');
- return Future<UuidContainer>.value(UuidContainer.fromUuid(randomUuid));
- }
-
- @ApiMethod(method: 'POST', path: 'storeGist')
- Future<UuidContainer> storeGist(GistToInternalIdMapping map) async {
- final result =
- await _databaseQuery<_GistMapping>('internalId =', map.internalId);
- if (result.isNotEmpty) {
- _logger.severe('Collision with mapping of Id ${map.gistId}.');
- throw BadRequestError('Mapping invalid.');
- } else {
- final entry = _GistMapping.fromMap(map);
- unawaited(
- _databaseCommit(inserts: <db.Model>[entry]).catchError((dynamic e) {
- _logger.severe(
- 'Error while recording mapping with Id ${map.gistId}. Error $e');
- throw e;
- }));
- _logger.info('Mapping with ID ${map.gistId} stored.');
- return Future<UuidContainer>.value(UuidContainer.fromUuid(map.gistId));
- }
- }
-
- @ApiMethod(method: 'GET', path: 'retrieveGist')
- Future<UuidContainer> retrieveGist({String id}) async {
- if (id == null) {
- throw BadRequestError('Missing parameter: \'id\'');
- }
- final result = await _databaseQuery<_GistMapping>('internalId =', id);
- if (result.isEmpty) {
- _logger.severe('Missing mapping for Id $id.');
- throw BadRequestError('Missing mapping for Id $id');
- } else {
- final entry = result.first as _GistMapping;
- _logger.info('Mapping with ID $id retrieved.');
- return Future<UuidContainer>.value(UuidContainer.fromUuid(entry.gistId));
- }
- }
-}
-
-/// Public interface object for storage of pads.
-class PadSaveObject {
- String dart;
- String html;
- String css;
- String uuid;
-
- PadSaveObject();
-
- PadSaveObject.fromData(this.dart, this.html, this.css, {this.uuid});
-
- PadSaveObject.fromRecordSource(_GaePadSaveObject record) {
- dart = record.getDart;
- html = record.getHtml;
- css = record.getCss;
- uuid = record.uuid;
- }
-}
-
-/// String container for IDs
-class UuidContainer {
- String uuid;
-
- UuidContainer();
-
- UuidContainer.fromUuid(this.uuid);
-}
-
-/// Map from id to id
-class GistToInternalIdMapping {
- String gistId;
- String internalId;
-
- GistToInternalIdMapping();
-
- GistToInternalIdMapping.fromIds(this.gistId, this.internalId);
-}
-
-/// Internal storage representation for storage of pads.
-@db.Kind()
-class _GaePadSaveObject extends db.Model {
- @db.BlobProperty()
- List<int> dart;
-
- @db.IntProperty()
- int epochTime;
-
- @db.BlobProperty()
- List<int> html;
-
- @db.BlobProperty()
- List<int> css;
-
- @db.StringProperty()
- String uuid;
-
- _GaePadSaveObject() {
- epochTime = DateTime.now().millisecondsSinceEpoch;
- }
-
- _GaePadSaveObject.fromData(String dart, String html, String css,
- {this.uuid}) {
- this.dart = _gzipEncode(dart);
- this.html = _gzipEncode(html);
- this.css = _gzipEncode(css);
- epochTime = DateTime.now().millisecondsSinceEpoch;
- }
-
- _GaePadSaveObject.fromDSO(PadSaveObject pso) {
- dart = _gzipEncode(pso.dart ?? '');
- html = _gzipEncode(pso.html ?? '');
- css = _gzipEncode(pso.css ?? '');
- uuid = pso.uuid;
- epochTime = DateTime.now().millisecondsSinceEpoch;
- }
-
- String get getDart => _gzipDecode(dart);
-
- String get getHtml => _gzipDecode(html);
-
- String get getCss => _gzipDecode(css);
-}
-
-/// Internal storage representation for gist id mapping.
-@db.Kind()
-class _GistMapping extends db.Model {
- @db.StringProperty()
- String internalId;
-
- @db.StringProperty()
- String gistId;
-
- @db.IntProperty()
- int epochTime;
-
- _GistMapping() {
- epochTime = DateTime.now().millisecondsSinceEpoch;
- }
-
- _GistMapping.fromMap(GistToInternalIdMapping map) {
- internalId = map.internalId;
- gistId = map.gistId;
- epochTime = DateTime.now().millisecondsSinceEpoch;
- }
-}
-
-String _computeSHA1(_GaePadSaveObject record) {
- final utf8 = convert.Utf8Encoder();
- return crypto.sha1
- .convert(utf8.convert(
- "blob 'n ${record.getDart} ${record.getHtml} ${record.getCss}"))
- .toString();
-}
-
-List<int> _gzipEncode(String input) =>
- io.gzip.encode(convert.utf8.encode(input));
-
-String _gzipDecode(List<int> input) =>
- convert.utf8.decode(io.gzip.decode(input));
diff --git a/test/all.dart b/test/all.dart
index 2b4ba9c..afd393d 100644
--- a/test/all.dart
+++ b/test/all.dart
@@ -10,7 +10,6 @@
import 'common_server_test.dart' as common_server_test;
import 'common_test.dart' as common_test;
import 'compiler_test.dart' as compiler_test;
-import 'dartpad_server_test.dart' as dartpad_server_test;
import 'flutter_web_test.dart' as flutter_web_test;
import 'gae_deployed_test.dart' as gae_deployed_test;
import 'pub_test.dart' as pub_test;
@@ -24,7 +23,6 @@
common_server_test.defineTests();
common_test.defineTests();
compiler_test.defineTests();
- dartpad_server_test.defineTests();
flutter_web_test.defineTests();
gae_deployed_test.defineTests();
pub_test.defineTests();
diff --git a/test/dartpad_server_test.dart b/test/dartpad_server_test.dart
deleted file mode 100644
index 0cfa1e9..0000000
--- a/test/dartpad_server_test.dart
+++ /dev/null
@@ -1,187 +0,0 @@
-// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-library services.dartpad_server_test;
-
-import 'dart:async';
-import 'dart:convert';
-
-import 'package:rpc/rpc.dart';
-import 'package:dart_services/src/common.dart';
-import 'package:dart_services/src/dartpad_support_server.dart';
-import 'package:test/test.dart';
-
-String quickFixesCode = r'''
-import 'dart:async';
-void main() {
- int i = 0;
-}
-''';
-
-String preFormattedCode = r'''
-void main()
-{
-int i = 0;
-}
-''';
-
-String postFormattedCode = r'''
-void main() {
- int i = 0;
-}
-''';
-
-void main() => defineTests();
-
-void defineTests() {
- FileRelayServer server;
- ApiServer apiServer;
-
- server = FileRelayServer(test: true);
- apiServer = ApiServer(apiPrefix: '/api', prettyPrint: true);
- apiServer.addApi(server);
-
- Future<HttpApiResponse> _sendPostRequest(String path, jsonData) {
- assert(apiServer != null);
- final uri = Uri.parse('/api/$path');
- final body = Stream.fromIterable([utf8.encode(json.encode(jsonData))]);
- final request = HttpApiRequest(
- 'POST', uri, {'content-type': 'application/json; charset=utf-8'}, body);
- return apiServer.handleHttpApiRequest(request);
- }
-
- Future<HttpApiResponse> _sendGetRequest(String path, [String queryParams]) {
- assert(apiServer != null);
- final uri = Uri.parse(
- queryParams == null ? '/api/$path' : '/api/$path?$queryParams');
- final body = Stream<List<int>>.fromIterable([]);
- final request = HttpApiRequest(
- 'GET', uri, {'content-type': 'application/json; charset=utf-8'}, body);
- return apiServer.handleHttpApiRequest(request);
- }
-
- group('ExportServer', () {
- test('Export', () async {
- final jsonData = {'dart': 'test', 'html': '', 'css': '', 'uuid': ''};
- final response =
- await _sendPostRequest('_dartpadsupportservices/v1/export', jsonData);
- expect(response.status, 200);
- final data = json.decode(utf8.decode(await response.body.first));
- expect(data['uuid'], isNotNull);
- });
-
- test('Export uuid different', () async {
- final jsonData = {'dart': 'test', 'html': '', 'css': '', 'uuid': ''};
- final response =
- await _sendPostRequest('_dartpadsupportservices/v1/export', jsonData);
- expect(response.status, 200);
- final data = json.decode(utf8.decode(await response.body.first));
- expect(data['uuid'], isNotNull);
- final responseTwo =
- await _sendPostRequest('_dartpadsupportservices/v1/export', jsonData);
- expect(responseTwo.status, 200);
- final dataTwo = json.decode(utf8.decode(await responseTwo.body.first));
- expect(dataTwo['uuid'] == data['uuid'], false);
- });
-
- test('Pull export', () async {
- var jsonData = {'dart': sampleCode, 'html': '', 'css': ''};
- final response =
- await _sendPostRequest('_dartpadsupportservices/v1/export', jsonData);
- expect(response.status, 200);
- final data = json.decode(utf8.decode(await response.body.first));
- expect(data['uuid'], isNotNull);
- jsonData = {'uuid': data['uuid'] as String};
- final pull = await _sendPostRequest(
- '_dartpadsupportservices/v1/pullExportData', jsonData);
- expect(pull.status, 200);
- final pullData = json.decode(utf8.decode(await pull.body.first));
- expect(pullData['dart'], sampleCode);
- expect(pullData['html'], '');
- expect(pullData['css'], '');
- expect(pullData['uuid'], data['uuid']);
- });
- // TODO: Test delete functionality
- });
-
- group('GistMapping', () {
- test('ID request', () async {
- final response = await _sendGetRequest(
- '_dartpadsupportservices/v1/getUnusedMappingId');
- expect(response.status, 200);
- final data = json.decode(utf8.decode(await response.body.first));
- expect(data['uuid'], isNotNull);
- final responseTwo = await _sendGetRequest(
- '_dartpadsupportservices/v1/getUnusedMappingId');
- expect(responseTwo.status, 200);
- final dataTwo = json.decode(utf8.decode(await responseTwo.body.first));
- expect(data['uuid'] == dataTwo['uuid'], false);
- });
-
- test('Store gist', () async {
- final response = await _sendGetRequest(
- '_dartpadsupportservices/v1/getUnusedMappingId');
- final gistId = 'teststore';
- expect(response.status, 200);
- final data = json.decode(utf8.decode(await response.body.first));
- expect(data['uuid'], isNotNull);
- final jsonData = {'gistId': gistId, 'internalId': data['uuid']};
- final postResponse = await _sendPostRequest(
- '_dartpadsupportservices/v1/storeGist', jsonData);
- expect(postResponse.status, 200);
- final postData = json.decode(utf8.decode(await postResponse.body.first));
- expect(postData['uuid'], gistId);
- });
-
- test('Store gist failure', () async {
- final response = await _sendGetRequest(
- '_dartpadsupportservices/v1/getUnusedMappingId');
- final gistId = 'testfail';
- expect(response.status, 200);
- final data = json.decode(utf8.decode(await response.body.first));
- expect(data['uuid'], isNotNull);
- var jsonData = {'gistId': gistId, 'internalId': data['uuid']};
- var postResponse = await _sendPostRequest(
- '_dartpadsupportservices/v1/storeGist', jsonData);
- expect(postResponse.status, 200);
- final postData = json.decode(utf8.decode(await postResponse.body.first));
- expect(postData['uuid'], gistId);
- jsonData = {'gistId': 'failure', 'internalId': data['uuid']};
- postResponse = await _sendPostRequest(
- '_dartpadsupportservices/v1/storeGist', jsonData);
- expect(postResponse.status, 400);
- });
-
- test('Retrieve gist success', () async {
- final response = await _sendGetRequest(
- '_dartpadsupportservices/v1/getUnusedMappingId');
- final gistId = 'testretrieve';
- expect(response.status, 200);
- final data = json.decode(utf8.decode(await response.body.first));
- expect(data['uuid'], isNotNull);
- final jsonData = {'gistId': gistId, 'internalId': data['uuid']};
- final postResponse = await _sendPostRequest(
- '_dartpadsupportservices/v1/storeGist', jsonData);
- expect(postResponse.status, 200);
- final postData = json.decode(utf8.decode(await postResponse.body.first));
- expect(postData['uuid'], gistId);
- final getResponse = await _sendGetRequest(
- '_dartpadsupportservices/v1/retrieveGist', 'id=${data['uuid']}');
- expect(getResponse.status, 200);
- final getData = json.decode(utf8.decode(await getResponse.body.first));
- expect(getData['uuid'], gistId);
- });
-
- test('Retrieve gist failure', () async {
- final response = await _sendGetRequest(
- '_dartpadsupportservices/v1/getUnusedMappingId');
- expect(response.status, 200);
- final data = json.decode(utf8.decode(await response.body.first));
- expect(data['uuid'], isNotNull);
- final getResponse = await _sendGetRequest(
- '_dartpadsupportservices/v1/retrieveGist', 'id=${data['uuid']}');
- expect(getResponse.status, 400);
- });
- });
-}
diff --git a/tool/grind.dart b/tool/grind.dart
index 799a6a8..ac2c331 100644
--- a/tool/grind.dart
+++ b/tool/grind.dart
@@ -51,8 +51,7 @@
@Task('Update the docker and SDK versions')
void updateDockerVersion() {
final platformVersion = Platform.version.split(' ').first;
- final dockerImageLines =
- File('Dockerfile').readAsLinesSync().map((String s) {
+ final dockerImageLines = File('Dockerfile').readAsLinesSync().map((String s) {
if (s.contains(_dockerVersionMatcher)) {
return 'FROM google/dart-runtime:$platformVersion';
}
@@ -73,8 +72,7 @@
void validateStorageArtifacts() async {
final version = SdkManager.flutterSdk.versionFull;
- const urlBase =
- 'https://storage.googleapis.com/compilation_artifacts/';
+ const urlBase = 'https://storage.googleapis.com/compilation_artifacts/';
for (final artifact in compilationArtifacts) {
await _validateExists('$urlBase$version/$artifact');
@@ -96,8 +94,7 @@
@Task('build the sdk compilation artifacts for upload to google storage')
void buildStorageArtifacts() {
// build and copy dart_sdk.js, flutter_web.js, and flutter_web.dill
- final temp =
- Directory.systemTemp.createTempSync('flutter_web_sample');
+ final temp = Directory.systemTemp.createTempSync('flutter_web_sample');
try {
_buildStorageArtifacts(temp);
@@ -243,8 +240,8 @@
}
@Task('Update discovery files and run all checks prior to deployment')
-@Depends(updateDockerVersion, discovery, analyze, test, fuzz,
- validateStorageArtifacts)
+@Depends(setupFlutterSubmodule, updateDockerVersion, discovery, analyze, test,
+ fuzz, validateStorageArtifacts)
void deploy() {
log('Run: gcloud app deploy --project=dart-services --no-promote');
}
@@ -267,18 +264,6 @@
log('writing ${discoveryFile.path}');
discoveryFile.writeAsStringSync('${result.stdout.trim()}\n');
- final resultDb = Process.runSync(
- Platform.executable, ['bin/server_dev.dart', '--discovery', '--relay']);
-
- if (resultDb.exitCode != 0) {
- throw 'Error generating the discovery document\n${result.stderr}';
- }
-
- final discoveryDbFile = File('doc/generated/_dartpadsupportservices.json');
- discoveryDbFile.parent.createSync();
- log('writing ${discoveryDbFile.path}');
- discoveryDbFile.writeAsStringSync('${resultDb.stdout.trim()}\n');
-
// Generate the Dart library from the json discovery file.
Pub.global.activate('discoveryapis_generator');
Pub.global.run('discoveryapis_generator:generate', arguments: [