External identifiers¶
Attach an industry, vendor, or application identifier to a PostProject object when another system needs to find that object by its own key. An identifier is a scheme, value, and optional qualifier; PostProject stores all three exactly as supplied and never rewrites or normalizes them.
The example attaches a camera serial number to an asset, reads the identifiers attached to that asset, and finds every object carrying the exact scheme and value:
static pp_error_code_t tag_camera_serial(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_transaction_t *transaction = NULL;
pp_external_identifier_set_t *attached = NULL;
pp_object_ref_set_t *matches = NULL;
pp_error_code_t status =
pp_production_begin_edit(production, NULL, NULL, &transaction, error);
if (status == PP_OK) {
status = pp_transaction_add_external_identifier(
transaction, &target, "com.example.camera.serial", "A-0007", NULL,
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_external_identifiers(production, &target,
&attached, error);
}
if (status == PP_OK) {
status = pp_production_find_by_external_identifier(
production, "com.example.camera.serial", "A-0007", NULL, &matches,
error);
}
if (status == PP_OK) {
printf("identifiers: %llu, matching objects: %llu\n",
(unsigned long long)pp_external_identifier_set_count(attached),
(unsigned long long)pp_object_ref_set_count(matches));
}
pp_object_ref_set_release(matches);
pp_external_identifier_set_release(attached);
pp_transaction_release(transaction);
return status;
}
void tag_camera_serial(postproject::Production &production,
const postproject::AssetId &asset_id) {
const postproject::ObjectRef target = postproject::ObjectRef::asset(asset_id);
const postproject::ExternalIdentifier identifier{
"com.example.camera.serial", "A-0007", std::nullopt};
auto transaction = production.edit().value();
transaction.addExternalIdentifier(target, identifier).value();
transaction.commit().value();
const auto attached = production.externalIdentifiers(target).value();
const auto matches =
production.findByExternalIdentifier(identifier.scheme, identifier.value).value();
require(attached.size() == 1 && matches == std::vector{target},
"identifier lookup");
}
def tag_camera_serial(production: Production, asset_id: AssetId) -> None:
identifier = ExternalIdentifier("com.example.camera.serial", "A-0007")
with production.edit() as transaction:
transaction.add_external_identifier(AssetRef(asset_id), identifier)
transaction.commit()
attached = production.external_identifiers[AssetRef(asset_id)]
matches = production.objects_by_external_identifier[
identifier.scheme, identifier.value
]
assert attached == (identifier,)
assert matches == (AssetRef(asset_id),)
fn tag_camera_serial(production: &mut SqliteProduction, asset_id: AssetId) -> Result<()> {
let target = ObjectRef::Asset(asset_id);
let identifier = ExternalIdentifier::new(
IdentifierScheme::new("com.example.camera.serial")?,
"A-0007",
None,
)?;
{
let mut transaction = production.begin_transaction()?;
transaction.add_external_identifier(target, &identifier)?;
transaction.commit()?;
}
let attached = production.external_identifiers(target)?;
let matches = production.find_by_external_identifier(
identifier.scheme(),
identifier.value(),
identifier.qualifier(),
)?;
assert_eq!(attached, vec![identifier]);
assert_eq!(matches, vec![target]);
Ok(())
}
postproject identifier add production.pproj asset "$ASSET_ID" \
com.example.camera.serial A-0007
postproject identifier list production.pproj asset "$ASSET_ID"
postproject identifier find production.pproj com.example.camera.serial A-0007
Attachment is a transactional mutation like any other: it stays pending until commit and appears in the revision feed.
Remove an identifier¶
An object can carry several identifiers, from the same scheme or from different ones. Removing an identifier requires the same exact scheme, value, and qualifier; other attachments stay in place:
static pp_error_code_t replace_identifiers(pp_production_t *production,
const pp_asset_id_t *asset_id,
uint64_t *out_remaining,
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_transaction_t *transaction = NULL;
pp_external_identifier_set_t *identifiers = NULL;
pp_object_ref_set_t *matches = NULL;
pp_read_session_t *view = NULL;
pp_error_code_t status =
pp_production_begin_edit(production, NULL, NULL, &transaction, error);
if (status == PP_OK) {
status = pp_transaction_add_external_identifier(transaction, &target,
"com.example.camera.serial",
"A-0007", NULL, error);
}
if (status == PP_OK) {
/* Unknown schemes and qualifiers round-trip verbatim. */
status = pp_transaction_add_external_identifier(
transaction, &target, "com.example.mam.id", "MAM-42", "staging", error);
}
if (status == PP_OK) {
pp_commit_receipt_t commit_receipt;
status = pp_transaction_commit(transaction, &commit_receipt, error);
}
pp_transaction_release(transaction);
transaction = NULL;
if (status == PP_OK) {
status = pp_production_read_session(production, &view, error);
}
if (status == PP_OK) {
status = pp_read_session_external_identifiers(view, &target,
&identifiers, error);
}
for (uint64_t i = 0;
status == PP_OK && i < pp_external_identifier_set_count(identifiers);
++i) {
const char *scheme, *value, *qualifier;
status = pp_external_identifier_set_get(identifiers, i, &scheme, &value,
&qualifier, error);
if (status == PP_OK) {
printf("%s = %s%s%s\n", scheme, value, qualifier != NULL ? " / " : "",
qualifier != NULL ? qualifier : "");
}
}
if (status == PP_OK) {
status = pp_read_session_find_by_external_identifier(
view, "com.example.mam.id", "MAM-42", "staging", &matches, error);
}
for (uint64_t i = 0; status == PP_OK && i < pp_object_ref_set_count(matches);
++i) {
pp_object_ref_t object;
status = pp_object_ref_set_get(matches, i, &object, error);
if (status == PP_OK) {
printf("found object of kind %u\n", object.kind);
}
}
/* Removal names the exact scheme, value, and qualifier. */
if (status == PP_OK) {
status = pp_read_session_begin_edit(view, NULL, &transaction, error);
}
pp_read_session_release(view);
if (status == PP_OK) {
status = pp_transaction_remove_external_identifier(
transaction, &target, "com.example.mam.id", "MAM-42", "staging", error);
}
if (status == PP_OK) {
pp_commit_receipt_t commit_receipt;
status = pp_transaction_commit(transaction, &commit_receipt, error);
}
pp_external_identifier_set_release(identifiers);
identifiers = NULL;
if (status == PP_OK) {
status = pp_production_external_identifiers(production, &target,
&identifiers, error);
}
if (status == PP_OK) {
*out_remaining = pp_external_identifier_set_count(identifiers);
}
pp_external_identifier_set_release(identifiers);
pp_object_ref_set_release(matches);
pp_transaction_release(transaction);
return status;
}
std::vector<postproject::ExternalIdentifier>
replace_reel_name(postproject::Production &production,
const postproject::AssetId &asset_id) {
const postproject::ObjectRef target = postproject::ObjectRef::asset(asset_id);
const postproject::ExternalIdentifier reel{"com.example.reel", "A001",
std::nullopt};
const postproject::ExternalIdentifier serial{"com.example.camera.serial",
"A-0007", std::string("body")};
auto attach = production.edit().value();
attach.addExternalIdentifier(target, reel).value();
attach.addExternalIdentifier(target, serial).value();
attach.commit().value();
auto view = production.readSession().value();
for (const auto &identifier : view.externalIdentifiers(target).value()) {
std::cout << identifier.scheme << " = " << identifier.value << '\n';
}
for (const auto &match :
view.findByExternalIdentifier(reel.scheme, reel.value,
reel.qualifier).value()) {
std::cout << "reel A001 names object kind "
<< static_cast<std::uint32_t>(match.kind()) << '\n';
}
// Removal needs the exact scheme, value, and qualifier that were attached.
auto detach = view.edit().value();
detach.removeExternalIdentifier(target, reel).value();
detach.commit().value();
return production.externalIdentifiers(target).value();
}
def replace_tape_identifier(
production: Production, asset_id: AssetId
) -> tuple[ExternalIdentifier, ...]:
serial = ExternalIdentifier("com.example.camera.serial", "A-0007")
tape = ExternalIdentifier("com.example.tape", "T-0012", qualifier="reel")
with production.edit() as transaction:
transaction.add_external_identifier(AssetRef(asset_id), serial)
transaction.add_external_identifier(AssetRef(asset_id), tape)
transaction.commit()
with production.read_session() as view:
for identifier in view.external_identifiers(AssetRef(asset_id)):
print(
f"{identifier.scheme}: {identifier.value} ({identifier.qualifier or '-'})"
)
# A qualifier restricts the lookup to identifiers with exactly that qualifier.
key = (tape.scheme, tape.value, "reel")
for target in view.find_by_external_identifier(*key):
print(f"tape {tape.value} identifies {target}")
# Removal matches the exact scheme, value, and qualifier.
with view.edit() as transaction:
transaction.remove_external_identifier(AssetRef(asset_id), tape)
transaction.commit()
return production.external_identifiers[AssetRef(asset_id)]
fn replace_reel_identifier(
production: &mut SqliteProduction,
asset_id: AssetId,
) -> Result<postproject_core::CommitReceipt> {
let target = ObjectRef::Asset(asset_id);
let reel = ExternalIdentifier::new(IdentifierScheme::new("com.example.reel")?, "R-12", None)?;
let serial = ExternalIdentifier::new(
IdentifierScheme::new("com.example.camera.serial")?,
"A-0007",
Some("body".to_owned()),
)?;
{
let mut transaction = production.begin_transaction()?;
transaction.add_external_identifier(target, &reel)?;
transaction.add_external_identifier(target, &serial)?;
transaction.commit()?;
}
let view = production.read_session()?;
for identifier in view.read().external_identifiers(target)? {
println!(
"{} = {} ({:?})",
identifier.scheme().as_str(),
identifier.value(),
identifier.qualifier()
);
}
for object in
view.read()
.find_by_external_identifier(reel.scheme(), reel.value(), reel.qualifier())?
{
println!("tagged with reel R-12: {object:?}");
}
let base = view.decision_base();
drop(view);
let mut transaction = production.begin_edit(base)?;
transaction.remove_external_identifier(target, &reel)?;
transaction.commit()
}
postproject identifier add knowledge.pproj asset "$ASSET_ID" \
com.example.camera.serial A-0007
postproject identifier add knowledge.pproj asset "$ASSET_ID" \
com.example.tape B-0112 --qualifier reel
BASE=$(postproject --json inspect knowledge.pproj | jq -r .decision_base)
postproject identifier list knowledge.pproj asset "$ASSET_ID"
postproject identifier find knowledge.pproj com.example.camera.serial A-0007
# A qualifier restricts the lookup to identifiers with exactly that qualifier.
postproject identifier find knowledge.pproj com.example.tape B-0112 \
--qualifier reel
# Removal matches the exact scheme, value, and qualifier.
postproject --decision-base "$BASE" identifier remove knowledge.pproj asset "$ASSET_ID" \
com.example.tape B-0112 --qualifier reel
Lookup is exact¶
A scheme is not a namespace prefix, values are compared byte-for-byte, and a lookup may return several objects because an external system can reuse a value. A lookup can also require an exact qualifier:
Pass the qualifier whenever you know it. Under a shared scheme such as the application scheme
https://postproject.org/id/application, the qualifier is what separates one application’s identifiers from another’s. Use a qualifier rooted in a domain you control, for exampleorg.example.editor:clip_uuid.Omit it to match any qualifier. The lookup then also returns objects whose identifier has no qualifier.
A qualified lookup never matches an unqualified identifier.
Treat the result as candidates for the integration to interpret, not as proof of identity.
To refer from a host document to a PostProject object, persist a host-object binding instead; external identifiers are lookup aids and assertions, not PostProject identity.