blob: f61c628ed15dac99c554b773dd27f46020e61140 [file] [log] [blame]
library syncbase_client;
import 'dart:async';
import 'dart:typed_data' show Uint8List;
import 'package:mojo/application.dart' show Application;
import 'gen/dart-gen/mojom/lib/mojo/syncbase.mojom.dart' as mojom;
// Export struct types from syncbase.mojom.
export 'gen/dart-gen/mojom/lib/mojo/syncbase.mojom.dart'
show BatchOptions, Perms, SyncGroupMemberInfo, SyncGroupSpec;
part 'src/app.dart';
part 'src/named_resource.dart';
part 'src/nosql/database.dart';
part 'src/nosql/row.dart';
part 'src/nosql/syncgroup.dart';
part 'src/nosql/table.dart';
bool isError(mojom.Error err) {
return err != null && err.id != '';
}
// TODO(nlacasse): Write some tests for this interface now that syncbase runs
// as a mojo service. Currently we rely on dartanalyzer for correctness.
class SyncbaseClient {
final Application _mojoApp;
final mojom.SyncbaseProxy _proxy;
final String url;
SyncbaseClient(this._mojoApp, this.url)
: _proxy = new mojom.SyncbaseProxy.unbound() {
print('connecting to $url');
_mojoApp.connectToService(url, _proxy);
print('connected');
}
// Closes the connection to the syncbase server.
// TODO(nlacasse): Is this necessary?
Future close({bool immediate: false}) {
return _proxy.close();
}
// app returns the app with the given name, which should not contain slashes.
SyncbaseApp app(String name) => new SyncbaseApp._internal(_proxy, name);
Future<mojom.Perms> getPermissions() async {
var v = await _proxy.ptr.serviceGetPermissions();
if (isError(v.err)) throw v.err;
// TODO(nlacasse): We need to return the version too. Create a struct type
// that combines perms and version?
return v.perms;
}
Future setPermissions(mojom.Perms perms, String version) async {
var v = await _proxy.ptr.serviceSetPermissions(perms, version);
if (isError(v.err)) throw v.err;
return;
}
}