topmark.core.machine.envelopes¶
topmark / core / 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_json_envelope ¶
Build a JSON envelope with meta plus one or more named payloads.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meta
|
MetaPayload
|
Metadata payload (tool/version). |
required |
**payloads
|
object
|
One or more named payload objects. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, object]
|
JSON-serializable envelope dict. |
Source code in src/topmark/core/machine/envelopes.py
build_ndjson_record ¶
Build a single NDJSON record with a uniform envelope (Pattern A).
Shape
{"kind": <kind>, "meta": <meta>, <container_key>: <payload>}
Where <container_key> defaults to kind when omitted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
str
|
NDJSON record kind. |
required |
meta
|
MetaPayload
|
NDJSON payload meta. |
required |
container_key
|
str | None
|
Optional payload container key; defaults to |
None
|
payload
|
object
|
The payload object (dict-like or object exposing |
required |
Returns:
| Type | Description |
|---|---|
dict[str, object]
|
NDJSON record dict in canonical envelope shape. |
Notes
This function does not serialize to JSON; see serializers.py.