osrlib.versioning
Schema and engine version stamping.
Every serialized model (saves, commands, events) stamps itself with these values from
birth. SCHEMA_VERSION is the single monotonically increasing integer shared by saves,
commands, and events — independent of the package version. Within a schema version,
changes are additive only (new event types, new optional fields); renames, removals, and
semantic changes bump it, and a loader migrates an older document forward (see
osrlib.persistence). The engine version identifies exact rules
behavior: identical replay outcomes are guaranteed only when the recorded and running
engine versions match.
The stamped-document helpers wrap a payload with both versions and a kind string, so
serialized artifacts (characters, parties, saves) share one envelope
that check_document can vet before any payload
field is trusted.
SCHEMA_VERSION
module-attribute
The current serialization schema version shared by saves, commands, and events.
Version 2 dropped the recovered-treasure ledger from the save payload: the
end-of-adventure award is computed from the departure-snapshot valuation delta
instead, so a save no longer needs to carry the ledger field. See
MIGRATIONS for the 1 → 2 step that drops it from
older saves on load.
check_document
Vet a stamped document's envelope and return its payload.
Unknown extra keys in the envelope are ignored, per the additive-schema contract.
A schema_version older than the current one is accepted and migrated in order
(see osrlib.persistence); schema version 1 is the floor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
document
|
Mapping[str, object]
|
A mapping previously produced by
|
required |
expected_kind
|
str
|
The kind the caller expects, e.g. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, object]
|
The document's payload. |
Raises:
| Type | Description |
|---|---|
ContentValidationError
|
If the envelope is malformed (missing keys, wrong
types) or the document's kind is not |
SaveVersionError
|
If the document's |
engine_version
engine_version() -> str
Return the exact osrlib package version, for stamping into saves and replays.
Returns:
| Type | Description |
|---|---|
str
|
The installed package version as reported by package metadata. |
stamp_document
Wrap a payload in the stamped-document envelope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
str
|
The document kind, e.g. |
required |
payload
|
Mapping[str, object]
|
The serialized model content. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, object]
|
A dict with |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |