Skip to content

Commit e752acb

Browse files
committed
feat: introduce async Firebase interfaces and restructure FirebaseApp, add projectId getter on FirebaseApp
1 parent cca32b0 commit e752acb

File tree

8 files changed

+82
-81
lines changed

8 files changed

+82
-81
lines changed

firebase/lib/firebase.dart

Lines changed: 4 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,11 @@
1-
import 'dart:async';
2-
3-
import 'firebase_mixin.dart';
4-
import 'src/app_options.dart';
5-
import 'src/firebase_product_service.dart';
61
export 'package:tekartik_firebase/src/app_options.dart'
72
show AppOptions, FirebaseAppOptions, FirebaseAppOptionsMixin;
8-
9-
export 'package:tekartik_firebase/src/firebase.dart'
10-
show firebaseAppNameDefault;
113
export 'package:tekartik_firebase/src/firebase_app_product.dart'
124
show FirebaseAppProductService, FirebaseAppProduct;
135
export 'package:tekartik_firebase/src/firebase_mixin.dart'
146
show FirebaseProductServiceMixin;
15-
export 'src/firebase_product_service.dart' show FirebaseProductService;
16-
17-
/// Async interface, needed for flutter.
18-
abstract class FirebaseAsync {
19-
/// Initialize the app with the given options.
20-
Future<App> initializeAppAsync({AppOptions? options, String? name});
21-
22-
/// Retrieves an existing instance of an App.
23-
Future<App> appAsync({String? name});
24-
}
25-
26-
/// Firebase interface.
27-
abstract class Firebase extends FirebaseAsync {
28-
/// Initialize the app with the given options.
29-
// @deprecated use async version
30-
App initializeApp({AppOptions? options, String? name});
31-
32-
/// Retrieves an existing instance of an App.
33-
App app({String? name});
34-
35-
/// True if firebase is local (i.e. FirebaseLocal, not rest, nor node, nor flutter
36-
bool get isLocal;
37-
}
38-
39-
/// This is the new type, App will be deprecated in the future
40-
typedef App = FirebaseApp;
417

42-
/// Firebase app.
43-
abstract class FirebaseApp {
44-
/// The app name
45-
String get name;
46-
47-
/// The app options
48-
AppOptions get options;
49-
50-
/// Deletes this app and frees up system resources.
51-
///
52-
/// Once deleted, any plugin functionality using this app instance will throw
53-
/// an error.
54-
///
55-
/// Deleting the default app is not possible and throws an exception.
56-
Future<void> delete();
57-
58-
/// Add a service and calls its init method.
59-
///
60-
/// Upon delete, close will be called
61-
Future<void> addService(FirebaseProductService service);
62-
63-
/// Get firebase
64-
Firebase get firebase;
65-
66-
/// True if local (nor node, nor rest, nor flutter)
67-
bool get isLocal;
68-
69-
/// True if it has admin credentials
70-
bool get hasAdminCredentials;
71-
72-
/// The latest initialized firebase app instance.
73-
static FirebaseApp get instance =>
74-
FirebaseMixin.latestFirebaseInstanceOrNull!;
75-
}
8+
export 'src/firebase.dart' show Firebase, FirebaseAsync;
9+
export 'src/firebase_app.dart'
10+
show firebaseAppNameDefault, FirebaseApp, App, TekartikFirebaseAppExt;
11+
export 'src/firebase_product_service.dart' show FirebaseProductService;

firebase/lib/src/firebase.dart

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
import 'package:tekartik_firebase/firebase.dart';
22

