Skip to content

Commit

Permalink
Merge v1.7.7 - _resolveValueAsUInt8List: handle prefixes hex: and `…
Browse files Browse the repository at this point in the history
…base64:`

 - `EntityHandler`:
   - `_resolveValueAsUInt8List`: handle `hex:` and `base64:` prefixed data.

- Change whereNotNull() to nonNulls.
  • Loading branch information
gmpassos authored Jun 23, 2024
2 parents f61c046 + 975abcf commit 2b755f7
Show file tree
Hide file tree
Showing 26 changed files with 109 additions and 99 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.7.7

- `EntityHandler`:
- `_resolveValueAsUInt8List`: handle `hex:` and `base64:` prefixed data.

## 1.7.6

- `EntityHandler`:
Expand Down
2 changes: 1 addition & 1 deletion lib/src/bones_api_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ typedef APILogger = void Function(APIRoot apiRoot, String type, String? message,
/// Bones API Library class.
class BonesAPI {
// ignore: constant_identifier_names
static const String VERSION = '1.7.6';
static const String VERSION = '1.7.7';

static bool _boot = false;

Expand Down
3 changes: 1 addition & 2 deletions lib/src/bones_api_condition.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:collection/collection.dart';
import 'package:reflection_factory/reflection_factory.dart';

import 'bones_api_condition_parser.dart';
Expand Down Expand Up @@ -936,7 +935,7 @@ class ConditionIdIN<O> extends Condition<O> {
var idsValues = this.idsValues;

var params =
idsValues.map((e) => e is ConditionParameter ? e : null).whereNotNull();
idsValues.map((e) => e is ConditionParameter ? e : null).nonNulls;
_setParameters(params);

_markResolved();
Expand Down
2 changes: 1 addition & 1 deletion lib/src/bones_api_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class APIConfig {
var val2 = _parseValue<E>(val);
if (val2 != null) return val2;

var keyPath = [k0, k1, k2, k3, k4].whereNotNull().join('/');
var keyPath = [k0, k1, k2, k3, k4].nonNulls.join('/');
throw StateError("Can't return key `$keyPath` as `$E`: $val");
}

Expand Down
40 changes: 28 additions & 12 deletions lib/src/bones_api_entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,22 @@ abstract class EntityHandler<O> with FieldsFromMap, EntityRulesResolver {
} else if (value.startsWith("data:")) {
var dataURL = DataURLBase64.parse(value);
return dataURL?.payloadArrayBuffer;
} else if (value.startsWith("hex:")) {
var hexData = value.substring(4);
try {
var data = hex.decode(hexData);
return data;
} catch (_) {
// Not a HEX data:
}
} else if (value.startsWith("base64:")) {
var base64Data = value.substring(7);
try {
var data = dart_convert.base64.decode(base64Data);
return data;
} catch (_) {
// Not a Base64 data:
}
} else if (value.startsWith("url(") && value.endsWith(")")) {
var allowReadFile = resolutionRulesResolved.allowReadFile;
if (!allowReadFile) return null;
Expand Down Expand Up @@ -1317,7 +1333,7 @@ abstract class EntityHandler<O> with FieldsFromMap, EntityRulesResolver {

return MapEntry(field, typeInfo);
})
.whereNotNull()
.nonNulls
.toMapFromEntries();

return UnmodifiableMapView(_fieldsEntityTypes = entityFields);
Expand All @@ -1331,7 +1347,7 @@ abstract class EntityHandler<O> with FieldsFromMap, EntityRulesResolver {
var entries = fieldsNames.map((f) {
var annotations = getFieldEntityAnnotations(o, f);
return annotations == null ? null : MapEntry(f, annotations);
}).whereNotNull();
}).nonNulls;

var map = Map<String, List<EntityAnnotation>>.fromEntries(entries);

Expand Down Expand Up @@ -2601,7 +2617,7 @@ class ClassReflectionEntityHandler<O> extends EntityHandler<O> {
});

_fieldsTypes = UnmodifiableMapView<String, TypeInfo>(
Map<String, TypeInfo>.fromEntries(types.whereNotNull()));
Map<String, TypeInfo>.fromEntries(types.nonNulls));
}
return _fieldsTypes!;
}
Expand Down Expand Up @@ -3058,12 +3074,12 @@ abstract class EntityStorage<O extends Object> extends EntityAccessor<O> {
var fieldValues = entityHandler.getField(o, e.key);
if (fieldValues == null ||
fieldValues is! Iterable ||
fieldValues.whereNotNull().isEmpty) continue;
fieldValues.nonNulls.isEmpty) continue;

