Skip to content

Commit

Permalink
builtins: update json.is_valid and yaml.is_valid for OPA v0.44.0
Browse files Browse the repository at this point in the history
We're pulling the testcases only from 0.45.0 now; and use setup-opa for getting
the binary that's used to generate the wasm module of the correct ABI version.

Fixes open-policy-agent#260.

Signed-off-by: Stephan Renatus <[email protected]>
  • Loading branch information
srenatus committed Oct 13, 2022
1 parent a675159 commit 926fc72
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ jobs:
node-version: [14.x, 16.x, 18.x]
opa-version:
- 0.30.2 # last version with ABI 1.1, 0.31.0+ has ABI 1.2
- 0.41.0 # 0.35.0 is the first release with https://github.com/open-policy-agent/opa/pull/4055
- 0.45.0 # 0.35.0 is the first release with https://github.com/open-policy-agent/opa/pull/4055

steps:
- uses: actions/checkout@v3

- name: Checkout OPA v${{ matrix.opa-version }}
- name: Checkout OPA v0.45.0 testcases
uses: actions/checkout@v3
with:
repository: open-policy-agent/opa
ref: v${{ matrix.opa-version }}
ref: v0.45.0
path: opa

- run: mkdir test/cases
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"lint": "git ls-files | xargs deno lint",
"fmt:check": "git ls-files | xargs deno fmt --check",
"fmt": "git ls-files | xargs deno fmt",
"test": "jest --verbose"
"test": "jest"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion src/builtins/json.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function isValidJSON(str) {
if (typeof str !== "string") {
return;
return false;
}
try {
JSON.parse(str);
Expand Down
5 changes: 2 additions & 3 deletions src/builtins/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ function parse(str) {
}

module.exports = {
// is_valid is expected to return nothing if input is invalid otherwise
// true/false for it being valid YAML.
"yaml.is_valid": (str) => typeof str === "string" ? parse(str).ok : undefined,
// is_valid is expected to return false if input is invalid; and true/false for it being valid YAML.
"yaml.is_valid": (str) => typeof str === "string" && parse(str).ok,
"yaml.marshal": (data) => yaml.stringify(data),
"yaml.unmarshal": (str) => parse(str).result,
};

0 comments on commit 926fc72

Please sign in to comment.