artifact
- Artifact bodies live at
artifact/<id>.mdas markdown with YAML frontmatter holding title, tags, timestamps, and tombstone (ADR-0016 §5). - Artifact notes are individual files at
artifact/notes/<note_id>.yaml.
const FRONTMATTER_DELIM
const FRONTMATTER_DELIM: &str = "---\n";The line that opens and closes the YAML frontmatter of an artifact file.
struct ArtifactFrontmatter
struct ArtifactFrontmatterYAML 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
struct ArtifactNoteFileOn-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
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
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
fn is_tombstoned_artifact_file(path: &Path) -> boolReturn 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
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
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
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
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 upsert_artifact
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
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
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. |