feat: reachable schema generation, and a README that describes the SDK #97
No reviewers
Labels
No labels
area:defold
area:docs
area:infra
area:protocol
area:testing
kind:bug
kind:chore
phase:breadth
phase:core
phase:hardening
phase:slice
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
yuris/spacetimedb-defold!97
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "schema-reachable"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes nothing on its own; it ticks the first DX items on #77, which this session rewrote from the stale
Roadmap: what comes after v1.1.0intoDeveloper experience and documentation. The wiki half of that work is already pushed as662d17cin the wiki repo.The defect. The SDK's headline decoding path needs a generated schema, and since 2.0.0 flipped the default to v2 a table with no generated
typescannot be decoded at all — it is skipped and reported asundescribed. The generator the docs told a consumer to run wasdev/tools/gen-schema.sh: bash,curlandjq..gitattributesexport-ignores/dev, sogit archive HEADhands a consumer 13 entries and none of them is that script. The one artefact the default wire cannot work without was the one artefact we did not deliver. Nothing about it was reachable — not the tool, not a fallback, not a documented way to hand-write around it.Two reachable paths, one transform.
stdb/typetags.luais the jq walker ofgen-schema.sh:171-459ported to Lua, and it is the only copy of those rules that ships.stdb.schema.fetch(opts, cb)reads<base>/v1/database/<db>/schema?version=9through thehttp_seamand calls back a readygentable — that is the development path, no external tool at all.stdb.schema.to_lua(gen)serialises the same table to a loadable module with the same-- GENERATEDheader the shell script writes — that is the release path, a file you commit and pin. Both go throughtypetags.build, so the dev path and the pinned path cannot describe the schema differently.gen-schema.shstays exactly where it is and keeps its existing job:conformance.sh:61-76regenerates and diffs it againstdev/test/fixtures/chat_schema.luaon every conformance run. It is the contributor's drift check against a live server, not a consumer deliverable, and it never was one.The seam grew a
get.http_seamexposedpostonly, becausestdb.auth.exchangewas the only caller.stdb/auth.luanow also exposesget(url, cb), same(status, body)callback and samestatus == 0meaning nothing answered. Callinghttp.requeststraight out ofschema.luawould have been one line shorter and would have thrown away the injection point the unit tests need. No headers parameter: nothing that gets sends any, and an argument every caller passes as nil is a lie about the interface.One click in the editor.
stdb/spacetimedb.editor_scriptadds Project → SpacetimeDB: Regenerate schema. It lives understdb/becauseinclude_dirs = stdbis the only directory Defold exposes to a consumer project, it reads its defaults fromspacetimedb.base_urlandspacetimedb.databasein the consumer'sgame.project, fetches witheditor.execute("curl", ...), and writes/my_schema.lua. It carries its own JSON decoder, ~60 lines, because the editor's Lua 5.2 runtime has no JSON module — and requiringjqin the editor would have reinstated the exact dependency this PR exists to remove. That decoder is editor-only and never reaches a game bundle; the runtime path uses the engine's builtin, injected as before.Shipping the shell script and shelling out to it was the obvious shortcut and is not possible: the manual is explicit that a dependency's files "do not exist as files (they are entries in a zip archive)", and only
ext.manifestandplugins/bin/${platform}are ever extracted. There is nothing on disk to execute.README. Now describes the SDK instead of the project's status. It leads with what the thing is, then a ~20-line example that runs verbatim on the default wire via
stdb.schema.fetch— the README had no code at all, which was the worst omission for anyone deciding whether to use this. Feature bullets,Installunchanged,Layoutnow states delivered-vs-repo, and aDocumentationsection that splits the wiki by audience. The two-wire narrative, thef32mantissa paragraph and the capture-provenance sentence moved to the wiki rather than being cut. No#Nreference survives in it.The pin, in
dev/test/test_fixtures.lua. A port with no adversary is a guess, sodev/test/fixtures/chat_schema.jsonis now committed — the raw schema body — and the new cases decode it, runtypetags.build, and deep-equal the result against thechat_schema.luathe jq walker produced. That closes the loop:conformance.shpins jq to the live server, this pins Lua to jq's committed output, and the two walkers cannot drift apart in silence. Ato_luaround-trip case assertsload(to_lua(build(d)))()deep-equalsbuild(d). New cases went into the existing file —runner.luacounts suites, and the count stays 11.Verified
lua dev/test/runner.lua— 11/11.stylua --check— clean, now including the editor script, which is Lua the checker was walking past because it is not named*.lua.schema.fetchdriven against that live server returns{ "u64", "string", "string" }formessage— the value committed atchat_schema.lua:106.typetags.luamakes the fixture case fail by name; reverting it goes green. A pin that cannot fail is decoration.Not verifiable here. The editor command cannot be unit-tested — there is no editor to drive from CI, and its whole surface is
editor.execute/editor.save. It needs a hand check: open a scratch project that depends on this SDK, Fetch Libraries, then Project → SpacetimeDB: Regenerate schema, and confirm the written/my_schema.luarequires cleanly and drives aconnect. If the command does not appear in the menu, the thing to check first is whether an.editor_scriptin a library canrequirea.luamodule from that same library; the fallback, if it cannot, is to inline the walker there and pin both copies equal in the fixture test.