@neetru/sdk 3.0.2 → 3.1.1

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.
Files changed (98) hide show
  1. package/CHANGELOG.md +554 -530
  2. package/dist/auth.cjs +219 -54
  3. package/dist/auth.cjs.map +1 -1
  4. package/dist/auth.d.cts +1 -2
  5. package/dist/auth.d.ts +1 -2
  6. package/dist/auth.mjs +219 -54
  7. package/dist/auth.mjs.map +1 -1
  8. package/dist/catalog.cjs +50 -2
  9. package/dist/catalog.cjs.map +1 -1
  10. package/dist/catalog.d.cts +1 -2
  11. package/dist/catalog.d.ts +1 -2
  12. package/dist/catalog.mjs +50 -2
  13. package/dist/catalog.mjs.map +1 -1
  14. package/dist/checkout.cjs +52 -3
  15. package/dist/checkout.cjs.map +1 -1
  16. package/dist/checkout.d.cts +1 -2
  17. package/dist/checkout.d.ts +1 -2
  18. package/dist/checkout.mjs +52 -3
  19. package/dist/checkout.mjs.map +1 -1
  20. package/dist/db-react.cjs +18 -6
  21. package/dist/db-react.cjs.map +1 -1
  22. package/dist/db-react.d.cts +35 -13
  23. package/dist/db-react.d.ts +35 -13
  24. package/dist/db-react.mjs +18 -6
  25. package/dist/db-react.mjs.map +1 -1
  26. package/dist/db.cjs +164 -56
  27. package/dist/db.cjs.map +1 -1
  28. package/dist/db.d.cts +1 -2
  29. package/dist/db.d.ts +1 -2
  30. package/dist/db.mjs +164 -56
  31. package/dist/db.mjs.map +1 -1
  32. package/dist/entitlements.cjs +50 -2
  33. package/dist/entitlements.cjs.map +1 -1
  34. package/dist/entitlements.d.cts +1 -2
  35. package/dist/entitlements.d.ts +1 -2
  36. package/dist/entitlements.mjs +50 -2
  37. package/dist/entitlements.mjs.map +1 -1
  38. package/dist/errors.cjs.map +1 -1
  39. package/dist/errors.d.cts +3 -1
  40. package/dist/errors.d.ts +3 -1
  41. package/dist/errors.mjs.map +1 -1
  42. package/dist/firestore-compat.cjs +411 -0
  43. package/dist/firestore-compat.cjs.map +1 -0
  44. package/dist/firestore-compat.d.cts +319 -0
  45. package/dist/firestore-compat.d.ts +319 -0
  46. package/dist/firestore-compat.mjs +383 -0
  47. package/dist/firestore-compat.mjs.map +1 -0
  48. package/dist/index.cjs +266 -66
  49. package/dist/index.cjs.map +1 -1
  50. package/dist/index.d.cts +9 -4
  51. package/dist/index.d.ts +9 -4
  52. package/dist/index.mjs +265 -67
  53. package/dist/index.mjs.map +1 -1
  54. package/dist/mocks.cjs.map +1 -1
  55. package/dist/mocks.d.cts +1 -2
  56. package/dist/mocks.d.ts +1 -2
  57. package/dist/mocks.mjs.map +1 -1
  58. package/dist/notifications.cjs +50 -2
  59. package/dist/notifications.cjs.map +1 -1
  60. package/dist/notifications.d.cts +1 -2
  61. package/dist/notifications.d.ts +1 -2
  62. package/dist/notifications.mjs +50 -2
  63. package/dist/notifications.mjs.map +1 -1
  64. package/dist/react.cjs +268 -2
  65. package/dist/react.cjs.map +1 -1
  66. package/dist/react.d.cts +135 -3
  67. package/dist/react.d.ts +135 -3
  68. package/dist/react.mjs +266 -3
  69. package/dist/react.mjs.map +1 -1
  70. package/dist/support.cjs +50 -2
  71. package/dist/support.cjs.map +1 -1
  72. package/dist/support.d.cts +1 -2
  73. package/dist/support.d.ts +1 -2
  74. package/dist/support.mjs +50 -2
  75. package/dist/support.mjs.map +1 -1
  76. package/dist/telemetry.cjs +65 -4
  77. package/dist/telemetry.cjs.map +1 -1
  78. package/dist/telemetry.d.cts +1 -2
  79. package/dist/telemetry.d.ts +1 -2
  80. package/dist/telemetry.mjs +65 -4
  81. package/dist/telemetry.mjs.map +1 -1
  82. package/dist/{types-D7zVkO3n.d.ts → types-B3XFHD4A.d.ts} +640 -2
  83. package/dist/{types-Dc4bjrrt.d.cts → types-DePdSU3P.d.cts} +640 -2
  84. package/dist/usage.cjs +50 -2
  85. package/dist/usage.cjs.map +1 -1
  86. package/dist/usage.d.cts +1 -2
  87. package/dist/usage.d.ts +1 -2
  88. package/dist/usage.mjs +50 -2
  89. package/dist/usage.mjs.map +1 -1
  90. package/dist/webhooks.cjs +83 -2
  91. package/dist/webhooks.cjs.map +1 -1
  92. package/dist/webhooks.d.cts +1 -2
  93. package/dist/webhooks.d.ts +1 -2
  94. package/dist/webhooks.mjs +83 -3
  95. package/dist/webhooks.mjs.map +1 -1
  96. package/package.json +156 -151
  97. package/dist/collection-ref-BDdfD87k.d.cts +0 -581
  98. package/dist/collection-ref-BDdfD87k.d.ts +0 -581
