Skip to main content

server/
script_state.rs

1//! A stored script as the script-edit form holds it, with the revision
2//! digesting its editable fields.
3
4use crate::artifact_mgmt::user::ScriptDetail;
5use crate::logical::hex_digest;
6
7/// The error text of a script edit whose expected revision no longer matches.
8pub const STALE_SCRIPT: &str = "the script changed since it was loaded; reload it";
9
10/// Whether an `enabled` tag value leaves the script on: only `false` turns it off.
11#[must_use]
12pub fn is_enabled(tag: Option<&str>) -> bool {
13    tag != Some("false")
14}
15
16/// Digest of the script's name, source and enabled state.
17#[must_use]
18pub fn script_revision(name: Option<&str>, source: Option<&str>, enabled: bool) -> String {
19    hex_digest(vec![format!("script {:?}", (name, source, enabled))])
20}
21
22impl ScriptDetail {
23    /// The revision an edit of this script must carry.
24    #[must_use]
25    pub fn revision(&self) -> String {
26        script_revision(
27            self.name.as_deref(),
28            self.source.as_deref(),
29            is_enabled(self.enabled.as_deref()),
30        )
31    }
32}