Skip to content

Split storage and storage-compat #5271

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 28 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4713a38
separate storage-compat from storage
Feiyang1 Aug 5, 2021
46a8d8c
commit
Feiyang1 Aug 5, 2021
c2fcd73
fix tests
Feiyang1 Aug 5, 2021
af627d2
wat?
Feiyang1 Aug 5, 2021
d2941ba
build storage-compat
Feiyang1 Aug 6, 2021
40dbf77
save
Feiyang1 Aug 6, 2021
6d99fb4
fixing some compat tests
Feiyang1 Aug 10, 2021
0a1d781
format
Feiyang1 Aug 10, 2021
af3dd18
update import path
Feiyang1 Aug 10, 2021
fe25775
format
Feiyang1 Aug 10, 2021
63c20ae
get compat tests to work
Feiyang1 Aug 10, 2021
c47721f
format
Feiyang1 Aug 10, 2021
56aa473
update package json
Feiyang1 Aug 10, 2021
307ca6c
cleanup
Feiyang1 Aug 10, 2021
d627474
Merge branch 'master' into fei-v9-main-storage
Feiyang1 Aug 10, 2021
3097128
format
Feiyang1 Aug 10, 2021
d3723ad
address comments
Feiyang1 Aug 12, 2021
53d6a7c
Merge branch 'master' into fei-v9-main-storage
Feiyang1 Aug 14, 2021
e82142d
Merge branch 'master' into fei-v9-main-storage
Feiyang1 Aug 18, 2021
fb7e7c6
Update packages/storage-compat/test/unit/service.test.ts
Feiyang1 Aug 18, 2021
572294d
add missing dev dep
Feiyang1 Aug 18, 2021
37fba27
Update packages/storage-compat/package.json
hsubox76 Aug 18, 2021
a55f49c
Merge branch 'master' into fei-v9-main-storage
Feiyang1 Aug 19, 2021
04d73ad
Merge branch 'fei-v9-main-storage' of https://github.com/firebase/fir…
Feiyang1 Aug 19, 2021
5afdd50
Update packages/storage-compat/package.json
hsubox76 Aug 19, 2021
6c2ddcb
Update deps after v8 release
hsubox76 Aug 19, 2021
5abbf4a
Merge branch 'master' into fei-v9-main-storage
Feiyang1 Aug 19, 2021
773f579
update compat version
Feiyang1 Aug 19, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 89 additions & 14 deletions common/api-review/storage.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { EmulatorMockTokenOptions } 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 { _FirebaseService } from '@firebase/app-exp';
import { NextFn } from '@firebase/util';
import { Provider } from '@firebase/component';
import { Subscribe } from '@firebase/util';
Expand All @@ -21,6 +21,11 @@ export function connectStorageEmulator(storage: FirebaseStorage, host: string, p
mockUserToken?: EmulatorMockTokenOptions | string;
}): void;

// Warning: (ae-forgotten-export) The symbol "StringData" needs to be exported by the entry point index.d.ts
//
// @internal (undocumented)
export function _dataFromString(format: StringFormat, stringData: string): StringData;

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

Expand Down Expand Up @@ -51,6 +56,55 @@ export interface FirebaseStorageError extends FirebaseError {
serverResponse: string | null;
}

// @public
export class _FirebaseStorageImpl implements FirebaseStorage {
constructor(
app: FirebaseApp, _authProvider: Provider<FirebaseAuthInternalName>,
_appCheckProvider: Provider<AppCheckInternalComponentName>,
_pool: ConnectionPool, _url?: string | undefined, _firebaseVersion?: string | undefined);
readonly app: FirebaseApp;
// @internal (undocumented)
readonly _appCheckProvider: Provider<AppCheckInternalComponentName>;
// (undocumented)
protected readonly _appId: string | null;
// (undocumented)
readonly _authProvider: Provider<FirebaseAuthInternalName>;
// Warning: (ae-incompatible-release-tags) The symbol "_bucket" is marked as @public, but its signature references "Location" which is marked as @internal
//
// (undocumented)
_bucket: _Location | null;
_delete(): Promise<void>;
// (undocumented)
readonly _firebaseVersion?: string | undefined;
// (undocumented)
_getAppCheckToken(): Promise<string | null>;
// (undocumented)
_getAuthToken(): Promise<string | null>;
// (undocumented)
get host(): string;
set host(host: string);
// Warning: (ae-forgotten-export) The symbol "RequestInfo" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "Request" needs to be exported by the entry point index.d.ts
//
// (undocumented)
_makeRequest<T>(requestInfo: RequestInfo_2<T>, authToken: string | null, appCheckToken: string | null): Request_2<T>;
// (undocumented)
makeRequestWithTokens<T>(requestInfo: RequestInfo_2<T>): Promise<Request_2<T>>;
// Warning: (ae-incompatible-release-tags) The symbol "_makeStorageReference" is marked as @public, but its signature references "Location" which is marked as @internal
// Warning: (ae-incompatible-release-tags) The symbol "_makeStorageReference" is marked as @public, but its signature references "Reference" which is marked as @internal
_makeStorageReference(loc: _Location): _Reference;
get maxOperationRetryTime(): number;
set maxOperationRetryTime(time: number);
get maxUploadRetryTime(): number;
set maxUploadRetryTime(time: number);
// Warning: (ae-forgotten-export) The symbol "ConnectionPool" needs to be exported by the entry point index.d.ts
//
// @internal (undocumented)
readonly _pool: ConnectionPool;
// (undocumented)
readonly _url?: string | undefined;
}

