@neetru/sdk 3.0.1 → 3.0.2

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 (46) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/auth.cjs +61 -13
  3. package/dist/auth.cjs.map +1 -1
  4. package/dist/auth.d.cts +2 -2
  5. package/dist/auth.d.ts +2 -2
  6. package/dist/auth.mjs +61 -13
  7. package/dist/auth.mjs.map +1 -1
  8. package/dist/catalog.d.cts +2 -2
  9. package/dist/catalog.d.ts +2 -2
  10. package/dist/checkout.d.cts +2 -2
  11. package/dist/checkout.d.ts +2 -2
  12. package/dist/{collection-ref-DqAAhuhX.d.cts → collection-ref-BDdfD87k.d.cts} +118 -9
  13. package/dist/{collection-ref-DqAAhuhX.d.ts → collection-ref-BDdfD87k.d.ts} +118 -9
  14. package/dist/db-react.d.cts +1 -1
  15. package/dist/db-react.d.ts +1 -1
  16. package/dist/db.cjs +81 -16
  17. package/dist/db.cjs.map +1 -1
  18. package/dist/db.d.cts +2 -2
  19. package/dist/db.d.ts +2 -2
  20. package/dist/db.mjs +76 -17
  21. package/dist/db.mjs.map +1 -1
  22. package/dist/entitlements.d.cts +2 -2
  23. package/dist/entitlements.d.ts +2 -2
  24. package/dist/index.cjs +81 -16
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.cts +2 -2
  27. package/dist/index.d.ts +2 -2
  28. package/dist/index.mjs +76 -17
  29. package/dist/index.mjs.map +1 -1
  30. package/dist/mocks.d.cts +2 -2
  31. package/dist/mocks.d.ts +2 -2
  32. package/dist/notifications.d.cts +2 -2
  33. package/dist/notifications.d.ts +2 -2
  34. package/dist/react.d.cts +2 -2
  35. package/dist/react.d.ts +2 -2
  36. package/dist/support.d.cts +2 -2
  37. package/dist/support.d.ts +2 -2
  38. package/dist/telemetry.d.cts +2 -2
  39. package/dist/telemetry.d.ts +2 -2
  40. package/dist/{types-DALIhcbq.d.ts → types-D7zVkO3n.d.ts} +1 -1
  41. package/dist/{types-Lfd3LiAF.d.cts → types-Dc4bjrrt.d.cts} +1 -1
  42. package/dist/usage.d.cts +2 -2
  43. package/dist/usage.d.ts +2 -2
  44. package/dist/webhooks.d.cts +2 -2
  45. package/dist/webhooks.d.ts +2 -2
  46. package/package.json +1 -1
package/dist/auth.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { o as NeetruClientConfig, N as NeetruClient } from './types-Lfd3LiAF.cjs';
2
- import './collection-ref-DqAAhuhX.cjs';
1
+ import { o as NeetruClientConfig, N as NeetruClient } from './types-Dc4bjrrt.cjs';
2
+ import './collection-ref-BDdfD87k.cjs';
3
3
  import 'drizzle-orm/node-postgres';
4
4
  import './errors.cjs';
5
5
 
package/dist/auth.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { o as NeetruClientConfig, N as NeetruClient } from './types-DALIhcbq.js';
2
- import './collection-ref-DqAAhuhX.js';
1
+ import { o as NeetruClientConfig, N as NeetruClient } from './types-D7zVkO3n.js';
2
+ import './collection-ref-BDdfD87k.js';
3
3
  import 'drizzle-orm/node-postgres';
4
4
  import './errors.js';
5
5
 
