artifact

Per-entity sync adapter for artifacts and their notes.

const FRONTMATTER_DELIM

source

const FRONTMATTER_DELIM: &str = "---\n";

The line that opens and closes the YAML frontmatter of an artifact file.

struct ArtifactFrontmatter

source

struct ArtifactFrontmatter

YAML frontmatter for .gest/artifact/<id>.md files.

Field Type Description
deleted_at Option<DateTime<Utc>> When the artifact was deleted; a set value makes the file a tombstone, and import deletes the row.
id Id The artifact’s id, which also names the file.
title String The artifact’s title.
tags Vec<String> The labels of the artifact’s tags; left out of the file when empty.
metadata Value The artifact’s JSON metadata; left out of the file when null.
archived_at Option<DateTime<Utc>> When the artifact was archived, or None while it is active.
created_at DateTime<Utc> When the artifact was created.
updated_at DateTime<Utc> When the artifact was last changed.

Implements Clone, Debug, Deserialize<'de>, Eq, PartialEq, Serialize.

struct ArtifactNoteFile

source

struct ArtifactNoteFile

On-disk wrapper for .gest/artifact/notes/<note_id>.yaml.

Field Type Description
deleted_at Option<DateTime<Utc>> When the note was deleted; a set value makes the file a tombstone, and import deletes the row.
id Id The note’s id, which also names the file.
entity_id Id The id of the artifact that the note belongs to.
author_id Option<Id> The author who wrote the note, if one is recorded.
body String The note’s text.
created_at DateTime<Utc> When the note was created.
updated_at DateTime<Utc> When the note was last changed.

Implements Clone, Debug, Deserialize<'de>, Eq, PartialEq, Serialize.

fn read_all

source

pub async fn read_all(conn: &Connection, project_id: &Id, gest_dir: &Path) -> Result<(), Error>

Import every artifact/*.md (and artifact/notes/*.yaml) file into SQLite.

A tombstoned file deletes its row; any other file inserts or updates its row. An artifact’s tags are replaced by the labels in its frontmatter.

Parameter Type Description
conn &Connection the database connection
project_id &Id the project that imported artifacts belong to
gest_dir &Path the project’s .gest/ directory
returns Result<(), Error> Ok(()) when every file is imported, or an error when a file cannot be read or parsed or a query fails.

fn write_all

source

pub async fn write_all(conn: &Connection, project_id: &Id, gest_dir: &Path) -> Result<(), Error>

Export every artifact and artifact note row to per-entity files.

Afterwards it removes the files of artifacts and notes that are no longer in the database, and their digests. Tombstoned artifact and note files stay, because clones read them as the delete signal.

Parameter Type Description
conn &Connection the database connection
project_id &Id the project whose artifacts to export
gest_dir &Path the project’s .gest/ directory
returns Result<(), Error> Ok(()) when every row is written, or an error when a query, a timestamp or a file write fails.

fn is_tombstoned_artifact_file

source

fn is_tombstoned_artifact_file(path: &Path) -> bool

Return true if the artifact file at path carries a tombstone in its YAML frontmatter. Errors and missing files are treated as “not tombstoned” so cleanup can fall back to its normal path.

Parameter Type Description
path &Path the artifact markdown file to inspect
returns bool true only when the frontmatter’s deleted_at is not null.

fn compose_artifact_file

source

fn compose_artifact_file(front: &ArtifactFrontmatter, body: &str) -> Result<String, Error>

Write an artifact file: the frontmatter as YAML between --- lines, then the body.

Both the YAML and the body end in a newline, added when missing.

Parameter Type Description
front &ArtifactFrontmatter the frontmatter to serialize
body &str the artifact’s markdown body
returns Result<String, Error> The file’s text, or an error when the frontmatter cannot be serialized.

fn load_artifact_tag_labels

source

async fn load_artifact_tag_labels(conn: &Connection, artifact_id: &Id) -> Result<Vec<String>, Error>

Read the labels of the tags attached to an artifact.

Parameter Type Description
conn &Connection the database connection
artifact_id &Id the artifact whose tags to read
returns Result<Vec<String>, Error> The labels in alphabetical order, or an error when the query fails.

fn parse_dt

source

fn parse_dt(s: &str) -> Result<DateTime<Utc>, Error>

Parse an RFC 3339 timestamp from the database into UTC.

Parameter Type Description
s &str the timestamp text
returns Result<DateTime<Utc>, Error> The time in UTC, or an Error::Io that holds the parse error.

fn split_frontmatter

source

fn split_frontmatter(raw: &str) -> Result<(&str, &str), Error>

Split a markdown file into its YAML frontmatter and the body that follows.

Parameter Type Description
raw &str the whole text of the artifact file
returns Result<(&str, &str), Error> The returned front slice always includes a trailing newline so it can be parsed by yaml_serde::from_str directly. The body slice is everything after the closing --- delimiter. It is an error when the file does not start with --- or the frontmatter is not closed.

fn sync_artifact_tags

source

async fn sync_artifact_tags(conn: &Connection, front: &ArtifactFrontmatter) -> Result<(), Error>

Replace an artifact’s tags with the labels in its frontmatter.

A label with no tag row gets a new tag.

Parameter Type Description
conn &Connection the database connection
front &ArtifactFrontmatter the frontmatter that holds the artifact’s id and tag labels
returns Result<(), Error> Ok(()) when the tags are stored, or an error when a query fails.

fn upsert_artifact

source

async fn upsert_artifact(
    conn: &Connection,
    project_id: &Id,
    front: &ArtifactFrontmatter,
    body: &str,
) -> Result<(), Error>

Insert an artifact row from its file, or update the row that has its id.

An update changes the archive time, body, metadata, title and updated_at; it keeps the project and created_at.

Parameter Type Description
conn &Connection the database connection
project_id &Id the project that a new row belongs to
front &ArtifactFrontmatter the parsed frontmatter
body &str the markdown body that follows the frontmatter
returns Result<(), Error> Ok(()) when the row is written, or an error when the query fails.

fn upsert_note

source

async fn upsert_note(conn: &Connection, file: &ArtifactNoteFile) -> Result<(), Error>

Insert an artifact note row from its file, or update the body and updated_at of the row that has its id.

Parameter Type Description
conn &Connection the database connection
file &ArtifactNoteFile the parsed note file
returns Result<(), Error> Ok(()) when the row is written, or an error when the query fails.

fn write_artifact_file

source

async fn write_artifact_file(
    conn: &Connection,
    project_id: &Id,
    gest_dir: &Path,
    path: &Path,
    serialized: &str,
) -> Result<(), Error>

Write the composed <frontmatter>\n<body> artifact file with digest caching.

The file is not written when its digest matches the one recorded for its path.

Parameter Type Description
conn &Connection the database connection
project_id &Id the project that owns the digest record
gest_dir &Path the project’s .gest/ directory
path &Path where to write the file, inside gest_dir
serialized &str the file’s text
returns Result<(), Error> Ok(()) when the file is written or already current, or an error when path is outside gest_dir or a write or query fails.