use crate::edge::EdgeRelation;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Visibility {
Verb,
Subhandler,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum VerbCategory {
Assertive,
Directive,
Commissive,
Declaration,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct HandlerDef {
pub name: &'static str,
pub description: &'static str,
pub visibility: Visibility,
pub category: VerbCategory,
}
#[deprecated(since = "0.2.0", note = "Use HandlerDef instead (ADR-023)")]
pub type VerbDef = HandlerDef;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum EndpointKind {
NoteOfKind(&'static str),
EntityOfKind(&'static str),
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct EdgeEndpointRule {
pub relation: EdgeRelation,
pub source: EndpointKind,
pub target: EndpointKind,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct NoteLifecycleSpec {
pub field: &'static str,
pub initial: &'static str,
pub terminal: &'static [&'static str],
pub transitions: &'static [(&'static str, &'static str)],
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct NoteKindSpec {
pub kind: &'static str,
pub aliases: &'static [&'static str],
pub lifecycle: NoteLifecycleSpec,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PackSchemaPlan {
pub pack: &'static str,
pub statements: &'static [&'static str],
}
pub trait Pack {
const NAME: &'static str;
const NOTE_KINDS: &'static [&'static str];
const ENTITY_KINDS: &'static [&'static str];
const HANDLERS: &'static [HandlerDef];
const EDGE_RULES: &'static [EdgeEndpointRule] = &[];
const REQUIRES: &'static [&'static str] = &[];
const NOTE_KIND_SPECS: &'static [NoteKindSpec] = &[];
const SCHEMA_PLAN: Option<PackSchemaPlan> = None;
const VALIDATION_RULES: &'static [&'static str] = &[];
}
#[cfg(test)]
mod tests {
use super::*;
struct TestPack;
impl Pack for TestPack {
const NAME: &'static str = "test";
const NOTE_KINDS: &'static [&'static str] = &["memo"];
const ENTITY_KINDS: &'static [&'static str] = &["widget"];
const HANDLERS: &'static [HandlerDef] = &[HandlerDef {
name: "do_thing",
description: "does a thing",
visibility: Visibility::Verb,
category: VerbCategory::Commissive,
}];
}
#[test]
fn pack_trait_compiles() {
assert_eq!(TestPack::NAME, "test");
assert_eq!(TestPack::NOTE_KINDS, &["memo"]);
assert_eq!(TestPack::ENTITY_KINDS, &["widget"]);
assert_eq!(TestPack::HANDLERS.len(), 1);
assert_eq!(TestPack::HANDLERS[0].name, "do_thing");
assert_eq!(TestPack::HANDLERS[0].visibility, Visibility::Verb);
assert_eq!(TestPack::HANDLERS[0].category, VerbCategory::Commissive);
}
#[test]
fn verb_category_variants_exist() {
let _ = VerbCategory::Assertive;
let _ = VerbCategory::Directive;
let _ = VerbCategory::Commissive;
let _ = VerbCategory::Declaration;
}
#[test]
fn pack_validation_rules_default_empty() {
assert!(TestPack::VALIDATION_RULES.is_empty());
}
}