Skip to content

Commit

Permalink
feat(storage): update remove and removeMany APIs (#4593)
Browse files Browse the repository at this point in the history
* chore: update removeMany API

* chore: update remove api, tests

* chore: handle leading slash

* test: update e2e tests

* chore: update sample app

* chore: fix comment

* chore: add doc comment

* chore: update path validation logic

* chore: remove leading `/` from tests

* chore: add `/` back to `StoragePathValidationException` test

* chore: update tests

* chore: remove leading `/`

* chore: update tests
  • Loading branch information
Jordan-Nelson committed Apr 9, 2024
1 parent cf1cd4a commit 92f7ffc
Show file tree
Hide file tree
Showing 26 changed files with 290 additions and 290 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,31 +209,31 @@ class StorageCategory extends AmplifyCategory<StoragePluginInterface> {
}

/// {@template amplify_core.amplify_storage_category.remove}
/// Removes an object specified by [key] with optional [StorageRemoveOptions],
/// Removes an object specified by [path] with optional [StorageRemoveOptions],
/// and returns a [StorageRemoveOperation].
/// {@endtemplate}
StorageRemoveOperation remove({
required String key,
required StoragePath path,
StorageRemoveOptions? options,
}) {
return identifyCall(
StorageCategoryMethod.remove,
() => defaultPlugin.remove(key: key, options: options),
() => defaultPlugin.remove(path: path, options: options),
);
}

/// {@template amplify_core.amplify_storage_category.remove_many}
/// Removes multiple objects specified by [keys] with optional
/// Removes multiple objects specified by [paths] with optional
/// [StorageRemoveManyOptions], and returns a [StorageRemoveManyOperation].
/// {@endtemplate}
StorageRemoveManyOperation removeMany({
required List<String> keys,
required List<StoragePath> paths,
StorageRemoveManyOptions? options,
}) {
return identifyCall(
StorageCategoryMethod.removeMany,
() => defaultPlugin.removeMany(
keys: keys,
paths: paths,
options: options,
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ abstract class StoragePluginInterface extends AmplifyPluginInterface {

/// {@macro amplify_core.amplify_storage_category.remove}
StorageRemoveOperation remove({
required String key,
required StoragePath path,
StorageRemoveOptions? options,
}) {
throw UnimplementedError('remove() has not been implemented.');
}

/// {@macro amplify_core.amplify_storage_category.remove_many}
StorageRemoveManyOperation removeMany({
required List<String> keys,
required List<StoragePath> paths,
StorageRemoveManyOptions? options,
}) {
throw UnimplementedError('removeMany() has not been implemented.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,20 @@ class StorageRemoveManyOptions extends StorageOperationOptions
AWSDebuggable {
/// {@macro amplify_core.storage.remove_many_options}
const StorageRemoveManyOptions({
super.accessLevel,
this.pluginOptions,
});

/// {@macro amplify_core.storage.remove_many_plugin_options}
final StorageRemoveManyPluginOptions? pluginOptions;

@override
List<Object?> get props => [accessLevel, pluginOptions];
List<Object?> get props => [pluginOptions];

@override
String get runtimeTypeName => 'StorageRemoveManyOptions';

@override
Map<String, Object?> toJson() => {
'accessLevel': accessLevel?.name,
'pluginOptions': pluginOptions?.toJson(),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import 'package:amplify_core/amplify_core.dart';
class StorageRemoveManyRequest {
/// {@macro amplify_core.storage.remove_many_request}
const StorageRemoveManyRequest({
required this.keys,
required this.paths,
this.options,
});

/// Object keys to be removed.
final List<String> keys;
final List<StoragePath> paths;

/// Configurable options of the [StorageRemoveManyRequest].
final StorageRemoveManyOptions? options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,20 @@ class StorageRemoveOptions extends StorageOperationOptions
AWSDebuggable {
/// {@macro amplify_core.storage.remove_options}
const StorageRemoveOptions({
super.accessLevel,
this.pluginOptions,
});

/// {@macro amplify_core.storage.remove_plugin_options}
final StorageRemovePluginOptions? pluginOptions;

@override
List<Object?> get props => [accessLevel, pluginOptions];
List<Object?> get props => [pluginOptions];

@override
String get runtimeTypeName => 'StorageRemoveOptions';

@override
Map<String, Object?> toJson() => {
'accessLevel': accessLevel?.name,
'pluginOptions': pluginOptions?.toJson(),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import 'package:amplify_core/amplify_core.dart';
class StorageRemoveRequest {
/// {@macro amplify_core.storage.remove_request}
const StorageRemoveRequest({
required this.key,
required this.path,
this.options,
});

/// The object key to be removed.
final String key;
final StoragePath path;

/// Configurable options of the [StorageRemoveRequest].
final StorageRemoveOptions? options;
Expand Down
4 changes: 2 additions & 2 deletions packages/amplify_core/lib/src/types/storage/storage_path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class StoragePath {
/// ### Example
/// {@template amplify_core.storage.storage_path.from_string.example}
/// ```
/// const p = StoragePath.fromString('/path/to/object.png');
/// const p = StoragePath.fromString('path/to/object.png');
/// ```
/// {@endtemplate}
const StoragePath.fromString(String path) : _path = path;
Expand All @@ -32,7 +32,7 @@ class StoragePath {
/// ### Example
/// {@template amplify_core.storage.storage_path.with_identity_id.example}
/// ```
/// const p = StoragePath.withIdentityId((String identityId) => '/users/$identityId/object.png');
/// const p = StoragePath.withIdentityId((String identityId) => 'users/$identityId/object.png');
/// ```
/// {@endtemplate}
factory StoragePath.withIdentityId(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ void testContentTypeInferTest({
group('content type inferring within upload', () {
tearDownAll(() async {
await Amplify.Storage.removeMany(
keys: testUploadKeys,
options: const StorageRemoveManyOptions(
accessLevel: StorageAccessLevel.private,
),
paths: testUploadKeys
.map(
(key) => StoragePath.withIdentityId(
(identityId) => 'private/$identityId/$key',
),
)
.toList(),
).result;
});

Expand All @@ -54,7 +57,9 @@ void testContentTypeInferTest({
final result = await s3Plugin
.uploadFile(
localFile: file,
path: StoragePath.fromString('/private/${testUploadKeys[index]}'),
path: StoragePath.withIdentityId(
(identityId) => 'private/$identityId/${testUploadKeys[index]}',
),
options: const StorageUploadFileOptions(
pluginOptions: S3UploadFilePluginOptions(
getProperties: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ void testContentTypeInferTest({

tearDownAll(() async {
await Amplify.Storage.removeMany(
keys: testUploadKeys,
options: const StorageRemoveManyOptions(
accessLevel: StorageAccessLevel.private,
),
paths: testUploadKeys
.map(
(key) => StoragePath.withIdentityId(
(identityId) => 'private/$identityId/$key',
),
)
.toList(),
).result;
});

Expand All @@ -51,8 +54,9 @@ void testContentTypeInferTest({
final result = await s3Plugin
.uploadFile(
localFile: file,
path: StoragePath.fromString(
'/private/${testUploadKeys[index]}',
path: StoragePath.withIdentityId(
(identityId) =>
'private/$identityId/${testUploadKeys[index]}',
),
options: const StorageUploadFileOptions(
pluginOptions: S3UploadFilePluginOptions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ void main() {
final key = 'Test - ${DateTime.now()}';
await Amplify.Storage.uploadData(
data: S3DataPayload.bytes('hello'.codeUnits),
path: StoragePath.fromString('/public/$key'),
path: StoragePath.fromString('public/$key'),
).result;

final getUrlResult = await Amplify.Storage.getUrl(
path: StoragePath.fromString('/public/$key'),
path: StoragePath.fromString('public/$key'),
).result;
final uri = getUrlResult.url;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ void testTransferAcceleration({
tearDownAll(() async {
for (final dataPayload in dataPayloads) {
await Amplify.Storage.remove(
key: dataPayload.targetKey,
options:
StorageRemoveOptions(accessLevel: dataPayload.targetAccessLevel),
path: StoragePath.fromString(dataPayload.targetKey),
).result;
}
});
Expand Down Expand Up @@ -94,8 +92,7 @@ void testTransferAcceleration({
tearDownAll(() async {
for (final awsFile in awsFiles) {
await Amplify.Storage.remove(
key: awsFile.targetKey,
options: StorageRemoveOptions(accessLevel: awsFile.targetAccessLevel),
path: StoragePath.fromString(awsFile.targetKey),
).result;
}
});
Expand Down
Loading

0 comments on commit 92f7ffc

Please sign in to comment.