@ensdomains/ensjs 3.0.0-beta.1 → 3.0.0-beta.2

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 (248) hide show
  1. package/dist/cjs/clients/decorators/subgraph.js.map +1 -1
  2. package/dist/cjs/contracts/consts.js +6 -0
  3. package/dist/cjs/contracts/consts.js.map +1 -1
  4. package/dist/cjs/dns.js +3 -3
  5. package/dist/cjs/dns.js.map +1 -1
  6. package/dist/cjs/errors/subgraph.js.map +1 -1
  7. package/dist/cjs/errors/utils.js +15 -18
  8. package/dist/cjs/errors/utils.js.map +1 -1
  9. package/dist/cjs/errors/version.js +1 -1
  10. package/dist/cjs/errors/version.js.map +1 -1
  11. package/dist/cjs/functions/dns/{prepareDnsImport.js → getDnsImportData.js} +3 -3
  12. package/dist/cjs/functions/dns/{prepareDnsImport.js.map → getDnsImportData.js.map} +1 -1
  13. package/dist/cjs/functions/dns/importDnsName.js +7 -7
  14. package/dist/cjs/functions/dns/importDnsName.js.map +1 -1
  15. package/dist/cjs/functions/public/_getContentHash.js +1 -1
  16. package/dist/cjs/functions/public/getSupportedInterfaces.js +1 -1
  17. package/dist/cjs/functions/public/getSupportedInterfaces.js.map +1 -1
  18. package/dist/cjs/functions/public/getWrapperData.js.map +1 -1
  19. package/dist/cjs/functions/subgraph/filters.js +3 -0
  20. package/dist/cjs/functions/subgraph/filters.js.map +1 -0
  21. package/dist/cjs/functions/subgraph/getNameHistory.js +1 -1
  22. package/dist/cjs/functions/subgraph/getNamesForAddress.js +140 -182
  23. package/dist/cjs/functions/subgraph/getNamesForAddress.js.map +1 -1
  24. package/dist/cjs/functions/subgraph/getSubnames.js +95 -108
  25. package/dist/cjs/functions/subgraph/getSubnames.js.map +1 -1
  26. package/dist/cjs/functions/subgraph/types.js +3 -0
  27. package/dist/cjs/functions/subgraph/types.js.map +1 -0
  28. package/dist/cjs/functions/subgraph/utils.js.map +1 -1
  29. package/dist/cjs/functions/wallet/createSubname.js +1 -1
  30. package/dist/cjs/functions/wallet/createSubname.js.map +1 -1
  31. package/dist/cjs/functions/wallet/setChildFuses.js +1 -1
  32. package/dist/cjs/functions/wallet/setChildFuses.js.map +1 -1
  33. package/dist/cjs/functions/wallet/setFuses.js +1 -1
  34. package/dist/cjs/functions/wallet/setFuses.js.map +1 -1
  35. package/dist/cjs/functions/wallet/wrapName.js +3 -1
  36. package/dist/cjs/functions/wallet/wrapName.js.map +1 -1
  37. package/dist/cjs/index.js +1 -2
  38. package/dist/cjs/index.js.map +1 -1
  39. package/dist/cjs/utils/contentHash.js +54 -131
  40. package/dist/cjs/utils/contentHash.js.map +1 -1
  41. package/dist/cjs/utils/encoders/encodeSetContentHash.js +1 -4
  42. package/dist/cjs/utils/encoders/encodeSetContentHash.js.map +1 -1
  43. package/dist/cjs/utils/format.js +1 -5
  44. package/dist/cjs/utils/format.js.map +1 -1
  45. package/dist/cjs/utils/fuses.js +181 -200
  46. package/dist/cjs/utils/fuses.js.map +1 -1
  47. package/dist/cjs/utils/index.js +4 -7
  48. package/dist/cjs/utils/index.js.map +1 -1
  49. package/dist/cjs/utils/registerHelpers.js +3 -1
  50. package/dist/cjs/utils/registerHelpers.js.map +1 -1
  51. package/dist/esm/clients/decorators/subgraph.js.map +1 -1
  52. package/dist/esm/contracts/consts.js +6 -0
  53. package/dist/esm/contracts/consts.js.map +1 -1
  54. package/dist/esm/dns.js +1 -1
  55. package/dist/esm/dns.js.map +1 -1
  56. package/dist/esm/errors/subgraph.js.map +1 -1
  57. package/dist/esm/errors/utils.js +13 -16
  58. package/dist/esm/errors/utils.js.map +1 -1
  59. package/dist/esm/errors/version.js +1 -1
  60. package/dist/esm/errors/version.js.map +1 -1
  61. package/dist/esm/functions/dns/{prepareDnsImport.js → getDnsImportData.js} +9 -10
  62. package/dist/esm/functions/dns/getDnsImportData.js.map +1 -0
  63. package/dist/esm/functions/dns/importDnsName.js +12 -12
  64. package/dist/esm/functions/dns/importDnsName.js.map +1 -1
  65. package/dist/esm/functions/public/_getContentHash.js +2 -2
  66. package/dist/esm/functions/public/getSupportedInterfaces.js +2 -2
  67. package/dist/esm/functions/public/getSupportedInterfaces.js.map +1 -1
  68. package/dist/esm/functions/public/getWrapperData.js.map +1 -1
  69. package/dist/esm/functions/subgraph/filters.js +2 -0
  70. package/dist/esm/functions/subgraph/filters.js.map +1 -0
  71. package/dist/esm/functions/subgraph/getNameHistory.js +2 -2
  72. package/dist/esm/functions/subgraph/getNamesForAddress.js +144 -183
  73. package/dist/esm/functions/subgraph/getNamesForAddress.js.map +1 -1
  74. package/dist/esm/functions/subgraph/getSubnames.js +101 -111
  75. package/dist/esm/functions/subgraph/getSubnames.js.map +1 -1
  76. package/dist/esm/functions/subgraph/types.js +2 -0
  77. package/dist/esm/functions/subgraph/types.js.map +1 -0
  78. package/dist/esm/functions/subgraph/utils.js.map +1 -1
  79. package/dist/esm/functions/wallet/createSubname.js +1 -1
  80. package/dist/esm/functions/wallet/createSubname.js.map +1 -1
  81. package/dist/esm/functions/wallet/setChildFuses.js +1 -1
  82. package/dist/esm/functions/wallet/setChildFuses.js.map +1 -1
  83. package/dist/esm/functions/wallet/setFuses.js +2 -2
  84. package/dist/esm/functions/wallet/setFuses.js.map +1 -1
  85. package/dist/esm/functions/wallet/wrapName.js +4 -2
  86. package/dist/esm/functions/wallet/wrapName.js.map +1 -1
  87. package/dist/esm/index.js +1 -1
  88. package/dist/esm/index.js.map +1 -1
  89. package/dist/esm/utils/contentHash.js +51 -128
  90. package/dist/esm/utils/contentHash.js.map +1 -1
  91. package/dist/esm/utils/encoders/encodeSetContentHash.js +2 -5
  92. package/dist/esm/utils/encoders/encodeSetContentHash.js.map +1 -1
  93. package/dist/esm/utils/format.js +0 -2
  94. package/dist/esm/utils/format.js.map +1 -1
  95. package/dist/esm/utils/fuses.js +180 -201
  96. package/dist/esm/utils/fuses.js.map +1 -1
  97. package/dist/esm/utils/index.js +2 -2
  98. package/dist/esm/utils/index.js.map +1 -1
  99. package/dist/esm/utils/registerHelpers.js +4 -2
  100. package/dist/esm/utils/registerHelpers.js.map +1 -1
  101. package/dist/types/clients/decorators/subgraph.d.ts +1 -1
  102. package/dist/types/clients/decorators/subgraph.d.ts.map +1 -1
  103. package/dist/types/clients/public.d.ts +1 -1
  104. package/dist/types/clients/subgraph.d.ts +1 -1
  105. package/dist/types/clients/wallet.d.ts +31 -67
  106. package/dist/types/clients/wallet.d.ts.map +1 -1
  107. package/dist/types/contracts/consts.d.ts +6 -0
  108. package/dist/types/contracts/consts.d.ts.map +1 -1
  109. package/dist/types/dns.d.ts +1 -1
  110. package/dist/types/dns.d.ts.map +1 -1
  111. package/dist/types/errors/subgraph.d.ts +4 -4
  112. package/dist/types/errors/subgraph.d.ts.map +1 -1
  113. package/dist/types/errors/utils.d.ts +10 -13
  114. package/dist/types/errors/utils.d.ts.map +1 -1
  115. package/dist/types/errors/version.d.ts +1 -1
  116. package/dist/types/errors/version.d.ts.map +1 -1
  117. package/dist/types/functions/dns/{prepareDnsImport.d.ts → getDnsImportData.d.ts} +11 -12
  118. package/dist/types/functions/dns/{prepareDnsImport.d.ts.map → getDnsImportData.d.ts.map} +1 -1
  119. package/dist/types/functions/dns/importDnsName.d.ts +12 -12
  120. package/dist/types/functions/dns/importDnsName.d.ts.map +1 -1
  121. package/dist/types/functions/public/getSupportedInterfaces.d.ts +19 -4
  122. package/dist/types/functions/public/getSupportedInterfaces.d.ts.map +1 -1
  123. package/dist/types/functions/public/getWrapperData.d.ts +2 -2
  124. package/dist/types/functions/public/getWrapperData.d.ts.map +1 -1
  125. package/dist/types/functions/subgraph/filters.d.ts +693 -0
  126. package/dist/types/functions/subgraph/filters.d.ts.map +1 -0
  127. package/dist/types/functions/subgraph/getNamesForAddress.d.ts +2 -0
  128. package/dist/types/functions/subgraph/getNamesForAddress.d.ts.map +1 -1
  129. package/dist/types/functions/subgraph/getSubnames.d.ts +3 -1
  130. package/dist/types/functions/subgraph/getSubnames.d.ts.map +1 -1
  131. package/dist/types/functions/subgraph/types.d.ts +13 -0
  132. package/dist/types/functions/subgraph/types.d.ts.map +1 -0
  133. package/dist/types/functions/subgraph/utils.d.ts +2 -2
  134. package/dist/types/functions/subgraph/utils.d.ts.map +1 -1
  135. package/dist/types/functions/wallet/commitName.d.ts +1 -1
  136. package/dist/types/functions/wallet/createSubname.d.ts +4 -4
  137. package/dist/types/functions/wallet/createSubname.d.ts.map +1 -1
  138. package/dist/types/functions/wallet/deleteSubname.d.ts +1 -1
  139. package/dist/types/functions/wallet/setAbiRecord.d.ts +1 -1
  140. package/dist/types/functions/wallet/setAddressRecord.d.ts +1 -1
  141. package/dist/types/functions/wallet/setChildFuses.d.ts +3 -3
  142. package/dist/types/functions/wallet/setChildFuses.d.ts.map +1 -1
  143. package/dist/types/functions/wallet/setContentHashRecord.d.ts +1 -1
  144. package/dist/types/functions/wallet/setFuses.d.ts +3 -3
  145. package/dist/types/functions/wallet/setFuses.d.ts.map +1 -1
  146. package/dist/types/functions/wallet/setPrimaryName.d.ts +1 -1
  147. package/dist/types/functions/wallet/setRecords.d.ts +1 -1
  148. package/dist/types/functions/wallet/setResolver.d.ts +1 -1
  149. package/dist/types/functions/wallet/setTextRecord.d.ts +1 -1
  150. package/dist/types/functions/wallet/transferName.d.ts +1 -1
  151. package/dist/types/functions/wallet/unwrapName.d.ts +1 -1
  152. package/dist/types/functions/wallet/wrapName.d.ts +3 -3
  153. package/dist/types/functions/wallet/wrapName.d.ts.map +1 -1
  154. package/dist/types/index.d.ts +1 -1
  155. package/dist/types/index.d.ts.map +1 -1
  156. package/dist/types/utils/contentHash.d.ts +7 -11
  157. package/dist/types/utils/contentHash.d.ts.map +1 -1
  158. package/dist/types/utils/encoders/encodeSetContentHash.d.ts.map +1 -1
  159. package/dist/types/utils/format.d.ts +0 -2
  160. package/dist/types/utils/format.d.ts.map +1 -1
  161. package/dist/types/utils/fuses.d.ts +164 -125
  162. package/dist/types/utils/fuses.d.ts.map +1 -1
  163. package/dist/types/utils/index.d.ts +2 -2
  164. package/dist/types/utils/index.d.ts.map +1 -1
  165. package/dist/types/utils/registerHelpers.d.ts +2 -2
  166. package/dist/types/utils/registerHelpers.d.ts.map +1 -1
  167. package/package.json +4 -3
  168. package/src/clients/decorators/subgraph.ts +1 -0
  169. package/src/contracts/consts.ts +6 -0
  170. package/src/dns.ts +5 -5
  171. package/src/errors/subgraph.ts +4 -4
  172. package/src/errors/utils.ts +21 -18
  173. package/src/errors/version.ts +1 -1
  174. package/src/functions/dns/{prepareDnsImport.ts → getDnsImportData.ts} +12 -13
  175. package/src/functions/dns/importDnsName.ts +20 -15
  176. package/src/functions/public/_getContentHash.ts +2 -2
  177. package/src/functions/public/getSupportedInterfaces.ts +48 -10
  178. package/src/functions/public/getWrapperData.ts +2 -2
  179. package/src/functions/subgraph/filters.ts +702 -0
  180. package/src/functions/subgraph/getNameHistory.ts +2 -2
  181. package/src/functions/subgraph/getNamesForAddress.ts +170 -186
  182. package/src/functions/subgraph/getSubnames.ts +121 -113
  183. package/src/functions/subgraph/types.ts +13 -0
  184. package/src/functions/subgraph/utils.ts +2 -2
  185. package/src/functions/wallet/createSubname.ts +4 -4
  186. package/src/functions/wallet/setChildFuses.ts +3 -3
  187. package/src/functions/wallet/setFuses.ts +6 -3
  188. package/src/functions/wallet/wrapName.ts +8 -3
  189. package/src/index.ts +0 -1
  190. package/src/utils/contentHash.ts +59 -113
  191. package/src/utils/encoders/encodeSetContentHash.ts +2 -4
  192. package/src/utils/format.ts +0 -6
  193. package/src/utils/fuses.ts +308 -308
  194. package/src/utils/index.ts +4 -5
  195. package/src/utils/registerHelpers.ts +5 -3
  196. package/dist/esm/functions/dns/prepareDnsImport.js.map +0 -1
  197. package/src/@types/@ensdomains/content-hash.d.ts +0 -1
  198. package/src/functions/dns/getDnsOwner.test.ts +0 -195
  199. package/src/functions/dns/importDnsName.test.ts +0 -117
  200. package/src/functions/dns/prepareDnsImport.test.ts +0 -115
  201. package/src/functions/public/batch.test.ts +0 -67
  202. package/src/functions/public/ccip.test.ts +0 -78
  203. package/src/functions/public/getAbiRecord.test.ts +0 -174
  204. package/src/functions/public/getAddressRecord.test.ts +0 -83
  205. package/src/functions/public/getAvailable.test.ts +0 -17
  206. package/src/functions/public/getContentHashRecord.test.ts +0 -28
  207. package/src/functions/public/getExpiry.test.ts +0 -48
  208. package/src/functions/public/getName.test.ts +0 -66
  209. package/src/functions/public/getOwner.test.ts +0 -87
  210. package/src/functions/public/getPrice.test.ts +0 -45
  211. package/src/functions/public/getRecords.test.ts +0 -49
  212. package/src/functions/public/getResolver.test.ts +0 -12
  213. package/src/functions/public/getTextRecord.test.ts +0 -20
  214. package/src/functions/public/getWrapperData.test.ts +0 -79
  215. package/src/functions/public/getWrapperName.test.ts +0 -19
  216. package/src/functions/subgraph/client.test.ts +0 -170
  217. package/src/functions/subgraph/getDecodedName.test.ts +0 -31
  218. package/src/functions/subgraph/getNameHistory.test.ts +0 -39
  219. package/src/functions/subgraph/getNamesForAddress.test.ts +0 -244
  220. package/src/functions/subgraph/getSubgraphRecords.test.ts +0 -74
  221. package/src/functions/subgraph/getSubgraphRegistrant.test.ts +0 -34
  222. package/src/functions/subgraph/getSubnames.test.ts +0 -202
  223. package/src/functions/wallet/commitName.test.ts +0 -58
  224. package/src/functions/wallet/createSubname.test.ts +0 -73
  225. package/src/functions/wallet/deleteSubname.test.ts +0 -150
  226. package/src/functions/wallet/registerName.test.ts +0 -81
  227. package/src/functions/wallet/renewNames.test.ts +0 -92
  228. package/src/functions/wallet/setAbiRecord.test.ts +0 -156
  229. package/src/functions/wallet/setAddressRecord.test.ts +0 -121
  230. package/src/functions/wallet/setChildFuses.test.ts +0 -97
  231. package/src/functions/wallet/setContentHashRecord.test.ts +0 -69
  232. package/src/functions/wallet/setFuses.test.ts +0 -287
  233. package/src/functions/wallet/setPrimaryName.test.ts +0 -71
  234. package/src/functions/wallet/setRecords.test.ts +0 -127
  235. package/src/functions/wallet/setResolver.test.ts +0 -114
  236. package/src/functions/wallet/setTextRecord.test.ts +0 -67
  237. package/src/functions/wallet/transferName.test.ts +0 -201
  238. package/src/functions/wallet/unwrapName.test.ts +0 -93
  239. package/src/functions/wallet/wrapName.test.ts +0 -195
  240. package/src/utils/generateRecordCallArray.test.ts +0 -84
  241. package/src/utils/labels.test.ts +0 -163
  242. package/src/utils/makeLabelNodeAndParent.test.ts +0 -11
  243. package/src/utils/makeSafeSecondsDate.test.ts +0 -14
  244. package/src/utils/normalise.test.ts +0 -35
  245. package/src/utils/ownerFromContract.test.ts +0 -52
  246. package/src/utils/registerHelpers.test.ts +0 -159
  247. package/src/utils/validation.test.ts +0 -170
  248. package/src/utils/wrapper.test.ts +0 -46
