Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

builtins: update json.is_valid and yaml.is_valid for OPA v0.44.0 #282

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
};