content capa

content-notes

Notes and tagging for any model via generic foreign keys

Notes and tagging for any model via generic foreign keys

Tiercontent
Roleunclassified (baselined)
Pathcrates/content/notes
Edition2021
Targetscontent_notes
Public items93 across 6 modules
Tests69

What it is for

# content-notes

Notes and tagging library crates for any model via generic foreign keys.

Core Concepts

Example

use content_notes::{Note, Tag, ObjectTag, Visibility, colors};
use uuid::Uuid;

// Create a note attached to a patient
let note = Note::builder()
.target("patients.Patient", "patient-123")
.content("Follow-up scheduled for next week")
.author(Uuid::new_v4())
.visibility(Visibility::Internal)
.build();

// Create a reusable tag
let urgent_tag = Tag::builder()
.name("Urgent")
.red()
.description("Requires immediate attention")
.build();

// Apply tag to a project
let object_tag = ObjectTag::builder()
.target("projects.Project", "project-456")
.tag(urgent_tag.id)
.tagged_by(Uuid::new_v4())
.build();

Capabilities

colors (other)

Standard tag colors.

Item
pub const RED: & str
pub const ORANGE: & str
pub const YELLOW: & str
pub const GREEN: & str
pub const BLUE: & str
pub const PURPLE: & str
pub const GRAY: & str
pub const DEFAULT: & str
fn is_valid_hex(color : & str) -> bool
fn normalize(color : & str) -> String

NotesError

Error types for the notes crate.

Item
pub enum NotesError
NotesError :: fn note_not_found(id : Uuid) -> Self
NotesError :: fn tag_not_found(slug : impl Into <String>) -> Self
NotesError :: fn tag_not_found_by_id(id : Uuid) -> Self
NotesError :: fn object_tag_not_found(id : Uuid) -> Self
NotesError :: fn duplicate_slug(slug : impl Into <String>) -> Self
NotesError :: fn tag_already_applied(tag_slug : impl Into <String>, target_type : impl Into <String>, target_id : impl Into <String>,) -> Self
NotesError :: fn invalid_color(color : impl Into <String>) -> Self

Note:Note

Note model for attaching comments to any target.

Item
pub struct Note

Note:builder

Note model for attaching comments to any target.

Item
Note :: fn builder() -> NoteBuilder

Note:can

Note model for attaching comments to any target.

Item
Note :: fn can_view(& self, user_id : Option <Uuid>, is_staff : bool) -> bool

Note:created

Note model for attaching comments to any target.

Item
Note :: fn created_at(& self) -> DateTime <Utc>

Note:deleted

Note model for attaching comments to any target.

Item
Note :: fn deleted_at(& self) -> Option <DateTime <Utc>>

Note:id

Note model for attaching comments to any target.

Item
Note :: fn id(& self) -> Uuid

Note:is

Note model for attaching comments to any target.

Item
Note :: fn is_for(& self, target_type : & str, target_id : & str) -> bool
Note :: fn is_by(& self, author_id : Uuid) -> bool
Note :: fn is_system_note(& self) -> bool

Note:preview

Note model for attaching comments to any target.

Item
Note :: fn preview(& self, max_chars : usize) -> & str

Note:restore

Note model for attaching comments to any target.

Item
Note :: fn restore(& mut self)

Note:soft

Note model for attaching comments to any target.

Item
Note :: fn soft_delete(& mut self)

Note:updated

Note model for attaching comments to any target.

Item
Note :: fn updated_at(& self) -> DateTime <Utc>

NoteBuilder

Note model for attaching comments to any target.

Item
pub struct NoteBuilder
NoteBuilder :: fn new() -> Self
NoteBuilder :: fn target(mut self, target_type : impl Into <String>, target_id : impl Into <String>) -> Self
NoteBuilder :: fn content(mut self, content : impl Into <String>) -> Self
NoteBuilder :: fn author(mut self, author_id : Uuid) -> Self
NoteBuilder :: fn visibility(mut self, visibility : Visibility) -> Self
NoteBuilder :: fn public(self) -> Self
NoteBuilder :: fn internal(self) -> Self
NoteBuilder :: fn private(self) -> Self
NoteBuilder :: fn metadata(mut self, metadata : JsonValue) -> Self
NoteBuilder :: fn build(self) -> Note

ObjectTag:ObjectTag

ObjectTag model for linking tags to any target.

