Skip to content

Commit f11aed7

Browse files
authored
fix(storage): Support typing generation for the storage API (#1019)
* fix(storage): Support typing generation for the storage API * fix(storage): Added newline at eof * fix(storage): Fixing an accidentally inserted import
1 parent ddce5b6 commit f11aed7

File tree

6 files changed

+90
-36
lines changed

6 files changed

+90
-36
lines changed

gulpfile.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ var paths = {
5757
'!src/credential.d.ts',
5858
'!src/database.d.ts',
5959
'!src/instance-id.d.ts',
60-
'!src/security-rules.d.ts',
60+
'!src/messaging.d.ts',
6161
'!src/project-management.d.ts',
6262
'!src/remote-config.d.ts',
63-
'!src/messaging.d.ts',
63+
'!src/security-rules.d.ts',
64+
'!src/storage.d.ts',
6465
],
6566
};
6667

@@ -71,7 +72,6 @@ const TEMPORARY_TYPING_EXCLUDES = [
7172
'!lib/firebase-service.d.ts',
7273
'!lib/auth/*.d.ts',
7374
'!lib/machine-learning/*.d.ts',
74-
'!lib/storage/*.d.ts',
7575
'!lib/utils/*.d.ts',
7676
];
7777

@@ -110,10 +110,10 @@ gulp.task('compile', function() {
110110

111111
// Add header
112112
.pipe(header(banner));
113-
113+
114114
// Exclude typings that are unintended (currently excludes all auto-generated
115115
// typings, but as services are refactored to auto-generate typings this will
116-
// change). Moreover, all *-internal.d.ts typings should not be exposed to
116+
// change). Moreover, all *-internal.d.ts typings should not be exposed to
117117
// developers as it denotes internally used types.
118118
if (declaration) {
119119
const configuration = [
@@ -153,7 +153,7 @@ gulp.task('copyTypings', function() {
153153
let workflow = gulp.src('src/*.d.ts')
154154
// Add header
155155
.pipe(header(banner));
156-
156+
157157
if (declaration) {
158158
workflow = workflow.pipe(filter(paths.curatedTypings));
159159
}

src/index.d.ts

+2-19
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { Bucket } from '@google-cloud/storage';
1817
import * as _firestore from '@google-cloud/firestore';
1918
import { Agent } from 'http';
2019

@@ -26,6 +25,7 @@ import * as _instanceId from './instance-id';
2625
import * as _projectManagement from './project-management';
2726
import * as _remoteConfig from './remote-config';
2827
import * as _securityRules from './security-rules';
28+
import * as _storage from './storage';
2929

3030
/* eslint-disable @typescript-eslint/ban-types */
3131

@@ -651,24 +651,7 @@ declare namespace admin.messaging {
651651
}
652652

653653
declare namespace admin.storage {
654-
655-
/**
656-
* The default `Storage` service if no
657-
* app is provided or the `Storage` service associated with the provided
658-
* app.
659-
*/
660-
interface Storage {
661-
/**
662-
* Optional app whose `Storage` service to
663-
* return. If not provided, the default `Storage` service will be returned.
664-
*/
665-
app: admin.app.App;
666-
/**
667-
* @returns A [Bucket](https://cloud.google.com/nodejs/docs/reference/storage/latest/Bucket)
668-
* instance as defined in the `@google-cloud/storage` package.
669-
*/
670-
bucket(name?: string): Bucket;
671-
}
654+
export import Storage = _storage.admin.storage.Storage;
672655
}
673656

674657
declare namespace admin.firestore {

src/storage.d.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*!
2+
* Copyright 2020 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { Bucket } from '@google-cloud/storage';
18+
import * as _admin from './index.d';
19+
20+
export namespace admin.storage {
21+
22+
/**
23+
* The default `Storage` service if no
24+
* app is provided or the `Storage` service associated with the provided
25+
* app.
26+
*/
27+
export interface Storage {
28+
/**
29+
* Optional app whose `Storage` service to
30+
* return. If not provided, the default `Storage` service will be returned.
31+
*/
32+
app: _admin.app.App;
33+
/**
34+
* @returns A [Bucket](https://cloud.google.com/nodejs/docs/reference/storage/latest/Bucket)
35+
* instance as defined in the `@google-cloud/storage` package.
36+
*/
37+
bucket(name?: string): Bucket;
38+
}
39+
}

src/storage/index.ts

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*!
2+
* Copyright 2020 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import * as _storage from './storage';
18+
import { FirebaseApp } from '../firebase-app';
19+
import * as firebaseAdmin from '../index';
20+
21+
export function storage(app?: FirebaseApp): _storage.Storage {
22+
if (typeof(app) === 'undefined') {
23+
app = firebaseAdmin.app();
24+
}
25+
return app.storage();
26+
}
27+
28+
/* eslint-disable @typescript-eslint/no-namespace */
29+
export namespace admin.storage {
30+
/* eslint-disable @typescript-eslint/no-empty-interface */
31+
export interface Storage extends _storage.Storage {}
32+
}

src/storage/storage.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ class StorageInternals implements FirebaseServiceInternalsInterface {
3939
}
4040

4141
/**
42-
* Storage service bound to the provided app.
42+
* The default `Storage` service if no
43+
* app is provided or the `Storage` service associated with the provided
44+
* app.
4345
*/
4446
export class Storage implements FirebaseServiceInterface {
4547
public readonly INTERNAL: StorageInternals = new StorageInternals();
@@ -50,6 +52,7 @@ export class Storage implements FirebaseServiceInterface {
5052
/**
5153
* @param {FirebaseApp} app The app for this Storage service.
5254
* @constructor
55+
* @internal
5356
*/
5457
constructor(app: FirebaseApp) {
5558
if (!validator.isNonNullObject(app) || !('options' in app)) {
@@ -98,12 +101,10 @@ export class Storage implements FirebaseServiceInterface {
98101
}
99102

100103
/**
101-
* Returns a reference to a Google Cloud Storage bucket. Returned reference can be used to upload
102-
* and download content from Google Cloud Storage.
103-
*
104-
* @param {string=} name Optional name of the bucket to be retrieved. If name is not specified,
105-
* retrieves a reference to the default bucket.
106-
* @return {Bucket} A Bucket object from the @google-cloud/storage library.
104+
* @param name Optional name of the bucket to be retrieved. If name is not specified,
105+
* retrieves a reference to the default bucket.
106+
* @returns A [Bucket](https://cloud.google.com/nodejs/docs/reference/storage/latest/Bucket)
107+
* instance as defined in the `@google-cloud/storage` package.
107108
*/
108109
public bucket(name?: string): Bucket {
109110
const bucketName = (typeof name !== 'undefined')
@@ -120,9 +121,7 @@ export class Storage implements FirebaseServiceInterface {
120121
}
121122

122123
/**
123-
* Returns the app associated with this Storage instance.
124-
*
125-
* @return {FirebaseApp} The app associated with this Storage instance.
124+
* @return The app associated with this Storage instance.
126125
*/
127126
get app(): FirebaseApp {
128127
return this.appInternal;

test/integration/typescript/src/example.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ describe('Init App', () => {
7171
});
7272

7373
it('Should return a Cloud Storage client', () => {
74-
const bucket: Bucket = app.storage().bucket('TestBucket');
74+
const storage: admin.storage.Storage = app.storage();
75+
const bucket: Bucket = storage.bucket('TestBucket');
7576
expect(bucket.name).to.equal('TestBucket');
7677
});
7778

0 commit comments

Comments
 (0)