@@ -1,7 +1,7 @@
1
1
  import { formatsByCoinType } from '@ensdomains/address-encoder'
2
2
  import { gql } from 'graphql-request'
3
3
  import type { ClientWithEns } from '../../contracts/consts.js'
4
- import { decodeContenthash } from '../../utils/contentHash.js'
4
+ import { decodeContentHash } from '../../utils/contentHash.js'
5
5
  import { namehash } from '../../utils/normalise.js'
6
6
  import { createSubgraphClient } from './client.js'
7
7
  import type {
@@ -300,7 +300,7 @@ const getNameHistory = async (
300
300
  }
301
301
  }
302
302
  case 'ContenthashChanged': {
303
- const { decoded: contentHash, protocolType } = decodeContenthash(
303
+ const { decoded: contentHash, protocolType } = decodeContentHash(
304
304
  event.hash,
305
305
  ) || { protocolType: null, decoded: null }
306
306
  return {
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/naming-convention */
1
2
  import { gql } from 'graphql-request'
2
3
  import type { Address } from 'viem'
3
4
  import type { ClientWithEns } from '../../contracts/consts.js'
@@ -6,8 +7,9 @@ import {
6
7
  InvalidFilterKeyError,
7
8
  InvalidOrderByError,
8
9
  } from '../../errors/subgraph.js'
9
- import { GRACE_PERIOD_SECONDS } from '../../utils/consts.js'
10
+ import { EMPTY_ADDRESS, GRACE_PERIOD_SECONDS } from '../../utils/consts.js'
10
11
  import { createSubgraphClient } from './client.js'
12
+ import type { DomainFilter } from './filters.js'
11
13
  import {
12
14
  domainDetailsFragment,
13
15
  registrationDetailsFragment,
@@ -16,6 +18,13 @@ import {
16
18
  } from './fragments.js'
17
19
  import { makeNameObject, type Name } from './utils.js'
18
20
 
21
+ const supportedOwnerFilters = [
22
+ 'owner',
23
+ 'registrant',
24
+ 'wrappedOwner',
25
+ 'resolvedAddress',
26
+ ] as const
27
+
19
28
  type GetNamesForAddressOrderBy =
20
29
  | 'expiryDate'
21
30
  | 'name'
@@ -38,6 +47,8 @@ type GetNamesForAddressFilter = GetNamesForAddressRelation & {
38
47
  allowExpired?: boolean
39
48
  /** Allows reverse record nodes to be included (default: false) */
40
49
  allowReverseRecord?: boolean
50
+ /** Allows deleted names to be included (default: false) */
51
+ allowDeleted?: boolean
41
52
  }
42
53
 
43
54
  export type GetNamesForAddressParameters = {
@@ -65,6 +76,70 @@ type SubgraphResult = {
65
76
  domains: SubgraphDomain[]
66
77
  }
67
78
 
79
+ const getOrderByFilter = ({
80
+ orderBy,
81
+ orderDirection,
82
+ previousPage,
83
+ }: Required<
84
+ Pick<
85
+ GetNamesForAddressParameters,
86
+ 'orderBy' | 'orderDirection' | 'previousPage'
87
+ >
88
+ >): DomainFilter => {
89
+ const lastDomain = previousPage[previousPage.length - 1]
90
+ const operator = orderDirection === 'asc' ? 'gt' : 'lt'
91
+
92
+ switch (orderBy) {
93
+ case 'expiryDate': {
94
+ let lastExpiryDate = lastDomain.expiryDate?.value
95
+ ? lastDomain.expiryDate.value / 1000
96
+ : 0
97
+ if (lastDomain.parentName === 'eth') {
98
+ lastExpiryDate += GRACE_PERIOD_SECONDS
99
+ }
100
+
101
+ if (orderDirection === 'asc' && lastExpiryDate === 0) {
102
+ return {
103
+ and: [{ expiryDate: null }, { [`id_${operator}`]: lastDomain.id }],
104
+ }
105
+ }
106
+ if (orderDirection === 'desc' && lastExpiryDate !== 0) {
107
+ return {
108
+ [`expiryDate_${operator}`]: `${lastExpiryDate}`,
109
+ }
110
+ }
111
+ return {
112
+ or: [
113
+ {
114
+ [`expiryDate_${operator}`]: `${lastExpiryDate}`,
115
+ },
116
+ { expiryDate: null },
117
+ ],
118
+ }
119
+ }
120
+ case 'name': {
121
+ return {
122
+ [`name_${operator}`]: lastDomain.name ?? '',
123
+ }
124
+ }
125
+ case 'labelName': {
126
+ return {
127
+ [`labelName_${operator}`]: lastDomain.labelName ?? '',
128
+ }
129
+ }
130
+ case 'createdAt': {
131
+ return {
132
+ [`createdAt_${operator}`]: `${lastDomain.createdAt.value / 1000}`,
133
+ }
134
+ }
135
+ default:
136
+ throw new InvalidOrderByError({
137
+ orderBy: orderBy || '<no orderBy provided>',
138
+ supportedOrderBys: ['expiryDate', 'name', 'labelName', 'createdAt'],
139
+ })
140
+ }
141
+ }
142
+
68
143
  /**
69
144
  * Gets the names for an address from the subgraph.
70
145
  * @param client - {@link ClientWithEns}
@@ -92,6 +167,7 @@ const getNamesForAddress = async (
92
167
  resolvedAddress: true,
93
168
  wrappedOwner: true,
94
169
  allowExpired: false,
170
+ allowDeleted: false,
95
171
  allowReverseRecord: false,
96
172
  },
97
173
  orderBy = 'name',
@@ -102,231 +178,139 @@ const getNamesForAddress = async (
102
178
  ): Promise<GetNamesForAddressReturnType> => {
103
179
  const subgraphClient = createSubgraphClient({ client })
104
180
 
105
- let ownerWhereFilter = `
106
- or: [
107
- `
108
- let hasFilterApplied = false
109
- const { allowExpired, allowReverseRecord, ...filters } = filter
110
- for (const [key, value] of Object.entries(filters)) {
111
- if (value) {
112
- hasFilterApplied = true
113
- switch (key) {
114
- case 'owner': {
115
- ownerWhereFilter += `
116
- { owner: $address }
117
- `
118
- break
119
- }
120
- case 'registrant': {
121
- ownerWhereFilter += `
122
- { registrant: $address }
123
- `
124
- break
125
- }
126
- case 'wrappedOwner': {
127
- ownerWhereFilter += `
128
- { wrappedOwner: $address }
129
- `
130
- break
131
- }
132
- case 'resolvedAddress': {
133
- ownerWhereFilter += `
134
- { resolvedAddress: $address }
135
- `
136
- break
137
- }
138
- default:
181
+ const { allowExpired, allowDeleted, allowReverseRecord, ...filters } = filter
182
+ const ownerWhereFilters: DomainFilter[] = Object.entries(filters).reduce(
183
+ (prev, [key, value]) => {
184
+ if (value) {
185
+ if (!supportedOwnerFilters.includes(key as any))
139
186
  throw new InvalidFilterKeyError({
140
187
  filterKey: key,
141
- supportedFilterKeys: [
142
- 'owner',
143
- 'registrant',
144
- 'wrappedOwner',
145
- 'resolvedAddress',
146
- ],
188
+ supportedFilterKeys: supportedOwnerFilters,
147
189
  })
190
+ return [
191
+ ...prev,
192
+ {
193
+ [key]: address.toLowerCase(),
194
+ },
195
+ ]
148
196
  }
149
- }
150
- }
197
+ return prev
198
+ },
199
+ [] as DomainFilter[],
200
+ )
201
+
202
+ const hasFilterApplied = ownerWhereFilters.length > 0
151
203
 
152
204
  if (!hasFilterApplied)
153
205
  throw new FilterKeyRequiredError({
154
- supportedFilterKeys: [
155
- 'owner',
156
- 'registrant',
157
- 'wrappedOwner',
158
- 'resolvedAddress',
159
- ],
206
+ supportedFilterKeys: supportedOwnerFilters,
160
207
  details: 'At least one ownership filter must be enabled',
161
208
  })
162
209
 
163
- ownerWhereFilter += `
164
- ]
165
- `
166
-
167
- const whereFilters = [ownerWhereFilter]
168
-
169
- let orderByFilter = ''
170
- let orderByStringVar = ''
210
+ const ownerWhereFilter: DomainFilter =
211
+ ownerWhereFilters.length > 1
212
+ ? { or: ownerWhereFilters }
213
+ : ownerWhereFilters[0]
214
+ const whereFilters: DomainFilter[] = [ownerWhereFilter]
171
215
 
172
- if (previousPage && previousPage.length > 0) {
173
- const lastDomain = previousPage[previousPage.length - 1]
174
- const operator = orderDirection === 'asc' ? 'gt' : 'lt'
175
- switch (orderBy) {
176
- case 'expiryDate': {
177
- let lastExpiryDate = lastDomain.expiryDate?.value
178
- ? lastDomain.expiryDate.value / 1000
179
- : 0
180
- if (lastDomain.parentName === 'eth') {
181
- lastExpiryDate += GRACE_PERIOD_SECONDS
182
- }
183
- if (orderDirection === 'asc' && lastExpiryDate === 0) {
184
- orderByFilter = `
185
- {
186
- and: [
187
- { expiryDate: null }
188
- { id_${operator}: "${lastDomain.id}" }
189
- ]
190
- }
191
- `
192
- } else if (orderDirection === 'desc' && lastExpiryDate !== 0) {
193
- orderByFilter = `
194
- {
195
- expiryDate_${operator}: ${lastExpiryDate}
196
- }
197
- `
198
- } else {
199
- orderByFilter = `
200
- {
201
- or: [
202
- {
203
- expiryDate_${operator}: ${lastExpiryDate}
204
- }
205
- { expiryDate: null }
206
- ]
207
- }
208
- `
209
- }
210
- break
211
- }
212
- case 'name': {
213
- orderByFilter = `
214
- {
215
- name_${operator}: $orderByStringVar
216
- }
217
- `
218
- orderByStringVar = lastDomain.name ?? ''
219
- break
220
- }
221
- case 'labelName': {
222
- orderByFilter = `
223
- {
224
- labelName_${operator}: $orderByStringVar
225
- }
226
- `
227
- orderByStringVar = lastDomain.labelName ?? ''
228
- break
229
- }
230
- case 'createdAt': {
231
- orderByFilter = `
232
- {
233
- createdAt_${operator}: ${lastDomain.createdAt.value / 1000}
234
- }
235
- `
236
- break
237
- }
238
- default:
239
- throw new InvalidOrderByError({
240
- orderBy,
241
- supportedOrderBys: ['expiryDate', 'name', 'labelName', 'createdAt'],
242
- })
243
- }
244
- whereFilters.push(orderByFilter)
216
+ if (previousPage?.length) {
217
+ whereFilters.push(
218
+ getOrderByFilter({
219
+ orderBy,
220
+ orderDirection,
221
+ previousPage,
222
+ }),
223
+ )
245
224
  }
246
225
 
247
226
  if (!allowReverseRecord) {
248
227
  // Exclude domains with parent addr.reverse
249
228
  // namehash of addr.reverse = 0x91d1777781884d03a6757a803996e38de2a42967fb37eeaca72729271025a9e2
250
- whereFilters.push(`
251
- {
252
- parent_not: "0x91d1777781884d03a6757a803996e38de2a42967fb37eeaca72729271025a9e2"
253
- }
254
- `)
229
+ whereFilters.push({
230
+ parent_not:
231
+ '0x91d1777781884d03a6757a803996e38de2a42967fb37eeaca72729271025a9e2',
232
+ })
255
233
  }
256
234
 
257
235
  if (!allowExpired) {
258
236
  // Exclude domains that are expired
259
237
  // if expiryDate is null, there is no expiry on the domain (registration or wrapped)
260
- whereFilters.push(`
261
- {
262
- or: [
263
- { expiryDate_gt: $expiryDate }
264
- { expiryDate: null }
265
- ]
266
- }
267
- `)
238
+ whereFilters.push({
239
+ or: [
240
+ { expiryDate_gt: `${Math.floor(Date.now() / 1000)}` },
241
+ { expiryDate: null },
242
+ ],
243
+ })
268
244
  }
269
245
 
270
- const whereFilter =
271
- whereFilters.length > 1
272
- ? `
273
- and: [
274
- {
275
- ${whereFilters.shift()}
276
- }
277
- ${whereFilters.join('\n')}
278
- ]
279
- `
280
- : whereFilters[0]
246
+ if (!allowDeleted) {
247
+ // exclude "deleted" domains
248
+ // when owner/resolver/registrant = null
249
+ whereFilters.push({
250
+ or: [
251
+ {
252
+ owner_not: EMPTY_ADDRESS,
253
+ },
254
+ {
255
+ resolver_not: null,
256
+ },
257
+ {
258
+ and: [
259
+ {
260
+ registrant_not: EMPTY_ADDRESS,
261
+ },
262
+ {
263
+ registrant_not: null,
264
+ },
265
+ ],
266
+ },
267
+ ],
268
+ })
269
+ }
270
+
271
+ const whereFilter: DomainFilter =
272
+ whereFilters.length > 1 ? { and: whereFilters } : whereFilters[0]
281
273
 
282
274
  const query = gql`
283
- query getNamesForAddress(
284
- $address: String!
285
- $orderBy: Domain_orderBy
286
- $orderDirection: OrderDirection
287
- $first: Int
288
- $expiryDate: Int
289
- $orderByStringVar: String
275
+ query getNamesForAddress(
276
+ $orderBy: Domain_orderBy
277
+ $orderDirection: OrderDirection
278
+ $first: Int
279
+ $whereFilter: Domain_filter
280
+ ) {
281
+ domains(
282
+ orderBy: $orderBy
283
+ orderDirection: $orderDirection
284
+ first: $first
285
+ where: $whereFilter
290
286
  ) {
291
- domains(
292
- orderBy: $orderBy
293
- orderDirection: $orderDirection
294
- first: $first
295
- where: {
296
- ${whereFilter}
297
- }
298
- ) {
299
- ...DomainDetails
300
- registration {
301
- ...RegistrationDetails
302
- }
303
- wrappedDomain {
304
- ...WrappedDomainDetails
305
- }
287
+ ...DomainDetails
288
+ registration {
289
+ ...RegistrationDetails
290
+ }
291
+ wrappedDomain {
292
+ ...WrappedDomainDetails
306
293
  }
307
294
  }
308
- ${domainDetailsFragment}
309
- ${registrationDetailsFragment}
310
- ${wrappedDomainDetailsFragment}
311
- `
295
+ }
296
+ ${domainDetailsFragment}
297
+ ${registrationDetailsFragment}
298
+ ${wrappedDomainDetailsFragment}
299
+ `
312
300
 
313
301
  const result = await subgraphClient.request<
314
302
  SubgraphResult,
315
303
  {
316
- address: string
317
304
  orderBy: string
318
305
  orderDirection: string
319
306
  first: number
320
- expiryDate: number
321
- orderByStringVar: string
307
+ whereFilter: DomainFilter
322
308
  }
323
309
  >(query, {
324
- address: address.toLowerCase(),
325
310
  orderBy,
326
311
  orderDirection,
327
312
  first: pageSize,
328
- expiryDate: Math.floor(Date.now() / 1000),
329
- orderByStringVar,
313
+ whereFilter,
330
314
  })
331
315
 
332
316
  if (!result) return []