@neetru/sdk 3.0.1 → 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 -492
  2. package/dist/auth.cjs +84 -15
  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 +84 -15
  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 +104 -18
  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 +99 -19
  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 +105 -19
  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 +100 -20
  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-DALIhcbq.d.ts → types-BRv8wBxX.d.ts} +581 -2
  53. package/dist/{types-Lfd3LiAF.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-DqAAhuhX.d.cts +0 -472
  60. package/dist/collection-ref-DqAAhuhX.d.ts +0 -472
package/dist/auth.d.cts CHANGED
@@ -1,5 +1,4 @@
1
- import { o as NeetruClientConfig, N as NeetruClient } from './types-Lfd3LiAF.cjs';
2
- import './collection-ref-DqAAhuhX.cjs';
1
+ import { B as NeetruClientConfig, z as NeetruClient } from './types-nwErcRX8.cjs';
3
2
  import 'drizzle-orm/node-postgres';
4
3
  import './errors.cjs';
5
4
 
package/dist/auth.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { o as NeetruClientConfig, N as NeetruClient } from './types-DALIhcbq.js';
2
- import './collection-ref-DqAAhuhX.js';
1
+ import { B as NeetruClientConfig, z as NeetruClient } from './types-BRv8wBxX.js';
3
2
  import 'drizzle-orm/node-postgres';
4
3
  import './errors.js';
5
4
 
package/dist/auth.mjs CHANGED
@@ -2041,7 +2041,60 @@ var MutationQueue = class {
2041
2041
  }
2042
2042
  };
2043
2043
 
2044
+ // src/db/field-value.ts
2045
+ var NEETRU_SENTINEL_KEY = "__neetru__";
2046
+ function isFieldSentinel(v) {
2047
+ return typeof v === "object" && v !== null && NEETRU_SENTINEL_KEY in v && typeof v[NEETRU_SENTINEL_KEY] === "string";
2048
+ }
2049
+ function isServerTimestampSentinel(v) {
2050
+ return isFieldSentinel(v) && v.__neetru__ === "serverTimestamp";
2051
+ }
2052
+ function isIncrementSentinel(v) {
2053
+ return isFieldSentinel(v) && v.__neetru__ === "increment" && typeof v.operand === "number" && Number.isFinite(v.operand);
2054
+ }
2055
+ function resolveSentinelLocally(value, baseValue) {
2056
+ if (isServerTimestampSentinel(value)) {
2057
+ return Date.now();
2058
+ }
2059
+ if (isIncrementSentinel(value)) {
2060
+ const base = typeof baseValue === "number" && Number.isFinite(baseValue) ? baseValue : 0;
2061
+ return base + value.operand;
2062
+ }
2063
+ return value;
2064
+ }
2065
+ function resolveSentinelsLocally(data, existing) {
2066
+ let touched = false;
2067
+ const out = {};
2068
+ for (const [k, v] of Object.entries(data)) {
2069
+ if (isFieldSentinel(v)) {
2070
+ touched = true;
2071
+ out[k] = resolveSentinelLocally(v, existing?.[k]);
2072
+ } else {
2073
+ out[k] = v;
2074
+ }
2075
+ }
2076
+ return touched ? out : data;
2077
+ }
2078
+ function hasFieldSentinel(data) {
2079
+ for (const v of Object.values(data)) {
2080
+ if (isFieldSentinel(v)) return true;
2081
+ }
2082
+ return false;
2083
+ }
2084
+
2044
2085
  // src/db/offline/sync-engine.ts
2086
+ function hasSentinels(payload) {
2087
+ return payload !== null && hasFieldSentinel(payload);
2088
+ }
2089
+ function sanitizeSentinelPayload(payload) {
2090
+ if (payload === null) return null;
2091
+ if (!hasFieldSentinel(payload)) return payload;
2092
+ const out = {};
2093
+ for (const [k, v] of Object.entries(payload)) {
2094
+ if (!isFieldSentinel(v)) out[k] = v;
2095
+ }
2096
+ return out;
2097
+ }
2045
2098
  var SyncEngine = class {
2046
2099
  _store;
2047
2100
  _queue;
@@ -2249,11 +2302,16 @@ var SyncEngine = class {
2249
2302
  }
2250
2303
  return;
2251
2304
  }
