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

Expose object metadata from Bucket.list #181

Merged
merged 2 commits into from
Nov 1, 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
2 changes: 1 addition & 1 deletion .github/workflows/gcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
matrix:
# Add macos-latest and/or windows-latest if relevant for this package.
os: [ubuntu-latest]
sdk: [2.19.0, dev]
sdk: [3.0.0, dev]
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672
Expand Down
11 changes: 11 additions & 0 deletions pkgs/gcloud/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
## 0.8.16-wip
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we mark this with a breaking version change?
We are still not 1.0.0 so I think we shouldn't worry too much

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, it's not likely to break anyone.


- **Breaking** `BucketEntry` is now `sealed` anyone implementing or subclassing
will experience breakage.
- Feature `BucketEntry` objects returns from `Bucket.list` are now instances
of:
* `BucketDirectoryEntry`, or,
* `BucketObjectEntry`, which implements `ObjectInfo` exposing metadata.

This means that anyone using `Bucket.list` to find objects, does not need
to use `Bucket.info` to fetch metadata for an object.
- Minimum Dart SDK constraint bumped to `^3.0.0`.

## 0.8.15

- Update the pubspec repository field to reflect the repo move.
Expand Down
14 changes: 12 additions & 2 deletions pkgs/gcloud/lib/src/storage_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,9 @@ class _ObjectPageImpl implements Page<BucketEntry> {
storage_api.Objects response)
: items = [
for (final item in response.prefixes ?? const <String>[])
BucketEntry._directory(item),
BucketDirectoryEntry._(item),
for (final item in response.items ?? const <storage_api.Object>[])
BucketEntry._object(item.name!)
_BucketObjectEntry(item)
],
_nextPageToken = response.nextPageToken;

Expand Down Expand Up @@ -430,6 +430,16 @@ class _ObjectInfoImpl implements ObjectInfo {
ObjectMetadata get metadata => _metadata;
}

class _BucketObjectEntry extends _ObjectInfoImpl implements BucketObjectEntry {
_BucketObjectEntry(storage_api.Object object) : super(object);

@override
bool get isDirectory => false;

@override
bool get isObject => true;
}

class _ObjectMetadata implements ObjectMetadata {
final storage_api.Object _object;
Acl? _cachedAcl;
Expand Down
29 changes: 22 additions & 7 deletions pkgs/gcloud/lib/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -668,23 +668,38 @@ abstract class ObjectMetadata {
/// Listing operate like a directory listing, despite the object
/// namespace being flat.
///
/// Instances of [BucketEntry] are either instances of [BucketDirectoryEntry]
/// or [BucketObjectEntry]. Casting to [BucketObjectEntry] will give access to
/// object metadata.
///
/// See [Bucket.list] for information on how the hierarchical structure
/// is determined.
class BucketEntry {
sealed class BucketEntry {
/// Whether this is information on an object.
final bool isObject;
bool get isObject;

/// Name of object or directory.
final String name;

BucketEntry._object(this.name) : isObject = true;

BucketEntry._directory(this.name) : isObject = false;
String get name;

/// Whether this is a prefix.
bool get isDirectory => !isObject;
}

/// Entry in [Bucket.list] representing a directory given the `delimiter`
/// passed.
class BucketDirectoryEntry extends BucketEntry {
@override
final String name;

BucketDirectoryEntry._(this.name);

@override
bool get isObject => false;
}

/// Entry in [Bucket.list] representing an object.
abstract class BucketObjectEntry implements BucketEntry, ObjectInfo {}

/// Access to operations on a specific cloud storage bucket.
abstract class Bucket {
/// Name of this bucket.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/gcloud/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ topics:
- gcp

environment:
sdk: '>=2.19.0 <4.0.0'
sdk: '^3.0.0'

dependencies:
_discoveryapis_commons: ^1.0.0
Expand Down