@xyo-network/payload 2.42.13 → 2.42.15

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 (177) hide show
  1. package/dist/cjs/Payloads.d.ts +1 -1
  2. package/dist/cjs/Payloads.d.ts.map +1 -1
  3. package/dist/cjs/index.d.ts +5 -6
  4. package/dist/cjs/index.d.ts.map +1 -1
  5. package/dist/cjs/index.js +5 -6
  6. package/dist/cjs/index.js.map +1 -1
  7. package/dist/cjs/isXyoPayloadOfSchemaType.d.ts +2 -2
  8. package/dist/cjs/isXyoPayloadOfSchemaType.d.ts.map +1 -1
  9. package/dist/docs.json +1300 -1630
  10. package/dist/esm/Payloads.d.ts +1 -1
  11. package/dist/esm/Payloads.d.ts.map +1 -1
  12. package/dist/esm/index.d.ts +5 -6
  13. package/dist/esm/index.d.ts.map +1 -1
  14. package/dist/esm/index.js +5 -6
  15. package/dist/esm/index.js.map +1 -1
  16. package/dist/esm/isXyoPayloadOfSchemaType.d.ts +2 -2
  17. package/dist/esm/isXyoPayloadOfSchemaType.d.ts.map +1 -1
  18. package/package.json +7 -8
  19. package/src/Payloads.ts +1 -1
  20. package/src/index.ts +5 -6
  21. package/src/isXyoPayloadOfSchemaType.ts +1 -1
  22. package/dist/cjs/Builder/Builder.d.ts +0 -13
  23. package/dist/cjs/Builder/Builder.d.ts.map +0 -1
  24. package/dist/cjs/Builder/Builder.js +0 -27
  25. package/dist/cjs/Builder/Builder.js.map +0 -1
  26. package/dist/cjs/Builder/index.d.ts +0 -2
  27. package/dist/cjs/Builder/index.d.ts.map +0 -1
  28. package/dist/cjs/Builder/index.js +0 -5
  29. package/dist/cjs/Builder/index.js.map +0 -1
  30. package/dist/cjs/Huri/Huri.d.ts +0 -32
  31. package/dist/cjs/Huri/Huri.d.ts.map +0 -1
  32. package/dist/cjs/Huri/Huri.js +0 -111
  33. package/dist/cjs/Huri/Huri.js.map +0 -1
  34. package/dist/cjs/Huri/index.d.ts +0 -2
  35. package/dist/cjs/Huri/index.d.ts.map +0 -1
  36. package/dist/cjs/Huri/index.js +0 -5
  37. package/dist/cjs/Huri/index.js.map +0 -1
  38. package/dist/cjs/SchemaNameValidator.d.ts +0 -68
  39. package/dist/cjs/SchemaNameValidator.d.ts.map +0 -1
  40. package/dist/cjs/SchemaNameValidator.js +0 -127
  41. package/dist/cjs/SchemaNameValidator.js.map +0 -1
  42. package/dist/cjs/Test/index.d.ts +0 -2
  43. package/dist/cjs/Test/index.d.ts.map +0 -1
  44. package/dist/cjs/Test/index.js +0 -5
  45. package/dist/cjs/Test/index.js.map +0 -1
  46. package/dist/cjs/Test/testPayload.d.ts +0 -6
  47. package/dist/cjs/Test/testPayload.d.ts.map +0 -1
  48. package/dist/cjs/Test/testPayload.js +0 -16
  49. package/dist/cjs/Test/testPayload.js.map +0 -1
  50. package/dist/cjs/Validator/Validator.d.ts +0 -11
  51. package/dist/cjs/Validator/Validator.d.ts.map +0 -1
  52. package/dist/cjs/Validator/Validator.js +0 -32
  53. package/dist/cjs/Validator/Validator.js.map +0 -1
  54. package/dist/cjs/Validator/index.d.ts +0 -2
  55. package/dist/cjs/Validator/index.d.ts.map +0 -1
  56. package/dist/cjs/Validator/index.js +0 -5
  57. package/dist/cjs/Validator/index.js.map +0 -1
  58. package/dist/cjs/Wrapper/Wrapper.d.ts +0 -23
  59. package/dist/cjs/Wrapper/Wrapper.d.ts.map +0 -1
  60. package/dist/cjs/Wrapper/Wrapper.js +0 -63
  61. package/dist/cjs/Wrapper/Wrapper.js.map +0 -1
  62. package/dist/cjs/Wrapper/index.d.ts +0 -2
  63. package/dist/cjs/Wrapper/index.d.ts.map +0 -1
  64. package/dist/cjs/Wrapper/index.js +0 -5
  65. package/dist/cjs/Wrapper/index.js.map +0 -1
  66. package/dist/cjs/models/PayloadFindFilter.d.ts +0 -16
  67. package/dist/cjs/models/PayloadFindFilter.d.ts.map +0 -1
  68. package/dist/cjs/models/PayloadFindFilter.js +0 -3
  69. package/dist/cjs/models/PayloadFindFilter.js.map +0 -1
  70. package/dist/cjs/models/PayloadSet/PayloadSetPayload.d.ts +0 -8
  71. package/dist/cjs/models/PayloadSet/PayloadSetPayload.d.ts.map +0 -1
  72. package/dist/cjs/models/PayloadSet/PayloadSetPayload.js +0 -3
  73. package/dist/cjs/models/PayloadSet/PayloadSetPayload.js.map +0 -1
  74. package/dist/cjs/models/PayloadSet/PayloadSetSchema.d.ts +0 -3
  75. package/dist/cjs/models/PayloadSet/PayloadSetSchema.d.ts.map +0 -1
  76. package/dist/cjs/models/PayloadSet/PayloadSetSchema.js +0 -5
  77. package/dist/cjs/models/PayloadSet/PayloadSetSchema.js.map +0 -1
  78. package/dist/cjs/models/PayloadSet/index.d.ts +0 -3
  79. package/dist/cjs/models/PayloadSet/index.d.ts.map +0 -1
  80. package/dist/cjs/models/PayloadSet/index.js +0 -6
  81. package/dist/cjs/models/PayloadSet/index.js.map +0 -1
  82. package/dist/cjs/models/XyoPayload.d.ts +0 -21
  83. package/dist/cjs/models/XyoPayload.d.ts.map +0 -1
  84. package/dist/cjs/models/XyoPayload.js +0 -5
  85. package/dist/cjs/models/XyoPayload.js.map +0 -1
  86. package/dist/cjs/models/index.d.ts +0 -4
  87. package/dist/cjs/models/index.d.ts.map +0 -1
  88. package/dist/cjs/models/index.js +0 -7
  89. package/dist/cjs/models/index.js.map +0 -1
  90. package/dist/esm/Builder/Builder.d.ts +0 -13
  91. package/dist/esm/Builder/Builder.d.ts.map +0 -1
  92. package/dist/esm/Builder/Builder.js +0 -27
  93. package/dist/esm/Builder/Builder.js.map +0 -1
  94. package/dist/esm/Builder/index.d.ts +0 -2
  95. package/dist/esm/Builder/index.d.ts.map +0 -1
  96. package/dist/esm/Builder/index.js +0 -2
  97. package/dist/esm/Builder/index.js.map +0 -1
  98. package/dist/esm/Huri/Huri.d.ts +0 -32
  99. package/dist/esm/Huri/Huri.d.ts.map +0 -1
  100. package/dist/esm/Huri/Huri.js +0 -104
  101. package/dist/esm/Huri/Huri.js.map +0 -1
  102. package/dist/esm/Huri/index.d.ts +0 -2
  103. package/dist/esm/Huri/index.d.ts.map +0 -1
  104. package/dist/esm/Huri/index.js +0 -2
  105. package/dist/esm/Huri/index.js.map +0 -1
  106. package/dist/esm/SchemaNameValidator.d.ts +0 -68
  107. package/dist/esm/SchemaNameValidator.d.ts.map +0 -1
  108. package/dist/esm/SchemaNameValidator.js +0 -114
  109. package/dist/esm/SchemaNameValidator.js.map +0 -1
  110. package/dist/esm/Test/index.d.ts +0 -2
  111. package/dist/esm/Test/index.d.ts.map +0 -1
  112. package/dist/esm/Test/index.js +0 -2
  113. package/dist/esm/Test/index.js.map +0 -1
  114. package/dist/esm/Test/testPayload.d.ts +0 -6
  115. package/dist/esm/Test/testPayload.d.ts.map +0 -1
  116. package/dist/esm/Test/testPayload.js +0 -12
  117. package/dist/esm/Test/testPayload.js.map +0 -1
  118. package/dist/esm/Validator/Validator.d.ts +0 -11
  119. package/dist/esm/Validator/Validator.d.ts.map +0 -1
  120. package/dist/esm/Validator/Validator.js +0 -28
  121. package/dist/esm/Validator/Validator.js.map +0 -1
  122. package/dist/esm/Validator/index.d.ts +0 -2
  123. package/dist/esm/Validator/index.d.ts.map +0 -1
  124. package/dist/esm/Validator/index.js +0 -2
  125. package/dist/esm/Validator/index.js.map +0 -1
  126. package/dist/esm/Wrapper/Wrapper.d.ts +0 -23
  127. package/dist/esm/Wrapper/Wrapper.d.ts.map +0 -1
  128. package/dist/esm/Wrapper/Wrapper.js +0 -52
  129. package/dist/esm/Wrapper/Wrapper.js.map +0 -1
  130. package/dist/esm/Wrapper/index.d.ts +0 -2
  131. package/dist/esm/Wrapper/index.d.ts.map +0 -1
  132. package/dist/esm/Wrapper/index.js +0 -2
  133. package/dist/esm/Wrapper/index.js.map +0 -1
  134. package/dist/esm/models/PayloadFindFilter.d.ts +0 -16
  135. package/dist/esm/models/PayloadFindFilter.d.ts.map +0 -1
  136. package/dist/esm/models/PayloadFindFilter.js +0 -2
  137. package/dist/esm/models/PayloadFindFilter.js.map +0 -1
  138. package/dist/esm/models/PayloadSet/PayloadSetPayload.d.ts +0 -8
  139. package/dist/esm/models/PayloadSet/PayloadSetPayload.d.ts.map +0 -1
  140. package/dist/esm/models/PayloadSet/PayloadSetPayload.js +0 -2
  141. package/dist/esm/models/PayloadSet/PayloadSetPayload.js.map +0 -1
  142. package/dist/esm/models/PayloadSet/PayloadSetSchema.d.ts +0 -3
  143. package/dist/esm/models/PayloadSet/PayloadSetSchema.d.ts.map +0 -1
  144. package/dist/esm/models/PayloadSet/PayloadSetSchema.js +0 -2
  145. package/dist/esm/models/PayloadSet/PayloadSetSchema.js.map +0 -1
  146. package/dist/esm/models/PayloadSet/index.d.ts +0 -3
  147. package/dist/esm/models/PayloadSet/index.d.ts.map +0 -1
  148. package/dist/esm/models/PayloadSet/index.js +0 -3
  149. package/dist/esm/models/PayloadSet/index.js.map +0 -1
  150. package/dist/esm/models/XyoPayload.d.ts +0 -21
  151. package/dist/esm/models/XyoPayload.d.ts.map +0 -1
  152. package/dist/esm/models/XyoPayload.js +0 -2
  153. package/dist/esm/models/XyoPayload.js.map +0 -1
  154. package/dist/esm/models/index.d.ts +0 -4
  155. package/dist/esm/models/index.d.ts.map +0 -1
  156. package/dist/esm/models/index.js +0 -4
  157. package/dist/esm/models/index.js.map +0 -1
  158. package/src/Builder/Builder.spec.ts +0 -38
  159. package/src/Builder/Builder.ts +0 -37
  160. package/src/Builder/index.ts +0 -1
  161. package/src/Huri/Huri.spec.ts +0 -92
  162. package/src/Huri/Huri.ts +0 -154
  163. package/src/Huri/index.ts +0 -1
  164. package/src/SchemaNameValidator.ts +0 -120
  165. package/src/Test/index.ts +0 -1
  166. package/src/Test/testPayload.ts +0 -16
  167. package/src/Validator/Validator.spec.ts +0 -52
  168. package/src/Validator/Validator.ts +0 -33
  169. package/src/Validator/index.ts +0 -1
  170. package/src/Wrapper/Wrapper.ts +0 -69
  171. package/src/Wrapper/index.ts +0 -1
  172. package/src/models/PayloadFindFilter.ts +0 -19
  173. package/src/models/PayloadSet/PayloadSetPayload.ts +0 -9
  174. package/src/models/PayloadSet/PayloadSetSchema.ts +0 -2
  175. package/src/models/PayloadSet/index.ts +0 -2
  176. package/src/models/XyoPayload.ts +0 -31
  177. package/src/models/index.ts +0 -3
