1 | import * as i0 from '@angular/core';
|
2 | import { InjectionToken, PLATFORM_ID, Injectable, Optional, Inject, NgModule } from '@angular/core';
|
3 | import { of, EMPTY, Observable } from 'rxjs';
|
4 | import { switchMap, map, shareReplay, tap, first } from 'rxjs/operators';
|
5 | import * as i1 from '@angular/fire/compat';
|
6 | import { ɵcacheInstance, ɵlazySDKProxy, ɵapplyMixins } from '@angular/fire/compat';
|
7 | import { isPlatformBrowser } from '@angular/common';
|
8 | import firebase from 'firebase/compat/app';
|
9 | import { VERSION } from '@angular/fire';
|
10 |
|
11 |
|
12 |
|
13 | const proxyPolyfillCompat = {
|
14 | app: null,
|
15 | trace: null,
|
16 | instrumentationEnabled: null,
|
17 | dataCollectionEnabled: null,
|
18 | };
|
19 |
|
20 | const INSTRUMENTATION_ENABLED = new InjectionToken('angularfire2.performance.instrumentationEnabled');
|
21 | const DATA_COLLECTION_ENABLED = new InjectionToken('angularfire2.performance.dataCollectionEnabled');
|
22 | class AngularFirePerformance {
|
23 | constructor(app, instrumentationEnabled, dataCollectionEnabled, zone,
|
24 | // tslint:disable-next-line:ban-types
|
25 | platformId) {
|
26 | this.zone = zone;
|
27 | this.performance = of(undefined).pipe(switchMap(() => isPlatformBrowser(platformId) ? zone.runOutsideAngular(() => import('firebase/compat/performance')) : EMPTY), map(() => ɵcacheInstance(`performance`, 'AngularFirePerformance', app.name, () => {
|
28 | const performance = zone.runOutsideAngular(() => app.performance());
|
29 | if (instrumentationEnabled === false) {
|
30 | performance.instrumentationEnabled = false;
|
31 | }
|
32 | if (dataCollectionEnabled === false) {
|
33 | performance.dataCollectionEnabled = false;
|
34 | }
|
35 | return performance;
|
36 | }, [instrumentationEnabled, dataCollectionEnabled])), shareReplay({ bufferSize: 1, refCount: false }));
|
37 | return ɵlazySDKProxy(this, this.performance, zone);
|
38 | }
|
39 | }
|
40 | AngularFirePerformance.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFirePerformance, deps: [{ token: i1.FirebaseApp }, { token: INSTRUMENTATION_ENABLED, optional: true }, { token: DATA_COLLECTION_ENABLED, optional: true }, { token: i0.NgZone }, { token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable });
|
41 | AngularFirePerformance.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFirePerformance, providedIn: 'any' });
|
42 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFirePerformance, decorators: [{
|
43 | type: Injectable,
|
44 | args: [{
|
45 | providedIn: 'any'
|
46 | }]
|
47 | }], ctorParameters: function () { return [{ type: i1.FirebaseApp }, { type: undefined, decorators: [{
|
48 | type: Optional
|
49 | }, {
|
50 | type: Inject,
|
51 | args: [INSTRUMENTATION_ENABLED]
|
52 | }] }, { type: undefined, decorators: [{
|
53 | type: Optional
|
54 | }, {
|
55 | type: Inject,
|
56 | args: [DATA_COLLECTION_ENABLED]
|
57 | }] }, { type: i0.NgZone }, { type: Object, decorators: [{
|
58 | type: Inject,
|
59 | args: [PLATFORM_ID]
|
60 | }] }]; } });
|
61 | const trace$ = (traceId) => {
|
62 | var _a;
|
63 | if (typeof window !== 'undefined' && ((_a = window.performance) === null || _a === void 0 ? void 0 : _a.mark)) {
|
64 | const entries = window.performance.getEntriesByName(traceId, 'measure') || [];
|
65 | const startMarkName = `_${traceId}Start[${entries.length}]`;
|
66 | const endMarkName = `_${traceId}End[${entries.length}]`;
|
67 | return new Observable(emitter => {
|
68 | window.performance.mark(startMarkName);
|
69 | emitter.next();
|
70 | return {
|
71 | unsubscribe: () => {
|
72 | window.performance.mark(endMarkName);
|
73 | window.performance.measure(traceId, startMarkName, endMarkName);
|
74 | }
|
75 | };
|
76 | });
|
77 | }
|
78 | else {
|
79 | return EMPTY;
|
80 | }
|
81 | };
|
82 | const traceUntil = (name, test, options) => (source$) => new Observable(subscriber => {
|
83 | const traceSubscription = trace$(name).subscribe();
|
84 | return source$.pipe(tap(a => test(a) && traceSubscription.unsubscribe(), () => {
|
85 | }, () => options && options.orComplete && traceSubscription.unsubscribe())).subscribe(subscriber);
|
86 | });
|
87 | const traceWhile = (name, test, options) => (source$) => new Observable(subscriber => {
|
88 | let traceSubscription;
|
89 | return source$.pipe(tap(a => {
|
90 | if (test(a)) {
|
91 | traceSubscription = traceSubscription || trace$(name).subscribe();
|
92 | }
|
93 | else {
|
94 | if (traceSubscription) {
|
95 | traceSubscription.unsubscribe();
|
96 | }
|
97 | traceSubscription = undefined;
|
98 | }
|
99 | }, () => {
|
100 | }, () => options && options.orComplete && traceSubscription && traceSubscription.unsubscribe())).subscribe(subscriber);
|
101 | });
|
102 | const traceUntilComplete = (name) => (source$) => new Observable(subscriber => {
|
103 | const traceSubscription = trace$(name).subscribe();
|
104 | return source$.pipe(tap(() => {
|
105 | }, () => {
|
106 | }, () => traceSubscription.unsubscribe())).subscribe(subscriber);
|
107 | });
|
108 | const traceUntilFirst = (name) => (source$) => new Observable(subscriber => {
|
109 | const traceSubscription = trace$(name).subscribe();
|
110 | return source$.pipe(tap(() => traceSubscription.unsubscribe(), () => {
|
111 | }, () => {
|
112 | })).subscribe(subscriber);
|
113 | });
|
114 | const trace = (name) => (source$) => new Observable(subscriber => {
|
115 | const traceSubscription = trace$(name).subscribe();
|
116 | return source$.pipe(tap(() => traceSubscription.unsubscribe(), () => {
|
117 | }, () => traceSubscription.unsubscribe())).subscribe(subscriber);
|
118 | });
|
119 | ɵapplyMixins(AngularFirePerformance, [proxyPolyfillCompat]);
|
120 |
|
121 | const IS_STABLE_START_MARK = 'Zone';
|
122 | const IS_STABLE_END_MARK = '_isStableEnd';
|
123 | class PerformanceMonitoringService {
|
124 | constructor(appRef) {
|
125 | var _a;
|
126 | if (typeof window !== 'undefined' && ((_a = window.performance) === null || _a === void 0 ? void 0 : _a.mark)) {
|
127 | this.disposable = appRef.isStable.pipe(first(it => it), tap(() => {
|
128 | window.performance.mark(IS_STABLE_END_MARK);
|
129 | window.performance.measure('isStable', IS_STABLE_START_MARK, IS_STABLE_END_MARK);
|
130 | })).subscribe();
|
131 | }
|
132 | }
|
133 | ngOnDestroy() {
|
134 | if (this.disposable) {
|
135 | this.disposable.unsubscribe();
|
136 | }
|
137 | }
|
138 | }
|
139 | PerformanceMonitoringService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: PerformanceMonitoringService, deps: [{ token: i0.ApplicationRef }], target: i0.ɵɵFactoryTarget.Injectable });
|
140 | PerformanceMonitoringService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: PerformanceMonitoringService });
|
141 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: PerformanceMonitoringService, decorators: [{
|
142 | type: Injectable
|
143 | }], ctorParameters: function () { return [{ type: i0.ApplicationRef }]; } });
|
144 |
|
145 | class AngularFirePerformanceModule {
|
146 | constructor(perf, _) {
|
147 | firebase.registerVersion('angularfire', VERSION.full, 'perf-compat');
|
148 |
|
149 |
|
150 | perf.dataCollectionEnabled.then(() => { });
|
151 | }
|
152 | }
|
153 | AngularFirePerformanceModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFirePerformanceModule, deps: [{ token: AngularFirePerformance }, { token: PerformanceMonitoringService, optional: true }], target: i0.ɵɵFactoryTarget.NgModule });
|
154 | AngularFirePerformanceModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFirePerformanceModule });
|
155 | AngularFirePerformanceModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFirePerformanceModule, providers: [AngularFirePerformance] });
|
156 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFirePerformanceModule, decorators: [{
|
157 | type: NgModule,
|
158 | args: [{
|
159 | providers: [AngularFirePerformance]
|
160 | }]
|
161 | }], ctorParameters: function () { return [{ type: AngularFirePerformance }, { type: PerformanceMonitoringService, decorators: [{
|
162 | type: Optional
|
163 | }] }]; } });
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 | export { AngularFirePerformance, AngularFirePerformanceModule, DATA_COLLECTION_ENABLED, INSTRUMENTATION_ENABLED, PerformanceMonitoringService, trace, traceUntil, traceUntilComplete, traceUntilFirst, traceWhile };
|
170 |
|