@ensnode/ensnode-react 0.0.0-next-20260102143513
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/LICENSE +21 -0
- package/README.md +339 -0
- package/dist/index.cjs +418 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +553 -0
- package/dist/index.d.ts +553 -0
- package/dist/index.js +404 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
2
|
+
import { QueryObserverOptions, DefaultError, QueryKey, DefinedInitialDataOptions, QueryClient, DefinedUseQueryResult, UndefinedInitialDataOptions, UseQueryResult, UseQueryOptions } from '@tanstack/react-query';
|
|
3
|
+
export { QueryClient } from '@tanstack/react-query';
|
|
4
|
+
import * as _ensnode_ensnode_sdk from '@ensnode/ensnode-sdk';
|
|
5
|
+
import { ClientOptions, ResolvePrimaryNameRequest, ResolvePrimaryNameResponse, ResolvePrimaryNamesRequest, ResolvePrimaryNamesResponse, ResolverRecordsSelection, ResolveRecordsRequest, ResolveRecordsResponse, AcceleratableRequest, UnresolvedIdentity, ConfigResponse, IndexingStatusRequest, IndexingStatusResponse, NameTokensRequest, NameTokensResponse, RegistrarActionsRequest, RegistrarActionsResponse, Identity } from '@ensnode/ensnode-sdk';
|
|
6
|
+
export { ResolverRecordsSelection } from '@ensnode/ensnode-sdk';
|
|
7
|
+
import * as react from 'react';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Configuration options for the ENSNode provider
|
|
11
|
+
*/
|
|
12
|
+
interface ENSNodeSDKConfig {
|
|
13
|
+
/** The ENSNode API client configuration */
|
|
14
|
+
client: ClientOptions;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Base query parameters that can be passed to hooks
|
|
18
|
+
*/
|
|
19
|
+
interface QueryParameter<TData = unknown, TError = Error> {
|
|
20
|
+
query?: Partial<QueryObserverOptions<TData, TError, TData, TData, readonly unknown[]>>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Configuration parameter for hooks that need access to config
|
|
24
|
+
*/
|
|
25
|
+
interface WithSDKConfigParameter<TConfig extends ENSNodeSDKConfig = ENSNodeSDKConfig> {
|
|
26
|
+
config?: TConfig | undefined;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Parameters for the useRecords hook.
|
|
30
|
+
*
|
|
31
|
+
* If `name` is null, the query will not be executed.
|
|
32
|
+
*/
|
|
33
|
+
interface UseRecordsParameters<SELECTION extends ResolverRecordsSelection> extends Omit<ResolveRecordsRequest<SELECTION>, "name">, QueryParameter<ResolveRecordsResponse<SELECTION>> {
|
|
34
|
+
name: ResolveRecordsRequest<SELECTION>["name"] | null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Parameters for the usePrimaryName hook.
|
|
38
|
+
*
|
|
39
|
+
* If `address` is null, the query will not be executed.
|
|
40
|
+
*/
|
|
41
|
+
interface UsePrimaryNameParameters extends Omit<ResolvePrimaryNameRequest, "address">, QueryParameter<ResolvePrimaryNameResponse> {
|
|
42
|
+
address: ResolvePrimaryNameRequest["address"] | null;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Parameters for the usePrimaryNames hook.
|
|
46
|
+
*
|
|
47
|
+
* If `address` is null, the query will not be executed.
|
|
48
|
+
*/
|
|
49
|
+
interface UsePrimaryNamesParameters extends Omit<ResolvePrimaryNamesRequest, "address">, QueryParameter<ResolvePrimaryNamesResponse> {
|
|
50
|
+
address: ResolvePrimaryNamesRequest["address"] | null;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Parameters for the useResolvedIdentity hook.
|
|
54
|
+
*/
|
|
55
|
+
interface UseResolvedIdentityParameters extends QueryParameter<ResolvePrimaryNameResponse>, AcceleratableRequest {
|
|
56
|
+
identity: UnresolvedIdentity;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* React context for ENSNode configuration
|
|
61
|
+
*/
|
|
62
|
+
declare const ENSNodeContext: react.Context<ENSNodeSDKConfig | undefined>;
|
|
63
|
+
|
|
64
|
+
type UseENSNodeConfigParameters = QueryParameter<ConfigResponse>;
|
|
65
|
+
declare function useENSNodeConfig(parameters?: WithSDKConfigParameter & UseENSNodeConfigParameters): _tanstack_react_query.UseQueryResult<_ensnode_ensnode_sdk.ENSApiPublicConfig, Error>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Hook to access the ENSNodeSDKConfig from context or parameters.
|
|
69
|
+
*
|
|
70
|
+
* @param parameters - Optional config parameter that overrides context
|
|
71
|
+
* @returns The ENSNode configuration
|
|
72
|
+
* @throws Error if no config is available in context or parameters
|
|
73
|
+
*/
|
|
74
|
+
declare function useENSNodeSDKConfig<TConfig extends ENSNodeSDKConfig = ENSNodeSDKConfig>(config: TConfig | undefined): TConfig;
|
|
75
|
+
|
|
76
|
+
interface UseIndexingStatusParameters extends IndexingStatusRequest, QueryParameter<IndexingStatusResponse> {
|
|
77
|
+
}
|
|
78
|
+
declare function useIndexingStatus(parameters?: WithSDKConfigParameter & UseIndexingStatusParameters): _tanstack_react_query.UseQueryResult<IndexingStatusResponse, Error>;
|
|
79
|
+
|
|
80
|
+
type UseNameTokensParameters = NameTokensRequest & QueryParameter<NameTokensResponse>;
|
|
81
|
+
/**
|
|
82
|
+
* Use Name Tokens hook
|
|
83
|
+
*
|
|
84
|
+
* Query ENSNode Name Tokens API.
|
|
85
|
+
*/
|
|
86
|
+
declare function useNameTokens(parameters: WithSDKConfigParameter & UseNameTokensParameters): _tanstack_react_query.UseQueryResult<NameTokensResponse, Error>;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Resolves the primary name of a specified address (Reverse Resolution).
|
|
90
|
+
*
|
|
91
|
+
* The returned Primary Name, if set, is guaranteed to be a normalized name.
|
|
92
|
+
* If the primary name set for the address is not normalized, `null` is returned as if no primary name was set.
|
|
93
|
+
*
|
|
94
|
+
* @param parameters - Configuration for the address resolution
|
|
95
|
+
* @returns Query result with resolved primary name
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* import { usePrimaryName } from "@ensnode/ensnode-react";
|
|
100
|
+
*
|
|
101
|
+
* function DisplayPrimaryNameAndAvatar() {
|
|
102
|
+
* const { data, isLoading, error } = usePrimaryName({
|
|
103
|
+
* address: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
|
|
104
|
+
* chainId: 1, // Ethereum Mainnet
|
|
105
|
+
* accelerate: true, // Attempt Protocol Acceleration
|
|
106
|
+
* });
|
|
107
|
+
*
|
|
108
|
+
* if (isLoading) return <div>Loading...</div>;
|
|
109
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
110
|
+
*
|
|
111
|
+
* return (
|
|
112
|
+
* <div>
|
|
113
|
+
* <h3>Primary Name (for Mainnet)</h3>
|
|
114
|
+
* <p>{data.name ?? "No Primary Name"}</p>
|
|
115
|
+
* </div>
|
|
116
|
+
* );
|
|
117
|
+
* }
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
declare function usePrimaryName(parameters: UsePrimaryNameParameters & WithSDKConfigParameter): _tanstack_react_query.UseQueryResult<_ensnode_ensnode_sdk.ResolvePrimaryNameResponse, Error>;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Resolves the primary names of a specified address across multiple chains.
|
|
124
|
+
*
|
|
125
|
+
* Each returned Primary Name, if set, is guaranteed to be a normalized name.
|
|
126
|
+
* If the primary name set for the address on any chain is not normalized, `null` is returned for that chain as if no primary name was set.
|
|
127
|
+
*
|
|
128
|
+
* @param parameters - Configuration for the address resolution
|
|
129
|
+
* @returns Query result with resolved primary names
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* import { usePrimaryNames } from "@ensnode/ensnode-react";
|
|
134
|
+
*
|
|
135
|
+
* function DisplayPrimaryNames() {
|
|
136
|
+
* const { data, isLoading, error } = usePrimaryNames({
|
|
137
|
+
* address: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
|
|
138
|
+
* });
|
|
139
|
+
*
|
|
140
|
+
* if (isLoading) return <div>Loading...</div>;
|
|
141
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
142
|
+
*
|
|
143
|
+
* return (
|
|
144
|
+
* <div>
|
|
145
|
+
* {Object.entries(data.names).map(([chainId, name]) => (
|
|
146
|
+
* <div key={chainId}>
|
|
147
|
+
* <h3>Primary Name (Chain Id: {chainId})</h3>
|
|
148
|
+
* <p>{name}</p>
|
|
149
|
+
* </div>
|
|
150
|
+
* ))}
|
|
151
|
+
* </div>
|
|
152
|
+
* );
|
|
153
|
+
* }
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
declare function usePrimaryNames(parameters: UsePrimaryNamesParameters & WithSDKConfigParameter): _tanstack_react_query.UseQueryResult<_ensnode_ensnode_sdk.ResolvePrimaryNamesResponse, Error>;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Resolves records for an ENS name (Forward Resolution).
|
|
160
|
+
*
|
|
161
|
+
* The returned `name` field, if set, is guaranteed to be a normalized name.
|
|
162
|
+
* If the name record returned by the resolver is not normalized, `null` is returned as if no name record was set.
|
|
163
|
+
*
|
|
164
|
+
* @param parameters - Configuration for the ENS name resolution
|
|
165
|
+
* @returns Query result with resolved records
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* import { useRecords } from "@ensnode/ensnode-react";
|
|
170
|
+
*
|
|
171
|
+
* function DisplayNameRecords() {
|
|
172
|
+
* const { data, isLoading, error } = useRecords({
|
|
173
|
+
* name: "jesse.base.eth",
|
|
174
|
+
* selection: {
|
|
175
|
+
* addresses: [60], // ETH CoinType
|
|
176
|
+
* texts: ["avatar", "com.twitter"]
|
|
177
|
+
* }
|
|
178
|
+
* });
|
|
179
|
+
*
|
|
180
|
+
* if (isLoading) return <div>Loading...</div>;
|
|
181
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
182
|
+
*
|
|
183
|
+
* return (
|
|
184
|
+
* <div>
|
|
185
|
+
* <h3>Resolved Records for vitalik.eth</h3>
|
|
186
|
+
* {data.records.addresses && (
|
|
187
|
+
* <p>ETH Address: {data.records.addresses[60]}</p>
|
|
188
|
+
* )}
|
|
189
|
+
* {data.records.texts && (
|
|
190
|
+
* <div>
|
|
191
|
+
* <p>Avatar: {data.records.texts.avatar}</p>
|
|
192
|
+
* <p>Twitter: {data.records.texts["com.twitter"]}</p>
|
|
193
|
+
* </div>
|
|
194
|
+
* )}
|
|
195
|
+
* </div>
|
|
196
|
+
* );
|
|
197
|
+
* }
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
declare function useRecords<SELECTION extends ResolverRecordsSelection>(parameters: UseRecordsParameters<SELECTION> & WithSDKConfigParameter): _tanstack_react_query.UseQueryResult<_ensnode_ensnode_sdk.ResolveRecordsResponse<SELECTION>, Error>;
|
|
201
|
+
|
|
202
|
+
interface UseRegistrarActionsParameters extends RegistrarActionsRequest, QueryParameter<RegistrarActionsResponse> {
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Use Registrar Actions hook
|
|
206
|
+
*
|
|
207
|
+
* Query ENSNode Registrar Actions API.
|
|
208
|
+
*/
|
|
209
|
+
declare function useRegistrarActions(parameters?: WithSDKConfigParameter & UseRegistrarActionsParameters): _tanstack_react_query.UseQueryResult<RegistrarActionsResponse, Error>;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Hook to perform ENSIP-19 primary name resolution to resolve an
|
|
213
|
+
* {@link UnresolvedIdentity} into a {@link ResolvedIdentity}.
|
|
214
|
+
*
|
|
215
|
+
* @param parameters - Configuration object for the hook
|
|
216
|
+
* @param parameters.identity - An {@link UnresolvedIdentity} containing the {@link DefaultableChainId}
|
|
217
|
+
* and {@link Address} to resolve.
|
|
218
|
+
* @param parameters.namespaceId - The {@link ENSNamespaceId} that `identity.chainId` should be interpreted
|
|
219
|
+
* through (via {@link getResolvePrimaryNameChainIdParam}) to determine the literal
|
|
220
|
+
* chainId that should be used for ENSIP-19 primary name resolution.
|
|
221
|
+
* @param parameters.accelerate - Whether to attempt Protocol Acceleration (default: false)
|
|
222
|
+
* when resolving the primary name.
|
|
223
|
+
*
|
|
224
|
+
* @returns An object containing:
|
|
225
|
+
* - `identity`: An {@link Identity} with one of four possible {@link ResolutionStatusIds}:
|
|
226
|
+
* - {@link ResolutionStatusIds.Unresolved}: While the query is pending (loading state).
|
|
227
|
+
* - {@link ResolutionStatusIds.Unknown}: If an error occurs during resolution.
|
|
228
|
+
* - {@link ResolutionStatusIds.Unnamed}: If the resolution found no primary name.
|
|
229
|
+
* - {@link ResolutionStatusIds.Named}: If a primary name is successfully resolved.
|
|
230
|
+
* - All other properties from the underlying {@link usePrimaryName} query (e.g., `isLoading`, `error`, `refetch`, etc.)
|
|
231
|
+
*/
|
|
232
|
+
declare function useResolvedIdentity(parameters: UseResolvedIdentityParameters): {
|
|
233
|
+
identity: Identity;
|
|
234
|
+
error: Error;
|
|
235
|
+
isError: true;
|
|
236
|
+
isPending: false;
|
|
237
|
+
isLoading: false;
|
|
238
|
+
isLoadingError: false;
|
|
239
|
+
isRefetchError: true;
|
|
240
|
+
isSuccess: false;
|
|
241
|
+
isPlaceholderData: false;
|
|
242
|
+
dataUpdatedAt: number;
|
|
243
|
+
errorUpdatedAt: number;
|
|
244
|
+
failureCount: number;
|
|
245
|
+
failureReason: Error | null;
|
|
246
|
+
errorUpdateCount: number;
|
|
247
|
+
isFetched: boolean;
|
|
248
|
+
isFetchedAfterMount: boolean;
|
|
249
|
+
isFetching: boolean;
|
|
250
|
+
isInitialLoading: boolean;
|
|
251
|
+
isPaused: boolean;
|
|
252
|
+
isRefetching: boolean;
|
|
253
|
+
isStale: boolean;
|
|
254
|
+
isEnabled: boolean;
|
|
255
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<_ensnode_ensnode_sdk.ResolvePrimaryNameResponse, Error>>;
|
|
256
|
+
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
257
|
+
promise: Promise<_ensnode_ensnode_sdk.ResolvePrimaryNameResponse>;
|
|
258
|
+
} | {
|
|
259
|
+
identity: Identity;
|
|
260
|
+
error: null;
|
|
261
|
+
isError: false;
|
|
262
|
+
isPending: false;
|
|
263
|
+
isLoading: false;
|
|
264
|
+
isLoadingError: false;
|
|
265
|
+
isRefetchError: false;
|
|
266
|
+
isSuccess: true;
|
|
267
|
+
isPlaceholderData: false;
|
|
268
|
+
dataUpdatedAt: number;
|
|
269
|
+
errorUpdatedAt: number;
|
|
270
|
+
failureCount: number;
|
|
271
|
+
failureReason: Error | null;
|
|
272
|
+
errorUpdateCount: number;
|
|
273
|
+
isFetched: boolean;
|
|
274
|
+
isFetchedAfterMount: boolean;
|
|
275
|
+
isFetching: boolean;
|
|
276
|
+
isInitialLoading: boolean;
|
|
277
|
+
isPaused: boolean;
|
|
278
|
+
isRefetching: boolean;
|
|
279
|
+
isStale: boolean;
|
|
280
|
+
isEnabled: boolean;
|
|
281
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<_ensnode_ensnode_sdk.ResolvePrimaryNameResponse, Error>>;
|
|
282
|
+
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
283
|
+
promise: Promise<_ensnode_ensnode_sdk.ResolvePrimaryNameResponse>;
|
|
284
|
+
} | {
|
|
285
|
+
identity: Identity;
|
|
286
|
+
error: Error;
|
|
287
|
+
isError: true;
|
|
288
|
+
isPending: false;
|
|
289
|
+
isLoading: false;
|
|
290
|
+
isLoadingError: true;
|
|
291
|
+
isRefetchError: false;
|
|
292
|
+
isSuccess: false;
|
|
293
|
+
isPlaceholderData: false;
|
|
294
|
+
dataUpdatedAt: number;
|
|
295
|
+
errorUpdatedAt: number;
|
|
296
|
+
failureCount: number;
|
|
297
|
+
failureReason: Error | null;
|
|
298
|
+
errorUpdateCount: number;
|
|
299
|
+
isFetched: boolean;
|
|
300
|
+
isFetchedAfterMount: boolean;
|
|
301
|
+
isFetching: boolean;
|
|
302
|
+
isInitialLoading: boolean;
|
|
303
|
+
isPaused: boolean;
|
|
304
|
+
isRefetching: boolean;
|
|
305
|
+
isStale: boolean;
|
|
306
|
+
isEnabled: boolean;
|
|
307
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<_ensnode_ensnode_sdk.ResolvePrimaryNameResponse, Error>>;
|
|
308
|
+
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
309
|
+
promise: Promise<_ensnode_ensnode_sdk.ResolvePrimaryNameResponse>;
|
|
310
|
+
} | {
|
|
311
|
+
identity: Identity;
|
|
312
|
+
error: null;
|
|
313
|
+
isError: false;
|
|
314
|
+
isPending: true;
|
|
315
|
+
isLoading: true;
|
|
316
|
+
isLoadingError: false;
|
|
317
|
+
isRefetchError: false;
|
|
318
|
+
isSuccess: false;
|
|
319
|
+
isPlaceholderData: false;
|
|
320
|
+
dataUpdatedAt: number;
|
|
321
|
+
errorUpdatedAt: number;
|
|
322
|
+
failureCount: number;
|
|
323
|
+
failureReason: Error | null;
|
|
324
|
+
errorUpdateCount: number;
|
|
325
|
+
isFetched: boolean;
|
|
326
|
+
isFetchedAfterMount: boolean;
|
|
327
|
+
isFetching: boolean;
|
|
328
|
+
isInitialLoading: boolean;
|
|
329
|
+
isPaused: boolean;
|
|
330
|
+
isRefetching: boolean;
|
|
331
|
+
isStale: boolean;
|
|
332
|
+
isEnabled: boolean;
|
|
333
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<_ensnode_ensnode_sdk.ResolvePrimaryNameResponse, Error>>;
|
|
334
|
+
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
335
|
+
promise: Promise<_ensnode_ensnode_sdk.ResolvePrimaryNameResponse>;
|
|
336
|
+
} | {
|
|
337
|
+
identity: Identity;
|
|
338
|
+
error: null;
|
|
339
|
+
isError: false;
|
|
340
|
+
isPending: true;
|
|
341
|
+
isLoadingError: false;
|
|
342
|
+
isRefetchError: false;
|
|
343
|
+
isSuccess: false;
|
|
344
|
+
isPlaceholderData: false;
|
|
345
|
+
dataUpdatedAt: number;
|
|
346
|
+
errorUpdatedAt: number;
|
|
347
|
+
failureCount: number;
|
|
348
|
+
failureReason: Error | null;
|
|
349
|
+
errorUpdateCount: number;
|
|
350
|
+
isFetched: boolean;
|
|
351
|
+
isFetchedAfterMount: boolean;
|
|
352
|
+
isFetching: boolean;
|
|
353
|
+
isLoading: boolean;
|
|
354
|
+
isInitialLoading: boolean;
|
|
355
|
+
isPaused: boolean;
|
|
356
|
+
isRefetching: boolean;
|
|
357
|
+
isStale: boolean;
|
|
358
|
+
isEnabled: boolean;
|
|
359
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<_ensnode_ensnode_sdk.ResolvePrimaryNameResponse, Error>>;
|
|
360
|
+
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
361
|
+
promise: Promise<_ensnode_ensnode_sdk.ResolvePrimaryNameResponse>;
|
|
362
|
+
} | {
|
|
363
|
+
identity: Identity;
|
|
364
|
+
isError: false;
|
|
365
|
+
error: null;
|
|
366
|
+
isPending: false;
|
|
367
|
+
isLoading: false;
|
|
368
|
+
isLoadingError: false;
|
|
369
|
+
isRefetchError: false;
|
|
370
|
+
isSuccess: true;
|
|
371
|
+
isPlaceholderData: true;
|
|
372
|
+
dataUpdatedAt: number;
|
|
373
|
+
errorUpdatedAt: number;
|
|
374
|
+
failureCount: number;
|
|
375
|
+
failureReason: Error | null;
|
|
376
|
+
errorUpdateCount: number;
|
|
377
|
+
isFetched: boolean;
|
|
378
|
+
isFetchedAfterMount: boolean;
|
|
379
|
+
isFetching: boolean;
|
|
380
|
+
isInitialLoading: boolean;
|
|
381
|
+
isPaused: boolean;
|
|
382
|
+
isRefetching: boolean;
|
|
383
|
+
isStale: boolean;
|
|
384
|
+
isEnabled: boolean;
|
|
385
|
+
refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<_ensnode_ensnode_sdk.ResolvePrimaryNameResponse, Error>>;
|
|
386
|
+
fetchStatus: _tanstack_react_query.FetchStatus;
|
|
387
|
+
promise: Promise<_ensnode_ensnode_sdk.ResolvePrimaryNameResponse>;
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Use Stale-While-Revalidate Query
|
|
392
|
+
*
|
|
393
|
+
* This hooks is a proxy for {@link useQuery} with addition of the following
|
|
394
|
+
* semantics:
|
|
395
|
+
* - if the query has been resolved successfully just once,
|
|
396
|
+
* the query result will always be success with data being the previously
|
|
397
|
+
* cached result,
|
|
398
|
+
* - the cached result can never go stale, or be garbage collected
|
|
399
|
+
* - the cached result can be only overridden by the current result when
|
|
400
|
+
* the query is successfully re-fetched (in other words,
|
|
401
|
+
* the `options.queryFn` returns a resolved promise).
|
|
402
|
+
*
|
|
403
|
+
* Please note how there can be any number of failed queries before one
|
|
404
|
+
* succeeds. In such case, no successful result has ever been cached and
|
|
405
|
+
* the query fails (`isError: true`, `error` is available) until
|
|
406
|
+
* the first successful resolution (`isSuccess: true`, `data` is available).
|
|
407
|
+
*
|
|
408
|
+
* @example
|
|
409
|
+
* ```tsx
|
|
410
|
+
* const swrQuery = useSwrQuery({
|
|
411
|
+
* queryKey: ['data'],
|
|
412
|
+
* queryFn: fetchData,
|
|
413
|
+
* });
|
|
414
|
+
*
|
|
415
|
+
* if (swrQuery.isPending) {
|
|
416
|
+
* // Show loading state while there's no cached successful result and
|
|
417
|
+
* // no query attempt was finished yet.
|
|
418
|
+
* return <>Loading...</>;
|
|
419
|
+
* }
|
|
420
|
+
*
|
|
421
|
+
* if (swrQuery.isError) {
|
|
422
|
+
* // Show error state when query attempt fails and
|
|
423
|
+
* // no cached successful result is available.
|
|
424
|
+
* return <>Error: {swrQuery.error.message}</>;
|
|
425
|
+
* }
|
|
426
|
+
*
|
|
427
|
+
* // Otherwise, show data when the cached successful result is available.
|
|
428
|
+
* return <>Data: {JSON.stringify(swrQuery.data)}</>;
|
|
429
|
+
* ```
|
|
430
|
+
*/
|
|
431
|
+
declare function useSwrQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>, queryClient?: QueryClient): DefinedUseQueryResult<NoInfer<TData>, TError>;
|
|
432
|
+
declare function useSwrQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>, queryClient?: QueryClient): UseQueryResult<NoInfer<TData>, TError>;
|
|
433
|
+
declare function useSwrQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, queryClient?: QueryClient): UseQueryResult<NoInfer<TData>, TError>;
|
|
434
|
+
|
|
435
|
+
interface ENSNodeProviderProps {
|
|
436
|
+
/** ENSNode configuration */
|
|
437
|
+
config: ENSNodeSDKConfig;
|
|
438
|
+
/**
|
|
439
|
+
* Optional QueryClient instance. If provided, you must wrap your app with QueryClientProvider yourself.
|
|
440
|
+
* If not provided, ENSNodeProvider will create and manage its own QueryClient internally.
|
|
441
|
+
*/
|
|
442
|
+
queryClient?: QueryClient;
|
|
443
|
+
/**
|
|
444
|
+
* Custom query client options when auto-creating a QueryClient.
|
|
445
|
+
* Only used when queryClient is not provided.
|
|
446
|
+
*/
|
|
447
|
+
queryClientOptions?: ConstructorParameters<typeof QueryClient>[0];
|
|
448
|
+
}
|
|
449
|
+
declare function ENSNodeProvider(parameters: React.PropsWithChildren<ENSNodeProviderProps>): react.FunctionComponentElement<{
|
|
450
|
+
children?: React.ReactNode;
|
|
451
|
+
config: ENSNodeSDKConfig;
|
|
452
|
+
}> | react.FunctionComponentElement<_tanstack_react_query.QueryClientProviderProps>;
|
|
453
|
+
/**
|
|
454
|
+
* Helper function to create ENSNode configuration
|
|
455
|
+
*/
|
|
456
|
+
declare function createConfig(options?: {
|
|
457
|
+
url?: string | URL;
|
|
458
|
+
}): ENSNodeSDKConfig;
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Immutable query options for data that is assumed to be immutable and should only be fetched once per full page refresh per unique key.
|
|
462
|
+
* Similar to SWR's immutable: true API.
|
|
463
|
+
*
|
|
464
|
+
* Use this for data that is assumed not to change (e.g., records for a specific name) until the next full page refresh.
|
|
465
|
+
*
|
|
466
|
+
* @example
|
|
467
|
+
* ```tsx
|
|
468
|
+
* useRecords({
|
|
469
|
+
* name: "vitalik.eth",
|
|
470
|
+
* selection: { texts: ["avatar"] },
|
|
471
|
+
* query: ASSUME_IMMUTABLE_QUERY
|
|
472
|
+
* })
|
|
473
|
+
* ```
|
|
474
|
+
*/
|
|
475
|
+
declare const ASSUME_IMMUTABLE_QUERY: {
|
|
476
|
+
readonly staleTime: number;
|
|
477
|
+
readonly gcTime: number;
|
|
478
|
+
readonly refetchOnWindowFocus: false;
|
|
479
|
+
readonly refetchOnReconnect: false;
|
|
480
|
+
readonly refetchOnMount: false;
|
|
481
|
+
};
|
|
482
|
+
/**
|
|
483
|
+
* Query keys for hooks. Simply keys by path and arguments.
|
|
484
|
+
*/
|
|
485
|
+
declare const queryKeys: {
|
|
486
|
+
base: (url: string) => readonly ["ensnode", string];
|
|
487
|
+
resolve: (url: string) => readonly ["ensnode", string, "resolve"];
|
|
488
|
+
records: (url: string, args: ResolveRecordsRequest<any>) => readonly ["ensnode", string, "resolve", "records", ResolveRecordsRequest<any>];
|
|
489
|
+
primaryName: (url: string, args: ResolvePrimaryNameRequest) => readonly ["ensnode", string, "resolve", "primary-name", ResolvePrimaryNameRequest];
|
|
490
|
+
primaryNames: (url: string, args: ResolvePrimaryNamesRequest) => readonly ["ensnode", string, "resolve", "primary-names", ResolvePrimaryNamesRequest];
|
|
491
|
+
config: (url: string) => readonly ["ensnode", string, "config"];
|
|
492
|
+
indexingStatus: (url: string) => readonly ["ensnode", string, "indexing-status"];
|
|
493
|
+
registrarActions: (url: string, args: RegistrarActionsRequest) => readonly ["ensnode", string, "registrar-actions", RegistrarActionsRequest];
|
|
494
|
+
nameTokens: (url: string, args: NameTokensRequest) => readonly ["ensnode", string, "name-tokens", NameTokensRequest];
|
|
495
|
+
};
|
|
496
|
+
/**
|
|
497
|
+
* Creates query options for Records Resolution
|
|
498
|
+
*/
|
|
499
|
+
declare function createRecordsQueryOptions<SELECTION extends ResolverRecordsSelection>(config: ENSNodeSDKConfig, args: ResolveRecordsRequest<SELECTION>): {
|
|
500
|
+
enabled: boolean;
|
|
501
|
+
queryKey: readonly ["ensnode", string, "resolve", "records", ResolveRecordsRequest<any>];
|
|
502
|
+
queryFn: () => Promise<_ensnode_ensnode_sdk.ResolveRecordsResponse<SELECTION>>;
|
|
503
|
+
};
|
|
504
|
+
/**
|
|
505
|
+
* Creates query options for Primary Name Resolution
|
|
506
|
+
*/
|
|
507
|
+
declare function createPrimaryNameQueryOptions(config: ENSNodeSDKConfig, args: ResolvePrimaryNameRequest): {
|
|
508
|
+
enabled: boolean;
|
|
509
|
+
queryKey: readonly ["ensnode", string, "resolve", "primary-name", ResolvePrimaryNameRequest];
|
|
510
|
+
queryFn: () => Promise<_ensnode_ensnode_sdk.ResolvePrimaryNameResponse>;
|
|
511
|
+
};
|
|
512
|
+
/**
|
|
513
|
+
* Creates query options for Primary Name Resolution
|
|
514
|
+
*/
|
|
515
|
+
declare function createPrimaryNamesQueryOptions(config: ENSNodeSDKConfig, args: ResolvePrimaryNamesRequest): {
|
|
516
|
+
enabled: boolean;
|
|
517
|
+
queryKey: readonly ["ensnode", string, "resolve", "primary-names", ResolvePrimaryNamesRequest];
|
|
518
|
+
queryFn: () => Promise<_ensnode_ensnode_sdk.ResolvePrimaryNamesResponse>;
|
|
519
|
+
};
|
|
520
|
+
/**
|
|
521
|
+
* Creates query options for ENSNode Config API
|
|
522
|
+
*/
|
|
523
|
+
declare function createConfigQueryOptions(config: ENSNodeSDKConfig): {
|
|
524
|
+
enabled: boolean;
|
|
525
|
+
queryKey: readonly ["ensnode", string, "config"];
|
|
526
|
+
queryFn: () => Promise<_ensnode_ensnode_sdk.ENSApiPublicConfig>;
|
|
527
|
+
};
|
|
528
|
+
/**
|
|
529
|
+
* Creates query options for ENSNode Indexing Status API
|
|
530
|
+
*/
|
|
531
|
+
declare function createIndexingStatusQueryOptions(config: ENSNodeSDKConfig): {
|
|
532
|
+
enabled: boolean;
|
|
533
|
+
queryKey: readonly ["ensnode", string, "indexing-status"];
|
|
534
|
+
queryFn: () => Promise<_ensnode_ensnode_sdk.IndexingStatusResponse>;
|
|
535
|
+
};
|
|
536
|
+
/**
|
|
537
|
+
* Creates query options for ENSNode Registrar Actions API
|
|
538
|
+
*/
|
|
539
|
+
declare function createRegistrarActionsQueryOptions(config: ENSNodeSDKConfig, args: RegistrarActionsRequest): {
|
|
540
|
+
enabled: boolean;
|
|
541
|
+
queryKey: readonly ["ensnode", string, "registrar-actions", RegistrarActionsRequest];
|
|
542
|
+
queryFn: () => Promise<_ensnode_ensnode_sdk.RegistrarActionsResponse>;
|
|
543
|
+
};
|
|
544
|
+
/**
|
|
545
|
+
* Creates query options for Name Tokens API
|
|
546
|
+
*/
|
|
547
|
+
declare function createNameTokensQueryOptions(config: ENSNodeSDKConfig, args: NameTokensRequest): {
|
|
548
|
+
enabled: boolean;
|
|
549
|
+
queryKey: readonly ["ensnode", string, "name-tokens", NameTokensRequest];
|
|
550
|
+
queryFn: () => Promise<_ensnode_ensnode_sdk.NameTokensResponse>;
|
|
551
|
+
};
|
|
552
|
+
|
|
553
|
+
export { ASSUME_IMMUTABLE_QUERY, ENSNodeContext, ENSNodeProvider, type ENSNodeProviderProps, type ENSNodeSDKConfig, type QueryParameter, type UsePrimaryNameParameters, type UsePrimaryNamesParameters, type UseRecordsParameters, type UseResolvedIdentityParameters, type WithSDKConfigParameter, createConfig, createConfigQueryOptions, createIndexingStatusQueryOptions, createNameTokensQueryOptions, createPrimaryNameQueryOptions, createPrimaryNamesQueryOptions, createRecordsQueryOptions, createRegistrarActionsQueryOptions, queryKeys, useENSNodeConfig, useENSNodeSDKConfig, useIndexingStatus, useNameTokens, usePrimaryName, usePrimaryNames, useRecords, useRegistrarActions, useResolvedIdentity, useSwrQuery };
|