Skip to content

Commit

Permalink
feat: list API init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
khatruong2009 committed Mar 26, 2024
1 parent 62ff206 commit a84864f
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class StorageCategory extends AmplifyCategory<StoragePluginInterface> {
/// returns a [StorageListOperation].
/// {@endtemplate}
StorageListOperation list({
String? path,
required StoragePath path,
StorageListOptions? options,
}) {
return identifyCall(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ abstract class StoragePluginInterface extends AmplifyPluginInterface {

/// {@macro amplify_core.amplify_storage_category.list}
StorageListOperation list({
String? path,
required StoragePath path,
StorageListOptions? options,
}) {
throw UnimplementedError('list() has not been implemented.');
Expand Down
4 changes: 2 additions & 2 deletions packages/amplify_core/lib/src/types/storage/list_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import 'package:amplify_core/amplify_core.dart';
class StorageListRequest {
/// {@macro amplify_core.storage.list_request}
const StorageListRequest({
this.path,
required this.path,
this.options,
});

/// Path to list objects under.
final String? path;
final StoragePath path;

/// Configurable options of the [StorageListRequest].
final StorageListOptions? options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,8 @@ void main() {

// Call list() and ensure length of result matches pageSize.
final listResult = await Amplify.Storage.list(
path: StoragePath.withIdentityId((identityId) => '/private/$identityId/'),
options: const StorageListOptions(
accessLevel: accessLevel,
pageSize: filesToList,
),
).result;
Expand Down Expand Up @@ -749,12 +749,15 @@ void main() {
do {
// Call list() until nextToken is null and ensure we paginated expected times.
final listResult = await Amplify.Storage.list(
path: StoragePath.withIdentityId(
(identityId) => '/private/$identityId/',
),
options: StorageListOptions(
accessLevel: accessLevel,
pageSize: filesToList,
nextToken: lastNextToken,
),
path: keyPrefix,
// path: keyPrefix,
).result;
lastNextToken = listResult.nextToken;
timesCalled++;
Expand All @@ -774,9 +777,10 @@ void main() {
'remove many objects belongs to the currently signed user',
(WidgetTester tester) async {
final listedObjects = await Amplify.Storage.list(
options: const StorageListOptions(
accessLevel: StorageAccessLevel.private,
path: StoragePath.withIdentityId(
(identityId) => '/private/$identityId/',
),
options: const StorageListOptions(),
).result;
expect(listedObjects.items, hasLength(2));

Expand Down Expand Up @@ -814,9 +818,10 @@ void main() {
'remove many objects belongs to the currently signed user',
(WidgetTester tester) async {
final listedObjects = await Amplify.Storage.list(
options: const StorageListOptions(
accessLevel: StorageAccessLevel.private,
path: StoragePath.withIdentityId(
(identityId) => '/private/$identityId/',
),
options: const StorageListOptions(),
).result;
expect(listedObjects.items, hasLength(2));

Expand Down
2 changes: 1 addition & 1 deletion packages/storage/amplify_storage_s3/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ class _HomeScreenState extends State<HomeScreen> {
Future<void> _listAllPublicFiles() async {
try {
final result = await Amplify.Storage.list(
path: const StoragePath.fromString('/public'),
options: const StorageListOptions(
accessLevel: StorageAccessLevel.guest,
pluginOptions: S3ListPluginOptions.listAll(),
),
).result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Future<void> listOperation() async {
pageSize: pageSize,
);
final operation = s3Plugin.list(
path: path,
path: StoragePath.fromString(path),
options: options,
);

Expand Down Expand Up @@ -133,7 +133,7 @@ Future<void> listOperation() async {

result = await s3Plugin
.list(
path: path,
path: StoragePath.fromString(path),
options: StorageListOptions(
accessLevel: accessLevel,
pageSize: pageSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,14 @@ class AmplifyStorageS3Dart extends StoragePluginInterface

@override
S3ListOperation list({
String? path,
required StoragePath path,
StorageListOptions? options,
}) {
final s3PluginOptions = reifyPluginOptions(
pluginOptions: options?.pluginOptions,
defaultPluginOptions: const S3ListPluginOptions(),
);
final s3Options = StorageListOptions(
accessLevel: options?.accessLevel,
pluginOptions: s3PluginOptions,
nextToken: options?.nextToken,
pageSize: options?.pageSize ?? 1000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class StorageS3Service {
/// service returned [smithy.UnknownSmithyHttpException] if any.
/// {@endtemplate}
Future<S3ListResult> list({
String? path,
required StoragePath path,
required StorageListOptions options,
}) async {
final s3PluginOptions = options.pluginOptions as S3ListPluginOptions? ??
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void main() {
});

group('list()', () {
const testPath = 'some/path';
const testPath = StoragePath.fromString('/some/path');
final testResult = S3ListResult(
<S3Item>[],
hasNextPage: false,
Expand Down Expand Up @@ -189,7 +189,6 @@ void main() {

test('should forward options to StorageS3Service.list() API', () async {
const testOptions = StorageListOptions(
accessLevel: testAccessLevelProtected,
pluginOptions: S3ListPluginOptions(excludeSubPaths: true),
nextToken: 'next-token-123',
pageSize: 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void main() {
//StorageListOption<>(S3ListOptions.forIdentity('throw exception for me');

await expectLater(
storageS3Service.list(path: 'a path', options: testOptions),
storageS3Service.list(path: const StoragePath.fromString('/a path'), options: testOptions),
throwsA(isA<StorageException>()),
);

Expand Down Expand Up @@ -133,7 +133,7 @@ void main() {
),
)
.toList();
const testPath = 'album';
const testPath = StoragePath.fromString('/album');
const testTargetIdentityId = 'someone-else-id';
const testOptions = StorageListOptions(
pageSize: testPageSize,
Expand Down Expand Up @@ -211,7 +211,7 @@ void main() {
),
)
.toList();
const testPath = 'album';
const testPath = StoragePath.fromString('album');
const testOptions = StorageListOptions(
accessLevel: testStorageAccessLevel,
pageSize: testPageSize,
Expand Down Expand Up @@ -278,7 +278,7 @@ void main() {

expect(
storageS3Service.list(
path: 'a path',
path: const StoragePath.fromString('apath'),
options: testOptions,
),
throwsA(isA<StorageAccessDeniedException>()),
Expand All @@ -297,7 +297,7 @@ void main() {
),
)
.toList();
const testPath = 'album';
const testPath = StoragePath.fromString('album');
const testOptions = StorageListOptions(
accessLevel: StorageAccessLevel.private,
pageSize: testPageSize,
Expand Down Expand Up @@ -407,7 +407,7 @@ void main() {

expect(
storageS3Service.list(
path: 'a path',
path: const StoragePath.fromString('apath'),
options: testOptions,
),
throwsA(isA<NetworkException>()),
Expand Down

0 comments on commit a84864f

Please sign in to comment.