Skip to content
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
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
## 1.9.0

- `APIPlatformBrowser`:
- Change use of `dart:html` (deprecated) to package `web`.

- `Json`:
- `defaultFieldValueResolver`: optimize primitives parsing (String, bool, int, double, num) .
- Added `dumpRuntimeTypes`.

- sdk: '>=3.6.0 <4.0.0'

- reflection_factory: ^2.5.0
- statistics: ^1.2.0
- swiss_knife: ^3.3.0
- yaml_writer: ^2.1.0
- mercury_client: ^2.3.0
- resource_portable: ^3.1.2
- collection: ^1.19.0
- web: ^1.1.0

## 1.8.7

- reflection_factory: ^2.4.10
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.8.7';
static const String VERSION = '1.9.0';

static bool _boot = false;

Expand Down
5 changes: 4 additions & 1 deletion lib/src/bones_api_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,10 @@ abstract class APIModuleProxyCallerListener<T>
var mainType =
typeInfo.isFuture ? (typeInfo.arguments0 ?? typeInfo) : typeInfo;

//var debugJsonPretty = Json.encode(json, pretty: true);
// var debugJsonPretty = Json.encode(json, pretty: true);
// print(debugJsonPretty);

// print(Json.dumpRuntimeTypes(json));

var jsonDecoder = Json.decoder(
entityHandlerProvider: EntityHandlerProvider.globalProvider);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/bones_api_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import 'dart:typed_data';
import 'package:args_simple/args_simple.dart';

import 'bones_api_platform_generic.dart'
if (dart.library.html) 'bones_api_platform_browser.dart'
if (dart.library.io) 'bones_api_platform_io.dart';
if (dart.library.io) 'bones_api_platform_io.dart'
if (dart.library.js_interop) 'bones_api_platform_browser.dart';

