Skip to content

Storage List API #1610

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

Merged
merged 57 commits into from
May 28, 2019
Merged

Storage List API #1610

merged 57 commits into from
May 28, 2019

Conversation

fredzqm
Copy link
Contributor

@fredzqm fredzqm commented Mar 17, 2019

API proposal: internal golink firebase-storage-list-api

@fredzqm fredzqm changed the title List API Storage List API Mar 17, 2019
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

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

Thanks! This looks pretty good. Most of my comments are style nits and suggestions for improved typings.

}

export interface ListOptions {
maxResults?: number | null | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

The question mark already implies undefined. You should get rid of either the question mark or the undefined. I lean towards keeping the question mark.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Fixed

@@ -0,0 +1,90 @@
/**
* @license
* Copyright 2017 Google Inc.
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like someone is really dwelling in the past here :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lol

import * as type from './type';
import { ListResult } from '../list';

export function fromResource(
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mind adding a comment to explain what a resource is in this context? Is it always of type ListResponse?

Alternatively, it might make sense to use more specific names. You should then add a type definition that describes the expected resource type:

interface Resource {
   nextPageToken?: string,
   ...
}

It also looks like this function is only used in this file and does not need to be exported.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


export function fromResource(
authWrapper: AuthWrapper,
resource: { [name: string]: any }
Copy link
Contributor

Choose a reason for hiding this comment

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

It's best to avoid any additional usages of any. Can you change this any to unknown? unknown still keeps type safety, which will also make the code easier to follow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I was borrowing the examples in metadata.ts. It is much more readable with types.

@@ -201,6 +203,28 @@ export class Reference {
});
}

/**
* @param options.maxResults limits the total number of prefixes and items to return..
* @param options.pageToken nextPageToken from a previous list(). Resume from that position.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe change this to:

'The nextPageToken from a previous list() response. If provided, listing is resumed from that position.

@@ -201,6 +203,28 @@ export class Reference {
});
}

/**
* @param options.maxResults limits the total number of prefixes and items to return..
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe prefix with If set, limits...

for (let i = 0; i < maps.length; i++) {
const location = maps[i][0] as Location;
const url = maps[i][1] as string;
for (const d of maps) {
Copy link
Contributor

Choose a reason for hiding this comment

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

While you are here, you could make this:

    for (const [location, url ] of maps) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

import * as type from './type';
import { ListResult } from '../list';

export function fromResource(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,90 @@
/**
* @license
* Copyright 2017 Google Inc.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lol


export function fromResource(
authWrapper: AuthWrapper,
resource: { [name: string]: any }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I was borrowing the examples in metadata.ts. It is much more readable with types.

if (resource[prefixesKey]) {
for (const path of resource[prefixesKey]) {
const reference = authWrapper.makeStorageReference(
new Location(authWrapper.bucket(), path.replace(/\/$/, ''))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if (!validType) {
throw 'Expected ListOptions object.';
}
const maxResultsKey = 'maxResults';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure

}

export interface ListOptions {
maxResults?: number | null | undefined;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Fixed

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

ℹ️ Googlers: Go here for more info.

@wilhuff wilhuff force-pushed the fz/storage-list branch from b2d4c76 to dff0f21 Compare May 25, 2019 01:15
@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

* @param options.maxResults If set, limits the total number of `prefixes`
* and `items` to return. The default and maximum maxResults is 1000.
* Use the nextPageToken to retrieve more objects.
* @param options.pageToken The `nextPageToken` from a previous call to
Copy link
Member

Choose a reason for hiding this comment

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

This style of describing the parameter only works if you define the type directly in this method, like the following:

    list(options?: {maxResults: number | null, pageToken: string | null}

If an interface is used, the comments should coexist with the interface definition.

Since you have defined an interface, can you move the comments to the interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Updated the doc.

@@ -124,3 +124,25 @@ toc:
path: /docs/reference/node/firebase.firestore.Transaction
- title: "WriteBatch"
path: /docs/reference/node/firebase.firestore.WriteBatch

- title: "firebase.storage"
Copy link
Member

Choose a reason for hiding this comment

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

I don't think storage is supported in Nodejs.

Copy link
Contributor Author

@fredzqm fredzqm May 28, 2019

Choose a reason for hiding this comment

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

I see. I will revert it.
OOC, any reason we did not have it in the first place?

@fredzqm fredzqm merged commit bc4a844 into master May 28, 2019
@firebase firebase locked and limited conversation to collaborators Oct 12, 2019
@fredzqm fredzqm deleted the fz/storage-list branch August 25, 2020 19:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants