Add yaml.dump() serializer #5

Closed
opened 2026-03-17 09:52:36 +01:00 by michael · 1 comment
Owner

Summary

yaml.lua has load() and load_file() but no serialization.
steurjan needs to write transaction_context/v2 and decision_snapshot/v2
as YAML files to the journal. Without dump(), every project that writes
YAML would need its own serializer.

Scope

Add yaml.dump(table) to src/daw/lua/common/yaml.lua.

Requirements

  • Output must be valid YAML 1.1 (readable by the existing load())
  • Support: nested maps, sequences, strings, numbers, booleans, nil
  • Strings with special chars (:, #, leading spaces) must be quoted
  • Indentation: 2 spaces (consistent with existing fixtures)
  • Key order: alphabetical (deterministic output for git diffs)
  • No dependency on lyaml -- pure Lua implementation required
  • If lyaml is present, may use it as Tier 1 (same 2-tier pattern as load)

Out of scope

  • Anchors, aliases, multi-document
  • Block scalars (|, >)
  • Preserving input key order

Interface

local yaml = require("daw.lua.common.yaml")
local out = yaml.dump(table)  -- returns string

Tests

Extend test/test_yaml.lua:

  • Round-trip: dump(load(fixture)) produces equivalent structure
  • Special string quoting
  • Nested maps and sequences
  • Boolean and number output

Refs

  • Needed by: DAW/steurjan#16 (IN adapter writes journal YAMLs)
  • Schema: docs/schemas/transaction_context.md, docs/schemas/decision_snapshot.md
## Summary `yaml.lua` has `load()` and `load_file()` but no serialization. steurjan needs to write `transaction_context/v2` and `decision_snapshot/v2` as YAML files to the journal. Without `dump()`, every project that writes YAML would need its own serializer. ## Scope Add `yaml.dump(table)` to `src/daw/lua/common/yaml.lua`. ## Requirements - Output must be valid YAML 1.1 (readable by the existing `load()`) - Support: nested maps, sequences, strings, numbers, booleans, nil - Strings with special chars (`:`, `#`, leading spaces) must be quoted - Indentation: 2 spaces (consistent with existing fixtures) - Key order: alphabetical (deterministic output for git diffs) - No dependency on lyaml -- pure Lua implementation required - If lyaml is present, may use it as Tier 1 (same 2-tier pattern as load) ## Out of scope - Anchors, aliases, multi-document - Block scalars (`|`, `>`) - Preserving input key order ## Interface ```lua local yaml = require("daw.lua.common.yaml") local out = yaml.dump(table) -- returns string ``` ## Tests Extend `test/test_yaml.lua`: - Round-trip: `dump(load(fixture))` produces equivalent structure - Special string quoting - Nested maps and sequences - Boolean and number output ## Refs - Needed by: DAW/steurjan#16 (IN adapter writes journal YAMLs) - Schema: docs/schemas/transaction_context.md, docs/schemas/decision_snapshot.md
Author
Owner

Implemented in yaml/dump.lua (pure-Lua tier) and wired into yaml/init.lua's Tier-1 lyaml.dump() path. Alphabetical key order, 2-space indent, string quoting for special chars, round-trip verified (dump(load(x)) equivalent structure).

Implemented in yaml/dump.lua (pure-Lua tier) and wired into yaml/init.lua's Tier-1 lyaml.dump() path. Alphabetical key order, 2-space indent, string quoting for special chars, round-trip verified (dump(load(x)) equivalent structure).
michael 2026-07-19 17:56:10 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
DAW/daw-lua-common#5
No description provided.