@xyo-network/diviner-temporal-indexing-memory 5.1.22 → 5.1.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.mjs.map +1 -1
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/node/index.mjs.map +1 -1
- package/package.json +40 -37
- package/src/IndexQueryResponseToDivinerQueryResponseDiviner/Diviner.ts +1 -1
- package/dist/browser/DivinerQueryToIndexQueryDiviner/spec/Diviner.spec.d.ts +0 -2
- package/dist/browser/DivinerQueryToIndexQueryDiviner/spec/Diviner.spec.d.ts.map +0 -1
- package/dist/browser/IndexCandidateToIndexDiviner/spec/Diviner.spec.d.ts +0 -2
- package/dist/browser/IndexCandidateToIndexDiviner/spec/Diviner.spec.d.ts.map +0 -1
- package/dist/browser/IndexQueryResponseToDivinerQueryResponseDiviner/spec/Diviner.spec.d.ts +0 -2
- package/dist/browser/IndexQueryResponseToDivinerQueryResponseDiviner/spec/Diviner.spec.d.ts.map +0 -1
- package/dist/browser/StateToIndexCandidateDiviner/spec/Diviner.spec.d.ts +0 -2
- package/dist/browser/StateToIndexCandidateDiviner/spec/Diviner.spec.d.ts.map +0 -1
- package/dist/browser/spec/Diviner.Multiple.spec.d.ts +0 -2
- package/dist/browser/spec/Diviner.Multiple.spec.d.ts.map +0 -1
- package/dist/browser/spec/Diviner.spec.d.ts +0 -2
- package/dist/browser/spec/Diviner.spec.d.ts.map +0 -1
- package/dist/neutral/DivinerQueryToIndexQueryDiviner/spec/Diviner.spec.d.ts +0 -2
- package/dist/neutral/DivinerQueryToIndexQueryDiviner/spec/Diviner.spec.d.ts.map +0 -1
- package/dist/neutral/IndexCandidateToIndexDiviner/spec/Diviner.spec.d.ts +0 -2
- package/dist/neutral/IndexCandidateToIndexDiviner/spec/Diviner.spec.d.ts.map +0 -1
- package/dist/neutral/IndexQueryResponseToDivinerQueryResponseDiviner/spec/Diviner.spec.d.ts +0 -2
- package/dist/neutral/IndexQueryResponseToDivinerQueryResponseDiviner/spec/Diviner.spec.d.ts.map +0 -1
- package/dist/neutral/StateToIndexCandidateDiviner/spec/Diviner.spec.d.ts +0 -2
- package/dist/neutral/StateToIndexCandidateDiviner/spec/Diviner.spec.d.ts.map +0 -1
- package/dist/neutral/spec/Diviner.Multiple.spec.d.ts +0 -2
- package/dist/neutral/spec/Diviner.Multiple.spec.d.ts.map +0 -1
- package/dist/neutral/spec/Diviner.spec.d.ts +0 -2
- package/dist/neutral/spec/Diviner.spec.d.ts.map +0 -1
- package/dist/node/DivinerQueryToIndexQueryDiviner/spec/Diviner.spec.d.ts +0 -2
- package/dist/node/DivinerQueryToIndexQueryDiviner/spec/Diviner.spec.d.ts.map +0 -1
- package/dist/node/IndexCandidateToIndexDiviner/spec/Diviner.spec.d.ts +0 -2
- package/dist/node/IndexCandidateToIndexDiviner/spec/Diviner.spec.d.ts.map +0 -1
- package/dist/node/IndexQueryResponseToDivinerQueryResponseDiviner/spec/Diviner.spec.d.ts +0 -2
- package/dist/node/IndexQueryResponseToDivinerQueryResponseDiviner/spec/Diviner.spec.d.ts.map +0 -1
- package/dist/node/StateToIndexCandidateDiviner/spec/Diviner.spec.d.ts +0 -2
- package/dist/node/StateToIndexCandidateDiviner/spec/Diviner.spec.d.ts.map +0 -1
- package/dist/node/spec/Diviner.Multiple.spec.d.ts +0 -2
- package/dist/node/spec/Diviner.Multiple.spec.d.ts.map +0 -1
- package/dist/node/spec/Diviner.spec.d.ts +0 -2
- package/dist/node/spec/Diviner.spec.d.ts.map +0 -1
- package/src/DivinerQueryToIndexQueryDiviner/spec/Diviner.spec.ts +0 -244
- package/src/IndexCandidateToIndexDiviner/spec/Diviner.spec.ts +0 -247
- package/src/IndexQueryResponseToDivinerQueryResponseDiviner/spec/Diviner.spec.ts +0 -103
- package/src/StateToIndexCandidateDiviner/spec/Diviner.spec.ts +0 -167
- package/src/spec/Diviner.Multiple.spec.ts +0 -214
- package/src/spec/Diviner.spec.ts +0 -225
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import '@xylabs/vitest-extended'
|
|
2
|
-
|
|
3
|
-
import type { PayloadDivinerQueryPayload } from '@xyo-network/diviner-payload-model'
|
|
4
|
-
import { PayloadDivinerQuerySchema } from '@xyo-network/diviner-payload-model'
|
|
5
|
-
import type { Payload } from '@xyo-network/payload-model'
|
|
6
|
-
import {
|
|
7
|
-
beforeAll,
|
|
8
|
-
describe, expect, it,
|
|
9
|
-
} from 'vitest'
|
|
10
|
-
|
|
11
|
-
import { TemporalIndexingDivinerIndexQueryResponseToDivinerQueryResponseDiviner } from '../Diviner.ts'
|
|
12
|
-
|
|
13
|
-
type QueryType = Payload<PayloadDivinerQueryPayload & Payload<{ status?: number; success?: boolean; url: string }>>
|
|
14
|
-
|
|
15
|
-
describe('TemporalIndexingDivinerIndexQueryResponseToDivinerQueryResponseDiviner', () => {
|
|
16
|
-
const url = 'https://xyo.network'
|
|
17
|
-
const queries: QueryType[] = [
|
|
18
|
-
{
|
|
19
|
-
schema: PayloadDivinerQuerySchema,
|
|
20
|
-
url,
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
schema: PayloadDivinerQuerySchema,
|
|
24
|
-
url,
|
|
25
|
-
},
|
|
26
|
-
]
|
|
27
|
-
const indexes = [
|
|
28
|
-
[
|
|
29
|
-
{
|
|
30
|
-
schema: 'TODO',
|
|
31
|
-
sources: [],
|
|
32
|
-
status: 200,
|
|
33
|
-
success: true,
|
|
34
|
-
timestamp: 1_234_567_890,
|
|
35
|
-
url,
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
[
|
|
39
|
-
{
|
|
40
|
-
schema: 'TODO',
|
|
41
|
-
sources: [],
|
|
42
|
-
status: 200,
|
|
43
|
-
success: true,
|
|
44
|
-
timestamp: 1_234_567_891,
|
|
45
|
-
url,
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
schema: 'TODO',
|
|
49
|
-
sources: [],
|
|
50
|
-
status: 500,
|
|
51
|
-
success: false,
|
|
52
|
-
timestamp: 1_234_567_892,
|
|
53
|
-
url,
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
]
|
|
57
|
-
let diviner: TemporalIndexingDivinerIndexQueryResponseToDivinerQueryResponseDiviner
|
|
58
|
-
beforeAll(async () => {
|
|
59
|
-
diviner = await TemporalIndexingDivinerIndexQueryResponseToDivinerQueryResponseDiviner.create({ account: 'random' })
|
|
60
|
-
})
|
|
61
|
-
const cases: [QueryType, Payload[]][] = queries.map((query, i) => [query, indexes[i]])
|
|
62
|
-
describe('divine', () => {
|
|
63
|
-
describe('with single url in index result', () => {
|
|
64
|
-
it.each(cases)('transforms single url index results', async (imageThumbnailDivinerQuery, imageThumbnailResultIndex) => {
|
|
65
|
-
const results = await diviner.divine([imageThumbnailDivinerQuery, ...imageThumbnailResultIndex])
|
|
66
|
-
expect(results).toBeArrayOfSize(imageThumbnailResultIndex.length)
|
|
67
|
-
expect(results).toBeArrayOfSize(imageThumbnailResultIndex.length)
|
|
68
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, unicorn/no-array-for-each
|
|
69
|
-
results.forEach((result: any, i) => {
|
|
70
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
|
-
const index = imageThumbnailResultIndex[i] as any
|
|
72
|
-
expect(result.url).toBe(imageThumbnailDivinerQuery.url)
|
|
73
|
-
expect(result.success).toBe(index.success)
|
|
74
|
-
expect(result.timestamp).toBe(index.timestamp)
|
|
75
|
-
expect(result.status).toBe(index.status)
|
|
76
|
-
expect(result.schema).toBe('TODO')
|
|
77
|
-
})
|
|
78
|
-
})
|
|
79
|
-
})
|
|
80
|
-
describe('with multiple urls in index result', () => {
|
|
81
|
-
it('transforms multiple url index results', async () => {
|
|
82
|
-
const indexesLength = indexes.flat().length
|
|
83
|
-
const results = await diviner.divine([...queries, ...indexes.flat()])
|
|
84
|
-
expect(results).toBeArrayOfSize(indexesLength)
|
|
85
|
-
expect(results).toBeArrayOfSize(indexesLength)
|
|
86
|
-
let resultsIterator = 0
|
|
87
|
-
for (const [i, { url }] of queries.entries()) {
|
|
88
|
-
const indexSet = indexes[i]
|
|
89
|
-
for (const index of indexSet) {
|
|
90
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
91
|
-
const result = results[resultsIterator] as any
|
|
92
|
-
expect(result.url).toBe(url)
|
|
93
|
-
expect(result.success).toBe(index.success)
|
|
94
|
-
expect(result.timestamp).toBe(index.timestamp)
|
|
95
|
-
expect(result.status).toBe(index.status)
|
|
96
|
-
expect(result.schema).toBe('TODO')
|
|
97
|
-
resultsIterator = ++resultsIterator
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
})
|
|
101
|
-
})
|
|
102
|
-
})
|
|
103
|
-
})
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import '@xylabs/vitest-extended'
|
|
2
|
-
|
|
3
|
-
import { filterAs } from '@xylabs/array'
|
|
4
|
-
import { assertEx } from '@xylabs/assert'
|
|
5
|
-
import { delay } from '@xylabs/delay'
|
|
6
|
-
import type { MemoryArchivist } from '@xyo-network/archivist-memory'
|
|
7
|
-
import { asArchivistInstance } from '@xyo-network/archivist-model'
|
|
8
|
-
import { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'
|
|
9
|
-
import { isBoundWitness } from '@xyo-network/boundwitness-model'
|
|
10
|
-
import type { IndexingDivinerState } from '@xyo-network/diviner-indexing-model'
|
|
11
|
-
import { asDivinerInstance } from '@xyo-network/diviner-model'
|
|
12
|
-
import type { PackageManifestPayload } from '@xyo-network/manifest'
|
|
13
|
-
import { ManifestWrapper } from '@xyo-network/manifest'
|
|
14
|
-
import { ModuleFactoryLocator } from '@xyo-network/module-factory-locator'
|
|
15
|
-
import type { ModuleState } from '@xyo-network/module-model'
|
|
16
|
-
import { isModuleState, ModuleStateSchema } from '@xyo-network/module-model'
|
|
17
|
-
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
18
|
-
import type { Payload, WithStorageMeta } from '@xyo-network/payload-model'
|
|
19
|
-
import { asOptionalStorageMeta } from '@xyo-network/payload-model'
|
|
20
|
-
import { HDWallet } from '@xyo-network/wallet'
|
|
21
|
-
import type { TimeStamp } from '@xyo-network/witness-timestamp'
|
|
22
|
-
import { isTimestamp, TimestampSchema } from '@xyo-network/witness-timestamp'
|
|
23
|
-
import {
|
|
24
|
-
beforeAll, describe, expect, it,
|
|
25
|
-
} from 'vitest'
|
|
26
|
-
|
|
27
|
-
import { TemporalIndexingDivinerStateToIndexCandidateDiviner } from '../Diviner.ts'
|
|
28
|
-
import TemporalStateToIndexCandidateDivinerManifest from './TemporalStateToIndexCandidateDiviner.json' with { type: 'json' }
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @group slow
|
|
32
|
-
*/
|
|
33
|
-
describe('TemporalStateToIndexCandidateDiviner', () => {
|
|
34
|
-
const sourceUrl = 'https://placekitten.com/200/300'
|
|
35
|
-
const thumbnailHttpSuccess = {
|
|
36
|
-
http: { status: 200 },
|
|
37
|
-
schema: 'network.xyo.image.thumbnail',
|
|
38
|
-
sourceHash: '7f39363514d9d9b958a5a993edeba35cb44f912c7072ed9ddd628728ac0fd681',
|
|
39
|
-
sourceUrl,
|
|
40
|
-
url: 'data:image/png;base64,===',
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const thumbnailHttpFail = {
|
|
44
|
-
http: {
|
|
45
|
-
|
|
46
|
-
ipAddress: '104.17.96.13',
|
|
47
|
-
status: 429,
|
|
48
|
-
},
|
|
49
|
-
schema: 'network.xyo.image.thumbnail',
|
|
50
|
-
sourceUrl,
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const thumbnailCodeFail = {
|
|
54
|
-
http: { code: 'FAILED' },
|
|
55
|
-
schema: 'network.xyo.image.thumbnail',
|
|
56
|
-
sourceUrl,
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const thumbnailWitnessFail = {
|
|
60
|
-
|
|
61
|
-
http: { ipAddress: '104.17.96.13' },
|
|
62
|
-
schema: 'network.xyo.image.thumbnail',
|
|
63
|
-
sourceUrl,
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
let testCases: WithStorageMeta<Payload>[][] = []
|
|
67
|
-
let archivist: MemoryArchivist
|
|
68
|
-
let sut: TemporalIndexingDivinerStateToIndexCandidateDiviner
|
|
69
|
-
|
|
70
|
-
beforeAll(async () => {
|
|
71
|
-
const wallet = await HDWallet.random()
|
|
72
|
-
const locator = new ModuleFactoryLocator()
|
|
73
|
-
locator.register(TemporalIndexingDivinerStateToIndexCandidateDiviner.factory())
|
|
74
|
-
const manifest = TemporalStateToIndexCandidateDivinerManifest as PackageManifestPayload
|
|
75
|
-
const manifestWrapper = new ManifestWrapper(manifest, wallet, locator)
|
|
76
|
-
const node = await manifestWrapper.loadNodeFromIndex(0)
|
|
77
|
-
await node.start()
|
|
78
|
-
|
|
79
|
-
const privateModules = manifest.nodes[0].modules?.private ?? []
|
|
80
|
-
const publicModules = manifest.nodes[0].modules?.public ?? []
|
|
81
|
-
const mods = await node.resolve('*')
|
|
82
|
-
expect(mods.length).toBe(privateModules.length + publicModules.length + 1)
|
|
83
|
-
|
|
84
|
-
// Insert previously witnessed payloads into thumbnail archivist
|
|
85
|
-
const httpSuccessTimestamp: TimeStamp = { schema: TimestampSchema, timestamp: 1 }
|
|
86
|
-
const [httpSuccessBoundWitness, httpSuccessPayloads] = await new BoundWitnessBuilder()
|
|
87
|
-
.payloads([thumbnailHttpSuccess, httpSuccessTimestamp])
|
|
88
|
-
.build()
|
|
89
|
-
const httpFailTimestamp: TimeStamp = { schema: TimestampSchema, timestamp: 2 }
|
|
90
|
-
const [httpFailBoundWitness, httpFailPayloads] = await (new BoundWitnessBuilder().payloads([thumbnailHttpFail, httpFailTimestamp])).build()
|
|
91
|
-
|
|
92
|
-
const witnessFailTimestamp: TimeStamp = { schema: TimestampSchema, timestamp: 3 }
|
|
93
|
-
const [witnessFailBoundWitness, witnessFailPayloads] = await new BoundWitnessBuilder()
|
|
94
|
-
.payloads([thumbnailWitnessFail, witnessFailTimestamp])
|
|
95
|
-
.build()
|
|
96
|
-
|
|
97
|
-
const codeFailTimestamp: TimeStamp = { schema: TimestampSchema, timestamp: 4 }
|
|
98
|
-
const [codeFailBoundWitness, codeFailPayloads] = await (new BoundWitnessBuilder().payloads([thumbnailCodeFail, codeFailTimestamp])).build()
|
|
99
|
-
|
|
100
|
-
archivist = assertEx(asArchivistInstance<MemoryArchivist>(await node.resolve('ImageThumbnailArchivist')))
|
|
101
|
-
const testCasesToCreate = [
|
|
102
|
-
[httpSuccessBoundWitness, ...httpSuccessPayloads],
|
|
103
|
-
[httpFailBoundWitness, ...httpFailPayloads],
|
|
104
|
-
[witnessFailBoundWitness, ...witnessFailPayloads],
|
|
105
|
-
[codeFailBoundWitness, ...codeFailPayloads],
|
|
106
|
-
]
|
|
107
|
-
|
|
108
|
-
for (const [bw, ...payloads] of testCasesToCreate) {
|
|
109
|
-
const createdTestCase = []
|
|
110
|
-
for (const payload of [bw, ...payloads]) {
|
|
111
|
-
await delay(2)
|
|
112
|
-
const [signedPayload] = await archivist.insert([payload])
|
|
113
|
-
createdTestCase.push(signedPayload)
|
|
114
|
-
}
|
|
115
|
-
testCases.push(createdTestCase)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
sut = assertEx(
|
|
119
|
-
asDivinerInstance(await node.resolve('TemporalStateToIndexCandidateDiviner')),
|
|
120
|
-
) as TemporalIndexingDivinerStateToIndexCandidateDiviner
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
describe('divine', () => {
|
|
124
|
-
describe('with no previous state', () => {
|
|
125
|
-
it('returns next state and batch results', async () => {
|
|
126
|
-
const results = await sut.divine()
|
|
127
|
-
expect(results.length).toBe(testCases.flat().length + 1)
|
|
128
|
-
const state = results.find(isModuleState<IndexingDivinerState>)
|
|
129
|
-
expect(state).toBeDefined()
|
|
130
|
-
const last = filterAs(results, asOptionalStorageMeta)
|
|
131
|
-
.map(p => p as WithStorageMeta<Payload>)
|
|
132
|
-
.toSorted(PayloadBuilder.compareStorageMeta)
|
|
133
|
-
.at(-1)
|
|
134
|
-
expect(last).toBeDefined()
|
|
135
|
-
expect(state?.state.cursor).toBe(last?._sequence)
|
|
136
|
-
})
|
|
137
|
-
})
|
|
138
|
-
describe('with previous state', () => {
|
|
139
|
-
it.each([1, 2, 3])('returns next state and batch results', async (batch) => {
|
|
140
|
-
const all = (await archivist.all()).toSorted(PayloadBuilder.compareStorageMeta)
|
|
141
|
-
const batchOffset = all.at((3 * batch) - 1)
|
|
142
|
-
expect(batchOffset).toBeDefined()
|
|
143
|
-
// Test across all offsets
|
|
144
|
-
const cursor = assertEx(batchOffset)._sequence
|
|
145
|
-
const lastState: ModuleState<IndexingDivinerState> = { schema: ModuleStateSchema, state: { cursor } }
|
|
146
|
-
const results = await sut.divine([lastState])
|
|
147
|
-
|
|
148
|
-
// Validate expected results length
|
|
149
|
-
// [BW, ImageThumbnail, TimeStamp] + 1 [ModuleState]
|
|
150
|
-
const expectedResults = testCases.slice(batch).flat().length + 1
|
|
151
|
-
expect(results.length).toBe(expectedResults)
|
|
152
|
-
|
|
153
|
-
// Validate expected state
|
|
154
|
-
const nextState = results.find(isModuleState<IndexingDivinerState>)
|
|
155
|
-
expect(nextState).toBeDefined()
|
|
156
|
-
expect(nextState?.state?.cursor).toBeDefined()
|
|
157
|
-
expect(nextState?.state.cursor).toBe(testCases?.at(-1)?.at(-1)?._sequence)
|
|
158
|
-
|
|
159
|
-
// Validate expected individual results
|
|
160
|
-
const bws = results.filter(isBoundWitness)
|
|
161
|
-
expect(bws.length).toBeGreaterThan(0)
|
|
162
|
-
const timestamps = results.filter(isTimestamp)
|
|
163
|
-
expect(timestamps.length).toBeGreaterThan(0)
|
|
164
|
-
})
|
|
165
|
-
})
|
|
166
|
-
})
|
|
167
|
-
})
|
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import '@xylabs/vitest-extended'
|
|
2
|
-
|
|
3
|
-
import { filterAs } from '@xylabs/array'
|
|
4
|
-
import { assertEx } from '@xylabs/assert'
|
|
5
|
-
import { delay } from '@xylabs/delay'
|
|
6
|
-
import { AsObjectFactory } from '@xylabs/object'
|
|
7
|
-
import type { MemoryArchivist } from '@xyo-network/archivist-memory'
|
|
8
|
-
import { asArchivistInstance } from '@xyo-network/archivist-model'
|
|
9
|
-
import { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'
|
|
10
|
-
import { asBoundWitness } from '@xyo-network/boundwitness-model'
|
|
11
|
-
import { asDivinerInstance } from '@xyo-network/diviner-model'
|
|
12
|
-
import type { PayloadDivinerQueryPayload } from '@xyo-network/diviner-payload-model'
|
|
13
|
-
import { PayloadDivinerQuerySchema } from '@xyo-network/diviner-payload-model'
|
|
14
|
-
import { isTemporalIndexingDivinerResultIndex } from '@xyo-network/diviner-temporal-indexing-model'
|
|
15
|
-
import type { PackageManifestPayload } from '@xyo-network/manifest'
|
|
16
|
-
import { ManifestWrapper } from '@xyo-network/manifest'
|
|
17
|
-
import { ModuleFactoryLocator } from '@xyo-network/module-factory-locator'
|
|
18
|
-
import type {
|
|
19
|
-
Labels, ModuleState, StateDictionary,
|
|
20
|
-
} from '@xyo-network/module-model'
|
|
21
|
-
import { isModuleState } from '@xyo-network/module-model'
|
|
22
|
-
import type { MemoryNode } from '@xyo-network/node-memory'
|
|
23
|
-
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
24
|
-
import type { Payload } from '@xyo-network/payload-model'
|
|
25
|
-
import { HDWallet } from '@xyo-network/wallet'
|
|
26
|
-
import type { TimeStamp } from '@xyo-network/witness-timestamp'
|
|
27
|
-
import { TimestampSchema } from '@xyo-network/witness-timestamp'
|
|
28
|
-
import {
|
|
29
|
-
beforeAll,
|
|
30
|
-
describe, expect, it,
|
|
31
|
-
} from 'vitest'
|
|
32
|
-
|
|
33
|
-
import { TemporalIndexingDiviner } from '../Diviner.ts'
|
|
34
|
-
import { TemporalIndexingDivinerDivinerQueryToIndexQueryDiviner } from '../DivinerQueryToIndexQueryDiviner/index.ts'
|
|
35
|
-
import { TemporalIndexingDivinerIndexCandidateToIndexDiviner } from '../IndexCandidateToIndexDiviner/index.ts'
|
|
36
|
-
import { TemporalIndexingDivinerIndexQueryResponseToDivinerQueryResponseDiviner } from '../IndexQueryResponseToDivinerQueryResponseDiviner/index.ts'
|
|
37
|
-
import { TemporalIndexingDivinerStateToIndexCandidateDiviner } from '../StateToIndexCandidateDiviner/index.ts'
|
|
38
|
-
import imageThumbnailDivinerManifest from './TemporalDiviner.json' with { type: 'json' }
|
|
39
|
-
|
|
40
|
-
type ImageThumbnail = Payload<{
|
|
41
|
-
http?: {
|
|
42
|
-
code?: string
|
|
43
|
-
ipAddress?: string
|
|
44
|
-
status?: number
|
|
45
|
-
}
|
|
46
|
-
// schema: 'network.xyo.image.thumbnail'
|
|
47
|
-
sourceHash?: string
|
|
48
|
-
sourceUrl: string
|
|
49
|
-
url?: string
|
|
50
|
-
}>
|
|
51
|
-
|
|
52
|
-
type Query = PayloadDivinerQueryPayload & { status?: number; success?: boolean; url?: string }
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* @group slow
|
|
56
|
-
*/
|
|
57
|
-
describe('TemporalIndexingDiviner - Multiple', () => {
|
|
58
|
-
const sourceUrl = 'https://placekitten.com/200/300'
|
|
59
|
-
const thumbnailHttpSuccess: ImageThumbnail = {
|
|
60
|
-
http: { status: 200 },
|
|
61
|
-
schema: 'network.xyo.image.thumbnail',
|
|
62
|
-
sourceHash: '7f39363514d9d9b958a5a993edeba35cb44f912c7072ed9ddd628728ac0fd681',
|
|
63
|
-
sourceUrl,
|
|
64
|
-
url: 'data:image/png;base64,===',
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const thumbnailHttpFail: ImageThumbnail = {
|
|
68
|
-
http: {
|
|
69
|
-
|
|
70
|
-
ipAddress: '104.17.96.13',
|
|
71
|
-
status: 429,
|
|
72
|
-
},
|
|
73
|
-
schema: 'network.xyo.image.thumbnail',
|
|
74
|
-
sourceUrl,
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const thumbnailCodeFail: ImageThumbnail = {
|
|
78
|
-
http: { code: 'FAILED' },
|
|
79
|
-
schema: 'network.xyo.image.thumbnail',
|
|
80
|
-
sourceUrl,
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const thumbnailWitnessFail: ImageThumbnail = {
|
|
84
|
-
|
|
85
|
-
http: { ipAddress: '104.17.96.13' },
|
|
86
|
-
schema: 'network.xyo.image.thumbnail',
|
|
87
|
-
sourceUrl,
|
|
88
|
-
}
|
|
89
|
-
const witnessedThumbnails = [thumbnailHttpSuccess, thumbnailHttpFail, thumbnailCodeFail, thumbnailWitnessFail]
|
|
90
|
-
|
|
91
|
-
let sut: TemporalIndexingDiviner
|
|
92
|
-
let node: MemoryNode
|
|
93
|
-
|
|
94
|
-
beforeAll(async () => {
|
|
95
|
-
const labels: Labels = { 'network.xyo.image.thumbnail': 'diviner' }
|
|
96
|
-
const wallet = await HDWallet.random()
|
|
97
|
-
const locator = new ModuleFactoryLocator()
|
|
98
|
-
locator.register(TemporalIndexingDivinerDivinerQueryToIndexQueryDiviner.factory(), labels)
|
|
99
|
-
locator.register(TemporalIndexingDivinerIndexCandidateToIndexDiviner.factory(), labels)
|
|
100
|
-
locator.register(TemporalIndexingDivinerIndexQueryResponseToDivinerQueryResponseDiviner.factory(), labels)
|
|
101
|
-
locator.register(TemporalIndexingDivinerStateToIndexCandidateDiviner.factory(), labels)
|
|
102
|
-
locator.register(TemporalIndexingDiviner.factory(), labels)
|
|
103
|
-
const manifest = imageThumbnailDivinerManifest as PackageManifestPayload
|
|
104
|
-
const manifestWrapper = new ManifestWrapper(manifest, wallet, locator)
|
|
105
|
-
node = await manifestWrapper.loadNodeFromIndex(0)
|
|
106
|
-
await node.start()
|
|
107
|
-
|
|
108
|
-
// Insert previously witnessed payloads into thumbnail archivist
|
|
109
|
-
const timestamp: TimeStamp = { schema: TimestampSchema, timestamp: Date.now() }
|
|
110
|
-
const [boundWitness, payloads] = await new BoundWitnessBuilder().payloads([timestamp, ...witnessedThumbnails]).build()
|
|
111
|
-
|
|
112
|
-
const thumbnailArchivist = assertEx(asArchivistInstance<MemoryArchivist>(await node.resolve('ImageThumbnailArchivist')))
|
|
113
|
-
await thumbnailArchivist.insert([boundWitness, ...payloads])
|
|
114
|
-
|
|
115
|
-
sut = assertEx(asDivinerInstance(await node.resolve('ImageThumbnailDiviner'))) as TemporalIndexingDiviner
|
|
116
|
-
|
|
117
|
-
// Allow enough time for diviner to divine
|
|
118
|
-
await delay(1000)
|
|
119
|
-
}, 40_000)
|
|
120
|
-
describe('diviner state', () => {
|
|
121
|
-
let stateArchivist: MemoryArchivist
|
|
122
|
-
beforeAll(async () => {
|
|
123
|
-
const mod = await node.resolve('AddressStateArchivist')
|
|
124
|
-
stateArchivist = assertEx(asArchivistInstance<MemoryArchivist>(mod))
|
|
125
|
-
})
|
|
126
|
-
it('has expected bound witnesses', async () => {
|
|
127
|
-
const payloads = await stateArchivist.all()
|
|
128
|
-
const stateBoundWitnesses = filterAs(payloads, asBoundWitness)
|
|
129
|
-
expect(stateBoundWitnesses).toBeArrayOfSize(1)
|
|
130
|
-
for (const stateBoundWitness of stateBoundWitnesses) {
|
|
131
|
-
expect(stateBoundWitness).toBeObject()
|
|
132
|
-
expect(stateBoundWitness.addresses).toBeArrayOfSize(1)
|
|
133
|
-
expect(stateBoundWitness.addresses).toContain(sut.address)
|
|
134
|
-
}
|
|
135
|
-
})
|
|
136
|
-
it('has expected state', async () => {
|
|
137
|
-
const payloads = await stateArchivist.all()
|
|
138
|
-
try {
|
|
139
|
-
const asModuleState = AsObjectFactory.create<ModuleState<StateDictionary>>(isModuleState)
|
|
140
|
-
const statePayloads = filterAs(payloads, asModuleState)
|
|
141
|
-
expect(statePayloads).toBeArrayOfSize(1)
|
|
142
|
-
expect(statePayloads.at(-1)).toBeObject()
|
|
143
|
-
const statePayload = assertEx(statePayloads.at(-1))
|
|
144
|
-
expect(statePayload.state).toBeObject()
|
|
145
|
-
expect(statePayload.state?.cursor).toBeDefined()
|
|
146
|
-
} catch (ex) {
|
|
147
|
-
console.error('State payloads:', payloads)
|
|
148
|
-
throw ex
|
|
149
|
-
}
|
|
150
|
-
})
|
|
151
|
-
})
|
|
152
|
-
describe('diviner index', () => {
|
|
153
|
-
let indexArchivist: MemoryArchivist
|
|
154
|
-
beforeAll(async () => {
|
|
155
|
-
const mod = await node.resolve('ImageThumbnailDivinerIndexArchivist')
|
|
156
|
-
indexArchivist = assertEx(asArchivistInstance<MemoryArchivist>(mod))
|
|
157
|
-
})
|
|
158
|
-
// NOTE: We're not signing indexes for performance reasons
|
|
159
|
-
it.skip('has expected bound witnesses', async () => {
|
|
160
|
-
const payloads = await indexArchivist.all()
|
|
161
|
-
const indexBoundWitnesses = filterAs(payloads, asBoundWitness)
|
|
162
|
-
expect(indexBoundWitnesses).toBeArrayOfSize(1)
|
|
163
|
-
const indexBoundWitness = indexBoundWitnesses[0]
|
|
164
|
-
expect(indexBoundWitness).toBeObject()
|
|
165
|
-
expect(indexBoundWitness.addresses).toBeArrayOfSize(1)
|
|
166
|
-
expect(indexBoundWitness.addresses).toContain(sut.address)
|
|
167
|
-
})
|
|
168
|
-
it('has expected index', async () => {
|
|
169
|
-
const payloads = await indexArchivist.all()
|
|
170
|
-
const indexPayloads = payloads.filter(isTemporalIndexingDivinerResultIndex)
|
|
171
|
-
expect(indexPayloads).toBeArrayOfSize((witnessedThumbnails).length)
|
|
172
|
-
})
|
|
173
|
-
})
|
|
174
|
-
describe('with no thumbnail for the provided URL', () => {
|
|
175
|
-
const url = 'https://does.not.exist.io'
|
|
176
|
-
const schema = PayloadDivinerQuerySchema
|
|
177
|
-
it('returns nothing', async () => {
|
|
178
|
-
const query: Query = { schema, url }
|
|
179
|
-
const result = await sut.divine([query])
|
|
180
|
-
expect(result).toBeArrayOfSize(0)
|
|
181
|
-
})
|
|
182
|
-
})
|
|
183
|
-
describe('with thumbnails for the provided URL', () => {
|
|
184
|
-
const url = sourceUrl
|
|
185
|
-
const schema = PayloadDivinerQuerySchema
|
|
186
|
-
describe('with no filter criteria', () => {
|
|
187
|
-
it('returns the most recent result', async () => {
|
|
188
|
-
const query: Query = { schema, url }
|
|
189
|
-
const results = await sut.divine([query])
|
|
190
|
-
const result = results.find(isTemporalIndexingDivinerResultIndex)
|
|
191
|
-
expect(result).toBeDefined()
|
|
192
|
-
const payload = assertEx((witnessedThumbnails).at(-1))
|
|
193
|
-
const expected = await PayloadBuilder.dataHash(payload)
|
|
194
|
-
expect(result?.$sources).toContain(expected)
|
|
195
|
-
})
|
|
196
|
-
})
|
|
197
|
-
describe('with filter criteria', () => {
|
|
198
|
-
describe('for status code', () => {
|
|
199
|
-
const cases: ImageThumbnail[] = [thumbnailHttpSuccess, thumbnailHttpFail]
|
|
200
|
-
it.each(cases)('returns the most recent instance of that status code', async (payload) => {
|
|
201
|
-
const { status } = payload.http ?? {}
|
|
202
|
-
const query: Query = {
|
|
203
|
-
schema, status, url,
|
|
204
|
-
}
|
|
205
|
-
const results = await sut.divine([query])
|
|
206
|
-
const result = results.find(isTemporalIndexingDivinerResultIndex)
|
|
207
|
-
expect(result).toBeDefined()
|
|
208
|
-
const expected = await PayloadBuilder.dataHash(payload)
|
|
209
|
-
expect(result?.$sources).toContain(expected)
|
|
210
|
-
})
|
|
211
|
-
})
|
|
212
|
-
})
|
|
213
|
-
})
|
|
214
|
-
})
|