package/dist/db.d.cts CHANGED
@@ -1,4 +1,3 @@
1
- export { C as ConflictRecord, a as CreateOfflineDocumentsOptions, D as DbBatchOp, b as DbChangeType, c as DbCollectionRef, d as DbDoc, e as DbDocRef, f as DbGetResult, g as DbListResult, h as DbQuery, i as DbWhereFilter, F as FieldSentinel, I as IncrementSentinel, N as NEETRU_SENTINEL_KEY, j as NeetruDbDocuments, R as RealtimeTransport, S as ServerTimestampSentinel, k as SyncState, W as WithFieldSentinels, l as increment, m as isFieldSentinel, n as isIncrementSentinel, o as isServerTimestampSentinel, s as serverTimestamp } from './collection-ref-BDdfD87k.cjs';
2
- export { k as DbSqlLease, p as NeetruDb, q as NeetruDbEngine, r as NeetruDbError, s as NeetruDbErrorCode, t as NeetruDbOptions, u as NeetruDbTransport, w as NeetruSqlClient, K as SqlOptions, a7 as createNeetruDb, a9 as createRestSyncTransport, ab as getWebSocketRealtimeClient } from './types-Dc4bjrrt.cjs';
1
+ export { i as ConflictRecord, j as CreateOfflineDocumentsOptions, l as DbBatchOp, m as DbChangeType, n as DbCollectionRef, o as DbDoc, p as DbDocRef, q as DbGetResult, r as DbListResult, t as DbQuery, u as DbSqlLease, w as DbWhereFilter, F as FieldSentinel, I as IncrementSentinel, N as NEETRU_SENTINEL_KEY, G as NeetruDb, H as NeetruDbDocuments, J as NeetruDbEngine, K as NeetruDbError, O as NeetruDbErrorCode, P as NeetruDbOptions, Q as NeetruDbTransport, S as NeetruSqlClient, $ as RealtimeTransport, a3 as ServerTimestampSentinel, a5 as SqlOptions, aa as SyncState, ar as WithFieldSentinels, at as createNeetruDb, av as createRestSyncTransport, ax as getWebSocketRealtimeClient, ay as increment, az as isFieldSentinel, aA as isIncrementSentinel, aB as isServerTimestampSentinel, aC as serverTimestamp } from './types-DePdSU3P.cjs';
3
2
  import 'drizzle-orm/node-postgres';
4
3
  import './errors.cjs';
