Skip to content

Commit

Permalink
Merge pull request #1218 from myConsciousness/1217-feature-request-ex…
Browse files Browse the repository at this point in the history
…pose-get-and-post-methods

💡 feat: add `.get` and `.post` methods (#1217)
  • Loading branch information
myConsciousness committed Jan 27, 2024
2 parents 88efcea + 6ee7fa6 commit e54f912
Show file tree
Hide file tree
Showing 38 changed files with 294 additions and 116 deletions.
5 changes: 5 additions & 0 deletions packages/atproto/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Note

## v0.11.3

- Added `.get` and `.post` methods on `ATProto` object. ([#1217](https://github.com/myConsciousness/atproto.dart/issues/1217))
- Added `atproto/lex_namespaces` package. You can use these constants for `.get` and `.post` methods.

## v0.11.2

- Upgraded `atproto_core`. ([#1159](https://github.com/myConsciousness/atproto.dart/issues/1159))
Expand Down
2 changes: 2 additions & 0 deletions packages/atproto/lib/atproto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export 'package:atproto_core/atproto_core.dart'
HttpStatus,
Serializable,
Platform,
ResponseDataBuilder,
ResponseDataAdaptor,
NSID,
AtUri,
CID,
Expand Down
5 changes: 5 additions & 0 deletions packages/atproto/lib/lex_namespaces.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright 2024 Shinya Kato. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided the conditions.

export 'package:atproto/src/nsids.g.dart';
74 changes: 73 additions & 1 deletion packages/atproto/lib/src/atproto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,45 @@ sealed class ATProto {
/// Returns the labels service.
/// This service represents `com.atproto.label.*`.
LabelService get label;

/// Returns the result of executing [methodId] as GET communication.
///
/// You can specify `Map<String, dynamic>`, `Uint8List`, or `EmptyData` as
/// generics. If a [to] parameter is specified to convert the response body
/// to a specific object, the generics need not be specified.
///
/// - [methodId]: name of method to execute in XRPC.
/// - [headers]: optional header information to be added to the request.
/// - [parameters]: arguments passed to [methodId].
/// - [to]: optional builder to convert the body of the response to a specific
/// object.
/// - [adaptor]: optional adapters to convert response bodies to a specific
/// structure.
Future<core.XRPCResponse<T>> get<T>(
final core.NSID methodId, {
final Map<String, String>? headers,
final Map<String, dynamic>? parameters,
final core.ResponseDataBuilder<T>? to,
final core.ResponseDataAdaptor? adaptor,
});

/// Returns the result of executing [methodId] as POST communication.
///
/// You can specify `Map<String, dynamic>`, `Uint8List`, or `EmptyData` as
/// generics. If a [to] parameter is specified to convert the response body
/// to a specific object, the generics need not be specified.
///
/// - [methodId]: name of method to execute in XRPC.
/// - [headers]: optional header information to be added to the request.
/// - [body]: data passed to [methodId].
/// - [to]: optional builder to convert the body of the response to a specific
/// object.
Future<core.XRPCResponse<T>> post<T>(
final core.NSID methodId, {
final Map<String, String>? headers,
final dynamic body,
final core.ResponseDataBuilder<T>? to,
});
}

final class _ATProto implements ATProto {
Expand All @@ -120,7 +159,8 @@ final class _ATProto implements ATProto {
repo = RepoService(ctx),
moderation = ModerationService(ctx),
sync = SyncService(ctx),
label = LabelService(ctx);
label = LabelService(ctx),
_ctx = ctx;

@override
final core.Session? session;
Expand Down Expand Up @@ -154,4 +194,36 @@ final class _ATProto implements ATProto {

@override
LabelService get labels => label;

final core.ServiceContext _ctx;

@override
Future<core.XRPCResponse<T>> get<T>(
final core.NSID methodId, {
final Map<String, String>? headers,
final Map<String, dynamic>? parameters,
final core.ResponseDataBuilder<T>? to,
final core.ResponseDataAdaptor? adaptor,
}) async =>
await _ctx.get(
methodId,
headers: headers,
parameters: parameters,
to: to,
adaptor: adaptor,
);

@override
Future<core.XRPCResponse<T>> post<T>(
final core.NSID methodId, {
final Map<String, String>? headers,
final dynamic body,
final core.ResponseDataBuilder<T>? to,
}) async =>
await _ctx.post(
methodId,
headers: headers,
body: body,
to: to,
);
}
2 changes: 1 addition & 1 deletion packages/atproto/lib/src/services/identity_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ final class IdentityService {

Future<core.XRPCResponse<T>> _findDID<T>({
required String handle,
core.To<T>? to,
core.ResponseDataBuilder<T>? to,
}) async =>
await _ctx.get(
ns.comAtprotoIdentityResolveHandle,
Expand Down
6 changes: 3 additions & 3 deletions packages/atproto/lib/src/services/repo_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ final class RepoService {
Future<core.XRPCResponse<T>> _findRecord<T>({
required core.AtUri uri,
required String? cid,
core.To<T>? to,
core.ResponseDataBuilder<T>? to,
}) async =>
await _ctx.get<T>(
ns.comAtprotoRepoGetRecord,
Expand All @@ -294,7 +294,7 @@ final class RepoService {
required String? rkeyStart,
required String? rkeyEnd,
required String? cursor,
core.To<T>? to,
core.ResponseDataBuilder<T>? to,
}) async =>
await _ctx.get(
ns.comAtprotoRepoListRecords,
Expand All @@ -312,7 +312,7 @@ final class RepoService {

Future<core.XRPCResponse<T>> _findRepoInfo<T>({
required String repo,
core.To<T>? to,
core.ResponseDataBuilder<T>? to,
}) async =>
await _ctx.get(
ns.comAtprotoRepoDescribeRepo,
Expand Down
8 changes: 4 additions & 4 deletions packages/atproto/lib/src/services/server_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ final class ServerService {
);

Future<core.XRPCResponse<T>> _findCurrentSession<T>({
core.To<T>? to,
core.ResponseDataBuilder<T>? to,
}) async =>
await _ctx.get(
ns.comAtprotoServerGetSession,
Expand All @@ -273,7 +273,7 @@ final class ServerService {
Future<core.XRPCResponse<T>> _findInviteCodes<T>({
required bool? includeUsed,
required bool? createAvailable,
core.To<T>? to,
core.ResponseDataBuilder<T>? to,
}) async =>
await _ctx.get(
ns.comAtprotoServerGetAccountInviteCodes,
Expand All @@ -285,15 +285,15 @@ final class ServerService {
);

Future<core.XRPCResponse<T>> _findAppPasswords<T>({
core.To<T>? to,
core.ResponseDataBuilder<T>? to,
}) async =>
await _ctx.get(
ns.comAtprotoServerListAppPasswords,
to: to,
);

Future<core.XRPCResponse<T>> _findServerInfo<T>({
core.To<T>? to,
core.ResponseDataBuilder<T>? to,
}) async =>
await _ctx.get(
ns.comAtprotoServerDescribeServer,
Expand Down
12 changes: 6 additions & 6 deletions packages/atproto/lib/src/services/sync_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ final class SyncService {
required String did,
required String? sinceCommitCid,
required core.ProgressStatus? progress,
core.To<T>? to,
core.ResponseDataBuilder<T>? to,
}) async =>
await _ctx.get(
ns.comAtprotoSyncGetRepo,
Expand All @@ -261,7 +261,7 @@ final class SyncService {
Future<core.XRPCResponse<T>> _findRepoBlocks<T>({
required String did,
required List<String> commitCids,
core.To<T>? to,
core.ResponseDataBuilder<T>? to,
}) async =>
await _ctx.get(
ns.comAtprotoSyncGetBlocks,
Expand All @@ -275,7 +275,7 @@ final class SyncService {

Future<core.XRPCResponse<T>> _findLatestCommit<T>({
required String did,
core.To<T>? to,
core.ResponseDataBuilder<T>? to,
}) async =>
await _ctx.get(
ns.comAtprotoSyncGetLatestCommit,
Expand All @@ -288,7 +288,7 @@ final class SyncService {
Future<core.XRPCResponse<T>> _findRecord<T>({
required core.AtUri uri,
required String? commitCid,
core.To<T>? to,
core.ResponseDataBuilder<T>? to,
}) async =>
await _ctx.get(
ns.comAtprotoSyncGetRecord,
Expand All @@ -305,7 +305,7 @@ final class SyncService {
Future<core.XRPCResponse<T>> _findRepos<T>({
required int? limit,
required String? cursor,
core.To<T>? to,
core.ResponseDataBuilder<T>? to,
}) async =>
await _ctx.get(
ns.comAtprotoSyncListRepos,
Expand All @@ -321,7 +321,7 @@ final class SyncService {
required String? sinceCid,
required int? limit,
required String? cursor,
core.To<T>? to,
core.ResponseDataBuilder<T>? to,
}) async =>
await _ctx.get(
ns.comAtprotoSyncListBlobs,
Expand Down
4 changes: 2 additions & 2 deletions packages/atproto/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: atproto
description: The most famous and powerful Dart/Flutter library for AT Protocol.
version: 0.11.2
version: 0.11.3
homepage: https://atprotodart.com
documentation: https://atprotodart.com/docs/packages/atproto
repository: https://github.com/myConsciousness/atproto.dart/tree/main/packages/atproto
Expand All @@ -17,7 +17,7 @@ topics:
- api

dependencies:
atproto_core: ^0.9.2
atproto_core: ^0.9.3
freezed_annotation: ^2.4.1
json_annotation: ^4.8.1
lex_annotation: ^0.0.1
Expand Down
5 changes: 5 additions & 0 deletions packages/atproto_core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Note

## v0.9.3

- Upgrade dependencies. ([#1217](https://github.com/myConsciousness/atproto.dart/issues/1217))
- Added `headers` parameter for `.get` method on `ServiceContext`.

## v0.9.2

- Upgrade dependencies. ([#1159](https://github.com/myConsciousness/atproto.dart/issues/1159))
Expand Down
3 changes: 2 additions & 1 deletion packages/atproto_core/lib/atproto_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export 'package:xrpc/xrpc.dart'
RateLimitPolicy,
Subscription,
Protocol,
To,
ResponseDataBuilder,
ResponseDataAdaptor,
NSID,
EmptyData,
HttpMethod,
Expand Down
6 changes: 3 additions & 3 deletions packages/atproto_core/lib/src/base_http_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ base class BaseHttpService {
Future<http.Response<T>> get<T>(
final String unencodedPath, {
final Map<String, dynamic>? parameters,
final http.To<T>? to,
final http.ResponseAdaptor? adaptor,
final http.ResponseDataBuilder<T>? to,
final http.ResponseDataAdaptor? adaptor,
}) async =>
await http.get(
unencodedPath,
Expand All @@ -49,7 +49,7 @@ base class BaseHttpService {
final String unencodedPath, {
final Map<String, String>? headers,
final dynamic body,
final http.To<T>? to,
final http.ResponseDataBuilder<T>? to,
}) async =>
await http.post(
unencodedPath,
Expand Down
15 changes: 8 additions & 7 deletions packages/atproto_core/lib/src/clients/service_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,17 @@ base class ServiceContext {

Future<xrpc.XRPCResponse<T>> get<T>(
final xrpc.NSID methodId, {
final Map<String, String>? headers,
final Map<String, dynamic>? parameters,
final xrpc.To<T>? to,
final xrpc.ResponseAdaptor? adaptor,
final xrpc.ResponseDataBuilder<T>? to,
final xrpc.ResponseDataAdaptor? adaptor,
}) async =>
await _challenge.execute(
() async => await xrpc.query(
methodId,
protocol: _protocol,
service: _service,
headers: _getHeaders(),
headers: _getHeaders(headers),
parameters: parameters,
to: to,
adaptor: adaptor,
Expand All @@ -75,7 +76,7 @@ base class ServiceContext {
final xrpc.NSID methodId, {
final Map<String, String>? headers,
final dynamic body,
final xrpc.To<T>? to,
final xrpc.ResponseDataBuilder<T>? to,
}) async =>
await _challenge.execute(
() async => await xrpc.procedure(
Expand All @@ -94,7 +95,7 @@ base class ServiceContext {
final xrpc.NSID methodId,
final Uint8List bytes, {
final Map<String, String>? headers,
final xrpc.To<T>? to,
final xrpc.ResponseDataBuilder<T>? to,
}) async =>
await _challenge.execute(
() async => await xrpc.upload(
Expand All @@ -112,8 +113,8 @@ base class ServiceContext {
Future<xrpc.XRPCResponse<xrpc.Subscription<T>>> stream<T>(
final xrpc.NSID methodId, {
final Map<String, dynamic>? parameters,
final xrpc.To<T>? to,
final xrpc.ResponseAdaptor? adaptor,
final xrpc.ResponseDataBuilder<T>? to,
final xrpc.ResponseDataAdaptor? adaptor,
}) async =>
await _challenge.execute(
() => xrpc.subscribe(
Expand Down
4 changes: 2 additions & 2 deletions packages/atproto_core/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: atproto_core
description: Core library for clients and tools. This package is mainly used by https://atprotodart.com packages.
version: 0.9.2
version: 0.9.3
homepage: https://atprotodart.com
documentation: https://atprotodart.com/docs/intro
repository: https://github.com/myConsciousness/atproto.dart/tree/main/packages/atproto_core
Expand All @@ -18,7 +18,7 @@ topics:
- core

dependencies:
xrpc: ^0.4.5
xrpc: ^0.5.0
at_uri: ^0.3.0
freezed_annotation: ^2.4.1
json_annotation: ^4.8.1
Expand Down
5 changes: 5 additions & 0 deletions packages/bluesky/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Note

## v0.15.5

- Added `.get` and `.post` methods on `Bluesky` object. ([#1217](https://github.com/myConsciousness/atproto.dart/issues/1217))
- Added `bluesky/lex_namespaces` package. You can use these constants for `.get` and `.post` methods.

## v0.15.4

- Upgraded `atproto_core`. ([#1159](https://github.com/myConsciousness/atproto.dart/issues/1159))
Expand Down
2 changes: 2 additions & 0 deletions packages/bluesky/lib/bluesky.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ export 'package:atproto_core/atproto_core.dart'
HttpStatus,
Serializable,
Platform,
ResponseDataBuilder,
ResponseDataAdaptor,
AtUri,
NSID,
CID,
Expand Down
6 changes: 6 additions & 0 deletions packages/bluesky/lib/lex_namespaces.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright 2024 Shinya Kato. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided the conditions.

export 'package:atproto/lex_namespaces.dart';
export 'package:bluesky/src/nsids.g.dart';
Loading

0 comments on commit e54f912

Please sign in to comment.