systemprompt_identifiers/
documents.rs1use crate::error::IdValidationError;
21
22crate::define_id!(DocumentId, uuid);
23crate::define_id!(DocumentFolderId, uuid);
24crate::define_id!(DocumentRevisionId, uuid);
25crate::define_id!(DocumentEditSessionId, uuid);
26crate::define_id!(DocumentCommentId, uuid);
27crate::define_id!(DocumentProposalId, uuid);
28crate::define_id!(DocumentAccessRequestId, uuid);
29crate::define_id!(DocumentUploadId, uuid);
30crate::define_id!(IssueReportId, uuid);
31crate::define_id!(ContentHash, checked, validate_content_hash);
32crate::define_id!(DocumentNodeId, checked, |value| {
33 crate::macros::validate_non_empty("DocumentNodeId", value)
34});
35crate::define_id!(DocumentOpId, checked, |value| {
36 crate::macros::validate_non_empty("DocumentOpId", value)
37});
38crate::define_id!(DocumentTemplateId, checked, |value| {
39 crate::macros::validate_non_empty("DocumentTemplateId", value)
40});
41crate::define_id!(DriveDeviceId, checked, |value| {
42 crate::macros::validate_non_empty("DriveDeviceId", value)
43});
44
45const CONTENT_HASH_LEN: usize = 64;
46
47fn validate_content_hash(value: &str) -> Result<(), IdValidationError> {
48 if value.is_empty() {
49 return Err(IdValidationError::empty("ContentHash"));
50 }
51 if value.len() != CONTENT_HASH_LEN {
52 return Err(IdValidationError::invalid(
53 "ContentHash",
54 "must be exactly 64 hex characters",
55 ));
56 }
57 if !value
58 .bytes()
59 .all(|b| b.is_ascii_digit() || (b'a'..=b'f').contains(&b))
60 {
61 return Err(IdValidationError::invalid(
62 "ContentHash",
63 "must be lowercase hex",
64 ));
65 }
66 Ok(())
67}