@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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/Diviner.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.spec.d.ts","sourceRoot":"","sources":["../../../../src/DivinerQueryToIndexQueryDiviner/spec/Diviner.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.spec.d.ts","sourceRoot":"","sources":["../../../../src/IndexCandidateToIndexDiviner/spec/Diviner.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
package/dist/neutral/IndexQueryResponseToDivinerQueryResponseDiviner/spec/Diviner.spec.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.spec.d.ts","sourceRoot":"","sources":["../../../../src/IndexQueryResponseToDivinerQueryResponseDiviner/spec/Diviner.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.spec.d.ts","sourceRoot":"","sources":["../../../../src/StateToIndexCandidateDiviner/spec/Diviner.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.Multiple.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/Diviner.Multiple.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/Diviner.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.spec.d.ts","sourceRoot":"","sources":["../../../../src/DivinerQueryToIndexQueryDiviner/spec/Diviner.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.spec.d.ts","sourceRoot":"","sources":["../../../../src/IndexCandidateToIndexDiviner/spec/Diviner.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
package/dist/node/IndexQueryResponseToDivinerQueryResponseDiviner/spec/Diviner.spec.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.spec.d.ts","sourceRoot":"","sources":["../../../../src/IndexQueryResponseToDivinerQueryResponseDiviner/spec/Diviner.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.spec.d.ts","sourceRoot":"","sources":["../../../../src/StateToIndexCandidateDiviner/spec/Diviner.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.Multiple.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/Diviner.Multiple.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/Diviner.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
import '@xylabs/vitest-extended'
|
|
2
|
-
|
|
3
|
-
import type { SchemaToJsonPathTransformExpressionsDictionary } from '@xyo-network/diviner-jsonpath-model'
|
|
4
|
-
import type { PayloadDivinerQueryPayload } from '@xyo-network/diviner-payload-model'
|
|
5
|
-
import { isPayloadDivinerQueryPayload, PayloadDivinerQuerySchema } from '@xyo-network/diviner-payload-model'
|
|
6
|
-
import type { TemporalIndexingDivinerDivinerQueryToIndexQueryDivinerConfig } from '@xyo-network/diviner-temporal-indexing-model'
|
|
7
|
-
import {
|
|
8
|
-
TemporalIndexingDivinerDivinerQueryToIndexQueryDivinerConfigSchema,
|
|
9
|
-
TemporalIndexingDivinerResultIndexSchema,
|
|
10
|
-
} from '@xyo-network/diviner-temporal-indexing-model'
|
|
11
|
-
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
12
|
-
import type { Payload } from '@xyo-network/payload-model'
|
|
13
|
-
import { isPayloadOfSchemaType } from '@xyo-network/payload-model'
|
|
14
|
-
import {
|
|
15
|
-
beforeAll,
|
|
16
|
-
describe, expect, it,
|
|
17
|
-
} from 'vitest'
|
|
18
|
-
|
|
19
|
-
import { TemporalIndexingDivinerDivinerQueryToIndexQueryDiviner } from '../Diviner.ts'
|
|
20
|
-
|
|
21
|
-
type QueryType = PayloadDivinerQueryPayload<{ status?: number; success?: boolean; url: string }>
|
|
22
|
-
|
|
23
|
-
describe('TemporalIndexingDivinerDivinerQueryToIndexQueryDiviner', () => {
|
|
24
|
-
const url = 'https://xyo.network'
|
|
25
|
-
let diviner: TemporalIndexingDivinerDivinerQueryToIndexQueryDiviner
|
|
26
|
-
describe('divine', () => {
|
|
27
|
-
describe('with with no config specified', () => {
|
|
28
|
-
const queries: QueryType[] = [
|
|
29
|
-
{
|
|
30
|
-
schema: PayloadDivinerQuerySchema,
|
|
31
|
-
url,
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
limit: 10,
|
|
35
|
-
order: 'asc',
|
|
36
|
-
schema: PayloadDivinerQuerySchema,
|
|
37
|
-
},
|
|
38
|
-
]
|
|
39
|
-
const expected: PayloadDivinerQueryPayload[] = [
|
|
40
|
-
{
|
|
41
|
-
limit: 1,
|
|
42
|
-
order: 'desc',
|
|
43
|
-
schema: 'network.xyo.diviner.payload.query',
|
|
44
|
-
schemas: [TemporalIndexingDivinerResultIndexSchema],
|
|
45
|
-
} as unknown as PayloadDivinerQueryPayload,
|
|
46
|
-
{
|
|
47
|
-
limit: 10,
|
|
48
|
-
order: 'asc',
|
|
49
|
-
schema: 'network.xyo.diviner.payload.query',
|
|
50
|
-
schemas: [TemporalIndexingDivinerResultIndexSchema],
|
|
51
|
-
} as unknown as PayloadDivinerQueryPayload,
|
|
52
|
-
]
|
|
53
|
-
beforeAll(async () => {
|
|
54
|
-
diviner = await TemporalIndexingDivinerDivinerQueryToIndexQueryDiviner.create({ account: 'random' })
|
|
55
|
-
})
|
|
56
|
-
const cases: [QueryType, PayloadDivinerQueryPayload][] = queries.map((query, i) => [query, expected[i]])
|
|
57
|
-
describe('with single query', () => {
|
|
58
|
-
it.each(cases)('transforms query using default settings', async (query, expected) => {
|
|
59
|
-
const results = await diviner.divine([query])
|
|
60
|
-
const actual = results.filter(isPayloadDivinerQueryPayload)
|
|
61
|
-
expect(actual).toBeArrayOfSize(1)
|
|
62
|
-
expect(PayloadBuilder.omitMeta(actual[0])).toEqual(PayloadBuilder.omitMeta(expected))
|
|
63
|
-
})
|
|
64
|
-
})
|
|
65
|
-
describe('with multiple queries', () => {
|
|
66
|
-
it('transforms queries using default settings', async () => {
|
|
67
|
-
const results = await diviner.divine(queries)
|
|
68
|
-
const actual = results.filter(isPayloadDivinerQueryPayload)
|
|
69
|
-
expect(actual).toBeArrayOfSize(expected.length)
|
|
70
|
-
expect(actual.map(i => PayloadBuilder.omitMeta(i))).toEqual(expected.map(i => PayloadBuilder.omitMeta(i)))
|
|
71
|
-
})
|
|
72
|
-
})
|
|
73
|
-
})
|
|
74
|
-
describe('with config fields specified', () => {
|
|
75
|
-
const divinerQuerySchema = 'network.xyo.test.source.query'
|
|
76
|
-
const indexQuerySchema = 'network.xyo.test.destination.query'
|
|
77
|
-
const indexSchema = 'network.xyo.test.index.schema'
|
|
78
|
-
const queries = [
|
|
79
|
-
{
|
|
80
|
-
schema: divinerQuerySchema,
|
|
81
|
-
url,
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
limit: 10,
|
|
85
|
-
order: 'asc',
|
|
86
|
-
schema: divinerQuerySchema,
|
|
87
|
-
status: 200,
|
|
88
|
-
success: true,
|
|
89
|
-
url,
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
limit: 10,
|
|
93
|
-
schema: divinerQuerySchema,
|
|
94
|
-
url,
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
schema: divinerQuerySchema,
|
|
98
|
-
url,
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
order: 'asc',
|
|
102
|
-
schema: divinerQuerySchema,
|
|
103
|
-
url,
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
schema: divinerQuerySchema,
|
|
107
|
-
status: 200,
|
|
108
|
-
url,
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
schema: divinerQuerySchema,
|
|
112
|
-
success: true,
|
|
113
|
-
url,
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
schema: divinerQuerySchema,
|
|
117
|
-
success: false,
|
|
118
|
-
url,
|
|
119
|
-
},
|
|
120
|
-
]
|
|
121
|
-
const expected = [
|
|
122
|
-
{
|
|
123
|
-
limit: 1,
|
|
124
|
-
order: 'desc',
|
|
125
|
-
schema: indexQuerySchema,
|
|
126
|
-
schemas: [indexSchema],
|
|
127
|
-
url,
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
limit: 10,
|
|
131
|
-
order: 'asc',
|
|
132
|
-
schema: indexQuerySchema,
|
|
133
|
-
schemas: [indexSchema],
|
|
134
|
-
status: 200,
|
|
135
|
-
success: true,
|
|
136
|
-
url,
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
limit: 10,
|
|
140
|
-
order: 'desc',
|
|
141
|
-
schema: indexQuerySchema,
|
|
142
|
-
schemas: [indexSchema],
|
|
143
|
-
url,
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
limit: 1,
|
|
147
|
-
order: 'desc',
|
|
148
|
-
schema: indexQuerySchema,
|
|
149
|
-
schemas: [indexSchema],
|
|
150
|
-
url,
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
limit: 1,
|
|
154
|
-
order: 'asc',
|
|
155
|
-
schema: indexQuerySchema,
|
|
156
|
-
schemas: [indexSchema],
|
|
157
|
-
url,
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
limit: 1,
|
|
161
|
-
order: 'desc',
|
|
162
|
-
schema: indexQuerySchema,
|
|
163
|
-
schemas: [indexSchema],
|
|
164
|
-
status: 200,
|
|
165
|
-
url,
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
limit: 1,
|
|
169
|
-
order: 'desc',
|
|
170
|
-
schema: indexQuerySchema,
|
|
171
|
-
schemas: [indexSchema],
|
|
172
|
-
success: true,
|
|
173
|
-
url,
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
limit: 1,
|
|
177
|
-
order: 'desc',
|
|
178
|
-
schema: indexQuerySchema,
|
|
179
|
-
schemas: [indexSchema],
|
|
180
|
-
success: false,
|
|
181
|
-
url,
|
|
182
|
-
},
|
|
183
|
-
]
|
|
184
|
-
const cases: [Payload, Payload][] = queries.map((query, i) => [query, expected[i]])
|
|
185
|
-
const schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary = {
|
|
186
|
-
[divinerQuerySchema]: [
|
|
187
|
-
{
|
|
188
|
-
destinationField: 'url',
|
|
189
|
-
sourcePathExpression: '$.url',
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
defaultValue: 1,
|
|
193
|
-
destinationField: 'limit',
|
|
194
|
-
sourcePathExpression: '$.limit',
|
|
195
|
-
},
|
|
196
|
-
{
|
|
197
|
-
// defaultValue: 0,
|
|
198
|
-
destinationField: 'cursor',
|
|
199
|
-
sourcePathExpression: '$.cursor',
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
defaultValue: 'desc',
|
|
203
|
-
destinationField: 'order',
|
|
204
|
-
sourcePathExpression: '$.order',
|
|
205
|
-
},
|
|
206
|
-
{
|
|
207
|
-
destinationField: 'status',
|
|
208
|
-
sourcePathExpression: '$.status',
|
|
209
|
-
},
|
|
210
|
-
{
|
|
211
|
-
destinationField: 'success',
|
|
212
|
-
sourcePathExpression: '$.success',
|
|
213
|
-
},
|
|
214
|
-
],
|
|
215
|
-
}
|
|
216
|
-
const config: TemporalIndexingDivinerDivinerQueryToIndexQueryDivinerConfig = {
|
|
217
|
-
divinerQuerySchema,
|
|
218
|
-
indexQuerySchema,
|
|
219
|
-
indexSchema,
|
|
220
|
-
schema: TemporalIndexingDivinerDivinerQueryToIndexQueryDivinerConfigSchema,
|
|
221
|
-
schemaTransforms,
|
|
222
|
-
}
|
|
223
|
-
beforeAll(async () => {
|
|
224
|
-
diviner = await TemporalIndexingDivinerDivinerQueryToIndexQueryDiviner.create({ account: 'random', config })
|
|
225
|
-
})
|
|
226
|
-
describe('with single query', () => {
|
|
227
|
-
it.each(cases)('transforms query using default settings', async (query, expected) => {
|
|
228
|
-
const results = await diviner.divine([query])
|
|
229
|
-
const actual = results.filter(isPayloadOfSchemaType<Payload>(indexQuerySchema))
|
|
230
|
-
expect(actual).toBeArrayOfSize(1)
|
|
231
|
-
expect(PayloadBuilder.omitMeta(actual[0])).toEqual(PayloadBuilder.omitMeta(expected))
|
|
232
|
-
})
|
|
233
|
-
})
|
|
234
|
-
describe('with multiple queries', () => {
|
|
235
|
-
it('transforms queries using default settings', async () => {
|
|
236
|
-
const results = await diviner.divine(queries)
|
|
237
|
-
const actual = results.filter(isPayloadOfSchemaType<Payload>(indexQuerySchema))
|
|
238
|
-
expect(actual).toBeArrayOfSize(expected.length)
|
|
239
|
-
expect(actual.map(i => PayloadBuilder.omitMeta(i))).toEqual(expected.map(i => PayloadBuilder.omitMeta(i)))
|
|
240
|
-
})
|
|
241
|
-
})
|
|
242
|
-
})
|
|
243
|
-
})
|
|
244
|
-
})
|
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import '@xylabs/vitest-extended'
|
|
2
|
-
|
|
3
|
-
import { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'
|
|
4
|
-
import type { BoundWitness } from '@xyo-network/boundwitness-model'
|
|
5
|
-
import type { SchemaToJsonPathTransformExpressionsDictionary } from '@xyo-network/diviner-jsonpath-model'
|
|
6
|
-
import { isTemporalIndexingDivinerResultIndex } from '@xyo-network/diviner-temporal-indexing-model'
|
|
7
|
-
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
8
|
-
import type { Payload } from '@xyo-network/payload-model'
|
|
9
|
-
import type { TimeStamp } from '@xyo-network/witness-timestamp'
|
|
10
|
-
import { TimestampSchema } from '@xyo-network/witness-timestamp'
|
|
11
|
-
import {
|
|
12
|
-
beforeAll,
|
|
13
|
-
describe, expect, it,
|
|
14
|
-
} from 'vitest'
|
|
15
|
-
|
|
16
|
-
import { TemporalIndexingDivinerIndexCandidateToIndexDiviner } from '../Diviner.ts'
|
|
17
|
-
|
|
18
|
-
type ImageThumbnail = Payload<{
|
|
19
|
-
http?: {
|
|
20
|
-
ipAddress?: string
|
|
21
|
-
status?: number
|
|
22
|
-
}
|
|
23
|
-
// schema: 'network.xyo.image.thumbnail'
|
|
24
|
-
sourceUrl: string
|
|
25
|
-
url?: string
|
|
26
|
-
}>
|
|
27
|
-
|
|
28
|
-
describe('TemporalIndexCandidateToImageThumbnailIndexDiviner', () => {
|
|
29
|
-
describe('divine', () => {
|
|
30
|
-
const timestampA = 1_234_567_890
|
|
31
|
-
const timestampPayloadA: TimeStamp = { schema: TimestampSchema, timestamp: timestampA }
|
|
32
|
-
const imageThumbnailPayloadA: ImageThumbnail = {
|
|
33
|
-
http: { status: 200 },
|
|
34
|
-
schema: 'network.xyo.image.thumbnail',
|
|
35
|
-
sourceUrl: 'https://xyo.network',
|
|
36
|
-
url: 'data',
|
|
37
|
-
}
|
|
38
|
-
const timestampB = 1_234_567_891
|
|
39
|
-
const timestampPayloadB: TimeStamp = { schema: TimestampSchema, timestamp: timestampB }
|
|
40
|
-
const imageThumbnailPayloadB: ImageThumbnail = {
|
|
41
|
-
http: { status: 500 },
|
|
42
|
-
schema: 'network.xyo.image.thumbnail',
|
|
43
|
-
sourceUrl: 'https://xyo.network',
|
|
44
|
-
}
|
|
45
|
-
const timestampC = 1_234_567_892
|
|
46
|
-
const timestampPayloadC: TimeStamp = { schema: TimestampSchema, timestamp: timestampC }
|
|
47
|
-
const imageThumbnailPayloadC: ImageThumbnail = {
|
|
48
|
-
|
|
49
|
-
http: { ipAddress: '192.169.1.1' },
|
|
50
|
-
schema: 'network.xyo.image.thumbnail',
|
|
51
|
-
sourceUrl: 'https://www.google.com',
|
|
52
|
-
}
|
|
53
|
-
describe('with single schema transform', () => {
|
|
54
|
-
const validateSingleResult = async (
|
|
55
|
-
input: [boundWitness: BoundWitness, timestamp: TimeStamp, thumbnail: ImageThumbnail],
|
|
56
|
-
result: Payload[],
|
|
57
|
-
) => {
|
|
58
|
-
const [boundWitness, timestamp, thumbnail] = input
|
|
59
|
-
const payloadDictionary = await PayloadBuilder.toHashMap([boundWitness, timestamp, thumbnail])
|
|
60
|
-
expect(result).toBeArrayOfSize(1)
|
|
61
|
-
expect(result.filter(isTemporalIndexingDivinerResultIndex)).toBeArrayOfSize(1)
|
|
62
|
-
const index = result.find(isTemporalIndexingDivinerResultIndex)
|
|
63
|
-
// eslint-disable-next-line sonarjs/no-alphabetical-sort
|
|
64
|
-
expect(index?.$sources.toSorted()).toEqual(Object.keys(payloadDictionary).toSorted())
|
|
65
|
-
expect(index?.timestamp).toBe(timestamp.timestamp)
|
|
66
|
-
expect((index as { url?: string })?.url).toBe(thumbnail.sourceUrl)
|
|
67
|
-
expect((index as { status?: number })?.status).toBe(thumbnail.http?.status)
|
|
68
|
-
}
|
|
69
|
-
beforeAll(async () => {
|
|
70
|
-
diviner = await TemporalIndexingDivinerIndexCandidateToIndexDiviner.create({
|
|
71
|
-
account: 'random',
|
|
72
|
-
config: {
|
|
73
|
-
schema: TemporalIndexingDivinerIndexCandidateToIndexDiviner.defaultConfigSchema,
|
|
74
|
-
schemaTransforms,
|
|
75
|
-
},
|
|
76
|
-
})
|
|
77
|
-
})
|
|
78
|
-
const schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary = {
|
|
79
|
-
'network.xyo.image.thumbnail': [
|
|
80
|
-
{ destinationField: 'url', sourcePathExpression: '$.sourceUrl' },
|
|
81
|
-
{ destinationField: 'status', sourcePathExpression: '$.http.status' },
|
|
82
|
-
],
|
|
83
|
-
'network.xyo.timestamp': [{ destinationField: 'timestamp', sourcePathExpression: '$.timestamp' }],
|
|
84
|
-
}
|
|
85
|
-
let diviner: TemporalIndexingDivinerIndexCandidateToIndexDiviner
|
|
86
|
-
|
|
87
|
-
const cases: [TimeStamp, ImageThumbnail][] = [
|
|
88
|
-
[timestampPayloadA, imageThumbnailPayloadA],
|
|
89
|
-
[timestampPayloadB, imageThumbnailPayloadB],
|
|
90
|
-
[timestampPayloadC, imageThumbnailPayloadC],
|
|
91
|
-
]
|
|
92
|
-
describe('with single result', () => {
|
|
93
|
-
it.each(cases)('transforms single result', async (timestamp, thumbnail) => {
|
|
94
|
-
const [boundWitness] = await new BoundWitnessBuilder().payloads([timestamp, thumbnail]).build()
|
|
95
|
-
const result = await diviner.divine([boundWitness, timestamp, thumbnail])
|
|
96
|
-
await validateSingleResult([boundWitness, timestamp, thumbnail], result)
|
|
97
|
-
})
|
|
98
|
-
it('transforms BW with multiple results inside', async () => {
|
|
99
|
-
const payloads = cases.flat()
|
|
100
|
-
const [boundWitness] = await new BoundWitnessBuilder().payloads(payloads).build()
|
|
101
|
-
const results = await diviner.divine([boundWitness, ...payloads])
|
|
102
|
-
expect(results).toBeArrayOfSize(Math.pow(cases.length, cases[0].length))
|
|
103
|
-
let resultIndex = 0
|
|
104
|
-
for (let i = 0; i < cases.length; i++) {
|
|
105
|
-
const thumbnail = cases[i][1]
|
|
106
|
-
// eslint-disable-next-line unicorn/no-for-loop
|
|
107
|
-
for (let j = 0; j < cases.length; j++) {
|
|
108
|
-
const timestamp = cases[j][0]
|
|
109
|
-
const result = results[resultIndex]
|
|
110
|
-
await validateSingleResult([boundWitness, timestamp, thumbnail], [result])
|
|
111
|
-
resultIndex++
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
})
|
|
115
|
-
it.each(cases)('handles sparse inputs', async (thumbnail, timestamp) => {
|
|
116
|
-
const [boundWitness] = await new BoundWitnessBuilder().payloads([timestamp, thumbnail]).build()
|
|
117
|
-
expect(await diviner.divine([thumbnail, timestamp])).toBeArrayOfSize(0)
|
|
118
|
-
expect(await diviner.divine([boundWitness, timestamp])).toBeArrayOfSize(0)
|
|
119
|
-
expect(await diviner.divine([boundWitness, thumbnail])).toBeArrayOfSize(0)
|
|
120
|
-
})
|
|
121
|
-
})
|
|
122
|
-
describe('with multiple results', () => {
|
|
123
|
-
it('transforms multiple results', async () => {
|
|
124
|
-
const data: [BoundWitness, TimeStamp, ImageThumbnail][] = await Promise.all(
|
|
125
|
-
cases.map(async (payloads) => {
|
|
126
|
-
const [bw] = await new BoundWitnessBuilder().payloads(payloads).build()
|
|
127
|
-
return [bw, ...payloads]
|
|
128
|
-
}),
|
|
129
|
-
)
|
|
130
|
-
const results = await diviner.divine(data.flat())
|
|
131
|
-
expect(results).toBeArrayOfSize(cases.length)
|
|
132
|
-
|
|
133
|
-
await Promise.all(
|
|
134
|
-
data.map(async (input, i) => {
|
|
135
|
-
const result = results[i]
|
|
136
|
-
await validateSingleResult(input, [result])
|
|
137
|
-
}),
|
|
138
|
-
)
|
|
139
|
-
})
|
|
140
|
-
it('handles sparse inputs', async () => {
|
|
141
|
-
const [bw] = await new BoundWitnessBuilder().payloads(cases[0]).build()
|
|
142
|
-
const results = await diviner.divine([bw, ...cases.flat()])
|
|
143
|
-
expect(results).toBeArrayOfSize(1)
|
|
144
|
-
await validateSingleResult([bw, ...cases[0]], results)
|
|
145
|
-
})
|
|
146
|
-
it('handles missing inputs', async () => {
|
|
147
|
-
const [bw] = await new BoundWitnessBuilder().payloads([...cases[0]]).build()
|
|
148
|
-
const results = await diviner.divine([bw, ...cases[0].slice(0, -1)])
|
|
149
|
-
expect(results).toBeArrayOfSize(0)
|
|
150
|
-
})
|
|
151
|
-
})
|
|
152
|
-
})
|
|
153
|
-
describe('with multiple schema transforms', () => {
|
|
154
|
-
const validateMultiResult = async (
|
|
155
|
-
input: [boundWitness: BoundWitness, timestamp: TimeStamp, thumbnail: ImageThumbnail, payload: Payload],
|
|
156
|
-
result: Payload[],
|
|
157
|
-
) => {
|
|
158
|
-
const [boundWitness, timestamp, thumbnail, payload] = input
|
|
159
|
-
const payloadDictionary = await PayloadBuilder.toHashMap([boundWitness, timestamp, thumbnail, payload])
|
|
160
|
-
expect(result).toBeArrayOfSize(1)
|
|
161
|
-
expect(result.filter(isTemporalIndexingDivinerResultIndex)).toBeArrayOfSize(1)
|
|
162
|
-
const index = result.find(isTemporalIndexingDivinerResultIndex)
|
|
163
|
-
// eslint-disable-next-line sonarjs/no-alphabetical-sort
|
|
164
|
-
expect(index?.$sources.toSorted()).toEqual(Object.keys(payloadDictionary).toSorted())
|
|
165
|
-
expect(index?.timestamp).toBe(timestamp.timestamp)
|
|
166
|
-
expect((index as { url?: string })?.url).toBe((payload as { sourceUrl?: string }).sourceUrl)
|
|
167
|
-
expect((index as { status?: number })?.status).toBe(thumbnail.http?.status)
|
|
168
|
-
}
|
|
169
|
-
beforeAll(async () => {
|
|
170
|
-
diviner = await TemporalIndexingDivinerIndexCandidateToIndexDiviner.create({
|
|
171
|
-
account: 'random',
|
|
172
|
-
config: {
|
|
173
|
-
schema: TemporalIndexingDivinerIndexCandidateToIndexDiviner.defaultConfigSchema,
|
|
174
|
-
schemaTransforms,
|
|
175
|
-
},
|
|
176
|
-
})
|
|
177
|
-
})
|
|
178
|
-
const schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary = {
|
|
179
|
-
'network.xyo.image.thumbnail': [{ destinationField: 'status', sourcePathExpression: '$.http.status' }],
|
|
180
|
-
'network.xyo.image.thumbnail.other': [{ destinationField: 'url', sourcePathExpression: '$.sourceUrl' }],
|
|
181
|
-
'network.xyo.timestamp': [{ destinationField: 'timestamp', sourcePathExpression: '$.timestamp' }],
|
|
182
|
-
}
|
|
183
|
-
let diviner: TemporalIndexingDivinerIndexCandidateToIndexDiviner
|
|
184
|
-
|
|
185
|
-
const cases: [TimeStamp, ImageThumbnail, Payload<{ sourceUrl: string }>][] = [
|
|
186
|
-
[
|
|
187
|
-
timestampPayloadA,
|
|
188
|
-
{ ...imageThumbnailPayloadA, sourceUrl: '' },
|
|
189
|
-
{ schema: 'network.xyo.image.thumbnail.other', sourceUrl: imageThumbnailPayloadA.sourceUrl },
|
|
190
|
-
],
|
|
191
|
-
[
|
|
192
|
-
timestampPayloadB,
|
|
193
|
-
{ ...imageThumbnailPayloadB, sourceUrl: '' },
|
|
194
|
-
{ schema: 'network.xyo.image.thumbnail.other', sourceUrl: imageThumbnailPayloadB.sourceUrl },
|
|
195
|
-
],
|
|
196
|
-
[
|
|
197
|
-
timestampPayloadC,
|
|
198
|
-
{ ...imageThumbnailPayloadC, sourceUrl: '' },
|
|
199
|
-
{ schema: 'network.xyo.image.thumbnail.other', sourceUrl: imageThumbnailPayloadC.sourceUrl },
|
|
200
|
-
],
|
|
201
|
-
]
|
|
202
|
-
describe('with single result', () => {
|
|
203
|
-
it.each(cases)('transforms single result', async (timestamp, thumbnail, payload) => {
|
|
204
|
-
const [boundWitness] = await new BoundWitnessBuilder().payloads([timestamp, thumbnail, payload]).build()
|
|
205
|
-
const result = await diviner.divine([boundWitness, timestamp, thumbnail, payload])
|
|
206
|
-
await validateMultiResult([boundWitness, timestamp, thumbnail, payload], result)
|
|
207
|
-
})
|
|
208
|
-
it.each(cases)('handles sparse inputs', async (thumbnail, timestamp, payload) => {
|
|
209
|
-
const [boundWitness] = await new BoundWitnessBuilder().payloads([timestamp, thumbnail, payload]).build()
|
|
210
|
-
expect(await diviner.divine([thumbnail, timestamp])).toBeArrayOfSize(0)
|
|
211
|
-
expect(await diviner.divine([boundWitness, timestamp])).toBeArrayOfSize(0)
|
|
212
|
-
expect(await diviner.divine([boundWitness, thumbnail])).toBeArrayOfSize(0)
|
|
213
|
-
})
|
|
214
|
-
})
|
|
215
|
-
describe('with multiple results', () => {
|
|
216
|
-
it('transforms multiple results', async () => {
|
|
217
|
-
const data: [BoundWitness, TimeStamp, ImageThumbnail, Payload][] = await Promise.all(
|
|
218
|
-
cases.map(async (payloads) => {
|
|
219
|
-
const [bw] = await new BoundWitnessBuilder().payloads(payloads).build()
|
|
220
|
-
return [bw, ...payloads]
|
|
221
|
-
}),
|
|
222
|
-
)
|
|
223
|
-
const results = await diviner.divine(data.flat())
|
|
224
|
-
expect(results).toBeArrayOfSize(cases.length)
|
|
225
|
-
|
|
226
|
-
await Promise.all(
|
|
227
|
-
data.map(async (input, i) => {
|
|
228
|
-
const result = results[i]
|
|
229
|
-
await validateMultiResult(input, [result])
|
|
230
|
-
}),
|
|
231
|
-
)
|
|
232
|
-
})
|
|
233
|
-
it('handles sparse inputs', async () => {
|
|
234
|
-
const [bw] = await new BoundWitnessBuilder().payloads(cases[0]).build()
|
|
235
|
-
const results = await diviner.divine([bw, ...cases.flat()])
|
|
236
|
-
expect(results).toBeArrayOfSize(1)
|
|
237
|
-
await validateMultiResult([bw, ...cases[0]], results)
|
|
238
|
-
})
|
|
239
|
-
it('handles missing inputs', async () => {
|
|
240
|
-
const [bw] = await new BoundWitnessBuilder().payloads([...cases[0]]).build()
|
|
241
|
-
const results = await diviner.divine([bw, ...cases[0].slice(0, -1)])
|
|
242
|
-
expect(results).toBeArrayOfSize(0)
|
|
243
|
-
})
|
|
244
|
-
})
|
|
245
|
-
})
|
|
246
|
-
})
|
|
247
|
-
})
|