Skip to content

Commit 755ab85

Browse files
committed
First.
1 parent d34bf2f commit 755ab85

15 files changed

+232
-0
lines changed

firebase-performance-0.0.3.tgz

170 KB
Binary file not shown.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@angular/core": ">=6.0.0 <8",
3636
"@angular/platform-browser": ">=6.0.0 <8",
3737
"@angular/platform-browser-dynamic": ">=6.0.0 <8",
38+
"@firebase/performance": "file:firebase-performance-0.0.3.tgz",
3839
"firebase": "^5.5.0",
3940
"rxjs": "^6.0.0",
4041
"ws": "^3.3.2",

src/core/firebase.app.module.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { InjectionToken, NgModule, Optional } from '@angular/core';
22
import { app, auth, database, firestore, functions, messaging, storage } from 'firebase/app';
3+
import { PerformanceController } from '@firebase/performance/dist/src/controllers/perf';
4+
35
// @ts-ignore (https://github.com/firebase/firebase-js-sdk/pull/1206)
46
import firebase from 'firebase/app'; // once fixed can pull in as "default as firebase" above
57

@@ -28,6 +30,7 @@ export class FirebaseApp implements app.App {
2830
// automaticDataCollectionEnabled is now private? _automaticDataCollectionEnabled?
2931
// automaticDataCollectionEnabled: true,
3032
messaging: () => FirebaseMessaging;
33+
performance: () => PerformanceController;
3134
storage: (storageBucket?: string) => FirebaseStorage;
3235
delete: () => Promise<void>;
3336
firestore: () => FirebaseFirestore;

src/performance/index.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './performance.spec';

src/performance/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './public_api';

src/performance/package.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "@angular/fire/performance",
3+
"version": "ANGULARFIRE2_VERSION",
4+
"description": "The performance monitoring module",
5+
"main": "../bundles/performance.umd.js",
6+
"module": "index.js",
7+
"es2015": "./es2015/index.js",
8+
"keywords": [
9+
"angular",
10+
"firebase",
11+
"rxjs"
12+
],
13+
"repository": {
14+
"type": "git",
15+
"url": "git+https://github.com/angular/angularfire2.git"
16+
},
17+
"author": "angular,firebase",
18+
"license": "MIT",
19+
"peerDependencies": {
20+
"@angular/fire": "ANGULARFIRE2_VERSION",
21+
"@angular/common": "ANGULAR_VERSION",
22+
"@angular/core": "ANGULAR_VERSION",
23+
"@angular/platform-browser": "ANGULAR_VERSION",
24+
"@angular/platform-browser-dynamic": "ANGULAR_VERSION",
25+
"@firebase/app": "FIREBASE_APP_VERSION",
26+
"@firebase/messaging": "FIREBASE_MESSAGING_VERSION",
27+
"rxjs": "RXJS_VERSION",
28+
"zone.js": "ZONEJS_VERSION"
29+
},
30+
"typings": "index.d.ts"
31+
}

src/performance/performance.module.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { NgModule } from '@angular/core';
2+
import { AngularFirePerformance } from './performance';
3+
4+
import 'firebase/perf';
5+
6+
@NgModule({
7+
providers: [ AngularFirePerformance ]
8+
})
9+
export class AngularFirePerformanceModule { }

src/performance/performance.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {}

