Skip to content

Commit a0a0051

Browse files
committed
feat(cli): deploy (wip)
1 parent ea704d8 commit a0a0051

File tree

12 files changed

+220
-274
lines changed

12 files changed

+220
-274
lines changed

meta-cli/src/cli/codegen.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
use std::path::{Path, PathBuf};
55
use std::sync::Arc;
66

7+
use super::{Action, GenArgs};
8+
use crate::config::Config;
79
use crate::typegraph::loader::LoaderPool;
8-
use crate::{config::Config, typegraph::postprocess};
910
use anyhow::{anyhow, Result};
1011
use async_trait::async_trait;
1112
use clap::{Parser, Subcommand};
1213

13-
use super::{Action, GenArgs};
14-
1514
#[derive(Parser, Debug)]
1615
pub struct Codegen {
1716
#[clap(subcommand)]
@@ -56,8 +55,7 @@ impl Action for Deno {
5655
Config::load_or_find(args.config, &dir).unwrap_or_else(|_| Config::default_in(&dir)),
5756
);
5857

59-
let loader_pool = LoaderPool::new(config, 1)
60-
.with_postprocessor(postprocess::DenoModules::default().codegen(true));
58+
let loader_pool = LoaderPool::new(config, 1);
6159

6260
let loader = loader_pool.get_loader().await?;
6361

meta-cli/src/cli/serialize.rs

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::deploy::actors::console::ConsoleActor;
88
use crate::deploy::actors::loader::{
99
LoadModule, LoaderActor, LoaderEvent, PostProcessOptions, StopBehavior,
1010
};
11+
use crate::typegraph::loader::TypegraphInfos;
1112
use actix::prelude::*;
1213
use anyhow::{bail, Context, Result};
1314
use async_trait::async_trait;
@@ -91,7 +92,7 @@ impl Action for Serialize {
9192
loader.do_send(LoadModule(dir.join(path).into()));
9293
}
9394

94-
let mut loaded: Vec<Box<Typegraph>> = vec![];
95+
let mut loaded: Vec<Box<TypegraphInfos>> = vec![];
9596
let mut event_rx = loader_event_rx;
9697
while let Some(event) = event_rx.recv().await {
9798
log::debug!("event");
@@ -106,37 +107,37 @@ impl Action for Serialize {
106107
}
107108
}
108109

109-
if let Some(prefix) = self.prefix.as_ref() {
110-
for tg in loaded.iter_mut() {
111-
tg.meta.prefix = Some(prefix.clone());
112-
}
113-
}
114-
115-
let tgs = loaded;
116-
117-
if let Some(tg_name) = self.typegraph.as_ref() {
118-
if let Some(tg) = tgs.iter().find(|tg| &tg.name().unwrap() == tg_name) {
119-
self.write(&self.to_string(&tg)?).await?;
120-
} else {
121-
let suggestions = tgs
122-
.iter()
123-
.map(|tg| tg.name().unwrap())
124-
.collect::<Vec<_>>()
125-
.join(", ");
126-
bail!(
127-
"typegraph \"{}\" not found; available typegraphs are: {suggestions}",
128-
tg_name
129-
);
130-
}
131-
} else if self.unique {
132-
if tgs.len() == 1 {
133-
self.write(&self.to_string(&tgs[0])?).await?;
134-
} else {
135-
bail!("expected only one typegraph, got {}", tgs.len());
136-
}
137-
} else {
138-
self.write(&self.to_string(&tgs)?).await?;
139-
}
110+
// if let Some(prefix) = self.prefix.as_ref() {
111+
// for tg in loaded.iter_mut() {
112+
// tg.meta.prefix = Some(prefix.clone());
113+
// }
114+
// }
115+
116+
// let tgs = loaded;
117+
118+
// if let Some(tg_name) = self.typegraph.as_ref() {
119+
// if let Some(tg) = tgs.iter().find(|tg| &tg.name().unwrap() == tg_name) {
120+
// self.write(&self.to_string(&tg)?).await?;
121+
// } else {
122+
// let suggestions = tgs
123+
// .iter()
124+
// .map(|tg| tg.name().unwrap())
125+
// .collect::<Vec<_>>()
126+
// .join(", ");
127+
// bail!(
128+
// "typegraph \"{}\" not found; available typegraphs are: {suggestions}",
129+
// tg_name
130+
// );
131+
// }
132+
// } else if self.unique {
133+
// if tgs.len() == 1 {
134+
// self.write(&self.to_string(&tgs[0])?).await?;
135+
// } else {
136+
// bail!("expected only one typegraph, got {}", tgs.len());
137+
// }
138+
// } else {
139+
// self.write(&self.to_string(&tgs)?).await?;
140+
// }
140141

141142
exit(0); // kill the server
142143
}

meta-cli/src/codegen/deno.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,11 +511,15 @@ mod tests {
511511
LoaderEvent::Typegraph(tg) => tg,
512512
evt => bail!("unexpected loader evt: {evt:?}"),
513513
};
514-
let module_codes = Codegen::new(&tg, &typegraph_test).codegen()?;
515-
assert_eq!(module_codes.len(), 1);
516514

