Skip to content

Commit

Permalink
Merge pull request #75 from myConsciousness/70-improve-suggestion-mov…
Browse files Browse the repository at this point in the history
…e-baseservice-to-atproto_core

fix: fixed for the issue (#70)
  • Loading branch information
myConsciousness committed Mar 12, 2023
2 parents 2ae76c8 + 906cc7e commit 14b56e3
Show file tree
Hide file tree
Showing 36 changed files with 227 additions and 434 deletions.
7 changes: 7 additions & 0 deletions packages/atproto/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Release Note

## v0.1.0

- Refactored structures. ([#70](https://github.com/myConsciousness/atproto.dart/issues/70))
- Moved `Empty` to `atproto_core`
- Moved `ATProtoResponse` to `atproto_core`
- Moved `ATProtoRequest` to `atproto_core`

## v0.0.4

- Fixed typo from `awtToken` to `accessJwt`.
Expand Down
45 changes: 14 additions & 31 deletions packages/atproto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

[![pub package](https://img.shields.io/pub/v/atproto.svg?logo=dart&logoColor=00b9fc)](https://pub.dartlang.org/packages/atproto)
[![Dart SDK Version](https://badgen.net/pub/sdk-version/atproto)](https://pub.dev/packages/atproto/)
[![Test](https://github.com/myConsciousness/atproto.dart/actions/workflows/test.yml/badge.svg)](https://github.com/myConsciousness/atproto.dart/actions/workflows/test.yml)
[![Analyzer](https://github.com/myConsciousness/atproto.dart/actions/workflows/analyzer.yml/badge.svg)](https://github.com/myConsciousness/atproto.dart/actions/workflows/analyzer.yml)
[![CICD](https://github.com/myConsciousness/atproto.dart/actions/workflows/cicd.yml/badge.svg)](https://github.com/myConsciousness/atproto.dart/actions/workflows/cicd.yml)
[![codecov](https://codecov.io/gh/myConsciousness/atproto.dart/branch/main/graph/badge.svg?token=J5GT1PF9Y3)](https://codecov.io/gh/myConsciousness/atproto.dart)
[![Issues](https://img.shields.io/github/issues/myConsciousness/atproto.dart?logo=github&logoColor=white)](https://github.com/myConsciousness/atproto.dart/issues)
[![Pull Requests](https://img.shields.io/github/issues-pr/myConsciousness/atproto.dart?logo=github&logoColor=white)](https://github.com/myConsciousness/atproto.dart/pulls)
Expand Down Expand Up @@ -50,10 +49,9 @@
- [1.4.4.2. Do Something on Retry](#1442-do-something-on-retry)
- [1.4.5. Thrown Exceptions](#145-thrown-exceptions)
- [1.5. Contribution 🏆](#15-contribution-)
- [1.6. Contributors ✨](#16-contributors-)
- [1.7. Support ❤️](#17-support-️)
- [1.8. License 🔑](#18-license-)
- [1.9. More Information 🧐](#19-more-information-)
- [1.6. Support ❤️](#16-support-️)
- [1.7. License 🔑](#17-license-)
- [1.8. More Information 🧐](#18-more-information-)

<!-- /TOC -->

Expand Down Expand Up @@ -283,15 +281,15 @@ The [RetryEvent](https://pub.dev/documentation/atproto/latest/atproto/RetryEvent

| Exception | Description |
| -------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| [ATProtoException](https://pub.dev/documentation/atproto/latest/atproto/ATProtoException-class.html) | The most basic exception object. For example, it can be used to search for posts that have already been deleted, etc. |
| [ATProtoException](https://pub.dev/documentation/atproto/latest/atproto_core/ATProtoException-class.html) | The most basic exception object. For example, it can be used to search for posts that have already been deleted, etc. |
| [UnauthorizedException](https://pub.dev/documentation/atproto/latest/atproto/UnauthorizedException-class.html) | Thrown when authentication fails with the specified access token. |
| [DataNotFoundException](https://pub.dev/documentation/atproto/latest/atproto/DataNotFoundException-class.html) | Thrown when response has no body or data field in body string, or when 404 status is returned. |

Also, all of the above exceptions thrown from the **atproto** process extend [ATProtoException](https://pub.dev/documentation/atproto/latest/atproto/ATProtoException-class.html). This means that you can take all exceptions as [ATProtoException](https://pub.dev/documentation/atproto/latest/atproto/ATProtoException-class.html) or handle them as certain exception types, depending on the situation.
Also, all of the above exceptions thrown from the **atproto** process extend [ATProtoException](https://pub.dev/documentation/atproto/latest/atproto_core/ATProtoException-class.html). This means that you can take all exceptions as [ATProtoException](https://pub.dev/documentation/atproto/latest/atproto_core/ATProtoException-class.html) or handle them as certain exception types, depending on the situation.

However note that, if you receive an individual type exception, be sure to define the process so that the individual exception type is cached before [ATProtoException](https://pub.dev/documentation/atproto/latest/atproto/ATProtoException-class.html). Otherwise, certain type exceptions will also be caught as [ATProtoException](https://pub.dev/documentation/atproto/latest/atproto/ATProtoException-class.html).
However note that, if you receive an individual type exception, be sure to define the process so that the individual exception type is cached before [ATProtoException](https://pub.dev/documentation/atproto/latest/atproto_core/ATProtoException-class.html). Otherwise, certain type exceptions will also be caught as [ATProtoException](https://pub.dev/documentation/atproto/latest/atproto_core/ATProtoException-class.html).

Therefore, if you need to catch a specific type of exception in addition to [ATProtoException](https://pub.dev/documentation/atproto/latest/atproto/ATProtoException-class.html), be sure to catch [ATProtoException](https://pub.dev/documentation/atproto/latest/atproto/ATProtoException-class.html) in the bottom catch clause as in the following example.
Therefore, if you need to catch a specific type of exception in addition to [ATProtoException](https://pub.dev/documentation/atproto/latest/atproto_core/ATProtoException-class.html), be sure to catch [ATProtoException](https://pub.dev/documentation/atproto/latest/atproto_core/ATProtoException-class.html) in the bottom catch clause as in the following example.

```dart
import 'package:atproto/atproto.dart' as atp;
Expand All @@ -306,9 +304,9 @@ Future<void> main() async {
final response = await atproto.sessions.lookupCurrentSession();
print(response);
} on UnauthorizedException catch (e) {
} on atp.UnauthorizedException catch (e) {
print(e);
} on ATProtoException catch (e) {
} on atp.ATProtoException catch (e) {
print(e);
}
}
Expand All @@ -335,22 +333,7 @@ Or you can create a [discussion](https://github.com/myConsciousness/atproto.dart

**Feel free to join this development, diverse opinions make software better!**

## 1.6. Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->

<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

## 1.7. Support ❤️
## 1.6. Support ❤️

The simplest way to show us your support is by **giving the project a star** at [GitHub](https://github.com/myConsciousness/atproto.dart) and [Pub.dev](https://pub.dev/packages/atproto).

Expand All @@ -376,20 +359,20 @@ You can also show on your repository that your app is made with **atproto** by u
[![Powered by atproto](https://img.shields.io/badge/Powered%20by-atproto-00acee.svg?style=for-the-badge)](https://github.com/myConsciousness/atproto.dart)
```

## 1.8. License 🔑
## 1.7. License 🔑

All resources of **atproto** is provided under the `BSD-3` license.

```license
Copyright 2022 Kato Shinya. All rights reserved.
Copyright 2023 Kato Shinya. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided the conditions.
```

> **Note**</br>
> License notices in the source are strictly validated based on `.github/header-checker-lint.yml`. Please check [header-checker-lint.yml](https://github.com/myConsciousness/atproto.dart/tree/main/.github/header-checker-lint.yml) for the permitted standards.
## 1.9. More Information 🧐
## 1.8. More Information 🧐

**atproto** was designed and implemented by **_Kato Shinya ([@myConsciousness](https://github.com/myConsciousness))_**.

Expand Down
7 changes: 4 additions & 3 deletions packages/atproto/lib/atproto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@

export 'package:atproto/src/atproto.dart';
export 'package:atproto/src/service/atproto_service.dart';
export 'package:atproto/src/service/entities/empty.dart';
export 'package:atproto/src/service/entities/record.dart';
export 'package:atproto/src/service/repositories/repositories_service.dart';
export 'package:atproto/src/service/response/atproto_request.dart';
export 'package:atproto/src/service/response/atproto_response.dart';
export 'package:atproto/src/service/sessions/current_session.dart';
export 'package:atproto/src/service/sessions/session.dart';
export 'package:atproto/src/service/sessions/sessions_service.dart';
export 'package:atproto_core/atproto_core.dart'
show
Empty,
ATProtoRequest,
ATProtoResponse,
Jitter,
RetryConfig,
RetryEvent,
ATProtoException,
UnauthorizedException,
DataNotFoundException,
RateLimitExceededException,
ForbiddenException,
HttpMethod,
HttpStatus;
18 changes: 18 additions & 0 deletions packages/atproto/lib/src/service/atproto_base_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2023 Kato Shinya. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided the conditions.

// 📦 Package imports:
import 'package:atproto_core/atproto_core.dart' as core;

abstract class ATProtoBaseService extends core.BaseService {
/// Returns the new instance of [ATProtoBaseService].
ATProtoBaseService({
required this.did,
required super.service,
required super.context,
});

/// The DID of authenticated user.
final String did;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
// 🌎 Project imports:
import 'package:atproto_core/atproto_core.dart' as core;

import '../base_service.dart';
import '../entities/empty.dart';
import '../atproto_base_service.dart';
import '../entities/record.dart';
import '../response/atproto_response.dart';

abstract class RepositoriesService {
/// Returns the new instance of [RepositoriesService].
Expand All @@ -23,18 +21,19 @@ abstract class RepositoriesService {
context: context,
);

Future<ATProtoResponse<Record>> createRecord({
Future<core.ATProtoResponse<Record>> createRecord({
required String collection,
required Map<String, dynamic> record,
});

Future<ATProtoResponse<Empty>> destroyRecord({
Future<core.ATProtoResponse<core.Empty>> destroyRecord({
required String collection,
required String uri,
});
}

class _RepositoriesService extends BaseService implements RepositoriesService {
class _RepositoriesService extends ATProtoBaseService
implements RepositoriesService {
/// Returns the new instance of [_RepositoriesService].
_RepositoriesService({
required super.did,
Expand All @@ -43,7 +42,7 @@ class _RepositoriesService extends BaseService implements RepositoriesService {
});

@override
Future<ATProtoResponse<Record>> createRecord({
Future<core.ATProtoResponse<Record>> createRecord({
required String collection,
required Map<String, dynamic> record,
}) async =>
Expand All @@ -60,7 +59,7 @@ class _RepositoriesService extends BaseService implements RepositoriesService {
);

@override
Future<ATProtoResponse<Empty>> destroyRecord({
Future<core.ATProtoResponse<core.Empty>> destroyRecord({
required String collection,
required String uri,
}) async =>
Expand Down
16 changes: 7 additions & 9 deletions packages/atproto/lib/src/service/sessions/sessions_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ import 'dart:convert';
import 'package:atproto_core/atproto_core.dart' as core;
import 'package:http/http.dart' as http;

import '../base_service.dart';
import '../response/atproto_request.dart';
import '../response/atproto_response.dart';
import '../atproto_base_service.dart';
import 'current_session.dart';
import 'session.dart';

Future<ATProtoResponse<Session>> createSession({
Future<core.ATProtoResponse<Session>> createSession({
String service = 'bsky.social',
required String handle,
required String password,
Expand Down Expand Up @@ -50,10 +48,10 @@ Future<ATProtoResponse<Session>> createSession({
);
}

return ATProtoResponse(
return core.ATProtoResponse(
headers: response.headers,
status: core.HttpStatus.ok,
request: ATProtoRequest(
request: core.ATProtoRequest(
method: core.HttpMethod.post,
url: response.request!.url,
),
Expand All @@ -76,10 +74,10 @@ abstract class SessionsService {
context: context,
);

Future<ATProtoResponse<CurrentSession>> lookupCurrentSession();
Future<core.ATProtoResponse<CurrentSession>> lookupCurrentSession();
}

class _SessionsService extends BaseService implements SessionsService {
class _SessionsService extends ATProtoBaseService implements SessionsService {
/// Returns the new instance of [_SessionsService].
_SessionsService({
required super.did,
Expand All @@ -88,7 +86,7 @@ class _SessionsService extends BaseService implements SessionsService {
});

@override
Future<ATProtoResponse<CurrentSession>> lookupCurrentSession() async =>
Future<core.ATProtoResponse<CurrentSession>> lookupCurrentSession() async =>
super.transformSingleDataResponse(
await super.get(
'/xrpc/com.atproto.session.get',
Expand Down
1 change: 0 additions & 1 deletion packages/atproto/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ environment:
dependencies:
atproto_core: ^0.0.2
http: ^0.13.5
universal_io: ^2.2.0
freezed_annotation: ^2.2.0
json_annotation: ^4.8.0

Expand Down
3 changes: 3 additions & 0 deletions packages/atproto/pubspec_overrides.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependency_overrides:
atproto_core:
path: ../atproto_core
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided the conditions.

import 'package:atproto/src/service/entities/empty.dart';
import 'package:atproto/src/service/entities/record.dart';
import 'package:atproto/src/service/repositories/repositories_service.dart';
// 🌎 Project imports:
import 'package:atproto/src/service/response/atproto_response.dart';
// 📦 Package imports:
import 'package:atproto_core/atproto_core.dart' as core;
import 'package:test/test.dart';

import '../../../mocks/client_context_stubs.dart' as context;
Expand All @@ -31,7 +28,7 @@ void main() {
record: {},
);

expect(response, isA<ATProtoResponse>());
expect(response, isA<core.ATProtoResponse>());
expect(response.data, isA<Record>());
});

Expand Down Expand Up @@ -93,8 +90,8 @@ void main() {
uri: '',
);

expect(response, isA<ATProtoResponse>());
expect(response.data, isA<Empty>());
expect(response, isA<core.ATProtoResponse>());
expect(response.data, isA<core.Empty>());
});

test('when unauthorized', () async {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// Copyright 2022 Kato Shinya. All rights reserved.
// Copyright 2023 Kato Shinya. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided the conditions.

// 🌎 Project imports:
import 'package:atproto/src/service/response/atproto_response.dart';
import 'package:atproto/src/service/sessions/current_session.dart';
import 'package:atproto/src/service/sessions/sessions_service.dart';
// 📦 Package imports:
import 'package:atproto_core/atproto_core.dart' as core;
import 'package:test/test.dart';

import '../../../mocks/client_context_stubs.dart' as context;
Expand All @@ -28,7 +26,7 @@ void main() {

final response = await sessions.lookupCurrentSession();

expect(response, isA<ATProtoResponse>());
expect(response, isA<core.ATProtoResponse>());
expect(response.data, isA<CurrentSession>());
});

Expand Down
10 changes: 10 additions & 0 deletions packages/atproto_core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Release Note

## v0.1.0

- Added core objects. ([#70](https://github.com/myConsciousness/atproto.dart/issues/70))
- `BaseService`
- `Empty`
- `ATProtoResponse`
- `ATProtoRequest`
- `ATProtoException`
- `ForbiddenException`

## v0.0.2

- Exposed `client_context.dart`.
Expand Down
5 changes: 5 additions & 0 deletions packages/atproto_core/lib/atproto_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided the conditions.

export 'package:atproto_core/src/base_service.dart';
export 'package:atproto_core/src/client/client_context.dart';
export 'package:atproto_core/src/client/jitter.dart';
export 'package:atproto_core/src/client/retry_event.dart';
export 'package:atproto_core/src/config/retry_config.dart';
export 'package:atproto_core/src/entities/empty.dart';
export 'package:atproto_core/src/exception/atproto_exception.dart';
export 'package:atproto_core/src/exception/data_not_found_exception.dart';
export 'package:atproto_core/src/exception/forbidden_exception.dart';
export 'package:atproto_core/src/exception/rate_limit_exceeded_exception.dart';
export 'package:atproto_core/src/exception/unauthorized_exception.dart';
export 'package:atproto_core/src/http_method.dart';
export 'package:atproto_core/src/http_status.dart';
export 'package:atproto_core/src/response/atproto_request.dart';
export 'package:atproto_core/src/response/atproto_response.dart';
export 'package:atproto_core/src/serializable.dart';
export 'package:atproto_core/src/service_helper.dart';
export 'package:atproto_core/src/util/json_utils.dart';
Loading

0 comments on commit 14b56e3

Please sign in to comment.