-
Notifications
You must be signed in to change notification settings - Fork 26.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Alex Kirszenberg <alexkirsz@users.noreply.github.com>
- Loading branch information
Showing
8 changed files
with
502 additions
and
312 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use napi::{bindgen_prelude::External, JsFunction}; | ||
use next_api::route::{Endpoint, EndpointVc, WrittenEndpoint}; | ||
|
||
use super::utils::{subscribe, RootTask, VcArc}; | ||
|
||
#[napi(object)] | ||
pub struct NapiWrittenEndpoint { | ||
pub server_entry_path: String, | ||
pub server_paths: Vec<String>, | ||
pub client_paths: Vec<String>, | ||
} | ||
|
||
impl From<&WrittenEndpoint> for NapiWrittenEndpoint { | ||
fn from(written_endpoint: &WrittenEndpoint) -> Self { | ||
Self { | ||
server_entry_path: written_endpoint.server_entry_path.clone(), | ||
server_paths: written_endpoint.server_paths.clone(), | ||
client_paths: written_endpoint.client_paths.clone(), | ||
} | ||
} | ||
} | ||
|
||
#[napi] | ||
pub async fn endpoint_write_to_disk( | ||
#[napi(ts_arg_type = "{ __napiType: \"Endpoint\" }")] endpoint: External<VcArc<EndpointVc>>, | ||
) -> napi::Result<NapiWrittenEndpoint> { | ||
let turbo_tasks = endpoint.turbo_tasks().clone(); | ||
let endpoint = **endpoint; | ||
let written = turbo_tasks | ||
.run_once(async move { Ok(endpoint.write_to_disk().strongly_consistent().await?) }) | ||
.await?; | ||
Ok((&*written).into()) | ||
} | ||
|
||
#[napi(ts_return_type = "{ __napiType: \"RootTask\" }")] | ||
pub fn endpoint_changed_subscribe( | ||
#[napi(ts_arg_type = "{ __napiType: \"Endpoint\" }")] endpoint: External<VcArc<EndpointVc>>, | ||
func: JsFunction, | ||
) -> napi::Result<External<RootTask>> { | ||
let turbo_tasks = endpoint.turbo_tasks().clone(); | ||
let endpoint = **endpoint; | ||
subscribe( | ||
turbo_tasks, | ||
func, | ||
move || { | ||
let endpoint = endpoint.clone(); | ||
async move { | ||
endpoint.changed().await?; | ||
Ok(()) | ||
} | ||
}, | ||
|_ctx| Ok(vec![()]), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod endpoint; | ||
pub mod project; | ||
pub mod utils; |
Oops, something went wrong.