package/dist/auth.mjs CHANGED
@@ -3335,6 +3335,43 @@ var TabCoordinator = class {
3335
3335
 
3336
3336
  // src/db/collection-ref.ts
3337
3337
  init_db_errors();
3338
+
3339
+ // src/db/field-value.ts
3340
+ var NEETRU_SENTINEL_KEY = "__neetru__";
3341
+ function isFieldSentinel(v) {
3342
+ return typeof v === "object" && v !== null && NEETRU_SENTINEL_KEY in v && typeof v[NEETRU_SENTINEL_KEY] === "string";
3343
+ }
3344
+ function isServerTimestampSentinel(v) {
3345
+ return isFieldSentinel(v) && v.__neetru__ === "serverTimestamp";
3346
+ }
3347
+ function isIncrementSentinel(v) {
3348
+ return isFieldSentinel(v) && v.__neetru__ === "increment" && typeof v.operand === "number" && Number.isFinite(v.operand);
3349
+ }
3350
+ function resolveSentinelLocally(value, baseValue) {
3351
+ if (isServerTimestampSentinel(value)) {
3352
+ return Date.now();
3353
+ }
3354
+ if (isIncrementSentinel(value)) {
3355
+ const base = typeof baseValue === "number" && Number.isFinite(baseValue) ? baseValue : 0;
3356
+ return base + value.operand;
3357
+ }
3358
+ return value;
3359
+ }
3360
+ function resolveSentinelsLocally(data, existing) {
3361
+ let touched = false;
3362
+ const out = {};
3363
+ for (const [k, v] of Object.entries(data)) {
3364
+ if (isFieldSentinel(v)) {
3365
+ touched = true;
3366
+ out[k] = resolveSentinelLocally(v, existing?.[k]);
3367
+ } else {
3368
+ out[k] = v;
3369
+ }
3370
+ }
3371
+ return touched ? out : data;
3372
+ }
3373
+
3374
+ // src/db/collection-ref.ts
3338
3375
  function isIndexedDBUnavailable() {
3339
3376
  return typeof indexedDB === "undefined" || typeof window === "undefined";
3340
3377
  }
@@ -3463,10 +3500,12 @@ var DbCollectionRefImpl = class {
3463
3500
  return this._buildListResult(q);
3464
3501
  }
3465
3502
  async add(data) {
3503
+ const rawData = data;
3504
+ const localData = resolveSentinelsLocally(rawData, void 0);
3466
3505
  const mutation = await this._queue.enqueue({
3467
3506
  collection: this._collection,
3468
3507
  op: "add",
3469
- payload: data,
3508
+ payload: rawData,
3470
3509
  baseVersion: null,
3471
3510
  batchId: null
3472
3511
  });
@@ -3474,7 +3513,7 @@ var DbCollectionRefImpl = class {
3474
3513
  await this._store.putDoc({
3475
3514
  collection: this._collection,
3476
3515
  id: docId,
3477
- data,
3516
+ data: localData,
3478
3517
  meta: {
3479
3518
  serverVersion: null,
3480
3519
  updatedAtServer: null,
@@ -3488,25 +3527,27 @@ var DbCollectionRefImpl = class {
3488
3527
  this._bus.emit([{
3489
3528
  type: "added",
3490
3529
  collection: this._collection,
3491
- doc: { id: docId, data }
3530
+ doc: { id: docId, data: localData }
3492
3531
  }]);
3493
3532
  return { ok: true, id: docId };
3494
3533
  }
3495
3534
  async set(id, data) {
3496
3535
  assertValidId(id);
3497
3536
  const existing = await this._store.getDoc(this._collection, id);
3537
+ const rawData = data;
3538
+ const localData = resolveSentinelsLocally(rawData, void 0);
3498
3539
  const mutation = await this._queue.enqueue({
3499
3540
  collection: this._collection,
3500
3541
  docId: id,
3501
3542
  op: "set",
3502
- payload: data,
3543
+ payload: rawData,
3503
3544
  baseVersion: existing?.meta.serverVersion ?? null,
3504
3545
  batchId: null
3505
3546
  });
3506
3547
  await this._store.putDoc({
3507
3548
  collection: this._collection,
3508
3549
  id,
3509
- data,
3550
+ data: localData,
3510
3551
  meta: {
3511
3552
  serverVersion: existing?.meta.serverVersion ?? null,
3512
3553
  updatedAtServer: existing?.meta.updatedAtServer ?? null,
@@ -3520,19 +3561,22 @@ var DbCollectionRefImpl = class {
3520
3561
  this._bus.emit([{
3521
3562
  type: existing && !existing.meta.deleted ? "modified" : "added",
3522
3563
  collection: this._collection,
3523
- doc: { id, data }
3564
+ doc: { id, data: localData }
3524
3565
  }]);
3525
3566
  return { ok: true };
3526
3567
  }
3527
3568
  async update(id, data) {
3528
3569
  assertValidId(id);
3529
3570
  const existing = await this._store.getDoc(this._collection, id);
3530
- const mergedData = existing?.meta.deleted ? { ...data } : { ...existing?.data ?? {}, ...data };
3571
+ const rawData = data;
3572
+ const existingBase = existing?.meta.deleted ? void 0 : existing?.data;
3573
+ const localData = resolveSentinelsLocally(rawData, existingBase);
3574
+ const mergedData = existing?.meta.deleted ? { ...localData } : { ...existing?.data ?? {}, ...localData };
3531
3575
  const mutation = await this._queue.enqueue({
3532
3576
  collection: this._collection,
3533
3577
  docId: id,
3534
3578
  op: "update",
3535
- payload: data,
3579
+ payload: rawData,
3536
3580
  baseVersion: existing?.meta.serverVersion ?? null,
3537
3581
  batchId: null
3538
3582
  });
@@ -3589,6 +3633,7 @@ var DbCollectionRefImpl = class {
3589
3633
  const collection = this._collection;
3590
3634
  if (op.kind === "add") {
3591
3635
  const data = op.data;
3636
+ const localData = resolveSentinelsLocally(data, void 0);
3592
3637
  const mutation = await this._queue.enqueue({
3593
3638
  collection,
3594
3639
  op: "add",
@@ -3600,7 +3645,7 @@ var DbCollectionRefImpl = class {
3600
3645
  await this._store.putDoc({
3601
3646
  collection,
3602
3647
  id: docId,
3603
- data,
3648
+ data: localData,
3604
3649
  meta: {
3605
3650
  serverVersion: null,
3606
3651
  updatedAtServer: null,
@@ -3611,11 +3656,12 @@ var DbCollectionRefImpl = class {
3611
3656
  ownerId: null
3612
3657
  }
3613
3658
  });
3614
- busChanges.push({ type: "added", collection, doc: { id: docId, data } });
3659
+ busChanges.push({ type: "added", collection, doc: { id: docId, data: localData } });
3615
3660
  } else if (op.kind === "set") {
3616
3661
  const id = op.id;
3617
3662
  const data = op.data;
3618
3663
  const existing = await this._store.getDoc(collection, id);
3664
+ const localData = resolveSentinelsLocally(data, void 0);
3619
3665
  const mutation = await this._queue.enqueue({
3620
3666
  collection,
3621
3667
  docId: id,
@@ -3627,7 +3673,7 @@ var DbCollectionRefImpl = class {
3627
3673
  await this._store.putDoc({
3628
3674
  collection,
3629
3675
  id,
3630
- data,
3676
+ data: localData,
3631
3677
  meta: {
3632
3678
  serverVersion: existing?.meta.serverVersion ?? null,
3633
3679
  updatedAtServer: existing?.meta.updatedAtServer ?? null,
@@ -3641,13 +3687,15 @@ var DbCollectionRefImpl = class {
3641
3687
  busChanges.push({
3642
3688
  type: existing && !existing.meta.deleted ? "modified" : "added",
3643
3689
  collection,
3644
- doc: { id, data }
3690
+ doc: { id, data: localData }
3645
3691
  });
3646
3692
  } else if (op.kind === "update") {
3647
3693
  const id = op.id;
3648
3694
  const data = op.data;
3649
3695
  const existing = await this._store.getDoc(collection, id);
3650
- const merged = { ...existing?.data ?? {}, ...data };
3696
+ const existingBase = existing?.meta.deleted ? void 0 : existing?.data;
3697
+ const localData = resolveSentinelsLocally(data, existingBase);
3698
+ const merged = { ...existing?.data ?? {}, ...localData };
3651
3699
  const mutation = await this._queue.enqueue({
3652
3700
  collection,
3653
3701
  docId: id,