@ensdomains/ensjs-query-core 0.0.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.
Files changed (68) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +85 -0
  3. package/src/actions/public/getAbiRecord.ts +39 -0
  4. package/src/actions/public/getAddressRecord.ts +38 -0
  5. package/src/actions/public/getAvailable.ts +39 -0
  6. package/src/actions/public/getContentHashRecord.ts +41 -0
  7. package/src/actions/public/getCredentials.ts +39 -0
  8. package/src/actions/public/getExpiry.ts +42 -0
  9. package/src/actions/public/getName.ts +39 -0
  10. package/src/actions/public/getOwner.ts +45 -0
  11. package/src/actions/public/getPrice.ts +42 -0
  12. package/src/actions/public/getRecords.ts +69 -0
  13. package/src/actions/public/getResolver.ts +39 -0
  14. package/src/actions/public/getSupportedInterfaces.ts +53 -0
  15. package/src/actions/public/getTextRecord.ts +39 -0
  16. package/src/actions/public/getWrapperData.ts +39 -0
  17. package/src/actions/public/getWrapperName.ts +39 -0
  18. package/src/actions/public/resolveNameData.ts +46 -0
  19. package/src/actions/wallet/clearRecords.ts +69 -0
  20. package/src/actions/wallet/commitName.ts +62 -0
  21. package/src/actions/wallet/createSubname.ts +67 -0
  22. package/src/actions/wallet/deleteSubname.ts +64 -0
  23. package/src/actions/wallet/index.ts +84 -0
  24. package/src/actions/wallet/registerName.ts +62 -0
  25. package/src/actions/wallet/renewNames.ts +65 -0
  26. package/src/actions/wallet/setAbiRecord.ts +63 -0
  27. package/src/actions/wallet/setAddressRecord.ts +58 -0
  28. package/src/actions/wallet/setContentHashRecord.ts +63 -0
  29. package/src/actions/wallet/setPrimaryName.ts +67 -0
  30. package/src/actions/wallet/setRecords.ts +62 -0
  31. package/src/actions/wallet/setResolver.ts +62 -0
  32. package/src/actions/wallet/setTextRecord.ts +58 -0
  33. package/src/actions/wallet/transferName.ts +73 -0
  34. package/src/example.ts +39 -0
  35. package/src/query/public/getAbiRecord.ts +61 -0
  36. package/src/query/public/getAddressRecord.ts +61 -0
  37. package/src/query/public/getAvailable.ts +61 -0
  38. package/src/query/public/getContentHashRecord.ts +61 -0
  39. package/src/query/public/getCredentials.ts +61 -0
  40. package/src/query/public/getExpiry.ts +64 -0
  41. package/src/query/public/getName.ts +61 -0
  42. package/src/query/public/getOwner.ts +67 -0
  43. package/src/query/public/getPrice.ts +65 -0
  44. package/src/query/public/getRecords.ts +83 -0
  45. package/src/query/public/getResolver.ts +61 -0
  46. package/src/query/public/getSupportedInterfaces.ts +80 -0
  47. package/src/query/public/getTextRecord.ts +62 -0
  48. package/src/query/public/getWrapperData.ts +61 -0
  49. package/src/query/public/getWrapperName.ts +61 -0
  50. package/src/query/public/index.ts +134 -0
  51. package/src/query/utils.ts +26 -0
  52. package/src/query/wallet/clearRecords.ts +54 -0
  53. package/src/query/wallet/commitName.ts +54 -0
  54. package/src/query/wallet/createSubname.ts +57 -0
  55. package/src/query/wallet/deleteSubname.ts +54 -0
  56. package/src/query/wallet/index.ts +85 -0
  57. package/src/query/wallet/registerName.ts +54 -0
  58. package/src/query/wallet/renewNames.ts +57 -0
  59. package/src/query/wallet/setAbiRecord.ts +53 -0
  60. package/src/query/wallet/setAddressRecord.ts +50 -0
  61. package/src/query/wallet/setContentHashRecord.ts +50 -0
  62. package/src/query/wallet/setPrimaryName.ts +57 -0
  63. package/src/query/wallet/setRecords.ts +54 -0
  64. package/src/query/wallet/setResolver.ts +54 -0
  65. package/src/query/wallet/setTextRecord.ts +50 -0
  66. package/src/query/wallet/transferName.ts +66 -0
  67. package/src/utils/chain.ts +50 -0
  68. package/src/utils/getAction.ts +56 -0
