topmark.config.machine.envelopes¶
topmark / config / machine / envelopes
Envelope builders for config-related machine-readable output.
Envelopes are small, JSON-friendly Python mappings that follow TopMark's machine output conventions:
- JSON: a single envelope object containing
metaplus one or more named payloads. - NDJSON: one JSON object per line, each carrying the
kindandmetaenvelope.
This module is pure (no I/O, no ConsoleLike) and delegates payload construction
to topmark.config.machine.payloads.
When NDJSON needs one diagnostic per line, this module flattens staged config-validation logs at the output boundary and streams the resulting compatibility diagnostics.
build_config_json_envelope ¶
Build the JSON envelope for a FrozenConfig snapshot.
Shape
{"meta":
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
FrozenConfig
|
Immutable runtime configuration to serialize. |
required |
resolved_toml
|
ResolvedTopmarkTomlSources
|
Resolved TOML sources used to build the optional layered provenance export. |
required |
meta
|
MetaPayload
|
Machine-output metadata (tool/version). |
required |
cfg_provenance_payload
|
TomlProvenancePayload | None
|
Optional machine-readable layered config provenance payload to include before the final flattened config payload. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, object]
|
A JSON-envelope mapping (not yet serialized). |
Source code in src/topmark/config/machine/envelopes.py
iter_config_ndjson_records ¶
Iterate NDJSON records for a FrozenConfig snapshot.
Shapes
- without provenance:
- with provenance: 1) {"kind": "config_provenance", "meta": ..., "config_provenance": ...} 2) {"kind": "config", "meta": ..., "config": ...}
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
FrozenConfig
|
Immutable runtime configuration to serialize. |
required |
resolved_toml
|
ResolvedTopmarkTomlSources
|
Resolved TOML sources used to build the optional layered provenance export. |
required |
meta
|
MetaPayload
|
Machine-output metadata (tool/version). |
required |
cfg_provenance_payload
|
TomlProvenancePayload | None
|
Optional machine-readable layered config provenance payload to emit before the final flattened config record. |
None
|
Yields:
| Type | Description |
|---|---|
dict[str, object]
|
An iterable of NDJSON record mappings (not yet serialized). |
Source code in src/topmark/config/machine/envelopes.py
build_config_diagnostics_json_envelope ¶
Build the JSON envelope for config diagnostics.
Shape
{"meta":
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
FrozenConfig
|
Immutable runtime configuration providing staged validation logs that are flattened for machine-readable output. |
required |
meta
|
MetaPayload
|
Machine-output metadata (tool/version). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, object]
|
A JSON-envelope mapping (not yet serialized). |
Source code in src/topmark/config/machine/envelopes.py
iter_config_diagnostics_ndjson_records ¶
Iterate NDJSON records for config diagnostics.
Shapes
- counts-only record: {"kind": "config_diagnostics", "meta": ..., "config_diagnostics": {"diagnostic_counts": ...}}
- one
diagnosticrecord per entry (domain="config")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
FrozenConfig
|
Immutable runtime configuration providing staged validation logs that are flattened for NDJSON output. |
required |
meta
|
MetaPayload
|
Machine-output metadata (tool/version). |
required |
Yields:
| Type | Description |
|---|---|
dict[str, object]
|
NDJSON record mappings (not yet serialized), in this order: |
dict[str, object]
|
1) one |
dict[str, object]
|
2+) one |
Source code in src/topmark/config/machine/envelopes.py
build_config_check_json_envelope ¶
Build the JSON envelope for topmark config check.
Shape
{"meta": ..., "config": ..., "config_diagnostics": ..., "config_check": ...}
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
FrozenConfig
|
Immutable runtime configuration. |
required |
resolved_toml
|
ResolvedTopmarkTomlSources
|
Resolved TOML sources used to build the optional layered provenance export. |
required |
meta
|
MetaPayload
|
Machine-output metadata (tool/version). |
required |
strict
|
bool
|
Whether warnings are treated as failures. |
required |
ok
|
bool
|
Whether the config passed validation. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, object]
|
A JSON-envelope mapping (not yet serialized). |
Source code in src/topmark/config/machine/envelopes.py
iter_config_prefix_ndjson_records ¶
iter_config_prefix_ndjson_records(
*,
config,
resolved_toml,
meta,
cfg_payload=None,
cfg_diag_payload=None,
)
Yield the standard NDJSON prefix records for config-aware machine streams.
Prefix
1) config record with the effective config snapshot
2) config_diagnostics record containing counts only
Callers that want per-diagnostic records should additionally emit
iter_diagnostic_ndjson_records(...).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
FrozenConfig
|
Effective configuration instance. |
required |
resolved_toml
|
ResolvedTopmarkTomlSources
|
Resolved TOML sources used to build the optional layered provenance export. |
required |
meta
|
MetaPayload
|
Shared metadata payload. |
required |
cfg_payload
|
ConfigPayload | None
|
Optional precomputed |
None
|
cfg_diag_payload
|
ConfigDiagnosticsPayload | None
|
Optional precomputed |
None
|
Yields:
| Type | Description |
|---|---|
dict[str, object]
|
NDJSON records for |
Source code in src/topmark/config/machine/envelopes.py
iter_config_check_ndjson_records ¶
Iterate NDJSON records for topmark config check.
Record sequence
1) config 2) config_diagnostics (counts-only) 3) config_check 4+) diagnostic (domain="config") one per flattened compatibility diagnostic
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
FrozenConfig
|
Immutable runtime configuration. |
required |
resolved_toml
|
ResolvedTopmarkTomlSources
|
Resolved TOML sources used to build the optional layered provenance export. |
required |
meta
|
MetaPayload
|
Machine-output metadata (tool/version). |
required |
strict
|
bool
|
Whether warnings are treated as failures. |
required |
ok
|
bool
|
Whether the config passed validation. |
required |
Yields:
| Type | Description |
|---|---|
dict[str, object]
|
NDJSON record mappings (not yet serialized), in this order: |
dict[str, object]
|
1) |
dict[str, object]
|
2) |
dict[str, object]
|
3) |
dict[str, object]
|
4+) |