Skip to content

Storage compat build and release #4641

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 13 commits into from
Mar 17, 2021
87 changes: 86 additions & 1 deletion common/api-review/storage.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,32 @@

import { CompleteFn } from '@firebase/util';
import { FirebaseApp } from '@firebase/app';
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
import { FirebaseError } from '@firebase/util';
import { _FirebaseService } from '@firebase/app';
import { NextFn } from '@firebase/util';
import { Provider } from '@firebase/component';
import { Subscribe } from '@firebase/util';
import { Unsubscribe } from '@firebase/util';

// @public
export function deleteObject(ref: StorageReference): Promise<void>;

// @internal (undocumented)
export class _FbsBlob {
constructor(data: Blob | Uint8Array | ArrayBuffer, elideCopy?: boolean);
// (undocumented)
static getBlob(...args: Array<string | _FbsBlob>): _FbsBlob | null;
// (undocumented)
size(): number;
// (undocumented)
slice(startByte: number, endByte: number): _FbsBlob | null;
// (undocumented)
type(): string;
// (undocumented)
uploadData(): Blob | Uint8Array;
}

// @public
export interface FirebaseStorageError extends FirebaseError {
serverResponse: string | null;
Expand All @@ -33,6 +51,9 @@ export interface FullMetadata extends UploadMetadata {
updated: string;
}

// @internal (undocumented)
export function _getChild(ref: StorageReference, childPath: string): _Reference;

// @public
export function getDownloadURL(ref: StorageReference): Promise<string>;

Expand Down Expand Up @@ -61,12 +82,50 @@ export interface ListResult {
prefixes: StorageReference[];
}

// @internal
export class _Location {
constructor(bucket: string, path: string);
// (undocumented)
readonly bucket: string;
// (undocumented)
bucketOnlyServerUrl(): string;
// (undocumented)
fullServerUrl(): string;
// (undocumented)
get isRoot(): boolean;
// (undocumented)
static makeFromBucketSpec(bucketString: string): _Location;
// (undocumented)
static makeFromUrl(url: string): _Location;
// (undocumented)
get path(): string;
}

// @public
export function ref(storage: StorageService, url?: string): StorageReference;

// @public
export function ref(storageOrRef: StorageService | StorageReference, path?: string): StorageReference;

// @internal
export class _Reference {
// Warning: (ae-forgotten-export) The symbol "StorageService" needs to be exported by the entry point index.d.ts
constructor(_service: StorageService_2, location: string | _Location);
get bucket(): string;
get fullPath(): string;
// (undocumented)
_location: _Location;
get name(): string;
// (undocumented)
protected _newRef(service: StorageService_2, location: _Location): _Reference;
get parent(): _Reference | null;
get root(): _Reference;
get storage(): StorageService_2;
_throwIfRoot(name: string): void;
// @override
toString(): string;
}

// @public
export interface SettableMetadata {
cacheControl?: string | undefined;
Expand Down Expand Up @@ -101,7 +160,7 @@ export interface StorageReference {
}

// @public
export interface StorageService {
export interface StorageService extends _FirebaseService {
readonly app: FirebaseApp;
maxOperationRetryTime: number;
maxUploadRetryTime: number;
Expand Down Expand Up @@ -158,6 +217,32 @@ export interface UploadTask {
then(onFulfilled?: ((snapshot: UploadTaskSnapshot) => unknown) | null, onRejected?: ((error: FirebaseStorageError) => unknown) | null): Promise<unknown>;
}

// @internal
export class _UploadTask {
constructor(ref: _Reference, blob: _FbsBlob, metadata?: Metadata | null);
_blob: _FbsBlob;
cancel(): boolean;
catch<T>(onRejected: (p1: FirebaseStorageError_2) => T | Promise<T>): Promise<T>;
// Warning: (ae-forgotten-export) The symbol "Metadata" needs to be exported by the entry point index.d.ts
_metadata: Metadata | null;
// Warning: (ae-forgotten-export) The symbol "TaskEvent" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "StorageObserver" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ErrorFn" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "CompleteFn" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "Unsubscribe" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "Subscribe" needs to be exported by the entry point index.d.ts
on(type: TaskEvent_2, nextOrObserver?: StorageObserver_2<UploadTaskSnapshot_2> | ((a: UploadTaskSnapshot_2) => unknown), error?: ErrorFn, completed?: CompleteFn_2): Unsubscribe_2 | Subscribe_2<UploadTaskSnapshot_2>;
pause(): boolean;
resume(): boolean;
// Warning: (ae-forgotten-export) The symbol "UploadTaskSnapshot" needs to be exported by the entry point index.d.ts
get snapshot(): UploadTaskSnapshot_2;
// Warning: (ae-forgotten-export) The symbol "InternalTaskState" needs to be exported by the entry point index.d.ts
_state: InternalTaskState;
// Warning: (ae-forgotten-export) The symbol "FirebaseStorageError" needs to be exported by the entry point index.d.ts
then<U>(onFulfilled?: ((value: UploadTaskSnapshot_2) => U | Promise<U>) | null, onRejected?: ((error: FirebaseStorageError_2) => U | Promise<U>) | null): Promise<U>;
_transferred: number;
}

// @public
export interface UploadTaskSnapshot {
bytesTransferred: number;
Expand Down
7 changes: 4 additions & 3 deletions packages-exp/analytics-compat/rollup.shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
*/
import pkg from './package.json';

const deps = Object.keys(
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
);
const deps = [
...Object.keys(Object.assign({}, pkg.peerDependencies, pkg.dependencies)),
'@firebase/analytics'
];

export const es5BuildsNoPlugin = [
/**
Expand Down
7 changes: 4 additions & 3 deletions packages-exp/app-compat/rollup.config.release.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import typescript from 'typescript';
import pkg from './package.json';
import { importPathTransformer } from '../../scripts/exp/ts-transform-import-path';

const deps = Object.keys(
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
);
const deps = [
...Object.keys(Object.assign({}, pkg.peerDependencies, pkg.dependencies)),
'@firebase/app'
];

/**
* ES5 Builds
Expand Down
7 changes: 4 additions & 3 deletions packages-exp/functions-compat/rollup.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import typescriptPlugin from 'rollup-plugin-typescript2';
import typescript from 'typescript';
import pkg from './package.json';

const deps = Object.keys(
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
);
const deps = [
...Object.keys(Object.assign({}, pkg.peerDependencies, pkg.dependencies)),
'@firebase/functions'
];

/**
* ES5 Builds
Expand Down
7 changes: 4 additions & 3 deletions packages-exp/performance-compat/rollup.shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@

import pkg from './package.json';

const deps = Object.keys(
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
);
const deps = [
...Object.keys(Object.assign({}, pkg.peerDependencies, pkg.dependencies)),
'@firebase/performance'
];

export const es5BuildsNoPlugin = [
/**
Expand Down
7 changes: 4 additions & 3 deletions packages-exp/remote-config-compat/rollup.shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@

import pkg from './package.json';

const deps = Object.keys(
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
);
const deps = [
...Object.keys(Object.assign({}, pkg.peerDependencies, pkg.dependencies)),
'@firebase/remote-config'
];

export const es5BuildsNoPlugin = [
/**
Expand Down
26 changes: 11 additions & 15 deletions packages/storage/compat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
* limitations under the License.
*/

import firebase from '@firebase/app';
// eslint-disable-next-line import/no-extraneous-dependencies
import firebase from '@firebase/app-compat';
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,
Expand All @@ -34,6 +33,8 @@ import {

import { name, version } from '../package.json';

import '../register-module';

/**
* Type constant for Firebase Storage.
*/
Expand All @@ -44,21 +45,16 @@ function factory(
{ instanceIdentifier: url }: InstanceFactoryOptions
): types.FirebaseStorage {
// Dependencies
// TODO: This should eventually be 'app-compat'
const app = container.getProvider('app').getImmediate();
const authProvider = container.getProvider('auth-internal');
const app = container.getProvider('app-compat').getImmediate();
const storageExp = container
.getProvider('storage-exp')
.getImmediate({ identifier: url });

// 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,
firebase.SDK_VERSION
)
storageExp
);
return storageServiceCompat;
}
Expand All @@ -69,7 +65,7 @@ export function registerStorage(instance: _FirebaseNamespace): void {
TaskState,
TaskEvent,
StringFormat,
Storage: StorageService,
Storage: StorageServiceCompat,
Reference: ReferenceCompat
};
instance.INTERNAL.registerComponent(
Expand All @@ -81,7 +77,7 @@ export function registerStorage(instance: _FirebaseNamespace): void {
instance.registerVersion(name, version);
}

registerStorage(firebase as _FirebaseNamespace);
registerStorage((firebase as unknown) as _FirebaseNamespace);

/**
* Define extension behavior for `registerStorage`
Expand Down
3 changes: 1 addition & 2 deletions packages/storage/compat/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { ListResult } from '../exp/api';
import * as types from '@firebase/storage-types';
import { ListResult } from '../src/list';
import { ReferenceCompat } from './reference';
import { StorageServiceCompat } from './service';

Expand Down
13 changes: 13 additions & 0 deletions packages/storage/compat/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "@firebase/storage-compat",
"version": "0.0.900",
"description": "The Cloud Storage component of the Firebase JS SDK.",
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
"main": "../dist/compat/node-cjs/index.js",
"browser": "../dist/compat/esm5/index.js",
"module": "../dist/compat/esm5/index.js",
"esm2017": "../dist/compat/esm2017/index.js",
"license": "Apache-2.0",
"typings": "../dist/compat/esm5/compat/index.d.ts"
}

37 changes: 21 additions & 16 deletions packages/storage/compat/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,34 @@
*/

import {
Reference,
_getChild,
StorageReference,
uploadBytesResumable,
list,
listAll,
getDownloadURL,
getMetadata,
updateMetadata,
deleteObject
} from '../src/reference';
import * as types from '@firebase/storage-types';
import { Metadata } from '../src/metadata';
import { dataFromString, StringFormat } from '../src/implementation/string';
deleteObject,
UploadTask,
StringFormat,
_UploadTask,
_getChild,
_Reference,
_FbsBlob
} from '../exp/api'; // import from the exp public API

import { UploadTaskCompat } from './task';
import { ListResultCompat } from './list';
import { StorageServiceCompat } from './service';

import * as types from '@firebase/storage-types';
import { Metadata } from '../src/metadata';
import { dataFromString } from '../src/implementation/string';
import { invalidRootOperation } from '../src/implementation/error';
import { UploadTask } from '../src/task';
import { FbsBlob } from '../src/implementation/blob';

export class ReferenceCompat implements types.Reference {
constructor(
private readonly _delegate: Reference,
private readonly _delegate: StorageReference,
public storage: StorageServiceCompat
) {}

Expand Down Expand Up @@ -120,11 +125,11 @@ export class ReferenceCompat implements types.Reference {
metadataClone['contentType'] = data.contentType;
}
return new UploadTaskCompat(
new UploadTask(
this._delegate,
new FbsBlob(data.data, true),
new _UploadTask(
this._delegate as _Reference,
new _FbsBlob(data.data, true),
metadataClone
),
) as UploadTask,
this
);
}
Expand Down Expand Up @@ -172,7 +177,7 @@ export class ReferenceCompat implements types.Reference {
* can be used to get the rest of the results.
*/
list(options?: types.ListOptions | null): Promise<types.ListResult> {
return list(this._delegate, options).then(
return list(this._delegate, options || undefined).then(
r => new ListResultCompat(r, this.storage)
);
}
Expand Down Expand Up @@ -222,7 +227,7 @@ export class ReferenceCompat implements types.Reference {
}

private _throwIfRoot(name: string): void {
if (this._delegate._location.path === '') {
if ((this._delegate as _Reference)._location.path === '') {
throw invalidRootOperation(name);
}
}
Expand Down
Loading