Skip to content

Commit d7a952e

Browse files
committed
cql2playground
1 parent a03a4ac commit d7a952e

File tree

7 files changed

+602
-0
lines changed

7 files changed

+602
-0
lines changed

cql2/index.html

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<html>
2+
<head>
3+
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
4+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
5+
</head>
6+
<body>
7+
<script type="module">
8+
import init, { CQL2 } from './pkg/cql2_wasm.js';
9+
10+
await init();
11+
window.CQL2 = CQL2;
12+
$(document).ready(function(){
13+
console.log("Ready");
14+
console.log("window.cql2", window.CQL2);
15+
function check(){
16+
let valid = false;
17+
let txt = "Invalid";
18+
let jsn = "Invalid";
19+
try {
20+
let val =$("#cqlin").val();
21+
console.log("cqlin val", val);
22+
let e = new window.CQL2(val);
23+
valid = e.is_valid();
24+
txt = e.to_text();
25+
jsn = e.to_json_pretty();
26+
} catch(error) {
27+
console.log(error);
28+
29+
}
30+
console.log(valid, txt, jsn);
31+
if (valid) {
32+
$("#cqlvalid").prop("checked", true);
33+
$("#cql2text").css({"background-color": "#90EE90"});
34+
$("#cql2json").css({"background-color": "#90EE90"});
35+
} else {
36+
$("#cqlvalid").prop("checked", false);
37+
$("#cql2text").css({"background-color": "pink"});
38+
$("#cql2json").css({"background-color": "pink"});
39+
};
40+
41+
$("#cql2text").val(txt);
42+
$("#cql2json").val(jsn);
43+
};
44+
$("#cqlin").bind('input propertychange', check);
45+
check();
46+
});
47+
48+
</script>
49+
<h1>CQL2 Playground</h1>
50+
<textarea id="cqlin" rows="20" cols="100">foo > 1</textarea>
51+
<br/>
52+
Valid:<input type="checkbox" id="cqlvalid" onclick="return false"></input>
53+
<br/>
54+
Parsed CQL2 Text
55+
<br/>
56+
<textarea id="cql2text" rows="10" cols="100" readonly>Parsed CQL2 Text</textarea>
57+
<br/>
58+
Parsed CQL2 JSON
59+
<br/>
60+
<textarea id="cql2json" rows="20" cols="100" readonly>Parsed CQL2 JSON</textarea>
61+
62+
63+
</body>
64+
<script>
65+
66+
</script>
67+
</html>

cql2/pkg/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# cql2-wasm
2+
## To Build
3+
`export RUSTFLAGS='--cfg getrandom_backend="wasm_js'`
4+
`wasm-pack build`

cql2/pkg/cql2_wasm.d.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
export class CQL2 {
4+
free(): void;
5+
constructor(v: string);
6+
is_valid(): boolean;
7+
to_json(): string;
8+
to_json_pretty(): string;
9+
to_text(): string;
10+
}
11+
12+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
13+
14+
export interface InitOutput {
15+
readonly memory: WebAssembly.Memory;
16+
readonly __wbg_cql2_free: (a: number, b: number) => void;
17+
readonly cql2_new: (a: number, b: number) => [number, number, number];
18+
readonly cql2_is_valid: (a: number) => number;
19+
readonly cql2_to_json: (a: number) => [number, number, number, number];
20+
readonly cql2_to_json_pretty: (a: number) => [number, number, number, number];
21+
readonly cql2_to_text: (a: number) => [number, number, number, number];
22+
readonly __wbindgen_exn_store: (a: number) => void;
23+
readonly __externref_table_alloc: () => number;
24+
readonly __wbindgen_export_2: WebAssembly.Table;
25+
readonly __wbindgen_malloc: (a: number, b: number) => number;
26+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
27+
readonly __externref_table_dealloc: (a: number) => void;
28+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
29+
readonly __wbindgen_start: () => void;
30+
}
31+
32+
export type SyncInitInput = BufferSource | WebAssembly.Module;
33+
/**
34+
* Instantiates the given `module`, which can either be bytes or
35+
* a precompiled `WebAssembly.Module`.
36+
*
37+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
38+
*
39+
* @returns {InitOutput}
40+
*/
41+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
42+
43+
/**
44+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
45+
* for everything else, calls `WebAssembly.instantiate` directly.
46+
*
47+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
48+
*
49+
* @returns {Promise<InitOutput>}
50+
*/
51+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;

0 commit comments

Comments
 (0)