@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.
- package/dist/browser/estimate/lib/parseDomainEstimates.d.ts.map +1 -1
- package/dist/browser/index.mjs +3 -5
- package/dist/browser/index.mjs.map +1 -1
- package/dist/browser/validation/name/Name.d.ts +1 -1
- package/dist/browser/validation/name/Name.d.ts.map +1 -1
- package/dist/neutral/estimate/lib/parseDomainEstimates.d.ts.map +1 -1
- package/dist/neutral/index.mjs +3 -5
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/validation/name/Name.d.ts +1 -1
- package/dist/neutral/validation/name/Name.d.ts.map +1 -1
- package/dist/node/estimate/lib/parseDomainEstimates.d.ts.map +1 -1
- package/dist/node/index.mjs +3 -5
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/validation/name/Name.d.ts +1 -1
- package/dist/node/validation/name/Name.d.ts.map +1 -1
- package/package.json +24 -20
- package/dist/browser/estimate/lib/spec/matchers/customMatchers.d.ts +0 -26
- package/dist/browser/estimate/lib/spec/matchers/customMatchers.d.ts.map +0 -1
- package/dist/browser/estimate/lib/spec/matchers/index.d.ts +0 -2
- package/dist/browser/estimate/lib/spec/matchers/index.d.ts.map +0 -1
- package/dist/neutral/estimate/lib/spec/matchers/customMatchers.d.ts +0 -26
- package/dist/neutral/estimate/lib/spec/matchers/customMatchers.d.ts.map +0 -1
- package/dist/neutral/estimate/lib/spec/matchers/index.d.ts +0 -2
- package/dist/neutral/estimate/lib/spec/matchers/index.d.ts.map +0 -1
- package/dist/node/estimate/lib/spec/matchers/customMatchers.d.ts +0 -26
- package/dist/node/estimate/lib/spec/matchers/customMatchers.d.ts.map +0 -1
- package/dist/node/estimate/lib/spec/matchers/index.d.ts +0 -2
- package/dist/node/estimate/lib/spec/matchers/index.d.ts.map +0 -1
- package/src/estimate/index.ts +0 -1
- package/src/estimate/lib/index.ts +0 -1
- package/src/estimate/lib/parseDomainEstimates.ts +0 -78
- package/src/estimate/lib/spec/matchers/customMatchers.ts +0 -287
- package/src/estimate/lib/spec/matchers/index.ts +0 -1
- package/src/estimate/lib/spec/matchers/vitest.customMatchers.d.ts +0 -27
- package/src/index.ts +0 -2
- package/src/validation/index.ts +0 -2
- package/src/validation/name/Name.ts +0 -123
- package/src/validation/name/index.ts +0 -2
- package/src/validation/name/lib/index.ts +0 -1
- package/src/validation/name/lib/removeDisallowedCharacters.ts +0 -26
- package/src/validation/name/types/ValidSources.ts +0 -1
- package/src/validation/name/types/index.ts +0 -1
- package/src/validation/validation/Constants.ts +0 -2
- package/src/validation/validation/factory/index.ts +0 -1
- package/src/validation/validation/factory/validators.ts +0 -47
- package/src/validation/validation/index.ts +0 -3
- package/src/validation/validation/validators/index.ts +0 -1
- package/src/validation/validation/validators/validators.ts +0 -129
|
@@ -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))
|