Skip to main content

onetaskgraph_plugin_api/
migration.rs

1//! What one sweep of a source's stored forms rewrote: the answer of
2//! [`TaskSource::migrate_stored_forms`](crate::TaskSource::migrate_stored_forms).
3//!
4//! A source that once wrote an item's long form in a spelling it no longer writes — a metadata
5//! slot its tracker shows as text, say — keeps reading that spelling, so nothing is lost by
6//! leaving it; the sweep is what rewrites the backlog once rather than item by item as each is
7//! next written. Which forms are superseded, and how an item is rewritten, is the plugin's alone;
8//! these types only say what it did.
9
10use crate::{MetadataRecord, NativeId};
11
12/// One item a sweep rewrote, or under a dry run would rewrite.
13#[derive(Debug, Clone, PartialEq, Eq)]
14#[non_exhaustive]
15pub struct MigratedItem {
16    /// Whether the item is a task, a project or a document.
17    pub kind: MetadataRecord,
18    /// The item's id in its source.
19    pub id: NativeId,
20    /// The superseded form the item was held in, as its plugin names it — `html-comment-slot`,
21    /// say.
22    pub from: String,
23}
24
25impl MigratedItem {
26    /// The item of `kind` with `id`, held in the superseded form named `from`.
27    #[must_use]
28    pub fn new(kind: MetadataRecord, id: NativeId, from: impl Into<String>) -> Self {
29        Self {
30            kind,
31            id,
32            from: from.into(),
33        }
34    }
35}
36
37/// One item a sweep found in a superseded form and could not rewrite.
38#[derive(Debug, Clone, PartialEq, Eq)]
39#[non_exhaustive]
40pub struct MigrationFailure {
41    /// The item, and the form it is still held in.
42    pub item: MigratedItem,
43    /// Why it was refused or not written, as the source said it.
44    pub reason: String,
45}
46
47impl MigrationFailure {
48    /// `item`, left in its superseded form for `reason`.
49    #[must_use]
50    pub fn new(item: MigratedItem, reason: impl Into<String>) -> Self {
51        Self {
52            item,
53            reason: reason.into(),
54        }
55    }
56}
57
58/// What one sweep of a source's stored forms did.
59///
60/// The default — nothing rewritten, nothing current, nothing failed — is the answer of a
61/// source that writes every item in the one form it has always written.
62#[derive(Debug, Clone, Default, PartialEq, Eq)]
63#[non_exhaustive]
64pub struct StoredFormMigration {
65    /// Each item rewritten into the current form, or under a dry run each item that would be.
66    pub rewritten: Vec<MigratedItem>,
67    /// How many of the items examined already held the current form — one holding nothing a
68    /// stored form could spell included — and were sent nothing.
69    pub current: u64,
70    /// Each item held in a superseded form that was refused or not written.
71    pub failed: Vec<MigrationFailure>,
72}