@xyo-network/xns-record-payloadset-plugins 5.3.1 → 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 (48) hide show
  1. package/dist/browser/estimate/lib/parseDomainEstimates.d.ts.map +1 -1
  2. package/dist/browser/index.mjs +3 -5
  3. package/dist/browser/index.mjs.map +1 -1
  4. package/dist/browser/validation/name/Name.d.ts +1 -1
  5. package/dist/browser/validation/name/Name.d.ts.map +1 -1
  6. package/dist/neutral/estimate/lib/parseDomainEstimates.d.ts.map +1 -1
  7. package/dist/neutral/index.mjs +3 -5
  8. package/dist/neutral/index.mjs.map +1 -1
  9. package/dist/neutral/validation/name/Name.d.ts +1 -1
  10. package/dist/neutral/validation/name/Name.d.ts.map +1 -1
  11. package/dist/node/estimate/lib/parseDomainEstimates.d.ts.map +1 -1
  12. package/dist/node/index.mjs +3 -5
  13. package/dist/node/index.mjs.map +1 -1
  14. package/dist/node/validation/name/Name.d.ts +1 -1
  15. package/dist/node/validation/name/Name.d.ts.map +1 -1
  16. package/package.json +24 -20
  17. package/dist/browser/estimate/lib/spec/matchers/customMatchers.d.ts +0 -26
  18. package/dist/browser/estimate/lib/spec/matchers/customMatchers.d.ts.map +0 -1
  19. package/dist/browser/estimate/lib/spec/matchers/index.d.ts +0 -2
  20. package/dist/browser/estimate/lib/spec/matchers/index.d.ts.map +0 -1
  21. package/dist/neutral/estimate/lib/spec/matchers/customMatchers.d.ts +0 -26
  22. package/dist/neutral/estimate/lib/spec/matchers/customMatchers.d.ts.map +0 -1
  23. package/dist/neutral/estimate/lib/spec/matchers/index.d.ts +0 -2
  24. package/dist/neutral/estimate/lib/spec/matchers/index.d.ts.map +0 -1
  25. package/dist/node/estimate/lib/spec/matchers/customMatchers.d.ts +0 -26
  26. package/dist/node/estimate/lib/spec/matchers/customMatchers.d.ts.map +0 -1
  27. package/dist/node/estimate/lib/spec/matchers/index.d.ts +0 -2
  28. package/dist/node/estimate/lib/spec/matchers/index.d.ts.map +0 -1
  29. package/src/estimate/index.ts +0 -1
  30. package/src/estimate/lib/index.ts +0 -1
  31. package/src/estimate/lib/parseDomainEstimates.ts +0 -78
  32. package/src/estimate/lib/spec/matchers/customMatchers.ts +0 -287
  33. package/src/estimate/lib/spec/matchers/index.ts +0 -1
  34. package/src/estimate/lib/spec/matchers/vitest.customMatchers.d.ts +0 -27
  35. package/src/index.ts +0 -2
  36. package/src/validation/index.ts +0 -2
  37. package/src/validation/name/Name.ts +0 -123
  38. package/src/validation/name/index.ts +0 -2
  39. package/src/validation/name/lib/index.ts +0 -1
  40. package/src/validation/name/lib/removeDisallowedCharacters.ts +0 -26
  41. package/src/validation/name/types/ValidSources.ts +0 -1
  42. package/src/validation/name/types/index.ts +0 -1
  43. package/src/validation/validation/Constants.ts +0 -2
  44. package/src/validation/validation/factory/index.ts +0 -1
  45. package/src/validation/validation/factory/validators.ts +0 -47
  46. package/src/validation/validation/index.ts +0 -3
  47. package/src/validation/validation/validators/index.ts +0 -1
  48. package/src/validation/validation/validators/validators.ts +0 -129
