@xyo-network/diviner-jsonpath-aggregate-memory 5.1.21 → 5.1.23

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/diviner-jsonpath-aggregate-memory",
3
- "version": "5.1.21",
3
+ "version": "5.1.23",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -30,30 +30,33 @@
30
30
  "types": "dist/neutral/index.d.ts",
31
31
  "files": [
32
32
  "dist",
33
- "src"
33
+ "src",
34
+ "!**/*.bench.*",
35
+ "!**/*.spec.*",
36
+ "!**/*.test.*"
34
37
  ],
35
38
  "dependencies": {
36
- "@xylabs/assert": "~5.0.24",
37
- "@xylabs/exists": "~5.0.24",
38
- "@xyo-network/boundwitness-model": "~5.1.21",
39
- "@xyo-network/diviner-abstract": "~5.1.21",
40
- "@xyo-network/diviner-jsonpath-aggregate-model": "~5.1.21",
41
- "@xyo-network/diviner-jsonpath-memory": "~5.1.21",
42
- "@xyo-network/diviner-model": "~5.1.21",
43
- "@xyo-network/payload-builder": "~5.1.21",
44
- "@xyo-network/payload-model": "~5.1.21",
45
- "@xyo-network/payload-utils": "~5.1.21"
39
+ "@xylabs/assert": "~5.0.33",
40
+ "@xylabs/exists": "~5.0.33",
41
+ "@xyo-network/boundwitness-model": "~5.1.23",
42
+ "@xyo-network/diviner-abstract": "~5.1.23",
43
+ "@xyo-network/diviner-jsonpath-aggregate-model": "~5.1.23",
44
+ "@xyo-network/diviner-jsonpath-memory": "~5.1.23",
45
+ "@xyo-network/diviner-model": "~5.1.23",
46
+ "@xyo-network/payload-builder": "~5.1.23",
47
+ "@xyo-network/payload-model": "~5.1.23",
48
+ "@xyo-network/payload-utils": "~5.1.23"
46
49
  },
47
50
  "devDependencies": {
48
51
  "@xylabs/ts-scripts-yarn3": "~7.2.8",
49
52
  "@xylabs/tsconfig": "~7.2.8",
50
- "@xylabs/vitest-extended": "~5.0.24",
51
- "@xyo-network/account": "~5.1.21",
52
- "@xyo-network/account-model": "~5.1.21",
53
- "@xyo-network/boundwitness-builder": "~5.1.21",
54
- "@xyo-network/diviner-jsonpath-model": "~5.1.21",
53
+ "@xylabs/vitest-extended": "~5.0.33",
54
+ "@xyo-network/account": "~5.1.23",
55
+ "@xyo-network/account-model": "~5.1.23",
56
+ "@xyo-network/boundwitness-builder": "~5.1.23",
57
+ "@xyo-network/diviner-jsonpath-model": "~5.1.23",
55
58
  "typescript": "~5.9.3",
56
- "vitest": "~4.0.8"
59
+ "vitest": "~4.0.9"
57
60
  },
