Skip to content

Commit 295051a

Browse files
authored
Merge pull request #5 from neuroglia-io/feat-replace-anyvalue
Replace `AnyValye` by `serde_json::Value`
2 parents 9729a04 + b3fed76 commit 295051a

File tree

14 files changed

+60
-92
lines changed

14 files changed

+60
-92
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

builders/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "serverless_workflow_builders"
3-
version = "1.0.0-alpha6.2"
3+
version = "1.0.0-alpha6.3"
44
edition = "2021"
55
authors = ["The Serverless Workflow Authors <cncf.serverless.workflow@gmail.com>"]
66
description = "Contains services used to build ServerlessWorkflow workflow definitions programatically"
@@ -12,6 +12,6 @@ keywords = ["serverless-workflow", "sdk", "builders"]
1212
categories = ["config", "parsing", "data-structures", "api-bindings"]
1313

1414
[dependencies]
15-
serverless_workflow_core = { path = "../core", version = "1.0.0-alpha6.2" }
15+
serverless_workflow_core = { path = "../core", version = "1.0.0-alpha6.3" }
1616
serde_json = "1.0"
1717
serde_yaml = "0.9"

builders/src/lib.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pub mod services;
33
#[cfg(test)]
44
mod unit_tests {
55

6-
use serverless_workflow_core::models::any::*;
6+
use serde_json::Value;
77
use serverless_workflow_core::models::duration::*;
88
use serverless_workflow_core::models::error::OneOfErrorDefinitionOrReference;
99
use crate::services::workflow::WorkflowBuilder;
@@ -33,16 +33,16 @@ mod unit_tests {
3333
let password = "fake-password";
3434
let call_task_name = "call-task";
3535
let call_function_name = "fake-function";
36-
let call_task_with: HashMap<String, AnyValue> = vec![
37-
("key1".to_string(), AnyValue::String("value1".to_string())),
38-
("key2".to_string(), AnyValue::String("value2".to_string()))]
36+
let call_task_with: HashMap<String, Value> = vec![
37+
("key1".to_string(), Value::String("value1".to_string())),
38+
("key2".to_string(), Value::String("value2".to_string()))]
3939
.into_iter()
4040
.collect();
4141
let do_task_name = "do-task";
4242
let emit_task_name = "emit-task";
43-
let emit_event_attributes: HashMap<String, AnyValue> = vec![
44-
("key1".to_string(), AnyValue::String("value1".to_string())),
45-
("key2".to_string(), AnyValue::String("value2".to_string()))]
43+
let emit_event_attributes: HashMap<String, Value> = vec![
44+
("key1".to_string(), Value::String("value1".to_string())),
45+
("key2".to_string(), Value::String("value2".to_string()))]
4646
.into_iter()
4747
.collect();
4848
let for_task_name = "for-task";
@@ -53,7 +53,7 @@ mod unit_tests {
5353
let listen_task_name = "listen-task";
5454
let raise_task_name = "raise-task-name";
5555
let raise_error_type = "error-type";
56-
let raise_error_status = AnyValue::Int16(400);
56+
let raise_error_status = json!(400);
5757
let raise_error_title = "error-title";
5858
let raise_error_detail = "error-detail";
5959
let raise_error_instance = "error-instance";
@@ -82,11 +82,11 @@ mod unit_tests {
8282
let workflow_namespace = "workflow-namespace";
8383
let workflow_name = "workflow-name";
8484
let workflow_version = "workflow-version";
85-
let workflow_input = AnyValue::Json(json!({"hello": "world"}));
85+
let workflow_input = json!({"hello": "world"});
8686
let set_task_name = "set-task-name";
87-
let set_task_variables : HashMap<String, AnyValue> = vec![
88-
("var1-name".to_string(), AnyValue::String("var1-value".to_string())),
89-
("var2-name".to_string(), AnyValue::UInt64(69))]
87+
let set_task_variables : HashMap<String, Value> = vec![
88+
("var1-name".to_string(), json!("var1-value".to_string())),
89+
("var2-name".to_string(), json!(69))]
9090
.into_iter()
9191
.collect();
9292
let switch_task_name = "switch-task-name";
@@ -95,9 +95,9 @@ mod unit_tests {
9595
let switch_case_then = "continue";
9696
let try_task_name = "try-task-name";
9797
let catch_when = "catch-when";
98-
let catch_errors_attributes: HashMap<String, AnyValue> = vec![
99-
("var1-name".to_string(), AnyValue::String("var1-value".to_string())),
100-
("var2-name".to_string(), AnyValue::UInt64(69))]
98+
let catch_errors_attributes: HashMap<String, Value> = vec![
99+
("var1-name".to_string(), json!("var1-value".to_string())),
100+
("var2-name".to_string(), json!(69))]
101101
.into_iter()
102102
.collect();
103103
let retry_except_when = "retry-except-when";
@@ -154,7 +154,7 @@ mod unit_tests {
154154
task.listen()
155155
.to(|e|{
156156
e.one()
157-
.with("key", AnyValue::String("value".to_string()));
157+
.with("key", Value::String("value".to_string()));
158158
});
159159
})
160160
.do_(raise_task_name, |task| {

builders/src/services/task.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::services::authentication::*;
22
use crate::services::timeout::*;
3-
use serverless_workflow_core::models::any::*;
3+
use serde_json::Value;
44
use serverless_workflow_core::models::duration::*;
55
use serverless_workflow_core::models::error::*;
66
use serverless_workflow_core::models::event::*;
@@ -261,7 +261,7 @@ impl CalltaskDefinitionBuilder {
261261
}
262262

263263
/// Adds a new argument to call the function with
264-
pub fn with(&mut self, name: &str, value: AnyValue) -> &mut Self{
264+
pub fn with(&mut self, name: &str, value: Value) -> &mut Self{
265265
if self.task.with.is_none(){
266266
self.task.with = Some(HashMap::new());
267267
}
@@ -272,7 +272,7 @@ impl CalltaskDefinitionBuilder {
272272
}
273273

274274
/// Sets the arguments to call the function with
275-
pub fn with_arguments(&mut self, arguments: HashMap<String, AnyValue>) -> &mut Self{
275+
pub fn with_arguments(&mut self, arguments: HashMap<String, Value>) -> &mut Self{
276276
self.task.with = Some(arguments);
277277
self
278278
}
@@ -1041,13 +1041,13 @@ impl SetTaskDefinitionBuilder{
10411041
}
10421042

10431043
/// Sets the specified variable
1044-
pub fn variable(&mut self, name: &str, value: AnyValue) -> &mut Self{
1044+
pub fn variable(&mut self, name: &str, value: Value) -> &mut Self{
10451045
self.task.set.insert(name.to_string(), value);
10461046
self
10471047
}
10481048

10491049
/// Configures the task to set the specified variables
1050-
pub fn variables(&mut self, variables: HashMap<String, AnyValue>) -> &mut Self{
1050+
pub fn variables(&mut self, variables: HashMap<String, Value>) -> &mut Self{
10511051
self.task.set = variables;
10521052
self
10531053
}
@@ -1385,13 +1385,13 @@ impl EventDefinitionBuilder{
13851385
}
13861386

13871387
/// Adds a new attribute to the event
1388-
pub fn with(&mut self, name: &str, value: AnyValue) -> &mut Self{
1388+
pub fn with(&mut self, name: &str, value: Value) -> &mut Self{
13891389
self.event.with.insert(name.to_string(), value);
13901390
self
13911391
}
13921392

13931393
/// Sets the event's attributes
1394-
pub fn with_attributes(&mut self, attributes: HashMap<String, AnyValue>) -> &mut Self{
1394+
pub fn with_attributes(&mut self, attributes: HashMap<String, Value>) -> &mut Self{
13951395
self.event.with = attributes;
13961396
self
13971397
}
@@ -1561,7 +1561,7 @@ impl EventFilterDefinitionBuilder{
15611561
}
15621562

15631563
/// Adds a new attribute to filter events by
1564-
pub fn with(&mut self, name: &str, value: AnyValue) -> &mut Self{
1564+
pub fn with(&mut self, name: &str, value: Value) -> &mut Self{
15651565
if self.filter.with.is_none(){
15661566
self.filter.with = Some(HashMap::new());
15671567
}
@@ -1572,7 +1572,7 @@ impl EventFilterDefinitionBuilder{
15721572
}
15731573

15741574
/// Sets a name/value mapping of the attributes to filter events by
1575-
pub fn with_attributes(&mut self, attributes: HashMap<String, AnyValue>) -> &mut Self{
1575+
pub fn with_attributes(&mut self, attributes: HashMap<String, Value>) -> &mut Self{
15761576
self.filter.with = Some(attributes);
15771577
self
15781578
}
@@ -1659,7 +1659,7 @@ impl ErrorDefinitionBuilder{
16591659
}
16601660

16611661
/// Sets the error's status
1662-
pub fn with_status(&mut self, status: AnyValue) -> &mut Self{
1662+
pub fn with_status(&mut self, status: Value) -> &mut Self{
16631663
self.error.status = status;
16641664
self
16651665
}
@@ -1952,7 +1952,7 @@ impl WorkflowProcessDefinitionBuilder{
19521952
}
19531953

19541954
/// Sets the input of the workflow to run
1955-
pub fn with_input(&mut self, input: AnyValue) -> &mut Self{
1955+
pub fn with_input(&mut self, input: Value) -> &mut Self{
19561956
self.process.input = Some(input);
19571957
self
19581958
}
@@ -2151,7 +2151,7 @@ impl ErrroFilterDefinitionBuilder{
21512151
}
21522152

21532153
/// Adds a new attribute filter
2154-
pub fn with(&mut self, name: &str, value: AnyValue) -> &mut Self{
2154+
pub fn with(&mut self, name: &str, value: Value) -> &mut Self{
21552155
if self.filter.with.is_none(){
21562156
self.filter.with = Some(HashMap::new());
21572157
}
@@ -2162,7 +2162,7 @@ impl ErrroFilterDefinitionBuilder{
21622162
}
21632163

21642164
/// Sets a name/value mapping of the attributes to filter errors by
2165-
pub fn with_attributes(&mut self, attributes: HashMap<String, AnyValue>) -> &mut Self{
2165+
pub fn with_attributes(&mut self, attributes: HashMap<String, Value>) -> &mut Self{
21662166
self.filter.with = Some(attributes);
21672167
self
21682168
}
@@ -2485,7 +2485,7 @@ impl InputDataModelDefinitionBuilder{
24852485
}
24862486

24872487
/// Configures the expression used to filter the input
2488-
pub fn from(&mut self, expression: AnyValue) -> &mut Self{
2488+
pub fn from(&mut self, expression: Value) -> &mut Self{
24892489
self.input.from = Some(expression);
24902490
self
24912491
}
@@ -2509,7 +2509,7 @@ impl OutputDataModelDefinitionBuilder{
25092509
}
25102510

25112511
/// Sets a runtime expression, if any, used to output specific data to the scope data
2512-
pub fn as_(&mut self, expression: AnyValue) -> &mut Self{
2512+
pub fn as_(&mut self, expression: Value) -> &mut Self{
25132513
self.output.as_ = Some(expression);
25142514
self
25152515
}
@@ -2548,7 +2548,7 @@ impl SchemaDefinitionBuilder{
25482548
}
25492549

25502550
/// Sets the schema document
2551-
pub fn with_document(&mut self, document: AnyValue) -> &mut Self{
2551+
pub fn with_document(&mut self, document: Value) -> &mut Self{
25522552
self.schema.document = Some(document);
25532553
self
25542554
}

core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "serverless_workflow_core"
3-
version = "1.0.0-alpha6.2"
3+
version = "1.0.0-alpha6.3"
44
edition = "2021"
55
authors = ["The Serverless Workflow Authors <cncf.serverless.workflow@gmail.com>"]
66
description = "Contains Serverless Workflow DSL models"

core/src/models/any.rs

Lines changed: 0 additions & 31 deletions
This file was deleted.

core/src/models/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use serde_derive::{Deserialize, Serialize};
2-
use crate::models::any::*;
2+
use serde_json::Value;
33

44
/// Represents the definition an error to raise
55
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
@@ -15,7 +15,7 @@ pub struct ErrorDefinition{
1515

1616
/// Gets/sets the status code produced by the described error
1717
#[serde(rename = "status")]
18-
pub status: AnyValue,
18+
pub status: Value,
1919

2020
/// Gets/sets a human-readable explanation specific to this occurrence of the error.
2121
#[serde(rename = "detail", skip_serializing_if = "Option::is_none")]
@@ -29,7 +29,7 @@ pub struct ErrorDefinition{
2929
impl ErrorDefinition{
3030

3131
/// Initializes a new ErrorDefinition
32-
pub fn new(type_: &str, title: &str, status: AnyValue, detail: Option<String>, instance: Option<String>) -> Self{
32+
pub fn new(type_: &str, title: &str, status: Value, detail: Option<String>, instance: Option<String>) -> Self{
3333
Self {
3434
type_: type_.to_string(),
3535
title: title.to_string(),

core/src/models/event.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use serde_derive::{Deserialize, Serialize};
2+
use serde_json::Value;
23
use std::collections::HashMap;
3-
use crate::models::any::*;
44

55
/// Represents the configuration of an event consumption strategy
66
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
@@ -30,7 +30,7 @@ pub struct EventFilterDefinition{
3030

3131
/// Gets/sets a name/value mapping of the attributes filtered events must define. Supports both regular expressions and runtime expressions
3232
#[serde(rename = "with", skip_serializing_if = "Option::is_none")]
33-
pub with : Option<HashMap<String, AnyValue>>,
33+
pub with : Option<HashMap<String, Value>>,
3434

3535
/// Gets/sets a name/definition mapping of the correlation to attempt when filtering events.
3636
#[serde(rename = "correlate", skip_serializing_if = "Option::is_none")]
@@ -66,11 +66,11 @@ pub struct EventDefinition{
6666

6767
/// Gets/sets a key/value mapping of the attributes of the configured event
6868
#[serde(rename = "with")]
69-
pub with: HashMap<String, AnyValue>
69+
pub with: HashMap<String, Value>
7070

7171
}
7272
impl EventDefinition {
73-
pub fn new(with: HashMap<String, AnyValue>) -> Self{
73+
pub fn new(with: HashMap<String, Value>) -> Self{
7474
Self{
7575
with
7676
}

core/src/models/input.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use serde_derive::{Deserialize, Serialize};
2-
use crate::models::any::*;
2+
use serde_json::Value;
33
use crate::models::schema::*;
44

55
/// Represents the definition of an input data model
@@ -12,6 +12,6 @@ pub struct InputDataModelDefinition{
1212

1313
/// Gets/sets a runtime expression, if any, used to build the workflow or task input data based on both input and scope data
1414
#[serde(rename = "from", skip_serializing_if = "Option::is_none")]
15-
pub from : Option<AnyValue>
15+
pub from : Option<Value>
1616

1717
}

core/src/models/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
pub mod any;
21
pub mod authentication;
32
pub mod catalog;
43
pub mod duration;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy