Skip to content

Commit

Permalink
Merging from dart3a
Browse files Browse the repository at this point in the history
  • Loading branch information
alextekartik committed Apr 2, 2024
2 parents 9917ee0 + 1536715 commit 50a7727
Show file tree
Hide file tree
Showing 15 changed files with 190 additions and 60 deletions.
46 changes: 3 additions & 43 deletions firebase/lib/firebase.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:async';

import 'package:tekartik_firebase/src/utils.dart';
import 'package:tekartik_firebase/src/app_options.dart';
export 'package:tekartik_firebase/src/app_options.dart'
show AppOptions, FirebaseAppOptions, FirebaseAppOptionsMixin;

export 'package:tekartik_firebase/src/firebase.dart'
show firebaseAppNameDefault;
Expand Down Expand Up @@ -45,48 +47,6 @@ abstract class App {
Future addService(FirebaseAppService service);
}

/// This is the new type, App will be deprecated in the future
typedef FirebaseAppOptions = AppOptions;

class AppOptions {
String? apiKey;
String? authDomain;
String? databaseURL;
String? projectId;
String? storageBucket;
String? messagingSenderId;
String? measurementId;
String? appId;

AppOptions(
{this.apiKey,
this.authDomain,
this.databaseURL,
this.projectId,
this.storageBucket,
this.messagingSenderId,
this.appId,
this.measurementId});

AppOptions.fromMap(Map<String, Object?> map) {
apiKey = map['apiKey']?.toString();
authDomain = map['authDomain']?.toString();
databaseURL = map['databaseURL']?.toString();
projectId = map['projectId']?.toString();
storageBucket = map['storageBucket']?.toString();
messagingSenderId = map['messagingSenderId']?.toString();
measurementId = map['measurementId']?.toString();
appId = map['appId']?.toString();
}

Map<String, Object?> toDebugMap() {
return {'apiKey': obfuscate(apiKey), projectId!: projectId};
}

@override
String toString() => toDebugMap().toString();
}

/// Attached firebase service.
///
/// Init is called
Expand Down
143 changes: 143 additions & 0 deletions firebase/lib/src/app_options.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import 'utils.dart';

/// This is the new type, App will be deprecated in the future
typedef FirebaseAppOptions = AppOptions;

class AppOptions {
String? apiKey;
String? authDomain;
String? databaseURL;
String? projectId;
String? storageBucket;
String? messagingSenderId;
String? measurementId;
String? appId;

AppOptions(
{this.apiKey,
this.authDomain,
this.databaseURL,
this.projectId,
this.storageBucket,
this.messagingSenderId,
this.appId,
this.measurementId});

factory AppOptions.fromMap(Map<String, Object?> map) =>
FirebaseAppOptionsFromMap(map);

Map<String, Object?> toDebugMap() {
return {'apiKey': obfuscate(apiKey), projectId!: projectId};
}

@override
String toString() => toDebugMap().toString();
}

class FirebaseAppOptionsFromMap
with FirebaseAppOptionsMixin
implements FirebaseAppOptions {
@override
String? apiKey;
@override
String? authDomain;
@override
String? databaseURL;
@override
String? projectId;
@override
String? storageBucket;
@override
String? messagingSenderId;
@override
String? measurementId;
@override
String? appId;

FirebaseAppOptionsFromMap(Map<String, Object?> map) {
apiKey = map['apiKey']?.toString();
authDomain = map['authDomain']?.toString();
databaseURL = map['databaseURL']?.toString();
projectId = map['projectId']?.toString();
storageBucket = map['storageBucket']?.toString();
messagingSenderId = map['messagingSenderId']?.toString();
measurementId = map['measurementId']?.toString();
appId = map['appId']?.toString();
}

@override
Map<String, Object?> toDebugMap() {
return {'apiKey': obfuscate(apiKey), projectId!: projectId};
}
}

