-
Notifications
You must be signed in to change notification settings - Fork 873
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up Storage modularization (#3499)
Refactor storage for modularization.
- Loading branch information
Showing
46 changed files
with
2,470 additions
and
1,055 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@firebase/storage': patch | ||
--- | ||
|
||
Refactored Storage to allow for modularization. |
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "../../config/api-extractor.json", | ||
// Point it to your entry point d.ts file. | ||
"mainEntryPointFilePath": "<projectFolder>/exp/dist/exp/index.d.ts", | ||
"dtsRollup": { | ||
"enabled": true, | ||
"untrimmedFilePath": "<projectFolder>/exp/dist/<unscopedPackageName>.d.ts", | ||
"publicTrimmedFilePath": "<projectFolder>/exp/dist/<unscopedPackageName>-public.d.ts" | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/** | ||
* @license | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import firebase from '@firebase/app'; | ||
import { _FirebaseNamespace } from '@firebase/app-types/private'; | ||
import { StringFormat } from '../src/implementation/string'; | ||
import { TaskEvent, TaskState } from '../src/implementation/taskenums'; | ||
|
||
import { XhrIoPool } from '../src/implementation/xhriopool'; | ||
import { ReferenceCompat } from './reference'; | ||
import { StorageServiceCompat } from './service'; | ||
import { StorageService } from '../src/service'; | ||
import * as types from '@firebase/storage-types'; | ||
import { | ||
Component, | ||
ComponentType, | ||
ComponentContainer | ||
} from '@firebase/component'; | ||
|
||
import { name, version } from '../package.json'; | ||
|
||
/** | ||
* Type constant for Firebase Storage. | ||
*/ | ||
const STORAGE_TYPE = 'storage'; | ||
|
||
function factory( | ||
container: ComponentContainer, | ||
url?: string | ||
): types.FirebaseStorage { | ||
// Dependencies | ||
// TODO: This should eventually be 'app-compat' | ||
const app = container.getProvider('app').getImmediate(); | ||
const authProvider = container.getProvider('auth-internal'); | ||
|
||
// TODO: get StorageService instance from component framework instead | ||
// of creating a new one. | ||
const storageServiceCompat: StorageServiceCompat = new StorageServiceCompat( | ||
app, | ||
new StorageService(app, authProvider, new XhrIoPool(), url) | ||
); | ||
return storageServiceCompat; | ||
} | ||
|
||
export function registerStorage(instance: _FirebaseNamespace): void { | ||
const namespaceExports = { | ||
// no-inline | ||
TaskState, | ||
TaskEvent, | ||
StringFormat, | ||
Storage: StorageService, | ||
Reference: ReferenceCompat | ||
}; | ||
instance.INTERNAL.registerComponent( | ||
new Component(STORAGE_TYPE, factory, ComponentType.PUBLIC) | ||
.setServiceProps(namespaceExports) | ||
.setMultipleInstances(true) | ||
); | ||
|
||
instance.registerVersion(name, version); | ||
} | ||
|
||
registerStorage(firebase as _FirebaseNamespace); | ||
|
||
/** | ||
* Define extension behavior for `registerStorage` | ||
*/ | ||
declare module '@firebase/app-types' { | ||
interface FirebaseNamespace { | ||
storage?: { | ||
(app?: FirebaseApp): types.FirebaseStorage; | ||
Storage: typeof types.FirebaseStorage; | ||
|
||
StringFormat: { | ||
BASE64: types.StringFormat; | ||
BASE64URL: types.StringFormat; | ||
DATA_URL: types.StringFormat; | ||
RAW: types.StringFormat; | ||
}; | ||
TaskEvent: { | ||
STATE_CHANGED: types.TaskEvent; | ||
}; | ||
TaskState: { | ||
CANCELED: types.TaskState; | ||
ERROR: types.TaskState; | ||
PAUSED: types.TaskState; | ||
RUNNING: types.TaskState; | ||
SUCCESS: types.TaskState; | ||
}; | ||
}; | ||
} | ||
interface FirebaseApp { | ||
storage?(storageBucket?: string): types.FirebaseStorage; | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* @license | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import * as types from '@firebase/storage-types'; | ||
import { ListResult } from '../src/list'; | ||
import { ReferenceCompat } from './reference'; | ||
import { StorageServiceCompat } from './service'; | ||
|
||
export class ListResultCompat implements types.ListResult { | ||
constructor( | ||
private readonly _delegate: ListResult, | ||
private readonly _service: StorageServiceCompat | ||
) {} | ||
|
||
get prefixes(): ReferenceCompat[] { | ||
return this._delegate.prefixes.map( | ||
ref => new ReferenceCompat(ref, this._service) | ||
); | ||
} | ||
get items(): ReferenceCompat[] { | ||
return this._delegate.items.map( | ||
ref => new ReferenceCompat(ref, this._service) | ||
); | ||
} | ||
get nextPageToken(): string | null { | ||
return this._delegate.nextPageToken || null; | ||
} | ||
} |
Oops, something went wrong.