Skip to content

Commit

Permalink
feat: add includeFoldersAsPrefixes for managed folders (#2413)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelgrosso1 committed Mar 7, 2024
1 parent c781bdc commit 3044d3c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/bucket.ts
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
Expand Up @@ -3124,6 +3124,20 @@ describe('storage', function () {
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({
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
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

0 comments on commit 3044d3c

Please sign in to comment.