FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(storage): add support for 'fields' query parameter to getFiles by thiyaguk09 · Pull Request #2521 · googleapis/nodejs-storage · GitHub

This repository was archived by the owner on Mar 3, 2026. It is now read-only.
/ nodejs-storage Public archive
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .json  (1) .ts  (4) All 2 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 2 additions & 0 deletions package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@
"pack-n-play": "^2.0.0",
"proxyquire": "^2.1.3",
"sinon": "^18.0.0",
"nise": "6.0.0",
"path-to-regexp": "6.2.2",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Let's just add a tacking issue to remove this once we upgrade to Node 18 minimum so we don't forget.

"tmp": "^0.2.0",
"typescript": "^5.1.6",
"yargs": "^17.3.1"
Expand Down
6 changes: 6 additions & 0 deletions src/bucket.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export interface GetFilesOptions {
startOffset?: string;
userProject?: string;
versions?: boolean;
fields?: string;
}

export interface CombineOptions extends PreconditionOptions {
Expand Down Expand Up @@ -2825,6 +2826,11 @@ class Bucket extends ServiceObject<Bucket, BucketMetadata> {
const files = itemsArray.map((file: FileMetadata) => {
const options = {} as FileOptions;

if (query.fields) {
const fileInstance = file;
return fileInstance;
}

if (query.versions) {
options.generation = file.generation;
}
Expand Down
2 changes: 1 addition & 1 deletion system-test/common.ts

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

We adjusted the test placement to address the previous failures.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ describe('Common', () => {
assert(err?.message.includes('ECONNREFUSED'));
const timeResponse = Date.now();
assert(timeResponse - timeRequest > minExpectedResponseTime);
done();
}
);
done();
});
});
});
14 changes: 14 additions & 0 deletions system-test/storage.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3249,6 +3249,20 @@ describe('storage', function () {
assert.strictEqual(files!.length, NEW_FILES.length);
});

it('returns file name only when fields is set as name', async () => {
const expected = [
{name: 'CloudLogo1'},
{name: 'CloudLogo2'},
{name: 'CloudLogo3'},
{name: `${DIRECTORY_NAME}/CloudLogo4`},
{name: `${DIRECTORY_NAME}/CloudLogo5`},
{name: `${DIRECTORY_NAME}/inner/CloudLogo6`},
];
const [files] = await bucket.getFiles({fields: 'items(name)'});

assert.deepStrictEqual(files, expected);
});

it('returns folders as prefixes when includeFoldersAsPrefixes is set', async () => {
const expected = [`${DIRECTORY_NAME}/`];
const [, , result] = await bucket.getFiles({
Expand Down
20 changes: 20 additions & 0 deletions test/bucket.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1866,6 +1866,26 @@ describe('Bucket', () => {
});
});

it('should return Files with specified values if queried for fields', done => {
bucket.request = (
reqOpts: DecorateRequestOptions,
callback: Function
) => {
callback(null, {
items: [{name: 'fake-file-name'}],
});
};

bucket.getFiles(
{fields: 'items(name)'},
(err: Error, files: FakeFile[]) => {
assert.ifError(err);
assert.strictEqual(files[0].name, 'fake-file-name');
done();
}
);
});

it('should return soft-deleted Files if queried for softDeleted', done => {
const softDeletedTime = new Date('1/1/2024').toISOString();
bucket.request = (
Expand Down

Back | FazBrowse Home | New Git URL