Skip to content

Commit

Permalink
Merge v1.6.5
Browse files Browse the repository at this point in the history
v1.6.5

 - `EntityAccessRules`:
   - Fix `toJsonEncodable` to allow rules to be applied to sub-entities. 

 - `APIResponse` extension on `Future` and `FutureOr`:
   - Added `payloadAsyncOr`.

 - `LoggerHandler`:
   - `flushMessages`: added parameter `delay`.

 - async_extension: ^1.2.7
 - reflection_factory: ^2.3.1
 - postgres: ^2.6.4
 - googleapis_auth: ^1.5.0
  • Loading branch information
gmpassos authored Mar 3, 2024
2 parents 91b3db9 + 4fb71a9 commit 2f4abfc
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 23 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
## 1.6.5

- `EntityAccessRules`:
- Fix `toJsonEncodable` to allow rules to be applied to sub-entities.

- `APIResponse` extension on `Future` and `FutureOr`:
- Added `payloadAsyncOr`.

- `LoggerHandler`:
- `flushMessages`: added parameter `delay`.

- async_extension: ^1.2.7
- reflection_factory: ^2.3.1
- postgres: ^2.6.4
- googleapis_auth: ^1.5.0

## 1.6.4

- `EntityReference`:
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.6.4';
static const String VERSION = '1.6.5';

static bool _boot = false;

Expand Down
10 changes: 8 additions & 2 deletions lib/src/bones_api_entity_rules.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'bones_api_base.dart';
import 'bones_api_entity_reference.dart';
import 'bones_api_extension.dart';
import 'bones_api_types.dart';
import 'bones_api_utils_json.dart';

