@xyo-network/payload-validator 2.42.15 → 2.42.17

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 (43) hide show
  1. package/dist/cjs/{Validator/Validator.d.ts → Validator.d.ts} +7 -2
  2. package/dist/cjs/Validator.d.ts.map +1 -0
  3. package/dist/cjs/{Validator/Validator.js → Validator.js} +10 -3
  4. package/dist/cjs/Validator.js.map +1 -0
  5. package/dist/cjs/index.d.ts +0 -1
  6. package/dist/cjs/index.d.ts.map +1 -1
  7. package/dist/cjs/index.js +0 -1
  8. package/dist/cjs/index.js.map +1 -1
  9. package/dist/docs.json +241 -706
  10. package/dist/esm/{Validator/Validator.d.ts → Validator.d.ts} +7 -2
  11. package/dist/esm/Validator.d.ts.map +1 -0
  12. package/dist/esm/{Validator/Validator.js → Validator.js} +9 -3
  13. package/dist/esm/Validator.js.map +1 -0
  14. package/dist/esm/index.d.ts +0 -1
  15. package/dist/esm/index.d.ts.map +1 -1
  16. package/dist/esm/index.js +0 -1
  17. package/dist/esm/index.js.map +1 -1
  18. package/package.json +4 -5
  19. package/src/{Validator/Validator.spec.ts → Validator.spec.ts} +0 -0
  20. package/src/{Validator/Validator.ts → Validator.ts} +17 -4
  21. package/src/index.ts +0 -1
  22. package/dist/cjs/SchemaNameValidator.d.ts +0 -68
  23. package/dist/cjs/SchemaNameValidator.d.ts.map +0 -1
  24. package/dist/cjs/SchemaNameValidator.js +0 -127
  25. package/dist/cjs/SchemaNameValidator.js.map +0 -1
  26. package/dist/cjs/Validator/Validator.d.ts.map +0 -1
  27. package/dist/cjs/Validator/Validator.js.map +0 -1
  28. package/dist/cjs/Validator/index.d.ts +0 -2
  29. package/dist/cjs/Validator/index.d.ts.map +0 -1
  30. package/dist/cjs/Validator/index.js +0 -5
  31. package/dist/cjs/Validator/index.js.map +0 -1
  32. package/dist/esm/SchemaNameValidator.d.ts +0 -68
  33. package/dist/esm/SchemaNameValidator.d.ts.map +0 -1
  34. package/dist/esm/SchemaNameValidator.js +0 -114
  35. package/dist/esm/SchemaNameValidator.js.map +0 -1
  36. package/dist/esm/Validator/Validator.d.ts.map +0 -1
  37. package/dist/esm/Validator/Validator.js.map +0 -1
  38. package/dist/esm/Validator/index.d.ts +0 -2
  39. package/dist/esm/Validator/index.d.ts.map +0 -1
  40. package/dist/esm/Validator/index.js +0 -2
  41. package/dist/esm/Validator/index.js.map +0 -1
  42. package/src/SchemaNameValidator.ts +0 -120
  43. package/src/Validator/index.ts +0 -1
@@ -1,120 +0,0 @@
1
- import { domainExists } from '@xyo-network/dns'
2
-
3
- /**
4
- * Validates a XYO schema structure and existence
5
- */
6
- export class XyoSchemaNameValidator {
7
- public schema?: string
8
- private _parts?: string[]
9
- private _rootDomain?: string
10
- constructor(schema?: string) {
11
- this.schema = schema
12
- }
13
-
14
- /**
15
- * Checks whether the schema is all lowercase
16
- *
17
- * @returns boolean
18
- */
19
- get isLowercase(): boolean {
20
- return this.schema === this.schema?.toLowerCase()
21
- }
22
-
23
- /**
24
- * Levels in the schema
25
- *
26
- * @returns number
27
- */
28
- get levels(): number | undefined {
29
- return this.parts?.length
30
- }
31
-
32
- /**
33
- * The schema converted into a string array split on '.'
34
- *
35
- * @returns string[]
36
- */
37
- get parts() {
38
- this._parts = this._parts ?? this.schema?.split('.')
39
- return this._parts
40
- }
41
-
42
- /**
43
- * The rootDomain is the first two levels of the schema, in reverse order
44
- * This can be used to determine who 'owns' that schema, based on domain
45
- * registration
46
- *
47
- * @returns string
48
- */
49
- get rootDomain(): string | undefined {
50
- this._rootDomain = this._rootDomain ?? this.domainLevel(1)
51
- return this._rootDomain
52
- }
53
-
54
- /**
55
- * Run all static validations
56
- * @returns Error[]
57
- */
58
-
59
- public all() {
60
- const errors: Error[] = []
61
- if ((this.schema?.length ?? 0) === 0) errors.push(Error('schema missing'))
62
- else if ((this.levels ?? 0) < 3) errors.push(Error(`schema levels < 3 [${this.levels}, ${this.schema}]`))
63
- else if (!this.isLowercase) errors.push(Error(`schema not lowercase [${this.schema}]`))
64
- return errors
65
- }
66
-
67
- /**
68
- * Run all the validations
69
- * @param checkExistance - boolean
70
- * @returns Error[]
71
- */
72
-
73
- public async allDynamic() {
74
- const errors: Error[] = []
75
- if ((this.schema?.length ?? 0) === 0) errors.push(Error('schema missing'))
76
- else if (!(await this.rootDomainExists())) errors.push(Error(`schema root domain must exist [${this.rootDomain}]`))
77
- return errors
78
- }
79
-
80
- /**
81
- * Determines how many levels of the schema's reverse domain
82
- * pass DNS resolution
83
- *
84
- * @returns number (0 if none exist)
85
- */
86
- public async domainExistenceDepth() {
87
- const levels = this.levels ?? 0
88
- let level = 0
89
- while (level < levels) {
90
- if (!(await domainExists(this.domainLevel(level)))) {
91
- break
92
- }
93
- level += 1
94
- }
95
- return level
96
- }
97
-
98
- /**
99
- * Checks if the root domain validates via DNS resolution
100
- *
101
- * @returns boolean
102
- */
103
- public async rootDomainExists() {
104
- return await domainExists(this.rootDomain)
105
- }
106
-
107
- /**
108
- *
109
- * Get a domain for the schema at a certain level
110
- *
111
- * @param level - Zero based level to check
112
- * @returns string
113
- */
114
- private domainLevel(level: number): string | undefined {
115
- return this.parts
116
- ?.slice(0, level + 1)
117
- .reverse()
118
- .join('.')
119
- }
120
- }
@@ -1 +0,0 @@
1
- export * from './Validator'