-
Notifications
You must be signed in to change notification settings - Fork 945
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
Storage List API #1610
Conversation
… into fz/storage-list
There was a problem hiding this 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.
packages/storage-types/index.d.ts
Outdated
} | ||
|
||
export interface ListOptions { | ||
maxResults?: number | null | undefined; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
packages/storage/src/reference.ts
Outdated
@@ -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. |
There was a problem hiding this comment.
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.
packages/storage/src/reference.ts
Outdated
@@ -201,6 +203,28 @@ export class Reference { | |||
}); | |||
} | |||
|
|||
/** | |||
* @param options.maxResults limits the total number of prefixes and items to return.. |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) {
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 } |
There was a problem hiding this comment.
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(/\/$/, '')) |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
packages/storage-types/index.d.ts
Outdated
} | ||
|
||
export interface ListOptions { | ||
maxResults?: number | null | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Fixed
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 ℹ️ Googlers: Go here for more info. |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
packages/firebase/index.d.ts
Outdated
* @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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
API proposal: internal golink firebase-storage-list-api