@herdwatch/lokijs 1.5.8-dev.6 → 1.5.8-dev.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +11 -0
- package/package.json +2 -1
- package/src/loki-indexed-adapter.js +27 -5
- package/src/lokijs.js +12 -2
package/index.d.ts
CHANGED
|
@@ -203,6 +203,17 @@ declare class Loki extends LokiEventEmitter {
|
|
|
203
203
|
databaseVersion: number;
|
|
204
204
|
engineVersion: number;
|
|
205
205
|
autosave: boolean;
|
|
206
|
+
/**
|
|
207
|
+
* A flag that determines whether the autosave functionality should be ignored.
|
|
208
|
+
* If set to true, the autosave operation will be bypassed.
|
|
209
|
+
*/
|
|
210
|
+
ignoreAutosave: boolean;
|
|
211
|
+
/**
|
|
212
|
+
* A boolean flag indicating whether the database should be serialized
|
|
213
|
+
* before saving. When set to true, the database content is converted
|
|
214
|
+
* to a serialized format to ensure data integrity during storage.
|
|
215
|
+
*/
|
|
216
|
+
serializeDatabaseBeforeSave: boolean;
|
|
206
217
|
autosaveInterval: number;
|
|
207
218
|
autosaveHandle: number | null;
|
|
208
219
|
persistenceAdapter: LokiPersistenceAdapter | null | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@herdwatch/lokijs",
|
|
3
|
-
"version": "1.5.8-dev.
|
|
3
|
+
"version": "1.5.8-dev.8",
|
|
4
4
|
"description": "Fast document oriented javascript in-memory database",
|
|
5
5
|
"homepage": "http://lokijs.org",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
],
|
|
28
28
|
"scripts": {
|
|
29
29
|
"lint": "jshint src",
|
|
30
|
+
"test:browser:dev": "karma start karma.conf.js",
|
|
30
31
|
"test:browser": "karma start karma.conf.js --single-run",
|
|
31
32
|
"test:node": "istanbul cover --dir coverage/nodejs node_modules/jasmine/bin/jasmine.js",
|
|
32
33
|
"pretest": "npm run lint",
|
|
@@ -43,6 +43,11 @@
|
|
|
43
43
|
this.app = 'loki';
|
|
44
44
|
this.options = options || {};
|
|
45
45
|
|
|
46
|
+
// Helper for reproduce WebKit bug
|
|
47
|
+
// https://github.com/ionic-team/cordova-plugin-ionic-webview/issues/354
|
|
48
|
+
// https://github.com/ionic-team/capacitor/issues/7439
|
|
49
|
+
this.simulateErrorMessage = null;
|
|
50
|
+
|
|
46
51
|
if (typeof appname !== 'undefined') {
|
|
47
52
|
this.app = appname;
|
|
48
53
|
}
|
|
@@ -142,17 +147,26 @@
|
|
|
142
147
|
* @memberof LokiIndexedAdapter
|
|
143
148
|
*/
|
|
144
149
|
LokiIndexedAdapter.prototype.saveDatabase = function (dbname, dbstring, callback) {
|
|
150
|
+
if(localStorage.getItem('debug-lokijs')){
|
|
151
|
+
console.time(`saveDatabase_${dbname}`);
|
|
152
|
+
}
|
|
145
153
|
var appName = this.app;
|
|
146
154
|
var adapter = this;
|
|
147
155
|
|
|
148
156
|
/**
|
|
149
|
-
* @param { success: boolean, error: Error } result
|
|
157
|
+
* @param { {success: boolean, error: Error} } result
|
|
150
158
|
*/
|
|
151
159
|
function saveCallback(result) {
|
|
152
160
|
if (result && result.success === true) {
|
|
153
161
|
callback(null);
|
|
162
|
+
if (localStorage.getItem('debug-lokijs')) {
|
|
163
|
+
console.timeEnd(`saveDatabase_${dbname}`);
|
|
164
|
+
const bytes = dbstring.length * 2;
|
|
165
|
+
const kb = bytes / 1024;
|
|
166
|
+
console.log(kb.toFixed(2) + ' KB');
|
|
167
|
+
}
|
|
154
168
|
} else {
|
|
155
|
-
console.error('Error saving database', result);
|
|
169
|
+
console.error('saveDatabase->saveCallback, Error saving database', result);
|
|
156
170
|
callback(result);
|
|
157
171
|
}
|
|
158
172
|
|
|
@@ -171,7 +185,15 @@
|
|
|
171
185
|
}
|
|
172
186
|
|
|
173
187
|
// set (add/update) entry to AKV database
|
|
174
|
-
|
|
188
|
+
try {
|
|
189
|
+
if (this.simulateErrorMessage) {
|
|
190
|
+
throw new Error(this.simulateErrorMessage);
|
|
191
|
+
}
|
|
192
|
+
this.catalog.setAppKey(appName, dbname, dbstring, saveCallback);
|
|
193
|
+
} catch (error) {
|
|
194
|
+
saveCallback({success: false, error});
|
|
195
|
+
}
|
|
196
|
+
|
|
175
197
|
};
|
|
176
198
|
|
|
177
199
|
// alias
|
|
@@ -451,7 +473,7 @@
|
|
|
451
473
|
res = {
|
|
452
474
|
app: app,
|
|
453
475
|
key: key,
|
|
454
|
-
appkey:
|
|
476
|
+
appkey: appkey,
|
|
455
477
|
val: val,
|
|
456
478
|
};
|
|
457
479
|
} else {
|
|
@@ -463,7 +485,7 @@
|
|
|
463
485
|
requestPut.onerror = (function (usercallback) {
|
|
464
486
|
return function (e) {
|
|
465
487
|
if (typeof usercallback === 'function') {
|
|
466
|
-
usercallback({ success: false, error:
|
|
488
|
+
usercallback({ success: false, error: requestPut.error });
|
|
467
489
|
} else {
|
|
468
490
|
console.error('LokiCatalog.setAppKey (set) onerror');
|
|
469
491
|
console.error(request.error);
|
package/src/lokijs.js
CHANGED
|
@@ -868,8 +868,10 @@
|
|
|
868
868
|
// pass autosave: true, autosaveInterval: 6000 in options to set 6 second autosave
|
|
869
869
|
this.autosave = false;
|
|
870
870
|
this.autosaveInterval = 5000;
|
|
871
|
+
this.ignoreAutosave = false;
|
|
871
872
|
this.autosaveHandle = null;
|
|
872
873
|
this.throttledSaves = true;
|
|
874
|
+
this.serializeDatabaseBeforeSave = true;
|
|
873
875
|
|
|
874
876
|
this.options = {};
|
|
875
877
|
|
|
@@ -2674,7 +2676,7 @@
|
|
|
2674
2676
|
// or autosave won't work if an update occurs between here and the callback
|
|
2675
2677
|
// TODO: This should be stored and rolled back in case of DB save failure
|
|
2676
2678
|
// TODO: Reference mode adapter should have the same behavior
|
|
2677
|
-
if (this.persistenceAdapter.mode !== "reference") {
|
|
2679
|
+
if (this.serializeDatabaseBeforeSave && this.persistenceAdapter.mode !== "reference") {
|
|
2678
2680
|
this.autosaveClearFlags();
|
|
2679
2681
|
}
|
|
2680
2682
|
|
|
@@ -2707,6 +2709,14 @@
|
|
|
2707
2709
|
self.autosaveClearFlags();
|
|
2708
2710
|
cFun(err);
|
|
2709
2711
|
});
|
|
2712
|
+
} else if (this.serializeDatabaseBeforeSave === false){
|
|
2713
|
+
if(localStorage.getItem('debug-lokijs')){
|
|
2714
|
+
console.log("Performing full database save...");
|
|
2715
|
+
}
|
|
2716
|
+
this.persistenceAdapter.saveDatabase(this.filename, this, function saveDatabasecallback(err) {
|
|
2717
|
+
self.autosaveClearFlags();
|
|
2718
|
+
cFun(err);
|
|
2719
|
+
});
|
|
2710
2720
|
}
|
|
2711
2721
|
// otherwise just pass the serialized database to adapter
|
|
2712
2722
|
else {
|
|
@@ -2852,7 +2862,7 @@
|
|
|
2852
2862
|
// so next step will be to implement collection level dirty flags set on insert/update/remove
|
|
2853
2863
|
// along with loki level isdirty() function which iterates all collections to see if any are dirty
|
|
2854
2864
|
|
|
2855
|
-
if (self.autosaveDirty()) {
|
|
2865
|
+
if (self.autosaveDirty() && !self.ignoreAutosave) {
|
|
2856
2866
|
self.saveDatabase(callback);
|
|
2857
2867
|
}
|
|
2858
2868
|
}, delay);
|