Skip to content

Commit

Permalink
Web persistor (#17)
Browse files Browse the repository at this point in the history
* temp commit

* temp commit

* refactor

* refactor

* refactor

* refactor

* woohoo

* woohoo

* fix

* update tasks

* update tasks

* add workflow

* add workflow

* finish unencrypted indexed db tests

* add encrypted test

* add encrypted test

* add encrypted test

* fix workflow

* fix workflow
  • Loading branch information
danReynolds authored Nov 8, 2024
1 parent 3b122bb commit c8183bb
Show file tree
Hide file tree
Showing 48 changed files with 2,664 additions and 1,721 deletions.
6 changes: 3 additions & 3 deletions .flutter-plugins
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
flutter_secure_storage=/Users/dan/.pub-cache/hosted/pub.dev/flutter_secure_storage-9.2.2/
flutter_secure_storage_linux=/Users/dan/.pub-cache/hosted/pub.dev/flutter_secure_storage_linux-1.2.1/
flutter_secure_storage_macos=/Users/dan/.pub-cache/hosted/pub.dev/flutter_secure_storage_macos-3.1.2/
flutter_secure_storage_web=/Users/dan/.pub-cache/hosted/pub.dev/flutter_secure_storage_web-1.2.1/
flutter_secure_storage_web=/Users/dan/.pub-cache/git/flutter_secure_storage-5a5692b609b3886cdd49b2ed06b9c079ecdff996/flutter_secure_storage_web/
flutter_secure_storage_windows=/Users/dan/.pub-cache/hosted/pub.dev/flutter_secure_storage_windows-3.1.2/
path_provider=/Users/dan/.pub-cache/hosted/pub.dev/path_provider-2.1.2/
path_provider_android=/Users/dan/.pub-cache/hosted/pub.dev/path_provider_android-2.2.2/
path_provider=/Users/dan/.pub-cache/hosted/pub.dev/path_provider-2.1.5/
path_provider_android=/Users/dan/.pub-cache/hosted/pub.dev/path_provider_android-2.2.12/
path_provider_foundation=/Users/dan/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.2/
path_provider_linux=/Users/dan/.pub-cache/hosted/pub.dev/path_provider_linux-2.2.1/
path_provider_windows=/Users/dan/.pub-cache/hosted/pub.dev/path_provider_windows-2.2.1/
31 changes: 31 additions & 0 deletions .github/workflows/flutter_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Run Flutter Tests

on:
pull_request:
branches:
- main # Adjust the target branch as needed

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.24.0'

- name: Install dependencies
run: flutter pub get

- name: Run Core tests
run: flutter test test/core

- name: Run Native tests
run: flutter test test/native

- name: Run Web tests
run: flutter test test/web --platform chrome
10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch example",
"request": "launch",
"type": "dart",
}
]
}
48 changes: 48 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Core tests",
"type": "shell",
"command": "flutter",
"args": ["test", "test/core"],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [],
"detail": "Runs a specific Flutter test file on the Chrome platform."
},
{
"label": "Native tests",
"type": "shell",
"command": "flutter",
"args": ["test", "test/native"],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [],
"detail": "Runs a specific Flutter test file on the Chrome platform."
},
{
"label": "Web tests",
"type": "shell",
"command": "flutter",
"args": [
"test",
"test/web",
"--platform",
"chrome"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [],
"detail": "Runs a specific Flutter test file on the Chrome platform."
}
]
}
45 changes: 40 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@
<br />
<br />

<table border="1">
<tr>
<th>Android</th>
<th>iOS</th>
<th>Web</th>
<th>macOS</th>
</tr>
<tr>
<td>✅</td>
<td>✅</td>
<td>✅</td>
<td>✅</td>
</tr>
</table>

<br />

Loon is a reactive document data store for Flutter.

## Features
Expand Down Expand Up @@ -276,11 +293,29 @@ Loon.doc('current_user_id').create('1');

## 🗄️ Data Persistence

A default file-based persistence option is available out of the box and can be configured on app start.
Persistence is supported on both web and native platforms. It works out of the box and can be configured on app start.

*Native* platforms (iOS, Android, macOS) use a default file-based persistence implementation, while *web* persists data to IndexedDB.

