Skip to content

Commit

Permalink
feat: Firebase Region can be specified by Enum.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Mar 15, 2024
1 parent a883d2a commit 9fe8503
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/katana_firebase/README.md
Expand Up @@ -46,7 +46,7 @@ Please initialize with the following code.

```dart
await FirebaseCore.initialize(
region: "asia-northeast1",
region: FirebaseRegion.asiaNortheast1,
options: DefaultFirebaseOptions.currentPlatform,
);
```
Expand Down
4 changes: 2 additions & 2 deletions packages/katana_firebase/lib/firebase/firebase_core.dart
Expand Up @@ -45,7 +45,7 @@ class FirebaseCore {
/// Firebaseのregionを返します。
///
/// [initialize]時に渡した[region]が格納されます。デフォルトは`asia-northeast1`です。
static late final String region;
static late final FirebaseRegion region;

/// Initialize Firebase.
///
Expand Down Expand Up @@ -79,7 +79,7 @@ class FirebaseCore {
/// await FirebaseCore.initialize();
/// ```
static Future<void> initialize({
String region = "asia-northeast1",
FirebaseRegion region = FirebaseRegion.asiaNortheast1,
FirebaseOptions? options,
}) async {
if (_completer != null) {
Expand Down
203 changes: 203 additions & 0 deletions packages/katana_firebase/lib/firebase/firebase_region.dart
@@ -0,0 +1,203 @@
part of "/katana_firebase.dart";

/// Specify the Firebase region.
///
/// Firebaseのリージョンを指定します。
enum FirebaseRegion {
/// Taiwan.
///
/// 台湾。
asiaEast1,

/// Hong Kong.
///
/// 香港。
asiaEast2,

/// Tokyo.
///
/// 東京。
asiaNortheast1,

/// Osaka.
///
/// 大阪。
asiaNortheast2,

/// Seoul.
///
/// ソウル。
asiaNortheast3,

/// Singapore.
///
/// シンガポール。
asiaSoutheast1,

/// Jakarta.
///
/// ジャカルタ。
asiaSoutheast2,

/// Mumbai.
///
/// ムンバイ。
asiaSouth1,

/// Finland.
///
/// フィンランド。
europeNorth1,

/// Warsaw.
///
/// ワルシャワ。
europeCentral2,

/// Belgium.
///
/// ベルギー。
europeWest1,

/// London.
///
/// ロンドン。
europeWest2,

/// Frankfurt.
///
/// フランクフルト。
europeWest3,

/// Zürich.
///
/// チューリッヒ。
europeWest6,

/// Iowa.
///
/// アイオワ。
usCentral1,

/// South Carolina.
///
/// 南カロライナ。
usEast1,

/// North Virginia.
///
/// 北バージニア。
usEast4,

/// Oregon.
///
/// オレゴン。
usWest1,

/// Los Angeles.
///
/// ロサンゼルス。
usWest2,

/// Salt Lake City.
///
/// ソルトレイクシティ。
usWest3,

/// Las Vegas.
///
/// ラスベガス。
usWest4,

/// Sydney.
///
/// シドニー。
australiaSoutheast1,

/// Melbourne.
///
/// メルボルン。
australiaSoutheast2,

/// Montréal.
///
/// モントリオール。
northamericaNortheast1,

/// Toronto.
///
/// トロント。
northamericaNortheast2,

/// São Paulo.
///
/// サンパウロ。
southamericaEast1,

/// Santiago, Chile.
///
/// サンティアゴ、チリ。
southamericaWest1;

/// Get the actual value.
///
/// 実際の値を取得します。
String get value {
switch (this) {
case FirebaseRegion.asiaEast1:
return "asia-east1";
case FirebaseRegion.asiaEast2:
return "asia-east2";
case FirebaseRegion.asiaNortheast1:
return "asia-northeast1";
case FirebaseRegion.asiaNortheast2:
return "asia-northeast2";
case FirebaseRegion.europeNorth1:
return "europe-north1";
case FirebaseRegion.europeWest1:
return "europe-west1";
case FirebaseRegion.europeWest2:
return "europe-west2";
case FirebaseRegion.usCentral1:
return "us-central1";
case FirebaseRegion.usEast1:
return "us-east1";
case FirebaseRegion.usEast4:
return "us-east4";
case FirebaseRegion.usWest1:
return "us-west1";
case FirebaseRegion.asiaNortheast3:
return "asia-northeast3";
case FirebaseRegion.asiaSoutheast1:
return "asia-southeast1";
case FirebaseRegion.asiaSoutheast2:
return "asia-southeast2";
case FirebaseRegion.asiaSouth1:
return "asia-south1";
case FirebaseRegion.australiaSoutheast1:
return "australia-southeast1";
case FirebaseRegion.australiaSoutheast2:
return "australia-southeast2";
case FirebaseRegion.europeCentral2:
return "europe-central2";
case FirebaseRegion.europeWest3:
return "europe-west3";
case FirebaseRegion.europeWest6:
return "europe-west6";
case FirebaseRegion.northamericaNortheast1:
return "northamerica-northeast1";
case FirebaseRegion.northamericaNortheast2:
return "northamerica-northeast2";
case FirebaseRegion.southamericaEast1:
return "southamerica-east1";
case FirebaseRegion.southamericaWest1:
return "southamerica-west1";
case FirebaseRegion.usWest2:
return "us-west2";
case FirebaseRegion.usWest3:
return "us-west3";
case FirebaseRegion.usWest4:
return "us-west4";
}
}
}
1 change: 1 addition & 0 deletions packages/katana_firebase/lib/katana_firebase.dart
Expand Up @@ -21,3 +21,4 @@ import "package:firebase_core/firebase_core.dart";
export "package:firebase_core/firebase_core.dart" show FirebaseOptions;

part "firebase/firebase_core.dart";
part "firebase/firebase_region.dart";
Expand Up @@ -47,7 +47,7 @@ class FirebaseFunctionsAdapter extends FunctionsAdapter {
this.windowsOptions,
this.macosOptions,
this.linuxOptions,
this.region,
required this.region,
FirebaseFunctions? functions,
}) : _options = options,
_functions = functions;
Expand All @@ -59,6 +59,7 @@ class FirebaseFunctionsAdapter extends FunctionsAdapter {
if (_functions != null) {
return _functions!;
}
final region = this.region.value;
if (region.isEmpty) {
return FirebaseFunctions.instance;
} else {
Expand Down Expand Up @@ -183,7 +184,7 @@ class FirebaseFunctionsAdapter extends FunctionsAdapter {
/// Firebase Functions Region.
///
/// Firebase Functionsのリージョン。
final String? region;
final FirebaseRegion region;

@override
String get endpoint => FirebaseCore.functionsEndpoint;
Expand Down

0 comments on commit 9fe8503

Please sign in to comment.