Skip to content

Commit 38ca3bb

Browse files
committed
Set up entry points
1 parent 742477f commit 38ca3bb

File tree

11 files changed

+330
-14
lines changed

11 files changed

+330
-14
lines changed

packages/storage/index.ts renamed to packages/storage/compat/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@
1717

1818
import firebase from '@firebase/app';
1919
import { _FirebaseNamespace } from '@firebase/app-types/private';
20-
import { StringFormat } from './src/implementation/string';
21-
import { TaskEvent, TaskState } from './src/implementation/taskenums';
20+
import { StringFormat } from '../src/implementation/string';
21+
import { TaskEvent, TaskState } from '../src/implementation/taskenums';
2222

23-
import { XhrIoPool } from './src/implementation/xhriopool';
24-
import { Reference } from './src/reference';
25-
import { StorageService } from './src/service';
23+
import { XhrIoPool } from '../src/implementation/xhriopool';
24+
import { ReferenceCompat as Reference } from './reference';
25+
import { StorageServiceCompat as StorageService } from './service';
2626
import * as types from '@firebase/storage-types';
2727
import {
2828
Component,
2929
ComponentType,
3030
ComponentContainer
3131
} from '@firebase/component';
3232

33-
import { name, version } from './package.json';
33+
import { name, version } from '../package.json';
3434

3535
/**
3636
* Type constant for Firebase Storage.

packages/storage/exp-types/index.d.ts

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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+
import { FirebaseApp } from '@firebase/app-types-exp';
19+
import { Observer, Unsubscribe } from '@firebase/util';
20+
21+
export interface FullMetadata extends UploadMetadata {
22+
bucket: string;
23+
fullPath: string;
24+
generation: string;
25+
metageneration: string;
26+
name: string;
27+
size: number;
28+
timeCreated: string;
29+
updated: string;
30+
}
31+
32+
export interface Reference {
33+
bucket: string;
34+
fullPath: string;
35+
name: string;
36+
root: Reference;
37+
storage: Storage;
38+
toString(): string;
39+
}
40+
41+
export interface ListResult {
42+
prefixes: Reference[];
43+
items: Reference[];
44+
nextPageToken: string | null;
45+
}
46+
47+
export interface ListOptions {
48+
maxResults?: number | null;
49+
pageToken?: string | null;
50+
}
51+
52+
export interface SettableMetadata {
53+
cacheControl?: string | null;
54+
contentDisposition?: string | null;
55+
contentEncoding?: string | null;
56+
contentLanguage?: string | null;
57+
contentType?: string | null;
58+
customMetadata?: {
59+
[/* warning: coerced from ? */ key: string]: string;
60+
} | null;
61+
}
62+
63+
export type StringFormat = string;
64+
export type TaskEvent = string;
65+
export type TaskState = string;
66+
67+
export interface UploadMetadata extends SettableMetadata {
68+
md5Hash?: string | null;
69+
}
70+
71+
export interface UploadTask {
72+
cancel(): boolean;
73+
catch(onRejected: (a: Error) => unknown): Promise<unknown>;
74+
on(
75+
event: TaskEvent,
76+
nextOrObserver?:
77+
| Partial<Observer<UploadTaskSnapshot>>
78+
| null
79+
| ((a: UploadTaskSnapshot) => unknown),
80+
error?: ((a: Error) => unknown) | null,
81+
complete?: Unsubscribe | null
82+
): Function;
83+
pause(): boolean;
84+
resume(): boolean;
85+
snapshot: UploadTaskSnapshot;
86+
then(
87+
onFulfilled?: ((a: UploadTaskSnapshot) => unknown) | null,
88+
onRejected?: ((a: Error) => unknown) | null
89+
): Promise<unknown>;
90+
}
91+
92+
export interface UploadTaskSnapshot {
93+
bytesTransferred: number;
94+
metadata: FullMetadata;
95+
ref: Reference;
96+
state: TaskState;
97+
task: UploadTask;
98+
totalBytes: number;
99+
}
100+
101+
export class FirebaseStorage {
102+
private constructor();
103+
104+
app: FirebaseApp | null;
105+
maxOperationRetryTime: number;
106+
maxUploadRetryTime: number;
107+
setMaxOperationRetryTime(time: number): void;
108+
setMaxUploadRetryTime(time: number): void;
109+
}
110+
111+
declare module '@firebase/component' {
112+
interface NameServiceMapping {
113+
'storage-exp': FirebaseStorage;
114+
}
115+
}

