From 3fec9f27ec0d2d9d7e67f5a0fbe9fc098f9371d6 Mon Sep 17 00:00:00 2001 From: Anand Krishnamoorthi Date: Tue, 6 Feb 2024 00:41:48 -0800 Subject: [PATCH] Regorus Playground Signed-off-by: Anand Krishnamoorthi --- _site/feed.xml | 2 +- _site/index.html | 119 ++++++++++++++++++++++-------------- _site/pkg/regorus_bg.wasm | Bin 4614759 -> 4614759 bytes index.markdown | 108 ++++++++++++++++++++------------- pkg/regorus_bg.wasm | Bin 4614759 -> 4614759 bytes style.css | 124 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 265 insertions(+), 88 deletions(-) create mode 100644 style.css diff --git a/_site/feed.xml b/_site/feed.xml index 089d5965..2c576ff9 100644 --- a/_site/feed.xml +++ b/_site/feed.xml @@ -1 +1 @@ -Jekyll2024-01-24T16:48:53-08:00http://localhost:4000/regorus/feed.xmlRegorus PlaygroundRun Regorus in a browser via WASM \ No newline at end of file +Jekyll2024-02-06T00:39:58-08:00http://localhost:4000/feed.xmlRegorus PlaygroundRun Regorus in a browser via WASM \ No newline at end of file diff --git a/_site/index.html b/_site/index.html index 45ddb2f5..9444e6a6 100644 --- a/_site/index.html +++ b/_site/index.html @@ -3,41 +3,48 @@ Regorus Playground - + -

Regorus Playground

- -
-
Policy
- -
-
- -
- -
-
Input JSON
-
- -

+    

Regorus Playground

+
+
+

Rego

+
+
+ +
+
+ + + +
+
+
+
+
+
+

Output

+
+
+
- + - - - + + + diff --git a/_site/pkg/regorus_bg.wasm b/_site/pkg/regorus_bg.wasm index 2f98e23ee4898fa271197310bd4733d7c6c446be..d1ed1797f71d5266fc035ac2c1ff3df56f872ebc 100644 GIT binary patch delta 248 zcmWm4Nm9Z<0EW>5C!7Vv8ASvHap;&1Bn}{I4iZi094@{ptGt2tu*!>gfb6&iKa00} zlmDOML_R4{WR7_jSY(M3%dD`<8tZJZ$rfcQY_mg^UG~`LfJ2Trrp5`U)H$QUIZax$ zxu8Rr%imrt??hRc7|$l&yR(UPQ8w^Hmj*U4k^kXLW`ZHpr4=lRR5&v%@Y0ij>%6p92mlbHp(xRH$;w88zxOXwsrhhjY4IaLE-t zuDMzC>uJv$S}zHm@!VtRegorus Playground -

Regorus Playground

- -
-
Policy
- -
-
- -
- -
-
Input JSON
-
- -

+    

Regorus Playground

+
+
+

Rego

+
+
+ +
+
+ + + +
+
+
+
+
+
+

Output

+
+
+
- + @@ -146,19 +152,25 @@ href="{{'node_modules/monaco-editor/min/vs/editor/editor.main.css'|relative_url} let separator = "\n###POLICY###\n" let framework_rego = 'package play' - var rego_editor = monaco.editor.create(document.getElementById('rego_container'), { + var rego_editor = monaco.editor.create(document.getElementById('Rego'), { value: framework_rego, language: 'Rego', minimap: { enabled: false }, }); - var input_editor = monaco.editor.create(document.getElementById('input_container'), { + var input_editor = monaco.editor.create(document.getElementById('Input'), { value: '{}', - language: 'javascript', + language: 'json', minimap: { enabled: false }, }); - var results_editor = monaco.editor.create(document.getElementById('results'), { + var data_editor = monaco.editor.create(document.getElementById('Data'), { + value: '{}', + language: 'json', + minimap: { enabled: false }, + }); + + var results_editor = monaco.editor.create(document.getElementById('Output'), { value: '{}', language: 'json', readOnly: true, @@ -167,30 +179,44 @@ href="{{'node_modules/monaco-editor/min/vs/editor/editor.main.css'|relative_url} rego_editor.setValue(loadFile("examples/example.rego")) input_editor.setValue(loadFile("examples/input.json")) + data_editor.setValue("{}") + document.getElementById('Data').style.display = 'none' function eval_query() { - let policy = rego_editor.getValue(); - let files = policy.split(separator) - - var startTime = new Date(); - var engine = new Engine(); - for (var i =0; i < files.length; ++i) { - engine.add_policy("policy.rego", files[i]) + let policy = rego_editor.getValue(); + let files = policy.split(separator) + + try { + var startTime = new Date(); + var engine = new Engine(); + for (var i =0; i < files.length; ++i) { + engine.add_policy("policy.rego", files[i]) + } + + engine.set_input(input_editor.getValue()); + engine.add_data(data_editor.getValue()); + let parse_time = new Date() - startTime; + + let results = engine.eval_query("data"); + var elapsed = new Date() - startTime; + let output = `// Evaluation took ${elapsed} milliseconds. parse = ${parse_time}, eval = ${elapsed - parse_time}\n${results}`; + results_editor.setValue(output) + } + catch (error) { + results_editor.setValue(error) + } } - - let input = input_editor.getValue(); - engine.set_input(input); - - let results = engine.eval_query("data"); - var elapsed = new Date() - startTime; - - let output = `// Evaluation took ${elapsed} milliseconds.\n${results}`; - results_editor.setValue(output) - - } async function run() { await init() - document.getElementById('eval').onclick = eval_query; + document.getElementById('Eval').onclick = eval_query; + document.getElementById('SelectInput').onclick = function() { + document.getElementById('Data').style.display = 'none' + document.getElementById('Input').style.display = 'inline' + } + document.getElementById('SelectData').onclick = function() { + document.getElementById('Input').style.display = 'none' + document.getElementById('Data').style.display = 'inline' + } } run(); diff --git a/pkg/regorus_bg.wasm b/pkg/regorus_bg.wasm index 2f98e23ee4898fa271197310bd4733d7c6c446be..d1ed1797f71d5266fc035ac2c1ff3df56f872ebc 100644 GIT binary patch delta 248 zcmWm4Nm9Z<0EW>5C!7Vv8ASvHap;&1Bn}{I4iZi094@{ptGt2tu*!>gfb6&iKa00} zlmDOML_R4{WR7_jSY(M3%dD`<8tZJZ$rfcQY_mg^UG~`LfJ2Trrp5`U)H$QUIZax$ zxu8Rr%imrt??hRc7|$l&yR(UPQ8w^Hmj*U4k^kXLW`ZHpr4=lRR5&v%@Y0ij>%6p92mlbHp(xRH$;w88zxOXwsrhhjY4IaLE-t zuDMzC>uJv$S}zHm@!Vt