Skip to content

Commit 3550eb0

Browse files
committed
style: format dart files
1 parent 5a14b1b commit 3550eb0

File tree

4 files changed

+100
-44
lines changed

4 files changed

+100
-44
lines changed

packages/dart/lib/src/objects/parse_offline_object.dart

Lines changed: 72 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
part of '../../parse_server_sdk.dart';
1+
part of '../../parse_server_sdk.dart';
22

33
extension ParseObjectOffline on ParseObject {
44
/// Load a single object by objectId from local storage.
5-
static Future<ParseObject?> loadFromLocalCache(String className, String objectId) async {
5+
static Future<ParseObject?> loadFromLocalCache(
6+
String className,
7+
String objectId,
8+
) async {
69
final CoreStore coreStore = ParseCoreData().getStore();
710
final String cacheKey = 'offline_cache_$className';
8-
final List<String> cached = await _getStringListAsStrings(coreStore, cacheKey);
11+
final List<String> cached = await _getStringListAsStrings(
12+
coreStore,
13+
cacheKey,
14+
);
915
for (final s in cached) {
1016
final jsonObj = json.decode(s);
1117
if (jsonObj['objectId'] == objectId) {
@@ -20,24 +26,35 @@ extension ParseObjectOffline on ParseObject {
2026
Future<void> saveToLocalCache() async {
2127
final CoreStore coreStore = ParseCoreData().getStore();
2228
final String cacheKey = 'offline_cache_$parseClassName';
23-
final List<String> cached = await _getStringListAsStrings(coreStore, cacheKey);
29+
final List<String> cached = await _getStringListAsStrings(
30+
coreStore,
31+
cacheKey,
32+
);
2433
// Remove any existing object with the same objectId
2534
cached.removeWhere((s) {
2635
final jsonObj = json.decode(s);
2736
return jsonObj['objectId'] == objectId;
2837
});
2938
cached.add(json.encode(toJson(full: true)));
3039
await coreStore.setStringList(cacheKey, cached);
31-
print('Saved object ${objectId ?? "(no objectId)"} to local cache for $parseClassName');
40+
print(
41+
'Saved object ${objectId ?? "(no objectId)"} to local cache for $parseClassName',
42+
);
3243
}
3344

3445
/// Save a list of objects to local storage efficiently.
35-
static Future<void> saveAllToLocalCache(String className, List<ParseObject> objectsToSave) async {
46+
static Future<void> saveAllToLocalCache(
47+
String className,
48+
List<ParseObject> objectsToSave,
49+
) async {
3650
if (objectsToSave.isEmpty) return;
3751

3852
final CoreStore coreStore = ParseCoreData().getStore();
3953
final String cacheKey = 'offline_cache_$className';
40-
final List<String> cachedStrings = await _getStringListAsStrings(coreStore, cacheKey);
54+
final List<String> cachedStrings = await _getStringListAsStrings(
55+
coreStore,
56+
cacheKey,
57+
);
4158

4259
// Use a Map for efficient lookup and update of existing objects
4360
final Map<String, String> objectMap = {};
@@ -49,7 +66,7 @@ extension ParseObjectOffline on ParseObject {
4966
objectMap[objectId] = s; // Store the original JSON string
5067
}
5168
} catch (e) {
52-
print('Error decoding cached object string during batch save: $e');
69+
print('Error decoding cached object string during batch save: $e');
5370
}
5471
}
5572

@@ -68,34 +85,48 @@ extension ParseObjectOffline on ParseObject {
6885
// Encode the new object data and replace/add it in the map
6986
objectMap[objectId] = json.encode(obj.toJson(full: true));
7087
} else {
71-
print('Skipping object without objectId during batch save for $className');
88+
print(
89+
'Skipping object without objectId during batch save for $className',
90+
);
7291
}
7392
}
7493

7594
// Convert the map values back to a list and save
7695
final List<String> updatedCachedStrings = objectMap.values.toList();
7796
await coreStore.setStringList(cacheKey, updatedCachedStrings);
78-
print('Batch saved to local cache for $className. Added: $added, Updated: $updated, Total: ${updatedCachedStrings.length}');
97+
print(
98+
'Batch saved to local cache for $className. Added: $added, Updated: $updated, Total: ${updatedCachedStrings.length}',
99+
);
79100
}
80101

81102
/// Remove this object from local storage (CoreStore).
82103
Future<void> removeFromLocalCache() async {
83104
final CoreStore coreStore = ParseCoreData().getStore();
84105
final String cacheKey = 'offline_cache_$parseClassName';
85-
final List<String> cached = await _getStringListAsStrings(coreStore, cacheKey);
106+
final List<String> cached = await _getStringListAsStrings(
107+
coreStore,
108+
cacheKey,
109+
);
86110
cached.removeWhere((s) {
87111
final jsonObj = json.decode(s);
88112
return jsonObj['objectId'] == objectId;
89113
});
90114
await coreStore.setStringList(cacheKey, cached);
91-
print('Removed object ${objectId ?? "(no objectId)"} from local cache for $parseClassName');
115+
print(
116+
'Removed object ${objectId ?? "(no objectId)"} from local cache for $parseClassName',
117+
);
92118
}
93119

94120
/// Load all objects of this class from local storage.
95-
static Future<List<ParseObject>> loadAllFromLocalCache(String className) async {
121+
static Future<List<ParseObject>> loadAllFromLocalCache(
122+
String className,
123+
) async {
96124
final CoreStore coreStore = ParseCoreData().getStore();
97125
final String cacheKey = 'offline_cache_$className';
98-
final List<String> cached = await _getStringListAsStrings(coreStore, cacheKey);
126+
final List<String> cached = await _getStringListAsStrings(
127+
coreStore,
128+
cacheKey,
129+
);
99130
print('Loaded ${cached.length} objects from local cache for $className');
100131
return cached.map<ParseObject>((s) {
101132
final jsonObj = json.decode(s);
@@ -106,7 +137,10 @@ extension ParseObjectOffline on ParseObject {
106137
Future<void> updateInLocalCache(Map<String, dynamic> updates) async {
107138
final CoreStore coreStore = ParseCoreData().getStore();
108139
final String cacheKey = 'offline_cache_$parseClassName';
109-
final List<String> cached = await _getStringListAsStrings(coreStore, cacheKey);
140+
final List<String> cached = await _getStringListAsStrings(
141+
coreStore,
142+
cacheKey,
143+
);
110144
for (int i = 0; i < cached.length; i++) {
111145
final jsonObj = json.decode(cached[i]);
112146
if (jsonObj['objectId'] == objectId) {
@@ -116,7 +150,9 @@ extension ParseObjectOffline on ParseObject {
116150
}
117151
}
118152
await coreStore.setStringList(cacheKey, cached);
119-
print('Updated object ${objectId ?? "(no objectId)"} in local cache for $parseClassName');
153+
print(
154+
'Updated object ${objectId ?? "(no objectId)"} in local cache for $parseClassName',
155+
);
120156
}
121157

122158
static Future<void> clearLocalCacheForClass(String className) async {
@@ -126,10 +162,16 @@ extension ParseObjectOffline on ParseObject {
126162
print('Cleared local cache for $className');
127163
}
128164

129-
static Future<bool> existsInLocalCache(String className, String objectId) async {
165+
static Future<bool> existsInLocalCache(
166+
String className,
167+
String objectId,
168+
) async {
130169
final CoreStore coreStore = ParseCoreData().getStore();
131170
final String cacheKey = 'offline_cache_$className';
132-
final List<String> cached = await _getStringListAsStrings(coreStore, cacheKey);
171+
final List<String> cached = await _getStringListAsStrings(
172+
coreStore,
173+
cacheKey,
174+
);
133175
for (final s in cached) {
134176
final jsonObj = json.decode(s);
135177
if (jsonObj['objectId'] == objectId) {
@@ -141,10 +183,15 @@ extension ParseObjectOffline on ParseObject {
141183
return false;
142184
}
143185

144-
static Future<List<String>> getAllObjectIdsInLocalCache(String className) async {
186+
static Future<List<String>> getAllObjectIdsInLocalCache(
187+
String className,
188+
) async {
145189
final CoreStore coreStore = ParseCoreData().getStore();
146190
final String cacheKey = 'offline_cache_$className';
147-
final List<String> cached = await _getStringListAsStrings(coreStore, cacheKey);
191+
final List<String> cached = await _getStringListAsStrings(
192+
coreStore,
193+
cacheKey,
194+
);
148195
print('Fetched all objectIds from local cache for $className');
149196
return cached.map((s) => json.decode(s)['objectId'] as String).toList();
150197
}
@@ -157,9 +204,12 @@ extension ParseObjectOffline on ParseObject {
157204
print('Synced local cache with server for $className');
158205
}
159206

160-
static Future<List<String>> _getStringListAsStrings(CoreStore coreStore, String cacheKey) async {
207+
static Future<List<String>> _getStringListAsStrings(
208+
CoreStore coreStore,
209+
String cacheKey,
210+
) async {
161211
final rawList = await coreStore.getStringList(cacheKey);
162212
if (rawList == null) return [];
163213
return List<String>.from(rawList.map((e) => e.toString()));
164214
}
165-
}
215+
}

packages/dart/lib/src/storage/core_store_memory.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class CoreStoreMemoryImp implements CoreStore {
4545
if (value is List<String>) return value;
4646
if (value is Iterable) return value.map((e) => e.toString()).toList();
4747
return null;
48-
}
48+
}
4949

5050
// @override
5151
// Future<List<String>?> getStringList(String key) async {

packages/dart/lib/src/storage/core_store_sem_impl.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,19 @@ class CoreStoreSembastImp implements CoreStore {
9595
}
9696

9797
@override
98-
Future<List<String>?> getStringList(String key) async {
99-
final value = await get(key);
100-
if (value == null) return null;
101-
if (value is List<String>) return value;
102-
if (value is Iterable) return value.map((e) => e.toString()).toList();
103-
return null;
104-
}
98+
Future<List<String>?> getStringList(String key) async {
99+
final value = await get(key);
100+
if (value == null) return null;
101+
if (value is List<String>) return value;
102+
if (value is Iterable) return value.map((e) => e.toString()).toList();
103+
return null;
104+
}
105105

106-
// @override
107-
// Future<List<String>?> getStringList(String key) async {
108-
// final List<String>? storedItem = await get(key);
109-
// return storedItem;
110-
// }
106+
// @override
107+
// Future<List<String>?> getStringList(String key) async {
108+
// final List<String>? storedItem = await get(key);
109+
// return storedItem;
110+
// }
111111

112112
@override
113113
Future<void> remove(String key) {

packages/dart/test_extension.dart

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import 'package:parse_server_sdk/parse_server_sdk.dart';
22

33
Future<void> main() async {
44
// Initialize Parse
5-
await Parse().initialize("keyApplicationId", "keyParseServerUrl",
6-
clientKey: "keyParseClientKey",
7-
debug: true,
8-
autoSendSessionId: true,
9-
coreStore: CoreStoreMemoryImp());
5+
await Parse().initialize(
6+
"keyApplicationId",
7+
"keyParseServerUrl",
8+
clientKey: "keyParseClientKey",
9+
debug: true,
10+
autoSendSessionId: true,
11+
coreStore: CoreStoreMemoryImp(),
12+
);
1013

1114
// Test if ParseObjectOffline extension is available
1215
var dietPlan = ParseObject('DietPlan')
@@ -15,13 +18,16 @@ Future<void> main() async {
1518

1619
try {
1720
// Test static method from extension
18-
var cachedObjects = await ParseObjectOffline.loadAllFromLocalCache('DietPlan');
19-
print('Extension static method works! Found ${cachedObjects.length} cached objects');
20-
21+
var cachedObjects = await ParseObjectOffline.loadAllFromLocalCache(
22+
'DietPlan',
23+
);
24+
print(
25+
'Extension static method works! Found ${cachedObjects.length} cached objects',
26+
);
27+
2128
// Test instance method from extension
2229
await dietPlan.saveToLocalCache();
2330
print('Extension instance method works! Saved object to cache');
24-
2531
} catch (e) {
2632
print('Extension methods not available: $e');
2733
}

0 commit comments

Comments
 (0)