abstract class EntityRules<R extends EntityRules<R>> {
final bool? _innocuous;
Expand Down Expand Up @@ -463,7 +462,14 @@ class EntityAccessRules extends EntityRules<EntityAccessRules> {

Object? map;
if (enc == null) {
map = Json.toJson(o, toEncodable: ReflectionFactory.toJsonEncodable);
var classReflection =
ReflectionFactory().getRegisterClassReflection(o.runtimeType);

if (classReflection != null) {
map = classReflection.toMapFromFields(o);
} else {
map = j.toJson(o, autoResetEntityCache: false);
}
} else {
map = enc(o, j);
}
Expand Down
4 changes: 4 additions & 0 deletions lib/src/bones_api_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,8 @@ extension ListOfStringExtension on List<String> {
extension FutureOrAPIResponseExtension<T> on FutureOr<APIResponse<T>> {
FutureOr<T?> get payloadAsync => then((r) => r.payload);

FutureOr<T?> payloadAsyncOr(T? def) => then((r) => r.payload ?? def);

FutureOr<APIResponseStatus> get statusAsync => then((r) => r.status);

FutureOr<Map<String, dynamic>> get headersAsync => then((r) => r.headers);
Expand All @@ -1037,6 +1039,8 @@ extension FutureOrAPIResponseExtension<T> on FutureOr<APIResponse<T>> {
extension FutureAPIResponseExtension<T> on Future<APIResponse<T>> {
Future<T?> get payloadAsync => then((r) => r.payload);

Future<T?> payloadAsyncOr(T? def) => then((r) => r.payload ?? def);

Future<APIResponseStatus> get statusAsync => then((r) => r.status);

Future<Map<String, dynamic>> get headersAsync => then((r) => r.headers);
Expand Down
7 changes: 5 additions & 2 deletions lib/src/bones_api_logging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ extension LoggerExntesion on logging.Logger {
return handler;
}

FutureOr<bool> flushMessages() => handler.flushMessages();
FutureOr<bool> flushMessages(
{Duration? delay = const Duration(milliseconds: 20)}) =>
handler.flushMessages(delay: delay);

static final Set<logging.Logger> _dbLoggers = {};

Expand Down Expand Up @@ -313,7 +315,8 @@ abstract class LoggerHandler {

void printMessage(logging.Level level, String message);

FutureOr<bool> flushMessages();
FutureOr<bool> flushMessages(
{Duration? delay = const Duration(milliseconds: 20)});

void logAll() {
logging.hierarchicalLoggingEnabled = true;
Expand Down
3 changes: 2 additions & 1 deletion lib/src/bones_api_logging_generic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class LoggerHandlerGeneric extends LoggerHandler {
}

@override
bool flushMessages() => false;
bool flushMessages({Duration? delay = const Duration(milliseconds: 20)}) =>
false;
}

LoggerHandler createLoggerHandler(Logger logger) {
Expand Down
16 changes: 13 additions & 3 deletions lib/src/bones_api_logging_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,19 @@ class LoggerHandlerIO extends LoggerHandler {
}

@override
FutureOr<bool> flushMessages() {
if (_printMessageQueue.isEmpty) return false;
return _scheduleFlushPrintMessageQueue();
FutureOr<bool> flushMessages(
{Duration? delay = const Duration(milliseconds: 20)}) {
if (_printMessageQueue.isEmpty) {
if (delay == null) return false;

return Future.delayed(delay).then((_) {
if (_printMessageQueue.isEmpty) return false;
return _scheduleFlushPrintMessageQueue();
});
}

return _scheduleFlushPrintMessageQueue(
delay: delay ?? Duration(milliseconds: 20));
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/src/bones_api_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ class APIServer extends _APIServerBase {
}
}

await _log.flushMessages();
await _log.flushMessages(delay: Duration(milliseconds: 50));

return true;
}
Expand Down
10 changes: 5 additions & 5 deletions 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.6.4
version: 1.6.5
homepage: https://github.com/Colossus-Services/bones_api

environment:
Expand All @@ -10,9 +10,9 @@ executables:
bones_api:

dependencies:
async_extension: ^1.2.5
async_extension: ^1.2.7
async_events: ^1.1.0
reflection_factory: ^2.3.0
reflection_factory: ^2.3.1
statistics: ^1.1.0
swiss_knife: ^3.2.0
data_serializer: ^1.1.0
Expand All @@ -38,7 +38,7 @@ dependencies:
logging: ^1.2.0
collection: ^1.18.0
mime: ^1.0.5
postgres: ^2.6.3
postgres: ^2.6.4
mysql1: ^0.20.0
gcloud: ^0.8.12
yaml: ^3.1.2
Expand All @@ -47,7 +47,7 @@ dependencies:
archive: ^3.4.10
stream_channel: ^2.1.2
http: ^1.2.1
googleapis_auth: ^1.4.1
googleapis_auth: ^1.5.0
crclib: ^3.0.0

dev_dependencies:
Expand Down
4 changes: 2 additions & 2 deletions test/bones_api_test.reflection.g.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// GENERATED CODE - DO NOT MODIFY BY HAND!
// BUILDER: reflection_factory/2.3.0
// BUILDER: reflection_factory/2.3.1
// BUILD COMMAND: dart run build_runner build
//

Expand All @@ -20,7 +20,7 @@ typedef __TI<T> = TypeInfo<T>;
typedef __PR = ParameterReflection;

mixin __ReflectionMixin {
static final Version _version = Version.parse('2.3.0');
static final Version _version = Version.parse('2.3.1');

Version get reflectionFactoryVersion => _version;

Expand Down
4 changes: 2 additions & 2 deletions test/bones_api_test_entities.reflection.g.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// GENERATED CODE - DO NOT MODIFY BY HAND!
// BUILDER: reflection_factory/2.3.0
// BUILDER: reflection_factory/2.3.1
// BUILD COMMAND: dart run build_runner build
//

Expand All @@ -20,7 +20,7 @@ typedef __TI<T> = TypeInfo<T>;
typedef __PR = ParameterReflection;

mixin __ReflectionMixin {
static final Version _version = Version.parse('2.3.0');
static final Version _version = Version.parse('2.3.1');

Version get reflectionFactoryVersion => _version;

Expand Down
4 changes: 2 additions & 2 deletions test/bones_api_test_modules.reflection.g.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// GENERATED CODE - DO NOT MODIFY BY HAND!
// BUILDER: reflection_factory/2.3.0
// BUILDER: reflection_factory/2.3.1
// BUILD COMMAND: dart run build_runner build
//

Expand All @@ -20,7 +20,7 @@ typedef __TI<T> = TypeInfo<T>;
typedef __PR = ParameterReflection;

mixin __ReflectionMixin {
static final Version _version = Version.parse('2.3.0');
static final Version _version = Version.parse('2.3.1');

Version get reflectionFactoryVersion => _version;

Expand Down
4 changes: 2 additions & 2 deletions test/bones_api_test_utils_test.reflection.g.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// GENERATED CODE - DO NOT MODIFY BY HAND!
// BUILDER: reflection_factory/2.3.0
// BUILDER: reflection_factory/2.3.1
// BUILD COMMAND: dart run build_runner build
//

Expand All @@ -20,7 +20,7 @@ typedef __TI<T> = TypeInfo<T>;
typedef __PR = ParameterReflection;

mixin __ReflectionMixin {
static final Version _version = Version.parse('2.3.0');
static final Version _version = Version.parse('2.3.1');

Version get reflectionFactoryVersion => _version;

Expand Down

0 comments on commit 2f4abfc

Please sign in to comment.