This commit is contained in:
JMARyA 2024-09-23 09:26:11 +02:00
parent 7f32f2429e
commit 65bfb5f8e2
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
10 changed files with 60 additions and 55 deletions

52
Cargo.lock generated
View file

@ -225,9 +225,9 @@ dependencies = [
[[package]]
name = "bson"
version = "2.12.0"
version = "2.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80cf6f7806607bd58ad490bab34bf60e25455ea4aaf995f897a13324d41ea580"
checksum = "068208f2b6fcfa27a7f1ee37488d2bb8ba2640f68f5475d08e1d9130696aba59"
dependencies = [
"ahash",
"base64 0.13.1",
@ -264,9 +264,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "bytes"
version = "1.7.1"
version = "1.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50"
checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3"
[[package]]
name = "case"
@ -276,9 +276,9 @@ checksum = "fd6c0e7b807d60291f42f33f58480c0bfafe28ed08286446f45e463728cf9c1c"
[[package]]
name = "cc"
version = "1.1.18"
version = "1.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b62ac837cdb5cb22e10a256099b4fc502b1dfe560cb282963a974d7abd80e476"
checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0"
dependencies = [
"shlex",
]
@ -328,18 +328,18 @@ dependencies = [
[[package]]
name = "clap"
version = "4.5.17"
version = "4.5.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac"
checksum = "b0956a43b323ac1afaffc053ed5c4b7c1f1800bacd1683c353aabbb752515dd3"
dependencies = [
"clap_builder",
]
[[package]]
name = "clap_builder"
version = "4.5.17"
version = "4.5.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8cf2dd12af7a047ad9d6da2b6b249759a22a7abc0f474c1dae1777afa4b21a73"
checksum = "4d72166dd41634086d5803a47eb71ae740e61d84709c36f3c34110173db3961b"
dependencies = [
"anstream",
"anstyle",
@ -1006,9 +1006,9 @@ dependencies = [
[[package]]
name = "iana-time-zone"
version = "0.1.60"
version = "0.1.61"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141"
checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220"
dependencies = [
"android_system_properties",
"core-foundation-sys",
@ -2038,9 +2038,9 @@ dependencies = [
[[package]]
name = "security-framework-sys"
version = "2.11.1"
version = "2.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf"
checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6"
dependencies = [
"core-foundation-sys",
"libc",
@ -2394,18 +2394,18 @@ dependencies = [
[[package]]
name = "thiserror"
version = "1.0.63"
version = "1.0.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724"
checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.63"
version = "1.0.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261"
checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3"
dependencies = [
"proc-macro2",
"quote",
@ -2565,9 +2565,9 @@ dependencies = [
[[package]]
name = "toml_edit"
version = "0.22.20"
version = "0.22.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d"
checksum = "3b072cee73c449a636ffd6f32bd8de3a9f7119139aff882f44943ce2986dc5cf"
dependencies = [
"indexmap",
"serde",
@ -2763,9 +2763,9 @@ checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
[[package]]
name = "unicode-normalization"
version = "0.1.23"
version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5"
checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956"
dependencies = [
"tinyvec",
]
@ -2778,15 +2778,15 @@ checksum = "52ea75f83c0137a9b98608359a5f1af8144876eb67bcb1ce837368e906a9f524"
[[package]]
name = "unicode-width"
version = "0.1.13"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d"
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
[[package]]
name = "unicode-xid"
version = "0.2.5"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "229730647fbc343e3a80e463c1db7f78f3855d3f3739bee0dda773c9a037c90a"
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
[[package]]
name = "unsafe-libyaml"

5
docs/Flow.md Normal file
View file

@ -0,0 +1,5 @@
# Flow
A flow is used to represent a workflow or manufacturing process.
## Flow Info
You define a flow within a JSON file stored in `./flows`.

View file

@ -64,4 +64,3 @@ variants:
```
This will mark any item variant as expired if it's older than 30 days.

View file

@ -1,7 +1,13 @@
# CDB Documentation
- Item
- Location
- Statistics
- Transaction
- Webhooks
## Basic Concepts
- [Item](./Item.md)
- [Transaction](./Transaction.md)
- [Location](./Location.md)
## Pipelines
- [Flow](./Flow.md)
## Advanced
- [Statistics](./Statistics.md)
- [Webhooks](./Webhooks.md)

View file

@ -8,10 +8,11 @@ Transactions can carry some information:
- Price - The price this item was acquired at
- Origin - Where this item is from
- Location - The [Location](Location.md) of the item
- Note - General notes
## Consume
If an item gets used or is removed from the inventory, you consume the transaction.
This adds some additional information to it:
- Price - The price of the item at removal. e.g the selling price, or if negative cost of removal
- Price - The price of the item at removal. e.g a selling price, or a negative value can represent cost of removal
- Destination - Where this item went, e.g a person who requested this item

View file

@ -1,10 +1,12 @@
use std::collections::HashMap;
use mongod::Model;
use crate::item::Item;
/// Item database
pub struct ItemDB {
index: mdq::Index,
index: HashMap<String, Item>,
}
impl ItemDB {
@ -13,34 +15,27 @@ impl ItemDB {
/// The directory should contain markdown documents with valid frontmatter to be parsed into `Item`s
pub async fn new(dir: &str) -> Self {
// scan for markdown item entries
let index = mdq::Index::new(dir, true);
let index = mdq::Index::new(dir, false);
let mut items = HashMap::new();
for item in &index.documents {
let item = Item::new(item);
item.insert_overwrite().await.unwrap();
log::info!("Adding item {} to DB", item.name);
items.insert(item._id.clone(), item);
}
Self { index }
Self { index: items }
}
/// Retrieves an item by name
pub fn get_item(&self, item: &str) -> Option<Item> {
self.index
.documents
.iter()
.map(Item::new) // <-- todo : performance?
.find(|x| x._id == item)
pub fn get_item(&self, item: &str) -> Option<&Item> {
self.index.get(item)
}
/// Get all items
pub fn items(&self) -> Vec<String> {
let mut ret = vec![];
for item in &self.index.documents {
let item = Item::new(item);
ret.push(item._id.clone());
}
ret
pub fn items(&self) -> Vec<&String> {
self.index.keys().collect()
}
}

View file

@ -80,5 +80,5 @@ pub fn verify_item_variant_exists(item_variant: &str, id: &str, itemdb: &ItemDB)
return Some(true);
}
return None;
None
}

View file

@ -35,9 +35,7 @@ impl Validate for Location {
impl Location {
/// Recursively get the conditions of a location. This inherits from parent locations.
pub fn conditions_rec<'a>(
&'a self,
) -> futures::future::BoxFuture<'a, Option<StorageConditions>> {
pub fn conditions_rec(&self) -> futures::future::BoxFuture<'_, Option<StorageConditions>> {
async move {
if let Some(cond) = &self.conditions {
return Some(cond.clone());
@ -64,7 +62,7 @@ impl Location {
}
// Get all children locations
pub fn children_recursive<'a>(&'a self) -> futures::future::BoxFuture<'a, Vec<Location>> {
pub fn children_recursive(&self) -> futures::future::BoxFuture<'_, Vec<Location>> {
async move {
let mut all = Vec::new();

View file

@ -185,6 +185,7 @@ impl mongod::ToAPI for Transaction {
"variant": self.variant,
"price": self.price,
"origin": self.origin,
"location": self.location.as_ref().map(|x| x.id().to_string()),
"timestamp": self.timestamp,
"consumed": self.consumed,
"note": self.note,

View file

@ -305,7 +305,7 @@ pub fn unique_flows(i: &[String]) -> Vec<String> {
if let Some(suffix) = s.strip_prefix("flow::") {
// Extract the part after "flow::" and split on "::" to get the kind (ignoring id)
let parts: Vec<&str> = suffix.split("::").collect();
if let Some(kind) = parts.get(0) {
if let Some(kind) = parts.first() {
// Build the common prefix "flow::kind"
let common_prefix = format!("flow::{}", kind);