Upgrading from 0.8 to 0.9
In 0.9 the knowledge pack constructors reject packs that fail the check — the code it affects, how to find the problems, and before-and-after code per language.
For: developers using their own knowledge packs
0.9 adds knowledge pack checking (check) and makes the pack constructors reject packs that break the spec. That is
the only incompatible change; code that uses no custom pack (only the bundled default, or no readings) is unaffected.
x-iztro = "0.9"pip install "x-iztro~=0.9.0"
go get github.com/x-haose/x-iztro/go/iztro@v0.9.0
npm install x-iztro@0.9Pack constructors reject packs that fail the check
Affected: given a pack with any error-level issue, these entry points built it in 0.8 and return
invalid_argument in 0.9:
| Language | Entry points |
|---|---|
| Rust | KnowledgePack::from_json, from_value; bridge kinds that take pack objects (mergeKnowledgePacks, text and chart selection with a knowledge object) |
| Python | KnowledgePack.from_dict, from_json, dicts passed to merged |
| Go | ParseKnowledgePack; Merged and text or chart selection with a custom pack (the core checks it) |
| JavaScript / TypeScript | KnowledgePack.fromObject, fromJSON, plain objects passed to merged |
0.8 checked only schema, so all of these passed and either left entries silently dead or failed only when used:
- missing
id/version/language, or alanguagethat is not an x-iztro language code; - entry keys the core does not know (such as
ziweiMjj), or a combination whose other star is not a major star; - wrong field types (Python and JavaScript did not check them at construction in 0.8; merging or rendering reported the first one);
category,yinYang,fiveElementsorstemoutside its allowed set, malformed concept and topic slugs, misspelt topic palaces;- HTML tags, images or external links in text.
The full list of codes, levels and sources is in Knowledge packs · Checking a pack. Warning-level issues (fields outside the spec, empty strings, summary style, page references and so on) are reported but never block construction.
Change: run check over your packs before upgrading and fix every error; the path and suggestion point at
the spot and the closest valid spelling.
let raw: serde_json::Value = serde_json::from_str(&std::fs::read_to_string("my-school.json")?)?;
for issue in KnowledgePack::check(&raw, None) {
println!("{} {issue}", issue.level.as_key());
}import json
from x_iztro import KnowledgePack
with open("my-school.json", encoding="utf-8") as f:
for issue in KnowledgePack.check(json.load(f)):
print(issue.level, issue.message)data, _ := os.ReadFile("my-school.json")
issues, err := iztro.CheckKnowledgePack(data, nil)
if err != nil {
log.Fatal(err)
}
for _, issue := range issues {
fmt.Println(issue.Level, issue.Message)
}const raw = JSON.parse(readFileSync('my-school.json', 'utf8'));
for (const issue of KnowledgePack.check(raw)) {
console.log(issue.level, issue.message);
}On rejection the message starts invalid knowledge pack: and lists every error-level issue with its path (0.8 only
explained schema or the first parse error). The Python and JavaScript exceptions and Go's *iztro.Error also carry
issues, the full list:
try:
pack = KnowledgePack.from_dict(raw)
except IztroError as e:
for issue in e.issues:
print(issue.path, issue.code)The pack holds the core's normalized copy, so all four languages build the same pack from the same input. That brings three more visible differences:
- Python
from_dictand JavaScriptfromObjectheld a reference to the object you passed in 0.8 and hold a copy in 0.9: later changes to that object do not affect the pack, and fields outside the spec no longer appear into_dict()/toJSON(); - a JSON syntax error in Python
from_jsonor JavaScriptfromJSONraisedJSONDecodeError/SyntaxErrorin 0.8 and is aninvalid_jsonissue raisingIztroErrorin 0.9; - Go's
ParseKnowledgePackdecoded the original text withencoding/jsonin 0.8, matching keys case-insensitively ("Intro"was accepted); in 0.9 it calls into the wasm core and decodes the core's normalized pack, so keys are case-sensitive, andParseKnowledgePackContextalso exists.
The full list of changes is in the CHANGELOG.
Upgrading from 0.6 to 0.7
Each breaking change in 0.7 — the code it affects, how to change it, before-and-after code per language — plus the fixes that change output.
Upgrading from 0.9 to 0.10
In 0.10 topic lists come back in display order and topic entries gain an order field — the code it affects, with before-and-after code per language.