Item
pub struct ObjectTag

ObjectTag:builder

ObjectTag model for linking tags to any target.

Item
ObjectTag :: fn builder() -> ObjectTagBuilder

ObjectTag:created

ObjectTag model for linking tags to any target.

Item
ObjectTag :: fn created_at(& self) -> DateTime <Utc>

ObjectTag:deleted

ObjectTag model for linking tags to any target.

Item
ObjectTag :: fn deleted_at(& self) -> Option <DateTime <Utc>>

ObjectTag:id

ObjectTag model for linking tags to any target.

Item
ObjectTag :: fn id(& self) -> Uuid

ObjectTag:is

ObjectTag model for linking tags to any target.

Item
ObjectTag :: fn is_for(& self, target_type : & str, target_id : & str) -> bool
ObjectTag :: fn is_tag(& self, tag_id : Uuid) -> bool
ObjectTag :: fn is_by(& self, user_id : Uuid) -> bool
ObjectTag :: fn is_system_tag(& self) -> bool

ObjectTag:matches

ObjectTag model for linking tags to any target.

Item
ObjectTag :: fn matches(& self, target_type : & str, target_id : & str, tag_id : Uuid) -> bool

ObjectTag:restore

ObjectTag model for linking tags to any target.

Item
ObjectTag :: fn restore(& mut self)

ObjectTag:soft

ObjectTag model for linking tags to any target.

Item
ObjectTag :: fn soft_delete(& mut self)

ObjectTag:updated

ObjectTag model for linking tags to any target.

Item
ObjectTag :: fn updated_at(& self) -> DateTime <Utc>

ObjectTagBuilder

ObjectTag model for linking tags to any target.

Item
pub struct ObjectTagBuilder
ObjectTagBuilder :: fn new() -> Self
ObjectTagBuilder :: fn target(mut self, target_type : impl Into <String>, target_id : impl Into <String>) -> Self
ObjectTagBuilder :: fn tag(mut self, tag_id : Uuid) -> Self
ObjectTagBuilder :: fn tagged_by(mut self, user_id : Uuid) -> Self
ObjectTagBuilder :: fn build(self) -> ObjectTag

Tag

Tag model for reusable labels.

Item
pub struct Tag
Tag :: fn builder() -> TagBuilder
Tag :: fn matches_slug(& self, slug : & str) -> bool
Tag :: fn slugify(name : & str) -> String
Tag :: fn id(& self) -> Uuid
Tag :: fn created_at(& self) -> DateTime <Utc>
Tag :: fn updated_at(& self) -> DateTime <Utc>
Tag :: fn deleted_at(& self) -> Option <DateTime <Utc>>
Tag :: fn soft_delete(& mut self)
Tag :: fn restore(& mut self)

TagBuilder:TagBuilder

Tag model for reusable labels.

Item
pub struct TagBuilder

TagBuilder:blue

Tag model for reusable labels.

Item
TagBuilder :: fn blue(self) -> Self

TagBuilder:build

Tag model for reusable labels.

Item
TagBuilder :: fn build(self) -> Tag

TagBuilder:color

Tag model for reusable labels.

Item
TagBuilder :: fn color(mut self, color : impl Into <String>) -> Self

TagBuilder:description

Tag model for reusable labels.

Item
TagBuilder :: fn description(mut self, description : impl Into <String>) -> Self

TagBuilder:gray

Tag model for reusable labels.

Item
TagBuilder :: fn gray(self) -> Self

TagBuilder:green

Tag model for reusable labels.

Item
TagBuilder :: fn green(self) -> Self

TagBuilder:name

Tag model for reusable labels.

Item
TagBuilder :: fn name(mut self, name : impl Into <String>) -> Self

TagBuilder:new

Tag model for reusable labels.

Item
TagBuilder :: fn new() -> Self

TagBuilder:orange

Tag model for reusable labels.

Item
TagBuilder :: fn orange(self) -> Self

TagBuilder:purple

Tag model for reusable labels.

Item
TagBuilder :: fn purple(self) -> Self

TagBuilder:red

Tag model for reusable labels.

Item
TagBuilder :: fn red(self) -> Self

TagBuilder:slug

Tag model for reusable labels.

Item
TagBuilder :: fn slug(mut self, slug : impl Into <String>) -> Self

TagBuilder:yellow

Tag model for reusable labels.

Item
TagBuilder :: fn yellow(self) -> Self

