@converse/skeletor 3.1.1 → 3.1.3
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/CHANGES.md +139 -0
- package/dist/skeletor.esm.js +21 -13
- package/dist/skeletor.esm.js.map +1 -1
- package/dist/skeletor.js +21 -13
- package/dist/skeletor.js.map +1 -1
- package/dist/skeletor.min.js +1 -1
- package/dist/skeletor.node.js +21 -13
- package/dist/skeletor.node.mjs +21 -13
- package/package.json +4 -2
- package/src/collection.ts +3 -2
- package/src/model.ts +0 -4
- package/src/storage.ts +18 -6
package/src/storage.ts
CHANGED
|
@@ -125,7 +125,7 @@ class PersistentStorage {
|
|
|
125
125
|
if (!NodeSQLiteStorage) {
|
|
126
126
|
throw new Error(
|
|
127
127
|
"Skeletor.storage: the 'node' storage type is only available in Node.js builds. " +
|
|
128
|
-
"Import from '@converse/skeletor/node' instead of '@converse/skeletor'."
|
|
128
|
+
"Import from '@converse/skeletor/node' instead of '@converse/skeletor'.",
|
|
129
129
|
);
|
|
130
130
|
}
|
|
131
131
|
this.store = new NodeSQLiteStorage(this.name);
|
|
@@ -166,7 +166,7 @@ class PersistentStorage {
|
|
|
166
166
|
const that = this;
|
|
167
167
|
|
|
168
168
|
async function localSync(method: SyncOperation, model: Model, options: SyncOptions) {
|
|
169
|
-
let resp: any,
|
|
169
|
+
let resp: any, caughtError: Error | undefined, promise: Promise<any>, new_attributes: any;
|
|
170
170
|
|
|
171
171
|
// We get the collection (and if necessary the model attribute.
|
|
172
172
|
// Waiting for storeInitialized will cause another iteration of
|
|
@@ -223,9 +223,11 @@ class PersistentStorage {
|
|
|
223
223
|
} catch (error: any) {
|
|
224
224
|
const storageSize = await that.getStorageSize();
|
|
225
225
|
if (error.code === 22 && storageSize === 0) {
|
|
226
|
-
|
|
226
|
+
caughtError = new Error('Private browsing is unsupported');
|
|
227
227
|
} else {
|
|
228
|
-
|
|
228
|
+
// Preserve a real Error (stack/name); wrap anything else so the
|
|
229
|
+
// error path always surfaces an Error, never a bare string.
|
|
230
|
+
caughtError = error instanceof Error ? error : new Error(error?.message ?? String(error));
|
|
229
231
|
}
|
|
230
232
|
}
|
|
231
233
|
|
|
@@ -239,10 +241,20 @@ class PersistentStorage {
|
|
|
239
241
|
const data = method === 'read' ? resp : null;
|
|
240
242
|
options.success(data, options);
|
|
241
243
|
}
|
|
244
|
+
} else if (method === 'read' && !caughtError) {
|
|
245
|
+
// A read that finds no record is a normal empty result (first run /
|
|
246
|
+
// empty storage), not an error. Resolve with `null` so the callback
|
|
247
|
+
// and promise forms of fetch() agree and a first-run read never
|
|
248
|
+
// rejects.
|
|
249
|
+
if (options && options.success) {
|
|
250
|
+
options.success(null, options);
|
|
251
|
+
}
|
|
242
252
|
} else {
|
|
243
|
-
|
|
253
|
+
// A genuine failure (storage threw, or a write produced no result):
|
|
254
|
+
// surface a real Error so consumers get a stack and `instanceof Error`
|
|
255
|
+
// holds.
|
|
244
256
|
if (options && options.error) {
|
|
245
|
-
options.error(
|
|
257
|
+
options.error(caughtError ?? new Error('Record Not Found'));
|
|
246
258
|
}
|
|
247
259
|
}
|
|
248
260
|
}
|