EntityRepository<Object>? tEntityRepository;
EntityHandler<Object>? tEntityHandler;

for (var e in fieldValues.whereNotNull()) {
for (var e in fieldValues.nonNulls) {
tEntityRepository ??= _resolveRepositoryProvider(
entityHandler, entityRepository, repositoryProvider,
obj: e, type: tType);
Expand Down Expand Up @@ -3435,7 +3451,7 @@ extension IterableEntityRepositoryProviderExtension

var entityRepositories = notClosed
.map((e) => e.getEntityRepository<T>(obj: obj, type: type, name: name))
.whereNotNull()
.nonNulls
.toList(growable: false);

return _resolveEntityRepository<T>(entityRepositories, type,
Expand Down Expand Up @@ -3499,7 +3515,7 @@ extension IterableEntityRepositoryProviderExtension

var entityRepositories = notClosed
.map((e) => e.getEntityRepositoryByType<T>(type))
.whereNotNull()
.nonNulls
.toList();

return _resolveEntityRepository<T>(entityRepositories, type,
Expand Down Expand Up @@ -4191,7 +4207,7 @@ abstract class EntityRepository<O extends Object> extends EntityAccessor<O>
var entities = _entitiesTracker.trackInstancesNullable(os);

if (stored) {
notifyStoredEntities(entities.whereNotNull());
notifyStoredEntities(entities.nonNulls);
}

return entities;
Expand All @@ -4201,7 +4217,7 @@ abstract class EntityRepository<O extends Object> extends EntityAccessor<O>
_entitiesTracker.untrackInstances(os);

if (deleted) {
notifyDeletedEntities(os.whereNotNull());
notifyDeletedEntities(os.nonNulls);
}
}

Expand Down Expand Up @@ -6062,7 +6078,7 @@ abstract class IterableEntityRepository<O extends Object>
var oId = getID(o, entityHandler: entityHandler);
var matches = ids.contains(oId);
return matches ? oId as I : null;
}).whereNotNull();
}).nonNulls;

return osIDs;
}
Expand Down Expand Up @@ -6103,7 +6119,7 @@ abstract class IterableEntityRepository<O extends Object>

var ids = entityHandler.getIDs<I>(os);

return ids.whereNotNull().toList();
return ids.nonNulls.toList();
}

@override
Expand Down Expand Up @@ -6233,7 +6249,7 @@ abstract class IterableEntityRepository<O extends Object>
var oId = getID(o, entityHandler: entityHandler);
var valuesIds = values.map((e) => valuesEntityHandler.getID(e));

var valuesIdsNotNull = IterableNullableExtension(valuesIds).whereNotNull();
var valuesIdsNotNull = valuesIds.nonNulls;

