Tiny multi-key JSON value database over a 4D sudoku lattice (1..215 cells per axis, 81 by default), with a SQL surface and sudoku digit constraints.
moon add riantr/tesseract@0.1.3///|
import {
"riantr/tesseract/src/tesseract",
}| Package | Kind | Native | Wasm | Wasm-GC | JS |
|---|---|---|---|---|---|
| riantr/tesseract/src/tesseract | library | yes | yes | yes | yes |
| riantr/tesseract/src/tesseract_dgp | library | yes | yes | yes | yes |
| riantr/tesseract/src/tesseract_sqlite | library | yes | yes | — | — |
| riantr/tesseract/src/tesseract_sa | library | yes | yes | — | — |
| cmd/main | executable | yes | yes | yes | yes |
| cmd/persist | executable | yes | yes | — | — |
| cmd/sa | executable | yes | yes | — | — |
| cmd/gui | executable | yes | — | — | — |
| C# original | this version | |
|---|---|---|
| shape | flat 9-cell ring shown as 3x3 | 3x3x3x3 lattice, 81 cells (default) |
| addressing | grid_position 1..9 | grid_position 1..81, or (x,y,z,w) |
| sudoku | none | digits 1..3, one set per axis-parallel line |
| structure | 9 rows / 1 box | 4 axes x 27 lines = 108 lines, 12 slabs |
| side = 3 (default) | side = 4 | |
|---|---|---|
| cells | 81 | 256 |
| digit domain | 1..3 | 1..4 |
| lines | 108 | 256 |
| slabs (each) | 12 of 27 cells | 16 of 64 cells |
| peers per cell | 8 | 12 |
moon run cmd/main -- --side 4 .status
moon run cmd/main -- --side 4 .solve .verifyposition = 1 + x*side^3 + y*side^2 + z*side + w (row-major, x slowest)digit(x,y,z,w) = (x + y + z + w) mod 3 + 1src/tesseract/
text.mbt ASCII helpers: trim, case folding, integer parse, split/join
coords.mbt the lattice: coordinates, positions, neighbours, shares_line
lattice.mbt lines, slabs, planes, peers
sudoku.mbt digits, the line rule, slab balance, backtracking solver
txn.mbt transactions: the undo journal, savepoints, statement atomicity
types.mbt GridCell, Record, Computed, DBResponse, DBStatus, formatting
logger.mbt bounded log ring (100 entries, matching the C# logger)
clock.mbt the injected clock and its ISO-8601 rendering
db.mbt the store, and the in-place resize between shapes
lexer.mbt the SQL tokenizer
ast.mbt the parsed shape of a statement
parser.mbt recursive descent, precedence climbing
exec.mbt the executor: expressions, aggregates, ordering, transactions
jsonpath.mbt the JSON path: parsing it, walking it, reading a number from text
serialize.mbt .tsr JSON, .md table, .sql dump, lattice rendering
cmd/main/ command line front end
cmd/gui/ the proton desktop window
main.mbt the App: entry point, page asset, command registration
state.mbt the store the window drives, and its JSON projections
commands.mbt the seven typed commands the page can call
web/index.html the page itself - inline CSS and JS, no build step
proton.project.json bundle identity, backend package, packaging settings
gui-smoke.mjs end-to-end smoke test driven through Chromium DevTools| operation | what it does |
|---|---|
| app:state | occupancy, cursor, digit count, the current side × side plane, sudoku health, log tail |
| app:lattice | change side; rebuilds the store in place and reports kept/dropped |
| app:write | insert / update / delete / clear / cursor, plus solve and demo |
| app:query | one SQL statement, returning rows and a repaint |
| app:geometry | line / slab / peers around a cell, with the covered positions |
| app:export | .tsr, .md, .sql, or the ASCII lattice |
| app:import | load a .tsr, .md or .sql dump back in |

| before | now | |
|---|---|---|
| WHERE key='a' AND key='b' | 1 row — the last conjunct overwrote the first | 0 rows |
| WHERE key='a' OR key='b' | INVALID_SYNTAX | 2 rows |
| LIMIT 1 | 3 rows | 1 row |
| ORDER BY key DESC | insertion order | sorted |
| WHERE digit=1+1 | INVALID_SYNTAX | evaluates |
| Area | Supported |
|---|---|
| statements | CREATE DATABASE, INSERT, UPDATE, DELETE, SELECT, transaction control |
| columns | key value position grid_position digit timestamp x y z w side |
| expressions | arithmetic, comparison, AND / OR / NOT, LIKE, parentheses |
| functions | length upper lower abs coords digits json_extract; geometry line slab peers; aggregates count sum min max avg |
| clauses | WHERE GROUP BY ORDER BY LIMIT OFFSET DISTINCT |
| three-valued logic | null is unknown; only WHERE folds it to false, everything else carries it |
| not supported | joins, subqueries, window functions, UNION, CTEs, and DDL beyond CREATE DATABASE |
CREATE DATABASE tesseract;
INSERT INTO tesseract (key, value) VALUES ('user_001', '{"age": 25}');
SELECT * FROM tesseract WHERE key = 'user_001';
SELECT * FROM tesseract WHERE value LIKE '%age%';
UPDATE tesseract SET value = '{"age": 26}' WHERE key = 'user_001';
DELETE FROM tesseract WHERE key = 'user_001';-- explicit address, as a position or as coordinates
INSERT INTO tesseract (key, value) VALUES ('k', 'v') AT 42;
INSERT INTO tesseract (key, value) VALUES ('k', 'v') AT (1,2,0,2);
-- sudoku digits, enforced against the lines through the cell
INSERT INTO tesseract (key, value, digit) VALUES ('k', 'v', 2);
UPDATE tesseract SET value = 'v', digit = 3 WHERE grid_position = 42;
-- coordinate predicates
SELECT * FROM tesseract WHERE x = 1 AND y = 2;
SELECT * FROM tesseract WHERE digit = 1;
-- geometry
SELECT * FROM tesseract WHERE line(42, 0); -- the 3-cell axis-parallel line
SELECT * FROM tesseract WHERE slab(42, 1); -- the 27-cell slab
SELECT * FROM tesseract WHERE peers(42); -- the 8 cells sharing a lineSELECT * FROM tesseract WHERE peers(42) AND key = 'user_001';OR < AND < NOT < = <> != < <= > >= LIKE IN IS NULL
< + - < * / % < unary - < literals, columns, ( ), functionsSELECT * FROM tesseract WHERE key = 'a' OR key = 'b';
SELECT * FROM tesseract WHERE digit = 1 + 1;
SELECT * FROM tesseract WHERE key IN ('a', 'b', 'c');
SELECT * FROM tesseract WHERE NOT (x = 1 AND y = 2);SELECT json_extract(value, '$.name') FROM tesseract WHERE key = 'user_001';
SELECT key FROM tesseract WHERE json_extract(value, '$.age') > 30;
SELECT sum(json_extract(value, '$.amount')) FROM tesseract;$ the whole document
$.name a key
$.a.b a key inside a key
$.tags[1] the second element of an array
$["a b"] a key that is not an identifier| lands on | answers |
|---|---|
| a whole number | the integer, at full 64-bit width |
| a number that is not a whole number | its own text, unrounded — 2.5 stays 2.5 |
| a string | the string |
| true / false | 1 / 0 |
| null | null |
| an object or an array | its JSON text, so it can be fed back in |
| nothing there | null |
-- matched every row that mentioned the word, including one with no such key
SELECT key FROM tesseract WHERE value LIKE '%name%';
-- matched the rows that have the key
SELECT key FROM tesseract WHERE json_extract(value, '$.name') IS NOT NULL;SELECT digit, count(*) FROM tesseract GROUP BY digit;
SELECT sum(digit) FROM tesseract WHERE digit > 0;
SELECT key FROM tesseract ORDER BY key DESC, digit ASC;
SELECT key FROM tesseract ORDER BY key LIMIT 10 OFFSET 20;
SELECT DISTINCT value FROM tesseract;BEGIN;
INSERT INTO tesseract (key, value) VALUES ('a', '1') AT 1;
SAVEPOINT sp;
INSERT INTO tesseract (key, value) VALUES ('b', '2') AT 2;
ROLLBACK TO sp; -- the 'b' insert goes; the transaction stays open
COMMIT;
ROLLBACK; -- or undo the whole thingmoon check --target all # type-check every backend
moon test # 240 tests
moon fmt --check # canonical formatting
node cli-smoke.mjs # both CLIs, as real processes (builds them first)
node gui-smoke.mjs # the window, over CDP (needs `proton_cli dev` running)
moon run cmd/main -- .help
moon run cmd/main -- .status
moon run cmd/main -- .demo
moon run cmd/main -- .solve .verify
moon run cmd/main -- "INSERT INTO tesseract (key,value) VALUES ('a','1') AT 5;" "SELECT * FROM tesseract;"
moon run cmd/main -- .export tsr > dump.tsr
# 256 cells, digits 1..4
moon run cmd/main -- --side 4 .status
moon run cmd/main -- --side 4 .solve .verify$ moon run cmd/main -- --side 999 .status
--side side 999 is above the maximum 215 (cells are stored in one flat array indexed by a 32-bit Int)moon run cmd/persist --target native -- .open sudoku.db \
"INSERT INTO tesseract (key,value,digit) VALUES ('user_001','{\"age\": 25}',1) AT 1;" \
.save .status .verify
# a second process reads the same file back
moon run cmd/persist --target native -- .open sudoku.db .status| command | effect |
|---|---|
| .open <path> | replace the store with the file's contents |
| .save [path] | write the store out, to <path> or to the last .open |
| .status | occupancy, digits, cursor, and the file in use |
| .verify | line and slab check over the digits in the store |
while read -r line; do moon run cmd/main -- "$line"; donemoonx riantr/moonbit_static_analysis@0.4.1 . > scan.tsv
moon run cmd/sa --target native -- store scan.tsv scan.db
moon run cmd/sa --target native -- runs scan.db
moon run cmd/sa --target native -- show scan.db
moon run cmd/sa --target native -- files scan.db
moon run cmd/sa --target native -- unparsed scan.db| table | holds |
|---|---|
| sa_runs | one row per scan: coverage, counts, target |
| sa_files | each file the analyzer reported on, with outcome, defects, notices, shown |
| sa_findings | the findings that were actually rendered |
| sa_by_kind | the per-.mbt/.mbti/.mbt.md rollup the tool prints |
| sa_unparsed | per reason: how many files, and up to three example paths |
moon update # refresh the registry index
moon install moonbit-community/proton_cli@0.5.1 # match the library version
proton_cli cef setup # CEF runtime + subprocess helper
proton_cli doctor # identity, toolchain and runtime
proton_cli dev # run the window
proton_cli build # native build
proton_cli package --dry-run # check the packaging plan
proton_cli package # produce dist/"resources": [ "cmd/gui/web" ]node gui-smoke.mjs| Command | Result |
|---|---|
| moon fmt --check | exit 0 |
| moon check --target wasm --deny-warn | exit 0 |
| moon check --target js --deny-warn | exit 0 |
| moon check --target native --deny-warn | exit 0 |
| moon check --target wasm-gc --deny-warn | exit 0 |
| moon test --target wasm --deny-warn | 240 passed, 0 failed |
| moon build --target wasm | exit 0 |
| typos (v1.50.3 — the version the workflow pins) | exit 0 |
| node cli-smoke.mjs | 14 passed, 0 failed |
| node gui-smoke.mjs | 45 passed, 0 failed |
| format | role |
|---|---|
| .tsr | JSON, the native save format; round-trips key, value, position, digit and timestamp losslessly |
| .md | Markdown table, human-readable and diffable |
| .sql | SQL dump this package's own parser re-imports |
Install
Download zipTiny multi-key JSON value database over a 4D sudoku lattice (1..215 cells per axis, 81 by default), with a SQL surface and sudoku digit constraints.