@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.
- package/dist/cjs/Payloads.d.ts +1 -1
- package/dist/cjs/Payloads.d.ts.map +1 -1
- package/dist/cjs/index.d.ts +5 -6
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +5 -6
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/isXyoPayloadOfSchemaType.d.ts +2 -2
- package/dist/cjs/isXyoPayloadOfSchemaType.d.ts.map +1 -1
- package/dist/docs.json +1300 -1630
- package/dist/esm/Payloads.d.ts +1 -1
- package/dist/esm/Payloads.d.ts.map +1 -1
- package/dist/esm/index.d.ts +5 -6
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +5 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/isXyoPayloadOfSchemaType.d.ts +2 -2
- package/dist/esm/isXyoPayloadOfSchemaType.d.ts.map +1 -1
- package/package.json +7 -8
- package/src/Payloads.ts +1 -1
- package/src/index.ts +5 -6
- package/src/isXyoPayloadOfSchemaType.ts +1 -1
- package/dist/cjs/Builder/Builder.d.ts +0 -13
- package/dist/cjs/Builder/Builder.d.ts.map +0 -1
- package/dist/cjs/Builder/Builder.js +0 -27
- package/dist/cjs/Builder/Builder.js.map +0 -1
- package/dist/cjs/Builder/index.d.ts +0 -2
- package/dist/cjs/Builder/index.d.ts.map +0 -1
- package/dist/cjs/Builder/index.js +0 -5
- package/dist/cjs/Builder/index.js.map +0 -1
- package/dist/cjs/Huri/Huri.d.ts +0 -32
- package/dist/cjs/Huri/Huri.d.ts.map +0 -1
- package/dist/cjs/Huri/Huri.js +0 -111
- package/dist/cjs/Huri/Huri.js.map +0 -1
- package/dist/cjs/Huri/index.d.ts +0 -2
- package/dist/cjs/Huri/index.d.ts.map +0 -1
- package/dist/cjs/Huri/index.js +0 -5
- package/dist/cjs/Huri/index.js.map +0 -1
- package/dist/cjs/SchemaNameValidator.d.ts +0 -68
- package/dist/cjs/SchemaNameValidator.d.ts.map +0 -1
- package/dist/cjs/SchemaNameValidator.js +0 -127
- package/dist/cjs/SchemaNameValidator.js.map +0 -1
- package/dist/cjs/Test/index.d.ts +0 -2
- package/dist/cjs/Test/index.d.ts.map +0 -1
- package/dist/cjs/Test/index.js +0 -5
- package/dist/cjs/Test/index.js.map +0 -1
- package/dist/cjs/Test/testPayload.d.ts +0 -6
- package/dist/cjs/Test/testPayload.d.ts.map +0 -1
- package/dist/cjs/Test/testPayload.js +0 -16
- package/dist/cjs/Test/testPayload.js.map +0 -1
- package/dist/cjs/Validator/Validator.d.ts +0 -11
- package/dist/cjs/Validator/Validator.d.ts.map +0 -1
- package/dist/cjs/Validator/Validator.js +0 -32
- package/dist/cjs/Validator/Validator.js.map +0 -1
- package/dist/cjs/Validator/index.d.ts +0 -2
- package/dist/cjs/Validator/index.d.ts.map +0 -1
- package/dist/cjs/Validator/index.js +0 -5
- package/dist/cjs/Validator/index.js.map +0 -1
- package/dist/cjs/Wrapper/Wrapper.d.ts +0 -23
- package/dist/cjs/Wrapper/Wrapper.d.ts.map +0 -1
- package/dist/cjs/Wrapper/Wrapper.js +0 -63
- package/dist/cjs/Wrapper/Wrapper.js.map +0 -1
- package/dist/cjs/Wrapper/index.d.ts +0 -2
- package/dist/cjs/Wrapper/index.d.ts.map +0 -1
- package/dist/cjs/Wrapper/index.js +0 -5
- package/dist/cjs/Wrapper/index.js.map +0 -1
- package/dist/cjs/models/PayloadFindFilter.d.ts +0 -16
- package/dist/cjs/models/PayloadFindFilter.d.ts.map +0 -1
- package/dist/cjs/models/PayloadFindFilter.js +0 -3
- package/dist/cjs/models/PayloadFindFilter.js.map +0 -1
- package/dist/cjs/models/PayloadSet/PayloadSetPayload.d.ts +0 -8
- package/dist/cjs/models/PayloadSet/PayloadSetPayload.d.ts.map +0 -1
- package/dist/cjs/models/PayloadSet/PayloadSetPayload.js +0 -3
- package/dist/cjs/models/PayloadSet/PayloadSetPayload.js.map +0 -1
- package/dist/cjs/models/PayloadSet/PayloadSetSchema.d.ts +0 -3
- package/dist/cjs/models/PayloadSet/PayloadSetSchema.d.ts.map +0 -1
- package/dist/cjs/models/PayloadSet/PayloadSetSchema.js +0 -5
- package/dist/cjs/models/PayloadSet/PayloadSetSchema.js.map +0 -1
- package/dist/cjs/models/PayloadSet/index.d.ts +0 -3
- package/dist/cjs/models/PayloadSet/index.d.ts.map +0 -1
- package/dist/cjs/models/PayloadSet/index.js +0 -6
- package/dist/cjs/models/PayloadSet/index.js.map +0 -1
- package/dist/cjs/models/XyoPayload.d.ts +0 -21
- package/dist/cjs/models/XyoPayload.d.ts.map +0 -1
- package/dist/cjs/models/XyoPayload.js +0 -5
- package/dist/cjs/models/XyoPayload.js.map +0 -1
- package/dist/cjs/models/index.d.ts +0 -4
- package/dist/cjs/models/index.d.ts.map +0 -1
- package/dist/cjs/models/index.js +0 -7
- package/dist/cjs/models/index.js.map +0 -1
- package/dist/esm/Builder/Builder.d.ts +0 -13
- package/dist/esm/Builder/Builder.d.ts.map +0 -1
- package/dist/esm/Builder/Builder.js +0 -27
- package/dist/esm/Builder/Builder.js.map +0 -1
- package/dist/esm/Builder/index.d.ts +0 -2
- package/dist/esm/Builder/index.d.ts.map +0 -1
- package/dist/esm/Builder/index.js +0 -2
- package/dist/esm/Builder/index.js.map +0 -1
- package/dist/esm/Huri/Huri.d.ts +0 -32
- package/dist/esm/Huri/Huri.d.ts.map +0 -1
- package/dist/esm/Huri/Huri.js +0 -104
- package/dist/esm/Huri/Huri.js.map +0 -1
- package/dist/esm/Huri/index.d.ts +0 -2
- package/dist/esm/Huri/index.d.ts.map +0 -1
- package/dist/esm/Huri/index.js +0 -2
- package/dist/esm/Huri/index.js.map +0 -1
- package/dist/esm/SchemaNameValidator.d.ts +0 -68
- package/dist/esm/SchemaNameValidator.d.ts.map +0 -1
- package/dist/esm/SchemaNameValidator.js +0 -114
- package/dist/esm/SchemaNameValidator.js.map +0 -1
- package/dist/esm/Test/index.d.ts +0 -2
- package/dist/esm/Test/index.d.ts.map +0 -1
- package/dist/esm/Test/index.js +0 -2
- package/dist/esm/Test/index.js.map +0 -1
- package/dist/esm/Test/testPayload.d.ts +0 -6
- package/dist/esm/Test/testPayload.d.ts.map +0 -1
- package/dist/esm/Test/testPayload.js +0 -12
- package/dist/esm/Test/testPayload.js.map +0 -1
- package/dist/esm/Validator/Validator.d.ts +0 -11
- package/dist/esm/Validator/Validator.d.ts.map +0 -1
- package/dist/esm/Validator/Validator.js +0 -28
- package/dist/esm/Validator/Validator.js.map +0 -1
- package/dist/esm/Validator/index.d.ts +0 -2
- package/dist/esm/Validator/index.d.ts.map +0 -1
- package/dist/esm/Validator/index.js +0 -2
- package/dist/esm/Validator/index.js.map +0 -1
- package/dist/esm/Wrapper/Wrapper.d.ts +0 -23
- package/dist/esm/Wrapper/Wrapper.d.ts.map +0 -1
- package/dist/esm/Wrapper/Wrapper.js +0 -52
- package/dist/esm/Wrapper/Wrapper.js.map +0 -1
- package/dist/esm/Wrapper/index.d.ts +0 -2
- package/dist/esm/Wrapper/index.d.ts.map +0 -1
- package/dist/esm/Wrapper/index.js +0 -2
- package/dist/esm/Wrapper/index.js.map +0 -1
- package/dist/esm/models/PayloadFindFilter.d.ts +0 -16
- package/dist/esm/models/PayloadFindFilter.d.ts.map +0 -1
- package/dist/esm/models/PayloadFindFilter.js +0 -2
- package/dist/esm/models/PayloadFindFilter.js.map +0 -1
- package/dist/esm/models/PayloadSet/PayloadSetPayload.d.ts +0 -8
- package/dist/esm/models/PayloadSet/PayloadSetPayload.d.ts.map +0 -1
- package/dist/esm/models/PayloadSet/PayloadSetPayload.js +0 -2
- package/dist/esm/models/PayloadSet/PayloadSetPayload.js.map +0 -1
- package/dist/esm/models/PayloadSet/PayloadSetSchema.d.ts +0 -3
- package/dist/esm/models/PayloadSet/PayloadSetSchema.d.ts.map +0 -1
- package/dist/esm/models/PayloadSet/PayloadSetSchema.js +0 -2
- package/dist/esm/models/PayloadSet/PayloadSetSchema.js.map +0 -1
- package/dist/esm/models/PayloadSet/index.d.ts +0 -3
- package/dist/esm/models/PayloadSet/index.d.ts.map +0 -1
- package/dist/esm/models/PayloadSet/index.js +0 -3
- package/dist/esm/models/PayloadSet/index.js.map +0 -1
- package/dist/esm/models/XyoPayload.d.ts +0 -21
- package/dist/esm/models/XyoPayload.d.ts.map +0 -1
- package/dist/esm/models/XyoPayload.js +0 -2
- package/dist/esm/models/XyoPayload.js.map +0 -1
- package/dist/esm/models/index.d.ts +0 -4
- package/dist/esm/models/index.d.ts.map +0 -1
- package/dist/esm/models/index.js +0 -4
- package/dist/esm/models/index.js.map +0 -1
- package/src/Builder/Builder.spec.ts +0 -38
- package/src/Builder/Builder.ts +0 -37
- package/src/Builder/index.ts +0 -1
- package/src/Huri/Huri.spec.ts +0 -92
- package/src/Huri/Huri.ts +0 -154
- package/src/Huri/index.ts +0 -1
- package/src/SchemaNameValidator.ts +0 -120
- package/src/Test/index.ts +0 -1
- package/src/Test/testPayload.ts +0 -16
- package/src/Validator/Validator.spec.ts +0 -52
- package/src/Validator/Validator.ts +0 -33
- package/src/Validator/index.ts +0 -1
- package/src/Wrapper/Wrapper.ts +0 -69
- package/src/Wrapper/index.ts +0 -1
- package/src/models/PayloadFindFilter.ts +0 -19
- package/src/models/PayloadSet/PayloadSetPayload.ts +0 -9
- package/src/models/PayloadSet/PayloadSetSchema.ts +0 -2
- package/src/models/PayloadSet/index.ts +0 -2
- package/src/models/XyoPayload.ts +0 -31
- package/src/models/index.ts +0 -3
package/src/Huri/Huri.spec.ts
DELETED
|
@@ -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'
|
package/src/Test/testPayload.ts
DELETED
|
@@ -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
|
-
}
|
package/src/Validator/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Validator'
|
package/src/Wrapper/Wrapper.ts
DELETED
|
@@ -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
|
-
}
|
package/src/Wrapper/index.ts
DELETED
|
@@ -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>
|
package/src/models/XyoPayload.ts
DELETED
|
@@ -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 }>
|
package/src/models/index.ts
DELETED