Skip to content

Commit

Permalink
fix: objectbox pub.dev score (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
techouse authored Jul 2, 2024
1 parent 27fe609 commit 2c3fddc
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/alice_objectbox/lib/alice_objectbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:alice_objectbox/extensions/alice_http_call_extension.dart';
import 'package:alice_objectbox/model/cached_alice_http_call.dart';
import 'package:alice_objectbox/objectbox.g.dart';

/// Implementation of [AliceStorage] using ObjectBox.
class AliceObjectBox implements AliceStorage {
const AliceObjectBox({
required AliceObjectBoxStore store,
Expand Down
8 changes: 3 additions & 5 deletions packages/alice_objectbox/lib/alice_objectbox_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import 'package:alice_objectbox/objectbox.g.dart';
import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart';

/// Provides access to the ObjectBox Store throughout the app.
///
/// Create this in the apps main function.
/// Implementation of [AliceStore] using ObjectBox.
class AliceObjectBoxStore implements AliceStore {
AliceObjectBoxStore._create(
this._store, {
Expand All @@ -22,7 +20,7 @@ class AliceObjectBoxStore implements AliceStore {
}
}

/// Create an instance of ObjectBox to use throughout the app.
/// Create an instance of [AliceObjectBoxStore] to use throughout the app.
static Future<AliceObjectBoxStore> create({
Store? store,
bool persistent = true,
Expand All @@ -47,7 +45,7 @@ class AliceObjectBoxStore implements AliceStore {

late final Store _store;

/// Boxes
/// Box to store [CachedAliceHttpCall] objects.
late final Box<CachedAliceHttpCall> httpCalls;

late final Map<Type, Box> _boxes = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:alice/model/alice_http_call.dart';
import 'package:alice_objectbox/model/cached_alice_http_call.dart';

/// Extension methods for [AliceHttpCall].
extension AliceHttpCallExtension on AliceHttpCall {
/// Converts [AliceHttpCall] to [CachedAliceHttpCall].
CachedAliceHttpCall toCached() => CachedAliceHttpCall(
id,
client: client,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:alice/model/alice_http_error.dart';
import 'package:alice_objectbox/model/cached_alice_http_error.dart';

/// Extension methods for [AliceHttpError].
extension AliceHttpErrorExtension on AliceHttpError {
/// Converts [AliceHttpError] to [CachedAliceHttpError].
CachedAliceHttpError toCached() => CachedAliceHttpError()
..error = error
..stackTrace = stackTrace;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:alice/model/alice_http_request.dart';
import 'package:alice_objectbox/model/cached_alice_http_request.dart';

/// Extension methods for [AliceHttpRequest].
extension AliceHttpRequestExtension on AliceHttpRequest {
/// Converts [AliceHttpRequest] to [CachedAliceHttpRequest].
CachedAliceHttpRequest toCached() => CachedAliceHttpRequest(
size: size,
time: time,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:alice/model/alice_http_response.dart';
import 'package:alice_objectbox/model/cached_alice_http_response.dart';

/// Extension methods for [AliceHttpResponse].
extension AliceHttpResponseExtension on AliceHttpResponse {
/// Converts [AliceHttpResponse] to [CachedAliceHttpResponse].
CachedAliceHttpResponse toCached() => CachedAliceHttpResponse(
status: status,
size: size,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'package:alice/model/alice_from_data_field.dart';
import 'package:json_annotation/json_annotation.dart';

/// Convert [AliceFormDataField] to and from JSON.
class AliceFormDataFieldConverter
implements JsonConverter<AliceFormDataField, Map<String, dynamic>> {
const AliceFormDataFieldConverter();

/// Instance of [AliceFormDataFieldConverter].
static const AliceFormDataFieldConverter instance =
AliceFormDataFieldConverter();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'package:alice/model/alice_form_data_file.dart';
import 'package:json_annotation/json_annotation.dart';

/// Convert [AliceFormDataFile] to and from JSON.
class AliceFormDataFileConverter
implements JsonConverter<AliceFormDataFile, Map<String, dynamic>> {
const AliceFormDataFileConverter();

/// Instance of [AliceFormDataFileConverter].
static const AliceFormDataFileConverter instance =
AliceFormDataFileConverter();

Expand Down
12 changes: 9 additions & 3 deletions packages/alice_objectbox/lib/model/cached_alice_http_call.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:alice_objectbox/model/cached_alice_http_response.dart';
import 'package:meta/meta.dart';
import 'package:objectbox/objectbox.dart';

/// ObjectBox [Entity] of [AliceHttpCall].
@Entity()
class CachedAliceHttpCall implements AliceHttpCall {
CachedAliceHttpCall(
Expand All @@ -27,6 +28,8 @@ class CachedAliceHttpCall implements AliceHttpCall {
this.duration = 0,
}) : createdTime = createdTime ?? DateTime.now();

/// ObjectBox internal ID.
@internal
@Id()
int objectId;

Expand Down Expand Up @@ -71,7 +74,8 @@ class CachedAliceHttpCall implements AliceHttpCall {
@Transient()
set request(AliceHttpRequest? value) => requestRel.target = value?.toCached();

@protected
/// [ToOne] relation of [request].
@internal
final ToOne<CachedAliceHttpRequest> requestRel =
ToOne<CachedAliceHttpRequest>();

Expand All @@ -84,7 +88,8 @@ class CachedAliceHttpCall implements AliceHttpCall {
set response(AliceHttpResponse? value) =>
responseRel.target = value?.toCached();

@protected
/// [ToOne] relation of [response].
@internal
final ToOne<CachedAliceHttpResponse> responseRel =
ToOne<CachedAliceHttpResponse>();

Expand All @@ -96,7 +101,8 @@ class CachedAliceHttpCall implements AliceHttpCall {
@Transient()
set error(AliceHttpError? value) => errorRel.target = value?.toCached();

@protected
/// [ToOne] relation of [error].
@internal
final ToOne<CachedAliceHttpError> errorRel = ToOne<CachedAliceHttpError>();

@override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import 'dart:convert' show jsonDecode, jsonEncode;

import 'package:alice/model/alice_http_error.dart';
import 'package:meta/meta.dart';
import 'package:objectbox/objectbox.dart';

/// ObjectBox [Entity] of [AliceHttpError].
@Entity()
class CachedAliceHttpError implements AliceHttpError {
CachedAliceHttpError({
this.objectId = 0,
});

/// ObjectBox internal ID.
@internal
@Id()
int objectId;

@override
@Transient()
dynamic error;

/// Custom data type converter of [error].
String? get dbError {
if (error != null) {
try {
Expand All @@ -27,15 +32,18 @@ class CachedAliceHttpError implements AliceHttpError {
return null;
}

/// Custom data type converter of [error].
set dbError(String? value) =>
error = value != null ? jsonDecode(value) : null;

@override
@Transient()
StackTrace? stackTrace;

/// Custom data type converter of [error].
String? get dbStackTrace => stackTrace?.toString();

/// Custom data type converter of [error].
set dbStackTrace(String? value) =>
stackTrace = value != null ? StackTrace.fromString(value) : null;
}
16 changes: 16 additions & 0 deletions packages/alice_objectbox/lib/model/cached_alice_http_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import 'package:alice/model/alice_from_data_field.dart';
import 'package:alice/model/alice_http_request.dart';
import 'package:alice_objectbox/json_converter/alice_form_data_field_converter.dart';
import 'package:alice_objectbox/json_converter/alice_form_data_file_converter.dart';
import 'package:meta/meta.dart';
import 'package:objectbox/objectbox.dart';

/// ObjectBox [Entity] of [AliceHttpRequest].
@Entity()
class CachedAliceHttpRequest implements AliceHttpRequest {
CachedAliceHttpRequest({
Expand All @@ -23,6 +25,8 @@ class CachedAliceHttpRequest implements AliceHttpRequest {
this.formDataFields,
}) : time = time ?? DateTime.now();

/// ObjectBox internal ID.
@internal
@Id()
int objectId;

Expand All @@ -37,15 +41,18 @@ class CachedAliceHttpRequest implements AliceHttpRequest {
@Transient()
Map<String, dynamic> headers;

/// Custom data type converter of [headers].
String get dbHeaders => jsonEncode(headers);

/// Custom data type converter of [headers].
set dbHeaders(String value) =>
headers = jsonDecode(value) as Map<String, dynamic>;

@override
@Transient()
dynamic body;

/// Custom data type converter of [body].
String? get dbBody {
if (body != null) {
try {
Expand All @@ -57,6 +64,7 @@ class CachedAliceHttpRequest implements AliceHttpRequest {
return null;
}

/// Custom data type converter of [body].
set dbBody(String? value) => body = value != null ? jsonDecode(value) : null;

@override
Expand All @@ -66,32 +74,38 @@ class CachedAliceHttpRequest implements AliceHttpRequest {
@Transient()
List<Cookie> cookies;

/// Custom data type converter of [cookies].
List<String> get dbCookies =>
cookies.map((Cookie cookie) => cookie.toString()).toList();

/// Custom data type converter of [cookies].
set dbCookies(List<String> value) => cookies =
value.map((String cookie) => Cookie.fromSetCookieValue(cookie)).toList();

@override
@Transient()
Map<String, dynamic> queryParameters;

/// Custom data type converter of [queryParameters].
String get dbQueryParameters => jsonEncode(queryParameters);

/// Custom data type converter of [queryParameters].
set dbQueryParameters(String value) =>
queryParameters = jsonDecode(value) as Map<String, dynamic>;

@override
@Transient()
List<AliceFormDataFile>? formDataFiles;

/// Custom data type converter of [formDataFiles].
List<String>? get dbFormDataFiles => formDataFiles
?.map(
(AliceFormDataFile file) =>
jsonEncode(AliceFormDataFileConverter.instance.toJson(file)),
)
.toList();

/// Custom data type converter of [formDataFiles].
set dbFormDataFiles(List<String>? value) => formDataFiles = value
?.map(
(String file) =>
Expand All @@ -103,13 +117,15 @@ class CachedAliceHttpRequest implements AliceHttpRequest {
@Transient()
List<AliceFormDataField>? formDataFields;

/// Custom data type converter of [formDataFields].
List<String>? get dbFormDataFields => formDataFields
?.map(
(AliceFormDataField field) =>
jsonEncode(AliceFormDataFieldConverter.instance.toJson(field)),
)
.toList();

/// Custom data type converter of [formDataFields].
set dbFormDataFields(List<String>? value) => formDataFields = value
?.map(
(String field) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'dart:convert' show jsonDecode, jsonEncode;

import 'package:alice/model/alice_http_response.dart';
import 'package:meta/meta.dart';
import 'package:objectbox/objectbox.dart';

/// ObjectBox [Entity] of [AliceHttpResponse].
@Entity()
class CachedAliceHttpResponse implements AliceHttpResponse {
CachedAliceHttpResponse({
Expand All @@ -14,6 +16,8 @@ class CachedAliceHttpResponse implements AliceHttpResponse {
this.headers,
}) : time = time ?? DateTime.now();

/// ObjectBox internal ID.
@internal
@Id()
int objectId;

Expand All @@ -31,6 +35,7 @@ class CachedAliceHttpResponse implements AliceHttpResponse {
@Transient()
dynamic body;

/// Custom data type converter of [body].
String? get dbBody {
if (body != null) {
try {
Expand All @@ -42,14 +47,17 @@ class CachedAliceHttpResponse implements AliceHttpResponse {
return null;
}

/// Custom data type converter of [body].
set dbBody(String? value) => body = value != null ? jsonDecode(value) : null;

@override
@Transient()
Map<String, String>? headers;

/// Custom data type converter of [headers].
String? get dbHeaders => headers != null ? jsonEncode(headers) : null;

/// Custom data type converter of [headers].
set dbHeaders(String? value) => headers = value != null
? (jsonDecode(value) as Map<String, dynamic>?)?.map(
(key, value) => MapEntry(key, value.toString()),
Expand Down

0 comments on commit 2c3fddc

Please sign in to comment.