package/dist/db.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export { C as ConflictRecord, a as CreateOfflineDocumentsOptions, D as DbBatchOp, b as DbChangeType, c as DbCollectionRef, d as DbDoc, e as DbDocRef, f as DbGetResult, g as DbListResult, h as DbQuery, i as DbWhereFilter, F as FieldSentinel, I as IncrementSentinel, N as NEETRU_SENTINEL_KEY, j as NeetruDbDocuments, R as RealtimeTransport, S as ServerTimestampSentinel, k as SyncState, W as WithFieldSentinels, l as increment, m as isFieldSentinel, n as isIncrementSentinel, o as isServerTimestampSentinel, s as serverTimestamp } from './collection-ref-BDdfD87k.js';
2
- export { k as DbSqlLease, p as NeetruDb, q as NeetruDbEngine, r as NeetruDbError, s as NeetruDbErrorCode, t as NeetruDbOptions, u as NeetruDbTransport, w as NeetruSqlClient, K as SqlOptions, a7 as createNeetruDb, a9 as createRestSyncTransport, ab as getWebSocketRealtimeClient } from './types-D7zVkO3n.js';
1
+ export { i as ConflictRecord, j as CreateOfflineDocumentsOptions, l as DbBatchOp, m as DbChangeType, n as DbCollectionRef, o as DbDoc, p as DbDocRef, q as DbGetResult, r as DbListResult, t as DbQuery, u as DbSqlLease, w as DbWhereFilter, F as FieldSentinel, I as IncrementSentinel, N as NEETRU_SENTINEL_KEY, G as NeetruDb, H as NeetruDbDocuments, J as NeetruDbEngine, K as NeetruDbError, O as NeetruDbErrorCode, P as NeetruDbOptions, Q as NeetruDbTransport, S as NeetruSqlClient, $ as RealtimeTransport, a3 as ServerTimestampSentinel, a5 as SqlOptions, aa as SyncState, ar as WithFieldSentinels, at as createNeetruDb, av as createRestSyncTransport, ax as getWebSocketRealtimeClient, ay as increment, az as isFieldSentinel, aA as isIncrementSentinel, aB as isServerTimestampSentinel, aC as serverTimestamp } from './types-B3XFHD4A.js';
3
2
  import 'drizzle-orm/node-postgres';
4
3
  import './errors.js';