mixin FirebaseAppOptionsMixin implements FirebaseAppOptions {
@override
Map<String, Object?> toDebugMap() {
return {'apiKey': obfuscate(apiKey), projectId!: projectId};
}

@override
String? get apiKey => throw UnimplementedError();

@override
String? get appId => throw UnimplementedError();

@override
String? get authDomain => throw UnimplementedError();

@override
String? get databaseURL => throw UnimplementedError();

@override
String? get measurementId => throw UnimplementedError();

@override
String? get messagingSenderId => throw UnimplementedError();

@override
String? get projectId => throw UnimplementedError();

@override
String? get storageBucket => throw UnimplementedError();

@override
set apiKey(String? apiKey) {
throw UnsupportedError('read only');
}

@override
set appId(String? appId) {
throw UnsupportedError('read only');
}

@override
set authDomain(String? authDomain) {
throw UnsupportedError('read only');
}

@override
set databaseURL(String? databaseURL) {
throw UnsupportedError('read only');
}

@override
set measurementId(String? measurementId) {
throw UnsupportedError('read only');
}

@override
set messagingSenderId(String? messagingSenderId) {
throw UnsupportedError('read only');
}

@override
set projectId(String? projectId) {
throw UnsupportedError('read only');
}

@override
set storageBucket(String? storageBucket) {
throw UnsupportedError('read only');
}
}
4 changes: 2 additions & 2 deletions firebase/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: tekartik_firebase
description: Firebase core
version: 0.9.0
version: 0.9.1
publish_to: none
#homepage: https://www.example.com
#author: alex <email@example.com>

environment:
sdk: '>=3.0.0 <4.0.0'
sdk: '>=3.3.0 <4.0.0'

dependencies:
tekartik_common_utils:
Expand Down
2 changes: 2 additions & 0 deletions firebase/test/firebase_mixin_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class FirebaseAppServiceMock implements FirebaseAppService {
}
}

class FirebaseAppOptionsMock with FirebaseAppOptionsMixin {}

