@xyo-network/api 2.47.8 → 2.47.10
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/docs.json +5788 -7256
- package/package.json +18 -18
- package/src/Api/Account/spec/Api.spec.ts +0 -58
- package/src/Api/Addresses/Address/spec/Api.spec.ts +0 -86
- package/src/Api/Addresses/spec/Api.spec.ts +0 -38
- package/src/Api/ApiUtil.spec.ts +0 -61
- package/src/Api/Archive/Api.spec.ts +0 -22
- package/src/Api/Archive/Schema/Api.spec.ts +0 -24
- package/src/Api/Archive/Schemas/Api.spec.ts +0 -24
- package/src/Api/Archive/Settings/Key/spec/Api.spec.ts +0 -39
- package/src/Api/Archives/Api.spec.ts +0 -12
- package/src/Api/Block/Api.spec.ts +0 -57
- package/src/Api/Node/Api.spec.ts +0 -146
- package/src/Api/Payload/Api.spec.ts +0 -34
- package/src/Api/Payload/Schema/Api.spec.ts +0 -61
- package/src/Api/spec/Api.spec.ts +0 -23
- package/src/Archivist/XyoRemoteArchivist.spec.ts +0 -55
- package/src/Diviner/AddressHistoryDiviner/XyoRemoteAddressHistoryDiviner.spec.ts +0 -81
- package/src/Diviner/ArchiveListApiDiviner/ArchiveListApiDiviner.spec.ts +0 -18
- package/src/Diviner/LocationDiviner/spec/LocationDivinerApi.spec.ts +0 -89
- package/src/Diviner/SchemaListApiDiviner/SchemaListApiDiviner.spec.ts +0 -22
- package/src/Diviner/SchemaStatsApiDiviner/SchemaStatsApiDiviner.spec.ts +0 -19
- package/src/User/Api.spec.ts +0 -31
package/package.json
CHANGED
|
@@ -11,28 +11,28 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xylabs/assert": "^2.7.1",
|
|
13
13
|
"@xylabs/delay": "^2.7.1",
|
|
14
|
-
"@xyo-network/account": "^2.47.
|
|
15
|
-
"@xyo-network/api-models": "^2.47.
|
|
16
|
-
"@xyo-network/archivist": "^2.47.
|
|
17
|
-
"@xyo-network/axios": "^2.47.
|
|
18
|
-
"@xyo-network/boundwitness-builder": "^2.47.
|
|
19
|
-
"@xyo-network/boundwitness-model": "^2.47.
|
|
20
|
-
"@xyo-network/core": "^2.47.
|
|
21
|
-
"@xyo-network/diviner": "^2.47.
|
|
22
|
-
"@xyo-network/diviner-model": "^2.47.
|
|
23
|
-
"@xyo-network/huri": "^2.47.
|
|
24
|
-
"@xyo-network/module": "^2.47.
|
|
25
|
-
"@xyo-network/payload-builder": "^2.47.
|
|
26
|
-
"@xyo-network/payload-model": "^2.47.
|
|
27
|
-
"@xyo-network/payload-wrapper": "^2.47.
|
|
28
|
-
"@xyo-network/schema-payload-plugin": "^2.47.
|
|
14
|
+
"@xyo-network/account": "^2.47.10",
|
|
15
|
+
"@xyo-network/api-models": "^2.47.10",
|
|
16
|
+
"@xyo-network/archivist": "^2.47.10",
|
|
17
|
+
"@xyo-network/axios": "^2.47.10",
|
|
18
|
+
"@xyo-network/boundwitness-builder": "^2.47.10",
|
|
19
|
+
"@xyo-network/boundwitness-model": "^2.47.10",
|
|
20
|
+
"@xyo-network/core": "^2.47.10",
|
|
21
|
+
"@xyo-network/diviner": "^2.47.10",
|
|
22
|
+
"@xyo-network/diviner-model": "^2.47.10",
|
|
23
|
+
"@xyo-network/huri": "^2.47.10",
|
|
24
|
+
"@xyo-network/module": "^2.47.10",
|
|
25
|
+
"@xyo-network/payload-builder": "^2.47.10",
|
|
26
|
+
"@xyo-network/payload-model": "^2.47.10",
|
|
27
|
+
"@xyo-network/payload-wrapper": "^2.47.10",
|
|
28
|
+
"@xyo-network/schema-payload-plugin": "^2.47.10",
|
|
29
29
|
"lodash": "^4.17.21"
|
|
30
30
|
},
|
|
31
31
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/lodash": "^4.14.191",
|
|
34
|
-
"@xylabs/ts-scripts-yarn3": "^2.
|
|
35
|
-
"@xylabs/tsconfig": "^2.
|
|
34
|
+
"@xylabs/ts-scripts-yarn3": "^2.15.0",
|
|
35
|
+
"@xylabs/tsconfig": "^2.15.0",
|
|
36
36
|
"typescript": "^4.9.5"
|
|
37
37
|
},
|
|
38
38
|
"browser": "dist/esm/index.js",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
},
|
|
69
69
|
"sideEffects": false,
|
|
70
70
|
"types": "dist/types/index.d.ts",
|
|
71
|
-
"version": "2.47.
|
|
71
|
+
"version": "2.47.10"
|
|
72
72
|
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { Account } from '@xyo-network/account'
|
|
2
|
-
import { XyoApiConfig } from '@xyo-network/api-models'
|
|
3
|
-
import { typeOf } from '@xyo-network/typeof'
|
|
4
|
-
|
|
5
|
-
import { XyoArchivistApi } from '../../Api'
|
|
6
|
-
import { XyoAccountApi } from '../Api'
|
|
7
|
-
|
|
8
|
-
const timeout = 20000
|
|
9
|
-
const config: XyoApiConfig = {
|
|
10
|
-
apiDomain: process.env.API_DOMAIN || 'http://localhost:8080',
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
describe('XyoAuthApi', () => {
|
|
14
|
-
describe('get', () => {
|
|
15
|
-
it('returns a new XyoWalletApi', () => {
|
|
16
|
-
const api = new XyoAccountApi(config)
|
|
17
|
-
expect(api).toBeDefined()
|
|
18
|
-
})
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
describe('challenge', function () {
|
|
22
|
-
it(
|
|
23
|
-
'success',
|
|
24
|
-
async () => {
|
|
25
|
-
const api = new XyoArchivistApi(config)
|
|
26
|
-
const account = Account.random()
|
|
27
|
-
const [data, envelope, response] = await api.account(account.addressValue.hex).challenge.post(undefined, 'tuple')
|
|
28
|
-
expect(response.status).toBe(200)
|
|
29
|
-
expect(envelope.errors).toBeUndefined()
|
|
30
|
-
expect(typeOf(data?.state)).toBe('string')
|
|
31
|
-
},
|
|
32
|
-
timeout,
|
|
33
|
-
)
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
/*describe('verify', function () {
|
|
37
|
-
it(
|
|
38
|
-
'success',
|
|
39
|
-
async () => {
|
|
40
|
-
const api = new XyoArchivistApi(config)
|
|
41
|
-
const address = XyoAddress.random()
|
|
42
|
-
const challenge = (await api.wallet(address.address).challenge.post(undefined))
|
|
43
|
-
const message = assertEx(challenge?.state)
|
|
44
|
-
const [data, envelope, response] = await api
|
|
45
|
-
.wallet(`0x${address.address}`)
|
|
46
|
-
.verify.post(
|
|
47
|
-
[{ message: assertEx(challenge?.state), signature: `0x${address.signKeccakMessage(message)}` }],
|
|
48
|
-
'tuple'
|
|
49
|
-
)
|
|
50
|
-
expect(response.status).toBe(200)
|
|
51
|
-
expect(envelope.error).toBeUndefined()
|
|
52
|
-
expect(data?.length).toBe(1)
|
|
53
|
-
|
|
54
|
-
},
|
|
55
|
-
timeout
|
|
56
|
-
)
|
|
57
|
-
})*/
|
|
58
|
-
})
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/assert'
|
|
2
|
-
import { Account } from '@xyo-network/account'
|
|
3
|
-
import { AddressPayload, AddressSchema } from '@xyo-network/address-payload-plugin'
|
|
4
|
-
import { XyoApiConfig, XyoApiResponseBody } from '@xyo-network/api-models'
|
|
5
|
-
import { XyoBoundWitness } from '@xyo-network/boundwitness-model'
|
|
6
|
-
import { BoundWitnessWrapper } from '@xyo-network/boundwitness-wrapper'
|
|
7
|
-
import { XyoPayload } from '@xyo-network/payload-model'
|
|
8
|
-
import { QueryPayload, QuerySchema } from '@xyo-network/query-payload-plugin'
|
|
9
|
-
|
|
10
|
-
import { XyoApiSimple } from '../../../../Simple'
|
|
11
|
-
import { XyoArchivistApi } from '../../../Api'
|
|
12
|
-
import { XyoAddressesApi } from '../../Api'
|
|
13
|
-
import { XyoAddressApi } from '../Api'
|
|
14
|
-
|
|
15
|
-
const config: XyoApiConfig = {
|
|
16
|
-
apiDomain: process.env.API_DOMAIN || 'http://localhost:8080',
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
describe('XyoAddressApi', () => {
|
|
20
|
-
describe('get', () => {
|
|
21
|
-
let api: XyoAddressApi
|
|
22
|
-
let result: XyoApiResponseBody<XyoPayload[]>
|
|
23
|
-
beforeAll(async () => {
|
|
24
|
-
const payloads = await new XyoAddressesApi(config).get()
|
|
25
|
-
expect(payloads).toBeArray()
|
|
26
|
-
const addressPayload = payloads?.find((p) => p.schema === AddressSchema) as AddressPayload
|
|
27
|
-
expect(addressPayload).toBeObject()
|
|
28
|
-
const address = addressPayload.address
|
|
29
|
-
api = new XyoArchivistApi(config).addresses.address(address)
|
|
30
|
-
result = await api.get()
|
|
31
|
-
expect(result).toBeArray()
|
|
32
|
-
})
|
|
33
|
-
it('method exists', () => {
|
|
34
|
-
expect(api).toBeDefined()
|
|
35
|
-
expect(api.get).toBeFunction()
|
|
36
|
-
})
|
|
37
|
-
describe('returns module', () => {
|
|
38
|
-
it('address', () => {
|
|
39
|
-
const addressPayload = result?.find((p) => p.schema === AddressSchema) as AddressPayload
|
|
40
|
-
expect(addressPayload).toBeObject()
|
|
41
|
-
const address = addressPayload.address
|
|
42
|
-
expect(address).toBeString()
|
|
43
|
-
})
|
|
44
|
-
it('supported queries', () => {
|
|
45
|
-
const queryPayloads = result?.filter((p) => p.schema === QuerySchema) as QueryPayload[]
|
|
46
|
-
expect(queryPayloads).toBeArray()
|
|
47
|
-
expect(queryPayloads.length).toBeGreaterThan(0)
|
|
48
|
-
queryPayloads?.map((query) => {
|
|
49
|
-
expect(query.query).toBeString()
|
|
50
|
-
})
|
|
51
|
-
})
|
|
52
|
-
})
|
|
53
|
-
})
|
|
54
|
-
describe('boundWitness', () => {
|
|
55
|
-
let address: string
|
|
56
|
-
let api: XyoApiSimple<XyoBoundWitness[]>
|
|
57
|
-
let history: XyoBoundWitness[]
|
|
58
|
-
beforeAll(async () => {
|
|
59
|
-
address = new Account({ phrase: 'test' }).addressValue.hex
|
|
60
|
-
api = new XyoArchivistApi(config).addresses.address(address).boundWitnesses
|
|
61
|
-
const result = await api.get()
|
|
62
|
-
expect(result).toBeArray()
|
|
63
|
-
history = assertEx(result)
|
|
64
|
-
})
|
|
65
|
-
it('method exists', () => {
|
|
66
|
-
expect(api).toBeDefined()
|
|
67
|
-
expect(api.get).toBeFunction()
|
|
68
|
-
})
|
|
69
|
-
describe('return BoundWitnesses', () => {
|
|
70
|
-
it('from the address specified', () => {
|
|
71
|
-
history?.map((block) => expect(block.addresses).toContain(address))
|
|
72
|
-
})
|
|
73
|
-
it('in sequential order', () => {
|
|
74
|
-
verifyBlockChainHistory(history)
|
|
75
|
-
})
|
|
76
|
-
})
|
|
77
|
-
})
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
const verifyBlockChainHistory = (history: XyoBoundWitness[]) => {
|
|
81
|
-
for (let i = 1; i < history.length; i++) {
|
|
82
|
-
const current = history[i - 1]
|
|
83
|
-
const previous = history[i]
|
|
84
|
-
expect(current.previous_hashes).toContain(new BoundWitnessWrapper(previous).hash)
|
|
85
|
-
}
|
|
86
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { AddressPayload, AddressSchema } from '@xyo-network/address-payload-plugin'
|
|
2
|
-
import { XyoApiConfig, XyoApiResponseBody } from '@xyo-network/api-models'
|
|
3
|
-
import { XyoPayloads } from '@xyo-network/payload-model'
|
|
4
|
-
import { QueryPayload, QuerySchema } from '@xyo-network/query-payload-plugin'
|
|
5
|
-
|
|
6
|
-
import { XyoAddressesApi } from '../Api'
|
|
7
|
-
|
|
8
|
-
const config: XyoApiConfig = {
|
|
9
|
-
apiDomain: process.env.API_DOMAIN || 'http://localhost:8080',
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
describe('XyoAddressesApi', () => {
|
|
13
|
-
describe('get', () => {
|
|
14
|
-
it('method exists', () => {
|
|
15
|
-
const api = new XyoAddressesApi(config)
|
|
16
|
-
expect(api).toBeDefined()
|
|
17
|
-
expect(api.get).toBeFunction()
|
|
18
|
-
})
|
|
19
|
-
describe('returns root module discover containing', () => {
|
|
20
|
-
let api: XyoAddressesApi
|
|
21
|
-
let response: XyoApiResponseBody<XyoPayloads>
|
|
22
|
-
beforeAll(async () => {
|
|
23
|
-
api = new XyoAddressesApi(config)
|
|
24
|
-
response = await api.get()
|
|
25
|
-
})
|
|
26
|
-
it('address', () => {
|
|
27
|
-
expect(response).toBeArray()
|
|
28
|
-
const addressPayload = response?.find((p) => p.schema === AddressSchema) as AddressPayload
|
|
29
|
-
expect(addressPayload).toBeObject()
|
|
30
|
-
expect(addressPayload.address).toBeString()
|
|
31
|
-
})
|
|
32
|
-
it('supported queries', () => {
|
|
33
|
-
const queries = response?.filter((d) => d.schema === QuerySchema) as QueryPayload[]
|
|
34
|
-
expect(queries.length).toBeGreaterThan(0)
|
|
35
|
-
})
|
|
36
|
-
})
|
|
37
|
-
})
|
|
38
|
-
})
|
package/src/Api/ApiUtil.spec.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { Wallet } from '@ethersproject/wallet'
|
|
2
|
-
import { assertEx } from '@xylabs/assert'
|
|
3
|
-
import { Account } from '@xyo-network/account'
|
|
4
|
-
import { XyoApiConfig } from '@xyo-network/api-models'
|
|
5
|
-
import { uuid } from '@xyo-network/core'
|
|
6
|
-
|
|
7
|
-
import { XyoArchivistApi } from './Api'
|
|
8
|
-
|
|
9
|
-
test('Must have tests defined', () => {
|
|
10
|
-
expect(true).toBeTruthy()
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
export const getApiConfig = (configData: Partial<XyoApiConfig> = {}): XyoApiConfig => {
|
|
14
|
-
const defaults: XyoApiConfig = {
|
|
15
|
-
apiDomain: process.env.API_DOMAIN || 'http://localhost:8080',
|
|
16
|
-
onError: (error) => error,
|
|
17
|
-
onFailure: (response) => response,
|
|
18
|
-
onSuccess: (response) => response,
|
|
19
|
-
}
|
|
20
|
-
return Object.assign({}, defaults, configData)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const getApi = (configData: Partial<XyoApiConfig> = {}): XyoArchivistApi => {
|
|
24
|
-
return new XyoArchivistApi(getApiConfig(configData))
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const getRandomArchiveName = (): string => {
|
|
28
|
-
const randomString = (Math.random() + 1).toString(36).substring(7).toLowerCase()
|
|
29
|
-
return `test-archive-${randomString}`
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const getTokenForNewUser = async (api: XyoArchivistApi): Promise<string> => {
|
|
33
|
-
const account = Account.random()
|
|
34
|
-
const address = new Wallet(account.private.bytes)
|
|
35
|
-
const challenge = await api.account(account.public).challenge.post()
|
|
36
|
-
const message = assertEx(challenge?.state, 'Missing state from login challenge')
|
|
37
|
-
const signature = await address.signMessage(message)
|
|
38
|
-
const verify = await api.account(account.public).verify.post({ message, signature })
|
|
39
|
-
const jwtToken = assertEx(verify?.token, 'Missing JWT token in response')
|
|
40
|
-
return jwtToken
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export const getNewArchive = async (api: XyoArchivistApi) => {
|
|
44
|
-
const jwtToken = await getTokenForNewUser(api)
|
|
45
|
-
const authenticatedApi = new XyoArchivistApi({ ...api.config, jwtToken })
|
|
46
|
-
const name = getRandomArchiveName()
|
|
47
|
-
const response = await authenticatedApi.archives.archive(name).put()
|
|
48
|
-
const archive = assertEx(response?.archive, 'Missing archive in response')
|
|
49
|
-
return archive
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export const testSchemaPrefix = 'network.xyo.schema.test.'
|
|
53
|
-
export const getSchemaName = (): string => {
|
|
54
|
-
return `${testSchemaPrefix}${uuid()}`
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export const getTimestampMinutesFromNow = (minutes = 0) => {
|
|
58
|
-
const t = new Date()
|
|
59
|
-
t.setMinutes(t.getMinutes() + minutes)
|
|
60
|
-
return +t
|
|
61
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { getApi, getRandomArchiveName, getTokenForNewUser } from '../ApiUtil.spec'
|
|
2
|
-
|
|
3
|
-
describe('XyoArchivistArchiveApi', () => {
|
|
4
|
-
const api = getApi()
|
|
5
|
-
const archive = getRandomArchiveName()
|
|
6
|
-
beforeEach(async () => {
|
|
7
|
-
const token = await getTokenForNewUser(api)
|
|
8
|
-
api.config.jwtToken = token
|
|
9
|
-
})
|
|
10
|
-
describe('put', () => {
|
|
11
|
-
it('creates the archive', async () => {
|
|
12
|
-
const response = await api.archives.archive(archive).put()
|
|
13
|
-
expect(response?.archive).toEqual(archive)
|
|
14
|
-
})
|
|
15
|
-
})
|
|
16
|
-
describe('get', () => {
|
|
17
|
-
it('gets the archive', async () => {
|
|
18
|
-
const response = await api.archives.archive(archive).get()
|
|
19
|
-
expect(response?.archive).toBe(archive)
|
|
20
|
-
})
|
|
21
|
-
})
|
|
22
|
-
})
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { XyoApiConfig } from '@xyo-network/api-models'
|
|
2
|
-
|
|
3
|
-
import { XyoArchivistApi } from '../../Api'
|
|
4
|
-
|
|
5
|
-
const config: XyoApiConfig = {
|
|
6
|
-
apiDomain: process.env.API_DOMAIN || 'http://localhost:8080',
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
describe('XyoArchivistSchemaApi', () => {
|
|
10
|
-
describe('schema', () => {
|
|
11
|
-
it('calculates the correct path', () => {
|
|
12
|
-
const api = new XyoArchivistApi(config)
|
|
13
|
-
const path = api.archive('foo').schema('foo.bar.baz').config.root
|
|
14
|
-
expect(path).toBe('/archive/foo/schema/foo.bar.baz/')
|
|
15
|
-
})
|
|
16
|
-
})
|
|
17
|
-
describe('recent', () => {
|
|
18
|
-
it('calculates the correct path', () => {
|
|
19
|
-
const api = new XyoArchivistApi(config)
|
|
20
|
-
const path = api.archive('foo').schema('foo.bar.baz').recent.config.root
|
|
21
|
-
expect(path).toBe('/archive/foo/schema/foo.bar.baz/recent/')
|
|
22
|
-
})
|
|
23
|
-
})
|
|
24
|
-
})
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { XyoApiConfig } from '@xyo-network/api-models'
|
|
2
|
-
|
|
3
|
-
import { XyoArchivistApi } from '../../Api'
|
|
4
|
-
|
|
5
|
-
const config: XyoApiConfig = {
|
|
6
|
-
apiDomain: process.env.API_DOMAIN || 'http://localhost:8080',
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
describe('XyoArchivistSchemasApi', () => {
|
|
10
|
-
describe('schema', () => {
|
|
11
|
-
it('calculates the correct path', () => {
|
|
12
|
-
const api = new XyoArchivistApi(config)
|
|
13
|
-
const path = api.archive('foo').schemas.config.root
|
|
14
|
-
expect(path).toBe('/archive/foo/schema/')
|
|
15
|
-
})
|
|
16
|
-
})
|
|
17
|
-
describe('recent', () => {
|
|
18
|
-
it('calculates the correct path', () => {
|
|
19
|
-
const api = new XyoArchivistApi(config)
|
|
20
|
-
const path = api.archive('foo').schemas.recent.config.root
|
|
21
|
-
expect(path).toBe('/archive/foo/schema/recent/')
|
|
22
|
-
})
|
|
23
|
-
})
|
|
24
|
-
})
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/assert'
|
|
2
|
-
|
|
3
|
-
import { XyoArchiveKey } from '../../../../../models'
|
|
4
|
-
import { XyoArchivistApi } from '../../../../Api'
|
|
5
|
-
import { getApi, getRandomArchiveName, getTokenForNewUser } from '../../../../ApiUtil.spec'
|
|
6
|
-
|
|
7
|
-
describe('XyoArchivistArchiveSettingsKeyApi', () => {
|
|
8
|
-
let api: XyoArchivistApi
|
|
9
|
-
let archive = ''
|
|
10
|
-
beforeEach(async () => {
|
|
11
|
-
archive = getRandomArchiveName()
|
|
12
|
-
api = getApi()
|
|
13
|
-
const token = await getTokenForNewUser(api)
|
|
14
|
-
api.config.jwtToken = token
|
|
15
|
-
await api.archives.archive(archive).put()
|
|
16
|
-
})
|
|
17
|
-
describe('post', () => {
|
|
18
|
-
it('Creates an archive key', async () => {
|
|
19
|
-
const response = await api.archives.archive(archive).settings.key.post()
|
|
20
|
-
expect(response).toBeArrayOfSize(1)
|
|
21
|
-
const key = response?.[0]
|
|
22
|
-
expect(key).toBeObject()
|
|
23
|
-
expect(key?.archive).toBeString()
|
|
24
|
-
expect(key?.key).toBeString()
|
|
25
|
-
})
|
|
26
|
-
})
|
|
27
|
-
describe('get', () => {
|
|
28
|
-
let key: XyoArchiveKey
|
|
29
|
-
beforeEach(async () => {
|
|
30
|
-
const response = await api.archives.archive(archive).settings.key.post()
|
|
31
|
-
key = assertEx(response?.[0])
|
|
32
|
-
})
|
|
33
|
-
it('Returns the keys for the archive', async () => {
|
|
34
|
-
const response = await api.archives.archive(archive).settings.key.get()
|
|
35
|
-
expect(response).toBeArrayOfSize(1)
|
|
36
|
-
expect(response).toContainEqual(key)
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
})
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { getApi } from '../ApiUtil.spec'
|
|
2
|
-
|
|
3
|
-
describe('XyoArchivistArchivesApi', () => {
|
|
4
|
-
describe('get', function () {
|
|
5
|
-
it('gets an array of archives owned', async () => {
|
|
6
|
-
const api = getApi()
|
|
7
|
-
const response = await api.archives.get()
|
|
8
|
-
expect(response).toBeArray()
|
|
9
|
-
expect(response?.length).toBeGreaterThan(0)
|
|
10
|
-
})
|
|
11
|
-
})
|
|
12
|
-
})
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'
|
|
2
|
-
|
|
3
|
-
import { testPayload } from '../../Test'
|
|
4
|
-
import { getApi, getNewArchive } from '../ApiUtil.spec'
|
|
5
|
-
|
|
6
|
-
describe('XyoArchivistArchiveBlockApi', () => {
|
|
7
|
-
const api = getApi()
|
|
8
|
-
describe('post', function () {
|
|
9
|
-
it.each([true, false])('posts a single bound witness', async (inlinePayloads) => {
|
|
10
|
-
const builder = new BoundWitnessBuilder({ inlinePayloads }).payload(testPayload)
|
|
11
|
-
const [bw] = builder.build()
|
|
12
|
-
const blocks = [bw]
|
|
13
|
-
const response = await api.archives.archive().block.post(blocks)
|
|
14
|
-
expect(response?.length).toEqual(blocks.length)
|
|
15
|
-
})
|
|
16
|
-
it.each([true, false])('posts multiple bound witnesses', async (inlinePayloads) => {
|
|
17
|
-
const builder = new BoundWitnessBuilder({ inlinePayloads }).payload(testPayload)
|
|
18
|
-
const [bw] = builder.build()
|
|
19
|
-
const blocks = [bw, bw]
|
|
20
|
-
const response = await api.archives.archive().block.post(blocks)
|
|
21
|
-
expect(response?.length).toEqual(blocks.length)
|
|
22
|
-
})
|
|
23
|
-
})
|
|
24
|
-
describe('stats', () => {
|
|
25
|
-
const [bw] = new BoundWitnessBuilder().build()
|
|
26
|
-
const blocks = [bw]
|
|
27
|
-
let archive = ''
|
|
28
|
-
beforeEach(async () => {
|
|
29
|
-
archive = await getNewArchive(api)
|
|
30
|
-
})
|
|
31
|
-
it('returns stats for boundwitness', async () => {
|
|
32
|
-
await api.archives.archive(archive).block.post(blocks)
|
|
33
|
-
const stats = await api.archives.archive(archive).block.stats.get()
|
|
34
|
-
expect(stats?.count).toBeGreaterThanOrEqual(blocks.length)
|
|
35
|
-
})
|
|
36
|
-
})
|
|
37
|
-
describe('find', () => {
|
|
38
|
-
const [bw] = new BoundWitnessBuilder().build()
|
|
39
|
-
const blocks = [bw]
|
|
40
|
-
let archive = ''
|
|
41
|
-
beforeEach(async () => {
|
|
42
|
-
archive = await getNewArchive(api)
|
|
43
|
-
})
|
|
44
|
-
it('returns bound witnesses from before the timestamp', async () => {
|
|
45
|
-
const timestamp = Date.now() - 10000
|
|
46
|
-
await api.archives.archive(archive).block.post(blocks)
|
|
47
|
-
const response = await api.archives.archive(archive).block.find({ order: 'asc', timestamp })
|
|
48
|
-
expect(response?.length).toBe(blocks.length)
|
|
49
|
-
})
|
|
50
|
-
it('returns bound witnesses from after the timestamp', async () => {
|
|
51
|
-
await api.archives.archive(archive).block.post(blocks)
|
|
52
|
-
const timestamp = Date.now() + 10000
|
|
53
|
-
const response = await api.archives.archive(archive).block.find({ order: 'desc', timestamp })
|
|
54
|
-
expect(response?.length).toBe(blocks.length)
|
|
55
|
-
})
|
|
56
|
-
})
|
|
57
|
-
})
|
package/src/Api/Node/Api.spec.ts
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/assert'
|
|
2
|
-
import { delay } from '@xylabs/delay'
|
|
3
|
-
import { XyoApiConfig, XyoApiEnvelope } from '@xyo-network/api-models'
|
|
4
|
-
import { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'
|
|
5
|
-
import { XyoBoundWitness } from '@xyo-network/boundwitness-model'
|
|
6
|
-
import { uuid } from '@xyo-network/core'
|
|
7
|
-
import { XyoPayloadBuilder } from '@xyo-network/payload-builder'
|
|
8
|
-
import { XyoPayload } from '@xyo-network/payload-model'
|
|
9
|
-
|
|
10
|
-
import { XyoArchivistApi } from '../Api'
|
|
11
|
-
|
|
12
|
-
const config: XyoApiConfig = {
|
|
13
|
-
apiDomain: process.env.API_DOMAIN || 'http://localhost:8080',
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const schema = 'network.xyo.debug'
|
|
17
|
-
|
|
18
|
-
const getQuery = (count = 1) => {
|
|
19
|
-
const payloads = [] as XyoPayload[]
|
|
20
|
-
for (let i = 0; i < count; i++) {
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
-
payloads.push(new XyoPayloadBuilder({ schema }).fields({ nonce: uuid() } as any).build())
|
|
23
|
-
}
|
|
24
|
-
return new BoundWitnessBuilder({ inlinePayloads: true }).payloads(payloads).build()[0]
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const issueQuery = async (query: XyoBoundWitness = getQuery()): Promise<string> => {
|
|
28
|
-
const api = new XyoArchivistApi(config)
|
|
29
|
-
const response = await api.node('temp').post(query)
|
|
30
|
-
const id = response?.[0]?.[0]
|
|
31
|
-
expect(id).toBeDefined()
|
|
32
|
-
return assertEx(id)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const validateAllResponseSchemas = (response: XyoApiEnvelope<XyoPayload | undefined>[][]): boolean => {
|
|
36
|
-
return response
|
|
37
|
-
.flat()
|
|
38
|
-
.map((r) => (r as unknown as XyoPayload)?.schema)
|
|
39
|
-
.every((s) => s === schema)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
describe('XyoArchivistNodeApi', () => {
|
|
43
|
-
describe('node', () => {
|
|
44
|
-
describe('without archive supplied', () => {
|
|
45
|
-
it('calculates the correct path', () => {
|
|
46
|
-
const api = new XyoArchivistApi(config)
|
|
47
|
-
const path = api.node().config.root
|
|
48
|
-
expect(path).toBe('/temp/')
|
|
49
|
-
})
|
|
50
|
-
})
|
|
51
|
-
describe('with archive supplied', () => {
|
|
52
|
-
const archive = 'foo'
|
|
53
|
-
it('calculates the correct path', () => {
|
|
54
|
-
const api = new XyoArchivistApi(config)
|
|
55
|
-
const path = api.node(archive).config.root
|
|
56
|
-
expect(path).toBe(`/${archive}/`)
|
|
57
|
-
})
|
|
58
|
-
})
|
|
59
|
-
})
|
|
60
|
-
describe('queryResult', () => {
|
|
61
|
-
let id = '123456789'
|
|
62
|
-
describe('with valid query id', () => {
|
|
63
|
-
beforeEach(async () => {
|
|
64
|
-
id = await issueQuery()
|
|
65
|
-
})
|
|
66
|
-
it.skip('returns the query result', async () => {
|
|
67
|
-
const api = new XyoArchivistApi(config)
|
|
68
|
-
await delay(1000)
|
|
69
|
-
const [_, payload, response] = await api.node().result(id).get('tuple')
|
|
70
|
-
expect(_).toBeUndefined()
|
|
71
|
-
expect(payload).toBeDefined()
|
|
72
|
-
expect((payload as unknown as XyoPayload).schema).toBe(schema)
|
|
73
|
-
expect(response.status).toBe(200)
|
|
74
|
-
})
|
|
75
|
-
})
|
|
76
|
-
describe('without archive supplied', () => {
|
|
77
|
-
it('calculates the correct path', () => {
|
|
78
|
-
const api = new XyoArchivistApi(config)
|
|
79
|
-
const path = api.node().result(id).config.root
|
|
80
|
-
expect(path).toBe(`/query/${id}/`)
|
|
81
|
-
})
|
|
82
|
-
})
|
|
83
|
-
describe('with archive supplied', () => {
|
|
84
|
-
const archive = 'foo'
|
|
85
|
-
it('calculates the correct path', () => {
|
|
86
|
-
const api = new XyoArchivistApi(config)
|
|
87
|
-
const path = api.node(archive).result(id).config.root
|
|
88
|
-
expect(path).toBe(`/query/${id}/`)
|
|
89
|
-
})
|
|
90
|
-
})
|
|
91
|
-
})
|
|
92
|
-
describe.skip('perform', () => {
|
|
93
|
-
it('creates and issues the query and returns the result', async () => {
|
|
94
|
-
const api = new XyoArchivistApi(config)
|
|
95
|
-
const response = await api.node().perform({}, schema)
|
|
96
|
-
expect(response).toBeDefined()
|
|
97
|
-
expect((response as unknown as XyoPayload).schema).toBe(schema)
|
|
98
|
-
})
|
|
99
|
-
})
|
|
100
|
-
describe.skip('performTransaction', () => {
|
|
101
|
-
describe('with a single BoundWitness', () => {
|
|
102
|
-
describe('with a single Payload', () => {
|
|
103
|
-
it('issues the query and returns the result', async () => {
|
|
104
|
-
const api = new XyoArchivistApi(config)
|
|
105
|
-
const query = [getQuery()]
|
|
106
|
-
const response = await api.node().performTransaction(query)
|
|
107
|
-
expect(response).toBeDefined()
|
|
108
|
-
expect(Array.isArray(response)).toBeTruthy()
|
|
109
|
-
expect(validateAllResponseSchemas(response)).toBeTruthy()
|
|
110
|
-
})
|
|
111
|
-
})
|
|
112
|
-
describe('with a multiple Payloads', () => {
|
|
113
|
-
it('issues the query and returns the result', async () => {
|
|
114
|
-
const api = new XyoArchivistApi(config)
|
|
115
|
-
const query = [getQuery(2)]
|
|
116
|
-
const response = await api.node().performTransaction(query)
|
|
117
|
-
expect(response).toBeDefined()
|
|
118
|
-
expect(Array.isArray(response)).toBeTruthy()
|
|
119
|
-
expect(validateAllResponseSchemas(response)).toBeTruthy()
|
|
120
|
-
})
|
|
121
|
-
})
|
|
122
|
-
})
|
|
123
|
-
describe('with a multiple BoundWitnesses', () => {
|
|
124
|
-
describe('with a single Payload', () => {
|
|
125
|
-
it('issues the query and returns the result', async () => {
|
|
126
|
-
const api = new XyoArchivistApi(config)
|
|
127
|
-
const query = [getQuery(), getQuery()]
|
|
128
|
-
const response = await api.node().performTransaction(query)
|
|
129
|
-
expect(response).toBeDefined()
|
|
130
|
-
expect(Array.isArray(response)).toBeTruthy()
|
|
131
|
-
expect(validateAllResponseSchemas(response)).toBeTruthy()
|
|
132
|
-
})
|
|
133
|
-
})
|
|
134
|
-
describe('with a multiple Payloads', () => {
|
|
135
|
-
it('issues the query and returns the result', async () => {
|
|
136
|
-
const api = new XyoArchivistApi(config)
|
|
137
|
-
const query = [getQuery(2), getQuery(2)]
|
|
138
|
-
const response = await api.node().performTransaction(query)
|
|
139
|
-
expect(response).toBeDefined()
|
|
140
|
-
expect(Array.isArray(response)).toBeTruthy()
|
|
141
|
-
expect(validateAllResponseSchemas(response)).toBeTruthy()
|
|
142
|
-
})
|
|
143
|
-
})
|
|
144
|
-
})
|
|
145
|
-
})
|
|
146
|
-
})
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'
|
|
2
|
-
|
|
3
|
-
import { getApi, getNewArchive, getTimestampMinutesFromNow } from '../ApiUtil.spec'
|
|
4
|
-
|
|
5
|
-
describe('XyoArchivistPayloadApi', () => {
|
|
6
|
-
describe('find', () => {
|
|
7
|
-
const api = getApi()
|
|
8
|
-
let archive = ''
|
|
9
|
-
beforeEach(async () => {
|
|
10
|
-
archive = await getNewArchive(api)
|
|
11
|
-
expect(archive).toBeTruthy()
|
|
12
|
-
})
|
|
13
|
-
describe('when order is ascending', () => {
|
|
14
|
-
it('returns payloads greater than or equal to timestamp', async () => {
|
|
15
|
-
const timestamp = getTimestampMinutesFromNow(-1)
|
|
16
|
-
const [boundWitness] = new BoundWitnessBuilder().build()
|
|
17
|
-
const blockResult = await api.archive(archive).block.post([boundWitness])
|
|
18
|
-
expect(blockResult?.length).toBe(1)
|
|
19
|
-
const response = await api.archive(archive).block.find({ order: 'asc', timestamp })
|
|
20
|
-
expect(response?.length).toBe(1)
|
|
21
|
-
})
|
|
22
|
-
})
|
|
23
|
-
describe('when order is descending', () => {
|
|
24
|
-
it('returns payloads less than or equal to timestamp', async () => {
|
|
25
|
-
const [boundWitness] = new BoundWitnessBuilder().build()
|
|
26
|
-
const blockResult = await api.archive(archive).block.post([boundWitness])
|
|
27
|
-
expect(blockResult?.length).toBe(1)
|
|
28
|
-
const timestamp = getTimestampMinutesFromNow(1)
|
|
29
|
-
const response = await api.archive(archive).block.find({ order: 'desc', timestamp })
|
|
30
|
-
expect(response?.length).toBe(1)
|
|
31
|
-
})
|
|
32
|
-
})
|
|
33
|
-
})
|
|
34
|
-
})
|