Skip to content

Commit 76b9c5a

Browse files
committed
Add some proposals and update bench suite for me
1 parent c4f4584 commit 76b9c5a

File tree

5 files changed

+164
-35
lines changed

5 files changed

+164
-35
lines changed

bench/package-lock.json

+61-27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bench/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"dependencies": {
1212
"@bestow/jsonlogic-rs": "^0.4.0",
1313
"json-logic-js": "^2.0.1",
14-
"json-rules-engine": "^6.0.1"
14+
"json-rules-engine": "^7.2.1"
1515
},
1616
"type": "module"
1717
}

bench/test.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { LogicEngine, AsyncLogicEngine } from '../index.js'
22
import fs from 'fs'
33
import { isDeepStrictEqual } from 'util'
4-
// import traverseCopy from '../utilities/traverseCopy.js'
54
import jl from 'json-logic-js'
65
import rust from '@bestow/jsonlogic-rs'
76

@@ -33,11 +32,7 @@ console.log(
3332
incompatible.length,
3433
compatible.length / (compatible.length + incompatible.length)
3534
)
36-
fs.writeFileSync('compatible.json', JSON.stringify(compatible, undefined, 4))
37-
fs.writeFileSync(
38-
'incompatible.json',
39-
JSON.stringify(incompatible, undefined, 4)
40-
)
35+
// eslint-disable-next-line no-unused-vars
4136
const defined = [
4237
[{ '+': [1, 2, 3, 4, 5] }, {}],
4338
[{ map: [[1, 2, 3, 4, 5], { '+': [{ var: '' }, 1] }] }, {}],
@@ -61,7 +56,7 @@ const defined = [
6156
[{ '-': [{ var: '' }, 1] }, 7, 6],
6257
[{ '*': [{ var: 'x' }, { var: 'y' }] }, { x: 1, y: 3 }, 3]
6358
]
64-
const tests = defined || compatible
59+
const tests = compatible
6560
const other = tests
6661
const built = other.map((i) => {
6762
return x.build(i[0])

suites/scopes.json

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
[
2+
"A proposal for handling scopes",
3+
{
4+
"description": "Map can add each number to index",
5+
"rule": {
6+
"map": [
7+
{ "var": "numbers" },
8+
{ "+": [{ "var": "../index" }, { "var": "" }]}
9+
]
10+
},
11+
"data": { "numbers": [1,2,3] },
12+
"result": [1,3,5]
13+
},
14+
{
15+
"description": "Map can add each number to value from context",
16+
"rule": {
17+
"map": [
18+
{ "var": "numbers" },
19+
{ "+": [{ "var": "../../value" }, { "var": "" }]}
20+
]
21+
},
22+
"data": { "numbers": [1,2,3], "value": 10 },
23+
"result": [11,12,13]
24+
},
25+
{
26+
"description": "Filter can use parent context to filter",
27+
"rule": {
28+
"filter": [
29+
{ "var": "people" },
30+
{ "===": [{ "var": "department" }, { "var": "../../department" }] }
31+
]
32+
},
33+
"data": {
34+
"department": "Engineering",
35+
"people": [
36+
{ "name": "Jay Ortiz", "department": "Engineering" },
37+
{ "name": "Louisa Hall", "department": "Sales" },
38+
{ "name": "Kyle Carlson", "department": "Sales" },
39+
{ "name": "Grace Ortiz", "department": "Engineering" },
40+
{ "name": "Isabelle Harrington", "department": "Marketing" },
41+
{ "name": "Harold Moore", "department": "Sales" },
42+
{ "name": "Clarence Schultz", "department": "Sales" },
43+
{ "name": "Jesse Keller", "department": "Engineering" },
44+
{ "name": "Phillip Holland", "department": "Marketing" },
45+
{ "name": "Mason Sullivan", "department": "Engineering" }
46+
]
47+
},
48+
"result": [
49+
{ "name": "Jay Ortiz", "department": "Engineering" },
50+
{ "name": "Grace Ortiz", "department": "Engineering" },
51+
{ "name": "Jesse Keller", "department": "Engineering" },
52+
{ "name": "Mason Sullivan", "department": "Engineering" }
53+
]
54+
}
55+
]

suites/vars.json

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[
2+
"Test Specification for Handling esoteric path traversal",
3+
{
4+
"description": "Fetches a value from an empty key",
5+
"rule": { "var": "." },
6+
"data": { "" : 1 },
7+
"result": 1
8+
},
9+
{
10+
"description": "Fetches a value from a nested empty key",
11+
"rule": { "var": ".." },
12+
"data": { "" : { "": 2 } },
13+
"result": 2
14+
},
15+
{
16+
"description": "Fetches a value from a doubly nested empty key",
17+
"rule": { "var": "..." },
18+
"data": { "" : { "": { "": 3 } } },
19+
"result": 3
20+
},
21+
{
22+
"description": "Fetches a value from a key with a dot in it",
23+
"rule": { "var": "\\.key" },
24+
"data": { ".key" : 4 },
25+
"result": 4
26+
},
27+
{
28+
"description":"Fetches a value from a key with a dot in it (2)",
29+
"rule": { "var": "hello\\.world" },
30+
"data": { "hello.world" : 5 },
31+
"result": 5
32+
},
33+
{
34+
"description": "Fetches a value from a key inside an empty key with a dot in it",
35+
"rule": { "var": ".\\.key" },
36+
"data": { "": { ".key" : 6 } },
37+
"result": 6
38+
},
39+
{
40+
"description": "Going a few levels deep",
41+
"rule": { "var": "..\\.key." },
42+
"data": { "": { "": { ".key": { "": 7 }} }},
43+
"result": 7
44+
}
45+
]

0 commit comments

Comments
 (0)