@ensnode/ensnode-sdk 1.3.0 → 1.3.1
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 +51 -167
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +49 -115
- package/dist/index.d.ts +49 -115
- package/dist/index.js +51 -167
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -576,183 +576,67 @@ function addDuration(timestamp, duration) {
|
|
|
576
576
|
return deserializeUnixTimestamp(timestamp + duration, "UnixTimestamp");
|
|
577
577
|
}
|
|
578
578
|
|
|
579
|
-
// src/shared/cache/
|
|
580
|
-
var
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
schedule(config) {
|
|
589
|
-
const { revalidate, interval, initialDelay = 0, onError } = config;
|
|
590
|
-
if (this.activeSchedules.has(revalidate)) {
|
|
591
|
-
return revalidate;
|
|
579
|
+
// src/shared/cache/swr-cache.ts
|
|
580
|
+
var SWRCache = class {
|
|
581
|
+
constructor(options) {
|
|
582
|
+
this.options = options;
|
|
583
|
+
if (options.proactiveRevalidationInterval) {
|
|
584
|
+
this.backgroundInterval = setInterval(
|
|
585
|
+
() => this.revalidate(),
|
|
586
|
+
secondsToMilliseconds(options.proactiveRevalidationInterval)
|
|
587
|
+
);
|
|
592
588
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
metadata.timeoutId = setTimeout(() => {
|
|
613
|
-
if (this.activeSchedules.has(revalidate)) {
|
|
614
|
-
executeRevalidation().then(() => scheduleNext());
|
|
615
|
-
}
|
|
616
|
-
}, interval);
|
|
617
|
-
};
|
|
618
|
-
if (initialDelay > 0) {
|
|
619
|
-
metadata.timeoutId = setTimeout(() => {
|
|
620
|
-
if (this.activeSchedules.has(revalidate)) {
|
|
621
|
-
executeRevalidation().then(() => scheduleNext());
|
|
589
|
+
if (options.proactivelyInitialize) this.revalidate();
|
|
590
|
+
}
|
|
591
|
+
cache = null;
|
|
592
|
+
inProgressRevalidate = null;
|
|
593
|
+
backgroundInterval = null;
|
|
594
|
+
async revalidate() {
|
|
595
|
+
if (!this.inProgressRevalidate) {
|
|
596
|
+
this.inProgressRevalidate = this.options.fn().then((result) => {
|
|
597
|
+
this.cache = {
|
|
598
|
+
result,
|
|
599
|
+
updatedAt: getUnixTime(/* @__PURE__ */ new Date())
|
|
600
|
+
};
|
|
601
|
+
}).catch((error) => {
|
|
602
|
+
if (!this.cache) {
|
|
603
|
+
this.cache = {
|
|
604
|
+
// ensure thrown value is always an Error instance
|
|
605
|
+
result: error instanceof Error ? error : new Error(String(error)),
|
|
606
|
+
updatedAt: getUnixTime(/* @__PURE__ */ new Date())
|
|
607
|
+
};
|
|
622
608
|
}
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
|
|
609
|
+
}).finally(() => {
|
|
610
|
+
this.inProgressRevalidate = null;
|
|
611
|
+
});
|
|
626
612
|
}
|
|
627
|
-
return
|
|
613
|
+
return this.inProgressRevalidate;
|
|
628
614
|
}
|
|
629
615
|
/**
|
|
630
|
-
*
|
|
616
|
+
* Read the most recently cached result from the `SWRCache`.
|
|
631
617
|
*
|
|
632
|
-
* @
|
|
618
|
+
* @returns a `ValueType` that was most recently successfully returned by `fn` or `Error` if `fn`
|
|
619
|
+
* has never successfully returned.
|
|
633
620
|
*/
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
if (!
|
|
637
|
-
if (
|
|
638
|
-
|
|
621
|
+
async read() {
|
|
622
|
+
if (!this.cache) await this.revalidate();
|
|
623
|
+
if (!this.cache) throw new Error("never");
|
|
624
|
+
if (durationBetween(this.cache.updatedAt, getUnixTime(/* @__PURE__ */ new Date())) > this.options.ttl) {
|
|
625
|
+
this.revalidate();
|
|
639
626
|
}
|
|
640
|
-
this.
|
|
627
|
+
return this.cache.result;
|
|
641
628
|
}
|
|
642
629
|
/**
|
|
643
|
-
*
|
|
630
|
+
* Destroys the background revalidation interval, if exists.
|
|
644
631
|
*/
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
}
|
|
632
|
+
destroy() {
|
|
633
|
+
if (this.backgroundInterval) {
|
|
634
|
+
clearInterval(this.backgroundInterval);
|
|
635
|
+
this.backgroundInterval = null;
|
|
650
636
|
}
|
|
651
|
-
this.activeSchedules.clear();
|
|
652
|
-
}
|
|
653
|
-
/**
|
|
654
|
-
* Get the count of active schedules.
|
|
655
|
-
* Useful for debugging and monitoring.
|
|
656
|
-
*
|
|
657
|
-
* @returns The number of currently active schedules
|
|
658
|
-
*/
|
|
659
|
-
getActiveScheduleCount() {
|
|
660
|
-
return this.activeSchedules.size;
|
|
661
637
|
}
|
|
662
638
|
};
|
|
663
639
|
|
|
664
|
-
// src/shared/cache/swr-cache.ts
|
|
665
|
-
var bgRevalidationScheduler = new BackgroundRevalidationScheduler();
|
|
666
|
-
var SWRCache = class _SWRCache {
|
|
667
|
-
options;
|
|
668
|
-
cache;
|
|
669
|
-
/**
|
|
670
|
-
* Optional promise of the current in-progress attempt to revalidate the `cache`.
|
|
671
|
-
*
|
|
672
|
-
* If null, no revalidation attempt is currently in progress.
|
|
673
|
-
* If not null, identifies the revalidation attempt that is currently in progress.
|
|
674
|
-
*
|
|
675
|
-
* Used to enforce no concurrent revalidation attempts.
|
|
676
|
-
*/
|
|
677
|
-
inProgressRevalidate;
|
|
678
|
-
/**
|
|
679
|
-
* The callback function being managed by `BackgroundRevalidationScheduler`.
|
|
680
|
-
*
|
|
681
|
-
* If null, no background revalidation is scheduled.
|
|
682
|
-
* If not null, identifies the background revalidation that is currently scheduled.
|
|
683
|
-
*
|
|
684
|
-
* Used to enforce no concurrent background revalidation attempts.
|
|
685
|
-
*/
|
|
686
|
-
scheduledBackgroundRevalidate;
|
|
687
|
-
constructor(options) {
|
|
688
|
-
this.cache = null;
|
|
689
|
-
this.inProgressRevalidate = null;
|
|
690
|
-
this.scheduledBackgroundRevalidate = null;
|
|
691
|
-
this.options = options;
|
|
692
|
-
}
|
|
693
|
-
/**
|
|
694
|
-
* Asynchronously create a new `SWRCache` instance.
|
|
695
|
-
*
|
|
696
|
-
* @param options - The {@link SWRCacheOptions} for the SWR cache.
|
|
697
|
-
* @returns a new `SWRCache` instance.
|
|
698
|
-
*/
|
|
699
|
-
static async create(options) {
|
|
700
|
-
const cache = new _SWRCache(options);
|
|
701
|
-
if (cache.options.proactivelyInitialize) {
|
|
702
|
-
cache.readCache();
|
|
703
|
-
}
|
|
704
|
-
return cache;
|
|
705
|
-
}
|
|
706
|
-
revalidate = async () => {
|
|
707
|
-
if (this.inProgressRevalidate) {
|
|
708
|
-
return this.inProgressRevalidate;
|
|
709
|
-
}
|
|
710
|
-
return this.options.fn().then((value) => {
|
|
711
|
-
this.cache = {
|
|
712
|
-
value,
|
|
713
|
-
updatedAt: getUnixTime(/* @__PURE__ */ new Date())
|
|
714
|
-
};
|
|
715
|
-
return this.cache;
|
|
716
|
-
}).catch(() => {
|
|
717
|
-
return null;
|
|
718
|
-
}).finally(() => {
|
|
719
|
-
this.inProgressRevalidate = null;
|
|
720
|
-
if (this.options.revalidationInterval === void 0) {
|
|
721
|
-
return;
|
|
722
|
-
}
|
|
723
|
-
if (this.scheduledBackgroundRevalidate) {
|
|
724
|
-
bgRevalidationScheduler.cancel(this.scheduledBackgroundRevalidate);
|
|
725
|
-
}
|
|
726
|
-
const backgroundRevalidate = async () => {
|
|
727
|
-
this.revalidate();
|
|
728
|
-
};
|
|
729
|
-
this.scheduledBackgroundRevalidate = bgRevalidationScheduler.schedule({
|
|
730
|
-
revalidate: backgroundRevalidate,
|
|
731
|
-
interval: secondsToMilliseconds(this.options.revalidationInterval)
|
|
732
|
-
});
|
|
733
|
-
});
|
|
734
|
-
};
|
|
735
|
-
/**
|
|
736
|
-
* Read the most recently cached `CachedValue` from the `SWRCache`.
|
|
737
|
-
*
|
|
738
|
-
* @returns a `CachedValue` holding a `value` of `ValueType` that was most recently successfully returned by `fn`
|
|
739
|
-
* or `null` if `fn` has never successfully returned and has always thrown an error,
|
|
740
|
-
*/
|
|
741
|
-
readCache = async () => {
|
|
742
|
-
if (!this.cache) {
|
|
743
|
-
this.inProgressRevalidate = this.revalidate();
|
|
744
|
-
return this.inProgressRevalidate;
|
|
745
|
-
}
|
|
746
|
-
if (durationBetween(this.cache.updatedAt, getUnixTime(/* @__PURE__ */ new Date())) <= this.options.ttl) {
|
|
747
|
-
return this.cache;
|
|
748
|
-
}
|
|
749
|
-
if (!this.inProgressRevalidate) {
|
|
750
|
-
this.inProgressRevalidate = this.revalidate();
|
|
751
|
-
}
|
|
752
|
-
return this.cache;
|
|
753
|
-
};
|
|
754
|
-
};
|
|
755
|
-
|
|
756
640
|
// src/shared/cache/ttl-cache.ts
|
|
757
641
|
import { getUnixTime as getUnixTime2 } from "date-fns/getUnixTime";
|
|
758
642
|
var TtlCache = class {
|
|
@@ -3974,7 +3858,11 @@ var translateDefaultableChainIdToChainId = (chainId, namespaceId) => {
|
|
|
3974
3858
|
// src/resolution/resolver-records-selection.ts
|
|
3975
3859
|
var isSelectionEmpty = (selection) => !selection.name && !selection.addresses?.length && !selection.texts?.length;
|
|
3976
3860
|
|
|
3977
|
-
// src/tracing/
|
|
3861
|
+
// src/tracing/ens-protocol-tracing.ts
|
|
3862
|
+
var PROTOCOL_ATTRIBUTE_PREFIX = "ens";
|
|
3863
|
+
var ATTR_PROTOCOL_NAME = `${PROTOCOL_ATTRIBUTE_PREFIX}.protocol`;
|
|
3864
|
+
var ATTR_PROTOCOL_STEP = `${PROTOCOL_ATTRIBUTE_PREFIX}.protocol.step`;
|
|
3865
|
+
var ATTR_PROTOCOL_STEP_RESULT = `${PROTOCOL_ATTRIBUTE_PREFIX}.protocol.step.result`;
|
|
3978
3866
|
var TraceableENSProtocol = /* @__PURE__ */ ((TraceableENSProtocol2) => {
|
|
3979
3867
|
TraceableENSProtocol2["ForwardResolution"] = "forward-resolution";
|
|
3980
3868
|
TraceableENSProtocol2["ReverseResolution"] = "reverse-resolution";
|
|
@@ -3999,10 +3887,6 @@ var ReverseResolutionProtocolStep = /* @__PURE__ */ ((ReverseResolutionProtocolS
|
|
|
3999
3887
|
ReverseResolutionProtocolStep2["VerifyResolvedAddressMatchesAddress"] = "verify-resolved-address-matches-address";
|
|
4000
3888
|
return ReverseResolutionProtocolStep2;
|
|
4001
3889
|
})(ReverseResolutionProtocolStep || {});
|
|
4002
|
-
var PROTOCOL_ATTRIBUTE_PREFIX = "ens";
|
|
4003
|
-
var ATTR_PROTOCOL_NAME = `${PROTOCOL_ATTRIBUTE_PREFIX}.protocol`;
|
|
4004
|
-
var ATTR_PROTOCOL_STEP = `${PROTOCOL_ATTRIBUTE_PREFIX}.protocol.step`;
|
|
4005
|
-
var ATTR_PROTOCOL_STEP_RESULT = `${PROTOCOL_ATTRIBUTE_PREFIX}.protocol.step.result`;
|
|
4006
3890
|
export {
|
|
4007
3891
|
ADDR_REVERSE_NODE,
|
|
4008
3892
|
ATTR_PROTOCOL_NAME,
|