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/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { C as ConnectionMonitor, a as ConnectionMonitorOptions, E as EnqueueOptions, H as HttpMethod, L as LowdataClient, b as LowdataClientConfig, Q as QueueItem, c as QueueItemStatus, d as QueuedResult, S as SyncEvent, e as createLowdataClient, g as getConnectionQuality, i as isQueued, o as onConnectionChange } from './client-
|
|
2
|
-
export { L as LowdataRequestError, d as defaultRetryOn } from './retry-
|
|
3
|
-
export { C as ConnectionInfo, a as ConnectionListener, b as ConnectionQuality, J as JitterStrategy, R as RequestPriority,
|
|
1
|
+
export { C as ConnectionMonitor, a as ConnectionMonitorOptions, E as EnqueueOptions, H as HttpMethod, L as LowdataClient, b as LowdataClientConfig, Q as QueueItem, c as QueueItemStatus, d as QueuedResult, S as SyncEvent, e as createLowdataClient, g as getConnectionQuality, i as isQueued, o as onConnectionChange } from './client-BmsR0Pf6.cjs';
|
|
2
|
+
export { L as LowdataRequestError, d as defaultRetryOn } from './retry-BnuESos0.cjs';
|
|
3
|
+
export { C as ConnectionInfo, a as ConnectionListener, b as ConnectionQuality, J as JitterStrategy, L as LowdataErrorHandler, c as LowdataErrorScope, R as RequestPriority, d as RetryBackoffConfig, U as Unsubscribe } from './types-D6fjl8Wy.cjs';
|
|
4
4
|
export { OfflineForm, createOfflineForm } from './forms.cjs';
|
|
5
|
-
export { F as FormRecord, a as FormStatus, b as FormSubmissionDetail, O as OfflineFormConfig } from './types-
|
|
5
|
+
export { F as FormRecord, a as FormStatus, b as FormSubmissionDetail, O as OfflineFormConfig } from './types-Cbm1nNDO.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { C as ConnectionMonitor, a as ConnectionMonitorOptions, E as EnqueueOptions, H as HttpMethod, L as LowdataClient, b as LowdataClientConfig, Q as QueueItem, c as QueueItemStatus, d as QueuedResult, S as SyncEvent, e as createLowdataClient, g as getConnectionQuality, i as isQueued, o as onConnectionChange } from './client-
|
|
2
|
-
export { L as LowdataRequestError, d as defaultRetryOn } from './retry-
|
|
3
|
-
export { C as ConnectionInfo, a as ConnectionListener, b as ConnectionQuality, J as JitterStrategy, R as RequestPriority,
|
|
1
|
+
export { C as ConnectionMonitor, a as ConnectionMonitorOptions, E as EnqueueOptions, H as HttpMethod, L as LowdataClient, b as LowdataClientConfig, Q as QueueItem, c as QueueItemStatus, d as QueuedResult, S as SyncEvent, e as createLowdataClient, g as getConnectionQuality, i as isQueued, o as onConnectionChange } from './client-DSKoYUj9.js';
|
|
2
|
+
export { L as LowdataRequestError, d as defaultRetryOn } from './retry-CnvZhHan.js';
|
|
3
|
+
export { C as ConnectionInfo, a as ConnectionListener, b as ConnectionQuality, J as JitterStrategy, L as LowdataErrorHandler, c as LowdataErrorScope, R as RequestPriority, d as RetryBackoffConfig, U as Unsubscribe } from './types-D6fjl8Wy.js';
|
|
4
4
|
export { OfflineForm, createOfflineForm } from './forms.js';
|
|
5
|
-
export { F as FormRecord, a as FormStatus, b as FormSubmissionDetail, O as OfflineFormConfig } from './types-
|
|
5
|
+
export { F as FormRecord, a as FormStatus, b as FormSubmissionDetail, O as OfflineFormConfig } from './types-1ha2HIfv.js';
|
package/dist/index.js
CHANGED
|
@@ -270,16 +270,23 @@ function getSharedDb() {
|
|
|
270
270
|
}
|
|
271
271
|
return sharedDbPromise;
|
|
272
272
|
}
|
|
273
|
-
function createDbFallbackAccessor(getDb) {
|
|
273
|
+
function createDbFallbackAccessor(getDb, onError) {
|
|
274
274
|
let dbAvailable = true;
|
|
275
275
|
return {
|
|
276
276
|
async run(fn, fallback) {
|
|
277
277
|
if (!dbAvailable) return fallback();
|
|
278
|
+
let db;
|
|
278
279
|
try {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
} catch {
|
|
280
|
+
db = await getDb();
|
|
281
|
+
} catch (error) {
|
|
282
282
|
dbAvailable = false;
|
|
283
|
+
onError == null ? void 0 : onError(error, { scope: "db-open" });
|
|
284
|
+
return fallback();
|
|
285
|
+
}
|
|
286
|
+
try {
|
|
287
|
+
return await fn(db);
|
|
288
|
+
} catch (error) {
|
|
289
|
+
onError == null ? void 0 : onError(error, { scope: "db-operation" });
|
|
283
290
|
return fallback();
|
|
284
291
|
}
|
|
285
292
|
},
|
|
@@ -305,9 +312,9 @@ var LowdataRequestError = class extends Error {
|
|
|
305
312
|
var STORE = "queue";
|
|
306
313
|
var PRIORITY_ORDER = { high: 0, normal: 1, low: 2 };
|
|
307
314
|
var RequestQueue = class {
|
|
308
|
-
constructor(getDb) {
|
|
315
|
+
constructor(getDb, onError) {
|
|
309
316
|
this.memory = /* @__PURE__ */ new Map();
|
|
310
|
-
this.accessor = createDbFallbackAccessor(getDb);
|
|
317
|
+
this.accessor = createDbFallbackAccessor(getDb, onError);
|
|
311
318
|
}
|
|
312
319
|
isPersistent() {
|
|
313
320
|
return this.accessor.isPersistent();
|
|
@@ -622,12 +629,16 @@ var SyncManager = class {
|
|
|
622
629
|
* or safety poll simply tries again.
|
|
623
630
|
*/
|
|
624
631
|
async drain() {
|
|
625
|
-
var _a, _b, _c, _d;
|
|
632
|
+
var _a, _b, _c, _d, _e, _f;
|
|
626
633
|
if (this.draining || this.disposed) return;
|
|
627
634
|
if (this.opts.connection.getStatus().quality === "offline") return;
|
|
628
635
|
this.draining = true;
|
|
629
636
|
try {
|
|
630
|
-
const db = await this.opts.getDb().catch(() =>
|
|
637
|
+
const db = await this.opts.getDb().catch((error) => {
|
|
638
|
+
var _a2, _b2;
|
|
639
|
+
(_b2 = (_a2 = this.opts).onError) == null ? void 0 : _b2.call(_a2, error, { scope: "db-open" });
|
|
640
|
+
return void 0;
|
|
641
|
+
});
|
|
631
642
|
const lock = await acquireSyncLock(db, SYNC_LOCK_NAME, this.ownerId);
|
|
632
643
|
if (!lock) return;
|
|
633
644
|
let succeeded = 0;
|
|
@@ -650,7 +661,8 @@ var SyncManager = class {
|
|
|
650
661
|
await lock.release().catch(() => {
|
|
651
662
|
});
|
|
652
663
|
}
|
|
653
|
-
} catch {
|
|
664
|
+
} catch (error) {
|
|
665
|
+
(_f = (_e = this.opts).onError) == null ? void 0 : _f.call(_e, error, { scope: "sync" });
|
|
654
666
|
} finally {
|
|
655
667
|
this.draining = false;
|
|
656
668
|
}
|
|
@@ -736,6 +748,9 @@ var MUTATING_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"
|
|
|
736
748
|
function defaultShouldQueueOffline({ method }) {
|
|
737
749
|
return MUTATING_METHODS.has(method);
|
|
738
750
|
}
|
|
751
|
+
var defaultOnError = (error, { scope }) => {
|
|
752
|
+
console.warn(`lowdata: internal error (${scope})`, error);
|
|
753
|
+
};
|
|
739
754
|
function normalizeHeaders(headers) {
|
|
740
755
|
if (!headers) return void 0;
|
|
741
756
|
if (headers instanceof Headers) {
|
|
@@ -764,15 +779,18 @@ var LowdataClient = class {
|
|
|
764
779
|
this.config = config;
|
|
765
780
|
this.syncEmitter = new Emitter();
|
|
766
781
|
this.destroyed = false;
|
|
782
|
+
var _a;
|
|
783
|
+
const onError = (_a = config.onError) != null ? _a : defaultOnError;
|
|
767
784
|
this.monitor = new ConnectionMonitor(config.connection);
|
|
768
|
-
this.requestQueue = new RequestQueue(() => getSharedDb());
|
|
785
|
+
this.requestQueue = new RequestQueue(() => getSharedDb(), onError);
|
|
769
786
|
this.syncManager = new SyncManager({
|
|
770
787
|
queue: this.requestQueue,
|
|
771
788
|
connection: this.monitor,
|
|
772
789
|
getDb: () => getSharedDb(),
|
|
773
790
|
retryConfig: config.retry,
|
|
774
791
|
syncConcurrency: config.syncConcurrency,
|
|
775
|
-
onEvent: (event) => this.syncEmitter.emit(event)
|
|
792
|
+
onEvent: (event) => this.syncEmitter.emit(event),
|
|
793
|
+
onError
|
|
776
794
|
});
|
|
777
795
|
this.connection = {
|
|
778
796
|
getStatus: () => this.monitor.getStatus(),
|