@ensnode/ensnode-sdk 0.0.0-next-20260209132028 → 0.0.0-next-20260210021759

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.
package/dist/index.cjs CHANGED
@@ -216,6 +216,7 @@ __export(index_exports, {
216
216
  parseNonNegativeInteger: () => parseNonNegativeInteger,
217
217
  parsePartialInterpretedName: () => parsePartialInterpretedName,
218
218
  parseReverseName: () => parseReverseName,
219
+ parseTimestamp: () => parseTimestamp,
219
220
  parseUsdc: () => parseUsdc,
220
221
  priceDai: () => priceDai,
221
222
  priceEth: () => priceEth,
@@ -3835,15 +3836,26 @@ var LruCache = class {
3835
3836
 
3836
3837
  // src/shared/cache/swr-cache.ts
3837
3838
  var import_date_fns = require("date-fns");
3838
- var import_getUnixTime = require("date-fns/getUnixTime");
3839
+ var import_getUnixTime2 = require("date-fns/getUnixTime");
3839
3840
 
3840
3841
  // src/shared/datetime.ts
3842
+ var import_getUnixTime = require("date-fns/getUnixTime");
3841
3843
  function durationBetween(start, end) {
3842
3844
  return deserializeDuration(end - start, "Duration");
3843
3845
  }
3844
3846
  function addDuration(timestamp, duration) {
3845
3847
  return deserializeUnixTimestamp(timestamp + duration, "UnixTimestamp");
3846
3848
  }
3849
+ function parseTimestamp(isoDateString) {
3850
+ if (!/Z$|[+-]\d{2}:\d{2}$/.test(isoDateString)) {
3851
+ throw new Error(`Timezone required: provide Z or offset`);
3852
+ }
3853
+ const date = new Date(isoDateString);
3854
+ if (Number.isNaN(date.getTime())) {
3855
+ throw new Error(`Invalid date string: ${isoDateString}`);
3856
+ }
3857
+ return deserializeUnixTimestamp((0, import_getUnixTime.getUnixTime)(date), "UnixTimestamp");
3858
+ }
3847
3859
 
3848
3860
  // src/shared/cache/swr-cache.ts
3849
3861
  var SWRCache = class {
@@ -3865,14 +3877,14 @@ var SWRCache = class {
3865
3877
  this.inProgressRevalidate = this.options.fn().then((result) => {
3866
3878
  this.cache = {
3867
3879
  result,
3868
- updatedAt: (0, import_getUnixTime.getUnixTime)(/* @__PURE__ */ new Date())
3880
+ updatedAt: (0, import_getUnixTime2.getUnixTime)(/* @__PURE__ */ new Date())
3869
3881
  };
3870
3882
  }).catch((error) => {
3871
- if (!this.cache) {
3883
+ if (!this.cache || this.cache.result instanceof Error) {
3872
3884
  this.cache = {
3873
3885
  // ensure thrown value is always an Error instance
3874
3886
  result: error instanceof Error ? error : new Error(String(error)),
3875
- updatedAt: (0, import_getUnixTime.getUnixTime)(/* @__PURE__ */ new Date())
3887
+ updatedAt: (0, import_getUnixTime2.getUnixTime)(/* @__PURE__ */ new Date())
3876
3888
  };
3877
3889
  }
3878
3890
  }).finally(() => {
@@ -3890,7 +3902,8 @@ var SWRCache = class {
3890
3902
  async read() {
3891
3903
  if (!this.cache) await this.revalidate();
3892
3904
  if (!this.cache) throw new Error("never");
3893
- if (durationBetween(this.cache.updatedAt, (0, import_getUnixTime.getUnixTime)(/* @__PURE__ */ new Date())) > this.options.ttl) {
3905
+ const effectiveTtl = this.cache.result instanceof Error && this.options.errorTtl !== void 0 ? this.options.errorTtl : this.options.ttl;
3906
+ if (durationBetween(this.cache.updatedAt, (0, import_getUnixTime2.getUnixTime)(/* @__PURE__ */ new Date())) > effectiveTtl) {
3894
3907
  this.revalidate();
3895
3908
  }
3896
3909
  return this.cache.result;
@@ -3907,7 +3920,7 @@ var SWRCache = class {
3907
3920
  };
3908
3921
 
3909
3922
  // src/shared/cache/ttl-cache.ts
3910
- var import_getUnixTime2 = require("date-fns/getUnixTime");
3923
+ var import_getUnixTime3 = require("date-fns/getUnixTime");
3911
3924
  var TtlCache = class {
3912
3925
  _cache = /* @__PURE__ */ new Map();
3913
3926
  _ttl;
@@ -3920,7 +3933,7 @@ var TtlCache = class {
3920
3933
  this._ttl = ttl;
3921
3934
  }
3922
3935
  _cleanup() {
3923
- const now = (0, import_getUnixTime2.getUnixTime)(/* @__PURE__ */ new Date());
3936
+ const now = (0, import_getUnixTime3.getUnixTime)(/* @__PURE__ */ new Date());
3924
3937
  for (const [key, entry] of this._cache.entries()) {
3925
3938
  if (entry.expiresAt <= now) {
3926
3939
  this._cache.delete(key);
@@ -3929,7 +3942,7 @@ var TtlCache = class {
3929
3942
  }
3930
3943
  set(key, value) {
3931
3944
  this._cleanup();
3932
- const expiresAt = addDuration((0, import_getUnixTime2.getUnixTime)(/* @__PURE__ */ new Date()), this._ttl);
3945
+ const expiresAt = addDuration((0, import_getUnixTime3.getUnixTime)(/* @__PURE__ */ new Date()), this._ttl);
3933
3946
  this._cache.set(key, { value, expiresAt });
3934
3947
  }
3935
3948
  get(key) {
@@ -3938,7 +3951,7 @@ var TtlCache = class {
3938
3951
  if (!entry) {
3939
3952
  return void 0;
3940
3953
  }
3941
- if (entry.expiresAt <= (0, import_getUnixTime2.getUnixTime)(/* @__PURE__ */ new Date())) {
3954
+ if (entry.expiresAt <= (0, import_getUnixTime3.getUnixTime)(/* @__PURE__ */ new Date())) {
3942
3955
  this._cache.delete(key);
3943
3956
  return void 0;
3944
3957
  }
@@ -3960,7 +3973,7 @@ var TtlCache = class {
3960
3973
  if (!entry) {
3961
3974
  return false;
3962
3975
  }
3963
- if (entry.expiresAt <= (0, import_getUnixTime2.getUnixTime)(/* @__PURE__ */ new Date())) {
3976
+ if (entry.expiresAt <= (0, import_getUnixTime3.getUnixTime)(/* @__PURE__ */ new Date())) {
3964
3977
  this._cache.delete(key);
3965
3978
  return false;
3966
3979
  }