@mark1russell7/market 0.1.8 → 0.1.9

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.
@@ -1,4 +1,5 @@
1
- import { convertible, quantity, valueIn } from "@mark1russell7/quantity";
1
+ import { a as moneyOf, i as moneyAbove, o as monthSchema, r as latestAverages } from "./average-B29bynFb.js";
2
+ import { convertible, quantity, valueIn, whyNotConvertible } from "@mark1russell7/quantity";
2
3
  import { checkSources, checkUnits } from "@mark1russell7/guidebook";
3
4
  // src/supplies.ts
4
5
  /** The format of a catalog of supplies. */
@@ -49,6 +50,7 @@ const SHELF_UNIT = "d";
49
50
  * - An error for an amount with no reason, with two reasons, or with a blank definition. A catalog from JSON can have them.
50
51
  * - An error for a unit that is not a unit of `@mark1russell7/quantity`.
51
52
  * - An error for a unit that does not convert to the unit of its resource.
53
+ * - The amount of the item of an average price has the same checks as each other amount.
52
54
  * - A warning for each value with no read, and for a no read with a blank reason.
53
55
  * - A warning for each fact and each source that no product uses.
54
56
  *
@@ -120,6 +122,7 @@ function checkSupplies(catalog, options = {}) {
120
122
  else amount(product.id, `gift of ${gift.resource}`, gift.amount, resource.unit);
121
123
  }
122
124
  if (product.energy !== void 0) amount(product.id, "food energy", product.energy, ENERGY_UNIT);
125
+ if (product.average !== void 0) amount(product.id, "average price", product.average.read ? product.average.per : product.average, product.average.read ? product.average.per.unit : "");
123
126
  if ("foodKeeper" in product.shelf) {
124
127
  if (!(Number.isSafeInteger(product.shelf.foodKeeper) && product.shelf.foodKeeper > 0)) error("supplies-shelf", "product", product.id, `The FoodKeeper id of the product ${product.id} is ${String(product.shelf.foodKeeper)}. It must be a whole number more than 0.`);
125
128
  } else amount(product.id, "shelf life", product.shelf, SHELF_UNIT);
@@ -174,6 +177,53 @@ function giftsOf(catalog, id, units) {
174
177
  };
175
178
  });
176
179
  }
180
+ /**
181
+ * This function gives the price of one unit of each product with a join to a series, in the order of the catalog.
182
+ * It takes the last month of each series (`latestAverages`). The price is in the money of the average price.
183
+ *
184
+ * - A product with no join is not in the result.
185
+ * - A join with no read, a series with no price, and a unit that does not fit give no read. A no read is not 0.
186
+ * - The unit of the series must convert to the unit of the product, for example USD/lb to 1 kg.
187
+ * - With the option `since`, a last price before that month gives no read. A series that stops then gives no old price.
188
+ *
189
+ * @param catalog - The catalog
190
+ * @param prices - The average prices, from one or more reads
191
+ * @param options - The option `since`: the first month of a price that the result can use, in the form `YYYY-MM`
192
+ * @returns The price of one unit of each product with a join, or no read with the reason
193
+ * @throws RangeError when `since` is not a month in the form `YYYY-MM`
194
+ */
195
+ function averageSupplyPrices(catalog, prices, options = {}) {
196
+ const { since } = options;
197
+ if (since !== void 0 && !monthSchema.safeParse(since).success) throw new RangeError(`The month ${String(since)} is not in the form YYYY-MM.`);
198
+ const last = new Map(latestAverages(prices).map((price) => [`${price.source}:${price.series}`, price]));
199
+ return catalog.products.flatMap((product) => {
200
+ const join = product.average;
201
+ if (join === void 0) return [];
202
+ const none = (why) => [{
203
+ product: product.id,
204
+ read: false,
205
+ why
206
+ }];
207
+ if (!join.read) return none(join.why);
208
+ const average = last.get(`${join.source}:${join.series}`);
209
+ if (average === void 0) return none(`The prices have no average price of the series ${join.series} of ${join.source}.`);
210
+ if (since !== void 0 && average.period < since) return none(`The last average price of the series ${join.series} of ${join.source} is for ${average.period}, before ${since}.`);
211
+ const money = moneyOf(average.price.unit);
212
+ if (money === void 0) return none(`The unit ${average.price.unit} of ${average.id} is not a price for each unit of an amount.`);
213
+ if (!known(join.per.unit)) return none(`The unit ${String(join.per.unit)} of the product ${product.id} is not a known unit.`);
214
+ const unit = `${money}/${join.per.unit}`;
215
+ const why = whyNotConvertible(average.price.unit, unit);
216
+ if (why !== void 0) return none(`The average price ${average.id} is in ${average.price.unit}, and it does not convert to ${unit}: ${why}.`);
217
+ const price = quantity(valueIn(average.price, unit) * join.per.amount, money);
218
+ return [{
219
+ product: product.id,
220
+ read: true,
221
+ price,
222
+ average: average.id,
223
+ period: average.period
224
+ }];
225
+ });
226
+ }
177
227
  // src/supplies-data.ts
178
228
  const CHECKED = "2026-11-22";
179
229
  /** The reference catalog of supplies. A household adds its own products to a copy of it. */
@@ -295,6 +345,17 @@ const SUPPLY_CATALOG = {
295
345
  shelf: {
296
346
  read: true,
297
347
  foodKeeper: 338
348
+ },
349
+ average: {
350
+ read: true,
351
+ source: "bls-ap",
352
+ series: "APU0000701312",
353
+ per: {
354
+ read: true,
355
+ amount: 1,
356
+ unit: "kg",
357
+ definition: "The product is 1 kg of dry white long-grain rice, the item of the series."
358
+ }
298
359
  }
299
360
  },
300
361
  {
@@ -319,6 +380,10 @@ const SUPPLY_CATALOG = {
319
380
  shelf: {
320
381
  read: true,
321
382
  foodKeeper: 375
383
+ },
384
+ average: {
385
+ read: false,
386
+ why: "The known series of average prices have no series of oats yet."
322
387
  }
323
388
  },
324
389
  {
@@ -343,6 +408,154 @@ const SUPPLY_CATALOG = {
343
408
  }
344
409
  ]
345
410
  };
346
- export { SUPPLY_CATALOG, SUPPLY_CODES, SUPPLY_FORMAT, SUPPLY_KINDS, checkSupplies, giftsOf, supplyWants };
411
+ // src/food-plan.ts
412
+ /** This function gives the money of a cost for each unit of time, for example `USD` for `USD/wk`. */
413
+ function moneyOfRate(unit) {
414
+ const money = moneyAbove(unit);
415
+ return money !== void 0 && convertible(unit, `${money}/d`) ? money : void 0;
416
+ }
417
+ /** The age and sex groups of a food plan of USDA. */
418
+ const FOOD_PLAN_GROUPS = [
419
+ "child-1",
420
+ "child-2-3",
421
+ "child-4-5",
422
+ "child-6-8",
423
+ "child-9-11",
424
+ "female-12-13",
425
+ "female-14-19",
426
+ "female-20-50",
427
+ "female-51-70",
428
+ "female-71-up",
429
+ "male-12-13",
430
+ "male-14-19",
431
+ "male-20-50",
432
+ "male-51-70",
433
+ "male-71-up"
434
+ ];
435
+ /**
436
+ * This function gives the cost of a food plan for the members of a household and a count of days. It adds the cost of
437
+ * each person, and then it applies the change for the size of the household.
438
+ *
439
+ * @param plan - The food plan
440
+ * @param members - The groups of the members of the household, each with its count of persons
441
+ * @param days - The count of days, a finite number of 0 or more
442
+ * @throws RangeError when a count of persons is not a whole number of 0 or more, or when the household has no person
443
+ * @throws RangeError when a group is not in the plan, or when the plan has no change for the size of the household
444
+ * @throws RangeError when the count of days is not a finite number of 0 or more
445
+ */
446
+ function foodPlanCost(plan, members, days) {
447
+ if (!(Number.isFinite(days) && days >= 0)) throw new RangeError(`The count of days is ${String(days)}. It must be a finite number of 0 or more.`);
448
+ let persons = 0;
449
+ let money;
450
+ let total = 0;
451
+ for (const member of members) {
452
+ if (!(Number.isSafeInteger(member.count) && member.count >= 0)) throw new RangeError(`The count of the group ${member.group} is ${String(member.count)}. It must be a whole number of 0 or more.`);
453
+ const weekly = plan.weekly[member.group];
454
+ const symbol = weekly === void 0 ? void 0 : moneyOfRate(weekly.unit);
455
+ if (weekly === void 0 || symbol === void 0) throw new RangeError(`The plan ${plan.id} has no cost for each unit of time of the group ${String(member.group)}.`);
456
+ if (money !== void 0 && symbol !== money) throw new RangeError(`The plan ${plan.id} has costs in ${money} and in ${symbol}.`);
457
+ money = symbol;
458
+ persons += member.count;
459
+ total += member.count * valueIn(weekly, `${symbol}/d`) * days;
460
+ }
461
+ if (persons === 0 || money === void 0) throw new RangeError("The household has no person.");
462
+ const size = plan.sizes.find((each) => persons >= each.from && (each.to === void 0 || persons <= each.to));
463
+ if (size === void 0) throw new RangeError(`The plan ${plan.id} has no change for a household of ${String(persons)} persons.`);
464
+ return quantity(total * (1 + size.change), money);
465
+ }
466
+ /**
467
+ * This function compares the cost of the food of a buy list with the cost of a food plan for the same members and
468
+ * days. A list of dry staples costs less than the plan, because the plan is a full diet. A ratio above 1 tells that
469
+ * a price or an amount of the list is possibly wrong. A low ratio is normal, because a list can be any part of a diet.
470
+ * The check of the amount of food is a check of its energy, not of its cost.
471
+ *
472
+ * @param cost - The cost of the food, in a money that converts to the money of the plan
473
+ * @param plan - The food plan
474
+ * @param members - The groups of the members of the household, each with its count of persons
475
+ * @param days - The count of days of the food
476
+ * @throws RangeError for the errors of `foodPlanCost`
477
+ * @throws The error of `valueIn` of `@mark1russell7/quantity` when the money of the cost does not convert to the money of the plan
478
+ */
479
+ function foodPlanCheck(cost, plan, members, days) {
480
+ const planned = foodPlanCost(plan, members, days);
481
+ const value = valueIn(cost, planned.unit);
482
+ const ratio = planned.value === 0 ? value === 0 ? 0 : Number.POSITIVE_INFINITY : value / planned.value;
483
+ return {
484
+ plan: planned,
485
+ cost: quantity(value, planned.unit),
486
+ ratio,
487
+ above: ratio > 1
488
+ };
489
+ }
490
+ // src/food-plan-data.ts
491
+ const week = (value) => ({
492
+ value,
493
+ unit: "USD/wk"
494
+ });
495
+ /** The costs of the food plans of USDA, one record for each plan and month. */
496
+ const FOOD_PLANS = [{
497
+ id: "usda.thrifty:2026-10",
498
+ title: "Official USDA Thrifty Food Plan: U.S. Average, October 2026",
499
+ area: "U.S. average",
500
+ period: "2026-10",
501
+ source: {
502
+ id: "usda.food-plans",
503
+ title: "USDA Food Plans: Monthly Cost of Food Reports",
504
+ url: "https://www.fna.usda.gov/research/cnpp/usda-food-plans/cost-food-monthly-reports",
505
+ license: "us-public-domain",
506
+ checked: "2026-11-22",
507
+ by: "USDA Food and Nutrition Administration"
508
+ },
509
+ locator: "CostofFoodOct2026Thrifty.pdf, the column Weekly Cost of the table of age-sex groups",
510
+ weekly: {
511
+ "child-1": week(26.4),
512
+ "child-2-3": week(39.8),
513
+ "child-4-5": week(43.5),
514
+ "child-6-8": week(48.3),
515
+ "child-9-11": week(55.8),
516
+ "female-12-13": week(51.7),
517
+ "female-14-19": week(60.1),
518
+ "female-20-50": week(58.7),
519
+ "female-51-70": week(54.6),
520
+ "female-71-up": week(60.3),
521
+ "male-12-13": week(59.7),
522
+ "male-14-19": week(75.3),
523
+ "male-20-50": week(73.7),
524
+ "male-51-70": week(65),
525
+ "male-71-up": week(62)
526
+ },
527
+ sizes: [
528
+ {
529
+ from: 1,
530
+ to: 1,
531
+ change: .2
532
+ },
533
+ {
534
+ from: 2,
535
+ to: 2,
536
+ change: .1
537
+ },
538
+ {
539
+ from: 3,
540
+ to: 3,
541
+ change: .05
542
+ },
543
+ {
544
+ from: 4,
545
+ to: 4,
546
+ change: 0
547
+ },
548
+ {
549
+ from: 5,
550
+ to: 6,
551
+ change: -.05
552
+ },
553
+ {
554
+ from: 7,
555
+ change: -.1
556
+ }
557
+ ]
558
+ }];
559
+ export { FOOD_PLANS, FOOD_PLAN_GROUPS, SUPPLY_CATALOG, SUPPLY_CODES, SUPPLY_FORMAT, SUPPLY_KINDS, averageSupplyPrices, checkSupplies, foodPlanCheck, foodPlanCost, giftsOf, supplyWants };
347
560
 