@@ -1,2 +0,0 @@
1
- export * from './customMatchers.ts';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/estimate/lib/spec/matchers/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA"}
@@ -1 +0,0 @@
1
- export * from './lib/index.ts'
@@ -1 +0,0 @@
1
- export * from './parseDomainEstimates.ts'
@@ -1,78 +0,0 @@
1
- import { findAs } from '@xylabs/array'
2
- import { exists } from '@xylabs/exists'
3
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
4
- import { isBoundWitness } from '@xyo-network/boundwitness-model'
5
- import type { HashLeaseEstimate } from '@xyo-network/diviner-hash-lease'
6
- import { asHashLeaseEstimate, HashLeaseEstimateSchema } from '@xyo-network/diviner-hash-lease'
7
- import { PayloadBuilder } from '@xyo-network/payload-builder'
8
- import type {
9
- Payload, Schema, WithSources,
10
- } from '@xyo-network/payload-model'
11
- import type {
12
- DomainEstimate,
13
- DomainRegistrationLease,
14
- } from '@xyo-network/xns-record-payload-plugins'
15
- import { asDomainRegistrationLeaseWithSources, DomainRegistrationLeaseSchema } from '@xyo-network/xns-record-payload-plugins'
16
-
17
- /**
18
- * Parses a generic array of payloads into estimates
19
- * @param payloads An array of payloads
20
- * @returns Parsed estimates
21
- */
22
- export const parseDomainEstimates = async (payloads?: Payload[]): Promise<DomainEstimate[]> => {
23
- if (!payloads) return []
24
- const bws = payloads
25
- // Find all bound witnesses
26
- .filter(isBoundWitness)
27
- // that have the required estimate payloads
28
- .filter(hasEstimatePayloads) ?? []
29
- if (bws.length === 0) return []
30
- const hashMap = await PayloadBuilder.toAllHashMap(payloads)
31
- return bws.map<DomainEstimate | undefined>((bw) => {
32
- const hashLeaseEstimate = getPayloadBySchemaFromBoundWitness<WithSources<HashLeaseEstimate>>(
33
- bw,
34
- HashLeaseEstimateSchema,
35
- hashMap,
36
- asHashLeaseEstimate,
37
- )
38
- if (!hashLeaseEstimate) return
39
- const domainLease = getPayloadBySchemaFromBoundWitness<WithSources<DomainRegistrationLease>>(
40
- bw,
41
- DomainRegistrationLeaseSchema,
42
- hashMap,
43
- asDomainRegistrationLeaseWithSources,
44
- )
45
- if (!domainLease) return
46
- return [bw, hashLeaseEstimate, domainLease]
47
- }).filter(exists)
48
- }
49
-
50
- /**
51
- * Tests if a BoundWitness has the required estimate payloads
52
- * @param bw The BoundWitness to check for estimate payloads
53
- * @returns True if the BoundWitness has the required estimate payloads, false otherwise
54
- */
55
- const hasEstimatePayloads = (bw: BoundWitness): boolean => {
56
- return bw.payload_schemas.includes(DomainRegistrationLeaseSchema)
57
- && bw.payload_schemas.includes(HashLeaseEstimateSchema)
58
- }
59
-
60
- /**
61
- * Finds the first instance of a payload in a BoundWitness by schema
62
- * @param bw The BoundWitness to extract the payload from
63
- * @param schema The schema of the payload to extract
64
- * @param hashMap The hashmap of the payloads
65
- * @param identity An identity function to check if the payload is of the correct type
66
- * @returns The payload if it exists or undefined
67
- */
68
- const getPayloadBySchemaFromBoundWitness = <T extends Payload = Payload>(
69
- bw: BoundWitness,
70
- schema: Schema,
71
- hashMap: Awaited<ReturnType<typeof PayloadBuilder.toHashMap>>,
72
- identity: (payload: Payload) => T,
73
- ): T | undefined => {
74
- const schemaIndex = bw.payload_schemas.indexOf(schema)
75
- if (schemaIndex === -1) return
76
- const hash = bw.payload_hashes[schemaIndex]
77
- return findAs([hashMap[hash]], identity)
78
- }
@@ -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,123 +0,0 @@
1
- import { assertEx } from '@xylabs/assert'
2
- import { isHash } from '@xylabs/hex'
3
- import type { Promisable } from '@xylabs/promise'
4
- import type { Payload } from '@xyo-network/payload-model'
5
- import type { DomainFields, TopLevelDomain } from '@xyo-network/xns-record-payload-plugins'
6
- import { DomainSchema } from '@xyo-network/xns-record-payload-plugins'
7
-
8
- import { MAX_DOMAIN_LENGTH, XnsNameSimpleValidators } from '../validation/index.ts'
9
- import { removeDisallowedCharacters } from './lib/index.ts'
10
- import type { ValidSourceTypes } from './types/index.ts'
11
-
12
- const defaultMaskOptions = { maskStartEndHyphens: false }
13
-
14
- export class XnsNameHelper {
15
- static readonly ValidTLDs = ['.xyo'] as const
16
-
17
- private _xnsName: Payload<DomainFields>
18
-
19
- private constructor(xnsName: Payload<DomainFields>) {
20
- this._xnsName = xnsName
21
- }
22
-
23
- get domain() {
24
- return assertEx(this.xnsName.domain, () => 'domain not found in payload')
25
- }
26
-
27
- get name() {
28
- return `${this.domain}.${this.tld}`
29
- }
30
-
31
- get tld() {
32
- return assertEx(this.xnsName.tld, () => 'tld not found in payload')
33
- }
34
-
35
- get xnsName() {
36
- return assertEx(this._xnsName, () => 'XnsNameHelper xnsName not set')
37
- }
38
-
39
- /**
40
- * Create an XnsNameHelper from a domain payload
41
- * @param {Domain} domain
42
- * @returns Promise<XnsNameHelper>
43
- */
44
- static fromPayload(domain: Payload<DomainFields>): Promisable<XnsNameHelper> {
45
- return new XnsNameHelper(domain)
46
- }
47
-
48
- /**
49
- * Create an XnsNameHelper from a string
50
- * @param {string} xnsName
51
- * @returns Promise<XnsNameHelper>
52
- */
53
- static fromString(xnsName: string): XnsNameHelper {
54
- const parts = xnsName.split('.')
55
- assertEx(parts.length === 2, () => 'Unable to parse xnsName')
56
-
57
- const domain = parts[0]
58
- const tld = parts[1] as TopLevelDomain
59
- return new XnsNameHelper({
60
- schema: DomainSchema, domain, tld,
61
- })
62
- }
63
-
64
- /**
65
- * Determine if a string is a valid XNS name or hash
66
- * @param {string} source?
67
- * @returns ValidSourceTypes
68
- */
69
- static isPotentialXnsNameOrHash(source?: string): ValidSourceTypes {
70
- if (isHash(source)) return 'hash'
71
- const xnsName = XnsNameHelper.ValidTLDs.some(tld => source?.endsWith(tld)) ? source : null
72
- return xnsName ? 'xnsName' : null
73
- }
74
-
75
- static async isValid(domain: Payload<DomainFields>): Promise<boolean> {
76
- const results = await Promise.all(XnsNameSimpleValidators.map(validator => validator(domain)))
77
- for (const result of results) {
78
- if (!result) return false
79
- }
80
- return true
81
- }
82
-
83
- /**
84
- * Mask a string to be a valid XNS name
85
- * @param {string} str
86
- * @returns string
87
- */
88
- static mask(str: string, options: { maskStartEndHyphens: boolean } = defaultMaskOptions): string {
89
- // Check if the domain name is too long
90
- if (str.length > MAX_DOMAIN_LENGTH) {
91
- throw new Error(`Domain name too long: ${str.length} exceeds max length: ${MAX_DOMAIN_LENGTH}`)
92
- }
93
-
94
- // convert to lowercase
95
- const lowercaseXnsName = str.toLowerCase()
96
-
97
- // Remove everything except letters, numbers, and dashes
98
-
99
- let formattedXnsName = lowercaseXnsName.replaceAll(/[^\dA-Za-z-]+$/g, '')
100
-
101
- // Remove leading and trailing dashes
102
-
103
- if (options.maskStartEndHyphens) formattedXnsName = formattedXnsName.replaceAll(/^-+|-+$/g, '')
104
-
105
- // Filter out disallowed characters.
106
- return removeDisallowedCharacters(formattedXnsName)
107
- }
108
-
109
- async validate(): Promise<[boolean, string[]]> {
110
- const errorMessages: string[] = []
111
- const onErrorsInternal = (message: string[]) => errorMessages.push(...message)
112
-
113
- for (const validator of XnsNameSimpleValidators) {
114
- await validator(this.xnsName, onErrorsInternal)
115
- }
116
-
117
- if (errorMessages.length > 0) {
118
- return [false, errorMessages]
119
- }
120
-
121
- return [true, []]
122
- }
123
- }
@@ -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'