Skip to content

Commit

Permalink
update: replace wit with codegen interface
Browse files Browse the repository at this point in the history
  • Loading branch information
luckasRanarison committed Oct 25, 2024
1 parent 042ae80 commit eb2db29
Show file tree
Hide file tree
Showing 88 changed files with 3,314 additions and 1,083 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ seahash = "4.1.0"
# patterns
anyhow = "1.0.89" # FIXME: replace anyhow with eyre
color-eyre = "0.6.3"
eyre = "0.6.12" # NOTE: keep in sync with verison used by color-eyre
thiserror = "1.0.64"
indoc = "2.0.5"
unindent = "0.2.3"
Expand Down Expand Up @@ -124,7 +123,6 @@ uuid = "1.10.0"
# wasm
wasmtime = "25.0.2"
wasmtime-wasi = "25.0.2"
wit-bindgen = "0.34.0"

# deno
# deno = { path = "../deno/cli" }
Expand All @@ -145,8 +143,6 @@ tracing-subscriber = { version = "0.3.18", features = [
tracing-error = "0.2"
# `unwrap` that also logs
tracing-unwrap = { version = "1.0.1", features = ["log-location"] }
# collect traces to file
tracing-appender = "0.2.3"

# async
futures = "=0.3.30" # pinned due to bug with .31 with zeromq (deno)
Expand Down
5 changes: 0 additions & 5 deletions src/typegraph/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ name = "typegraph_core"
version = "0.5.0-rc.2"
edition = "2021"

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
common.workspace = true
metagen.workspace = true
Expand All @@ -20,8 +17,6 @@ serde_json.workspace = true
indoc.workspace = true
unindent.workspace = true

wit-bindgen.workspace = true

once_cell.workspace = true
regex.workspace = true
indexmap.workspace = true
Expand Down
22 changes: 11 additions & 11 deletions src/typegraph/core/src/conversion/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::errors::Result;
use common::typegraph::{Auth, AuthProtocol, Cors, Rate};
use indexmap::IndexMap;

impl From<crate::wit::core::Cors> for Cors {
fn from(value: crate::wit::core::Cors) -> Self {
impl From<crate::sdk::core::Cors> for Cors {
fn from(value: crate::sdk::core::Cors) -> Self {
Cors {
allow_origin: value.allow_origin,
allow_headers: value.allow_headers,
Expand All @@ -18,8 +18,8 @@ impl From<crate::wit::core::Cors> for Cors {
}
}

impl From<crate::wit::core::Rate> for Rate {
fn from(value: crate::wit::core::Rate) -> Self {
impl From<crate::sdk::core::Rate> for Rate {
fn from(value: crate::sdk::core::Rate) -> Self {
Rate {
window_limit: value.window_limit,
window_sec: value.window_sec,
Expand All @@ -30,17 +30,17 @@ impl From<crate::wit::core::Rate> for Rate {
}
}

impl From<crate::wit::utils::AuthProtocol> for AuthProtocol {
fn from(value: crate::wit::utils::AuthProtocol) -> Self {
impl From<crate::sdk::utils::AuthProtocol> for AuthProtocol {
fn from(value: crate::sdk::utils::AuthProtocol) -> Self {
match value {
crate::wit::utils::AuthProtocol::Oauth2 => AuthProtocol::OAuth2,
crate::wit::utils::AuthProtocol::Jwt => AuthProtocol::Jwt,
crate::wit::utils::AuthProtocol::Basic => AuthProtocol::Basic,
crate::sdk::utils::AuthProtocol::Oauth2 => AuthProtocol::OAuth2,
crate::sdk::utils::AuthProtocol::Jwt => AuthProtocol::Jwt,
crate::sdk::utils::AuthProtocol::Basic => AuthProtocol::Basic,
}
}
}

impl crate::wit::utils::Auth {
impl crate::sdk::utils::Auth {
pub fn convert(&self) -> Result<Auth> {
let mut auth_data = IndexMap::new();
for (k, v) in self.auth_data.iter() {
Expand All @@ -51,7 +51,7 @@ impl crate::wit::utils::Auth {
}
Ok(Auth {
name: self.name.clone(),
protocol: self.protocol.into(),
protocol: self.protocol.clone().into(),
auth_data,
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/typegraph/core/src/conversion/policies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
use common::typegraph::Policy;

use crate::errors::Result;
use crate::sdk::core::PolicySpec;
use crate::typegraph::TypegraphContext;
use crate::wit::core::PolicySpec;

use std::hash::Hash as _;

use super::hash::Hashable;

impl crate::wit::core::Policy {
impl crate::sdk::core::Policy {
pub fn convert(&self, ctx: &mut TypegraphContext) -> Result<Policy> {
let mat_id = ctx.register_materializer(self.materializer)?;
Ok(Policy {
Expand Down
50 changes: 25 additions & 25 deletions src/typegraph/core/src/conversion/runtimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use crate::runtimes::{
DenoMaterializer, Materializer as RawMaterializer, PythonMaterializer, RandomMaterializer,
Runtime, TemporalMaterializer, WasmMaterializer,
};
use crate::wit::core::{Artifact as WitArtifact, RuntimeId};
use crate::wit::runtimes::{
use crate::sdk::core::{Artifact as SdkArtifact, RuntimeId};
use crate::sdk::runtimes::{
HttpMethod, KvMaterializer, MaterializerHttpRequest, SubstantialBackend,
};
use crate::{typegraph::TypegraphContext, wit::runtimes::Effect as WitEffect};
use crate::{sdk::runtimes::Effect as SdkEffect, typegraph::TypegraphContext};
use common::typegraph::runtimes::deno::DenoRuntimeData;
use common::typegraph::runtimes::graphql::GraphQLRuntimeData;
use common::typegraph::runtimes::grpc::GrpcRuntimeData;
Expand Down Expand Up @@ -45,13 +45,13 @@ fn effect(typ: EffectType, idempotent: bool) -> Effect {
}
}

impl From<WitEffect> for Effect {
fn from(eff: WitEffect) -> Self {
impl From<SdkEffect> for Effect {
fn from(eff: SdkEffect) -> Self {
match eff {
WitEffect::Read => effect(EffectType::Read, true),
WitEffect::Create(idemp) => effect(EffectType::Create, idemp),
WitEffect::Update(idemp) => effect(EffectType::Update, idemp),
WitEffect::Delete(idemp) => effect(EffectType::Delete, idemp),
SdkEffect::Read => effect(EffectType::Read, true),
SdkEffect::Create(idemp) => effect(EffectType::Create, idemp),
SdkEffect::Update(idemp) => effect(EffectType::Update, idemp),
SdkEffect::Delete(idemp) => effect(EffectType::Delete, idemp),
}
}
}
Expand All @@ -62,7 +62,7 @@ pub trait MaterializerConverter {
&self,
c: &mut TypegraphContext,
runtime_id: RuntimeId,
effect: WitEffect,
effect: SdkEffect,
) -> Result<common::typegraph::Materializer>;
}

Expand All @@ -71,7 +71,7 @@ impl<T: MaterializerConverter> MaterializerConverter for Rc<T> {
&self,
c: &mut TypegraphContext,
runtime_id: RuntimeId,
effect: WitEffect,
effect: SdkEffect,
) -> Result<common::typegraph::Materializer> {
(**self).convert(c, runtime_id, effect)
}
Expand All @@ -82,7 +82,7 @@ impl MaterializerConverter for DenoMaterializer {
&self,
c: &mut TypegraphContext,
runtime_id: RuntimeId,
effect: WitEffect,
effect: SdkEffect,
) -> Result<Materializer> {
use crate::runtimes::DenoMaterializer::*;
let runtime = c.register_runtime(runtime_id)?;
Expand Down Expand Up @@ -159,12 +159,12 @@ impl MaterializerConverter for MaterializerHttpRequest {
&self,
c: &mut TypegraphContext,
runtime_id: RuntimeId,
effect: WitEffect,
effect: SdkEffect,
) -> Result<common::typegraph::Materializer> {
let runtime = c.register_runtime(runtime_id)?;

let mut data: IndexMap<String, serde_json::Value> = serde_json::from_value(json!({
"verb": http_method(self.method),
"verb": http_method(self.method.clone()),
"path": self.path,
"content_type": self.content_type.as_deref().unwrap_or("application/json"),
"header_prefix": self.header_prefix.as_deref().unwrap_or("header#"),
Expand Down Expand Up @@ -212,7 +212,7 @@ impl MaterializerConverter for PythonMaterializer {
&self,
c: &mut TypegraphContext,
runtime_id: RuntimeId,
effect: WitEffect,
effect: SdkEffect,
) -> Result<Materializer> {
use crate::runtimes::PythonMaterializer::*;
let runtime = c.register_runtime(runtime_id)?;
Expand Down Expand Up @@ -272,7 +272,7 @@ impl MaterializerConverter for RandomMaterializer {
&self,
c: &mut TypegraphContext,
runtime_id: RuntimeId,
effect: WitEffect,
effect: SdkEffect,
) -> Result<Materializer> {
let runtime = c.register_runtime(runtime_id)?;
let RandomMaterializer::Runtime(ret) = self;
Expand All @@ -291,8 +291,8 @@ impl MaterializerConverter for RandomMaterializer {
}
}

impl From<WitArtifact> for Artifact {
fn from(artifact: WitArtifact) -> Self {
impl From<SdkArtifact> for Artifact {
fn from(artifact: SdkArtifact) -> Self {
Artifact {
path: artifact.path.into(),
hash: artifact.hash,
Expand All @@ -301,9 +301,9 @@ impl From<WitArtifact> for Artifact {
}
}

impl From<Artifact> for WitArtifact {
impl From<Artifact> for SdkArtifact {
fn from(artifact: Artifact) -> Self {
WitArtifact {
SdkArtifact {
path: artifact.path.as_os_str().to_str().unwrap().to_string(),
hash: artifact.hash,
size: artifact.size,
Expand All @@ -316,7 +316,7 @@ impl MaterializerConverter for WasmMaterializer {
&self,
c: &mut TypegraphContext,
runtime_id: RuntimeId,
effect: WitEffect,
effect: SdkEffect,
) -> Result<Materializer> {
let runtime = c.register_runtime(runtime_id)?;
let (name, func_name) = match &self {
Expand Down Expand Up @@ -344,7 +344,7 @@ impl MaterializerConverter for TemporalMaterializer {
&self,
c: &mut TypegraphContext,
runtime_id: RuntimeId,
effect: WitEffect,
effect: SdkEffect,
) -> Result<Materializer> {
use crate::runtimes::TemporalMaterializer::*;
let runtime = c.register_runtime(runtime_id)?;
Expand Down Expand Up @@ -390,7 +390,7 @@ impl MaterializerConverter for KvMaterializer {
&self,
c: &mut TypegraphContext,
runtime_id: RuntimeId,
effect: WitEffect,
effect: SdkEffect,
) -> Result<Materializer> {
let runtime = c.register_runtime(runtime_id)?;
let data = serde_json::from_value(json!({})).map_err(|e| e.to_string())?;
Expand Down Expand Up @@ -518,10 +518,10 @@ pub fn convert_runtime(_c: &mut TypegraphContext, runtime: Runtime) -> Result<Co
.map(|desc| WorkflowFileDescription {
file: PathBuf::from(desc.file.clone()),
kind: match desc.kind {
crate::wit::runtimes::WorkflowKind::Python => {
crate::sdk::runtimes::WorkflowKind::Python => {
substantial::WorkflowKind::Python
}
crate::wit::runtimes::WorkflowKind::Deno => {
crate::sdk::runtimes::WorkflowKind::Deno => {
substantial::WorkflowKind::Deno
}
},
Expand Down
18 changes: 17 additions & 1 deletion src/typegraph/core/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@

use std::convert::Infallible;

pub use crate::wit::core::Error as TgError;
pub use crate::sdk::core::Error as TgError;

pub type Result<T, E = TgError> = std::result::Result<T, E>;

impl std::fmt::Display for TgError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.stack.join("\n"))
}
}

impl std::error::Error for TgError {}

impl From<Infallible> for TgError {
fn from(_: Infallible) -> Self {
unreachable!()
Expand All @@ -33,6 +41,14 @@ impl From<anyhow::Error> for TgError {
}
}

impl From<std::io::Error> for TgError {
fn from(e: std::io::Error) -> Self {
Self {
stack: vec![e.to_string()],
}
}
}

impl TgError {
pub fn from_std(e: impl std::error::Error) -> Self {
Self {
Expand Down
10 changes: 5 additions & 5 deletions src/typegraph/core/src/global_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ use crate::errors::{self, Result, TgError};
use crate::runtimes::{
DenoMaterializer, Materializer, MaterializerData, MaterializerDenoModule, Runtime,
};
use crate::sdk::core::{MaterializerId, Policy as CorePolicy, PolicyId, RuntimeId};
use crate::sdk::utils::Auth as SdkAuth;
use crate::types::type_ref::TypeRef;
use crate::types::{
AsTypeDefEx as _, NamedTypeRef, Type, TypeDef, TypeDefExt, TypeId, TypeRefBuilder,
};
use crate::wit::core::{Policy as CorePolicy, PolicyId, RuntimeId};
use crate::wit::utils::Auth as WitAuth;

#[allow(unused)]
use crate::wit::runtimes::{Effect, MaterializerDenoPredefined, MaterializerId};
use crate::sdk::runtimes::{Effect, MaterializerDenoPredefined};
use graphql_parser::parse_query;
use indexmap::IndexMap;
use std::rc::Rc;
Expand Down Expand Up @@ -86,7 +86,7 @@ impl Store {
runtime_id: deno_runtime,
effect: Effect::Read,
data: MaterializerData::Deno(Rc::new(DenoMaterializer::Predefined(
crate::wit::runtimes::MaterializerDenoPredefined {
crate::sdk::runtimes::MaterializerDenoPredefined {
name: "true".to_string(),
},
))),
Expand Down Expand Up @@ -423,7 +423,7 @@ impl Store {
with_store(|s| s.graphql_endpoints.clone())
}

pub fn add_auth(auth: WitAuth) -> Result<u32> {
pub fn add_auth(auth: SdkAuth) -> Result<u32> {
with_store_mut(|s| {
let auth = auth.convert()?;
s.auths.push(auth);
Expand Down
Loading

0 comments on commit eb2db29

Please sign in to comment.