Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6c14956
Remote save
SilasMarvin Jul 14, 2023
3b2e3b5
Working remote embeddings
SilasMarvin Jul 17, 2023
f1d6bf7
Compiling
SilasMarvin Jul 19, 2023
22f280e
Commit before moving everything to lazy
SilasMarvin Jul 19, 2023
ec090ca
Working lazy python
SilasMarvin Jul 21, 2023
58c01a3
Commit before moving adjusting Javascript macros
SilasMarvin Jul 21, 2023
9e7b146
Working javascript sdk
SilasMarvin Jul 22, 2023
abb4f5e
Working javascript sdk
SilasMarvin Jul 26, 2023
76ccf3a
The start of working pipelines
SilasMarvin Jul 28, 2023
cfcc66b
Working pipelines in python
SilasMarvin Aug 3, 2023
a9dcbc9
Uncomment
SilasMarvin Aug 3, 2023
8b48750
Added to_dict function
SilasMarvin Aug 3, 2023
6e3f1e6
Small changes and prep for progress bars
SilasMarvin Aug 4, 2023
5365557
Working progress bars and many other small but exciting things
SilasMarvin Aug 4, 2023
66476ff
Prepping to push to test pypi
SilasMarvin Aug 7, 2023
f2613d7
Prepping for javascript
SilasMarvin Aug 8, 2023
92c9623
Improvments to javascript and updates to the python sdk deploy script
SilasMarvin Aug 8, 2023
8a4e3cf
Prepping for real tests
SilasMarvin Aug 8, 2023
12bb3a8
Updated sql
SilasMarvin Aug 9, 2023
2b5b68b
Python examples translated to use pipelines
SilasMarvin Aug 9, 2023
447fc80
Mostly cleaned up and documented crate, and cleaned up python README …
SilasMarvin Aug 10, 2023
333c5e6
Ready for test deployments
SilasMarvin Aug 10, 2023
11bcce2
Updated manual build file for python
SilasMarvin Aug 10, 2023
845bf02
Build fast
SilasMarvin Aug 11, 2023
4904a1a
Small tweaks
SilasMarvin Aug 11, 2023
64dc7e2
Prepping for another test release
SilasMarvin Aug 11, 2023
c3b274c
Prepping to expand query_builder
SilasMarvin Aug 11, 2023
cb143a5
Massive cleanups to macros
SilasMarvin Aug 11, 2023
c66b07b
Massive cleanups to macros
SilasMarvin Aug 11, 2023
b7d4c2d
Ready to release
SilasMarvin Aug 11, 2023
a2c87b1
Formatting
SilasMarvin Aug 13, 2023
dd9c3ab
Renamed files
SilasMarvin Aug 21, 2023
5568608
Added removed file
SilasMarvin Aug 21, 2023
4a2e98d
Removed unnecessary file
SilasMarvin Aug 21, 2023
e673af4
Updated sdk version to 0.9
SilasMarvin Aug 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Working javascript sdk
  • Loading branch information
SilasMarvin committed Aug 21, 2023
commit abb4f5e15f24e97c9597d9cc409f9cd78034c1a0
157 changes: 74 additions & 83 deletions pgml-sdks/rust/pgml-macros/src/javascript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,67 @@ use std::io::{Read, Write};
use syn::{visit::Visit, DeriveInput, ItemImpl, Type};

use crate::common::{AttributeArgs, GetImplMethod};
use crate::types::{GetSupportedType, OutputType, SupportedType};

