@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
@@ -1,5 +1,5 @@
1
- import { I as ResolvedConfig, E as EntitlementCheck } from './types-Lfd3LiAF.cjs';
2
- import './collection-ref-DqAAhuhX.cjs';
1
+ import { I as ResolvedConfig, E as EntitlementCheck } from './types-Dc4bjrrt.cjs';
2
+ import './collection-ref-BDdfD87k.cjs';
3
3
  import 'drizzle-orm/node-postgres';
4
4
  import './errors.cjs';
5
5
 
@@ -1,5 +1,5 @@
1
- import { I as ResolvedConfig, E as EntitlementCheck } from './types-DALIhcbq.js';
2
- import './collection-ref-DqAAhuhX.js';
1
+ import { I as ResolvedConfig, E as EntitlementCheck } 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/index.cjs CHANGED
@@ -2231,7 +2231,7 @@ var SyncEngine = class {
2231
2231
  return true;
2232
2232
  }
2233
2233
  /** Atualiza o cache após confirmação de escrita (outcome=confirmed). */
2234
- async _applySyncedDoc(collection, docId, serverVersion, serverTimestamp, mut, busChanges) {
2234
+ async _applySyncedDoc(collection, docId, serverVersion, serverTimestamp2, mut, busChanges) {
2235
2235
  const existing = await this._store.getDoc(collection, docId);
2236
2236
  if (mut.op === "remove") {
2237
2237
  if (existing) {
@@ -2240,7 +2240,7 @@ var SyncEngine = class {
2240
2240
  meta: {
2241
2241
  ...existing.meta,
2242
2242
  serverVersion,
2243
- updatedAtServer: serverTimestamp,
2243
+ updatedAtServer: serverTimestamp2,
2244
2244
  updatedAtLocal: Date.now(),
2245
2245
  state: "synced",
2246
2246
  deleted: true,
@@ -2258,7 +2258,7 @@ var SyncEngine = class {
2258
2258
  data: mut.op === "update" ? { ...existing?.data ?? {}, ...newData } : newData,
2259
2259
  meta: {
2260
2260
  serverVersion,
2261
- updatedAtServer: serverTimestamp,
2261
+ updatedAtServer: serverTimestamp2,
2262
2262
  updatedAtLocal: Date.now(),
2263
2263
  state: "synced",
2264
2264
  pendingMutationIds: [],
@@ -3337,6 +3337,54 @@ var TabCoordinator = class {
3337
3337
 
3338
3338
  // src/db/collection-ref.ts
3339
3339
  init_db_errors();
3340
+
3341
+ // src/db/field-value.ts
3342
+ var NEETRU_SENTINEL_KEY = "__neetru__";
3343
+ function serverTimestamp() {
3344
+ return { __neetru__: "serverTimestamp" };
3345
+ }
3346
+ function increment(n) {
3347
+ if (typeof n !== "number" || !Number.isFinite(n)) {
3348
+ throw new TypeError(
3349
+ `increment(n): n deve ser um n\xFAmero finito (recebido: ${String(n)}).`
3350
+ );
3351
+ }
3352
+ return { __neetru__: "increment", operand: n };
3353
+ }
3354
+ function isFieldSentinel(v) {
3355
+ return typeof v === "object" && v !== null && NEETRU_SENTINEL_KEY in v && typeof v[NEETRU_SENTINEL_KEY] === "string";
3356
+ }
3357
+ function isServerTimestampSentinel(v) {
3358
+ return isFieldSentinel(v) && v.__neetru__ === "serverTimestamp";
3359
+ }
3360
+ function isIncrementSentinel(v) {
3361
+ return isFieldSentinel(v) && v.__neetru__ === "increment" && typeof v.operand === "number" && Number.isFinite(v.operand);
3362
+ }
3363
+ function resolveSentinelLocally(value, baseValue) {
3364
+ if (isServerTimestampSentinel(value)) {
3365
+ return Date.now();
3366
+ }
3367
+ if (isIncrementSentinel(value)) {
3368
+ const base = typeof baseValue === "number" && Number.isFinite(baseValue) ? baseValue : 0;
3369
+ return base + value.operand;
3370
+ }
3371
+ return value;
3372
+ }
3373
+ function resolveSentinelsLocally(data, existing) {
3374
+ let touched = false;
3375
+ const out = {};
3376
+ for (const [k, v] of Object.entries(data)) {
3377
+ if (isFieldSentinel(v)) {
3378
+ touched = true;
3379
+ out[k] = resolveSentinelLocally(v, existing?.[k]);
3380
+ } else {
3381
+ out[k] = v;
3382
+ }
3383
+ }
3384
+ return touched ? out : data;
3385
+ }
3386
+
3387
+ // src/db/collection-ref.ts
3340
3388
  function isIndexedDBUnavailable() {
3341
3389
  return typeof indexedDB === "undefined" || typeof window === "undefined";
3342
3390
  }
@@ -3465,10 +3513,12 @@ var DbCollectionRefImpl = class {
3465
3513
  return this._buildListResult(q);
3466
3514
  }
3467
3515
  async add(data) {
3516
+ const rawData = data;
3517
+ const localData = resolveSentinelsLocally(rawData, void 0);
3468
3518
  const mutation = await this._queue.enqueue({
3469
3519
  collection: this._collection,
3470
3520
  op: "add",
3471
- payload: data,
3521
+ payload: rawData,
3472
3522
  baseVersion: null,
3473
3523
  batchId: null
3474
3524
  });
@@ -3476,7 +3526,7 @@ var DbCollectionRefImpl = class {
3476
3526
  await this._store.putDoc({
3477
3527
  collection: this._collection,
3478
3528
  id: docId,
3479
- data,
3529
+ data: localData,
3480
3530
  meta: {
3481
3531
  serverVersion: null,
3482
3532
  updatedAtServer: null,
@@ -3490,25 +3540,27 @@ var DbCollectionRefImpl = class {
3490
3540
  this._bus.emit([{
3491
3541
  type: "added",
3492
3542
  collection: this._collection,
3493
- doc: { id: docId, data }
3543
+ doc: { id: docId, data: localData }
3494
3544
  }]);
3495
3545
  return { ok: true, id: docId };
3496
3546
  }
3497
3547
  async set(id, data) {
3498
3548
  assertValidId(id);
3499
3549
  const existing = await this._store.getDoc(this._collection, id);
3550
+ const rawData = data;
3551
+ const localData = resolveSentinelsLocally(rawData, void 0);
3500
3552
  const mutation = await this._queue.enqueue({
3501
3553
  collection: this._collection,
3502
3554
  docId: id,
3503
3555
  op: "set",
3504
- payload: data,
3556
+ payload: rawData,
3505
3557
  baseVersion: existing?.meta.serverVersion ?? null,
3506
3558
  batchId: null
3507
3559
  });
3508
3560
  await this._store.putDoc({
3509
3561
  collection: this._collection,
3510
3562
  id,
3511
- data,
3563
+ data: localData,
3512
3564
  meta: {
3513
3565
  serverVersion: existing?.meta.serverVersion ?? null,
3514
3566
  updatedAtServer: existing?.meta.updatedAtServer ?? null,
@@ -3522,19 +3574,22 @@ var DbCollectionRefImpl = class {
3522
3574
  this._bus.emit([{
3523
3575
  type: existing && !existing.meta.deleted ? "modified" : "added",
3524
3576
  collection: this._collection,
3525
- doc: { id, data }
3577
+ doc: { id, data: localData }
3526
3578
  }]);
3527
3579
  return { ok: true };
3528
3580
  }
3529
3581
  async update(id, data) {
3530
3582
  assertValidId(id);
3531
3583
  const existing = await this._store.getDoc(this._collection, id);
3532
- const mergedData = existing?.meta.deleted ? { ...data } : { ...existing?.data ?? {}, ...data };
3584
+ const rawData = data;
3585
+ const existingBase = existing?.meta.deleted ? void 0 : existing?.data;
3586
+ const localData = resolveSentinelsLocally(rawData, existingBase);
3587
+ const mergedData = existing?.meta.deleted ? { ...localData } : { ...existing?.data ?? {}, ...localData };
3533
3588
  const mutation = await this._queue.enqueue({
3534
3589
  collection: this._collection,
3535
3590
  docId: id,
3536
3591
  op: "update",
3537
- payload: data,
3592
+ payload: rawData,
3538
3593
  baseVersion: existing?.meta.serverVersion ?? null,
3539
3594
  batchId: null
3540
3595
  });
@@ -3591,6 +3646,7 @@ var DbCollectionRefImpl = class {
3591
3646
  const collection = this._collection;
3592
3647
  if (op.kind === "add") {
3593
3648
  const data = op.data;
3649
+ const localData = resolveSentinelsLocally(data, void 0);
3594
3650
  const mutation = await this._queue.enqueue({
3595
3651
  collection,
3596
3652
  op: "add",
@@ -3602,7 +3658,7 @@ var DbCollectionRefImpl = class {
3602
3658
  await this._store.putDoc({
3603
3659
  collection,
3604
3660
  id: docId,
3605
- data,
3661
+ data: localData,
3606
3662
  meta: {
3607
3663
  serverVersion: null,
3608
3664
  updatedAtServer: null,
@@ -3613,11 +3669,12 @@ var DbCollectionRefImpl = class {
3613
3669
  ownerId: null
3614
3670
  }
3615
3671
  });
3616
- busChanges.push({ type: "added", collection, doc: { id: docId, data } });
3672
+ busChanges.push({ type: "added", collection, doc: { id: docId, data: localData } });
3617
3673
  } else if (op.kind === "set") {
3618
3674
  const id = op.id;
3619
3675
  const data = op.data;
3620
3676
  const existing = await this._store.getDoc(collection, id);
3677
+ const localData = resolveSentinelsLocally(data, void 0);
3621
3678
  const mutation = await this._queue.enqueue({
3622
3679
  collection,
3623
3680
  docId: id,
@@ -3629,7 +3686,7 @@ var DbCollectionRefImpl = class {
3629
3686
  await this._store.putDoc({
3630
3687
  collection,
3631
3688
  id,
3632
- data,
3689
+ data: localData,
3633
3690
  meta: {
3634
3691
  serverVersion: existing?.meta.serverVersion ?? null,
3635
3692
  updatedAtServer: existing?.meta.updatedAtServer ?? null,
@@ -3643,13 +3700,15 @@ var DbCollectionRefImpl = class {
3643
3700
  busChanges.push({
3644
3701
  type: existing && !existing.meta.deleted ? "modified" : "added",
3645
3702
  collection,
3646
- doc: { id, data }
3703
+ doc: { id, data: localData }
3647
3704
  });
3648
3705
  } else if (op.kind === "update") {
3649
3706
  const id = op.id;
3650
3707
  const data = op.data;
3651
3708
  const existing = await this._store.getDoc(collection, id);
3652
- const merged = { ...existing?.data ?? {}, ...data };
3709
+ const existingBase = existing?.meta.deleted ? void 0 : existing?.data;
3710
+ const localData = resolveSentinelsLocally(data, existingBase);
3711
+ const merged = { ...existing?.data ?? {}, ...localData };
3653
3712
  const mutation = await this._queue.enqueue({
3654
3713
  collection,
3655
3714
  docId: id,
@@ -6095,12 +6154,18 @@ exports.MockNotifications = MockNotifications;
6095
6154
  exports.MockSupport = MockSupport;
6096
6155
  exports.MockUsage = MockUsage;
6097
6156
  exports.MockWebhooks = MockWebhooks;
6157
+ exports.NEETRU_SENTINEL_KEY = NEETRU_SENTINEL_KEY;
6098
6158
  exports.VERSION = VERSION;
6099
6159
  exports.createCheckoutNamespace = createCheckoutNamespace;
6100
6160
  exports.createNeetruClient = createNeetruClient;
6101
6161
  exports.createNeetruDb = createNeetruDb;
6102
6162
  exports.createNotificationsNamespace = createNotificationsNamespace;
6103
6163
  exports.createWebhooksNamespace = createWebhooksNamespace;
6164
+ exports.increment = increment;
6165
+ exports.isFieldSentinel = isFieldSentinel;
6166
+ exports.isIncrementSentinel = isIncrementSentinel;
6167
+ exports.isServerTimestampSentinel = isServerTimestampSentinel;
6168
+ exports.serverTimestamp = serverTimestamp;
6104
6169
  exports.verifyWebhookSignature = verifyWebhookSignature;
6105
6170
  //# sourceMappingURL=index.cjs.map
6106
6171
  //# sourceMappingURL=index.cjs.map