Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(celest): Migrate to native_storage #97

Merged
merged 11 commits into from
Apr 10, 2024
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
120 changes: 1 addition & 119 deletions .github/workflows/celest_core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,71 +31,7 @@ jobs:
- name: Format
working-directory: packages/celest_core
run: dart format --set-exit-if-changed .
test_darwin:
needs: analyze_and_format
runs-on: macos-latest-xlarge
timeout-minutes: 20
steps:
- name: Git Checkout
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # 4.1.2
- name: Setup Flutter
uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1 # 2.16.0
with:
cache: true
- name: Get Packages
working-directory: packages/celest_core
run: dart pub get
- name: Test
working-directory: packages/celest_core
run: dart test
- name: Get Packages (Example)
working-directory: packages/celest_core/example
run: flutter pub get
- name: Setup iOS Simulator
run: |
RUNTIME=$(xcrun simctl list runtimes | grep 'iOS 17' | tail -n 1 | cut -d' ' -f 7)
echo "Using runtime: $RUNTIME"
xcrun simctl create ios 'iPhone 15 Pro Max' $RUNTIME
echo "Booting simulator"
xcrun simctl boot ios
echo "Booted simulator"
- name: Test (iOS)
working-directory: packages/celest_core/example
run: flutter test -d ios integration_test/storage_test.dart
- name: Test (macOS)
working-directory: packages/celest_core/example
run: flutter test -d macos integration_test/storage_test.dart
test_android:
needs: analyze_and_format
runs-on:
group: public
labels: linux
timeout-minutes: 15
steps:
- name: Git Checkout
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # 4.1.2
- name: Setup Flutter
uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1 # 2.16.0
with:
cache: true
- name: Get Packages (Example)
working-directory: packages/celest_core/example
run: flutter pub get
- name: Enable KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Test (Android)
uses: ReactiveCircus/android-emulator-runner@6b0df4b0efb23bb0ec63d881db79aefbc976e4b2 # 2.30.1
with:
# Matches `package:jni` compileSdkVersion
# https://github.com/dart-lang/native/blob/001910c9f40d637cb25c19bb500fb89cebdf7450/pkgs/jni/android/build.gradle#L57C23-L57C25
api-level: 31
arch: x86_64
script: cd packages/celest_core/example && flutter test -d emulator integration_test/storage_test.dart
test_linux:
needs: analyze_and_format
test:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
Expand All @@ -105,66 +41,12 @@ jobs:
uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1 # 2.16.0
with:
cache: true
- name: Install Build Dependencies
run: sudo apt-get update && sudo apt-get install -y clang cmake git ninja-build pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev
- name: Setup Test Environment
working-directory: packages/celest_core
run: tool/setup-ci.sh
- name: Get Packages
working-directory: packages/celest_core
run: dart pub get
- name: Test
working-directory: packages/celest_core
run: dart test
- name: Get Packages (Example)
working-directory: packages/celest_core/example
run: flutter pub get
- name: Test (Linux)
working-directory: packages/celest_core/example
run: |
# Headless tests require virtual display for the linux tests to run.
export DISPLAY=:99
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 &
flutter test -d linux integration_test/storage_test.dart
# TODO: Re-enable
# Need to fix this: Git error. Command: `git clone --mirror https://github.com/dart-lang/native /c/Users/runneradmin/.pub-cache\git\cache\native-647c69ed8027da6d6def6bc40efa87cf1a2f76aa`
# test_windows:
# needs: analyze_and_format
# runs-on: windows-latest
# timeout-minutes: 15
# steps:
# - name: Git Checkout
# uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # 4.1.2
# - name: Setup Flutter
# uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1 # 2.16.0
# with:
# cache: true
# - name: Get Packages
# working-directory: packages/celest_core
# run: dart pub get --no-example
# - name: Test
# working-directory: packages/celest_core
# run: dart test
# - name: Get Packages (Example)
# working-directory: packages/celest_core/example
# run: flutter pub get
# - name: Test (Windows)
# working-directory: packages/celest_core/example
# run: flutter test -d windows integration_test/storage_test.dart
test_web:
needs: analyze_and_format
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Git Checkout
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # 4.1.2
- name: Setup Flutter
uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1 # 2.16.0
with:
cache: true
- name: Get Packages
working-directory: packages/celest_core
run: dart pub get
- name: Test (Chrome, dart2js)
working-directory: packages/celest_core
run: dart test -p chrome
Expand Down
5 changes: 1 addition & 4 deletions examples/todo/celest/lib/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ class Celest with CelestBase {

late CelestEnvironment _currentEnvironment;

late final SecureStorage _secureStorage = SecureStorage();

@override
late _$http.Client httpClient =
CelestHttpClient(secureStorage: _secureStorage);
late _$http.Client httpClient = CelestHttpClient();

late Uri _baseUri;

Expand Down
6 changes: 3 additions & 3 deletions packages/celest_auth/example/celest/lib/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ class Celest with CelestBase {

late CelestEnvironment _currentEnvironment;

late final SecureStorage _secureStorage = SecureStorage();
late final NativeStorage _storage = NativeStorage().scoped('celest');

@override
late _$http.Client httpClient =
CelestHttpClient(secureStorage: _secureStorage);
CelestHttpClient(secureStorage: _storage.secure);

late Uri _baseUri;

final _functions = CelestFunctions();

late final CelestAuth _auth = CelestAuth(
this,
secureStorage: _secureStorage,
storage: _storage,
);

T _checkInitialized<T>(T Function() value) {
Expand Down
4 changes: 2 additions & 2 deletions packages/celest_auth/example/celest/lib/src/client/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ extension type CelestAuth._(_$auth_impl.AuthImpl _hub)
implements _$celest_auth.Auth {
CelestAuth(
CelestBase celest, {
required SecureStorage secureStorage,
required NativeStorage storage,
}) : _hub = _$auth_impl.AuthImpl(
celest,
secureStorage: secureStorage,
storage: storage,
);

_$auth_impl.Email get email => _$auth_impl.Email(_hub);
Expand Down
2 changes: 2 additions & 0 deletions packages/celest_auth/example/celest/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ dependency_overrides:
path: ../../
celest_core:
path: ../../../celest_core
native_storage:
path: ../../../native/storage

dev_dependencies:
lints: ^3.0.0
Expand Down
2 changes: 2 additions & 0 deletions packages/celest_auth/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ dependency_overrides:
path: ../../celest_core
corks_cedar:
path: ../../corks_cedar
native_storage:
path: ../../native/storage

dev_dependencies:
flutter_test:
Expand Down
15 changes: 9 additions & 6 deletions packages/celest_auth/lib/src/auth_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ export 'flows/email_flow.dart';
final class AuthImpl implements Auth {
AuthImpl(
this.celest, {
required this.secureStorage,
LocalStorage? localStorage,
}) : localStorage = localStorage ?? LocalStorage();
NativeStorage? storage,
}) : _storage = storage ?? NativeStorage(scope: 'celest/auth');

AuthState? _authState;

Expand Down Expand Up @@ -84,7 +83,7 @@ final class AuthImpl implements Auth {
@override
Future<void> signOut() async {
localStorage.delete('userId');
secureStorage.delete('cork');
secureStorage.delete('cork').ignore();
try {
await protocol.signOut();
} finally {
Expand All @@ -93,14 +92,18 @@ final class AuthImpl implements Auth {
}

final CelestBase celest;
final LocalStorage localStorage;
final SecureStorage secureStorage;
final NativeStorage _storage;

NativeStorage get localStorage => _storage;
IsolatedNativeStorage get secureStorage => _storage.secure.isolated;

late final AuthClient protocol = AuthClient(celest);

Future<void> close() async {
await _authStateSubscription.cancel();
await _authFlowSubscription?.cancel();
await _authStateController.close();
localStorage.close();
await secureStorage.close();
}
}
6 changes: 6 additions & 0 deletions packages/celest_auth/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ dependencies:
shelf_router: ^1.1.4
stream_transform: ^2.1.0

dependency_overrides:
celest_core:
path: ../celest_core
native_storage:
path: ../native/storage

dev_dependencies:
build_runner: ^2.4.8
built_value_generator: ^8.9.1
Expand Down
4 changes: 4 additions & 0 deletions packages/celest_core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.4.0-dev.2

- Migrate to `package:native_storage`

## 0.4.0-dev.1

## 0.3.2
Expand Down
43 changes: 0 additions & 43 deletions packages/celest_core/example/.gitignore

This file was deleted.

45 changes: 0 additions & 45 deletions packages/celest_core/example/.metadata

This file was deleted.

3 changes: 0 additions & 3 deletions packages/celest_core/example/README.md

This file was deleted.

1 change: 0 additions & 1 deletion packages/celest_core/example/analysis_options.yaml

This file was deleted.

13 changes: 0 additions & 13 deletions packages/celest_core/example/android/.gitignore

This file was deleted.

Loading