3-
/// The default [FirebaseApp] name.
4-
const firebaseAppNameDefault = '[DEFAULT]';
3+
/// Async interface, needed for flutter.
4+
abstract class FirebaseAsync {
5+
/// Initialize the app with the given options.
6+
Future<App> initializeAppAsync({AppOptions? options, String? name});
7+
8+
/// Retrieves an existing instance of an App.
9+
Future<App> appAsync({String? name});
10+
}
11+
12+
/// Firebase interface.
13+
abstract class Firebase extends FirebaseAsync {
14+
/// Initialize the app with the given options.
15+
// @deprecated use async version
16+
App initializeApp({AppOptions? options, String? name});
17+
18+
/// Retrieves an existing instance of an App.
19+
App app({String? name});
20+
21+
/// True if firebase is local (i.e. FirebaseLocal, not rest, nor node, nor flutter
22+
bool get isLocal;
23+
}

firebase/lib/src/firebase_app.dart

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import 'app_options.dart';
2+
import 'firebase.dart';
3+
import 'firebase_mixin.dart';
4+
import 'firebase_product_service.dart';
5+
6+
/// The default [FirebaseApp] name.
7+
const firebaseAppNameDefault = '[DEFAULT]';
8+
9+
/// This is the new type, App will be deprecated in the future
10+
typedef App = FirebaseApp;
11+
12+
/// Firebase app.
13+
abstract class FirebaseApp {
14+
/// The app name
15+
String get name;
16+
17+
/// The app options
18+
FirebaseAppOptions get options;
19+
20+
/// Deletes this app and frees up system resources.
21+
///
22+
/// Once deleted, any plugin functionality using this app instance will throw
23+
/// an error.
24+
///
25+
/// Deleting the default app is not possible and throws an exception.
26+
Future<void> delete();
27+
28+
/// Add a service and calls its init method.
29+
///
30+
/// Upon delete, close will be called
31+
Future<void> addService(FirebaseProductService service);
32+
33+
/// Get firebase
34+
Firebase get firebase;
35+
36+
/// True if local (nor node, nor rest, nor flutter)
37+
bool get isLocal;
38+
39+
/// True if it has admin credentials
40+
bool get hasAdminCredentials;
41+
42+
/// The latest initialized firebase app instance.
43+
static FirebaseApp get instance =>
44+
FirebaseMixin.latestFirebaseInstanceOrNull!;
45+
}
46+
47+
/// Firebase app extensions
48+
extension TekartikFirebaseAppExt on FirebaseApp {
49+
/// Project id should never be null!
50+
String get projectId => options.projectId!;
51+
}

firebase/test/firebase_mixin_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ void main() {
126126
test('service', () async {
127127
var firebase = FirebaseMock();
128128
var app = firebase.initializeApp();
129+
expect(app.projectId, _defaultProjectId);
129130
expect(app.hasAdminCredentials, isFalse);
130131
expect(FirebaseApp.instance, app);
131132

firebase_local/test/firebase_local_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ void main() {
1919
var firebase = FirebaseLocal();
2020
var app = firebase.initializeApp(options: AppOptions(projectId: 'test'));
2121
expect(FirebaseMixin.latestFirebaseInstanceOrNull, app);
22+
expect(app.name, '[DEFAULT]');
23+
expect(app.projectId, 'test');
2224
});
2325
test('projectId', () async {
2426
var firebase = FirebaseLocal();

firebase_sim/test/firebase_app_sim_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ void run(TestContext testContext) {
2626
setUpAll(() {
2727
app = testContext.firebase.initializeApp(name: 'test_sim') as AppSim;
2828
expect(FirebaseApp.instance, app);
29+
expect(app.name, 'test_sim');
30+
expect(app.projectId, 'sim');
2931
});
3032
tearDownAll(() async {
3133
await app.delete();

firebase_test/lib/firebase_app_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ void runFirebaseAppTests(
1212
var firebaseApp = getFirebaseApp();
1313
expect(firebaseApp.isLocal, firebaseApp.isLocal);
1414
expect(firebaseApp.options.projectId, isNotNull);
15+
expect(firebaseApp.projectId, firebaseApp.options.projectId);
1516
});
1617
}

firebase_test/tool/travis.dart

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)