src/performance/performance.ts

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import { Injectable, Inject, Optional, NgZone, ApplicationRef } from '@angular/core';
2+
import { Observable } from 'rxjs';
3+
import { filter, tap, take } from 'rxjs/operators';
4+
import { FirebaseOptions, FirebaseAppConfig } from '@angular/fire';
5+
import { FirebaseOptionsToken, FirebaseNameOrConfigToken, _firebaseAppFactory } from '@angular/fire';
6+
import { PerformanceController } from '@firebase/performance/dist/src/controllers/perf';
7+
8+
export type TraceOptions = {
9+
metrics: {[key:string]: number},
10+
attributes?:{[key:string]:string},
11+
attribute$?:{[key:string]:Observable<string>},
12+
incrementMetric$:{[key:string]: Observable<number|void|null|undefined>},
13+
metric$?:{[key:string]: Observable<number>}
14+
};
15+
16+
@Injectable()
17+
export class AngularFirePerformance {
18+
19+
performance: PerformanceController;
20+
21+
constructor(
22+
@Inject(FirebaseOptionsToken) options:FirebaseOptions,
23+
@Optional() @Inject(FirebaseNameOrConfigToken) nameOrConfig:string|FirebaseAppConfig|null|undefined,
24+
appRef: ApplicationRef,
25+
private zone: NgZone
26+
) {
27+
28+
this.performance = zone.runOutsideAngular(() => {
29+
const app = _firebaseAppFactory(options, nameOrConfig);
30+
return app.performance();
31+
});
32+
33+
// TODO detirmine more built in metrics
34+
appRef.isStable.pipe(
35+
this.traceComplete('isStable'),
36+
filter(it => it),
37+
take(1)
38+
).subscribe();
39+
40+
}
41+
42+
trace$ = (name:string, options?: TraceOptions) => new Observable<void>(emitter =>
43+
this.zone.runOutsideAngular(() => {
44+
const trace = this.performance.trace(name);
45+
options && options.metrics && Object.keys(options.metrics).forEach(metric => {
46+
trace.putMetric(metric, options!.metrics![metric])
47+
});
48+
options && options.attributes && Object.keys(options.attributes).forEach(attribute => {
49+
trace.putAttribute(attribute, options!.attributes![attribute])
50+
});
51+
const attributeSubscriptions = options && options.attribute$ ? Object.keys(options.attribute$).map(attribute =>
52+
options!.attribute$![attribute].subscribe(next => trace.putAttribute(attribute, next))
53+
) : [];
54+
const metricSubscriptions = options && options.metric$ ? Object.keys(options.metric$).map(metric =>
55+
options!.metric$![metric].subscribe(next => trace.putMetric(metric, next))
56+
) : [];
57+
const incrementOnSubscriptions = options && options.incrementMetric$ ? Object.keys(options.incrementMetric$).map(metric =>
58+
options!.incrementMetric$![metric].subscribe(next => trace.incrementMetric(metric, next || undefined))
59+
) : [];
60+
emitter.next(trace.start());
61+
return { unsubscribe: () => {
62+
trace.stop();
63+
metricSubscriptions.forEach(m => m.unsubscribe());
64+
incrementOnSubscriptions.forEach(m => m.unsubscribe());
65+
attributeSubscriptions.forEach(m => m.unsubscribe());
66+
}};
67+
})
68+
);
69+
70+
traceUntil = <T=any>(name:string, test: (a:T) => boolean, options?: TraceOptions) => (source$: Observable<T>) => {
71+
const traceSubscription = this.trace$(name, options).subscribe();
72+
return source$.pipe(
73+
tap(a => { if (test(a)) { traceSubscription.unsubscribe() }})
74+
)
75+
};
76+
77+
traceComplete = <T=any>(name:string, options?: TraceOptions) => (source$: Observable<T>) => {
78+
const traceSubscription = this.trace$(name, options).subscribe();
79+
return source$.pipe(
80+
tap(
81+
() => {},
82+
() => {},
83+
() => traceSubscription.unsubscribe()
84+
)
85+
)
86+
};
87+
88+
trace = <T=any>(name:string, options?: TraceOptions) => (source$: Observable<T>) => {
89+
const traceSubscription = this.trace$(name, options).subscribe();
90+
return source$.pipe(
91+
tap(
92+
() => traceSubscription.unsubscribe(),
93+
() => {},
94+
() => traceSubscription.unsubscribe()
95+
)
96+
)
97+
};
98+
99+
}

src/performance/public_api.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './performance';
2+
export * from './performance.module';

src/performance/test-config.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
export const COMMON_CONFIG = {
3+
apiKey: "AIzaSyBVSy3YpkVGiKXbbxeK0qBnu3-MNZ9UIjA",
4+
authDomain: "angularfire2-test.firebaseapp.com",
5+
databaseURL: "https://angularfire2-test.firebaseio.com",
6+
storageBucket: "angularfire2-test.appspot.com",
7+
messagingSenderId: "920323787688"
8+
};

src/performance/tsconfig-build.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": ".",
4+
"experimentalDecorators": true,
5+
"emitDecoratorMetadata": true,
6+
"module": "es2015",
7+
"target": "es2015",
8+
"noImplicitAny": false,
9+
"outDir": "../../dist/packages-dist/performance/es2015",
10+
"rootDir": ".",
11+
"sourceMap": true,
12+
"inlineSources": true,
13+
"declaration": false,
14+
"removeComments": true,
15+
"strictNullChecks": true,
16+
"lib": ["es2015", "dom", "es2015.promise", "es2015.collection", "es2015.iterable"],
17+
"skipLibCheck": true,
18+
"moduleResolution": "node",
19+
"paths": {
20+
"@angular/fire": ["../../dist/packages-dist"]
21+
}
22+
},
23+
"files": [
24+
"index.ts",
25+
"../../node_modules/zone.js/dist/zone.js.d.ts"
26+
],
27+
"angularCompilerOptions": {
28+
"skipTemplateCodegen": true,
29+
"strictMetadataEmit": true,
30+
"enableSummariesForJit": false
31+
}
32+
}
33+

src/performance/tsconfig-esm.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"extends": "./tsconfig-build.json",
3+
"compilerOptions": {
4+
"target": "es5",
5+
"outDir": "../../dist/packages-dist/performance",
6+
"declaration": true
7+
},
8+
"files": [
9+
"public_api.ts",
10+
"../../node_modules/zone.js/dist/zone.js.d.ts"
11+
],
12+
"angularCompilerOptions": {
13+
"skipTemplateCodegen": true,
14+
"strictMetadataEmit": true,
15+
"enableSummariesForJit": false,
16+
"flatModuleOutFile": "index.js",
17+
"flatModuleId": "@angular/fire/performance"
18+
}
19+
}

