|
| 1 | +# Metadata Editing |
| 2 | + |
| 3 | +`openmeta/metadata_editing.h` provides a bounded transactional editing contract |
| 4 | +for the same logical fields accepted by the high-level Creation API. It edits |
| 5 | +canonical portable-XMP entries in a finalized `MetaStore` without requiring a |
| 6 | +host to work with namespace paths or entry IDs. |
| 7 | + |
| 8 | +The API is experimental and versioned by |
| 9 | +`kMetadataEditingContractVersion == 1`. |
| 10 | + |
| 11 | +## C++ Example |
| 12 | + |
| 13 | +```cpp |
| 14 | +#include "openmeta/metadata_editing.h" |
| 15 | + |
| 16 | +#include <array> |
| 17 | + |
| 18 | +const std::array operations = { |
| 19 | + openmeta::make_metadata_edit_set( |
| 20 | + openmeta::make_metadata_creation_text( |
| 21 | + openmeta::MetadataCreationFieldKind::Title, "Edited title")), |
| 22 | + openmeta::make_metadata_edit_add( |
| 23 | + openmeta::make_metadata_creation_text( |
| 24 | + openmeta::MetadataCreationFieldKind::Keyword, "approved")), |
| 25 | + openmeta::make_metadata_edit_remove( |
| 26 | + openmeta::MetadataCreationFieldKind::Creator, 0), |
| 27 | +}; |
| 28 | + |
| 29 | +openmeta::MetadataEditingRequest request; |
| 30 | +request.operations = operations; |
| 31 | + |
| 32 | +openmeta::MetaStore edited; |
| 33 | +const openmeta::MetadataEditingResult result = |
| 34 | + openmeta::edit_metadata(source, request, &edited); |
| 35 | +``` |
| 36 | +
|
| 37 | +`source` must be finalized. The output is replaced only after every operation |
| 38 | +has passed validation and the entire edit has committed. On failure, `edited` |
| 39 | +is unchanged and `failed_operation_index` identifies the rejected operation |
| 40 | +when available. |
| 41 | +
|
| 42 | +## Operation Semantics |
| 43 | +
|
| 44 | +| Operation | Behavior | |
| 45 | +| --- | --- | |
| 46 | +| `Add` | Creates an absent singleton or appends a creator/keyword value. Adding an existing singleton is an explicit conflict. | |
| 47 | +| `Set` | Replaces one active value. Existing key, origin, block, wire provenance, and flags are preserved; `Dirty` is added. | |
| 48 | +| `Remove` | Marks one active value as `Deleted | Dirty`. The tombstone remains available for writeback and audit behavior. | |
| 49 | +| `RemoveAll` | Tombstones every active occurrence. This can repair malformed duplicate singleton fields before a new value is added in the same transaction. | |
| 50 | +
|
| 51 | +Operations observe earlier operations in request order. For repeated creators |
| 52 | +and keywords, `occurrence` is a zero-based index into the current active |
| 53 | +logical values. Removing an occurrence shifts later values for subsequent |
| 54 | +operations. New repeated values receive the next unused canonical property |
| 55 | +index; existing index gaps are not renumbered. |
| 56 | +
|
| 57 | +Singleton fields accept only occurrence zero. If a malformed store contains |
| 58 | +multiple active copies, single-value `Set` and `Remove` return |
| 59 | +`AmbiguousTarget`; use `RemoveAll` followed by `Add` when that repair is |
| 60 | +intended. Missing targets are errors rather than silent no-ops. |
| 61 | +
|
| 62 | +## Provenance And Blocks |
| 63 | +
|
| 64 | +`Set` changes only the value and dirty flag. `Remove` changes only entry flags. |
| 65 | +Both therefore retain the original block and wire provenance. |
| 66 | +
|
| 67 | +`Add` emits a new dirty canonical portable-XMP entry. When the store already |
| 68 | +contains an XMP entry with a valid block, the new entry uses that block and a |
| 69 | +later deterministic order. A finalized empty store can also be edited; its new |
| 70 | +entry has no source block because no original carrier exists. Portable XMP and |
| 71 | +transfer preparation can serialize that entry normally. |
| 72 | +
|
| 73 | +Editing does not compact tombstones automatically. Call the lower-level |
| 74 | +`compact(...)` helper only when losing deleted-entry identity is appropriate |
| 75 | +for the host workflow. |
| 76 | +
|
| 77 | +## Validation And Limits |
| 78 | +
|
| 79 | +`Add` and `Set` use exactly the Creation field mapping and value validation. |
| 80 | +Text must be non-empty valid UTF-8 and XML 1.0 character data. Orientation, |
| 81 | +rating, dimensions, color space, ISO, and rational values use the constraints |
| 82 | +documented in [creation.md](creation.md). |
| 83 | +
|
| 84 | +The hard maxima are: |
| 85 | +
|
| 86 | +- `1024` operations |
| 87 | +- `1 MiB` of UTF-8 text per `Add` or `Set` operation |
| 88 | +- `8 MiB` of UTF-8 text per request |
| 89 | +
|
| 90 | +`MetadataEditingRequest::limits` may lower but not raise these bounds. The |
| 91 | +implementation keeps no global state. Concurrent calls are safe when callers |
| 92 | +use distinct output stores and do not mutate the finalized source. |
| 93 | +
|
| 94 | +## Python |
| 95 | +
|
| 96 | +Python operation objects own their text and pass the same request to C++: |
| 97 | +
|
| 98 | +```python |
| 99 | +import openmeta |
| 100 | +
|
| 101 | +K = openmeta.MetadataCreationFieldKind |
| 102 | +edited = document.edit_metadata([ |
| 103 | + openmeta.metadata_edit_set( |
| 104 | + openmeta.metadata_creation_text(K.Title, "Edited title")), |
| 105 | + openmeta.metadata_edit_add( |
| 106 | + openmeta.metadata_creation_text(K.Keyword, "approved")), |
| 107 | + openmeta.metadata_edit_remove(K.Creator, 0), |
| 108 | +]) |
| 109 | +``` |
| 110 | + |
| 111 | +The method returns a detached edited `Document`; the original document is not |
| 112 | +mutated. The result can be queried, dumped as XMP, or converted into a transfer |
| 113 | +snapshot. Invalid requests raise `ValueError` with the C++ status and rejected |
| 114 | +operation index. |
| 115 | + |
| 116 | +## Current Scope |
| 117 | + |
| 118 | +This milestone edits the 24 logical fields listed in |
| 119 | +[creation.md](creation.md). It does not yet provide high-level arbitrary |
| 120 | +EXIF/IPTC/XMP/custom-key operations, language-alternative selection beyond |
| 121 | +`x-default`, structural block editing, a full EXIF/IPTC/XMP synchronization |
| 122 | +engine, or direct in-place file patching. Lower-level `MetaEdit` remains |
| 123 | +available for entry-ID-based host code, while transfer and writer APIs handle |
| 124 | +container persistence. |
0 commit comments