@neetru/sdk 3.0.2 → 3.1.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.
Files changed (60) hide show
  1. package/CHANGELOG.md +554 -530
  2. package/dist/auth.cjs +60 -39
  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 +60 -39
  7. package/dist/auth.mjs.map +1 -1
  8. package/dist/catalog.d.cts +1 -2
  9. package/dist/catalog.d.ts +1 -2
  10. package/dist/checkout.d.cts +1 -2
  11. package/dist/checkout.d.ts +1 -2
  12. package/dist/db-react.cjs +15 -5
  13. package/dist/db-react.cjs.map +1 -1
  14. package/dist/db-react.d.cts +35 -13
  15. package/dist/db-react.d.ts +35 -13
  16. package/dist/db-react.mjs +15 -5
  17. package/dist/db-react.mjs.map +1 -1
  18. package/dist/db.cjs +71 -50
  19. package/dist/db.cjs.map +1 -1
  20. package/dist/db.d.cts +1 -2
  21. package/dist/db.d.ts +1 -2
  22. package/dist/db.mjs +71 -50
  23. package/dist/db.mjs.map +1 -1
  24. package/dist/entitlements.d.cts +1 -2
  25. package/dist/entitlements.d.ts +1 -2
  26. package/dist/firestore-compat.cjs +399 -0
  27. package/dist/firestore-compat.cjs.map +1 -0
  28. package/dist/firestore-compat.d.cts +294 -0
  29. package/dist/firestore-compat.d.ts +294 -0
  30. package/dist/firestore-compat.mjs +371 -0
  31. package/dist/firestore-compat.mjs.map +1 -0
  32. package/dist/index.cjs +72 -51
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +2 -3
  35. package/dist/index.d.ts +2 -3
  36. package/dist/index.mjs +72 -51
  37. package/dist/index.mjs.map +1 -1
  38. package/dist/mocks.d.cts +1 -2
  39. package/dist/mocks.d.ts +1 -2
  40. package/dist/notifications.d.cts +1 -2
  41. package/dist/notifications.d.ts +1 -2
  42. package/dist/react.cjs +267 -0
  43. package/dist/react.cjs.map +1 -1
  44. package/dist/react.d.cts +117 -3
  45. package/dist/react.d.ts +117 -3
  46. package/dist/react.mjs +265 -1
  47. package/dist/react.mjs.map +1 -1
  48. package/dist/support.d.cts +1 -2
  49. package/dist/support.d.ts +1 -2
  50. package/dist/telemetry.d.cts +1 -2
  51. package/dist/telemetry.d.ts +1 -2
  52. package/dist/{types-D7zVkO3n.d.ts → types-BRv8wBxX.d.ts} +581 -2
  53. package/dist/{types-Dc4bjrrt.d.cts → types-nwErcRX8.d.cts} +581 -2
  54. package/dist/usage.d.cts +1 -2
  55. package/dist/usage.d.ts +1 -2
  56. package/dist/webhooks.d.cts +1 -2
  57. package/dist/webhooks.d.ts +1 -2
  58. package/package.json +156 -151
  59. package/dist/collection-ref-BDdfD87k.d.cts +0 -581
  60. 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, ap as WithFieldSentinels, ar as createNeetruDb, at as createRestSyncTransport, av as getWebSocketRealtimeClient, aw as increment, ax as isFieldSentinel, ay as isIncrementSentinel, az as isServerTimestampSentinel, aA as serverTimestamp } from './types-nwErcRX8.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, ap as WithFieldSentinels, ar as createNeetruDb, at as createRestSyncTransport, av as getWebSocketRealtimeClient, aw as increment, ax as isFieldSentinel, ay as isIncrementSentinel, az as isServerTimestampSentinel, aA as serverTimestamp } from './types-BRv8wBxX.js';
3
2
  import 'drizzle-orm/node-postgres';
4
3
  import './errors.js';
package/dist/db.mjs CHANGED
@@ -1350,7 +1350,71 @@ var MutationQueue = class {
1350
1350
  }
1351
1351
  };
1352
1352
 
