@ensdomains/ensjs 3.0.0-alpha.6 → 3.0.0-alpha.9
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/cjs/GqlManager.d.ts +3 -0
- package/dist/cjs/GqlManager.js +62 -2
- package/dist/cjs/functions/getProfile.d.ts +4 -1
- package/dist/cjs/functions/getProfile.js +62 -18
- package/dist/cjs/functions/getRecords.d.ts +1 -0
- package/dist/cjs/functions/setRecord.d.ts +18 -0
- package/dist/cjs/functions/setRecord.js +27 -0
- package/dist/cjs/index.d.ts +7 -2
- package/dist/cjs/index.js +6 -1
- package/dist/cjs/utils/labels.js +4 -3
- package/dist/cjs/utils/normalise.d.ts +1 -1
- package/dist/cjs/utils/normalise.js +10 -3
- package/dist/cjs/utils/recordHelpers.d.ts +3 -0
- package/dist/cjs/utils/recordHelpers.js +42 -15
- package/dist/esm/GqlManager.d.ts +3 -0
- package/dist/esm/GqlManager.js +58 -2
- package/dist/esm/functions/getProfile.d.ts +4 -1
- package/dist/esm/functions/getProfile.js +62 -18
- package/dist/esm/functions/getRecords.d.ts +1 -0
- package/dist/esm/functions/setRecord.d.ts +18 -0
- package/dist/esm/functions/setRecord.js +24 -0
- package/dist/esm/index.d.ts +7 -2
- package/dist/esm/index.js +6 -1
- package/dist/esm/utils/labels.js +4 -3
- package/dist/esm/utils/normalise.d.ts +1 -1
- package/dist/esm/utils/normalise.js +10 -3
- package/dist/esm/utils/recordHelpers.d.ts +3 -0
- package/dist/esm/utils/recordHelpers.js +40 -14
- package/package.json +7 -5
- package/src/GqlManager.test.ts +170 -0
- package/src/GqlManager.ts +67 -2
- package/src/functions/getProfile.test.ts +16 -1
- package/src/functions/getProfile.ts +82 -19
- package/src/functions/getRecords.ts +1 -0
- package/src/functions/setRecord.test.ts +100 -0
- package/src/functions/setRecord.ts +63 -0
- package/src/functions/setRecords.test.ts +2 -2
- package/src/index.ts +8 -1
- package/src/utils/labels.ts +5 -3
- package/src/utils/normalise.ts +10 -4
- package/src/utils/recordHelpers.ts +52 -18
|
@@ -33,6 +33,47 @@ export const generateSetAddr = (
|
|
|
33
33
|
)
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
export type RecordTypes = 'contentHash' | 'text' | 'addr'
|
|
37
|
+
|
|
38
|
+
export type RecordInput<T extends RecordTypes> = T extends 'contentHash'
|
|
39
|
+
? string
|
|
40
|
+
: RecordItem
|
|
41
|
+
|
|
42
|
+
export function generateSingleRecordCall<T extends RecordTypes>(
|
|
43
|
+
namehash: string,
|
|
44
|
+
resolver: PublicResolver,
|
|
45
|
+
type: T,
|
|
46
|
+
): (record: RecordInput<T>) => string {
|
|
47
|
+
if (type === 'contentHash') {
|
|
48
|
+
return (_r: RecordInput<T>) => {
|
|
49
|
+
const record = _r as string
|
|
50
|
+
let _contentHash = ''
|
|
51
|
+
if (record !== _contentHash) {
|
|
52
|
+
const encoded = encodeContenthash(record)
|
|
53
|
+
if (encoded.error) throw new Error(encoded.error)
|
|
54
|
+
_contentHash = encoded.encoded as string
|
|
55
|
+
}
|
|
56
|
+
return resolver.interface.encodeFunctionData('setContenthash', [
|
|
57
|
+
namehash,
|
|
58
|
+
_contentHash,
|
|
59
|
+
])
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
return (_r: RecordInput<T>) => {
|
|
63
|
+
const record = _r as RecordItem
|
|
64
|
+
if (type === 'text') {
|
|
65
|
+
return resolver.interface.encodeFunctionData('setText', [
|
|
66
|
+
namehash,
|
|
67
|
+
record.key,
|
|
68
|
+
record.value,
|
|
69
|
+
])
|
|
70
|
+
} else {
|
|
71
|
+
return generateSetAddr(namehash, record.key, record.value, resolver)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
36
77
|
export const generateRecordCallArray = (
|
|
37
78
|
namehash: string,
|
|
38
79
|
records: RecordOptions,
|
|
@@ -41,31 +82,24 @@ export const generateRecordCallArray = (
|
|
|
41
82
|
const calls: string[] = []
|
|
42
83
|
|
|
43
84
|
if (records.contentHash) {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
'
|
|
48
|
-
|
|
49
|
-
)
|
|
85
|
+
const data = generateSingleRecordCall(
|
|
86
|
+
namehash,
|
|
87
|
+
resolver,
|
|
88
|
+
'contentHash',
|
|
89
|
+
)(records.contentHash)
|
|
50
90
|
data && calls.push(data)
|
|
51
91
|
}
|
|
52
92
|
|
|
53
93
|
if (records.texts && records.texts.length > 0) {
|
|
54
|
-
records.texts
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
key,
|
|
58
|
-
value,
|
|
59
|
-
])
|
|
60
|
-
data && calls.push(data)
|
|
61
|
-
})
|
|
94
|
+
records.texts
|
|
95
|
+
.map(generateSingleRecordCall(namehash, resolver, 'text'))
|
|
96
|
+
.forEach((call) => calls.push(call))
|
|
62
97
|
}
|
|
63
98
|
|
|
64
99
|
if (records.coinTypes && records.coinTypes.length > 0) {
|
|
65
|
-
records.coinTypes
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
})
|
|
100
|
+
records.coinTypes
|
|
101
|
+
.map(generateSingleRecordCall(namehash, resolver, 'addr'))
|
|
102
|
+
.forEach((call) => calls.push(call))
|
|
69
103
|
}
|
|
70
104
|
|
|
71
105
|
return calls
|