Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove runtime field from TypeNode #858

Closed
wants to merge 10 commits into from
1 change: 0 additions & 1 deletion src/common/src/typegraph/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ pub enum Injection {
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct TypeNodeBase {
pub title: String,
pub runtime: u32,
pub policies: Vec<PolicyIndices>,
#[serde(default)]
pub description: Option<String>,
Expand Down
2 changes: 1 addition & 1 deletion src/meta-cli/src/cli/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl Deploy {
let dir: Arc<Path> = args.dir()?.into();

let config_path = args.config.clone();
let config = Arc::new(Config::load_or_find(config_path, &dir)?);
let config = Arc::new(Config::load_or_find(config_path.as_deref(), &dir)?);

let options = deploy.options.clone();

Expand Down
2 changes: 1 addition & 1 deletion src/meta-cli/src/cli/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl Action for Doctor {
}
println!();

let config = Config::load_or_find(args.config.clone(), dir);
let config = Config::load_or_find(args.config.as_deref(), dir);

ui::title("Project", w);
match config {
Expand Down
2 changes: 1 addition & 1 deletion src/meta-cli/src/cli/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Action for Gen {
#[tracing::instrument]
async fn run(&self, args: ConfigArgs) -> Result<()> {
let dir = args.dir()?;
let config = Config::load_or_find(args.config, &dir)?;
let config = Config::load_or_find(args.config.as_deref(), &dir)?;
let config = Arc::new(config);

let Some(mgen_conf) = &config.metagen else {
Expand Down
2 changes: 1 addition & 1 deletion src/meta-cli/src/cli/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Action for List {
async fn run(&self, args: ConfigArgs) -> Result<()> {
let dir = args.dir()?;
let config_path = args.config.clone();
let config = Arc::new(Config::load_or_find(config_path, &dir)?);
let config = Arc::new(Config::load_or_find(config_path.as_deref(), &dir)?);

let mut node_config = config.node(&self.node, &self.target);
if self.target == "dev" {
Expand Down
7 changes: 5 additions & 2 deletions src/meta-cli/src/cli/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ impl Action for Serialize {
let dir = args.dir()?;
let config_path = args.config.clone();

let config = Config::load_or_find(config_path, &dir)?;

let config =
Config::load_or_find(config_path.as_deref(), &dir).or_else(|e| match config_path {
Some(_) => Err(e),
_ => Ok(Config::default_in(&dir)),
})?;
let config = Arc::new(config);

let console = ConsoleActor::new(Arc::clone(&config)).start();
Expand Down
2 changes: 1 addition & 1 deletion src/meta-cli/src/cli/undeploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Action for Undeploy {
async fn run(&self, args: super::ConfigArgs) -> Result<()> {
let dir = args.dir()?;
let config_path = args.config.clone();
let config = Config::load_or_find(config_path, &dir)?;
let config = Config::load_or_find(config_path.as_deref(), &dir)?;
let node_config = config.node(&self.node, &self.target);
let node = node_config.build(&dir).await?;

Expand Down
11 changes: 6 additions & 5 deletions src/meta-cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,12 @@ impl Config {

/// Load config file:
/// if the config_path is None, search the config file recursively on parent directories.
pub fn load_or_find<P: AsRef<Path>>(
config_path: Option<PathBuf>,
search_start_dir: P,
pub fn load_or_find(
config_path: Option<&Path>,
search_start_dir: impl AsRef<Path>,
) -> Result<Config> {
if let Some(path) = config_path {
Config::from_file(&path).with_context(|| format!("config file not found at {path:?}"))
Config::from_file(path).with_context(|| format!("config file not found at {path:?}"))
} else {
Ok(Config::find(search_start_dir)?
.ok_or_else(|| ferr!("could not find config file"))?)
Expand Down Expand Up @@ -334,6 +334,7 @@ impl Config {
pub fn dir(&self) -> Result<&Path> {
self.path
.as_deref()
.or(Some(self.base_dir.as_path()))
.ok_or_else(|| ferr!("config path required"))?
.parent()
.ok_or_else(|| ferr!("config path has no parent"))
Expand All @@ -351,7 +352,7 @@ mod tests {
fn load_missing_config_file() -> Result<()> {
let project_root = get_project_root()?;
let path = project_root.join("path/to/metatype.yml");
let load_res = Config::load_or_find(Some(path), project_root);
let load_res = Config::load_or_find(Some(&path), project_root);
assert_err_contains(load_res, "config file not found at");
Ok(())
}
Expand Down
1 change: 0 additions & 1 deletion src/metagen/src/tests/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ pub fn default_type_node_base() -> TypeNodeBase {
title: String::new(),
as_id: false,
config: Default::default(),
runtime: 0,
policies: vec![],
injection: None,
description: None,
Expand Down
6 changes: 5 additions & 1 deletion src/typegate/src/engine/planner/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,11 @@ export class Planner {
);
}

const runtime = this.tg.runtimeReferences[schema.runtime];
const runtime = (schema.type === Type.FUNCTION)
? this.tg
.runtimeReferences[(this.tg.materializer(schema.materializer)).runtime]
: node.parentStage?.props.runtime ??
this.tg.runtimeReferences[this.tg.denoRuntimeIdx];

const stage = this.createComputeStage(node, {
dependencies: node.parentStage ? [node.parentStage.id()] : [],
Expand Down
1 change: 0 additions & 1 deletion src/typegate/src/engine/typecheck/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ export class ResultValidationCompiler {
cg.generateStringValidator({
type: "string",
title: "__TypeName",
runtime: -1,
policies: [],
as_id: false,
});
Expand Down
2 changes: 0 additions & 2 deletions src/typegate/src/runtimes/typegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ interface TypeInfo {
as_id: boolean;
title: string;
type: string;
runtime: string;
/** list of json string */
enum: string[] | null;
/** json string */
Expand Down Expand Up @@ -562,7 +561,6 @@ function walkPath(
title: node.title,
type: node.type,
enum: node.enum ?? null,
runtime: tg.runtime(node.runtime).name,
config: node.config ? JSON.stringify(node.config) : null,
default: defaultValue ? JSON.stringify(defaultValue) : null,
format: format ?? null,
Expand Down
10 changes: 8 additions & 2 deletions src/typegate/src/typegraph/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ import randomizeRecursively from "../runtimes/random.ts";
import type { Typegate } from "../typegate/mod.ts";
import { TypeUtils } from "./utils.ts";

export type { Cors, Rate, TypeGraphDS, TypeMaterializer, TypePolicy, TypeRuntime };
export type {
Cors,
Rate,
TypeGraphDS,
TypeMaterializer,
TypePolicy,
TypeRuntime,
};

export type RuntimeResolver = Record<string, Runtime>;

Expand Down Expand Up @@ -89,7 +96,6 @@ export class TypeGraph implements AsyncDisposable {
title: "string",
type: "string",
policies: [],
runtime: -1,
as_id: false,
};

Expand Down
12 changes: 0 additions & 12 deletions src/typegate/src/typegraph/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
export type OptionalNode = {
type: "optional";
title: string;
runtime: number;
policies: PolicyIndices[];
description?: string | null;
injection?: Injection | null;
Expand All @@ -21,7 +20,6 @@ export type OptionalNode = {
export type BooleanNode = {
type: "boolean";
title: string;
runtime: number;
policies: PolicyIndices[];
description?: string | null;
injection?: Injection | null;
Expand All @@ -34,7 +32,6 @@ export type BooleanNode = {
export type FloatNode = {
type: "float";
title: string;
runtime: number;
policies: PolicyIndices[];
description?: string | null;
injection?: Injection | null;
Expand All @@ -52,7 +49,6 @@ export type FloatNode = {
export type IntegerNode = {
type: "integer";
title: string;
runtime: number;
policies: PolicyIndices[];
description?: string | null;
injection?: Injection | null;
Expand All @@ -70,7 +66,6 @@ export type IntegerNode = {
export type StringNode = {
type: "string";
title: string;
runtime: number;
policies: PolicyIndices[];
description?: string | null;
injection?: Injection | null;
Expand All @@ -87,7 +82,6 @@ export type StringNode = {
export type FileNode = {
type: "file";
title: string;
runtime: number;
policies: PolicyIndices[];
description?: string | null;
injection?: Injection | null;
Expand All @@ -103,7 +97,6 @@ export type FileNode = {
export type ObjectNode = {
type: "object";
title: string;
runtime: number;
policies: PolicyIndices[];
description?: string | null;
injection?: Injection | null;
Expand All @@ -120,7 +113,6 @@ export type ObjectNode = {
export type ListNode = {
type: "list";
title: string;
runtime: number;
policies: PolicyIndices[];
description?: string | null;
injection?: Injection | null;
Expand All @@ -137,7 +129,6 @@ export type ListNode = {
export type FunctionNode = {
type: "function";
title: string;
runtime: number;
policies: PolicyIndices[];
description?: string | null;
injection?: Injection | null;
Expand All @@ -156,7 +147,6 @@ export type FunctionNode = {
export type UnionNode = {
type: "union";
title: string;
runtime: number;
policies: PolicyIndices[];
description?: string | null;
injection?: Injection | null;
Expand All @@ -170,7 +160,6 @@ export type UnionNode = {
export type EitherNode = {
type: "either";
title: string;
runtime: number;
policies: PolicyIndices[];
description?: string | null;
injection?: Injection | null;
Expand All @@ -184,7 +173,6 @@ export type EitherNode = {
export type AnyNode = {
type: "any";
title: string;
runtime: number;
policies: PolicyIndices[];
description?: string | null;
injection?: Injection | null;
Expand Down
Loading
Loading