packages/storage/exp/api.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @license
3+
* Copyright 2020 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+
import { ref as ref_, StorageService } from '../src/service';
19+
import { Reference } from '../src/reference';
20+
21+
function ref(storage: StorageService, url?: string): Reference | null;
22+
function ref(storage, url): Reference | null {
23+
return ref_(storage, url);
24+
}

packages/storage/exp/index.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* @license
3+
* Copyright 2020 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+
import { _registerComponent, registerVersion } from '@firebase/app-exp';
19+
import { StringFormat } from '../src/implementation/string';
20+
import { TaskEvent, TaskState } from '../src/implementation/taskenums';
21+
22+
import { XhrIoPool } from '../src/implementation/xhriopool';
23+
import { Reference } from '../src/reference';
24+
import { StorageService } from '../src/service';
25+
import {
26+
Component,
27+
ComponentType,
28+
ComponentContainer
29+
} from '@firebase/component';
30+
31+
import { name, version } from '../package.json';
32+
33+
export { ref } from '../src/service';
34+
export {
35+
uploadBytes,
36+
uploadString,
37+
getMetadata,
38+
updateMetadata,
39+
list,
40+
listAll,
41+
getDownloadURL,
42+
deleteObject
43+
} from '../src/reference';
44+
45+
/**
46+
* Type constant for Firebase Storage.
47+
*/
48+
const STORAGE_TYPE = 'storage-exp';
49+
50+
function factory(container: ComponentContainer, url?: string): StorageService {
51+
// Dependencies
52+
const app = container.getProvider('app').getImmediate();
53+
const authProvider = container.getProvider('auth-internal');
54+
55+
return (new StorageService(
56+
app,
57+
authProvider,
58+
new XhrIoPool(),
59+
url
60+
) as unknown) as StorageService;
61+
}
62+
63+
export function registerStorage(): void {
64+
const namespaceExports = {
65+
// no-inline
66+
TaskState,
67+
TaskEvent,
68+
StringFormat,
69+
Storage: StorageService,
70+
Reference
71+
};
72+
_registerComponent(
73+
new Component(STORAGE_TYPE, factory, ComponentType.PUBLIC)
74+
.setServiceProps(namespaceExports)
75+
.setMultipleInstances(true)
76+
);
77+
78+
registerVersion(name, version);
79+
}
80+
81+
registerStorage();

packages/storage/exp/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "@firebase/storage/exp",
3+
"description": "A tree-shakeable version of the Storage SDK",
4+
"main": "../dist/exp/index.cjs.js",
5+
"module": "../dist/exp/index.esm2017.js",
6+
"browser": "../dist/exp/index.esm2017.js",
7+
"typings": "../exp-types/index.d.ts",
8+
"private": true
9+
}

packages/storage/karma.conf.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
const karma = require('karma');
19-
const path = require('path');
2018
const karmaBase = require('../../config/karma.base');
2119
const { argv } = require('yargs');
2220

packages/storage/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"scripts": {
1111
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
1212
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
13-
"build": "rollup -c",
13+
"build": "rollup -c rollup.config.compat.js",
14+
"build:exp": "rollup -c rollup.config.exp.js",
1415
"build:deps": "lerna run --scope @firebase/'{app,storage}' --include-dependencies build",
1516
"dev": "rollup -c -w",
1617
"test": "run-p test:browser lint",
@@ -35,6 +36,7 @@
3536
"devDependencies": {
3637
"@firebase/auth": "0.x",
3738
"rollup": "2.23.0",
39+
"rollup-plugin-json": "4.0.0",
3840
"rollup-plugin-typescript2": "0.27.1",
3941
"typescript": "3.9.6"
4042
},

packages/storage/rollup.config.js renamed to packages/storage/rollup.config.compat.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2018 Google Inc.
3+
* Copyright 2018 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.
@@ -35,7 +35,7 @@ const es5BuildPlugins = [
3535

3636
const es5Builds = [
3737
{
38-
input: 'index.ts',
38+
input: './compat/index.ts',
3939
output: [
4040
{ file: pkg.main, format: 'cjs', sourcemap: true },
4141
{ file: pkg.module, format: 'es', sourcemap: true }
@@ -62,7 +62,7 @@ const es2017BuildPlugins = [
6262

6363
const es2017Builds = [
6464
{
65-
input: 'index.ts',
65+
input: './compat/index.ts',
6666
output: {
6767
file: pkg.esm2017,
6868
format: 'es',
@@ -73,4 +73,5 @@ const es2017Builds = [
7373
}
7474
];
7575

76+
// eslint-disable-next-line import/no-default-export
7677
export default [...es5Builds, ...es2017Builds];

0 commit comments

Comments
 (0)