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

feat: add includeFoldersAsPrefixes for managed folders #2413

Merged
merged 1 commit into from
Mar 7, 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
9 changes: 9 additions & 0 deletions src/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export interface GetFilesOptions {
autoPaginate?: boolean;
delimiter?: string;
endOffset?: string;
includeFoldersAsPrefixes?: boolean;
includeTrailingDelimiter?: boolean;
prefix?: string;
matchGlob?: string;
Expand Down Expand Up @@ -2608,6 +2609,10 @@ class Bucket extends ServiceObject<Bucket, BucketMetadata> {
* @property {string} [endOffset] Filter results to objects whose names are
* lexicographically before endOffset. If startOffset is also set, the objects
* listed have names between startOffset (inclusive) and endOffset (exclusive).
* @property {boolean} [includeFoldersAsPrefixes] If true, includes folders and
* managed folders in the set of prefixes returned by the query. Only applicable if
* delimiter is set to / and autoPaginate is set to false.
* See: https://cloud.google.com/storage/docs/managed-folders
* @property {boolean} [includeTrailingDelimiter] If true, objects that end in
* exactly one instance of delimiter have their metadata included in items[]
* in addition to the relevant part of the object name appearing in prefixes[].
Expand Down Expand Up @@ -2648,6 +2653,10 @@ class Bucket extends ServiceObject<Bucket, BucketMetadata> {
* @param {string} [query.endOffset] Filter results to objects whose names are
* lexicographically before endOffset. If startOffset is also set, the objects
* listed have names between startOffset (inclusive) and endOffset (exclusive).
* @param {boolean} [query.includeFoldersAsPrefixes] If true, includes folders and
* managed folders in the set of prefixes returned by the query. Only applicable if
* delimiter is set to / and autoPaginate is set to false.
* See: https://cloud.google.com/storage/docs/managed-folders
* @param {boolean} [query.includeTrailingDelimiter] If true, objects that end in
* exactly one instance of delimiter have their metadata included in items[]
* in addition to the relevant part of the object name appearing in prefixes[].
Expand Down
14 changes: 14 additions & 0 deletions system-test/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3129,6 +3129,20 @@ describe('storage', () => {
assert.strictEqual(files!.length, NEW_FILES.length);
});

it('returns folders as prefixes when includeFoldersAsPrefixes is set', async () => {
const expected = [`${DIRECTORY_NAME}/`];
const [, , result] = await bucket.getFiles({
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't confirm a specific managed folder is in the list of prefixes; It might be the best we can do right now though because you'd need to make a one-off request to create a managed folder through Apiary Node.js client to verify functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By apiary you mean storage control?

Copy link
Member

Choose a reason for hiding this comment

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

No, there's support in Storage v1 json apiary that has CreateManagedFolder RPC which would help with this test until Storage Control is available.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably beyond the scope of this change to start pulling in other dependencies just for a single test case.

Copy link
Contributor

Choose a reason for hiding this comment

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

When do we plan on adding the create functionality in this library?

delimiter: '/',
includeFoldersAsPrefixes: true,
autoPaginate: false,
});

assert.deepStrictEqual(
(result as {prefixes: string[]}).prefixes,
expected
);
});

it('should get files as a stream', done => {
let numFilesEmitted = 0;

Expand Down
19 changes: 17 additions & 2 deletions test/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1772,10 +1772,25 @@ describe('Bucket', () => {
it('should get files with a query', done => {
const token = 'next-page-token';
bucket.request = (reqOpts: DecorateRequestOptions) => {
assert.deepStrictEqual(reqOpts.qs, {maxResults: 5, pageToken: token});
assert.deepStrictEqual(reqOpts.qs, {
maxResults: 5,
pageToken: token,
includeFoldersAsPrefixes: true,
delimiter: '/',
autoPaginate: false,
});
done();
};
bucket.getFiles({maxResults: 5, pageToken: token}, util.noop);
bucket.getFiles(
{
maxResults: 5,
pageToken: token,
includeFoldersAsPrefixes: true,
delimiter: '/',
autoPaginate: false,
},
util.noop
);
});

it('should return nextQuery if more results exist', () => {
Expand Down
Loading