From a24b78667b6fcba073d00b1126fab345bc0cbc5d Mon Sep 17 00:00:00 2001 From: Josh Crowther Date: Thu, 21 Sep 2017 19:17:28 -0700 Subject: [PATCH] Fixing broken int tests --- integration/typescript/karma.conf.js | 2 +- integration/typescript/package.json | 4 +- .../{src => test}/namespace.test.ts | 0 .../typescript/{src => test}/typings.d.ts | 0 integration/typescript/tsconfig.json | 7 +- packages/firebase/index.d.ts | 586 ++++++++++++++++++ packages/firebase/package.json | 3 +- 7 files changed, 593 insertions(+), 9 deletions(-) rename integration/typescript/{src => test}/namespace.test.ts (100%) rename integration/typescript/{src => test}/typings.d.ts (100%) create mode 100644 packages/firebase/index.d.ts diff --git a/integration/typescript/karma.conf.js b/integration/typescript/karma.conf.js index 695fcaf58a8..90943306531 100644 --- a/integration/typescript/karma.conf.js +++ b/integration/typescript/karma.conf.js @@ -21,7 +21,7 @@ const karmaBase = require('../../config/karma.base'); module.exports = function(config) { const karmaConfig = Object.assign({}, karmaBase, { // files to load into karma - files: [{ pattern: `dist/**/*` }], + files: ['test/**/*.test.*'], // frameworks to use // available frameworks: https://npmjs.org/browse/keyword/karma-adapter frameworks: ['mocha'] diff --git a/integration/typescript/package.json b/integration/typescript/package.json index 164ac7c2acd..d118c2548a7 100644 --- a/integration/typescript/package.json +++ b/integration/typescript/package.json @@ -3,9 +3,7 @@ "private": true, "version": "0.1.0", "scripts": { - "pretest": "tsc", - "test:browser": "karma start --single-run", - "test": "run-p test:browser" + "test": "karma start --single-run" }, "dependencies": { "firebase": "^4.3.3" diff --git a/integration/typescript/src/namespace.test.ts b/integration/typescript/test/namespace.test.ts similarity index 100% rename from integration/typescript/src/namespace.test.ts rename to integration/typescript/test/namespace.test.ts diff --git a/integration/typescript/src/typings.d.ts b/integration/typescript/test/typings.d.ts similarity index 100% rename from integration/typescript/src/typings.d.ts rename to integration/typescript/test/typings.d.ts diff --git a/integration/typescript/tsconfig.json b/integration/typescript/tsconfig.json index f3f69d4b023..2bafd9987e2 100644 --- a/integration/typescript/tsconfig.json +++ b/integration/typescript/tsconfig.json @@ -1,16 +1,15 @@ { + "extends": "../../config/tsconfig.base.json", "compileOnSave": false, "compilerOptions": { "allowJs": true, + "declaration": false, "module": "commonjs", "moduleResolution": "node", "noImplicitAny": true, "outDir": "dist", "target": "ES5", - "sourceMap": true, - "typeRoots" : [ - "node_modules/@types" - ] + "sourceMap": true }, "exclude": [ "node_modules", diff --git a/packages/firebase/index.d.ts b/packages/firebase/index.d.ts new file mode 100644 index 00000000000..3f71bf8c05a --- /dev/null +++ b/packages/firebase/index.d.ts @@ -0,0 +1,586 @@ +/** +* Copyright 2017 Google Inc. +* +* 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. +*/ +declare namespace firebase { + type CompleteFn = () => void; + + interface FirebaseError { + code: string; + message: string; + name: string; + stack?: string; + } + + interface Observer { + complete(): any; + error(error: E): any; + next(value: V | null): any; + } + + var SDK_VERSION: string; + + type Unsubscribe = () => void; + + interface User extends firebase.UserInfo { + delete(): Promise; + emailVerified: boolean; + getIdToken(forceRefresh?: boolean): Promise; + getToken(forceRefresh?: boolean): Promise; + isAnonymous: boolean; + linkAndRetrieveDataWithCredential( + credential: firebase.auth.AuthCredential + ): Promise; + linkWithCredential(credential: firebase.auth.AuthCredential): Promise; + linkWithPhoneNumber( + phoneNumber: string, + applicationVerifier: firebase.auth.ApplicationVerifier + ): Promise; + linkWithPopup(provider: firebase.auth.AuthProvider): Promise; + linkWithRedirect(provider: firebase.auth.AuthProvider): Promise; + phoneNumber: string | null; + providerData: (firebase.UserInfo | null)[]; + reauthenticateAndRetrieveDataWithCredential( + credential: firebase.auth.AuthCredential + ): Promise; + reauthenticateWithCredential( + credential: firebase.auth.AuthCredential + ): Promise; + reauthenticateWithPhoneNumber( + phoneNumber: string, + applicationVerifier: firebase.auth.ApplicationVerifier + ): Promise; + reauthenticateWithPopup(provider: firebase.auth.AuthProvider): Promise; + reauthenticateWithRedirect( + provider: firebase.auth.AuthProvider + ): Promise; + refreshToken: string; + reload(): Promise; + sendEmailVerification( + actionCodeSettings?: firebase.auth.ActionCodeSettings | null + ): Promise; + toJSON(): Object; + unlink(providerId: string): Promise; + updateEmail(newEmail: string): Promise; + updatePassword(newPassword: string): Promise; + updatePhoneNumber( + phoneCredential: firebase.auth.AuthCredential + ): Promise; + updateProfile(profile: { + displayName: string | null; + photoURL: string | null; + }): Promise; + } + + interface UserInfo { + displayName: string | null; + email: string | null; + phoneNumber: string | null; + photoURL: string | null; + providerId: string; + uid: string; + } + + function app(name?: string): firebase.app.App; + + var apps: (firebase.app.App | null)[]; + + function auth(app?: firebase.app.App): firebase.auth.Auth; + + function database(app?: firebase.app.App): firebase.database.Database; + + function initializeApp(options: Object, name?: string): firebase.app.App; + + function messaging(app?: firebase.app.App): firebase.messaging.Messaging; + + function storage(app?: firebase.app.App): firebase.storage.Storage; +} + +declare namespace firebase.app { + interface App { + auth(): firebase.auth.Auth; + database(): firebase.database.Database; + delete(): Promise; + messaging(): firebase.messaging.Messaging; + name: string; + options: Object; + storage(url?: string): firebase.storage.Storage; + } +} + +declare namespace firebase.auth { + interface ActionCodeInfo {} + + type ActionCodeSettings = { + android?: { + installApp?: boolean; + minimumVersion?: string; + packageName: string; + }; + handleCodeInApp?: boolean; + iOS?: { bundleId: string }; + url: string; + }; + + type AdditionalUserInfo = { + profile: Object | null; + providerId: string; + username?: string | null; + }; + + interface ApplicationVerifier { + type: string; + verify(): Promise; + } + + interface Auth { + app: firebase.app.App; + applyActionCode(code: string): Promise; + checkActionCode(code: string): Promise; + confirmPasswordReset(code: string, newPassword: string): Promise; + createUserWithEmailAndPassword( + email: string, + password: string + ): Promise; + currentUser: firebase.User | null; + fetchProvidersForEmail(email: string): Promise; + getRedirectResult(): Promise; + languageCode: string | null; + onAuthStateChanged( + nextOrObserver: + | firebase.Observer + | ((a: firebase.User | null) => any), + error?: (a: firebase.auth.Error) => any, + completed?: firebase.Unsubscribe + ): firebase.Unsubscribe; + onIdTokenChanged( + nextOrObserver: + | firebase.Observer + | ((a: firebase.User | null) => any), + error?: (a: firebase.auth.Error) => any, + completed?: firebase.Unsubscribe + ): firebase.Unsubscribe; + sendPasswordResetEmail( + email: string, + actionCodeSettings?: firebase.auth.ActionCodeSettings | null + ): Promise; + setPersistence(persistence: firebase.auth.Auth.Persistence): Promise; + signInAndRetrieveDataWithCredential( + credential: firebase.auth.AuthCredential + ): Promise; + signInAnonymously(): Promise; + signInWithCredential( + credential: firebase.auth.AuthCredential + ): Promise; + signInWithCustomToken(token: string): Promise; + signInWithEmailAndPassword(email: string, password: string): Promise; + signInWithPhoneNumber( + phoneNumber: string, + applicationVerifier: firebase.auth.ApplicationVerifier + ): Promise; + signInWithPopup(provider: firebase.auth.AuthProvider): Promise; + signInWithRedirect(provider: firebase.auth.AuthProvider): Promise; + signOut(): Promise; + useDeviceLanguage(): any; + verifyPasswordResetCode(code: string): Promise; + } + + interface AuthCredential { + providerId: string; + } + + interface AuthProvider { + providerId: string; + } + + interface ConfirmationResult { + confirm(verificationCode: string): Promise; + verificationId: string; + } + + class EmailAuthProvider extends EmailAuthProvider_Instance { + static PROVIDER_ID: string; + static credential( + email: string, + password: string + ): firebase.auth.AuthCredential; + } + class EmailAuthProvider_Instance implements firebase.auth.AuthProvider { + providerId: string; + } + + interface Error { + code: string; + message: string; + } + + class FacebookAuthProvider extends FacebookAuthProvider_Instance { + static PROVIDER_ID: string; + static credential(token: string): firebase.auth.AuthCredential; + } + class FacebookAuthProvider_Instance implements firebase.auth.AuthProvider { + addScope(scope: string): firebase.auth.AuthProvider; + providerId: string; + setCustomParameters( + customOAuthParameters: Object + ): firebase.auth.AuthProvider; + } + + class GithubAuthProvider extends GithubAuthProvider_Instance { + static PROVIDER_ID: string; + static credential(token: string): firebase.auth.AuthCredential; + } + class GithubAuthProvider_Instance implements firebase.auth.AuthProvider { + addScope(scope: string): firebase.auth.AuthProvider; + providerId: string; + setCustomParameters( + customOAuthParameters: Object + ): firebase.auth.AuthProvider; + } + + class GoogleAuthProvider extends GoogleAuthProvider_Instance { + static PROVIDER_ID: string; + static credential( + idToken?: string | null, + accessToken?: string | null + ): firebase.auth.AuthCredential; + } + class GoogleAuthProvider_Instance implements firebase.auth.AuthProvider { + addScope(scope: string): firebase.auth.AuthProvider; + providerId: string; + setCustomParameters( + customOAuthParameters: Object + ): firebase.auth.AuthProvider; + } + + class PhoneAuthProvider extends PhoneAuthProvider_Instance { + static PROVIDER_ID: string; + static credential( + verificationId: string, + verificationCode: string + ): firebase.auth.AuthCredential; + } + class PhoneAuthProvider_Instance implements firebase.auth.AuthProvider { + constructor(auth?: firebase.auth.Auth | null); + providerId: string; + verifyPhoneNumber( + phoneNumber: string, + applicationVerifier: firebase.auth.ApplicationVerifier + ): Promise; + } + + class RecaptchaVerifier extends RecaptchaVerifier_Instance {} + class RecaptchaVerifier_Instance + implements firebase.auth.ApplicationVerifier { + constructor( + container: any | string, + parameters?: Object | null, + app?: firebase.app.App | null + ); + clear(): any; + render(): Promise; + type: string; + verify(): Promise; + } + + class TwitterAuthProvider extends TwitterAuthProvider_Instance { + static PROVIDER_ID: string; + static credential( + token: string, + secret: string + ): firebase.auth.AuthCredential; + } + class TwitterAuthProvider_Instance implements firebase.auth.AuthProvider { + providerId: string; + setCustomParameters( + customOAuthParameters: Object + ): firebase.auth.AuthProvider; + } + + type UserCredential = { + additionalUserInfo?: firebase.auth.AdditionalUserInfo | null; + credential: firebase.auth.AuthCredential | null; + operationType?: string | null; + user: firebase.User | null; + }; +} + +declare namespace firebase.auth.Auth { + type Persistence = string; + var Persistence: { + LOCAL: Persistence; + NONE: Persistence; + SESSION: Persistence; + }; +} + +declare namespace firebase.database { + interface DataSnapshot { + child(path: string): firebase.database.DataSnapshot; + exists(): boolean; + exportVal(): any; + forEach(action: (a: firebase.database.DataSnapshot) => boolean): boolean; + getPriority(): string | number | null; + hasChild(path: string): boolean; + hasChildren(): boolean; + key: string | null; + numChildren(): number; + ref: firebase.database.Reference; + toJSON(): Object | null; + val(): any; + } + + interface Database { + app: firebase.app.App; + goOffline(): any; + goOnline(): any; + ref(path?: string): firebase.database.Reference; + refFromURL(url: string): firebase.database.Reference; + } + + interface OnDisconnect { + cancel(onComplete?: (a: Error | null) => any): Promise; + remove(onComplete?: (a: Error | null) => any): Promise; + set(value: any, onComplete?: (a: Error | null) => any): Promise; + setWithPriority( + value: any, + priority: number | string | null, + onComplete?: (a: Error | null) => any + ): Promise; + update(values: Object, onComplete?: (a: Error | null) => any): Promise; + } + + interface Query { + endAt( + value: number | string | boolean | null, + key?: string + ): firebase.database.Query; + equalTo( + value: number | string | boolean | null, + key?: string + ): firebase.database.Query; + isEqual(other: firebase.database.Query | null): boolean; + limitToFirst(limit: number): firebase.database.Query; + limitToLast(limit: number): firebase.database.Query; + off( + eventType?: string, + callback?: (a: firebase.database.DataSnapshot, b?: string | null) => any, + context?: Object | null + ): any; + on( + eventType: string, + callback: (a: firebase.database.DataSnapshot | null, b?: string) => any, + cancelCallbackOrContext?: Object | null, + context?: Object | null + ): (a: firebase.database.DataSnapshot | null, b?: string) => any; + once( + eventType: string, + successCallback?: (a: firebase.database.DataSnapshot, b?: string) => any, + failureCallbackOrContext?: Object | null, + context?: Object | null + ): Promise; + orderByChild(path: string): firebase.database.Query; + orderByKey(): firebase.database.Query; + orderByPriority(): firebase.database.Query; + orderByValue(): firebase.database.Query; + ref: firebase.database.Reference; + startAt( + value: number | string | boolean | null, + key?: string + ): firebase.database.Query; + toJSON(): Object; + toString(): string; + } + + interface Reference extends firebase.database.Query { + child(path: string): firebase.database.Reference; + key: string | null; + onDisconnect(): firebase.database.OnDisconnect; + parent: firebase.database.Reference | null; + path: string; + push( + value?: any, + onComplete?: (a: Error | null) => any + ): firebase.database.ThenableReference; + remove(onComplete?: (a: Error | null) => any): Promise; + root: firebase.database.Reference; + set(value: any, onComplete?: (a: Error | null) => any): Promise; + setPriority( + priority: string | number | null, + onComplete: (a: Error | null) => any + ): Promise; + setWithPriority( + newVal: any, + newPriority: string | number | null, + onComplete?: (a: Error | null) => any + ): Promise; + transaction( + transactionUpdate: (a: any) => any, + onComplete?: ( + a: Error | null, + b: boolean, + c: firebase.database.DataSnapshot | null + ) => any, + applyLocally?: boolean + ): Promise; + update(values: Object, onComplete?: (a: Error | null) => any): Promise; + } + + interface ThenableReference + extends firebase.database.Reference, + PromiseLike {} + + function enableLogging( + logger?: boolean | ((a: string) => any), + persistent?: boolean + ): any; +} + +declare namespace firebase.database.ServerValue { + var TIMESTAMP: Object; +} + +declare namespace firebase.messaging { + interface Messaging { + deleteToken(token: string): Promise | null; + getToken(): Promise | null; + onMessage( + nextOrObserver: firebase.Observer | ((a: Object) => any) + ): firebase.Unsubscribe; + onTokenRefresh( + nextOrObserver: firebase.Observer | ((a: Object) => any) + ): firebase.Unsubscribe; + requestPermission(): Promise | null; + setBackgroundMessageHandler(callback: (a: Object) => any): any; + useServiceWorker(registration: any): any; + } +} + +declare namespace firebase.storage { + interface FullMetadata extends firebase.storage.UploadMetadata { + bucket: string; + downloadURLs: string[]; + fullPath: string; + generation: string; + metageneration: string; + name: string; + size: number; + timeCreated: string; + updated: string; + } + + interface Reference { + bucket: string; + child(path: string): firebase.storage.Reference; + delete(): Promise; + fullPath: string; + getDownloadURL(): Promise; + getMetadata(): Promise; + name: string; + parent: firebase.storage.Reference | null; + put( + data: any | any | any, + metadata?: firebase.storage.UploadMetadata + ): firebase.storage.UploadTask; + putString( + data: string, + format?: firebase.storage.StringFormat, + metadata?: firebase.storage.UploadMetadata + ): firebase.storage.UploadTask; + root: firebase.storage.Reference; + storage: firebase.storage.Storage; + toString(): string; + updateMetadata(metadata: firebase.storage.SettableMetadata): Promise; + } + + interface SettableMetadata { + cacheControl?: string | null; + contentDisposition?: string | null; + contentEncoding?: string | null; + contentLanguage?: string | null; + contentType?: string | null; + customMetadata?: { + [/* warning: coerced from ? */ key: string]: string; + } | null; + } + + interface Storage { + app: firebase.app.App; + maxOperationRetryTime: number; + maxUploadRetryTime: number; + ref(path?: string): firebase.storage.Reference; + refFromURL(url: string): firebase.storage.Reference; + setMaxOperationRetryTime(time: number): any; + setMaxUploadRetryTime(time: number): any; + } + + type StringFormat = string; + var StringFormat: { + BASE64: StringFormat; + BASE64URL: StringFormat; + DATA_URL: StringFormat; + RAW: StringFormat; + }; + + type TaskEvent = string; + var TaskEvent: { + STATE_CHANGED: TaskEvent; + }; + + type TaskState = string; + var TaskState: { + CANCELED: TaskState; + ERROR: TaskState; + PAUSED: TaskState; + RUNNING: TaskState; + SUCCESS: TaskState; + }; + + interface UploadMetadata extends firebase.storage.SettableMetadata { + md5Hash?: string | null; + } + + interface UploadTask { + cancel(): boolean; + catch(onRejected: (a: Error) => any): Promise; + on( + event: firebase.storage.TaskEvent, + nextOrObserver?: + | firebase.Observer + | null + | ((a: Object) => any), + error?: ((a: Error) => any) | null, + complete?: (firebase.Unsubscribe) | null + ): Function; + pause(): boolean; + resume(): boolean; + snapshot: firebase.storage.UploadTaskSnapshot; + then( + onFulfilled?: ((a: firebase.storage.UploadTaskSnapshot) => any) | null, + onRejected?: ((a: Error) => any) | null + ): Promise; + } + + interface UploadTaskSnapshot { + bytesTransferred: number; + downloadURL: string | null; + metadata: firebase.storage.FullMetadata; + ref: firebase.storage.Reference; + state: firebase.storage.TaskState; + task: firebase.storage.UploadTask; + totalBytes: number; + } +} + +export = firebase; diff --git a/packages/firebase/package.json b/packages/firebase/package.json index e4dc175472b..f79f3460609 100644 --- a/packages/firebase/package.json +++ b/packages/firebase/package.json @@ -41,5 +41,6 @@ "webpack": "^3.5.6", "webpack-dev-server": "^2.8.1", "wrapper-webpack-plugin": "^1.0.0" - } + }, + "typings": "index.d.ts" }