// @public
export interface FullMetadata extends UploadMetadata {
bucket: string;
Expand All @@ -77,6 +131,14 @@ export function getMetadata(ref: StorageReference): Promise<FullMetadata>;
// @public
export function getStorage(app?: FirebaseApp, bucketUrl?: string): FirebaseStorage;

// Warning: (ae-forgotten-export) The symbol "FirebaseStorageError" needs to be exported by the entry point index.d.ts
//
// @internal (undocumented)
export function _invalidArgument(message: string): FirebaseStorageError_2;

// @internal (undocumented)
export function _invalidRootOperation(name: string): FirebaseStorageError_2;

// @public
export function list(ref: StorageReference, options?: ListOptions): Promise<ListResult>;

Expand Down Expand Up @@ -123,18 +185,17 @@ export function ref(storageOrRef: FirebaseStorage | StorageReference, path?: str

// @internal
export class _Reference {
// Warning: (ae-forgotten-export) The symbol "FirebaseStorageImpl" needs to be exported by the entry point index.d.ts
constructor(_service: FirebaseStorageImpl, location: string | _Location);
constructor(_service: _FirebaseStorageImpl, location: string | _Location);
get bucket(): string;
get fullPath(): string;
// (undocumented)
_location: _Location;
get name(): string;
// (undocumented)
protected _newRef(service: FirebaseStorageImpl, location: _Location): _Reference;
protected _newRef(service: _FirebaseStorageImpl, location: _Location): _Reference;
get parent(): _Reference | null;
get root(): _Reference;
get storage(): FirebaseStorageImpl;
get storage(): _FirebaseStorageImpl;
_throwIfRoot(name: string): void;
// @override
toString(): string;
Expand Down Expand Up @@ -187,9 +248,29 @@ export const StringFormat: {
// @public
export type TaskEvent = 'state_changed';

// @public
export type _TaskEvent = string;

// @public
export const _TaskEvent: {
STATE_CHANGED: string;
};

// @public
export type TaskState = 'running' | 'paused' | 'success' | 'canceled' | 'error';

// @public
export type _TaskState = typeof _TaskState[keyof typeof _TaskState];

// @public
export const _TaskState: {
readonly RUNNING: "running";
readonly PAUSED: "paused";
readonly SUCCESS: "success";
readonly CANCELED: "canceled";
readonly ERROR: "error";
};

// @public
export function updateMetadata(ref: StorageReference, metadata: SettableMetadata): Promise<FullMetadata>;

Expand Down Expand Up @@ -232,21 +313,15 @@ export class _UploadTask {
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>;
on(type: _TaskEvent, nextOrObserver?: StorageObserver<UploadTaskSnapshot> | null | ((snapshot: UploadTaskSnapshot) => unknown), error?: ((a: FirebaseStorageError_2) => unknown) | null, completed?: Unsubscribe_2 | null): Unsubscribe_2 | Subscribe_2<UploadTaskSnapshot>;
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;
get snapshot(): UploadTaskSnapshot;
// 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>;
then<U>(onFulfilled?: ((value: UploadTaskSnapshot) => U | Promise<U>) | null, onRejected?: ((error: FirebaseStorageError_2) => U | Promise<U>) | null): Promise<U>;
_transferred: number;
}

Expand Down
2 changes: 1 addition & 1 deletion packages-exp/app-exp/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { name as performanceCompatName } from '../../../packages-exp/performance
import { name as remoteConfigName } from '../../../packages-exp/remote-config-exp/package.json';
import { name as remoteConfigCompatName } from '../../../packages-exp/remote-config-compat/package.json';
import { name as storageName } from '../../../packages/storage/package.json';
import { name as storageCompatName } from '../../../packages/storage/compat/package.json';
import { name as storageCompatName } from '../../../packages/storage-compat/package.json';
import { name as firestoreName } from '../../../packages/firestore/package.json';
import { name as firestoreCompatName } from '../../../packages/firestore/compat/package.json';
import { name as packageName } from '../../../packages-exp/firebase-exp/package.json';
Expand Down
6 changes: 3 additions & 3 deletions packages/rules-unit-testing/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export type FirebaseEmulatorOptions = {

function trimmedBase64Encode(val: string): string {
// Use base64url encoding and remove padding in the end (dot characters).
return base64Encode(val).replace(/\./g, "");
return base64Encode(val).replace(/\./g, '');
}

function createUnsecuredJwt(token: TokenOptions, projectId?: string): string {
Expand Down Expand Up @@ -498,7 +498,7 @@ function initializeApp(
ComponentType.PRIVATE
);

((app as unknown) as _FirebaseApp)._addOrOverwriteComponent(
(app as unknown as _FirebaseApp)._addOrOverwriteComponent(
mockAuthComponent
);
}
Expand Down Expand Up @@ -703,7 +703,7 @@ export function assertFails(pr: Promise<any>): any {
errCode === 'permission-denied' ||
errCode === 'permission_denied' ||
errMessage.indexOf('permission_denied') >= 0 ||
errMessage.indexOf('permission denied') >= 0 ||
errMessage.indexOf('permission denied') >= 0 ||
// Storage permission errors contain message: (storage/unauthorized)
errMessage.indexOf('unauthorized') >= 0;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license
* Copyright 2021 Google LLC
* 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.
Expand All @@ -15,20 +15,23 @@
* limitations under the License.
*/

/**
* Returns an replacement configuration for `@rollup/plugin-alias` that replaces
* references to platform-specific files with implementations for the provided
* target platform.
*/
function generateAliasConfig(platform) {
return {
entries: [
const path = require('path');

module.exports = {
extends: '../../config/.eslintrc.js',
parserOptions: {
project: 'tsconfig.json',
// to make vscode-eslint work with monorepo
// https://github.com/typescript-eslint/typescript-eslint/issues/251#issuecomment-463943250
tsconfigRootDir: __dirname
},
rules: {
'@typescript-eslint/no-unused-vars': [
'error',
{
find: /^(.*)\/platform\/([^.\/]*)(\.ts)?$/,
replacement: `$1\/platform/${platform}/$2.ts`
varsIgnorePattern: '^_',
args: 'none'
}
]
};
}

exports.generateAliasConfig = generateAliasConfig;
}
};
5 changes: 5 additions & 0 deletions packages/storage-compat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @firebase/storage

This is the Cloud Storage component of the Firebase JS SDK.

**This package is not intended for direct usage, and should only be used via the officially supported [firebase](https://www.npmjs.com/package/firebase) package.**
46 changes: 46 additions & 0 deletions packages/storage-compat/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @license
* Copyright 2017 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.
*/

const karmaBase = require('../../config/karma.base');
const { argv } = require('yargs');

module.exports = function (config) {
const karmaConfig = Object.assign({}, karmaBase, {
// files to load into karma
files: getTestFiles(argv),
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha']
});

config.set(karmaConfig);
};

function getTestFiles(argv) {
let unitTestFiles = ['test/unit/*'];
let integrationTestFiles = ['test/integration/*'];

if (argv.unit) {
return unitTestFiles;
} else if (argv.integration) {
return integrationTestFiles;
} else {
return [...unitTestFiles, ...integrationTestFiles];
}
}

module.exports.files = getTestFiles(argv);
49 changes: 49 additions & 0 deletions packages/storage-compat/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "@firebase/storage-compat",
"version": "0.0.900",
"description": "The Firebase Firestore compatibility package",
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
"main": "./dist/index.cjs.js",
"browser": "./dist/index.esm2017.js",
"module": "./dist/index.esm2017.js",
"esm5": "./dist/index.esm5.js",
"license": "Apache-2.0",
"typings": "./dist/src/index.d.ts",
"scripts": {
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
"build": "rollup -c rollup.config.js && yarn add-compat-overloads",
"build:deps": "lerna run --scope @firebase/storage-compat --include-dependencies build",
"dev": "rollup -c -w",
"test": "run-p test:browser test:node lint",
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:browser test:node",
"test:browser:unit": "karma start --single-run --unit",
"test:browser:integration": "karma start --single-run --integration",
"test:browser": "karma start --single-run",
"test:node": "TS_NODE_FILES=true TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --file src/index.ts --config ../../config/mocharc.node.js",
"test:debug": "karma start --browser=Chrome",
"prettier": "prettier --write 'src/**/*.ts' 'test/**/*.ts'",
"add-compat-overloads": "ts-node-script ../../scripts/exp/create-overloads.ts -i ../storage/dist/storage-public.d.ts -o dist/src/index.d.ts -a -r FirebaseStorage:types.FirebaseStorage -r StorageReference:types.Reference -r FirebaseApp:FirebaseAppCompat --moduleToEnhance @firebase/storage"
},
"peerDependencies": {
"@firebase/app-compat": "0.x"
},
"dependencies": {
"@firebase/storage": "0.7.0",
"@firebase/storage-types": "0.5.0",
"@firebase/util": "1.3.0",
"@firebase/component": "0.5.6",
"tslib": "^2.1.0"
},
"devDependencies": {
"@firebase/app-compat": "0.x",
"@firebase/auth-compat": "0.x",
"rollup": "2.52.2",
"@rollup/plugin-json": "4.1.0",
"rollup-plugin-typescript2": "0.30.0",
"typescript": "4.2.2"
},
"files": [
"dist"
]
}
Loading