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
4 changes: 4 additions & 0 deletions .github/workflows/analyze.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ on:
- "pubspec.yaml"
- ".github/workflows/analyze.yaml"

permissions:
contents: read
pull-requests: write

jobs:
analysis:
name: 🕵️ Analyze
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/backup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
branches:
- main

permissions:
contents: read

jobs:
mirror-to-gitlab:
name: 💾 Backup to GitLab
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jobs:
check-version:
name: 💡 Check version
runs-on: ubuntu-latest
permissions:
contents: write
if: github.ref_type == 'tag'
timeout-minutes: 10
steps:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ on:
- "pubspec.yaml"
- ".github/workflows/test.yaml"

permissions:
contents: read

jobs:
test:
name: 🧪 Test
Expand Down
10 changes: 6 additions & 4 deletions .zed/debug.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
[
{
"adapter": "Dart",
"label": "Run example (simple)",
"label": "Run example (real client)",
"type": "dart",
"args": ["--simple"],
"request": "launch",
"program": "$ZED_WORKTREE_ROOT/example/lib/main.dart"
},
{
"adapter": "Dart",
"label": "Run example (real client)",
"label": "Run example (simple)",
"type": "dart",
"request": "launch",
"program": "$ZED_WORKTREE_ROOT/example/lib/main.dart"
"program": "$ZED_WORKTREE_ROOT/example/lib/main.dart",
"args": [
"--simple"
]
}
]
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![CodeFactor](https://www.codefactor.io/repository/github/tsinis/functional_status_codes/badge)](https://www.codefactor.io/repository/github/tsinis/functional_status_codes)
[![Pub points](https://img.shields.io/pub/points/functional_status_codes)](https://pub.dev/packages/functional_status_codes/score)
[![Created](https://img.shields.io/github/created-at/tsinis/functional_status_codes)](https://github.com/tsinis/functional_status_codes/commit/23d35c4fc890d01b8dc93409738e4fc61712e94f)
[![GitHub issues](https://img.shields.io/github/issues-raw/tsinis/functional_status_codes)](https://github.com/tsinis/functional_status_codes/issues?q=is%3Aissue+is%3Aopen)
![CodeRabbit Pull Request Reviews](https://img.shields.io/coderabbit/prs/github/tsinis/functional_status_codes?utm_source=oss&utm_medium=github&utm_campaign=tsinis%2Ffunctional_status_codes&labelColor=171717&color=FF570A&link=https%3A%2F%2Fcoderabbit.ai&label=CodeRabbit+Reviews)
[![License](https://img.shields.io/badge/License-BSD_3--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
[![Size](https://img.shields.io/github/languages/code-size/tsinis/functional_status_codes)](https://github.com/tsinis/functional_status_codes#why-should-i-use-this-package)
Expand Down Expand Up @@ -139,9 +140,9 @@ The use of `StatusCode` extension type and boolean getters (`isInformational`, `

10. **No 3rd-party dependencies**: This package has no third-party dependencies, ensuring that you won't have any issues or conflicts with other dependencies (no even `meta` here, because of that).

11. **High code coverage**: The code in this package has almost 100% code coverage, with more than 1000 tests, providing confidence in its reliability and stability.
11. **High code coverage**: The code in this package has almost 100% code coverage, with more than 1120 tests, providing confidence in its reliability and stability.

12. **Industry adopted**: This package is actively used (since 2022) in production by numerous European companies, ensuring its efficacy and robustness in real-world scenarios.
12. **Industry adopted**: This package is actively used (for years) in production by numerous European companies, ensuring its efficacy and robustness in real-world scenarios.

13. **BSD-3-Clause License**: This package and sources are released under the BSD-3-Clause license, a permissive license that is also used by the Dart and Flutter SDKs. It allows users to use, modify, and distribute the code with minimal restrictions.

Expand All @@ -151,6 +152,8 @@ The use of `StatusCode` extension type and boolean getters (`isInformational`, `

16. **Mirrored Repository**: The GitHub repository, including all package tags, is mirrored on [GitLab](https://gitlab.com/tsinis/functional_status_codes/), providing an alternative access point should GitHub become unavailable.

17. **Verified publisher**: Published and maintained under an active, verified pub.dev publisher account since 2022.

By using these features of the `functional_status_codes` package, you promote a more robust, readable, and maintainable approach to HTTP status code handling in your Dart projects.

### Getting started
Expand Down
18 changes: 11 additions & 7 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,12 @@ dart_code_metrics:
min-occurrences: 4

# Disabled:
# Shorthands:
- prefer-returning-shorthands: false
- prefer-shorthands-with-constructors: false
- prefer-shorthands-with-enums: false
- prefer-shorthands-with-static-fields: false
# Other disabled:
- arguments-ordering: false # This will be a breaking change.
- avoid-continue: false # Just a matter of style.
- avoid-deprecated-usage: false # Using default deprecated_member_use_from_same_package.
- avoid-inferrable-type-arguments: false # Against prefer-explicit-type-arguments.
- avoid-long-files: false # A lot of data and collections.
- avoid-throw: false # Breaking change + we have maybe* methods.
- no-magic-number: false # Packages contain a lot of numbers.
- no-magic-string: false # Packages contain a lot of strings.
- parameters-ordering: false # This will be a breaking change.
Expand Down Expand Up @@ -218,6 +213,7 @@ dart_code_metrics:
- avoid-missing-completer-stack-trace: true
- avoid-missing-enum-constant-in-map: true
- avoid-missing-interpolation: true
- avoid-missing-test-files: true
- avoid-misused-set-literals: true
- avoid-misused-test-matchers: true
- avoid-misused-wildcard-pattern: true
Expand Down Expand Up @@ -276,9 +272,11 @@ dart_code_metrics:
- avoid-type-casts: true
- avoid-unassigned-fields: true
- avoid-unassigned-late-fields: true
- avoid-unassigned-local-variable: true
- avoid-unassigned-stream-subscriptions: true
- avoid-uncaught-future-errors: true
- avoid-unconditional-break: true
- avoid-undisposed-instances: true
- avoid-unknown-pragma: true
- avoid-unnecessary-block: true
- avoid-unnecessary-call: true
Expand All @@ -304,6 +302,7 @@ dart_code_metrics:
- avoid-unnecessary-nullable-parameters: true
- avoid-unnecessary-nullable-return-type: true
- avoid-unnecessary-overrides: true
- avoid-unnecessary-parentheses: true
- avoid-unnecessary-patterns: true
- avoid-unnecessary-reassignment: true
- avoid-unnecessary-return: true
Expand Down Expand Up @@ -401,6 +400,7 @@ dart_code_metrics:
- prefer-match-file-name: true
- prefer-moving-to-variable: true
- prefer-named-boolean-parameters: true
- prefer-non-nulls: true
- prefer-null-aware-elements: true
- prefer-null-aware-spread: true
- prefer-overriding-parent-equality: true
Expand All @@ -413,6 +413,10 @@ dart_code_metrics:
- prefer-return-await: true
- prefer-returning-condition: true
- prefer-returning-conditional-expressions: true
- prefer-returning-shorthands: true
- prefer-shorthands-with-constructors: true
- prefer-shorthands-with-enums: true
- prefer-shorthands-with-static-fields: true
- prefer-simpler-boolean-expressions: true
- prefer-simpler-patterns-null-check: true
- prefer-single-declaration-per-file: true
Expand Down Expand Up @@ -658,4 +662,4 @@ linter:
use_to_and_as_if_applicable: true
use_truncating_division: true
valid_regexps: true
void_checks: true
void_checks: true
2 changes: 1 addition & 1 deletion example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include: ../analysis_options.yaml
include: ../analysis_options.yaml
26 changes: 16 additions & 10 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,13 @@ Future<int?> _realClient(List<String> arguments, [http.Client? client]) async {

// If the status code is a success status code, check if it is a 201
// (Created) or 200 (OK) code.
return response.statusCode.maybeWhenStatusCode(
isSuccess: () {
return response.statusCode.maybeMapStatusCode(
isSuccess: (successStatus) {
// If the status code is success one, convert it to a registered
// status code object.
final registeredCode = response.statusCode.toRegisteredStatusCode();
final registeredCode = successStatus.toRegisteredStatusCode();

// Use the [StatusCode] type to determine the specific status code
// type.
// Use the [StatusCode] type to determine the specific status code type.
return registeredCode?.maybeMap(
createdHttp201: (status) {
print('Response has registered success status but not 200 code');
Expand All @@ -114,19 +113,26 @@ Future<int?> _realClient(List<String> arguments, [http.Client? client]) async {
print('Response has success status but not 200 code');

// Return the status code.
return response.statusCode;
return successStatus;
},
) ??
// If the status code is not a registered status code, return the
// status code.
response.statusCode;
successStatus;
},
orElse: () {
isClientError: (errorStatus) {
if (errorStatus.isOneOf(const [StatusCode.tooManyRequestsHttp429])) {
print('Response has too many requests status :(');
}

return errorStatus; // Return the status code.
},
orElse: (otherStatus) {
// If the status code is not a success status code, print an error
// message and return the status code.
print('Request failed with status: ${response.statusCode}!');
print('Request failed with status: $otherStatus!');

return response.statusCode;
return otherStatus;
},
);
}
6 changes: 3 additions & 3 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ description: A simple one and modified http package example with use of function
publish_to: none

environment:
sdk: ^3.11.1
sdk: ^3.11.3

dependencies:
functional_status_codes:
path: ../
http: any # ignore: avoid-any-version, it's exampe app.

dev_dependencies:
dart_code_metrics_presets: ^2.29.0 # DCM.
dart_code_metrics_presets: ^2.30.0 # DCM.
lints: ^6.1.0 # From Google.
test: ^1.30.0 # From Google.
test: ^1.31.0 # From Google.
2 changes: 1 addition & 1 deletion lib/src/status_code.dart
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ extension type const StatusCode._(int _code) implements int {
/// See also:
/// - [pattern], the raw regular expression string this getter utilizes.
/// - [StatusCode], which contains standard HTTP status codes.
static RegExp get regExp => RegExp(pattern, caseSensitive: false);
static RegExp get regExp => .new(pattern, caseSensitive: false);

/// Returns the [StatusCode] type value for the given status code, if it
/// exists. Otherwise, returns `null`.
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ environment:

dev_dependencies:
coverage: ^1.15.0 # From Google.
dart_code_metrics_presets: ^2.29.0 # DCM.
dart_code_metrics_presets: ^2.30.0 # DCM.
lints: ^6.1.0 # From Google.
test: ^1.30.0 # From Google.
test: ^1.31.0 # From Google.
Loading