-
Notifications
You must be signed in to change notification settings - Fork 945
Set up Storage modularization #3499
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
Conversation
🦋 Changeset detectedLatest commit: b9751e2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
packages/storage/src/reference.ts
Outdated
* @return A reference to the parent of the | ||
* current object, or null if the current object is the root. | ||
*/ | ||
export function getParent(ref: Reference): Reference | null { |
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.
We need to figure out a name for this.
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.
Put parent back as a method on Reference
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.
Should we remove this method then?
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.
Removed this function and inlined the code into get parent()
packages/storage/src/reference.ts
Outdated
* Deletes the object at this location. | ||
* @return A promise that resolves if the deletion succeeds. | ||
*/ | ||
export function deleteObject(ref: Reference): Promise<void> { |
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.
In Firestore (and I believe Auth is doing this as well), we are taking the interface type and then use a casting helper to cast to the internal type. This ensures that someone doesn't use the old Reference in new code.
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.
Is ReferenceCompat duck type compatible with Reference?
bbfc41e
to
396e809
Compare
Not for review, just pushing code as-is to get some advice on if I'm going about the Typescript refactoring wrong. (Trying to explicitly implement the public API in the compat classes.) |
e810bad
to
570975e
Compare
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
3be9953
to
22c62e9
Compare
packages/storage/compat/list.ts
Outdated
export class ListResultCompat implements types.ListResult { | ||
constructor( | ||
private readonly delegate: ListResult, | ||
private converter: (ref: Reference) => ReferenceCompat |
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.
Is there a reason we cannot "hardcode" this converter in this class? We already seem to have cyclic references just because we imported the type.
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 seems like it doesn't complain about cyclic references if it's only a type, but it does if you bring in actual code. Because types don't impact execution? Not sure the exact rationale.
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.
Since this type cannot be constructed without passing in a factory function for References, it seems that in practice, these types are always included in the bundle?
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.
Only reviewed the compat code so far. Will review the rest of the PR tomorrow.
packages/storage/compat/reference.ts
Outdated
* Updates the metadata for this object. | ||
* @param metadata The new metadata for the object. |
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.
Just want to mention that we are changing to use tsdoc for documenting in vNext, which is used by api-documenter to generate reference docs. It is similar to jsdoc, but has some differences, for exmaple,
you need to put a -
after the parameter name and it's returns
instead of return
. See https://api-extractor.com/pages/tsdoc/doc_comment_syntax/ for the complete syntax.
You don't have to change the comments for the existing code.
packages/storage/compat/service.ts
Outdated
private converter: (ref: Reference) => ReferenceCompat | ||
) {} | ||
|
||
app = this.delegate.app; |
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.
IIUC, we are not using @firebase/app-exp
app yet. this.delegate.app
is currently the @firebase/app
app which is passed to StorageService
here.
Before we officially release the modular SDK, we need to change the compat factory to something like:
function compatFactory(container) {
const app = container.getProvider('app-compat').getImmediate()!;
const storage = container.getProvider('storage').getImmediate()!;
return new StorageServiceCompat(app, storage);
}
The compat app should be passed to StorageServiceCompat
as a constructor parameter.
d206430
to
cf14b39
Compare
packages/storage/src/reference.ts
Outdated
@@ -54,9 +51,9 @@ import { | |||
* the project ID of the base firebase.App instance. | |||
*/ | |||
export class Reference { | |||
protected location: Location; | |||
location: Location; |
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 think we should make them private as they appears to be internal implementations that outside should not have direct access to. We provide getters storage
, bucket
and fullPath
to access them instead.
We can remove the @internal annotation if they are private.
packages/storage/compat/list.ts
Outdated
export class ListResultCompat implements types.ListResult { | ||
constructor( | ||
private readonly _delegate: ListResult, | ||
private _referenceConverter: (ref: Reference) => ReferenceCompat |
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 feels simpler to pass in the Storage instance and "hardcode" the conversion to ReferenceCompat in this class.
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 did it to get rid of the circular dependency warnings. Should we just ignore them? They look so messy.
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.
Decided to have more readable code and live with a couple of circular dependency warnings.
packages/storage/src/reference.ts
Outdated
* @return A reference to the parent of the | ||
* current object, or null if the current object is the root. | ||
*/ | ||
export function getParent(ref: Reference): Reference | null { |
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.
Should we remove this method then?
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.
LGTM. The PR contains some unrelated changes currently, you may need to merge with master to get a clean diff.
I would recommend generating a size report for the modular APIs as soon as possible, and whenever you make new changes, so you can check it against your expectations and fix issues (e.g. unexpected dependencies).
You probably want to use the cli directly for the first time because the PR integration doesn't work very well for new code.
a4964b4
to
765c410
Compare
packages/storage/compat/task.ts
Outdated
private readonly _ref: ReferenceCompat | ||
) {} | ||
|
||
snapshot = new UploadTaskSnapshotCompat( |
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.
Consider making this a getter.
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.
packages/storage/compat/task.ts
Outdated
| StorageObserver<UploadTaskSnapshot> | ||
| undefined | ||
| ((a: UploadTaskSnapshot) => unknown) = undefined; | ||
if (nextOrObserver != null) { |
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 seems like code that someone might "fix" in the future by changing "!=" to "!==". This will then break the client. I usually just do !!nextOrObserver
.
Optional.
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.
packages/storage/compat/task.ts
Outdated
} else { | ||
wrappedNextOrObserver = { | ||
next: | ||
nextOrObserver.next == null |
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.
Same comment as above.
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 invalidArgument( | ||
index: number, | ||
fnName: string, | ||
message: string | ||
): FirebaseStorageError; |
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.
Note that there is only a single callsiste for invalidArgument
with fnName
and message
. We could simplify this code by removing the outlier.
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.
Ack, missed removing that param type check.
import { DEFAULT_HOST } from './constants'; | ||
|
||
/** | ||
* @struct | ||
* @public |
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.
Should we drop this?
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.
Removed.
@@ -28,7 +29,7 @@ export const StringFormat = { | |||
}; | |||
|
|||
/** | |||
* @struct | |||
* @internal |
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.
Again, I think we could drop this since this is in an internal source folder.
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.
Removed.
c079ef7
to
27bfcc5
Compare
20a05fe
to
b9751e2
Compare
* Rolls a node app building bundles. * Build bundle files for given list of project IDs. * Build the bundle json map and save it for integration tests. * Add emulator_settings.ts to gulp * Move bundle.test.ts to api/ * Bundles passes all tests and expose in classic API * Add CI project ID to bundles. * Adhoc string replacement and length re-calculation * Fix lint errors. * Delete old changes from make node app * Address comments * Update yarn.lock for release (#3998) Temp fix where database version is bumped before firebase-admin can update deps * Manually prepares the bundle strings. * Update API * Update config.ts * Use Chrome for karma debugging (#4007) * Cache emulator between runs (#3956) * Remote Config Modularization (#3975) * rc exp init * Add apis * register rc exp * implement funcitonal APIs * fix tests * build rc exp * add api-extractor to rc types * cast directly witout function * delete changelog for rc exp * add code owners to rc exp * update dep version * Remove AuthErrorCode from core export (#4013) * Remove AuthErrorCode from core export * Api * Update config.ts to remove bundles * adds a root changelog (#4009) * adds a root changelog * Update CHANGELOG.md Co-authored-by: Feiyang <[email protected]> * Update dependency typescript to v4.0.5 (#3846) Co-authored-by: Renovate Bot <[email protected]> * Update dependency karma-firefox-launcher to v2 (#3987) Co-authored-by: Renovate Bot <[email protected]> * Update dependency google-closure-library to v20200830 (#3765) * Update dependency google-closure-library to v20200830 * Replace goog.isArray with Array.isArray https://github.com/google/closure-library/releases/tag/v20200628 Co-authored-by: Renovate Bot <[email protected]> Co-authored-by: Alex Volkovitsky <[email protected]> * exclude remote config exp packages in changeset (#4014) * Set 1s timeout for onBackgroundMessage Hook (#3780) * await onBackgroundMessage hook * Create fluffy-panthers-hide.md * block in onPush to let onBackgroundMessage to execute * polish wording * Update changeset to be more specific * Update fluffy-panthers-hide.md * Clarify PR is about a bug fix * Update fluffy-panthers-hide.md * A whole bunch of things to bring auth (compat) to parity (#3970) * Handle anonymous auth re-login edge case * Formatting * Initial fixes * Fix redirect * clean up additional user info * Formatting * PR feedback * Fix some tests * Fix tests & write some new ones * Fix broken build * Formatting * Formatting * PR feedback * Formatting * PR feedback Co-authored-by: avolkovi <[email protected]> * Add withFunctionsTriggersDisabled method to rules-unit-testing (#3928) * Update integration tests to use free functions * Functions compat package (#3739) * Add free functions to exports * Fix to avoid false failures on changeset checker (#4012) * Add changeset for Firestore (#4030) * Update functions-compat dep version and fix changeset script error (#4032) * Update integration tests. Minified tests fail. * Bump node memory limit for all test CI (#4035) * Compat Layer for Firestore (#4003) * Rename all public API types to PublicX (#4039) * Update all non-major dependencies (#3953) Co-authored-by: Renovate Bot <[email protected]> * Version Packages (#4033) Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * Set up Storage modularization (#3499) Refactor storage for modularization. * Free functions removed from exp database.ts Co-authored-by: Christina Holland <[email protected]> Co-authored-by: Sebastian Schmidt <[email protected]> Co-authored-by: Sam Stern <[email protected]> Co-authored-by: Feiyang <[email protected]> Co-authored-by: Sam Horlbeck Olsen <[email protected]> Co-authored-by: Dimitri Mitropoulos <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Renovate Bot <[email protected]> Co-authored-by: Alex Volkovitsky <[email protected]> Co-authored-by: Kai Wu <[email protected]> Co-authored-by: Google Open Source Bot <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Separating entry points into
exp
andcompat
versions.Main implementation is
exp
but exp entry point is in a subfolder. Current version has wrapper classes in acompat
folder, but package entry point is at top level.Unit test files have been split into a "compat" version and an "exp" version when necessary.
The goal of this PR specifically is to have a functional backwards-compatible Storage SDK through the wrapper files in the compat/ dir, without the
exp
package being ready for public use yet.In order to get the
exp
package ready for publishing we need to make additional PRs to:uploadBytes()
function (this one includes `uploadBytesResumable())