enum APIPlatformType {
generic,
Expand Down
13 changes: 7 additions & 6 deletions lib/src/bones_api_platform_browser.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'dart:async';
// ignore: deprecated_member_use
import 'dart:html';
import 'dart:js_interop';

import 'dart:typed_data';

import 'package:mercury_client/mercury_client.dart';
import 'package:swiss_knife/swiss_knife.dart';
import 'package:web/web.dart' as web;

import 'bones_api_extension.dart';
import 'bones_api_platform.dart';
Expand Down Expand Up @@ -65,13 +66,13 @@ class APIPlatformBrowser extends APIPlatform {
void stdout(Object? o) => stdoutLn(o);

@override
void stdoutLn(Object? o) => window.console.log(o);
void stdoutLn(Object? o) => web.console.log(o?.jsify());

@override
void stderr(Object? o) => stderrLn(o);

@override
void stderrLn(Object? o) => window.console.error(o);
void stderrLn(Object? o) => web.console.error(o?.jsify());

static final RegExp _regExpUriStart = RegExp(r'^\w+:/');

Expand Down Expand Up @@ -131,7 +132,7 @@ class APIPlatformBrowser extends APIPlatform {

@override
Iterable<String> get propertiesKeys {
var location = window.location.href.trim();
var location = web.window.location.href.trim();
var uri = location.isNotEmpty ? Uri.tryParse(location) : null;

return {..._properties.keys, ...?uri?.queryParameters.keys};
Expand All @@ -152,7 +153,7 @@ class APIPlatformBrowser extends APIPlatform {
var prev = _properties[key];
if (prev != null) return prev;

var location = window.location.href.trim();
var location = web.window.location.href.trim();
if (location.isEmpty) return defaultValue;

var uri = Uri.tryParse(location);
Expand Down
28 changes: 28 additions & 0 deletions lib/src/bones_api_utils_json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,16 @@
return null;
} else if (type.type == value.runtimeType) {
return value;
} else if (type.isStringType) {
return TypeParser.parseString(value);

Check warning on line 597 in lib/src/bones_api_utils_json.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_api_utils_json.dart#L597

Added line #L597 was not covered by tests
} else if (type.isIntType) {
return TypeParser.parseInt(value);

Check warning on line 599 in lib/src/bones_api_utils_json.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_api_utils_json.dart#L599

Added line #L599 was not covered by tests
} else if (type.isDoubleType) {
return TypeParser.parseDouble(value);

Check warning on line 601 in lib/src/bones_api_utils_json.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_api_utils_json.dart#L601

Added line #L601 was not covered by tests
} else if (type.isNumType) {
return TypeParser.parseNum(value);

Check warning on line 603 in lib/src/bones_api_utils_json.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_api_utils_json.dart#L603

Added line #L603 was not covered by tests
} else if (type.isBoolType) {
return TypeParser.parseBool(value);

Check warning on line 605 in lib/src/bones_api_utils_json.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_api_utils_json.dart#L605

Added line #L605 was not covered by tests
} else if (type.isEntityReferenceType && value is EntityReference) {
if (type.arguments0?.type == value.type) {
return value;
Expand Down Expand Up @@ -668,6 +678,24 @@
? entityHandler.castIterableNullable(list, entityType)
: entityHandler.castIterable(list, entityType);
}

/// A debugging tool that generates a `String` representation of [o],
/// showing the [runtimeType] of each value in the tree.
static String dumpRuntimeTypes(Object? o, [String indent = '']) {
if (o == null) return '$indent<null>';
if (o is String) return '$indent<String>:"$o"';
if (o is bool) return '$indent<bool>:$o';
if (o is int) return '$indent<int>:$o';
if (o is double) return '$indent<double>:$o';
if (o is num) return '$indent<num>:$o';
if (o is Iterable) {
return '$indent<${o.runtimeType}>:[\n$indent${o.map((e) => dumpRuntimeTypes(e, ' $indent')).join(',\n$indent')}\n$indent]';
}
if (o is Map) {
return '$indent<${o.runtimeType}>:{\n$indent${o.entries.map((e) => "${dumpRuntimeTypes(e.key, ' $indent')}=${dumpRuntimeTypes(e.value, '')}").join(',\n$indent')}\n$indent}';
}
return '@<${o.runtimeType}>:$o';

Check warning on line 697 in lib/src/bones_api_utils_json.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_api_utils_json.dart#L697

Added line #L697 was not covered by tests
}
}

extension JsonEntityCacheExtension on JsonEntityCache {
Expand Down
19 changes: 10 additions & 9 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
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.8.7
version: 1.9.0
homepage: https://github.com/Colossus-Services/bones_api

environment:
sdk: '>=3.5.0 <4.0.0'
sdk: '>=3.6.0 <4.0.0'

executables:
bones_api:

dependencies:
async_extension: ^1.2.14
async_events: ^1.2.0
reflection_factory: ^2.4.10
statistics: ^1.1.3
swiss_knife: ^3.2.3
reflection_factory: ^2.5.0
statistics: ^1.2.0
swiss_knife: ^3.3.0
data_serializer: ^1.2.1
shared_map: ^1.1.9
graph_explorer: ^1.0.2
ascii_art_tree: ^1.0.6
map_history: ^1.0.6
dart_spawner: ^1.1.0
yaml_writer: ^2.0.1
mercury_client: ^2.2.4
yaml_writer: ^2.1.0
mercury_client: ^2.3.0
project_template: ^1.1.0
resource_portable: ^3.1.0
resource_portable: ^3.1.2
docker_commander: ^2.1.7
args_simple: ^1.1.0
shelf_letsencrypt: ^2.0.1
Expand All @@ -36,7 +36,7 @@ dependencies:
petitparser: ^6.1.0
hotreloader: ^4.3.0
logging: ^1.3.0
collection: ^1.18.0
collection: ^1.19.0
mime: ^1.0.6
postgres: ^2.6.4
mysql1: ^0.20.0
Expand All @@ -49,6 +49,7 @@ dependencies:
http: ^1.3.0
googleapis_auth: ^1.6.0
crclib: ^3.0.0
web: ^1.1.0

dev_dependencies:
lints: ^5.1.1
Expand Down
4 changes: 2 additions & 2 deletions test/bones_api_config_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ y=zzz
expect(
apiConfig.toYAMLEncoded(),
equals('foo: 123\n'
'bar: \'abc\'\n'
'bar: "abc"\n'
'password: 123456\n'
'baz: \'%bar%\'\n'));
'baz: "%bar%"\n'));

expect(
apiConfig.toPropertiesEncoded(),
Expand Down
2 changes: 1 addition & 1 deletion test/bones_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ class _MyHttpClientRequester extends mercury_client.HttpClientRequester {
response = await _getURL(
request.requestURL,
method: APIRequestMethod.POST,
payload: request.sendData,
payload: request.sendData as List<int>?,
payloadType: request.headerContentType,
);
} else {
Expand Down
8 changes: 4 additions & 4 deletions test/bones_api_test.reflection.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading