@benchme/scenarios 0.9.0 → 0.10.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.
Files changed (132) hide show
  1. package/dist/acme-v1/index.d.ts +2 -1
  2. package/dist/acme-v1/index.js +4 -1
  3. package/dist/acme-v1/index.js.map +1 -1
  4. package/dist/acme-v1/names.d.ts +3 -0
  5. package/dist/acme-v1/names.js +3 -0
  6. package/dist/acme-v1/names.js.map +1 -1
  7. package/dist/guide-v1/index.js +2 -0
  8. package/dist/guide-v1/index.js.map +1 -1
  9. package/dist/index.d.ts +14 -2
  10. package/dist/index.js +15 -2
  11. package/dist/index.js.map +1 -1
  12. package/dist/prng.d.ts +7 -0
  13. package/dist/prng.js +12 -0
  14. package/dist/prng.js.map +1 -1
  15. package/dist/scenario.d.ts +68 -0
  16. package/dist/scenario.js.map +1 -1
  17. package/dist/shops-v1/index.js +2 -0
  18. package/dist/shops-v1/index.js.map +1 -1
  19. package/dist/sites/cinema/generate.d.ts +22 -0
  20. package/dist/sites/cinema/generate.js +258 -0
  21. package/dist/sites/cinema/generate.js.map +1 -0
  22. package/dist/sites/cinema/index.d.ts +3 -0
  23. package/dist/sites/cinema/index.js +4 -0
  24. package/dist/sites/cinema/index.js.map +1 -0
  25. package/dist/sites/cinema/rules.d.ts +142 -0
  26. package/dist/sites/cinema/rules.js +191 -0
  27. package/dist/sites/cinema/rules.js.map +1 -0
  28. package/dist/sites/cinema/types.d.ts +93 -0
  29. package/dist/sites/cinema/types.js +2 -0
  30. package/dist/sites/cinema/types.js.map +1 -0
  31. package/dist/sites/clinic/generate.d.ts +28 -0
  32. package/dist/sites/clinic/generate.js +282 -0
  33. package/dist/sites/clinic/generate.js.map +1 -0
  34. package/dist/sites/clinic/index.d.ts +3 -0
  35. package/dist/sites/clinic/index.js +3 -0
  36. package/dist/sites/clinic/index.js.map +1 -0
  37. package/dist/sites/clinic/rules.d.ts +96 -0
  38. package/dist/sites/clinic/rules.js +154 -0
  39. package/dist/sites/clinic/rules.js.map +1 -0
  40. package/dist/sites/clinic/types.d.ts +125 -0
  41. package/dist/sites/clinic/types.js +2 -0
  42. package/dist/sites/clinic/types.js.map +1 -0
  43. package/dist/sites/dining/generate.d.ts +15 -0
  44. package/dist/sites/dining/generate.js +146 -0
  45. package/dist/sites/dining/generate.js.map +1 -0
  46. package/dist/sites/dining/index.d.ts +3 -0
  47. package/dist/sites/dining/index.js +4 -0
  48. package/dist/sites/dining/index.js.map +1 -0
  49. package/dist/sites/dining/rules.d.ts +92 -0
  50. package/dist/sites/dining/rules.js +156 -0
  51. package/dist/sites/dining/rules.js.map +1 -0
  52. package/dist/sites/dining/types.d.ts +69 -0
  53. package/dist/sites/dining/types.js +14 -0
  54. package/dist/sites/dining/types.js.map +1 -0
  55. package/dist/sites/events/generate.d.ts +27 -0
  56. package/dist/sites/events/generate.js +197 -0
  57. package/dist/sites/events/generate.js.map +1 -0
  58. package/dist/sites/events/index.d.ts +3 -0
  59. package/dist/sites/events/index.js +4 -0
  60. package/dist/sites/events/index.js.map +1 -0
  61. package/dist/sites/events/rules.d.ts +99 -0
  62. package/dist/sites/events/rules.js +172 -0
  63. package/dist/sites/events/rules.js.map +1 -0
  64. package/dist/sites/events/types.d.ts +78 -0
  65. package/dist/sites/events/types.js +10 -0
  66. package/dist/sites/events/types.js.map +1 -0
  67. package/dist/sites/flights/generate.d.ts +21 -0
  68. package/dist/sites/flights/generate.js +210 -0
  69. package/dist/sites/flights/generate.js.map +1 -0
  70. package/dist/sites/flights/index.d.ts +3 -0
  71. package/dist/sites/flights/index.js +3 -0
  72. package/dist/sites/flights/index.js.map +1 -0
  73. package/dist/sites/flights/rules.d.ts +79 -0
  74. package/dist/sites/flights/rules.js +125 -0
  75. package/dist/sites/flights/rules.js.map +1 -0
  76. package/dist/sites/flights/types.d.ts +69 -0
  77. package/dist/sites/flights/types.js +2 -0
  78. package/dist/sites/flights/types.js.map +1 -0
  79. package/dist/sites/homes/generate.d.ts +19 -0
  80. package/dist/sites/homes/generate.js +180 -0
  81. package/dist/sites/homes/generate.js.map +1 -0
  82. package/dist/sites/homes/index.d.ts +3 -0
  83. package/dist/sites/homes/index.js +3 -0
  84. package/dist/sites/homes/index.js.map +1 -0
  85. package/dist/sites/homes/rules.d.ts +68 -0
  86. package/dist/sites/homes/rules.js +94 -0
  87. package/dist/sites/homes/rules.js.map +1 -0
  88. package/dist/sites/homes/types.d.ts +62 -0
  89. package/dist/sites/homes/types.js +2 -0
  90. package/dist/sites/homes/types.js.map +1 -0
  91. package/dist/sites/hotels/generate.d.ts +16 -0
  92. package/dist/sites/hotels/generate.js +134 -0
  93. package/dist/sites/hotels/generate.js.map +1 -0
  94. package/dist/sites/pizza/catalog.d.ts +34 -0
  95. package/dist/sites/pizza/catalog.js +65 -0
  96. package/dist/sites/pizza/catalog.js.map +1 -0
  97. package/dist/sites/pizza/generate.d.ts +19 -0
  98. package/dist/sites/pizza/generate.js +203 -0
  99. package/dist/sites/pizza/generate.js.map +1 -0
  100. package/dist/sites/pizza/index.d.ts +4 -0
  101. package/dist/sites/pizza/index.js +4 -0
  102. package/dist/sites/pizza/index.js.map +1 -0
  103. package/dist/sites/pizza/rules.d.ts +134 -0
  104. package/dist/sites/pizza/rules.js +217 -0
  105. package/dist/sites/pizza/rules.js.map +1 -0
  106. package/dist/sites/pizza/types.d.ts +114 -0
  107. package/dist/sites/pizza/types.js +2 -0
  108. package/dist/sites/pizza/types.js.map +1 -0
  109. package/dist/sites/rows.d.ts +14 -0
  110. package/dist/sites/rows.js +45 -0
  111. package/dist/sites/rows.js.map +1 -0
  112. package/dist/sites/sports/generate.d.ts +18 -0
  113. package/dist/sites/sports/generate.js +247 -0
  114. package/dist/sites/sports/generate.js.map +1 -0
  115. package/dist/sites/sports/index.d.ts +3 -0
  116. package/dist/sites/sports/index.js +3 -0
  117. package/dist/sites/sports/index.js.map +1 -0
  118. package/dist/sites/sports/rules.d.ts +110 -0
  119. package/dist/sites/sports/rules.js +139 -0
  120. package/dist/sites/sports/rules.js.map +1 -0
  121. package/dist/sites/sports/types.d.ts +91 -0
  122. package/dist/sites/sports/types.js +8 -0
  123. package/dist/sites/sports/types.js.map +1 -0
  124. package/dist/stays.d.ts +63 -0
  125. package/dist/stays.js +96 -0
  126. package/dist/stays.js.map +1 -0
  127. package/dist/web-v1/index.js +2 -0
  128. package/dist/web-v1/index.js.map +1 -1
  129. package/dist/webmcp-v1/index.d.ts +11 -0
  130. package/dist/webmcp-v1/index.js +26 -0
  131. package/dist/webmcp-v1/index.js.map +1 -0
  132. package/package.json +1 -1