package/dist/db.mjs CHANGED
@@ -85,8 +85,47 @@ var init_idempotency = __esm({
85
85
  // src/http.ts
86
86
  var http_exports = {};
87
87
  __export(http_exports, {
88
+ checkCoreVersionCompat: () => checkCoreVersionCompat,
88
89
  httpRequest: () => httpRequest
89
90
  });
91
+ function stripRevision(v) {
92
+ return v.split("+")[0] ?? v;
93
+ }
94
+ function compareCalVer(a, b) {
95
+ const partsA = stripRevision(a).split(".").map(Number);
96
+ const partsB = stripRevision(b).split(".").map(Number);
97
+ const len = Math.max(partsA.length, partsB.length);
98
+ for (let i = 0; i < len; i++) {
99
+ const pa = partsA[i] ?? 0;
100
+ const pb = partsB[i] ?? 0;
101
+ if (pa !== pb) return pa - pb;
102
+ }
103
+ return 0;
104
+ }
105
+ function getSdkMajor() {
106
+ try {
107
+ const ver = globalThis.__NEETRU_SDK_VERSION__;
108
+ if (ver) return parseInt(ver.split(".")[0] ?? "3", 10);
109
+ } catch {
110
+ }
111
+ return 3;
112
+ }
113
+ function checkCoreVersionCompat(coreVersion) {
114
+ if (!coreVersion) return;
115
+ const sdkMajor = getSdkMajor();
116
+ const minCore = COMPAT_MATRIX[sdkMajor];
117
+ if (!minCore) return;
118
+ const stripped = stripRevision(coreVersion);
119
+ if (compareCalVer(stripped, minCore) < 0) {
120
+ const key = `${sdkMajor}:${stripped}`;
121
+ if (!_warnedCoreTooOld.has(key)) {
122
+ _warnedCoreTooOld.add(key);
123
+ console.warn(
124
+ `[Neetru SDK] Aten\xE7\xE3o: Core vers\xE3o "${coreVersion}" \xE9 anterior ao m\xEDnimo recomendado "${minCore}" para SDK major ${sdkMajor}. Alguns recursos podem n\xE3o funcionar corretamente. Atualize o Core para a vers\xE3o mais recente.`
125
+ );
126
+ }
127
+ }
128
+ }
90
129
  function backoffMs(attempt) {
91
130
  const base = 200 * Math.pow(4, attempt);
92
131
  const jitter = base * 0.2 * (Math.random() * 2 - 1);
@@ -95,11 +134,11 @@ function backoffMs(attempt) {
95
134
  function parseRetryAfter(value) {
96
135
  if (!value) return null;
97
136
  const secs = Number(value);
98
- if (Number.isFinite(secs) && secs >= 0) return Math.round(secs * 1e3);
137
+ if (Number.isFinite(secs) && secs >= 0) return Math.min(Math.round(secs * 1e3), MAX_RETRY_AFTER_MS);
99
138
  const dateMs = Date.parse(value);
100
139
  if (Number.isFinite(dateMs)) {
101
140
  const delta = dateMs - Date.now();
102
- if (delta > 0) return delta;
141
+ if (delta > 0) return Math.min(delta, MAX_RETRY_AFTER_MS);
103
142
  }
104
143
  return null;
105
144
  }
@@ -110,6 +149,7 @@ function statusToCode(status) {
110
149
  if (status === 401) return "unauthorized";
111
150
  if (status === 403) return "forbidden";
112
151
  if (status === 404) return "not_found";
152
+ if (status === 409) return "conflict";
113
153
  if (status === 422 || status === 400) return "validation_failed";
114
154
  if (status === 429) return "rate_limited";
115
155
  if (status >= 500) return "server_error";
@@ -181,6 +221,8 @@ async function httpRequest(config, opts) {
181
221
  }
182
222
  const requestId = res.headers.get("x-request-id") ?? res.headers.get("x-correlation-id") ?? void 0;
183
223
  if (res.ok) {
224
+ const coreVersion = res.headers.get("x-neetru-version");
225
+ if (coreVersion) checkCoreVersionCompat(coreVersion);
184
226
  const parsed = await safeJson(res);
185
227
  return parsed;
186
228
  }
@@ -209,11 +251,17 @@ async function httpRequest(config, opts) {
209
251
  }
210
252
  throw lastError ?? new NeetruError("unknown", "unexpected httpRequest exit");
211
253
  }
212
- var DEFAULT_RETRIES_READ, DEFAULT_RETRIES_WRITE, READ_METHODS, RETRYABLE_CODES2;
254
+ var COMPAT_MATRIX, _warnedCoreTooOld, DEFAULT_RETRIES_READ, DEFAULT_RETRIES_WRITE, READ_METHODS, RETRYABLE_CODES2, MAX_RETRY_AFTER_MS;
213
255
  var init_http = __esm({
214
256
  "src/http.ts"() {
215
257
  init_errors();
216
258
  init_idempotency();
259
+ COMPAT_MATRIX = {
260
+ // SDK major 3.x requer Core ≥ 2026.05.1 (suporte a X-Neetru-Version header,
261
+ // runTransaction write-after-read, verifyWebhookRequest, webhooks 3.0+)
262
+ 3: "2026.05.1"
263
+ };
264
+ _warnedCoreTooOld = /* @__PURE__ */ new Set();
217
265
  DEFAULT_RETRIES_READ = 2;
218
266
  DEFAULT_RETRIES_WRITE = 0;
219
267
  READ_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD"]);
@@ -222,6 +270,7 @@ var init_http = __esm({
222
270
  "server_error",
223
271
  "network_error"
224
272
  ]);
273
+ MAX_RETRY_AFTER_MS = 6e4;
225
274
  }
226
275
  });
227
276
 
@@ -788,6 +837,31 @@ var LocalStore = class {
788
837
  this.db?.close();
789
838
  this.db = null;
790
839
  }
840
+ /**
841
+ * Apaga completamente o banco IndexedDB e o recria do zero.
842
+ *
843
+ * Ao contrário de `close()` + `open()` (que reabre o banco existente sem
844
+ * apagar dados), `clearAll()` chama `indexedDB.deleteDatabase(dbName)` e
845
+ * só então chama `open()` — garantindo que nenhum documento, mutação ou
846
+ * metadado sobrevive.
847
+ *
848
+ * BUG fix: `clearCache()` em `NeetruDbDocumentsImpl` chamava close+open,
849
+ * que reabre o mesmo banco. `clearAll()` é o método correto.
850
+ */
851
+ async clearAll() {
852
+ if (this.db !== null) {
853
+ this.db.close();
854
+ this.db = null;
855
+ }
856
+ await new Promise((resolve, reject) => {
857
+ const req = indexedDB.deleteDatabase(this.dbName);
858
+ req.onsuccess = () => resolve();
859
+ req.onerror = () => reject(req.error);
860
+ req.onblocked = () => {
861
+ };
862
+ });
863
+ await this.open();
864
+ }
791
865
  assertOpen() {
792
866
  if (this.db === null) {
793
867
  throw new Error("LocalStore: banco n\xE3o est\xE1 aberto. Chame open() primeiro.");
@@ -995,6 +1069,12 @@ var MemoryStore = class {
995
1069
  async open() {
996
1070
  }
997
1071
  async close() {
1072
+ }
1073
+ /**
1074
+ * Apaga todos os dados em memória — equivalente ao `indexedDB.deleteDatabase`
1075
+ * que `LocalStore.clearAll()` executa em ambientes com IndexedDB.
1076
+ */
1077
+ async clearAll() {
998
1078
  this._docs.clear();
999
1079
  this._mutations.clear();
1000
1080
  this._meta.clear();
@@ -1350,7 +1430,71 @@ var MutationQueue = class {
1350
1430
  }
1351
1431
  };
1352
1432
 
1433
+ // src/db/field-value.ts
1434
+ var NEETRU_SENTINEL_KEY = "__neetru__";
1435
+ function serverTimestamp() {
1436
+ return { __neetru__: "serverTimestamp" };
1437
+ }
1438
+ function increment(n) {
1439
+ if (typeof n !== "number" || !Number.isFinite(n)) {
1440
+ throw new TypeError(
1441
+ `increment(n): n deve ser um n\xFAmero finito (recebido: ${String(n)}).`
1442
+ );
1443
+ }
1444
+ return { __neetru__: "increment", operand: n };
1445
+ }
1446
+ function isFieldSentinel(v) {
1447
+ return typeof v === "object" && v !== null && NEETRU_SENTINEL_KEY in v && typeof v[NEETRU_SENTINEL_KEY] === "string";
1448
+ }
1449
+ function isServerTimestampSentinel(v) {
1450
+ return isFieldSentinel(v) && v.__neetru__ === "serverTimestamp";
1451
+ }
1452
+ function isIncrementSentinel(v) {
1453
+ return isFieldSentinel(v) && v.__neetru__ === "increment" && typeof v.operand === "number" && Number.isFinite(v.operand);
1454
+ }
1455
+ function resolveSentinelLocally(value, baseValue) {
1456
+ if (isServerTimestampSentinel(value)) {
1457
+ return Date.now();
1458
+ }
1459
+ if (isIncrementSentinel(value)) {
1460
+ const base = typeof baseValue === "number" && Number.isFinite(baseValue) ? baseValue : 0;
1461
+ return base + value.operand;
1462
+ }
1463
+ return value;
1464
+ }
1465
+ function resolveSentinelsLocally(data, existing) {
1466
+ let touched = false;
1467
+ const out = {};
1468
+ for (const [k, v] of Object.entries(data)) {
1469
+ if (isFieldSentinel(v)) {
1470
+ touched = true;
1471
+ out[k] = resolveSentinelLocally(v, existing?.[k]);
1472
+ } else {
1473
+ out[k] = v;
1474
+ }
1475
+ }
1476
+ return touched ? out : data;
1477
+ }
1478
+ function hasFieldSentinel(data) {
1479
+ for (const v of Object.values(data)) {
1480
+ if (isFieldSentinel(v)) return true;
1481
+ }
1482
+ return false;
1483
+ }
1484
+
1353
1485
  // src/db/offline/sync-engine.ts
1486
+ function hasSentinels(payload) {
1487
+ return payload !== null && hasFieldSentinel(payload);
1488
+ }
1489
+ function sanitizeSentinelPayload(payload) {
1490
+ if (payload === null) return null;
1491
+ if (!hasFieldSentinel(payload)) return payload;
1492
+ const out = {};
1493
+ for (const [k, v] of Object.entries(payload)) {
1494
+ if (!isFieldSentinel(v)) out[k] = v;
1495
+ }
1496
+ return out;
1497
+ }
1354
1498
  var SyncEngine = class {
1355
1499
  _store;
1356
1500
  _queue;
@@ -1456,6 +1600,8 @@ var SyncEngine = class {
1456
1600
  const phase1Ok = await this._phase1Push();
1457
1601
  if (!phase1Ok) {
1458
1602
  this._updateState({ status: "idle" });
1603
+ this._refreshPendingWrites().catch(() => {
1604
+ });
1459
1605
  this._syncing = false;
1460
1606
  return;
1461
1607
  }
@@ -1558,11 +1704,16 @@ var SyncEngine = class {
1558
1704
  }
1559
1705
  return;
1560
1706
  }
1561
- const newData = mut.payload ?? (existing?.data ?? {});
1707
+ const literalPayload = sanitizeSentinelPayload(mut.payload);
1708
+ const newData = literalPayload ?? (existing?.data ?? {});
1562
1709
  const updatedDoc = {
1563
1710
  collection,
1564
1711
  id: docId,
1565
- data: mut.op === "update" ? { ...existing?.data ?? {}, ...newData } : newData,
1712
+ data: mut.op === "update" ? { ...existing?.data ?? {}, ...newData } : (
1713
+ // add/set: se o payload tinha sentinels, o cache otimista (existing.data)
1714
+ // é a fonte de verdade até o pull; senão usa o payload literal.
1715
+ hasSentinels(mut.payload) ? { ...existing?.data ?? {}, ...newData } : newData
1716
+ ),
1566
1717
  meta: {
1567
1718
  serverVersion,
1568
1719
  updatedAtServer: serverTimestamp2,
@@ -1837,7 +1988,7 @@ var SyncEngine = class {
1837
1988
  ownerId: localDoc.meta.ownerId
1838
1989
  }
1839
1990
  };
1840
- const pendingMuts = await this._queue.drain();
1991
+ const pendingMuts = await this._queue.listAll();
1841
1992
  const docMut = pendingMuts.find(
1842
1993
  (m) => m.collection === serverDoc.collection && m.docId === serverDoc.id
1843
1994
  );
@@ -2644,54 +2795,6 @@ var TabCoordinator = class {
2644
2795
 
2645
2796
  // src/db/collection-ref.ts
2646
2797
  init_db_errors();
2647
-
2648
- // src/db/field-value.ts
2649
- var NEETRU_SENTINEL_KEY = "__neetru__";
2650
- function serverTimestamp() {
2651
- return { __neetru__: "serverTimestamp" };
2652
- }
2653
- function increment(n) {
2654
- if (typeof n !== "number" || !Number.isFinite(n)) {
2655
- throw new TypeError(
2656
- `increment(n): n deve ser um n\xFAmero finito (recebido: ${String(n)}).`
2657
- );
2658
- }
2659
- return { __neetru__: "increment", operand: n };
2660
- }
2661
- function isFieldSentinel(v) {
2662
- return typeof v === "object" && v !== null && NEETRU_SENTINEL_KEY in v && typeof v[NEETRU_SENTINEL_KEY] === "string";
2663
- }
2664
- function isServerTimestampSentinel(v) {
2665
- return isFieldSentinel(v) && v.__neetru__ === "serverTimestamp";
2666
- }
2667
- function isIncrementSentinel(v) {
2668
- return isFieldSentinel(v) && v.__neetru__ === "increment" && typeof v.operand === "number" && Number.isFinite(v.operand);
2669
- }
2670
- function resolveSentinelLocally(value, baseValue) {
2671
- if (isServerTimestampSentinel(value)) {
2672
- return Date.now();
2673
- }
2674
- if (isIncrementSentinel(value)) {
2675
- const base = typeof baseValue === "number" && Number.isFinite(baseValue) ? baseValue : 0;
2676
- return base + value.operand;
2677
- }
2678
- return value;
2679
- }
2680
- function resolveSentinelsLocally(data, existing) {
2681
- let touched = false;
2682
- const out = {};
2683
- for (const [k, v] of Object.entries(data)) {
2684
- if (isFieldSentinel(v)) {
2685
- touched = true;
2686
- out[k] = resolveSentinelLocally(v, existing?.[k]);
2687
- } else {
2688
- out[k] = v;
2689
- }
2690
- }
2691
- return touched ? out : data;
2692
- }
2693
-
2694
- // src/db/collection-ref.ts
2695
2798
  function isIndexedDBUnavailable() {
2696
2799
  return typeof indexedDB === "undefined" || typeof window === "undefined";
2697
2800
  }
@@ -3239,8 +3342,13 @@ var NeetruDbDocumentsImpl = class {
3239
3342
  return this._engine.flush();
3240
3343
  }
3241
3344
  async clearCache() {
3242
- await this._store.close();
3243
- await this._store.open();
3345
+ const storeWithClear = this._store;
3346
+ if (typeof storeWithClear.clearAll === "function") {
3347
+ await storeWithClear.clearAll();
3348
+ } else {
3349
+ await this._store.close();
3350
+ await this._store.open();
3351
+ }
3244
3352
  }
3245
3353
  async getConflicts() {
3246
3354
  return this._store.listConflicts();