|
10 | 10 | </head> |
11 | 11 | <body> |
12 | 12 | <h1>json_schema_wasm - browser demo</h1> |
13 | | - <pre id="out">initialising …</pre> |
| 13 | + <pre id="out">initializing …</pre> |
14 | 14 |
|
15 | 15 | <script type="module"> |
16 | 16 | // The Wasm package is built into `pkg/` by `just wasm-demo` with |
17 | 17 | // wasm-pack build wasm --target web --out-dir examples/wasm/pkg |
18 | | -import init, { check_compat, generate_value } from "../../wasm/pkg/jsoncompat_wasm.js"; |
| 18 | + import init, { check_compat, generate_value } from "../../wasm/pkg/jsoncompat_wasm.js"; |
19 | 19 |
|
20 | 20 | const out = document.getElementById('out'); |
21 | 21 |
|
22 | 22 | (async () => { |
23 | 23 | await init(); |
| 24 | + const oldSchema = `{ |
| 25 | + "type": "object", |
| 26 | + "properties": { |
| 27 | + "name": { "type": "string" }, |
| 28 | + "age": { "type": "integer", "minimum": 18 } |
| 29 | + }, |
| 30 | + "required": ["name"] |
| 31 | +}`; |
| 32 | + const newSchema = `{ |
| 33 | + "type": "object", |
| 34 | + "properties": { |
| 35 | + "name": { "type": "string", "minLength": 5 }, |
| 36 | + "age": { "type": "integer", "minimum": 18 } |
| 37 | + } |
| 38 | +}`; |
24 | 39 |
|
25 | | - const oldSchema = '{"type":"string"}'; |
26 | | - const newSchema = '{"type":"number"}'; |
27 | 40 |
|
28 | 41 | const lines = []; |
29 | 42 | lines.push('=== Compatibility checks ==='); |
30 | 43 | for (const role of ['serializer','deserializer','both']) { |
31 | 44 | const ok = await check_compat(oldSchema, newSchema, role); |
32 | 45 | lines.push(`${role.padEnd(12)}: ${ok}`); |
33 | 46 | } |
34 | | - |
35 | 47 | lines.push('\n=== Example value generation ==='); |
36 | 48 | const sample = await generate_value(oldSchema, 3); |
37 | 49 | lines.push(sample); |
|
0 commit comments