topmark.version.machine.serializers¶
topmark / version / machine / serializers
Pure JSON/NDJSON serialization utilities for machine-readable output.
This module converts already-shaped machine-readable output objects (envelopes or NDJSON record mappings) into strings.
It is intentionally:
- Console-free (no ConsoleLike, no printing)
- Click-free
- side-effect-free (serialization only)
Separation of concerns:
- topmark.version.machine.payloads builds payload objects
(domain data, no envelope).
- topmark.version.machine.envelopes builds envelopes/records
(adds meta/kind/container keys).
- This module serializes those shapes to JSON/NDJSON strings.
Conventions:
- json.dumps() does not append a trailing newline.
- serialize_ndjson() returns a string that does end with a final \\n,
which is convenient for CLI printing and piping.
serialize_version ¶
Serialize topmark version output in machine-readable JSON/NDJSON form.
JSON envelope
{"meta": {...}, "version_info": {"version": "...", "version_format": "..."}}
NDJSON stream
1) {"kind": "version", "meta": {...}, "version": {...}}
2) Optional diagnostic record if SemVer conversion failed and a fallback occurred.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meta
|
MetaPayload
|
Metadata payload (tool/version). |
required |
fmt
|
OutputFormat
|
Output format. Only JSON and NDJSON are supported here. |
required |
semver
|
bool
|
Whether to attempt SemVer conversion of the tool version. |
required |
Returns:
| Type | Description |
|---|---|
str | Iterator[str]
|
Serialized JSON string or or NDJSON string iterable. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/topmark/version/machine/serializers.py
serialize_version_json ¶
Serialize topmark version output in machine-readable JSON/NDJSON form.
JSON envelope
{"meta": {...}, "version_info": {"version": "...", "version_format": "..."}}
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meta
|
MetaPayload
|
Metadata payload (tool/version). |
required |
semver
|
bool
|
Whether to attempt SemVer conversion of the tool version. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Serialized NDJSON string. |
Source code in src/topmark/version/machine/serializers.py
serialize_version_ndjson ¶
Serialize topmark version output in machine-readable JSON/NDJSON form.
NDJSON stream
1) {"kind": "version", "meta": {...}, "version": {...}}
2) Optional diagnostic record if SemVer conversion failed and a fallback occurred.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meta
|
MetaPayload
|
Metadata payload (tool/version). |
required |
semver
|
bool
|
Whether to attempt SemVer conversion of the tool version. |
required |
Yields:
| Type | Description |
|---|---|
str
|
Serialized JSON string. |