Skip to content

Commit d9a6171

Browse files
authored
Add WEB-support for CoreStoreSembastImp (#436)
* Add websupport for CoreStoreSembastImp * Add debug warning when using sembast on web ParseCoreData().debug should be null at that time * fixed issues
1 parent a0b6020 commit d9a6171

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ await Parse().initialize(
2727
```
2828

2929
If you want to use secure storage or use the Flutter web/desktop SDK, please change to the below instance of CoreStorage as it has no dependencies on Flutter.
30+
31+
**The `CoreStoreSembastImp` does not encrypt the data!** (Web is not safe anyway. Encrypt fields manually as needed.)
3032
```dart
3133
3234
await Parse().initialize(

lib/parse_server_sdk_dart.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import 'package:parse_server_sdk/src/network/parse_websocket.dart'
1414
import 'package:path/path.dart' as path;
1515
import 'package:sembast/sembast.dart';
1616
import 'package:sembast/sembast_io.dart';
17+
import 'package:sembast_web/sembast_web.dart';
1718
import 'package:uuid/uuid.dart';
1819
import 'package:web_socket_channel/web_socket_channel.dart';
1920
import 'package:xxtea/xxtea.dart';

lib/src/storage/core_store_sem_impl.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@ class CoreStoreSembastImp implements CoreStore {
99
static Future<CoreStore> getInstance(String dbPath,
1010
{DatabaseFactory factory, String password = 'flutter_sdk'}) async {
1111
if (_instance == null) {
12-
factory ??= databaseFactoryIo;
13-
final SembastCodec codec = getXXTeaSembastCodec(password: password);
14-
final Database db = await factory.openDatabase(dbPath, codec: codec);
12+
factory ??= !parseIsWeb ? databaseFactoryIo : databaseFactoryWeb;
13+
assert(() {
14+
if (parseIsWeb) {
15+
print(
16+
'Warning: CoreStoreSembastImp of the Parse_Server_SDK does not encrypt the database on WEB.');
17+
}
18+
return true;
19+
}());
20+
final Database db = await factory.openDatabase(dbPath,
21+
codec: !parseIsWeb ? getXXTeaSembastCodec(password: password) : null);
1522
_instance =
1623
CoreStoreSembastImp._internal(db, StoreRef<String, String>.main());
1724
}

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dependencies:
1717

1818
#Database
1919
sembast: ^2.4.7+6
20+
sembast_web: '>=1.0.0'
2021
xxtea: ^2.0.3
2122
shared_preferences: ^0.5.10 # only used in the flutter part
2223

0 commit comments

Comments
 (0)