Skip to content

Commit

Permalink
Merge 6fe38b9 into 707edcc
Browse files Browse the repository at this point in the history
  • Loading branch information
desistefanova committed May 25, 2023
2 parents 707edcc + 6fe38b9 commit 6608c2c
Show file tree
Hide file tree
Showing 10 changed files with 685 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,8 @@
## vNext (TBD)

### Enhancements

* Added `User.getMongoDBbClient` exposing an API for CRUD operations on a Remote Atlas App Service.([#1162](https://github.com/realm/realm-dart/issues/1162))
* Add `RealmResults.isValid` ([#1231](https://github.com/realm/realm-dart/pull/1231)).
* Support `Decimal128` datatype ([#1192](https://github.com/realm/realm-dart/pull/1192)).
* Realm logging is extended to support logging of all Realm storage level messages. (Core upgrade).
Expand Down
5 changes: 4 additions & 1 deletion dartdoc_options.yaml
Expand Up @@ -15,7 +15,10 @@ dartdoc:
"Sync":
markdown: topic.md
name: Sync
categoryOrder: ["Realm", "Configuration", "Annotations", "Application", "Sync"]
"Atlas App Services":
markdown: topic.md
name: Atlas App Services
categoryOrder: ["Realm", "Configuration", "Annotations", "Application", "Sync", "Atlas App Services"]
examplePathPrefix: 'example'
# nodoc: ['generator/flutter/ffigen/scripts/src/test/*.g.dart']
showUndocumentedCategories: true
Expand Down
2 changes: 2 additions & 0 deletions flutter/realm_flutter/tests/test_driver/realm_test.dart
Expand Up @@ -26,6 +26,7 @@ import '../test/session_test.dart' as session_test;
import '../test/subscription_test.dart' as subscription_test;
import '../test/user_test.dart' as user_test;
import '../test/realm_logger_test.dart' as realm_logger_test;
import '../test/mongodb_docs_test.dart' as mongodb_docs_test;

Future<String> main(List<String> args) async {
final Completer<String> completer = Completer<String>();
Expand Down Expand Up @@ -53,6 +54,7 @@ Future<String> main(List<String> args) async {
await subscription_test.main(args);
await user_test.main(args);
await realm_logger_test.main(args);
await mongodb_docs_test.main(args);

tearDown(() {
if (Invoker.current?.liveTest.state.result == test_api.Result.error || Invoker.current?.liveTest.state.result == test_api.Result.failure) {
Expand Down
46 changes: 42 additions & 4 deletions lib/src/cli/atlas_apps/baas_client.dart
Expand Up @@ -84,7 +84,32 @@ class BaasClient {
}
};''';

static const String _documentCollectionName = "AtlasDocAllTypes";
static const String _documentCollectionSchema = '''{
"title": "AtlasDocAllTypes",
"bsonType": "object",
"required": ["_id", "stringProp", "boolProp", "dateProp", "doubleProp", "objectIdProp", "uuidProp", "intProp"],
"properties": {
"_id": {"bsonType": "objectId"},
"stringProp": {"bsonType": "string"},
"boolProp": {"bsonType": "bool"},
"dateProp": {"bsonType": "date"},
"doubleProp": {"bsonType": "double"},
"objectIdProp": {"bsonType": "objectId"},
"uuidProp": {"bsonType": "uuid"},
"intProp": {"bsonType": "long"},
"nullableStringProp": {"bsonType": "string"},
"nullableBoolProp": {"bsonType": "bool"},
"nullableDateProp": {"bsonType": "date"},
"nullableDoubleProp": {"bsonType": "double"},
"nullableObjectIdProp": {"bsonType": "objectId"},
"nullableUuidProp": {"bsonType": "uuid"},
"nullableIntProp": {"bsonType": "long"}
}
}''';

static const String defaultAppName = "flexible";
static const String serviceName = 'BackingDB';

final String _baseUrl;
final String? _clusterName;
Expand Down Expand Up @@ -355,6 +380,7 @@ class BaasClient {

await _createMongoDBService(
app,
serviceName,
syncConfig: '''{
"flexible_sync": {
"state": "enabled",
Expand Down Expand Up @@ -382,6 +408,9 @@ class BaasClient {
);
await _put('groups/$_groupId/apps/$appId/sync/config', '{ "development_mode_enabled": true }');

if (confirmationType != "email" && confirmationType != "auto") {
await createSchema(app, serviceName: serviceName, collectionName: _documentCollectionName, schema: _documentCollectionSchema);
}
//create email/password user for tests
final dynamic createUserResult = await _post('groups/$_groupId/apps/$appId/users', '{"email": "realm-test@realm.io", "password":"123456"}');
print("Create user result: $createUserResult");
Expand Down Expand Up @@ -464,10 +493,10 @@ class BaasClient {
}''');
}

Future<String> _createMongoDBService(BaasApp app, {required String syncConfig, required String rules}) async {
final serviceName = _clusterName == null ? 'mongodb' : 'mongodb-atlas';
Future<String> _createMongoDBService(BaasApp app, String serviceName, {required String syncConfig, required String rules}) async {
final serviceType = _clusterName == null ? 'mongodb' : 'mongodb-atlas';
final mongoConfig = _clusterName == null ? '{ "uri": "mongodb://localhost:26000" }' : '{ "clusterName": "$_clusterName" }';
final mongoServiceId = await _createService(app, 'BackingDB', serviceName, mongoConfig);
final mongoServiceId = await _createService(app, serviceName, serviceType, mongoConfig);

await _post('groups/$_groupId/apps/$app/services/$mongoServiceId/default_rule', rules);

Expand Down Expand Up @@ -581,7 +610,7 @@ class BaasClient {
final app = BaasApp(appId, clientAppId, name, appUniqueName);

final dynamic services = await _get('groups/$_groupId/apps/$appId/services');
dynamic service = services.firstWhere((dynamic s) => s["name"] == "BackingDB", orElse: () => throw Exception("Func 'confirmFunc' not found"));
dynamic service = services.firstWhere((dynamic s) => s["name"] == serviceName, orElse: () => throw Exception("Func 'confirmFunc' not found"));
final mongoServiceId = service['_id'] as String;
final dynamic configDocs = await _get('groups/$_groupId/apps/$appId/services/$mongoServiceId/config');
final dynamic flexibleSync = configDocs['flexible_sync'];
Expand All @@ -593,6 +622,15 @@ class BaasClient {
});
await _patch('groups/$_groupId/apps/$app/services/$mongoServiceId/config', data);
}

Future<void> createSchema(BaasApp app, {required String serviceName, required String collectionName, required dynamic schema}) async {
print('Create schema $collectionName for ${app.clientAppId}');

final urlSchema = 'groups/$_groupId/apps/$app/schemas';
dynamic metadata = '{"database": "db_${app.uniqueName}", "collection": "$collectionName", "data_source": "$serviceName"}';
String fullSchema = '{"metadata": $metadata, "schema": $schema }';
await _post(urlSchema, fullSchema);
}
}

class BaasApp {
Expand Down

0 comments on commit 6608c2c

Please sign in to comment.