@@ -0,0 +1,61 @@
1
+ import {
2
+ ASSERT_NO_TYPE_ERROR,
3
+ type ExcludeTE,
4
+ } from '@ensdomains/ensjs/internal'
5
+ import type { QueryOptions } from '@tanstack/query-core'
6
+ import type { Config } from '@wagmi/core'
7
+ import type {
8
+ Compute,
9
+ ExactPartial,
10
+ ScopeKeyParameter,
11
+ } from '@wagmi/core/internal'
12
+ import type { Chain } from 'viem'
13
+ import {
14
+ type GetAvailableErrorType,
15
+ type GetAvailableParameters,
16
+ type GetAvailableReturnType,
17
+ getAvailable,
18
+ } from '../../actions/public/getAvailable.js'
19
+ import type { RequireConfigContracts } from '../../utils/chain.js'
20
+ import { filterQueryOptions } from '../utils.js'
21
+
22
+ export type GetAvailableOptions<config extends Config> = Compute<
23
+ ExactPartial<GetAvailableParameters<config>> & ScopeKeyParameter
24
+ >
25
+
26
+ export function getAvailableQueryOptions<
27
+ chains extends readonly [Chain, ...Chain[]],
28
+ >(
29
+ config: RequireConfigContracts<chains, 'ensBaseRegistrarImplementation'>,
30
+ options: GetAvailableOptions<ExcludeTE<typeof config>> = {},
31
+ ) {
32
+ ASSERT_NO_TYPE_ERROR(config)
33
+
34
+ return {
35
+ async queryFn({ queryKey }) {
36
+ const { name, scopeKey: _, ...parameters } = queryKey[1]
37
+ if (!name) throw new Error('name is required')
38
+ return getAvailable<chains>(config, { ...parameters, name })
39
+ },
40
+ queryKey: getAvailableQueryKey(options),
41
+ } as const satisfies QueryOptions<
42
+ GetAvailableQueryFnData,
43
+ GetAvailableErrorType,
44
+ GetAvailableData,
45
+ GetAvailableQueryKey<typeof config>
46
+ >
47
+ }
48
+
49
+ export type GetAvailableQueryFnData = GetAvailableReturnType
50
+
51
+ export type GetAvailableData = GetAvailableQueryFnData
52
+
53
+ export function getAvailableQueryKey<config extends Config>(
54
+ options: GetAvailableOptions<config> = {},
55
+ ) {
56
+ return ['ensjs_available', filterQueryOptions(options)] as const
57
+ }
58
+
59
+ export type GetAvailableQueryKey<config extends Config> = ReturnType<
60
+ typeof getAvailableQueryKey<config>
61
+ >
@@ -0,0 +1,61 @@
1
+ import {
2
+ ASSERT_NO_TYPE_ERROR,
3
+ type ExcludeTE,
4
+ } from '@ensdomains/ensjs/internal'
5
+ import type { QueryOptions } from '@tanstack/query-core'
6
+ import type { Config } from '@wagmi/core'
7
+ import type {
8
+ Compute,
9
+ ExactPartial,
10
+ ScopeKeyParameter,
11
+ } from '@wagmi/core/internal'
12
+ import type { Chain } from 'viem'
13
+ import {
14
+ type GetContentHashRecordErrorType,
15
+ type GetContentHashRecordParameters,
16
+ type GetContentHashRecordReturnType,
17
+ getContentHashRecord,
18
+ } from '../../actions/public/getContentHashRecord.js'
19
+ import type { RequireConfigContracts } from '../../utils/chain.js'
20
+ import { filterQueryOptions } from '../utils.js'
21
+
22
+ export type GetContentHashRecordOptions<config extends Config> = Compute<
23
+ ExactPartial<GetContentHashRecordParameters<config>> & ScopeKeyParameter
24
+ >
25
+
26
+ export function getContentHashRecordQueryOptions<
27
+ chains extends readonly [Chain, ...Chain[]],
28
+ >(
29
+ config: RequireConfigContracts<chains, 'ensUniversalResolver'>,
30
+ options: GetContentHashRecordOptions<ExcludeTE<typeof config>> = {},
31
+ ) {
32
+ ASSERT_NO_TYPE_ERROR(config)
33
+
34
+ return {
35
+ async queryFn({ queryKey }) {
36
+ const { name, scopeKey: _, ...parameters } = queryKey[1]
37
+ if (!name) throw new Error('name is required')
38
+ return getContentHashRecord<chains>(config, { ...parameters, name })
39
+ },
40
+ queryKey: getContentHashRecordQueryKey(options),
41
+ } as const satisfies QueryOptions<
42
+ GetContentHashRecordQueryFnData,
43
+ GetContentHashRecordErrorType,
44
+ GetContentHashRecordData,
45
+ GetContentHashRecordQueryKey<typeof config>
46
+ >
47
+ }
48
+
49
+ export type GetContentHashRecordQueryFnData = GetContentHashRecordReturnType
50
+
51
+ export type GetContentHashRecordData = GetContentHashRecordQueryFnData
52
+
53
+ export function getContentHashRecordQueryKey<config extends Config>(
54
+ options: GetContentHashRecordOptions<config> = {},
55
+ ) {
56
+ return ['ensjs_contentHashRecord', filterQueryOptions(options)] as const
57
+ }
58
+
59
+ export type GetContentHashRecordQueryKey<config extends Config> = ReturnType<
60
+ typeof getContentHashRecordQueryKey<config>
61
+ >
@@ -0,0 +1,61 @@
1
+ import {
2
+ ASSERT_NO_TYPE_ERROR,
3
+ type ExcludeTE,
4
+ } from '@ensdomains/ensjs/internal'
5
+ import type { QueryOptions } from '@tanstack/query-core'
6
+ import type { Config } from '@wagmi/core'
7
+ import type {
8
+ Compute,
9
+ ExactPartial,
10
+ ScopeKeyParameter,
11
+ } from '@wagmi/core/internal'
12
+ import type { Chain } from 'viem'
13
+ import {
14
+ type GetCredentialsErrorType,
15
+ type GetCredentialsParameters,
16
+ type GetCredentialsReturnType,
17
+ getCredentials,
18
+ } from '../../actions/public/getCredentials.js'
19
+ import type { RequireConfigContracts } from '../../utils/chain.js'
20
+ import { filterQueryOptions } from '../utils.js'
21
+
22
+ export type GetCredentialsOptions<config extends Config> = Compute<
23
+ ExactPartial<GetCredentialsParameters<config>> & ScopeKeyParameter
24
+ >
25
+
26
+ export function getCredentialsQueryOptions<
27
+ chains extends readonly [Chain, ...Chain[]],
28
+ >(
29
+ config: RequireConfigContracts<chains, 'ensUniversalResolver'>,
30
+ options: GetCredentialsOptions<ExcludeTE<typeof config>> = {},
31
+ ) {
32
+ ASSERT_NO_TYPE_ERROR(config)
33
+
34
+ return {
35
+ async queryFn({ queryKey }) {
36
+ const { name, scopeKey: _, ...parameters } = queryKey[1]
37
+ if (!name) throw new Error('name is required')
38
+ return getCredentials<chains>(config, { ...parameters, name })
39
+ },
40
+ queryKey: getCredentialsQueryKey(options),
41
+ } as const satisfies QueryOptions<
42
+ GetCredentialsQueryFnData,
43
+ GetCredentialsErrorType,
44
+ GetCredentialsData,
45
+ GetCredentialsQueryKey<typeof config>
46
+ >
47
+ }
48
+
49
+ export type GetCredentialsQueryFnData = GetCredentialsReturnType
50
+
51
+ export type GetCredentialsData = GetCredentialsQueryFnData
52
+
53
+ export function getCredentialsQueryKey<config extends Config>(
54
+ options: GetCredentialsOptions<config> = {},
55
+ ) {
56
+ return ['ensjs_credentials', filterQueryOptions(options)] as const
57
+ }
58
+
59
+ export type GetCredentialsQueryKey<config extends Config> = ReturnType<
60
+ typeof getCredentialsQueryKey<config>
61
+ >
@@ -0,0 +1,64 @@
1
+ import {
2
+ ASSERT_NO_TYPE_ERROR,
3
+ type ExcludeTE,
4
+ } from '@ensdomains/ensjs/internal'
5
+ import type { QueryOptions } from '@tanstack/query-core'
6
+ import type { Config } from '@wagmi/core'
7
+ import type {
8
+ Compute,
9
+ ExactPartial,
10
+ ScopeKeyParameter,
11
+ } from '@wagmi/core/internal'
12
+ import type { Chain } from 'viem'
13
+ import {
14
+ type GetExpiryErrorType,
15
+ type GetExpiryParameters,
16
+ type GetExpiryReturnType,
17
+ getExpiry,
18
+ } from '../../actions/public/getExpiry.js'
19
+ import type { RequireConfigContracts } from '../../utils/chain.js'
20
+ import { filterQueryOptions } from '../utils.js'
21
+
22
+ export type GetExpiryOptions<config extends Config> = Compute<
23
+ ExactPartial<GetExpiryParameters<config>> & ScopeKeyParameter
24
+ >
25
+
26
+ export function getExpiryQueryOptions<
27
+ chains extends readonly [Chain, ...Chain[]],
28
+ >(
29
+ config: RequireConfigContracts<
30
+ chains,
31
+ 'ensNameWrapper' | 'ensBaseRegistrarImplementation' | 'multicall3'
32
+ >,
33
+ options: GetExpiryOptions<ExcludeTE<typeof config>> = {},
34
+ ) {
35
+ ASSERT_NO_TYPE_ERROR(config)
36
+
37
+ return {
38
+ async queryFn({ queryKey }) {
39
+ const { name, scopeKey: _, ...parameters } = queryKey[1]
40
+ if (!name) throw new Error('name is required')
41
+ return getExpiry<chains>(config, { ...parameters, name })
42
+ },
43
+ queryKey: getExpiryQueryKey(options),
44
+ } as const satisfies QueryOptions<
45
+ GetExpiryQueryFnData,
46
+ GetExpiryErrorType,
47
+ GetExpiryData,
48
+ GetExpiryQueryKey<typeof config>
49
+ >
50
+ }
51
+
52
+ export type GetExpiryQueryFnData = GetExpiryReturnType
53
+
54
+ export type GetExpiryData = GetExpiryQueryFnData
55
+
56
+ export function getExpiryQueryKey<config extends Config>(
57
+ options: GetExpiryOptions<config> = {},
58
+ ) {
59
+ return ['ensjs_expiry', filterQueryOptions(options)] as const
60
+ }
61
+
62
+ export type GetExpiryQueryKey<config extends Config> = ReturnType<
63
+ typeof getExpiryQueryKey<config>
64
+ >
@@ -0,0 +1,61 @@
1
+ import {
2
+ ASSERT_NO_TYPE_ERROR,
3
+ type ExcludeTE,
4
+ } from '@ensdomains/ensjs/internal'
5
+ import type { QueryOptions } from '@tanstack/query-core'
6
+ import type { Config } from '@wagmi/core'
7
+ import type {
8
+ Compute,
9
+ ExactPartial,
10
+ ScopeKeyParameter,
11
+ } from '@wagmi/core/internal'
12
+ import type { Chain } from 'viem'
13
+ import {
14
+ type GetNameErrorType,
15
+ type GetNameParameters,
16
+ type GetNameReturnType,
17
+ getName,
18
+ } from '../../actions/public/getName.js'
19
+ import type { RequireConfigContracts } from '../../utils/chain.js'
20
+ import { filterQueryOptions } from '../utils.js'
21
+
22
+ export type GetNameOptions<config extends Config> = Compute<
23
+ ExactPartial<GetNameParameters<config>> & ScopeKeyParameter
24
+ >
25
+
26
+ export function getNameQueryOptions<
27
+ chains extends readonly [Chain, ...Chain[]],
28
+ >(
29
+ config: RequireConfigContracts<chains, 'ensUniversalResolver'>,
30
+ options: GetNameOptions<ExcludeTE<typeof config>> = {},
31
+ ) {
32
+ ASSERT_NO_TYPE_ERROR(config)
33
+
34
+ return {
35
+ async queryFn({ queryKey }) {
36
+ const { address, scopeKey: _, ...parameters } = queryKey[1]
37
+ if (!address) throw new Error('address is required')
38
+ return getName<chains>(config, { ...parameters, address })
39
+ },
40
+ queryKey: getNameQueryKey(options),
41
+ } as const satisfies QueryOptions<
42
+ GetNameQueryFnData,
43
+ GetNameErrorType,
44
+ GetNameData,
45
+ GetNameQueryKey<typeof config>
46
+ >
47
+ }
48
+
49
+ export type GetNameQueryFnData = GetNameReturnType
50
+
51
+ export type GetNameData = GetNameQueryFnData
52
+
53
+ export function getNameQueryKey<config extends Config>(
54
+ options: GetNameOptions<config> = {},
55
+ ) {
56
+ return ['ensjs_name', filterQueryOptions(options)] as const
57
+ }
58
+
59
+ export type GetNameQueryKey<config extends Config> = ReturnType<
60
+ typeof getNameQueryKey<config>
61
+ >
@@ -0,0 +1,67 @@
1
+ import {
2
+ ASSERT_NO_TYPE_ERROR,
3
+ type ExcludeTE,
4
+ } from '@ensdomains/ensjs/internal'
5
+ import type { QueryOptions } from '@tanstack/query-core'
6
+ import type { Config } from '@wagmi/core'
7
+ import type {
8
+ Compute,
9
+ ExactPartial,
10
+ ScopeKeyParameter,
11
+ } from '@wagmi/core/internal'
12
+ import type { Chain } from 'viem'
13
+ import {
14
+ type GetOwnerErrorType,
15
+ type GetOwnerParameters,
16
+ type GetOwnerReturnType,
17
+ getOwner,
18
+ } from '../../actions/public/getOwner.js'
19
+ import type { RequireConfigContracts } from '../../utils/chain.js'
20
+ import { filterQueryOptions } from '../utils.js'
21
+
22
+ export type GetOwnerOptions<config extends Config> = Compute<
23
+ ExactPartial<GetOwnerParameters<config>> & ScopeKeyParameter
24
+ >
25
+
26
+ export function getOwnerQueryOptions<
27
+ chains extends readonly [Chain, ...Chain[]],
28
+ >(
29
+ config: RequireConfigContracts<
30
+ chains,
31
+ | 'ensNameWrapper'
32
+ | 'ensRegistry'
33
+ | 'ensBaseRegistrarImplementation'
34
+ | 'multicall3'
35
+ >,
36
+ options: GetOwnerOptions<ExcludeTE<typeof config>> = {},
37
+ ) {
38
+ ASSERT_NO_TYPE_ERROR(config)
39
+
40
+ return {
41
+ async queryFn({ queryKey }) {
42
+ const { name, scopeKey: _, ...parameters } = queryKey[1]
43
+ if (!name) throw new Error('name is required')
44
+ return getOwner<chains>(config, { ...parameters, name })
45
+ },
46
+ queryKey: getOwnerQueryKey(options),
47
+ } as const satisfies QueryOptions<
48
+ GetOwnerQueryFnData,
49
+ GetOwnerErrorType,
50
+ GetOwnerData,
51
+ GetOwnerQueryKey<typeof config>
52
+ >
53
+ }
54
+
55
+ export type GetOwnerQueryFnData = GetOwnerReturnType
56
+
57
+ export type GetOwnerData = GetOwnerQueryFnData
58
+
59
+ export function getOwnerQueryKey<config extends Config>(
60
+ options: GetOwnerOptions<config> = {},
61
+ ) {
62
+ return ['ensjs_owner', filterQueryOptions(options)] as const
63
+ }
64
+
65
+ export type GetOwnerQueryKey<config extends Config> = ReturnType<
66
+ typeof getOwnerQueryKey<config>
67
+ >
@@ -0,0 +1,65 @@
1
+ import {
2
+ ASSERT_NO_TYPE_ERROR,
3
+ type ExcludeTE,
4
+ } from '@ensdomains/ensjs/internal'
5
+ import type { QueryOptions } from '@tanstack/query-core'
6
+ import type { Config } from '@wagmi/core'
7
+ import type {
8
+ Compute,
9
+ ExactPartial,
10
+ ScopeKeyParameter,
11
+ } from '@wagmi/core/internal'
12
+ import type { Chain } from 'viem'
13
+ import {
14
+ type GetPriceErrorType,
15
+ type GetPriceParameters,
16
+ type GetPriceReturnType,
17
+ getPrice,
18
+ } from '../../actions/public/getPrice.js'
19
+ import type { RequireConfigContracts } from '../../utils/chain.js'
20
+ import { filterQueryOptions } from '../utils.js'
21
+
22
+ export type GetPriceOptions<config extends Config> = Compute<
23
+ ExactPartial<GetPriceParameters<config>> & ScopeKeyParameter
24
+ >
25
+
26
+ export function getPriceQueryOptions<
27
+ chains extends readonly [Chain, ...Chain[]],
28
+ >(
29
+ config: RequireConfigContracts<
30
+ chains,
31
+ 'ensEthRegistrarController' | 'multicall3'
32
+ >,
33
+ options: GetPriceOptions<ExcludeTE<typeof config>> = {},
34
+ ) {
35
+ ASSERT_NO_TYPE_ERROR(config)
36
+
37
+ return {
38
+ async queryFn({ queryKey }) {
39
+ const { nameOrNames, duration, scopeKey: _, ...parameters } = queryKey[1]
40
+ if (!nameOrNames) throw new Error('nameOrNames is required')
41
+ if (duration === undefined) throw new Error('duration is required')
42
+ return getPrice<chains>(config, { ...parameters, nameOrNames, duration })
43
+ },
44
+ queryKey: getPriceQueryKey(options),
45
+ } as const satisfies QueryOptions<
46
+ GetPriceQueryFnData,
47
+ GetPriceErrorType,
48
+ GetPriceData,
49
+ GetPriceQueryKey<typeof config>
50
+ >
51
+ }
52
+
53
+ export type GetPriceQueryFnData = GetPriceReturnType
54
+
55
+ export type GetPriceData = GetPriceQueryFnData
56
+
57
+ export function getPriceQueryKey<config extends Config>(
58
+ options: GetPriceOptions<config> = {},
59
+ ) {
60
+ return ['ensjs_price', filterQueryOptions(options)] as const
61
+ }
62
+
63
+ export type GetPriceQueryKey<config extends Config> = ReturnType<
64
+ typeof getPriceQueryKey<config>
65
+ >
@@ -0,0 +1,83 @@
1
+ import {
2
+ ASSERT_NO_TYPE_ERROR,
3
+ type ExcludeTE,
4
+ } from '@ensdomains/ensjs/internal'
5
+ import type { QueryOptions } from '@tanstack/query-core'
6
+ import type { Config } from '@wagmi/core'
7
+ import type {
8
+ Compute,
9
+ ExactPartial,
10
+ ScopeKeyParameter,
11
+ } from '@wagmi/core/internal'
12
+ import type { Chain } from 'viem'
13
+ import {
14
+ type GetRecordsErrorType,
15
+ type GetRecordsParameters,
16
+ type GetRecordsReturnType,
17
+ getRecords,
18
+ } from '../../actions/public/getRecords.js'
19
+ import type { RequireConfigContracts } from '../../utils/chain.js'
20
+ import { filterQueryOptions } from '../utils.js'
21
+
22
+ export type GetRecordsOptions<
23
+ config extends Config,
24
+ texts extends readonly string[] | undefined = undefined,
25
+ coins extends readonly (string | number)[] | undefined = undefined,
26
+ contentHash extends boolean | undefined = undefined,
27
+ abi extends boolean | undefined = undefined,
28
+ > = Compute<
29
+ ExactPartial<GetRecordsParameters<config, texts, coins, contentHash, abi>> &
30
+ ScopeKeyParameter
31
+ >
32
+
33
+ export function getRecordsQueryOptions<
34
+ chains extends readonly [Chain, ...Chain[]],
35
+ const texts extends readonly string[] | undefined = undefined,
36
+ const coins extends readonly (string | number)[] | undefined = undefined,
37
+ const contentHash extends boolean | undefined = undefined,
38
+ const abi extends boolean | undefined = undefined,
39
+ >(
40
+ config: RequireConfigContracts<chains, 'ensUniversalResolver' | 'multicall3'>,
41
+ options: GetRecordsOptions<ExcludeTE<typeof config>> = {},
42
+ ) {
43
+ ASSERT_NO_TYPE_ERROR(config)
44
+
45
+ return {
46
+ async queryFn({ queryKey }) {
47
+ const { name, scopeKey: _, ...parameters } = queryKey[1]
48
+ if (!name) throw new Error('name is required')
49
+ return getRecords<chains, texts, coins, contentHash, abi>(config, {
50
+ ...parameters,
51
+ name,
52
+ })
53
+ },
54
+ queryKey: getRecordsQueryKey(options),
55
+ } as const satisfies QueryOptions<
56
+ GetRecordsQueryFnData<texts, coins, contentHash, abi>,
57
+ GetRecordsErrorType,
58
+ GetRecordsData,
59
+ GetRecordsQueryKey<typeof config>
60
+ >
61
+ }
62
+
63
+ export type GetRecordsQueryFnData<
64
+ texts extends readonly string[] | undefined = readonly string[],
65
+ coins extends readonly (string | number)[] | undefined = readonly (
66
+ | string
67
+ | number
68
+ )[],
69
+ contentHash extends boolean | undefined = true,
70
+ abi extends boolean | undefined = true,
71
+ > = GetRecordsReturnType<texts, coins, contentHash, abi>
72
+
73
+ export type GetRecordsData = GetRecordsQueryFnData
74
+
75
+ export function getRecordsQueryKey<config extends Config>(
76
+ options: GetRecordsOptions<config> = {},
77
+ ) {
78
+ return ['ensjs_records', filterQueryOptions(options)] as const
79
+ }
80
+
81
+ export type GetRecordsQueryKey<config extends Config> = ReturnType<
82
+ typeof getRecordsQueryKey<config>
83
+ >
@@ -0,0 +1,61 @@
1
+ import {
2
+ ASSERT_NO_TYPE_ERROR,
3
+ type ExcludeTE,
4
+ } from '@ensdomains/ensjs/internal'
5
+ import type { QueryOptions } from '@tanstack/query-core'
6
+ import type { Config } from '@wagmi/core'
7
+ import type {
8
+ Compute,
9
+ ExactPartial,
10
+ ScopeKeyParameter,
11
+ } from '@wagmi/core/internal'
12
+ import type { Chain } from 'viem'
13
+ import {
14
+ type GetResolverErrorType,
15
+ type GetResolverParameters,
16
+ type GetResolverReturnType,
17
+ getResolver,
18
+ } from '../../actions/public/getResolver.js'
19
+ import type { RequireConfigContracts } from '../../utils/chain.js'
20
+ import { filterQueryOptions } from '../utils.js'
21
+
22
+ export type GetResolverOptions<config extends Config> = Compute<
23
+ ExactPartial<GetResolverParameters<config>> & ScopeKeyParameter
24
+ >
25
+
26
+ export function getResolverQueryOptions<
27
+ chains extends readonly [Chain, ...Chain[]],
28
+ >(
29
+ config: RequireConfigContracts<chains, 'ensRegistry'>,
30
+ options: GetResolverOptions<ExcludeTE<typeof config>> = {},
31
+ ) {
32
+ ASSERT_NO_TYPE_ERROR(config)
33
+
34
+ return {
35
+ async queryFn({ queryKey }) {
36
+ const { name, scopeKey: _, ...parameters } = queryKey[1]
37
+ if (!name) throw new Error('name is required')
38
+ return getResolver<chains>(config, { ...parameters, name })
39
+ },
40
+ queryKey: getResolverQueryKey(options),
41
+ } as const satisfies QueryOptions<
42
+ GetResolverQueryFnData,
43
+ GetResolverErrorType,
44
+ GetResolverData,
45
+ GetResolverQueryKey<typeof config>
46
+ >
47
+ }
48
+
49
+ export type GetResolverQueryFnData = GetResolverReturnType
50
+
51
+ export type GetResolverData = GetResolverQueryFnData
52
+
53
+ export function getResolverQueryKey<config extends Config>(
54
+ options: GetResolverOptions<config> = {},
55
+ ) {
56
+ return ['ensjs_resolver', filterQueryOptions(options)] as const
57
+ }
58
+
59
+ export type GetResolverQueryKey<config extends Config> = ReturnType<
60
+ typeof getResolverQueryKey<config>
61
+ >
@@ -0,0 +1,80 @@
1
+ import {
2
+ ASSERT_NO_TYPE_ERROR,
3
+ type ExcludeTE,
4
+ } from '@ensdomains/ensjs/internal'
5
+ import type { QueryOptions } from '@tanstack/query-core'
6
+ import type { Config } from '@wagmi/core'
7
+ import type {
8
+ Compute,
9
+ ExactPartial,
10
+ ScopeKeyParameter,
11
+ } from '@wagmi/core/internal'
12
+ import type { Chain, Hex } from 'viem'
13
+ import {
14
+ type GetSupportedInterfacesErrorType,
15
+ type GetSupportedInterfacesParameters,
16
+ type GetSupportedInterfacesReturnType,
17
+ getSupportedInterfaces,
18
+ } from '../../actions/public/getSupportedInterfaces.js'
19
+ import type { RequireConfigContracts } from '../../utils/chain.js'
20
+ import { filterQueryOptions } from '../utils.js'
21
+
22
+ export type GetSupportedInterfacesOptions<
23
+ config extends Config,
24
+ interfaces extends readonly Hex[] = readonly Hex[],
25
+ > = Compute<
26
+ ExactPartial<GetSupportedInterfacesParameters<config, interfaces>> &
27
+ ScopeKeyParameter
28
+ >
29
+
30
+ export function getSupportedInterfacesQueryOptions<
31
+ chains extends readonly [Chain, ...Chain[]],
32
+ const interfaces extends readonly Hex[],
33
+ >(
34
+ config: RequireConfigContracts<chains, 'multicall3'>,
35
+ options: GetSupportedInterfacesOptions<
36
+ ExcludeTE<typeof config>,
37
+ interfaces
38
+ > = {},
39
+ ) {
40
+ ASSERT_NO_TYPE_ERROR(config)
41
+
42
+ return {
43
+ async queryFn({ queryKey }) {
44
+ const { address, interfaces, scopeKey: _, ...parameters } = queryKey[1]
45
+ if (!address) throw new Error('address is required')
46
+ if (!interfaces) throw new Error('interfaces is required')
47
+ return getSupportedInterfaces<chains, interfaces>(config, {
48
+ ...parameters,
49
+ address,
50
+ interfaces,
51
+ })
52
+ },
53
+ queryKey: getSupportedInterfacesQueryKey(options),
54
+ } as const satisfies QueryOptions<
55
+ GetSupportedInterfacesQueryFnData<interfaces>,
56
+ GetSupportedInterfacesErrorType,
57
+ GetSupportedInterfacesData<interfaces>,
58
+ GetSupportedInterfacesQueryKey<typeof config, interfaces>
59
+ >
60
+ }
61
+
62
+ export type GetSupportedInterfacesQueryFnData<
63
+ interfaces extends readonly Hex[] = readonly Hex[],
64
+ > = GetSupportedInterfacesReturnType<interfaces>
65
+
66
+ export type GetSupportedInterfacesData<
67
+ interfaces extends readonly Hex[] = readonly Hex[],
68
+ > = GetSupportedInterfacesQueryFnData<interfaces>
69
+
70
+ export function getSupportedInterfacesQueryKey<
71
+ config extends Config,
72
+ interfaces extends readonly Hex[] = readonly Hex[],
73
+ >(options: GetSupportedInterfacesOptions<config, interfaces> = {}) {
74
+ return ['ensjs_supportedInterfaces', filterQueryOptions(options)] as const
75
+ }
76
+
77
+ export type GetSupportedInterfacesQueryKey<
78
+ config extends Config,
79
+ interfaces extends readonly Hex[] = readonly Hex[],
80
+ > = ReturnType<typeof getSupportedInterfacesQueryKey<config, interfaces>>