return putRelationship(oId, valuesType, valuesIdsNotNull)
.resolveMapped((ok) {
Expand Down
7 changes: 3 additions & 4 deletions lib/src/bones_api_entity_annotation.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:collection/collection.dart';
import 'package:meta/meta_meta.dart';
import 'package:statistics/statistics.dart';

Expand Down Expand Up @@ -184,11 +183,11 @@ extension IterableEntityAnnotationExtension on Iterable<EntityAnnotation> {
}

extension IterableEntityFieldExtension on Iterable<EntityField> {
List<num> get maximum => map((e) => e.maximum).whereNotNull().toList();
List<num> get maximum => map((e) => e.maximum).nonNulls.toList();

List<num> get minimum => map((e) => e.minimum).whereNotNull().toList();
List<num> get minimum => map((e) => e.minimum).nonNulls.toList();

List<String> get regexp => map((e) => e.regexp).whereNotNull().toList();
List<String> get regexp => map((e) => e.regexp).nonNulls.toList();

List<EntityField> get unique => where((e) => e.isUnique).toList();

Expand Down
27 changes: 12 additions & 15 deletions lib/src/bones_api_entity_db.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ class DBAdapterRegister<C extends Object, A extends DBAdapter<C>> {
conf.map((key, value) => MapEntry<String, dynamic>(
key.toString(), value as dynamic)));
})
.whereNotNull()
.nonNulls
.toList()
..sort((a, b) => a.value.length.compareTo(b.value.length));
}
Expand Down Expand Up @@ -1230,7 +1230,7 @@ class DBEntityRepository<O extends Object> extends EntityRepository<O>
@override
FutureOr<Iterable<I>> existIDs<I extends Object>(List<I?> ids,
{Transaction? transaction}) {
var idsNotNull = ids is List<I> ? ids : ids.whereNotNull().toList();
var idsNotNull = ids is List<I> ? ids : ids.nonNulls.toList();
if (idsNotNull.isEmpty) return <I>[];

var cachedEntityByIDs =
Expand Down Expand Up @@ -1448,7 +1448,7 @@ class DBEntityRepository<O extends Object> extends EntityRepository<O>
ConditionIdIN matcher,
Object? parameters,
EntityResolutionRules? resolutionRules) {
var ids = matcher.idsValues.whereNotNull().toList();
var ids = matcher.idsValues.nonNulls.toList();
if (ids.isEmpty) return <O>[];

final resolutionRulesResolved =
Expand Down Expand Up @@ -1565,7 +1565,7 @@ class DBEntityRepository<O extends Object> extends EntityRepository<O>

Iterable<Map<String, dynamic>> entries;
if (results is! Iterable<Map<String, dynamic>>) {
entries = results.whereNotNull();
entries = results.nonNulls;
} else {
entries = results;
}
Expand Down Expand Up @@ -1671,7 +1671,7 @@ class DBEntityRepository<O extends Object> extends EntityRepository<O>
var tableColumn = fieldsColumns[field]!;

var ids = resultsList.map((e) => e[tableColumn]).toList();
var idsUniques = ids.whereNotNull().toSet().toList();
var idsUniques = ids.nonNulls.toSet().toList();

var entities = repo
.selectByIDs(idsUniques,
Expand Down Expand Up @@ -1744,7 +1744,7 @@ class DBEntityRepository<O extends Object> extends EntityRepository<O>
var repo = _resolveEntityRepository(e.value);
return repo != null ? MapEntry(e.key, repo) : null;
})
.whereNotNull()
.nonNulls
.toMapFromEntries();

Map<String, EntityRepository<Object>> _resolveFieldsEntityRepositories(
Expand All @@ -1763,7 +1763,7 @@ class DBEntityRepository<O extends Object> extends EntityRepository<O>
}
return e;
})
.whereNotNull()
.nonNulls
.toMapFromEntries();
}

Expand Down Expand Up @@ -1845,15 +1845,12 @@ class DBEntityRepository<O extends Object> extends EntityRepository<O>

