@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/db.d.cts CHANGED
@@ -1,4 +1,4 @@
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, N as NeetruDbDocuments, R as RealtimeTransport, S as SyncState } from './collection-ref-DqAAhuhX.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-Lfd3LiAF.cjs';
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';
3
3
  import 'drizzle-orm/node-postgres';
4
4
  import './errors.cjs';
package/dist/db.d.ts CHANGED
@@ -1,4 +1,4 @@
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, N as NeetruDbDocuments, R as RealtimeTransport, S as SyncState } from './collection-ref-DqAAhuhX.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-DALIhcbq.js';
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';
3
3
  import 'drizzle-orm/node-postgres';
4
4
  import './errors.js';
package/dist/db.mjs CHANGED
@@ -1538,7 +1538,7 @@ var SyncEngine = class {
1538
1538
  return true;
1539
1539
  }
1540
1540
  /** Atualiza o cache após confirmação de escrita (outcome=confirmed). */
1541
- async _applySyncedDoc(collection, docId, serverVersion, serverTimestamp, mut, busChanges) {
1541
+ async _applySyncedDoc(collection, docId, serverVersion, serverTimestamp2, mut, busChanges) {
1542
1542
  const existing = await this._store.getDoc(collection, docId);
1543
1543
  if (mut.op === "remove") {
1544
1544
  if (existing) {
@@ -1547,7 +1547,7 @@ var SyncEngine = class {
1547
1547
  meta: {
1548
1548
  ...existing.meta,
1549
1549
  serverVersion,
1550
- updatedAtServer: serverTimestamp,
1550
+ updatedAtServer: serverTimestamp2,
1551
1551
  updatedAtLocal: Date.now(),
1552
1552
  state: "synced",
1553
1553
  deleted: true,
@@ -1565,7 +1565,7 @@ var SyncEngine = class {
1565
1565
  data: mut.op === "update" ? { ...existing?.data ?? {}, ...newData } : newData,
1566
1566
  meta: {
1567
1567
  serverVersion,
1568
- updatedAtServer: serverTimestamp,
1568
+ updatedAtServer: serverTimestamp2,
1569
1569
  updatedAtLocal: Date.now(),
1570
1570
  state: "synced",
1571
1571
  pendingMutationIds: [],
@@ -2644,6 +2644,54 @@ var TabCoordinator = class {
2644
2644
 
2645
2645
  // src/db/collection-ref.ts
2646
2646
  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
2647
2695
  function isIndexedDBUnavailable() {
2648
2696
  return typeof indexedDB === "undefined" || typeof window === "undefined";
2649
2697
  }
@@ -2772,10 +2820,12 @@ var DbCollectionRefImpl = class {
2772
2820
  return this._buildListResult(q);
2773
2821
  }
2774
2822
  async add(data) {
2823
+ const rawData = data;
2824
+ const localData = resolveSentinelsLocally(rawData, void 0);
2775
2825
  const mutation = await this._queue.enqueue({
2776
2826
  collection: this._collection,
2777
2827
  op: "add",
2778
- payload: data,
2828
+ payload: rawData,
2779
2829
  baseVersion: null,
2780
2830
  batchId: null
2781
2831
  });
@@ -2783,7 +2833,7 @@ var DbCollectionRefImpl = class {
2783
2833
  await this._store.putDoc({
2784
2834
  collection: this._collection,
2785
2835
  id: docId,
2786
- data,
2836
+ data: localData,
2787
2837
  meta: {
2788
2838
  serverVersion: null,
2789
2839
  updatedAtServer: null,
@@ -2797,25 +2847,27 @@ var DbCollectionRefImpl = class {
2797
2847
  this._bus.emit([{
2798
2848
  type: "added",
2799
2849
  collection: this._collection,
2800
- doc: { id: docId, data }
2850
+ doc: { id: docId, data: localData }
2801
2851
  }]);
2802
2852
  return { ok: true, id: docId };
2803
2853
  }
2804
2854
  async set(id, data) {
2805
2855
  assertValidId(id);
2806
2856
  const existing = await this._store.getDoc(this._collection, id);
2857
+ const rawData = data;
2858
+ const localData = resolveSentinelsLocally(rawData, void 0);
2807
2859
  const mutation = await this._queue.enqueue({
2808
2860
  collection: this._collection,
2809
2861
  docId: id,
2810
2862
  op: "set",
2811
- payload: data,
2863
+ payload: rawData,
2812
2864
  baseVersion: existing?.meta.serverVersion ?? null,
2813
2865
  batchId: null
2814
2866
  });
2815
2867
  await this._store.putDoc({
2816
2868
  collection: this._collection,
2817
2869
  id,
2818
- data,
2870
+ data: localData,
2819
2871
  meta: {
2820
2872
  serverVersion: existing?.meta.serverVersion ?? null,
2821
2873
  updatedAtServer: existing?.meta.updatedAtServer ?? null,
@@ -2829,19 +2881,22 @@ var DbCollectionRefImpl = class {
2829
2881
  this._bus.emit([{
2830
2882
  type: existing && !existing.meta.deleted ? "modified" : "added",
2831
2883
  collection: this._collection,
2832
- doc: { id, data }
2884
+ doc: { id, data: localData }
2833
2885
  }]);
2834
2886
  return { ok: true };
2835
2887
  }
2836
2888
  async update(id, data) {
2837
2889
  assertValidId(id);
2838
2890
  const existing = await this._store.getDoc(this._collection, id);
2839
- const mergedData = existing?.meta.deleted ? { ...data } : { ...existing?.data ?? {}, ...data };
2891
+ const rawData = data;
2892
+ const existingBase = existing?.meta.deleted ? void 0 : existing?.data;
2893
+ const localData = resolveSentinelsLocally(rawData, existingBase);
2894
+ const mergedData = existing?.meta.deleted ? { ...localData } : { ...existing?.data ?? {}, ...localData };
2840
2895
  const mutation = await this._queue.enqueue({
2841
2896
  collection: this._collection,
2842
2897
  docId: id,
2843
2898
  op: "update",
2844
- payload: data,
2899
+ payload: rawData,
2845
2900
  baseVersion: existing?.meta.serverVersion ?? null,
2846
2901
  batchId: null
2847
2902
  });
@@ -2898,6 +2953,7 @@ var DbCollectionRefImpl = class {
2898
2953
  const collection = this._collection;
2899
2954
  if (op.kind === "add") {
2900
2955
  const data = op.data;
2956
+ const localData = resolveSentinelsLocally(data, void 0);
2901
2957
  const mutation = await this._queue.enqueue({
2902
2958
  collection,
2903
2959
  op: "add",
@@ -2909,7 +2965,7 @@ var DbCollectionRefImpl = class {
2909
2965
  await this._store.putDoc({
2910
2966
  collection,
2911
2967
  id: docId,
2912
- data,
2968
+ data: localData,
2913
2969
  meta: {
2914
2970
  serverVersion: null,
2915
2971
  updatedAtServer: null,
@@ -2920,11 +2976,12 @@ var DbCollectionRefImpl = class {
2920
2976
  ownerId: null
2921
2977
  }
2922
2978
  });
2923
- busChanges.push({ type: "added", collection, doc: { id: docId, data } });
2979
+ busChanges.push({ type: "added", collection, doc: { id: docId, data: localData } });
2924
2980
  } else if (op.kind === "set") {
2925
2981
  const id = op.id;
2926
2982
  const data = op.data;
2927
2983
  const existing = await this._store.getDoc(collection, id);
2984
+ const localData = resolveSentinelsLocally(data, void 0);
2928
2985
  const mutation = await this._queue.enqueue({
2929
2986
  collection,
2930
2987
  docId: id,
@@ -2936,7 +2993,7 @@ var DbCollectionRefImpl = class {
2936
2993
  await this._store.putDoc({
2937
2994
  collection,
2938
2995
  id,
2939
- data,
2996
+ data: localData,
2940
2997
  meta: {
2941
2998
  serverVersion: existing?.meta.serverVersion ?? null,
2942
2999
  updatedAtServer: existing?.meta.updatedAtServer ?? null,
@@ -2950,13 +3007,15 @@ var DbCollectionRefImpl = class {
2950
3007
  busChanges.push({
2951
3008
  type: existing && !existing.meta.deleted ? "modified" : "added",
2952
3009
  collection,
2953
- doc: { id, data }
3010
+ doc: { id, data: localData }
2954
3011
  });
2955
3012
  } else if (op.kind === "update") {
2956
3013
  const id = op.id;
2957
3014
  const data = op.data;
2958
3015
  const existing = await this._store.getDoc(collection, id);
2959
- const merged = { ...existing?.data ?? {}, ...data };
3016
+ const existingBase = existing?.meta.deleted ? void 0 : existing?.data;
3017
+ const localData = resolveSentinelsLocally(data, existingBase);
3018
+ const merged = { ...existing?.data ?? {}, ...localData };
2960
3019
  const mutation = await this._queue.enqueue({
2961
3020
  collection,
2962
3021
  docId: id,
@@ -3988,6 +4047,6 @@ function createLazyCollectionRef(name, getDocsPromise) {
3988
4047
  };
3989
4048
  }
3990
4049
 
3991
- export { NeetruDbError, createNeetruDb, createRestSyncTransport, getWebSocketRealtimeClient };
4050
+ export { NEETRU_SENTINEL_KEY, NeetruDbError, createNeetruDb, createRestSyncTransport, getWebSocketRealtimeClient, increment, isFieldSentinel, isIncrementSentinel, isServerTimestampSentinel, serverTimestamp };
3992
4051
  //# sourceMappingURL=db.mjs.map
3993
4052
  //# sourceMappingURL=db.mjs.map