2252
- const newData = mut.payload ?? (existing?.data ?? {});
2305
+ const literalPayload = sanitizeSentinelPayload(mut.payload);
2306
+ const newData = literalPayload ?? (existing?.data ?? {});
2253
2307
  const updatedDoc = {
2254
2308
  collection,
2255
2309
  id: docId,
2256
- data: mut.op === "update" ? { ...existing?.data ?? {}, ...newData } : newData,
2310
+ data: mut.op === "update" ? { ...existing?.data ?? {}, ...newData } : (
2311
+ // add/set: se o payload tinha sentinels, o cache otimista (existing.data)
2312
+ // é a fonte de verdade até o pull; senão usa o payload literal.
2313
+ hasSentinels(mut.payload) ? { ...existing?.data ?? {}, ...newData } : newData
2314
+ ),
2257
2315
  meta: {
2258
2316
  serverVersion,
2259
2317
  updatedAtServer: serverTimestamp,
@@ -3463,10 +3521,12 @@ var DbCollectionRefImpl = class {
3463
3521
  return this._buildListResult(q);
3464
3522
  }
3465
3523
  async add(data) {
3524
+ const rawData = data;
3525
+ const localData = resolveSentinelsLocally(rawData, void 0);
3466
3526
  const mutation = await this._queue.enqueue({
3467
3527
  collection: this._collection,
3468
3528
  op: "add",
3469
- payload: data,
3529
+ payload: rawData,
3470
3530
  baseVersion: null,
3471
3531
  batchId: null
3472
3532
  });
@@ -3474,7 +3534,7 @@ var DbCollectionRefImpl = class {
3474
3534
  await this._store.putDoc({
3475
3535
  collection: this._collection,
3476
3536
  id: docId,
3477
- data,
3537
+ data: localData,
3478
3538
  meta: {
3479
3539
  serverVersion: null,
3480
3540
  updatedAtServer: null,
@@ -3488,25 +3548,27 @@ var DbCollectionRefImpl = class {
3488
3548
  this._bus.emit([{
3489
3549
  type: "added",
3490
3550
  collection: this._collection,
3491
- doc: { id: docId, data }
3551
+ doc: { id: docId, data: localData }
3492
3552
  }]);
3493
3553
  return { ok: true, id: docId };
3494
3554
  }
3495
3555
  async set(id, data) {
3496
3556
  assertValidId(id);
3497
3557
  const existing = await this._store.getDoc(this._collection, id);
3558
+ const rawData = data;
3559
+ const localData = resolveSentinelsLocally(rawData, void 0);
3498
3560
  const mutation = await this._queue.enqueue({
3499
3561
  collection: this._collection,
3500
3562
  docId: id,
3501
3563
  op: "set",
3502
- payload: data,
3564
+ payload: rawData,
3503
3565
  baseVersion: existing?.meta.serverVersion ?? null,
3504
3566
  batchId: null
3505
3567
  });
3506
3568
  await this._store.putDoc({
3507
3569
  collection: this._collection,
3508
3570
  id,
3509
- data,
3571
+ data: localData,
3510
3572
  meta: {
3511
3573
  serverVersion: existing?.meta.serverVersion ?? null,
3512
3574
  updatedAtServer: existing?.meta.updatedAtServer ?? null,
@@ -3520,19 +3582,22 @@ var DbCollectionRefImpl = class {
3520
3582
  this._bus.emit([{
3521
3583
  type: existing && !existing.meta.deleted ? "modified" : "added",
3522
3584
  collection: this._collection,
3523
- doc: { id, data }
3585
+ doc: { id, data: localData }
3524
3586
  }]);
3525
3587
  return { ok: true };
3526
3588
  }
3527
3589
  async update(id, data) {
3528
3590
  assertValidId(id);
3529
3591
  const existing = await this._store.getDoc(this._collection, id);
3530
- const mergedData = existing?.meta.deleted ? { ...data } : { ...existing?.data ?? {}, ...data };
3592
+ const rawData = data;
3593
+ const existingBase = existing?.meta.deleted ? void 0 : existing?.data;
3594
+ const localData = resolveSentinelsLocally(rawData, existingBase);
3595
+ const mergedData = existing?.meta.deleted ? { ...localData } : { ...existing?.data ?? {}, ...localData };
3531
3596
  const mutation = await this._queue.enqueue({
3532
3597
  collection: this._collection,
3533
3598
  docId: id,
3534
3599
  op: "update",
3535
- payload: data,
3600
+ payload: rawData,
3536
3601
  baseVersion: existing?.meta.serverVersion ?? null,
3537
3602
  batchId: null
3538
3603
  });
@@ -3589,6 +3654,7 @@ var DbCollectionRefImpl = class {
3589
3654
  const collection = this._collection;
3590
3655
  if (op.kind === "add") {
3591
3656
  const data = op.data;
3657
+ const localData = resolveSentinelsLocally(data, void 0);
3592
3658
  const mutation = await this._queue.enqueue({
3593
3659
  collection,
3594
3660
  op: "add",
@@ -3600,7 +3666,7 @@ var DbCollectionRefImpl = class {
3600
3666
  await this._store.putDoc({
3601
3667
  collection,
3602
3668
  id: docId,
3603
- data,
3669
+ data: localData,
3604
3670
  meta: {
3605
3671
  serverVersion: null,
3606
3672
  updatedAtServer: null,
@@ -3611,11 +3677,12 @@ var DbCollectionRefImpl = class {
3611
3677
  ownerId: null
3612
3678
  }
3613
3679
  });
3614
- busChanges.push({ type: "added", collection, doc: { id: docId, data } });
3680
+ busChanges.push({ type: "added", collection, doc: { id: docId, data: localData } });
3615
3681
  } else if (op.kind === "set") {
3616
3682
  const id = op.id;
3617
3683
  const data = op.data;
3618
3684
  const existing = await this._store.getDoc(collection, id);
3685
+ const localData = resolveSentinelsLocally(data, void 0);
3619
3686
  const mutation = await this._queue.enqueue({
3620
3687
  collection,
3621
3688
  docId: id,
@@ -3627,7 +3694,7 @@ var DbCollectionRefImpl = class {
3627
3694
  await this._store.putDoc({
3628
3695
  collection,
3629
3696
  id,
3630
- data,
3697
+ data: localData,
3631
3698
  meta: {
3632
3699
  serverVersion: existing?.meta.serverVersion ?? null,
3633
3700
  updatedAtServer: existing?.meta.updatedAtServer ?? null,
@@ -3641,13 +3708,15 @@ var DbCollectionRefImpl = class {
3641
3708
  busChanges.push({
3642
3709
  type: existing && !existing.meta.deleted ? "modified" : "added",
3643
3710
  collection,
3644
- doc: { id, data }
3711
+ doc: { id, data: localData }
3645
3712
  });
3646
3713
  } else if (op.kind === "update") {
3647
3714
  const id = op.id;
3648
3715
  const data = op.data;
3649
3716
  const existing = await this._store.getDoc(collection, id);
3650
- const merged = { ...existing?.data ?? {}, ...data };
3717
+ const existingBase = existing?.meta.deleted ? void 0 : existing?.data;
3718
+ const localData = resolveSentinelsLocally(data, existingBase);
3719
+ const merged = { ...existing?.data ?? {}, ...localData };
3651
3720
  const mutation = await this._queue.enqueue({
3652
3721
  collection,
3653
3722
  docId: id,