348
561
  //# sourceMappingURL=supplies-entry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"supplies-entry.js","names":[],"sources":["../src/supplies.ts","../src/supplies-data.ts"],"sourcesContent":["import { checkSources, checkUnits, type CitedUnit, type Finding, type FindingCode, type GateOptions, type Source } from \"@mark1russell7/guidebook\";\nimport { convertible, quantity, valueIn } from \"@mark1russell7/quantity\";\nimport type { PartWant } from \"./offers.ts\";\nimport type { ProductWant } from \"./order.ts\";\n\n/*\n * This module is the format and the gate of a catalog of supplies: the products that a household keeps for an\n * emergency, the resource and the amount that one unit gives, and its shelf life. Each value has a cited fact, the\n * definition of the product, or an explicit no read. The facts and their sources are the records of\n * `@mark1russell7/guidebook`, and its gate examines them. The module names no person and no place.\n */\n\n/** The format of a catalog of supplies. */\nexport const SUPPLY_FORMAT = \"supply-catalog/1\";\n\n/** The kinds of the supplies. */\nexport const SUPPLY_KINDS = [\"water\", \"food\", \"power\", \"light\", \"heat\", \"first-aid\", \"communication\"] as const;\n\n/** A kind of a supply. */\nexport type SupplyKind = (typeof SUPPLY_KINDS)[number];\n\n/** A value that no source gives yet. The reason tells what is missing. */\nexport interface NoRead {\n readonly read: false;\n readonly why: string;\n}\n\n/**\n * An amount with its reason. The reason is a cited fact: the `id` of a unit of the catalog with the use `fact`.\n * Or it is the definition of the product, for example the 1 gal of a jug of 1 gal.\n */\nexport type CitedAmount =\n | { readonly read: true; readonly amount: number; readonly unit: string; readonly fact: string; readonly definition?: never }\n | { readonly read: true; readonly amount: number; readonly unit: string; readonly definition: string; readonly fact?: never };\n\n/** A resource that a supply gives, with its unit, for example `water.stored` in `L`. The codes are the resource codes of a store. */\nexport interface SupplyResource {\n readonly code: string;\n readonly unit: string;\n readonly title: string;\n}\n\n/** The gift of one unit of a product: an amount of one resource, or no read. */\nexport interface SupplyGift {\n readonly resource: string;\n readonly amount: CitedAmount | NoRead;\n}\n\n/**\n * The shelf life of a product: a cited amount of time, the `id` of a product of the FoodKeeper data of USDA FSIS, or no read.\n * The entry `/foodkeeper` of `@mark1russell7/stock` gives the due rule of a FoodKeeper product.\n */\nexport type ShelfLife = CitedAmount | { readonly read: true; readonly foodKeeper: number } | NoRead;\n\n/** A product of the catalog. */\nexport interface SupplyProduct {\n readonly id: string;\n readonly title: string;\n readonly kind: SupplyKind;\n /** The part that the offers of a seller must match. A product with no part has no offer, so it has no price. */\n readonly want?: PartWant | undefined;\n /** The resources that one unit gives. */\n readonly gives: readonly SupplyGift[];\n /** The food energy of one unit, in a unit of energy. A cooking converter gives it. */\n readonly energy?: CitedAmount | NoRead | undefined;\n readonly shelf: ShelfLife;\n}\n\n/** A catalog of supplies: the sources, the cited facts, the resources and the products. */\nexport interface SupplyCatalog {\n readonly format: typeof SUPPLY_FORMAT;\n readonly sources: readonly Source[];\n readonly facts: readonly CitedUnit[];\n readonly resources: readonly SupplyResource[];\n readonly products: readonly SupplyProduct[];\n}\n\n/** The codes of the findings of the catalog gate. */\nexport const SUPPLY_CODES = [\n \"supplies-format\",\n \"supplies-twice\",\n \"supplies-kind\",\n \"supplies-resource\",\n \"supplies-fact\",\n \"supplies-amount\",\n \"supplies-unit\",\n \"supplies-shelf\",\n \"supplies-unused\",\n \"supplies-no-read\",\n \"supplies-no-reason\",\n] as const;\n\n/** A code of a finding of the catalog gate. */\nexport type SupplyCode = (typeof SUPPLY_CODES)[number];\n\n/** A finding of the catalog gate, or of the gate of the facts and their sources. */\nexport type SupplyFinding = Finding<SupplyCode | FindingCode, \"source\" | \"unit\" | \"resource\" | \"product\">;\n\n/** This function tells if a text is a unit of `@mark1russell7/quantity`. `convertible` throws for an unknown unit. */\nfunction known(unit: unknown): boolean {\n if (typeof unit !== \"string\") return false;\n try {\n return convertible(unit, unit);\n } catch {\n return false;\n }\n}\n\n/** The unit that each food energy converts to. */\nconst ENERGY_UNIT = \"kcal\";\n/** The unit that each shelf life converts to. */\nconst SHELF_UNIT = \"d\";\n\n/**\n * This function examines a catalog. It gives the findings of the sources and the facts (the gate of\n * `@mark1russell7/guidebook`), and the findings of the products:\n *\n * - An error for a product or a resource two times, a kind that is not a supply kind, and a gift of an unknown resource.\n * - An error for a fact that is not a fact of the catalog, and for an amount that is not more than 0.\n * - An error for an amount with no reason, with two reasons, or with a blank definition. A catalog from JSON can have them.\n * - An error for a unit that is not a unit of `@mark1russell7/quantity`.\n * - An error for a unit that does not convert to the unit of its resource.\n * - A warning for each value with no read, and for a no read with a blank reason.\n * - A warning for each fact and each source that no product uses.\n *\n * The function takes a decoded catalog: each record has the fields of its type. Decode a catalog from JSON first, for\n * example with the entry `/read` of `@mark1russell7/optional`. The gate then finds the values that the type does not hold.\n *\n * @param catalog - The catalog\n * @param options - The options of the gate of the sources, for example the date of the gate\n */\nexport function checkSupplies(catalog: SupplyCatalog, options: GateOptions = {}): SupplyFinding[] {\n const out: SupplyFinding[] = [...checkSources(catalog.sources, options), ...checkUnits(catalog.facts, catalog.sources, options)];\n const error = (code: SupplyCode, record: \"resource\" | \"product\", id: string, message: string): void => {\n out.push({ level: \"error\", code, record, id, message });\n };\n const warning = (code: SupplyCode, record: \"source\" | \"unit\" | \"product\", id: string, message: string): void => {\n out.push({ level: \"warning\", code, record, id, message });\n };\n if (catalog.format !== SUPPLY_FORMAT) error(\"supplies-format\", \"product\", \"\", `The format is ${String(catalog.format)}. It must be ${SUPPLY_FORMAT}.`);\n\n const resources = new Map<string, SupplyResource>();\n for (const resource of catalog.resources) {\n if (resources.has(resource.code)) error(\"supplies-twice\", \"resource\", resource.code, `The resource ${resource.code} is two times in the catalog.`);\n if (!known(resource.unit)) error(\"supplies-unit\", \"resource\", resource.code, `The unit ${String(resource.unit)} of the resource ${resource.code} is not a known unit.`);\n resources.set(resource.code, resource);\n }\n const facts = new Map(catalog.facts.map((fact) => [fact.id, fact]));\n const used = new Set<string>();\n\n /** This function examines one cited amount, and gives the unit check to `units`. */\n const amount = (product: string, what: string, value: CitedAmount | NoRead, unit: string): void => {\n if (!value.read) {\n warning(\"supplies-no-read\", \"product\", product, `The ${what} of the product ${product} is no read: ${String(value.why)}`);\n if (typeof value.why !== \"string\" || value.why.trim() === \"\") warning(\"supplies-no-reason\", \"product\", product, `The no read of the ${what} of the product ${product} has no reason.`);\n return;\n }\n // The type permits one reason only. A catalog from JSON can have no reason, two reasons or a blank definition.\n const reasons = (value.fact === undefined ? 0 : 1) + (value.definition === undefined ? 0 : 1);\n if (reasons !== 1) error(\"supplies-fact\", \"product\", product, `The ${what} of the product ${product} has ${String(reasons)} reasons. It must have a fact or a definition, not the two.`);\n else if (value.definition !== undefined && (typeof value.definition !== \"string\" || value.definition.trim() === \"\")) error(\"supplies-fact\", \"product\", product, `The definition of the ${what} of the product ${product} is blank.`);\n if (value.fact !== undefined) {\n const fact = facts.get(value.fact);\n if (fact === undefined || fact.use !== \"fact\") error(\"supplies-fact\", \"product\", product, `The ${what} of the product ${product} cites ${value.fact}, and the catalog has no fact with that id.`);\n used.add(value.fact);\n }\n if (!(Number.isFinite(value.amount) && value.amount > 0)) error(\"supplies-amount\", \"product\", product, `The ${what} of the product ${product} is ${String(value.amount)}. It must be a finite number more than 0.`);\n if (!known(value.unit)) error(\"supplies-unit\", \"product\", product, `The unit ${String(value.unit)} of the ${what} of the product ${product} is not a known unit.`);\n else if (known(unit) && !convertible(value.unit, unit)) error(\"supplies-unit\", \"product\", product, `The ${what} of the product ${product} is in ${value.unit}, and ${value.unit} does not convert to ${unit}.`);\n };\n\n const products = new Set<string>();\n for (const product of catalog.products) {\n if (products.has(product.id)) error(\"supplies-twice\", \"product\", product.id, `The product ${product.id} is two times in the catalog.`);\n products.add(product.id);\n if (!(SUPPLY_KINDS as readonly string[]).includes(product.kind)) error(\"supplies-kind\", \"product\", product.id, `The kind ${String(product.kind)} of the product ${product.id} is not a supply kind.`);\n const gifts = new Set<string>();\n for (const gift of product.gives) {\n if (gifts.has(gift.resource)) error(\"supplies-twice\", \"product\", product.id, `The product ${product.id} gives the resource ${gift.resource} two times.`);\n gifts.add(gift.resource);\n const resource = resources.get(gift.resource);\n if (resource === undefined) error(\"supplies-resource\", \"product\", product.id, `The product ${product.id} gives the resource ${gift.resource}, and the catalog has no such resource.`);\n else amount(product.id, `gift of ${gift.resource}`, gift.amount, resource.unit);\n }\n if (product.energy !== undefined) amount(product.id, \"food energy\", product.energy, ENERGY_UNIT);\n if (\"foodKeeper\" in product.shelf) {\n if (!(Number.isSafeInteger(product.shelf.foodKeeper) && product.shelf.foodKeeper > 0)) error(\"supplies-shelf\", \"product\", product.id, `The FoodKeeper id of the product ${product.id} is ${String(product.shelf.foodKeeper)}. It must be a whole number more than 0.`);\n } else amount(product.id, \"shelf life\", product.shelf, SHELF_UNIT);\n }\n\n for (const fact of catalog.facts) if (!used.has(fact.id)) warning(\"supplies-unused\", \"unit\", fact.id, `No product uses the fact ${fact.id}.`);\n const cited = new Set(catalog.facts.map((fact) => fact.source));\n for (const source of catalog.sources) if (!cited.has(source.id)) warning(\"supplies-unused\", \"source\", source.id, `No fact cites the source ${source.id}.`);\n return out;\n}\n\n/**\n * This function gives the wants of the products with a part, in the order of the catalog, for `buyCandidates`.\n * A product with no part has no offer, so it is not in the result.\n *\n * @param catalog - The catalog\n * @param max - The largest count of units of a product. The default is 1 for each product\n */\nexport function supplyWants(catalog: SupplyCatalog, max: (product: SupplyProduct) => number = () => 1): ProductWant[] {\n return catalog.products.flatMap((product) => (product.want === undefined ? [] : [{ product: product.id, want: product.want, max: max(product) }]));\n}\n\n/** The gift of a count of units: an amount in the unit of its resource, or no read. */\nexport type GiftOf = { readonly resource: string; readonly read: true; readonly amount: number; readonly unit: string } | { readonly resource: string; readonly read: false; readonly why: string };\n\n/**\n * This function gives the resources of a count of units of a product, each in the unit of its resource.\n * A gift with no read stays no read: it is not 0.\n *\n * @param catalog - The catalog\n * @param id - The `id` of the product\n * @param units - The count of units\n * @throws RangeError when the count of units is not a finite number of 0 or more\n * @throws RangeError when the catalog has no such product, or a gift of an unknown resource\n * @throws The error of `valueIn` of `@mark1russell7/quantity` when the unit of a gift does not convert to the unit of its resource\n */\nexport function giftsOf(catalog: SupplyCatalog, id: string, units: number): GiftOf[] {\n if (!(Number.isFinite(units) && units >= 0)) throw new RangeError(`The count of units is ${String(units)}. It must be a finite number of 0 or more.`);\n const product = catalog.products.find((each) => each.id === id);\n if (product === undefined) throw new RangeError(`The catalog has no product ${id}.`);\n return product.gives.map((gift): GiftOf => {\n const resource = catalog.resources.find((each) => each.code === gift.resource);\n if (resource === undefined) throw new RangeError(`The product ${id} gives the resource ${gift.resource}, and the catalog has no such resource.`);\n if (!gift.amount.read) return { resource: gift.resource, read: false, why: gift.amount.why };\n return { resource: gift.resource, read: true, amount: units * valueIn(quantity(gift.amount.amount, gift.amount.unit), resource.unit), unit: resource.unit };\n });\n}\n","import { SUPPLY_FORMAT, type SupplyCatalog } from \"./supplies.ts\";\n\n// The reference catalog of supplies. Each value has a cited fact, the definition of the product, or a no read.\n// Each fact is in own words, not a quote. The shelf life of a food is a product of the FoodKeeper data of USDA FSIS:\n// the entry `/foodkeeper` of `@mark1russell7/stock` gives its due rule, so this catalog does not copy its times.\n\nconst CHECKED = \"2026-11-22\";\n\n/** The reference catalog of supplies. A household adds its own products to a copy of it. */\nexport const SUPPLY_CATALOG: SupplyCatalog = {\n format: SUPPLY_FORMAT,\n sources: [\n { id: \"ready.water\", title: \"Water\", url: \"https://www.ready.gov/water\", license: \"us-public-domain\", checked: CHECKED, by: \"FEMA (Ready.gov)\" },\n { id: \"fdc.sr-legacy\", title: \"FoodData Central, SR Legacy\", url: \"https://fdc.nal.usda.gov/\", license: \"cc0\", checked: CHECKED, by: \"USDA Agricultural Research Service\" },\n ],\n facts: [\n {\n id: \"ready.water-replace\",\n use: \"fact\",\n text: \"The page tells to replace the stored water that is not commercially bottled each six months.\",\n source: \"ready.water\",\n locator: \"Water storage\",\n },\n {\n id: \"fdc.rice-white\",\n use: \"fact\",\n text: \"The item 168877 (white long-grain rice, raw, enriched) gives 365 kcal in 100 g. Thus 1 kg gives 3650 kcal.\",\n source: \"fdc.sr-legacy\",\n locator: \"FDC ID 168877\",\n },\n {\n id: \"fdc.oats\",\n use: \"fact\",\n text: \"The item 173904 (oats, regular and quick, not fortified, dry) gives 379 kcal in 100 g. Thus 1 kg gives 3790 kcal.\",\n source: \"fdc.sr-legacy\",\n locator: \"FDC ID 173904\",\n },\n ],\n resources: [\n { code: \"water.stored\", unit: \"L\", title: \"Stored drinking water\" },\n { code: \"food.grain-dry\", unit: \"kg\", title: \"Dry grain, to cook with water and fuel\" },\n { code: \"energy.battery\", unit: \"Wh\", title: \"Energy in a battery\" },\n ],\n products: [\n {\n id: \"water.jug-1gal\",\n title: \"Drinking water, commercially bottled, in a jug of 1 gal\",\n kind: \"water\",\n gives: [{ resource: \"water.stored\", amount: { read: true, amount: 1, unit: \"gal\", definition: \"The product is a jug of 1 gal.\" } }],\n shelf: { read: false, why: \"The source tells to keep commercially bottled water sealed, and it gives no time. The date on the label applies.\" },\n },\n {\n id: \"water.container-1gal\",\n title: \"A water container of 1 gal, filled from the tap\",\n kind: \"water\",\n gives: [{ resource: \"water.stored\", amount: { read: true, amount: 1, unit: \"gal\", definition: \"The product is a container of 1 gal.\" } }],\n shelf: { read: true, amount: 6, unit: \"mo\", fact: \"ready.water-replace\" },\n },\n {\n id: \"food.rice-white-1kg\",\n title: \"White long-grain rice, dry, 1 kg\",\n kind: \"food\",\n gives: [{ resource: \"food.grain-dry\", amount: { read: true, amount: 1, unit: \"kg\", definition: \"The product is 1 kg of dry rice.\" } }],\n energy: { read: true, amount: 3650, unit: \"kcal\", fact: \"fdc.rice-white\" },\n shelf: { read: true, foodKeeper: 338 },\n },\n {\n id: \"food.oats-1kg\",\n title: \"Rolled oats, dry, 1 kg\",\n kind: \"food\",\n gives: [{ resource: \"food.grain-dry\", amount: { read: true, amount: 1, unit: \"kg\", definition: \"The product is 1 kg of dry oats.\" } }],\n energy: { read: true, amount: 3790, unit: \"kcal\", fact: \"fdc.oats\" },\n shelf: { read: true, foodKeeper: 375 },\n },\n {\n id: \"power.anker-737\",\n title: \"Anker 737 Power Bank (PowerCore 24K)\",\n kind: \"power\",\n want: { brands: [\"Anker\"], partNumbers: [\"A1289\"] },\n gives: [{ resource: \"energy.battery\", amount: { read: false, why: \"The page of the maker gives 24,000 mAh and no Wh. A charge does not convert to energy without its voltage.\" } }],\n shelf: { read: false, why: \"No source is read yet.\" },\n },\n ],\n};\n"],"mappings":";;;;AAaA,MAAa,gBAAgB;;AAG7B,MAAa,eAAe;CAAC;CAAS;CAAQ;CAAS;CAAS;CAAQ;CAAa;AAAe;;AA8DpG,MAAa,eAAe;CAC1B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AASA,SAAS,MAAM,MAAwB;CACrC,IAAI,OAAO,SAAS,UAAU,OAAO;CACrC,IAAI;EACF,OAAO,YAAY,MAAM,IAAI;CAC/B,QAAQ;EACN,OAAO;CACT;AACF;;AAGA,MAAM,cAAc;;AAEpB,MAAM,aAAa;;;;;;;;;;;;;;;;;;;AAoBnB,SAAgB,cAAc,SAAwB,UAAuB,CAAC,GAAoB;CAChG,MAAM,MAAuB,CAAC,GAAG,aAAa,QAAQ,SAAS,OAAO,GAAG,GAAG,WAAW,QAAQ,OAAO,QAAQ,SAAS,OAAO,CAAC;CAC/H,MAAM,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MAAM;KAAM,QAAQ;KAAG,MAAM;KAAM,YAAY;IAAmC;GAAE,CAAC;GACrI,QAAQ;IAAE,MAAM;IAAM,QAAQ;IAAM,MAAM;IAAQ,MAAM;GAAW;GACnE,OAAO;IAAE,MAAM;IAAM,YAAY;GAAI;EACvC;EACA;GACE,IAAI;GACJ,OAAO;GACP,MAAM;GACN,MAAM;IAAE,QAAQ,CAAC,OAAO;IAAG,aAAa,CAAC,OAAO;GAAE;GAClD,OAAO,CAAC;IAAE,UAAU;IAAkB,QAAQ;KAAE,MAAM;KAAO,KAAK;IAA6G;GAAE,CAAC;GAClL,OAAO;IAAE,MAAM;IAAO,KAAK;GAAyB;EACtD;CACF;AACF"}
