Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add storage bucket type #5478

Merged
merged 1 commit into from
Sep 20, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ part 'network_exception.dart';
part 'push/push_notification_exception.dart';
part 'storage/access_denied_exception.dart';
part 'storage/http_status_exception.dart';
part 'storage/invalid_storage_bucket_exception.dart';
part 'storage/local_file_not_found_exception.dart';
part 'storage/not_found_exception.dart';
part 'storage/operation_canceled_exception.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
part of '../amplify_exception.dart';

/// {@template amplify_core.storage.invalid_storage_bucket_exception}
/// Exception thrown when the [StorageBucket] is invalid.
/// {@endtemplate}
class InvalidStorageBucketException extends StorageException {
const InvalidStorageBucketException(
super.message, {
super.recoverySuggestion,
super.underlyingException,
});

@override
String get runtimeTypeName => 'InvalidStorageBucketException';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// {@template amplify_core.storage.bucket_info}
/// Presents a storage bucket information.
/// {@endtemplate}
class BucketInfo {
/// {@macro amplify_core.storage.bucket_info}
const BucketInfo({required this.bucketName, required this.region});
final String bucketName;
final String region;
}
19 changes: 19 additions & 0 deletions packages/amplify_core/lib/src/types/storage/storage_bucket.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:amplify_core/src/config/amplify_outputs/storage/storage_outputs.dart';
import 'package:amplify_core/src/types/storage/bucket_info.dart';
import 'package:amplify_core/src/types/storage/storage_bucket_from_outputs.dart';
import 'package:meta/meta.dart';

/// Presents a storage bucket.
class StorageBucket {
/// Creates a [StorageBucket] from [BucketInfo].
const StorageBucket.fromBucketInfo(this._info);

/// Creates a [StorageBucket] defined by the [name] in AmplifyOutputs file.
factory StorageBucket.fromOutputs(String name) =>
StorageBucketFromOutputs(name);

final BucketInfo _info;

@internal
BucketInfo resolveBucketInfo(StorageOutputs? storageOutputs) => _info;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:amplify_core/amplify_core.dart';
import 'package:amplify_core/src/config/amplify_outputs/storage/storage_outputs.dart';
import 'package:meta/meta.dart';

/// {@template amplify_core.storage.storage_bucket_from_outputs}
/// Creates a [StorageBucket] defined by the name in AmplifyOutputs file.
/// {@endtemplate}
@internal
class StorageBucketFromOutputs implements StorageBucket {
/// {@macro amplify_core.storage.storage_bucket_from_outputs}
const StorageBucketFromOutputs(this._name);

final String _name;

@override
BucketInfo resolveBucketInfo(StorageOutputs? storageOutputs) {
assert(
storageOutputs != null,
const InvalidStorageBucketException(
'Amplify Storage is not configured.',
recoverySuggestion:
'Make sure storage exists in the Amplify Outputs file.',
),
);
// TODO(nikahsn): fix after adding buckets to StorageOutputs.
return BucketInfo(
bucketName: _name,
region: storageOutputs!.awsRegion,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export '../exception/amplify_exception.dart'
StorageOperationCanceledException,
NetworkException,
UnknownException;
export 'bucket_info.dart';
export 'copy_operation.dart';
export 'copy_options.dart';
export 'copy_request.dart';
Expand Down Expand Up @@ -44,6 +45,7 @@ export 'remove_operation.dart';
export 'remove_options.dart';
export 'remove_request.dart';
export 'remove_result.dart';
export 'storage_bucket.dart';
export 'storage_item.dart';
export 'storage_path.dart';
export 'transfer_progress.dart';
Expand Down
Loading