@xyo-network/xns-record-payloadset-plugins 5.3.2 → 5.3.3

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 (129) hide show
  1. package/dist/browser/estimate/index.d.ts +2 -0
  2. package/dist/browser/estimate/index.d.ts.map +1 -0
  3. package/dist/browser/estimate/lib/index.d.ts +2 -0
  4. package/dist/browser/estimate/lib/index.d.ts.map +1 -0
  5. package/dist/browser/estimate/lib/parseDomainEstimates.d.ts +9 -0
  6. package/dist/browser/estimate/lib/parseDomainEstimates.d.ts.map +1 -0
  7. package/dist/browser/index.d.ts +3 -0
  8. package/dist/browser/index.d.ts.map +1 -0
  9. package/dist/browser/index.mjs +284 -0
  10. package/dist/browser/index.mjs.map +1 -0
  11. package/dist/browser/validation/index.d.ts +3 -0
  12. package/dist/browser/validation/index.d.ts.map +1 -0
  13. package/dist/browser/validation/name/Name.d.ts +42 -0
  14. package/dist/browser/validation/name/Name.d.ts.map +1 -0
  15. package/dist/browser/validation/name/index.d.ts +3 -0
  16. package/dist/browser/validation/name/index.d.ts.map +1 -0
  17. package/dist/browser/validation/name/lib/index.d.ts +2 -0
  18. package/dist/browser/validation/name/lib/index.d.ts.map +1 -0
  19. package/dist/browser/validation/name/lib/removeDisallowedCharacters.d.ts +7 -0
  20. package/dist/browser/validation/name/lib/removeDisallowedCharacters.d.ts.map +1 -0
  21. package/dist/browser/validation/name/types/ValidSources.d.ts +2 -0
  22. package/dist/browser/validation/name/types/ValidSources.d.ts.map +1 -0
  23. package/dist/browser/validation/name/types/index.d.ts +2 -0
  24. package/dist/browser/validation/name/types/index.d.ts.map +1 -0
  25. package/dist/browser/validation/validation/Constants.d.ts +3 -0
  26. package/dist/browser/validation/validation/Constants.d.ts.map +1 -0
  27. package/dist/browser/validation/validation/factory/index.d.ts +2 -0
  28. package/dist/browser/validation/validation/factory/index.d.ts.map +1 -0
  29. package/dist/browser/validation/validation/factory/validators.d.ts +6 -0
  30. package/dist/browser/validation/validation/factory/validators.d.ts.map +1 -0
  31. package/dist/browser/validation/validation/index.d.ts +4 -0
  32. package/dist/browser/validation/validation/index.d.ts.map +1 -0
  33. package/dist/browser/validation/validation/validators/index.d.ts +2 -0
  34. package/dist/browser/validation/validation/validators/index.d.ts.map +1 -0
  35. package/dist/browser/validation/validation/validators/validators.d.ts +14 -0
  36. package/dist/browser/validation/validation/validators/validators.d.ts.map +1 -0
  37. package/dist/neutral/estimate/index.d.ts +2 -0
  38. package/dist/neutral/estimate/index.d.ts.map +1 -0
  39. package/dist/neutral/estimate/lib/index.d.ts +2 -0
  40. package/dist/neutral/estimate/lib/index.d.ts.map +1 -0
  41. package/dist/neutral/estimate/lib/parseDomainEstimates.d.ts +9 -0
  42. package/dist/neutral/estimate/lib/parseDomainEstimates.d.ts.map +1 -0
  43. package/dist/neutral/index.d.ts +3 -0
  44. package/dist/neutral/index.d.ts.map +1 -0
  45. package/dist/neutral/index.mjs +284 -0
  46. package/dist/neutral/index.mjs.map +1 -0
  47. package/dist/neutral/validation/index.d.ts +3 -0
  48. package/dist/neutral/validation/index.d.ts.map +1 -0
  49. package/dist/neutral/validation/name/Name.d.ts +42 -0
  50. package/dist/neutral/validation/name/Name.d.ts.map +1 -0
  51. package/dist/neutral/validation/name/index.d.ts +3 -0
  52. package/dist/neutral/validation/name/index.d.ts.map +1 -0
  53. package/dist/neutral/validation/name/lib/index.d.ts +2 -0
  54. package/dist/neutral/validation/name/lib/index.d.ts.map +1 -0
  55. package/dist/neutral/validation/name/lib/removeDisallowedCharacters.d.ts +7 -0
  56. package/dist/neutral/validation/name/lib/removeDisallowedCharacters.d.ts.map +1 -0
  57. package/dist/neutral/validation/name/types/ValidSources.d.ts +2 -0
  58. package/dist/neutral/validation/name/types/ValidSources.d.ts.map +1 -0
  59. package/dist/neutral/validation/name/types/index.d.ts +2 -0
  60. package/dist/neutral/validation/name/types/index.d.ts.map +1 -0
  61. package/dist/neutral/validation/validation/Constants.d.ts +3 -0
  62. package/dist/neutral/validation/validation/Constants.d.ts.map +1 -0
  63. package/dist/neutral/validation/validation/factory/index.d.ts +2 -0
  64. package/dist/neutral/validation/validation/factory/index.d.ts.map +1 -0
  65. package/dist/neutral/validation/validation/factory/validators.d.ts +6 -0
  66. package/dist/neutral/validation/validation/factory/validators.d.ts.map +1 -0
  67. package/dist/neutral/validation/validation/index.d.ts +4 -0
  68. package/dist/neutral/validation/validation/index.d.ts.map +1 -0
  69. package/dist/neutral/validation/validation/validators/index.d.ts +2 -0
  70. package/dist/neutral/validation/validation/validators/index.d.ts.map +1 -0
  71. package/dist/neutral/validation/validation/validators/validators.d.ts +14 -0
  72. package/dist/neutral/validation/validation/validators/validators.d.ts.map +1 -0
  73. package/dist/node/estimate/index.d.ts +2 -0
  74. package/dist/node/estimate/index.d.ts.map +1 -0
  75. package/dist/node/estimate/lib/index.d.ts +2 -0
  76. package/dist/node/estimate/lib/index.d.ts.map +1 -0
  77. package/dist/node/estimate/lib/parseDomainEstimates.d.ts +9 -0
  78. package/dist/node/estimate/lib/parseDomainEstimates.d.ts.map +1 -0
  79. package/dist/node/index.d.ts +3 -0
  80. package/dist/node/index.d.ts.map +1 -0
  81. package/dist/node/index.mjs +284 -0
  82. package/dist/node/index.mjs.map +1 -0
  83. package/dist/node/validation/index.d.ts +3 -0
  84. package/dist/node/validation/index.d.ts.map +1 -0
  85. package/dist/node/validation/name/Name.d.ts +42 -0
  86. package/dist/node/validation/name/Name.d.ts.map +1 -0
  87. package/dist/node/validation/name/index.d.ts +3 -0
  88. package/dist/node/validation/name/index.d.ts.map +1 -0
  89. package/dist/node/validation/name/lib/index.d.ts +2 -0
  90. package/dist/node/validation/name/lib/index.d.ts.map +1 -0
  91. package/dist/node/validation/name/lib/removeDisallowedCharacters.d.ts +7 -0
  92. package/dist/node/validation/name/lib/removeDisallowedCharacters.d.ts.map +1 -0
  93. package/dist/node/validation/name/types/ValidSources.d.ts +2 -0
  94. package/dist/node/validation/name/types/ValidSources.d.ts.map +1 -0
  95. package/dist/node/validation/name/types/index.d.ts +2 -0
  96. package/dist/node/validation/name/types/index.d.ts.map +1 -0
  97. package/dist/node/validation/validation/Constants.d.ts +3 -0
  98. package/dist/node/validation/validation/Constants.d.ts.map +1 -0
  99. package/dist/node/validation/validation/factory/index.d.ts +2 -0
  100. package/dist/node/validation/validation/factory/index.d.ts.map +1 -0
  101. package/dist/node/validation/validation/factory/validators.d.ts +6 -0
  102. package/dist/node/validation/validation/factory/validators.d.ts.map +1 -0
  103. package/dist/node/validation/validation/index.d.ts +4 -0
  104. package/dist/node/validation/validation/index.d.ts.map +1 -0
  105. package/dist/node/validation/validation/validators/index.d.ts +2 -0
  106. package/dist/node/validation/validation/validators/index.d.ts.map +1 -0
  107. package/dist/node/validation/validation/validators/validators.d.ts +14 -0
  108. package/dist/node/validation/validation/validators/validators.d.ts.map +1 -0
  109. package/package.json +11 -6
  110. package/src/estimate/index.ts +0 -1
  111. package/src/estimate/lib/index.ts +0 -1
  112. package/src/estimate/lib/parseDomainEstimates.ts +0 -77
  113. package/src/estimate/lib/spec/matchers/customMatchers.ts +0 -287
  114. package/src/estimate/lib/spec/matchers/index.ts +0 -1
  115. package/src/estimate/lib/spec/matchers/vitest.customMatchers.d.ts +0 -27
  116. package/src/index.ts +0 -2
  117. package/src/validation/index.ts +0 -2
  118. package/src/validation/name/Name.ts +0 -122
  119. package/src/validation/name/index.ts +0 -2
  120. package/src/validation/name/lib/index.ts +0 -1
  121. package/src/validation/name/lib/removeDisallowedCharacters.ts +0 -26
  122. package/src/validation/name/types/ValidSources.ts +0 -1
  123. package/src/validation/name/types/index.ts +0 -1
  124. package/src/validation/validation/Constants.ts +0 -2
  125. package/src/validation/validation/factory/index.ts +0 -1
  126. package/src/validation/validation/factory/validators.ts +0 -47
  127. package/src/validation/validation/index.ts +0 -3
  128. package/src/validation/validation/validators/index.ts +0 -1
  129. package/src/validation/validation/validators/validators.ts +0 -129