Visibility

Visibility levels for notes.

Item
pub enum Visibility
Visibility :: fn as_str(& self) -> & 'static str
Visibility :: fn parse(s : & str) -> Option <Self>
Visibility :: fn is_public(& self) -> bool
Visibility :: fn requires_auth(& self) -> bool
Visibility :: fn is_private(& self) -> bool
Visibility :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result
Visibility :: fn from_str(s : & str) -> Result <Self, Self::Err>

How to use it

From this crate's own rustdoc:

use content_notes::{Note, Tag, ObjectTag, Visibility, colors};
use uuid::Uuid;

// Create a note attached to a patient
let note = Note::builder()
    .target("patients.Patient", "patient-123")
    .content("Follow-up scheduled for next week")
    .author(Uuid::new_v4())
    .visibility(Visibility::Internal)
    .build();

// Create a reusable tag
let urgent_tag = Tag::builder()
    .name("Urgent")
    .red()
    .description("Requires immediate attention")
    .build();

// Apply tag to a project
let object_tag = ObjectTag::builder()
    .target("projects.Project", "project-456")
    .tag(urgent_tag.id)
    .tagged_by(Uuid::new_v4())
    .build();

Module structure

content_notes

flowchart TD
  n_content_notes["content_notes"]
  n_content_notes --> n_colors["colors"]
  n_content_notes --> n_error["error"]
  n_content_notes --> n_note["note"]
  n_content_notes --> n_object_tag["object_tag"]
  n_content_notes --> n_tag["tag"]
  n_content_notes --> n_visibility["visibility"]

Public surface

`colors`

ItemWhat it is
pub const RED: & strRed color for urgent/critical tags.
pub const ORANGE: & strOrange color for warning/attention tags.
pub const YELLOW: & strYellow color for caution/pending tags.
pub const GREEN: & strGreen color for success/approved tags.
pub const BLUE: & strBlue color for info/reference tags.
pub const PURPLE: & strPurple color for special/premium tags.
pub const GRAY: & strGray color for neutral/default tags.
pub const DEFAULT: & strDefault tag color (gray).
fn is_valid_hex(color : & str) -> boolCheck if a string is a valid hex color.
fn normalize(color : & str) -> StringNormalize a hex color to uppercase.

`error`

ItemWhat it is
pub enum NotesErrorErrors that can occur in note operations.
NotesError :: fn note_not_found(id : Uuid) -> SelfCreate a new NoteNotFound error.
NotesError :: fn tag_not_found(slug : impl Into <String>) -> SelfCreate a new TagNotFound error by slug.
NotesError :: fn tag_not_found_by_id(id : Uuid) -> SelfCreate a new TagNotFoundById error.
NotesError :: fn object_tag_not_found(id : Uuid) -> SelfCreate a new ObjectTagNotFound error.
NotesError :: fn duplicate_slug(slug : impl Into <String>) -> SelfCreate a new DuplicateSlug error.
NotesError :: fn tag_already_applied(tag_slug : impl Into <String>, target_type : impl Into <String>, target_id : impl Into <String>,) -> SelfCreate a new TagAlreadyApplied error.
NotesError :: fn invalid_color(color : impl Into <String>) -> SelfCreate a new InvalidColor error.

`note`

ItemWhat it is
pub struct NoteA note attached to any target via generic foreign key.
Note :: fn builder() -> NoteBuilderCreate a new note builder.
Note :: fn is_for(& self, target_type : & str, target_id : & str) -> boolCheck if this note is for the given target.
Note :: fn is_by(& self, author_id : Uuid) -> boolCheck if this note was created by the given author.
Note :: fn is_system_note(& self) -> boolCheck if this is a system-generated note (no author).
Note :: fn can_view(& self, user_id : Option <Uuid>, is_staff : bool) -> boolCheck if a user can view this note based on visibility
Note :: fn preview(& self, max_chars : usize) -> & strGet content preview (first N characters).
Note :: fn id(& self) -> Uuid
Note :: fn created_at(& self) -> DateTime <Utc>
Note :: fn updated_at(& self) -> DateTime <Utc>
Note :: fn deleted_at(& self) -> Option <DateTime <Utc>>
Note :: fn soft_delete(& mut self)Mark as soft-deleted.
Note :: fn restore(& mut self)Restore from soft-deleted state.
pub struct NoteBuilderBuilder for Note.
NoteBuilder :: fn new() -> SelfCreate a new builder.
NoteBuilder :: fn target(mut self, target_type : impl Into <String>, target_id : impl Into <String>) -> SelfSet the target.
NoteBuilder :: fn content(mut self, content : impl Into <String>) -> SelfSet the content.
NoteBuilder :: fn author(mut self, author_id : Uuid) -> SelfSet the author.
NoteBuilder :: fn visibility(mut self, visibility : Visibility) -> SelfSet visibility.
NoteBuilder :: fn public(self) -> SelfSet as public visibility.
NoteBuilder :: fn internal(self) -> SelfSet as internal visibility.
NoteBuilder :: fn private(self) -> SelfSet as private visibility.
NoteBuilder :: fn metadata(mut self, metadata : JsonValue) -> SelfSet metadata.
NoteBuilder :: fn build(self) -> NoteBuild the note

