lowdata 0.1.0 → 0.2.0
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/README.md +37 -4
- package/dist/{client-CqO3Y1J5.d.cts → client-BmsR0Pf6.d.cts} +8 -2
- package/dist/{client-BvdWSYIM.d.ts → client-DSKoYUj9.d.ts} +8 -2
- package/dist/forms.cjs +29 -11
- package/dist/forms.cjs.map +1 -1
- package/dist/forms.d.cts +4 -4
- package/dist/forms.d.ts +4 -4
- package/dist/forms.js +29 -11
- package/dist/forms.js.map +1 -1
- package/dist/index.cjs +29 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +29 -11
- package/dist/index.js.map +1 -1
- package/dist/media.cjs +1 -1
- package/dist/media.cjs.map +1 -1
- package/dist/media.d.cts +2 -2
- package/dist/media.d.ts +2 -2
- package/dist/media.js +1 -1
- package/dist/media.js.map +1 -1
- package/dist/network.cjs +29 -11
- package/dist/network.cjs.map +1 -1
- package/dist/network.d.cts +7 -6
- package/dist/network.d.ts +7 -6
- package/dist/network.js +29 -11
- package/dist/network.js.map +1 -1
- package/dist/{progressiveImage-BhY_K8Dj.d.ts → progressiveImage-BOdic4dJ.d.ts} +1 -1
- package/dist/{progressiveImage-BWNdewbi.d.cts → progressiveImage-CDpz_rv3.d.cts} +1 -1
- package/dist/react.cjs +29 -11
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +4 -4
- package/dist/react.d.ts +4 -4
- package/dist/react.js +29 -11
- package/dist/react.js.map +1 -1
- package/dist/{retry-C3zL9T5Z.d.cts → retry-BnuESos0.d.cts} +1 -1
- package/dist/{retry-D6DfKGOi.d.ts → retry-CnvZhHan.d.ts} +1 -1
- package/dist/{types-Bn1BAcch.d.ts → types-1ha2HIfv.d.ts} +1 -1
- package/dist/{types-CZDYS-fB.d.cts → types-Cbm1nNDO.d.cts} +1 -1
- package/dist/{types--FRrBa-i.d.cts → types-D6fjl8Wy.d.cts} +22 -1
- package/dist/{types--FRrBa-i.d.ts → types-D6fjl8Wy.d.ts} +22 -1
- package/package.json +22 -2
package/dist/react.js
CHANGED
|
@@ -279,16 +279,23 @@ function getSharedDb() {
|
|
|
279
279
|
}
|
|
280
280
|
return sharedDbPromise;
|
|
281
281
|
}
|
|
282
|
-
function createDbFallbackAccessor(getDb) {
|
|
282
|
+
function createDbFallbackAccessor(getDb, onError) {
|
|
283
283
|
let dbAvailable = true;
|
|
284
284
|
return {
|
|
285
285
|
async run(fn, fallback) {
|
|
286
286
|
if (!dbAvailable) return fallback();
|
|
287
|
+
let db;
|
|
287
288
|
try {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
} catch {
|
|
289
|
+
db = await getDb();
|
|
290
|
+
} catch (error) {
|
|
291
291
|
dbAvailable = false;
|
|
292
|
+
onError == null ? void 0 : onError(error, { scope: "db-open" });
|
|
293
|
+
return fallback();
|
|
294
|
+
}
|
|
295
|
+
try {
|
|
296
|
+
return await fn(db);
|
|
297
|
+
} catch (error) {
|
|
298
|
+
onError == null ? void 0 : onError(error, { scope: "db-operation" });
|
|
292
299
|
return fallback();
|
|
293
300
|
}
|
|
294
301
|
},
|
|
@@ -314,9 +321,9 @@ var LowdataRequestError = class extends Error {
|
|
|
314
321
|
var STORE = "queue";
|
|
315
322
|
var PRIORITY_ORDER = { high: 0, normal: 1, low: 2 };
|
|
316
323
|
var RequestQueue = class {
|
|
317
|
-
constructor(getDb) {
|
|
324
|
+
constructor(getDb, onError) {
|
|
318
325
|
this.memory = /* @__PURE__ */ new Map();
|
|
319
|
-
this.accessor = createDbFallbackAccessor(getDb);
|
|
326
|
+
this.accessor = createDbFallbackAccessor(getDb, onError);
|
|
320
327
|
}
|
|
321
328
|
isPersistent() {
|
|
322
329
|
return this.accessor.isPersistent();
|
|
@@ -631,12 +638,16 @@ var SyncManager = class {
|
|
|
631
638
|
* or safety poll simply tries again.
|
|
632
639
|
*/
|
|
633
640
|
async drain() {
|
|
634
|
-
var _a, _b, _c, _d;
|
|
641
|
+
var _a, _b, _c, _d, _e, _f;
|
|
635
642
|
if (this.draining || this.disposed) return;
|
|
636
643
|
if (this.opts.connection.getStatus().quality === "offline") return;
|
|
637
644
|
this.draining = true;
|
|
638
645
|
try {
|
|
639
|
-
const db = await this.opts.getDb().catch(() =>
|
|
646
|
+
const db = await this.opts.getDb().catch((error) => {
|
|
647
|
+
var _a2, _b2;
|
|
648
|
+
(_b2 = (_a2 = this.opts).onError) == null ? void 0 : _b2.call(_a2, error, { scope: "db-open" });
|
|
649
|
+
return void 0;
|
|
650
|
+
});
|
|
640
651
|
const lock = await acquireSyncLock(db, SYNC_LOCK_NAME, this.ownerId);
|
|
641
652
|
if (!lock) return;
|
|
642
653
|
let succeeded = 0;
|
|
@@ -659,7 +670,8 @@ var SyncManager = class {
|
|
|
659
670
|
await lock.release().catch(() => {
|
|
660
671
|
});
|
|
661
672
|
}
|
|
662
|
-
} catch {
|
|
673
|
+
} catch (error) {
|
|
674
|
+
(_f = (_e = this.opts).onError) == null ? void 0 : _f.call(_e, error, { scope: "sync" });
|
|
663
675
|
} finally {
|
|
664
676
|
this.draining = false;
|
|
665
677
|
}
|
|
@@ -745,6 +757,9 @@ var MUTATING_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"
|
|
|
745
757
|
function defaultShouldQueueOffline({ method }) {
|
|
746
758
|
return MUTATING_METHODS.has(method);
|
|
747
759
|
}
|
|
760
|
+
var defaultOnError = (error, { scope }) => {
|
|
761
|
+
console.warn(`lowdata: internal error (${scope})`, error);
|
|
762
|
+
};
|
|
748
763
|
function normalizeHeaders(headers) {
|
|
749
764
|
if (!headers) return void 0;
|
|
750
765
|
if (headers instanceof Headers) {
|
|
@@ -773,15 +788,18 @@ var LowdataClient = class {
|
|
|
773
788
|
this.config = config;
|
|
774
789
|
this.syncEmitter = new Emitter();
|
|
775
790
|
this.destroyed = false;
|
|
791
|
+
var _a;
|
|
792
|
+
const onError = (_a = config.onError) != null ? _a : defaultOnError;
|
|
776
793
|
this.monitor = new ConnectionMonitor(config.connection);
|
|
777
|
-
this.requestQueue = new RequestQueue(() => getSharedDb());
|
|
794
|
+
this.requestQueue = new RequestQueue(() => getSharedDb(), onError);
|
|
778
795
|
this.syncManager = new SyncManager({
|
|
779
796
|
queue: this.requestQueue,
|
|
780
797
|
connection: this.monitor,
|
|
781
798
|
getDb: () => getSharedDb(),
|
|
782
799
|
retryConfig: config.retry,
|
|
783
800
|
syncConcurrency: config.syncConcurrency,
|
|
784
|
-
onEvent: (event) => this.syncEmitter.emit(event)
|
|
801
|
+
onEvent: (event) => this.syncEmitter.emit(event),
|
|
802
|
+
onError
|
|
785
803
|
});
|
|
786
804
|
this.connection = {
|
|
787
805
|
getStatus: () => this.monitor.getStatus(),
|