// ignore: discarded_futures
return targetsAsync.resolveMapped((targets) {
var allTargetsById = Map.fromEntries(targets
.whereNotNull()
var allTargetsById = Map.fromEntries(targets.nonNulls
.map((e) => MapEntry(targetEntityRepository.getEntityID(e)!, e)));

var relationshipsEntities = relationships.map((id, targetIds) {
var targetEntities = targetIds
.map((id) => allTargetsById[id])
.whereNotNull()
.toList();
var targetEntities =
targetIds.map((id) => allTargetsById[id]).nonNulls.toList();

var targetEntitiesCast =
targetEntityHandler.castList(targetEntities, targetType)!;
Expand Down Expand Up @@ -1938,7 +1935,7 @@ class DBEntityRepository<O extends Object> extends EntityRepository<O>
if (relationship == null) return null;

return MapEntry(e.key, relationship);
}).whereNotNull();
}).nonNulls;

var relationshipFields =
Map<String, TableRelationshipReference>.fromEntries(entries);
Expand Down Expand Up @@ -2257,7 +2254,7 @@ class DBAdapterException implements DBException, WithRuntimeTypeNameSafe {
if (o == null) {
return null;
} else if (o is Iterable) {
return '$indent${o.map(resolveToString).whereNotNull().join('\n$indent')}';
return '$indent${o.map(resolveToString).nonNulls.join('\n$indent')}';
} else if (o is TransactionOperation) {
return o.toString();
} else if (o is Function()) {
Expand Down
6 changes: 3 additions & 3 deletions lib/src/bones_api_entity_db_memory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ class DBSQLMemoryAdapter extends DBSQLAdapter<DBSQLMemoryAdapterContext>

return match ? MapEntry(e.key, obj) : null;
})
.whereNotNull()
.nonNulls
.toList(growable: false);

_checkNotReferencedEntities(entries, table, sql);
Expand Down Expand Up @@ -1004,7 +1004,7 @@ class DBSQLMemoryAdapter extends DBSQLAdapter<DBSQLMemoryAdapterContext>

var targetIds = relWithID
.map((relId) => relMap[relId]?[targetRelationshipField])
.whereNotNull()
.nonNulls
.toList();

if (targetIds.isEmpty) {
Expand All @@ -1025,7 +1025,7 @@ class DBSQLMemoryAdapter extends DBSQLAdapter<DBSQLMemoryAdapterContext>
? null
: _resolveEntityMap(e, entityHandler2, tableScheme2);
})
.whereNotNull()
.nonNulls
.toList();
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/bones_api_entity_db_mysql.dart
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ class DBMySQLAdapter extends DBSQLAdapter<DBMySqlConnectionWrapper>
otherRef.sourceField,
);
})
.whereNotNull()
.nonNulls
.toList();

return relationships;
Expand Down Expand Up @@ -587,7 +587,7 @@ class DBMySQLAdapter extends DBSQLAdapter<DBMySqlConnectionWrapper>
sourceField, reference);
});
})
.whereNotNull()
.nonNulls
.resolveAll();

return mapEntriesRet.resolveMapped((mapEntries) {
Expand Down
3 changes: 1 addition & 2 deletions lib/src/bones_api_entity_db_object_gcs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:io';
import 'dart:typed_data';

import 'package:async_extension/async_extension.dart';
import 'package:collection/collection.dart' hide IterableIntegerExtension;
import 'package:crclib/catalog.dart';
import 'package:crclib/crclib.dart';
import 'package:gcloud/storage.dart' as gcs;
Expand Down Expand Up @@ -460,7 +459,7 @@ class DBObjectGCSAdapter extends DBObjectAdapter<DBObjectGCSAdapterContext> {

var objInfo = await _getObjectInfo(objFile);
return objInfo != null && objInfo.length > 0 ? id : null;
}).resolveMapped((ids) => ids.whereNotNull().toList());
}).resolveMapped((ids) => ids.nonNulls.toList());
}

@override
Expand Down
3 changes: 1 addition & 2 deletions lib/src/bones_api_entity_db_object_memory.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:collection';

import 'package:async_extension/async_extension.dart';
import 'package:collection/collection.dart';
import 'package:logging/logging.dart' as logging;
import 'package:map_history/map_history.dart';
import 'package:reflection_factory/reflection_factory.dart';
Expand Down Expand Up @@ -497,7 +496,7 @@ class DBObjectMemoryAdapter

return entry;
})
.whereNotNull()
.nonNulls
.toList();

return entries;
Expand Down
Loading

0 comments on commit 2b755f7

Please sign in to comment.