chore: fix and format using melos

This commit is contained in:
2023-02-23 19:19:48 +01:00
parent d098d9a6bf
commit 8d833d39d7
152 changed files with 441 additions and 468 deletions
@@ -32,14 +32,15 @@ enum EmailVerificationAction {
changeEmail;
String toSnakeCase() => name.splitMapJoin(
RegExp('[A-Z]'),
onMatch: (m) => '_${m[0]?.toLowerCase()}',
onNonMatch: (n) => n,
);
RegExp('[A-Z]'),
onMatch: (m) => '_${m[0]?.toLowerCase()}',
onNonMatch: (n) => n,
);
factory EmailVerificationAction.fromString(String str) => EmailVerificationAction.values.firstWhere(
(element) => element.toSnakeCase() == str,
);
factory EmailVerificationAction.fromString(String str) =>
EmailVerificationAction.values.firstWhere(
(element) => element.toSnakeCase() == str,
);
}
class VerifyCode {
@@ -56,23 +57,24 @@ class VerifyCode {
String? email,
String? verificationCode,
EmailVerificationAction? action,
}) => VerifyCode(
email: email ?? this.email,
verificationCode: verificationCode ?? this.verificationCode,
action: action ?? this.action,
);
}) =>
VerifyCode(
email: email ?? this.email,
verificationCode: verificationCode ?? this.verificationCode,
action: action ?? this.action,
);
Map<String, dynamic> toMap() => <String, dynamic>{
'email': email,
'verification_code': verificationCode,
'action': action.toSnakeCase(),
};
'email': email,
'verification_code': verificationCode,
'action': action.toSnakeCase(),
};
factory VerifyCode.fromMap(Map<String, dynamic> map) => VerifyCode(
email: map['email'] as String,
verificationCode: map['verification_code'] as String,
action: EmailVerificationAction.fromString(map['action'] as String),
);
email: map['email'] as String,
verificationCode: map['verification_code'] as String,
action: EmailVerificationAction.fromString(map['action'] as String),
);
String toJson() => json.encode(toMap());
@@ -95,20 +97,22 @@ class Account {
Account copyWith({
String? email,
String? sessionId,
}) => Account(
email: email ?? this.email,
sessionId: sessionId ?? this.sessionId,
);
}) =>
Account(
email: email ?? this.email,
sessionId: sessionId ?? this.sessionId,
);
Map<String, dynamic> toMap() => <String, dynamic>{
'email': email,
'session_id': sessionId,
};
'email': email,
'session_id': sessionId,
};
factory Account.fromMap(Map<String, dynamic> map) => Account(
email: map['email'] as String,
sessionId: map['session_id'] != null ? map['session_id'] as String : null,
);
email: map['email'] as String,
sessionId:
map['session_id'] != null ? map['session_id'] as String : null,
);
String toJson() => json.encode(toMap());
@@ -130,20 +134,21 @@ class SignUp {
SignUp copyWith({
String? sessionId,
String? password,
}) => SignUp(
sessionId: sessionId ?? this.sessionId,
password: password ?? this.password,
);
}) =>
SignUp(
sessionId: sessionId ?? this.sessionId,
password: password ?? this.password,
);
Map<String, dynamic> toMap() => <String, dynamic>{
'session_id': sessionId,
'password': password,
};
'session_id': sessionId,
'password': password,
};
factory SignUp.fromMap(Map<String, dynamic> map) => SignUp(
sessionId: map['session_id'] as String,
password: map['password'] as String,
);
sessionId: map['session_id'] as String,
password: map['password'] as String,
);
String toJson() => json.encode(toMap());
@@ -168,23 +173,24 @@ class TokenSuccess {
String? accessToken,
String? refreshToken,
Account? account,
}) => TokenSuccess(
accessToken: accessToken ?? this.accessToken,
refreshToken: refreshToken ?? this.refreshToken,
account: account ?? this.account,
);
}) =>
TokenSuccess(
accessToken: accessToken ?? this.accessToken,
refreshToken: refreshToken ?? this.refreshToken,
account: account ?? this.account,
);
Map<String, dynamic> toMap() => <String, dynamic>{
'access_token': accessToken,
'refresh_token': refreshToken,
'account': account.toMap(),
};
'access_token': accessToken,
'refresh_token': refreshToken,
'account': account.toMap(),
};
factory TokenSuccess.fromMap(Map<String, dynamic> map) => TokenSuccess(
accessToken: map['access_token'] as String,
refreshToken: map['refresh_token'] as String,
account: Account.fromMap(map['account'] as Map<String, dynamic>),
);
accessToken: map['access_token'] as String,
refreshToken: map['refresh_token'] as String,
account: Account.fromMap(map['account'] as Map<String, dynamic>),
);
String toJson() => json.encode(toMap());
@@ -207,20 +213,21 @@ class Login {
Login copyWith({
String? email,
String? password,
}) => Login(
email: email ?? this.email,
password: password ?? this.password,
);
}) =>
Login(
email: email ?? this.email,
password: password ?? this.password,
);
Map<String, dynamic> toMap() => <String, dynamic>{
'email': email,
'password': password,
};
'email': email,
'password': password,
};
factory Login.fromMap(Map<String, dynamic> map) => Login(
email: map['email'] as String,
password: map['password'] as String,
);
email: map['email'] as String,
password: map['password'] as String,
);
String toJson() => json.encode(toMap());
@@ -25,7 +25,6 @@ import 'package:wyatt_http_client/src/pipeline.dart';
import 'package:wyatt_http_client/src/utils/http_methods.dart';
class MiddlewareClient extends BaseClient {
MiddlewareClient({
Pipeline? pipeline,
Client? inner,
@@ -1,16 +1,15 @@
// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
@@ -23,7 +23,6 @@ import 'package:wyatt_http_client/src/utils/authentication_methods.dart';
import 'package:wyatt_http_client/src/utils/header_keys.dart';
class BasicAuthMiddleware with OnRequestMiddleware implements Middleware {
BasicAuthMiddleware({
this.username,
this.password,
@@ -25,7 +25,6 @@ import 'package:wyatt_http_client/src/utils/http_status.dart';
class DigestAuthMiddleware
with OnRequestMiddleware, OnResponseMiddleware
implements Middleware {
DigestAuthMiddleware({
required this.username,
required this.password,
@@ -1,16 +1,16 @@
// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
@@ -31,7 +31,6 @@ typedef TokenParser = String Function(Map<String, dynamic>);
class RefreshTokenAuthMiddleware
with OnRequestMiddleware, OnResponseMiddleware
implements Middleware {
RefreshTokenAuthMiddleware({
required this.authorizationEndpoint,
required this.tokenEndpoint,
@@ -20,7 +20,6 @@ import 'package:wyatt_http_client/src/models/middleware_request.dart';
import 'package:wyatt_http_client/src/utils/convert.dart';
class UnsafeAuthMiddleware with OnRequestMiddleware implements Middleware {
UnsafeAuthMiddleware({
this.username,
this.password,
@@ -20,7 +20,6 @@ import 'package:wyatt_http_client/src/models/middleware_request.dart';
import 'package:wyatt_http_client/src/utils/protocols.dart';
class UriPrefixMiddleware with OnRequestMiddleware implements Middleware {
UriPrefixMiddleware({
required this.protocol,
required this.authority,
@@ -44,15 +44,19 @@ class MiddlewareContext {
MiddlewareRequest? lastRequest,
MiddlewareResponse? originalResponse,
MiddlewareResponse? lastResponse,
}) => MiddlewareContext(
pipeline: pipeline ?? this.pipeline,
client: client ?? this.client,
originalRequest: originalRequest ?? this.originalRequest,
lastRequest: lastRequest ?? this.lastRequest,
originalResponse: originalResponse ?? this.originalResponse,
lastResponse: lastResponse ?? this.lastResponse,
);
}) =>
MiddlewareContext(
pipeline: pipeline ?? this.pipeline,
client: client ?? this.client,
originalRequest: originalRequest ?? this.originalRequest,
lastRequest: lastRequest ?? this.lastRequest,
originalResponse: originalResponse ?? this.originalResponse,
lastResponse: lastResponse ?? this.lastResponse,
);
@override
String toString() => 'MiddlewareContext(pipeline: $pipeline, client: $client, originalRequest: $originalRequest, lastRequest: $lastRequest, originalResponse: $originalResponse, lastResponse: $lastResponse)';
String toString() =>
'MiddlewareContext(pipeline: $pipeline, client: $client, '
'originalRequest: $originalRequest, lastRequest: $lastRequest, '
'originalResponse: $originalResponse, lastResponse: $lastResponse)';
}
@@ -31,6 +31,7 @@ class MiddlewareResponse {
return '';
}
}
int? get contentLength => httpResponse.contentLength;
Map<String, String> get headers => httpResponse.headers;
@@ -40,11 +41,11 @@ class MiddlewareResponse {
MiddlewareResponse copyWith({
BaseResponse? httpResponse,
}) => MiddlewareResponse(
httpResponse: httpResponse ?? this.httpResponse,
);
}) =>
MiddlewareResponse(
httpResponse: httpResponse ?? this.httpResponse,
);
@override
String toString() =>
'MiddlewareResponse(httpResponse: $httpResponse)';
String toString() => 'MiddlewareResponse(httpResponse: $httpResponse)';
}
@@ -1,16 +1,16 @@
// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
@@ -17,7 +17,6 @@
import 'dart:convert';
class UnfreezedRequest {
UnfreezedRequest({
required this.method,
required this.url,
@@ -37,15 +36,16 @@ class UnfreezedRequest {
Map<String, String>? headers,
Object? body,
Encoding? encoding,
}) => UnfreezedRequest(
method: method ?? this.method,
url: url ?? this.url,
headers: headers ?? this.headers,
body: body ?? this.body,
encoding: encoding ?? this.encoding,
);
}) =>
UnfreezedRequest(
method: method ?? this.method,
url: url ?? this.url,
headers: headers ?? this.headers,
body: body ?? this.body,
encoding: encoding ?? this.encoding,
);
@override
String toString() => 'UnfreezedRequest(method: $method, url: $url, headers: '
'$headers, body: $body, encoding: $encoding)';
'$headers, body: $body, encoding: $encoding)';
}
@@ -20,7 +20,6 @@ import 'package:wyatt_http_client/src/models/middleware_request.dart';
import 'package:wyatt_http_client/src/models/middleware_response.dart';
class Pipeline {
Pipeline() : _middlewares = <Middleware>[];
Pipeline.fromIterable(Iterable<Middleware> middlewares)
: _middlewares = middlewares.toList();
@@ -65,8 +64,7 @@ class Pipeline {
MiddlewareContext ctx = context.copyWith(lastRequest: req);
for (final middleware in _middlewares) {
if (middleware is OnRequestMiddleware) {
req = await (middleware as OnRequestMiddleware)
.onRequest(ctx, request);
req = await (middleware as OnRequestMiddleware).onRequest(ctx, request);
ctx = context.copyWith(lastRequest: req);
}
}
@@ -34,10 +34,12 @@ class Convert {
static String mapToQuery(Map<String, String> map, {Encoding? encoding}) {
final pairs = <List<String>>[];
map.forEach((key, value) => pairs.add([
Uri.encodeQueryComponent(key, encoding: encoding ?? utf8),
Uri.encodeQueryComponent(value, encoding: encoding ?? utf8)
]),);
map.forEach(
(key, value) => pairs.add([
Uri.encodeQueryComponent(key, encoding: encoding ?? utf8),
Uri.encodeQueryComponent(value, encoding: encoding ?? utf8)
]),
);
return pairs.map((pair) => '${pair[0]}=${pair[1]}').join('&');
}
}
@@ -19,7 +19,8 @@ import 'dart:math';
import 'package:wyatt_http_client/src/utils/convert.dart';
import 'package:wyatt_http_client/src/utils/crypto.dart';
class DigestAuth { // request counter
class DigestAuth {
// request counter
DigestAuth(this.username, this.password);
String username;
@@ -22,7 +22,7 @@ enum HttpMethods {
patch('PATCH'),
delete('DELETE');
final String method;
const HttpMethods(this.method);
final String method;
}
@@ -81,10 +81,13 @@ enum HttpStatus {
// Client generated status code.
networkConnectTimeoutError(599);
final int statusCode;
const HttpStatus(this.statusCode);
factory HttpStatus.from(int status) =>
HttpStatus.values.firstWhere((element) => element.statusCode == status);
final int statusCode;
bool equals(Object other) {
if (other is HttpStatus) {
return statusCode == other.statusCode;
@@ -104,8 +107,4 @@ enum HttpStatus {
bool isClientError() => statusCode >= 400 && statusCode < 500;
bool isServerError() => statusCode >= 500 && statusCode < 600;
factory HttpStatus.from(int status) => HttpStatus.values
.firstWhere((element) => element.statusCode == status);
}
@@ -1,16 +1,16 @@
// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.