src/performance/tsconfig-test.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": "./tsconfig-esm.json",
3+
"compilerOptions": {
4+
"baseUrl": ".",
5+
"paths": {
6+
"@angular/fire": ["../../dist/packages-dist"]
7+
}
8+
},
9+
"files": [
10+
"index.spec.ts",
11+
"../../node_modules/zone.js/dist/zone.js.d.ts"
12+
]
13+
}

tools/build.js

+11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const GLOBALS = {
2323
'firebase/messaging': 'firebase',
2424
'firebase/firestore': 'firebase',
2525
'firebase/functions': 'firebase',
26+
'firebase/perf': 'firebase',
2627
'firebase/storage': 'firebase',
2728
'@angular/fire': 'angularfire2',
2829
'@angular/fire/auth': 'angularfire2.auth',
@@ -32,6 +33,7 @@ const GLOBALS = {
3233
'@angular/fire/functions': 'angularfire2.functions',
3334
'@angular/fire/storage': 'angularfire2.storage',
3435
'@angular/fire/messaging': 'angularfire2.messaging',
36+
'@angular/fire/performance': 'angularfire2.performance'
3537
};
3638

3739
// Map of dependency versions across all packages
@@ -57,6 +59,7 @@ const MODULE_NAMES = {
5759
functions: 'angularfire2.functions',
5860
storage: 'angularfire2.storage',
5961
messaging: 'angularfire2.messaging',
62+
performance: 'angularfire2.performance'
6063
};
6164

6265
const ENTRIES = {
@@ -68,6 +71,7 @@ const ENTRIES = {
6871
functions: `${process.cwd()}/dist/packages-dist/functions/index.js`,
6972
storage: `${process.cwd()}/dist/packages-dist/storage/index.js`,
7073
messaging: `${process.cwd()}/dist/packages-dist/messaging/index.js`,
74+
performance: `${process.cwd()}/dist/packages-dist/performance/index.js`
7175
};
7276

7377
const SRC_PKG_PATHS = {
@@ -80,6 +84,7 @@ const SRC_PKG_PATHS = {
8084
functions: `${process.cwd()}/src/functions/package.json`,
8185
storage: `${process.cwd()}/src/storage/package.json`,
8286
messaging: `${process.cwd()}/src/messaging/package.json`,
87+
performance: `${process.cwd()}/src/performance/package.json`
8388
};
8489

8590
const DEST_PKG_PATHS = {
@@ -92,6 +97,7 @@ const DEST_PKG_PATHS = {
9297
functions: `${process.cwd()}/dist/packages-dist/functions/package.json`,
9398
storage: `${process.cwd()}/dist/packages-dist/storage/package.json`,
9499
messaging: `${process.cwd()}/dist/packages-dist/messaging/package.json`,
100+
performance: `${process.cwd()}/dist/packages-dist/performance/package.json`
95101
};
96102

97103
// Constants for running typescript commands
@@ -262,6 +268,7 @@ function getVersions() {
262268
getDestPackageFile('functions'),
263269
getDestPackageFile('storage'),
264270
getDestPackageFile('messaging'),
271+
getDestPackageFile('performance'),
265272
getDestPackageFile('database-deprecated')
266273
];
267274
return paths
@@ -302,6 +309,7 @@ function buildModules(globals) {
302309
const functions$ = buildModule('functions', globals);
303310
const storage$ = buildModule('storage', globals);
304311
const messaging$ = buildModule('messaging', globals);
312+
const performance$ = buildModule('performance', globals);
305313
const dbdep$ = buildModule('database-deprecated', globals);
306314
return forkJoin(core$, from(copyRootTest())).pipe(
307315
switchMapTo(auth$),
@@ -310,6 +318,7 @@ function buildModules(globals) {
310318
switchMapTo(functions$),
311319
switchMapTo(storage$),
312320
switchMapTo(messaging$),
321+
switchMapTo(performance$),
313322
switchMapTo(dbdep$)
314323
);
315324
}
@@ -331,6 +340,7 @@ function buildLibrary(globals) {
331340
const functionsStats = measure('functions');
332341
const storageStats = measure('storage');
333342
const messagingStats = measure('messaging');
343+
const performanceStats = measure('performance');
334344
const dbdepStats = measure('database-deprecated');
335345
console.log(`
336346
core.umd.js - ${coreStats.size}, ${coreStats.gzip}
@@ -340,6 +350,7 @@ function buildLibrary(globals) {
340350
functions.umd.js - ${functionsStats.size}, ${functionsStats.gzip}
341351
storage.umd.js - ${storageStats.size}, ${storageStats.gzip}
342352
messaging.umd.js - ${messagingStats.size}, ${messagingStats.gzip}
353+
performance.umd.js - ${performanceStats.size}, ${performanceStats.gzip}
343354
database-deprecated.umd.js - ${dbdepStats.size}, ${dbdepStats.gzip}
344355
`);
345356
verifyVersions();

0 commit comments

Comments
 (0)