Skip to content

Deprecated: feat(storage): add delimiter support to list API #5110

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

Closed
wants to merge 4 commits into from
Closed
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 @@ -16,8 +16,11 @@ class StorageListOptions
this.pageSize = 1000,
this.nextToken,
this.pluginOptions,
// this.subpathStrategy,
});

// final SubpathStrategy subpathStrategy;

/// The number of object to be listed in each page.
final int pageSize;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:amplify_core/amplify_core.dart';
class StorageListResult<Item extends StorageItem> {
/// {@macro amplify_core.storage.list_result}
const StorageListResult(
// this.excludedSubpaths,
this.items, {
required this.hasNextPage,
this.nextToken,
Expand All @@ -17,6 +18,8 @@ class StorageListResult<Item extends StorageItem> {
/// The objects listed in the current page.
final List<Item> items;

// final List<String> excludedSubpaths;

/// Whether has next page that can be listed using [nextToken].
final bool hasNextPage;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// // SPDX-License-Identifier: Apache-2.0
//
// import 'package:amplify_core/amplify_core.dart';
//
// /// {@template amplify_core.storage.subpath_strategy}
// /// Presents ..
// /// {@endtemplate}
// class SubpathStrategy {
// /// {@macro amplify_core.storage.subpath_strategy}
// const SubpathStrategy({
// required this.path,
// this.options,
// });
//
// /// ..
// final StoragePath path;
//
// /// ..
// final StorageListOptions? options;
// }
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ void main() {
});

group('list() with options', () {
group('excluding sub paths', () {
group(
'@Deprecated for StorageListOptions.subpathStrategy, excluding sub paths with excludeSubPaths & delimiter',
() {
testWidgets('default delimiter', (_) async {
final listResult = await Amplify.Storage.list(
path: StoragePath.fromString('$uniquePrefix/'),
Expand Down Expand Up @@ -113,6 +115,44 @@ void main() {
});
});

group('excluding sub paths with StorageListOptions.subpathStrategy',
() {
// testWidgets('default delimiter', (_) async {
// final listResult = await Amplify.Storage.list(
// path: StoragePath.fromString('$uniquePrefix/'),
// options: const StorageListOptions(
// subpaths: Subpaths.exclude(delimiter: "-"),
// ),
// ).result as S3ListResult;
//
// expect(listResult.items.length, 3);
// expect(listResult.items.first.path, contains('file1.txt'));
//
// expect(listResult.metadata.subPaths.length, 1);
// expect(listResult.metadata.subPaths.first, '$uniquePrefix/subdir/');
// expect(listResult.metadata.delimiter, '/');
// });
//
// testWidgets('custom delimiter', (_) async {
// final listResult = await Amplify.Storage.list(
// path: StoragePath.fromString('$uniquePrefix/'),
// options: const StorageListOptions(
// subpaths: Subpaths.exclude(delimiter: "-"),
// ),
// ).result as S3ListResult;
//
// expect(listResult.items.length, 3);
// expect(listResult.items.first.path, contains('file1.txt'));
//
// expect(listResult.metadata.subPaths.length, 1);
// expect(
// listResult.metadata.subPaths.first,
// '$uniquePrefix/subdir2#',
// );
// expect(listResult.metadata.delimiter, '-');
// });
});

testWidgets('should respect pageSize limitation', (_) async {
final listResult = await Amplify.Storage.list(
path: StoragePath.fromString(uniquePrefix),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ class S3ListPluginOptions extends StorageListPluginOptions {

/// Whether to exclude objects under the sub paths of the path to list. The
/// default value is `false`.
// @Deprecated('use StorageListOptions.subpathStrategy instead')
final bool excludeSubPaths;

/// The delimiter to use when evaluating sub paths. If [excludeSubPaths] is
/// false, this value has no impact on behavior.
// @Deprecated('use StorageListOptions.subpathStrategy instead')
final String delimiter;

/// Whether to list all objects under a given path without pagination. The
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class S3ListResult extends StorageListResult<S3Item> {
}

/// The metadata returned from the Storage S3 plugin `list` API.
// @Deprecated('use StorageListResult.excludedSubpaths instead')
class S3ListMetadata {
/// Creates a S3ListMetadata from the `commonPrefix` and `delimiter`
/// properties of the [s3.ListObjectsV2Output].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void main() {
});

test(
'should attach delimiter to the ListObjectV2Request when options excludeSubPaths is set to true',
'Deprecated for StorageListOptions.subpathStrategy, should attach delimiter to the ListObjectV2Request when options excludeSubPaths is set to true',
() async {
final testS3Objects = [1, 2, 3, 4, 5]
.map(
Expand Down Expand Up @@ -213,6 +213,67 @@ void main() {
expect(result.metadata.subPaths, equals(testSubPaths));
});

test(
'StorageListOptions.subpathStrategy, should attach delimiter to the ListObjectV2Request when StorageListOptions.subpathStrategy.exclude() is called',
() async {
// final testS3Objects = [1, 2, 3, 4, 5]
// .map(
// (e) => S3Object(
// key: '${testPrefix}object-$e',
// size: Int64(100 * 4),
// eTag: 'object-$e-eTag',
// ),
// )
// .toList();
// const testPath = StoragePath.fromString('album');
// const testOptions = StorageListOptions(
// pageSize: testPageSize,
// pluginOptions: S3ListPluginOptions(excludeSubPaths: true),
// );
// const testSubPaths = [
// 'album#folder1',
// 'album#folder2',
// 'album#folder1#sub-folder1',
// ];
// final testPaginatedResult =
// PaginatedResult<ListObjectsV2Output, int, String>(
// ListObjectsV2Output(
// contents: testS3Objects,
// commonPrefixes: [
// CommonPrefix(prefix: testSubPaths[0]),
// CommonPrefix(prefix: testSubPaths[1]),
// CommonPrefix(
// prefix: testSubPaths[2],
// ),
// ],
// delimiter: testDelimiter,
// name: testBucketName,
// maxKeys: testPageSize,
// ),
// next: ([int? pageSize]) {
// throw UnimplementedError();
// },
// nextContinuationToken: testNextContinuationToken,
// );
// final smithyOperation = MockSmithyOperation<
// PaginatedResult<ListObjectsV2Output, int, String>>();
//
// when(
// () => smithyOperation.result,
// ).thenAnswer((_) async => testPaginatedResult);
//
// when(
// () => s3Client.listObjectsV2(any()),
// ).thenAnswer((_) => smithyOperation);
//
// final result = await storageS3Service.list(
// path: testPath,
// options: testOptions,
// );
//
// expect(result.metadata.subPaths, equals(testSubPaths));
});

test(
'should throw StorageAccessDeniedException when UnknownSmithyHttpException'
' with status code 403 returned from service', () async {
Expand Down
Loading