-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
174 additions
and
46 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
function onRequest({request}) { | ||
return {request} | ||
} | ||
|
||
function hello(val) { | ||
let json = JSON.parse(val) | ||
return JSON.stringify(json.id) | ||
} |
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
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
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
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,53 @@ | ||
use std::sync::Arc; | ||
|
||
use crate::blueprint::*; | ||
use crate::config; | ||
use crate::config::Field; | ||
use crate::javascript::Runtime; | ||
Check failure on line 6 in src/blueprint/operators/js.rs GitHub Actions / Test AWS Lambda Build
|
||
use crate::lambda::Expression; | ||
use crate::try_fold::TryFold; | ||
use crate::valid::{Valid, ValidationError, Validator}; | ||
|
||
pub struct CompileJs<'a> { | ||
pub name: &'a str, | ||
pub script: &'a Option<String>, | ||
} | ||
|
||
pub fn compile_js(inputs: CompileJs) -> Valid<Expression, String> { | ||
let name = inputs.name; | ||
let quickjs = rquickjs::Runtime::new().unwrap(); | ||
Check failure on line 18 in src/blueprint/operators/js.rs GitHub Actions / Test AWS Lambda Build
|
||
let ctx = rquickjs::Context::full(&quickjs).unwrap(); | ||
Check failure on line 19 in src/blueprint/operators/js.rs GitHub Actions / Test AWS Lambda Build
|
||
|
||
Valid::from_option(inputs.script.as_ref(), "script is required".to_string()).and_then( | ||
|script| { | ||
Valid::from( | ||
ctx.with(|ctx| { | ||
ctx.eval::<(), &str>(script)?; | ||
Ok::<_, anyhow::Error>(()) | ||
}) | ||
.map_err(|e| ValidationError::new(e.to_string())), | ||
) | ||
.map(|_| { | ||
Expression::Js(Arc::new(Runtime::new( | ||
name.to_string(), | ||
Script { source: script.clone(), timeout: None }, | ||
))) | ||
}) | ||
}, | ||
) | ||
} | ||
|
||
pub fn update_js_field<'a>( | ||
) -> TryFold<'a, (&'a ConfigModule, &'a Field, &'a config::Type, &'a str), FieldDefinition, String> | ||
{ | ||
TryFold::<(&ConfigModule, &Field, &config::Type, &str), FieldDefinition, String>::new( | ||
|(module, field, _, _), b_field| { | ||
let Some(js) = &field.script else { | ||
return Valid::succeed(b_field); | ||
}; | ||
|
||
compile_js(CompileJs { script: &module.extensions.script, name: &js.name }) | ||
.map(|resolver| b_field.resolver(Some(resolver))) | ||
}, | ||
) | ||
} |
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
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
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
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
File renamed without changes.
File renamed without changes.
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
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
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
File renamed without changes.
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
Oops, something went wrong.