@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.cjs
CHANGED
|
@@ -793,183 +793,67 @@ function addDuration(timestamp, duration) {
|
|
|
793
793
|
return deserializeUnixTimestamp(timestamp + duration, "UnixTimestamp");
|
|
794
794
|
}
|
|
795
795
|
|
|
796
|
-
// src/shared/cache/
|
|
797
|
-
var
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
schedule(config) {
|
|
806
|
-
const { revalidate, interval, initialDelay = 0, onError } = config;
|
|
807
|
-
if (this.activeSchedules.has(revalidate)) {
|
|
808
|
-
return revalidate;
|
|
796
|
+
// src/shared/cache/swr-cache.ts
|
|
797
|
+
var SWRCache = class {
|
|
798
|
+
constructor(options) {
|
|
799
|
+
this.options = options;
|
|
800
|
+
if (options.proactiveRevalidationInterval) {
|
|
801
|
+
this.backgroundInterval = setInterval(
|
|
802
|
+
() => this.revalidate(),
|
|
803
|
+
(0, import_date_fns.secondsToMilliseconds)(options.proactiveRevalidationInterval)
|
|
804
|
+
);
|
|
809
805
|
}
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
metadata.timeoutId = setTimeout(() => {
|
|
830
|
-
if (this.activeSchedules.has(revalidate)) {
|
|
831
|
-
executeRevalidation().then(() => scheduleNext());
|
|
832
|
-
}
|
|
833
|
-
}, interval);
|
|
834
|
-
};
|
|
835
|
-
if (initialDelay > 0) {
|
|
836
|
-
metadata.timeoutId = setTimeout(() => {
|
|
837
|
-
if (this.activeSchedules.has(revalidate)) {
|
|
838
|
-
executeRevalidation().then(() => scheduleNext());
|
|
806
|
+
if (options.proactivelyInitialize) this.revalidate();
|
|
807
|
+
}
|
|
808
|
+
cache = null;
|
|
809
|
+
inProgressRevalidate = null;
|
|
810
|
+
backgroundInterval = null;
|
|
811
|
+
async revalidate() {
|
|
812
|
+
if (!this.inProgressRevalidate) {
|
|
813
|
+
this.inProgressRevalidate = this.options.fn().then((result) => {
|
|
814
|
+
this.cache = {
|
|
815
|
+
result,
|
|
816
|
+
updatedAt: (0, import_getUnixTime.getUnixTime)(/* @__PURE__ */ new Date())
|
|
817
|
+
};
|
|
818
|
+
}).catch((error) => {
|
|
819
|
+
if (!this.cache) {
|
|
820
|
+
this.cache = {
|
|
821
|
+
// ensure thrown value is always an Error instance
|
|
822
|
+
result: error instanceof Error ? error : new Error(String(error)),
|
|
823
|
+
updatedAt: (0, import_getUnixTime.getUnixTime)(/* @__PURE__ */ new Date())
|
|
824
|
+
};
|
|
839
825
|
}
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
|
|
826
|
+
}).finally(() => {
|
|
827
|
+
this.inProgressRevalidate = null;
|
|
828
|
+
});
|
|
843
829
|
}
|
|
844
|
-
return
|
|
830
|
+
return this.inProgressRevalidate;
|
|
845
831
|
}
|
|
846
832
|
/**
|
|
847
|
-
*
|
|
833
|
+
* Read the most recently cached result from the `SWRCache`.
|
|
848
834
|
*
|
|
849
|
-
* @
|
|
835
|
+
* @returns a `ValueType` that was most recently successfully returned by `fn` or `Error` if `fn`
|
|
836
|
+
* has never successfully returned.
|
|
850
837
|
*/
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
if (!
|
|
854
|
-
if (
|
|
855
|
-
|
|
838
|
+
async read() {
|
|
839
|
+
if (!this.cache) await this.revalidate();
|
|
840
|
+
if (!this.cache) throw new Error("never");
|
|
841
|
+
if (durationBetween(this.cache.updatedAt, (0, import_getUnixTime.getUnixTime)(/* @__PURE__ */ new Date())) > this.options.ttl) {
|
|
842
|
+
this.revalidate();
|
|
856
843
|
}
|
|
857
|
-
this.
|
|
844
|
+
return this.cache.result;
|
|
858
845
|
}
|
|
859
846
|
/**
|
|
860
|
-
*
|
|
847
|
+
* Destroys the background revalidation interval, if exists.
|
|
861
848
|
*/
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
}
|
|
849
|
+
destroy() {
|
|
850
|
+
if (this.backgroundInterval) {
|
|
851
|
+
clearInterval(this.backgroundInterval);
|
|
852
|
+
this.backgroundInterval = null;
|
|
867
853
|
}
|
|
868
|
-
this.activeSchedules.clear();
|
|
869
|
-
}
|
|
870
|
-
/**
|
|
871
|
-
* Get the count of active schedules.
|
|
872
|
-
* Useful for debugging and monitoring.
|
|
873
|
-
*
|
|
874
|
-
* @returns The number of currently active schedules
|
|
875
|
-
*/
|
|
876
|
-
getActiveScheduleCount() {
|
|
877
|
-
return this.activeSchedules.size;
|
|
878
854
|
}
|
|
879
855
|
};
|
|
880
856
|
|
|
881
|
-
// src/shared/cache/swr-cache.ts
|
|
882
|
-
var bgRevalidationScheduler = new BackgroundRevalidationScheduler();
|
|
883
|
-
var SWRCache = class _SWRCache {
|
|
884
|
-
options;
|
|
885
|
-
cache;
|
|
886
|
-
/**
|
|
887
|
-
* Optional promise of the current in-progress attempt to revalidate the `cache`.
|
|
888
|
-
*
|
|
889
|
-
* If null, no revalidation attempt is currently in progress.
|
|
890
|
-
* If not null, identifies the revalidation attempt that is currently in progress.
|
|
891
|
-
*
|
|
892
|
-
* Used to enforce no concurrent revalidation attempts.
|
|
893
|
-
*/
|
|
894
|
-
inProgressRevalidate;
|
|
895
|
-
/**
|
|
896
|
-
* The callback function being managed by `BackgroundRevalidationScheduler`.
|
|
897
|
-
*
|
|
898
|
-
* If null, no background revalidation is scheduled.
|
|
899
|
-
* If not null, identifies the background revalidation that is currently scheduled.
|
|
900
|
-
*
|
|
901
|
-
* Used to enforce no concurrent background revalidation attempts.
|
|
902
|
-
*/
|
|
903
|
-
scheduledBackgroundRevalidate;
|
|
904
|
-
constructor(options) {
|
|
905
|
-
this.cache = null;
|
|
906
|
-
this.inProgressRevalidate = null;
|
|
907
|
-
this.scheduledBackgroundRevalidate = null;
|
|
908
|
-
this.options = options;
|
|
909
|
-
}
|
|
910
|
-
/**
|
|
911
|
-
* Asynchronously create a new `SWRCache` instance.
|
|
912
|
-
*
|
|
913
|
-
* @param options - The {@link SWRCacheOptions} for the SWR cache.
|
|
914
|
-
* @returns a new `SWRCache` instance.
|
|
915
|
-
*/
|
|
916
|
-
static async create(options) {
|
|
917
|
-
const cache = new _SWRCache(options);
|
|
918
|
-
if (cache.options.proactivelyInitialize) {
|
|
919
|
-
cache.readCache();
|
|
920
|
-
}
|
|
921
|
-
return cache;
|
|
922
|
-
}
|
|
923
|
-
revalidate = async () => {
|
|
924
|
-
if (this.inProgressRevalidate) {
|
|
925
|
-
return this.inProgressRevalidate;
|
|
926
|
-
}
|
|
927
|
-
return this.options.fn().then((value) => {
|
|
928
|
-
this.cache = {
|
|
929
|
-
value,
|
|
930
|
-
updatedAt: (0, import_getUnixTime.getUnixTime)(/* @__PURE__ */ new Date())
|
|
931
|
-
};
|
|
932
|
-
return this.cache;
|
|
933
|
-
}).catch(() => {
|
|
934
|
-
return null;
|
|
935
|
-
}).finally(() => {
|
|
936
|
-
this.inProgressRevalidate = null;
|
|
937
|
-
if (this.options.revalidationInterval === void 0) {
|
|
938
|
-
return;
|
|
939
|
-
}
|
|
940
|
-
if (this.scheduledBackgroundRevalidate) {
|
|
941
|
-
bgRevalidationScheduler.cancel(this.scheduledBackgroundRevalidate);
|
|
942
|
-
}
|
|
943
|
-
const backgroundRevalidate = async () => {
|
|
944
|
-
this.revalidate();
|
|
945
|
-
};
|
|
946
|
-
this.scheduledBackgroundRevalidate = bgRevalidationScheduler.schedule({
|
|
947
|
-
revalidate: backgroundRevalidate,
|
|
948
|
-
interval: (0, import_date_fns.secondsToMilliseconds)(this.options.revalidationInterval)
|
|
949
|
-
});
|
|
950
|
-
});
|
|
951
|
-
};
|
|
952
|
-
/**
|
|
953
|
-
* Read the most recently cached `CachedValue` from the `SWRCache`.
|
|
954
|
-
*
|
|
955
|
-
* @returns a `CachedValue` holding a `value` of `ValueType` that was most recently successfully returned by `fn`
|
|
956
|
-
* or `null` if `fn` has never successfully returned and has always thrown an error,
|
|
957
|
-
*/
|
|
958
|
-
readCache = async () => {
|
|
959
|
-
if (!this.cache) {
|
|
960
|
-
this.inProgressRevalidate = this.revalidate();
|
|
961
|
-
return this.inProgressRevalidate;
|
|
962
|
-
}
|
|
963
|
-
if (durationBetween(this.cache.updatedAt, (0, import_getUnixTime.getUnixTime)(/* @__PURE__ */ new Date())) <= this.options.ttl) {
|
|
964
|
-
return this.cache;
|
|
965
|
-
}
|
|
966
|
-
if (!this.inProgressRevalidate) {
|
|
967
|
-
this.inProgressRevalidate = this.revalidate();
|
|
968
|
-
}
|
|
969
|
-
return this.cache;
|
|
970
|
-
};
|
|
971
|
-
};
|
|
972
|
-
|
|
973
857
|
// src/shared/cache/ttl-cache.ts
|
|
974
858
|
var import_getUnixTime2 = require("date-fns/getUnixTime");
|
|
975
859
|
var TtlCache = class {
|
|
@@ -4179,7 +4063,11 @@ var translateDefaultableChainIdToChainId = (chainId, namespaceId) => {
|
|
|
4179
4063
|
// src/resolution/resolver-records-selection.ts
|
|
4180
4064
|
var isSelectionEmpty = (selection) => !selection.name && !selection.addresses?.length && !selection.texts?.length;
|
|
4181
4065
|
|
|
4182
|
-
// src/tracing/
|
|
4066
|
+
// src/tracing/ens-protocol-tracing.ts
|
|
4067
|
+
var PROTOCOL_ATTRIBUTE_PREFIX = "ens";
|
|
4068
|
+
var ATTR_PROTOCOL_NAME = `${PROTOCOL_ATTRIBUTE_PREFIX}.protocol`;
|
|
4069
|
+
var ATTR_PROTOCOL_STEP = `${PROTOCOL_ATTRIBUTE_PREFIX}.protocol.step`;
|
|
4070
|
+
var ATTR_PROTOCOL_STEP_RESULT = `${PROTOCOL_ATTRIBUTE_PREFIX}.protocol.step.result`;
|
|
4183
4071
|
var TraceableENSProtocol = /* @__PURE__ */ ((TraceableENSProtocol2) => {
|
|
4184
4072
|
TraceableENSProtocol2["ForwardResolution"] = "forward-resolution";
|
|
4185
4073
|
TraceableENSProtocol2["ReverseResolution"] = "reverse-resolution";
|
|
@@ -4204,8 +4092,4 @@ var ReverseResolutionProtocolStep = /* @__PURE__ */ ((ReverseResolutionProtocolS
|
|
|
4204
4092
|
ReverseResolutionProtocolStep2["VerifyResolvedAddressMatchesAddress"] = "verify-resolved-address-matches-address";
|
|
4205
4093
|
return ReverseResolutionProtocolStep2;
|
|
4206
4094
|
})(ReverseResolutionProtocolStep || {});
|
|
4207
|
-
var PROTOCOL_ATTRIBUTE_PREFIX = "ens";
|
|
4208
|
-
var ATTR_PROTOCOL_NAME = `${PROTOCOL_ATTRIBUTE_PREFIX}.protocol`;
|
|
4209
|
-
var ATTR_PROTOCOL_STEP = `${PROTOCOL_ATTRIBUTE_PREFIX}.protocol.step`;
|
|
4210
|
-
var ATTR_PROTOCOL_STEP_RESULT = `${PROTOCOL_ATTRIBUTE_PREFIX}.protocol.step.result`;
|
|
4211
4095
|
//# sourceMappingURL=index.cjs.map
|