diff --git a/Cargo.lock b/Cargo.lock
index 19eeba8..a442793 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -224,7 +224,7 @@ checksum = "677d1d8ab452a3936018a687b20e6f7cf5363d713b732b8884001317b0e48aa3"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 1.0.107",
]
[[package]]
@@ -383,7 +383,7 @@ dependencies = [
"regex",
"rustc-hash",
"shlex",
- "syn",
+ "syn 1.0.107",
]
[[package]]
@@ -750,7 +750,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096"
dependencies = [
"quote",
- "syn",
+ "syn 1.0.107",
]
[[package]]
@@ -777,7 +777,7 @@ dependencies = [
"proc-macro2",
"quote",
"scratch",
- "syn",
+ "syn 1.0.107",
]
[[package]]
@@ -794,7 +794,7 @@ checksum = "3e7e2adeb6a0d4a282e581096b06e1791532b7d576dcde5ccd9382acf55db8e6"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 1.0.107",
]
[[package]]
@@ -983,7 +983,7 @@ checksum = "bdfb8ce053d86b91919aad980c220b1fb8401a9394410e1c289ed7e66b61835d"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 1.0.107",
]
[[package]]
@@ -1056,14 +1056,15 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
name = "gloo-net"
-version = "0.1.0"
+version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2899cb1a13be9020b010967adc6b2a8a343b6f1428b90238c9d53ca24decc6db"
+checksum = "8ac9e8288ae2c632fa9f8657ac70bfe38a1530f345282d7ba66a1f70b72b7dc4"
dependencies = [
"futures-channel",
"futures-core",
"futures-sink",
"gloo-utils",
+ "http",
"js-sys",
"pin-project",
"serde",
@@ -1088,9 +1089,9 @@ dependencies = [
[[package]]
name = "gloo-utils"
-version = "0.1.6"
+version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a8e8fc851e9c7b9852508bc6e3f690f452f474417e8545ec9857b7f7377036b5"
+checksum = "0b5555354113b18c547c1d3a98fbf7fb32a9ff4f6fa112ce823a21641a0ba3aa"
dependencies = [
"js-sys",
"serde",
@@ -1233,9 +1234,9 @@ dependencies = [
[[package]]
name = "http"
-version = "0.2.8"
+version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399"
+checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb"
dependencies = [
"bytes",
"fnv",
@@ -1448,10 +1449,10 @@ dependencies = [
"base64 0.21.0",
"chrono",
"console_error_panic_hook",
+ "gloo-net",
"js-sys",
"maud",
"recipes",
- "reqwasm",
"serde",
"serde_json",
"sycamore",
@@ -1602,7 +1603,7 @@ dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
- "syn",
+ "syn 1.0.107",
]
[[package]]
@@ -1658,7 +1659,7 @@ checksum = "731f8ecebd9f3a4aa847dfe75455e4757a45da40a7793d2f0b1f9b6ed18b23f3"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 1.0.107",
]
[[package]]
@@ -1923,7 +1924,7 @@ checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 1.0.107",
]
[[package]]
@@ -1989,7 +1990,7 @@ dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
- "syn",
+ "syn 1.0.107",
"version_check",
]
@@ -2006,9 +2007,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
-version = "1.0.49"
+version = "1.0.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5"
+checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b"
dependencies = [
"unicode-ident",
]
@@ -2044,9 +2045,9 @@ dependencies = [
[[package]]
name = "quote"
-version = "1.0.23"
+version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
+checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
dependencies = [
"proc-macro2",
]
@@ -2133,15 +2134,6 @@ version = "0.6.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
-[[package]]
-name = "reqwasm"
-version = "0.5.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "05b89870d729c501fa7a68c43bf4d938bbb3a8c156d333d90faa0e8b3e3212fb"
-dependencies = [
- "gloo-net",
-]
-
[[package]]
name = "ring"
version = "0.16.20"
@@ -2186,7 +2178,7 @@ dependencies = [
"proc-macro2",
"quote",
"rust-embed-utils",
- "syn",
+ "syn 1.0.107",
"walkdir",
]
@@ -2311,7 +2303,7 @@ checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 1.0.107",
]
[[package]]
@@ -2525,7 +2517,7 @@ dependencies = [
"sha2 0.10.6",
"sqlx-core",
"sqlx-rt",
- "syn",
+ "syn 1.0.107",
"url",
]
@@ -2618,7 +2610,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
- "syn",
+ "syn 1.0.107",
]
[[package]]
@@ -2653,7 +2645,7 @@ dependencies = [
"nom",
"proc-macro2",
"quote",
- "syn",
+ "syn 1.0.107",
"unicode-xid",
]
@@ -2694,6 +2686,17 @@ dependencies = [
"unicode-ident",
]
+[[package]]
+name = "syn"
+version = "2.0.39"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
[[package]]
name = "sync_wrapper"
version = "0.1.1"
@@ -2732,7 +2735,7 @@ checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 1.0.107",
]
[[package]]
@@ -2823,7 +2826,7 @@ checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 1.0.107",
]
[[package]]
@@ -2938,7 +2941,7 @@ checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 1.0.107",
]
[[package]]
@@ -3158,28 +3161,26 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
-version = "0.2.84"
+version = "0.2.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b"
+checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e"
dependencies = [
"cfg-if 1.0.0",
- "serde",
- "serde_json",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
-version = "0.2.84"
+version = "0.2.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9"
+checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826"
dependencies = [
"bumpalo",
"log",
"once_cell",
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.39",
"wasm-bindgen-shared",
]
@@ -3197,9 +3198,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
-version = "0.2.84"
+version = "0.2.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5"
+checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@@ -3207,22 +3208,22 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
-version = "0.2.84"
+version = "0.2.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6"
+checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.39",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
-version = "0.2.84"
+version = "0.2.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d"
+checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f"
[[package]]
name = "wasm-bindgen-test"
@@ -3269,7 +3270,7 @@ dependencies = [
"proc-macro2",
"quote",
"str_inflector",
- "syn",
+ "syn 1.0.107",
]
[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index 33fc471..4ba40ed 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,5 +1,6 @@
[workspace]
members = [ "recipes", "kitchen", "web", "api" ]
+resolver = "2"
[patch.crates-io]
# TODO(jwall): When the fix for RcSignal Binding is released we can drop this patch.
diff --git a/Makefile b/Makefile
index cdddd93..41ef01d 100644
--- a/Makefile
+++ b/Makefile
@@ -14,6 +14,11 @@
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
mkfile_dir := $(dir $(mkfile_path))
sqlite_url := sqlite://$(mkfile_dir)/.session_store/store.db
+out := dist
+project := kitchen
+
+export out
+export kitchen
kitchen: wasm kitchen/src/*.rs
cd kitchen; cargo build
@@ -27,15 +32,18 @@ static-prep: web/index.html web/favicon.ico web/static/*.css
cp -r web/favicon.ico web/dist/
cp -r web/static web/dist/
-wasmrelease: wasmrelease-dist static-prep
+wasmrelease: wasm-opt static-prep
+
+wasm-opt: wasmrelease-dist
+ cd web; sh ../scripts/wasm-opt.sh release
wasmrelease-dist: web/src/*.rs web/src/components/*.rs
- cd web; wasm-pack build --mode no-install --release --target web --no-typescript --out-name kitchen_wasm --out-dir dist/
+ cd web; sh ../scripts/wasm-build.sh release
wasm: wasm-dist static-prep
wasm-dist: web/src/*.rs web/src/components/*.rs
- cd web; wasm-pack build --mode no-install --target web --no-typescript --out-dir dist/ --features debug_logs
+ cd web; sh ../scripts/wasm-build.sh debug
clean:
rm -rf web/dist/*
@@ -50,5 +58,5 @@ sqlx-add-%:
sqlx-revert:
cd kitchen; cargo sqlx migrate revert --database-url $(sqlite_url)
-sqlx-prepare:
+sqlx-prepare: kitchen
cd kitchen; cargo sqlx prepare --database-url $(sqlite_url)
diff --git a/flake.lock b/flake.lock
index a36dfa2..9a80f3f 100644
--- a/flake.lock
+++ b/flake.lock
@@ -99,11 +99,11 @@
},
"nixpkgs_2": {
"locked": {
- "lastModified": 1679174867,
- "narHash": "sha256-fFxb8wN3bjOMvHPr63Iyzo3cuHhQzWW03UkckfTeBWU=",
+ "lastModified": 1719152388,
+ "narHash": "sha256-pHg0nzAa2ZM+zFamfsY7ZvVaB19pMr5wl4G5nO0J7eU=",
"owner": "NixOS",
"repo": "nixpkgs",
- "rev": "f5ec87b82832736f1624874fd34eb60c0b68bdd6",
+ "rev": "be54c7d931a68ba6a79f097ce979288e90a74288",
"type": "github"
},
"original": {
@@ -124,17 +124,16 @@
},
"rust-overlay": {
"inputs": {
- "flake-utils": "flake-utils_2",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
- "lastModified": 1702001829,
- "narHash": "sha256-6gEVidNVqzTb06zIy2Gxhz9m6/jXyAgViRxfgEpZkQ8=",
+ "lastModified": 1718681902,
+ "narHash": "sha256-E/T7Ge6ayEQe7FVKMJqDBoHyLhRhjc6u9CmU8MyYfy0=",
"owner": "oxalica",
"repo": "rust-overlay",
- "rev": "c2a1dd067a928624c1aab36f976758c0722c79bd",
+ "rev": "16c8ad83297c278eebe740dea5491c1708960dd1",
"type": "github"
},
"original": {
diff --git a/flake.nix b/flake.nix
index f01beae..8884f75 100644
--- a/flake.nix
+++ b/flake.nix
@@ -25,7 +25,7 @@
let
overlays = [ rust-overlay.overlays.default ];
pkgs = import nixpkgs { inherit system overlays; };
- rust-wasm = pkgs.rust-bin.stable."1.74.1".default.override {
+ rust-wasm = pkgs.rust-bin.stable."1.77.0".default.override {
extensions = [ "rust-src" ];
# Add wasm32 as an extra target besides the native target.
targets = [ "wasm32-unknown-unknown" ];
@@ -45,6 +45,14 @@
wasm-bindgen = pkgs.callPackage wasm-bindgenGen { inherit pkgs; };
kitchenWasm = kitchenWasmGen {
inherit pkgs rust-wasm wasm-bindgen version;
+ lockFile = ./Cargo.lock;
+ outputHashes = {
+ # I'm maintaining some patches for these so the lockfile hashes are a little
+ # incorrect. We override those here.
+ "wasm-web-component-0.2.0" = "sha256-quuPgzGb2F96blHmD3BAUjsWQYbSyJGZl27PVrwL92k=";
+ "sycamore-0.8.2" = "sha256-D968+8C5EelGGmot9/LkAlULZOf/Cr+1WYXRCMwb1nQ=";
+ "sqlx-0.6.2" = "sha256-X/LFvtzRfiOIEZJiVzmFvvULPpjhqvI99pSwH7a//GM=";
+ };
};
kitchen = (kitchenGen {
inherit pkgs version naersk-lib kitchenWasm rust-wasm;
diff --git a/kitchen/build.rs b/kitchen/build.rs
index 7609593..d506869 100644
--- a/kitchen/build.rs
+++ b/kitchen/build.rs
@@ -2,4 +2,4 @@
fn main() {
// trigger recompilation when a new migration is added
println!("cargo:rerun-if-changed=migrations");
-}
\ No newline at end of file
+}
diff --git a/kitchen/migrations/20240701002811_recipe-servings.down.sql b/kitchen/migrations/20240701002811_recipe-servings.down.sql
new file mode 100644
index 0000000..eea316a
--- /dev/null
+++ b/kitchen/migrations/20240701002811_recipe-servings.down.sql
@@ -0,0 +1,2 @@
+-- Add down migration script here
+ALTER TABLE recipes DROP COLUMN serving_count;
diff --git a/kitchen/migrations/20240701002811_recipe-servings.up.sql b/kitchen/migrations/20240701002811_recipe-servings.up.sql
new file mode 100644
index 0000000..e1e3920
--- /dev/null
+++ b/kitchen/migrations/20240701002811_recipe-servings.up.sql
@@ -0,0 +1,2 @@
+-- Add up migration script here
+ALTER TABLE recipes ADD column serving_count number;
diff --git a/kitchen/src/web/mod.rs b/kitchen/src/web/mod.rs
index 09d1b03..c0ec8d0 100644
--- a/kitchen/src/web/mod.rs
+++ b/kitchen/src/web/mod.rs
@@ -1,4 +1,3 @@
-use std::collections::BTreeMap;
// Copyright 2022 Jeremy Wall
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,6 +11,7 @@ use std::collections::BTreeMap;
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
+use std::collections::BTreeMap;
use std::path::PathBuf;
use std::sync::Arc;
use std::{collections::BTreeSet, net::SocketAddr};
diff --git a/models/browser_state.als b/models/browser_state.als
new file mode 100644
index 0000000..2adf814
--- /dev/null
+++ b/models/browser_state.als
@@ -0,0 +1,51 @@
+sig Id {}
+sig Text {}
+
+sig Recipe {
+ , id: one Id
+ , text: one Text
+}
+
+fact {
+ no r1, r2: Recipe | (r1.id = r2.id) and (r1.text != r2.text)
+ no r1, r2: Recipe | (r1 != r2) and (r1.id = r2.id)
+}
+
+sig Ingredient {}
+sig Modifier {}
+sig Amt {}
+
+sig ModifiedInventory {
+ , ingredient: one Ingredient
+ , modifier: lone Modifier
+ , amt: one Amt
+}
+
+fact {
+ no mi1, mi2: ModifiedInventory | mi1 != mi2 && (mi1.ingredient = mi2.ingredient) and (mi1.modifier = mi2.modifier)
+}
+
+sig DeletedInventory {
+ , ingredient: one Ingredient
+ , modifier: lone Modifier
+}
+
+fact {
+ no mi1, mi2: DeletedInventory | mi1 != mi2 && (mi1.ingredient = mi2.ingredient) and (mi1.modifier = mi2.modifier)
+}
+
+sig ExtraItems {
+ , ingredient: one Ingredient
+ , amt: one Amt
+}
+
+sig State {
+ , recipes: some Recipe
+ , modified: set ModifiedInventory
+ , deleted: set DeletedInventory
+ , extras: set ExtraItems
+} {
+ no rs: Recipe | rs not in recipes
+}
+
+run { } for 3 but exactly 2 State, 2 Modifier, exactly 3 ModifiedInventory, exactly 9 Ingredient
diff --git a/models/planning.d2 b/models/planning.d2
new file mode 100644
index 0000000..04dafdf
--- /dev/null
+++ b/models/planning.d2
@@ -0,0 +1,17 @@
+Meal Planning: {
+ shape: sequence_diagram
+ user: Cook; client: Kitchen frontend; kitchen: Kitchen backend
+
+ user -> client: Start new meal Plan
+ client -> kitchen: new plan created
+ user -> client: Add recipe to meal plan
+ client -> kitchen: Update meal plan with recipe
+ client -> client: cache updated meal plan
+ user -> client: Do inventory
+ client -> kitchen: Store inventory mutations
+ client -> client: cache inventory mutations
+ user -> client: Undo mutation
+ client -> kitchen: Store inventory mutations
+ client -> client: cache inventory mutations
+ user -> user: Cook recipes
+}
diff --git a/models/planning.svg b/models/planning.svg
new file mode 100644
index 0000000..b9984ec
--- /dev/null
+++ b/models/planning.svg
@@ -0,0 +1,125 @@
+
diff --git a/nix/kitchenWasm/default.nix b/nix/kitchenWasm/default.nix
index 500712b..7d7c00b 100644
--- a/nix/kitchenWasm/default.nix
+++ b/nix/kitchenWasm/default.nix
@@ -3,23 +3,18 @@
features ? "",
rust-wasm,
wasm-bindgen,
+ lockFile,
+ outputHashes,
}:
with pkgs;
let
pname = "kitchen-wasm";
src = ./../..;
- lockFile = ./../../Cargo.lock;
# NOTE(jwall): Because we use wasm-pack directly below we need
# the cargo dependencies to already be installed.
- cargoDeps = (pkgs.rustPlatform.importCargoLock { inherit lockFile; outputHashes = {
- # I'm maintaining some patches for these so the lockfile hashes are a little
- # incorrect. We override those here.
- "wasm-web-component-0.2.0" = "sha256-quuPgzGb2F96blHmD3BAUjsWQYbSyJGZl27PVrwL92k=";
- "sycamore-0.8.2" = "sha256-D968+8C5EelGGmot9/LkAlULZOf/Cr+1WYXRCMwb1nQ=";
- "sqlx-0.6.2" = "sha256-X/LFvtzRfiOIEZJiVzmFvvULPpjhqvI99pSwH7a//GM=";
- };
- });
+ cargoDeps = (pkgs.rustPlatform.importCargoLock { inherit lockFile outputHashes; });
in
+# TODO(zaphar): I should actually be leveraging naersklib.buildPackage with a postInstall for the optimization and bindgen
stdenv.mkDerivation {
inherit src pname;
version = version;
@@ -34,12 +29,19 @@ stdenv.mkDerivation {
'';
# TODO(jwall): Build this from the root rather than the src.
buildPhase = ''
- echo building with wasm-pack
mkdir -p $out
cd web
cp -r static $out
- RUST_LOG=info wasm-pack build --mode no-install --release --target web --out-dir $out ${features};
+ sh ../scripts/wasm-build.sh release
+ #cargo build --lib --release --target wasm32-unknown-unknown --target-dir $out ${features} --offline
+ #wasm-bindgen $out/wasm32-unknown-unknown/release/kitchen_wasm.wasm --out-dir $out --typescript --target web
+ #sh ../scripts/wasm-opt.sh release
+ wasm-opt $out/kitchen_wasm_bg.wasm -o $out/kitchen_wasm_bg-opt.wasm -O
+ rm -f $out/kitchen_wasm_bg.wasm
+ mv $out/kitchen_wasm_bg-opt.wasm $out/kitchen_wasm_bg.wasm
cp -r index.html $out
cp -r favicon.ico $out
+ rm -rf $out/release
+ rm -rf $out/wasm32-unknown-unknown
'';
}
diff --git a/nix/wasm-bindgen/default.nix b/nix/wasm-bindgen/default.nix
index f9f8d19..14b4d18 100644
--- a/nix/wasm-bindgen/default.nix
+++ b/nix/wasm-bindgen/default.nix
@@ -8,9 +8,7 @@ in
, nodejs
, pkg-config
, openssl
-, stdenv
, curl
-, runCommand
}:
# This package is special so we don't use the naersk infrastructure to build it.
@@ -20,14 +18,14 @@ rustPlatform.buildRustPackage rec {
pname = "wasm-bindgen-cli";
# NOTE(jwall): This must exactly match the version of the wasm-bindgen crate
# we are using.
- version = "0.2.84";
+ version = "0.2.89";
src = fetchCrate {
inherit pname version;
- sha256 = "sha256-0rK+Yx4/Jy44Fw5VwJ3tG243ZsyOIBBehYU54XP/JGk=";
+ sha256 = "sha256-IPxP68xtNSpwJjV2yNMeepAS0anzGl02hYlSTvPocz8=";
};
- cargoSha256 = "sha256-vcpxcRlW1OKoD64owFF6mkxSqmNrvY+y3Ckn5UwEQ50=";
+ cargoSha256 = "sha256-pBeQaG6i65uJrJptZQLuIaCb/WCQMhba1Z1OhYqA8Zc=";
nativeBuildInputs = [ pkg-config ];
@@ -36,5 +34,5 @@ rustPlatform.buildRustPackage rec {
nativeCheckInputs = [ nodejs ];
# other tests require it to be ran in the wasm-bindgen monorepo
- cargoTestFlags = [ "--test=interface-types" ];
-}
\ No newline at end of file
+ cargoTestFlags = [ "--test=reference" ];
+}
diff --git a/readme.md b/readme.md
index f4d92c9..8edd299 100644
--- a/readme.md
+++ b/readme.md
@@ -6,10 +6,6 @@ A web assembly experiment in Meal Planning and Shopping List management.
Ensure you have rust installed with support for the web assembly target. You can see instructions here: [Rust wasm book](https://rustwasm.github.io/docs/book/game-of-life/setup.html).
-You will also want to have trunk installed. You can see instructions for that here: [trunk](https://trunkrs.dev/)
-
-Then obtain the source. We do not at this time publish kitchen on [crates.io](https://crates.io/).
-
```sh
git clone https://github.com/zaphar/kitchen
cd kitchen
@@ -23,7 +19,7 @@ make release
# Hacking on kitchen
-If you want to hack on kitchen, then you may find it useful to use trunk in dev mode. The run script will run build the app and run trunk with it watching for changes and reloading on demand in your browser.
+The run script will run build the app and run it for you.
```sh
./run.sh
@@ -37,4 +33,4 @@ If all of the above looks like too much work, and you already use the nix packag
```sh
nix run github:zaphar/kitchen
-```
\ No newline at end of file
+```
diff --git a/recipes/src/lib.rs b/recipes/src/lib.rs
index 416b5dd..c1e9aed 100644
--- a/recipes/src/lib.rs
+++ b/recipes/src/lib.rs
@@ -156,16 +156,28 @@ impl IngredientAccumulator {
set.insert(recipe_title.clone());
self.inner.insert(key, (i.clone(), set));
} else {
- let amt = match (self.inner[&key].0.amt, i.amt) {
- (Volume(rvm), Volume(lvm)) => Volume(lvm + rvm),
- (Count(lqty), Count(rqty)) => Count(lqty + rqty),
- (Weight(lqty), Weight(rqty)) => Weight(lqty + rqty),
+ let amts = match (&self.inner[&key].0.amt, &i.amt) {
+ (Volume(rvm), Volume(lvm)) => vec![Volume(lvm + rvm)],
+ (Count(lqty), Count(rqty)) => vec![Count(lqty + rqty)],
+ (Weight(lqty), Weight(rqty)) => vec![Weight(lqty + rqty)],
+ (Package(lnm, lqty), Package(rnm, rqty)) => {
+ if lnm == rnm {
+ vec![Package(lnm.clone(), lqty + rqty)]
+ } else {
+ vec![
+ Package(lnm.clone(), lqty.clone()),
+ Package(rnm.clone(), rqty.clone()),
+ ]
+ }
+ }
_ => unreachable!(),
};
- self.inner.get_mut(&key).map(|(i, set)| {
- i.amt = amt;
- set.insert(recipe_title.clone());
- });
+ for amt in amts {
+ self.inner.get_mut(&key).map(|(i, set)| {
+ i.amt = amt;
+ set.insert(recipe_title.clone());
+ });
+ }
}
}
}
diff --git a/recipes/src/parse.rs b/recipes/src/parse.rs
index bf2e30e..9ee2714 100644
--- a/recipes/src/parse.rs
+++ b/recipes/src/parse.rs
@@ -334,7 +334,14 @@ make_fn!(unit,
text_token!("kg"),
text_token!("grams"),
text_token!("gram"),
- text_token!("g")),
+ text_token!("g"),
+ text_token!("pkg"),
+ text_token!("package"),
+ text_token!("bottle"),
+ text_token!("bot"),
+ text_token!("bag"),
+ text_token!("can")
+ ),
_ => ws,
(u.to_lowercase().to_singular())
)
@@ -393,6 +400,7 @@ pub fn measure(i: StrIter) -> abortable_parser::Result {
"oz" => Weight(Oz(qty)),
"kg" | "kilogram" => Weight(Kilogram(qty)),
"g" | "gram" => Weight(Gram(qty)),
+ "pkg" | "package" | "can" | "bag" | "bottle" | "bot" => Measure::pkg(s, qty),
_u => {
eprintln!("Invalid unit: {}", _u);
unreachable!()
@@ -418,9 +426,8 @@ pub fn normalize_name(name: &str) -> String {
// NOTE(jwall): The below unwrap is safe because of the length
// check above.
let last = parts.last().unwrap();
- let normalized = last.to_singular();
prefix.push(' ');
- prefix.push_str(&normalized);
+ prefix.push_str(&last.to_string());
return prefix;
}
return name.trim().to_lowercase().to_owned();
diff --git a/recipes/src/test.rs b/recipes/src/test.rs
index ff5ebd6..8d89421 100644
--- a/recipes/src/test.rs
+++ b/recipes/src/test.rs
@@ -235,32 +235,30 @@ fn test_ingredient_name_parse() {
#[test]
fn test_ingredient_parse() {
for (i, expected) in vec![
- //(
- // "1 cup flour ",
- // Ingredient::new("flour", None, Volume(Cup(Quantity::Whole(1))), ""),
- //),
- //(
- // "\t1 cup flour ",
- // Ingredient::new("flour", None, Volume(Cup(Quantity::Whole(1))), ""),
- //),
- //(
- // "1 cup apple (chopped)",
- // Ingredient::new(
- // "apple",
- // Some("chopped".to_owned()),
- // Volume(Cup(Quantity::Whole(1))),
- // "",
- // ),
- //),
- //(
- // "1 cup apple (chopped) ",
- // Ingredient::new(
- // "apple",
- // Some("chopped".to_owned()),
- // Volume(Cup(Quantity::Whole(1))),
- // "",
- // ),
- //),
+ (
+ "1 cup flour ",
+ Ingredient::new("flour", None, Volume(Cup(Quantity::Whole(1)))),
+ ),
+ (
+ "\t1 cup flour ",
+ Ingredient::new("flour", None, Volume(Cup(Quantity::Whole(1)))),
+ ),
+ (
+ "1 cup apple (chopped)",
+ Ingredient::new(
+ "apple",
+ Some("chopped".to_owned()),
+ Volume(Cup(Quantity::Whole(1))),
+ ),
+ ),
+ (
+ "1 cup apple (chopped) ",
+ Ingredient::new(
+ "apple",
+ Some("chopped".to_owned()),
+ Volume(Cup(Quantity::Whole(1))),
+ ),
+ ),
(
"1 green bell pepper (chopped) ",
Ingredient::new(
@@ -269,6 +267,46 @@ fn test_ingredient_parse() {
Count(Quantity::Whole(1)),
),
),
+ (
+ "1 pkg green onion",
+ Ingredient::new(
+ "green onion",
+ None,
+ Package("pkg".into(), Quantity::Whole(1)),
+ ),
+ ),
+ (
+ "1 bottle green onion",
+ Ingredient::new(
+ "green onion",
+ None,
+ Package("bottle".into(), Quantity::Whole(1)),
+ ),
+ ),
+ (
+ "1 bot green onion",
+ Ingredient::new(
+ "green onion",
+ None,
+ Package("bot".into(), Quantity::Whole(1)),
+ ),
+ ),
+ (
+ "1 bag green onion",
+ Ingredient::new(
+ "green onion",
+ None,
+ Package("bag".into(), Quantity::Whole(1)),
+ ),
+ ),
+ (
+ "1 can baked beans",
+ Ingredient::new(
+ "baked beans",
+ None,
+ Package("can".into(), Quantity::Whole(1)),
+ ),
+ ),
] {
match parse::ingredient(StrIter::new(i)) {
ParseResult::Complete(_, ing) => assert_eq!(ing, expected),
diff --git a/recipes/src/unit.rs b/recipes/src/unit.rs
index f31333a..ea60379 100644
--- a/recipes/src/unit.rs
+++ b/recipes/src/unit.rs
@@ -22,6 +22,7 @@ use std::{
convert::TryFrom,
fmt::Display,
ops::{Add, Div, Mul, Sub},
+ rc::Rc,
};
use num_rational::Ratio;
@@ -179,6 +180,20 @@ impl VolumeMeasure {
macro_rules! volume_op {
($trait:ident, $method:ident) => {
+ impl $trait for &VolumeMeasure {
+ type Output = VolumeMeasure;
+
+ fn $method(self, lhs: Self) -> Self::Output {
+ let (l, r) = (self.get_ml(), lhs.get_ml());
+ let result = ML($trait::$method(l, r));
+ if self.metric() {
+ result.normalize()
+ } else {
+ result.into_tsp().normalize()
+ }
+ }
+ }
+
impl $trait for VolumeMeasure {
type Output = Self;
@@ -293,6 +308,20 @@ impl WeightMeasure {
macro_rules! weight_op {
($trait:ident, $method:ident) => {
+ impl $trait for &WeightMeasure {
+ type Output = WeightMeasure;
+
+ fn $method(self, lhs: Self) -> Self::Output {
+ let (l, r) = (self.get_grams(), lhs.get_grams());
+ let result = WeightMeasure::Gram($trait::$method(l, r));
+ if self.metric() {
+ result.normalize()
+ } else {
+ result.into_oz().normalize()
+ }
+ }
+ }
+
impl $trait for WeightMeasure {
type Output = Self;
@@ -335,18 +364,19 @@ impl Display for WeightMeasure {
use WeightMeasure::{Gram, Kilogram, Oz, Pound};
-#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord)]
+#[derive(Clone, Debug, PartialEq, PartialOrd, Eq, Ord)]
/// Measurements in a Recipe with associated units for them.
pub enum Measure {
/// Volume measurements as meter cubed base unit
Volume(VolumeMeasure),
/// Simple count of items
Count(Quantity),
+ Package(Rc, Quantity),
/// Weight measure as Grams base unit
Weight(WeightMeasure),
}
-use Measure::{Count, Volume, Weight};
+use Measure::{Count, Package, Volume, Weight};
impl Measure {
pub fn tsp(qty: Quantity) -> Self {
@@ -407,11 +437,16 @@ impl Measure {
Weight(Oz(qty))
}
+ pub fn pkg>>(name: S, qty: Quantity) -> Self {
+ Package(name.into(), qty)
+ }
+
pub fn measure_type(&self) -> String {
match self {
Volume(_) => "Volume",
Count(_) => "Count",
Weight(_) => "Weight",
+ Package(_, _) => "Package",
}
.to_owned()
}
@@ -421,6 +456,7 @@ impl Measure {
Volume(vm) => vm.plural(),
Count(qty) => qty.plural(),
Weight(wm) => wm.plural(),
+ Package(_, qty) => qty.plural(),
}
}
@@ -429,6 +465,7 @@ impl Measure {
Volume(vm) => Volume(vm.normalize()),
Count(qty) => Count(qty.clone()),
Weight(wm) => Weight(wm.normalize()),
+ Package(nm, qty) => Package(nm.clone(), qty.clone()),
}
}
}
@@ -439,6 +476,7 @@ impl Display for Measure {
Volume(vm) => write!(w, "{}", vm),
Count(qty) => write!(w, "{}", qty),
Weight(wm) => write!(w, "{}", wm),
+ Package(nm, qty) => write!(w, "{} {}", qty, nm),
}
}
}
@@ -533,6 +571,26 @@ impl TryFrom for Quantity {
macro_rules! quantity_op {
($trait:ident, $method:ident) => {
+ impl $trait for &Quantity {
+ type Output = Quantity;
+
+ fn $method(self, lhs: Self) -> Self::Output {
+ match (self, lhs) {
+ (Whole(rhs), Whole(lhs)) => Frac($trait::$method(
+ Ratio::from_integer(*rhs),
+ Ratio::from_integer(*lhs),
+ )),
+ (Frac(rhs), Frac(lhs)) => Frac($trait::$method(rhs, lhs)),
+ (Whole(rhs), Frac(lhs)) => {
+ Frac($trait::$method(Ratio::from_integer(*rhs), lhs))
+ }
+ (Frac(rhs), Whole(lhs)) => {
+ Frac($trait::$method(rhs, Ratio::from_integer(*lhs)))
+ }
+ }
+ }
+ }
+
impl $trait for Quantity {
type Output = Self;
diff --git a/scripts/wasm-build.sh b/scripts/wasm-build.sh
new file mode 100644
index 0000000..d92053d
--- /dev/null
+++ b/scripts/wasm-build.sh
@@ -0,0 +1,9 @@
+set -x
+buildtype=$1;
+
+if [ ${buildtype} = "release" ]; then
+ buildtype_flag="--release"
+fi
+
+cargo build --lib ${buildtype_flag} --target wasm32-unknown-unknown --target-dir $out --features debug_logs
+wasm-bindgen $out/wasm32-unknown-unknown/${buildtype}/kitchen_wasm.wasm --out-dir $out --typescript --target web
diff --git a/scripts/wasm-opt.sh b/scripts/wasm-opt.sh
new file mode 100644
index 0000000..f983110
--- /dev/null
+++ b/scripts/wasm-opt.sh
@@ -0,0 +1,6 @@
+set -x
+buildtype=$1;
+
+wasm-opt $out/wasm32-unknown-unkown/${buildtype}/${project}_wasm.wasm --out-dir dist/ -O
+rm -f $out/${project}_wasm_bg.wasm
+mv $out/${project}_wasm_bg-opt.wasm dist/${project}_wasm_bg.wasm
diff --git a/web/Cargo.toml b/web/Cargo.toml
index 45bfb4a..6244a10 100644
--- a/web/Cargo.toml
+++ b/web/Cargo.toml
@@ -43,12 +43,12 @@ features = ["fmt", "time"]
version = "0.4.22"
features = ["serde"]
-[dependencies.reqwasm]
-version = "0.5.0"
+[dependencies.gloo-net]
+version = "0.4.0"
[dependencies.wasm-bindgen]
# we need wasm-bindgen v0.2.84 exactly
-version = "= 0.2.84"
+version = "= 0.2.89"
[dependencies.web-sys]
version = "0.3"
@@ -56,6 +56,7 @@ features = [
"Event",
"InputEvent",
"CustomEvent",
+ "CustomEventInit",
"EventTarget",
"History",
"HtmlAnchorElement",
diff --git a/web/index.html b/web/index.html
index 19de9be..30e81d5 100644
--- a/web/index.html
+++ b/web/index.html
@@ -19,7 +19,7 @@
-
+
@@ -35,4 +35,4 @@