Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust Plugins Env Bindings Refactor #1694

Merged
merged 5 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions packages/js/manifests/polywrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
"@polywrap/logging-js": "0.10.0",
"@polywrap/polywrap-manifest-schemas": "0.10.0",
"jsonschema": "1.4.0",
"semver": "7.4.0",
"semver": "7.5.0",
"yaml": "2.1.3"
},
"devDependencies": {
"@polywrap/os-js": "0.10.0",
"@types/jest": "26.0.8",
"@types/mustache": "4.0.1",
"@types/prettier": "2.6.0",
"@types/semver": "7.3.8",
"@types/semver": "7.3.11",
"jest": "26.6.3",
"json-schema-to-typescript": "11.0.2",
"mustache": "4.0.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/js/manifests/wrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"@apidevtools/json-schema-ref-parser": "9.0.9",
"jsonschema": "1.4.0",
"semver": "7.4.0"
"semver": "7.5.0"
},
"devDependencies": {
"@polywrap/msgpack-js": "0.10.0",
Expand All @@ -26,7 +26,7 @@
"@types/jest": "26.0.8",
"@types/mustache": "4.0.1",
"@types/prettier": "2.6.0",
"@types/semver": "7.3.8",
"@types/semver": "7.3.11",
"jest": "26.6.3",
"json-schema-to-typescript": "11.0.2",
"mustache": "4.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
/// All modifications will be overwritten.

use std::sync::Arc;
use polywrap_core::invoke::Invoker;
use polywrap_core::{invoke::Invoker};
use polywrap_plugin::error::PluginError;
use polywrap_plugin::module::PluginModule;
use serde::{Serialize, Deserialize};
use super::types::*;
use async_trait::async_trait;

{{#moduleType}}
{{#methods}}
Expand All @@ -20,11 +19,10 @@ pub struct Args{{#toUpper}}{{name}}{{/toUpper}} {

{{/methods}}
{{/moduleType}}
#[async_trait]
pub trait Module: PluginModule {
{{#moduleType}}
{{#methods}}
async fn {{#detectKeyword}}{{#toLower}}{{name}}{{/toLower}}{{/detectKeyword}}(&mut self, args: &Args{{#toUpper}}{{name}}{{/toUpper}}, invoker: Arc<dyn Invoker>) -> Result<{{#return}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/return}}, PluginError>;
fn {{#detectKeyword}}{{#toLower}}{{name}}{{/toLower}}{{/detectKeyword}}(&mut self, args: &Args{{#toUpper}}{{name}}{{/toUpper}}, invoker: Arc<dyn Invoker>{{#env}}, env: {{^required}}Option<{{/required}}Env{{^required}}>{{/required}}{{/env}}) -> Result<{{#return}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/return}}, PluginError>;
{{^last}}

{{/last}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::{Serialize, Deserialize};
use num_bigint::BigInt;
use bigdecimal::BigDecimal as BigNumber;
use serde_json as JSON;
use std::collections::BTreeMap as Map;
use polywrap_msgpack::extensions::generic_map::GenericMap as Map;
{{#importedModuleTypes}}
use std::sync::Arc;
use polywrap_msgpack::{decode, serialize};
Expand Down Expand Up @@ -114,7 +114,7 @@ impl {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} {
}

{{#methods}}
pub async fn {{#detectKeyword}}{{#toLower}}{{name}}{{/toLower}}{{/detectKeyword}}(args: &{{#toUpper}}{{parent.type}}{{/toUpper}}Args{{#toUpper}}{{name}}{{/toUpper}}, invoker: Arc<dyn Invoker>) -> Result<{{#return}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/return}}, PluginError> {
pub fn {{#detectKeyword}}{{#toLower}}{{name}}{{/toLower}}{{/detectKeyword}}(args: &{{#toUpper}}{{parent.type}}{{/toUpper}}Args{{#toUpper}}{{name}}{{/toUpper}}, invoker: Arc<dyn Invoker>) -> Result<{{#return}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/return}}, PluginError> {
let uri = {{#parent}}{{#toUpper}}{{type}}{{/toUpper}}{{/parent}}::URI;
let serialized_args = serialize(args.clone()).unwrap();
let opt_args = Some(serialized_args.as_slice());
Expand All @@ -126,7 +126,6 @@ impl {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} {
None,
None
)
.await
.map_err(|e| PluginError::SubinvocationError {
uri: uri.to_string(),
method: "{{name}}".to_string(),
Expand Down Expand Up @@ -156,7 +155,7 @@ impl<'a> {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}}<'a
}

{{#methods}}
pub async fn {{#toLower}}{{name}}{{/toLower}}(&self, args: &{{#toUpper}}{{parent.type}}{{/toUpper}}Args{{#toUpper}}{{name}}{{/toUpper}}) -> Result<{{#return}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/return}}, PluginError> {
pub fn {{#toLower}}{{name}}{{/toLower}}(&self, args: &{{#toUpper}}{{parent.type}}{{/toUpper}}Args{{#toUpper}}{{name}}{{/toUpper}}) -> Result<{{#return}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/return}}, PluginError> {
let uri = self.uri;
let serialized_args = serialize(args.clone()).unwrap();
let result = invoker.invoke_raw(
Expand All @@ -165,7 +164,7 @@ impl<'a> {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}}<'a
serialized_args,
None,
None
.await
)
.map_err(|e| PluginError::SubinvocationError {
uri: uri.to_string(),
method: "{{name}}".to_string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
/// All modifications will be overwritten.

use std::sync::Arc;
use polywrap_core::invoke::Invoker;
use polywrap_core::{invoke::Invoker};
use polywrap_plugin::error::PluginError;
use polywrap_plugin::module::PluginModule;
use serde::{Serialize, Deserialize};
use super::types::*;
use async_trait::async_trait;

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ArgsModuleMethod {
Expand Down Expand Up @@ -46,13 +45,12 @@ pub struct ArgsIf {
pub _if: Else,
}

#[async_trait]
pub trait Module: PluginModule {
async fn module_method(&mut self, args: &ArgsModuleMethod, invoker: Arc<dyn Invoker>) -> Result<i32, PluginError>;
fn module_method(&mut self, args: &ArgsModuleMethod, invoker: Arc<dyn Invoker>) -> Result<i32, PluginError>;

async fn object_method(&mut self, args: &ArgsObjectMethod, invoker: Arc<dyn Invoker>) -> Result<Option<AnotherType>, PluginError>;
fn object_method(&mut self, args: &ArgsObjectMethod, invoker: Arc<dyn Invoker>, env: Env) -> Result<Option<AnotherType>, PluginError>;

async fn optional_env_method(&mut self, args: &ArgsOptionalEnvMethod, invoker: Arc<dyn Invoker>) -> Result<Option<AnotherType>, PluginError>;
fn optional_env_method(&mut self, args: &ArgsOptionalEnvMethod, invoker: Arc<dyn Invoker>, env: Option<Env>) -> Result<Option<AnotherType>, PluginError>;

async fn _if(&mut self, args: &ArgsIf, invoker: Arc<dyn Invoker>) -> Result<Else, PluginError>;
fn _if(&mut self, args: &ArgsIf, invoker: Arc<dyn Invoker>) -> Result<Else, PluginError>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::{Serialize, Deserialize};
use num_bigint::BigInt;
use bigdecimal::BigDecimal as BigNumber;
use serde_json as JSON;
use std::collections::BTreeMap as Map;
use polywrap_msgpack::extensions::generic_map::GenericMap as Map;
use std::sync::Arc;
use polywrap_msgpack::{decode, serialize};
use polywrap_core::{invoke::{Invoker}, uri::Uri};
Expand Down Expand Up @@ -187,7 +187,7 @@ impl<'a> TestImportModule<'a> {
TestImportModule { uri: uri }
}

pub async fn imported_method(&self, args: &TestImportModuleArgsImportedMethod) -> Result<Option<TestImportObject>, PluginError> {
pub fn imported_method(&self, args: &TestImportModuleArgsImportedMethod) -> Result<Option<TestImportObject>, PluginError> {
let uri = self.uri;
let serialized_args = serialize(args.clone()).unwrap();
let result = invoker.invoke_raw(
Expand All @@ -196,7 +196,7 @@ impl<'a> TestImportModule<'a> {
serialized_args,
None,
None
.await
)
.map_err(|e| PluginError::SubinvocationError {
uri: uri.to_string(),
method: "importedMethod".to_string(),
Expand All @@ -207,7 +207,7 @@ impl<'a> TestImportModule<'a> {
Ok(Some(decode(result.as_slice())?))
}

pub async fn another_method(&self, args: &TestImportModuleArgsAnotherMethod) -> Result<i32, PluginError> {
pub fn another_method(&self, args: &TestImportModuleArgsAnotherMethod) -> Result<i32, PluginError> {
let uri = self.uri;
let serialized_args = serialize(args.clone()).unwrap();
let result = invoker.invoke_raw(
Expand All @@ -216,7 +216,7 @@ impl<'a> TestImportModule<'a> {
serialized_args,
None,
None
.await
)
.map_err(|e| PluginError::SubinvocationError {
uri: uri.to_string(),
method: "anotherMethod".to_string(),
Expand All @@ -227,7 +227,7 @@ impl<'a> TestImportModule<'a> {
Ok(decode(result.as_slice())?)
}

pub async fn returns_array_of_enums(&self, args: &TestImportModuleArgsReturnsArrayOfEnums) -> Result<Vec<Option<TestImportEnumReturn>>, PluginError> {
pub fn returns_array_of_enums(&self, args: &TestImportModuleArgsReturnsArrayOfEnums) -> Result<Vec<Option<TestImportEnumReturn>>, PluginError> {
let uri = self.uri;
let serialized_args = serialize(args.clone()).unwrap();
let result = invoker.invoke_raw(
Expand All @@ -236,7 +236,7 @@ impl<'a> TestImportModule<'a> {
serialized_args,
None,
None
.await
)
.map_err(|e| PluginError::SubinvocationError {
uri: uri.to_string(),
method: "returnsArrayOfEnums".to_string(),
Expand Down
52 changes: 26 additions & 26 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2516,9 +2516,9 @@
integrity sha512-0d5Wd09ItQWH1qFbEyQ7oTQ3GZrMfth5JkbN3EvTKLXcHLRDSXeLnlvlOn0wvxVIwK5o2M8JzP/OWz7T3NRsbw==

"@types/lodash@^4.14.182":
version "4.14.192"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.192.tgz#5790406361a2852d332d41635d927f1600811285"
integrity sha512-km+Vyn3BYm5ytMO13k9KTp27O75rbQ0NFw+U//g+PX7VZyjCioXaRFisqSIJRECljcTv73G3i6BpglNGHgUQ5A==
version "4.14.194"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.194.tgz#b71eb6f7a0ff11bff59fc987134a093029258a76"
integrity sha512-r22s9tAS7imvBt2lyHC9B8AGwWnXaYb1tY09oyLkXDs4vArpYJzw09nj8MLx5VfciBPGIb+ZwG0ssYnEPJxn/g==

"@types/minimatch@*", "@types/minimatch@^5.1.2":
version "5.1.2"
Expand Down Expand Up @@ -2593,10 +2593,10 @@
"@types/glob" "*"
"@types/node" "*"

"@types/semver@7.3.8":
version "7.3.8"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.8.tgz#508a27995498d7586dcecd77c25e289bfaf90c59"
integrity sha512-D/2EJvAlCEtYFEYmmlGwbGXuK886HzyCc3nZX/tkFTQdEU8jZDAgiv08P162yB17y4ZXZoq7yFAnW4GDBb9Now==
"@types/semver@7.3.11":
version "7.3.11"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.11.tgz#7a84d3228f34e68d14955fc406f8e66fdbe9e65e"
integrity sha512-R9HhjC4aKx3jL0FLwU7x6qMTysTvLh7jesRslXmxgCOXZwyh5dsnmrPQQToMyess8D4U+8G9x9mBFZoC/1o/Tw==

"@types/shelljs@0.8.9":
version "0.8.9"
Expand Down Expand Up @@ -3536,9 +3536,9 @@ camelcase@^6.0.0:
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==

caniuse-lite@^1.0.30001449:
version "1.0.30001478"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001478.tgz#0ef8a1cf8b16be47a0f9fc4ecfc952232724b32a"
integrity sha512-gMhDyXGItTHipJj2ApIvR+iVB5hd0KP3svMWWXDvZOmjzJJassGLMfxRkQCSYgGd2gtdL/ReeiyvMSFD1Ss6Mw==
version "1.0.30001480"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001480.tgz#9bbd35ee44c2480a1e3a3b9f4496f5066817164a"
integrity sha512-q7cpoPPvZYgtyC4VaBSN0Bt+PJ4c4EYRf0DrduInOz2SkFpHD5p3LnvEpqBp7UnJn+8x1Ogl1s38saUxe+ihQQ==

capture-exit@^2.0.0:
version "2.0.0"
Expand Down Expand Up @@ -4357,9 +4357,9 @@ electron-fetch@^1.7.2:
encoding "^0.1.13"

electron-to-chromium@^1.4.284:
version "1.4.362"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.362.tgz#1dfd7a076fc4785a16941f06410d0668e1a7a1aa"
integrity sha512-PYzAoScDfUcAwZfJQvr6hK2xXzLsMocj/Wuz6LpW6TZQNVv9TflBSB+UoEPuFujc478BgAxCoCFarcVPmjzsog==
version "1.4.367"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.367.tgz#d9ddc529ba2315fc852b722c359e4a40e86aa742"
integrity sha512-mNuDxb+HpLhPGUKrg0hSxbTjHWw8EziwkwlJNkFUj3W60ypigLDRVz04vU+VRsJPi8Gub+FDhYUpuTm9xiEwRQ==

elliptic@6.5.4:
version "6.5.4"
Expand Down Expand Up @@ -4606,9 +4606,9 @@ eslint-import-resolver-node@^0.3.4:
resolve "^1.22.1"

eslint-module-utils@^2.6.0:
version "2.7.4"
resolved "https://registry.yarnpkg.com/eslint-module-utils/-/eslint-module-utils-2.7.4.tgz#4f3e41116aaf13a20792261e61d3a2e7e0583974"
integrity sha512-j4GT+rqzCoRKHwURX7pddtIPGySnX9Si/cgMI5ztrcqOPtk5dDEeZ34CQVPphnqkJytlc97Vuk05Um2mJ3gEQA==
version "2.8.0"
resolved "https://registry.yarnpkg.com/eslint-module-utils/-/eslint-module-utils-2.8.0.tgz#e439fee65fc33f6bba630ff621efc38ec0375c49"
integrity sha512-aWajIYfsqCKRDgUfjEXNN/JlrzauMuSEy5sbd7WXbtW3EH6A6MpwEh42c7qD+MqQo9QMJ6fWLAeIJynx0g6OAw==
dependencies:
debug "^3.2.7"

Expand Down Expand Up @@ -7286,9 +7286,9 @@ long@^4.0.0:
integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==

long@^5.2.0:
version "5.2.1"
resolved "https://registry.yarnpkg.com/long/-/long-5.2.1.tgz#e27595d0083d103d2fa2c20c7699f8e0c92b897f"
integrity sha512-GKSNGeNAtw8IryjjkhZxuKB3JzlcLTwjtiQCHKvqQet81I93kXslhDQruGI/QsddO83mcDToBVy7GqGS/zYf/A==
version "5.2.3"
resolved "https://registry.yarnpkg.com/long/-/long-5.2.3.tgz#a3ba97f3877cf1d778eccbcb048525ebb77499e1"
integrity sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==

lru-cache@^5.1.1:
version "5.1.1"
Expand Down Expand Up @@ -9315,10 +9315,10 @@ semver@7.3.8:
dependencies:
lru-cache "^6.0.0"

semver@7.4.0, semver@7.x, semver@^7.1.1, semver@^7.1.3, semver@^7.2.1, semver@^7.3.2, semver@^7.3.4, semver@^7.3.5:
version "7.4.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.4.0.tgz#8481c92feffc531ab1e012a8ffc15bdd3a0f4318"
integrity sha512-RgOxM8Mw+7Zus0+zcLEUn8+JfoLpj/huFTItQy2hsM4khuC1HYRDp0cU482Ewn/Fcy6bCjufD8vAj7voC66KQw==
semver@7.5.0, semver@7.x, semver@^7.1.1, semver@^7.1.3, semver@^7.2.1, semver@^7.3.2, semver@^7.3.4, semver@^7.3.5:
version "7.5.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.0.tgz#ed8c5dc8efb6c629c88b23d41dc9bf40c1d96cd0"
integrity sha512-+XC0AD/R7Q2mPSRuy2Id0+CGTZ98+8f+KvwirxOKIEyid+XSx6HbC63p+O4IndTHuX5Z+JxQ0TghCkO5Cg/2HA==
dependencies:
lru-cache "^6.0.0"

Expand Down Expand Up @@ -10343,9 +10343,9 @@ upath@^2.0.1:
integrity sha512-1uEe95xksV1O0CYKXo8vQvN1JEbtJp7lb7C5U9HMsIp6IVwntkH/oNUzyVNQSd4S1sYk2FpSSW44FqMc8qee5w==

update-browserslist-db@^1.0.10:
version "1.0.10"
resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.0.10.tgz#0f54b876545726f17d00cd9a2561e6dade943ff3"
integrity sha512-OztqDenkfFkbSG+tRxBeAnCVPckDBcvibKd35yDONx6OU8N7sqgwc7rCbkJ/WcYtVRZ4ba68d6byhC21GFh7sQ==
version "1.0.11"
resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.0.11.tgz#9a2a641ad2907ae7b3616506f4b977851db5b940"
integrity sha512-dCwEFf0/oT85M1fHBg4F0jtLwJrutGoHSQXCh7u4o2t1drG+c0a9Flnqww6XUKSfQMPpJBRjU8d4RXB09qtvaA==
dependencies:
escalade "^3.1.1"
picocolors "^1.0.0"
Expand Down