@@ -1,92 +0,0 @@
1
- import { delay } from '@xylabs/delay'
2
-
3
- import { XyoPayload } from '../models'
4
- import { Huri } from './Huri'
5
-
6
- const hash = 'fb3606d71dcdd49a0aacc9d234e412684d577803c8a9ed9399a9d3776cc88e24'
7
-
8
- const valid = [
9
- `https://${hash}`,
10
- `https://api.archivist.xyo.network/temp/${hash}`,
11
- `https://api.archivist.xyo.network/${hash}`,
12
- `http://api.archivist.xyo.network/${hash}`,
13
- `/api.archivist.xyo.network/${hash}`,
14
- `//${hash}`,
15
- `/${hash}`,
16
- `${hash}`,
17
- ]
18
-
19
- const validWithTempArchive = [
20
- `https://api.archivist.xyo.network/temp/${hash}`,
21
- `https://api.archivist.xyo.network/temp/${hash}`,
22
- `http://api.archivist.xyo.network/temp/${hash}`,
23
- `/api.archivist.xyo.network/temp/${hash}`,
24
- ]
25
-
26
- const invalid = [`https:///api.archivist.xyo.network/${hash}`, `https://api.archivist.xyo.network//${hash}`]
27
-
28
- describe('Huri', () => {
29
- describe('Valid Items', () => {
30
- valid.map((item) => {
31
- test(`valid [${item}]`, () => {
32
- try {
33
- const huri = new Huri(item)
34
- expect(huri.hash).toBe(hash)
35
- } catch (ex) {
36
- console.error(`Valid Huri failed: [${item}]`)
37
- console.error(ex)
38
- }
39
- })
40
- })
41
- })
42
- describe('Valid Items w/archive', () => {
43
- validWithTempArchive.map((item) => {
44
- test(`valid w/archive [${item}]`, () => {
45
- try {
46
- const huri = new Huri(item)
47
- expect(huri.hash).toBe(hash)
48
- expect(huri.archive).toBe('temp')
49
- } catch (ex) {
50
- console.error(`Valid Huri w/archive failed: [${item}]`)
51
- console.error(ex)
52
- }
53
- })
54
- })
55
- })
56
- describe('Invalid Items', () => {
57
- invalid.map((item) => {
58
- test(`invalid [${item}]`, () => {
59
- expect(() => new Huri(item)).toThrowError()
60
- })
61
- })
62
- })
63
- describe('Api Fetch', () => {
64
- it('Valid Huri', async () => {
65
- const huri = new Huri('https://beta.api.archivist.xyo.network/18f97b3e85f5bede65e7c0a85d74aee896de58ead8bc4b1b3d7300646c653057')
66
- const result = await huri.fetch()
67
- expect(result?.schema).toBe('network.xyo.schema')
68
- })
69
- it('Invalid Huri', async () => {
70
- const huri = new Huri('https://beta.api.archivist.xyo.network/18f97b3e85f5bede65e7c0a85d74aee896de58ead8bc4b1b3d7300646c653bad')
71
- await expect(huri.fetch()).rejects.toThrow()
72
- })
73
- })
74
- describe('Fetch Override', () => {
75
- invalid.map((item) => {
76
- test(`invalid [${item}]`, async () => {
77
- const oldFetch = Huri.fetch
78
- Huri.fetch = async <T extends XyoPayload = XyoPayload>(huri: Huri): Promise<T | undefined> => {
79
- await delay(0)
80
- const payload: T = {
81
- schema: huri.hash,
82
- } as T
83
- return payload
84
- }
85
- const huri = new Huri('https://beta.api.archivist.xyo.network/18f97b3e85f5bede65e7c0a85d74aee896de58ead8bc4b1b3d7300646c653057')
86
- const result = await huri.fetch()
87
- Huri.fetch = oldFetch
88
- expect(result?.schema).toBe('18f97b3e85f5bede65e7c0a85d74aee896de58ead8bc4b1b3d7300646c653057')
89
- })
90
- })
91
- })
92
- })
package/src/Huri/Huri.ts DELETED
@@ -1,154 +0,0 @@
1
- import { assertEx } from '@xylabs/assert'
2
- import { AddressValue } from '@xyo-network/account'
3
- import { DataLike } from '@xyo-network/core'
4
- import axios from 'axios'
5
-
6
- import { XyoPayload } from '../models'
7
-
8
- export type XyoObjectCategory = 'block' | 'payload'
9
-
10
- export type HuriFetchFunction = (huri: Huri) => Promise<XyoPayload | undefined>
11
-
12
- /*
13
- Valid Huri:
14
-
15
- [<protocol>://][<archivist>/[<archive>/]]<hash>
16
-
17
- defaults:
18
- protocol: https
19
- archivist: api.archivist.xyo.network
20
- */
21
-
22
- export interface HuriOptions {
23
- archivistUri?: string
24
- }
25
-
26
- export interface FetchedPayload<T extends XyoPayload = XyoPayload> {
27
- huri?: Huri
28
- payload: T
29
- }
30
-
31
- export class Huri<T extends XyoPayload = XyoPayload> {
32
- public archive?: string
33
- public archivist?: string
34
- public hash: string
35
- public originalHref: string
36
- public protocol?: string
37
-
38
- private isHuri = true
39
-
40
- constructor(huri: DataLike | Huri, { archivistUri }: HuriOptions = {}) {
41
- const huriString = Huri.isHuri(huri)?.href ?? typeof huri === 'string' ? (huri as string) : new AddressValue(huri as DataLike).hex
42
- this.originalHref = huriString
43
-
44
- const protocol = Huri.parseProtocol(huriString)
45
- this.protocol = protocol ?? 'https'
46
-
47
- const path = assertEx(Huri.parsePath(huriString), 'Missing path')
48
- this.hash = this.parsePath(path, protocol !== undefined)
49
-
50
- //if archivistUri sent, overwrite protocol and archivist
51
- if (archivistUri) {
52
- const archivistUriParts = archivistUri.split('://')
53
- this.protocol = archivistUriParts[0]
54
- this.archivist = archivistUriParts[1]
55
- }
56
-
57
- this.validateParse()
58
- }
59
-
60
- /*
61
- The full href or the hash
62
- */
63
- public get href() {
64
- const parts: string[] = []
65
- if (this.protocol) {
66
- parts.push(`${this.protocol}:/`)
67
- }
68
- if (this.archive) {
69
- parts.push(`${this.archive}`)
70
- }
71
- if (this.archivist) {
72
- parts.push(`${this.archivist}`)
73
- }
74
- parts.push(this.hash)
75
- return parts.join('/')
76
- }
77
-
78
- static async fetch<T extends XyoPayload = XyoPayload>(huri: Huri): Promise<T | undefined> {
79
- return (await axios.get<T>(huri.href)).data
80
- }
81
-
82
- public static isHuri(value: unknown) {
83
- if (typeof value === 'object') {
84
- return (value as Huri).isHuri ? (value as Huri) : undefined
85
- }
86
- return undefined
87
- }
88
-
89
- private static parsePath(huri: string) {
90
- const protocolSplit = huri.split('//')
91
- assertEx(protocolSplit.length <= 2, `Invalid format [${huri}]`)
92
- if (protocolSplit.length === 1) {
93
- return huri
94
- }
95
- if (protocolSplit.length === 2) {
96
- return protocolSplit[1]
97
- }
98
- }
99
-
100
- private static parseProtocol(huri: string) {
101
- const protocolSplit = huri.split('//')
102
- assertEx(protocolSplit.length <= 2, `Invalid second protocol [${protocolSplit[2]}]`)
103
- const rawProtocol = protocolSplit.length === 2 ? protocolSplit.shift() : undefined
104
- if (rawProtocol) {
105
- const protocolParts = rawProtocol?.split(':')
106
- assertEx(protocolParts.length === 2, `Invalid protocol format [${rawProtocol}]`)
107
- assertEx(protocolParts[1].length === 0, `Invalid protocol format (post :) [${rawProtocol}]`)
108
- return protocolParts.shift()
109
- }
110
- }
111
-
112
- public async fetch(): Promise<T | undefined> {
113
- return await Huri.fetch<T>(this)
114
- }
115
-
116
- public toString() {
117
- return this.href
118
- }
119
-
120
- private parsePath(path: string, hasProtocol: boolean) {
121
- const pathParts = path.split('/')
122
-
123
- //if the protocol was found, then there is not allowed to be a leading /
124
- assertEx(!(hasProtocol && pathParts[0].length === 0), 'Invalid protocol separator')
125
-
126
- //remove leading '/' if needed
127
- pathParts[0].length === 0 ? pathParts.shift() : null
128
-
129
- //hash is assumed to be the last part
130
- const hash = assertEx(pathParts.pop(), 'No hash specified')
131
-
132
- //archivist is assumed to be the first part
133
- this.archivist = pathParts.shift() ?? 'api.archivist.xyo.network'
134
-
135
- //the archive is whatever is left
136
- this.archive = pathParts.pop()
137
-
138
- //after we pull off all the path parts, there should be nothing left
139
- assertEx(pathParts.length === 0, 'Too many path parts')
140
-
141
- return hash
142
- }
143
-
144
- private validateParse() {
145
- //the archivist should not be zero length
146
- assertEx(this.archivist?.length !== 0, 'Invalid archivist length')
147
-
148
- //the archivist should not be zero length (can be undefined)
149
- assertEx(this.archive?.length !== 0, 'Invalid archive length')
150
-
151
- //the archive should not be set if the archivist is not set
152
- assertEx(!(this.archive && !this.archivist), 'If specifying archive, archivist is also required')
153
- }
154
- }
package/src/Huri/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './Huri'
@@ -1,120 +0,0 @@
1
- import { domainExists } from '@xyo-network/core'
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
- }
package/src/Test/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './testPayload'
@@ -1,16 +0,0 @@
1
- import { StringKeyObject } from '@xyo-network/core'
2
-
3
- import { XyoPayload } from '../models'
4
-
5
- const testSchema = 'network.xyo.test'
6
- const testPayload: XyoPayload<StringKeyObject> = {
7
- numberField: 1,
8
- objectField: {
9
- numberField: 1,
10
- stringField: 'stringValue',
11
- },
12
- schema: testSchema,
13
- stringField: 'stringValue',
14
- }
15
-
16
- export { testPayload, testSchema }
@@ -1,52 +0,0 @@
1
- import { dumpErrors } from '@xyo-network/core'
2
-
3
- import { XyoPayload } from '../models'
4
- import { PayloadValidator } from './Validator'
5
-
6
- const testPayloadNoSchema: XyoPayload = {} as XyoPayload
7
- const testPayloadMixedCase: XyoPayload = {
8
- schema: 'network.xyo.testMixedCaseSchema',
9
- } as XyoPayload
10
- const testPayloadTooFewLevels: XyoPayload = {
11
- schema: 'network.xyo',
12
- } as XyoPayload
13
- const testPayloadDoesNotExist: XyoPayload = {
14
- schema: 'network.dfd-sf-sf-s.blahblah',
15
- } as XyoPayload
16
- const testPayloadValid: XyoPayload = {
17
- schema: 'network.xyo.test',
18
- } as XyoPayload
19
-
20
- test('all [missing schema]', () => {
21
- const validator = new PayloadValidator(testPayloadNoSchema)
22
- const errors = validator.validate()
23
- expect(errors.length).toBe(1)
24
- })
25
-
26
- test('all [mixed case]', () => {
27
- const validator = new PayloadValidator(testPayloadMixedCase)
28
- const errors = validator.validate()
29
- expect(errors.length).toBe(1)
30
- })
31
-
32
- test('all [too few levels]', () => {
33
- const validator = new PayloadValidator(testPayloadTooFewLevels)
34
- const errors = validator.validate()
35
- expect(errors.length).toBe(1)
36
- })
37
-
38
- test('all [does not exist]', () => {
39
- const validator = new PayloadValidator(testPayloadDoesNotExist)
40
- const errors = validator.validate()
41
- dumpErrors(errors)
42
- expect(errors.length).toBe(0)
43
- })
44
-
45
- test('all [valid]', () => {
46
- const validator = new PayloadValidator(testPayloadValid)
47
-
48
- let errors: Error[] = []
49
- errors = validator.validate()
50
- dumpErrors(errors)
51
- expect(errors.length).toBe(0)
52
- })
@@ -1,33 +0,0 @@
1
- import { Validator, XyoValidatorBase } from '@xyo-network/core'
2
-
3
- import { XyoPayload } from '../models'
4
- import { XyoSchemaNameValidator } from '../SchemaNameValidator'
5
-
6
- export class PayloadValidator<T extends XyoPayload = XyoPayload> extends XyoValidatorBase<T> implements Validator<T> {
7
- private _schemaValidator?: XyoSchemaNameValidator
8
-
9
- constructor(payload: T) {
10
- super(payload)
11
- }
12
-
13
- get schemaValidator() {
14
- this._schemaValidator = this._schemaValidator ?? new XyoSchemaNameValidator(this.obj.schema ?? '')
15
- return this._schemaValidator
16
- }
17
-
18
- public schemaName() {
19
- const errors: Error[] = []
20
- if (this.obj.schema === undefined) {
21
- errors.push(Error('schema missing'))
22
- } else {
23
- errors.push(...this.schemaValidator.all())
24
- }
25
- return errors
26
- }
27
-
28
- public validate() {
29
- const errors: Error[] = []
30
- errors.push(...this.schemaName())
31
- return errors
32
- }
33
- }
@@ -1 +0,0 @@
1
- export * from './Validator'
@@ -1,69 +0,0 @@
1
- import { assertEx } from '@xylabs/assert'
2
- import { DataLike, deepOmitUnderscoreFields, Hasher } from '@xyo-network/core'
3
- import { Promisable } from '@xyo-network/promise'
4
-
5
- import { Huri } from '../Huri'
6
- import { XyoPayload } from '../models'
7
- import { PayloadValidator } from '../Validator'
8
-
9
- export abstract class PayloadWrapperBase<TPayload extends XyoPayload = XyoPayload> extends Hasher<TPayload> {
10
- public get body() {
11
- return deepOmitUnderscoreFields<TPayload>(this.obj)
12
- }
13
-
14
- get errors() {
15
- return new PayloadValidator(this.payload).validate()
16
- }
17
-
18
- public get payload() {
19
- return assertEx(this.obj, 'Missing payload object')
20
- }
21
-
22
- public get previousHash() {
23
- return null
24
- }
25
-
26
- public get schema() {
27
- return this.payload.schema
28
- }
29
-
30
- //intentionally not naming this 'schema' so that the wrapper is not confused for a XyoPayload
31
- public get schemaName() {
32
- return assertEx(this.obj.schema, 'Missing payload schema')
33
- }
34
-
35
- get valid() {
36
- return this.errors.length === 0
37
- }
38
-
39
- public static load(_address: DataLike | Huri): Promisable<PayloadWrapperBase | null> {
40
- throw Error('Not implemented')
41
- }
42
-
43
- public static parse(_obj: unknown): PayloadWrapperBase {
44
- throw Error('Not implemented')
45
- }
46
- }
47
-
48
- export class PayloadWrapper<TPayload extends XyoPayload = XyoPayload> extends PayloadWrapperBase<TPayload> {
49
- private isPayloadWrapper = true
50
-
51
- public static override async load(address: DataLike | Huri) {
52
- const payload = await new Huri(address).fetch()
53
- return payload ? new PayloadWrapper(payload) : null
54
- }
55
-
56
- public static override parse<T extends XyoPayload = XyoPayload>(obj: unknown): PayloadWrapper<T> {
57
- assertEx(!Array.isArray(obj), 'Array can not be converted to PayloadWrapper')
58
- switch (typeof obj) {
59
- case 'object': {
60
- const castWrapper = obj as PayloadWrapper<T>
61
- return assertEx(
62
- castWrapper?.isPayloadWrapper ? castWrapper : (obj as XyoPayload).schema ? new PayloadWrapper(obj as T) : null,
63
- 'Unable to parse payload object',
64
- )
65
- }
66
- }
67
- throw Error(`Unable to parse [${typeof obj}]`)
68
- }
69
- }
@@ -1 +0,0 @@
1
- export * from './Wrapper'
@@ -1,19 +0,0 @@
1
- /** @deprecated use offset as a string (hash) instead */
2
- export interface PayloadFindFilterTimeOffset {
3
- offset?: number
4
- }
5
-
6
- export interface PayloadFindFilterHashOffset {
7
- offset?: string
8
- }
9
-
10
- // eslint-disable-next-line deprecation/deprecation
11
- export type PayloadFindFilterOffset = PayloadFindFilterTimeOffset | PayloadFindFilterHashOffset
12
-
13
- export type PayloadFindFilter = {
14
- limit?: number
15
- order?: 'desc' | 'asc'
16
- schema?: string | string[]
17
- /** @deprecated use offset instead */
18
- timestamp?: number
19
- } & PayloadFindFilterOffset
@@ -1,9 +0,0 @@
1
- import { XyoPayload } from '../XyoPayload'
2
- import { PayloadSetSchema } from './PayloadSetSchema'
3
-
4
- export interface PayloadSet {
5
- optional?: Record<string, number>
6
- required?: Record<string, number>
7
- }
8
-
9
- export type PayloadSetPayload = XyoPayload<PayloadSet, PayloadSetSchema>
@@ -1,2 +0,0 @@
1
- export type PayloadSetSchema = 'network.xyo.payload.set'
2
- export const PayloadSetSchema: PayloadSetSchema = 'network.xyo.payload.set'
@@ -1,2 +0,0 @@
1
- export * from './PayloadSetPayload'
2
- export * from './PayloadSetSchema'
@@ -1,31 +0,0 @@
1
- import { EmptyObject } from '@xyo-network/core'
2
-
3
- export type WithTimestamp<T extends EmptyObject = EmptyObject> = T & { timestamp: number }
4
-
5
- export type XyoPayloadSchema = 'network.xyo.payload'
6
- export const XyoPayloadSchema: XyoPayloadSchema = 'network.xyo.payload'
7
-
8
- export type SchemaFields = {
9
- schema: string
10
- }
11
-
12
- export type WithSchema<T extends EmptyObject | void = void> = T extends EmptyObject ? SchemaFields & T : SchemaFields
13
-
14
- export type PayloadFields = {
15
- sources?: string[]
16
- timestamp?: number
17
- }
18
-
19
- export type WithPayload<T extends EmptyObject | void = void> = WithSchema<T extends EmptyObject ? PayloadFields & T : PayloadFields>
20
-
21
- export type XyoPayload<
22
- T extends void | EmptyObject | WithSchema = void,
23
- S extends string = T extends WithSchema ? T['schema'] : string,
24
- > = T extends WithSchema
25
- ? /* Type sent is an XyoPayload */
26
- WithPayload<T>
27
- : T extends EmptyObject
28
- ? /* Type sent is an Object */
29
- WithPayload<T & { schema: S }>
30
- : /* Type sent is void */
31
- WithPayload<{ schema: S }>
@@ -1,3 +0,0 @@
1
- export * from './PayloadFindFilter'
2
- export * from './PayloadSet'
3
- export * from './XyoPayload'