Skip to content

Commit 2d7e8d4

Browse files
committed
Split storage and storage-compat (#5271)
* separate storage-compat from storage * commit * fix tests * wat? * build storage-compat * save * fixing some compat tests * format * update import path * format * get compat tests to work * format * update package json * cleanup * format * address comments * Update packages/storage-compat/test/unit/service.test.ts Co-authored-by: Christina Holland <[email protected]> * add missing dev dep * Update packages/storage-compat/package.json * Update packages/storage-compat/package.json * Update deps after v8 release * update compat version
1 parent 7818176 commit 2d7e8d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+921
-1258
lines changed

common/api-review/storage.api.md

+89-14
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { EmulatorMockTokenOptions } from '@firebase/util';
1010
import { FirebaseApp } from '@firebase/app';
1111
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
1212
import { FirebaseError } from '@firebase/util';
13-
import { _FirebaseService } from '@firebase/app';
13+
import { _FirebaseService } from '@firebase/app-exp';
1414
import { NextFn } from '@firebase/util';
1515
import { Provider } from '@firebase/component';
1616
import { Subscribe } from '@firebase/util';
@@ -21,6 +21,11 @@ export function connectStorageEmulator(storage: FirebaseStorage, host: string, p
2121
mockUserToken?: EmulatorMockTokenOptions | string;
2222
}): void;
2323

24+
// Warning: (ae-forgotten-export) The symbol "StringData" needs to be exported by the entry point index.d.ts
25+
//
26+
// @internal (undocumented)
27+
export function _dataFromString(format: StringFormat, stringData: string): StringData;
28+
2429
// @public
2530
export function deleteObject(ref: StorageReference): Promise<void>;
2631

@@ -51,6 +56,55 @@ export interface FirebaseStorageError extends FirebaseError {
5156
serverResponse: string | null;
5257
}
5358

