Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions examples/firebase/celest/client/lib/firebase_test_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ enum CelestEnvironment {
local;

Uri get baseUri => switch (this) {
local => _$celest.kIsWeb || !Platform.isAndroid
? Uri.parse('http://localhost:7777')
: Uri.parse('http://10.0.2.2:7777'),
};
local =>
_$celest.kIsWeb || !Platform.isAndroid
? Uri.parse('http://localhost:7777')
: Uri.parse('http://10.0.2.2:7777'),
};
}

class Celest with _$celest.CelestBase {
Expand All @@ -41,22 +42,21 @@ class Celest with _$celest.CelestBase {
_$native_storage_native_storage.NativeStorage(scope: 'celest');

@override
late _$http_http.Client httpClient =
_$celest.CelestHttpClient(secureStorage: nativeStorage.secure);
late _$http_http.Client httpClient = _$celest.CelestHttpClient(
secureStorage: nativeStorage.secure,
);

late Uri _baseUri;

final _functions = CelestFunctions();

late CelestAuth _auth = CelestAuth(
this,
storage: nativeStorage,
);
late CelestAuth _auth = CelestAuth(this, storage: nativeStorage);

T _checkInitialized<T>(T Function() value) {
if (!_initialized) {
throw StateError(
'Celest has not been initialized. Make sure to call `celest.init()` at the start of your `main` method.');
'Celest has not been initialized. Make sure to call `celest.init()` at the start of your `main` method.',
);
}
return value();
}
Expand All @@ -72,10 +72,17 @@ class Celest with _$celest.CelestBase {
CelestAuth get auth => _checkInitialized(() => _auth);

void init({
CelestEnvironment environment = CelestEnvironment.local,
CelestEnvironment? environment,
_$celest.Serializers? serializers,
ExternalAuth? externalAuth,
}) {
if (environment == null) {
const environmentOverride = String.fromEnvironment(
'CELEST_ENVIRONMENT',
defaultValue: 'local',
);
environment = CelestEnvironment.values.byName(environmentOverride);
}
if (_initialized) {
_reset();
}
Expand All @@ -88,10 +95,7 @@ class Celest with _$celest.CelestBase {

void _reset() {
_auth.close().ignore();
_auth = CelestAuth(
this,
storage: nativeStorage,
);
_auth = CelestAuth(this, storage: nativeStorage);
_initialized = false;
}
}
14 changes: 5 additions & 9 deletions examples/firebase/celest/client/lib/src/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ extension type CelestAuth._(_$celest.AuthImpl _hub) implements _$celest.Auth {
CelestAuth(
_$celest.CelestBase celest, {
required _$native_storage_native_storage.NativeStorage storage,
}) : _hub = _$celest.AuthImpl(
celest,
storage: storage,
);
}) : _hub = _$celest.AuthImpl(celest, storage: storage);
}

/// External authentication providers which can be used to sign in to Celest.
Expand All @@ -28,10 +25,8 @@ extension type CelestAuth._(_$celest.AuthImpl _hub) implements _$celest.Auth {
/// the external auth providers.
class ExternalAuth extends _$celest.TokenSource {
/// {@macro celest_auth.token_source.of}
const ExternalAuth.of({
required super.provider,
required super.stream,
}) : super.of();
const ExternalAuth.of({required super.provider, required super.stream})
: super.of();

/// Creates an instance of [ExternalAuth] for Firebase Auth.
///
Expand All @@ -48,7 +43,8 @@ class ExternalAuth extends _$celest.TokenSource {
/// }
/// ```
factory ExternalAuth.firebase(
_$firebase_auth_firebase_auth.FirebaseAuth firebase) {
_$firebase_auth_firebase_auth.FirebaseAuth firebase,
) {
return ExternalAuth.of(
provider: _$celest.AuthProviderType.firebase,
stream: firebase.idTokenChanges().asyncMap((user) => user?.getIdToken()),
Expand Down
87 changes: 47 additions & 40 deletions examples/firebase/celest/client/lib/src/functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ class CelestFunctions {
}

class CelestFunctionsAuth {
Never _throwError({
int? code,
required Map<String, Object?> body,
}) {
Never _throwError({int? code, required Map<String, Object?> body}) {
final status = body['@status'] as Map<String, Object?>?;
final message = status?['message'] as String?;
final details = status?['details'] as _$celest.JsonList?;
Expand All @@ -33,27 +30,28 @@ class CelestFunctionsAuth {
final errorDetails as Map<String, Object?>,
{
'@type': 'dart.core.StackTrace',
'value': final stackTraceValue as String
'value': final stackTraceValue as String,
},
...
...,
] =>
(
errorDetails['@type'],
errorDetails['value'],
StackTrace.fromString(stackTraceValue),
),
[final errorDetails as Map<String, Object?>, ...] => (
errorDetails['@type'],
errorDetails['value'],
StackTrace.empty,
),
errorDetails['@type'],
errorDetails['value'],
StackTrace.empty,
),
};

switch (errorType) {
case 'celest.core.v1.CloudException':
Error.throwWithStackTrace(
_$celest.Serializers.instance
.deserialize<_$celest.CloudException>(errorValue),
_$celest.Serializers.instance.deserialize<_$celest.CloudException>(
errorValue,
),
stackTrace,
);
case 'celest.core.v1.CancelledException':
Expand All @@ -64,8 +62,9 @@ class CelestFunctionsAuth {
);
case 'celest.core.v1.UnknownError':
Error.throwWithStackTrace(
_$celest.Serializers.instance
.deserialize<_$celest.UnknownError>(errorValue),
_$celest.Serializers.instance.deserialize<_$celest.UnknownError>(
errorValue,
),
stackTrace,
);
case 'celest.core.v1.BadRequestException':
Expand All @@ -82,8 +81,9 @@ class CelestFunctionsAuth {
);
case 'celest.core.v1.NotFoundException':
Error.throwWithStackTrace(
_$celest.Serializers.instance
.deserialize<_$celest.NotFoundException>(errorValue),
_$celest.Serializers.instance.deserialize<_$celest.NotFoundException>(
errorValue,
),
stackTrace,
);
case 'celest.core.v1.AlreadyExistsException':
Expand Down Expand Up @@ -112,8 +112,9 @@ class CelestFunctionsAuth {
);
case 'celest.core.v1.AbortedException':
Error.throwWithStackTrace(
_$celest.Serializers.instance
.deserialize<_$celest.AbortedException>(errorValue),
_$celest.Serializers.instance.deserialize<_$celest.AbortedException>(
errorValue,
),
stackTrace,
);
case 'celest.core.v1.OutOfRangeException':
Expand All @@ -136,14 +137,16 @@ class CelestFunctionsAuth {
);
case 'celest.core.v1.UnavailableError':
Error.throwWithStackTrace(
_$celest.Serializers.instance
.deserialize<_$celest.UnavailableError>(errorValue),
_$celest.Serializers.instance.deserialize<_$celest.UnavailableError>(
errorValue,
),
stackTrace,
);
case 'celest.core.v1.DataLossError':
Error.throwWithStackTrace(
_$celest.Serializers.instance
.deserialize<_$celest.DataLossError>(errorValue),
_$celest.Serializers.instance.deserialize<_$celest.DataLossError>(
errorValue,
),
stackTrace,
);
case 'celest.core.v1.DeadlineExceededError':
Expand Down Expand Up @@ -190,14 +193,16 @@ class CelestFunctionsAuth {
);
case 'dart.core.UnsupportedError':
Error.throwWithStackTrace(
_$celest.Serializers.instance
.deserialize<UnsupportedError>(errorValue),
_$celest.Serializers.instance.deserialize<UnsupportedError>(
errorValue,
),
stackTrace,
);
case 'dart.core.UnimplementedError':
Error.throwWithStackTrace(
_$celest.Serializers.instance
.deserialize<UnimplementedError>(errorValue),
_$celest.Serializers.instance.deserialize<UnimplementedError>(
errorValue,
),
stackTrace,
);
case 'dart.core.StateError':
Expand All @@ -213,14 +218,16 @@ class CelestFunctionsAuth {
);
case 'dart.core.OutOfMemoryError':
Error.throwWithStackTrace(
_$celest.Serializers.instance
.deserialize<OutOfMemoryError>(errorValue),
_$celest.Serializers.instance.deserialize<OutOfMemoryError>(
errorValue,
),
stackTrace,
);
case 'dart.core.StackOverflowError':
Error.throwWithStackTrace(
_$celest.Serializers.instance
.deserialize<StackOverflowError>(errorValue),
_$celest.Serializers.instance.deserialize<StackOverflowError>(
errorValue,
),
stackTrace,
);
case 'dart.core.Exception':
Expand All @@ -230,8 +237,9 @@ class CelestFunctionsAuth {
);
case 'dart.core.FormatException':
Error.throwWithStackTrace(
_$celest.Serializers.instance
.deserialize<FormatException>(errorValue),
_$celest.Serializers.instance.deserialize<FormatException>(
errorValue,
),
stackTrace,
);
case 'dart.core.IntegerDivisionByZeroException':
Expand All @@ -247,14 +255,16 @@ class CelestFunctionsAuth {
);
case 'dart.async.TimeoutException':
Error.throwWithStackTrace(
_$celest.Serializers.instance
.deserialize<TimeoutException>(errorValue),
_$celest.Serializers.instance.deserialize<TimeoutException>(
errorValue,
),
stackTrace,
);
case 'dart.convert.JsonUnsupportedObjectError':
Error.throwWithStackTrace(
_$celest.Serializers.instance
.deserialize<JsonUnsupportedObjectError>(errorValue),
_$celest.Serializers.instance.deserialize<JsonUnsupportedObjectError>(
errorValue,
),
stackTrace,
);
default:
Expand All @@ -269,10 +279,7 @@ class CelestFunctionsAuth {
}
}

@_$celest.CloudFunction(
api: 'auth',
function: 'currentUser',
)
@_$celest.CloudFunction(api: 'auth', function: 'currentUser')
Future<_$celest.User> currentUser() async {
final $response = await celest.httpClient.get(
celest.baseUri.resolve('/auth/current-user'),
Expand Down
Loading
Loading