58
61
  "publishConfig": {
59
62
  "access": "public"
@@ -1,2 +0,0 @@
1
- import '@xylabs/vitest-extended';
2
- //# sourceMappingURL=reducePayloads.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"reducePayloads.spec.d.ts","sourceRoot":"","sources":["../../../../src/jsonpath/spec/reducePayloads.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
@@ -1,2 +0,0 @@
1
- import '@xylabs/vitest-extended';
2
- //# sourceMappingURL=Diviner.spec.d.ts.map
@@ -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,93 +0,0 @@
1
- import '@xylabs/vitest-extended'
2
-
3
- import type { SchemaToJsonPathTransformExpressionsDictionary } from '@xyo-network/diviner-jsonpath-model'
4
- import { PayloadBuilder } from '@xyo-network/payload-builder'
5
- import type { AnyPayload } from '@xyo-network/payload-model'
6
- import {
7
- describe, expect, it,
8
- } from 'vitest'
9
-
10
- import { jsonPathToTransformersDictionary } from '../jsonPathToTransformersDictionary.ts'
11
- import { reducePayloads } from '../reducePayloads.ts'
12
-
13
- describe('transformPayloads', () => {
14
- type TestData = [
15
- description: string,
16
- payloads: AnyPayload[],
17
- payloadTransformers: SchemaToJsonPathTransformExpressionsDictionary,
18
- output: AnyPayload,
19
- ]
20
- const cases: TestData[] = [
21
- [
22
- 'transforms single payload',
23
- [{ a: 0, schema: 'network.xyo.test.source.a' }],
24
- { 'network.xyo.test.source.a': [{ destinationField: 'c', sourcePathExpression: '$.a' }] },
25
- { c: 0, schema: 'network.xyo.test.destination' },
26
- ],
27
- [
28
- 'transforms multiple payloads',
29
- [
30
- { a: 0, schema: 'network.xyo.test.source.a' },
31
- { b: 1, schema: 'network.xyo.test.source.b' },
32
- ],
33
- {
34
- 'network.xyo.test.source.a': [{ destinationField: 'c', sourcePathExpression: '$.a' }],
35
- 'network.xyo.test.source.b': [{ destinationField: 'd', sourcePathExpression: '$.b' }],
36
- },
37
- {
38
- c: 0, d: 1, schema: 'network.xyo.test.destination',
39
- },
40
- ],
41
- [
42
- 'transforms with default value if source property is missing',
43
- [{ schema: 'network.xyo.test.source.a' }],
44
- {
45
- 'network.xyo.test.source.a': [{
46
- defaultValue: 0, destinationField: 'c', sourcePathExpression: '$.a',
47
- }],
48
- },
49
- { c: 0, schema: 'network.xyo.test.destination' },
50
- ],
51
- [
52
- 'does not transform with default value if source property is null',
53
- [{ a: null, schema: 'network.xyo.test.source.a' }],
54
- {
55
- 'network.xyo.test.source.a': [{
56
- defaultValue: 0, destinationField: 'c', sourcePathExpression: '$.a',
57
- }],
58
- },
59
- { c: null, schema: 'network.xyo.test.destination' },
60
- ],
61
- [
62
- 'does not transform with default value if source property is false',
63
- [{ a: false, schema: 'network.xyo.test.source.a' }],
64
- {
65
- 'network.xyo.test.source.a': [{
66
- defaultValue: 0, destinationField: 'c', sourcePathExpression: '$.a',
67
- }],
68
- },
69
- { c: false, schema: 'network.xyo.test.destination' },
70
- ],
71
- [
72
- 'does not transform with default value if source property is falsy',
73
- [{ a: 0, schema: 'network.xyo.test.source.a' }],
74
- {
75
- 'network.xyo.test.source.a': [{
76
- defaultValue: 1, destinationField: 'c', sourcePathExpression: '$.a',
77
- }],
78
- },
79
- { c: 0, schema: 'network.xyo.test.destination' },
80
- ],
81
- ]
82
- it.each(cases)('%s', async (_title, inputs, schemaTransforms, output) => {
83
- const transforms = jsonPathToTransformersDictionary(schemaTransforms)
84
- const destinationSchema = output.schema
85
- const sources = await PayloadBuilder.dataHashes(inputs)
86
- const withSources = await reducePayloads(inputs, transforms, destinationSchema, false)
87
- const withoutSources = await reducePayloads(inputs, transforms, destinationSchema, true)
88
- // With sources
89
- expect(withSources).toEqual({ sources, ...output })
90
- // Without sources
91
- expect(withoutSources).toEqual({ ...output })
92
- })
93
- })
@@ -1,218 +0,0 @@
1
- import '@xylabs/vitest-extended'
2
-
3
- import { Account } from '@xyo-network/account'
4
- import type { AccountInstance } from '@xyo-network/account-model'
5
- import { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'
6
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
7
- import type { SchemaToJsonPathTransformExpressionsDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'
8
- import { PayloadBuilder } from '@xyo-network/payload-builder'
9
- import type { Payload } from '@xyo-network/payload-model'
10
- import { isPayloadOfSchemaType } from '@xyo-network/payload-model'
11
- import {
12
- beforeAll,
13
- describe, expect, it,
14
- } from 'vitest'
15
-
16
- import { JsonPathAggregateDiviner } from '../Diviner.ts'
17
-
18
- function countCombinations<T>(jaggedArray: T[][]): number {
19
- return jaggedArray.reduce((total, currentArray) => total * currentArray.length, 1)
20
- }
21
-
22
- type ImageThumbnail = Payload<{
23
- http?: {
24
- ipAddress?: string
25
- status?: number
26
- }
27
- // schema: 'network.xyo.image.thumbnail'
28
- sourceUrl: string
29
- url?: string
30
- }>
31
- type TimeStamp = Payload<{ timestamp: number }>
32
- type ResultType = Payload<{ sources: string[]; status?: number; timestamp: number; url?: string }>
33
-
34
- describe('JsonPathAggregateDiviner', () => {
35
- describe('divine', () => {
36
- const destinationSchema = 'network.xyo.test'
37
- const timestampA = 1_234_567_890
38
- const timestampPayloadA = { schema: 'network.xyo.timestamp', timestamp: timestampA }
39
- const imageThumbnailPayloadA: ImageThumbnail = {
40
- http: { status: 200 },
41
- schema: 'network.xyo.image.thumbnail',
42
- sourceUrl: 'https://node.xyo.network',
43
- url: 'data',
44
- }
45
- const timestampB = 1_234_567_891
46
- const timestampPayloadB = { schema: 'network.xyo.timestamp', timestamp: timestampB }
47
- const imageThumbnailPayloadB: ImageThumbnail = {
48
- http: { status: 500 },
49
- schema: 'network.xyo.image.thumbnail',
50
- sourceUrl: 'https://www.google.com',
51
- }
52
- const timestampC = 1_234_567_892
53
- const timestampPayloadC = { schema: 'network.xyo.timestamp', timestamp: timestampC }
54
- const imageThumbnailPayloadC: ImageThumbnail = {
55
-
56
- http: { ipAddress: '192.169.1.1' },
57
- schema: 'network.xyo.image.thumbnail',
58
- sourceUrl: 'https://explore.xyo.network',
59
- }
60
- let account: AccountInstance
61
- beforeAll(async () => {
62
- account = await Account.random()
63
- })
64
- describe('with only payload schema transforms', () => {
65
- const validatePayloadResult = async (input: [timestamp: TimeStamp, thumbnail: ImageThumbnail, payload: Payload], result: Payload[]) => {
66
- const [timestamp, thumbnail, payload] = input
67
- const payloadDictionary = await PayloadBuilder.toDataHashMap([timestamp, thumbnail, payload])
68
- expect(result).toBeArrayOfSize(1)
69
- expect(result.filter(isPayloadOfSchemaType<Payload>(destinationSchema))).toBeArrayOfSize(1)
70
- const index = result.find(isPayloadOfSchemaType<ResultType>(destinationSchema))
71
- // eslint-disable-next-line sonarjs/no-alphabetical-sort
72
- expect(index?.sources.toSorted()).toEqual(Object.keys(payloadDictionary).toSorted())
73
- expect(index?.timestamp).toBe(timestamp.timestamp)
74
- expect(index?.url).toBe((payload as { sourceUrl?: string }).sourceUrl)
75
- expect(index?.status).toBe(thumbnail.http?.status)
76
- }
77
- beforeAll(async () => {
78
- const config = {
79
- destinationSchema, schema: JsonPathAggregateDiviner.defaultConfigSchema, schemaTransforms,
80
- }
81
- diviner = await JsonPathAggregateDiviner.create({ account, config })
82
- })
83
- const schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary = {
84
- 'network.xyo.image.thumbnail': [{ destinationField: 'status', sourcePathExpression: '$.http.status' }],
85
- 'network.xyo.image.thumbnail.other': [{ destinationField: 'url', sourcePathExpression: '$.sourceUrl' }],
86
- 'network.xyo.timestamp': [{ destinationField: 'timestamp', sourcePathExpression: '$.timestamp' }],
87
- }
88
- let diviner: JsonPathAggregateDiviner
89
-
90
- const cases: [TimeStamp, ImageThumbnail, Payload<{ sourceUrl: string }>][] = [
91
- [
92
- timestampPayloadA,
93
- { ...imageThumbnailPayloadA, sourceUrl: '' },
94
- { schema: 'network.xyo.image.thumbnail.other', sourceUrl: imageThumbnailPayloadA.sourceUrl },
95
- ],
96
- [
97
- timestampPayloadB,
98
- { ...imageThumbnailPayloadB, sourceUrl: '' },
99
- { schema: 'network.xyo.image.thumbnail.other', sourceUrl: imageThumbnailPayloadB.sourceUrl },
100
- ],
101
- [
102
- timestampPayloadC,
103
- { ...imageThumbnailPayloadC, sourceUrl: '' },
104
- { schema: 'network.xyo.image.thumbnail.other', sourceUrl: imageThumbnailPayloadC.sourceUrl },
105
- ],
106
- ]
107
- describe('with single input', () => {
108
- it.each(cases)('transforms single input', async (timestamp, thumbnail, payload) => {
109
- const result = await diviner.divine([timestamp, thumbnail, payload])
110
- await validatePayloadResult([timestamp, thumbnail, payload], result)
111
- })
112
- })
113
- describe('with multiple inputs', () => {
114
- it('transforms to multiple outputs', async () => {
115
- const results = await diviner.divine(cases.flat())
116
- expect(results).toBeArrayOfSize(countCombinations(cases))
117
- let resultIndex = 0
118
- for (let i = 0; i < cases.length; i++) {
119
- const thumbnail = cases[i][1]
120
- for (let j = 0; j < cases.length; j++) {
121
- const payload = cases[j][2]
122
- // eslint-disable-next-line unicorn/no-for-loop
123
- for (let k = 0; k < cases.length; k++) {
124
- const timestamp = cases[k][0]
125
- const result = results[resultIndex]
126
- await validatePayloadResult([timestamp, thumbnail, payload], [result])
127
- resultIndex++
128
- }
129
- }
130
- }
131
- })
132
- })
133
- describe('with sparse input', () => {
134
- it.each(cases)('returns empty array', async (thumbnail, timestamp, payload) => {
135
- const [boundWitness] = await new BoundWitnessBuilder().payloads([timestamp, thumbnail, payload]).build()
136
- expect(await diviner.divine([thumbnail, timestamp])).toBeArrayOfSize(0)
137
- expect(await diviner.divine([boundWitness, timestamp])).toBeArrayOfSize(0)
138
- expect(await diviner.divine([boundWitness, thumbnail])).toBeArrayOfSize(0)
139
- })
140
- })
141
- })
142
- describe('with multiple schema transforms', () => {
143
- const validateMultiResult = async (
144
- input: [boundWitness: BoundWitness, timestamp: TimeStamp, thumbnail: ImageThumbnail, payload: Payload],
145
- result: Payload[],
146
- ) => {
147
- const [boundWitness, timestamp, thumbnail, payload] = input
148
- const payloadDictionary = await PayloadBuilder.toDataHashMap([boundWitness, timestamp, thumbnail, payload])
149
- expect(result).toBeArrayOfSize(1)
150
- expect(result.filter(isPayloadOfSchemaType<Payload>(destinationSchema))).toBeArrayOfSize(1)
151
- const index = result.find(isPayloadOfSchemaType<ResultType>(destinationSchema))
152
- // eslint-disable-next-line sonarjs/no-alphabetical-sort
153
- expect(index?.sources.toSorted()).toEqual(Object.keys(payloadDictionary).toSorted())
154
- expect(index?.timestamp).toBe(timestamp.timestamp)
155
- expect(index?.url).toBe((payload as { sourceUrl?: string }).sourceUrl)
156
- expect(index?.status).toBe(thumbnail.http?.status)
157
- }
158
- beforeAll(async () => {
159
- const config = {
160
- destinationSchema, schema: JsonPathAggregateDiviner.defaultConfigSchema, schemaTransforms,
161
- }
162
- diviner = await JsonPathAggregateDiviner.create({ account, config })
163
- })
164
- const schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary = {
165
- 'network.xyo.boundwitness': [],
166
- 'network.xyo.image.thumbnail': [{ destinationField: 'status', sourcePathExpression: '$.http.status' }],
167
- 'network.xyo.image.thumbnail.other': [{ destinationField: 'url', sourcePathExpression: '$.sourceUrl' }],
168
- 'network.xyo.timestamp': [{ destinationField: 'timestamp', sourcePathExpression: '$.timestamp' }],
169
- }
170
- let diviner: JsonPathAggregateDiviner
171
-
172
- const cases: [TimeStamp, ImageThumbnail, Payload<{ sourceUrl: string }>][] = [
173
- [
174
- timestampPayloadA,
175
- { ...imageThumbnailPayloadA, sourceUrl: '' },
176
- { schema: 'network.xyo.image.thumbnail.other', sourceUrl: imageThumbnailPayloadA.sourceUrl },
177
- ],
178
- [
179
- timestampPayloadB,
180
- { ...imageThumbnailPayloadB, sourceUrl: '' },
181
- { schema: 'network.xyo.image.thumbnail.other', sourceUrl: imageThumbnailPayloadB.sourceUrl },
182
- ],
183
- [
184
- timestampPayloadC,
185
- { ...imageThumbnailPayloadC, sourceUrl: '' },
186
- { schema: 'network.xyo.image.thumbnail.other', sourceUrl: imageThumbnailPayloadC.sourceUrl },
187
- ],
188
- ]
189
- describe('with single input', () => {
190
- it.each(cases)('transforms single input', async (timestamp, thumbnail, payload) => {
191
- const [boundWitness] = await new BoundWitnessBuilder().payloads([timestamp, thumbnail, payload]).build()
192
- const result = await diviner.divine([boundWitness, timestamp, thumbnail, payload])
193
- await validateMultiResult([boundWitness, timestamp, thumbnail, payload], result)
194
- })
195
- })
196
- describe('with multiple inputs', () => {
197
- it('transforms to multiple outputs', async () => {
198
- const bws = await Promise.all(cases.map(async c => await new BoundWitnessBuilder().payloads(c).build()))
199
- const allCases = bws.map((bw, i) => [bw[0], ...cases[i]] as [BoundWitness, TimeStamp, ImageThumbnail, Payload])
200
- const results = await diviner.divine(allCases.flat())
201
- expect(results).toBeArrayOfSize(cases.length)
202
- for (const [i, c] of allCases.entries()) {
203
- const [boundWitness, timestamp, thumbnail, payload] = c
204
- await validateMultiResult([boundWitness, timestamp, thumbnail, payload], [results[i]])
205
- }
206
- })
207
- })
208
- describe('with sparse input', () => {
209
- it.each(cases)('returns empty array', async (thumbnail, timestamp, payload) => {
210
- const [boundWitness] = await new BoundWitnessBuilder().payloads([timestamp, thumbnail, payload]).build()
211
- expect(await diviner.divine([thumbnail, timestamp])).toBeArrayOfSize(0)
212
- expect(await diviner.divine([boundWitness, timestamp])).toBeArrayOfSize(0)
213
- expect(await diviner.divine([boundWitness, thumbnail])).toBeArrayOfSize(0)
214
- })
215
- })
216
- })
217
- })
218
- })