Fix some things

Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
Marcel Müller 2025-02-08 15:45:21 +01:00
parent 6b1e799d6b
commit e600807376
10 changed files with 421 additions and 81 deletions

236
Cargo.lock generated
View file

@ -4,19 +4,13 @@ version = 4
[[package]]
name = "addr2line"
version = "0.21.0"
version = "0.24.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1"
dependencies = [
"gimli",
]
[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "adler2"
version = "2.0.0"
@ -112,6 +106,17 @@ dependencies = [
"serde_json",
]
[[package]]
name = "async-trait"
version = "0.1.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "644dd749086bf3771a2fbc5f256fdb982d53f011c7d5d560304eafeecebce79d"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "autocfg"
version = "1.4.0"
@ -120,17 +125,17 @@ checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
[[package]]
name = "backtrace"
version = "0.3.71"
version = "0.3.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d"
checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a"
dependencies = [
"addr2line",
"cc",
"cfg-if",
"libc",
"miniz_oxide 0.7.4",
"miniz_oxide",
"object",
"rustc-demangle",
"windows-targets",
]
[[package]]
@ -170,10 +175,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36"
[[package]]
name = "bytes"
version = "1.9.0"
name = "block-buffer"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b"
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
dependencies = [
"generic-array",
]
[[package]]
name = "bytes"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f61dac84819c6588b558454b194026eb1f09c293b9036ae9b159e74e73ab6cf9"
dependencies = [
"serde",
]
@ -189,9 +203,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.2.10"
version = "1.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13208fcbb66eaeffe09b99fffbe1af420f00a7b35aa99ad683dfc1aa76145229"
checksum = "c7777341816418c02e033934a09f20dc0ccaf65a5201ef8a450ae0105a573fda"
dependencies = [
"shlex",
]
@ -204,9 +218,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "4.5.27"
version = "4.5.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "769b0145982b4b48713e01ec42d61614425f27b7058bda7180a3a41f30104796"
checksum = "3e77c3243bd94243c03672cb5154667347c457ca271254724f9f393aee1c05ff"
dependencies = [
"clap_builder",
"clap_derive",
@ -226,9 +240,9 @@ dependencies = [
[[package]]
name = "clap_derive"
version = "4.5.24"
version = "4.5.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54b755194d6389280185988721fffba69495eed5ee9feeee9a599b53db80318c"
checksum = "bf4ced95c6f4a675af3da73304b9ac4ed991640c36374e4b46795c49e17cf1ed"
dependencies = [
"heck",
"proc-macro2",
@ -248,6 +262,15 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
[[package]]
name = "cpufeatures"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
dependencies = [
"libc",
]
[[package]]
name = "crc32fast"
version = "1.4.2"
@ -257,6 +280,16 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "crypto-common"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
dependencies = [
"generic-array",
"typenum",
]
[[package]]
name = "deranged"
version = "0.3.11"
@ -266,6 +299,16 @@ dependencies = [
"powerfmt",
]
[[package]]
name = "digest"
version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [
"block-buffer",
"crypto-common",
]
[[package]]
name = "either"
version = "1.13.0"
@ -288,6 +331,16 @@ dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "filesystem-trustfall-adapter"
version = "0.1.1"
dependencies = [
"serde",
"serde_json",
"sha256",
"trustfall",
]
[[package]]
name = "flate2"
version = "1.0.35"
@ -295,7 +348,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c"
dependencies = [
"crc32fast",
"miniz_oxide 0.8.3",
"miniz_oxide",
]
[[package]]
@ -394,21 +447,32 @@ dependencies = [
]
[[package]]
name = "getrandom"
version = "0.2.15"
name = "generic-array"
version = "0.14.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
dependencies = [
"typenum",
"version_check",
]
[[package]]
name = "getrandom"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43a49c392881ce6d5c3b8cb70f98717b7c07aabbdff06687b9030dbfbe2725f8"
dependencies = [
"cfg-if",
"libc",
"wasi",
"wasi 0.13.3+wasi-0.2.2",
"windows-targets",
]
[[package]]
name = "gimli"
version = "0.28.1"
version = "0.31.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
[[package]]
name = "hashbrown"
@ -422,6 +486,12 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "human-panic"
version = "2.0.2"
@ -478,9 +548,9 @@ checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674"
[[package]]
name = "jiff"
version = "0.1.28"
version = "0.1.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c607c728e28764fecde611a2764a3a5db19ae21dcec46f292244f5cc5c085a81"
checksum = "c04ef77ae73f3cf50510712722f0c4e8b46f5aaa1bf5ffad2ae213e6495e78e5"
dependencies = [
"jiff-tzdb-platform",
"log",
@ -580,9 +650,9 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "miette"
version = "7.4.0"
version = "7.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "317f146e2eb7021892722af37cf1b971f0a70c8406f487e24952667616192c64"
checksum = "1a955165f87b37fd1862df2a59547ac542c77ef6d17c666f619d1ad22dd89484"
dependencies = [
"backtrace",
"backtrace-ext",
@ -601,24 +671,15 @@ dependencies = [
[[package]]
name = "miette-derive"
version = "7.4.0"
version = "7.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23c9b935fbe1d6cbd1dac857b54a688145e2d93f48db36010514d0f612d0ad67"
checksum = "bf45bf44ab49be92fd1227a3be6fc6f617f1a337c06af54981048574d8783147"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "miniz_oxide"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08"
dependencies = [
"adler",
]
[[package]]
name = "miniz_oxide"
version = "0.8.3"
@ -635,7 +696,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd"
dependencies = [
"libc",
"wasi",
"wasi 0.11.0+wasi-snapshot-preview1",
"windows-sys 0.52.0",
]
@ -730,18 +791,18 @@ dependencies = [
[[package]]
name = "object"
version = "0.32.2"
version = "0.36.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441"
checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87"
dependencies = [
"memchr",
]
[[package]]
name = "once_cell"
version = "1.20.2"
version = "1.20.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e"
[[package]]
name = "onig"
@ -846,6 +907,7 @@ version = "0.1.0"
dependencies = [
"camino",
"clap",
"filesystem-trustfall-adapter",
"futures",
"human-panic",
"jiff",
@ -994,9 +1056,9 @@ dependencies = [
[[package]]
name = "ryu"
version = "1.0.18"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
checksum = "6ea1a2d0a644769cc99faa24c3ad26b379b786fe7c36fd3c546254801650e6dd"
[[package]]
name = "same-file"
@ -1035,9 +1097,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.137"
version = "1.0.138"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "930cfb6e6abf99298aaad7d29abbef7a9999a9a8806a40088f55f0dcec03146b"
checksum = "d434192e7da787e94a6ea7e9670b26a036d0ca41e0b7efb2676dd32bae872949"
dependencies = [
"itoa",
"memchr",
@ -1054,6 +1116,30 @@ dependencies = [
"serde",
]
[[package]]
name = "sha2"
version = "0.10.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
]
[[package]]
name = "sha256"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18278f6a914fa3070aa316493f7d2ddfb9ac86ebc06fa3b83bffda487e9065b0"
dependencies = [
"async-trait",
"bytes",
"hex",
"sha2",
"tokio",
]
[[package]]
name = "sharded-slab"
version = "0.1.7"
@ -1135,9 +1221,9 @@ checksum = "b7401a30af6cb5818bb64852270bb722533397edcfc7344954a38f420819ece2"
[[package]]
name = "syn"
version = "2.0.96"
version = "2.0.98"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80"
checksum = "36147f1a48ae0ec2b5b3bc5b537d267457555a10dc06f3dbc8cb11ba3006d3b1"
dependencies = [
"proc-macro2",
"quote",
@ -1323,9 +1409,9 @@ dependencies = [
[[package]]
name = "toml"
version = "0.8.19"
version = "0.8.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e"
checksum = "cd87a5cdd6ffab733b2f74bc4fd7ee5fff6634124999ac278c35fc78c6120148"
dependencies = [
"serde",
"serde_spanned",
@ -1454,6 +1540,12 @@ dependencies = [
"syn",
]
[[package]]
name = "typenum"
version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]]
name = "ucd-trie"
version = "0.1.7"
@ -1486,9 +1578,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "uuid"
version = "1.12.1"
version = "1.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3758f5e68192bb96cc8f9b7e2c2cfdabb435499a28499a42f8f984092adad4b"
checksum = "ced87ca4be083373936a67f8de945faa23b6b42384bd5b64434850802c6dccd0"
dependencies = [
"getrandom",
]
@ -1499,6 +1591,12 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
[[package]]
name = "version_check"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "walkdir"
version = "2.5.0"
@ -1515,6 +1613,15 @@ version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasi"
version = "0.13.3+wasi-0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26816d2e1a4a36a2940b96c5296ce403917633dff8f3440e9b236ed6f6bacad2"
dependencies = [
"wit-bindgen-rt",
]
[[package]]
name = "winapi"
version = "0.3.9"
@ -1630,13 +1737,22 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "winnow"
version = "0.6.25"
version = "0.6.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad699df48212c6cc6eb4435f35500ac6fd3b9913324f938aea302022ce19d310"
checksum = "1e90edd2ac1aa278a5c4599b1d89cf03074b610800f866d4026dc199d7929a28"
dependencies = [
"memchr",
]
[[package]]
name = "wit-bindgen-rt"
version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3268f3d866458b787f390cf61f4bbb563b922d091359f9608842999eaee3943c"
dependencies = [
"bitflags 2.8.0",
]
[[package]]
name = "yaml-rust"
version = "0.4.5"

View file

@ -8,6 +8,7 @@ license.workspace = true
[dependencies]
camino = { version = "1.1.9", features = ["serde", "serde1"] }
clap = { version = "4.5.27", features = ["derive"] }
filesystem-trustfall-adapter = { version = "0.1.1", path = "../../../trustfall-adapters-zimbopro/filesystem-trustfall-adapter" }
futures = "0.3.31"
human-panic = "2.0.2"
jiff = "0.1.28"

View file

@ -8,8 +8,10 @@ use camino::Utf8PathBuf;
use clap::Parser;
use clap::Subcommand;
use clap::ValueHint;
use filesystem_trustfall_adapter::FileSystemAdapter;
use human_panic::Metadata;
use miette::IntoDiagnostic;
use parsing::Definition;
use parsing::Record;
use tracing::info;
use tracing_subscriber::EnvFilter;
@ -64,7 +66,7 @@ async fn main() -> miette::Result<()> {
let records = parsing::load_records(root_folder, &definitions).await?;
let schema = trustfall_plaixt::to_schema(&definitions);
let (schema, adapter) = get_schema_and_adapter(&definitions, records.clone());
match args.mode {
ArgMode::Query => {
@ -75,13 +77,9 @@ async fn main() -> miette::Result<()> {
let result = execute_query(
&schema,
Arc::new(trustfall_plaixt::TrustfallMultiAdapter {
plaixt: trustfall_plaixt::PlaixtAdapter {
records: records.clone(),
},
}),
Arc::new(adapter),
&query,
BTreeMap::<Arc<str>, FieldValue>::from([("search".into(), "trust".into())]),
BTreeMap::<Arc<str>, FieldValue>::from([]),
)
.unwrap()
.collect::<Vec<_>>();
@ -96,6 +94,20 @@ async fn main() -> miette::Result<()> {
Ok(())
}
fn get_schema_and_adapter(
definitions: &BTreeMap<String, Vec<Definition>>,
records: Vec<Record>,
) -> (trustfall::Schema, trustfall_plaixt::TrustfallMultiAdapter) {
let schema = trustfall_plaixt::to_schema(definitions);
let adapter = trustfall_plaixt::TrustfallMultiAdapter {
plaixt: trustfall_plaixt::PlaixtAdapter {
records: records.clone(),
},
filesystem: FileSystemAdapter::new(),
};
(schema, adapter)
}
fn print_records(records: &[Record]) {
for record in records {
println!("{kind} @ {at} {{", kind = record.kind, at = record.at);
@ -105,3 +117,37 @@ fn print_records(records: &[Record]) {
println!("}}")
}
}
#[cfg(test)]
mod tests {
use camino::Utf8PathBuf;
use tracing_subscriber::EnvFilter;
use trustfall::provider::check_adapter_invariants;
use crate::get_schema_and_adapter;
use crate::parsing;
#[tokio::test]
async fn ensure_adapter_satisfies_invariants() {
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.pretty()
.with_test_writer()
.init();
let root_folder = Utf8PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../examples");
println!("{root_folder}");
let definitions = parsing::load_definitions(&root_folder.join("definitions"))
.await
.unwrap();
let records = parsing::load_records(&root_folder, &definitions)
.await
.unwrap();
let (schema, adapter) = get_schema_and_adapter(&definitions, records.clone());
check_adapter_invariants(&schema, adapter);
}
}

View file

@ -15,6 +15,8 @@ use miette::NamedSource;
use owo_colors::OwoColorize;
use tokio_stream::wrappers::ReadDirStream;
use crate::trustfall_plaixt::ADAPTER_SEP;
#[derive(Debug, Clone)]
pub struct Record {
pub(crate) kind: String,
@ -156,6 +158,7 @@ pub(crate) async fn load_records(
#[derive(Debug)]
pub enum DefinitionKind {
String,
Path,
OneOf(Vec<String>),
}
@ -163,6 +166,7 @@ impl DefinitionKind {
pub(crate) fn trustfall_kind(&self) -> String {
match self {
DefinitionKind::String => String::from("String"),
DefinitionKind::Path => format!("fs{ADAPTER_SEP}Path"),
DefinitionKind::OneOf(_vecs) => String::from("String"),
}
}
@ -173,6 +177,10 @@ impl DefinitionKind {
.is_string()
.then_some(())
.ok_or("Expected a string here".to_string()),
DefinitionKind::Path => val
.is_string()
.then_some(())
.ok_or("Expected a path encoded as a string here".to_string()),
DefinitionKind::OneOf(options) => val
.as_string()
.is_some_and(|val| options.iter().any(|o| o == val))
@ -187,6 +195,7 @@ impl TryFrom<&str> for DefinitionKind {
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value.to_ascii_lowercase().as_str() {
"string" => Ok(DefinitionKind::String),
"path" => Ok(DefinitionKind::Path),
other => miette::bail!("Did not recognize valid field kind: \"{other}\""),
}
}

View file

@ -19,7 +19,7 @@ use trustfall::Schema;
use crate::parsing::Definition;
use crate::parsing::Record;
const ADAPTER_SEP: &str = "__";
pub(crate) const ADAPTER_SEP: &str = "__";
#[derive(Debug, Default)]
pub struct StartingVertex {
@ -155,12 +155,29 @@ pub(crate) fn to_schema(definitions: &BTreeMap<String, Vec<Definition>>) -> Sche
{}
type RootSchemaQuery {{
{roots}
fs{ADAPTER_SEP}Path(path: String!): fs{ADAPTER_SEP}Path!,
}}
interface Record {{
at: String!,
kind: String!,
}}
interface fs{ADAPTER_SEP}Path {{
path: String!
}}
type fs{ADAPTER_SEP}Folder implements fs{ADAPTER_SEP}Path {{
path: String!
children: [fs{ADAPTER_SEP}Path!]
}}
type fs{ADAPTER_SEP}File implements fs{ADAPTER_SEP}Path {{
path: String!
size: Int!
extension: String!
Hash: String!
}}
{types}
"#,
Schema::ALL_DIRECTIVE_DEFINITIONS,
@ -179,11 +196,23 @@ pub(crate) fn to_schema(definitions: &BTreeMap<String, Vec<Definition>>) -> Sche
pub struct TrustfallMultiAdapter {
pub plaixt: PlaixtAdapter,
pub filesystem: filesystem_trustfall_adapter::FileSystemAdapter,
}
#[derive(Debug, Clone)]
pub enum TrustfallMultiVertex {
Plaixt(PlaixtVertex),
Filesystem(filesystem_trustfall_adapter::vertex::Vertex),
}
impl AsVertex<filesystem_trustfall_adapter::vertex::Vertex> for TrustfallMultiVertex {
fn as_vertex(&self) -> Option<&filesystem_trustfall_adapter::vertex::Vertex> {
self.as_filesystem()
}
fn into_vertex(self) -> Option<filesystem_trustfall_adapter::vertex::Vertex> {
self.as_filesystem().cloned()
}
}
impl AsVertex<PlaixtVertex> for TrustfallMultiVertex {
@ -204,6 +233,20 @@ impl TrustfallMultiVertex {
None
}
}
pub fn as_filesystem(
&self,
) -> Option<
&<filesystem_trustfall_adapter::FileSystemAdapter as trustfall::provider::Adapter<
'static,
>>::Vertex,
> {
if let Self::Filesystem(v) = self {
Some(v)
} else {
None
}
}
}
impl<'v> Adapter<'v> for TrustfallMultiAdapter {
@ -217,7 +260,11 @@ impl<'v> Adapter<'v> for TrustfallMultiAdapter {
) -> trustfall::provider::VertexIterator<'v, Self::Vertex> {
let (adapter_name, edge_name) = edge_name.split_once(ADAPTER_SEP).unwrap();
trace!(?adapter_name, ?edge_name, "Got start vertex");
trace!(
?adapter_name,
?edge_name,
"resolving top-level starting vertex"
);
match adapter_name {
"Plaixt" => {
@ -229,6 +276,18 @@ impl<'v> Adapter<'v> for TrustfallMultiAdapter {
Box::new(iter.map(TrustfallMultiVertex::Plaixt))
}
"fs" => {
let iter = self.filesystem.resolve_starting_vertices(
&Arc::from(edge_name),
parameters,
resolve_info,
);
Box::new(
iter.inspect(|v| trace!(?v, "Got vertex"))
.map(TrustfallMultiVertex::Filesystem),
)
}
_ => unreachable!(),
}
}
@ -243,7 +302,10 @@ impl<'v> Adapter<'v> for TrustfallMultiAdapter {
where
V: trustfall::provider::AsVertex<Self::Vertex> + 'v,
{
let (adapter_name, type_name) = type_name.split_once(ADAPTER_SEP).unwrap();
trace!(?type_name, ?property_name, "resolving top-level property");
let (adapter_name, type_name) = type_name
.split_once(ADAPTER_SEP)
.unwrap_or(("Plaixt", type_name));
match adapter_name {
"Plaixt" => {
@ -268,6 +330,29 @@ impl<'v> Adapter<'v> for TrustfallMultiAdapter {
.map(|((_ctx, name), og_ctx)| (og_ctx, name)),
)
}
"fs" => {
let contexts = contexts.collect::<Vec<_>>();
let properties = self.filesystem.resolve_property(
Box::new(
contexts
.clone()
.into_iter()
.map(|v| v.flat_map(&mut |v: V| v.into_vertex()))
.inspect(|v| trace!(?v, "Got vertex")),
),
&Arc::from(type_name),
property_name,
resolve_info,
);
Box::new(
properties
.into_iter()
.zip(contexts)
.map(|((_ctx, name), og_ctx)| (og_ctx, name)),
)
}
_ => unreachable!(),
}
}
@ -284,6 +369,7 @@ impl<'v> Adapter<'v> for TrustfallMultiAdapter {
V,
trustfall::provider::VertexIterator<'v, Self::Vertex>,
> {
trace!(?type_name, ?edge_name, "Resolving top-level neighbor");
let (adapter_name, type_name) = type_name.split_once(ADAPTER_SEP).unwrap();
match adapter_name {
@ -315,6 +401,37 @@ impl<'v> Adapter<'v> for TrustfallMultiAdapter {
}),
)
}
"fs" => {
let contexts = contexts.collect::<Vec<_>>();
let properties = self.filesystem.resolve_neighbors(
Box::new(
contexts
.clone()
.into_iter()
.map(|v| v.flat_map(&mut |v: V| v.into_vertex())),
),
&Arc::from(type_name),
edge_name,
parameters,
resolve_info,
);
Box::new(
properties
.into_iter()
.zip(contexts)
.map(|((_ctx, vals), og_ctx)| {
(
og_ctx,
Box::new(
vals.inspect(|v| trace!(?v, "Got vertex"))
.map(TrustfallMultiVertex::Filesystem),
) as Box<_>,
)
}),
)
}
_ => unreachable!(),
}
}
@ -326,7 +443,7 @@ impl<'v> Adapter<'v> for TrustfallMultiAdapter {
coerce_to_type: &Arc<str>,
resolve_info: &trustfall::provider::ResolveInfo,
) -> trustfall::provider::ContextOutcomeIterator<'v, V, bool> {
trace!(?type_name, ?coerce_to_type, "Trying to coerce");
trace!(?type_name, ?coerce_to_type, "Top-level coerce");
let (adapter_name, coerce_to_type) = coerce_to_type.split_once(ADAPTER_SEP).unwrap();
match adapter_name {
@ -352,6 +469,30 @@ impl<'v> Adapter<'v> for TrustfallMultiAdapter {
.map(|((_ctx, val), og_ctx)| (og_ctx, val)),
)
}
"fs" => {
let contexts = contexts.collect::<Vec<_>>();
let properties = self.filesystem.resolve_coercion(
Box::new(
contexts
.clone()
.into_iter()
.map(|v| v.flat_map(&mut |v: V| v.into_vertex())),
),
type_name,
&Arc::from(coerce_to_type),
resolve_info,
);
let type_name = type_name.clone();
let coerce_to_type = coerce_to_type.to_string();
Box::new(properties.into_iter().zip(contexts).map(
move |((_ctx, allowed), og_ctx)| {
trace!(?allowed, ?type_name, ?coerce_to_type, "Allowed coercion?");
(og_ctx, allowed)
},
))
}
_ => unreachable!(),
}
}
@ -454,7 +595,7 @@ impl<'a> Adapter<'a> for PlaixtAdapter {
fn resolve_neighbors<V: trustfall::provider::AsVertex<Self::Vertex> + 'a>(
&self,
contexts: trustfall::provider::ContextIterator<'a, V>,
_type_name: &Arc<str>,
type_name: &Arc<str>,
edge_name: &Arc<str>,
_parameters: &trustfall::provider::EdgeParameters,
_resolve_info: &trustfall::provider::ResolveEdgeInfo,
@ -463,6 +604,7 @@ impl<'a> Adapter<'a> for PlaixtAdapter {
V,
trustfall::provider::VertexIterator<'a, Self::Vertex>,
> {
trace!(?type_name, ?edge_name, "Resolving neighbors");
match edge_name.as_ref() {
"fields" => resolve_neighbors_with(contexts, |c| {
Box::new(
@ -474,7 +616,8 @@ impl<'a> Adapter<'a> for PlaixtAdapter {
.into_iter(),
)
}),
_ => unreachable!(),
_ => resolve_neighbors_with(contexts, |c| todo!()),
_ => unreachable!("Could not resolve {edge_name}"),
}
}

View file

@ -21,3 +21,7 @@ changelog "2025-02-07" {
version "0.1.0"
type "Feature"
}
file_test "2025-02-08" {
path "Cargo.toml"
}

View file

@ -0,0 +1,7 @@
// This is the default changelog entry for the plaixt project
define since="2025-02-08 00:00:00+01:00" {
fields {
path is="Path"
}
}

6
flake.lock generated
View file

@ -63,11 +63,11 @@
]
},
"locked": {
"lastModified": 1738117527,
"narHash": "sha256-GFviGfaezjGLFUlxdv3zyC7rSZvTXqwcG/YsF6MDkOw=",
"lastModified": 1738981474,
"narHash": "sha256-YIELTXxfATG0g1wXjyaOWA4qrlubds3MG4FvMPCxSGg=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "6a3dc6ce4132bd57359214d986db376f2333c14d",
"rev": "5c571e5ff246d8fc5f76ba6e38dc8edb6e4002fe",
"type": "github"
},
"original": {

22
query
View file

@ -1,13 +1,27 @@
{
Plaixt__RecordsAll {
... on Plaixt__changelog {
... on Plaixt__file_test {
at @output
kind @output
fields {
title @output @filter(op: "has_substring", value: ["$search"])
version @output
type @output
path {
... on fs__File {
size @output
}
}
}
}
}
# fs__Path(path: "./crates/plaixt/") {
# ... on fs__Folder {
# directory: path @output
# children @fold {
# ... on fs__File {
# file: path @output
# size @output
# }
# }
# }
# }
}

View file

@ -1,2 +1,2 @@
[toolchain]
channel = "1.84.0"
channel = "1.84.1"