1353
+ // src/db/field-value.ts
1354
+ var NEETRU_SENTINEL_KEY = "__neetru__";
1355
+ function serverTimestamp() {
1356
+ return { __neetru__: "serverTimestamp" };
1357
+ }
1358
+ function increment(n) {
1359
+ if (typeof n !== "number" || !Number.isFinite(n)) {
1360
+ throw new TypeError(
1361
+ `increment(n): n deve ser um n\xFAmero finito (recebido: ${String(n)}).`
1362
+ );
1363
+ }
1364
+ return { __neetru__: "increment", operand: n };
1365
+ }
1366
+ function isFieldSentinel(v) {
1367
+ return typeof v === "object" && v !== null && NEETRU_SENTINEL_KEY in v && typeof v[NEETRU_SENTINEL_KEY] === "string";
1368
+ }
1369
+ function isServerTimestampSentinel(v) {
1370
+ return isFieldSentinel(v) && v.__neetru__ === "serverTimestamp";
1371
+ }
1372
+ function isIncrementSentinel(v) {
1373
+ return isFieldSentinel(v) && v.__neetru__ === "increment" && typeof v.operand === "number" && Number.isFinite(v.operand);
1374
+ }
1375
+ function resolveSentinelLocally(value, baseValue) {
1376
+ if (isServerTimestampSentinel(value)) {
1377
+ return Date.now();
1378
+ }
1379
+ if (isIncrementSentinel(value)) {
1380
+ const base = typeof baseValue === "number" && Number.isFinite(baseValue) ? baseValue : 0;
1381
+ return base + value.operand;
1382
+ }
1383
+ return value;
1384
+ }
1385
+ function resolveSentinelsLocally(data, existing) {
1386
+ let touched = false;
1387
+ const out = {};
1388
+ for (const [k, v] of Object.entries(data)) {
1389
+ if (isFieldSentinel(v)) {
1390
+ touched = true;
1391
+ out[k] = resolveSentinelLocally(v, existing?.[k]);
1392
+ } else {
1393
+ out[k] = v;
1394
+ }
1395
+ }
1396
+ return touched ? out : data;
1397
+ }
1398
+ function hasFieldSentinel(data) {
1399
+ for (const v of Object.values(data)) {
1400
+ if (isFieldSentinel(v)) return true;
1401
+ }
1402
+ return false;
1403
+ }
1404
+
1353
1405
  // src/db/offline/sync-engine.ts
1406
+ function hasSentinels(payload) {
1407
+ return payload !== null && hasFieldSentinel(payload);
1408
+ }
1409
+ function sanitizeSentinelPayload(payload) {
1410
+ if (payload === null) return null;
1411
+ if (!hasFieldSentinel(payload)) return payload;
1412
+ const out = {};
1413
+ for (const [k, v] of Object.entries(payload)) {
1414
+ if (!isFieldSentinel(v)) out[k] = v;
1415
+ }
1416
+ return out;
1417
+ }
1354
1418
  var SyncEngine = class {
1355
1419
  _store;
1356
1420
  _queue;
@@ -1558,11 +1622,16 @@ var SyncEngine = class {
1558
1622
  }
1559
1623
  return;
1560
1624
  }
1561
- const newData = mut.payload ?? (existing?.data ?? {});
1625
+ const literalPayload = sanitizeSentinelPayload(mut.payload);
1626
+ const newData = literalPayload ?? (existing?.data ?? {});
1562
1627
  const updatedDoc = {
1563
1628
  collection,
1564
1629
  id: docId,
1565
- data: mut.op === "update" ? { ...existing?.data ?? {}, ...newData } : newData,
1630
+ data: mut.op === "update" ? { ...existing?.data ?? {}, ...newData } : (
1631
+ // add/set: se o payload tinha sentinels, o cache otimista (existing.data)
1632
+ // é a fonte de verdade até o pull; senão usa o payload literal.
1633
+ hasSentinels(mut.payload) ? { ...existing?.data ?? {}, ...newData } : newData
1634
+ ),
1566
1635
  meta: {
1567
1636
  serverVersion,
1568
1637
  updatedAtServer: serverTimestamp2,
@@ -2644,54 +2713,6 @@ var TabCoordinator = class {
2644
2713
 
2645
2714
  // src/db/collection-ref.ts
2646
2715
  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
2716
  function isIndexedDBUnavailable() {
2696
2717
  return typeof indexedDB === "undefined" || typeof window === "undefined";
2697
2718
  }