Skip to content
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
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ homepage = "https://github.com/Shopify/shopify-function-wasm-api"
description = "High-level interface for interfacing with the Shopify Function Wasm API"

[dependencies]
shopify_function_wasm_api_core = { path = "../core", version = "0.1.0" }
shopify_function_wasm_api_core = { path = "../core", version = "0.2.0" }
thiserror = "2.0"
seq-macro = "0.3.5"

[target.'cfg(not(target_family = "wasm"))'.dependencies]
shopify_function_provider = { path = "../provider", version = "1.0.1" }
shopify_function_provider = { path = "../provider", version = "2.0.0" }
serde_json = "1.0"
rmp-serde = "1.3"

Expand All @@ -33,4 +33,3 @@ path = "examples/cart-checkout-validation-wasm-api.rs"
[[example]]
name = "cart-checkout-validation-wasi-json"
path = "examples/cart-checkout-validation-wasi-json.rs"

26 changes: 4 additions & 22 deletions api/examples/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ impl Deserialize for Value {
// special case to exercise string interning and get_obj_prop
let raw_value = match key.as_str() {
"foo" => {
let interned_string_id = FOO_INTERNED_STRING_ID.load_from_value(value);
let interned_string_id = FOO_INTERNED_STRING_ID.load();
value.get_interned_obj_prop(interned_string_id)
}
"bar" => {
let interned_string_id = BAR_INTERNED_STRING_ID.load_from_value(value);
let interned_string_id = BAR_INTERNED_STRING_ID.load();
value.get_interned_obj_prop(interned_string_id)
}
"abc" | "def" => value.get_obj_prop(key.as_str()),
Expand Down Expand Up @@ -94,13 +94,11 @@ impl Serialize for Value {
for (key, value) in object {
match key.as_str() {
"foo" => {
let interned_string_id =
FOO_INTERNED_STRING_ID.load_from_context(ctx);
let interned_string_id = FOO_INTERNED_STRING_ID.load();
ctx.write_interned_utf8_str(interned_string_id)?;
}
"bar" => {
let interned_string_id =
BAR_INTERNED_STRING_ID.load_from_context(ctx);
let interned_string_id = BAR_INTERNED_STRING_ID.load();
ctx.write_interned_utf8_str(interned_string_id)?;
}
_ => ctx.write_utf8_str(key)?,
Expand Down Expand Up @@ -138,20 +136,4 @@ mod tests {

assert_eq!(result, Value::Object(Vec::new()));
}

#[test]
fn test_echo_multiple_contexts_with_interned_string_cache() {
// tests the cached interned string logic by having multiple contexts that
// hit the interned string cache
let input = serde_json::json!({ "foo": "bar"});
let context = Context::new_with_input(input.clone());
let api_value = context.input_get().unwrap();
let input_value: Value = Deserialize::deserialize(&api_value).unwrap();
let result = echo(input_value);
let context2 = Context::new_with_input(input);
let api_value2 = context2.input_get().unwrap();
let input_value2: Value = Deserialize::deserialize(&api_value2).unwrap();
let result2 = echo(input_value2);
assert_eq!(result, result2);
}
}
Loading