@mark1russell7/market 0.1.2 → 0.1.4

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.
@@ -0,0 +1,346 @@
1
+ import { UnitError, add, compare, convert, convertible, kindOf, scale } from "@mark1russell7/quantity";
2
+ import { quantitySchema } from "@mark1russell7/quantity/schema";
3
+ import { z } from "zod";
4
+ // src/gtin.ts
5
+ /**
6
+ * This module reads the GTIN of a product: a GTIN-8, a UPC-A (12 digits), an EAN-13 or a GTIN-14.
7
+ * The last digit is a check digit. The sum of the other digits, with the weights 3 and 1 from the right, gives it.
8
+ */
9
+ const LENGTHS = /* @__PURE__ */ new Set([
10
+ 8,
11
+ 12,
12
+ 13,
13
+ 14
14
+ ]);
15
+ /**
16
+ * This function gives the check digit of the digits of a GTIN without its last digit.
17
+ *
18
+ * @throws RangeError when the text has a character that is not a digit, or no character.
19
+ */
20
+ function gtinCheckDigit(body) {
21
+ if (!/^\d+$/.test(body)) throw new RangeError(`The text ${JSON.stringify(body)} is not a string of digits.`);
22
+ let total = 0;
23
+ for (let i = 0; i < body.length; i += 1) {
24
+ const digit = body.charCodeAt(body.length - 1 - i) - 48;
25
+ total += i % 2 === 0 ? digit * 3 : digit;
26
+ }
27
+ return (10 - total % 10) % 10;
28
+ }
29
+ /**
30
+ * This function gives the GTIN-14 form of a GTIN, or null. It removes the spaces and the hyphens first.
31
+ * It refuses a length other than 8, 12, 13 or 14 digits, a wrong check digit, and a GTIN of zeros only.
32
+ */
33
+ function parseGtin(text) {
34
+ const digits = text.replace(/[\s-]/g, "");
35
+ if (!/^\d+$/.test(digits) || !LENGTHS.has(digits.length) || /^0+$/.test(digits)) return null;
36
+ if (gtinCheckDigit(digits.slice(0, -1)) !== Number(digits.slice(-1))) return null;
37
+ return digits.padStart(14, "0");
38
+ }
39
+ // src/identifiers.ts
40
+ /**
41
+ * This function folds a brand or a part number for a comparison. The result has only capital letters A to Z
42
+ * and digits. Thus `MZ-V8V1T0B/AM` and `mzv8v1t0bam` fold to one text.
43
+ */
44
+ function foldCode(text) {
45
+ return text.normalize("NFKD").toUpperCase().replace(/[^A-Z0-9]/g, "");
46
+ }
47
+ /**
48
+ * This function gives the match keys of a record, sorted and with no copy. A key is `gtin:` with the GTIN-14,
49
+ * or `part:` with the folded brand and part number. Two records with a key in common name one product.
50
+ * The function ignores a GTIN that is not valid, and a part number whose brand or number folds to no text.
51
+ */
52
+ function matchKeys(identifiers) {
53
+ const keys = /* @__PURE__ */ new Set();
54
+ for (const text of identifiers.gtins) {
55
+ const gtin = parseGtin(text);
56
+ if (gtin !== null) keys.add(`gtin:${gtin}`);
57
+ }
58
+ for (const { brand, partNumber } of identifiers.partNumbers) {
59
+ const folded = [foldCode(brand), foldCode(partNumber)];
60
+ if (folded.every((part) => part !== "")) keys.add(`part:${folded.join("/")}`);
61
+ }
62
+ return [...keys].sort();
63
+ }
64
+ // src/price.ts
65
+ /**
66
+ * This function gives the unit price for an order of `count` units. The price of the largest break at or
67
+ * below the count applies, or the price of the reading when no break applies.
68
+ *
69
+ * @throws RangeError when the count is not a whole number, or when it is less than the minimum of the reading.
70
+ */
71
+ function unitPriceFor(reading, count) {
72
+ const minimum = reading.minimumQuantity ?? 1;
73
+ if (!Number.isSafeInteger(count) || count < minimum) throw new RangeError(`The count ${count} is not a whole number of ${minimum} or more.`);
74
+ let price = reading.price;
75
+ for (const entry of reading.priceBreaks ?? []) if (entry.quantity <= count) price = entry.unitPrice;
76
+ return price;
77
+ }
78
+ /**
79
+ * This function gives the cost of an order of `count` units with its shipping, or null when the shipping
80
+ * cost is not known. The cost is exact, and the function does not round it to the cent.
81
+ *
82
+ * @throws RangeError when the count is not a whole number, or when it is less than the minimum of the reading.
83
+ */
84
+ function costOf(reading, count) {
85
+ const goods = scale(unitPriceFor(reading, count), count);
86
+ switch (reading.shipping.kind) {
87
+ case "free": return goods;
88
+ case "fixed": return add(goods, reading.shipping.cost);
89
+ default: return null;
90
+ }
91
+ }
92
+ // src/offers.ts
93
+ /**
94
+ * This function tells if an offer is an offer of the part. One part number of the offer must have a brand of the
95
+ * want and start with a part number of the want. `foldCode` folds each text before the comparison. A part number
96
+ * of another maker does not match: many makers use short numbers like `A1383`.
97
+ */
98
+ function offersPart(offer, want) {
99
+ const brands = new Set(want.brands.map(foldCode).filter((brand) => brand !== ""));
100
+ const parts = want.partNumbers.map(foldCode).filter((part) => part !== "");
101
+ return offer.partNumbers.some(({ brand, partNumber }) => {
102
+ const folded = foldCode(partNumber);
103
+ return brands.has(foldCode(brand)) && parts.some((part) => folded.startsWith(part));
104
+ });
105
+ }
106
+ /**
107
+ * This function gives the latest observation of each offer, in the order of the offer ids. When two readings of
108
+ * one offer have the same instant, the later one in the list applies.
109
+ */
110
+ function latestObservations(observations) {
111
+ const latest = /* @__PURE__ */ new Map();
112
+ for (const each of observations) {
113
+ const seen = latest.get(each.offer.id);
114
+ if (seen === void 0 || Date.parse(seen.reading.at) <= Date.parse(each.reading.at)) latest.set(each.offer.id, each);
115
+ }
116
+ return [...latest.values()].sort((a, b) => order(a.offer.id, b.offer.id));
117
+ }
118
+ /** This function gives the latest observation of each offer of the part, in the order of the offer ids. */
119
+ function offersOfPart(observations, want) {
120
+ return latestObservations(observations.filter((each) => offersPart(each.offer, want)));
121
+ }
122
+ /**
123
+ * This function chooses the offer to buy from the latest observation of each offer. It skips an offer with a
124
+ * condition that the buyer does not accept, a price in another currency, or a minimum above the count.
125
+ *
126
+ * @throws RangeError when the count is not a whole number of 1 or more, or when the currency is not a unit of money.
127
+ */
128
+ function bestOffer(observations, options) {
129
+ const { currency, count = 1, conditions = ["new"] } = options;
130
+ if (!Number.isSafeInteger(count) || count < 1) throw new RangeError(`The count ${count} is not a whole number of 1 or more.`);
131
+ if (!isMoney(currency)) throw new RangeError(`The currency ${currency} is not a unit of money of @mark1russell7/quantity.`);
132
+ const accepted = new Set(conditions);
133
+ const offers = [];
134
+ const skipped = [];
135
+ for (const observation of latestObservations(observations)) {
136
+ const { offer, reading } = observation;
137
+ const minimum = reading.minimumQuantity ?? 1;
138
+ if (!accepted.has(offer.condition)) skipped.push({
139
+ offerId: offer.id,
140
+ why: `The condition ${offer.condition} is not a condition that the buyer accepts.`
141
+ });
142
+ else if (!converts(reading.price.unit, currency)) skipped.push({
143
+ offerId: offer.id,
144
+ why: `The price is in ${reading.price.unit}, not in ${currency}.`
145
+ });
146
+ else if (count < minimum) skipped.push({
147
+ offerId: offer.id,
148
+ why: `The minimum order is ${minimum} units, more than the count ${count}.`
149
+ });
150
+ else {
151
+ const goods = convert(scale(unitPriceFor(reading, count), count), currency);
152
+ const total = reading.shipping.kind !== "fixed" || converts(reading.shipping.cost.unit, currency) ? costOf(reading, count) : null;
153
+ const cost = total === null ? null : convert(total, currency);
154
+ const inStock = reading.availability === "in-stock" || reading.availability === "low-stock";
155
+ offers.push({
156
+ observation,
157
+ goods,
158
+ cost,
159
+ inStock
160
+ });
161
+ }
162
+ }
163
+ offers.sort((a, b) => compare(a.goods, b.goods) || byCost(a.cost, b.cost) || order(a.observation.offer.id, b.observation.offer.id));
164
+ return {
165
+ best: offers.find((choice) => choice.inStock) ?? offers[0] ?? null,
166
+ offers,
167
+ skipped
168
+ };
169
+ }
170
+ /** This function tells if a unit is a unit of money that the quantity package knows. */
171
+ function isMoney(unit) {
172
+ try {
173
+ return kindOf(unit) === "money";
174
+ } catch (error) {
175
+ if (error instanceof UnitError) return false;
176
+ throw error;
177
+ }
178
+ }
179
+ /** 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. */
180
+ function converts(from, to) {
181
+ try {
182
+ return convertible(from, to);
183
+ } catch (error) {
184
+ if (error instanceof UnitError) return false;
185
+ throw error;
186
+ }
187
+ }
188
+ /** This function orders two costs. A known cost comes before a cost that is not known. */
189
+ function byCost(a, b) {
190
+ if (a === null || b === null) return a === b ? 0 : a === null ? 1 : -1;
191
+ return compare(a, b);
192
+ }
193
+ /** This function orders two texts by their code units, so the order does not depend on the locale. */
194
+ function order(a, b) {
195
+ return a < b ? -1 : a > b ? 1 : 0;
196
+ }
197
+ // src/records.ts
198
+ /**
199
+ * The conditions of an offer. A source maps its own condition to one of them, and it keeps its own text in
200
+ * the field `grade` of the offer.
201
+ */
202
+ const CONDITIONS = [
203
+ "new",
204
+ "open-box",
205
+ "refurbished",
206
+ "used",
207
+ "for-parts",
208
+ "unknown"
209
+ ];
210
+ /** The states of the stock of an offer at the time of a reading. */
211
+ const AVAILABILITIES = [
212
+ "in-stock",
213
+ "low-stock",
214
+ "out-of-stock",
215
+ "preorder",
216
+ "unknown"
217
+ ];
218
+ /** The buying formats of an offer. In an auction, the price of a reading is the current bid. */
219
+ const FORMATS = ["fixed-price", "auction"];
220
+ /** This schema accepts a text with a character that is not a space, and with no space at an end. */
221
+ const textSchema = z.string().refine((text) => text !== "" && text === text.trim(), "The text is empty, or it has a space at an end.");
222
+ /** This schema accepts the name of a source: small letters, digits and hyphens, with a letter first. */
223
+ const sourceSchema = z.string().regex(/^[a-z][a-z0-9-]*$/, "The name of a source has small letters, digits and hyphens, with a letter first.");
224
+ /** This schema accepts a GTIN in its GTIN-14 form, with a correct check digit. `parseGtin` gives this form. */
225
+ const gtinSchema = z.string().refine((text) => /^\d{14}$/.test(text) && parseGtin(text) === text, "The GTIN is not a GTIN-14 with a correct check digit.");
226
+ /** This schema accepts an amount of money of zero or more, for example `{ "value": 129.99, "unit": "USD" }`. */
227
+ const moneySchema = quantitySchema("money", { nonnegative: true });
228
+ /** This schema accepts an instant in UTC in the ISO 8601 form, for example `2026-11-12T18:00:00Z`. */
229
+ const instantSchema = z.iso.datetime();
230
+ /** This schema accepts a part number of a maker. */
231
+ const partNumberSchema = z.strictObject({
232
+ brand: textSchema,
233
+ partNumber: textSchema
234
+ });
235
+ /** This schema accepts one specification as text, for example `{ "name": "Capacity", "value": "1 TB" }`. */
236
+ const specSchema = z.strictObject({
237
+ name: textSchema,
238
+ value: textSchema
239
+ });
240
+ /** This schema accepts a seller. A rating is the percent of good feedback and the count of the feedback. */
241
+ const sellerSchema = z.strictObject({
242
+ id: textSchema.optional(),
243
+ name: textSchema.optional(),
244
+ rating: z.strictObject({
245
+ percent: z.number().min(0).max(100),
246
+ count: z.int().nonnegative()
247
+ }).optional()
248
+ });
249
+ /** This schema accepts a product: one thing that a person can buy, with its identifiers and its specifications. */
250
+ const productSchema = z.strictObject({
251
+ id: textSchema,
252
+ title: textSchema,
253
+ brand: textSchema.optional(),
254
+ category: z.array(textSchema).optional(),
255
+ gtins: z.array(gtinSchema),
256
+ partNumbers: z.array(partNumberSchema),
257
+ specs: z.array(specSchema)
258
+ });
259
+ /** This function gives the id of an offer: the name of its source, a colon, and the id at the source. */
260
+ function offerId(source, sourceId) {
261
+ return `${source}:${sourceId}`;
262
+ }
263
+ /** This function gives the name of the source of an offer id: the text before the first colon. */
264
+ function sourceOfOffer(id) {
265
+ const colon = id.indexOf(":");
266
+ if (colon <= 0) throw new RangeError(`The offer id ${JSON.stringify(id)} has no source.`);
267
+ return id.slice(0, colon);
268
+ }
269
+ /**
270
+ * This schema accepts an offer: one product at one seller. The offer has the identifiers that the source gives.
271
+ * `productId` names the product of the catalog after a match.
272
+ */
273
+ const offerSchema = z.strictObject({
274
+ id: textSchema,
275
+ source: sourceSchema,
276
+ sourceId: textSchema,
277
+ productId: textSchema.optional(),
278
+ title: textSchema,
279
+ url: z.url({ protocol: /^https$/ }).optional(),
280
+ seller: sellerSchema,
281
+ condition: z.enum(CONDITIONS),
282
+ grade: textSchema.optional(),
283
+ format: z.enum(FORMATS),
284
+ endsAt: instantSchema.optional(),
285
+ gtins: z.array(gtinSchema),
286
+ partNumbers: z.array(partNumberSchema),
287
+ specs: z.array(specSchema)
288
+ }).refine((offer) => offer.id === offerId(offer.source, offer.sourceId), {
289
+ message: "The id of an offer is its source and its source id, with a colon between them.",
290
+ path: ["id"]
291
+ });
292
+ /** This schema accepts the shipping of a reading. A calculated cost depends on the address of the buyer. */
293
+ const shippingSchema = z.discriminatedUnion("kind", [
294
+ z.strictObject({ kind: z.literal("free") }),
295
+ z.strictObject({
296
+ kind: z.literal("fixed"),
297
+ cost: moneySchema
298
+ }),
299
+ z.strictObject({ kind: z.literal("calculated") }),
300
+ z.strictObject({ kind: z.literal("unknown") })
301
+ ]);
302
+ /** This schema accepts a price break: the unit price for an order of `quantity` units or more. */
303
+ const priceBreakSchema = z.strictObject({
304
+ quantity: z.int().min(2),
305
+ unitPrice: moneySchema
306
+ });
307
+ /**
308
+ * This schema accepts a price reading: the state of one offer at one instant. `price` is the unit price for an
309
+ * order of `minimumQuantity` units, or of one unit. The quantities of the breaks increase, and each is more
310
+ * than the minimum.
311
+ */
312
+ const priceReadingSchema = z.strictObject({
313
+ offerId: textSchema,
314
+ at: instantSchema,
315
+ price: moneySchema,
316
+ listPrice: moneySchema.optional(),
317
+ shipping: shippingSchema,
318
+ availability: z.enum(AVAILABILITIES),
319
+ available: z.int().nonnegative().optional(),
320
+ minimumQuantity: z.int().min(1).optional(),
321
+ priceBreaks: z.array(priceBreakSchema).optional()
322
+ }).superRefine((reading, context) => {
323
+ let last = reading.minimumQuantity ?? 1;
324
+ for (const [index, entry] of (reading.priceBreaks ?? []).entries()) {
325
+ if (entry.quantity <= last) context.addIssue({
326
+ code: "custom",
327
+ message: `The break ${index} has the quantity ${entry.quantity}, which is not more than ${last}.`,
328
+ path: [
329
+ "priceBreaks",
330
+ index,
331
+ "quantity"
332
+ ]
333
+ });
334
+ last = Math.max(last, entry.quantity);
335
+ }
336
+ const { availability, available } = reading;
337
+ if (available === void 0 || availability === "unknown" || availability === "preorder") return;
338
+ if (availability === "out-of-stock" !== (available === 0)) context.addIssue({
339
+ code: "custom",
340
+ message: `The availability ${availability} does not agree with the count ${available}.`,
341
+ path: ["available"]
342
+ });
343
+ });
344
+ export { costOf as C, gtinCheckDigit as D, matchKeys as E, parseGtin as O, offersPart as S, foldCode as T, specSchema as _, instantSchema as a, latestObservations as b, offerSchema as c, priceReadingSchema as d, productSchema as f, sourceSchema as g, sourceOfOffer as h, gtinSchema as i, partNumberSchema as l, shippingSchema as m, CONDITIONS as n, moneySchema as o, sellerSchema as p, FORMATS as r, offerId as s, AVAILABILITIES as t, priceBreakSchema as u, textSchema as v, unitPriceFor as w, offersOfPart as x, bestOffer as y };
345
+
346
+ //# sourceMappingURL=records-hK1UCmpm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"records-hK1UCmpm.js","names":[],"sources":["../src/gtin.ts","../src/identifiers.ts","../src/price.ts","../src/offers.ts","../src/records.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 { 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","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"],"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,KAA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AAS,YAAY;CACjC,IAAI,OAAO,QAAQ,mBAAmB;CACtC,KAAK,MAAM,CAAC,OAAO,WAAW,QAAQ,eAAe,CAAC,EAAA,CAAG,QAAQ,GAAG;EAClE,IAAI,MAAM,YAAY,MACpB,QAAQ,SAAS;GACf,MAAM;GACN,SAAS,aAAa,MAAM,oBAAoB,MAAM,SAAS,2BAA2B,KAAK;GAC/F,MAAM;IAAC;IAAe;IAAO;GAAU;EACzC,CAAC;EAEH,OAAO,KAAK,IAAI,MAAM,MAAM,QAAQ;CACtC;CACA,MAAM,EAAE,cAAc,cAAc;CACpC,IAAI,cAAc,KAAA,KAAa,iBAAiB,aAAa,iBAAiB,YAAY;CAC1F,IAAK,iBAAiB,oBAAqB,cAAc,IACvD,QAAQ,SAAS;EACf,MAAM;EACN,SAAS,oBAAoB,aAAa,iCAAiC,UAAU;EACrF,MAAM,CAAC,WAAW;CACpB,CAAC;AAEL,CAAC"}
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/market",
4
- "version": "0.1.2",
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, and a board of current prices within the terms of each source.",
4
+ "version": "0.1.4",
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, and a buy plan: the Pareto front of the baskets of a need.",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
@@ -20,7 +20,9 @@
20
20
  "price-history",
21
21
  "products",
22
22
  "catalog",
23
- "parts"
23
+ "parts",
24
+ "buy-plan",
25
+ "pareto"
24
26
  ],
25
27
  "type": "module",
26
28
  "main": "./build/index.js",
@@ -30,6 +32,11 @@
30
32
  "import": "./build/index.js",
31
33
  "default": "./build/index.js"
32
34
  },
35
+ "./plan": {
36
+ "types": "./build/plan.d.ts",
37
+ "import": "./build/plan.js",
38
+ "default": "./build/plan.js"
39
+ },
33
40
  "./package.json": "./package.json"
34
41
  },
35
42
  "files": [
@@ -37,6 +44,10 @@
37
44
  ],
38
45
  "dependencies": {
39
46
  "@mark1russell7/quantity": "^0.4.0",
47
+ "@mark1russell7/strategy-search": "^0.1.0",
48
+ "@mark1russell7/strategy-space": "^0.1.0",
49
+ "@mark1russell7/vex": "^0.19.1",
50
+ "@mark1russell7/vex-domains": "^0.19.1",
40
51
  "zod": "^4.6.7"
41
52
  },
42
53
  "devDependencies": {