void main() {
group('firebase', () {
test('service', () async {
Expand Down
2 changes: 1 addition & 1 deletion firebase_browser/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: 0.9.0
publish_to: none

environment:
sdk: '>=3.0.0 <4.0.0'
sdk: '>=3.3.0 <4.0.0'

dependencies:
js:
Expand Down
2 changes: 1 addition & 1 deletion firebase_local/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ publish_to: none
#author: alex <email@example.com>

environment:
sdk: '>=3.0.0 <4.0.0'
sdk: '>=3.3.0 <4.0.0'

dependencies:
uuid: '>=1.0.0'
Expand Down
7 changes: 5 additions & 2 deletions firebase_rest/lib/firebase_rest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import 'package:tekartik_firebase/firebase_admin.dart';
import 'package:tekartik_firebase_rest/src/firebase_rest.dart';

export 'package:tekartik_firebase_rest/src/firebase_rest.dart'
show AppOptionsRest, FirebaseAdminCredentialRest;
show
AppOptionsRest,
FirebaseAdminCredentialRest,
FirebaseAdminRestExtension;

export 'src/app_options_access_token.dart' show getAppOptionsFromAccessToken;
export 'src/scopes.dart'
Expand All @@ -21,7 +24,7 @@ abstract class FirebaseRest implements Firebase {}
abstract class FirebaseAdminRest implements FirebaseRest, FirebaseAdmin {}

/// Rest firebase api
FirebaseRest get firebaseRest => impl;
FirebaseAdminRest get firebaseRest => impl;

/// Rest app extension (if any)
abstract class AppRest implements App {
Expand Down
29 changes: 25 additions & 4 deletions firebase_rest/lib/src/firebase_rest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:tekartik_firebase/firebase.dart';
import 'package:tekartik_firebase/firebase_admin.dart';
import 'package:tekartik_firebase/src/firebase_mixin.dart'; // ignore: implementation_imports
import 'package:tekartik_firebase_rest/firebase_rest.dart';

import 'platform.dart';

String get _defaultAppName => firebaseAppNameDefault;
Expand All @@ -14,6 +15,25 @@ abstract class AdminAppOptionsRest implements AppOptionsRest {
Client? get client;
}

/// Rest extension.
extension FirebaseAdminRestExtension on FirebaseAdminRest {
/// Initialize rest with a service account json map.
Future<FirebaseApp> initializeAppWithServiceAccountMap(Map map) async {
var credentials = FirebaseAdminCredentialRest.fromServiceAccountMap(map);
credential.setApplicationDefault(credentials);
return await initializeAppAsync();
}

/// Initialize rest with a service account json string.
Future<FirebaseApp> initializeAppWithServiceAccountString(
String serviceAccountString) async {
var credentials = FirebaseAdminCredentialRest.fromServiceAccountJson(
serviceAccountString);
credential.setApplicationDefault(credentials);
return await initializeAppAsync();
}
}

/// The app options to use for REST app initialization.
abstract class AppOptionsRest extends AppOptions {
/// The http client
Expand Down Expand Up @@ -52,9 +72,7 @@ class AppOptionsRestImpl extends AppOptions implements AppOptionsRest {
}
}

class FirebaseRestImpl
with FirebaseMixin
implements FirebaseRest, FirebaseAdmin {
class FirebaseRestImpl with FirebaseMixin implements FirebaseAdminRest {
@override
App initializeApp({AppOptions? options, String? name}) {
name ??= _defaultAppName;
Expand All @@ -71,9 +89,9 @@ class FirebaseRestImpl

@override
Future<App> initializeAppAsync({AppOptions? options, String? name}) async {
var app = initializeApp(options: options, name: name);
// initialize client
await credential.applicationDefault()?.getAccessToken();
var app = initializeApp(options: options, name: name);
return app;
}

Expand Down Expand Up @@ -173,12 +191,15 @@ class FirebaseAdminCredentialServiceRest
/// Rest credentials implementation
abstract class FirebaseAdminCredentialRest implements FirebaseAdminCredential {
AppOptionsRest? get appOptions;

AuthClient? get authClient;

factory FirebaseAdminCredentialRest.fromServiceAccountJson(
String serviceAccountJson,
{List<String>? scopes}) {
return newFromServiceAccountJson(serviceAccountJson, scopes: scopes);
}

factory FirebaseAdminCredentialRest.fromServiceAccountMap(
Map serviceAccountMap,
{List<String>? scopes}) {
Expand Down
1 change: 1 addition & 0 deletions firebase_rest/lib/src/firebase_rest_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class FirebaseAdminCredentialRestImpl implements FirebaseAdminCredentialRest {
{List<String>? scopes})
: scopes = scopes ?? firebaseBaseScopes {
projectId = serviceAccountMap['project_id']?.toString();

serviceAccountCredentials =
ServiceAccountCredentials.fromJson(serviceAccountMap);
}
Expand Down
4 changes: 2 additions & 2 deletions firebase_rest/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: tekartik_firebase_rest
description: Firebase rest
version: 0.8.3
version: 0.8.4
publish_to: none
#homepage: https://www.example.com
#author: alex <email@example.com>

environment:
sdk: '>=3.0.0 <4.0.0'
sdk: '>=3.3.0 <4.0.0'

dependencies:
uuid: '>=1.0.0'
Expand Down
2 changes: 1 addition & 1 deletion firebase_sim/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ publish_to: none
#author: alex <email@example.com>

environment:
sdk: '>=3.0.0 <4.0.0'
sdk: '>=3.3.0 <4.0.0'

dependencies:
tekartik_firebase:
Expand Down
2 changes: 1 addition & 1 deletion firebase_sim_browser/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ publish_to: none
#author: alex <email@example.com>

environment:
sdk: '>=3.0.0 <4.0.0'
sdk: '>=3.3.0 <4.0.0'

dependencies:
tekartik_firebase_sim:
Expand Down
2 changes: 1 addition & 1 deletion firebase_sim_io/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ publish_to: none
#author: alex <email@example.com>

environment:
sdk: '>=3.0.0 <4.0.0'
sdk: '>=3.3.0 <4.0.0'

dependencies:
tekartik_firebase_sim:
Expand Down
2 changes: 1 addition & 1 deletion firebase_test/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ publish_to: none
#author: alex <email@example.com>

environment:
sdk: '>=3.0.0 <4.0.0'
sdk: '>=3.3.0 <4.0.0'

dependencies:
uuid: '>=1.0.0'
Expand Down
Loading

0 comments on commit 50a7727

Please sign in to comment.