1
+ {"version":3,"file":"supplies-entry.js","names":[],"sources":["../src/supplies.ts","../src/supplies-data.ts","../src/food-plan.ts","../src/food-plan-data.ts"],"sourcesContent":["import { checkSources, checkUnits, type CitedUnit, type Finding, type FindingCode, type GateOptions, type Source } from \"@mark1russell7/guidebook\";\nimport { convertible, quantity, valueIn, whyNotConvertible, type Quantity } from \"@mark1russell7/quantity\";\nimport { latestAverages, moneyOf, monthSchema, type AveragePrice } from \"./average.ts\";\nimport type { PartWant } from \"./offers.ts\";\nimport type { ProductWant } from \"./order.ts\";\n\n/*\n * This module is the format and the gate of a catalog of supplies: the products that a household keeps for an\n * emergency, the resource and the amount that one unit gives, and its shelf life. Each value has a cited fact, the\n * definition of the product, or an explicit no read. The facts and their sources are the records of\n * `@mark1russell7/guidebook`, and its gate examines them. The module names no person and no place.\n */\n\n/** The format of a catalog of supplies. */\nexport const SUPPLY_FORMAT = \"supply-catalog/1\";\n\n/** The kinds of the supplies. */\nexport const SUPPLY_KINDS = [\"water\", \"food\", \"power\", \"light\", \"heat\", \"first-aid\", \"communication\"] as const;\n\n/** A kind of a supply. */\nexport type SupplyKind = (typeof SUPPLY_KINDS)[number];\n\n/** A value that no source gives yet. The reason tells what is missing. */\nexport interface NoRead {\n readonly read: false;\n readonly why: string;\n}\n\n/**\n * An amount with its reason. The reason is a cited fact: the `id` of a unit of the catalog with the use `fact`.\n * Or it is the definition of the product, for example the 1 gal of a jug of 1 gal.\n */\nexport type CitedAmount =\n | { readonly read: true; readonly amount: number; readonly unit: string; readonly fact: string; readonly definition?: never }\n | { readonly read: true; readonly amount: number; readonly unit: string; readonly definition: string; readonly fact?: never };\n\n/** A resource that a supply gives, with its unit, for example `water.stored` in `L`. The codes are the resource codes of a store. */\nexport interface SupplyResource {\n readonly code: string;\n readonly unit: string;\n readonly title: string;\n}\n\n/** The gift of one unit of a product: an amount of one resource, or no read. */\nexport interface SupplyGift {\n readonly resource: string;\n readonly amount: CitedAmount | NoRead;\n}\n\n/**\n * The shelf life of a product: a cited amount of time, the `id` of a product of the FoodKeeper data of USDA FSIS, or no read.\n * The entry `/foodkeeper` of `@mark1russell7/stock` gives the due rule of a FoodKeeper product.\n */\nexport type ShelfLife = CitedAmount | { readonly read: true; readonly foodKeeper: number } | NoRead;\n\n/**\n * The join of a product to a series of average prices. It names the source and the series. It also gives the amount\n * of the item of the series in one unit of the product. For example, 1 kg of dry rice is the amount of a series of\n * rice in USD/lb.\n */\nexport interface AverageJoin {\n readonly read: true;\n /** The source of the average prices, for example `bls-ap`. */\n readonly source: string;\n /** The id of the series in the source, for example `APU0000701312`. */\n readonly series: string;\n /** The amount of the item of the series in one unit of the product, with its reason. */\n readonly per: CitedAmount;\n}\n\n/** A product of the catalog. */\nexport interface SupplyProduct {\n readonly id: string;\n readonly title: string;\n readonly kind: SupplyKind;\n /** The part that the offers of a seller must match. A product with no part has no offer, so it has no price. */\n readonly want?: PartWant | undefined;\n /** The resources that one unit gives. */\n readonly gives: readonly SupplyGift[];\n /** The food energy of one unit, in a unit of energy. A cooking converter gives it. */\n readonly energy?: CitedAmount | NoRead | undefined;\n readonly shelf: ShelfLife;\n /**\n * The series of average prices that gives the price of one unit, or no read with the reason. A product with no join\n * and no part has no price.\n */\n readonly average?: AverageJoin | NoRead | undefined;\n}\n\n/** A catalog of supplies: the sources, the cited facts, the resources and the products. */\nexport interface SupplyCatalog {\n readonly format: typeof SUPPLY_FORMAT;\n readonly sources: readonly Source[];\n readonly facts: readonly CitedUnit[];\n readonly resources: readonly SupplyResource[];\n readonly products: readonly SupplyProduct[];\n}\n\n/** The codes of the findings of the catalog gate. */\nexport const SUPPLY_CODES = [\n \"supplies-format\",\n \"supplies-twice\",\n \"supplies-kind\",\n \"supplies-resource\",\n \"supplies-fact\",\n \"supplies-amount\",\n \"supplies-unit\",\n \"supplies-shelf\",\n \"supplies-unused\",\n \"supplies-no-read\",\n \"supplies-no-reason\",\n] as const;\n\n/** A code of a finding of the catalog gate. */\nexport type SupplyCode = (typeof SUPPLY_CODES)[number];\n\n/** A finding of the catalog gate, or of the gate of the facts and their sources. */\nexport type SupplyFinding = Finding<SupplyCode | FindingCode, \"source\" | \"unit\" | \"resource\" | \"product\">;\n\n/** This function tells if a text is a unit of `@mark1russell7/quantity`. `convertible` throws for an unknown unit. */\nfunction known(unit: unknown): boolean {\n if (typeof unit !== \"string\") return false;\n try {\n return convertible(unit, unit);\n } catch {\n return false;\n }\n}\n\n/** The unit that each food energy converts to. */\nconst ENERGY_UNIT = \"kcal\";\n/** The unit that each shelf life converts to. */\nconst SHELF_UNIT = \"d\";\n\n/**\n * This function examines a catalog. It gives the findings of the sources and the facts (the gate of\n * `@mark1russell7/guidebook`), and the findings of the products:\n *\n * - An error for a product or a resource two times, a kind that is not a supply kind, and a gift of an unknown resource.\n * - An error for a fact that is not a fact of the catalog, and for an amount that is not more than 0.\n * - An error for an amount with no reason, with two reasons, or with a blank definition. A catalog from JSON can have them.\n * - An error for a unit that is not a unit of `@mark1russell7/quantity`.\n * - An error for a unit that does not convert to the unit of its resource.\n * - The amount of the item of an average price has the same checks as each other amount.\n * - A warning for each value with no read, and for a no read with a blank reason.\n * - A warning for each fact and each source that no product uses.\n *\n * The function takes a decoded catalog: each record has the fields of its type. Decode a catalog from JSON first, for\n * example with the entry `/read` of `@mark1russell7/optional`. The gate then finds the values that the type does not hold.\n *\n * @param catalog - The catalog\n * @param options - The options of the gate of the sources, for example the date of the gate\n */\nexport function checkSupplies(catalog: SupplyCatalog, options: GateOptions = {}): SupplyFinding[] {\n const out: SupplyFinding[] = [...checkSources(catalog.sources, options), ...checkUnits(catalog.facts, catalog.sources, options)];\n const error = (code: SupplyCode, record: \"resource\" | \"product\", id: string, message: string): void => {\n out.push({ level: \"error\", code, record, id, message });\n };\n const warning = (code: SupplyCode, record: \"source\" | \"unit\" | \"product\", id: string, message: string): void => {\n out.push({ level: \"warning\", code, record, id, message });\n };\n if (catalog.format !== SUPPLY_FORMAT) error(\"supplies-format\", \"product\", \"\", `The format is ${String(catalog.format)}. It must be ${SUPPLY_FORMAT}.`);\n\n const resources = new Map<string, SupplyResource>();\n for (const resource of catalog.resources) {\n if (resources.has(resource.code)) error(\"supplies-twice\", \"resource\", resource.code, `The resource ${resource.code} is two times in the catalog.`);\n if (!known(resource.unit)) error(\"supplies-unit\", \"resource\", resource.code, `The unit ${String(resource.unit)} of the resource ${resource.code} is not a known unit.`);\n resources.set(resource.code, resource);\n }\n const facts = new Map(catalog.facts.map((fact) => [fact.id, fact]));\n const used = new Set<string>();\n\n /** This function examines one cited amount, and gives the unit check to `units`. */\n const amount = (product: string, what: string, value: CitedAmount | NoRead, unit: string): void => {\n if (!value.read) {\n warning(\"supplies-no-read\", \"product\", product, `The ${what} of the product ${product} is no read: ${String(value.why)}`);\n if (typeof value.why !== \"string\" || value.why.trim() === \"\") warning(\"supplies-no-reason\", \"product\", product, `The no read of the ${what} of the product ${product} has no reason.`);\n return;\n }\n // The type permits one reason only. A catalog from JSON can have no reason, two reasons or a blank definition.\n const reasons = (value.fact === undefined ? 0 : 1) + (value.definition === undefined ? 0 : 1);\n if (reasons !== 1) error(\"supplies-fact\", \"product\", product, `The ${what} of the product ${product} has ${String(reasons)} reasons. It must have a fact or a definition, not the two.`);\n else if (value.definition !== undefined && (typeof value.definition !== \"string\" || value.definition.trim() === \"\")) error(\"supplies-fact\", \"product\", product, `The definition of the ${what} of the product ${product} is blank.`);\n if (value.fact !== undefined) {\n const fact = facts.get(value.fact);\n if (fact === undefined || fact.use !== \"fact\") error(\"supplies-fact\", \"product\", product, `The ${what} of the product ${product} cites ${value.fact}, and the catalog has no fact with that id.`);\n used.add(value.fact);\n }\n if (!(Number.isFinite(value.amount) && value.amount > 0)) error(\"supplies-amount\", \"product\", product, `The ${what} of the product ${product} is ${String(value.amount)}. It must be a finite number more than 0.`);\n if (!known(value.unit)) error(\"supplies-unit\", \"product\", product, `The unit ${String(value.unit)} of the ${what} of the product ${product} is not a known unit.`);\n else if (known(unit) && !convertible(value.unit, unit)) error(\"supplies-unit\", \"product\", product, `The ${what} of the product ${product} is in ${value.unit}, and ${value.unit} does not convert to ${unit}.`);\n };\n\n const products = new Set<string>();\n for (const product of catalog.products) {\n if (products.has(product.id)) error(\"supplies-twice\", \"product\", product.id, `The product ${product.id} is two times in the catalog.`);\n products.add(product.id);\n if (!(SUPPLY_KINDS as readonly string[]).includes(product.kind)) error(\"supplies-kind\", \"product\", product.id, `The kind ${String(product.kind)} of the product ${product.id} is not a supply kind.`);\n const gifts = new Set<string>();\n for (const gift of product.gives) {\n if (gifts.has(gift.resource)) error(\"supplies-twice\", \"product\", product.id, `The product ${product.id} gives the resource ${gift.resource} two times.`);\n gifts.add(gift.resource);\n const resource = resources.get(gift.resource);\n if (resource === undefined) error(\"supplies-resource\", \"product\", product.id, `The product ${product.id} gives the resource ${gift.resource}, and the catalog has no such resource.`);\n else amount(product.id, `gift of ${gift.resource}`, gift.amount, resource.unit);\n }\n if (product.energy !== undefined) amount(product.id, \"food energy\", product.energy, ENERGY_UNIT);\n if (product.average !== undefined) amount(product.id, \"average price\", product.average.read ? product.average.per : product.average, product.average.read ? product.average.per.unit : \"\");\n if (\"foodKeeper\" in product.shelf) {\n if (!(Number.isSafeInteger(product.shelf.foodKeeper) && product.shelf.foodKeeper > 0)) error(\"supplies-shelf\", \"product\", product.id, `The FoodKeeper id of the product ${product.id} is ${String(product.shelf.foodKeeper)}. It must be a whole number more than 0.`);\n } else amount(product.id, \"shelf life\", product.shelf, SHELF_UNIT);\n }\n\n for (const fact of catalog.facts) if (!used.has(fact.id)) warning(\"supplies-unused\", \"unit\", fact.id, `No product uses the fact ${fact.id}.`);\n const cited = new Set(catalog.facts.map((fact) => fact.source));\n for (const source of catalog.sources) if (!cited.has(source.id)) warning(\"supplies-unused\", \"source\", source.id, `No fact cites the source ${source.id}.`);\n return out;\n}\n\n/**\n * This function gives the wants of the products with a part, in the order of the catalog, for `buyCandidates`.\n * A product with no part has no offer, so it is not in the result.\n *\n * @param catalog - The catalog\n * @param max - The largest count of units of a product. The default is 1 for each product\n */\nexport function supplyWants(catalog: SupplyCatalog, max: (product: SupplyProduct) => number = () => 1): ProductWant[] {\n return catalog.products.flatMap((product) => (product.want === undefined ? [] : [{ product: product.id, want: product.want, max: max(product) }]));\n}\n\n/** The gift of a count of units: an amount in the unit of its resource, or no read. */\nexport type GiftOf = { readonly resource: string; readonly read: true; readonly amount: number; readonly unit: string } | { readonly resource: string; readonly read: false; readonly why: string };\n\n/**\n * This function gives the resources of a count of units of a product, each in the unit of its resource.\n * A gift with no read stays no read: it is not 0.\n *\n * @param catalog - The catalog\n * @param id - The `id` of the product\n * @param units - The count of units\n * @throws RangeError when the count of units is not a finite number of 0 or more\n * @throws RangeError when the catalog has no such product, or a gift of an unknown resource\n * @throws The error of `valueIn` of `@mark1russell7/quantity` when the unit of a gift does not convert to the unit of its resource\n */\nexport function giftsOf(catalog: SupplyCatalog, id: string, units: number): GiftOf[] {\n if (!(Number.isFinite(units) && units >= 0)) throw new RangeError(`The count of units is ${String(units)}. It must be a finite number of 0 or more.`);\n const product = catalog.products.find((each) => each.id === id);\n if (product === undefined) throw new RangeError(`The catalog has no product ${id}.`);\n return product.gives.map((gift): GiftOf => {\n const resource = catalog.resources.find((each) => each.code === gift.resource);\n if (resource === undefined) throw new RangeError(`The product ${id} gives the resource ${gift.resource}, and the catalog has no such resource.`);\n if (!gift.amount.read) return { resource: gift.resource, read: false, why: gift.amount.why };\n return { resource: gift.resource, read: true, amount: units * valueIn(quantity(gift.amount.amount, gift.amount.unit), resource.unit), unit: resource.unit };\n });\n}\n\n/** The price of one unit of a product from an average price, or no read with the reason. */\nexport type SupplyPrice =\n | { readonly product: string; readonly read: true; readonly price: Quantity; readonly average: string; readonly period: string }\n | { readonly product: string; readonly read: false; readonly why: string };\n\n/**\n * This function gives the price of one unit of each product with a join to a series, in the order of the catalog.\n * It takes the last month of each series (`latestAverages`). The price is in the money of the average price.\n *\n * - A product with no join is not in the result.\n * - A join with no read, a series with no price, and a unit that does not fit give no read. A no read is not 0.\n * - The unit of the series must convert to the unit of the product, for example USD/lb to 1 kg.\n * - With the option `since`, a last price before that month gives no read. A series that stops then gives no old price.\n *\n * @param catalog - The catalog\n * @param prices - The average prices, from one or more reads\n * @param options - The option `since`: the first month of a price that the result can use, in the form `YYYY-MM`\n * @returns The price of one unit of each product with a join, or no read with the reason\n * @throws RangeError when `since` is not a month in the form `YYYY-MM`\n */\nexport function averageSupplyPrices(catalog: SupplyCatalog, prices: readonly AveragePrice[], options: { readonly since?: string | undefined } = {}): SupplyPrice[] {\n const { since } = options;\n if (since !== undefined && !monthSchema.safeParse(since).success) throw new RangeError(`The month ${String(since)} is not in the form YYYY-MM.`);\n const last = new Map(latestAverages(prices).map((price) => [`${price.source}:${price.series}`, price]));\n return catalog.products.flatMap((product): SupplyPrice[] => {\n const join = product.average;\n if (join === undefined) return [];\n const none = (why: string): SupplyPrice[] => [{ product: product.id, read: false, why }];\n if (!join.read) return none(join.why);\n const average = last.get(`${join.source}:${join.series}`);\n if (average === undefined) return none(`The prices have no average price of the series ${join.series} of ${join.source}.`);\n if (since !== undefined && average.period < since) return none(`The last average price of the series ${join.series} of ${join.source} is for ${average.period}, before ${since}.`);\n const money = moneyOf(average.price.unit);\n if (money === undefined) return none(`The unit ${average.price.unit} of ${average.id} is not a price for each unit of an amount.`);\n if (!known(join.per.unit)) return none(`The unit ${String(join.per.unit)} of the product ${product.id} is not a known unit.`);\n const unit = `${money}/${join.per.unit}`;\n const why = whyNotConvertible(average.price.unit, unit);\n if (why !== undefined) return none(`The average price ${average.id} is in ${average.price.unit}, and it does not convert to ${unit}: ${why}.`);\n const price = quantity(valueIn(average.price, unit) * join.per.amount, money);\n return [{ product: product.id, read: true, price, average: average.id, period: average.period }];\n });\n}\n","import { SUPPLY_FORMAT, type SupplyCatalog } from \"./supplies.ts\";\n\n// The reference catalog of supplies. Each value has a cited fact, the definition of the product, or a no read.\n// Each fact is in own words, not a quote. The shelf life of a food is a product of the FoodKeeper data of USDA FSIS:\n// the entry `/foodkeeper` of `@mark1russell7/stock` gives its due rule, so this catalog does not copy its times.\n\nconst CHECKED = \"2026-11-22\";\n\n/** The reference catalog of supplies. A household adds its own products to a copy of it. */\nexport const SUPPLY_CATALOG: SupplyCatalog = {\n format: SUPPLY_FORMAT,\n sources: [\n { id: \"ready.water\", title: \"Water\", url: \"https://www.ready.gov/water\", license: \"us-public-domain\", checked: CHECKED, by: \"FEMA (Ready.gov)\" },\n { id: \"fdc.sr-legacy\", title: \"FoodData Central, SR Legacy\", url: \"https://fdc.nal.usda.gov/\", license: \"cc0\", checked: CHECKED, by: \"USDA Agricultural Research Service\" },\n ],\n facts: [\n {\n id: \"ready.water-replace\",\n use: \"fact\",\n text: \"The page tells to replace the stored water that is not commercially bottled each six months.\",\n source: \"ready.water\",\n locator: \"Water storage\",\n },\n {\n id: \"fdc.rice-white\",\n use: \"fact\",\n text: \"The item 168877 (white long-grain rice, raw, enriched) gives 365 kcal in 100 g. Thus 1 kg gives 3650 kcal.\",\n source: \"fdc.sr-legacy\",\n locator: \"FDC ID 168877\",\n },\n {\n id: \"fdc.oats\",\n use: \"fact\",\n text: \"The item 173904 (oats, regular and quick, not fortified, dry) gives 379 kcal in 100 g. Thus 1 kg gives 3790 kcal.\",\n source: \"fdc.sr-legacy\",\n locator: \"FDC ID 173904\",\n },\n ],\n resources: [\n { code: \"water.stored\", unit: \"L\", title: \"Stored drinking water\" },\n { code: \"food.grain-dry\", unit: \"kg\", title: \"Dry grain, to cook with water and fuel\" },\n { code: \"energy.battery\", unit: \"Wh\", title: \"Energy in a battery\" },\n ],\n products: [\n {\n id: \"water.jug-1gal\",\n title: \"Drinking water, commercially bottled, in a jug of 1 gal\",\n kind: \"water\",\n gives: [{ resource: \"water.stored\", amount: { read: true, amount: 1, unit: \"gal\", definition: \"The product is a jug of 1 gal.\" } }],\n shelf: { read: false, why: \"The source tells to keep commercially bottled water sealed, and it gives no time. The date on the label applies.\" },\n },\n {\n id: \"water.container-1gal\",\n title: \"A water container of 1 gal, filled from the tap\",\n kind: \"water\",\n gives: [{ resource: \"water.stored\", amount: { read: true, amount: 1, unit: \"gal\", definition: \"The product is a container of 1 gal.\" } }],\n shelf: { read: true, amount: 6, unit: \"mo\", fact: \"ready.water-replace\" },\n },\n {\n id: \"food.rice-white-1kg\",\n title: \"White long-grain rice, dry, 1 kg\",\n kind: \"food\",\n gives: [{ resource: \"food.grain-dry\", amount: { read: true, amount: 1, unit: \"kg\", definition: \"The product is 1 kg of dry rice.\" } }],\n energy: { read: true, amount: 3650, unit: \"kcal\", fact: \"fdc.rice-white\" },\n shelf: { read: true, foodKeeper: 338 },\n average: {\n read: true,\n source: \"bls-ap\",\n series: \"APU0000701312\",\n per: { read: true, amount: 1, unit: \"kg\", definition: \"The product is 1 kg of dry white long-grain rice, the item of the series.\" },\n },\n },\n {\n id: \"food.oats-1kg\",\n title: \"Rolled oats, dry, 1 kg\",\n kind: \"food\",\n gives: [{ resource: \"food.grain-dry\", amount: { read: true, amount: 1, unit: \"kg\", definition: \"The product is 1 kg of dry oats.\" } }],\n energy: { read: true, amount: 3790, unit: \"kcal\", fact: \"fdc.oats\" },\n shelf: { read: true, foodKeeper: 375 },\n average: { read: false, why: \"The known series of average prices have no series of oats yet.\" },\n },\n {\n id: \"power.anker-737\",\n title: \"Anker 737 Power Bank (PowerCore 24K)\",\n kind: \"power\",\n want: { brands: [\"Anker\"], partNumbers: [\"A1289\"] },\n gives: [{ resource: \"energy.battery\", amount: { read: false, why: \"The page of the maker gives 24,000 mAh and no Wh. A charge does not convert to energy without its voltage.\" } }],\n shelf: { read: false, why: \"No source is read yet.\" },\n },\n ],\n};\n","import type { Source } from \"@mark1russell7/guidebook\";\nimport { convertible, quantity, valueIn, type Quantity } from \"@mark1russell7/quantity\";\nimport { moneyAbove } from \"./average.ts\";\n\n/** This function gives the money of a cost for each unit of time, for example `USD` for `USD/wk`. */\nfunction moneyOfRate(unit: string): string | undefined {\n const money = moneyAbove(unit);\n return money !== undefined && convertible(unit, `${money}/d`) ? money : undefined;\n}\n\n/*\n * This module has the cost of a food plan: the cost of the food of one week for one person of each age and sex, from\n * an official source. A check compares the food of a buy list with the cost of the plan for the same people and days.\n * The module names no person. The members of a household are input data.\n */\n\n/** The age and sex groups of a food plan of USDA. */\nexport const FOOD_PLAN_GROUPS = [\n \"child-1\",\n \"child-2-3\",\n \"child-4-5\",\n \"child-6-8\",\n \"child-9-11\",\n \"female-12-13\",\n \"female-14-19\",\n \"female-20-50\",\n \"female-51-70\",\n \"female-71-up\",\n \"male-12-13\",\n \"male-14-19\",\n \"male-20-50\",\n \"male-51-70\",\n \"male-71-up\",\n] as const;\n\n/** An age and sex group of a food plan. */\nexport type FoodPlanGroup = (typeof FOOD_PLAN_GROUPS)[number];\n\n/** The change of the cost for a size of household, for example 0.2 for one person. */\nexport interface FoodPlanSize {\n /** The smallest count of persons. */\n readonly from: number;\n /** The largest count of persons. Without it, the change applies to each larger household. */\n readonly to?: number | undefined;\n /** The change of the cost, as a fraction: 0.2 adds 20 percent, and -0.05 subtracts 5 percent. */\n readonly change: number;\n}\n\n/** The cost of a food plan in one area and one month, from one source. */\nexport interface FoodPlan {\n /** The id, for example `usda.thrifty:2026-10`. */\n readonly id: string;\n readonly title: string;\n /** The area, as the source names it, for example `U.S. average`. */\n readonly area: string;\n /** The month of the costs, in the form `YYYY-MM`. */\n readonly period: string;\n readonly source: Source;\n /** The place of the table in the source. */\n readonly locator: string;\n /** The cost of the food of one week for one person of each group, for example `{ \"value\": 58.7, \"unit\": \"USD/wk\" }`. */\n readonly weekly: Readonly<Record<FoodPlanGroup, Quantity>>;\n /** The change of the cost for each size of household. The costs of `weekly` are for the size with the change 0. */\n readonly sizes: readonly FoodPlanSize[];\n}\n\n/** A group of the members of a household, and the count of its persons. */\nexport interface FoodPlanMember {\n readonly group: FoodPlanGroup;\n readonly count: number;\n}\n\n/** The result of a check of the cost of food against a food plan. */\nexport interface FoodPlanCheck {\n /** The cost of the plan for the same members and days. */\n readonly plan: Quantity;\n /** The cost of the food, in the money of the plan. */\n readonly cost: Quantity;\n /** The cost of the food divided by the cost of the plan. */\n readonly ratio: number;\n /**\n * True when the food costs more than the plan. The Thrifty plan is the lowest of the four plans of USDA. Thus a list\n * above the cost of the Thrifty plan is not wrong when it has foods that cost more than staples.\n */\n readonly above: boolean;\n}\n\n/**\n * This function gives the cost of a food plan for the members of a household and a count of days. It adds the cost of\n * each person, and then it applies the change for the size of the household.\n *\n * @param plan - The food plan\n * @param members - The groups of the members of the household, each with its count of persons\n * @param days - The count of days, a finite number of 0 or more\n * @throws RangeError when a count of persons is not a whole number of 0 or more, or when the household has no person\n * @throws RangeError when a group is not in the plan, or when the plan has no change for the size of the household\n * @throws RangeError when the count of days is not a finite number of 0 or more\n */\nexport function foodPlanCost(plan: FoodPlan, members: readonly FoodPlanMember[], days: number): Quantity {\n if (!(Number.isFinite(days) && days >= 0)) throw new RangeError(`The count of days is ${String(days)}. It must be a finite number of 0 or more.`);\n let persons = 0;\n let money: string | undefined;\n let total = 0;\n for (const member of members) {\n if (!(Number.isSafeInteger(member.count) && member.count >= 0)) throw new RangeError(`The count of the group ${member.group} is ${String(member.count)}. It must be a whole number of 0 or more.`);\n const weekly = plan.weekly[member.group] as Quantity | undefined;\n const symbol = weekly === undefined ? undefined : moneyOfRate(weekly.unit);\n if (weekly === undefined || symbol === undefined) throw new RangeError(`The plan ${plan.id} has no cost for each unit of time of the group ${String(member.group)}.`);\n if (money !== undefined && symbol !== money) throw new RangeError(`The plan ${plan.id} has costs in ${money} and in ${symbol}.`);\n money = symbol;\n persons += member.count;\n total += member.count * valueIn(weekly, `${symbol}/d`) * days;\n }\n if (persons === 0 || money === undefined) throw new RangeError(\"The household has no person.\");\n const size = plan.sizes.find((each) => persons >= each.from && (each.to === undefined || persons <= each.to));\n if (size === undefined) throw new RangeError(`The plan ${plan.id} has no change for a household of ${String(persons)} persons.`);\n return quantity(total * (1 + size.change), money);\n}\n\n/**\n * This function compares the cost of the food of a buy list with the cost of a food plan for the same members and\n * days. A list of dry staples costs less than the plan, because the plan is a full diet. A ratio above 1 tells that\n * a price or an amount of the list is possibly wrong. A low ratio is normal, because a list can be any part of a diet.\n * The check of the amount of food is a check of its energy, not of its cost.\n *\n * @param cost - The cost of the food, in a money that converts to the money of the plan\n * @param plan - The food plan\n * @param members - The groups of the members of the household, each with its count of persons\n * @param days - The count of days of the food\n * @throws RangeError for the errors of `foodPlanCost`\n * @throws The error of `valueIn` of `@mark1russell7/quantity` when the money of the cost does not convert to the money of the plan\n */\nexport function foodPlanCheck(cost: Quantity, plan: FoodPlan, members: readonly FoodPlanMember[], days: number): FoodPlanCheck {\n const planned = foodPlanCost(plan, members, days);\n const value = valueIn(cost, planned.unit);\n const ratio = planned.value === 0 ? (value === 0 ? 0 : Number.POSITIVE_INFINITY) : value / planned.value;\n return { plan: planned, cost: quantity(value, planned.unit), ratio, above: ratio > 1 };\n}\n","import type { FoodPlan } from \"./food-plan.ts\";\n\n// The costs of the food plans of USDA. Each value is from the table of the report, read on 2026-11-22. The report\n// rounds each weekly cost to 10 cents. Footnote 2 of the report gives the change for each size of household.\n\nconst week = (value: number): { readonly value: number; readonly unit: string } => ({ value, unit: \"USD/wk\" });\n\n/** The costs of the food plans of USDA, one record for each plan and month. */\nexport const FOOD_PLANS: readonly FoodPlan[] = [\n {\n id: \"usda.thrifty:2026-10\",\n title: \"Official USDA Thrifty Food Plan: U.S. Average, October 2026\",\n area: \"U.S. average\",\n period: \"2026-10\",\n source: {\n id: \"usda.food-plans\",\n title: \"USDA Food Plans: Monthly Cost of Food Reports\",\n url: \"https://www.fna.usda.gov/research/cnpp/usda-food-plans/cost-food-monthly-reports\",\n license: \"us-public-domain\",\n checked: \"2026-11-22\",\n by: \"USDA Food and Nutrition Administration\",\n },\n locator: \"CostofFoodOct2026Thrifty.pdf, the column Weekly Cost of the table of age-sex groups\",\n weekly: {\n \"child-1\": week(26.4),\n \"child-2-3\": week(39.8),\n \"child-4-5\": week(43.5),\n \"child-6-8\": week(48.3),\n \"child-9-11\": week(55.8),\n \"female-12-13\": week(51.7),\n \"female-14-19\": week(60.1),\n \"female-20-50\": week(58.7),\n \"female-51-70\": week(54.6),\n \"female-71-up\": week(60.3),\n \"male-12-13\": week(59.7),\n \"male-14-19\": week(75.3),\n \"male-20-50\": week(73.7),\n \"male-51-70\": week(65),\n \"male-71-up\": week(62),\n },\n sizes: [\n { from: 1, to: 1, change: 0.2 },\n { from: 2, to: 2, change: 0.1 },\n { from: 3, to: 3, change: 0.05 },\n { from: 4, to: 4, change: 0 },\n { from: 5, to: 6, change: -0.05 },\n { from: 7, change: -0.1 },\n ],\n },\n];\n"],"mappings":";;;;;AAcA,MAAa,gBAAgB;;AAG7B,MAAa,eAAe;CAAC;CAAS;CAAQ;CAAS;CAAS;CAAQ;CAAa;AAAe;;AAkFpG,MAAa,eAAe;CAC1B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AASA,SAAS,MAAM,MAAwB;CACrC,IAAI,OAAO,SAAS,UAAU,OAAO;CACrC,IAAI;EACF,OAAO,YAAY,MAAM,IAAI;CAC/B,QAAQ;EACN,OAAO;CACT;AACF;;AAGA,MAAM,cAAc;;AAEpB,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;AAqBnB,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9B;GAAE,MAAM;GAAG,IAAI;GAAG,QAAQ;EAAI;EAC9B;GAAE,MAAM;GAAG,IAAI;GAAG,QAAQ;EAAK;EAC/B;GAAE,MAAM;GAAG,IAAI;GAAG,QAAQ;EAAE;EAC5B;GAAE,MAAM;GAAG,IAAI;GAAG,QAAQ;EAAM;EAChC;GAAE,MAAM;GAAG,QAAQ;EAAK;CAC1B;AACF,CACF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/market",
4
- "version": "0.1.8",
4
+ "version": "0.1.9",
5
5
  "description": "The records of a market: a product, an offer of a seller and a price reading, with their checks, the GTIN check, match keys, the cost of an order, the storage rules of a source, the best offer of a part, a board of current prices within the terms of each source, a buy plan: the Pareto front of the baskets of a need, and metered prices of cloud resources with tiers, free amounts, terms and their cost.",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -1 +0,0 @@
1
- {"version":3,"file":"offers-B_8DqLSA.js","names":[],"sources":["../src/gtin.ts","../src/records.ts","../src/identifiers.ts","../src/price.ts","../src/offers.ts"],"sourcesContent":["/**\n * This module reads the GTIN of a product: a GTIN-8, a UPC-A (12 digits), an EAN-13 or a GTIN-14.\n * The last digit is a check digit. The sum of the other digits, with the weights 3 and 1 from the right, gives it.\n */\n\nconst LENGTHS: ReadonlySet<number> = new Set([8, 12, 13, 14]);\n\n/**\n * This function gives the check digit of the digits of a GTIN without its last digit.\n *\n * @throws RangeError when the text has a character that is not a digit, or no character.\n */\nexport function gtinCheckDigit(body: string): number {\n if (!/^\\d+$/.test(body)) throw new RangeError(`The text ${JSON.stringify(body)} is not a string of digits.`);\n let total = 0;\n for (let i = 0; i < body.length; i += 1) {\n const digit = body.charCodeAt(body.length - 1 - i) - 48;\n total += i % 2 === 0 ? digit * 3 : digit;\n }\n return (10 - (total % 10)) % 10;\n}\n\n/**\n * This function gives the GTIN-14 form of a GTIN, or null. It removes the spaces and the hyphens first.\n * It refuses a length other than 8, 12, 13 or 14 digits, a wrong check digit, and a GTIN of zeros only.\n */\nexport function parseGtin(text: string): string | null {\n const digits = text.replace(/[\\s-]/g, \"\");\n if (!/^\\d+$/.test(digits) || !LENGTHS.has(digits.length) || /^0+$/.test(digits)) return null;\n if (gtinCheckDigit(digits.slice(0, -1)) !== Number(digits.slice(-1))) return null;\n return digits.padStart(14, \"0\");\n}\n","import type { Quantity } from \"@mark1russell7/quantity\";\nimport { quantitySchema } from \"@mark1russell7/quantity/schema\";\nimport { z } from \"zod\";\nimport { parseGtin } from \"./gtin.ts\";\nimport type { PartNumber } from \"./identifiers.ts\";\n\n/**\n * The conditions of an offer. A source maps its own condition to one of them, and it keeps its own text in\n * the field `grade` of the offer.\n */\nexport const CONDITIONS = [\"new\", \"open-box\", \"refurbished\", \"used\", \"for-parts\", \"unknown\"] as const;\n/** The condition of an offer. */\nexport type Condition = (typeof CONDITIONS)[number];\n\n/** The states of the stock of an offer at the time of a reading. */\nexport const AVAILABILITIES = [\"in-stock\", \"low-stock\", \"out-of-stock\", \"preorder\", \"unknown\"] as const;\n/** The state of the stock of an offer. */\nexport type Availability = (typeof AVAILABILITIES)[number];\n\n/** The buying formats of an offer. In an auction, the price of a reading is the current bid. */\nexport const FORMATS = [\"fixed-price\", \"auction\"] as const;\n/** The buying format of an offer. */\nexport type Format = (typeof FORMATS)[number];\n\n/** One specification of a product as text. */\nexport interface Spec {\n readonly name: string;\n readonly value: string;\n}\n\n/** The feedback of a seller: the percent of good feedback, and the count of the feedback. */\nexport interface Rating {\n readonly percent: number;\n readonly count: number;\n}\n\n/** A seller of an offer. A source gives some of these fields, or none. */\nexport interface Seller {\n readonly id?: string | undefined;\n readonly name?: string | undefined;\n readonly rating?: Rating | undefined;\n}\n\n/** A product of the catalog: one thing that a person can buy, with its identifiers and its specifications. */\nexport interface Product {\n readonly id: string;\n readonly title: string;\n readonly brand?: string | undefined;\n readonly category?: readonly string[] | undefined;\n readonly gtins: readonly string[];\n readonly partNumbers: readonly PartNumber[];\n readonly specs: readonly Spec[];\n}\n\n/** An offer of a seller: one product at one seller, with the identifiers that the source gives. */\nexport interface Offer {\n readonly id: string;\n readonly source: string;\n readonly sourceId: string;\n readonly productId?: string | undefined;\n readonly title: string;\n readonly url?: string | undefined;\n readonly seller: Seller;\n readonly condition: Condition;\n readonly grade?: string | undefined;\n readonly format: Format;\n readonly endsAt?: string | undefined;\n readonly gtins: readonly string[];\n readonly partNumbers: readonly PartNumber[];\n readonly specs: readonly Spec[];\n}\n\n/** The shipping of a reading. A calculated cost depends on the address of the buyer. */\nexport type Shipping =\n | { readonly kind: \"free\" }\n | { readonly kind: \"fixed\"; readonly cost: Quantity }\n | { readonly kind: \"calculated\" }\n | { readonly kind: \"unknown\" };\n\n/** A price break of a reading: the unit price for an order of `quantity` units or more. */\nexport interface PriceBreak {\n readonly quantity: number;\n readonly unitPrice: Quantity;\n}\n\n/** A price reading: the state of one offer at one instant. */\nexport interface PriceReading {\n readonly offerId: string;\n readonly at: string;\n readonly price: Quantity;\n readonly listPrice?: Quantity | undefined;\n readonly shipping: Shipping;\n readonly availability: Availability;\n readonly available?: number | undefined;\n readonly minimumQuantity?: number | undefined;\n readonly priceBreaks?: readonly PriceBreak[] | undefined;\n}\n\n/** This schema accepts a text with a character that is not a space, and with no space at an end. */\nexport const textSchema: z.ZodType<string> = z\n .string()\n .refine((text) => text !== \"\" && text === text.trim(), \"The text is empty, or it has a space at an end.\");\n\n/** This schema accepts the name of a source: small letters, digits and hyphens, with a letter first. */\nexport const sourceSchema: z.ZodType<string> = z\n .string()\n .regex(/^[a-z][a-z0-9-]*$/, \"The name of a source has small letters, digits and hyphens, with a letter first.\");\n\n/** This schema accepts a GTIN in its GTIN-14 form, with a correct check digit. `parseGtin` gives this form. */\nexport const gtinSchema: z.ZodType<string> = z\n .string()\n .refine((text) => /^\\d{14}$/.test(text) && parseGtin(text) === text, \"The GTIN is not a GTIN-14 with a correct check digit.\");\n\n/** This schema accepts an amount of money of zero or more, for example `{ \"value\": 129.99, \"unit\": \"USD\" }`. */\nexport const moneySchema: z.ZodType<Quantity, Quantity> = quantitySchema(\"money\", { nonnegative: true });\n\n/** This schema accepts an instant in UTC in the ISO 8601 form, for example `2026-11-12T18:00:00Z`. */\nexport const instantSchema: z.ZodType<string> = z.iso.datetime();\n\n/** This schema accepts a part number of a maker. */\nexport const partNumberSchema: z.ZodType<PartNumber> = z.strictObject({ brand: textSchema, partNumber: textSchema });\n\n/** This schema accepts one specification as text, for example `{ \"name\": \"Capacity\", \"value\": \"1 TB\" }`. */\nexport const specSchema: z.ZodType<Spec> = z.strictObject({ name: textSchema, value: textSchema });\n\n/** This schema accepts a seller. A rating is the percent of good feedback and the count of the feedback. */\nexport const sellerSchema: z.ZodType<Seller> = z.strictObject({\n id: textSchema.optional(),\n name: textSchema.optional(),\n rating: z.strictObject({ percent: z.number().min(0).max(100), count: z.int().nonnegative() }).optional(),\n});\n\n/** This schema accepts a product: one thing that a person can buy, with its identifiers and its specifications. */\nexport const productSchema: z.ZodType<Product> = z.strictObject({\n id: textSchema,\n title: textSchema,\n brand: textSchema.optional(),\n category: z.array(textSchema).optional(),\n gtins: z.array(gtinSchema),\n partNumbers: z.array(partNumberSchema),\n specs: z.array(specSchema),\n});\n\n/** This function gives the id of an offer: the name of its source, a colon, and the id at the source. */\nexport function offerId(source: string, sourceId: string): string {\n return `${source}:${sourceId}`;\n}\n\n/** This function gives the name of the source of an offer id: the text before the first colon. */\nexport function sourceOfOffer(id: string): string {\n const colon = id.indexOf(\":\");\n if (colon <= 0) throw new RangeError(`The offer id ${JSON.stringify(id)} has no source.`);\n return id.slice(0, colon);\n}\n\n/**\n * This schema accepts an offer: one product at one seller. The offer has the identifiers that the source gives.\n * `productId` names the product of the catalog after a match.\n */\nexport const offerSchema: z.ZodType<Offer> = z\n .strictObject({\n id: textSchema,\n source: sourceSchema,\n sourceId: textSchema,\n productId: textSchema.optional(),\n title: textSchema,\n url: z.url({ protocol: /^https$/ }).optional(),\n seller: sellerSchema,\n condition: z.enum(CONDITIONS),\n grade: textSchema.optional(),\n format: z.enum(FORMATS),\n endsAt: instantSchema.optional(),\n gtins: z.array(gtinSchema),\n partNumbers: z.array(partNumberSchema),\n specs: z.array(specSchema),\n })\n .refine((offer) => offer.id === offerId(offer.source, offer.sourceId), {\n message: \"The id of an offer is its source and its source id, with a colon between them.\",\n path: [\"id\"],\n });\n\n/** This schema accepts the shipping of a reading. A calculated cost depends on the address of the buyer. */\nexport const shippingSchema: z.ZodType<Shipping> = z.discriminatedUnion(\"kind\", [\n z.strictObject({ kind: z.literal(\"free\") }),\n z.strictObject({ kind: z.literal(\"fixed\"), cost: moneySchema }),\n z.strictObject({ kind: z.literal(\"calculated\") }),\n z.strictObject({ kind: z.literal(\"unknown\") }),\n]);\n\n/** This schema accepts a price break: the unit price for an order of `quantity` units or more. */\nexport const priceBreakSchema: z.ZodType<PriceBreak> = z.strictObject({ quantity: z.int().min(2), unitPrice: moneySchema });\n\n/**\n * This schema accepts a price reading: the state of one offer at one instant. `price` is the unit price for an\n * order of `minimumQuantity` units, or of one unit. The quantities of the breaks increase, and each is more\n * than the minimum.\n */\nexport const priceReadingSchema: z.ZodType<PriceReading> = z\n .strictObject({\n offerId: textSchema,\n at: instantSchema,\n price: moneySchema,\n listPrice: moneySchema.optional(),\n shipping: shippingSchema,\n availability: z.enum(AVAILABILITIES),\n available: z.int().nonnegative().optional(),\n minimumQuantity: z.int().min(1).optional(),\n priceBreaks: z.array(priceBreakSchema).optional(),\n })\n .superRefine((reading, context) => {\n let last = reading.minimumQuantity ?? 1;\n for (const [index, entry] of (reading.priceBreaks ?? []).entries()) {\n if (entry.quantity <= last) {\n context.addIssue({\n code: \"custom\",\n message: `The break ${index} has the quantity ${entry.quantity}, which is not more than ${last}.`,\n path: [\"priceBreaks\", index, \"quantity\"],\n });\n }\n last = Math.max(last, entry.quantity);\n }\n const { availability, available } = reading;\n if (available === undefined || availability === \"unknown\" || availability === \"preorder\") return;\n if ((availability === \"out-of-stock\") !== (available === 0)) {\n context.addIssue({\n code: \"custom\",\n message: `The availability ${availability} does not agree with the count ${available}.`,\n path: [\"available\"],\n });\n }\n });\n","import { parseGtin } from \"./gtin.ts\";\n\n/** A part number of a maker: the brand, and the number that the maker gives to the part. */\nexport interface PartNumber {\n readonly brand: string;\n readonly partNumber: string;\n}\n\n/** The identifiers of a product or of an offer. */\nexport interface Identifiers {\n readonly gtins: readonly string[];\n readonly partNumbers: readonly PartNumber[];\n}\n\n/**\n * This function folds a brand or a part number for a comparison. The result has only capital letters A to Z\n * and digits. Thus `MZ-V8V1T0B/AM` and `mzv8v1t0bam` fold to one text.\n */\nexport function foldCode(text: string): string {\n return text.normalize(\"NFKD\").toUpperCase().replace(/[^A-Z0-9]/g, \"\");\n}\n\n/**\n * This function gives the match keys of a record, sorted and with no copy. A key is `gtin:` with the GTIN-14,\n * or `part:` with the folded brand and part number. Two records with a key in common name one product.\n * The function ignores a GTIN that is not valid, and a part number whose brand or number folds to no text.\n */\nexport function matchKeys(identifiers: Identifiers): string[] {\n const keys = new Set<string>();\n for (const text of identifiers.gtins) {\n const gtin = parseGtin(text);\n if (gtin !== null) keys.add(`gtin:${gtin}`);\n }\n for (const { brand, partNumber } of identifiers.partNumbers) {\n const folded = [foldCode(brand), foldCode(partNumber)];\n if (folded.every((part) => part !== \"\")) keys.add(`part:${folded.join(\"/\")}`);\n }\n return [...keys].sort();\n}\n","import { add, scale, type Quantity } from \"@mark1russell7/quantity\";\nimport type { PriceReading } from \"./records.ts\";\n\n/**\n * This function gives the unit price for an order of `count` units. The price of the largest break at or\n * below the count applies, or the price of the reading when no break applies.\n *\n * @throws RangeError when the count is not a whole number, or when it is less than the minimum of the reading.\n */\nexport function unitPriceFor(reading: PriceReading, count: number): Quantity {\n const minimum = reading.minimumQuantity ?? 1;\n if (!Number.isSafeInteger(count) || count < minimum) {\n throw new RangeError(`The count ${count} is not a whole number of ${minimum} or more.`);\n }\n let price: Quantity = reading.price;\n for (const entry of reading.priceBreaks ?? []) if (entry.quantity <= count) price = entry.unitPrice;\n return price;\n}\n\n/**\n * This function gives the cost of an order of `count` units with its shipping, or null when the shipping\n * cost is not known. The cost is exact, and the function does not round it to the cent.\n *\n * @throws RangeError when the count is not a whole number, or when it is less than the minimum of the reading.\n */\nexport function costOf(reading: PriceReading, count: number): Quantity | null {\n const goods = scale(unitPriceFor(reading, count), count);\n switch (reading.shipping.kind) {\n case \"free\":\n return goods;\n case \"fixed\":\n return add(goods, reading.shipping.cost);\n default:\n return null;\n }\n}\n","import { compare, convert, convertible, kindOf, scale, UnitError, type Quantity } from \"@mark1russell7/quantity\";\nimport { foldCode } from \"./identifiers.ts\";\nimport { costOf, unitPriceFor } from \"./price.ts\";\nimport type { Condition, Offer, PriceReading } from \"./records.ts\";\n\n/** One offer of a source, and its price reading at one instant. */\nexport interface Observation {\n readonly offer: Offer;\n readonly reading: PriceReading;\n}\n\n/**\n * This record names a part that a buyer wants: the names of its maker, and its part numbers. A seller can write\n * the brand of one maker in more than one form, so the want has a list of names.\n */\nexport interface PartWant {\n /** The names of the maker, as the sellers write the brand. */\n readonly brands: readonly string[];\n /** The part numbers of the maker. A part number of an offer matches when it starts with one of them, after the fold. */\n readonly partNumbers: readonly string[];\n}\n\n/**\n * This function tells if an offer is an offer of the part. One part number of the offer must have a brand of the\n * want and start with a part number of the want. `foldCode` folds each text before the comparison. A part number\n * of another maker does not match: many makers use short numbers like `A1383`.\n */\nexport function offersPart(offer: Pick<Offer, \"partNumbers\">, want: PartWant): boolean {\n const brands = new Set(want.brands.map(foldCode).filter((brand) => brand !== \"\"));\n const parts = want.partNumbers.map(foldCode).filter((part) => part !== \"\");\n return offer.partNumbers.some(({ brand, partNumber }) => {\n const folded = foldCode(partNumber);\n return brands.has(foldCode(brand)) && parts.some((part) => folded.startsWith(part));\n });\n}\n\n/**\n * This function gives the latest observation of each offer, in the order of the offer ids. When two readings of\n * one offer have the same instant, the later one in the list applies.\n */\nexport function latestObservations(observations: readonly Observation[]): Observation[] {\n const latest = new Map<string, Observation>();\n for (const each of observations) {\n const seen = latest.get(each.offer.id);\n if (seen === undefined || Date.parse(seen.reading.at) <= Date.parse(each.reading.at)) latest.set(each.offer.id, each);\n }\n return [...latest.values()].sort((a, b) => order(a.offer.id, b.offer.id));\n}\n\n/** This function gives the latest observation of each offer of the part, in the order of the offer ids. */\nexport function offersOfPart(observations: readonly Observation[], want: PartWant): Observation[] {\n return latestObservations(observations.filter((each) => offersPart(each.offer, want)));\n}\n\n/** This record is one offer that a buyer can choose, with the price of an order in the currency of the buyer. */\nexport interface OfferChoice {\n readonly observation: Observation;\n /** The unit price for the count, times the count. */\n readonly goods: Quantity;\n /** The goods and the shipping, or null when the shipping cost is not known. */\n readonly cost: Quantity | null;\n /** True when the availability is `in-stock` or `low-stock`. */\n readonly inStock: boolean;\n}\n\n/** These options change the choice of an offer. */\nexport interface BestOfferOptions {\n /** The currency of the prices, a unit of money of `@mark1russell7/quantity`, for example `USD`. An offer with a price in another currency is skipped. */\n readonly currency: string;\n /** The count of units of the order. The default is 1. */\n readonly count?: number;\n /** The conditions that the buyer accepts. The default is `new` only. */\n readonly conditions?: readonly Condition[];\n}\n\n/** This record is the choice of an offer: the best offer, each offer in the order of the price, and each skipped offer. */\nexport interface BestOffer {\n /** The offer with the lowest price that is in stock, or else the offer with the lowest price, or null with no offer. */\n readonly best: OfferChoice | null;\n /** The offers, from the lowest price of the goods. Equal prices go in the order of the cost, then of the offer id. */\n readonly offers: readonly OfferChoice[];\n /** The offers that the choice skipped, each with the reason. */\n readonly skipped: readonly { readonly offerId: string; readonly why: string }[];\n}\n\n/**\n * This function chooses the offer to buy from the latest observation of each offer. It skips an offer with a\n * condition that the buyer does not accept, a price in another currency, or a minimum above the count.\n *\n * @throws RangeError when the count is not a whole number of 1 or more, or when the currency is not a unit of money.\n */\nexport function bestOffer(observations: readonly Observation[], options: BestOfferOptions): BestOffer {\n const { currency, count = 1, conditions = [\"new\"] } = options;\n if (!Number.isSafeInteger(count) || count < 1) throw new RangeError(`The count ${count} is not a whole number of 1 or more.`);\n if (!isMoney(currency)) throw new RangeError(`The currency ${currency} is not a unit of money of @mark1russell7/quantity.`);\n const accepted = new Set<Condition>(conditions);\n const offers: OfferChoice[] = [];\n const skipped: { offerId: string; why: string }[] = [];\n for (const observation of latestObservations(observations)) {\n const { offer, reading } = observation;\n const minimum = reading.minimumQuantity ?? 1;\n if (!accepted.has(offer.condition)) skipped.push({ offerId: offer.id, why: `The condition ${offer.condition} is not a condition that the buyer accepts.` });\n else if (!converts(reading.price.unit, currency)) skipped.push({ offerId: offer.id, why: `The price is in ${reading.price.unit}, not in ${currency}.` });\n else if (count < minimum) skipped.push({ offerId: offer.id, why: `The minimum order is ${minimum} units, more than the count ${count}.` });\n else {\n const goods = convert(scale(unitPriceFor(reading, count), count), currency);\n // A shipping cost in another currency is not known in the currency of the buyer.\n const shipping = reading.shipping.kind !== \"fixed\" || converts(reading.shipping.cost.unit, currency);\n const total = shipping ? costOf(reading, count) : null;\n const cost = total === null ? null : convert(total, currency);\n const inStock = reading.availability === \"in-stock\" || reading.availability === \"low-stock\";\n offers.push({ observation, goods, cost, inStock });\n }\n }\n offers.sort((a, b) => compare(a.goods, b.goods) || byCost(a.cost, b.cost) || order(a.observation.offer.id, b.observation.offer.id));\n const best = offers.find((choice) => choice.inStock) ?? offers[0] ?? null;\n return { best, offers, skipped };\n}\n\n/** This function tells if a unit is a unit of money that the quantity package knows. */\nfunction isMoney(unit: string): boolean {\n try {\n return kindOf(unit) === \"money\";\n } catch (error) {\n if (error instanceof UnitError) return false;\n throw error;\n }\n}\n\n/** This function tells if an amount in one unit converts to another unit. A unit that the quantity package does not know does not convert. */\nfunction converts(from: string, to: string): boolean {\n try {\n return convertible(from, to);\n } catch (error) {\n if (error instanceof UnitError) return false;\n throw error;\n }\n}\n\n/** This function orders two costs. A known cost comes before a cost that is not known. */\nfunction byCost(a: Quantity | null, b: Quantity | null): number {\n if (a === null || b === null) return a === b ? 0 : a === null ? 1 : -1;\n return compare(a, b);\n}\n\n/** This function orders two texts by their code units, so the order does not depend on the locale. */\nfunction order(a: string, b: string): number {\n return a < b ? -1 : a > b ? 1 : 0;\n}\n\n/** The offer to buy for one count of a part, or the reason that no offer is usable. */\nexport type Priced = { readonly ok: true; readonly offerId: string; readonly cost: Quantity } | { readonly ok: false; readonly why: string };\n\n/**\n * This function chooses the offer to buy for a count of a part: the in-stock offer with the lowest cost, with the\n * shipping. An offer with a cost that is not known is not usable. Equal costs keep the order of `bestOffer`.\n */\nexport function priceOf(observations: readonly Observation[], count: number, need: { readonly currency: string; readonly conditions?: readonly Condition[] | undefined }): Priced {\n const choice = bestOffer(observations, { currency: need.currency, count, ...(need.conditions === undefined ? {} : { conditions: need.conditions }) });\n let pick: (OfferChoice & { readonly cost: Quantity }) | undefined;\n for (const offer of choice.offers) {\n const cost = offer.cost;\n if (offer.inStock && cost !== null && (pick === undefined || compare(cost, pick.cost) < 0)) pick = { ...offer, cost };\n }\n if (pick !== undefined) return { ok: true, offerId: pick.observation.offer.id, cost: pick.cost };\n if (choice.offers.length > 0) return { ok: false, why: `No offer of ${String(count)} units is in stock with a known cost.` };\n const first = choice.skipped[0];\n return { ok: false, why: first === undefined ? \"No offer matches the part.\" : `No offer is usable. The first offer that the choice skipped: ${first.why}` };\n}\n"],"mappings":";;;;;;;;AAKA,MAAM,0BAA+B,IAAI,IAAI;CAAC;CAAG;CAAI;CAAI;AAAE,CAAC;;;;;;AAO5D,SAAgB,eAAe,MAAsB;CACnD,IAAI,CAAC,QAAQ,KAAK,IAAI,GAAG,MAAM,IAAI,WAAW,YAAY,KAAK,UAAU,IAAI,EAAE,4BAA4B;CAC3G,IAAI,QAAQ;CACZ,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK,GAAG;EACvC,MAAM,QAAQ,KAAK,WAAW,KAAK,SAAS,IAAI,CAAC,IAAI;EACrD,SAAS,IAAI,MAAM,IAAI,QAAQ,IAAI;CACrC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