Skip to main content

Module project

Module project 

Source
Expand description

The .kernsetzer project file: a zip archive with

meta.json          { "format_version": 2, "created_with": "kernsetzer 0.1.0", "modified": "…" }
book.json          the Book, pretty-printed
assets/<id>        images, referenced by id from book.json

plus book.json (de)serialization with schema migrations, and the autosave sidecar <name>.kernsetzer.autosave next to the project.

Saving writes a temporary sibling and renames it over the project, so a crash mid-save never leaves a half-written project behind.

Structs§

Meta
Contents of meta.json: facts about the file, not about the book.
Project
A book with its images and file metadata: what a .kernsetzer holds.

Enums§

ProjectError

Constants§

CREATED_WITH
The build that writes a file, as recorded in meta.json.
EXTENSION
The project file’s extension, without the dot.
MAX_ASSET_BYTES
Largest single asset accepted (same limit as the .docx importer).
MAX_JSON_BYTES
Largest book.json / meta.json accepted (a 100k-word novel is ~2 MB).
MIGRATIONS
OLD_EXTENSION
The extension of project files from before the rename. Files with it are still opened.

Functions§

autosave_path
The autosave sidecar for a project: Roman.kernsetzer → Roman.kernsetzer.autosave, in the same folder. If it exists when a project is opened, the last session ended without a clean save.
book_from_json
Parse book.json, migrating older formats to the current one.
book_to_json
discard_autosave
Remove the autosave sidecar, if there is one.
migrate
Bring a book.json value of any supported version to the current format, applying the migrations in order.
now_rfc3339
The current time as RFC 3339 in UTC, to the second.

Type Aliases§

Migration
One schema step: MIGRATIONS[i] turns a version i + 1 book.json into version i + 2. Each step is a plain function on JSON, written once and never changed afterwards (old files stay old). When the schema changes incompatibly: bump FORMAT_VERSION, append the step, and commit a fixture of the old version under tests/fixtures/.