Skip to content

Commit 51ec515

Browse files
committed
wip: store artifact deps in global_store
1 parent 1488c88 commit 51ec515

File tree

6 files changed

+61
-22
lines changed

6 files changed

+61
-22
lines changed

libs/common/src/typegraph/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ pub struct Queries {
8989
pub endpoints: Vec<String>,
9090
}
9191

92+
// #[cfg_attr(feature = "codegen", derive(JsonSchema))]
93+
// #[derive(Serialize, Deserialize, Clone, Debug, Default)]
94+
// pub struct DependencyMeta {
95+
// pub name: String,
96+
// pub dep_hash: String,
97+
// pub relative_path_prefix: PathBuf,
98+
// }
99+
92100
#[cfg_attr(feature = "codegen", derive(JsonSchema))]
93101
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
94102
pub struct TypeMeta {
@@ -101,6 +109,7 @@ pub struct TypeMeta {
101109
pub version: String,
102110
pub random_seed: Option<u32>,
103111
pub ref_artifacts: HashMap<String, PathBuf>,
112+
// pub artifact_deps: HashMap<String, Vec<DependencyMeta>>,
104113
}
105114

106115
#[cfg_attr(feature = "codegen", derive(JsonSchema))]

typegraph/core/src/conversion/runtimes.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::collections::HashMap;
66
use std::rc::Rc;
77

88
use crate::errors::Result;
9+
use crate::global_store::Store;
910
use crate::runtimes::prisma::get_prisma_context;
1011
use crate::runtimes::{
1112
DenoMaterializer, Materializer as RawMaterializer, PythonMaterializer, RandomMaterializer,
@@ -231,6 +232,11 @@ impl MaterializerConverter for PythonMaterializer {
231232
Module(module) => {
232233
c.add_ref_artifacts(module.artifact_hash.clone(), module.artifact.clone().into())?;
233234

235+
let deps = module.deps.clone();
236+
for dep in deps {
237+
Store::register_dep(module.artifact_hash.clone(), dep);
238+
}
239+
234240
let data = serde_json::from_value(json!({
235241
"artifact": module.artifact,
236242
"artifact_hash": module.artifact_hash,

typegraph/core/src/global_store.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ use crate::wit::utils::Auth as WitAuth;
1212

1313
#[allow(unused)]
1414
use crate::wit::core::ArtifactResolutionConfig;
15-
use crate::wit::runtimes::{Effect, MaterializerDenoPredefined, MaterializerId};
15+
use crate::wit::runtimes::{
16+
Effect, MaterializerDenoPredefined, MaterializerId, ModuleDependencyMeta,
17+
};
1618
use graphql_parser::parse_query;
1719
use indexmap::IndexMap;
1820
use std::path::PathBuf;
@@ -52,6 +54,9 @@ pub struct Store {
5254
predefined_deno_functions: HashMap<String, MaterializerId>,
5355
deno_modules: HashMap<String, MaterializerId>,
5456

57+
// module dependencies
58+
artifact_deps: HashMap<String, Vec<ModuleDependencyMeta>>,
59+
5560
public_policy_id: PolicyId,
5661

5762
prisma_migration_runtime: RuntimeId,
@@ -237,6 +242,23 @@ impl Store {
237242
with_store_mut(|store| store.random_seed = value)
238243
}
239244

245+
// pub fn get_deps(artifact_hash: String) -> Vec<ModuleDependencyMeta> {
246+
// with_store(|store| match store.artifact_deps.get(&artifact_hash) {
247+
// Some(deps) => deps.clone(),
248+
// None => vec![],
249+
// })
250+
// }
251+
252+
pub fn register_dep(artifact_hash: String, dep: ModuleDependencyMeta) {
253+
with_store_mut(|store| {
254+
store
255+
.artifact_deps
256+
.entry(artifact_hash)
257+
.or_default()
258+
.push(dep)
259+
})
260+
}
261+
240262
pub fn pick_branch_by_path(supertype_id: TypeId, path: &[String]) -> Result<(Type, TypeId)> {
241263
let (_, supertype) = supertype_id.resolve_ref()?;
242264
let supertype = &supertype;

typegraph/core/wit/typegraph.wit

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,17 @@ interface runtimes {
326326
fn: string,
327327
}
328328

329+
record module-dependency-meta {
330+
path: string,
331+
dep-hash: string,
332+
relative-path-prefix: string,
333+
}
334+
329335
record materializer-python-module {
330336
runtime: runtime-id,
331337
artifact: string,
332338
artifact-hash: string,
339+
deps: list<module-dependency-meta>,
333340
}
334341

335342
record materializer-python-import {

typegraph/node/sdk/src/runtimes/python.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33

44
import * as t from "../types.js";
55
import { runtimes } from "../wit.js";
6-
import {
7-
DependencyMeta,
8-
Effect,
9-
} from "../gen/interfaces/metatype-typegraph-runtimes.js";
6+
import { Effect } from "../gen/interfaces/metatype-typegraph-runtimes.js";
107
import { Materializer, Runtime } from "./mod.js";
118
import { fx } from "../index.js";
129
import { getFileHash } from "../utils/file_utils.js";
@@ -110,21 +107,21 @@ export class PythonRuntime extends Runtime {
110107
const artifactHash = await getFileHash(module);
111108

112109
// generate dep meta
113-
const depMetas: DependencyMeta[] = [];
114-
for (const dep of deps) {
115-
const depHash = await getFileHash(dep);
116-
const depMeta: DependencyMeta = {
117-
path: dep,
118-
depHash: depHash,
119-
};
120-
depMetas.push(depMeta);
121-
}
110+
// const depMetas: DependencyMeta[] = [];
111+
// for (const dep of deps) {
112+
// const depHash = await getFileHash(dep);
113+
// const depMeta: DependencyMeta = {
114+
// path: dep,
115+
// depHash: depHash,
116+
// };
117+
// depMetas.push(depMeta);
118+
// }
122119

123120
const matId = runtimes.fromPythonModule(base, {
124121
artifact: module,
125122
runtime: this._id,
126123
artifactHash: artifactHash,
127-
deps: depMetas,
124+
deps: [],
128125
});
129126

130127
const pyModMatId = runtimes.fromPythonImport(base, {

typegraph/python/typegraph/runtimes/python.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
from typing import TYPE_CHECKING, List, Optional
77

88
from astunparse import unparse
9-
109
from typegraph.gen.exports.runtimes import (
1110
BaseMaterializer,
12-
DependencyMeta,
1311
Effect,
1412
EffectRead,
1513
MaterializerPythonDef,
@@ -106,10 +104,10 @@ def import_(
106104

107105
# generate dep_metas
108106
dep_metas = []
109-
for dep in deps:
110-
dep_hash = get_file_hash(dep)
111-
dep_meta = DependencyMeta(path=dep, dep_hash=dep_hash)
112-
dep_metas.append(dep_meta)
107+
# for dep in deps:
108+
# dep_hash = get_file_hash(dep)
109+
# dep_meta = DependencyMeta(path=dep, dep_hash=dep_hash)
110+
# dep_metas.append(dep_meta)
113111

114112
base = BaseMaterializer(runtime=self.id.value, effect=effect)
115113
mat_id = runtimes.from_python_module(
@@ -118,7 +116,7 @@ def import_(
118116
MaterializerPythonModule(
119117
artifact=module,
120118
artifact_hash=artifact_hash,
121-
deps=deps,
119+
deps=dep_metas,
122120
runtime=self.id.value,
123121
),
124122
)

0 commit comments

Comments
 (0)