@xyo-network/diviner-jsonpath-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 +15 -12
- package/dist/neutral/jsonpath/spec/isScalarJsonPathExpression.spec.d.ts +0 -2
- package/dist/neutral/jsonpath/spec/isScalarJsonPathExpression.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/src/jsonpath/spec/isScalarJsonPathExpression.spec.ts +0 -22
- package/src/spec/Diviner.spec.ts +0 -139
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/diviner-jsonpath-memory",
|
|
3
|
-
"version": "5.1.
|
|
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,26 +30,29 @@
|
|
|
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.
|
|
37
|
-
"@xyo-network/diviner-abstract": "~5.1.
|
|
38
|
-
"@xyo-network/diviner-jsonpath-model": "~5.1.
|
|
39
|
-
"@xyo-network/diviner-model": "~5.1.
|
|
40
|
-
"@xyo-network/payload-builder": "~5.1.
|
|
41
|
-
"@xyo-network/payload-model": "~5.1.
|
|
39
|
+
"@xylabs/assert": "~5.0.33",
|
|
40
|
+
"@xyo-network/diviner-abstract": "~5.1.23",
|
|
41
|
+
"@xyo-network/diviner-jsonpath-model": "~5.1.23",
|
|
42
|
+
"@xyo-network/diviner-model": "~5.1.23",
|
|
43
|
+
"@xyo-network/payload-builder": "~5.1.23",
|
|
44
|
+
"@xyo-network/payload-model": "~5.1.23",
|
|
42
45
|
"jsonpath": "~1.1.1"
|
|
43
46
|
},
|
|
44
47
|
"devDependencies": {
|
|
45
48
|
"@types/jsonpath": "~0.2.4",
|
|
46
49
|
"@xylabs/ts-scripts-yarn3": "~7.2.8",
|
|
47
50
|
"@xylabs/tsconfig": "~7.2.8",
|
|
48
|
-
"@xylabs/vitest-extended": "~5.0.
|
|
49
|
-
"@xyo-network/wallet": "~5.1.
|
|
50
|
-
"@xyo-network/wallet-model": "~5.1.
|
|
51
|
+
"@xylabs/vitest-extended": "~5.0.33",
|
|
52
|
+
"@xyo-network/wallet": "~5.1.23",
|
|
53
|
+
"@xyo-network/wallet-model": "~5.1.23",
|
|
51
54
|
"typescript": "~5.9.3",
|
|
52
|
-
"vitest": "~4.0.
|
|
55
|
+
"vitest": "~4.0.9"
|
|
53
56
|
},
|
|
54
57
|
"publishConfig": {
|
|
55
58
|
"access": "public"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isScalarJsonPathExpression.spec.d.ts","sourceRoot":"","sources":["../../../../src/jsonpath/spec/isScalarJsonPathExpression.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,22 +0,0 @@
|
|
|
1
|
-
import '@xylabs/vitest-extended'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
describe, expect, it,
|
|
5
|
-
} from 'vitest'
|
|
6
|
-
|
|
7
|
-
import { isScalarJsonPathExpression } from '../isScalarJsonPathExpression.ts'
|
|
8
|
-
|
|
9
|
-
describe('isScalarJsonPathExpression', () => {
|
|
10
|
-
describe('should return true for scalar values', () => {
|
|
11
|
-
const values = ['$.store', '$.store.book[0]', '$.store.book.title']
|
|
12
|
-
it.each(values)('%s', (value) => {
|
|
13
|
-
expect(isScalarJsonPathExpression(value)).toBeTruthy()
|
|
14
|
-
})
|
|
15
|
-
})
|
|
16
|
-
describe('should return false for array values', () => {
|
|
17
|
-
const values = ['$.store.book[*]', '$.store..price', '$.store.book[0,1]', '$.store.book[0:2]']
|
|
18
|
-
it.each(values)('%s', (value) => {
|
|
19
|
-
expect(isScalarJsonPathExpression(value)).toBeFalsy()
|
|
20
|
-
})
|
|
21
|
-
})
|
|
22
|
-
})
|
package/src/spec/Diviner.spec.ts
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import '@xylabs/vitest-extended'
|
|
2
|
-
|
|
3
|
-
import type { JsonPathTransformExpression } from '@xyo-network/diviner-jsonpath-model'
|
|
4
|
-
import { JsonPathDivinerConfigSchema } from '@xyo-network/diviner-jsonpath-model'
|
|
5
|
-
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
6
|
-
import type { AnyPayload } from '@xyo-network/payload-model'
|
|
7
|
-
import { HDWallet } from '@xyo-network/wallet'
|
|
8
|
-
import type { WalletInstance } from '@xyo-network/wallet-model'
|
|
9
|
-
import {
|
|
10
|
-
beforeAll,
|
|
11
|
-
describe, expect, it,
|
|
12
|
-
} from 'vitest'
|
|
13
|
-
|
|
14
|
-
import { JsonPathDiviner } from '../Diviner.ts'
|
|
15
|
-
describe('JsonPathDiviner', () => {
|
|
16
|
-
type TestData = [description: string, input: AnyPayload[], transformers: JsonPathTransformExpression[], expected: AnyPayload[]]
|
|
17
|
-
const cases: TestData[] = [
|
|
18
|
-
[
|
|
19
|
-
'transforms single payload',
|
|
20
|
-
[{ a: 0, schema: 'network.xyo.test.source.a' }],
|
|
21
|
-
[{ destinationField: 'c', sourcePathExpression: '$.a' }],
|
|
22
|
-
[{ c: 0, schema: 'network.xyo.test.destination' }],
|
|
23
|
-
],
|
|
24
|
-
[
|
|
25
|
-
'transforms multiple payloads',
|
|
26
|
-
[
|
|
27
|
-
{ a: 0, schema: 'network.xyo.test.source.a' },
|
|
28
|
-
{ b: 1, schema: 'network.xyo.test.source.b' },
|
|
29
|
-
],
|
|
30
|
-
[
|
|
31
|
-
{ destinationField: 'c', sourcePathExpression: '$.a' },
|
|
32
|
-
{ destinationField: 'd', sourcePathExpression: '$.b' },
|
|
33
|
-
],
|
|
34
|
-
[
|
|
35
|
-
{ c: 0, schema: 'network.xyo.test.destination' },
|
|
36
|
-
{ d: 1, schema: 'network.xyo.test.destination' },
|
|
37
|
-
],
|
|
38
|
-
],
|
|
39
|
-
[
|
|
40
|
-
'transforms with default value if source property is missing',
|
|
41
|
-
[{ schema: 'network.xyo.test.source.a' }],
|
|
42
|
-
[{
|
|
43
|
-
defaultValue: 0, destinationField: 'c', sourcePathExpression: '$.a',
|
|
44
|
-
}],
|
|
45
|
-
[{ c: 0, schema: 'network.xyo.test.destination' }],
|
|
46
|
-
],
|
|
47
|
-
[
|
|
48
|
-
'transforms with default value if source property is undefined',
|
|
49
|
-
[{ schema: 'network.xyo.test.source.a' }],
|
|
50
|
-
[{
|
|
51
|
-
defaultValue: 0, destinationField: 'c', sourcePathExpression: '$.a',
|
|
52
|
-
}],
|
|
53
|
-
[{ c: 0, schema: 'network.xyo.test.destination' }],
|
|
54
|
-
],
|
|
55
|
-
// TODO: Since this returns an array, it will not work with the current
|
|
56
|
-
// implementation. Uncomment when arrayed transformer values are supported.
|
|
57
|
-
// [
|
|
58
|
-
// 'transforms array with * (all elements)',
|
|
59
|
-
// [{ a: [0, 1, 2], schema: 'network.xyo.test.source.a' }],
|
|
60
|
-
// [{ destinationField: 'c', sourcePathExpression: '$.a[*]' }],
|
|
61
|
-
// [{ c: 0, schema: 'network.xyo.test.destination' }],
|
|
62
|
-
// ],
|
|
63
|
-
[
|
|
64
|
-
'transforms array (first position)',
|
|
65
|
-
[{ a: [0, 1, 2], schema: 'network.xyo.test.source.a' }],
|
|
66
|
-
[{ destinationField: 'c', sourcePathExpression: '$.a[0]' }],
|
|
67
|
-
[{ c: 0, schema: 'network.xyo.test.destination' }],
|
|
68
|
-
],
|
|
69
|
-
[
|
|
70
|
-
'transforms array (Nth position)',
|
|
71
|
-
[{ a: [0, 1, 2], schema: 'network.xyo.test.source.a' }],
|
|
72
|
-
[{ destinationField: 'c', sourcePathExpression: '$.a[1]' }],
|
|
73
|
-
[{ c: 1, schema: 'network.xyo.test.destination' }],
|
|
74
|
-
],
|
|
75
|
-
[
|
|
76
|
-
'transforms array (last position via subscript)',
|
|
77
|
-
[{ a: [0, 1, 2], schema: 'network.xyo.test.source.a' }],
|
|
78
|
-
[{ destinationField: 'c', sourcePathExpression: '$.a[(@.length-1)]' }],
|
|
79
|
-
[{ c: 2, schema: 'network.xyo.test.destination' }],
|
|
80
|
-
],
|
|
81
|
-
// NOTE: Since this can return an array, it should stop passing when
|
|
82
|
-
// the arrayed transformer values are supported.
|
|
83
|
-
[
|
|
84
|
-
'transforms array (last position via slice)',
|
|
85
|
-
[{ a: [0, 1, 2], schema: 'network.xyo.test.source.a' }],
|
|
86
|
-
[{ destinationField: 'c', sourcePathExpression: '$.a[-1:]' }],
|
|
87
|
-
[{ c: 2, schema: 'network.xyo.test.destination' }],
|
|
88
|
-
],
|
|
89
|
-
[
|
|
90
|
-
'does not transform with default value if source property is null',
|
|
91
|
-
[{ a: null, schema: 'network.xyo.test.source.a' }],
|
|
92
|
-
[{
|
|
93
|
-
defaultValue: 0, destinationField: 'c', sourcePathExpression: '$.a',
|
|
94
|
-
}],
|
|
95
|
-
[{ c: null, schema: 'network.xyo.test.destination' }],
|
|
96
|
-
],
|
|
97
|
-
[
|
|
98
|
-
'does not transform with default value if source property is false',
|
|
99
|
-
[{ a: false, schema: 'network.xyo.test.source.a' }],
|
|
100
|
-
[{
|
|
101
|
-
defaultValue: 0, destinationField: 'c', sourcePathExpression: '$.a',
|
|
102
|
-
}],
|
|
103
|
-
[{ c: false, schema: 'network.xyo.test.destination' }],
|
|
104
|
-
],
|
|
105
|
-
[
|
|
106
|
-
'does not transform with default value if source property is falsy',
|
|
107
|
-
[{ a: 0, schema: 'network.xyo.test.source.a' }],
|
|
108
|
-
[{
|
|
109
|
-
defaultValue: 1, destinationField: 'c', sourcePathExpression: '$.a',
|
|
110
|
-
}],
|
|
111
|
-
[{ c: 0, schema: 'network.xyo.test.destination' }],
|
|
112
|
-
],
|
|
113
|
-
]
|
|
114
|
-
let wallet: WalletInstance
|
|
115
|
-
beforeAll(async () => {
|
|
116
|
-
wallet = await HDWallet.random()
|
|
117
|
-
})
|
|
118
|
-
it.each(cases)('%s', async (_title, inputs, transforms, outputs) => {
|
|
119
|
-
const destinationSchema = outputs?.[0]?.schema
|
|
120
|
-
const config = {
|
|
121
|
-
destinationSchema,
|
|
122
|
-
schema: JsonPathDivinerConfigSchema,
|
|
123
|
-
transforms,
|
|
124
|
-
}
|
|
125
|
-
const sut = await JsonPathDiviner.create({ account: wallet, config })
|
|
126
|
-
// Arrange
|
|
127
|
-
const expected = await Promise.all(
|
|
128
|
-
outputs.map(async (output, index) => {
|
|
129
|
-
return { sources: [(await PayloadBuilder.dataHash(inputs[index]))], ...output }
|
|
130
|
-
}),
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
// Act
|
|
134
|
-
const actual = await sut.divine(inputs)
|
|
135
|
-
|
|
136
|
-
// Assert
|
|
137
|
-
expect(actual.map(i => PayloadBuilder.omitMeta(i))).toEqual(expected.map(i => PayloadBuilder.omitMeta(i)))
|
|
138
|
-
})
|
|
139
|
-
})
|