@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/auth.cjs CHANGED
@@ -2043,7 +2043,60 @@ var MutationQueue = class {
2043
2043
  }
2044
2044
  };
2045
2045
 
2046
+ // src/db/field-value.ts
2047
+ var NEETRU_SENTINEL_KEY = "__neetru__";
2048
+ function isFieldSentinel(v) {
2049
+ return typeof v === "object" && v !== null && NEETRU_SENTINEL_KEY in v && typeof v[NEETRU_SENTINEL_KEY] === "string";
2050
+ }
2051
+ function isServerTimestampSentinel(v) {
2052
+ return isFieldSentinel(v) && v.__neetru__ === "serverTimestamp";
2053
+ }
2054
+ function isIncrementSentinel(v) {
2055
+ return isFieldSentinel(v) && v.__neetru__ === "increment" && typeof v.operand === "number" && Number.isFinite(v.operand);
2056
+ }
2057
+ function resolveSentinelLocally(value, baseValue) {
2058
+ if (isServerTimestampSentinel(value)) {
2059
+ return Date.now();
2060
+ }
2061
+ if (isIncrementSentinel(value)) {
2062
+ const base = typeof baseValue === "number" && Number.isFinite(baseValue) ? baseValue : 0;
2063
+ return base + value.operand;
2064
+ }
2065
+ return value;
2066
+ }
2067
+ function resolveSentinelsLocally(data, existing) {
2068
+ let touched = false;
2069
+ const out = {};
2070
+ for (const [k, v] of Object.entries(data)) {
2071
+ if (isFieldSentinel(v)) {
2072
+ touched = true;
2073
+ out[k] = resolveSentinelLocally(v, existing?.[k]);
2074
+ } else {
2075
+ out[k] = v;
2076
+ }
2077
+ }
2078
+ return touched ? out : data;
2079
+ }
2080
+ function hasFieldSentinel(data) {
2081
+ for (const v of Object.values(data)) {
2082
+ if (isFieldSentinel(v)) return true;
2083
+ }
2084
+ return false;
2085
+ }
2086
+
2046
2087
  // src/db/offline/sync-engine.ts
2088
+ function hasSentinels(payload) {
2089
+ return payload !== null && hasFieldSentinel(payload);
2090
+ }
2091
+ function sanitizeSentinelPayload(payload) {
2092
+ if (payload === null) return null;
2093
+ if (!hasFieldSentinel(payload)) return payload;
2094
+ const out = {};
2095
+ for (const [k, v] of Object.entries(payload)) {
2096
+ if (!isFieldSentinel(v)) out[k] = v;
2097
+ }
2098
+ return out;
2099
+ }
2047
2100
  var SyncEngine = class {
2048
2101
  _store;
2049
2102
  _queue;
@@ -2251,11 +2304,16 @@ var SyncEngine = class {
2251
2304
  }
2252
2305
  return;
2253
2306
  }
2254
- const newData = mut.payload ?? (existing?.data ?? {});
2307
+ const literalPayload = sanitizeSentinelPayload(mut.payload);
2308
+ const newData = literalPayload ?? (existing?.data ?? {});
2255
2309
  const updatedDoc = {
2256
2310
  collection,
2257
2311
  id: docId,
2258
- data: mut.op === "update" ? { ...existing?.data ?? {}, ...newData } : newData,
2312
+ data: mut.op === "update" ? { ...existing?.data ?? {}, ...newData } : (
2313
+ // add/set: se o payload tinha sentinels, o cache otimista (existing.data)
2314
+ // é a fonte de verdade até o pull; senão usa o payload literal.
2315
+ hasSentinels(mut.payload) ? { ...existing?.data ?? {}, ...newData } : newData
2316
+ ),
2259
2317
  meta: {
2260
2318
  serverVersion,
2261
2319
  updatedAtServer: serverTimestamp,
@@ -3337,43 +3395,6 @@ var TabCoordinator = class {
3337
3395
 
3338
3396
  // src/db/collection-ref.ts
3339
3397
  init_db_errors();
3340
-
3341
- // src/db/field-value.ts
3342
- var NEETRU_SENTINEL_KEY = "__neetru__";
3343
- function isFieldSentinel(v) {
3344
- return typeof v === "object" && v !== null && NEETRU_SENTINEL_KEY in v && typeof v[NEETRU_SENTINEL_KEY] === "string";
3345
- }
3346
- function isServerTimestampSentinel(v) {
3347
- return isFieldSentinel(v) && v.__neetru__ === "serverTimestamp";
3348
- }
3349
- function isIncrementSentinel(v) {
3350
- return isFieldSentinel(v) && v.__neetru__ === "increment" && typeof v.operand === "number" && Number.isFinite(v.operand);
3351
- }
3352
- function resolveSentinelLocally(value, baseValue) {
3353
- if (isServerTimestampSentinel(value)) {
3354
- return Date.now();
3355
- }
3356
- if (isIncrementSentinel(value)) {
3357
- const base = typeof baseValue === "number" && Number.isFinite(baseValue) ? baseValue : 0;
3358
- return base + value.operand;
3359
- }
3360
- return value;
3361
- }
3362
- function resolveSentinelsLocally(data, existing) {
3363
- let touched = false;
3364
- const out = {};
3365
- for (const [k, v] of Object.entries(data)) {
3366
- if (isFieldSentinel(v)) {
3367
- touched = true;
3368
- out[k] = resolveSentinelLocally(v, existing?.[k]);
3369
- } else {
3370
- out[k] = v;
3371
- }
3372
- }
3373
- return touched ? out : data;
3374
- }
3375
-
3376
- // src/db/collection-ref.ts
3377
3398
  function isIndexedDBUnavailable() {
3378
3399
  return typeof indexedDB === "undefined" || typeof window === "undefined";
3379
3400
  }