`object_tag`

ItemWhat it is
pub struct ObjectTagLinks a tag to any target via generic foreign key.
ObjectTag :: fn builder() -> ObjectTagBuilderCreate a new object tag builder.
ObjectTag :: fn is_for(& self, target_type : & str, target_id : & str) -> boolCheck if this object tag is for the given target.
ObjectTag :: fn is_tag(& self, tag_id : Uuid) -> boolCheck if this object tag uses the given tag.
ObjectTag :: fn is_by(& self, user_id : Uuid) -> boolCheck if this object tag was created by the given user.
ObjectTag :: fn is_system_tag(& self) -> boolCheck if this is a system-applied tag (no user).
ObjectTag :: fn matches(& self, target_type : & str, target_id : & str, tag_id : Uuid) -> boolCheck if this matches the given target and tag.
ObjectTag :: fn id(& self) -> Uuid
ObjectTag :: fn created_at(& self) -> DateTime <Utc>
ObjectTag :: fn updated_at(& self) -> DateTime <Utc>
ObjectTag :: fn deleted_at(& self) -> Option <DateTime <Utc>>
ObjectTag :: fn soft_delete(& mut self)Mark as soft-deleted.
ObjectTag :: fn restore(& mut self)Restore from soft-deleted state.
pub struct ObjectTagBuilderBuilder for ObjectTag.
ObjectTagBuilder :: fn new() -> SelfCreate a new builder.
ObjectTagBuilder :: fn target(mut self, target_type : impl Into <String>, target_id : impl Into <String>) -> SelfSet the target.
ObjectTagBuilder :: fn tag(mut self, tag_id : Uuid) -> SelfSet the tag ID.
ObjectTagBuilder :: fn tagged_by(mut self, user_id : Uuid) -> SelfSet who applied the tag.
ObjectTagBuilder :: fn build(self) -> ObjectTagBuild the object tag

`tag`

ItemWhat it is
pub struct TagA reusable tag/label for categorization.
Tag :: fn builder() -> TagBuilderCreate a new tag builder.
Tag :: fn matches_slug(& self, slug : & str) -> boolCheck if this tag matches the given slug.
Tag :: fn slugify(name : & str) -> StringGenerate a slug from a name
Tag :: fn id(& self) -> Uuid
Tag :: fn created_at(& self) -> DateTime <Utc>
Tag :: fn updated_at(& self) -> DateTime <Utc>
Tag :: fn deleted_at(& self) -> Option <DateTime <Utc>>
Tag :: fn soft_delete(& mut self)Mark as soft-deleted.
Tag :: fn restore(& mut self)Restore from soft-deleted state.
pub struct TagBuilderBuilder for Tag.
TagBuilder :: fn new() -> SelfCreate a new builder.
TagBuilder :: fn name(mut self, name : impl Into <String>) -> SelfSet the display name.
TagBuilder :: fn slug(mut self, slug : impl Into <String>) -> SelfSet the slug (URL-friendly identifier).
TagBuilder :: fn color(mut self, color : impl Into <String>) -> SelfSet the color (hex format).
TagBuilder :: fn red(self) -> SelfSet color to red.
TagBuilder :: fn orange(self) -> SelfSet color to orange.
TagBuilder :: fn yellow(self) -> SelfSet color to yellow.
TagBuilder :: fn green(self) -> SelfSet color to green.
TagBuilder :: fn blue(self) -> SelfSet color to blue.
TagBuilder :: fn purple(self) -> SelfSet color to purple.
TagBuilder :: fn gray(self) -> SelfSet color to gray.
TagBuilder :: fn description(mut self, description : impl Into <String>) -> SelfSet the description.
TagBuilder :: fn build(self) -> TagBuild the tag

