topmark.version.machine.envelopes¶
topmark / version / machine / envelopes
Envelope and record shaping utilities for machine-readable output.
This module defines shape builders for TopMark machine-readable output:
- JSON envelopes (single JSON objects) containing "meta" plus named payloads.
- NDJSON record objects containing "kind", "meta", and a payload container.
This module is intentionally:
- Console-free (no printing)
- Click-free
- serialization-free (no json.dumps)
Where things live:
- topmark.core.machine.payloads: build payload objects
(domain data).
- topmark.core.machine.envelopes: build envelopes/records
around payloads.
- topmark.core.machine.serializers: serialize
envelopes/records to strings.
NDJSON convention (Pattern A):
- Every record includes "kind" and "meta".
- Prefer omitting container_key so the container key equals kind.
build_version_ndjson_record ¶
Build an NDJSON version record for the version command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meta
|
MetaPayload
|
Metadata payload (tool/version). |
required |
payload
|
Mapping[str, object]
|
Version payload with version info. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, object]
|
Shaped NDJSON record mapping: |
dict[str, object]
|
|
Source code in src/topmark/version/machine/envelopes.py
build_version_diagnostic_ndjson_record ¶
Build an NDJSON diagnostic record for the version command.
Emitted when SemVer conversion was requested but failed and TopMark fell back to the original PEP 440 version string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meta
|
MetaPayload
|
Metadata payload (tool/version). |
required |
message
|
str
|
Human-readable diagnostic message. |
required |
level
|
DiagnosticLevel
|
Diagnostic severity (defaults to WARNING). |
WARNING
|
Returns:
| Type | Description |
|---|---|
dict[str, object]
|
Shaped NDJSON record: |
dict[str, object]
|
{"kind": "diagnostic", "meta": {...}, "diagnostic": {...}} |
Source code in src/topmark/version/machine/envelopes.py
iter_version_ndjson_records ¶
Build NDJSON records for topmark version (Pattern A).
Contract: every record includes kind and meta.
Records
1) kind="version" with payload under key "version" 2) (optional) kind="diagnostic" if SemVer conversion was requested and failed
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 |
|---|---|
dict[str, object]
|
Shaped NDJSON record mappings. |