Skip to content

Commit 1119a4b

Browse files
feat(storage)!: move delimiter to S3ListPluginOptions (#4773)
* chore: move delimiter to `S3ListPluginOptions` * chore: regenerate files
1 parent ad7f868 commit 1119a4b

File tree

6 files changed

+57
-29
lines changed

6 files changed

+57
-29
lines changed

packages/storage/amplify_storage_s3/example/integration_test/list_test.dart

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ void main() {
1919
'$uniquePrefix/file1.txt',
2020
'$uniquePrefix/file2.txt',
2121
'$uniquePrefix/subdir/file3.txt',
22+
'$uniquePrefix/subdir2#file4.txt',
2223
];
2324
group('standard config', () {
2425
setUpAll(() async {
@@ -70,20 +71,46 @@ void main() {
7071
});
7172

7273
group('list() with options', () {
73-
testWidgets(
74-
'should list all files with unique prefix excluding subPaths',
75-
(_) async {
76-
final listResult = await Amplify.Storage.list(
77-
path: StoragePath.fromString('$uniquePrefix/'),
78-
options: const StorageListOptions(
79-
pluginOptions: S3ListPluginOptions(
80-
excludeSubPaths: true,
74+
group('excluding sub paths', () {
75+
testWidgets('default delimiter', (_) async {
76+
final listResult = await Amplify.Storage.list(
77+
path: StoragePath.fromString('$uniquePrefix/'),
78+
options: const StorageListOptions(
79+
pluginOptions: S3ListPluginOptions(
80+
excludeSubPaths: true,
81+
),
8182
),
82-
),
83-
).result;
83+
).result as S3ListResult;
84+
85+
expect(listResult.items.length, 3);
86+
expect(listResult.items.first.path, contains('file1.txt'));
87+
88+
expect(listResult.metadata.subPaths.length, 1);
89+
expect(listResult.metadata.subPaths.first, '$uniquePrefix/subdir/');
90+
expect(listResult.metadata.delimiter, '/');
91+
});
92+
93+
testWidgets('custom delimiter', (_) async {
94+
final listResult = await Amplify.Storage.list(
95+
path: StoragePath.fromString('$uniquePrefix/'),
96+
options: const StorageListOptions(
97+
pluginOptions: S3ListPluginOptions(
98+
excludeSubPaths: true,
99+
delimiter: '#',
100+
),
101+
),
102+
).result as S3ListResult;
84103

85-
expect(listResult.items.length, 2);
86-
expect(listResult.items.first.path, contains('file1.txt'));
104+
expect(listResult.items.length, 3);
105+
expect(listResult.items.first.path, contains('file1.txt'));
106+
107+
expect(listResult.metadata.subPaths.length, 1);
108+
expect(
109+
listResult.metadata.subPaths.first,
110+
'$uniquePrefix/subdir2#',
111+
);
112+
expect(listResult.metadata.delimiter, '#');
113+
});
87114
});
88115

89116
testWidgets('should respect pageSize limitation', (_) async {
@@ -130,7 +157,7 @@ void main() {
130157
),
131158
).result;
132159

133-
expect(listResult.items.length, 3);
160+
expect(listResult.items.length, uploadedPaths.length);
134161
expect(listResult.nextToken, isNull);
135162
});
136163
});

packages/storage/amplify_storage_s3/lib/src/amplify_storage_s3_impl.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ import 'package:amplify_storage_s3_dart/amplify_storage_s3_dart.dart';
1212
/// {@endtemplate}
1313
class AmplifyStorageS3 extends AmplifyStorageS3Dart {
1414
/// {@macro amplify_storage_s3_.amplify_storage_s3_plugin}
15-
AmplifyStorageS3({
16-
super.delimiter,
17-
});
15+
AmplifyStorageS3();
1816

1917
/// A plugin key which can be used with `Amplify.Storage.getPlugin` to retrieve
2018
/// a S3-specific Storage category interface.

packages/storage/amplify_storage_s3_dart/lib/src/amplify_storage_s3_dart_impl.dart

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ class AmplifyStorageS3Dart extends StoragePluginInterface
3030
with AWSDebuggable, AWSLoggerMixin {
3131
/// {@macro amplify_storage_s3_dart.amplify_storage_s3_plugin_dart}
3232
AmplifyStorageS3Dart({
33-
String? delimiter,
3433
@visibleForTesting DependencyManager? dependencyManagerOverride,
35-
}) : _delimiter = delimiter,
36-
_dependencyManagerOverride = dependencyManagerOverride;
34+
}) : _dependencyManagerOverride = dependencyManagerOverride;
3735

3836
/// {@template amplify_storage_s3_dart.plugin_key}
3937
/// A plugin key which can be used with `Amplify.Storage.getPlugin` to retrieve
@@ -42,8 +40,6 @@ class AmplifyStorageS3Dart extends StoragePluginInterface
4240
static const StoragePluginKey<AmplifyStorageS3Dart> pluginKey =
4341
_AmplifyStorageS3DartPluginKey();
4442

45-
final String? _delimiter;
46-
4743
final DependencyManager? _dependencyManagerOverride;
4844

4945
@override
@@ -112,7 +108,6 @@ class AmplifyStorageS3Dart extends StoragePluginInterface
112108
StorageS3Service(
113109
credentialsProvider: credentialsProvider,
114110
s3PluginConfig: s3PluginConfig,
115-
delimiter: _delimiter,
116111
pathResolver: _pathResolver,
117112
logger: logger,
118113
dependencyManager: dependencies,

packages/storage/amplify_storage_s3_dart/lib/src/model/s3_list_plugin_options.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ class S3ListPluginOptions extends StorageListPluginOptions {
1313
/// {@macro storage.amplify_storage_s3.list_plugin_options}
1414
const S3ListPluginOptions({
1515
bool excludeSubPaths = false,
16+
String delimiter = '/',
1617
}) : this._(
1718
excludeSubPaths: excludeSubPaths,
19+
delimiter: delimiter,
1820
);
1921

2022
const S3ListPluginOptions._({
2123
this.excludeSubPaths = false,
24+
this.delimiter = '/',
2225
this.listAll = false,
2326
});
2427

@@ -40,6 +43,10 @@ class S3ListPluginOptions extends StorageListPluginOptions {
4043
/// default value is `false`.
4144
final bool excludeSubPaths;
4245

46+
/// The delimiter to use when evaluating sub paths. If [excludeSubPaths] is
47+
/// false, this value has no impact on behavior.
48+
final String delimiter;
49+
4350
/// Whether to list all objects under a given path without pagination. The
4451
/// default value is `false`.
4552
///

packages/storage/amplify_storage_s3_dart/lib/src/model/s3_list_plugin_options.g.dart

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/storage/amplify_storage_s3_dart/lib/src/storage_s3_service/service/storage_s3_service_impl.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class StorageS3Service {
3636
required AWSIamAmplifyAuthProvider credentialsProvider,
3737
required AWSLogger logger,
3838
required DependencyManager dependencyManager,
39-
String? delimiter,
4039
}) {
4140
final usePathStyle = s3PluginConfig.bucket.contains('.');
4241

@@ -61,7 +60,6 @@ class StorageS3Service {
6160
credentialsProvider: credentialsProvider,
6261
logger: logger,
6362
dependencyManager: dependencyManager,
64-
delimiter: delimiter,
6563
);
6664
}
6765

@@ -72,9 +70,7 @@ class StorageS3Service {
7270
required AWSIamAmplifyAuthProvider credentialsProvider,
7371
required AWSLogger logger,
7472
required DependencyManager dependencyManager,
75-
String? delimiter,
7673
}) : _s3PluginConfig = s3PluginConfig,
77-
_delimiter = delimiter ?? '/',
7874
_defaultS3ClientConfig = s3ClientConfig,
7975
// dependencyManager.get() => S3Client is used for unit tests
8076
_defaultS3Client = dependencyManager.get() ??
@@ -99,7 +95,6 @@ class StorageS3Service {
9995
sigv4.S3ServiceConfiguration(signPayload: false);
10096

10197
final S3PluginConfig _s3PluginConfig;
102-
final String _delimiter;
10398
final smithy_aws.S3ClientConfig _defaultS3ClientConfig;
10499
final s3.S3Client _defaultS3Client;
105100
final S3PathResolver _pathResolver;
@@ -141,7 +136,9 @@ class StorageS3Service {
141136
..prefix = resolvedPath
142137
..maxKeys = options.pageSize
143138
..continuationToken = options.nextToken
144-
..delimiter = s3PluginOptions.excludeSubPaths ? _delimiter : null;
139+
..delimiter = s3PluginOptions.excludeSubPaths
140+
? s3PluginOptions.delimiter
141+
: null;
145142
});
146143

147144
try {
@@ -164,7 +161,9 @@ class StorageS3Service {
164161
builder
165162
..bucket = _s3PluginConfig.bucket
166163
..prefix = resolvedPath
167-
..delimiter = s3PluginOptions.excludeSubPaths ? _delimiter : null;
164+
..delimiter = s3PluginOptions.excludeSubPaths
165+
? s3PluginOptions.delimiter
166+
: null;
168167
});
169168

170169
listResult = await _defaultS3Client.listObjectsV2(request).result;

0 commit comments

Comments
 (0)