pub fn generate_custom_into_js_result(parsed: DeriveInput) -> proc_macro::TokenStream {
let name = parsed.ident;
let fields_named = match parsed.data {
syn::Data::Struct(s) => match s.fields {
syn::Fields::Named(n) => n,
_ => panic!("custom_into_js proc_macro structs should only have named fields"),
},
_ => panic!("custom_into_js proc_macro should only be used on structs"),
};

let mut sets = Vec::new();
let mut interface = format!("\ninterface {} {{\n", name);

fields_named.named.into_pairs().for_each(|p| {
let v = p.into_value();
let name = v.ident.to_token_stream().to_string();
let name_ident = v.ident;
sets.push(quote! {
let js_item = self.#name_ident.into_js_result(cx)?;
js_object.set(cx, #name, js_item)?;
});
let ty = GetSupportedType::get_type(&v.ty);
let decleration = match &ty {
SupportedType::Option(o) => format!("{}?", get_typescript_type(o)),
_ => get_typescript_type(&ty),
};
interface.push_str(&format!("\t{}: {},\n", name, decleration));
});

interface.push('}');
let mut file = OpenOptions::new()
.create(true)
.write(true)
.append(true)
.read(true)
.open("javascript/index.d.ts")
.unwrap();
let mut contents = String::new();
file.read_to_string(&mut contents)
.expect("Unable to read typescript decleration file");
if !contents.contains(&interface) {
file.write_all(interface.as_bytes())
.expect("Unable to write typescript decleration file");
}

let out = quote! {
#[cfg(feature = "javascript")]
impl IntoJsResult for #name {
type Output = neon::types::JsObject;
fn into_js_result<'a, 'b, 'c: 'b, C: neon::context::Context<'c>>(self, cx: &mut C) -> neon::result::JsResult<'b, Self::Output> {
use neon::object::Object;
let js_object = cx.empty_object();
#(#sets)*
Ok(js_object)
}
}
};
proc_macro::TokenStream::from(out)
}
use crate::types::{OutputType, SupportedType};

// pub fn generate_custom_into_js_result(parsed: DeriveInput) -> proc_macro::TokenStream {
// let name = parsed.ident;
// let fields_named = match parsed.data {
// syn::Data::Struct(s) => match s.fields {
// syn::Fields::Named(n) => n,
// _ => panic!("custom_into_js proc_macro structs should only have named fields"),
// },
// _ => panic!("custom_into_js proc_macro should only be used on structs"),
// };
//
// let mut sets = Vec::new();
// let mut interface = format!("\ninterface {} {{\n", name);
//
// fields_named.named.into_pairs().for_each(|p| {
// let v = p.into_value();
// let name = v.ident.to_token_stream().to_string();
// let name_ident = v.ident;
// sets.push(quote! {
// let js_item = self.#name_ident.into_js_result(cx)?;
// js_object.set(cx, #name, js_item)?;NODE_OPTIONS=--experimental-vm-modules
// });
// let ty = GetSupportedType::get_type(&v.ty);
// let decleration = match &ty {
// SupportedType::Option(o) => format!("{}?", get_typescript_type(o)),
// _ => get_typescript_type(&ty),
// };
// interface.push_str(&format!("\t{}: {},\n", name, decleration));
// });
//
// interface.push('}');
// let mut file = OpenOptions::new()
// .create(true)
// .write(true)
// .append(true)
// .read(true)
// .open("javascript/index.d.ts")
// .unwrap();
// let mut contents = String::new();
// file.read_to_string(&mut contents)
// .expect("Unable to read typescript decleration file");
// if !contents.contains(&interface) {
// file.write_all(interface.as_bytes())
// .expect("Unable to write typescript decleration file");
// }
//
// let out = quote! {
// #[cfg(feature = "javascript")]
// impl IntoJsResult for #name {
// type Output = neon::types::JsObject;
// fn into_js_result<'a, 'b, 'c: 'b, C: neon::context::Context<'c>>(self, cx: &mut C) -> neon::result::JsResult<'b, Self::Output> {
// use neon::object::Object;
// let js_object = cx.empty_object();
// #(#sets)*
// Ok(js_object)
// }
// }
// };
// proc_macro::TokenStream::from(out)
// }