`visibility`

ItemWhat it is
pub enum VisibilityVisibility level for a note
Visibility :: fn as_str(& self) -> & 'static strGet the string representation.
Visibility :: fn parse(s : & str) -> Option <Self>Parse from string.
Visibility :: fn is_public(& self) -> boolCheck if this visibility allows public access.
Visibility :: fn requires_auth(& self) -> boolCheck if this visibility requires authentication.
Visibility :: fn is_private(& self) -> boolCheck if this visibility is author-only.
Visibility :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result
Visibility :: fn from_str(s : & str) -> Result <Self, Self::Err>

Re-exports. Exported here, defined elsewhere.

ExportDefined in
NotesErrorerror::NotesError
Visibilityvisibility::Visibility
colorsastag_colorscolorsastag_colors
{HasId,SoftDeletable,Timestamped}foundation_basemodels::{HasId,SoftDeletable,Timestamped}
{Note,NoteBuilder}note::{Note,NoteBuilder}
{ObjectTag,ObjectTagBuilder}object_tag::{ObjectTag,ObjectTagBuilder}
{Tag,TagBuilder}tag::{Tag,TagBuilder}

Boundary

Reaches into foundation.

Shares tier content with 5 other crates: content-assets, content-calendar, content-calendar-recurrence, content-cms, content-directory-listing.

_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._

Where it sits

Tier (ontology)content
Architectural role (taxonomy)unclassified (baselined)
Locationcrates/content/notes
Vocabulary in force (lexicon)current

Tier flow. Which tiers this crate's own edges cross.

flowchart LR
  n_content["content"] --> n_foundation["foundation"]

Dependencies

Runtime, in this workspace.

CrateTierOptionalOnly on
`foundation-basemodels`foundationnoalways

Runtime, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
chrono^0.4serdenoalways
serde^1derivenoalways
serde_json^1noalways
sqlx^0.8runtime-tokio, postgres, chrono, uuid, jsonnoalways
thiserror^2noalways
tokio^1fullnoalways
uuid^1v4, v7, serde, jsnoalways

Development, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
tokio-test^0.4noalways

Build. None.

Depended on by. 1 workspace crate.

Signal flow — what reaches this crate, and what it reaches.

flowchart LR
  n_application_notes["application-notes"] -->|uses| SELF
  SELF["content-notes"]
  SELF -->|runtime| n_foundation_basemodels["foundation-basemodels"]
  classDef self fill:#1f883d,stroke:#1f883d,color:#fff;
  class SELF self;

Feature flags

No Cargo features are defined: every capability is unconditional, so no consumer can receive a half-wired crate.

Targets

KindNameSource
libcontent_notes`src/lib.rs`

Error model

Error typeNamed by
NotesErrordeclared, no public signature returns it

Operational characteristics

PropertyEvidence
async public surfacenone detected
async runtimeyes
database accessyes
network I/Onone detected
unsafe codenone detected
environment variablesnone detected

No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.

Configuration

No environment variable is read with a literal name anywhere in this crate. A variable whose key is computed at run time cannot be listed here, and is not claimed to be absent.

1 workspace crate depends on this one: application-notes.

Verification

KindCount
Unit tests69
Integration tests0
Examples0
Doctests1

Evidence by module. How often each public module is named by something executable.

ModuleTestsExamplesConsumers
colors1000
error100
note200
object_tag200
tag200
visibility100

What the tests establish, by name:

Documentation coverage

MeasureDocumentedTotal
Public items with rustdoc7993
Public modules with a //! block66
pie showData
    title Public items with rustdoc
    "Documented" : 79
    "No rustdoc detected" : 14

Metrics

MetricValue
Rust source files7
Source lines1929
Code lines1358
Public API items93
Public modules6
Tests69
Examples0
Cargo features0
Direct runtime dependencies8
Workspace reverse dependencies1
pie showData
    title Public API by kind
    "constant" : 8
    "enum" : 2
    "function" : 2
    "method" : 75
    "struct" : 6
pie showData
    title Rust source composition
    "Code" : 1358
    "Blank or comment" : 571

Generation

Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.

Todas las content · Manual