Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit bd6de71

Browse files
Fix Dart 2 runtime issues. (#53)
Upgrade to Dart 2.0.0-dev.54.0 to fix issues with mirrors in Dart 2 mode. Added lots of types.
1 parent a509960 commit bd6de71

24 files changed

+174
-158
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
.dart_tool/
12
pubspec.lock
23
packages
34
.pub
4-
.packages
5+
.packages

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.5.0
2+
3+
* Fixes to support Dart 2.
4+
15
## 0.4.0+1
26

37
* Made a number of strong-mode improvements.

lib/common.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ class StreamFromPages<T> {
3636
bool _paused = false;
3737
bool _cancelled = false;
3838
Page _currentPage;
39-
StreamController _controller;
39+
StreamController<T> _controller;
4040

4141
StreamFromPages(this._firstPageProvider) {
42-
_controller = new StreamController(
42+
_controller = new StreamController<T>(
4343
sync: true,
4444
onListen: _onListen,
4545
onPause: _onPause,

lib/datastore.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class Key {
141141

142142
factory Key.fromParent(String kind, int id, {Key parent}) {
143143
var partition;
144-
var elements = [];
144+
var elements = <KeyElement>[];
145145
if (parent != null) {
146146
partition = parent.partition;
147147
elements.addAll(parent.elements);

lib/db.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import 'dart:core' as core;
1515
import 'dart:mirrors' as mirrors;
1616

1717
import 'common.dart' show StreamFromPages;
18-
import 'datastore.dart' as datastore;
18+
import 'datastore.dart' as ds;
1919
import 'service_scope.dart' as ss;
2020

2121
part 'src/db/annotations.dart';

lib/service_scope.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ void register(Object key, Object value, {onScopeExit()}) {
122122
///
123123
/// The registered on-scope-exit functions are executed in reverse registration
124124
/// order.
125-
Object registerScopeExitCallback(onScopeExitCallback()) {
125+
void registerScopeExitCallback(onScopeExitCallback()) {
126126
var serviceScope = _serviceScope;
127127
if (serviceScope == null) {
128128
throw new StateError('Not running inside a service scope zone.');
129129
}
130-
return serviceScope.registerOnScopeExitCallback(onScopeExitCallback);
130+
serviceScope.registerOnScopeExitCallback(onScopeExitCallback);
131131
}
132132

133133
/// Look up an item by it's key in the currently active service scope.

lib/src/datastore_impl.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ class DatastoreImpl implements datastore.Datastore {
162162
}
163163

164164
static datastore.Entity _convertApi2DatastoreEntity(api.Entity entity) {
165-
var unindexedProperties = new Set();
166-
var properties = {};
165+
var unindexedProperties = new Set<String>();
166+
var properties = <String, Object>{};
167167

168168
if (entity.properties != null) {
169169
entity.properties.forEach((String name, api.Value value) {
@@ -267,7 +267,7 @@ class DatastoreImpl implements datastore.Datastore {
267267
return orders.map(_convertDatastore2ApiOrder).toList();
268268
}
269269

270-
static Future _handleError(error, stack) {
270+
static Future<Null> _handleError(error, stack) {
271271
if (error is api.DetailedApiRequestError) {
272272
if (error.status == 400) {
273273
return new Future.error(
@@ -317,7 +317,7 @@ class DatastoreImpl implements datastore.Datastore {
317317
request.mode = 'NON_TRANSACTIONAL';
318318
}
319319

320-
var mutations = request.mutations = [];
320+
var mutations = request.mutations = <api.Mutation>[];
321321
if (inserts != null) {
322322
for (int i = 0; i < inserts.length; i++) {
323323
mutations.add(new api.Mutation()
@@ -349,7 +349,8 @@ class DatastoreImpl implements datastore.Datastore {
349349
keys = mutationResults
350350
.skip(autoIdStartIndex)
351351
.take(autoIdInserts.length)
352-
.map((api.MutationResult r) => _convertApi2DatastoreKey(r.key))
352+
.map<datastore.Key>(
353+
(api.MutationResult r) => _convertApi2DatastoreKey(r.key))
353354
.toList();
354355
}
355356
return new datastore.CommitResult(keys);
@@ -495,7 +496,7 @@ class QueryPageImpl implements Page<datastore.Entity> {
495496
request.query.limit = batchLimit;
496497

497498
return api.projects.runQuery(request, project).then((response) {
498-
var returnedEntities = const [];
499+
var returnedEntities = const <datastore.Entity>[];
499500

500501
var batch = response.batch;
501502
if (batch.entityResults != null) {

lib/src/db/annotations.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class ModelKeyProperty extends PrimitiveProperty {
179179

180180
Object decodePrimitiveValue(ModelDB db, Object value) {
181181
if (value == null) return null;
182-
return db.fromDatastoreKey(value as datastore.Key);
182+
return db.fromDatastoreKey(value as ds.Key);
183183
}
184184
}
185185

@@ -201,13 +201,13 @@ class BlobProperty extends PrimitiveProperty {
201201

202202
Object encodeValue(ModelDB db, Object value, {bool forComparison: false}) {
203203
if (value == null) return null;
204-
return new datastore.BlobValue(value);
204+
return new ds.BlobValue(value);
205205
}
206206

207207
Object decodePrimitiveValue(ModelDB db, Object value) {
208208
if (value == null) return null;
209209

210-
return (value as datastore.BlobValue).bytes;
210+
return (value as ds.BlobValue).bytes;
211211
}
212212
}
213213

@@ -298,4 +298,9 @@ class StringListProperty extends ListProperty {
298298
const StringListProperty({String propertyName, bool indexed: true})
299299
: super(const StringProperty(),
300300
propertyName: propertyName, indexed: indexed);
301+
302+
@override
303+
Object decodePrimitiveValue(ModelDB db, Object value) {
304+
return (super.decodePrimitiveValue(db, value) as core.List).cast<String>();
305+
}
301306
}

lib/src/db/db.dart

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Transaction {
2525
static const int _TRANSACTION_COMMITTED = 2;
2626

2727
final DatastoreDB db;
28-
final datastore.Transaction _datastoreTransaction;
28+
final ds.Transaction _datastoreTransaction;
2929

3030
final List<Model> _inserts = [];
3131
final List<Key> _deletes = [];
@@ -108,30 +108,30 @@ class Transaction {
108108
}
109109

110110
class Query {
111-
final _relationMapping = const <String, datastore.FilterRelation>{
112-
'<': datastore.FilterRelation.LessThan,
113-
'<=': datastore.FilterRelation.LessThanOrEqual,
114-
'>': datastore.FilterRelation.GreatherThan,
115-
'>=': datastore.FilterRelation.GreatherThanOrEqual,
116-
'=': datastore.FilterRelation.Equal,
111+
final _relationMapping = const <String, ds.FilterRelation>{
112+
'<': ds.FilterRelation.LessThan,
113+
'<=': ds.FilterRelation.LessThanOrEqual,
114+
'>': ds.FilterRelation.GreatherThan,
115+
'>=': ds.FilterRelation.GreatherThanOrEqual,
116+
'=': ds.FilterRelation.Equal,
117117
};
118118

119119
final DatastoreDB _db;
120-
final datastore.Transaction _transaction;
120+
final ds.Transaction _transaction;
121121
final String _kind;
122122

123123
final Partition _partition;
124124
final Key _ancestorKey;
125125

126-
final List<datastore.Filter> _filters = [];
127-
final List<datastore.Order> _orders = [];
126+
final List<ds.Filter> _filters = [];
127+
final List<ds.Order> _orders = [];
128128
int _offset;
129129
int _limit;
130130

131131
Query(DatastoreDB dbImpl, Type kind,
132132
{Partition partition,
133133
Key ancestorKey,
134-
datastore.Transaction datastoreTransaction})
134+
ds.Transaction datastoreTransaction})
135135
: _db = dbImpl,
136136
_kind = dbImpl.modelDB.kindName(kind),
137137
_partition = partition,
@@ -165,11 +165,11 @@ class Query {
165165
// This is for backwards compatibility: We allow [datastore.Key]s for now.
166166
// TODO: We should remove the condition in a major version update of
167167
// `package:gcloud`.
168-
if (comparisonObject is! datastore.Key) {
168+
if (comparisonObject is! ds.Key) {
169169
comparisonObject = _db.modelDB
170170
.toDatastoreValue(_kind, name, comparisonObject, forComparison: true);
171171
}
172-
_filters.add(new datastore.Filter(
172+
_filters.add(new ds.Filter(
173173
_relationMapping[comparison], propertyName, comparisonObject));
174174
}
175175

@@ -182,11 +182,11 @@ class Query {
182182
void order(String orderString) {
183183
// TODO: validate [orderString] (e.g. is name valid)
184184
if (orderString.startsWith('-')) {
185-
_orders.add(new datastore.Order(datastore.OrderDirection.Decending,
185+
_orders.add(new ds.Order(ds.OrderDirection.Decending,
186186
_convertToDatastoreName(orderString.substring(1))));
187187
} else {
188-
_orders.add(new datastore.Order(datastore.OrderDirection.Ascending,
189-
_convertToDatastoreName(orderString)));
188+
_orders.add(new ds.Order(
189+
ds.OrderDirection.Ascending, _convertToDatastoreName(orderString)));
190190
}
191191
}
192192

@@ -220,7 +220,7 @@ class Query {
220220
if (_ancestorKey != null) {
221221
ancestorKey = _db.modelDB.toDatastoreKey(_ancestorKey);
222222
}
223-
var query = new datastore.Query(
223+
var query = new ds.Query(
224224
ancestorKey: ancestorKey,
225225
kind: _kind,
226226
filters: _filters,
@@ -230,10 +230,10 @@ class Query {
230230

231231
var partition;
232232
if (_partition != null) {
233-
partition = new datastore.Partition(_partition.namespace);
233+
partition = new ds.Partition(_partition.namespace);
234234
}
235235

236-
return new StreamFromPages((int pageSize) {
236+
return new StreamFromPages<ds.Entity>((int pageSize) {
237237
return _db.datastore
238238
.query(query, transaction: _transaction, partition: partition);
239239
}).stream.map(_db.modelDB.fromDatastoreEntity);
@@ -254,7 +254,7 @@ class Query {
254254
}
255255

256256
class DatastoreDB {
257-
final datastore.Datastore datastore;
257+
final ds.Datastore datastore;
258258
final ModelDB _modelDB;
259259
Partition _defaultPartition;
260260

@@ -356,13 +356,13 @@ class DatastoreDB {
356356
Future _commitHelper(DatastoreDB db,
357357
{List<Model> inserts,
358358
List<Key> deletes,
359-
datastore.Transaction datastoreTransaction}) {
359+
ds.Transaction datastoreTransaction}) {
360360
var entityInserts, entityAutoIdInserts, entityDeletes;
361361
var autoIdModelInserts;
362362
if (inserts != null) {
363-
entityInserts = [];
364-
entityAutoIdInserts = [];
365-
autoIdModelInserts = [];
363+
entityInserts = <ds.Entity>[];
364+
entityAutoIdInserts = <ds.Entity>[];
365+
autoIdModelInserts = <Model>[];
366366

367367
for (var model in inserts) {
368368
// If parent was not explicitly set, we assume this model will map to
@@ -388,7 +388,7 @@ Future _commitHelper(DatastoreDB db,
388388
autoIdInserts: entityAutoIdInserts,
389389
deletes: entityDeletes,
390390
transaction: datastoreTransaction)
391-
.then((datastore.CommitResult result) {
391+
.then((ds.CommitResult result) {
392392
if (entityAutoIdInserts != null && entityAutoIdInserts.length > 0) {
393393
for (var i = 0; i < result.autoIdInsertKeys.length; i++) {
394394
var key = db.modelDB.fromDatastoreKey(result.autoIdInsertKeys[i]);
@@ -400,11 +400,11 @@ Future _commitHelper(DatastoreDB db,
400400
}
401401

402402
Future<List<Model>> _lookupHelper(DatastoreDB db, List<Key> keys,
403-
{datastore.Transaction datastoreTransaction}) {
403+
{ds.Transaction datastoreTransaction}) {
404404
var entityKeys = keys.map(db.modelDB.toDatastoreKey).toList();
405405
return db.datastore
406406
.lookup(entityKeys, transaction: datastoreTransaction)
407-
.then((List<datastore.Entity> entities) {
407+
.then((List<ds.Entity> entities) {
408408
return entities.map(db.modelDB.fromDatastoreEntity).toList();
409409
});
410410
}

lib/src/db/model_db.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@ part of gcloud.db;
1111
*/
1212
abstract class ModelDB {
1313
/**
14-
* Converts a [datastore.Key] to a [Key].
14+
* Converts a [ds.Key] to a [Key].
1515
*/
16-
Key fromDatastoreKey(datastore.Key datastoreKey);
16+
Key fromDatastoreKey(ds.Key datastoreKey);
1717

1818
/**
19-
* Converts a [Key] to a [datastore.Key].
19+
* Converts a [Key] to a [ds.Key].
2020
*/
21-
datastore.Key toDatastoreKey(Key dbKey);
21+
ds.Key toDatastoreKey(Key dbKey);
2222

2323
/**
24-
* Converts a [Model] instance to a [datastore.Entity].
24+
* Converts a [Model] instance to a [ds.Entity].
2525
*/
26-
datastore.Entity toDatastoreEntity(Model model);
26+
ds.Entity toDatastoreEntity(Model model);
2727

2828
/**
29-
* Converts a [datastore.Entity] to a [Model] instance.
29+
* Converts a [ds.Entity] to a [Model] instance.
3030
*/
31-
Model fromDatastoreEntity(datastore.Entity entity);
31+
Model fromDatastoreEntity(ds.Entity entity);
3232

3333
/**
3434
* Returns the kind name for instances of [type].

0 commit comments

Comments
 (0)