59+
// @public
60+
export class _FirebaseStorageImpl implements FirebaseStorage {
61+
constructor(
62+
app: FirebaseApp, _authProvider: Provider<FirebaseAuthInternalName>,
63+
_appCheckProvider: Provider<AppCheckInternalComponentName>,
64+
_pool: ConnectionPool, _url?: string | undefined, _firebaseVersion?: string | undefined);
65+
readonly app: FirebaseApp;
66+
// @internal (undocumented)
67+
readonly _appCheckProvider: Provider<AppCheckInternalComponentName>;
68+
// (undocumented)
69+
protected readonly _appId: string | null;
70+
// (undocumented)
71+
readonly _authProvider: Provider<FirebaseAuthInternalName>;
72+
// Warning: (ae-incompatible-release-tags) The symbol "_bucket" is marked as @public, but its signature references "Location" which is marked as @internal
73+
//
74+
// (undocumented)
75+
_bucket: _Location | null;
76+
_delete(): Promise<void>;
77+
// (undocumented)
78+
readonly _firebaseVersion?: string | undefined;
79+
// (undocumented)
80+
_getAppCheckToken(): Promise<string | null>;
81+
// (undocumented)
82+
_getAuthToken(): Promise<string | null>;
83+
// (undocumented)
84+
get host(): string;
85+
set host(host: string);
86+
// Warning: (ae-forgotten-export) The symbol "RequestInfo" needs to be exported by the entry point index.d.ts
87+
// Warning: (ae-forgotten-export) The symbol "Request" needs to be exported by the entry point index.d.ts
88+
//
89+
// (undocumented)
90+
_makeRequest<T>(requestInfo: RequestInfo_2<T>, authToken: string | null, appCheckToken: string | null): Request_2<T>;
91+
// (undocumented)
92+
makeRequestWithTokens<T>(requestInfo: RequestInfo_2<T>): Promise<Request_2<T>>;
93+
// Warning: (ae-incompatible-release-tags) The symbol "_makeStorageReference" is marked as @public, but its signature references "Location" which is marked as @internal
94+
// Warning: (ae-incompatible-release-tags) The symbol "_makeStorageReference" is marked as @public, but its signature references "Reference" which is marked as @internal
95+
_makeStorageReference(loc: _Location): _Reference;
96+
get maxOperationRetryTime(): number;
97+
set maxOperationRetryTime(time: number);
98+
get maxUploadRetryTime(): number;
99+
set maxUploadRetryTime(time: number);
100+
// Warning: (ae-forgotten-export) The symbol "ConnectionPool" needs to be exported by the entry point index.d.ts
101+
//
102+
// @internal (undocumented)
103+
readonly _pool: ConnectionPool;
104+
// (undocumented)
105+
readonly _url?: string | undefined;
106+
}
107+
54108
// @public
55109
export interface FullMetadata extends UploadMetadata {
56110
bucket: string;
@@ -77,6 +131,14 @@ export function getMetadata(ref: StorageReference): Promise<FullMetadata>;
77131
// @public
78132
export function getStorage(app?: FirebaseApp, bucketUrl?: string): FirebaseStorage;
79133

134+
// Warning: (ae-forgotten-export) The symbol "FirebaseStorageError" needs to be exported by the entry point index.d.ts
135+
//
136+
// @internal (undocumented)
137+
export function _invalidArgument(message: string): FirebaseStorageError_2;
138+
139+
// @internal (undocumented)
140+
export function _invalidRootOperation(name: string): FirebaseStorageError_2;
141+
80142
// @public
81143
export function list(ref: StorageReference, options?: ListOptions): Promise<ListResult>;
82144

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

124186
// @internal
125187
export class _Reference {
126-
// Warning: (ae-forgotten-export) The symbol "FirebaseStorageImpl" needs to be exported by the entry point index.d.ts
127-
constructor(_service: FirebaseStorageImpl, location: string | _Location);
188+
constructor(_service: _FirebaseStorageImpl, location: string | _Location);
128189
get bucket(): string;
129190
get fullPath(): string;
130191
// (undocumented)
131192
_location: _Location;
132193
get name(): string;
133194
// (undocumented)
134-
protected _newRef(service: FirebaseStorageImpl, location: _Location): _Reference;
195+
protected _newRef(service: _FirebaseStorageImpl, location: _Location): _Reference;
135196
get parent(): _Reference | null;
136197
get root(): _Reference;
137-
get storage(): FirebaseStorageImpl;
198+
get storage(): _FirebaseStorageImpl;
138199
_throwIfRoot(name: string): void;
139200
// @override
140201
toString(): string;
@@ -187,9 +248,29 @@ export const StringFormat: {
187248
// @public
188249
export type TaskEvent = 'state_changed';
189250

251+
// @public
252+
export type _TaskEvent = string;
253+
254+
// @public
255+
export const _TaskEvent: {
256+
STATE_CHANGED: string;
257+
};
258+
190259
// @public
191260
export type TaskState = 'running' | 'paused' | 'success' | 'canceled' | 'error';
192261

262+
// @public
263+
export type _TaskState = typeof _TaskState[keyof typeof _TaskState];
264+
265+
// @public
266+
export const _TaskState: {
267+
readonly RUNNING: "running";
268+
readonly PAUSED: "paused";
269+
readonly SUCCESS: "success";
270+
readonly CANCELED: "canceled";
271+
readonly ERROR: "error";
272+
};
273+
193274
// @public
194275
export function updateMetadata(ref: StorageReference, metadata: SettableMetadata): Promise<FullMetadata>;
195276

@@ -232,21 +313,15 @@ export class _UploadTask {
232313
catch<T>(onRejected: (p1: FirebaseStorageError_2) => T | Promise<T>): Promise<T>;
233314
// Warning: (ae-forgotten-export) The symbol "Metadata" needs to be exported by the entry point index.d.ts
234315
_metadata: Metadata | null;
235-
// Warning: (ae-forgotten-export) The symbol "TaskEvent" needs to be exported by the entry point index.d.ts
236-
// Warning: (ae-forgotten-export) The symbol "StorageObserver" needs to be exported by the entry point index.d.ts
237-
// Warning: (ae-forgotten-export) The symbol "ErrorFn" needs to be exported by the entry point index.d.ts
238-
// Warning: (ae-forgotten-export) The symbol "CompleteFn" needs to be exported by the entry point index.d.ts
239316
// Warning: (ae-forgotten-export) The symbol "Unsubscribe" needs to be exported by the entry point index.d.ts
240317
// Warning: (ae-forgotten-export) The symbol "Subscribe" needs to be exported by the entry point index.d.ts
241-
on(type: TaskEvent_2, nextOrObserver?: StorageObserver_2<UploadTaskSnapshot_2> | ((a: UploadTaskSnapshot_2) => unknown), error?: ErrorFn, completed?: CompleteFn_2): Unsubscribe_2 | Subscribe_2<UploadTaskSnapshot_2>;
318+
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>;
242319
pause(): boolean;
243320
resume(): boolean;
244-
// Warning: (ae-forgotten-export) The symbol "UploadTaskSnapshot" needs to be exported by the entry point index.d.ts
245-
get snapshot(): UploadTaskSnapshot_2;
321+
get snapshot(): UploadTaskSnapshot;
246322
// Warning: (ae-forgotten-export) The symbol "InternalTaskState" needs to be exported by the entry point index.d.ts
247323
_state: InternalTaskState;
248-
// Warning: (ae-forgotten-export) The symbol "FirebaseStorageError" needs to be exported by the entry point index.d.ts
249-
then<U>(onFulfilled?: ((value: UploadTaskSnapshot_2) => U | Promise<U>) | null, onRejected?: ((error: FirebaseStorageError_2) => U | Promise<U>) | null): Promise<U>;
324+
then<U>(onFulfilled?: ((value: UploadTaskSnapshot) => U | Promise<U>) | null, onRejected?: ((error: FirebaseStorageError_2) => U | Promise<U>) | null): Promise<U>;
250325
_transferred: number;
251326
}
252327

packages-exp/app-exp/src/constants.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { name as performanceCompatName } from '../../../packages-exp/performance
3636
import { name as remoteConfigName } from '../../../packages-exp/remote-config-exp/package.json';
3737
import { name as remoteConfigCompatName } from '../../../packages-exp/remote-config-compat/package.json';
3838
import { name as storageName } from '../../../packages/storage/package.json';
39-
import { name as storageCompatName } from '../../../packages/storage/compat/package.json';
39+
import { name as storageCompatName } from '../../../packages/storage-compat/package.json';
4040
import { name as firestoreName } from '../../../packages/firestore/package.json';
4141
import { name as firestoreCompatName } from '../../../packages/firestore/compat/package.json';
4242
import { name as packageName } from '../../../packages-exp/firebase-exp/package.json';

packages/rules-unit-testing/src/api/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export type FirebaseEmulatorOptions = {
160160

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

166166
function createUnsecuredJwt(token: TokenOptions, projectId?: string): string {
@@ -498,7 +498,7 @@ function initializeApp(
498498
ComponentType.PRIVATE
499499
);
500500

501-
((app as unknown) as _FirebaseApp)._addOrOverwriteComponent(
501+
(app as unknown as _FirebaseApp)._addOrOverwriteComponent(
502502
mockAuthComponent
503503
);
504504
}
@@ -703,7 +703,7 @@ export function assertFails(pr: Promise<any>): any {
703703
errCode === 'permission-denied' ||
704704
errCode === 'permission_denied' ||
705705
errMessage.indexOf('permission_denied') >= 0 ||
706-
errMessage.indexOf('permission denied') >= 0 ||
706+
errMessage.indexOf('permission denied') >= 0 ||
707707
// Storage permission errors contain message: (storage/unauthorized)
708708
errMessage.indexOf('unauthorized') >= 0;
709709

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2021 Google LLC
3+
* Copyright 2020 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -15,20 +15,23 @@
1515
* limitations under the License.
1616
*/
1717

18-
/**
19-
* Returns an replacement configuration for `@rollup/plugin-alias` that replaces
20-
* references to platform-specific files with implementations for the provided
21-
* target platform.
22-
*/
23-
function generateAliasConfig(platform) {
24-
return {
25-
entries: [
18+
const path = require('path');
19+
20+
module.exports = {
21+
extends: '../../config/.eslintrc.js',
22+
parserOptions: {
23+
project: 'tsconfig.json',
24+
// to make vscode-eslint work with monorepo
25+
// https://github.com/typescript-eslint/typescript-eslint/issues/251#issuecomment-463943250
26+
tsconfigRootDir: __dirname
27+
},
28+
rules: {
29+
'@typescript-eslint/no-unused-vars': [
30+
'error',
2631
{
27-
find: /^(.*)\/platform\/([^.\/]*)(\.ts)?$/,
28-
replacement: `$1\/platform/${platform}/$2.ts`
32+
varsIgnorePattern: '^_',
33+
args: 'none'
2934
}
3035
]
31-
};
32-
}
33-
34-
exports.generateAliasConfig = generateAliasConfig;
36+
}
37+
};

packages/storage-compat/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# @firebase/storage
2+
3+
This is the Cloud Storage component of the Firebase JS SDK.
4+
5+
**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.**

packages/storage-compat/karma.conf.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* @license
3+
* Copyright 2017 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
const karmaBase = require('../../config/karma.base');
19+
const { argv } = require('yargs');
20+
21+
module.exports = function (config) {
22+
const karmaConfig = Object.assign({}, karmaBase, {
23+
// files to load into karma
24+
files: getTestFiles(argv),
25+
// frameworks to use
26+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
27+
frameworks: ['mocha']
28+
});
29+
30+
config.set(karmaConfig);
31+
};
32+
33+
function getTestFiles(argv) {
34+
let unitTestFiles = ['test/unit/*'];
35+
let integrationTestFiles = ['test/integration/*'];
36+
37+
if (argv.unit) {
38+
return unitTestFiles;
39+
} else if (argv.integration) {
40+
return integrationTestFiles;
41+
} else {
42+
return [...unitTestFiles, ...integrationTestFiles];
43+
}
44+
}
45+
46+
module.exports.files = getTestFiles(argv);

packages/storage-compat/package.json

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "@firebase/storage-compat",
3+
"version": "0.0.900",
4+
"description": "The Firebase Firestore compatibility package",
5+
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
6+
"main": "./dist/index.cjs.js",
7+
"browser": "./dist/index.esm2017.js",
8+
"module": "./dist/index.esm2017.js",
9+
"esm5": "./dist/index.esm5.js",
10+
"license": "Apache-2.0",
11+
"typings": "./dist/src/index.d.ts",
12+
"scripts": {
13+
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
14+
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
15+
"build": "rollup -c rollup.config.js && yarn add-compat-overloads",
16+
"build:deps": "lerna run --scope @firebase/storage-compat --include-dependencies build",
17+
"dev": "rollup -c -w",
18+
"test": "run-p test:browser test:node lint",
19+
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:browser test:node",
20+
"test:browser:unit": "karma start --single-run --unit",
21+
"test:browser:integration": "karma start --single-run --integration",
22+
"test:browser": "karma start --single-run",
23+
"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",
24+
"test:debug": "karma start --browser=Chrome",
25+
"prettier": "prettier --write 'src/**/*.ts' 'test/**/*.ts'",
26+
"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"
27+
},
28+
"peerDependencies": {
29+
"@firebase/app-compat": "0.x"
30+
},
31+
"dependencies": {
32+
"@firebase/storage": "0.7.0",
33+
"@firebase/storage-types": "0.5.0",
34+
"@firebase/util": "1.3.0",
35+
"@firebase/component": "0.5.6",
36+
"tslib": "^2.1.0"
37+
},
38+
"devDependencies": {
39+
"@firebase/app-compat": "0.x",
40+
"@firebase/auth-compat": "0.x",
41+
"rollup": "2.52.2",
42+
"@rollup/plugin-json": "4.1.0",
43+
"rollup-plugin-typescript2": "0.30.0",
44+
"typescript": "4.2.2"
45+
},
46+
"files": [
47+
"dist"
48+
]
49+
}

0 commit comments

Comments
 (0)