Skip to content

Commit f723c2e

Browse files
committed
fix: ts
1 parent 9c4711a commit f723c2e

5 files changed

Lines changed: 10 additions & 11 deletions

File tree

src/metadata.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ pub(crate) fn check_std_entry(
532532

533533
/// Servings information that can be numeric or a string
534534
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
535+
#[cfg_attr(feature = "ts", derive(tsify::Tsify))]
535536
#[serde(untagged)]
536537
pub enum Servings {
537538
/// Numeric servings count

src/model.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::borrow::Cow;
55
use serde::{Deserialize, Serialize};
66

77
#[cfg(feature = "ts")]
8-
use tsify::{declare, Tsify};
8+
use tsify::Tsify;
99

1010
use crate::{
1111
convert::Converter, metadata::Metadata, parser::Modifiers, quantity::Quantity, GroupedQuantity,

src/quantity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
77
use thiserror::Error;
88

99
#[cfg(feature = "ts")]
10-
use tsify::{declare, Tsify};
10+
use tsify::Tsify;
1111

1212
use crate::convert::{ConvertError, Converter, PhysicalQuantity, Unit};
1313

src/scale.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
use crate::{convert::Converter, quantity::Value, Quantity, Recipe};
44
use thiserror::Error;
55

6-
#[cfg(feature = "ts")]
7-
use tsify::Tsify;
86

97
/// Error type for scaling operations
10-
#[derive(Debug, Error)]
8+
#[derive(Debug, Error, serde::Serialize, serde::Deserialize)]
9+
#[cfg_attr(feature = "ts", derive(tsify::Tsify))]
1110
pub enum ScaleError {
1211
/// The recipe has no valid numeric servings value
1312
#[error("Cannot scale recipe: servings metadata is not a valid number")]

typescript/src/lib.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub struct Parser {
2323
#[derive(Tsify, Serialize, Deserialize)]
2424
#[tsify(into_wasm_abi, from_wasm_abi)]
2525
pub struct ScaledRecipeWithReport {
26-
recipe: cooklang::ScaledRecipe,
26+
recipe: cooklang::Recipe,
2727
report: String,
2828
}
2929

@@ -85,11 +85,10 @@ impl Parser {
8585

8686
pub fn parse(&self, input: &str) -> ScaledRecipeWithReport {
8787
let (recipe, _report) = self.parser.parse(input).into_tuple();
88-
let scaled = recipe
89-
.expect("expected recipe")
90-
.scale(1., self.parser.converter());
88+
let mut recipe = recipe.expect("expected recipe");
89+
recipe.scale(1., self.parser.converter());
9190
let data = ScaledRecipeWithReport {
92-
recipe: scaled,
91+
recipe,
9392
report: "<no output>".to_string(),
9493
};
9594
data
@@ -135,7 +134,7 @@ impl Parser {
135134
author: Option<NameAndUrl>,
136135
source: Option<NameAndUrl>,
137136
time: Option<RecipeTime>,
138-
servings: Option<Vec<u32>>,
137+
servings: Option<cooklang::metadata::Servings>,
139138
locale: Option<(&'a str, Option<&'a str>)>,
140139
}
141140
let val = StdMeta {

0 commit comments

Comments
 (0)