517-
let test_name = typegraph_test.to_string_lossy().to_string();
518-
insta::assert_snapshot!(test_name, &module_codes[0].code);
515+
// TODO:
516+
// run typegraph! thenget serialized version
517+
518+
// let module_codes = Codegen::new(&tg, &typegraph_test).codegen()?;
519+
// assert_eq!(module_codes.len(), 1);
520+
521+
// let test_name = typegraph_test.to_string_lossy().to_string();
522+
// insta::assert_snapshot!(test_name, &module_codes[0].code);
519523

520524
assert!(matches!(
521525
event_rx.recv().await,

meta-cli/src/deploy/actors/loader.rs

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@ use std::sync::Arc;
77

88
use actix::prelude::Context;
99
use actix::prelude::*;
10-
use colored::Colorize;
11-
use common::typegraph::Typegraph;
1210
use tokio::sync::{mpsc, oneshot};
1311

1412
use crate::config::Config;
15-
use crate::typegraph::loader::LoaderPool;
13+
use crate::typegraph::loader::{LoaderPool, TypegraphInfos};
1614
use crate::typegraph::postprocess::{DenoModules, EmbedPrismaMigrations};
17-
use crate::utils::plural_suffix;
1815

1916
use super::console::{Console, ConsoleActor};
2017

@@ -66,7 +63,7 @@ pub enum StopBehavior {
6663

6764
#[derive(Clone, Debug)]
6865
pub enum LoaderEvent {
69-
Typegraph(Box<Typegraph>),
66+
Typegraph(Box<TypegraphInfos>),
7067
Stopped(StopBehavior),
7168
}
7269

@@ -115,12 +112,7 @@ impl LoaderActor {
115112
max_parallel_loads: usize,
116113
postprocess_options: PostProcessOptions,
117114
) -> LoaderPool {
118-
let mut pool = LoaderPool::new(config, max_parallel_loads);
119-
if let Some(deno) = &postprocess_options.deno {
120-
pool = pool.with_postprocessor(deno.clone());
121-
}
122-
123-
pool
115+
LoaderPool::new(config, max_parallel_loads)
124116
}
125117

126118
fn load_module(&self, self_addr: Addr<Self>, path: Arc<Path>) {
@@ -131,7 +123,7 @@ impl LoaderActor {
131123
// TODO error handling?
132124
let loader = loader_pool.get_loader().await.unwrap();
133125
match loader.load_module(path.clone()).await {
134-
Ok(tgs) => self_addr.do_send(LoadedModule(path, tgs)),
126+
Ok(tgs_infos) => self_addr.do_send(LoadedModule(path, tgs_infos)),
135127
Err(e) => {
136128
if counter.is_some() {
137129
// auto stop
@@ -169,7 +161,7 @@ struct SetStoppedTx(oneshot::Sender<StopBehavior>);
169161

170162
#[derive(Message)]
171163
#[rtype(result = "()")]
172-
struct LoadedModule(pub Arc<Path>, Vec<Typegraph>);
164+
struct LoadedModule(pub Arc<Path>, TypegraphInfos);
173165

174166
impl Actor for LoaderActor {
175167
type Context = Context<Self>;
@@ -227,28 +219,8 @@ impl Handler<LoadedModule> for LoaderActor {
227219
type Result = ();
228220

229221
fn handle(&mut self, msg: LoadedModule, ctx: &mut Context<Self>) -> Self::Result {
230-
let LoadedModule(path, tgs) = msg;
231-
let count = tgs.len();
232-
self.console.info(format!(
233-
"Loaded {count} typegraph{s} from {path:?}: {tgs}",
234-
s = plural_suffix(count),
235-
tgs = tgs
236-
.iter()
237-
.map(|tg| tg.name().unwrap().cyan().to_string())
238-
.collect::<Vec<_>>()
239-
.join(", ")
240-
));
241-
for tg in tgs.into_iter() {
242-
if let Err(e) = self.event_tx.send(LoaderEvent::Typegraph(Box::new(tg))) {
243-
self.console
244-
.error(format!("failed to send typegraph: {:?}", e));
245-
if self.counter.is_some() {
246-
// auto stop
247-
ctx.stop();
248-
return;
249-
}
250-
}
251-
}
222+
let LoadedModule(path, tg_infos) = msg;
223+
self.console.info(format!("Loaded 1 file from {path:?}"));
252224
if let Some(counter) = self.counter.as_ref() {
253225
let count = counter.fetch_sub(1, Ordering::SeqCst);
254226
if count == 0 {

meta-cli/src/deploy/actors/push_manager.rs

Lines changed: 63 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use colored::Colorize;
1616
use common::typegraph::Typegraph;
1717
use tokio::sync::oneshot;
1818

19-
use crate::typegraph::postprocess::EmbeddedPrismaMigrationOptionsPatch;
2019
use common::node::Node;
2120

2221
use super::console::{
@@ -225,27 +224,27 @@ impl PushManagerActor {
225224
}
226225
}
227226

228-
pub fn apply_options(&mut self, push: Push) -> Result<Push> {
229-
let typegraph_key = push.typegraph.get_key()?;
230-
if let Some(options) = self.one_time_push_options.remove(&typegraph_key) {
231-
let mut push = push;
232-
for option in options {
233-
match option {
234-
OneTimePushOption::ForceReset { runtime_name } => {
235-
let mut typegraph = (*push.typegraph).clone();
236-
EmbeddedPrismaMigrationOptionsPatch::default()
237-
.reset_on_drift(true)
238-
.apply(&mut typegraph, vec![runtime_name])
239-
.unwrap();
240-
push.typegraph = typegraph.into();
241-
}
242-
}
243-
}
244-
Ok(push)
245-
} else {
246-
Ok(push)
247-
}
248-
}
227+
// pub fn apply_options(&mut self, push: Push) -> Result<Push> {
228+
// let typegraph_key = push.typegraph.get_key()?;
229+
// if let Some(options) = self.one_time_push_options.remove(&typegraph_key) {
230+
// let mut push = push;
231+
// for option in options {
232+
// match option {
233+
// OneTimePushOption::ForceReset { runtime_name } => {
234+
// let mut typegraph = (*push.typegraph).clone();
235+
// EmbeddedPrismaMigrationOptionsPatch::default()
236+
// .reset_on_drift(true)
237+
// .apply(&mut typegraph, vec![runtime_name])
238+
// .unwrap();
239+
// push.typegraph = typegraph.into();
240+
// }
241+
// }
242+
// }
243+
// Ok(push)
244+
// } else {
245+
// Ok(push)
246+
// }
247+
// }
249248
}
250249

251250
impl Actor for PushManagerActor {
@@ -264,15 +263,15 @@ impl Handler<Push> for PushManagerActor {
264263
type Result = ();
265264

266265
fn handle(&mut self, push: Push, _ctx: &mut Self::Context) -> Self::Result {
267-
if self.add_active(&push.typegraph) {
268-
let push = self.apply_options(push).unwrap(); // TODO error handling
269-
270-
self.pusher.do_send(push);
271-
} else {
272-
let tg_name = push.typegraph.name().unwrap().cyan();
273-
self.console
274-
.warning(format!("Typegraph {tg_name} was not pushed."));
275-
}
266+
// if self.add_active(&push.typegraph) {
267+
// // let push = self.apply_options(push).unwrap(); // TODO error handling
268+
269+
// self.pusher.do_send(push);
270+
// } else {
271+
// let tg_name = push.typegraph.name().unwrap().cyan();
272+
// self.console
273+
// .warning(format!("Typegraph {tg_name} was not pushed."));
274+
// }
276275
}
277276
}
278277

@@ -345,39 +344,39 @@ impl Handler<PushFinished> for PushManagerActor {
345344
type Result = ();
346345

347346
fn handle(&mut self, msg: PushFinished, ctx: &mut Self::Context) -> Self::Result {
348-
let name = msg.push.typegraph.name().unwrap();
349-
350-
if msg.success {
351-
self.console.info(format!(
352-
"{} Successfully pushed typegraph {name}.",
353-
"✓".green(),
354-
name = name.cyan()
355-
));
356-
}
357-
358-
let res = self.remove_active(&msg.push.typegraph);
359-
let Some(CancelationStatus(is_cancelled)) = res else {
360-
return;
361-
};
362-
363-
if let Some(follow_up) = msg.follow_up {
364-
use PushFollowUp as F;
365-
match follow_up {
366-
F::ScheduleRetry => {
367-
if !is_cancelled {
368-
self.schedule_retry(msg.push, ctx.address());
369-
}
370-
}
371-
F::Interact(interaction) => {
372-
if !is_cancelled {
373-
let console = self.console.clone();
374-
Arbiter::current().spawn(async move {
375-
Self::interact(console, interaction).await;
376-
});
377-
}
378-
}
379-
}
380-
}
347+
// let name = msg.push.typegraph.name().unwrap();
348+
349+
// if msg.success {
350+
// self.console.info(format!(
351+
// "{} Successfully pushed typegraph {name}.",
352+
// "✓".green(),
353+
// name = name.cyan()
354+
// ));
355+
// }
356+
357+
// let res = self.remove_active(&msg.push.typegraph);
358+
// let Some(CancelationStatus(is_cancelled)) = res else {
359+
// return;
360+
// };
361+
362+
// if let Some(follow_up) = msg.follow_up {
363+
// use PushFollowUp as F;
364+
// match follow_up {
365+
// F::ScheduleRetry => {
366+
// if !is_cancelled {
367+
// self.schedule_retry(msg.push, ctx.address());
368+
// }
369+
// }
370+
// F::Interact(interaction) => {
371+
// if !is_cancelled {
372+
// let console = self.console.clone();
373+
// Arbiter::current().spawn(async move {
374+
// Self::interact(console, interaction).await;
375+
// });
376+
// }
377+
// }
378+
// }
379+
// }
381380
}
382381
}
383382

0 commit comments

Comments
 (0)