Metadata assertions¶
PostProject stores metadata as assertions about an object. Each assertion has three distinct parts:
vocabulary + property + typed value
The vocabulary identifies who defines the term. The property identifies the term inside that vocabulary. The value carries the data without collapsing its type into plain text. This design lets PostProject retain standardized and application-specific metadata without inventing a broad media vocabulary of its own.
An assertion can target a production, asset, representation, resource, activity, or job. Metadata is not copied automatically between these identity levels.
Repetition and structure¶
A property may have several independently ordered assertions. For example, two keywords are two values of the same property. A list is instead one value whose contents are ordered. PostProject preserves that distinction.
Values can be:
plain or language-tagged text;
signed and unsigned integers, exact decimal or rational numbers, and booleans;
timestamps and URIs;
opaque bytes;
ordered lists and ordered named structures;
references to PostProject objects.
Floating-point numbers and unconstrained JSON are not canonical persisted forms. The SQLite backend uses a private, deterministic, versioned binary encoding.
Unknown terms¶
Core does not require a vocabulary package to retain a property. Unknown vocabulary and property identifiers round-trip exactly. A future registry may add labels, cardinality hints, expected types, or validation, but absence of that registry must not discard data.
Safety limits¶
Values are validated before persistence. Current limits include 32 nested levels, 4,096 direct list items or structure fields, one mebibyte per text value, 15 mebibytes per binary or aggregate payload, and a bounded decimal scale. Stored encodings are decoded as untrusted input; invalid tags, lengths, UTF-8, URIs, language tags, object kinds, truncation, and trailing bytes return errors rather than panicking.
Across public surfaces¶
This example writes a language-tagged title and reads it through both object and property-oriented views:
static const char *const IPTC_VIDEO_METADATA_HUB =
"https://iptc.org/std/videometadatahub/recommendation/"
"iptc-vmhub-1.7-schema.json";
static pp_error_code_t add_title(pp_production_t *production,
const pp_asset_id_t *asset_id,
pp_error_t **error) {
pp_object_ref_t target;
pp_error_code_t reference_status = pp_object_ref_from_asset(*asset_id, &target, error);
if (reference_status != PP_OK) return reference_status;
pp_metadata_input_t *title = NULL;
pp_transaction_t *transaction = NULL;
pp_metadata_set_t *on_asset = NULL;
pp_metadata_set_t *everywhere = NULL;
pp_error_code_t status =
pp_metadata_input_create_string("Interview", "en-US", &title, error);
if (status == PP_OK) {
status = pp_production_begin_edit(production, NULL, NULL, &transaction, error);
}
if (status == PP_OK) {
status = pp_transaction_add_metadata_value(
transaction, &target, IPTC_VIDEO_METADATA_HUB, "title", title, error);
}
if (status == PP_OK) {
pp_commit_receipt_t commit_receipt;
status = pp_transaction_commit(transaction, &commit_receipt, error);
}
if (status == PP_OK) {
status = pp_production_metadata(production, &target, &on_asset, error);
}
if (status == PP_OK) {
status = pp_production_find_metadata(production, IPTC_VIDEO_METADATA_HUB,
"title", &everywhere, error);
}
for (uint64_t index = 0;
status == PP_OK && index < pp_metadata_set_count(on_asset); ++index) {
pp_object_ref_t owner;
const char *vocabulary = NULL;
const char *property = NULL;
const pp_metadata_value_t *value = NULL;
const char *text = NULL;
const char *language = NULL;
status = pp_metadata_set_get(on_asset, index, &owner, &vocabulary,
&property, &value, error);
if (status == PP_OK &&
pp_metadata_value_kind(value) == PP_METADATA_LANG_STRING) {
status = pp_metadata_value_get_string(value, &text, &language, error);
if (status == PP_OK) {
printf("%s: %s [%s]\n", property, text, language);
}
}
}
pp_metadata_set_release(everywhere);
pp_metadata_set_release(on_asset);
pp_transaction_release(transaction);
pp_metadata_input_release(title);
return status;
}
void add_title(postproject::Production &production,
const postproject::AssetId &asset_id) {
const postproject::ObjectRef target = postproject::ObjectRef::asset(asset_id);
auto transaction = production.edit().value();
transaction.addMetadataValue(
target,
"https://iptc.org/std/videometadatahub/recommendation/"
"iptc-vmhub-1.7-schema.json",
"title", postproject::MetadataValue::languageString("Interview", "en-US")).value();
transaction.commit().value();
// Read one target's assertions with the C function pp_production_metadata().
}
def add_title(production: Production, asset_id: AssetId) -> None:
title = MetadataProperty(
"https://iptc.org/std/videometadatahub/recommendation/iptc-vmhub-1.7-schema.json",
"title",
)
with production.edit() as transaction:
transaction.add_metadata(
AssetRef(asset_id), title, MetadataLanguageString("Interview", "en-US")
)
transaction.commit()
for assertion in production.metadata[AssetRef(asset_id)]:
print(f"{assertion.property.property}: {assertion.value}")
assert len(production.metadata_by_property[title]) == 1
fn add_title(production: &mut SqliteProduction, asset_id: AssetId) -> Result<()> {
let title = MetadataProperty::new(
VocabularyId::new(
"https://iptc.org/std/videometadatahub/recommendation/iptc-vmhub-1.7-schema.json",
)?,
PropertyId::new("title")?,
);
let target = ObjectRef::Asset(asset_id);
{
let mut transaction = production.begin_transaction()?;
transaction.add_metadata_value(
target,
&title,
&MetadataValue::language_string("Interview", "en-US")?,
)?;
transaction.commit()?;
}
let on_asset = production.metadata(target)?;
let everywhere = production.query_by_metadata_property(&title)?;
assert_eq!(on_asset.len(), 1);
assert_eq!(everywhere.len(), 1);
Ok(())
}
IPTC_VMHUB=https://iptc.org/std/videometadatahub/recommendation/iptc-vmhub-1.7-schema.json
postproject metadata add-text production.pproj asset "$ASSET_ID" \
"$IPTC_VMHUB" title "Interview" --language en-US
postproject metadata list production.pproj asset "$ASSET_ID"
postproject metadata find production.pproj "$IPTC_VMHUB" title
Every value kind round-trips with its type, including nested lists, structures, and object references:
static const char *const EDITORIAL = "https://example.com/ns/editorial/1";
enum { VALUE_COUNT = 13 };
static pp_error_code_t add_typed_values(pp_production_t *production,
const pp_asset_id_t *asset_id,
const pp_representation_id_t *representation_id,
pp_error_t **error) {
static const uint8_t thumbnail[] = {0x89, 0x50, 0x4e, 0x47};
pp_object_ref_t target;
pp_error_code_t reference_status = pp_object_ref_from_asset(*asset_id, &target, error);
if (reference_status != PP_OK) return reference_status;
pp_object_ref_t source;
reference_status = pp_object_ref_from_representation(*representation_id, &source, error);
if (reference_status != PP_OK) return reference_status;
const char *const properties[VALUE_COUNT] = {
"slate", "title", "offset", "frame-count", "gain",
"approved", "reviewed-at", "homepage", "thumbnail", "frame-rate",
"keywords", "camera", "source"};
pp_metadata_input_t *values[VALUE_COUNT] = {NULL};
pp_metadata_input_t *keyword[2] = {NULL, NULL};
pp_metadata_input_t *field[2] = {NULL, NULL};
pp_transaction_t *transaction = NULL;
pp_error_code_t status =
pp_metadata_input_create_string("A001 T3", NULL, &values[0], error);
if (status == PP_OK) {
/* A language tag makes this a language string. */
status = pp_metadata_input_create_string("Interview", "en-US", &values[1],
error);
}
if (status == PP_OK) {
status = pp_metadata_input_create_i64(-12, &values[2], error);
}
if (status == PP_OK) {
status = pp_metadata_input_create_u64(2400, &values[3], error);
}
if (status == PP_OK) {
/* Decimals are exact: coefficient 325 with scale 2 is 3.25. */
status = pp_metadata_input_create_decimal("325", 2, &values[4], error);
}
if (status == PP_OK) {
status = pp_metadata_input_create_bool(1, &values[5], error);
}
if (status == PP_OK) {
status = pp_metadata_input_create_timestamp(INT64_C(1767225600000000),
&values[6], error);
}
if (status == PP_OK) {
status = pp_metadata_input_create_uri("https://example.com/interviews/3",
&values[7], error);
}
if (status == PP_OK) {
status = pp_metadata_input_create_bytes(thumbnail, sizeof thumbnail,
&values[8], error);
}
if (status == PP_OK) {
status = pp_metadata_input_create_rational(24000, 1001, &values[9], error);
}
if (status == PP_OK) {
status =
pp_metadata_input_create_string("interview", NULL, &keyword[0], error);
}
if (status == PP_OK) {
status =
pp_metadata_input_create_string("exterior", NULL, &keyword[1], error);
}
if (status == PP_OK) {
/* Collections copy their children, which stay owned by the caller. */
const pp_metadata_input_t *items[] = {keyword[0], keyword[1]};
status = pp_metadata_input_create_list(items, 2, &values[10], error);
}
if (status == PP_OK) {
status = pp_metadata_input_create_string("ARRI", NULL, &field[0], error);
}
if (status == PP_OK) {
status = pp_metadata_input_create_u64(800, &field[1], error);
}
if (status == PP_OK) {
const char *names[] = {"make", "iso"};
const pp_metadata_input_t *fields[] = {field[0], field[1]};
status =
pp_metadata_input_create_struct(names, fields, 2, &values[11], error);
}
if (status == PP_OK) {
status = pp_metadata_input_create_reference(&source, &values[12], error);
}
if (status == PP_OK) {
status = pp_production_begin_edit(production, NULL, NULL, &transaction, error);
}
for (int i = 0; status == PP_OK && i < VALUE_COUNT; ++i) {
status = pp_transaction_add_metadata_value(transaction, &target, EDITORIAL,
properties[i], values[i], error);
}
if (status == PP_OK) {
pp_commit_receipt_t commit_receipt;
status = pp_transaction_commit(transaction, &commit_receipt, error);
}
pp_transaction_release(transaction);
for (int i = 0; i < 2; ++i) {
pp_metadata_input_release(field[i]);
pp_metadata_input_release(keyword[i]);
}
for (int i = 0; i < VALUE_COUNT; ++i) {
pp_metadata_input_release(values[i]);
}
return status;
}
static pp_error_code_t print_value(const pp_metadata_value_t *value,
uint32_t *seen_kinds, pp_error_t **error) {
const pp_metadata_value_kind_t kind = pp_metadata_value_kind(value);
pp_error_code_t status = PP_OK;
*seen_kinds |= kind < 32 ? UINT32_C(1) << kind : 0;
switch (kind) {
case PP_METADATA_STRING:
case PP_METADATA_LANG_STRING: {
const char *text, *language;
status = pp_metadata_value_get_string(value, &text, &language, error);
if (status == PP_OK) {
printf("\"%s\"%s%s", text, language != NULL ? "@" : "",
language != NULL ? language : "");
}
break;
}
case PP_METADATA_I64: {
int64_t number = 0;
status = pp_metadata_value_get_i64(value, &number, error);
if (status == PP_OK) {
printf("%lld", (long long)number);
}
break;
}
case PP_METADATA_U64: {
uint64_t number = 0;
status = pp_metadata_value_get_u64(value, &number, error);
if (status == PP_OK) {
printf("%llu", (unsigned long long)number);
}
break;
}
case PP_METADATA_DECIMAL: {
const char *coefficient;
uint32_t scale = 0;
status = pp_metadata_value_get_decimal(value, &coefficient, &scale, error);
if (status == PP_OK) {
printf("%se-%u", coefficient, scale);
}
break;
}
case PP_METADATA_BOOL: {
uint8_t flag = 0;
status = pp_metadata_value_get_bool(value, &flag, error);
if (status == PP_OK) {
printf("%s", flag ? "true" : "false");
}
break;
}
case PP_METADATA_TIMESTAMP: {
int64_t micros = 0;
status = pp_metadata_value_get_timestamp(value, µs, error);
if (status == PP_OK) {
printf("%lld us since 1970", (long long)micros);
}
break;
}
case PP_METADATA_URI: {
const char *uri;
status = pp_metadata_value_get_uri(value, &uri, error);
if (status == PP_OK) {
printf("<%s>", uri);
}
break;
}
case PP_METADATA_BYTES: {
const uint8_t *bytes;
uint64_t length = 0;
status = pp_metadata_value_get_bytes(value, &bytes, &length, error);
if (status == PP_OK) {
printf("%llu bytes", (unsigned long long)length);
}
break;
}
case PP_METADATA_RATIONAL: {
int64_t numerator = 0;
uint64_t denominator = 0;
status =
pp_metadata_value_get_rational(value, &numerator, &denominator, error);
if (status == PP_OK) {
printf("%lld/%llu", (long long)numerator,
(unsigned long long)denominator);
}
break;
}
case PP_METADATA_LIST: {
printf("[");
for (uint64_t i = 0;
status == PP_OK && i < pp_metadata_value_list_count(value); ++i) {
const pp_metadata_value_t *item;
status = pp_metadata_value_list_get(value, i, &item, error);
if (status == PP_OK) {
printf("%s", i > 0 ? ", " : "");
status = print_value(item, seen_kinds, error);
}
}
printf("]");
break;
}
case PP_METADATA_STRUCT: {
printf("{");
for (uint64_t i = 0;
status == PP_OK && i < pp_metadata_value_struct_count(value); ++i) {
const char *name;
const pp_metadata_value_t *field;
status = pp_metadata_value_struct_get(value, i, &name, &field, error);
if (status == PP_OK) {
printf("%s%s: ", i > 0 ? ", " : "", name);
status = print_value(field, seen_kinds, error);
}
}
printf("}");
break;
}
case PP_METADATA_REFERENCE: {
pp_object_ref_t reference;
status = pp_metadata_value_get_reference(value, &reference, error);
if (status == PP_OK) {
printf("object of kind %u", reference.kind);
}
break;
}
default:
/* Newer libraries may add kinds; skip what this host does not know. */
printf("(unknown kind %u)", kind);
break;
}
return status;
}
static pp_error_code_t print_typed_values(const pp_production_t *production,
const pp_asset_id_t *asset_id,
uint32_t *out_seen_kinds,
pp_error_t **error) {
pp_object_ref_t target;
pp_error_code_t reference_status = pp_object_ref_from_asset(*asset_id, &target, error);
if (reference_status != PP_OK) return reference_status;
pp_metadata_set_t *metadata = NULL;
pp_error_code_t status =
pp_production_metadata(production, &target, &metadata, error);
for (uint64_t i = 0; status == PP_OK && i < pp_metadata_set_count(metadata);
++i) {
pp_object_ref_t owner;
const char *vocabulary, *property;
const pp_metadata_value_t *value;
status = pp_metadata_set_get(metadata, i, &owner, &vocabulary, &property,
&value, error);
if (status == PP_OK && strcmp(vocabulary, EDITORIAL) == 0) {
printf("%s: ", property);
status = print_value(value, out_seen_kinds, error);
printf("\n");
}
}
pp_metadata_set_release(metadata);
return status;
}
static pp_error_code_t count_values_by_page(const pp_production_t *production,
const char *property,
uint64_t *out_count,
pp_error_t **error) {
char cursor_storage[2049] = {0};
const char *cursor = NULL;
pp_error_code_t status = PP_OK;
*out_count = 0;
while (status == PP_OK) {
pp_metadata_set_t *page = NULL;
/* A NULL exact value matches every value of the property. */
status = pp_production_query_metadata(production, EDITORIAL, property, NULL,
UINT32_C(1), cursor, &page, error);
*out_count += status == PP_OK ? pp_metadata_set_count(page) : 0;
const char *next =
status == PP_OK ? pp_metadata_set_next_cursor(page) : NULL;
const int copied =
next != NULL
? snprintf(cursor_storage, sizeof cursor_storage, "%s", next)
: 0;
pp_metadata_set_release(page);
if (status != PP_OK || copied == 0) {
break;
}
if (copied < 0 || (size_t)copied >= sizeof cursor_storage) {
status = PP_ERROR_INTERNAL;
}
cursor = cursor_storage;
}
return status;
}
constexpr const char *editorial = "https://example.com/ns/editorial/1";
void add_editorial_metadata(postproject::Production &production,
const postproject::AssetId &asset_id,
const postproject::RepresentationId &representation_id) {
using postproject::MetadataValue;
const postproject::ObjectRef asset = postproject::ObjectRef::asset(asset_id);
std::vector<MetadataValue> keywords;
keywords.push_back(MetadataValue::plainString("interview"));
keywords.push_back(MetadataValue::plainString("exterior"));
std::vector<postproject::MetadataField> slate;
slate.push_back({"scene", MetadataValue::plainString("12A")});
slate.push_back({"take", MetadataValue::unsignedInteger(3)});
auto transaction = production.edit().value();
const auto add = [&](const char *property, const MetadataValue &value) {
transaction.addMetadataValue(asset, editorial, property, value).value();
};
add("title", MetadataValue::plainString("Harbour interview"));
add("caption", MetadataValue::languageString("Am Hafen", "de-DE"));
add("timecode-offset", MetadataValue::signedInteger(-48));
add("frame-count", MetadataValue::unsignedInteger(86400));
add("aspect-ratio", MetadataValue::decimal("239", 2)); // 2.39
add("circled", MetadataValue::boolean(true));
add("shot-at", MetadataValue::timestamp(1'700'000'000'000'000));
add("licence", MetadataValue::uri("https://example.com/licences/7"));
add("checksum", MetadataValue::bytes({0xde, 0xad, 0xbe, 0xef}));
add("frame-rate", MetadataValue::rational(24000, 1001));
add("keywords", MetadataValue::list(keywords));
add("slate", MetadataValue::structure(slate));
add("preferred-representation",
MetadataValue::reference(
postproject::ObjectRef::representation(representation_id)));
transaction.commit().value();
}
std::map<std::string, std::size_t>
count_editorial_values(const postproject::Production &production,
const std::vector<std::string> &properties) {
std::map<std::string, std::size_t> counts;
for (const auto &property : properties) {
// Follow next_cursor until the query is exhausted.
std::optional<std::string> cursor;
do {
const auto page =
production.queryMetadata(editorial, property, 1, cursor).value();
counts[property] += page.items.size();
cursor = page.next_cursor;
} while (cursor.has_value());
}
// Values come back as MetadataValue objects: read them, pass one to an
// exact-value query, or copy it onto another target.
const auto frame_rate = production.queryMetadata(
editorial, "frame-rate",
postproject::MetadataValue::rational(24000, 1001), 10).value();
std::cout << "assets shot at 23.976 fps: " << frame_rate.items.size() << '\n';
const auto keywords =
production.queryMetadata(editorial, "keywords", 1).value();
if (const auto *list =
keywords.items.front().value.getIf<postproject::MetadataList>()) {
for (const auto &item : list->items) {
std::cout << "keyword: "
<< item.getIf<postproject::MetadataString>()->value << '\n';
}
}
const auto slate = production.queryMetadata(editorial, "slate", 1).value();
std::visit(
[](const auto &value) {
using Value = std::decay_t<decltype(value)>;
if constexpr (std::is_same_v<Value, postproject::MetadataStructure>) {
std::cout << "slate has " << value.fields.size() << " fields\n";
}
},
slate.items.front().value.variant());
return counts;
}
def add_editorial_metadata(
production: Production, asset_id: AssetId, original_id: RepresentationId
) -> None:
values: dict[str, MetadataInput] = {
"title": "Interview",
"headline": MetadataLanguageString("Gespräch am Morgen", "de"),
"reel-offset": -48,
"take-count": MetadataU64(3),
"gain-db": MetadataDecimal(coefficient=-125, scale=1), # -12.5
"approved": True,
"shot-at": MetadataTimestamp(1_700_000_000_000_000),
"script": MetadataUri("https://example.com/scripts/ep1"),
"thumbnail": b"\x89PNG",
"frame-rate": Fraction(24_000, 1_001),
"keywords": (("interview", "exterior")),
"lens": MetadataStruct(
(
MetadataStructField("model", "Example 35mm"),
MetadataStructField("focal-length-mm", MetadataU64(35)),
)
),
"selected-take": MetadataReference(RepresentationRef(original_id)),
}
with production.edit() as transaction:
for name, value in values.items():
transaction.add_metadata(AssetRef(asset_id), (EDITORIAL, name), value)
transaction.commit()
def describe(value: MetadataInput) -> str:
match value:
case str(text):
return text
case bool() | int() | bytes() | Fraction():
return repr(value)
case MetadataUri(text):
return text
case MetadataLanguageString(text, language):
return f"{text} @{language}"
case MetadataU64(number):
return str(number)
case MetadataDecimal(coefficient, scale):
return f"{coefficient}e-{scale}"
case MetadataTimestamp(unix_micros):
return f"{unix_micros} µs since the Unix epoch"
case tuple(items) | list(items):
return "[" + ", ".join(describe(item) for item in items) + "]"
case MetadataStruct(fields):
return (
"{" + ", ".join(f"{f.name}: {describe(f.value)}" for f in fields) + "}"
)
case MetadataReference(target):
return f"-> {target}"
raise TypeError("unsupported metadata value")
def print_metadata(production: Production, target: ObjectReference) -> None:
for assertion in production.metadata[target]:
print(f"{assertion.property.property} = {describe(assertion.value)}")
def find_approved(production: Production) -> list[ObjectReference]:
approved = MetadataProperty(EDITORIAL, "approved")
targets: list[ObjectReference] = []
cursor = None
while True:
# Pass the same property, value, and limit with each cursor.
page = production.query_metadata(approved, limit=1, cursor=cursor, value=(True))
targets.extend(assertion.target for assertion in page.items)
cursor = page.next_cursor
if cursor is None:
return targets
fn editorial(property: &str) -> Result<MetadataProperty> {
Ok(MetadataProperty::new(
VocabularyId::new("https://example.com/ns/editorial/1")?,
PropertyId::new(property)?,
))
}
fn add_typed_metadata(
production: &mut SqliteProduction,
asset_id: AssetId,
original_id: RepresentationId,
) -> Result<()> {
let values = [
("slate", MetadataValue::string("12A/3")?),
(
"title",
MetadataValue::language_string("Interview", "en-US")?,
),
("offset", MetadataValue::i64(-48)),
("take", MetadataValue::u64(3)),
(
"exposure",
MetadataValue::decimal(DecimalValue::new(125, 2)?),
),
("circled", MetadataValue::boolean(true)),
(
"shot-at",
MetadataValue::timestamp(Timestamp::from_unix_micros(1_700_000_000_000_000)),
),
(
"script",
MetadataValue::uri("https://example.com/scripts/12")?,
),
(
"thumbnail-hash",
MetadataValue::bytes(vec![0xde, 0xad, 0xbe, 0xef])?,
),
(
"rate",
MetadataValue::rational(RationalValue::new(24000, 1001)?),
),
(
"keywords",
MetadataValue::list(vec![
MetadataValue::string("interview")?,
MetadataValue::string("exterior")?,
])?,
),
(
"lens",
MetadataValue::structure(vec![
MetadataField::new(PropertyId::new("model")?, MetadataValue::string("35mm")?),
MetadataField::new(PropertyId::new("t-stop")?, MetadataValue::u64(2)),
])?,
),
(
"selected-take",
MetadataValue::reference(ObjectRef::Representation(original_id)),
),
];
let target = ObjectRef::Asset(asset_id);
let mut transaction = production.begin_transaction()?;
for (property, value) in &values {
transaction.add_metadata_value(target, &editorial(property)?, value)?;
}
transaction.commit()?;
drop(transaction);
for assertion in production.metadata(target)? {
let property = assertion.property().property().as_str();
println!("{property}: {}", describe(assertion.value()));
}
Ok(())
}
fn describe(value: &MetadataValue) -> String {
match value.kind() {
MetadataValueKind::String => format!("{:?}", value.as_string()),
MetadataValueKind::LangString => format!("{:?}", value.as_language_string()),
MetadataValueKind::I64 => format!("{:?}", value.as_i64()),
MetadataValueKind::U64 => format!("{:?}", value.as_u64()),
MetadataValueKind::Decimal => format!("{:?}", value.as_decimal()),
MetadataValueKind::Bool => format!("{:?}", value.as_bool()),
MetadataValueKind::Timestamp => format!("{:?}", value.as_timestamp()),
MetadataValueKind::Uri => format!("{:?}", value.as_uri()),
MetadataValueKind::Bytes => format!("{:?}", value.as_bytes()),
MetadataValueKind::Rational => format!("{:?}", value.as_rational()),
MetadataValueKind::List => {
let items = value.as_list().unwrap_or_default();
let items: Vec<String> = items.iter().map(describe).collect();
format!("[{}]", items.join(", "))
}
MetadataValueKind::Struct => {
let fields = value.as_structure().unwrap_or_default();
let fields: Vec<String> = fields
.iter()
.map(|field| format!("{}: {}", field.name().as_str(), describe(field.value())))
.collect();
format!("{{{}}}", fields.join(", "))
}
MetadataValueKind::Reference => format!("{:?}", value.as_reference()),
// New value types may be added; preserve what cannot be interpreted.
_ => "unsupported value type".to_owned(),
}
}
fn objects_with_slate(production: &SqliteProduction) -> Result<Vec<ObjectRef>> {
let query = MetadataQuery::new(editorial("slate")?, None)?;
let mut objects = Vec::new();
let mut cursor = None;
loop {
let page = production.metadata_query(&query, &QueryPageRequest::new(1, cursor)?)?;
objects.extend(page.items().iter().map(MetadataMatch::target));
cursor = page.next_cursor().cloned();
if cursor.is_none() {
return Ok(objects);
}
}
}
EDITORIAL=https://example.com/ns/editorial/1
mkdir -p values
# One JSON value file per property; "type" selects the metadata value type.
cat > values/slug.json <<'EOF'
{"type": "string", "value": "INT-001"}
EOF
cat > values/title.json <<'EOF'
{"type": "lang_string", "value": "Interview", "language": "en-US"}
EOF
cat > values/offset.json <<'EOF'
{"type": "i64", "value": -12}
EOF
cat > values/take.json <<'EOF'
{"type": "u64", "value": 3}
EOF
cat > values/gain.json <<'EOF'
{"type": "decimal", "coefficient": "-35", "scale": 1}
EOF
cat > values/approved.json <<'EOF'
{"type": "bool", "value": true}
EOF
cat > values/shot-at.json <<'EOF'
{"type": "timestamp", "unix_micros": 1767225600000000}
EOF
cat > values/homepage.json <<'EOF'
{"type": "uri", "value": "https://example.com/interview"}
EOF
cat > values/checksum.json <<'EOF'
{"type": "bytes", "hex": "00ff10"}
EOF
cat > values/rate.json <<'EOF'
{"type": "rational", "numerator": 24000, "denominator": 1001}
EOF
cat > values/keywords.json <<'EOF'
{"type": "list", "values": [
{"type": "string", "value": "interview"},
{"type": "string", "value": "exterior"}
]}
EOF
cat > values/camera.json <<'EOF'
{"type": "struct", "fields": [
{"name": "model", "value": {"type": "string", "value": "A-Cam"}},
{"name": "iso", "value": {"type": "u64", "value": 800}}
]}
EOF
cat > values/source.json <<EOF
{"type": "reference",
"target": {"target_kind": "representation", "target_id": "$ORIGINAL_ID"}}
EOF
for VALUE_FILE in values/*.json; do
postproject metadata add knowledge.pproj asset "$ASSET_ID" "$EDITORIAL" \
"$(basename "$VALUE_FILE" .json)" "$VALUE_FILE"
done
postproject --json metadata list knowledge.pproj asset "$ASSET_ID" |
jq -r '.[] | .property + ": " + (.value | if .type == "lang_string" then
"\(.value) (\(.language))"
elif .type == "decimal" then "\(.coefficient)e-\(.scale)"
elif .type == "timestamp" then "\(.unix_micros) us"
elif .type == "bytes" then "0x\(.hex)"
elif .type == "rational" then "\(.numerator)/\(.denominator)"
elif .type == "list" then [.values[].value] | join(", ")
elif .type == "struct" then [.fields[] | "\(.name)=\(.value.value)"] | join(", ")
elif .type == "reference" then "\(.target.kind) \(.target.id)"
else .value | tostring end)'
# Metadata queries are paged; follow next_cursor until it is null.
CURSOR=
while :; do
ARGS=(--json metadata find knowledge.pproj "$EDITORIAL" take --limit 1)
[[ -n "$CURSOR" ]] && ARGS+=(--cursor "$CURSOR")
PAGE=$(postproject "${ARGS[@]}")
jq -r '.items[] | "\(.target_kind) \(.target_id) take \(.value.value)"' <<<"$PAGE"
CURSOR=$(jq -r '.next_cursor // empty' <<<"$PAGE")
[[ -z "$CURSOR" ]] && break
done