@@ -0,0 +1,69 @@
1
+ /**
2
+ * The restaurant reservation site (apps/dining). Restaurants in the cities of
3
+ * CITY_LIST, their seating (tables per area), and reservations already made.
4
+ * A reservation holds one table of its area for two hours from a half-hour
5
+ * seating time. Rules: ./rules.ts.
6
+ */
7
+ /** Seating areas, in the order the site lists them. */
8
+ export declare const DINING_AREAS: readonly ["indoor", "terrace", "bar", "private"];
9
+ export type DiningArea = (typeof DINING_AREAS)[number];
10
+ /** Dietary menus a restaurant may offer besides its regular one. */
11
+ export declare const DINING_MENUS: readonly ["vegetarian", "vegan", "gluten-free"];
12
+ export type DiningMenu = (typeof DINING_MENUS)[number];
13
+ export declare const DINING_CUISINES: readonly ["french", "italian", "japanese", "indian", "mexican", "greek", "thai", "lebanese"];
14
+ /** Monday first, as the site lists opening hours. */
15
+ export declare const DINING_WEEKDAYS: readonly ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"];
16
+ export type DiningWeekday = (typeof DINING_WEEKDAYS)[number];
17
+ /** One day's opening hours, "HH:MM" on the half hour. */
18
+ export type DiningDayHours = {
19
+ opens: string;
20
+ closes: string;
21
+ };
22
+ export type DiningRestaurant = {
23
+ code: string;
24
+ name: string;
25
+ city: string;
26
+ cuisine: string;
27
+ /** 1 (inexpensive) to 4 (expensive); the pages print it as $ to $$$$. */
28
+ priceLevel: number;
29
+ description: string;
30
+ menus: string[];
31
+ /** The one weekday it is closed; `hours[closedDay]` is null. */
32
+ closedDay: DiningWeekday;
33
+ hours: Record<DiningWeekday, DiningDayHours | null>;
34
+ /** Charged per guest when the reservation is made; 0 where no deposit is asked. */
35
+ depositPerGuestCents: number;
36
+ /** A flat fee added to the deposit of a private-room reservation; null where there is no private room. */
37
+ privateRoomFeeCents: number | null;
38
+ };
39
+ /** A restaurant's tables in one area: `tables` tables, each seating up to `seats`. */
40
+ export type DiningSeating = {
41
+ restaurantCode: string;
42
+ area: DiningArea;
43
+ seats: number;
44
+ tables: number;
45
+ };
46
+ export type DiningReservationStatus = "confirmed" | "cancelled";
47
+ export type DiningReservation = {
48
+ reservationNo: string;
49
+ restaurantCode: string;
50
+ area: DiningArea;
51
+ /** "YYYY-MM-DD". */
52
+ date: string;
53
+ /** The seating time, "HH:MM" on the half hour; the table is held for two hours from it. */
54
+ time: string;
55
+ partySize: number;
56
+ guestName: string;
57
+ guestEmail: string;
58
+ guestPhone: string;
59
+ /** The special request, "" when there is none. */
60
+ note: string;
61
+ status: DiningReservationStatus;
62
+ depositCents: number;
63
+ createdAt: string;
64
+ };
65
+ export type DiningRows = {
66
+ restaurants: DiningRestaurant[];
67
+ seating: DiningSeating[];
68
+ reservations: DiningReservation[];
69
+ };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The restaurant reservation site (apps/dining). Restaurants in the cities of
3
+ * CITY_LIST, their seating (tables per area), and reservations already made.
4
+ * A reservation holds one table of its area for two hours from a half-hour
5
+ * seating time. Rules: ./rules.ts.
6
+ */
7
+ /** Seating areas, in the order the site lists them. */
8
+ export const DINING_AREAS = ["indoor", "terrace", "bar", "private"];
9
+ /** Dietary menus a restaurant may offer besides its regular one. */
10
+ export const DINING_MENUS = ["vegetarian", "vegan", "gluten-free"];
11
+ export const DINING_CUISINES = ["french", "italian", "japanese", "indian", "mexican", "greek", "thai", "lebanese"];
12
+ /** Monday first, as the site lists opening hours. */
13
+ export const DINING_WEEKDAYS = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"];
14
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/sites/dining/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,uDAAuD;AACvD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,CAAU,CAAC;AAG7E,oEAAoE;AACpE,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,YAAY,EAAE,OAAO,EAAE,aAAa,CAAU,CAAC;AAG5E,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,CAAU,CAAC;AAE5H,qDAAqD;AACrD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,CAAU,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { type EventRows } from "./types.js";
2
+ /**
3
+ * The office events site's rows: an office in each of the six cities with 4–6
4
+ * meeting rooms, a staff directory, events between March and June 2027, and
5
+ * registrations for the open ones. Drawn from a stream of its own
6
+ * (`substream(seed, "events")`), so adding the site moved no other site's row.
7
+ *
8
+ * Some state is there on purpose: a few rooms are booked from opening to
9
+ * closing on one day, the earliest session of every training course at every
10
+ * office is full, some other open events are full, some events and
11
+ * registrations are cancelled, and most people hold several registrations.
12
+ */
13
+ export declare const EVENT_SIZES: {
14
+ readonly roomsPerOffice: readonly [4, 6];
15
+ readonly people: 36;
16
+ readonly visitors: 14;
17
+ readonly events: 70;
18
+ readonly courses: 4;
19
+ readonly sessionsPerOffice: 3;
20
+ readonly solidDays: 8;
21
+ };
22
+ /** Seeded events fall in this span, so the rest of 2027 is free in every room. */
23
+ export declare const EVENT_BUSY: {
24
+ readonly from: "2027-03-01";
25
+ readonly days: 122;
26
+ };
27
+ export declare function eventRows(seed: number): EventRows;
@@ -0,0 +1,197 @@
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 { eventDraftProblem, eventGuestList, eventMinutes, eventRegisterProblem, eventTimeOf, eventTimeProblem } from "./rules.js";
5
+ import { EVENT_EQUIPMENT } from "./types.js";
6
+ /**
7
+ * The office events site's rows: an office in each of the six cities with 4–6
8
+ * meeting rooms, a staff directory, events between March and June 2027, and
9
+ * registrations for the open ones. Drawn from a stream of its own
10
+ * (`substream(seed, "events")`), so adding the site moved no other site's row.
11
+ *
12
+ * Some state is there on purpose: a few rooms are booked from opening to
13
+ * closing on one day, the earliest session of every training course at every
14
+ * office is full, some other open events are full, some events and
15
+ * registrations are cancelled, and most people hold several registrations.
16
+ */
17
+ export const EVENT_SIZES = { roomsPerOffice: [4, 6], people: 36, visitors: 14, events: 70, courses: 4, sessionsPerOffice: 3, solidDays: 8 };
18
+ /** Seeded events fall in this span, so the rest of 2027 is free in every room. */
19
+ export const EVENT_BUSY = { from: "2027-03-01", days: 122 };
20
+ const CAPACITIES = [4, 6, 8, 10, 12, 16, 20, 30];
21
+ const EQUIPMENT_ODDS = { projector: 0.55, "video conferencing": 0.5, whiteboard: 0.65 };
22
+ const TEAMS = ["Finance", "Sales", "Engineering", "Operations", "Legal", "People", "Design", "Support"];
23
+ const TOPICS = ["Budget", "Roadmap", "Hiring", "Vendor", "Release", "Pricing", "Inventory", "Logistics", "Quality", "Customer"];
24
+ const KINDS = ["review", "planning", "sync", "workshop", "briefing", "retrospective", "check-in", "demo"];
25
+ const PURPOSES = ["Agree the next steps and who owns them.", "Go through the figures for the quarter.", "Collect questions before the deadline.", "Share progress and blockers.", "Decide on the open proposals.", "Walk through the changes and their dates."];
26
+ const COURSES = ["First-aid course", "Fire warden training", "Data privacy basics", "Expense tool walkthrough", "Presentation skills", "Negotiation basics"];
27
+ const WEEKDAYS_ONLY = ["mon", "tue", "wed", "thu", "fri"];
28
+ const stamp = (rng) => new Date(Date.UTC(2027, 0, 2 + int(rng, 0, 50), int(rng, 7, 21), int(rng, 0, 59))).toISOString();
29
+ function makeOffices(rng) {
30
+ return CITY_LIST.map((city) => ({
31
+ code: `OF-${city.slice(0, 3).toUpperCase()}`,
32
+ name: `${city} office`,
33
+ city,
34
+ address: `${int(rng, 2, 180)} ${word(rng)} Street, ${city}`,
35
+ opensAt: pick(rng, ["07:30", "08:00", "08:30", "09:00"]),
36
+ closesAt: pick(rng, ["17:30", "18:00", "18:30", "19:00", "20:00"]),
37
+ openDays: rng() < 0.3 ? [...WEEKDAYS_ONLY, "sat"] : [...WEEKDAYS_ONLY],
38
+ }));
39
+ }
40
+ /** Capacities differ within an office, so "the larger of two rooms" is never a tie. */
41
+ function makeRooms(rng, offices) {
42
+ const names = new Set();
43
+ return offices.flatMap((o) => {
44
+ const caps = shuffle(rng, CAPACITIES).slice(0, int(rng, EVENT_SIZES.roomsPerOffice[0], EVENT_SIZES.roomsPerOffice[1])).sort((a, b) => a - b);
45
+ return caps.map((capacity, i) => {
46
+ let name = "";
47
+ do
48
+ name = `${word(rng, 2)} room`;
49
+ while (names.has(name));
50
+ names.add(name);
51
+ return {
52
+ code: `${o.code.slice(3)}-R${i + 1}`,
53
+ officeCode: o.code,
54
+ name,
55
+ floor: int(rng, 0, 4),
56
+ capacity,
57
+ equipment: EVENT_EQUIPMENT.filter((e) => rng() < EQUIPMENT_ODDS[e]),
58
+ accessible: rng() < 0.6,
59
+ };
60
+ });
61
+ });
62
+ }
63
+ function makePeople(rng, offices) {
64
+ const names = shuffle(rng, FIRST_NAMES.flatMap((f) => LAST_NAMES.map((l) => [f, l])));
65
+ const people = names.slice(0, EVENT_SIZES.people).map(([f, l], i) => ({
66
+ email: `${f}.${l}@staff.example`.toLowerCase(),
67
+ name: `${f} ${l}`,
68
+ officeCode: offices[i % offices.length].code,
69
+ team: pick(rng, TEAMS),
70
+ }));
71
+ const visitors = names.slice(EVENT_SIZES.people, EVENT_SIZES.people + EVENT_SIZES.visitors).map(([f, l]) => ({ name: `${f} ${l}`, email: `${f}.${l}@visitor.example`.toLowerCase() }));
72
+ return { people, visitors };
73
+ }
74
+ export function eventRows(seed) {
75
+ const rng = substream(seed, "events");
76
+ const offices = makeOffices(rng);
77
+ const rooms = makeRooms(rng, offices);
78
+ const { people, visitors } = makePeople(rng, offices);
79
+ const rows = { offices, rooms, people, events: [], registrations: [] };
80
+ const officeOf = new Map(offices.map((o) => [o.code, o]));
81
+ const staffOf = (officeCode) => people.filter((p) => p.officeCode === officeCode);
82
+ const day = () => addDays(EVENT_BUSY.from, int(rng, 0, EVENT_BUSY.days - 1));
83
+ /** Adds the event when the rules take it; returns it, or null when they refuse (a taken room, a closed day). */
84
+ const add = (room, d, status = "scheduled") => {
85
+ const draft = { ...d, roomCode: room.code };
86
+ if (eventDraftProblem(rows, draft))
87
+ return null;
88
+ const event = {
89
+ code: `EV-${1001 + rows.events.length}`,
90
+ title: draft.title,
91
+ description: draft.description,
92
+ date: draft.date,
93
+ startTime: draft.startTime,
94
+ endTime: draft.endTime,
95
+ officeCode: room.officeCode,
96
+ roomCode: room.code,
97
+ organiserEmail: draft.organiserEmail,
98
+ guestEmails: eventGuestList(draft.guestEmails, draft.organiserEmail),
99
+ registration: draft.registration,
100
+ places: draft.places,
101
+ status,
102
+ createdAt: stamp(rng),
103
+ };
104
+ rows.events.push(event);
105
+ return event;
106
+ };
107
+ const guestsFor = (room, organiser, most) => {
108
+ const guests = shuffle(rng, people.filter((p) => p.email !== organiser.email)).slice(0, int(rng, 0, Math.min(most, room.capacity - 1))).map((p) => p.email);
109
+ if (guests.length < room.capacity - 1 && rng() < 0.15)
110
+ guests.push(`${word(rng, 2).toLowerCase()}@partner.example`);
111
+ return guests;
112
+ };
113
+ const slotIn = (office, minutes) => {
114
+ const open = eventMinutes(office.opensAt);
115
+ const start = open + 30 * int(rng, 0, Math.floor((eventMinutes(office.closesAt) - open - minutes) / 30));
116
+ return { startTime: eventTimeOf(start), endTime: eventTimeOf(start + minutes) };
117
+ };
118
+ // Meetings: a room, a day, a slot in the office's hours; some open to registration, a few cancelled.
119
+ for (let i = 0; i < EVENT_SIZES.events; i++) {
120
+ const room = pick(rng, rooms);
121
+ const office = officeOf.get(room.officeCode);
122
+ const organiser = rng() < 0.8 ? pick(rng, staffOf(office.code)) : pick(rng, people);
123
+ const guestEmails = guestsFor(room, organiser, 6);
124
+ const free = room.capacity - 1 - guestEmails.length;
125
+ const open = free >= 2 && rng() < 0.35;
126
+ const title = `${pick(rng, TOPICS)} ${pick(rng, KINDS)}`;
127
+ add(room, { title, description: pick(rng, PURPOSES), date: day(), ...slotIn(office, pick(rng, [30, 45, 60, 90, 120])), organiserEmail: organiser.email, guestEmails, registration: open ? "open" : "invite-only", places: open ? int(rng, 2, Math.min(free, 8)) : null }, rng() < 0.08 ? "cancelled" : "scheduled");
128
+ }
129
+ // Courses: one title, three open sessions at each of two or three offices. The earliest at each office fills up below.
130
+ const earliest = new Set();
131
+ for (const title of shuffle(rng, COURSES).slice(0, EVENT_SIZES.courses)) {
132
+ const trainer = pick(rng, people);
133
+ for (const office of shuffle(rng, offices).slice(0, int(rng, 2, 3))) {
134
+ const sessions = [];
135
+ for (let tries = 0; sessions.length < EVENT_SIZES.sessionsPerOffice && tries < 40; tries++) {
136
+ const places = int(rng, 3, 6);
137
+ const fits = rooms.filter((r) => r.officeCode === office.code && r.capacity >= places + 1);
138
+ if (fits.length === 0)
139
+ break;
140
+ const room = pick(rng, fits);
141
+ const made = add(room, { title, description: `${title}: one of several sessions, register for one.`, date: day(), ...slotIn(office, pick(rng, [60, 90, 120])), organiserEmail: trainer.email, guestEmails: [], registration: "open", places });
142
+ if (made)
143
+ sessions.push(made);
144
+ }
145
+ const first = [...sessions].sort((a, b) => a.date.localeCompare(b.date) || a.startTime.localeCompare(b.startTime))[0];
146
+ if (first)
147
+ earliest.add(first.code);
148
+ }
149
+ }
150
+ // Booked solid on purpose: a room taken by back-to-back meetings from opening to closing on one day.
151
+ for (let i = 0; i < EVENT_SIZES.solidDays; i++) {
152
+ const room = pick(rng, rooms);
153
+ const office = officeOf.get(room.officeCode);
154
+ let date = day();
155
+ while (eventTimeProblem(office, { date, startTime: office.opensAt, endTime: eventTimeOf(eventMinutes(office.opensAt) + 60) }))
156
+ date = addDays(date, 1);
157
+ const close = eventMinutes(office.closesAt);
158
+ for (let t = eventMinutes(office.opensAt); t < close;) {
159
+ const held = rows.events.filter((e) => e.roomCode === room.code && e.date === date && e.status === "scheduled");
160
+ const over = held.find((e) => eventMinutes(e.startTime) <= t && t < eventMinutes(e.endTime));
161
+ if (over) {
162
+ t = eventMinutes(over.endTime);
163
+ continue;
164
+ }
165
+ const next = Math.min(close, ...held.map((e) => eventMinutes(e.startTime)).filter((s) => s > t));
166
+ const length = Math.min(pick(rng, [60, 90, 120]), next - t);
167
+ const organiser = pick(rng, staffOf(office.code));
168
+ const made = add(room, { title: `${pick(rng, TOPICS)} ${pick(rng, KINDS)}`, description: pick(rng, PURPOSES), date, startTime: eventTimeOf(t), endTime: eventTimeOf(t + length), organiserEmail: organiser.email, guestEmails: guestsFor(room, organiser, 4), registration: "invite-only", places: null });
169
+ if (!made)
170
+ break;
171
+ t += length;
172
+ }
173
+ }
174
+ // Registrations, held to the same rule as the site's: places left, no second registration, no overlap.
175
+ const registrants = [...people.map((p) => ({ name: p.name, email: p.email })), ...visitors];
176
+ const register = (event, who, status) => rows.registrations.push({ regNo: `RG-${3001 + rows.registrations.length}`, eventCode: event.code, name: who.name, email: who.email, status, createdAt: stamp(rng) });
177
+ for (const event of rows.events.filter((e) => e.status === "scheduled" && e.registration === "open")) {
178
+ const places = event.places;
179
+ const target = earliest.has(event.code) || rng() < 0.2 ? places : int(rng, 0, places - 1);
180
+ let taken = 0;
181
+ for (const who of shuffle(rng, registrants)) {
182
+ if (taken >= target)
183
+ break;
184
+ if (eventRegisterProblem(rows, event, who))
185
+ continue;
186
+ // A cancelled registration now and then: it holds no place.
187
+ if (rng() < 0.1)
188
+ register(event, who, "cancelled");
189
+ else {
190
+ register(event, who, "registered");
191
+ taken++;
192
+ }
193
+ }
194
+ }
195
+ return rows;
196
+ }
197
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/sites/events/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,iBAAiB,EAAE,cAAc,EAAE,YAAY,EAAE,oBAAoB,EAAE,WAAW,EAAE,gBAAgB,EAAyC,MAAM,YAAY,CAAC;AACzK,OAAO,EAAE,eAAe,EAAgH,MAAM,YAAY,CAAC;AAE3J;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,cAAc,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAW,CAAC;AAErJ,kFAAkF;AAClF,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,GAAG,EAAW,CAAC;AACrE,MAAM,UAAU,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AACjD,MAAM,cAAc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,GAAG,CAAC,EAAE,CAAC,CAAC;IACvK,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,WAAW,IAAI,CAAC,CAAC,YAAY,KAAK,MAAM,CAAC,EAAE,CAAC;QACrG,MAAM,MAAM,GAAG,KAAK,CAAC,MAAgB,CAAC;QACtC,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC;QAC1F,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,EAAE,CAAC;YAC5C,IAAI,KAAK,IAAI,MAAM;gBAAE,MAAM;YAC3B,IAAI,oBAAoB,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC;gBAAE,SAAS;YACrD,4DAA4D;YAC5D,IAAI,GAAG,EAAE,GAAG,GAAG;gBAAE,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;iBAC9C,CAAC;gBACJ,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC;gBACnC,KAAK,EAAE,CAAC;YACV,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { EVENT_BUSY, EVENT_SIZES, eventRows } from "./generate.js";
2
+ export { EVENT_MAX_MINUTES, EVENT_STEP_MINUTES, EVENT_WINDOW, eventCancelProblem, eventChangeProblem, eventDraftProblem, eventFreeRooms, eventGuestList, eventHeadcount, eventMinutes, eventOfficeOf, eventPlacesLeft, eventRegisterProblem, eventRegisteredCount, eventRoomClash, eventTimeOf, eventTimeProblem, eventWeekday, eventsOverlap, isEventEmail, isEventTime, type EventDraft, type EventFreeRoom, type EventProblem, type EventRegistrant, type EventRoomQuery, } from "./rules.js";
3
+ export { EVENT_EQUIPMENT, EVENT_WEEKDAYS, type EventEquipment, type EventOffice, type EventPerson, type EventRegistration, type EventRegistrationMode, type EventRegistrationStatus, type EventRoom, type EventRows, type EventStatus, type EventWeekday, type OfficeEvent, } from "./types.js";
@@ -0,0 +1,4 @@
1
+ export { EVENT_BUSY, EVENT_SIZES, eventRows } from "./generate.js";
2
+ export { EVENT_MAX_MINUTES, EVENT_STEP_MINUTES, EVENT_WINDOW, eventCancelProblem, eventChangeProblem, eventDraftProblem, eventFreeRooms, eventGuestList, eventHeadcount, eventMinutes, eventOfficeOf, eventPlacesLeft, eventRegisterProblem, eventRegisteredCount, eventRoomClash, eventTimeOf, eventTimeProblem, eventWeekday, eventsOverlap, isEventEmail, isEventTime, } from "./rules.js";
3
+ export { EVENT_EQUIPMENT, EVENT_WEEKDAYS, } from "./types.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/sites/events/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,cAAc,EACd,YAAY,EACZ,aAAa,EACb,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,WAAW,GAMZ,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,eAAe,EACf,cAAc,GAYf,MAAM,YAAY,CAAC"}
@@ -0,0 +1,99 @@
1
+ import { type EventOffice, type EventRegistrationMode, type EventRows, type EventWeekday, type OfficeEvent } from "./types.js";
2
+ /**
3
+ * The office events site's rules, as pure functions over rows. apps/events
4
+ * enforces them inside every write's transaction and answers every room
5
+ * search with them, and the intent corpus derives its answer keys with them,
6
+ * so the site and the keys cannot disagree about what is free, what fits or
7
+ * who can register.
8
+ */
9
+ /** The dates events can be held on. Fixed, not "from today", so a seed means the same calendar forever. */
10
+ export declare const EVENT_WINDOW: {
11
+ readonly first: "2027-01-01";
12
+ readonly last: "2027-12-31";
13
+ };
14
+ /** Start and end times fall on the quarter hour. */
15
+ export declare const EVENT_STEP_MINUTES = 15;
16
+ export declare const EVENT_MAX_MINUTES: number;
17
+ export type EventProblem = {
18
+ code: string;
19
+ message: string;
20
+ };
21
+ export type EventDraft = {
22
+ title: string;
23
+ description: string;
24
+ date: string;
25
+ startTime: string;
26
+ endTime: string;
27
+ roomCode: string;
28
+ organiserEmail: string;
29
+ guestEmails: readonly string[];
30
+ registration: EventRegistrationMode;
31
+ places: number | null;
32
+ };
33
+ export type EventRoomQuery = {
34
+ officeCode: string;
35
+ date: string;
36
+ startTime: string;
37
+ endTime: string;
38
+ people: number;
39
+ equipment?: readonly string[];
40
+ accessible?: boolean;
41
+ };
42
+ /** A room that is free for the whole time asked and fits the query. */
43
+ export type EventFreeRoom = {
44
+ roomCode: string;
45
+ roomName: string;
46
+ officeCode: string;
47
+ floor: number;
48
+ capacity: number;
49
+ equipment: string[];
50
+ accessible: boolean;
51
+ };
52
+ export type EventRegistrant = {
53
+ name: string;
54
+ email: string;
55
+ };
56
+ type Slot = {
57
+ date: string;
58
+ startTime: string;
59
+ endTime: string;
60
+ };
61
+ /** "HH:MM", 24-hour, on the quarter hour. */
62
+ export declare function isEventTime(s: string): boolean;
63
+ export declare function isEventEmail(s: string): boolean;
64
+ export declare const eventMinutes: (t: string) => number;
65
+ export declare const eventTimeOf: (minutes: number) => string;
66
+ export declare function eventWeekday(date: string): EventWeekday;
67
+ /** Two slots overlap when they share a date and some minute: back to back (one ends as the other starts) is not an overlap. */
68
+ export declare function eventsOverlap(a: Slot, b: Slot): boolean;
69
+ /** A guest list as the site stores it: trimmed, lowercased, each email once, the organiser left out, sorted. */
70
+ export declare function eventGuestList(emails: readonly string[], organiserEmail: string): string[];
71
+ /** An office by its code or its city, case-insensitive. */
72
+ export declare function eventOfficeOf<O extends EventOffice>(offices: readonly O[], key: string): O | undefined;
73
+ /** The scheduled event holding the room for any part of the slot, other than `exceptCode`. Cancelled events hold nothing. */
74
+ export declare function eventRoomClash(rows: Pick<EventRows, "events">, roomCode: string, slot: Slot, exceptCode?: string): OfficeEvent | null;
75
+ export declare function eventRegisteredCount(rows: Pick<EventRows, "registrations">, eventCode: string): number;
76
+ /** Places still open to registration: the place limit less the active registrations; null for an invitation-only event. */
77
+ export declare function eventPlacesLeft(rows: Pick<EventRows, "registrations">, event: OfficeEvent): number | null;
78
+ /** Why an office cannot hold anything at that time: the date, the window, the times, the length, the open days, the hours. */
79
+ export declare function eventTimeProblem(office: EventOffice, slot: Slot): EventProblem | null;
80
+ /** Everyone the room must hold: the organiser, each invited guest, and every place open to registration. */
81
+ export declare function eventHeadcount(draft: Pick<EventDraft, "guestEmails" | "organiserEmail" | "places">): number;
82
+ /**
83
+ * The rule every new or changed event is held to: a title, a room, a time the
84
+ * office is open, a directory organiser, valid guest emails, places only on an
85
+ * open event, a room that holds everyone, and a room free for the whole time.
86
+ */
87
+ export declare function eventDraftProblem(rows: EventRows, draft: EventDraft, exceptCode?: string): EventProblem | null;
88
+ /** Only the organiser changes an event, a cancelled one never, and never down to fewer places than people registered. */
89
+ export declare function eventChangeProblem(rows: EventRows, event: OfficeEvent, actingEmail: string, next: EventDraft): EventProblem | null;
90
+ export declare function eventCancelProblem(event: OfficeEvent, actingEmail: string): EventProblem | null;
91
+ /**
92
+ * Who can register for an event: it is scheduled and open to registration, the
93
+ * person is not registered for it already, a place is left, and they are not
94
+ * registered for another scheduled event at an overlapping time.
95
+ */
96
+ export declare function eventRegisterProblem(rows: EventRows, event: OfficeEvent, who: EventRegistrant): EventProblem | null;
97
+ /** Rooms in the office that hold the people, have every piece of equipment asked, are step-free when asked, and are free the whole time — smallest first. */
98
+ export declare function eventFreeRooms(rows: EventRows, q: EventRoomQuery): EventFreeRoom[];
99
+ export {};
@@ -0,0 +1,172 @@
1
+ import { isDate } from "../../stays.js";
2
+ import { EVENT_WEEKDAYS } from "./types.js";
3
+ /**
4
+ * The office events site's rules, as pure functions over rows. apps/events
5
+ * enforces them inside every write's transaction and answers every room
6
+ * search with them, and the intent corpus derives its answer keys with them,
7
+ * so the site and the keys cannot disagree about what is free, what fits or
8
+ * who can register.
9
+ */
10
+ /** The dates events can be held on. Fixed, not "from today", so a seed means the same calendar forever. */
11
+ export const EVENT_WINDOW = { first: "2027-01-01", last: "2027-12-31" };
12
+ /** Start and end times fall on the quarter hour. */
13
+ export const EVENT_STEP_MINUTES = 15;
14
+ export const EVENT_MAX_MINUTES = 8 * 60;
15
+ const TIME = /^([01]\d|2[0-3]):([0-5]\d)$/;
16
+ const EMAIL = /^[^\s@]+@[^\s@.]+(\.[^\s@.]+)*\.[A-Za-z]{2,}$/;
17
+ const pad = (n) => String(n).padStart(2, "0");
18
+ /** "HH:MM", 24-hour, on the quarter hour. */
19
+ export function isEventTime(s) {
20
+ return TIME.test(s) && Number(s.slice(3, 5)) % EVENT_STEP_MINUTES === 0;
21
+ }
22
+ export function isEventEmail(s) {
23
+ return EMAIL.test(s.trim());
24
+ }
25
+ export const eventMinutes = (t) => Number(t.slice(0, 2)) * 60 + Number(t.slice(3, 5));
26
+ export const eventTimeOf = (minutes) => `${pad(Math.floor(minutes / 60))}:${pad(minutes % 60)}`;
27
+ export function eventWeekday(date) {
28
+ return EVENT_WEEKDAYS[(new Date(`${date}T00:00:00Z`).getUTCDay() + 6) % 7];
29
+ }
30
+ /** Two slots overlap when they share a date and some minute: back to back (one ends as the other starts) is not an overlap. */
31
+ export function eventsOverlap(a, b) {
32
+ return a.date === b.date && a.startTime < b.endTime && b.startTime < a.endTime;
33
+ }
34
+ /** A guest list as the site stores it: trimmed, lowercased, each email once, the organiser left out, sorted. */
35
+ export function eventGuestList(emails, organiserEmail) {
36
+ const organiser = organiserEmail.trim().toLowerCase();
37
+ return [...new Set(emails.map((e) => e.trim().toLowerCase()).filter((e) => e && e !== organiser))].sort();
38
+ }
39
+ /** An office by its code or its city, case-insensitive. */
40
+ export function eventOfficeOf(offices, key) {
41
+ const k = key.trim().toLowerCase();
42
+ return offices.find((o) => o.code.toLowerCase() === k || o.city.toLowerCase() === k);
43
+ }
44
+ /** The scheduled event holding the room for any part of the slot, other than `exceptCode`. Cancelled events hold nothing. */
45
+ export function eventRoomClash(rows, roomCode, slot, exceptCode) {
46
+ return rows.events.find((e) => e.roomCode === roomCode && e.status === "scheduled" && e.code !== exceptCode && eventsOverlap(e, slot)) ?? null;
47
+ }
48
+ export function eventRegisteredCount(rows, eventCode) {
49
+ return rows.registrations.filter((r) => r.eventCode === eventCode && r.status === "registered").length;
50
+ }
51
+ /** Places still open to registration: the place limit less the active registrations; null for an invitation-only event. */
52
+ export function eventPlacesLeft(rows, event) {
53
+ return event.places === null ? null : Math.max(0, event.places - eventRegisteredCount(rows, event.code));
54
+ }
55
+ /** Why an office cannot hold anything at that time: the date, the window, the times, the length, the open days, the hours. */
56
+ export function eventTimeProblem(office, slot) {
57
+ if (!isDate(slot.date))
58
+ return { code: "BAD_DATE", message: `${slot.date} is not a date (YYYY-MM-DD)` };
59
+ if (slot.date < EVENT_WINDOW.first || slot.date > EVENT_WINDOW.last)
60
+ return { code: "OUTSIDE_WINDOW", message: `events can be held from ${EVENT_WINDOW.first} to ${EVENT_WINDOW.last}` };
61
+ if (!isEventTime(slot.startTime) || !isEventTime(slot.endTime))
62
+ return { code: "BAD_TIME", message: "start and end times are HH:MM (24-hour) on the quarter hour" };
63
+ if (slot.endTime <= slot.startTime)
64
+ return { code: "END_BEFORE_START", message: `an event must end after it starts (${slot.startTime} to ${slot.endTime})` };
65
+ if (eventMinutes(slot.endTime) - eventMinutes(slot.startTime) > EVENT_MAX_MINUTES)
66
+ return { code: "TOO_LONG", message: `an event lasts at most ${EVENT_MAX_MINUTES / 60} hours` };
67
+ if (!office.openDays.includes(eventWeekday(slot.date)))
68
+ return { code: "OFFICE_CLOSED", message: `the ${office.name} is closed on ${slot.date} (open ${office.openDays.join(", ")})` };
69
+ if (slot.startTime < office.opensAt || slot.endTime > office.closesAt)
70
+ return { code: "OUTSIDE_HOURS", message: `the ${office.name} is open from ${office.opensAt} to ${office.closesAt}` };
71
+ return null;
72
+ }
73
+ /** Everyone the room must hold: the organiser, each invited guest, and every place open to registration. */
74
+ export function eventHeadcount(draft) {
75
+ return 1 + eventGuestList(draft.guestEmails, draft.organiserEmail).length + (draft.places ?? 0);
76
+ }
77
+ /**
78
+ * The rule every new or changed event is held to: a title, a room, a time the
79
+ * office is open, a directory organiser, valid guest emails, places only on an
80
+ * open event, a room that holds everyone, and a room free for the whole time.
81
+ */
82
+ export function eventDraftProblem(rows, draft, exceptCode) {
83
+ if (!draft.title.trim())
84
+ return { code: "NO_TITLE", message: "an event needs a title" };
85
+ const room = rows.rooms.find((r) => r.code === draft.roomCode);
86
+ if (!room)
87
+ return { code: "UNKNOWN_ROOM", message: `no room ${draft.roomCode}` };
88
+ const office = rows.offices.find((o) => o.code === room.officeCode);
89
+ const slot = { date: draft.date, startTime: draft.startTime, endTime: draft.endTime };
90
+ const time = eventTimeProblem(office, slot);
91
+ if (time)
92
+ return time;
93
+ const organiser = draft.organiserEmail.trim().toLowerCase();
94
+ if (!rows.people.some((p) => p.email === organiser))
95
+ return { code: "UNKNOWN_ORGANISER", message: `${draft.organiserEmail} is not in the staff directory; only staff can organise an event` };
96
+ const bad = draft.guestEmails.find((e) => !isEventEmail(e));
97
+ if (bad !== undefined)
98
+ return { code: "BAD_GUEST_EMAIL", message: `"${bad}" is not an email address` };
99
+ if (draft.registration === "open" && (draft.places === null || !Number.isInteger(draft.places) || draft.places < 1))
100
+ return { code: "BAD_PLACES", message: "an event open to registration needs at least one place" };
101
+ if (draft.registration === "invite-only" && draft.places !== null)
102
+ return { code: "BAD_PLACES", message: "an invitation-only event has no places to register for" };
103
+ const people = eventHeadcount(draft);
104
+ if (people > room.capacity)
105
+ return { code: "OVER_CAPACITY", message: `${room.name} (${room.code}) holds ${room.capacity} people; this event needs ${people} (the organiser, the guests and the places)` };
106
+ const clash = eventRoomClash(rows, room.code, slot, exceptCode);
107
+ if (clash)
108
+ return { code: "ROOM_TAKEN", message: `${room.name} (${room.code}) is taken from ${clash.startTime} to ${clash.endTime} on ${clash.date} by ${clash.code}` };
109
+ return null;
110
+ }
111
+ /** Only the organiser changes an event, a cancelled one never, and never down to fewer places than people registered. */
112
+ export function eventChangeProblem(rows, event, actingEmail, next) {
113
+ if (event.status === "cancelled")
114
+ return { code: "EVENT_CANCELLED", message: `${event.code} is cancelled` };
115
+ if (actingEmail.trim().toLowerCase() !== event.organiserEmail)
116
+ return { code: "NOT_ORGANISER", message: `only the organiser of ${event.code} can change it` };
117
+ const registered = eventRegisteredCount(rows, event.code);
118
+ if (registered > 0 && (next.registration === "invite-only" || (next.places ?? 0) < registered)) {
119
+ return { code: "PLACES_BELOW_REGISTERED", message: `${registered} people are registered for ${event.code}; it needs at least that many places` };
120
+ }
121
+ return eventDraftProblem(rows, next, event.code);
122
+ }
123
+ export function eventCancelProblem(event, actingEmail) {
124
+ if (event.status === "cancelled")
125
+ return { code: "ALREADY_CANCELLED", message: `${event.code} is already cancelled` };
126
+ if (actingEmail.trim().toLowerCase() !== event.organiserEmail)
127
+ return { code: "NOT_ORGANISER", message: `only the organiser of ${event.code} can cancel it` };
128
+ return null;
129
+ }
130
+ /**
131
+ * Who can register for an event: it is scheduled and open to registration, the
132
+ * person is not registered for it already, a place is left, and they are not
133
+ * registered for another scheduled event at an overlapping time.
134
+ */
135
+ export function eventRegisterProblem(rows, event, who) {
136
+ if (!who.name.trim())
137
+ return { code: "NO_NAME", message: "a registration needs the person's name" };
138
+ if (!isEventEmail(who.email))
139
+ return { code: "BAD_EMAIL", message: `"${who.email}" is not an email address` };
140
+ if (event.status === "cancelled")
141
+ return { code: "EVENT_CANCELLED", message: `${event.code} is cancelled` };
142
+ if (event.registration === "invite-only")
143
+ return { code: "INVITE_ONLY", message: `${event.code} is by invitation only` };
144
+ const email = who.email.trim().toLowerCase();
145
+ const mine = rows.registrations.filter((r) => r.email === email && r.status === "registered");
146
+ if (mine.some((r) => r.eventCode === event.code))
147
+ return { code: "ALREADY_REGISTERED", message: `${email} is already registered for ${event.code}` };
148
+ if ((eventPlacesLeft(rows, event) ?? 0) < 1)
149
+ return { code: "FULL", message: `${event.code} is full: all ${event.places} places are taken` };
150
+ const byCode = new Map(rows.events.map((e) => [e.code, e]));
151
+ for (const r of mine) {
152
+ const other = byCode.get(r.eventCode);
153
+ if (other && other.status === "scheduled" && eventsOverlap(other, event)) {
154
+ return { code: "OVERLAP", message: `${email} is registered for ${other.code} "${other.title}", ${other.date} ${other.startTime}–${other.endTime}, which overlaps` };
155
+ }
156
+ }
157
+ return null;
158
+ }
159
+ /** Rooms in the office that hold the people, have every piece of equipment asked, are step-free when asked, and are free the whole time — smallest first. */
160
+ export function eventFreeRooms(rows, q) {
161
+ const office = rows.offices.find((o) => o.code === q.officeCode);
162
+ const slot = { date: q.date, startTime: q.startTime, endTime: q.endTime };
163
+ if (!office || eventTimeProblem(office, slot))
164
+ return [];
165
+ const wanted = (q.equipment ?? []).map((e) => e.trim().toLowerCase()).filter(Boolean);
166
+ return rows.rooms
167
+ .filter((r) => r.officeCode === office.code && r.capacity >= q.people && wanted.every((e) => r.equipment.includes(e)) && (!q.accessible || r.accessible))
168
+ .filter((r) => !eventRoomClash(rows, r.code, slot))
169
+ .sort((x, y) => x.capacity - y.capacity || x.code.localeCompare(y.code))
170
+ .map((r) => ({ roomCode: r.code, roomName: r.name, officeCode: r.officeCode, floor: r.floor, capacity: r.capacity, equipment: [...r.equipment], accessible: r.accessible }));
171
+ }
172
+ //# sourceMappingURL=rules.js.map