pub fn generate_javascript_derive(parsed: DeriveInput) -> proc_macro::TokenStream {
let name_ident = format_ident!("{}Javascript", parsed.ident);
Expand Down Expand Up @@ -175,8 +175,16 @@ pub fn generate_javascript_methods(
.iter()
.filter(|a| !matches!(a.1, SupportedType::S))
.map(|a| match &a.1 {
SupportedType::Option(o) => format!("{}?: {}", a.0, get_typescript_type(o)),
_ => format!("{}: {}", a.0, get_typescript_type(&a.1)),
SupportedType::Option(o) => format!(
"{}?: {}",
a.0.replace("mut", "").trim(),
get_typescript_type(o)
),
_ => format!(
"{}: {}",
a.0.replace("mut", "").trim(),
get_typescript_type(&a.1)
),
})
.collect::<Vec<String>>()
.join(", ");
Expand Down Expand Up @@ -384,19 +392,6 @@ fn convert_method_wrapper_arguments(
let (o, i, m) = convert_method_wrapper_arguments(name_ident.clone(), &r.ty, index);

match *r.ty.clone() {
// SupportedType::Option(_o) => (quote! {
// let #argument_ident = cx.argument_opt(#i as i32);
// // let #argument_ident = <#argument_type_tokens>::from_option_js_type(&mut cx, #argument_ident)?;
// let #argument_ident = match #argument_ident {
// Some(v) => Some(v.root(&mut cx))
// };
// }, quote! {
// let #argument_ident = match #argument_ident {
// Some(v) => v.into_inner(&mut cx),
// None => None
// };
// let #argument_ident = <#argument_type_tokens>::from_option_js_type(&mut cx, #argument_ident)?;
// }),
SupportedType::Option(_o) => panic!("We do not support references to options yet"),

SupportedType::Database
Expand All @@ -419,11 +414,6 @@ fn convert_method_wrapper_arguments(
m,
)
}

// _ => (quote! {
// let #argument_ident = cx.argument::<#argument_type_js>(#i as i32)?;
// let #argument_ident = <#argument_type_tokens>::from_js_type(&mut cx, #argument_ident)?;
// }, quote!{})
_ => {
if r.mutable {
(o, i, quote! { &mut #m})
Expand Down Expand Up @@ -468,7 +458,7 @@ fn convert_method_wrapper_arguments(
quote! { #name_ident},
)
}
SupportedType::Option(o) => {
SupportedType::Option(_o) => {
let t = ty.to_type(Some("Javascript")).expect(
"Could not parse type in convert_method_wrapper_arguments in javascript.rs",
);
Expand Down Expand Up @@ -576,7 +566,6 @@ fn get_typescript_type(ty: &SupportedType) -> String {
)
}
SupportedType::JsonHashMap => "Map<string, string>".to_string(),
SupportedType::DateTime => "Date".to_string(),
SupportedType::Tuple(t) => {
let mut types = Vec::new();
for ty in t {
Expand All @@ -592,6 +581,8 @@ fn get_typescript_type(ty: &SupportedType) -> String {
SupportedType::i64 | SupportedType::f64 | SupportedType::u64 => "number".to_string(),
// Our own types
t @ SupportedType::Database
| t @ SupportedType::Json
| t @ SupportedType::DateTime
| t @ SupportedType::Collection
| t @ SupportedType::Splitter
| t @ SupportedType::QueryBuilder
Expand Down
22 changes: 11 additions & 11 deletions pgml-sdks/rust/pgml-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ pub fn custom_methods(
output
}

#[proc_macro_derive(custom_into_py)]
pub fn custom_into_py(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let parsed = parse_macro_input!(input as DeriveInput);
python::generate_into_py(parsed)
}

#[proc_macro_derive(custom_into_js_result)]
pub fn custom_into_js_result(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let parsed = parse_macro_input!(input as DeriveInput);
javascript::generate_custom_into_js_result(parsed)
}
// #[proc_macro_derive(custom_into_py)]
// pub fn custom_into_py(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
// let parsed = parse_macro_input!(input as DeriveInput);
// python::generate_into_py(parsed)
// }

// #[proc_macro_derive(custom_into_js_result)]
// pub fn custom_into_js_result(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
// let parsed = parse_macro_input!(input as DeriveInput);
// javascript::generate_custom_into_js_result(parsed)
// }
Loading