The currently available persistence options are broken down by platform:

### Native

* **FilePersistor**: The default file-based persistence implementation for native platforms. Documents are stored in one or more files based on the persistence configuration.

### Web

* **IndexedDBPersistor**: The default persistence implementation for web platforms. Documents are stored in [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API), a low-level API for web-based client-side storage.
* > Note: Encryption on web is experimental through [flutter_secure_storage](https://pub.dev/packages/flutter_secure_storage#configure-web-version). It is important to enable the correct headers in order to ensure security of encryption on web.
## ⚙️ Configuration

A persistor can be specified explicitly on startup, or `Persistor.current()` can be used to dynamically select the default persistence implementation for the current platform.


```dart
void main() {
Loon.configure(persistor: FilePersistor());
Loon.configure(persistor: Persistor.current());
Loon.hydrate().then(() {
print('Hydration complete');
Expand All @@ -299,9 +334,9 @@ await Loon.hydrate([
]);
```

## ⚙️ Persistence options
## ⚙️ Dynamic options

Persistence options can be specified globally or on a per-collection basis.
Persistence options can be specified both globally as well as on a per-collection basis.

```dart
// main.dart
Expand Down Expand Up @@ -422,7 +457,7 @@ whenever a document's data changes and if its associated key is updated, then th

## 🎨 Custom persistence

If you would prefer to persist data using an alternative implementation than the default `FilePersistor`, you just need to implement the persistence interface:
If you would prefer to persist data using an alternative implementation than the default persistors, you can implement the persistence interface:

```dart
import 'package:loon/loon.dart';
Expand Down
6 changes: 1 addition & 5 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import 'dart:async';

import 'package:example/models/user.dart';
import 'package:flutter/material.dart';
import 'package:loon/loon.dart';
import 'package:loon/persistor/file_persistor/file_persistor_settings.dart';
import 'package:uuid/uuid.dart';

const uuid = Uuid();
Expand All @@ -12,9 +10,7 @@ void main() async {
WidgetsFlutterBinding.ensureInitialized();

Loon.configure(
persistor: FilePersistor(
settings: const FilePersistorSettings(encrypted: true),
),
persistor: Persistor.current(),
enableLogging: true,
);

Expand Down
18 changes: 13 additions & 5 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -275,18 +275,18 @@ packages:
dependency: transitive
description:
name: path_provider
sha256: b27217933eeeba8ff24845c34003b003b2b22151de3c908d0e679e8fe1aa078b
sha256: "50c5dd5b6e1aaf6fb3a78b33f6aa3afca52bf903a8a5298f53101fdaee55bbcd"
url: "https://pub.dev"
source: hosted
version: "2.1.2"
version: "2.1.5"
path_provider_android:
dependency: transitive
description:
name: path_provider_android
sha256: "477184d672607c0a3bf68fbbf601805f92ef79c82b64b4d6eb318cbca4c48668"
sha256: c464428172cb986b758c6d1724c603097febb8fb855aa265aeecc9280c294d4a
url: "https://pub.dev"
source: hosted
version: "2.2.2"
version: "2.2.12"
path_provider_foundation:
dependency: transitive
description:
Expand Down Expand Up @@ -444,6 +444,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "14.2.5"
web:
dependency: transitive
description:
name: web
sha256: cd3543bd5798f6ad290ea73d210f423502e71900302dde696f8bff84bf89a1cb
url: "https://pub.dev"
source: hosted
version: "1.1.0"
win32:
dependency: transitive
description:
Expand All @@ -462,4 +470,4 @@ packages:
version: "1.0.0"
sdks:
dart: ">=3.5.0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
flutter: ">=3.24.0"
4 changes: 2 additions & 2 deletions lib/loon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ library loon;

import 'dart:async';
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:flutter/foundation.dart' hide Key;
import 'package:uuid/uuid.dart';
import 'dart:collection';
import 'persistor/platform_persistor/platform_persistor.dart';

export 'widgets/query_stream_builder.dart';
export 'widgets/document_stream_builder.dart';
export 'persistor/file_persistor/file_persistor.dart';

part 'store/base_value_store.dart';
part 'store/path_ref_store.dart';
Expand Down
Loading

0 comments on commit c8183bb

Please sign in to comment.