Skip to content

Commit ff27f22

Browse files
committed
docs: add missing types, errors and refine docstrings for ShoppingCart and ProductCatalog
1 parent faa7832 commit ff27f22

5 files changed

Lines changed: 40 additions & 11 deletions

File tree

src/classes/product_catalog.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ import {
1313
import { InvalidProductCatalogFormat } from "../errors";
1414

1515
/**
16-
* Product Catalog Manager
17-
*
18-
* Used in conjunction with {@link ShoppingCart}
16+
* Product Catalog Manager: used in conjunction with {@link ShoppingCart}
1917
*
2018
* ## Usage
2119
*
@@ -28,10 +26,12 @@ import { InvalidProductCatalogFormat } from "../errors";
2826
* ```typescript
2927
* import { ProductCatalog } from "@tmlmt/cooklang-parser";
3028
*
31-
* const catalog = `[eggs]
29+
* const catalog = `
30+
* [eggs]
3231
* aliases = ["oeuf", "huevo"]
3332
* 01123 = { name = "Single Egg", size = "1", price = 2 }
3433
* 11244 = { name = "Pack of 6 eggs", size = "6", price = 10 }
34+
*
3535
* [flour]
3636
* aliases = ["farine", "Mehl"]
3737
* 01124 = { name = "Small pack", size = "100%g", price = 1.5 }

src/classes/shopping_cart.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export interface ShoppingCartSummary {
5353
}
5454

5555
/**
56-
* Shopping Cart Manager: a tool to find the best combination of products to buy to satisfy a shopping list.
56+
* Shopping Cart Manager: a tool to find the best combination of products to buy (defined in a {@link ProductCatalog}) to satisfy a {@link ShoppingList}.
5757
*
5858
* @example
5959
* ```ts

src/errors.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ You can either remove the reference to create a new ${item_type} defined as ${ne
1414
}
1515
}
1616

17+
/**
18+
* Error thrown when trying to build a shopping cart without a product catalog
19+
* @category Errors
20+
*/
1721
export class NoProductCatalogForCartError extends Error {
1822
constructor() {
1923
super(
@@ -23,6 +27,10 @@ export class NoProductCatalogForCartError extends Error {
2327
}
2428
}
2529

30+
/**
31+
* Error thrown when trying to build a shopping cart without a shopping list
32+
* @category Errors
33+
*/
2634
export class NoShoppingListForCartError extends Error {
2735
constructor() {
2836
super(

src/index.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ import {
99
} from "./classes/shopping_cart";
1010
import { Section } from "./classes/section";
1111

12+
export {
13+
CategoryConfig,
14+
ProductCatalog,
15+
Recipe,
16+
ShoppingList,
17+
ShoppingCart,
18+
Section,
19+
};
20+
1221
import type {
1322
Metadata,
1423
Ingredient,
@@ -19,6 +28,7 @@ import type {
1928
DecimalValue,
2029
FractionValue,
2130
TextValue,
31+
FixedNumericValue,
2232
Timer,
2333
TextItem,
2434
IngredientItem,
@@ -47,13 +57,8 @@ import type {
4757
} from "./types";
4858

4959
export {
50-
Recipe,
51-
ShoppingList,
52-
ShoppingCart,
5360
ShoppingCartOptions,
5461
ShoppingCartSummary,
55-
CategoryConfig,
56-
ProductCatalog,
5762
Metadata,
5863
Ingredient,
5964
IngredientFlag,
@@ -63,6 +68,7 @@ export {
6368
DecimalValue,
6469
FractionValue,
6570
TextValue,
71+
FixedNumericValue,
6672
Timer,
6773
TextItem,
6874
IngredientItem,
@@ -79,7 +85,6 @@ export {
7985
RecipeWithServings,
8086
CategoryIngredient,
8187
Category,
82-
Section,
8388
QuantityPart,
8489
ProductOption,
8590
ProductSelection,
@@ -90,3 +95,10 @@ export {
9095
CartMisMatch,
9196
NoProductMatchErrorCode,
9297
};
98+
99+
import {
100+
NoProductCatalogForCartError,
101+
NoShoppingListForCartError,
102+
} from "./errors";
103+
104+
export { NoProductCatalogForCartError, NoShoppingListForCartError };

src/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ export interface FixedValue {
170170
value: TextValue | DecimalValue | FractionValue;
171171
}
172172

173+
/**
174+
* Represents a single, fixed numeric quantity.
175+
* This can be a decimal or fraction.
176+
* @category Types
177+
*/
173178
export interface FixedNumericValue {
174179
type: "fixed";
175180
value: DecimalValue | FractionValue;
@@ -495,6 +500,10 @@ export interface ProductMatch {
495500
*/
496501
export type CartMatch = ProductMatch[];
497502

503+
/**
504+
* Represents the error codes for an ingredient which didn't match with any product in the product catalog, in a {@link ShoppingCart}
505+
* @category Types
506+
*/
498507
export type NoProductMatchErrorCode =
499508
| "incompatibleUnits"
500509
| "noProduct"

0 commit comments

Comments
 (0)