@@ -1,287 +0,0 @@
1
- interface ExpectationResult {
2
- actual?: unknown
3
- expected?: unknown
4
- message: () => string
5
- pass: boolean
6
- }
7
-
8
- function toBeType(received: unknown, expectedType: string): ExpectationResult {
9
- const pass = typeof received === expectedType && !Number.isNaN(received)
10
- return pass
11
- ? {
12
- message: () => `expected ${received} not to be a ${expectedType}`,
13
- pass: true,
14
- }
15
- : {
16
- message: () => `expected ${received} to be a ${expectedType}`,
17
- pass: false,
18
- }
19
- }
20
-
21
- export const matchers = {
22
- toBeArrayOfSize(received: unknown, expectedSize: number): ExpectationResult {
23
- const pass = Array.isArray(received) && received.length === expectedSize
24
- return pass
25
- ? {
26
- message: () => `expected array not to have size ${expectedSize}, but received array of size ${received.length}`,
27
- pass: true,
28
- }
29
- : {
30
- message: () => Array.isArray(received)
31
- ? `expected array of size ${expectedSize}, but received array of size ${received.length}`
32
- : `expected array of size ${expectedSize}, but received a non-array`,
33
- pass: false,
34
- }
35
- },
36
- toBeArray(received: unknown): ExpectationResult {
37
- const pass = Array.isArray(received)
38
- return pass
39
- ? {
40
- message: () => 'expected array',
41
- pass: true,
42
- }
43
- : {
44
- message: () => `expected array, but received ${typeof received}`,
45
- pass: false,
46
- }
47
- },
48
- toBeOneOf(received: unknown, expected: unknown[]): ExpectationResult {
49
- const pass = expected.includes(received)
50
- return pass
51
- ? {
52
- pass: true,
53
- message: () =>
54
- `expected ${received} not to be one of ${JSON.stringify(expected)}`,
55
- }
56
- : {
57
- pass: false,
58
- message: () =>
59
- `expected ${received} to be one of ${JSON.stringify(expected)}`,
60
- }
61
- },
62
- toBeNegative(received: number): ExpectationResult {
63
- if (typeof received !== 'number') {
64
- throw new TypeError(`Expected a number, but received ${typeof received}`)
65
- }
66
-
67
- const pass = received < 0
68
- return pass
69
- ? {
70
- pass: true,
71
- message: () =>
72
- `expected ${received} not to be negative`,
73
- }
74
- : {
75
- pass: false,
76
- message: () =>
77
- `expected ${received} to be negative`,
78
- }
79
- },
80
- toBePositive(received: number): ExpectationResult {
81
- if (typeof received !== 'number') {
82
- throw new TypeError(`Expected a number, but received ${typeof received}`)
83
- }
84
-
85
- const pass = received > 0
86
- return pass
87
- ? {
88
- pass: true,
89
- message: () =>
90
- `expected ${received} not to be positive`,
91
- }
92
- : {
93
- pass: false,
94
- message: () =>
95
- `expected ${received} to be positive`,
96
- }
97
- },
98
- toBeNumber: (received: unknown) => toBeType(received, 'number'),
99
- toBeFunction: (received: unknown) => toBeType(received, 'function'),
100
- toBeString: (received: unknown) => toBeType(received, 'string'),
101
- toBeObject(received: unknown): ExpectationResult {
102
- const pass = typeof received === 'object' && !Array.isArray(received) && received !== null
103
- return pass
104
- ? {
105
- message: () => `expected ${received} to be object`,
106
- pass: true,
107
- }
108
- : {
109
- message: () => `expected ${received} to be an object but was ${Array.isArray(received) ? 'array' : typeof received}`,
110
- pass: false,
111
- }
112
- },
113
- toBeInteger(received: number): ExpectationResult {
114
- if (typeof received !== 'number') {
115
- throw new TypeError(`Expected a number, but received ${typeof received}`)
116
- }
117
-
118
- const pass = Number.isInteger(received)
119
- return pass
120
- ? {
121
- pass: true,
122
- message: () =>
123
- `expected ${received} not to be an integer`,
124
- }
125
- : {
126
- pass: false,
127
- message: () =>
128
- `expected ${received} to be an integer`,
129
- }
130
- },
131
- toBeFalse(received: unknown): ExpectationResult {
132
- const pass = received === false
133
- return pass
134
- ? {
135
- message: () => `expected ${received} to be false`,
136
- pass: true,
137
- }
138
- : {
139
- message: () => `expected ${received} to be false but was not false`,
140
- pass: false,
141
- }
142
- },
143
- toBeTrue(received: unknown): ExpectationResult {
144
- const pass = received === true
145
- return pass
146
- ? {
147
- message: () => `expected ${received} to be true`,
148
- pass: true,
149
- }
150
- : {
151
- message: () => `expected ${received} to be true but was not true`,
152
- pass: false,
153
- }
154
- },
155
- toIncludeAllMembers(received: unknown[], expected: unknown[]): ExpectationResult {
156
- if (!Array.isArray(received) || !Array.isArray(expected)) {
157
- return {
158
- pass: false,
159
- message: () => 'Expected both received and expected values to be arrays.',
160
- }
161
- }
162
-
163
- const missingMembers = expected.filter(item => !received.includes(item))
164
-
165
- return missingMembers.length === 0
166
- ? {
167
- pass: true,
168
- message: () =>
169
- `Expected array not to include all members of ${JSON.stringify(expected)}, but it does.`,
170
- }
171
- : {
172
- pass: false,
173
- message: () =>
174
- `Expected array to include all members of ${JSON.stringify(expected)}. Missing members: ${JSON.stringify(
175
- missingMembers,
176
- )}.`,
177
- }
178
- },
179
- toContainAllKeys(received: object, expectedKeys: string[]): ExpectationResult {
180
- if (typeof received !== 'object' || received === null) {
181
- return {
182
- pass: false,
183
- message: () => `Expected ${JSON.stringify(received)} to be an object.`,
184
- }
185
- }
186
-
187
- if (!Array.isArray(expectedKeys)) {
188
- return {
189
- pass: false,
190
- message: () => `Expected keys to be an array, but received ${JSON.stringify(expectedKeys)}.`,
191
- }
192
- }
193
-
194
- const missingKeys = expectedKeys.filter(key => !(key in received))
195
-
196
- return missingKeys.length === 0
197
- ? {
198
- pass: true,
199
- message: () =>
200
- `Expected object not to contain all keys ${JSON.stringify(expectedKeys)}, but it does.`,
201
- }
202
- : {
203
- pass: false,
204
- message: () =>
205
- `Expected object to contain all keys ${JSON.stringify(expectedKeys)}. Missing keys: ${JSON.stringify(
206
- missingKeys,
207
- )}.`,
208
- }
209
- },
210
- toContainValues(received: object, expectedValues: unknown[]): ExpectationResult {
211
- if (typeof received !== 'object' || received === null) {
212
- return {
213
- pass: false,
214
- message: () => `Expected ${JSON.stringify(received)} to be an object.`,
215
- }
216
- }
217
-
218
- if (!Array.isArray(expectedValues)) {
219
- return {
220
- pass: false,
221
- message: () => `Expected values to be an array, but received ${JSON.stringify(expectedValues)}.`,
222
- }
223
- }
224
-
225
- const objectValues = Object.values(received)
226
-
227
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
228
- const deepEqual = (a: any, b: any): boolean => {
229
- if (a === b) return true
230
- if (typeof a !== typeof b) return false
231
- if (a && b && typeof a === 'object') {
232
- const aKeys = Object.keys(a)
233
- const bKeys = Object.keys(b)
234
- if (aKeys.length !== bKeys.length) return false
235
- return aKeys.every(key => deepEqual(a[key], b[key]))
236
- }
237
- return false
238
- }
239
-
240
- const missingValues = expectedValues.filter(
241
- expectedValue => !objectValues.some(value => deepEqual(value, expectedValue)),
242
- )
243
-
244
- return missingValues.length === 0
245
- ? {
246
- pass: true,
247
- message: () =>
248
- `Expected object not to contain all values ${JSON.stringify(expectedValues)}, but it does.`,
249
- }
250
- : {
251
- pass: false,
252
- message: () =>
253
- `Expected object to contain all values ${JSON.stringify(expectedValues)}. Missing values: ${JSON.stringify(
254
- missingValues,
255
- )}.`,
256
- }
257
- },
258
- toBeEmpty(received: unknown): ExpectationResult {
259
- let isEmpty = false
260
-
261
- if (Array.isArray(received) || typeof received === 'string') {
262
- isEmpty = received.length === 0
263
- } else if (received && typeof received === 'object') {
264
- isEmpty = Object.keys(received).length === 0
265
- } else if (received instanceof Map || received instanceof Set) {
266
- isEmpty = received.size === 0
267
- } else {
268
- return {
269
- pass: false,
270
- message: () =>
271
- `Expected value to be an empty array, string, object, Map, or Set, but received ${typeof received}.`,
272
- }
273
- }
274
-
275
- return isEmpty
276
- ? {
277
- pass: true,
278
- message: () =>
279
- 'Expected value not to be empty, but it was.',
280
- }
281
- : {
282
- pass: false,
283
- message: () =>
284
- 'Expected value to be empty, but it was not.',
285
- }
286
- },
287
- }
@@ -1 +0,0 @@
1
- export * from './customMatchers.ts'
@@ -1,27 +0,0 @@
1
- // vitest.customMatchers.d.ts
2
- import 'vitest'
3
-
4
- interface CustomMatchers<T = unknown> {
5
- toBeArray(): T
6
- toBeArrayOfSize(size: number): T
7
- toBeEmpty(): T
8
- toBeFalse(): T
9
- toBeFunction(): T
10
- toBeInteger(): T
11
- toBeNegative(): T
12
- toBeNumber(): T
13
- toBeObject(): T
14
- toBeOneOf(expected: unknown[]): T
15
- toBePositive(): T
16
- toBeString(): T
17
- toBeTrue(): T
18
- toContainAllKeys(expectedKeys: string[]): T
19
- toContainValues(expectedValues: unknown[]): T
20
- toIncludeAllMembers(expected: unknown[]): T
21
- }
22
-
23
- // Extend the expect Matchers interface
24
- declare module 'vitest' {
25
- interface Assertion<T = unknown> extends CustomMatchers<T> {}
26
- interface AsymmetricMatchersContaining extends CustomMatchers {}
27
- }
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './estimate/index.ts'
2
- export * from './validation/index.ts'
@@ -1,2 +0,0 @@
1
- export * from './name/index.ts'
2
- export * from './validation/index.ts'
@@ -1,122 +0,0 @@
1
- import type { Promisable } from '@xylabs/sdk-js'
2
- import { assertEx, isHash } from '@xylabs/sdk-js'
3
- import type { Payload } from '@xyo-network/payload-model'
4
- import type { DomainFields, TopLevelDomain } from '@xyo-network/xns-record-payload-plugins'
5
- import { DomainSchema } from '@xyo-network/xns-record-payload-plugins'
6
-
7
- import { MAX_DOMAIN_LENGTH, XnsNameSimpleValidators } from '../validation/index.ts'
8
- import { removeDisallowedCharacters } from './lib/index.ts'
9
- import type { ValidSourceTypes } from './types/index.ts'
10
-
11
- const defaultMaskOptions = { maskStartEndHyphens: false }
12
-
13
- export class XnsNameHelper {
14
- static readonly ValidTLDs = ['.xyo'] as const
15
-
16
- private _xnsName: Payload<DomainFields>
17
-
18
- private constructor(xnsName: Payload<DomainFields>) {
19
- this._xnsName = xnsName
20
- }
21
-
22
- get domain() {
23
- return assertEx(this.xnsName.domain, () => 'domain not found in payload')
24
- }
25
-
26
- get name() {
27
- return `${this.domain}.${this.tld}`
28
- }
29
-
30
- get tld() {
31
- return assertEx(this.xnsName.tld, () => 'tld not found in payload')
32
- }
33
-
34
- get xnsName() {
35
- return assertEx(this._xnsName, () => 'XnsNameHelper xnsName not set')
36
- }
37
-
38
- /**
39
- * Create an XnsNameHelper from a domain payload
40
- * @param {Domain} domain
41
- * @returns Promise<XnsNameHelper>
42
- */
43
- static fromPayload(domain: Payload<DomainFields>): Promisable<XnsNameHelper> {
44
- return new XnsNameHelper(domain)
45
- }
46
-
47
- /**
48
- * Create an XnsNameHelper from a string
49
- * @param {string} xnsName
50
- * @returns Promise<XnsNameHelper>
51
- */
52
- static fromString(xnsName: string): XnsNameHelper {
53
- const parts = xnsName.split('.')
54
- assertEx(parts.length === 2, () => 'Unable to parse xnsName')
55
-
56
- const domain = parts[0]
57
- const tld = parts[1] as TopLevelDomain
58
- return new XnsNameHelper({
59
- schema: DomainSchema, domain, tld,
60
- })
61
- }
62
-
63
- /**
64
- * Determine if a string is a valid XNS name or hash
65
- * @param {string} source?
66
- * @returns ValidSourceTypes
67
- */
68
- static isPotentialXnsNameOrHash(source?: string): ValidSourceTypes {
69
- if (isHash(source)) return 'hash'
70
- const xnsName = XnsNameHelper.ValidTLDs.some(tld => source?.endsWith(tld)) ? source : null
71
- return xnsName ? 'xnsName' : null
72
- }
73
-
74
- static async isValid(domain: Payload<DomainFields>): Promise<boolean> {
75
- const results = await Promise.all(XnsNameSimpleValidators.map(validator => validator(domain)))
76
- for (const result of results) {
77
- if (!result) return false
78
- }
79
- return true
80
- }
81
-
82
- /**
83
- * Mask a string to be a valid XNS name
84
- * @param {string} str
85
- * @returns string
86
- */
87
- static mask(str: string, options: { maskStartEndHyphens: boolean } = defaultMaskOptions): string {
88
- // Check if the domain name is too long
89
- if (str.length > MAX_DOMAIN_LENGTH) {
90
- throw new Error(`Domain name too long: ${str.length} exceeds max length: ${MAX_DOMAIN_LENGTH}`)
91
- }
92
-
93
- // convert to lowercase
94
- const lowercaseXnsName = str.toLowerCase()
95
-
96
- // Remove everything except letters, numbers, and dashes
97
-
98
- let formattedXnsName = lowercaseXnsName.replaceAll(/[^\dA-Za-z-]+$/g, '')
99
-
100
- // Remove leading and trailing dashes
101
-
102
- if (options.maskStartEndHyphens) formattedXnsName = formattedXnsName.replaceAll(/^-+|-+$/g, '')
103
-
104
- // Filter out disallowed characters.
105
- return removeDisallowedCharacters(formattedXnsName)
106
- }
107
-
108
- async validate(): Promise<[boolean, string[]]> {
109
- const errorMessages: string[] = []
110
- const onErrorsInternal = (message: string[]) => errorMessages.push(...message)
111
-
112
- for (const validator of XnsNameSimpleValidators) {
113
- await validator(this.xnsName, onErrorsInternal)
114
- }
115
-
116
- if (errorMessages.length > 0) {
117
- return [false, errorMessages]
118
- }
119
-
120
- return [true, []]
121
- }
122
- }
@@ -1,2 +0,0 @@
1
- export * from './Name.ts'
2
- export * from './types/index.ts'
@@ -1 +0,0 @@
1
- export * from './removeDisallowedCharacters.ts'
@@ -1,26 +0,0 @@
1
- import { DisallowedModuleIdentifierCharacters } from '@xyo-network/module-model'
2
-
3
- /**
4
- * A set of all the disallowed characters in module identifiers
5
- */
6
- const DISALLOWED_CHARACTERS = new Set(Object.keys(DisallowedModuleIdentifierCharacters))
7
-
8
- /**
9
- * Iterates over a string removing disallowed characters
10
- * @param xnsName The XNS name to remove disallowed characters from
11
- * @returns The XNS name with disallowed characters removed
12
- */
13
- export const removeDisallowedCharacters = (xnsName: string): string => {
14
- // Create the initial result
15
- let result = ''
16
- // Iterate over each character in the XNS name
17
- for (const char of xnsName) {
18
- // If the character is not a disallowed character
19
- if (!DISALLOWED_CHARACTERS.has(char)) {
20
- // add it to the result
21
- result += char
22
- }
23
- }
24
- // Return the result which contains only allowed characters
25
- return result
26
- }
@@ -1 +0,0 @@
1
- export type ValidSourceTypes = 'xnsName' | 'hash' | null
@@ -1 +0,0 @@
1
- export * from './ValidSources.ts'
@@ -1,2 +0,0 @@
1
- export const MIN_DOMAIN_LENGTH = 3
2
- export const MAX_DOMAIN_LENGTH = 128
@@ -1 +0,0 @@
1
- export * from './validators.ts'
@@ -1,47 +0,0 @@
1
- import type { Payload, PayloadValidationFunction } from '@xyo-network/payload-model'
2
- import type { DomainFields } from '@xyo-network/xns-record-payload-plugins'
3
-
4
- export const getDomainReservedStringsValidator = (
5
- reservedStrings: string[],
6
- ): PayloadValidationFunction<Payload<DomainFields>> => {
7
- return (payload: Payload<DomainFields>) => {
8
- const { domain } = payload
9
- // Check if in one of the reserved name lists
10
- if (reservedStrings.includes(domain)) {
11
- console.log('Reserved name')
12
- return false
13
- }
14
- return true
15
- }
16
- }
17
-
18
- export const getDomainReservedFragmentsValidator = (
19
- reservedFragments: string[],
20
- ): PayloadValidationFunction<Payload<DomainFields>> => {
21
- return (payload: Payload<DomainFields>) => {
22
- const { domain } = payload
23
- // Check if any of our fragments are in the name
24
- for (const reserved of reservedFragments) {
25
- if (domain.includes(reserved)) {
26
- console.log('Reserved name fragment')
27
- return false
28
- }
29
- }
30
- return true
31
- }
32
- }
33
-
34
- export const getDomainReservedNamesValidator = (reservedNames: string[]): PayloadValidationFunction<Payload<DomainFields>> => {
35
- return (payload: Payload<DomainFields>) => {
36
- const { domain } = payload
37
- // Check if any of our fragments are in the name
38
- for (const reserved of reservedNames) {
39
- const parts = reserved.split(' ')
40
- if (domain === [parts[1], parts[0]].join('') || domain === [parts[0], parts[1]].join('')) {
41
- console.log('Reserved name')
42
- return false
43
- }
44
- }
45
- return true
46
- }
47
- }
@@ -1,3 +0,0 @@
1
- export * from './Constants.ts'
2
- export * from './factory/index.ts'
3
- export * from './validators/index.ts'
@@ -1 +0,0 @@
1
- export * from './validators.ts'
@@ -1,129 +0,0 @@
1
- import { isModuleName } from '@xyo-network/module-model'
2
- import type { Payload } from '@xyo-network/payload-model'
3
- import type { DomainFields } from '@xyo-network/xns-record-payload-plugins'
4
-
5
- import { MAX_DOMAIN_LENGTH, MIN_DOMAIN_LENGTH } from '../Constants.ts'
6
-
7
- export type PayloadValidationFunctionWithError<T extends Payload = Payload> = (payload: T, onErrors?: (message: string[]) => void) => boolean | Promise<boolean>
8
-
9
- export const domainCasingValidator: PayloadValidationFunctionWithError<Payload<DomainFields>> = (
10
- payload: Payload<DomainFields>,
11
- onErrors?: (message: string[]) => void,
12
- ) => {
13
- const { domain } = payload
14
- // Check if all lowercase
15
- if (domain.toLowerCase() !== domain) {
16
- onErrors?.(['name must be lowercase'])
17
- return false
18
- }
19
- return true
20
- }
21
-
22
- export const domainModuleNameValidator: PayloadValidationFunctionWithError<Payload<DomainFields>> = (
23
- payload: Payload<DomainFields>,
24
- onErrors?: (message: string[]) => void,
25
- ) => {
26
- const { domain } = payload
27
-
28
- // check if domain is a valid name
29
- if (!isModuleName(domain)) {
30
- onErrors?.([`Domain is not a valid module name: ${domain}`])
31
- return false
32
- }
33
-
34
- return true
35
- }
36
-
37
- export const domainTldValidator: PayloadValidationFunctionWithError<Payload<DomainFields>> = (
38
- payload: Payload<DomainFields>,
39
- onErrors?: (message: string[]) => void,
40
- ) => {
41
- const { tld } = payload
42
- const errorMessages: string[] = []
43
-
44
- // Check if all lowercase
45
- if (tld.toLowerCase() !== tld) {
46
- errorMessages.push('TLD must be lowercase')
47
- }
48
- // Check if supported TLDs
49
- if (tld !== 'xyo') {
50
- errorMessages.push('Only XYO TLD currently supported')
51
- }
52
- if (errorMessages.length > 0) {
53
- onErrors?.(errorMessages)
54
- return false
55
- }
56
- return true
57
- }
58
-
59
- export const getDomainLengthValidator = (
60
- minNameLength = MIN_DOMAIN_LENGTH,
61
- maxLength = MAX_DOMAIN_LENGTH,
62
- ): PayloadValidationFunctionWithError<Payload<DomainFields>> => {
63
- return (
64
- payload: Payload<DomainFields>,
65
- onErrors?: (message: string[]) => void,
66
- ) => {
67
- const { domain } = payload
68
- const errorMessages: string[] = []
69
-
70
- // Check if min length
71
- if (domain.length < minNameLength) {
72
- errorMessages.push(`name must be at least ${minNameLength} characters`)
73
- }
74
-
75
- if (domain.length > maxLength) {
76
- errorMessages.push(`name must be no more than ${maxLength} characters`)
77
- }
78
-
79
- if (errorMessages.length > 0) {
80
- onErrors?.(errorMessages)
81
- return false
82
- }
83
-
84
- return true
85
- }
86
- }
87
-
88
- export const getDomainAllowedHyphensValidator = (
89
- options?: { end?: boolean; start?: boolean },
90
- ): PayloadValidationFunctionWithError<Payload<DomainFields>> => {
91
- return (
92
- payload: Payload<DomainFields>,
93
- onErrors?: (message: string[]) => void,
94
- ) => {
95
- const { domain } = payload
96
- const { start, end } = options ?? {}
97
- const errorMessages: string[] = []
98
-
99
- if (!start && domain.startsWith('-')) {
100
- errorMessages.push('name cannot start with hyphen')
101
- }
102
-
103
- if (!end && domain.endsWith('-')) {
104
- errorMessages.push('name cannot end with hyphen')
105
- }
106
-
107
- if (errorMessages.length > 0) {
108
- onErrors?.(errorMessages)
109
- return false
110
- }
111
- return true
112
- }
113
- }
114
-
115
- export const XnsNameSimpleValidators = [
116
- domainCasingValidator,
117
- domainModuleNameValidator,
118
- domainTldValidator,
119
- getDomainLengthValidator(),
120
- getDomainAllowedHyphensValidator(),
121
- ]
122
-
123
- export const XnsNameSimpleValidatorsWithErrors = (onErrors: (message: string[]) => void) => [
124
- domainCasingValidator,
125
- domainModuleNameValidator,
126
- domainTldValidator,
127
- getDomainLengthValidator(),
128
- getDomainAllowedHyphensValidator(),
129
- ].map(validator => (payload: Payload<DomainFields>) => validator(payload, onErrors))