Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.7.5 #90

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 1.7.5

- New `IterableEntityReferenceExtension` and `IterableEntityReferenceListExtension`.

- `EntityReference`: added `idAsInt` and `idNotNullAsInt`.
- `EntityReferenceList`: added `idsAsInt` and `idsNotNullAsInt`.

## 1.7.4

- `TimedMap`:
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.4';
static const String VERSION = '1.7.5';

static bool _boot = false;

Expand Down
52 changes: 52 additions & 0 deletions lib/src/bones_api_entity_reference.dart
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,17 @@
/// See [idAs].
I idNotNullAs<I>() => id as I;

/// Returns [id] as [int] or null.
/// See [idNotNullAs].
int? get idAsInt {
var id = this.id;
return id is int ? id : null;

Check warning on line 711 in lib/src/bones_api_entity_reference.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_api_entity_reference.dart#L709-L711

Added lines #L709 - L711 were not covered by tests
}

/// Returns [id] as [int].
/// See [idAsInt].
int get idNotNullAsInt => id as int;

Check warning on line 716 in lib/src/bones_api_entity_reference.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_api_entity_reference.dart#L716

Added line #L716 was not covered by tests

Object? _resolveID() {
var id = _id;
if (id != null) return id;
Expand Down Expand Up @@ -1649,6 +1660,15 @@
/// See [idsAs].
List<I> idsNotNullAs<I>() => ids?.whereType<I>().toList() ?? [];

/// Returns the [ids] with type [int] or null.
/// See [idsNotNullAs].
List<int?> get idsAsInt =>
ids?.map((e) => e is int ? e : null).toList() ?? [];

Check warning on line 1666 in lib/src/bones_api_entity_reference.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_api_entity_reference.dart#L1665-L1666

Added lines #L1665 - L1666 were not covered by tests

/// Returns the [ids] with type [int].
/// See [idsAsInt].
List<int> get idsNotNullAsInt => ids?.whereType<int>().toList() ?? [];

Check warning on line 1670 in lib/src/bones_api_entity_reference.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_api_entity_reference.dart#L1670

Added line #L1670 was not covered by tests

List<Object?>? _resolveIDs() {
var ids = _ids;
if (ids != null) return ids;
Expand Down Expand Up @@ -2356,6 +2376,38 @@
FutureOr<List<T?>?> getNotNull() => this?.getNotNull();
}

extension IterableEntityReferenceExtension<T> on Iterable<EntityReference<T>> {
List<Object> get allIDs => map((e) => e.id).whereNotNull().toList();

Check warning on line 2380 in lib/src/bones_api_entity_reference.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_api_entity_reference.dart#L2380

Added line #L2380 was not covered by tests

List<I> allIDsAs<I>() => map((e) => e.idAs<I>()).whereType<I>().toList();

Check warning on line 2382 in lib/src/bones_api_entity_reference.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_api_entity_reference.dart#L2382

Added line #L2382 was not covered by tests

List<int> get allIDsAsInt => map((e) => e.idNotNullAsInt).toList();

Check warning on line 2384 in lib/src/bones_api_entity_reference.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_api_entity_reference.dart#L2384

Added line #L2384 was not covered by tests

List<T> get allEntities => map((e) => e.entity).whereType<T>().toList();

Check warning on line 2386 in lib/src/bones_api_entity_reference.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_api_entity_reference.dart#L2386

Added line #L2386 was not covered by tests
}

extension IterableEntityReferenceListExtension<T>
on Iterable<EntityReferenceList<T>> {
List<Object> get allIDs => expand((e) => e.ids ?? []).whereNotNull().toList();

Check warning on line 2391 in lib/src/bones_api_entity_reference.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_api_entity_reference.dart#L2391

Added line #L2391 was not covered by tests

List<I> allIDsAs<I>() => expand((e) => e.idsAs<I>()).whereType<I>().toList();

Check warning on line 2393 in lib/src/bones_api_entity_reference.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_api_entity_reference.dart#L2393

Added line #L2393 was not covered by tests

List<int> get allIDsAsInt => expand((e) => e.idsNotNullAsInt).toList();

Check warning on line 2395 in lib/src/bones_api_entity_reference.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_api_entity_reference.dart#L2395

Added line #L2395 was not covered by tests

List<T> get allEntities => expand((e) => e.entitiesNotNull).toList();

Check warning on line 2397 in lib/src/bones_api_entity_reference.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_api_entity_reference.dart#L2397

Added line #L2397 was not covered by tests
}

extension IterableOfIterableEntityReferenceListExtension<T>
on Iterable<Iterable<EntityReferenceList<T>>> {
List<Object> get allIDs => expand((e) => e.allIDs).toList();

Check warning on line 2402 in lib/src/bones_api_entity_reference.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_api_entity_reference.dart#L2402

Added line #L2402 was not covered by tests

List<I> allIDsAs<I>() => expand((e) => e.allIDsAs<I>()).toList();

Check warning on line 2404 in lib/src/bones_api_entity_reference.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_api_entity_reference.dart#L2404

Added line #L2404 was not covered by tests

List<int> get allIDsAsInt => expand((e) => e.allIDsAsInt).toList();

Check warning on line 2406 in lib/src/bones_api_entity_reference.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_api_entity_reference.dart#L2406

Added line #L2406 was not covered by tests

List<T> get allEntities => expand((e) => e.allEntities).toList();

Check warning on line 2408 in lib/src/bones_api_entity_reference.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_api_entity_reference.dart#L2408

Added line #L2408 was not covered by tests
}

extension _ListExtension<T> on List<T> {
List<T> mergeWith(List<T> other) => List<T>.generate(length, (i) {
T a = this[i];
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: bones_api
description: Bones_API - A powerful API backend framework for Dart. It comes with a built-in HTTP Server, route handler, entity handler, SQL translator, and DB adapters.
version: 1.7.4
version: 1.7.5
homepage: https://github.com/Colossus-Services/bones_api

environment:
Expand Down
Loading