@benchme/scenarios 0.9.1 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/acme-v1/index.d.ts +2 -1
- package/dist/acme-v1/index.js +4 -1
- package/dist/acme-v1/index.js.map +1 -1
- package/dist/acme-v1/names.d.ts +3 -0
- package/dist/acme-v1/names.js +3 -0
- package/dist/acme-v1/names.js.map +1 -1
- package/dist/cuj-v1/accounts.d.ts +14 -0
- package/dist/cuj-v1/accounts.js +52 -0
- package/dist/cuj-v1/accounts.js.map +1 -0
- package/dist/cuj-v1/index.d.ts +10 -0
- package/dist/cuj-v1/index.js +21 -0
- package/dist/cuj-v1/index.js.map +1 -0
- package/dist/guide-v1/index.js +2 -0
- package/dist/guide-v1/index.js.map +1 -1
- package/dist/index.d.ts +16 -2
- package/dist/index.js +18 -2
- package/dist/index.js.map +1 -1
- package/dist/prng.d.ts +7 -0
- package/dist/prng.js +12 -0
- package/dist/prng.js.map +1 -1
- package/dist/scenario.d.ts +78 -0
- package/dist/scenario.js.map +1 -1
- package/dist/shops-v1/index.js +2 -0
- package/dist/shops-v1/index.js.map +1 -1
- package/dist/sites/cinema/generate.d.ts +22 -0
- package/dist/sites/cinema/generate.js +258 -0
- package/dist/sites/cinema/generate.js.map +1 -0
- package/dist/sites/cinema/index.d.ts +3 -0
- package/dist/sites/cinema/index.js +4 -0
- package/dist/sites/cinema/index.js.map +1 -0
- package/dist/sites/cinema/rules.d.ts +142 -0
- package/dist/sites/cinema/rules.js +191 -0
- package/dist/sites/cinema/rules.js.map +1 -0
- package/dist/sites/cinema/types.d.ts +93 -0
- package/dist/sites/cinema/types.js +2 -0
- package/dist/sites/cinema/types.js.map +1 -0
- package/dist/sites/clinic/generate.d.ts +28 -0
- package/dist/sites/clinic/generate.js +282 -0
- package/dist/sites/clinic/generate.js.map +1 -0
- package/dist/sites/clinic/index.d.ts +3 -0
- package/dist/sites/clinic/index.js +3 -0
- package/dist/sites/clinic/index.js.map +1 -0
- package/dist/sites/clinic/rules.d.ts +96 -0
- package/dist/sites/clinic/rules.js +154 -0
- package/dist/sites/clinic/rules.js.map +1 -0
- package/dist/sites/clinic/types.d.ts +125 -0
- package/dist/sites/clinic/types.js +2 -0
- package/dist/sites/clinic/types.js.map +1 -0
- package/dist/sites/dining/generate.d.ts +15 -0
- package/dist/sites/dining/generate.js +146 -0
- package/dist/sites/dining/generate.js.map +1 -0
- package/dist/sites/dining/index.d.ts +3 -0
- package/dist/sites/dining/index.js +4 -0
- package/dist/sites/dining/index.js.map +1 -0
- package/dist/sites/dining/rules.d.ts +92 -0
- package/dist/sites/dining/rules.js +156 -0
- package/dist/sites/dining/rules.js.map +1 -0
- package/dist/sites/dining/types.d.ts +69 -0
- package/dist/sites/dining/types.js +14 -0
- package/dist/sites/dining/types.js.map +1 -0
- package/dist/sites/events/generate.d.ts +27 -0
- package/dist/sites/events/generate.js +197 -0
- package/dist/sites/events/generate.js.map +1 -0
- package/dist/sites/events/index.d.ts +3 -0
- package/dist/sites/events/index.js +4 -0
- package/dist/sites/events/index.js.map +1 -0
- package/dist/sites/events/rules.d.ts +99 -0
- package/dist/sites/events/rules.js +172 -0
- package/dist/sites/events/rules.js.map +1 -0
- package/dist/sites/events/types.d.ts +78 -0
- package/dist/sites/events/types.js +10 -0
- package/dist/sites/events/types.js.map +1 -0
- package/dist/sites/flights/generate.d.ts +21 -0
- package/dist/sites/flights/generate.js +210 -0
- package/dist/sites/flights/generate.js.map +1 -0
- package/dist/sites/flights/index.d.ts +3 -0
- package/dist/sites/flights/index.js +3 -0
- package/dist/sites/flights/index.js.map +1 -0
- package/dist/sites/flights/rules.d.ts +79 -0
- package/dist/sites/flights/rules.js +125 -0
- package/dist/sites/flights/rules.js.map +1 -0
- package/dist/sites/flights/types.d.ts +69 -0
- package/dist/sites/flights/types.js +2 -0
- package/dist/sites/flights/types.js.map +1 -0
- package/dist/sites/homes/generate.d.ts +19 -0
- package/dist/sites/homes/generate.js +180 -0
- package/dist/sites/homes/generate.js.map +1 -0
- package/dist/sites/homes/index.d.ts +3 -0
- package/dist/sites/homes/index.js +3 -0
- package/dist/sites/homes/index.js.map +1 -0
- package/dist/sites/homes/rules.d.ts +68 -0
- package/dist/sites/homes/rules.js +94 -0
- package/dist/sites/homes/rules.js.map +1 -0
- package/dist/sites/homes/types.d.ts +62 -0
- package/dist/sites/homes/types.js +2 -0
- package/dist/sites/homes/types.js.map +1 -0
- package/dist/sites/hotels/generate.d.ts +16 -0
- package/dist/sites/hotels/generate.js +134 -0
- package/dist/sites/hotels/generate.js.map +1 -0
- package/dist/sites/pizza/catalog.d.ts +34 -0
- package/dist/sites/pizza/catalog.js +65 -0
- package/dist/sites/pizza/catalog.js.map +1 -0
- package/dist/sites/pizza/generate.d.ts +19 -0
- package/dist/sites/pizza/generate.js +203 -0
- package/dist/sites/pizza/generate.js.map +1 -0
- package/dist/sites/pizza/index.d.ts +4 -0
- package/dist/sites/pizza/index.js +4 -0
- package/dist/sites/pizza/index.js.map +1 -0
- package/dist/sites/pizza/rules.d.ts +134 -0
- package/dist/sites/pizza/rules.js +217 -0
- package/dist/sites/pizza/rules.js.map +1 -0
- package/dist/sites/pizza/types.d.ts +114 -0
- package/dist/sites/pizza/types.js +2 -0
- package/dist/sites/pizza/types.js.map +1 -0
- package/dist/sites/rows.d.ts +14 -0
- package/dist/sites/rows.js +45 -0
- package/dist/sites/rows.js.map +1 -0
- package/dist/sites/sports/generate.d.ts +18 -0
- package/dist/sites/sports/generate.js +247 -0
- package/dist/sites/sports/generate.js.map +1 -0
- package/dist/sites/sports/index.d.ts +3 -0
- package/dist/sites/sports/index.js +3 -0
- package/dist/sites/sports/index.js.map +1 -0
- package/dist/sites/sports/rules.d.ts +110 -0
- package/dist/sites/sports/rules.js +139 -0
- package/dist/sites/sports/rules.js.map +1 -0
- package/dist/sites/sports/types.d.ts +91 -0
- package/dist/sites/sports/types.js +8 -0
- package/dist/sites/sports/types.js.map +1 -0
- package/dist/stays.d.ts +63 -0
- package/dist/stays.js +96 -0
- package/dist/stays.js.map +1 -0
- package/dist/web-v1/index.js +2 -0
- package/dist/web-v1/index.js.map +1 -1
- package/dist/webmcp-v1/index.d.ts +11 -0
- package/dist/webmcp-v1/index.js +26 -0
- package/dist/webmcp-v1/index.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { CITY_LIST, FIRST_NAMES, LAST_NAMES, word } from "../../acme-v1/names.js";
|
|
2
|
+
import { int, pick, shuffle, substream } from "../../prng.js";
|
|
3
|
+
import { addDays } from "../../stays.js";
|
|
4
|
+
import { PIZZA_CHEESES, PIZZA_CRUSTS, PIZZA_SAUCES, PIZZA_SIZE_KEYS, PIZZA_SIZE_SHAPES, PIZZA_SLOT_TIMES, PIZZA_TOPPING_SHAPES } from "./catalog.js";
|
|
5
|
+
import { pizzaMenuSearch, pizzaOutOfStock, pizzaPlaceOrder, pizzaSlotLeft } from "./rules.js";
|
|
6
|
+
/**
|
|
7
|
+
* The pizza site's rows: two branches in each of six cities, the menu, the
|
|
8
|
+
* toppings each branch has run out of, and orders already placed. Drawn from a
|
|
9
|
+
* stream of its own (`substream(seed, "pizza")`), so adding the site moved no
|
|
10
|
+
* other row. Some slots are full on purpose (and the slot after each such run
|
|
11
|
+
* has room for one pizza only), and a few customers ordered their favourite
|
|
12
|
+
* pizza more than once: a search has to check slots and stock, not just prices.
|
|
13
|
+
*/
|
|
14
|
+
export const PIZZA_ROW_COUNTS = { branchesPerCity: 2, pickupOnly: 3, menu: 14, customers: 24, orders: 64, fullRuns: 6, repeatCustomers: 4 };
|
|
15
|
+
/** Seeded slots fall in these three weeks; the rest of 2027 is empty. */
|
|
16
|
+
const BUSY_FROM = "2027-05-03";
|
|
17
|
+
const BUSY_DAYS = 21;
|
|
18
|
+
const DISTRICTS = ["Market Street", "Riverside", "Old Town", "Station Road", "Harbour Quay", "North Gate", "Mill Lane", "Castle Hill"];
|
|
19
|
+
const MENU_SUFFIXES = ["Garden", "Feast", "Melt", "Harvest", "Supreme", "Special", "Original", "Deluxe"];
|
|
20
|
+
const STREETS = ["Street", "Road", "Lane", "Avenue"];
|
|
21
|
+
const r5 = (cents) => Math.round(cents / 5) * 5;
|
|
22
|
+
const listed = (xs) => (xs.length <= 1 ? (xs[0] ?? "") : `${xs.slice(0, -1).join(", ")} and ${xs[xs.length - 1]}`);
|
|
23
|
+
function makeSizes(rng) {
|
|
24
|
+
let cents = int(rng, 16, 19) * 50;
|
|
25
|
+
return PIZZA_SIZE_SHAPES.map((s, i) => {
|
|
26
|
+
if (i > 0)
|
|
27
|
+
cents += int(rng, 5, 7) * 50;
|
|
28
|
+
return { ...s, baseCents: cents };
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function makeToppings(rng) {
|
|
32
|
+
return PIZZA_TOPPING_SHAPES.map(({ meat, ...t }) => {
|
|
33
|
+
const small = (int(rng, 16, 30) + (meat ? 8 : 0)) * 5;
|
|
34
|
+
return { ...t, allergens: [...t.allergens], pricesCents: { small, medium: r5(small * 1.25), large: r5(small * 1.5), xlarge: r5(small * 1.75) } };
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function makeMenu(rng, toppings) {
|
|
38
|
+
const meat = PIZZA_TOPPING_SHAPES.filter((t) => t.meat).map((t) => t.key);
|
|
39
|
+
const vegetarian = toppings.filter((t) => t.vegetarian).map((t) => t.key);
|
|
40
|
+
const vegan = toppings.filter((t) => t.vegan).map((t) => t.key);
|
|
41
|
+
const kinds = shuffle(rng, [...Array(5).fill("meat"), ...Array(5).fill("vegetarian"), ...Array(4).fill("vegan")]);
|
|
42
|
+
const names = new Set();
|
|
43
|
+
return kinds.map((kind, i) => {
|
|
44
|
+
let name = "";
|
|
45
|
+
do
|
|
46
|
+
name = `${word(rng)} ${pick(rng, MENU_SUFFIXES)}`;
|
|
47
|
+
while (names.has(name));
|
|
48
|
+
names.add(name);
|
|
49
|
+
const crust = pick(rng, ["classic", "classic", "thin"]);
|
|
50
|
+
const sauce = pick(rng, kind === "vegan" ? ["tomato", "tomato", "bbq"] : kind === "vegetarian" ? ["tomato", "tomato", "pesto", "garlic-cream", "bbq"] : ["tomato", "tomato", "bbq", "garlic-cream"]);
|
|
51
|
+
const cheese = pick(rng, kind === "vegan" ? ["none", "cashew"] : ["regular", "regular", "extra"]);
|
|
52
|
+
const chosen = kind === "meat"
|
|
53
|
+
? [...shuffle(rng, meat).slice(0, int(rng, 1, 2)), ...shuffle(rng, vegetarian).slice(0, int(rng, 1, 2))]
|
|
54
|
+
: shuffle(rng, kind === "vegan" ? vegan : vegetarian).slice(0, int(rng, 2, 4));
|
|
55
|
+
const parts = [sauce === "none" ? null : `${PIZZA_SAUCES.find((s) => s.key === sauce)?.name.toLowerCase()} sauce`, cheese === "none" ? null : PIZZA_CHEESES.find((c) => c.key === cheese)?.name.toLowerCase(), ...chosen.map((t) => toppings.find((x) => x.key === t)?.name.toLowerCase())];
|
|
56
|
+
const text = listed(parts.filter((p) => !!p));
|
|
57
|
+
return {
|
|
58
|
+
code: `PZ-${101 + i}`,
|
|
59
|
+
name,
|
|
60
|
+
description: `${text[0]?.toUpperCase()}${text.slice(1)} on a ${PIZZA_CRUSTS.find((c) => c.key === crust)?.name.toLowerCase()} crust.`,
|
|
61
|
+
crust,
|
|
62
|
+
sauce,
|
|
63
|
+
cheese,
|
|
64
|
+
toppings: [...chosen].sort(),
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function makeBranches(rng) {
|
|
69
|
+
const total = CITY_LIST.length * PIZZA_ROW_COUNTS.branchesPerCity;
|
|
70
|
+
const pickupOnly = new Set(shuffle(rng, Array.from({ length: total }, (_, i) => i)).slice(0, PIZZA_ROW_COUNTS.pickupOnly));
|
|
71
|
+
return CITY_LIST.flatMap((city, c) => shuffle(rng, DISTRICTS)
|
|
72
|
+
.slice(0, PIZZA_ROW_COUNTS.branchesPerCity)
|
|
73
|
+
.map((district, d) => {
|
|
74
|
+
const n = c * PIZZA_ROW_COUNTS.branchesPerCity + d;
|
|
75
|
+
const delivers = !pickupOnly.has(n);
|
|
76
|
+
return {
|
|
77
|
+
code: `BR-${101 + n}`,
|
|
78
|
+
name: `${city} ${district}`,
|
|
79
|
+
city,
|
|
80
|
+
address: `${int(rng, 2, 98)} ${word(rng)} ${pick(rng, STREETS)}, ${city}`,
|
|
81
|
+
delivers,
|
|
82
|
+
deliveryFeeCents: delivers ? int(rng, 6, 10) * 50 : null,
|
|
83
|
+
freeDeliveryFromCents: delivers ? pick(rng, [3000, 3500, 4000, 4500, 5000]) : null,
|
|
84
|
+
slotCapacity: int(rng, 4, 8),
|
|
85
|
+
};
|
|
86
|
+
}));
|
|
87
|
+
}
|
|
88
|
+
/** Diet filters a guest asks for; the cheapest menu pizza meeting each is out at a few branches on purpose. */
|
|
89
|
+
const DIET_TRAPS = [{ vegetarian: true, without: ["nuts"] }, { vegan: true, without: ["nuts"] }, { without: ["dairy"] }];
|
|
90
|
+
/**
|
|
91
|
+
* 0–2 toppings out at each branch, drawn from those the menu uses, so some menu
|
|
92
|
+
* pizzas cannot be made somewhere. Then, for each diet trap, two more branches
|
|
93
|
+
* run out of a topping of the cheapest menu pizza that meets it: there, the
|
|
94
|
+
* pizza a guest would pick from the menu alone cannot be made.
|
|
95
|
+
*/
|
|
96
|
+
function makeStockouts(rng, catalog) {
|
|
97
|
+
const used = [...new Set(catalog.pizzas.flatMap((p) => p.toppings))].sort();
|
|
98
|
+
const out = catalog.branches.flatMap((b) => shuffle(rng, used).slice(0, int(rng, 0, 2)).map((toppingKey) => ({ branchCode: b.code, toppingKey })));
|
|
99
|
+
for (const trap of DIET_TRAPS) {
|
|
100
|
+
const cheapest = pizzaMenuSearch({ ...catalog, stockouts: [] }, { size: "medium", ...trap })[0];
|
|
101
|
+
if (!cheapest)
|
|
102
|
+
continue;
|
|
103
|
+
const able = catalog.branches.filter((b) => pizzaOutOfStock(out, b.code, cheapest.toppings).length === 0);
|
|
104
|
+
for (const b of shuffle(rng, able).slice(0, 2))
|
|
105
|
+
out.push({ branchCode: b.code, toppingKey: pick(rng, cheapest.toppings) });
|
|
106
|
+
}
|
|
107
|
+
return out.sort((x, y) => x.branchCode.localeCompare(y.branchCode) || x.toppingKey.localeCompare(y.toppingKey));
|
|
108
|
+
}
|
|
109
|
+
function makeCustomers(rng, menu) {
|
|
110
|
+
const out = new Map();
|
|
111
|
+
while (out.size < PIZZA_ROW_COUNTS.customers) {
|
|
112
|
+
const first = pick(rng, FIRST_NAMES);
|
|
113
|
+
const last = pick(rng, LAST_NAMES);
|
|
114
|
+
const email = `${first}.${last}${int(rng, 1, 9)}@example.org`.toLowerCase();
|
|
115
|
+
const city = pick(rng, CITY_LIST);
|
|
116
|
+
const address = `${int(rng, 2, 98)} ${word(rng)} ${pick(rng, STREETS)}, ${city}`;
|
|
117
|
+
if (!out.has(email))
|
|
118
|
+
out.set(email, { name: `${first} ${last}`, email, city, address, favourite: pick(rng, menu) });
|
|
119
|
+
}
|
|
120
|
+
return [...out.values()];
|
|
121
|
+
}
|
|
122
|
+
export function pizzaRows(seed) {
|
|
123
|
+
const rng = substream(seed, "pizza");
|
|
124
|
+
const sizes = makeSizes(rng);
|
|
125
|
+
const toppings = makeToppings(rng);
|
|
126
|
+
const pizzas = makeMenu(rng, toppings);
|
|
127
|
+
const branches = makeBranches(rng);
|
|
128
|
+
const stockouts = makeStockouts(rng, { sizes, toppings, pizzas, branches });
|
|
129
|
+
const customers = makeCustomers(rng, pizzas);
|
|
130
|
+
const rows = { sizes, toppings, pizzas, branches, stockouts, orders: [] };
|
|
131
|
+
const canMake = (b, p) => pizzaOutOfStock(stockouts, b.code, p.toppings).length === 0;
|
|
132
|
+
const customLine = (b) => {
|
|
133
|
+
const size = pick(rng, PIZZA_SIZE_KEYS);
|
|
134
|
+
const crusts = PIZZA_CRUSTS.filter((c) => c.sizes.includes(size));
|
|
135
|
+
const stocked = toppings.filter((t) => pizzaOutOfStock(stockouts, b.code, [t.key]).length === 0).map((t) => t.key);
|
|
136
|
+
return { size, crust: pick(rng, crusts).key, sauce: pick(rng, ["tomato", "tomato", "bbq", "pesto"]), cheese: pick(rng, ["regular", "regular", "extra"]), toppings: shuffle(rng, stocked).slice(0, int(rng, 1, 4)), quantity: int(rng, 1, 2) };
|
|
137
|
+
};
|
|
138
|
+
const menuLine = (b, want, quantity) => {
|
|
139
|
+
const p = want && canMake(b, want) ? want : pick(rng, pizzas.filter((x) => canMake(b, x)));
|
|
140
|
+
return p ? { pizzaCode: p.code, size: pick(rng, PIZZA_SIZE_KEYS), quantity } : null;
|
|
141
|
+
};
|
|
142
|
+
const place = (c, b, slotDate, slotTime, lines, status, fulfilment) => {
|
|
143
|
+
const r = pizzaPlaceOrder(rows, { branchCode: b.code, fulfilment, address: fulfilment === "delivery" ? c.address : null, slotDate, slotTime, lines });
|
|
144
|
+
if ("problem" in r)
|
|
145
|
+
return false;
|
|
146
|
+
const order = {
|
|
147
|
+
orderNo: `PO-${10001 + rows.orders.length}`,
|
|
148
|
+
branchCode: b.code,
|
|
149
|
+
customerName: c.name,
|
|
150
|
+
customerEmail: c.email,
|
|
151
|
+
fulfilment,
|
|
152
|
+
address: fulfilment === "delivery" ? c.address : null,
|
|
153
|
+
slotDate,
|
|
154
|
+
slotTime,
|
|
155
|
+
status,
|
|
156
|
+
lines: r.quote.lines,
|
|
157
|
+
subtotalCents: r.quote.subtotalCents,
|
|
158
|
+
deliveryFeeCents: r.quote.deliveryFeeCents,
|
|
159
|
+
totalCents: r.quote.totalCents,
|
|
160
|
+
createdAt: new Date(Date.UTC(2027, 3, 1 + int(rng, 0, 29), int(rng, 8, 22), int(rng, 0, 59))).toISOString(),
|
|
161
|
+
};
|
|
162
|
+
rows.orders.push(order);
|
|
163
|
+
return true;
|
|
164
|
+
};
|
|
165
|
+
const busyDay = () => addDays(BUSY_FROM, int(rng, 0, BUSY_DAYS - 1));
|
|
166
|
+
const inCity = (city) => branches.filter((b) => b.city === city);
|
|
167
|
+
for (let i = 0; i < PIZZA_ROW_COUNTS.orders; i++) {
|
|
168
|
+
const c = pick(rng, customers);
|
|
169
|
+
const b = pick(rng, inCity(c.city));
|
|
170
|
+
const fulfilment = b.delivers && rng() < 0.5 ? "delivery" : "pickup";
|
|
171
|
+
const lines = Array.from({ length: rng() < 0.7 ? 1 : 2 }, () => (rng() < 0.75 ? menuLine(b, rng() < 0.6 ? c.favourite : null, int(rng, 1, 2)) : customLine(b))).filter((x) => !!x);
|
|
172
|
+
const roll = rng();
|
|
173
|
+
const status = roll < 0.45 ? "received" : roll < 0.6 ? "preparing" : roll < 0.75 ? (fulfilment === "delivery" ? "out_for_delivery" : "preparing") : roll < 0.9 ? "delivered" : "cancelled";
|
|
174
|
+
place(c, b, busyDay(), pick(rng, PIZZA_SLOT_TIMES), lines, status, fulfilment);
|
|
175
|
+
}
|
|
176
|
+
// Full on purpose: a run of 2–3 slots with no room left, then a slot with room for one pizza.
|
|
177
|
+
for (let i = 0; i < PIZZA_ROW_COUNTS.fullRuns; i++) {
|
|
178
|
+
const b = pick(rng, branches);
|
|
179
|
+
const date = busyDay();
|
|
180
|
+
const start = int(rng, 6, 14);
|
|
181
|
+
const length = int(rng, 2, 3);
|
|
182
|
+
for (let s = start; s <= start + length; s++) {
|
|
183
|
+
const time = PIZZA_SLOT_TIMES[s];
|
|
184
|
+
const keep = s === start + length ? 1 : 0;
|
|
185
|
+
for (let guard = 0; pizzaSlotLeft(b, rows.orders, date, time) > keep && guard < 20; guard++) {
|
|
186
|
+
const c = pick(rng, customers);
|
|
187
|
+
const item = menuLine(b, c.favourite, Math.min(pizzaSlotLeft(b, rows.orders, date, time) - keep, int(rng, 1, 3)));
|
|
188
|
+
if (item)
|
|
189
|
+
place(c, b, date, time, [item], rng() < 0.7 ? "received" : "preparing", "pickup");
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
// A few customers with their favourite pizza in two more received orders.
|
|
194
|
+
for (const c of shuffle(rng, customers).slice(0, PIZZA_ROW_COUNTS.repeatCustomers)) {
|
|
195
|
+
for (let n = 0, guard = 0; n < 2 && guard < 10; guard++) {
|
|
196
|
+
const b = pick(rng, inCity(c.city).filter((x) => canMake(x, c.favourite)).concat(branches.filter((x) => canMake(x, c.favourite))));
|
|
197
|
+
if (place(c, b, busyDay(), pick(rng, PIZZA_SLOT_TIMES), [{ pizzaCode: c.favourite.code, size: pick(rng, PIZZA_SIZE_KEYS), quantity: 1 }], "received", "pickup"))
|
|
198
|
+
n++;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return rows;
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=generate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/sites/pizza/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAClF,OAAO,EAAY,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACrJ,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,eAAe,EAAE,aAAa,EAA4C,MAAM,YAAY,CAAC;AAGxI;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,eAAe,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,eAAe,EAAE,CAAC,EAAW,CAAC;AAErJ,yEAAyE;AACzE,MAAM,SAAS,GAA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C,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;YACnI,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,gBAAgB,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,eAAe,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,EAAE,UAAU,EAAE,QAAQ,CAAC;gBAAE,CAAC,EAAE,CAAC;QACvK,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { PIZZA_ALLERGENS, PIZZA_CHEESES, PIZZA_CRUSTS, PIZZA_HOLDING, PIZZA_MAX_LINES, PIZZA_MAX_QUANTITY, PIZZA_MAX_TOPPINGS, PIZZA_SAUCES, PIZZA_SIZE_KEYS, PIZZA_SLOT_TIMES, PIZZA_STATUSES, PIZZA_WINDOW, } from "./catalog.js";
|
|
2
|
+
export { PIZZA_ROW_COUNTS, pizzaRows } from "./generate.js";
|
|
3
|
+
export { pizzaChangeLine, pizzaConfigProblem, pizzaDeliveryFeeCents, pizzaDiet, pizzaLockProblem, pizzaMenuSearch, pizzaOutOfStock, pizzaPlaceOrder, pizzaQuote, pizzaResolveLine, pizzaSizeFor, pizzaSlotLeft, pizzaSlots, pizzaToppingsKey, pizzaUnitCents, type PizzaCatalog, type PizzaDiet, type PizzaLineChange, type PizzaLineInput, type PizzaMenuOffer, type PizzaMenuQuery, type PizzaOrderInput, type PizzaProblem, type PizzaQuote, type PizzaQuoteInput, type PizzaSlot, type PizzaSlotQuery, } from "./rules.js";
|
|
4
|
+
export type { PizzaMenuItem, PizzaAllergen, PizzaBranch, PizzaCheese, PizzaConfig, PizzaCrust, PizzaFulfilment, PizzaOption, PizzaOrder, PizzaOrderLine, PizzaOrderStatus, PizzaRows, PizzaSauce, PizzaSize, PizzaSizeKey, PizzaStockout, PizzaTopping, } from "./types.js";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { PIZZA_ALLERGENS, PIZZA_CHEESES, PIZZA_CRUSTS, PIZZA_HOLDING, PIZZA_MAX_LINES, PIZZA_MAX_QUANTITY, PIZZA_MAX_TOPPINGS, PIZZA_SAUCES, PIZZA_SIZE_KEYS, PIZZA_SLOT_TIMES, PIZZA_STATUSES, PIZZA_WINDOW, } from "./catalog.js";
|
|
2
|
+
export { PIZZA_ROW_COUNTS, pizzaRows } from "./generate.js";
|
|
3
|
+
export { pizzaChangeLine, pizzaConfigProblem, pizzaDeliveryFeeCents, pizzaDiet, pizzaLockProblem, pizzaMenuSearch, pizzaOutOfStock, pizzaPlaceOrder, pizzaQuote, pizzaResolveLine, pizzaSizeFor, pizzaSlotLeft, pizzaSlots, pizzaToppingsKey, pizzaUnitCents, } from "./rules.js";
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/sites/pizza/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,aAAa,EACb,YAAY,EACZ,aAAa,EACb,eAAe,EACf,kBAAkB,EAClB,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,YAAY,GACb,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,qBAAqB,EACrB,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,eAAe,EACf,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,cAAc,GAaf,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { PizzaMenuItem, PizzaAllergen, PizzaBranch, PizzaConfig, PizzaFulfilment, PizzaOrder, PizzaOrderLine, PizzaRows, PizzaSize, PizzaStockout } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* The pizza site's rules, as pure functions over rows. apps/pizza enforces them
|
|
4
|
+
* inside every write's transaction and answers every search with them, and the
|
|
5
|
+
* intent corpus derives its answer keys with them, so the site and the keys
|
|
6
|
+
* cannot disagree about what can be ordered, when, or what it costs.
|
|
7
|
+
*/
|
|
8
|
+
export type PizzaProblem = {
|
|
9
|
+
code: string;
|
|
10
|
+
message: string;
|
|
11
|
+
};
|
|
12
|
+
export type PizzaCatalog = Pick<PizzaRows, "sizes" | "toppings">;
|
|
13
|
+
/** One line of an order as a caller asks for it: a menu pizza (with any option named in its place), or a pizza from scratch. */
|
|
14
|
+
export type PizzaLineInput = {
|
|
15
|
+
pizzaCode?: string | null;
|
|
16
|
+
size: string;
|
|
17
|
+
crust?: string;
|
|
18
|
+
sauce?: string;
|
|
19
|
+
cheese?: string;
|
|
20
|
+
toppings?: readonly string[];
|
|
21
|
+
quantity: number;
|
|
22
|
+
};
|
|
23
|
+
export type PizzaQuoteInput = {
|
|
24
|
+
branchCode: string;
|
|
25
|
+
fulfilment: PizzaFulfilment;
|
|
26
|
+
lines: readonly PizzaLineInput[];
|
|
27
|
+
};
|
|
28
|
+
export type PizzaOrderInput = PizzaQuoteInput & {
|
|
29
|
+
address?: string | null;
|
|
30
|
+
slotDate: string;
|
|
31
|
+
slotTime: string;
|
|
32
|
+
};
|
|
33
|
+
export type PizzaQuote = {
|
|
34
|
+
branchCode: string;
|
|
35
|
+
fulfilment: PizzaFulfilment;
|
|
36
|
+
lines: PizzaOrderLine[];
|
|
37
|
+
subtotalCents: number;
|
|
38
|
+
deliveryFeeCents: number;
|
|
39
|
+
totalCents: number;
|
|
40
|
+
outOfStock: string[];
|
|
41
|
+
};
|
|
42
|
+
export type PizzaDiet = {
|
|
43
|
+
vegetarian: boolean;
|
|
44
|
+
vegan: boolean;
|
|
45
|
+
allergens: PizzaAllergen[];
|
|
46
|
+
};
|
|
47
|
+
export type PizzaMenuQuery = {
|
|
48
|
+
size: string;
|
|
49
|
+
branchCode?: string;
|
|
50
|
+
vegetarian?: boolean;
|
|
51
|
+
vegan?: boolean;
|
|
52
|
+
without?: readonly string[];
|
|
53
|
+
maxPriceCents?: number;
|
|
54
|
+
toppings?: readonly string[];
|
|
55
|
+
};
|
|
56
|
+
export type PizzaMenuOffer = PizzaDiet & {
|
|
57
|
+
pizzaCode: string;
|
|
58
|
+
name: string;
|
|
59
|
+
size: string;
|
|
60
|
+
priceCents: number;
|
|
61
|
+
crust: string;
|
|
62
|
+
sauce: string;
|
|
63
|
+
cheese: string;
|
|
64
|
+
toppings: string[];
|
|
65
|
+
};
|
|
66
|
+
export type PizzaSlot = {
|
|
67
|
+
time: string;
|
|
68
|
+
capacity: number;
|
|
69
|
+
left: number;
|
|
70
|
+
};
|
|
71
|
+
export type PizzaSlotQuery = {
|
|
72
|
+
branchCode: string;
|
|
73
|
+
date: string;
|
|
74
|
+
pizzas?: number;
|
|
75
|
+
from?: string;
|
|
76
|
+
};
|
|
77
|
+
/** A change to one line of a received order: options replaced, toppings replaced, added or removed, quantity. */
|
|
78
|
+
export type PizzaLineChange = {
|
|
79
|
+
size?: string;
|
|
80
|
+
crust?: string;
|
|
81
|
+
sauce?: string;
|
|
82
|
+
cheese?: string;
|
|
83
|
+
toppings?: readonly string[];
|
|
84
|
+
addToppings?: readonly string[];
|
|
85
|
+
removeToppings?: readonly string[];
|
|
86
|
+
quantity?: number;
|
|
87
|
+
};
|
|
88
|
+
/** A topping set as one comparable string: the keys sorted and comma-joined. */
|
|
89
|
+
export declare const pizzaToppingsKey: (toppings: readonly string[]) => string;
|
|
90
|
+
/** The smallest size that serves `people`, or null when none does. */
|
|
91
|
+
export declare function pizzaSizeFor(sizes: readonly PizzaSize[], people: number): PizzaSize | null;
|
|
92
|
+
/** The configuration a line asks for: its menu pizza's, with each option it names in its place; from scratch, a classic crust, tomato sauce, mozzarella and the toppings it names. */
|
|
93
|
+
export declare function pizzaResolveLine(pizzas: readonly PizzaMenuItem[], item: PizzaLineInput): {
|
|
94
|
+
config: PizzaConfig;
|
|
95
|
+
pizzaCode: string | null;
|
|
96
|
+
} | {
|
|
97
|
+
problem: PizzaProblem;
|
|
98
|
+
};
|
|
99
|
+
/** Why a configuration cannot be made at all: an unknown option, a crust not made in the size, a topping twice, too many, or nothing on it. */
|
|
100
|
+
export declare function pizzaConfigProblem(catalog: PizzaCatalog, c: PizzaConfig): PizzaProblem | null;
|
|
101
|
+
/** One pizza's price: the size's base, the crust and cheese surcharges in that size, and each topping's price in that size. The configuration must be valid. */
|
|
102
|
+
export declare function pizzaUnitCents(catalog: PizzaCatalog, c: PizzaConfig): number;
|
|
103
|
+
/** Vegetarian or vegan when every part is; the allergens of every part, in PIZZA_ALLERGENS order. */
|
|
104
|
+
export declare function pizzaDiet(catalog: PizzaCatalog, c: Omit<PizzaConfig, "size">): PizzaDiet;
|
|
105
|
+
/** The toppings in `toppings` that the branch has run out of, sorted. */
|
|
106
|
+
export declare function pizzaOutOfStock(stockouts: readonly PizzaStockout[], branchCode: string, toppings: readonly string[]): string[];
|
|
107
|
+
/** No fee for pickup; for delivery the branch's fee, unless the subtotal reaches its free-delivery threshold. */
|
|
108
|
+
export declare function pizzaDeliveryFeeCents(branch: PizzaBranch, fulfilment: PizzaFulfilment, subtotalCents: number): number;
|
|
109
|
+
/** Pizzas the branch can still make in one slot: its capacity less every pizza of the orders that hold it (all but cancelled), `exceptOrderNo` left out. */
|
|
110
|
+
export declare function pizzaSlotLeft(branch: PizzaBranch, orders: readonly PizzaOrder[], date: string, time: string, exceptOrderNo?: string): number;
|
|
111
|
+
/** A branch's slots on a date, from `from` on, each with what it can still make — only those with room for `pizzas` when it is given. */
|
|
112
|
+
export declare function pizzaSlots(rows: Pick<PizzaRows, "branches" | "orders">, q: PizzaSlotQuery): PizzaSlot[];
|
|
113
|
+
/** Every line resolved, checked and priced at the branch, and the order's subtotal, delivery fee and total. Stock is reported, not refused. */
|
|
114
|
+
export declare function pizzaQuote(rows: Omit<PizzaRows, "orders">, input: PizzaQuoteInput): {
|
|
115
|
+
quote: PizzaQuote;
|
|
116
|
+
} | {
|
|
117
|
+
problem: PizzaProblem;
|
|
118
|
+
};
|
|
119
|
+
/** The rule every new order is held to: the slot, the address, the lines (pizzaQuote), stock at the branch, then room in the slot. On success, the priced order. */
|
|
120
|
+
export declare function pizzaPlaceOrder(rows: PizzaRows, input: PizzaOrderInput): {
|
|
121
|
+
quote: PizzaQuote;
|
|
122
|
+
} | {
|
|
123
|
+
problem: PizzaProblem;
|
|
124
|
+
};
|
|
125
|
+
/** Only a received order can be changed or cancelled. */
|
|
126
|
+
export declare function pizzaLockProblem(order: Pick<PizzaOrder, "orderNo" | "status">): PizzaProblem | null;
|
|
127
|
+
/** One line of a received order changed: the new configuration checked, its toppings in stock, the slot's room for the new quantities, the order re-priced. */
|
|
128
|
+
export declare function pizzaChangeLine(rows: PizzaRows, order: PizzaOrder, line: number, change: PizzaLineChange): {
|
|
129
|
+
order: PizzaOrder;
|
|
130
|
+
} | {
|
|
131
|
+
problem: PizzaProblem;
|
|
132
|
+
};
|
|
133
|
+
/** Every menu pizza that can be made in the size (at the branch, when one is named: none of its toppings out there) and meets each filter, cheapest first. */
|
|
134
|
+
export declare function pizzaMenuSearch(rows: Omit<PizzaRows, "orders">, q: PizzaMenuQuery): PizzaMenuOffer[];
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { isDate } from "../../stays.js";
|
|
2
|
+
import { PIZZA_ALLERGENS, PIZZA_CHEESES, PIZZA_CRUSTS, PIZZA_HOLDING, PIZZA_MAX_LINES, PIZZA_MAX_QUANTITY, PIZZA_MAX_TOPPINGS, PIZZA_SAUCES, PIZZA_SLOT_TIMES, PIZZA_WINDOW } from "./catalog.js";
|
|
3
|
+
const norm = (s) => s.trim().toLowerCase();
|
|
4
|
+
const code = (s) => s.trim().toUpperCase();
|
|
5
|
+
const byKey = (xs, key) => xs.find((x) => x.key === key);
|
|
6
|
+
const listed = (xs) => (xs.length <= 1 ? (xs[0] ?? "") : `${xs.slice(0, -1).join(", ")} and ${xs[xs.length - 1]}`);
|
|
7
|
+
const fail = (c, message) => ({ problem: { code: c, message } });
|
|
8
|
+
/** A topping set as one comparable string: the keys sorted and comma-joined. */
|
|
9
|
+
export const pizzaToppingsKey = (toppings) => [...toppings].sort().join(",");
|
|
10
|
+
/** The smallest size that serves `people`, or null when none does. */
|
|
11
|
+
export function pizzaSizeFor(sizes, people) {
|
|
12
|
+
return [...sizes].sort((x, y) => x.serves - y.serves).find((s) => s.serves >= people) ?? null;
|
|
13
|
+
}
|
|
14
|
+
/** The configuration a line asks for: its menu pizza's, with each option it names in its place; from scratch, a classic crust, tomato sauce, mozzarella and the toppings it names. */
|
|
15
|
+
export function pizzaResolveLine(pizzas, item) {
|
|
16
|
+
const base = item.pizzaCode ? pizzas.find((p) => p.code === code(item.pizzaCode)) : undefined;
|
|
17
|
+
if (item.pizzaCode && !base)
|
|
18
|
+
return fail("UNKNOWN_PIZZA", `no menu pizza ${item.pizzaCode}`);
|
|
19
|
+
const from = base ?? { crust: "classic", sauce: "tomato", cheese: "regular", toppings: [] };
|
|
20
|
+
return {
|
|
21
|
+
pizzaCode: base?.code ?? null,
|
|
22
|
+
config: { size: norm(item.size), crust: norm(item.crust ?? from.crust), sauce: norm(item.sauce ?? from.sauce), cheese: norm(item.cheese ?? from.cheese), toppings: (item.toppings ?? from.toppings).map(norm).sort() },
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** Why a configuration cannot be made at all: an unknown option, a crust not made in the size, a topping twice, too many, or nothing on it. */
|
|
26
|
+
export function pizzaConfigProblem(catalog, c) {
|
|
27
|
+
const size = byKey(catalog.sizes, c.size);
|
|
28
|
+
if (!size)
|
|
29
|
+
return { code: "UNKNOWN_SIZE", message: `no size ${c.size}; the sizes are ${listed(catalog.sizes.map((s) => s.key))}` };
|
|
30
|
+
const crust = byKey(PIZZA_CRUSTS, c.crust);
|
|
31
|
+
if (!crust)
|
|
32
|
+
return { code: "UNKNOWN_CRUST", message: `no crust ${c.crust}; the crusts are ${listed(PIZZA_CRUSTS.map((x) => x.key))}` };
|
|
33
|
+
if (!crust.sizes.includes(size.key))
|
|
34
|
+
return { code: "CRUST_NOT_IN_SIZE", message: `the ${crust.name} crust is made in ${listed(crust.sizes)} only, not ${size.key}` };
|
|
35
|
+
if (!byKey(PIZZA_SAUCES, c.sauce))
|
|
36
|
+
return { code: "UNKNOWN_SAUCE", message: `no sauce ${c.sauce}; the sauces are ${listed(PIZZA_SAUCES.map((x) => x.key))}` };
|
|
37
|
+
if (!byKey(PIZZA_CHEESES, c.cheese))
|
|
38
|
+
return { code: "UNKNOWN_CHEESE", message: `no cheese ${c.cheese}; the cheeses are ${listed(PIZZA_CHEESES.map((x) => x.key))}` };
|
|
39
|
+
const unknown = c.toppings.find((t) => !byKey(catalog.toppings, t));
|
|
40
|
+
if (unknown !== undefined)
|
|
41
|
+
return { code: "UNKNOWN_TOPPING", message: `no topping ${unknown}` };
|
|
42
|
+
if (new Set(c.toppings).size !== c.toppings.length)
|
|
43
|
+
return { code: "DUPLICATE_TOPPING", message: "each topping can be on a pizza once" };
|
|
44
|
+
if (c.toppings.length > PIZZA_MAX_TOPPINGS)
|
|
45
|
+
return { code: "TOO_MANY_TOPPINGS", message: `a pizza has at most ${PIZZA_MAX_TOPPINGS} toppings` };
|
|
46
|
+
if (c.sauce === "none" && c.cheese === "none" && c.toppings.length === 0)
|
|
47
|
+
return { code: "EMPTY_PIZZA", message: "a pizza needs a sauce, a cheese or a topping" };
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
/** One pizza's price: the size's base, the crust and cheese surcharges in that size, and each topping's price in that size. The configuration must be valid. */
|
|
51
|
+
export function pizzaUnitCents(catalog, c) {
|
|
52
|
+
const size = byKey(catalog.sizes, c.size);
|
|
53
|
+
const crust = byKey(PIZZA_CRUSTS, c.crust);
|
|
54
|
+
const cheese = byKey(PIZZA_CHEESES, c.cheese);
|
|
55
|
+
const toppings = c.toppings.reduce((sum, t) => sum + (byKey(catalog.toppings, t)?.pricesCents[size.key] ?? 0), 0);
|
|
56
|
+
return size.baseCents + (crust?.surchargeCents[size.key] ?? 0) + (cheese?.surchargeCents[size.key] ?? 0) + toppings;
|
|
57
|
+
}
|
|
58
|
+
/** Vegetarian or vegan when every part is; the allergens of every part, in PIZZA_ALLERGENS order. */
|
|
59
|
+
export function pizzaDiet(catalog, c) {
|
|
60
|
+
const parts = [byKey(PIZZA_CRUSTS, c.crust), byKey(PIZZA_SAUCES, c.sauce), byKey(PIZZA_CHEESES, c.cheese), ...c.toppings.map((t) => byKey(catalog.toppings, t))].filter((p) => !!p);
|
|
61
|
+
return { vegetarian: parts.every((p) => p.vegetarian), vegan: parts.every((p) => p.vegan), allergens: PIZZA_ALLERGENS.filter((a) => parts.some((p) => p.allergens.includes(a))) };
|
|
62
|
+
}
|
|
63
|
+
/** The toppings in `toppings` that the branch has run out of, sorted. */
|
|
64
|
+
export function pizzaOutOfStock(stockouts, branchCode, toppings) {
|
|
65
|
+
const out = new Set(stockouts.filter((s) => s.branchCode === code(branchCode)).map((s) => s.toppingKey));
|
|
66
|
+
return [...new Set(toppings.filter((t) => out.has(t)))].sort();
|
|
67
|
+
}
|
|
68
|
+
/** No fee for pickup; for delivery the branch's fee, unless the subtotal reaches its free-delivery threshold. */
|
|
69
|
+
export function pizzaDeliveryFeeCents(branch, fulfilment, subtotalCents) {
|
|
70
|
+
if (fulfilment === "pickup")
|
|
71
|
+
return 0;
|
|
72
|
+
return branch.freeDeliveryFromCents !== null && subtotalCents >= branch.freeDeliveryFromCents ? 0 : (branch.deliveryFeeCents ?? 0);
|
|
73
|
+
}
|
|
74
|
+
/** Pizzas the branch can still make in one slot: its capacity less every pizza of the orders that hold it (all but cancelled), `exceptOrderNo` left out. */
|
|
75
|
+
export function pizzaSlotLeft(branch, orders, date, time, exceptOrderNo) {
|
|
76
|
+
const held = orders
|
|
77
|
+
.filter((o) => o.branchCode === branch.code && o.slotDate === date && o.slotTime === time && PIZZA_HOLDING.includes(o.status) && o.orderNo !== exceptOrderNo)
|
|
78
|
+
.reduce((sum, o) => sum + o.lines.reduce((n, i) => n + i.quantity, 0), 0);
|
|
79
|
+
return Math.max(0, branch.slotCapacity - held);
|
|
80
|
+
}
|
|
81
|
+
/** A branch's slots on a date, from `from` on, each with what it can still make — only those with room for `pizzas` when it is given. */
|
|
82
|
+
export function pizzaSlots(rows, q) {
|
|
83
|
+
const branch = rows.branches.find((b) => b.code === code(q.branchCode));
|
|
84
|
+
if (!branch || !isDate(q.date) || q.date < PIZZA_WINDOW.first || q.date > PIZZA_WINDOW.last)
|
|
85
|
+
return [];
|
|
86
|
+
return PIZZA_SLOT_TIMES.filter((t) => !q.from || t >= q.from)
|
|
87
|
+
.map((time) => ({ time, capacity: branch.slotCapacity, left: pizzaSlotLeft(branch, rows.orders, q.date, time) }))
|
|
88
|
+
.filter((s) => s.left >= (q.pizzas ?? 0));
|
|
89
|
+
}
|
|
90
|
+
/** Every line resolved, checked and priced at the branch, and the order's subtotal, delivery fee and total. Stock is reported, not refused. */
|
|
91
|
+
export function pizzaQuote(rows, input) {
|
|
92
|
+
const branch = rows.branches.find((b) => b.code === code(input.branchCode));
|
|
93
|
+
if (!branch)
|
|
94
|
+
return fail("UNKNOWN_BRANCH", `no branch ${input.branchCode}`);
|
|
95
|
+
if (input.fulfilment === "delivery" && !branch.delivers)
|
|
96
|
+
return fail("NO_DELIVERY", `${branch.name} does not deliver; order for pickup`);
|
|
97
|
+
if (input.lines.length === 0)
|
|
98
|
+
return fail("NO_LINES", "an order needs at least one pizza");
|
|
99
|
+
if (input.lines.length > PIZZA_MAX_LINES)
|
|
100
|
+
return fail("TOO_MANY_LINES", `an order has at most ${PIZZA_MAX_LINES} lines`);
|
|
101
|
+
const lines = [];
|
|
102
|
+
for (const [i, item] of input.lines.entries()) {
|
|
103
|
+
if (!Number.isInteger(item.quantity) || item.quantity < 1 || item.quantity > PIZZA_MAX_QUANTITY)
|
|
104
|
+
return fail("BAD_QUANTITY", `a line is 1 to ${PIZZA_MAX_QUANTITY} pizzas`);
|
|
105
|
+
const r = pizzaResolveLine(rows.pizzas, item);
|
|
106
|
+
if ("problem" in r)
|
|
107
|
+
return r;
|
|
108
|
+
const p = pizzaConfigProblem(rows, r.config);
|
|
109
|
+
if (p)
|
|
110
|
+
return { problem: p };
|
|
111
|
+
const unitCents = pizzaUnitCents(rows, r.config);
|
|
112
|
+
lines.push({ line: i + 1, pizzaCode: r.pizzaCode, ...r.config, quantity: item.quantity, unitCents, lineCents: unitCents * item.quantity });
|
|
113
|
+
}
|
|
114
|
+
const subtotalCents = lines.reduce((sum, i) => sum + i.lineCents, 0);
|
|
115
|
+
const deliveryFeeCents = pizzaDeliveryFeeCents(branch, input.fulfilment, subtotalCents);
|
|
116
|
+
const outOfStock = pizzaOutOfStock(rows.stockouts, branch.code, lines.flatMap((i) => i.toppings));
|
|
117
|
+
return { quote: { branchCode: branch.code, fulfilment: input.fulfilment, lines, subtotalCents, deliveryFeeCents, totalCents: subtotalCents + deliveryFeeCents, outOfStock } };
|
|
118
|
+
}
|
|
119
|
+
/** The slot rules: a date in the window, one of the slot times. */
|
|
120
|
+
function slotProblem(date, time) {
|
|
121
|
+
if (!isDate(date))
|
|
122
|
+
return { code: "BAD_DATE", message: `slot date ${date} is not a date (YYYY-MM-DD)` };
|
|
123
|
+
if (date < PIZZA_WINDOW.first || date > PIZZA_WINDOW.last)
|
|
124
|
+
return { code: "OUTSIDE_WINDOW", message: `orders are taken for slots from ${PIZZA_WINDOW.first} to ${PIZZA_WINDOW.last}` };
|
|
125
|
+
if (!PIZZA_SLOT_TIMES.includes(time))
|
|
126
|
+
return { code: "BAD_SLOT_TIME", message: `slots start every 30 minutes from ${PIZZA_SLOT_TIMES[0]} to ${PIZZA_SLOT_TIMES[PIZZA_SLOT_TIMES.length - 1]}` };
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
const outMessage = (rows, branch, out) => `the ${branch} branch is out of ${listed(out.map((t) => rows.toppings.find((x) => x.key === t)?.name.toLowerCase() ?? t))}`;
|
|
130
|
+
/** The rule every new order is held to: the slot, the address, the lines (pizzaQuote), stock at the branch, then room in the slot. On success, the priced order. */
|
|
131
|
+
export function pizzaPlaceOrder(rows, input) {
|
|
132
|
+
if (!rows.branches.some((b) => b.code === code(input.branchCode)))
|
|
133
|
+
return fail("UNKNOWN_BRANCH", `no branch ${input.branchCode}`);
|
|
134
|
+
const slot = slotProblem(input.slotDate, input.slotTime);
|
|
135
|
+
if (slot)
|
|
136
|
+
return { problem: slot };
|
|
137
|
+
if (input.fulfilment === "delivery" && !(input.address ?? "").trim())
|
|
138
|
+
return fail("NO_ADDRESS", "a delivery needs an address");
|
|
139
|
+
const q = pizzaQuote(rows, input);
|
|
140
|
+
if ("problem" in q)
|
|
141
|
+
return q;
|
|
142
|
+
const branch = rows.branches.find((b) => b.code === q.quote.branchCode);
|
|
143
|
+
if (q.quote.outOfStock.length)
|
|
144
|
+
return fail("TOPPING_OUT", outMessage(rows, branch.name, q.quote.outOfStock));
|
|
145
|
+
const need = q.quote.lines.reduce((n, i) => n + i.quantity, 0);
|
|
146
|
+
const left = pizzaSlotLeft(branch, rows.orders, input.slotDate, input.slotTime);
|
|
147
|
+
if (need > left)
|
|
148
|
+
return fail("SLOT_FULL", `${branch.name} can make ${left} more pizza(s) in the ${input.slotTime} slot on ${input.slotDate}; this order has ${need}`);
|
|
149
|
+
return q;
|
|
150
|
+
}
|
|
151
|
+
/** Only a received order can be changed or cancelled. */
|
|
152
|
+
export function pizzaLockProblem(order) {
|
|
153
|
+
if (order.status === "cancelled")
|
|
154
|
+
return { code: "ALREADY_CANCELLED", message: `order ${order.orderNo} is already cancelled` };
|
|
155
|
+
if (order.status !== "received")
|
|
156
|
+
return { code: "ORDER_LOCKED", message: `order ${order.orderNo} is ${order.status.replace(/_/g, " ")}; only a received order can be changed or cancelled` };
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
/** One line of a received order changed: the new configuration checked, its toppings in stock, the slot's room for the new quantities, the order re-priced. */
|
|
160
|
+
export function pizzaChangeLine(rows, order, line, change) {
|
|
161
|
+
const lock = pizzaLockProblem(order);
|
|
162
|
+
if (lock)
|
|
163
|
+
return { problem: lock };
|
|
164
|
+
const item = order.lines.find((i) => i.line === line);
|
|
165
|
+
if (!item)
|
|
166
|
+
return fail("UNKNOWN_LINE", `order ${order.orderNo} has no line ${line}`);
|
|
167
|
+
let toppings = (change.toppings ?? item.toppings).map(norm);
|
|
168
|
+
for (const t of (change.removeToppings ?? []).map(norm)) {
|
|
169
|
+
if (!toppings.includes(t))
|
|
170
|
+
return fail("TOPPING_NOT_ON_PIZZA", `line ${line} has no ${t} to remove`);
|
|
171
|
+
toppings = toppings.filter((x) => x !== t);
|
|
172
|
+
}
|
|
173
|
+
toppings = [...toppings, ...(change.addToppings ?? []).map(norm)];
|
|
174
|
+
const asInput = (i) => ({ size: i.size, crust: i.crust, sauce: i.sauce, cheese: i.cheese, toppings: i.toppings, quantity: i.quantity });
|
|
175
|
+
const changed = { size: change.size ?? item.size, crust: change.crust ?? item.crust, sauce: change.sauce ?? item.sauce, cheese: change.cheese ?? item.cheese, toppings, quantity: change.quantity ?? item.quantity };
|
|
176
|
+
const q = pizzaQuote(rows, { branchCode: order.branchCode, fulfilment: order.fulfilment, lines: order.lines.map((i) => (i.line === line ? changed : asInput(i))) });
|
|
177
|
+
if ("problem" in q)
|
|
178
|
+
return q;
|
|
179
|
+
const branch = rows.branches.find((b) => b.code === order.branchCode);
|
|
180
|
+
const now = q.quote.lines[order.lines.indexOf(item)];
|
|
181
|
+
const out = pizzaOutOfStock(rows.stockouts, branch.code, now.toppings);
|
|
182
|
+
if (out.length)
|
|
183
|
+
return fail("TOPPING_OUT", outMessage(rows, branch.name, out));
|
|
184
|
+
const need = q.quote.lines.reduce((n, i) => n + i.quantity, 0);
|
|
185
|
+
const left = pizzaSlotLeft(branch, rows.orders, order.slotDate, order.slotTime, order.orderNo);
|
|
186
|
+
if (need > left)
|
|
187
|
+
return fail("SLOT_FULL", `${branch.name} can make ${left} more pizza(s) for this order's slot; it would have ${need}`);
|
|
188
|
+
const lines = q.quote.lines.map((i, n) => ({ ...i, pizzaCode: order.lines[n]?.pizzaCode ?? null, line: order.lines[n]?.line ?? i.line }));
|
|
189
|
+
return { order: { ...order, lines, subtotalCents: q.quote.subtotalCents, deliveryFeeCents: q.quote.deliveryFeeCents, totalCents: q.quote.totalCents } };
|
|
190
|
+
}
|
|
191
|
+
/** Every menu pizza that can be made in the size (at the branch, when one is named: none of its toppings out there) and meets each filter, cheapest first. */
|
|
192
|
+
export function pizzaMenuSearch(rows, q) {
|
|
193
|
+
const size = norm(q.size);
|
|
194
|
+
const without = (q.without ?? []).map(norm).filter(Boolean);
|
|
195
|
+
const must = (q.toppings ?? []).map(norm).filter(Boolean);
|
|
196
|
+
if (q.branchCode && !rows.branches.some((b) => b.code === code(q.branchCode)))
|
|
197
|
+
return [];
|
|
198
|
+
const offers = [];
|
|
199
|
+
for (const p of rows.pizzas) {
|
|
200
|
+
const config = { size, crust: p.crust, sauce: p.sauce, cheese: p.cheese, toppings: p.toppings };
|
|
201
|
+
if (pizzaConfigProblem(rows, config))
|
|
202
|
+
continue;
|
|
203
|
+
if (q.branchCode && pizzaOutOfStock(rows.stockouts, q.branchCode, p.toppings).length)
|
|
204
|
+
continue;
|
|
205
|
+
const diet = pizzaDiet(rows, config);
|
|
206
|
+
if ((q.vegetarian && !diet.vegetarian) || (q.vegan && !diet.vegan) || without.some((a) => diet.allergens.includes(a)))
|
|
207
|
+
continue;
|
|
208
|
+
if (must.some((t) => !p.toppings.includes(t)))
|
|
209
|
+
continue;
|
|
210
|
+
const priceCents = pizzaUnitCents(rows, config);
|
|
211
|
+
if (q.maxPriceCents !== undefined && priceCents > q.maxPriceCents)
|
|
212
|
+
continue;
|
|
213
|
+
offers.push({ pizzaCode: p.code, name: p.name, size, priceCents, crust: p.crust, sauce: p.sauce, cheese: p.cheese, toppings: p.toppings, ...diet });
|
|
214
|
+
}
|
|
215
|
+
return offers.sort((x, y) => x.priceCents - y.priceCents || x.pizzaCode.localeCompare(y.pizzaCode));
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=rules.js.map
|