Skip to content

Commit

Permalink
wip: rpc methods
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
luckasRanarison committed Oct 17, 2024
1 parent bcb9bb6 commit fe5318b
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ common = { path = "src/common/" }
substantial = { path = "src/substantial/" }
metagen = { path = "src/metagen/" }
typegate_engine = { path = "src/typegate/engine" }
typegraph_core = { path = "src/typegraph/core" }

# cli
clap = "=4.5.13"
Expand Down
1 change: 1 addition & 0 deletions src/meta-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ typegate = ["dep:typegate_engine"]

# internal
typegate_engine = { workspace = true, optional = true }
typegraph_core.workspace = true
common.workspace = true
metagen.workspace = true

Expand Down
8 changes: 7 additions & 1 deletion src/meta-cli/src/deploy/actors/task/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::deploy::actors::console::Console;
use crate::deploy::actors::task_manager::TaskRef;
use crate::interlude::*;
use crate::secrets::Secrets;
use crate::typegraph::rpc::{TypegraphFunc, TypegraphRpcCall};
use color_eyre::owo_colors::OwoColorize;
use common::node::Node;
use serde::Deserialize;
Expand Down Expand Up @@ -161,7 +162,11 @@ pub enum MigrationActionOverride {
#[serde(tag = "method", content = "params")]
pub enum RpcCall {
GetDeployTarget,
GetDeployData { typegraph: String },
GetDeployData {
typegraph: String,
},
#[serde(untagged)]
Typegraph(TypegraphRpcCall),
}

struct ResetDatabase(PrismaRuntimeId);
Expand Down Expand Up @@ -305,6 +310,7 @@ impl TaskAction for DeployAction {
}

RpcCall::GetDeployData { typegraph } => Ok(self.get_deploy_data(typegraph).await?),
RpcCall::Typegraph(call) => Ok(call.execute()?),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/meta-cli/src/typegraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

pub mod dependency_graph;
pub mod loader;
pub mod rpc;
25 changes: 25 additions & 0 deletions src/meta-cli/src/typegraph/rpc/aws.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use serde::{Deserialize, Serialize};
use serde_json::Value;
use typegraph_core::{
types::{aws::*, core::RuntimeId},
Result,
};

use super::TypegraphFunc;

#[rustfmt::skip]
#[derive(Debug, Serialize, Deserialize)]
pub enum AwsCall {
RegisterS3Runtime { data: S3RuntimeData },
S3PresignGet { runtime: RuntimeId, data: S3PresignGetParams },
S3PresignPut { runtime: RuntimeId, data: S3PresignPutParams },
S3List { runtime: RuntimeId, bucket: String },
S3Upload { runtime: RuntimeId, bucket: String },
S3UploadAll { runtime: RuntimeId, bucket: String },
}

impl TypegraphFunc for AwsCall {
fn execute(&self) -> Result<Value> {
todo!()
}
}
43 changes: 43 additions & 0 deletions src/meta-cli/src/typegraph/rpc/core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use serde::{Deserialize, Serialize};
use serde_json::Value;
use typegraph_core::{types::core::*, Result};

use super::TypegraphFunc;

#[rustfmt::skip]
#[derive(Debug, Serialize, Deserialize)]
pub enum CoreCall {
InitTypegraph { params: TypegraphInitParams },
SerializeTypegraph { params: SerializeParams },
WithInjection { type_id: TypeId, injection: String },
Refb { name: String, attributes: Option<String> },
Integerb { data: TypeInteger, base: TypeBase },
Floatb { data: TypeFloat, base: TypeBase },
Booleanb { base: TypeBase },
Stringb { data: TypeString, base: TypeBase },
Fileb { data: TypeFile, base: TypeBase },
Listb { data: TypeList, base: TypeBase },
Optionalb { data: TypeOptional, base: TypeBase },
Unionb { data: TypeUnion, base: TypeBase },
Eitherb { data: TypeEither, base: TypeBase },
Strucutb { data: TypeStruct, base: TypeBase },
Funcb { data: TypeFunc },
ExtendStruct { type_id: TypeId, props: Vec<(String, Vec<TypeId>)> },
AsId { type_id: TypeId, composite: bool },
GetTypeRepr { type_id: TypeId },
GetTransformData { resolver_input: TypeId, transfrom_type: String },
RegisterPolicy { policy: Policy },
RegisterContextPolicy { key: String, check: ContextCheck },
WithPolicy { type_id: TypeId, policy_chain: Vec<PolicySpec> },
GetPublicPolicy,
GetInternalPolicy,
RenameType { type_id: TypeId, new_name: String },
Expose { fns: Vec<(String, TypeId)>, default_policy: Option<Vec<PolicySpec>> },
SetSeed { seed: Option<u32> },
}

impl TypegraphFunc for CoreCall {
fn execute(&self) -> Result<Value> {
todo!()
}
}
24 changes: 24 additions & 0 deletions src/meta-cli/src/typegraph/rpc/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
mod aws;
mod core;
mod runtimes;
mod utils;

use enum_dispatch::enum_dispatch;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use typegraph_core::Result;

#[enum_dispatch]
pub trait TypegraphFunc {
fn execute(&self) -> Result<Value>;
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
#[enum_dispatch(TypegraphFunc)]
pub enum TypegraphRpcCall {
Core(core::CoreCall),
Runtimes(runtimes::RuntimeCall),
Aws(aws::AwsCall),
Utils(utils::UtilsCall),
}
70 changes: 70 additions & 0 deletions src/meta-cli/src/typegraph/rpc/runtimes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use serde::{Deserialize, Serialize};
use serde_json::Value;
use typegraph_core::{
types::{
core::{RuntimeId, TypeId},
runtimes::*,
},
Result,
};

use super::TypegraphFunc;

#[rustfmt::skip]
#[derive(Debug, Serialize, Deserialize)]
pub enum RuntimeCall {
GetDenoRuntime,
RegisterDenoFunc { data: MaterializerDenoFunc, effect: Effect },
RegisterDenoStatic { data: MaterializerDenoStatic, effect: Effect },
GetPredefindedDenoFunc { data: MaterializerDenoPredefined },
ImportDenoFunction { data: MaterializerDenoImport },
RegisterGraphqlRuntime { data: GraphqlRuntimeData },
GraphqlQuery { base: BaseMaterializer, data: MaterializerGraphqlQuery },
GraphqlMutation { base: BaseMaterializer, data: MaterializerGraphqlQuery },
RegisterHttpRuntime { data: HttpRuntimeData },
HttpRequest { base: BaseMaterializer, data: MaterializerHttpRequest },
RegisterPythonRuntime,
FromPythonLambda { base: BaseMaterializer, data: MaterializerPythonLambda },
FromPythonDef { base: BaseMaterializer, data: MaterializerPythonDef },
FromPythonModule { base: BaseMaterializer, data: MaterializerPythonModule },
FromPythonImport { base: BaseMaterializer, data: MaterializerPythonImport },
RegisterRandomRuntime { data: RandomRuntimeData },
CreateRandomMat { base: BaseMaterializer, data: MaterializerRandom },
RegisterWasmReflectedRuntime { data: WasmRuntimeData },
FromWasmReflectedFunc { base: BaseMaterializer, data: MaterializerWasmReflectedFunc },
RegisterWasmWireRuntime { data: WasmRuntimeData },
FromWasmWireHandler { base: BaseMaterializer, data: MaterializerWasmWireHandler },
RegisterPrismaRuntime { data: PrismaRuntimeData },
PrismaFindUnique { runtime: RuntimeId, model: TypeId },
PrismaFindMany { runtime: RuntimeId, model: TypeId },
PrismaFindFirst { runtime: RuntimeId, model: TypeId },
PrismaAggregate { runtime: RuntimeId, model: TypeId },
PrismaCount { runtime: RuntimeId, model: TypeId },
PrismaGroupBy { runtime: RuntimeId, model: TypeId },
PrismaCreateOne { runtime: RuntimeId, model: TypeId },
PrismaCreateMany { runtime: RuntimeId, model: TypeId },
PrismaUpdateOne { runtime: RuntimeId, model: TypeId },
PrismaUpdateMany { runtime: RuntimeId, model: TypeId },
PrismaUpsertOne { runtime: RuntimeId, model: TypeId },
PrismaDeleteOne { runtime: RuntimeId, model: TypeId },
PrismaDeleteMany { runtime: RuntimeId, model: TypeId },
PrismaExecute { runtime: RuntimeId, query: String, param: TypeId, effect: Effect },
PrismaQueryRaw { runtime: RuntimeId, query: String, param: Option<TypeId>, out: TypeId },
PrismaLink { data: PrismaLinkData },
RegisterTemporalRuntime { data: TemporalRuntimeData },
GenerateTemporalOperation { runtime: RuntimeId, data: TemporalOperationData },
RegisterTypegateMaterializer { operation: TypegateOperation },
RegisterTypegraphMaterializer { operation: TypegraphOperation },
RegisterSubstantialRuntime { data: SubstantialRuntimeData },
GenerateSubstantialOperation { runtime: RuntimeId, data: SubstantialOperationData },
RegisterKvRuntime { data: KvRuntimeData },
KvOperation { base: BaseMaterializer, data: KvMaterializer },
RegisterGrpcRuntime { data: GrpcRuntimeData },
CallGrpcMethod { runtime: RuntimeId, data: GrpcData },
}

impl TypegraphFunc for RuntimeCall {
fn execute(&self) -> Result<Value> {
todo!()
}
}
31 changes: 31 additions & 0 deletions src/meta-cli/src/typegraph/rpc/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use serde::{Deserialize, Serialize};
use serde_json::Value;
use typegraph_core::{
types::{core::TypeId, utils::*},
Result,
};

use super::TypegraphFunc;

#[rustfmt::skip]
#[derive(Debug, Serialize, Deserialize)]
pub enum UtilsCall {
GenReduceb { supertype_id: TypeId, data: Reduce },
AddGraphqlEndpoint { graphql: String },
AddAuth { data: Auth },
AddRawAuth { data: String },
Oauth2 { service_name: String, scopes: String },
Oauth2WithoutProfiler { service_name: String, scopes: String },
Oauth2WithExtendedProfiler { service_name: String, scopes: String, extension: String },
Oauth2WithCustomProfiler { service_name: String, scopes: String, profiler: TypeId },
GqlDeployQuery { params: QueryDeployParams },
GqlRemoveQuery { tg_name: Vec<String> },
MetagenExec { config: FdkConfig },
MetagenWriteFiles { items: Vec<FdkOutput>, typegraph_dir: String },
}

impl TypegraphFunc for UtilsCall {
fn execute(&self) -> Result<Value> {
todo!()
}
}
1 change: 1 addition & 0 deletions src/typegraph/core/src/types/runtimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ pub struct TemporalOperationData {
}

// typegate
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum TypegateOperation {
ListTypegraphs,
FindTypegraph,
Expand Down

0 comments on commit fe5318b

Please sign in to comment.